@dereekb/firebase 13.0.6 → 13.0.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/test/index.cjs.js CHANGED
@@ -3485,6 +3485,87 @@ function describeFirestoreDocumentUtilityTests(f) {
3485
3485
  });
3486
3486
  });
3487
3487
  });
3488
+ // MARK: limitedFirestoreDocumentAccessorSnapshotCache
3489
+ describe('limitedFirestoreDocumentAccessorSnapshotCache()', () => {
3490
+ it('should expose the underlying accessor', () => {
3491
+ const accessor = f.instance.mockItemCollection.documentAccessor();
3492
+ const cache = firebase.limitedFirestoreDocumentAccessorSnapshotCache(accessor);
3493
+ expect(cache.accessor).toBe(accessor);
3494
+ });
3495
+ describe('getDocumentSnapshotDataPairForKey()', () => {
3496
+ it('should return a snapshot data pair for an existing document', async () => {
3497
+ const accessor = f.instance.mockItemCollection.documentAccessor();
3498
+ const cache = firebase.limitedFirestoreDocumentAccessorSnapshotCache(accessor);
3499
+ const pair = await cache.getDocumentSnapshotDataPairForKey(items[0].key);
3500
+ expect(pair.document).toBeDefined();
3501
+ expect(pair.document.key).toBe(items[0].key);
3502
+ expect(pair.snapshot).toBeDefined();
3503
+ expect(pair.data).toBeDefined();
3504
+ expect(pair.data.id).toBe(items[0].id);
3505
+ expect(pair.data.key).toBe(items[0].key);
3506
+ });
3507
+ it('should return the same promise for the same key', async () => {
3508
+ const accessor = f.instance.mockItemCollection.documentAccessor();
3509
+ const cache = firebase.limitedFirestoreDocumentAccessorSnapshotCache(accessor);
3510
+ const promise1 = cache.getDocumentSnapshotDataPairForKey(items[0].key);
3511
+ const promise2 = cache.getDocumentSnapshotDataPairForKey(items[0].key);
3512
+ expect(promise1).toBe(promise2);
3513
+ });
3514
+ it('should return undefined data for a non-existent document', async () => {
3515
+ const accessor = f.instance.mockItemCollection.documentAccessor();
3516
+ const cache = firebase.limitedFirestoreDocumentAccessorSnapshotCache(accessor);
3517
+ const newDoc = firebase.newDocuments(accessor, 1)[0];
3518
+ const pair = await cache.getDocumentSnapshotDataPairForKey(newDoc.key);
3519
+ expect(pair.document).toBeDefined();
3520
+ expect(pair.data).toBeUndefined();
3521
+ });
3522
+ });
3523
+ describe('getDocumentSnapshotDataPairsForKeys()', () => {
3524
+ it('should return pairs for all keys in order', async () => {
3525
+ const accessor = f.instance.mockItemCollection.documentAccessor();
3526
+ const cache = firebase.limitedFirestoreDocumentAccessorSnapshotCache(accessor);
3527
+ const keys = items.map((x) => x.key);
3528
+ const pairs = await cache.getDocumentSnapshotDataPairsForKeys(keys);
3529
+ expect(pairs.length).toBe(testDocumentCount);
3530
+ pairs.forEach((pair, i) => {
3531
+ expect(pair.document.key).toBe(items[i].key);
3532
+ expect(pair.data).toBeDefined();
3533
+ expect(pair.data.id).toBe(items[i].id);
3534
+ });
3535
+ });
3536
+ it('should use the cache for duplicate keys', async () => {
3537
+ const accessor = f.instance.mockItemCollection.documentAccessor();
3538
+ const cache = firebase.limitedFirestoreDocumentAccessorSnapshotCache(accessor);
3539
+ const key = items[0].key;
3540
+ const [pair1] = await cache.getDocumentSnapshotDataPairsForKeys([key]);
3541
+ const [pair2] = await cache.getDocumentSnapshotDataPairsForKeys([key]);
3542
+ expect(pair1).toBe(pair2);
3543
+ });
3544
+ });
3545
+ describe('getDocumentSnapshotDataPairsWithDataForKeys()', () => {
3546
+ it('should return pairs for all existing documents', async () => {
3547
+ const accessor = f.instance.mockItemCollection.documentAccessor();
3548
+ const cache = firebase.limitedFirestoreDocumentAccessorSnapshotCache(accessor);
3549
+ const keys = items.map((x) => x.key);
3550
+ const pairs = await cache.getDocumentSnapshotDataPairsWithDataForKeys(keys);
3551
+ expect(pairs.length).toBe(testDocumentCount);
3552
+ pairs.forEach((pair) => {
3553
+ expect(pair.data).toBeDefined();
3554
+ expect(pair.data.id).toBeDefined();
3555
+ expect(pair.data.key).toBeDefined();
3556
+ });
3557
+ });
3558
+ it('should filter out non-existent documents', async () => {
3559
+ const accessor = f.instance.mockItemCollection.documentAccessor();
3560
+ const cache = firebase.limitedFirestoreDocumentAccessorSnapshotCache(accessor);
3561
+ const newDoc = firebase.newDocuments(accessor, 1)[0];
3562
+ const keys = [...items.map((x) => x.key), newDoc.key];
3563
+ const pairs = await cache.getDocumentSnapshotDataPairsWithDataForKeys(keys);
3564
+ expect(pairs.length).toBe(testDocumentCount);
3565
+ expect(pairs.every((p) => p.data != null)).toBe(true);
3566
+ });
3567
+ });
3568
+ });
3488
3569
  });
