@peerbit/indexer-tests 1.0.4 → 1.1.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/src/tests.ts CHANGED
@@ -13,28 +13,25 @@ import {
13
13
  BoolQuery,
14
14
  ByteMatchQuery,
15
15
  Compare,
16
- CountRequest,
17
- DeleteRequest,
18
16
  type Index,
19
17
  type IndexEngineInitProperties,
18
+ type IndexIterator,
20
19
  type Indices,
21
20
  IntegerCompare,
22
21
  IsNull,
22
+ type IterateOptions,
23
23
  Nested,
24
24
  Not,
25
25
  Or,
26
26
  Query,
27
- SearchRequest,
28
27
  type Shape,
29
28
  Sort,
30
29
  SortDirection,
31
30
  StringMatch,
32
31
  StringMatchMethod,
33
- SumRequest,
34
32
  extractFieldValue,
35
33
  getIdProperty,
36
34
  id,
37
- iterate,
38
35
  toId,
39
36
  } from "@peerbit/indexer-interface";
40
37
  import {
@@ -125,14 +122,21 @@ class DocumentNext extends Base {
125
122
  const bigIntSort = <T extends number | bigint>(a: T, b: T): number =>
126
123
  a > b ? 1 : 0 || -(a < b);
127
124
 
128
- const search = <T>(
125
+ const search = <T, S extends Shape | undefined>(
129
126
  index: Index<T, any>,
130
- query: SearchRequest,
131
- options?: { shape: Shape },
127
+ query: IterateOptions,
128
+ options?: { shape: S },
132
129
  ) => {
133
130
  // fetch max u32
134
- query.fetch = 0xffffffff;
135
- return index.query(query, options);
131
+ return index.iterate<S>(query, options).all();
132
+ };
133
+
134
+ const assertIteratorIsDone = async (iterator: IndexIterator<any, any>) => {
135
+ const next = await iterator.next(1);
136
+ if (next.length > 0) {
137
+ throw new Error(`Iterator is not done, got more results`);
138
+ }
139
+ expect(iterator.done()).to.be.true;
136
140
  };
137
141
 
138
142
  export const tests = (
@@ -307,11 +311,9 @@ export const tests = (
307
311
  }
308
312
  }
309
313
 
310
- await store.del(
311
- new DeleteRequest({
312
- query: deleteQueryObject,
313
- }),
314
- );
314
+ await store.del({
315
+ query: deleteQueryObject,
316
+ });
315
317
  expect(await store.getSize()).equal(0);
316
318
  result = await store.get(toId(docId));
317
319
 
@@ -396,20 +398,17 @@ export const tests = (
396
398
 
397
399
  await store.put(doc);
398
400
 
399
- const results = await search(
400
- store,
401
- new SearchRequest({
402
- query: [
403
- new StringMatch({
404
- key: "id",
405
- value: "123",
406
- caseInsensitive: false,
407
- method: StringMatchMethod.contains,
408
- }),
409
- ],
410
- }),
411
- );
412
- expect(results.results).to.have.length(1);
401
+ const results = await search(store, {
402
+ query: [
403
+ new StringMatch({
404
+ key: "id",
405
+ value: "123",
406
+ caseInsensitive: false,
407
+ method: StringMatchMethod.contains,
408
+ }),
409
+ ],
410
+ });
411
+ expect(results).to.have.length(1);
413
412
  });
414
413
  });
415
414
 
@@ -569,9 +568,9 @@ export const tests = (
569
568
  it("no-args", async () => {
570
569
  await setupDefault();
571
570
 
572
- const results = await search(store, new SearchRequest({ query: [] }));
573
- expect(results.results).to.have.length(4);
574
- for (const result of results.results) {
571
+ const results = await search(store, { query: [] });
572
+ expect(results).to.have.length(4);
573
+ for (const result of results) {
575
574
  checkDocument(result.value, ...defaultDocs);
576
575
  }
577
576
  });
@@ -581,136 +580,115 @@ export const tests = (
581
580
  await setupDefault();
582
581
  });
583
582
  it("exact", async () => {
584
- const responses = await search(
585
- store,
586
- new SearchRequest({
587
- query: [
588
- new StringMatch({
589
- key: "name",
590
- value: "hello world",
591
- caseInsensitive: true,
592
- }),
593
- ],
594
- }),
595
- );
596
- expect(
597
- responses.results.map((x) => x.id.primitive),
598
- ).to.have.members(["1", "2"]);
583
+ const responses = await search(store, {
584
+ query: [
585
+ new StringMatch({
586
+ key: "name",
587
+ value: "hello world",
588
+ caseInsensitive: true,
589
+ }),
590
+ ],
591
+ });
592
+ expect(responses.map((x) => x.id.primitive)).to.have.members([
593
+ "1",
594
+ "2",
595
+ ]);
599
596
  });
600
597
 
601
598
  it("exact-case-insensitive", async () => {
602
- const responses = await search(
603
- store,
604
- new SearchRequest({
605
- query: [
606
- new StringMatch({
607
- key: "name",
608
- value: "Hello World",
609
- caseInsensitive: true,
610
- }),
611
- ],
612
- }),
613
- );
614
- expect(responses.results).to.have.length(2);
615
- expect(
616
- responses.results.map((x) => x.id.primitive),
617
- ).to.have.members(["1", "2"]);
599
+ const responses = await search(store, {
600
+ query: [
601
+ new StringMatch({
602
+ key: "name",
603
+ value: "Hello World",
604
+ caseInsensitive: true,
605
+ }),
606
+ ],
607
+ });
608
+ expect(responses).to.have.length(2);
609
+ expect(responses.map((x) => x.id.primitive)).to.have.members([
610
+ "1",
611
+ "2",
612
+ ]);
618
613
  });
619
614
 
620
615
  it("exact case sensitive", async () => {
621
- let responses = await search(
622
- store,
623
- new SearchRequest({
624
- query: [
625
- new StringMatch({
626
- key: "name",
627
- value: "Hello World",
628
- caseInsensitive: false,
629
- }),
630
- ],
631
- }),
632
- );
633
- expect(responses.results).to.have.length(1);
634
- expect(
635
- responses.results.map((x) => x.id.primitive),
636
- ).to.have.members(["2"]);
637
- responses = await search(
638
- store,
639
- new SearchRequest({
640
- query: [
641
- new StringMatch({
642
- key: "name",
643
- value: "hello world",
644
- caseInsensitive: false,
645
- }),
646
- ],
647
- }),
648
- );
649
- expect(
650
- responses.results.map((x) => x.id.primitive),
651
- ).to.have.members(["1"]);
616
+ let responses = await search(store, {
617
+ query: [
618
+ new StringMatch({
619
+ key: "name",
620
+ value: "Hello World",
621
+ caseInsensitive: false,
622
+ }),
623
+ ],
624
+ });
625
+ expect(responses).to.have.length(1);
626
+ expect(responses.map((x) => x.id.primitive)).to.have.members(["2"]);
627
+ responses = await search(store, {
628
+ query: [
629
+ new StringMatch({
630
+ key: "name",
631
+ value: "hello world",
632
+ caseInsensitive: false,
633
+ }),
634
+ ],
635
+ });
636
+ expect(responses.map((x) => x.id.primitive)).to.have.members(["1"]);
652
637
  });
653
638
  it("prefix", async () => {
654
- const responses = await search(
655
- store,
656
- new SearchRequest({
657
- query: [
658
- new StringMatch({
659
- key: "name",
660
- value: "hel",
661
- method: StringMatchMethod.prefix,
662
- caseInsensitive: true,
663
- }),
664
- ],
665
- }),
666
- );
667
- expect(responses.results).to.have.length(2);
668
- expect(
669
- responses.results.map((x) => x.id.primitive),
670
- ).to.have.members(["1", "2"]);
639
+ const responses = await search(store, {
640
+ query: [
641
+ new StringMatch({
642
+ key: "name",
643
+ value: "hel",
644
+ method: StringMatchMethod.prefix,
645
+ caseInsensitive: true,
646
+ }),
647
+ ],
648
+ });
649
+ expect(responses).to.have.length(2);
650
+ expect(responses.map((x) => x.id.primitive)).to.have.members([
651
+ "1",
652
+ "2",
653
+ ]);
671
654
  });
672
655
 
673
656
  it("contains", async () => {
674
- const responses = await search(
675
- store,
676
- new SearchRequest({
657
+ const responses = await search(store, {
658
+ query: [
659
+ new StringMatch({
660
+ key: "name",
661
+ value: "ello",
662
+ method: StringMatchMethod.contains,
663
+ caseInsensitive: true,
664
+ }),
665
+ ],
666
+ });
667
+ expect(responses).to.have.length(2);
668
+ expect(responses.map((x) => x.id.primitive)).to.have.members([
669
+ "1",
670
+ "2",
671
+ ]);
672
+ });
673
+
674
+ describe("arr", () => {
675
+ it("arr", async () => {
676
+ const responses = await search(store, {
677
677
  query: [
678
678
  new StringMatch({
679
- key: "name",
680
- value: "ello",
679
+ key: "tags",
680
+ value: "world",
681
681
  method: StringMatchMethod.contains,
682
682
  caseInsensitive: true,
683
683
  }),
684
684
  ],
685
- }),
686
- );
687
- expect(responses.results).to.have.length(2);
688
- expect(
689
- responses.results.map((x) => x.id.primitive),
690
- ).to.have.members(["1", "2"]);
691
- });
692
-
693
- describe("arr", () => {
694
- it("arr", async () => {
695
- const responses = await search(
696
- store,
697
- new SearchRequest({
698
- query: [
699
- new StringMatch({
700
- key: "tags",
701
- value: "world",
702
- method: StringMatchMethod.contains,
703
- caseInsensitive: true,
704
- }),
705
- ],
706
- }),
707
- );
708
- expect(responses.results).to.have.length(1);
709
- expect(
710
- responses.results.map((x) => x.id.primitive),
711
- ).to.have.members(["2"]);
685
+ });
686
+ expect(responses).to.have.length(1);
687
+ expect(responses.map((x) => x.id.primitive)).to.have.members([
688
+ "2",
689
+ ]);
712
690
 
713
- checkDocument(responses.results[0].value, ...defaultDocs);
691
+ checkDocument(responses[0].value, ...defaultDocs);
714
692
  });
715
693
  });
716
694
  });
@@ -718,21 +696,16 @@ export const tests = (
718
696
  it("missing", async () => {
719
697
  await setupDefault();
720
698
 
721
- const responses = await search(
722
- store,
723
- new SearchRequest({
724
- query: [
725
- new IsNull({
726
- key: "name",
727
- }),
728
- ],
729
- }),
730
- );
699
+ const responses = await search(store, {
700
+ query: [
701
+ new IsNull({
702
+ key: "name",
703
+ }),
704
+ ],
705
+ });
731
706
 
732
- expect(responses.results).to.have.length(1);
733
- expect(responses.results.map((x) => x.id.primitive)).to.deep.equal([
734
- "4",
735
- ]);
707
+ expect(responses).to.have.length(1);
708
+ expect(responses.map((x) => x.id.primitive)).to.deep.equal(["4"]);
736
709
  });
737
710
 
738
711
  describe("uint8arrays", () => {
@@ -741,77 +714,65 @@ export const tests = (
741
714
  it("matches", async () => {
742
715
  await setupDefault();
743
716
 
744
- const responses = await search(
745
- store,
746
- new SearchRequest({
747
- query: [
748
- new ByteMatchQuery({
749
- key: "data",
750
- value: new Uint8Array([1]),
751
- }),
752
- ],
753
- }),
754
- );
755
- expect(responses.results).to.have.length(1);
756
- expect(
757
- responses.results.map((x) => x.id.primitive),
758
- ).to.deep.equal(["1"]);
717
+ const responses = await search(store, {
718
+ query: [
719
+ new ByteMatchQuery({
720
+ key: "data",
721
+ value: new Uint8Array([1]),
722
+ }),
723
+ ],
724
+ });
725
+ expect(responses).to.have.length(1);
726
+ expect(responses.map((x) => x.id.primitive)).to.deep.equal([
727
+ "1",
728
+ ]);
759
729
  });
760
730
  it("un-matches", async () => {
761
731
  await setupDefault();
762
732
 
763
- const responses = await search(
764
- store,
765
- new SearchRequest({
766
- query: [
767
- new ByteMatchQuery({
768
- key: "data",
769
- value: new Uint8Array([199]),
770
- }),
771
- ],
772
- }),
773
- );
774
- expect(responses.results).to.be.empty;
733
+ const responses = await search(store, {
734
+ query: [
735
+ new ByteMatchQuery({
736
+ key: "data",
737
+ value: new Uint8Array([199]),
738
+ }),
739
+ ],
740
+ });
741
+ expect(responses).to.be.empty;
775
742
  });
776
743
  });
777
744
  describe("integer", () => {
778
745
  it("exists", async () => {
779
746
  await setupDefault();
780
747
 
781
- const responses = await search(
782
- store,
783
- new SearchRequest({
784
- query: [
785
- new IntegerCompare({
786
- key: "data",
787
- compare: Compare.Equal,
788
- value: 1,
789
- }),
790
- ],
791
- }),
792
- );
793
- expect(responses.results).to.have.length(1);
794
- expect(
795
- responses.results.map((x) => x.id.primitive),
796
- ).to.deep.equal(["1"]);
748
+ const responses = await search(store, {
749
+ query: [
750
+ new IntegerCompare({
751
+ key: "data",
752
+ compare: Compare.Equal,
753
+ value: 1,
754
+ }),
755
+ ],
756
+ });
757
+ expect(responses).to.have.length(1);
758
+ expect(responses.map((x) => x.id.primitive)).to.deep.equal([
759
+ "1",
760
+ ]);
797
761
  });
798
762
 
799
763
  it("does not exist", async () => {
800
764
  await setupDefault();
801
765
 
802
- const responses = await search(
803
- store,
804
- new SearchRequest({
805
- query: [
806
- new IntegerCompare({
807
- key: "data",
808
- compare: Compare.Equal,
809
- value: 199,
810
- }),
811
- ],
812
- }),
813
- );
814
- expect(responses.results).to.be.empty;
766
+ const responses = await search(store, {
767
+ query: [
768
+ new IntegerCompare({
769
+ key: "data",
770
+ compare: Compare.Equal,
771
+ value: 199,
772
+ }),
773
+ ],
774
+ });
775
+ expect(responses).to.be.empty;
815
776
  });
816
777
  });
817
778
  });
@@ -821,77 +782,65 @@ export const tests = (
821
782
  it("matches", async () => {
822
783
  await setupDefault();
823
784
 
824
- const responses = await search(
825
- store,
826
- new SearchRequest({
827
- query: [
828
- new ByteMatchQuery({
829
- key: "fixedData",
830
- value: new Uint8Array(32).fill(1),
831
- }),
832
- ],
833
- }),
834
- );
835
- expect(responses.results).to.have.length(1);
836
- expect(
837
- responses.results.map((x) => x.id.primitive),
838
- ).to.deep.equal(["1"]);
785
+ const responses = await search(store, {
786
+ query: [
787
+ new ByteMatchQuery({
788
+ key: "fixedData",
789
+ value: new Uint8Array(32).fill(1),
790
+ }),
791
+ ],
792
+ });
793
+ expect(responses).to.have.length(1);
794
+ expect(responses.map((x) => x.id.primitive)).to.deep.equal([
795
+ "1",
796
+ ]);
839
797
  });
840
798
  it("un-matches", async () => {
841
799
  await setupDefault();
842
800
 
843
- const responses = await search(
844
- store,
845
- new SearchRequest({
846
- query: [
847
- new ByteMatchQuery({
848
- key: "data",
849
- value: new Uint8Array(32).fill(99),
850
- }),
851
- ],
852
- }),
853
- );
854
- expect(responses.results).to.be.empty;
801
+ const responses = await search(store, {
802
+ query: [
803
+ new ByteMatchQuery({
804
+ key: "data",
805
+ value: new Uint8Array(32).fill(99),
806
+ }),
807
+ ],
808
+ });
809
+ expect(responses).to.be.empty;
855
810
  });
856
811
  });
