@dereekb/firebase 13.6.6 → 13.6.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.cjs.js +769 -53
- package/index.esm.js +759 -55
- package/package.json +5 -5
- package/src/lib/client/firestore/firestore.d.ts +6 -1
- package/src/lib/common/firestore/accessor/document.d.ts +43 -9
- package/src/lib/common/firestore/cache/cache.d.ts +365 -0
- package/src/lib/common/firestore/cache/cache.memory.d.ts +187 -0
- package/src/lib/common/firestore/cache/index.d.ts +2 -0
- package/src/lib/common/firestore/collection/collection.d.ts +3 -2
- package/src/lib/common/firestore/collection/collection.group.d.ts +2 -1
- package/src/lib/common/firestore/context.d.ts +23 -5
- package/src/lib/common/firestore/index.d.ts +1 -0
- package/test/index.cjs.js +145 -77
- package/test/index.esm.js +144 -79
- package/test/package.json +6 -6
- package/test/src/lib/client/firebase.authorized.d.ts +28 -2
- package/test/src/lib/client/firebase.d.ts +9 -1
- package/test/src/lib/client/firestore.mock.item.fixture.authorized.d.ts +3 -0
package/test/index.esm.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
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
|
-
import { AbstractTestContextFixture, testContextBuilder, instanceWrapTestContextFactory, AbstractWrappedFixtureWithInstance, itShouldFail, expectFail, callbackTest } from '@dereekb/util/test';
|
|
3
2
|
import { initializeTestEnvironment } from '@firebase/rules-unit-testing';
|
|
4
|
-
import {
|
|
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';
|
|
5
4
|
import { setLogLevel } from 'firebase/firestore';
|
|
5
|
+
import { AbstractTestContextFixture, instanceWrapTestContextFactory, AbstractWrappedFixtureWithInstance, itShouldFail, expectFail, callbackTest } from '@dereekb/util/test';
|
|
6
6
|
import { firstValueFrom, filter, skip, from, first, map, switchMap } from 'rxjs';
|
|
7
7
|
import { SubscriptionObject, iteratorNextPageUntilPage, flattenAccumulatorResultItemArray, accumulatorCurrentPageListLoadingState, isLoadingStateFinishedLoading, accumulatorFlattenPageListLoadingState } from '@dereekb/rxjs';
|
|
8
8
|
import { addDays, startOfDay, addHours } from 'date-fns';
|
|
@@ -936,71 +936,113 @@ function _ts_generator$5(thisArg, body) {
|
|
|
936
936
|
* A TestContextBuilderFunction for building firebase test context factories using @firebase/firebase and @firebase/rules-unit-testing. This means CLIENT TESTING ONLY. For server testing, look at @dereekb/firestore-server.
|
|
937
937
|
*
|
|
938
938
|
* This can be used to easily build a testing context that sets up RulesTestEnvironment for tests that sets itself up and tears itself down.
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
939
|
+
*
|
|
940
|
+
* The {@link RulesTestEnvironment} is initialized once per test suite (`beforeAll`) and cleaned up
|
|
941
|
+
* once (`afterAll`), while fresh drivers and a {@link RulesTestContext} are created per test (`beforeEach`). This avoids
|
|
942
|
+
* repeated calls to `initializeTestEnvironment` (which hits the emulator's `PUT /internal/setRules` endpoint),
|
|
943
|
+
* preventing interference between parallel workers sharing the same Firebase Storage emulator. The Storage
|
|
944
|
+
* emulator maintains rules globally (not per-project), so concurrent `setRules` calls from multiple workers
|
|
945
|
+
* can momentarily leave the emulator in a transitional state that causes `storage/unauthorized` errors.
|
|
946
|
+
*/ var firebaseRulesUnitTestBuilder = function firebaseRulesUnitTestBuilder(inputConfig) {
|
|
947
|
+
var _ref;
|
|
948
|
+
var config = {
|
|
949
|
+
testEnvironment: (_ref = inputConfig === null || inputConfig === void 0 ? void 0 : inputConfig.testEnvironment) !== null && _ref !== void 0 ? _ref : {},
|
|
950
|
+
rulesContext: inputConfig === null || inputConfig === void 0 ? void 0 : inputConfig.rulesContext
|
|
951
|
+
};
|
|
952
|
+
return function(buildTests) {
|
|
953
|
+
var fixture = new RulesUnitTestFirebaseTestingContextFixture();
|
|
954
|
+
var rulesTestEnvironment;
|
|
955
|
+
// Initialize the emulator environment once per test suite.
|
|
956
|
+
// This is the expensive operation that hits the emulator's REST API (e.g. PUT /internal/setRules).
|
|
957
|
+
beforeAll(function() {
|
|
958
|
+
return _async_to_generator$5(function() {
|
|
959
|
+
return _ts_generator$5(this, function(_state) {
|
|
960
|
+
switch(_state.label){
|
|
961
|
+
case 0:
|
|
962
|
+
return [
|
|
963
|
+
4,
|
|
964
|
+
initializeTestEnvironment(config.testEnvironment)
|
|
965
|
+
];
|
|
966
|
+
case 1:
|
|
967
|
+
rulesTestEnvironment = _state.sent();
|
|
968
|
+
return [
|
|
969
|
+
2
|
|
970
|
+
];
|
|
971
|
+
}
|
|
972
|
+
});
|
|
973
|
+
})();
|
|
974
|
+
});
|
|
975
|
+
// Clean up the emulator environment once after all tests complete.
|
|
976
|
+
afterAll(function() {
|
|
977
|
+
return _async_to_generator$5(function() {
|
|
978
|
+
return _ts_generator$5(this, function(_state) {
|
|
979
|
+
switch(_state.label){
|
|
980
|
+
case 0:
|
|
981
|
+
if (!rulesTestEnvironment) return [
|
|
982
|
+
3,
|
|
983
|
+
2
|
|
984
|
+
];
|
|
985
|
+
return [
|
|
986
|
+
4,
|
|
987
|
+
rulesTestEnvironment.cleanup().catch(function(e) {
|
|
988
|
+
console.warn('firebaseRulesUnitTestBuilder(): Failed to cleanup rules test environment', e);
|
|
989
|
+
throw e;
|
|
990
|
+
})
|
|
991
|
+
];
|
|
992
|
+
case 1:
|
|
993
|
+
_state.sent();
|
|
994
|
+
_state.label = 2;
|
|
995
|
+
case 2:
|
|
996
|
+
return [
|
|
997
|
+
2
|
|
998
|
+
];
|
|
999
|
+
}
|
|
1000
|
+
});
|
|
1001
|
+
})();
|
|
1002
|
+
});
|
|
1003
|
+
// Create fresh drivers and RulesTestContext per test.
|
|
1004
|
+
// Drivers are recreated per test because the Firestore testing driver fuzzes collection names
|
|
1005
|
+
// (via makeTestingFirestoreAccesorDriver) to provide data isolation between tests.
|
|
1006
|
+
var clearInstance = null;
|
|
1007
|
+
beforeEach(function() {
|
|
1008
|
+
return _async_to_generator$5(function() {
|
|
1009
|
+
var drivers, rulesTestContext, instance;
|
|
1010
|
+
return _ts_generator$5(this, function(_state) {
|
|
1011
|
+
try {
|
|
957
1012
|
drivers = _object_spread$1({}, makeTestingFirestoreDrivers(firebaseFirestoreClientDrivers()), makeTestingFirebaseStorageDrivers(firebaseStorageClientDrivers(), {
|
|
958
1013
|
useTestDefaultBucket: true
|
|
959
1014
|
}));
|
|
960
|
-
testEnvironment = config.testEnvironment;
|
|
961
1015
|
if (config.testEnvironment.collectionNames) {
|
|
962
1016
|
drivers.firestoreAccessorDriver.initWithCollectionNames(config.testEnvironment.collectionNames);
|
|
963
|
-
testEnvironment = _object_spread_props(_object_spread$1({}, testEnvironment), {
|
|
964
|
-
firestore: rewriteEmulatorConfigRulesForFuzzedCollectionNames(testEnvironment.firestore)
|
|
965
|
-
});
|
|
966
1017
|
}
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
_state.sent();
|
|
996
|
-
return [
|
|
997
|
-
2
|
|
998
|
-
];
|
|
999
|
-
}
|
|
1000
|
-
});
|
|
1001
|
-
})();
|
|
1002
|
-
}
|
|
1003
|
-
});
|
|
1018
|
+
rulesTestContext = rulesTestContextForConfig(rulesTestEnvironment, config.rulesContext);
|
|
1019
|
+
instance = new RulesUnitTestTestFirebaseInstance(drivers, rulesTestEnvironment, rulesTestContext);
|
|
1020
|
+
clearInstance = fixture.setInstance(instance);
|
|
1021
|
+
} catch (e) {
|
|
1022
|
+
console.error('firebaseRulesUnitTestBuilder(): Failed building a test instance. Error: ', e);
|
|
1023
|
+
if (clearInstance) {
|
|
1024
|
+
clearInstance();
|
|
1025
|
+
clearInstance = null;
|
|
1026
|
+
}
|
|
1027
|
+
throw e;
|
|
1028
|
+
}
|
|
1029
|
+
return [
|
|
1030
|
+
2
|
|
1031
|
+
];
|
|
1032
|
+
});
|
|
1033
|
+
})();
|
|
1034
|
+
});
|
|
1035
|
+
// Declare tests
|
|
1036
|
+
buildTests(fixture);
|
|
1037
|
+
// Clear the instance reference after each test.
|
|
1038
|
+
afterEach(function() {
|
|
1039
|
+
if (clearInstance) {
|
|
1040
|
+
clearInstance();
|
|
1041
|
+
clearInstance = null;
|
|
1042
|
+
}
|
|
1043
|
+
});
|
|
1044
|
+
};
|
|
1045
|
+
};
|
|
1004
1046
|
// MARK: Internal
|
|
1005
1047
|
function rulesTestContextForConfig(rulesTestEnv, testingRulesConfig) {
|
|
1006
1048
|
var rulesTestContext;
|
|
@@ -1012,18 +1054,6 @@ function rulesTestContextForConfig(rulesTestEnv, testingRulesConfig) {
|
|
|
1012
1054
|
}
|
|
1013
1055
|
return rulesTestContext;
|
|
1014
1056
|
}
|
|
1015
|
-
function rewriteEmulatorConfigRulesForFuzzedCollectionNames(config, fuzzedCollectionNamesMap) {
|
|
1016
|
-
if (config && config.rules) {
|
|
1017
|
-
config = _object_spread_props(_object_spread$1({}, config), {
|
|
1018
|
-
rules: rewriteRulesForFuzzedCollectionNames(config.rules)
|
|
1019
|
-
});
|
|
1020
|
-
}
|
|
1021
|
-
return config;
|
|
1022
|
-
}
|
|
1023
|
-
function rewriteRulesForFuzzedCollectionNames(rules, fuzzedCollectionNamesMap) {
|
|
1024
|
-
// TODO: rewrite the rules using regex matching/replacement.
|
|
1025
|
-
return rules;
|
|
1026
|
-
}
|
|
1027
1057
|
// MARK: Utility
|
|
1028
1058
|
/**
|
|
1029
1059
|
* Registers `beforeAll`/`afterAll` hooks to suppress verbose Firestore log output during tests.
|
|
@@ -1042,24 +1072,56 @@ function rewriteRulesForFuzzedCollectionNames(rules, fuzzedCollectionNamesMap) {
|
|
|
1042
1072
|
/**
|
|
1043
1073
|
* Default user ID used for the authenticated context in client-side Firebase tests.
|
|
1044
1074
|
*/ var TESTING_AUTHORIZED_FIREBASE_USER_ID = '0';
|
|
1075
|
+
/**
|
|
1076
|
+
* Permissive Firestore security rules that allow all reads and writes.
|
|
1077
|
+
*/ var AUTHORIZED_FIRESTORE_RULES = "\nrules_version = '2';\nservice cloud.firestore {\n match /databases/{database}/documents {\n match /{document=**} {\n allow read, write: if true;\n }\n }\n}\n";
|
|
1078
|
+
/**
|
|
1079
|
+
* Permissive Firebase Storage security rules that allow all reads and writes.
|
|
1080
|
+
*/ var AUTHORIZED_STORAGE_RULES = "\nrules_version = '2';\nservice firebase.storage {\n match /b/{bucket}/o {\n match /{allPaths=**} {\n allow read, write: if true;\n }\n }\n}\n";
|
|
1045
1081
|
/**
|
|
1046
1082
|
* Pre-configured {@link FirebaseTestContextFactory} that provides a fully authorized (all reads/writes allowed)
|
|
1047
1083
|
* Firebase emulator context for both Firestore and Storage.
|
|
1048
1084
|
*
|
|
1049
1085
|
* Uses permissive security rules and authenticates as {@link TESTING_AUTHORIZED_FIREBASE_USER_ID}.
|
|
1050
|
-
*
|
|
1086
|
+
*
|
|
1087
|
+
* **Important:** Only use this factory for tests that actually need Firebase Storage access.
|
|
1088
|
+
* Firestore-only tests should use {@link authorizedFirestoreOnlyFactory} instead to avoid
|
|
1089
|
+
* interfering with the storage emulator's global rules endpoint during parallel test execution.
|
|
1051
1090
|
*
|
|
1052
1091
|
* @example
|
|
1053
1092
|
* ```ts
|
|
1054
|
-
* const f =
|
|
1093
|
+
* const f = testWithMockItemStorageFixture()(authorizedFirebaseFactory);
|
|
1055
1094
|
* ```
|
|
1056
1095
|
*/ var authorizedFirebaseFactory = firebaseRulesUnitTestBuilder({
|
|
1057
1096
|
testEnvironment: {
|
|
1058
1097
|
firestore: {
|
|
1059
|
-
rules:
|
|
1098
|
+
rules: AUTHORIZED_FIRESTORE_RULES
|
|
1060
1099
|
},
|
|
1061
1100
|
storage: {
|
|
1062
|
-
rules:
|
|
1101
|
+
rules: AUTHORIZED_STORAGE_RULES
|
|
1102
|
+
}
|
|
1103
|
+
},
|
|
1104
|
+
rulesContext: {
|
|
1105
|
+
userId: TESTING_AUTHORIZED_FIREBASE_USER_ID
|
|
1106
|
+
}
|
|
1107
|
+
});
|
|
1108
|
+
/**
|
|
1109
|
+
* Pre-configured {@link FirebaseTestContextFactory} that provides a fully authorized Firestore-only
|
|
1110
|
+
* emulator context without configuring Storage rules.
|
|
1111
|
+
*
|
|
1112
|
+
* Use this for Firestore-only tests when running with parallel workers. The Firebase Storage
|
|
1113
|
+
* emulator maintains rules globally (not per-project like Firestore), so `initializeTestEnvironment`
|
|
1114
|
+
* calls that include storage rules from non-storage workers will hit `PUT /internal/setRules`
|
|
1115
|
+
* concurrently, which can cause transient `storage/unauthorized` errors in the storage test worker.
|
|
1116
|
+
*
|
|
1117
|
+
* @example
|
|
1118
|
+
* ```ts
|
|
1119
|
+
* const f = testWithMockItemCollectionFixture()(authorizedFirestoreOnlyFactory);
|
|
1120
|
+
* ```
|
|
1121
|
+
*/ var authorizedFirestoreOnlyFactory = firebaseRulesUnitTestBuilder({
|
|
1122
|
+
testEnvironment: {
|
|
1123
|
+
firestore: {
|
|
1124
|
+
rules: AUTHORIZED_FIRESTORE_RULES
|
|
1063
1125
|
}
|
|
1064
1126
|
},
|
|
1065
1127
|
rulesContext: {
|
|
@@ -2133,8 +2195,11 @@ function _is_native_reflect_construct$2() {
|
|
|
2133
2195
|
/**
|
|
2134
2196
|
* Convenience mock instance for collection tests within an authorized firebase context.
|
|
2135
2197
|
*
|
|
2198
|
+
* Uses {@link authorizedFirestoreOnlyFactory} to avoid touching the Storage emulator's
|
|
2199
|
+
* global rules endpoint, preventing interference with parallel storage test workers.
|
|
2200
|
+
*
|
|
2136
2201
|
* Uses @firebase/firestore. This is ONLY for the client.
|
|
2137
|
-
*/ var authorizedTestWithMockItemCollection = testWithMockItemCollectionFixture()(
|
|
2202
|
+
*/ var authorizedTestWithMockItemCollection = testWithMockItemCollectionFixture()(authorizedFirestoreOnlyFactory);
|
|
2138
2203
|
/**
|
|
2139
2204
|
* Convenience mock instance for storage tests within an authorized firebase context.
|
|
2140
2205
|
*
|
|
@@ -12481,4 +12546,4 @@ function _ts_generator(thisArg, body) {
|
|
|
12481
12546
|
});
|
|
12482
12547
|
}
|
|
12483
12548
|
|
|
12484
|
-
export { 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, 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 };
|
|
12549
|
+
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 };
|
package/test/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dereekb/firebase/test",
|
|
3
|
-
"version": "13.6.
|
|
3
|
+
"version": "13.6.7",
|
|
4
4
|
"peerDependencies": {
|
|
5
|
-
"@dereekb/date": "13.6.
|
|
6
|
-
"@dereekb/firebase": "13.6.
|
|
7
|
-
"@dereekb/model": "13.6.
|
|
8
|
-
"@dereekb/rxjs": "13.6.
|
|
9
|
-
"@dereekb/util": "13.6.
|
|
5
|
+
"@dereekb/date": "13.6.7",
|
|
6
|
+
"@dereekb/firebase": "13.6.7",
|
|
7
|
+
"@dereekb/model": "13.6.7",
|
|
8
|
+
"@dereekb/rxjs": "13.6.7",
|
|
9
|
+
"@dereekb/util": "13.6.7",
|
|
10
10
|
"@firebase/rules-unit-testing": "5.0.0",
|
|
11
11
|
"date-fns": "^4.0.0",
|
|
12
12
|
"firebase": "^12.0.0",
|
|
@@ -8,16 +8,42 @@ export declare const TESTING_AUTHORIZED_FIREBASE_USER_ID = "0";
|
|
|
8
8
|
* Convenience type alias for a test context factory that produces {@link RulesUnitTestFirebaseTestingContextFixture} instances.
|
|
9
9
|
*/
|
|
10
10
|
export type FirebaseTestContextFactory = TestContextFactory<RulesUnitTestFirebaseTestingContextFixture>;
|
|
11
|
+
/**
|
|
12
|
+
* Permissive Firestore security rules that allow all reads and writes.
|
|
13
|
+
*/
|
|
14
|
+
export declare const AUTHORIZED_FIRESTORE_RULES = "\nrules_version = '2';\nservice cloud.firestore {\n match /databases/{database}/documents {\n match /{document=**} {\n allow read, write: if true;\n }\n }\n}\n";
|
|
15
|
+
/**
|
|
16
|
+
* Permissive Firebase Storage security rules that allow all reads and writes.
|
|
17
|
+
*/
|
|
18
|
+
export declare const AUTHORIZED_STORAGE_RULES = "\nrules_version = '2';\nservice firebase.storage {\n match /b/{bucket}/o {\n match /{allPaths=**} {\n allow read, write: if true;\n }\n }\n}\n";
|
|
11
19
|
/**
|
|
12
20
|
* Pre-configured {@link FirebaseTestContextFactory} that provides a fully authorized (all reads/writes allowed)
|
|
13
21
|
* Firebase emulator context for both Firestore and Storage.
|
|
14
22
|
*
|
|
15
23
|
* Uses permissive security rules and authenticates as {@link TESTING_AUTHORIZED_FIREBASE_USER_ID}.
|
|
16
|
-
*
|
|
24
|
+
*
|
|
25
|
+
* **Important:** Only use this factory for tests that actually need Firebase Storage access.
|
|
26
|
+
* Firestore-only tests should use {@link authorizedFirestoreOnlyFactory} instead to avoid
|
|
27
|
+
* interfering with the storage emulator's global rules endpoint during parallel test execution.
|
|
17
28
|
*
|
|
18
29
|
* @example
|
|
19
30
|
* ```ts
|
|
20
|
-
* const f =
|
|
31
|
+
* const f = testWithMockItemStorageFixture()(authorizedFirebaseFactory);
|
|
21
32
|
* ```
|
|
22
33
|
*/
|
|
23
34
|
export declare const authorizedFirebaseFactory: FirebaseTestContextFactory;
|
|
35
|
+
/**
|
|
36
|
+
* Pre-configured {@link FirebaseTestContextFactory} that provides a fully authorized Firestore-only
|
|
37
|
+
* emulator context without configuring Storage rules.
|
|
38
|
+
*
|
|
39
|
+
* Use this for Firestore-only tests when running with parallel workers. The Firebase Storage
|
|
40
|
+
* emulator maintains rules globally (not per-project like Firestore), so `initializeTestEnvironment`
|
|
41
|
+
* calls that include storage rules from non-storage workers will hit `PUT /internal/setRules`
|
|
42
|
+
* concurrently, which can cause transient `storage/unauthorized` errors in the storage test worker.
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```ts
|
|
46
|
+
* const f = testWithMockItemCollectionFixture()(authorizedFirestoreOnlyFactory);
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
export declare const authorizedFirestoreOnlyFactory: FirebaseTestContextFactory;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type TestFirestoreContext, type TestingFirestoreDrivers } from '../common/firestore/firestore';
|
|
2
2
|
import { type Maybe } from '@dereekb/util';
|
|
3
|
+
import { type TestContextBuilderFunction } from '@dereekb/util/test';
|
|
3
4
|
import { type TestEnvironmentConfig, type RulesTestEnvironment, type RulesTestContext, type TokenOptions, type EmulatorConfig } from '@firebase/rules-unit-testing';
|
|
4
5
|
import { type FirebaseStorage, type Firestore } from '@dereekb/firebase';
|
|
5
6
|
import { type TestFirebaseStorageContext, type TestingFirebaseStorageDrivers } from '../common/storage/storage';
|
|
@@ -104,8 +105,15 @@ export declare class RulesUnitTestFirebaseTestingContextFixture extends TestFire
|
|
|
104
105
|
* A TestContextBuilderFunction for building firebase test context factories using @firebase/firebase and @firebase/rules-unit-testing. This means CLIENT TESTING ONLY. For server testing, look at @dereekb/firestore-server.
|
|
105
106
|
*
|
|
106
107
|
* This can be used to easily build a testing context that sets up RulesTestEnvironment for tests that sets itself up and tears itself down.
|
|
108
|
+
*
|
|
109
|
+
* The {@link RulesTestEnvironment} is initialized once per test suite (`beforeAll`) and cleaned up
|
|
110
|
+
* once (`afterAll`), while fresh drivers and a {@link RulesTestContext} are created per test (`beforeEach`). This avoids
|
|
111
|
+
* repeated calls to `initializeTestEnvironment` (which hits the emulator's `PUT /internal/setRules` endpoint),
|
|
112
|
+
* preventing interference between parallel workers sharing the same Firebase Storage emulator. The Storage
|
|
113
|
+
* emulator maintains rules globally (not per-project), so concurrent `setRules` calls from multiple workers
|
|
114
|
+
* can momentarily leave the emulator in a transitional state that causes `storage/unauthorized` errors.
|
|
107
115
|
*/
|
|
108
|
-
export declare const firebaseRulesUnitTestBuilder:
|
|
116
|
+
export declare const firebaseRulesUnitTestBuilder: TestContextBuilderFunction<RulesUnitTestTestFirebaseInstance, RulesUnitTestFirebaseTestingContextFixture, RulesUnitTestingConfig>;
|
|
109
117
|
/**
|
|
110
118
|
* Registers `beforeAll`/`afterAll` hooks to suppress verbose Firestore log output during tests.
|
|
111
119
|
*
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Convenience mock instance for collection tests within an authorized firebase context.
|
|
3
3
|
*
|
|
4
|
+
* Uses {@link authorizedFirestoreOnlyFactory} to avoid touching the Storage emulator's
|
|
5
|
+
* global rules endpoint, preventing interference with parallel storage test workers.
|
|
6
|
+
*
|
|
4
7
|
* Uses @firebase/firestore. This is ONLY for the client.
|
|
5
8
|
*/
|
|
6
9
|
export declare const authorizedTestWithMockItemCollection: import("@dereekb/util/test").TestContextFactory<import("..").MockItemCollectionFixture>;
|