@tanstack/db 0.1.7 → 0.1.9

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.
Files changed (34) hide show
  1. package/dist/cjs/collection.cjs +6 -21
  2. package/dist/cjs/collection.cjs.map +1 -1
  3. package/dist/cjs/collection.d.cts +0 -1
  4. package/dist/cjs/proxy.cjs +9 -58
  5. package/dist/cjs/proxy.cjs.map +1 -1
  6. package/dist/cjs/query/live/collection-config-builder.cjs +24 -17
  7. package/dist/cjs/query/live/collection-config-builder.cjs.map +1 -1
  8. package/dist/cjs/query/live/collection-config-builder.d.cts +0 -2
  9. package/dist/cjs/query/live/collection-subscriber.cjs +25 -16
  10. package/dist/cjs/query/live/collection-subscriber.cjs.map +1 -1
  11. package/dist/cjs/query/live/collection-subscriber.d.cts +1 -1
  12. package/dist/cjs/utils.cjs +75 -0
  13. package/dist/cjs/utils.cjs.map +1 -1
  14. package/dist/cjs/utils.d.cts +5 -0
  15. package/dist/esm/collection.d.ts +0 -1
  16. package/dist/esm/collection.js +6 -21
  17. package/dist/esm/collection.js.map +1 -1
  18. package/dist/esm/proxy.js +9 -58
  19. package/dist/esm/proxy.js.map +1 -1
  20. package/dist/esm/query/live/collection-config-builder.d.ts +0 -2
  21. package/dist/esm/query/live/collection-config-builder.js +24 -17
  22. package/dist/esm/query/live/collection-config-builder.js.map +1 -1
  23. package/dist/esm/query/live/collection-subscriber.d.ts +1 -1
  24. package/dist/esm/query/live/collection-subscriber.js +25 -16
  25. package/dist/esm/query/live/collection-subscriber.js.map +1 -1
  26. package/dist/esm/utils.d.ts +5 -0
  27. package/dist/esm/utils.js +76 -1
  28. package/dist/esm/utils.js.map +1 -1
  29. package/package.json +3 -2
  30. package/src/collection.ts +9 -26
  31. package/src/proxy.ts +16 -107
  32. package/src/query/live/collection-config-builder.ts +30 -21
  33. package/src/query/live/collection-subscriber.ts +44 -25
  34. package/src/utils.ts +125 -0
@@ -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");
@@ -255,7 +256,7 @@ class CollectionImpl {
255
256
  const previousVisibleValue = currentVisibleState.get(key);
256
257
  const newVisibleValue = this.get(key);
257
258
  const completedOp = completedOptimisticOps.get(key);
258
- const isRedundantSync = completedOp && newVisibleValue !== void 0 && this.deepEqual(completedOp.value, newVisibleValue);
259
+ const isRedundantSync = completedOp && newVisibleValue !== void 0 && utils.deepEquals(completedOp.value, newVisibleValue);
259
260
  if (!isRedundantSync) {
260
261
  if (previousVisibleValue === void 0 && newVisibleValue !== void 0) {
261
262
  events.push({
@@ -269,7 +270,7 @@ class CollectionImpl {
269
270
  key,
270
271
  value: previousVisibleValue
271
272
  });
272
- } else if (previousVisibleValue !== void 0 && newVisibleValue !== void 0 && !this.deepEqual(previousVisibleValue, newVisibleValue)) {
273
+ } else if (previousVisibleValue !== void 0 && newVisibleValue !== void 0 && !utils.deepEquals(previousVisibleValue, newVisibleValue)) {
273
274
  events.push({
274
275
  type: `update`,
275
276
  key,
@@ -721,6 +722,9 @@ class CollectionImpl {
721
722
  clearTimeout(this.gcTimeoutId);
722
723
  }
723
724
  const gcTime = this.config.gcTime ?? 3e5;
725
+ if (gcTime === 0) {
726
+ return;
727
+ }
724
728
  this.gcTimeoutId = setTimeout(() => {
725
729
  if (this.activeSubscribersCount === 0) {
726
730
  this.cleanup();
@@ -753,7 +757,6 @@ class CollectionImpl {
753
757
  removeSubscriber() {
754
758
  this.activeSubscribersCount--;
755
759
  if (this.activeSubscribersCount === 0) {
756
- this.activeSubscribersCount = 0;
757
760
  this.startGCTimer();
758
761
  } else if (this.activeSubscribersCount < 0) {
759
762
  throw new errors.NegativeActiveSubscribersError();
@@ -1193,24 +1196,6 @@ class CollectionImpl {
1193
1196
  }
1194
1197
  }
1195
1198
  }
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
1199
  validateData(data, type, key) {
1215
1200
  if (!this.config.schema) return data;
1216
1201
  const standardSchema = this.ensureStandardSchema(this.config.schema);