@fireproof/core 0.17.1 → 0.17.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. package/README.md +2 -2
  2. package/dist/browser/fireproof.cjs +2 -5
  3. package/dist/browser/fireproof.cjs.map +1 -1
  4. package/dist/browser/fireproof.d.cts +21 -24
  5. package/dist/browser/fireproof.d.ts +21 -24
  6. package/dist/browser/fireproof.global.js +140 -92
  7. package/dist/browser/fireproof.global.js.map +1 -1
  8. package/dist/browser/fireproof.js +2 -5
  9. package/dist/browser/fireproof.js.map +1 -1
  10. package/dist/browser/metafile-cjs.json +1 -1
  11. package/dist/browser/metafile-esm.json +1 -1
  12. package/dist/browser/metafile-iife.json +1 -1
  13. package/dist/memory/fireproof.cjs +2 -5
  14. package/dist/memory/fireproof.cjs.map +1 -1
  15. package/dist/memory/fireproof.d.cts +21 -24
  16. package/dist/memory/fireproof.d.ts +21 -24
  17. package/dist/memory/fireproof.global.js +140 -92
  18. package/dist/memory/fireproof.global.js.map +1 -1
  19. package/dist/memory/fireproof.js +2 -5
  20. package/dist/memory/fireproof.js.map +1 -1
  21. package/dist/memory/metafile-cjs.json +1 -1
  22. package/dist/memory/metafile-esm.json +1 -1
  23. package/dist/memory/metafile-iife.json +1 -1
  24. package/dist/node/fireproof.cjs +2 -5
  25. package/dist/node/fireproof.cjs.map +1 -1
  26. package/dist/node/fireproof.d.cts +21 -24
  27. package/dist/node/fireproof.d.ts +21 -24
  28. package/dist/node/fireproof.global.js +140 -92
  29. package/dist/node/fireproof.global.js.map +1 -1
  30. package/dist/node/fireproof.js +2 -5
  31. package/dist/node/fireproof.js.map +1 -1
  32. package/dist/node/metafile-cjs.json +1 -1
  33. package/dist/node/metafile-esm.json +1 -1
  34. package/dist/node/metafile-iife.json +1 -1
  35. package/package.json +4 -4
@@ -17,13 +17,16 @@ type ClockHead = ClockLink[];
17
17
  type DocFragment = Uint8Array | string | number | boolean | null | AnyLink | DocFragment[] | {
18
18
  [key: string]: DocFragment;
19
19
  };
20
- type DocRecord = Record<string, DocFragment>;
21
- type Doc<T extends DocRecord = {}> = DocBase & DocBody<T>;
20
+ type DocRecord<T> = {
21
+ [K in keyof T]: DocFragment;
22
+ };
23
+ type DocFiles = Record<string, DocFileMeta | File>;
22
24
  type DocBase = {
23
25
  _id?: string;
24
26
  _files?: DocFiles;
25
27
  _publicFiles?: DocFiles;
26
28
  };
