@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
package/src/EntityMutator.ts
CHANGED
|
@@ -20,7 +20,6 @@ import EntityMutationTriggerConfiguration, {
|
|
|
20
20
|
import EntityMutationValidator from './EntityMutationValidator';
|
|
21
21
|
import EntityPrivacyPolicy from './EntityPrivacyPolicy';
|
|
22
22
|
import { EntityQueryContext, EntityTransactionalQueryContext } from './EntityQueryContext';
|
|
23
|
-
import ReadonlyEntity from './ReadonlyEntity';
|
|
24
23
|
import ViewerContext from './ViewerContext';
|
|
25
24
|
import EntityInvalidFieldValueError from './errors/EntityInvalidFieldValueError';
|
|
26
25
|
import { timeAndLogMutationEventAsync } from './metrics/EntityMetricsUtils';
|
|
@@ -39,7 +38,7 @@ abstract class BaseMutator<
|
|
|
39
38
|
TEntity,
|
|
40
39
|
TSelectedFields
|
|
41
40
|
>,
|
|
42
|
-
TSelectedFields extends keyof TFields
|
|
41
|
+
TSelectedFields extends keyof TFields,
|
|
43
42
|
> {
|
|
44
43
|
constructor(
|
|
45
44
|
protected readonly companionProvider: EntityCompanionProvider,
|
|
@@ -78,7 +77,7 @@ abstract class BaseMutator<
|
|
|
78
77
|
TSelectedFields
|
|
79
78
|
>,
|
|
80
79
|
protected readonly databaseAdapter: EntityDatabaseAdapter<TFields>,
|
|
81
|
-
protected readonly metricsAdapter: IEntityMetricsAdapter
|
|
80
|
+
protected readonly metricsAdapter: IEntityMetricsAdapter,
|
|
82
81
|
) {}
|
|
83
82
|
|
|
84
83
|
protected validateFields(fields: Partial<TFields>): void {
|
|
@@ -103,12 +102,12 @@ abstract class BaseMutator<
|
|
|
103
102
|
TViewerContext,
|
|
104
103
|
TEntity,
|
|
105
104
|
TSelectedFields
|
|
106
|
-
|
|
105
|
+
>,
|
|
107
106
|
): Promise<void> {
|
|
108
107
|
await Promise.all(
|
|
109
108
|
validators.map((validator) =>
|
|
110
|
-
validator.executeAsync(this.viewerContext, queryContext, entity, mutationInfo)
|
|
111
|
-
)
|
|
109
|
+
validator.executeAsync(this.viewerContext, queryContext, entity, mutationInfo),
|
|
110
|
+
),
|
|
112
111
|
);
|
|
113
112
|
}
|
|
114
113
|
|
|
@@ -118,15 +117,15 @@ abstract class BaseMutator<
|
|
|
118
117
|
| undefined,
|
|
119
118
|
queryContext: EntityTransactionalQueryContext,
|
|
120
119
|
entity: TEntity,
|
|
121
|
-
mutationInfo: EntityTriggerMutationInfo<TFields, TID, TViewerContext, TEntity, TSelectedFields
|
|
120
|
+
mutationInfo: EntityTriggerMutationInfo<TFields, TID, TViewerContext, TEntity, TSelectedFields>,
|
|
122
121
|
): Promise<void> {
|
|
123
122
|
if (!triggers) {
|
|
124
123
|
return;
|
|
125
124
|
}
|
|
126
125
|
await Promise.all(
|
|
127
126
|
triggers.map((trigger) =>
|
|
128
|
-
trigger.executeAsync(this.viewerContext, queryContext, entity, mutationInfo)
|
|
129
|
-
)
|
|
127
|
+
trigger.executeAsync(this.viewerContext, queryContext, entity, mutationInfo),
|
|
128
|
+
),
|
|
130
129
|
);
|
|
131
130
|
}
|
|
132
131
|
|
|
@@ -141,13 +140,13 @@ abstract class BaseMutator<
|
|
|
141
140
|
>[]
|
|
142
141
|
| undefined,
|
|
143
142
|
entity: TEntity,
|
|
144
|
-
mutationInfo: EntityTriggerMutationInfo<TFields, TID, TViewerContext, TEntity, TSelectedFields
|
|
143
|
+
mutationInfo: EntityTriggerMutationInfo<TFields, TID, TViewerContext, TEntity, TSelectedFields>,
|
|
145
144
|
): Promise<void> {
|
|
146
145
|
if (!triggers) {
|
|
147
146
|
return;
|
|
148
147
|
}
|
|
149
148
|
await Promise.all(
|
|
150
|
-
triggers.map((trigger) => trigger.executeAsync(this.viewerContext, entity, mutationInfo))
|
|
149
|
+
triggers.map((trigger) => trigger.executeAsync(this.viewerContext, entity, mutationInfo)),
|
|
151
150
|
);
|
|
152
151
|
}
|
|
153
152
|
}
|
|
@@ -167,7 +166,7 @@ export class CreateMutator<
|
|
|
167
166
|
TEntity,
|
|
168
167
|
TSelectedFields
|
|
169
168
|
>,
|
|
170
|
-
TSelectedFields extends keyof TFields
|
|
169
|
+
TSelectedFields extends keyof TFields,
|
|
171
170
|
> extends BaseMutator<TFields, TID, TViewerContext, TEntity, TPrivacyPolicy, TSelectedFields> {
|
|
172
171
|
private readonly fieldsForEntity: Partial<TFields> = {};
|
|
173
172
|
|
|
@@ -190,7 +189,7 @@ export class CreateMutator<
|
|
|
190
189
|
return await timeAndLogMutationEventAsync(
|
|
191
190
|
this.metricsAdapter,
|
|
192
191
|
EntityMetricsMutationType.CREATE,
|
|
193
|
-
this.entityClass.name
|
|
192
|
+
this.entityClass.name,
|
|
194
193
|
)(this.createInTransactionAsync());
|
|
195
194
|
}
|
|
196
195
|
|
|
@@ -203,20 +202,21 @@ export class CreateMutator<
|
|
|
203
202
|
|
|
204
203
|
private async createInTransactionAsync(): Promise<Result<TEntity>> {
|
|
205
204
|
return await this.queryContext.runInTransactionIfNotInTransactionAsync((innerQueryContext) =>
|
|
206
|
-
this.createInternalAsync(innerQueryContext)
|
|
205
|
+
this.createInternalAsync(innerQueryContext),
|
|
207
206
|
);
|
|
208
207
|
}
|
|
209
208
|
|
|
210
209
|
private async createInternalAsync(
|
|
211
|
-
queryContext: EntityTransactionalQueryContext
|
|
210
|
+
queryContext: EntityTransactionalQueryContext,
|
|
212
211
|
): Promise<Result<TEntity>> {
|
|
213
212
|
this.validateFields(this.fieldsForEntity);
|
|
214
213
|
|
|
215
214
|
const entityLoader = this.entityLoaderFactory.forLoad(this.viewerContext, queryContext, {
|
|
215
|
+
previousValue: null,
|
|
216
216
|
cascadingDeleteCause: null,
|
|
217
217
|
});
|
|
218
218
|
|
|
219
|
-
const temporaryEntityForPrivacyCheck = entityLoader.constructEntity({
|
|
219
|
+
const temporaryEntityForPrivacyCheck = entityLoader.utils().constructEntity({
|
|
220
220
|
[this.entityConfiguration.idField]: '00000000-0000-0000-0000-000000000000', // zero UUID
|
|
221
221
|
...this.fieldsForEntity,
|
|
222
222
|
} as unknown as TFields);
|
|
@@ -225,10 +225,10 @@ export class CreateMutator<
|
|
|
225
225
|
this.privacyPolicy.authorizeCreateAsync(
|
|
226
226
|
this.viewerContext,
|
|
227
227
|
queryContext,
|
|
228
|
-
{ cascadingDeleteCause: null },
|
|
228
|
+
{ previousValue: null, cascadingDeleteCause: null },
|
|
229
229
|
temporaryEntityForPrivacyCheck,
|
|
230
|
-
this.metricsAdapter
|
|
231
|
-
)
|
|
230
|
+
this.metricsAdapter,
|
|
231
|
+
),
|
|
232
232
|
);
|
|
233
233
|
if (!authorizeCreateResult.ok) {
|
|
234
234
|
return authorizeCreateResult;
|
|
@@ -238,28 +238,28 @@ export class CreateMutator<
|
|
|
238
238
|
this.mutationValidators,
|
|
239
239
|
queryContext,
|
|
240
240
|
temporaryEntityForPrivacyCheck,
|
|
241
|
-
{ type: EntityMutationType.CREATE }
|
|
241
|
+
{ type: EntityMutationType.CREATE },
|
|
242
242
|
);
|
|
243
243
|
await this.executeMutationTriggersAsync(
|
|
244
244
|
this.mutationTriggers.beforeAll,
|
|
245
245
|
queryContext,
|
|
246
246
|
temporaryEntityForPrivacyCheck,
|
|
247
|
-
{ type: EntityMutationType.CREATE }
|
|
247
|
+
{ type: EntityMutationType.CREATE },
|
|
248
248
|
);
|
|
249
249
|
await this.executeMutationTriggersAsync(
|
|
250
250
|
this.mutationTriggers.beforeCreate,
|
|
251
251
|
queryContext,
|
|
252
252
|
temporaryEntityForPrivacyCheck,
|
|
253
|
-
{ type: EntityMutationType.CREATE }
|
|
253
|
+
{ type: EntityMutationType.CREATE },
|
|
254
254
|
);
|
|
255
255
|
|
|
256
256
|
const insertResult = await this.databaseAdapter.insertAsync(queryContext, this.fieldsForEntity);
|
|
257
257
|
|
|
258
258
|
queryContext.appendPostCommitInvalidationCallback(
|
|
259
|
-
entityLoader.invalidateFieldsAsync.bind(entityLoader, insertResult)
|
|
259
|
+
entityLoader.utils().invalidateFieldsAsync.bind(entityLoader, insertResult),
|
|
260
260
|
);
|
|
261
261
|
|
|
262
|
-
const unauthorizedEntityAfterInsert = entityLoader.constructEntity(insertResult);
|
|
262
|
+
const unauthorizedEntityAfterInsert = entityLoader.utils().constructEntity(insertResult);
|
|
263
263
|
const newEntity = await entityLoader
|
|
264
264
|
.enforcing()
|
|
265
265
|
.loadByIDAsync(unauthorizedEntityAfterInsert.getID());
|
|
@@ -268,13 +268,13 @@ export class CreateMutator<
|
|
|
268
268
|
this.mutationTriggers.afterCreate,
|
|
269
269
|
queryContext,
|
|
270
270
|
newEntity,
|
|
271
|
-
{ type: EntityMutationType.CREATE }
|
|
271
|
+
{ type: EntityMutationType.CREATE },
|
|
272
272
|
);
|
|
273
273
|
await this.executeMutationTriggersAsync(
|
|
274
274
|
this.mutationTriggers.afterAll,
|
|
275
275
|
queryContext,
|
|
276
276
|
newEntity,
|
|
277
|
-
{ type: EntityMutationType.CREATE }
|
|
277
|
+
{ type: EntityMutationType.CREATE },
|
|
278
278
|
);
|
|
279
279
|
|
|
280
280
|
queryContext.appendPostCommitCallback(
|
|
@@ -282,8 +282,8 @@ export class CreateMutator<
|
|
|
282
282
|
this,
|
|
283
283
|
this.mutationTriggers.afterCommit,
|
|
284
284
|
newEntity,
|
|
285
|
-
{ type: EntityMutationType.CREATE }
|
|
286
|
-
)
|
|
285
|
+
{ type: EntityMutationType.CREATE },
|
|
286
|
+
),
|
|
287
287
|
);
|
|
288
288
|
|
|
289
289
|
return result(newEntity);
|
|
@@ -305,7 +305,7 @@ export class UpdateMutator<
|
|
|
305
305
|
TEntity,
|
|
306
306
|
TSelectedFields
|
|
307
307
|
>,
|
|
308
|
-
TSelectedFields extends keyof TFields
|
|
308
|
+
TSelectedFields extends keyof TFields,
|
|
309
309
|
> extends BaseMutator<TFields, TID, TViewerContext, TEntity, TPrivacyPolicy, TSelectedFields> {
|
|
310
310
|
private readonly originalEntity: TEntity;
|
|
311
311
|
private readonly fieldsForEntity: TFields;
|
|
@@ -349,7 +349,7 @@ export class UpdateMutator<
|
|
|
349
349
|
>,
|
|
350
350
|
databaseAdapter: EntityDatabaseAdapter<TFields>,
|
|
351
351
|
metricsAdapter: IEntityMetricsAdapter,
|
|
352
|
-
originalEntity: TEntity
|
|
352
|
+
originalEntity: TEntity,
|
|
353
353
|
) {
|
|
354
354
|
super(
|
|
355
355
|
companionProvider,
|
|
@@ -362,7 +362,7 @@ export class UpdateMutator<
|
|
|
362
362
|
mutationTriggers,
|
|
363
363
|
entityLoaderFactory,
|
|
364
364
|
databaseAdapter,
|
|
365
|
-
metricsAdapter
|
|
365
|
+
metricsAdapter,
|
|
366
366
|
);
|
|
367
367
|
this.originalEntity = originalEntity;
|
|
368
368
|
this.fieldsForEntity = { ...originalEntity.getAllDatabaseFields() };
|
|
@@ -388,7 +388,7 @@ export class UpdateMutator<
|
|
|
388
388
|
return await timeAndLogMutationEventAsync(
|
|
389
389
|
this.metricsAdapter,
|
|
390
390
|
EntityMetricsMutationType.UPDATE,
|
|
391
|
-
this.entityClass.name
|
|
391
|
+
this.entityClass.name,
|
|
392
392
|
)(this.updateInTransactionAsync(false, null));
|
|
393
393
|
}
|
|
394
394
|
|
|
@@ -401,41 +401,43 @@ export class UpdateMutator<
|
|
|
401
401
|
|
|
402
402
|
private async updateInTransactionAsync(
|
|
403
403
|
skipDatabaseUpdate: true,
|
|
404
|
-
cascadingDeleteCause: EntityCascadingDeletionInfo
|
|
404
|
+
cascadingDeleteCause: EntityCascadingDeletionInfo,
|
|
405
405
|
): Promise<Result<TEntity>>;
|
|
406
406
|
private async updateInTransactionAsync(
|
|
407
407
|
skipDatabaseUpdate: false,
|
|
408
|
-
cascadingDeleteCause: EntityCascadingDeletionInfo | null
|
|
408
|
+
cascadingDeleteCause: EntityCascadingDeletionInfo | null,
|
|
409
409
|
): Promise<Result<TEntity>>;
|
|
410
410
|
private async updateInTransactionAsync(
|
|
411
411
|
skipDatabaseUpdate: boolean,
|
|
412
|
-
cascadingDeleteCause: EntityCascadingDeletionInfo | null
|
|
412
|
+
cascadingDeleteCause: EntityCascadingDeletionInfo | null,
|
|
413
413
|
): Promise<Result<TEntity>> {
|
|
414
414
|
return await this.queryContext.runInTransactionIfNotInTransactionAsync((innerQueryContext) =>
|
|
415
|
-
this.updateInternalAsync(innerQueryContext, skipDatabaseUpdate, cascadingDeleteCause)
|
|
415
|
+
this.updateInternalAsync(innerQueryContext, skipDatabaseUpdate, cascadingDeleteCause),
|
|
416
416
|
);
|
|
417
417
|
}
|
|
418
418
|
|
|
419
419
|
private async updateInternalAsync(
|
|
420
420
|
queryContext: EntityTransactionalQueryContext,
|
|
421
421
|
skipDatabaseUpdate: boolean,
|
|
422
|
-
cascadingDeleteCause: EntityCascadingDeletionInfo | null
|
|
422
|
+
cascadingDeleteCause: EntityCascadingDeletionInfo | null,
|
|
423
423
|
): Promise<Result<TEntity>> {
|
|
424
424
|
this.validateFields(this.updatedFields);
|
|
425
|
+
this.ensureStableIDField(this.updatedFields);
|
|
425
426
|
|
|
426
427
|
const entityLoader = this.entityLoaderFactory.forLoad(this.viewerContext, queryContext, {
|
|
428
|
+
previousValue: this.originalEntity,
|
|
427
429
|
cascadingDeleteCause,
|
|
428
430
|
});
|
|
429
431
|
|
|
430
|
-
const entityAboutToBeUpdated = entityLoader.constructEntity(this.fieldsForEntity);
|
|
432
|
+
const entityAboutToBeUpdated = entityLoader.utils().constructEntity(this.fieldsForEntity);
|
|
431
433
|
const authorizeUpdateResult = await asyncResult(
|
|
432
434
|
this.privacyPolicy.authorizeUpdateAsync(
|
|
433
435
|
this.viewerContext,
|
|
434
436
|
queryContext,
|
|
435
|
-
{ cascadingDeleteCause },
|
|
437
|
+
{ previousValue: this.originalEntity, cascadingDeleteCause },
|
|
436
438
|
entityAboutToBeUpdated,
|
|
437
|
-
this.metricsAdapter
|
|
438
|
-
)
|
|
439
|
+
this.metricsAdapter,
|
|
440
|
+
),
|
|
439
441
|
);
|
|
440
442
|
if (!authorizeUpdateResult.ok) {
|
|
441
443
|
return authorizeUpdateResult;
|
|
@@ -445,60 +447,55 @@ export class UpdateMutator<
|
|
|
445
447
|
this.mutationValidators,
|
|
446
448
|
queryContext,
|
|
447
449
|
entityAboutToBeUpdated,
|
|
448
|
-
{ type: EntityMutationType.UPDATE, previousValue: this.originalEntity, cascadingDeleteCause }
|
|
450
|
+
{ type: EntityMutationType.UPDATE, previousValue: this.originalEntity, cascadingDeleteCause },
|
|
449
451
|
);
|
|
450
452
|
await this.executeMutationTriggersAsync(
|
|
451
453
|
this.mutationTriggers.beforeAll,
|
|
452
454
|
queryContext,
|
|
453
455
|
entityAboutToBeUpdated,
|
|
454
|
-
{ type: EntityMutationType.UPDATE, previousValue: this.originalEntity, cascadingDeleteCause }
|
|
456
|
+
{ type: EntityMutationType.UPDATE, previousValue: this.originalEntity, cascadingDeleteCause },
|
|
455
457
|
);
|
|
456
458
|
await this.executeMutationTriggersAsync(
|
|
457
459
|
this.mutationTriggers.beforeUpdate,
|
|
458
460
|
queryContext,
|
|
459
461
|
entityAboutToBeUpdated,
|
|
460
|
-
{ type: EntityMutationType.UPDATE, previousValue: this.originalEntity, cascadingDeleteCause }
|
|
462
|
+
{ type: EntityMutationType.UPDATE, previousValue: this.originalEntity, cascadingDeleteCause },
|
|
461
463
|
);
|
|
462
464
|
|
|
463
465
|
// skip the database update when specified
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
466
|
+
if (!skipDatabaseUpdate) {
|
|
467
|
+
await this.databaseAdapter.updateAsync(
|
|
468
|
+
queryContext,
|
|
469
|
+
this.entityConfiguration.idField,
|
|
470
|
+
entityAboutToBeUpdated.getID(),
|
|
471
|
+
this.updatedFields,
|
|
472
|
+
);
|
|
473
|
+
}
|
|
472
474
|
|
|
473
475
|
queryContext.appendPostCommitInvalidationCallback(
|
|
474
|
-
entityLoader
|
|
475
|
-
|
|
476
|
-
this.originalEntity.getAllDatabaseFields()
|
|
477
|
-
)
|
|
476
|
+
entityLoader
|
|
477
|
+
.utils()
|
|
478
|
+
.invalidateFieldsAsync.bind(entityLoader, this.originalEntity.getAllDatabaseFields()),
|
|
478
479
|
);
|
|
479
480
|
queryContext.appendPostCommitInvalidationCallback(
|
|
480
|
-
entityLoader.invalidateFieldsAsync.bind(entityLoader, this.fieldsForEntity)
|
|
481
|
+
entityLoader.utils().invalidateFieldsAsync.bind(entityLoader, this.fieldsForEntity),
|
|
481
482
|
);
|
|
482
483
|
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
? await entityLoader
|
|
487
|
-
.enforcing()
|
|
488
|
-
.loadByIDAsync(entityLoader.constructEntity(updateResult).getID())
|
|
489
|
-
: entityAboutToBeUpdated;
|
|
484
|
+
const updatedEntity = await entityLoader
|
|
485
|
+
.enforcing()
|
|
486
|
+
.loadByIDAsync(entityAboutToBeUpdated.getID()); // ID is guaranteed to be stable by ensureStableIDField
|
|
490
487
|
|
|
491
488
|
await this.executeMutationTriggersAsync(
|
|
492
489
|
this.mutationTriggers.afterUpdate,
|
|
493
490
|
queryContext,
|
|
494
491
|
updatedEntity,
|
|
495
|
-
{ type: EntityMutationType.UPDATE, previousValue: this.originalEntity, cascadingDeleteCause }
|
|
492
|
+
{ type: EntityMutationType.UPDATE, previousValue: this.originalEntity, cascadingDeleteCause },
|
|
496
493
|
);
|
|
497
494
|
await this.executeMutationTriggersAsync(
|
|
498
495
|
this.mutationTriggers.afterAll,
|
|
499
496
|
queryContext,
|
|
500
497
|
updatedEntity,
|
|
501
|
-
{ type: EntityMutationType.UPDATE, previousValue: this.originalEntity, cascadingDeleteCause }
|
|
498
|
+
{ type: EntityMutationType.UPDATE, previousValue: this.originalEntity, cascadingDeleteCause },
|
|
502
499
|
);
|
|
503
500
|
|
|
504
501
|
queryContext.appendPostCommitCallback(
|
|
@@ -510,12 +507,20 @@ export class UpdateMutator<
|
|
|
510
507
|
type: EntityMutationType.UPDATE,
|
|
511
508
|
previousValue: this.originalEntity,
|
|
512
509
|
cascadingDeleteCause,
|
|
513
|
-
}
|
|
514
|
-
)
|
|
510
|
+
},
|
|
511
|
+
),
|
|
515
512
|
);
|
|
516
513
|
|
|
517
514
|
return result(updatedEntity);
|
|
518
515
|
}
|
|
516
|
+
|
|
517
|
+
private ensureStableIDField(updatedFields: Partial<TFields>): void {
|
|
518
|
+
const originalId = this.originalEntity.getID();
|
|
519
|
+
const idField = this.entityConfiguration.idField;
|
|
520
|
+
if (updatedFields.hasOwnProperty(idField) && originalId !== updatedFields[idField]) {
|
|
521
|
+
throw new Error(`id field updates not supported: (entityClass = ${this.entityClass.name})`);
|
|
522
|
+
}
|
|
523
|
+
}
|
|
519
524
|
}
|
|
520
525
|
|
|
521
526
|
/**
|
|
@@ -533,7 +538,7 @@ export class DeleteMutator<
|
|
|
533
538
|
TEntity,
|
|
534
539
|
TSelectedFields
|
|
535
540
|
>,
|
|
536
|
-
TSelectedFields extends keyof TFields
|
|
541
|
+
TSelectedFields extends keyof TFields,
|
|
537
542
|
> extends BaseMutator<TFields, TID, TViewerContext, TEntity, TPrivacyPolicy, TSelectedFields> {
|
|
538
543
|
constructor(
|
|
539
544
|
companionProvider: EntityCompanionProvider,
|
|
@@ -573,7 +578,7 @@ export class DeleteMutator<
|
|
|
573
578
|
>,
|
|
574
579
|
databaseAdapter: EntityDatabaseAdapter<TFields>,
|
|
575
580
|
metricsAdapter: IEntityMetricsAdapter,
|
|
576
|
-
private readonly entity: TEntity
|
|
581
|
+
private readonly entity: TEntity,
|
|
577
582
|
) {
|
|
578
583
|
super(
|
|
579
584
|
companionProvider,
|
|
@@ -586,7 +591,7 @@ export class DeleteMutator<
|
|
|
586
591
|
mutationTriggers,
|
|
587
592
|
entityLoaderFactory,
|
|
588
593
|
databaseAdapter,
|
|
589
|
-
metricsAdapter
|
|
594
|
+
metricsAdapter,
|
|
590
595
|
);
|
|
591
596
|
}
|
|
592
597
|
|
|
@@ -598,7 +603,7 @@ export class DeleteMutator<
|
|
|
598
603
|
return await timeAndLogMutationEventAsync(
|
|
599
604
|
this.metricsAdapter,
|
|
600
605
|
EntityMetricsMutationType.DELETE,
|
|
601
|
-
this.entityClass.name
|
|
606
|
+
this.entityClass.name,
|
|
602
607
|
)(this.deleteInTransactionAsync(new Set(), false, null));
|
|
603
608
|
}
|
|
604
609
|
|
|
@@ -612,15 +617,15 @@ export class DeleteMutator<
|
|
|
612
617
|
private async deleteInTransactionAsync(
|
|
613
618
|
processedEntityIdentifiersFromTransitiveDeletions: Set<string>,
|
|
614
619
|
skipDatabaseDeletion: boolean,
|
|
615
|
-
cascadingDeleteCause: EntityCascadingDeletionInfo | null
|
|
620
|
+
cascadingDeleteCause: EntityCascadingDeletionInfo | null,
|
|
616
621
|
): Promise<Result<void>> {
|
|
617
622
|
return await this.queryContext.runInTransactionIfNotInTransactionAsync((innerQueryContext) =>
|
|
618
623
|
this.deleteInternalAsync(
|
|
619
624
|
innerQueryContext,
|
|
620
625
|
processedEntityIdentifiersFromTransitiveDeletions,
|
|
621
626
|
skipDatabaseDeletion,
|
|
622
|
-
cascadingDeleteCause
|
|
623
|
-
)
|
|
627
|
+
cascadingDeleteCause,
|
|
628
|
+
),
|
|
624
629
|
);
|
|
625
630
|
}
|
|
626
631
|
|
|
@@ -628,16 +633,16 @@ export class DeleteMutator<
|
|
|
628
633
|
queryContext: EntityTransactionalQueryContext,
|
|
629
634
|
processedEntityIdentifiersFromTransitiveDeletions: Set<string>,
|
|
630
635
|
skipDatabaseDeletion: boolean,
|
|
631
|
-
cascadingDeleteCause: EntityCascadingDeletionInfo | null
|
|
636
|
+
cascadingDeleteCause: EntityCascadingDeletionInfo | null,
|
|
632
637
|
): Promise<Result<void>> {
|
|
633
638
|
const authorizeDeleteResult = await asyncResult(
|
|
634
639
|
this.privacyPolicy.authorizeDeleteAsync(
|
|
635
640
|
this.viewerContext,
|
|
636
641
|
queryContext,
|
|
637
|
-
{ cascadingDeleteCause },
|
|
642
|
+
{ previousValue: null, cascadingDeleteCause },
|
|
638
643
|
this.entity,
|
|
639
|
-
this.metricsAdapter
|
|
640
|
-
)
|
|
644
|
+
this.metricsAdapter,
|
|
645
|
+
),
|
|
641
646
|
);
|
|
642
647
|
if (!authorizeDeleteResult.ok) {
|
|
643
648
|
return authorizeDeleteResult;
|
|
@@ -647,48 +652,51 @@ export class DeleteMutator<
|
|
|
647
652
|
this.entity,
|
|
648
653
|
queryContext,
|
|
649
654
|
processedEntityIdentifiersFromTransitiveDeletions,
|
|
650
|
-
cascadingDeleteCause
|
|
655
|
+
cascadingDeleteCause,
|
|
651
656
|
);
|
|
652
657
|
|
|
653
658
|
await this.executeMutationTriggersAsync(
|
|
654
659
|
this.mutationTriggers.beforeAll,
|
|
655
660
|
queryContext,
|
|
656
661
|
this.entity,
|
|
657
|
-
{ type: EntityMutationType.DELETE, cascadingDeleteCause }
|
|
662
|
+
{ type: EntityMutationType.DELETE, cascadingDeleteCause },
|
|
658
663
|
);
|
|
659
664
|
await this.executeMutationTriggersAsync(
|
|
660
665
|
this.mutationTriggers.beforeDelete,
|
|
661
666
|
queryContext,
|
|
662
667
|
this.entity,
|
|
663
|
-
{ type: EntityMutationType.DELETE, cascadingDeleteCause }
|
|
668
|
+
{ type: EntityMutationType.DELETE, cascadingDeleteCause },
|
|
664
669
|
);
|
|
665
670
|
|
|
666
671
|
if (!skipDatabaseDeletion) {
|
|
667
672
|
await this.databaseAdapter.deleteAsync(
|
|
668
673
|
queryContext,
|
|
669
674
|
this.entityConfiguration.idField,
|
|
670
|
-
this.entity.getID()
|
|
675
|
+
this.entity.getID(),
|
|
671
676
|
);
|
|
672
677
|
}
|
|
673
678
|
|
|
674
679
|
const entityLoader = this.entityLoaderFactory.forLoad(this.viewerContext, queryContext, {
|
|
680
|
+
previousValue: null,
|
|
675
681
|
cascadingDeleteCause,
|
|
676
682
|
});
|
|
677
683
|
queryContext.appendPostCommitInvalidationCallback(
|
|
678
|
-
entityLoader
|
|
684
|
+
entityLoader
|
|
685
|
+
.utils()
|
|
686
|
+
.invalidateFieldsAsync.bind(entityLoader, this.entity.getAllDatabaseFields()),
|
|
679
687
|
);
|
|
680
688
|
|
|
681
689
|
await this.executeMutationTriggersAsync(
|
|
682
690
|
this.mutationTriggers.afterDelete,
|
|
683
691
|
queryContext,
|
|
684
692
|
this.entity,
|
|
685
|
-
{ type: EntityMutationType.DELETE, cascadingDeleteCause }
|
|
693
|
+
{ type: EntityMutationType.DELETE, cascadingDeleteCause },
|
|
686
694
|
);
|
|
687
695
|
await this.executeMutationTriggersAsync(
|
|
688
696
|
this.mutationTriggers.afterAll,
|
|
689
697
|
queryContext,
|
|
690
698
|
this.entity,
|
|
691
|
-
{ type: EntityMutationType.DELETE, cascadingDeleteCause }
|
|
699
|
+
{ type: EntityMutationType.DELETE, cascadingDeleteCause },
|
|
692
700
|
);
|
|
693
701
|
|
|
694
702
|
queryContext.appendPostCommitCallback(
|
|
@@ -696,8 +704,8 @@ export class DeleteMutator<
|
|
|
696
704
|
this,
|
|
697
705
|
this.mutationTriggers.afterCommit,
|
|
698
706
|
this.entity,
|
|
699
|
-
{ type: EntityMutationType.DELETE, cascadingDeleteCause }
|
|
700
|
-
)
|
|
707
|
+
{ type: EntityMutationType.DELETE, cascadingDeleteCause },
|
|
708
|
+
),
|
|
701
709
|
);
|
|
702
710
|
|
|
703
711
|
return result();
|
|
@@ -721,7 +729,7 @@ export class DeleteMutator<
|
|
|
721
729
|
entity: TEntity,
|
|
722
730
|
queryContext: EntityTransactionalQueryContext,
|
|
723
731
|
processedEntityIdentifiers: Set<string>,
|
|
724
|
-
cascadingDeleteCause: EntityCascadingDeletionInfo | null
|
|
732
|
+
cascadingDeleteCause: EntityCascadingDeletionInfo | null,
|
|
725
733
|
): Promise<void> {
|
|
726
734
|
// prevent infinite reference cycles by keeping track of entities already processed
|
|
727
735
|
if (processedEntityIdentifiers.has(entity.getUniqueIdentifier())) {
|
|
@@ -737,12 +745,27 @@ export class DeleteMutator<
|
|
|
737
745
|
TEntity,
|
|
738
746
|
TPrivacyPolicy,
|
|
739
747
|
TSelectedFields
|
|
740
|
-
|
|
748
|
+
>,
|
|
741
749
|
).entityCompanionDefinition;
|
|
742
750
|
const entityConfiguration = companionDefinition.entityConfiguration;
|
|
743
751
|
const inboundEdges = entityConfiguration.inboundEdges;
|
|
752
|
+
|
|
753
|
+
const newCascadingDeleteCause = {
|
|
754
|
+
entity,
|
|
755
|
+
cascadingDeleteCause,
|
|
756
|
+
};
|
|
757
|
+
|
|
744
758
|
await Promise.all(
|
|
745
759
|
inboundEdges.map(async (entityClass) => {
|
|
760
|
+
const loaderFactory = entity
|
|
761
|
+
.getViewerContext()
|
|
762
|
+
.getViewerScopedEntityCompanionForClass(entityClass)
|
|
763
|
+
.getLoaderFactory();
|
|
764
|
+
const mutatorFactory = entity
|
|
765
|
+
.getViewerContext()
|
|
766
|
+
.getViewerScopedEntityCompanionForClass(entityClass)
|
|
767
|
+
.getMutatorFactory();
|
|
768
|
+
|
|
746
769
|
return await mapMapAsync(
|
|
747
770
|
this.companionProvider.getCompanionForEntity(entityClass).entityCompanionDefinition
|
|
748
771
|
.entityConfiguration.schema,
|
|
@@ -753,43 +776,24 @@ export class DeleteMutator<
|
|
|
753
776
|
}
|
|
754
777
|
|
|
755
778
|
const associatedConfiguration = this.companionProvider.getCompanionForEntity(
|
|
756
|
-
association.associatedEntityClass
|
|
779
|
+
association.associatedEntityClass,
|
|
757
780
|
).entityCompanionDefinition.entityConfiguration;
|
|
758
781
|
if (associatedConfiguration !== entityConfiguration) {
|
|
759
782
|
return;
|
|
760
783
|
}
|
|
761
784
|
|
|
762
|
-
const
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
.
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
entity,
|
|
775
|
-
cascadingDeleteCause,
|
|
776
|
-
};
|
|
777
|
-
|
|
778
|
-
let inboundReferenceEntities: readonly ReadonlyEntity<any, any, any, any>[];
|
|
779
|
-
if (associatedEntityLookupByField) {
|
|
780
|
-
inboundReferenceEntities = await loaderFactory
|
|
781
|
-
.forLoad(queryContext, { cascadingDeleteCause: newCascadingDeleteCause })
|
|
782
|
-
.enforcing()
|
|
783
|
-
.loadManyByFieldEqualingAsync(
|
|
784
|
-
fieldName,
|
|
785
|
-
entity.getField(associatedEntityLookupByField as any)
|
|
786
|
-
);
|
|
787
|
-
} else {
|
|
788
|
-
inboundReferenceEntities = await loaderFactory
|
|
789
|
-
.forLoad(queryContext, { cascadingDeleteCause: newCascadingDeleteCause })
|
|
790
|
-
.enforcing()
|
|
791
|
-
.loadManyByFieldEqualingAsync(fieldName, entity.getID());
|
|
792
|
-
}
|
|
785
|
+
const inboundReferenceEntities = await loaderFactory
|
|
786
|
+
.forLoad(queryContext, {
|
|
787
|
+
previousValue: null,
|
|
788
|
+
cascadingDeleteCause: newCascadingDeleteCause,
|
|
789
|
+
})
|
|
790
|
+
.enforcing()
|
|
791
|
+
.loadManyByFieldEqualingAsync(
|
|
792
|
+
fieldName,
|
|
793
|
+
association.associatedEntityLookupByField
|
|
794
|
+
? entity.getField(association.associatedEntityLookupByField as any)
|
|
795
|
+
: entity.getID(),
|
|
796
|
+
);
|
|
793
797
|
|
|
794
798
|
switch (association.edgeDeletionBehavior) {
|
|
795
799
|
case EntityEdgeDeletionBehavior.CASCADE_DELETE_INVALIDATE_CACHE_ONLY: {
|
|
@@ -801,10 +805,10 @@ export class DeleteMutator<
|
|
|
801
805
|
.deleteInTransactionAsync(
|
|
802
806
|
processedEntityIdentifiers,
|
|
803
807
|
/* skipDatabaseDeletion */ true, // deletion is handled by DB
|
|
804
|
-
newCascadingDeleteCause
|
|
805
|
-
)
|
|
806
|
-
)
|
|
807
|
-
)
|
|
808
|
+
newCascadingDeleteCause,
|
|
809
|
+
),
|
|
810
|
+
),
|
|
811
|
+
),
|
|
808
812
|
);
|
|
809
813
|
break;
|
|
810
814
|
}
|
|
@@ -815,12 +819,11 @@ export class DeleteMutator<
|
|
|
815
819
|
mutatorFactory
|
|
816
820
|
.forUpdate(inboundReferenceEntity, queryContext)
|
|
817
821
|
.setField(fieldName, null)
|
|
818
|
-
[
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
)
|
|
822
|
+
[
|
|
823
|
+
'updateInTransactionAsync'
|
|
824
|
+
](/* skipDatabaseUpdate */ true, newCascadingDeleteCause),
|
|
825
|
+
),
|
|
826
|
+
),
|
|
824
827
|
);
|
|
825
828
|
break;
|
|
826
829
|
}
|
|
@@ -831,12 +834,11 @@ export class DeleteMutator<
|
|
|
831
834
|
mutatorFactory
|
|
832
835
|
.forUpdate(inboundReferenceEntity, queryContext)
|
|
833
836
|
.setField(fieldName, null)
|
|
834
|
-
[
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
)
|
|
837
|
+
[
|
|
838
|
+
'updateInTransactionAsync'
|
|
839
|
+
](/* skipDatabaseUpdate */ false, newCascadingDeleteCause),
|
|
840
|
+
),
|
|
841
|
+
),
|
|
840
842
|
);
|
|
841
843
|
break;
|
|
842
844
|
}
|
|
@@ -849,16 +851,16 @@ export class DeleteMutator<
|
|
|
849
851
|
.deleteInTransactionAsync(
|
|
850
852
|
processedEntityIdentifiers,
|
|
851
853
|
/* skipDatabaseDeletion */ false,
|
|
852
|
-
newCascadingDeleteCause
|
|
853
|
-
)
|
|
854
|
-
)
|
|
855
|
-
)
|
|
854
|
+
newCascadingDeleteCause,
|
|
855
|
+
),
|
|
856
|
+
),
|
|
857
|
+
),
|
|
856
858
|
);
|
|
857
859
|
}
|
|
858
860
|
}
|
|
859
|
-
}
|
|
861
|
+
},
|
|
860
862
|
);
|
|
861
|
-
})
|
|
863
|
+
}),
|
|
862
864
|
);
|
|
863
865
|
}
|
|
864
866
|
}
|