@expo/entity 0.41.0 → 0.43.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/AuthorizationResultBasedEntityAssociationLoader.d.ts +16 -16
- package/build/AuthorizationResultBasedEntityAssociationLoader.js.map +1 -1
- package/build/AuthorizationResultBasedEntityLoader.d.ts +39 -67
- package/build/AuthorizationResultBasedEntityLoader.js +85 -62
- package/build/AuthorizationResultBasedEntityLoader.js.map +1 -1
- package/build/AuthorizationResultBasedEntityMutator.d.ts +16 -16
- package/build/AuthorizationResultBasedEntityMutator.js.map +1 -1
- package/build/ComposedEntityCacheAdapter.d.ts +7 -6
- package/build/ComposedEntityCacheAdapter.js +28 -28
- package/build/ComposedEntityCacheAdapter.js.map +1 -1
- package/build/ComposedSecondaryEntityCache.d.ts +1 -1
- package/build/ComposedSecondaryEntityCache.js.map +1 -1
- package/build/EnforcingEntityAssociationLoader.d.ts +15 -15
- package/build/EnforcingEntityAssociationLoader.js.map +1 -1
- package/build/EnforcingEntityCreator.d.ts +2 -2
- package/build/EnforcingEntityDeleter.d.ts +2 -2
- package/build/EnforcingEntityLoader.d.ts +104 -18
- package/build/EnforcingEntityLoader.js +113 -12
- package/build/EnforcingEntityLoader.js.map +1 -1
- package/build/EnforcingEntityUpdater.d.ts +2 -2
- package/build/Entity.d.ts +10 -10
- package/build/Entity.js.map +1 -1
- package/build/EntityAssociationLoader.d.ts +3 -3
- package/build/EntityCompanion.d.ts +5 -5
- package/build/EntityCompanion.js.map +1 -1
- package/build/EntityCompanionProvider.d.ts +6 -6
- package/build/EntityCompanionProvider.js.map +1 -1
- package/build/EntityConfiguration.d.ts +46 -5
- package/build/EntityConfiguration.js +39 -1
- package/build/EntityConfiguration.js.map +1 -1
- package/build/EntityCreator.d.ts +4 -4
- package/build/EntityDatabaseAdapter.d.ts +15 -14
- package/build/EntityDatabaseAdapter.js +20 -12
- package/build/EntityDatabaseAdapter.js.map +1 -1
- package/build/EntityDeleter.d.ts +4 -4
- package/build/EntityFieldDefinition.d.ts +20 -10
- package/build/EntityFieldDefinition.js +3 -1
- package/build/EntityFieldDefinition.js.map +1 -1
- package/build/EntityFields.d.ts +14 -12
- package/build/EntityFields.js.map +1 -1
- package/build/EntityLoader.d.ts +5 -5
- package/build/EntityLoaderFactory.d.ts +3 -3
- package/build/EntityLoaderFactory.js.map +1 -1
- package/build/EntityLoaderUtils.d.ts +2 -2
- package/build/EntityLoaderUtils.js +27 -1
- package/build/EntityLoaderUtils.js.map +1 -1
- package/build/EntityMutationInfo.d.ts +2 -2
- package/build/EntityMutationTriggerConfiguration.d.ts +14 -14
- package/build/EntityMutationTriggerConfiguration.js.map +1 -1
- package/build/EntityMutationValidator.d.ts +2 -2
- package/build/EntityMutatorFactory.d.ts +5 -5
- package/build/EntityMutatorFactory.js.map +1 -1
- package/build/EntityPrivacyPolicy.d.ts +14 -14
- package/build/EntityPrivacyPolicy.js.map +1 -1
- package/build/EntitySecondaryCacheLoader.d.ts +4 -4
- package/build/EntityUpdater.d.ts +4 -4
- package/build/GenericEntityCacheAdapter.d.ts +7 -6
- package/build/GenericEntityCacheAdapter.js +13 -14
- package/build/GenericEntityCacheAdapter.js.map +1 -1
- package/build/GenericSecondaryEntityCache.d.ts +3 -3
- package/build/GenericSecondaryEntityCache.js.map +1 -1
- package/build/IEntityCacheAdapter.d.ts +17 -16
- package/build/IEntityCacheAdapterProvider.d.ts +1 -1
- package/build/IEntityDatabaseAdapterProvider.d.ts +1 -1
- package/build/IEntityGenericCacher.d.ts +15 -5
- package/build/ReadonlyEntity.d.ts +8 -8
- package/build/ReadonlyEntity.js.map +1 -1
- package/build/ViewerContext.d.ts +1 -1
- package/build/ViewerScopedEntityCompanion.d.ts +5 -5
- package/build/ViewerScopedEntityCompanionProvider.d.ts +1 -1
- package/build/ViewerScopedEntityLoaderFactory.d.ts +3 -3
- package/build/ViewerScopedEntityMutatorFactory.d.ts +5 -5
- package/build/entityUtils.d.ts +1 -1
- package/build/entityUtils.js.map +1 -1
- package/build/errors/EntityInvalidFieldValueError.d.ts +2 -2
- package/build/errors/EntityNotAuthorizedError.d.ts +1 -1
- package/build/errors/EntityNotFoundError.d.ts +2 -2
- package/build/index.d.ts +7 -7
- package/build/index.js +8 -13
- package/build/index.js.map +1 -1
- package/build/internal/CompositeFieldHolder.d.ts +48 -0
- package/build/internal/CompositeFieldHolder.js +116 -0
- package/build/internal/CompositeFieldHolder.js.map +1 -0
- package/build/internal/CompositeFieldValueMap.d.ts +15 -0
- package/build/internal/CompositeFieldValueMap.js +51 -0
- package/build/internal/CompositeFieldValueMap.js.map +1 -0
- package/build/internal/EntityDataManager.d.ts +16 -16
- package/build/internal/EntityDataManager.js +42 -45
- package/build/internal/EntityDataManager.js.map +1 -1
- package/build/internal/EntityFieldTransformationUtils.d.ts +5 -5
- package/build/internal/EntityFieldTransformationUtils.js.map +1 -1
- package/build/internal/EntityLoadInterfaces.d.ts +104 -0
- package/build/internal/EntityLoadInterfaces.js +25 -0
- package/build/internal/EntityLoadInterfaces.js.map +1 -0
- package/build/internal/EntityTableDataCoordinator.d.ts +6 -6
- package/build/internal/EntityTableDataCoordinator.js.map +1 -1
- package/build/internal/ReadThroughEntityCache.d.ts +17 -16
- package/build/internal/ReadThroughEntityCache.js +36 -36
- package/build/internal/ReadThroughEntityCache.js.map +1 -1
- package/build/internal/SingleFieldHolder.d.ts +34 -0
- package/build/internal/SingleFieldHolder.js +90 -0
- package/build/internal/SingleFieldHolder.js.map +1 -0
- package/build/metrics/EntityMetricsUtils.d.ts +2 -1
- package/build/metrics/EntityMetricsUtils.js.map +1 -1
- package/build/metrics/IEntityMetricsAdapter.d.ts +5 -0
- package/build/metrics/IEntityMetricsAdapter.js.map +1 -1
- package/build/rules/AlwaysAllowPrivacyPolicyRule.d.ts +2 -2
- package/build/rules/AlwaysAllowPrivacyPolicyRule.js.map +1 -1
- package/build/rules/AlwaysDenyPrivacyPolicyRule.d.ts +2 -2
- package/build/rules/AlwaysDenyPrivacyPolicyRule.js.map +1 -1
- package/build/rules/AlwaysSkipPrivacyPolicyRule.d.ts +2 -2
- package/build/rules/AlwaysSkipPrivacyPolicyRule.js.map +1 -1
- package/build/rules/PrivacyPolicyRule.d.ts +2 -2
- package/build/tsconfig.build.tsbuildinfo +1 -0
- package/build/utils/EntityPrivacyUtils.d.ts +4 -4
- package/build/utils/EntityPrivacyUtils.js.map +1 -1
- package/build/utils/collections/SerializableKeyMap.d.ts +27 -0
- package/build/utils/collections/SerializableKeyMap.js +60 -0
- package/build/utils/collections/SerializableKeyMap.js.map +1 -0
- package/build/utils/collections/maps.js +1 -2
- package/build/utils/collections/maps.js.map +1 -1
- package/build/utils/collections/sets.d.ts +1 -0
- package/build/utils/collections/sets.js +7 -0
- package/build/utils/collections/sets.js.map +1 -0
- package/build/utils/mergeEntityMutationTriggerConfigurations.d.ts +1 -1
- package/package.json +8 -5
- package/src/AuthorizationResultBasedEntityAssociationLoader.ts +56 -49
- package/src/AuthorizationResultBasedEntityLoader.ts +194 -81
- package/src/AuthorizationResultBasedEntityMutator.ts +71 -45
- package/src/ComposedEntityCacheAdapter.ts +55 -46
- package/src/ComposedSecondaryEntityCache.ts +5 -2
- package/src/EnforcingEntityAssociationLoader.ts +52 -44
- package/src/EnforcingEntityCreator.ts +5 -5
- package/src/EnforcingEntityDeleter.ts +5 -5
- package/src/EnforcingEntityLoader.ts +158 -21
- package/src/EnforcingEntityUpdater.ts +5 -5
- package/src/Entity.ts +39 -39
- package/src/EntityAssociationLoader.ts +6 -6
- package/src/EntityCompanion.ts +11 -11
- package/src/EntityCompanionProvider.ts +21 -18
- package/src/EntityConfiguration.ts +123 -9
- package/src/EntityCreator.ts +7 -7
- package/src/EntityDatabaseAdapter.ts +51 -28
- package/src/EntityDeleter.ts +7 -7
- package/src/EntityFieldDefinition.ts +32 -12
- package/src/EntityFields.ts +49 -12
- package/src/EntityLoader.ts +8 -8
- package/src/EntityLoaderFactory.ts +8 -8
- package/src/EntityLoaderUtils.ts +39 -10
- package/src/EntityMutationInfo.ts +6 -6
- package/src/EntityMutationTriggerConfiguration.ts +68 -20
- package/src/EntityMutationValidator.ts +4 -4
- package/src/EntityMutatorFactory.ts +13 -13
- package/src/EntityPrivacyPolicy.ts +50 -26
- package/src/EntitySecondaryCacheLoader.ts +6 -6
- package/src/EntityUpdater.ts +7 -7
- package/src/GenericEntityCacheAdapter.ts +39 -28
- package/src/GenericSecondaryEntityCache.ts +6 -3
- package/src/IEntityCacheAdapter.ts +45 -25
- package/src/IEntityCacheAdapterProvider.ts +3 -3
- package/src/IEntityDatabaseAdapterProvider.ts +3 -3
- package/src/IEntityGenericCacher.ts +33 -5
- package/src/ReadonlyEntity.ts +24 -24
- package/src/ViewerContext.ts +5 -5
- package/src/ViewerScopedEntityCompanion.ts +7 -7
- package/src/ViewerScopedEntityCompanionProvider.ts +6 -6
- package/src/ViewerScopedEntityLoaderFactory.ts +7 -7
- package/src/ViewerScopedEntityMutatorFactory.ts +8 -8
- package/src/__tests__/AuthorizationResultBasedEntityAssociationLoader-test.ts +4 -4
- package/src/__tests__/AuthorizationResultBasedEntityLoader-constructor-test.ts +14 -13
- package/src/__tests__/AuthorizationResultBasedEntityLoader-test.ts +367 -69
- package/src/__tests__/ComposedCacheAdapter-test.ts +235 -117
- package/src/__tests__/EnforcingEntityLoader-test.ts +135 -1
- package/src/__tests__/Entity-test.ts +2 -2
- package/src/__tests__/EntityAssociationLoader-test.ts +2 -2
- package/src/__tests__/EntityCommonUseCases-test.ts +11 -11
- package/src/__tests__/EntityCompanion-test.ts +4 -4
- package/src/__tests__/EntityCompanionProvider-test.ts +9 -8
- package/src/__tests__/EntityConfiguration-test.ts +85 -6
- package/src/__tests__/EntityDatabaseAdapter-test.ts +113 -17
- package/src/__tests__/EntityEdges-test.ts +97 -72
- package/src/__tests__/EntityFields-test.ts +2 -2
- package/src/__tests__/EntityLoader-test.ts +2 -2
- package/src/__tests__/EntityMutator-MutationCacheConsistency-test.ts +11 -11
- package/src/__tests__/EntityMutator-SingleCompositeFieldCacheConsistency-test.ts +73 -0
- package/src/__tests__/EntityMutator-test.ts +74 -46
- package/src/__tests__/EntityPrivacyPolicy-test.ts +51 -74
- package/src/__tests__/EntityQueryContext-test.ts +1 -1
- package/src/__tests__/EntitySecondaryCacheLoader-test.ts +3 -3
- package/src/__tests__/EntitySelfReferentialEdges-test.ts +64 -39
- package/src/__tests__/GenericEntityCacheAdapter-test.ts +83 -28
- package/src/__tests__/ReadonlyEntity-test.ts +3 -3
- package/src/__tests__/ViewerContext-test.ts +1 -1
- package/src/__tests__/ViewerScopedEntityCompanion-test.ts +5 -2
- package/src/__tests__/ViewerScopedEntityCompanionProvider-test.ts +1 -1
- package/src/__tests__/ViewerScopedEntityMutatorFactory-test.ts +12 -3
- package/src/__tests__/cases/TwoEntitySameTableDisjointRows-test.ts +12 -12
- package/src/__tests__/cases/TwoEntitySameTableOverlappingRows-test.ts +12 -12
- package/src/entityUtils.ts +4 -1
- package/src/errors/EntityInvalidFieldValueError.ts +5 -5
- package/src/errors/EntityNotAuthorizedError.ts +3 -3
- package/src/errors/EntityNotFoundError.ts +5 -5
- package/src/index.ts +7 -7
- package/src/internal/CompositeFieldHolder.ts +218 -0
- package/src/internal/CompositeFieldValueMap.ts +78 -0
- package/src/internal/EntityDataManager.ts +107 -96
- package/src/internal/EntityFieldTransformationUtils.ts +33 -14
- package/src/internal/EntityLoadInterfaces.ts +143 -0
- package/src/internal/EntityTableDataCoordinator.ts +8 -5
- package/src/internal/ReadThroughEntityCache.ts +63 -50
- package/src/internal/SingleFieldHolder.ts +131 -0
- package/src/internal/__tests__/CompositeFieldHolder-test.ts +25 -0
- package/src/internal/__tests__/CompositeFieldValueMap-test.ts +43 -0
- package/src/internal/__tests__/EntityDataManager-test.ts +308 -91
- package/src/internal/__tests__/EntityFieldTransformationUtils-test.ts +3 -2
- package/src/internal/__tests__/ReadThroughEntityCache-test.ts +315 -107
- package/src/metrics/EntityMetricsUtils.ts +7 -2
- package/src/metrics/IEntityMetricsAdapter.ts +6 -0
- package/src/rules/AlwaysAllowPrivacyPolicyRule.ts +5 -5
- package/src/rules/AlwaysDenyPrivacyPolicyRule.ts +5 -5
- package/src/rules/AlwaysSkipPrivacyPolicyRule.ts +5 -5
- package/src/rules/PrivacyPolicyRule.ts +4 -4
- package/src/rules/__tests__/AlwaysAllowPrivacyPolicyRule-test.ts +1 -1
- package/src/rules/__tests__/AlwaysDenyPrivacyPolicyRule-test.ts +1 -1
- package/src/rules/__tests__/AlwaysSkipPrivacyPolicyRule-test.ts +1 -1
- package/src/utils/EntityPrivacyUtils.ts +72 -30
- package/src/utils/{testing → __testfixtures__}/PrivacyPolicyRuleTestUtils.ts +26 -26
- package/src/{testfixtures → utils/__testfixtures__}/SimpleTestEntity.ts +16 -15
- package/src/utils/__testfixtures__/StubCacheAdapter.ts +164 -0
- package/src/utils/{testing → __testfixtures__}/StubDatabaseAdapter.ts +19 -12
- package/src/utils/{testing → __testfixtures__}/StubDatabaseAdapterProvider.ts +4 -4
- package/src/utils/__testfixtures__/TSMockitoExtensions.ts +69 -0
- package/src/{testfixtures → utils/__testfixtures__}/TestEntity.ts +21 -15
- package/src/{testfixtures → utils/__testfixtures__}/TestEntity2.ts +16 -15
- package/src/{testfixtures → utils/__testfixtures__}/TestEntityWithMutationTriggers.ts +23 -22
- package/src/{testfixtures → utils/__testfixtures__}/TestViewerContext.ts +1 -1
- package/src/utils/{testing → __testfixtures__}/describeFieldTestCase.ts +1 -1
- package/src/utils/__tests__/EntityPrivacyUtils-test.ts +62 -66
- package/src/utils/__tests__/canViewerDeleteAsync-edgeDeletionPermissionInferenceBehavior-test.ts +29 -25
- package/src/utils/__tests__/mergeEntityMutationTriggerConfigurations-test.ts +1 -1
- package/src/utils/collections/SerializableKeyMap.ts +84 -0
- package/src/utils/collections/__tests__/SerializableKeyMap-test.ts +119 -0
- package/src/utils/collections/__tests__/sets-test.ts +17 -0
- package/src/utils/collections/maps.ts +7 -8
- package/src/utils/collections/sets.ts +3 -0
- package/src/utils/mergeEntityMutationTriggerConfigurations.ts +5 -5
- package/build/__tests__/AuthorizationResultBasedEntityAssociationLoader-test.d.ts +0 -1
- package/build/__tests__/AuthorizationResultBasedEntityAssociationLoader-test.js +0 -242
- package/build/__tests__/AuthorizationResultBasedEntityAssociationLoader-test.js.map +0 -1
- package/build/__tests__/AuthorizationResultBasedEntityLoader-constructor-test.d.ts +0 -26
- package/build/__tests__/AuthorizationResultBasedEntityLoader-constructor-test.js +0 -110
- package/build/__tests__/AuthorizationResultBasedEntityLoader-constructor-test.js.map +0 -1
- package/build/__tests__/AuthorizationResultBasedEntityLoader-test.d.ts +0 -1
- package/build/__tests__/AuthorizationResultBasedEntityLoader-test.js +0 -401
- package/build/__tests__/AuthorizationResultBasedEntityLoader-test.js.map +0 -1
- package/build/__tests__/ComposedCacheAdapter-test.d.ts +0 -1
- package/build/__tests__/ComposedCacheAdapter-test.js +0 -229
- package/build/__tests__/ComposedCacheAdapter-test.js.map +0 -1
- package/build/__tests__/ComposedSecondaryEntityCache-test.d.ts +0 -1
- package/build/__tests__/ComposedSecondaryEntityCache-test.js +0 -66
- package/build/__tests__/ComposedSecondaryEntityCache-test.js.map +0 -1
- package/build/__tests__/EnforcingEntityAssociationLoader-test.d.ts +0 -1
- package/build/__tests__/EnforcingEntityAssociationLoader-test.js +0 -115
- package/build/__tests__/EnforcingEntityAssociationLoader-test.js.map +0 -1
- package/build/__tests__/EnforcingEntityLoader-test.d.ts +0 -1
- package/build/__tests__/EnforcingEntityLoader-test.js +0 -253
- package/build/__tests__/EnforcingEntityLoader-test.js.map +0 -1
- package/build/__tests__/Entity-test.d.ts +0 -1
- package/build/__tests__/Entity-test.js +0 -94
- package/build/__tests__/Entity-test.js.map +0 -1
- package/build/__tests__/EntityAssociationLoader-test.d.ts +0 -1
- package/build/__tests__/EntityAssociationLoader-test.js +0 -30
- package/build/__tests__/EntityAssociationLoader-test.js.map +0 -1
- package/build/__tests__/EntityCommonUseCases-test.d.ts +0 -1
- package/build/__tests__/EntityCommonUseCases-test.js +0 -146
- package/build/__tests__/EntityCommonUseCases-test.js.map +0 -1
- package/build/__tests__/EntityCompanion-test.d.ts +0 -1
- package/build/__tests__/EntityCompanion-test.js +0 -77
- package/build/__tests__/EntityCompanion-test.js.map +0 -1
- package/build/__tests__/EntityCompanionProvider-test.d.ts +0 -1
- package/build/__tests__/EntityCompanionProvider-test.js +0 -54
- package/build/__tests__/EntityCompanionProvider-test.js.map +0 -1
- package/build/__tests__/EntityConfiguration-test.d.ts +0 -1
- package/build/__tests__/EntityConfiguration-test.js +0 -103
- package/build/__tests__/EntityConfiguration-test.js.map +0 -1
- package/build/__tests__/EntityDatabaseAdapter-test.d.ts +0 -1
- package/build/__tests__/EntityDatabaseAdapter-test.js +0 -146
- package/build/__tests__/EntityDatabaseAdapter-test.js.map +0 -1
- package/build/__tests__/EntityEdges-test.d.ts +0 -1
- package/build/__tests__/EntityEdges-test.js +0 -723
- package/build/__tests__/EntityEdges-test.js.map +0 -1
- package/build/__tests__/EntityFields-test.d.ts +0 -1
- package/build/__tests__/EntityFields-test.js +0 -63
- package/build/__tests__/EntityFields-test.js.map +0 -1
- package/build/__tests__/EntityLoader-test.d.ts +0 -1
- package/build/__tests__/EntityLoader-test.js +0 -36
- package/build/__tests__/EntityLoader-test.js.map +0 -1
- package/build/__tests__/EntityMutator-MutationCacheConsistency-test.d.ts +0 -1
- package/build/__tests__/EntityMutator-MutationCacheConsistency-test.js +0 -73
- package/build/__tests__/EntityMutator-MutationCacheConsistency-test.js.map +0 -1
- package/build/__tests__/EntityMutator-test.d.ts +0 -1
- package/build/__tests__/EntityMutator-test.js +0 -741
- package/build/__tests__/EntityMutator-test.js.map +0 -1
- package/build/__tests__/EntityPrivacyPolicy-test.d.ts +0 -1
- package/build/__tests__/EntityPrivacyPolicy-test.js +0 -463
- package/build/__tests__/EntityPrivacyPolicy-test.js.map +0 -1
- package/build/__tests__/EntityQueryContext-test.d.ts +0 -1
- package/build/__tests__/EntityQueryContext-test.js +0 -116
- package/build/__tests__/EntityQueryContext-test.js.map +0 -1
- package/build/__tests__/EntitySecondaryCacheLoader-test.d.ts +0 -1
- package/build/__tests__/EntitySecondaryCacheLoader-test.js +0 -60
- package/build/__tests__/EntitySecondaryCacheLoader-test.js.map +0 -1
- package/build/__tests__/EntitySelfReferentialEdges-test.d.ts +0 -1
- package/build/__tests__/EntitySelfReferentialEdges-test.js +0 -201
- package/build/__tests__/EntitySelfReferentialEdges-test.js.map +0 -1
- package/build/__tests__/GenericEntityCacheAdapter-test.d.ts +0 -1
- package/build/__tests__/GenericEntityCacheAdapter-test.js +0 -80
- package/build/__tests__/GenericEntityCacheAdapter-test.js.map +0 -1
- package/build/__tests__/ReadonlyEntity-test.d.ts +0 -1
- package/build/__tests__/ReadonlyEntity-test.js +0 -211
- package/build/__tests__/ReadonlyEntity-test.js.map +0 -1
- package/build/__tests__/ViewerContext-test.d.ts +0 -1
- package/build/__tests__/ViewerContext-test.js +0 -30
- package/build/__tests__/ViewerContext-test.js.map +0 -1
- package/build/__tests__/ViewerScopedEntityCompanion-test.d.ts +0 -1
- package/build/__tests__/ViewerScopedEntityCompanion-test.js +0 -20
- package/build/__tests__/ViewerScopedEntityCompanion-test.js.map +0 -1
- package/build/__tests__/ViewerScopedEntityCompanionProvider-test.d.ts +0 -1
- package/build/__tests__/ViewerScopedEntityCompanionProvider-test.js +0 -20
- package/build/__tests__/ViewerScopedEntityCompanionProvider-test.js.map +0 -1
- package/build/__tests__/ViewerScopedEntityLoaderFactory-test.d.ts +0 -1
- package/build/__tests__/ViewerScopedEntityLoaderFactory-test.js +0 -23
- package/build/__tests__/ViewerScopedEntityLoaderFactory-test.js.map +0 -1
- package/build/__tests__/ViewerScopedEntityMutatorFactory-test.d.ts +0 -1
- package/build/__tests__/ViewerScopedEntityMutatorFactory-test.js +0 -22
- package/build/__tests__/ViewerScopedEntityMutatorFactory-test.js.map +0 -1
- package/build/__tests__/cases/TwoEntitySameTableDisjointRows-test.d.ts +0 -1
- package/build/__tests__/cases/TwoEntitySameTableDisjointRows-test.js +0 -123
- package/build/__tests__/cases/TwoEntitySameTableDisjointRows-test.js.map +0 -1
- package/build/__tests__/cases/TwoEntitySameTableOverlappingRows-test.d.ts +0 -1
- package/build/__tests__/cases/TwoEntitySameTableOverlappingRows-test.js +0 -121
- package/build/__tests__/cases/TwoEntitySameTableOverlappingRows-test.js.map +0 -1
- package/build/__tests__/entityUtils-test.d.ts +0 -1
- package/build/__tests__/entityUtils-test.js +0 -87
- package/build/__tests__/entityUtils-test.js.map +0 -1
- package/build/internal/__tests__/EntityDataManager-test.d.ts +0 -1
- package/build/internal/__tests__/EntityDataManager-test.js +0 -373
- package/build/internal/__tests__/EntityDataManager-test.js.map +0 -1
- package/build/internal/__tests__/EntityFieldTransformationUtils-test.d.ts +0 -1
- package/build/internal/__tests__/EntityFieldTransformationUtils-test.js +0 -136
- package/build/internal/__tests__/EntityFieldTransformationUtils-test.js.map +0 -1
- package/build/internal/__tests__/ReadThroughEntityCache-test.d.ts +0 -1
- package/build/internal/__tests__/ReadThroughEntityCache-test.js +0 -206
- package/build/internal/__tests__/ReadThroughEntityCache-test.js.map +0 -1
- package/build/rules/__tests__/AlwaysAllowPrivacyPolicyRule-test.d.ts +0 -1
- package/build/rules/__tests__/AlwaysAllowPrivacyPolicyRule-test.js +0 -21
- package/build/rules/__tests__/AlwaysAllowPrivacyPolicyRule-test.js.map +0 -1
- package/build/rules/__tests__/AlwaysDenyPrivacyPolicyRule-test.d.ts +0 -1
- package/build/rules/__tests__/AlwaysDenyPrivacyPolicyRule-test.js +0 -21
- package/build/rules/__tests__/AlwaysDenyPrivacyPolicyRule-test.js.map +0 -1
- package/build/rules/__tests__/AlwaysSkipPrivacyPolicyRule-test.d.ts +0 -1
- package/build/rules/__tests__/AlwaysSkipPrivacyPolicyRule-test.js +0 -21
- package/build/rules/__tests__/AlwaysSkipPrivacyPolicyRule-test.js.map +0 -1
- package/build/testfixtures/DateIDTestEntity.d.ts +0 -19
- package/build/testfixtures/DateIDTestEntity.js +0 -48
- package/build/testfixtures/DateIDTestEntity.js.map +0 -1
- package/build/testfixtures/SimpleTestEntity.d.ts +0 -20
- package/build/testfixtures/SimpleTestEntity.js +0 -48
- package/build/testfixtures/SimpleTestEntity.js.map +0 -1
- package/build/testfixtures/TestEntity.d.ts +0 -30
- package/build/testfixtures/TestEntity.js +0 -93
- package/build/testfixtures/TestEntity.js.map +0 -1
- package/build/testfixtures/TestEntity2.d.ts +0 -20
- package/build/testfixtures/TestEntity2.js +0 -51
- package/build/testfixtures/TestEntity2.js.map +0 -1
- package/build/testfixtures/TestEntityNumberKey.d.ts +0 -19
- package/build/testfixtures/TestEntityNumberKey.js +0 -48
- package/build/testfixtures/TestEntityNumberKey.js.map +0 -1
- package/build/testfixtures/TestEntityWithMutationTriggers.d.ts +0 -36
- package/build/testfixtures/TestEntityWithMutationTriggers.js +0 -82
- package/build/testfixtures/TestEntityWithMutationTriggers.js.map +0 -1
- package/build/testfixtures/TestViewerContext.d.ts +0 -3
- package/build/testfixtures/TestViewerContext.js +0 -10
- package/build/testfixtures/TestViewerContext.js.map +0 -1
- package/build/utils/__tests__/EntityPrivacyUtils-test.d.ts +0 -1
- package/build/utils/__tests__/EntityPrivacyUtils-test.js +0 -486
- package/build/utils/__tests__/EntityPrivacyUtils-test.js.map +0 -1
- package/build/utils/__tests__/canViewerDeleteAsync-edgeDeletionPermissionInferenceBehavior-test.d.ts +0 -1
- package/build/utils/__tests__/canViewerDeleteAsync-edgeDeletionPermissionInferenceBehavior-test.js +0 -178
- package/build/utils/__tests__/canViewerDeleteAsync-edgeDeletionPermissionInferenceBehavior-test.js.map +0 -1
- package/build/utils/__tests__/mergeEntityMutationTriggerConfigurations-test.d.ts +0 -1
- package/build/utils/__tests__/mergeEntityMutationTriggerConfigurations-test.js +0 -26
- package/build/utils/__tests__/mergeEntityMutationTriggerConfigurations-test.js.map +0 -1
- package/build/utils/collections/__tests__/maps-test.d.ts +0 -1
- package/build/utils/collections/__tests__/maps-test.js +0 -120
- package/build/utils/collections/__tests__/maps-test.js.map +0 -1
- package/build/utils/testing/PrivacyPolicyRuleTestUtils.d.ts +0 -28
- package/build/utils/testing/PrivacyPolicyRuleTestUtils.js +0 -52
- package/build/utils/testing/PrivacyPolicyRuleTestUtils.js.map +0 -1
- package/build/utils/testing/StubCacheAdapter.d.ts +0 -27
- package/build/utils/testing/StubCacheAdapter.js +0 -86
- package/build/utils/testing/StubCacheAdapter.js.map +0 -1
- package/build/utils/testing/StubDatabaseAdapter.d.ts +0 -25
- package/build/utils/testing/StubDatabaseAdapter.js +0 -191
- package/build/utils/testing/StubDatabaseAdapter.js.map +0 -1
- package/build/utils/testing/StubDatabaseAdapterProvider.d.ts +0 -7
- package/build/utils/testing/StubDatabaseAdapterProvider.js +0 -14
- package/build/utils/testing/StubDatabaseAdapterProvider.js.map +0 -1
- package/build/utils/testing/StubQueryContextProvider.d.ts +0 -7
- package/build/utils/testing/StubQueryContextProvider.js +0 -19
- package/build/utils/testing/StubQueryContextProvider.js.map +0 -1
- package/build/utils/testing/__tests__/PrivacyPolicyRuleTestUtils-test.d.ts +0 -1
- package/build/utils/testing/__tests__/PrivacyPolicyRuleTestUtils-test.js +0 -42
- package/build/utils/testing/__tests__/PrivacyPolicyRuleTestUtils-test.js.map +0 -1
- package/build/utils/testing/__tests__/StubDatabaseAdapter-test.d.ts +0 -1
- package/build/utils/testing/__tests__/StubDatabaseAdapter-test.js +0 -402
- package/build/utils/testing/__tests__/StubDatabaseAdapter-test.js.map +0 -1
- package/build/utils/testing/createUnitTestEntityCompanionProvider.d.ts +0 -7
- package/build/utils/testing/createUnitTestEntityCompanionProvider.js +0 -36
- package/build/utils/testing/createUnitTestEntityCompanionProvider.js.map +0 -1
- package/build/utils/testing/describeFieldTestCase.d.ts +0 -2
- package/build/utils/testing/describeFieldTestCase.js +0 -18
- package/build/utils/testing/describeFieldTestCase.js.map +0 -1
- package/src/testfixtures/DateIDTestEntity.ts +0 -59
- package/src/testfixtures/TestEntityNumberKey.ts +0 -59
- package/src/utils/testing/StubCacheAdapter.ts +0 -122
- package/src/utils/testing/__tests__/PrivacyPolicyRuleTestUtils-test.ts +0 -42
- package/src/utils/testing/__tests__/StubDatabaseAdapter-test.ts +0 -548
- /package/src/utils/{testing → __testfixtures__}/StubQueryContextProvider.ts +0 -0
- /package/src/utils/{testing → __testfixtures__}/createUnitTestEntityCompanionProvider.ts +0 -0
package/src/EntityCreator.ts
CHANGED
|
@@ -10,14 +10,14 @@ import ViewerContext from './ViewerContext';
|
|
|
10
10
|
* The primary interface for creating entities.
|
|
11
11
|
*/
|
|
12
12
|
export default class EntityCreator<
|
|
13
|
-
TFields extends
|
|
14
|
-
|
|
13
|
+
TFields extends Record<string, any>,
|
|
14
|
+
TIDField extends keyof NonNullable<Pick<TFields, TSelectedFields>>,
|
|
15
15
|
TViewerContext extends ViewerContext,
|
|
16
16
|
TViewerContext2 extends TViewerContext,
|
|
17
|
-
TEntity extends ReadonlyEntity<TFields,
|
|
17
|
+
TEntity extends ReadonlyEntity<TFields, TIDField, TViewerContext, TSelectedFields>,
|
|
18
18
|
TPrivacyPolicy extends EntityPrivacyPolicy<
|
|
19
19
|
TFields,
|
|
20
|
-
|
|
20
|
+
TIDField,
|
|
21
21
|
TViewerContext,
|
|
22
22
|
TEntity,
|
|
23
23
|
TSelectedFields
|
|
@@ -29,7 +29,7 @@ export default class EntityCreator<
|
|
|
29
29
|
private readonly queryContext: EntityQueryContext,
|
|
30
30
|
private readonly entityClass: IEntityClass<
|
|
31
31
|
TFields,
|
|
32
|
-
|
|
32
|
+
TIDField,
|
|
33
33
|
TViewerContext,
|
|
34
34
|
TEntity,
|
|
35
35
|
TPrivacyPolicy,
|
|
@@ -43,7 +43,7 @@ export default class EntityCreator<
|
|
|
43
43
|
*/
|
|
44
44
|
enforcing(): EnforcingEntityCreator<
|
|
45
45
|
TFields,
|
|
46
|
-
|
|
46
|
+
TIDField,
|
|
47
47
|
TViewerContext,
|
|
48
48
|
TEntity,
|
|
49
49
|
TPrivacyPolicy,
|
|
@@ -59,7 +59,7 @@ export default class EntityCreator<
|
|
|
59
59
|
*/
|
|
60
60
|
withAuthorizationResults(): AuthorizationResultBasedCreateMutator<
|
|
61
61
|
TFields,
|
|
62
|
-
|
|
62
|
+
TIDField,
|
|
63
63
|
TViewerContext,
|
|
64
64
|
TEntity,
|
|
65
65
|
TPrivacyPolicy,
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import invariant from 'invariant';
|
|
2
|
+
|
|
1
3
|
import EntityConfiguration from './EntityConfiguration';
|
|
2
4
|
import { EntityQueryContext } from './EntityQueryContext';
|
|
3
5
|
import {
|
|
@@ -6,12 +8,13 @@ import {
|
|
|
6
8
|
transformFieldsToDatabaseObject,
|
|
7
9
|
FieldTransformerMap,
|
|
8
10
|
} from './internal/EntityFieldTransformationUtils';
|
|
11
|
+
import { IEntityLoadKey, IEntityLoadValue } from './internal/EntityLoadInterfaces';
|
|
9
12
|
|
|
10
13
|
/**
|
|
11
14
|
* Equality operand that is used for selecting entities with a field with a single value.
|
|
12
15
|
*/
|
|
13
16
|
export interface SingleValueFieldEqualityCondition<
|
|
14
|
-
TFields,
|
|
17
|
+
TFields extends Record<string, any>,
|
|
15
18
|
N extends keyof TFields = keyof TFields,
|
|
16
19
|
> {
|
|
17
20
|
fieldName: N;
|
|
@@ -22,7 +25,7 @@ export interface SingleValueFieldEqualityCondition<
|
|
|
22
25
|
* Equality operand that is used for selecting entities with a field matching one of multiple values.
|
|
23
26
|
*/
|
|
24
27
|
export interface MultiValueFieldEqualityCondition<
|
|
25
|
-
TFields,
|
|
28
|
+
TFields extends Record<string, any>,
|
|
26
29
|
N extends keyof TFields = keyof TFields,
|
|
27
30
|
> {
|
|
28
31
|
fieldName: N;
|
|
@@ -33,12 +36,13 @@ export interface MultiValueFieldEqualityCondition<
|
|
|
33
36
|
* A single equality operand for use in a selection clause.
|
|
34
37
|
* See EntityLoader.loadManyByFieldEqualityConjunctionAsync documentation for examples.
|
|
35
38
|
*/
|
|
36
|
-
export type FieldEqualityCondition<
|
|
37
|
-
|
|
38
|
-
|
|
39
|
+
export type FieldEqualityCondition<
|
|
40
|
+
TFields extends Record<string, any>,
|
|
41
|
+
N extends keyof TFields = keyof TFields,
|
|
42
|
+
> = SingleValueFieldEqualityCondition<TFields, N> | MultiValueFieldEqualityCondition<TFields, N>;
|
|
39
43
|
|
|
40
44
|
export function isSingleValueFieldEqualityCondition<
|
|
41
|
-
TFields,
|
|
45
|
+
TFields extends Record<string, any>,
|
|
42
46
|
N extends keyof TFields = keyof TFields,
|
|
43
47
|
>(
|
|
44
48
|
condition: FieldEqualityCondition<TFields, N>,
|
|
@@ -64,7 +68,7 @@ export enum OrderByOrdering {
|
|
|
64
68
|
/**
|
|
65
69
|
* SQL modifiers that only affect the selection but not the projection.
|
|
66
70
|
*/
|
|
67
|
-
export interface QuerySelectionModifiers<TFields
|
|
71
|
+
export interface QuerySelectionModifiers<TFields extends Record<string, any>> {
|
|
68
72
|
/**
|
|
69
73
|
* Order the entities by specified columns and orders.
|
|
70
74
|
*/
|
|
@@ -84,7 +88,7 @@ export interface QuerySelectionModifiers<TFields> {
|
|
|
84
88
|
limit?: number;
|
|
85
89
|
}
|
|
86
90
|
|
|
87
|
-
export interface QuerySelectionModifiersWithOrderByRaw<TFields
|
|
91
|
+
export interface QuerySelectionModifiersWithOrderByRaw<TFields extends Record<string, any>>
|
|
88
92
|
extends QuerySelectionModifiers<TFields> {
|
|
89
93
|
/**
|
|
90
94
|
* Order the entities by a raw SQL `ORDER BY` clause.
|
|
@@ -113,10 +117,13 @@ export interface TableQuerySelectionModifiersWithOrderByRaw extends TableQuerySe
|
|
|
113
117
|
* handles all entity field transformation. Subclasses are responsible for
|
|
114
118
|
* implementing database-specific logic for a type of database.
|
|
115
119
|
*/
|
|
116
|
-
export default abstract class EntityDatabaseAdapter<
|
|
120
|
+
export default abstract class EntityDatabaseAdapter<
|
|
121
|
+
TFields extends Record<string, any>,
|
|
122
|
+
TIDField extends keyof TFields,
|
|
123
|
+
> {
|
|
117
124
|
private readonly fieldTransformerMap: FieldTransformerMap;
|
|
118
125
|
|
|
119
|
-
constructor(private readonly entityConfiguration: EntityConfiguration<TFields>) {
|
|
126
|
+
constructor(private readonly entityConfiguration: EntityConfiguration<TFields, TIDField>) {
|
|
120
127
|
this.fieldTransformerMap = this.getFieldTransformerMap();
|
|
121
128
|
}
|
|
122
129
|
|
|
@@ -128,37 +135,53 @@ export default abstract class EntityDatabaseAdapter<TFields extends Record<strin
|
|
|
128
135
|
protected abstract getFieldTransformerMap(): FieldTransformerMap;
|
|
129
136
|
|
|
130
137
|
/**
|
|
131
|
-
* Fetch many objects where
|
|
138
|
+
* Fetch many objects where key is one of values.
|
|
132
139
|
*
|
|
133
140
|
* @param queryContext - query context with which to perform the fetch
|
|
134
|
-
* @param
|
|
135
|
-
* @param
|
|
136
|
-
* @returns map from
|
|
141
|
+
* @param key - load key being queried
|
|
142
|
+
* @param values - load values being queried
|
|
143
|
+
* @returns map from value to objects that match the query for that value
|
|
137
144
|
*/
|
|
138
|
-
async fetchManyWhereAsync<
|
|
145
|
+
async fetchManyWhereAsync<
|
|
146
|
+
TLoadKey extends IEntityLoadKey<TFields, TIDField, TSerializedLoadValue, TLoadValue>,
|
|
147
|
+
TSerializedLoadValue,
|
|
148
|
+
TLoadValue extends IEntityLoadValue<TSerializedLoadValue>,
|
|
149
|
+
>(
|
|
139
150
|
queryContext: EntityQueryContext,
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
): Promise<ReadonlyMap<
|
|
143
|
-
const
|
|
151
|
+
key: TLoadKey,
|
|
152
|
+
values: readonly TLoadValue[],
|
|
153
|
+
): Promise<ReadonlyMap<TLoadValue, readonly Readonly<TFields>[]>> {
|
|
154
|
+
const keyDatabaseColumns = key.getDatabaseColumns(this.entityConfiguration);
|
|
155
|
+
const valueDatabaseValues = values.map((value) => key.getDatabaseValues(value));
|
|
156
|
+
|
|
144
157
|
const results = await this.fetchManyWhereInternalAsync(
|
|
145
158
|
queryContext.getQueryInterface(),
|
|
146
159
|
this.entityConfiguration.tableName,
|
|
147
|
-
|
|
148
|
-
|
|
160
|
+
keyDatabaseColumns,
|
|
161
|
+
valueDatabaseValues,
|
|
149
162
|
);
|
|
163
|
+
|
|
150
164
|
const objects = results.map((result) =>
|
|
151
165
|
transformDatabaseObjectToFields(this.entityConfiguration, this.fieldTransformerMap, result),
|
|
152
166
|
);
|
|
153
167
|
|
|
154
|
-
const objectMap =
|
|
155
|
-
for (const
|
|
156
|
-
objectMap.set(
|
|
168
|
+
const objectMap = key.vendNewLoadValueMap<Readonly<TFields>[]>();
|
|
169
|
+
for (const value of values) {
|
|
170
|
+
objectMap.set(value, []);
|
|
157
171
|
}
|
|
158
172
|
|
|
159
173
|
objects.forEach((object) => {
|
|
160
|
-
const
|
|
161
|
-
|
|
174
|
+
const objectMapKeyForObject = key.getLoadValueForObject(object);
|
|
175
|
+
invariant(
|
|
176
|
+
objectMapKeyForObject !== null,
|
|
177
|
+
`One or more fields from the object is invalid for key ${key}; ${JSON.stringify(object)}. This may indicate a faulty database adapter implementation.`,
|
|
178
|
+
);
|
|
179
|
+
const objectList = objectMap.get(objectMapKeyForObject);
|
|
180
|
+
invariant(
|
|
181
|
+
objectList !== undefined,
|
|
182
|
+
`Unexpected object field value during database result transformation: ${objectMapKeyForObject}. This should never happen.`,
|
|
183
|
+
);
|
|
184
|
+
objectList.push(object);
|
|
162
185
|
});
|
|
163
186
|
|
|
164
187
|
return objectMap;
|
|
@@ -167,8 +190,8 @@ export default abstract class EntityDatabaseAdapter<TFields extends Record<strin
|
|
|
167
190
|
protected abstract fetchManyWhereInternalAsync(
|
|
168
191
|
queryInterface: any,
|
|
169
192
|
tableName: string,
|
|
170
|
-
|
|
171
|
-
|
|
193
|
+
tableColumns: readonly string[],
|
|
194
|
+
tableTuples: (readonly any[])[],
|
|
172
195
|
): Promise<object[]>;
|
|
173
196
|
|
|
174
197
|
/**
|
package/src/EntityDeleter.ts
CHANGED
|
@@ -10,13 +10,13 @@ import ViewerContext from './ViewerContext';
|
|
|
10
10
|
* The primary interface for deleting entities.
|
|
11
11
|
*/
|
|
12
12
|
export default class EntityDeleter<
|
|
13
|
-
TFields extends
|
|
14
|
-
|
|
13
|
+
TFields extends Record<string, any>,
|
|
14
|
+
TIDField extends keyof NonNullable<Pick<TFields, TSelectedFields>>,
|
|
15
15
|
TViewerContext extends ViewerContext,
|
|
16
|
-
TEntity extends ReadonlyEntity<TFields,
|
|
16
|
+
TEntity extends ReadonlyEntity<TFields, TIDField, TViewerContext, TSelectedFields>,
|
|
17
17
|
TPrivacyPolicy extends EntityPrivacyPolicy<
|
|
18
18
|
TFields,
|
|
19
|
-
|
|
19
|
+
TIDField,
|
|
20
20
|
TViewerContext,
|
|
21
21
|
TEntity,
|
|
22
22
|
TSelectedFields
|
|
@@ -28,7 +28,7 @@ export default class EntityDeleter<
|
|
|
28
28
|
private readonly queryContext: EntityQueryContext,
|
|
29
29
|
private readonly entityClass: IEntityClass<
|
|
30
30
|
TFields,
|
|
31
|
-
|
|
31
|
+
TIDField,
|
|
32
32
|
TViewerContext,
|
|
33
33
|
TEntity,
|
|
34
34
|
TPrivacyPolicy,
|
|
@@ -42,7 +42,7 @@ export default class EntityDeleter<
|
|
|
42
42
|
*/
|
|
43
43
|
enforcing(): EnforcingEntityDeleter<
|
|
44
44
|
TFields,
|
|
45
|
-
|
|
45
|
+
TIDField,
|
|
46
46
|
TViewerContext,
|
|
47
47
|
TEntity,
|
|
48
48
|
TPrivacyPolicy,
|
|
@@ -58,7 +58,7 @@ export default class EntityDeleter<
|
|
|
58
58
|
*/
|
|
59
59
|
withAuthorizationResults(): AuthorizationResultBasedDeleteMutator<
|
|
60
60
|
TFields,
|
|
61
|
-
|
|
61
|
+
TIDField,
|
|
62
62
|
TViewerContext,
|
|
63
63
|
TEntity,
|
|
64
64
|
TPrivacyPolicy,
|
|
@@ -71,16 +71,16 @@ export enum EntityEdgeDeletionAuthorizationInferenceBehavior {
|
|
|
71
71
|
export interface EntityAssociationDefinition<
|
|
72
72
|
TViewerContext extends ViewerContext,
|
|
73
73
|
TAssociatedFields extends object,
|
|
74
|
-
|
|
74
|
+
TAssociatedIDField extends keyof NonNullable<Pick<TAssociatedFields, TAssociatedSelectedFields>>,
|
|
75
75
|
TAssociatedEntity extends ReadonlyEntity<
|
|
76
76
|
TAssociatedFields,
|
|
77
|
-
|
|
77
|
+
TAssociatedIDField,
|
|
78
78
|
TViewerContext,
|
|
79
79
|
TAssociatedSelectedFields
|
|
80
80
|
>,
|
|
81
81
|
TAssociatedPrivacyPolicy extends EntityPrivacyPolicy<
|
|
82
82
|
TAssociatedFields,
|
|
83
|
-
|
|
83
|
+
TAssociatedIDField,
|
|
84
84
|
TViewerContext,
|
|
85
85
|
TAssociatedEntity,
|
|
86
86
|
TAssociatedSelectedFields
|
|
@@ -92,7 +92,7 @@ export interface EntityAssociationDefinition<
|
|
|
92
92
|
*/
|
|
93
93
|
associatedEntityClass: IEntityClass<
|
|
94
94
|
TAssociatedFields,
|
|
95
|
-
|
|
95
|
+
TAssociatedIDField,
|
|
96
96
|
TViewerContext,
|
|
97
97
|
TAssociatedEntity,
|
|
98
98
|
TAssociatedPrivacyPolicy,
|
|
@@ -135,38 +135,58 @@ export interface EntityAssociationDefinition<
|
|
|
135
135
|
/**
|
|
136
136
|
* Options for EntityFieldDefinition
|
|
137
137
|
*/
|
|
138
|
-
export interface
|
|
138
|
+
export interface EntityFieldDefinitionOptionsBase {
|
|
139
139
|
/**
|
|
140
140
|
* Column name in the database.
|
|
141
141
|
*/
|
|
142
142
|
columnName: string;
|
|
143
143
|
|
|
144
|
+
/**
|
|
145
|
+
* Defines the association behavior for an entity that this column references.
|
|
146
|
+
*/
|
|
147
|
+
association?: EntityAssociationDefinition<any, any, any, any, any, any>;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export interface EntityFieldDefinitionOptionsExplicitCache
|
|
151
|
+
extends EntityFieldDefinitionOptionsBase {
|
|
144
152
|
/**
|
|
145
153
|
* Whether or not to cache loaded instances of the entity by this field. The column name is
|
|
146
154
|
* used to derive a cache key for the cache entry. If true, this column must be able uniquely
|
|
147
|
-
* identify the entity.
|
|
155
|
+
* identify the entity and the database must have a unique constraint on the column.
|
|
148
156
|
*/
|
|
149
|
-
cache
|
|
157
|
+
cache: boolean;
|
|
158
|
+
}
|
|
150
159
|
|
|
160
|
+
export interface EntityFieldDefinitionOptions extends EntityFieldDefinitionOptionsBase {
|
|
151
161
|
/**
|
|
152
|
-
*
|
|
162
|
+
* Whether or not to cache loaded instances of the entity by this field. The column name is
|
|
163
|
+
* used to derive a cache key for the cache entry. If true, this column must be able uniquely
|
|
164
|
+
* identify the entity and the database must have a unique constraint on the column.
|
|
153
165
|
*/
|
|
154
|
-
|
|
166
|
+
cache?: boolean;
|
|
155
167
|
}
|
|
156
168
|
|
|
157
169
|
/**
|
|
158
170
|
* Definition for a field referencing a column in the underlying database. Specifies things like
|
|
159
171
|
* cache behavior and associations, and handles input validation.
|
|
160
172
|
*/
|
|
161
|
-
export abstract class EntityFieldDefinition<T> {
|
|
173
|
+
export abstract class EntityFieldDefinition<T, TRequireExplicitCache extends boolean> {
|
|
162
174
|
readonly columnName: string;
|
|
163
175
|
readonly cache: boolean;
|
|
164
176
|
readonly association: EntityAssociationDefinition<any, any, any, any, any, any> | undefined;
|
|
177
|
+
|
|
178
|
+
// @ts-expect-error this is to ensure that different constructor requirements produce incompatible
|
|
179
|
+
// objects in the eyes of the type system
|
|
180
|
+
protected readonly _cacheRawSentinel: TRequireExplicitCache;
|
|
181
|
+
|
|
165
182
|
/**
|
|
166
|
-
*
|
|
167
183
|
* @param options - options for this field definition
|
|
168
184
|
*/
|
|
169
|
-
constructor(
|
|
185
|
+
constructor(
|
|
186
|
+
options: TRequireExplicitCache extends true
|
|
187
|
+
? EntityFieldDefinitionOptionsExplicitCache
|
|
188
|
+
: EntityFieldDefinitionOptions,
|
|
189
|
+
) {
|
|
170
190
|
this.columnName = options.columnName;
|
|
171
191
|
this.cache = options.cache ?? false;
|
|
172
192
|
this.association = options.association;
|
package/src/EntityFields.ts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
EntityFieldDefinition,
|
|
3
|
+
EntityFieldDefinitionOptions,
|
|
4
|
+
EntityFieldDefinitionOptionsExplicitCache,
|
|
5
|
+
} from './EntityFieldDefinition';
|
|
2
6
|
|
|
3
7
|
// Use our own regex since the `uuid` package doesn't support validating UUIDv6/7/8 yet
|
|
4
8
|
const UUID_REGEX =
|
|
@@ -7,7 +11,10 @@ const UUID_REGEX =
|
|
|
7
11
|
/**
|
|
8
12
|
* EntityFieldDefinition for a column with a JS string type.
|
|
9
13
|
*/
|
|
10
|
-
export class StringField extends EntityFieldDefinition<
|
|
14
|
+
export class StringField<TRequireExplicitCache extends boolean> extends EntityFieldDefinition<
|
|
15
|
+
string,
|
|
16
|
+
TRequireExplicitCache
|
|
17
|
+
> {
|
|
11
18
|
protected validateInputValueInternal(value: string): boolean {
|
|
12
19
|
return typeof value === 'string';
|
|
13
20
|
}
|
|
@@ -17,7 +24,9 @@ export class StringField extends EntityFieldDefinition<string> {
|
|
|
17
24
|
* EntityFieldDefinition for a column with a JS string type.
|
|
18
25
|
* Enforces that the string is a valid UUID.
|
|
19
26
|
*/
|
|
20
|
-
export class UUIDField
|
|
27
|
+
export class UUIDField<
|
|
28
|
+
TRequireExplicitCache extends boolean,
|
|
29
|
+
> extends StringField<TRequireExplicitCache> {
|
|
21
30
|
protected override validateInputValueInternal(value: string): boolean {
|
|
22
31
|
return super.validateInputValueInternal(value) && UUID_REGEX.test(value);
|
|
23
32
|
}
|
|
@@ -26,7 +35,10 @@ export class UUIDField extends StringField {
|
|
|
26
35
|
/**
|
|
27
36
|
* EntityFieldDefinition for a column with a JS Date type.
|
|
28
37
|
*/
|
|
29
|
-
export class DateField extends EntityFieldDefinition<
|
|
38
|
+
export class DateField<TRequireExplicitCache extends boolean> extends EntityFieldDefinition<
|
|
39
|
+
Date,
|
|
40
|
+
TRequireExplicitCache
|
|
41
|
+
> {
|
|
30
42
|
protected validateInputValueInternal(value: Date): boolean {
|
|
31
43
|
return value instanceof Date;
|
|
32
44
|
}
|
|
@@ -35,7 +47,10 @@ export class DateField extends EntityFieldDefinition<Date> {
|
|
|
35
47
|
/**
|
|
36
48
|
* EntityFieldDefinition for a column with a JS boolean type.
|
|
37
49
|
*/
|
|
38
|
-
export class BooleanField extends
|
|
50
|
+
export class BooleanField<TRequireExplicitCache extends boolean> extends EntityFieldDefinition<
|
|
51
|
+
boolean,
|
|
52
|
+
TRequireExplicitCache
|
|
53
|
+
> {
|
|
39
54
|
protected validateInputValueInternal(value: boolean): boolean {
|
|
40
55
|
return typeof value === 'boolean';
|
|
41
56
|
}
|
|
@@ -45,7 +60,10 @@ export class BooleanField extends EntityFieldDefinition<boolean> {
|
|
|
45
60
|
* EntityFieldDefinition for a column with a JS number type.
|
|
46
61
|
* Enforces that the number is an integer.
|
|
47
62
|
*/
|
|
48
|
-
export class IntField extends EntityFieldDefinition<
|
|
63
|
+
export class IntField<TRequireExplicitCache extends boolean> extends EntityFieldDefinition<
|
|
64
|
+
number,
|
|
65
|
+
TRequireExplicitCache
|
|
66
|
+
> {
|
|
49
67
|
protected validateInputValueInternal(value: number): boolean {
|
|
50
68
|
return typeof value === 'number' && Number.isInteger(value);
|
|
51
69
|
}
|
|
@@ -55,7 +73,10 @@ export class IntField extends EntityFieldDefinition<number> {
|
|
|
55
73
|
* EntityFieldDefinition for a column with a JS number type.
|
|
56
74
|
* Enforces that the number is a float (which includes integers in JS).
|
|
57
75
|
*/
|
|
58
|
-
export class FloatField extends EntityFieldDefinition<
|
|
76
|
+
export class FloatField<TRequireExplicitCache extends boolean> extends EntityFieldDefinition<
|
|
77
|
+
number,
|
|
78
|
+
TRequireExplicitCache
|
|
79
|
+
> {
|
|
59
80
|
protected validateInputValueInternal(value: number): boolean {
|
|
60
81
|
return typeof value === 'number';
|
|
61
82
|
}
|
|
@@ -65,7 +86,10 @@ export class FloatField extends EntityFieldDefinition<number> {
|
|
|
65
86
|
* EntityFieldDefinition for a column with a JS string array type.
|
|
66
87
|
* Enforces that every member of the string array is a string.
|
|
67
88
|
*/
|
|
68
|
-
export class StringArrayField extends EntityFieldDefinition<
|
|
89
|
+
export class StringArrayField<TRequireExplicitCache extends boolean> extends EntityFieldDefinition<
|
|
90
|
+
string[],
|
|
91
|
+
TRequireExplicitCache
|
|
92
|
+
> {
|
|
69
93
|
protected validateInputValueInternal(value: string[]): boolean {
|
|
70
94
|
return Array.isArray(value) && value.every((subValue) => typeof subValue === 'string');
|
|
71
95
|
}
|
|
@@ -74,7 +98,10 @@ export class StringArrayField extends EntityFieldDefinition<string[]> {
|
|
|
74
98
|
/**
|
|
75
99
|
* EntityFieldDefinition for a column with a JS JSON object type.
|
|
76
100
|
*/
|
|
77
|
-
export class JSONObjectField extends EntityFieldDefinition<
|
|
101
|
+
export class JSONObjectField<TRequireExplicitCache extends boolean> extends EntityFieldDefinition<
|
|
102
|
+
object,
|
|
103
|
+
TRequireExplicitCache
|
|
104
|
+
> {
|
|
78
105
|
protected validateInputValueInternal(value: object): boolean {
|
|
79
106
|
return typeof value === 'object' && !Array.isArray(value);
|
|
80
107
|
}
|
|
@@ -83,7 +110,10 @@ export class JSONObjectField extends EntityFieldDefinition<object> {
|
|
|
83
110
|
/**
|
|
84
111
|
* EntityFieldDefinition for a enum column with a JS string or number type.
|
|
85
112
|
*/
|
|
86
|
-
export class EnumField extends EntityFieldDefinition<
|
|
113
|
+
export class EnumField<TRequireExplicitCache extends boolean> extends EntityFieldDefinition<
|
|
114
|
+
string | number,
|
|
115
|
+
TRequireExplicitCache
|
|
116
|
+
> {
|
|
87
117
|
protected validateInputValueInternal(value: string | number): boolean {
|
|
88
118
|
return typeof value === 'number' || typeof value === 'string';
|
|
89
119
|
}
|
|
@@ -92,9 +122,16 @@ export class EnumField extends EntityFieldDefinition<string | number> {
|
|
|
92
122
|
/**
|
|
93
123
|
* EntityFieldDefinition for a enum column with a strict typescript enum type.
|
|
94
124
|
*/
|
|
95
|
-
export class StrictEnumField<
|
|
125
|
+
export class StrictEnumField<
|
|
126
|
+
T extends object,
|
|
127
|
+
TRequireExplicitCache extends boolean,
|
|
128
|
+
> extends EnumField<TRequireExplicitCache> {
|
|
96
129
|
private readonly enum: T;
|
|
97
|
-
constructor(
|
|
130
|
+
constructor(
|
|
131
|
+
options: TRequireExplicitCache extends true
|
|
132
|
+
? EntityFieldDefinitionOptionsExplicitCache & { enum: T }
|
|
133
|
+
: EntityFieldDefinitionOptions & { enum: T },
|
|
134
|
+
) {
|
|
98
135
|
super(options);
|
|
99
136
|
this.enum = options.enum;
|
|
100
137
|
}
|
package/src/EntityLoader.ts
CHANGED
|
@@ -12,14 +12,14 @@ import ViewerContext from './ViewerContext';
|
|
|
12
12
|
* cached, and authorized against the entity's EntityPrivacyPolicy.
|
|
13
13
|
*/
|
|
14
14
|
export default class EntityLoader<
|
|
15
|
-
TFields extends
|
|
16
|
-
|
|
15
|
+
TFields extends Record<string, any>,
|
|
16
|
+
TIDField extends keyof NonNullable<Pick<TFields, TSelectedFields>>,
|
|
17
17
|
TViewerContext extends ViewerContext,
|
|
18
18
|
TViewerContext2 extends TViewerContext,
|
|
19
|
-
TEntity extends ReadonlyEntity<TFields,
|
|
19
|
+
TEntity extends ReadonlyEntity<TFields, TIDField, TViewerContext, TSelectedFields>,
|
|
20
20
|
TPrivacyPolicy extends EntityPrivacyPolicy<
|
|
21
21
|
TFields,
|
|
22
|
-
|
|
22
|
+
TIDField,
|
|
23
23
|
TViewerContext,
|
|
24
24
|
TEntity,
|
|
25
25
|
TSelectedFields
|
|
@@ -31,7 +31,7 @@ export default class EntityLoader<
|
|
|
31
31
|
private readonly queryContext: EntityQueryContext,
|
|
32
32
|
private readonly entityClass: IEntityClass<
|
|
33
33
|
TFields,
|
|
34
|
-
|
|
34
|
+
TIDField,
|
|
35
35
|
TViewerContext,
|
|
36
36
|
TEntity,
|
|
37
37
|
TPrivacyPolicy,
|
|
@@ -46,7 +46,7 @@ export default class EntityLoader<
|
|
|
46
46
|
*/
|
|
47
47
|
enforcing(): EnforcingEntityLoader<
|
|
48
48
|
TFields,
|
|
49
|
-
|
|
49
|
+
TIDField,
|
|
50
50
|
TViewerContext,
|
|
51
51
|
TEntity,
|
|
52
52
|
TPrivacyPolicy,
|
|
@@ -62,7 +62,7 @@ export default class EntityLoader<
|
|
|
62
62
|
*/
|
|
63
63
|
withAuthorizationResults(): AuthorizationResultBasedEntityLoader<
|
|
64
64
|
TFields,
|
|
65
|
-
|
|
65
|
+
TIDField,
|
|
66
66
|
TViewerContext,
|
|
67
67
|
TEntity,
|
|
68
68
|
TPrivacyPolicy,
|
|
@@ -80,7 +80,7 @@ export default class EntityLoader<
|
|
|
80
80
|
*/
|
|
81
81
|
public utils(): EntityLoaderUtils<
|
|
82
82
|
TFields,
|
|
83
|
-
|
|
83
|
+
TIDField,
|
|
84
84
|
TViewerContext,
|
|
85
85
|
TEntity,
|
|
86
86
|
TPrivacyPolicy,
|
|
@@ -12,13 +12,13 @@ import IEntityMetricsAdapter from './metrics/IEntityMetricsAdapter';
|
|
|
12
12
|
* The primary entry point for loading entities.
|
|
13
13
|
*/
|
|
14
14
|
export default class EntityLoaderFactory<
|
|
15
|
-
TFields extends
|
|
16
|
-
|
|
15
|
+
TFields extends Record<string, any>,
|
|
16
|
+
TIDField extends keyof NonNullable<Pick<TFields, TSelectedFields>>,
|
|
17
17
|
TViewerContext extends ViewerContext,
|
|
18
|
-
TEntity extends ReadonlyEntity<TFields,
|
|
18
|
+
TEntity extends ReadonlyEntity<TFields, TIDField, TViewerContext, TSelectedFields>,
|
|
19
19
|
TPrivacyPolicy extends EntityPrivacyPolicy<
|
|
20
20
|
TFields,
|
|
21
|
-
|
|
21
|
+
TIDField,
|
|
22
22
|
TViewerContext,
|
|
23
23
|
TEntity,
|
|
24
24
|
TSelectedFields
|
|
@@ -28,13 +28,13 @@ export default class EntityLoaderFactory<
|
|
|
28
28
|
constructor(
|
|
29
29
|
private readonly entityCompanion: EntityCompanion<
|
|
30
30
|
TFields,
|
|
31
|
-
|
|
31
|
+
TIDField,
|
|
32
32
|
TViewerContext,
|
|
33
33
|
TEntity,
|
|
34
34
|
TPrivacyPolicy,
|
|
35
35
|
TSelectedFields
|
|
36
36
|
>,
|
|
37
|
-
private readonly dataManager: EntityDataManager<TFields>,
|
|
37
|
+
private readonly dataManager: EntityDataManager<TFields, TIDField>,
|
|
38
38
|
protected readonly metricsAdapter: IEntityMetricsAdapter,
|
|
39
39
|
) {}
|
|
40
40
|
|
|
@@ -48,14 +48,14 @@ export default class EntityLoaderFactory<
|
|
|
48
48
|
queryContext: EntityQueryContext,
|
|
49
49
|
privacyPolicyEvaluationContext: EntityPrivacyPolicyEvaluationContext<
|
|
50
50
|
TFields,
|
|
51
|
-
|
|
51
|
+
TIDField,
|
|
52
52
|
TViewerContext,
|
|
53
53
|
TEntity,
|
|
54
54
|
TSelectedFields
|
|
55
55
|
>,
|
|
56
56
|
): AuthorizationResultBasedEntityLoader<
|
|
57
57
|
TFields,
|
|
58
|
-
|
|
58
|
+
TIDField,
|
|
59
59
|
TViewerContext,
|
|
60
60
|
TEntity,
|
|
61
61
|
TPrivacyPolicy,
|