@tanstack/db 0.0.33 → 0.1.1
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/collection.cjs +22 -12
- package/dist/cjs/collection.cjs.map +1 -1
- package/dist/cjs/collection.d.cts +6 -1
- package/dist/cjs/local-only.cjs.map +1 -1
- package/dist/cjs/local-only.d.cts +2 -14
- package/dist/cjs/local-storage.cjs.map +1 -1
- package/dist/cjs/local-storage.d.cts +3 -14
- package/dist/cjs/query/compiler/group-by.cjs +10 -10
- package/dist/cjs/query/compiler/group-by.cjs.map +1 -1
- package/dist/cjs/query/compiler/index.cjs +11 -11
- package/dist/cjs/query/compiler/index.cjs.map +1 -1
- package/dist/cjs/query/compiler/joins.cjs +8 -8
- package/dist/cjs/query/compiler/joins.cjs.map +1 -1
- package/dist/cjs/query/compiler/order-by.cjs +2 -2
- package/dist/cjs/query/compiler/order-by.cjs.map +1 -1
- package/dist/cjs/query/compiler/order-by.d.cts +1 -1
- package/dist/cjs/query/compiler/select.cjs +2 -2
- package/dist/cjs/query/compiler/select.cjs.map +1 -1
- package/dist/cjs/query/live-query-collection.cjs +4 -4
- package/dist/cjs/query/live-query-collection.cjs.map +1 -1
- package/dist/cjs/transactions.cjs +1 -0
- package/dist/cjs/transactions.cjs.map +1 -1
- package/dist/cjs/types.d.cts +1 -1
- package/dist/esm/collection.d.ts +6 -1
- package/dist/esm/collection.js +22 -12
- package/dist/esm/collection.js.map +1 -1
- package/dist/esm/local-only.d.ts +2 -14
- package/dist/esm/local-only.js.map +1 -1
- package/dist/esm/local-storage.d.ts +3 -14
- package/dist/esm/local-storage.js.map +1 -1
- package/dist/esm/query/compiler/group-by.js +1 -1
- package/dist/esm/query/compiler/group-by.js.map +1 -1
- package/dist/esm/query/compiler/index.js +1 -1
- package/dist/esm/query/compiler/index.js.map +1 -1
- package/dist/esm/query/compiler/joins.js +1 -1
- package/dist/esm/query/compiler/joins.js.map +1 -1
- package/dist/esm/query/compiler/order-by.d.ts +1 -1
- package/dist/esm/query/compiler/order-by.js +1 -1
- package/dist/esm/query/compiler/order-by.js.map +1 -1
- package/dist/esm/query/compiler/select.js +1 -1
- package/dist/esm/query/compiler/select.js.map +1 -1
- package/dist/esm/query/live-query-collection.js +1 -1
- package/dist/esm/query/live-query-collection.js.map +1 -1
- package/dist/esm/transactions.js +1 -0
- package/dist/esm/transactions.js.map +1 -1
- package/dist/esm/types.d.ts +1 -1
- package/package.json +3 -3
- package/src/collection.ts +34 -15
- package/src/local-only.ts +6 -1
- package/src/local-storage.ts +6 -1
- package/src/query/compiler/group-by.ts +1 -1
- package/src/query/compiler/index.ts +1 -1
- package/src/query/compiler/joins.ts +2 -2
- package/src/query/compiler/order-by.ts +2 -2
- package/src/query/compiler/select.ts +1 -1
- package/src/query/live-query-collection.ts +2 -2
- package/src/transactions.ts +1 -0
- package/src/types.ts +1 -1
package/dist/esm/collection.d.ts
CHANGED
|
@@ -289,6 +289,11 @@ export declare class CollectionImpl<T extends object = Record<string, unknown>,
|
|
|
289
289
|
* This method processes operations from pending transactions and applies them to the synced data
|
|
290
290
|
*/
|
|
291
291
|
commitPendingTransactions: () => void;
|
|
292
|
+
/**
|
|
293
|
+
* Schedule cleanup of a transaction when it completes
|
|
294
|
+
* @private
|
|
295
|
+
*/
|
|
296
|
+
private scheduleTransactionCleanup;
|
|
292
297
|
private ensureStandardSchema;
|
|
293
298
|
getKeyFromItem(item: T): TKey;
|
|
294
299
|
generateGlobalKey(key: any, item: any): string;
|
|
@@ -343,7 +348,7 @@ export declare class CollectionImpl<T extends object = Record<string, unknown>,
|
|
|
343
348
|
*/
|
|
344
349
|
private updateIndexes;
|
|
345
350
|
private deepEqual;
|
|
346
|
-
|
|
351
|
+
validateData(data: unknown, type: `insert` | `update`, key?: TKey): T | never;
|
|
347
352
|
/**
|
|
348
353
|
* Inserts one or more items into the collection
|
|
349
354
|
* @param items - Single item or array of items to insert
|
package/dist/esm/collection.js
CHANGED
|
@@ -252,6 +252,7 @@ class CollectionImpl {
|
|
|
252
252
|
if (ambientTransaction) {
|
|
253
253
|
ambientTransaction.applyMutations(mutations);
|
|
254
254
|
this.transactions.set(ambientTransaction.id, ambientTransaction);
|
|
255
|
+
this.scheduleTransactionCleanup(ambientTransaction);
|
|
255
256
|
this.recomputeOptimisticState(true);
|
|
256
257
|
return ambientTransaction;
|
|
257
258
|
} else {
|
|
@@ -266,6 +267,7 @@ class CollectionImpl {
|
|
|
266
267
|
directOpTransaction.applyMutations(mutations);
|
|
267
268
|
directOpTransaction.commit();
|
|
268
269
|
this.transactions.set(directOpTransaction.id, directOpTransaction);
|
|
270
|
+
this.scheduleTransactionCleanup(directOpTransaction);
|
|
269
271
|
this.recomputeOptimisticState(true);
|
|
270
272
|
return directOpTransaction;
|
|
271
273
|
}
|
|
@@ -306,6 +308,7 @@ class CollectionImpl {
|
|
|
306
308
|
if (ambientTransaction) {
|
|
307
309
|
ambientTransaction.applyMutations(mutations);
|
|
308
310
|
this.transactions.set(ambientTransaction.id, ambientTransaction);
|
|
311
|
+
this.scheduleTransactionCleanup(ambientTransaction);
|
|
309
312
|
this.recomputeOptimisticState(true);
|
|
310
313
|
return ambientTransaction;
|
|
311
314
|
}
|
|
@@ -321,6 +324,7 @@ class CollectionImpl {
|
|
|
321
324
|
directOpTransaction.applyMutations(mutations);
|
|
322
325
|
directOpTransaction.commit();
|
|
323
326
|
this.transactions.set(directOpTransaction.id, directOpTransaction);
|
|
327
|
+
this.scheduleTransactionCleanup(directOpTransaction);
|
|
324
328
|
this.recomputeOptimisticState(true);
|
|
325
329
|
return directOpTransaction;
|
|
326
330
|
};
|
|
@@ -661,11 +665,8 @@ class CollectionImpl {
|
|
|
661
665
|
this.optimisticUpserts.clear();
|
|
662
666
|
this.optimisticDeletes.clear();
|
|
663
667
|
const activeTransactions = [];
|
|
664
|
-
const completedTransactions = [];
|
|
665
668
|
for (const transaction of this.transactions.values()) {
|
|
666
|
-
if (transaction.state
|
|
667
|
-
completedTransactions.push(transaction);
|
|
668
|
-
} else if (![`completed`, `failed`].includes(transaction.state)) {
|
|
669
|
+
if (![`completed`, `failed`].includes(transaction.state)) {
|
|
669
670
|
activeTransactions.push(transaction);
|
|
670
671
|
}
|
|
671
672
|
}
|
|
@@ -700,19 +701,11 @@ class CollectionImpl {
|
|
|
700
701
|
});
|
|
701
702
|
if (this.pendingSyncedTransactions.length > 0 && !triggeredByUserAction) {
|
|
702
703
|
const pendingSyncKeys = /* @__PURE__ */ new Set();
|
|
703
|
-
const completedTransactionMutations = /* @__PURE__ */ new Set();
|
|
704
704
|
for (const transaction of this.pendingSyncedTransactions) {
|
|
705
705
|
for (const operation of transaction.operations) {
|
|
706
706
|
pendingSyncKeys.add(operation.key);
|
|
707
707
|
}
|
|
708
708
|
}
|
|
709
|
-
for (const tx of completedTransactions) {
|
|
710
|
-
for (const mutation of tx.mutations) {
|
|
711
|
-
if (mutation.collection === this) {
|
|
712
|
-
completedTransactionMutations.add(mutation.mutationId);
|
|
713
|
-
}
|
|
714
|
-
}
|
|
715
|
-
}
|
|
716
709
|
const filteredEvents = filteredEventsBySyncStatus.filter((event) => {
|
|
717
710
|
if (event.type === `delete` && pendingSyncKeys.has(event.key)) {
|
|
718
711
|
const hasActiveOptimisticMutation = activeTransactions.some(
|
|
@@ -933,6 +926,20 @@ class CollectionImpl {
|
|
|
933
926
|
}
|
|
934
927
|
return result;
|
|
935
928
|
}
|
|
929
|
+
/**
|
|
930
|
+
* Schedule cleanup of a transaction when it completes
|
|
931
|
+
* @private
|
|
932
|
+
*/
|
|
933
|
+
scheduleTransactionCleanup(transaction) {
|
|
934
|
+
if (transaction.state === `completed`) {
|
|
935
|
+
this.transactions.delete(transaction.id);
|
|
936
|
+
return;
|
|
937
|
+
}
|
|
938
|
+
transaction.isPersisted.promise.then(() => {
|
|
939
|
+
this.transactions.delete(transaction.id);
|
|
940
|
+
}).catch(() => {
|
|
941
|
+
});
|
|
942
|
+
}
|
|
936
943
|
ensureStandardSchema(schema) {
|
|
937
944
|
if (schema && `~standard` in schema) {
|
|
938
945
|
return schema;
|
|
@@ -1213,11 +1220,13 @@ class CollectionImpl {
|
|
|
1213
1220
|
}
|
|
1214
1221
|
});
|
|
1215
1222
|
emptyTransaction.commit();
|
|
1223
|
+
this.scheduleTransactionCleanup(emptyTransaction);
|
|
1216
1224
|
return emptyTransaction;
|
|
1217
1225
|
}
|
|
1218
1226
|
if (ambientTransaction) {
|
|
1219
1227
|
ambientTransaction.applyMutations(mutations);
|
|
1220
1228
|
this.transactions.set(ambientTransaction.id, ambientTransaction);
|
|
1229
|
+
this.scheduleTransactionCleanup(ambientTransaction);
|
|
1221
1230
|
this.recomputeOptimisticState(true);
|
|
1222
1231
|
return ambientTransaction;
|
|
1223
1232
|
}
|
|
@@ -1232,6 +1241,7 @@ class CollectionImpl {
|
|
|
1232
1241
|
directOpTransaction.applyMutations(mutations);
|
|
1233
1242
|
directOpTransaction.commit();
|
|
1234
1243
|
this.transactions.set(directOpTransaction.id, directOpTransaction);
|
|
1244
|
+
this.scheduleTransactionCleanup(directOpTransaction);
|
|
1235
1245
|
this.recomputeOptimisticState(true);
|
|
1236
1246
|
return directOpTransaction;
|
|
1237
1247
|
}
|