29
+ type Doc<T extends DocRecord<T> = {}> = DocBase & T;
27
30
  type DocFileMeta = {
28
31
  type: string;
29
32
  size: number;
@@ -32,12 +35,6 @@ type DocFileMeta = {
32
35
  url?: string;
33
36
  file?: () => Promise<File>;
34
37
  };
35
- type DocFiles = Record<string, DocFileMeta | File>;
36
- type DocBody<T extends DocRecord = {}> = {
37
- _id?: string;
38
- } & {
39
- [K in Exclude<keyof T, keyof DocBase>]: DocFragment;
40
- } & T;
41
38
  type DocUpdate = {
42
39
  key: string;
43
40
  value?: Record<string, any>;
@@ -54,7 +51,7 @@ type IndexUpdate = {
54
51
  value?: DocFragment;
55
52
  del?: boolean;
56
53
  };
57
- type IndexRow<T extends DocRecord = {}> = {
54
+ type IndexRow<T extends DocRecord<T> = {}> = {
58
55
  id: string;
59
56
  key: IndexKey;
60
57
  row?: DocFragment;
@@ -95,12 +92,12 @@ type AnyDecodedBlock = {
95
92
  value: any;
96
93
  };
97
94
  type EmitFn = (k: DocFragment, v?: DocFragment) => void;
98
- type MapFn = <T extends DocRecord = {}>(doc: Doc<T>, emit: EmitFn) => DocFragment | void;
95
+ type MapFn = <T extends DocRecord<T> = {}>(doc: Doc<T>, emit: EmitFn) => DocFragment | void;
99
96
  type ChangesOptions = {
100
97
  dirty?: boolean;
101
98
  limit?: number;
102
99
  };
103
- type ChangesResponse<T extends DocRecord = {}> = {
100
+ type ChangesResponse<T extends DocRecord<T> = {}> = {
104
101
  clock: ClockHead;
105
102
  rows: {
106
103
  key: string;
@@ -121,7 +118,7 @@ declare class IndexTree {
121
118
  root: ProllyNode | null;
122
119
  }
123
120
  interface ProllyNode extends ProllyNode$1 {
124
- getAllEntries<T extends DocRecord = {}>(): PromiseLike<{
121
+ getAllEntries<T extends DocRecord<T> = {}>(): PromiseLike<{
125
122
  [x: string]: any;
126
123
  result: IndexRow<T>[];
127
124
  }>;
@@ -129,10 +126,10 @@ interface ProllyNode extends ProllyNode$1 {
129
126
  [x: string]: any;
130
127
  result: IndexKey[];
131
128
  }>;
132
- range<T extends DocRecord = {}>(a: IndexKey, b: IndexKey): Promise<{
129
+ range<T extends DocRecord<T> = {}>(a: IndexKey, b: IndexKey): Promise<{
133
130
  result: IndexRow<T>[];
134
131
  }>;
135
- get<T extends DocRecord = {}>(key: string): Promise<{
132
+ get<T extends DocRecord<T> = {}>(key: string): Promise<{
136
133
  result: IndexRow<T>[];
137
134
  }>;
138
135
  bulk(bulk: IndexUpdate[]): PromiseLike<{
@@ -159,8 +156,8 @@ declare class Index {
159
156
  initError: Error | null;
160
157
  ready: Promise<void>;
161
158
  constructor(crdt: CRDT, name: string, mapFn?: MapFn, meta?: IdxMeta);
162
- applyMapFn<T extends Record<string, any> = {}>(name: string, mapFn?: MapFn, meta?: IdxMeta): void;
163
- query<T extends DocRecord = {}>(opts?: QueryOpts): Promise<{
159
+ applyMapFn<T extends DocRecord<T> = {}>(name: string, mapFn?: MapFn, meta?: IdxMeta): void;
160
+ query<T extends DocRecord<T> = {}>(opts?: QueryOpts): Promise<{
164
161
  rows: IndexRow<T>[];
165
162
  }>;
166
163
  _resetIndex(): void;
@@ -263,18 +260,18 @@ declare class Database {
263
260
  _writeQueue: WriteQueue;
264
261
  blockstore: EncryptedBlockstore;
265
262
  constructor(name?: string, opts?: ConfigOpts);
266
- get<T extends DocRecord = {}>(id: string): Promise<Doc<T>>;
267
- put<T extends DocRecord = {}>(doc: Doc<T>): Promise<DbResponse>;
263
+ get<T extends DocRecord<T> = {}>(id: string): Promise<Doc<T>>;
264
+ put<T extends DocRecord<T> = {}>(doc: Doc<T>): Promise<DbResponse>;
268
265
  del(id: string): Promise<DbResponse>;
269
- changes<T extends DocRecord = {}>(since?: ClockHead, opts?: ChangesOptions): Promise<ChangesResponse<T>>;
270
- allDocs<T extends DocRecord = {}>(): Promise<{
266
+ changes<T extends DocRecord<T> = {}>(since?: ClockHead, opts?: ChangesOptions): Promise<ChangesResponse<T>>;
267
+ allDocs<T extends DocRecord<T> = {}>(): Promise<{
271
268
  rows: {
272
269
  key: string;
273
270
  value: Doc<T>;
274
271
  }[];
275
272
  clock: ClockHead;
276
273
  }>;
277
- allDocuments<T extends DocRecord = {}>(): Promise<{
274
+ allDocuments<T extends DocRecord<T> = {}>(): Promise<{
278
275
  rows: {
279
276
  key: string;
280
277
  value: Doc<T>;
@@ -282,17 +279,17 @@ declare class Database {
282
279
  clock: ClockHead;
283
280
  }>;
284
281
  subscribe(listener: ListenerFn | NoUpdateListenerFn, updates?: boolean): () => void;
285
- query<T extends DocRecord = {}>(field: string | MapFn, opts?: QueryOpts): Promise<{
282
+ query<T extends DocRecord<T> = {}>(field: string | MapFn, opts?: QueryOpts): Promise<{
286
283
  rows: IndexRow<T>[];
287
284
  }>;
288
285
  compact(): Promise<void>;
289
286
  _notify(updates: DocUpdate[]): Promise<void>;
290
287
  _no_update_notify(): Promise<void>;
291
288
  }
292
- type UpdateListenerFn = <T extends DocRecord = {}>(docs: Doc<T>[]) => Promise<void> | void;
289
+ type UpdateListenerFn = <T extends DocRecord<T>>(docs: Doc<T>[]) => Promise<void> | void;
293
290
  type NoUpdateListenerFn = () => Promise<void> | void;
294
291
  type ListenerFn = UpdateListenerFn | NoUpdateListenerFn;
295
292
  declare function fireproof(name: string, opts?: ConfigOpts): Database;
296
293
 
297
- export { type AnyBlock, type AnyDecodedBlock, type AnyLink, type CRDTMeta, type ChangesOptions, type ChangesResponse, type ClockHead, type ClockLink, type ConfigOpts, Database, type DbResponse, type Doc, type DocBase, type DocBody, type DocFileMeta, type DocFiles, type DocFragment, type DocRecord, type DocUpdate, type DocValue, type IdxMeta, type IdxMetaMap, type IndexKey, type IndexRow, type IndexUpdate, type MapFn, type QueryOpts, fireproof };
294
+ export { type AnyBlock, type AnyDecodedBlock, type AnyLink, type CRDTMeta, type ChangesOptions, type ChangesResponse, type ClockHead, type ClockLink, type ConfigOpts, Database, type DbResponse, type Doc, type DocBase, type DocFileMeta, type DocFiles, type DocFragment, type DocRecord, type DocUpdate, type DocValue, type IdxMeta, type IdxMetaMap, type IndexKey, type IndexRow, type IndexUpdate, type MapFn, type QueryOpts, fireproof };
298
295
  declare module '@fireproof/core'
@@ -4136,22 +4136,6 @@ var Fireproof = (() => {
4136
4136
  }
4137
4137
  }
4138
4138
  };
4139
- var MultiBlockFetcher = class {
4140
- /** @type {API.BlockFetcher[]} */
4141
- #fetchers;
4142
- /** @param {API.BlockFetcher[]} fetchers */
4143
- constructor(...fetchers) {
4144
- this.#fetchers = fetchers;
4145
- }
4146
- /** @type {API.BlockFetcher['get']} */
4147
- async get(link2) {
4148
- for (const f of this.#fetchers) {
4149
- const v = await f.get(link2);
4150
- if (v)
4151
- return v;
4152
- }
4153
- }
4154
- };
4155
4139
 
4156
4140
  // ../../node_modules/.pnpm/yocto-queue@1.0.0/node_modules/yocto-queue/index.js
4157
4141
  var Node = class {
@@ -10218,8 +10202,7 @@ You can use close({ resize: true }) to resize header`);
10218
10202
  }
10219
10203
  async _commitInternal(t, done, opts = { noLoader: false, compact: false }) {
10220
10204
  await this.ready;
10221
- const header = done;
10222
- const fp = this.makeCarHeader(header, this.carLog, !!opts.compact);
10205
+ const fp = this.makeCarHeader(done, this.carLog, !!opts.compact);
10223
10206
  let roots = await this.prepareRoots(fp, t);
10224
10207
  const { cid, bytes } = await this.prepareCarFile(roots[0], t, !!opts.public);
10225
10208
  await this.carStore.save({ cid, bytes });
@@ -10250,10 +10233,9 @@ You can use close({ resize: true }) to resize header`);
10250
10233
  }
10251
10234
  async updateCarLog(cid, fp, compact) {
10252
10235
  if (compact) {
10253
- const fpCar = fp;
10254
- const previousCompactCid = this.carLog[this.carLog.length - 1];
10255
- fpCar.compact.map((c) => c.toString()).forEach(this.seenCompacted.add, this.seenCompacted);
10256
- this.carLog = [...uniqueCids([cid, ...this.carLog], this.seenCompacted)];
10236
+ const previousCompactCid = fp.compact[fp.compact.length - 1];
10237
+ fp.compact.map((c) => c.toString()).forEach(this.seenCompacted.add, this.seenCompacted);
10238
+ this.carLog = [...uniqueCids([...this.carLog, ...fp.cars, cid], this.seenCompacted)];
10257
10239
  void this.removeCidsForCompact(previousCompactCid);
10258
10240
  } else {
10259
10241
  this.carLog.unshift(cid);
@@ -10267,13 +10249,14 @@ You can use close({ resize: true }) to resize header`);
10267
10249
  await this.carStore.remove(cid2);
10268
10250
  }
10269
10251
  }
10270
- async flushCars() {
10271
- await this.ready;
10272
- for (const cid of this.carLog) {
10273
- const dbMeta = { car: cid, key: this.key || null };
10274
- await this.remoteWAL.enqueue(dbMeta, { public: false });
10275
- }
10276
- }
10252
+ // async flushCars() {
10253
+ // await this.ready
10254
+ // // for each cid in car log, make a dbMeta
10255
+ // for (const cid of this.carLog) {
10256
+ // const dbMeta = { car: cid, key: this.key || null } as DbMeta
10257
+ // await this.remoteWAL!.enqueue(dbMeta, { public: false })
10258
+ // }
10259
+ // }
10277
10260
  async *entries() {
10278
10261
  await this.ready;
10279
10262
  for (const [, block] of this.getBlockCache) {
@@ -19035,7 +19018,7 @@ ${key.data.toString("base64")}
19035
19018
  return await (0, import_promises.writeFile)(path, data);
19036
19019
  }
19037
19020
 
19038
- // ../../node_modules/.pnpm/@web3-storage+pail@0.4.0/node_modules/@web3-storage/pail/src/clock/index.js
19021
+ // ../../node_modules/.pnpm/@web3-storage+pail@0.4.1/node_modules/@web3-storage/pail/src/clock/index.js
19039
19022
  var advance = async (blocks, head, event) => {
19040
19023
  const events = new EventFetcher(blocks);
19041
19024
  const headmap = new Map(head.map((cid) => [cid.toString(), cid]));
@@ -19109,7 +19092,6 @@ ${key.data.toString("base64")}
19109
19092
  return true;
19110
19093
  const [{ value: aevent }, { value: bevent }] = await Promise.all([events.get(a), events.get(b)]);
19111
19094
  const links3 = [...aevent.parents];
19112
- const seen = /* @__PURE__ */ new Set();
19113
19095
  while (links3.length) {
19114
19096
  const link2 = links3.shift();
19115
19097
  if (!link2)
@@ -19118,9 +19100,6 @@ ${key.data.toString("base64")}
19118
19100
  return true;
19119
19101
  if (bevent.parents.some((p) => link2.toString() === p.toString()))
19120
19102
  continue;
19121
- if (seen.has(link2.toString()))
19122
- continue;
19123
- seen.add(link2.toString());
19124
19103
  const { value: event } = await events.get(link2);
19125
19104
  links3.push(...event.parents);
19126
19105
  }
@@ -19161,7 +19140,7 @@ ${key.data.toString("base64")}
19161
19140
  };
19162
19141
  var shortLink = (l) => `${String(l).slice(0, 4)}..${String(l).slice(-4)}`;
19163
19142
 
19164
- // ../../node_modules/.pnpm/@web3-storage+pail@0.4.0/node_modules/@web3-storage/pail/src/shard.js
19143
+ // ../../node_modules/.pnpm/@web3-storage+pail@0.4.1/node_modules/@web3-storage/pail/src/shard.js
19165
19144
  var MaxKeyLength = 64;
19166
19145
  var MaxShardSize = 512 * 1024;
19167
19146
  var CID_TAG2 = new Token(Type.tag, 42);
@@ -19292,41 +19271,8 @@ ${key.data.toString("base64")}
19292
19271
  }
19293
19272
  }
19294
19273
  };
19295
- var encodedLength = (shard) => {
19296
- let entriesLength = 0;
19297
- for (const entry of shard.entries) {
19298
- entriesLength += entryEncodedLength(entry);
19299
- }
19300
- const tokens = [
19301
- new Token(Type.map, 3),
19302
- new Token(Type.string, "entries"),
19303
- new Token(Type.array, shard.entries.length),
19304
- new Token(Type.string, "maxKeyLength"),
19305
- new Token(Type.uint, shard.maxKeyLength),
19306
- new Token(Type.string, "maxSize"),
19307
- new Token(Type.uint, shard.maxSize)
19308
- ];
19309
- return tokensToLength(tokens) + entriesLength;
19310
- };
19311
- var entryEncodedLength = (entry) => {
19312
- const tokens = [
19313
- new Token(Type.array, entry.length),
19314
- new Token(Type.string, entry[0])
19315
- ];
19316
- if (Array.isArray(entry[1])) {
19317
- tokens.push(new Token(Type.array, entry[1].length));
19318
- for (const link2 of entry[1]) {
19319
- tokens.push(CID_TAG2);
19320
- tokens.push(new Token(Type.bytes, { length: link2.byteLength + 1 }));
19321
- }
19322
- } else {
19323
- tokens.push(CID_TAG2);
19324
- tokens.push(new Token(Type.bytes, { length: entry[1].byteLength + 1 }));
19325
- }
19326
- return tokensToLength(tokens);
19327
- };
19328
19274
 
19329
- // ../../node_modules/.pnpm/@web3-storage+pail@0.4.0/node_modules/@web3-storage/pail/src/index.js
19275
+ // ../../node_modules/.pnpm/@web3-storage+pail@0.4.1/node_modules/@web3-storage/pail/src/index.js
19330
19276
  var put = async (blocks, root2, key, value) => {
19331
19277
  const shards = new ShardFetcher(blocks);
19332
19278
  const rshard = await shards.get(root2);
@@ -19529,15 +19475,118 @@ ${key.data.toString("base64")}
19529
19475
  return [shard];
19530
19476
  };
19531
19477
 
19532
- // ../../node_modules/.pnpm/@web3-storage+pail@0.4.0/node_modules/@web3-storage/pail/src/batch/shard.js
19478
+ // ../../node_modules/.pnpm/@web3-storage+pail@0.4.1/node_modules/@web3-storage/pail/src/block.js
19479
+ var MemoryBlockstore2 = class {
19480
+ /** @type {Map<string, Uint8Array>} */
19481
+ #blocks = /* @__PURE__ */ new Map();
19482
+ /**
19483
+ * @param {Array<import('multiformats').Block>} [blocks]
19484
+ */
19485
+ constructor(blocks) {
19486
+ if (blocks) {
19487
+ this.#blocks = new Map(blocks.map((b) => [b.cid.toString(), b.bytes]));
19488
+ }
19489
+ }
19490
+ /** @type {API.BlockFetcher['get']} */
19491
+ async get(cid) {
19492
+ const bytes = this.#blocks.get(cid.toString());
19493
+ if (!bytes)
19494
+ return;
19495
+ return { cid, bytes };
19496
+ }
19497
+ /**
19498
+ * @param {API.UnknownLink} cid
19499
+ * @param {Uint8Array} bytes
19500
+ */
19501
+ async put(cid, bytes) {
19502
+ this.#blocks.set(cid.toString(), bytes);
19503
+ }
19504
+ /**
19505
+ * @param {API.UnknownLink} cid
19506
+ * @param {Uint8Array} bytes
19507
+ */
19508
+ putSync(cid, bytes) {
19509
+ this.#blocks.set(cid.toString(), bytes);
19510
+ }
19511
+ /** @param {API.UnknownLink} cid */
19512
+ async delete(cid) {
19513
+ this.#blocks.delete(cid.toString());
19514
+ }
19515
+ /** @param {API.UnknownLink} cid */
19516
+ deleteSync(cid) {
19517
+ this.#blocks.delete(cid.toString());
19518
+ }
19519
+ *entries() {
19520
+ for (const [str, bytes] of this.#blocks) {
19521
+ yield { cid: parse(str), bytes };
19522
+ }
19523
+ }
19524
+ };
19525
+ var MultiBlockFetcher = class {
19526
+ /** @type {API.BlockFetcher[]} */
19527
+ #fetchers;
19528
+ /** @param {API.BlockFetcher[]} fetchers */
19529
+ constructor(...fetchers) {
19530
+ this.#fetchers = fetchers;
19531
+ }
19532
+ /** @type {API.BlockFetcher['get']} */
19533
+ async get(link2) {
19534
+ for (const f of this.#fetchers) {
19535
+ const v = await f.get(link2);
19536
+ if (v)
19537
+ return v;
19538
+ }
19539
+ }
19540
+ };
19541
+
19542
+ // ../../node_modules/.pnpm/@web3-storage+pail@0.4.1/node_modules/@web3-storage/pail/src/batch/shard.js
19543
+ var ShardLinkByteLength = 36;
19544
+ var CID_TAG3 = new Token(Type.tag, 42);
19533
19545
  var create8 = (init2) => ({
19534
19546
  base: init2?.base,
19535
19547
  prefix: init2?.prefix ?? "",
19536
- entries: init2?.entries ?? [],
19548
+ entries: [...init2?.entries ?? []],
19537
19549
  ...configure(init2)
19538
19550
  });
19551
+ var encodedLength = (shard) => {
19552
+ let entriesLength = 0;
19553
+ for (const entry of shard.entries) {
19554
+ entriesLength += entryEncodedLength(entry);
19555
+ }
19556
+ const tokens = [
19557
+ new Token(Type.map, 3),
19558
+ new Token(Type.string, "entries"),
19559
+ new Token(Type.array, shard.entries.length),
19560
+ new Token(Type.string, "maxKeyLength"),
19561
+ new Token(Type.uint, shard.maxKeyLength),
19562
+ new Token(Type.string, "maxSize"),
19563
+ new Token(Type.uint, shard.maxSize)
19564
+ ];
19565
+ return tokensToLength(tokens) + entriesLength;
19566
+ };
19567
+ var entryEncodedLength = (entry) => {
19568
+ const tokens = [
19569
+ new Token(Type.array, entry.length),
19570
+ new Token(Type.string, entry[0])
19571
+ ];
19572
+ if (Array.isArray(entry[1])) {
19573
+ tokens.push(new Token(Type.array, entry[1].length));
19574
+ for (const item of entry[1]) {
19575
+ tokens.push(CID_TAG3);
19576
+ if (isLink(item)) {
19577
+ tokens.push(new Token(Type.bytes, { length: item.byteLength + 1 }));
19578
+ } else {
19579
+ tokens.push(new Token(Type.bytes, { length: ShardLinkByteLength + 1 }));
19580
+ }
19581
+ }
19582
+ } else {
19583
+ tokens.push(CID_TAG3);
19584
+ tokens.push(new Token(Type.bytes, { length: entry[1].byteLength + 1 }));
19585
+ }
19586
+ return tokensToLength(tokens);
19587
+ };
19539
19588
 
19540
- // ../../node_modules/.pnpm/@web3-storage+pail@0.4.0/node_modules/@web3-storage/pail/src/batch/index.js
19589
+ // ../../node_modules/.pnpm/@web3-storage+pail@0.4.1/node_modules/@web3-storage/pail/src/batch/index.js
19541
19590
  var Batcher = class _Batcher {
19542
19591
  #committed = false;
19543
19592
  /**
@@ -19552,7 +19601,7 @@ ${key.data.toString("base64")}
19552
19601
  constructor({ blocks, entries: entries3, prefix, maxSize, maxKeyLength, base: base4 }) {
19553
19602
  this.blocks = blocks;
19554
19603
  this.prefix = prefix;
19555
- this.entries = entries3;
19604
+ this.entries = [...entries3];
19556
19605
  this.base = base4;
19557
19606
  this.maxSize = maxSize;
19558
19607
  this.maxKeyLength = maxKeyLength;
@@ -19582,7 +19631,7 @@ ${key.data.toString("base64")}
19582
19631
  static async create({ blocks, link: link2, prefix }) {
19583
19632
  const shards = new ShardFetcher(blocks);
19584
19633
  const base4 = await shards.get(link2);
19585
- return new _Batcher({ blocks, entries: base4.value.entries, prefix, base: base4, ...configure(base4.value) });
19634
+ return new _Batcher({ blocks, prefix, base: base4, ...base4.value });
19586
19635
  }
19587
19636
  };
19588
19637
  var put2 = async (blocks, shard, key, value) => {
@@ -19619,7 +19668,7 @@ ${key.data.toString("base64")}
19619
19668
  entry = [pfxskeys[0].key, [batcher]];
19620
19669
  }
19621
19670
  shard.entries = putEntry(asShardEntries(shard.entries), asShardEntry(entry));
19622
- const size = encodedLength(withEntries(asShardEntries(shard.entries), shard));
19671
+ const size = encodedLength(shard);
19623
19672
  if (size > shard.maxSize) {
19624
19673
  const common = findCommonPrefix(
19625
19674
  asShardEntries(shard.entries),
@@ -19656,14 +19705,16 @@ ${key.data.toString("base64")}
19656
19705
  }
19657
19706
  };
19658
19707
  var traverse2 = async (shards, key, shard) => {
19659
- for (const e of shard.entries) {
19660
- const [k, v] = e;
19708
+ for (let i = 0; i < shard.entries.length; i++) {
19709
+ const [k, v] = shard.entries[i];
19661
19710
  if (key <= k)
19662
19711
  break;
19663
19712
  if (key.startsWith(k) && Array.isArray(v)) {
19664
19713
  if (isShardLink(v[0])) {
19665
19714
  const blk = await shards.get(v[0], shard.prefix + k);
19666
- v[0] = create8({ base: blk, prefix: blk.prefix, ...blk.value });
19715
+ const batcher = create8({ base: blk, prefix: blk.prefix, ...blk.value });
19716
+ shard.entries[i] = [k, v[1] == null ? [batcher] : [batcher, v[1]]];
19717
+ return traverse2(shards, key.slice(k.length), batcher);
19667
19718
  }
19668
19719
  return traverse2(shards, key.slice(k.length), v[0]);
19669
19720
  }
@@ -19717,9 +19768,9 @@ ${key.data.toString("base64")}
19717
19768
  static code = "ERR_BATCH_COMMITTED";
19718
19769
  };
19719
19770
 
19720
- // ../../node_modules/.pnpm/@web3-storage+pail@0.4.0/node_modules/@web3-storage/pail/src/crdt/index.js
19771
+ // ../../node_modules/.pnpm/@web3-storage+pail@0.4.1/node_modules/@web3-storage/pail/src/crdt/index.js
19721
19772
  var put3 = async (blocks, head, key, value) => {
19722
- const mblocks = new MemoryBlockstore();
19773
+ const mblocks = new MemoryBlockstore2();
19723
19774
  blocks = new MultiBlockFetcher(mblocks, blocks);
19724
19775
  if (!head.length) {
19725
19776
  const shard = await ShardBlock.create();
@@ -19803,7 +19854,7 @@ ${key.data.toString("base64")}
19803
19854
  var root = async (blocks, head) => {
19804
19855
  if (!head.length)
19805
19856
  throw new Error("cannot determine root of headless clock");
19806
- const mblocks = new MemoryBlockstore();
19857
+ const mblocks = new MemoryBlockstore2();
19807
19858
  blocks = new MultiBlockFetcher(mblocks, blocks);
19808
19859
  const events = new EventFetcher(blocks);
19809
19860
  if (head.length === 1) {
@@ -19862,7 +19913,7 @@ ${key.data.toString("base64")}
19862
19913
  return;
19863
19914
  const result = await root(blocks, head);
19864
19915
  if (result.additions.length) {
19865
- blocks = new MultiBlockFetcher(new MemoryBlockstore(result.additions), blocks);
19916
+ blocks = new MultiBlockFetcher(new MemoryBlockstore2(result.additions), blocks);
19866
19917
  }
19867
19918
  return get2(blocks, result.root, key);
19868
19919
  };
@@ -19871,7 +19922,7 @@ ${key.data.toString("base64")}
19871
19922
  return;
19872
19923
  const result = await root(blocks, head);
19873
19924
  if (result.additions.length) {
19874
- blocks = new MultiBlockFetcher(new MemoryBlockstore(result.additions), blocks);
19925
+ blocks = new MultiBlockFetcher(new MemoryBlockstore2(result.additions), blocks);
19875
19926
  }
19876
19927
  yield* entries(blocks, result.root, options);
19877
19928
  };
@@ -19955,7 +20006,7 @@ ${key.data.toString("base64")}
19955
20006
  return acc.concat(...rest);
19956
20007
  };
19957
20008
 
19958
- // ../../node_modules/.pnpm/@web3-storage+pail@0.4.0/node_modules/@web3-storage/pail/src/crdt/batch/index.js
20009
+ // ../../node_modules/.pnpm/@web3-storage+pail@0.4.1/node_modules/@web3-storage/pail/src/crdt/batch/index.js
19959
20010
  var Batcher2 = class _Batcher {
19960
20011
  #committed = false;
19961
20012
  /**
@@ -19974,7 +20025,7 @@ ${key.data.toString("base64")}
19974
20025
  this.blocks = blocks;
19975
20026
  this.head = head;
19976
20027
  this.prefix = prefix;
19977
- this.entries = entries3;
20028
+ this.entries = [...entries3];
19978
20029
  this.base = base4;
19979
20030
  this.maxSize = maxSize;
19980
20031
  this.maxKeyLength = maxKeyLength;
@@ -20000,7 +20051,7 @@ ${key.data.toString("base64")}
20000
20051
  const res = await commit(this);
20001
20052
  const data = { type: "batch", ops: this.ops, root: res.root };
20002
20053
  const event = await EventBlock.create(data, this.head);
20003
- const mblocks = new MemoryBlockstore();
20054
+ const mblocks = new MemoryBlockstore2();
20004
20055
  const blocks = new MultiBlockFetcher(mblocks, this.blocks);
20005
20056
  mblocks.putSync(event.cid, event.bytes);
20006
20057
  const head = await advance(blocks, this.head, event.cid);
@@ -20040,7 +20091,7 @@ ${key.data.toString("base64")}
20040
20091
  * @param {string} init.prefix
20041
20092
  */
20042
20093
  static async create({ blocks, head, prefix }) {
20043
- const mblocks = new MemoryBlockstore();
20094
+ const mblocks = new MemoryBlockstore2();
20044
20095
  blocks = new MultiBlockFetcher(mblocks, blocks);
20045
20096
  if (!head.length) {
20046
20097
  const base5 = await ShardBlock.create();
@@ -29249,7 +29300,7 @@ ${key.data.toString("base64")}
29249
29300
  }
29250
29301
  } else {
29251
29302
  if (!mapFn) {
29252
- mapFn = makeMapFnFromName(name7);
29303
+ mapFn = (doc) => doc[name7] ?? void 0;
29253
29304
  }
29254
29305
  if (this.mapFnString) {
29255
29306
  if (this.mapFnString !== mapFn.toString())
@@ -29390,9 +29441,6 @@ ${key.data.toString("base64")}
29390
29441
  });
29391
29442
  }
29392
29443
  };
29393
- function makeMapFnFromName(name7) {
29394
- return (doc) => doc[name7] ?? void 0;
29395
- }
29396
29444
 
29397
29445
  // src/apply-head-queue.ts
29398
29446
  function applyHeadQueue(worker) {
@@ -29533,7 +29581,7 @@ ${key.data.toString("base64")}
29533
29581
  try {
29534
29582
  head = await advance(tblocks, head, cid);
29535
29583
  } catch (e) {
29536
- console.error("failed to advance", cid.toString(), e);
29584
+ console.log("failed to advance head:", cid.toString());
29537
29585
  continue;
29538
29586
  }
29539
29587
  }