@expo/entity 0.33.0 → 0.34.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 +6 -29
- package/build/Entity.js.map +1 -1
- package/build/EntityAssociationLoader.d.ts +8 -8
- package/build/EntityAssociationLoader.js +4 -20
- package/build/EntityAssociationLoader.js.map +1 -1
- package/build/EntityFields.js +3 -2
- package/build/EntityFields.js.map +1 -1
- package/build/EntityMutationTriggerConfiguration.d.ts +5 -7
- package/build/EntityMutationTriggerConfiguration.js +3 -4
- package/build/EntityMutationTriggerConfiguration.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/IEntityCacheAdapterProvider.d.ts +1 -1
- package/build/ReadonlyEntity.d.ts +1 -1
- package/build/ReadonlyEntity.js +1 -4
- 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 +69 -37
- package/build/__tests__/EntityAssociationLoader-test.js.map +1 -1
- package/build/__tests__/EntityCommonUseCases-test.js +19 -11
- package/build/__tests__/EntityCommonUseCases-test.js.map +1 -1
- package/build/__tests__/EntityEdges-test.js +72 -40
- package/build/__tests__/EntityEdges-test.js.map +1 -1
- package/build/__tests__/EntityFields-test.js +7 -1
- package/build/__tests__/EntityFields-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 +79 -47
- 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 +12 -8
- package/build/__tests__/cases/TwoEntitySameTableDisjointRows-test.js.map +1 -1
- package/build/__tests__/cases/TwoEntitySameTableOverlappingRows-test.js +15 -13
- 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 +3 -0
- package/build/testfixtures/TestViewerContext.js +6 -0
- package/build/testfixtures/TestViewerContext.js.map +1 -1
- package/package.json +2 -2
- package/src/Entity.ts +6 -29
- package/src/EntityAssociationLoader.ts +9 -25
- package/src/EntityFields.ts +5 -3
- package/src/EntityMutationTriggerConfiguration.ts +5 -7
- package/src/EntityQueryContextProvider.ts +1 -1
- package/src/IEntityCacheAdapterProvider.ts +1 -1
- package/src/ReadonlyEntity.ts +1 -4
- package/src/ViewerContext.ts +5 -5
- package/src/__tests__/Entity-test.ts +43 -27
- package/src/__tests__/EntityAssociationLoader-test.ts +168 -86
- package/src/__tests__/EntityCommonUseCases-test.ts +36 -18
- package/src/__tests__/EntityEdges-test.ts +102 -40
- package/src/__tests__/EntityFields-test.ts +7 -1
- package/src/__tests__/EntityLoader-constructor-test.ts +1 -1
- package/src/__tests__/EntityLoader-test.ts +19 -19
- package/src/__tests__/EntityMutator-MutationCacheConsistency-test.ts +19 -16
- package/src/__tests__/EntityMutator-test.ts +67 -61
- package/src/__tests__/EntitySecondaryCacheLoader-test.ts +20 -11
- package/src/__tests__/EntitySelfReferentialEdges-test.ts +115 -47
- package/src/__tests__/ReadonlyEntity-test.ts +15 -13
- package/src/__tests__/ViewerContext-test.ts +3 -2
- package/src/__tests__/cases/TwoEntitySameTableDisjointRows-test.ts +33 -22
- package/src/__tests__/cases/TwoEntitySameTableOverlappingRows-test.ts +30 -22
- 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 +15 -12
- package/src/testfixtures/TestEntity2.ts +8 -8
- package/src/testfixtures/TestViewerContext.ts +12 -1
|
@@ -469,36 +469,54 @@ describe('EntityMutator.processEntityDeletionForInboundEdgesAsync', () => {
|
|
|
469
469
|
const companionProvider = createUnitTestEntityCompanionProvider();
|
|
470
470
|
const viewerContext = new TestViewerContext(companionProvider);
|
|
471
471
|
|
|
472
|
-
const parent = await ParentEntity.creator(
|
|
473
|
-
|
|
472
|
+
const parent = await ParentEntity.creator(
|
|
473
|
+
viewerContext,
|
|
474
|
+
viewerContext.getQueryContext()
|
|
475
|
+
).enforceCreateAsync();
|
|
476
|
+
const child = await ChildEntity.creator(viewerContext, viewerContext.getQueryContext())
|
|
474
477
|
.setField('parent_id', parent.getID())
|
|
475
478
|
.enforceCreateAsync();
|
|
476
|
-
const grandchild = await GrandChildEntity.creator(
|
|
479
|
+
const grandchild = await GrandChildEntity.creator(
|
|
480
|
+
viewerContext,
|
|
481
|
+
viewerContext.getQueryContext()
|
|
482
|
+
)
|
|
477
483
|
.setField('parent_id', child.getID())
|
|
478
484
|
.enforceCreateAsync();
|
|
479
485
|
|
|
480
486
|
await expect(
|
|
481
|
-
ParentEntity.loader(viewerContext
|
|
487
|
+
ParentEntity.loader(viewerContext, viewerContext.getQueryContext())
|
|
488
|
+
.enforcing()
|
|
489
|
+
.loadByIDNullableAsync(parent.getID())
|
|
482
490
|
).resolves.not.toBeNull();
|
|
483
491
|
await expect(
|
|
484
|
-
ChildEntity.loader(viewerContext
|
|
492
|
+
ChildEntity.loader(viewerContext, viewerContext.getQueryContext())
|
|
493
|
+
.enforcing()
|
|
494
|
+
.loadByIDNullableAsync(child.getID())
|
|
485
495
|
).resolves.not.toBeNull();
|
|
486
496
|
await expect(
|
|
487
|
-
GrandChildEntity.loader(viewerContext
|
|
497
|
+
GrandChildEntity.loader(viewerContext, viewerContext.getQueryContext())
|
|
498
|
+
.enforcing()
|
|
499
|
+
.loadByIDNullableAsync(grandchild.getID())
|
|
488
500
|
).resolves.not.toBeNull();
|
|
489
501
|
|
|
490
502
|
privacyPolicyEvaluationRecords.shouldRecord = true;
|
|
491
|
-
await ParentEntity.enforceDeleteAsync(parent);
|
|
503
|
+
await ParentEntity.enforceDeleteAsync(parent, viewerContext.getQueryContext());
|
|
492
504
|
privacyPolicyEvaluationRecords.shouldRecord = false;
|
|
493
505
|
|
|
494
506
|
await expect(
|
|
495
|
-
ParentEntity.loader(viewerContext
|
|
507
|
+
ParentEntity.loader(viewerContext, viewerContext.getQueryContext())
|
|
508
|
+
.enforcing()
|
|
509
|
+
.loadByIDNullableAsync(parent.getID())
|
|
496
510
|
).resolves.toBeNull();
|
|
497
511
|
await expect(
|
|
498
|
-
ChildEntity.loader(viewerContext
|
|
512
|
+
ChildEntity.loader(viewerContext, viewerContext.getQueryContext())
|
|
513
|
+
.enforcing()
|
|
514
|
+
.loadByIDNullableAsync(child.getID())
|
|
499
515
|
).resolves.toBeNull();
|
|
500
516
|
await expect(
|
|
501
|
-
GrandChildEntity.loader(viewerContext
|
|
517
|
+
GrandChildEntity.loader(viewerContext, viewerContext.getQueryContext())
|
|
518
|
+
.enforcing()
|
|
519
|
+
.loadByIDNullableAsync(grandchild.getID())
|
|
502
520
|
).resolves.toBeNull();
|
|
503
521
|
|
|
504
522
|
// two calls for each trigger, one beforeDelete, one afterDelete
|
|
@@ -587,38 +605,55 @@ describe('EntityMutator.processEntityDeletionForInboundEdgesAsync', () => {
|
|
|
587
605
|
const companionProvider = createUnitTestEntityCompanionProvider();
|
|
588
606
|
const viewerContext = new TestViewerContext(companionProvider);
|
|
589
607
|
|
|
590
|
-
const parent = await ParentEntity.creator(
|
|
591
|
-
|
|
608
|
+
const parent = await ParentEntity.creator(
|
|
609
|
+
viewerContext,
|
|
610
|
+
viewerContext.getQueryContext()
|
|
611
|
+
).enforceCreateAsync();
|
|
612
|
+
const child = await ChildEntity.creator(viewerContext, viewerContext.getQueryContext())
|
|
592
613
|
.setField('parent_id', parent.getID())
|
|
593
614
|
.enforceCreateAsync();
|
|
594
|
-
const grandchild = await GrandChildEntity.creator(
|
|
615
|
+
const grandchild = await GrandChildEntity.creator(
|
|
616
|
+
viewerContext,
|
|
617
|
+
viewerContext.getQueryContext()
|
|
618
|
+
)
|
|
595
619
|
.setField('parent_id', child.getID())
|
|
596
620
|
.enforceCreateAsync();
|
|
597
621
|
|
|
598
622
|
await expect(
|
|
599
|
-
ParentEntity.loader(viewerContext
|
|
623
|
+
ParentEntity.loader(viewerContext, viewerContext.getQueryContext())
|
|
624
|
+
.enforcing()
|
|
625
|
+
.loadByIDNullableAsync(parent.getID())
|
|
600
626
|
).resolves.not.toBeNull();
|
|
601
627
|
await expect(
|
|
602
|
-
ChildEntity.loader(viewerContext
|
|
628
|
+
ChildEntity.loader(viewerContext, viewerContext.getQueryContext())
|
|
629
|
+
.enforcing()
|
|
630
|
+
.loadByIDNullableAsync(child.getID())
|
|
603
631
|
).resolves.not.toBeNull();
|
|
604
632
|
await expect(
|
|
605
|
-
GrandChildEntity.loader(viewerContext
|
|
633
|
+
GrandChildEntity.loader(viewerContext, viewerContext.getQueryContext())
|
|
634
|
+
.enforcing()
|
|
635
|
+
.loadByIDNullableAsync(grandchild.getID())
|
|
606
636
|
).resolves.not.toBeNull();
|
|
607
637
|
|
|
608
638
|
privacyPolicyEvaluationRecords.shouldRecord = true;
|
|
609
|
-
await ParentEntity.enforceDeleteAsync(parent);
|
|
639
|
+
await ParentEntity.enforceDeleteAsync(parent, viewerContext.getQueryContext());
|
|
610
640
|
privacyPolicyEvaluationRecords.shouldRecord = false;
|
|
611
641
|
|
|
612
642
|
await expect(
|
|
613
|
-
ParentEntity.loader(viewerContext
|
|
643
|
+
ParentEntity.loader(viewerContext, viewerContext.getQueryContext())
|
|
644
|
+
.enforcing()
|
|
645
|
+
.loadByIDNullableAsync(parent.getID())
|
|
614
646
|
).resolves.toBeNull();
|
|
615
647
|
|
|
616
|
-
const loadedChild = await ChildEntity.loader(viewerContext)
|
|
648
|
+
const loadedChild = await ChildEntity.loader(viewerContext, viewerContext.getQueryContext())
|
|
617
649
|
.enforcing()
|
|
618
650
|
.loadByIDAsync(child.getID());
|
|
619
651
|
expect(loadedChild.getField('parent_id')).toBeNull();
|
|
620
652
|
|
|
621
|
-
const loadedGrandchild = await GrandChildEntity.loader(
|
|
653
|
+
const loadedGrandchild = await GrandChildEntity.loader(
|
|
654
|
+
viewerContext,
|
|
655
|
+
viewerContext.getQueryContext()
|
|
656
|
+
)
|
|
622
657
|
.enforcing()
|
|
623
658
|
.loadByIDAsync(grandchild.getID());
|
|
624
659
|
expect(loadedGrandchild.getField('parent_id')).toEqual(loadedChild.getID());
|
|
@@ -698,24 +733,32 @@ describe('EntityMutator.processEntityDeletionForInboundEdgesAsync', () => {
|
|
|
698
733
|
const companionProvider = createUnitTestEntityCompanionProvider();
|
|
699
734
|
const viewerContext = new TestViewerContext(companionProvider);
|
|
700
735
|
|
|
701
|
-
const parent = await ParentEntity.creator(
|
|
702
|
-
|
|
736
|
+
const parent = await ParentEntity.creator(
|
|
737
|
+
viewerContext,
|
|
738
|
+
viewerContext.getQueryContext()
|
|
739
|
+
).enforceCreateAsync();
|
|
740
|
+
const child = await ChildEntity.creator(viewerContext, viewerContext.getQueryContext())
|
|
703
741
|
.setField('parent_id', parent.getID())
|
|
704
742
|
.enforceCreateAsync();
|
|
705
|
-
const grandchild = await GrandChildEntity.creator(
|
|
743
|
+
const grandchild = await GrandChildEntity.creator(
|
|
744
|
+
viewerContext,
|
|
745
|
+
viewerContext.getQueryContext()
|
|
746
|
+
)
|
|
706
747
|
.setField('parent_id', child.getID())
|
|
707
748
|
.enforceCreateAsync();
|
|
708
749
|
|
|
709
750
|
await expect(
|
|
710
|
-
ParentEntity.loader(viewerContext
|
|
751
|
+
ParentEntity.loader(viewerContext, viewerContext.getQueryContext())
|
|
752
|
+
.enforcing()
|
|
753
|
+
.loadByIDNullableAsync(parent.getID())
|
|
711
754
|
).resolves.not.toBeNull();
|
|
712
755
|
await expect(
|
|
713
|
-
ChildEntity.loader(viewerContext)
|
|
756
|
+
ChildEntity.loader(viewerContext, viewerContext.getQueryContext())
|
|
714
757
|
.enforcing()
|
|
715
758
|
.loadByFieldEqualingAsync('parent_id', parent.getID())
|
|
716
759
|
).resolves.not.toBeNull();
|
|
717
760
|
await expect(
|
|
718
|
-
GrandChildEntity.loader(viewerContext)
|
|
761
|
+
GrandChildEntity.loader(viewerContext, viewerContext.getQueryContext())
|
|
719
762
|
.enforcing()
|
|
720
763
|
.loadByFieldEqualingAsync('parent_id', child.getID())
|
|
721
764
|
).resolves.not.toBeNull();
|
|
@@ -739,7 +782,7 @@ describe('EntityMutator.processEntityDeletionForInboundEdgesAsync', () => {
|
|
|
739
782
|
expect(grandChildCachedBefore.get(child.getID())?.status).toEqual(CacheStatus.HIT);
|
|
740
783
|
|
|
741
784
|
privacyPolicyEvaluationRecords.shouldRecord = true;
|
|
742
|
-
await ParentEntity.enforceDeleteAsync(parent);
|
|
785
|
+
await ParentEntity.enforceDeleteAsync(parent, viewerContext.getQueryContext());
|
|
743
786
|
privacyPolicyEvaluationRecords.shouldRecord = false;
|
|
744
787
|
|
|
745
788
|
const childCachedAfter = await childCacheAdapter.loadManyAsync('parent_id', [parent.getID()]);
|
|
@@ -751,15 +794,20 @@ describe('EntityMutator.processEntityDeletionForInboundEdgesAsync', () => {
|
|
|
751
794
|
expect(grandChildCachedAfter.get(child.getID())?.status).toEqual(CacheStatus.HIT);
|
|
752
795
|
|
|
753
796
|
await expect(
|
|
754
|
-
ParentEntity.loader(viewerContext
|
|
797
|
+
ParentEntity.loader(viewerContext, viewerContext.getQueryContext())
|
|
798
|
+
.enforcing()
|
|
799
|
+
.loadByIDNullableAsync(parent.getID())
|
|
755
800
|
).resolves.toBeNull();
|
|
756
801
|
|
|
757
|
-
const loadedChild = await ChildEntity.loader(viewerContext)
|
|
802
|
+
const loadedChild = await ChildEntity.loader(viewerContext, viewerContext.getQueryContext())
|
|
758
803
|
.enforcing()
|
|
759
804
|
.loadByIDAsync(child.getID());
|
|
760
805
|
expect(loadedChild).not.toBeNull();
|
|
761
806
|
|
|
762
|
-
const loadedGrandchild = await GrandChildEntity.loader(
|
|
807
|
+
const loadedGrandchild = await GrandChildEntity.loader(
|
|
808
|
+
viewerContext,
|
|
809
|
+
viewerContext.getQueryContext()
|
|
810
|
+
)
|
|
763
811
|
.enforcing()
|
|
764
812
|
.loadByIDAsync(grandchild.getID());
|
|
765
813
|
expect(loadedGrandchild.getField('parent_id')).toEqual(loadedChild.getID());
|
|
@@ -831,24 +879,32 @@ describe('EntityMutator.processEntityDeletionForInboundEdgesAsync', () => {
|
|
|
831
879
|
const companionProvider = createUnitTestEntityCompanionProvider();
|
|
832
880
|
const viewerContext = new TestViewerContext(companionProvider);
|
|
833
881
|
|
|
834
|
-
const parent = await ParentEntity.creator(
|
|
835
|
-
|
|
882
|
+
const parent = await ParentEntity.creator(
|
|
883
|
+
viewerContext,
|
|
884
|
+
viewerContext.getQueryContext()
|
|
885
|
+
).enforceCreateAsync();
|
|
886
|
+
const child = await ChildEntity.creator(viewerContext, viewerContext.getQueryContext())
|
|
836
887
|
.setField('parent_id', parent.getID())
|
|
837
888
|
.enforceCreateAsync();
|
|
838
|
-
const grandchild = await GrandChildEntity.creator(
|
|
889
|
+
const grandchild = await GrandChildEntity.creator(
|
|
890
|
+
viewerContext,
|
|
891
|
+
viewerContext.getQueryContext()
|
|
892
|
+
)
|
|
839
893
|
.setField('parent_id', child.getID())
|
|
840
894
|
.enforceCreateAsync();
|
|
841
895
|
|
|
842
896
|
await expect(
|
|
843
|
-
ParentEntity.loader(viewerContext
|
|
897
|
+
ParentEntity.loader(viewerContext, viewerContext.getQueryContext())
|
|
898
|
+
.enforcing()
|
|
899
|
+
.loadByIDNullableAsync(parent.getID())
|
|
844
900
|
).resolves.not.toBeNull();
|
|
845
901
|
await expect(
|
|
846
|
-
ChildEntity.loader(viewerContext)
|
|
902
|
+
ChildEntity.loader(viewerContext, viewerContext.getQueryContext())
|
|
847
903
|
.enforcing()
|
|
848
904
|
.loadByFieldEqualingAsync('parent_id', parent.getID())
|
|
849
905
|
).resolves.not.toBeNull();
|
|
850
906
|
await expect(
|
|
851
|
-
GrandChildEntity.loader(viewerContext)
|
|
907
|
+
GrandChildEntity.loader(viewerContext, viewerContext.getQueryContext())
|
|
852
908
|
.enforcing()
|
|
853
909
|
.loadByFieldEqualingAsync('parent_id', child.getID())
|
|
854
910
|
).resolves.not.toBeNull();
|
|
@@ -872,7 +928,7 @@ describe('EntityMutator.processEntityDeletionForInboundEdgesAsync', () => {
|
|
|
872
928
|
expect(grandChildCachedBefore.get(child.getID())?.status).toEqual(CacheStatus.HIT);
|
|
873
929
|
|
|
874
930
|
privacyPolicyEvaluationRecords.shouldRecord = true;
|
|
875
|
-
await ParentEntity.enforceDeleteAsync(parent);
|
|
931
|
+
await ParentEntity.enforceDeleteAsync(parent, viewerContext.getQueryContext());
|
|
876
932
|
privacyPolicyEvaluationRecords.shouldRecord = false;
|
|
877
933
|
|
|
878
934
|
const childCachedAfter = await childCacheAdapter.loadManyAsync('parent_id', [parent.getID()]);
|
|
@@ -884,13 +940,19 @@ describe('EntityMutator.processEntityDeletionForInboundEdgesAsync', () => {
|
|
|
884
940
|
expect(grandChildCachedAfter.get(child.getID())?.status).toEqual(CacheStatus.MISS);
|
|
885
941
|
|
|
886
942
|
await expect(
|
|
887
|
-
ParentEntity.loader(viewerContext
|
|
943
|
+
ParentEntity.loader(viewerContext, viewerContext.getQueryContext())
|
|
944
|
+
.enforcing()
|
|
945
|
+
.loadByIDNullableAsync(parent.getID())
|
|
888
946
|
).resolves.toBeNull();
|
|
889
947
|
await expect(
|
|
890
|
-
ChildEntity.loader(viewerContext
|
|
948
|
+
ChildEntity.loader(viewerContext, viewerContext.getQueryContext())
|
|
949
|
+
.enforcing()
|
|
950
|
+
.loadByIDNullableAsync(child.getID())
|
|
891
951
|
).resolves.not.toBeNull();
|
|
892
952
|
await expect(
|
|
893
|
-
GrandChildEntity.loader(viewerContext
|
|
953
|
+
GrandChildEntity.loader(viewerContext, viewerContext.getQueryContext())
|
|
954
|
+
.enforcing()
|
|
955
|
+
.loadByIDNullableAsync(grandchild.getID())
|
|
894
956
|
).resolves.not.toBeNull();
|
|
895
957
|
|
|
896
958
|
// two calls for each trigger, one beforeDelete, one afterDelete
|
|
@@ -55,7 +55,13 @@ describe(EntityFieldDefinition, () => {
|
|
|
55
55
|
describeFieldTestCase(new StringField({ columnName: 'wat' }), ['hello', ''], [1, true, {}, [[]]]);
|
|
56
56
|
describeFieldTestCase(
|
|
57
57
|
new UUIDField({ columnName: 'wat' }),
|
|
58
|
-
[
|
|
58
|
+
[
|
|
59
|
+
uuidv1(),
|
|
60
|
+
uuidv3('wat', uuidv3.DNS),
|
|
61
|
+
uuidv4(),
|
|
62
|
+
uuidv5('wat', uuidv5.DNS),
|
|
63
|
+
/* UUIDv7 */ '018ebfda-dc80-782d-a891-22a0aa057d52',
|
|
64
|
+
],
|
|
59
65
|
[uuidv4().replace('-', ''), '', 'hello']
|
|
60
66
|
);
|
|
61
67
|
describeFieldTestCase(new DateField({ columnName: 'wat' }), [new Date()], [Date.now()]);
|
|
@@ -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.getNonTransactionalQueryContext();
|
|
127
127
|
|
|
128
128
|
const databaseAdapter = new StubDatabaseAdapter<TestFields>(
|
|
129
129
|
testEntityConfiguration,
|
|
@@ -5,7 +5,6 @@ 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';
|
|
9
8
|
import { enforceResultsAsync } from '../entityUtils';
|
|
10
9
|
import EntityDataManager from '../internal/EntityDataManager';
|
|
11
10
|
import ReadThroughEntityCache from '../internal/ReadThroughEntityCache';
|
|
@@ -15,6 +14,7 @@ import TestEntity, {
|
|
|
15
14
|
TestEntityPrivacyPolicy,
|
|
16
15
|
testEntityConfiguration,
|
|
17
16
|
} 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(TestViewerContext));
|
|
26
26
|
const privacyPolicyEvaluationContext = instance(mock<EntityPrivacyPolicyEvaluationContext>());
|
|
27
27
|
const metricsAdapter = instance(mock<IEntityMetricsAdapter>());
|
|
28
|
-
const queryContext = StubQueryContextProvider.
|
|
28
|
+
const queryContext = StubQueryContextProvider.getNonTransactionalQueryContext();
|
|
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(TestViewerContext));
|
|
121
121
|
const privacyPolicyEvaluationContext = instance(mock<EntityPrivacyPolicyEvaluationContext>());
|
|
122
122
|
const metricsAdapter = instance(mock<IEntityMetricsAdapter>());
|
|
123
|
-
const queryContext = StubQueryContextProvider.
|
|
123
|
+
const queryContext = StubQueryContextProvider.getNonTransactionalQueryContext();
|
|
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(TestViewerContext));
|
|
220
220
|
const privacyPolicyEvaluationContext = instance(mock<EntityPrivacyPolicyEvaluationContext>());
|
|
221
221
|
const metricsAdapter = instance(mock<IEntityMetricsAdapter>());
|
|
222
|
-
const queryContext = StubQueryContextProvider.
|
|
222
|
+
const queryContext = StubQueryContextProvider.getNonTransactionalQueryContext();
|
|
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(TestViewerContext));
|
|
317
317
|
const privacyPolicyEvaluationContext = instance(mock<EntityPrivacyPolicyEvaluationContext>());
|
|
318
318
|
const metricsAdapter = instance(mock<IEntityMetricsAdapter>());
|
|
319
|
-
const queryContext = StubQueryContextProvider.
|
|
319
|
+
const queryContext = StubQueryContextProvider.getNonTransactionalQueryContext();
|
|
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(TestViewerContext));
|
|
378
378
|
const privacyPolicyEvaluationContext = instance(mock<EntityPrivacyPolicyEvaluationContext>());
|
|
379
379
|
const metricsAdapter = instance(mock<IEntityMetricsAdapter>());
|
|
380
|
-
const queryContext = StubQueryContextProvider.
|
|
380
|
+
const queryContext = StubQueryContextProvider.getNonTransactionalQueryContext();
|
|
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(TestViewerContext));
|
|
406
406
|
const privacyPolicyEvaluationContext = instance(mock<EntityPrivacyPolicyEvaluationContext>());
|
|
407
407
|
const metricsAdapter = instance(mock<IEntityMetricsAdapter>());
|
|
408
|
-
const queryContext = StubQueryContextProvider.
|
|
408
|
+
const queryContext = StubQueryContextProvider.getNonTransactionalQueryContext();
|
|
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(TestViewerContext));
|
|
433
433
|
const privacyPolicyEvaluationContext = instance(mock<EntityPrivacyPolicyEvaluationContext>());
|
|
434
434
|
const metricsAdapter = instance(mock<IEntityMetricsAdapter>());
|
|
435
|
-
const queryContext = StubQueryContextProvider.
|
|
435
|
+
const queryContext = StubQueryContextProvider.getNonTransactionalQueryContext();
|
|
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(TestViewerContext));
|
|
464
464
|
const privacyPolicyEvaluationContext = instance(mock<EntityPrivacyPolicyEvaluationContext>());
|
|
465
465
|
const metricsAdapter = instance(mock<IEntityMetricsAdapter>());
|
|
466
|
-
const queryContext = StubQueryContextProvider.
|
|
466
|
+
const queryContext = StubQueryContextProvider.getNonTransactionalQueryContext();
|
|
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(TestViewerContext));
|
|
510
510
|
const privacyPolicyEvaluationContext = instance(mock<EntityPrivacyPolicyEvaluationContext>());
|
|
511
511
|
const metricsAdapter = instance(mock<IEntityMetricsAdapter>());
|
|
512
|
-
const queryContext = StubQueryContextProvider.
|
|
512
|
+
const queryContext = StubQueryContextProvider.getNonTransactionalQueryContext();
|
|
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';
|
|
9
8
|
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
|
+
TestViewerContext,
|
|
20
20
|
BlahEntity
|
|
21
21
|
> {
|
|
22
22
|
protected override readonly createRules = [
|
|
23
|
-
new AlwaysAllowPrivacyPolicyRule<BlahFields, string,
|
|
23
|
+
new AlwaysAllowPrivacyPolicyRule<BlahFields, string, TestViewerContext, BlahEntity>(),
|
|
24
24
|
];
|
|
25
25
|
protected override readonly readRules = [
|
|
26
|
-
new AlwaysAllowPrivacyPolicyRule<BlahFields, string,
|
|
26
|
+
new AlwaysAllowPrivacyPolicyRule<BlahFields, string, TestViewerContext, BlahEntity>(),
|
|
27
27
|
];
|
|
28
28
|
protected override readonly updateRules = [
|
|
29
|
-
new AlwaysAllowPrivacyPolicyRule<BlahFields, string,
|
|
29
|
+
new AlwaysAllowPrivacyPolicyRule<BlahFields, string, TestViewerContext, BlahEntity>(),
|
|
30
30
|
];
|
|
31
31
|
protected override readonly deleteRules = [
|
|
32
|
-
new AlwaysAllowPrivacyPolicyRule<BlahFields, string,
|
|
32
|
+
new AlwaysAllowPrivacyPolicyRule<BlahFields, string, TestViewerContext, BlahEntity>(),
|
|
33
33
|
];
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
class BlahEntity extends Entity<BlahFields, string,
|
|
36
|
+
class BlahEntity extends Entity<BlahFields, string, TestViewerContext> {
|
|
37
37
|
static defineCompanionDefinition(): EntityCompanionDefinition<
|
|
38
38
|
BlahFields,
|
|
39
39
|
string,
|
|
40
|
-
|
|
40
|
+
TestViewerContext,
|
|
41
41
|
BlahEntity,
|
|
42
42
|
BlahEntityPrivacyPolicy
|
|
43
43
|
> {
|
|
@@ -66,16 +66,16 @@ class BlahEntity extends Entity<BlahFields, string, ViewerContext> {
|
|
|
66
66
|
class TestNonTransactionalMutationTrigger extends EntityNonTransactionalMutationTrigger<
|
|
67
67
|
BlahFields,
|
|
68
68
|
string,
|
|
69
|
-
|
|
69
|
+
TestViewerContext,
|
|
70
70
|
BlahEntity
|
|
71
71
|
> {
|
|
72
72
|
async executeAsync(
|
|
73
|
-
viewerContext:
|
|
73
|
+
viewerContext: TestViewerContext,
|
|
74
74
|
entity: BlahEntity,
|
|
75
|
-
mutationInfo: EntityTriggerMutationInfo<BlahFields, string,
|
|
75
|
+
mutationInfo: EntityTriggerMutationInfo<BlahFields, string, TestViewerContext, 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, viewerContext.getQueryContext())
|
|
79
79
|
.enforcing()
|
|
80
80
|
.loadByIDNullableAsync(entity.getID());
|
|
81
81
|
if (entityLoaded) {
|
|
@@ -90,14 +90,17 @@ 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 TestViewerContext(companionProvider);
|
|
94
94
|
|
|
95
95
|
// put it in cache
|
|
96
|
-
const entity = await BlahEntity.creator(
|
|
97
|
-
|
|
96
|
+
const entity = await BlahEntity.creator(
|
|
97
|
+
viewerContext,
|
|
98
|
+
viewerContext.getQueryContext()
|
|
99
|
+
).enforceCreateAsync();
|
|
100
|
+
const entityLoaded = await BlahEntity.loader(viewerContext, viewerContext.getQueryContext())
|
|
98
101
|
.enforcing()
|
|
99
102
|
.loadByIDAsync(entity.getID());
|
|
100
103
|
|
|
101
|
-
await BlahEntity.enforceDeleteAsync(entityLoaded);
|
|
104
|
+
await BlahEntity.enforceDeleteAsync(entityLoaded, viewerContext.getQueryContext());
|
|
102
105
|
});
|
|
103
106
|
});
|