@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'
@@ -4129,22 +4129,6 @@ var Fireproof = (() => {
4129
4129
  }
4130
4130
  }
4131
4131
  };
4132
- var MultiBlockFetcher = class {
4133
- /** @type {API.BlockFetcher[]} */
4134
- #fetchers;
4135
- /** @param {API.BlockFetcher[]} fetchers */
4136
- constructor(...fetchers) {
4137
- this.#fetchers = fetchers;
4138
- }
4139
- /** @type {API.BlockFetcher['get']} */
4140
- async get(link2) {
4141
- for (const f of this.#fetchers) {
4142
- const v = await f.get(link2);
4143
- if (v)
4144
- return v;
4145
- }
4146
- }
4147
- };
4148
4132
 
4149
4133
  // ../../node_modules/.pnpm/yocto-queue@1.0.0/node_modules/yocto-queue/index.js
4150
4134
  var Node = class {
@@ -10157,8 +10141,7 @@ You can use close({ resize: true }) to resize header`);
10157
10141
  }
10158
10142
  async _commitInternal(t, done, opts = { noLoader: false, compact: false }) {
10159
10143
  await this.ready;
10160
- const header = done;
10161
- const fp = this.makeCarHeader(header, this.carLog, !!opts.compact);
10144
+ const fp = this.makeCarHeader(done, this.carLog, !!opts.compact);
10162
10145
  let roots = await this.prepareRoots(fp, t);
10163
10146
  const { cid, bytes } = await this.prepareCarFile(roots[0], t, !!opts.public);
10164
10147
  await this.carStore.save({ cid, bytes });
@@ -10189,10 +10172,9 @@ You can use close({ resize: true }) to resize header`);
10189
10172
  }
10190
10173
  async updateCarLog(cid, fp, compact) {
10191
10174
  if (compact) {
10192
- const fpCar = fp;
10193
- const previousCompactCid = this.carLog[this.carLog.length - 1];
10194
- fpCar.compact.map((c) => c.toString()).forEach(this.seenCompacted.add, this.seenCompacted);
10195
- this.carLog = [...uniqueCids([cid, ...this.carLog], this.seenCompacted)];
10175
+ const previousCompactCid = fp.compact[fp.compact.length - 1];
10176
+ fp.compact.map((c) => c.toString()).forEach(this.seenCompacted.add, this.seenCompacted);
10177
+ this.carLog = [...uniqueCids([...this.carLog, ...fp.cars, cid], this.seenCompacted)];
10196
10178
  void this.removeCidsForCompact(previousCompactCid);
10197
10179
  } else {
10198
10180
  this.carLog.unshift(cid);
@@ -10206,13 +10188,14 @@ You can use close({ resize: true }) to resize header`);
10206
10188
  await this.carStore.remove(cid2);
10207
10189
  }
10208
10190
  }
10209
- async flushCars() {
10210
- await this.ready;
10211
- for (const cid of this.carLog) {
10212
- const dbMeta = { car: cid, key: this.key || null };
10213
- await this.remoteWAL.enqueue(dbMeta, { public: false });
10214
- }
10215
- }
10191
+ // async flushCars() {
10192
+ // await this.ready
10193
+ // // for each cid in car log, make a dbMeta
10194
+ // for (const cid of this.carLog) {
10195
+ // const dbMeta = { car: cid, key: this.key || null } as DbMeta
10196
+ // await this.remoteWAL!.enqueue(dbMeta, { public: false })
10197
+ // }
10198
+ // }
10216
10199
  async *entries() {
10217
10200
  await this.ready;
10218
10201
  for (const [, block] of this.getBlockCache) {
@@ -10981,7 +10964,7 @@ You can use close({ resize: true }) to resize header`);
10981
10964
  }
10982
10965
  };
10983
10966
 
10984
- // ../../node_modules/.pnpm/@web3-storage+pail@0.4.0/node_modules/@web3-storage/pail/src/clock/index.js
10967
+ // ../../node_modules/.pnpm/@web3-storage+pail@0.4.1/node_modules/@web3-storage/pail/src/clock/index.js
10985
10968
  var advance = async (blocks, head, event) => {
10986
10969
  const events = new EventFetcher(blocks);
10987
10970
  const headmap = new Map(head.map((cid) => [cid.toString(), cid]));
@@ -11055,7 +11038,6 @@ You can use close({ resize: true }) to resize header`);
11055
11038
  return true;
11056
11039
  const [{ value: aevent }, { value: bevent }] = await Promise.all([events.get(a), events.get(b)]);
11057
11040
  const links3 = [...aevent.parents];
11058
- const seen = /* @__PURE__ */ new Set();
11059
11041
  while (links3.length) {
11060
11042
  const link2 = links3.shift();
11061
11043
  if (!link2)
@@ -11064,9 +11046,6 @@ You can use close({ resize: true }) to resize header`);
11064
11046
  return true;
