@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
|
@@ -469,54 +469,36 @@ describe('EntityMutator.processEntityDeletionForInboundEdgesAsync', () => {
|
|
|
469
469
|
const companionProvider = createUnitTestEntityCompanionProvider();
|
|
470
470
|
const viewerContext = new TestViewerContext(companionProvider);
|
|
471
471
|
|
|
472
|
-
const parent = await ParentEntity.creator(
|
|
473
|
-
|
|
474
|
-
viewerContext.getQueryContext()
|
|
475
|
-
).enforceCreateAsync();
|
|
476
|
-
const child = await ChildEntity.creator(viewerContext, viewerContext.getQueryContext())
|
|
472
|
+
const parent = await ParentEntity.creator(viewerContext).enforceCreateAsync();
|
|
473
|
+
const child = await ChildEntity.creator(viewerContext)
|
|
477
474
|
.setField('parent_id', parent.getID())
|
|
478
475
|
.enforceCreateAsync();
|
|
479
|
-
const grandchild = await GrandChildEntity.creator(
|
|
480
|
-
viewerContext,
|
|
481
|
-
viewerContext.getQueryContext()
|
|
482
|
-
)
|
|
476
|
+
const grandchild = await GrandChildEntity.creator(viewerContext)
|
|
483
477
|
.setField('parent_id', child.getID())
|
|
484
478
|
.enforceCreateAsync();
|
|
485
479
|
|
|
486
480
|
await expect(
|
|
487
|
-
ParentEntity.loader(viewerContext
|
|
488
|
-
.enforcing()
|
|
489
|
-
.loadByIDNullableAsync(parent.getID())
|
|
481
|
+
ParentEntity.loader(viewerContext).enforcing().loadByIDNullableAsync(parent.getID())
|
|
490
482
|
).resolves.not.toBeNull();
|
|
491
483
|
await expect(
|
|
492
|
-
ChildEntity.loader(viewerContext
|
|
493
|
-
.enforcing()
|
|
494
|
-
.loadByIDNullableAsync(child.getID())
|
|
484
|
+
ChildEntity.loader(viewerContext).enforcing().loadByIDNullableAsync(child.getID())
|
|
495
485
|
).resolves.not.toBeNull();
|
|
496
486
|
await expect(
|
|
497
|
-
GrandChildEntity.loader(viewerContext
|
|
498
|
-
.enforcing()
|
|
499
|
-
.loadByIDNullableAsync(grandchild.getID())
|
|
487
|
+
GrandChildEntity.loader(viewerContext).enforcing().loadByIDNullableAsync(grandchild.getID())
|
|
500
488
|
).resolves.not.toBeNull();
|
|
501
489
|
|
|
502
490
|
privacyPolicyEvaluationRecords.shouldRecord = true;
|
|
503
|
-
await ParentEntity.enforceDeleteAsync(parent
|
|
491
|
+
await ParentEntity.enforceDeleteAsync(parent);
|
|
504
492
|
privacyPolicyEvaluationRecords.shouldRecord = false;
|
|
505
493
|
|
|
506
494
|
await expect(
|
|
507
|
-
ParentEntity.loader(viewerContext
|
|
508
|
-
.enforcing()
|
|
509
|
-
.loadByIDNullableAsync(parent.getID())
|
|
495
|
+
ParentEntity.loader(viewerContext).enforcing().loadByIDNullableAsync(parent.getID())
|
|
510
496
|
).resolves.toBeNull();
|
|
511
497
|
await expect(
|
|
512
|
-
ChildEntity.loader(viewerContext
|
|
513
|
-
.enforcing()
|
|
514
|
-
.loadByIDNullableAsync(child.getID())
|
|
498
|
+
ChildEntity.loader(viewerContext).enforcing().loadByIDNullableAsync(child.getID())
|
|
515
499
|
).resolves.toBeNull();
|
|
516
500
|
await expect(
|
|
517
|
-
GrandChildEntity.loader(viewerContext
|
|
518
|
-
.enforcing()
|
|
519
|
-
.loadByIDNullableAsync(grandchild.getID())
|
|
501
|
+
GrandChildEntity.loader(viewerContext).enforcing().loadByIDNullableAsync(grandchild.getID())
|
|
520
502
|
).resolves.toBeNull();
|
|
521
503
|
|
|
522
504
|
// two calls for each trigger, one beforeDelete, one afterDelete
|
|
@@ -605,55 +587,38 @@ describe('EntityMutator.processEntityDeletionForInboundEdgesAsync', () => {
|
|
|
605
587
|
const companionProvider = createUnitTestEntityCompanionProvider();
|
|
606
588
|
const viewerContext = new TestViewerContext(companionProvider);
|
|
607
589
|
|
|
608
|
-
const parent = await ParentEntity.creator(
|
|
609
|
-
|
|
610
|
-
viewerContext.getQueryContext()
|
|
611
|
-
).enforceCreateAsync();
|
|
612
|
-
const child = await ChildEntity.creator(viewerContext, viewerContext.getQueryContext())
|
|
590
|
+
const parent = await ParentEntity.creator(viewerContext).enforceCreateAsync();
|
|
591
|
+
const child = await ChildEntity.creator(viewerContext)
|
|
613
592
|
.setField('parent_id', parent.getID())
|
|
614
593
|
.enforceCreateAsync();
|
|
615
|
-
const grandchild = await GrandChildEntity.creator(
|
|
616
|
-
viewerContext,
|
|
617
|
-
viewerContext.getQueryContext()
|
|
618
|
-
)
|
|
594
|
+
const grandchild = await GrandChildEntity.creator(viewerContext)
|
|
619
595
|
.setField('parent_id', child.getID())
|
|
620
596
|
.enforceCreateAsync();
|
|
621
597
|
|
|
622
598
|
await expect(
|
|
623
|
-
ParentEntity.loader(viewerContext
|
|
624
|
-
.enforcing()
|
|
625
|
-
.loadByIDNullableAsync(parent.getID())
|
|
599
|
+
ParentEntity.loader(viewerContext).enforcing().loadByIDNullableAsync(parent.getID())
|
|
626
600
|
).resolves.not.toBeNull();
|
|
627
601
|
await expect(
|
|
628
|
-
ChildEntity.loader(viewerContext
|
|
629
|
-
.enforcing()
|
|
630
|
-
.loadByIDNullableAsync(child.getID())
|
|
602
|
+
ChildEntity.loader(viewerContext).enforcing().loadByIDNullableAsync(child.getID())
|
|
631
603
|
).resolves.not.toBeNull();
|
|
632
604
|
await expect(
|
|
633
|
-
GrandChildEntity.loader(viewerContext
|
|
634
|
-
.enforcing()
|
|
635
|
-
.loadByIDNullableAsync(grandchild.getID())
|
|
605
|
+
GrandChildEntity.loader(viewerContext).enforcing().loadByIDNullableAsync(grandchild.getID())
|
|
636
606
|
).resolves.not.toBeNull();
|
|
637
607
|
|
|
638
608
|
privacyPolicyEvaluationRecords.shouldRecord = true;
|
|
639
|
-
await ParentEntity.enforceDeleteAsync(parent
|
|
609
|
+
await ParentEntity.enforceDeleteAsync(parent);
|
|
640
610
|
privacyPolicyEvaluationRecords.shouldRecord = false;
|
|
641
611
|
|
|
642
612
|
await expect(
|
|
643
|
-
ParentEntity.loader(viewerContext
|
|
644
|
-
.enforcing()
|
|
645
|
-
.loadByIDNullableAsync(parent.getID())
|
|
613
|
+
ParentEntity.loader(viewerContext).enforcing().loadByIDNullableAsync(parent.getID())
|
|
646
614
|
).resolves.toBeNull();
|
|
647
615
|
|
|
648
|
-
const loadedChild = await ChildEntity.loader(viewerContext
|
|
616
|
+
const loadedChild = await ChildEntity.loader(viewerContext)
|
|
649
617
|
.enforcing()
|
|
650
618
|
.loadByIDAsync(child.getID());
|
|
651
619
|
expect(loadedChild.getField('parent_id')).toBeNull();
|
|
652
620
|
|
|
653
|
-
const loadedGrandchild = await GrandChildEntity.loader(
|
|
654
|
-
viewerContext,
|
|
655
|
-
viewerContext.getQueryContext()
|
|
656
|
-
)
|
|
621
|
+
const loadedGrandchild = await GrandChildEntity.loader(viewerContext)
|
|
657
622
|
.enforcing()
|
|
658
623
|
.loadByIDAsync(grandchild.getID());
|
|
659
624
|
expect(loadedGrandchild.getField('parent_id')).toEqual(loadedChild.getID());
|
|
@@ -733,32 +698,24 @@ describe('EntityMutator.processEntityDeletionForInboundEdgesAsync', () => {
|
|
|
733
698
|
const companionProvider = createUnitTestEntityCompanionProvider();
|
|
734
699
|
const viewerContext = new TestViewerContext(companionProvider);
|
|
735
700
|
|
|
736
|
-
const parent = await ParentEntity.creator(
|
|
737
|
-
|
|
738
|
-
viewerContext.getQueryContext()
|
|
739
|
-
).enforceCreateAsync();
|
|
740
|
-
const child = await ChildEntity.creator(viewerContext, viewerContext.getQueryContext())
|
|
701
|
+
const parent = await ParentEntity.creator(viewerContext).enforceCreateAsync();
|
|
702
|
+
const child = await ChildEntity.creator(viewerContext)
|
|
741
703
|
.setField('parent_id', parent.getID())
|
|
742
704
|
.enforceCreateAsync();
|
|
743
|
-
const grandchild = await GrandChildEntity.creator(
|
|
744
|
-
viewerContext,
|
|
745
|
-
viewerContext.getQueryContext()
|
|
746
|
-
)
|
|
705
|
+
const grandchild = await GrandChildEntity.creator(viewerContext)
|
|
747
706
|
.setField('parent_id', child.getID())
|
|
748
707
|
.enforceCreateAsync();
|
|
749
708
|
|
|
750
709
|
await expect(
|
|
751
|
-
ParentEntity.loader(viewerContext
|
|
752
|
-
.enforcing()
|
|
753
|
-
.loadByIDNullableAsync(parent.getID())
|
|
710
|
+
ParentEntity.loader(viewerContext).enforcing().loadByIDNullableAsync(parent.getID())
|
|
754
711
|
).resolves.not.toBeNull();
|
|
755
712
|
await expect(
|
|
756
|
-
ChildEntity.loader(viewerContext
|
|
713
|
+
ChildEntity.loader(viewerContext)
|
|
757
714
|
.enforcing()
|
|
758
715
|
.loadByFieldEqualingAsync('parent_id', parent.getID())
|
|
759
716
|
).resolves.not.toBeNull();
|
|
760
717
|
await expect(
|
|
761
|
-
GrandChildEntity.loader(viewerContext
|
|
718
|
+
GrandChildEntity.loader(viewerContext)
|
|
762
719
|
.enforcing()
|
|
763
720
|
.loadByFieldEqualingAsync('parent_id', child.getID())
|
|
764
721
|
).resolves.not.toBeNull();
|
|
@@ -782,7 +739,7 @@ describe('EntityMutator.processEntityDeletionForInboundEdgesAsync', () => {
|
|
|
782
739
|
expect(grandChildCachedBefore.get(child.getID())?.status).toEqual(CacheStatus.HIT);
|
|
783
740
|
|
|
784
741
|
privacyPolicyEvaluationRecords.shouldRecord = true;
|
|
785
|
-
await ParentEntity.enforceDeleteAsync(parent
|
|
742
|
+
await ParentEntity.enforceDeleteAsync(parent);
|
|
786
743
|
privacyPolicyEvaluationRecords.shouldRecord = false;
|
|
787
744
|
|
|
788
745
|
const childCachedAfter = await childCacheAdapter.loadManyAsync('parent_id', [parent.getID()]);
|
|
@@ -794,20 +751,15 @@ describe('EntityMutator.processEntityDeletionForInboundEdgesAsync', () => {
|
|
|
794
751
|
expect(grandChildCachedAfter.get(child.getID())?.status).toEqual(CacheStatus.HIT);
|
|
795
752
|
|
|
796
753
|
await expect(
|
|
797
|
-
ParentEntity.loader(viewerContext
|
|
798
|
-
.enforcing()
|
|
799
|
-
.loadByIDNullableAsync(parent.getID())
|
|
754
|
+
ParentEntity.loader(viewerContext).enforcing().loadByIDNullableAsync(parent.getID())
|
|
800
755
|
).resolves.toBeNull();
|
|
801
756
|
|
|
802
|
-
const loadedChild = await ChildEntity.loader(viewerContext
|
|
757
|
+
const loadedChild = await ChildEntity.loader(viewerContext)
|
|
803
758
|
.enforcing()
|
|
804
759
|
.loadByIDAsync(child.getID());
|
|
805
760
|
expect(loadedChild).not.toBeNull();
|
|
806
761
|
|
|
807
|
-
const loadedGrandchild = await GrandChildEntity.loader(
|
|
808
|
-
viewerContext,
|
|
809
|
-
viewerContext.getQueryContext()
|
|
810
|
-
)
|
|
762
|
+
const loadedGrandchild = await GrandChildEntity.loader(viewerContext)
|
|
811
763
|
.enforcing()
|
|
812
764
|
.loadByIDAsync(grandchild.getID());
|
|
813
765
|
expect(loadedGrandchild.getField('parent_id')).toEqual(loadedChild.getID());
|
|
@@ -879,32 +831,24 @@ describe('EntityMutator.processEntityDeletionForInboundEdgesAsync', () => {
|
|
|
879
831
|
const companionProvider = createUnitTestEntityCompanionProvider();
|
|
880
832
|
const viewerContext = new TestViewerContext(companionProvider);
|
|
881
833
|
|
|
882
|
-
const parent = await ParentEntity.creator(
|
|
883
|
-
|
|
884
|
-
viewerContext.getQueryContext()
|
|
885
|
-
).enforceCreateAsync();
|
|
886
|
-
const child = await ChildEntity.creator(viewerContext, viewerContext.getQueryContext())
|
|
834
|
+
const parent = await ParentEntity.creator(viewerContext).enforceCreateAsync();
|
|
835
|
+
const child = await ChildEntity.creator(viewerContext)
|
|
887
836
|
.setField('parent_id', parent.getID())
|
|
888
837
|
.enforceCreateAsync();
|
|
889
|
-
const grandchild = await GrandChildEntity.creator(
|
|
890
|
-
viewerContext,
|
|
891
|
-
viewerContext.getQueryContext()
|
|
892
|
-
)
|
|
838
|
+
const grandchild = await GrandChildEntity.creator(viewerContext)
|
|
893
839
|
.setField('parent_id', child.getID())
|
|
894
840
|
.enforceCreateAsync();
|
|
895
841
|
|
|
896
842
|
await expect(
|
|
897
|
-
ParentEntity.loader(viewerContext
|
|
898
|
-
.enforcing()
|
|
899
|
-
.loadByIDNullableAsync(parent.getID())
|
|
843
|
+
ParentEntity.loader(viewerContext).enforcing().loadByIDNullableAsync(parent.getID())
|
|
900
844
|
).resolves.not.toBeNull();
|
|
901
845
|
await expect(
|
|
902
|
-
ChildEntity.loader(viewerContext
|
|
846
|
+
ChildEntity.loader(viewerContext)
|
|
903
847
|
.enforcing()
|
|
904
848
|
.loadByFieldEqualingAsync('parent_id', parent.getID())
|
|
905
849
|
).resolves.not.toBeNull();
|
|
906
850
|
await expect(
|
|
907
|
-
GrandChildEntity.loader(viewerContext
|
|
851
|
+
GrandChildEntity.loader(viewerContext)
|
|
908
852
|
.enforcing()
|
|
909
853
|
.loadByFieldEqualingAsync('parent_id', child.getID())
|
|
910
854
|
).resolves.not.toBeNull();
|
|
@@ -928,7 +872,7 @@ describe('EntityMutator.processEntityDeletionForInboundEdgesAsync', () => {
|
|
|
928
872
|
expect(grandChildCachedBefore.get(child.getID())?.status).toEqual(CacheStatus.HIT);
|
|
929
873
|
|
|
930
874
|
privacyPolicyEvaluationRecords.shouldRecord = true;
|
|
931
|
-
await ParentEntity.enforceDeleteAsync(parent
|
|
875
|
+
await ParentEntity.enforceDeleteAsync(parent);
|
|
932
876
|
privacyPolicyEvaluationRecords.shouldRecord = false;
|
|
933
877
|
|
|
934
878
|
const childCachedAfter = await childCacheAdapter.loadManyAsync('parent_id', [parent.getID()]);
|
|
@@ -940,19 +884,13 @@ describe('EntityMutator.processEntityDeletionForInboundEdgesAsync', () => {
|
|
|
940
884
|
expect(grandChildCachedAfter.get(child.getID())?.status).toEqual(CacheStatus.MISS);
|
|
941
885
|
|
|
942
886
|
await expect(
|
|
943
|
-
ParentEntity.loader(viewerContext
|
|
944
|
-
.enforcing()
|
|
945
|
-
.loadByIDNullableAsync(parent.getID())
|
|
887
|
+
ParentEntity.loader(viewerContext).enforcing().loadByIDNullableAsync(parent.getID())
|
|
946
888
|
).resolves.toBeNull();
|
|
947
889
|
await expect(
|
|
948
|
-
ChildEntity.loader(viewerContext
|
|
949
|
-
.enforcing()
|
|
950
|
-
.loadByIDNullableAsync(child.getID())
|
|
890
|
+
ChildEntity.loader(viewerContext).enforcing().loadByIDNullableAsync(child.getID())
|
|
951
891
|
).resolves.not.toBeNull();
|
|
952
892
|
await expect(
|
|
953
|
-
GrandChildEntity.loader(viewerContext
|
|
954
|
-
.enforcing()
|
|
955
|
-
.loadByIDNullableAsync(grandchild.getID())
|
|
893
|
+
GrandChildEntity.loader(viewerContext).enforcing().loadByIDNullableAsync(grandchild.getID())
|
|
956
894
|
).resolves.not.toBeNull();
|
|
957
895
|
|
|
958
896
|
// two calls for each trigger, one beforeDelete, one afterDelete
|
|
@@ -123,7 +123,7 @@ describe(EntityLoader, () => {
|
|
|
123
123
|
const viewerContext = instance(mock(ViewerContext));
|
|
124
124
|
const privacyPolicyEvaluationContext = instance(mock<EntityPrivacyPolicyEvaluationContext>());
|
|
125
125
|
const metricsAdapter = instance(mock<IEntityMetricsAdapter>());
|
|
126
|
-
const queryContext = StubQueryContextProvider.
|
|
126
|
+
const queryContext = StubQueryContextProvider.getQueryContext();
|
|
127
127
|
|
|
128
128
|
const databaseAdapter = new StubDatabaseAdapter<TestFields>(
|
|
129
129
|
testEntityConfiguration,
|
|
@@ -5,6 +5,7 @@ import { v4 as uuidv4 } from 'uuid';
|
|
|
5
5
|
import { OrderByOrdering } from '../EntityDatabaseAdapter';
|
|
6
6
|
import EntityLoader from '../EntityLoader';
|
|
7
7
|
import { EntityPrivacyPolicyEvaluationContext } from '../EntityPrivacyPolicy';
|
|
8
|
+
import ViewerContext from '../ViewerContext';
|
|
8
9
|
import { enforceResultsAsync } from '../entityUtils';
|
|
9
10
|
import EntityDataManager from '../internal/EntityDataManager';
|
|
10
11
|
import ReadThroughEntityCache from '../internal/ReadThroughEntityCache';
|
|
@@ -14,7 +15,6 @@ import TestEntity, {
|
|
|
14
15
|
TestEntityPrivacyPolicy,
|
|
15
16
|
testEntityConfiguration,
|
|
16
17
|
} from '../testfixtures/TestEntity';
|
|
17
|
-
import TestViewerContext from '../testfixtures/TestViewerContext';
|
|
18
18
|
import { NoCacheStubCacheAdapterProvider } from '../utils/testing/StubCacheAdapter';
|
|
19
19
|
import StubDatabaseAdapter from '../utils/testing/StubDatabaseAdapter';
|
|
20
20
|
import StubQueryContextProvider from '../utils/testing/StubQueryContextProvider';
|
|
@@ -22,10 +22,10 @@ import StubQueryContextProvider from '../utils/testing/StubQueryContextProvider'
|
|
|
22
22
|
describe(EntityLoader, () => {
|
|
23
23
|
it('loads entities', async () => {
|
|
24
24
|
const dateToInsert = new Date();
|
|
25
|
-
const viewerContext = instance(mock(
|
|
25
|
+
const viewerContext = instance(mock(ViewerContext));
|
|
26
26
|
const privacyPolicyEvaluationContext = instance(mock<EntityPrivacyPolicyEvaluationContext>());
|
|
27
27
|
const metricsAdapter = instance(mock<IEntityMetricsAdapter>());
|
|
28
|
-
const queryContext = StubQueryContextProvider.
|
|
28
|
+
const queryContext = StubQueryContextProvider.getQueryContext();
|
|
29
29
|
|
|
30
30
|
const id1 = uuidv4();
|
|
31
31
|
const id2 = uuidv4();
|
|
@@ -117,10 +117,10 @@ describe(EntityLoader, () => {
|
|
|
117
117
|
it('loads entities with loadManyByFieldEqualityConjunction', async () => {
|
|
118
118
|
const privacyPolicy = new TestEntityPrivacyPolicy();
|
|
119
119
|
const spiedPrivacyPolicy = spy(privacyPolicy);
|
|
120
|
-
const viewerContext = instance(mock(
|
|
120
|
+
const viewerContext = instance(mock(ViewerContext));
|
|
121
121
|
const privacyPolicyEvaluationContext = instance(mock<EntityPrivacyPolicyEvaluationContext>());
|
|
122
122
|
const metricsAdapter = instance(mock<IEntityMetricsAdapter>());
|
|
123
|
-
const queryContext = StubQueryContextProvider.
|
|
123
|
+
const queryContext = StubQueryContextProvider.getQueryContext();
|
|
124
124
|
|
|
125
125
|
const id1 = uuidv4();
|
|
126
126
|
const id2 = uuidv4();
|
|
@@ -216,10 +216,10 @@ describe(EntityLoader, () => {
|
|
|
216
216
|
it('loads entities with loadFirstByFieldEqualityConjunction', async () => {
|
|
217
217
|
const privacyPolicy = new TestEntityPrivacyPolicy();
|
|
218
218
|
const spiedPrivacyPolicy = spy(privacyPolicy);
|
|
219
|
-
const viewerContext = instance(mock(
|
|
219
|
+
const viewerContext = instance(mock(ViewerContext));
|
|
220
220
|
const privacyPolicyEvaluationContext = instance(mock<EntityPrivacyPolicyEvaluationContext>());
|
|
221
221
|
const metricsAdapter = instance(mock<IEntityMetricsAdapter>());
|
|
222
|
-
const queryContext = StubQueryContextProvider.
|
|
222
|
+
const queryContext = StubQueryContextProvider.getQueryContext();
|
|
223
223
|
|
|
224
224
|
const id1 = uuidv4();
|
|
225
225
|
const id2 = uuidv4();
|
|
@@ -313,10 +313,10 @@ describe(EntityLoader, () => {
|
|
|
313
313
|
const privacyPolicy = new TestEntityPrivacyPolicy();
|
|
314
314
|
const spiedPrivacyPolicy = spy(privacyPolicy);
|
|
315
315
|
|
|
316
|
-
const viewerContext = instance(mock(
|
|
316
|
+
const viewerContext = instance(mock(ViewerContext));
|
|
317
317
|
const privacyPolicyEvaluationContext = instance(mock<EntityPrivacyPolicyEvaluationContext>());
|
|
318
318
|
const metricsAdapter = instance(mock<IEntityMetricsAdapter>());
|
|
319
|
-
const queryContext = StubQueryContextProvider.
|
|
319
|
+
const queryContext = StubQueryContextProvider.getQueryContext();
|
|
320
320
|
|
|
321
321
|
const id1 = uuidv4();
|
|
322
322
|
const databaseAdapter = new StubDatabaseAdapter<TestFields>(
|
|
@@ -374,10 +374,10 @@ describe(EntityLoader, () => {
|
|
|
374
374
|
});
|
|
375
375
|
|
|
376
376
|
it('invalidates upon invalidate one', async () => {
|
|
377
|
-
const viewerContext = instance(mock(
|
|
377
|
+
const viewerContext = instance(mock(ViewerContext));
|
|
378
378
|
const privacyPolicyEvaluationContext = instance(mock<EntityPrivacyPolicyEvaluationContext>());
|
|
379
379
|
const metricsAdapter = instance(mock<IEntityMetricsAdapter>());
|
|
380
|
-
const queryContext = StubQueryContextProvider.
|
|
380
|
+
const queryContext = StubQueryContextProvider.getQueryContext();
|
|
381
381
|
const privacyPolicy = instance(mock(TestEntityPrivacyPolicy));
|
|
382
382
|
const dataManagerMock = mock<EntityDataManager<TestFields>>();
|
|
383
383
|
const dataManagerInstance = instance(dataManagerMock);
|
|
@@ -402,10 +402,10 @@ describe(EntityLoader, () => {
|
|
|
402
402
|
});
|
|
403
403
|
|
|
404
404
|
it('invalidates upon invalidate by field', async () => {
|
|
405
|
-
const viewerContext = instance(mock(
|
|
405
|
+
const viewerContext = instance(mock(ViewerContext));
|
|
406
406
|
const privacyPolicyEvaluationContext = instance(mock<EntityPrivacyPolicyEvaluationContext>());
|
|
407
407
|
const metricsAdapter = instance(mock<IEntityMetricsAdapter>());
|
|
408
|
-
const queryContext = StubQueryContextProvider.
|
|
408
|
+
const queryContext = StubQueryContextProvider.getQueryContext();
|
|
409
409
|
const privacyPolicy = instance(mock(TestEntityPrivacyPolicy));
|
|
410
410
|
const dataManagerMock = mock<EntityDataManager<TestFields>>();
|
|
411
411
|
const dataManagerInstance = instance(dataManagerMock);
|
|
@@ -429,10 +429,10 @@ describe(EntityLoader, () => {
|
|
|
429
429
|
});
|
|
430
430
|
|
|
431
431
|
it('invalidates upon invalidate by entity', async () => {
|
|
432
|
-
const viewerContext = instance(mock(
|
|
432
|
+
const viewerContext = instance(mock(ViewerContext));
|
|
433
433
|
const privacyPolicyEvaluationContext = instance(mock<EntityPrivacyPolicyEvaluationContext>());
|
|
434
434
|
const metricsAdapter = instance(mock<IEntityMetricsAdapter>());
|
|
435
|
-
const queryContext = StubQueryContextProvider.
|
|
435
|
+
const queryContext = StubQueryContextProvider.getQueryContext();
|
|
436
436
|
const privacyPolicy = instance(mock(TestEntityPrivacyPolicy));
|
|
437
437
|
const dataManagerMock = mock<EntityDataManager<TestFields>>();
|
|
438
438
|
const dataManagerInstance = instance(dataManagerMock);
|
|
@@ -460,10 +460,10 @@ describe(EntityLoader, () => {
|
|
|
460
460
|
});
|
|
461
461
|
|
|
462
462
|
it('returns error result when not allowed', async () => {
|
|
463
|
-
const viewerContext = instance(mock(
|
|
463
|
+
const viewerContext = instance(mock(ViewerContext));
|
|
464
464
|
const privacyPolicyEvaluationContext = instance(mock<EntityPrivacyPolicyEvaluationContext>());
|
|
465
465
|
const metricsAdapter = instance(mock<IEntityMetricsAdapter>());
|
|
466
|
-
const queryContext = StubQueryContextProvider.
|
|
466
|
+
const queryContext = StubQueryContextProvider.getQueryContext();
|
|
467
467
|
const privacyPolicyMock = mock(TestEntityPrivacyPolicy);
|
|
468
468
|
const dataManagerMock = mock<EntityDataManager<TestFields>>();
|
|
469
469
|
|
|
@@ -506,10 +506,10 @@ describe(EntityLoader, () => {
|
|
|
506
506
|
});
|
|
507
507
|
|
|
508
508
|
it('throws upon database adapter error', async () => {
|
|
509
|
-
const viewerContext = instance(mock(
|
|
509
|
+
const viewerContext = instance(mock(ViewerContext));
|
|
510
510
|
const privacyPolicyEvaluationContext = instance(mock<EntityPrivacyPolicyEvaluationContext>());
|
|
511
511
|
const metricsAdapter = instance(mock<IEntityMetricsAdapter>());
|
|
512
|
-
const queryContext = StubQueryContextProvider.
|
|
512
|
+
const queryContext = StubQueryContextProvider.getQueryContext();
|
|
513
513
|
const privacyPolicy = instance(mock(TestEntityPrivacyPolicy));
|
|
514
514
|
const dataManagerMock = mock<EntityDataManager<TestFields>>();
|
|
515
515
|
|
|
@@ -5,8 +5,8 @@ import { UUIDField } from '../EntityFields';
|
|
|
5
5
|
import { EntityMutationType, EntityTriggerMutationInfo } from '../EntityMutationInfo';
|
|
6
6
|
import { EntityNonTransactionalMutationTrigger } from '../EntityMutationTriggerConfiguration';
|
|
7
7
|
import EntityPrivacyPolicy from '../EntityPrivacyPolicy';
|
|
8
|
+
import ViewerContext from '../ViewerContext';
|
|
8
9
|
import AlwaysAllowPrivacyPolicyRule from '../rules/AlwaysAllowPrivacyPolicyRule';
|
|
9
|
-
import TestViewerContext from '../testfixtures/TestViewerContext';
|
|
10
10
|
import { createUnitTestEntityCompanionProvider } from '../utils/testing/createUnitTestEntityCompanionProvider';
|
|
11
11
|
|
|
12
12
|
type BlahFields = {
|
|
@@ -16,28 +16,28 @@ type BlahFields = {
|
|
|
16
16
|
class BlahEntityPrivacyPolicy extends EntityPrivacyPolicy<
|
|
17
17
|
BlahFields,
|
|
18
18
|
string,
|
|
19
|
-
|
|
19
|
+
ViewerContext,
|
|
20
20
|
BlahEntity
|
|
21
21
|
> {
|
|
22
22
|
protected override readonly createRules = [
|
|
23
|
-
new AlwaysAllowPrivacyPolicyRule<BlahFields, string,
|
|
23
|
+
new AlwaysAllowPrivacyPolicyRule<BlahFields, string, ViewerContext, BlahEntity>(),
|
|
24
24
|
];
|
|
25
25
|
protected override readonly readRules = [
|
|
26
|
-
new AlwaysAllowPrivacyPolicyRule<BlahFields, string,
|
|
26
|
+
new AlwaysAllowPrivacyPolicyRule<BlahFields, string, ViewerContext, BlahEntity>(),
|
|
27
27
|
];
|
|
28
28
|
protected override readonly updateRules = [
|
|
29
|
-
new AlwaysAllowPrivacyPolicyRule<BlahFields, string,
|
|
29
|
+
new AlwaysAllowPrivacyPolicyRule<BlahFields, string, ViewerContext, BlahEntity>(),
|
|
30
30
|
];
|
|
31
31
|
protected override readonly deleteRules = [
|
|
32
|
-
new AlwaysAllowPrivacyPolicyRule<BlahFields, string,
|
|
32
|
+
new AlwaysAllowPrivacyPolicyRule<BlahFields, string, ViewerContext, BlahEntity>(),
|
|
33
33
|
];
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
class BlahEntity extends Entity<BlahFields, string,
|
|
36
|
+
class BlahEntity extends Entity<BlahFields, string, ViewerContext> {
|
|
37
37
|
static defineCompanionDefinition(): EntityCompanionDefinition<
|
|
38
38
|
BlahFields,
|
|
39
39
|
string,
|
|
40
|
-
|
|
40
|
+
ViewerContext,
|
|
41
41
|
BlahEntity,
|
|
42
42
|
BlahEntityPrivacyPolicy
|
|
43
43
|
> {
|
|
@@ -66,16 +66,16 @@ class BlahEntity extends Entity<BlahFields, string, TestViewerContext> {
|
|
|
66
66
|
class TestNonTransactionalMutationTrigger extends EntityNonTransactionalMutationTrigger<
|
|
67
67
|
BlahFields,
|
|
68
68
|
string,
|
|
69
|
-
|
|
69
|
+
ViewerContext,
|
|
70
70
|
BlahEntity
|
|
71
71
|
> {
|
|
72
72
|
async executeAsync(
|
|
73
|
-
viewerContext:
|
|
73
|
+
viewerContext: ViewerContext,
|
|
74
74
|
entity: BlahEntity,
|
|
75
|
-
mutationInfo: EntityTriggerMutationInfo<BlahFields, string,
|
|
75
|
+
mutationInfo: EntityTriggerMutationInfo<BlahFields, string, ViewerContext, BlahEntity>
|
|
76
76
|
): Promise<void> {
|
|
77
77
|
if (mutationInfo.type === EntityMutationType.DELETE) {
|
|
78
|
-
const entityLoaded = await BlahEntity.loader(viewerContext
|
|
78
|
+
const entityLoaded = await BlahEntity.loader(viewerContext)
|
|
79
79
|
.enforcing()
|
|
80
80
|
.loadByIDNullableAsync(entity.getID());
|
|
81
81
|
if (entityLoaded) {
|
|
@@ -90,17 +90,14 @@ class TestNonTransactionalMutationTrigger extends EntityNonTransactionalMutation
|
|
|
90
90
|
describe('EntityMutator', () => {
|
|
91
91
|
test('cache consistency with post-commit callbacks', async () => {
|
|
92
92
|
const companionProvider = createUnitTestEntityCompanionProvider();
|
|
93
|
-
const viewerContext = new
|
|
93
|
+
const viewerContext = new ViewerContext(companionProvider);
|
|
94
94
|
|
|
95
95
|
// put it in cache
|
|
96
|
-
const entity = await BlahEntity.creator(
|
|
97
|
-
|
|
98
|
-
viewerContext.getQueryContext()
|
|
99
|
-
).enforceCreateAsync();
|
|
100
|
-
const entityLoaded = await BlahEntity.loader(viewerContext, viewerContext.getQueryContext())
|
|
96
|
+
const entity = await BlahEntity.creator(viewerContext).enforceCreateAsync();
|
|
97
|
+
const entityLoaded = await BlahEntity.loader(viewerContext)
|
|
101
98
|
.enforcing()
|
|
102
99
|
.loadByIDAsync(entity.getID());
|
|
103
100
|
|
|
104
|
-
await BlahEntity.enforceDeleteAsync(entityLoaded
|
|
101
|
+
await BlahEntity.enforceDeleteAsync(entityLoaded);
|
|
105
102
|
});
|
|
106
103
|
});
|