3489
3570
  describe('document.rxjs.ts', () => {
3490
3571
  // MARK: latestSnapshotsFromDocuments
@@ -3532,10 +3613,10 @@ function describeFirestoreDocumentUtilityTests(f) {
3532
3613
  });
3533
3614
  }));
3534
3615
  });
3535
- // MARK: latestDataFromDocuments
3536
- describe('latestDataFromDocuments()', () => {
3616
+ // MARK: streamDocumentSnapshotsData
3617
+ describe('streamDocumentSnapshotsData()', () => {
3537
3618
  it('should emit data with id/key for all documents', test.callbackTest((done) => {
3538
- sub.subscription = firebase.latestDataFromDocuments(items)
3619
+ sub.subscription = firebase.streamDocumentSnapshotsData(items)
3539
3620
  .pipe(rxjs$1.first())
3540
3621
  .subscribe((data) => {
3541
3622
  expect(data.length).toBe(testDocumentCount);
@@ -3548,7 +3629,7 @@ function describeFirestoreDocumentUtilityTests(f) {
3548
3629
  });
3549
3630
  }));
3550
3631
  it('should emit an empty array for empty input', test.callbackTest((done) => {
3551
- sub.subscription = firebase.latestDataFromDocuments([])
3632
+ sub.subscription = firebase.streamDocumentSnapshotsData([])
3552
3633
  .pipe(rxjs$1.first())
3553
3634
  .subscribe((data) => {
3554
3635
  expect(data.length).toBe(0);
package/test/index.esm.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { performAsyncTasks, cachedGetter, bitwiseObjectDencoder, modelFieldConversions, isEvenNumber, arrayFactory, mapGetter, randomNumberFactory, randomFromArrayFactory, idBatchFactory, unique, waitForMs, arrayContainsDuplicateValue, useCallback, readableStreamToBuffer, SLASH_PATH_SEPARATOR } from '@dereekb/util';
2
2
  import { AbstractTestContextFixture, testContextBuilder, instanceWrapTestContextFactory, AbstractWrappedFixtureWithInstance, itShouldFail, expectFail, callbackTest } from '@dereekb/util/test';
3
3
  import { initializeTestEnvironment } from '@firebase/rules-unit-testing';
4
- import { firebaseStorageClientDrivers, firebaseFirestoreClientDrivers, firestoreContextFactory, firebaseStorageContextFactory, firestoreModelIdentity, snapshotConverterFunctions, firestoreBoolean, optionalFirestoreNumber, optionalFirestoreDate, optionalFirestoreArray, optionalFirestoreString, firestoreDate, firestoreBitwiseObjectMap, firestoreUniqueStringArray, firestoreNumber, firestoreString, firestoreUID, copyUserRelatedDataAccessorFactoryFunction, firestoreSubObject, AbstractFirestoreDocumentWithParent, AbstractFirestoreDocument, firebaseModelServiceFactory, grantFullAccessIfAdmin, firebaseModelsService, systemStateFirestoreCollection, allChildDocumentsUnderParent, where, makeDocuments, getDocumentSnapshotPairs, useDocumentSnapshot, useDocumentSnapshotData, firestoreIdBatchVerifierFactory, whereDocumentId, loadAllFirestoreDocumentSnapshotPairs, loadAllFirestoreDocumentSnapshot, iterateFirestoreDocumentSnapshotPairs, iterateFirestoreDocumentSnapshots, iterateFirestoreDocumentSnapshotPairBatches, iterateFirestoreDocumentSnapshotBatches, limit, orderBy, limitToLast, whereStringHasRootIdentityModelKey, whereStringValueHasPrefix, whereDateIsAfterWithSort, whereDateIsBeforeWithSort, whereDateIsOnOrAfterWithSort, whereDateIsOnOrBeforeWithSort, whereDateIsInRange, whereDateIsBetween, startAt, orderByDocumentId, startAtValue, startAfter, endAt, endAtValue, endBefore, streamFromOnSnapshot, latestSnapshotsFromDocuments, newDocuments, getDocumentSnapshots, getDocumentSnapshotPair, getDocumentSnapshotDataPair, getDocumentSnapshotDataPairs, getDocumentSnapshotDataPairsWithData, getDocumentSnapshotDataTuples, getDocumentSnapshotData, getDocumentSnapshotsData, getDataFromDocumentSnapshots, loadDocumentsForSnapshots, loadDocumentsForDocumentReferences, loadDocumentsForDocumentReferencesFromValues, loadDocumentsForKeys, loadDocumentsForKeysFromValues, loadDocumentsForIds, loadDocumentsForIdsFromValues, firestoreDocumentLoader, firestoreDocumentSnapshotPairsLoader, documentData, documentDataFunction, documentDataWithIdAndKey, setIdAndKeyFromSnapshotOnDocumentData, setIdAndKeyFromKeyIdRefOnDocumentData, firestoreModelIdFromDocument, firestoreModelIdsFromDocuments, firestoreModelKeyFromDocument, firestoreModelKeysFromDocuments, documentReferenceFromDocument, documentReferencesFromDocuments, mapLatestSnapshotsFromDocuments, latestDataFromDocuments, dataFromDocumentSnapshots, streamDocumentSnapshotDataPairs, streamDocumentSnapshotDataPairsWithData, firebaseQuerySnapshotAccumulator, firebaseQueryItemAccumulator, uploadFileWithStream, iterateStorageListFilesByEachFile } from '@dereekb/firebase';
4
+ import { firebaseStorageClientDrivers, firebaseFirestoreClientDrivers, firestoreContextFactory, firebaseStorageContextFactory, firestoreModelIdentity, snapshotConverterFunctions, firestoreBoolean, optionalFirestoreNumber, optionalFirestoreDate, optionalFirestoreArray, optionalFirestoreString, firestoreDate, firestoreBitwiseObjectMap, firestoreUniqueStringArray, firestoreNumber, firestoreString, firestoreUID, copyUserRelatedDataAccessorFactoryFunction, firestoreSubObject, AbstractFirestoreDocumentWithParent, AbstractFirestoreDocument, firebaseModelServiceFactory, grantFullAccessIfAdmin, firebaseModelsService, systemStateFirestoreCollection, allChildDocumentsUnderParent, where, makeDocuments, getDocumentSnapshotPairs, useDocumentSnapshot, useDocumentSnapshotData, firestoreIdBatchVerifierFactory, whereDocumentId, loadAllFirestoreDocumentSnapshotPairs, loadAllFirestoreDocumentSnapshot, iterateFirestoreDocumentSnapshotPairs, iterateFirestoreDocumentSnapshots, iterateFirestoreDocumentSnapshotPairBatches, iterateFirestoreDocumentSnapshotBatches, limit, orderBy, limitToLast, whereStringHasRootIdentityModelKey, whereStringValueHasPrefix, whereDateIsAfterWithSort, whereDateIsBeforeWithSort, whereDateIsOnOrAfterWithSort, whereDateIsOnOrBeforeWithSort, whereDateIsInRange, whereDateIsBetween, startAt, orderByDocumentId, startAtValue, startAfter, endAt, endAtValue, endBefore, streamFromOnSnapshot, latestSnapshotsFromDocuments, newDocuments, getDocumentSnapshots, getDocumentSnapshotPair, getDocumentSnapshotDataPair, getDocumentSnapshotDataPairs, getDocumentSnapshotDataPairsWithData, getDocumentSnapshotDataTuples, getDocumentSnapshotData, getDocumentSnapshotsData, getDataFromDocumentSnapshots, loadDocumentsForSnapshots, loadDocumentsForDocumentReferences, loadDocumentsForDocumentReferencesFromValues, loadDocumentsForKeys, loadDocumentsForKeysFromValues, loadDocumentsForIds, loadDocumentsForIdsFromValues, firestoreDocumentLoader, firestoreDocumentSnapshotPairsLoader, documentData, documentDataFunction, documentDataWithIdAndKey, setIdAndKeyFromSnapshotOnDocumentData, setIdAndKeyFromKeyIdRefOnDocumentData, firestoreModelIdFromDocument, firestoreModelIdsFromDocuments, firestoreModelKeyFromDocument, firestoreModelKeysFromDocuments, documentReferenceFromDocument, documentReferencesFromDocuments, limitedFirestoreDocumentAccessorSnapshotCache, mapLatestSnapshotsFromDocuments, streamDocumentSnapshotsData, dataFromDocumentSnapshots, streamDocumentSnapshotDataPairs, streamDocumentSnapshotDataPairsWithData, firebaseQuerySnapshotAccumulator, firebaseQueryItemAccumulator, uploadFileWithStream, iterateStorageListFilesByEachFile } from '@dereekb/firebase';
5
5
  import { setLogLevel } from 'firebase/firestore';
6
6
  import { firstValueFrom, filter, skip, from, first, map, switchMap } from 'rxjs';
7
7
  import { SubscriptionObject, iteratorNextPageUntilPage, flattenAccumulatorResultItemArray, accumulatorCurrentPageListLoadingState, isLoadingStateFinishedLoading, accumulatorFlattenPageListLoadingState } from '@dereekb/rxjs';
@@ -3483,6 +3483,87 @@ function describeFirestoreDocumentUtilityTests(f) {
3483
3483
  });
3484
3484
  });
3485
3485
  });
3486
+ // MARK: limitedFirestoreDocumentAccessorSnapshotCache
3487
+ describe('limitedFirestoreDocumentAccessorSnapshotCache()', () => {
3488
+ it('should expose the underlying accessor', () => {
3489
+ const accessor = f.instance.mockItemCollection.documentAccessor();
3490
+ const cache = limitedFirestoreDocumentAccessorSnapshotCache(accessor);
3491
+ expect(cache.accessor).toBe(accessor);
3492
+ });
3493
+ describe('getDocumentSnapshotDataPairForKey()', () => {
3494
+ it('should return a snapshot data pair for an existing document', async () => {
3495
+ const accessor = f.instance.mockItemCollection.documentAccessor();
3496
+ const cache = limitedFirestoreDocumentAccessorSnapshotCache(accessor);
3497
+ const pair = await cache.getDocumentSnapshotDataPairForKey(items[0].key);
3498
+ expect(pair.document).toBeDefined();
3499
+ expect(pair.document.key).toBe(items[0].key);
3500
+ expect(pair.snapshot).toBeDefined();
3501
+ expect(pair.data).toBeDefined();
3502
+ expect(pair.data.id).toBe(items[0].id);
3503
+ expect(pair.data.key).toBe(items[0].key);
3504
+ });
3505
+ it('should return the same promise for the same key', async () => {
3506
+ const accessor = f.instance.mockItemCollection.documentAccessor();
3507
+ const cache = limitedFirestoreDocumentAccessorSnapshotCache(accessor);
3508
+ const promise1 = cache.getDocumentSnapshotDataPairForKey(items[0].key);
3509
+ const promise2 = cache.getDocumentSnapshotDataPairForKey(items[0].key);
3510
+ expect(promise1).toBe(promise2);
3511
+ });
3512
+ it('should return undefined data for a non-existent document', async () => {
3513
+ const accessor = f.instance.mockItemCollection.documentAccessor();
3514
+ const cache = limitedFirestoreDocumentAccessorSnapshotCache(accessor);
3515
+ const newDoc = newDocuments(accessor, 1)[0];
3516
+ const pair = await cache.getDocumentSnapshotDataPairForKey(newDoc.key);
3517
+ expect(pair.document).toBeDefined();
3518
+ expect(pair.data).toBeUndefined();
3519
+ });
3520
+ });
3521
+ describe('getDocumentSnapshotDataPairsForKeys()', () => {
3522
+ it('should return pairs for all keys in order', async () => {
3523
+ const accessor = f.instance.mockItemCollection.documentAccessor();
3524
+ const cache = limitedFirestoreDocumentAccessorSnapshotCache(accessor);
3525
+ const keys = items.map((x) => x.key);
3526
+ const pairs = await cache.getDocumentSnapshotDataPairsForKeys(keys);
3527
+ expect(pairs.length).toBe(testDocumentCount);
3528
+ pairs.forEach((pair, i) => {
3529
+ expect(pair.document.key).toBe(items[i].key);
3530
+ expect(pair.data).toBeDefined();
3531
+ expect(pair.data.id).toBe(items[i].id);
3532
+ });
3533
+ });
3534
+ it('should use the cache for duplicate keys', async () => {
3535
+ const accessor = f.instance.mockItemCollection.documentAccessor();
3536
+ const cache = limitedFirestoreDocumentAccessorSnapshotCache(accessor);
3537
+ const key = items[0].key;
3538
+ const [pair1] = await cache.getDocumentSnapshotDataPairsForKeys([key]);
3539
+ const [pair2] = await cache.getDocumentSnapshotDataPairsForKeys([key]);
3540
+ expect(pair1).toBe(pair2);
3541
+ });
3542
+ });
3543
+ describe('getDocumentSnapshotDataPairsWithDataForKeys()', () => {
3544
+ it('should return pairs for all existing documents', async () => {
3545
+ const accessor = f.instance.mockItemCollection.documentAccessor();
3546
+ const cache = limitedFirestoreDocumentAccessorSnapshotCache(accessor);
3547
+ const keys = items.map((x) => x.key);
3548
+ const pairs = await cache.getDocumentSnapshotDataPairsWithDataForKeys(keys);
3549
+ expect(pairs.length).toBe(testDocumentCount);
3550
+ pairs.forEach((pair) => {
3551
+ expect(pair.data).toBeDefined();
3552
+ expect(pair.data.id).toBeDefined();
3553
+ expect(pair.data.key).toBeDefined();
3554
+ });
3555
+ });
3556
+ it('should filter out non-existent documents', async () => {
3557
+ const accessor = f.instance.mockItemCollection.documentAccessor();
3558
+ const cache = limitedFirestoreDocumentAccessorSnapshotCache(accessor);
3559
+ const newDoc = newDocuments(accessor, 1)[0];
3560
+ const keys = [...items.map((x) => x.key), newDoc.key];
3561
+ const pairs = await cache.getDocumentSnapshotDataPairsWithDataForKeys(keys);
3562
+ expect(pairs.length).toBe(testDocumentCount);
3563
+ expect(pairs.every((p) => p.data != null)).toBe(true);
3564
+ });
3565
+ });
3566
+ });
3486
3567
  });
3487
3568
  describe('document.rxjs.ts', () => {
3488
3569
  // MARK: latestSnapshotsFromDocuments
@@ -3530,10 +3611,10 @@ function describeFirestoreDocumentUtilityTests(f) {
3530
3611
  });
3531
3612
  }));
3532
3613
  });
