@expo/entity 0.55.0 → 0.57.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/src/AuthorizationResultBasedEntityAssociationLoader.d.ts +1 -1
- package/build/src/AuthorizationResultBasedEntityAssociationLoader.js.map +1 -1
- package/build/src/AuthorizationResultBasedEntityLoader.d.ts +18 -24
- package/build/src/AuthorizationResultBasedEntityLoader.js +37 -56
- package/build/src/AuthorizationResultBasedEntityLoader.js.map +1 -1
- package/build/src/AuthorizationResultBasedEntityMutator.js +26 -19
- package/build/src/AuthorizationResultBasedEntityMutator.js.map +1 -1
- package/build/src/EnforcingEntityCreator.d.ts +1 -1
- package/build/src/EnforcingEntityCreator.js +1 -1
- package/build/src/EnforcingEntityLoader.d.ts +1 -58
- package/build/src/EnforcingEntityLoader.js +0 -65
- package/build/src/EnforcingEntityLoader.js.map +1 -1
- package/build/src/Entity.d.ts +6 -0
- package/build/src/Entity.js +6 -0
- package/build/src/Entity.js.map +1 -1
- package/build/src/EntityCompanion.d.ts +2 -2
- package/build/src/EntityCompanion.js.map +1 -1
- package/build/src/EntityCompanionProvider.d.ts +1 -1
- package/build/src/EntityCompanionProvider.js +4 -4
- package/build/src/EntityConfiguration.d.ts +1 -1
- package/build/src/EntityConfiguration.js +1 -2
- package/build/src/EntityConfiguration.js.map +1 -1
- package/build/src/{EntityLoaderUtils.d.ts → EntityConstructionUtils.d.ts} +15 -29
- package/build/src/EntityConstructionUtils.js +118 -0
- package/build/src/EntityConstructionUtils.js.map +1 -0
- package/build/src/EntityDatabaseAdapter.d.ts +10 -108
- package/build/src/EntityDatabaseAdapter.js +14 -76
- package/build/src/EntityDatabaseAdapter.js.map +1 -1
- package/build/src/EntityFieldDefinition.d.ts +1 -1
- package/build/src/EntityInvalidationUtils.d.ts +41 -0
- package/build/src/EntityInvalidationUtils.js +71 -0
- package/build/src/EntityInvalidationUtils.js.map +1 -0
- package/build/src/EntityLoader.d.ts +0 -6
- package/build/src/EntityLoader.js +0 -7
- package/build/src/EntityLoader.js.map +1 -1
- package/build/src/EntityLoaderFactory.d.ts +4 -0
- package/build/src/EntityLoaderFactory.js +10 -3
- package/build/src/EntityLoaderFactory.js.map +1 -1
- package/build/src/EntityPrivacyPolicy.d.ts +27 -0
- package/build/src/EntityPrivacyPolicy.js +22 -1
- package/build/src/EntityPrivacyPolicy.js.map +1 -1
- package/build/src/EntitySecondaryCacheLoader.d.ts +14 -3
- package/build/src/EntitySecondaryCacheLoader.js +21 -4
- package/build/src/EntitySecondaryCacheLoader.js.map +1 -1
- package/build/src/ReadonlyEntity.d.ts +4 -5
- package/build/src/ReadonlyEntity.js +7 -8
- package/build/src/ReadonlyEntity.js.map +1 -1
- package/build/src/ViewerContext.d.ts +6 -6
- package/build/src/ViewerContext.js +8 -8
- package/build/src/ViewerScopedEntityCompanion.d.ts +1 -1
- package/build/src/ViewerScopedEntityCompanion.js.map +1 -1
- package/build/src/ViewerScopedEntityLoaderFactory.d.ts +4 -0
- package/build/src/ViewerScopedEntityLoaderFactory.js +6 -0
- package/build/src/ViewerScopedEntityLoaderFactory.js.map +1 -1
- package/build/src/errors/EntityDatabaseAdapterError.d.ts +4 -0
- package/build/src/errors/EntityDatabaseAdapterError.js +13 -1
- package/build/src/errors/EntityDatabaseAdapterError.js.map +1 -1
- package/build/src/errors/EntityError.d.ts +2 -1
- package/build/src/errors/EntityError.js +1 -0
- package/build/src/errors/EntityError.js.map +1 -1
- package/build/src/index.d.ts +2 -1
- package/build/src/index.js +2 -1
- package/build/src/index.js.map +1 -1
- package/build/src/internal/EntityDataManager.d.ts +8 -16
- package/build/src/internal/EntityDataManager.js +8 -18
- package/build/src/internal/EntityDataManager.js.map +1 -1
- package/build/src/internal/EntityFieldTransformationUtils.js.map +1 -1
- package/build/src/internal/EntityLoadInterfaces.d.ts +2 -0
- package/build/src/internal/EntityLoadInterfaces.js +2 -0
- package/build/src/internal/EntityLoadInterfaces.js.map +1 -1
- package/build/src/internal/EntityTableDataCoordinator.d.ts +2 -0
- package/build/src/internal/EntityTableDataCoordinator.js +4 -0
- package/build/src/internal/EntityTableDataCoordinator.js.map +1 -1
- package/build/src/metrics/EntityMetricsUtils.d.ts +1 -0
- package/build/src/metrics/EntityMetricsUtils.js +15 -1
- package/build/src/metrics/EntityMetricsUtils.js.map +1 -1
- package/build/src/metrics/IEntityMetricsAdapter.d.ts +4 -1
- package/build/src/metrics/IEntityMetricsAdapter.js +3 -0
- package/build/src/metrics/IEntityMetricsAdapter.js.map +1 -1
- package/build/src/rules/AllowIfAllSubRulesAllowPrivacyPolicyRule.d.ts +2 -2
- package/build/src/rules/AllowIfAnySubRuleAllowsPrivacyPolicyRule.d.ts +2 -2
- package/build/src/rules/EvaluateIfEntityFieldPredicatePrivacyPolicyRule.d.ts +2 -2
- package/build/src/rules/PrivacyPolicyRule.d.ts +2 -2
- package/build/src/utils/EntityPrivacyUtils.js +11 -20
- package/build/src/utils/EntityPrivacyUtils.js.map +1 -1
- package/build/src/utils/collections/maps.d.ts +2 -2
- package/build/src/utils/collections/maps.js +2 -2
- package/package.json +4 -4
- package/src/AuthorizationResultBasedEntityAssociationLoader.ts +4 -7
- package/src/AuthorizationResultBasedEntityLoader.ts +58 -88
- package/src/AuthorizationResultBasedEntityMutator.ts +35 -20
- package/src/EnforcingEntityCreator.ts +1 -1
- package/src/EnforcingEntityLoader.ts +1 -95
- package/src/Entity.ts +6 -0
- package/src/EntityCompanion.ts +2 -2
- package/src/EntityCompanionProvider.ts +4 -4
- package/src/EntityConfiguration.ts +8 -5
- package/src/EntityConstructionUtils.ts +168 -0
- package/src/EntityDatabaseAdapter.ts +32 -222
- package/src/EntityFieldDefinition.ts +1 -1
- package/src/{EntityLoaderUtils.ts → EntityInvalidationUtils.ts} +5 -96
- package/src/EntityLoader.ts +0 -16
- package/src/EntityLoaderFactory.ts +50 -10
- package/src/EntityPrivacyPolicy.ts +44 -1
- package/src/EntitySecondaryCacheLoader.ts +54 -3
- package/src/ReadonlyEntity.ts +9 -11
- package/src/ViewerContext.ts +10 -10
- package/src/ViewerScopedEntityCompanion.ts +1 -1
- package/src/ViewerScopedEntityLoaderFactory.ts +37 -0
- package/src/__tests__/AuthorizationResultBasedEntityLoader-constructor-test.ts +3 -5
- package/src/__tests__/AuthorizationResultBasedEntityLoader-test.ts +34 -419
- package/src/__tests__/ComposedCacheAdapter-test.ts +3 -3
- package/src/__tests__/EnforcingEntityLoader-test.ts +2 -134
- package/src/__tests__/EntityCompanion-test.ts +18 -0
- package/src/__tests__/EntityConfiguration-test.ts +4 -4
- package/src/__tests__/EntityDatabaseAdapter-test.ts +33 -68
- package/src/__tests__/EntityEdges-test.ts +10 -10
- package/src/__tests__/EntityLoader-test.ts +6 -4
- package/src/__tests__/EntityMutator-test.ts +27 -15
- package/src/__tests__/EntityPrivacyPolicy-test.ts +102 -0
- package/src/__tests__/EntityQueryContext-test.ts +11 -11
- package/src/__tests__/EntitySecondaryCacheLoader-test.ts +10 -5
- package/src/__tests__/EntitySelfReferentialEdges-test.ts +6 -6
- package/src/__tests__/GenericEntityCacheAdapter-test.ts +18 -15
- package/src/__tests__/GenericSecondaryEntityCache-test.ts +27 -5
- package/src/__tests__/ReadonlyEntity-test.ts +6 -4
- package/src/__tests__/ViewerContext-test.ts +4 -4
- package/src/__tests__/ViewerScopedEntityCompanion-test.ts +1 -0
- package/src/__tests__/cases/TwoEntitySameTableDisjointRows-test.ts +0 -17
- package/src/errors/EntityDatabaseAdapterError.ts +14 -0
- package/src/errors/EntityError.ts +1 -0
- package/src/errors/__tests__/EntityDatabaseAdapterError-test.ts +9 -0
- package/src/errors/__tests__/EntityError-test.ts +13 -5
- package/src/index.ts +2 -1
- package/src/internal/EntityDataManager.ts +19 -54
- package/src/internal/EntityFieldTransformationUtils.ts +5 -5
- package/src/internal/EntityLoadInterfaces.ts +2 -0
- package/src/internal/EntityTableDataCoordinator.ts +2 -2
- package/src/internal/__tests__/CompositeFieldHolder-test.ts +8 -2
- package/src/internal/__tests__/EntityDataManager-test.ts +71 -202
- package/src/internal/__tests__/ReadThroughEntityCache-test.ts +39 -24
- package/src/metrics/EntityMetricsUtils.ts +23 -0
- package/src/metrics/IEntityMetricsAdapter.ts +3 -0
- package/src/metrics/__tests__/EntityMetricsUtils-test.ts +120 -0
- package/src/rules/AllowIfAllSubRulesAllowPrivacyPolicyRule.ts +2 -2
- package/src/rules/AllowIfAnySubRuleAllowsPrivacyPolicyRule.ts +2 -2
- package/src/rules/EvaluateIfEntityFieldPredicatePrivacyPolicyRule.ts +2 -2
- package/src/rules/PrivacyPolicyRule.ts +2 -2
- package/src/rules/__tests__/AllowIfAllSubRulesAllowPrivacyPolicyRule-test.ts +4 -4
- package/src/rules/__tests__/AllowIfAnySubRuleAllowsPrivacyPolicyRule-test.ts +4 -4
- package/src/rules/__tests__/AllowIfInParentCascadeDeletionPrivacyPolicyRule-test.ts +11 -1
- package/src/rules/__tests__/AlwaysAllowPrivacyPolicyRule-test.ts +2 -2
- package/src/rules/__tests__/AlwaysDenyPrivacyPolicyRule-test.ts +2 -2
- package/src/rules/__tests__/AlwaysSkipPrivacyPolicyRule-test.ts +2 -2
- package/src/rules/__tests__/EvaluateIfEntityFieldPredicatePrivacyPolicyRule-test.ts +3 -3
- package/src/utils/EntityPrivacyUtils.ts +18 -29
- package/src/utils/__testfixtures__/PrivacyPolicyRuleTestUtils.ts +2 -2
- package/src/utils/__testfixtures__/StubDatabaseAdapter.ts +13 -101
- package/src/utils/__tests__/EntityCreationUtils-test.ts +6 -6
- package/src/utils/__tests__/EntityPrivacyUtils-test.ts +2 -2
- package/src/utils/collections/maps.ts +2 -2
- package/build/src/EntityLoaderUtils.js +0 -147
- package/build/src/EntityLoaderUtils.js.map +0 -1
|
@@ -4,8 +4,8 @@ import { anyOfClass, anything, instance, mock, spy, verify, when } from 'ts-mock
|
|
|
4
4
|
import { v4 as uuidv4 } from 'uuid';
|
|
5
5
|
|
|
6
6
|
import { AuthorizationResultBasedEntityLoader } from '../AuthorizationResultBasedEntityLoader';
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
7
|
+
import { EntityConstructionUtils } from '../EntityConstructionUtils';
|
|
8
|
+
import { EntityInvalidationUtils } from '../EntityInvalidationUtils';
|
|
9
9
|
import { EntityPrivacyPolicyEvaluationContext } from '../EntityPrivacyPolicy';
|
|
10
10
|
import { ViewerContext } from '../ViewerContext';
|
|
11
11
|
import { enforceResultsAsync } from '../entityUtils';
|
|
@@ -90,7 +90,7 @@ describe(AuthorizationResultBasedEntityLoader, () => {
|
|
|
90
90
|
instance(mock<IEntityMetricsAdapter>()),
|
|
91
91
|
TestEntity.name,
|
|
92
92
|
);
|
|
93
|
-
const
|
|
93
|
+
const constructionUtils = new EntityConstructionUtils(
|
|
94
94
|
viewerContext,
|
|
95
95
|
queryContext,
|
|
96
96
|
privacyPolicyEvaluationContext,
|
|
@@ -98,7 +98,6 @@ describe(AuthorizationResultBasedEntityLoader, () => {
|
|
|
98
98
|
TestEntity,
|
|
99
99
|
/* entitySelectedFields */ undefined,
|
|
100
100
|
privacyPolicy,
|
|
101
|
-
dataManager,
|
|
102
101
|
metricsAdapter,
|
|
103
102
|
);
|
|
104
103
|
const entityLoader = new AuthorizationResultBasedEntityLoader(
|
|
@@ -106,8 +105,7 @@ describe(AuthorizationResultBasedEntityLoader, () => {
|
|
|
106
105
|
testEntityConfiguration,
|
|
107
106
|
TestEntity,
|
|
108
107
|
dataManager,
|
|
109
|
-
|
|
110
|
-
utils,
|
|
108
|
+
constructionUtils,
|
|
111
109
|
);
|
|
112
110
|
|
|
113
111
|
const entity = await enforceAsyncResult(entityLoader.loadByIDAsync(id1));
|
|
@@ -234,7 +232,7 @@ describe(AuthorizationResultBasedEntityLoader, () => {
|
|
|
234
232
|
instance(mock<IEntityMetricsAdapter>()),
|
|
235
233
|
TestEntity.name,
|
|
236
234
|
);
|
|
237
|
-
const
|
|
235
|
+
const constructionUtils = new EntityConstructionUtils(
|
|
238
236
|
viewerContext,
|
|
239
237
|
queryContext,
|
|
240
238
|
privacyPolicyEvaluationContext,
|
|
@@ -242,7 +240,6 @@ describe(AuthorizationResultBasedEntityLoader, () => {
|
|
|
242
240
|
TestEntity,
|
|
243
241
|
/* entitySelectedFields */ undefined,
|
|
244
242
|
privacyPolicy,
|
|
245
|
-
dataManager,
|
|
246
243
|
metricsAdapter,
|
|
247
244
|
);
|
|
248
245
|
const entityLoader = new AuthorizationResultBasedEntityLoader(
|
|
@@ -250,8 +247,7 @@ describe(AuthorizationResultBasedEntityLoader, () => {
|
|
|
250
247
|
testEntityConfiguration,
|
|
251
248
|
TestEntity,
|
|
252
249
|
dataManager,
|
|
253
|
-
|
|
254
|
-
utils,
|
|
250
|
+
constructionUtils,
|
|
255
251
|
);
|
|
256
252
|
|
|
257
253
|
const entities = await enforceResultsAsync(
|
|
@@ -322,311 +318,6 @@ describe(AuthorizationResultBasedEntityLoader, () => {
|
|
|
322
318
|
).toEqual([id3]);
|
|
323
319
|
});
|
|
324
320
|
|
|
325
|
-
it('loads entities with loadManyByFieldEqualityConjunction', async () => {
|
|
326
|
-
const privacyPolicy = new TestEntityPrivacyPolicy();
|
|
327
|
-
const spiedPrivacyPolicy = spy(privacyPolicy);
|
|
328
|
-
const viewerContext = instance(mock(ViewerContext));
|
|
329
|
-
const privacyPolicyEvaluationContext =
|
|
330
|
-
instance(
|
|
331
|
-
mock<
|
|
332
|
-
EntityPrivacyPolicyEvaluationContext<
|
|
333
|
-
TestFields,
|
|
334
|
-
'customIdField',
|
|
335
|
-
ViewerContext,
|
|
336
|
-
TestEntity
|
|
337
|
-
>
|
|
338
|
-
>(),
|
|
339
|
-
);
|
|
340
|
-
const metricsAdapter = instance(mock<IEntityMetricsAdapter>());
|
|
341
|
-
const queryContext = new StubQueryContextProvider().getQueryContext();
|
|
342
|
-
|
|
343
|
-
const id1 = uuidv4();
|
|
344
|
-
const id2 = uuidv4();
|
|
345
|
-
const id3 = uuidv4();
|
|
346
|
-
const databaseAdapter = new StubDatabaseAdapter<TestFields, 'customIdField'>(
|
|
347
|
-
testEntityConfiguration,
|
|
348
|
-
StubDatabaseAdapter.convertFieldObjectsToDataStore(
|
|
349
|
-
testEntityConfiguration,
|
|
350
|
-
new Map([
|
|
351
|
-
[
|
|
352
|
-
testEntityConfiguration.tableName,
|
|
353
|
-
[
|
|
354
|
-
{
|
|
355
|
-
customIdField: id1,
|
|
356
|
-
stringField: 'huh',
|
|
357
|
-
intField: 4,
|
|
358
|
-
testIndexedField: '4',
|
|
359
|
-
dateField: new Date(),
|
|
360
|
-
nullableField: null,
|
|
361
|
-
},
|
|
362
|
-
{
|
|
363
|
-
customIdField: id2,
|
|
364
|
-
stringField: 'huh',
|
|
365
|
-
intField: 4,
|
|
366
|
-
testIndexedField: '5',
|
|
367
|
-
dateField: new Date(),
|
|
368
|
-
nullableField: null,
|
|
369
|
-
},
|
|
370
|
-
{
|
|
371
|
-
customIdField: id3,
|
|
372
|
-
stringField: 'huh2',
|
|
373
|
-
intField: 4,
|
|
374
|
-
testIndexedField: '6',
|
|
375
|
-
dateField: new Date(),
|
|
376
|
-
nullableField: null,
|
|
377
|
-
},
|
|
378
|
-
],
|
|
379
|
-
],
|
|
380
|
-
]),
|
|
381
|
-
),
|
|
382
|
-
);
|
|
383
|
-
const cacheAdapterProvider = new NoCacheStubCacheAdapterProvider();
|
|
384
|
-
const cacheAdapter = cacheAdapterProvider.getCacheAdapter(testEntityConfiguration);
|
|
385
|
-
const entityCache = new ReadThroughEntityCache(testEntityConfiguration, cacheAdapter);
|
|
386
|
-
const dataManager = new EntityDataManager(
|
|
387
|
-
databaseAdapter,
|
|
388
|
-
entityCache,
|
|
389
|
-
new StubQueryContextProvider(),
|
|
390
|
-
instance(mock<IEntityMetricsAdapter>()),
|
|
391
|
-
TestEntity.name,
|
|
392
|
-
);
|
|
393
|
-
const utils = new EntityLoaderUtils(
|
|
394
|
-
viewerContext,
|
|
395
|
-
queryContext,
|
|
396
|
-
privacyPolicyEvaluationContext,
|
|
397
|
-
testEntityConfiguration,
|
|
398
|
-
TestEntity,
|
|
399
|
-
/* entitySelectedFields */ undefined,
|
|
400
|
-
privacyPolicy,
|
|
401
|
-
dataManager,
|
|
402
|
-
metricsAdapter,
|
|
403
|
-
);
|
|
404
|
-
const entityLoader = new AuthorizationResultBasedEntityLoader(
|
|
405
|
-
queryContext,
|
|
406
|
-
testEntityConfiguration,
|
|
407
|
-
TestEntity,
|
|
408
|
-
dataManager,
|
|
409
|
-
metricsAdapter,
|
|
410
|
-
utils,
|
|
411
|
-
);
|
|
412
|
-
const entityResults = await enforceResultsAsync(
|
|
413
|
-
entityLoader.loadManyByFieldEqualityConjunctionAsync([
|
|
414
|
-
{
|
|
415
|
-
fieldName: 'stringField',
|
|
416
|
-
fieldValue: 'huh',
|
|
417
|
-
},
|
|
418
|
-
{
|
|
419
|
-
fieldName: 'intField',
|
|
420
|
-
fieldValues: [4],
|
|
421
|
-
},
|
|
422
|
-
]),
|
|
423
|
-
);
|
|
424
|
-
expect(entityResults).toHaveLength(2);
|
|
425
|
-
verify(
|
|
426
|
-
spiedPrivacyPolicy.authorizeReadAsync(
|
|
427
|
-
viewerContext,
|
|
428
|
-
queryContext,
|
|
429
|
-
privacyPolicyEvaluationContext,
|
|
430
|
-
anyOfClass(TestEntity),
|
|
431
|
-
anything(),
|
|
432
|
-
),
|
|
433
|
-
).twice();
|
|
434
|
-
|
|
435
|
-
await expect(
|
|
436
|
-
entityLoader.loadManyByFieldEqualityConjunctionAsync([
|
|
437
|
-
{ fieldName: 'customIdField', fieldValue: 'not-a-uuid' },
|
|
438
|
-
]),
|
|
439
|
-
).rejects.toThrow('Entity field not valid: TestEntity (customIdField = not-a-uuid)');
|
|
440
|
-
});
|
|
441
|
-
|
|
442
|
-
it('loads entities with loadFirstByFieldEqualityConjunction', async () => {
|
|
443
|
-
const privacyPolicy = new TestEntityPrivacyPolicy();
|
|
444
|
-
const spiedPrivacyPolicy = spy(privacyPolicy);
|
|
445
|
-
const viewerContext = instance(mock(ViewerContext));
|
|
446
|
-
const privacyPolicyEvaluationContext =
|
|
447
|
-
instance(
|
|
448
|
-
mock<
|
|
449
|
-
EntityPrivacyPolicyEvaluationContext<
|
|
450
|
-
TestFields,
|
|
451
|
-
'customIdField',
|
|
452
|
-
ViewerContext,
|
|
453
|
-
TestEntity
|
|
454
|
-
>
|
|
455
|
-
>(),
|
|
456
|
-
);
|
|
457
|
-
const metricsAdapter = instance(mock<IEntityMetricsAdapter>());
|
|
458
|
-
const queryContext = new StubQueryContextProvider().getQueryContext();
|
|
459
|
-
|
|
460
|
-
const id1 = uuidv4();
|
|
461
|
-
const id2 = uuidv4();
|
|
462
|
-
const id3 = uuidv4();
|
|
463
|
-
const databaseAdapter = new StubDatabaseAdapter<TestFields, 'customIdField'>(
|
|
464
|
-
testEntityConfiguration,
|
|
465
|
-
StubDatabaseAdapter.convertFieldObjectsToDataStore(
|
|
466
|
-
testEntityConfiguration,
|
|
467
|
-
new Map([
|
|
468
|
-
[
|
|
469
|
-
testEntityConfiguration.tableName,
|
|
470
|
-
[
|
|
471
|
-
{
|
|
472
|
-
customIdField: id1,
|
|
473
|
-
stringField: 'huh',
|
|
474
|
-
intField: 4,
|
|
475
|
-
testIndexedField: '4',
|
|
476
|
-
dateField: new Date(),
|
|
477
|
-
nullableField: null,
|
|
478
|
-
},
|
|
479
|
-
{
|
|
480
|
-
customIdField: id2,
|
|
481
|
-
stringField: 'huh',
|
|
482
|
-
intField: 4,
|
|
483
|
-
testIndexedField: '5',
|
|
484
|
-
dateField: new Date(),
|
|
485
|
-
nullableField: null,
|
|
486
|
-
},
|
|
487
|
-
{
|
|
488
|
-
customIdField: id3,
|
|
489
|
-
stringField: 'huh2',
|
|
490
|
-
intField: 4,
|
|
491
|
-
testIndexedField: '6',
|
|
492
|
-
dateField: new Date(),
|
|
493
|
-
nullableField: null,
|
|
494
|
-
},
|
|
495
|
-
],
|
|
496
|
-
],
|
|
497
|
-
]),
|
|
498
|
-
),
|
|
499
|
-
);
|
|
500
|
-
const cacheAdapterProvider = new NoCacheStubCacheAdapterProvider();
|
|
501
|
-
const cacheAdapter = cacheAdapterProvider.getCacheAdapter(testEntityConfiguration);
|
|
502
|
-
const entityCache = new ReadThroughEntityCache(testEntityConfiguration, cacheAdapter);
|
|
503
|
-
const dataManager = new EntityDataManager(
|
|
504
|
-
databaseAdapter,
|
|
505
|
-
entityCache,
|
|
506
|
-
new StubQueryContextProvider(),
|
|
507
|
-
instance(mock<IEntityMetricsAdapter>()),
|
|
508
|
-
TestEntity.name,
|
|
509
|
-
);
|
|
510
|
-
const utils = new EntityLoaderUtils(
|
|
511
|
-
viewerContext,
|
|
512
|
-
queryContext,
|
|
513
|
-
privacyPolicyEvaluationContext,
|
|
514
|
-
testEntityConfiguration,
|
|
515
|
-
TestEntity,
|
|
516
|
-
/* entitySelectedFields */ undefined,
|
|
517
|
-
privacyPolicy,
|
|
518
|
-
dataManager,
|
|
519
|
-
metricsAdapter,
|
|
520
|
-
);
|
|
521
|
-
const entityLoader = new AuthorizationResultBasedEntityLoader(
|
|
522
|
-
queryContext,
|
|
523
|
-
testEntityConfiguration,
|
|
524
|
-
TestEntity,
|
|
525
|
-
dataManager,
|
|
526
|
-
metricsAdapter,
|
|
527
|
-
utils,
|
|
528
|
-
);
|
|
529
|
-
const result = await entityLoader.loadFirstByFieldEqualityConjunctionAsync(
|
|
530
|
-
[
|
|
531
|
-
{
|
|
532
|
-
fieldName: 'stringField',
|
|
533
|
-
fieldValue: 'huh',
|
|
534
|
-
},
|
|
535
|
-
{
|
|
536
|
-
fieldName: 'intField',
|
|
537
|
-
fieldValue: 4,
|
|
538
|
-
},
|
|
539
|
-
],
|
|
540
|
-
{ orderBy: [{ fieldName: 'testIndexedField', order: OrderByOrdering.DESCENDING }] },
|
|
541
|
-
);
|
|
542
|
-
expect(result).not.toBeNull();
|
|
543
|
-
expect(result!.ok).toBe(true);
|
|
544
|
-
expect(result!.enforceValue().getField('testIndexedField')).toEqual('5');
|
|
545
|
-
verify(
|
|
546
|
-
spiedPrivacyPolicy.authorizeReadAsync(
|
|
547
|
-
viewerContext,
|
|
548
|
-
queryContext,
|
|
549
|
-
privacyPolicyEvaluationContext,
|
|
550
|
-
anyOfClass(TestEntity),
|
|
551
|
-
anything(),
|
|
552
|
-
),
|
|
553
|
-
).once();
|
|
554
|
-
});
|
|
555
|
-
|
|
556
|
-
it('loads entities with loadManyByRawWhereClauseAsync', async () => {
|
|
557
|
-
const privacyPolicy = new TestEntityPrivacyPolicy();
|
|
558
|
-
const spiedPrivacyPolicy = spy(privacyPolicy);
|
|
559
|
-
const viewerContext = instance(mock(ViewerContext));
|
|
560
|
-
const privacyPolicyEvaluationContext =
|
|
561
|
-
instance(
|
|
562
|
-
mock<
|
|
563
|
-
EntityPrivacyPolicyEvaluationContext<
|
|
564
|
-
TestFields,
|
|
565
|
-
'customIdField',
|
|
566
|
-
ViewerContext,
|
|
567
|
-
TestEntity
|
|
568
|
-
>
|
|
569
|
-
>(),
|
|
570
|
-
);
|
|
571
|
-
const metricsAdapter = instance(mock<IEntityMetricsAdapter>());
|
|
572
|
-
const queryContext = new StubQueryContextProvider().getQueryContext();
|
|
573
|
-
|
|
574
|
-
const dataManagerMock = mock<EntityDataManager<TestFields, 'customIdField'>>(EntityDataManager);
|
|
575
|
-
when(
|
|
576
|
-
dataManagerMock.loadManyByRawWhereClauseAsync(
|
|
577
|
-
queryContext,
|
|
578
|
-
anything(),
|
|
579
|
-
anything(),
|
|
580
|
-
anything(),
|
|
581
|
-
),
|
|
582
|
-
).thenResolve([
|
|
583
|
-
{
|
|
584
|
-
customIdField: 'id',
|
|
585
|
-
stringField: 'huh',
|
|
586
|
-
intField: 4,
|
|
587
|
-
testIndexedField: '4',
|
|
588
|
-
dateField: new Date(),
|
|
589
|
-
nullableField: null,
|
|
590
|
-
},
|
|
591
|
-
]);
|
|
592
|
-
const dataManager = instance(dataManagerMock);
|
|
593
|
-
const utils = new EntityLoaderUtils(
|
|
594
|
-
viewerContext,
|
|
595
|
-
queryContext,
|
|
596
|
-
privacyPolicyEvaluationContext,
|
|
597
|
-
testEntityConfiguration,
|
|
598
|
-
TestEntity,
|
|
599
|
-
/* entitySelectedFields */ undefined,
|
|
600
|
-
privacyPolicy,
|
|
601
|
-
dataManager,
|
|
602
|
-
metricsAdapter,
|
|
603
|
-
);
|
|
604
|
-
const entityLoader = new AuthorizationResultBasedEntityLoader(
|
|
605
|
-
queryContext,
|
|
606
|
-
testEntityConfiguration,
|
|
607
|
-
TestEntity,
|
|
608
|
-
dataManager,
|
|
609
|
-
metricsAdapter,
|
|
610
|
-
utils,
|
|
611
|
-
);
|
|
612
|
-
const result = await entityLoader.loadManyByRawWhereClauseAsync('id = ?', [1], {
|
|
613
|
-
orderBy: [{ fieldName: 'testIndexedField', order: OrderByOrdering.DESCENDING }],
|
|
614
|
-
});
|
|
615
|
-
expect(result).toHaveLength(1);
|
|
616
|
-
expect(result[0]).not.toBeNull();
|
|
617
|
-
expect(result[0]!.ok).toBe(true);
|
|
618
|
-
expect(result[0]!.enforceValue().getField('testIndexedField')).toEqual('4');
|
|
619
|
-
verify(
|
|
620
|
-
spiedPrivacyPolicy.authorizeReadAsync(
|
|
621
|
-
viewerContext,
|
|
622
|
-
queryContext,
|
|
623
|
-
privacyPolicyEvaluationContext,
|
|
624
|
-
anyOfClass(TestEntity),
|
|
625
|
-
anything(),
|
|
626
|
-
),
|
|
627
|
-
).once();
|
|
628
|
-
});
|
|
629
|
-
|
|
630
321
|
it('authorizes loaded entities', async () => {
|
|
631
322
|
const privacyPolicy = new TestEntityPrivacyPolicy();
|
|
632
323
|
const spiedPrivacyPolicy = spy(privacyPolicy);
|
|
@@ -678,7 +369,7 @@ describe(AuthorizationResultBasedEntityLoader, () => {
|
|
|
678
369
|
instance(mock<IEntityMetricsAdapter>()),
|
|
679
370
|
TestEntity.name,
|
|
680
371
|
);
|
|
681
|
-
const
|
|
372
|
+
const constructionUtils = new EntityConstructionUtils(
|
|
682
373
|
viewerContext,
|
|
683
374
|
queryContext,
|
|
684
375
|
privacyPolicyEvaluationContext,
|
|
@@ -686,7 +377,6 @@ describe(AuthorizationResultBasedEntityLoader, () => {
|
|
|
686
377
|
TestEntity,
|
|
687
378
|
/* entitySelectedFields */ undefined,
|
|
688
379
|
privacyPolicy,
|
|
689
|
-
dataManager,
|
|
690
380
|
metricsAdapter,
|
|
691
381
|
);
|
|
692
382
|
const entityLoader = new AuthorizationResultBasedEntityLoader(
|
|
@@ -694,8 +384,7 @@ describe(AuthorizationResultBasedEntityLoader, () => {
|
|
|
694
384
|
testEntityConfiguration,
|
|
695
385
|
TestEntity,
|
|
696
386
|
dataManager,
|
|
697
|
-
|
|
698
|
-
utils,
|
|
387
|
+
constructionUtils,
|
|
699
388
|
);
|
|
700
389
|
const entity = await enforceAsyncResult(entityLoader.loadByIDAsync(id1));
|
|
701
390
|
verify(
|
|
@@ -710,48 +399,21 @@ describe(AuthorizationResultBasedEntityLoader, () => {
|
|
|
710
399
|
});
|
|
711
400
|
|
|
712
401
|
it('invalidates upon invalidate one', async () => {
|
|
713
|
-
const viewerContext = instance(mock(ViewerContext));
|
|
714
|
-
const privacyPolicyEvaluationContext =
|
|
715
|
-
instance(
|
|
716
|
-
mock<
|
|
717
|
-
EntityPrivacyPolicyEvaluationContext<
|
|
718
|
-
TestFields,
|
|
719
|
-
'customIdField',
|
|
720
|
-
ViewerContext,
|
|
721
|
-
TestEntity
|
|
722
|
-
>
|
|
723
|
-
>(),
|
|
724
|
-
);
|
|
725
402
|
const metricsAdapter = instance(mock<IEntityMetricsAdapter>());
|
|
726
|
-
const queryContext = new StubQueryContextProvider().getQueryContext();
|
|
727
|
-
const privacyPolicy = instance(mock(TestEntityPrivacyPolicy));
|
|
728
403
|
const dataManagerMock = mock<EntityDataManager<TestFields, 'customIdField'>>();
|
|
729
404
|
const dataManagerInstance = instance(dataManagerMock);
|
|
730
405
|
|
|
731
406
|
const id1 = uuidv4();
|
|
732
|
-
const
|
|
733
|
-
viewerContext,
|
|
734
|
-
queryContext,
|
|
735
|
-
privacyPolicyEvaluationContext,
|
|
407
|
+
const invalidationUtils = new EntityInvalidationUtils(
|
|
736
408
|
testEntityConfiguration,
|
|
737
409
|
TestEntity,
|
|
738
|
-
/* entitySelectedFields */ undefined,
|
|
739
|
-
privacyPolicy,
|
|
740
410
|
dataManagerInstance,
|
|
741
411
|
metricsAdapter,
|
|
742
412
|
);
|
|
743
|
-
const entityLoader = new AuthorizationResultBasedEntityLoader(
|
|
744
|
-
queryContext,
|
|
745
|
-
testEntityConfiguration,
|
|
746
|
-
TestEntity,
|
|
747
|
-
dataManagerInstance,
|
|
748
|
-
metricsAdapter,
|
|
749
|
-
utils,
|
|
750
|
-
);
|
|
751
413
|
|
|
752
414
|
const date = new Date();
|
|
753
415
|
|
|
754
|
-
await
|
|
416
|
+
await invalidationUtils.invalidateFieldsAsync({
|
|
755
417
|
customIdField: id1,
|
|
756
418
|
testIndexedField: 'h1',
|
|
757
419
|
intField: 5,
|
|
@@ -787,11 +449,14 @@ describe(AuthorizationResultBasedEntityLoader, () => {
|
|
|
787
449
|
new SingleFieldValueHolder<TestFields, 'dateField'>(date),
|
|
788
450
|
],
|
|
789
451
|
[
|
|
790
|
-
new CompositeFieldHolder(['stringField', 'intField']),
|
|
452
|
+
new CompositeFieldHolder<TestFields, 'customIdField'>(['stringField', 'intField']),
|
|
791
453
|
new CompositeFieldValueHolder({ stringField: 'huh', intField: 5 }),
|
|
792
454
|
],
|
|
793
455
|
[
|
|
794
|
-
new CompositeFieldHolder
|
|
456
|
+
new CompositeFieldHolder<TestFields, 'customIdField'>([
|
|
457
|
+
'stringField',
|
|
458
|
+
'testIndexedField',
|
|
459
|
+
]),
|
|
795
460
|
new CompositeFieldValueHolder({ stringField: 'huh', testIndexedField: 'h1' }),
|
|
796
461
|
],
|
|
797
462
|
]),
|
|
@@ -800,21 +465,7 @@ describe(AuthorizationResultBasedEntityLoader, () => {
|
|
|
800
465
|
});
|
|
801
466
|
|
|
802
467
|
it('invalidates upon invalidate by entity', async () => {
|
|
803
|
-
const viewerContext = instance(mock(ViewerContext));
|
|
804
|
-
const privacyPolicyEvaluationContext =
|
|
805
|
-
instance(
|
|
806
|
-
mock<
|
|
807
|
-
EntityPrivacyPolicyEvaluationContext<
|
|
808
|
-
TestFields,
|
|
809
|
-
'customIdField',
|
|
810
|
-
ViewerContext,
|
|
811
|
-
TestEntity
|
|
812
|
-
>
|
|
813
|
-
>(),
|
|
814
|
-
);
|
|
815
468
|
const metricsAdapter = instance(mock<IEntityMetricsAdapter>());
|
|
816
|
-
const queryContext = new StubQueryContextProvider().getQueryContext();
|
|
817
|
-
const privacyPolicy = instance(mock(TestEntityPrivacyPolicy));
|
|
818
469
|
const dataManagerMock = mock<EntityDataManager<TestFields, 'customIdField'>>();
|
|
819
470
|
const dataManagerInstance = instance(dataManagerMock);
|
|
820
471
|
|
|
@@ -832,26 +483,14 @@ describe(AuthorizationResultBasedEntityLoader, () => {
|
|
|
832
483
|
});
|
|
833
484
|
const entityInstance = instance(entityMock);
|
|
834
485
|
|
|
835
|
-
const
|
|
836
|
-
viewerContext,
|
|
837
|
-
queryContext,
|
|
838
|
-
privacyPolicyEvaluationContext,
|
|
486
|
+
const invalidationUtils = new EntityInvalidationUtils(
|
|
839
487
|
testEntityConfiguration,
|
|
840
488
|
TestEntity,
|
|
841
|
-
/* entitySelectedFields */ undefined,
|
|
842
|
-
privacyPolicy,
|
|
843
489
|
dataManagerInstance,
|
|
844
490
|
metricsAdapter,
|
|
845
491
|
);
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
testEntityConfiguration,
|
|
849
|
-
TestEntity,
|
|
850
|
-
dataManagerInstance,
|
|
851
|
-
metricsAdapter,
|
|
852
|
-
utils,
|
|
853
|
-
);
|
|
854
|
-
await entityLoader.utils.invalidateEntityAsync(entityInstance);
|
|
492
|
+
|
|
493
|
+
await invalidationUtils.invalidateEntityAsync(entityInstance);
|
|
855
494
|
|
|
856
495
|
verify(dataManagerMock.invalidateKeyValuePairsAsync(anything())).once();
|
|
857
496
|
verify(
|
|
@@ -880,11 +519,14 @@ describe(AuthorizationResultBasedEntityLoader, () => {
|
|
|
880
519
|
new SingleFieldValueHolder<TestFields, 'dateField'>(date),
|
|
881
520
|
],
|
|
882
521
|
[
|
|
883
|
-
new CompositeFieldHolder(['stringField', 'intField']),
|
|
522
|
+
new CompositeFieldHolder<TestFields, 'customIdField'>(['stringField', 'intField']),
|
|
884
523
|
new CompositeFieldValueHolder({ stringField: 'huh', intField: 5 }),
|
|
885
524
|
],
|
|
886
525
|
[
|
|
887
|
-
new CompositeFieldHolder
|
|
526
|
+
new CompositeFieldHolder<TestFields, 'customIdField'>([
|
|
527
|
+
'stringField',
|
|
528
|
+
'testIndexedField',
|
|
529
|
+
]),
|
|
888
530
|
new CompositeFieldValueHolder({ stringField: 'huh', testIndexedField: 'h1' }),
|
|
889
531
|
],
|
|
890
532
|
]),
|
|
@@ -893,21 +535,8 @@ describe(AuthorizationResultBasedEntityLoader, () => {
|
|
|
893
535
|
});
|
|
894
536
|
|
|
895
537
|
it('invalidates upon invalidate by entity within transaction', async () => {
|
|
896
|
-
const viewerContext = instance(mock(ViewerContext));
|
|
897
|
-
const privacyPolicyEvaluationContext =
|
|
898
|
-
instance(
|
|
899
|
-
mock<
|
|
900
|
-
EntityPrivacyPolicyEvaluationContext<
|
|
901
|
-
TestFields,
|
|
902
|
-
'customIdField',
|
|
903
|
-
ViewerContext,
|
|
904
|
-
TestEntity
|
|
905
|
-
>
|
|
906
|
-
>(),
|
|
907
|
-
);
|
|
908
538
|
const metricsAdapter = instance(mock<IEntityMetricsAdapter>());
|
|
909
539
|
|
|
910
|
-
const privacyPolicy = instance(mock(TestEntityPrivacyPolicy));
|
|
911
540
|
const dataManagerMock = mock<EntityDataManager<TestFields, 'customIdField'>>();
|
|
912
541
|
const dataManagerInstance = instance(dataManagerMock);
|
|
913
542
|
|
|
@@ -926,26 +555,13 @@ describe(AuthorizationResultBasedEntityLoader, () => {
|
|
|
926
555
|
const entityInstance = instance(entityMock);
|
|
927
556
|
|
|
928
557
|
await new StubQueryContextProvider().runInTransactionAsync(async (queryContext) => {
|
|
929
|
-
const
|
|
930
|
-
viewerContext,
|
|
931
|
-
queryContext,
|
|
932
|
-
privacyPolicyEvaluationContext,
|
|
558
|
+
const invalidationUtils = new EntityInvalidationUtils(
|
|
933
559
|
testEntityConfiguration,
|
|
934
560
|
TestEntity,
|
|
935
|
-
/* entitySelectedFields */ undefined,
|
|
936
|
-
privacyPolicy,
|
|
937
561
|
dataManagerInstance,
|
|
938
562
|
metricsAdapter,
|
|
939
563
|
);
|
|
940
|
-
|
|
941
|
-
queryContext,
|
|
942
|
-
testEntityConfiguration,
|
|
943
|
-
TestEntity,
|
|
944
|
-
dataManagerInstance,
|
|
945
|
-
metricsAdapter,
|
|
946
|
-
utils,
|
|
947
|
-
);
|
|
948
|
-
entityLoader.utils.invalidateEntityForTransaction(queryContext, entityInstance);
|
|
564
|
+
invalidationUtils.invalidateEntityForTransaction(queryContext, entityInstance);
|
|
949
565
|
|
|
950
566
|
verify(
|
|
951
567
|
dataManagerMock.invalidateKeyValuePairsForTransaction(queryContext, anything()),
|
|
@@ -977,11 +593,14 @@ describe(AuthorizationResultBasedEntityLoader, () => {
|
|
|
977
593
|
new SingleFieldValueHolder<TestFields, 'dateField'>(date),
|
|
978
594
|
],
|
|
979
595
|
[
|
|
980
|
-
new CompositeFieldHolder(['stringField', 'intField']),
|
|
596
|
+
new CompositeFieldHolder<TestFields, 'customIdField'>(['stringField', 'intField']),
|
|
981
597
|
new CompositeFieldValueHolder({ stringField: 'huh', intField: 5 }),
|
|
982
598
|
],
|
|
983
599
|
[
|
|
984
|
-
new CompositeFieldHolder
|
|
600
|
+
new CompositeFieldHolder<TestFields, 'customIdField'>([
|
|
601
|
+
'stringField',
|
|
602
|
+
'testIndexedField',
|
|
603
|
+
]),
|
|
985
604
|
new CompositeFieldValueHolder({ stringField: 'huh', testIndexedField: 'h1' }),
|
|
986
605
|
],
|
|
987
606
|
]),
|
|
@@ -1041,7 +660,7 @@ describe(AuthorizationResultBasedEntityLoader, () => {
|
|
|
1041
660
|
const privacyPolicy = instance(privacyPolicyMock);
|
|
1042
661
|
const dataManagerInstance = instance(dataManagerMock);
|
|
1043
662
|
|
|
1044
|
-
const
|
|
663
|
+
const constructionUtils = new EntityConstructionUtils(
|
|
1045
664
|
viewerContext,
|
|
1046
665
|
queryContext,
|
|
1047
666
|
privacyPolicyEvaluationContext,
|
|
@@ -1049,7 +668,6 @@ describe(AuthorizationResultBasedEntityLoader, () => {
|
|
|
1049
668
|
TestEntity,
|
|
1050
669
|
/* entitySelectedFields */ undefined,
|
|
1051
670
|
privacyPolicy,
|
|
1052
|
-
dataManagerInstance,
|
|
1053
671
|
metricsAdapter,
|
|
1054
672
|
);
|
|
1055
673
|
const entityLoader = new AuthorizationResultBasedEntityLoader(
|
|
@@ -1057,8 +675,7 @@ describe(AuthorizationResultBasedEntityLoader, () => {
|
|
|
1057
675
|
testEntityConfiguration,
|
|
1058
676
|
TestEntity,
|
|
1059
677
|
dataManagerInstance,
|
|
1060
|
-
|
|
1061
|
-
utils,
|
|
678
|
+
constructionUtils,
|
|
1062
679
|
);
|
|
1063
680
|
|
|
1064
681
|
const entityResult = await entityLoader.loadByIDAsync(id1);
|
|
@@ -1093,7 +710,7 @@ describe(AuthorizationResultBasedEntityLoader, () => {
|
|
|
1093
710
|
|
|
1094
711
|
const dataManagerInstance = instance(dataManagerMock);
|
|
1095
712
|
|
|
1096
|
-
const
|
|
713
|
+
const constructionUtils = new EntityConstructionUtils(
|
|
1097
714
|
viewerContext,
|
|
1098
715
|
queryContext,
|
|
1099
716
|
privacyPolicyEvaluationContext,
|
|
@@ -1101,7 +718,6 @@ describe(AuthorizationResultBasedEntityLoader, () => {
|
|
|
1101
718
|
TestEntity,
|
|
1102
719
|
/* entitySelectedFields */ undefined,
|
|
1103
720
|
privacyPolicy,
|
|
1104
|
-
dataManagerInstance,
|
|
1105
721
|
metricsAdapter,
|
|
1106
722
|
);
|
|
1107
723
|
const entityLoader = new AuthorizationResultBasedEntityLoader(
|
|
@@ -1109,8 +725,7 @@ describe(AuthorizationResultBasedEntityLoader, () => {
|
|
|
1109
725
|
testEntityConfiguration,
|
|
1110
726
|
TestEntity,
|
|
1111
727
|
dataManagerInstance,
|
|
1112
|
-
|
|
1113
|
-
utils,
|
|
728
|
+
constructionUtils,
|
|
1114
729
|
);
|
|
1115
730
|
|
|
1116
731
|
const loadByValue = uuidv4();
|
|
@@ -289,7 +289,7 @@ describe(ComposedEntityCacheAdapter, () => {
|
|
|
289
289
|
const { cacheAdapter } = makeTestCacheAdapters();
|
|
290
290
|
const results = await cacheAdapter.loadManyAsync(
|
|
291
291
|
new SingleFieldHolder<BlahFields, 'id', 'id'>('id'),
|
|
292
|
-
[] as
|
|
292
|
+
[] as readonly SingleFieldValueHolder<BlahFields, 'id'>[],
|
|
293
293
|
);
|
|
294
294
|
expect(results.size).toBe(0);
|
|
295
295
|
});
|
|
@@ -298,7 +298,7 @@ describe(ComposedEntityCacheAdapter, () => {
|
|
|
298
298
|
const cacheAdapter = new ComposedEntityCacheAdapter<BlahFields, 'id'>([]);
|
|
299
299
|
const results = await cacheAdapter.loadManyAsync(
|
|
300
300
|
new SingleFieldHolder<BlahFields, 'id', 'id'>('id'),
|
|
301
|
-
[] as
|
|
301
|
+
[] as readonly SingleFieldValueHolder<BlahFields, 'id'>[],
|
|
302
302
|
);
|
|
303
303
|
expect(results.size).toBe(0);
|
|
304
304
|
});
|
|
@@ -430,7 +430,7 @@ describe(ComposedEntityCacheAdapter, () => {
|
|
|
430
430
|
|
|
431
431
|
await cacheAdapter.invalidateManyAsync(
|
|
432
432
|
new SingleFieldHolder<BlahFields, 'id', 'id'>('id'),
|
|
433
|
-
[] as
|
|
433
|
+
[] as readonly SingleFieldValueHolder<BlahFields, 'id'>[],
|
|
434
434
|
);
|
|
435
435
|
});
|
|
436
436
|
});
|