@expo/entity 0.31.0 → 0.32.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/ComposedEntityCacheAdapter.d.ts +4 -6
- package/build/ComposedEntityCacheAdapter.js +3 -6
- package/build/ComposedEntityCacheAdapter.js.map +1 -1
- package/build/EnforcingEntityLoader.d.ts +6 -1
- package/build/EnforcingEntityLoader.js +8 -0
- package/build/EnforcingEntityLoader.js.map +1 -1
- package/build/Entity.d.ts +20 -10
- package/build/Entity.js +2 -2
- package/build/Entity.js.map +1 -1
- package/build/EntityAssociationLoader.d.ts +9 -9
- package/build/EntityCompanion.d.ts +6 -5
- package/build/EntityCompanion.js +6 -4
- package/build/EntityCompanion.js.map +1 -1
- package/build/EntityCompanionProvider.d.ts +28 -36
- package/build/EntityCompanionProvider.js +4 -19
- package/build/EntityCompanionProvider.js.map +1 -1
- package/build/EntityConfiguration.d.ts +3 -3
- package/build/EntityConfiguration.js +2 -2
- package/build/EntityConfiguration.js.map +1 -1
- package/build/EntityDatabaseAdapter.d.ts +1 -1
- package/build/EntityDatabaseAdapter.js +1 -1
- package/build/EntityDatabaseAdapter.js.map +1 -1
- package/build/EntityFieldDefinition.d.ts +2 -2
- package/build/EntityFieldDefinition.js +1 -1
- package/build/EntityFieldDefinition.js.map +1 -1
- package/build/EntityLoader.d.ts +19 -2
- package/build/EntityLoader.js +41 -5
- package/build/EntityLoader.js.map +1 -1
- package/build/EntityLoaderFactory.d.ts +4 -7
- package/build/EntityLoaderFactory.js +3 -5
- package/build/EntityLoaderFactory.js.map +1 -1
- package/build/EntityMutationInfo.d.ts +3 -3
- package/build/EntityMutationInfo.js +1 -1
- package/build/EntityMutationInfo.js.map +1 -1
- package/build/EntityMutationTriggerConfiguration.d.ts +3 -3
- package/build/EntityMutationValidator.d.ts +1 -1
- package/build/EntityMutator.d.ts +9 -7
- package/build/EntityMutator.js +21 -21
- package/build/EntityMutator.js.map +1 -1
- package/build/EntityMutatorFactory.d.ts +4 -2
- package/build/EntityMutatorFactory.js +5 -4
- package/build/EntityMutatorFactory.js.map +1 -1
- package/build/EntityPrivacyPolicy.d.ts +3 -3
- package/build/EntityPrivacyPolicy.js +2 -2
- package/build/EntityPrivacyPolicy.js.map +1 -1
- package/build/EntityQueryContext.d.ts +13 -5
- package/build/EntityQueryContext.js +11 -4
- package/build/EntityQueryContext.js.map +1 -1
- package/build/EntityQueryContextProvider.d.ts +3 -3
- package/build/EntityQueryContextProvider.js +2 -2
- package/build/EntityQueryContextProvider.js.map +1 -1
- package/build/EntitySecondaryCacheLoader.d.ts +1 -1
- package/build/EntitySecondaryCacheLoader.js +1 -1
- package/build/EntitySecondaryCacheLoader.js.map +1 -1
- package/build/GenericEntityCacheAdapter.d.ts +14 -0
- package/build/GenericEntityCacheAdapter.js +38 -0
- package/build/GenericEntityCacheAdapter.js.map +1 -0
- package/build/{EntityCacheAdapter.d.ts → IEntityCacheAdapter.d.ts} +5 -8
- package/build/IEntityCacheAdapter.js +3 -0
- package/build/IEntityCacheAdapter.js.map +1 -0
- package/build/IEntityCacheAdapterProvider.d.ts +2 -2
- package/build/IEntityGenericCacher.d.ts +31 -2
- package/build/ReadonlyEntity.d.ts +19 -7
- package/build/ReadonlyEntity.js +15 -13
- package/build/ReadonlyEntity.js.map +1 -1
- package/build/ViewerContext.d.ts +3 -3
- package/build/ViewerContext.js +3 -3
- package/build/ViewerContext.js.map +1 -1
- package/build/ViewerScopedEntityCompanion.d.ts +2 -2
- package/build/ViewerScopedEntityCompanion.js.map +1 -1
- package/build/ViewerScopedEntityCompanionProvider.d.ts +3 -3
- package/build/ViewerScopedEntityCompanionProvider.js +3 -3
- package/build/ViewerScopedEntityCompanionProvider.js.map +1 -1
- package/build/ViewerScopedEntityLoaderFactory.d.ts +1 -1
- package/build/ViewerScopedEntityMutatorFactory.d.ts +1 -1
- package/build/__tests__/ComposedCacheAdapter-test.js +4 -8
- package/build/__tests__/ComposedCacheAdapter-test.js.map +1 -1
- package/build/__tests__/EnforcingEntityLoader-test.js +26 -0
- package/build/__tests__/EnforcingEntityLoader-test.js.map +1 -1
- package/build/__tests__/Entity-test.js +42 -20
- package/build/__tests__/Entity-test.js.map +1 -1
- package/build/__tests__/EntityAssociationLoader-test.js +6 -6
- package/build/__tests__/EntityAssociationLoader-test.js.map +1 -1
- package/build/__tests__/EntityCommonUseCases-test.js +20 -22
- package/build/__tests__/EntityCommonUseCases-test.js.map +1 -1
- package/build/__tests__/EntityCompanion-test.js +2 -1
- package/build/__tests__/EntityCompanion-test.js.map +1 -1
- package/build/__tests__/EntityCompanionProvider-test.js +15 -40
- package/build/__tests__/EntityCompanionProvider-test.js.map +1 -1
- package/build/__tests__/EntityEdges-test.js +48 -54
- package/build/__tests__/EntityEdges-test.js.map +1 -1
- package/build/__tests__/EntityLoader-constructor-test.d.ts +9 -5
- package/build/__tests__/EntityLoader-constructor-test.js +13 -14
- package/build/__tests__/EntityLoader-constructor-test.js.map +1 -1
- package/build/__tests__/EntityLoader-test.js +80 -10
- package/build/__tests__/EntityLoader-test.js.map +1 -1
- package/build/__tests__/EntityMutator-MutationCacheConsistency-test.js +20 -22
- package/build/__tests__/EntityMutator-MutationCacheConsistency-test.js.map +1 -1
- package/build/__tests__/EntityMutator-test.js +67 -14
- package/build/__tests__/EntityMutator-test.js.map +1 -1
- package/build/__tests__/EntityPrivacyPolicy-test.js +82 -29
- package/build/__tests__/EntityPrivacyPolicy-test.js.map +1 -1
- package/build/__tests__/EntityQueryContext-test.js +12 -0
- package/build/__tests__/EntityQueryContext-test.js.map +1 -1
- package/build/__tests__/EntitySecondaryCacheLoader-test.js +1 -2
- package/build/__tests__/EntitySecondaryCacheLoader-test.js.map +1 -1
- package/build/__tests__/EntitySelfReferentialEdges-test.js +16 -20
- package/build/__tests__/EntitySelfReferentialEdges-test.js.map +1 -1
- package/build/__tests__/GenericEntityCacheAdapter-test.d.ts +1 -0
- package/build/__tests__/GenericEntityCacheAdapter-test.js +80 -0
- package/build/__tests__/GenericEntityCacheAdapter-test.js.map +1 -0
- package/build/__tests__/ReadonlyEntity-test.js +79 -13
- package/build/__tests__/ReadonlyEntity-test.js.map +1 -1
- package/build/__tests__/ViewerScopedEntityCompanionProvider-test.js +2 -25
- package/build/__tests__/ViewerScopedEntityCompanionProvider-test.js.map +1 -1
- package/build/__tests__/cases/TwoEntitySameTableDisjointRows-test.js +20 -23
- package/build/__tests__/cases/TwoEntitySameTableDisjointRows-test.js.map +1 -1
- package/build/__tests__/cases/TwoEntitySameTableOverlappingRows-test.js +17 -20
- package/build/__tests__/cases/TwoEntitySameTableOverlappingRows-test.js.map +1 -1
- package/build/errors/EntityError.js +2 -2
- package/build/errors/EntityError.js.map +1 -1
- package/build/errors/EntityInvalidFieldValueError.d.ts +2 -2
- package/build/errors/EntityInvalidFieldValueError.js.map +1 -1
- package/build/errors/EntityNotAuthorizedError.d.ts +2 -2
- package/build/errors/EntityNotAuthorizedError.js +1 -1
- package/build/errors/EntityNotAuthorizedError.js.map +1 -1
- package/build/errors/EntityNotFoundError.d.ts +2 -2
- package/build/errors/EntityNotFoundError.js.map +1 -1
- package/build/index.d.ts +2 -1
- package/build/index.js +3 -3
- package/build/index.js.map +1 -1
- package/build/internal/EntityDataManager.d.ts +1 -1
- package/build/internal/EntityDataManager.js +1 -1
- package/build/internal/EntityDataManager.js.map +1 -1
- package/build/internal/EntityFieldTransformationUtils.d.ts +1 -1
- package/build/internal/EntityFieldTransformationUtils.js +4 -4
- package/build/internal/EntityFieldTransformationUtils.js.map +1 -1
- package/build/internal/EntityTableDataCoordinator.d.ts +3 -3
- package/build/internal/EntityTableDataCoordinator.js.map +1 -1
- package/build/internal/ReadThroughEntityCache.d.ts +3 -3
- package/build/internal/ReadThroughEntityCache.js +1 -1
- package/build/internal/ReadThroughEntityCache.js.map +1 -1
- package/build/internal/__tests__/EntityDataManager-test.js +1 -1
- package/build/internal/__tests__/EntityDataManager-test.js.map +1 -1
- package/build/internal/__tests__/ReadThroughEntityCache-test.js.map +1 -1
- package/build/metrics/EntityMetricsUtils.js.map +1 -1
- package/build/metrics/IEntityMetricsAdapter.js +4 -4
- 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 +1 -1
- package/build/rules/PrivacyPolicyRule.js +1 -1
- package/build/rules/PrivacyPolicyRule.js.map +1 -1
- package/build/testfixtures/DateIDTestEntity.d.ts +2 -3
- package/build/testfixtures/DateIDTestEntity.js +7 -9
- package/build/testfixtures/DateIDTestEntity.js.map +1 -1
- package/build/testfixtures/SimpleTestEntity.d.ts +3 -4
- package/build/testfixtures/SimpleTestEntity.js +7 -9
- package/build/testfixtures/SimpleTestEntity.js.map +1 -1
- package/build/testfixtures/TestEntity.d.ts +2 -3
- package/build/testfixtures/TestEntity.js +14 -10
- package/build/testfixtures/TestEntity.js.map +1 -1
- package/build/testfixtures/TestEntity2.d.ts +2 -3
- package/build/testfixtures/TestEntity2.js +7 -9
- package/build/testfixtures/TestEntity2.js.map +1 -1
- package/build/testfixtures/TestEntityNumberKey.d.ts +2 -3
- package/build/testfixtures/TestEntityNumberKey.js +7 -9
- package/build/testfixtures/TestEntityNumberKey.js.map +1 -1
- package/build/utils/testing/PrivacyPolicyRuleTestUtils.d.ts +4 -4
- package/build/utils/testing/StubCacheAdapter.d.ts +6 -5
- package/build/utils/testing/StubCacheAdapter.js +5 -6
- package/build/utils/testing/StubCacheAdapter.js.map +1 -1
- package/build/utils/testing/StubDatabaseAdapterProvider.js.map +1 -1
- package/build/utils/testing/StubQueryContextProvider.d.ts +2 -1
- package/build/utils/testing/StubQueryContextProvider.js +1 -1
- package/build/utils/testing/StubQueryContextProvider.js.map +1 -1
- package/build/utils/testing/createUnitTestEntityCompanionProvider.js +2 -2
- package/build/utils/testing/createUnitTestEntityCompanionProvider.js.map +1 -1
- package/package.json +3 -3
- package/src/ComposedEntityCacheAdapter.ts +4 -11
- package/src/EnforcingEntityLoader.ts +17 -1
- package/src/Entity.ts +23 -12
- package/src/EntityAssociationLoader.ts +12 -12
- package/src/EntityCompanion.ts +13 -32
- package/src/EntityCompanionProvider.ts +41 -80
- package/src/EntityConfiguration.ts +4 -5
- package/src/EntityFieldDefinition.ts +2 -2
- package/src/EntityLoader.ts +45 -2
- package/src/EntityLoaderFactory.ts +7 -9
- package/src/EntityMutationInfo.ts +2 -2
- package/src/EntityMutationTriggerConfiguration.ts +3 -3
- package/src/EntityMutationValidator.ts +1 -1
- package/src/EntityMutator.ts +38 -31
- package/src/EntityMutatorFactory.ts +6 -1
- package/src/EntityPrivacyPolicy.ts +2 -2
- package/src/EntityQueryContext.ts +24 -4
- package/src/EntityQueryContextProvider.ts +7 -5
- package/src/EntitySecondaryCacheLoader.ts +1 -1
- package/src/GenericEntityCacheAdapter.ts +65 -0
- package/src/{EntityCacheAdapter.ts → IEntityCacheAdapter.ts} +5 -8
- package/src/IEntityCacheAdapterProvider.ts +2 -2
- package/src/IEntityGenericCacher.ts +32 -2
- package/src/ReadonlyEntity.ts +32 -32
- package/src/ViewerContext.ts +10 -8
- package/src/ViewerScopedEntityCompanion.ts +2 -2
- package/src/ViewerScopedEntityCompanionProvider.ts +4 -12
- package/src/ViewerScopedEntityLoaderFactory.ts +1 -1
- package/src/ViewerScopedEntityMutatorFactory.ts +1 -1
- package/src/__tests__/ComposedCacheAdapter-test.ts +6 -11
- package/src/__tests__/EnforcingEntityLoader-test.ts +41 -0
- package/src/__tests__/Entity-test.ts +42 -21
- package/src/__tests__/EntityCommonUseCases-test.ts +20 -22
- package/src/__tests__/EntityCompanion-test.ts +6 -9
- package/src/__tests__/EntityCompanionProvider-test.ts +14 -26
- package/src/__tests__/EntityEdges-test.ts +43 -49
- package/src/__tests__/EntityLoader-constructor-test.ts +16 -12
- package/src/__tests__/EntityLoader-test.ts +105 -0
- package/src/__tests__/EntityMutator-MutationCacheConsistency-test.ts +20 -22
- package/src/__tests__/EntityMutator-test.ts +119 -19
- package/src/__tests__/EntityPrivacyPolicy-test.ts +82 -29
- package/src/__tests__/EntityQueryContext-test.ts +23 -1
- package/src/__tests__/EntitySelfReferentialEdges-test.ts +8 -10
- package/src/__tests__/GenericEntityCacheAdapter-test.ts +102 -0
- package/src/__tests__/ReadonlyEntity-test.ts +79 -13
- package/src/__tests__/ViewerScopedEntityCompanionProvider-test.ts +2 -5
- package/src/__tests__/cases/TwoEntitySameTableDisjointRows-test.ts +30 -24
- package/src/__tests__/cases/TwoEntitySameTableOverlappingRows-test.ts +14 -18
- package/src/errors/EntityInvalidFieldValueError.ts +2 -2
- package/src/errors/EntityNotAuthorizedError.ts +2 -2
- package/src/errors/EntityNotFoundError.ts +2 -2
- package/src/index.ts +2 -1
- package/src/internal/EntityDataManager.ts +1 -1
- package/src/internal/EntityTableDataCoordinator.ts +4 -4
- package/src/internal/ReadThroughEntityCache.ts +2 -2
- package/src/internal/__tests__/EntityDataManager-test.ts +2 -1
- package/src/internal/__tests__/ReadThroughEntityCache-test.ts +8 -8
- package/src/metrics/EntityMetricsUtils.ts +1 -1
- package/src/rules/AlwaysAllowPrivacyPolicyRule.ts +2 -2
- package/src/rules/AlwaysDenyPrivacyPolicyRule.ts +2 -2
- package/src/rules/AlwaysSkipPrivacyPolicyRule.ts +2 -2
- package/src/rules/PrivacyPolicyRule.ts +1 -1
- package/src/testfixtures/DateIDTestEntity.ts +6 -8
- package/src/testfixtures/SimpleTestEntity.ts +6 -8
- package/src/testfixtures/TestEntity.ts +19 -15
- package/src/testfixtures/TestEntity2.ts +6 -8
- package/src/testfixtures/TestEntityNumberKey.ts +6 -8
- package/src/utils/testing/PrivacyPolicyRuleTestUtils.ts +4 -4
- package/src/utils/testing/StubCacheAdapter.ts +9 -11
- package/src/utils/testing/StubDatabaseAdapterProvider.ts +1 -1
- package/src/utils/testing/StubQueryContextProvider.ts +4 -3
- package/src/utils/testing/createUnitTestEntityCompanionProvider.ts +3 -3
- package/build/EntityCacheAdapter.js +0 -13
- package/build/EntityCacheAdapter.js.map +0 -1
|
@@ -1,19 +1,17 @@
|
|
|
1
|
-
import
|
|
2
|
-
import EntityConfiguration from './EntityConfiguration';
|
|
1
|
+
import IEntityCacheAdapter from './IEntityCacheAdapter';
|
|
3
2
|
import { CacheLoadResult } from './internal/ReadThroughEntityCache';
|
|
4
3
|
/**
|
|
5
|
-
* A
|
|
4
|
+
* A IEntityCacheAdapter that composes other IEntityCacheAdapter instances.
|
|
6
5
|
*/
|
|
7
|
-
export default class ComposedEntityCacheAdapter<TFields>
|
|
6
|
+
export default class ComposedEntityCacheAdapter<TFields> implements IEntityCacheAdapter<TFields> {
|
|
8
7
|
private readonly cacheAdapters;
|
|
9
8
|
/**
|
|
10
|
-
* @param entityConfiguration - configuration for entity being loaded
|
|
11
9
|
* @param cacheAdapters - list of cache adapters to compose in order of precedence.
|
|
12
10
|
* Earlier cache adapters are read from first and written to (including invalidations) last.
|
|
13
11
|
* Typically, caches closer to the application should be ordered before caches closer to the database.
|
|
14
12
|
* A lower layer cache is closer to the database, while a higher layer cache is closer to the application.
|
|
15
13
|
*/
|
|
16
|
-
constructor(
|
|
14
|
+
constructor(cacheAdapters: IEntityCacheAdapter<TFields>[]);
|
|
17
15
|
loadManyAsync<N extends keyof TFields>(fieldName: N, fieldValues: readonly NonNullable<TFields[N]>[]): Promise<ReadonlyMap<NonNullable<TFields[N]>, CacheLoadResult<TFields>>>;
|
|
18
16
|
cacheManyAsync<N extends keyof TFields>(fieldName: N, objectMap: ReadonlyMap<NonNullable<TFields[N]>, Readonly<TFields>>): Promise<void>;
|
|
19
17
|
cacheDBMissesAsync<N extends keyof TFields>(fieldName: N, fieldValues: readonly NonNullable<TFields[N]>[]): Promise<void>;
|
|
@@ -4,21 +4,18 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const nullthrows_1 = __importDefault(require("nullthrows"));
|
|
7
|
-
const EntityCacheAdapter_1 = __importDefault(require("./EntityCacheAdapter"));
|
|
8
7
|
const ReadThroughEntityCache_1 = require("./internal/ReadThroughEntityCache");
|
|
9
8
|
/**
|
|
10
|
-
* A
|
|
9
|
+
* A IEntityCacheAdapter that composes other IEntityCacheAdapter instances.
|
|
11
10
|
*/
|
|
12
|
-
class ComposedEntityCacheAdapter
|
|
11
|
+
class ComposedEntityCacheAdapter {
|
|
13
12
|
/**
|
|
14
|
-
* @param entityConfiguration - configuration for entity being loaded
|
|
15
13
|
* @param cacheAdapters - list of cache adapters to compose in order of precedence.
|
|
16
14
|
* Earlier cache adapters are read from first and written to (including invalidations) last.
|
|
17
15
|
* Typically, caches closer to the application should be ordered before caches closer to the database.
|
|
18
16
|
* A lower layer cache is closer to the database, while a higher layer cache is closer to the application.
|
|
19
17
|
*/
|
|
20
|
-
constructor(
|
|
21
|
-
super(entityConfiguration);
|
|
18
|
+
constructor(cacheAdapters) {
|
|
22
19
|
this.cacheAdapters = cacheAdapters;
|
|
23
20
|
}
|
|
24
21
|
async loadManyAsync(fieldName, fieldValues) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ComposedEntityCacheAdapter.js","sourceRoot":"","sources":["../src/ComposedEntityCacheAdapter.ts"],"names":[],"mappings":";;;;;AAAA,4DAAoC;
|
|
1
|
+
{"version":3,"file":"ComposedEntityCacheAdapter.js","sourceRoot":"","sources":["../src/ComposedEntityCacheAdapter.ts"],"names":[],"mappings":";;;;;AAAA,4DAAoC;AAGpC,8EAAiF;AAEjF;;GAEG;AACH,MAAqB,0BAA0B;IAC7C;;;;;OAKG;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,EAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC;YACvD,MAAM,YAAY,CAAC,mBAAmB,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC;SAChE;IACH,CAAC;CACF;AA/GD,6CA+GC"}
|
|
@@ -7,7 +7,7 @@ import ViewerContext from './ViewerContext';
|
|
|
7
7
|
* Enforcing view on an entity loader. All loads through this loader will throw
|
|
8
8
|
* if the loads are not successful.
|
|
9
9
|
*/
|
|
10
|
-
export default class EnforcingEntityLoader<TFields, TID extends NonNullable<TFields[TSelectedFields]>, TViewerContext extends ViewerContext, TEntity extends ReadonlyEntity<TFields, TID, TViewerContext, TSelectedFields>, TPrivacyPolicy extends EntityPrivacyPolicy<TFields, TID, TViewerContext, TEntity, TSelectedFields>, TSelectedFields extends keyof TFields> {
|
|
10
|
+
export default class EnforcingEntityLoader<TFields extends object, TID extends NonNullable<TFields[TSelectedFields]>, TViewerContext extends ViewerContext, TEntity extends ReadonlyEntity<TFields, TID, TViewerContext, TSelectedFields>, TPrivacyPolicy extends EntityPrivacyPolicy<TFields, TID, TViewerContext, TEntity, TSelectedFields>, TSelectedFields extends keyof TFields> {
|
|
11
11
|
private readonly entityLoader;
|
|
12
12
|
constructor(entityLoader: EntityLoader<TFields, TID, TViewerContext, TEntity, TPrivacyPolicy, TSelectedFields>);
|
|
13
13
|
/**
|
|
@@ -42,6 +42,11 @@ export default class EnforcingEntityLoader<TFields, TID extends NonNullable<TFie
|
|
|
42
42
|
* @throws EntityNotAuthorizedError when viewer is not authorized to view one or more of the returned entities
|
|
43
43
|
*/
|
|
44
44
|
loadManyByIDsAsync(ids: readonly TID[]): Promise<ReadonlyMap<TID, TEntity>>;
|
|
45
|
+
/**
|
|
46
|
+
* Enforcing version of entity loader method by the same name.
|
|
47
|
+
* @throws EntityNotAuthorizedError when viewer is not authorized to view one or more of the returned entities
|
|
48
|
+
*/
|
|
49
|
+
loadFirstByFieldEqualityConjunctionAsync<N extends keyof Pick<TFields, TSelectedFields>>(fieldEqualityOperands: FieldEqualityCondition<TFields, N>[], querySelectionModifiers: Omit<QuerySelectionModifiers<TFields>, 'limit'> & Required<Pick<QuerySelectionModifiers<TFields>, 'orderBy'>>): Promise<TEntity | null>;
|
|
45
50
|
/**
|
|
46
51
|
* Enforcing version of entity loader method by the same name.
|
|
47
52
|
* @throws EntityNotAuthorizedError when viewer is not authorized to view one or more of the returned entities
|
|
@@ -59,6 +59,14 @@ class EnforcingEntityLoader {
|
|
|
59
59
|
const entityResults = await this.entityLoader.loadManyByIDsAsync(ids);
|
|
60
60
|
return (0, maps_1.mapMap)(entityResults, (result) => result.enforceValue());
|
|
61
61
|
}
|
|
62
|
+
/**
|
|
63
|
+
* Enforcing version of entity loader method by the same name.
|
|
64
|
+
* @throws EntityNotAuthorizedError when viewer is not authorized to view one or more of the returned entities
|
|
65
|
+
*/
|
|
66
|
+
async loadFirstByFieldEqualityConjunctionAsync(fieldEqualityOperands, querySelectionModifiers) {
|
|
67
|
+
const entityResult = await this.entityLoader.loadFirstByFieldEqualityConjunctionAsync(fieldEqualityOperands, querySelectionModifiers);
|
|
68
|
+
return entityResult ? entityResult.enforceValue() : null;
|
|
69
|
+
}
|
|
62
70
|
/**
|
|
63
71
|
* Enforcing version of entity loader method by the same name.
|
|
64
72
|
* @throws EntityNotAuthorizedError when viewer is not authorized to view one or more of the returned entities
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EnforcingEntityLoader.js","sourceRoot":"","sources":["../src/EnforcingEntityLoader.ts"],"names":[],"mappings":";;AASA,mDAAkD;AAElD;;;GAGG;AACH,MAAqB,qBAAqB;IAcxC,YACmB,YAOhB;QAPgB,iBAAY,GAAZ,YAAY,CAO5B;IACA,CAAC;IAEJ;;;OAGG;IACH,KAAK,CAAC,gCAAgC,CACpC,SAAY,EACZ,WAA+C;QAE/C,MAAM,oBAAoB,GAAG,MAAM,IAAI,CAAC,YAAY,CAAC,gCAAgC,CACnF,SAAS,EACT,WAA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,GAAG,CAAC,CAAC;QACtE,OAAO,IAAA,aAAM,EAAC,aAAa,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,YAAY,EAAE,CAAC,CAAC;IAClE,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,wCAAwC,CAC5C,qBAA2D,EAC3D,uBAC6D;QAE7D,MAAM,YAAY,GAAG,MAAM,IAAI,CAAC,YAAY,CAAC,wCAAwC,CACnF,qBAAqB,EACrB,uBAAuB,CACxB,CAAC;QACF,OAAO,YAAY,CAAC,CAAC,CAAC,YAAY,CAAC,YAAY,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;IAC3D,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,uCAAuC,CAC3C,qBAA2D,EAC3D,0BAA4D,EAAE;QAE9D,MAAM,aAAa,GAAG,MAAM,IAAI,CAAC,YAAY,CAAC,uCAAuC,CACnF,qBAAqB,EACrB,uBAAuB,CACxB,CAAC;QACF,OAAO,aAAa,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,YAAY,EAAE,CAAC,CAAC;IAC9D,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,6BAA6B,CACjC,cAAsB,EACtB,QAAwB,EACxB,0BAA0E,EAAE;QAE5E,MAAM,aAAa,GAAG,MAAM,IAAI,CAAC,YAAY,CAAC,6BAA6B,CACzE,cAAc,EACd,QAAQ,EACR,uBAAuB,CACxB,CAAC;QACF,OAAO,aAAa,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,YAAY,EAAE,CAAC,CAAC;IAC9D,CAAC;CACF;AApJD,wCAoJC"}
|
package/build/Entity.d.ts
CHANGED
|
@@ -23,33 +23,33 @@ import ViewerContext from './ViewerContext';
|
|
|
23
23
|
* All concrete entity implementations should extend this class and provide their
|
|
24
24
|
* own EntityCompanionDefinition.
|
|
25
25
|
*/
|
|
26
|
-
export default abstract class Entity<TFields, TID extends NonNullable<TFields[TSelectedFields]>, TViewerContext extends ViewerContext, TSelectedFields extends keyof TFields = keyof TFields> extends ReadonlyEntity<TFields, TID, TViewerContext, TSelectedFields> {
|
|
26
|
+
export default abstract class Entity<TFields extends object, TID extends NonNullable<TFields[TSelectedFields]>, TViewerContext extends ViewerContext, TSelectedFields extends keyof TFields = keyof TFields> extends ReadonlyEntity<TFields, TID, TViewerContext, TSelectedFields> {
|
|
27
27
|
/**
|
|
28
28
|
* Vend mutator for creating a new entity in given query context.
|
|
29
29
|
* @param viewerContext - viewer context of creating user
|
|
30
30
|
* @param queryContext - query context in which to perform the create
|
|
31
31
|
* @returns mutator for creating an entity
|
|
32
32
|
*/
|
|
33
|
-
static creator<TMFields, TMID extends NonNullable<TMFields[TMSelectedFields]>, TMViewerContext extends ViewerContext, TMViewerContext2 extends TMViewerContext, TMEntity extends Entity<TMFields, TMID, TMViewerContext, TMSelectedFields>, TMPrivacyPolicy extends EntityPrivacyPolicy<TMFields, TMID, TMViewerContext, TMEntity, TMSelectedFields>, TMSelectedFields extends keyof TMFields = keyof TMFields>(this: IEntityClass<TMFields, TMID, TMViewerContext, TMEntity, TMPrivacyPolicy, TMSelectedFields>, viewerContext: TMViewerContext2, queryContext?: EntityQueryContext): CreateMutator<TMFields, TMID, TMViewerContext, TMEntity, TMPrivacyPolicy, TMSelectedFields>;
|
|
33
|
+
static creator<TMFields extends object, TMID extends NonNullable<TMFields[TMSelectedFields]>, TMViewerContext extends ViewerContext, TMViewerContext2 extends TMViewerContext, TMEntity extends Entity<TMFields, TMID, TMViewerContext, TMSelectedFields>, TMPrivacyPolicy extends EntityPrivacyPolicy<TMFields, TMID, TMViewerContext, TMEntity, TMSelectedFields>, TMSelectedFields extends keyof TMFields = keyof TMFields>(this: IEntityClass<TMFields, TMID, TMViewerContext, TMEntity, TMPrivacyPolicy, TMSelectedFields>, viewerContext: TMViewerContext2, queryContext?: EntityQueryContext): CreateMutator<TMFields, TMID, TMViewerContext, TMEntity, TMPrivacyPolicy, TMSelectedFields>;
|
|
34
34
|
/**
|
|
35
35
|
* Vend mutator for updating an existing entity in given query context.
|
|
36
36
|
* @param existingEntity - entity to update
|
|
37
37
|
* @param queryContext - query context in which to perform the update
|
|
38
38
|
* @returns mutator for updating existingEntity
|
|
39
39
|
*/
|
|
40
|
-
static updater<TMFields, TMID extends NonNullable<TMFields[TMSelectedFields]>, TMViewerContext extends ViewerContext, TMEntity extends Entity<TMFields, TMID, TMViewerContext, TMSelectedFields>, TMPrivacyPolicy extends EntityPrivacyPolicy<TMFields, TMID, TMViewerContext, TMEntity, TMSelectedFields>, TMSelectedFields extends keyof TMFields = keyof TMFields>(this: IEntityClass<TMFields, TMID, TMViewerContext, TMEntity, TMPrivacyPolicy, TMSelectedFields>, existingEntity: TMEntity, queryContext?: EntityQueryContext): UpdateMutator<TMFields, TMID, TMViewerContext, TMEntity, TMPrivacyPolicy, TMSelectedFields>;
|
|
40
|
+
static updater<TMFields extends object, TMID extends NonNullable<TMFields[TMSelectedFields]>, TMViewerContext extends ViewerContext, TMEntity extends Entity<TMFields, TMID, TMViewerContext, TMSelectedFields>, TMPrivacyPolicy extends EntityPrivacyPolicy<TMFields, TMID, TMViewerContext, TMEntity, TMSelectedFields>, TMSelectedFields extends keyof TMFields = keyof TMFields>(this: IEntityClass<TMFields, TMID, TMViewerContext, TMEntity, TMPrivacyPolicy, TMSelectedFields>, existingEntity: TMEntity, queryContext?: EntityQueryContext): UpdateMutator<TMFields, TMID, TMViewerContext, TMEntity, TMPrivacyPolicy, TMSelectedFields>;
|
|
41
41
|
/**
|
|
42
42
|
* Delete an existing entity in given query context.
|
|
43
43
|
* @param existingEntity - entity to delete
|
|
44
44
|
* @param queryContext - query context in which to perform the delete
|
|
45
45
|
*/
|
|
46
|
-
static deleteAsync<TMFields, TMID extends NonNullable<TMFields[TMSelectedFields]>, TMViewerContext extends ViewerContext, TMEntity extends Entity<TMFields, TMID, TMViewerContext, TMSelectedFields>, TMPrivacyPolicy extends EntityPrivacyPolicy<TMFields, TMID, TMViewerContext, TMEntity, TMSelectedFields>, TMSelectedFields extends keyof TMFields = keyof TMFields>(this: IEntityClass<TMFields, TMID, TMViewerContext, TMEntity, TMPrivacyPolicy, TMSelectedFields>, existingEntity: TMEntity, queryContext?: EntityQueryContext): Promise<Result<void>>;
|
|
46
|
+
static deleteAsync<TMFields extends object, TMID extends NonNullable<TMFields[TMSelectedFields]>, TMViewerContext extends ViewerContext, TMEntity extends Entity<TMFields, TMID, TMViewerContext, TMSelectedFields>, TMPrivacyPolicy extends EntityPrivacyPolicy<TMFields, TMID, TMViewerContext, TMEntity, TMSelectedFields>, TMSelectedFields extends keyof TMFields = keyof TMFields>(this: IEntityClass<TMFields, TMID, TMViewerContext, TMEntity, TMPrivacyPolicy, TMSelectedFields>, existingEntity: TMEntity, queryContext?: EntityQueryContext): Promise<Result<void>>;
|
|
47
47
|
/**
|
|
48
48
|
* Delete an existing entity in given query context, throwing if deletion is unsuccessful.
|
|
49
49
|
* @param existingEntity - entity to delete
|
|
50
50
|
* @param queryContext - query context in which to perform the delete
|
|
51
51
|
*/
|
|
52
|
-
static enforceDeleteAsync<TMFields, TMID extends NonNullable<TMFields[TMSelectedFields]>, TMViewerContext extends ViewerContext, TMEntity extends Entity<TMFields, TMID, TMViewerContext, TMSelectedFields>, TMPrivacyPolicy extends EntityPrivacyPolicy<TMFields, TMID, TMViewerContext, TMEntity, TMSelectedFields>, TMSelectedFields extends keyof TMFields = keyof TMFields>(this: IEntityClass<TMFields, TMID, TMViewerContext, TMEntity, TMPrivacyPolicy, TMSelectedFields>, existingEntity: TMEntity, queryContext?: EntityQueryContext): Promise<void>;
|
|
52
|
+
static enforceDeleteAsync<TMFields extends object, TMID extends NonNullable<TMFields[TMSelectedFields]>, TMViewerContext extends ViewerContext, TMEntity extends Entity<TMFields, TMID, TMViewerContext, TMSelectedFields>, TMPrivacyPolicy extends EntityPrivacyPolicy<TMFields, TMID, TMViewerContext, TMEntity, TMSelectedFields>, TMSelectedFields extends keyof TMFields = keyof TMFields>(this: IEntityClass<TMFields, TMID, TMViewerContext, TMEntity, TMPrivacyPolicy, TMSelectedFields>, existingEntity: TMEntity, queryContext?: EntityQueryContext): Promise<void>;
|
|
53
53
|
/**
|
|
54
54
|
* Check whether an entity loaded by a viewer can be updated by that same viewer.
|
|
55
55
|
*
|
|
@@ -66,7 +66,7 @@ export default abstract class Entity<TFields, TID extends NonNullable<TFields[TS
|
|
|
66
66
|
* @param existingEntity - entity loaded by viewer
|
|
67
67
|
* @param queryContext - query context in which to perform the check
|
|
68
68
|
*/
|
|
69
|
-
static canViewerUpdateAsync<TMFields, TMID extends NonNullable<TMFields[TMSelectedFields]>, TMViewerContext extends ViewerContext, TMEntity extends Entity<TMFields, TMID, TMViewerContext, TMSelectedFields>, TMPrivacyPolicy extends EntityPrivacyPolicy<TMFields, TMID, TMViewerContext, TMEntity, TMSelectedFields>, TMSelectedFields extends keyof TMFields = keyof TMFields>(this: IEntityClass<TMFields, TMID, TMViewerContext, TMEntity, TMPrivacyPolicy, TMSelectedFields>, existingEntity: TMEntity, queryContext?: EntityQueryContext): Promise<boolean>;
|
|
69
|
+
static canViewerUpdateAsync<TMFields extends object, TMID extends NonNullable<TMFields[TMSelectedFields]>, TMViewerContext extends ViewerContext, TMEntity extends Entity<TMFields, TMID, TMViewerContext, TMSelectedFields>, TMPrivacyPolicy extends EntityPrivacyPolicy<TMFields, TMID, TMViewerContext, TMEntity, TMSelectedFields>, TMSelectedFields extends keyof TMFields = keyof TMFields>(this: IEntityClass<TMFields, TMID, TMViewerContext, TMEntity, TMPrivacyPolicy, TMSelectedFields>, existingEntity: TMEntity, queryContext?: EntityQueryContext): Promise<boolean>;
|
|
70
70
|
/**
|
|
71
71
|
* Check whether an entity loaded by a viewer can be deleted by that same viewer.
|
|
72
72
|
*
|
|
@@ -76,12 +76,22 @@ export default abstract class Entity<TFields, TID extends NonNullable<TFields[TS
|
|
|
76
76
|
* @param existingEntity - entity loaded by viewer
|
|
77
77
|
* @param queryContext - query context in which to perform the check
|
|
78
78
|
*/
|
|
79
|
-
static canViewerDeleteAsync<TMFields, TMID extends NonNullable<TMFields[TMSelectedFields]>, TMViewerContext extends ViewerContext, TMEntity extends Entity<TMFields, TMID, TMViewerContext, TMSelectedFields>, TMPrivacyPolicy extends EntityPrivacyPolicy<TMFields, TMID, TMViewerContext, TMEntity, TMSelectedFields>, TMSelectedFields extends keyof TMFields = keyof TMFields>(this: IEntityClass<TMFields, TMID, TMViewerContext, TMEntity, TMPrivacyPolicy, TMSelectedFields>, existingEntity: TMEntity, queryContext?: EntityQueryContext): Promise<boolean>;
|
|
79
|
+
static canViewerDeleteAsync<TMFields extends object, TMID extends NonNullable<TMFields[TMSelectedFields]>, TMViewerContext extends ViewerContext, TMEntity extends Entity<TMFields, TMID, TMViewerContext, TMSelectedFields>, TMPrivacyPolicy extends EntityPrivacyPolicy<TMFields, TMID, TMViewerContext, TMEntity, TMSelectedFields>, TMSelectedFields extends keyof TMFields = keyof TMFields>(this: IEntityClass<TMFields, TMID, TMViewerContext, TMEntity, TMPrivacyPolicy, TMSelectedFields>, existingEntity: TMEntity, queryContext?: EntityQueryContext): Promise<boolean>;
|
|
80
80
|
}
|
|
81
81
|
/**
|
|
82
82
|
* An interface to pass in constructor (class) of an Entity as a function argument.
|
|
83
83
|
*/
|
|
84
|
-
export interface IEntityClass<TFields, TID extends NonNullable<TFields[TSelectedFields]>, TViewerContext extends ViewerContext, TEntity extends ReadonlyEntity<TFields, TID, TViewerContext, TSelectedFields>, TPrivacyPolicy extends EntityPrivacyPolicy<TFields, TID, TViewerContext, TEntity, TSelectedFields>, TSelectedFields extends keyof TFields = keyof TFields> {
|
|
85
|
-
new (
|
|
86
|
-
|
|
84
|
+
export interface IEntityClass<TFields extends object, TID extends NonNullable<TFields[TSelectedFields]>, TViewerContext extends ViewerContext, TEntity extends ReadonlyEntity<TFields, TID, TViewerContext, TSelectedFields>, TPrivacyPolicy extends EntityPrivacyPolicy<TFields, TID, TViewerContext, TEntity, TSelectedFields>, TSelectedFields extends keyof TFields = keyof TFields> {
|
|
85
|
+
new (constructorParam: {
|
|
86
|
+
viewerContext: TViewerContext;
|
|
87
|
+
id: TID;
|
|
88
|
+
databaseFields: Readonly<TFields>;
|
|
89
|
+
selectedFields: Readonly<Pick<TFields, TSelectedFields>>;
|
|
90
|
+
}): TEntity;
|
|
91
|
+
/**
|
|
92
|
+
* Returns a EntityCompanionDefinition for this entity.
|
|
93
|
+
*
|
|
94
|
+
* Memoized by the entity framework.
|
|
95
|
+
*/
|
|
96
|
+
defineCompanionDefinition(): EntityCompanionDefinition<TFields, TID, TViewerContext, TEntity, TPrivacyPolicy, TSelectedFields>;
|
|
87
97
|
}
|
package/build/Entity.js
CHANGED
|
@@ -114,7 +114,7 @@ class Entity extends ReadonlyEntity_1.default {
|
|
|
114
114
|
const companion = existingEntity
|
|
115
115
|
.getViewerContext()
|
|
116
116
|
.getViewerScopedEntityCompanionForClass(this);
|
|
117
|
-
const privacyPolicy =
|
|
117
|
+
const privacyPolicy = companion.entityCompanion.privacyPolicy;
|
|
118
118
|
const evaluationResult = await (0, results_1.asyncResult)(privacyPolicy.authorizeUpdateAsync(existingEntity.getViewerContext(), queryContext, { cascadingDeleteCause: null }, existingEntity, companion.getMetricsAdapter()));
|
|
119
119
|
return evaluationResult.ok;
|
|
120
120
|
}
|
|
@@ -135,7 +135,7 @@ class Entity extends ReadonlyEntity_1.default {
|
|
|
135
135
|
const companion = existingEntity
|
|
136
136
|
.getViewerContext()
|
|
137
137
|
.getViewerScopedEntityCompanionForClass(this);
|
|
138
|
-
const privacyPolicy =
|
|
138
|
+
const privacyPolicy = companion.entityCompanion.privacyPolicy;
|
|
139
139
|
const evaluationResult = await (0, results_1.asyncResult)(privacyPolicy.authorizeDeleteAsync(existingEntity.getViewerContext(), queryContext, { cascadingDeleteCause: null }, existingEntity, companion.getMetricsAdapter()));
|
|
140
140
|
return evaluationResult.ok;
|
|
141
141
|
}
|
package/build/Entity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AAE,EACjC,YAAY,EACZ,EAAE,oBAAoB,EAAE,IAAI,EAAE,EAC9B,cAAc,EACd,SAAS,CAAC,iBAAiB,EAAE,CAC9B,CACF,CAAC;QACF,OAAO,gBAAgB,CAAC,EAAE,CAAC;IAC7B,CAAC;IAED;;;;;;;;OAQG;IACH,MAAM,CAAC,KAAK,CAAC,oBAAoB,CAsB/B,cAAwB,EACxB,eAAmC,cAAc;SAC9C,gBAAgB,EAAE;SAClB,sCAAsC,CAAC,IAAI,CAAC;SAC5C,uBAAuB,EAAE;SACzB,eAAe,EAAE;QAEpB,MAAM,SAAS,GAAG,cAAc;aAC7B,gBAAgB,EAAE;aAClB,sCAAsC,CAAC,IAAI,CAAC,CAAC;QAChD,MAAM,aAAa,GAAG,SAAS,CAAC,eAAe,CAAC,aAAa,CAAC;QAC9D,MAAM,gBAAgB,GAAG,MAAM,IAAA,qBAAW,EACxC,aAAa,CAAC,oBAAoB,CAChC,cAAc,CAAC,gBAAgB,EAAE,EACjC,YAAY,EACZ,EAAE,oBAAoB,EAAE,IAAI,EAAE,EAC9B,cAAc,EACd,SAAS,CAAC,iBAAiB,EAAE,CAC9B,CACF,CAAC;QACF,OAAO,gBAAgB,CAAC,EAAE,CAAC;IAC7B,CAAC;CACF;AA/RD,yBA+RC"}
|
|
@@ -9,7 +9,7 @@ import ViewerContext from './ViewerContext';
|
|
|
9
9
|
* associated with an entity. In relational databases, these entities are often referenced
|
|
10
10
|
* by foreign keys.
|
|
11
11
|
*/
|
|
12
|
-
export default class EntityAssociationLoader<TFields, TID extends NonNullable<TFields[TSelectedFields]>, TViewerContext extends ViewerContext, TEntity extends ReadonlyEntity<TFields, TID, TViewerContext, TSelectedFields>, TSelectedFields extends keyof TFields> {
|
|
12
|
+
export default class EntityAssociationLoader<TFields extends object, TID extends NonNullable<TFields[TSelectedFields]>, TViewerContext extends ViewerContext, TEntity extends ReadonlyEntity<TFields, TID, TViewerContext, TSelectedFields>, TSelectedFields extends keyof TFields> {
|
|
13
13
|
private readonly entity;
|
|
14
14
|
constructor(entity: TEntity);
|
|
15
15
|
/**
|
|
@@ -19,7 +19,7 @@ export default class EntityAssociationLoader<TFields, TID extends NonNullable<TF
|
|
|
19
19
|
* @param associatedEntityClass - class of the associated entity
|
|
20
20
|
* @param queryContext - query context in which to perform the load
|
|
21
21
|
*/
|
|
22
|
-
loadAssociatedEntityAsync<TIdentifyingField extends keyof Pick<TFields, TSelectedFields>, TAssociatedFields, TAssociatedID extends NonNullable<TAssociatedFields[TAssociatedSelectedFields]>, TAssociatedEntity extends ReadonlyEntity<TAssociatedFields, TAssociatedID, TViewerContext, TAssociatedSelectedFields>, TAssociatedPrivacyPolicy extends EntityPrivacyPolicy<TAssociatedFields, TAssociatedID, TViewerContext, TAssociatedEntity, TAssociatedSelectedFields>, TAssociatedSelectedFields extends keyof TAssociatedFields = keyof TAssociatedFields>(fieldIdentifyingAssociatedEntity: TIdentifyingField, associatedEntityClass: IEntityClass<TAssociatedFields, TAssociatedID, TViewerContext, TAssociatedEntity, TAssociatedPrivacyPolicy, TAssociatedSelectedFields>, queryContext?: EntityQueryContext): Promise<Result<null extends TFields[TIdentifyingField] ? TAssociatedEntity | null : TAssociatedEntity>>;
|
|
22
|
+
loadAssociatedEntityAsync<TIdentifyingField extends keyof Pick<TFields, TSelectedFields>, TAssociatedFields extends object, TAssociatedID extends NonNullable<TAssociatedFields[TAssociatedSelectedFields]>, TAssociatedEntity extends ReadonlyEntity<TAssociatedFields, TAssociatedID, TViewerContext, TAssociatedSelectedFields>, TAssociatedPrivacyPolicy extends EntityPrivacyPolicy<TAssociatedFields, TAssociatedID, TViewerContext, TAssociatedEntity, TAssociatedSelectedFields>, TAssociatedSelectedFields extends keyof TAssociatedFields = keyof TAssociatedFields>(fieldIdentifyingAssociatedEntity: TIdentifyingField, associatedEntityClass: IEntityClass<TAssociatedFields, TAssociatedID, TViewerContext, TAssociatedEntity, TAssociatedPrivacyPolicy, TAssociatedSelectedFields>, queryContext?: EntityQueryContext): Promise<Result<null extends TFields[TIdentifyingField] ? TAssociatedEntity | null : TAssociatedEntity>>;
|
|
23
23
|
/**
|
|
24
24
|
* Load many entities associated with this entity, often referred to as entites belonging
|
|
25
25
|
* to this entity. In a relational database, the field in the foreign entity is a
|
|
@@ -29,7 +29,7 @@ export default class EntityAssociationLoader<TFields, TID extends NonNullable<TF
|
|
|
29
29
|
* @param associatedEntityFieldContainingThisID - field of associated entity which contains the ID of this entity
|
|
30
30
|
* @param queryContext - query context in which to perform the load
|
|
31
31
|
*/
|
|
32
|
-
loadManyAssociatedEntitiesAsync<TAssociatedFields, TAssociatedID extends NonNullable<TAssociatedFields[TAssociatedSelectedFields]>, TAssociatedEntity extends ReadonlyEntity<TAssociatedFields, TAssociatedID, TViewerContext, TAssociatedSelectedFields>, TAssociatedPrivacyPolicy extends EntityPrivacyPolicy<TAssociatedFields, TAssociatedID, TViewerContext, TAssociatedEntity, TAssociatedSelectedFields>, TAssociatedSelectedFields extends keyof TAssociatedFields = keyof TAssociatedFields>(associatedEntityClass: IEntityClass<TAssociatedFields, TAssociatedID, TViewerContext, TAssociatedEntity, TAssociatedPrivacyPolicy, TAssociatedSelectedFields>, associatedEntityFieldContainingThisID: keyof Pick<TAssociatedFields, TAssociatedSelectedFields>, queryContext?: EntityQueryContext): Promise<readonly Result<TAssociatedEntity>[]>;
|
|
32
|
+
loadManyAssociatedEntitiesAsync<TAssociatedFields extends object, TAssociatedID extends NonNullable<TAssociatedFields[TAssociatedSelectedFields]>, TAssociatedEntity extends ReadonlyEntity<TAssociatedFields, TAssociatedID, TViewerContext, TAssociatedSelectedFields>, TAssociatedPrivacyPolicy extends EntityPrivacyPolicy<TAssociatedFields, TAssociatedID, TViewerContext, TAssociatedEntity, TAssociatedSelectedFields>, TAssociatedSelectedFields extends keyof TAssociatedFields = keyof TAssociatedFields>(associatedEntityClass: IEntityClass<TAssociatedFields, TAssociatedID, TViewerContext, TAssociatedEntity, TAssociatedPrivacyPolicy, TAssociatedSelectedFields>, associatedEntityFieldContainingThisID: keyof Pick<TAssociatedFields, TAssociatedSelectedFields>, queryContext?: EntityQueryContext): Promise<readonly Result<TAssociatedEntity>[]>;
|
|
33
33
|
/**
|
|
34
34
|
* Load an associated entity identified by a field value of this entity. In a relational database,
|
|
35
35
|
* the field in this entity is a foreign key to a unique field of the associated entity.
|
|
@@ -38,7 +38,7 @@ export default class EntityAssociationLoader<TFields, TID extends NonNullable<TF
|
|
|
38
38
|
* @param associatedEntityLookupByField - field of associated entity with which to look up the associated entity
|
|
39
39
|
* @param queryContext - query context in which to perform the load
|
|
40
40
|
*/
|
|
41
|
-
loadAssociatedEntityByFieldEqualingAsync<TAssociatedFields, TAssociatedID extends NonNullable<TAssociatedFields[TAssociatedSelectedFields]>, TAssociatedEntity extends ReadonlyEntity<TAssociatedFields, TAssociatedID, TViewerContext, TAssociatedSelectedFields>, TAssociatedPrivacyPolicy extends EntityPrivacyPolicy<TAssociatedFields, TAssociatedID, TViewerContext, TAssociatedEntity, TAssociatedSelectedFields>, TAssociatedSelectedFields extends keyof TAssociatedFields = keyof TAssociatedFields>(fieldIdentifyingAssociatedEntity: keyof Pick<TFields, TSelectedFields>, associatedEntityClass: IEntityClass<TAssociatedFields, TAssociatedID, TViewerContext, TAssociatedEntity, TAssociatedPrivacyPolicy, TAssociatedSelectedFields>, associatedEntityLookupByField: keyof Pick<TAssociatedFields, TAssociatedSelectedFields>, queryContext?: EntityQueryContext): Promise<Result<TAssociatedEntity> | null>;
|
|
41
|
+
loadAssociatedEntityByFieldEqualingAsync<TAssociatedFields extends object, TAssociatedID extends NonNullable<TAssociatedFields[TAssociatedSelectedFields]>, TAssociatedEntity extends ReadonlyEntity<TAssociatedFields, TAssociatedID, TViewerContext, TAssociatedSelectedFields>, TAssociatedPrivacyPolicy extends EntityPrivacyPolicy<TAssociatedFields, TAssociatedID, TViewerContext, TAssociatedEntity, TAssociatedSelectedFields>, TAssociatedSelectedFields extends keyof TAssociatedFields = keyof TAssociatedFields>(fieldIdentifyingAssociatedEntity: keyof Pick<TFields, TSelectedFields>, associatedEntityClass: IEntityClass<TAssociatedFields, TAssociatedID, TViewerContext, TAssociatedEntity, TAssociatedPrivacyPolicy, TAssociatedSelectedFields>, associatedEntityLookupByField: keyof Pick<TAssociatedFields, TAssociatedSelectedFields>, queryContext?: EntityQueryContext): Promise<Result<TAssociatedEntity> | null>;
|
|
42
42
|
/**
|
|
43
43
|
* Load many associated entities identified by a field value of this entity. In a relational database,
|
|
44
44
|
* the field in this entity refers to a field of the associated entity.
|
|
@@ -47,14 +47,14 @@ export default class EntityAssociationLoader<TFields, TID extends NonNullable<TF
|
|
|
47
47
|
* @param associatedEntityLookupByField - field of associated entities with which to look up the associated entities
|
|
48
48
|
* @param queryContext - query context in which to perform the load
|
|
49
49
|
*/
|
|
50
|
-
loadManyAssociatedEntitiesByFieldEqualingAsync<TAssociatedFields, TAssociatedID extends NonNullable<TAssociatedFields[TAssociatedSelectedFields]>, TAssociatedEntity extends ReadonlyEntity<TAssociatedFields, TAssociatedID, TViewerContext, TAssociatedSelectedFields>, TAssociatedPrivacyPolicy extends EntityPrivacyPolicy<TAssociatedFields, TAssociatedID, TViewerContext, TAssociatedEntity, TAssociatedSelectedFields>, TAssociatedSelectedFields extends keyof TAssociatedFields = keyof TAssociatedFields>(fieldIdentifyingAssociatedEntity: keyof Pick<TFields, TSelectedFields>, associatedEntityClass: IEntityClass<TAssociatedFields, TAssociatedID, TViewerContext, TAssociatedEntity, TAssociatedPrivacyPolicy, TAssociatedSelectedFields>, associatedEntityLookupByField: keyof Pick<TAssociatedFields, TAssociatedSelectedFields>, queryContext?: EntityQueryContext): Promise<readonly Result<TAssociatedEntity>[]>;
|
|
50
|
+
loadManyAssociatedEntitiesByFieldEqualingAsync<TAssociatedFields extends object, TAssociatedID extends NonNullable<TAssociatedFields[TAssociatedSelectedFields]>, TAssociatedEntity extends ReadonlyEntity<TAssociatedFields, TAssociatedID, TViewerContext, TAssociatedSelectedFields>, TAssociatedPrivacyPolicy extends EntityPrivacyPolicy<TAssociatedFields, TAssociatedID, TViewerContext, TAssociatedEntity, TAssociatedSelectedFields>, TAssociatedSelectedFields extends keyof TAssociatedFields = keyof TAssociatedFields>(fieldIdentifyingAssociatedEntity: keyof Pick<TFields, TSelectedFields>, associatedEntityClass: IEntityClass<TAssociatedFields, TAssociatedID, TViewerContext, TAssociatedEntity, TAssociatedPrivacyPolicy, TAssociatedSelectedFields>, associatedEntityLookupByField: keyof Pick<TAssociatedFields, TAssociatedSelectedFields>, queryContext?: EntityQueryContext): Promise<readonly Result<TAssociatedEntity>[]>;
|
|
51
51
|
/**
|
|
52
52
|
* Load an associated entity by folding a sequence of EntityLoadThroughDirective. At each
|
|
53
53
|
* fold step, load an associated entity identified by a field value of the current fold value.
|
|
54
54
|
* @param loadDirectives - associated entity load directives instructing each step of the fold
|
|
55
55
|
* @param queryContext - query context in which to perform the loads
|
|
56
56
|
*/
|
|
57
|
-
loadAssociatedEntityThroughAsync<TFields2, TID2 extends NonNullable<TFields2[TSelectedFields2]>, TEntity2 extends ReadonlyEntity<TFields2, TID2, TViewerContext, TSelectedFields2>, TPrivacyPolicy2 extends EntityPrivacyPolicy<TFields2, TID2, TViewerContext, TEntity2, TSelectedFields2>, TSelectedFields2 extends keyof TFields2 = keyof TFields2>(loadDirectives: [
|
|
57
|
+
loadAssociatedEntityThroughAsync<TFields2 extends object, TID2 extends NonNullable<TFields2[TSelectedFields2]>, TEntity2 extends ReadonlyEntity<TFields2, TID2, TViewerContext, TSelectedFields2>, TPrivacyPolicy2 extends EntityPrivacyPolicy<TFields2, TID2, TViewerContext, TEntity2, TSelectedFields2>, TSelectedFields2 extends keyof TFields2 = keyof TFields2>(loadDirectives: [
|
|
58
58
|
EntityLoadThroughDirective<TViewerContext, TFields, TFields2, TID2, TEntity2, TPrivacyPolicy2, TSelectedFields, TSelectedFields2>
|
|
59
59
|
], queryContext?: EntityQueryContext): Promise<Result<TEntity2> | null>;
|
|
60
60
|
/**
|
|
@@ -63,7 +63,7 @@ export default class EntityAssociationLoader<TFields, TID extends NonNullable<TF
|
|
|
63
63
|
* @param loadDirectives - associated entity load directives instructing each step of the fold
|
|
64
64
|
* @param queryContext - query context in which to perform the loads
|
|
65
65
|
*/
|
|
66
|
-
loadAssociatedEntityThroughAsync<TFields2, TID2 extends NonNullable<TFields2[TSelectedFields2]>, TEntity2 extends ReadonlyEntity<TFields2, TID2, TViewerContext, TSelectedFields2>, TPrivacyPolicy2 extends EntityPrivacyPolicy<TFields2, TID2, TViewerContext, TEntity2, TSelectedFields2>, TFields3, TID3 extends NonNullable<TFields3[TSelectedFields3]>, TEntity3 extends ReadonlyEntity<TFields3, TID3, TViewerContext, TSelectedFields3>, TPrivacyPolicy3 extends EntityPrivacyPolicy<TFields3, TID3, TViewerContext, TEntity3, TSelectedFields3>, TSelectedFields2 extends keyof TFields2 = keyof TFields2, TSelectedFields3 extends keyof TFields3 = keyof TFields3>(loadDirectives: [
|
|
66
|
+
loadAssociatedEntityThroughAsync<TFields2 extends object, TID2 extends NonNullable<TFields2[TSelectedFields2]>, TEntity2 extends ReadonlyEntity<TFields2, TID2, TViewerContext, TSelectedFields2>, TPrivacyPolicy2 extends EntityPrivacyPolicy<TFields2, TID2, TViewerContext, TEntity2, TSelectedFields2>, TFields3 extends object, TID3 extends NonNullable<TFields3[TSelectedFields3]>, TEntity3 extends ReadonlyEntity<TFields3, TID3, TViewerContext, TSelectedFields3>, TPrivacyPolicy3 extends EntityPrivacyPolicy<TFields3, TID3, TViewerContext, TEntity3, TSelectedFields3>, TSelectedFields2 extends keyof TFields2 = keyof TFields2, TSelectedFields3 extends keyof TFields3 = keyof TFields3>(loadDirectives: [
|
|
67
67
|
EntityLoadThroughDirective<TViewerContext, TFields, TFields2, TID2, TEntity2, TPrivacyPolicy2, TSelectedFields, TSelectedFields2>,
|
|
68
68
|
EntityLoadThroughDirective<TViewerContext, TFields2, TFields3, TID3, TEntity3, TPrivacyPolicy3, TSelectedFields2, TSelectedFields3>
|
|
69
69
|
], queryContext?: EntityQueryContext): Promise<Result<TEntity3> | null>;
|
|
@@ -73,7 +73,7 @@ export default class EntityAssociationLoader<TFields, TID extends NonNullable<TF
|
|
|
73
73
|
* @param loadDirectives - associated entity load directives instructing each step of the fold
|
|
74
74
|
* @param queryContext - query context in which to perform the loads
|
|
75
75
|
*/
|
|
76
|
-
loadAssociatedEntityThroughAsync<TFields2, TID2 extends NonNullable<TFields2[TSelectedFields2]>, TEntity2 extends ReadonlyEntity<TFields2, TID2, TViewerContext, TSelectedFields2>, TPrivacyPolicy2 extends EntityPrivacyPolicy<TFields2, TID2, TViewerContext, TEntity2, TSelectedFields2>, TFields3, TID3 extends NonNullable<TFields3[TSelectedFields3]>, TEntity3 extends ReadonlyEntity<TFields3, TID3, TViewerContext, TSelectedFields3>, TPrivacyPolicy3 extends EntityPrivacyPolicy<TFields3, TID3, TViewerContext, TEntity3, TSelectedFields3>, TFields4, TID4 extends NonNullable<TFields4[TSelectedFields4]>, TEntity4 extends ReadonlyEntity<TFields4, TID4, TViewerContext, TSelectedFields4>, TPrivacyPolicy4 extends EntityPrivacyPolicy<TFields4, TID4, TViewerContext, TEntity4, TSelectedFields4>, TSelectedFields2 extends keyof TFields2 = keyof TFields2, TSelectedFields3 extends keyof TFields3 = keyof TFields3, TSelectedFields4 extends keyof TFields4 = keyof TFields4>(loadDirective: [
|
|
76
|
+
loadAssociatedEntityThroughAsync<TFields2 extends object, TID2 extends NonNullable<TFields2[TSelectedFields2]>, TEntity2 extends ReadonlyEntity<TFields2, TID2, TViewerContext, TSelectedFields2>, TPrivacyPolicy2 extends EntityPrivacyPolicy<TFields2, TID2, TViewerContext, TEntity2, TSelectedFields2>, TFields3 extends object, TID3 extends NonNullable<TFields3[TSelectedFields3]>, TEntity3 extends ReadonlyEntity<TFields3, TID3, TViewerContext, TSelectedFields3>, TPrivacyPolicy3 extends EntityPrivacyPolicy<TFields3, TID3, TViewerContext, TEntity3, TSelectedFields3>, TFields4 extends object, TID4 extends NonNullable<TFields4[TSelectedFields4]>, TEntity4 extends ReadonlyEntity<TFields4, TID4, TViewerContext, TSelectedFields4>, TPrivacyPolicy4 extends EntityPrivacyPolicy<TFields4, TID4, TViewerContext, TEntity4, TSelectedFields4>, TSelectedFields2 extends keyof TFields2 = keyof TFields2, TSelectedFields3 extends keyof TFields3 = keyof TFields3, TSelectedFields4 extends keyof TFields4 = keyof TFields4>(loadDirective: [
|
|
77
77
|
EntityLoadThroughDirective<TViewerContext, TFields, TFields2, TID2, TEntity2, TPrivacyPolicy2, TSelectedFields, TSelectedFields2>,
|
|
78
78
|
EntityLoadThroughDirective<TViewerContext, TFields2, TFields3, TID3, TEntity3, TPrivacyPolicy3, TSelectedFields2, TSelectedFields3>,
|
|
79
79
|
EntityLoadThroughDirective<TViewerContext, TFields3, TFields4, TID4, TEntity4, TPrivacyPolicy4, TSelectedFields3, TSelectedFields4>
|
|
@@ -89,7 +89,7 @@ export default class EntityAssociationLoader<TFields, TID extends NonNullable<TF
|
|
|
89
89
|
/**
|
|
90
90
|
* Instruction for each step of a load-associated-through method.
|
|
91
91
|
*/
|
|
92
|
-
export interface EntityLoadThroughDirective<TViewerContext extends ViewerContext, TFields, TAssociatedFields, TAssociatedID extends NonNullable<TAssociatedFields[TAssociatedSelectedFields]>, TAssociatedEntity extends ReadonlyEntity<TAssociatedFields, TAssociatedID, TViewerContext, TAssociatedSelectedFields>, TAssociatedPrivacyPolicy extends EntityPrivacyPolicy<TAssociatedFields, TAssociatedID, TViewerContext, TAssociatedEntity, TAssociatedSelectedFields>, TSelectedFields extends keyof TFields = keyof TFields, TAssociatedSelectedFields extends keyof TAssociatedFields = keyof TAssociatedFields> {
|
|
92
|
+
export interface EntityLoadThroughDirective<TViewerContext extends ViewerContext, TFields, TAssociatedFields extends object, TAssociatedID extends NonNullable<TAssociatedFields[TAssociatedSelectedFields]>, TAssociatedEntity extends ReadonlyEntity<TAssociatedFields, TAssociatedID, TViewerContext, TAssociatedSelectedFields>, TAssociatedPrivacyPolicy extends EntityPrivacyPolicy<TAssociatedFields, TAssociatedID, TViewerContext, TAssociatedEntity, TAssociatedSelectedFields>, TSelectedFields extends keyof TFields = keyof TFields, TAssociatedSelectedFields extends keyof TAssociatedFields = keyof TAssociatedFields> {
|
|
93
93
|
/**
|
|
94
94
|
* Class of entity to load at this step.
|
|
95
95
|
*/
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import EntityCompanionProvider, { EntityCompanionDefinition } from './EntityCompanionProvider';
|
|
2
2
|
import EntityLoaderFactory from './EntityLoaderFactory';
|
|
3
|
-
import EntityMutationTriggerConfiguration from './EntityMutationTriggerConfiguration';
|
|
4
|
-
import EntityMutationValidator from './EntityMutationValidator';
|
|
5
3
|
import EntityMutatorFactory from './EntityMutatorFactory';
|
|
6
4
|
import EntityPrivacyPolicy from './EntityPrivacyPolicy';
|
|
7
5
|
import EntityQueryContextProvider from './EntityQueryContextProvider';
|
|
@@ -15,12 +13,15 @@ export interface IPrivacyPolicyClass<TPrivacyPolicy> {
|
|
|
15
13
|
/**
|
|
16
14
|
* Composition root responsible for orchestrating setup of Entity mutators and loaders.
|
|
17
15
|
*/
|
|
18
|
-
export default class EntityCompanion<TFields, TID extends NonNullable<TFields[TSelectedFields]>, TViewerContext extends ViewerContext, TEntity extends ReadonlyEntity<TFields, TID, TViewerContext, TSelectedFields>, TPrivacyPolicy extends EntityPrivacyPolicy<TFields, TID, TViewerContext, TEntity, TSelectedFields>, TSelectedFields extends keyof TFields> {
|
|
16
|
+
export default class EntityCompanion<TFields extends object, TID extends NonNullable<TFields[TSelectedFields]>, TViewerContext extends ViewerContext, TEntity extends ReadonlyEntity<TFields, TID, TViewerContext, TSelectedFields>, TPrivacyPolicy extends EntityPrivacyPolicy<TFields, TID, TViewerContext, TEntity, TSelectedFields>, TSelectedFields extends keyof TFields> {
|
|
17
|
+
readonly entityCompanionProvider: EntityCompanionProvider;
|
|
18
|
+
readonly entityCompanionDefinition: EntityCompanionDefinition<TFields, TID, TViewerContext, TEntity, TPrivacyPolicy, TSelectedFields>;
|
|
19
19
|
private readonly tableDataCoordinator;
|
|
20
20
|
private readonly metricsAdapter;
|
|
21
|
+
readonly privacyPolicy: TPrivacyPolicy;
|
|
21
22
|
private readonly entityLoaderFactory;
|
|
22
23
|
private readonly entityMutatorFactory;
|
|
23
|
-
constructor(
|
|
24
|
+
constructor(entityCompanionProvider: EntityCompanionProvider, entityCompanionDefinition: EntityCompanionDefinition<TFields, TID, TViewerContext, TEntity, TPrivacyPolicy, TSelectedFields>, tableDataCoordinator: EntityTableDataCoordinator<TFields>, metricsAdapter: IEntityMetricsAdapter);
|
|
24
25
|
getLoaderFactory(): EntityLoaderFactory<TFields, TID, TViewerContext, TEntity, TPrivacyPolicy, TSelectedFields>;
|
|
25
26
|
getMutatorFactory(): EntityMutatorFactory<TFields, TID, TViewerContext, TEntity, TPrivacyPolicy, TSelectedFields>;
|
|
26
27
|
/**
|
package/build/EntityCompanion.js
CHANGED
|
@@ -9,12 +9,14 @@ const EntityMutatorFactory_1 = __importDefault(require("./EntityMutatorFactory")
|
|
|
9
9
|
* Composition root responsible for orchestrating setup of Entity mutators and loaders.
|
|
10
10
|
*/
|
|
11
11
|
class EntityCompanion {
|
|
12
|
-
constructor(
|
|
12
|
+
constructor(entityCompanionProvider, entityCompanionDefinition, tableDataCoordinator, metricsAdapter) {
|
|
13
|
+
this.entityCompanionProvider = entityCompanionProvider;
|
|
14
|
+
this.entityCompanionDefinition = entityCompanionDefinition;
|
|
13
15
|
this.tableDataCoordinator = tableDataCoordinator;
|
|
14
16
|
this.metricsAdapter = metricsAdapter;
|
|
15
|
-
|
|
16
|
-
this.entityLoaderFactory = new EntityLoaderFactory_1.default(
|
|
17
|
-
this.entityMutatorFactory = new EntityMutatorFactory_1.default(tableDataCoordinator.entityConfiguration, entityClass, privacyPolicy, mutationValidators, mutationTriggers, this.entityLoaderFactory, tableDataCoordinator.databaseAdapter, metricsAdapter);
|
|
17
|
+
this.privacyPolicy = new entityCompanionDefinition.privacyPolicyClass();
|
|
18
|
+
this.entityLoaderFactory = new EntityLoaderFactory_1.default(this, tableDataCoordinator.dataManager, metricsAdapter);
|
|
19
|
+
this.entityMutatorFactory = new EntityMutatorFactory_1.default(entityCompanionProvider, tableDataCoordinator.entityConfiguration, entityCompanionDefinition.entityClass, this.privacyPolicy, entityCompanionDefinition.mutationValidators ?? [], entityCompanionDefinition.mutationTriggers ?? {}, this.entityLoaderFactory, tableDataCoordinator.databaseAdapter, metricsAdapter);
|
|
18
20
|
}
|
|
19
21
|
getLoaderFactory() {
|
|
20
22
|
return this.entityLoaderFactory;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EntityCompanion.js","sourceRoot":"","sources":["../src/EntityCompanion.ts"],"names":[],"mappings":";;;;;AACA,gFAAwD;
|
|
1
|
+
{"version":3,"file":"EntityCompanion.js","sourceRoot":"","sources":["../src/EntityCompanion.ts"],"names":[],"mappings":";;;;;AACA,gFAAwD;AACxD,kFAA0D;AAY1D;;GAEG;AACH,MAAqB,eAAe;IAiClC,YACkB,uBAAgD,EAChD,yBAOf,EACgB,oBAAyD,EACzD,cAAqC;QAVtC,4BAAuB,GAAvB,uBAAuB,CAAyB;QAChD,8BAAyB,GAAzB,yBAAyB,CAOxC;QACgB,yBAAoB,GAApB,oBAAoB,CAAqC;QACzD,mBAAc,GAAd,cAAc,CAAuB;QAEtD,IAAI,CAAC,aAAa,GAAG,IAAI,yBAAyB,CAAC,kBAAkB,EAAE,CAAC;QACxE,IAAI,CAAC,mBAAmB,GAAG,IAAI,6BAAmB,CAOhD,IAAI,EAAE,oBAAoB,CAAC,WAAW,EAAE,cAAc,CAAC,CAAC;QAC1D,IAAI,CAAC,oBAAoB,GAAG,IAAI,8BAAoB,CAClD,uBAAuB,EACvB,oBAAoB,CAAC,mBAAmB,EACxC,yBAAyB,CAAC,WAAW,EACrC,IAAI,CAAC,aAAa,EAClB,yBAAyB,CAAC,kBAAkB,IAAI,EAAE,EAClD,yBAAyB,CAAC,gBAAgB,IAAI,EAAE,EAChD,IAAI,CAAC,mBAAmB,EACxB,oBAAoB,CAAC,eAAe,EACpC,cAAc,CACf,CAAC;IACJ,CAAC;IAED,gBAAgB;QAQd,OAAO,IAAI,CAAC,mBAAmB,CAAC;IAClC,CAAC;IAED,iBAAiB;QAQf,OAAO,IAAI,CAAC,oBAAoB,CAAC;IACnC,CAAC;IAED;;OAEG;IACH,uBAAuB;QACrB,OAAO,IAAI,CAAC,oBAAoB,CAAC,uBAAuB,EAAE,CAAC;IAC7D,CAAC;IAED;;OAEG;IACH,iBAAiB;QACf,OAAO,IAAI,CAAC,cAAc,CAAC;IAC7B,CAAC;CACF;AAvGD,kCAuGC"}
|
|
@@ -14,12 +14,12 @@ import IEntityMetricsAdapter from './metrics/IEntityMetricsAdapter';
|
|
|
14
14
|
* Backing database and transaction type for an entity. The definitions and implementations
|
|
15
15
|
* are provided by injection in the root EntityCompanionProvider to allow for mocking and sharing.
|
|
16
16
|
*/
|
|
17
|
-
export
|
|
17
|
+
export type DatabaseAdapterFlavor = string;
|
|
18
18
|
/**
|
|
19
19
|
* Cache system for an entity. The definitions and implementations are provided by injection
|
|
20
20
|
* in the root EntityCompanionProvider to allow for mocking and sharing.
|
|
21
21
|
*/
|
|
22
|
-
export
|
|
22
|
+
export type CacheAdapterFlavor = string;
|
|
23
23
|
/**
|
|
24
24
|
* Defines a set interfaces for a entity database adapter flavor. An entity that uses a flavor
|
|
25
25
|
* will use the specified adapter for database accesses and the specified query context provider
|
|
@@ -40,41 +40,33 @@ export interface CacheAdapterFlavorDefinition {
|
|
|
40
40
|
* Definition for constructing a companion for an entity. Defines the core set of objects
|
|
41
41
|
* used to power the entity framework for a particular type of entity.
|
|
42
42
|
*/
|
|
43
|
-
export
|
|
43
|
+
export interface EntityCompanionDefinition<TFields extends object, TID extends NonNullable<TFields[TSelectedFields]>, TViewerContext extends ViewerContext, TEntity extends ReadonlyEntity<TFields, TID, TViewerContext, TSelectedFields>, TPrivacyPolicy extends EntityPrivacyPolicy<TFields, TID, TViewerContext, TEntity, TSelectedFields>, TSelectedFields extends keyof TFields = keyof TFields> {
|
|
44
|
+
/**
|
|
45
|
+
* The concrete Entity class for which this is the definition.
|
|
46
|
+
*/
|
|
44
47
|
readonly entityClass: IEntityClass<TFields, TID, TViewerContext, TEntity, TPrivacyPolicy, TSelectedFields>;
|
|
48
|
+
/**
|
|
49
|
+
* The EntityConfiguration for this entity.
|
|
50
|
+
*/
|
|
45
51
|
readonly entityConfiguration: EntityConfiguration<TFields>;
|
|
52
|
+
/**
|
|
53
|
+
* The EntityPrivacyPolicy class for this entity.
|
|
54
|
+
*/
|
|
46
55
|
readonly privacyPolicyClass: IPrivacyPolicyClass<TPrivacyPolicy>;
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
*/
|
|
62
|
-
privacyPolicyClass: IPrivacyPolicyClass<TPrivacyPolicy>;
|
|
63
|
-
/**
|
|
64
|
-
* An optional list of EntityMutationValidator for this entity.
|
|
65
|
-
*/
|
|
66
|
-
mutationValidators?: () => EntityMutationValidator<TFields, TID, TViewerContext, TEntity, TSelectedFields>[];
|
|
67
|
-
/**
|
|
68
|
-
* An optional list of EntityMutationTrigger for this entity.
|
|
69
|
-
*/
|
|
70
|
-
mutationTriggers?: () => EntityMutationTriggerConfiguration<TFields, TID, TViewerContext, TEntity, TSelectedFields>;
|
|
71
|
-
/**
|
|
72
|
-
* An optional subset of fields defined in the EntityConfiguration which belong to this entity.
|
|
73
|
-
* For use when multiple types of entities are backed by a single table (EntityConfiguration) yet
|
|
74
|
-
* only expose a subset of the fields.
|
|
75
|
-
*/
|
|
76
|
-
entitySelectedFields?: TSelectedFields[];
|
|
77
|
-
});
|
|
56
|
+
/**
|
|
57
|
+
* An optional list of EntityMutationValidator for this entity.
|
|
58
|
+
*/
|
|
59
|
+
readonly mutationValidators?: EntityMutationValidator<TFields, TID, TViewerContext, TEntity, TSelectedFields>[];
|
|
60
|
+
/**
|
|
61
|
+
* An optional list of EntityMutationTrigger for this entity.
|
|
62
|
+
*/
|
|
63
|
+
readonly mutationTriggers?: EntityMutationTriggerConfiguration<TFields, TID, TViewerContext, TEntity, TSelectedFields>;
|
|
64
|
+
/**
|
|
65
|
+
* An optional subset of fields defined in the EntityConfiguration which belong to this entity.
|
|
66
|
+
* For use when multiple types of entities are backed by a single table (EntityConfiguration) yet
|
|
67
|
+
* only expose a subset of the fields.
|
|
68
|
+
*/
|
|
69
|
+
readonly entitySelectedFields?: TSelectedFields[];
|
|
78
70
|
}
|
|
79
71
|
/**
|
|
80
72
|
* An instance of the Entity framework.
|
|
@@ -89,6 +81,7 @@ export default class EntityCompanionProvider {
|
|
|
89
81
|
readonly metricsAdapter: IEntityMetricsAdapter;
|
|
90
82
|
private databaseAdapterFlavors;
|
|
91
83
|
private cacheAdapterFlavors;
|
|
84
|
+
private readonly companionDefinitionMap;
|
|
92
85
|
private readonly companionMap;
|
|
93
86
|
private readonly tableDataCoordinatorMap;
|
|
94
87
|
/**
|
|
@@ -103,9 +96,8 @@ export default class EntityCompanionProvider {
|
|
|
103
96
|
* companion is constructed using the configuration provided by the factory.
|
|
104
97
|
*
|
|
105
98
|
* @param entityClass - entity class to load
|
|
106
|
-
* @param factory - entity companion factory
|
|
107
99
|
*/
|
|
108
|
-
getCompanionForEntity<TFields, TID extends NonNullable<TFields[TSelectedFields]>, TViewerContext extends ViewerContext, TEntity extends ReadonlyEntity<TFields, TID, TViewerContext, TSelectedFields>, TPrivacyPolicy extends EntityPrivacyPolicy<TFields, TID, TViewerContext, TEntity, TSelectedFields>, TSelectedFields extends keyof TFields>(entityClass: IEntityClass<TFields, TID, TViewerContext, TEntity, TPrivacyPolicy, TSelectedFields
|
|
100
|
+
getCompanionForEntity<TFields extends object, TID extends NonNullable<TFields[TSelectedFields]>, TViewerContext extends ViewerContext, TEntity extends ReadonlyEntity<TFields, TID, TViewerContext, TSelectedFields>, TPrivacyPolicy extends EntityPrivacyPolicy<TFields, TID, TViewerContext, TEntity, TSelectedFields>, TSelectedFields extends keyof TFields>(entityClass: IEntityClass<TFields, TID, TViewerContext, TEntity, TPrivacyPolicy, TSelectedFields>): EntityCompanion<TFields, TID, TViewerContext, TEntity, TPrivacyPolicy, TSelectedFields>;
|
|
109
101
|
getQueryContextProviderForDatabaseAdaptorFlavor(databaseAdapterFlavor: DatabaseAdapterFlavor): EntityQueryContextProvider;
|
|
110
102
|
private getTableDataCoordinatorForEntity;
|
|
111
103
|
}
|
|
@@ -3,26 +3,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.EntityCompanionDefinition = void 0;
|
|
7
6
|
const invariant_1 = __importDefault(require("invariant"));
|
|
8
7
|
const EntityCompanion_1 = __importDefault(require("./EntityCompanion"));
|
|
9
8
|
const EntityTableDataCoordinator_1 = __importDefault(require("./internal/EntityTableDataCoordinator"));
|
|
10
9
|
const maps_1 = require("./utils/collections/maps");
|
|
11
|
-
/**
|
|
12
|
-
* Definition for constructing a companion for an entity. Defines the core set of objects
|
|
13
|
-
* used to power the entity framework for a particular type of entity.
|
|
14
|
-
*/
|
|
15
|
-
class EntityCompanionDefinition {
|
|
16
|
-
constructor({ entityClass, entityConfiguration, privacyPolicyClass, mutationValidators = () => [], mutationTriggers = () => ({}), entitySelectedFields = Array.from(entityConfiguration.schema.keys()), }) {
|
|
17
|
-
this.entityClass = entityClass;
|
|
18
|
-
this.entityConfiguration = entityConfiguration;
|
|
19
|
-
this.privacyPolicyClass = privacyPolicyClass;
|
|
20
|
-
this.mutationValidators = mutationValidators;
|
|
21
|
-
this.mutationTriggers = mutationTriggers;
|
|
22
|
-
this.entitySelectedFields = entitySelectedFields;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
exports.EntityCompanionDefinition = EntityCompanionDefinition;
|
|
26
10
|
/**
|
|
27
11
|
* An instance of the Entity framework.
|
|
28
12
|
*
|
|
@@ -43,6 +27,7 @@ class EntityCompanionProvider {
|
|
|
43
27
|
this.metricsAdapter = metricsAdapter;
|
|
44
28
|
this.databaseAdapterFlavors = databaseAdapterFlavors;
|
|
45
29
|
this.cacheAdapterFlavors = cacheAdapterFlavors;
|
|
30
|
+
this.companionDefinitionMap = new Map();
|
|
46
31
|
this.companionMap = new Map();
|
|
47
32
|
this.tableDataCoordinatorMap = new Map();
|
|
48
33
|
}
|
|
@@ -51,12 +36,12 @@ class EntityCompanionProvider {
|
|
|
51
36
|
* companion is constructed using the configuration provided by the factory.
|
|
52
37
|
*
|
|
53
38
|
* @param entityClass - entity class to load
|
|
54
|
-
* @param factory - entity companion factory
|
|
55
39
|
*/
|
|
56
|
-
getCompanionForEntity(entityClass
|
|
40
|
+
getCompanionForEntity(entityClass) {
|
|
41
|
+
const entityCompanionDefinition = (0, maps_1.computeIfAbsent)(this.companionDefinitionMap, entityClass.name, () => entityClass.defineCompanionDefinition());
|
|
57
42
|
const tableDataCoordinator = this.getTableDataCoordinatorForEntity(entityCompanionDefinition.entityConfiguration, entityClass.name);
|
|
58
43
|
return (0, maps_1.computeIfAbsent)(this.companionMap, entityClass.name, () => {
|
|
59
|
-
return new EntityCompanion_1.default(
|
|
44
|
+
return new EntityCompanion_1.default(this, entityCompanionDefinition, tableDataCoordinator, this.metricsAdapter);
|
|
60
45
|
});
|
|
61
46
|
}
|
|
62
47
|
getQueryContextProviderForDatabaseAdaptorFlavor(databaseAdapterFlavor) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EntityCompanionProvider.js","sourceRoot":"","sources":["../src/EntityCompanionProvider.ts"],"names":[],"mappings":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,EAAE,CAC/E,CAAC;QAEF,OAAO,2BAA2B,CAAC,oBAAoB,CAAC;IAC1D,CAAC;IAEO,gCAAgC,CACtC,mBAAiD,EACjD,eAAuB;QAEvB,OAAO,IAAA,sBAAe,EAAC,IAAI,CAAC,uBAAuB,EAAE,mBAAmB,CAAC,SAAS,EAAE,GAAG,EAAE;YACvF,MAAM,2BAA2B,GAAG,IAAI,CAAC,sBAAsB,CAAC,GAAG,CACjE,mBAAmB,CAAC,qBAAqB,CAC1C,CAAC;YACF,IAAA,mBAAS,EACP,2BAA2B,EAC3B,uDAAuD,mBAAmB,CAAC,qBAAqB,EAAE,CACnG,CAAC;YAEF,MAAM,wBAAwB,GAAG,IAAI,CAAC,mBAAmB,CAAC,GAAG,CAC3D,mBAAmB,CAAC,kBAAkB,CACvC,CAAC;YACF,IAAA,mBAAS,EACP,wBAAwB,EACxB,oDAAoD,mBAAmB,CAAC,kBAAkB,EAAE,CAC7F,CAAC;YAEF,OAAO,IAAI,oCAA0B,CACnC,mBAAmB,EACnB,2BAA2B,CAAC,eAAe,EAC3C,wBAAwB,CAAC,oBAAoB,EAC7C,2BAA2B,CAAC,oBAAoB,EAChD,IAAI,CAAC,cAAc,EACnB,eAAe,CAChB,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AApHD,0CAoHC"}
|
|
@@ -10,13 +10,13 @@ export default class EntityConfiguration<TFields> {
|
|
|
10
10
|
readonly tableName: string;
|
|
11
11
|
readonly cacheableKeys: ReadonlySet<keyof TFields>;
|
|
12
12
|
readonly cacheKeyVersion: number;
|
|
13
|
-
readonly
|
|
13
|
+
readonly inboundEdges: IEntityClass<any, any, any, any, any, any>[];
|
|
14
14
|
readonly schema: ReadonlyMap<keyof TFields, EntityFieldDefinition<any>>;
|
|
15
15
|
readonly entityToDBFieldsKeyMapping: ReadonlyMap<keyof TFields, string>;
|
|
16
16
|
readonly dbToEntityFieldsKeyMapping: ReadonlyMap<string, keyof TFields>;
|
|
17
17
|
readonly databaseAdapterFlavor: DatabaseAdapterFlavor;
|
|
18
18
|
readonly cacheAdapterFlavor: CacheAdapterFlavor;
|
|
19
|
-
constructor({ idField, tableName, schema,
|
|
19
|
+
constructor({ idField, tableName, schema, inboundEdges, cacheKeyVersion, databaseAdapterFlavor, cacheAdapterFlavor, }: {
|
|
20
20
|
/**
|
|
21
21
|
* The field used to identify this entity. Must be a unique field in the table.
|
|
22
22
|
*/
|
|
@@ -32,7 +32,7 @@ export default class EntityConfiguration<TFields> {
|
|
|
32
32
|
/**
|
|
33
33
|
* List of other entity types that reference this type in EntityFieldDefinition associations.
|
|
34
34
|
*/
|
|
35
|
-
|
|
35
|
+
inboundEdges?: IEntityClass<any, any, any, any, any, any>[];
|
|
36
36
|
/**
|
|
37
37
|
* Cache key version for this entity type. Should be bumped when a field is added to, removed from, or changed
|
|
38
38
|
* in this entity and the underlying database table.
|