857
812
  describe("integer", () => {
858
813
  it("exists", async () => {
859
814
  await setupDefault();
860
815
 
861
- const responses = await search(
862
- store,
863
- new SearchRequest({
864
- query: [
865
- new IntegerCompare({
866
- key: "data",
867
- compare: Compare.Equal,
868
- value: 1,
869
- }),
870
- ],
871
- }),
872
- );
873
- expect(responses.results).to.have.length(1);
874
- expect(
875
- responses.results.map((x) => x.id.primitive),
876
- ).to.deep.equal(["1"]);
816
+ const responses = await search(store, {
817
+ query: [
818
+ new IntegerCompare({
819
+ key: "data",
820
+ compare: Compare.Equal,
821
+ value: 1,
822
+ }),
823
+ ],
824
+ });
825
+ expect(responses).to.have.length(1);
826
+ expect(responses.map((x) => x.id.primitive)).to.deep.equal([
827
+ "1",
828
+ ]);
877
829
  });
878
830
 
879
831
  it("does not exist", async () => {
880
832
  await setupDefault();
881
833
 
882
- const responses = await search(
883
- store,
884
- new SearchRequest({
885
- query: [
886
- new IntegerCompare({
887
- key: "data",
888
- compare: Compare.Equal,
889
- value: 199,
890
- }),
891
- ],
892
- }),
893
- );
894
- expect(responses.results).to.be.empty;
834
+ const responses = await search(store, {
835
+ query: [
836
+ new IntegerCompare({
837
+ key: "data",
838
+ compare: Compare.Equal,
839
+ value: 199,
840
+ }),
841
+ ],
842
+ });
843
+ expect(responses).to.be.empty;
895
844
  });
896
845
  });
897
846
  });
@@ -899,21 +848,16 @@ export const tests = (
899
848
  +it("bool", async () => {
900
849
  await setupDefault();
901
850
 
902
- const responses = await search(
903
- store,
904
- new SearchRequest({
905
- query: [
906
- new BoolQuery({
907
- key: "bool",
908
- value: true,
909
- }),
910
- ],
911
- }),
912
- );
913
- expect(responses.results).to.have.length(1);
914
- expect(responses.results.map((x) => x.id.primitive)).to.deep.equal([
915
- "1",
916
- ]);
851
+ const responses = await search(store, {
852
+ query: [
853
+ new BoolQuery({
854
+ key: "bool",
855
+ value: true,
856
+ }),
857
+ ],
858
+ });
859
+ expect(responses).to.have.length(1);
860
+ expect(responses.map((x) => x.id.primitive)).to.deep.equal(["1"]);
917
861
  });
918
862
 
919
863
  describe("array", () => {
@@ -944,20 +888,15 @@ export const tests = (
944
888
  }),
945
889
  );
946
890
 
947
- const results = await search(
948
- store,
949
- new SearchRequest({
950
- query: [
951
- new ByteMatchQuery({
952
- key: "bytesArrays",
953
- value: new Uint8Array([2]),
954
- }),
955
- ],
956
- }),
957
- );
958
- expect(results.results.map((x) => x.value.id)).to.deep.equal([
959
- d1.id,
960
- ]);
891
+ const results = await search(store, {
892
+ query: [
893
+ new ByteMatchQuery({
894
+ key: "bytesArrays",
895
+ value: new Uint8Array([2]),
896
+ }),
897
+ ],
898
+ });
899
+ expect(results.map((x) => x.value.id)).to.deep.equal([d1.id]);
961
900
  });
962
901
  });
963
902
 
@@ -993,19 +932,14 @@ export const tests = (
993
932
  }),
994
933
  );
995
934
 
996
- const results = await search(
997
- store,
998
- new SearchRequest({
999
- query: new IntegerCompare({
1000
- key: ["documents", "number"],
1001
- compare: Compare.Equal,
1002
- value: d1.documents[0]!.number,
1003
- }),
935
+ const results = await search(store, {
936
+ query: new IntegerCompare({
937
+ key: ["documents", "number"],
938
+ compare: Compare.Equal,
939
+ value: d1.documents[0]!.number,
1004
940
  }),
1005
- );
1006
- expect(results.results.map((x) => x.value.id)).to.deep.equal([
1007
- d1.id,
1008
- ]);
941
+ });
942
+ expect(results.map((x) => x.value.id)).to.deep.equal([d1.id]);
1009
943
  });
1010
944
 
