Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com>
This commit is contained in:
Denis Bykhov
2024-09-11 15:31:26 +07:00
committed by GitHub
parent 74c27d6dd7
commit bf1de1f436
62 changed files with 4187 additions and 632 deletions
+4 -12
View File
@@ -14,6 +14,7 @@
//
import {
type LowLevelStorage,
type Class,
type Doc,
type DocumentQuery,
@@ -26,7 +27,6 @@ import {
type MeasureContext,
type ModelDb,
type Ref,
type StorageIterator,
type Tx,
type TxResult,
type WorkspaceId
@@ -36,7 +36,7 @@ import type { ServerFindOptions } from './types'
export interface DomainHelperOperations {
create: (domain: Domain) => Promise<void>
exists: (domain: Domain) => boolean
exists: (domain: Domain) => Promise<boolean>
listDomains: () => Promise<Set<Domain>>
createIndex: (domain: Domain, value: string | FieldIndexConfig<Doc>, options?: { name: string }) => Promise<void>
@@ -99,8 +99,8 @@ export type DbAdapterHandler = (
/**
* @public
*/
export interface DbAdapter {
init?: () => Promise<void>
export interface DbAdapter extends LowLevelStorage {
init?: (domains?: string[], excludeDomains?: string[]) => Promise<void>
helper: () => DomainHelperOperations
@@ -114,14 +114,6 @@ export interface DbAdapter {
tx: (ctx: MeasureContext, ...tx: Tx[]) => Promise<TxResult[]>
find: (ctx: MeasureContext, domain: Domain, recheck?: boolean) => StorageIterator
load: (ctx: MeasureContext, domain: Domain, docs: Ref<Doc>[]) => Promise<Doc[]>
upload: (ctx: MeasureContext, domain: Domain, docs: Doc[]) => Promise<void>
clean: (ctx: MeasureContext, domain: Domain, docs: Ref<Doc>[]) => Promise<void>
groupBy: <T>(ctx: MeasureContext, domain: Domain, field: string) => Promise<Set<T>>
// Bulk update operations
update: (ctx: MeasureContext, domain: Domain, operations: Map<Ref<Doc>, DocumentUpdate<Doc>>) => Promise<void>
+1 -1
View File
@@ -93,7 +93,7 @@ export class DomainIndexHelperImpl implements DomainHelper {
const added = new Set<string>()
try {
if (!operations.exists(domain)) {
if (!(await operations.exists(domain))) {
return
}
const has50Documents = documents > 50
+26 -2
View File
@@ -23,6 +23,7 @@ import core, {
type FindResult,
type Hierarchy,
type IndexingConfiguration,
type Iterator,
type MeasureContext,
ModelDb,
type Ref,
@@ -32,12 +33,25 @@ import core, {
type TxResult,
type WorkspaceId
} from '@hcengineering/core'
import { type DbAdapter, type DomainHelperOperations } from './adapter'
import { type DbAdapterHandler, type DbAdapter, type DomainHelperOperations } from './adapter'
/**
* @public
*/
export class DummyDbAdapter implements DbAdapter {
on?: ((handler: DbAdapterHandler) => void) | undefined
async traverse<T extends Doc>(
domain: Domain,
query: DocumentQuery<T>,
options?: Pick<FindOptions<T>, 'sort' | 'limit' | 'projection'>
): Promise<Iterator<T>> {
return {
next: async () => [],
close: async () => {}
}
}
async findAll<T extends Doc>(
ctx: MeasureContext,
_class: Ref<Class<T>>,
@@ -52,7 +66,7 @@ export class DummyDbAdapter implements DbAdapter {
helper (): DomainHelperOperations {
return {
create: async () => {},
exists: () => true,
exists: async () => true,
listDomains: async () => new Set(),
createIndex: async () => {},
dropIndex: async () => {},
@@ -90,6 +104,16 @@ export class DummyDbAdapter implements DbAdapter {
async groupBy<T>(ctx: MeasureContext, domain: Domain, field: string): Promise<Set<T>> {
return new Set()
}
async rawFindAll<T extends Doc>(domain: Domain, query: DocumentQuery<T>, options?: FindOptions<T>): Promise<T[]> {
return []
}
async rawUpdate<T extends Doc>(
domain: Domain,
query: DocumentQuery<T>,
operations: DocumentUpdate<T>
): Promise<void> {}
}
class InMemoryAdapter extends DummyDbAdapter implements DbAdapter {