@expo/entity 0.32.0 → 0.34.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/EnforcingEntityLoader.d.ts +5 -0
- package/build/EnforcingEntityLoader.js +8 -0
- package/build/EnforcingEntityLoader.js.map +1 -1
- package/build/Entity.d.ts +6 -6
- package/build/Entity.js +6 -29
- package/build/Entity.js.map +1 -1
- package/build/EntityAssociationLoader.d.ts +8 -8
- package/build/EntityAssociationLoader.js +4 -20
- package/build/EntityAssociationLoader.js.map +1 -1
- package/build/EntityFields.js +3 -2
- package/build/EntityFields.js.map +1 -1
- package/build/EntityLoader.d.ts +6 -0
- package/build/EntityLoader.js +11 -0
- package/build/EntityLoader.js.map +1 -1
- package/build/EntityMutationTriggerConfiguration.d.ts +5 -7
- package/build/EntityMutationTriggerConfiguration.js +3 -4
- package/build/EntityMutationTriggerConfiguration.js.map +1 -1
- package/build/EntityQueryContextProvider.d.ts +1 -1
- package/build/EntityQueryContextProvider.js +1 -1
- package/build/EntityQueryContextProvider.js.map +1 -1
- package/build/IEntityCacheAdapterProvider.d.ts +1 -1
- package/build/ReadonlyEntity.d.ts +1 -1
- package/build/ReadonlyEntity.js +1 -4
- package/build/ReadonlyEntity.js.map +1 -1
- package/build/ViewerContext.d.ts +2 -2
- package/build/ViewerContext.js +3 -3
- package/build/ViewerContext.js.map +1 -1
- package/build/__tests__/EnforcingEntityLoader-test.js +27 -0
- package/build/__tests__/EnforcingEntityLoader-test.js.map +1 -1
- package/build/__tests__/Entity-test.js +13 -13
- package/build/__tests__/Entity-test.js.map +1 -1
- package/build/__tests__/EntityAssociationLoader-test.js +69 -37
- package/build/__tests__/EntityAssociationLoader-test.js.map +1 -1
- package/build/__tests__/EntityCommonUseCases-test.js +19 -11
- package/build/__tests__/EntityCommonUseCases-test.js.map +1 -1
- package/build/__tests__/EntityEdges-test.js +72 -40
- package/build/__tests__/EntityEdges-test.js.map +1 -1
- package/build/__tests__/EntityFields-test.js +7 -1
- package/build/__tests__/EntityFields-test.js.map +1 -1
- package/build/__tests__/EntityLoader-constructor-test.js +1 -1
- package/build/__tests__/EntityLoader-constructor-test.js.map +1 -1
- package/build/__tests__/EntityLoader-test.js +22 -20
- package/build/__tests__/EntityLoader-test.js.map +1 -1
- package/build/__tests__/EntityMutator-MutationCacheConsistency-test.js +6 -6
- package/build/__tests__/EntityMutator-MutationCacheConsistency-test.js.map +1 -1
- package/build/__tests__/EntityMutator-test.js +20 -20
- package/build/__tests__/EntityMutator-test.js.map +1 -1
- package/build/__tests__/EntitySecondaryCacheLoader-test.js +10 -10
- package/build/__tests__/EntitySecondaryCacheLoader-test.js.map +1 -1
- package/build/__tests__/EntitySelfReferentialEdges-test.js +79 -47
- package/build/__tests__/EntitySelfReferentialEdges-test.js.map +1 -1
- package/build/__tests__/ReadonlyEntity-test.js +13 -13
- package/build/__tests__/ReadonlyEntity-test.js.map +1 -1
- package/build/__tests__/ViewerContext-test.js +2 -2
- package/build/__tests__/ViewerContext-test.js.map +1 -1
- package/build/__tests__/cases/TwoEntitySameTableDisjointRows-test.js +12 -8
- package/build/__tests__/cases/TwoEntitySameTableDisjointRows-test.js.map +1 -1
- package/build/__tests__/cases/TwoEntitySameTableOverlappingRows-test.js +15 -13
- package/build/__tests__/cases/TwoEntitySameTableOverlappingRows-test.js.map +1 -1
- package/build/internal/EntityDataManager.js +1 -1
- package/build/internal/EntityDataManager.js.map +1 -1
- package/build/internal/__tests__/EntityDataManager-test.js +11 -11
- package/build/internal/__tests__/EntityDataManager-test.js.map +1 -1
- package/build/testfixtures/SimpleTestEntity.d.ts +8 -8
- package/build/testfixtures/SimpleTestEntity.js.map +1 -1
- package/build/testfixtures/TestEntity.d.ts +12 -12
- package/build/testfixtures/TestEntity.js.map +1 -1
- package/build/testfixtures/TestEntity2.d.ts +8 -8
- package/build/testfixtures/TestEntity2.js.map +1 -1
- package/build/testfixtures/TestViewerContext.d.ts +3 -0
- package/build/testfixtures/TestViewerContext.js +6 -0
- package/build/testfixtures/TestViewerContext.js.map +1 -1
- package/package.json +2 -2
- package/src/EnforcingEntityLoader.ts +9 -0
- package/src/Entity.ts +6 -29
- package/src/EntityAssociationLoader.ts +9 -25
- package/src/EntityFields.ts +5 -3
- package/src/EntityLoader.ts +17 -0
- package/src/EntityMutationTriggerConfiguration.ts +5 -7
- package/src/EntityQueryContextProvider.ts +1 -1
- package/src/IEntityCacheAdapterProvider.ts +1 -1
- package/src/ReadonlyEntity.ts +1 -4
- package/src/ViewerContext.ts +5 -5
- package/src/__tests__/EnforcingEntityLoader-test.ts +43 -0
- package/src/__tests__/Entity-test.ts +43 -27
- package/src/__tests__/EntityAssociationLoader-test.ts +168 -86
- package/src/__tests__/EntityCommonUseCases-test.ts +36 -18
- package/src/__tests__/EntityEdges-test.ts +102 -40
- package/src/__tests__/EntityFields-test.ts +7 -1
- package/src/__tests__/EntityLoader-constructor-test.ts +1 -1
- package/src/__tests__/EntityLoader-test.ts +24 -20
- package/src/__tests__/EntityMutator-MutationCacheConsistency-test.ts +19 -16
- package/src/__tests__/EntityMutator-test.ts +67 -61
- package/src/__tests__/EntitySecondaryCacheLoader-test.ts +20 -11
- package/src/__tests__/EntitySelfReferentialEdges-test.ts +115 -47
- package/src/__tests__/ReadonlyEntity-test.ts +15 -13
- package/src/__tests__/ViewerContext-test.ts +3 -2
- package/src/__tests__/cases/TwoEntitySameTableDisjointRows-test.ts +33 -22
- package/src/__tests__/cases/TwoEntitySameTableOverlappingRows-test.ts +30 -22
- package/src/internal/EntityDataManager.ts +1 -1
- package/src/internal/__tests__/EntityDataManager-test.ts +11 -11
- package/src/testfixtures/SimpleTestEntity.ts +8 -8
- package/src/testfixtures/TestEntity.ts +15 -12
- package/src/testfixtures/TestEntity2.ts +8 -8
- package/src/testfixtures/TestViewerContext.ts +12 -1
|
@@ -3,26 +3,26 @@ import { EntityCompanionDefinition } from '../../EntityCompanionProvider';
|
|
|
3
3
|
import EntityConfiguration from '../../EntityConfiguration';
|
|
4
4
|
import { UUIDField, StringField } from '../../EntityFields';
|
|
5
5
|
import EntityPrivacyPolicy from '../../EntityPrivacyPolicy';
|
|
6
|
-
import ViewerContext from '../../ViewerContext';
|
|
7
6
|
import AlwaysAllowPrivacyPolicyRule from '../../rules/AlwaysAllowPrivacyPolicyRule';
|
|
7
|
+
import TestViewerContext from '../../testfixtures/TestViewerContext';
|
|
8
8
|
import { createUnitTestEntityCompanionProvider } from '../../utils/testing/createUnitTestEntityCompanionProvider';
|
|
9
9
|
|
|
10
10
|
describe('Two entities backed by the same table', () => {
|
|
11
11
|
test('mutate through different types and keep consistent cache and dataloader', async () => {
|
|
12
12
|
const companionProvider = createUnitTestEntityCompanionProvider();
|
|
13
|
-
const viewerContext = new
|
|
13
|
+
const viewerContext = new TestViewerContext(companionProvider);
|
|
14
14
|
|
|
15
|
-
const entity1 = await OneTestEntity.creator(viewerContext)
|
|
15
|
+
const entity1 = await OneTestEntity.creator(viewerContext, viewerContext.getQueryContext())
|
|
16
16
|
.setField('fake_field', 'hello')
|
|
17
17
|
.enforceCreateAsync();
|
|
18
18
|
expect(entity1).toBeInstanceOf(OneTestEntity);
|
|
19
19
|
|
|
20
|
-
const entity2 = await TwoTestEntity.loader(viewerContext)
|
|
20
|
+
const entity2 = await TwoTestEntity.loader(viewerContext, viewerContext.getQueryContext())
|
|
21
21
|
.enforcing()
|
|
22
22
|
.loadByIDAsync(entity1.getID());
|
|
23
23
|
expect(entity2).toBeInstanceOf(TwoTestEntity);
|
|
24
24
|
|
|
25
|
-
const updated2 = await TwoTestEntity.updater(entity2)
|
|
25
|
+
const updated2 = await TwoTestEntity.updater(entity2, viewerContext.getQueryContext())
|
|
26
26
|
.setField('fake_field', 'world')
|
|
27
27
|
.setField('other_field', 'wat')
|
|
28
28
|
.enforceUpdateAsync();
|
|
@@ -32,7 +32,7 @@ describe('Two entities backed by the same table', () => {
|
|
|
32
32
|
fake_field: 'world',
|
|
33
33
|
});
|
|
34
34
|
|
|
35
|
-
const loaded1 = await OneTestEntity.loader(viewerContext)
|
|
35
|
+
const loaded1 = await OneTestEntity.loader(viewerContext, viewerContext.getQueryContext())
|
|
36
36
|
.enforcing()
|
|
37
37
|
.loadByIDAsync(entity1.getID());
|
|
38
38
|
expect(loaded1.getAllFields()).toMatchObject({
|
|
@@ -43,14 +43,14 @@ describe('Two entities backed by the same table', () => {
|
|
|
43
43
|
|
|
44
44
|
test('cached field that differs between the two to test invalidation', async () => {
|
|
45
45
|
const companionProvider = createUnitTestEntityCompanionProvider();
|
|
46
|
-
const viewerContext = new
|
|
46
|
+
const viewerContext = new TestViewerContext(companionProvider);
|
|
47
47
|
|
|
48
|
-
const entity = await TwoTestEntity.creator(viewerContext)
|
|
48
|
+
const entity = await TwoTestEntity.creator(viewerContext, viewerContext.getQueryContext())
|
|
49
49
|
.setField('fake_field', 'hello')
|
|
50
50
|
.setField('other_field', 'huh')
|
|
51
51
|
.enforceCreateAsync();
|
|
52
52
|
|
|
53
|
-
const loadedEntity = await TwoTestEntity.loader(viewerContext)
|
|
53
|
+
const loadedEntity = await TwoTestEntity.loader(viewerContext, viewerContext.getQueryContext())
|
|
54
54
|
.enforcing()
|
|
55
55
|
.loadByFieldEqualingAsync('other_field', 'huh');
|
|
56
56
|
expect(loadedEntity?.getAllFields()).toMatchObject({
|
|
@@ -59,12 +59,14 @@ describe('Two entities backed by the same table', () => {
|
|
|
59
59
|
other_field: 'huh',
|
|
60
60
|
});
|
|
61
61
|
|
|
62
|
-
const loaded1 = await OneTestEntity.loader(viewerContext)
|
|
62
|
+
const loaded1 = await OneTestEntity.loader(viewerContext, viewerContext.getQueryContext())
|
|
63
63
|
.enforcing()
|
|
64
64
|
.loadByIDAsync(entity.getID());
|
|
65
|
-
await OneTestEntity.updater(loaded1
|
|
65
|
+
await OneTestEntity.updater(loaded1, viewerContext.getQueryContext())
|
|
66
|
+
.setField('fake_field', 'world')
|
|
67
|
+
.enforceUpdateAsync();
|
|
66
68
|
|
|
67
|
-
const loaded2 = await TwoTestEntity.loader(viewerContext)
|
|
69
|
+
const loaded2 = await TwoTestEntity.loader(viewerContext, viewerContext.getQueryContext())
|
|
68
70
|
.enforcing()
|
|
69
71
|
.loadByFieldEqualingAsync('other_field', 'huh');
|
|
70
72
|
expect(loaded2?.getAllFields()).toMatchObject({
|
|
@@ -73,7 +75,7 @@ describe('Two entities backed by the same table', () => {
|
|
|
73
75
|
other_field: 'huh',
|
|
74
76
|
});
|
|
75
77
|
|
|
76
|
-
const loaded22 = await TwoTestEntity.loader(viewerContext)
|
|
78
|
+
const loaded22 = await TwoTestEntity.loader(viewerContext, viewerContext.getQueryContext())
|
|
77
79
|
.enforcing()
|
|
78
80
|
.loadByFieldEqualingAsync('fake_field', 'world');
|
|
79
81
|
expect(loaded22?.getAllFields()).toMatchObject({
|
|
@@ -114,26 +116,32 @@ const testEntityConfiguration = new EntityConfiguration<TestFields>({
|
|
|
114
116
|
cacheAdapterFlavor: 'redis',
|
|
115
117
|
});
|
|
116
118
|
|
|
117
|
-
class TestEntityPrivacyPolicy extends EntityPrivacyPolicy<
|
|
119
|
+
class TestEntityPrivacyPolicy extends EntityPrivacyPolicy<
|
|
120
|
+
any,
|
|
121
|
+
string,
|
|
122
|
+
TestViewerContext,
|
|
123
|
+
any,
|
|
124
|
+
any
|
|
125
|
+
> {
|
|
118
126
|
protected override readonly readRules = [
|
|
119
|
-
new AlwaysAllowPrivacyPolicyRule<any, string,
|
|
127
|
+
new AlwaysAllowPrivacyPolicyRule<any, string, TestViewerContext, any, any>(),
|
|
120
128
|
];
|
|
121
129
|
protected override readonly createRules = [
|
|
122
|
-
new AlwaysAllowPrivacyPolicyRule<any, string,
|
|
130
|
+
new AlwaysAllowPrivacyPolicyRule<any, string, TestViewerContext, any, any>(),
|
|
123
131
|
];
|
|
124
132
|
protected override readonly updateRules = [
|
|
125
|
-
new AlwaysAllowPrivacyPolicyRule<any, string,
|
|
133
|
+
new AlwaysAllowPrivacyPolicyRule<any, string, TestViewerContext, any, any>(),
|
|
126
134
|
];
|
|
127
135
|
protected override readonly deleteRules = [
|
|
128
|
-
new AlwaysAllowPrivacyPolicyRule<any, string,
|
|
136
|
+
new AlwaysAllowPrivacyPolicyRule<any, string, TestViewerContext, any, any>(),
|
|
129
137
|
];
|
|
130
138
|
}
|
|
131
139
|
|
|
132
|
-
class OneTestEntity extends Entity<TestFields, string,
|
|
140
|
+
class OneTestEntity extends Entity<TestFields, string, TestViewerContext, OneTestFields> {
|
|
133
141
|
static defineCompanionDefinition(): EntityCompanionDefinition<
|
|
134
142
|
TestFields,
|
|
135
143
|
string,
|
|
136
|
-
|
|
144
|
+
TestViewerContext,
|
|
137
145
|
OneTestEntity,
|
|
138
146
|
TestEntityPrivacyPolicy,
|
|
139
147
|
OneTestFields
|
|
@@ -147,11 +155,11 @@ class OneTestEntity extends Entity<TestFields, string, ViewerContext, OneTestFie
|
|
|
147
155
|
}
|
|
148
156
|
}
|
|
149
157
|
|
|
150
|
-
class TwoTestEntity extends Entity<TestFields, string,
|
|
158
|
+
class TwoTestEntity extends Entity<TestFields, string, TestViewerContext, TwoTestFields> {
|
|
151
159
|
static defineCompanionDefinition(): EntityCompanionDefinition<
|
|
152
160
|
TestFields,
|
|
153
161
|
string,
|
|
154
|
-
|
|
162
|
+
TestViewerContext,
|
|
155
163
|
TwoTestEntity,
|
|
156
164
|
TestEntityPrivacyPolicy,
|
|
157
165
|
TwoTestFields
|
|
@@ -76,7 +76,7 @@ export default class EntityDataManager<TFields> {
|
|
|
76
76
|
entityClassName: this.entityClassName,
|
|
77
77
|
});
|
|
78
78
|
return await this.databaseAdapter.fetchManyWhereAsync(
|
|
79
|
-
this.queryContextProvider.
|
|
79
|
+
this.queryContextProvider.getNonTransactionalQueryContext(),
|
|
80
80
|
fieldName,
|
|
81
81
|
fetcherValues
|
|
82
82
|
);
|
|
@@ -78,7 +78,7 @@ describe(EntityDataManager, () => {
|
|
|
78
78
|
new NoOpEntityMetricsAdapter(),
|
|
79
79
|
TestEntity.name
|
|
80
80
|
);
|
|
81
|
-
const queryContext = StubQueryContextProvider.
|
|
81
|
+
const queryContext = StubQueryContextProvider.getNonTransactionalQueryContext();
|
|
82
82
|
|
|
83
83
|
const dbSpy = jest.spyOn(databaseAdapter, 'fetchManyWhereAsync');
|
|
84
84
|
const cacheSpy = jest.spyOn(entityCache, 'readManyThroughAsync');
|
|
@@ -126,7 +126,7 @@ describe(EntityDataManager, () => {
|
|
|
126
126
|
new NoOpEntityMetricsAdapter(),
|
|
127
127
|
TestEntity.name
|
|
128
128
|
);
|
|
129
|
-
const queryContext = StubQueryContextProvider.
|
|
129
|
+
const queryContext = StubQueryContextProvider.getNonTransactionalQueryContext();
|
|
130
130
|
|
|
131
131
|
const dbSpy = jest.spyOn(databaseAdapter, 'fetchManyWhereAsync');
|
|
132
132
|
const cacheSpy = jest.spyOn(entityCache, 'readManyThroughAsync');
|
|
@@ -174,7 +174,7 @@ describe(EntityDataManager, () => {
|
|
|
174
174
|
new NoOpEntityMetricsAdapter(),
|
|
175
175
|
TestEntity.name
|
|
176
176
|
);
|
|
177
|
-
const queryContext = StubQueryContextProvider.
|
|
177
|
+
const queryContext = StubQueryContextProvider.getNonTransactionalQueryContext();
|
|
178
178
|
// use second data manager to ensure that cache is hit instead of data loader
|
|
179
179
|
const entityDataManager2 = new EntityDataManager(
|
|
180
180
|
databaseAdapter,
|
|
@@ -218,7 +218,7 @@ describe(EntityDataManager, () => {
|
|
|
218
218
|
new NoOpEntityMetricsAdapter(),
|
|
219
219
|
TestEntity.name
|
|
220
220
|
);
|
|
221
|
-
const queryContext = StubQueryContextProvider.
|
|
221
|
+
const queryContext = StubQueryContextProvider.getNonTransactionalQueryContext();
|
|
222
222
|
|
|
223
223
|
const dbSpy = jest.spyOn(databaseAdapter, 'fetchManyWhereAsync');
|
|
224
224
|
const cacheSpy = jest.spyOn(entityCache, 'readManyThroughAsync');
|
|
@@ -254,7 +254,7 @@ describe(EntityDataManager, () => {
|
|
|
254
254
|
new NoOpEntityMetricsAdapter(),
|
|
255
255
|
TestEntity.name
|
|
256
256
|
);
|
|
257
|
-
const queryContext = StubQueryContextProvider.
|
|
257
|
+
const queryContext = StubQueryContextProvider.getNonTransactionalQueryContext();
|
|
258
258
|
|
|
259
259
|
const dbSpy = jest.spyOn(databaseAdapter, 'fetchManyWhereAsync');
|
|
260
260
|
const cacheSpy = jest.spyOn(entityCache, 'readManyThroughAsync');
|
|
@@ -298,7 +298,7 @@ describe(EntityDataManager, () => {
|
|
|
298
298
|
new NoOpEntityMetricsAdapter(),
|
|
299
299
|
TestEntity.name
|
|
300
300
|
);
|
|
301
|
-
const queryContext = StubQueryContextProvider.
|
|
301
|
+
const queryContext = StubQueryContextProvider.getNonTransactionalQueryContext();
|
|
302
302
|
|
|
303
303
|
const objectInQuestion = objects.get(testEntityConfiguration.tableName)![1]!;
|
|
304
304
|
|
|
@@ -337,7 +337,7 @@ describe(EntityDataManager, () => {
|
|
|
337
337
|
new NoOpEntityMetricsAdapter(),
|
|
338
338
|
TestEntity.name
|
|
339
339
|
);
|
|
340
|
-
const queryContext = StubQueryContextProvider.
|
|
340
|
+
const queryContext = StubQueryContextProvider.getNonTransactionalQueryContext();
|
|
341
341
|
|
|
342
342
|
const objectInQuestion = objects.get(testEntityConfiguration.tableName)![1]!;
|
|
343
343
|
|
|
@@ -415,7 +415,7 @@ describe(EntityDataManager, () => {
|
|
|
415
415
|
new NoOpEntityMetricsAdapter(),
|
|
416
416
|
TestEntity.name
|
|
417
417
|
);
|
|
418
|
-
const queryContext = StubQueryContextProvider.
|
|
418
|
+
const queryContext = StubQueryContextProvider.getNonTransactionalQueryContext();
|
|
419
419
|
|
|
420
420
|
const dbSpy = jest.spyOn(databaseAdapter, 'fetchManyByFieldEqualityConjunctionAsync');
|
|
421
421
|
const cacheSpy = jest.spyOn(entityCache, 'readManyThroughAsync');
|
|
@@ -461,7 +461,7 @@ describe(EntityDataManager, () => {
|
|
|
461
461
|
new NoOpEntityMetricsAdapter(),
|
|
462
462
|
TestEntity.name
|
|
463
463
|
);
|
|
464
|
-
const queryContext = StubQueryContextProvider.
|
|
464
|
+
const queryContext = StubQueryContextProvider.getNonTransactionalQueryContext();
|
|
465
465
|
|
|
466
466
|
await expect(
|
|
467
467
|
entityDataManager.loadManyByFieldEqualingAsync(queryContext, 'customIdField', ['2'])
|
|
@@ -488,7 +488,7 @@ describe(EntityDataManager, () => {
|
|
|
488
488
|
metricsAdapter,
|
|
489
489
|
TestEntity.name
|
|
490
490
|
);
|
|
491
|
-
const queryContext = StubQueryContextProvider.
|
|
491
|
+
const queryContext = StubQueryContextProvider.getNonTransactionalQueryContext();
|
|
492
492
|
|
|
493
493
|
await entityDataManager.loadManyByFieldEqualingAsync(queryContext, 'customIdField', ['1']);
|
|
494
494
|
verify(
|
|
@@ -591,7 +591,7 @@ describe(EntityDataManager, () => {
|
|
|
591
591
|
new NoOpEntityMetricsAdapter(),
|
|
592
592
|
TestEntity.name
|
|
593
593
|
);
|
|
594
|
-
const queryContext = StubQueryContextProvider.
|
|
594
|
+
const queryContext = StubQueryContextProvider.getNonTransactionalQueryContext();
|
|
595
595
|
|
|
596
596
|
await expect(
|
|
597
597
|
entityDataManager.loadManyByFieldEqualingAsync(queryContext, 'nullableField', [null as any])
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import TestViewerContext from './TestViewerContext';
|
|
1
2
|
import Entity from '../Entity';
|
|
2
3
|
import { EntityCompanionDefinition } from '../EntityCompanionProvider';
|
|
3
4
|
import EntityConfiguration from '../EntityConfiguration';
|
|
4
5
|
import { UUIDField } from '../EntityFields';
|
|
5
6
|
import EntityPrivacyPolicy from '../EntityPrivacyPolicy';
|
|
6
|
-
import ViewerContext from '../ViewerContext';
|
|
7
7
|
import AlwaysAllowPrivacyPolicyRule from '../rules/AlwaysAllowPrivacyPolicyRule';
|
|
8
8
|
|
|
9
9
|
export type SimpleTestFields = {
|
|
@@ -27,7 +27,7 @@ export const simpleTestEntityConfiguration = new EntityConfiguration<SimpleTestF
|
|
|
27
27
|
export class SimpleTestEntityPrivacyPolicy extends EntityPrivacyPolicy<
|
|
28
28
|
SimpleTestFields,
|
|
29
29
|
string,
|
|
30
|
-
|
|
30
|
+
TestViewerContext,
|
|
31
31
|
SimpleTestEntity,
|
|
32
32
|
SimpleTestFieldSelection
|
|
33
33
|
> {
|
|
@@ -35,7 +35,7 @@ export class SimpleTestEntityPrivacyPolicy extends EntityPrivacyPolicy<
|
|
|
35
35
|
new AlwaysAllowPrivacyPolicyRule<
|
|
36
36
|
SimpleTestFields,
|
|
37
37
|
string,
|
|
38
|
-
|
|
38
|
+
TestViewerContext,
|
|
39
39
|
SimpleTestEntity,
|
|
40
40
|
SimpleTestFieldSelection
|
|
41
41
|
>(),
|
|
@@ -44,7 +44,7 @@ export class SimpleTestEntityPrivacyPolicy extends EntityPrivacyPolicy<
|
|
|
44
44
|
new AlwaysAllowPrivacyPolicyRule<
|
|
45
45
|
SimpleTestFields,
|
|
46
46
|
string,
|
|
47
|
-
|
|
47
|
+
TestViewerContext,
|
|
48
48
|
SimpleTestEntity,
|
|
49
49
|
SimpleTestFieldSelection
|
|
50
50
|
>(),
|
|
@@ -53,7 +53,7 @@ export class SimpleTestEntityPrivacyPolicy extends EntityPrivacyPolicy<
|
|
|
53
53
|
new AlwaysAllowPrivacyPolicyRule<
|
|
54
54
|
SimpleTestFields,
|
|
55
55
|
string,
|
|
56
|
-
|
|
56
|
+
TestViewerContext,
|
|
57
57
|
SimpleTestEntity,
|
|
58
58
|
SimpleTestFieldSelection
|
|
59
59
|
>(),
|
|
@@ -62,7 +62,7 @@ export class SimpleTestEntityPrivacyPolicy extends EntityPrivacyPolicy<
|
|
|
62
62
|
new AlwaysAllowPrivacyPolicyRule<
|
|
63
63
|
SimpleTestFields,
|
|
64
64
|
string,
|
|
65
|
-
|
|
65
|
+
TestViewerContext,
|
|
66
66
|
SimpleTestEntity,
|
|
67
67
|
SimpleTestFieldSelection
|
|
68
68
|
>(),
|
|
@@ -72,13 +72,13 @@ export class SimpleTestEntityPrivacyPolicy extends EntityPrivacyPolicy<
|
|
|
72
72
|
export default class SimpleTestEntity extends Entity<
|
|
73
73
|
SimpleTestFields,
|
|
74
74
|
string,
|
|
75
|
-
|
|
75
|
+
TestViewerContext,
|
|
76
76
|
SimpleTestFieldSelection
|
|
77
77
|
> {
|
|
78
78
|
static defineCompanionDefinition(): EntityCompanionDefinition<
|
|
79
79
|
SimpleTestFields,
|
|
80
80
|
string,
|
|
81
|
-
|
|
81
|
+
TestViewerContext,
|
|
82
82
|
SimpleTestEntity,
|
|
83
83
|
SimpleTestEntityPrivacyPolicy,
|
|
84
84
|
SimpleTestFieldSelection
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { result, Result } from '@expo/results';
|
|
2
2
|
|
|
3
|
+
import TestViewerContext from './TestViewerContext';
|
|
3
4
|
import Entity from '../Entity';
|
|
4
5
|
import { EntityCompanionDefinition } from '../EntityCompanionProvider';
|
|
5
6
|
import EntityConfiguration from '../EntityConfiguration';
|
|
6
7
|
import { UUIDField, StringField, DateField, IntField } from '../EntityFields';
|
|
7
8
|
import EntityPrivacyPolicy from '../EntityPrivacyPolicy';
|
|
8
|
-
import ViewerContext from '../ViewerContext';
|
|
9
9
|
import AlwaysAllowPrivacyPolicyRule from '../rules/AlwaysAllowPrivacyPolicyRule';
|
|
10
10
|
|
|
11
11
|
export type TestFields = {
|
|
@@ -48,28 +48,28 @@ export const testEntityConfiguration = new EntityConfiguration<TestFields>({
|
|
|
48
48
|
export class TestEntityPrivacyPolicy extends EntityPrivacyPolicy<
|
|
49
49
|
TestFields,
|
|
50
50
|
string,
|
|
51
|
-
|
|
51
|
+
TestViewerContext,
|
|
52
52
|
TestEntity
|
|
53
53
|
> {
|
|
54
54
|
protected override readonly readRules = [
|
|
55
|
-
new AlwaysAllowPrivacyPolicyRule<TestFields, string,
|
|
55
|
+
new AlwaysAllowPrivacyPolicyRule<TestFields, string, TestViewerContext, TestEntity>(),
|
|
56
56
|
];
|
|
57
57
|
protected override readonly createRules = [
|
|
58
|
-
new AlwaysAllowPrivacyPolicyRule<TestFields, string,
|
|
58
|
+
new AlwaysAllowPrivacyPolicyRule<TestFields, string, TestViewerContext, TestEntity>(),
|
|
59
59
|
];
|
|
60
60
|
protected override readonly updateRules = [
|
|
61
|
-
new AlwaysAllowPrivacyPolicyRule<TestFields, string,
|
|
61
|
+
new AlwaysAllowPrivacyPolicyRule<TestFields, string, TestViewerContext, TestEntity>(),
|
|
62
62
|
];
|
|
63
63
|
protected override readonly deleteRules = [
|
|
64
|
-
new AlwaysAllowPrivacyPolicyRule<TestFields, string,
|
|
64
|
+
new AlwaysAllowPrivacyPolicyRule<TestFields, string, TestViewerContext, TestEntity>(),
|
|
65
65
|
];
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
-
export default class TestEntity extends Entity<TestFields, string,
|
|
68
|
+
export default class TestEntity extends Entity<TestFields, string, TestViewerContext> {
|
|
69
69
|
static defineCompanionDefinition(): EntityCompanionDefinition<
|
|
70
70
|
TestFields,
|
|
71
71
|
string,
|
|
72
|
-
|
|
72
|
+
TestViewerContext,
|
|
73
73
|
TestEntity,
|
|
74
74
|
TestEntityPrivacyPolicy
|
|
75
75
|
> {
|
|
@@ -84,7 +84,10 @@ export default class TestEntity extends Entity<TestFields, string, ViewerContext
|
|
|
84
84
|
return 'Hello World!';
|
|
85
85
|
}
|
|
86
86
|
|
|
87
|
-
static async hello(
|
|
87
|
+
static async hello(
|
|
88
|
+
viewerContext: TestViewerContext,
|
|
89
|
+
testValue: string
|
|
90
|
+
): Promise<Result<TestEntity>> {
|
|
88
91
|
const fields = {
|
|
89
92
|
customIdField: testValue,
|
|
90
93
|
testIndexedField: 'hello',
|
|
@@ -103,15 +106,15 @@ export default class TestEntity extends Entity<TestFields, string, ViewerContext
|
|
|
103
106
|
);
|
|
104
107
|
}
|
|
105
108
|
|
|
106
|
-
static async returnError(_viewerContext:
|
|
109
|
+
static async returnError(_viewerContext: TestViewerContext): Promise<Result<TestEntity>> {
|
|
107
110
|
return result(new Error('return entity'));
|
|
108
111
|
}
|
|
109
112
|
|
|
110
|
-
static async throwError(_viewerContext:
|
|
113
|
+
static async throwError(_viewerContext: TestViewerContext): Promise<Result<TestEntity>> {
|
|
111
114
|
throw new Error('threw entity');
|
|
112
115
|
}
|
|
113
116
|
|
|
114
|
-
static async nonResult(_viewerContext:
|
|
117
|
+
static async nonResult(_viewerContext: TestViewerContext, testValue: string): Promise<string> {
|
|
115
118
|
return testValue;
|
|
116
119
|
}
|
|
117
120
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import TestViewerContext from './TestViewerContext';
|
|
1
2
|
import Entity from '../Entity';
|
|
2
3
|
import { EntityCompanionDefinition } from '../EntityCompanionProvider';
|
|
3
4
|
import EntityConfiguration from '../EntityConfiguration';
|
|
4
5
|
import { UUIDField } from '../EntityFields';
|
|
5
6
|
import EntityPrivacyPolicy from '../EntityPrivacyPolicy';
|
|
6
|
-
import ViewerContext from '../ViewerContext';
|
|
7
7
|
import AlwaysAllowPrivacyPolicyRule from '../rules/AlwaysAllowPrivacyPolicyRule';
|
|
8
8
|
|
|
9
9
|
export type Test2Fields = {
|
|
@@ -29,28 +29,28 @@ export const testEntity2Configuration = new EntityConfiguration<Test2Fields>({
|
|
|
29
29
|
export class TestEntity2PrivacyPolicy extends EntityPrivacyPolicy<
|
|
30
30
|
Test2Fields,
|
|
31
31
|
string,
|
|
32
|
-
|
|
32
|
+
TestViewerContext,
|
|
33
33
|
TestEntity2
|
|
34
34
|
> {
|
|
35
35
|
protected override readonly readRules = [
|
|
36
|
-
new AlwaysAllowPrivacyPolicyRule<Test2Fields, string,
|
|
36
|
+
new AlwaysAllowPrivacyPolicyRule<Test2Fields, string, TestViewerContext, TestEntity2>(),
|
|
37
37
|
];
|
|
38
38
|
protected override readonly createRules = [
|
|
39
|
-
new AlwaysAllowPrivacyPolicyRule<Test2Fields, string,
|
|
39
|
+
new AlwaysAllowPrivacyPolicyRule<Test2Fields, string, TestViewerContext, TestEntity2>(),
|
|
40
40
|
];
|
|
41
41
|
protected override readonly updateRules = [
|
|
42
|
-
new AlwaysAllowPrivacyPolicyRule<Test2Fields, string,
|
|
42
|
+
new AlwaysAllowPrivacyPolicyRule<Test2Fields, string, TestViewerContext, TestEntity2>(),
|
|
43
43
|
];
|
|
44
44
|
protected override readonly deleteRules = [
|
|
45
|
-
new AlwaysAllowPrivacyPolicyRule<Test2Fields, string,
|
|
45
|
+
new AlwaysAllowPrivacyPolicyRule<Test2Fields, string, TestViewerContext, TestEntity2>(),
|
|
46
46
|
];
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
export default class TestEntity2 extends Entity<Test2Fields, string,
|
|
49
|
+
export default class TestEntity2 extends Entity<Test2Fields, string, TestViewerContext> {
|
|
50
50
|
static defineCompanionDefinition(): EntityCompanionDefinition<
|
|
51
51
|
Test2Fields,
|
|
52
52
|
string,
|
|
53
|
-
|
|
53
|
+
TestViewerContext,
|
|
54
54
|
TestEntity2,
|
|
55
55
|
TestEntity2PrivacyPolicy
|
|
56
56
|
> {
|
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
import { EntityQueryContext, EntityTransactionalQueryContext } from '../EntityQueryContext';
|
|
1
2
|
import ViewerContext from '../ViewerContext';
|
|
2
3
|
|
|
3
|
-
export default class TestViewerContext extends ViewerContext {
|
|
4
|
+
export default class TestViewerContext extends ViewerContext {
|
|
5
|
+
public getQueryContext(): EntityQueryContext {
|
|
6
|
+
return super.getNonTransactionalQueryContextForDatabaseAdaptorFlavor('postgres');
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
public async runInTransactionAsync<TResult>(
|
|
10
|
+
transactionScope: (queryContext: EntityTransactionalQueryContext) => Promise<TResult>
|
|
11
|
+
): Promise<TResult> {
|
|
12
|
+
return await super.runInTransactionForDatabaseAdaptorFlavorAsync('postgres', transactionScope);
|
|
13
|
+
}
|
|
14
|
+
}
|