Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/rxdb-db-collection/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"packageManager": "[email protected]",
"peerDependencies": {
"rxdb": ">=16.17.2",
"rxjs": ">=7.8.2",
"typescript": ">=4.7"
},
"author": "Kyle Mathews",
Expand Down
7 changes: 2 additions & 5 deletions packages/rxdb-db-collection/src/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@ const RESERVED_RXDB_FIELDS = new Set([
`_meta`,
])

export function stripRxdbFields<T extends Record<string, any>>(
obj: T | any
): T {
if (!obj) return obj
const out: any = Array.isArray(obj) ? [] : {}
export function stripRxdbFields<T extends Record<string, unknown>>(obj: T): T {
const out: Record<string, unknown> = {}
for (const k of Object.keys(obj)) {
if (RESERVED_RXDB_FIELDS.has(k)) continue
out[k] = obj[k]
Expand Down
33 changes: 19 additions & 14 deletions packages/rxdb-db-collection/src/rxdb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import type {
RxCollection,
RxDocumentData,
} from "rxdb/plugins/core"
import type { Subscription } from "rxjs"

import type {
BaseCollectionConfig,
Expand All @@ -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<RxCollection, Set<any>>()
export const OPEN_RXDB_SUBSCRIPTIONS = new WeakMap<
RxCollection,
Set<Subscription>
>()

/**
* Configuration interface for RxDB collection options
Expand Down Expand Up @@ -106,7 +110,7 @@ export function rxdbCollectionOptions(config: RxDBCollectionConfig<any, any>) {

// "getKey"
const primaryPath = rxCollection.schema.primaryPath
function getKey(item: any): string {
function getKey(item: Record<string, unknown>): string {
const key: string = item[primaryPath] as string
return key
}
Expand Down Expand Up @@ -147,15 +151,16 @@ export function rxdbCollectionOptions(config: RxDBCollectionConfig<any, any>) {
},
},
],
} 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,
}
Expand Down Expand Up @@ -198,11 +203,11 @@ export function rxdbCollectionOptions(config: RxDBCollectionConfig<any, any>) {
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) => {
Expand Down Expand Up @@ -234,7 +239,7 @@ export function rxdbCollectionOptions(config: RxDBCollectionConfig<any, any>) {

if (buffer.length) {
begin()
for (const msg of buffer) write(msg as any)
for (const msg of buffer) write(msg)
commit()
buffer.length = 0
}
Expand All @@ -258,14 +263,14 @@ export function rxdbCollectionOptions(config: RxDBCollectionConfig<any, any>) {
getSyncMetadata: undefined,
}

const collectionConfig: CollectionConfig<Row, string, any> = {
const collectionConfig: CollectionConfig<Row, string> = {
...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<any>).then((result) => {
return rxCollection.bulkUpsert(newItems).then((result) => {
if (result.error.length > 0) {
throw rxStorageWriteErrorToRxError(ensureNotFalsy(result.error[0]))
}
Expand All @@ -285,15 +290,15 @@ export function rxdbCollectionOptions(config: RxDBCollectionConfig<any, any>) {
if (!doc) {
continue
}
await doc.incrementalPatch(newValue as any)
await doc.incrementalPatch(newValue)
}
},
onDelete: async (params) => {
debug(`delete`, params)
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
Expand Down
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading