@peerbit/document 10.0.4 → 10.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/dist/benchmark/index.js +114 -59
- package/dist/benchmark/index.js.map +1 -1
- package/dist/benchmark/iterate-replicate-2.js +117 -63
- package/dist/benchmark/iterate-replicate-2.js.map +1 -1
- package/dist/benchmark/iterate-replicate.js +106 -56
- package/dist/benchmark/iterate-replicate.js.map +1 -1
- package/dist/benchmark/memory/child.js +114 -59
- package/dist/benchmark/memory/child.js.map +1 -1
- package/dist/benchmark/replication.js +106 -52
- package/dist/benchmark/replication.js.map +1 -1
- package/dist/src/domain.d.ts.map +1 -1
- package/dist/src/domain.js +1 -3
- package/dist/src/domain.js.map +1 -1
- package/dist/src/events.d.ts +1 -1
- package/dist/src/events.d.ts.map +1 -1
- package/dist/src/index.d.ts +1 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/most-common-query-predictor.d.ts +3 -3
- package/dist/src/most-common-query-predictor.d.ts.map +1 -1
- package/dist/src/most-common-query-predictor.js.map +1 -1
- package/dist/src/operation.js +175 -81
- package/dist/src/operation.js.map +1 -1
- package/dist/src/prefetch.d.ts +2 -2
- package/dist/src/prefetch.d.ts.map +1 -1
- package/dist/src/prefetch.js.map +1 -1
- package/dist/src/program.d.ts +2 -2
- package/dist/src/program.d.ts.map +1 -1
- package/dist/src/program.js +550 -508
- package/dist/src/program.js.map +1 -1
- package/dist/src/resumable-iterator.d.ts.map +1 -1
- package/dist/src/resumable-iterator.js +44 -0
- package/dist/src/resumable-iterator.js.map +1 -1
- package/dist/src/search.d.ts +14 -10
- package/dist/src/search.d.ts.map +1 -1
- package/dist/src/search.js +2477 -2120
- package/dist/src/search.js.map +1 -1
- package/package.json +21 -19
- package/src/domain.ts +1 -3
- package/src/events.ts +1 -1
- package/src/index.ts +1 -0
- package/src/most-common-query-predictor.ts +19 -5
- package/src/prefetch.ts +12 -3
- package/src/program.ts +7 -5
- package/src/resumable-iterator.ts +44 -0
- package/src/search.ts +564 -196
package/src/program.ts
CHANGED
|
@@ -50,7 +50,8 @@ import {
|
|
|
50
50
|
coerceWithIndexed,
|
|
51
51
|
} from "./search.js";
|
|
52
52
|
|
|
53
|
-
const logger
|
|
53
|
+
const logger = loggerFn("peerbit:program:document");
|
|
54
|
+
const warn = logger.newScope("warn");
|
|
54
55
|
|
|
55
56
|
export class OperationError extends Error {
|
|
56
57
|
constructor(message?: string) {
|
|
@@ -67,13 +68,13 @@ type CanPerformPut<T> = {
|
|
|
67
68
|
entry: Entry<PutOperation>;
|
|
68
69
|
};
|
|
69
70
|
|
|
70
|
-
type CanPerformDelete
|
|
71
|
+
type CanPerformDelete = {
|
|
71
72
|
type: "delete";
|
|
72
73
|
operation: DeleteOperation;
|
|
73
74
|
entry: Entry<DeleteOperation>;
|
|
74
75
|
};
|
|
75
76
|
|
|
76
|
-
export type CanPerformOperations<T> = CanPerformPut<T> | CanPerformDelete
|
|
77
|
+
export type CanPerformOperations<T> = CanPerformPut<T> | CanPerformDelete;
|
|
77
78
|
export type CanPerform<T> = (
|
|
78
79
|
properties: CanPerformOperations<T>,
|
|
79
80
|
) => MaybePromise<boolean>;
|
|
@@ -367,7 +368,7 @@ export class Documents<
|
|
|
367
368
|
}
|
|
368
369
|
} catch (error) {
|
|
369
370
|
if (error instanceof BorshError) {
|
|
370
|
-
|
|
371
|
+
warn("Received payload that could not be decoded, skipping");
|
|
371
372
|
return false;
|
|
372
373
|
}
|
|
373
374
|
throw error;
|
|
@@ -512,7 +513,7 @@ export class Documents<
|
|
|
512
513
|
if (error instanceof AccessError) {
|
|
513
514
|
return false; // we cant index because we can not decrypt
|
|
514
515
|
} else if (error instanceof BorshError) {
|
|
515
|
-
|
|
516
|
+
warn("Received payload that could not be decoded, skipping");
|
|
516
517
|
return false;
|
|
517
518
|
}
|
|
518
519
|
throw error;
|
|
@@ -632,6 +633,7 @@ export class Documents<
|
|
|
632
633
|
change: Change<Operation>,
|
|
633
634
|
reference?: { document: T; operation: PutOperation; unique?: boolean },
|
|
634
635
|
): Promise<void> {
|
|
636
|
+
logger.trace("handleChanges called", change);
|
|
635
637
|
const isAppendOperation =
|
|
636
638
|
change?.added.length === 1 ? !!change.added[0] : false;
|
|
637
639
|
const removedSet = new Map<string, ShallowOrFullEntry<Operation>>();
|
|
@@ -6,6 +6,9 @@ import {
|
|
|
6
6
|
type SearchRequestIndexed,
|
|
7
7
|
} from "@peerbit/document-interface";
|
|
8
8
|
import type * as indexerTypes from "@peerbit/indexer-interface";
|
|
9
|
+
import { logger as loggerFn } from "@peerbit/logger";
|
|
10
|
+
|
|
11
|
+
const iteratorLogger = loggerFn("peerbit:document:index:iterate");
|
|
9
12
|
|
|
10
13
|
export class ResumableIterators<T extends Record<string, any>> {
|
|
11
14
|
constructor(
|
|
@@ -23,6 +26,11 @@ export class ResumableIterators<T extends Record<string, any>> {
|
|
|
23
26
|
request: SearchRequest | SearchRequestIndexed | IterationRequest,
|
|
24
27
|
options?: { keepAlive?: boolean },
|
|
25
28
|
) {
|
|
29
|
+
iteratorLogger("iterate:start", {
|
|
30
|
+
id: request.idString,
|
|
31
|
+
fetch: request.fetch,
|
|
32
|
+
keepAlive: Boolean(options?.keepAlive),
|
|
33
|
+
});
|
|
26
34
|
const iterator = this.index.iterate(request);
|
|
27
35
|
const firstResult = await iterator.next(request.fetch);
|
|
28
36
|
const keepAlive = options?.keepAlive === true;
|
|
@@ -34,6 +42,12 @@ export class ResumableIterators<T extends Record<string, any>> {
|
|
|
34
42
|
};
|
|
35
43
|
this.queues.add(request.idString, cachedIterator);
|
|
36
44
|
}
|
|
45
|
+
iteratorLogger("iterate:queued", {
|
|
46
|
+
id: request.idString,
|
|
47
|
+
keepAlive,
|
|
48
|
+
done: iterator.done() === true,
|
|
49
|
+
batch: firstResult.length,
|
|
50
|
+
});
|
|
37
51
|
/* console.debug(
|
|
38
52
|
"[ResumableIterators] iterateAndFetch",
|
|
39
53
|
request.idString,
|
|
@@ -52,6 +66,9 @@ export class ResumableIterators<T extends Record<string, any>> {
|
|
|
52
66
|
) {
|
|
53
67
|
const iterator = this.queues.get(request.idString);
|
|
54
68
|
if (!iterator) {
|
|
69
|
+
iteratorLogger.error("Iterator missing", {
|
|
70
|
+
id: request.idString,
|
|
71
|
+
});
|
|
55
72
|
throw new Error(
|
|
56
73
|
"Missing iterator for request with id: " + request.idString,
|
|
57
74
|
);
|
|
@@ -67,6 +84,20 @@ export class ResumableIterators<T extends Record<string, any>> {
|
|
|
67
84
|
? request.amount
|
|
68
85
|
: iterator.request.fetch;
|
|
69
86
|
const next = await iterator.iterator.next(fetchAmount);
|
|
87
|
+
let pending: number | undefined;
|
|
88
|
+
try {
|
|
89
|
+
pending = await iterator.iterator.pending();
|
|
90
|
+
} catch {
|
|
91
|
+
pending = undefined;
|
|
92
|
+
}
|
|
93
|
+
iteratorLogger("iterate:next", {
|
|
94
|
+
id: request.idString,
|
|
95
|
+
fetch: fetchAmount,
|
|
96
|
+
keepAlive: iterator.keepAlive,
|
|
97
|
+
resultLength: next.length,
|
|
98
|
+
pending,
|
|
99
|
+
done: iterator.iterator.done?.(),
|
|
100
|
+
});
|
|
70
101
|
/* console.debug(
|
|
71
102
|
"[ResumableIterators] next",
|
|
72
103
|
request.idString,
|
|
@@ -80,10 +111,16 @@ export class ResumableIterators<T extends Record<string, any>> {
|
|
|
80
111
|
}
|
|
81
112
|
|
|
82
113
|
close(close: { idString: string }) {
|
|
114
|
+
iteratorLogger("iterate:close", {
|
|
115
|
+
id: close.idString,
|
|
116
|
+
});
|
|
83
117
|
this.clear(close.idString);
|
|
84
118
|
}
|
|
85
119
|
|
|
86
120
|
private clear(id: string) {
|
|
121
|
+
iteratorLogger("iterate:clear", {
|
|
122
|
+
id,
|
|
123
|
+
});
|
|
87
124
|
this.queues.del(id);
|
|
88
125
|
}
|
|
89
126
|
|
|
@@ -97,9 +134,16 @@ export class ResumableIterators<T extends Record<string, any>> {
|
|
|
97
134
|
return undefined;
|
|
98
135
|
}
|
|
99
136
|
const pending = await iterator.iterator.pending();
|
|
137
|
+
// debug
|
|
138
|
+
// console.error("[resumable:getPending]", { id, pending, keepAlive: iterator.keepAlive });
|
|
100
139
|
if (pending === 0 && iterator.iterator.done() && !iterator.keepAlive) {
|
|
101
140
|
this.clear(id);
|
|
102
141
|
}
|
|
142
|
+
iteratorLogger("iterate:pending", {
|
|
143
|
+
id,
|
|
144
|
+
pending,
|
|
145
|
+
keepAlive: iterator.keepAlive,
|
|
146
|
+
});
|
|
103
147
|
return pending;
|
|
104
148
|
}
|
|
105
149
|
}
|