@fireproof/core-base 0.0.0-smoke-1b31059-1752074105

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.
Files changed (51) hide show
  1. package/LICENSE.md +232 -0
  2. package/apply-head-queue.d.ts +17 -0
  3. package/apply-head-queue.js +47 -0
  4. package/apply-head-queue.js.map +1 -0
  5. package/apply-head-queue.ts +72 -0
  6. package/bundle-not-impl.d.ts +1 -0
  7. package/bundle-not-impl.js +4 -0
  8. package/bundle-not-impl.js.map +1 -0
  9. package/bundle-not-impl.ts +4 -0
  10. package/crdt-clock.d.ts +25 -0
  11. package/crdt-clock.js +138 -0
  12. package/crdt-clock.js.map +1 -0
  13. package/crdt-clock.ts +192 -0
  14. package/crdt-helpers.d.ts +18 -0
  15. package/crdt-helpers.js +331 -0
  16. package/crdt-helpers.js.map +1 -0
  17. package/crdt-helpers.ts +484 -0
  18. package/crdt.d.ts +40 -0
  19. package/crdt.js +172 -0
  20. package/crdt.js.map +1 -0
  21. package/crdt.ts +268 -0
  22. package/database.d.ts +32 -0
  23. package/database.js +136 -0
  24. package/database.js.map +1 -0
  25. package/database.ts +200 -0
  26. package/index.d.ts +6 -0
  27. package/index.js +7 -0
  28. package/index.js.map +1 -0
  29. package/index.ts +9 -0
  30. package/indexer-helpers.d.ts +25 -0
  31. package/indexer-helpers.js +155 -0
  32. package/indexer-helpers.js.map +1 -0
  33. package/indexer-helpers.ts +263 -0
  34. package/indexer.d.ts +22 -0
  35. package/indexer.js +246 -0
  36. package/indexer.js.map +1 -0
  37. package/indexer.ts +360 -0
  38. package/ledger.d.ts +55 -0
  39. package/ledger.js +245 -0
  40. package/ledger.js.map +1 -0
  41. package/ledger.ts +344 -0
  42. package/package.json +54 -0
  43. package/tsconfig.json +18 -0
  44. package/version.d.ts +1 -0
  45. package/version.js +4 -0
  46. package/version.js.map +1 -0
  47. package/version.ts +3 -0
  48. package/write-queue.d.ts +4 -0
  49. package/write-queue.js +69 -0
  50. package/write-queue.js.map +1 -0
  51. package/write-queue.ts +93 -0
