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