@peerbit/indexer-tests 3.0.2 → 3.0.4
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/benchmarks.d.ts.map +1 -1
- package/dist/src/benchmarks.js +100 -19
- package/dist/src/benchmarks.js.map +1 -1
- package/dist/src/tests.d.ts.map +1 -1
- package/dist/src/tests.js +48 -1
- package/dist/src/tests.js.map +1 -1
- package/package.json +3 -3
- package/src/benchmarks.ts +10 -1
- package/src/tests.ts +66 -6
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@peerbit/indexer-tests",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.4",
|
|
4
4
|
"description": "Tests document store index engines",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"type": "module",
|
|
@@ -60,8 +60,8 @@
|
|
|
60
60
|
"uint8arrays": "^5.1.0",
|
|
61
61
|
"benchmark": "^2.1.4",
|
|
62
62
|
"uuid": "^10.0.0",
|
|
63
|
-
"@peerbit/indexer-interface": "3.0.
|
|
64
|
-
"@peerbit/crypto": "3.1.
|
|
63
|
+
"@peerbit/indexer-interface": "3.0.4",
|
|
64
|
+
"@peerbit/crypto": "3.1.1",
|
|
65
65
|
"@peerbit/time": "3.0.0"
|
|
66
66
|
},
|
|
67
67
|
"scripts": {
|
package/src/benchmarks.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { field, vec } from "@dao-xyz/borsh";
|
|
1
|
+
import { field, variant, vec } from "@dao-xyz/borsh";
|
|
2
2
|
import {
|
|
3
3
|
And,
|
|
4
4
|
BoolQuery,
|
|
@@ -44,6 +44,7 @@ const stringBenchmark = async (
|
|
|
44
44
|
createIndicies: (directory?: string) => Indices | Promise<Indices>,
|
|
45
45
|
type: "transient" | "persist" = "transient",
|
|
46
46
|
) => {
|
|
47
|
+
@variant("benchmark_string_document")
|
|
47
48
|
class StringDocument {
|
|
48
49
|
@id({ type: "string" })
|
|
49
50
|
id: string;
|
|
@@ -122,6 +123,7 @@ const boolQueryBenchmark = async (
|
|
|
122
123
|
createIndicies: (directory?: string) => Indices | Promise<Indices>,
|
|
123
124
|
type: "transient" | "persist" = "transient",
|
|
124
125
|
) => {
|
|
126
|
+
@variant("benchmark_bool_query_document")
|
|
125
127
|
class BoolQueryDocument {
|
|
126
128
|
@id({ type: "string" })
|
|
127
129
|
id: string;
|
|
@@ -205,6 +207,7 @@ const inequalityBenchmark = async (
|
|
|
205
207
|
createIndicies: (directory?: string) => Indices | Promise<Indices>,
|
|
206
208
|
type: "transient" | "persist" = "transient",
|
|
207
209
|
) => {
|
|
210
|
+
@variant("benchmark_number_query_document")
|
|
208
211
|
class NumberQueryDocument {
|
|
209
212
|
@id({ type: "string" })
|
|
210
213
|
id: string;
|
|
@@ -296,6 +299,7 @@ const getBenchmark = async (
|
|
|
296
299
|
createIndicies: (directory?: string) => Indices | Promise<Indices>,
|
|
297
300
|
type: "transient" | "persist" = "transient",
|
|
298
301
|
) => {
|
|
302
|
+
@variant("benchmark_get_bool_query_document")
|
|
299
303
|
class BoolQueryDocument {
|
|
300
304
|
@id({ type: "string" })
|
|
301
305
|
id: string;
|
|
@@ -359,6 +363,7 @@ const nestedBoolQueryBenchmark = async (
|
|
|
359
363
|
createIndicies: (directory?: string) => Indices | Promise<Indices>,
|
|
360
364
|
type: "transient" | "persist" = "transient",
|
|
361
365
|
) => {
|
|
366
|
+
@variant("benchmark_nested_bool_value")
|
|
362
367
|
class Nested {
|
|
363
368
|
@field({ type: "bool" })
|
|
364
369
|
bool: boolean;
|
|
@@ -368,6 +373,7 @@ const nestedBoolQueryBenchmark = async (
|
|
|
368
373
|
}
|
|
369
374
|
}
|
|
370
375
|
|
|
376
|
+
@variant("benchmark_nested_bool_query_document")
|
|
371
377
|
class NestedBoolQueryDocument {
|
|
372
378
|
@id({ type: "string" })
|
|
373
379
|
id: string;
|
|
@@ -438,6 +444,7 @@ const shapedQueryBenchmark = async (
|
|
|
438
444
|
createIndicies: (directory?: string) => Indices | Promise<Indices>,
|
|
439
445
|
type: "transient" | "persist" = "transient",
|
|
440
446
|
) => {
|
|
447
|
+
@variant("benchmark_shaped_nested_bool_value")
|
|
441
448
|
class Nested {
|
|
442
449
|
@field({ type: "bool" })
|
|
443
450
|
bool: boolean;
|
|
@@ -447,6 +454,7 @@ const shapedQueryBenchmark = async (
|
|
|
447
454
|
}
|
|
448
455
|
}
|
|
449
456
|
|
|
457
|
+
@variant("benchmark_shaped_nested_bool_query_document")
|
|
450
458
|
class NestedBoolQueryDocument {
|
|
451
459
|
@id({ type: "string" })
|
|
452
460
|
id: string;
|
|
@@ -533,6 +541,7 @@ const multiFieldQueryBenchmark = async (
|
|
|
533
541
|
createIndicies: (directory?: string) => Indices | Promise<Indices>,
|
|
534
542
|
type: "transient" | "persist" = "transient",
|
|
535
543
|
) => {
|
|
544
|
+
@variant("benchmark_replication_range_indexable_u32")
|
|
536
545
|
class ReplicationRangeIndexableU32 {
|
|
537
546
|
@id({ type: "string" })
|
|
538
547
|
id: string;
|
package/src/tests.ts
CHANGED
|
@@ -21,6 +21,7 @@ import {
|
|
|
21
21
|
IsNull,
|
|
22
22
|
type IterateOptions,
|
|
23
23
|
Not,
|
|
24
|
+
NotStartedError,
|
|
24
25
|
Or,
|
|
25
26
|
Query,
|
|
26
27
|
type Shape,
|
|
@@ -134,6 +135,16 @@ const assertIteratorIsDone = async (iterator: IndexIterator<any, any>) => {
|
|
|
134
135
|
expect(iterator.done()).to.be.true;
|
|
135
136
|
};
|
|
136
137
|
|
|
138
|
+
const expectNotStarted = async (fn: () => any) => {
|
|
139
|
+
try {
|
|
140
|
+
await fn();
|
|
141
|
+
} catch (error) {
|
|
142
|
+
expect(error).to.be.instanceOf(NotStartedError);
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
expect.fail("Expected NotStartedError");
|
|
146
|
+
};
|
|
147
|
+
|
|
137
148
|
export const tests = (
|
|
138
149
|
createIndicies: (directory?: string) => Indices | Promise<Indices>,
|
|
139
150
|
type: "transient" | "persist" = "transient",
|
|
@@ -297,6 +308,55 @@ export const tests = (
|
|
|
297
308
|
await indices?.drop?.();
|
|
298
309
|
});
|
|
299
310
|
|
|
311
|
+
describe("lifecycle", () => {
|
|
312
|
+
it("throws from public data APIs after stop has completed", async () => {
|
|
313
|
+
const { store, indices } = await setup({ schema: Document });
|
|
314
|
+
await store.put(
|
|
315
|
+
new Document({
|
|
316
|
+
id: "closed",
|
|
317
|
+
name: "closed",
|
|
318
|
+
number: 10n,
|
|
319
|
+
tags: ["closed"],
|
|
320
|
+
}),
|
|
321
|
+
);
|
|
322
|
+
expect(await store.getSize()).to.equal(1);
|
|
323
|
+
|
|
324
|
+
const openIterator = store.iterate();
|
|
325
|
+
|
|
326
|
+
await indices.stop();
|
|
327
|
+
|
|
328
|
+
await expectNotStarted(() => store.get(toId("closed")));
|
|
329
|
+
await expectNotStarted(() =>
|
|
330
|
+
store.put(
|
|
331
|
+
new Document({
|
|
332
|
+
id: "late",
|
|
333
|
+
name: "late",
|
|
334
|
+
number: 1n,
|
|
335
|
+
tags: ["late"],
|
|
336
|
+
}),
|
|
337
|
+
),
|
|
338
|
+
);
|
|
339
|
+
await expectNotStarted(() =>
|
|
340
|
+
store.del({
|
|
341
|
+
query: new StringMatch({
|
|
342
|
+
key: "id",
|
|
343
|
+
value: "closed",
|
|
344
|
+
method: StringMatchMethod.exact,
|
|
345
|
+
caseInsensitive: false,
|
|
346
|
+
}),
|
|
347
|
+
}),
|
|
348
|
+
);
|
|
349
|
+
await expectNotStarted(() => store.count());
|
|
350
|
+
await expectNotStarted(() => store.getSize());
|
|
351
|
+
await expectNotStarted(() => store.sum({ key: "number" }));
|
|
352
|
+
await expectNotStarted(() => store.iterate());
|
|
353
|
+
await expectNotStarted(() => openIterator.next(1));
|
|
354
|
+
await expectNotStarted(() => openIterator.pending());
|
|
355
|
+
await expectNotStarted(() => openIterator.all());
|
|
356
|
+
await openIterator.close();
|
|
357
|
+
});
|
|
358
|
+
});
|
|
359
|
+
|
|
300
360
|
describe("indexBy", () => {
|
|
301
361
|
const testIndex = async (
|
|
302
362
|
store: Index<any, any>,
|
|
@@ -367,12 +427,12 @@ export const tests = (
|
|
|
367
427
|
try {
|
|
368
428
|
await store.put(doc);
|
|
369
429
|
} catch (error) {
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
430
|
+
expect(error).to.haveOwnProperty(
|
|
431
|
+
"message",
|
|
432
|
+
"Unexpected index key: undefined, expected: string, number, bigint, Uint8Array or ArrayBufferView",
|
|
433
|
+
);
|
|
434
|
+
}
|
|
435
|
+
});
|
|
376
436
|
|
|
377
437
|
it("index by another property", async () => {
|
|
378
438
|
const { store } = await setup({
|