@dereekb/dbx-firebase 8.4.0 → 8.5.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.
@@ -2,7 +2,7 @@ import { urlWithoutParameters, AUTH_ADMIN_ROLE, cachedGetter, addToSet, removeFr
2
2
  import * as i0 from '@angular/core';
3
3
  import { InjectionToken, Injectable, Inject, Optional, Component, Input, Directive, EventEmitter, Output, NgModule, Injector, forwardRef, Host } from '@angular/core';
4
4
  import { getToken, initializeAppCheck, ReCaptchaV3Provider } from 'firebase/app-check';
5
- import { switchMap, from, first, map, of, shareReplay, timeout, startWith, distinctUntilChanged, firstValueFrom, BehaviorSubject, combineLatest, tap, Subject, throttleTime, NEVER, exhaustMap, filter, take } from 'rxjs';
5
+ import { switchMap, from, first, map, of, shareReplay, distinctUntilChanged, firstValueFrom, BehaviorSubject, combineLatest, tap, filter, take, startWith, Subject, throttleTime, NEVER, exhaustMap } from 'rxjs';
6
6
  import * as i1 from '@angular/fire/app-check';
7
7
  import { provideAppCheck } from '@angular/fire/app-check';
8
8
  import * as i4 from '@angular/material/button';
@@ -11,7 +11,7 @@ import * as i2 from '@angular/material/icon';
11
11
  import { MatIconModule } from '@angular/material/icon';
12
12
  import * as i6 from '@angular/common';
13
13
  import { CommonModule } from '@angular/common';
14
- import { filterMaybe, isNot, SubscriptionObject, cleanupDestroyable, accumulatorFlattenPageListLoadingState, useFirst, pageLoadingStateFromObs, asObservable, useAsObservable, successResult, beginLoading, loadingStateFromObs, errorResult, lazyFrom, cleanup } from '@dereekb/rxjs';
14
+ import { timeoutStartWith, filterMaybe, isNot, SubscriptionObject, cleanupDestroyable, accumulatorFlattenPageListLoadingState, useFirst, pageLoadingStateFromObs, asObservable, useAsObservable, successResult, beginLoading, loadingStateFromObs, errorResult, lazyFrom, cleanup } from '@dereekb/rxjs';
15
15
  import * as i3$1 from '@dereekb/dbx-core';
16
16
  import { loggedInObsFromIsLoggedIn, loggedOutObsFromIsLoggedIn, authUserIdentifier, DbxInjectionContext, AbstractForwardDbxInjectionContextDirective, DBX_INJECTION_COMPONENT_DATA, DbxInjectionComponentModule, DbxAuthService, AbstractSubscriptionDirective, AbstractIfDirective, DbxRouteParamReaderInstance, DbxRouteParamDefaultRedirectInstance, LockSetComponentStore } from '@dereekb/dbx-core';
17
17
  import * as i1$1 from '@angular/fire/auth';
@@ -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 { firebaseFirestoreContextFactory, iterationQueryDocChangeWatcher, firebaseQueryItemAccumulator, firestoreModelKeysFromDocuments, firestoreModelIdsFromDocuments, documentReferencesFromDocuments, getDocumentSnapshots, getDataFromDocumentSnapshots, loadDocumentsForKeys, loadDocumentsForDocumentReferences, loadDocumentsForIds, documentDataWithId } from '@dereekb/firebase';
34
+ import { firebaseFirestoreContextFactory, iterationQueryDocChangeWatcher, firebaseQueryItemAccumulator, firestoreModelKeysFromDocuments, firestoreModelIdsFromDocuments, documentReferencesFromDocuments, getDocumentSnapshots, getDataFromDocumentSnapshots, streamDocumentSnapshots, dataFromDocumentSnapshots, loadDocumentsForKeys, loadDocumentsForDocumentReferences, loadDocumentsForIds, documentDataWithId } 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.
@@ -195,10 +195,7 @@ class DbxFirebaseAuthService {
195
195
  constructor(firebaseAuth, delegate) {
196
196
  this.firebaseAuth = firebaseAuth;
197
197
  this._authState$ = authState(this.firebaseAuth);
198
- this.currentAuthUser$ = this._authState$.pipe(timeout({
199
- first: 1000,
200
- with: () => this._authState$.pipe(startWith(null))
201
- }), distinctUntilChanged(), shareReplay(1));
198
+ this.currentAuthUser$ = this._authState$.pipe(timeoutStartWith(null, 1000), distinctUntilChanged(), shareReplay(1));
202
199
  this.currentAuthUserInfo$ = this.currentAuthUser$.pipe(map((x) => (x ? authUserInfoFromAuthUser(x) : undefined)));
203
200
  this.authUser$ = this.currentAuthUser$.pipe(filterMaybe());
204
201
  this.authUserInfo$ = this.authUser$.pipe(map(authUserInfoFromAuthUser));
@@ -1873,6 +1870,40 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.2", ngImpor
1873
1870
  type: NgModule
1874
1871
  }] });
