// // Copyright © 2022 Hardcore Engineering Inc. // // Licensed under the Eclipse Public License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. You may // obtain a copy of the License at https://www.eclipse.org/legal/epl-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // // See the License for the specific language governing permissions and // limitations under the License. // import { type Class, type Doc, type DocumentQuery, type DocumentUpdate, type Domain, type FieldIndexConfig, type FindResult, type Hierarchy, type LowLevelStorage, type MeasureContext, type ModelDb, type Ref, type Tx, type TxResult, type WorkspaceId } from '@hcengineering/core' import { type StorageAdapter } from './storage' import type { ServerFindOptions } from './types' export interface DomainHelperOperations { create: (domain: Domain) => Promise exists: (domain: Domain) => Promise listDomains: () => Promise> createIndex: (domain: Domain, value: string | FieldIndexConfig, options?: { name: string }) => Promise dropIndex: (domain: Domain, name: string) => Promise listIndexes: (domain: Domain) => Promise<{ name: string }[]> // Could return 0 even if it has documents estimatedCount: (domain: Domain) => Promise } export interface DomainHelper { checkDomain: ( ctx: MeasureContext, domain: Domain, documents: number, operations: DomainHelperOperations ) => Promise } export type DbAdapterHandler = ( domain: Domain, event: 'add' | 'update' | 'delete' | 'read', count: number, helper: DomainHelperOperations ) => void /** * @public */ export interface DbAdapter extends LowLevelStorage { init?: (domains?: string[], excludeDomains?: string[]) => Promise helper?: () => DomainHelperOperations close: () => Promise findAll: ( ctx: MeasureContext, _class: Ref>, query: DocumentQuery, options?: ServerFindOptions ) => Promise> tx: (ctx: MeasureContext, ...tx: Tx[]) => Promise // Bulk update operations update: (ctx: MeasureContext, domain: Domain, operations: Map, DocumentUpdate>) => Promise // Allow to register a handler to listen for domain operations on?: (handler: DbAdapterHandler) => void } /** * @public */ export interface TxAdapter extends DbAdapter { getModel: (ctx: MeasureContext) => Promise } /** * @public */ export type DbAdapterFactory = ( ctx: MeasureContext, hierarchy: Hierarchy, url: string, workspaceId: WorkspaceId, modelDb: ModelDb, storage: StorageAdapter ) => Promise