@expo/entity 0.34.0 → 0.35.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/Entity.d.ts +6 -6
- package/build/Entity.js +29 -6
- package/build/Entity.js.map +1 -1
- package/build/EntityAssociationLoader.d.ts +8 -8
- package/build/EntityAssociationLoader.js +20 -4
- package/build/EntityAssociationLoader.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/ReadonlyEntity.d.ts +1 -1
- package/build/ReadonlyEntity.js +4 -1
- 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__/Entity-test.js +13 -13
- package/build/__tests__/Entity-test.js.map +1 -1
- package/build/__tests__/EntityAssociationLoader-test.js +37 -69
- package/build/__tests__/EntityAssociationLoader-test.js.map +1 -1
- package/build/__tests__/EntityCommonUseCases-test.js +11 -19
- package/build/__tests__/EntityCommonUseCases-test.js.map +1 -1
- package/build/__tests__/EntityEdges-test.js +40 -72
- package/build/__tests__/EntityEdges-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 +19 -19
- 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 +47 -79
- 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 +8 -12
- package/build/__tests__/cases/TwoEntitySameTableDisjointRows-test.js.map +1 -1
- package/build/__tests__/cases/TwoEntitySameTableOverlappingRows-test.js +13 -15
- 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 +0 -3
- package/build/testfixtures/TestViewerContext.js +0 -6
- package/build/testfixtures/TestViewerContext.js.map +1 -1
- package/package.json +2 -2
- package/src/Entity.ts +29 -6
- package/src/EntityAssociationLoader.ts +25 -9
- package/src/EntityQueryContextProvider.ts +1 -1
- package/src/ReadonlyEntity.ts +4 -1
- package/src/ViewerContext.ts +5 -5
- package/src/__tests__/Entity-test.ts +27 -43
- package/src/__tests__/EntityAssociationLoader-test.ts +86 -168
- package/src/__tests__/EntityCommonUseCases-test.ts +18 -36
- package/src/__tests__/EntityEdges-test.ts +40 -102
- package/src/__tests__/EntityLoader-constructor-test.ts +1 -1
- package/src/__tests__/EntityLoader-test.ts +19 -19
- package/src/__tests__/EntityMutator-MutationCacheConsistency-test.ts +16 -19
- package/src/__tests__/EntityMutator-test.ts +61 -67
- package/src/__tests__/EntitySecondaryCacheLoader-test.ts +11 -20
- package/src/__tests__/EntitySelfReferentialEdges-test.ts +47 -115
- package/src/__tests__/ReadonlyEntity-test.ts +13 -15
- package/src/__tests__/ViewerContext-test.ts +2 -3
- package/src/__tests__/cases/TwoEntitySameTableDisjointRows-test.ts +22 -33
- package/src/__tests__/cases/TwoEntitySameTableOverlappingRows-test.ts +22 -30
- 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 +12 -15
- package/src/testfixtures/TestEntity2.ts +8 -8
- package/src/testfixtures/TestViewerContext.ts +1 -12
|
@@ -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';
|
|
6
7
|
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 ViewerContext(companionProvider);
|
|
14
14
|
|
|
15
|
-
const entity1 = await OneTestEntity.creator(viewerContext
|
|
15
|
+
const entity1 = await OneTestEntity.creator(viewerContext)
|
|
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)
|
|
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)
|
|
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)
|
|
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 ViewerContext(companionProvider);
|
|
47
47
|
|
|
48
|
-
const entity = await TwoTestEntity.creator(viewerContext
|
|
48
|
+
const entity = await TwoTestEntity.creator(viewerContext)
|
|
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)
|
|
54
54
|
.enforcing()
|
|
55
55
|
.loadByFieldEqualingAsync('other_field', 'huh');
|
|
56
56
|
expect(loadedEntity?.getAllFields()).toMatchObject({
|
|
@@ -59,14 +59,12 @@ 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)
|
|
63
63
|
.enforcing()
|
|
64
64
|
.loadByIDAsync(entity.getID());
|
|
65
|
-
await OneTestEntity.updater(loaded1,
|
|
66
|
-
.setField('fake_field', 'world')
|
|
67
|
-
.enforceUpdateAsync();
|
|
65
|
+
await OneTestEntity.updater(loaded1).setField('fake_field', 'world').enforceUpdateAsync();
|
|
68
66
|
|
|
69
|
-
const loaded2 = await TwoTestEntity.loader(viewerContext
|
|
67
|
+
const loaded2 = await TwoTestEntity.loader(viewerContext)
|
|
70
68
|
.enforcing()
|
|
71
69
|
.loadByFieldEqualingAsync('other_field', 'huh');
|
|
72
70
|
expect(loaded2?.getAllFields()).toMatchObject({
|
|
@@ -75,7 +73,7 @@ describe('Two entities backed by the same table', () => {
|
|
|
75
73
|
other_field: 'huh',
|
|
76
74
|
});
|
|
77
75
|
|
|
78
|
-
const loaded22 = await TwoTestEntity.loader(viewerContext
|
|
76
|
+
const loaded22 = await TwoTestEntity.loader(viewerContext)
|
|
79
77
|
.enforcing()
|
|
80
78
|
.loadByFieldEqualingAsync('fake_field', 'world');
|
|
81
79
|
expect(loaded22?.getAllFields()).toMatchObject({
|
|
@@ -116,32 +114,26 @@ const testEntityConfiguration = new EntityConfiguration<TestFields>({
|
|
|
116
114
|
cacheAdapterFlavor: 'redis',
|
|
117
115
|
});
|
|
118
116
|
|
|
119
|
-
class TestEntityPrivacyPolicy extends EntityPrivacyPolicy<
|
|
120
|
-
any,
|
|
121
|
-
string,
|
|
122
|
-
TestViewerContext,
|
|
123
|
-
any,
|
|
124
|
-
any
|
|
125
|
-
> {
|
|
117
|
+
class TestEntityPrivacyPolicy extends EntityPrivacyPolicy<any, string, ViewerContext, any, any> {
|
|
126
118
|
protected override readonly readRules = [
|
|
127
|
-
new AlwaysAllowPrivacyPolicyRule<any, string,
|
|
119
|
+
new AlwaysAllowPrivacyPolicyRule<any, string, ViewerContext, any, any>(),
|
|
128
120
|
];
|
|
129
121
|
protected override readonly createRules = [
|
|
130
|
-
new AlwaysAllowPrivacyPolicyRule<any, string,
|
|
122
|
+
new AlwaysAllowPrivacyPolicyRule<any, string, ViewerContext, any, any>(),
|
|
131
123
|
];
|
|
132
124
|
protected override readonly updateRules = [
|
|
133
|
-
new AlwaysAllowPrivacyPolicyRule<any, string,
|
|
125
|
+
new AlwaysAllowPrivacyPolicyRule<any, string, ViewerContext, any, any>(),
|
|
134
126
|
];
|
|
135
127
|
protected override readonly deleteRules = [
|
|
136
|
-
new AlwaysAllowPrivacyPolicyRule<any, string,
|
|
128
|
+
new AlwaysAllowPrivacyPolicyRule<any, string, ViewerContext, any, any>(),
|
|
137
129
|
];
|
|
138
130
|
}
|
|
139
131
|
|
|
140
|
-
class OneTestEntity extends Entity<TestFields, string,
|
|
132
|
+
class OneTestEntity extends Entity<TestFields, string, ViewerContext, OneTestFields> {
|
|
141
133
|
static defineCompanionDefinition(): EntityCompanionDefinition<
|
|
142
134
|
TestFields,
|
|
143
135
|
string,
|
|
144
|
-
|
|
136
|
+
ViewerContext,
|
|
145
137
|
OneTestEntity,
|
|
146
138
|
TestEntityPrivacyPolicy,
|
|
147
139
|
OneTestFields
|
|
@@ -155,11 +147,11 @@ class OneTestEntity extends Entity<TestFields, string, TestViewerContext, OneTes
|
|
|
155
147
|
}
|
|
156
148
|
}
|
|
157
149
|
|
|
158
|
-
class TwoTestEntity extends Entity<TestFields, string,
|
|
150
|
+
class TwoTestEntity extends Entity<TestFields, string, ViewerContext, TwoTestFields> {
|
|
159
151
|
static defineCompanionDefinition(): EntityCompanionDefinition<
|
|
160
152
|
TestFields,
|
|
161
153
|
string,
|
|
162
|
-
|
|
154
|
+
ViewerContext,
|
|
163
155
|
TwoTestEntity,
|
|
164
156
|
TestEntityPrivacyPolicy,
|
|
165
157
|
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.getQueryContext(),
|
|
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.getQueryContext();
|
|
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.getQueryContext();
|
|
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.getQueryContext();
|
|
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.getQueryContext();
|
|
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.getQueryContext();
|
|
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.getQueryContext();
|
|
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.getQueryContext();
|
|
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.getQueryContext();
|
|
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.getQueryContext();
|
|
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.getQueryContext();
|
|
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.getQueryContext();
|
|
595
595
|
|
|
596
596
|
await expect(
|
|
597
597
|
entityDataManager.loadManyByFieldEqualingAsync(queryContext, 'nullableField', [null as any])
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import TestViewerContext from './TestViewerContext';
|
|
2
1
|
import Entity from '../Entity';
|
|
3
2
|
import { EntityCompanionDefinition } from '../EntityCompanionProvider';
|
|
4
3
|
import EntityConfiguration from '../EntityConfiguration';
|
|
5
4
|
import { UUIDField } from '../EntityFields';
|
|
6
5
|
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
|
+
ViewerContext,
|
|
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
|
+
ViewerContext,
|
|
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
|
+
ViewerContext,
|
|
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
|
+
ViewerContext,
|
|
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
|
+
ViewerContext,
|
|
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
|
+
ViewerContext,
|
|
76
76
|
SimpleTestFieldSelection
|
|
77
77
|
> {
|
|
78
78
|
static defineCompanionDefinition(): EntityCompanionDefinition<
|
|
79
79
|
SimpleTestFields,
|
|
80
80
|
string,
|
|
81
|
-
|
|
81
|
+
ViewerContext,
|
|
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';
|
|
4
3
|
import Entity from '../Entity';
|
|
5
4
|
import { EntityCompanionDefinition } from '../EntityCompanionProvider';
|
|
6
5
|
import EntityConfiguration from '../EntityConfiguration';
|
|
7
6
|
import { UUIDField, StringField, DateField, IntField } from '../EntityFields';
|
|
8
7
|
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
|
+
ViewerContext,
|
|
52
52
|
TestEntity
|
|
53
53
|
> {
|
|
54
54
|
protected override readonly readRules = [
|
|
55
|
-
new AlwaysAllowPrivacyPolicyRule<TestFields, string,
|
|
55
|
+
new AlwaysAllowPrivacyPolicyRule<TestFields, string, ViewerContext, TestEntity>(),
|
|
56
56
|
];
|
|
57
57
|
protected override readonly createRules = [
|
|
58
|
-
new AlwaysAllowPrivacyPolicyRule<TestFields, string,
|
|
58
|
+
new AlwaysAllowPrivacyPolicyRule<TestFields, string, ViewerContext, TestEntity>(),
|
|
59
59
|
];
|
|
60
60
|
protected override readonly updateRules = [
|
|
61
|
-
new AlwaysAllowPrivacyPolicyRule<TestFields, string,
|
|
61
|
+
new AlwaysAllowPrivacyPolicyRule<TestFields, string, ViewerContext, TestEntity>(),
|
|
62
62
|
];
|
|
63
63
|
protected override readonly deleteRules = [
|
|
64
|
-
new AlwaysAllowPrivacyPolicyRule<TestFields, string,
|
|
64
|
+
new AlwaysAllowPrivacyPolicyRule<TestFields, string, ViewerContext, 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, ViewerContext> {
|
|
69
69
|
static defineCompanionDefinition(): EntityCompanionDefinition<
|
|
70
70
|
TestFields,
|
|
71
71
|
string,
|
|
72
|
-
|
|
72
|
+
ViewerContext,
|
|
73
73
|
TestEntity,
|
|
74
74
|
TestEntityPrivacyPolicy
|
|
75
75
|
> {
|
|
@@ -84,10 +84,7 @@ export default class TestEntity extends Entity<TestFields, string, TestViewerCon
|
|
|
84
84
|
return 'Hello World!';
|
|
85
85
|
}
|
|
86
86
|
|
|
87
|
-
static async hello(
|
|
88
|
-
viewerContext: TestViewerContext,
|
|
89
|
-
testValue: string
|
|
90
|
-
): Promise<Result<TestEntity>> {
|
|
87
|
+
static async hello(viewerContext: ViewerContext, testValue: string): Promise<Result<TestEntity>> {
|
|
91
88
|
const fields = {
|
|
92
89
|
customIdField: testValue,
|
|
93
90
|
testIndexedField: 'hello',
|
|
@@ -106,15 +103,15 @@ export default class TestEntity extends Entity<TestFields, string, TestViewerCon
|
|
|
106
103
|
);
|
|
107
104
|
}
|
|
108
105
|
|
|
109
|
-
static async returnError(_viewerContext:
|
|
106
|
+
static async returnError(_viewerContext: ViewerContext): Promise<Result<TestEntity>> {
|
|
110
107
|
return result(new Error('return entity'));
|
|
111
108
|
}
|
|
112
109
|
|
|
113
|
-
static async throwError(_viewerContext:
|
|
110
|
+
static async throwError(_viewerContext: ViewerContext): Promise<Result<TestEntity>> {
|
|
114
111
|
throw new Error('threw entity');
|
|
115
112
|
}
|
|
116
113
|
|
|
117
|
-
static async nonResult(_viewerContext:
|
|
114
|
+
static async nonResult(_viewerContext: ViewerContext, testValue: string): Promise<string> {
|
|
118
115
|
return testValue;
|
|
119
116
|
}
|
|
120
117
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import TestViewerContext from './TestViewerContext';
|
|
2
1
|
import Entity from '../Entity';
|
|
3
2
|
import { EntityCompanionDefinition } from '../EntityCompanionProvider';
|
|
4
3
|
import EntityConfiguration from '../EntityConfiguration';
|
|
5
4
|
import { UUIDField } from '../EntityFields';
|
|
6
5
|
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
|
+
ViewerContext,
|
|
33
33
|
TestEntity2
|
|
34
34
|
> {
|
|
35
35
|
protected override readonly readRules = [
|
|
36
|
-
new AlwaysAllowPrivacyPolicyRule<Test2Fields, string,
|
|
36
|
+
new AlwaysAllowPrivacyPolicyRule<Test2Fields, string, ViewerContext, TestEntity2>(),
|
|
37
37
|
];
|
|
38
38
|
protected override readonly createRules = [
|
|
39
|
-
new AlwaysAllowPrivacyPolicyRule<Test2Fields, string,
|
|
39
|
+
new AlwaysAllowPrivacyPolicyRule<Test2Fields, string, ViewerContext, TestEntity2>(),
|
|
40
40
|
];
|
|
41
41
|
protected override readonly updateRules = [
|
|
42
|
-
new AlwaysAllowPrivacyPolicyRule<Test2Fields, string,
|
|
42
|
+
new AlwaysAllowPrivacyPolicyRule<Test2Fields, string, ViewerContext, TestEntity2>(),
|
|
43
43
|
];
|
|
44
44
|
protected override readonly deleteRules = [
|
|
45
|
-
new AlwaysAllowPrivacyPolicyRule<Test2Fields, string,
|
|
45
|
+
new AlwaysAllowPrivacyPolicyRule<Test2Fields, string, ViewerContext, 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, ViewerContext> {
|
|
50
50
|
static defineCompanionDefinition(): EntityCompanionDefinition<
|
|
51
51
|
Test2Fields,
|
|
52
52
|
string,
|
|
53
|
-
|
|
53
|
+
ViewerContext,
|
|
54
54
|
TestEntity2,
|
|
55
55
|
TestEntity2PrivacyPolicy
|
|
56
56
|
> {
|
|
@@ -1,14 +1,3 @@
|
|
|
1
|
-
import { EntityQueryContext, EntityTransactionalQueryContext } from '../EntityQueryContext';
|
|
2
1
|
import ViewerContext from '../ViewerContext';
|
|
3
2
|
|
|
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
|
-
}
|
|
3
|
+
export default class TestViewerContext extends ViewerContext {}
|