1011
945
  it("update array", async () => {
@@ -1028,32 +962,26 @@ export const tests = (
1028
962
  // should have update results
1029
963
  expect(
1030
964
  (
1031
- await search(
1032
- store,
1033
- new SearchRequest({
1034
- query: new IntegerCompare({
1035
- key: ["documents", "number"],
1036
- compare: Compare.Equal,
1037
- value: 123n,
1038
- }),
965
+ await search(store, {
966
+ query: new IntegerCompare({
967
+ key: ["documents", "number"],
968
+ compare: Compare.Equal,
969
+ value: 123n,
1039
970
  }),
1040
- )
1041
- ).results.length,
971
+ })
972
+ ).length,
1042
973
  ).to.equal(0);
1043
974
 
1044
975
  expect(
1045
976
  (
1046
- await search(
1047
- store,
1048
- new SearchRequest({
1049
- query: new IntegerCompare({
1050
- key: ["documents", "number"],
1051
- compare: Compare.Equal,
1052
- value: 124n,
1053
- }),
977
+ await search(store, {
978
+ query: new IntegerCompare({
979
+ key: ["documents", "number"],
980
+ compare: Compare.Equal,
981
+ value: 124n,
1054
982
  }),
1055
- )
1056
- ).results.map((x) => x.value.id),
983
+ })
984
+ ).map((x) => x.value.id),
1057
985
  ).to.deep.equal([d1.id]);
1058
986
  });
1059
987
 
@@ -1067,29 +995,24 @@ export const tests = (
1067
995
  });
1068
996
 
1069
997
  await store.put(d1);
1070
- const [deleted] = await store.del(
1071
- new DeleteRequest({
1072
- query: {
1073
- id: d1.id,
1074
- },
1075
- }),
1076
- );
998
+ const [deleted] = await store.del({
999
+ query: {
1000
+ id: d1.id,
1001
+ },
1002
+ });
1077
1003
 
1078
1004
  expect(deleted.key).to.deep.equal(d1.id);
1079
1005
 
1080
1006
  expect(
1081
1007
  (
1082
- await search(
1083
- store,
1084
- new SearchRequest({
1085
- query: new IntegerCompare({
1086
- key: ["documents", "number"],
1087
- compare: Compare.Equal,
1088
- value: 123n,
1089
- }),
1008
+ await search(store, {
1009
+ query: new IntegerCompare({
1010
+ key: ["documents", "number"],
1011
+ compare: Compare.Equal,
1012
+ value: 123n,
1090
1013
  }),
1091
- )
1092
- ).results.length,
1014
+ })
1015
+ ).length,
1093
1016
  ).to.equal(0);
1094
1017
 
1095
1018
  d1.documents = [
@@ -1099,32 +1022,26 @@ export const tests = (
1099
1022
 
1100
1023
  expect(
1101
1024
  (
1102
- await search(
1103
- store,
1104
- new SearchRequest({
1105
- query: new IntegerCompare({
1106
- key: ["documents", "number"],
1107
- compare: Compare.Equal,
1108
- value: 124n,
1109
- }),
1025
+ await search(store, {
1026
+ query: new IntegerCompare({
1027
+ key: ["documents", "number"],
1028
+ compare: Compare.Equal,
1029
+ value: 124n,
1110
1030
  }),
1111
- )
1112
- ).results.map((x) => x.value.id),
1031
+ })
1032
+ ).map((x) => x.value.id),
1113
1033
  ).to.deep.equal([d1.id]);
1114
1034
 
1115
1035
  expect(
1116
1036
  (
1117
- await search(
1118
- store,
1119
- new SearchRequest({
1120
- query: new IntegerCompare({
1121
- key: ["documents", "number"],
1122
- compare: Compare.Equal,
1123
- value: 123n,
1124
- }),
1037
+ await search(store, {
1038
+ query: new IntegerCompare({
1039
+ key: ["documents", "number"],
1040
+ compare: Compare.Equal,
1041
+ value: 123n,
1125
1042
  }),
1126
- )
1127
- ).results.length,
1043
+ })
1044
+ ).length,
1128
1045
  ).to.equal(0);
1129
1046
  });
1130
1047
  });
@@ -1136,78 +1053,69 @@ export const tests = (
1136
1053
  });
1137
1054
 
1138
1055
  it("and", async () => {
1139
- const responses = await search(
1140
- store,
1141
- new SearchRequest({
1142
- query: [
1143
- new And([
1144
- new StringMatch({
1145
- key: "name",
1146
- value: "hello",
1147
- caseInsensitive: true,
1148
- method: StringMatchMethod.contains,
1149
- }),
1150
- new StringMatch({
1151
- key: "name",
1152
- value: "world",
1153
- caseInsensitive: true,
1154
- method: StringMatchMethod.contains,
1155
- }),
1156
- ]),
1157
- ],
1158
- }),
1159
- );
1160
- expect(responses.results).to.have.length(2);
1161
- expect(
1162
- responses.results.map((x) => x.id.primitive),
1163
- ).to.have.members(["1", "2"]);
1056
+ const responses = await search(store, {
1057
+ query: [
1058
+ new And([
1059
+ new StringMatch({
1060
+ key: "name",
1061
+ value: "hello",
1062
+ caseInsensitive: true,
1063
+ method: StringMatchMethod.contains,
1064
+ }),
1065
+ new StringMatch({
1066
+ key: "name",
1067
+ value: "world",
1068
+ caseInsensitive: true,
1069
+ method: StringMatchMethod.contains,
1070
+ }),
1071
+ ]),
1072
+ ],
1073
+ });
1074
+ expect(responses).to.have.length(2);
1075
+ expect(responses.map((x) => x.id.primitive)).to.have.members([
1076
+ "1",
1077
+ "2",
1078
+ ]);
1164
1079
  });
1165
1080
 
1166
1081
  it("or", async () => {
1167
- const responses = await search(
1168
- store,
1169
- new SearchRequest({
1170
- query: [
1171
- new Or([
1172
- new StringMatch({
1173
- key: "id",
1174
- value: "1",
1175
- }),
1176
- new StringMatch({
1177
- key: "id",
1178
- value: "2",
1179
- }),
1180
- ]),
1181
- ],
1182
- }),
1183
- );
1184
- expect(responses.results).to.have.length(2);
1185
- expect(
1186
- responses.results.map((x) => x.id.primitive),
1187
- ).to.have.members(["1", "2"]);
1082
+ const responses = await search(store, {
1083
+ query: [
1084
+ new Or([
1085
+ new StringMatch({
1086
+ key: "id",
1087
+ value: "1",
1088
+ }),
1089
+ new StringMatch({
1090
+ key: "id",
1091
+ value: "2",
1092
+ }),
1093
+ ]),
1094
+ ],
1095
+ });
1096
+ expect(responses).to.have.length(2);
1097
+ expect(responses.map((x) => x.id.primitive)).to.have.members([
1098
+ "1",
1099
+ "2",
1100
+ ]);
1188
1101
  });
1189
1102
 
1190
1103
  it("not", async () => {
1191
- const responses = await search(
1192
- store,
1193
- new SearchRequest({
1194
- query: [
1195
- new And([
1196
- new Not(
1197
- new IntegerCompare({
1198
- key: "number",
1199
- compare: Compare.Greater,
1200
- value: 1n,
1201
- }),
1202
- ),
1203
- ]),
1204
- ],
1205
- }),
1206
- );
1207
- expect(responses.results).to.have.length(1);
1208
- expect(
1209
- responses.results.map((x) => x.id.primitive),
1210
- ).to.have.members(["1"]);
1104
+ const responses = await search(store, {
1105
+ query: [
1106
+ new And([
1107
+ new Not(
1108
+ new IntegerCompare({
1109
+ key: "number",
1110
+ compare: Compare.Greater,
1111
+ value: 1n,
1112
+ }),
1113
+ ),
1114
+ ]),
1115
+ ],
1116
+ });
1117
+ expect(responses).to.have.length(1);
1118
+ expect(responses.map((x) => x.id.primitive)).to.have.members(["1"]);
1211
1119
  });
1212
1120
  });
1213
1121
 
@@ -1216,96 +1124,81 @@ export const tests = (
1216
1124
  await setupDefault();
1217
1125
  });
1218
1126
  it("equal", async () => {
1219
- const response = await search(
1220
- store,
1221
- new SearchRequest({
1222
- query: [
1223
- new IntegerCompare({
1224
- key: "number",
1225
- compare: Compare.Equal,
1226
- value: 2n,
1227
- }),
1228
- ],
1229
- }),
1230
- );
1231
- expect(response.results).to.have.length(1);
1232
- expect(response.results[0].value.number).to.be.oneOf([2n, 2]);
1127
+ const response = await search(store, {
1128
+ query: [
1129
+ new IntegerCompare({
1130
+ key: "number",
1131
+ compare: Compare.Equal,
1132
+ value: 2n,
1133
+ }),
1134
+ ],
1135
+ });
1136
+ expect(response).to.have.length(1);
1137
+ expect(response[0].value.number).to.be.oneOf([2n, 2]);
1233
1138
  });
1234
1139
 
1235
1140
  it("gt", async () => {
1236
- const response = await search(
1237
- store,
1238
- new SearchRequest({
1239
- query: [
1240
- new IntegerCompare({
1241
- key: "number",
1242
- compare: Compare.Greater,
1243
- value: 2n,
1244
- }),
1245
- ],
1246
- }),
1247
- );
1248
- expect(response.results).to.have.length(1);
1249
- expect(response.results[0].value.number).to.be.oneOf([3n, 3]);
1141
+ const response = await search(store, {
1142
+ query: [
1143
+ new IntegerCompare({
1144
+ key: "number",
1145
+ compare: Compare.Greater,
1146
+ value: 2n,
1147
+ }),
1148
+ ],
1149
+ });
1150
+ expect(response).to.have.length(1);
1151
+ expect(response[0].value.number).to.be.oneOf([3n, 3]);
1250
1152
  });
1251
1153
 
1252
1154
  it("gte", async () => {
1253
- const response = await search(
1254
- store,
1255
- new SearchRequest({
1256
- query: [
1257
- new IntegerCompare({
1258
- key: "number",
1259
- compare: Compare.GreaterOrEqual,
1260
- value: 2n,
1261
- }),
1262
- ],
1263
- }),
1264
- );
1265
- response.results.sort((a, b) =>
1155
+ const response = await search(store, {
1156
+ query: [
1157
+ new IntegerCompare({
1158
+ key: "number",
1159
+ compare: Compare.GreaterOrEqual,
1160
+ value: 2n,
1161
+ }),
1162
+ ],
1163
+ });
1164
+ response.sort((a, b) =>
1266
1165
  bigIntSort(a.value.number as bigint, b.value.number as bigint),
1267
1166
  );
1268
- expect(response.results).to.have.length(2);
1269
- expect(response.results[0].value.number).to.be.oneOf([2n, 2]);
1270
- expect(response.results[1].value.number).to.be.oneOf([3n, 3]);
1167
+ expect(response).to.have.length(2);
1168
+ expect(response[0].value.number).to.be.oneOf([2n, 2]);
1169
+ expect(response[1].value.number).to.be.oneOf([3n, 3]);
1271
1170
  });
1272
1171
 
1273
1172
  it("lt", async () => {
1274
- const response = await search(
1275
- store,
1276
- new SearchRequest({
1277
- query: [
1278
- new IntegerCompare({
1279
- key: "number",
1280
- compare: Compare.Less,
1281
- value: 2n,
1282
- }),
1283
- ],
1284
- }),
1285
- );
1286
- expect(response.results).to.have.length(1);
1287
- expect(response.results[0].value.number).to.be.oneOf([1n, 1]);
1173
+ const response = await search(store, {
1174
+ query: [
1175
+ new IntegerCompare({
1176
+ key: "number",
1177
+ compare: Compare.Less,
1178
+ value: 2n,
1179
+ }),
1180
+ ],
1181
+ });
1182
+ expect(response).to.have.length(1);
1183
+ expect(response[0].value.number).to.be.oneOf([1n, 1]);
1288
1184
  });
1289
1185
 
1290
1186
  it("lte", async () => {
1291
- const response = await search(
1292
- store,
1293
- new SearchRequest({
1294
- query: [
1295
- new IntegerCompare({
1296
- key: "number",
1297
- compare: Compare.LessOrEqual,
1298
- value: 2n,
1299
- }),
1300
- ],
1301
- }),
1302
- );
1303
- response.results.sort((a, b) =>
1187
+ const response = await search(store, {
1188
+ query: [
1189
+ new IntegerCompare({
1190
+ key: "number",
1191
+ compare: Compare.LessOrEqual,
1192
+ value: 2n,
1193
+ }),
1194
+ ],
1195
+ });
1196
+ response.sort((a, b) =>
1304
1197
  bigIntSort(a.value.number as bigint, b.value.number as bigint),
1305
1198
  );
1306
- expect(response.results).to.have.length(2);
1307
- expect(response.results[0].value.number).to.be.oneOf([1n, 1]);
1308
- expect(response.results[1].value.number).to.be.oneOf([2n, 2]);
1199
+ expect(response).to.have.length(2);
1200
+ expect(response[0].value.number).to.be.oneOf([1n, 1]);
1201
+ expect(response[1].value.number).to.be.oneOf([2n, 2]);
1309
1202
  });
1310
1203
  });
1311
1204
 
@@ -1340,97 +1233,82 @@ export const tests = (
1340
1233
  });
1341
1234
 
1342
1235
  it("equal", async () => {
1343
- const response = await search(
1344
- store,
1345
- new SearchRequest({
1346
- query: [
1347
- new IntegerCompare({
1348
- key: "bigint",
1349
- compare: Compare.Equal,
1350
- value: first,
1351
- }),
1352
- ],
1353
- }),
1354
- );
1355
- expect(response.results).to.have.length(1);
1356
- expect(response.results[0].value.bigint).to.equal(first);
1236
+ const response = await search(store, {
1237
+ query: [
1238
+ new IntegerCompare({
1239
+ key: "bigint",
1240
+ compare: Compare.Equal,
1241
+ value: first,
1242
+ }),
1243
+ ],
1244
+ });
1245
+ expect(response).to.have.length(1);
1246
+ expect(response[0].value.bigint).to.equal(first);
1357
1247
  });
1358
1248
 
1359
1249
  it("gt", async () => {
1360
- const response = await search(
1361
- store,
1362
- new SearchRequest({
1363
- query: [
1364
- new IntegerCompare({
1365
- key: "bigint",
1366
- compare: Compare.Greater,
1367
- value: second,
1368
- }),
1369
- ],
1370
- }),
1371
- );
1372
- expect(response.results).to.have.length(1);
1373
- expect(response.results[0].value.bigint).to.equal(third);
1250
+ const response = await search(store, {
1251
+ query: [
1252
+ new IntegerCompare({
1253
+ key: "bigint",
1254
+ compare: Compare.Greater,
1255
+ value: second,
1256
+ }),
1257
+ ],
1258
+ });
1259
+ expect(response).to.have.length(1);
1260
+ expect(response[0].value.bigint).to.equal(third);
1374
1261
  });
1375
1262
 
1376
1263
  it("gte", async () => {
1377
- const response = await search(
1378
- store,
1379
- new SearchRequest({
1380
- query: [
1381
- new IntegerCompare({
1382
- key: "bigint",
1383
- compare: Compare.GreaterOrEqual,
1384
- value: second,
1385
- }),
1386
- ],
1387
- }),
1388
- );
1389
- response.results.sort((a, b) =>
1264
+ const response = await search(store, {
1265
+ query: [
1266
+ new IntegerCompare({
1267
+ key: "bigint",
1268
+ compare: Compare.GreaterOrEqual,
1269
+ value: second,
1270
+ }),
1271
+ ],
1272
+ });
1273
+ response.sort((a, b) =>
1390
1274
  bigIntSort(a.value.bigint as bigint, b.value.bigint as bigint),
1391
1275
  );
1392
- expect(response.results).to.have.length(2);
1393
- expect(response.results[0].value.bigint).to.equal(second);
1394
- expect(response.results[1].value.bigint).to.equal(third);
1276
+ expect(response).to.have.length(2);
1277
+ expect(response[0].value.bigint).to.equal(second);
1278
+ expect(response[1].value.bigint).to.equal(third);
1395
1279
  });
1396
1280
 
1397
1281
  it("lt", async () => {
1398
- const response = await search(
1399
- store,
1400
- new SearchRequest({
1401
- query: [
1402
- new IntegerCompare({
1403
- key: "bigint",
1404
- compare: Compare.Less,
1405
- value: second,
1406
- }),
1407
- ],
1408
- }),
1409
- );
1410
- expect(response.results).to.have.length(1);
1411
- expect(response.results[0].value.bigint).to.equal(first);
1282
+ const response = await search(store, {
1283
+ query: [
1284
+ new IntegerCompare({
1285
+ key: "bigint",
1286
+ compare: Compare.Less,
1287
+ value: second,
1288
+ }),
1289
+ ],
1290
+ });
1291
+ expect(response).to.have.length(1);
1292
+ expect(response[0].value.bigint).to.equal(first);
1412
1293
  });
1413
1294
 
1414
1295
  it("lte", async () => {
1415
- const response = await search(
1416
- store,
1417
- new SearchRequest({
1418
- query: [
1419
- new IntegerCompare({
1420
- key: "bigint",
1421
- compare: Compare.LessOrEqual,
1422
- value: second,
1423
- }),
1424
- ],
1425
- }),
1426
- );
1427
- response.results.sort((a, b) =>
1296
+ const response = await search(store, {
1297
+ query: [
1298
+ new IntegerCompare({
1299
+ key: "bigint",
1300
+ compare: Compare.LessOrEqual,
1301
+ value: second,
1302
+ }),
1303
+ ],
1304
+ });
1305
+ response.sort((a, b) =>
1428
1306
  bigIntSort(a.value.number as bigint, b.value.number as bigint),
1429
1307
  );
1430
1308
 
1431
- expect(response.results).to.have.length(2);
1432
- expect(response.results[0].value.bigint).to.equal(first);
1433
- expect(response.results[1].value.bigint).to.equal(second);
1309
+ expect(response).to.have.length(2);
1310
+ expect(response[0].value.bigint).to.equal(first);
1311
+ expect(response[1].value.bigint).to.equal(second);
1434
1312
  });
1435
1313
  });
1436
1314
 
@@ -1480,22 +1358,19 @@ export const tests = (
1480
1358
  });
1481
1359
  await store.put(doc2);
1482
1360
 
1483
- const response = await search(
1484
- store,
1485
- new SearchRequest({
1486
- query: [
1487
- new IntegerCompare({
1488
- key: ["nested", "number"],
1489
- compare: Compare.GreaterOrEqual,
1490
- value: 2n,
1491
- }),
1492
- ],
1493
- }),
1494
- );
1495
- expect(response.results).to.have.length(1);
1496
- expect(response.results[0].value.id).to.equal("2");
1361
+ const response = await search(store, {
1362
+ query: [
1363
+ new IntegerCompare({
1364
+ key: ["nested", "number"],
1365
+ compare: Compare.GreaterOrEqual,
1366
+ value: 2n,
1367
+ }),
1368
+ ],
1369
+ });
1370
+ expect(response).to.have.length(1);
1371
+ expect(response[0].value.id).to.equal("2");
1497
1372
 
1498
- checkDocument(response.results[0].value, doc2);
1373
+ checkDocument(response[0].value, doc2);
1499
1374
  });
1500
1375
 
1501
1376
  it("bool", async () => {
@@ -1511,35 +1386,29 @@ export const tests = (
1511
1386
  });
1512
1387
 
1513
1388
  await store.put(doc2);
1514
- let response = await search(
1515
- store,
1516
- new SearchRequest({
1517
- query: [
1518
- new BoolQuery({
1519
- key: ["nested", "bool"],
1520
- value: true,
1521
- }),
1522
- ],
1523
- }),
1524
- );
1525
- expect(response.results).to.have.length(1);
1526
- expect(response.results[0].value.id).to.equal("2");
1527
- checkDocument(response.results[0].value, doc2);
1389
+ let response = await search(store, {
1390
+ query: [
1391
+ new BoolQuery({
1392
+ key: ["nested", "bool"],
1393
+ value: true,
1394
+ }),
1395
+ ],
1396
+ });
1397
+ expect(response).to.have.length(1);
1398
+ expect(response[0].value.id).to.equal("2");
1399
+ checkDocument(response[0].value, doc2);
1528
1400
 
1529
- response = await search(
1530
- store,
1531
- new SearchRequest({
1532
- query: [
1533
- new BoolQuery({
1534
- key: ["nested", "bool"],
1535
- value: false,
1536
- }),
1537
- ],
1538
- }),
1539
- );
1540
- expect(response.results).to.have.length(1);
1541
- expect(response.results[0].value.id).to.equal("1");
1542
- checkDocument(response.results[0].value, doc1);
1401
+ response = await search(store, {
1402
+ query: [
1403
+ new BoolQuery({
1404
+ key: ["nested", "bool"],
1405
+ value: false,
1406
+ }),
1407
+ ],
1408
+ });
1409
+ expect(response).to.have.length(1);
1410
+ expect(response[0].value.id).to.equal("1");
1411
+ checkDocument(response[0].value, doc1);
1543
1412
  });
1544
1413
  });
1545
1414
 
@@ -1584,35 +1453,29 @@ export const tests = (
1584
1453
  });
1585
1454
 
1586
1455
  await store.put(doc2);
1587
- let response = await search(
1588
- store,
1589
- new SearchRequest({
1590
- query: [
1591
- new BoolQuery({
1592
- key: ["nested", "bool"],
1593
- value: true,
1594
- }),
1595
- ],
1596
- }),
1597
- );
1598
- expect(response.results).to.have.length(1);
1599
- expect(response.results[0].value.id).to.equal("2");
1600
- checkDocument(response.results[0].value, doc2);
1456
+ let response = await search(store, {
1457
+ query: [
1458
+ new BoolQuery({
1459
+ key: ["nested", "bool"],
1460
+ value: true,
1461
+ }),
1462
+ ],
1463
+ });
1464
+ expect(response).to.have.length(1);
1465
+ expect(response[0].value.id).to.equal("2");
1466
+ checkDocument(response[0].value, doc2);
1601
1467
 
1602
- response = await search(
1603
- store,
1604
- new SearchRequest({
1605
- query: [
1606
- new BoolQuery({
1607
- key: ["nested", "bool"],
1608
- value: false,
1609
- }),
1610
- ],
1611
- }),
1612
- );
1613
- expect(response.results).to.have.length(1);
1614
- expect(response.results[0].value.id).to.equal("1");
1615
- checkDocument(response.results[0].value, doc1);
1468
+ response = await search(store, {
1469
+ query: [
1470
+ new BoolQuery({
1471
+ key: ["nested", "bool"],
1472
+ value: false,
1473
+ }),
1474
+ ],
1475
+ });
1476
+ expect(response).to.have.length(1);
1477
+ expect(response[0].value.id).to.equal("1");
1478
+ checkDocument(response[0].value, doc1);
1616
1479
  });
1617
1480
  });
1618
1481
 
@@ -1670,22 +1533,19 @@ export const tests = (
1670
1533
  });
1671
1534
  await store.put(doc2);
1672
1535
 
1673
- const response = await search(
1674
- store,
1675
- new SearchRequest({
1676
- query: [
1677
- new IntegerCompare({
1678
- key: ["nested", "nestedAgain", "number"],
1679
- compare: Compare.GreaterOrEqual,
1680
- value: 2n,
1681
- }),
1682
- ],
1683
- }),
1684
- );
1685
- expect(response.results).to.have.length(1);
1686
- expect(response.results[0].value.id).to.equal("2");
1536
+ const response = await search(store, {
1537
+ query: [
1538
+ new IntegerCompare({
1539
+ key: ["nested", "nestedAgain", "number"],
1540
+ compare: Compare.GreaterOrEqual,
1541
+ value: 2n,
1542
+ }),
1543
+ ],
1544
+ });
1545
+ expect(response).to.have.length(1);
1546
+ expect(response[0].value.id).to.equal("2");
1687
1547
 
1688
- checkDocument(response.results[0].value, doc2);
1548
+ checkDocument(response[0].value, doc2);
1689
1549
  });
1690
1550
  });
1691
1551
 
