@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.
- package/esm2020/lib/model/loader/collection.change.trigger.mjs +9 -2
- package/esm2020/lib/model/loader/collection.loader.instance.mjs +13 -2
- package/esm2020/lib/model/loader/collection.loader.mjs +1 -1
- package/esm2020/lib/model/loader/document.loader.instance.mjs +1 -1
- package/esm2020/lib/model/loader/document.loader.mjs +1 -1
- package/esm2020/lib/model/store/store.collection.mjs +5 -1
- package/esm2020/lib/model/store/store.document.mjs +19 -4
- package/fesm2015/dereekb-dbx-firebase.mjs +40 -4
- package/fesm2015/dereekb-dbx-firebase.mjs.map +1 -1
- package/fesm2020/dereekb-dbx-firebase.mjs +41 -4
- package/fesm2020/dereekb-dbx-firebase.mjs.map +1 -1
- package/lib/model/loader/collection.change.trigger.d.ts +4 -0
- package/lib/model/loader/collection.loader.d.ts +2 -2
- package/lib/model/loader/collection.loader.instance.d.ts +10 -2
- package/lib/model/loader/document.loader.d.ts +5 -5
- package/lib/model/loader/document.loader.instance.d.ts +5 -5
- package/lib/model/store/store.collection.d.ts +11 -3
- package/lib/model/store/store.collection.directive.d.ts +1 -1
- package/lib/model/store/store.document.d.ts +17 -7
- package/lib/model/store/store.document.directive.d.ts +2 -2
- package/package.json +6 -6
|
@@ -31,7 +31,7 @@ import { provideFunctions, getFunctions, connectFunctionsEmulator, Functions } f
|
|
|
31
31
|
import * as i1$3 from '@angular/fire/firestore';
|
|
32
32
|
import { provideFirestore, getFirestore, connectFirestoreEmulator, enableIndexedDbPersistence, Firestore } from '@angular/fire/firestore';
|
|
33
33
|
import { HTTP_INTERCEPTORS } from '@angular/common/http';
|
|
34
|
-
import { clientFirebaseFirestoreContextFactory, iterationQueryDocChangeWatcher, firebaseQueryItemAccumulator, firestoreModelKeysFromDocuments, firestoreModelIdsFromDocuments, documentReferencesFromDocuments, getDocumentSnapshots, getDataFromDocumentSnapshots, streamDocumentSnapshots, dataFromDocumentSnapshots, loadDocumentsForKeys, loadDocumentsForDocumentReferences, loadDocumentsForIds, firestoreModelIdsFromKey, firestoreModelKeyPartPairs, firestoreModelKeyPairObject,
|
|
34
|
+
import { clientFirebaseFirestoreContextFactory, iterationQueryDocChangeWatcher, firebaseQuerySnapshotAccumulator, firebaseQueryItemAccumulator, firestoreModelKeysFromDocuments, firestoreModelIdsFromDocuments, documentReferencesFromDocuments, getDocumentSnapshots, getDataFromDocumentSnapshots, streamDocumentSnapshots, dataFromDocumentSnapshots, loadDocumentsForKeys, loadDocumentsForDocumentReferences, loadDocumentsForIds, firestoreModelIdsFromKey, firestoreModelKeyPartPairs, firestoreModelKeyPairObject, documentDataWithIdAndKey, clientFirebaseStorageContextFactory } from '@dereekb/firebase';
|
|
35
35
|
|
|
36
36
|
/**
|
|
37
37
|
* Enables debug token generation for AppCheck by setting FIREBASE_APPCHECK_DEBUG_TOKEN in the browser's self/window.
|
|
@@ -1962,6 +1962,10 @@ class DbxFirebaseCollectionChangeTriggerInstance {
|
|
|
1962
1962
|
/**
|
|
1963
1963
|
* Creates a new DbxFirebaseCollectionChangeWatcher, set the modes to "auto", and creates a new DbxFirebaseCollectionChangeTriggerInstance.
|
|
1964
1964
|
*
|
|
1965
|
+
* If no trigger function is provided it will default to resetting the store.
|
|
1966
|
+
*
|
|
1967
|
+
* NOTE: Don't forget to initialize the DbxFirebaseCollectionChangeTriggerInstance and handle other lifecycle changes.
|
|
1968
|
+
*
|
|
1965
1969
|
* @param store
|
|
1966
1970
|
* @param triggerFunction
|
|
1967
1971
|
* @returns
|
|
@@ -1970,7 +1974,10 @@ function dbxFirebaseCollectionChangeTriggerForStore(store, triggerFunction) {
|
|
|
1970
1974
|
return dbxFirebaseCollectionChangeTrigger({
|
|
1971
1975
|
watcher: dbxFirebaseCollectionChangeWatcher(store, 'auto'),
|
|
1972
1976
|
destroyWatcherOnDestroy: true,
|
|
1973
|
-
triggerFunction
|
|
1977
|
+
triggerFunction: triggerFunction ??
|
|
1978
|
+
(() => {
|
|
1979
|
+
store.restart();
|
|
1980
|
+
})
|
|
1974
1981
|
});
|
|
1975
1982
|
}
|
|
1976
1983
|
function dbxFirebaseCollectionChangeTriggerForWatcher(watcher, triggerFunction) {
|
|
@@ -2011,7 +2018,18 @@ class DbxFirebaseCollectionLoaderInstance {
|
|
|
2011
2018
|
}), cleanupDestroyable(), // cleanup the iteration
|
|
2012
2019
|
shareReplay(1));
|
|
2013
2020
|
this.queryChangeWatcher$ = this.firestoreIteration$.pipe(map((instance) => iterationQueryDocChangeWatcher({ instance })), shareReplay(1));
|
|
2021
|
+
this.snapshotAccumulator$ = this.firestoreIteration$.pipe(map((x) => firebaseQuerySnapshotAccumulator(x)), cleanupDestroyable(), shareReplay(1));
|
|
2022
|
+
this.snapshotAccumulatorDocumentRefs$ = this.snapshotAccumulator$.pipe(switchMap((x) => x.allItems$.pipe(map((y) => y.map((z) => z.map((zz) => zz.ref))))), shareReplay(1));
|
|
2023
|
+
this.snapshotAccumulatorDocuments$ = combineLatest([this.collection$.pipe(filterMaybe()), this.snapshotAccumulatorDocumentRefs$]).pipe(map(([collection, documentRefs]) => {
|
|
2024
|
+
const accessor = collection.documentAccessor();
|
|
2025
|
+
return documentRefs.map((y) => y.map((z) => accessor.loadDocument(z)));
|
|
2026
|
+
}), shareReplay(1));
|
|
2014
2027
|
this.accumulator$ = this.firestoreIteration$.pipe(map((x) => firebaseQueryItemAccumulator(x)), cleanupDestroyable(), shareReplay(1));
|
|
2028
|
+
this.accumulatorItems$ = this.accumulator$.pipe(switchMap((x) => x.allItems$), shareReplay(1));
|
|
2029
|
+
this.hasDocuments$ = this.firestoreIteration$.pipe(switchMap((x) => x.firstState$.pipe(map((x) => Boolean(x.value?.length)))), shareReplay(1));
|
|
2030
|
+
this.allDocumentRefs$ = this.snapshotAccumulatorDocumentRefs$.pipe(map((x) => x.flat()), shareReplay(1));
|
|
2031
|
+
this.allDocuments$ = this.snapshotAccumulatorDocuments$.pipe(map((x) => x.flat()), shareReplay(1));
|
|
2032
|
+
this.allDocumentData$ = this.accumulatorItems$.pipe(map((x) => x.flat()), shareReplay(1));
|
|
2015
2033
|
this.pageLoadingState$ = this.accumulator$.pipe(switchMap((x) => accumulatorFlattenPageListLoadingState(x)), shareReplay(1));
|
|
2016
2034
|
}
|
|
2017
2035
|
init() {
|
|
@@ -2555,6 +2573,10 @@ class AbstractDbxFirebaseCollectionStore extends LockSetComponentStore {
|
|
|
2555
2573
|
this.queryChangeWatcher$ = this.loader$.pipe(switchMap((x) => x.queryChangeWatcher$));
|
|
2556
2574
|
this.accumulator$ = this.loader$.pipe(switchMap((x) => x.accumulator$));
|
|
2557
2575
|
this.pageLoadingState$ = this.loader$.pipe(switchMap((x) => x.pageLoadingState$));
|
|
2576
|
+
this.hasDocuments$ = this.loader$.pipe(switchMap((x) => x.hasDocuments$));
|
|
2577
|
+
this.allDocumentRefs$ = this.loader$.pipe(switchMap((x) => x.allDocumentRefs$));
|
|
2578
|
+
this.allDocuments$ = this.loader$.pipe(switchMap((x) => x.allDocuments$));
|
|
2579
|
+
this.allDocumentData$ = this.loader$.pipe(switchMap((x) => x.allDocumentData$));
|
|
2558
2580
|
this.setFirestoreCollection = this.updater((state, firestoreCollection) => ({ ...state, firestoreCollection }));
|
|
2559
2581
|
}
|
|
2560
2582
|
}
|
|
@@ -2603,6 +2625,10 @@ class AbstractDbxFirebaseDocumentStore extends LockSetComponentStore {
|
|
|
2603
2625
|
}
|
|
2604
2626
|
return document;
|
|
2605
2627
|
}), distinctUntilChanged(), shareReplay(1));
|
|
2628
|
+
/**
|
|
2629
|
+
* Whether or not an id/ref/key has been input and currentDocument is not null.
|
|
2630
|
+
*/
|
|
2631
|
+
this.hasRef$ = this.currentDocument$.pipe(map((x) => x?.documentRef != null), distinctUntilChanged(), shareReplay(1));
|
|
2606
2632
|
this.document$ = this.currentDocument$.pipe(filterMaybe(), distinctUntilChanged(), shareReplay(1));
|
|
2607
2633
|
this.documentLoadingState$ = this.currentDocument$.pipe(map((x) => (x ? successResult(x) : beginLoading())), shareReplay(1));
|
|
2608
2634
|
this.id$ = this.document$.pipe(map((x) => x.id), shareReplay(1));
|
|
@@ -2613,12 +2639,12 @@ class AbstractDbxFirebaseDocumentStore extends LockSetComponentStore {
|
|
|
2613
2639
|
this.ref$ = this.document$.pipe(map((x) => x.documentRef), shareReplay(1));
|
|
2614
2640
|
this.snapshot$ = this.document$.pipe(switchMap((x) => x.accessor.stream()), shareReplay(1));
|
|
2615
2641
|
this.snapshotLoadingState$ = this.currentDocument$.pipe(switchMap(() => loadingStateFromObs(this.snapshot$)), shareReplay(1));
|
|
2616
|
-
this.currentData$ = this.document$.pipe(switchMap((x) => x.accessor.stream().pipe(map((y) =>
|
|
2642
|
+
this.currentData$ = this.document$.pipe(switchMap((x) => x.accessor.stream().pipe(map((y) => documentDataWithIdAndKey(y)))), shareReplay(1));
|
|
2617
2643
|
this.data$ = this.currentDocument$.pipe(switchMap(() => this.currentData$.pipe(filterMaybe())), shareReplay(1));
|
|
2618
2644
|
this.dataLoadingState$ = this.snapshotLoadingState$.pipe(map((x) => {
|
|
2619
2645
|
let result;
|
|
2620
2646
|
if (x.value) {
|
|
2621
|
-
const data =
|
|
2647
|
+
const data = documentDataWithIdAndKey(x.value);
|
|
2622
2648
|
if (data) {
|
|
2623
2649
|
result = successResult(data);
|
|
2624
2650
|
}
|
|
@@ -2634,6 +2660,17 @@ class AbstractDbxFirebaseDocumentStore extends LockSetComponentStore {
|
|
|
2634
2660
|
}
|
|
2635
2661
|
return result;
|
|
2636
2662
|
}), shareReplay(1));
|
|
2663
|
+
/**
|
|
2664
|
+
* Returns false while hasRef$ is false, and then returns exists$.
|
|
2665
|
+
*/
|
|
2666
|
+
this.currentExists$ = this.hasRef$.pipe(switchMap((hasRef) => {
|
|
2667
|
+
if (hasRef) {
|
|
2668
|
+
return this.exists$;
|
|
2669
|
+
}
|
|
2670
|
+
else {
|
|
2671
|
+
return of(false);
|
|
2672
|
+
}
|
|
2673
|
+
}), shareReplay(1));
|
|
2637
2674
|
this.exists$ = this.currentData$.pipe(map((x) => isMaybeSo(x)), shareReplay(1));
|
|
2638
2675
|
this.doesNotExist$ = this.exists$.pipe(map((x) => !x), shareReplay(1));
|
|
2639
2676
|
this.modelIdentity$ = this.document$.pipe(map((x) => x.modelIdentity), shareReplay(1));
|