@tanstack/db-sqlite-persistence-core 0.1.6 → 0.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/persisted.cjs +13 -3
- package/dist/cjs/persisted.cjs.map +1 -1
- package/dist/cjs/persisted.d.cts +16 -16
- package/dist/cjs/sqlite-core-adapter.cjs +6 -10
- package/dist/cjs/sqlite-core-adapter.cjs.map +1 -1
- package/dist/cjs/sqlite-core-adapter.d.cts +7 -7
- package/dist/esm/persisted.d.ts +16 -16
- package/dist/esm/persisted.js +13 -3
- package/dist/esm/persisted.js.map +1 -1
- package/dist/esm/sqlite-core-adapter.d.ts +7 -7
- package/dist/esm/sqlite-core-adapter.js +6 -10
- package/dist/esm/sqlite-core-adapter.js.map +1 -1
- package/package.json +2 -2
- package/src/persisted.ts +71 -81
- package/src/sqlite-core-adapter.ts +46 -50
|
@@ -19,7 +19,7 @@ export type SQLitePullSinceResult<TKey extends string | number> = {
|
|
|
19
19
|
deletedKeys: Array<TKey>;
|
|
20
20
|
deltas: Array<ReplayableTxDelta<Record<string, unknown>, TKey>>;
|
|
21
21
|
};
|
|
22
|
-
export declare class SQLiteCorePersistenceAdapter
|
|
22
|
+
export declare class SQLiteCorePersistenceAdapter implements PersistenceAdapter {
|
|
23
23
|
private readonly driver;
|
|
24
24
|
private readonly schemaVersion;
|
|
25
25
|
private readonly schemaMismatchPolicy;
|
|
@@ -34,16 +34,16 @@ export declare class SQLiteCorePersistenceAdapter<T extends object, TKey extends
|
|
|
34
34
|
loadSubset(collectionId: string, options: LoadSubsetOptions, ctx?: {
|
|
35
35
|
requiredIndexSignatures?: ReadonlyArray<string>;
|
|
36
36
|
}): Promise<Array<{
|
|
37
|
-
key:
|
|
38
|
-
value:
|
|
37
|
+
key: string | number;
|
|
38
|
+
value: Record<string, unknown>;
|
|
39
39
|
metadata?: unknown;
|
|
40
40
|
}>>;
|
|
41
|
-
applyCommittedTx(collectionId: string, tx: PersistedTx
|
|
41
|
+
applyCommittedTx(collectionId: string, tx: PersistedTx): Promise<void>;
|
|
42
42
|
loadCollectionMetadata(collectionId: string): Promise<Array<{
|
|
43
43
|
key: string;
|
|
44
44
|
value: unknown;
|
|
45
45
|
}>>;
|
|
46
|
-
scanRows(collectionId: string, options?: PersistedRowScanOptions): Promise<Array<PersistedScannedRow
|
|
46
|
+
scanRows(collectionId: string, options?: PersistedRowScanOptions): Promise<Array<PersistedScannedRow>>;
|
|
47
47
|
ensureIndex(collectionId: string, signature: string, spec: PersistedIndexSpec): Promise<void>;
|
|
48
48
|
markIndexRemoved(collectionId: string, signature: string): Promise<void>;
|
|
49
49
|
getStreamPosition(collectionId: string): Promise<{
|
|
@@ -51,7 +51,7 @@ export declare class SQLiteCorePersistenceAdapter<T extends object, TKey extends
|
|
|
51
51
|
latestSeq: number;
|
|
52
52
|
latestRowVersion: number;
|
|
53
53
|
}>;
|
|
54
|
-
pullSince(collectionId: string, fromRowVersion: number): Promise<SQLitePullSinceResult<
|
|
54
|
+
pullSince(collectionId: string, fromRowVersion: number): Promise<SQLitePullSinceResult<string | number>>;
|
|
55
55
|
private loadSubsetInternal;
|
|
56
56
|
private applyInMemoryWhere;
|
|
57
57
|
private applyInMemoryOrderBy;
|
|
@@ -63,5 +63,5 @@ export declare class SQLiteCorePersistenceAdapter<T extends object, TKey extends
|
|
|
63
63
|
private handleSchemaMismatch;
|
|
64
64
|
private ensureInitialized;
|
|
65
65
|
}
|
|
66
|
-
export declare function createSQLiteCorePersistenceAdapter
|
|
66
|
+
export declare function createSQLiteCorePersistenceAdapter(options: SQLiteCoreAdapterOptions): PersistenceAdapter;
|
|
67
67
|
export {};
|
package/dist/esm/persisted.d.ts
CHANGED
|
@@ -152,7 +152,7 @@ export type ReplayableTxDelta<T extends Record<string, unknown> = Record<string,
|
|
|
152
152
|
rowMetadataMutations: Array<PersistedRowMetadataMutation<TKey>>;
|
|
153
153
|
collectionMetadataMutations: Array<PersistedCollectionMetadataMutation>;
|
|
154
154
|
};
|
|
155
|
-
export type PersistedScannedRow<T extends object, TKey extends string | number = string | number> = {
|
|
155
|
+
export type PersistedScannedRow<T extends object = Record<string, unknown>, TKey extends string | number = string | number> = {
|
|
156
156
|
key: TKey;
|
|
157
157
|
value: T;
|
|
158
158
|
metadata?: unknown;
|
|
@@ -160,7 +160,7 @@ export type PersistedScannedRow<T extends object, TKey extends string | number =
|
|
|
160
160
|
export type PersistedRowScanOptions = {
|
|
161
161
|
metadataOnly?: boolean;
|
|
162
162
|
};
|
|
163
|
-
export type PersistedTx<T extends object, TKey extends string | number = string | number> = {
|
|
163
|
+
export type PersistedTx<T extends object = Record<string, unknown>, TKey extends string | number = string | number> = {
|
|
164
164
|
txId: string;
|
|
165
165
|
term: number;
|
|
166
166
|
seq: number;
|
|
@@ -186,20 +186,20 @@ export type PersistedTx<T extends object, TKey extends string | number = string
|
|
|
186
186
|
rowMetadataMutations?: Array<PersistedRowMetadataMutation<TKey>>;
|
|
187
187
|
collectionMetadataMutations?: Array<PersistedCollectionMetadataMutation>;
|
|
188
188
|
};
|
|
189
|
-
export interface PersistenceAdapter
|
|
189
|
+
export interface PersistenceAdapter {
|
|
190
190
|
loadSubset: (collectionId: string, options: LoadSubsetOptions, ctx?: {
|
|
191
191
|
requiredIndexSignatures?: ReadonlyArray<string>;
|
|
192
192
|
}) => Promise<Array<{
|
|
193
|
-
key:
|
|
194
|
-
value:
|
|
193
|
+
key: string | number;
|
|
194
|
+
value: Record<string, unknown>;
|
|
195
195
|
metadata?: unknown;
|
|
196
196
|
}>>;
|
|
197
|
-
applyCommittedTx: (collectionId: string, tx: PersistedTx
|
|
197
|
+
applyCommittedTx: (collectionId: string, tx: PersistedTx) => Promise<void>;
|
|
198
198
|
loadCollectionMetadata?: (collectionId: string) => Promise<Array<{
|
|
199
199
|
key: string;
|
|
200
200
|
value: unknown;
|
|
201
201
|
}>>;
|
|
202
|
-
scanRows?: (collectionId: string, options?: PersistedRowScanOptions) => Promise<Array<PersistedScannedRow
|
|
202
|
+
scanRows?: (collectionId: string, options?: PersistedRowScanOptions) => Promise<Array<PersistedScannedRow>>;
|
|
203
203
|
ensureIndex: (collectionId: string, signature: string, spec: PersistedIndexSpec) => Promise<void>;
|
|
204
204
|
markIndexRemoved?: (collectionId: string, signature: string) => Promise<void>;
|
|
205
205
|
getStreamPosition?: (collectionId: string) => Promise<{
|
|
@@ -226,17 +226,17 @@ export interface PersistedCollectionCoordinator {
|
|
|
226
226
|
requestApplyLocalMutations?: (collectionId: string, mutations: Array<PersistedMutationEnvelope>) => Promise<ApplyLocalMutationsResponse>;
|
|
227
227
|
pullSince?: (collectionId: string, fromRowVersion: number) => Promise<PullSinceResponse>;
|
|
228
228
|
}
|
|
229
|
-
export interface PersistedCollectionPersistence
|
|
230
|
-
adapter: PersistenceAdapter
|
|
229
|
+
export interface PersistedCollectionPersistence {
|
|
230
|
+
adapter: PersistenceAdapter;
|
|
231
231
|
coordinator?: PersistedCollectionCoordinator;
|
|
232
232
|
resolvePersistenceForCollection?: (options: {
|
|
233
233
|
collectionId: string;
|
|
234
234
|
mode: PersistedCollectionMode;
|
|
235
235
|
schemaVersion?: number;
|
|
236
|
-
}) => PersistedCollectionPersistence
|
|
237
|
-
resolvePersistenceForMode?: (mode: PersistedCollectionMode) => PersistedCollectionPersistence
|
|
236
|
+
}) => PersistedCollectionPersistence;
|
|
237
|
+
resolvePersistenceForMode?: (mode: PersistedCollectionMode) => PersistedCollectionPersistence;
|
|
238
238
|
}
|
|
239
|
-
type PersistedResolvedPersistence
|
|
239
|
+
type PersistedResolvedPersistence = PersistedCollectionPersistence & {
|
|
240
240
|
coordinator: PersistedCollectionCoordinator;
|
|
241
241
|
};
|
|
242
242
|
export type PersistedCollectionLeadershipState = {
|
|
@@ -252,19 +252,19 @@ export interface PersistedCollectionUtils extends UtilsRecord {
|
|
|
252
252
|
}
|
|
253
253
|
export type PersistedSyncWrappedOptions<T extends object, TKey extends string | number, TSchema extends StandardSchemaV1 = never, TUtils extends UtilsRecord = UtilsRecord> = CollectionConfig<T, TKey, TSchema, TUtils> & {
|
|
254
254
|
sync: SyncConfig<T, TKey>;
|
|
255
|
-
persistence: PersistedCollectionPersistence
|
|
255
|
+
persistence: PersistedCollectionPersistence;
|
|
256
256
|
schemaVersion?: number;
|
|
257
257
|
};
|
|
258
258
|
export type PersistedLocalOnlyOptions<T extends object, TKey extends string | number, TSchema extends StandardSchemaV1 = never, TUtils extends UtilsRecord = UtilsRecord> = Omit<CollectionConfig<T, TKey, TSchema, TUtils>, `sync`> & {
|
|
259
|
-
persistence: PersistedCollectionPersistence
|
|
259
|
+
persistence: PersistedCollectionPersistence;
|
|
260
260
|
schemaVersion?: number;
|
|
261
261
|
};
|
|
262
262
|
type PersistedSyncOptionsResult<T extends object, TKey extends string | number, TSchema extends StandardSchemaV1, TUtils extends UtilsRecord> = CollectionConfig<T, TKey, TSchema, TUtils> & {
|
|
263
|
-
persistence: PersistedResolvedPersistence
|
|
263
|
+
persistence: PersistedResolvedPersistence;
|
|
264
264
|
};
|
|
265
265
|
type PersistedLocalOnlyOptionsResult<T extends object, TKey extends string | number, TSchema extends StandardSchemaV1, TUtils extends UtilsRecord> = CollectionConfig<T, TKey, TSchema, TUtils & PersistedCollectionUtils> & {
|
|
266
266
|
id: string;
|
|
267
|
-
persistence: PersistedResolvedPersistence
|
|
267
|
+
persistence: PersistedResolvedPersistence;
|
|
268
268
|
utils: TUtils & PersistedCollectionUtils;
|
|
269
269
|
};
|
|
270
270
|
/**
|
package/dist/esm/persisted.js
CHANGED
|
@@ -510,7 +510,10 @@ class PersistedCollectionRuntime {
|
|
|
510
510
|
if (!this.persistence.adapter.scanRows) {
|
|
511
511
|
return [];
|
|
512
512
|
}
|
|
513
|
-
return this.persistence.adapter.scanRows(
|
|
513
|
+
return this.persistence.adapter.scanRows(
|
|
514
|
+
this.collectionId,
|
|
515
|
+
options
|
|
516
|
+
);
|
|
514
517
|
}
|
|
515
518
|
async scanPersistedRows(options) {
|
|
516
519
|
return this.applyMutex.run(() => this.scanPersistedRowsUnsafe(options));
|
|
@@ -657,7 +660,10 @@ class PersistedCollectionRuntime {
|
|
|
657
660
|
txId: tx.txId,
|
|
658
661
|
latestRowVersion: tx.rowVersion,
|
|
659
662
|
requiresFullReload: transaction.truncate,
|
|
660
|
-
changedRows: transaction.operations.filter((operation) => operation.type === `update`).map((operation) => ({
|
|
663
|
+
changedRows: transaction.operations.filter((operation) => operation.type === `update`).map((operation) => ({
|
|
664
|
+
key: operation.key,
|
|
665
|
+
value: operation.value
|
|
666
|
+
})),
|
|
661
667
|
deletedKeys: transaction.operations.filter((operation) => operation.type === `delete`).map((operation) => operation.key),
|
|
662
668
|
rowMetadataMutations: tx.rowMetadataMutations,
|
|
663
669
|
collectionMetadataMutations: tx.collectionMetadataMutations
|
|
@@ -685,7 +691,11 @@ class PersistedCollectionRuntime {
|
|
|
685
691
|
rowMetadataMutations: Array.from(
|
|
686
692
|
transaction.rowMetadataWrites.entries()
|
|
687
693
|
).map(
|
|
688
|
-
([key, metadataWrite]) => metadataWrite.type === `delete` ? { type: `delete`, key } : {
|
|
694
|
+
([key, metadataWrite]) => metadataWrite.type === `delete` ? { type: `delete`, key } : {
|
|
695
|
+
type: `set`,
|
|
696
|
+
key,
|
|
697
|
+
value: metadataWrite.value
|
|
698
|
+
}
|
|
689
699
|
),
|
|
690
700
|
collectionMetadataMutations: Array.from(
|
|
691
701
|
transaction.collectionMetadataWrites.entries()
|