@@ -1756,27 +1616,24 @@ export const tests = (
1756
1616
  });
1757
1617
  await store.put(doc2);
1758
1618
 
1759
- const response = await search(
1760
- store,
1761
- new SearchRequest({
1762
- query: [
1763
- new IntegerCompare({
1764
- key: [
1765
- "nested",
1766
- "nestedAgain",
1767
- "nestedAgainAgain",
1768
- "number",
1769
- ],
1770
- compare: Compare.GreaterOrEqual,
1771
- value: 2n,
1772
- }),
1773
- ],
1774
- }),
1775
- );
1619
+ const response = await search(store, {
1620
+ query: [
1621
+ new IntegerCompare({
1622
+ key: [
1623
+ "nested",
1624
+ "nestedAgain",
1625
+ "nestedAgainAgain",
1626
+ "number",
1627
+ ],
1628
+ compare: Compare.GreaterOrEqual,
1629
+ value: 2n,
1630
+ }),
1631
+ ],
1632
+ });
1776
1633
 
1777
- expect(response.results).to.have.length(1);
1778
- expect(response.results[0].value.id).to.equal("2");
1779
- checkDocument(response.results[0].value, doc2);
1634
+ expect(response).to.have.length(1);
1635
+ expect(response[0].value.id).to.equal("2");
1636
+ checkDocument(response[0].value, doc2);
1780
1637
  });
1781
1638
  });
1782
1639
 
@@ -1841,22 +1698,19 @@ export const tests = (
1841
1698
  });
1842
1699
  await store.put(doc2);
1843
1700
 
1844
- const response = await search(
1845
- store,
1846
- new SearchRequest({
1847
- query: [
1848
- new StringMatch({
1849
- key: ["nested", "string"],
1850
- value: "hello",
1851
- }),
1852
- ],
1853
- }),
1854
- );
1855
-
1856
- expect(response.results).to.have.length(1);
1857
- expect(response.results[0].value.id).to.equal("2");
1701
+ const response = await search(store, {
1702
+ query: [
1703
+ new StringMatch({
1704
+ key: ["nested", "string"],
1705
+ value: "hello",
1706
+ }),
1707
+ ],
1708
+ });
1858
1709
 
1859
- checkDocument(response.results[0].value, doc2);
1710
+ expect(response).to.have.length(1);
1711
+ expect(response[0].value.id).to.equal("2");
1712
+
1713
+ checkDocument(response[0].value, doc2);
1860
1714
  });
1861
1715
  });
1862
1716
 
@@ -1934,22 +1788,19 @@ export const tests = (
1934
1788
  });
1935
1789
  await store.put(doc2);
1936
1790
 
1937
- const response = await search(
1938
- store,
1939
- new SearchRequest({
1940
- query: [
1941
- new StringMatch({
1942
- key: ["nested", "nestedAgain", "string"],
1943
- value: "hello",
1944
- }),
1945
- ],
1946
- }),
1947
- );
1791
+ const response = await search(store, {
1792
+ query: [
1793
+ new StringMatch({
1794
+ key: ["nested", "nestedAgain", "string"],
1795
+ value: "hello",
1796
+ }),
1797
+ ],
1798
+ });
1948
1799
 
1949
- expect(response.results).to.have.length(1);
1950
- expect(response.results[0].value.id).to.equal("2");
1800
+ expect(response).to.have.length(1);
1801
+ expect(response[0].value.id).to.equal("2");
1951
1802
 
1952
- checkDocument(response.results[0].value, doc2);
1803
+ checkDocument(response[0].value, doc2);
1953
1804
  });
1954
1805
  });
1955
1806
 
@@ -2026,21 +1877,18 @@ export const tests = (
2026
1877
 
2027
1878
  await store.put(doc2);
2028
1879
 
2029
- const response = await search(
2030
- store,
2031
- new SearchRequest({
2032
- query: [
2033
- new StringMatch({
2034
- key: ["array", "string"],
2035
- value: "world",
2036
- }),
2037
- ],
2038
- }),
2039
- );
1880
+ const response = await search(store, {
1881
+ query: [
1882
+ new StringMatch({
1883
+ key: ["array", "string"],
1884
+ value: "world",
1885
+ }),
1886
+ ],
1887
+ });
2040
1888
 
2041
- expect(response.results).to.have.length(1);
2042
- expect(response.results[0].value.id).to.equal("2");
2043
- checkDocument(response.results[0].value, doc2);
1889
+ expect(response).to.have.length(1);
1890
+ expect(response[0].value.id).to.equal("2");
1891
+ checkDocument(response[0].value, doc2);
2044
1892
  });
2045
1893
  });
2046
1894
 
@@ -2107,21 +1955,18 @@ export const tests = (
2107
1955
 
2108
1956
  await store.put(doc2);
2109
1957
 
2110
- const response = await search(
2111
- store,
2112
- new SearchRequest({
2113
- query: [
2114
- new StringMatch({
2115
- key: ["base", "string"],
2116
- value: "world",
2117
- }),
2118
- ],
2119
- }),
2120
- );
1958
+ const response = await search(store, {
1959
+ query: [
1960
+ new StringMatch({
1961
+ key: ["base", "string"],
1962
+ value: "world",
1963
+ }),
1964
+ ],
1965
+ });
2121
1966
 
2122
- expect(response.results).to.have.length(1);
2123
- expect(response.results[0].value.id).to.equal("2");
2124
- checkDocument(response.results[0].value, doc2);
1967
+ expect(response).to.have.length(1);
1968
+ expect(response[0].value.id).to.equal("2");
1969
+ checkDocument(response[0].value, doc2);
2125
1970
  });
2126
1971
  });
2127
1972
 
@@ -2171,23 +2016,20 @@ export const tests = (
2171
2016
  });
2172
2017
  await store.put(doc2);
2173
2018
 
2174
- const response = await search(
2175
- store,
2176
- new SearchRequest({
2177
- query: [
2178
- new StringMatch({
2179
- key: ["nested", "arr"],
2180
- value: "värld",
2181
- }),
2182
- ],
2183
- }),
2184
- );
2019
+ const response = await search(store, {
2020
+ query: [
2021
+ new StringMatch({
2022
+ key: ["nested", "arr"],
2023
+ value: "värld",
2024
+ }),
2025
+ ],
2026
+ });
2185
2027
 
2186
- expect(response.results).to.have.length(1);
2187
- expect(
2188
- response.results.map((x) => x.value.id),
2189
- ).to.have.members(["2"]);
2190
- checkDocument(response.results[0].value, doc2);
2028
+ expect(response).to.have.length(1);
2029
+ expect(response.map((x) => x.value.id)).to.have.members([
2030
+ "2",
2031
+ ]);
2032
+ checkDocument(response[0].value, doc2);
2191
2033
  });
2192
2034
  });
2193
2035
 
@@ -2250,30 +2092,27 @@ export const tests = (
2250
2092
  }),
2251
2093
  );
2252
2094
 
2253
- const response = await search(
2254
- store,
2255
- new SearchRequest({
2256
- query: [
2257
- new Nested({
2258
- path: "array",
2259
- query: new And([
2260
- new StringMatch({
2261
- key: "a",
2262
- value: "hello",
2263
- }),
2264
- new StringMatch({
2265
- key: "b",
2266
- value: "world",
2267
- }),
2268
- ]),
2269
- }),
2270
- ],
2271
- }),
2272
- );
2095
+ const response = await search(store, {
2096
+ query: [
2097
+ new Nested({
2098
+ path: "array",
2099
+ query: new And([
2100
+ new StringMatch({
2101
+ key: "a",
2102
+ value: "hello",
2103
+ }),
2104
+ new StringMatch({
2105
+ key: "b",
2106
+ value: "world",
2107
+ }),
2108
+ ]),
2109
+ }),
2110
+ ],
2111
+ });
2273
2112
 
2274
- expect(response.results).to.have.length(1);
2275
- expect(response.results[0].value.id).to.equal("1");
2276
- checkDocument(response.results[0].value, doc1);
2113
+ expect(response).to.have.length(1);
2114
+ expect(response[0].value.id).to.equal("1");
2115
+ checkDocument(response[0].value, doc1);
2277
2116
  });
2278
2117
 
2279
2118
  it("nested partial match", async () => {
@@ -2305,24 +2144,21 @@ export const tests = (
2305
2144
  }),
2306
2145
  );
2307
2146
 
2308
- const response = await search(
2309
- store,
2310
- new SearchRequest({
2311
- query: [
2312
- new StringMatch({
2313
- key: ["array", "a"],
2314
- value: "hello",
2315
- }),
2316
- new StringMatch({
2317
- key: ["array", "b"],
2318
- value: "world",
2319
- }),
2320
- ],
2321
- }),
2322
- );
2147
+ const response = await search(store, {
2148
+ query: [
2149
+ new StringMatch({
2150
+ key: ["array", "a"],
2151
+ value: "hello",
2152
+ }),
2153
+ new StringMatch({
2154
+ key: ["array", "b"],
2155
+ value: "world",
2156
+ }),
2157
+ ],
2158
+ });
2323
2159
 
2324
- expect(response.results).to.have.length(2);
2325
- checkDocument(response.results[0].value, doc1);
2160
+ expect(response).to.have.length(2);
2161
+ checkDocument(response[0].value, doc1);
2326
2162
  });
2327
2163
  });
2328
2164
  });
