diff --git a/packages/rxdb-db-collection/package.json b/packages/rxdb-db-collection/package.json index 1e90642d3..0cb237a82 100644 --- a/packages/rxdb-db-collection/package.json +++ b/packages/rxdb-db-collection/package.json @@ -35,6 +35,7 @@ "packageManager": "pnpm@10.18.1", "peerDependencies": { "rxdb": ">=16.17.2", + "rxjs": ">=7.8.2", "typescript": ">=4.7" }, "author": "Kyle Mathews", diff --git a/packages/rxdb-db-collection/src/helper.ts b/packages/rxdb-db-collection/src/helper.ts index 096005edd..151ca1fc8 100644 --- a/packages/rxdb-db-collection/src/helper.ts +++ b/packages/rxdb-db-collection/src/helper.ts @@ -5,11 +5,8 @@ const RESERVED_RXDB_FIELDS = new Set([ `_meta`, ]) -export function stripRxdbFields>( - obj: T | any -): T { - if (!obj) return obj - const out: any = Array.isArray(obj) ? [] : {} +export function stripRxdbFields>(obj: T): T { + const out: Record = {} for (const k of Object.keys(obj)) { if (RESERVED_RXDB_FIELDS.has(k)) continue out[k] = obj[k] diff --git a/packages/rxdb-db-collection/src/rxdb.ts b/packages/rxdb-db-collection/src/rxdb.ts index 6c1c12968..dfb1f9011 100644 --- a/packages/rxdb-db-collection/src/rxdb.ts +++ b/packages/rxdb-db-collection/src/rxdb.ts @@ -13,6 +13,7 @@ import type { RxCollection, RxDocumentData, } from "rxdb/plugins/core" +import type { Subscription } from "rxjs" import type { BaseCollectionConfig, @@ -27,7 +28,10 @@ const debug = DebugModule.debug(`ts/db:rxdb`) /** * Used in tests to ensure proper cleanup */ -export const OPEN_RXDB_SUBSCRIPTIONS = new WeakMap>() +export const OPEN_RXDB_SUBSCRIPTIONS = new WeakMap< + RxCollection, + Set +>() /** * Configuration interface for RxDB collection options @@ -106,7 +110,7 @@ export function rxdbCollectionOptions(config: RxDBCollectionConfig) { // "getKey" const primaryPath = rxCollection.schema.primaryPath - function getKey(item: any): string { + function getKey(item: Record): string { const key: string = item[primaryPath] as string return key } @@ -147,15 +151,16 @@ export function rxdbCollectionOptions(config: RxDBCollectionConfig) { }, }, ], - } as any, - sort: [{ "_meta.lwt": `asc` }, { [primaryPath]: `asc` } as any], + _deleted: false, + }, + sort: [{ "_meta.lwt": `asc` }, { [primaryPath]: `asc` }], limit: syncBatchSize, skip: 0, } } else { query = { - selector: {}, - sort: [{ "_meta.lwt": `asc` }, { [primaryPath]: `asc` } as any], + selector: { _deleted: false }, + sort: [{ "_meta.lwt": `asc` }, { [primaryPath]: `asc` }], limit: syncBatchSize, skip: 0, } @@ -198,11 +203,11 @@ export function rxdbCollectionOptions(config: RxDBCollectionConfig) { return } begin() - write(msg as any) + write(msg) commit() } - let sub: any + let sub: Subscription function startOngoingFetch() { // Subscribe early and buffer live changes during initial load and ongoing sub = rxCollection.$.subscribe((ev) => { @@ -234,7 +239,7 @@ export function rxdbCollectionOptions(config: RxDBCollectionConfig) { if (buffer.length) { begin() - for (const msg of buffer) write(msg as any) + for (const msg of buffer) write(msg) commit() buffer.length = 0 } @@ -258,14 +263,14 @@ export function rxdbCollectionOptions(config: RxDBCollectionConfig) { getSyncMetadata: undefined, } - const collectionConfig: CollectionConfig = { + const collectionConfig: CollectionConfig = { ...restConfig, - getKey: getKey as any, + getKey, sync, onInsert: async (params) => { debug(`insert`, params) const newItems = params.transaction.mutations.map((m) => m.modified) - return rxCollection.bulkUpsert(newItems as Array).then((result) => { + return rxCollection.bulkUpsert(newItems).then((result) => { if (result.error.length > 0) { throw rxStorageWriteErrorToRxError(ensureNotFalsy(result.error[0])) } @@ -285,7 +290,7 @@ export function rxdbCollectionOptions(config: RxDBCollectionConfig) { if (!doc) { continue } - await doc.incrementalPatch(newValue as any) + await doc.incrementalPatch(newValue) } }, onDelete: async (params) => { @@ -293,7 +298,7 @@ export function rxdbCollectionOptions(config: RxDBCollectionConfig) { const mutations = params.transaction.mutations.filter( (m) => m.type === `delete` ) - const ids = mutations.map((mutation: any) => getKey(mutation.original)) + const ids = mutations.map((mutation) => getKey(mutation.original)) return rxCollection.bulkRemove(ids).then((result) => { if (result.error.length > 0) { throw result.error diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index eb4e5b5b0..2c4e70314 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -720,6 +720,9 @@ importers: rxdb: specifier: 16.19.1 version: 16.19.1(rxjs@7.8.2)(socks@2.8.7) + rxjs: + specifier: '>=7.8.2' + version: 7.8.2 typescript: specifier: '>=4.7' version: 5.9.2