@wovin/core 0.1.19 → 0.1.21

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.
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  unchunkApplogsBlock
3
- } from "./chunk-3HHBRM32.min.js";
3
+ } from "./chunk-IIF2KSDX.min.js";
4
4
  import {
5
5
  CID,
6
6
  areCidsEqual,
@@ -129,4 +129,4 @@ async function updateThreadFromSnapshot(thread, cid, retriever, options) {
129
129
  export {
130
130
  updateThreadFromSnapshot
131
131
  };
132
- //# sourceMappingURL=chunk-W477A74Z.min.js.map
132
+ //# sourceMappingURL=chunk-FWL2ZJCW.min.js.map
@@ -3913,6 +3913,55 @@ async function makeCarBlob(roots, blocks) {
3913
3913
  async function carFromBlob(blob) {
3914
3914
  return CarReader.fromBytes(new Uint8Array(await blob.arrayBuffer()));
3915
3915
  }
3916
+ function extractCids(value) {
3917
+ if (value instanceof CID) return [value];
3918
+ if (Array.isArray(value)) return value.flatMap(extractCids);
3919
+ if (value && typeof value === "object") return Object.values(value).flatMap(extractCids);
3920
+ return [];
3921
+ }
3922
+ var MAX_COLLECT_BLOCKS = 1e6;
3923
+ async function collectDagBlocks(startCID, blockStore) {
3924
+ const visited = /* @__PURE__ */ new Set();
3925
+ const blocks = [];
3926
+ const queue = [startCID];
3927
+ while (queue.length > 0) {
3928
+ if (blocks.length >= MAX_COLLECT_BLOCKS) {
3929
+ WARN(`[collectDagBlocks] hit ${MAX_COLLECT_BLOCKS} block limit, returning partial result`);
3930
+ break;
3931
+ }
3932
+ const cid = queue.shift();
3933
+ const cidStr = cid.toString();
3934
+ if (visited.has(cidStr)) continue;
3935
+ visited.add(cidStr);
3936
+ let bytes;
3937
+ try {
3938
+ bytes = await blockStore.get(cid);
3939
+ } catch {
3940
+ WARN(`[collectDagBlocks] block not found: ${cidStr}, stopping this branch`);
3941
+ continue;
3942
+ }
3943
+ if (!bytes) {
3944
+ WARN(`[collectDagBlocks] block not found: ${cidStr}, stopping this branch`);
3945
+ continue;
3946
+ }
3947
+ blocks.push({ cid, bytes });
3948
+ if (blocks.length % 1e3 === 0) {
3949
+ LOG(`[collectDagBlocks] collected ${blocks.length} blocks...`);
3950
+ }
3951
+ try {
3952
+ const decoded = decode(bytes);
3953
+ const childCids = extractCids(decoded);
3954
+ for (const child of childCids) {
3955
+ if (!visited.has(child.toString())) {
3956
+ queue.push(child);
3957
+ }
3958
+ }
3959
+ } catch {
3960
+ }
3961
+ }
3962
+ DEBUG(`[collectDagBlocks] collected ${blocks.length} blocks from ${startCID.toString()}`);
3963
+ return blocks;
3964
+ }
3916
3965
  function streamReaderToIterable(bodyReader) {
3917
3966
  return (async function* () {
3918
3967
  while (true) {
@@ -4118,6 +4167,7 @@ export {
4118
4167
  makeCarOut,
4119
4168
  makeCarBlob,
4120
4169
  carFromBlob,
4170
+ collectDagBlocks,
4121
4171
  streamReaderToIterable
4122
4172
  };
4123
- //# sourceMappingURL=chunk-3HHBRM32.min.js.map
4173
+ //# sourceMappingURL=chunk-IIF2KSDX.min.js.map