@peerbit/log 6.0.34 → 6.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/native-graph.d.ts +2 -0
- package/dist/benchmark/native-graph.d.ts.map +1 -0
- package/dist/benchmark/native-graph.js +74 -0
- package/dist/benchmark/native-graph.js.map +1 -0
- package/dist/src/entry-index.d.ts +34 -0
- package/dist/src/entry-index.d.ts.map +1 -1
- package/dist/src/entry-index.js +169 -26
- package/dist/src/entry-index.js.map +1 -1
- package/dist/src/log.d.ts +3 -0
- package/dist/src/log.d.ts.map +1 -1
- package/dist/src/log.js +25 -8
- package/dist/src/log.js.map +1 -1
- package/package.json +12 -11
- package/src/entry-index.ts +270 -37
- package/src/log.ts +35 -9
package/src/log.ts
CHANGED
|
@@ -25,6 +25,7 @@ import { type Encoding, NO_ENCODING } from "./encoding.js";
|
|
|
25
25
|
import {
|
|
26
26
|
EntryIndex,
|
|
27
27
|
type MaybeResolveOptions,
|
|
28
|
+
type NativeLogGraph,
|
|
28
29
|
type ResultsIterator,
|
|
29
30
|
type ReturnTypeFromResolveOptions,
|
|
30
31
|
} from "./entry-index.js";
|
|
@@ -93,6 +94,7 @@ export type LogProperties<T> = {
|
|
|
93
94
|
encoding?: Encoding<T>;
|
|
94
95
|
clock?: LamportClock;
|
|
95
96
|
appendDurability?: AppendDurability;
|
|
97
|
+
nativeGraph?: boolean | { heads?: boolean };
|
|
96
98
|
sortFn?: Sorting.SortFn;
|
|
97
99
|
trim?: TrimOptions;
|
|
98
100
|
canAppend?: CanAppend<T>;
|
|
@@ -243,10 +245,36 @@ export class Log<T> {
|
|
|
243
245
|
throw new Error("Id not set");
|
|
244
246
|
}
|
|
245
247
|
|
|
248
|
+
const nativeGraph =
|
|
249
|
+
options.nativeGraph &&
|
|
250
|
+
(await (async () => {
|
|
251
|
+
let createLogGraphIndex: () => Promise<NativeLogGraph>;
|
|
252
|
+
try {
|
|
253
|
+
({ createLogGraphIndex } = (await import(
|
|
254
|
+
["@peerbit", "log-rust"].join("/")
|
|
255
|
+
)) as {
|
|
256
|
+
createLogGraphIndex: () => Promise<NativeLogGraph>;
|
|
257
|
+
});
|
|
258
|
+
} catch {
|
|
259
|
+
throw new Error(
|
|
260
|
+
"Log nativeGraph requires @peerbit/log-rust to be installed and built",
|
|
261
|
+
);
|
|
262
|
+
}
|
|
263
|
+
const headsRequested =
|
|
264
|
+
typeof options.nativeGraph === "object"
|
|
265
|
+
? options.nativeGraph.heads !== false
|
|
266
|
+
: true;
|
|
267
|
+
return {
|
|
268
|
+
graph: await createLogGraphIndex(),
|
|
269
|
+
useHeads: headsRequested && this._sortFn === LastWriteWins,
|
|
270
|
+
};
|
|
271
|
+
})());
|
|
272
|
+
|
|
246
273
|
this._entryIndex = new EntryIndex({
|
|
247
274
|
store: this._storage,
|
|
248
275
|
init: (e) => e.init(this),
|
|
249
276
|
onGidRemoved,
|
|
277
|
+
nativeGraph: nativeGraph || undefined,
|
|
250
278
|
index: await (
|
|
251
279
|
await this._indexer.scope("heads")
|
|
252
280
|
).init({ schema: ShallowEntry }),
|
|
@@ -1019,16 +1047,14 @@ export class Log<T> {
|
|
|
1019
1047
|
skipFirst = false,
|
|
1020
1048
|
) {
|
|
1021
1049
|
const toDelete = await this.prepareDeleteRecursively(from, skipFirst);
|
|
1022
|
-
const
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1050
|
+
const removedEntries: ShallowEntry[] = [];
|
|
1051
|
+
for (const x of toDelete) {
|
|
1052
|
+
const removedEntry = await x.fn();
|
|
1053
|
+
if (removedEntry) {
|
|
1054
|
+
removedEntries.push(removedEntry);
|
|
1026
1055
|
}
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
const results = Promise.all(promises);
|
|
1031
|
-
return (await results).filter((x) => x) as ShallowEntry[];
|
|
1056
|
+
}
|
|
1057
|
+
return removedEntries;
|
|
1032
1058
|
}
|
|
1033
1059
|
|
|
1034
1060
|
/// TODO simplify methods below
|