@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.
Files changed (82) hide show
  1. package/build/Entity.d.ts +6 -6
  2. package/build/Entity.js +29 -6
  3. package/build/Entity.js.map +1 -1
  4. package/build/EntityAssociationLoader.d.ts +8 -8
  5. package/build/EntityAssociationLoader.js +20 -4
  6. package/build/EntityAssociationLoader.js.map +1 -1
  7. package/build/EntityQueryContextProvider.d.ts +1 -1
  8. package/build/EntityQueryContextProvider.js +1 -1
  9. package/build/EntityQueryContextProvider.js.map +1 -1
  10. package/build/ReadonlyEntity.d.ts +1 -1
  11. package/build/ReadonlyEntity.js +4 -1
  12. package/build/ReadonlyEntity.js.map +1 -1
  13. package/build/ViewerContext.d.ts +2 -2
  14. package/build/ViewerContext.js +3 -3
  15. package/build/ViewerContext.js.map +1 -1
  16. package/build/__tests__/Entity-test.js +13 -13
  17. package/build/__tests__/Entity-test.js.map +1 -1
  18. package/build/__tests__/EntityAssociationLoader-test.js +37 -69
  19. package/build/__tests__/EntityAssociationLoader-test.js.map +1 -1
  20. package/build/__tests__/EntityCommonUseCases-test.js +11 -19
  21. package/build/__tests__/EntityCommonUseCases-test.js.map +1 -1
  22. package/build/__tests__/EntityEdges-test.js +40 -72
  23. package/build/__tests__/EntityEdges-test.js.map +1 -1
  24. package/build/__tests__/EntityLoader-constructor-test.js +1 -1
  25. package/build/__tests__/EntityLoader-constructor-test.js.map +1 -1
  26. package/build/__tests__/EntityLoader-test.js +19 -19
  27. package/build/__tests__/EntityLoader-test.js.map +1 -1
  28. package/build/__tests__/EntityMutator-MutationCacheConsistency-test.js +6 -6
  29. package/build/__tests__/EntityMutator-MutationCacheConsistency-test.js.map +1 -1
  30. package/build/__tests__/EntityMutator-test.js +20 -20
  31. package/build/__tests__/EntityMutator-test.js.map +1 -1
  32. package/build/__tests__/EntitySecondaryCacheLoader-test.js +10 -10
  33. package/build/__tests__/EntitySecondaryCacheLoader-test.js.map +1 -1
  34. package/build/__tests__/EntitySelfReferentialEdges-test.js +47 -79
  35. package/build/__tests__/EntitySelfReferentialEdges-test.js.map +1 -1
  36. package/build/__tests__/ReadonlyEntity-test.js +13 -13
  37. package/build/__tests__/ReadonlyEntity-test.js.map +1 -1
  38. package/build/__tests__/ViewerContext-test.js +2 -2
  39. package/build/__tests__/ViewerContext-test.js.map +1 -1
  40. package/build/__tests__/cases/TwoEntitySameTableDisjointRows-test.js +8 -12
  41. package/build/__tests__/cases/TwoEntitySameTableDisjointRows-test.js.map +1 -1
  42. package/build/__tests__/cases/TwoEntitySameTableOverlappingRows-test.js +13 -15
  43. package/build/__tests__/cases/TwoEntitySameTableOverlappingRows-test.js.map +1 -1
  44. package/build/internal/EntityDataManager.js +1 -1
  45. package/build/internal/EntityDataManager.js.map +1 -1
  46. package/build/internal/__tests__/EntityDataManager-test.js +11 -11
  47. package/build/internal/__tests__/EntityDataManager-test.js.map +1 -1
  48. package/build/testfixtures/SimpleTestEntity.d.ts +8 -8
  49. package/build/testfixtures/SimpleTestEntity.js.map +1 -1
  50. package/build/testfixtures/TestEntity.d.ts +12 -12
  51. package/build/testfixtures/TestEntity.js.map +1 -1
  52. package/build/testfixtures/TestEntity2.d.ts +8 -8
  53. package/build/testfixtures/TestEntity2.js.map +1 -1
  54. package/build/testfixtures/TestViewerContext.d.ts +0 -3
  55. package/build/testfixtures/TestViewerContext.js +0 -6
  56. package/build/testfixtures/TestViewerContext.js.map +1 -1
  57. package/package.json +2 -2
  58. package/src/Entity.ts +29 -6
  59. package/src/EntityAssociationLoader.ts +25 -9
  60. package/src/EntityQueryContextProvider.ts +1 -1
  61. package/src/ReadonlyEntity.ts +4 -1
  62. package/src/ViewerContext.ts +5 -5
  63. package/src/__tests__/Entity-test.ts +27 -43
  64. package/src/__tests__/EntityAssociationLoader-test.ts +86 -168
  65. package/src/__tests__/EntityCommonUseCases-test.ts +18 -36
  66. package/src/__tests__/EntityEdges-test.ts +40 -102
  67. package/src/__tests__/EntityLoader-constructor-test.ts +1 -1
  68. package/src/__tests__/EntityLoader-test.ts +19 -19
  69. package/src/__tests__/EntityMutator-MutationCacheConsistency-test.ts +16 -19
  70. package/src/__tests__/EntityMutator-test.ts +61 -67
  71. package/src/__tests__/EntitySecondaryCacheLoader-test.ts +11 -20
  72. package/src/__tests__/EntitySelfReferentialEdges-test.ts +47 -115
  73. package/src/__tests__/ReadonlyEntity-test.ts +13 -15
  74. package/src/__tests__/ViewerContext-test.ts +2 -3
  75. package/src/__tests__/cases/TwoEntitySameTableDisjointRows-test.ts +22 -33
  76. package/src/__tests__/cases/TwoEntitySameTableOverlappingRows-test.ts +22 -30
  77. package/src/internal/EntityDataManager.ts +1 -1
  78. package/src/internal/__tests__/EntityDataManager-test.ts +11 -11
  79. package/src/testfixtures/SimpleTestEntity.ts +8 -8
  80. package/src/testfixtures/TestEntity.ts +12 -15
  81. package/src/testfixtures/TestEntity2.ts +8 -8
  82. package/src/testfixtures/TestViewerContext.ts +1 -12
