@dereekb/dbx-firebase 9.2.0 → 9.3.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.
@@ -32,7 +32,7 @@ import { provideFunctions, getFunctions, connectFunctionsEmulator, Functions } f
32
32
  import * as i1$3 from '@angular/fire/firestore';
33
33
  import { provideFirestore, getFirestore, connectFirestoreEmulator, enableIndexedDbPersistence, Firestore } from '@angular/fire/firestore';
34
34
  import { HTTP_INTERCEPTORS } from '@angular/common/http';
35
- import { clientFirebaseFirestoreContextFactory, iterationQueryDocChangeWatcher, firebaseQueryItemAccumulator, firestoreModelKeysFromDocuments, firestoreModelIdsFromDocuments, documentReferencesFromDocuments, getDocumentSnapshots, getDataFromDocumentSnapshots, streamDocumentSnapshots, dataFromDocumentSnapshots, loadDocumentsForKeys, loadDocumentsForDocumentReferences, loadDocumentsForIds, firestoreModelIdsFromKey, firestoreModelKeyPartPairs, firestoreModelKeyPairObject, documentDataWithId, clientFirebaseStorageContextFactory } from '@dereekb/firebase';
35
+ import { clientFirebaseFirestoreContextFactory, iterationQueryDocChangeWatcher, firebaseQuerySnapshotAccumulator, firebaseQueryItemAccumulator, firestoreModelKeysFromDocuments, firestoreModelIdsFromDocuments, documentReferencesFromDocuments, getDocumentSnapshots, getDataFromDocumentSnapshots, streamDocumentSnapshots, dataFromDocumentSnapshots, loadDocumentsForKeys, loadDocumentsForDocumentReferences, loadDocumentsForIds, firestoreModelIdsFromKey, firestoreModelKeyPartPairs, firestoreModelKeyPairObject, documentDataWithIdAndKey, clientFirebaseStorageContextFactory } from '@dereekb/firebase';
36
36
 
37
37
  /**
38
38
  * Enables debug token generation for AppCheck by setting FIREBASE_APPCHECK_DEBUG_TOKEN in the browser's self/window.
@@ -1989,6 +1989,10 @@ class DbxFirebaseCollectionChangeTriggerInstance {
1989
1989
  /**
1990
1990
  * Creates a new DbxFirebaseCollectionChangeWatcher, set the modes to "auto", and creates a new DbxFirebaseCollectionChangeTriggerInstance.
1991
1991
  *
1992
+ * If no trigger function is provided it will default to resetting the store.
1993
+ *
1994
+ * NOTE: Don't forget to initialize the DbxFirebaseCollectionChangeTriggerInstance and handle other lifecycle changes.
1995
+ *
1992
1996
  * @param store
1993
1997
  * @param triggerFunction
1994
1998
  * @returns
@@ -1997,7 +2001,9 @@ function dbxFirebaseCollectionChangeTriggerForStore(store, triggerFunction) {
1997
2001
  return dbxFirebaseCollectionChangeTrigger({
1998
2002
  watcher: dbxFirebaseCollectionChangeWatcher(store, 'auto'),
1999
2003
  destroyWatcherOnDestroy: true,
2000
- triggerFunction
2004
+ triggerFunction: triggerFunction !== null && triggerFunction !== void 0 ? triggerFunction : (() => {
2005
+ store.restart();
2006
+ })
2001
2007
  });
2002
2008
  }
2003
2009
  function dbxFirebaseCollectionChangeTriggerForWatcher(watcher, triggerFunction) {
@@ -2039,7 +2045,18 @@ class DbxFirebaseCollectionLoaderInstance {
2039
2045
  }), cleanupDestroyable(), // cleanup the iteration
2040
2046
  shareReplay(1));
2041
2047
  this.queryChangeWatcher$ = this.firestoreIteration$.pipe(map((instance) => iterationQueryDocChangeWatcher({ instance })), shareReplay(1));
2048
+ this.snapshotAccumulator$ = this.firestoreIteration$.pipe(map((x) => firebaseQuerySnapshotAccumulator(x)), cleanupDestroyable(), shareReplay(1));
2049
+ this.snapshotAccumulatorDocumentRefs$ = this.snapshotAccumulator$.pipe(switchMap((x) => x.allItems$.pipe(map((y) => y.map((z) => z.map((zz) => zz.ref))))), shareReplay(1));
2050
+ this.snapshotAccumulatorDocuments$ = combineLatest([this.collection$.pipe(filterMaybe()), this.snapshotAccumulatorDocumentRefs$]).pipe(map(([collection, documentRefs]) => {
2051
+ const accessor = collection.documentAccessor();
2052
+ return documentRefs.map((y) => y.map((z) => accessor.loadDocument(z)));
2053
+ }), shareReplay(1));
2042
2054
  this.accumulator$ = this.firestoreIteration$.pipe(map((x) => firebaseQueryItemAccumulator(x)), cleanupDestroyable(), shareReplay(1));
2055
+ this.accumulatorItems$ = this.accumulator$.pipe(switchMap((x) => x.allItems$), shareReplay(1));
2056
+ this.hasDocuments$ = this.firestoreIteration$.pipe(switchMap((x) => x.firstState$.pipe(map((x) => { var _a; return Boolean((_a = x.value) === null || _a === void 0 ? void 0 : _a.length); }))), shareReplay(1));
2057
+ this.allDocumentRefs$ = this.snapshotAccumulatorDocumentRefs$.pipe(map((x) => x.flat()), shareReplay(1));
2058
+ this.allDocuments$ = this.snapshotAccumulatorDocuments$.pipe(map((x) => x.flat()), shareReplay(1));
2059
+ this.allDocumentData$ = this.accumulatorItems$.pipe(map((x) => x.flat()), shareReplay(1));
2043
2060
  this.pageLoadingState$ = this.accumulator$.pipe(switchMap((x) => accumulatorFlattenPageListLoadingState(x)), shareReplay(1));
2044
2061
  }
2045
2062
  init() {
@@ -2589,6 +2606,10 @@ class AbstractDbxFirebaseCollectionStore extends LockSetComponentStore {
2589
2606
  this.queryChangeWatcher$ = this.loader$.pipe(switchMap((x) => x.queryChangeWatcher$));
2590
2607
  this.accumulator$ = this.loader$.pipe(switchMap((x) => x.accumulator$));
2591
2608
  this.pageLoadingState$ = this.loader$.pipe(switchMap((x) => x.pageLoadingState$));
2609
+ this.hasDocuments$ = this.loader$.pipe(switchMap((x) => x.hasDocuments$));
2610
+ this.allDocumentRefs$ = this.loader$.pipe(switchMap((x) => x.allDocumentRefs$));
2611
+ this.allDocuments$ = this.loader$.pipe(switchMap((x) => x.allDocuments$));
2612
+ this.allDocumentData$ = this.loader$.pipe(switchMap((x) => x.allDocumentData$));
2592
2613
  this.setFirestoreCollection = this.updater((state, firestoreCollection) => (Object.assign(Object.assign({}, state), { firestoreCollection })));
2593
2614
  }
2594
2615
  }
@@ -2637,6 +2658,10 @@ class AbstractDbxFirebaseDocumentStore extends LockSetComponentStore {
2637
2658
  }
2638
2659
  return document;
2639
2660
  }), distinctUntilChanged(), shareReplay(1));
2661
+ /**
2662
+ * Whether or not an id/ref/key has been input and currentDocument is not null.
2663
+ */
2664
+ this.hasRef$ = this.currentDocument$.pipe(map((x) => (x === null || x === void 0 ? void 0 : x.documentRef) != null), distinctUntilChanged(), shareReplay(1));
2640
2665
  this.document$ = this.currentDocument$.pipe(filterMaybe(), distinctUntilChanged(), shareReplay(1));