11065
11047
  if (bevent.parents.some((p) => link2.toString() === p.toString()))
11066
11048
  continue;
11067
- if (seen.has(link2.toString()))
11068
- continue;
11069
- seen.add(link2.toString());
11070
11049
  const { value: event } = await events.get(link2);
11071
11050
  links3.push(...event.parents);
11072
11051
  }
@@ -11107,7 +11086,7 @@ You can use close({ resize: true }) to resize header`);
11107
11086
  };
11108
11087
  var shortLink = (l) => `${String(l).slice(0, 4)}..${String(l).slice(-4)}`;
11109
11088
 
11110
- // ../../node_modules/.pnpm/@web3-storage+pail@0.4.0/node_modules/@web3-storage/pail/src/shard.js
11089
+ // ../../node_modules/.pnpm/@web3-storage+pail@0.4.1/node_modules/@web3-storage/pail/src/shard.js
11111
11090
  var MaxKeyLength = 64;
11112
11091
  var MaxShardSize = 512 * 1024;
11113
11092
  var CID_TAG2 = new Token(Type.tag, 42);
@@ -11238,41 +11217,8 @@ You can use close({ resize: true }) to resize header`);
11238
11217
  }
11239
11218
  }
11240
11219
  };
11241
- var encodedLength = (shard) => {
11242
- let entriesLength = 0;
11243
- for (const entry of shard.entries) {
11244
- entriesLength += entryEncodedLength(entry);
11245
- }
11246
- const tokens = [
11247
- new Token(Type.map, 3),
11248
- new Token(Type.string, "entries"),
11249
- new Token(Type.array, shard.entries.length),
11250
- new Token(Type.string, "maxKeyLength"),
11251
- new Token(Type.uint, shard.maxKeyLength),
11252
- new Token(Type.string, "maxSize"),
11253
- new Token(Type.uint, shard.maxSize)
11254
- ];
11255
- return tokensToLength(tokens) + entriesLength;
11256
- };
11257
- var entryEncodedLength = (entry) => {
11258
- const tokens = [
11259
- new Token(Type.array, entry.length),
11260
- new Token(Type.string, entry[0])
11261
- ];
11262
- if (Array.isArray(entry[1])) {
11263
- tokens.push(new Token(Type.array, entry[1].length));
11264
- for (const link2 of entry[1]) {
11265
- tokens.push(CID_TAG2);
11266
- tokens.push(new Token(Type.bytes, { length: link2.byteLength + 1 }));
11267
- }
11268
- } else {
11269
- tokens.push(CID_TAG2);
11270
- tokens.push(new Token(Type.bytes, { length: entry[1].byteLength + 1 }));
11271
- }
11272
- return tokensToLength(tokens);
11273
- };
11274
11220
 
