@signaldb/core 1.7.0 → 1.7.2

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.
@@ -1,15 +1,10 @@
1
1
  "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
4
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
2
  class EventEmitter {
6
- constructor() {
7
- __publicField(this, "_maxListeners", 100);
8
- /**
9
- * We store a set of the listeners for each event.
10
- */
11
- __publicField(this, "_listenerStore", /* @__PURE__ */ new Map());
12
- }
3
+ _maxListeners = 100;
4
+ /**
5
+ * We store a set of the listeners for each event.
6
+ */
7
+ _listenerStore = /* @__PURE__ */ new Map();
13
8
  setMaxListeners(max) {
14
9
  this._maxListeners = max;
15
10
  return this;
@@ -49,10 +44,10 @@ class EventEmitter {
49
44
  * @returns The emitter instance (for chaining).
50
45
  */
51
46
  once(eventName, listener) {
52
- const onceWrapper = (...args) => {
47
+ const onceWrapper = ((...args) => {
53
48
  listener(...args);
54
49
  this.off(eventName, onceWrapper);
55
- };
50
+ });
56
51
  return this.on(eventName, onceWrapper);
57
52
  }
58
53
  /**
@@ -1,19 +1,16 @@
1
1
  "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
4
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
2
  const isEqual = require("./index.cjs10.js");
6
3
  const uniqueBy = require("./index.cjs26.js");
7
4
  class Observer {
5
+ previousItems = [];
6
+ callbacks;
7
+ unbindEvents;
8
8
  /**
9
9
  * Creates a new instance of the `Observer` class.
10
10
  * Sets up event bindings and initializes the callbacks for tracking changes in a collection.
11
11
  * @param bindEvents - A function to bind external events to the observer. Must return a cleanup function to unbind those events.
12
12
  */
13
13
  constructor(bindEvents) {
14
- __publicField(this, "previousItems", []);
15
- __publicField(this, "callbacks");
16
- __publicField(this, "unbindEvents");
17
14
  this.callbacks = {
18
15
  added: [],
19
16
  addedBefore: [],
@@ -64,7 +61,6 @@ class Observer {
64
61
  ]));
65
62
  if (this.hasCallbacks(["changed", "changedField", "movedBefore", "removed"])) {
66
63
  oldItemsMap.forEach(({ item: oldItem, index, beforeItem: oldBeforeItem }) => {
67
- var _a;
68
64
  const newItem = newItemsMap.get(oldItem.id);
69
65
  if (newItem) {
70
66
  if (this.hasCallbacks(["changed", "changedField"]) && !isEqual(newItem.item, oldItem)) {
@@ -81,7 +77,7 @@ class Observer {
81
77
  });
82
78
  }
83
79
  }
84
- if (newItem.index !== index && ((_a = newItem.beforeItem) == null ? void 0 : _a.id) !== (oldBeforeItem == null ? void 0 : oldBeforeItem.id)) {
80
+ if (newItem.index !== index && newItem.beforeItem?.id !== oldBeforeItem?.id) {
85
81
  this.call("movedBefore", newItem.item, newItem.beforeItem);
86
82
  }
87
83
  } else {
@@ -36,7 +36,6 @@ function clone(value) {
36
36
  function deepClone(object) {
37
37
  if (typeof structuredClone === "function")
38
38
  return structuredClone(object);
39
- /* istanbul ignore next -- @preserve */
40
39
  return clone(object);
41
40
  }
42
41
  exports.clone = clone;
@@ -1,7 +1,4 @@
1
1
  "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
4
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
2
  Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
6
3
  const sortItems = require("./index.cjs15.js");
7
4
  const project = require("./index.cjs16.js");
@@ -14,6 +11,10 @@ function isInReactiveScope(reactivity) {
14
11
  return reactivity.isInScope();
15
12
  }
16
13
  class Cursor {
14
+ observer;
15
+ getFilteredItems;
16
+ options;
17
+ onCleanupCallbacks = [];
17
18
  /**
18
19
  * Creates a new instance of the `Cursor` class.
19
20
  * Provides utilities for querying, observing, and transforming items from a collection.
@@ -31,10 +32,6 @@ class Cursor {
31
32
  * @param options.fieldTracking - A boolean to enable fine-grained field tracking for reactivity.
32
33
  */
33
34
  constructor(getItems, options) {
34
- __publicField(this, "observer");
35
- __publicField(this, "getFilteredItems");
36
- __publicField(this, "options");
37
- __publicField(this, "onCleanupCallbacks", []);
38
35
  this.getFilteredItems = getItems;
39
36
  this.options = options || {};
40
37
  }
@@ -1,9 +1,9 @@
1
1
  "use strict";
2
2
  function createSignal(reactivityAdapter, initialValue, isEqual = Object.is) {
3
3
  let value = initialValue;
4
- const dependency = reactivityAdapter == null ? void 0 : reactivityAdapter.create();
4
+ const dependency = reactivityAdapter?.create();
5
5
  const isInReactiveScope = () => {
6
- if (!(reactivityAdapter == null ? void 0 : reactivityAdapter.isInScope))
6
+ if (!reactivityAdapter?.isInScope)
7
7
  return true;
8
8
  return reactivityAdapter.isInScope();
9
9
  };
@@ -45,6 +45,9 @@ function getIndexInfo(indexProviders, selector) {
45
45
  }
46
46
  if (Array.isArray($or)) {
47
47
  const $orNew = [];
48
+ const matchedBefore = matched;
49
+ const positionsBefore = positions;
50
+ let hasNonIndexField = false;
48
51
  for (const sel of $or) {
49
52
  const { matched: selMatched, positions: selPositions, optimizedSelector } = getIndexInfo(indexProviders, sel);
50
53
  if (selMatched) {
@@ -55,10 +58,16 @@ function getIndexInfo(indexProviders, selector) {
55
58
  }
56
59
  } else {
57
60
  $orNew.push(sel);
61
+ hasNonIndexField = true;
58
62
  }
59
63
  }
60
64
  if ($orNew.length > 0)
61
65
  newSelector.$or = $orNew;
66
+ if (hasNonIndexField) {
67
+ newSelector.$or = $or;
68
+ matched = matchedBefore;
69
+ positions = positionsBefore;
70
+ }
62
71
  }
63
72
  return {
64
73
  matched,
@@ -1,7 +1,4 @@
1
1
  "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
4
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
2
  Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
6
3
  const index = require("./index.cjs3.js");
7
4
  const combinePersistenceAdapters = require("./index.cjs5.js");
@@ -23,6 +20,8 @@ function createReplicationAdapter(options) {
23
20
  });
24
21
  }
25
22
  class ReplicatedCollection extends index.default {
23
+ isPullingRemoteSignal;
24
+ isPushingRemoteSignal;
26
25
  /**
27
26
  * Creates a new instance of the `ReplicatedCollection` class.
28
27
  * Sets up the replication adapter, combining it with an optional persistence adapter, and
@@ -59,13 +58,11 @@ class ReplicatedCollection extends index.default {
59
58
  }
60
59
  } : void 0
61
60
  });
62
- const persistenceAdapter = (options == null ? void 0 : options.persistence) ? combinePersistenceAdapters.default(replicationAdapter, options.persistence) : replicationAdapter;
61
+ const persistenceAdapter = options?.persistence ? combinePersistenceAdapters.default(replicationAdapter, options.persistence) : replicationAdapter;
63
62
  super({
64
63
  ...options,
65
64
  persistence: persistenceAdapter
66
65
  });
67
- __publicField(this, "isPullingRemoteSignal");
68
- __publicField(this, "isPushingRemoteSignal");
69
66
  this.isPullingRemoteSignal = createSignal(options.reactivity, false);
70
67
  this.isPushingRemoteSignal = createSignal(options.reactivity, false);
71
68
  }
@@ -1,7 +1,4 @@
1
1
  "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
4
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
2
  Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
6
3
  const EventEmitter = require("./index.cjs13.js");
7
4
  const match = require("./index.cjs18.js");
@@ -36,7 +33,67 @@ function applyUpdates(currentItems, { added, modified, removed }) {
36
33
  });
37
34
  return items;
38
35
  }
39
- const _Collection = class _Collection extends EventEmitter {
36
+ class Collection extends EventEmitter {
37
+ static collections = [];
38
+ static debugMode = false;
39
+ static batchOperationInProgress = false;
40
+ static fieldTracking = false;
41
+ static onCreationCallbacks = [];
42
+ static onDisposeCallbacks = [];
43
+ static getCollections() {
44
+ return Collection.collections;
45
+ }
46
+ static onCreation(callback) {
47
+ Collection.onCreationCallbacks.push(callback);
48
+ }
49
+ static onDispose(callback) {
50
+ Collection.onDisposeCallbacks.push(callback);
51
+ }
52
+ /**
53
+ * Enables debug mode for all collections.
54
+ */
55
+ static enableDebugMode = () => {
56
+ Collection.debugMode = true;
57
+ Collection.collections.forEach((collection) => {
58
+ collection.setDebugMode(true);
59
+ });
60
+ };
61
+ /**
62
+ * Enables field tracking for all collections.
63
+ * @param enable - A boolean indicating whether to enable field tracking.
64
+ */
65
+ static setFieldTracking = (enable) => {
66
+ Collection.fieldTracking = enable;
67
+ Collection.collections.forEach((collection) => {
68
+ collection.setFieldTracking(enable);
69
+ });
70
+ };
71
+ /**
72
+ * Executes a batch operation, allowing multiple modifications to the collection
73
+ * while deferring index rebuilding until all operations in the batch are completed.
74
+ * This improves performance by avoiding repetitive index recalculations and
75
+ * provides atomicity for the batch of operations.
76
+ * @param callback - The batch operation to execute.
77
+ */
78
+ static batch(callback) {
79
+ Collection.batchOperationInProgress = true;
80
+ Collection.collections.reduce((memo, collection) => () => collection.batch(() => memo()), callback)();
81
+ Collection.batchOperationInProgress = false;
82
+ }
83
+ name;
84
+ options;
85
+ persistenceAdapter = null;
86
+ isPullingSignal;
87
+ isPushingSignal;
88
+ indexProviders = [];
89
+ indicesOutdated = false;
90
+ idIndex = /* @__PURE__ */ new Map();
91
+ debugMode;
92
+ batchOperationInProgress = false;
93
+ isDisposed = false;
94
+ postBatchCallbacks = /* @__PURE__ */ new Set();
95
+ fieldTracking = false;
96
+ persistenceReadyPromise;
40
97
  /**
41
98
  * Initializes a new instance of the `Collection` class with optional configuration.
42
99
  * Sets up memory, persistence, reactivity, and indices as specified in the options.
@@ -55,34 +112,20 @@ const _Collection = class _Collection extends EventEmitter {
55
112
  */
56
113
  constructor(options) {
57
114
  super();
58
- __publicField(this, "name");
59
- __publicField(this, "options");
60
- __publicField(this, "persistenceAdapter", null);
61
- __publicField(this, "isPullingSignal");
62
- __publicField(this, "isPushingSignal");
63
- __publicField(this, "indexProviders", []);
64
- __publicField(this, "indicesOutdated", false);
65
- __publicField(this, "idIndex", /* @__PURE__ */ new Map());
66
- __publicField(this, "debugMode");
67
- __publicField(this, "batchOperationInProgress", false);
68
- __publicField(this, "isDisposed", false);
69
- __publicField(this, "postBatchCallbacks", /* @__PURE__ */ new Set());
70
- __publicField(this, "fieldTracking", false);
71
- __publicField(this, "persistenceReadyPromise");
72
- _Collection.collections.push(this);
73
- this.name = (options == null ? void 0 : options.name) ?? `${this.constructor.name}-${randomId()}`;
115
+ Collection.collections.push(this);
116
+ this.name = options?.name ?? `${this.constructor.name}-${randomId()}`;
74
117
  this.options = {
75
118
  memory: [],
76
119
  ...options
77
120
  };
78
- this.fieldTracking = this.options.fieldTracking ?? _Collection.fieldTracking;
79
- this.debugMode = this.options.enableDebugMode ?? _Collection.debugMode;
121
+ this.fieldTracking = this.options.fieldTracking ?? Collection.fieldTracking;
122
+ this.debugMode = this.options.enableDebugMode ?? Collection.debugMode;
80
123
  this.indexProviders = [
81
124
  createIndex.createExternalIndex("id", this.idIndex),
82
125
  ...this.options.indices || []
83
126
  ];
84
127
  this.rebuildIndices();
85
- this.isPullingSignal = createSignal(this.options.reactivity, !!(options == null ? void 0 : options.persistence));
128
+ this.isPullingSignal = createSignal(this.options.reactivity, !!options?.persistence);
86
129
  this.isPushingSignal = createSignal(this.options.reactivity, false);
87
130
  this.on("persistence.pullStarted", () => {
88
131
  this.isPullingSignal.set(true);
@@ -227,28 +270,7 @@ const _Collection = class _Collection extends EventEmitter {
227
270
  this.once("persistence.init", resolve);
228
271
  this.once("persistence.error", reject);
229
272
  });
230
- _Collection.onCreationCallbacks.forEach((callback) => callback(this));
231
- }
232
- static getCollections() {
233
- return _Collection.collections;
234
- }
235
- static onCreation(callback) {
236
- _Collection.onCreationCallbacks.push(callback);
237
- }
238
- static onDispose(callback) {
239
- _Collection.onDisposeCallbacks.push(callback);
240
- }
241
- /**
242
- * Executes a batch operation, allowing multiple modifications to the collection
243
- * while deferring index rebuilding until all operations in the batch are completed.
244
- * This improves performance by avoiding repetitive index recalculations and
245
- * provides atomicity for the batch of operations.
246
- * @param callback - The batch operation to execute.
247
- */
248
- static batch(callback) {
249
- _Collection.batchOperationInProgress = true;
250
- _Collection.collections.reduce((memo, collection) => () => collection.batch(() => memo()), callback)();
251
- _Collection.batchOperationInProgress = false;
273
+ Collection.onCreationCallbacks.forEach((callback) => callback(this));
252
274
  }
253
275
  /**
254
276
  * Checks whether the collection is currently performing a pull operation
@@ -434,8 +456,7 @@ const _Collection = class _Collection extends EventEmitter {
434
456
  * @returns A promise that resolves when the collection is disposed.
435
457
  */
436
458
  async dispose() {
437
- var _a;
438
- if ((_a = this.persistenceAdapter) == null ? void 0 : _a.unregister)
459
+ if (this.persistenceAdapter?.unregister)
439
460
  await this.persistenceAdapter.unregister();
440
461
  this.persistenceAdapter = null;
441
462
  this.memory().map(() => this.memory().pop());
@@ -443,8 +464,8 @@ const _Collection = class _Collection extends EventEmitter {
443
464
  this.indexProviders = [];
444
465
  this.isDisposed = true;
445
466
  this.removeAllListeners();
446
- _Collection.collections = _Collection.collections.filter((collection) => collection !== this);
447
- _Collection.onDisposeCallbacks.forEach((callback) => callback(this));
467
+ Collection.collections = Collection.collections.filter((collection) => collection !== this);
468
+ Collection.onDisposeCallbacks.forEach((callback) => callback(this));
448
469
  }
449
470
  /**
450
471
  * Finds multiple items in the collection based on a selector and optional options.
@@ -590,7 +611,7 @@ const _Collection = class _Collection extends EventEmitter {
590
611
  const { $setOnInsert, ...restModifier } = modifier;
591
612
  const { item, index } = this.getItemAndIndex(selector);
592
613
  if (item == null) {
593
- if (options == null ? void 0 : options.upsert) {
614
+ if (options?.upsert) {
594
615
  const newItem = modify({}, {
595
616
  ...restModifier,
596
617
  $set: {
@@ -615,7 +636,7 @@ const _Collection = class _Collection extends EventEmitter {
615
636
  }
616
637
  this.emit("updateOne", selector, modifier);
617
638
  this.executeInDebugMode((callstack) => this.emit("_debug.updateOne", callstack, selector, modifier));
618
- if (item == null && !(options == null ? void 0 : options.upsert))
639
+ if (item == null && !options?.upsert)
619
640
  return 0;
620
641
  return 1;
621
642
  }
@@ -637,7 +658,7 @@ const _Collection = class _Collection extends EventEmitter {
637
658
  throw new Error("Invalid modifier");
638
659
  const { $setOnInsert, ...restModifier } = modifier;
639
660
  const items = this.getItems(selector);
640
- if (items.length === 0 && (options == null ? void 0 : options.upsert)) {
661
+ if (items.length === 0 && options?.upsert) {
641
662
  const newItem = modify({}, {
642
663
  ...restModifier,
643
664
  $set: {
@@ -673,7 +694,7 @@ const _Collection = class _Collection extends EventEmitter {
673
694
  });
674
695
  this.emit("updateMany", selector, modifier);
675
696
  this.executeInDebugMode((callstack) => this.emit("_debug.updateMany", callstack, selector, modifier));
676
- return changes.length === 0 && (options == null ? void 0 : options.upsert) ? 1 : changes.length;
697
+ return changes.length === 0 && options?.upsert ? 1 : changes.length;
677
698
  }
678
699
  /**
679
700
  * Replaces a single item in the collection that matches the given selector.
@@ -691,7 +712,7 @@ const _Collection = class _Collection extends EventEmitter {
691
712
  throw new Error("Invalid selector");
692
713
  const { item, index } = this.getItemAndIndex(selector);
693
714
  if (item == null) {
694
- if (options == null ? void 0 : options.upsert) {
715
+ if (options?.upsert) {
695
716
  if (replacement.id != null && this.getItemAndIndex({ id: replacement.id }).item != null) {
696
717
  throw new Error("Item with same id already exists");
697
718
  }
@@ -709,7 +730,7 @@ const _Collection = class _Collection extends EventEmitter {
709
730
  }
710
731
  this.emit("replaceOne", selector, replacement);
711
732
  this.executeInDebugMode((callstack) => this.emit("_debug.replaceOne", callstack, selector, replacement));
712
- if (item == null && !(options == null ? void 0 : options.upsert))
733
+ if (item == null && !options?.upsert)
713
734
  return 0;
714
735
  return 1;
715
736
  }
@@ -762,32 +783,6 @@ const _Collection = class _Collection extends EventEmitter {
762
783
  this.executeInDebugMode((callstack) => this.emit("_debug.removeMany", callstack, selector));
763
784
  return items.length;
764
785
  }
765
- };
766
- __publicField(_Collection, "collections", []);
767
- __publicField(_Collection, "debugMode", false);
768
- __publicField(_Collection, "batchOperationInProgress", false);
769
- __publicField(_Collection, "fieldTracking", false);
770
- __publicField(_Collection, "onCreationCallbacks", []);
771
- __publicField(_Collection, "onDisposeCallbacks", []);
772
- /**
773
- * Enables debug mode for all collections.
774
- */
775
- __publicField(_Collection, "enableDebugMode", () => {
776
- _Collection.debugMode = true;
777
- _Collection.collections.forEach((collection) => {
778
- collection.setDebugMode(true);
779
- });
780
- });
781
- /**
782
- * Enables field tracking for all collections.
783
- * @param enable - A boolean indicating whether to enable field tracking.
784
- */
785
- __publicField(_Collection, "setFieldTracking", (enable) => {
786
- _Collection.fieldTracking = enable;
787
- _Collection.collections.forEach((collection) => {
788
- collection.setFieldTracking(enable);
789
- });
790
- });
791
- let Collection = _Collection;
786
+ }
792
787
  exports.createIndex = createIndex.default;
793
788
  exports.default = Collection;
@@ -1,10 +1,18 @@
1
1
  "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
4
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
2
  const ReplicatedCollection = require("./index.cjs23.js");
6
3
  const createSignal = require("./index.cjs21.js");
7
4
  class AutoFetchCollection extends ReplicatedCollection.default {
5
+ activeObservers = /* @__PURE__ */ new Map();
6
+ observerTimeouts = /* @__PURE__ */ new Map();
7
+ purgeDelay;
8
+ idQueryCache = /* @__PURE__ */ new Map();
9
+ itemsCache = /* @__PURE__ */ new Map();
10
+ fetchQueryItems;
11
+ triggerReload = null;
12
+ reactivityAdapter = null;
13
+ loadingSignals = /* @__PURE__ */ new Map();
14
+ isFetchingSignal;
15
+ mergeItems;
8
16
  /**
9
17
  * @param options {Object} - Options for the collection.
10
18
  * @param options.fetchQueryItems {Function} - A function that fetches items from the server. It takes the selector as an argument and returns a promise that resolves to an object with an `items` property.
@@ -32,17 +40,6 @@ class AutoFetchCollection extends ReplicatedCollection.default {
32
40
  triggerRemoteChange = onChange;
33
41
  }
34
42
  });
35
- __publicField(this, "activeObservers", /* @__PURE__ */ new Map());
36
- __publicField(this, "observerTimeouts", /* @__PURE__ */ new Map());
37
- __publicField(this, "purgeDelay");
38
- __publicField(this, "idQueryCache", /* @__PURE__ */ new Map());
39
- __publicField(this, "itemsCache", /* @__PURE__ */ new Map());
40
- __publicField(this, "fetchQueryItems");
41
- __publicField(this, "triggerReload", null);
42
- __publicField(this, "reactivityAdapter", null);
43
- __publicField(this, "loadingSignals", /* @__PURE__ */ new Map());
44
- __publicField(this, "isFetchingSignal");
45
- __publicField(this, "mergeItems");
46
43
  this.mergeItems = options.mergeItems ?? ((itemA, itemB) => ({ ...itemA, ...itemB }));
47
44
  this.purgeDelay = options.purgeDelay ?? 1e4;
48
45
  this.isFetchingSignal = createSignal(options.reactivity, false);
@@ -103,8 +100,7 @@ class AutoFetchCollection extends ReplicatedCollection.default {
103
100
  });
104
101
  }
105
102
  handleObserverCreation(selector) {
106
- var _a;
107
- const activeObservers = ((_a = this.activeObservers.get(this.getKeyForSelector(selector))) == null ? void 0 : _a.count) ?? 0;
103
+ const activeObservers = this.activeObservers.get(this.getKeyForSelector(selector))?.count ?? 0;
108
104
  this.activeObservers.set(this.getKeyForSelector(selector), {
109
105
  selector,
110
106
  count: activeObservers + 1
@@ -116,8 +112,7 @@ class AutoFetchCollection extends ReplicatedCollection.default {
116
112
  void this.fetchSelector(selector);
117
113
  }
118
114
  handleObserverDisposal(selector) {
119
- var _a;
120
- const currentObservers = ((_a = this.activeObservers.get(this.getKeyForSelector(selector))) == null ? void 0 : _a.count) ?? 0;
115
+ const currentObservers = this.activeObservers.get(this.getKeyForSelector(selector))?.count ?? 0;
121
116
  const activeObservers = currentObservers - 1;
122
117
  if (activeObservers > 0) {
123
118
  this.activeObservers.set(this.getKeyForSelector(selector), {
@@ -2,7 +2,7 @@
2
2
  Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
3
3
  const createPersistenceAdapter = require("./index.cjs8.js");
4
4
  function createTemporaryFallbackExecutor(firstResolvingPromiseFunction, secondResolvingPromiseFunction, options) {
5
- const cacheTimeout = options == null ? void 0 : options.cacheTimeout;
5
+ const cacheTimeout = options?.cacheTimeout;
6
6
  let isResolved = false;
7
7
  let resolvedValue = null;
8
8
  let timeout = null;
@@ -23,7 +23,7 @@ function createTemporaryFallbackExecutor(firstResolvingPromiseFunction, secondRe
23
23
  }
24
24
  isResolved = true;
25
25
  resolvedValue = result;
26
- if (options == null ? void 0 : options.onResolve)
26
+ if (options?.onResolve)
27
27
  options.onResolve(resolvedValue);
28
28
  return result;
29
29
  });
@@ -38,13 +38,12 @@ function combinePersistenceAdapters(slowAdapter, fastAdapter) {
38
38
  const readExecutor = createTemporaryFallbackExecutor(() => fastAdapter.load(), () => slowAdapter.load(), {
39
39
  cacheTimeout: 100,
40
40
  onResolve: (result) => {
41
- var _a, _b, _c;
42
41
  if (handleChange)
43
42
  void handleChange();
44
43
  void fastAdapter.save(result.items || [], {
45
- added: ((_a = result.changes) == null ? void 0 : _a.added) || [],
46
- modified: ((_b = result.changes) == null ? void 0 : _b.modified) || [],
47
- removed: ((_c = result.changes) == null ? void 0 : _c.removed) || []
44
+ added: result.changes?.added || [],
45
+ modified: result.changes?.modified || [],
46
+ removed: result.changes?.removed || []
48
47
  });
49
48
  }
50
49
  });
package/dist/index13.mjs CHANGED
@@ -1,14 +1,9 @@
1
- var __defProp = Object.defineProperty;
2
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
4
1
  class EventEmitter {
5
- constructor() {
6
- __publicField(this, "_maxListeners", 100);
7
- /**
8
- * We store a set of the listeners for each event.
9
- */
10
- __publicField(this, "_listenerStore", /* @__PURE__ */ new Map());
11
- }
2
+ _maxListeners = 100;
3
+ /**
4
+ * We store a set of the listeners for each event.
5
+ */
6
+ _listenerStore = /* @__PURE__ */ new Map();
12
7
  setMaxListeners(max) {
13
8
  this._maxListeners = max;
14
9
  return this;
@@ -48,10 +43,10 @@ class EventEmitter {
48
43
  * @returns The emitter instance (for chaining).
49
44
  */
50
45
  once(eventName, listener) {
51
- const onceWrapper = (...args) => {
46
+ const onceWrapper = ((...args) => {
52
47
  listener(...args);
53
48
  this.off(eventName, onceWrapper);
54
- };
49
+ });
55
50
  return this.on(eventName, onceWrapper);
56
51
  }
57
52
  /**
package/dist/index17.mjs CHANGED
@@ -1,18 +1,15 @@
1
- var __defProp = Object.defineProperty;
2
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
4
1
  import isEqual from "./index10.mjs";
5
2
  import uniqueBy from "./index26.mjs";
6
3
  class Observer {
4
+ previousItems = [];
5
+ callbacks;
6
+ unbindEvents;
7
7
  /**
8
8
  * Creates a new instance of the `Observer` class.
9
9
  * Sets up event bindings and initializes the callbacks for tracking changes in a collection.
10
10
  * @param bindEvents - A function to bind external events to the observer. Must return a cleanup function to unbind those events.
11
11
  */
12
12
  constructor(bindEvents) {
13
- __publicField(this, "previousItems", []);
14
- __publicField(this, "callbacks");
15
- __publicField(this, "unbindEvents");
16
13
  this.callbacks = {
17
14
  added: [],
18
15
  addedBefore: [],
@@ -63,7 +60,6 @@ class Observer {
63
60
  ]));
64
61
  if (this.hasCallbacks(["changed", "changedField", "movedBefore", "removed"])) {
65
62
  oldItemsMap.forEach(({ item: oldItem, index, beforeItem: oldBeforeItem }) => {
66
- var _a;
67
63
  const newItem = newItemsMap.get(oldItem.id);
68
64
  if (newItem) {
69
65
  if (this.hasCallbacks(["changed", "changedField"]) && !isEqual(newItem.item, oldItem)) {
@@ -80,7 +76,7 @@ class Observer {
80
76
  });
81
77
  }
82
78
  }
83
- if (newItem.index !== index && ((_a = newItem.beforeItem) == null ? void 0 : _a.id) !== (oldBeforeItem == null ? void 0 : oldBeforeItem.id)) {
79
+ if (newItem.index !== index && newItem.beforeItem?.id !== oldBeforeItem?.id) {
84
80
  this.call("movedBefore", newItem.item, newItem.beforeItem);
85
81
  }
86
82
  } else {
package/dist/index19.mjs CHANGED
@@ -34,7 +34,6 @@ function clone(value) {
34
34
  function deepClone(object) {
35
35
  if (typeof structuredClone === "function")
36
36
  return structuredClone(object);
37
- /* istanbul ignore next -- @preserve */
38
37
  return clone(object);
39
38
  }
40
39
  export {
package/dist/index2.mjs CHANGED
@@ -1,6 +1,3 @@
1
- var __defProp = Object.defineProperty;
2
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
4
1
  import sortItems from "./index15.mjs";
5
2
  import project from "./index16.mjs";
6
3
  import Observer from "./index17.mjs";
@@ -12,6 +9,10 @@ function isInReactiveScope(reactivity) {
12
9
  return reactivity.isInScope();
13
10
  }
14
11
  class Cursor {
12
+ observer;
13
+ getFilteredItems;
14
+ options;
15
+ onCleanupCallbacks = [];
15
16
  /**
16
17
  * Creates a new instance of the `Cursor` class.
17
18
  * Provides utilities for querying, observing, and transforming items from a collection.
@@ -29,10 +30,6 @@ class Cursor {
29
30
  * @param options.fieldTracking - A boolean to enable fine-grained field tracking for reactivity.
30
31
  */
31
32
  constructor(getItems, options) {
32
- __publicField(this, "observer");
33
- __publicField(this, "getFilteredItems");
34
- __publicField(this, "options");
35
- __publicField(this, "onCleanupCallbacks", []);
36
33
  this.getFilteredItems = getItems;
37
34
  this.options = options || {};
38
35
  }
package/dist/index21.mjs CHANGED
@@ -1,8 +1,8 @@
1
1
  function createSignal(reactivityAdapter, initialValue, isEqual = Object.is) {
2
2
  let value = initialValue;
3
- const dependency = reactivityAdapter == null ? void 0 : reactivityAdapter.create();
3
+ const dependency = reactivityAdapter?.create();
4
4
  const isInReactiveScope = () => {
5
- if (!(reactivityAdapter == null ? void 0 : reactivityAdapter.isInScope))
5
+ if (!reactivityAdapter?.isInScope)
6
6
  return true;
7
7
  return reactivityAdapter.isInScope();
8
8
  };
package/dist/index22.mjs CHANGED
@@ -43,6 +43,9 @@ function getIndexInfo(indexProviders, selector) {
43
43
  }
44
44
  if (Array.isArray($or)) {
45
45
  const $orNew = [];
46
+ const matchedBefore = matched;
47
+ const positionsBefore = positions;
48
+ let hasNonIndexField = false;
46
49
  for (const sel of $or) {
47
50
  const { matched: selMatched, positions: selPositions, optimizedSelector } = getIndexInfo(indexProviders, sel);
48
51
  if (selMatched) {
@@ -53,10 +56,16 @@ function getIndexInfo(indexProviders, selector) {
53
56
  }
54
57
  } else {
55
58
  $orNew.push(sel);
59
+ hasNonIndexField = true;
56
60
  }
57
61
  }
58
62
  if ($orNew.length > 0)
59
63
  newSelector.$or = $orNew;
64
+ if (hasNonIndexField) {
65
+ newSelector.$or = $or;
66
+ matched = matchedBefore;
67
+ positions = positionsBefore;
68
+ }
60
69
  }
61
70
  return {
62
71
  matched,
package/dist/index23.mjs CHANGED
@@ -1,6 +1,3 @@
1
- var __defProp = Object.defineProperty;
2
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
4
1
  import Collection from "./index3.mjs";
5
2
  import combinePersistenceAdapters from "./index5.mjs";
6
3
  import createPersistenceAdapter from "./index8.mjs";
@@ -21,6 +18,8 @@ function createReplicationAdapter(options) {
21
18
  });
22
19
  }
23
20
  class ReplicatedCollection extends Collection {
21
+ isPullingRemoteSignal;
22
+ isPushingRemoteSignal;
24
23
  /**
25
24
  * Creates a new instance of the `ReplicatedCollection` class.
26
25
  * Sets up the replication adapter, combining it with an optional persistence adapter, and
@@ -57,13 +56,11 @@ class ReplicatedCollection extends Collection {
57
56
  }
58
57
  } : void 0
59
58
  });
60
- const persistenceAdapter = (options == null ? void 0 : options.persistence) ? combinePersistenceAdapters(replicationAdapter, options.persistence) : replicationAdapter;
59
+ const persistenceAdapter = options?.persistence ? combinePersistenceAdapters(replicationAdapter, options.persistence) : replicationAdapter;
61
60
  super({
62
61
  ...options,
63
62
  persistence: persistenceAdapter
64
63
  });
65
- __publicField(this, "isPullingRemoteSignal");
66
- __publicField(this, "isPushingRemoteSignal");
67
64
  this.isPullingRemoteSignal = createSignal(options.reactivity, false);
68
65
  this.isPushingRemoteSignal = createSignal(options.reactivity, false);
69
66
  }
package/dist/index3.mjs CHANGED
@@ -1,6 +1,3 @@
1
- var __defProp = Object.defineProperty;
2
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
4
1
  import EventEmitter from "./index13.mjs";
5
2
  import match from "./index18.mjs";
6
3
  import modify from "./index11.mjs";
@@ -35,7 +32,67 @@ function applyUpdates(currentItems, { added, modified, removed }) {
35
32
  });
36
33
  return items;
37
34
  }
38
- const _Collection = class _Collection extends EventEmitter {
35
+ class Collection extends EventEmitter {
36
+ static collections = [];
37
+ static debugMode = false;
38
+ static batchOperationInProgress = false;
39
+ static fieldTracking = false;
40
+ static onCreationCallbacks = [];
41
+ static onDisposeCallbacks = [];
42
+ static getCollections() {
43
+ return Collection.collections;
44
+ }
45
+ static onCreation(callback) {
46
+ Collection.onCreationCallbacks.push(callback);
47
+ }
48
+ static onDispose(callback) {
49
+ Collection.onDisposeCallbacks.push(callback);
50
+ }
51
+ /**
52
+ * Enables debug mode for all collections.
53
+ */
54
+ static enableDebugMode = () => {
55
+ Collection.debugMode = true;
56
+ Collection.collections.forEach((collection) => {
57
+ collection.setDebugMode(true);
58
+ });
59
+ };
60
+ /**
61
+ * Enables field tracking for all collections.
62
+ * @param enable - A boolean indicating whether to enable field tracking.
63
+ */
64
+ static setFieldTracking = (enable) => {
65
+ Collection.fieldTracking = enable;
66
+ Collection.collections.forEach((collection) => {
67
+ collection.setFieldTracking(enable);
68
+ });
69
+ };
70
+ /**
71
+ * Executes a batch operation, allowing multiple modifications to the collection
72
+ * while deferring index rebuilding until all operations in the batch are completed.
73
+ * This improves performance by avoiding repetitive index recalculations and
74
+ * provides atomicity for the batch of operations.
75
+ * @param callback - The batch operation to execute.
76
+ */
77
+ static batch(callback) {
78
+ Collection.batchOperationInProgress = true;
79
+ Collection.collections.reduce((memo, collection) => () => collection.batch(() => memo()), callback)();
80
+ Collection.batchOperationInProgress = false;
81
+ }
82
+ name;
83
+ options;
84
+ persistenceAdapter = null;
85
+ isPullingSignal;
86
+ isPushingSignal;
87
+ indexProviders = [];
88
+ indicesOutdated = false;
89
+ idIndex = /* @__PURE__ */ new Map();
90
+ debugMode;
91
+ batchOperationInProgress = false;
92
+ isDisposed = false;
93
+ postBatchCallbacks = /* @__PURE__ */ new Set();
94
+ fieldTracking = false;
95
+ persistenceReadyPromise;
39
96
  /**
40
97
  * Initializes a new instance of the `Collection` class with optional configuration.
41
98
  * Sets up memory, persistence, reactivity, and indices as specified in the options.
@@ -54,34 +111,20 @@ const _Collection = class _Collection extends EventEmitter {
54
111
  */
55
112
  constructor(options) {
56
113
  super();
57
- __publicField(this, "name");
58
- __publicField(this, "options");
59
- __publicField(this, "persistenceAdapter", null);
60
- __publicField(this, "isPullingSignal");
61
- __publicField(this, "isPushingSignal");
62
- __publicField(this, "indexProviders", []);
63
- __publicField(this, "indicesOutdated", false);
64
- __publicField(this, "idIndex", /* @__PURE__ */ new Map());
65
- __publicField(this, "debugMode");
66
- __publicField(this, "batchOperationInProgress", false);
67
- __publicField(this, "isDisposed", false);
68
- __publicField(this, "postBatchCallbacks", /* @__PURE__ */ new Set());
69
- __publicField(this, "fieldTracking", false);
70
- __publicField(this, "persistenceReadyPromise");
71
- _Collection.collections.push(this);
72
- this.name = (options == null ? void 0 : options.name) ?? `${this.constructor.name}-${randomId()}`;
114
+ Collection.collections.push(this);
115
+ this.name = options?.name ?? `${this.constructor.name}-${randomId()}`;
73
116
  this.options = {
74
117
  memory: [],
75
118
  ...options
76
119
  };
77
- this.fieldTracking = this.options.fieldTracking ?? _Collection.fieldTracking;
78
- this.debugMode = this.options.enableDebugMode ?? _Collection.debugMode;
120
+ this.fieldTracking = this.options.fieldTracking ?? Collection.fieldTracking;
121
+ this.debugMode = this.options.enableDebugMode ?? Collection.debugMode;
79
122
  this.indexProviders = [
80
123
  createExternalIndex("id", this.idIndex),
81
124
  ...this.options.indices || []
82
125
  ];
83
126
  this.rebuildIndices();
84
- this.isPullingSignal = createSignal(this.options.reactivity, !!(options == null ? void 0 : options.persistence));
127
+ this.isPullingSignal = createSignal(this.options.reactivity, !!options?.persistence);
85
128
  this.isPushingSignal = createSignal(this.options.reactivity, false);
86
129
  this.on("persistence.pullStarted", () => {
87
130
  this.isPullingSignal.set(true);
@@ -226,28 +269,7 @@ const _Collection = class _Collection extends EventEmitter {
226
269
  this.once("persistence.init", resolve);
227
270
  this.once("persistence.error", reject);
228
271
  });
229
- _Collection.onCreationCallbacks.forEach((callback) => callback(this));
230
- }
231
- static getCollections() {
232
- return _Collection.collections;
233
- }
234
- static onCreation(callback) {
235
- _Collection.onCreationCallbacks.push(callback);
236
- }
237
- static onDispose(callback) {
238
- _Collection.onDisposeCallbacks.push(callback);
239
- }
240
- /**
241
- * Executes a batch operation, allowing multiple modifications to the collection
242
- * while deferring index rebuilding until all operations in the batch are completed.
243
- * This improves performance by avoiding repetitive index recalculations and
244
- * provides atomicity for the batch of operations.
245
- * @param callback - The batch operation to execute.
246
- */
247
- static batch(callback) {
248
- _Collection.batchOperationInProgress = true;
249
- _Collection.collections.reduce((memo, collection) => () => collection.batch(() => memo()), callback)();
250
- _Collection.batchOperationInProgress = false;
272
+ Collection.onCreationCallbacks.forEach((callback) => callback(this));
251
273
  }
252
274
  /**
253
275
  * Checks whether the collection is currently performing a pull operation
@@ -433,8 +455,7 @@ const _Collection = class _Collection extends EventEmitter {
433
455
  * @returns A promise that resolves when the collection is disposed.
434
456
  */
435
457
  async dispose() {
436
- var _a;
437
- if ((_a = this.persistenceAdapter) == null ? void 0 : _a.unregister)
458
+ if (this.persistenceAdapter?.unregister)
438
459
  await this.persistenceAdapter.unregister();
439
460
  this.persistenceAdapter = null;
440
461
  this.memory().map(() => this.memory().pop());
@@ -442,8 +463,8 @@ const _Collection = class _Collection extends EventEmitter {
442
463
  this.indexProviders = [];
443
464
  this.isDisposed = true;
444
465
  this.removeAllListeners();
445
- _Collection.collections = _Collection.collections.filter((collection) => collection !== this);
446
- _Collection.onDisposeCallbacks.forEach((callback) => callback(this));
466
+ Collection.collections = Collection.collections.filter((collection) => collection !== this);
467
+ Collection.onDisposeCallbacks.forEach((callback) => callback(this));
447
468
  }
448
469
  /**
449
470
  * Finds multiple items in the collection based on a selector and optional options.
@@ -589,7 +610,7 @@ const _Collection = class _Collection extends EventEmitter {
589
610
  const { $setOnInsert, ...restModifier } = modifier;
590
611
  const { item, index } = this.getItemAndIndex(selector);
591
612
  if (item == null) {
592
- if (options == null ? void 0 : options.upsert) {
613
+ if (options?.upsert) {
593
614
  const newItem = modify({}, {
594
615
  ...restModifier,
595
616
  $set: {
@@ -614,7 +635,7 @@ const _Collection = class _Collection extends EventEmitter {
614
635
  }
615
636
  this.emit("updateOne", selector, modifier);
616
637
  this.executeInDebugMode((callstack) => this.emit("_debug.updateOne", callstack, selector, modifier));
617
- if (item == null && !(options == null ? void 0 : options.upsert))
638
+ if (item == null && !options?.upsert)
618
639
  return 0;
619
640
  return 1;
620
641
  }
@@ -636,7 +657,7 @@ const _Collection = class _Collection extends EventEmitter {
636
657
  throw new Error("Invalid modifier");
637
658
  const { $setOnInsert, ...restModifier } = modifier;
638
659
  const items = this.getItems(selector);
639
- if (items.length === 0 && (options == null ? void 0 : options.upsert)) {
660
+ if (items.length === 0 && options?.upsert) {
640
661
  const newItem = modify({}, {
641
662
  ...restModifier,
642
663
  $set: {
@@ -672,7 +693,7 @@ const _Collection = class _Collection extends EventEmitter {
672
693
  });
673
694
  this.emit("updateMany", selector, modifier);
674
695
  this.executeInDebugMode((callstack) => this.emit("_debug.updateMany", callstack, selector, modifier));
675
- return changes.length === 0 && (options == null ? void 0 : options.upsert) ? 1 : changes.length;
696
+ return changes.length === 0 && options?.upsert ? 1 : changes.length;
676
697
  }
677
698
  /**
678
699
  * Replaces a single item in the collection that matches the given selector.
@@ -690,7 +711,7 @@ const _Collection = class _Collection extends EventEmitter {
690
711
  throw new Error("Invalid selector");
691
712
  const { item, index } = this.getItemAndIndex(selector);
692
713
  if (item == null) {
693
- if (options == null ? void 0 : options.upsert) {
714
+ if (options?.upsert) {
694
715
  if (replacement.id != null && this.getItemAndIndex({ id: replacement.id }).item != null) {
695
716
  throw new Error("Item with same id already exists");
696
717
  }
@@ -708,7 +729,7 @@ const _Collection = class _Collection extends EventEmitter {
708
729
  }
709
730
  this.emit("replaceOne", selector, replacement);
710
731
  this.executeInDebugMode((callstack) => this.emit("_debug.replaceOne", callstack, selector, replacement));
711
- if (item == null && !(options == null ? void 0 : options.upsert))
732
+ if (item == null && !options?.upsert)
712
733
  return 0;
713
734
  return 1;
714
735
  }
@@ -761,33 +782,7 @@ const _Collection = class _Collection extends EventEmitter {
761
782
  this.executeInDebugMode((callstack) => this.emit("_debug.removeMany", callstack, selector));
762
783
  return items.length;
763
784
  }
764
- };
765
- __publicField(_Collection, "collections", []);
766
- __publicField(_Collection, "debugMode", false);
767
- __publicField(_Collection, "batchOperationInProgress", false);
768
- __publicField(_Collection, "fieldTracking", false);
769
- __publicField(_Collection, "onCreationCallbacks", []);
770
- __publicField(_Collection, "onDisposeCallbacks", []);
771
- /**
772
- * Enables debug mode for all collections.
773
- */
774
- __publicField(_Collection, "enableDebugMode", () => {
775
- _Collection.debugMode = true;
776
- _Collection.collections.forEach((collection) => {
777
- collection.setDebugMode(true);
778
- });
779
- });
780
- /**
781
- * Enables field tracking for all collections.
782
- * @param enable - A boolean indicating whether to enable field tracking.
783
- */
784
- __publicField(_Collection, "setFieldTracking", (enable) => {
785
- _Collection.fieldTracking = enable;
786
- _Collection.collections.forEach((collection) => {
787
- collection.setFieldTracking(enable);
788
- });
789
- });
790
- let Collection = _Collection;
785
+ }
791
786
  export {
792
787
  default2 as createIndex,
793
788
  Collection as default
package/dist/index4.mjs CHANGED
@@ -1,9 +1,17 @@
1
- var __defProp = Object.defineProperty;
2
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
4
1
  import ReplicatedCollection from "./index23.mjs";
5
2
  import createSignal from "./index21.mjs";
6
3
  class AutoFetchCollection extends ReplicatedCollection {
4
+ activeObservers = /* @__PURE__ */ new Map();
5
+ observerTimeouts = /* @__PURE__ */ new Map();
6
+ purgeDelay;
7
+ idQueryCache = /* @__PURE__ */ new Map();
8
+ itemsCache = /* @__PURE__ */ new Map();
9
+ fetchQueryItems;
10
+ triggerReload = null;
11
+ reactivityAdapter = null;
12
+ loadingSignals = /* @__PURE__ */ new Map();
13
+ isFetchingSignal;
14
+ mergeItems;
7
15
  /**
8
16
  * @param options {Object} - Options for the collection.
9
17
  * @param options.fetchQueryItems {Function} - A function that fetches items from the server. It takes the selector as an argument and returns a promise that resolves to an object with an `items` property.
@@ -31,17 +39,6 @@ class AutoFetchCollection extends ReplicatedCollection {
31
39
  triggerRemoteChange = onChange;
32
40
  }
33
41
  });
34
- __publicField(this, "activeObservers", /* @__PURE__ */ new Map());
35
- __publicField(this, "observerTimeouts", /* @__PURE__ */ new Map());
36
- __publicField(this, "purgeDelay");
37
- __publicField(this, "idQueryCache", /* @__PURE__ */ new Map());
38
- __publicField(this, "itemsCache", /* @__PURE__ */ new Map());
39
- __publicField(this, "fetchQueryItems");
40
- __publicField(this, "triggerReload", null);
41
- __publicField(this, "reactivityAdapter", null);
42
- __publicField(this, "loadingSignals", /* @__PURE__ */ new Map());
43
- __publicField(this, "isFetchingSignal");
44
- __publicField(this, "mergeItems");
45
42
  this.mergeItems = options.mergeItems ?? ((itemA, itemB) => ({ ...itemA, ...itemB }));
46
43
  this.purgeDelay = options.purgeDelay ?? 1e4;
47
44
  this.isFetchingSignal = createSignal(options.reactivity, false);
@@ -102,8 +99,7 @@ class AutoFetchCollection extends ReplicatedCollection {
102
99
  });
103
100
  }
104
101
  handleObserverCreation(selector) {
105
- var _a;
106
- const activeObservers = ((_a = this.activeObservers.get(this.getKeyForSelector(selector))) == null ? void 0 : _a.count) ?? 0;
102
+ const activeObservers = this.activeObservers.get(this.getKeyForSelector(selector))?.count ?? 0;
107
103
  this.activeObservers.set(this.getKeyForSelector(selector), {
108
104
  selector,
109
105
  count: activeObservers + 1
@@ -115,8 +111,7 @@ class AutoFetchCollection extends ReplicatedCollection {
115
111
  void this.fetchSelector(selector);
116
112
  }
117
113
  handleObserverDisposal(selector) {
118
- var _a;
119
- const currentObservers = ((_a = this.activeObservers.get(this.getKeyForSelector(selector))) == null ? void 0 : _a.count) ?? 0;
114
+ const currentObservers = this.activeObservers.get(this.getKeyForSelector(selector))?.count ?? 0;
120
115
  const activeObservers = currentObservers - 1;
121
116
  if (activeObservers > 0) {
122
117
  this.activeObservers.set(this.getKeyForSelector(selector), {
package/dist/index5.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import createPersistenceAdapter from "./index8.mjs";
2
2
  function createTemporaryFallbackExecutor(firstResolvingPromiseFunction, secondResolvingPromiseFunction, options) {
3
- const cacheTimeout = options == null ? void 0 : options.cacheTimeout;
3
+ const cacheTimeout = options?.cacheTimeout;
4
4
  let isResolved = false;
5
5
  let resolvedValue = null;
6
6
  let timeout = null;
@@ -21,7 +21,7 @@ function createTemporaryFallbackExecutor(firstResolvingPromiseFunction, secondRe
21
21
  }
22
22
  isResolved = true;
23
23
  resolvedValue = result;
24
- if (options == null ? void 0 : options.onResolve)
24
+ if (options?.onResolve)
25
25
  options.onResolve(resolvedValue);
26
26
  return result;
27
27
  });
@@ -36,13 +36,12 @@ function combinePersistenceAdapters(slowAdapter, fastAdapter) {
36
36
  const readExecutor = createTemporaryFallbackExecutor(() => fastAdapter.load(), () => slowAdapter.load(), {
37
37
  cacheTimeout: 100,
38
38
  onResolve: (result) => {
39
- var _a, _b, _c;
40
39
  if (handleChange)
41
40
  void handleChange();
42
41
  void fastAdapter.save(result.items || [], {
43
- added: ((_a = result.changes) == null ? void 0 : _a.added) || [],
44
- modified: ((_b = result.changes) == null ? void 0 : _b.modified) || [],
45
- removed: ((_c = result.changes) == null ? void 0 : _c.removed) || []
42
+ added: result.changes?.added || [],
43
+ modified: result.changes?.modified || [],
44
+ removed: result.changes?.removed || []
46
45
  });
47
46
  }
48
47
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@signaldb/core",
3
- "version": "1.7.0",
3
+ "version": "1.7.2",
4
4
  "description": "SignalDB is a client-side database that provides a simple MongoDB-like interface to the data with first-class typescript support to achieve an optimistic UI. Data persistence can be achieved by using storage providers that store the data through a JSON interface to places such as localStorage.",
5
5
  "scripts": {
6
6
  "build": "rimraf dist && vite build",
@@ -55,9 +55,9 @@
55
55
  ],
56
56
  "dependencies": {
57
57
  "fast-sort": "^3.4.1",
58
- "mingo": "^6.5.1"
58
+ "mingo": "^7.0.0"
59
59
  },
60
60
  "devDependencies": {
61
- "zod": "^3.24.2"
61
+ "zod": "^4.0.14"
62
62
  }
63
63
  }