@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/dist/src/tests.d.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
1
|
import { type Indices } from "@peerbit/indexer-interface";
|
|
2
|
-
export declare const tests: (createIndicies: (directory?: string) => Indices | Promise<Indices>, type: "transient" | "persist",
|
|
2
|
+
export declare const tests: (createIndicies: (directory?: string) => Indices | Promise<Indices>, type: "transient" | "persist", properties: {
|
|
3
|
+
shapingSupported: boolean;
|
|
4
|
+
u64SumSupported: boolean;
|
|
5
|
+
}) => Mocha.Suite;
|
|
3
6
|
//# sourceMappingURL=tests.d.ts.map
|
package/dist/src/tests.d.ts.map
CHANGED
|
@@ -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;AA0GpC,eAAO,MAAM,KAAK,mBACD,CAAC,SAAS,CAAC,EAAE,MAAM,KAAK,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,QAC5D,WAAW,GAAG,SAAS,
|
|
1
|
+
{"version":3,"file":"tests.d.ts","sourceRoot":"","sources":["../../src/tests.ts"],"names":[],"mappings":"AAUA,OAAO,EAQN,KAAK,OAAO,EAiBZ,MAAM,4BAA4B,CAAC;AA0GpC,eAAO,MAAM,KAAK,mBACD,CAAC,SAAS,CAAC,EAAE,MAAM,KAAK,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,QAC5D,WAAW,GAAG,SAAS,cACjB;IACX,gBAAgB,EAAE,OAAO,CAAC;IAC1B,eAAe,EAAE,OAAO,CAAC;CACzB,gBA41GD,CAAC"}
|
package/dist/src/tests.js
CHANGED
|
@@ -136,7 +136,7 @@ const assertIteratorIsDone = async (iterator) => {
|
|
|
136
136
|
}
|
|
137
137
|
expect(iterator.done()).to.be.true;
|
|
138
138
|
};
|
|
139
|
-
export const tests = (createIndicies, type = "transient",
|
|
139
|
+
export const tests = (createIndicies, type = "transient", properties) => {
|
|
140
140
|
return describe("index", () => {
|
|
141
141
|
let store;
|
|
142
142
|
let indices;
|
|
@@ -435,34 +435,33 @@ export const tests = (createIndicies, type = "transient", shapingSupported) => {
|
|
|
435
435
|
await testIndex(store, doc);
|
|
436
436
|
});
|
|
437
437
|
});
|
|
438
|
-
|
|
438
|
+
/* TMP renable with sqlite support u64
|
|
439
|
+
describe("bigint", () => {
|
|
439
440
|
class DocumentBigintId {
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
441
|
+
@field({ type: "u64" })
|
|
442
|
+
id: bigint;
|
|
443
|
+
|
|
444
|
+
@field({ type: "u64" })
|
|
445
|
+
value: bigint;
|
|
446
|
+
|
|
447
|
+
constructor(properties: { id: bigint; value: bigint }) {
|
|
443
448
|
this.id = properties.id;
|
|
444
449
|
this.value = properties.value;
|
|
445
450
|
}
|
|
446
451
|
}
|
|
447
|
-
|
|
448
|
-
field({ type: "u64" }),
|
|
449
|
-
__metadata("design:type", BigInt)
|
|
450
|
-
], DocumentBigintId.prototype, "id", void 0);
|
|
451
|
-
__decorate([
|
|
452
|
-
field({ type: "string" }),
|
|
453
|
-
__metadata("design:type", String)
|
|
454
|
-
], DocumentBigintId.prototype, "value", void 0);
|
|
452
|
+
|
|
455
453
|
it("index as bigint", async () => {
|
|
456
454
|
const { store } = await setup({ schema: DocumentBigintId });
|
|
455
|
+
|
|
457
456
|
// make the id less than 2^53, but greater than u32 max
|
|
458
|
-
const id = BigInt(2 **
|
|
457
|
+
const id = BigInt(2 ** 63 - 1);
|
|
459
458
|
const doc = new DocumentBigintId({
|
|
460
459
|
id,
|
|
461
|
-
value:
|
|
460
|
+
value: id,
|
|
462
461
|
});
|
|
463
462
|
await testIndex(store, doc);
|
|
464
463
|
});
|
|
465
|
-
});
|
|
464
|
+
}); */
|
|
466
465
|
describe("by decorator", () => {
|
|
467
466
|
class DocumentWithDecoratedId {
|
|
468
467
|
xyz;
|
|
@@ -770,7 +769,7 @@ export const tests = (createIndicies, type = "transient", shapingSupported) => {
|
|
|
770
769
|
});
|
|
771
770
|
});
|
|
772
771
|
});
|
|
773
|
-
|
|
772
|
+
it("bool", async () => {
|
|
774
773
|
await setupDefault();
|
|
775
774
|
const responses = await search(store, {
|
|
776
775
|
query: [
|
|
@@ -2095,7 +2094,7 @@ export const tests = (createIndicies, type = "transient", shapingSupported) => {
|
|
|
2095
2094
|
const results = await search(store, { query: [] }, { shape: { id: true } });
|
|
2096
2095
|
expect(results).to.have.length(4);
|
|
2097
2096
|
for (const result of results) {
|
|
2098
|
-
if (shapingSupported) {
|
|
2097
|
+
if (properties.shapingSupported) {
|
|
2099
2098
|
expect(Object.keys(result.value)).to.have.length(1);
|
|
2100
2099
|
expect(result.value["id"]).to.exist;
|
|
2101
2100
|
}
|
|
@@ -2114,7 +2113,7 @@ export const tests = (createIndicies, type = "transient", shapingSupported) => {
|
|
|
2114
2113
|
if (arr.length > 0) {
|
|
2115
2114
|
for (const element of arr) {
|
|
2116
2115
|
expect(element.number).to.exist;
|
|
2117
|
-
if (shapingSupported) {
|
|
2116
|
+
if (properties.shapingSupported) {
|
|
2118
2117
|
expect(Object.keys(element)).to.have.length(1);
|
|
2119
2118
|
}
|
|
2120
2119
|
}
|
|
@@ -2179,7 +2178,7 @@ export const tests = (createIndicies, type = "transient", shapingSupported) => {
|
|
|
2179
2178
|
.all();
|
|
2180
2179
|
expect(shapedResults).to.have.length(1);
|
|
2181
2180
|
expect(shapedResults[0].value.id).to.equal("2");
|
|
2182
|
-
if (shapingSupported) {
|
|
2181
|
+
if (properties.shapingSupported) {
|
|
2183
2182
|
expect(shapedResults[0].value["nested"]).to.be.undefined;
|
|
2184
2183
|
}
|
|
2185
2184
|
else {
|
|
@@ -2215,7 +2214,7 @@ export const tests = (createIndicies, type = "transient", shapingSupported) => {
|
|
|
2215
2214
|
.all();
|
|
2216
2215
|
expect(shapedResults).to.have.length(1);
|
|
2217
2216
|
expect(shapedResults[0].value.id).to.equal(d2.id);
|
|
2218
|
-
if (shapingSupported) {
|
|
2217
|
+
if (properties.shapingSupported) {
|
|
2219
2218
|
expect({ ...shapedResults[0].value.nested }).to.deep.equal({
|
|
2220
2219
|
bool: false,
|
|
2221
2220
|
});
|
|
@@ -2316,7 +2315,7 @@ export const tests = (createIndicies, type = "transient", shapingSupported) => {
|
|
|
2316
2315
|
.all();
|
|
2317
2316
|
expect(shapedResults).to.have.length(1);
|
|
2318
2317
|
expect(shapedResults[0].value.id).to.equal("2");
|
|
2319
|
-
if (shapingSupported) {
|
|
2318
|
+
if (properties.shapingSupported) {
|
|
2320
2319
|
expect(shapedResults[0].value["nested"]).to.be.undefined;
|
|
2321
2320
|
}
|
|
2322
2321
|
else {
|
|
@@ -2352,7 +2351,7 @@ export const tests = (createIndicies, type = "transient", shapingSupported) => {
|
|
|
2352
2351
|
.all();
|
|
2353
2352
|
expect(shapedResults).to.have.length(1);
|
|
2354
2353
|
expect(shapedResults[0].value.id).to.equal(d2.id);
|
|
2355
|
-
if (shapingSupported) {
|
|
2354
|
+
if (properties.shapingSupported) {
|
|
2356
2355
|
expect({ ...shapedResults[0].value.nested }).to.deep.equal({
|
|
2357
2356
|
bool: false,
|
|
2358
2357
|
});
|
|
@@ -2419,7 +2418,7 @@ export const tests = (createIndicies, type = "transient", shapingSupported) => {
|
|
|
2419
2418
|
.all();
|
|
2420
2419
|
expect(shapedResults).to.have.length(1);
|
|
2421
2420
|
expect(shapedResults[0].value.id).to.equal("2");
|
|
2422
|
-
if (shapingSupported) {
|
|
2421
|
+
if (properties.shapingSupported) {
|
|
2423
2422
|
expect(shapedResults[0].value["nested"]).to.be.undefined;
|
|
2424
2423
|
}
|
|
2425
2424
|
else {
|
|
@@ -2447,7 +2446,7 @@ export const tests = (createIndicies, type = "transient", shapingSupported) => {
|
|
|
2447
2446
|
.all();
|
|
2448
2447
|
expect(shapedResults).to.have.length(1);
|
|
2449
2448
|
expect(shapedResults[0].value.id).to.equal(d2.id);
|
|
2450
|
-
if (shapingSupported) {
|
|
2449
|
+
if (properties.shapingSupported) {
|
|
2451
2450
|
expect({ ...shapedResults[0].value.nested[0] }).to.deep.equal({
|
|
2452
2451
|
bool: false,
|
|
2453
2452
|
});
|
|
@@ -2481,9 +2480,9 @@ export const tests = (createIndicies, type = "transient", shapingSupported) => {
|
|
|
2481
2480
|
});
|
|
2482
2481
|
});
|
|
2483
2482
|
describe("sort", () => {
|
|
2484
|
-
const put = async (id) => {
|
|
2483
|
+
const put = async (id, stringId) => {
|
|
2485
2484
|
const doc = new Document({
|
|
2486
|
-
id: String(id),
|
|
2485
|
+
id: stringId ?? String(id),
|
|
2487
2486
|
name: String(id),
|
|
2488
2487
|
number: BigInt(id),
|
|
2489
2488
|
tags: [],
|
|
@@ -2547,7 +2546,7 @@ export const tests = (createIndicies, type = "transient", shapingSupported) => {
|
|
|
2547
2546
|
await put(0);
|
|
2548
2547
|
await put(1);
|
|
2549
2548
|
await put(2);
|
|
2550
|
-
{
|
|
2549
|
+
const f1 = async () => {
|
|
2551
2550
|
const iterator = store.iterate({
|
|
2552
2551
|
query: [],
|
|
2553
2552
|
sort: [new Sort({ direction: SortDirection.ASC, key: "name" })],
|
|
@@ -2556,8 +2555,8 @@ export const tests = (createIndicies, type = "transient", shapingSupported) => {
|
|
|
2556
2555
|
const next = await iterator.next(3);
|
|
2557
2556
|
expect(next.map((x) => x.value.name)).to.deep.equal(["0", "1", "2"]);
|
|
2558
2557
|
await assertIteratorIsDone(iterator);
|
|
2559
|
-
}
|
|
2560
|
-
{
|
|
2558
|
+
};
|
|
2559
|
+
const f2 = async () => {
|
|
2561
2560
|
const iterator = store.iterate({
|
|
2562
2561
|
query: [],
|
|
2563
2562
|
sort: [new Sort({ direction: SortDirection.DESC, key: "name" })],
|
|
@@ -2566,13 +2565,100 @@ export const tests = (createIndicies, type = "transient", shapingSupported) => {
|
|
|
2566
2565
|
const next = await iterator.next(3);
|
|
2567
2566
|
expect(next.map((x) => x.value.name)).to.deep.equal(["2", "1", "0"]);
|
|
2568
2567
|
await assertIteratorIsDone(iterator);
|
|
2569
|
-
}
|
|
2568
|
+
};
|
|
2569
|
+
await f1();
|
|
2570
|
+
await f2();
|
|
2570
2571
|
});
|
|
2572
|
+
it("sorts by order", async () => {
|
|
2573
|
+
await put(0);
|
|
2574
|
+
await put(1);
|
|
2575
|
+
await put(2);
|
|
2576
|
+
const f1 = async () => {
|
|
2577
|
+
const iterator = store.iterate({
|
|
2578
|
+
query: [],
|
|
2579
|
+
sort: [new Sort({ direction: SortDirection.ASC, key: "name" })],
|
|
2580
|
+
});
|
|
2581
|
+
expect(iterator.done()).to.be.undefined;
|
|
2582
|
+
const next = await iterator.next(3);
|
|
2583
|
+
expect(next.map((x) => x.value.name)).to.deep.equal(["0", "1", "2"]);
|
|
2584
|
+
await assertIteratorIsDone(iterator);
|
|
2585
|
+
};
|
|
2586
|
+
const f2 = async () => {
|
|
2587
|
+
const iterator = store.iterate({
|
|
2588
|
+
query: [],
|
|
2589
|
+
sort: [new Sort({ direction: SortDirection.DESC, key: "name" })],
|
|
2590
|
+
});
|
|
2591
|
+
expect(iterator.done()).to.be.undefined;
|
|
2592
|
+
const next = await iterator.next(3);
|
|
2593
|
+
expect(next.map((x) => x.value.name)).to.deep.equal(["2", "1", "0"]);
|
|
2594
|
+
await assertIteratorIsDone(iterator);
|
|
2595
|
+
};
|
|
2596
|
+
const f3 = async () => {
|
|
2597
|
+
const iterator = store.iterate({
|
|
2598
|
+
query: [],
|
|
2599
|
+
sort: [new Sort({ direction: SortDirection.ASC, key: "name" })],
|
|
2600
|
+
});
|
|
2601
|
+
expect(iterator.done()).to.be.undefined;
|
|
2602
|
+
let next = await iterator.next(2);
|
|
2603
|
+
expect(next.map((x) => x.value.name)).to.deep.equal(["0", "1"]);
|
|
2604
|
+
next = await iterator.next(1);
|
|
2605
|
+
expect(next.map((x) => x.value.name)).to.deep.equal(["2"]);
|
|
2606
|
+
await assertIteratorIsDone(iterator);
|
|
2607
|
+
};
|
|
2608
|
+
const f4 = async () => {
|
|
2609
|
+
const iterator = store.iterate({
|
|
2610
|
+
query: [],
|
|
2611
|
+
sort: [new Sort({ direction: SortDirection.DESC, key: "name" })],
|
|
2612
|
+
});
|
|
2613
|
+
expect(iterator.done()).to.be.undefined;
|
|
2614
|
+
let next = await iterator.next(2);
|
|
2615
|
+
expect(next.map((x) => x.value.name)).to.deep.equal(["2", "1"]);
|
|
2616
|
+
next = await iterator.next(1);
|
|
2617
|
+
expect(next.map((x) => x.value.name)).to.deep.equal(["0"]);
|
|
2618
|
+
await assertIteratorIsDone(iterator);
|
|
2619
|
+
};
|
|
2620
|
+
const f5 = async () => {
|
|
2621
|
+
const iterator = store.iterate({
|
|
2622
|
+
query: [],
|
|
2623
|
+
sort: [new Sort({ direction: SortDirection.ASC, key: "name" })],
|
|
2624
|
+
});
|
|
2625
|
+
expect(iterator.done()).to.be.undefined;
|
|
2626
|
+
let next = await iterator.next(1);
|
|
2627
|
+
expect(next.map((x) => x.value.name)).to.deep.equal(["0"]);
|
|
2628
|
+
next = await iterator.next(1);
|
|
2629
|
+
expect(next.map((x) => x.value.name)).to.deep.equal(["1"]);
|
|
2630
|
+
next = await iterator.next(1);
|
|
2631
|
+
expect(next.map((x) => x.value.name)).to.deep.equal(["2"]);
|
|
2632
|
+
await assertIteratorIsDone(iterator);
|
|
2633
|
+
};
|
|
2634
|
+
await f1();
|
|
2635
|
+
await f2();
|
|
2636
|
+
await f3();
|
|
2637
|
+
await f4();
|
|
2638
|
+
await f5();
|
|
2639
|
+
});
|
|
2640
|
+
/* it("no sort is stable", async () => {
|
|
2641
|
+
// TODO this test is actually not a good predictor of stability
|
|
2642
|
+
|
|
2643
|
+
const insertCount = 500;
|
|
2644
|
+
for (let i = 0; i < insertCount; i++) {
|
|
2645
|
+
await put(i, uuid());
|
|
2646
|
+
}
|
|
2647
|
+
|
|
2648
|
+
const resolvedValues: Set<number> = new Set()
|
|
2649
|
+
const batchSize = 123;
|
|
2650
|
+
const iterator = store.iterate();
|
|
2651
|
+
while (!iterator.done()) {
|
|
2652
|
+
const next = await iterator.next(batchSize);
|
|
2653
|
+
next.map((x) => resolvedValues.add(Number(x.value.number)));
|
|
2654
|
+
}
|
|
2655
|
+
expect(resolvedValues.size).to.equal(insertCount);
|
|
2656
|
+
}); */
|
|
2571
2657
|
it("strings", async () => {
|
|
2572
2658
|
await put(0);
|
|
2573
2659
|
await put(1);
|
|
2574
2660
|
await put(2);
|
|
2575
|
-
const iterator =
|
|
2661
|
+
const iterator = store.iterate({
|
|
2576
2662
|
query: [],
|
|
2577
2663
|
sort: [new Sort({ direction: SortDirection.ASC, key: "name" })],
|
|
2578
2664
|
});
|
|
@@ -2881,23 +2967,63 @@ export const tests = (createIndicies, type = "transient", shapingSupported) => {
|
|
|
2881
2967
|
// TODO session timeouts?
|
|
2882
2968
|
});
|
|
2883
2969
|
describe("sum", () => {
|
|
2970
|
+
class SummableDocument {
|
|
2971
|
+
id;
|
|
2972
|
+
value;
|
|
2973
|
+
constructor(opts) {
|
|
2974
|
+
this.id = opts.id;
|
|
2975
|
+
this.value = opts.value;
|
|
2976
|
+
}
|
|
2977
|
+
}
|
|
2978
|
+
__decorate([
|
|
2979
|
+
field({ type: "string" }),
|
|
2980
|
+
__metadata("design:type", String)
|
|
2981
|
+
], SummableDocument.prototype, "id", void 0);
|
|
2982
|
+
__decorate([
|
|
2983
|
+
field({ type: option("u32") }),
|
|
2984
|
+
__metadata("design:type", Number)
|
|
2985
|
+
], SummableDocument.prototype, "value", void 0);
|
|
2884
2986
|
it("it returns sum", async () => {
|
|
2885
|
-
await
|
|
2886
|
-
|
|
2987
|
+
await setup({ schema: SummableDocument });
|
|
2988
|
+
await store.put(new SummableDocument({
|
|
2989
|
+
id: "1",
|
|
2990
|
+
value: 1,
|
|
2991
|
+
}));
|
|
2992
|
+
await store.put(new SummableDocument({
|
|
2993
|
+
id: "2",
|
|
2994
|
+
value: 2,
|
|
2995
|
+
}));
|
|
2996
|
+
const sum = await store.sum({ key: "value" });
|
|
2887
2997
|
typeof sum === "bigint"
|
|
2888
|
-
? expect(sum).to.equal(
|
|
2889
|
-
: expect(sum).to.equal(
|
|
2998
|
+
? expect(sum).to.equal(3n)
|
|
2999
|
+
: expect(sum).to.equal(3);
|
|
2890
3000
|
});
|
|
3001
|
+
if (properties.u64SumSupported) {
|
|
3002
|
+
it("u64", async () => {
|
|
3003
|
+
await setupDefault();
|
|
3004
|
+
const sum = await store.sum({ key: "number" });
|
|
3005
|
+
typeof sum === "bigint"
|
|
3006
|
+
? expect(sum).to.equal(6n)
|
|
3007
|
+
: expect(sum).to.equal(6);
|
|
3008
|
+
});
|
|
3009
|
+
}
|
|
2891
3010
|
it("it returns sum with query", async () => {
|
|
2892
|
-
await
|
|
3011
|
+
await setup({ schema: SummableDocument });
|
|
3012
|
+
await store.put(new SummableDocument({
|
|
3013
|
+
id: "1",
|
|
3014
|
+
value: 1,
|
|
3015
|
+
}));
|
|
3016
|
+
await store.put(new SummableDocument({
|
|
3017
|
+
id: "2",
|
|
3018
|
+
value: 2,
|
|
3019
|
+
}));
|
|
2893
3020
|
const sum = await store.sum({
|
|
2894
|
-
key: "
|
|
3021
|
+
key: "value",
|
|
2895
3022
|
query: [
|
|
2896
|
-
new
|
|
2897
|
-
key: "
|
|
2898
|
-
|
|
2899
|
-
|
|
2900
|
-
caseInsensitive: true,
|
|
3023
|
+
new IntegerCompare({
|
|
3024
|
+
key: "value",
|
|
3025
|
+
compare: Compare.Greater,
|
|
3026
|
+
value: 1,
|
|
2901
3027
|
}),
|
|
2902
3028
|
],
|
|
2903
3029
|
});
|