@@ -14,24 +14,20 @@ describe(EntityAssociationLoader, () => {
14
14
  const companionProvider = createUnitTestEntityCompanionProvider();
15
15
  const viewerContext = new TestViewerContext(companionProvider);
16
16
  const testOtherEntity = await enforceAsyncResult(
17
- TestEntity.creator(viewerContext, viewerContext.getQueryContext()).createAsync()
17
+ TestEntity.creator(viewerContext).createAsync()
18
18
  );
19
19
  const testEntity = await enforceAsyncResult(
20
- TestEntity.creator(viewerContext, viewerContext.getQueryContext())
20
+ TestEntity.creator(viewerContext)
21
21
  .setField('stringField', testOtherEntity.getID())
22
22
  .createAsync()
23
23
  );
24
24
  const loadedOther = await enforceAsyncResult(
25
- testEntity
26
- .associationLoader()
27
- .loadAssociatedEntityAsync('stringField', TestEntity, viewerContext.getQueryContext())
25
+ testEntity.associationLoader().loadAssociatedEntityAsync('stringField', TestEntity)
28
26
  );
29
27
  expect(loadedOther.getID()).toEqual(testOtherEntity.getID());
30
28
 
31
29
  const loadedOther2 = await enforceAsyncResult(
32
- testEntity
33
- .associationLoader()
34
- .loadAssociatedEntityAsync('nullableField', TestEntity, viewerContext.getQueryContext())
30
+ testEntity.associationLoader().loadAssociatedEntityAsync('nullableField', TestEntity)
35
31
  );
36
32
  expect(loadedOther2).toBeNull();
37
33
  });