@@ -2337,15 +2173,12 @@ export const tests = (
2337
2173
  it("can query one of the version", async () => {
2338
2174
  await store.put(new DocumentNext({ anotherField: "hello" }));
2339
2175
 
2340
- const result = await search(
2341
- store,
2342
- new SearchRequest({
2343
- query: new StringMatch({ key: "anotherField", value: "hello" }),
2344
- }),
2345
- );
2346
- expect(result.results).to.have.length(1);
2176
+ const result = await search(store, {
2177
+ query: new StringMatch({ key: "anotherField", value: "hello" }),
2178
+ });
2179
+ expect(result).to.have.length(1);
2347
2180
 
2348
- const [doc] = result.results;
2181
+ const [doc] = result;
2349
2182
  expect(doc.value).to.be.instanceOf(DocumentNext);
2350
2183
  });
2351
2184
 
@@ -2354,15 +2187,12 @@ export const tests = (
2354
2187
  await store.put(new DocumentNext({ name }));
2355
2188
  await store.put(new DocumentNext({ name }));
2356
2189
 
2357
- const result = await search(
2358
- store,
2359
- new SearchRequest({
2360
- query: new StringMatch({ key: "name", value: name }),
2361
- }),
2362
- );
2190
+ const result = await search(store, {
2191
+ query: new StringMatch({ key: "name", value: name }),
2192
+ });
2363
2193
 
2364
- expect(result.results).to.have.length(2);
2365
- for (const doc of result.results) {
2194
+ expect(result).to.have.length(2);
2195
+ for (const doc of result) {
2366
2196
  expect(doc.value).to.be.instanceOf(DocumentNext);
2367
2197
  }
2368
2198
  });
@@ -2377,11 +2207,11 @@ export const tests = (
2377
2207
  it("filter field", async () => {
2378
2208
  const results = await search(
2379
2209
  store,
2380
- new SearchRequest({ query: [] }),
2210
+ { query: [] },
2381
2211
  { shape: { id: true } },
2382
2212
  );
2383
- expect(results.results).to.have.length(4);
2384
- for (const result of results.results) {
2213
+ expect(results).to.have.length(4);
2214
+ for (const result of results) {
2385
2215
  if (shapingSupported) {
2386
2216
  expect(Object.keys(result.value)).to.have.length(1);
2387
2217
  expect(result.value["id"]).to.exist;
@@ -2397,11 +2227,11 @@ export const tests = (
2397
2227
  it("nested field", async () => {
2398
2228
  const results = await search(
2399
2229
  store,
2400
- new SearchRequest({ query: [] }),
2401
- { shape: { nestedVec: { number: true } } },
2230
+ { query: [] },
2231
+ { shape: { nestedVec: [{ number: true }] } },
2402
2232
  );
2403
- expect(results.results).to.have.length(4);
2404
- for (const value of results.results) {
2233
+ expect(results).to.have.length(4);
2234
+ for (const value of results) {
2405
2235
  const arr = value.value["nestedVec"];
2406
2236
  expect(arr).to.be.exist;
2407
2237
 
@@ -2470,29 +2300,31 @@ export const tests = (
2470
2300
  ),
2471
2301
  );
2472
2302
 
2473
- const shapedResults = await iterate(
2474
- index.store,
2475
- new SearchRequest({
2476
- query: new BoolQuery({ key: ["nested", "bool"], value: false }),
2477
- fetch: 1,
2478
- }),
2479
- ).all({ shape: { id: true } });
2303
+ const shapedResults = await index.store
2304
+ .iterate(
2305
+ {
2306
+ query: new BoolQuery({
2307
+ key: ["nested", "bool"],
2308
+ value: false,
2309
+ }),
2310
+ },
2311
+ { shape: { id: true } },
2312
+ )
2313
+ .all();
2480
2314
  expect(shapedResults).to.have.length(1);
2481
2315
  expect(shapedResults[0].value.id).to.equal("2");
2482
2316
 
2483
2317
  if (shapingSupported) {
2484
- expect(shapedResults[0].value.nested).to.be.undefined;
2318
+ expect(shapedResults[0].value["nested"]).to.be.undefined;
2485
2319
  } else {
2486
- expect(shapedResults[0].value.nested).to.exist;
2320
+ expect(shapedResults[0].value["nested"]).to.exist;
2487
2321
  }
2488
2322
 
2489
- const unshapedResults = await iterate(
2490
- index.store,
2491
- new SearchRequest({
2323
+ const unshapedResults = await index.store
2324
+ .iterate({
2492
2325
  query: new BoolQuery({ key: ["nested", "bool"], value: false }),
2493
- fetch: 1,
2494
- }),
2495
- ).all();
2326
+ })
2327
+ .all();
2496
2328
  expect(unshapedResults).to.have.length(1);
2497
2329
  expect(unshapedResults[0].value.id).to.equal("2");
2498
2330
  expect(unshapedResults[0].value.nested).to.exist;
@@ -2513,24 +2345,24 @@ export const tests = (
2513
2345
  await index.store.put(d1);
2514
2346
  await index.store.put(d2);
2515
2347
 
2516
- const unshapedResults = await iterate(
2517
- index.store,
2518
- new SearchRequest({
2348
+ const unshapedResults = await index.store
2349
+ .iterate({
2519
2350
  query: new StringMatch({ key: ["id"], value: "2" }),
2520
- fetch: 1,
2521
- }),
2522
- ).all();
2351
+ })
2352
+ .all();
2523
2353
  expect(unshapedResults).to.have.length(1);
2524
2354
  expect(unshapedResults[0].value.id).to.equal(d2.id);
2525
2355
  expect(unshapedResults[0].value.nested).to.deep.equal(d2.nested);
2526
2356
 
2527
- const shapedResults = await iterate(
2528
- index.store,
2529
- new SearchRequest({
2530
- query: new StringMatch({ key: ["id"], value: "2" }),
2531
- fetch: 1,
2532
- }),
2533
- ).all({ shape: { id: true, nested: { bool: true } } });
2357
+ const shapedResults = await index.store
2358
+ .iterate(
2359
+ {
2360
+ query: new StringMatch({ key: ["id"], value: "2" }),
2361
+ },
2362
+ { shape: { id: true, nested: { bool: true } } },
2363
+ )
2364
+ .all();
2365
+
2534
2366
  expect(shapedResults).to.have.length(1);
2535
2367
  expect(shapedResults[0].value.id).to.equal(d2.id);
2536
2368
 
@@ -2620,31 +2452,35 @@ export const tests = (
2620
2452
  ),
2621
2453
  );
2622
2454
 
2623
- const shapedResults = await iterate(
2624
- index.store,
2625
- new SearchRequest({
2626
- query: new BoolQuery({ key: ["nested", "bool"], value: false }),
2627
- fetch: 1,
2628
- }),
2629
- ).all({ shape: { id: true } });
2455
+ const shapedResults = await index.store
2456
+ .iterate(
2457
+ {
2458
+ query: new BoolQuery({
2459
+ key: ["nested", "bool"],
2460
+ value: false,
2461
+ }),
2462
+ },
2463
+ { shape: { id: true } },
2464
+ )
2465
+ .all();
2630
2466
  expect(shapedResults).to.have.length(1);
2631
2467
  expect(shapedResults[0].value.id).to.equal("2");
2632
2468
 
2633
2469
  if (shapingSupported) {
2634
- expect(shapedResults[0].value.nested).to.be.undefined;
2470
+ expect(shapedResults[0].value["nested"]).to.be.undefined;
2635
2471
  } else {
2636
- expect(shapedResults[0].value.nested).to.exist;
2472
+ expect(shapedResults[0].value["nested"]).to.exist;
2637
2473
  }
2638
2474
 
2639
- const unshapedResults = await iterate(
2640
- index.store,
2641
- new SearchRequest({
2475
+ const unshapedResults = await index.store
2476
+ .iterate({
2642
2477
  query: new BoolQuery({ key: ["nested", "bool"], value: false }),
2643
- fetch: 1,
2644
- }),
2645
- ).all();
2478
+ })
2479
+ .all();
2480
+
2646
2481
  expect(unshapedResults).to.have.length(1);
2647
2482
  expect(unshapedResults[0].value.id).to.equal("2");
2483
+
2648
2484
  expect(unshapedResults[0].value.nested).to.exist;
2649
2485
  });
2650
2486
 
@@ -2663,24 +2499,23 @@ export const tests = (
2663
2499
  await index.store.put(d1);
2664
2500
  await index.store.put(d2);
2665
2501
 
2666
- const unshapedResults = await iterate(
2667
- index.store,
2668
- new SearchRequest({
2502
+ const unshapedResults = await index.store
2503
+ .iterate({
2669
2504
  query: new StringMatch({ key: ["id"], value: "2" }),
2670
- fetch: 1,
2671
- }),
2672
- ).all();
2505
+ })
2506
+ .all();
2673
2507
  expect(unshapedResults).to.have.length(1);
2674
2508
  expect(unshapedResults[0].value.id).to.equal(d2.id);
2675
2509
  expect(unshapedResults[0].value.nested).to.deep.equal(d2.nested);
2676
2510
 
2677
- const shapedResults = await iterate(
2678
- index.store,
2679
- new SearchRequest({
2680
- query: new StringMatch({ key: ["id"], value: "2" }),
2681
- fetch: 1,
2682
- }),
2683
- ).all({ shape: { id: true, nested: { bool: true } } });
2511
+ const shapedResults = await index.store
2512
+ .iterate(
2513
+ {
2514
+ query: new StringMatch({ key: ["id"], value: "2" }),
2515
+ },
2516
+ { shape: { id: true, nested: { bool: true } } },
2517
+ )
2518
+ .all();
2684
2519
  expect(shapedResults).to.have.length(1);
2685
2520
  expect(shapedResults[0].value.id).to.equal(d2.id);
2686
2521
 
@@ -2747,29 +2582,31 @@ export const tests = (
2747
2582
  ),
2748
2583
  );
2749
2584
 
2750
- const shapedResults = await iterate(
2751
- index.store,
2752
- new SearchRequest({
2753
- query: new BoolQuery({ key: ["nested", "bool"], value: false }),
2754
- fetch: 1,
2755
- }),
2756
- ).all({ shape: { id: true } });
2585
+ const shapedResults = await index.store
2586
+ .iterate(
2587
+ {
2588
+ query: new BoolQuery({
2589
+ key: ["nested", "bool"],
2590
+ value: false,
2591
+ }),
2592
+ },
2593
+ { shape: { id: true } },
2594
+ )
2595
+ .all();
2757
2596
  expect(shapedResults).to.have.length(1);
2758
2597
  expect(shapedResults[0].value.id).to.equal("2");
2759
2598
 
2760
2599
  if (shapingSupported) {
2761
- expect(shapedResults[0].value.nested).to.be.undefined;
2600
+ expect(shapedResults[0].value["nested"]).to.be.undefined;
2762
2601
  } else {
2763
- expect(shapedResults[0].value.nested).to.exist;
2602
+ expect(shapedResults[0].value["nested"]).to.exist;
2764
2603
  }
2765
2604
 
2766
- const unshapedResults = await iterate(
2767
- index.store,
2768
- new SearchRequest({
2605
+ const unshapedResults = await index.store
2606
+ .iterate({
2769
2607
  query: new BoolQuery({ key: ["nested", "bool"], value: false }),
2770
- fetch: 1,
2771
- }),
2772
- ).all();
2608
+ })
2609
+ .all();
2773
2610
  expect(unshapedResults).to.have.length(1);
2774
2611
  expect(unshapedResults[0].value.id).to.equal("2");
2775
2612
  expect(unshapedResults[0].value.nested).to.exist;
@@ -2790,13 +2627,14 @@ export const tests = (
2790
2627
  await index.store.put(d1);
2791
2628
  await index.store.put(d2);
2792
2629
 
2793
- const shapedResults = await iterate(
2794
- index.store,
2795
- new SearchRequest({
2796
- query: new StringMatch({ key: ["id"], value: "2" }),
2797
- fetch: 1,
2798
- }),
2799
- ).all({ shape: { id: true, nested: { bool: true } } });
2630
+ const shapedResults = await index.store
2631
+ .iterate(
2632
+ {
2633
+ query: new StringMatch({ key: ["id"], value: "2" }),
2634
+ },
2635
+ { shape: { id: true, nested: [{ bool: true }] } },
2636
+ )
2637
+ .all();
2800
2638
  expect(shapedResults).to.have.length(1);
2801
2639
  expect(shapedResults[0].value.id).to.equal(d2.id);
2802
2640
 
@@ -2810,19 +2648,43 @@ export const tests = (
2810
2648
  );
2811
2649
  }
2812
2650
 
2813
- const unshapedResults = await iterate(
2814
- index.store,
2815
- new SearchRequest({
2651
+ const unshapedResults = await index.store
2652
+ .iterate({
2816
2653
  query: new StringMatch({ key: ["id"], value: "2" }),
2817
- fetch: 1,
2818
- }),
2819
- ).all();
2654
+ })
2655
+ .all();
2820
2656
  expect(unshapedResults).to.have.length(1);
2821
2657
  expect(unshapedResults[0].value.id).to.equal(d2.id);
2822
2658
  expect(unshapedResults[0].value.nested[0]).to.deep.equal(
2823
2659
  d2.nested[0],
2824
2660
  );
2825
2661
  });
2662
+
2663
+ it("true resolves fully", async () => {
2664
+ index = await setup({ schema: NestedBoolQueryDocument });
2665
+
2666
+ const d1 = new NestedBoolQueryDocument(
2667
+ "1",
2668
+ new MultifieldNested(true, 1, ["1"]),
2669
+ );
2670
+
2671
+ await index.store.put(d1);
2672
+
2673
+ const shapedResults = await index.store
2674
+ .iterate(
2675
+ {
2676
+ query: [],
2677
+ },
2678
+ { shape: { id: true, nested: true } },
2679
+ )
2680
+ .all();
2681
+ expect(shapedResults).to.have.length(1);
2682
+ expect(shapedResults[0].value.id).to.equal(d1.id);
2683
+
2684
+ expect(shapedResults[0].value.nested[0]).to.deep.equal(
2685
+ d1.nested[0],
2686
+ );
2687
+ });
2826
2688
  });
2827
2689
  });
2828
2690
  });
@@ -2853,24 +2715,30 @@ export const tests = (
2853
2715
  ],
2854
2716
  ) => {
2855
2717
  await waitForResolved(async () => {
2856
- const req = new SearchRequest({
2718
+ const req = {
2857
2719
  query,
2858
2720
  sort,
2859
- });
2860
- const iterator = iterate(store, req);
2721
+ };
2722
+ const iterator = store.iterate(req);
2723
+
2724
+ // No fetches has been made, so we don't know whether we are done yet
2725
+ expect(iterator.done()).to.be.undefined;
2861
2726
 
2862
2727
  if (batches.length === 0) {
2863
- // No fetches has been made, so we don't know whether we are done yet
2864
- expect(iterator.done()).to.be.false;
2728
+ await assertIteratorIsDone(iterator);
2865
2729
  } else {
2730
+ let first = true;
2866
2731
  for (const batch of batches) {
2867
- expect(iterator.done()).to.be.false;
2732
+ first
2733
+ ? expect(iterator.done()).to.be.undefined
2734
+ : expect(iterator.done()).to.be.false;
2735
+ first = false;
2868
2736
  const next = await iterator.next(batch.length);
2869
- expect(
2870
- next.results.map((x) => Number(x.value.number)),
2871
- ).to.deep.equal(batch.map((x) => Number(x)));
2737
+ expect(next.map((x) => Number(x.value.number))).to.deep.equal(
2738
+ batch.map((x) => Number(x)),
2739
+ );
2872
2740
  }
2873
- expect(iterator.done()).to.be.true;
2741
+ await assertIteratorIsDone(iterator);
2874
2742
  }
2875
2743
  });
2876
2744
  };
