@dereekb/firebase 13.11.2 → 13.11.3
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 +2440 -575
- package/index.esm.js +2419 -579
- package/package.json +5 -5
- package/src/lib/client/firestore/array.d.ts +1 -0
- package/src/lib/client/firestore/driver.accessor.batch.d.ts +1 -0
- package/src/lib/client/firestore/driver.accessor.create.d.ts +1 -0
- package/src/lib/client/firestore/driver.accessor.d.ts +1 -0
- package/src/lib/client/firestore/driver.accessor.default.d.ts +1 -0
- package/src/lib/client/firestore/driver.accessor.transaction.d.ts +1 -0
- package/src/lib/client/firestore/increment.d.ts +1 -0
- package/src/lib/client/function/development.function.factory.d.ts +1 -0
- package/src/lib/client/function/function.factory.d.ts +2 -0
- package/src/lib/client/function/model.function.factory.d.ts +1 -0
- package/src/lib/common/firestore/accessor/accessor.d.ts +1 -0
- package/src/lib/common/firestore/accessor/accessor.wrap.d.ts +1 -0
- package/src/lib/common/firestore/accessor/accessor.wrap.modify.d.ts +4 -0
- package/src/lib/common/firestore/accessor/array.d.ts +1 -0
- package/src/lib/common/firestore/accessor/document.d.ts +4 -0
- package/src/lib/common/firestore/accessor/document.paged.d.ts +134 -0
- package/src/lib/common/firestore/accessor/document.utility.d.ts +195 -0
- package/src/lib/common/firestore/accessor/increment.d.ts +1 -0
- package/src/lib/common/firestore/accessor/index.d.ts +1 -0
- package/src/lib/common/firestore/cache/cache.d.ts +1 -0
- package/src/lib/common/firestore/cache/cache.memory.d.ts +3 -0
- package/src/lib/common/firestore/collection/collection.d.ts +29 -2
- package/src/lib/common/firestore/collection/collection.group.d.ts +1 -0
- package/src/lib/common/firestore/collection/collection.query.d.ts +1 -0
- package/src/lib/common/firestore/collection/collection.single.d.ts +1 -0
- package/src/lib/common/firestore/collection/collection.util.d.ts +1 -0
- package/src/lib/common/firestore/collection/index.d.ts +1 -0
- package/src/lib/common/firestore/collection/subcollection.d.ts +1 -0
- package/src/lib/common/firestore/collection/subcollection.paged.d.ts +226 -0
- package/src/lib/common/firestore/collection/subcollection.single.d.ts +1 -0
- package/src/lib/common/firestore/context.d.ts +37 -1
- package/src/lib/common/firestore/driver/query.handler.d.ts +1 -0
- package/src/lib/common/firestore/error.d.ts +1 -0
- package/src/lib/common/firestore/query/constraint.d.ts +2 -0
- package/src/lib/common/firestore/query/iterator.d.ts +5 -0
- package/src/lib/common/firestore/query/query.d.ts +1 -0
- package/src/lib/common/firestore/snapshot/snapshot.d.ts +1 -0
- package/src/lib/common/firestore/snapshot/snapshot.field.d.ts +262 -0
- package/src/lib/common/firestore/util/id.batch.d.ts +1 -0
- package/src/lib/common/model/function.d.ts +1 -0
- package/src/lib/common/model/model.service.d.ts +8 -0
- package/src/lib/common/model/permission/permission.service.d.ts +1 -0
- package/src/lib/common/model/permission/permission.service.grant.d.ts +6 -0
- package/src/lib/common/storage/accessor/path.model.d.ts +1 -0
- package/src/lib/common/storage/context.d.ts +1 -0
- package/src/lib/common/storage/driver/accessor.iterate.d.ts +1 -0
- package/src/lib/common/storage/driver/list.d.ts +1 -0
- package/src/lib/common/storage/storage.d.ts +1 -0
- package/src/lib/model/notification/index.d.ts +2 -0
- package/src/lib/model/notification/notification.api.d.ts +36 -1
- package/src/lib/model/notification/notification.config.d.ts +1 -0
- package/src/lib/model/notification/notification.create.d.ts +2 -0
- package/src/lib/model/notification/notification.create.loggedevent.d.ts +33 -0
- package/src/lib/model/notification/notification.create.task.d.ts +1 -0
- package/src/lib/model/notification/notification.d.ts +179 -3
- package/src/lib/model/notification/notification.details.d.ts +1 -0
- package/src/lib/model/notification/notification.id.d.ts +23 -1
- package/src/lib/model/notification/notification.loggedevent.loader.d.ts +82 -0
- package/src/lib/model/notification/notification.message.d.ts +2 -0
- package/src/lib/model/notification/notification.query.d.ts +17 -0
- package/src/lib/model/notification/notification.util.d.ts +12 -1
- package/src/lib/model/storagefile/storagefile.create.d.ts +1 -0
- package/src/lib/model/storagefile/storagefile.d.ts +1 -0
- package/src/lib/model/storagefile/storagefile.file.d.ts +1 -0
- package/src/lib/model/storagefile/storagefile.permission.d.ts +1 -0
- package/src/lib/model/storagefile/storagefile.upload.d.ts +2 -0
- package/src/lib/model/storagefile/storagefile.upload.determiner.d.ts +2 -0
- package/test/index.cjs.js +1038 -1
- package/test/index.esm.js +1031 -3
- package/test/package.json +6 -6
- package/test/src/lib/common/mock/mock.item.d.ts +119 -2
- package/test/src/lib/common/mock/mock.item.service.d.ts +21 -1
package/test/index.esm.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { performAsyncTasks, cachedGetter, bitwiseObjectDencoder, modelFieldConversions, waitForMs, isEvenNumber, unique, arrayFactory, mapGetter, randomNumberFactory, randomFromArrayFactory, idBatchFactory, arrayContainsDuplicateValue, useCallback, readableStreamToBuffer, SLASH_PATH_SEPARATOR } from '@dereekb/util';
|
|
2
2
|
import { initializeTestEnvironment } from '@firebase/rules-unit-testing';
|
|
3
|
-
import { firebaseStorageContextFactory, firestoreContextFactory, firebaseFirestoreClientDrivers, firebaseStorageClientDrivers, firestoreModelIdentity, snapshotConverterFunctions, firestoreBoolean, optionalFirestoreNumber, optionalFirestoreDate, optionalFirestoreArray, optionalFirestoreString, firestoreDate, firestoreBitwiseObjectMap, firestoreUniqueStringArray, firestoreNumber, firestoreString, firestoreUID, copyUserRelatedDataAccessorFactoryFunction, firestoreSubObject, AbstractFirestoreDocument, AbstractFirestoreDocumentWithParent, firebaseModelServiceFactory, grantFullAccessIfAdmin, firebaseModelsService, systemStateFirestoreCollection, allChildDocumentsUnderParent, where, makeDocuments, getDocumentSnapshotPairs, useDocumentSnapshot, useDocumentSnapshotData, firestoreIdBatchVerifierFactory, limit, orderBy, limitToLast, whereDocumentId, loadAllFirestoreDocumentSnapshotPairs, loadAllFirestoreDocumentSnapshot, iterateFirestoreDocumentSnapshotPairs, iterateFirestoreDocumentSnapshots, iterateFirestoreDocumentSnapshotPairBatches, iterateFirestoreDocumentSnapshotBatches, whereStringHasRootIdentityModelKey, whereStringValueHasPrefix, whereDateIsAfterWithSort, whereDateIsBeforeWithSort, whereDateIsOnOrAfterWithSort, whereDateIsOnOrBeforeWithSort, whereDateIsInRange, whereDateIsBetween, startAt, orderByDocumentId, startAtValue, startAfter, endAt, endAtValue, endBefore, streamFromOnSnapshot, latestSnapshotsFromDocuments, newDocuments, loadDocumentsForDocumentReferences, loadDocumentsForDocumentReferencesFromValues, loadDocumentsForKeys, loadDocumentsForKeysFromValues, loadDocumentsForIds, loadDocumentsForIdsFromValues, firestoreDocumentLoader, setIdAndKeyFromKeyIdRefOnDocumentData, firestoreModelIdFromDocument, firestoreModelIdsFromDocuments, firestoreModelKeyFromDocument, firestoreModelKeysFromDocuments, documentReferenceFromDocument, documentReferencesFromDocuments, limitedFirestoreDocumentAccessorSnapshotCache, mapLatestSnapshotsFromDocuments, streamDocumentSnapshotsData, dataFromDocumentSnapshots, streamDocumentSnapshotDataPairs, streamDocumentSnapshotDataPairsWithData, getDocumentSnapshots, getDocumentSnapshotPair, getDocumentSnapshotDataPair, getDocumentSnapshotDataPairs, getDocumentSnapshotDataPairsWithData, getDocumentSnapshotDataTuples, getDocumentSnapshotData, getDocumentSnapshotsData, getDataFromDocumentSnapshots, loadDocumentsForSnapshots, firestoreDocumentSnapshotPairsLoader, documentData, documentDataFunction, documentDataWithIdAndKey, setIdAndKeyFromSnapshotOnDocumentData, firebaseQuerySnapshotAccumulator, firebaseQueryItemAccumulator, uploadFileWithStream, iterateStorageListFilesByEachFile } from '@dereekb/firebase';
|
|
3
|
+
import { firebaseStorageContextFactory, firestoreContextFactory, firebaseFirestoreClientDrivers, firebaseStorageClientDrivers, firestoreModelIdentity, snapshotConverterFunctions, firestoreBoolean, optionalFirestoreNumber, optionalFirestoreDate, optionalFirestoreArray, optionalFirestoreString, firestoreDate, firestoreBitwiseObjectMap, firestoreUniqueStringArray, firestoreNumber, firestoreString, firestoreUID, copyUserRelatedDataAccessorFactoryFunction, firestoreSubObject, defaultPagedItemPageDataConverter, AbstractFirestoreDocument, AbstractFirestoreDocumentWithParent, firebaseModelServiceFactory, grantFullAccessIfAdmin, firebaseModelsService, systemStateFirestoreCollection, allChildDocumentsUnderParent, where, makeDocuments, getDocumentSnapshotPairs, useDocumentSnapshot, useDocumentSnapshotData, firestoreIdBatchVerifierFactory, limit, orderBy, limitToLast, whereDocumentId, loadAllFirestoreDocumentSnapshotPairs, loadAllFirestoreDocumentSnapshot, iterateFirestoreDocumentSnapshotPairs, iterateFirestoreDocumentSnapshots, iterateFirestoreDocumentSnapshotPairBatches, iterateFirestoreDocumentSnapshotBatches, whereStringHasRootIdentityModelKey, whereStringValueHasPrefix, whereDateIsAfterWithSort, whereDateIsBeforeWithSort, whereDateIsOnOrAfterWithSort, whereDateIsOnOrBeforeWithSort, whereDateIsInRange, whereDateIsBetween, startAt, orderByDocumentId, startAtValue, startAfter, endAt, endAtValue, endBefore, streamFromOnSnapshot, latestSnapshotsFromDocuments, newDocuments, loadDocumentsForDocumentReferences, loadDocumentsForDocumentReferencesFromValues, loadDocumentsForKeys, loadDocumentsForKeysFromValues, loadDocumentsForIds, loadDocumentsForIdsFromValues, firestoreDocumentLoader, setIdAndKeyFromKeyIdRefOnDocumentData, firestoreModelIdFromDocument, firestoreModelIdsFromDocuments, firestoreModelKeyFromDocument, firestoreModelKeysFromDocuments, documentReferenceFromDocument, documentReferencesFromDocuments, limitedFirestoreDocumentAccessorSnapshotCache, mapLatestSnapshotsFromDocuments, streamDocumentSnapshotsData, dataFromDocumentSnapshots, streamDocumentSnapshotDataPairs, streamDocumentSnapshotDataPairsWithData, getDocumentSnapshots, getDocumentSnapshotPair, getDocumentSnapshotDataPair, getDocumentSnapshotDataPairs, getDocumentSnapshotDataPairsWithData, getDocumentSnapshotDataTuples, getDocumentSnapshotData, getDocumentSnapshotsData, getDataFromDocumentSnapshots, loadDocumentsForSnapshots, firestoreDocumentSnapshotPairsLoader, documentData, documentDataFunction, documentDataWithIdAndKey, setIdAndKeyFromSnapshotOnDocumentData, firebaseQuerySnapshotAccumulator, firebaseQueryItemAccumulator, uploadFileWithStream, iterateStorageListFilesByEachFile } from '@dereekb/firebase';
|
|
4
4
|
import { setLogLevel } from 'firebase/firestore';
|
|
5
5
|
import { AbstractTestContextFixture, instanceWrapTestContextFactory, AbstractWrappedFixtureWithInstance, itShouldFail, callbackTest, expectFail } from '@dereekb/util/test';
|
|
6
6
|
import { firstValueFrom, filter, skip, from, first, map, switchMap } from 'rxjs';
|
|
@@ -1721,6 +1721,119 @@ var mockItemUserIdentifier = '0';
|
|
|
1721
1721
|
firestoreContext: firestoreContext
|
|
1722
1722
|
});
|
|
1723
1723
|
}
|
|
1724
|
+
// MARK: MockItemPaged
|
|
1725
|
+
/**
|
|
1726
|
+
* {@link firestoreModelIdentity} for the MockItemPaged subcollection (`mockItemPaged` / `mip2`).
|
|
1727
|
+
*
|
|
1728
|
+
* Child of {@link mockItemIdentity}. Stores a logical {@link MockItemPagedEntry} array distributed
|
|
1729
|
+
* across multiple page documents, plus an index document that summarizes the layout. See
|
|
1730
|
+
* {@link PagedItemFirestoreCollection} for the underlying mechanism.
|
|
1731
|
+
*/ var mockItemPagedIdentity = firestoreModelIdentity(mockItemIdentity, 'mockItemPaged', 'mip2');
|
|
1732
|
+
/**
|
|
1733
|
+
* {@link AbstractFirestoreDocumentWithParent} implementation for a single page document inside a
|
|
1734
|
+
* {@link MockItemPagedFirestoreCollection}. Used by the model service factory to address pages
|
|
1735
|
+
* the same way other subcollection documents are addressed.
|
|
1736
|
+
*/ var MockItemPagedDocument = /*#__PURE__*/ function(AbstractFirestoreDocumentWithParent) {
|
|
1737
|
+
_inherits$4(MockItemPagedDocument, AbstractFirestoreDocumentWithParent);
|
|
1738
|
+
function MockItemPagedDocument() {
|
|
1739
|
+
_class_call_check$5(this, MockItemPagedDocument);
|
|
1740
|
+
return _call_super$4(this, MockItemPagedDocument, arguments);
|
|
1741
|
+
}
|
|
1742
|
+
_create_class$4(MockItemPagedDocument, [
|
|
1743
|
+
{
|
|
1744
|
+
key: "modelIdentity",
|
|
1745
|
+
get: function get() {
|
|
1746
|
+
return mockItemPagedIdentity;
|
|
1747
|
+
}
|
|
1748
|
+
}
|
|
1749
|
+
]);
|
|
1750
|
+
return MockItemPagedDocument;
|
|
1751
|
+
}(AbstractFirestoreDocumentWithParent);
|
|
1752
|
+
/**
|
|
1753
|
+
* Per-item converter for {@link MockItemPagedEntry} used by the paged accessor.
|
|
1754
|
+
*
|
|
1755
|
+
* The mock entry shape is already Firestore-safe, so the converter is an identity
|
|
1756
|
+
* pass-through. Production usage may wrap a real converter (e.g. for date fields).
|
|
1757
|
+
*/ var mockItemPagedEntryConverter = {
|
|
1758
|
+
fromData: function fromData(data) {
|
|
1759
|
+
return data;
|
|
1760
|
+
},
|
|
1761
|
+
toData: function toData(item) {
|
|
1762
|
+
return item;
|
|
1763
|
+
}
|
|
1764
|
+
};
|
|
1765
|
+
/**
|
|
1766
|
+
* Static distribution scheme for {@link MockItemPagedEntry} that buckets items by their
|
|
1767
|
+
* {@link MockItemPagedEntry.group} field across three page IDs (`a`, `b`, `c`).
|
|
1768
|
+
*/ var mockItemPagedAlphaDistributionScheme = {
|
|
1769
|
+
pageIds: [
|
|
1770
|
+
'a',
|
|
1771
|
+
'b',
|
|
1772
|
+
'c'
|
|
1773
|
+
],
|
|
1774
|
+
distribute: function distribute(entry) {
|
|
1775
|
+
return entry.group;
|
|
1776
|
+
}
|
|
1777
|
+
};
|
|
1778
|
+
/**
|
|
1779
|
+
* Default `maxItemsPerPage` used by the dynamic mock paged collection factory. Kept small to
|
|
1780
|
+
* exercise multi-page boundary conditions in tests without writing many entries.
|
|
1781
|
+
*/ var MOCK_ITEM_PAGED_DEFAULT_MAX_ITEMS_PER_PAGE = 3;
|
|
1782
|
+
/**
|
|
1783
|
+
* Creates a factory for producing {@link MockItemPagedFirestoreCollection} instances bound to a
|
|
1784
|
+
* parent {@link MockItemDocument}.
|
|
1785
|
+
*
|
|
1786
|
+
* @param firestoreContext - The Firestore context used to resolve the underlying subcollection.
|
|
1787
|
+
* @param config - Optional config selecting between dynamic (default) and static distribution.
|
|
1788
|
+
* @returns A factory that, given a parent {@link MockItemDocument}, returns a paged subcollection
|
|
1789
|
+
* wired with {@link mockItemPagedEntryConverter}.
|
|
1790
|
+
*/ function mockItemPagedFirestoreCollection(firestoreContext, config) {
|
|
1791
|
+
var _ref = config !== null && config !== void 0 ? config : {}, distributionScheme = _ref.distributionScheme, _ref_maxItemsPerPage = _ref.maxItemsPerPage, maxItemsPerPage = _ref_maxItemsPerPage === void 0 ? MOCK_ITEM_PAGED_DEFAULT_MAX_ITEMS_PER_PAGE : _ref_maxItemsPerPage;
|
|
1792
|
+
return function(parent) {
|
|
1793
|
+
return firestoreContext.pagedItemFirestoreCollection({
|
|
1794
|
+
modelIdentity: mockItemPagedIdentity,
|
|
1795
|
+
collection: firestoreContext.subcollection(parent.documentRef, mockItemPagedIdentity.collectionName),
|
|
1796
|
+
parent: parent,
|
|
1797
|
+
makeDocument: function makeDocument(a, d) {
|
|
1798
|
+
return new MockItemPagedDocument(a, d);
|
|
1799
|
+
},
|
|
1800
|
+
firestoreContext: firestoreContext,
|
|
1801
|
+
maxItemsPerPage: maxItemsPerPage,
|
|
1802
|
+
distributionScheme: distributionScheme,
|
|
1803
|
+
itemConverter: mockItemPagedEntryConverter
|
|
1804
|
+
});
|
|
1805
|
+
};
|
|
1806
|
+
}
|
|
1807
|
+
/**
|
|
1808
|
+
* Creates a {@link CollectionGroup} reference for querying all {@link MockItemPagedDocumentData}
|
|
1809
|
+
* page documents across parents.
|
|
1810
|
+
*
|
|
1811
|
+
* Note: the index document (`_index`) lives in the same Firestore collection but has a different
|
|
1812
|
+
* shape ({@link PagedItemIndexData}); collection-group queries will surface both. Consumers
|
|
1813
|
+
* should filter by document id when only pages are desired.
|
|
1814
|
+
*
|
|
1815
|
+
* @param context - The Firestore context used to resolve the collection group.
|
|
1816
|
+
* @returns A typed {@link CollectionGroup} reference for the MockItemPaged collection name.
|
|
1817
|
+
*/ function mockItemPagedCollectionReference(context) {
|
|
1818
|
+
return context.collectionGroup(mockItemPagedIdentity.collectionName);
|
|
1819
|
+
}
|
|
1820
|
+
/**
|
|
1821
|
+
* Creates a {@link MockItemPagedFirestoreCollectionGroup} for cross-parent access to paged
|
|
1822
|
+
* page documents.
|
|
1823
|
+
*
|
|
1824
|
+
* @param firestoreContext - The Firestore context used to resolve the underlying collection group reference.
|
|
1825
|
+
* @returns A typed {@link MockItemPagedFirestoreCollectionGroup}.
|
|
1826
|
+
*/ function mockItemPagedFirestoreCollectionGroup(firestoreContext) {
|
|
1827
|
+
return firestoreContext.firestoreCollectionGroup({
|
|
1828
|
+
modelIdentity: mockItemPagedIdentity,
|
|
1829
|
+
converter: defaultPagedItemPageDataConverter(),
|
|
1830
|
+
queryLike: mockItemPagedCollectionReference(firestoreContext),
|
|
1831
|
+
makeDocument: function makeDocument(accessor, documentAccessor) {
|
|
1832
|
+
return new MockItemPagedDocument(accessor, documentAccessor);
|
|
1833
|
+
},
|
|
1834
|
+
firestoreContext: firestoreContext
|
|
1835
|
+
});
|
|
1836
|
+
}
|
|
1724
1837
|
// MARK: Mock System Item
|
|
1725
1838
|
/**
|
|
1726
1839
|
* System state type identifier for mock system state data.
|
|
@@ -1778,6 +1891,14 @@ function _class_call_check$4(instance, Constructor) {
|
|
|
1778
1891
|
mockItemSubItemCollectionGroup: mockItemSubItemFirestoreCollectionGroup(firestoreContext),
|
|
1779
1892
|
mockItemSubItemDeepCollectionFactory: mockItemSubItemDeepFirestoreCollection(firestoreContext),
|
|
1780
1893
|
mockItemSubItemDeepCollectionGroup: mockItemSubItemDeepFirestoreCollectionGroup(firestoreContext),
|
|
1894
|
+
mockItemPagedCollectionFactory: mockItemPagedFirestoreCollection(firestoreContext),
|
|
1895
|
+
mockItemPagedStaticCollectionFactory: mockItemPagedFirestoreCollection(firestoreContext, {
|
|
1896
|
+
distributionScheme: mockItemPagedAlphaDistributionScheme
|
|
1897
|
+
}),
|
|
1898
|
+
mockItemPagedCollectionFactoryWithConfig: function mockItemPagedCollectionFactoryWithConfig(config) {
|
|
1899
|
+
return mockItemPagedFirestoreCollection(firestoreContext, config);
|
|
1900
|
+
},
|
|
1901
|
+
mockItemPagedCollectionGroup: mockItemPagedFirestoreCollectionGroup(firestoreContext),
|
|
1781
1902
|
mockItemSystemStateCollection: systemStateFirestoreCollection(firestoreContext, mockItemSystemStateStoredDataConverterMap)
|
|
1782
1903
|
};
|
|
1783
1904
|
}
|
|
@@ -1855,6 +1976,24 @@ function _class_call_check$4(instance, Constructor) {
|
|
|
1855
1976
|
return c.app.mockItemSubItemDeepCollectionGroup;
|
|
1856
1977
|
}
|
|
1857
1978
|
});
|
|
1979
|
+
/**
|
|
1980
|
+
* Model service factory for {@link MockItemPagedDocumentData} (paged page documents).
|
|
1981
|
+
*
|
|
1982
|
+
* Returns configurable roles from `context.rolesToReturn`, defaulting to `{ read: true }`. The
|
|
1983
|
+
* page document is the framework envelope (`{ i, c }`); per-entry permissions are not modelled
|
|
1984
|
+
* because entries live inside the page array, not as standalone documents.
|
|
1985
|
+
*/ var mockItemPagedFirebaseModelServiceFactory = firebaseModelServiceFactory({
|
|
1986
|
+
roleMapForModel: function roleMapForModel(output, context, _model) {
|
|
1987
|
+
var _context_rolesToReturn;
|
|
1988
|
+
var roles = (_context_rolesToReturn = context.rolesToReturn) !== null && _context_rolesToReturn !== void 0 ? _context_rolesToReturn : {
|
|
1989
|
+
read: true
|
|
1990
|
+
};
|
|
1991
|
+
return roles;
|
|
1992
|
+
},
|
|
1993
|
+
getFirestoreCollection: function getFirestoreCollection(c) {
|
|
1994
|
+
return c.app.mockItemPagedCollectionGroup;
|
|
1995
|
+
}
|
|
1996
|
+
});
|
|
1858
1997
|
/**
|
|
1859
1998
|
* Model service factory for {@link SystemState}. Only grants access to system admins via {@link grantFullAccessIfAdmin}.
|
|
1860
1999
|
*/ var mockItemSystemStateFirebaseModelServiceFactory = firebaseModelServiceFactory({
|
|
@@ -1875,7 +2014,8 @@ function _class_call_check$4(instance, Constructor) {
|
|
|
1875
2014
|
mockItemPrivate: mockItemPrivateFirebaseModelServiceFactory,
|
|
1876
2015
|
mockItemUser: mockItemUserFirebaseModelServiceFactory,
|
|
1877
2016
|
mockItemSub: mockItemSubItemFirebaseModelServiceFactory,
|
|
1878
|
-
mockItemSubItemDeep: mockItemSubItemDeepFirebaseModelServiceFactory
|
|
2017
|
+
mockItemSubItemDeep: mockItemSubItemDeepFirebaseModelServiceFactory,
|
|
2018
|
+
mockItemPaged: mockItemPagedFirebaseModelServiceFactory
|
|
1879
2019
|
};
|
|
1880
2020
|
/**
|
|
1881
2021
|
* Composite model service built from {@link MOCK_FIREBASE_MODEL_SERVICE_FACTORIES}.
|
|
@@ -3578,6 +3718,894 @@ function _ts_generator$4(thisArg, body) {
|
|
|
3578
3718
|
});
|
|
3579
3719
|
});
|
|
3580
3720
|
});
|
|
3721
|
+
describe('pagedItemFirestoreCollection (MockItemPaged)', function() {
|
|
3722
|
+
describe('configuration', function() {
|
|
3723
|
+
it('exposes indexDocumentId, distributionScheme, and isStaticDistribution flags', function() {
|
|
3724
|
+
var dynamicCollection = f.instance.collections.mockItemPagedCollectionFactory(itemDocument);
|
|
3725
|
+
expect(dynamicCollection.indexDocumentId).toBe('_index');
|
|
3726
|
+
expect(dynamicCollection.isStaticDistribution).toBe(false);
|
|
3727
|
+
expect(dynamicCollection.distributionScheme).toBeUndefined();
|
|
3728
|
+
var staticCollection = f.instance.collections.mockItemPagedStaticCollectionFactory(itemDocument);
|
|
3729
|
+
expect(staticCollection.indexDocumentId).toBe('_index');
|
|
3730
|
+
expect(staticCollection.isStaticDistribution).toBe(true);
|
|
3731
|
+
expect(staticCollection.distributionScheme).toBeDefined();
|
|
3732
|
+
});
|
|
3733
|
+
});
|
|
3734
|
+
describe('on an empty collection', function() {
|
|
3735
|
+
var collection;
|
|
3736
|
+
beforeEach(function() {
|
|
3737
|
+
collection = f.instance.collections.mockItemPagedCollectionFactory(itemDocument);
|
|
3738
|
+
});
|
|
3739
|
+
describe('loadIndex()', function() {
|
|
3740
|
+
it('returns undefined when the index document has not been written yet', function() {
|
|
3741
|
+
return _async_to_generator$4(function() {
|
|
3742
|
+
var index;
|
|
3743
|
+
return _ts_generator$4(this, function(_state) {
|
|
3744
|
+
switch(_state.label){
|
|
3745
|
+
case 0:
|
|
3746
|
+
return [
|
|
3747
|
+
4,
|
|
3748
|
+
collection.loadIndex()
|
|
3749
|
+
];
|
|
3750
|
+
case 1:
|
|
3751
|
+
index = _state.sent();
|
|
3752
|
+
expect(index).toBeUndefined();
|
|
3753
|
+
return [
|
|
3754
|
+
2
|
|
3755
|
+
];
|
|
3756
|
+
}
|
|
3757
|
+
});
|
|
3758
|
+
})();
|
|
3759
|
+
});
|
|
3760
|
+
});
|
|
3761
|
+
describe('loadAllItems()', function() {
|
|
3762
|
+
it('returns an empty array when the index document has not been written yet', function() {
|
|
3763
|
+
return _async_to_generator$4(function() {
|
|
3764
|
+
var items;
|
|
3765
|
+
return _ts_generator$4(this, function(_state) {
|
|
3766
|
+
switch(_state.label){
|
|
3767
|
+
case 0:
|
|
3768
|
+
return [
|
|
3769
|
+
4,
|
|
3770
|
+
collection.loadAllItems()
|
|
3771
|
+
];
|
|
3772
|
+
case 1:
|
|
3773
|
+
items = _state.sent();
|
|
3774
|
+
expect(items).toEqual([]);
|
|
3775
|
+
return [
|
|
3776
|
+
2
|
|
3777
|
+
];
|
|
3778
|
+
}
|
|
3779
|
+
});
|
|
3780
|
+
})();
|
|
3781
|
+
});
|
|
3782
|
+
});
|
|
3783
|
+
describe('loadItemsForPages()', function() {
|
|
3784
|
+
it('returns an empty array when no pages exist', function() {
|
|
3785
|
+
return _async_to_generator$4(function() {
|
|
3786
|
+
var items;
|
|
3787
|
+
return _ts_generator$4(this, function(_state) {
|
|
3788
|
+
switch(_state.label){
|
|
3789
|
+
case 0:
|
|
3790
|
+
return [
|
|
3791
|
+
4,
|
|
3792
|
+
collection.loadItemsForPages([
|
|
3793
|
+
'0',
|
|
3794
|
+
'1'
|
|
3795
|
+
])
|
|
3796
|
+
];
|
|
3797
|
+
case 1:
|
|
3798
|
+
items = _state.sent();
|
|
3799
|
+
expect(items).toEqual([]);
|
|
3800
|
+
return [
|
|
3801
|
+
2
|
|
3802
|
+
];
|
|
3803
|
+
}
|
|
3804
|
+
});
|
|
3805
|
+
})();
|
|
3806
|
+
});
|
|
3807
|
+
it('returns an empty array when called with no page ids', function() {
|
|
3808
|
+
return _async_to_generator$4(function() {
|
|
3809
|
+
var items;
|
|
3810
|
+
return _ts_generator$4(this, function(_state) {
|
|
3811
|
+
switch(_state.label){
|
|
3812
|
+
case 0:
|
|
3813
|
+
return [
|
|
3814
|
+
4,
|
|
3815
|
+
collection.loadItemsForPages([])
|
|
3816
|
+
];
|
|
3817
|
+
case 1:
|
|
3818
|
+
items = _state.sent();
|
|
3819
|
+
expect(items).toEqual([]);
|
|
3820
|
+
return [
|
|
3821
|
+
2
|
|
3822
|
+
];
|
|
3823
|
+
}
|
|
3824
|
+
});
|
|
3825
|
+
})();
|
|
3826
|
+
});
|
|
3827
|
+
});
|
|
3828
|
+
});
|
|
3829
|
+
describe('writeAllItems() (dynamic distribution)', function() {
|
|
3830
|
+
var collection;
|
|
3831
|
+
beforeEach(function() {
|
|
3832
|
+
collection = f.instance.collections.mockItemPagedCollectionFactory(itemDocument);
|
|
3833
|
+
});
|
|
3834
|
+
it('splits items across pages by maxItemsPerPage and updates the index', function() {
|
|
3835
|
+
return _async_to_generator$4(function() {
|
|
3836
|
+
var items, index;
|
|
3837
|
+
return _ts_generator$4(this, function(_state) {
|
|
3838
|
+
switch(_state.label){
|
|
3839
|
+
case 0:
|
|
3840
|
+
items = [
|
|
3841
|
+
{
|
|
3842
|
+
id: '1',
|
|
3843
|
+
group: 'a',
|
|
3844
|
+
value: 1
|
|
3845
|
+
},
|
|
3846
|
+
{
|
|
3847
|
+
id: '2',
|
|
3848
|
+
group: 'a',
|
|
3849
|
+
value: 2
|
|
3850
|
+
},
|
|
3851
|
+
{
|
|
3852
|
+
id: '3',
|
|
3853
|
+
group: 'b',
|
|
3854
|
+
value: 3
|
|
3855
|
+
},
|
|
3856
|
+
{
|
|
3857
|
+
id: '4',
|
|
3858
|
+
group: 'b',
|
|
3859
|
+
value: 4
|
|
3860
|
+
},
|
|
3861
|
+
{
|
|
3862
|
+
id: '5',
|
|
3863
|
+
group: 'c',
|
|
3864
|
+
value: 5
|
|
3865
|
+
}
|
|
3866
|
+
];
|
|
3867
|
+
return [
|
|
3868
|
+
4,
|
|
3869
|
+
collection.writeAllItems(items)
|
|
3870
|
+
];
|
|
3871
|
+
case 1:
|
|
3872
|
+
_state.sent();
|
|
3873
|
+
return [
|
|
3874
|
+
4,
|
|
3875
|
+
collection.loadIndex()
|
|
3876
|
+
];
|
|
3877
|
+
case 2:
|
|
3878
|
+
index = _state.sent();
|
|
3879
|
+
expect(index).toBeDefined();
|
|
3880
|
+
expect(index === null || index === void 0 ? void 0 : index.tc).toBe(items.length);
|
|
3881
|
+
expect(index === null || index === void 0 ? void 0 : index.p).toEqual([
|
|
3882
|
+
'0',
|
|
3883
|
+
'1'
|
|
3884
|
+
]);
|
|
3885
|
+
expect(index === null || index === void 0 ? void 0 : index.pc).toEqual({
|
|
3886
|
+
'0': MOCK_ITEM_PAGED_DEFAULT_MAX_ITEMS_PER_PAGE,
|
|
3887
|
+
'1': items.length - MOCK_ITEM_PAGED_DEFAULT_MAX_ITEMS_PER_PAGE
|
|
3888
|
+
});
|
|
3889
|
+
expect(index === null || index === void 0 ? void 0 : index.u).toBeGreaterThan(0);
|
|
3890
|
+
return [
|
|
3891
|
+
2
|
|
3892
|
+
];
|
|
3893
|
+
}
|
|
3894
|
+
});
|
|
3895
|
+
})();
|
|
3896
|
+
});
|
|
3897
|
+
it('round-trips items via loadAllItems()', function() {
|
|
3898
|
+
return _async_to_generator$4(function() {
|
|
3899
|
+
var items, loaded;
|
|
3900
|
+
return _ts_generator$4(this, function(_state) {
|
|
3901
|
+
switch(_state.label){
|
|
3902
|
+
case 0:
|
|
3903
|
+
items = Array.from({
|
|
3904
|
+
length: 7
|
|
3905
|
+
}, function(_, i) {
|
|
3906
|
+
return {
|
|
3907
|
+
id: "".concat(i),
|
|
3908
|
+
group: 'a',
|
|
3909
|
+
value: i
|
|
3910
|
+
};
|
|
3911
|
+
});
|
|
3912
|
+
return [
|
|
3913
|
+
4,
|
|
3914
|
+
collection.writeAllItems(items)
|
|
3915
|
+
];
|
|
3916
|
+
case 1:
|
|
3917
|
+
_state.sent();
|
|
3918
|
+
return [
|
|
3919
|
+
4,
|
|
3920
|
+
collection.loadAllItems()
|
|
3921
|
+
];
|
|
3922
|
+
case 2:
|
|
3923
|
+
loaded = _state.sent();
|
|
3924
|
+
expect(loaded).toHaveLength(items.length);
|
|
3925
|
+
expect(loaded.map(function(x) {
|
|
3926
|
+
return x.id;
|
|
3927
|
+
}).sort()).toEqual(items.map(function(x) {
|
|
3928
|
+
return x.id;
|
|
3929
|
+
}).sort());
|
|
3930
|
+
return [
|
|
3931
|
+
2
|
|
3932
|
+
];
|
|
3933
|
+
}
|
|
3934
|
+
});
|
|
3935
|
+
})();
|
|
3936
|
+
});
|
|
3937
|
+
it('writes a single page when items fit within maxItemsPerPage', function() {
|
|
3938
|
+
return _async_to_generator$4(function() {
|
|
3939
|
+
var items, index;
|
|
3940
|
+
return _ts_generator$4(this, function(_state) {
|
|
3941
|
+
switch(_state.label){
|
|
3942
|
+
case 0:
|
|
3943
|
+
items = [
|
|
3944
|
+
{
|
|
3945
|
+
id: '1',
|
|
3946
|
+
group: 'a',
|
|
3947
|
+
value: 1
|
|
3948
|
+
},
|
|
3949
|
+
{
|
|
3950
|
+
id: '2',
|
|
3951
|
+
group: 'a',
|
|
3952
|
+
value: 2
|
|
3953
|
+
}
|
|
3954
|
+
];
|
|
3955
|
+
return [
|
|
3956
|
+
4,
|
|
3957
|
+
collection.writeAllItems(items)
|
|
3958
|
+
];
|
|
3959
|
+
case 1:
|
|
3960
|
+
_state.sent();
|
|
3961
|
+
return [
|
|
3962
|
+
4,
|
|
3963
|
+
collection.loadIndex()
|
|
3964
|
+
];
|
|
3965
|
+
case 2:
|
|
3966
|
+
index = _state.sent();
|
|
3967
|
+
expect(index === null || index === void 0 ? void 0 : index.tc).toBe(2);
|
|
3968
|
+
expect(index === null || index === void 0 ? void 0 : index.p).toEqual([
|
|
3969
|
+
'0'
|
|
3970
|
+
]);
|
|
3971
|
+
expect(index === null || index === void 0 ? void 0 : index.pc).toEqual({
|
|
3972
|
+
'0': 2
|
|
3973
|
+
});
|
|
3974
|
+
return [
|
|
3975
|
+
2
|
|
3976
|
+
];
|
|
3977
|
+
}
|
|
3978
|
+
});
|
|
3979
|
+
})();
|
|
3980
|
+
});
|
|
3981
|
+
it('writes only the index when given an empty items array', function() {
|
|
3982
|
+
return _async_to_generator$4(function() {
|
|
3983
|
+
var index;
|
|
3984
|
+
return _ts_generator$4(this, function(_state) {
|
|
3985
|
+
switch(_state.label){
|
|
3986
|
+
case 0:
|
|
3987
|
+
return [
|
|
3988
|
+
4,
|
|
3989
|
+
collection.writeAllItems([])
|
|
3990
|
+
];
|
|
3991
|
+
case 1:
|
|
3992
|
+
_state.sent();
|
|
3993
|
+
return [
|
|
3994
|
+
4,
|
|
3995
|
+
collection.loadIndex()
|
|
3996
|
+
];
|
|
3997
|
+
case 2:
|
|
3998
|
+
index = _state.sent();
|
|
3999
|
+
expect(index).toBeDefined();
|
|
4000
|
+
expect(index === null || index === void 0 ? void 0 : index.tc).toBe(0);
|
|
4001
|
+
expect(index === null || index === void 0 ? void 0 : index.p).toEqual([]);
|
|
4002
|
+
expect(index === null || index === void 0 ? void 0 : index.pc).toEqual({});
|
|
4003
|
+
return [
|
|
4004
|
+
2
|
|
4005
|
+
];
|
|
4006
|
+
}
|
|
4007
|
+
});
|
|
4008
|
+
})();
|
|
4009
|
+
});
|
|
4010
|
+
it('shrinks pages and deletes obsolete pages on a smaller rewrite', function() {
|
|
4011
|
+
return _async_to_generator$4(function() {
|
|
4012
|
+
var initialItems, initialIndex, smallerItems, newIndex, reloaded, removedPage;
|
|
4013
|
+
return _ts_generator$4(this, function(_state) {
|
|
4014
|
+
switch(_state.label){
|
|
4015
|
+
case 0:
|
|
4016
|
+
initialItems = Array.from({
|
|
4017
|
+
length: 9
|
|
4018
|
+
}, function(_, i) {
|
|
4019
|
+
return {
|
|
4020
|
+
id: "".concat(i),
|
|
4021
|
+
group: 'a',
|
|
4022
|
+
value: i
|
|
4023
|
+
};
|
|
4024
|
+
});
|
|
4025
|
+
return [
|
|
4026
|
+
4,
|
|
4027
|
+
collection.writeAllItems(initialItems)
|
|
4028
|
+
];
|
|
4029
|
+
case 1:
|
|
4030
|
+
_state.sent();
|
|
4031
|
+
return [
|
|
4032
|
+
4,
|
|
4033
|
+
collection.loadIndex()
|
|
4034
|
+
];
|
|
4035
|
+
case 2:
|
|
4036
|
+
initialIndex = _state.sent();
|
|
4037
|
+
expect(initialIndex === null || initialIndex === void 0 ? void 0 : initialIndex.p).toEqual([
|
|
4038
|
+
'0',
|
|
4039
|
+
'1',
|
|
4040
|
+
'2'
|
|
4041
|
+
]);
|
|
4042
|
+
smallerItems = initialItems.slice(0, 2);
|
|
4043
|
+
return [
|
|
4044
|
+
4,
|
|
4045
|
+
collection.writeAllItems(smallerItems)
|
|
4046
|
+
];
|
|
4047
|
+
case 3:
|
|
4048
|
+
_state.sent();
|
|
4049
|
+
return [
|
|
4050
|
+
4,
|
|
4051
|
+
collection.loadIndex()
|
|
4052
|
+
];
|
|
4053
|
+
case 4:
|
|
4054
|
+
newIndex = _state.sent();
|
|
4055
|
+
expect(newIndex === null || newIndex === void 0 ? void 0 : newIndex.tc).toBe(2);
|
|
4056
|
+
expect(newIndex === null || newIndex === void 0 ? void 0 : newIndex.p).toEqual([
|
|
4057
|
+
'0'
|
|
4058
|
+
]);
|
|
4059
|
+
expect(newIndex === null || newIndex === void 0 ? void 0 : newIndex.pc).toEqual({
|
|
4060
|
+
'0': 2
|
|
4061
|
+
});
|
|
4062
|
+
return [
|
|
4063
|
+
4,
|
|
4064
|
+
collection.loadAllItems()
|
|
4065
|
+
];
|
|
4066
|
+
case 5:
|
|
4067
|
+
reloaded = _state.sent();
|
|
4068
|
+
expect(reloaded).toHaveLength(2);
|
|
4069
|
+
return [
|
|
4070
|
+
4,
|
|
4071
|
+
collection.loadItemsForPages([
|
|
4072
|
+
'1'
|
|
4073
|
+
])
|
|
4074
|
+
];
|
|
4075
|
+
case 6:
|
|
4076
|
+
removedPage = _state.sent();
|
|
4077
|
+
expect(removedPage).toEqual([]);
|
|
4078
|
+
return [
|
|
4079
|
+
2
|
|
4080
|
+
];
|
|
4081
|
+
}
|
|
4082
|
+
});
|
|
4083
|
+
})();
|
|
4084
|
+
});
|
|
4085
|
+
it('replaces previously written items on rewrite (no merge)', function() {
|
|
4086
|
+
return _async_to_generator$4(function() {
|
|
4087
|
+
var firstItems, replacementItems, reloaded;
|
|
4088
|
+
return _ts_generator$4(this, function(_state) {
|
|
4089
|
+
switch(_state.label){
|
|
4090
|
+
case 0:
|
|
4091
|
+
firstItems = [
|
|
4092
|
+
{
|
|
4093
|
+
id: 'A',
|
|
4094
|
+
group: 'a',
|
|
4095
|
+
value: 1
|
|
4096
|
+
},
|
|
4097
|
+
{
|
|
4098
|
+
id: 'B',
|
|
4099
|
+
group: 'a',
|
|
4100
|
+
value: 2
|
|
4101
|
+
}
|
|
4102
|
+
];
|
|
4103
|
+
return [
|
|
4104
|
+
4,
|
|
4105
|
+
collection.writeAllItems(firstItems)
|
|
4106
|
+
];
|
|
4107
|
+
case 1:
|
|
4108
|
+
_state.sent();
|
|
4109
|
+
replacementItems = [
|
|
4110
|
+
{
|
|
4111
|
+
id: 'C',
|
|
4112
|
+
group: 'a',
|
|
4113
|
+
value: 3
|
|
4114
|
+
},
|
|
4115
|
+
{
|
|
4116
|
+
id: 'D',
|
|
4117
|
+
group: 'a',
|
|
4118
|
+
value: 4
|
|
4119
|
+
}
|
|
4120
|
+
];
|
|
4121
|
+
return [
|
|
4122
|
+
4,
|
|
4123
|
+
collection.writeAllItems(replacementItems)
|
|
4124
|
+
];
|
|
4125
|
+
case 2:
|
|
4126
|
+
_state.sent();
|
|
4127
|
+
return [
|
|
4128
|
+
4,
|
|
4129
|
+
collection.loadAllItems()
|
|
4130
|
+
];
|
|
4131
|
+
case 3:
|
|
4132
|
+
reloaded = _state.sent();
|
|
4133
|
+
expect(reloaded.map(function(x) {
|
|
4134
|
+
return x.id;
|
|
4135
|
+
}).sort()).toEqual([
|
|
4136
|
+
'C',
|
|
4137
|
+
'D'
|
|
4138
|
+
]);
|
|
4139
|
+
return [
|
|
4140
|
+
2
|
|
4141
|
+
];
|
|
4142
|
+
}
|
|
4143
|
+
});
|
|
4144
|
+
})();
|
|
4145
|
+
});
|
|
4146
|
+
});
|
|
4147
|
+
describe('writeAllItems() with custom maxItemsPerPage', function() {
|
|
4148
|
+
it('writes one page per item when maxItemsPerPage is 1', function() {
|
|
4149
|
+
return _async_to_generator$4(function() {
|
|
4150
|
+
var collection, items, index, reloaded;
|
|
4151
|
+
return _ts_generator$4(this, function(_state) {
|
|
4152
|
+
switch(_state.label){
|
|
4153
|
+
case 0:
|
|
4154
|
+
collection = f.instance.collections.mockItemPagedCollectionFactoryWithConfig({
|
|
4155
|
+
maxItemsPerPage: 1
|
|
4156
|
+
})(itemDocument);
|
|
4157
|
+
items = Array.from({
|
|
4158
|
+
length: 10
|
|
4159
|
+
}, function(_, i) {
|
|
4160
|
+
return {
|
|
4161
|
+
id: "".concat(i),
|
|
4162
|
+
group: 'a',
|
|
4163
|
+
value: i
|
|
4164
|
+
};
|
|
4165
|
+
});
|
|
4166
|
+
return [
|
|
4167
|
+
4,
|
|
4168
|
+
collection.writeAllItems(items)
|
|
4169
|
+
];
|
|
4170
|
+
case 1:
|
|
4171
|
+
_state.sent();
|
|
4172
|
+
return [
|
|
4173
|
+
4,
|
|
4174
|
+
collection.loadIndex()
|
|
4175
|
+
];
|
|
4176
|
+
case 2:
|
|
4177
|
+
index = _state.sent();
|
|
4178
|
+
expect(index === null || index === void 0 ? void 0 : index.tc).toBe(items.length);
|
|
4179
|
+
expect(index === null || index === void 0 ? void 0 : index.p).toEqual([
|
|
4180
|
+
'0',
|
|
4181
|
+
'1',
|
|
4182
|
+
'2',
|
|
4183
|
+
'3',
|
|
4184
|
+
'4',
|
|
4185
|
+
'5',
|
|
4186
|
+
'6',
|
|
4187
|
+
'7',
|
|
4188
|
+
'8',
|
|
4189
|
+
'9'
|
|
4190
|
+
]);
|
|
4191
|
+
expect(index === null || index === void 0 ? void 0 : index.pc).toEqual({
|
|
4192
|
+
'0': 1,
|
|
4193
|
+
'1': 1,
|
|
4194
|
+
'2': 1,
|
|
4195
|
+
'3': 1,
|
|
4196
|
+
'4': 1,
|
|
4197
|
+
'5': 1,
|
|
4198
|
+
'6': 1,
|
|
4199
|
+
'7': 1,
|
|
4200
|
+
'8': 1,
|
|
4201
|
+
'9': 1
|
|
4202
|
+
});
|
|
4203
|
+
return [
|
|
4204
|
+
4,
|
|
4205
|
+
collection.loadAllItems()
|
|
4206
|
+
];
|
|
4207
|
+
case 3:
|
|
4208
|
+
reloaded = _state.sent();
|
|
4209
|
+
expect(reloaded).toHaveLength(items.length);
|
|
4210
|
+
expect(reloaded.map(function(x) {
|
|
4211
|
+
return x.id;
|
|
4212
|
+
}).sort()).toEqual(items.map(function(x) {
|
|
4213
|
+
return x.id;
|
|
4214
|
+
}).sort());
|
|
4215
|
+
return [
|
|
4216
|
+
2
|
|
4217
|
+
];
|
|
4218
|
+
}
|
|
4219
|
+
});
|
|
4220
|
+
})();
|
|
4221
|
+
});
|
|
4222
|
+
});
|
|
4223
|
+
describe('writeAllItems() (static distribution)', function() {
|
|
4224
|
+
var collection;
|
|
4225
|
+
beforeEach(function() {
|
|
4226
|
+
collection = f.instance.collections.mockItemPagedStaticCollectionFactory(itemDocument);
|
|
4227
|
+
});
|
|
4228
|
+
it('routes items to scheme-defined page ids', function() {
|
|
4229
|
+
return _async_to_generator$4(function() {
|
|
4230
|
+
var items, index;
|
|
4231
|
+
return _ts_generator$4(this, function(_state) {
|
|
4232
|
+
switch(_state.label){
|
|
4233
|
+
case 0:
|
|
4234
|
+
items = [
|
|
4235
|
+
{
|
|
4236
|
+
id: '1',
|
|
4237
|
+
group: 'a',
|
|
4238
|
+
value: 1
|
|
4239
|
+
},
|
|
4240
|
+
{
|
|
4241
|
+
id: '2',
|
|
4242
|
+
group: 'b',
|
|
4243
|
+
value: 2
|
|
4244
|
+
},
|
|
4245
|
+
{
|
|
4246
|
+
id: '3',
|
|
4247
|
+
group: 'b',
|
|
4248
|
+
value: 3
|
|
4249
|
+
},
|
|
4250
|
+
{
|
|
4251
|
+
id: '4',
|
|
4252
|
+
group: 'c',
|
|
4253
|
+
value: 4
|
|
4254
|
+
}
|
|
4255
|
+
];
|
|
4256
|
+
return [
|
|
4257
|
+
4,
|
|
4258
|
+
collection.writeAllItems(items)
|
|
4259
|
+
];
|
|
4260
|
+
case 1:
|
|
4261
|
+
_state.sent();
|
|
4262
|
+
return [
|
|
4263
|
+
4,
|
|
4264
|
+
collection.loadIndex()
|
|
4265
|
+
];
|
|
4266
|
+
case 2:
|
|
4267
|
+
index = _state.sent();
|
|
4268
|
+
expect(index === null || index === void 0 ? void 0 : index.tc).toBe(items.length);
|
|
4269
|
+
expect(index === null || index === void 0 ? void 0 : index.p).toEqual([
|
|
4270
|
+
'a',
|
|
4271
|
+
'b',
|
|
4272
|
+
'c'
|
|
4273
|
+
]);
|
|
4274
|
+
expect(index === null || index === void 0 ? void 0 : index.pc).toEqual({
|
|
4275
|
+
a: 1,
|
|
4276
|
+
b: 2,
|
|
4277
|
+
c: 1
|
|
4278
|
+
});
|
|
4279
|
+
return [
|
|
4280
|
+
2
|
|
4281
|
+
];
|
|
4282
|
+
}
|
|
4283
|
+
});
|
|
4284
|
+
})();
|
|
4285
|
+
});
|
|
4286
|
+
it('omits empty scheme pages from the index', function() {
|
|
4287
|
+
return _async_to_generator$4(function() {
|
|
4288
|
+
var items, index;
|
|
4289
|
+
return _ts_generator$4(this, function(_state) {
|
|
4290
|
+
switch(_state.label){
|
|
4291
|
+
case 0:
|
|
4292
|
+
items = [
|
|
4293
|
+
{
|
|
4294
|
+
id: '1',
|
|
4295
|
+
group: 'a',
|
|
4296
|
+
value: 1
|
|
4297
|
+
},
|
|
4298
|
+
{
|
|
4299
|
+
id: '2',
|
|
4300
|
+
group: 'c',
|
|
4301
|
+
value: 2
|
|
4302
|
+
}
|
|
4303
|
+
];
|
|
4304
|
+
return [
|
|
4305
|
+
4,
|
|
4306
|
+
collection.writeAllItems(items)
|
|
4307
|
+
];
|
|
4308
|
+
case 1:
|
|
4309
|
+
_state.sent();
|
|
4310
|
+
return [
|
|
4311
|
+
4,
|
|
4312
|
+
collection.loadIndex()
|
|
4313
|
+
];
|
|
4314
|
+
case 2:
|
|
4315
|
+
index = _state.sent();
|
|
4316
|
+
expect(index === null || index === void 0 ? void 0 : index.p).toEqual([
|
|
4317
|
+
'a',
|
|
4318
|
+
'c'
|
|
4319
|
+
]);
|
|
4320
|
+
expect(index === null || index === void 0 ? void 0 : index.pc).toEqual({
|
|
4321
|
+
a: 1,
|
|
4322
|
+
c: 1
|
|
4323
|
+
});
|
|
4324
|
+
return [
|
|
4325
|
+
2
|
|
4326
|
+
];
|
|
4327
|
+
}
|
|
4328
|
+
});
|
|
4329
|
+
})();
|
|
4330
|
+
});
|
|
4331
|
+
it('loadItemsForPages() returns only the requested static page', function() {
|
|
4332
|
+
return _async_to_generator$4(function() {
|
|
4333
|
+
var _aItems_, items, aItems, bItems;
|
|
4334
|
+
return _ts_generator$4(this, function(_state) {
|
|
4335
|
+
switch(_state.label){
|
|
4336
|
+
case 0:
|
|
4337
|
+
items = [
|
|
4338
|
+
{
|
|
4339
|
+
id: '1',
|
|
4340
|
+
group: 'a',
|
|
4341
|
+
value: 1
|
|
4342
|
+
},
|
|
4343
|
+
{
|
|
4344
|
+
id: '2',
|
|
4345
|
+
group: 'b',
|
|
4346
|
+
value: 2
|
|
4347
|
+
},
|
|
4348
|
+
{
|
|
4349
|
+
id: '3',
|
|
4350
|
+
group: 'b',
|
|
4351
|
+
value: 3
|
|
4352
|
+
},
|
|
4353
|
+
{
|
|
4354
|
+
id: '4',
|
|
4355
|
+
group: 'c',
|
|
4356
|
+
value: 4
|
|
4357
|
+
}
|
|
4358
|
+
];
|
|
4359
|
+
return [
|
|
4360
|
+
4,
|
|
4361
|
+
collection.writeAllItems(items)
|
|
4362
|
+
];
|
|
4363
|
+
case 1:
|
|
4364
|
+
_state.sent();
|
|
4365
|
+
return [
|
|
4366
|
+
4,
|
|
4367
|
+
collection.loadItemsForPages([
|
|
4368
|
+
'a'
|
|
4369
|
+
])
|
|
4370
|
+
];
|
|
4371
|
+
case 2:
|
|
4372
|
+
aItems = _state.sent();
|
|
4373
|
+
expect(aItems).toHaveLength(1);
|
|
4374
|
+
expect((_aItems_ = aItems[0]) === null || _aItems_ === void 0 ? void 0 : _aItems_.id).toBe('1');
|
|
4375
|
+
return [
|
|
4376
|
+
4,
|
|
4377
|
+
collection.loadItemsForPages([
|
|
4378
|
+
'b'
|
|
4379
|
+
])
|
|
4380
|
+
];
|
|
4381
|
+
case 3:
|
|
4382
|
+
bItems = _state.sent();
|
|
4383
|
+
expect(bItems).toHaveLength(2);
|
|
4384
|
+
expect(bItems.map(function(x) {
|
|
4385
|
+
return x.id;
|
|
4386
|
+
}).sort()).toEqual([
|
|
4387
|
+
'2',
|
|
4388
|
+
'3'
|
|
4389
|
+
]);
|
|
4390
|
+
return [
|
|
4391
|
+
2
|
|
4392
|
+
];
|
|
4393
|
+
}
|
|
4394
|
+
});
|
|
4395
|
+
})();
|
|
4396
|
+
});
|
|
4397
|
+
it('loadItemsForPages() returns an empty array for an unwritten scheme page', function() {
|
|
4398
|
+
return _async_to_generator$4(function() {
|
|
4399
|
+
var items, missing;
|
|
4400
|
+
return _ts_generator$4(this, function(_state) {
|
|
4401
|
+
switch(_state.label){
|
|
4402
|
+
case 0:
|
|
4403
|
+
items = [
|
|
4404
|
+
{
|
|
4405
|
+
id: '1',
|
|
4406
|
+
group: 'a',
|
|
4407
|
+
value: 1
|
|
4408
|
+
}
|
|
4409
|
+
];
|
|
4410
|
+
return [
|
|
4411
|
+
4,
|
|
4412
|
+
collection.writeAllItems(items)
|
|
4413
|
+
];
|
|
4414
|
+
case 1:
|
|
4415
|
+
_state.sent();
|
|
4416
|
+
return [
|
|
4417
|
+
4,
|
|
4418
|
+
collection.loadItemsForPages([
|
|
4419
|
+
'b'
|
|
4420
|
+
])
|
|
4421
|
+
];
|
|
4422
|
+
case 2:
|
|
4423
|
+
missing = _state.sent();
|
|
4424
|
+
expect(missing).toEqual([]);
|
|
4425
|
+
return [
|
|
4426
|
+
2
|
|
4427
|
+
];
|
|
4428
|
+
}
|
|
4429
|
+
});
|
|
4430
|
+
})();
|
|
4431
|
+
});
|
|
4432
|
+
itShouldFail('when distribute() returns a page id outside the scheme', function() {
|
|
4433
|
+
return _async_to_generator$4(function() {
|
|
4434
|
+
return _ts_generator$4(this, function(_state) {
|
|
4435
|
+
switch(_state.label){
|
|
4436
|
+
case 0:
|
|
4437
|
+
return [
|
|
4438
|
+
4,
|
|
4439
|
+
expectFail(function() {
|
|
4440
|
+
return collection.writeAllItems([
|
|
4441
|
+
{
|
|
4442
|
+
id: '1',
|
|
4443
|
+
group: 'z',
|
|
4444
|
+
value: 1
|
|
4445
|
+
}
|
|
4446
|
+
]);
|
|
4447
|
+
})
|
|
4448
|
+
];
|
|
4449
|
+
case 1:
|
|
4450
|
+
_state.sent();
|
|
4451
|
+
return [
|
|
4452
|
+
2
|
|
4453
|
+
];
|
|
4454
|
+
}
|
|
4455
|
+
});
|
|
4456
|
+
})();
|
|
4457
|
+
});
|
|
4458
|
+
});
|
|
4459
|
+
describe('writeAllItemsInTransaction()', function() {
|
|
4460
|
+
it('writes pages and updates the index inside a transaction', function() {
|
|
4461
|
+
return _async_to_generator$4(function() {
|
|
4462
|
+
var collection, items, index, reloaded;
|
|
4463
|
+
return _ts_generator$4(this, function(_state) {
|
|
4464
|
+
switch(_state.label){
|
|
4465
|
+
case 0:
|
|
4466
|
+
collection = f.instance.collections.mockItemPagedCollectionFactory(itemDocument);
|
|
4467
|
+
items = Array.from({
|
|
4468
|
+
length: 4
|
|
4469
|
+
}, function(_, i) {
|
|
4470
|
+
return {
|
|
4471
|
+
id: "".concat(i),
|
|
4472
|
+
group: 'a',
|
|
4473
|
+
value: i
|
|
4474
|
+
};
|
|
4475
|
+
});
|
|
4476
|
+
return [
|
|
4477
|
+
4,
|
|
4478
|
+
f.parent.firestoreContext.runTransaction(function(transaction) {
|
|
4479
|
+
return _async_to_generator$4(function() {
|
|
4480
|
+
return _ts_generator$4(this, function(_state) {
|
|
4481
|
+
switch(_state.label){
|
|
4482
|
+
case 0:
|
|
4483
|
+
return [
|
|
4484
|
+
4,
|
|
4485
|
+
collection.writeAllItemsInTransaction(transaction, items)
|
|
4486
|
+
];
|
|
4487
|
+
case 1:
|
|
4488
|
+
_state.sent();
|
|
4489
|
+
return [
|
|
4490
|
+
2
|
|
4491
|
+
];
|
|
4492
|
+
}
|
|
4493
|
+
});
|
|
4494
|
+
})();
|
|
4495
|
+
})
|
|
4496
|
+
];
|
|
4497
|
+
case 1:
|
|
4498
|
+
_state.sent();
|
|
4499
|
+
return [
|
|
4500
|
+
4,
|
|
4501
|
+
collection.loadIndex()
|
|
4502
|
+
];
|
|
4503
|
+
case 2:
|
|
4504
|
+
index = _state.sent();
|
|
4505
|
+
expect(index === null || index === void 0 ? void 0 : index.tc).toBe(items.length);
|
|
4506
|
+
expect(index === null || index === void 0 ? void 0 : index.p).toEqual([
|
|
4507
|
+
'0',
|
|
4508
|
+
'1'
|
|
4509
|
+
]);
|
|
4510
|
+
return [
|
|
4511
|
+
4,
|
|
4512
|
+
collection.loadAllItems()
|
|
4513
|
+
];
|
|
4514
|
+
case 3:
|
|
4515
|
+
reloaded = _state.sent();
|
|
4516
|
+
expect(reloaded).toHaveLength(items.length);
|
|
4517
|
+
return [
|
|
4518
|
+
2
|
|
4519
|
+
];
|
|
4520
|
+
}
|
|
4521
|
+
});
|
|
4522
|
+
})();
|
|
4523
|
+
});
|
|
4524
|
+
it('shrinks and deletes obsolete pages inside a transaction', function() {
|
|
4525
|
+
return _async_to_generator$4(function() {
|
|
4526
|
+
var collection, initialItems, initialIndex, smallerItems, newIndex, removedPage;
|
|
4527
|
+
return _ts_generator$4(this, function(_state) {
|
|
4528
|
+
switch(_state.label){
|
|
4529
|
+
case 0:
|
|
4530
|
+
collection = f.instance.collections.mockItemPagedCollectionFactory(itemDocument);
|
|
4531
|
+
initialItems = Array.from({
|
|
4532
|
+
length: 7
|
|
4533
|
+
}, function(_, i) {
|
|
4534
|
+
return {
|
|
4535
|
+
id: "".concat(i),
|
|
4536
|
+
group: 'a',
|
|
4537
|
+
value: i
|
|
4538
|
+
};
|
|
4539
|
+
});
|
|
4540
|
+
return [
|
|
4541
|
+
4,
|
|
4542
|
+
collection.writeAllItems(initialItems)
|
|
4543
|
+
];
|
|
4544
|
+
case 1:
|
|
4545
|
+
_state.sent();
|
|
4546
|
+
return [
|
|
4547
|
+
4,
|
|
4548
|
+
collection.loadIndex()
|
|
4549
|
+
];
|
|
4550
|
+
case 2:
|
|
4551
|
+
initialIndex = _state.sent();
|
|
4552
|
+
expect(initialIndex === null || initialIndex === void 0 ? void 0 : initialIndex.p).toEqual([
|
|
4553
|
+
'0',
|
|
4554
|
+
'1',
|
|
4555
|
+
'2'
|
|
4556
|
+
]);
|
|
4557
|
+
smallerItems = initialItems.slice(0, 2);
|
|
4558
|
+
return [
|
|
4559
|
+
4,
|
|
4560
|
+
f.parent.firestoreContext.runTransaction(function(transaction) {
|
|
4561
|
+
return _async_to_generator$4(function() {
|
|
4562
|
+
return _ts_generator$4(this, function(_state) {
|
|
4563
|
+
switch(_state.label){
|
|
4564
|
+
case 0:
|
|
4565
|
+
return [
|
|
4566
|
+
4,
|
|
4567
|
+
collection.writeAllItemsInTransaction(transaction, smallerItems)
|
|
4568
|
+
];
|
|
4569
|
+
case 1:
|
|
4570
|
+
_state.sent();
|
|
4571
|
+
return [
|
|
4572
|
+
2
|
|
4573
|
+
];
|
|
4574
|
+
}
|
|
4575
|
+
});
|
|
4576
|
+
})();
|
|
4577
|
+
})
|
|
4578
|
+
];
|
|
4579
|
+
case 3:
|
|
4580
|
+
_state.sent();
|
|
4581
|
+
return [
|
|
4582
|
+
4,
|
|
4583
|
+
collection.loadIndex()
|
|
4584
|
+
];
|
|
4585
|
+
case 4:
|
|
4586
|
+
newIndex = _state.sent();
|
|
4587
|
+
expect(newIndex === null || newIndex === void 0 ? void 0 : newIndex.tc).toBe(2);
|
|
4588
|
+
expect(newIndex === null || newIndex === void 0 ? void 0 : newIndex.p).toEqual([
|
|
4589
|
+
'0'
|
|
4590
|
+
]);
|
|
4591
|
+
return [
|
|
4592
|
+
4,
|
|
4593
|
+
collection.loadItemsForPages([
|
|
4594
|
+
'1'
|
|
4595
|
+
])
|
|
4596
|
+
];
|
|
4597
|
+
case 5:
|
|
4598
|
+
removedPage = _state.sent();
|
|
4599
|
+
expect(removedPage).toEqual([]);
|
|
4600
|
+
return [
|
|
4601
|
+
2
|
|
4602
|
+
];
|
|
4603
|
+
}
|
|
4604
|
+
});
|
|
4605
|
+
})();
|
|
4606
|
+
});
|
|
4607
|
+
});
|
|
4608
|
+
});
|
|
3581
4609
|
});
|
|
3582
4610
|
});
|
|
3583
4611
|
describe('documentAccessor()', function() {
|
|
@@ -12657,4 +13685,4 @@ function _ts_generator(thisArg, body) {
|
|
|
12657
13685
|
});
|
|
12658
13686
|
}
|
|
12659
13687
|
|
|
12660
|
-
export { AUTHORIZED_FIRESTORE_RULES, AUTHORIZED_STORAGE_RULES, MOCK_FIREBASE_MODEL_SERVICE_FACTORIES, MOCK_SYSTEM_STATE_TYPE, MockItemCollectionFixture, MockItemCollectionFixtureInstance, MockItemCollections, MockItemDocument, MockItemPrivateDocument, MockItemSettingsItemEnum, MockItemStorageFixture, MockItemStorageFixtureInstance, MockItemSubItemDeepDocument, MockItemSubItemDocument, MockItemUserDocument, RulesUnitTestFirebaseTestingContextFixture, RulesUnitTestTestFirebaseInstance, TESTING_AUTHORIZED_FIREBASE_USER_ID, TestFirebaseContextFixture, TestFirebaseInstance, TestFirebaseStorageContextFixture, TestFirebaseStorageInstance, TestFirestoreContextFixture, TestFirestoreInstance, allChildMockItemSubItemDeepsWithinMockItem, authorizedFirebaseFactory, authorizedFirestoreOnlyFactory, authorizedTestWithMockItemCollection, authorizedTestWithMockItemStorage, changeFirestoreLogLevelBeforeAndAfterTests, clearTestFirestoreContextCollections, describeFirebaseStorageAccessorDriverTests, describeFirestoreAccessorDriverTests, describeFirestoreDocumentAccessorTests, describeFirestoreDocumentUtilityTests, describeFirestoreIterationTests, describeFirestoreQueryDriverTests, firebaseRulesUnitTestBuilder, makeMockItemCollections, makeRulesTestFirebaseStorageContext, makeRulesTestFirestoreContext, makeTestingFirebaseStorageAccesorDriver, makeTestingFirebaseStorageDrivers, makeTestingFirestoreAccesorDriver, makeTestingFirestoreDrivers, mockFirebaseModelServices, mockItemCollectionReference, mockItemConverter, mockItemFirebaseModelServiceFactory, mockItemFirestoreCollection, mockItemIdentity, mockItemPrivateCollectionReference, mockItemPrivateCollectionReferenceFactory, mockItemPrivateConverter, mockItemPrivateFirebaseModelServiceFactory, mockItemPrivateFirestoreCollection, mockItemPrivateFirestoreCollectionGroup, mockItemPrivateIdentity, mockItemSettingsItemDencoder, mockItemSubItemCollectionReference, mockItemSubItemCollectionReferenceFactory, mockItemSubItemConverter, mockItemSubItemDeepCollectionReference, mockItemSubItemDeepCollectionReferenceFactory, mockItemSubItemDeepConverter, mockItemSubItemDeepFirebaseModelServiceFactory, mockItemSubItemDeepFirestoreCollection, mockItemSubItemDeepFirestoreCollectionGroup, mockItemSubItemDeepIdentity, mockItemSubItemFirebaseModelServiceFactory, mockItemSubItemFirestoreCollection, mockItemSubItemFirestoreCollectionGroup, mockItemSubItemIdentity, mockItemSystemDataConverter, mockItemSystemStateFirebaseModelServiceFactory, mockItemSystemStateStoredDataConverterMap, mockItemUserAccessorFactory, mockItemUserCollectionName, mockItemUserCollectionReference, mockItemUserCollectionReferenceFactory, mockItemUserConverter, mockItemUserFirebaseModelServiceFactory, mockItemUserFirestoreCollection, mockItemUserFirestoreCollectionGroup, mockItemUserIdentifier, mockItemUserIdentity, mockItemWithTestValue, mockItemWithValue, testWithMockItemCollectionFixture, testWithMockItemStorageFixture };
|
|
13688
|
+
export { AUTHORIZED_FIRESTORE_RULES, AUTHORIZED_STORAGE_RULES, MOCK_FIREBASE_MODEL_SERVICE_FACTORIES, MOCK_ITEM_PAGED_DEFAULT_MAX_ITEMS_PER_PAGE, MOCK_SYSTEM_STATE_TYPE, MockItemCollectionFixture, MockItemCollectionFixtureInstance, MockItemCollections, MockItemDocument, MockItemPagedDocument, MockItemPrivateDocument, MockItemSettingsItemEnum, MockItemStorageFixture, MockItemStorageFixtureInstance, MockItemSubItemDeepDocument, MockItemSubItemDocument, MockItemUserDocument, RulesUnitTestFirebaseTestingContextFixture, RulesUnitTestTestFirebaseInstance, TESTING_AUTHORIZED_FIREBASE_USER_ID, TestFirebaseContextFixture, TestFirebaseInstance, TestFirebaseStorageContextFixture, TestFirebaseStorageInstance, TestFirestoreContextFixture, TestFirestoreInstance, allChildMockItemSubItemDeepsWithinMockItem, authorizedFirebaseFactory, authorizedFirestoreOnlyFactory, authorizedTestWithMockItemCollection, authorizedTestWithMockItemStorage, changeFirestoreLogLevelBeforeAndAfterTests, clearTestFirestoreContextCollections, describeFirebaseStorageAccessorDriverTests, describeFirestoreAccessorDriverTests, describeFirestoreDocumentAccessorTests, describeFirestoreDocumentUtilityTests, describeFirestoreIterationTests, describeFirestoreQueryDriverTests, firebaseRulesUnitTestBuilder, makeMockItemCollections, makeRulesTestFirebaseStorageContext, makeRulesTestFirestoreContext, makeTestingFirebaseStorageAccesorDriver, makeTestingFirebaseStorageDrivers, makeTestingFirestoreAccesorDriver, makeTestingFirestoreDrivers, mockFirebaseModelServices, mockItemCollectionReference, mockItemConverter, mockItemFirebaseModelServiceFactory, mockItemFirestoreCollection, mockItemIdentity, mockItemPagedAlphaDistributionScheme, mockItemPagedCollectionReference, mockItemPagedEntryConverter, mockItemPagedFirebaseModelServiceFactory, mockItemPagedFirestoreCollection, mockItemPagedFirestoreCollectionGroup, mockItemPagedIdentity, mockItemPrivateCollectionReference, mockItemPrivateCollectionReferenceFactory, mockItemPrivateConverter, mockItemPrivateFirebaseModelServiceFactory, mockItemPrivateFirestoreCollection, mockItemPrivateFirestoreCollectionGroup, mockItemPrivateIdentity, mockItemSettingsItemDencoder, mockItemSubItemCollectionReference, mockItemSubItemCollectionReferenceFactory, mockItemSubItemConverter, mockItemSubItemDeepCollectionReference, mockItemSubItemDeepCollectionReferenceFactory, mockItemSubItemDeepConverter, mockItemSubItemDeepFirebaseModelServiceFactory, mockItemSubItemDeepFirestoreCollection, mockItemSubItemDeepFirestoreCollectionGroup, mockItemSubItemDeepIdentity, mockItemSubItemFirebaseModelServiceFactory, mockItemSubItemFirestoreCollection, mockItemSubItemFirestoreCollectionGroup, mockItemSubItemIdentity, mockItemSystemDataConverter, mockItemSystemStateFirebaseModelServiceFactory, mockItemSystemStateStoredDataConverterMap, mockItemUserAccessorFactory, mockItemUserCollectionName, mockItemUserCollectionReference, mockItemUserCollectionReferenceFactory, mockItemUserConverter, mockItemUserFirebaseModelServiceFactory, mockItemUserFirestoreCollection, mockItemUserFirestoreCollectionGroup, mockItemUserIdentifier, mockItemUserIdentity, mockItemWithTestValue, mockItemWithValue, testWithMockItemCollectionFixture, testWithMockItemStorageFixture };
|