@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/cjs/collection.cjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const proxy = require("./proxy.cjs");
|
|
4
|
+
const utils = require("./utils.cjs");
|
|
4
5
|
const SortedMap = require("./SortedMap.cjs");
|
|
5
6
|
const refProxy = require("./query/builder/ref-proxy.cjs");
|
|
6
7
|
const btreeIndex = require("./indexes/btree-index.cjs");
|
|
@@ -61,13 +62,32 @@ class CollectionImpl {
|
|
|
61
62
|
break;
|
|
62
63
|
}
|
|
63
64
|
}
|
|
64
|
-
const
|
|
65
|
-
|
|
65
|
+
const {
|
|
66
|
+
committedSyncedTransactions,
|
|
67
|
+
uncommittedSyncedTransactions,
|
|
68
|
+
hasTruncateSync
|
|
69
|
+
} = this.pendingSyncedTransactions.reduce(
|
|
70
|
+
(acc, t) => {
|
|
71
|
+
if (t.committed) {
|
|
72
|
+
acc.committedSyncedTransactions.push(t);
|
|
73
|
+
if (t.truncate === true) {
|
|
74
|
+
acc.hasTruncateSync = true;
|
|
75
|
+
}
|
|
76
|
+
} else {
|
|
77
|
+
acc.uncommittedSyncedTransactions.push(t);
|
|
78
|
+
}
|
|
79
|
+
return acc;
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
committedSyncedTransactions: [],
|
|
83
|
+
uncommittedSyncedTransactions: [],
|
|
84
|
+
hasTruncateSync: false
|
|
85
|
+
}
|
|
66
86
|
);
|
|
67
87
|
if (!hasPersistingTransaction || hasTruncateSync) {
|
|
68
88
|
this.isCommittingSyncTransactions = true;
|
|
69
89
|
const changedKeys = /* @__PURE__ */ new Set();
|
|
70
|
-
for (const transaction of
|
|
90
|
+
for (const transaction of committedSyncedTransactions) {
|
|
71
91
|
for (const operation of transaction.operations) {
|
|
72
92
|
changedKeys.add(operation.key);
|
|
73
93
|
}
|
|
@@ -84,7 +104,7 @@ class CollectionImpl {
|
|
|
84
104
|
}
|
|
85
105
|
const events = [];
|
|
86
106
|
const rowUpdateMode = this.config.sync.rowUpdateMode || `partial`;
|
|
87
|
-
for (const transaction of
|
|
107
|
+
for (const transaction of committedSyncedTransactions) {
|
|
88
108
|
if (transaction.truncate) {
|
|
89
109
|
for (const key of this.syncedData.keys()) {
|
|
90
110
|
if (this.optimisticDeletes.has(key)) continue;
|
|
@@ -141,12 +161,9 @@ class CollectionImpl {
|
|
|
141
161
|
}
|
|
142
162
|
}
|
|
143
163
|
}
|
|
144
|
-
|
|
145
|
-
(t) => t.truncate === true
|
|
146
|
-
);
|
|
147
|
-
if (hadTruncate) {
|
|
164
|
+
if (hasTruncateSync) {
|
|
148
165
|
const syncedInsertedOrUpdatedKeys = /* @__PURE__ */ new Set();
|
|
149
|
-
for (const t of
|
|
166
|
+
for (const t of committedSyncedTransactions) {
|
|
150
167
|
for (const op of t.operations) {
|
|
151
168
|
if (op.type === `insert` || op.type === `update`) {
|
|
152
169
|
syncedInsertedOrUpdatedKeys.add(op.key);
|
|
@@ -255,7 +272,7 @@ class CollectionImpl {
|
|
|
255
272
|
const previousVisibleValue = currentVisibleState.get(key);
|
|
256
273
|
const newVisibleValue = this.get(key);
|
|
257
274
|
const completedOp = completedOptimisticOps.get(key);
|
|
258
|
-
const isRedundantSync = completedOp && newVisibleValue !== void 0 &&
|
|
275
|
+
const isRedundantSync = completedOp && newVisibleValue !== void 0 && utils.deepEquals(completedOp.value, newVisibleValue);
|
|
259
276
|
if (!isRedundantSync) {
|
|
260
277
|
if (previousVisibleValue === void 0 && newVisibleValue !== void 0) {
|
|
261
278
|
events.push({
|
|
@@ -269,7 +286,7 @@ class CollectionImpl {
|
|
|
269
286
|
key,
|
|
270
287
|
value: previousVisibleValue
|
|
271
288
|
});
|
|
272
|
-
} else if (previousVisibleValue !== void 0 && newVisibleValue !== void 0 && !
|
|
289
|
+
} else if (previousVisibleValue !== void 0 && newVisibleValue !== void 0 && !utils.deepEquals(previousVisibleValue, newVisibleValue)) {
|
|
273
290
|
events.push({
|
|
274
291
|
type: `update`,
|
|
275
292
|
key,
|
|
@@ -284,7 +301,7 @@ class CollectionImpl {
|
|
|
284
301
|
this.updateIndexes(events);
|
|
285
302
|
}
|
|
286
303
|
this.emitEvents(events, true);
|
|
287
|
-
this.pendingSyncedTransactions =
|
|
304
|
+
this.pendingSyncedTransactions = uncommittedSyncedTransactions;
|
|
288
305
|
this.preSyncVisibleState.clear();
|
|
289
306
|
Promise.resolve().then(() => {
|
|
290
307
|
this.recentlySyncedKeys.clear();
|
|
@@ -1195,24 +1212,6 @@ class CollectionImpl {
|
|
|
1195
1212
|
}
|
|
1196
1213
|
}
|
|
1197
1214
|
}
|
|
1198
|
-
deepEqual(a, b) {
|
|
1199
|
-
if (a === b) return true;
|
|
1200
|
-
if (a == null || b == null) return false;
|
|
1201
|
-
if (typeof a !== typeof b) return false;
|
|
1202
|
-
if (typeof a === `object`) {
|
|
1203
|
-
if (Array.isArray(a) !== Array.isArray(b)) return false;
|
|
1204
|
-
const keysA = Object.keys(a);
|
|
1205
|
-
const keysB = Object.keys(b);
|
|
1206
|
-
if (keysA.length !== keysB.length) return false;
|
|
1207
|
-
const keysBSet = new Set(keysB);
|
|
1208
|
-
for (const key of keysA) {
|
|
1209
|
-
if (!keysBSet.has(key)) return false;
|
|
1210
|
-
if (!this.deepEqual(a[key], b[key])) return false;
|
|
1211
|
-
}
|
|
1212
|
-
return true;
|
|
1213
|
-
}
|
|
1214
|
-
return false;
|
|
1215
|
-
}
|
|
1216
1215
|
validateData(data, type, key) {
|
|
1217
1216
|
if (!this.config.schema) return data;
|
|
1218
1217
|
const standardSchema = this.ensureStandardSchema(this.config.schema);
|