// // 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 FieldIndex, type FindOptions, type FindResult, type Hierarchy, type IndexingConfiguration, type MeasureContext, type ModelDb, type Ref, type StorageIterator, type Tx, type TxResult, type WorkspaceId } from '@hcengineering/core' import { type StorageAdapter } from './storage' export interface DomainHelperOperations { create: (domain: Domain) => Promise exists: (domain: Domain) => boolean createIndex: (domain: Domain, value: string | FieldIndex, options?: { name: string }) => Promise dropIndex: (domain: Domain, name: string) => Promise listIndexes: (domain: Domain) => Promise<{ name: string }[]> hasDocuments: (domain: Domain, count: number) => Promise } export interface DomainHelper { checkDomain: ( ctx: MeasureContext, domain: Domain, forceCreate: boolean, operations: DomainHelperOperations ) => Promise } export interface RawDBAdapterStream { next: () => Promise close: () => Promise } /** * @public */ export interface RawDBAdapter { find: ( ctx: MeasureContext, workspace: WorkspaceId, domain: Domain, query: DocumentQuery, options?: Omit, 'projection' | 'lookup'> ) => Promise> findStream: ( ctx: MeasureContext, workspace: WorkspaceId, domain: Domain, query: DocumentQuery, options?: Omit, 'projection' | 'lookup'> ) => Promise> upload: (ctx: MeasureContext, workspace: WorkspaceId, domain: Domain, docs: T[]) => Promise update: ( ctx: MeasureContext, workspace: WorkspaceId, domain: Domain, docs: Map, DocumentUpdate> ) => Promise clean: (ctx: MeasureContext, workspace: WorkspaceId, domain: Domain, docs: Ref[]) => Promise close: () => Promise } /** * @public */ export interface DbAdapter { init?: () => Promise helper?: () => DomainHelperOperations createIndexes: (domain: Domain, config: Pick, 'indexes'>) => Promise removeOldIndex: (domain: Domain, deletePattern: RegExp, keepPattern: RegExp) => Promise close: () => Promise findAll: ( ctx: MeasureContext, _class: Ref>, query: DocumentQuery, options?: FindOptions & { domain?: Domain // Allow to find for Doc's in specified domain only. } ) => Promise> tx: (ctx: MeasureContext, ...tx: Tx[]) => Promise find: (ctx: MeasureContext, domain: Domain, recheck?: boolean) => StorageIterator load: (ctx: MeasureContext, domain: Domain, docs: Ref[]) => Promise upload: (ctx: MeasureContext, domain: Domain, docs: Doc[]) => Promise clean: (ctx: MeasureContext, domain: Domain, docs: Ref[]) => Promise // Bulk update operations update: (ctx: MeasureContext, domain: Domain, operations: Map, DocumentUpdate>) => Promise } /** * @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