@@ -2901,38 +2769,24 @@ export const tests = (
2901
2769
  await put(1);
2902
2770
  await put(2);
2903
2771
  {
2904
- const iterator = await iterate(
2905
- store,
2906
- new SearchRequest({
2907
- query: [],
2908
- sort: [new Sort({ direction: SortDirection.ASC, key: "name" })],
2909
- }),
2910
- );
2911
- expect(iterator.done()).to.be.false;
2772
+ const iterator = store.iterate({
2773
+ query: [],
2774
+ sort: [new Sort({ direction: SortDirection.ASC, key: "name" })],
2775
+ });
2776
+ expect(iterator.done()).to.be.undefined;
2912
2777
  const next = await iterator.next(3);
2913
- expect(next.results.map((x) => x.value.name)).to.deep.equal([
2914
- "0",
2915
- "1",
2916
- "2",
2917
- ]);
2918
- expect(iterator.done()).to.be.true;
2778
+ expect(next.map((x) => x.value.name)).to.deep.equal(["0", "1", "2"]);
2779
+ await assertIteratorIsDone(iterator);
2919
2780
  }
2920
2781
  {
2921
- const iterator = await iterate(
2922
- store,
2923
- new SearchRequest({
2924
- query: [],
2925
- sort: [new Sort({ direction: SortDirection.DESC, key: "name" })],
2926
- }),
2927
- );
2928
- expect(iterator.done()).to.be.false;
2782
+ const iterator = store.iterate({
2783
+ query: [],
2784
+ sort: [new Sort({ direction: SortDirection.DESC, key: "name" })],
2785
+ });
2786
+ expect(iterator.done()).to.be.undefined;
2929
2787
  const next = await iterator.next(3);
2930
- expect(next.results.map((x) => x.value.name)).to.deep.equal([
2931
- "2",
2932
- "1",
2933
- "0",
2934
- ]);
2935
- expect(iterator.done()).to.be.true;
2788
+ expect(next.map((x) => x.value.name)).to.deep.equal(["2", "1", "0"]);
2789
+ await assertIteratorIsDone(iterator);
2936
2790
  }
2937
2791
  });
2938
2792
 
@@ -2941,21 +2795,14 @@ export const tests = (
2941
2795
  await put(1);
2942
2796
  await put(2);
2943
2797
 
2944
- const iterator = await iterate(
2945
- store,
2946
- new SearchRequest({
2947
- query: [],
2948
- sort: [new Sort({ direction: SortDirection.ASC, key: "name" })],
2949
- }),
2950
- );
2951
- expect(iterator.done()).to.be.false;
2798
+ const iterator = await store.iterate({
2799
+ query: [],
2800
+ sort: [new Sort({ direction: SortDirection.ASC, key: "name" })],
2801
+ });
2802
+ expect(iterator.done()).to.be.undefined;
2952
2803
  const next = await iterator.next(3);
2953
- expect(next.results.map((x) => x.value.name)).to.deep.equal([
2954
- "0",
2955
- "1",
2956
- "2",
2957
- ]);
2958
- expect(iterator.done()).to.be.true;
2804
+ expect(next.map((x) => x.value.name)).to.deep.equal(["0", "1", "2"]);
2805
+ await assertIteratorIsDone(iterator);
2959
2806
  });
2960
2807
 
2961
2808
  describe("nested", () => {
@@ -2971,20 +2818,18 @@ export const tests = (
2971
2818
  await store.put(doc1);
2972
2819
  await store.put(doc2);
2973
2820
 
2974
- const iterator = iterate(
2975
- store,
2976
- new SearchRequest({
2977
- sort: [
2978
- new Sort({
2979
- direction: SortDirection.DESC,
2980
- key: ["nested", "number"],
2981
- }),
2982
- ],
2983
- }),
2984
- );
2985
- expect(iterator.done()).to.be.false;
2821
+ const iterator = store.iterate({
2822
+ sort: [
2823
+ new Sort({
2824
+ direction: SortDirection.DESC,
2825
+ key: ["nested", "number"],
2826
+ }),
2827
+ ],
2828
+ });
2829
+ expect(iterator.done()).to.be.undefined;
2986
2830
  const next = await iterator.next(2);
2987
- expect(next.results.map((x) => x.value.id)).to.deep.equal(["2", "1"]);
2831
+ expect(next.map((x) => x.value.id)).to.deep.equal(["2", "1"]);
2832
+ await assertIteratorIsDone(iterator);
2988
2833
  });
2989
2834
 
2990
2835
  describe("nested-nested-invariant", () => {
@@ -3029,23 +2874,18 @@ export const tests = (
3029
2874
  });
3030
2875
 
3031
2876
  it("nested-variants", async () => {
3032
- const iterator = iterate(
3033
- store,
3034
- new SearchRequest({
3035
- sort: [
3036
- new Sort({
3037
- direction: SortDirection.DESC,
3038
- key: ["nested", "v0", "number"],
3039
- }),
3040
- ],
3041
- }),
3042
- );
3043
- expect(iterator.done()).to.be.false;
2877
+ const iterator = store.iterate({
2878
+ sort: [
2879
+ new Sort({
2880
+ direction: SortDirection.DESC,
2881
+ key: ["nested", "v0", "number"],
2882
+ }),
2883
+ ],
2884
+ });
2885
+ expect(iterator.done()).to.be.undefined;
3044
2886
  const next = await iterator.next(2);
3045
- expect(next.results.map((x) => x.value.id)).to.deep.equal([
3046
- "2",
3047
- "1",
3048
- ]);
2887
+ expect(next.map((x) => x.value.id)).to.deep.equal(["2", "1"]);
2888
+ await assertIteratorIsDone(iterator);
3049
2889
  });
3050
2890
  });
3051
2891
 
@@ -3092,82 +2932,76 @@ export const tests = (
3092
2932
  });
3093
2933
 
3094
2934
  it("nested-variants", async () => {
3095
- const iterator = iterate(
3096
- store,
3097
- new SearchRequest({
3098
- sort: [
3099
- new Sort({
3100
- direction: SortDirection.DESC,
3101
- key: ["nested", "v0", "number"],
3102
- }),
3103
- ],
3104
- }),
3105
- );
3106
- expect(iterator.done()).to.be.false;
2935
+ const iterator = store.iterate({
2936
+ sort: [
2937
+ new Sort({
2938
+ direction: SortDirection.DESC,
2939
+ key: ["nested", "v0", "number"],
2940
+ }),
2941
+ ],
2942
+ });
2943
+ expect(iterator.done()).to.be.undefined;
3107
2944
  const next = await iterator.next(2);
3108
- expect(next.results.map((x) => x.value.id)).to.deep.equal([
3109
- "2",
3110
- "1",
3111
- ]);
2945
+ expect(next.map((x) => x.value.id)).to.deep.equal(["2", "1"]);
3112
2946
  });
3113
2947
  });
3114
2948
  /* TODO (requires sort join interleaving)
3115
2949
 
3116
2950
  describe("nested-nested-variant", () => {
3117
-
2951
+
3118
2952
  abstract class Base { }
3119
-
2953
+
3120
2954
  @variant(0)
3121
2955
  class V0 extends Base {
3122
-
2956
+
3123
2957
  @field({ type: 'u64' })
3124
2958
  number: bigint;
3125
-
2959
+
3126
2960
  constructor(number: bigint) {
3127
2961
  super()
3128
2962
  this.number = number;
3129
2963
  }
3130
2964
  }
3131
-
2965
+
3132
2966
  @variant(1)
3133
2967
  class V1 extends Base {
3134
-
2968
+
3135
2969
  @field({ type: 'u64' })
3136
2970
  number: bigint;
3137
-
2971
+
3138
2972
  constructor(number: bigint) {
3139
2973
  super()
3140
2974
  this.number = number;
3141
2975
  }
3142
2976
  }
3143
-
2977
+
3144
2978
  class NestedValue {
3145
2979
  @field({ type: Base })
3146
2980
  v0: Base;
3147
-
2981
+
3148
2982
  constructor(v0?: Base) {
3149
2983
  this.v0 = v0;
3150
2984
  }
3151
2985
  }
3152
-
2986
+
3153
2987
  class Document {
3154
2988
  @id({ type: 'string' })
3155
2989
  id: string;
3156
-
2990
+
3157
2991
  @field({ type: NestedValue })
3158
2992
  nested: NestedValue;
3159
-
2993
+
3160
2994
  constructor(id: string, nested: NestedValue) {
3161
2995
  this.id = id;
3162
2996
  this.nested = nested;
3163
2997
  }
3164
2998
  }
3165
-
2999
+
3166
3000
  const doc1 = new Document("1", new NestedValue(new V0(1n)));
3167
3001
  const doc2 = new Document("2", new NestedValue(new V0(2n)));
3168
3002
  const doc3 = new Document("3", new NestedValue(new V1(3n)));
3169
3003
  const doc4 = new Document("4", new NestedValue(new V1(4n)));
3170
-
3004
+
3171
3005
  beforeEach(async () => {
3172
3006
  await setup({ schema: Document });
3173
3007
  await store.put(doc1);
@@ -3175,15 +3009,15 @@ export const tests = (
3175
3009
  await store.put(doc3);
3176
3010
  await store.put(doc4);
3177
3011
  });
3178
-
3012
+
3179
3013
  it("nested-variants", async () => {
3180
- const iterator = iterate(store, new SearchRequest({ sort: [new Sort({ direction: SortDirection.DESC, key: ["nested", "v0", "number"] })] }));
3014
+ const iterator = iterate(store, ({ sort: [new Sort({ direction: SortDirection.DESC, key: ["nested", "v0", "number"] })] }));
3181
3015
  expect(iterator.done()).to.be.false;
3182
3016
  const next = await iterator.next(4);
3183
3017
  expect(next.results.map((x) => x.value.id)).to.deep.equal(["4", "3", "2", "1"]);
3184
-
3018
+
3185
3019
  })
3186
-
3020
+
3187
3021
  })*/
