@peerbit/indexer-tests 3.0.5 → 3.0.7

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.
@@ -1,3 +1,4 @@
1
1
  export { tests } from "./tests.js";
2
+ export { tieParityTests } from "./tie-parity.js";
2
3
  export { benchmarks } from "./benchmarks.js";
3
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC"}
package/dist/src/index.js CHANGED
@@ -1,3 +1,4 @@
1
1
  export { tests } from "./tests.js";
2
+ export { tieParityTests } from "./tie-parity.js";
2
3
  export { benchmarks } from "./benchmarks.js";
3
4
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"tests.d.ts","sourceRoot":"","sources":["../../src/tests.ts"],"names":[],"mappings":"AAUA,OAAO,EAQN,KAAK,OAAO,EAiBZ,MAAM,4BAA4B,CAAC;AAgHpC,eAAO,MAAM,KAAK,GACjB,gBAAgB,CAAC,SAAS,CAAC,EAAE,MAAM,KAAK,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,EAClE,MAAM,WAAW,GAAG,SAAuB,EAC3C,YAAY;IACX,gBAAgB,EAAE,OAAO,CAAC;IAC1B,eAAe,EAAE,OAAO,CAAC;IACzB,gBAAgB,EAAE,OAAO,CAAC;CAC1B,gBAmzID,CAAC"}
1
+ {"version":3,"file":"tests.d.ts","sourceRoot":"","sources":["../../src/tests.ts"],"names":[],"mappings":"AAUA,OAAO,EAQN,KAAK,OAAO,EAiBZ,MAAM,4BAA4B,CAAC;AAgHpC,eAAO,MAAM,KAAK,GACjB,gBAAgB,CAAC,SAAS,CAAC,EAAE,MAAM,KAAK,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,EAClE,MAAM,WAAW,GAAG,SAAuB,EAC3C,YAAY;IACX,gBAAgB,EAAE,OAAO,CAAC;IAC1B,eAAe,EAAE,OAAO,CAAC;IACzB,gBAAgB,EAAE,OAAO,CAAC;CAC1B,gBA8jJD,CAAC"}
package/dist/src/tests.js CHANGED
@@ -4695,6 +4695,213 @@ export const tests = (createIndicies, type = "transient", properties) => {
4695
4695
  }
4696
4696
  expect(await iterator.pending()).to.eq(0);
4697
4697
  });
