@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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StubQueryContextProvider.js","sourceRoot":"","sources":["../../../src/utils/testing/StubQueryContextProvider.ts"],"names":[],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"StubQueryContextProvider.js","sourceRoot":"","sources":["../../../src/utils/testing/StubQueryContextProvider.ts"],"names":[],"mappings":";;;;;;AACA,kGAA0E;AAE1E,MAAa,wBAAyB,SAAQ,oCAA0B;IAC5D,iBAAiB;QACzB,OAAO,EAAE,CAAC;IACZ,CAAC;IAES,uBAAuB,CAC/B,kBAAsC;QAEtC,OAAO,CAAC,gBAAgB,EAAE,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,gBAAgB,CAAC,EAAE,CAAC,CAAC,CAAC;IACrE,CAAC;IAES,6BAA6B,CACrC,oBAAyB;QAEzB,OAAO,CAAC,gBAAgB,EAAE,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,gBAAgB,CAAC,EAAE,CAAC,CAAC,CAAC;IACrE,CAAC;CACF;AAhBD,4DAgBC;AAED,kBAAe,IAAI,wBAAwB,EAAE,CAAC"}
|
|
@@ -4,11 +4,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.createUnitTestEntityCompanionProvider = void 0;
|
|
7
|
-
const EntityCompanionProvider_1 = __importDefault(require("../../EntityCompanionProvider"));
|
|
8
|
-
const NoOpEntityMetricsAdapter_1 = __importDefault(require("../../metrics/NoOpEntityMetricsAdapter"));
|
|
9
7
|
const StubCacheAdapter_1 = require("./StubCacheAdapter");
|
|
10
8
|
const StubDatabaseAdapterProvider_1 = __importDefault(require("./StubDatabaseAdapterProvider"));
|
|
11
9
|
const StubQueryContextProvider_1 = __importDefault(require("./StubQueryContextProvider"));
|
|
10
|
+
const EntityCompanionProvider_1 = __importDefault(require("../../EntityCompanionProvider"));
|
|
11
|
+
const NoOpEntityMetricsAdapter_1 = __importDefault(require("../../metrics/NoOpEntityMetricsAdapter"));
|
|
12
12
|
/**
|
|
13
13
|
* Entity companion provider for use in unit tests. All database and cache implementations
|
|
14
14
|
* are replaced with in-memory simulations.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createUnitTestEntityCompanionProvider.js","sourceRoot":"","sources":["../../../src/utils/testing/createUnitTestEntityCompanionProvider.ts"],"names":[],"mappings":";;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"createUnitTestEntityCompanionProvider.js","sourceRoot":"","sources":["../../../src/utils/testing/createUnitTestEntityCompanionProvider.ts"],"names":[],"mappings":";;;;;;AAAA,yDAA+E;AAC/E,gGAAwE;AACxE,0FAAkE;AAClE,4FAAoE;AAEpE,sGAA8E;AAE9E;;;GAGG;AACI,MAAM,qCAAqC,GAAG,CACnD,iBAAwC,IAAI,kCAAwB,EAAE,EAC7C,EAAE;IAC3B,OAAO,IAAI,iCAAuB,CAChC,cAAc,EACd,IAAI,GAAG,CAAC;QACN;YACE,UAAU;YACV;gBACE,eAAe,EAAE,IAAI,qCAA2B,EAAE;gBAClD,oBAAoB,EAAE,kCAAwB;aAC/C;SACF;KACF,CAAC,EACF,IAAI,GAAG,CAAC;QACN;YACE,OAAO;YACP;gBACE,oBAAoB,EAAE,IAAI,4DAAyC,EAAE;aACtE;SACF;KACF,CAAC,CACH,CAAC;AACJ,CAAC,CAAC;AAvBW,QAAA,qCAAqC,yCAuBhD"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@expo/entity",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.32.0",
|
|
4
4
|
"description": "A privacy-first data model",
|
|
5
5
|
"files": [
|
|
6
6
|
"build",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"barrelsby": "barrelsby --directory src --location top --exclude tests__ --singleQuotes --exportDefault --delete"
|
|
20
20
|
},
|
|
21
21
|
"engines": {
|
|
22
|
-
"node": ">=
|
|
22
|
+
"node": ">=16"
|
|
23
23
|
},
|
|
24
24
|
"keywords": [
|
|
25
25
|
"entity"
|
|
@@ -33,5 +33,5 @@
|
|
|
33
33
|
"invariant": "^2.2.4",
|
|
34
34
|
"uuid": "^8.3.0"
|
|
35
35
|
},
|
|
36
|
-
"gitHead": "
|
|
36
|
+
"gitHead": "d2a4405fa1af673a98e36b9b7c76c0ee7961a23e"
|
|
37
37
|
}
|
|
@@ -1,26 +1,19 @@
|
|
|
1
1
|
import nullthrows from 'nullthrows';
|
|
2
2
|
|
|
3
|
-
import
|
|
4
|
-
import EntityConfiguration from './EntityConfiguration';
|
|
3
|
+
import IEntityCacheAdapter from './IEntityCacheAdapter';
|
|
5
4
|
import { CacheStatus, CacheLoadResult } from './internal/ReadThroughEntityCache';
|
|
6
5
|
|
|
7
6
|
/**
|
|
8
|
-
* A
|
|
7
|
+
* A IEntityCacheAdapter that composes other IEntityCacheAdapter instances.
|
|
9
8
|
*/
|
|
10
|
-
export default class ComposedEntityCacheAdapter<TFields>
|
|
9
|
+
export default class ComposedEntityCacheAdapter<TFields> implements IEntityCacheAdapter<TFields> {
|
|
11
10
|
/**
|
|
12
|
-
* @param entityConfiguration - configuration for entity being loaded
|
|
13
11
|
* @param cacheAdapters - list of cache adapters to compose in order of precedence.
|
|
14
12
|
* Earlier cache adapters are read from first and written to (including invalidations) last.
|
|
15
13
|
* Typically, caches closer to the application should be ordered before caches closer to the database.
|
|
16
14
|
* A lower layer cache is closer to the database, while a higher layer cache is closer to the application.
|
|
17
15
|
*/
|
|
18
|
-
constructor(
|
|
19
|
-
entityConfiguration: EntityConfiguration<TFields>,
|
|
20
|
-
private readonly cacheAdapters: EntityCacheAdapter<TFields>[]
|
|
21
|
-
) {
|
|
22
|
-
super(entityConfiguration);
|
|
23
|
-
}
|
|
16
|
+
constructor(private readonly cacheAdapters: IEntityCacheAdapter<TFields>[]) {}
|
|
24
17
|
|
|
25
18
|
public async loadManyAsync<N extends keyof TFields>(
|
|
26
19
|
fieldName: N,
|
|
@@ -14,7 +14,7 @@ import { mapMap } from './utils/collections/maps';
|
|
|
14
14
|
* if the loads are not successful.
|
|
15
15
|
*/
|
|
16
16
|
export default class EnforcingEntityLoader<
|
|
17
|
-
TFields,
|
|
17
|
+
TFields extends object,
|
|
18
18
|
TID extends NonNullable<TFields[TSelectedFields]>,
|
|
19
19
|
TViewerContext extends ViewerContext,
|
|
20
20
|
TEntity extends ReadonlyEntity<TFields, TID, TViewerContext, TSelectedFields>,
|
|
@@ -114,6 +114,22 @@ export default class EnforcingEntityLoader<
|
|
|
114
114
|
return mapMap(entityResults, (result) => result.enforceValue());
|
|
115
115
|
}
|
|
116
116
|
|
|
117
|
+
/**
|
|
118
|
+
* Enforcing version of entity loader method by the same name.
|
|
119
|
+
* @throws EntityNotAuthorizedError when viewer is not authorized to view one or more of the returned entities
|
|
120
|
+
*/
|
|
121
|
+
async loadFirstByFieldEqualityConjunctionAsync<N extends keyof Pick<TFields, TSelectedFields>>(
|
|
122
|
+
fieldEqualityOperands: FieldEqualityCondition<TFields, N>[],
|
|
123
|
+
querySelectionModifiers: Omit<QuerySelectionModifiers<TFields>, 'limit'> &
|
|
124
|
+
Required<Pick<QuerySelectionModifiers<TFields>, 'orderBy'>>
|
|
125
|
+
): Promise<TEntity | null> {
|
|
126
|
+
const entityResult = await this.entityLoader.loadFirstByFieldEqualityConjunctionAsync(
|
|
127
|
+
fieldEqualityOperands,
|
|
128
|
+
querySelectionModifiers
|
|
129
|
+
);
|
|
130
|
+
return entityResult ? entityResult.enforceValue() : null;
|
|
131
|
+
}
|
|
132
|
+
|
|
117
133
|
/**
|
|
118
134
|
* Enforcing version of entity loader method by the same name.
|
|
119
135
|
* @throws EntityNotAuthorizedError when viewer is not authorized to view one or more of the returned entities
|
package/src/Entity.ts
CHANGED
|
@@ -26,7 +26,7 @@ import ViewerContext from './ViewerContext';
|
|
|
26
26
|
* own EntityCompanionDefinition.
|
|
27
27
|
*/
|
|
28
28
|
export default abstract class Entity<
|
|
29
|
-
TFields,
|
|
29
|
+
TFields extends object,
|
|
30
30
|
TID extends NonNullable<TFields[TSelectedFields]>,
|
|
31
31
|
TViewerContext extends ViewerContext,
|
|
32
32
|
TSelectedFields extends keyof TFields = keyof TFields
|
|
@@ -38,7 +38,7 @@ export default abstract class Entity<
|
|
|
38
38
|
* @returns mutator for creating an entity
|
|
39
39
|
*/
|
|
40
40
|
static creator<
|
|
41
|
-
TMFields,
|
|
41
|
+
TMFields extends object,
|
|
42
42
|
TMID extends NonNullable<TMFields[TMSelectedFields]>,
|
|
43
43
|
TMViewerContext extends ViewerContext,
|
|
44
44
|
TMViewerContext2 extends TMViewerContext,
|
|
@@ -79,7 +79,7 @@ export default abstract class Entity<
|
|
|
79
79
|
* @returns mutator for updating existingEntity
|
|
80
80
|
*/
|
|
81
81
|
static updater<
|
|
82
|
-
TMFields,
|
|
82
|
+
TMFields extends object,
|
|
83
83
|
TMID extends NonNullable<TMFields[TMSelectedFields]>,
|
|
84
84
|
TMViewerContext extends ViewerContext,
|
|
85
85
|
TMEntity extends Entity<TMFields, TMID, TMViewerContext, TMSelectedFields>,
|
|
@@ -120,7 +120,7 @@ export default abstract class Entity<
|
|
|
120
120
|
* @param queryContext - query context in which to perform the delete
|
|
121
121
|
*/
|
|
122
122
|
static deleteAsync<
|
|
123
|
-
TMFields,
|
|
123
|
+
TMFields extends object,
|
|
124
124
|
TMID extends NonNullable<TMFields[TMSelectedFields]>,
|
|
125
125
|
TMViewerContext extends ViewerContext,
|
|
126
126
|
TMEntity extends Entity<TMFields, TMID, TMViewerContext, TMSelectedFields>,
|
|
@@ -162,7 +162,7 @@ export default abstract class Entity<
|
|
|
162
162
|
* @param queryContext - query context in which to perform the delete
|
|
163
163
|
*/
|
|
164
164
|
static enforceDeleteAsync<
|
|
165
|
-
TMFields,
|
|
165
|
+
TMFields extends object,
|
|
166
166
|
TMID extends NonNullable<TMFields[TMSelectedFields]>,
|
|
167
167
|
TMViewerContext extends ViewerContext,
|
|
168
168
|
TMEntity extends Entity<TMFields, TMID, TMViewerContext, TMSelectedFields>,
|
|
@@ -215,7 +215,7 @@ export default abstract class Entity<
|
|
|
215
215
|
* @param queryContext - query context in which to perform the check
|
|
216
216
|
*/
|
|
217
217
|
static async canViewerUpdateAsync<
|
|
218
|
-
TMFields,
|
|
218
|
+
TMFields extends object,
|
|
219
219
|
TMID extends NonNullable<TMFields[TMSelectedFields]>,
|
|
220
220
|
TMViewerContext extends ViewerContext,
|
|
221
221
|
TMEntity extends Entity<TMFields, TMID, TMViewerContext, TMSelectedFields>,
|
|
@@ -246,7 +246,7 @@ export default abstract class Entity<
|
|
|
246
246
|
const companion = existingEntity
|
|
247
247
|
.getViewerContext()
|
|
248
248
|
.getViewerScopedEntityCompanionForClass(this);
|
|
249
|
-
const privacyPolicy =
|
|
249
|
+
const privacyPolicy = companion.entityCompanion.privacyPolicy;
|
|
250
250
|
const evaluationResult = await asyncResult(
|
|
251
251
|
privacyPolicy.authorizeUpdateAsync(
|
|
252
252
|
existingEntity.getViewerContext(),
|
|
@@ -269,7 +269,7 @@ export default abstract class Entity<
|
|
|
269
269
|
* @param queryContext - query context in which to perform the check
|
|
270
270
|
*/
|
|
271
271
|
static async canViewerDeleteAsync<
|
|
272
|
-
TMFields,
|
|
272
|
+
TMFields extends object,
|
|
273
273
|
TMID extends NonNullable<TMFields[TMSelectedFields]>,
|
|
274
274
|
TMViewerContext extends ViewerContext,
|
|
275
275
|
TMEntity extends Entity<TMFields, TMID, TMViewerContext, TMSelectedFields>,
|
|
@@ -300,7 +300,7 @@ export default abstract class Entity<
|
|
|
300
300
|
const companion = existingEntity
|
|
301
301
|
.getViewerContext()
|
|
302
302
|
.getViewerScopedEntityCompanionForClass(this);
|
|
303
|
-
const privacyPolicy =
|
|
303
|
+
const privacyPolicy = companion.entityCompanion.privacyPolicy;
|
|
304
304
|
const evaluationResult = await asyncResult(
|
|
305
305
|
privacyPolicy.authorizeDeleteAsync(
|
|
306
306
|
existingEntity.getViewerContext(),
|
|
@@ -318,7 +318,7 @@ export default abstract class Entity<
|
|
|
318
318
|
* An interface to pass in constructor (class) of an Entity as a function argument.
|
|
319
319
|
*/
|
|
320
320
|
export interface IEntityClass<
|
|
321
|
-
TFields,
|
|
321
|
+
TFields extends object,
|
|
322
322
|
TID extends NonNullable<TFields[TSelectedFields]>,
|
|
323
323
|
TViewerContext extends ViewerContext,
|
|
324
324
|
TEntity extends ReadonlyEntity<TFields, TID, TViewerContext, TSelectedFields>,
|
|
@@ -331,8 +331,19 @@ export interface IEntityClass<
|
|
|
331
331
|
>,
|
|
332
332
|
TSelectedFields extends keyof TFields = keyof TFields
|
|
333
333
|
> {
|
|
334
|
-
new (
|
|
335
|
-
|
|
334
|
+
new (constructorParam: {
|
|
335
|
+
viewerContext: TViewerContext;
|
|
336
|
+
id: TID;
|
|
337
|
+
databaseFields: Readonly<TFields>;
|
|
338
|
+
selectedFields: Readonly<Pick<TFields, TSelectedFields>>;
|
|
339
|
+
}): TEntity;
|
|
340
|
+
|
|
341
|
+
/**
|
|
342
|
+
* Returns a EntityCompanionDefinition for this entity.
|
|
343
|
+
*
|
|
344
|
+
* Memoized by the entity framework.
|
|
345
|
+
*/
|
|
346
|
+
defineCompanionDefinition(): EntityCompanionDefinition<
|
|
336
347
|
TFields,
|
|
337
348
|
TID,
|
|
338
349
|
TViewerContext,
|
|
@@ -12,7 +12,7 @@ import ViewerContext from './ViewerContext';
|
|
|
12
12
|
* by foreign keys.
|
|
13
13
|
*/
|
|
14
14
|
export default class EntityAssociationLoader<
|
|
15
|
-
TFields,
|
|
15
|
+
TFields extends object,
|
|
16
16
|
TID extends NonNullable<TFields[TSelectedFields]>,
|
|
17
17
|
TViewerContext extends ViewerContext,
|
|
18
18
|
TEntity extends ReadonlyEntity<TFields, TID, TViewerContext, TSelectedFields>,
|
|
@@ -29,7 +29,7 @@ export default class EntityAssociationLoader<
|
|
|
29
29
|
*/
|
|
30
30
|
async loadAssociatedEntityAsync<
|
|
31
31
|
TIdentifyingField extends keyof Pick<TFields, TSelectedFields>,
|
|
32
|
-
TAssociatedFields,
|
|
32
|
+
TAssociatedFields extends object,
|
|
33
33
|
TAssociatedID extends NonNullable<TAssociatedFields[TAssociatedSelectedFields]>,
|
|
34
34
|
TAssociatedEntity extends ReadonlyEntity<
|
|
35
35
|
TAssociatedFields,
|
|
@@ -91,7 +91,7 @@ export default class EntityAssociationLoader<
|
|
|
91
91
|
* @param queryContext - query context in which to perform the load
|
|
92
92
|
*/
|
|
93
93
|
async loadManyAssociatedEntitiesAsync<
|
|
94
|
-
TAssociatedFields,
|
|
94
|
+
TAssociatedFields extends object,
|
|
95
95
|
TAssociatedID extends NonNullable<TAssociatedFields[TAssociatedSelectedFields]>,
|
|
96
96
|
TAssociatedEntity extends ReadonlyEntity<
|
|
97
97
|
TAssociatedFields,
|
|
@@ -144,7 +144,7 @@ export default class EntityAssociationLoader<
|
|
|
144
144
|
* @param queryContext - query context in which to perform the load
|
|
145
145
|
*/
|
|
146
146
|
async loadAssociatedEntityByFieldEqualingAsync<
|
|
147
|
-
TAssociatedFields,
|
|
147
|
+
TAssociatedFields extends object,
|
|
148
148
|
TAssociatedID extends NonNullable<TAssociatedFields[TAssociatedSelectedFields]>,
|
|
149
149
|
TAssociatedEntity extends ReadonlyEntity<
|
|
150
150
|
TAssociatedFields,
|
|
@@ -201,7 +201,7 @@ export default class EntityAssociationLoader<
|
|
|
201
201
|
* @param queryContext - query context in which to perform the load
|
|
202
202
|
*/
|
|
203
203
|
async loadManyAssociatedEntitiesByFieldEqualingAsync<
|
|
204
|
-
TAssociatedFields,
|
|
204
|
+
TAssociatedFields extends object,
|
|
205
205
|
TAssociatedID extends NonNullable<TAssociatedFields[TAssociatedSelectedFields]>,
|
|
206
206
|
TAssociatedEntity extends ReadonlyEntity<
|
|
207
207
|
TAssociatedFields,
|
|
@@ -257,7 +257,7 @@ export default class EntityAssociationLoader<
|
|
|
257
257
|
* @param queryContext - query context in which to perform the loads
|
|
258
258
|
*/
|
|
259
259
|
async loadAssociatedEntityThroughAsync<
|
|
260
|
-
TFields2,
|
|
260
|
+
TFields2 extends object,
|
|
261
261
|
TID2 extends NonNullable<TFields2[TSelectedFields2]>,
|
|
262
262
|
TEntity2 extends ReadonlyEntity<TFields2, TID2, TViewerContext, TSelectedFields2>,
|
|
263
263
|
TPrivacyPolicy2 extends EntityPrivacyPolicy<
|
|
@@ -291,7 +291,7 @@ export default class EntityAssociationLoader<
|
|
|
291
291
|
* @param queryContext - query context in which to perform the loads
|
|
292
292
|
*/
|
|
293
293
|
async loadAssociatedEntityThroughAsync<
|
|
294
|
-
TFields2,
|
|
294
|
+
TFields2 extends object,
|
|
295
295
|
TID2 extends NonNullable<TFields2[TSelectedFields2]>,
|
|
296
296
|
TEntity2 extends ReadonlyEntity<TFields2, TID2, TViewerContext, TSelectedFields2>,
|
|
297
297
|
TPrivacyPolicy2 extends EntityPrivacyPolicy<
|
|
@@ -301,7 +301,7 @@ export default class EntityAssociationLoader<
|
|
|
301
301
|
TEntity2,
|
|
302
302
|
TSelectedFields2
|
|
303
303
|
>,
|
|
304
|
-
TFields3,
|
|
304
|
+
TFields3 extends object,
|
|
305
305
|
TID3 extends NonNullable<TFields3[TSelectedFields3]>,
|
|
306
306
|
TEntity3 extends ReadonlyEntity<TFields3, TID3, TViewerContext, TSelectedFields3>,
|
|
307
307
|
TPrivacyPolicy3 extends EntityPrivacyPolicy<
|
|
@@ -346,7 +346,7 @@ export default class EntityAssociationLoader<
|
|
|
346
346
|
* @param queryContext - query context in which to perform the loads
|
|
347
347
|
*/
|
|
348
348
|
async loadAssociatedEntityThroughAsync<
|
|
349
|
-
TFields2,
|
|
349
|
+
TFields2 extends object,
|
|
350
350
|
TID2 extends NonNullable<TFields2[TSelectedFields2]>,
|
|
351
351
|
TEntity2 extends ReadonlyEntity<TFields2, TID2, TViewerContext, TSelectedFields2>,
|
|
352
352
|
TPrivacyPolicy2 extends EntityPrivacyPolicy<
|
|
@@ -356,7 +356,7 @@ export default class EntityAssociationLoader<
|
|
|
356
356
|
TEntity2,
|
|
357
357
|
TSelectedFields2
|
|
358
358
|
>,
|
|
359
|
-
TFields3,
|
|
359
|
+
TFields3 extends object,
|
|
360
360
|
TID3 extends NonNullable<TFields3[TSelectedFields3]>,
|
|
361
361
|
TEntity3 extends ReadonlyEntity<TFields3, TID3, TViewerContext, TSelectedFields3>,
|
|
362
362
|
TPrivacyPolicy3 extends EntityPrivacyPolicy<
|
|
@@ -366,7 +366,7 @@ export default class EntityAssociationLoader<
|
|
|
366
366
|
TEntity3,
|
|
367
367
|
TSelectedFields3
|
|
368
368
|
>,
|
|
369
|
-
TFields4,
|
|
369
|
+
TFields4 extends object,
|
|
370
370
|
TID4 extends NonNullable<TFields4[TSelectedFields4]>,
|
|
371
371
|
TEntity4 extends ReadonlyEntity<TFields4, TID4, TViewerContext, TSelectedFields4>,
|
|
372
372
|
TPrivacyPolicy4 extends EntityPrivacyPolicy<
|
|
@@ -482,7 +482,7 @@ export default class EntityAssociationLoader<
|
|
|
482
482
|
export interface EntityLoadThroughDirective<
|
|
483
483
|
TViewerContext extends ViewerContext,
|
|
484
484
|
TFields,
|
|
485
|
-
TAssociatedFields,
|
|
485
|
+
TAssociatedFields extends object,
|
|
486
486
|
TAssociatedID extends NonNullable<TAssociatedFields[TAssociatedSelectedFields]>,
|
|
487
487
|
TAssociatedEntity extends ReadonlyEntity<
|
|
488
488
|
TAssociatedFields,
|
package/src/EntityCompanion.ts
CHANGED
|
@@ -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';
|
|
@@ -18,7 +16,7 @@ export interface IPrivacyPolicyClass<TPrivacyPolicy> {
|
|
|
18
16
|
* Composition root responsible for orchestrating setup of Entity mutators and loaders.
|
|
19
17
|
*/
|
|
20
18
|
export default class EntityCompanion<
|
|
21
|
-
TFields,
|
|
19
|
+
TFields extends object,
|
|
22
20
|
TID extends NonNullable<TFields[TSelectedFields]>,
|
|
23
21
|
TViewerContext extends ViewerContext,
|
|
24
22
|
TEntity extends ReadonlyEntity<TFields, TID, TViewerContext, TSelectedFields>,
|
|
@@ -31,6 +29,8 @@ export default class EntityCompanion<
|
|
|
31
29
|
>,
|
|
32
30
|
TSelectedFields extends keyof TFields
|
|
33
31
|
> {
|
|
32
|
+
public readonly privacyPolicy: TPrivacyPolicy;
|
|
33
|
+
|
|
34
34
|
private readonly entityLoaderFactory: EntityLoaderFactory<
|
|
35
35
|
TFields,
|
|
36
36
|
TID,
|
|
@@ -49,7 +49,8 @@ export default class EntityCompanion<
|
|
|
49
49
|
>;
|
|
50
50
|
|
|
51
51
|
constructor(
|
|
52
|
-
|
|
52
|
+
public readonly entityCompanionProvider: EntityCompanionProvider,
|
|
53
|
+
public readonly entityCompanionDefinition: EntityCompanionDefinition<
|
|
53
54
|
TFields,
|
|
54
55
|
TID,
|
|
55
56
|
TViewerContext,
|
|
@@ -58,24 +59,9 @@ export default class EntityCompanion<
|
|
|
58
59
|
TSelectedFields
|
|
59
60
|
>,
|
|
60
61
|
private readonly tableDataCoordinator: EntityTableDataCoordinator<TFields>,
|
|
61
|
-
PrivacyPolicyClass: IPrivacyPolicyClass<TPrivacyPolicy>,
|
|
62
|
-
mutationValidators: EntityMutationValidator<
|
|
63
|
-
TFields,
|
|
64
|
-
TID,
|
|
65
|
-
TViewerContext,
|
|
66
|
-
TEntity,
|
|
67
|
-
TSelectedFields
|
|
68
|
-
>[],
|
|
69
|
-
mutationTriggers: EntityMutationTriggerConfiguration<
|
|
70
|
-
TFields,
|
|
71
|
-
TID,
|
|
72
|
-
TViewerContext,
|
|
73
|
-
TEntity,
|
|
74
|
-
TSelectedFields
|
|
75
|
-
>,
|
|
76
62
|
private readonly metricsAdapter: IEntityMetricsAdapter
|
|
77
63
|
) {
|
|
78
|
-
|
|
64
|
+
this.privacyPolicy = new entityCompanionDefinition.privacyPolicyClass();
|
|
79
65
|
this.entityLoaderFactory = new EntityLoaderFactory<
|
|
80
66
|
TFields,
|
|
81
67
|
TID,
|
|
@@ -83,19 +69,14 @@ export default class EntityCompanion<
|
|
|
83
69
|
TEntity,
|
|
84
70
|
TPrivacyPolicy,
|
|
85
71
|
TSelectedFields
|
|
86
|
-
>(
|
|
87
|
-
tableDataCoordinator.entityConfiguration,
|
|
88
|
-
entityClass,
|
|
89
|
-
privacyPolicy,
|
|
90
|
-
tableDataCoordinator.dataManager,
|
|
91
|
-
metricsAdapter
|
|
92
|
-
);
|
|
72
|
+
>(this, tableDataCoordinator.dataManager, metricsAdapter);
|
|
93
73
|
this.entityMutatorFactory = new EntityMutatorFactory(
|
|
74
|
+
entityCompanionProvider,
|
|
94
75
|
tableDataCoordinator.entityConfiguration,
|
|
95
|
-
entityClass,
|
|
96
|
-
privacyPolicy,
|
|
97
|
-
mutationValidators,
|
|
98
|
-
mutationTriggers,
|
|
76
|
+
entityCompanionDefinition.entityClass,
|
|
77
|
+
this.privacyPolicy,
|
|
78
|
+
entityCompanionDefinition.mutationValidators ?? [],
|
|
79
|
+
entityCompanionDefinition.mutationTriggers ?? {},
|
|
99
80
|
this.entityLoaderFactory,
|
|
100
81
|
tableDataCoordinator.databaseAdapter,
|
|
101
82
|
metricsAdapter
|
|
@@ -49,8 +49,8 @@ export interface CacheAdapterFlavorDefinition {
|
|
|
49
49
|
* Definition for constructing a companion for an entity. Defines the core set of objects
|
|
50
50
|
* used to power the entity framework for a particular type of entity.
|
|
51
51
|
*/
|
|
52
|
-
export
|
|
53
|
-
TFields,
|
|
52
|
+
export interface EntityCompanionDefinition<
|
|
53
|
+
TFields extends object,
|
|
54
54
|
TID extends NonNullable<TFields[TSelectedFields]>,
|
|
55
55
|
TViewerContext extends ViewerContext,
|
|
56
56
|
TEntity extends ReadonlyEntity<TFields, TID, TViewerContext, TSelectedFields>,
|
|
@@ -63,6 +63,9 @@ export class EntityCompanionDefinition<
|
|
|
63
63
|
>,
|
|
64
64
|
TSelectedFields extends keyof TFields = keyof TFields
|
|
65
65
|
> {
|
|
66
|
+
/**
|
|
67
|
+
* The concrete Entity class for which this is the definition.
|
|
68
|
+
*/
|
|
66
69
|
readonly entityClass: IEntityClass<
|
|
67
70
|
TFields,
|
|
68
71
|
TID,
|
|
@@ -71,85 +74,45 @@ export class EntityCompanionDefinition<
|
|
|
71
74
|
TPrivacyPolicy,
|
|
72
75
|
TSelectedFields
|
|
73
76
|
>;
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* The EntityConfiguration for this entity.
|
|
80
|
+
*/
|
|
74
81
|
readonly entityConfiguration: EntityConfiguration<TFields>;
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* The EntityPrivacyPolicy class for this entity.
|
|
85
|
+
*/
|
|
75
86
|
readonly privacyPolicyClass: IPrivacyPolicyClass<TPrivacyPolicy>;
|
|
76
|
-
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* An optional list of EntityMutationValidator for this entity.
|
|
90
|
+
*/
|
|
91
|
+
readonly mutationValidators?: EntityMutationValidator<
|
|
77
92
|
TFields,
|
|
78
93
|
TID,
|
|
79
94
|
TViewerContext,
|
|
80
95
|
TEntity,
|
|
81
96
|
TSelectedFields
|
|
82
97
|
>[];
|
|
83
|
-
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* An optional list of EntityMutationTrigger for this entity.
|
|
101
|
+
*/
|
|
102
|
+
readonly mutationTriggers?: EntityMutationTriggerConfiguration<
|
|
84
103
|
TFields,
|
|
85
104
|
TID,
|
|
86
105
|
TViewerContext,
|
|
87
106
|
TEntity,
|
|
88
107
|
TSelectedFields
|
|
89
108
|
>;
|
|
90
|
-
readonly entitySelectedFields: TSelectedFields[];
|
|
91
109
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
entitySelectedFields = Array.from(entityConfiguration.schema.keys()) as TSelectedFields[],
|
|
99
|
-
}: {
|
|
100
|
-
/**
|
|
101
|
-
* The concrete Entity class for which this is the definition.
|
|
102
|
-
*/
|
|
103
|
-
entityClass: IEntityClass<
|
|
104
|
-
TFields,
|
|
105
|
-
TID,
|
|
106
|
-
TViewerContext,
|
|
107
|
-
TEntity,
|
|
108
|
-
TPrivacyPolicy,
|
|
109
|
-
TSelectedFields
|
|
110
|
-
>;
|
|
111
|
-
/**
|
|
112
|
-
* The EntityConfiguration for this entity.
|
|
113
|
-
*/
|
|
114
|
-
entityConfiguration: EntityConfiguration<TFields>;
|
|
115
|
-
/**
|
|
116
|
-
* The EntityPrivacyPolicy class for this entity.
|
|
117
|
-
*/
|
|
118
|
-
privacyPolicyClass: IPrivacyPolicyClass<TPrivacyPolicy>;
|
|
119
|
-
/**
|
|
120
|
-
* An optional list of EntityMutationValidator for this entity.
|
|
121
|
-
*/
|
|
122
|
-
mutationValidators?: () => EntityMutationValidator<
|
|
123
|
-
TFields,
|
|
124
|
-
TID,
|
|
125
|
-
TViewerContext,
|
|
126
|
-
TEntity,
|
|
127
|
-
TSelectedFields
|
|
128
|
-
>[];
|
|
129
|
-
/**
|
|
130
|
-
* An optional list of EntityMutationTrigger for this entity.
|
|
131
|
-
*/
|
|
132
|
-
mutationTriggers?: () => EntityMutationTriggerConfiguration<
|
|
133
|
-
TFields,
|
|
134
|
-
TID,
|
|
135
|
-
TViewerContext,
|
|
136
|
-
TEntity,
|
|
137
|
-
TSelectedFields
|
|
138
|
-
>;
|
|
139
|
-
/**
|
|
140
|
-
* An optional subset of fields defined in the EntityConfiguration which belong to this entity.
|
|
141
|
-
* For use when multiple types of entities are backed by a single table (EntityConfiguration) yet
|
|
142
|
-
* only expose a subset of the fields.
|
|
143
|
-
*/
|
|
144
|
-
entitySelectedFields?: TSelectedFields[];
|
|
145
|
-
}) {
|
|
146
|
-
this.entityClass = entityClass;
|
|
147
|
-
this.entityConfiguration = entityConfiguration;
|
|
148
|
-
this.privacyPolicyClass = privacyPolicyClass;
|
|
149
|
-
this.mutationValidators = mutationValidators;
|
|
150
|
-
this.mutationTriggers = mutationTriggers;
|
|
151
|
-
this.entitySelectedFields = entitySelectedFields;
|
|
152
|
-
}
|
|
110
|
+
/**
|
|
111
|
+
* An optional subset of fields defined in the EntityConfiguration which belong to this entity.
|
|
112
|
+
* For use when multiple types of entities are backed by a single table (EntityConfiguration) yet
|
|
113
|
+
* only expose a subset of the fields.
|
|
114
|
+
*/
|
|
115
|
+
readonly entitySelectedFields?: TSelectedFields[];
|
|
153
116
|
}
|
|
154
117
|
|
|
155
118
|
/**
|
|
@@ -162,6 +125,10 @@ export class EntityCompanionDefinition<
|
|
|
162
125
|
* EntityCompanion for each type of Entity.
|
|
163
126
|
*/
|
|
164
127
|
export default class EntityCompanionProvider {
|
|
128
|
+
private readonly companionDefinitionMap: Map<
|
|
129
|
+
string,
|
|
130
|
+
EntityCompanionDefinition<any, any, any, any, any, any>
|
|
131
|
+
> = new Map();
|
|
165
132
|
private readonly companionMap: Map<string, EntityCompanion<any, any, any, any, any, any>> =
|
|
166
133
|
new Map();
|
|
167
134
|
private readonly tableDataCoordinatorMap: Map<string, EntityTableDataCoordinator<any>> =
|
|
@@ -187,10 +154,9 @@ export default class EntityCompanionProvider {
|
|
|
187
154
|
* companion is constructed using the configuration provided by the factory.
|
|
188
155
|
*
|
|
189
156
|
* @param entityClass - entity class to load
|
|
190
|
-
* @param factory - entity companion factory
|
|
191
157
|
*/
|
|
192
158
|
getCompanionForEntity<
|
|
193
|
-
TFields,
|
|
159
|
+
TFields extends object,
|
|
194
160
|
TID extends NonNullable<TFields[TSelectedFields]>,
|
|
195
161
|
TViewerContext extends ViewerContext,
|
|
196
162
|
TEntity extends ReadonlyEntity<TFields, TID, TViewerContext, TSelectedFields>,
|
|
@@ -210,27 +176,22 @@ export default class EntityCompanionProvider {
|
|
|
210
176
|
TEntity,
|
|
211
177
|
TPrivacyPolicy,
|
|
212
178
|
TSelectedFields
|
|
213
|
-
>,
|
|
214
|
-
entityCompanionDefinition: EntityCompanionDefinition<
|
|
215
|
-
TFields,
|
|
216
|
-
TID,
|
|
217
|
-
TViewerContext,
|
|
218
|
-
TEntity,
|
|
219
|
-
TPrivacyPolicy,
|
|
220
|
-
TSelectedFields
|
|
221
179
|
>
|
|
222
180
|
): EntityCompanion<TFields, TID, TViewerContext, TEntity, TPrivacyPolicy, TSelectedFields> {
|
|
181
|
+
const entityCompanionDefinition = computeIfAbsent(
|
|
182
|
+
this.companionDefinitionMap,
|
|
183
|
+
entityClass.name,
|
|
184
|
+
() => entityClass.defineCompanionDefinition()
|
|
185
|
+
);
|
|
223
186
|
const tableDataCoordinator = this.getTableDataCoordinatorForEntity(
|
|
224
187
|
entityCompanionDefinition.entityConfiguration,
|
|
225
188
|
entityClass.name
|
|
226
189
|
);
|
|
227
190
|
return computeIfAbsent(this.companionMap, entityClass.name, () => {
|
|
228
191
|
return new EntityCompanion(
|
|
229
|
-
|
|
192
|
+
this,
|
|
193
|
+
entityCompanionDefinition,
|
|
230
194
|
tableDataCoordinator,
|
|
231
|
-
entityCompanionDefinition.privacyPolicyClass,
|
|
232
|
-
entityCompanionDefinition.mutationValidators(),
|
|
233
|
-
entityCompanionDefinition.mutationTriggers(),
|
|
234
195
|
this.metricsAdapter
|
|
235
196
|
);
|
|
236
197
|
});
|
|
@@ -13,7 +13,7 @@ export default class EntityConfiguration<TFields> {
|
|
|
13
13
|
readonly cacheableKeys: ReadonlySet<keyof TFields>;
|
|
14
14
|
readonly cacheKeyVersion: number;
|
|
15
15
|
|
|
16
|
-
readonly
|
|
16
|
+
readonly inboundEdges: IEntityClass<any, any, any, any, any, any>[];
|
|
17
17
|
readonly schema: ReadonlyMap<keyof TFields, EntityFieldDefinition<any>>;
|
|
18
18
|
readonly entityToDBFieldsKeyMapping: ReadonlyMap<keyof TFields, string>;
|
|
19
19
|
readonly dbToEntityFieldsKeyMapping: ReadonlyMap<string, keyof TFields>;
|
|
@@ -25,7 +25,7 @@ export default class EntityConfiguration<TFields> {
|
|
|
25
25
|
idField,
|
|
26
26
|
tableName,
|
|
27
27
|
schema,
|
|
28
|
-
|
|
28
|
+
inboundEdges = [],
|
|
29
29
|
cacheKeyVersion = 0,
|
|
30
30
|
databaseAdapterFlavor,
|
|
31
31
|
cacheAdapterFlavor,
|
|
@@ -48,7 +48,7 @@ export default class EntityConfiguration<TFields> {
|
|
|
48
48
|
/**
|
|
49
49
|
* List of other entity types that reference this type in EntityFieldDefinition associations.
|
|
50
50
|
*/
|
|
51
|
-
|
|
51
|
+
inboundEdges?: IEntityClass<any, any, any, any, any, any>[];
|
|
52
52
|
|
|
53
53
|
/**
|
|
54
54
|
* Cache key version for this entity type. Should be bumped when a field is added to, removed from, or changed
|
|
@@ -71,8 +71,7 @@ export default class EntityConfiguration<TFields> {
|
|
|
71
71
|
this.cacheKeyVersion = cacheKeyVersion;
|
|
72
72
|
this.databaseAdapterFlavor = databaseAdapterFlavor;
|
|
73
73
|
this.cacheAdapterFlavor = cacheAdapterFlavor;
|
|
74
|
-
|
|
75
|
-
this.getInboundEdges = getInboundEdges;
|
|
74
|
+
this.inboundEdges = inboundEdges;
|
|
76
75
|
|
|
77
76
|
// external schema is a Record to typecheck that all fields have FieldDefinitions,
|
|
78
77
|
// but internally the most useful representation is a map for lookups
|
|
@@ -41,7 +41,7 @@ export enum EntityEdgeDeletionBehavior {
|
|
|
41
41
|
*/
|
|
42
42
|
export interface EntityAssociationDefinition<
|
|
43
43
|
TViewerContext extends ViewerContext,
|
|
44
|
-
TAssociatedFields,
|
|
44
|
+
TAssociatedFields extends object,
|
|
45
45
|
TAssociatedID extends NonNullable<TAssociatedFields[TAssociatedSelectedFields]>,
|
|
46
46
|
TAssociatedEntity extends ReadonlyEntity<
|
|
47
47
|
TAssociatedFields,
|
|
@@ -61,7 +61,7 @@ export interface EntityAssociationDefinition<
|
|
|
61
61
|
/**
|
|
62
62
|
* Class of entity on the other end of this edge.
|
|
63
63
|
*/
|
|
64
|
-
|
|
64
|
+
associatedEntityClass: IEntityClass<
|
|
65
65
|
TAssociatedFields,
|
|
66
66
|
TAssociatedID,
|
|
67
67
|
TViewerContext,
|