11275
- // ../../node_modules/.pnpm/@web3-storage+pail@0.4.0/node_modules/@web3-storage/pail/src/index.js
11221
+ // ../../node_modules/.pnpm/@web3-storage+pail@0.4.1/node_modules/@web3-storage/pail/src/index.js
11276
11222
  var put = async (blocks, root2, key, value) => {
11277
11223
  const shards = new ShardFetcher(blocks);
11278
11224
  const rshard = await shards.get(root2);
@@ -11475,15 +11421,118 @@ You can use close({ resize: true }) to resize header`);
11475
11421
  return [shard];
11476
11422
  };
11477
11423
 
11478
- // ../../node_modules/.pnpm/@web3-storage+pail@0.4.0/node_modules/@web3-storage/pail/src/batch/shard.js
11424
+ // ../../node_modules/.pnpm/@web3-storage+pail@0.4.1/node_modules/@web3-storage/pail/src/block.js
11425
+ var MemoryBlockstore2 = class {
11426
+ /** @type {Map<string, Uint8Array>} */
11427
+ #blocks = /* @__PURE__ */ new Map();
11428
+ /**
11429
+ * @param {Array<import('multiformats').Block>} [blocks]
11430
+ */
11431
+ constructor(blocks) {
11432
+ if (blocks) {
11433
+ this.#blocks = new Map(blocks.map((b) => [b.cid.toString(), b.bytes]));
11434
+ }
11435
+ }
11436
+ /** @type {API.BlockFetcher['get']} */
11437
+ async get(cid) {
11438
+ const bytes = this.#blocks.get(cid.toString());
11439
+ if (!bytes)
11440
+ return;
11441
+ return { cid, bytes };
11442
+ }
11443
+ /**
11444
+ * @param {API.UnknownLink} cid
11445
+ * @param {Uint8Array} bytes
11446
+ */
11447
+ async put(cid, bytes) {
11448
+ this.#blocks.set(cid.toString(), bytes);
11449
+ }
11450
+ /**
11451
+ * @param {API.UnknownLink} cid
11452
+ * @param {Uint8Array} bytes
11453
+ */
11454
+ putSync(cid, bytes) {
11455
+ this.#blocks.set(cid.toString(), bytes);
11456
+ }
11457
+ /** @param {API.UnknownLink} cid */
11458
+ async delete(cid) {
11459
+ this.#blocks.delete(cid.toString());
11460
+ }
11461
+ /** @param {API.UnknownLink} cid */
11462
+ deleteSync(cid) {
11463
+ this.#blocks.delete(cid.toString());
11464
+ }
11465
+ *entries() {
11466
+ for (const [str, bytes] of this.#blocks) {
11467
+ yield { cid: parse(str), bytes };
11468
+ }
11469
+ }
11470
+ };
11471
+ var MultiBlockFetcher = class {
11472
+ /** @type {API.BlockFetcher[]} */
11473
+ #fetchers;
11474
+ /** @param {API.BlockFetcher[]} fetchers */
11475
+ constructor(...fetchers) {
11476
+ this.#fetchers = fetchers;
11477
+ }
11478
+ /** @type {API.BlockFetcher['get']} */
11479
+ async get(link2) {
11480
+ for (const f of this.#fetchers) {
11481
+ const v = await f.get(link2);
11482
+ if (v)
11483
+ return v;
11484
+ }
11485
+ }
11486
+ };
11487
+
11488
+ // ../../node_modules/.pnpm/@web3-storage+pail@0.4.1/node_modules/@web3-storage/pail/src/batch/shard.js
11489
+ var ShardLinkByteLength = 36;
11490
+ var CID_TAG3 = new Token(Type.tag, 42);
11479
11491
  var create8 = (init2) => ({
11480
11492
  base: init2?.base,
11481
11493
  prefix: init2?.prefix ?? "",
11482
- entries: init2?.entries ?? [],
11494
+ entries: [...init2?.entries ?? []],
11483
11495
  ...configure(init2)
11484
11496
  });
11497
+ var encodedLength = (shard) => {
11498
+ let entriesLength = 0;
11499
+ for (const entry of shard.entries) {
11500
+ entriesLength += entryEncodedLength(entry);
11501
+ }
11502
+ const tokens = [
11503
+ new Token(Type.map, 3),
11504
+ new Token(Type.string, "entries"),
11505
+ new Token(Type.array, shard.entries.length),
11506
+ new Token(Type.string, "maxKeyLength"),
11507
+ new Token(Type.uint, shard.maxKeyLength),
11508
+ new Token(Type.string, "maxSize"),
11509
+ new Token(Type.uint, shard.maxSize)
11510
+ ];
11511
+ return tokensToLength(tokens) + entriesLength;
11512
+ };
11513
+ var entryEncodedLength = (entry) => {
11514
+ const tokens = [
11515
+ new Token(Type.array, entry.length),
11516
+ new Token(Type.string, entry[0])
11517
+ ];
11518
+ if (Array.isArray(entry[1])) {
11519
+ tokens.push(new Token(Type.array, entry[1].length));
11520
+ for (const item of entry[1]) {
11521
+ tokens.push(CID_TAG3);
11522
+ if (isLink(item)) {
11523
+ tokens.push(new Token(Type.bytes, { length: item.byteLength + 1 }));
11524
+ } else {
11525
+ tokens.push(new Token(Type.bytes, { length: ShardLinkByteLength + 1 }));
11526
+ }
11527
+ }
11528
+ } else {
11529
+ tokens.push(CID_TAG3);
11530
+ tokens.push(new Token(Type.bytes, { length: entry[1].byteLength + 1 }));
11531
+ }
11532
+ return tokensToLength(tokens);
11533
+ };
11485
11534
 
11486
- // ../../node_modules/.pnpm/@web3-storage+pail@0.4.0/node_modules/@web3-storage/pail/src/batch/index.js
11535
+ // ../../node_modules/.pnpm/@web3-storage+pail@0.4.1/node_modules/@web3-storage/pail/src/batch/index.js
11487
11536
  var Batcher = class _Batcher {
11488
11537
  #committed = false;
11489
11538
  /**
@@ -11498,7 +11547,7 @@ You can use close({ resize: true }) to resize header`);
11498
11547
  constructor({ blocks, entries: entries3, prefix, maxSize, maxKeyLength, base: base4 }) {
11499
11548
  this.blocks = blocks;
11500
11549
  this.prefix = prefix;
11501
- this.entries = entries3;
11550
+ this.entries = [...entries3];
11502
11551
  this.base = base4;
11503
11552
  this.maxSize = maxSize;
11504
11553
  this.maxKeyLength = maxKeyLength;
@@ -11528,7 +11577,7 @@ You can use close({ resize: true }) to resize header`);
11528
11577
  static async create({ blocks, link: link2, prefix }) {
11529
11578
  const shards = new ShardFetcher(blocks);
11530
11579
  const base4 = await shards.get(link2);
11531
- return new _Batcher({ blocks, entries: base4.value.entries, prefix, base: base4, ...configure(base4.value) });
11580
+ return new _Batcher({ blocks, prefix, base: base4, ...base4.value });
11532
11581
  }
11533
11582
  };
11534
11583
  var put2 = async (blocks, shard, key, value) => {
@@ -11565,7 +11614,7 @@ You can use close({ resize: true }) to resize header`);
11565
11614
  entry = [pfxskeys[0].key, [batcher]];
