@dereekb/firebase 13.6.6 → 13.6.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/index.cjs.js CHANGED
@@ -488,7 +488,7 @@ function _is_native_reflect_construct$9() {
488
488
  return COPY_USER_RELATED_DATA_ACCESSOR_FACTORY_FUNCTION();
489
489
  }
490
490
 
491
- function asyncGeneratorStep$k(gen, resolve, reject, _next, _throw, key, arg) {
491
+ function asyncGeneratorStep$l(gen, resolve, reject, _next, _throw, key, arg) {
492
492
  try {
493
493
  var info = gen[key](arg);
494
494
  var value = info.value;
@@ -502,22 +502,22 @@ function asyncGeneratorStep$k(gen, resolve, reject, _next, _throw, key, arg) {
502
502
  Promise.resolve(value).then(_next, _throw);
503
503
  }
504
504
  }
505
- function _async_to_generator$k(fn) {
505
+ function _async_to_generator$l(fn) {
506
506
  return function() {
507
507
  var self = this, args = arguments;
508
508
  return new Promise(function(resolve, reject) {
509
509
  var gen = fn.apply(self, args);
510
510
  function _next(value) {
511
- asyncGeneratorStep$k(gen, resolve, reject, _next, _throw, "next", value);
511
+ asyncGeneratorStep$l(gen, resolve, reject, _next, _throw, "next", value);
512
512
  }
513
513
  function _throw(err) {
514
- asyncGeneratorStep$k(gen, resolve, reject, _next, _throw, "throw", err);
514
+ asyncGeneratorStep$l(gen, resolve, reject, _next, _throw, "throw", err);
515
515
  }
516
516
  _next(undefined);
517
517
  });
518
518
  };
519
519
  }
520
- function _ts_generator$k(thisArg, body) {
520
+ function _ts_generator$l(thisArg, body) {
521
521
  var f, y, t, _ = {
522
522
  label: 0,
523
523
  sent: function() {
@@ -687,9 +687,9 @@ function _ts_generator$k(thisArg, body) {
687
687
  * @returns A function that updates the document with converted data
688
688
  */ function updateWithAccessorUpdateAndConverterFunction(accessor, converter) {
689
689
  return function(data, params) {
690
- return _async_to_generator$k(function() {
690
+ return _async_to_generator$l(function() {
691
691
  var updateInput, updateData;
692
- return _ts_generator$k(this, function(_state) {
692
+ return _ts_generator$l(this, function(_state) {
693
693
  updateInput = util.filterUndefinedValues(data);
694
694
  updateData = converter.toFirestore(updateInput, {
695
695
  merge: true
@@ -732,7 +732,129 @@ function _ts_generator$k(thisArg, body) {
732
732
  */ FirestoreDocumentContextType["BATCH"] = "batch";
733
733
  })(exports.FirestoreDocumentContextType || (exports.FirestoreDocumentContextType = {}));
734
734
 
735
- function asyncGeneratorStep$j(gen, resolve, reject, _next, _throw, key, arg) {
735
+ /**
736
+ * Creates a {@link FirestoreCollectionDocumentCache} that delegates to the given
737
+ * collection cache with the key pre-bound.
738
+ *
739
+ * @param collectionCache - The parent collection cache
740
+ * @param key - The document path to bind
741
+ * @returns A document-scoped cache
742
+ *
743
+ * @example
744
+ * ```ts
745
+ * const docCache = firestoreCollectionDocumentCache(collectionCache, 'users/abc');
746
+ * docCache.set({ data: userData });
747
+ * const entry = docCache.get();
748
+ * ```
749
+ */ function firestoreCollectionDocumentCache(collectionCache, key) {
750
+ return {
751
+ get: function get(maxTtl) {
752
+ return collectionCache.get(key, maxTtl);
753
+ },
754
+ set: function set(entry) {
755
+ return collectionCache.set(key, entry);
756
+ },
757
+ invalidate: function invalidate() {
758
+ return collectionCache.invalidate(key);
759
+ }
760
+ };
761
+ }
762
+ /**
763
+ * Singleton noop {@link FirestoreCollectionDocumentCache} that discards all operations.
764
+ */ var NOOP_FIRESTORE_COLLECTION_DOCUMENT_CACHE = {
765
+ get: function get() {
766
+ return undefined;
767
+ },
768
+ set: function set() {},
769
+ invalidate: function invalidate() {}
770
+ };
771
+ /**
772
+ * Returns the singleton noop {@link FirestoreCollectionDocumentCache}.
773
+ */ function noopFirestoreCollectionDocumentCache() {
774
+ return NOOP_FIRESTORE_COLLECTION_DOCUMENT_CACHE;
775
+ }
776
+ // MARK: Noop
777
+ /**
778
+ * Singleton noop {@link FirestoreCollectionCacheInstance} that discards all operations.
779
+ */ var NOOP_FIRESTORE_COLLECTION_CACHE_INSTANCE = {
780
+ get: function get() {
781
+ return undefined;
782
+ },
783
+ getOrFetch: function getOrFetch(_key, fetchFn) {
784
+ return fetchFn();
785
+ }
786
+ };
787
+ /**
788
+ * Singleton noop {@link FirestoreCollectionCache} that discards all operations.
789
+ *
790
+ * Used when no cache driver is configured so that `.cache` is always defined,
791
+ * avoiding optional checks throughout the codebase.
792
+ */ var NOOP_FIRESTORE_COLLECTION_CACHE = {
793
+ defaultTtl: 0,
794
+ get: function get() {
795
+ return undefined;
796
+ },
797
+ set: function set() {},
798
+ invalidate: function invalidate() {},
799
+ clear: function clear() {},
800
+ instance: function instance() {
801
+ return NOOP_FIRESTORE_COLLECTION_CACHE_INSTANCE;
802
+ },
803
+ destroy: function destroy() {}
804
+ };
805
+ /**
806
+ * Returns the singleton noop {@link FirestoreCollectionCache} that discards all operations.
807
+ *
808
+ * Used when no cache driver is configured so that `.cache` is always defined.
809
+ *
810
+ * @example
811
+ * ```ts
812
+ * const cache = noopFirestoreCollectionCache();
813
+ * cache.get('path/to/doc'); // always returns undefined
814
+ * cache.set('path/to/doc', { data }); // no-op
815
+ * ```
816
+ */ function noopFirestoreCollectionCache() {
817
+ return NOOP_FIRESTORE_COLLECTION_CACHE;
818
+ }
819
+ /**
820
+ * Singleton noop {@link FirestoreContextCache} that always returns noop collection caches.
821
+ *
822
+ * Used when no cache factory is configured so that `FirestoreContext.cache` is always defined.
823
+ */ var NOOP_FIRESTORE_CONTEXT_CACHE = {
824
+ cacheForCollection: function cacheForCollection() {
825
+ return noopFirestoreCollectionCache();
826
+ },
827
+ events$: rxjs$1.EMPTY,
828
+ disabledTypes: new Set(),
829
+ isEnabled: function isEnabled() {
830
+ return false;
831
+ },
832
+ setEnabled: function setEnabled() {},
833
+ clearAll: function clearAll() {},
834
+ isEnabledForType: function isEnabledForType() {
835
+ return false;
836
+ },
837
+ setEnabledForType: function setEnabledForType() {},
838
+ clearForType: function clearForType() {},
839
+ destroy: function destroy() {}
840
+ };
841
+ /**
842
+ * Returns the singleton noop {@link FirestoreContextCache}.
843
+ *
844
+ * Used when no cache factory is configured so that `FirestoreContext.cache` is always defined,
845
+ * avoiding null checks throughout the codebase.
846
+ *
847
+ * @example
848
+ * ```ts
849
+ * const cache = noopFirestoreContextCache();
850
+ * cache.cacheForCollection('user', { defaultTtl: 0 }); // returns noop collection cache
851
+ * cache.isEnabled(); // false
852
+ * ```
853
+ */ function noopFirestoreContextCache() {
854
+ return NOOP_FIRESTORE_CONTEXT_CACHE;
855
+ }
856
+
857
+ function asyncGeneratorStep$k(gen, resolve, reject, _next, _throw, key, arg) {
736
858
  try {
737
859
  var info = gen[key](arg);
738
860
  var value = info.value;
@@ -746,22 +868,22 @@ function asyncGeneratorStep$j(gen, resolve, reject, _next, _throw, key, arg) {
746
868
  Promise.resolve(value).then(_next, _throw);
747
869
  }
748
870
  }
749
- function _async_to_generator$j(fn) {
871
+ function _async_to_generator$k(fn) {
750
872
  return function() {
751
873
  var self = this, args = arguments;
752
874
  return new Promise(function(resolve, reject) {
753
875
  var gen = fn.apply(self, args);
754
876
  function _next(value) {
755
- asyncGeneratorStep$j(gen, resolve, reject, _next, _throw, "next", value);
877
+ asyncGeneratorStep$k(gen, resolve, reject, _next, _throw, "next", value);
756
878
  }
757
879
  function _throw(err) {
758
- asyncGeneratorStep$j(gen, resolve, reject, _next, _throw, "throw", err);
880
+ asyncGeneratorStep$k(gen, resolve, reject, _next, _throw, "throw", err);
759
881
  }
760
882
  _next(undefined);
761
883
  });
762
884
  };
763
885
  }
764
- function _ts_generator$j(thisArg, body) {
886
+ function _ts_generator$k(thisArg, body) {
765
887
  var f, y, t, _ = {
766
888
  label: 0,
767
889
  sent: function() {
@@ -874,9 +996,9 @@ function _ts_generator$j(thisArg, body) {
874
996
  * @see https://cloud.google.com/firestore/docs/samples/firestore-data-set-numeric-increment
875
997
  */ function incrementUpdateWithAccessorFunction(accessor) {
876
998
  return function(data) {
877
- return _async_to_generator$j(function() {
999
+ return _async_to_generator$k(function() {
878
1000
  var updateData;
879
- return _ts_generator$j(this, function(_state) {
1001
+ return _ts_generator$k(this, function(_state) {
880
1002
  updateData = util.filterFalsyAndEmptyValues(data);
881
1003
  // Only update
882
1004
  if (!util.objectHasNoKeys(updateData)) {
@@ -893,7 +1015,7 @@ function _ts_generator$j(thisArg, body) {
893
1015
  };
894
1016
  }
895
1017
 
896
- function asyncGeneratorStep$i(gen, resolve, reject, _next, _throw, key, arg) {
1018
+ function asyncGeneratorStep$j(gen, resolve, reject, _next, _throw, key, arg) {
897
1019
  try {
898
1020
  var info = gen[key](arg);
899
1021
  var value = info.value;
@@ -907,22 +1029,22 @@ function asyncGeneratorStep$i(gen, resolve, reject, _next, _throw, key, arg) {
907
1029
  Promise.resolve(value).then(_next, _throw);
908
1030
  }
909
1031
  }
910
- function _async_to_generator$i(fn) {
1032
+ function _async_to_generator$j(fn) {
911
1033
  return function() {
912
1034
  var self = this, args = arguments;
913
1035
  return new Promise(function(resolve, reject) {
914
1036
  var gen = fn.apply(self, args);
915
1037
  function _next(value) {
916
- asyncGeneratorStep$i(gen, resolve, reject, _next, _throw, "next", value);
1038
+ asyncGeneratorStep$j(gen, resolve, reject, _next, _throw, "next", value);
917
1039
  }
918
1040
  function _throw(err) {
919
- asyncGeneratorStep$i(gen, resolve, reject, _next, _throw, "throw", err);
1041
+ asyncGeneratorStep$j(gen, resolve, reject, _next, _throw, "throw", err);
920
1042
  }
921
1043
  _next(undefined);
922
1044
  });
923
1045
  };
924
1046
  }
925
- function _ts_generator$i(thisArg, body) {
1047
+ function _ts_generator$j(thisArg, body) {
926
1048
  var f, y, t, _ = {
927
1049
  label: 0,
928
1050
  sent: function() {
@@ -1034,9 +1156,9 @@ function _ts_generator$i(thisArg, body) {
1034
1156
  * @see https://firebase.google.com/docs/firestore/manage-data/add-data#update_elements_in_an_array
1035
1157
  */ function arrayUpdateWithAccessorFunction(accessor) {
1036
1158
  return function(data) {
1037
- return _async_to_generator$i(function() {
1159
+ return _async_to_generator$j(function() {
1038
1160
  var updateData;
1039
- return _ts_generator$i(this, function(_state) {
1161
+ return _ts_generator$j(this, function(_state) {
1040
1162
  updateData = util.filterFalsyAndEmptyValues(data);
1041
1163
  // Only update
1042
1164
  if (!util.objectHasNoKeys(updateData)) {
@@ -1158,6 +1280,7 @@ function _is_native_reflect_construct$8() {
1158
1280
  _class_call_check$h(this, AbstractFirestoreDocument);
1159
1281
  _define_property$u(this, "_accessor", void 0);
1160
1282
  _define_property$u(this, "_documentAccessor", void 0);
1283
+ _define_property$u(this, "_cache", void 0);
1161
1284
  _define_property$u(this, "stream$", rxjs.lazyFrom(function() {
1162
1285
  return _this._accessor.stream();
1163
1286
  }));
@@ -1166,6 +1289,7 @@ function _is_native_reflect_construct$8() {
1166
1289
  }));
1167
1290
  this._accessor = accessor;
1168
1291
  this._documentAccessor = documentAccessor;
1292
+ this._cache = documentAccessor.cacheForDocument(accessor.documentRef);
1169
1293
  }
1170
1294
  _create_class$a(AbstractFirestoreDocument, [
1171
1295
  {
@@ -1174,6 +1298,12 @@ function _is_native_reflect_construct$8() {
1174
1298
  return this._accessor;
1175
1299
  }
1176
1300
  },
1301
+ {
1302
+ key: "cache",
1303
+ get: function get() {
1304
+ return this._cache;
1305
+ }
1306
+ },
1177
1307
  {
1178
1308
  key: "documentAccessor",
1179
1309
  get: function get() {
@@ -1226,41 +1356,69 @@ function _is_native_reflect_construct$8() {
1226
1356
  /**
1227
1357
  * Retrieves a DocumentSnapshot of the document as an Observable. Streams based on the input mode.
1228
1358
  *
1359
+ * Passively populates the cache with each emitted snapshot.
1360
+ *
1229
1361
  * @param mode - The stream mode controlling how the Observable emits snapshot updates
1230
1362
  * @returns An Observable that emits DocumentSnapshot values based on the given mode
1231
1363
  */ key: "snapshotStream",
1232
1364
  value: function snapshotStream(mode) {
1233
- return snapshotStreamForAccessor(this.accessor, mode);
1365
+ var _this = this;
1366
+ return snapshotStreamForAccessor(this.accessor, mode).pipe(rxjs$1.tap(function(snap) {
1367
+ var data = snap.data();
1368
+ if (data != null) {
1369
+ _this._cache.set({
1370
+ data: data
1371
+ });
1372
+ }
1373
+ }));
1234
1374
  }
1235
1375
  },
1236
1376
  {
1237
1377
  /**
1238
1378
  * Retrieves the data of the DocumentSnapshot of the document as an Observable. Streams based on the input mode.
1239
1379
  *
1380
+ * Passively populates the cache via {@link snapshotStream}.
1381
+ *
1240
1382
  * @param mode - The stream mode controlling how the Observable emits snapshot data updates
1241
1383
  * @param options - Optional SnapshotOptions for reading the document data
1242
1384
  * @returns An Observable that emits the document data or undefined based on the given mode
1243
1385
  */ key: "snapshotDataStream",
1244
1386
  value: function snapshotDataStream(mode, options) {
1245
- return snapshotStreamDataForAccessor(this.accessor, mode, options);
1387
+ return this.snapshotStream(mode).pipe(rxjs$1.map(function(snap) {
1388
+ return snap.data(options);
1389
+ }));
1246
1390
  }
1247
1391
  },
1248
1392
  {
1249
1393
  /**
1250
- * Retrieves a DocumentSnapshot of the document.
1394
+ * Retrieves a DocumentSnapshot of the document from Firestore.
1251
1395
  *
1252
- * @returns
1396
+ * Passively populates the cache with the fetched snapshot.
1397
+ *
1398
+ * @returns A Promise resolving to the document snapshot
1253
1399
  */ key: "snapshot",
1254
1400
  value: function snapshot() {
1255
- return this.accessor.get();
1401
+ var _this = this;
1402
+ return this.accessor.get().then(function(snap) {
1403
+ var data = snap.data();
1404
+ if (data != null) {
1405
+ _this._cache.set({
1406
+ data: data
1407
+ });
1408
+ }
1409
+ return snap;
1410
+ });
1256
1411
  }
1257
1412
  },
1258
1413
  {
1259
1414
  /**
1260
- * Retrieves the data of the DocumentSnapshot of the document.
1415
+ * Retrieves the data of the document, checking the cache first.
1261
1416
  *
1262
- * @param options
1263
- * @returns
1417
+ * If a fresh cache entry exists, returns it without hitting Firestore.
1418
+ * Otherwise falls through to {@link snapshot} which populates the cache.
1419
+ *
1420
+ * @param options - Optional SnapshotOptions for reading the document data
1421
+ * @returns A Promise resolving to the document data, or undefined if the document does not exist
1264
1422
  */ key: "snapshotData",
1265
1423
  value: function snapshotData(options) {
1266
1424
  return this.snapshot().then(function(x) {
@@ -1283,49 +1441,74 @@ function _is_native_reflect_construct$8() {
1283
1441
  /**
1284
1442
  * Creates the document if it does not exist, using the accessor's create functionality.
1285
1443
  *
1286
- * @param data
1287
- * @returns
1444
+ * Populates the cache with the written data after a successful create.
1445
+ *
1446
+ * @param data - The document data to create
1447
+ * @returns A Promise that resolves when the create completes
1288
1448
  */ key: "create",
1289
1449
  value: function create(data) {
1290
- return this.accessor.create(data);
1450
+ var _this = this;
1451
+ return this.accessor.create(data).then(function(result) {
1452
+ _this._cache.set({
1453
+ data: data
1454
+ });
1455
+ return result;
1456
+ });
1291
1457
  }
1292
1458
  },
1293
1459
  {
1294
1460
  /**
1295
- * Updates the document using the accessor's update functionalty if the document exists. This differs from Firestore's default
1461
+ * Updates the document using the accessor's update functionality if the document exists. This differs from Firestore's default
1296
1462
  * update implementation which does not use the configured converter. This update function will, allowing the use of
1297
1463
  * snapshotConverterFunctions().
1298
1464
  *
1299
- * Throws an exception when it does not exist.
1465
+ * Invalidates the cache entry since partial updates don't provide the full document.
1466
+ * Throws an exception when the document does not exist.
1300
1467
  *
1301
1468
  * @param data - Partial document data to update
1302
1469
  * @param params - Optional update parameters
1303
1470
  * @returns A Promise that resolves when the update completes
1304
1471
  */ key: "update",
1305
1472
  value: function update(data, params) {
1306
- return updateWithAccessorUpdateAndConverterFunction(this.accessor, this.converter)(data, params);
1473
+ var _this = this;
1474
+ return updateWithAccessorUpdateAndConverterFunction(this.accessor, this.converter)(data, params).then(function(result) {
1475
+ _this._cache.invalidate();
1476
+ return result;
1477
+ });
1307
1478
  }
1308
1479
  },
1309
1480
  {
1310
1481
  /**
1311
1482
  * Updates the document using the accessor's increment functionality.
1312
1483
  *
1484
+ * Invalidates the cache entry since increment updates don't provide the full document.
1485
+ *
1313
1486
  * @param data - The increment update to apply to numeric fields
1314
1487
  * @returns A Promise that resolves when the increment update completes
1315
1488
  */ key: "increment",
1316
1489
  value: function increment(data) {
1317
- return incrementUpdateWithAccessorFunction(this.accessor)(data);
1490
+ var _this = this;
1491
+ return incrementUpdateWithAccessorFunction(this.accessor)(data).then(function(result) {
1492
+ _this._cache.invalidate();
1493
+ return result;
1494
+ });
1318
1495
  }
1319
1496
  },
1320
1497
  {
1321
1498
  /**
1322
1499
  * Updates the document using the accessor's array field update functionality.
1323
1500
  *
1501
+ * Invalidates the cache entry since array updates don't provide the full document.
1502
+ *
1324
1503
  * @param data - The array field update to apply (union or remove elements)
1325
1504
  * @returns A Promise that resolves when the array update completes
1326
1505
  */ key: "arrayUpdate",
1327
1506
  value: function arrayUpdate(data) {
1328
- return arrayUpdateWithAccessorFunction(this.accessor)(data);
1507
+ var _this = this;
1508
+ return arrayUpdateWithAccessorFunction(this.accessor)(data).then(function(result) {
1509
+ _this._cache.invalidate();
1510
+ return result;
1511
+ });
1329
1512
  }
1330
1513
  }
1331
1514
  ]);
@@ -1337,7 +1520,7 @@ function _is_native_reflect_construct$8() {
1337
1520
  * @param config - Configuration including converter, accessor factory, and document factory
1338
1521
  * @returns A factory function for creating LimitedFirestoreDocumentAccessor instances
1339
1522
  */ function limitedFirestoreDocumentAccessorFactory(config) {
1340
- var firestoreContext = config.firestoreContext, firestoreAccessorDriver = config.firestoreAccessorDriver, makeDocument = config.makeDocument, interceptAccessorFactory = config.accessorFactory, inputDefaultConverter = config.converter, inputConverterFactory = config.converterFactory, modelIdentity = config.modelIdentity;
1523
+ var firestoreContext = config.firestoreContext, firestoreAccessorDriver = config.firestoreAccessorDriver, makeDocument = config.makeDocument, interceptAccessorFactory = config.accessorFactory, inputDefaultConverter = config.converter, inputConverterFactory = config.converterFactory, modelIdentity = config.modelIdentity, inputCache = config.cache;
1341
1524
  var expectedCollectionName = firestoreAccessorDriver.fuzzedPathForPath ? firestoreAccessorDriver.fuzzedPathForPath(modelIdentity.collectionName) : modelIdentity.collectionName;
1342
1525
  var converterFactory = inputConverterFactory ? function(ref) {
1343
1526
  var _inputConverterFactory;
@@ -1366,10 +1549,17 @@ function _is_native_reflect_construct$8() {
1366
1549
  };
1367
1550
  var databaseContext = context !== null && context !== void 0 ? context : config.firestoreAccessorDriver.defaultContextFactory();
1368
1551
  var dataAccessorFactory = interceptAccessorFactory ? interceptAccessorFactory(databaseContext.accessorFactory) : databaseContext.accessorFactory;
1552
+ // Transaction/batch contexts bypass cache; otherwise bind the collection cache to the document ref
1553
+ var cacheForDocument = context ? function() {
1554
+ return noopFirestoreCollectionDocumentCache();
1555
+ } : function(ref) {
1556
+ return firestoreCollectionDocumentCache(inputCache, ref.path);
1557
+ };
1369
1558
  var documentAccessor = {
1370
1559
  converter: inputDefaultConverter,
1371
1560
  converterFactory: converterFactory,
1372
1561
  modelIdentity: modelIdentity,
1562
+ cacheForDocument: cacheForDocument,
1373
1563
  loadDocumentFrom: function loadDocumentFrom(document) {
1374
1564
  return loadDocument(document.documentRef);
1375
1565
  },
@@ -1500,7 +1690,7 @@ var AbstractFirestoreDocumentWithParent = /*#__PURE__*/ function(AbstractFiresto
1500
1690
  x.loadDocumentForWriteBatch = singleAccessor.loadDocumentForWriteBatch;
1501
1691
  }
1502
1692
 
1503
- function asyncGeneratorStep$h(gen, resolve, reject, _next, _throw, key, arg) {
1693
+ function asyncGeneratorStep$i(gen, resolve, reject, _next, _throw, key, arg) {
1504
1694
  try {
1505
1695
  var info = gen[key](arg);
1506
1696
  var value = info.value;
@@ -1514,22 +1704,22 @@ function asyncGeneratorStep$h(gen, resolve, reject, _next, _throw, key, arg) {
1514
1704
  Promise.resolve(value).then(_next, _throw);
1515
1705
  }
1516
1706
  }
1517
- function _async_to_generator$h(fn) {
1707
+ function _async_to_generator$i(fn) {
1518
1708
  return function() {
1519
1709
  var self = this, args = arguments;
1520
1710
  return new Promise(function(resolve, reject) {
1521
1711
  var gen = fn.apply(self, args);
1522
1712
  function _next(value) {
1523
- asyncGeneratorStep$h(gen, resolve, reject, _next, _throw, "next", value);
1713
+ asyncGeneratorStep$i(gen, resolve, reject, _next, _throw, "next", value);
1524
1714
  }
1525
1715
  function _throw(err) {
1526
- asyncGeneratorStep$h(gen, resolve, reject, _next, _throw, "throw", err);
1716
+ asyncGeneratorStep$i(gen, resolve, reject, _next, _throw, "throw", err);
1527
1717
  }
1528
1718
  _next(undefined);
1529
1719
  });
1530
1720
  };
1531
1721
  }
1532
- function _ts_generator$h(thisArg, body) {
1722
+ function _ts_generator$i(thisArg, body) {
1533
1723
  var f, y, t, _ = {
1534
1724
  label: 0,
1535
1725
  sent: function() {
@@ -1665,9 +1855,9 @@ function _ts_generator$h(thisArg, body) {
1665
1855
  return util.performMakeLoop({
1666
1856
  count: make.count,
1667
1857
  make: function make1(i) {
1668
- return _async_to_generator$h(function() {
1858
+ return _async_to_generator$i(function() {
1669
1859
  var document, data;
1670
- return _ts_generator$h(this, function(_state) {
1860
+ return _ts_generator$i(this, function(_state) {
1671
1861
  switch(_state.label){
1672
1862
  case 0:
1673
1863
  document = newDocumentFn(documentAccessor);
@@ -2026,9 +2216,9 @@ function documentDataWithIdAndKey(snapshot) {
2026
2216
  * @param defaultValue - Fallback value when `document` is nullish or the snapshot is unavailable
2027
2217
  * @returns The result of `use`, or the default value
2028
2218
  */ function useDocumentSnapshot(document, use, defaultValue) {
2029
- return _async_to_generator$h(function() {
2219
+ return _async_to_generator$i(function() {
2030
2220
  var snapshot;
2031
- return _ts_generator$h(this, function(_state) {
2221
+ return _ts_generator$i(this, function(_state) {
2032
2222
  switch(_state.label){
2033
2223
  case 0:
2034
2224
  return [
@@ -2155,8 +2345,8 @@ function documentDataWithIdAndKey(snapshot) {
2155
2345
  return cached;
2156
2346
  }
2157
2347
  function getDocumentSnapshotDataPairsForKeys(keys) {
2158
- return _async_to_generator$h(function() {
2159
- return _ts_generator$h(this, function(_state) {
2348
+ return _async_to_generator$i(function() {
2349
+ return _ts_generator$i(this, function(_state) {
2160
2350
  return [
2161
2351
  2,
2162
2352
  Promise.all(keys.map(function(key) {
@@ -2167,9 +2357,9 @@ function documentDataWithIdAndKey(snapshot) {
2167
2357
  })();
2168
2358
  }
2169
2359
  function getDocumentSnapshotDataPairsWithDataForKeys(keys) {
2170
- return _async_to_generator$h(function() {
2360
+ return _async_to_generator$i(function() {
2171
2361
  var pairs;
2172
- return _ts_generator$h(this, function(_state) {
2362
+ return _ts_generator$i(this, function(_state) {
2173
2363
  switch(_state.label){
2174
2364
  case 0:
2175
2365
  return [
@@ -2311,6 +2501,499 @@ function documentDataWithIdAndKey(snapshot) {
2311
2501
  * @deprecated Use {@link streamDocumentSnapshotsData} instead.
2312
2502
  */ var latestDataFromDocuments = streamDocumentSnapshotsData;
2313
2503
 
2504
+ function asyncGeneratorStep$h(gen, resolve, reject, _next, _throw, key, arg) {
2505
+ try {
2506
+ var info = gen[key](arg);
2507
+ var value = info.value;
2508
+ } catch (error) {
2509
+ reject(error);
2510
+ return;
2511
+ }
2512
+ if (info.done) {
2513
+ resolve(value);
2514
+ } else {
2515
+ Promise.resolve(value).then(_next, _throw);
2516
+ }
2517
+ }
2518
+ function _async_to_generator$h(fn) {
2519
+ return function() {
2520
+ var self = this, args = arguments;
2521
+ return new Promise(function(resolve, reject) {
2522
+ var gen = fn.apply(self, args);
2523
+ function _next(value) {
2524
+ asyncGeneratorStep$h(gen, resolve, reject, _next, _throw, "next", value);
2525
+ }
2526
+ function _throw(err) {
2527
+ asyncGeneratorStep$h(gen, resolve, reject, _next, _throw, "throw", err);
2528
+ }
2529
+ _next(undefined);
2530
+ });
2531
+ };
2532
+ }
2533
+ function _ts_generator$h(thisArg, body) {
2534
+ var f, y, t, _ = {
2535
+ label: 0,
2536
+ sent: function() {
2537
+ if (t[0] & 1) throw t[1];
2538
+ return t[1];
2539
+ },
2540
+ trys: [],
2541
+ ops: []
2542
+ }, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype), d = Object.defineProperty;
2543
+ return d(g, "next", {
2544
+ value: verb(0)
2545
+ }), d(g, "throw", {
2546
+ value: verb(1)
2547
+ }), d(g, "return", {
2548
+ value: verb(2)
2549
+ }), typeof Symbol === "function" && d(g, Symbol.iterator, {
2550
+ value: function() {
2551
+ return this;
2552
+ }
2553
+ }), g;
2554
+ function verb(n) {
2555
+ return function(v) {
2556
+ return step([
2557
+ n,
2558
+ v
2559
+ ]);
2560
+ };
2561
+ }
2562
+ function step(op) {
2563
+ if (f) throw new TypeError("Generator is already executing.");
2564
+ while(g && (g = 0, op[0] && (_ = 0)), _)try {
2565
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
2566
+ if (y = 0, t) op = [
2567
+ op[0] & 2,
2568
+ t.value
2569
+ ];
2570
+ switch(op[0]){
2571
+ case 0:
2572
+ case 1:
2573
+ t = op;
2574
+ break;
2575
+ case 4:
2576
+ _.label++;
2577
+ return {
2578
+ value: op[1],
2579
+ done: false
2580
+ };
2581
+ case 5:
2582
+ _.label++;
2583
+ y = op[1];
2584
+ op = [
2585
+ 0
2586
+ ];
2587
+ continue;
2588
+ case 7:
2589
+ op = _.ops.pop();
2590
+ _.trys.pop();
2591
+ continue;
2592
+ default:
2593
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
2594
+ _ = 0;
2595
+ continue;
2596
+ }
2597
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
2598
+ _.label = op[1];
2599
+ break;
2600
+ }
2601
+ if (op[0] === 6 && _.label < t[1]) {
2602
+ _.label = t[1];
2603
+ t = op;
2604
+ break;
2605
+ }
2606
+ if (t && _.label < t[2]) {
2607
+ _.label = t[2];
2608
+ _.ops.push(op);
2609
+ break;
2610
+ }
2611
+ if (t[2]) _.ops.pop();
2612
+ _.trys.pop();
2613
+ continue;
2614
+ }
2615
+ op = body.call(thisArg, _);
2616
+ } catch (e) {
2617
+ op = [
2618
+ 6,
2619
+ e
2620
+ ];
2621
+ y = 0;
2622
+ } finally{
2623
+ f = t = 0;
2624
+ }
2625
+ if (op[0] & 5) throw op[1];
2626
+ return {
2627
+ value: op[0] ? op[1] : void 0,
2628
+ done: true
2629
+ };
2630
+ }
2631
+ }
2632
+ /**
2633
+ * Default TTL used by the in-memory cache when no TTL is specified.
2634
+ *
2635
+ * Set to 5 minutes.
2636
+ */ var IN_MEMORY_CACHE_DEFAULT_TTL = 5 * 60 * 1000;
2637
+ /**
2638
+ * Creates an in-memory {@link FirestoreCollectionCacheDelegate} backed by a Map.
2639
+ *
2640
+ * @example
2641
+ * ```ts
2642
+ * const delegate = inMemoryFirestoreCollectionCacheDelegate<UserData>();
2643
+ * ```
2644
+ */ function inMemoryFirestoreCollectionCacheDelegate() {
2645
+ var entries = new Map();
2646
+ return {
2647
+ get: function get(key) {
2648
+ return entries.get(key);
2649
+ },
2650
+ set: function set(key, entry) {
2651
+ return entries.set(key, entry);
2652
+ },
2653
+ delete: function _delete(key) {
2654
+ entries.delete(key);
2655
+ },
2656
+ clear: function clear() {
2657
+ return entries.clear();
2658
+ }
2659
+ };
2660
+ }
2661
+ /**
2662
+ * Creates a no-storage {@link FirestoreCollectionCacheDelegate} that discards all data.
2663
+ *
2664
+ * Used by {@link readLoggingFirestoreContextCache} where only event emission matters.
2665
+ *
2666
+ * @example
2667
+ * ```ts
2668
+ * const delegate = noopFirestoreCollectionCacheDelegate<UserData>();
2669
+ * ```
2670
+ */ function noopFirestoreCollectionCacheDelegate() {
2671
+ return {
2672
+ get: function get() {
2673
+ return undefined;
2674
+ },
2675
+ set: function set() {},
2676
+ delete: function _delete() {},
2677
+ clear: function clear() {}
2678
+ };
2679
+ }
2680
+ /**
2681
+ * Creates a {@link FirestoreCollectionCache} with shared TTL, event, and enabled/disabled logic.
2682
+ *
2683
+ * The actual storage is handled by the provided {@link FirestoreCollectionCacheDelegate}.
2684
+ *
2685
+ * @template T - The document data type
2686
+ * @param config - Configuration including TTL, enabled check, event emitter, and delegate
2687
+ * @returns A collection cache instance
2688
+ */ function makeFirestoreCollectionCache(config) {
2689
+ var defaultTtl = config.defaultTtl, isEnabled = config.isEnabled, emitEvent = config.emitEvent, delegate = config.delegate;
2690
+ function isFresh(entry, maxTtl) {
2691
+ var age = Date.now() - entry.cachedAt.getTime();
2692
+ return age < maxTtl;
2693
+ }
2694
+ var cache = {
2695
+ defaultTtl: defaultTtl,
2696
+ get: function get(key, maxTtl) {
2697
+ var result;
2698
+ if (isEnabled()) {
2699
+ var entry = delegate.get(key);
2700
+ var effectiveTtl = maxTtl !== null && maxTtl !== void 0 ? maxTtl : defaultTtl;
2701
+ if (entry && isFresh(entry, effectiveTtl)) {
2702
+ emitEvent('hit', key);
2703
+ result = entry;
2704
+ } else {
2705
+ if (entry) {
2706
+ delegate.delete(key);
2707
+ }
2708
+ emitEvent('miss', key);
2709
+ }
2710
+ }
2711
+ return result;
2712
+ },
2713
+ set: function set(key, input) {
2714
+ if (isEnabled()) {
2715
+ var entry = {
2716
+ key: key,
2717
+ data: input.data,
2718
+ cachedAt: new Date()
2719
+ };
2720
+ delegate.set(key, entry);
2721
+ emitEvent('update', key);
2722
+ }
2723
+ },
2724
+ invalidate: function invalidate(key) {
2725
+ if (isEnabled()) {
2726
+ delegate.delete(key);
2727
+ emitEvent('invalidate', key);
2728
+ }
2729
+ },
2730
+ clear: function clear() {
2731
+ delegate.clear();
2732
+ },
2733
+ instance: function instance() {
2734
+ return makeFirestoreCollectionCacheInstance(cache);
2735
+ },
2736
+ destroy: function destroy() {
2737
+ delegate.clear();
2738
+ }
2739
+ };
2740
+ return cache;
2741
+ }
2742
+ /**
2743
+ * Creates a {@link FirestoreContextCache} with shared event handling, enable/disable controls,
2744
+ * and per-type management. The actual cache storage for each collection is handled by
2745
+ * delegates created via {@link MakeFirestoreContextCacheConfig.createDelegate}.
2746
+ *
2747
+ * This is the shared foundation used by both {@link inMemoryFirestoreContextCache} and
2748
+ * {@link readLoggingFirestoreContextCache}.
2749
+ *
2750
+ * @param config - Configuration including default TTL and delegate factory
2751
+ * @returns A new context cache
2752
+ *
2753
+ * @example
2754
+ * ```ts
2755
+ * const contextCache = makeFirestoreContextCache({
2756
+ * defaultTtl: 60000,
2757
+ * createDelegate: () => inMemoryFirestoreCollectionCacheDelegate()
2758
+ * });
2759
+ * ```
2760
+ */ function makeFirestoreContextCache(config) {
2761
+ var globalDefaultTtl = config.defaultTtl, createDelegate = config.createDelegate, mapEvents$ = config.mapEvents$;
2762
+ var collectionCaches = new Map();
2763
+ var disabledTypes = new Set();
2764
+ var eventsSubject = new rxjs$1.Subject();
2765
+ var globalEnabled = true;
2766
+ var rawEvents$ = eventsSubject.asObservable();
2767
+ var events$ = mapEvents$ ? mapEvents$(rawEvents$) : rawEvents$;
2768
+ function emitEvent(type, collectionType, key) {
2769
+ eventsSubject.next({
2770
+ type: type,
2771
+ collectionType: collectionType,
2772
+ key: key !== null && key !== void 0 ? key : null,
2773
+ timestamp: new Date()
2774
+ });
2775
+ }
2776
+ function isEffectivelyEnabled(collectionType) {
2777
+ return globalEnabled && !disabledTypes.has(collectionType);
2778
+ }
2779
+ var contextCache = {
2780
+ cacheForCollection: function cacheForCollection(collectionType, collectionConfig) {
2781
+ var cache = collectionCaches.get(collectionType);
2782
+ if (!cache) {
2783
+ var _collectionConfig_defaultTtl;
2784
+ cache = makeFirestoreCollectionCache({
2785
+ defaultTtl: (_collectionConfig_defaultTtl = collectionConfig.defaultTtl) !== null && _collectionConfig_defaultTtl !== void 0 ? _collectionConfig_defaultTtl : globalDefaultTtl,
2786
+ isEnabled: function isEnabled() {
2787
+ return isEffectivelyEnabled(collectionType);
2788
+ },
2789
+ emitEvent: function emitEvent1(type, key) {
2790
+ return emitEvent(type, collectionType, key);
2791
+ },
2792
+ delegate: createDelegate(collectionType)
2793
+ });
2794
+ collectionCaches.set(collectionType, cache);
2795
+ }
2796
+ return cache;
2797
+ },
2798
+ events$: events$,
2799
+ get disabledTypes () {
2800
+ return disabledTypes;
2801
+ },
2802
+ isEnabled: function isEnabled() {
2803
+ return globalEnabled;
2804
+ },
2805
+ setEnabled: function setEnabled(enabled) {
2806
+ globalEnabled = enabled;
2807
+ },
2808
+ clearAll: function clearAll() {
2809
+ collectionCaches.forEach(function(cache) {
2810
+ return cache.clear();
2811
+ });
2812
+ },
2813
+ isEnabledForType: function isEnabledForType(collectionType) {
2814
+ return isEffectivelyEnabled(collectionType);
2815
+ },
2816
+ setEnabledForType: function setEnabledForType(collectionType, enabled) {
2817
+ if (enabled) {
2818
+ disabledTypes.delete(collectionType);
2819
+ } else {
2820
+ disabledTypes.add(collectionType);
2821
+ }
2822
+ var eventType = enabled ? 'enable_collection' : 'disable_collection';
2823
+ emitEvent(eventType, collectionType);
2824
+ },
2825
+ clearForType: function clearForType(collectionType) {
2826
+ var cache = collectionCaches.get(collectionType);
2827
+ if (cache) {
2828
+ cache.clear();
2829
+ }
2830
+ },
2831
+ destroy: function destroy() {
2832
+ eventsSubject.complete();
2833
+ collectionCaches.forEach(function(cache) {
2834
+ return cache.destroy();
2835
+ });
2836
+ collectionCaches.clear();
2837
+ }
2838
+ };
2839
+ return contextCache;
2840
+ }
2841
+ // MARK: In-Memory Cache
2842
+ /**
2843
+ * Creates a {@link FirestoreContextCacheFactory} that stores cached documents in memory.
2844
+ *
2845
+ * Uses simple Map-based storage with TTL-based expiration. Suitable for
2846
+ * client-side caching where the application lifecycle matches the cache lifecycle.
2847
+ *
2848
+ * @returns A factory function that creates in-memory context caches
2849
+ *
2850
+ * @example
2851
+ * ```ts
2852
+ * const factory = inMemoryFirestoreContextCacheFactory();
2853
+ * const contextCache = factory({ defaultTtl: 60000 });
2854
+ * ```
2855
+ */ function inMemoryFirestoreContextCacheFactory() {
2856
+ return function(config) {
2857
+ return inMemoryFirestoreContextCache(config);
2858
+ };
2859
+ }
2860
+ /**
2861
+ * Creates an in-memory {@link FirestoreContextCache} that manages per-collection
2862
+ * caches with TTL-based expiration, per-type enable/disable, and event streaming.
2863
+ *
2864
+ * @param config - Optional configuration
2865
+ * @returns A new context cache
2866
+ *
2867
+ * @example
2868
+ * ```ts
2869
+ * const contextCache = inMemoryFirestoreContextCache({ defaultTtl: 60000 });
2870
+ * const userCache = contextCache.cacheForCollection<UserData>('user', { defaultTtl: 30000 });
2871
+ * userCache.set('users/abc', { data: userData });
2872
+ * ```
2873
+ */ function inMemoryFirestoreContextCache(config) {
2874
+ var _ref;
2875
+ return makeFirestoreContextCache({
2876
+ defaultTtl: (_ref = config === null || config === void 0 ? void 0 : config.defaultTtl) !== null && _ref !== void 0 ? _ref : IN_MEMORY_CACHE_DEFAULT_TTL,
2877
+ createDelegate: function createDelegate() {
2878
+ return inMemoryFirestoreCollectionCacheDelegate();
2879
+ }
2880
+ });
2881
+ }
2882
+ // MARK: Read-Logging Cache
2883
+ /**
2884
+ * Creates a {@link FirestoreContextCacheFactory} that emits events for all cache interactions
2885
+ * but does not actually store any data.
2886
+ *
2887
+ * Useful for analytics, debugging, and monitoring read patterns without the
2888
+ * memory overhead of actual caching.
2889
+ *
2890
+ * @returns A factory function that creates read-logging context caches
2891
+ *
2892
+ * @example
2893
+ * ```ts
2894
+ * const factory = readLoggingFirestoreContextCacheFactory();
2895
+ * const contextCache = factory();
2896
+ * contextCache.events$.subscribe((event) => console.log(event));
2897
+ * ```
2898
+ */ function readLoggingFirestoreContextCacheFactory() {
2899
+ return function(config) {
2900
+ return readLoggingFirestoreContextCache(config);
2901
+ };
2902
+ }
2903
+ /**
2904
+ * Creates a {@link FirestoreContextCache} that emits events for all cache interactions
2905
+ * but does not actually store any data. Every `get()` call results in a 'miss' event.
2906
+ *
2907
+ * Useful for tracking read patterns, debugging, and monitoring which documents
2908
+ * are accessed and how often, without the memory overhead of actual caching.
2909
+ *
2910
+ * @param config - Optional configuration
2911
+ * @returns A new read-logging context cache
2912
+ *
2913
+ * @example
2914
+ * ```ts
2915
+ * const contextCache = readLoggingFirestoreContextCache();
2916
+ * contextCache.events$.subscribe((event) => {
2917
+ * console.log(`${event.type}: ${event.collectionType} ${event.key}`);
2918
+ * });
2919
+ * ```
2920
+ */ function readLoggingFirestoreContextCache(config) {
2921
+ var _ref;
2922
+ return makeFirestoreContextCache({
2923
+ defaultTtl: (_ref = config === null || config === void 0 ? void 0 : config.defaultTtl) !== null && _ref !== void 0 ? _ref : IN_MEMORY_CACHE_DEFAULT_TTL,
2924
+ createDelegate: function createDelegate() {
2925
+ return noopFirestoreCollectionCacheDelegate();
2926
+ },
2927
+ mapEvents$: function mapEvents$(events$) {
2928
+ return events$.pipe(rxjs$1.filter(function(event) {
2929
+ return event.type !== 'miss';
2930
+ }));
2931
+ }
2932
+ });
2933
+ }
2934
+ // MARK: Cache Instance
2935
+ /**
2936
+ * Creates an operation-scoped {@link FirestoreCollectionCacheInstance} that deduplicates
2937
+ * concurrent reads and uses the parent cache as a warm start.
2938
+ *
2939
+ * @template T - The document data type
2940
+ * @param parentCache - The parent collection cache for warm-start lookups
2941
+ * @returns An operation-scoped cache instance
2942
+ */ function makeFirestoreCollectionCacheInstance(parentCache) {
2943
+ var localEntries = new Map();
2944
+ var inFlight = new Map();
2945
+ var instance = {
2946
+ get: function get(key, maxTtl) {
2947
+ // Check local instance cache first
2948
+ var result = localEntries.get(key);
2949
+ // Fall back to parent cache
2950
+ if (!result) {
2951
+ result = parentCache.get(key, maxTtl);
2952
+ if (result) {
2953
+ localEntries.set(key, result);
2954
+ }
2955
+ }
2956
+ return result;
2957
+ },
2958
+ getOrFetch: function getOrFetch(key, fetchFn) {
2959
+ return _async_to_generator$h(function() {
2960
+ var cached, existing, fetchPromise;
2961
+ return _ts_generator$h(this, function(_state) {
2962
+ // Check local cache first
2963
+ cached = localEntries.get(key);
2964
+ if (cached) {
2965
+ return [
2966
+ 2,
2967
+ cached
2968
+ ];
2969
+ }
2970
+ // Check for in-flight request
2971
+ existing = inFlight.get(key);
2972
+ if (existing) {
2973
+ return [
2974
+ 2,
2975
+ existing
2976
+ ];
2977
+ }
2978
+ // Start new fetch
2979
+ fetchPromise = fetchFn().then(function(entry) {
2980
+ localEntries.set(key, entry);
2981
+ parentCache.set(key, entry);
2982
+ inFlight.delete(key);
2983
+ return entry;
2984
+ });
2985
+ inFlight.set(key, fetchPromise);
2986
+ return [
2987
+ 2,
2988
+ fetchPromise
2989
+ ];
2990
+ });
2991
+ })();
2992
+ }
2993
+ };
2994
+ return instance;
2995
+ }
2996
+
2314
2997
  /**
2315
2998
  * Platform-agnostic Firestore type definitions.
2316
2999
  *
@@ -7093,9 +7776,14 @@ var FIRESTORE_DUMMY_MODEL_KEY = 'dummymodel/dummykey';
7093
7776
  * @param inputConfig - Configuration for the collection
7094
7777
  * @returns A fully configured FirestoreCollection instance
7095
7778
  */ function makeFirestoreCollection(inputConfig) {
7779
+ var _config_defaultTtl;
7096
7780
  var config = inputConfig;
7097
7781
  var modelIdentity = config.modelIdentity, collection = config.collection, firestoreContext = config.firestoreContext, firestoreAccessorDriver = config.firestoreAccessorDriver;
7098
7782
  config.queryLike = collection;
7783
+ var cache = firestoreContext.cache.cacheForCollection(modelIdentity.collectionType, {
7784
+ defaultTtl: (_config_defaultTtl = config.defaultTtl) !== null && _config_defaultTtl !== void 0 ? _config_defaultTtl : 0
7785
+ });
7786
+ config.cache = cache;
7099
7787
  var documentAccessor = firestoreDocumentAccessorFactory(config);
7100
7788
  var documentAccessorExtension = firestoreDocumentAccessorContextExtension({
7101
7789
  documentAccessor: documentAccessor,
@@ -7108,6 +7796,7 @@ var FIRESTORE_DUMMY_MODEL_KEY = 'dummymodel/dummykey';
7108
7796
  var query = queryFactory.query;
7109
7797
  return _object_spread_props$f(_object_spread$j({
7110
7798
  config: config,
7799
+ cache: cache,
7111
7800
  modelIdentity: modelIdentity,
7112
7801
  collection: collection,
7113
7802
  queryLike: collection,
@@ -7204,7 +7893,12 @@ function _object_spread_props$e(target, source) {
7204
7893
  * @param config - Configuration for the collection group
7205
7894
  * @returns A fully configured FirestoreCollectionGroup instance
7206
7895
  */ function makeFirestoreCollectionGroup(config) {
7896
+ var _config_defaultTtl;
7207
7897
  var modelIdentity = config.modelIdentity, queryLike = config.queryLike, firestoreContext = config.firestoreContext, firestoreAccessorDriver = config.firestoreAccessorDriver;
7898
+ var cache = firestoreContext.cache.cacheForCollection(modelIdentity.collectionType, {
7899
+ defaultTtl: (_config_defaultTtl = config.defaultTtl) !== null && _config_defaultTtl !== void 0 ? _config_defaultTtl : 0
7900
+ });
7901
+ config.cache = cache;
7208
7902
  // Create the document accessor for loading documents
7209
7903
  var documentAccessor = limitedFirestoreDocumentAccessorFactory(config);
7210
7904
  // Create the document accessor extension with context
@@ -7223,6 +7917,7 @@ function _object_spread_props$e(target, source) {
7223
7917
  // Return the fully constructed collection group
7224
7918
  return _object_spread_props$e(_object_spread$i({
7225
7919
  config: config,
7920
+ cache: cache,
7226
7921
  queryLike: queryLike,
7227
7922
  modelIdentity: modelIdentity,
7228
7923
  firestoreContext: firestoreContext
@@ -7381,8 +8076,11 @@ function _unsupported_iterable_to_array$9(o, minLen) {
7381
8076
  * @param drivers - The Firestore drivers to use in created contexts
7382
8077
  * @returns A factory function that creates FirestoreContext instances
7383
8078
  */ function firestoreContextFactory(drivers) {
7384
- return function(firestore) {
8079
+ return function(firestore, params) {
7385
8080
  var _drivers_firestoreAccessorDriver;
8081
+ var _ref;
8082
+ var _params_firestoreContextCacheFactory;
8083
+ var contextCache = (_ref = params === null || params === void 0 ? void 0 : (_params_firestoreContextCacheFactory = params.firestoreContextCacheFactory) === null || _params_firestoreContextCacheFactory === void 0 ? void 0 : _params_firestoreContextCacheFactory.call(params)) !== null && _ref !== void 0 ? _ref : noopFirestoreContextCache();
7386
8084
  var makeFirestoreCollectionConfig = function makeFirestoreCollectionConfig(config) {
7387
8085
  var collection = config.collection;
7388
8086
  var queryLike = collection !== null && collection !== void 0 ? collection : config.queryLike;
@@ -7405,6 +8103,7 @@ function _unsupported_iterable_to_array$9(o, minLen) {
7405
8103
  var context = {
7406
8104
  firestore: firestore,
7407
8105
  drivers: drivers,
8106
+ cache: contextCache,
7408
8107
  collectionGroup: function collectionGroup(collectionId) {
7409
8108
  return drivers.firestoreAccessorDriver.collectionGroup(firestore, collectionId);
7410
8109
  },
@@ -8750,8 +9449,13 @@ var _obj;
8750
9449
  *
8751
9450
  * @example
8752
9451
  * ```ts
9452
+ * // Without caching
8753
9453
  * const context = clientFirebaseFirestoreContextFactory(firestore);
8754
- * const collection = context.collection(myCollectionConfig);
9454
+ *
9455
+ * // With caching
9456
+ * const context = clientFirebaseFirestoreContextFactory(firestore, {
9457
+ * firestoreContextCacheFactory: inMemoryFirestoreContextCacheFactory()
9458
+ * });
8755
9459
  * ```
8756
9460
  */ var clientFirebaseFirestoreContextFactory = firestoreContextFactory(firebaseFirestoreClientDrivers());
8757
9461
 
@@ -18184,6 +18888,7 @@ exports.FirebaseDevelopmentFunctions = FirebaseDevelopmentFunctions;
18184
18888
  exports.FirebaseModelPermissionServiceInstance = FirebaseModelPermissionServiceInstance;
18185
18889
  exports.FirebaseServerError = FirebaseServerError;
18186
18890
  exports.HIGH_UPLOADED_FILE_TYPE_DETERMINATION_LEVEL = HIGH_UPLOADED_FILE_TYPE_DETERMINATION_LEVEL;
18891
+ exports.IN_MEMORY_CACHE_DEFAULT_TTL = IN_MEMORY_CACHE_DEFAULT_TTL;
18187
18892
  exports.LOW_UPLOADED_FILE_TYPE_DETERMINATION_LEVEL = LOW_UPLOADED_FILE_TYPE_DETERMINATION_LEVEL;
18188
18893
  exports.MAX_FIRESTORE_MAP_ZOOM_LEVEL_VALUE = MAX_FIRESTORE_MAP_ZOOM_LEVEL_VALUE;
18189
18894
  exports.MIN_FIRESTORE_MAP_ZOOM_LEVEL_VALUE = MIN_FIRESTORE_MAP_ZOOM_LEVEL_VALUE;
@@ -18378,6 +19083,7 @@ exports.firestoreBoolean = firestoreBoolean;
18378
19083
  exports.firestoreClientAccessorDriver = firestoreClientAccessorDriver;
18379
19084
  exports.firestoreClientArrayUpdateToUpdateData = firestoreClientArrayUpdateToUpdateData;
18380
19085
  exports.firestoreClientIncrementUpdateToUpdateData = firestoreClientIncrementUpdateToUpdateData;
19086
+ exports.firestoreCollectionDocumentCache = firestoreCollectionDocumentCache;
18381
19087
  exports.firestoreCollectionQueryFactory = firestoreCollectionQueryFactory;
18382
19088
  exports.firestoreContextFactory = firestoreContextFactory;
18383
19089
  exports.firestoreDate = firestoreDate;
@@ -18507,6 +19213,9 @@ exports.grantModelRolesOnlyIfFunction = grantModelRolesOnlyIfFunction;
18507
19213
  exports.grantStorageFileRolesForUserAuthFunction = grantStorageFileRolesForUserAuthFunction;
18508
19214
  exports.inContextFirebaseModelServiceFactory = inContextFirebaseModelServiceFactory;
18509
19215
  exports.inContextFirebaseModelsServiceFactory = inContextFirebaseModelsServiceFactory;
19216
+ exports.inMemoryFirestoreCollectionCacheDelegate = inMemoryFirestoreCollectionCacheDelegate;
19217
+ exports.inMemoryFirestoreContextCache = inMemoryFirestoreContextCache;
19218
+ exports.inMemoryFirestoreContextCacheFactory = inMemoryFirestoreContextCacheFactory;
18510
19219
  exports.incrementUpdateWithAccessorFunction = incrementUpdateWithAccessorFunction;
18511
19220
  exports.inferKeyFromTwoWayFlatFirestoreModelKey = inferKeyFromTwoWayFlatFirestoreModelKey;
18512
19221
  exports.inferNotificationBoxRelatedModelKey = inferNotificationBoxRelatedModelKey;
@@ -18563,6 +19272,7 @@ exports.makeDocuments = makeDocuments;
18563
19272
  exports.makeFirestoreCollection = makeFirestoreCollection;
18564
19273
  exports.makeFirestoreCollectionGroup = makeFirestoreCollectionGroup;
18565
19274
  exports.makeFirestoreCollectionWithParent = makeFirestoreCollectionWithParent;
19275
+ exports.makeFirestoreContextCache = makeFirestoreContextCache;
18566
19276
  exports.makeFirestoreItemPageIteratorDelegate = makeFirestoreItemPageIteratorDelegate;
18567
19277
  exports.makeFirestoreQueryConstraintFunctionsDriver = makeFirestoreQueryConstraintFunctionsDriver;
18568
19278
  exports.makeRootSingleItemFirestoreCollection = makeRootSingleItemFirestoreCollection;
@@ -18582,6 +19292,10 @@ exports.newDocuments = newDocuments;
18582
19292
  exports.newNotificationBoxRecipientForUid = newNotificationBoxRecipientForUid;
18583
19293
  exports.noContentNotificationMessageFunctionFactory = noContentNotificationMessageFunctionFactory;
18584
19294
  exports.noStringFormatInStorageUploadOptionsError = noStringFormatInStorageUploadOptionsError;
19295
+ exports.noopFirestoreCollectionCache = noopFirestoreCollectionCache;
19296
+ exports.noopFirestoreCollectionCacheDelegate = noopFirestoreCollectionCacheDelegate;
19297
+ exports.noopFirestoreCollectionDocumentCache = noopFirestoreCollectionDocumentCache;
19298
+ exports.noopFirestoreContextCache = noopFirestoreContextCache;
18585
19299
  exports.notificationBoxCollectionReference = notificationBoxCollectionReference;
18586
19300
  exports.notificationBoxConverter = notificationBoxConverter;
18587
19301
  exports.notificationBoxFirestoreCollection = notificationBoxFirestoreCollection;
@@ -18673,6 +19387,8 @@ exports.processAllQueuedStorageFilesParamsType = processAllQueuedStorageFilesPar
18673
19387
  exports.processStorageFileParamsType = processStorageFileParamsType;
18674
19388
  exports.readFirestoreModelKey = readFirestoreModelKey;
18675
19389
  exports.readFirestoreModelKeyFromDocumentSnapshot = readFirestoreModelKeyFromDocumentSnapshot;
19390
+ exports.readLoggingFirestoreContextCache = readLoggingFirestoreContextCache;
19391
+ exports.readLoggingFirestoreContextCacheFactory = readLoggingFirestoreContextCacheFactory;
18676
19392
  exports.regenerateAllFlaggedStorageFileGroupsContentParamsType = regenerateAllFlaggedStorageFileGroupsContentParamsType;
18677
19393
  exports.regenerateStorageFileGroupContentParamsType = regenerateStorageFileGroupContentParamsType;
18678
19394
  exports.replaceConstraints = replaceConstraints;