import type { FilledMangoQuery, RxDocumentData, RxJsonSchema, RxStorage, RxStorageInstanceCreationParams, RxStorageStatics } from 'nxdb-old/src/types'; import { ensureRxStorageInstanceParamsAreCorrect } from 'nxdb-old/src/rx-storage-helper'; import { DEFAULT_CHECKPOINT_SCHEMA, getPrimaryFieldOfPrimaryKey } from 'nxdb-old/src/rx-schema-helper'; import { RX_STORAGE_NAME_MONGODB, primarySwapMongoDBQuerySelector, swapToMongoSort } from 'nxdb-old/src/plugins/storage-mongodb/mongodb-helper'; import type { MongoDBDatabaseSettings, MongoDBPreparedQuery, MongoDBSettings, MongoDBStorageInternals } from 'nxdb-old/src/plugins/storage-mongodb/mongodb-types'; import { RxStorageInstanceMongoDB, createMongoDBStorageInstance } from 'nxdb-old/src/plugins/storage-mongodb/rx-storage-instance-mongodb'; export const RxStorageMongoDBStatics: RxStorageStatics = { prepareQuery( schema: RxJsonSchema>, mutateableQuery: FilledMangoQuery ) { const primaryKey = getPrimaryFieldOfPrimaryKey(schema.primaryKey) as any; const preparedQuery: MongoDBPreparedQuery = { query: mutateableQuery, mongoSelector: primarySwapMongoDBQuerySelector( primaryKey, mutateableQuery.selector ), mongoSort: swapToMongoSort(mutateableQuery.sort) }; return preparedQuery; }, checkpointSchema: DEFAULT_CHECKPOINT_SCHEMA }; export class RxStorageMongoDB implements RxStorage { public name = RX_STORAGE_NAME_MONGODB; public statics = RxStorageMongoDBStatics; constructor( public databaseSettings: MongoDBDatabaseSettings ) { } public createStorageInstance( params: RxStorageInstanceCreationParams ): Promise> { ensureRxStorageInstanceParamsAreCorrect(params); return createMongoDBStorageInstance(this, params, this.databaseSettings); } } export function getRxStorageMongoDB( databaseSettings: MongoDBDatabaseSettings ): RxStorageMongoDB { const storage = new RxStorageMongoDB(databaseSettings); return storage; }