@tanstack/db 0.1.8 → 0.1.10
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 +29 -30
- package/dist/cjs/collection.cjs.map +1 -1
- package/dist/cjs/collection.d.cts +0 -1
- package/dist/cjs/proxy.cjs +9 -58
- package/dist/cjs/proxy.cjs.map +1 -1
- package/dist/cjs/query/builder/index.cjs +7 -4
- package/dist/cjs/query/builder/index.cjs.map +1 -1
- package/dist/cjs/query/compiler/group-by.cjs +7 -6
- package/dist/cjs/query/compiler/group-by.cjs.map +1 -1
- package/dist/cjs/query/compiler/group-by.d.cts +5 -1
- package/dist/cjs/query/compiler/index.cjs +1 -0
- package/dist/cjs/query/compiler/index.cjs.map +1 -1
- package/dist/cjs/query/compiler/order-by.cjs +13 -5
- package/dist/cjs/query/compiler/order-by.cjs.map +1 -1
- package/dist/cjs/query/compiler/order-by.d.cts +2 -2
- package/dist/cjs/query/live/collection-config-builder.cjs +3 -0
- package/dist/cjs/query/live/collection-config-builder.cjs.map +1 -1
- package/dist/cjs/query/live/collection-config-builder.d.cts +2 -2
- package/dist/cjs/utils.cjs +75 -0
- package/dist/cjs/utils.cjs.map +1 -1
- package/dist/cjs/utils.d.cts +5 -0
- package/dist/esm/collection.d.ts +0 -1
- package/dist/esm/collection.js +29 -30
- package/dist/esm/collection.js.map +1 -1
- package/dist/esm/proxy.js +9 -58
- package/dist/esm/proxy.js.map +1 -1
- package/dist/esm/query/builder/index.js +7 -4
- package/dist/esm/query/builder/index.js.map +1 -1
- package/dist/esm/query/compiler/group-by.d.ts +5 -1
- package/dist/esm/query/compiler/group-by.js +8 -7
- package/dist/esm/query/compiler/group-by.js.map +1 -1
- package/dist/esm/query/compiler/index.js +1 -0
- package/dist/esm/query/compiler/index.js.map +1 -1
- package/dist/esm/query/compiler/order-by.d.ts +2 -2
- package/dist/esm/query/compiler/order-by.js +13 -5
- package/dist/esm/query/compiler/order-by.js.map +1 -1
- package/dist/esm/query/live/collection-config-builder.d.ts +2 -2
- package/dist/esm/query/live/collection-config-builder.js +3 -0
- package/dist/esm/query/live/collection-config-builder.js.map +1 -1
- package/dist/esm/utils.d.ts +5 -0
- package/dist/esm/utils.js +76 -1
- package/dist/esm/utils.js.map +1 -1
- package/package.json +3 -2
- package/src/collection.ts +31 -35
- package/src/proxy.ts +16 -107
- package/src/query/builder/index.ts +11 -6
- package/src/query/compiler/group-by.ts +9 -8
- package/src/query/compiler/index.ts +1 -0
- package/src/query/compiler/order-by.ts +14 -5
- package/src/query/live/collection-config-builder.ts +7 -6
- package/src/utils.ts +125 -0
package/dist/esm/collection.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { withArrayChangeTracking, withChangeTracking } from "./proxy.js";
|
|
2
|
+
import { deepEquals } from "./utils.js";
|
|
2
3
|
import { SortedMap } from "./SortedMap.js";
|
|
3
4
|
import { createSingleRowRefProxy, toExpression } from "./query/builder/ref-proxy.js";
|
|
4
5
|
import { BTreeIndex } from "./indexes/btree-index.js";
|
|
@@ -59,13 +60,32 @@ class CollectionImpl {
|
|
|
59
60
|
break;
|
|
60
61
|
}
|
|
61
62
|
}
|
|
62
|
-
const
|
|
63
|
-
|
|
63
|
+
const {
|
|
64
|
+
committedSyncedTransactions,
|
|
65
|
+
uncommittedSyncedTransactions,
|
|
66
|
+
hasTruncateSync
|
|
67
|
+
} = this.pendingSyncedTransactions.reduce(
|
|
68
|
+
(acc, t) => {
|
|
69
|
+
if (t.committed) {
|
|
70
|
+
acc.committedSyncedTransactions.push(t);
|
|
71
|
+
if (t.truncate === true) {
|
|
72
|
+
acc.hasTruncateSync = true;
|
|
73
|
+
}
|
|
74
|
+
} else {
|
|
75
|
+
acc.uncommittedSyncedTransactions.push(t);
|
|
76
|
+
}
|
|
77
|
+
return acc;
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
committedSyncedTransactions: [],
|
|
81
|
+
uncommittedSyncedTransactions: [],
|
|
82
|
+
hasTruncateSync: false
|
|
83
|
+
}
|
|
64
84
|
);
|
|
65
85
|
if (!hasPersistingTransaction || hasTruncateSync) {
|
|
66
86
|
this.isCommittingSyncTransactions = true;
|
|
67
87
|
const changedKeys = /* @__PURE__ */ new Set();
|
|
68
|
-
for (const transaction of
|
|
88
|
+
for (const transaction of committedSyncedTransactions) {
|
|
69
89
|
for (const operation of transaction.operations) {
|
|
70
90
|
changedKeys.add(operation.key);
|
|
71
91
|
}
|
|
@@ -82,7 +102,7 @@ class CollectionImpl {
|
|
|
82
102
|
}
|
|
83
103
|
const events = [];
|
|
84
104
|
const rowUpdateMode = this.config.sync.rowUpdateMode || `partial`;
|
|
85
|
-
for (const transaction of
|
|
105
|
+
for (const transaction of committedSyncedTransactions) {
|
|
86
106
|
if (transaction.truncate) {
|
|
87
107
|
for (const key of this.syncedData.keys()) {
|
|
88
108
|
if (this.optimisticDeletes.has(key)) continue;
|
|
@@ -139,12 +159,9 @@ class CollectionImpl {
|
|
|
139
159
|
}
|
|
140
160
|
}
|
|
141
161
|
}
|
|
142
|
-
|
|
143
|
-
(t) => t.truncate === true
|
|
144
|
-
);
|
|
145
|
-
if (hadTruncate) {
|
|
162
|
+
if (hasTruncateSync) {
|
|
146
163
|
const syncedInsertedOrUpdatedKeys = /* @__PURE__ */ new Set();
|
|
147
|
-
for (const t of
|
|
164
|
+
for (const t of committedSyncedTransactions) {
|
|
148
165
|
for (const op of t.operations) {
|
|
149
166
|
if (op.type === `insert` || op.type === `update`) {
|
|
150
167
|
syncedInsertedOrUpdatedKeys.add(op.key);
|
|
@@ -253,7 +270,7 @@ class CollectionImpl {
|
|
|
253
270
|
const previousVisibleValue = currentVisibleState.get(key);
|
|
254
271
|
const newVisibleValue = this.get(key);
|
|
255
272
|
const completedOp = completedOptimisticOps.get(key);
|
|
256
|
-
const isRedundantSync = completedOp && newVisibleValue !== void 0 &&
|
|
273
|
+
const isRedundantSync = completedOp && newVisibleValue !== void 0 && deepEquals(completedOp.value, newVisibleValue);
|
|
257
274
|
if (!isRedundantSync) {
|
|
258
275
|
if (previousVisibleValue === void 0 && newVisibleValue !== void 0) {
|
|
259
276
|
events.push({
|
|
@@ -267,7 +284,7 @@ class CollectionImpl {
|
|
|
267
284
|
key,
|
|
268
285
|
value: previousVisibleValue
|
|
269
286
|
});
|
|
270
|
-
} else if (previousVisibleValue !== void 0 && newVisibleValue !== void 0 && !
|
|
287
|
+
} else if (previousVisibleValue !== void 0 && newVisibleValue !== void 0 && !deepEquals(previousVisibleValue, newVisibleValue)) {
|
|
271
288
|
events.push({
|
|
272
289
|
type: `update`,
|
|
273
290
|
key,
|
|
@@ -282,7 +299,7 @@ class CollectionImpl {
|
|
|
282
299
|
this.updateIndexes(events);
|
|
283
300
|
}
|
|
284
301
|
this.emitEvents(events, true);
|
|
285
|
-
this.pendingSyncedTransactions =
|
|
302
|
+
this.pendingSyncedTransactions = uncommittedSyncedTransactions;
|
|
286
303
|
this.preSyncVisibleState.clear();
|
|
287
304
|
Promise.resolve().then(() => {
|
|
288
305
|
this.recentlySyncedKeys.clear();
|
|
@@ -1193,24 +1210,6 @@ class CollectionImpl {
|
|
|
1193
1210
|
}
|
|
1194
1211
|
}
|
|
1195
1212
|
}
|
|
1196
|
-
deepEqual(a, b) {
|
|
1197
|
-
if (a === b) return true;
|
|
1198
|
-
if (a == null || b == null) return false;
|
|
1199
|
-
if (typeof a !== typeof b) return false;
|
|
1200
|
-
if (typeof a === `object`) {
|
|
1201
|
-
if (Array.isArray(a) !== Array.isArray(b)) return false;
|
|
1202
|
-
const keysA = Object.keys(a);
|
|
1203
|
-
const keysB = Object.keys(b);
|
|
1204
|
-
if (keysA.length !== keysB.length) return false;
|
|
1205
|
-
const keysBSet = new Set(keysB);
|
|
1206
|
-
for (const key of keysA) {
|
|
1207
|
-
if (!keysBSet.has(key)) return false;
|
|
1208
|
-
if (!this.deepEqual(a[key], b[key])) return false;
|
|
1209
|
-
}
|
|
1210
|
-
return true;
|
|
1211
|
-
}
|
|
1212
|
-
return false;
|
|
1213
|
-
}
|
|
1214
1213
|
validateData(data, type, key) {
|
|
1215
1214
|
if (!this.config.schema) return data;
|
|
1216
1215
|
const standardSchema = this.ensureStandardSchema(this.config.schema);
|