2641
2666
  this.documentLoadingState$ = this.currentDocument$.pipe(map((x) => (x ? successResult(x) : beginLoading())), shareReplay(1));
2642
2667
  this.id$ = this.document$.pipe(map((x) => x.id), shareReplay(1));
@@ -2647,12 +2672,12 @@ class AbstractDbxFirebaseDocumentStore extends LockSetComponentStore {
2647
2672
  this.ref$ = this.document$.pipe(map((x) => x.documentRef), shareReplay(1));
2648
2673
  this.snapshot$ = this.document$.pipe(switchMap((x) => x.accessor.stream()), shareReplay(1));
2649
2674
  this.snapshotLoadingState$ = this.currentDocument$.pipe(switchMap(() => loadingStateFromObs(this.snapshot$)), shareReplay(1));
2650
- this.currentData$ = this.document$.pipe(switchMap((x) => x.accessor.stream().pipe(map((y) => documentDataWithId(y)))), shareReplay(1));
2675
+ this.currentData$ = this.document$.pipe(switchMap((x) => x.accessor.stream().pipe(map((y) => documentDataWithIdAndKey(y)))), shareReplay(1));
2651
2676
  this.data$ = this.currentDocument$.pipe(switchMap(() => this.currentData$.pipe(filterMaybe())), shareReplay(1));
2652
2677
  this.dataLoadingState$ = this.snapshotLoadingState$.pipe(map((x) => {
2653
2678
  let result;
2654
2679
  if (x.value) {
2655
- const data = documentDataWithId(x.value);
2680
+ const data = documentDataWithIdAndKey(x.value);
2656
2681
  if (data) {
2657
2682
  result = successResult(data);
2658
2683
  }
@@ -2665,6 +2690,17 @@ class AbstractDbxFirebaseDocumentStore extends LockSetComponentStore {
2665
2690
  }
2666
2691
  return result;
2667
2692
  }), shareReplay(1));
2693
+ /**
2694
+ * Returns false while hasRef$ is false, and then returns exists$.
2695
+ */
2696
+ this.currentExists$ = this.hasRef$.pipe(switchMap((hasRef) => {
2697
+ if (hasRef) {
2698
+ return this.exists$;
2699
+ }
2700
+ else {
2701
+ return of(false);
2702
+ }
2703
+ }), shareReplay(1));
2668
2704
  this.exists$ = this.currentData$.pipe(map((x) => isMaybeSo(x)), shareReplay(1));
2669
2705
  this.doesNotExist$ = this.exists$.pipe(map((x) => !x), shareReplay(1));
2670
2706
  this.modelIdentity$ = this.document$.pipe(map((x) => x.modelIdentity), shareReplay(1));