@expo/entity 0.60.0 → 0.61.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/src/AuthorizationResultBasedEntityAssociationLoader.d.ts +6 -6
- package/build/src/AuthorizationResultBasedEntityAssociationLoader.js +5 -10
- package/build/src/AuthorizationResultBasedEntityLoader.d.ts +9 -9
- package/build/src/AuthorizationResultBasedEntityLoader.js +27 -35
- package/build/src/AuthorizationResultBasedEntityMutator.d.ts +13 -13
- package/build/src/AuthorizationResultBasedEntityMutator.js +54 -65
- package/build/src/ComposedEntityCacheAdapter.d.ts +3 -3
- package/build/src/ComposedEntityCacheAdapter.js +15 -23
- package/build/src/ComposedSecondaryEntityCache.d.ts +1 -1
- package/build/src/ComposedSecondaryEntityCache.js +4 -12
- package/build/src/EnforcingEntityAssociationLoader.d.ts +5 -5
- package/build/src/EnforcingEntityAssociationLoader.js +6 -11
- package/build/src/EnforcingEntityCreator.d.ts +4 -4
- package/build/src/EnforcingEntityCreator.js +3 -8
- package/build/src/EnforcingEntityDeleter.d.ts +4 -4
- package/build/src/EnforcingEntityDeleter.js +3 -8
- package/build/src/EnforcingEntityLoader.d.ts +5 -5
- package/build/src/EnforcingEntityLoader.js +9 -14
- package/build/src/EnforcingEntityUpdater.d.ts +4 -4
- package/build/src/EnforcingEntityUpdater.js +3 -8
- package/build/src/Entity.d.ts +9 -9
- package/build/src/Entity.js +11 -16
- package/build/src/EntityAssociationLoader.d.ts +5 -5
- package/build/src/EntityAssociationLoader.js +5 -10
- package/build/src/EntityCompanion.d.ts +9 -9
- package/build/src/EntityCompanion.js +6 -11
- package/build/src/EntityCompanionProvider.d.ts +13 -12
- package/build/src/EntityCompanionProvider.js +13 -21
- package/build/src/EntityConfiguration.d.ts +4 -4
- package/build/src/EntityConfiguration.js +14 -23
- package/build/src/EntityConstructionUtils.d.ts +8 -8
- package/build/src/EntityConstructionUtils.js +15 -23
- package/build/src/EntityCreator.d.ts +7 -7
- package/build/src/EntityCreator.js +3 -8
- package/build/src/EntityDatabaseAdapter.d.ts +4 -4
- package/build/src/EntityDatabaseAdapter.js +19 -27
- package/build/src/EntityDeleter.d.ts +7 -7
- package/build/src/EntityDeleter.js +3 -8
- package/build/src/EntityFieldDefinition.d.ts +4 -4
- package/build/src/EntityFieldDefinition.js +5 -10
- package/build/src/EntityFields.d.ts +2 -1
- package/build/src/EntityFields.js +12 -27
- package/build/src/EntityInvalidationUtils.d.ts +8 -8
- package/build/src/EntityInvalidationUtils.js +4 -9
- package/build/src/EntityLoader.d.ts +7 -7
- package/build/src/EntityLoader.js +3 -8
- package/build/src/EntityLoaderFactory.d.ts +10 -10
- package/build/src/EntityLoaderFactory.js +7 -12
- package/build/src/EntityMutationInfo.d.ts +2 -2
- package/build/src/EntityMutationInfo.js +2 -6
- package/build/src/EntityMutationTriggerConfiguration.d.ts +4 -4
- package/build/src/EntityMutationTriggerConfiguration.js +2 -8
- package/build/src/EntityMutationValidatorConfiguration.d.ts +4 -4
- package/build/src/EntityMutationValidatorConfiguration.js +1 -6
- package/build/src/EntityMutatorFactory.d.ts +13 -13
- package/build/src/EntityMutatorFactory.js +5 -10
- package/build/src/EntityPrivacyPolicy.d.ts +7 -7
- package/build/src/EntityPrivacyPolicy.js +22 -27
- package/build/src/EntityQueryContext.d.ts +1 -1
- package/build/src/EntityQueryContext.js +11 -22
- package/build/src/EntityQueryContextProvider.d.ts +2 -1
- package/build/src/EntityQueryContextProvider.js +7 -12
- package/build/src/EntitySecondaryCacheLoader.d.ts +7 -7
- package/build/src/EntitySecondaryCacheLoader.js +4 -9
- package/build/src/EntityUpdater.d.ts +7 -7
- package/build/src/EntityUpdater.js +3 -8
- package/build/src/GenericEntityCacheAdapter.d.ts +4 -4
- package/build/src/GenericEntityCacheAdapter.js +5 -13
- package/build/src/GenericSecondaryEntityCache.d.ts +2 -2
- package/build/src/GenericSecondaryEntityCache.js +10 -18
- package/build/src/IEntityCacheAdapter.d.ts +2 -2
- package/build/src/IEntityCacheAdapter.js +1 -3
- package/build/src/IEntityCacheAdapterProvider.d.ts +2 -2
- package/build/src/IEntityCacheAdapterProvider.js +1 -3
- package/build/src/IEntityDatabaseAdapterProvider.d.ts +2 -2
- package/build/src/IEntityDatabaseAdapterProvider.js +1 -3
- package/build/src/IEntityGenericCacher.d.ts +2 -2
- package/build/src/IEntityGenericCacher.js +1 -3
- package/build/src/ReadonlyEntity.d.ts +9 -9
- package/build/src/ReadonlyEntity.js +9 -17
- package/build/src/ViewerContext.d.ts +6 -6
- package/build/src/ViewerContext.js +3 -8
- package/build/src/ViewerScopedEntityCompanion.d.ts +8 -8
- package/build/src/ViewerScopedEntityCompanion.js +5 -10
- package/build/src/ViewerScopedEntityCompanionProvider.d.ts +6 -6
- package/build/src/ViewerScopedEntityCompanionProvider.js +3 -8
- package/build/src/ViewerScopedEntityLoaderFactory.d.ts +8 -8
- package/build/src/ViewerScopedEntityLoaderFactory.js +1 -6
- package/build/src/ViewerScopedEntityMutatorFactory.d.ts +7 -7
- package/build/src/ViewerScopedEntityMutatorFactory.js +1 -6
- package/build/src/entityUtils.d.ts +1 -1
- package/build/src/entityUtils.js +9 -21
- package/build/src/errors/EntityCacheAdapterError.d.ts +1 -1
- package/build/src/errors/EntityCacheAdapterError.js +5 -11
- package/build/src/errors/EntityDatabaseAdapterError.d.ts +1 -1
- package/build/src/errors/EntityDatabaseAdapterError.js +41 -59
- package/build/src/errors/EntityError.js +5 -10
- package/build/src/errors/EntityInvalidFieldValueError.d.ts +5 -5
- package/build/src/errors/EntityInvalidFieldValueError.js +4 -9
- package/build/src/errors/EntityNotAuthorizedError.d.ts +4 -4
- package/build/src/errors/EntityNotAuthorizedError.js +6 -11
- package/build/src/errors/EntityNotFoundError.d.ts +5 -5
- package/build/src/errors/EntityNotFoundError.js +4 -9
- package/build/src/index.d.ts +77 -77
- package/build/src/index.js +77 -94
- package/build/src/internal/CompositeFieldHolder.d.ts +3 -2
- package/build/src/internal/CompositeFieldHolder.js +11 -21
- package/build/src/internal/CompositeFieldValueMap.d.ts +2 -2
- package/build/src/internal/CompositeFieldValueMap.js +7 -12
- package/build/src/internal/EntityDataManager.d.ts +6 -6
- package/build/src/internal/EntityDataManager.js +25 -33
- package/build/src/internal/EntityFieldTransformationUtils.d.ts +1 -1
- package/build/src/internal/EntityFieldTransformationUtils.js +11 -23
- package/build/src/internal/EntityLoadInterfaces.d.ts +3 -2
- package/build/src/internal/EntityLoadInterfaces.js +4 -9
- package/build/src/internal/EntityTableDataCoordinator.d.ts +8 -8
- package/build/src/internal/EntityTableDataCoordinator.js +4 -9
- package/build/src/internal/ReadThroughEntityCache.d.ts +3 -3
- package/build/src/internal/ReadThroughEntityCache.js +7 -15
- package/build/src/internal/SingleFieldHolder.d.ts +3 -2
- package/build/src/internal/SingleFieldHolder.js +9 -19
- package/build/src/metrics/EntityMetricsUtils.d.ts +3 -3
- package/build/src/metrics/EntityMetricsUtils.js +6 -14
- package/build/src/metrics/IEntityMetricsAdapter.d.ts +2 -2
- package/build/src/metrics/IEntityMetricsAdapter.js +8 -12
- package/build/src/metrics/NoOpEntityMetricsAdapter.d.ts +1 -1
- package/build/src/metrics/NoOpEntityMetricsAdapter.js +1 -6
- package/build/src/rules/AllowIfAllSubRulesAllowPrivacyPolicyRule.d.ts +5 -5
- package/build/src/rules/AllowIfAllSubRulesAllowPrivacyPolicyRule.js +5 -10
- package/build/src/rules/AllowIfAnySubRuleAllowsPrivacyPolicyRule.d.ts +5 -5
- package/build/src/rules/AllowIfAnySubRuleAllowsPrivacyPolicyRule.js +5 -10
- package/build/src/rules/AllowIfInParentCascadeDeletionPrivacyPolicyRule.d.ts +6 -6
- package/build/src/rules/AllowIfInParentCascadeDeletionPrivacyPolicyRule.js +6 -11
- package/build/src/rules/AlwaysAllowPrivacyPolicyRule.d.ts +5 -5
- package/build/src/rules/AlwaysAllowPrivacyPolicyRule.js +3 -8
- package/build/src/rules/AlwaysDenyPrivacyPolicyRule.d.ts +5 -5
- package/build/src/rules/AlwaysDenyPrivacyPolicyRule.js +3 -8
- package/build/src/rules/AlwaysSkipPrivacyPolicyRule.d.ts +5 -5
- package/build/src/rules/AlwaysSkipPrivacyPolicyRule.js +3 -8
- package/build/src/rules/EvaluateIfEntityFieldPredicatePrivacyPolicyRule.d.ts +5 -5
- package/build/src/rules/EvaluateIfEntityFieldPredicatePrivacyPolicyRule.js +3 -8
- package/build/src/rules/PrivacyPolicyRule.d.ts +4 -4
- package/build/src/rules/PrivacyPolicyRule.js +3 -8
- package/build/src/utils/EntityCreationUtils.d.ts +5 -5
- package/build/src/utils/EntityCreationUtils.js +6 -11
- package/build/src/utils/EntityPrivacyUtils.d.ts +5 -5
- package/build/src/utils/EntityPrivacyUtils.js +20 -27
- package/build/src/utils/collections/SerializableKeyMap.js +1 -6
- package/build/src/utils/collections/maps.js +11 -27
- package/build/src/utils/collections/sets.js +1 -5
- package/build/src/utils/mergeEntityMutationTriggerConfigurations.d.ts +3 -3
- package/build/src/utils/mergeEntityMutationTriggerConfigurations.js +1 -5
- package/package.json +7 -6
- package/src/AuthorizationResultBasedEntityAssociationLoader.ts +7 -6
- package/src/AuthorizationResultBasedEntityLoader.ts +19 -17
- package/src/AuthorizationResultBasedEntityMutator.ts +24 -22
- package/src/ComposedEntityCacheAdapter.ts +5 -4
- package/src/ComposedSecondaryEntityCache.ts +2 -2
- package/src/EnforcingEntityAssociationLoader.ts +7 -7
- package/src/EnforcingEntityCreator.ts +4 -4
- package/src/EnforcingEntityDeleter.ts +4 -4
- package/src/EnforcingEntityLoader.ts +8 -8
- package/src/EnforcingEntityUpdater.ts +4 -4
- package/src/Entity.ts +13 -13
- package/src/EntityAssociationLoader.ts +6 -6
- package/src/EntityCompanion.ts +13 -10
- package/src/EntityCompanionProvider.ts +15 -14
- package/src/EntityConfiguration.ts +6 -8
- package/src/EntityConstructionUtils.ts +16 -12
- package/src/EntityCreator.ts +7 -7
- package/src/EntityDatabaseAdapter.ts +6 -6
- package/src/EntityDeleter.ts +7 -7
- package/src/EntityFieldDefinition.ts +4 -4
- package/src/EntityFields.ts +3 -3
- package/src/EntityInvalidationUtils.ts +10 -10
- package/src/EntityLoader.ts +7 -7
- package/src/EntityLoaderFactory.ts +13 -10
- package/src/EntityMutationInfo.ts +2 -2
- package/src/EntityMutationTriggerConfiguration.ts +4 -4
- package/src/EntityMutationValidatorConfiguration.ts +4 -4
- package/src/EntityMutatorFactory.ts +13 -13
- package/src/EntityPrivacyPolicy.ts +9 -10
- package/src/EntityQueryContext.ts +1 -1
- package/src/EntityQueryContextProvider.ts +2 -2
- package/src/EntitySecondaryCacheLoader.ts +8 -8
- package/src/EntityUpdater.ts +7 -7
- package/src/GenericEntityCacheAdapter.ts +5 -5
- package/src/GenericSecondaryEntityCache.ts +4 -4
- package/src/IEntityCacheAdapter.ts +2 -2
- package/src/IEntityCacheAdapterProvider.ts +2 -2
- package/src/IEntityDatabaseAdapterProvider.ts +2 -2
- package/src/IEntityGenericCacher.ts +2 -2
- package/src/ReadonlyEntity.ts +11 -11
- package/src/ViewerContext.ts +8 -8
- package/src/ViewerScopedEntityCompanion.ts +8 -8
- package/src/ViewerScopedEntityCompanionProvider.ts +6 -6
- package/src/ViewerScopedEntityLoaderFactory.ts +11 -8
- package/src/ViewerScopedEntityMutatorFactory.ts +8 -8
- package/src/__tests__/AuthorizationResultBasedEntityAssociationLoader-test.ts +6 -6
- package/src/__tests__/AuthorizationResultBasedEntityLoader-constructor-test.ts +16 -15
- package/src/__tests__/AuthorizationResultBasedEntityLoader-test.ts +21 -18
- package/src/__tests__/ComposedCacheAdapter-test.ts +8 -7
- package/src/__tests__/ComposedSecondaryEntityCache-test.ts +3 -3
- package/src/__tests__/EnforcingEntityAssociationLoader-test.ts +2 -2
- package/src/__tests__/EnforcingEntityLoader-test.ts +4 -4
- package/src/__tests__/Entity-test.ts +8 -8
- package/src/__tests__/EntityAssociationLoader-test.ts +6 -6
- package/src/__tests__/EntityCommonUseCases-test.ts +17 -13
- package/src/__tests__/EntityCompanion-test.ts +11 -11
- package/src/__tests__/EntityCompanionProvider-test.ts +8 -7
- package/src/__tests__/EntityConfiguration-test.ts +3 -3
- package/src/__tests__/EntityDatabaseAdapter-test.ts +11 -7
- package/src/__tests__/EntityEdges-test.ts +17 -19
- package/src/__tests__/EntityFields-test.ts +3 -3
- package/src/__tests__/EntityLoader-test.ts +7 -7
- package/src/__tests__/EntityMutator-MutationCacheConsistency-test.ts +12 -11
- package/src/__tests__/EntityMutator-SingleCompositeFieldCacheConsistency-test.ts +4 -4
- package/src/__tests__/EntityMutator-test.ts +32 -36
- package/src/__tests__/EntityPrivacyPolicy-test.ts +19 -19
- package/src/__tests__/EntityQueryContext-test.ts +9 -9
- package/src/__tests__/EntitySecondaryCacheLoader-test.ts +8 -7
- package/src/__tests__/EntitySelfReferentialEdges-test.ts +12 -12
- package/src/__tests__/GenericEntityCacheAdapter-test.ts +6 -6
- package/src/__tests__/GenericSecondaryEntityCache-test.ts +16 -18
- package/src/__tests__/ReadonlyEntity-test.ts +10 -10
- package/src/__tests__/ViewerContext-test.ts +3 -3
- package/src/__tests__/ViewerScopedEntityCompanion-test.ts +7 -7
- package/src/__tests__/ViewerScopedEntityCompanionProvider-test.ts +5 -5
- package/src/__tests__/ViewerScopedEntityLoaderFactory-test.ts +5 -5
- package/src/__tests__/ViewerScopedEntityMutatorFactory-test.ts +6 -6
- package/src/__tests__/cases/TwoEntitySameTableDisjointRows-test.ts +9 -9
- package/src/__tests__/cases/TwoEntitySameTableOverlappingRows-test.ts +8 -8
- package/src/__tests__/entityUtils-test.ts +4 -4
- package/src/entityUtils.ts +1 -1
- package/src/errors/EntityCacheAdapterError.ts +1 -1
- package/src/errors/EntityDatabaseAdapterError.ts +1 -1
- package/src/errors/EntityInvalidFieldValueError.ts +5 -5
- package/src/errors/EntityNotAuthorizedError.ts +4 -4
- package/src/errors/EntityNotFoundError.ts +5 -5
- package/src/errors/__tests__/EntityDatabaseAdapterError-test.ts +2 -2
- package/src/errors/__tests__/EntityError-test.ts +7 -7
- package/src/index.ts +77 -77
- package/src/internal/CompositeFieldHolder.ts +6 -10
- package/src/internal/CompositeFieldValueMap.ts +3 -5
- package/src/internal/EntityDataManager.ts +11 -14
- package/src/internal/EntityFieldTransformationUtils.ts +2 -2
- package/src/internal/EntityLoadInterfaces.ts +3 -2
- package/src/internal/EntityTableDataCoordinator.ts +9 -9
- package/src/internal/ReadThroughEntityCache.ts +4 -4
- package/src/internal/SingleFieldHolder.ts +4 -8
- package/src/internal/__tests__/CompositeFieldHolder-test.ts +1 -1
- package/src/internal/__tests__/CompositeFieldValueMap-test.ts +3 -3
- package/src/internal/__tests__/EntityDataManager-test.ts +15 -18
- package/src/internal/__tests__/EntityFieldTransformationUtils-test.ts +3 -3
- package/src/internal/__tests__/ReadThroughEntityCache-test.ts +6 -6
- package/src/metrics/EntityMetricsUtils.ts +5 -5
- package/src/metrics/IEntityMetricsAdapter.ts +3 -3
- package/src/metrics/NoOpEntityMetricsAdapter.ts +2 -2
- package/src/metrics/__tests__/EntityMetricsUtils-test.ts +4 -7
- package/src/rules/AllowIfAllSubRulesAllowPrivacyPolicyRule.ts +5 -5
- package/src/rules/AllowIfAnySubRuleAllowsPrivacyPolicyRule.ts +5 -5
- package/src/rules/AllowIfInParentCascadeDeletionPrivacyPolicyRule.ts +9 -6
- package/src/rules/AlwaysAllowPrivacyPolicyRule.ts +5 -5
- package/src/rules/AlwaysDenyPrivacyPolicyRule.ts +5 -5
- package/src/rules/AlwaysSkipPrivacyPolicyRule.ts +5 -5
- package/src/rules/EvaluateIfEntityFieldPredicatePrivacyPolicyRule.ts +5 -5
- package/src/rules/PrivacyPolicyRule.ts +4 -4
- package/src/rules/__tests__/AllowIfAllSubRulesAllowPrivacyPolicyRule-test.ts +8 -8
- package/src/rules/__tests__/AllowIfAnySubRuleAllowsPrivacyPolicyRule-test.ts +8 -8
- package/src/rules/__tests__/AllowIfInParentCascadeDeletionPrivacyPolicyRule-test.ts +7 -7
- package/src/rules/__tests__/AlwaysAllowPrivacyPolicyRule-test.ts +5 -5
- package/src/rules/__tests__/AlwaysDenyPrivacyPolicyRule-test.ts +5 -5
- package/src/rules/__tests__/AlwaysSkipPrivacyPolicyRule-test.ts +5 -5
- package/src/rules/__tests__/EvaluateIfEntityFieldPredicatePrivacyPolicyRule-test.ts +9 -8
- package/src/utils/EntityCreationUtils.ts +7 -7
- package/src/utils/EntityPrivacyUtils.ts +13 -9
- package/src/utils/__testfixtures__/PrivacyPolicyRuleTestUtils.ts +6 -5
- package/src/utils/__testfixtures__/SimpleTestEntity.ts +7 -7
- package/src/utils/__testfixtures__/StubCacheAdapter.ts +6 -5
- package/src/utils/__testfixtures__/StubDatabaseAdapter.ts +6 -6
- package/src/utils/__testfixtures__/StubDatabaseAdapterProvider.ts +4 -4
- package/src/utils/__testfixtures__/StubQueryContextProvider.ts +2 -2
- package/src/utils/__testfixtures__/TSMockitoExtensions.ts +5 -5
- package/src/utils/__testfixtures__/TestEntity.ts +9 -8
- package/src/utils/__testfixtures__/TestEntity2.ts +7 -7
- package/src/utils/__testfixtures__/TestEntityWithMutationTriggers.ts +10 -10
- package/src/utils/__testfixtures__/TestViewerContext.ts +1 -1
- package/src/utils/__testfixtures__/createUnitTestEntityCompanionProvider.ts +6 -6
- package/src/utils/__testfixtures__/describeFieldTestCase.ts +1 -1
- package/src/utils/__tests__/EntityCreationUtils-test.ts +7 -7
- package/src/utils/__tests__/EntityPrivacyUtils-test.ts +20 -21
- package/src/utils/__tests__/canViewerDeleteAsync-edgeDeletionPermissionInferenceBehavior-test.ts +12 -12
- package/src/utils/__tests__/mergeEntityMutationTriggerConfigurations-test.ts +2 -2
- package/src/utils/collections/__tests__/SerializableKeyMap-test.ts +2 -1
- package/src/utils/collections/__tests__/maps-test.ts +5 -5
- package/src/utils/collections/__tests__/sets-test.ts +1 -1
- package/src/utils/mergeEntityMutationTriggerConfigurations.ts +3 -3
- package/build/src/AuthorizationResultBasedEntityAssociationLoader.js.map +0 -1
- package/build/src/AuthorizationResultBasedEntityLoader.js.map +0 -1
- package/build/src/AuthorizationResultBasedEntityMutator.js.map +0 -1
- package/build/src/ComposedEntityCacheAdapter.js.map +0 -1
- package/build/src/ComposedSecondaryEntityCache.js.map +0 -1
- package/build/src/EnforcingEntityAssociationLoader.js.map +0 -1
- package/build/src/EnforcingEntityCreator.js.map +0 -1
- package/build/src/EnforcingEntityDeleter.js.map +0 -1
- package/build/src/EnforcingEntityLoader.js.map +0 -1
- package/build/src/EnforcingEntityUpdater.js.map +0 -1
- package/build/src/Entity.js.map +0 -1
- package/build/src/EntityAssociationLoader.js.map +0 -1
- package/build/src/EntityCompanion.js.map +0 -1
- package/build/src/EntityCompanionProvider.js.map +0 -1
- package/build/src/EntityConfiguration.js.map +0 -1
- package/build/src/EntityConstructionUtils.js.map +0 -1
- package/build/src/EntityCreator.js.map +0 -1
- package/build/src/EntityDatabaseAdapter.js.map +0 -1
- package/build/src/EntityDeleter.js.map +0 -1
- package/build/src/EntityFieldDefinition.js.map +0 -1
- package/build/src/EntityFields.js.map +0 -1
- package/build/src/EntityInvalidationUtils.js.map +0 -1
- package/build/src/EntityLoader.js.map +0 -1
- package/build/src/EntityLoaderFactory.js.map +0 -1
- package/build/src/EntityMutationInfo.js.map +0 -1
- package/build/src/EntityMutationTriggerConfiguration.js.map +0 -1
- package/build/src/EntityMutationValidatorConfiguration.js.map +0 -1
- package/build/src/EntityMutatorFactory.js.map +0 -1
- package/build/src/EntityPrivacyPolicy.js.map +0 -1
- package/build/src/EntityQueryContext.js.map +0 -1
- package/build/src/EntityQueryContextProvider.js.map +0 -1
- package/build/src/EntitySecondaryCacheLoader.js.map +0 -1
- package/build/src/EntityUpdater.js.map +0 -1
- package/build/src/GenericEntityCacheAdapter.js.map +0 -1
- package/build/src/GenericSecondaryEntityCache.js.map +0 -1
- package/build/src/IEntityCacheAdapter.js.map +0 -1
- package/build/src/IEntityCacheAdapterProvider.js.map +0 -1
- package/build/src/IEntityDatabaseAdapterProvider.js.map +0 -1
- package/build/src/IEntityGenericCacher.js.map +0 -1
- package/build/src/ReadonlyEntity.js.map +0 -1
- package/build/src/ViewerContext.js.map +0 -1
- package/build/src/ViewerScopedEntityCompanion.js.map +0 -1
- package/build/src/ViewerScopedEntityCompanionProvider.js.map +0 -1
- package/build/src/ViewerScopedEntityLoaderFactory.js.map +0 -1
- package/build/src/ViewerScopedEntityMutatorFactory.js.map +0 -1
- package/build/src/entityUtils.js.map +0 -1
- package/build/src/errors/EntityCacheAdapterError.js.map +0 -1
- package/build/src/errors/EntityDatabaseAdapterError.js.map +0 -1
- package/build/src/errors/EntityError.js.map +0 -1
- package/build/src/errors/EntityInvalidFieldValueError.js.map +0 -1
- package/build/src/errors/EntityNotAuthorizedError.js.map +0 -1
- package/build/src/errors/EntityNotFoundError.js.map +0 -1
- package/build/src/index.js.map +0 -1
- package/build/src/internal/CompositeFieldHolder.js.map +0 -1
- package/build/src/internal/CompositeFieldValueMap.js.map +0 -1
- package/build/src/internal/EntityDataManager.js.map +0 -1
- package/build/src/internal/EntityFieldTransformationUtils.js.map +0 -1
- package/build/src/internal/EntityLoadInterfaces.js.map +0 -1
- package/build/src/internal/EntityTableDataCoordinator.js.map +0 -1
- package/build/src/internal/ReadThroughEntityCache.js.map +0 -1
- package/build/src/internal/SingleFieldHolder.js.map +0 -1
- package/build/src/metrics/EntityMetricsUtils.js.map +0 -1
- package/build/src/metrics/IEntityMetricsAdapter.js.map +0 -1
- package/build/src/metrics/NoOpEntityMetricsAdapter.js.map +0 -1
- package/build/src/rules/AllowIfAllSubRulesAllowPrivacyPolicyRule.js.map +0 -1
- package/build/src/rules/AllowIfAnySubRuleAllowsPrivacyPolicyRule.js.map +0 -1
- package/build/src/rules/AllowIfInParentCascadeDeletionPrivacyPolicyRule.js.map +0 -1
- package/build/src/rules/AlwaysAllowPrivacyPolicyRule.js.map +0 -1
- package/build/src/rules/AlwaysDenyPrivacyPolicyRule.js.map +0 -1
- package/build/src/rules/AlwaysSkipPrivacyPolicyRule.js.map +0 -1
- package/build/src/rules/EvaluateIfEntityFieldPredicatePrivacyPolicyRule.js.map +0 -1
- package/build/src/rules/PrivacyPolicyRule.js.map +0 -1
- package/build/src/utils/EntityCreationUtils.js.map +0 -1
- package/build/src/utils/EntityPrivacyUtils.js.map +0 -1
- package/build/src/utils/collections/SerializableKeyMap.js.map +0 -1
- package/build/src/utils/collections/maps.js.map +0 -1
- package/build/src/utils/collections/sets.js.map +0 -1
- package/build/src/utils/mergeEntityMutationTriggerConfigurations.js.map +0 -1
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { Result } from '@expo/results';
|
|
2
|
-
import { IEntityClass } from './Entity';
|
|
3
|
-
import { EntityPrivacyPolicy } from './EntityPrivacyPolicy';
|
|
4
|
-
import { EntityQueryContext } from './EntityQueryContext';
|
|
5
|
-
import { ReadonlyEntity } from './ReadonlyEntity';
|
|
6
|
-
import { ViewerContext } from './ViewerContext';
|
|
1
|
+
import type { Result } from '@expo/results';
|
|
2
|
+
import type { IEntityClass } from './Entity.ts';
|
|
3
|
+
import type { EntityPrivacyPolicy } from './EntityPrivacyPolicy.ts';
|
|
4
|
+
import type { EntityQueryContext } from './EntityQueryContext.ts';
|
|
5
|
+
import type { ReadonlyEntity } from './ReadonlyEntity.ts';
|
|
6
|
+
import type { ViewerContext } from './ViewerContext.ts';
|
|
7
7
|
/**
|
|
8
8
|
* An association loader is a set of convenience methods for loading entities
|
|
9
9
|
* associated with an entity. In relational databases, these entities are often referenced
|
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AuthorizationResultBasedEntityAssociationLoader = void 0;
|
|
4
|
-
const results_1 = require("@expo/results");
|
|
1
|
+
import { result } from '@expo/results';
|
|
5
2
|
/**
|
|
6
3
|
* An association loader is a set of convenience methods for loading entities
|
|
7
4
|
* associated with an entity. In relational databases, these entities are often referenced
|
|
8
5
|
* by foreign keys.
|
|
9
6
|
*/
|
|
10
|
-
class AuthorizationResultBasedEntityAssociationLoader {
|
|
7
|
+
export class AuthorizationResultBasedEntityAssociationLoader {
|
|
11
8
|
entity;
|
|
12
9
|
queryContext;
|
|
13
10
|
constructor(entity, queryContext) {
|
|
@@ -23,7 +20,7 @@ class AuthorizationResultBasedEntityAssociationLoader {
|
|
|
23
20
|
async loadAssociatedEntityAsync(fieldIdentifyingAssociatedEntity, associatedEntityClass) {
|
|
24
21
|
const associatedEntityID = this.entity.getField(fieldIdentifyingAssociatedEntity);
|
|
25
22
|
if (!associatedEntityID) {
|
|
26
|
-
return
|
|
23
|
+
return result(null);
|
|
27
24
|
}
|
|
28
25
|
const loader = this.entity
|
|
29
26
|
.getViewerContext()
|
|
@@ -112,12 +109,10 @@ class AuthorizationResultBasedEntityAssociationLoader {
|
|
|
112
109
|
return null;
|
|
113
110
|
}
|
|
114
111
|
if (!associatedEntityResult.ok) {
|
|
115
|
-
return
|
|
112
|
+
return result(associatedEntityResult.reason);
|
|
116
113
|
}
|
|
117
114
|
currentEntity = associatedEntityResult.value;
|
|
118
115
|
}
|
|
119
|
-
return
|
|
116
|
+
return result(currentEntity);
|
|
120
117
|
}
|
|
121
118
|
}
|
|
122
|
-
exports.AuthorizationResultBasedEntityAssociationLoader = AuthorizationResultBasedEntityAssociationLoader;
|
|
123
|
-
//# sourceMappingURL=AuthorizationResultBasedEntityAssociationLoader.js.map
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { Result } from '@expo/results';
|
|
2
|
-
import { IEntityClass } from './Entity';
|
|
3
|
-
import { EntityCompositeField, EntityCompositeFieldValue, EntityConfiguration } from './EntityConfiguration';
|
|
4
|
-
import { EntityConstructionUtils } from './EntityConstructionUtils';
|
|
5
|
-
import { EntityPrivacyPolicy } from './EntityPrivacyPolicy';
|
|
6
|
-
import { EntityQueryContext } from './EntityQueryContext';
|
|
7
|
-
import { ReadonlyEntity } from './ReadonlyEntity';
|
|
8
|
-
import { ViewerContext } from './ViewerContext';
|
|
9
|
-
import { EntityDataManager } from './internal/EntityDataManager';
|
|
1
|
+
import type { Result } from '@expo/results';
|
|
2
|
+
import type { IEntityClass } from './Entity.ts';
|
|
3
|
+
import type { EntityCompositeField, EntityCompositeFieldValue, EntityConfiguration } from './EntityConfiguration.ts';
|
|
4
|
+
import type { EntityConstructionUtils } from './EntityConstructionUtils.ts';
|
|
5
|
+
import type { EntityPrivacyPolicy } from './EntityPrivacyPolicy.ts';
|
|
6
|
+
import type { EntityQueryContext } from './EntityQueryContext.ts';
|
|
7
|
+
import type { ReadonlyEntity } from './ReadonlyEntity.ts';
|
|
8
|
+
import type { ViewerContext } from './ViewerContext.ts';
|
|
9
|
+
import type { EntityDataManager } from './internal/EntityDataManager.ts';
|
|
10
10
|
/**
|
|
11
11
|
* Authorization-result-based entity loader. All normal loads are batched,
|
|
12
12
|
* cached, and authorized against the entity's EntityPrivacyPolicy. All loads through this
|
|
@@ -1,25 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const EntityNotFoundError_1 = require("./errors/EntityNotFoundError");
|
|
11
|
-
const CompositeFieldHolder_1 = require("./internal/CompositeFieldHolder");
|
|
12
|
-
const CompositeFieldValueMap_1 = require("./internal/CompositeFieldValueMap");
|
|
13
|
-
const SingleFieldHolder_1 = require("./internal/SingleFieldHolder");
|
|
14
|
-
const maps_1 = require("./utils/collections/maps");
|
|
15
|
-
const sets_1 = require("./utils/collections/sets");
|
|
1
|
+
import nullthrows from '@expo/nullthrows';
|
|
2
|
+
import { result } from '@expo/results';
|
|
3
|
+
import invariant from 'invariant';
|
|
4
|
+
import { EntityNotFoundError } from "./errors/EntityNotFoundError.js";
|
|
5
|
+
import { CompositeFieldValueHolder } from "./internal/CompositeFieldHolder.js";
|
|
6
|
+
import { CompositeFieldValueMap } from "./internal/CompositeFieldValueMap.js";
|
|
7
|
+
import { SingleFieldHolder, SingleFieldValueHolder } from "./internal/SingleFieldHolder.js";
|
|
8
|
+
import { mapKeys, mapMap } from "./utils/collections/maps.js";
|
|
9
|
+
import { areSetsEqual } from "./utils/collections/sets.js";
|
|
16
10
|
/**
|
|
17
11
|
* Authorization-result-based entity loader. All normal loads are batched,
|
|
18
12
|
* cached, and authorized against the entity's EntityPrivacyPolicy. All loads through this
|
|
19
13
|
* loader are are results (or null for some loader methods), where an unsuccessful result
|
|
20
14
|
* means an authorization error or entity construction error occurred. Other errors are thrown.
|
|
21
15
|
*/
|
|
22
|
-
class AuthorizationResultBasedEntityLoader {
|
|
16
|
+
export class AuthorizationResultBasedEntityLoader {
|
|
23
17
|
queryContext;
|
|
24
18
|
entityConfiguration;
|
|
25
19
|
entityClass;
|
|
@@ -40,7 +34,7 @@ class AuthorizationResultBasedEntityLoader {
|
|
|
40
34
|
async loadManyByFieldEqualingManyAsync(fieldName, fieldValues) {
|
|
41
35
|
const { loadKey, loadValues } = this.validateFieldAndValuesAndConvertToHolders(fieldName, fieldValues);
|
|
42
36
|
const loadValuesToFieldObjects = await this.dataManager.loadManyEqualingAsync(this.queryContext, loadKey, loadValues);
|
|
43
|
-
const fieldValuesToFieldObjects =
|
|
37
|
+
const fieldValuesToFieldObjects = mapKeys(loadValuesToFieldObjects, (loadValue) => loadValue.fieldValue);
|
|
44
38
|
return await this.constructionUtils.constructAndAuthorizeEntitiesAsync(fieldValuesToFieldObjects);
|
|
45
39
|
}
|
|
46
40
|
/**
|
|
@@ -60,7 +54,7 @@ class AuthorizationResultBasedEntityLoader {
|
|
|
60
54
|
async loadManyByFieldEqualingAsync(fieldName, fieldValue) {
|
|
61
55
|
const entityResults = await this.loadManyByFieldEqualingManyAsync(fieldName, [fieldValue]);
|
|
62
56
|
const entityResultsForFieldValue = entityResults.get(fieldValue);
|
|
63
|
-
(
|
|
57
|
+
invariant(entityResultsForFieldValue !== undefined, `${fieldValue} should be guaranteed to be present in returned map of entities`);
|
|
64
58
|
return entityResultsForFieldValue;
|
|
65
59
|
}
|
|
66
60
|
/**
|
|
@@ -95,7 +89,7 @@ class AuthorizationResultBasedEntityLoader {
|
|
|
95
89
|
compositeFieldValue,
|
|
96
90
|
]);
|
|
97
91
|
const entityResultForCompositeFieldValue = entityResults.get(compositeFieldValue);
|
|
98
|
-
(
|
|
92
|
+
invariant(entityResultForCompositeFieldValue !== undefined, `${compositeFieldValue} should be guaranteed to be present in returned map of entities`);
|
|
99
93
|
return entityResultForCompositeFieldValue;
|
|
100
94
|
}
|
|
101
95
|
/**
|
|
@@ -105,7 +99,7 @@ class AuthorizationResultBasedEntityLoader {
|
|
|
105
99
|
*/
|
|
106
100
|
async loadByFieldEqualingAsync(uniqueFieldName, fieldValue) {
|
|
107
101
|
const entityResults = await this.loadManyByFieldEqualingAsync(uniqueFieldName, fieldValue);
|
|
108
|
-
(
|
|
102
|
+
invariant(entityResults.length <= 1, `loadByFieldEqualing: Multiple entities of type ${this.entityClass.name} found for ${String(uniqueFieldName)}=${fieldValue}`);
|
|
109
103
|
return entityResults[0] ?? null;
|
|
110
104
|
}
|
|
111
105
|
/**
|
|
@@ -114,7 +108,7 @@ class AuthorizationResultBasedEntityLoader {
|
|
|
114
108
|
*/
|
|
115
109
|
async loadByCompositeFieldEqualingAsync(compositeField, compositeFieldValue) {
|
|
116
110
|
const entityResults = await this.loadManyByCompositeFieldEqualingAsync(compositeField, compositeFieldValue);
|
|
117
|
-
(
|
|
111
|
+
invariant(entityResults.length <= 1, `loadByCompositeFieldEqualing: Multiple entities of type ${this.entityClass.name} found for composite field (${compositeField.join(',')})=${JSON.stringify(compositeFieldValue)}`);
|
|
118
112
|
return entityResults[0] ?? null;
|
|
119
113
|
}
|
|
120
114
|
/**
|
|
@@ -124,7 +118,7 @@ class AuthorizationResultBasedEntityLoader {
|
|
|
124
118
|
async loadByIDAsync(id) {
|
|
125
119
|
const entityResults = await this.loadManyByIDsAsync([id]);
|
|
126
120
|
// loadManyByIDsAsync is always populated for each id supplied
|
|
127
|
-
return (
|
|
121
|
+
return nullthrows(entityResults.get(id));
|
|
128
122
|
}
|
|
129
123
|
/**
|
|
130
124
|
* Authorization-result-based version of the EnforcingEntityLoader method by the same name.
|
|
@@ -139,10 +133,10 @@ class AuthorizationResultBasedEntityLoader {
|
|
|
139
133
|
*/
|
|
140
134
|
async loadManyByIDsAsync(ids) {
|
|
141
135
|
const entityResults = (await this.loadManyByFieldEqualingManyAsync(this.entityConfiguration.idField, ids));
|
|
142
|
-
return
|
|
136
|
+
return mapMap(entityResults, (entityResultsForId, id) => {
|
|
143
137
|
const entityResult = entityResultsForId[0];
|
|
144
138
|
return (entityResult ??
|
|
145
|
-
|
|
139
|
+
result(new EntityNotFoundError({
|
|
146
140
|
entityClass: this.entityClass,
|
|
147
141
|
fieldName: this.entityConfiguration.idField,
|
|
148
142
|
fieldValue: id,
|
|
@@ -155,33 +149,33 @@ class AuthorizationResultBasedEntityLoader {
|
|
|
155
149
|
*/
|
|
156
150
|
async loadManyByIDsNullableAsync(ids) {
|
|
157
151
|
const entityResults = (await this.loadManyByFieldEqualingManyAsync(this.entityConfiguration.idField, ids));
|
|
158
|
-
return
|
|
152
|
+
return mapMap(entityResults, (entityResultsForId) => {
|
|
159
153
|
return entityResultsForId[0] ?? null;
|
|
160
154
|
});
|
|
161
155
|
}
|
|
162
156
|
validateFieldAndValuesAndConvertToHolders(fieldName, fieldValues) {
|
|
163
157
|
this.constructionUtils.validateFieldAndValues(fieldName, fieldValues);
|
|
164
158
|
return {
|
|
165
|
-
loadKey: new
|
|
166
|
-
loadValues: fieldValues.map((fieldValue) => new
|
|
159
|
+
loadKey: new SingleFieldHolder(fieldName),
|
|
160
|
+
loadValues: fieldValues.map((fieldValue) => new SingleFieldValueHolder(fieldValue)),
|
|
167
161
|
};
|
|
168
162
|
}
|
|
169
163
|
validateFieldAndValueAndConvertToHolders(fieldName, fieldValue) {
|
|
170
164
|
this.constructionUtils.validateFieldAndValues(fieldName, [fieldValue]);
|
|
171
165
|
return {
|
|
172
|
-
loadKey: new
|
|
173
|
-
loadValue: new
|
|
166
|
+
loadKey: new SingleFieldHolder(fieldName),
|
|
167
|
+
loadValue: new SingleFieldValueHolder(fieldValue),
|
|
174
168
|
};
|
|
175
169
|
}
|
|
176
170
|
validateCompositeFieldAndValuesAndConvertToHolders(compositeField, compositeFieldValues) {
|
|
177
171
|
// validate that the composite field input is defined in the entity configuration
|
|
178
172
|
const compositeFieldHolder = this.entityConfiguration.compositeFieldInfo.getCompositeFieldHolderForCompositeField(compositeField);
|
|
179
|
-
(
|
|
173
|
+
invariant(compositeFieldHolder, `must have composite field definition for composite field = ${String(compositeField)}`);
|
|
180
174
|
const cacheableCompositeFieldFieldsSet = compositeFieldHolder.getFieldSet();
|
|
181
|
-
const compositeFieldValueHolders = compositeFieldValues.map((compositeFieldValue) => new
|
|
175
|
+
const compositeFieldValueHolders = compositeFieldValues.map((compositeFieldValue) => new CompositeFieldValueHolder(compositeFieldValue));
|
|
182
176
|
// validate that the composite field values are valid
|
|
183
177
|
for (const compositeFieldValueHolder of compositeFieldValueHolders) {
|
|
184
|
-
(
|
|
178
|
+
invariant(areSetsEqual(cacheableCompositeFieldFieldsSet, compositeFieldValueHolder.getFieldSet()), `composite field values must contain exactly the fields defined in the composite field definition: ${compositeField}`);
|
|
185
179
|
for (const field of compositeField) {
|
|
186
180
|
const fieldValue = compositeFieldValueHolder.compositeFieldValue[field];
|
|
187
181
|
this.constructionUtils.validateFieldAndValues(field, [fieldValue]);
|
|
@@ -193,7 +187,7 @@ class AuthorizationResultBasedEntityLoader {
|
|
|
193
187
|
};
|
|
194
188
|
}
|
|
195
189
|
async constructAndAuthorizeEntitiesFromCompositeFieldValueHolderMapAsync(map) {
|
|
196
|
-
return new
|
|
190
|
+
return new CompositeFieldValueMap(await Promise.all(Array.from(map.entries()).map(async ([compositeFieldValueHolder, fieldObjects]) => {
|
|
197
191
|
return [
|
|
198
192
|
compositeFieldValueHolder,
|
|
199
193
|
await this.constructionUtils.constructAndAuthorizeEntitiesArrayAsync(fieldObjects),
|
|
@@ -201,5 +195,3 @@ class AuthorizationResultBasedEntityLoader {
|
|
|
201
195
|
})));
|
|
202
196
|
}
|
|
203
197
|
}
|
|
204
|
-
exports.AuthorizationResultBasedEntityLoader = AuthorizationResultBasedEntityLoader;
|
|
205
|
-
//# sourceMappingURL=AuthorizationResultBasedEntityLoader.js.map
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { Result } from '@expo/results';
|
|
2
|
-
import { Entity, IEntityClass } from './Entity';
|
|
3
|
-
import { EntityCompanionProvider } from './EntityCompanionProvider';
|
|
4
|
-
import { EntityConfiguration } from './EntityConfiguration';
|
|
5
|
-
import { EntityDatabaseAdapter } from './EntityDatabaseAdapter';
|
|
6
|
-
import { EntityLoaderFactory } from './EntityLoaderFactory';
|
|
7
|
-
import { EntityCascadingDeletionInfo, EntityTriggerMutationInfo, EntityValidatorMutationInfo } from './EntityMutationInfo';
|
|
8
|
-
import { EntityMutationTrigger, EntityMutationTriggerConfiguration, EntityNonTransactionalMutationTrigger } from './EntityMutationTriggerConfiguration';
|
|
9
|
-
import { EntityMutationValidator, EntityMutationValidatorConfiguration } from './EntityMutationValidatorConfiguration';
|
|
10
|
-
import { EntityPrivacyPolicy } from './EntityPrivacyPolicy';
|
|
11
|
-
import { EntityQueryContext, EntityTransactionalQueryContext } from './EntityQueryContext';
|
|
12
|
-
import { ViewerContext } from './ViewerContext';
|
|
13
|
-
import { IEntityMetricsAdapter } from './metrics/IEntityMetricsAdapter';
|
|
1
|
+
import type { Result } from '@expo/results';
|
|
2
|
+
import type { Entity, IEntityClass } from './Entity.ts';
|
|
3
|
+
import type { EntityCompanionProvider } from './EntityCompanionProvider.ts';
|
|
4
|
+
import type { EntityConfiguration } from './EntityConfiguration.ts';
|
|
5
|
+
import type { EntityDatabaseAdapter } from './EntityDatabaseAdapter.ts';
|
|
6
|
+
import type { EntityLoaderFactory } from './EntityLoaderFactory.ts';
|
|
7
|
+
import type { EntityCascadingDeletionInfo, EntityTriggerMutationInfo, EntityValidatorMutationInfo } from './EntityMutationInfo.ts';
|
|
8
|
+
import type { EntityMutationTrigger, EntityMutationTriggerConfiguration, EntityNonTransactionalMutationTrigger } from './EntityMutationTriggerConfiguration.ts';
|
|
9
|
+
import type { EntityMutationValidator, EntityMutationValidatorConfiguration } from './EntityMutationValidatorConfiguration.ts';
|
|
10
|
+
import type { EntityPrivacyPolicy } from './EntityPrivacyPolicy.ts';
|
|
11
|
+
import type { EntityQueryContext, EntityTransactionalQueryContext } from './EntityQueryContext.ts';
|
|
12
|
+
import type { ViewerContext } from './ViewerContext.ts';
|
|
13
|
+
import type { IEntityMetricsAdapter } from './metrics/IEntityMetricsAdapter.ts';
|
|
14
14
|
/**
|
|
15
15
|
* Base class for entity mutators. Mutators are builder-like class instances that are
|
|
16
16
|
* responsible for creating, updating, and deleting entities, and for calling out to
|
|
@@ -1,18 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const EntityMutationInfo_1 = require("./EntityMutationInfo");
|
|
11
|
-
const entityUtils_1 = require("./entityUtils");
|
|
12
|
-
const EntityInvalidFieldValueError_1 = require("./errors/EntityInvalidFieldValueError");
|
|
13
|
-
const EntityMetricsUtils_1 = require("./metrics/EntityMetricsUtils");
|
|
14
|
-
const IEntityMetricsAdapter_1 = require("./metrics/IEntityMetricsAdapter");
|
|
15
|
-
const maps_1 = require("./utils/collections/maps");
|
|
1
|
+
import { asyncResult, enforceAsyncResult, result } from '@expo/results';
|
|
2
|
+
import invariant from 'invariant';
|
|
3
|
+
import { EntityEdgeDeletionBehavior } from "./EntityFieldDefinition.js";
|
|
4
|
+
import { EntityMutationType } from "./EntityMutationInfo.js";
|
|
5
|
+
import { enforceResultsAsync } from "./entityUtils.js";
|
|
6
|
+
import { EntityInvalidFieldValueError } from "./errors/EntityInvalidFieldValueError.js";
|
|
7
|
+
import { timeAndLogMutationEventAsync } from "./metrics/EntityMetricsUtils.js";
|
|
8
|
+
import { EntityMetricsMutationType } from "./metrics/IEntityMetricsAdapter.js";
|
|
9
|
+
import { mapMapAsync } from "./utils/collections/maps.js";
|
|
16
10
|
/**
|
|
17
11
|
* Base class for entity mutators. Mutators are builder-like class instances that are
|
|
18
12
|
* responsible for creating, updating, and deleting entities, and for calling out to
|
|
@@ -99,7 +93,7 @@ const maps_1 = require("./utils/collections/maps");
|
|
|
99
93
|
* - https://engineering.fb.com/2013/06/25/core-infra/tao-the-power-of-the-graph/
|
|
100
94
|
* - https://hazelcast.com/blog/a-hitchhikers-guide-to-caching-patterns/
|
|
101
95
|
*/
|
|
102
|
-
class AuthorizationResultBasedBaseMutator {
|
|
96
|
+
export class AuthorizationResultBasedBaseMutator {
|
|
103
97
|
companionProvider;
|
|
104
98
|
viewerContext;
|
|
105
99
|
queryContext;
|
|
@@ -128,10 +122,10 @@ class AuthorizationResultBasedBaseMutator {
|
|
|
128
122
|
for (const fieldName in fields) {
|
|
129
123
|
const fieldValue = fields[fieldName];
|
|
130
124
|
const fieldDefinition = this.entityConfiguration.schema.get(fieldName);
|
|
131
|
-
(
|
|
125
|
+
invariant(fieldDefinition, `must have field definition for field = ${fieldName}`);
|
|
132
126
|
const isInputValid = fieldDefinition.validateInputValue(fieldValue);
|
|
133
127
|
if (!isInputValid) {
|
|
134
|
-
throw new
|
|
128
|
+
throw new EntityInvalidFieldValueError(this.entityClass, fieldName, fieldValue);
|
|
135
129
|
}
|
|
136
130
|
}
|
|
137
131
|
}
|
|
@@ -154,11 +148,10 @@ class AuthorizationResultBasedBaseMutator {
|
|
|
154
148
|
await Promise.all(triggers.map((trigger) => trigger.executeAsync(this.viewerContext, entity, mutationInfo)));
|
|
155
149
|
}
|
|
156
150
|
}
|
|
157
|
-
exports.AuthorizationResultBasedBaseMutator = AuthorizationResultBasedBaseMutator;
|
|
158
151
|
/**
|
|
159
152
|
* Mutator for creating a new entity.
|
|
160
153
|
*/
|
|
161
|
-
class AuthorizationResultBasedCreateMutator extends AuthorizationResultBasedBaseMutator {
|
|
154
|
+
export class AuthorizationResultBasedCreateMutator extends AuthorizationResultBasedBaseMutator {
|
|
162
155
|
fieldsForEntity = {};
|
|
163
156
|
/**
|
|
164
157
|
* Set the value for entity field.
|
|
@@ -175,7 +168,7 @@ class AuthorizationResultBasedCreateMutator extends AuthorizationResultBasedBase
|
|
|
175
168
|
* @returns authorized, cached, newly-created entity result, where result error can be UnauthorizedError
|
|
176
169
|
*/
|
|
177
170
|
async createAsync() {
|
|
178
|
-
return await
|
|
171
|
+
return await timeAndLogMutationEventAsync(this.metricsAdapter, EntityMetricsMutationType.CREATE, this.entityClass.name, this.queryContext)(this.createInTransactionAsync());
|
|
179
172
|
}
|
|
180
173
|
async createInTransactionAsync() {
|
|
181
174
|
return await this.queryContext.runInTransactionIfNotInTransactionAsync((innerQueryContext) => this.createInternalAsync(innerQueryContext));
|
|
@@ -195,13 +188,13 @@ class AuthorizationResultBasedCreateMutator extends AuthorizationResultBasedBase
|
|
|
195
188
|
[this.entityConfiguration.idField]: '00000000-0000-0000-0000-000000000000', // zero UUID
|
|
196
189
|
...this.fieldsForEntity,
|
|
197
190
|
});
|
|
198
|
-
const authorizeCreateResult = await
|
|
191
|
+
const authorizeCreateResult = await asyncResult(this.privacyPolicy.authorizeCreateAsync(this.viewerContext, queryContext, { previousValue: null, cascadingDeleteCause: null }, temporaryEntityForPrivacyCheck, this.metricsAdapter));
|
|
199
192
|
if (!authorizeCreateResult.ok) {
|
|
200
193
|
return authorizeCreateResult;
|
|
201
194
|
}
|
|
202
|
-
await this.executeMutationValidatorsAsync(this.mutationValidators.beforeCreateAndUpdate, queryContext, temporaryEntityForPrivacyCheck, { type:
|
|
203
|
-
await this.executeMutationTriggersAsync(this.mutationTriggers.beforeAll, queryContext, temporaryEntityForPrivacyCheck, { type:
|
|
204
|
-
await this.executeMutationTriggersAsync(this.mutationTriggers.beforeCreate, queryContext, temporaryEntityForPrivacyCheck, { type:
|
|
195
|
+
await this.executeMutationValidatorsAsync(this.mutationValidators.beforeCreateAndUpdate, queryContext, temporaryEntityForPrivacyCheck, { type: EntityMutationType.CREATE });
|
|
196
|
+
await this.executeMutationTriggersAsync(this.mutationTriggers.beforeAll, queryContext, temporaryEntityForPrivacyCheck, { type: EntityMutationType.CREATE });
|
|
197
|
+
await this.executeMutationTriggersAsync(this.mutationTriggers.beforeCreate, queryContext, temporaryEntityForPrivacyCheck, { type: EntityMutationType.CREATE });
|
|
205
198
|
const insertResult = await this.databaseAdapter.insertAsync(queryContext, this.fieldsForEntity);
|
|
206
199
|
// Invalidate all caches for the new entity so that any previously-negatively-cached loads
|
|
207
200
|
// are removed from the caches.
|
|
@@ -211,18 +204,17 @@ class AuthorizationResultBasedCreateMutator extends AuthorizationResultBasedBase
|
|
|
211
204
|
});
|
|
212
205
|
invalidationUtils.invalidateFieldsForTransaction(queryContext, insertResult);
|
|
213
206
|
const unauthorizedEntityAfterInsert = constructionUtils.constructEntity(insertResult);
|
|
214
|
-
const newEntity = await
|
|
215
|
-
await this.executeMutationTriggersAsync(this.mutationTriggers.afterCreate, queryContext, newEntity, { type:
|
|
216
|
-
await this.executeMutationTriggersAsync(this.mutationTriggers.afterAll, queryContext, newEntity, { type:
|
|
217
|
-
queryContext.appendPostCommitCallback(this.executeNonTransactionalMutationTriggersAsync.bind(this, this.mutationTriggers.afterCommit, newEntity, { type:
|
|
218
|
-
return
|
|
207
|
+
const newEntity = await enforceAsyncResult(entityLoader.loadByIDAsync(unauthorizedEntityAfterInsert.getID()));
|
|
208
|
+
await this.executeMutationTriggersAsync(this.mutationTriggers.afterCreate, queryContext, newEntity, { type: EntityMutationType.CREATE });
|
|
209
|
+
await this.executeMutationTriggersAsync(this.mutationTriggers.afterAll, queryContext, newEntity, { type: EntityMutationType.CREATE });
|
|
210
|
+
queryContext.appendPostCommitCallback(this.executeNonTransactionalMutationTriggersAsync.bind(this, this.mutationTriggers.afterCommit, newEntity, { type: EntityMutationType.CREATE }));
|
|
211
|
+
return result(newEntity);
|
|
219
212
|
}
|
|
220
213
|
}
|
|
221
|
-
exports.AuthorizationResultBasedCreateMutator = AuthorizationResultBasedCreateMutator;
|
|
222
214
|
/**
|
|
223
215
|
* Mutator for updating an existing entity.
|
|
224
216
|
*/
|
|
225
|
-
class AuthorizationResultBasedUpdateMutator extends AuthorizationResultBasedBaseMutator {
|
|
217
|
+
export class AuthorizationResultBasedUpdateMutator extends AuthorizationResultBasedBaseMutator {
|
|
226
218
|
cascadingDeleteCause;
|
|
227
219
|
originalEntity;
|
|
228
220
|
fieldsForEntity;
|
|
@@ -249,7 +241,7 @@ class AuthorizationResultBasedUpdateMutator extends AuthorizationResultBasedBase
|
|
|
249
241
|
* @returns authorized updated entity result, where result error can be UnauthorizedError
|
|
250
242
|
*/
|
|
251
243
|
async updateAsync() {
|
|
252
|
-
return await
|
|
244
|
+
return await timeAndLogMutationEventAsync(this.metricsAdapter, EntityMetricsMutationType.UPDATE, this.entityClass.name, this.queryContext)(this.updateInTransactionAsync(false));
|
|
253
245
|
}
|
|
254
246
|
async updateInTransactionAsync(skipDatabaseUpdate) {
|
|
255
247
|
return await this.queryContext.runInTransactionIfNotInTransactionAsync((innerQueryContext) => this.updateInternalAsync(innerQueryContext, skipDatabaseUpdate));
|
|
@@ -267,22 +259,22 @@ class AuthorizationResultBasedUpdateMutator extends AuthorizationResultBasedBase
|
|
|
267
259
|
cascadingDeleteCause: this.cascadingDeleteCause,
|
|
268
260
|
});
|
|
269
261
|
const entityAboutToBeUpdated = constructionUtils.constructEntity(this.fieldsForEntity);
|
|
270
|
-
const authorizeUpdateResult = await
|
|
262
|
+
const authorizeUpdateResult = await asyncResult(this.privacyPolicy.authorizeUpdateAsync(this.viewerContext, queryContext, { previousValue: this.originalEntity, cascadingDeleteCause: this.cascadingDeleteCause }, entityAboutToBeUpdated, this.metricsAdapter));
|
|
271
263
|
if (!authorizeUpdateResult.ok) {
|
|
272
264
|
return authorizeUpdateResult;
|
|
273
265
|
}
|
|
274
266
|
await this.executeMutationValidatorsAsync(this.mutationValidators.beforeCreateAndUpdate, queryContext, entityAboutToBeUpdated, {
|
|
275
|
-
type:
|
|
267
|
+
type: EntityMutationType.UPDATE,
|
|
276
268
|
previousValue: this.originalEntity,
|
|
277
269
|
cascadingDeleteCause: this.cascadingDeleteCause,
|
|
278
270
|
});
|
|
279
271
|
await this.executeMutationTriggersAsync(this.mutationTriggers.beforeAll, queryContext, entityAboutToBeUpdated, {
|
|
280
|
-
type:
|
|
272
|
+
type: EntityMutationType.UPDATE,
|
|
281
273
|
previousValue: this.originalEntity,
|
|
282
274
|
cascadingDeleteCause: this.cascadingDeleteCause,
|
|
283
275
|
});
|
|
284
276
|
await this.executeMutationTriggersAsync(this.mutationTriggers.beforeUpdate, queryContext, entityAboutToBeUpdated, {
|
|
285
|
-
type:
|
|
277
|
+
type: EntityMutationType.UPDATE,
|
|
286
278
|
previousValue: this.originalEntity,
|
|
287
279
|
cascadingDeleteCause: this.cascadingDeleteCause,
|
|
288
280
|
});
|
|
@@ -307,23 +299,23 @@ class AuthorizationResultBasedUpdateMutator extends AuthorizationResultBasedBase
|
|
|
307
299
|
});
|
|
308
300
|
invalidationUtils.invalidateFieldsForTransaction(queryContext, this.originalEntity.getAllDatabaseFields());
|
|
309
301
|
invalidationUtils.invalidateFieldsForTransaction(queryContext, this.fieldsForEntity);
|
|
310
|
-
const updatedEntity = await
|
|
302
|
+
const updatedEntity = await enforceAsyncResult(entityLoader.loadByIDAsync(entityAboutToBeUpdated.getID())); // ID is guaranteed to be stable by ensureStableIDField
|
|
311
303
|
await this.executeMutationTriggersAsync(this.mutationTriggers.afterUpdate, queryContext, updatedEntity, {
|
|
312
|
-
type:
|
|
304
|
+
type: EntityMutationType.UPDATE,
|
|
313
305
|
previousValue: this.originalEntity,
|
|
314
306
|
cascadingDeleteCause: this.cascadingDeleteCause,
|
|
315
307
|
});
|
|
316
308
|
await this.executeMutationTriggersAsync(this.mutationTriggers.afterAll, queryContext, updatedEntity, {
|
|
317
|
-
type:
|
|
309
|
+
type: EntityMutationType.UPDATE,
|
|
318
310
|
previousValue: this.originalEntity,
|
|
319
311
|
cascadingDeleteCause: this.cascadingDeleteCause,
|
|
320
312
|
});
|
|
321
313
|
queryContext.appendPostCommitCallback(this.executeNonTransactionalMutationTriggersAsync.bind(this, this.mutationTriggers.afterCommit, updatedEntity, {
|
|
322
|
-
type:
|
|
314
|
+
type: EntityMutationType.UPDATE,
|
|
323
315
|
previousValue: this.originalEntity,
|
|
324
316
|
cascadingDeleteCause: this.cascadingDeleteCause,
|
|
325
317
|
}));
|
|
326
|
-
return
|
|
318
|
+
return result(updatedEntity);
|
|
327
319
|
}
|
|
328
320
|
ensureStableIDField(updatedFields) {
|
|
329
321
|
const originalId = this.originalEntity.getID();
|
|
@@ -333,11 +325,10 @@ class AuthorizationResultBasedUpdateMutator extends AuthorizationResultBasedBase
|
|
|
333
325
|
}
|
|
334
326
|
}
|
|
335
327
|
}
|
|
336
|
-
exports.AuthorizationResultBasedUpdateMutator = AuthorizationResultBasedUpdateMutator;
|
|
337
328
|
/**
|
|
338
329
|
* Mutator for deleting an existing entity.
|
|
339
330
|
*/
|
|
340
|
-
class AuthorizationResultBasedDeleteMutator extends AuthorizationResultBasedBaseMutator {
|
|
331
|
+
export class AuthorizationResultBasedDeleteMutator extends AuthorizationResultBasedBaseMutator {
|
|
341
332
|
entity;
|
|
342
333
|
cascadingDeleteCause;
|
|
343
334
|
constructor(companionProvider, viewerContext, queryContext, entityConfiguration, entityClass, privacyPolicy, mutationValidators, mutationTriggers, entityLoaderFactory, databaseAdapter, metricsAdapter, entity, cascadingDeleteCause) {
|
|
@@ -350,27 +341,27 @@ class AuthorizationResultBasedDeleteMutator extends AuthorizationResultBasedBase
|
|
|
350
341
|
* @returns void result, where result error can be UnauthorizedError
|
|
351
342
|
*/
|
|
352
343
|
async deleteAsync() {
|
|
353
|
-
return await
|
|
344
|
+
return await timeAndLogMutationEventAsync(this.metricsAdapter, EntityMetricsMutationType.DELETE, this.entityClass.name, this.queryContext)(this.deleteInTransactionAsync(new Set(), false));
|
|
354
345
|
}
|
|
355
346
|
async deleteInTransactionAsync(processedEntityIdentifiersFromTransitiveDeletions, skipDatabaseDeletion) {
|
|
356
347
|
return await this.queryContext.runInTransactionIfNotInTransactionAsync((innerQueryContext) => this.deleteInternalAsync(innerQueryContext, processedEntityIdentifiersFromTransitiveDeletions, skipDatabaseDeletion));
|
|
357
348
|
}
|
|
358
349
|
async deleteInternalAsync(queryContext, processedEntityIdentifiersFromTransitiveDeletions, skipDatabaseDeletion) {
|
|
359
|
-
const authorizeDeleteResult = await
|
|
350
|
+
const authorizeDeleteResult = await asyncResult(this.privacyPolicy.authorizeDeleteAsync(this.viewerContext, queryContext, { previousValue: null, cascadingDeleteCause: this.cascadingDeleteCause }, this.entity, this.metricsAdapter));
|
|
360
351
|
if (!authorizeDeleteResult.ok) {
|
|
361
352
|
return authorizeDeleteResult;
|
|
362
353
|
}
|
|
363
354
|
await this.processEntityDeletionForInboundEdgesAsync(this.entity, queryContext, processedEntityIdentifiersFromTransitiveDeletions);
|
|
364
355
|
await this.executeMutationValidatorsAsync(this.mutationValidators.beforeDelete, queryContext, this.entity, {
|
|
365
|
-
type:
|
|
356
|
+
type: EntityMutationType.DELETE,
|
|
366
357
|
cascadingDeleteCause: this.cascadingDeleteCause,
|
|
367
358
|
});
|
|
368
359
|
await this.executeMutationTriggersAsync(this.mutationTriggers.beforeAll, queryContext, this.entity, {
|
|
369
|
-
type:
|
|
360
|
+
type: EntityMutationType.DELETE,
|
|
370
361
|
cascadingDeleteCause: this.cascadingDeleteCause,
|
|
371
362
|
});
|
|
372
363
|
await this.executeMutationTriggersAsync(this.mutationTriggers.beforeDelete, queryContext, this.entity, {
|
|
373
|
-
type:
|
|
364
|
+
type: EntityMutationType.DELETE,
|
|
374
365
|
cascadingDeleteCause: this.cascadingDeleteCause,
|
|
375
366
|
});
|
|
376
367
|
if (!skipDatabaseDeletion) {
|
|
@@ -385,18 +376,18 @@ class AuthorizationResultBasedDeleteMutator extends AuthorizationResultBasedBase
|
|
|
385
376
|
});
|
|
386
377
|
invalidationUtils.invalidateFieldsForTransaction(queryContext, this.entity.getAllDatabaseFields());
|
|
387
378
|
await this.executeMutationTriggersAsync(this.mutationTriggers.afterDelete, queryContext, this.entity, {
|
|
388
|
-
type:
|
|
379
|
+
type: EntityMutationType.DELETE,
|
|
389
380
|
cascadingDeleteCause: this.cascadingDeleteCause,
|
|
390
381
|
});
|
|
391
382
|
await this.executeMutationTriggersAsync(this.mutationTriggers.afterAll, queryContext, this.entity, {
|
|
392
|
-
type:
|
|
383
|
+
type: EntityMutationType.DELETE,
|
|
393
384
|
cascadingDeleteCause: this.cascadingDeleteCause,
|
|
394
385
|
});
|
|
395
386
|
queryContext.appendPostCommitCallback(this.executeNonTransactionalMutationTriggersAsync.bind(this, this.mutationTriggers.afterCommit, this.entity, {
|
|
396
|
-
type:
|
|
387
|
+
type: EntityMutationType.DELETE,
|
|
397
388
|
cascadingDeleteCause: this.cascadingDeleteCause,
|
|
398
389
|
}));
|
|
399
|
-
return
|
|
390
|
+
return result();
|
|
400
391
|
}
|
|
401
392
|
/**
|
|
402
393
|
* Finds all entities referencing the specified entity and either deletes them, nullifies
|
|
@@ -434,7 +425,7 @@ class AuthorizationResultBasedDeleteMutator extends AuthorizationResultBasedBase
|
|
|
434
425
|
.getViewerContext()
|
|
435
426
|
.getViewerScopedEntityCompanionForClass(entityClass)
|
|
436
427
|
.getMutatorFactory();
|
|
437
|
-
return await
|
|
428
|
+
return await mapMapAsync(this.companionProvider.getCompanionForEntity(entityClass).entityCompanionDefinition
|
|
438
429
|
.entityConfiguration.schema, async (fieldDefinition, fieldName) => {
|
|
439
430
|
const association = fieldDefinition.association;
|
|
440
431
|
if (!association) {
|
|
@@ -444,7 +435,7 @@ class AuthorizationResultBasedDeleteMutator extends AuthorizationResultBasedBase
|
|
|
444
435
|
if (associatedConfiguration !== entityConfiguration) {
|
|
445
436
|
return;
|
|
446
437
|
}
|
|
447
|
-
const inboundReferenceEntities = await
|
|
438
|
+
const inboundReferenceEntities = await enforceResultsAsync(loaderFactory
|
|
448
439
|
.forLoad(queryContext, {
|
|
449
440
|
previousValue: null,
|
|
450
441
|
cascadingDeleteCause: newCascadingDeleteCause,
|
|
@@ -453,27 +444,27 @@ class AuthorizationResultBasedDeleteMutator extends AuthorizationResultBasedBase
|
|
|
453
444
|
? entity.getField(association.associatedEntityLookupByField)
|
|
454
445
|
: entity.getID()));
|
|
455
446
|
switch (association.edgeDeletionBehavior) {
|
|
456
|
-
case
|
|
457
|
-
await Promise.all(inboundReferenceEntities.map((inboundReferenceEntity) =>
|
|
447
|
+
case EntityEdgeDeletionBehavior.CASCADE_DELETE_INVALIDATE_CACHE_ONLY: {
|
|
448
|
+
await Promise.all(inboundReferenceEntities.map((inboundReferenceEntity) => enforceAsyncResult(mutatorFactory
|
|
458
449
|
.forDelete(inboundReferenceEntity, queryContext, newCascadingDeleteCause)
|
|
459
450
|
.deleteInTransactionAsync(processedEntityIdentifiers,
|
|
460
451
|
/* skipDatabaseDeletion */ true))));
|
|
461
452
|
break;
|
|
462
453
|
}
|
|
463
|
-
case
|
|
464
|
-
await Promise.all(inboundReferenceEntities.map((inboundReferenceEntity) =>
|
|
454
|
+
case EntityEdgeDeletionBehavior.SET_NULL_INVALIDATE_CACHE_ONLY: {
|
|
455
|
+
await Promise.all(inboundReferenceEntities.map((inboundReferenceEntity) => enforceAsyncResult(mutatorFactory
|
|
465
456
|
.forUpdate(inboundReferenceEntity, queryContext, newCascadingDeleteCause)
|
|
466
457
|
.setField(fieldName, null)['updateInTransactionAsync'](/* skipDatabaseUpdate */ true))));
|
|
467
458
|
break;
|
|
468
459
|
}
|
|
469
|
-
case
|
|
470
|
-
await Promise.all(inboundReferenceEntities.map((inboundReferenceEntity) =>
|
|
460
|
+
case EntityEdgeDeletionBehavior.SET_NULL: {
|
|
461
|
+
await Promise.all(inboundReferenceEntities.map((inboundReferenceEntity) => enforceAsyncResult(mutatorFactory
|
|
471
462
|
.forUpdate(inboundReferenceEntity, queryContext, newCascadingDeleteCause)
|
|
472
463
|
.setField(fieldName, null)['updateInTransactionAsync'](/* skipDatabaseUpdate */ false))));
|
|
473
464
|
break;
|
|
474
465
|
}
|
|
475
|
-
case
|
|
476
|
-
await Promise.all(inboundReferenceEntities.map((inboundReferenceEntity) =>
|
|
466
|
+
case EntityEdgeDeletionBehavior.CASCADE_DELETE: {
|
|
467
|
+
await Promise.all(inboundReferenceEntities.map((inboundReferenceEntity) => enforceAsyncResult(mutatorFactory
|
|
477
468
|
.forDelete(inboundReferenceEntity, queryContext, newCascadingDeleteCause)
|
|
478
469
|
.deleteInTransactionAsync(processedEntityIdentifiers,
|
|
479
470
|
/* skipDatabaseDeletion */ false))));
|
|
@@ -483,5 +474,3 @@ class AuthorizationResultBasedDeleteMutator extends AuthorizationResultBasedBase
|
|
|
483
474
|
}));
|
|
484
475
|
}
|
|
485
476
|
}
|
|
486
|
-
exports.AuthorizationResultBasedDeleteMutator = AuthorizationResultBasedDeleteMutator;
|
|
487
|
-
//# sourceMappingURL=AuthorizationResultBasedEntityMutator.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { IEntityCacheAdapter } from './IEntityCacheAdapter';
|
|
2
|
-
import { IEntityLoadKey, IEntityLoadValue } from './internal/EntityLoadInterfaces';
|
|
3
|
-
import { CacheLoadResult } from './internal/ReadThroughEntityCache';
|
|
1
|
+
import type { IEntityCacheAdapter } from './IEntityCacheAdapter.ts';
|
|
2
|
+
import type { IEntityLoadKey, IEntityLoadValue } from './internal/EntityLoadInterfaces.ts';
|
|
3
|
+
import type { CacheLoadResult } from './internal/ReadThroughEntityCache.ts';
|
|
4
4
|
/**
|
|
5
5
|
* A IEntityCacheAdapter that composes other IEntityCacheAdapter instances.
|
|
6
6
|
*/
|