diff --git a/packages/inmemory/src/inMemoryStorage/instance.ts b/packages/inmemory/src/inMemoryStorage/instance.ts index 15704a14..674d87f8 100644 --- a/packages/inmemory/src/inMemoryStorage/instance.ts +++ b/packages/inmemory/src/inMemoryStorage/instance.ts @@ -8,16 +8,16 @@ import { fixTxPipe } from '@pluto-encrypted/shared' import { type QueryMatcher } from 'rxdb/dist/types/types' export class RxStorageIntanceInMemory implements RxStorageInstance< -RxDocType, -InMemoryStorageInternals, -InMemorySettings, -RxStorageDefaultCheckpoint> { + RxDocType, + InMemoryStorageInternals, + InMemorySettings, + RxStorageDefaultCheckpoint> { public readonly primaryPath: StringKeys> public conflictResultionTasks$ = new Subject>() public changes$ = new Subject>, RxStorageDefaultCheckpoint>>() public closed: boolean = false - constructor ( + constructor( public readonly storage: RxStorageInMemoryType, public readonly databaseName: string, public readonly collectionName: string, @@ -28,7 +28,7 @@ RxStorageDefaultCheckpoint> { this.primaryPath = getPrimaryFieldOfPrimaryKey(this.schema.primaryKey) } - async bulkWrite ( + async bulkWrite( documentWrites: Array>, context: string): Promise> { const primaryPath = this.primaryPath @@ -42,8 +42,17 @@ RxStorageDefaultCheckpoint> { const currentId = currentWriteDoc.document[this.primaryPath] as any const previousDocument = currentWriteDoc.previous ?? this.internals.documents.get(currentId) if (context === 'data-migrator-delete') { - if (previousDocument && previousDocument._rev === currentWriteDoc.document._rev) { - fixedDocs.push(currentWriteDoc) + if (previousDocument) { + fixedDocs.push({ + document: { + ...previousDocument, + _deleted: true + }, + previous: { + ...previousDocument, + _deleted: false + } + }); } } else { if (previousDocument && previousDocument._rev !== currentWriteDoc.document._rev) { @@ -100,11 +109,11 @@ RxStorageDefaultCheckpoint> { return await Promise.resolve(ret) } - async findDocumentsById (ids: string[], withDeleted: boolean): Promise> { + async findDocumentsById(ids: string[], withDeleted: boolean): Promise> { return this.internals.bulkGet(ids, withDeleted) } - async query (preparedQuery: InMemoryPreparedQuery): Promise> { + async query(preparedQuery: InMemoryPreparedQuery): Promise> { const { queryPlan, query } = preparedQuery const selector = query.selector const selectorKeys = Object.keys(selector) @@ -175,7 +184,7 @@ RxStorageDefaultCheckpoint> { } } - async count (preparedQuery: any): Promise { + async count(preparedQuery: any): Promise { const result = await this.query(preparedQuery) return { count: result.documents.length, @@ -184,28 +193,28 @@ RxStorageDefaultCheckpoint> { } /* istanbul ignore next */ - async getAttachmentData (): Promise { + async getAttachmentData(): Promise { throw new Error('Method not implemented.') } /* istanbul ignore next */ - async getChangedDocumentsSince (): Promise<{ documents: Array>, checkpoint: RxStorageDefaultCheckpoint }> { + async getChangedDocumentsSince(): Promise<{ documents: Array>, checkpoint: RxStorageDefaultCheckpoint }> { throw new Error('Method not implemented.') } /* istanbul ignore next */ - changeStream (): Observable, RxStorageDefaultCheckpoint>> { + changeStream(): Observable, RxStorageDefaultCheckpoint>> { return this.changes$.asObservable() } - async cleanup (): Promise { + async cleanup(): Promise { this.internals.clear() return true } /* istanbul ignore next */ - async close (): Promise { + async close(): Promise { if (this.closed) { await Promise.reject(new Error('already closed')); return } @@ -215,16 +224,16 @@ RxStorageDefaultCheckpoint> { } /* istanbul ignore next */ - async remove (): Promise { + async remove(): Promise { await Promise.resolve() } - conflictResultionTasks (): Observable> { + conflictResultionTasks(): Observable> { return this.conflictResultionTasks$.asObservable() } /* istanbul ignore next */ - async resolveConflictResultionTask (): Promise { + async resolveConflictResultionTask(): Promise { await Promise.resolve() } }