@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
|
@@ -44,10 +44,10 @@ const blahEntityConfiguration = new EntityConfiguration<BlahT>({
|
|
|
44
44
|
describe(getDatabaseFieldForEntityField, () => {
|
|
45
45
|
it('returns correct mapping', () => {
|
|
46
46
|
expect(getDatabaseFieldForEntityField(blahEntityConfiguration, 'cacheable')).toEqual(
|
|
47
|
-
'cacheable'
|
|
47
|
+
'cacheable',
|
|
48
48
|
);
|
|
49
49
|
expect(
|
|
50
|
-
getDatabaseFieldForEntityField(blahEntityConfiguration, 'uniqueButNotCacheable')
|
|
50
|
+
getDatabaseFieldForEntityField(blahEntityConfiguration, 'uniqueButNotCacheable'),
|
|
51
51
|
).toEqual('unique_but_not_cacheable');
|
|
52
52
|
});
|
|
53
53
|
});
|
|
@@ -59,7 +59,7 @@ describe(transformDatabaseObjectToFields, () => {
|
|
|
59
59
|
id: 'blah',
|
|
60
60
|
unique_but_not_cacheable: 'wat',
|
|
61
61
|
who: 'why',
|
|
62
|
-
})
|
|
62
|
+
}),
|
|
63
63
|
).toEqual({
|
|
64
64
|
id: 'blah',
|
|
65
65
|
uniqueButNotCacheable: 'wat',
|
|
@@ -79,7 +79,7 @@ describe(transformDatabaseObjectToFields, () => {
|
|
|
79
79
|
expect(
|
|
80
80
|
transformDatabaseObjectToFields(blahEntityConfiguration, fieldTransformMap, {
|
|
81
81
|
transform_read: 'wat',
|
|
82
|
-
})
|
|
82
|
+
}),
|
|
83
83
|
).toEqual({
|
|
84
84
|
transformRead: 'wat-read-transformed',
|
|
85
85
|
});
|
|
@@ -93,7 +93,7 @@ describe(transformFieldsToDatabaseObject, () => {
|
|
|
93
93
|
id: 'blah',
|
|
94
94
|
cacheable: 'wat',
|
|
95
95
|
uniqueButNotCacheable: 'wat',
|
|
96
|
-
})
|
|
96
|
+
}),
|
|
97
97
|
).toEqual({
|
|
98
98
|
id: 'blah',
|
|
99
99
|
cacheable: 'wat',
|
|
@@ -114,7 +114,7 @@ describe(transformFieldsToDatabaseObject, () => {
|
|
|
114
114
|
expect(
|
|
115
115
|
transformFieldsToDatabaseObject(blahEntityConfiguration, fieldTransformMap, {
|
|
116
116
|
transformWrite: 'wat',
|
|
117
|
-
})
|
|
117
|
+
}),
|
|
118
118
|
).toEqual({
|
|
119
119
|
transform_write: 'wat-write-transformed',
|
|
120
120
|
});
|
|
@@ -122,7 +122,7 @@ describe(transformFieldsToDatabaseObject, () => {
|
|
|
122
122
|
});
|
|
123
123
|
|
|
124
124
|
describe(transformCacheObjectToFields, () => {
|
|
125
|
-
it('does field read transformation', () => {
|
|
125
|
+
it('does field read transformation, keeping unknown fields for cache version inconsistencies', () => {
|
|
126
126
|
const fieldTransformMap = new Map([
|
|
127
127
|
[
|
|
128
128
|
StringField.name,
|
|
@@ -136,16 +136,18 @@ describe(transformCacheObjectToFields, () => {
|
|
|
136
136
|
transformCacheObjectToFields(blahEntityConfiguration, fieldTransformMap, {
|
|
137
137
|
id: 'hello',
|
|
138
138
|
transformRead: 'wat',
|
|
139
|
-
|
|
139
|
+
unknownField: 'who',
|
|
140
|
+
}),
|
|
140
141
|
).toEqual({
|
|
141
142
|
id: 'hello',
|
|
142
143
|
transformRead: 'wat-read-transformed-cache',
|
|
144
|
+
unknownField: 'who',
|
|
143
145
|
});
|
|
144
146
|
});
|
|
145
147
|
});
|
|
146
148
|
|
|
147
149
|
describe(transformFieldsToCacheObject, () => {
|
|
148
|
-
it('does field write transformation', () => {
|
|
150
|
+
it('does field write transformation, keeping unknown fields at runtime for cache version inconsistencies', () => {
|
|
149
151
|
const fieldTransformMap = new Map([
|
|
150
152
|
[
|
|
151
153
|
StringField.name,
|
|
@@ -159,10 +161,12 @@ describe(transformFieldsToCacheObject, () => {
|
|
|
159
161
|
transformFieldsToCacheObject(blahEntityConfiguration, fieldTransformMap, {
|
|
160
162
|
id: 'hello',
|
|
161
163
|
transformWrite: 'wat',
|
|
162
|
-
|
|
164
|
+
unknownField: 'who',
|
|
165
|
+
} as any),
|
|
163
166
|
).toEqual({
|
|
164
167
|
id: 'hello',
|
|
165
168
|
transformWrite: 'wat-write-transformed-cache',
|
|
169
|
+
unknownField: 'who',
|
|
166
170
|
});
|
|
167
171
|
});
|
|
168
172
|
});
|
|
@@ -23,7 +23,7 @@ const makeEntityConfiguration = (cacheIdField: boolean): EntityConfiguration<Bla
|
|
|
23
23
|
const createIdFetcher =
|
|
24
24
|
(ids: string[]) =>
|
|
25
25
|
async <N extends keyof BlahFields>(
|
|
26
|
-
fetcherFieldValues: readonly NonNullable<BlahFields[N]>[]
|
|
26
|
+
fetcherFieldValues: readonly NonNullable<BlahFields[N]>[],
|
|
27
27
|
): Promise<ReadonlyMap<NonNullable<BlahFields[N]>, readonly Readonly<BlahFields>[]>> => {
|
|
28
28
|
const results = new Map();
|
|
29
29
|
fetcherFieldValues.forEach((v) => {
|
|
@@ -36,6 +36,22 @@ const createIdFetcher =
|
|
|
36
36
|
return results;
|
|
37
37
|
};
|
|
38
38
|
|
|
39
|
+
const createFetcherNonUnique =
|
|
40
|
+
(ids: string[]) =>
|
|
41
|
+
async <N extends keyof BlahFields>(
|
|
42
|
+
fetcherFieldValues: readonly NonNullable<BlahFields[N]>[],
|
|
43
|
+
): Promise<ReadonlyMap<NonNullable<BlahFields[N]>, readonly Readonly<BlahFields>[]>> => {
|
|
44
|
+
const results = new Map();
|
|
45
|
+
fetcherFieldValues.forEach((v) => {
|
|
46
|
+
if (ids.includes(v)) {
|
|
47
|
+
results.set(v, [{ id: v }, { id: v + '2' }]);
|
|
48
|
+
} else {
|
|
49
|
+
results.set(v, []);
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
return results;
|
|
53
|
+
};
|
|
54
|
+
|
|
39
55
|
describe(ReadThroughEntityCache, () => {
|
|
40
56
|
describe('readManyThroughAsync', () => {
|
|
41
57
|
it('fetches from DB upon cache miss and caches the result', async () => {
|
|
@@ -48,7 +64,7 @@ describe(ReadThroughEntityCache, () => {
|
|
|
48
64
|
new Map([
|
|
49
65
|
['wat', { status: CacheStatus.MISS }],
|
|
50
66
|
['who', { status: CacheStatus.MISS }],
|
|
51
|
-
])
|
|
67
|
+
]),
|
|
52
68
|
);
|
|
53
69
|
|
|
54
70
|
const result = await entityCache.readManyThroughAsync('id', ['wat', 'who'], fetcher);
|
|
@@ -61,16 +77,16 @@ describe(ReadThroughEntityCache, () => {
|
|
|
61
77
|
new Map([
|
|
62
78
|
['wat', { id: 'wat' }],
|
|
63
79
|
['who', { id: 'who' }],
|
|
64
|
-
])
|
|
65
|
-
)
|
|
66
|
-
)
|
|
80
|
+
]),
|
|
81
|
+
),
|
|
82
|
+
),
|
|
67
83
|
).once();
|
|
68
84
|
verify(cacheAdapterMock.cacheDBMissesAsync('id', deepEqual([]))).once();
|
|
69
85
|
expect(result).toEqual(
|
|
70
86
|
new Map([
|
|
71
87
|
['wat', [{ id: 'wat' }]],
|
|
72
88
|
['who', [{ id: 'who' }]],
|
|
73
|
-
])
|
|
89
|
+
]),
|
|
74
90
|
);
|
|
75
91
|
});
|
|
76
92
|
|
|
@@ -84,7 +100,7 @@ describe(ReadThroughEntityCache, () => {
|
|
|
84
100
|
new Map([
|
|
85
101
|
['wat', { status: CacheStatus.HIT, item: { id: 'wat' } }],
|
|
86
102
|
['who', { status: CacheStatus.HIT, item: { id: 'who' } }],
|
|
87
|
-
])
|
|
103
|
+
]),
|
|
88
104
|
);
|
|
89
105
|
|
|
90
106
|
const result = await entityCache.readManyThroughAsync('id', ['wat', 'who'], fetcher);
|
|
@@ -97,16 +113,16 @@ describe(ReadThroughEntityCache, () => {
|
|
|
97
113
|
new Map([
|
|
98
114
|
['wat', { id: 'wat' }],
|
|
99
115
|
['who', { id: 'who' }],
|
|
100
|
-
])
|
|
101
|
-
)
|
|
102
|
-
)
|
|
116
|
+
]),
|
|
117
|
+
),
|
|
118
|
+
),
|
|
103
119
|
).never();
|
|
104
120
|
verify(cacheAdapterMock.cacheDBMissesAsync('id', deepEqual([]))).never();
|
|
105
121
|
expect(result).toEqual(
|
|
106
122
|
new Map([
|
|
107
123
|
['wat', [{ id: 'wat' }]],
|
|
108
124
|
['who', [{ id: 'who' }]],
|
|
109
|
-
])
|
|
125
|
+
]),
|
|
110
126
|
);
|
|
111
127
|
});
|
|
112
128
|
|
|
@@ -119,7 +135,7 @@ describe(ReadThroughEntityCache, () => {
|
|
|
119
135
|
const fetcher = createIdFetcher(['wat', 'who']);
|
|
120
136
|
|
|
121
137
|
when(cacheAdapterMock.loadManyAsync('id', deepEqual(['why']))).thenResolve(
|
|
122
|
-
new Map([['why', { status: CacheStatus.MISS }]])
|
|
138
|
+
new Map([['why', { status: CacheStatus.MISS }]]),
|
|
123
139
|
);
|
|
124
140
|
|
|
125
141
|
const result = await entityCache.readManyThroughAsync('id', ['why'], fetcher);
|
|
@@ -137,7 +153,7 @@ describe(ReadThroughEntityCache, () => {
|
|
|
137
153
|
const fetcher = createIdFetcher([]);
|
|
138
154
|
|
|
139
155
|
when(cacheAdapterMock.loadManyAsync('id', deepEqual(['why']))).thenResolve(
|
|
140
|
-
new Map([['why', { status: CacheStatus.NEGATIVE }]])
|
|
156
|
+
new Map([['why', { status: CacheStatus.NEGATIVE }]]),
|
|
141
157
|
);
|
|
142
158
|
|
|
143
159
|
const result = await entityCache.readManyThroughAsync('id', ['why'], fetcher);
|
|
@@ -154,31 +170,31 @@ describe(ReadThroughEntityCache, () => {
|
|
|
154
170
|
const fetcher = createIdFetcher(['wat', 'who', 'why']);
|
|
155
171
|
|
|
156
172
|
when(
|
|
157
|
-
cacheAdapterMock.loadManyAsync('id', deepEqual(['wat', 'who', 'why', 'how']))
|
|
173
|
+
cacheAdapterMock.loadManyAsync('id', deepEqual(['wat', 'who', 'why', 'how'])),
|
|
158
174
|
).thenResolve(
|
|
159
175
|
new Map([
|
|
160
176
|
['wat', { status: CacheStatus.MISS }],
|
|
161
177
|
['who', { status: CacheStatus.NEGATIVE }],
|
|
162
178
|
['why', { status: CacheStatus.HIT, item: { id: 'why' } }],
|
|
163
179
|
['how', { status: CacheStatus.MISS }],
|
|
164
|
-
])
|
|
180
|
+
]),
|
|
165
181
|
);
|
|
166
182
|
|
|
167
183
|
const result = await entityCache.readManyThroughAsync(
|
|
168
184
|
'id',
|
|
169
185
|
['wat', 'who', 'why', 'how'],
|
|
170
|
-
fetcher
|
|
186
|
+
fetcher,
|
|
171
187
|
);
|
|
172
188
|
verify(cacheAdapterMock.loadManyAsync('id', deepEqual(['wat', 'who', 'why', 'how']))).once();
|
|
173
189
|
verify(
|
|
174
|
-
cacheAdapterMock.cacheManyAsync('id', deepEqual(new Map([['wat', { id: 'wat' }]])))
|
|
190
|
+
cacheAdapterMock.cacheManyAsync('id', deepEqual(new Map([['wat', { id: 'wat' }]]))),
|
|
175
191
|
).once();
|
|
176
192
|
verify(cacheAdapterMock.cacheDBMissesAsync('id', deepEqual(['how']))).once();
|
|
177
193
|
expect(result).toEqual(
|
|
178
194
|
new Map([
|
|
179
195
|
['wat', [{ id: 'wat' }]],
|
|
180
196
|
['why', [{ id: 'why' }]],
|
|
181
|
-
])
|
|
197
|
+
]),
|
|
182
198
|
);
|
|
183
199
|
});
|
|
184
200
|
|
|
@@ -191,6 +207,46 @@ describe(ReadThroughEntityCache, () => {
|
|
|
191
207
|
verify(cacheAdapterMock.loadManyAsync('id', anything())).never();
|
|
192
208
|
expect(result).toEqual(new Map([['wat', [{ id: 'wat' }]]]));
|
|
193
209
|
});
|
|
210
|
+
|
|
211
|
+
it('does not cache when DB returns multiple objects for what is supposed to be unique and returns empty', async () => {
|
|
212
|
+
const consoleSpy = jest.spyOn(console, 'warn');
|
|
213
|
+
|
|
214
|
+
const cacheAdapterMock = mock<IEntityCacheAdapter<BlahFields>>();
|
|
215
|
+
const cacheAdapter = instance(cacheAdapterMock);
|
|
216
|
+
const entityCache = new ReadThroughEntityCache(makeEntityConfiguration(true), cacheAdapter);
|
|
217
|
+
const fetcher = createFetcherNonUnique(['wat', 'who']);
|
|
218
|
+
|
|
219
|
+
when(cacheAdapterMock.loadManyAsync('id', deepEqual(['wat', 'who']))).thenResolve(
|
|
220
|
+
new Map([
|
|
221
|
+
['wat', { status: CacheStatus.MISS }],
|
|
222
|
+
['who', { status: CacheStatus.MISS }],
|
|
223
|
+
]),
|
|
224
|
+
);
|
|
225
|
+
|
|
226
|
+
const result = await entityCache.readManyThroughAsync('id', ['wat', 'who'], fetcher);
|
|
227
|
+
|
|
228
|
+
verify(cacheAdapterMock.loadManyAsync('id', deepEqual(['wat', 'who']))).once();
|
|
229
|
+
verify(
|
|
230
|
+
cacheAdapterMock.cacheManyAsync(
|
|
231
|
+
'id',
|
|
232
|
+
deepEqual(
|
|
233
|
+
new Map([
|
|
234
|
+
['wat', { id: 'wat' }],
|
|
235
|
+
['who', { id: 'who' }],
|
|
236
|
+
]),
|
|
237
|
+
),
|
|
238
|
+
),
|
|
239
|
+
).never();
|
|
240
|
+
verify(cacheAdapterMock.cacheDBMissesAsync('id', deepEqual([]))).once();
|
|
241
|
+
expect(result).toEqual(new Map());
|
|
242
|
+
|
|
243
|
+
expect(consoleSpy).toHaveBeenCalledWith(
|
|
244
|
+
'unique key id in blah returned multiple rows for wat',
|
|
245
|
+
);
|
|
246
|
+
expect(consoleSpy).toHaveBeenCalledWith(
|
|
247
|
+
'unique key id in blah returned multiple rows for who',
|
|
248
|
+
);
|
|
249
|
+
});
|
|
194
250
|
});
|
|
195
251
|
|
|
196
252
|
describe('invalidateManyAsync', () => {
|
|
@@ -8,7 +8,7 @@ export const timeAndLogLoadEventAsync =
|
|
|
8
8
|
(
|
|
9
9
|
metricsAdapter: IEntityMetricsAdapter,
|
|
10
10
|
loadType: EntityMetricsLoadType,
|
|
11
|
-
entityClassName: string
|
|
11
|
+
entityClassName: string,
|
|
12
12
|
) =>
|
|
13
13
|
async <TFields>(promise: Promise<readonly Readonly<TFields>[]>) => {
|
|
14
14
|
const startTime = Date.now();
|
|
@@ -29,10 +29,10 @@ export const timeAndLogLoadMapEventAsync =
|
|
|
29
29
|
(
|
|
30
30
|
metricsAdapter: IEntityMetricsAdapter,
|
|
31
31
|
loadType: EntityMetricsLoadType,
|
|
32
|
-
entityClassName: string
|
|
32
|
+
entityClassName: string,
|
|
33
33
|
) =>
|
|
34
34
|
async <TFields, N extends keyof TFields>(
|
|
35
|
-
promise: Promise<ReadonlyMap<NonNullable<TFields[N]>, readonly Readonly<TFields>[]
|
|
35
|
+
promise: Promise<ReadonlyMap<NonNullable<TFields[N]>, readonly Readonly<TFields>[]>>,
|
|
36
36
|
) => {
|
|
37
37
|
const startTime = Date.now();
|
|
38
38
|
const result = await promise;
|
|
@@ -54,7 +54,7 @@ export const timeAndLogMutationEventAsync =
|
|
|
54
54
|
(
|
|
55
55
|
metricsAdapter: IEntityMetricsAdapter,
|
|
56
56
|
mutationType: EntityMetricsMutationType,
|
|
57
|
-
entityClassName: string
|
|
57
|
+
entityClassName: string,
|
|
58
58
|
) =>
|
|
59
59
|
async <T>(promise: Promise<T>) => {
|
|
60
60
|
const startTime = Date.now();
|
|
@@ -140,7 +140,7 @@ export default interface IEntityMetricsAdapter {
|
|
|
140
140
|
* Called when a dataloader, cache, or database load is initiated via the standard
|
|
141
141
|
* load methods (not equality conjunction or raw). Most commonly used for logging
|
|
142
142
|
* a waterfall to determine dataloader and cache hit rates and ratios.
|
|
143
|
-
* @param
|
|
143
|
+
* @param incrementLoadCountEvent - count of field values being loaded for a field
|
|
144
144
|
*/
|
|
145
145
|
incrementDataManagerLoadCount(incrementLoadCountEvent: IncrementLoadCountEvent): void;
|
|
146
146
|
}
|
|
@@ -12,13 +12,19 @@ export default class AlwaysAllowPrivacyPolicyRule<
|
|
|
12
12
|
TID extends NonNullable<TFields[TSelectedFields]>,
|
|
13
13
|
TViewerContext extends ViewerContext,
|
|
14
14
|
TEntity extends ReadonlyEntity<TFields, TID, TViewerContext, TSelectedFields>,
|
|
15
|
-
TSelectedFields extends keyof TFields = keyof TFields
|
|
15
|
+
TSelectedFields extends keyof TFields = keyof TFields,
|
|
16
16
|
> extends PrivacyPolicyRule<TFields, TID, TViewerContext, TEntity, TSelectedFields> {
|
|
17
17
|
async evaluateAsync(
|
|
18
18
|
_viewerContext: TViewerContext,
|
|
19
19
|
_queryContext: EntityQueryContext,
|
|
20
|
-
_evaluationContext: EntityPrivacyPolicyEvaluationContext
|
|
21
|
-
|
|
20
|
+
_evaluationContext: EntityPrivacyPolicyEvaluationContext<
|
|
21
|
+
TFields,
|
|
22
|
+
TID,
|
|
23
|
+
TViewerContext,
|
|
24
|
+
TEntity,
|
|
25
|
+
TSelectedFields
|
|
26
|
+
>,
|
|
27
|
+
_entity: TEntity,
|
|
22
28
|
): Promise<RuleEvaluationResult> {
|
|
23
29
|
return RuleEvaluationResult.ALLOW;
|
|
24
30
|
}
|
|
@@ -12,13 +12,19 @@ export default class AlwaysDenyPrivacyPolicyRule<
|
|
|
12
12
|
TID extends NonNullable<TFields[TSelectedFields]>,
|
|
13
13
|
TViewerContext extends ViewerContext,
|
|
14
14
|
TEntity extends ReadonlyEntity<TFields, TID, TViewerContext, TSelectedFields>,
|
|
15
|
-
TSelectedFields extends keyof TFields = keyof TFields
|
|
15
|
+
TSelectedFields extends keyof TFields = keyof TFields,
|
|
16
16
|
> extends PrivacyPolicyRule<TFields, TID, TViewerContext, TEntity, TSelectedFields> {
|
|
17
17
|
async evaluateAsync(
|
|
18
18
|
_viewerContext: TViewerContext,
|
|
19
19
|
_queryContext: EntityQueryContext,
|
|
20
|
-
_evaluationContext: EntityPrivacyPolicyEvaluationContext
|
|
21
|
-
|
|
20
|
+
_evaluationContext: EntityPrivacyPolicyEvaluationContext<
|
|
21
|
+
TFields,
|
|
22
|
+
TID,
|
|
23
|
+
TViewerContext,
|
|
24
|
+
TEntity,
|
|
25
|
+
TSelectedFields
|
|
26
|
+
>,
|
|
27
|
+
_entity: TEntity,
|
|
22
28
|
): Promise<RuleEvaluationResult> {
|
|
23
29
|
return RuleEvaluationResult.DENY;
|
|
24
30
|
}
|
|
@@ -12,13 +12,19 @@ export default class AlwaysSkipPrivacyPolicyRule<
|
|
|
12
12
|
TID extends NonNullable<TFields[TSelectedFields]>,
|
|
13
13
|
TViewerContext extends ViewerContext,
|
|
14
14
|
TEntity extends ReadonlyEntity<TFields, TID, TViewerContext, TSelectedFields>,
|
|
15
|
-
TSelectedFields extends keyof TFields = keyof TFields
|
|
15
|
+
TSelectedFields extends keyof TFields = keyof TFields,
|
|
16
16
|
> extends PrivacyPolicyRule<TFields, TID, TViewerContext, TEntity, TSelectedFields> {
|
|
17
17
|
async evaluateAsync(
|
|
18
18
|
_viewerContext: TViewerContext,
|
|
19
19
|
_queryContext: EntityQueryContext,
|
|
20
|
-
_evaluationContext: EntityPrivacyPolicyEvaluationContext
|
|
21
|
-
|
|
20
|
+
_evaluationContext: EntityPrivacyPolicyEvaluationContext<
|
|
21
|
+
TFields,
|
|
22
|
+
TID,
|
|
23
|
+
TViewerContext,
|
|
24
|
+
TEntity,
|
|
25
|
+
TSelectedFields
|
|
26
|
+
>,
|
|
27
|
+
_entity: TEntity,
|
|
22
28
|
): Promise<RuleEvaluationResult> {
|
|
23
29
|
return RuleEvaluationResult.SKIP;
|
|
24
30
|
}
|
|
@@ -41,12 +41,18 @@ export default abstract class PrivacyPolicyRule<
|
|
|
41
41
|
TID extends NonNullable<TFields[TSelectedFields]>,
|
|
42
42
|
TViewerContext extends ViewerContext,
|
|
43
43
|
TEntity extends ReadonlyEntity<TFields, TID, TViewerContext, TSelectedFields>,
|
|
44
|
-
TSelectedFields extends keyof TFields = keyof TFields
|
|
44
|
+
TSelectedFields extends keyof TFields = keyof TFields,
|
|
45
45
|
> {
|
|
46
46
|
abstract evaluateAsync(
|
|
47
47
|
viewerContext: TViewerContext,
|
|
48
48
|
queryContext: EntityQueryContext,
|
|
49
|
-
evaluationContext: EntityPrivacyPolicyEvaluationContext
|
|
50
|
-
|
|
49
|
+
evaluationContext: EntityPrivacyPolicyEvaluationContext<
|
|
50
|
+
TFields,
|
|
51
|
+
TID,
|
|
52
|
+
TViewerContext,
|
|
53
|
+
TEntity,
|
|
54
|
+
TSelectedFields
|
|
55
|
+
>,
|
|
56
|
+
entity: TEntity,
|
|
51
57
|
): Promise<RuleEvaluationResult>;
|
|
52
58
|
}
|
|
@@ -11,7 +11,8 @@ describePrivacyPolicyRule(new AlwaysAllowPrivacyPolicyRule(), {
|
|
|
11
11
|
{
|
|
12
12
|
viewerContext: instance(mock(ViewerContext)),
|
|
13
13
|
queryContext: instance(mock(EntityQueryContext)),
|
|
14
|
-
evaluationContext:
|
|
14
|
+
evaluationContext:
|
|
15
|
+
instance(mock<EntityPrivacyPolicyEvaluationContext<any, any, any, any, any>>()),
|
|
15
16
|
entity: anything(),
|
|
16
17
|
},
|
|
17
18
|
],
|
|
@@ -11,7 +11,8 @@ describePrivacyPolicyRule(new AlwaysDenyPrivacyPolicyRule(), {
|
|
|
11
11
|
{
|
|
12
12
|
viewerContext: instance(mock(ViewerContext)),
|
|
13
13
|
queryContext: instance(mock(EntityQueryContext)),
|
|
14
|
-
evaluationContext:
|
|
14
|
+
evaluationContext:
|
|
15
|
+
instance(mock<EntityPrivacyPolicyEvaluationContext<any, any, any, any, any>>()),
|
|
15
16
|
entity: anything(),
|
|
16
17
|
},
|
|
17
18
|
],
|
|
@@ -11,7 +11,8 @@ describePrivacyPolicyRule(new AlwaysSkipPrivacyPolicyRule(), {
|
|
|
11
11
|
{
|
|
12
12
|
viewerContext: instance(mock(ViewerContext)),
|
|
13
13
|
queryContext: instance(mock(EntityQueryContext)),
|
|
14
|
-
evaluationContext:
|
|
14
|
+
evaluationContext:
|
|
15
|
+
instance(mock<EntityPrivacyPolicyEvaluationContext<any, any, any, any, any>>()),
|
|
15
16
|
entity: anything(),
|
|
16
17
|
},
|
|
17
18
|
],
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import Entity from '../Entity';
|
|
2
|
+
import { EntityCompanionDefinition } from '../EntityCompanionProvider';
|
|
3
|
+
import EntityConfiguration from '../EntityConfiguration';
|
|
4
|
+
import { StringField, UUIDField } from '../EntityFields';
|
|
5
|
+
import { EntityTriggerMutationInfo } from '../EntityMutationInfo';
|
|
6
|
+
import {
|
|
7
|
+
EntityMutationTrigger,
|
|
8
|
+
EntityNonTransactionalMutationTrigger,
|
|
9
|
+
} from '../EntityMutationTriggerConfiguration';
|
|
10
|
+
import EntityPrivacyPolicy from '../EntityPrivacyPolicy';
|
|
11
|
+
import { EntityQueryContext } from '../EntityQueryContext';
|
|
12
|
+
import ViewerContext from '../ViewerContext';
|
|
13
|
+
import AlwaysAllowPrivacyPolicyRule from '../rules/AlwaysAllowPrivacyPolicyRule';
|
|
14
|
+
|
|
15
|
+
export type TestMTFields = {
|
|
16
|
+
id: string;
|
|
17
|
+
stringField: string;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export const testEntityMTConfiguration = new EntityConfiguration<TestMTFields>({
|
|
21
|
+
idField: 'id',
|
|
22
|
+
tableName: 'test_entity_should_not_write_to_db_3',
|
|
23
|
+
schema: {
|
|
24
|
+
id: new UUIDField({
|
|
25
|
+
columnName: 'id',
|
|
26
|
+
}),
|
|
27
|
+
stringField: new StringField({
|
|
28
|
+
columnName: 'string_field',
|
|
29
|
+
}),
|
|
30
|
+
},
|
|
31
|
+
databaseAdapterFlavor: 'postgres',
|
|
32
|
+
cacheAdapterFlavor: 'redis',
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
export class TestEntityMTPrivacyPolicy extends EntityPrivacyPolicy<
|
|
36
|
+
TestMTFields,
|
|
37
|
+
string,
|
|
38
|
+
ViewerContext,
|
|
39
|
+
TestEntityWithMutationTriggers
|
|
40
|
+
> {
|
|
41
|
+
protected override readonly readRules = [
|
|
42
|
+
new AlwaysAllowPrivacyPolicyRule<
|
|
43
|
+
TestMTFields,
|
|
44
|
+
string,
|
|
45
|
+
ViewerContext,
|
|
46
|
+
TestEntityWithMutationTriggers
|
|
47
|
+
>(),
|
|
48
|
+
];
|
|
49
|
+
protected override readonly createRules = [
|
|
50
|
+
new AlwaysAllowPrivacyPolicyRule<
|
|
51
|
+
TestMTFields,
|
|
52
|
+
string,
|
|
53
|
+
ViewerContext,
|
|
54
|
+
TestEntityWithMutationTriggers
|
|
55
|
+
>(),
|
|
56
|
+
];
|
|
57
|
+
protected override readonly updateRules = [
|
|
58
|
+
new AlwaysAllowPrivacyPolicyRule<
|
|
59
|
+
TestMTFields,
|
|
60
|
+
string,
|
|
61
|
+
ViewerContext,
|
|
62
|
+
TestEntityWithMutationTriggers
|
|
63
|
+
>(),
|
|
64
|
+
];
|
|
65
|
+
protected override readonly deleteRules = [
|
|
66
|
+
new AlwaysAllowPrivacyPolicyRule<
|
|
67
|
+
TestMTFields,
|
|
68
|
+
string,
|
|
69
|
+
ViewerContext,
|
|
70
|
+
TestEntityWithMutationTriggers
|
|
71
|
+
>(),
|
|
72
|
+
];
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export class TestMutationTrigger extends EntityMutationTrigger<
|
|
76
|
+
TestMTFields,
|
|
77
|
+
string,
|
|
78
|
+
ViewerContext,
|
|
79
|
+
TestEntityWithMutationTriggers,
|
|
80
|
+
keyof TestMTFields
|
|
81
|
+
> {
|
|
82
|
+
constructor(
|
|
83
|
+
// @ts-expect-error key is never used but is helpful for debugging
|
|
84
|
+
private readonly key: string,
|
|
85
|
+
) {
|
|
86
|
+
super();
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
async executeAsync(
|
|
90
|
+
_viewerContext: ViewerContext,
|
|
91
|
+
_queryContext: EntityQueryContext,
|
|
92
|
+
_entity: TestEntityWithMutationTriggers,
|
|
93
|
+
_mutationInfo: EntityTriggerMutationInfo<
|
|
94
|
+
TestMTFields,
|
|
95
|
+
string,
|
|
96
|
+
ViewerContext,
|
|
97
|
+
TestEntityWithMutationTriggers,
|
|
98
|
+
keyof TestMTFields
|
|
99
|
+
>,
|
|
100
|
+
): Promise<void> {}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export class NonTransactionalTestMutationTrigger extends EntityNonTransactionalMutationTrigger<
|
|
104
|
+
TestMTFields,
|
|
105
|
+
string,
|
|
106
|
+
ViewerContext,
|
|
107
|
+
TestEntityWithMutationTriggers,
|
|
108
|
+
keyof TestMTFields
|
|
109
|
+
> {
|
|
110
|
+
constructor(
|
|
111
|
+
// @ts-expect-error key is never used but is helpful for debugging
|
|
112
|
+
private readonly key: string,
|
|
113
|
+
) {
|
|
114
|
+
super();
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
async executeAsync(
|
|
118
|
+
_viewerContext: ViewerContext,
|
|
119
|
+
_entity: TestEntityWithMutationTriggers,
|
|
120
|
+
_mutationInfo: EntityTriggerMutationInfo<
|
|
121
|
+
TestMTFields,
|
|
122
|
+
string,
|
|
123
|
+
ViewerContext,
|
|
124
|
+
TestEntityWithMutationTriggers,
|
|
125
|
+
keyof TestMTFields
|
|
126
|
+
>,
|
|
127
|
+
): Promise<void> {}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* A test Entity that has one afterCreate and one afterAll trigger
|
|
132
|
+
*/
|
|
133
|
+
export default class TestEntityWithMutationTriggers extends Entity<
|
|
134
|
+
TestMTFields,
|
|
135
|
+
string,
|
|
136
|
+
ViewerContext
|
|
137
|
+
> {
|
|
138
|
+
static defineCompanionDefinition(): EntityCompanionDefinition<
|
|
139
|
+
TestMTFields,
|
|
140
|
+
string,
|
|
141
|
+
ViewerContext,
|
|
142
|
+
TestEntityWithMutationTriggers,
|
|
143
|
+
TestEntityMTPrivacyPolicy
|
|
144
|
+
> {
|
|
145
|
+
return {
|
|
146
|
+
entityClass: TestEntityWithMutationTriggers,
|
|
147
|
+
entityConfiguration: testEntityMTConfiguration,
|
|
148
|
+
privacyPolicyClass: TestEntityMTPrivacyPolicy,
|
|
149
|
+
mutationTriggers: {
|
|
150
|
+
afterCreate: [new TestMutationTrigger('localAfterCreate')],
|
|
151
|
+
afterAll: [new TestMutationTrigger('localAfterAll')],
|
|
152
|
+
afterCommit: [new NonTransactionalTestMutationTrigger('localAfterCommit')],
|
|
153
|
+
},
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
}
|