@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
|
@@ -15,7 +15,12 @@ describe(ReadonlyEntity, () => {
|
|
|
15
15
|
const data = {
|
|
16
16
|
id: 'what',
|
|
17
17
|
};
|
|
18
|
-
const testEntity = new SimpleTestEntity(
|
|
18
|
+
const testEntity = new SimpleTestEntity({
|
|
19
|
+
viewerContext,
|
|
20
|
+
id: 'what',
|
|
21
|
+
databaseFields: data,
|
|
22
|
+
selectedFields: data,
|
|
23
|
+
});
|
|
19
24
|
expect(testEntity.getID()).toEqual('what');
|
|
20
25
|
});
|
|
21
26
|
});
|
|
@@ -26,7 +31,12 @@ describe(ReadonlyEntity, () => {
|
|
|
26
31
|
const data = {
|
|
27
32
|
id: 'what',
|
|
28
33
|
};
|
|
29
|
-
const testEntity = new SimpleTestEntity(
|
|
34
|
+
const testEntity = new SimpleTestEntity({
|
|
35
|
+
viewerContext,
|
|
36
|
+
id: 'what',
|
|
37
|
+
databaseFields: data,
|
|
38
|
+
selectedFields: data,
|
|
39
|
+
});
|
|
30
40
|
expect(testEntity.toString()).toEqual('SimpleTestEntity[what]');
|
|
31
41
|
});
|
|
32
42
|
});
|
|
@@ -34,11 +44,25 @@ describe(ReadonlyEntity, () => {
|
|
|
34
44
|
describe('getUniqueIdentifier', () => {
|
|
35
45
|
it('returns a different value for two different entities of the same type', () => {
|
|
36
46
|
const viewerContext = instance(mock(ViewerContext));
|
|
37
|
-
const testEntity = new SimpleTestEntity(
|
|
47
|
+
const testEntity = new SimpleTestEntity({
|
|
48
|
+
viewerContext,
|
|
38
49
|
id: '1',
|
|
50
|
+
databaseFields: {
|
|
51
|
+
id: '1',
|
|
52
|
+
},
|
|
53
|
+
selectedFields: {
|
|
54
|
+
id: '1',
|
|
55
|
+
},
|
|
39
56
|
});
|
|
40
|
-
const testEntity2 = new SimpleTestEntity(
|
|
57
|
+
const testEntity2 = new SimpleTestEntity({
|
|
58
|
+
viewerContext,
|
|
41
59
|
id: '2',
|
|
60
|
+
databaseFields: {
|
|
61
|
+
id: '2',
|
|
62
|
+
},
|
|
63
|
+
selectedFields: {
|
|
64
|
+
id: '2',
|
|
65
|
+
},
|
|
42
66
|
});
|
|
43
67
|
expect(testEntity.getUniqueIdentifier()).not.toEqual(testEntity2.getUniqueIdentifier());
|
|
44
68
|
});
|
|
@@ -47,22 +71,43 @@ describe(ReadonlyEntity, () => {
|
|
|
47
71
|
const viewerContext = instance(mock(ViewerContext));
|
|
48
72
|
const viewerContext2 = instance(mock(ViewerContext));
|
|
49
73
|
const data = { id: '1' };
|
|
50
|
-
const testEntity = new SimpleTestEntity(
|
|
51
|
-
|
|
74
|
+
const testEntity = new SimpleTestEntity({
|
|
75
|
+
viewerContext,
|
|
76
|
+
id: '1',
|
|
77
|
+
databaseFields: data,
|
|
78
|
+
selectedFields: data,
|
|
79
|
+
});
|
|
80
|
+
const testEntity2 = new SimpleTestEntity({
|
|
81
|
+
viewerContext: viewerContext2,
|
|
82
|
+
id: '1',
|
|
83
|
+
databaseFields: data,
|
|
84
|
+
selectedFields: data,
|
|
85
|
+
});
|
|
52
86
|
expect(testEntity.getUniqueIdentifier()).toEqual(testEntity2.getUniqueIdentifier());
|
|
53
87
|
});
|
|
54
88
|
|
|
55
89
|
it('returns a different value for different entities even if same ID', () => {
|
|
56
90
|
const viewerContext = instance(mock(ViewerContext));
|
|
57
91
|
const data = { id: '1' };
|
|
58
|
-
const testEntity = new SimpleTestEntity(
|
|
59
|
-
|
|
92
|
+
const testEntity = new SimpleTestEntity({
|
|
93
|
+
viewerContext,
|
|
94
|
+
id: 'what',
|
|
95
|
+
databaseFields: data,
|
|
96
|
+
selectedFields: data,
|
|
97
|
+
});
|
|
98
|
+
const data2 = {
|
|
60
99
|
customIdField: '1',
|
|
61
100
|
testIndexedField: '2',
|
|
62
101
|
stringField: '3',
|
|
63
102
|
intField: 4,
|
|
64
103
|
dateField: new Date(),
|
|
65
104
|
nullableField: null,
|
|
105
|
+
};
|
|
106
|
+
const testEntity2 = new TestEntity({
|
|
107
|
+
viewerContext,
|
|
108
|
+
id: '1',
|
|
109
|
+
databaseFields: data2,
|
|
110
|
+
selectedFields: data2,
|
|
66
111
|
});
|
|
67
112
|
expect(testEntity.getUniqueIdentifier()).not.toEqual(testEntity2.getUniqueIdentifier());
|
|
68
113
|
});
|
|
@@ -72,16 +117,27 @@ describe(ReadonlyEntity, () => {
|
|
|
72
117
|
const viewerContext = instance(mock(ViewerContext));
|
|
73
118
|
const dataWithoutID = {};
|
|
74
119
|
expect(() => {
|
|
75
|
-
|
|
120
|
+
// eslint-disable-next-line no-new
|
|
121
|
+
new SimpleTestEntity({
|
|
122
|
+
viewerContext,
|
|
123
|
+
id: undefined as any,
|
|
124
|
+
databaseFields: dataWithoutID as any,
|
|
125
|
+
selectedFields: dataWithoutID as any,
|
|
126
|
+
});
|
|
76
127
|
}).toThrow();
|
|
77
128
|
});
|
|
78
129
|
|
|
79
|
-
it('returns correct
|
|
130
|
+
it('returns correct viewerCo}ntext from instantiation', () => {
|
|
80
131
|
const viewerContext = instance(mock(ViewerContext));
|
|
81
132
|
const data = {
|
|
82
133
|
id: 'what',
|
|
83
134
|
};
|
|
84
|
-
const testEntity = new SimpleTestEntity(
|
|
135
|
+
const testEntity = new SimpleTestEntity({
|
|
136
|
+
viewerContext,
|
|
137
|
+
id: 'what',
|
|
138
|
+
databaseFields: data,
|
|
139
|
+
selectedFields: data,
|
|
140
|
+
});
|
|
85
141
|
expect(testEntity.getViewerContext()).toBe(viewerContext);
|
|
86
142
|
});
|
|
87
143
|
|
|
@@ -90,7 +146,12 @@ describe(ReadonlyEntity, () => {
|
|
|
90
146
|
const data = {
|
|
91
147
|
id: 'what',
|
|
92
148
|
};
|
|
93
|
-
const testEntity = new SimpleTestEntity(
|
|
149
|
+
const testEntity = new SimpleTestEntity({
|
|
150
|
+
viewerContext,
|
|
151
|
+
id: 'what',
|
|
152
|
+
databaseFields: data,
|
|
153
|
+
selectedFields: data,
|
|
154
|
+
});
|
|
94
155
|
expect(testEntity.getField('id')).toEqual('what');
|
|
95
156
|
expect(testEntity.getAllFields()).toEqual(data);
|
|
96
157
|
});
|
|
@@ -102,7 +163,12 @@ describe(ReadonlyEntity, () => {
|
|
|
102
163
|
const data = {
|
|
103
164
|
id: 'what',
|
|
104
165
|
};
|
|
105
|
-
const testEntity = new SimpleTestEntity(
|
|
166
|
+
const testEntity = new SimpleTestEntity({
|
|
167
|
+
viewerContext,
|
|
168
|
+
id: 'what',
|
|
169
|
+
databaseFields: data,
|
|
170
|
+
selectedFields: data,
|
|
171
|
+
});
|
|
106
172
|
expect(testEntity.associationLoader()).toBeInstanceOf(EntityAssociationLoader);
|
|
107
173
|
});
|
|
108
174
|
});
|
|
@@ -4,7 +4,7 @@ import EntityCompanionProvider from '../EntityCompanionProvider';
|
|
|
4
4
|
import ViewerContext from '../ViewerContext';
|
|
5
5
|
import ViewerScopedEntityCompanion from '../ViewerScopedEntityCompanion';
|
|
6
6
|
import ViewerScopedEntityCompanionProvider from '../ViewerScopedEntityCompanionProvider';
|
|
7
|
-
import TestEntity
|
|
7
|
+
import TestEntity from '../testfixtures/TestEntity';
|
|
8
8
|
|
|
9
9
|
describe(ViewerScopedEntityCompanionProvider, () => {
|
|
10
10
|
it('returns viewer scoped entity companion', () => {
|
|
@@ -15,10 +15,7 @@ describe(ViewerScopedEntityCompanionProvider, () => {
|
|
|
15
15
|
vc
|
|
16
16
|
);
|
|
17
17
|
expect(
|
|
18
|
-
viewerScopedEntityCompanionProvider.getViewerScopedCompanionForEntity(
|
|
19
|
-
TestEntity,
|
|
20
|
-
testEntityCompanion
|
|
21
|
-
)
|
|
18
|
+
viewerScopedEntityCompanionProvider.getViewerScopedCompanionForEntity(TestEntity)
|
|
22
19
|
).toBeInstanceOf(ViewerScopedEntityCompanion);
|
|
23
20
|
});
|
|
24
21
|
});
|
|
@@ -122,14 +122,19 @@ class TestEntityPrivacyPolicy extends EntityPrivacyPolicy<any, string, ViewerCon
|
|
|
122
122
|
}
|
|
123
123
|
|
|
124
124
|
class OneTestEntity extends Entity<TestFields, string, ViewerContext, OneTestFields> {
|
|
125
|
-
constructor(
|
|
126
|
-
|
|
125
|
+
constructor(constructorParams: {
|
|
126
|
+
viewerContext: ViewerContext;
|
|
127
|
+
id: string;
|
|
128
|
+
databaseFields: Readonly<TestFields>;
|
|
129
|
+
selectedFields: Readonly<Pick<TestFields, OneTestFields>>;
|
|
130
|
+
}) {
|
|
131
|
+
if (constructorParams.selectedFields.entity_type !== EntityType.ONE) {
|
|
127
132
|
throw new Error('OneTestEntity must be instantiated with one data');
|
|
128
133
|
}
|
|
129
|
-
super(
|
|
134
|
+
super(constructorParams);
|
|
130
135
|
}
|
|
131
136
|
|
|
132
|
-
static
|
|
137
|
+
static defineCompanionDefinition(): EntityCompanionDefinition<
|
|
133
138
|
TestFields,
|
|
134
139
|
string,
|
|
135
140
|
ViewerContext,
|
|
@@ -137,19 +142,29 @@ class OneTestEntity extends Entity<TestFields, string, ViewerContext, OneTestFie
|
|
|
137
142
|
TestEntityPrivacyPolicy,
|
|
138
143
|
OneTestFields
|
|
139
144
|
> {
|
|
140
|
-
return
|
|
145
|
+
return {
|
|
146
|
+
entityClass: OneTestEntity,
|
|
147
|
+
entityConfiguration: testEntityConfiguration,
|
|
148
|
+
privacyPolicyClass: TestEntityPrivacyPolicy,
|
|
149
|
+
entitySelectedFields: ['id', 'entity_type', 'common_other_field'],
|
|
150
|
+
};
|
|
141
151
|
}
|
|
142
152
|
}
|
|
143
153
|
|
|
144
154
|
class TwoTestEntity extends Entity<TestFields, string, ViewerContext, TwoTestFields> {
|
|
145
|
-
constructor(
|
|
146
|
-
|
|
155
|
+
constructor(constructorParams: {
|
|
156
|
+
viewerContext: ViewerContext;
|
|
157
|
+
id: string;
|
|
158
|
+
databaseFields: Readonly<TestFields>;
|
|
159
|
+
selectedFields: Readonly<Pick<TestFields, TwoTestFields>>;
|
|
160
|
+
}) {
|
|
161
|
+
if (constructorParams.selectedFields.entity_type !== EntityType.TWO) {
|
|
147
162
|
throw new Error('TwoTestEntity must be instantiated with two data');
|
|
148
163
|
}
|
|
149
|
-
super(
|
|
164
|
+
super(constructorParams);
|
|
150
165
|
}
|
|
151
166
|
|
|
152
|
-
static
|
|
167
|
+
static defineCompanionDefinition(): EntityCompanionDefinition<
|
|
153
168
|
TestFields,
|
|
154
169
|
string,
|
|
155
170
|
ViewerContext,
|
|
@@ -157,20 +172,11 @@ class TwoTestEntity extends Entity<TestFields, string, ViewerContext, TwoTestFie
|
|
|
157
172
|
TestEntityPrivacyPolicy,
|
|
158
173
|
TwoTestFields
|
|
159
174
|
> {
|
|
160
|
-
return
|
|
175
|
+
return {
|
|
176
|
+
entityClass: TwoTestEntity,
|
|
177
|
+
entityConfiguration: testEntityConfiguration,
|
|
178
|
+
privacyPolicyClass: TestEntityPrivacyPolicy,
|
|
179
|
+
entitySelectedFields: ['id', 'other_field', 'common_other_field', 'entity_type'],
|
|
180
|
+
};
|
|
161
181
|
}
|
|
162
182
|
}
|
|
163
|
-
|
|
164
|
-
const oneTestEntityCompanion = new EntityCompanionDefinition({
|
|
165
|
-
entityClass: OneTestEntity,
|
|
166
|
-
entityConfiguration: testEntityConfiguration,
|
|
167
|
-
privacyPolicyClass: TestEntityPrivacyPolicy,
|
|
168
|
-
entitySelectedFields: ['id', 'entity_type', 'common_other_field'],
|
|
169
|
-
});
|
|
170
|
-
|
|
171
|
-
const twoTestEntityCompanion = new EntityCompanionDefinition({
|
|
172
|
-
entityClass: TwoTestEntity,
|
|
173
|
-
entityConfiguration: testEntityConfiguration,
|
|
174
|
-
privacyPolicyClass: TestEntityPrivacyPolicy,
|
|
175
|
-
entitySelectedFields: ['id', 'other_field', 'common_other_field', 'entity_type'],
|
|
176
|
-
});
|
|
@@ -130,7 +130,7 @@ class TestEntityPrivacyPolicy extends EntityPrivacyPolicy<any, string, ViewerCon
|
|
|
130
130
|
}
|
|
131
131
|
|
|
132
132
|
class OneTestEntity extends Entity<TestFields, string, ViewerContext, OneTestFields> {
|
|
133
|
-
static
|
|
133
|
+
static defineCompanionDefinition(): EntityCompanionDefinition<
|
|
134
134
|
TestFields,
|
|
135
135
|
string,
|
|
136
136
|
ViewerContext,
|
|
@@ -138,12 +138,17 @@ class OneTestEntity extends Entity<TestFields, string, ViewerContext, OneTestFie
|
|
|
138
138
|
TestEntityPrivacyPolicy,
|
|
139
139
|
OneTestFields
|
|
140
140
|
> {
|
|
141
|
-
return
|
|
141
|
+
return {
|
|
142
|
+
entityClass: OneTestEntity,
|
|
143
|
+
entityConfiguration: testEntityConfiguration,
|
|
144
|
+
privacyPolicyClass: TestEntityPrivacyPolicy,
|
|
145
|
+
entitySelectedFields: ['id', 'fake_field'],
|
|
146
|
+
};
|
|
142
147
|
}
|
|
143
148
|
}
|
|
144
149
|
|
|
145
150
|
class TwoTestEntity extends Entity<TestFields, string, ViewerContext, TwoTestFields> {
|
|
146
|
-
static
|
|
151
|
+
static defineCompanionDefinition(): EntityCompanionDefinition<
|
|
147
152
|
TestFields,
|
|
148
153
|
string,
|
|
149
154
|
ViewerContext,
|
|
@@ -151,20 +156,11 @@ class TwoTestEntity extends Entity<TestFields, string, ViewerContext, TwoTestFie
|
|
|
151
156
|
TestEntityPrivacyPolicy,
|
|
152
157
|
TwoTestFields
|
|
153
158
|
> {
|
|
154
|
-
return
|
|
159
|
+
return {
|
|
160
|
+
entityClass: TwoTestEntity,
|
|
161
|
+
entityConfiguration: testEntityConfiguration,
|
|
162
|
+
privacyPolicyClass: TestEntityPrivacyPolicy,
|
|
163
|
+
entitySelectedFields: ['id', 'other_field', 'fake_field'],
|
|
164
|
+
};
|
|
155
165
|
}
|
|
156
166
|
}
|
|
157
|
-
|
|
158
|
-
const oneTestEntityCompanion = new EntityCompanionDefinition({
|
|
159
|
-
entityClass: OneTestEntity,
|
|
160
|
-
entityConfiguration: testEntityConfiguration,
|
|
161
|
-
privacyPolicyClass: TestEntityPrivacyPolicy,
|
|
162
|
-
entitySelectedFields: ['id', 'fake_field'],
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
const twoTestEntityCompanion = new EntityCompanionDefinition({
|
|
166
|
-
entityClass: TwoTestEntity,
|
|
167
|
-
entityConfiguration: testEntityConfiguration,
|
|
168
|
-
privacyPolicyClass: TestEntityPrivacyPolicy,
|
|
169
|
-
entitySelectedFields: ['id', 'other_field', 'fake_field'],
|
|
170
|
-
});
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
+
import EntityError, { EntityErrorCode, EntityErrorState } from './EntityError';
|
|
1
2
|
import { IEntityClass } from '../Entity';
|
|
2
3
|
import EntityPrivacyPolicy from '../EntityPrivacyPolicy';
|
|
3
4
|
import ReadonlyEntity from '../ReadonlyEntity';
|
|
4
5
|
import ViewerContext from '../ViewerContext';
|
|
5
|
-
import EntityError, { EntityErrorCode, EntityErrorState } from './EntityError';
|
|
6
6
|
|
|
7
7
|
export default class EntityInvalidFieldValueError<
|
|
8
|
-
TFields,
|
|
8
|
+
TFields extends object,
|
|
9
9
|
TID extends NonNullable<TFields[TSelectedFields]>,
|
|
10
10
|
TViewerContext extends ViewerContext,
|
|
11
11
|
TEntity extends ReadonlyEntity<TFields, TID, TViewerContext, TSelectedFields>,
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
+
import EntityError, { EntityErrorCode, EntityErrorState } from './EntityError';
|
|
1
2
|
import { EntityAuthorizationAction } from '../EntityPrivacyPolicy';
|
|
2
3
|
import ReadonlyEntity from '../ReadonlyEntity';
|
|
3
4
|
import ViewerContext from '../ViewerContext';
|
|
4
|
-
import EntityError, { EntityErrorCode, EntityErrorState } from './EntityError';
|
|
5
5
|
|
|
6
6
|
export default class EntityNotAuthorizedError<
|
|
7
|
-
TFields,
|
|
7
|
+
TFields extends object,
|
|
8
8
|
TID extends NonNullable<TFields[TSelectedFields]>,
|
|
9
9
|
TViewerContext extends ViewerContext,
|
|
10
10
|
TEntity extends ReadonlyEntity<TFields, TID, TViewerContext, TSelectedFields>,
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
+
import EntityError, { EntityErrorCode, EntityErrorState } from './EntityError';
|
|
1
2
|
import { IEntityClass } from '../Entity';
|
|
2
3
|
import EntityPrivacyPolicy from '../EntityPrivacyPolicy';
|
|
3
4
|
import ReadonlyEntity from '../ReadonlyEntity';
|
|
4
5
|
import ViewerContext from '../ViewerContext';
|
|
5
|
-
import EntityError, { EntityErrorCode, EntityErrorState } from './EntityError';
|
|
6
6
|
|
|
7
7
|
export default class EntityNotFoundError<
|
|
8
|
-
TFields,
|
|
8
|
+
TFields extends object,
|
|
9
9
|
TID extends NonNullable<TFields[TSelectedFields]>,
|
|
10
10
|
TViewerContext extends ViewerContext,
|
|
11
11
|
TEntity extends ReadonlyEntity<TFields, TID, TViewerContext, TSelectedFields>,
|
package/src/index.ts
CHANGED
|
@@ -12,7 +12,8 @@ export { default as Entity } from './Entity';
|
|
|
12
12
|
export * from './Entity';
|
|
13
13
|
export { default as EntityAssociationLoader } from './EntityAssociationLoader';
|
|
14
14
|
export * from './EntityAssociationLoader';
|
|
15
|
-
export { default as
|
|
15
|
+
export { default as IEntityCacheAdapter } from './IEntityCacheAdapter';
|
|
16
|
+
export { default as GenericEntityCacheAdapter } from './GenericEntityCacheAdapter';
|
|
16
17
|
export { default as EntityCompanion } from './EntityCompanion';
|
|
17
18
|
export * from './EntityCompanion';
|
|
18
19
|
export { default as EntityCompanionProvider } from './EntityCompanionProvider';
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import DataLoader from 'dataloader';
|
|
2
2
|
|
|
3
|
+
import ReadThroughEntityCache from './ReadThroughEntityCache';
|
|
3
4
|
import EntityDatabaseAdapter, {
|
|
4
5
|
FieldEqualityCondition,
|
|
5
6
|
QuerySelectionModifiers,
|
|
@@ -17,7 +18,6 @@ import IEntityMetricsAdapter, {
|
|
|
17
18
|
IncrementLoadCountEventType,
|
|
18
19
|
} from '../metrics/IEntityMetricsAdapter';
|
|
19
20
|
import { computeIfAbsent, zipToMap } from '../utils/collections/maps';
|
|
20
|
-
import ReadThroughEntityCache from './ReadThroughEntityCache';
|
|
21
21
|
|
|
22
22
|
/**
|
|
23
23
|
* A data manager is responsible for orchestrating multiple sources of entity
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import
|
|
1
|
+
import EntityDataManager from './EntityDataManager';
|
|
2
|
+
import ReadThroughEntityCache from './ReadThroughEntityCache';
|
|
2
3
|
import EntityConfiguration from '../EntityConfiguration';
|
|
3
4
|
import EntityDatabaseAdapter from '../EntityDatabaseAdapter';
|
|
4
5
|
import EntityQueryContextProvider from '../EntityQueryContextProvider';
|
|
6
|
+
import IEntityCacheAdapter from '../IEntityCacheAdapter';
|
|
5
7
|
import IEntityCacheAdapterProvider from '../IEntityCacheAdapterProvider';
|
|
6
8
|
import IEntityDatabaseAdapterProvider from '../IEntityDatabaseAdapterProvider';
|
|
7
9
|
import IEntityMetricsAdapter from '../metrics/IEntityMetricsAdapter';
|
|
8
|
-
import EntityDataManager from './EntityDataManager';
|
|
9
|
-
import ReadThroughEntityCache from './ReadThroughEntityCache';
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* Responsible for orchestrating fetching and caching of entity data from a
|
|
@@ -15,7 +15,7 @@ import ReadThroughEntityCache from './ReadThroughEntityCache';
|
|
|
15
15
|
*/
|
|
16
16
|
export default class EntityTableDataCoordinator<TFields> {
|
|
17
17
|
readonly databaseAdapter: EntityDatabaseAdapter<TFields>;
|
|
18
|
-
readonly cacheAdapter:
|
|
18
|
+
readonly cacheAdapter: IEntityCacheAdapter<TFields>;
|
|
19
19
|
readonly dataManager: EntityDataManager<TFields>;
|
|
20
20
|
|
|
21
21
|
constructor(
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import invariant from 'invariant';
|
|
2
2
|
|
|
3
|
-
import EntityCacheAdapter from '../EntityCacheAdapter';
|
|
4
3
|
import EntityConfiguration from '../EntityConfiguration';
|
|
4
|
+
import IEntityCacheAdapter from '../IEntityCacheAdapter';
|
|
5
5
|
import { filterMap } from '../utils/collections/maps';
|
|
6
6
|
|
|
7
7
|
export enum CacheStatus {
|
|
@@ -29,7 +29,7 @@ export type CacheLoadResult<TFields> =
|
|
|
29
29
|
export default class ReadThroughEntityCache<TFields> {
|
|
30
30
|
constructor(
|
|
31
31
|
private readonly entityConfiguration: EntityConfiguration<TFields>,
|
|
32
|
-
private readonly entityCacheAdapter:
|
|
32
|
+
private readonly entityCacheAdapter: IEntityCacheAdapter<TFields>
|
|
33
33
|
) {}
|
|
34
34
|
|
|
35
35
|
private isFieldCacheable<N extends keyof TFields>(fieldName: N): boolean {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { verify, deepEqual, mock, instance, when, anything } from 'ts-mockito';
|
|
2
2
|
|
|
3
|
-
import EntityCacheAdapter from '../../EntityCacheAdapter';
|
|
4
3
|
import EntityConfiguration from '../../EntityConfiguration';
|
|
5
4
|
import { UUIDField } from '../../EntityFields';
|
|
5
|
+
import IEntityCacheAdapter from '../../IEntityCacheAdapter';
|
|
6
6
|
import ReadThroughEntityCache, { CacheStatus } from '../ReadThroughEntityCache';
|
|
7
7
|
|
|
8
8
|
type BlahFields = {
|
|
@@ -39,7 +39,7 @@ const createIdFetcher =
|
|
|
39
39
|
describe(ReadThroughEntityCache, () => {
|
|
40
40
|
describe('readManyThroughAsync', () => {
|
|
41
41
|
it('fetches from DB upon cache miss and caches the result', async () => {
|
|
42
|
-
const cacheAdapterMock = mock<
|
|
42
|
+
const cacheAdapterMock = mock<IEntityCacheAdapter<BlahFields>>();
|
|
43
43
|
const cacheAdapter = instance(cacheAdapterMock);
|
|
44
44
|
const entityCache = new ReadThroughEntityCache(makeEntityConfiguration(true), cacheAdapter);
|
|
45
45
|
const fetcher = createIdFetcher(['wat', 'who']);
|
|
@@ -75,7 +75,7 @@ describe(ReadThroughEntityCache, () => {
|
|
|
75
75
|
});
|
|
76
76
|
|
|
77
77
|
it('does not fetch from the DB or cache results when all cache fetches are hits', async () => {
|
|
78
|
-
const cacheAdapterMock = mock<
|
|
78
|
+
const cacheAdapterMock = mock<IEntityCacheAdapter<BlahFields>>();
|
|
79
79
|
const cacheAdapter = instance(cacheAdapterMock);
|
|
80
80
|
const entityCache = new ReadThroughEntityCache(makeEntityConfiguration(true), cacheAdapter);
|
|
81
81
|
const fetcher = createIdFetcher(['wat', 'who']);
|
|
@@ -111,7 +111,7 @@ describe(ReadThroughEntityCache, () => {
|
|
|
111
111
|
});
|
|
112
112
|
|
|
113
113
|
it('negatively caches db misses', async () => {
|
|
114
|
-
const cacheAdapterMock = mock<
|
|
114
|
+
const cacheAdapterMock = mock<IEntityCacheAdapter<BlahFields>>();
|
|
115
115
|
const cacheAdapter = instance(cacheAdapterMock);
|
|
116
116
|
const entityCache = new ReadThroughEntityCache(makeEntityConfiguration(true), cacheAdapter);
|
|
117
117
|
|
|
@@ -131,7 +131,7 @@ describe(ReadThroughEntityCache, () => {
|
|
|
131
131
|
});
|
|
132
132
|
|
|
133
133
|
it('does not return or fetch negatively cached results from DB', async () => {
|
|
134
|
-
const cacheAdapterMock = mock<
|
|
134
|
+
const cacheAdapterMock = mock<IEntityCacheAdapter<BlahFields>>();
|
|
135
135
|
const cacheAdapter = instance(cacheAdapterMock);
|
|
136
136
|
const entityCache = new ReadThroughEntityCache(makeEntityConfiguration(true), cacheAdapter);
|
|
137
137
|
const fetcher = createIdFetcher([]);
|
|
@@ -148,7 +148,7 @@ describe(ReadThroughEntityCache, () => {
|
|
|
148
148
|
});
|
|
149
149
|
|
|
150
150
|
it('does a mix and match of hit, miss, and negative', async () => {
|
|
151
|
-
const cacheAdapterMock = mock<
|
|
151
|
+
const cacheAdapterMock = mock<IEntityCacheAdapter<BlahFields>>();
|
|
152
152
|
const cacheAdapter = instance(cacheAdapterMock);
|
|
153
153
|
const entityCache = new ReadThroughEntityCache(makeEntityConfiguration(true), cacheAdapter);
|
|
154
154
|
const fetcher = createIdFetcher(['wat', 'who', 'why']);
|
|
@@ -183,7 +183,7 @@ describe(ReadThroughEntityCache, () => {
|
|
|
183
183
|
});
|
|
184
184
|
|
|
185
185
|
it('does not call into cache for field that is not cacheable', async () => {
|
|
186
|
-
const cacheAdapterMock = mock<
|
|
186
|
+
const cacheAdapterMock = mock<IEntityCacheAdapter<BlahFields>>();
|
|
187
187
|
const cacheAdapter = instance(cacheAdapterMock);
|
|
188
188
|
const entityCache = new ReadThroughEntityCache(makeEntityConfiguration(false), cacheAdapter);
|
|
189
189
|
const fetcher = createIdFetcher(['wat']);
|
|
@@ -195,7 +195,7 @@ describe(ReadThroughEntityCache, () => {
|
|
|
195
195
|
|
|
196
196
|
describe('invalidateManyAsync', () => {
|
|
197
197
|
it('calls cache adapter invalidate', async () => {
|
|
198
|
-
const cacheAdapterMock = mock<
|
|
198
|
+
const cacheAdapterMock = mock<IEntityCacheAdapter<BlahFields>>();
|
|
199
199
|
const cacheAdapter = instance(cacheAdapterMock);
|
|
200
200
|
const entityCache = new ReadThroughEntityCache(makeEntityConfiguration(true), cacheAdapter);
|
|
201
201
|
await entityCache.invalidateManyAsync('id', ['wat']);
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { reduceMap } from '../utils/collections/maps';
|
|
2
1
|
import IEntityMetricsAdapter, {
|
|
3
2
|
EntityMetricsLoadType,
|
|
4
3
|
EntityMetricsMutationType,
|
|
5
4
|
} from './IEntityMetricsAdapter';
|
|
5
|
+
import { reduceMap } from '../utils/collections/maps';
|
|
6
6
|
|
|
7
7
|
export const timeAndLogLoadEventAsync =
|
|
8
8
|
(
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
+
import PrivacyPolicyRule, { RuleEvaluationResult } from './PrivacyPolicyRule';
|
|
1
2
|
import { EntityPrivacyPolicyEvaluationContext } from '../EntityPrivacyPolicy';
|
|
2
3
|
import { EntityQueryContext } from '../EntityQueryContext';
|
|
3
4
|
import ReadonlyEntity from '../ReadonlyEntity';
|
|
4
5
|
import ViewerContext from '../ViewerContext';
|
|
5
|
-
import PrivacyPolicyRule, { RuleEvaluationResult } from './PrivacyPolicyRule';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Privacy policy rule that always allows.
|
|
9
9
|
*/
|
|
10
10
|
export default class AlwaysAllowPrivacyPolicyRule<
|
|
11
|
-
TFields,
|
|
11
|
+
TFields extends object,
|
|
12
12
|
TID extends NonNullable<TFields[TSelectedFields]>,
|
|
13
13
|
TViewerContext extends ViewerContext,
|
|
14
14
|
TEntity extends ReadonlyEntity<TFields, TID, TViewerContext, TSelectedFields>,
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
+
import PrivacyPolicyRule, { RuleEvaluationResult } from './PrivacyPolicyRule';
|
|
1
2
|
import { EntityPrivacyPolicyEvaluationContext } from '../EntityPrivacyPolicy';
|
|
2
3
|
import { EntityQueryContext } from '../EntityQueryContext';
|
|
3
4
|
import ReadonlyEntity from '../ReadonlyEntity';
|
|
4
5
|
import ViewerContext from '../ViewerContext';
|
|
5
|
-
import PrivacyPolicyRule, { RuleEvaluationResult } from './PrivacyPolicyRule';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Privacy policy rule that always denies.
|
|
9
9
|
*/
|
|
10
10
|
export default class AlwaysDenyPrivacyPolicyRule<
|
|
11
|
-
TFields,
|
|
11
|
+
TFields extends object,
|
|
12
12
|
TID extends NonNullable<TFields[TSelectedFields]>,
|
|
13
13
|
TViewerContext extends ViewerContext,
|
|
14
14
|
TEntity extends ReadonlyEntity<TFields, TID, TViewerContext, TSelectedFields>,
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
+
import PrivacyPolicyRule, { RuleEvaluationResult } from './PrivacyPolicyRule';
|
|
1
2
|
import { EntityPrivacyPolicyEvaluationContext } from '../EntityPrivacyPolicy';
|
|
2
3
|
import { EntityQueryContext } from '../EntityQueryContext';
|
|
3
4
|
import ReadonlyEntity from '../ReadonlyEntity';
|
|
4
5
|
import ViewerContext from '../ViewerContext';
|
|
5
|
-
import PrivacyPolicyRule, { RuleEvaluationResult } from './PrivacyPolicyRule';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* A no-op policy rule that always skips.
|
|
9
9
|
*/
|
|
10
10
|
export default class AlwaysSkipPrivacyPolicyRule<
|
|
11
|
-
TFields,
|
|
11
|
+
TFields extends object,
|
|
12
12
|
TID extends NonNullable<TFields[TSelectedFields]>,
|
|
13
13
|
TViewerContext extends ViewerContext,
|
|
14
14
|
TEntity extends ReadonlyEntity<TFields, TID, TViewerContext, TSelectedFields>,
|
|
@@ -37,7 +37,7 @@ export enum RuleEvaluationResult {
|
|
|
37
37
|
* would be named something like `DenyIfViewerHasBeenBlockedPrivacyPolicyRule`.
|
|
38
38
|
*/
|
|
39
39
|
export default abstract class PrivacyPolicyRule<
|
|
40
|
-
TFields,
|
|
40
|
+
TFields extends object,
|
|
41
41
|
TID extends NonNullable<TFields[TSelectedFields]>,
|
|
42
42
|
TViewerContext extends ViewerContext,
|
|
43
43
|
TEntity extends ReadonlyEntity<TFields, TID, TViewerContext, TSelectedFields>,
|
|
@@ -43,19 +43,17 @@ export class DateIDTestEntityPrivacyPolicy extends EntityPrivacyPolicy<
|
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
export default class DateIDTestEntity extends Entity<DateIDTestFields, Date, ViewerContext> {
|
|
46
|
-
static
|
|
46
|
+
static defineCompanionDefinition(): EntityCompanionDefinition<
|
|
47
47
|
DateIDTestFields,
|
|
48
48
|
Date,
|
|
49
49
|
ViewerContext,
|
|
50
50
|
DateIDTestEntity,
|
|
51
51
|
DateIDTestEntityPrivacyPolicy
|
|
52
52
|
> {
|
|
53
|
-
return
|
|
53
|
+
return {
|
|
54
|
+
entityClass: DateIDTestEntity,
|
|
55
|
+
entityConfiguration: dateIDTestEntityConfiguration,
|
|
56
|
+
privacyPolicyClass: DateIDTestEntityPrivacyPolicy,
|
|
57
|
+
};
|
|
54
58
|
}
|
|
55
59
|
}
|
|
56
|
-
|
|
57
|
-
export const dateIDTestEntityCompanion = new EntityCompanionDefinition({
|
|
58
|
-
entityClass: DateIDTestEntity,
|
|
59
|
-
entityConfiguration: dateIDTestEntityConfiguration,
|
|
60
|
-
privacyPolicyClass: DateIDTestEntityPrivacyPolicy,
|
|
61
|
-
});
|
|
@@ -75,7 +75,7 @@ export default class SimpleTestEntity extends Entity<
|
|
|
75
75
|
ViewerContext,
|
|
76
76
|
SimpleTestFieldSelection
|
|
77
77
|
> {
|
|
78
|
-
static
|
|
78
|
+
static defineCompanionDefinition(): EntityCompanionDefinition<
|
|
79
79
|
SimpleTestFields,
|
|
80
80
|
string,
|
|
81
81
|
ViewerContext,
|
|
@@ -83,12 +83,10 @@ export default class SimpleTestEntity extends Entity<
|
|
|
83
83
|
SimpleTestEntityPrivacyPolicy,
|
|
84
84
|
SimpleTestFieldSelection
|
|
85
85
|
> {
|
|
86
|
-
return
|
|
86
|
+
return {
|
|
87
|
+
entityClass: SimpleTestEntity,
|
|
88
|
+
entityConfiguration: simpleTestEntityConfiguration,
|
|
89
|
+
privacyPolicyClass: SimpleTestEntityPrivacyPolicy,
|
|
90
|
+
};
|
|
87
91
|
}
|
|
88
92
|
}
|
|
89
|
-
|
|
90
|
-
export const testEntityCompanion = new EntityCompanionDefinition({
|
|
91
|
-
entityClass: SimpleTestEntity,
|
|
92
|
-
entityConfiguration: simpleTestEntityConfiguration,
|
|
93
|
-
privacyPolicyClass: SimpleTestEntityPrivacyPolicy,
|
|
94
|
-
});
|