@expo/entity 0.35.0 → 0.36.0
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/build/AuthorizationResultBasedEntityLoader.d.ts +128 -0
- package/build/AuthorizationResultBasedEntityLoader.js +196 -0
- package/build/AuthorizationResultBasedEntityLoader.js.map +1 -0
- package/build/ComposedEntityCacheAdapter.js +1 -0
- package/build/ComposedEntityCacheAdapter.js.map +1 -1
- package/build/ComposedSecondaryEntityCache.js +1 -0
- package/build/ComposedSecondaryEntityCache.js.map +1 -1
- package/build/EnforcingEntityLoader.d.ts +5 -4
- package/build/EnforcingEntityLoader.js +4 -2
- package/build/EnforcingEntityLoader.js.map +1 -1
- package/build/Entity.d.ts +0 -27
- package/build/Entity.js +0 -50
- package/build/Entity.js.map +1 -1
- package/build/EntityAssociationLoader.d.ts +1 -1
- package/build/EntityAssociationLoader.js +17 -8
- package/build/EntityAssociationLoader.js.map +1 -1
- package/build/EntityCompanion.js +9 -1
- package/build/EntityCompanion.js.map +1 -1
- package/build/EntityCompanionProvider.d.ts +3 -1
- package/build/EntityCompanionProvider.js +10 -4
- package/build/EntityCompanionProvider.js.map +1 -1
- package/build/EntityConfiguration.d.ts +2 -1
- package/build/EntityConfiguration.js +19 -1
- package/build/EntityConfiguration.js.map +1 -1
- package/build/EntityDatabaseAdapter.d.ts +2 -2
- package/build/EntityDatabaseAdapter.js +5 -3
- package/build/EntityDatabaseAdapter.js.map +1 -1
- package/build/EntityFieldDefinition.d.ts +21 -10
- package/build/EntityFieldDefinition.js +8 -9
- package/build/EntityFieldDefinition.js.map +1 -1
- package/build/EntityFields.d.ts +10 -0
- package/build/EntityFields.js +15 -1
- package/build/EntityFields.js.map +1 -1
- package/build/EntityLoader.d.ts +12 -125
- package/build/EntityLoader.js +24 -239
- package/build/EntityLoader.js.map +1 -1
- package/build/EntityLoaderFactory.d.ts +1 -1
- package/build/EntityLoaderFactory.js +3 -0
- package/build/EntityLoaderFactory.js.map +1 -1
- package/build/EntityLoaderUtils.d.ts +58 -0
- package/build/EntityLoaderUtils.js +109 -0
- package/build/EntityLoaderUtils.js.map +1 -0
- package/build/EntityMutator.d.ts +1 -0
- package/build/EntityMutator.js +71 -56
- package/build/EntityMutator.js.map +1 -1
- package/build/EntityMutatorFactory.js +9 -0
- package/build/EntityMutatorFactory.js.map +1 -1
- package/build/EntityPrivacyPolicy.d.ts +11 -5
- package/build/EntityPrivacyPolicy.js +5 -7
- package/build/EntityPrivacyPolicy.js.map +1 -1
- package/build/EntityQueryContext.d.ts +2 -1
- package/build/EntityQueryContext.js +11 -6
- package/build/EntityQueryContext.js.map +1 -1
- package/build/EntitySecondaryCacheLoader.js +5 -1
- package/build/EntitySecondaryCacheLoader.js.map +1 -1
- package/build/GenericEntityCacheAdapter.js +1 -0
- package/build/GenericEntityCacheAdapter.js.map +1 -1
- package/build/GenericSecondaryEntityCache.js +2 -0
- package/build/GenericSecondaryEntityCache.js.map +1 -1
- package/build/IEntityCacheAdapterProvider.d.ts +1 -1
- package/build/IEntityDatabaseAdapterProvider.d.ts +1 -1
- package/build/ReadonlyEntity.js +5 -1
- package/build/ReadonlyEntity.js.map +1 -1
- package/build/ViewerContext.js +2 -0
- package/build/ViewerContext.js.map +1 -1
- package/build/ViewerScopedEntityCompanion.js +2 -0
- package/build/ViewerScopedEntityCompanion.js.map +1 -1
- package/build/ViewerScopedEntityCompanionProvider.d.ts +0 -1
- package/build/ViewerScopedEntityCompanionProvider.js +2 -1
- package/build/ViewerScopedEntityCompanionProvider.js.map +1 -1
- package/build/ViewerScopedEntityLoaderFactory.d.ts +1 -1
- package/build/ViewerScopedEntityLoaderFactory.js +2 -0
- package/build/ViewerScopedEntityLoaderFactory.js.map +1 -1
- package/build/ViewerScopedEntityMutatorFactory.js +2 -0
- package/build/ViewerScopedEntityMutatorFactory.js.map +1 -1
- package/build/__tests__/ComposedCacheAdapter-test.js +2 -0
- package/build/__tests__/ComposedCacheAdapter-test.js.map +1 -1
- package/build/__tests__/ComposedSecondaryEntityCache-test.js +1 -0
- package/build/__tests__/ComposedSecondaryEntityCache-test.js.map +1 -1
- package/build/__tests__/EnforcingEntityLoader-test.js +101 -113
- package/build/__tests__/EnforcingEntityLoader-test.js.map +1 -1
- package/build/__tests__/Entity-test.js +0 -132
- package/build/__tests__/Entity-test.js.map +1 -1
- package/build/__tests__/EntityAssociationLoader-test.js +6 -2
- package/build/__tests__/EntityAssociationLoader-test.js.map +1 -1
- package/build/__tests__/EntityCommonUseCases-test.js +24 -22
- package/build/__tests__/EntityCommonUseCases-test.js.map +1 -1
- package/build/__tests__/EntityCompanion-test.js +26 -3
- package/build/__tests__/EntityCompanion-test.js.map +1 -1
- package/build/__tests__/EntityConfiguration-test.js +103 -0
- package/build/__tests__/EntityConfiguration-test.js.map +1 -0
- package/build/__tests__/EntityDatabaseAdapter-test.js +6 -0
- package/build/__tests__/EntityDatabaseAdapter-test.js.map +1 -1
- package/build/__tests__/EntityEdges-test.js +61 -20
- package/build/__tests__/EntityEdges-test.js.map +1 -1
- package/build/__tests__/EntityFields-test.js +6 -0
- package/build/__tests__/EntityFields-test.js.map +1 -1
- package/build/__tests__/EntityLoader-constructor-test.js +16 -17
- package/build/__tests__/EntityLoader-constructor-test.js.map +1 -1
- package/build/__tests__/EntityLoader-test.js +74 -22
- package/build/__tests__/EntityLoader-test.js.map +1 -1
- package/build/__tests__/EntityMutator-MutationCacheConsistency-test.js +12 -15
- package/build/__tests__/EntityMutator-MutationCacheConsistency-test.js.map +1 -1
- package/build/__tests__/EntityMutator-test.js +54 -9
- package/build/__tests__/EntityMutator-test.js.map +1 -1
- package/build/__tests__/EntityPrivacyPolicy-test.js +77 -59
- package/build/__tests__/EntityPrivacyPolicy-test.js.map +1 -1
- package/build/__tests__/EntityQueryContext-test.js +9 -0
- package/build/__tests__/EntityQueryContext-test.js.map +1 -1
- package/build/__tests__/EntitySelfReferentialEdges-test.js +42 -25
- package/build/__tests__/EntitySelfReferentialEdges-test.js.map +1 -1
- package/build/__tests__/ViewerScopedEntityLoaderFactory-test.js.map +1 -1
- package/build/__tests__/cases/TwoEntitySameTableDisjointRows-test.js +20 -18
- package/build/__tests__/cases/TwoEntitySameTableDisjointRows-test.js.map +1 -1
- package/build/__tests__/cases/TwoEntitySameTableOverlappingRows-test.js +12 -15
- package/build/__tests__/cases/TwoEntitySameTableOverlappingRows-test.js.map +1 -1
- package/build/entityUtils.d.ts +1 -1
- package/build/entityUtils.js.map +1 -1
- package/build/errors/EntityCacheAdapterError.js +2 -5
- package/build/errors/EntityCacheAdapterError.js.map +1 -1
- package/build/errors/EntityDatabaseAdapterError.js +14 -35
- package/build/errors/EntityDatabaseAdapterError.js.map +1 -1
- package/build/errors/EntityError.js +1 -0
- package/build/errors/EntityError.js.map +1 -1
- package/build/errors/EntityInvalidFieldValueError.js +2 -2
- package/build/errors/EntityInvalidFieldValueError.js.map +1 -1
- package/build/errors/EntityNotAuthorizedError.js +3 -2
- package/build/errors/EntityNotAuthorizedError.js.map +1 -1
- package/build/errors/EntityNotFoundError.js +2 -2
- package/build/errors/EntityNotFoundError.js.map +1 -1
- package/build/index.d.ts +1 -0
- package/build/index.js +1 -0
- package/build/index.js.map +1 -1
- package/build/internal/EntityDataManager.d.ts +1 -1
- package/build/internal/EntityDataManager.js +6 -1
- package/build/internal/EntityDataManager.js.map +1 -1
- package/build/internal/EntityFieldTransformationUtils.d.ts +5 -5
- package/build/internal/EntityFieldTransformationUtils.js +5 -8
- package/build/internal/EntityFieldTransformationUtils.js.map +1 -1
- package/build/internal/EntityTableDataCoordinator.d.ts +1 -1
- package/build/internal/EntityTableDataCoordinator.js +5 -0
- package/build/internal/EntityTableDataCoordinator.js.map +1 -1
- package/build/internal/ReadThroughEntityCache.d.ts +1 -1
- package/build/internal/ReadThroughEntityCache.js +2 -0
- package/build/internal/ReadThroughEntityCache.js.map +1 -1
- package/build/internal/__tests__/EntityFieldTransformationUtils-test.js +6 -2
- package/build/internal/__tests__/EntityFieldTransformationUtils-test.js.map +1 -1
- package/build/internal/__tests__/ReadThroughEntityCache-test.js +33 -0
- package/build/internal/__tests__/ReadThroughEntityCache-test.js.map +1 -1
- package/build/metrics/IEntityMetricsAdapter.d.ts +1 -1
- package/build/rules/AlwaysAllowPrivacyPolicyRule.d.ts +1 -1
- package/build/rules/AlwaysAllowPrivacyPolicyRule.js.map +1 -1
- package/build/rules/AlwaysDenyPrivacyPolicyRule.d.ts +1 -1
- package/build/rules/AlwaysDenyPrivacyPolicyRule.js.map +1 -1
- package/build/rules/AlwaysSkipPrivacyPolicyRule.d.ts +1 -1
- package/build/rules/AlwaysSkipPrivacyPolicyRule.js.map +1 -1
- package/build/rules/PrivacyPolicyRule.d.ts +1 -1
- package/build/rules/PrivacyPolicyRule.js.map +1 -1
- package/build/rules/__tests__/AlwaysAllowPrivacyPolicyRule-test.js.map +1 -1
- package/build/rules/__tests__/AlwaysDenyPrivacyPolicyRule-test.js.map +1 -1
- package/build/rules/__tests__/AlwaysSkipPrivacyPolicyRule-test.js.map +1 -1
- package/build/testfixtures/DateIDTestEntity.js +12 -15
- package/build/testfixtures/DateIDTestEntity.js.map +1 -1
- package/build/testfixtures/SimpleTestEntity.js +12 -15
- package/build/testfixtures/SimpleTestEntity.js.map +1 -1
- package/build/testfixtures/TestEntity.js +12 -15
- package/build/testfixtures/TestEntity.js.map +1 -1
- package/build/testfixtures/TestEntity2.js +12 -15
- package/build/testfixtures/TestEntity2.js.map +1 -1
- package/build/testfixtures/TestEntityNumberKey.js +12 -15
- package/build/testfixtures/TestEntityNumberKey.js.map +1 -1
- package/build/testfixtures/TestEntityWithMutationTriggers.d.ts +36 -0
- package/build/testfixtures/TestEntityWithMutationTriggers.js +82 -0
- package/build/testfixtures/TestEntityWithMutationTriggers.js.map +1 -0
- package/build/utils/EntityPrivacyUtils.d.ts +34 -0
- package/build/utils/EntityPrivacyUtils.js +160 -0
- package/build/utils/EntityPrivacyUtils.js.map +1 -0
- package/build/utils/__tests__/EntityPrivacyUtils-test.d.ts +1 -0
- package/build/utils/__tests__/EntityPrivacyUtils-test.js +395 -0
- package/build/utils/__tests__/EntityPrivacyUtils-test.js.map +1 -0
- package/build/utils/__tests__/mergeEntityMutationTriggerConfigurations-test.d.ts +1 -0
- package/build/utils/__tests__/mergeEntityMutationTriggerConfigurations-test.js +26 -0
- package/build/utils/__tests__/mergeEntityMutationTriggerConfigurations-test.js.map +1 -0
- package/build/utils/collections/maps.js.map +1 -1
- package/build/utils/mergeEntityMutationTriggerConfigurations.d.ts +4 -0
- package/build/utils/mergeEntityMutationTriggerConfigurations.js +28 -0
- package/build/utils/mergeEntityMutationTriggerConfigurations.js.map +1 -0
- package/build/utils/testing/PrivacyPolicyRuleTestUtils.d.ts +1 -1
- package/build/utils/testing/PrivacyPolicyRuleTestUtils.js.map +1 -1
- package/build/utils/testing/StubCacheAdapter.d.ts +3 -3
- package/build/utils/testing/StubCacheAdapter.js +3 -3
- package/build/utils/testing/StubCacheAdapter.js.map +1 -1
- package/build/utils/testing/StubDatabaseAdapter.d.ts +2 -2
- package/build/utils/testing/StubDatabaseAdapter.js +4 -2
- package/build/utils/testing/StubDatabaseAdapter.js.map +1 -1
- package/build/utils/testing/StubDatabaseAdapterProvider.d.ts +1 -1
- package/build/utils/testing/StubDatabaseAdapterProvider.js +1 -3
- package/build/utils/testing/StubDatabaseAdapterProvider.js.map +1 -1
- package/build/utils/testing/__tests__/PrivacyPolicyRuleTestUtils-test.d.ts +1 -0
- package/build/utils/testing/__tests__/PrivacyPolicyRuleTestUtils-test.js +42 -0
- package/build/utils/testing/__tests__/PrivacyPolicyRuleTestUtils-test.js.map +1 -0
- package/build/utils/testing/__tests__/StubDatabaseAdapter-test.js +53 -0
- package/build/utils/testing/__tests__/StubDatabaseAdapter-test.js.map +1 -1
- package/build/utils/testing/describeFieldTestCase.js.map +1 -1
- package/package.json +4 -3
- package/src/AuthorizationResultBasedEntityLoader.ts +297 -0
- package/src/ComposedEntityCacheAdapter.ts +6 -6
- package/src/ComposedSecondaryEntityCache.ts +8 -8
- package/src/EnforcingEntityLoader.ts +20 -19
- package/src/Entity.ts +11 -126
- package/src/EntityAssociationLoader.ts +40 -41
- package/src/EntityCompanion.ts +8 -4
- package/src/EntityCompanionProvider.ts +24 -16
- package/src/EntityConfiguration.ts +18 -7
- package/src/EntityDatabaseAdapter.ts +41 -41
- package/src/EntityFieldDefinition.ts +28 -18
- package/src/EntityFields.ts +15 -0
- package/src/EntityLoader.ts +63 -357
- package/src/EntityLoaderFactory.ts +10 -4
- package/src/EntityLoaderUtils.ts +149 -0
- package/src/EntityMutationInfo.ts +2 -2
- package/src/EntityMutationTriggerConfiguration.ts +5 -5
- package/src/EntityMutationValidator.ts +2 -2
- package/src/EntityMutator.ts +146 -144
- package/src/EntityMutatorFactory.ts +8 -8
- package/src/EntityPrivacyPolicy.ts +78 -28
- package/src/EntityQueryContext.ts +14 -13
- package/src/EntityQueryContextProvider.ts +5 -5
- package/src/EntitySecondaryCacheLoader.ts +13 -11
- package/src/GenericEntityCacheAdapter.ts +10 -10
- package/src/GenericSecondaryEntityCache.ts +6 -6
- package/src/IEntityCacheAdapter.ts +4 -4
- package/src/IEntityCacheAdapterProvider.ts +2 -2
- package/src/IEntityDatabaseAdapterProvider.ts +2 -2
- package/src/ReadonlyEntity.ts +5 -5
- package/src/ViewerContext.ts +5 -5
- package/src/ViewerScopedEntityCompanion.ts +4 -4
- package/src/ViewerScopedEntityCompanionProvider.ts +4 -5
- package/src/ViewerScopedEntityLoaderFactory.ts +10 -4
- package/src/ViewerScopedEntityMutatorFactory.ts +5 -5
- package/src/__tests__/ComposedCacheAdapter-test.ts +12 -10
- package/src/__tests__/ComposedSecondaryEntityCache-test.ts +8 -8
- package/src/__tests__/EnforcingEntityLoader-test.ts +236 -159
- package/src/__tests__/Entity-test.ts +0 -202
- package/src/__tests__/EntityAssociationLoader-test.ts +29 -25
- package/src/__tests__/EntityCommonUseCases-test.ts +29 -13
- package/src/__tests__/EntityCompanion-test.ts +57 -5
- package/src/__tests__/EntityConfiguration-test.ts +118 -0
- package/src/__tests__/EntityDatabaseAdapter-test.ts +11 -11
- package/src/__tests__/EntityEdges-test.ts +108 -36
- package/src/__tests__/EntityFields-test.ts +14 -2
- package/src/__tests__/EntityLoader-constructor-test.ts +20 -7
- package/src/__tests__/EntityLoader-test.ts +214 -86
- package/src/__tests__/EntityMutator-MutationCacheConsistency-test.ts +2 -2
- package/src/__tests__/EntityMutator-test.ts +281 -96
- package/src/__tests__/EntityPrivacyPolicy-test.ts +166 -53
- package/src/__tests__/EntityQueryContext-test.ts +30 -12
- package/src/__tests__/EntitySecondaryCacheLoader-test.ts +7 -7
- package/src/__tests__/EntitySelfReferentialEdges-test.ts +46 -26
- package/src/__tests__/GenericEntityCacheAdapter-test.ts +2 -2
- package/src/__tests__/ViewerContext-test.ts +1 -1
- package/src/__tests__/ViewerScopedEntityCompanion-test.ts +2 -2
- package/src/__tests__/ViewerScopedEntityCompanionProvider-test.ts +2 -2
- package/src/__tests__/ViewerScopedEntityLoaderFactory-test.ts +2 -1
- package/src/__tests__/cases/TwoEntitySameTableDisjointRows-test.ts +19 -19
- package/src/__tests__/entityUtils-test.ts +2 -2
- package/src/entityUtils.ts +4 -4
- package/src/errors/EntityError.ts +4 -1
- package/src/errors/EntityInvalidFieldValueError.ts +2 -2
- package/src/errors/EntityNotAuthorizedError.ts +3 -3
- package/src/errors/EntityNotFoundError.ts +2 -2
- package/src/index.ts +1 -0
- package/src/internal/EntityDataManager.ts +24 -24
- package/src/internal/EntityFieldTransformationUtils.ts +39 -32
- package/src/internal/EntityTableDataCoordinator.ts +3 -3
- package/src/internal/ReadThroughEntityCache.ts +9 -9
- package/src/internal/__tests__/EntityDataManager-test.ts +51 -51
- package/src/internal/__tests__/EntityFieldTransformationUtils-test.ts +14 -10
- package/src/internal/__tests__/ReadThroughEntityCache-test.ts +74 -18
- package/src/metrics/EntityMetricsUtils.ts +4 -4
- package/src/metrics/IEntityMetricsAdapter.ts +1 -1
- package/src/rules/AlwaysAllowPrivacyPolicyRule.ts +9 -3
- package/src/rules/AlwaysDenyPrivacyPolicyRule.ts +9 -3
- package/src/rules/AlwaysSkipPrivacyPolicyRule.ts +9 -3
- package/src/rules/PrivacyPolicyRule.ts +9 -3
- package/src/rules/__tests__/AlwaysAllowPrivacyPolicyRule-test.ts +2 -1
- package/src/rules/__tests__/AlwaysDenyPrivacyPolicyRule-test.ts +2 -1
- package/src/rules/__tests__/AlwaysSkipPrivacyPolicyRule-test.ts +2 -1
- package/src/testfixtures/TestEntity.ts +1 -1
- package/src/testfixtures/TestEntityWithMutationTriggers.ts +156 -0
- package/src/utils/EntityPrivacyUtils.ts +325 -0
- package/src/utils/__tests__/EntityPrivacyUtils-test.ts +570 -0
- package/src/utils/__tests__/mergeEntityMutationTriggerConfigurations-test.ts +29 -0
- package/src/utils/collections/__tests__/maps-test.ts +2 -2
- package/src/utils/collections/maps.ts +11 -11
- package/src/utils/mergeEntityMutationTriggerConfigurations.ts +44 -0
- package/src/utils/testing/PrivacyPolicyRuleTestUtils.ts +25 -22
- package/src/utils/testing/StubCacheAdapter.ts +17 -15
- package/src/utils/testing/StubDatabaseAdapter.ts +35 -30
- package/src/utils/testing/StubDatabaseAdapterProvider.ts +2 -2
- package/src/utils/testing/StubQueryContextProvider.ts +2 -2
- package/src/utils/testing/__tests__/PrivacyPolicyRuleTestUtils-test.ts +42 -0
- package/src/utils/testing/__tests__/StubDatabaseAdapter-test.ts +111 -29
- package/src/utils/testing/createUnitTestEntityCompanionProvider.ts +2 -2
- package/src/utils/testing/describeFieldTestCase.ts +1 -1
- package/build/__tests__/EntityDataConfiguration-test.js +0 -68
- package/build/__tests__/EntityDataConfiguration-test.js.map +0 -1
- package/src/__tests__/EntityDataConfiguration-test.ts +0 -77
- /package/build/__tests__/{EntityDataConfiguration-test.d.ts → EntityConfiguration-test.d.ts} +0 -0
|
@@ -17,6 +17,7 @@ import EntityConfiguration from '../EntityConfiguration';
|
|
|
17
17
|
import EntityDatabaseAdapter from '../EntityDatabaseAdapter';
|
|
18
18
|
import EntityLoader from '../EntityLoader';
|
|
19
19
|
import EntityLoaderFactory from '../EntityLoaderFactory';
|
|
20
|
+
import EntityLoaderUtils from '../EntityLoaderUtils';
|
|
20
21
|
import {
|
|
21
22
|
EntityMutationType,
|
|
22
23
|
EntityTriggerMutationInfo,
|
|
@@ -68,7 +69,7 @@ class TestMutationTrigger extends EntityMutationTrigger<
|
|
|
68
69
|
ViewerContext,
|
|
69
70
|
TestEntity,
|
|
70
71
|
keyof TestFields
|
|
71
|
-
|
|
72
|
+
>,
|
|
72
73
|
): Promise<void> {}
|
|
73
74
|
}
|
|
74
75
|
|
|
@@ -89,7 +90,7 @@ const setUpMutationValidatorSpies = (
|
|
|
89
90
|
ViewerContext,
|
|
90
91
|
TestEntity,
|
|
91
92
|
keyof TestFields
|
|
92
|
-
>[]
|
|
93
|
+
>[],
|
|
93
94
|
): EntityMutationValidator<TestFields, string, ViewerContext, TestEntity, keyof TestFields>[] => {
|
|
94
95
|
return mutationValidators.map((validator) => spy(validator));
|
|
95
96
|
};
|
|
@@ -110,7 +111,7 @@ const verifyValidatorCounts = (
|
|
|
110
111
|
ViewerContext,
|
|
111
112
|
TestEntity,
|
|
112
113
|
keyof TestFields
|
|
113
|
-
|
|
114
|
+
>,
|
|
114
115
|
): void => {
|
|
115
116
|
for (const validator of mutationValidatorSpies) {
|
|
116
117
|
verify(
|
|
@@ -118,8 +119,8 @@ const verifyValidatorCounts = (
|
|
|
118
119
|
viewerContext,
|
|
119
120
|
anyOfClass(EntityTransactionalQueryContext),
|
|
120
121
|
anyOfClass(TestEntity),
|
|
121
|
-
deepEqual(mutationInfo)
|
|
122
|
-
)
|
|
122
|
+
deepEqual(mutationInfo),
|
|
123
|
+
),
|
|
123
124
|
).times(expectedCalls);
|
|
124
125
|
}
|
|
125
126
|
};
|
|
@@ -131,7 +132,7 @@ const setUpMutationTriggerSpies = (
|
|
|
131
132
|
ViewerContext,
|
|
132
133
|
TestEntity,
|
|
133
134
|
keyof TestFields
|
|
134
|
-
|
|
135
|
+
>,
|
|
135
136
|
): EntityMutationTriggerConfiguration<
|
|
136
137
|
TestFields,
|
|
137
138
|
string,
|
|
@@ -185,7 +186,7 @@ const verifyTriggerCounts = (
|
|
|
185
186
|
ViewerContext,
|
|
186
187
|
TestEntity,
|
|
187
188
|
keyof TestFields
|
|
188
|
-
|
|
189
|
+
>,
|
|
189
190
|
): void => {
|
|
190
191
|
Object.keys(executed).forEach((s) => {
|
|
191
192
|
if ((executed as any)[s]) {
|
|
@@ -194,8 +195,8 @@ const verifyTriggerCounts = (
|
|
|
194
195
|
viewerContext,
|
|
195
196
|
anyOfClass(EntityTransactionalQueryContext),
|
|
196
197
|
anyOfClass(TestEntity),
|
|
197
|
-
deepEqual(mutationInfo)
|
|
198
|
-
)
|
|
198
|
+
deepEqual(mutationInfo),
|
|
199
|
+
),
|
|
199
200
|
).once();
|
|
200
201
|
} else {
|
|
201
202
|
verify(
|
|
@@ -203,8 +204,8 @@ const verifyTriggerCounts = (
|
|
|
203
204
|
viewerContext,
|
|
204
205
|
anyOfClass(EntityTransactionalQueryContext),
|
|
205
206
|
anyOfClass(TestEntity),
|
|
206
|
-
deepEqual(mutationInfo)
|
|
207
|
-
)
|
|
207
|
+
deepEqual(mutationInfo),
|
|
208
|
+
),
|
|
208
209
|
).never();
|
|
209
210
|
}
|
|
210
211
|
});
|
|
@@ -214,8 +215,8 @@ const verifyTriggerCounts = (
|
|
|
214
215
|
viewerContext,
|
|
215
216
|
anyOfClass(EntityTransactionalQueryContext),
|
|
216
217
|
anyOfClass(TestEntity),
|
|
217
|
-
deepEqual(mutationInfo)
|
|
218
|
-
)
|
|
218
|
+
deepEqual(mutationInfo),
|
|
219
|
+
),
|
|
219
220
|
).once();
|
|
220
221
|
|
|
221
222
|
verify(
|
|
@@ -223,21 +224,21 @@ const verifyTriggerCounts = (
|
|
|
223
224
|
viewerContext,
|
|
224
225
|
anyOfClass(EntityTransactionalQueryContext),
|
|
225
226
|
anyOfClass(TestEntity),
|
|
226
|
-
deepEqual(mutationInfo)
|
|
227
|
-
)
|
|
227
|
+
deepEqual(mutationInfo),
|
|
228
|
+
),
|
|
228
229
|
).once();
|
|
229
230
|
|
|
230
231
|
verify(
|
|
231
232
|
mutationTriggerSpies.afterCommit![0]!.executeAsync(
|
|
232
233
|
viewerContext,
|
|
233
234
|
anyOfClass(TestEntity),
|
|
234
|
-
deepEqual(mutationInfo)
|
|
235
|
-
)
|
|
235
|
+
deepEqual(mutationInfo),
|
|
236
|
+
),
|
|
236
237
|
).once();
|
|
237
238
|
};
|
|
238
239
|
|
|
239
240
|
const createEntityMutatorFactory = (
|
|
240
|
-
existingObjects: TestFields[]
|
|
241
|
+
existingObjects: TestFields[],
|
|
241
242
|
): {
|
|
242
243
|
privacyPolicy: TestEntityPrivacyPolicy;
|
|
243
244
|
entityLoaderFactory: EntityLoaderFactory<
|
|
@@ -295,17 +296,16 @@ const createEntityMutatorFactory = (
|
|
|
295
296
|
afterAll: [new TestMutationTrigger()],
|
|
296
297
|
afterCommit: [new TestNonTransactionalMutationTrigger()],
|
|
297
298
|
};
|
|
298
|
-
const privacyPolicy = new TestEntityPrivacyPolicy();
|
|
299
299
|
const databaseAdapter = new StubDatabaseAdapter<TestFields>(
|
|
300
300
|
testEntityConfiguration,
|
|
301
301
|
StubDatabaseAdapter.convertFieldObjectsToDataStore(
|
|
302
302
|
testEntityConfiguration,
|
|
303
|
-
new Map([[testEntityConfiguration.tableName, existingObjects]])
|
|
304
|
-
)
|
|
303
|
+
new Map([[testEntityConfiguration.tableName, existingObjects]]),
|
|
304
|
+
),
|
|
305
305
|
);
|
|
306
306
|
const customStubDatabaseAdapterProvider: IEntityDatabaseAdapterProvider = {
|
|
307
|
-
getDatabaseAdapter<TFields
|
|
308
|
-
_entityConfiguration: EntityConfiguration<TFields
|
|
307
|
+
getDatabaseAdapter<TFields extends Record<string, any>>(
|
|
308
|
+
_entityConfiguration: EntityConfiguration<TFields>,
|
|
309
309
|
): EntityDatabaseAdapter<TFields> {
|
|
310
310
|
return databaseAdapter as any as EntityDatabaseAdapter<TFields>;
|
|
311
311
|
},
|
|
@@ -333,7 +333,7 @@ const createEntityMutatorFactory = (
|
|
|
333
333
|
cacheAdapterProvider,
|
|
334
334
|
},
|
|
335
335
|
],
|
|
336
|
-
])
|
|
336
|
+
]),
|
|
337
337
|
);
|
|
338
338
|
|
|
339
339
|
const dataManager = new EntityDataManager(
|
|
@@ -341,26 +341,26 @@ const createEntityMutatorFactory = (
|
|
|
341
341
|
entityCache,
|
|
342
342
|
StubQueryContextProvider,
|
|
343
343
|
metricsAdapter,
|
|
344
|
-
TestEntity.name
|
|
344
|
+
TestEntity.name,
|
|
345
345
|
);
|
|
346
346
|
const entityLoaderFactory = new EntityLoaderFactory(
|
|
347
347
|
companionProvider.getCompanionForEntity(TestEntity),
|
|
348
348
|
dataManager,
|
|
349
|
-
metricsAdapter
|
|
349
|
+
metricsAdapter,
|
|
350
350
|
);
|
|
351
351
|
const entityMutatorFactory = new EntityMutatorFactory(
|
|
352
352
|
companionProvider,
|
|
353
353
|
testEntityConfiguration,
|
|
354
354
|
TestEntity,
|
|
355
|
-
privacyPolicy,
|
|
355
|
+
companionProvider.getCompanionForEntity(TestEntity).privacyPolicy,
|
|
356
356
|
mutationValidators,
|
|
357
357
|
mutationTriggers,
|
|
358
358
|
entityLoaderFactory,
|
|
359
359
|
databaseAdapter,
|
|
360
|
-
metricsAdapter
|
|
360
|
+
metricsAdapter,
|
|
361
361
|
);
|
|
362
362
|
return {
|
|
363
|
-
privacyPolicy,
|
|
363
|
+
privacyPolicy: companionProvider.getCompanionForEntity(TestEntity).privacyPolicy,
|
|
364
364
|
entityLoaderFactory,
|
|
365
365
|
entityMutatorFactory,
|
|
366
366
|
metricsAdapter,
|
|
@@ -438,10 +438,10 @@ describe(EntityMutatorFactory, () => {
|
|
|
438
438
|
spiedPrivacyPolicy.authorizeCreateAsync(
|
|
439
439
|
viewerContext,
|
|
440
440
|
anyOfClass(EntityTransactionalQueryContext),
|
|
441
|
-
deepEqual({ cascadingDeleteCause: null }),
|
|
441
|
+
deepEqual({ previousValue: null, cascadingDeleteCause: null }),
|
|
442
442
|
anyOfClass(TestEntity),
|
|
443
|
-
anything()
|
|
444
|
-
)
|
|
443
|
+
anything(),
|
|
444
|
+
),
|
|
445
445
|
).once();
|
|
446
446
|
});
|
|
447
447
|
|
|
@@ -488,7 +488,7 @@ describe(EntityMutatorFactory, () => {
|
|
|
488
488
|
beforeDelete: false,
|
|
489
489
|
afterDelete: false,
|
|
490
490
|
},
|
|
491
|
-
{ type: EntityMutationType.CREATE }
|
|
491
|
+
{ type: EntityMutationType.CREATE },
|
|
492
492
|
);
|
|
493
493
|
});
|
|
494
494
|
|
|
@@ -531,7 +531,18 @@ describe(EntityMutatorFactory, () => {
|
|
|
531
531
|
describe('forUpdate', () => {
|
|
532
532
|
it('updates entities', async () => {
|
|
533
533
|
const viewerContext = mock<ViewerContext>();
|
|
534
|
-
const privacyPolicyEvaluationContext =
|
|
534
|
+
const privacyPolicyEvaluationContext =
|
|
535
|
+
instance(
|
|
536
|
+
mock<
|
|
537
|
+
EntityPrivacyPolicyEvaluationContext<
|
|
538
|
+
TestFields,
|
|
539
|
+
string,
|
|
540
|
+
ViewerContext,
|
|
541
|
+
TestEntity,
|
|
542
|
+
keyof TestFields
|
|
543
|
+
>
|
|
544
|
+
>(),
|
|
545
|
+
);
|
|
535
546
|
const queryContext = StubQueryContextProvider.getQueryContext();
|
|
536
547
|
|
|
537
548
|
const id1 = uuidv4();
|
|
@@ -558,7 +569,8 @@ describe(EntityMutatorFactory, () => {
|
|
|
558
569
|
const existingEntity = await enforceAsyncResult(
|
|
559
570
|
entityLoaderFactory
|
|
560
571
|
.forLoad(viewerContext, queryContext, privacyPolicyEvaluationContext)
|
|
561
|
-
.
|
|
572
|
+
.withAuthorizationResults()
|
|
573
|
+
.loadByIDAsync(id2),
|
|
562
574
|
);
|
|
563
575
|
|
|
564
576
|
const updatedEntity = await entityMutatorFactory
|
|
@@ -573,14 +585,14 @@ describe(EntityMutatorFactory, () => {
|
|
|
573
585
|
const reloadedEntity = await enforceAsyncResult(
|
|
574
586
|
entityLoaderFactory
|
|
575
587
|
.forLoad(viewerContext, queryContext, privacyPolicyEvaluationContext)
|
|
576
|
-
.
|
|
588
|
+
.withAuthorizationResults()
|
|
589
|
+
.loadByIDAsync(id2),
|
|
577
590
|
);
|
|
578
591
|
expect(reloadedEntity.getAllFields()).toMatchObject(updatedEntity.getAllFields());
|
|
579
592
|
});
|
|
580
593
|
|
|
581
594
|
it('checks privacy', async () => {
|
|
582
595
|
const viewerContext = mock<ViewerContext>();
|
|
583
|
-
const privacyPolicyEvaluationContext = instance(mock<EntityPrivacyPolicyEvaluationContext>());
|
|
584
596
|
const queryContext = StubQueryContextProvider.getQueryContext();
|
|
585
597
|
|
|
586
598
|
const id1 = uuidv4();
|
|
@@ -609,8 +621,9 @@ describe(EntityMutatorFactory, () => {
|
|
|
609
621
|
|
|
610
622
|
const existingEntity = await enforceAsyncResult(
|
|
611
623
|
entityLoaderFactory
|
|
612
|
-
.forLoad(viewerContext, queryContext,
|
|
613
|
-
.
|
|
624
|
+
.forLoad(viewerContext, queryContext, { previousValue: null, cascadingDeleteCause: null })
|
|
625
|
+
.withAuthorizationResults()
|
|
626
|
+
.loadByIDAsync(id2),
|
|
614
627
|
);
|
|
615
628
|
|
|
616
629
|
await entityMutatorFactory
|
|
@@ -622,16 +635,37 @@ describe(EntityMutatorFactory, () => {
|
|
|
622
635
|
spiedPrivacyPolicy.authorizeUpdateAsync(
|
|
623
636
|
viewerContext,
|
|
624
637
|
anyOfClass(EntityTransactionalQueryContext),
|
|
625
|
-
deepEqual({ cascadingDeleteCause: null }),
|
|
638
|
+
deepEqual({ previousValue: existingEntity, cascadingDeleteCause: null }),
|
|
626
639
|
anyOfClass(TestEntity),
|
|
627
|
-
anything()
|
|
628
|
-
)
|
|
640
|
+
anything(),
|
|
641
|
+
),
|
|
642
|
+
).once();
|
|
643
|
+
|
|
644
|
+
verify(
|
|
645
|
+
spiedPrivacyPolicy.authorizeReadAsync(
|
|
646
|
+
viewerContext,
|
|
647
|
+
anyOfClass(EntityTransactionalQueryContext),
|
|
648
|
+
deepEqual({ previousValue: existingEntity, cascadingDeleteCause: null }),
|
|
649
|
+
anyOfClass(TestEntity),
|
|
650
|
+
anything(),
|
|
651
|
+
),
|
|
629
652
|
).once();
|
|
630
653
|
});
|
|
631
654
|
|
|
632
655
|
it('executes triggers', async () => {
|
|
633
656
|
const viewerContext = mock<ViewerContext>();
|
|
634
|
-
const privacyPolicyEvaluationContext =
|
|
657
|
+
const privacyPolicyEvaluationContext =
|
|
658
|
+
instance(
|
|
659
|
+
mock<
|
|
660
|
+
EntityPrivacyPolicyEvaluationContext<
|
|
661
|
+
TestFields,
|
|
662
|
+
string,
|
|
663
|
+
ViewerContext,
|
|
664
|
+
TestEntity,
|
|
665
|
+
keyof TestFields
|
|
666
|
+
>
|
|
667
|
+
>(),
|
|
668
|
+
);
|
|
635
669
|
const queryContext = StubQueryContextProvider.getQueryContext();
|
|
636
670
|
|
|
637
671
|
const id1 = uuidv4();
|
|
@@ -661,7 +695,8 @@ describe(EntityMutatorFactory, () => {
|
|
|
661
695
|
const existingEntity = await enforceAsyncResult(
|
|
662
696
|
entityLoaderFactory
|
|
663
697
|
.forLoad(viewerContext, queryContext, privacyPolicyEvaluationContext)
|
|
664
|
-
.
|
|
698
|
+
.withAuthorizationResults()
|
|
699
|
+
.loadByIDAsync(id2),
|
|
665
700
|
);
|
|
666
701
|
|
|
667
702
|
await entityMutatorFactory
|
|
@@ -684,12 +719,24 @@ describe(EntityMutatorFactory, () => {
|
|
|
684
719
|
type: EntityMutationType.UPDATE,
|
|
685
720
|
previousValue: existingEntity,
|
|
686
721
|
cascadingDeleteCause: null,
|
|
687
|
-
}
|
|
722
|
+
},
|
|
688
723
|
);
|
|
689
724
|
});
|
|
725
|
+
|
|
690
726
|
it('executes validators', async () => {
|
|
691
727
|
const viewerContext = mock<ViewerContext>();
|
|
692
|
-
const privacyPolicyEvaluationContext =
|
|
728
|
+
const privacyPolicyEvaluationContext =
|
|
729
|
+
instance(
|
|
730
|
+
mock<
|
|
731
|
+
EntityPrivacyPolicyEvaluationContext<
|
|
732
|
+
TestFields,
|
|
733
|
+
string,
|
|
734
|
+
ViewerContext,
|
|
735
|
+
TestEntity,
|
|
736
|
+
keyof TestFields
|
|
737
|
+
>
|
|
738
|
+
>(),
|
|
739
|
+
);
|
|
693
740
|
const queryContext = StubQueryContextProvider.getQueryContext();
|
|
694
741
|
|
|
695
742
|
const id1 = uuidv4();
|
|
@@ -719,7 +766,8 @@ describe(EntityMutatorFactory, () => {
|
|
|
719
766
|
const existingEntity = await enforceAsyncResult(
|
|
720
767
|
entityLoaderFactory
|
|
721
768
|
.forLoad(viewerContext, queryContext, privacyPolicyEvaluationContext)
|
|
722
|
-
.
|
|
769
|
+
.withAuthorizationResults()
|
|
770
|
+
.loadByIDAsync(id2),
|
|
723
771
|
);
|
|
724
772
|
|
|
725
773
|
await entityMutatorFactory
|
|
@@ -733,12 +781,74 @@ describe(EntityMutatorFactory, () => {
|
|
|
733
781
|
cascadingDeleteCause: null,
|
|
734
782
|
});
|
|
735
783
|
});
|
|
784
|
+
|
|
785
|
+
it('throws when id field is updated', async () => {
|
|
786
|
+
const viewerContext = mock<ViewerContext>();
|
|
787
|
+
const privacyPolicyEvaluationContext =
|
|
788
|
+
instance(
|
|
789
|
+
mock<
|
|
790
|
+
EntityPrivacyPolicyEvaluationContext<
|
|
791
|
+
TestFields,
|
|
792
|
+
string,
|
|
793
|
+
ViewerContext,
|
|
794
|
+
TestEntity,
|
|
795
|
+
keyof TestFields
|
|
796
|
+
>
|
|
797
|
+
>(),
|
|
798
|
+
);
|
|
799
|
+
const queryContext = StubQueryContextProvider.getQueryContext();
|
|
800
|
+
|
|
801
|
+
const id1 = uuidv4();
|
|
802
|
+
const { entityMutatorFactory, entityLoaderFactory } = createEntityMutatorFactory([
|
|
803
|
+
{
|
|
804
|
+
customIdField: id1,
|
|
805
|
+
stringField: 'huh',
|
|
806
|
+
testIndexedField: '4',
|
|
807
|
+
intField: 3,
|
|
808
|
+
dateField: new Date(),
|
|
809
|
+
nullableField: null,
|
|
810
|
+
},
|
|
811
|
+
]);
|
|
812
|
+
|
|
813
|
+
const existingEntity = await enforceAsyncResult(
|
|
814
|
+
entityLoaderFactory
|
|
815
|
+
.forLoad(viewerContext, queryContext, privacyPolicyEvaluationContext)
|
|
816
|
+
.withAuthorizationResults()
|
|
817
|
+
.loadByIDAsync(id1),
|
|
818
|
+
);
|
|
819
|
+
|
|
820
|
+
await expect(
|
|
821
|
+
entityMutatorFactory
|
|
822
|
+
.forUpdate(existingEntity, queryContext)
|
|
823
|
+
.setField('customIdField', uuidv4())
|
|
824
|
+
.enforceUpdateAsync(),
|
|
825
|
+
).rejects.toThrow('id field updates not supported: (entityClass = TestEntity)');
|
|
826
|
+
|
|
827
|
+
const reloadedEntity = await enforceAsyncResult(
|
|
828
|
+
entityLoaderFactory
|
|
829
|
+
.forLoad(viewerContext, queryContext, privacyPolicyEvaluationContext)
|
|
830
|
+
.withAuthorizationResults()
|
|
831
|
+
.loadByIDAsync(id1),
|
|
832
|
+
);
|
|
833
|
+
expect(reloadedEntity.getAllFields()).toMatchObject(existingEntity.getAllFields());
|
|
834
|
+
});
|
|
736
835
|
});
|
|
737
836
|
|
|
738
837
|
describe('forDelete', () => {
|
|
739
838
|
it('deletes entities', async () => {
|
|
740
839
|
const viewerContext = mock<ViewerContext>();
|
|
741
|
-
const privacyPolicyEvaluationContext =
|
|
840
|
+
const privacyPolicyEvaluationContext =
|
|
841
|
+
instance(
|
|
842
|
+
mock<
|
|
843
|
+
EntityPrivacyPolicyEvaluationContext<
|
|
844
|
+
TestFields,
|
|
845
|
+
string,
|
|
846
|
+
ViewerContext,
|
|
847
|
+
TestEntity,
|
|
848
|
+
keyof TestFields
|
|
849
|
+
>
|
|
850
|
+
>(),
|
|
851
|
+
);
|
|
742
852
|
const queryContext = StubQueryContextProvider.getQueryContext();
|
|
743
853
|
|
|
744
854
|
const id1 = uuidv4();
|
|
@@ -756,7 +866,8 @@ describe(EntityMutatorFactory, () => {
|
|
|
756
866
|
const existingEntity = await enforceAsyncResult(
|
|
757
867
|
entityLoaderFactory
|
|
758
868
|
.forLoad(viewerContext, queryContext, privacyPolicyEvaluationContext)
|
|
759
|
-
.
|
|
869
|
+
.withAuthorizationResults()
|
|
870
|
+
.loadByIDAsync(id1),
|
|
760
871
|
);
|
|
761
872
|
expect(existingEntity).toBeTruthy();
|
|
762
873
|
|
|
@@ -766,14 +877,26 @@ describe(EntityMutatorFactory, () => {
|
|
|
766
877
|
enforceAsyncResult(
|
|
767
878
|
entityLoaderFactory
|
|
768
879
|
.forLoad(viewerContext, queryContext, privacyPolicyEvaluationContext)
|
|
769
|
-
.
|
|
770
|
-
|
|
880
|
+
.withAuthorizationResults()
|
|
881
|
+
.loadByIDAsync(id1),
|
|
882
|
+
),
|
|
771
883
|
).rejects.toBeInstanceOf(Error);
|
|
772
884
|
});
|
|
773
885
|
|
|
774
886
|
it('checks privacy', async () => {
|
|
775
887
|
const viewerContext = mock<ViewerContext>();
|
|
776
|
-
const privacyPolicyEvaluationContext =
|
|
888
|
+
const privacyPolicyEvaluationContext =
|
|
889
|
+
instance(
|
|
890
|
+
mock<
|
|
891
|
+
EntityPrivacyPolicyEvaluationContext<
|
|
892
|
+
TestFields,
|
|
893
|
+
string,
|
|
894
|
+
ViewerContext,
|
|
895
|
+
TestEntity,
|
|
896
|
+
keyof TestFields
|
|
897
|
+
>
|
|
898
|
+
>(),
|
|
899
|
+
);
|
|
777
900
|
const queryContext = StubQueryContextProvider.getQueryContext();
|
|
778
901
|
|
|
779
902
|
const id1 = uuidv4();
|
|
@@ -794,7 +917,8 @@ describe(EntityMutatorFactory, () => {
|
|
|
794
917
|
const existingEntity = await enforceAsyncResult(
|
|
795
918
|
entityLoaderFactory
|
|
796
919
|
.forLoad(viewerContext, queryContext, privacyPolicyEvaluationContext)
|
|
797
|
-
.
|
|
920
|
+
.withAuthorizationResults()
|
|
921
|
+
.loadByIDAsync(id1),
|
|
798
922
|
);
|
|
799
923
|
|
|
800
924
|
await entityMutatorFactory.forDelete(existingEntity, queryContext).enforceDeleteAsync();
|
|
@@ -805,14 +929,25 @@ describe(EntityMutatorFactory, () => {
|
|
|
805
929
|
anyOfClass(EntityTransactionalQueryContext),
|
|
806
930
|
anything(),
|
|
807
931
|
anyOfClass(TestEntity),
|
|
808
|
-
anything()
|
|
809
|
-
)
|
|
932
|
+
anything(),
|
|
933
|
+
),
|
|
810
934
|
).once();
|
|
811
935
|
});
|
|
812
936
|
|
|
813
937
|
it('executes triggers', async () => {
|
|
814
938
|
const viewerContext = mock<ViewerContext>();
|
|
815
|
-
const privacyPolicyEvaluationContext =
|
|
939
|
+
const privacyPolicyEvaluationContext =
|
|
940
|
+
instance(
|
|
941
|
+
mock<
|
|
942
|
+
EntityPrivacyPolicyEvaluationContext<
|
|
943
|
+
TestFields,
|
|
944
|
+
string,
|
|
945
|
+
ViewerContext,
|
|
946
|
+
TestEntity,
|
|
947
|
+
keyof TestFields
|
|
948
|
+
>
|
|
949
|
+
>(),
|
|
950
|
+
);
|
|
816
951
|
const queryContext = StubQueryContextProvider.getQueryContext();
|
|
817
952
|
|
|
818
953
|
const id1 = uuidv4();
|
|
@@ -833,7 +968,8 @@ describe(EntityMutatorFactory, () => {
|
|
|
833
968
|
const existingEntity = await enforceAsyncResult(
|
|
834
969
|
entityLoaderFactory
|
|
835
970
|
.forLoad(viewerContext, queryContext, privacyPolicyEvaluationContext)
|
|
836
|
-
.
|
|
971
|
+
.withAuthorizationResults()
|
|
972
|
+
.loadByIDAsync(id1),
|
|
837
973
|
);
|
|
838
974
|
|
|
839
975
|
await entityMutatorFactory.forDelete(existingEntity, queryContext).enforceDeleteAsync();
|
|
@@ -849,13 +985,24 @@ describe(EntityMutatorFactory, () => {
|
|
|
849
985
|
beforeDelete: true,
|
|
850
986
|
afterDelete: true,
|
|
851
987
|
},
|
|
852
|
-
{ type: EntityMutationType.DELETE, cascadingDeleteCause: null }
|
|
988
|
+
{ type: EntityMutationType.DELETE, cascadingDeleteCause: null },
|
|
853
989
|
);
|
|
854
990
|
});
|
|
855
991
|
|
|
856
992
|
it('does not execute validators', async () => {
|
|
857
993
|
const viewerContext = mock<ViewerContext>();
|
|
858
|
-
const privacyPolicyEvaluationContext =
|
|
994
|
+
const privacyPolicyEvaluationContext =
|
|
995
|
+
instance(
|
|
996
|
+
mock<
|
|
997
|
+
EntityPrivacyPolicyEvaluationContext<
|
|
998
|
+
TestFields,
|
|
999
|
+
string,
|
|
1000
|
+
ViewerContext,
|
|
1001
|
+
TestEntity,
|
|
1002
|
+
keyof TestFields
|
|
1003
|
+
>
|
|
1004
|
+
>(),
|
|
1005
|
+
);
|
|
859
1006
|
const queryContext = StubQueryContextProvider.getQueryContext();
|
|
860
1007
|
|
|
861
1008
|
const id1 = uuidv4();
|
|
@@ -876,7 +1023,8 @@ describe(EntityMutatorFactory, () => {
|
|
|
876
1023
|
const existingEntity = await enforceAsyncResult(
|
|
877
1024
|
entityLoaderFactory
|
|
878
1025
|
.forLoad(viewerContext, queryContext, privacyPolicyEvaluationContext)
|
|
879
|
-
.
|
|
1026
|
+
.withAuthorizationResults()
|
|
1027
|
+
.loadByIDAsync(id1),
|
|
880
1028
|
);
|
|
881
1029
|
|
|
882
1030
|
await entityMutatorFactory.forDelete(existingEntity, queryContext).enforceDeleteAsync();
|
|
@@ -889,7 +1037,18 @@ describe(EntityMutatorFactory, () => {
|
|
|
889
1037
|
|
|
890
1038
|
it('invalidates cache for fields upon create', async () => {
|
|
891
1039
|
const viewerContext = mock<ViewerContext>();
|
|
892
|
-
const privacyPolicyEvaluationContext =
|
|
1040
|
+
const privacyPolicyEvaluationContext =
|
|
1041
|
+
instance(
|
|
1042
|
+
mock<
|
|
1043
|
+
EntityPrivacyPolicyEvaluationContext<
|
|
1044
|
+
TestFields,
|
|
1045
|
+
string,
|
|
1046
|
+
ViewerContext,
|
|
1047
|
+
TestEntity,
|
|
1048
|
+
keyof TestFields
|
|
1049
|
+
>
|
|
1050
|
+
>(),
|
|
1051
|
+
);
|
|
893
1052
|
const queryContext = StubQueryContextProvider.getQueryContext();
|
|
894
1053
|
|
|
895
1054
|
const id1 = uuidv4();
|
|
@@ -907,7 +1066,8 @@ describe(EntityMutatorFactory, () => {
|
|
|
907
1066
|
const entites1 = await enforceResultsAsync(
|
|
908
1067
|
entityLoaderFactory
|
|
909
1068
|
.forLoad(viewerContext, queryContext, privacyPolicyEvaluationContext)
|
|
910
|
-
.
|
|
1069
|
+
.withAuthorizationResults()
|
|
1070
|
+
.loadManyByFieldEqualingAsync('stringField', 'huh'),
|
|
911
1071
|
);
|
|
912
1072
|
expect(entites1).toHaveLength(1);
|
|
913
1073
|
|
|
@@ -915,13 +1075,14 @@ describe(EntityMutatorFactory, () => {
|
|
|
915
1075
|
entityMutatorFactory
|
|
916
1076
|
.forCreate(viewerContext, queryContext)
|
|
917
1077
|
.setField('stringField', 'huh')
|
|
918
|
-
.createAsync()
|
|
1078
|
+
.createAsync(),
|
|
919
1079
|
);
|
|
920
1080
|
|
|
921
1081
|
const entities2 = await enforceResultsAsync(
|
|
922
1082
|
entityLoaderFactory
|
|
923
1083
|
.forLoad(viewerContext, queryContext, privacyPolicyEvaluationContext)
|
|
924
|
-
.
|
|
1084
|
+
.withAuthorizationResults()
|
|
1085
|
+
.loadManyByFieldEqualingAsync('stringField', 'huh'),
|
|
925
1086
|
);
|
|
926
1087
|
expect(entities2).toHaveLength(2);
|
|
927
1088
|
});
|
|
@@ -945,7 +1106,7 @@ describe(EntityMutatorFactory, () => {
|
|
|
945
1106
|
entityMutatorFactory
|
|
946
1107
|
.forCreate(viewerContext, queryContext)
|
|
947
1108
|
.setField('stringField', 10 as any)
|
|
948
|
-
.createAsync()
|
|
1109
|
+
.createAsync(),
|
|
949
1110
|
).rejects.toThrowError('Entity field not valid: TestEntity (stringField = 10)');
|
|
950
1111
|
|
|
951
1112
|
const createdEntity = await entityMutatorFactory
|
|
@@ -957,7 +1118,7 @@ describe(EntityMutatorFactory, () => {
|
|
|
957
1118
|
entityMutatorFactory
|
|
958
1119
|
.forUpdate(createdEntity, queryContext)
|
|
959
1120
|
.setField('stringField', 10 as any)
|
|
960
|
-
.updateAsync()
|
|
1121
|
+
.updateAsync(),
|
|
961
1122
|
).rejects.toThrowError('Entity field not valid: TestEntity (stringField = 10)');
|
|
962
1123
|
});
|
|
963
1124
|
|
|
@@ -992,7 +1153,19 @@ describe(EntityMutatorFactory, () => {
|
|
|
992
1153
|
keyof SimpleTestFields
|
|
993
1154
|
>
|
|
994
1155
|
>(EntityLoader);
|
|
995
|
-
|
|
1156
|
+
const entityLoaderUtilsMock =
|
|
1157
|
+
mock<
|
|
1158
|
+
EntityLoaderUtils<
|
|
1159
|
+
SimpleTestFields,
|
|
1160
|
+
string,
|
|
1161
|
+
ViewerContext,
|
|
1162
|
+
SimpleTestEntity,
|
|
1163
|
+
SimpleTestEntityPrivacyPolicy,
|
|
1164
|
+
keyof SimpleTestFields
|
|
1165
|
+
>
|
|
1166
|
+
>(EntityLoaderUtils);
|
|
1167
|
+
when(entityLoaderUtilsMock.constructEntity(anything())).thenReturn(fakeEntity);
|
|
1168
|
+
when(entityLoaderMock.utils()).thenReturn(instance(entityLoaderUtilsMock));
|
|
996
1169
|
const entityLoader = instance(entityLoaderMock);
|
|
997
1170
|
|
|
998
1171
|
const entityLoaderFactoryMock =
|
|
@@ -1010,8 +1183,8 @@ describe(EntityMutatorFactory, () => {
|
|
|
1010
1183
|
entityLoaderFactoryMock.forLoad(
|
|
1011
1184
|
viewerContext,
|
|
1012
1185
|
anyOfClass(EntityTransactionalQueryContext),
|
|
1013
|
-
anything()
|
|
1014
|
-
)
|
|
1186
|
+
anything(),
|
|
1187
|
+
),
|
|
1015
1188
|
).thenReturn(entityLoader);
|
|
1016
1189
|
const entityLoaderFactory = instance(entityLoaderFactoryMock);
|
|
1017
1190
|
|
|
@@ -1023,8 +1196,8 @@ describe(EntityMutatorFactory, () => {
|
|
|
1023
1196
|
anyOfClass(EntityTransactionalQueryContext),
|
|
1024
1197
|
anything(),
|
|
1025
1198
|
anyOfClass(SimpleTestEntity),
|
|
1026
|
-
anything()
|
|
1027
|
-
)
|
|
1199
|
+
anything(),
|
|
1200
|
+
),
|
|
1028
1201
|
).thenReject(rejectionError);
|
|
1029
1202
|
when(
|
|
1030
1203
|
privacyPolicyMock.authorizeUpdateAsync(
|
|
@@ -1032,8 +1205,8 @@ describe(EntityMutatorFactory, () => {
|
|
|
1032
1205
|
anyOfClass(EntityTransactionalQueryContext),
|
|
1033
1206
|
anything(),
|
|
1034
1207
|
anyOfClass(SimpleTestEntity),
|
|
1035
|
-
anything()
|
|
1036
|
-
)
|
|
1208
|
+
anything(),
|
|
1209
|
+
),
|
|
1037
1210
|
).thenReject(rejectionError);
|
|
1038
1211
|
when(
|
|
1039
1212
|
privacyPolicyMock.authorizeDeleteAsync(
|
|
@@ -1041,8 +1214,8 @@ describe(EntityMutatorFactory, () => {
|
|
|
1041
1214
|
anyOfClass(EntityTransactionalQueryContext),
|
|
1042
1215
|
anything(),
|
|
1043
1216
|
anyOfClass(SimpleTestEntity),
|
|
1044
|
-
anything()
|
|
1045
|
-
)
|
|
1217
|
+
anything(),
|
|
1218
|
+
),
|
|
1046
1219
|
).thenReject(rejectionError);
|
|
1047
1220
|
|
|
1048
1221
|
const entityMutatorFactory = new EntityMutatorFactory(
|
|
@@ -1054,7 +1227,7 @@ describe(EntityMutatorFactory, () => {
|
|
|
1054
1227
|
{},
|
|
1055
1228
|
entityLoaderFactory,
|
|
1056
1229
|
databaseAdapter,
|
|
1057
|
-
metricsAdapter
|
|
1230
|
+
metricsAdapter,
|
|
1058
1231
|
);
|
|
1059
1232
|
|
|
1060
1233
|
const entityCreateResult = await entityMutatorFactory
|
|
@@ -1116,7 +1289,19 @@ describe(EntityMutatorFactory, () => {
|
|
|
1116
1289
|
keyof SimpleTestFields
|
|
1117
1290
|
>
|
|
1118
1291
|
>(EntityLoader);
|
|
1119
|
-
|
|
1292
|
+
const entityLoaderUtilsMock =
|
|
1293
|
+
mock<
|
|
1294
|
+
EntityLoaderUtils<
|
|
1295
|
+
SimpleTestFields,
|
|
1296
|
+
string,
|
|
1297
|
+
ViewerContext,
|
|
1298
|
+
SimpleTestEntity,
|
|
1299
|
+
SimpleTestEntityPrivacyPolicy,
|
|
1300
|
+
keyof SimpleTestFields
|
|
1301
|
+
>
|
|
1302
|
+
>(EntityLoaderUtils);
|
|
1303
|
+
when(entityLoaderUtilsMock.constructEntity(anything())).thenReturn(fakeEntity);
|
|
1304
|
+
when(entityLoaderMock.utils()).thenReturn(instance(entityLoaderUtilsMock));
|
|
1120
1305
|
const entityLoader = instance(entityLoaderMock);
|
|
1121
1306
|
|
|
1122
1307
|
const entityLoaderFactoryMock =
|
|
@@ -1134,30 +1319,30 @@ describe(EntityMutatorFactory, () => {
|
|
|
1134
1319
|
entityLoaderFactoryMock.forLoad(
|
|
1135
1320
|
viewerContext,
|
|
1136
1321
|
anyOfClass(EntityTransactionalQueryContext),
|
|
1137
|
-
anything()
|
|
1138
|
-
)
|
|
1322
|
+
anything(),
|
|
1323
|
+
),
|
|
1139
1324
|
).thenReturn(entityLoader);
|
|
1140
1325
|
const entityLoaderFactory = instance(entityLoaderFactoryMock);
|
|
1141
1326
|
|
|
1142
1327
|
const rejectionError = new Error();
|
|
1143
1328
|
|
|
1144
1329
|
when(
|
|
1145
|
-
databaseAdapterMock.insertAsync(anyOfClass(EntityTransactionalQueryContext), anything())
|
|
1330
|
+
databaseAdapterMock.insertAsync(anyOfClass(EntityTransactionalQueryContext), anything()),
|
|
1146
1331
|
).thenReject(rejectionError);
|
|
1147
1332
|
when(
|
|
1148
1333
|
databaseAdapterMock.updateAsync(
|
|
1149
1334
|
anyOfClass(EntityTransactionalQueryContext),
|
|
1150
1335
|
anything(),
|
|
1151
1336
|
anything(),
|
|
1152
|
-
anything()
|
|
1153
|
-
)
|
|
1337
|
+
anything(),
|
|
1338
|
+
),
|
|
1154
1339
|
).thenReject(rejectionError);
|
|
1155
1340
|
when(
|
|
1156
1341
|
databaseAdapterMock.deleteAsync(
|
|
1157
1342
|
anyOfClass(EntityTransactionalQueryContext),
|
|
1158
1343
|
anything(),
|
|
1159
|
-
anything()
|
|
1160
|
-
)
|
|
1344
|
+
anything(),
|
|
1345
|
+
),
|
|
1161
1346
|
).thenReject(rejectionError);
|
|
1162
1347
|
|
|
1163
1348
|
const entityMutatorFactory = new EntityMutatorFactory(
|
|
@@ -1169,17 +1354,17 @@ describe(EntityMutatorFactory, () => {
|
|
|
1169
1354
|
{},
|
|
1170
1355
|
entityLoaderFactory,
|
|
1171
1356
|
instance(databaseAdapterMock),
|
|
1172
|
-
metricsAdapter
|
|
1357
|
+
metricsAdapter,
|
|
1173
1358
|
);
|
|
1174
1359
|
|
|
1175
1360
|
await expect(
|
|
1176
|
-
entityMutatorFactory.forCreate(viewerContext, queryContext).createAsync()
|
|
1361
|
+
entityMutatorFactory.forCreate(viewerContext, queryContext).createAsync(),
|
|
1177
1362
|
).rejects.toEqual(rejectionError);
|
|
1178
1363
|
await expect(
|
|
1179
|
-
entityMutatorFactory.forUpdate(fakeEntity, queryContext).updateAsync()
|
|
1364
|
+
entityMutatorFactory.forUpdate(fakeEntity, queryContext).updateAsync(),
|
|
1180
1365
|
).rejects.toEqual(rejectionError);
|
|
1181
1366
|
await expect(
|
|
1182
|
-
entityMutatorFactory.forDelete(fakeEntity, queryContext).deleteAsync()
|
|
1367
|
+
entityMutatorFactory.forDelete(fakeEntity, queryContext).deleteAsync(),
|
|
1183
1368
|
).rejects.toEqual(rejectionError);
|
|
1184
1369
|
});
|
|
1185
1370
|
|
|
@@ -1193,14 +1378,14 @@ describe(EntityMutatorFactory, () => {
|
|
|
1193
1378
|
entityMutatorFactory
|
|
1194
1379
|
.forCreate(viewerContext, queryContext)
|
|
1195
1380
|
.setField('stringField', 'huh')
|
|
1196
|
-
.createAsync()
|
|
1381
|
+
.createAsync(),
|
|
1197
1382
|
);
|
|
1198
1383
|
|
|
1199
1384
|
await enforceAsyncResult(
|
|
1200
1385
|
entityMutatorFactory
|
|
1201
1386
|
.forUpdate(newEntity, queryContext)
|
|
1202
1387
|
.setField('stringField', 'wat')
|
|
1203
|
-
.updateAsync()
|
|
1388
|
+
.updateAsync(),
|
|
1204
1389
|
);
|
|
1205
1390
|
|
|
1206
1391
|
await enforceAsyncResult(entityMutatorFactory.forDelete(newEntity, queryContext).deleteAsync());
|
|
@@ -1210,24 +1395,24 @@ describe(EntityMutatorFactory, () => {
|
|
|
1210
1395
|
objectContaining({
|
|
1211
1396
|
type: EntityMetricsMutationType.CREATE,
|
|
1212
1397
|
entityClassName: TestEntity.name,
|
|
1213
|
-
})
|
|
1214
|
-
)
|
|
1398
|
+
}),
|
|
1399
|
+
),
|
|
1215
1400
|
).once();
|
|
1216
1401
|
verify(
|
|
1217
1402
|
spiedMetricsAdapter.logMutatorMutationEvent(
|
|
1218
1403
|
objectContaining({
|
|
1219
1404
|
type: EntityMetricsMutationType.UPDATE,
|
|
1220
1405
|
entityClassName: TestEntity.name,
|
|
1221
|
-
})
|
|
1222
|
-
)
|
|
1406
|
+
}),
|
|
1407
|
+
),
|
|
1223
1408
|
).once();
|
|
1224
1409
|
verify(
|
|
1225
1410
|
spiedMetricsAdapter.logMutatorMutationEvent(
|
|
1226
1411
|
objectContaining({
|
|
1227
1412
|
type: EntityMetricsMutationType.DELETE,
|
|
1228
1413
|
entityClassName: TestEntity.name,
|
|
1229
|
-
})
|
|
1230
|
-
)
|
|
1414
|
+
}),
|
|
1415
|
+
),
|
|
1231
1416
|
).once();
|
|
1232
1417
|
verify(spiedMetricsAdapter.logMutatorMutationEvent(anything())).thrice();
|
|
1233
1418
|
});
|