@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,5 +1,5 @@
|
|
|
1
|
-
import EntityCacheAdapter from './EntityCacheAdapter';
|
|
2
1
|
import EntityConfiguration from './EntityConfiguration';
|
|
2
|
+
import IEntityCacheAdapter from './IEntityCacheAdapter';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* A cache adapter provider vends cache adapters for a particular cache adapter type.
|
|
@@ -11,5 +11,5 @@ export default interface IEntityCacheAdapterProvider {
|
|
|
11
11
|
*/
|
|
12
12
|
getCacheAdapter<TFields>(
|
|
13
13
|
entityConfiguration: EntityConfiguration<TFields>
|
|
14
|
-
):
|
|
14
|
+
): IEntityCacheAdapter<TFields>;
|
|
15
15
|
}
|
|
@@ -1,15 +1,45 @@
|
|
|
1
1
|
import { CacheLoadResult } from './internal/ReadThroughEntityCache';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* A cacher stores and loads key-value pairs. It also supports negative caching - it stores the absence
|
|
5
|
-
* of keys that don't exist in the backing datastore.
|
|
4
|
+
* A generic cacher stores and loads key-value pairs. It also supports negative caching - it stores the absence
|
|
5
|
+
* of keys that don't exist in the backing datastore. It is also responsible for cache key creation.
|
|
6
6
|
*/
|
|
7
7
|
export default interface IEntityGenericCacher<TFields> {
|
|
8
|
+
/**
|
|
9
|
+
* Load many keys from the cache. Return info in a format that is useful for read-through caching and
|
|
10
|
+
* negative caching.
|
|
11
|
+
*
|
|
12
|
+
* @param keys - cache keys to load
|
|
13
|
+
*/
|
|
8
14
|
loadManyAsync(keys: readonly string[]): Promise<ReadonlyMap<string, CacheLoadResult<TFields>>>;
|
|
9
15
|
|
|
16
|
+
/**
|
|
17
|
+
* Cache many objects for specified keys.
|
|
18
|
+
*
|
|
19
|
+
* @param objectMap - map from cache key to object to cache for key
|
|
20
|
+
*/
|
|
10
21
|
cacheManyAsync(objectMap: ReadonlyMap<string, Readonly<TFields>>): Promise<void>;
|
|
11
22
|
|
|
23
|
+
/**
|
|
24
|
+
* Negatively-cache specified keys. Subsequent loads for these keys (without calling invalidate) may
|
|
25
|
+
* return a negative CacheLoadResult
|
|
26
|
+
*
|
|
27
|
+
* @param keys - keys to cache negatively
|
|
28
|
+
*/
|
|
12
29
|
cacheDBMissesAsync(keys: readonly string[]): Promise<void>;
|
|
13
30
|
|
|
31
|
+
/**
|
|
32
|
+
* Invalidate specified keys in cache. Subsequent loads for these keys may return a cache miss.
|
|
33
|
+
*
|
|
34
|
+
* @param keys - keys to invalidate
|
|
35
|
+
*/
|
|
14
36
|
invalidateManyAsync(keys: readonly string[]): Promise<void>;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Create a cache key for a field and value of a object being cached or invalidated.
|
|
40
|
+
*
|
|
41
|
+
* @param fieldName - name of the object field for this cache key
|
|
42
|
+
* @param fieldValue - value of the obejct field for this cache key
|
|
43
|
+
*/
|
|
44
|
+
makeCacheKey<N extends keyof TFields>(fieldName: N, fieldValue: NonNullable<TFields[N]>): string;
|
|
15
45
|
}
|
package/src/ReadonlyEntity.ts
CHANGED
|
@@ -2,12 +2,10 @@ import invariant from 'invariant';
|
|
|
2
2
|
|
|
3
3
|
import { IEntityClass } from './Entity';
|
|
4
4
|
import EntityAssociationLoader from './EntityAssociationLoader';
|
|
5
|
-
import { EntityCompanionDefinition } from './EntityCompanionProvider';
|
|
6
5
|
import EntityLoader from './EntityLoader';
|
|
7
6
|
import EntityPrivacyPolicy from './EntityPrivacyPolicy';
|
|
8
7
|
import { EntityQueryContext } from './EntityQueryContext';
|
|
9
8
|
import ViewerContext from './ViewerContext';
|
|
10
|
-
import { pick } from './entityUtils';
|
|
11
9
|
|
|
12
10
|
/**
|
|
13
11
|
* A readonly entity exposes only the read functionality of an Entity. Used as the base
|
|
@@ -18,45 +16,47 @@ import { pick } from './entityUtils';
|
|
|
18
16
|
* - Entities representing immutable tables.
|
|
19
17
|
*/
|
|
20
18
|
export default abstract class ReadonlyEntity<
|
|
21
|
-
TFields,
|
|
19
|
+
TFields extends object,
|
|
22
20
|
TID extends NonNullable<TFields[TSelectedFields]>,
|
|
23
21
|
TViewerContext extends ViewerContext,
|
|
24
22
|
TSelectedFields extends keyof TFields = keyof TFields
|
|
25
23
|
> {
|
|
24
|
+
private readonly viewerContext: TViewerContext;
|
|
26
25
|
private readonly id: TID;
|
|
27
|
-
private readonly
|
|
26
|
+
private readonly databaseFields: Readonly<TFields>;
|
|
27
|
+
private readonly selectedFields: Readonly<Pick<TFields, TSelectedFields>>;
|
|
28
28
|
|
|
29
29
|
/**
|
|
30
30
|
* Constructs an instance of an Entity.
|
|
31
|
-
*
|
|
32
|
-
* @param
|
|
31
|
+
*
|
|
32
|
+
* @param constructorParam - data needed to construct an instance of an entity
|
|
33
|
+
* viewerContext - the ViewerContext reading this entity
|
|
34
|
+
* id - the ID of this entity
|
|
35
|
+
* databaseFields - all underlying fields for this entity's data
|
|
36
|
+
* selectedFields - selected fields for this entity from TSelectedFields type
|
|
37
|
+
*
|
|
38
|
+
* This should only be overridden in cases where additional data validation is needed.
|
|
39
|
+
* The params should not be modified when calling super during constructions.
|
|
33
40
|
*
|
|
34
41
|
* @internal
|
|
35
42
|
*/
|
|
36
|
-
constructor(
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
TSelectedFields
|
|
49
|
-
>;
|
|
50
|
-
const idField = companionDefinition.entityConfiguration.idField as keyof Pick<
|
|
51
|
-
TFields,
|
|
52
|
-
TSelectedFields
|
|
53
|
-
>;
|
|
54
|
-
const id = databaseFields[idField];
|
|
55
|
-
invariant(id, 'must provide ID to create an entity');
|
|
56
|
-
this.id = id as any;
|
|
43
|
+
constructor({
|
|
44
|
+
viewerContext,
|
|
45
|
+
id,
|
|
46
|
+
databaseFields,
|
|
47
|
+
selectedFields,
|
|
48
|
+
}: {
|
|
49
|
+
viewerContext: TViewerContext;
|
|
50
|
+
id: TID;
|
|
51
|
+
databaseFields: Readonly<TFields>;
|
|
52
|
+
selectedFields: Readonly<Pick<TFields, TSelectedFields>>;
|
|
53
|
+
}) {
|
|
54
|
+
invariant(id !== null && id !== undefined, 'id must be non-null');
|
|
57
55
|
|
|
58
|
-
|
|
59
|
-
this.
|
|
56
|
+
this.viewerContext = viewerContext;
|
|
57
|
+
this.id = id;
|
|
58
|
+
this.databaseFields = databaseFields;
|
|
59
|
+
this.selectedFields = selectedFields;
|
|
60
60
|
}
|
|
61
61
|
|
|
62
62
|
toString(): string {
|
|
@@ -102,14 +102,14 @@ export default abstract class ReadonlyEntity<
|
|
|
102
102
|
getField<K extends keyof Pick<TFields, TSelectedFields>>(
|
|
103
103
|
fieldName: K
|
|
104
104
|
): Pick<TFields, TSelectedFields>[K] {
|
|
105
|
-
return this.
|
|
105
|
+
return this.selectedFields[fieldName];
|
|
106
106
|
}
|
|
107
107
|
|
|
108
108
|
/**
|
|
109
109
|
* @returns all underlying fields from this entity's data
|
|
110
110
|
*/
|
|
111
111
|
getAllFields(): Readonly<Pick<TFields, TSelectedFields>> {
|
|
112
|
-
return { ...this.
|
|
112
|
+
return { ...this.selectedFields };
|
|
113
113
|
}
|
|
114
114
|
|
|
115
115
|
/**
|
|
@@ -125,7 +125,7 @@ export default abstract class ReadonlyEntity<
|
|
|
125
125
|
* @param queryContext - query context in which to perform the load
|
|
126
126
|
*/
|
|
127
127
|
static loader<
|
|
128
|
-
TMFields,
|
|
128
|
+
TMFields extends object,
|
|
129
129
|
TMID extends NonNullable<TMFields[TMSelectedFields]>,
|
|
130
130
|
TMViewerContext extends ViewerContext,
|
|
131
131
|
TMViewerContext2 extends TMViewerContext,
|
package/src/ViewerContext.ts
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import { IEntityClass } from './Entity';
|
|
2
2
|
import EntityCompanionProvider, { DatabaseAdapterFlavor } from './EntityCompanionProvider';
|
|
3
3
|
import EntityPrivacyPolicy from './EntityPrivacyPolicy';
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
EntityQueryContext,
|
|
6
|
+
EntityTransactionalQueryContext,
|
|
7
|
+
TransactionConfig,
|
|
8
|
+
} from './EntityQueryContext';
|
|
5
9
|
import ReadonlyEntity from './ReadonlyEntity';
|
|
6
10
|
import ViewerScopedEntityCompanion from './ViewerScopedEntityCompanion';
|
|
7
11
|
import ViewerScopedEntityCompanionProvider from './ViewerScopedEntityCompanionProvider';
|
|
@@ -27,7 +31,7 @@ export default class ViewerContext {
|
|
|
27
31
|
}
|
|
28
32
|
|
|
29
33
|
getViewerScopedEntityCompanionForClass<
|
|
30
|
-
TMFields,
|
|
34
|
+
TMFields extends object,
|
|
31
35
|
TMID extends NonNullable<TMFields[TMSelectedFields]>,
|
|
32
36
|
TMViewerContext extends ViewerContext,
|
|
33
37
|
TMEntity extends ReadonlyEntity<TMFields, TMID, TMViewerContext, TMSelectedFields>,
|
|
@@ -56,10 +60,7 @@ export default class ViewerContext {
|
|
|
56
60
|
TMPrivacyPolicy,
|
|
57
61
|
TMSelectedFields
|
|
58
62
|
> {
|
|
59
|
-
return this.viewerScopedEntityCompanionProvider.getViewerScopedCompanionForEntity(
|
|
60
|
-
entityClass,
|
|
61
|
-
entityClass.getCompanionDefinition()
|
|
62
|
-
);
|
|
63
|
+
return this.viewerScopedEntityCompanionProvider.getViewerScopedCompanionForEntity(entityClass);
|
|
63
64
|
}
|
|
64
65
|
|
|
65
66
|
/**
|
|
@@ -82,11 +83,12 @@ export default class ViewerContext {
|
|
|
82
83
|
*/
|
|
83
84
|
async runInTransactionForDatabaseAdaptorFlavorAsync<TResult>(
|
|
84
85
|
databaseAdaptorFlavor: DatabaseAdapterFlavor,
|
|
85
|
-
transactionScope: (queryContext: EntityTransactionalQueryContext) => Promise<TResult
|
|
86
|
+
transactionScope: (queryContext: EntityTransactionalQueryContext) => Promise<TResult>,
|
|
87
|
+
transactionConfig?: TransactionConfig
|
|
86
88
|
): Promise<TResult> {
|
|
87
89
|
return await this.entityCompanionProvider
|
|
88
90
|
.getQueryContextProviderForDatabaseAdaptorFlavor(databaseAdaptorFlavor)
|
|
89
91
|
.getQueryContext()
|
|
90
|
-
.runInTransactionIfNotInTransactionAsync(transactionScope);
|
|
92
|
+
.runInTransactionIfNotInTransactionAsync(transactionScope, transactionConfig);
|
|
91
93
|
}
|
|
92
94
|
}
|
|
@@ -12,7 +12,7 @@ import IEntityMetricsAdapter from './metrics/IEntityMetricsAdapter';
|
|
|
12
12
|
* from the viewer-scoped entity companion provider.
|
|
13
13
|
*/
|
|
14
14
|
export default class ViewerScopedEntityCompanion<
|
|
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>,
|
|
@@ -26,7 +26,7 @@ export default class ViewerScopedEntityCompanion<
|
|
|
26
26
|
TSelectedFields extends keyof TFields
|
|
27
27
|
> {
|
|
28
28
|
constructor(
|
|
29
|
-
|
|
29
|
+
public readonly entityCompanion: EntityCompanion<
|
|
30
30
|
TFields,
|
|
31
31
|
TID,
|
|
32
32
|
TViewerContext,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { IEntityClass } from './Entity';
|
|
2
|
-
import EntityCompanionProvider
|
|
2
|
+
import EntityCompanionProvider from './EntityCompanionProvider';
|
|
3
3
|
import EntityPrivacyPolicy from './EntityPrivacyPolicy';
|
|
4
4
|
import ReadonlyEntity from './ReadonlyEntity';
|
|
5
5
|
import ViewerContext from './ViewerContext';
|
|
@@ -19,10 +19,10 @@ export default class ViewerScopedEntityCompanionProvider {
|
|
|
19
19
|
* companion is constructed using the configuration provided by the factory.
|
|
20
20
|
*
|
|
21
21
|
* @param entityClass - entity class to load
|
|
22
|
-
* @param
|
|
22
|
+
* @param entityCompanionDefinitionFn - function defining entity companion definition
|
|
23
23
|
*/
|
|
24
24
|
getViewerScopedCompanionForEntity<
|
|
25
|
-
TFields,
|
|
25
|
+
TFields extends object,
|
|
26
26
|
TID extends NonNullable<TFields[TSelectedFields]>,
|
|
27
27
|
TViewerContext extends ViewerContext,
|
|
28
28
|
TEntity extends ReadonlyEntity<TFields, TID, TViewerContext, TSelectedFields>,
|
|
@@ -42,14 +42,6 @@ export default class ViewerScopedEntityCompanionProvider {
|
|
|
42
42
|
TEntity,
|
|
43
43
|
TPrivacyPolicy,
|
|
44
44
|
TSelectedFields
|
|
45
|
-
>,
|
|
46
|
-
entityCompanionDefinition: EntityCompanionDefinition<
|
|
47
|
-
TFields,
|
|
48
|
-
TID,
|
|
49
|
-
TViewerContext,
|
|
50
|
-
TEntity,
|
|
51
|
-
TPrivacyPolicy,
|
|
52
|
-
TSelectedFields
|
|
53
45
|
>
|
|
54
46
|
): ViewerScopedEntityCompanion<
|
|
55
47
|
TFields,
|
|
@@ -60,7 +52,7 @@ export default class ViewerScopedEntityCompanionProvider {
|
|
|
60
52
|
TSelectedFields
|
|
61
53
|
> {
|
|
62
54
|
return new ViewerScopedEntityCompanion(
|
|
63
|
-
this.entityCompanionProvider.getCompanionForEntity(entityClass
|
|
55
|
+
this.entityCompanionProvider.getCompanionForEntity(entityClass),
|
|
64
56
|
this.viewerContext as TViewerContext
|
|
65
57
|
);
|
|
66
58
|
}
|
|
@@ -9,7 +9,7 @@ import ViewerContext from './ViewerContext';
|
|
|
9
9
|
* Provides a cleaner API for loading entities by passing through the ViewerContext.
|
|
10
10
|
*/
|
|
11
11
|
export default class ViewerScopedEntityLoaderFactory<
|
|
12
|
-
TFields,
|
|
12
|
+
TFields extends object,
|
|
13
13
|
TID extends NonNullable<TFields[TSelectedFields]>,
|
|
14
14
|
TViewerContext extends ViewerContext,
|
|
15
15
|
TEntity extends ReadonlyEntity<TFields, TID, TViewerContext, TSelectedFields>,
|
|
@@ -9,7 +9,7 @@ import ViewerContext from './ViewerContext';
|
|
|
9
9
|
* Provides a cleaner API for mutating entities by passing through the ViewerContext.
|
|
10
10
|
*/
|
|
11
11
|
export default class ViewerScopedEntityMutatorFactory<
|
|
12
|
-
TFields,
|
|
12
|
+
TFields extends object,
|
|
13
13
|
TID extends NonNullable<TFields[TSelectedFields]>,
|
|
14
14
|
TViewerContext extends ViewerContext,
|
|
15
15
|
TEntity extends ReadonlyEntity<TFields, TID, TViewerContext, TSelectedFields>,
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import invariant from 'invariant';
|
|
2
2
|
|
|
3
3
|
import ComposedEntityCacheAdapter from '../ComposedEntityCacheAdapter';
|
|
4
|
-
import EntityCacheAdapter from '../EntityCacheAdapter';
|
|
5
4
|
import EntityConfiguration from '../EntityConfiguration';
|
|
6
5
|
import { UUIDField } from '../EntityFields';
|
|
6
|
+
import IEntityCacheAdapter from '../IEntityCacheAdapter';
|
|
7
7
|
import { CacheLoadResult, CacheStatus } from '../internal/ReadThroughEntityCache';
|
|
8
8
|
|
|
9
9
|
type BlahFields = {
|
|
@@ -23,13 +23,11 @@ const entityConfiguration = new EntityConfiguration<BlahFields>({
|
|
|
23
23
|
export const DOES_NOT_EXIST_LOCAL_MEMORY_CACHE = Symbol('doesNotExist');
|
|
24
24
|
type LocalMemoryCacheValue<TFields> = Readonly<TFields> | typeof DOES_NOT_EXIST_LOCAL_MEMORY_CACHE;
|
|
25
25
|
|
|
26
|
-
class TestLocalCacheAdapter<TFields>
|
|
26
|
+
class TestLocalCacheAdapter<TFields> implements IEntityCacheAdapter<TFields> {
|
|
27
27
|
constructor(
|
|
28
|
-
entityConfiguration: EntityConfiguration<TFields>,
|
|
28
|
+
private readonly entityConfiguration: EntityConfiguration<TFields>,
|
|
29
29
|
private readonly cache: Map<string, LocalMemoryCacheValue<TFields>>
|
|
30
|
-
) {
|
|
31
|
-
super(entityConfiguration);
|
|
32
|
-
}
|
|
30
|
+
) {}
|
|
33
31
|
|
|
34
32
|
public async loadManyAsync<N extends keyof TFields>(
|
|
35
33
|
fieldName: N,
|
|
@@ -123,10 +121,7 @@ function makeTestCacheAdapters(): {
|
|
|
123
121
|
const fallbackCache = new Map();
|
|
124
122
|
const fallbackCacheAdapter = new TestLocalCacheAdapter(entityConfiguration, fallbackCache);
|
|
125
123
|
|
|
126
|
-
const cacheAdapter = new ComposedEntityCacheAdapter(
|
|
127
|
-
primaryCacheAdapter,
|
|
128
|
-
fallbackCacheAdapter,
|
|
129
|
-
]);
|
|
124
|
+
const cacheAdapter = new ComposedEntityCacheAdapter([primaryCacheAdapter, fallbackCacheAdapter]);
|
|
130
125
|
|
|
131
126
|
return {
|
|
132
127
|
primaryCache,
|
|
@@ -229,7 +224,7 @@ describe(ComposedEntityCacheAdapter, () => {
|
|
|
229
224
|
});
|
|
230
225
|
|
|
231
226
|
it('handles 0 cache adapter compose case', async () => {
|
|
232
|
-
const cacheAdapter = new ComposedEntityCacheAdapter(
|
|
227
|
+
const cacheAdapter = new ComposedEntityCacheAdapter<any>([]);
|
|
233
228
|
const results = await cacheAdapter.loadManyAsync('id', []);
|
|
234
229
|
expect(results).toEqual(new Map());
|
|
235
230
|
});
|
|
@@ -222,6 +222,46 @@ describe(EnforcingEntityLoader, () => {
|
|
|
222
222
|
});
|
|
223
223
|
});
|
|
224
224
|
|
|
225
|
+
describe('loadFirstByFieldEqualityConjunction', () => {
|
|
226
|
+
it('throws when result is unsuccessful', async () => {
|
|
227
|
+
const entityLoaderMock = mock<EntityLoader<any, any, any, any, any, any>>(EntityLoader);
|
|
228
|
+
const rejection = new Error();
|
|
229
|
+
when(
|
|
230
|
+
entityLoaderMock.loadFirstByFieldEqualityConjunctionAsync(anything(), anything())
|
|
231
|
+
).thenResolve(result(rejection));
|
|
232
|
+
const entityLoader = instance(entityLoaderMock);
|
|
233
|
+
const enforcingEntityLoader = new EnforcingEntityLoader(entityLoader);
|
|
234
|
+
await expect(
|
|
235
|
+
enforcingEntityLoader.loadFirstByFieldEqualityConjunctionAsync(anything(), anything())
|
|
236
|
+
).rejects.toThrow(rejection);
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
it('returns value when result is successful', async () => {
|
|
240
|
+
const entityLoaderMock = mock<EntityLoader<any, any, any, any, any, any>>(EntityLoader);
|
|
241
|
+
const resolved = {};
|
|
242
|
+
when(
|
|
243
|
+
entityLoaderMock.loadFirstByFieldEqualityConjunctionAsync(anything(), anything())
|
|
244
|
+
).thenResolve(result(resolved));
|
|
245
|
+
const entityLoader = instance(entityLoaderMock);
|
|
246
|
+
const enforcingEntityLoader = new EnforcingEntityLoader(entityLoader);
|
|
247
|
+
await expect(
|
|
248
|
+
enforcingEntityLoader.loadFirstByFieldEqualityConjunctionAsync(anything(), anything())
|
|
249
|
+
).resolves.toEqual(resolved);
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
it('returns null when the query is successful but no rows match', async () => {
|
|
253
|
+
const entityLoaderMock = mock<EntityLoader<any, any, any, any, any, any>>(EntityLoader);
|
|
254
|
+
when(
|
|
255
|
+
entityLoaderMock.loadFirstByFieldEqualityConjunctionAsync(anything(), anything())
|
|
256
|
+
).thenResolve(null);
|
|
257
|
+
const entityLoader = instance(entityLoaderMock);
|
|
258
|
+
const enforcingEntityLoader = new EnforcingEntityLoader(entityLoader);
|
|
259
|
+
await expect(
|
|
260
|
+
enforcingEntityLoader.loadFirstByFieldEqualityConjunctionAsync(anything(), anything())
|
|
261
|
+
).resolves.toBeNull();
|
|
262
|
+
});
|
|
263
|
+
});
|
|
264
|
+
|
|
225
265
|
describe('loadManyByFieldEqualityConjunction', () => {
|
|
226
266
|
it('throws when result is unsuccessful', async () => {
|
|
227
267
|
const entityLoaderMock = mock<EntityLoader<any, any, any, any, any, any>>(EntityLoader);
|
|
@@ -290,6 +330,7 @@ describe(EnforcingEntityLoader, () => {
|
|
|
290
330
|
'tryConstructEntities',
|
|
291
331
|
'validateFieldValues',
|
|
292
332
|
'constructAndAuthorizeEntitiesAsync',
|
|
333
|
+
'constructEntity',
|
|
293
334
|
];
|
|
294
335
|
expect(loaderProperties).toEqual(expect.arrayContaining(knownLoaderOnlyDifferences));
|
|
295
336
|
|
|
@@ -26,7 +26,12 @@ describe(Entity, () => {
|
|
|
26
26
|
const data = {
|
|
27
27
|
id: 'what',
|
|
28
28
|
};
|
|
29
|
-
const testEntity = new SimpleTestEntity(
|
|
29
|
+
const testEntity = new SimpleTestEntity({
|
|
30
|
+
viewerContext,
|
|
31
|
+
id: 'what',
|
|
32
|
+
databaseFields: data,
|
|
33
|
+
selectedFields: data,
|
|
34
|
+
});
|
|
30
35
|
expect(SimpleTestEntity.updater(testEntity)).toBeInstanceOf(UpdateMutator);
|
|
31
36
|
});
|
|
32
37
|
});
|
|
@@ -38,7 +43,12 @@ describe(Entity, () => {
|
|
|
38
43
|
const data = {
|
|
39
44
|
id: 'what',
|
|
40
45
|
};
|
|
41
|
-
const testEntity = new SimpleTestDenyDeleteEntity(
|
|
46
|
+
const testEntity = new SimpleTestDenyDeleteEntity({
|
|
47
|
+
viewerContext,
|
|
48
|
+
id: 'what',
|
|
49
|
+
databaseFields: data,
|
|
50
|
+
selectedFields: data,
|
|
51
|
+
});
|
|
42
52
|
const canViewerUpdate = await SimpleTestDenyDeleteEntity.canViewerUpdateAsync(testEntity);
|
|
43
53
|
expect(canViewerUpdate).toBe(true);
|
|
44
54
|
});
|
|
@@ -49,7 +59,12 @@ describe(Entity, () => {
|
|
|
49
59
|
const data = {
|
|
50
60
|
id: 'what',
|
|
51
61
|
};
|
|
52
|
-
const testEntity = new SimpleTestDenyUpdateEntity(
|
|
62
|
+
const testEntity = new SimpleTestDenyUpdateEntity({
|
|
63
|
+
viewerContext,
|
|
64
|
+
id: 'what',
|
|
65
|
+
databaseFields: data,
|
|
66
|
+
selectedFields: data,
|
|
67
|
+
});
|
|
53
68
|
const canViewerUpdate = await SimpleTestDenyUpdateEntity.canViewerUpdateAsync(testEntity);
|
|
54
69
|
expect(canViewerUpdate).toBe(false);
|
|
55
70
|
});
|
|
@@ -62,7 +77,12 @@ describe(Entity, () => {
|
|
|
62
77
|
const data = {
|
|
63
78
|
id: 'what',
|
|
64
79
|
};
|
|
65
|
-
const testEntity = new SimpleTestDenyUpdateEntity(
|
|
80
|
+
const testEntity = new SimpleTestDenyUpdateEntity({
|
|
81
|
+
viewerContext,
|
|
82
|
+
id: 'what',
|
|
83
|
+
databaseFields: data,
|
|
84
|
+
selectedFields: data,
|
|
85
|
+
});
|
|
66
86
|
const canViewerDelete = await SimpleTestDenyUpdateEntity.canViewerDeleteAsync(testEntity);
|
|
67
87
|
expect(canViewerDelete).toBe(true);
|
|
68
88
|
});
|
|
@@ -73,7 +93,12 @@ describe(Entity, () => {
|
|
|
73
93
|
const data = {
|
|
74
94
|
id: 'what',
|
|
75
95
|
};
|
|
76
|
-
const testEntity = new SimpleTestDenyDeleteEntity(
|
|
96
|
+
const testEntity = new SimpleTestDenyDeleteEntity({
|
|
97
|
+
viewerContext,
|
|
98
|
+
id: 'what',
|
|
99
|
+
databaseFields: data,
|
|
100
|
+
selectedFields: data,
|
|
101
|
+
});
|
|
77
102
|
const canViewerDelete = await SimpleTestDenyDeleteEntity.canViewerDeleteAsync(testEntity);
|
|
78
103
|
expect(canViewerDelete).toBe(false);
|
|
79
104
|
});
|
|
@@ -177,37 +202,33 @@ class SimpleTestDenyDeleteEntityPrivacyPolicy extends EntityPrivacyPolicy<
|
|
|
177
202
|
}
|
|
178
203
|
|
|
179
204
|
class SimpleTestDenyUpdateEntity extends Entity<TestEntityFields, string, ViewerContext> {
|
|
180
|
-
static
|
|
205
|
+
static defineCompanionDefinition(): EntityCompanionDefinition<
|
|
181
206
|
TestEntityFields,
|
|
182
207
|
string,
|
|
183
208
|
ViewerContext,
|
|
184
209
|
SimpleTestDenyUpdateEntity,
|
|
185
210
|
SimpleTestDenyUpdateEntityPrivacyPolicy
|
|
186
211
|
> {
|
|
187
|
-
return
|
|
212
|
+
return {
|
|
213
|
+
entityClass: SimpleTestDenyUpdateEntity,
|
|
214
|
+
entityConfiguration: testEntityConfiguration,
|
|
215
|
+
privacyPolicyClass: SimpleTestDenyUpdateEntityPrivacyPolicy,
|
|
216
|
+
};
|
|
188
217
|
}
|
|
189
218
|
}
|
|
190
219
|
|
|
191
|
-
const simpleTestDenyUpdateEntityCompanion = new EntityCompanionDefinition({
|
|
192
|
-
entityClass: SimpleTestDenyUpdateEntity,
|
|
193
|
-
entityConfiguration: testEntityConfiguration,
|
|
194
|
-
privacyPolicyClass: SimpleTestDenyUpdateEntityPrivacyPolicy,
|
|
195
|
-
});
|
|
196
|
-
|
|
197
220
|
class SimpleTestDenyDeleteEntity extends Entity<TestEntityFields, string, ViewerContext> {
|
|
198
|
-
static
|
|
221
|
+
static defineCompanionDefinition(): EntityCompanionDefinition<
|
|
199
222
|
TestEntityFields,
|
|
200
223
|
string,
|
|
201
224
|
ViewerContext,
|
|
202
225
|
SimpleTestDenyDeleteEntity,
|
|
203
226
|
SimpleTestDenyDeleteEntityPrivacyPolicy
|
|
204
227
|
> {
|
|
205
|
-
return
|
|
228
|
+
return {
|
|
229
|
+
entityClass: SimpleTestDenyDeleteEntity,
|
|
230
|
+
entityConfiguration: testEntityConfiguration,
|
|
231
|
+
privacyPolicyClass: SimpleTestDenyDeleteEntityPrivacyPolicy,
|
|
232
|
+
};
|
|
206
233
|
}
|
|
207
234
|
}
|
|
208
|
-
|
|
209
|
-
const simpleTestDenyDeleteEntityCompanion = new EntityCompanionDefinition({
|
|
210
|
-
entityClass: SimpleTestDenyDeleteEntity,
|
|
211
|
-
entityConfiguration: testEntityConfiguration,
|
|
212
|
-
privacyPolicyClass: SimpleTestDenyDeleteEntityPrivacyPolicy,
|
|
213
|
-
});
|
|
@@ -31,14 +31,32 @@ type BlahFields = {
|
|
|
31
31
|
};
|
|
32
32
|
|
|
33
33
|
class BlahEntity extends Entity<BlahFields, string, TestUserViewerContext> {
|
|
34
|
-
static
|
|
34
|
+
static defineCompanionDefinition(): EntityCompanionDefinition<
|
|
35
35
|
BlahFields,
|
|
36
36
|
string,
|
|
37
37
|
TestUserViewerContext,
|
|
38
38
|
BlahEntity,
|
|
39
39
|
BlahEntityPrivacyPolicy
|
|
40
40
|
> {
|
|
41
|
-
return
|
|
41
|
+
return {
|
|
42
|
+
entityClass: BlahEntity,
|
|
43
|
+
entityConfiguration: new EntityConfiguration<BlahFields>({
|
|
44
|
+
idField: 'id',
|
|
45
|
+
tableName: 'blah_table',
|
|
46
|
+
schema: {
|
|
47
|
+
id: new UUIDField({
|
|
48
|
+
columnName: 'id',
|
|
49
|
+
cache: true,
|
|
50
|
+
}),
|
|
51
|
+
ownerID: new UUIDField({
|
|
52
|
+
columnName: 'owner_id',
|
|
53
|
+
}),
|
|
54
|
+
},
|
|
55
|
+
databaseAdapterFlavor: 'postgres',
|
|
56
|
+
cacheAdapterFlavor: 'redis',
|
|
57
|
+
}),
|
|
58
|
+
privacyPolicyClass: BlahEntityPrivacyPolicy,
|
|
59
|
+
};
|
|
42
60
|
}
|
|
43
61
|
}
|
|
44
62
|
|
|
@@ -84,26 +102,6 @@ class BlahEntityPrivacyPolicy extends EntityPrivacyPolicy<
|
|
|
84
102
|
];
|
|
85
103
|
}
|
|
86
104
|
|
|
87
|
-
const blahCompanion = new EntityCompanionDefinition({
|
|
88
|
-
entityClass: BlahEntity,
|
|
89
|
-
entityConfiguration: new EntityConfiguration<BlahFields>({
|
|
90
|
-
idField: 'id',
|
|
91
|
-
tableName: 'blah_table',
|
|
92
|
-
schema: {
|
|
93
|
-
id: new UUIDField({
|
|
94
|
-
columnName: 'id',
|
|
95
|
-
cache: true,
|
|
96
|
-
}),
|
|
97
|
-
ownerID: new UUIDField({
|
|
98
|
-
columnName: 'owner_id',
|
|
99
|
-
}),
|
|
100
|
-
},
|
|
101
|
-
databaseAdapterFlavor: 'postgres',
|
|
102
|
-
cacheAdapterFlavor: 'redis',
|
|
103
|
-
}),
|
|
104
|
-
privacyPolicyClass: BlahEntityPrivacyPolicy,
|
|
105
|
-
});
|
|
106
|
-
|
|
107
105
|
it('runs through a common workflow', async () => {
|
|
108
106
|
// will be one entity companion provider for each request, so
|
|
109
107
|
// share amongst all VCs created in that request
|
|
@@ -1,27 +1,24 @@
|
|
|
1
1
|
import { instance, mock, when } from 'ts-mockito';
|
|
2
2
|
|
|
3
3
|
import EntityCompanion from '../EntityCompanion';
|
|
4
|
+
import EntityCompanionProvider from '../EntityCompanionProvider';
|
|
4
5
|
import EntityLoaderFactory from '../EntityLoaderFactory';
|
|
5
6
|
import EntityMutatorFactory from '../EntityMutatorFactory';
|
|
6
7
|
import EntityTableDataCoordinator from '../internal/EntityTableDataCoordinator';
|
|
7
8
|
import IEntityMetricsAdapter from '../metrics/IEntityMetricsAdapter';
|
|
8
|
-
import TestEntity, {
|
|
9
|
-
TestEntityPrivacyPolicy,
|
|
10
|
-
testEntityConfiguration,
|
|
11
|
-
TestFields,
|
|
12
|
-
} from '../testfixtures/TestEntity';
|
|
9
|
+
import TestEntity, { testEntityConfiguration, TestFields } from '../testfixtures/TestEntity';
|
|
13
10
|
|
|
14
11
|
describe(EntityCompanion, () => {
|
|
15
12
|
it('correctly instantiates mutator and loader factories', () => {
|
|
13
|
+
const entityCompanionProvider = instance(mock<EntityCompanionProvider>());
|
|
14
|
+
|
|
16
15
|
const tableDataCoordinatorMock = mock<EntityTableDataCoordinator<TestFields>>();
|
|
17
16
|
when(tableDataCoordinatorMock.entityConfiguration).thenReturn(testEntityConfiguration);
|
|
18
17
|
|
|
19
18
|
const companion = new EntityCompanion(
|
|
20
|
-
|
|
19
|
+
entityCompanionProvider,
|
|
20
|
+
TestEntity.defineCompanionDefinition(),
|
|
21
21
|
instance(tableDataCoordinatorMock),
|
|
22
|
-
TestEntityPrivacyPolicy,
|
|
23
|
-
[],
|
|
24
|
-
{},
|
|
25
22
|
instance(mock<IEntityMetricsAdapter>())
|
|
26
23
|
);
|
|
27
24
|
expect(companion.getLoaderFactory()).toBeInstanceOf(EntityLoaderFactory);
|