3188
3022
 
3189
3023
  /* TODO
@@ -3210,7 +3044,7 @@ export const tests = (
3210
3044
  await store.put(doc2);
3211
3045
  await store.put(doc3);
3212
3046
 
3213
- const iterator = iterate(store, new SearchRequest({ query: [new IntegerCompare({ key: 'number', compare: 'gte', value: 102n }), new Nested({ path: 'nestedVec', id: 'path-to-nested', query: [new IntegerCompare({ key: 'number', compare: 'gte', value: 200 })] })], sort: [new Sort({ direction: SortDirection.DESC, key: ["path-to-nested", "number"] })] }));
3047
+ const iterator = iterate(store, ({ query: [new IntegerCompare({ key: 'number', compare: 'gte', value: 102n }), new Nested({ path: 'nestedVec', id: 'path-to-nested', query: [new IntegerCompare({ key: 'number', compare: 'gte', value: 200 })] })], sort: [new Sort({ direction: SortDirection.DESC, key: ["path-to-nested", "number"] })] }));
3214
3048
  expect(iterator.done()).to.be.false;
3215
3049
  const next = await iterator.next(2);
3216
3050
  expect(next.results.map((x) => x.value.id)).to.deep.equal(["2", "1"]);
@@ -3223,51 +3057,45 @@ export const tests = (
3223
3057
  await put(0);
3224
3058
  await put(1);
3225
3059
  await put(2);
3226
- const request = new SearchRequest({
3060
+ const request = {
3227
3061
  query: [],
3228
- });
3229
- const iterator = iterate(store, request);
3230
- expect(iterator.done()).to.be.false;
3062
+ };
3063
+ const iterator = store.iterate(request);
3064
+ expect(iterator.done()).to.be.undefined;
3231
3065
  await iterator.next(2); // fetch some, but not all
3232
- expect(store.getPending(request.idString)).equal(1);
3066
+ expect(iterator.done()).to.be.false;
3067
+ expect(await iterator.pending()).equal(1);
3233
3068
  await iterator.close();
3234
- await waitForResolved(
3235
- () => expect(store.getPending(request.idString)).equal(undefined),
3236
- { timeout: 3000, delayInterval: 50 },
3237
- );
3069
+ expect(await iterator.pending()).equal(0);
3070
+ expect(iterator.done()).to.be.true;
3238
3071
  });
3239
3072
 
3240
3073
  it("end of iterator", async () => {
3241
3074
  await put(0);
3242
3075
  await put(1);
3243
3076
  await put(2);
3244
- const request = new SearchRequest({
3077
+ const request = {
3245
3078
  query: [],
3246
- });
3247
- const iterator = await iterate(store, request);
3248
- expect(iterator.done()).to.be.false;
3079
+ };
3080
+ const iterator = store.iterate(request);
3081
+ expect(iterator.done()).to.be.undefined;
3249
3082
  await iterator.next(3); // fetch all
3250
- await waitForResolved(
3251
- () => expect(store.getPending(request.idString)).equal(undefined),
3252
- { timeout: 3000, delayInterval: 50 },
3253
- );
3083
+ expect(await iterator.pending()).equal(0);
3084
+ expect(iterator.done()).to.be.true;
3254
3085
  });
3255
3086
 
3256
3087
  it("end of iterator, multiple nexts", async () => {
3257
3088
  await put(0);
3258
3089
  await put(1);
3259
3090
  await put(2);
3260
- const request = new SearchRequest({
3091
+ const request = {
3261
3092
  query: [],
3262
- });
3263
- const iterator = await iterate(store, request);
3093
+ };
3094
+ const iterator = store.iterate(request);
3264
3095
  await iterator.next(2);
3265
3096
  await iterator.next(1);
3266
- expect(iterator.done()).to.be.true;
3267
- await waitForResolved(
3268
- () => expect(store.getPending(request.idString)).equal(undefined),
3269
- { timeout: 3000, delayInterval: 50 },
3270
- );
3097
+ assertIteratorIsDone(iterator);
3098
+ expect(await iterator.pending()).equal(0);
3271
3099
  });
3272
3100
  });
3273
3101
 
@@ -3281,7 +3109,7 @@ export const tests = (
3281
3109
  describe("sum", () => {
3282
3110
  it("it returns sum", async () => {
3283
3111
  await setupDefault();
3284
- const sum = await store.sum(new SumRequest({ key: "number" }));
3112
+ const sum = await store.sum({ key: "number" });
3285
3113
  typeof sum === "bigint"
3286
3114
  ? expect(sum).to.equal(6n)
3287
3115
  : expect(sum).to.equal(6);
@@ -3289,19 +3117,17 @@ export const tests = (
3289
3117
 
3290
3118
  it("it returns sum with query", async () => {
3291
3119
  await setupDefault();
3292
- const sum = await store.sum(
3293
- new SumRequest({
3294
- key: "number",
3295
- query: [
3296
- new StringMatch({
3297
- key: "tags",
3298
- value: "world",
3299
- method: StringMatchMethod.contains,
3300
- caseInsensitive: true,
3301
- }),
3302
- ],
3303
- }),
3304
- );
3120
+ const sum = await store.sum({
3121
+ key: "number",
3122
+ query: [
3123
+ new StringMatch({
3124
+ key: "tags",
3125
+ value: "world",
3126
+ method: StringMatchMethod.contains,
3127
+ caseInsensitive: true,
3128
+ }),
3129
+ ],
3130
+ });
3305
3131
  typeof sum === "bigint"
3306
3132
  ? expect(sum).to.equal(2n)
3307
3133
  : expect(sum).to.equal(2);
@@ -3328,11 +3154,9 @@ export const tests = (
3328
3154
  await store.put(doc2);
3329
3155
  await store.put(doc3);
3330
3156
 
3331
- const sum = await store.sum(
3332
- new SumRequest({
3333
- key: ["nested", "number"],
3334
- }),
3335
- );
3157
+ const sum = await store.sum({
3158
+ key: ["nested", "number"],
3159
+ });
3336
3160
 
3337
3161
  typeof sum === "bigint"
3338
3162
  ? expect(sum).to.equal(3n)
@@ -3343,24 +3167,22 @@ export const tests = (
3343
3167
  describe("count", () => {
3344
3168
  it("it returns count", async () => {
3345
3169
  await setupDefault();
3346
- const sum = await store.count(new CountRequest());
3170
+ const sum = await store.count();
3347
3171
  expect(sum).to.equal(4);
3348
3172
  });
3349
3173
 
3350
3174
  it("it returns count with query", async () => {
3351
3175
  await setupDefault();
3352
- const sum = await store.count(
3353
- new CountRequest({
3354
- query: [
3355
- new StringMatch({
3356
- key: "tags",
3357
- value: "world",
3358
- method: StringMatchMethod.contains,
3359
- caseInsensitive: true,
3360
- }),
3361
- ],
3362
- }),
3363
- );
3176
+ const sum = await store.count({
3177
+ query: [
3178
+ new StringMatch({
3179
+ key: "tags",
3180
+ value: "world",
3181
+ method: StringMatchMethod.contains,
3182
+ caseInsensitive: true,
3183
+ }),
3184
+ ],
3185
+ });
3364
3186
  expect(sum).to.equal(1);
3365
3187
  });
3366
3188
  });
@@ -3368,18 +3190,16 @@ export const tests = (
3368
3190
  describe("delete", () => {
3369
3191
  it("delete with query", async () => {
3370
3192
  await setupDefault();
3371
- await store.del(
3372
- new DeleteRequest({
3373
- query: [
3374
- new StringMatch({
3375
- key: "tags",
3376
- value: "world",
3377
- method: StringMatchMethod.contains,
3378
- caseInsensitive: true,
3379
- }),
3380
- ],
3381
- }),
3382
- );
3193
+ await store.del({
3194
+ query: [
3195
+ new StringMatch({
3196
+ key: "tags",
3197
+ value: "world",
3198
+ method: StringMatchMethod.contains,
3199
+ caseInsensitive: true,
3200
+ }),
3201
+ ],
3202
+ });
3383
3203
  expect(await store.getSize()).to.equal(3);
3384
3204
  });
3385
3205
  });
@@ -3415,7 +3235,7 @@ export const tests = (
3415
3235
  for (let i = 0; i < 100; i++) {
3416
3236
  promises.push(
3417
3237
  (async () => {
3418
- results.push(await store.count(new CountRequest()));
3238
+ results.push(await store.count());
3419
3239
  })(),
3420
3240
  );
3421
3241
  }
@@ -3598,14 +3418,10 @@ export const tests = (
3598
3418
  await aIndex.put(
3599
3419
  new Document({ id: "a", name: "hello", number: 1n, tags: [] }),
3600
3420
  );
3601
- expect(
3602
- await aIndex.count(new CountRequest({ query: { id: "a" } })),
3603
- ).to.eq(1);
3421
+ expect(await aIndex.count({ query: { id: "a" } })).to.eq(1);
3604
3422
 
3605
3423
  await bIndex.put(new AnotherDocument("b"));
3606
- expect(
3607
- await bIndex.count(new CountRequest({ query: { id: "b" } })),
3608
- ).to.eq(1);
3424
+ expect(await bIndex.count({ query: { id: "b" } })).to.eq(1);
3609
3425
  });
3610
3426
  });
3611
3427
  });
@@ -3658,7 +3474,7 @@ describe("multi-dimensional", () => {
3658
3474
  promises.push(
3659
3475
  search(
3660
3476
  store,
3661
- new SearchRequest({
3477
+ ({
3662
3478
  query: [
3663
3479
  new IntegerCompare({
3664
3480
  key: "number",
@@ -3673,7 +3489,7 @@ describe("multi-dimensional", () => {
3673
3489
  promises.push(
3674
3490
  search(
3675
3491
  store,
3676
- new SearchRequest({
3492
+ ({
3677
3493
  query: [
3678
3494
  new IntegerCompare({
3679
3495
  key: "number",