@@ -41,27 +37,15 @@ describe(EntityAssociationLoader, () => {
41
37
  it('loads many associated entities referencing this entity', async () => {
42
38
  const companionProvider = createUnitTestEntityCompanionProvider();
43
39
  const viewerContext = new TestViewerContext(companionProvider);
44
- const testEntity = await enforceAsyncResult(
45
- TestEntity.creator(viewerContext, viewerContext.getQueryContext()).createAsync()
46
- );
40
+ const testEntity = await enforceAsyncResult(TestEntity.creator(viewerContext).createAsync());
47
41
  const testOtherEntity1 = await enforceAsyncResult(
48
- TestEntity.creator(viewerContext, viewerContext.getQueryContext())
49
- .setField('stringField', testEntity.getID())
50
- .createAsync()
42
+ TestEntity.creator(viewerContext).setField('stringField', testEntity.getID()).createAsync()
51
43
  );
52
44
  const testOtherEntity2 = await enforceAsyncResult(
53
- TestEntity.creator(viewerContext, viewerContext.getQueryContext())
54
- .setField('stringField', testEntity.getID())
55
- .createAsync()
45
+ TestEntity.creator(viewerContext).setField('stringField', testEntity.getID()).createAsync()
56
46
  );
57
47
  const loaded = await enforceResultsAsync(
58
- testEntity
59
- .associationLoader()
60
- .loadManyAssociatedEntitiesAsync(
61
- TestEntity,
62
- 'stringField',
63
- viewerContext.getQueryContext()
64
- )
48
+ testEntity.associationLoader().loadManyAssociatedEntitiesAsync(TestEntity, 'stringField')
65
49
  );
66
50
  expect(loaded).toHaveLength(2);
67
51
  expect(loaded.find((e) => e.getID() === testOtherEntity1.getID())).not.toBeUndefined();
@@ -74,21 +58,16 @@ describe(EntityAssociationLoader, () => {
74
58
  const companionProvider = createUnitTestEntityCompanionProvider();
75
59
  const viewerContext = new TestViewerContext(companionProvider);
76
60
  const testOtherEntity = await enforceAsyncResult(
77
- TestEntity.creator(viewerContext, viewerContext.getQueryContext()).createAsync()
61
+ TestEntity.creator(viewerContext).createAsync()
78
62
  );
79
63
  const testEntity = await enforceAsyncResult(
80
- TestEntity.creator(viewerContext, viewerContext.getQueryContext())
64
+ TestEntity.creator(viewerContext)
81
65
  .setField('stringField', testOtherEntity.getID())
82
66
  .createAsync()
83
67
  );
84
68
  const loadedOtherResult = await testEntity
85
69
  .associationLoader()
86
- .loadAssociatedEntityByFieldEqualingAsync(
87
- 'stringField',
88
- TestEntity,
89
- 'customIdField',
90
- viewerContext.getQueryContext()
91
- );
70
+ .loadAssociatedEntityByFieldEqualingAsync('stringField', TestEntity, 'customIdField');
92
71
  expect(loadedOtherResult?.enforceValue().getID()).toEqual(testOtherEntity.getID());
93
72
  });
94
73
 
@@ -96,18 +75,11 @@ describe(EntityAssociationLoader, () => {
96
75
  const companionProvider = createUnitTestEntityCompanionProvider();
97
76
  const viewerContext = new TestViewerContext(companionProvider);
98
77
  const testEntity = await enforceAsyncResult(
99
- TestEntity.creator(viewerContext, viewerContext.getQueryContext())
100
- .setField('stringField', uuidv4())
101
- .createAsync()
78
+ TestEntity.creator(viewerContext).setField('stringField', uuidv4()).createAsync()
102
79
  );
103
80
  const loadedOtherResult = await testEntity
104
81
  .associationLoader()
105
- .loadAssociatedEntityByFieldEqualingAsync(
106
- 'stringField',
107
- TestEntity,
108
- 'customIdField',
109
- viewerContext.getQueryContext()
110
- );
82
+ .loadAssociatedEntityByFieldEqualingAsync('stringField', TestEntity, 'customIdField');
111
83
  expect(loadedOtherResult).toBeNull();
112
84
  });
113
85
 
@@ -115,18 +87,11 @@ describe(EntityAssociationLoader, () => {
115
87
  const companionProvider = createUnitTestEntityCompanionProvider();
116
88
  const viewerContext = new TestViewerContext(companionProvider);
117
89
  const testEntity = await enforceAsyncResult(
118
- TestEntity.creator(viewerContext, viewerContext.getQueryContext())
119
- .setField('stringField', 'blah')
120
- .createAsync()
90
+ TestEntity.creator(viewerContext).setField('stringField', 'blah').createAsync()
121
91
  );
122
92
  const loadedOtherResult = await testEntity
123
93
  .associationLoader()
124
- .loadAssociatedEntityByFieldEqualingAsync(
125
- 'nullableField',
126
- TestEntity,
127
- 'customIdField',
128
- viewerContext.getQueryContext()
129
- );
94
+ .loadAssociatedEntityByFieldEqualingAsync('nullableField', TestEntity, 'customIdField');
130
95
  expect(loadedOtherResult).toBeNull();
131
96
  });
132
97
  });
@@ -135,18 +100,12 @@ describe(EntityAssociationLoader, () => {
135
100
  it('loads many associated entities by field equaling', async () => {
136
101
  const companionProvider = createUnitTestEntityCompanionProvider();
137
102
  const viewerContext = new TestViewerContext(companionProvider);
138
- const testEntity = await enforceAsyncResult(
139
- TestEntity.creator(viewerContext, viewerContext.getQueryContext()).createAsync()
140
- );
103
+ const testEntity = await enforceAsyncResult(TestEntity.creator(viewerContext).createAsync());
141
104
  const testOtherEntity1 = await enforceAsyncResult(
142
- TestEntity.creator(viewerContext, viewerContext.getQueryContext())
143
- .setField('stringField', testEntity.getID())
144
- .createAsync()
105
+ TestEntity.creator(viewerContext).setField('stringField', testEntity.getID()).createAsync()
145
106
  );
146
107
  const testOtherEntity2 = await enforceAsyncResult(
147
- TestEntity.creator(viewerContext, viewerContext.getQueryContext())
148
- .setField('stringField', testEntity.getID())
149
- .createAsync()
108
+ TestEntity.creator(viewerContext).setField('stringField', testEntity.getID()).createAsync()
150
109
  );
151
110
  const loaded = await enforceResultsAsync(
152
111
  testEntity
@@ -154,8 +113,7 @@ describe(EntityAssociationLoader, () => {
154
113
  .loadManyAssociatedEntitiesByFieldEqualingAsync(
155
114
  'customIdField',
156
115
  TestEntity,
157
- 'stringField',
158
- viewerContext.getQueryContext()
116
+ 'stringField'
159
117
  )
160
118
  );
161
119
  expect(loaded).toHaveLength(2);
@@ -166,17 +124,14 @@ describe(EntityAssociationLoader, () => {
166
124
  it('returns empty results when field being queried by is null', async () => {
167
125
  const companionProvider = createUnitTestEntityCompanionProvider();
168
126
  const viewerContext = new TestViewerContext(companionProvider);
169
- const testEntity = await enforceAsyncResult(
170
- TestEntity.creator(viewerContext, viewerContext.getQueryContext()).createAsync()
171
- );
127
+ const testEntity = await enforceAsyncResult(TestEntity.creator(viewerContext).createAsync());
172
128
  const loaded = await enforceResultsAsync(
173
129
  testEntity
174
130
  .associationLoader()
175
131
  .loadManyAssociatedEntitiesByFieldEqualingAsync(
176
132
  'nullableField',
177
133
  TestEntity,
178
- 'stringField',
179
- viewerContext.getQueryContext()
134
+ 'stringField'
180
135
  )
181
136
  );
182
137
  expect(loaded).toHaveLength(0);
@@ -187,68 +142,53 @@ describe(EntityAssociationLoader, () => {
187
142
  it('chain loads associated entities', async () => {
188
143
  const companionProvider = createUnitTestEntityCompanionProvider();
189
144
  const viewerContext = new TestViewerContext(companionProvider);
190
- const testEntity4 = await enforceAsyncResult(
191
- TestEntity.creator(viewerContext, viewerContext.getQueryContext()).createAsync()
192
- );
145
+ const testEntity4 = await enforceAsyncResult(TestEntity.creator(viewerContext).createAsync());
193
146
  const testEntity3 = await enforceAsyncResult(
194
- TestEntity2.creator(viewerContext, viewerContext.getQueryContext())
195
- .setField('foreignKey', testEntity4.getID())
196
- .createAsync()
147
+ TestEntity2.creator(viewerContext).setField('foreignKey', testEntity4.getID()).createAsync()
197
148
  );
198
149
  const testEntity2 = await enforceAsyncResult(
199
- TestEntity.creator(viewerContext, viewerContext.getQueryContext())
150
+ TestEntity.creator(viewerContext)
200
151
  .setField('testIndexedField', testEntity3.getID())
201
152
  .createAsync()
202
153
  );
203
154
  const testEntity = await enforceAsyncResult(
204
- TestEntity2.creator(viewerContext, viewerContext.getQueryContext())
205
- .setField('foreignKey', testEntity2.getID())
206
- .createAsync()
155
+ TestEntity2.creator(viewerContext).setField('foreignKey', testEntity2.getID()).createAsync()
207
156
  );
208
157
 
209
- const loaded2Result = await testEntity.associationLoader().loadAssociatedEntityThroughAsync(
210
- [
211
- {
212
- associatedEntityClass: TestEntity,
213
- fieldIdentifyingAssociatedEntity: 'foreignKey',
214
- },
215
- ],
216
- viewerContext.getQueryContext()
217
- );
158
+ const loaded2Result = await testEntity.associationLoader().loadAssociatedEntityThroughAsync([
159
+ {
160
+ associatedEntityClass: TestEntity,
161
+ fieldIdentifyingAssociatedEntity: 'foreignKey',
162
+ },
163
+ ]);
218
164
  expect(loaded2Result?.enforceValue().getID()).toEqual(testEntity2.getID());
219
165
 
220
- const loaded3Result = await testEntity.associationLoader().loadAssociatedEntityThroughAsync(
221
- [
222
- {
223
- associatedEntityClass: TestEntity,
224
- fieldIdentifyingAssociatedEntity: 'foreignKey',
225
- },
226
- {
227
- associatedEntityClass: TestEntity2,
228
- fieldIdentifyingAssociatedEntity: 'testIndexedField',
229
- },
230
- ],
231
- viewerContext.getQueryContext()
232
- );
166
+ const loaded3Result = await testEntity.associationLoader().loadAssociatedEntityThroughAsync([
167
+ {
168
+ associatedEntityClass: TestEntity,
169
+ fieldIdentifyingAssociatedEntity: 'foreignKey',
170
+ },
171
+ {
172
+ associatedEntityClass: TestEntity2,
173
+ fieldIdentifyingAssociatedEntity: 'testIndexedField',
174
+ },
175
+ ]);
233
176
  expect(loaded3Result?.enforceValue().getID()).toEqual(testEntity3.getID());
234
177
 
235
- const loaded4Result = await testEntity.associationLoader().loadAssociatedEntityThroughAsync(
236
- [
237
- {
238
- associatedEntityClass: TestEntity,
239
- fieldIdentifyingAssociatedEntity: 'foreignKey',
240
- },
241
- {
242
- associatedEntityClass: TestEntity2,
243
- fieldIdentifyingAssociatedEntity: 'testIndexedField',
244
- },
245
- {
246
- associatedEntityClass: TestEntity,
247
- fieldIdentifyingAssociatedEntity: 'foreignKey',
248
- },
249
- ],
250
- viewerContext.getQueryContext()
251
- );
178
+ const loaded4Result = await testEntity.associationLoader().loadAssociatedEntityThroughAsync([
179
+ {
180
+ associatedEntityClass: TestEntity,
181
+ fieldIdentifyingAssociatedEntity: 'foreignKey',
182
+ },
183
+ {
184
+ associatedEntityClass: TestEntity2,
185
+ fieldIdentifyingAssociatedEntity: 'testIndexedField',
186
+ },
187
+ {
188
+ associatedEntityClass: TestEntity,
189
+ fieldIdentifyingAssociatedEntity: 'foreignKey',
190
+ },
191
+ ]);
252
192
  expect(loaded4Result?.enforceValue().getID()).toEqual(testEntity4.getID());
253
193
  });
254
194
 
@@ -257,20 +197,15 @@ describe(EntityAssociationLoader, () => {
257
197
  const viewerContext = new TestViewerContext(companionProvider);
258
198
 
259
199
  const testEntity = await enforceAsyncResult(
260
- TestEntity2.creator(viewerContext, viewerContext.getQueryContext())
261
- .setField('foreignKey', uuidv4())
262
- .createAsync()
200
+ TestEntity2.creator(viewerContext).setField('foreignKey', uuidv4()).createAsync()
263
201
  );
264
202
 
265
- const loadResult = await testEntity.associationLoader().loadAssociatedEntityThroughAsync(
266
- [
267
- {
268
- associatedEntityClass: TestEntity,
269
- fieldIdentifyingAssociatedEntity: 'foreignKey',
270
- },
271
- ],
272
- viewerContext.getQueryContext()
273
- );
203
+ const loadResult = await testEntity.associationLoader().loadAssociatedEntityThroughAsync([
204
+ {
205
+ associatedEntityClass: TestEntity,
206
+ fieldIdentifyingAssociatedEntity: 'foreignKey',
207
+ },
208
+ ]);
274
209
  expect(loadResult?.ok).toBe(false);
275
210
  });
276
211
 
@@ -280,26 +215,19 @@ describe(EntityAssociationLoader, () => {
280
215
 
281
216
  const fieldValue = uuidv4();
282
217
  const testEntity2 = await enforceAsyncResult(
283
- TestEntity.creator(viewerContext, viewerContext.getQueryContext())
284
- .setField('stringField', fieldValue)
285
- .createAsync()
218
+ TestEntity.creator(viewerContext).setField('stringField', fieldValue).createAsync()
286
219
  );
287
220
  const testEntity = await enforceAsyncResult(
288
- TestEntity2.creator(viewerContext, viewerContext.getQueryContext())
289
- .setField('foreignKey', fieldValue)
290
- .createAsync()
221
+ TestEntity2.creator(viewerContext).setField('foreignKey', fieldValue).createAsync()
291
222
  );
292
223
 
293
- const loaded2Result = await testEntity.associationLoader().loadAssociatedEntityThroughAsync(
294
- [
295
- {
296
- associatedEntityClass: TestEntity,
297
- fieldIdentifyingAssociatedEntity: 'foreignKey',
298
- associatedEntityLookupByField: 'stringField',
299
- },
300
- ],
301
- viewerContext.getQueryContext()
302
- );
224
+ const loaded2Result = await testEntity.associationLoader().loadAssociatedEntityThroughAsync([
225
+ {
226
+ associatedEntityClass: TestEntity,
227
+ fieldIdentifyingAssociatedEntity: 'foreignKey',
228
+ associatedEntityLookupByField: 'stringField',
229
+ },
230
+ ]);
303
231
  expect(loaded2Result?.enforceValue().getID()).toEqual(testEntity2.getID());
304
232
  });
305
233
 
@@ -308,21 +236,16 @@ describe(EntityAssociationLoader, () => {
308
236
  const viewerContext = new TestViewerContext(companionProvider);
309
237
 
310
238
  const testEntity = await enforceAsyncResult(
311
- TestEntity2.creator(viewerContext, viewerContext.getQueryContext())
312
- .setField('foreignKey', uuidv4())
313
- .createAsync()
239
+ TestEntity2.creator(viewerContext).setField('foreignKey', uuidv4()).createAsync()
314
240
  );
315
241
 
316
- const loaded2Result = await testEntity.associationLoader().loadAssociatedEntityThroughAsync(
317
- [
318
- {
319
- associatedEntityClass: TestEntity,
320
- fieldIdentifyingAssociatedEntity: 'foreignKey',
321
- associatedEntityLookupByField: 'stringField',
322
- },
323
- ],
324
- viewerContext.getQueryContext()
325
- );
242
+ const loaded2Result = await testEntity.associationLoader().loadAssociatedEntityThroughAsync([
243
+ {
244
+ associatedEntityClass: TestEntity,
245
+ fieldIdentifyingAssociatedEntity: 'foreignKey',
246
+ associatedEntityLookupByField: 'stringField',
247
+ },
248
+ ]);
326
249
  expect(loaded2Result).toBeNull();
327
250
  });
328
251
 
@@ -331,20 +254,15 @@ describe(EntityAssociationLoader, () => {
331
254
  const viewerContext = new TestViewerContext(companionProvider);
332
255
 
333
256
  const testEntity = await enforceAsyncResult(
334
- TestEntity.creator(viewerContext, viewerContext.getQueryContext())
335
- .setField('nullableField', null)
336
- .createAsync()
257
+ TestEntity.creator(viewerContext).setField('nullableField', null).createAsync()
337
258
  );
338
259
 
339
- const loadedResult = await testEntity.associationLoader().loadAssociatedEntityThroughAsync(
340
- [
341
- {
342
- associatedEntityClass: TestEntity,
343
- fieldIdentifyingAssociatedEntity: 'nullableField',
344
- },
345
- ],
346
- viewerContext.getQueryContext()
347
- );
260
+ const loadedResult = await testEntity.associationLoader().loadAssociatedEntityThroughAsync([
261
+ {
262
+ associatedEntityClass: TestEntity,
263
+ fieldIdentifyingAssociatedEntity: 'nullableField',
264
+ },
265
+ ]);
348
266
  expect(loadedResult).toBeNull();
349
267
  });
350
268
  });
@@ -7,15 +7,15 @@ import EntityConfiguration from '../EntityConfiguration';
7
7
  import { UUIDField } from '../EntityFields';
8
8
  import EntityPrivacyPolicy, { EntityPrivacyPolicyEvaluationContext } from '../EntityPrivacyPolicy';
9
9
  import { EntityQueryContext } from '../EntityQueryContext';
10
+ import ViewerContext from '../ViewerContext';
10
11
  import { enforceResultsAsync } from '../entityUtils';
11
12
  import EntityNotAuthorizedError from '../errors/EntityNotAuthorizedError';
12
13
  import AlwaysAllowPrivacyPolicyRule from '../rules/AlwaysAllowPrivacyPolicyRule';
13
14
  import AlwaysDenyPrivacyPolicyRule from '../rules/AlwaysDenyPrivacyPolicyRule';
14
15
  import PrivacyPolicyRule, { RuleEvaluationResult } from '../rules/PrivacyPolicyRule';
15
- import TestViewerContext from '../testfixtures/TestViewerContext';
16
16
  import { createUnitTestEntityCompanionProvider } from '../utils/testing/createUnitTestEntityCompanionProvider';
17
17
 
18
- class TestUserViewerContext extends TestViewerContext {
18
+ class TestUserViewerContext extends ViewerContext {
19
19
  constructor(entityCompanionProvider: EntityCompanionProvider, private readonly userID: string) {
20
20
  super(entityCompanionProvider);
21
21
  }
@@ -82,23 +82,23 @@ class DenyIfNotOwnerPrivacyPolicyRule extends PrivacyPolicyRule<
82
82
  class BlahEntityPrivacyPolicy extends EntityPrivacyPolicy<
83
83
  BlahFields,
84
84
  string,
85
- TestUserViewerContext,
85
+ ViewerContext,
86
86
  BlahEntity
87
87
  > {
88
88
  protected override readonly createRules = [
89
89
  new DenyIfNotOwnerPrivacyPolicyRule(),
90
- new AlwaysAllowPrivacyPolicyRule<BlahFields, string, TestUserViewerContext, BlahEntity>(),
90
+ new AlwaysAllowPrivacyPolicyRule<BlahFields, string, ViewerContext, BlahEntity>(),
91
91
  ];
92
92
  protected override readonly readRules = [
93
93
  new DenyIfNotOwnerPrivacyPolicyRule(),
94
- new AlwaysAllowPrivacyPolicyRule<BlahFields, string, TestUserViewerContext, BlahEntity>(),
94
+ new AlwaysAllowPrivacyPolicyRule<BlahFields, string, ViewerContext, BlahEntity>(),
95
95
  ];
96
96
  protected override readonly updateRules = [
97
97
  new DenyIfNotOwnerPrivacyPolicyRule(),
98
- new AlwaysAllowPrivacyPolicyRule<BlahFields, string, TestUserViewerContext, BlahEntity>(),
98
+ new AlwaysAllowPrivacyPolicyRule<BlahFields, string, ViewerContext, BlahEntity>(),
99
99
  ];
100
100
  protected override readonly deleteRules = [
101
- new AlwaysDenyPrivacyPolicyRule<BlahFields, string, TestUserViewerContext, BlahEntity>(),
101
+ new AlwaysDenyPrivacyPolicyRule<BlahFields, string, ViewerContext, BlahEntity>(),
102
102
  ];
103
103
  }
104
104
 
@@ -110,21 +110,15 @@ it('runs through a common workflow', async () => {
110
110
  const vc2 = new TestUserViewerContext(entityCompanionProvider, uuidv4());
111
111
 
112
112
  const blahOwner1 = await enforceAsyncResult(
113
- BlahEntity.creator(vc1, vc1.getQueryContext())
114
- .setField('ownerID', vc1.getUserID()!)
115
- .createAsync()
113
+ BlahEntity.creator(vc1).setField('ownerID', vc1.getUserID()!).createAsync()
116
114
  );
117
115
 
118
116
  await enforceAsyncResult(
119
- BlahEntity.creator(vc1, vc1.getQueryContext())
120
- .setField('ownerID', vc1.getUserID()!)
121
- .createAsync()
117
+ BlahEntity.creator(vc1).setField('ownerID', vc1.getUserID()!).createAsync()
122
118
  );
123
119
 
124
120
  const blahOwner2 = await enforceAsyncResult(
125
- BlahEntity.creator(vc2, vc2.getQueryContext())
126
- .setField('ownerID', vc2.getUserID()!)
127
- .createAsync()
121
+ BlahEntity.creator(vc2).setField('ownerID', vc2.getUserID()!).createAsync()
128
122
  );
129
123
 
130
124
  // sanity check created objects
@@ -133,45 +127,33 @@ it('runs through a common workflow', async () => {
133
127
 
134
128
  // check that two people can't read each others data
135
129
  await expect(
136
- enforceAsyncResult(
137
- BlahEntity.loader(vc1, vc1.getQueryContext()).loadByIDAsync(blahOwner2.getID())
138
- )
130
+ enforceAsyncResult(BlahEntity.loader(vc1).loadByIDAsync(blahOwner2.getID()))
139
131
  ).rejects.toBeInstanceOf(EntityNotAuthorizedError);
140
132
  await expect(
141
- enforceAsyncResult(
142
- BlahEntity.loader(vc2, vc2.getQueryContext()).loadByIDAsync(blahOwner1.getID())
143
- )
133
+ enforceAsyncResult(BlahEntity.loader(vc2).loadByIDAsync(blahOwner1.getID()))
144
134
  ).rejects.toBeInstanceOf(EntityNotAuthorizedError);
145
135
 
146
136
  // check that all of owner 1's objects can be loaded
147
137
  const results = await enforceResultsAsync(
148
- BlahEntity.loader(vc1, vc1.getQueryContext()).loadManyByFieldEqualingAsync(
149
- 'ownerID',
150
- vc1.getUserID()!
151
- )
138
+ BlahEntity.loader(vc1).loadManyByFieldEqualingAsync('ownerID', vc1.getUserID()!)
152
139
  );
153
140
  expect(results).toHaveLength(2);
154
141
 
155
142
  // check that two people can't create objects owned by others
156
143
  await expect(
157
144
  enforceAsyncResult(
158
- BlahEntity.creator(vc2, vc2.getQueryContext())
159
- .setField('ownerID', blahOwner1.getID())
160
- .createAsync()
145
+ BlahEntity.creator(vc2).setField('ownerID', blahOwner1.getID()).createAsync()
161
146
  )
162
147
  ).rejects.toBeInstanceOf(EntityNotAuthorizedError);
163
148
 
164
149
  // check that empty load many returns nothing
165
- const results2 = await BlahEntity.loader(
166
- vc1,
167
- vc1.getQueryContext()
168
- ).loadManyByFieldEqualingManyAsync('ownerID', []);
150
+ const results2 = await BlahEntity.loader(vc1).loadManyByFieldEqualingManyAsync('ownerID', []);
169
151
  for (const value in results2.values) {
170
152
  expect(value).toHaveLength(0);
171
153
  }
172
154
 
173
155
  // check that the user can't delete their own data (as specified by privacy rules)
174
- await expect(
175
- enforceAsyncResult(BlahEntity.deleteAsync(blahOwner2, vc1.getQueryContext()))
176
- ).rejects.toBeInstanceOf(EntityNotAuthorizedError);
156
+ await expect(enforceAsyncResult(BlahEntity.deleteAsync(blahOwner2))).rejects.toBeInstanceOf(
157
+ EntityNotAuthorizedError
158
+ );
177
159
  });