@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
package/src/Entity.ts
CHANGED
|
@@ -61,7 +61,10 @@ export default abstract class Entity<
|
|
|
61
61
|
TMSelectedFields
|
|
62
62
|
>,
|
|
63
63
|
viewerContext: TMViewerContext2,
|
|
64
|
-
queryContext: EntityQueryContext
|
|
64
|
+
queryContext: EntityQueryContext = viewerContext
|
|
65
|
+
.getViewerScopedEntityCompanionForClass(this)
|
|
66
|
+
.getQueryContextProvider()
|
|
67
|
+
.getQueryContext()
|
|
65
68
|
): CreateMutator<TMFields, TMID, TMViewerContext, TMEntity, TMPrivacyPolicy, TMSelectedFields> {
|
|
66
69
|
return viewerContext
|
|
67
70
|
.getViewerScopedEntityCompanionForClass(this)
|
|
@@ -98,7 +101,11 @@ export default abstract class Entity<
|
|
|
98
101
|
TMSelectedFields
|
|
99
102
|
>,
|
|
100
103
|
existingEntity: TMEntity,
|
|
101
|
-
queryContext: EntityQueryContext
|
|
104
|
+
queryContext: EntityQueryContext = existingEntity
|
|
105
|
+
.getViewerContext()
|
|
106
|
+
.getViewerScopedEntityCompanionForClass(this)
|
|
107
|
+
.getQueryContextProvider()
|
|
108
|
+
.getQueryContext()
|
|
102
109
|
): UpdateMutator<TMFields, TMID, TMViewerContext, TMEntity, TMPrivacyPolicy, TMSelectedFields> {
|
|
103
110
|
return existingEntity
|
|
104
111
|
.getViewerContext()
|
|
@@ -135,7 +142,11 @@ export default abstract class Entity<
|
|
|
135
142
|
TMSelectedFields
|
|
136
143
|
>,
|
|
137
144
|
existingEntity: TMEntity,
|
|
138
|
-
queryContext: EntityQueryContext
|
|
145
|
+
queryContext: EntityQueryContext = existingEntity
|
|
146
|
+
.getViewerContext()
|
|
147
|
+
.getViewerScopedEntityCompanionForClass(this)
|
|
148
|
+
.getQueryContextProvider()
|
|
149
|
+
.getQueryContext()
|
|
139
150
|
): Promise<Result<void>> {
|
|
140
151
|
return existingEntity
|
|
141
152
|
.getViewerContext()
|
|
@@ -173,7 +184,11 @@ export default abstract class Entity<
|
|
|
173
184
|
TMSelectedFields
|
|
174
185
|
>,
|
|
175
186
|
existingEntity: TMEntity,
|
|
176
|
-
queryContext: EntityQueryContext
|
|
187
|
+
queryContext: EntityQueryContext = existingEntity
|
|
188
|
+
.getViewerContext()
|
|
189
|
+
.getViewerScopedEntityCompanionForClass(this)
|
|
190
|
+
.getQueryContextProvider()
|
|
191
|
+
.getQueryContext()
|
|
177
192
|
): Promise<void> {
|
|
178
193
|
return existingEntity
|
|
179
194
|
.getViewerContext()
|
|
@@ -222,7 +237,11 @@ export default abstract class Entity<
|
|
|
222
237
|
TMSelectedFields
|
|
223
238
|
>,
|
|
224
239
|
existingEntity: TMEntity,
|
|
225
|
-
queryContext: EntityQueryContext
|
|
240
|
+
queryContext: EntityQueryContext = existingEntity
|
|
241
|
+
.getViewerContext()
|
|
242
|
+
.getViewerScopedEntityCompanionForClass(this)
|
|
243
|
+
.getQueryContextProvider()
|
|
244
|
+
.getQueryContext()
|
|
226
245
|
): Promise<boolean> {
|
|
227
246
|
const companion = existingEntity
|
|
228
247
|
.getViewerContext()
|
|
@@ -272,7 +291,11 @@ export default abstract class Entity<
|
|
|
272
291
|
TMSelectedFields
|
|
273
292
|
>,
|
|
274
293
|
existingEntity: TMEntity,
|
|
275
|
-
queryContext: EntityQueryContext
|
|
294
|
+
queryContext: EntityQueryContext = existingEntity
|
|
295
|
+
.getViewerContext()
|
|
296
|
+
.getViewerScopedEntityCompanionForClass(this)
|
|
297
|
+
.getQueryContextProvider()
|
|
298
|
+
.getQueryContext()
|
|
276
299
|
): Promise<boolean> {
|
|
277
300
|
const companion = existingEntity
|
|
278
301
|
.getViewerContext()
|
|
@@ -55,7 +55,11 @@ export default class EntityAssociationLoader<
|
|
|
55
55
|
TAssociatedPrivacyPolicy,
|
|
56
56
|
TAssociatedSelectedFields
|
|
57
57
|
>,
|
|
58
|
-
queryContext: EntityQueryContext
|
|
58
|
+
queryContext: EntityQueryContext = this.entity
|
|
59
|
+
.getViewerContext()
|
|
60
|
+
.getViewerScopedEntityCompanionForClass(associatedEntityClass)
|
|
61
|
+
.getQueryContextProvider()
|
|
62
|
+
.getQueryContext()
|
|
59
63
|
): Promise<
|
|
60
64
|
Result<null extends TFields[TIdentifyingField] ? TAssociatedEntity | null : TAssociatedEntity>
|
|
61
65
|
> {
|
|
@@ -113,7 +117,11 @@ export default class EntityAssociationLoader<
|
|
|
113
117
|
TAssociatedSelectedFields
|
|
114
118
|
>,
|
|
115
119
|
associatedEntityFieldContainingThisID: keyof Pick<TAssociatedFields, TAssociatedSelectedFields>,
|
|
116
|
-
queryContext: EntityQueryContext
|
|
120
|
+
queryContext: EntityQueryContext = this.entity
|
|
121
|
+
.getViewerContext()
|
|
122
|
+
.getViewerScopedEntityCompanionForClass(associatedEntityClass)
|
|
123
|
+
.getQueryContextProvider()
|
|
124
|
+
.getQueryContext()
|
|
117
125
|
): Promise<readonly Result<TAssociatedEntity>[]> {
|
|
118
126
|
const thisID = this.entity.getID();
|
|
119
127
|
const loader = this.entity
|
|
@@ -163,7 +171,11 @@ export default class EntityAssociationLoader<
|
|
|
163
171
|
TAssociatedSelectedFields
|
|
164
172
|
>,
|
|
165
173
|
associatedEntityLookupByField: keyof Pick<TAssociatedFields, TAssociatedSelectedFields>,
|
|
166
|
-
queryContext: EntityQueryContext
|
|
174
|
+
queryContext: EntityQueryContext = this.entity
|
|
175
|
+
.getViewerContext()
|
|
176
|
+
.getViewerScopedEntityCompanionForClass(associatedEntityClass)
|
|
177
|
+
.getQueryContextProvider()
|
|
178
|
+
.getQueryContext()
|
|
167
179
|
): Promise<Result<TAssociatedEntity> | null> {
|
|
168
180
|
const associatedFieldValue = this.entity.getField(fieldIdentifyingAssociatedEntity);
|
|
169
181
|
if (!associatedFieldValue) {
|
|
@@ -216,7 +228,11 @@ export default class EntityAssociationLoader<
|
|
|
216
228
|
TAssociatedSelectedFields
|
|
217
229
|
>,
|
|
218
230
|
associatedEntityLookupByField: keyof Pick<TAssociatedFields, TAssociatedSelectedFields>,
|
|
219
|
-
queryContext: EntityQueryContext
|
|
231
|
+
queryContext: EntityQueryContext = this.entity
|
|
232
|
+
.getViewerContext()
|
|
233
|
+
.getViewerScopedEntityCompanionForClass(associatedEntityClass)
|
|
234
|
+
.getQueryContextProvider()
|
|
235
|
+
.getQueryContext()
|
|
220
236
|
): Promise<readonly Result<TAssociatedEntity>[]> {
|
|
221
237
|
const associatedFieldValue = this.entity.getField(fieldIdentifyingAssociatedEntity);
|
|
222
238
|
if (!associatedFieldValue) {
|
|
@@ -265,7 +281,7 @@ export default class EntityAssociationLoader<
|
|
|
265
281
|
TSelectedFields2
|
|
266
282
|
>
|
|
267
283
|
],
|
|
268
|
-
queryContext
|
|
284
|
+
queryContext?: EntityQueryContext
|
|
269
285
|
): Promise<Result<TEntity2> | null>;
|
|
270
286
|
|
|
271
287
|
/**
|
|
@@ -320,7 +336,7 @@ export default class EntityAssociationLoader<
|
|
|
320
336
|
TSelectedFields3
|
|
321
337
|
>
|
|
322
338
|
],
|
|
323
|
-
queryContext
|
|
339
|
+
queryContext?: EntityQueryContext
|
|
324
340
|
): Promise<Result<TEntity3> | null>;
|
|
325
341
|
|
|
326
342
|
/**
|
|
@@ -396,7 +412,7 @@ export default class EntityAssociationLoader<
|
|
|
396
412
|
TSelectedFields4
|
|
397
413
|
>
|
|
398
414
|
],
|
|
399
|
-
queryContext
|
|
415
|
+
queryContext?: EntityQueryContext
|
|
400
416
|
): Promise<Result<TEntity4> | null>;
|
|
401
417
|
|
|
402
418
|
/**
|
|
@@ -407,12 +423,12 @@ export default class EntityAssociationLoader<
|
|
|
407
423
|
*/
|
|
408
424
|
async loadAssociatedEntityThroughAsync(
|
|
409
425
|
loadDirectives: EntityLoadThroughDirective<TViewerContext, any, any, any, any, any, any, any>[],
|
|
410
|
-
queryContext
|
|
426
|
+
queryContext?: EntityQueryContext
|
|
411
427
|
): Promise<Result<ReadonlyEntity<any, any, any, any>> | null>;
|
|
412
428
|
|
|
413
429
|
async loadAssociatedEntityThroughAsync(
|
|
414
430
|
loadDirectives: EntityLoadThroughDirective<TViewerContext, any, any, any, any, any, any, any>[],
|
|
415
|
-
queryContext
|
|
431
|
+
queryContext?: EntityQueryContext
|
|
416
432
|
): Promise<Result<ReadonlyEntity<any, any, any, any>> | null> {
|
|
417
433
|
let currentEntity: ReadonlyEntity<any, any, any, any> = this.entity;
|
|
418
434
|
for (const loadDirective of loadDirectives) {
|
|
@@ -12,7 +12,7 @@ export default abstract class EntityQueryContextProvider {
|
|
|
12
12
|
/**
|
|
13
13
|
* Vend a regular (non-transactional) entity query context.
|
|
14
14
|
*/
|
|
15
|
-
public
|
|
15
|
+
public getQueryContext(): EntityNonTransactionalQueryContext {
|
|
16
16
|
return new EntityNonTransactionalQueryContext(this.getQueryInterface(), this);
|
|
17
17
|
}
|
|
18
18
|
|
package/src/ReadonlyEntity.ts
CHANGED
|
@@ -148,7 +148,10 @@ export default abstract class ReadonlyEntity<
|
|
|
148
148
|
TMSelectedFields
|
|
149
149
|
>,
|
|
150
150
|
viewerContext: TMViewerContext2,
|
|
151
|
-
queryContext: EntityQueryContext
|
|
151
|
+
queryContext: EntityQueryContext = viewerContext
|
|
152
|
+
.getViewerScopedEntityCompanionForClass(this)
|
|
153
|
+
.getQueryContextProvider()
|
|
154
|
+
.getQueryContext()
|
|
152
155
|
): EntityLoader<TMFields, TMID, TMViewerContext, TMEntity, TMPrivacyPolicy, TMSelectedFields> {
|
|
153
156
|
return viewerContext
|
|
154
157
|
.getViewerScopedEntityCompanionForClass(this)
|
package/src/ViewerContext.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { IEntityClass } from './Entity';
|
|
|
2
2
|
import EntityCompanionProvider, { DatabaseAdapterFlavor } from './EntityCompanionProvider';
|
|
3
3
|
import EntityPrivacyPolicy from './EntityPrivacyPolicy';
|
|
4
4
|
import {
|
|
5
|
-
|
|
5
|
+
EntityQueryContext,
|
|
6
6
|
EntityTransactionalQueryContext,
|
|
7
7
|
TransactionConfig,
|
|
8
8
|
} from './EntityQueryContext';
|
|
@@ -67,12 +67,12 @@ export default class ViewerContext {
|
|
|
67
67
|
* Get the regular (non-transactional) query context for a database adaptor flavor.
|
|
68
68
|
* @param databaseAdaptorFlavor - database adaptor flavor
|
|
69
69
|
*/
|
|
70
|
-
|
|
70
|
+
getQueryContextForDatabaseAdaptorFlavor(
|
|
71
71
|
databaseAdaptorFlavor: DatabaseAdapterFlavor
|
|
72
|
-
):
|
|
72
|
+
): EntityQueryContext {
|
|
73
73
|
return this.entityCompanionProvider
|
|
74
74
|
.getQueryContextProviderForDatabaseAdaptorFlavor(databaseAdaptorFlavor)
|
|
75
|
-
.
|
|
75
|
+
.getQueryContext();
|
|
76
76
|
}
|
|
77
77
|
|
|
78
78
|
/**
|
|
@@ -88,7 +88,7 @@ export default class ViewerContext {
|
|
|
88
88
|
): Promise<TResult> {
|
|
89
89
|
return await this.entityCompanionProvider
|
|
90
90
|
.getQueryContextProviderForDatabaseAdaptorFlavor(databaseAdaptorFlavor)
|
|
91
|
-
.
|
|
91
|
+
.getQueryContext()
|
|
92
92
|
.runInTransactionIfNotInTransactionAsync(transactionScope, transactionConfig);
|
|
93
93
|
}
|
|
94
94
|
}
|
|
@@ -4,27 +4,25 @@ import EntityConfiguration from '../EntityConfiguration';
|
|
|
4
4
|
import { UUIDField } from '../EntityFields';
|
|
5
5
|
import { CreateMutator, UpdateMutator } from '../EntityMutator';
|
|
6
6
|
import EntityPrivacyPolicy from '../EntityPrivacyPolicy';
|
|
7
|
+
import ViewerContext from '../ViewerContext';
|
|
7
8
|
import AlwaysAllowPrivacyPolicyRule from '../rules/AlwaysAllowPrivacyPolicyRule';
|
|
8
9
|
import AlwaysDenyPrivacyPolicyRule from '../rules/AlwaysDenyPrivacyPolicyRule';
|
|
9
10
|
import SimpleTestEntity from '../testfixtures/SimpleTestEntity';
|
|
10
|
-
import TestViewerContext from '../testfixtures/TestViewerContext';
|
|
11
11
|
import { createUnitTestEntityCompanionProvider } from '../utils/testing/createUnitTestEntityCompanionProvider';
|
|
12
12
|
|
|
13
13
|
describe(Entity, () => {
|
|
14
14
|
describe('creator', () => {
|
|
15
15
|
it('creates a new CreateMutator', () => {
|
|
16
16
|
const companionProvider = createUnitTestEntityCompanionProvider();
|
|
17
|
-
const viewerContext = new
|
|
18
|
-
expect(
|
|
19
|
-
SimpleTestEntity.creator(viewerContext, viewerContext.getQueryContext())
|
|
20
|
-
).toBeInstanceOf(CreateMutator);
|
|
17
|
+
const viewerContext = new ViewerContext(companionProvider);
|
|
18
|
+
expect(SimpleTestEntity.creator(viewerContext)).toBeInstanceOf(CreateMutator);
|
|
21
19
|
});
|
|
22
20
|
});
|
|
23
21
|
|
|
24
22
|
describe('updater', () => {
|
|
25
23
|
it('creates a new UpdateMutator', () => {
|
|
26
24
|
const companionProvider = createUnitTestEntityCompanionProvider();
|
|
27
|
-
const viewerContext = new
|
|
25
|
+
const viewerContext = new ViewerContext(companionProvider);
|
|
28
26
|
const data = {
|
|
29
27
|
id: 'what',
|
|
30
28
|
};
|
|
@@ -34,16 +32,14 @@ describe(Entity, () => {
|
|
|
34
32
|
databaseFields: data,
|
|
35
33
|
selectedFields: data,
|
|
36
34
|
});
|
|
37
|
-
expect(SimpleTestEntity.updater(testEntity
|
|
38
|
-
UpdateMutator
|
|
39
|
-
);
|
|
35
|
+
expect(SimpleTestEntity.updater(testEntity)).toBeInstanceOf(UpdateMutator);
|
|
40
36
|
});
|
|
41
37
|
});
|
|
42
38
|
|
|
43
39
|
describe('canViewerUpdateAsync', () => {
|
|
44
40
|
it('appropriately executes update privacy policy', async () => {
|
|
45
41
|
const companionProvider = createUnitTestEntityCompanionProvider();
|
|
46
|
-
const viewerContext = new
|
|
42
|
+
const viewerContext = new ViewerContext(companionProvider);
|
|
47
43
|
const data = {
|
|
48
44
|
id: 'what',
|
|
49
45
|
};
|
|
@@ -53,16 +49,13 @@ describe(Entity, () => {
|
|
|
53
49
|
databaseFields: data,
|
|
54
50
|
selectedFields: data,
|
|
55
51
|
});
|
|
56
|
-
const canViewerUpdate = await SimpleTestDenyDeleteEntity.canViewerUpdateAsync(
|
|
57
|
-
testEntity,
|
|
58
|
-
viewerContext.getQueryContext()
|
|
59
|
-
);
|
|
52
|
+
const canViewerUpdate = await SimpleTestDenyDeleteEntity.canViewerUpdateAsync(testEntity);
|
|
60
53
|
expect(canViewerUpdate).toBe(true);
|
|
61
54
|
});
|
|
62
55
|
|
|
63
56
|
it('denies when policy denies', async () => {
|
|
64
57
|
const companionProvider = createUnitTestEntityCompanionProvider();
|
|
65
|
-
const viewerContext = new
|
|
58
|
+
const viewerContext = new ViewerContext(companionProvider);
|
|
66
59
|
const data = {
|
|
67
60
|
id: 'what',
|
|
68
61
|
};
|
|
@@ -72,10 +65,7 @@ describe(Entity, () => {
|
|
|
72
65
|
databaseFields: data,
|
|
73
66
|
selectedFields: data,
|
|
74
67
|
});
|
|
75
|
-
const canViewerUpdate = await SimpleTestDenyUpdateEntity.canViewerUpdateAsync(
|
|
76
|
-
testEntity,
|
|
77
|
-
viewerContext.getQueryContext()
|
|
78
|
-
);
|
|
68
|
+
const canViewerUpdate = await SimpleTestDenyUpdateEntity.canViewerUpdateAsync(testEntity);
|
|
79
69
|
expect(canViewerUpdate).toBe(false);
|
|
80
70
|
});
|
|
81
71
|
});
|
|
@@ -83,7 +73,7 @@ describe(Entity, () => {
|
|
|
83
73
|
describe('canViewerDeleteAsync', () => {
|
|
84
74
|
it('appropriately executes update privacy policy', async () => {
|
|
85
75
|
const companionProvider = createUnitTestEntityCompanionProvider();
|
|
86
|
-
const viewerContext = new
|
|
76
|
+
const viewerContext = new ViewerContext(companionProvider);
|
|
87
77
|
const data = {
|
|
88
78
|
id: 'what',
|
|
89
79
|
};
|
|
@@ -93,16 +83,13 @@ describe(Entity, () => {
|
|
|
93
83
|
databaseFields: data,
|
|
94
84
|
selectedFields: data,
|
|
95
85
|
});
|
|
96
|
-
const canViewerDelete = await SimpleTestDenyUpdateEntity.canViewerDeleteAsync(
|
|
97
|
-
testEntity,
|
|
98
|
-
viewerContext.getQueryContext()
|
|
99
|
-
);
|
|
86
|
+
const canViewerDelete = await SimpleTestDenyUpdateEntity.canViewerDeleteAsync(testEntity);
|
|
100
87
|
expect(canViewerDelete).toBe(true);
|
|
101
88
|
});
|
|
102
89
|
|
|
103
90
|
it('denies when policy denies', async () => {
|
|
104
91
|
const companionProvider = createUnitTestEntityCompanionProvider();
|
|
105
|
-
const viewerContext = new
|
|
92
|
+
const viewerContext = new ViewerContext(companionProvider);
|
|
106
93
|
const data = {
|
|
107
94
|
id: 'what',
|
|
108
95
|
};
|
|
@@ -112,10 +99,7 @@ describe(Entity, () => {
|
|
|
112
99
|
databaseFields: data,
|
|
113
100
|
selectedFields: data,
|
|
114
101
|
});
|
|
115
|
-
const canViewerDelete = await SimpleTestDenyDeleteEntity.canViewerDeleteAsync(
|
|
116
|
-
testEntity,
|
|
117
|
-
viewerContext.getQueryContext()
|
|
118
|
-
);
|
|
102
|
+
const canViewerDelete = await SimpleTestDenyDeleteEntity.canViewerDeleteAsync(testEntity);
|
|
119
103
|
expect(canViewerDelete).toBe(false);
|
|
120
104
|
});
|
|
121
105
|
});
|
|
@@ -140,14 +124,14 @@ const testEntityConfiguration = new EntityConfiguration<TestEntityFields>({
|
|
|
140
124
|
class SimpleTestDenyUpdateEntityPrivacyPolicy extends EntityPrivacyPolicy<
|
|
141
125
|
TestEntityFields,
|
|
142
126
|
string,
|
|
143
|
-
|
|
127
|
+
ViewerContext,
|
|
144
128
|
SimpleTestDenyUpdateEntity
|
|
145
129
|
> {
|
|
146
130
|
protected override readonly readRules = [
|
|
147
131
|
new AlwaysAllowPrivacyPolicyRule<
|
|
148
132
|
TestEntityFields,
|
|
149
133
|
string,
|
|
150
|
-
|
|
134
|
+
ViewerContext,
|
|
151
135
|
SimpleTestDenyUpdateEntity
|
|
152
136
|
>(),
|
|
153
137
|
];
|
|
@@ -155,7 +139,7 @@ class SimpleTestDenyUpdateEntityPrivacyPolicy extends EntityPrivacyPolicy<
|
|
|
155
139
|
new AlwaysAllowPrivacyPolicyRule<
|
|
156
140
|
TestEntityFields,
|
|
157
141
|
string,
|
|
158
|
-
|
|
142
|
+
ViewerContext,
|
|
159
143
|
SimpleTestDenyUpdateEntity
|
|
160
144
|
>(),
|
|
161
145
|
];
|
|
@@ -163,7 +147,7 @@ class SimpleTestDenyUpdateEntityPrivacyPolicy extends EntityPrivacyPolicy<
|
|
|
163
147
|
new AlwaysDenyPrivacyPolicyRule<
|
|
164
148
|
TestEntityFields,
|
|
165
149
|
string,
|
|
166
|
-
|
|
150
|
+
ViewerContext,
|
|
167
151
|
SimpleTestDenyUpdateEntity
|
|
168
152
|
>(),
|
|
169
153
|
];
|
|
@@ -171,7 +155,7 @@ class SimpleTestDenyUpdateEntityPrivacyPolicy extends EntityPrivacyPolicy<
|
|
|
171
155
|
new AlwaysAllowPrivacyPolicyRule<
|
|
172
156
|
TestEntityFields,
|
|
173
157
|
string,
|
|
174
|
-
|
|
158
|
+
ViewerContext,
|
|
175
159
|
SimpleTestDenyUpdateEntity
|
|
176
160
|
>(),
|
|
177
161
|
];
|
|
@@ -180,14 +164,14 @@ class SimpleTestDenyUpdateEntityPrivacyPolicy extends EntityPrivacyPolicy<
|
|
|
180
164
|
class SimpleTestDenyDeleteEntityPrivacyPolicy extends EntityPrivacyPolicy<
|
|
181
165
|
TestEntityFields,
|
|
182
166
|
string,
|
|
183
|
-
|
|
167
|
+
ViewerContext,
|
|
184
168
|
SimpleTestDenyDeleteEntity
|
|
185
169
|
> {
|
|
186
170
|
protected override readonly readRules = [
|
|
187
171
|
new AlwaysAllowPrivacyPolicyRule<
|
|
188
172
|
TestEntityFields,
|
|
189
173
|
string,
|
|
190
|
-
|
|
174
|
+
ViewerContext,
|
|
191
175
|
SimpleTestDenyDeleteEntity
|
|
192
176
|
>(),
|
|
193
177
|
];
|
|
@@ -195,7 +179,7 @@ class SimpleTestDenyDeleteEntityPrivacyPolicy extends EntityPrivacyPolicy<
|
|
|
195
179
|
new AlwaysAllowPrivacyPolicyRule<
|
|
196
180
|
TestEntityFields,
|
|
197
181
|
string,
|
|
198
|
-
|
|
182
|
+
ViewerContext,
|
|
199
183
|
SimpleTestDenyDeleteEntity
|
|
200
184
|
>(),
|
|
201
185
|
];
|
|
@@ -203,7 +187,7 @@ class SimpleTestDenyDeleteEntityPrivacyPolicy extends EntityPrivacyPolicy<
|
|
|
203
187
|
new AlwaysAllowPrivacyPolicyRule<
|
|
204
188
|
TestEntityFields,
|
|
205
189
|
string,
|
|
206
|
-
|
|
190
|
+
ViewerContext,
|
|
207
191
|
SimpleTestDenyDeleteEntity
|
|
208
192
|
>(),
|
|
209
193
|
];
|
|
@@ -211,17 +195,17 @@ class SimpleTestDenyDeleteEntityPrivacyPolicy extends EntityPrivacyPolicy<
|
|
|
211
195
|
new AlwaysDenyPrivacyPolicyRule<
|
|
212
196
|
TestEntityFields,
|
|
213
197
|
string,
|
|
214
|
-
|
|
198
|
+
ViewerContext,
|
|
215
199
|
SimpleTestDenyDeleteEntity
|
|
216
200
|
>(),
|
|
217
201
|
];
|
|
218
202
|
}
|
|
219
203
|
|
|
220
|
-
class SimpleTestDenyUpdateEntity extends Entity<TestEntityFields, string,
|
|
204
|
+
class SimpleTestDenyUpdateEntity extends Entity<TestEntityFields, string, ViewerContext> {
|
|
221
205
|
static defineCompanionDefinition(): EntityCompanionDefinition<
|
|
222
206
|
TestEntityFields,
|
|
223
207
|
string,
|
|
224
|
-
|
|
208
|
+
ViewerContext,
|
|
225
209
|
SimpleTestDenyUpdateEntity,
|
|
226
210
|
SimpleTestDenyUpdateEntityPrivacyPolicy
|
|
227
211
|
> {
|
|
@@ -233,11 +217,11 @@ class SimpleTestDenyUpdateEntity extends Entity<TestEntityFields, string, TestVi
|
|
|
233
217
|
}
|
|
234
218
|
}
|
|
235
219
|
|
|
236
|
-
class SimpleTestDenyDeleteEntity extends Entity<TestEntityFields, string,
|
|
220
|
+
class SimpleTestDenyDeleteEntity extends Entity<TestEntityFields, string, ViewerContext> {
|
|
237
221
|
static defineCompanionDefinition(): EntityCompanionDefinition<
|
|
238
222
|
TestEntityFields,
|
|
239
223
|
string,
|
|
240
|
-
|
|
224
|
+
ViewerContext,
|
|
241
225
|
SimpleTestDenyDeleteEntity,
|
|
242
226
|
SimpleTestDenyDeleteEntityPrivacyPolicy
|
|
243
227
|
> {
|