3533
- // MARK: latestDataFromDocuments
3534
- describe('latestDataFromDocuments()', () => {
3614
+ // MARK: streamDocumentSnapshotsData
3615
+ describe('streamDocumentSnapshotsData()', () => {
3535
3616
  it('should emit data with id/key for all documents', callbackTest((done) => {
3536
- sub.subscription = latestDataFromDocuments(items)
3617
+ sub.subscription = streamDocumentSnapshotsData(items)
3537
3618
  .pipe(first())
3538
3619
  .subscribe((data) => {
3539
3620
  expect(data.length).toBe(testDocumentCount);
@@ -3546,7 +3627,7 @@ function describeFirestoreDocumentUtilityTests(f) {
3546
3627
  });
3547
3628
  }));
3548
3629
  it('should emit an empty array for empty input', callbackTest((done) => {
3549
- sub.subscription = latestDataFromDocuments([])
3630
+ sub.subscription = streamDocumentSnapshotsData([])
3550
3631
  .pipe(first())
3551
3632
  .subscribe((data) => {
3552
3633
  expect(data.length).toBe(0);
package/test/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@dereekb/firebase/test",
3
- "version": "13.0.6",
3
+ "version": "13.0.7",
4
4
  "peerDependencies": {
5
- "@dereekb/date": "13.0.6",
6
- "@dereekb/firebase": "13.0.6",
7
- "@dereekb/model": "13.0.6",
8
- "@dereekb/rxjs": "13.0.6",
9
- "@dereekb/util": "13.0.6",
5
+ "@dereekb/date": "13.0.7",
6
+ "@dereekb/firebase": "13.0.7",
7
+ "@dereekb/model": "13.0.7",
8
+ "@dereekb/rxjs": "13.0.7",
9
+ "@dereekb/util": "13.0.7",
10
10
  "@firebase/rules-unit-testing": "5.0.0",
11
11
  "date-fns": "^4.0.0",
12
12
  "firebase": "^12.0.0",