11566
11615
  }
11567
11616
  shard.entries = putEntry(asShardEntries(shard.entries), asShardEntry(entry));
11568
- const size = encodedLength(withEntries(asShardEntries(shard.entries), shard));
11617
+ const size = encodedLength(shard);
11569
11618
  if (size > shard.maxSize) {
11570
11619
  const common = findCommonPrefix(
11571
11620
  asShardEntries(shard.entries),
@@ -11602,14 +11651,16 @@ You can use close({ resize: true }) to resize header`);
11602
11651
  }
11603
11652
  };
11604
11653
  var traverse2 = async (shards, key, shard) => {
11605
- for (const e of shard.entries) {
11606
- const [k, v] = e;
11654
+ for (let i = 0; i < shard.entries.length; i++) {
11655
+ const [k, v] = shard.entries[i];
11607
11656
  if (key <= k)
11608
11657
  break;
11609
11658
  if (key.startsWith(k) && Array.isArray(v)) {
11610
11659
  if (isShardLink(v[0])) {
11611
11660
  const blk = await shards.get(v[0], shard.prefix + k);
11612
- v[0] = create8({ base: blk, prefix: blk.prefix, ...blk.value });
11661
+ const batcher = create8({ base: blk, prefix: blk.prefix, ...blk.value });
11662
+ shard.entries[i] = [k, v[1] == null ? [batcher] : [batcher, v[1]]];
11663
+ return traverse2(shards, key.slice(k.length), batcher);
11613
11664
  }
11614
11665
  return traverse2(shards, key.slice(k.length), v[0]);
11615
11666
  }
@@ -11663,9 +11714,9 @@ You can use close({ resize: true }) to resize header`);
11663
11714
  static code = "ERR_BATCH_COMMITTED";
11664
11715
  };
11665
11716
 
11666
- // ../../node_modules/.pnpm/@web3-storage+pail@0.4.0/node_modules/@web3-storage/pail/src/crdt/index.js
11717
+ // ../../node_modules/.pnpm/@web3-storage+pail@0.4.1/node_modules/@web3-storage/pail/src/crdt/index.js
11667
11718
  var put3 = async (blocks, head, key, value) => {
11668
- const mblocks = new MemoryBlockstore();
11719
+ const mblocks = new MemoryBlockstore2();
11669
11720
  blocks = new MultiBlockFetcher(mblocks, blocks);
11670
11721
  if (!head.length) {
11671
11722
  const shard = await ShardBlock.create();
@@ -11749,7 +11800,7 @@ You can use close({ resize: true }) to resize header`);
11749
11800
  var root = async (blocks, head) => {
11750
11801
  if (!head.length)
11751
11802
  throw new Error("cannot determine root of headless clock");
11752
- const mblocks = new MemoryBlockstore();
11803
+ const mblocks = new MemoryBlockstore2();
11753
11804
  blocks = new MultiBlockFetcher(mblocks, blocks);
11754
11805
  const events = new EventFetcher(blocks);
11755
11806
  if (head.length === 1) {
@@ -11808,7 +11859,7 @@ You can use close({ resize: true }) to resize header`);
11808
11859
  return;
11809
11860
  const result = await root(blocks, head);
11810
11861
  if (result.additions.length) {
11811
- blocks = new MultiBlockFetcher(new MemoryBlockstore(result.additions), blocks);
11862
+ blocks = new MultiBlockFetcher(new MemoryBlockstore2(result.additions), blocks);
11812
11863
  }
11813
11864
  return get2(blocks, result.root, key);
11814
11865
  };