package/crdt-clock.ts ADDED
@@ -0,0 +1,192 @@
1
+ import { advance } from "@web3-storage/pail/clock";
2
+ import { root } from "@web3-storage/pail/crdt";
3
+ import { Logger } from "@adviser/cement";
4
+
5
+ import { clockChangesSince, toPailFetcher } from "./crdt-helpers.js";
6
+ import {
7
+ type DocUpdate,
8
+ type ClockHead,
9
+ type DocTypes,
10
+ type VoidFn,
11
+ type UnReg,
12
+ type SuperThis,
13
+ type BaseBlockstore,
14
+ type CarTransaction,
15
+ PARAM,
16
+ } from "@fireproof/core-types-base";
17
+ import { applyHeadQueue, ApplyHeadQueue } from "./apply-head-queue.js";
18
+ import { ensureLogger } from "@fireproof/core-runtime";
19
+ import { anyBlock2FPBlock } from "@fireproof/core-blockstore";
20
+
21
+ export class CRDTClockImpl {
22
+ // todo: track local and remote clocks independently, merge on read
23
+ // that way we can drop the whole remote if we need to
24
+ // should go with making sure the local clock only references locally available blockstore on write
25
+ readonly head: ClockHead = [];
26
+
27
+ readonly zoomers = new Map<string, VoidFn>();
28
+ readonly watchers = new Map<string, (updates: DocUpdate<DocTypes>[]) => void>();
29
+ readonly emptyWatchers = new Map<string, VoidFn>();
30
+
31
+ readonly blockstore: BaseBlockstore; // ready blockstore
32
+
33
+ readonly applyHeadQueue: ApplyHeadQueue<DocTypes>;
34
+ transaction?: CarTransaction;
35
+
36
+ async ready(): Promise<void> {
37
+ /* no-op */
38
+ }
39
+
40
+ async close() {
41
+ /* no-op */
42
+ }
43
+
44
+ readonly logger: Logger;
45
+ readonly sthis: SuperThis;
46
+ constructor(blockstore: BaseBlockstore) {
47
+ this.sthis = blockstore.sthis;
48
+ this.blockstore = blockstore;
49
+ this.logger = ensureLogger(blockstore.sthis, "CRDTClock");
50
+ this.applyHeadQueue = applyHeadQueue(this.int_applyHead.bind(this), this.logger);
51
+ }
52
+
53
+ setHead(head: ClockHead) {
54
+ // this.head = head;
55
+ this.head.splice(0, this.head.length, ...head);
56
+ }
57
+
58
+ async applyHead(newHead: ClockHead, prevHead: ClockHead, updates?: DocUpdate<DocTypes>[]): Promise<void> {
59
+ for await (const { updates: updatesAcc, all } of this.applyHeadQueue.push({
60
+ newHead,
61
+ prevHead,
62
+ updates,
63
+ })) {
64
+ return this.processUpdates(updatesAcc, all, prevHead);
65
+ }
66
+ }
67
+
68
+ async processUpdates(updatesAcc: DocUpdate<DocTypes>[], all: boolean, prevHead: ClockHead) {
69
+ let internalUpdates = updatesAcc;
70
+ if (this.watchers.size && !all) {
71
+ const changes = await clockChangesSince<DocTypes>(this.blockstore, this.head, prevHead, {}, this.logger);
72
+ internalUpdates = changes.result;
73
+ }
74
+ this.zoomers.forEach((fn) => fn());
75
+ this.notifyWatchers(internalUpdates || []);
76
+ }
77
+
78
+ notifyWatchers(updates: DocUpdate<DocTypes>[]) {
79
+ updates = updates.filter((update) => update.id !== PARAM.GENESIS_CID);
80
+ if (!updates.length) {
81
+ return;
82
+ }
83
+ this.emptyWatchers.forEach((fn) => fn());
84
+ this.watchers.forEach((fn) => fn(updates || []));
85
+ }
86
+
87
+ onTick(fn: (updates: DocUpdate<DocTypes>[]) => void): UnReg {
88
+ const key = this.sthis.timeOrderedNextId().str;
89
+ this.watchers.set(key, fn);
90
+ return () => {
91
+ this.watchers.delete(key);
92
+ };
93
+ }
94
+
95
+ onTock(fn: VoidFn): UnReg {
96
+ const key = this.sthis.timeOrderedNextId().str;
97
+ this.emptyWatchers.set(key, fn);
98
+ return () => {
99
+ this.emptyWatchers.delete(key);
100
+ };
101
+ }
102
+
103
+ onZoom(fn: VoidFn): UnReg {
104
+ const key = this.sthis.timeOrderedNextId().str;
105
+ this.zoomers.set(key, fn);
106
+ return () => {
107
+ this.zoomers.delete(key);
108
+ };
109
+ }
110
+
111
+ async int_applyHead(newHead: ClockHead, prevHead: ClockHead, localUpdates: boolean) {
112
+ // if (!(this.head && prevHead && newHead)) {
113
+ // throw new Error("missing head");
114
+ // }
115
+
116
+ const noLoader = !localUpdates;
117
+
118
+ // console.log("int_applyHead", this.applyHeadQueue.size(), this.head, newHead, prevHead, localUpdates);
119
+ const ogHead = sortClockHead(this.head);
120
+ newHead = sortClockHead(newHead);
121
+ if (compareClockHeads(ogHead, newHead)) {
122
+ return;
123
+ }
124
+ const ogPrev = sortClockHead(prevHead);
125
+ if (compareClockHeads(ogHead, ogPrev)) {
126
+ this.setHead(newHead);
127
+ return;
128
+ }
129
+
130
+ // const noLoader = this.head.length === 1 && !updates?.length
131
+ if (!this.blockstore) {
132
+ throw this.logger.Error().Msg("missing blockstore").AsError();
133
+ }
134
+ await validateBlocks(this.logger, newHead, this.blockstore);
135
+ if (!this.transaction) {
136
+ this.transaction = this.blockstore.openTransaction({ noLoader, add: false });
137
+ }
138
+ const tblocks = this.transaction;
139
+
140
+ const advancedHead = await advanceBlocks(this.logger, newHead, tblocks, this.head);
141
+ const result = await root(toPailFetcher(tblocks), advancedHead);
142
+
143
+ const fpBlocks = await Promise.all(result.additions.map(anyBlock2FPBlock));
144
+ for (const fp of fpBlocks) {
145
+ tblocks.putSync(fp);
146
+ }
147
+
148
+ // for (const block of [
149
+ // ...result.additions,
150
+ // // ...result.removals
151
+ // ]) {
152
+ // tblocks.putSync(await anyBlock2FPBlock(block));
153
+ // }
154
+ if (!noLoader) {
155
+ await this.blockstore.commitTransaction(tblocks, { head: advancedHead }, { add: false, noLoader });
156
+ this.transaction = undefined;
157
+ }
158
+ this.setHead(advancedHead);
159
+ }
160
+ }
161
+
162
+ // Helper functions
163
+ function sortClockHead(clockHead: ClockHead) {
164
+ return clockHead.sort((a, b) => a.toString().localeCompare(b.toString()));
165
+ }
166
+
167
+ async function validateBlocks(logger: Logger, newHead: ClockHead, blockstore?: BaseBlockstore) {
168
+ if (!blockstore) throw logger.Error().Msg("missing blockstore");
169
+ newHead.map(async (cid) => {
170
+ const got = await blockstore.get(cid);
171
+ if (!got) {
172
+ throw logger.Error().Str("cid", cid.toString()).Msg("int_applyHead missing block").AsError();
173
+ }
174
+ });
175
+ }
176
+
177
+ function compareClockHeads(head1: ClockHead, head2: ClockHead) {
178
+ return head1.toString() === head2.toString();
179
+ }
180
+
181
+ async function advanceBlocks(logger: Logger, newHead: ClockHead, tblocks: CarTransaction, head: ClockHead) {
182
+ for (const cid of newHead) {
183
+ try {
184
+ head = await advance(toPailFetcher(tblocks), head, cid);
185
+ } catch (e) {
186
+ logger.Error().Err(e).Msg("failed to advance head");
187
+ // console.log('failed to advance head:', cid.toString(), e)
188
+ // continue;
189
+ }
190
+ }
191
+ return head;
192
+ }
@@ -0,0 +1,18 @@
1
+ import { Block } from "multiformats/block";
2
+ import { BlockFetcher as PailBlockFetcher } from "@web3-storage/pail/crdt/api";
3
+ import { BlockFetcher, StoreRuntime, CompactFetcher } from "@fireproof/core-types-blockstore";
4
+ import { type DocUpdate, type ClockHead, type DocValue, type CRDTMeta, type ChangesOptions, type DocTypes, CarTransaction, BaseBlockstore } from "@fireproof/core-types-base";
5
+ import { Logger } from "@adviser/cement";
6
+ export declare function toPailFetcher(tblocks: BlockFetcher): PailBlockFetcher;
7
+ export declare function sanitizeDocumentFields<T>(obj: T): T;
8
+ export declare function applyBulkUpdateToCrdt<T extends DocTypes>(store: StoreRuntime, tblocks: CarTransaction, head: ClockHead, updates: DocUpdate<T>[], logger: Logger): Promise<CRDTMeta>;
9
+ export declare function getValueFromCrdt<T extends DocTypes>(blocks: BaseBlockstore, head: ClockHead, key: string, logger: Logger): Promise<DocValue<T>>;
10
+ export declare function readFiles<T extends DocTypes>(blocks: BaseBlockstore, { doc }: Partial<DocValue<T>>): void;
11
+ export declare function clockChangesSince<T extends DocTypes>(blocks: BlockFetcher, head: ClockHead, since: ClockHead, opts: ChangesOptions, logger: Logger): Promise<{
12
+ result: DocUpdate<T>[];
13
+ head: ClockHead;
14
+ }>;
15
+ export declare function getAllEntries<T extends DocTypes>(blocks: BlockFetcher, head: ClockHead, logger: Logger): AsyncGenerator<DocUpdate<T>, void, unknown>;
16
+ export declare function clockVis(blocks: BlockFetcher, head: ClockHead): AsyncGenerator<string, void, unknown>;
17
+ export declare function doCompact(blockLog: CompactFetcher, head: ClockHead, logger: Logger): Promise<void>;
18
+ export declare function getBlock(blocks: BlockFetcher, cidString: string): Promise<Block<unknown, 113, 18, 1>>;
@@ -0,0 +1,331 @@
1
+ import { asyncBlockDecode } from "@fireproof/core-runtime";
2
+ import { parse } from "multiformats/link";
3
+ import { Block } from "multiformats/block";
4
+ import { sha256 as hasher } from "multiformats/hashes/sha2";
5
+ import * as codec from "@ipld/dag-cbor";
6
+ import { put, get, entries, root } from "@web3-storage/pail/crdt";
7
+ import { EventFetcher, vis } from "@web3-storage/pail/clock";
8
+ import * as Batch from "@web3-storage/pail/crdt/batch";
9
+ import { CarTransactionImpl, anyBlock2FPBlock, doc2FPBlock, fileBlock2FPBlock, } from "@fireproof/core-blockstore";
10
+ import { throwFalsy, PARAM, NotFoundError, } from "@fireproof/core-types-base";
11
+ function time(tag) {
12
+ }
13
+ function timeEnd(tag) {
14
+ }
15
+ function toString(key, logger) {
16
+ switch (typeof key) {
17
+ case "string":
18
+ case "number":
19
+ return key.toString();
20
+ default:
21
+ throw logger.Error().Msg("Invalid key type").AsError();
22
+ }
23
+ }
24
+ export function toPailFetcher(tblocks) {
25
+ return {
26
+ get: async (link) => {
27
+ const block = await tblocks.get(link);
28
+ return block
29
+ ? {
30
+ cid: block.cid,
31
+ bytes: block.bytes,
32
+ }
33
+ : undefined;
34
+ },
35
+ };
36
+ }
37
+ export function sanitizeDocumentFields(obj) {
38
+ if (Array.isArray(obj)) {
39
+ return obj.map((item) => {
40
+ if (typeof item === "object" && item !== null) {
41
+ return sanitizeDocumentFields(item);
42
+ }
43
+ return item;
44
+ });
45
+ }
46
+ else if (typeof obj === "object" && obj !== null) {
47
+ if (obj instanceof Date) {
48
+ return obj.toISOString();
49
+ }
50
+ const typedObj = obj;
51
+ const result = {};
52
+ for (const key in typedObj) {
53
+ if (Object.hasOwnProperty.call(typedObj, key)) {
54
+ const value = typedObj[key];
55
+ if (value === null || (!Number.isNaN(value) && value !== undefined)) {
56
+ if (typeof value === "object" && !key.startsWith("_")) {
57
+ if (value instanceof Date) {
58
+ result[key] = value.toISOString();
59
+ }
60
+ else {
61
+ const sanitized = sanitizeDocumentFields(value);
62
+ result[key] = sanitized;
63
+ }
64
+ }
65
+ else {
66
+ result[key] = value;
67
+ }
68
+ }
69
+ }
70
+ }
71
+ return result;
72
+ }
73
+ return obj;
74
+ }
75
+ export async function applyBulkUpdateToCrdt(store, tblocks, head, updates, logger) {
76
+ let result = null;
77
+ if (updates.length > 1) {
78
+ const batch = await Batch.create(toPailFetcher(tblocks), head);
79
+ for (const update of updates) {
80
+ const link = await writeDocContent(store, tblocks, update, logger);
81
+ await batch.put(toString(update.id, logger), link);
82
+ }
83
+ result = await batch.commit();
84
+ }
85
+ else if (updates.length === 1) {
86
+ const link = await writeDocContent(store, tblocks, updates[0], logger);
87
+ result = await put(toPailFetcher(tblocks), head, toString(updates[0].id, logger), link);
88
+ }
89
+ if (!result)
90
+ throw logger.Error().Uint64("updates.len", updates.length).Msg("Missing result").AsError();
91
+ if (result.event) {
92
+ for (const block of [
93
+ ...result.additions,
94
+ result.event,
95
+ ]) {
96
+ tblocks.putSync(await anyBlock2FPBlock(block));
97
+ }
98
+ }
99
+ return { head: result.head };
100
+ }
101
+ async function writeDocContent(store, blocks, update, logger) {
102
+ let value;
103
+ if (update.del) {
104
+ value = { del: true };
105
+ }
106
+ else {
107
+ if (!update.value)
108
+ throw logger.Error().Msg("Missing value").AsError();
109
+ await processFiles(store, blocks, update.value, logger);
110
+ value = { doc: update.value };
111
+ }
112
+ const block = await doc2FPBlock(value);
113
+ blocks.putSync(block);
114
+ return block.cid;
115
+ }
116
+ async function processFiles(store, blocks, doc, logger) {
117
+ if (doc._files) {
118
+ await processFileset(logger, store, blocks, doc._files);
119
+ }
120
+ if (doc._publicFiles) {
121
+ await processFileset(logger, store, blocks, doc._publicFiles);
122
+ }
123
+ }
124
+ async function processFileset(logger, store, blocks, files) {
125
+ const dbBlockstore = blocks.parent;
126
+ if (!dbBlockstore.loader)
127
+ throw logger.Error().Msg("Missing loader, ledger name is required").AsError();
128
+ const t = new CarTransactionImpl(dbBlockstore);
129
+ const didPut = [];
130
+ for (const filename in files) {
131
+ if (File === files[filename].constructor) {
132
+ const file = files[filename];
133
+ const { cid, blocks: fileBlocks } = await store.encodeFile(file);
134
+ didPut.push(filename);
135
+ for (const block of fileBlocks) {
136
+ t.putSync(await fileBlock2FPBlock(block));
137
+ }
138
+ files[filename] = { cid, type: file.type, size: file.size, lastModified: file.lastModified };
139
+ }
140
+ else {
141
+ const { cid, type, size, car, lastModified } = files[filename];
142
+ if (cid && type && size && car) {
143
+ files[filename] = { cid, type, size, car, lastModified };
144
+ }
145
+ }
146
+ }
147
+ if (didPut.length) {
148
+ const car = await dbBlockstore.loader.commitFiles(t, { files });
149
+ if (car) {
150
+ for (const name of didPut) {
151
+ files[name] = { car, ...files[name] };
152
+ }
153
+ }
154
+ }
155
+ }
156
+ export async function getValueFromCrdt(blocks, head, key, logger) {
157
+ if (!head.length)
158
+ throw logger.Debug().Msg("Getting from an empty ledger").AsError();
159
+ const link = await get(toPailFetcher(blocks), head, key);
160
+ if (!link) {
161
+ throw new NotFoundError(`Not found: ${key}`);
162
+ }
163
+ const ret = await getValueFromLink(blocks, link, logger);
164
+ return ret;
165
+ }
166
+ export function readFiles(blocks, { doc }) {
167
+ if (!doc)
168
+ return;
169
+ if (doc._files) {
170
+ readFileset(blocks, doc._files);
171
+ }
172
+ if (doc._publicFiles) {
173
+ readFileset(blocks, doc._publicFiles, true);
174
+ }
175
+ }
176
+ function readFileset(blocks, files, isPublic = false) {
177
+ for (const filename in files) {
178
+ const fileMeta = files[filename];
179
+ if (fileMeta.cid) {
180
+ if (isPublic) {
181
+ fileMeta.url = `https://${fileMeta.cid.toString()}.ipfs.w3s.link/`;
182
+ }
183
+ if (fileMeta.car) {
184
+ fileMeta.file = async () => {
185
+ const result = await blocks.ebOpts.storeRuntime.decodeFile({
186
+ get: async (cid) => {
187
+ return await blocks.getFile(throwFalsy(fileMeta.car), cid);
188
+ },
189
+ }, fileMeta.cid, fileMeta);
190
+ if (result.isErr()) {
191
+ throw blocks.logger.Error().Any("error", result.Err()).Any("cid", fileMeta.cid).Msg("Error decoding file").AsError();
192
+ }
193
+ return result.unwrap();
194
+ };
195
+ }
196
+ }
197
+ files[filename] = fileMeta;
198
+ }
199
+ }
200
+ async function getValueFromLink(blocks, link, logger) {
201
+ const block = await blocks.get(link);
202
+ if (!block)
203
+ throw logger.Error().Str("link", link.toString()).Msg(`Missing linked block`).AsError();
204
+ const { value } = (await asyncBlockDecode({ bytes: block.bytes, hasher, codec }));
205
+ const cvalue = {
206
+ ...value,
207
+ cid: link,
208
+ };
209
+ readFiles(blocks, cvalue);
210
+ return cvalue;
211
+ }
212
+ class DirtyEventFetcher extends EventFetcher {
213
+ logger;
214
+ constructor(logger, blocks) {
215
+ super(toPailFetcher(blocks));
216
+ this.logger = logger;
217
+ }
218
+ async get(link) {
219
+ try {
220
+ return await super.get(link);
221
+ }
222
+ catch (e) {
223
+ this.logger.Error().Ref("link", link.toString()).Err(e).Msg("Missing event");
224
+ return { value: undefined };
225
+ }
226
+ }
227
+ }
228
+ export async function clockChangesSince(blocks, head, since, opts, logger) {
229
+ const eventsFetcher = (opts.dirty ? new DirtyEventFetcher(logger, blocks) : new EventFetcher(toPailFetcher(blocks)));
230
+ const keys = new Set();
231
+ const updates = await gatherUpdates(blocks, eventsFetcher, head, since, [], keys, new Set(), opts.limit || Infinity, logger);
232
+ return { result: updates.reverse(), head };
233
+ }
234
+ async function gatherUpdates(blocks, eventsFetcher, head, since, updates = [], keys, didLinks, limit, logger) {
235
+ if (limit <= 0)
236
+ return updates;
237
+ const sHead = head.map((l) => l.toString());
238
+ for (const link of since) {
239
+ if (sHead.includes(link.toString())) {
240
+ return updates;
241
+ }
242
+ }
243
+ for (const link of head) {
244
+ if (didLinks.has(link.toString()))
245
+ continue;
246
+ didLinks.add(link.toString());
247
+ const { value: event } = await eventsFetcher.get(link);
248
+ if (!event)
249
+ continue;
250
+ const { type } = event.data;
251
+ let ops = [];
252
+ if (type === "batch") {
253
+ ops = event.data.ops;
254
+ }
255
+ else if (type === "put") {
256
+ ops = [event.data];
257
+ }
258
+ for (let i = ops.length - 1; i >= 0; i--) {
259
+ const { key, value } = ops[i];
260
+ if (!keys.has(key)) {
261
+ const docValue = await getValueFromLink(blocks, value, logger);
262
+ if (key === PARAM.GENESIS_CID) {
263
+ continue;
264
+ }
265
+ updates.push({ id: key, value: docValue.doc, del: docValue.del, clock: link });
266
+ limit--;
267
+ keys.add(key);
268
+ }
269
+ }
270
+ if (event.parents) {
271
+ updates = await gatherUpdates(blocks, eventsFetcher, event.parents, since, updates, keys, didLinks, limit, logger);
272
+ }
273
+ }
274
+ return updates;
275
+ }
276
+ export async function* getAllEntries(blocks, head, logger) {
277
+ for await (const [key, link] of entries(toPailFetcher(blocks), head)) {
278
+ if (key !== PARAM.GENESIS_CID) {
279
+ const docValue = await getValueFromLink(blocks, link, logger);
280
+ yield { id: key, value: docValue.doc, del: docValue.del };
281
+ }
282
+ }
283
+ }
284
+ export async function* clockVis(blocks, head) {
285
+ for await (const line of vis(toPailFetcher(blocks), head)) {
286
+ yield line;
287
+ }
288
+ }
289
+ let isCompacting = false;
290
+ export async function doCompact(blockLog, head, logger) {
291
+ if (isCompacting) {
292
+ return;
293
+ }
294
+ isCompacting = true;
295
+ time("compact head");
296
+ for (const cid of head) {
297
+ const bl = await blockLog.get(cid);
298
+ if (!bl)
299
+ throw logger.Error().Ref("cid", cid).Msg("Missing head block").AsError();
300
+ }
301
+ timeEnd("compact head");
302
+ time("compact all entries");
303
+ for await (const _entry of getAllEntries(blockLog, head, logger)) {
304
+ }
305
+ timeEnd("compact all entries");
306
+ time("compact clock vis");
307
+ for await (const _line of vis(toPailFetcher(blockLog), head)) {
308
+ void 1;
309
+ }
310
+ timeEnd("compact clock vis");
311
+ time("compact root");
312
+ const result = await root(toPailFetcher(blockLog), head);
313
+ timeEnd("compact root");
314
+ time("compact root blocks");
315
+ for (const block of [...result.additions, ...result.removals]) {
316
+ blockLog.loggedBlocks.putSync(await anyBlock2FPBlock(block));
317
+ }
318
+ timeEnd("compact root blocks");
319
+ time("compact changes");
320
+ await clockChangesSince(blockLog, head, [], {}, logger);
321
+ timeEnd("compact changes");
322
+ isCompacting = false;
323
+ }
324
+ export async function getBlock(blocks, cidString) {
325
+ const block = await blocks.get(parse(cidString));
326
+ if (!block)
327
+ throw new Error(`Missing block ${cidString}`);
328
+ const { cid, value } = await asyncBlockDecode({ bytes: block.bytes, codec, hasher });
329
+ return new Block({ cid, value, bytes: block.bytes });
330
+ }
331
+ //# sourceMappingURL=crdt-helpers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"crdt-helpers.js","sourceRoot":"","sources":["crdt-helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAC1C,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,MAAM,IAAI,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,KAAK,KAAK,MAAM,gBAAgB,CAAC;AACxC,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAC;AASlE,OAAO,EAAE,YAAY,EAAE,GAAG,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,KAAK,KAAK,MAAM,+BAA+B,CAAC;AAEvD,OAAO,EAEL,kBAAkB,EAClB,gBAAgB,EAChB,WAAW,EACX,iBAAiB,GAClB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAYL,UAAU,EAGV,KAAK,EACL,aAAa,GACd,MAAM,4BAA4B,CAAC;AAKpC,SAAS,IAA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