1875
1872
 
1873
+ /**
1874
+ * DbxFirebaseCollectionChangeWatcher instance
1875
+ */
1876
+ class DbxFirebaseCollectionChangeWatcherInstance {
1877
+ constructor(store) {
1878
+ this.store = store;
1879
+ this._mode = new BehaviorSubject('off');
1880
+ this._sub = new SubscriptionObject();
1881
+ this.mode$ = this._mode.pipe(distinctUntilChanged());
1882
+ this.event$ = this.store.queryChangeWatcher$.pipe(switchMap((x) => x.event$.pipe(filter((x) => x.type !== 'none'), // do not share 'none' events.
1883
+ take(1), // only need one event to mark as change is available.
1884
+ startWith({
1885
+ time: new Date(),
1886
+ type: 'none'
1887
+ }))), shareReplay(1));
1888
+ this.hasChangeAvailable$ = this.event$.pipe(map((x) => x.type !== 'none'), shareReplay(1));
1889
+ this.triggered$ = combineLatest([this.mode$, this.hasChangeAvailable$]).pipe(map(([mode, hasChange]) => mode === 'auto' && hasChange));
1890
+ this.trigger$ = this.triggered$.pipe(filter((triggered) => triggered), map(() => undefined));
1891
+ }
1892
+ destroy() {
1893
+ this._sub.destroy();
1894
+ this._mode.complete();
1895
+ }
1896
+ get mode() {
1897
+ return this._mode.value;
1898
+ }
1899
+ set mode(mode) {
1900
+ this._mode.next(mode);
1901
+ }
1902
+ }
1903
+ function dbxFirebaseCollectionChangeWatcher(store) {
1904
+ return new DbxFirebaseCollectionChangeWatcherInstance(store);
1905
+ }
1906
+
1876
1907
  /**
1877
1908
  * DbxFirebaseModelLoader implementation within an instance.
1878
1909
  */
@@ -1986,7 +2017,16 @@ class DbxLimitedFirebaseDocumentLoaderInstance {
1986
2017
  this.refs$ = this.documents$.pipe(map(documentReferencesFromDocuments));
1987
2018
  this.snapshots$ = this.documents$.pipe(switchMap((docs) => this._restart.pipe(startWith(null), exhaustMap(() => getDocumentSnapshots(docs)))), shareReplay(1));
1988
2019
  this.data$ = this.snapshots$.pipe(map((snapshots) => getDataFromDocumentSnapshots(snapshots, true)), shareReplay(1));
2020
+ /**
2021
+ * Snapshot stream of the documents
2022
+ */
2023
+ this.snapshotsStream$ = this.documents$.pipe(switchMap((docs) => streamDocumentSnapshots(docs)), shareReplay(1));
2024
+ /**
2025
+ * Data streamd of the documents.
2026
+ */
2027
+ this.dataStream$ = this.snapshotsStream$.pipe(dataFromDocumentSnapshots(), shareReplay(1));
1989
2028
  this.pageLoadingState$ = pageLoadingStateFromObs(this.data$, false);
2029
+ this.pageLoadingStateStream$ = pageLoadingStateFromObs(this.dataStream$, false);
1990
2030
  }