@@ -11817,7 +11868,7 @@ You can use close({ resize: true }) to resize header`);
11817
11868
  return;
11818
11869
  const result = await root(blocks, head);
11819
11870
  if (result.additions.length) {
11820
- blocks = new MultiBlockFetcher(new MemoryBlockstore(result.additions), blocks);
11871
+ blocks = new MultiBlockFetcher(new MemoryBlockstore2(result.additions), blocks);
11821
11872
  }
11822
11873
  yield* entries(blocks, result.root, options);
11823
11874
  };
@@ -11901,7 +11952,7 @@ You can use close({ resize: true }) to resize header`);
11901
11952
  return acc.concat(...rest);
11902
11953
  };
11903
11954
 
11904
- // ../../node_modules/.pnpm/@web3-storage+pail@0.4.0/node_modules/@web3-storage/pail/src/crdt/batch/index.js
11955
+ // ../../node_modules/.pnpm/@web3-storage+pail@0.4.1/node_modules/@web3-storage/pail/src/crdt/batch/index.js
11905
11956
  var Batcher2 = class _Batcher {
11906
11957
  #committed = false;
11907
11958
  /**
@@ -11920,7 +11971,7 @@ You can use close({ resize: true }) to resize header`);
11920
11971
  this.blocks = blocks;
11921
11972
  this.head = head;
11922
11973
  this.prefix = prefix;
11923
- this.entries = entries3;
11974
+ this.entries = [...entries3];
11924
11975
  this.base = base4;
11925
11976
  this.maxSize = maxSize;
11926
11977
  this.maxKeyLength = maxKeyLength;
@@ -11946,7 +11997,7 @@ You can use close({ resize: true }) to resize header`);
11946
11997
  const res = await commit(this);
11947
11998
  const data = { type: "batch", ops: this.ops, root: res.root };
11948
11999
  const event = await EventBlock.create(data, this.head);
11949
- const mblocks = new MemoryBlockstore();
12000
+ const mblocks = new MemoryBlockstore2();
11950
12001
  const blocks = new MultiBlockFetcher(mblocks, this.blocks);
11951
12002
  mblocks.putSync(event.cid, event.bytes);
11952
12003
  const head = await advance(blocks, this.head, event.cid);
@@ -11986,7 +12037,7 @@ You can use close({ resize: true }) to resize header`);
11986
12037
  * @param {string} init.prefix
11987
12038
  */
11988
12039
  static async create({ blocks, head, prefix }) {
11989
- const mblocks = new MemoryBlockstore();
12040
+ const mblocks = new MemoryBlockstore2();
11990
12041
  blocks = new MultiBlockFetcher(mblocks, blocks);
11991
12042
  if (!head.length) {
11992
12043
  const base5 = await ShardBlock.create();
@@ -21200,7 +21251,7 @@ You can use close({ resize: true }) to resize header`);
21200
21251
  }
21201
21252
  } else {
21202
21253
  if (!mapFn) {
21203
- mapFn = makeMapFnFromName(name7);
21254
+ mapFn = (doc) => doc[name7] ?? void 0;
21204
21255
  }
21205
21256
  if (this.mapFnString) {
21206
21257
  if (this.mapFnString !== mapFn.toString())
@@ -21341,9 +21392,6 @@ You can use close({ resize: true }) to resize header`);
21341
21392
  });
21342
21393
  }
21343
21394
  };
21344
- function makeMapFnFromName(name7) {
21345
- return (doc) => doc[name7] ?? void 0;
21346
- }
21347
21395
 
21348
21396
  // src/apply-head-queue.ts
21349
21397
  function applyHeadQueue(worker) {
@@ -21484,7 +21532,7 @@ You can use close({ resize: true }) to resize header`);
21484
21532
  try {
21485
21533
  head = await advance(tblocks, head, cid);
21486
21534
  } catch (e) {
21487
- console.error("failed to advance", cid.toString(), e);
21535
+ console.log("failed to advance head:", cid.toString());
21488
21536
  continue;
21489
21537
  }
21490
21538
  }