4698
+ it("all after partial next returns only remaining sorted results", async () => {
4699
+ await put(0);
4700
+ await put(1);
4701
+ await put(2);
4702
+ const iterator = store.iterate({
4703
+ query: [],
4704
+ sort: [new Sort({ direction: SortDirection.ASC, key: "name" })],
4705
+ });
4706
+ expect((await iterator.next(1)).map((x) => x.value.name)).to.deep.equal(["0"]);
4707
+ expect((await iterator.all()).map((x) => x.value.name)).to.deep.equal([
4708
+ "1",
4709
+ "2",
4710
+ ]);
4711
+ expect(iterator.done()).to.be.true;
4712
+ });
4713
+ it("deleting an already yielded sorted result does not skip the next result", async () => {
4714
+ await put(0);
4715
+ await put(1);
4716
+ await put(2);
4717
+ const iterator = store.iterate({
4718
+ query: [],
4719
+ sort: [new Sort({ direction: SortDirection.ASC, key: "name" })],
4720
+ });
4721
+ expect((await iterator.next(1)).map((x) => x.value.name)).to.deep.equal(["0"]);
4722
+ await store.del({
4723
+ query: new StringMatch({
4724
+ key: "id",
4725
+ value: "0",
4726
+ method: StringMatchMethod.exact,
4727
+ caseInsensitive: false,
4728
+ }),
4729
+ });
4730
+ expect((await iterator.next(2)).map((x) => x.value.name)).to.deep.equal(["1", "2"]);
4731
+ expect(iterator.done()).to.be.true;
4732
+ });
4733
+ it("inserting before an already yielded sorted result does not duplicate it", async () => {
4734
+ await put(1);
4735
+ await put(2);
4736
+ const iterator = store.iterate({
4737
+ query: [],
4738
+ sort: [new Sort({ direction: SortDirection.ASC, key: "name" })],
4739
+ });
4740
+ expect((await iterator.next(1)).map((x) => x.value.name)).to.deep.equal(["1"]);
4741
+ await put(0);
4742
+ const rest = (await iterator.next(3)).map((x) => x.value.name);
4743
+ expect(new Set(rest).size).to.equal(rest.length);
4744
+ expect(rest).to.not.include("1");
4745
+ expect(rest).to.include("2");
4746
+ });
4747
+ it("keeps a mutated iterator open while unseen sorted results remain", async () => {
4748
+ await put(0);
4749
+ await put(2);
4750
+ const iterator = store.iterate({
4751
+ query: [],
4752
+ sort: [new Sort({ direction: SortDirection.ASC, key: "name" })],
4753
+ });
4754
+ expect((await iterator.next(1)).map((x) => x.value.name)).to.deep.equal(["0"]);
4755
+ await put(1);
4756
+ if (properties.iteratorsMutable) {
4757
+ expect((await iterator.next(1)).map((x) => x.value.name)).to.deep.equal(["1"]);
4758
+ expect(iterator.done()).to.be.false;
4759
+ expect(await iterator.pending()).to.equal(1);
4760
+ expect((await iterator.next(1)).map((x) => x.value.name)).to.deep.equal(["2"]);
4761
+ }
4762
+ else {
4763
+ expect((await iterator.next(1)).map((x) => x.value.name)).to.deep.equal(["2"]);
4764
+ }
4765
+ expect(iterator.done()).to.be.true;
4766
+ });
4767
+ it("next Infinity sees inserts after an initially empty page", async () => {
4768
+ const iterator = store.iterate({
4769
+ query: [],
4770
+ sort: [new Sort({ direction: SortDirection.ASC, key: "name" })],
4771
+ });
4772
+ expect(await iterator.next(1)).to.deep.equal([]);
4773
+ await put(0);
4774
+ const rest = (await iterator.next(Infinity)).map((x) => x.value.name);
4775
+ expect(rest).to.deep.equal(properties.iteratorsMutable ? ["0"] : []);
4776
+ });
4777
+ it("keeps an explicitly closed iterator terminal across mutations", async () => {
4778
+ await put(0);
4779
+ const iterator = store.iterate({
4780
+ query: [],
4781
+ sort: [new Sort({ direction: SortDirection.ASC, key: "name" })],
4782
+ });
4783
+ await iterator.close();
4784
+ await put(1);
4785
+ expect(await iterator.next(1)).to.deep.equal([]);
4786
+ expect(await iterator.all()).to.deep.equal([]);
4787
+ expect(await iterator.pending()).to.equal(0);
4788
+ expect(iterator.done()).to.be.true;
4789
+ });
4790
+ it("can continue a mutable iterator after all and a later insert", async () => {
4791
+ await put(0);
4792
+ const iterator = store.iterate({
4793
+ query: [],
4794
+ sort: [new Sort({ direction: SortDirection.ASC, key: "name" })],
4795
+ });
4796
+ expect((await iterator.all()).map((x) => x.value.name)).to.deep.equal([
4797
+ "0",
4798
+ ]);
4799
+ await put(1);
4800
+ expect((await iterator.next(1)).map((x) => x.value.name)).to.deep.equal(properties.iteratorsMutable ? ["1"] : []);
4801
+ });
4802
+ it("refreshes pending after an exhausted mutable iterator mutates", async () => {
4803
+ const iterator = store.iterate({
4804
+ query: [],
4805
+ sort: [new Sort({ direction: SortDirection.ASC, key: "name" })],
4806
+ });
4807
+ expect(await iterator.next(1)).to.deep.equal([]);
4808
+ await put(0);
4809
+ expect(await iterator.pending()).to.equal(properties.iteratorsMutable ? 1 : 0);
4810
+ if (properties.iteratorsMutable) {
4811
+ expect(iterator.done()).to.be.false;
4812
+ expect((await iterator.next(1)).map((x) => x.value.name)).to.deep.equal(["0"]);
4813
+ }
4814
+ });
4815
+ it("can mark live results delivered outside the iterator as yielded", async () => {
4816
+ if (!properties.iteratorsMutable) {
4817
+ return;
4818
+ }
4819
+ await put(0);
4820
+ await put(1);
4821
+ const iterator = store.iterate({
4822
+ query: [],
4823
+ sort: [new Sort({ direction: SortDirection.ASC, key: "name" })],
4824
+ });
4825
+ expect((await iterator.next(1)).map((x) => x.value.id)).to.deep.equal([
4826
+ "0",
4827
+ ]);
4828
+ await put(2);
4829
+ expect(iterator.markYielded).to.be.a("function");
4830
+ await iterator.markYielded([toId("2")]);
4831
+ expect(await iterator.pending()).to.equal(1);
4832
+ expect((await iterator.next(2)).map((x) => x.value.id)).to.deep.equal([
4833
+ "1",
4834
+ ]);
4835
+ expect(await iterator.pending()).to.equal(0);
4836
+ expect(iterator.done()).to.be.true;
4837
+ });
4838
+ it("tracks filtered updates without duplicates", async () => {
4839
+ if (!properties.iteratorsMutable) {
4840
+ return;
4841
+ }
4842
+ await put(0, { name: "match" });
4843
+ await put(1, { name: "miss" });
4844
+ await put(2, { name: "match" });
4845
+ const iterator = store.iterate({
4846
+ query: new StringMatch({
4847
+ key: "name",
4848
+ value: "match",
4849
+ method: StringMatchMethod.exact,
4850
+ caseInsensitive: false,
4851
+ }),
4852
+ sort: [new Sort({ direction: SortDirection.ASC, key: "number" })],
4853
+ });
4854
+ expect((await iterator.next(1)).map((x) => x.value.id)).to.deep.equal([
4855
+ "0",
4856
+ ]);
4857
+ await put(1, { name: "match" });
4858
+ await put(2, { name: "miss" });
4859
+ await put(0, { name: "match" });
4860
+ await put(3, { name: "match" });
4861
+ expect((await iterator.all()).map((x) => x.value.id)).to.deep.equal([
4862
+ "1",
4863
+ "3",
4864
+ ]);
4865
+ });
4866
+ it("rescans beyond 128 yielded rows after a mutation", async () => {
4867
+ if (!properties.iteratorsMutable) {
4868
+ return;
4869
+ }
4870
+ for (let i = 0; i < 140; i++) {
4871
+ await put(i);
4872
+ }
4873
+ const iterator = store.iterate({
4874
+ query: [],
4875
+ sort: [new Sort({ direction: SortDirection.ASC, key: "number" })],
4876
+ });
4877
+ expect(await iterator.next(130)).to.have.length(130);
4878
+ await store.del({
4879
+ query: new StringMatch({
4880
+ key: "id",
4881
+ value: "0",
4882
+ method: StringMatchMethod.exact,
4883
+ caseInsensitive: false,
4884
+ }),
4885
+ });
4886
+ await put(200);
4887
+ expect((await iterator.next(1)).map((x) => x.value.id)).to.deep.equal([
4888
+ "130",
4889
+ ]);
4890
+ const remaining = (await iterator.all()).map((x) => x.value.id);
4891
+ expect(remaining).to.deep.equal([
4892
+ "131",
4893
+ "132",
4894
+ "133",
4895
+ "134",
4896
+ "135",
4897
+ "136",
4898
+ "137",
4899
+ "138",
4900
+ "139",
4901
+ "200",
4902
+ ]);
4903
+ expect(new Set(remaining).size).to.equal(remaining.length);
4904
+ });
4698
4905
  describe("close", () => {
4699
4906
  it("by invoking close()", async () => {
4700
4907
  await put(0);