live-cache 0.2.5 → 0.2.7

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/index.mjs CHANGED
@@ -129,6 +129,7 @@ class Collection {
129
129
  this.dataMap = {};
130
130
  this.indexes = {};
131
131
  this.counter = 0;
132
+ this.lastUpdated = new Date();
132
133
  }
133
134
  /**
134
135
  * Clear all in-memory documents and indexes.
@@ -137,6 +138,10 @@ class Collection {
137
138
  this.dataMap = {};
138
139
  this.indexes = {};
139
140
  this.counter = 0;
141
+ this.lastUpdated = new Date();
142
+ }
143
+ updateLastUpdated() {
144
+ this.lastUpdated = new Date();
140
145
  }
141
146
  /**
142
147
  * Add a document to all relevant indexes
@@ -164,6 +169,7 @@ class Collection {
164
169
  if (!this.indexes[fullIndexKey].includes(doc._id)) {
165
170
  this.indexes[fullIndexKey].push(doc._id);
166
171
  }
172
+ this.updateLastUpdated();
167
173
  }
168
174
  /**
169
175
  * Remove a document from all indexes
@@ -191,6 +197,7 @@ class Collection {
191
197
  delete this.indexes[fullIndexKey];
192
198
  }
193
199
  }
200
+ this.updateLastUpdated();
194
201
  }
195
202
  /**
196
203
  * Find a single document by _id or by matching conditions (optimized with indexes)
@@ -259,6 +266,7 @@ class Collection {
259
266
  this.dataMap[doc._id] = doc;
260
267
  // Add to indexes
261
268
  this.addToIndexes(doc);
269
+ this.updateLastUpdated();
262
270
  return doc;
263
271
  }
264
272
  /**
@@ -273,6 +281,7 @@ class Collection {
273
281
  this.removeFromIndexes(doc);
274
282
  // Remove from dataMap
275
283
  delete this.dataMap[doc._id];
284
+ this.updateLastUpdated();
276
285
  return true;
277
286
  }
278
287
  /**
@@ -297,6 +306,7 @@ class Collection {
297
306
  this.removeFromIndexes(doc);
298
307
  doc.updateData(update);
299
308
  this.addToIndexes(doc);
309
+ this.updateLastUpdated();
300
310
  return doc;
301
311
  }
302
312
  /**
@@ -313,6 +323,7 @@ class Collection {
313
323
  this.addToIndexes(doc);
314
324
  insertedDocs.push(doc);
315
325
  }
326
+ this.updateLastUpdated();
316
327
  return insertedDocs;
317
328
  }
318
329
  /**
@@ -1432,31 +1443,6 @@ function useRegister(controller, store = getDefaultObjectStore()) {
1432
1443
  return stored;
1433
1444
  }
1434
1445
 
1435
- /**
1436
- * React hook to subscribe to a registered controller.
1437
- *
1438
- * - Looks up the controller by name from the `ObjectStore` (context by default)
1439
- * - Subscribes to `controller.publish()`
1440
- * - Exposes `data`, `loading`, `error`, and the `controller` instance
1441
- *
1442
- * @param name - controller name
1443
- * @param where - optional `Collection.find()` filter (string `_id` or partial)
1444
- * @param options - store selection, initialise behavior, abort-on-unmount, and invalidation wiring
1445
- *
1446
- * When `options.withInvalidation` is true, this hook calls
1447
- * `controller.invalidator.registerInvalidation()` on mount and
1448
- * `controller.invalidator.unregisterInvalidation()` on unmount.
1449
- *
1450
- * @example
1451
- * ```tsx
1452
- * const { data, controller } = useController<User, "users">("users", undefined, {
1453
- * withInvalidation: true,
1454
- * });
1455
- * return (
1456
- * <button onClick={() => void controller.invalidate()}>Refresh</button>
1457
- * );
1458
- * ```
1459
- */
1460
1446
  function useController(controllerInstance, where, options) {
1461
1447
  var _a, _b;
1462
1448
  const optionalStore = options === null || options === void 0 ? void 0 : options.store;