1991
2031
  destroy() {
1992
2032
  this._documents.complete();
@@ -2084,32 +2124,27 @@ class DbxFirebaseCollectionChangeDirective extends AbstractSubscriptionDirective
2084
2124
  constructor(dbxFirebaseCollectionStoreDirective) {
2085
2125
  super();
2086
2126
  this.dbxFirebaseCollectionStoreDirective = dbxFirebaseCollectionStoreDirective;
2087
- this._mode = new BehaviorSubject('manual');
2088
- this.mode$ = this._mode.pipe(distinctUntilChanged());
2089
- this.event$ = this.dbxFirebaseCollectionStoreDirective.store.queryChangeWatcher$.pipe(switchMap((x) => x.event$.pipe(filter((x) => x.type !== 'none'), // do not share 'none' events.
2090
- take(1), // only need one event to mark as change is available.
2091
- startWith({
2092
- time: new Date(),
2093
- type: 'none'
2094
- }))), shareReplay(1));
2095
- this.hasChangeAvailable$ = this.event$.pipe(map((x) => x.type !== 'none'), shareReplay(1));
2127
+ this._watcher = dbxFirebaseCollectionChangeWatcher(this.dbxFirebaseCollectionStoreDirective.store);
2128
+ this.mode$ = this._watcher.mode$;
2129
+ this.event$ = this._watcher.event$;
2130
+ this.hasChangeAvailable$ = this._watcher.hasChangeAvailable$;
2131
+ this.triggered$ = this._watcher.triggered$;
2132
+ this.trigger$ = this._watcher.trigger$;
2096
2133
  }
2097
2134
  ngOnInit() {
2098
- this.sub = combineLatest([this.mode$, this.hasChangeAvailable$])
2099
- .pipe(filter(([mode, hasChange]) => mode === 'auto' && hasChange))
2100
- .subscribe(() => {
2135
+ this.sub = this._watcher.trigger$.subscribe(() => {
2101
2136
  this.restart();
2102
2137
  });
2103
2138
  }
2104
2139
  ngOnDestroy() {
2105
2140
  super.ngOnDestroy();
2106
- this._mode.complete();
2141
+ this._watcher.destroy();
2107
2142
  }
2108
2143
  get mode() {
2109
- return this._mode.value;
2144
+ return this._watcher.mode;
2110
2145
  }
2111
2146
  set mode(mode) {
2112
- this._mode.next(mode || 'manual');
2147
+ this._watcher.mode = mode || 'off';
2113
2148
  }
2114
2149
  restart() {
2115
2150
  this.dbxFirebaseCollectionStoreDirective.store.restart();
@@ -2740,5 +2775,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.2", ngImpor
2740
2775
  * Generated bundle index. Do not edit.
2741
2776
  */
2742
2777
 
2743
- export { AbstractConfiguredDbxFirebaseLoginButtonDirective, AbstractDbxFirebaseCollectionStore, AbstractDbxFirebaseCollectionWithParentStore, AbstractDbxFirebaseDocumentStore, AbstractDbxFirebaseDocumentWithParentStore, DBX_FIREBASE_MODEL_DOES_NOT_EXIST_ERROR, DBX_FIREBASE_OPTIONS_TOKEN, DBX_FIREBASE_ROUTER_SYNC_DEFAULT_ID_PARAM_KEY, DBX_FIREBASE_ROUTER_SYNC_USE_DEFAULT_PARAM_VALUE, DBX_FIRESTORE_CONTEXT_TOKEN, DEFAULT_CONFIGURED_DBX_FIREBASE_LOGIN_BUTTON_TEMPLATE, DEFAULT_DBX_FIREBASE_AUTH_SERVICE_DELEGATE, DEFAULT_FIREBASE_AUTH_LOGIN_PASSWORD_CONFIG, DEFAULT_FIREBASE_AUTH_LOGIN_PASSWORD_CONFIG_TOKEN, DEFAULT_FIREBASE_AUTH_LOGIN_PROVIDERS_TOKEN, DEFAULT_FIREBASE_AUTH_LOGIN_TERMS_COMPONENT_CLASS_TOKEN, DEFAULT_FIREBASE_LOGIN_METHOD_CATEGORY, DbxFirebaseAppCheckHttpInterceptor, DbxFirebaseAuthContextInfo, DbxFirebaseAuthLoginService, DbxFirebaseAuthModule, DbxFirebaseAuthService, DbxFirebaseAuthServiceDelegate, DbxFirebaseCollectionChangeDirective, DbxFirebaseCollectionHasChangeDirective, DbxFirebaseCollectionListDirective, DbxFirebaseCollectionLoaderInstance, DbxFirebaseCollectionStoreDirective, DbxFirebaseCollectionWithParentStoreDirective, DbxFirebaseDefaultAppCheckProviderModule, DbxFirebaseDefaultAuthProviderModule, DbxFirebaseDefaultFirebaseProvidersModule, DbxFirebaseDefaultFirestoreProviderModule, DbxFirebaseDefaultFunctionsProviderModule, DbxFirebaseDefaultStorageProviderModule, DbxFirebaseDocumentAuthIdDirective, DbxFirebaseDocumentLoaderInstance, DbxFirebaseDocumentStoreDirective, DbxFirebaseDocumentStoreRouteIdDirective, DbxFirebaseEmailFormComponent, DbxFirebaseEmailRecoveryFormComponent, DbxFirebaseEmulatorModule, DbxFirebaseFirestoreCollectionModule, DbxFirebaseFunctionsModule, DbxFirebaseLoginAnonymousComponent, DbxFirebaseLoginAppleComponent, DbxFirebaseLoginButtonComponent, DbxFirebaseLoginButtonContainerComponent, DbxFirebaseLoginComponent, DbxFirebaseLoginContext, DbxFirebaseLoginContextBackButtonComponent, DbxFirebaseLoginContextDirective, DbxFirebaseLoginEmailComponent, DbxFirebaseLoginEmailContentComponent, DbxFirebaseLoginFacebookComponent, DbxFirebaseLoginGitHubComponent, DbxFirebaseLoginGoogleComponent, DbxFirebaseLoginListComponent, DbxFirebaseLoginMicrosoftComponent, DbxFirebaseLoginModule, DbxFirebaseLoginModuleRootConfig, DbxFirebaseLoginTermsComponent, DbxFirebaseLoginTermsSimpleComponent, DbxFirebaseLoginTwitterComponent, DbxFirebaseModelModule, DbxFirebaseModelStoreModule, DbxFirebaseModule, DbxFirebaseParsedEmulatorsConfig, DbxFirebaseRegisterComponent, DbxFirebaseRegisterEmailComponent, DbxFirestoreContextService, DbxLimitedFirebaseDocumentLoaderInstance, FIREBASE_AUTH_NETWORK_REQUEST_ERROR, FIREBASE_AUTH_USER_NOT_FOUND_ERROR, OAUTH_FIREBASE_LOGIN_METHOD_CATEGORY, authRolesObsWithClaimsService, authUserInfoFromAuthUser, authUserStateFromFirebaseAuthService, dbxFirebaseCollectionLoaderInstance, dbxFirebaseCollectionLoaderInstanceWithCollection, dbxFirebaseDocumentLoaderInstance, dbxFirebaseDocumentLoaderInstanceWithAccessor, dbxLimitedFirebaseDocumentLoaderInstance, dbxLimitedFirebaseDocumentLoaderInstanceWithAccessor, defaultDbxFirebaseAuthServiceDelegateWithClaimsService, defaultFirebaseAuthLoginProvidersFactory, enableAppCheckDebugTokenGeneration, firebaseAuthErrorToReadableError, firebaseAuthTokenFromUser, firebaseDocumentStoreCreateFunction, firebaseDocumentStoreDeleteFunction, firebaseDocumentStoreUpdateFunction, modelDoesNotExistError, provideDbxFirebaseCollectionStoreDirective, provideDbxFirebaseCollectionWithParentStoreDirective, provideDbxFirebaseDocumentStoreDirective, readValueFromIdToken, setParentStoreEffect };
2778
+ export { AbstractConfiguredDbxFirebaseLoginButtonDirective, AbstractDbxFirebaseCollectionStore, AbstractDbxFirebaseCollectionWithParentStore, AbstractDbxFirebaseDocumentStore, AbstractDbxFirebaseDocumentWithParentStore, DBX_FIREBASE_MODEL_DOES_NOT_EXIST_ERROR, DBX_FIREBASE_OPTIONS_TOKEN, DBX_FIREBASE_ROUTER_SYNC_DEFAULT_ID_PARAM_KEY, DBX_FIREBASE_ROUTER_SYNC_USE_DEFAULT_PARAM_VALUE, DBX_FIRESTORE_CONTEXT_TOKEN, DEFAULT_CONFIGURED_DBX_FIREBASE_LOGIN_BUTTON_TEMPLATE, DEFAULT_DBX_FIREBASE_AUTH_SERVICE_DELEGATE, DEFAULT_FIREBASE_AUTH_LOGIN_PASSWORD_CONFIG, DEFAULT_FIREBASE_AUTH_LOGIN_PASSWORD_CONFIG_TOKEN, DEFAULT_FIREBASE_AUTH_LOGIN_PROVIDERS_TOKEN, DEFAULT_FIREBASE_AUTH_LOGIN_TERMS_COMPONENT_CLASS_TOKEN, DEFAULT_FIREBASE_LOGIN_METHOD_CATEGORY, DbxFirebaseAppCheckHttpInterceptor, DbxFirebaseAuthContextInfo, DbxFirebaseAuthLoginService, DbxFirebaseAuthModule, DbxFirebaseAuthService, DbxFirebaseAuthServiceDelegate, DbxFirebaseCollectionChangeDirective, DbxFirebaseCollectionChangeWatcherInstance, DbxFirebaseCollectionHasChangeDirective, DbxFirebaseCollectionListDirective, DbxFirebaseCollectionLoaderInstance, DbxFirebaseCollectionStoreDirective, DbxFirebaseCollectionWithParentStoreDirective, DbxFirebaseDefaultAppCheckProviderModule, DbxFirebaseDefaultAuthProviderModule, DbxFirebaseDefaultFirebaseProvidersModule, DbxFirebaseDefaultFirestoreProviderModule, DbxFirebaseDefaultFunctionsProviderModule, DbxFirebaseDefaultStorageProviderModule, DbxFirebaseDocumentAuthIdDirective, DbxFirebaseDocumentLoaderInstance, DbxFirebaseDocumentStoreDirective, DbxFirebaseDocumentStoreRouteIdDirective, DbxFirebaseEmailFormComponent, DbxFirebaseEmailRecoveryFormComponent, DbxFirebaseEmulatorModule, DbxFirebaseFirestoreCollectionModule, DbxFirebaseFunctionsModule, DbxFirebaseLoginAnonymousComponent, DbxFirebaseLoginAppleComponent, DbxFirebaseLoginButtonComponent, DbxFirebaseLoginButtonContainerComponent, DbxFirebaseLoginComponent, DbxFirebaseLoginContext, DbxFirebaseLoginContextBackButtonComponent, DbxFirebaseLoginContextDirective, DbxFirebaseLoginEmailComponent, DbxFirebaseLoginEmailContentComponent, DbxFirebaseLoginFacebookComponent, DbxFirebaseLoginGitHubComponent, DbxFirebaseLoginGoogleComponent, DbxFirebaseLoginListComponent, DbxFirebaseLoginMicrosoftComponent, DbxFirebaseLoginModule, DbxFirebaseLoginModuleRootConfig, DbxFirebaseLoginTermsComponent, DbxFirebaseLoginTermsSimpleComponent, DbxFirebaseLoginTwitterComponent, DbxFirebaseModelModule, DbxFirebaseModelStoreModule, DbxFirebaseModule, DbxFirebaseParsedEmulatorsConfig, DbxFirebaseRegisterComponent, DbxFirebaseRegisterEmailComponent, DbxFirestoreContextService, DbxLimitedFirebaseDocumentLoaderInstance, FIREBASE_AUTH_NETWORK_REQUEST_ERROR, FIREBASE_AUTH_USER_NOT_FOUND_ERROR, OAUTH_FIREBASE_LOGIN_METHOD_CATEGORY, authRolesObsWithClaimsService, authUserInfoFromAuthUser, authUserStateFromFirebaseAuthService, dbxFirebaseCollectionChangeWatcher, dbxFirebaseCollectionLoaderInstance, dbxFirebaseCollectionLoaderInstanceWithCollection, dbxFirebaseDocumentLoaderInstance, dbxFirebaseDocumentLoaderInstanceWithAccessor, dbxLimitedFirebaseDocumentLoaderInstance, dbxLimitedFirebaseDocumentLoaderInstanceWithAccessor, defaultDbxFirebaseAuthServiceDelegateWithClaimsService, defaultFirebaseAuthLoginProvidersFactory, enableAppCheckDebugTokenGeneration, firebaseAuthErrorToReadableError, firebaseAuthTokenFromUser, firebaseDocumentStoreCreateFunction, firebaseDocumentStoreDeleteFunction, firebaseDocumentStoreUpdateFunction, modelDoesNotExistError, provideDbxFirebaseCollectionStoreDirective, provideDbxFirebaseCollectionWithParentStoreDirective, provideDbxFirebaseDocumentStoreDirective, readValueFromIdToken, setParentStoreEffect };
2744
2779
  //# sourceMappingURL=dereekb-dbx-firebase.mjs.map