@peerbit/indexer-tests 1.1.1 → 1.1.2-4d7d8ba
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/dist/src/tests.d.ts +4 -1
- package/dist/src/tests.d.ts.map +1 -1
- package/dist/src/tests.js +169 -43
- package/dist/src/tests.js.map +1 -1
- package/package.json +66 -66
- package/src/tests.ts +175 -35
package/package.json
CHANGED
|
@@ -1,68 +1,68 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
2
|
+
"name": "@peerbit/indexer-tests",
|
|
3
|
+
"version": "1.1.2-4d7d8ba",
|
|
4
|
+
"description": "Tests document store index engines",
|
|
5
|
+
"sideEffects": false,
|
|
6
|
+
"type": "module",
|
|
7
|
+
"types": "./dist/src/index.d.ts",
|
|
8
|
+
"typesVersions": {
|
|
9
|
+
"*": {
|
|
10
|
+
"*": [
|
|
11
|
+
"*",
|
|
12
|
+
"dist/*",
|
|
13
|
+
"dist/src/*",
|
|
14
|
+
"dist/src/*/index"
|
|
15
|
+
],
|
|
16
|
+
"src/*": [
|
|
17
|
+
"*",
|
|
18
|
+
"dist/*",
|
|
19
|
+
"dist/src/*",
|
|
20
|
+
"dist/src/*/index"
|
|
21
|
+
]
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"files": [
|
|
25
|
+
"src",
|
|
26
|
+
"dist",
|
|
27
|
+
"!dist/e2e",
|
|
28
|
+
"!dist/test",
|
|
29
|
+
"!**/*.tsbuildinfo"
|
|
30
|
+
],
|
|
31
|
+
"exports": {
|
|
32
|
+
".": {
|
|
33
|
+
"types": "./dist/src/index.d.ts",
|
|
34
|
+
"import": "./dist/src/index.js"
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
"browser": {
|
|
38
|
+
"./dist/src/benchmarks.js": "./dist/src/benchmarks.browser.js"
|
|
39
|
+
},
|
|
40
|
+
"eslintConfig": {
|
|
41
|
+
"extends": "peerbit",
|
|
42
|
+
"parserOptions": {
|
|
43
|
+
"project": true,
|
|
44
|
+
"sourceType": "module"
|
|
45
|
+
},
|
|
46
|
+
"ignorePatterns": [
|
|
47
|
+
"!.aegir.js",
|
|
48
|
+
"test/ts-use",
|
|
49
|
+
"*.d.ts"
|
|
50
|
+
]
|
|
51
|
+
},
|
|
52
|
+
"publishConfig": {
|
|
53
|
+
"access": "public"
|
|
54
|
+
},
|
|
55
|
+
"scripts": {
|
|
56
|
+
"clean": "aegir clean",
|
|
57
|
+
"build": "aegir build --no-bundle",
|
|
58
|
+
"test": "",
|
|
59
|
+
"lint": "aegir lint"
|
|
60
|
+
},
|
|
61
|
+
"author": "dao.xyz",
|
|
62
|
+
"license": "MIT",
|
|
63
|
+
"dependencies": {
|
|
64
|
+
"@peerbit/indexer-interface": "2.0.0-4d7d8ba",
|
|
65
|
+
"@types/uuid": "^9.0.8",
|
|
66
|
+
"benchmark": "^2.1.4"
|
|
67
|
+
}
|
|
68
68
|
}
|
package/src/tests.ts
CHANGED
|
@@ -142,7 +142,10 @@ const assertIteratorIsDone = async (iterator: IndexIterator<any, any>) => {
|
|
|
142
142
|
export const tests = (
|
|
143
143
|
createIndicies: (directory?: string) => Indices | Promise<Indices>,
|
|
144
144
|
type: "transient" | "persist" = "transient",
|
|
145
|
-
|
|
145
|
+
properties: {
|
|
146
|
+
shapingSupported: boolean;
|
|
147
|
+
u64SumSupported: boolean;
|
|
148
|
+
},
|
|
146
149
|
) => {
|
|
147
150
|
return describe("index", () => {
|
|
148
151
|
let store: Index<any, any>;
|
|
@@ -489,15 +492,16 @@ export const tests = (
|
|
|
489
492
|
});
|
|
490
493
|
});
|
|
491
494
|
|
|
492
|
-
|
|
495
|
+
/* TMP renable with sqlite support u64
|
|
496
|
+
describe("bigint", () => {
|
|
493
497
|
class DocumentBigintId {
|
|
494
498
|
@field({ type: "u64" })
|
|
495
499
|
id: bigint;
|
|
496
500
|
|
|
497
|
-
@field({ type: "
|
|
498
|
-
value:
|
|
501
|
+
@field({ type: "u64" })
|
|
502
|
+
value: bigint;
|
|
499
503
|
|
|
500
|
-
constructor(properties: { id: bigint; value:
|
|
504
|
+
constructor(properties: { id: bigint; value: bigint }) {
|
|
501
505
|
this.id = properties.id;
|
|
502
506
|
this.value = properties.value;
|
|
503
507
|
}
|
|
@@ -507,14 +511,14 @@ export const tests = (
|
|
|
507
511
|
const { store } = await setup({ schema: DocumentBigintId });
|
|
508
512
|
|
|
509
513
|
// make the id less than 2^53, but greater than u32 max
|
|
510
|
-
const id = BigInt(2 **
|
|
514
|
+
const id = BigInt(2 ** 63 - 1);
|
|
511
515
|
const doc = new DocumentBigintId({
|
|
512
516
|
id,
|
|
513
|
-
value:
|
|
517
|
+
value: id,
|
|
514
518
|
});
|
|
515
519
|
await testIndex(store, doc);
|
|
516
520
|
});
|
|
517
|
-
});
|
|
521
|
+
}); */
|
|
518
522
|
|
|
519
523
|
describe("by decorator", () => {
|
|
520
524
|
class DocumentWithDecoratedId {
|
|
@@ -845,7 +849,8 @@ export const tests = (
|
|
|
845
849
|
});
|
|
846
850
|
});
|
|
847
851
|
});
|
|
848
|
-
|
|
852
|
+
|
|
853
|
+
it("bool", async () => {
|
|
849
854
|
await setupDefault();
|
|
850
855
|
|
|
851
856
|
const responses = await search(store, {
|
|
@@ -2212,7 +2217,7 @@ export const tests = (
|
|
|
2212
2217
|
);
|
|
2213
2218
|
expect(results).to.have.length(4);
|
|
2214
2219
|
for (const result of results) {
|
|
2215
|
-
if (shapingSupported) {
|
|
2220
|
+
if (properties.shapingSupported) {
|
|
2216
2221
|
expect(Object.keys(result.value)).to.have.length(1);
|
|
2217
2222
|
expect(result.value["id"]).to.exist;
|
|
2218
2223
|
} else {
|
|
@@ -2238,7 +2243,7 @@ export const tests = (
|
|
|
2238
2243
|
if (arr.length > 0) {
|
|
2239
2244
|
for (const element of arr) {
|
|
2240
2245
|
expect(element.number).to.exist;
|
|
2241
|
-
if (shapingSupported) {
|
|
2246
|
+
if (properties.shapingSupported) {
|
|
2242
2247
|
expect(Object.keys(element)).to.have.length(1);
|
|
2243
2248
|
}
|
|
2244
2249
|
}
|
|
@@ -2314,7 +2319,7 @@ export const tests = (
|
|
|
2314
2319
|
expect(shapedResults).to.have.length(1);
|
|
2315
2320
|
expect(shapedResults[0].value.id).to.equal("2");
|
|
2316
2321
|
|
|
2317
|
-
if (shapingSupported) {
|
|
2322
|
+
if (properties.shapingSupported) {
|
|
2318
2323
|
expect(shapedResults[0].value["nested"]).to.be.undefined;
|
|
2319
2324
|
} else {
|
|
2320
2325
|
expect(shapedResults[0].value["nested"]).to.exist;
|
|
@@ -2366,7 +2371,7 @@ export const tests = (
|
|
|
2366
2371
|
expect(shapedResults).to.have.length(1);
|
|
2367
2372
|
expect(shapedResults[0].value.id).to.equal(d2.id);
|
|
2368
2373
|
|
|
2369
|
-
if (shapingSupported) {
|
|
2374
|
+
if (properties.shapingSupported) {
|
|
2370
2375
|
expect({ ...shapedResults[0].value.nested }).to.deep.equal({
|
|
2371
2376
|
bool: false,
|
|
2372
2377
|
});
|
|
@@ -2466,7 +2471,7 @@ export const tests = (
|
|
|
2466
2471
|
expect(shapedResults).to.have.length(1);
|
|
2467
2472
|
expect(shapedResults[0].value.id).to.equal("2");
|
|
2468
2473
|
|
|
2469
|
-
if (shapingSupported) {
|
|
2474
|
+
if (properties.shapingSupported) {
|
|
2470
2475
|
expect(shapedResults[0].value["nested"]).to.be.undefined;
|
|
2471
2476
|
} else {
|
|
2472
2477
|
expect(shapedResults[0].value["nested"]).to.exist;
|
|
@@ -2519,7 +2524,7 @@ export const tests = (
|
|
|
2519
2524
|
expect(shapedResults).to.have.length(1);
|
|
2520
2525
|
expect(shapedResults[0].value.id).to.equal(d2.id);
|
|
2521
2526
|
|
|
2522
|
-
if (shapingSupported) {
|
|
2527
|
+
if (properties.shapingSupported) {
|
|
2523
2528
|
expect({ ...shapedResults[0].value.nested }).to.deep.equal({
|
|
2524
2529
|
bool: false,
|
|
2525
2530
|
});
|
|
@@ -2596,7 +2601,7 @@ export const tests = (
|
|
|
2596
2601
|
expect(shapedResults).to.have.length(1);
|
|
2597
2602
|
expect(shapedResults[0].value.id).to.equal("2");
|
|
2598
2603
|
|
|
2599
|
-
if (shapingSupported) {
|
|
2604
|
+
if (properties.shapingSupported) {
|
|
2600
2605
|
expect(shapedResults[0].value["nested"]).to.be.undefined;
|
|
2601
2606
|
} else {
|
|
2602
2607
|
expect(shapedResults[0].value["nested"]).to.exist;
|
|
@@ -2638,7 +2643,7 @@ export const tests = (
|
|
|
2638
2643
|
expect(shapedResults).to.have.length(1);
|
|
2639
2644
|
expect(shapedResults[0].value.id).to.equal(d2.id);
|
|
2640
2645
|
|
|
2641
|
-
if (shapingSupported) {
|
|
2646
|
+
if (properties.shapingSupported) {
|
|
2642
2647
|
expect({ ...shapedResults[0].value.nested[0] }).to.deep.equal({
|
|
2643
2648
|
bool: false,
|
|
2644
2649
|
});
|
|
@@ -2690,9 +2695,9 @@ export const tests = (
|
|
|
2690
2695
|
});
|
|
2691
2696
|
|
|
2692
2697
|
describe("sort", () => {
|
|
2693
|
-
const put = async (id: number) => {
|
|
2698
|
+
const put = async (id: number, stringId?: string) => {
|
|
2694
2699
|
const doc = new Document({
|
|
2695
|
-
id: String(id),
|
|
2700
|
+
id: stringId ?? String(id),
|
|
2696
2701
|
name: String(id),
|
|
2697
2702
|
number: BigInt(id),
|
|
2698
2703
|
tags: [],
|
|
@@ -2768,7 +2773,7 @@ export const tests = (
|
|
|
2768
2773
|
await put(0);
|
|
2769
2774
|
await put(1);
|
|
2770
2775
|
await put(2);
|
|
2771
|
-
{
|
|
2776
|
+
const f1 = async () => {
|
|
2772
2777
|
const iterator = store.iterate({
|
|
2773
2778
|
query: [],
|
|
2774
2779
|
sort: [new Sort({ direction: SortDirection.ASC, key: "name" })],
|
|
@@ -2777,8 +2782,8 @@ export const tests = (
|
|
|
2777
2782
|
const next = await iterator.next(3);
|
|
2778
2783
|
expect(next.map((x) => x.value.name)).to.deep.equal(["0", "1", "2"]);
|
|
2779
2784
|
await assertIteratorIsDone(iterator);
|
|
2780
|
-
}
|
|
2781
|
-
{
|
|
2785
|
+
};
|
|
2786
|
+
const f2 = async () => {
|
|
2782
2787
|
const iterator = store.iterate({
|
|
2783
2788
|
query: [],
|
|
2784
2789
|
sort: [new Sort({ direction: SortDirection.DESC, key: "name" })],
|
|
@@ -2787,15 +2792,104 @@ export const tests = (
|
|
|
2787
2792
|
const next = await iterator.next(3);
|
|
2788
2793
|
expect(next.map((x) => x.value.name)).to.deep.equal(["2", "1", "0"]);
|
|
2789
2794
|
await assertIteratorIsDone(iterator);
|
|
2790
|
-
}
|
|
2795
|
+
};
|
|
2796
|
+
await f1();
|
|
2797
|
+
await f2();
|
|
2791
2798
|
});
|
|
2792
2799
|
|
|
2800
|
+
it("sorts by order", async () => {
|
|
2801
|
+
await put(0);
|
|
2802
|
+
await put(1);
|
|
2803
|
+
await put(2);
|
|
2804
|
+
const f1 = async () => {
|
|
2805
|
+
const iterator = store.iterate({
|
|
2806
|
+
query: [],
|
|
2807
|
+
sort: [new Sort({ direction: SortDirection.ASC, key: "name" })],
|
|
2808
|
+
});
|
|
2809
|
+
expect(iterator.done()).to.be.undefined;
|
|
2810
|
+
const next = await iterator.next(3);
|
|
2811
|
+
expect(next.map((x) => x.value.name)).to.deep.equal(["0", "1", "2"]);
|
|
2812
|
+
await assertIteratorIsDone(iterator);
|
|
2813
|
+
};
|
|
2814
|
+
const f2 = async () => {
|
|
2815
|
+
const iterator = store.iterate({
|
|
2816
|
+
query: [],
|
|
2817
|
+
sort: [new Sort({ direction: SortDirection.DESC, key: "name" })],
|
|
2818
|
+
});
|
|
2819
|
+
expect(iterator.done()).to.be.undefined;
|
|
2820
|
+
const next = await iterator.next(3);
|
|
2821
|
+
expect(next.map((x) => x.value.name)).to.deep.equal(["2", "1", "0"]);
|
|
2822
|
+
await assertIteratorIsDone(iterator);
|
|
2823
|
+
};
|
|
2824
|
+
const f3 = async () => {
|
|
2825
|
+
const iterator = store.iterate({
|
|
2826
|
+
query: [],
|
|
2827
|
+
sort: [new Sort({ direction: SortDirection.ASC, key: "name" })],
|
|
2828
|
+
});
|
|
2829
|
+
expect(iterator.done()).to.be.undefined;
|
|
2830
|
+
let next = await iterator.next(2);
|
|
2831
|
+
expect(next.map((x) => x.value.name)).to.deep.equal(["0", "1"]);
|
|
2832
|
+
next = await iterator.next(1);
|
|
2833
|
+
expect(next.map((x) => x.value.name)).to.deep.equal(["2"]);
|
|
2834
|
+
await assertIteratorIsDone(iterator);
|
|
2835
|
+
};
|
|
2836
|
+
const f4 = async () => {
|
|
2837
|
+
const iterator = store.iterate({
|
|
2838
|
+
query: [],
|
|
2839
|
+
sort: [new Sort({ direction: SortDirection.DESC, key: "name" })],
|
|
2840
|
+
});
|
|
2841
|
+
expect(iterator.done()).to.be.undefined;
|
|
2842
|
+
let next = await iterator.next(2);
|
|
2843
|
+
expect(next.map((x) => x.value.name)).to.deep.equal(["2", "1"]);
|
|
2844
|
+
next = await iterator.next(1);
|
|
2845
|
+
expect(next.map((x) => x.value.name)).to.deep.equal(["0"]);
|
|
2846
|
+
await assertIteratorIsDone(iterator);
|
|
2847
|
+
};
|
|
2848
|
+
const f5 = async () => {
|
|
2849
|
+
const iterator = store.iterate({
|
|
2850
|
+
query: [],
|
|
2851
|
+
sort: [new Sort({ direction: SortDirection.ASC, key: "name" })],
|
|
2852
|
+
});
|
|
2853
|
+
expect(iterator.done()).to.be.undefined;
|
|
2854
|
+
let next = await iterator.next(1);
|
|
2855
|
+
expect(next.map((x) => x.value.name)).to.deep.equal(["0"]);
|
|
2856
|
+
next = await iterator.next(1);
|
|
2857
|
+
expect(next.map((x) => x.value.name)).to.deep.equal(["1"]);
|
|
2858
|
+
next = await iterator.next(1);
|
|
2859
|
+
expect(next.map((x) => x.value.name)).to.deep.equal(["2"]);
|
|
2860
|
+
await assertIteratorIsDone(iterator);
|
|
2861
|
+
};
|
|
2862
|
+
await f1();
|
|
2863
|
+
await f2();
|
|
2864
|
+
await f3();
|
|
2865
|
+
await f4();
|
|
2866
|
+
await f5();
|
|
2867
|
+
});
|
|
2868
|
+
|
|
2869
|
+
/* it("no sort is stable", async () => {
|
|
2870
|
+
// TODO this test is actually not a good predictor of stability
|
|
2871
|
+
|
|
2872
|
+
const insertCount = 500;
|
|
2873
|
+
for (let i = 0; i < insertCount; i++) {
|
|
2874
|
+
await put(i, uuid());
|
|
2875
|
+
}
|
|
2876
|
+
|
|
2877
|
+
const resolvedValues: Set<number> = new Set()
|
|
2878
|
+
const batchSize = 123;
|
|
2879
|
+
const iterator = store.iterate();
|
|
2880
|
+
while (!iterator.done()) {
|
|
2881
|
+
const next = await iterator.next(batchSize);
|
|
2882
|
+
next.map((x) => resolvedValues.add(Number(x.value.number)));
|
|
2883
|
+
}
|
|
2884
|
+
expect(resolvedValues.size).to.equal(insertCount);
|
|
2885
|
+
}); */
|
|
2886
|
+
|
|
2793
2887
|
it("strings", async () => {
|
|
2794
2888
|
await put(0);
|
|
2795
2889
|
await put(1);
|
|
2796
2890
|
await put(2);
|
|
2797
2891
|
|
|
2798
|
-
const iterator =
|
|
2892
|
+
const iterator = store.iterate({
|
|
2799
2893
|
query: [],
|
|
2800
2894
|
sort: [new Sort({ direction: SortDirection.ASC, key: "name" })],
|
|
2801
2895
|
});
|
|
@@ -3107,24 +3201,70 @@ export const tests = (
|
|
|
3107
3201
|
});
|
|
3108
3202
|
|
|
3109
3203
|
describe("sum", () => {
|
|
3204
|
+
class SummableDocument {
|
|
3205
|
+
@field({ type: "string" })
|
|
3206
|
+
id: string;
|
|
3207
|
+
|
|
3208
|
+
@field({ type: option("u32") })
|
|
3209
|
+
value?: number;
|
|
3210
|
+
|
|
3211
|
+
constructor(opts: SummableDocument) {
|
|
3212
|
+
this.id = opts.id;
|
|
3213
|
+
this.value = opts.value;
|
|
3214
|
+
}
|
|
3215
|
+
}
|
|
3110
3216
|
it("it returns sum", async () => {
|
|
3111
|
-
await
|
|
3112
|
-
|
|
3217
|
+
await setup({ schema: SummableDocument });
|
|
3218
|
+
await store.put(
|
|
3219
|
+
new SummableDocument({
|
|
3220
|
+
id: "1",
|
|
3221
|
+
value: 1,
|
|
3222
|
+
}),
|
|
3223
|
+
);
|
|
3224
|
+
await store.put(
|
|
3225
|
+
new SummableDocument({
|
|
3226
|
+
id: "2",
|
|
3227
|
+
value: 2,
|
|
3228
|
+
}),
|
|
3229
|
+
);
|
|
3230
|
+
const sum = await store.sum({ key: "value" });
|
|
3113
3231
|
typeof sum === "bigint"
|
|
3114
|
-
? expect(sum).to.equal(
|
|
3115
|
-
: expect(sum).to.equal(
|
|
3232
|
+
? expect(sum).to.equal(3n)
|
|
3233
|
+
: expect(sum).to.equal(3);
|
|
3116
3234
|
});
|
|
3117
3235
|
|
|
3236
|
+
if (properties.u64SumSupported) {
|
|
3237
|
+
it("u64", async () => {
|
|
3238
|
+
await setupDefault();
|
|
3239
|
+
const sum = await store.sum({ key: "number" });
|
|
3240
|
+
typeof sum === "bigint"
|
|
3241
|
+
? expect(sum).to.equal(6n)
|
|
3242
|
+
: expect(sum).to.equal(6);
|
|
3243
|
+
});
|
|
3244
|
+
}
|
|
3245
|
+
|
|
3118
3246
|
it("it returns sum with query", async () => {
|
|
3119
|
-
await
|
|
3247
|
+
await setup({ schema: SummableDocument });
|
|
3248
|
+
await store.put(
|
|
3249
|
+
new SummableDocument({
|
|
3250
|
+
id: "1",
|
|
3251
|
+
value: 1,
|
|
3252
|
+
}),
|
|
3253
|
+
);
|
|
3254
|
+
await store.put(
|
|
3255
|
+
new SummableDocument({
|
|
3256
|
+
id: "2",
|
|
3257
|
+
value: 2,
|
|
3258
|
+
}),
|
|
3259
|
+
);
|
|
3260
|
+
|
|
3120
3261
|
const sum = await store.sum({
|
|
3121
|
-
key: "
|
|
3262
|
+
key: "value",
|
|
3122
3263
|
query: [
|
|
3123
|
-
new
|
|
3124
|
-
key: "
|
|
3125
|
-
|
|
3126
|
-
|
|
3127
|
-
caseInsensitive: true,
|
|
3264
|
+
new IntegerCompare({
|
|
3265
|
+
key: "value",
|
|
3266
|
+
compare: Compare.Greater,
|
|
3267
|
+
value: 1,
|
|
3128
3268
|
}),
|
|
3129
3269
|
],
|
|
3130
3270
|
});
|