filecoin 0.5.0 → 0.5.1

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 (63) hide show
  1. package/README.md +1 -1
  2. package/dist/chunks/{chunk-IAJFQYLN.js → chunk-5CKSVYCY.js} +2 -2
  3. package/dist/chunks/{chunk-K63EJUGU.js → chunk-AHVL5QFR.js} +2 -2
  4. package/dist/chunks/{chunk-CIVQHT3F.js → chunk-CC75NTEJ.js} +2 -2
  5. package/dist/chunks/{chunk-YVRWI5E3.js → chunk-D63BUPKY.js} +2 -2
  6. package/dist/chunks/{chunk-GCPUMM4E.js → chunk-I5AWWJGL.js} +2 -2
  7. package/dist/chunks/{chunk-63JLHZEK.js → chunk-IFG72OQD.js} +2 -2
  8. package/dist/chunks/{chunk-JFBUOLJ3.js → chunk-P2G2GV6U.js} +2 -2
  9. package/dist/chunks/{chunk-QRFSFJOZ.js → chunk-PSXNKYPA.js} +2 -2
  10. package/dist/chunks/{chunk-DHTPICN4.js → chunk-QAYTK26Z.js} +2 -2
  11. package/dist/chunks/{chunk-ASZ5KTWE.js → chunk-QLZRQUR6.js} +2 -2
  12. package/dist/chunks/{chunk-BFBNDHQG.js → chunk-S2DTA2FM.js} +2 -2
  13. package/dist/chunks/chunk-SVWQJYA5.js +3 -0
  14. package/dist/chunks/chunk-SVWQJYA5.js.map +7 -0
  15. package/dist/chunks/{chunk-MWVOEA6K.js → chunk-TCUXKQ65.js} +2 -2
  16. package/dist/chunks/{chunk-72RYXITT.js → chunk-UW35AN2V.js} +2 -2
  17. package/dist/chunks/{chunk-72RYXITT.js.map → chunk-UW35AN2V.js.map} +2 -2
  18. package/dist/chunks/{chunk-BZITZ3BI.js → chunk-VGOSQFKJ.js} +2 -2
  19. package/dist/chunks/{chunk-Z6O5SHUU.js → chunk-ZAMDBJVN.js} +2 -2
  20. package/dist/chunks/{delete-BO7K4456.js → delete-SPJVG4ZK.js} +2 -2
  21. package/dist/chunks/{doctor-NF75MDBO.js → doctor-AQGSDILX.js} +2 -2
  22. package/dist/chunks/{get-3EC2XCFH.js → get-C4RUQWRS.js} +2 -2
  23. package/dist/chunks/{inspect-FDI442BE.js → inspect-NXI72CUH.js} +2 -2
  24. package/dist/chunks/{inspect-RJCGSGKG.js → inspect-SBGOKBEP.js} +2 -2
  25. package/dist/chunks/{login-NNTYQ37I.js → login-3LYCAAPW.js} +2 -2
  26. package/dist/chunks/{logout-3RWZFH2E.js → logout-JLRMENQI.js} +2 -2
  27. package/dist/chunks/{ls-GNEVBKRP.js → ls-N5D6HCA4.js} +2 -2
  28. package/dist/chunks/{ls-F546AXRG.js → ls-O5RNPZCH.js} +2 -2
  29. package/dist/chunks/{put-FXMGPSU6.js → put-GTJP7IFM.js} +2 -2
  30. package/dist/chunks/{resume-G5PS246S.js → resume-BCEYVRX7.js} +2 -2
  31. package/dist/chunks/{status-HOLDXKMR.js → status-IWMRFMPV.js} +2 -2
  32. package/dist/main.js +1 -1
  33. package/dist/main.js.map +1 -1
  34. package/dist/tsconfig.tsbuildinfo +1 -1
  35. package/package.json +2 -2
  36. package/dist/chunks/chunk-AKXAQJ6H.js +0 -3
  37. package/dist/chunks/chunk-AKXAQJ6H.js.map +0 -7
  38. /package/dist/chunks/{chunk-IAJFQYLN.js.map → chunk-5CKSVYCY.js.map} +0 -0
  39. /package/dist/chunks/{chunk-K63EJUGU.js.map → chunk-AHVL5QFR.js.map} +0 -0
  40. /package/dist/chunks/{chunk-CIVQHT3F.js.map → chunk-CC75NTEJ.js.map} +0 -0
  41. /package/dist/chunks/{chunk-YVRWI5E3.js.map → chunk-D63BUPKY.js.map} +0 -0
  42. /package/dist/chunks/{chunk-GCPUMM4E.js.map → chunk-I5AWWJGL.js.map} +0 -0
  43. /package/dist/chunks/{chunk-63JLHZEK.js.map → chunk-IFG72OQD.js.map} +0 -0
  44. /package/dist/chunks/{chunk-JFBUOLJ3.js.map → chunk-P2G2GV6U.js.map} +0 -0
  45. /package/dist/chunks/{chunk-QRFSFJOZ.js.map → chunk-PSXNKYPA.js.map} +0 -0
  46. /package/dist/chunks/{chunk-DHTPICN4.js.map → chunk-QAYTK26Z.js.map} +0 -0
  47. /package/dist/chunks/{chunk-ASZ5KTWE.js.map → chunk-QLZRQUR6.js.map} +0 -0
  48. /package/dist/chunks/{chunk-BFBNDHQG.js.map → chunk-S2DTA2FM.js.map} +0 -0
  49. /package/dist/chunks/{chunk-MWVOEA6K.js.map → chunk-TCUXKQ65.js.map} +0 -0
  50. /package/dist/chunks/{chunk-BZITZ3BI.js.map → chunk-VGOSQFKJ.js.map} +0 -0
  51. /package/dist/chunks/{chunk-Z6O5SHUU.js.map → chunk-ZAMDBJVN.js.map} +0 -0
  52. /package/dist/chunks/{delete-BO7K4456.js.map → delete-SPJVG4ZK.js.map} +0 -0
  53. /package/dist/chunks/{doctor-NF75MDBO.js.map → doctor-AQGSDILX.js.map} +0 -0
  54. /package/dist/chunks/{get-3EC2XCFH.js.map → get-C4RUQWRS.js.map} +0 -0
  55. /package/dist/chunks/{inspect-FDI442BE.js.map → inspect-NXI72CUH.js.map} +0 -0
  56. /package/dist/chunks/{inspect-RJCGSGKG.js.map → inspect-SBGOKBEP.js.map} +0 -0
  57. /package/dist/chunks/{login-NNTYQ37I.js.map → login-3LYCAAPW.js.map} +0 -0
  58. /package/dist/chunks/{logout-3RWZFH2E.js.map → logout-JLRMENQI.js.map} +0 -0
  59. /package/dist/chunks/{ls-GNEVBKRP.js.map → ls-N5D6HCA4.js.map} +0 -0
  60. /package/dist/chunks/{ls-F546AXRG.js.map → ls-O5RNPZCH.js.map} +0 -0
  61. /package/dist/chunks/{put-FXMGPSU6.js.map → put-GTJP7IFM.js.map} +0 -0
  62. /package/dist/chunks/{resume-G5PS246S.js.map → resume-BCEYVRX7.js.map} +0 -0
  63. /package/dist/chunks/{status-HOLDXKMR.js.map → status-IWMRFMPV.js.map} +0 -0
package/README.md CHANGED
@@ -131,7 +131,7 @@ Ctrl+C, SIGTERM, or SIGHUP stops the work at the next step. `filecoin` returns a
131
131
  | `FILECOIN_STATE_DIR` | SQLite state and staged CARs. Default: the platform data directory for `filecoin` |
132
132
  | `FILECOIN_RPC_URL` | RPC endpoint. Default: synapse-core's fallback transport for the chain |
133
133
  | `FILECOIN_CONSOLE_URL` | filecoin-app origin for approval and funding links, such as `http://localhost:5173` for a local app. Default: `https://poc.filecoin.cloud` |
134
- | `FILECOIN_API_URL` | filecoin-api origin for retrieval links, such as `http://localhost:8787` for a local API. Default: `https://api.filecoin.cloud` |
134
+ | `FILECOIN_API_URL` | filecoin-api origin for retrieval links, such as `http://localhost:8787` for a local API. Default: `https://api.filecoin.io` |
135
135
  | `FILECOIN_OUTPUT`, `FILECOIN_AGENT` | Override clipact's output mode and agent detection |
136
136
 
137
137
  The prototype saves the session private key in the config file with mode 0600, so only its owner can read it. `filecoin logout` deletes the local key. The key stays authorized on chain until it expires or you revoke it on the filecoin-app session keys page.
@@ -1,4 +1,4 @@
1
1
  import { createRequire as __createRequire } from 'node:module'; const require = __createRequire(import.meta.url);
2
2
  import{C as z,a as e,b as a,c as l,e as u,f as s,g as c,i as o,k as t,u as m,v as d,w as p}from"./chunk-JUFFOBKU.js";import{d as i}from"./chunk-3TJUKWFC.js";var v=i({name:"ls",description:"List managed resources, newest first",examples:["filecoin ls","filecoin ls --all --limit 50"],input:c({...p,all:l().default(!1).describe("Include resources pending removal"),...m}),env:d,secrets:["sessionKey"],output:s({network:e(),resources:u(s({ref:e(),kind:o(["file","folder"]),name:e(),size:a().int(),status:o(["active","removal_pending"]),url:e().describe("filecoin-api link a browser renders"),createdAt:e()})),nextCursor:e().optional()}),errors:[t.authRequired,t.loginPending],readOnly:!0,human:n=>n.resources.length===0?`No resources on ${n.network}.`:[...n.resources.map(r=>`${r.ref} ${r.kind.padEnd(8)} ${z(r.size).padStart(10)} ${r.name}${r.status==="active"?"":` (${r.status})`}`),...n.nextCursor?[`more: --cursor ${n.nextCursor}`]:[]].join(`
3
- `),handler:()=>import("./ls-F546AXRG.js")});export{v as a};
4
- //# sourceMappingURL=chunk-IAJFQYLN.js.map
3
+ `),handler:()=>import("./ls-O5RNPZCH.js")});export{v as a};
4
+ //# sourceMappingURL=chunk-5CKSVYCY.js.map
@@ -1,4 +1,4 @@
1
1
  import { createRequire as __createRequire } from 'node:module'; const require = __createRequire(import.meta.url);
2
2
  import{a as o,f as s,g as i,m as n,u as t,v as m,z as u}from"./chunk-JUFFOBKU.js";import{d as r}from"./chunk-3TJUKWFC.js";var d=r({name:"resume",description:"Continue an unfinished operation with its saved input",examples:["filecoin operations resume op_abc123"],input:i({id:o().describe("Operation ID (op_\u2026)"),...t}),positionals:["id"],env:m,secrets:["sessionKey"],output:s(u),errors:n,idempotent:!0,human:e=>e.state==="ready"?`Stored ${e.resource.name} (${e.resource.ref})
3
- ${e.urls.browser}`:`Removal of ${e.resource.ref} (${e.resource.name}) scheduled.`,handler:()=>import("./resume-G5PS246S.js")});export{d as a};
4
- //# sourceMappingURL=chunk-K63EJUGU.js.map
3
+ ${e.urls.browser}`:`Removal of ${e.resource.ref} (${e.resource.name}) scheduled.`,handler:()=>import("./resume-BCEYVRX7.js")});export{d as a};
4
+ //# sourceMappingURL=chunk-AHVL5QFR.js.map
@@ -1,5 +1,5 @@
1
1
  import { createRequire as __createRequire } from 'node:module'; const require = __createRequire(import.meta.url);
2
2
  import{C as h,a as e,b as s,c as r,e as c,f as i,g as l,i as a,j as d,m as u,u as z,v as m,x as f,y as g}from"./chunk-JUFFOBKU.js";import{d as p}from"./chunk-3TJUKWFC.js";var b=i({kind:a(["file","folder"]),name:e(),size:s().int().describe("Bytes to store: the file, or the packed CAR"),files:s().int(),rootCid:e().optional(),network:e(),authorization:a(["ready","login_required","login_pending","scopes_missing"]).describe("Whether the session key can sign this put"),missingScopes:c(e()).optional(),provider:i({id:e(),serviceURL:e(),dataSetId:e().optional().describe("Existing data set to add to")}).optional(),cost:i({token:d("USDFC"),ready:r().describe("The payer can cover it now"),depositNeeded:e(),needsApproval:r(),ratePerMonth:e(),lockup:e(),fundingUrl:e().optional()}).optional(),checkedAt:e()}),k=p({name:"put",description:"Store a file (raw piece) or directory (UnixFS CAR) with one copy",examples:["filecoin put ./report.pdf","filecoin put ./site --name docs","filecoin publish ./site --dry-run"],input:l({path:e().describe("File or directory to store"),name:e().min(1).optional().describe("Display name (default: basename)"),provider:e().regex(/^\d+$/,"Expected a decimal provider ID").optional().describe("Storage provider ID (default: automatic)"),...z}),positionals:["path"],env:m,secrets:["sessionKey"],output:i({dryRun:r(),operationId:e().optional().describe("Set when dryRun is false"),state:d("ready").optional(),resource:f.optional(),urls:g.optional(),estimate:b.optional().describe("Set when dryRun is true")}),errors:u,dryRun:!0,human:o=>{if(o.estimate){let t=o.estimate,n=[`Would store ${t.kind} ${t.name}: ${h(t.size)}, ${t.files} file(s) on ${t.network}`,`authorization: ${t.authorization}`];return t.provider&&n.push(`provider: ${t.provider.id} (${t.provider.serviceURL})`),t.cost&&n.push(`cost: ${t.cost.ratePerMonth} USDFC/month, lockup ${t.cost.lockup} USDFC, ${t.cost.ready?"funded":`deposit ${t.cost.depositNeeded} USDFC first`}`),n.join(`
3
3
  `)}return`Stored ${o.resource?.name} (${o.resource?.ref})
4
- ${o.urls?.browser}`},handler:()=>import("./put-FXMGPSU6.js")});export{k as a};
5
- //# sourceMappingURL=chunk-CIVQHT3F.js.map
4
+ ${o.urls?.browser}`},handler:()=>import("./put-GTJP7IFM.js")});export{k as a};
5
+ //# sourceMappingURL=chunk-CC75NTEJ.js.map
@@ -1,3 +1,3 @@
1
1
  import { createRequire as __createRequire } from 'node:module'; const require = __createRequire(import.meta.url);
2
- import{d as n,e as o,n as s}from"./chunk-72RYXITT.js";function f(r){if(r===n.id.toString())return"mainnet";if(r===o.id.toString())return"calibration";throw new Error(`Unknown chain ID ${r}.`)}function c(r,e,d,a,t){let i=new URL(`get/${encodeURIComponent(d)}`,r.endsWith("/")?r:`${r}/`);return i.searchParams.set("network",e),a&&i.searchParams.set("browser","true"),t&&i.searchParams.set("provider",t),i.toString()}function p(r){let e=f(r.chainId);return{piece:c(r.apiUrl,e,r.pieceCid,!1,r.providerId),browser:c(r.apiUrl,e,r.rootCid??r.pieceCid,!0,r.rootCid?void 0:r.providerId)}}function l(r,e){return p({apiUrl:e,chainId:r.chainId,pieceCid:r.pieceCid,rootCid:r.rootCid})}function w(r){let[e]=r.copies;if(!e)throw new Error(`Resource ${r.ref} has no stored copies.`);return s({cid:r.pieceCid,serviceURL:e.serviceURL.endsWith("/")?e.serviceURL:`${e.serviceURL}/`})}export{p as a,l as b,w as c};
3
- //# sourceMappingURL=chunk-YVRWI5E3.js.map
2
+ import{d as n,e as o,n as s}from"./chunk-UW35AN2V.js";function f(r){if(r===n.id.toString())return"mainnet";if(r===o.id.toString())return"calibration";throw new Error(`Unknown chain ID ${r}.`)}function c(r,e,d,a,t){let i=new URL(`get/${encodeURIComponent(d)}`,r.endsWith("/")?r:`${r}/`);return i.searchParams.set("network",e),a&&i.searchParams.set("browser","true"),t&&i.searchParams.set("provider",t),i.toString()}function p(r){let e=f(r.chainId);return{piece:c(r.apiUrl,e,r.pieceCid,!1,r.providerId),browser:c(r.apiUrl,e,r.rootCid??r.pieceCid,!0,r.rootCid?void 0:r.providerId)}}function l(r,e){return p({apiUrl:e,chainId:r.chainId,pieceCid:r.pieceCid,rootCid:r.rootCid})}function w(r){let[e]=r.copies;if(!e)throw new Error(`Resource ${r.ref} has no stored copies.`);return s({cid:r.pieceCid,serviceURL:e.serviceURL.endsWith("/")?e.serviceURL:`${e.serviceURL}/`})}export{p as a,l as b,w as c};
3
+ //# sourceMappingURL=chunk-D63BUPKY.js.map
@@ -1,3 +1,3 @@
1
1
  import { createRequire as __createRequire } from 'node:module'; const require = __createRequire(import.meta.url);
2
- import{a as w}from"./chunk-AKXAQJ6H.js";import{a as y,b as M}from"./chunk-YVRWI5E3.js";import{C as L,F as g,L as J,M as _,N as S,O as T,Q as b,R as z,S as F,T as B,U as v}from"./chunk-72RYXITT.js";import{k as p,o as E,p as I,q as l}from"./chunk-JUFFOBKU.js";import{p as m,q as $}from"./chunk-3TJUKWFC.js";import{createReadStream as j}from"node:fs";import{rm as q,stat as k}from"node:fs/promises";import{basename as Q,join as X,resolve as V}from"node:path";var G={source:"filecoin"},K={source:"filecoin",withIPFSIndexing:""},Y=96;async function H(e){let t=V(e.path),i=await k(t).catch(()=>{});if(!i||!(i.isFile()||i.isDirectory()))throw I(`No file or directory at ${e.path}.`,"path");let r=e.name??Q(t);return i.isDirectory()?{sourcePath:t,kind:"folder",name:r}:(C(i.size),{sourcePath:t,kind:"file",name:r,size:i.size})}async function ve(e,t){let i=await H(t),r=S(e.db,{action:"put",resourceRef:_("res"),chainId:e.chainId,payer:e.payer,input:{sourcePath:i.sourcePath,name:i.name,kind:i.kind,providerId:t.providerId?.toString()}});return await N(e,r.id)}async function Se(e){let t=await H(e),i;if(t.kind==="file")i={kind:"file",name:t.name,size:t.size??0,files:1};else{let d=await w(t.sourcePath);C(d.size),i={kind:"folder",name:t.name,size:d.size,files:d.files,rootCid:d.rootCid.toString()}}if(!e.backend)return i;let r=await e.backend.selectPlacement({metadata:P(i.kind),providerId:e.providerId}),a=await e.backend.quote({size:i.size,placement:r});return{...i,placement:r,quote:a}}async function N(e,t){let i=T(e.db,t);if(!i)throw l(`Operation ${t} not found.`);if(i.executionStatus==="completed")return x(e,i);let r=z(e.db,t);try{return e.onOperation?.(r),r.action==="put"?await te(e,r):await ae(e,r)}catch(a){throw b(e.db,r.id,{executionStatus:"failed",pid:null,error:e.signal?.aborted?"Interrupted":a instanceof Error?a.message:String(a)}),e.signal?.aborted?a:E(a,r.id)}finally{F(r.id)}}function x(e,t){let i=v(e.db,t.resourceRef);if(!i)throw l(`Resource ${t.resourceRef} of ${t.id} no longer exists.`);return Z(e,t,i)}function Z(e,t,i){return{operationId:t.id,state:t.action==="put"?"ready":"removal_pending",resource:i,urls:M(i,e.apiUrl)}}function W(e,t,i,r={}){J(e.db,()=>{B(e.db,i),b(e.db,t.id,{executionStatus:"completed",phase:"done",pid:null,error:null,checkpoint:r})})}function C(e){if(e<g.MIN_UPLOAD_SIZE||e>g.MAX_UPLOAD_SIZE)throw I(`Content must be between ${g.MIN_UPLOAD_SIZE} and ${g.MAX_UPLOAD_SIZE} bytes; got ${e}.`,"path")}function P(e){return e==="folder"?K:G}async function ee(e,t){let i=j(e,{signal:t});return(await L(i)).toString()}function u(e,t,i,r){return b(e.db,t.id,{checkpoint:i,...r?{phase:r}:{}})}async function te(e,t){let{input:i}=t,r=i.kind??"file",a=i.name??"upload",d=e.signal;if(!i.sourcePath)throw new Error(`Operation ${t.id} has no source.`);let s=i.sourcePath;if(r==="folder"&&(s=X(e.stagingDir(t.id),"folder.car"),!await k(s).catch(()=>{}))){if(t.checkpoint.pieceCid)throw new m({code:p.stagingMissing,message:`The staged CAR of ${t.id} is missing, so it cannot be resumed.`,next:[{by:"agent",command:`filecoin put ${i.sourcePath}`,description:"Start a new put of the same directory"}]});t=u(e,t,{},"packing"),e.progress?.({phase:"packing",message:`Packing ${i.sourcePath}`});let D=await w(i.sourcePath,s);t=u(e,t,{rootCid:D.rootCid.toString(),size:D.size})}d?.throwIfAborted();let c=(await k(s)).size;C(c),e.progress?.({phase:"hashing",message:"Computing PieceCID"});let o=await ee(s,d);if(t.checkpoint.pieceCid&&t.checkpoint.pieceCid!==o)throw new m({code:p.sourceChanged,message:`${s} changed since operation ${t.id} started.`,next:[{by:"agent",command:`filecoin put ${i.sourcePath}`,description:"Start a new put with the current content"}]});t=u(e,t,{pieceCid:o,size:c},"storing");let n=ne(t.checkpoint);if(!n){e.progress?.({phase:"placing",message:"Selecting a storage provider"}),n=await e.backend.selectPlacement({metadata:P(r),providerId:i.providerId?BigInt(i.providerId):void 0});let h=await e.backend.quote({size:c,placement:n});if(!h.ready)throw re(h);t=u(e,t,{providerId:n.providerId.toString(),serviceURL:n.serviceURL,payee:n.payee,...n.dataSetId==null?{}:{dataSetId:n.dataSetId.toString(),clientDataSetId:n.clientDataSetId?.toString()}})}t.checkpoint.commit||t.checkpoint.stored||(await e.backend.hasPiece({serviceURL:n.serviceURL,pieceCid:o})||(e.progress?.({phase:"uploading",message:`Uploading ${c} bytes to provider ${n.providerId}`}),await e.backend.upload({serviceURL:n.serviceURL,path:s,size:c,pieceCid:o})),t=u(e,t,{stored:!0}));let R=y({apiUrl:e.apiUrl,chainId:t.chainId,pieceCid:o,rootCid:t.checkpoint.rootCid,providerId:n.providerId.toString()}),U=()=>e.progress?.({phase:"link",message:R.browser,data:{pieceCid:o,urls:R}});r==="file"&&U();let f=await ie(e,t,n,{pieceCid:o,name:a},r==="folder"?U:void 0),O=y({apiUrl:e.apiUrl,chainId:t.chainId,pieceCid:o,rootCid:t.checkpoint.rootCid}),A={ref:t.resourceRef,kind:r,name:a,chainId:t.chainId,payer:t.payer,pieceCid:o,...t.checkpoint.rootCid?{rootCid:t.checkpoint.rootCid}:{},size:c,copies:[{providerId:n.providerId.toString(),dataSetId:f.dataSetId.toString(),pieceId:f.pieceId.toString(),serviceURL:n.serviceURL}],url:O.browser,status:"active",createdAt:new Date().toISOString()};return W(e,t,A,{dataSetId:f.dataSetId.toString(),pieceId:f.pieceId.toString()}),r==="folder"&&await q(e.stagingDir(t.id),{recursive:!0,force:!0}).catch(()=>{}),{operationId:t.id,state:"ready",resource:A,urls:O}}async function ie(e,t,i,r,a){let d={name:r.name.slice(0,Y),...t.checkpoint.rootCid?{ipfsRootCID:t.checkpoint.rootCid}:{}},s=t.checkpoint.commit;if(s){let n=await e.backend.findCommit({nonce:BigInt(s.nonce)});if(n)return n}t=u(e,t,{},"committing");let c=s;if(c||(e.progress?.({phase:"committing",message:"Signing the commit"}),c=await e.backend.signCommit({placement:i,pieceCid:r.pieceCid,metadata:P(t.input.kind??"file"),pieceMetadata:d}),t=u(e,t,{commit:c})),!t.checkpoint.statusUrl){e.progress?.({phase:"committing",message:c.created?"Creating data set and adding piece":"Adding piece"});let n=await e.backend.submitCommit({placement:i,pieceCid:r.pieceCid,commit:c,pieceMetadata:d});t=u(e,t,{statusUrl:n.statusUrl,transactionHash:n.transactionHash})}a?.();let{transactionHash:o}=t.checkpoint;e.progress?.({phase:"committing",message:o?`Waiting for confirmation of transaction ${o}`:"Waiting for on-chain confirmation",...o?{data:{transactionHash:o}}:{}});try{return await e.backend.waitForCommit({statusUrl:t.checkpoint.statusUrl,created:c.created})}catch(n){throw $(n)&&n.code===p.commitRejected&&u(e,t,{statusUrl:void 0,transactionHash:void 0}),n}}function re(e){return new m({code:p.insufficientFunds,message:e.needsApproval?"The payer must deposit USDFC and approve Warm Storage before uploading.":"The payer must deposit more USDFC before uploading.",details:{fundingUrl:e.fundingUrl,depositNeeded:e.depositNeeded.toString(),needsApproval:e.needsApproval},next:[{by:"user",description:`Fund the account at ${e.fundingUrl}`}]})}function ne(e){if(e.providerId&&e.serviceURL&&e.payee)return{providerId:BigInt(e.providerId),serviceURL:e.serviceURL,payee:e.payee,...e.dataSetId&&e.clientDataSetId?{dataSetId:BigInt(e.dataSetId),clientDataSetId:BigInt(e.clientDataSetId)}:{}}}async function we(e,t){let i=v(e.db,t,e);if(!i)throw l(`No managed resource ${t} for this account.`,{by:"agent",command:"filecoin ls",description:"List managed resources"});if(i.status!=="active")throw I(`${t} is already pending removal.`,"ref");let[r]=i.copies;if(!r)throw new Error(`Resource ${t} has no stored copies.`);let a=S(e.db,{action:"delete",resourceRef:t,chainId:e.chainId,payer:e.payer,input:{},checkpoint:{providerId:r.providerId,serviceURL:r.serviceURL,dataSetId:r.dataSetId,pieceId:r.pieceId}});return await N(e,a.id)}async function ae(e,t){let i=v(e.db,t.resourceRef);if(!i)throw l(`Resource ${t.resourceRef} no longer exists.`);let{serviceURL:r,dataSetId:a,pieceId:d}=t.checkpoint;if(!(r&&a&&d))throw new Error(`Operation ${t.id} is missing its removal target.`);if(!t.checkpoint.transactionHash){t=u(e,t,{},"removing"),e.progress?.({phase:"removing",message:`Scheduling removal of piece ${d}`});let{transactionHash:n}=await e.backend.schedulePieceRemoval({serviceURL:r,dataSetId:BigInt(a),pieceId:BigInt(d)});t=u(e,t,{transactionHash:n})}let s=t.checkpoint.transactionHash;if(e.progress?.({phase:"removing",message:`Waiting for confirmation of removal transaction ${s}`,data:{transactionHash:s}}),(await e.backend.waitForTransaction(s)).status!=="success")throw u(e,t,{transactionHash:void 0}),new m({code:p.removalReverted,message:`Removal transaction ${s} reverted; the piece is still stored.`});let o={...i,status:"removal_pending"};return W(e,t,o),Z(e,t,o)}export{ve as a,Se as b,N as c,x as d,we as e};
3
- //# sourceMappingURL=chunk-GCPUMM4E.js.map
2
+ import{a as w}from"./chunk-SVWQJYA5.js";import{a as y,b as M}from"./chunk-D63BUPKY.js";import{C as L,F as g,L as J,M as _,N as S,O as T,Q as b,R as z,S as F,T as B,U as v}from"./chunk-UW35AN2V.js";import{k as p,o as E,p as I,q as l}from"./chunk-JUFFOBKU.js";import{p as m,q as $}from"./chunk-3TJUKWFC.js";import{createReadStream as j}from"node:fs";import{rm as q,stat as k}from"node:fs/promises";import{basename as Q,join as X,resolve as V}from"node:path";var G={source:"filecoin"},K={source:"filecoin",withIPFSIndexing:""},Y=96;async function H(e){let t=V(e.path),i=await k(t).catch(()=>{});if(!i||!(i.isFile()||i.isDirectory()))throw I(`No file or directory at ${e.path}.`,"path");let r=e.name??Q(t);return i.isDirectory()?{sourcePath:t,kind:"folder",name:r}:(C(i.size),{sourcePath:t,kind:"file",name:r,size:i.size})}async function ve(e,t){let i=await H(t),r=S(e.db,{action:"put",resourceRef:_("res"),chainId:e.chainId,payer:e.payer,input:{sourcePath:i.sourcePath,name:i.name,kind:i.kind,providerId:t.providerId?.toString()}});return await N(e,r.id)}async function Se(e){let t=await H(e),i;if(t.kind==="file")i={kind:"file",name:t.name,size:t.size??0,files:1};else{let d=await w(t.sourcePath);C(d.size),i={kind:"folder",name:t.name,size:d.size,files:d.files,rootCid:d.rootCid.toString()}}if(!e.backend)return i;let r=await e.backend.selectPlacement({metadata:P(i.kind),providerId:e.providerId}),a=await e.backend.quote({size:i.size,placement:r});return{...i,placement:r,quote:a}}async function N(e,t){let i=T(e.db,t);if(!i)throw l(`Operation ${t} not found.`);if(i.executionStatus==="completed")return x(e,i);let r=z(e.db,t);try{return e.onOperation?.(r),r.action==="put"?await te(e,r):await ae(e,r)}catch(a){throw b(e.db,r.id,{executionStatus:"failed",pid:null,error:e.signal?.aborted?"Interrupted":a instanceof Error?a.message:String(a)}),e.signal?.aborted?a:E(a,r.id)}finally{F(r.id)}}function x(e,t){let i=v(e.db,t.resourceRef);if(!i)throw l(`Resource ${t.resourceRef} of ${t.id} no longer exists.`);return Z(e,t,i)}function Z(e,t,i){return{operationId:t.id,state:t.action==="put"?"ready":"removal_pending",resource:i,urls:M(i,e.apiUrl)}}function W(e,t,i,r={}){J(e.db,()=>{B(e.db,i),b(e.db,t.id,{executionStatus:"completed",phase:"done",pid:null,error:null,checkpoint:r})})}function C(e){if(e<g.MIN_UPLOAD_SIZE||e>g.MAX_UPLOAD_SIZE)throw I(`Content must be between ${g.MIN_UPLOAD_SIZE} and ${g.MAX_UPLOAD_SIZE} bytes; got ${e}.`,"path")}function P(e){return e==="folder"?K:G}async function ee(e,t){let i=j(e,{signal:t});return(await L(i)).toString()}function u(e,t,i,r){return b(e.db,t.id,{checkpoint:i,...r?{phase:r}:{}})}async function te(e,t){let{input:i}=t,r=i.kind??"file",a=i.name??"upload",d=e.signal;if(!i.sourcePath)throw new Error(`Operation ${t.id} has no source.`);let s=i.sourcePath;if(r==="folder"&&(s=X(e.stagingDir(t.id),"folder.car"),!await k(s).catch(()=>{}))){if(t.checkpoint.pieceCid)throw new m({code:p.stagingMissing,message:`The staged CAR of ${t.id} is missing, so it cannot be resumed.`,next:[{by:"agent",command:`filecoin put ${i.sourcePath}`,description:"Start a new put of the same directory"}]});t=u(e,t,{},"packing"),e.progress?.({phase:"packing",message:`Packing ${i.sourcePath}`});let D=await w(i.sourcePath,s);t=u(e,t,{rootCid:D.rootCid.toString(),size:D.size})}d?.throwIfAborted();let c=(await k(s)).size;C(c),e.progress?.({phase:"hashing",message:"Computing PieceCID"});let o=await ee(s,d);if(t.checkpoint.pieceCid&&t.checkpoint.pieceCid!==o)throw new m({code:p.sourceChanged,message:`${s} changed since operation ${t.id} started.`,next:[{by:"agent",command:`filecoin put ${i.sourcePath}`,description:"Start a new put with the current content"}]});t=u(e,t,{pieceCid:o,size:c},"storing");let n=ne(t.checkpoint);if(!n){e.progress?.({phase:"placing",message:"Selecting a storage provider"}),n=await e.backend.selectPlacement({metadata:P(r),providerId:i.providerId?BigInt(i.providerId):void 0});let h=await e.backend.quote({size:c,placement:n});if(!h.ready)throw re(h);t=u(e,t,{providerId:n.providerId.toString(),serviceURL:n.serviceURL,payee:n.payee,...n.dataSetId==null?{}:{dataSetId:n.dataSetId.toString(),clientDataSetId:n.clientDataSetId?.toString()}})}t.checkpoint.commit||t.checkpoint.stored||(await e.backend.hasPiece({serviceURL:n.serviceURL,pieceCid:o})||(e.progress?.({phase:"uploading",message:`Uploading ${c} bytes to provider ${n.providerId}`}),await e.backend.upload({serviceURL:n.serviceURL,path:s,size:c,pieceCid:o})),t=u(e,t,{stored:!0}));let R=y({apiUrl:e.apiUrl,chainId:t.chainId,pieceCid:o,rootCid:t.checkpoint.rootCid,providerId:n.providerId.toString()}),U=()=>e.progress?.({phase:"link",message:R.browser,data:{pieceCid:o,urls:R}});r==="file"&&U();let f=await ie(e,t,n,{pieceCid:o,name:a},r==="folder"?U:void 0),O=y({apiUrl:e.apiUrl,chainId:t.chainId,pieceCid:o,rootCid:t.checkpoint.rootCid}),A={ref:t.resourceRef,kind:r,name:a,chainId:t.chainId,payer:t.payer,pieceCid:o,...t.checkpoint.rootCid?{rootCid:t.checkpoint.rootCid}:{},size:c,copies:[{providerId:n.providerId.toString(),dataSetId:f.dataSetId.toString(),pieceId:f.pieceId.toString(),serviceURL:n.serviceURL}],url:O.browser,status:"active",createdAt:new Date().toISOString()};return W(e,t,A,{dataSetId:f.dataSetId.toString(),pieceId:f.pieceId.toString()}),r==="folder"&&await q(e.stagingDir(t.id),{recursive:!0,force:!0}).catch(()=>{}),{operationId:t.id,state:"ready",resource:A,urls:O}}async function ie(e,t,i,r,a){let d={name:r.name.slice(0,Y),...t.checkpoint.rootCid?{ipfsRootCID:t.checkpoint.rootCid}:{}},s=t.checkpoint.commit;if(s){let n=await e.backend.findCommit({nonce:BigInt(s.nonce)});if(n)return n}t=u(e,t,{},"committing");let c=s;if(c||(e.progress?.({phase:"committing",message:"Signing the commit"}),c=await e.backend.signCommit({placement:i,pieceCid:r.pieceCid,metadata:P(t.input.kind??"file"),pieceMetadata:d}),t=u(e,t,{commit:c})),!t.checkpoint.statusUrl){e.progress?.({phase:"committing",message:c.created?"Creating data set and adding piece":"Adding piece"});let n=await e.backend.submitCommit({placement:i,pieceCid:r.pieceCid,commit:c,pieceMetadata:d});t=u(e,t,{statusUrl:n.statusUrl,transactionHash:n.transactionHash})}a?.();let{transactionHash:o}=t.checkpoint;e.progress?.({phase:"committing",message:o?`Waiting for confirmation of transaction ${o}`:"Waiting for on-chain confirmation",...o?{data:{transactionHash:o}}:{}});try{return await e.backend.waitForCommit({statusUrl:t.checkpoint.statusUrl,created:c.created})}catch(n){throw $(n)&&n.code===p.commitRejected&&u(e,t,{statusUrl:void 0,transactionHash:void 0}),n}}function re(e){return new m({code:p.insufficientFunds,message:e.needsApproval?"The payer must deposit USDFC and approve Warm Storage before uploading.":"The payer must deposit more USDFC before uploading.",details:{fundingUrl:e.fundingUrl,depositNeeded:e.depositNeeded.toString(),needsApproval:e.needsApproval},next:[{by:"user",description:`Fund the account at ${e.fundingUrl}`}]})}function ne(e){if(e.providerId&&e.serviceURL&&e.payee)return{providerId:BigInt(e.providerId),serviceURL:e.serviceURL,payee:e.payee,...e.dataSetId&&e.clientDataSetId?{dataSetId:BigInt(e.dataSetId),clientDataSetId:BigInt(e.clientDataSetId)}:{}}}async function we(e,t){let i=v(e.db,t,e);if(!i)throw l(`No managed resource ${t} for this account.`,{by:"agent",command:"filecoin ls",description:"List managed resources"});if(i.status!=="active")throw I(`${t} is already pending removal.`,"ref");let[r]=i.copies;if(!r)throw new Error(`Resource ${t} has no stored copies.`);let a=S(e.db,{action:"delete",resourceRef:t,chainId:e.chainId,payer:e.payer,input:{},checkpoint:{providerId:r.providerId,serviceURL:r.serviceURL,dataSetId:r.dataSetId,pieceId:r.pieceId}});return await N(e,a.id)}async function ae(e,t){let i=v(e.db,t.resourceRef);if(!i)throw l(`Resource ${t.resourceRef} no longer exists.`);let{serviceURL:r,dataSetId:a,pieceId:d}=t.checkpoint;if(!(r&&a&&d))throw new Error(`Operation ${t.id} is missing its removal target.`);if(!t.checkpoint.transactionHash){t=u(e,t,{},"removing"),e.progress?.({phase:"removing",message:`Scheduling removal of piece ${d}`});let{transactionHash:n}=await e.backend.schedulePieceRemoval({serviceURL:r,dataSetId:BigInt(a),pieceId:BigInt(d)});t=u(e,t,{transactionHash:n})}let s=t.checkpoint.transactionHash;if(e.progress?.({phase:"removing",message:`Waiting for confirmation of removal transaction ${s}`,data:{transactionHash:s}}),(await e.backend.waitForTransaction(s)).status!=="success")throw u(e,t,{transactionHash:void 0}),new m({code:p.removalReverted,message:`Removal transaction ${s} reverted; the piece is still stored.`});let o={...i,status:"removal_pending"};return W(e,t,o),Z(e,t,o)}export{ve as a,Se as b,N as c,x as d,we as e};
3
+ //# sourceMappingURL=chunk-I5AWWJGL.js.map
@@ -1,4 +1,4 @@
1
1
  import { createRequire as __createRequire } from 'node:module'; const require = __createRequire(import.meta.url);
2
2
  import{a as e,c as s,f as r,g as d,h as p,i,j as l,u,v as f}from"./chunk-JUFFOBKU.js";import{d as a}from"./chunk-3TJUKWFC.js";var y=a({name:"status",description:"Show the session, scope expiries, and funding readiness",examples:["filecoin status","filecoin status --network mainnet"],input:d(u),env:f,secrets:["sessionKey"],output:r({network:e(),session:r({state:i(["none","pending","active"]),source:i(["env","config"]).optional(),address:e().optional(),rootAddress:e().optional(),url:e().optional().describe("Approval link of a pending login"),scopes:p(e(),e()).optional().describe('Expiry per scope, or "expired" or "not granted"')}),account:r({token:l("USDFC"),funds:e(),availableFunds:e(),debt:e(),ready:s().describe("Ready to pay for a new 1 MiB upload"),needsApproval:s(),depositNeeded:e(),fundingUrl:e().optional()}).optional()}),readOnly:!0,human:({network:z,session:n,account:o})=>{let t=[`network: ${z}`,`session: ${n.state}`];n.url&&t.push(`approve at: ${n.url}`),n.rootAddress&&t.push(`wallet: ${n.rootAddress}`);for(let[c,g]of Object.entries(n.scopes??{}))t.push(` ${c}: ${g}`);return o&&(t.push(`funds: ${o.availableFunds} of ${o.funds} USDFC available`,`ready: ${o.ready?"yes":"no"}`),o.fundingUrl&&t.push(`fund at: ${o.fundingUrl}`)),t.join(`
3
- `)},handler:()=>import("./status-HOLDXKMR.js")});export{y as a};
4
- //# sourceMappingURL=chunk-63JLHZEK.js.map
3
+ `)},handler:()=>import("./status-IWMRFMPV.js")});export{y as a};
4
+ //# sourceMappingURL=chunk-IFG72OQD.js.map
@@ -1,3 +1,3 @@
1
1
  import { createRequire as __createRequire } from 'node:module'; const require = __createRequire(import.meta.url);
2
- import{a as o,f as s,g as t,m as c,u as m,v as i,z as n}from"./chunk-JUFFOBKU.js";import{d as r}from"./chunk-3TJUKWFC.js";var u=r({name:"delete",description:"Schedule removal of a managed resource",examples:["filecoin delete res_abc123","filecoin rm res_abc123 --yes"],input:t({ref:o().describe("Resource ref (res_\u2026)"),...m}),positionals:["ref"],env:i,secrets:["sessionKey"],output:s(n),errors:c,confirm:e=>`Schedules removal of ${e.ref}; the provider deletes the stored copy.`,human:e=>`Removal of ${e.resource.ref} (${e.resource.name}) scheduled.`,handler:()=>import("./delete-BO7K4456.js")});export{u as a};
3
- //# sourceMappingURL=chunk-JFBUOLJ3.js.map
2
+ import{a as o,f as s,g as t,m as c,u as m,v as i,z as n}from"./chunk-JUFFOBKU.js";import{d as r}from"./chunk-3TJUKWFC.js";var u=r({name:"delete",description:"Schedule removal of a managed resource",examples:["filecoin delete res_abc123","filecoin rm res_abc123 --yes"],input:t({ref:o().describe("Resource ref (res_\u2026)"),...m}),positionals:["ref"],env:i,secrets:["sessionKey"],output:s(n),errors:c,confirm:e=>`Schedules removal of ${e.ref}; the provider deletes the stored copy.`,human:e=>`Removal of ${e.resource.ref} (${e.resource.name}) scheduled.`,handler:()=>import("./delete-SPJVG4ZK.js")});export{u as a};
3
+ //# sourceMappingURL=chunk-P2G2GV6U.js.map
@@ -1,3 +1,3 @@
1
1
  import { createRequire as __createRequire } from 'node:module'; const require = __createRequire(import.meta.url);
2
- import{A as u,a as t,b as o,d as e,f as s,g as p,h as i,i as c,k as n,u as a,v as d}from"./chunk-JUFFOBKU.js";import{d as r}from"./chunk-3TJUKWFC.js";var h=r({name:"inspect",description:"Show an operation with its saved input and checkpoint",examples:["filecoin operations inspect op_abc123"],input:p({id:t().describe("Operation ID (op_\u2026)"),...a}),positionals:["id"],env:d,secrets:["sessionKey"],output:s({id:t(),action:c(["put","delete"]),resourceRef:t(),chainId:t(),payer:t(),executionStatus:u,phase:t(),input:i(t(),e()),checkpoint:i(t(),e()),pid:o().int().optional(),error:t().optional(),createdAt:t(),updatedAt:t()}),errors:[n.authRequired,n.loginPending,n.notFound],readOnly:!0,handler:()=>import("./inspect-FDI442BE.js")});export{h as a};
3
- //# sourceMappingURL=chunk-QRFSFJOZ.js.map
2
+ import{A as u,a as t,b as o,d as e,f as s,g as p,h as i,i as c,k as n,u as a,v as d}from"./chunk-JUFFOBKU.js";import{d as r}from"./chunk-3TJUKWFC.js";var h=r({name:"inspect",description:"Show an operation with its saved input and checkpoint",examples:["filecoin operations inspect op_abc123"],input:p({id:t().describe("Operation ID (op_\u2026)"),...a}),positionals:["id"],env:d,secrets:["sessionKey"],output:s({id:t(),action:c(["put","delete"]),resourceRef:t(),chainId:t(),payer:t(),executionStatus:u,phase:t(),input:i(t(),e()),checkpoint:i(t(),e()),pid:o().int().optional(),error:t().optional(),createdAt:t(),updatedAt:t()}),errors:[n.authRequired,n.loginPending,n.notFound],readOnly:!0,handler:()=>import("./inspect-NXI72CUH.js")});export{h as a};
3
+ //# sourceMappingURL=chunk-PSXNKYPA.js.map
@@ -1,4 +1,4 @@
1
1
  import { createRequire as __createRequire } from 'node:module'; const require = __createRequire(import.meta.url);
2
2
  import{a as r,b as c,c as a,f as i,g as u,i as d,k as t,u as p,v as l,x as m,y as b}from"./chunk-JUFFOBKU.js";import{d as n}from"./chunk-3TJUKWFC.js";var C=n({name:"inspect",description:"Show a managed resource and its retrieval URLs",examples:["filecoin inspect res_abc123","filecoin inspect res_abc123 --check"],input:u({ref:r().describe("Resource ref (res_\u2026)"),check:a().default(!1).describe("Probe the piece URL with a HEAD request"),...p}),positionals:["ref"],env:l,secrets:["sessionKey"],output:i({resource:m,urls:b,retrieval:i({url:r(),state:d(["ready","unavailable"]),status:c().int().describe("HTTP status; 0 when unreachable"),checkedAt:r()}).optional()}),errors:[t.authRequired,t.loginPending,t.notFound],readOnly:!0,human:({resource:e,urls:o,retrieval:s})=>[`${e.ref} ${e.kind} ${e.name} (${e.status})`,`pieceCid: ${e.pieceCid}`,...e.rootCid?[`rootCid: ${e.rootCid}`]:[],`piece: ${o.piece}`,`browser: ${o.browser}`,...s?[`retrieval: ${s.state} (HTTP ${s.status})`]:[]].join(`
3
- `),handler:()=>import("./inspect-RJCGSGKG.js")});export{C as a};
4
- //# sourceMappingURL=chunk-DHTPICN4.js.map
3
+ `),handler:()=>import("./inspect-SBGOKBEP.js")});export{C as a};
4
+ //# sourceMappingURL=chunk-QAYTK26Z.js.map
@@ -1,4 +1,4 @@
1
1
  import { createRequire as __createRequire } from 'node:module'; const require = __createRequire(import.meta.url);
2
2
  import{B as u,a as r,c as i,e as s,f as a,g as p,k as n,u as m,v as c,w as l}from"./chunk-JUFFOBKU.js";import{d as t}from"./chunk-3TJUKWFC.js";var h=t({name:"ls",description:"List put and delete operations, most recently updated first",examples:["filecoin operations ls","filecoin operations ls --incomplete"],input:p({...l,incomplete:i().default(!1).describe("Only operations that have not completed"),...m}),env:c,secrets:["sessionKey"],output:a({network:r(),operations:s(u),nextCursor:r().optional()}),errors:[n.authRequired,n.loginPending],readOnly:!0,human:o=>o.operations.length===0?`No operations on ${o.network}.`:[...o.operations.map(e=>`${e.id} ${e.action.padEnd(6)} ${e.executionStatus.padEnd(9)} ${e.phase.padEnd(10)} ${e.resourceRef}${e.error?` ${e.error}`:""}`),...o.nextCursor?[`more: --cursor ${o.nextCursor}`]:[]].join(`
3
- `),handler:()=>import("./ls-GNEVBKRP.js")});export{h as a};
4
- //# sourceMappingURL=chunk-ASZ5KTWE.js.map
3
+ `),handler:()=>import("./ls-N5D6HCA4.js")});export{h as a};
4
+ //# sourceMappingURL=chunk-QLZRQUR6.js.map
@@ -1,3 +1,3 @@
1
1
  import { createRequire as __createRequire } from 'node:module'; const require = __createRequire(import.meta.url);
2
- import{C as l,a as e,b as r,c as n,f as s,g as u,i as c,k as i,u as a,v as f}from"./chunk-JUFFOBKU.js";import{d as o}from"./chunk-3TJUKWFC.js";var b=o({name:"get",description:"Download and verify a resource (by ref or PieceCID)",examples:["filecoin get res_abc123","filecoin get res_abc123 --output ./copy"],input:u({target:e().describe("Resource ref (res_\u2026), PieceCID, or root CID"),output:e().optional().describe("Output path (default: the resource name)"),force:n().default(!1).describe("Overwrite an existing file"),...a}),positionals:["target"],env:f,secrets:["sessionKey"],output:s({kind:c(["file","folder"]),ref:e().optional(),pieceCid:e(),output:e().describe("Written file or directory"),size:r().int().describe("Verified bytes downloaded"),files:r().int().optional().describe("Files extracted"),url:e()}),errors:[i.authRequired,i.loginPending,i.notFound,i.outputExists,i.verificationFailed,i.unsafePath],idempotent:!0,human:t=>`Wrote ${t.output} (${l(t.size)}${t.files==null?"":`, ${t.files} files`}), verified against ${t.pieceCid}`,handler:()=>import("./get-3EC2XCFH.js")});export{b as a};
3
- //# sourceMappingURL=chunk-BFBNDHQG.js.map
2
+ import{C as l,a as e,b as r,c as n,f as s,g as u,i as c,k as i,u as a,v as f}from"./chunk-JUFFOBKU.js";import{d as o}from"./chunk-3TJUKWFC.js";var b=o({name:"get",description:"Download and verify a resource (by ref or PieceCID)",examples:["filecoin get res_abc123","filecoin get res_abc123 --output ./copy"],input:u({target:e().describe("Resource ref (res_\u2026), PieceCID, or root CID"),output:e().optional().describe("Output path (default: the resource name)"),force:n().default(!1).describe("Overwrite an existing file"),...a}),positionals:["target"],env:f,secrets:["sessionKey"],output:s({kind:c(["file","folder"]),ref:e().optional(),pieceCid:e(),output:e().describe("Written file or directory"),size:r().int().describe("Verified bytes downloaded"),files:r().int().optional().describe("Files extracted"),url:e()}),errors:[i.authRequired,i.loginPending,i.notFound,i.outputExists,i.verificationFailed,i.unsafePath],idempotent:!0,human:t=>`Wrote ${t.output} (${l(t.size)}${t.files==null?"":`, ${t.files} files`}), verified against ${t.pieceCid}`,handler:()=>import("./get-C4RUQWRS.js")});export{b as a};
3
+ //# sourceMappingURL=chunk-S2DTA2FM.js.map
@@ -0,0 +1,3 @@
1
+ import { createRequire as __createRequire } from 'node:module'; const require = __createRequire(import.meta.url);
2
+ import{A as k,B as Oe,o as qi,p as te,q as Gi,r as ji,s as sr,t as Yi,u as J,v as Ki,w as Ji,x as Xi,y as ar,z as et}from"./chunk-UW35AN2V.js";import{k as St,p as Wi}from"./chunk-JUFFOBKU.js";import{p as It}from"./chunk-3TJUKWFC.js";import{b as Qe,c as ee,d as At}from"./chunk-YIAP3JO3.js";var os=Qe((ch,is)=>{is.exports=Dn;var ns=128,xu=127,ku=~xu,Eu=Math.pow(2,31);function Dn(t,e,r){if(Number.MAX_SAFE_INTEGER&&t>Number.MAX_SAFE_INTEGER)throw Dn.bytes=0,new RangeError("Could not encode varint");e=e||[],r=r||0;for(var n=r;t>=Eu;)e[r++]=t&255|ns,t/=128;for(;t&ku;)e[r++]=t&255|ns,t>>>=7;return e[r]=t|0,Dn.bytes=r-n+1,e}});var cs=Qe((uh,as)=>{as.exports=Ln;var _u=128,ss=127;function Ln(t,n){var r=0,n=n||0,i=0,o=n,s,a=t.length;do{if(o>=a||i>49)throw Ln.bytes=0,new RangeError("Could not decode varint");s=t[o++],r+=i<28?(s&ss)<<i:(s&ss)*Math.pow(2,i),i+=7}while(s>=_u);return Ln.bytes=o-n,r}});var fs=Qe((fh,us)=>{var Au=Math.pow(2,7),Iu=Math.pow(2,14),Su=Math.pow(2,21),Tu=Math.pow(2,28),vu=Math.pow(2,35),Bu=Math.pow(2,42),Cu=Math.pow(2,49),Du=Math.pow(2,56),Lu=Math.pow(2,63);us.exports=function(t){return t<Au?1:t<Iu?2:t<Su?3:t<Tu?4:t<vu?5:t<Bu?6:t<Cu?7:t<Du?8:t<Lu?9:10}});var Tr=Qe((lh,ls)=>{ls.exports={encode:os(),decode:cs(),encodingLength:fs()}});var qs=Qe((Dp,Ws)=>{"use strict";Ws.exports=class{constructor(){this._bitArrays=[],this._data=[],this._length=0,this._changedLength=!1,this._changedData=!1}set(e,r){let n=this._internalPositionFor(e,!1);if(r===void 0)n!==-1&&(this._unsetInternalPos(n),this._unsetBit(e),this._changedLength=!0,this._changedData=!0);else{let i=!1;n===-1?(n=this._data.length,this._setBit(e),this._changedData=!0):i=!0,this._setInternalPos(n,e,r,i),this._changedLength=!0}}unset(e){this.set(e,void 0)}get(e){this._sortData();let r=this._internalPositionFor(e,!0);if(r!==-1)return this._data[r][1]}push(e){return this.set(this.length,e),this.length}get length(){if(this._sortData(),this._changedLength){let e=this._data[this._data.length-1];this._length=e?e[0]+1:0,this._changedLength=!1}return this._length}forEach(e){let r=0;for(;r<this.length;)e(this.get(r),r,this),r++}map(e){let r=0,n=new Array(this.length);for(;r<this.length;)n[r]=e(this.get(r),r,this),r++;return n}reduce(e,r){let n=0,i=r;for(;n<this.length;){let o=this.get(n);i=e(i,o,n),n++}return i}find(e){let r=0,n,i;for(;r<this.length&&!n;)i=this.get(r),n=e(i),r++;return n?i:void 0}_internalPositionFor(e,r){let n=this._bytePosFor(e,r);if(n>=this._bitArrays.length)return-1;let i=this._bitArrays[n],o=e-n*7;if(!((i&1<<o)>0))return-1;let a=this._bitArrays.slice(0,n).reduce(Ef,0),c=~(4294967295<<o+1),u=Vs(i&c);return a+u-1}_bytePosFor(e,r){let n=Math.floor(e/7),i=n+1;for(;!r&&this._bitArrays.length<i;)this._bitArrays.push(0);return n}_setBit(e){let r=this._bytePosFor(e,!1);this._bitArrays[r]|=1<<e-r*7}_unsetBit(e){let r=this._bytePosFor(e,!1);this._bitArrays[r]&=~(1<<e-r*7)}_setInternalPos(e,r,n,i){let o=this._data,s=[r,n];if(i)this._sortData(),o[e]=s;else{if(o.length)if(o[o.length-1][0]>=r)o.push(s);else if(o[0][0]<=r)o.unshift(s);else{let a=Math.round(o.length/2);this._data=o.slice(0,a).concat(s).concat(o.slice(a))}else this._data.push(s);this._changedData=!0,this._changedLength=!0}}_unsetInternalPos(e){this._data.splice(e,1)}_sortData(){this._changedData&&this._data.sort(_f),this._changedData=!1}bitField(){let e=[],r=8,n=0,i=0,o,s=this._bitArrays.slice();for(;s.length||n;){n===0&&(o=s.shift(),n=7);let c=Math.min(n,r),u=~(255<<c),f=o&u;i|=f<<8-r,o=o>>>c,n-=c,r-=c,(!r||!n&&!s.length)&&(e.push(i),i=0,r=8)}for(var a=e.length-1;a>0&&e[a]===0;a--)e.pop();return e}compactArray(){return this._sortData(),this._data.map(Af)}};function Ef(t,e){return t+Vs(e)}function Vs(t){let e=t;return e=e-(e>>1&1431655765),e=(e&858993459)+(e>>2&858993459),(e+(e>>4)&252645135)*16843009>>24}function _f(t,e){return t[0]-e[0]}function Af(t){return t[1]}});var Wa=Qe((vw,Ti)=>{"use strict";var El=Object.prototype.hasOwnProperty,M="~";function rr(){}Object.create&&(rr.prototype=Object.create(null),new rr().__proto__||(M=!1));function _l(t,e,r){this.fn=t,this.context=e,this.once=r||!1}function Va(t,e,r,n,i){if(typeof r!="function")throw new TypeError("The listener must be a function");var o=new _l(r,n||t,i),s=M?M+e:e;return t._events[s]?t._events[s].fn?t._events[s]=[t._events[s],o]:t._events[s].push(o):(t._events[s]=o,t._eventsCount++),t}function nn(t,e){--t._eventsCount===0?t._events=new rr:delete t._events[e]}function O(){this._events=new rr,this._eventsCount=0}O.prototype.eventNames=function(){var e=[],r,n;if(this._eventsCount===0)return e;for(n in r=this._events)El.call(r,n)&&e.push(M?n.slice(1):n);return Object.getOwnPropertySymbols?e.concat(Object.getOwnPropertySymbols(r)):e};O.prototype.listeners=function(e){var r=M?M+e:e,n=this._events[r];if(!n)return[];if(n.fn)return[n.fn];for(var i=0,o=n.length,s=new Array(o);i<o;i++)s[i]=n[i].fn;return s};O.prototype.listenerCount=function(e){var r=M?M+e:e,n=this._events[r];return n?n.fn?1:n.length:0};O.prototype.emit=function(e,r,n,i,o,s){var a=M?M+e:e;if(!this._events[a])return!1;var c=this._events[a],u=arguments.length,f,d;if(c.fn){switch(c.once&&this.removeListener(e,c.fn,void 0,!0),u){case 1:return c.fn.call(c.context),!0;case 2:return c.fn.call(c.context,r),!0;case 3:return c.fn.call(c.context,r,n),!0;case 4:return c.fn.call(c.context,r,n,i),!0;case 5:return c.fn.call(c.context,r,n,i,o),!0;case 6:return c.fn.call(c.context,r,n,i,o,s),!0}for(d=1,f=new Array(u-1);d<u;d++)f[d-1]=arguments[d];c.fn.apply(c.context,f)}else{var m=c.length,w;for(d=0;d<m;d++)switch(c[d].once&&this.removeListener(e,c[d].fn,void 0,!0),u){case 1:c[d].fn.call(c[d].context);break;case 2:c[d].fn.call(c[d].context,r);break;case 3:c[d].fn.call(c[d].context,r,n);break;case 4:c[d].fn.call(c[d].context,r,n,i);break;default:if(!f)for(w=1,f=new Array(u-1);w<u;w++)f[w-1]=arguments[w];c[d].fn.apply(c[d].context,f)}}return!0};O.prototype.on=function(e,r,n){return Va(this,e,r,n,!1)};O.prototype.once=function(e,r,n){return Va(this,e,r,n,!0)};O.prototype.removeListener=function(e,r,n,i){var o=M?M+e:e;if(!this._events[o])return this;if(!r)return nn(this,o),this;var s=this._events[o];if(s.fn)s.fn===r&&(!i||s.once)&&(!n||s.context===n)&&nn(this,o);else{for(var a=0,c=[],u=s.length;a<u;a++)(s[a].fn!==r||i&&!s[a].once||n&&s[a].context!==n)&&c.push(s[a]);c.length?this._events[o]=c.length===1?c[0]:c:nn(this,o)}return this};O.prototype.removeAllListeners=function(e){var r;return e?(r=M?M+e:e,this._events[r]&&nn(this,r)):(this._events=new rr,this._eventsCount=0),this};O.prototype.off=O.prototype.removeListener;O.prototype.addListener=O.prototype.on;O.prefixed=M;O.EventEmitter=O;typeof Ti<"u"&&(Ti.exports=O)});import{createReadStream as ql,createWriteStream as Oi}from"node:fs";import{lstat as Bc,mkdir as mn,open as Gl,readdir as jl,rename as Yl,rm as Kl}from"node:fs/promises";import{basename as Jl,dirname as $i,join as Cc,relative as Xl,resolve as Mi,sep as Dc}from"node:path";import{Readable as Hi,Writable as Zl}from"node:stream";import{pipeline as Vi}from"node:stream/promises";import Ru from"fs";var Lc=["Object","RegExp","Date","Error","Map","Set","WeakMap","WeakSet","ArrayBuffer","SharedArrayBuffer","DataView","Promise","URL","HTMLElement","Int8Array","Uint8ClampedArray","Int16Array","Uint16Array","Int32Array","Uint32Array","Float32Array","Float64Array","BigInt64Array","BigUint64Array","Tagged"];function pn(t){if(t===null)return"null";if(t===void 0)return"undefined";if(t===!0||t===!1)return"boolean";let e=typeof t;if(e==="string"||e==="number"||e==="bigint"||e==="symbol")return e;if(e==="function")return"Function";if(Array.isArray(t))return"Array";if(t instanceof Uint8Array)return"Uint8Array";if(t.constructor===Object)return"Object";let r=Nc(t);return r||"Object"}function Nc(t){let e=Object.prototype.toString.call(t).slice(8,-1);if(Lc.includes(e))return e}var l=class{constructor(e,r,n){this.major=e,this.majorEncoded=e<<5,this.name=r,this.terminal=n}toString(){return`Type[${this.major}].${this.name}`}compare(e){return this.major<e.major?-1:this.major>e.major?1:0}static equals(e,r){return e===r||e.major===r.major&&e.name===r.name}};l.uint=new l(0,"uint",!0);l.negint=new l(1,"negint",!0);l.bytes=new l(2,"bytes",!0);l.string=new l(3,"string",!0);l.array=new l(4,"array",!1);l.map=new l(5,"map",!1);l.tag=new l(6,"tag",!1);l.float=new l(7,"float",!0);l.false=new l(7,"false",!0);l.true=new l(7,"true",!0);l.null=new l(7,"null",!0);l.undefined=new l(7,"undefined",!0);l.break=new l(7,"break",!0);var h=class{constructor(e,r,n){this.type=e,this.value=r,this.encodedLength=n,this.encodedBytes=void 0,this.byteValue=void 0}toString(){return`Token[${this.type}].${this.value}`}};var Tt=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&typeof globalThis.Buffer.isBuffer=="function",Rc=new TextEncoder;function cr(t){return Tt&&globalThis.Buffer.isBuffer(t)}function $e(t){return t instanceof Uint8Array?cr(t)?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):t:Uint8Array.from(t)}var Uc=24,Pc=200,tt=Tt?t=>t.length>=Uc?globalThis.Buffer.from(t):Zi(t):t=>t.length>=Pc?Rc.encode(t):Zi(t),oe=t=>Uint8Array.from(t),eo=Tt?(t,e,r)=>cr(t)?new Uint8Array(t.subarray(e,r)):t.slice(e,r):(t,e,r)=>t.slice(e,r),to=Tt?(t,e)=>(t=t.map(r=>r instanceof Uint8Array?r:globalThis.Buffer.from(r)),$e(globalThis.Buffer.concat(t,e))):(t,e)=>{let r=new Uint8Array(e),n=0;for(let i of t)n+i.length>r.length&&(i=i.subarray(0,r.length-n)),r.set(i,n),n+=i.length;return r},yn=Tt?t=>globalThis.Buffer.allocUnsafe(t):t=>new Uint8Array(t);function rt(t,e){if(cr(t)&&cr(e))return t.compare(e);for(let r=0;r<t.length;r++)if(t[r]!==e[r])return t[r]<e[r]?-1:1;return 0}function Zi(t){let e=[],r=0;for(let n=0;n<t.length;n++){let i=t.charCodeAt(n);i<128?e[r++]=i:i<2048?(e[r++]=i>>6|192,e[r++]=i&63|128):(i&64512)===55296&&n+1<t.length&&(t.charCodeAt(n+1)&64512)===56320?(i=65536+((i&1023)<<10)+(t.charCodeAt(++n)&1023),e[r++]=i>>18|240,e[r++]=i>>12&63|128,e[r++]=i>>6&63|128,e[r++]=i&63|128):(i>=55296&&i<=57343&&(i=65533),e[r++]=i>>12|224,e[r++]=i>>6&63|128,e[r++]=i&63|128)}return e}var Qi=4096;function ro(t){let e=t.length;if(e<=Qi)return String.fromCharCode.apply(String,t);let r="",n=0;for(;n<e;)r+=String.fromCharCode.apply(String,t.slice(n,n+=Qi));return r}var Fc=256,vt=class{constructor(e=Fc){this.chunkSize=e,this.cursor=0,this.maxCursor=-1,this.chunks=[],this._initReuseChunk=null}reset(){this.cursor=0,this.maxCursor=-1,this.chunks.length&&(this.chunks=[]),this._initReuseChunk!==null&&(this.chunks.push(this._initReuseChunk),this.maxCursor=this._initReuseChunk.length-1)}pushByte(e){let r=this.chunks[this.chunks.length-1];this.cursor>this.maxCursor&&(r=yn(this.chunkSize),this.chunks.push(r),this.maxCursor+=r.length,this._initReuseChunk===null&&(this._initReuseChunk=r));let n=r.length-(this.maxCursor-this.cursor)-1;r[n]=e,this.cursor++}push(e){let r=this.chunks[this.chunks.length-1];if(this.cursor+e.length<=this.maxCursor+1){let i=r.length-(this.maxCursor-this.cursor)-1;r.set(e,i)}else{if(r){let i=r.length-(this.maxCursor-this.cursor)-1;i<r.length&&(this.chunks[this.chunks.length-1]=r.subarray(0,i),this.maxCursor=this.cursor-1)}e.length<64&&e.length<this.chunkSize?(r=yn(this.chunkSize),this.chunks.push(r),this.maxCursor+=r.length,this._initReuseChunk===null&&(this._initReuseChunk=r),r.set(e,0)):(this.chunks.push(e),this.maxCursor+=e.length)}this.cursor+=e.length}toBytes(e=!1){let r;if(this.chunks.length===1){let n=this.chunks[0];e&&this.cursor>n.length/2?(r=this.cursor===n.length?n:n.subarray(0,this.cursor),this._initReuseChunk=null,this.chunks=[]):r=eo(n,0,this.cursor)}else r=to(this.chunks,this.cursor);return e&&this.reset(),r}},ur=class{constructor(e){this.dest=e,this.cursor=0,this.chunks=[e]}reset(){this.cursor=0}pushByte(e){if(this.cursor>=this.dest.length)throw new Error("write out of bounds, destination buffer is too small");this.dest[this.cursor++]=e}push(e){if(this.cursor+e.length>this.dest.length)throw new Error("write out of bounds, destination buffer is too small");this.dest.set(e,this.cursor),this.cursor+=e.length}toBytes(e=!1){let r=this.dest.subarray(0,this.cursor);return e&&this.reset(),r}};var g="CBOR decode error:",Me="CBOR encode error:",Bt=[];Bt[23]=1;Bt[24]=2;Bt[25]=3;Bt[26]=5;Bt[27]=9;function de(t,e,r){if(t.length-e<r)throw new Error(`${g} not enough data for type`)}var R=[24,256,65536,4294967296,BigInt("18446744073709551616")];function q(t,e,r){de(t,e,1);let n=t[e];if(r.strict===!0&&n<R[0])throw new Error(`${g} integer encoded in more bytes than necessary (strict decode)`);return n}function G(t,e,r){de(t,e,2);let n=t[e]<<8|t[e+1];if(r.strict===!0&&n<R[1])throw new Error(`${g} integer encoded in more bytes than necessary (strict decode)`);return n}function j(t,e,r){de(t,e,4);let n=t[e]*16777216+(t[e+1]<<16)+(t[e+2]<<8)+t[e+3];if(r.strict===!0&&n<R[2])throw new Error(`${g} integer encoded in more bytes than necessary (strict decode)`);return n}function Y(t,e,r){de(t,e,8);let n=t[e]*16777216+(t[e+1]<<16)+(t[e+2]<<8)+t[e+3],i=t[e+4]*16777216+(t[e+5]<<16)+(t[e+6]<<8)+t[e+7],o=(BigInt(n)<<BigInt(32))+BigInt(i);if(r.strict===!0&&o<R[3])throw new Error(`${g} integer encoded in more bytes than necessary (strict decode)`);if(o<=Number.MAX_SAFE_INTEGER)return Number(o);if(r.allowBigInt===!0)return o;throw new Error(`${g} integers outside of the safe integer range are not supported`)}function no(t,e,r,n){return new h(l.uint,q(t,e+1,n),2)}function io(t,e,r,n){return new h(l.uint,G(t,e+1,n),3)}function oo(t,e,r,n){return new h(l.uint,j(t,e+1,n),5)}function so(t,e,r,n){return new h(l.uint,Y(t,e+1,n),9)}function se(t,e){return D(t,0,e.value)}function D(t,e,r){if(r<R[0]){let n=Number(r);t.pushByte(e|n)}else if(r<R[1]){let n=Number(r);t.push([e|24,n])}else if(r<R[2]){let n=Number(r);t.push([e|25,n>>>8,n&255])}else if(r<R[3]){let n=Number(r);t.push([e|26,n>>>24&255,n>>>16&255,n>>>8&255,n&255])}else{let n=BigInt(r);if(n<R[4]){let i=[e|27,0,0,0,0,0,0,0],o=Number(n&BigInt(4294967295)),s=Number(n>>BigInt(32)&BigInt(4294967295));i[8]=o&255,o=o>>8,i[7]=o&255,o=o>>8,i[6]=o&255,o=o>>8,i[5]=o&255,i[4]=s&255,s=s>>8,i[3]=s&255,s=s>>8,i[2]=s&255,s=s>>8,i[1]=s&255,t.push(i)}else throw new Error(`${g} encountered BigInt larger than allowable range`)}}se.encodedSize=function(e){return D.encodedSize(e.value)};D.encodedSize=function(e){return e<R[0]?1:e<R[1]?2:e<R[2]?3:e<R[3]?5:9};se.compareTokens=function(e,r){return e.value<r.value?-1:e.value>r.value?1:0};function ao(t,e,r,n){return new h(l.negint,-1-q(t,e+1,n),2)}function co(t,e,r,n){return new h(l.negint,-1-G(t,e+1,n),3)}function uo(t,e,r,n){return new h(l.negint,-1-j(t,e+1,n),5)}var gn=BigInt(-1),fo=BigInt(1);function lo(t,e,r,n){let i=Y(t,e+1,n);if(typeof i!="bigint"){let o=-1-i;if(o>=Number.MIN_SAFE_INTEGER)return new h(l.negint,o,9)}if(n.allowBigInt!==!0)throw new Error(`${g} integers outside of the safe integer range are not supported`);return new h(l.negint,gn-BigInt(i),9)}function fr(t,e){let r=e.value,n=typeof r=="bigint"?r*gn-fo:r*-1-1;D(t,e.type.majorEncoded,n)}fr.encodedSize=function(e){let r=e.value,n=typeof r=="bigint"?r*gn-fo:r*-1-1;return n<R[0]?1:n<R[1]?2:n<R[2]?3:n<R[3]?5:9};fr.compareTokens=function(e,r){return e.value<r.value?1:e.value>r.value?-1:0};function Ct(t,e,r,n){de(t,e,r+n);let i=t.slice(e+r,e+r+n);return new h(l.bytes,i,r+n)}function ho(t,e,r,n){return Ct(t,e,1,r)}function mo(t,e,r,n){return Ct(t,e,2,q(t,e+1,n))}function po(t,e,r,n){return Ct(t,e,3,G(t,e+1,n))}function yo(t,e,r,n){return Ct(t,e,5,j(t,e+1,n))}function go(t,e,r,n){let i=Y(t,e+1,n);if(typeof i=="bigint")throw new Error(`${g} 64-bit integer bytes lengths not supported`);return Ct(t,e,9,i)}function lr(t){return t.encodedBytes===void 0&&(t.encodedBytes=l.equals(t.type,l.string)?tt(t.value):t.value),t.encodedBytes}function nt(t,e){let r=lr(e);D(t,e.type.majorEncoded,r.length),t.push(r)}nt.encodedSize=function(e){let r=lr(e);return D.encodedSize(r.length)+r.length};nt.compareTokens=function(e,r){return Oc(lr(e),lr(r))};function Oc(t,e){return t.length<e.length?-1:t.length>e.length?1:rt(t,e)}var wo=new TextDecoder,Mc=32;function Hc(t,e,r){if(r-e<Mc){let i="";for(let o=e;o<r;o++){let s=t[o];if(s&128)return wo.decode(t.subarray(e,r));i+=String.fromCharCode(s)}return i}return wo.decode(t.subarray(e,r))}function Dt(t,e,r,n,i){let o=r+n;de(t,e,o);let s=new h(l.string,Hc(t,e+r,e+o),o);return i.retainStringBytes===!0&&(s.byteValue=t.slice(e+r,e+o)),s}function bo(t,e,r,n){return Dt(t,e,1,r,n)}function xo(t,e,r,n){return Dt(t,e,2,q(t,e+1,n),n)}function ko(t,e,r,n){return Dt(t,e,3,G(t,e+1,n),n)}function Eo(t,e,r,n){return Dt(t,e,5,j(t,e+1,n),n)}function _o(t,e,r,n){let i=Y(t,e+1,n);if(typeof i=="bigint")throw new Error(`${g} 64-bit integer string lengths not supported`);return Dt(t,e,9,i,n)}var Ao=nt;function it(t,e,r,n){return new h(l.array,n,r)}function Io(t,e,r,n){return it(t,e,1,r)}function So(t,e,r,n){return it(t,e,2,q(t,e+1,n))}function To(t,e,r,n){return it(t,e,3,G(t,e+1,n))}function vo(t,e,r,n){return it(t,e,5,j(t,e+1,n))}function Bo(t,e,r,n){let i=Y(t,e+1,n);if(typeof i=="bigint")throw new Error(`${g} 64-bit integer array lengths not supported`);return it(t,e,9,i)}function Co(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${g} indefinite length items not allowed`);return it(t,e,1,1/0)}function dr(t,e){D(t,l.array.majorEncoded,e.value)}dr.compareTokens=se.compareTokens;dr.encodedSize=function(e){return D.encodedSize(e.value)};function ot(t,e,r,n){return new h(l.map,n,r)}function Do(t,e,r,n){return ot(t,e,1,r)}function Lo(t,e,r,n){return ot(t,e,2,q(t,e+1,n))}function No(t,e,r,n){return ot(t,e,3,G(t,e+1,n))}function Ro(t,e,r,n){return ot(t,e,5,j(t,e+1,n))}function Uo(t,e,r,n){let i=Y(t,e+1,n);if(typeof i=="bigint")throw new Error(`${g} 64-bit integer map lengths not supported`);return ot(t,e,9,i)}function Po(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${g} indefinite length items not allowed`);return ot(t,e,1,1/0)}function hr(t,e){D(t,l.map.majorEncoded,e.value)}hr.compareTokens=se.compareTokens;hr.encodedSize=function(e){return D.encodedSize(e.value)};function Fo(t,e,r,n){return new h(l.tag,r,1)}function zo(t,e,r,n){return new h(l.tag,q(t,e+1,n),2)}function Oo(t,e,r,n){return new h(l.tag,G(t,e+1,n),3)}function $o(t,e,r,n){return new h(l.tag,j(t,e+1,n),5)}function Mo(t,e,r,n){return new h(l.tag,Y(t,e+1,n),9)}function mr(t,e){D(t,l.tag.majorEncoded,e.value)}mr.compareTokens=se.compareTokens;mr.encodedSize=function(e){return D.encodedSize(e.value)};var pr=20,yr=21,gr=22,wr=23;function Vo(t,e,r,n){if(n.allowUndefined===!1)throw new Error(`${g} undefined values are not supported`);return n.coerceUndefinedToNull===!0?new h(l.null,null,1):new h(l.undefined,void 0,1)}function Wo(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${g} indefinite length items not allowed`);return new h(l.break,void 0,1)}function wn(t,e,r){if(r){if(r.allowNaN===!1&&Number.isNaN(t))throw new Error(`${g} NaN values are not supported`);if(r.allowInfinity===!1&&(t===1/0||t===-1/0))throw new Error(`${g} Infinity values are not supported`)}return new h(l.float,t,e)}function qo(t,e,r,n){return wn(br(t,e+1),3,n)}function Go(t,e,r,n){return wn(xr(t,e+1),5,n)}function jo(t,e,r,n){return wn(Jo(t,e+1),9,n)}function Lt(t,e,r){let n=e.value;if(n===!1)t.pushByte(l.float.majorEncoded|pr);else if(n===!0)t.pushByte(l.float.majorEncoded|yr);else if(n===null)t.pushByte(l.float.majorEncoded|gr);else if(n===void 0)t.pushByte(l.float.majorEncoded|wr);else{let i,o=!1;(!r||r.float64!==!0)&&(bn(n),i=br(L,1),n===i||Number.isNaN(n)?(L[0]=249,t.push(L.slice(0,3)),o=!0):(xn(n),i=xr(L,1),n===i&&(L[0]=250,t.push(L.slice(0,5)),o=!0))),o||(Ko(n),i=Jo(L,1),L[0]=251,t.push(L.slice(0,9)))}}Lt.encodedSize=function(e,r){let n=e.value;if(n===!1||n===!0||n===null||n===void 0)return 1;if(!r||r.float64!==!0){bn(n);let i=br(L,1);if(n===i||Number.isNaN(n))return 3;if(xn(n),i=xr(L,1),n===i)return 5}return 9};var Yo=new ArrayBuffer(9),X=new DataView(Yo,1),L=new Uint8Array(Yo,0);function bn(t){if(t===1/0)X.setUint16(0,31744,!1);else if(t===-1/0)X.setUint16(0,64512,!1);else if(Number.isNaN(t))X.setUint16(0,32256,!1);else{X.setFloat32(0,t);let e=X.getUint32(0),r=(e&2139095040)>>23,n=e&8388607;if(r===255)X.setUint16(0,31744,!1);else if(r===0)X.setUint16(0,(e&2147483648)>>16|n>>13,!1);else{let i=r-127;i<-24?X.setUint16(0,0):i<-14?X.setUint16(0,(e&2147483648)>>16|1<<24+i,!1):X.setUint16(0,(e&2147483648)>>16|i+15<<10|n>>13,!1)}}}function br(t,e){if(t.length-e<2)throw new Error(`${g} not enough data for float16`);let r=(t[e]<<8)+t[e+1];if(r===31744)return 1/0;if(r===64512)return-1/0;if(r===32256)return NaN;let n=r>>10&31,i=r&1023,o;return n===0?o=i*2**-24:n!==31?o=(i+1024)*2**(n-25):o=i===0?1/0:NaN,r&32768?-o:o}function xn(t){X.setFloat32(0,t,!1)}function xr(t,e){if(t.length-e<4)throw new Error(`${g} not enough data for float32`);let r=(t.byteOffset||0)+e;return new DataView(t.buffer,r,4).getFloat32(0,!1)}function Ko(t){X.setFloat64(0,t,!1)}function Jo(t,e){if(t.length-e<8)throw new Error(`${g} not enough data for float64`);let r=(t.byteOffset||0)+e;return new DataView(t.buffer,r,8).getFloat64(0,!1)}function jc(t,e){let r=t.value;if(r===!1)return Uint8Array.of(l.float.majorEncoded|pr);if(r===!0)return Uint8Array.of(l.float.majorEncoded|yr);if(r===null)return Uint8Array.of(l.float.majorEncoded|gr);if(r===void 0)return Uint8Array.of(l.float.majorEncoded|wr);if(!e){if(bn(r),r===br(L,1)||Number.isNaN(r))return L[0]=249,L.slice(0,3);if(xn(r),r===xr(L,1))return L[0]=250,L.slice(0,5)}return Ko(r),L[0]=251,L.slice(0,9)}function Ho(t,e){let r=t,n=e?.float64===!0,i=n?r._keyBytesFloat64:r._keyBytes;if(i!==void 0)return i;let o=jc(t,n);return n?r._keyBytesFloat64=o:r._keyBytes=o,o}Lt.compareTokens=function(e,r,n){let i=Ho(e,n),o=Ho(r,n);return i.length!==o.length?i.length<o.length?-1:1:rt(i,o)};function A(t,e,r){throw new Error(`${g} encountered invalid minor (${r}) for major ${t[e]>>>5}`)}function kr(t){return()=>{throw new Error(`${g} ${t}`)}}var p=[];for(let t=0;t<=23;t++)p[t]=A;p[24]=no;p[25]=io;p[26]=oo;p[27]=so;p[28]=A;p[29]=A;p[30]=A;p[31]=A;for(let t=32;t<=55;t++)p[t]=A;p[56]=ao;p[57]=co;p[58]=uo;p[59]=lo;p[60]=A;p[61]=A;p[62]=A;p[63]=A;for(let t=64;t<=87;t++)p[t]=ho;p[88]=mo;p[89]=po;p[90]=yo;p[91]=go;p[92]=A;p[93]=A;p[94]=A;p[95]=kr("indefinite length bytes/strings are not supported");for(let t=96;t<=119;t++)p[t]=bo;p[120]=xo;p[121]=ko;p[122]=Eo;p[123]=_o;p[124]=A;p[125]=A;p[126]=A;p[127]=kr("indefinite length bytes/strings are not supported");for(let t=128;t<=151;t++)p[t]=Io;p[152]=So;p[153]=To;p[154]=vo;p[155]=Bo;p[156]=A;p[157]=A;p[158]=A;p[159]=Co;for(let t=160;t<=183;t++)p[t]=Do;p[184]=Lo;p[185]=No;p[186]=Ro;p[187]=Uo;p[188]=A;p[189]=A;p[190]=A;p[191]=Po;for(let t=192;t<=215;t++)p[t]=Fo;p[216]=zo;p[217]=Oo;p[218]=$o;p[219]=Mo;p[220]=A;p[221]=A;p[222]=A;p[223]=A;for(let t=224;t<=243;t++)p[t]=kr("simple values are not supported");p[244]=A;p[245]=A;p[246]=A;p[247]=Vo;p[248]=kr("simple values are not supported");p[249]=qo;p[250]=Go;p[251]=jo;p[252]=A;p[253]=A;p[254]=A;p[255]=Wo;var re=[];for(let t=0;t<24;t++)re[t]=new h(l.uint,t,1);for(let t=-1;t>=-24;t--)re[31-t]=new h(l.negint,t,1);re[64]=new h(l.bytes,new Uint8Array(0),1);re[96]=new h(l.string,"",1);re[128]=new h(l.array,0,1);re[160]=new h(l.map,0,1);re[244]=new h(l.false,!1,1);re[245]=new h(l.true,!0,1);re[246]=new h(l.null,null,1);function Er(t){switch(t.type){case l.false:return oe([244]);case l.true:return oe([245]);case l.null:return oe([246]);case l.bytes:return t.value.length?void 0:oe([64]);case l.string:return t.value===""?oe([96]):void 0;case l.array:return t.value===0?oe([128]):void 0;case l.map:return t.value===0?oe([160]):void 0;case l.uint:return t.value<24?oe([Number(t.value)]):void 0;case l.negint:if(t.value>=-24)return oe([31-Number(t.value)])}}var Kc={float64:!1,mapSorter:_n,quickEncodeToken:Er},ts=Object.freeze({mapSorter:Xc,quickEncodeToken:Er});function En(){let t=[];return t[l.uint.major]=se,t[l.negint.major]=fr,t[l.bytes.major]=nt,t[l.string.major]=Ao,t[l.array.major]=dr,t[l.map.major]=hr,t[l.tag.major]=mr,t[l.float.major]=Lt,t}var Ve=En(),_r=new vt,at=class t{constructor(e,r){this.obj=e,this.parent=r}includes(e){let r=this;do if(r.obj===e)return!0;while(r=r.parent);return!1}static createCheck(e,r){if(e&&e.includes(r))throw new Error(`${Me} object contains circular references`);return new t(r,e)}},ge={null:new h(l.null,null),undefined:new h(l.undefined,void 0),true:new h(l.true,!0),false:new h(l.false,!1),emptyArray:new h(l.array,0),emptyMap:new h(l.map,0)},ae={number(t,e,r,n){return!Number.isInteger(t)||!Number.isSafeInteger(t)?new h(l.float,t):t>=0?new h(l.uint,t):new h(l.negint,t)},bigint(t,e,r,n){return t>=BigInt(0)?new h(l.uint,t):new h(l.negint,t)},Uint8Array(t,e,r,n){return new h(l.bytes,t)},string(t,e,r,n){return new h(l.string,t)},boolean(t,e,r,n){return t?ge.true:ge.false},null(t,e,r,n){return ge.null},undefined(t,e,r,n){return ge.undefined},ArrayBuffer(t,e,r,n){return new h(l.bytes,new Uint8Array(t))},DataView(t,e,r,n){return new h(l.bytes,new Uint8Array(t.buffer,t.byteOffset,t.byteLength))},Array(t,e,r,n){if(!t.length)return r.addBreakTokens===!0?[ge.emptyArray,new h(l.break)]:ge.emptyArray;n=at.createCheck(n,t);let i=[],o=0;for(let s of t)i[o++]=be(s,r,n);return r.addBreakTokens?[new h(l.array,t.length),i,new h(l.break)]:[new h(l.array,t.length),i]},Object(t,e,r,n){let i=e!=="Object",o=i?t.keys():Object.keys(t),s=i?t.size:o.length,a;if(s){a=new Array(s),n=at.createCheck(n,t);let c=!i&&r.ignoreUndefinedProperties,u=0;for(let f of o){let d=i?t.get(f):t[f];c&&d===void 0||(a[u++]=[be(f,r,n),be(d,r,n)])}u<s&&(a.length=u)}return a?.length?(Jc(a,r),r.addBreakTokens?[new h(l.map,a.length),a,new h(l.break)]:[new h(l.map,a.length),a]):r.addBreakTokens===!0?[ge.emptyMap,new h(l.break)]:ge.emptyMap},Tagged(t,e,r,n){return[new h(l.tag,t.tag),be(t.value,r,n)]}};ae.Map=ae.Object;ae.Buffer=ae.Uint8Array;for(let t of"Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" "))ae[`${t}Array`]=ae.DataView;function be(t,e={},r){let n=pn(t),i=e&&e.typeEncoders&&e.typeEncoders[n]||ae[n];if(typeof i=="function"){let s=i(t,n,e,r);if(s!=null)return s}let o=ae[n];if(!o)throw new Error(`${Me} unsupported type: ${n}`);return o(t,n,e,r)}function Jc(t,e){let r=e.mapSorter;r&&t.sort((n,i)=>r(n,i,e))}function _n(t,e,r){let n=Array.isArray(t[0])?t[0][0]:t[0],i=Array.isArray(e[0])?e[0][0]:e[0];if(n.type.major!==i.type.major)return n.type.compare(i.type);let o=n.type.major,s=Ve[o].compareTokens(n,i,r);return s===0&&console.warn("WARNING: complex key types used, CBOR key sorting guarantees are gone"),s}function Xc(t,e){if(t[0]instanceof h&&e[0]instanceof h){let r=t[0],n=e[0];return r._keyBytes||(r._keyBytes=Xo(r.value)),n._keyBytes||(n._keyBytes=Xo(n.value)),rt(r._keyBytes,n._keyBytes)}throw new Error("rfc8949MapSorter: complex key types are not supported yet")}function Xo(t){return In(t,Ve,ts)}function st(t,e,r,n){if(Array.isArray(e))for(let i of e)st(t,i,r,n);else r[e.type.major](t,e,n)}var Zo=l.uint.majorEncoded,Qo=l.negint.majorEncoded,Zc=l.bytes.majorEncoded,Qc=l.string.majorEncoded,es=l.array.majorEncoded,kn=l.map.majorEncoded,eu=l.float.majorEncoded|pr,tu=l.float.majorEncoded|yr,ru=l.float.majorEncoded|gr,nu=l.float.majorEncoded|wr,iu=BigInt(-1),ou=BigInt(1);function we(t,e,r){r<24?t.pushByte(e|Number(r)):D(t,e,r)}function su(t){return t.addBreakTokens!==!0}function au(t,e,r,n,i){let o=r==="Map",s=o?e.keys():Object.keys(e),a=o?e.size:s.length;if(!a){t.pushByte(kn);return}i=at.createCheck(i,e);let c=!o&&n.ignoreUndefinedProperties,u=new Array(a),f=0;for(let d of s){let m=o?e.get(d):e[d];c&&m===void 0||(u[f++]=[be(d,n,i),m])}if(f===0){t.pushByte(kn);return}f<a&&(u.length=f),u.sort((d,m)=>_n(d,m,n)),we(t,kn,f);for(let[d,m]of u)st(t,d,Ve,n),An(t,m,n,i)}function An(t,e,r,n){let i=pn(e),o=r.typeEncoders&&r.typeEncoders[i];if(o){let s=o(e,i,r,n);if(s!=null){st(t,s,Ve,r);return}}switch(i){case"null":t.pushByte(ru);return;case"undefined":t.pushByte(nu);return;case"boolean":t.pushByte(e?tu:eu);return;case"number":!Number.isInteger(e)||!Number.isSafeInteger(e)?Lt(t,new h(l.float,e),r):e>=0?we(t,Zo,e):we(t,Qo,e*-1-1);return;case"bigint":e>=BigInt(0)?we(t,Zo,e):we(t,Qo,e*iu-ou);return;case"string":{let s=tt(e);we(t,Qc,s.length),t.push(s);return}case"Uint8Array":we(t,Zc,e.length),t.push(e);return;case"Array":if(!e.length){t.pushByte(es);return}n=at.createCheck(n,e),we(t,es,e.length);for(let s of e)An(t,s,r,n);return;case"Object":case"Map":if(r.mapSorter===_n)au(t,e,i,r,n);else{let s=ae.Object(e,i,r,n);st(t,s,Ve,r)}return;default:{let s=ae[i];if(!s)throw new Error(`${Me} unsupported type: ${i}`);let a=s(e,i,r,n);st(t,a,Ve,r)}}}function In(t,e,r,n){let i=n instanceof Uint8Array,o=i?new ur(n):_r,s=be(t,r);if(!Array.isArray(s)&&r.quickEncodeToken){let a=r.quickEncodeToken(s);if(a)return i?(o.push(a),o.toBytes()):a;let c=e[s.type.major];if(c.encodedSize){let u=c.encodedSize(s,r);if(i||(o=new vt(u)),c(o,s,r),o.chunks.length!==1)throw new Error(`Unexpected error: pre-calculated length for ${s} was wrong`);return i?o.toBytes():$e(o.chunks[0])}}return o.reset(),st(o,s,e,r),o.toBytes(!0)}function Sn(t,e){return e=Object.assign({},Kc,e),su(e)?(_r.reset(),An(_r,t,e,void 0),_r.toBytes(!0)):In(t,Ve,e)}var cu={strict:!1,allowIndefinite:!0,allowUndefined:!0,allowBigInt:!0},Ar=class{constructor(e,r={}){this._pos=0,this.data=e,this.options=r}pos(){return this._pos}done(){return this._pos>=this.data.length}next(){let e=this.data[this._pos],r=re[e];if(r===void 0){let n=p[e];if(!n)throw new Error(`${g} no decoder for major type ${e>>>5} (byte 0x${e.toString(16).padStart(2,"0")})`);let i=e&31;r=n(this.data,this._pos,i,this.options)}return this._pos+=r.encodedLength,r}},xe=Symbol.for("DONE"),ct=Symbol.for("BREAK");function uu(t,e,r){let n=[];for(let i=0;i<t.value;i++){let o=ke(e,r);if(o===ct){if(t.value===1/0)break;throw new Error(`${g} got unexpected break to lengthed array`)}if(o===xe)throw new Error(`${g} found array but not enough entries (got ${i}, expected ${t.value})`);n[i]=o}return n}function fu(t,e,r){let n=r.useMaps===!0,i=r.rejectDuplicateMapKeys===!0,o=n?void 0:{},s=n?new Map:void 0;for(let a=0;a<t.value;a++){let c=ke(e,r);if(c===ct){if(t.value===1/0)break;throw new Error(`${g} got unexpected break to lengthed map`)}if(c===xe)throw new Error(`${g} found map but not enough entries (got ${a} [no key], expected ${t.value})`);if(!n&&typeof c!="string")throw new Error(`${g} non-string keys not supported (got ${typeof c})`);if(i&&(n&&s.has(c)||!n&&Object.hasOwn(o,c)))throw new Error(`${g} found repeat map key "${c}"`);let u=ke(e,r);if(u===xe)throw new Error(`${g} found map but not enough entries (got ${a} [no value], expected ${t.value})`);n?s.set(c,u):c==="__proto__"?Object.defineProperty(o,c,{value:u,configurable:!0,enumerable:!0,writable:!0}):o[c]=u}return n?s:o}function*lu(t,e,r){for(let n=0;n<t.value;n++){let i=ke(e,r);if(i===ct){if(t.value===1/0)break;throw new Error(`${g} got unexpected break to lengthed map`)}if(i===xe)throw new Error(`${g} found map but not enough entries (got ${n} [no key], expected ${t.value})`);let o=ke(e,r);if(o===xe)throw new Error(`${g} found map but not enough entries (got ${n} [no value], expected ${t.value})`);yield[i,o]}}function du(t,e){let r=function(){if(r._called)throw new Error(`${g} tag decode() may only be called once`);r._called=!0;let n=ke(t,e);if(n===xe)throw new Error(`${g} tag content missing`);if(n===ct)throw new Error(`${g} got unexpected break in tag content`);return n};return r.entries=function(){if(r._called)throw new Error(`${g} tag decode() may only be called once`);r._called=!0;let n=t.next();if(!l.equals(n.type,l.map))throw new Error(`${g} entries() requires map content, got ${n.type.name}`);let i=[];for(let o of lu(n,t,e))i.push(o);return i},r._called=!1,r}function ke(t,e){if(t.done())return xe;let r=t.next();if(l.equals(r.type,l.break))return ct;if(r.type.terminal)return r.value;if(l.equals(r.type,l.array))return uu(r,t,e);if(l.equals(r.type,l.map))return fu(r,t,e);if(l.equals(r.type,l.tag)){if(e.tags&&typeof e.tags[r.value]=="function"){let n=du(t,e),i=e.tags[r.value](n);if(!n._called)throw new Error(`${g} tag decoder must call decode() or entries()`);return i}throw new Error(`${g} tag not supported (${r.value})`)}throw new Error("unsupported")}function Tn(t,e){if(!(t instanceof Uint8Array))throw new Error(`${g} data to decode must be a Uint8Array`);e=Object.assign({},cu,e);let r=$e(t),n=e.tokenizer||new Ar(r,e),i=ke(n,e);if(i===xe)throw new Error(`${g} did not find any content to decode`);if(i===ct)throw new Error(`${g} got unexpected break`);return[i,t.subarray(n.pos())]}function Nt(t,e){let[r,n]=Tn(t,e);if(n.length>0)throw new Error(`${g} too many terminals, data makes no sense`);return r}var Ir=class t{constructor(e,r){if(typeof e!="number"||!Number.isInteger(e)||e<0)throw new TypeError("Tagged: tag must be a non-negative integer");this.tag=e,this.value=r}static decoder(e){return r=>new t(e,r())}static preserve(...e){let r={};for(let n of e)r[n]=t.decoder(n);return r}};Object.defineProperty(Ir.prototype,Symbol.toStringTag,{value:"Tagged"});var rs=42;function mu(t){return t instanceof ArrayBuffer?new Uint8Array(t,0,t.byteLength):t}function pu(t){if(t.asCID!==t&&t["/"]!==t.bytes)return null;let e=k.asCID(t);if(!e)return null;let r=new Uint8Array(e.bytes.byteLength+1);return r.set(e.bytes,1),[new h(l.tag,rs),new h(l.bytes,r)]}function yu(){throw new Error("`undefined` is not supported by the IPLD Data Model and cannot be encoded")}function gu(t){if(Number.isNaN(t))throw new Error("`NaN` is not supported by the IPLD Data Model and cannot be encoded");if(t===1/0||t===-1/0)throw new Error("`Infinity` and `-Infinity` is not supported by the IPLD Data Model and cannot be encoded");return null}function wu(t){for(let e of t.keys())if(typeof e!="string"||e.length===0)throw new Error("Non-string Map keys are not supported by the IPLD Data Model and cannot be encoded");return null}var vn={float64:!0,typeEncoders:{Map:wu,Object:pu,undefined:yu,number:gu}},sh={...vn,typeEncoders:{...vn.typeEncoders}};function bu(t){let e=t();if(e[0]!==0)throw new Error("Invalid CID for CBOR tag 42; expected leading 0x00");return k.decode(e.subarray(1))}var Bn={allowIndefinite:!1,coerceUndefinedToNull:!0,allowNaN:!1,allowInfinity:!1,allowBigInt:!0,strict:!0,useMaps:!1,rejectDuplicateMapKeys:!0,tags:{[rs]:bu}},ah={...Bn,tags:{...Bn.tags}};var Sr=113,Cn=t=>Sn(t,vn),We=t=>Nt(mu(t),Bn);var Ee=At(Tr(),1),Ut={SHA2_256:18,LENGTH:32,DAG_PB:112},Nn=40;function ut(t,e){if(!t.length)throw new Error("Unexpected end of data");let r=Ee.default.decode(t);return e.seek(Ee.default.decode.bytes),r}function Rn(t){let e=new DataView(t.buffer,t.byteOffset,t.byteLength),r=0;return{version:2,characteristics:[e.getBigUint64(r,!0),e.getBigUint64(r+=8,!0)],dataOffset:Number(e.getBigUint64(r+=8,!0)),dataSize:Number(e.getBigUint64(r+=8,!0)),indexOffset:Number(e.getBigUint64(r+=8,!0))}}function Un(t){Ee.default.decode(t);let e=Ee.default.decode.bytes,r=Ee.default.decode(t.subarray(Ee.default.decode.bytes)),n=Ee.default.decode.bytes;return e+n+r}var _e={Null:t=>t===null?t:void 0,Int:t=>Number.isInteger(t)?t:void 0,Float:t=>typeof t=="number"&&Number.isFinite(t)?t:void 0,String:t=>typeof t=="string"?t:void 0,Bool:t=>typeof t=="boolean"?t:void 0,Bytes:t=>t instanceof Uint8Array?t:void 0,Link:t=>t!==null&&typeof t=="object"&&t.asCID===t?t:void 0,List:t=>Array.isArray(t)?t:void 0,Map:t=>t!==null&&typeof t=="object"&&t.asCID!==t&&!Array.isArray(t)&&!(t instanceof Uint8Array)?t:void 0},Pt={"CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)":_e.Link,"CarV1HeaderOrV2Pragma > roots (anon)":t=>{if(_e.List(t)!==void 0){for(let e=0;e<t.length;e++){let r=t[e];if(r=Pt["CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)"](r),r===void 0)return;if(r!==t[e]){let n=t.slice(0,e);for(let i=e;i<t.length;i++){let o=t[i];if(o=Pt["CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)"](o),o===void 0)return;n.push(o)}return n}}return t}},Int:_e.Int,CarV1HeaderOrV2Pragma:t=>{if(_e.Map(t)===void 0)return;let e=Object.entries(t),r=t,n=1;for(let i=0;i<e.length;i++){let[o,s]=e[i];switch(o){case"roots":{let a=Pt["CarV1HeaderOrV2Pragma > roots (anon)"](t[o]);if(a===void 0)return;if(a!==s||r!==t){if(r===t){r={};for(let c=0;c<i;c++)r[e[c][0]]=e[c][1]}r.roots=a}}break;case"version":{n--;let a=Pt.Int(t[o]);if(a===void 0)return;if(a!==s||r!==t){if(r===t){r={};for(let c=0;c<i;c++)r[e[c][0]]=e[c][1]}r.version=a}}break;default:return}}if(!(n>0))return r}},Ft={"CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)":_e.Link,"CarV1HeaderOrV2Pragma > roots (anon)":t=>{if(_e.List(t)!==void 0){for(let e=0;e<t.length;e++){let r=t[e];if(r=Ft["CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)"](r),r===void 0)return;if(r!==t[e]){let n=t.slice(0,e);for(let i=e;i<t.length;i++){let o=t[i];if(o=Ft["CarV1HeaderOrV2Pragma > roots (anon) > valueType (anon)"](o),o===void 0)return;n.push(o)}return n}}return t}},Int:_e.Int,CarV1HeaderOrV2Pragma:t=>{if(_e.Map(t)===void 0)return;let e=Object.entries(t),r=t,n=1;for(let i=0;i<e.length;i++){let[o,s]=e[i];switch(o){case"roots":{let a=Ft["CarV1HeaderOrV2Pragma > roots (anon)"](s);if(a===void 0)return;if(a!==s||r!==t){if(r===t){r={};for(let c=0;c<i;c++)r[e[c][0]]=e[c][1]}r.roots=a}}break;case"version":{n--;let a=Ft.Int(s);if(a===void 0)return;if(a!==s||r!==t){if(r===t){r={};for(let c=0;c<i;c++)r[e[c][0]]=e[c][1]}r.version=a}}break;default:return}}if(!(n>0))return r}},Pn={toTyped:Pt.CarV1HeaderOrV2Pragma,toRepresentation:Ft.CarV1HeaderOrV2Pragma};var _h=Ru.readSync;var Th=En();var Uu=At(Tr(),1);var Lh=[new h(l.map,2),new h(l.string,"version"),new h(l.uint,1),new h(l.string,"roots")],Nh=new h(l.tag,42);import ws from"fs";import{Readable as Hu}from"stream";async function ft(t,e){let r=ut(await t.upTo(8),t);if(r===0)throw new Error("Invalid CAR header (zero length)");let n=await t.exactly(r,!0),i=We(n);if(Pn.toTyped(i)===void 0)throw new Error("Invalid CAR header format");if(i.version!==1&&i.version!==2||e!==void 0&&i.version!==e)throw new Error(`Invalid CAR version: ${i.version}${e!==void 0?` (expected ${e})`:""}`);if(i.version===1){if(!Array.isArray(i.roots))throw new Error("Invalid CAR header format");return i}if(i.roots!==void 0)throw new Error("Invalid CAR header format");let o=Rn(await t.exactly(Nn,!0));t.seek(o.dataOffset-t.pos);let s=await ft(t,1);return Object.assign(s,o)}async function Fu(t){let e=await t.exactly(2,!1);if(e[0]===Ut.SHA2_256&&e[1]===Ut.LENGTH){let s=await t.exactly(34,!0),a=et(s);return k.create(0,Ut.DAG_PB,a)}let r=ut(await t.upTo(8),t);if(r!==1)throw new Error(`Unexpected CID version (${r})`);let n=ut(await t.upTo(8),t),i=await t.exactly(Un(await t.upTo(8)),!0),o=et(i);return k.create(r,n,o)}async function ds(t){let e=t.pos,r=ut(await t.upTo(8),t);if(r===0)throw new Error("Invalid CAR section (zero length)");r+=t.pos-e;let n=await Fu(t),i=r-Number(t.pos-e);return{cid:n,length:r,blockLength:i}}async function zu(t){let{cid:e,blockLength:r}=await ds(t);return{bytes:await t.exactly(r,!0),cid:e}}async function Ou(t){let e=t.pos,{cid:r,length:n,blockLength:i}=await ds(t),o={cid:r,length:n,blockLength:i,offset:e,blockOffset:t.pos};return t.seek(o.blockLength),o}function Ot(t){let e=(async()=>{let r=await ft(t);if(r.version===2){let n=t.pos-r.dataOffset;t=$u(t,r.dataSize-n)}return r})();return{header:()=>e,async*blocks(){for(await e;(await t.upTo(8)).length>0;)yield await zu(t)},async*blocksIndex(){for(await e;(await t.upTo(8)).length>0;)yield await Ou(t)}}}function qe(t){let e=0;return{async upTo(r){return t.subarray(e,e+Math.min(r,t.length-e))},async exactly(r,n=!1){if(r>t.length-e)throw new Error("Unexpected end of data");let i=t.subarray(e,e+r);return n&&(e+=r),i},seek(r){e+=r},get pos(){return e}}}function Fn(t){let e=0,r=0,n=0,i=new Uint8Array(0),o=async s=>{r=i.length-n;let a=[i.subarray(n)];for(;r<s;){let u=await t();if(u==null)break;r<0?u.length>r&&a.push(u.subarray(-r)):a.push(u),r+=u.length}i=new Uint8Array(a.reduce((u,f)=>u+f.length,0));let c=0;for(let u of a)i.set(u,c),c+=u.length;n=0};return{async upTo(s){return i.length-n<s&&await o(s),i.subarray(n,n+Math.min(i.length-n,s))},async exactly(s,a=!1){if(i.length-n<s&&await o(s),i.length-n<s)throw new Error("Unexpected end of data");let c=i.subarray(n,n+s);return a&&(e+=s,n+=s),c},seek(s){e+=s,n+=s},get pos(){return e}}}function $t(t){let e=t[Symbol.asyncIterator]();async function r(){let n=await e.next();return n.done?null:n.value}return Fn(r)}function $u(t,e){let r=0;return{async upTo(n){let i=await t.upTo(n);return i.length+r>e&&(i=i.subarray(0,e-r)),i},async exactly(n,i=!1){let o=await t.exactly(n,i);if(o.length+r>e)throw new Error("Unexpected end of data");return i&&(r+=n),o},seek(n){r+=n,t.seek(n)},get pos(){return t.pos}}}var lt=class{constructor(e,r,n){this._version=e,this._roots=r,this._iterator=n}get version(){return this._version}async getRoots(){return this._roots}[Symbol.asyncIterator](){return this._iterator}static async fromBytes(e){if(!(e instanceof Uint8Array))throw new TypeError("fromBytes() requires a Uint8Array");return hs(qe(e))}static async fromIterable(e){if(!e||typeof e[Symbol.asyncIterator]!="function")throw new TypeError("fromIterable() requires an async iterable");return hs($t(e))}};async function hs(t){let e=Ot(t),{version:r,roots:n}=await e.header();return new lt(r,n,e.blocksIndex())}import ms from"fs";import{promisify as ps}from"util";var zn;function vr(t,e,r,n,i){return zn||(zn=ps(ms.read)),zn(t,e,r,n,i)}var On;function ys(t,e,r,n,i){return On||(On=ps(ms.write)),On(t,e,r,n,i)}var Mt=class{constructor(e,r){this._header=e,this._blocks=r,this._keys=r.map(n=>n.cid.toString())}get version(){return this._header.version}async getRoots(){return this._header.roots}async has(e){return this._keys.indexOf(e.toString())>-1}async get(e){let r=this._keys.indexOf(e.toString());return r>-1?this._blocks[r]:void 0}async*blocks(){for(let e of this._blocks)yield e}async*cids(){for(let e of this._blocks)yield e.cid}static async fromBytes(e){if(!(e instanceof Uint8Array))throw new TypeError("fromBytes() requires a Uint8Array");return gs(qe(e))}static async fromIterable(e){if(!e||typeof e[Symbol.asyncIterator]!="function")throw new TypeError("fromIterable() requires an async iterable");return gs($t(e))}};async function gs(t){let e=Ot(t),r=await e.header(),n=[];for await(let i of e.blocks())n.push(i);return new Mt(r,n)}var Ht=class extends Mt{static async readRaw(e,r){let{cid:n,blockLength:i,blockOffset:o}=r,s=new Uint8Array(i),a;if(typeof e=="number")a=(await vr(e,s,0,i,o)).bytesRead;else if(typeof e=="object"&&typeof e.read=="function")a=(await e.read(s,0,i,o)).bytesRead;else throw new TypeError("Bad fd");if(a!==i)throw new Error(`Failed to read entire block (${a} instead of ${i})`);return{cid:n,bytes:s}}};var Vt=class t{constructor(e,r,n,i,o){this._version=e,this._path=r,this._roots=n,this._index=i,this._order=o,this._fd=null}get version(){return this._version}async getRoots(){return this._roots}async has(e){return this._index.has(e.toString())}async get(e){let r=this._index.get(e.toString());if(!r)return;this._fd||(this._fd=await ws.promises.open(this._path,"r"));let n={cid:e,length:0,offset:0,blockLength:r.blockLength,blockOffset:r.blockOffset};return Ht.readRaw(this._fd,n)}async*blocks(){for(let e of this._order){let r=await this.get(k.parse(e));if(!r)throw new Error("Unexpected internal error");yield r}}async*cids(){for(let e of this._order)yield k.parse(e)}async close(){if(this._fd)return this._fd.close()}static async fromFile(e){if(typeof e!="string")throw new TypeError("fromFile() requires a file path string");let r=await lt.fromIterable(Hu.from(ws.createReadStream(e))),n=new Map,i=[];for await(let{cid:o,blockLength:s,blockOffset:a}of r){let c=o.toString();n.set(c,{blockLength:s,blockOffset:a}),i.push(c)}return new t(r.version,e,await r.getRoots(),n,i)}};var $n=At(Tr(),1),bs=1;function Wt(t){let e=Cn({version:bs,roots:t}),r=$n.default.encode(e.length),n=new Uint8Array(r.length+e.length);return n.set(r,0),n.set(e,r.length),n}function xs(t){return{async setRoots(e){let r=Wt(e);await t.write(r)},async writeBlock(e){let{cid:r,bytes:n}=e;await t.write(new Uint8Array($n.default.encode(r.bytes.length+n.length))),await t.write(r.bytes),n.length&&await t.write(n)},async close(){await t.end()},version(){return bs}}}function Br(){}function ks(){let t=[],e=null,r=Br,n=!1,i=null,o=Br,s=()=>(e||(e=new Promise(u=>{r=()=>{e=null,r=Br,u()}})),e),a={write(u){t.push(u);let f=s();return o(),f},async end(){n=!0;let u=s();o(),await u}},c={async next(){let u=t.shift();return u?(t.length===0&&r(),{done:!1,value:u}):n?(r(),{done:!0,value:void 0}):(i||(i=new Promise(f=>{o=()=>(i=null,o=Br,f(c.next()))})),i)}};return{writer:a,iterator:c}}var Cr=class t{constructor(e,r){this._encoder=r,this._mutex=r.setRoots(e),this._ended=!1}async put(e){if(!(e.bytes instanceof Uint8Array)||!e.cid)throw new TypeError("Can only write {cid, bytes} objects");if(this._ended)throw new Error("Already closed");let r=k.asCID(e.cid);if(!r)throw new TypeError("Can only write {cid, bytes} objects");return this._mutex=this._mutex.then(()=>this._encoder.writeBlock({cid:r,bytes:e.bytes})),this._mutex}async close(){if(this._ended)throw new Error("Already closed");return await this._mutex,this._ended=!0,this._encoder.close()}version(){return this._encoder.version()}static create(e){e=Vu(e);let{encoder:r,iterator:n}=Es(),i=new t(e,r),o=new Dr(n);return{writer:i,out:o}}static createAppender(){let{encoder:e,iterator:r}=Es();e.setRoots=()=>Promise.resolve();let n=new t([],e),i=new Dr(r);return{writer:n,out:i}}static async updateRootsInBytes(e,r){let n=qe(e);await ft(n);let i=Wt(r);if(Number(n.pos)!==i.length)throw new Error(`updateRoots() can only overwrite a header of the same length (old header is ${n.pos} bytes, new header is ${i.length} bytes)`);return e.set(i,0),e}},Dr=class{constructor(e){this._iterator=e}[Symbol.asyncIterator](){if(this._iterating)throw new Error("Multiple iterator not supported");return this._iterating=!0,this._iterator}};function Es(){let t=ks(),{writer:e,iterator:r}=t;return{encoder:xs(e),iterator:r}}function Vu(t){if(t===void 0)return[];if(!Array.isArray(t)){let r=k.asCID(t);if(!r)throw new TypeError("roots must be a single CID or an array of CIDs");return[r]}let e=[];for(let r of t){let n=k.asCID(r);if(!n)throw new TypeError("roots must be a single CID or an array of CIDs");e.push(n)}return e}var dt=class extends Cr{static async updateRootsInFile(e,r){let i,o=0,s;if(typeof e=="number")s=async()=>(await vr(e,i,0,256,o)).bytesRead;else if(typeof e=="object"&&typeof e.read=="function")s=async()=>(await e.read(i,0,256,o)).bytesRead;else throw new TypeError("Bad fd");let a=Fn(async()=>{i=new Uint8Array(256);let u=await s();return o+=u,u<256?i.subarray(0,u):i});await ft(a);let c=Wt(r);if(a.pos!==c.length)throw new Error(`updateRoots() can only overwrite a header of the same length (old header is ${a.pos} bytes, new header is ${c.length} bytes)`);typeof e=="number"?await ys(e,c,0,c.length,0):typeof e=="object"&&typeof e.read=="function"&&await e.write(c,0,c.length,0)}};var ht=class t extends Error{static name="BadPathError";static code="ERR_BAD_PATH";name=t.name;code=t.code;constructor(e="Bad path"){super(e)}},H=class t extends Error{static name="NotFoundError";static code="ERR_NOT_FOUND";name=t.name;code=t.code;constructor(e="Not found"){super(e)}},mt=class t extends Error{static name="NoResolverError";static code="ERR_NO_RESOLVER";name=t.name;code=t.code;constructor(e="No resolver"){super(e)}},v=class t extends Error{static name="NotUnixFSError";static code="ERR_NOT_UNIXFS";name=t.name;code=t.code;constructor(e="Not UnixFS"){super(e)}},Lr=class t extends Error{static name="OverReadError";static code="ERR_OVER_READ";name=t.name;code=t.code;constructor(e="Over read"){super(e)}},Nr=class t extends Error{static name="UnderReadError";static code="ERR_UNDER_READ";name=t.name;code=t.code;constructor(e="Under read"){super(e)}},he=class t extends Error{static name="InvalidParametersError";static code="ERR_INVALID_PARAMS";name=t.name;code=t.code;constructor(e="Invalid parameters"){super(e)}};var _s=class extends Array{constructor(){super(),this.inRecursive=[]}prefix(e){let r=this.inRecursive[this.inRecursive.length-1];r&&(l.equals(r.type,l.array)&&(r.elements++,r.elements!==1&&e.push([44])),l.equals(r.type,l.map)&&(r.elements++,r.elements!==1&&(r.elements%2===1?e.push([44]):e.push([58]))))}[l.uint.major](e,r){this.prefix(e);let n=String(r.value),i=[];for(let o=0;o<n.length;o++)i[o]=n.charCodeAt(o);e.push(i)}[l.negint.major](e,r){this[l.uint.major](e,r)}[l.bytes.major](e,r){throw new Error(`${Me} unsupported type: Uint8Array`)}[l.string.major](e,r){this.prefix(e);let n=tt(JSON.stringify(r.value));e.push(n.length>32?$e(n):n)}[l.array.major](e,r){this.prefix(e),this.inRecursive.push({type:l.array,elements:0}),e.push([91])}[l.map.major](e,r){this.prefix(e),this.inRecursive.push({type:l.map,elements:0}),e.push([123])}[l.tag.major](e,r){}[l.float.major](e,r){if(r.type.name==="break"){let s=this.inRecursive.pop();if(s){if(l.equals(s.type,l.array))e.push([93]);else if(l.equals(s.type,l.map))e.push([125]);else throw new Error("Unexpected recursive type; this should not happen!");return}throw new Error("Unexpected break; this should not happen!")}if(r.value===void 0)throw new Error(`${Me} unsupported type: undefined`);if(this.prefix(e),r.type.name==="true"){e.push([116,114,117,101]);return}else if(r.type.name==="false"){e.push([102,97,108,115,101]);return}else if(r.type.name==="null"){e.push([110,117,108,108]);return}let n=String(r.value),i=[],o=!1;for(let s=0;s<n.length;s++)i[s]=n.charCodeAt(s),!o&&(i[s]===46||i[s]===101||i[s]===69)&&(o=!0);o||(i.push(46),i.push(48)),e.push(i)}};var pt=class{constructor(e,r={}){this._pos=0,this.data=e,this.options=r,this.modeStack=["value"],this.lastToken=""}pos(){return this._pos}done(){return this._pos>=this.data.length}ch(){return this.data[this._pos]}currentMode(){return this.modeStack[this.modeStack.length-1]}skipWhitespace(){let e=this.ch();for(;e===32||e===9||e===13||e===10;)e=this.data[++this._pos]}expect(e){if(this.data.length-this._pos<e.length)throw new Error(`${g} unexpected end of input at position ${this._pos}`);for(let r=0;r<e.length;r++)if(this.data[this._pos++]!==e[r])throw new Error(`${g} unexpected token at position ${this._pos}, expected to find '${String.fromCharCode(...e)}'`)}parseNumber(){let e=this._pos,r=!1,n=!1,i=a=>{for(;!this.done();){let c=this.ch();if(a.includes(c))this._pos++;else break}};if(this.ch()===45&&(r=!0,this._pos++),this.ch()===48)if(this._pos++,this.ch()===46)this._pos++,n=!0;else return new h(l.uint,0,this._pos-e);if(i([48,49,50,51,52,53,54,55,56,57]),r&&this._pos===e+1)throw new Error(`${g} unexpected token at position ${this._pos}`);if(!this.done()&&this.ch()===46){if(n)throw new Error(`${g} unexpected token at position ${this._pos}`);n=!0,this._pos++,i([48,49,50,51,52,53,54,55,56,57])}!this.done()&&(this.ch()===101||this.ch()===69)&&(n=!0,this._pos++,!this.done()&&(this.ch()===43||this.ch()===45)&&this._pos++,i([48,49,50,51,52,53,54,55,56,57]));let o=String.fromCharCode.apply(null,this.data.subarray(e,this._pos)),s=parseFloat(o);return n?new h(l.float,s,this._pos-e):this.options.allowBigInt!==!0||Number.isSafeInteger(s)?new h(s>=0?l.uint:l.negint,s,this._pos-e):new h(s>=0?l.uint:l.negint,BigInt(o),this._pos-e)}parseString(){if(this.ch()!==34)throw new Error(`${g} unexpected character at position ${this._pos}; this shouldn't happen`);this._pos++;for(let o=this._pos,s=0;o<this.data.length&&s<65536;o++,s++){let a=this.data[o];if(a===92||a<32||a>=128)break;if(a===34){let c=String.fromCharCode.apply(null,this.data.subarray(this._pos,o));return this._pos=o+1,new h(l.string,c,s)}}let e=this._pos,r=[],n=()=>{if(this._pos+4>=this.data.length)throw new Error(`${g} unexpected end of unicode escape sequence at position ${this._pos}`);let o=0;for(let s=0;s<4;s++){let a=this.ch();if(a>=48&&a<=57)a-=48;else if(a>=97&&a<=102)a=a-97+10;else if(a>=65&&a<=70)a=a-65+10;else throw new Error(`${g} unexpected unicode escape character at position ${this._pos}`);o=o*16+a,this._pos++}return o},i=()=>{let o=this.ch(),s=null,a=o>239?4:o>223?3:o>191?2:1;if(this._pos+a>this.data.length)throw new Error(`${g} unexpected unicode sequence at position ${this._pos}`);let c,u,f,d;switch(a){case 1:o<128&&(s=o);break;case 2:c=this.data[this._pos+1],(c&192)===128&&(d=(o&31)<<6|c&63,d>127&&(s=d));break;case 3:c=this.data[this._pos+1],u=this.data[this._pos+2],(c&192)===128&&(u&192)===128&&(d=(o&15)<<12|(c&63)<<6|u&63,d>2047&&(d<55296||d>57343)&&(s=d));break;case 4:c=this.data[this._pos+1],u=this.data[this._pos+2],f=this.data[this._pos+3],(c&192)===128&&(u&192)===128&&(f&192)===128&&(d=(o&15)<<18|(c&63)<<12|(u&63)<<6|f&63,d>65535&&d<1114112&&(s=d))}s===null?(s=65533,a=1):s>65535&&(s-=65536,r.push(s>>>10&1023|55296),s=56320|s&1023),r.push(s),this._pos+=a};for(;!this.done();){let o=this.ch(),s;switch(o){case 92:if(this._pos++,this.done())throw new Error(`${g} unexpected string termination at position ${this._pos}`);switch(s=this.ch(),this._pos++,s){case 34:case 39:case 92:case 47:r.push(s);break;case 98:r.push(8);break;case 116:r.push(9);break;case 110:r.push(10);break;case 102:r.push(12);break;case 114:r.push(13);break;case 117:r.push(n());break;default:throw new Error(`${g} unexpected string escape character at position ${this._pos}`)}break;case 34:return this._pos++,new h(l.string,ro(r),this._pos-e);default:if(o<32)throw new Error(`${g} invalid control character at position ${this._pos}`);o<128?(r.push(o),this._pos++):i()}}throw new Error(`${g} unexpected end of string at position ${this._pos}`)}parseValue(){switch(this.ch()){case 123:return this.modeStack.push("obj-start"),this._pos++,new h(l.map,1/0,1);case 91:return this.modeStack.push("array-start"),this._pos++,new h(l.array,1/0,1);case 34:return this.parseString();case 110:return this.expect([110,117,108,108]),new h(l.null,null,4);case 102:return this.expect([102,97,108,115,101]),new h(l.false,!1,5);case 116:return this.expect([116,114,117,101]),new h(l.true,!0,4);case 45:case 48:case 49:case 50:case 51:case 52:case 53:case 54:case 55:case 56:case 57:return this.parseNumber();default:throw new Error(`${g} unexpected character at position ${this._pos}`)}}next(){switch(this.skipWhitespace(),this.currentMode()){case"value":return this.modeStack.pop(),this.parseValue();case"array-value":{if(this.modeStack.pop(),this.ch()===93)return this._pos++,this.skipWhitespace(),new h(l.break,void 0,1);if(this.ch()!==44)throw new Error(`${g} unexpected character at position ${this._pos}, was expecting array delimiter but found '${String.fromCharCode(this.ch())}'`);return this._pos++,this.modeStack.push("array-value"),this.skipWhitespace(),this.parseValue()}case"array-start":return this.modeStack.pop(),this.ch()===93?(this._pos++,this.skipWhitespace(),new h(l.break,void 0,1)):(this.modeStack.push("array-value"),this.skipWhitespace(),this.parseValue());case"obj-key":if(this.ch()===125)return this.modeStack.pop(),this._pos++,this.skipWhitespace(),new h(l.break,void 0,1);if(this.ch()!==44)throw new Error(`${g} unexpected character at position ${this._pos}, was expecting object delimiter but found '${String.fromCharCode(this.ch())}'`);this._pos++,this.skipWhitespace();case"obj-start":{if(this.modeStack.pop(),this.ch()===125)return this._pos++,this.skipWhitespace(),new h(l.break,void 0,1);let e=this.parseString();if(this.skipWhitespace(),this.ch()!==58)throw new Error(`${g} unexpected character at position ${this._pos}, was expecting key/value delimiter ':' but found '${String.fromCharCode(this.ch())}'`);return this._pos++,this.modeStack.push("obj-value"),e}case"obj-value":return this.modeStack.pop(),this.modeStack.push("obj-key"),this.skipWhitespace(),this.parseValue();default:throw new Error(`${g} unexpected parse state at position ${this._pos}; this shouldn't happen`)}}};function Mn(t,e){return e=Object.assign({tokenizer:new pt(t,e)},e),Nt(t,e)}var Vn={};ee(Vn,{base64:()=>Hn,base64pad:()=>Gu,base64url:()=>ju,base64urlpad:()=>Yu});var Hn=J({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Gu=J({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),ju=J({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Yu=J({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});function Ku(t){return t instanceof ArrayBuffer?new Uint8Array(t,0,t.byteLength):t}var Wn=class extends pt{constructor(e,r){super(e,r),this.tokenBuffer=[]}done(){return this.tokenBuffer.length===0&&super.done()}_next(){return this.tokenBuffer.length>0?this.tokenBuffer.pop():super.next()}next(){let e=this._next();if(l.equals(e.type,l.map)){let r=this._next();if(l.equals(r.type,l.string)&&r.value==="/"){let n=this._next();if(l.equals(n.type,l.string)){let i=this._next();if(!l.equals(i.type,l.break))throw new Error("Invalid encoded CID form");return this.tokenBuffer.push(n),new h(l.tag,42,0)}if(l.equals(n.type,l.map)){let i=this._next();if(l.equals(i.type,l.string)&&i.value==="bytes"){let o=this._next();if(l.equals(o.type,l.string)){for(let a=0;a<2;a++){let c=this._next();if(!l.equals(c.type,l.break))throw new Error("Invalid encoded Bytes form")}let s=Hn.decode(`m${o.value}`);return new h(l.bytes,s,o.value.length)}this.tokenBuffer.push(o)}this.tokenBuffer.push(i)}this.tokenBuffer.push(n)}this.tokenBuffer.push(r)}return e}},As={allowIndefinite:!1,allowUndefined:!1,allowNaN:!1,allowInfinity:!1,allowBigInt:!0,strict:!0,useMaps:!1,rejectDuplicateMapKeys:!0,tags:{42:t=>k.parse(t())}};var Rr=297;var Ur=t=>{let e=Ku(t),r=Object.assign(As,{tokenizer:new Wn(e,As)});return Mn(e,r)};var Wm=new TextDecoder;var qm=new TextEncoder;var Ae={};ee(Ae,{code:()=>Ge,createLink:()=>Us,createNode:()=>Rs,decode:()=>Gt,encode:()=>F,name:()=>af,prepare:()=>P,validate:()=>jn});var Ju=new TextDecoder;function qn(t,e){let r=0;for(let n=0;;n+=7){if(n>=64)throw new Error("protobuf: varint overflow");if(e>=t.length)throw new Error("protobuf: unexpected end of data");let i=t[e++];if(r+=n<28?(i&127)<<n:(i&127)*2**n,i<128)break}return[r,e]}function Fr(t,e){let r;[r,e]=qn(t,e);let n=e+r;if(r<0||n<0)throw new Error("protobuf: invalid length");if(n>t.length)throw new Error("protobuf: unexpected end of data");return[t.subarray(e,n),n]}function Is(t,e){let r;return[r,e]=qn(t,e),[r&7,r>>3,e]}function Xu(t){let e={},r=t.length,n=0;for(;n<r;){let i,o;if([i,o,n]=Is(t,n),o===1){if(e.Hash)throw new Error("protobuf: (PBLink) duplicate Hash section");if(i!==2)throw new Error(`protobuf: (PBLink) wrong wireType (${i}) for Hash`);if(e.Name!==void 0)throw new Error("protobuf: (PBLink) invalid order, found Name before Hash");if(e.Tsize!==void 0)throw new Error("protobuf: (PBLink) invalid order, found Tsize before Hash");[e.Hash,n]=Fr(t,n)}else if(o===2){if(e.Name!==void 0)throw new Error("protobuf: (PBLink) duplicate Name section");if(i!==2)throw new Error(`protobuf: (PBLink) wrong wireType (${i}) for Name`);if(e.Tsize!==void 0)throw new Error("protobuf: (PBLink) invalid order, found Tsize before Name");let s;[s,n]=Fr(t,n),e.Name=Ju.decode(s)}else if(o===3){if(e.Tsize!==void 0)throw new Error("protobuf: (PBLink) duplicate Tsize section");if(i!==0)throw new Error(`protobuf: (PBLink) wrong wireType (${i}) for Tsize`);[e.Tsize,n]=qn(t,n)}else throw new Error(`protobuf: (PBLink) invalid fieldNumber, expected 1, 2 or 3, got ${o}`)}if(n>r)throw new Error("protobuf: (PBLink) unexpected end of data");return e}function Ss(t){let e=t.length,r=0,n,i=!1,o;for(;r<e;){let a,c;if([a,c,r]=Is(t,r),a!==2)throw new Error(`protobuf: (PBNode) invalid wireType, expected 2, got ${a}`);if(c===1){if(o)throw new Error("protobuf: (PBNode) duplicate Data section");[o,r]=Fr(t,r),n&&(i=!0)}else if(c===2){if(i)throw new Error("protobuf: (PBNode) duplicate Links section");n||(n=[]);let u;[u,r]=Fr(t,r),n.push(Xu(u))}else throw new Error(`protobuf: (PBNode) invalid fieldNumber, expected 1 or 2, got ${c}`)}if(r>e)throw new Error("protobuf: (PBNode) unexpected end of data");let s={};return o&&(s.Data=o),s.Links=n||[],s}var Bs=new TextEncoder,Ts=2**32,Zu=2**31;function Qu(t,e){let r=e.length;if(typeof t.Tsize=="number"){if(t.Tsize<0)throw new Error("Tsize cannot be negative");if(!Number.isSafeInteger(t.Tsize))throw new Error("Tsize too large for encoding");r=qt(e,r,t.Tsize)-1,e[r]=24}if(typeof t.Name=="string"){let n=Bs.encode(t.Name);r-=n.length,e.set(n,r),r=qt(e,r,n.length)-1,e[r]=18}return t.Hash&&(r-=t.Hash.length,e.set(t.Hash,r),r=qt(e,r,t.Hash.length)-1,e[r]=10),e.length-r}function vs(t,e,r){return t-=e.Data.length,r.set(e.Data,t),t=qt(r,t,e.Data.length)-1,r[t]=10,t}function Cs(t,e){let r=tf(t),n=new Uint8Array(r),i=r,o=e?.fieldOrder==="data-first"?e.fieldOrder:"links-first";if(t.Data&&o==="links-first"&&(i=vs(i,t,n)),t.Links)for(let s=t.Links.length-1;s>=0;s--){let a=Qu(t.Links[s],n.subarray(0,i));i-=a,i=qt(n,i,a)-1,n[i]=18}return t.Data&&o==="data-first"&&(i=vs(i,t,n)),n}function ef(t){let e=0;if(t.Hash){let r=t.Hash.length;e+=1+r+yt(r)}if(typeof t.Name=="string"){let r=Bs.encode(t.Name).length;e+=1+r+yt(r)}return typeof t.Tsize=="number"&&(e+=1+yt(t.Tsize)),e}function tf(t){let e=0;if(t.Data){let r=t.Data.length;e+=1+r+yt(r)}if(t.Links)for(let r of t.Links){let n=ef(r);e+=1+n+yt(n)}return e}function qt(t,e,r){e-=yt(r);let n=e;for(;r>=Zu;)t[e++]=r&127|128,r/=128;for(;r>=128;)t[e++]=r&127|128,r>>>=7;return t[e]=r,n}function yt(t){return t%2===0&&t++,Math.floor((rf(t)+6)/7)}function rf(t){let e=0;return t>=Ts&&(t=Math.floor(t/Ts),e=32),t>=65536&&(t>>>=16,e+=16),t>=256&&(t>>>=8,e+=8),e+nf[t]}var nf=[0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8];var of=["Data","Links"],sf=["Hash","Name","Tsize"],Gn=new TextEncoder;function Ls(t,e){if(t===e)return 0;let r=t.Name?Gn.encode(t.Name):[],n=e.Name?Gn.encode(e.Name):[],i=r.length,o=n.length;for(let s=0,a=Math.min(i,o);s<a;++s)if(r[s]!==n[s]){i=r[s],o=n[s];break}return i<o?-1:o<i?1:0}function Ds(t,e){return!Object.keys(t).some(r=>!e.includes(r))}function Ns(t){if(typeof t.asCID=="object"){let r=k.asCID(t);if(!r)throw new TypeError("Invalid DAG-PB form");return{Hash:r}}if(typeof t!="object"||Array.isArray(t))throw new TypeError("Invalid DAG-PB form");let e={};if(t.Hash){let r=k.asCID(t.Hash);try{r||(typeof t.Hash=="string"?r=k.parse(t.Hash):t.Hash instanceof Uint8Array&&(r=k.decode(t.Hash)))}catch(n){throw new TypeError(`Invalid DAG-PB form: ${n.message}`)}r&&(e.Hash=r)}if(!e.Hash)throw new TypeError("Invalid DAG-PB form");return typeof t.Name=="string"&&(e.Name=t.Name),typeof t.Tsize=="number"&&(e.Tsize=t.Tsize),e}function P(t){if((t instanceof Uint8Array||typeof t=="string")&&(t={Data:t}),typeof t!="object"||Array.isArray(t))throw new TypeError("Invalid DAG-PB form");let e={};if(t.Data!==void 0)if(typeof t.Data=="string")e.Data=Gn.encode(t.Data);else if(t.Data instanceof Uint8Array)e.Data=t.Data;else throw new TypeError("Invalid DAG-PB form");if(t.Links!==void 0)if(Array.isArray(t.Links))e.Links=t.Links.map(Ns),e.Links.sort(Ls);else throw new TypeError("Invalid DAG-PB form");else e.Links=[];return e}function jn(t){if(!t||typeof t!="object"||Array.isArray(t)||t instanceof Uint8Array||t["/"]&&t["/"]===t.bytes)throw new TypeError("Invalid DAG-PB form");if(!Ds(t,of))throw new TypeError("Invalid DAG-PB form (extraneous properties)");if(t.Data!==void 0&&!(t.Data instanceof Uint8Array))throw new TypeError("Invalid DAG-PB form (Data must be bytes)");if(!Array.isArray(t.Links))throw new TypeError("Invalid DAG-PB form (Links must be a list)");for(let e=0;e<t.Links.length;e++){let r=t.Links[e];if(!r||typeof r!="object"||Array.isArray(r)||r instanceof Uint8Array||r["/"]&&r["/"]===r.bytes)throw new TypeError("Invalid DAG-PB form (bad link)");if(!Ds(r,sf))throw new TypeError("Invalid DAG-PB form (extraneous properties on link)");if(r.Hash===void 0)throw new TypeError("Invalid DAG-PB form (link must have a Hash)");if(r.Hash==null||!r.Hash["/"]||r.Hash["/"]!==r.Hash.bytes)throw new TypeError("Invalid DAG-PB form (link Hash must be a CID)");if(r.Name!==void 0&&typeof r.Name!="string")throw new TypeError("Invalid DAG-PB form (link Name must be a string)");if(r.Tsize!==void 0){if(typeof r.Tsize!="number"||r.Tsize%1!==0)throw new TypeError("Invalid DAG-PB form (link Tsize must be an integer)");if(r.Tsize<0)throw new TypeError("Invalid DAG-PB form (link Tsize cannot be negative)")}if(e>0&&Ls(r,t.Links[e-1])===-1)throw new TypeError("Invalid DAG-PB form (links must be sorted by Name bytes)")}}function Rs(t,e=[]){return P({Data:t,Links:e})}function Us(t,e,r){return Ns({Hash:r,Name:t,Tsize:e})}function Ps(t){return t instanceof ArrayBuffer?new Uint8Array(t,0,t.byteLength):t}var af="dag-pb",Ge=112;function F(t,e){jn(t);let r={};return t.Links&&(r.Links=t.Links.map(n=>{let i={};return n.Hash&&(i.Hash=n.Hash.bytes),n.Name!==void 0&&(i.Name=n.Name),n.Tsize!==void 0&&(i.Tsize=n.Tsize),i})),t.Data&&(r.Data=t.Data),Cs(r,e)}function Gt(t){let e=Ps(t),r=Ss(e),n={};return r.Data&&(n.Data=r.Data),r.Links&&(n.Links=r.Links.map(i=>{let o={};try{o.Hash=k.decode(i.Hash)}catch{}if(!o.Hash)throw new Error("Invalid Hash field found in link, expected CID");return i.Name!==void 0&&(o.Name=i.Name),i.Tsize!==void 0&&(o.Tsize=i.Tsize),o})),n}var ep=new TextEncoder,cf=new TextDecoder;var zr=512;function Or(t){return JSON.parse(cf.decode(t))}var Ie={};ee(Ie,{code:()=>ce,decode:()=>lf,encode:()=>ff,name:()=>uf});var uf="raw",ce=85;function ff(t){return te(t)}function lf(t){return te(t)}var Yn={};ee(Yn,{identity:()=>Yt});var Fs=0,df="identity",zs=te;function hf(t,e){if(e?.truncate!=null&&e.truncate!==t.byteLength){if(e.truncate<0||e.truncate>t.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${t.byteLength}`);t=t.subarray(0,e.truncate)}return ar(Fs,zs(t))}var Yt={code:Fs,name:df,encode:zs,digest:hf};import{Buffer as mf}from"node:buffer";function je(t){if(t.buffer instanceof ArrayBuffer)return new Uint8Array(t.buffer,t.byteOffset,t.byteLength);let e=t.slice();return new Uint8Array(e.buffer,0,e.byteLength)}function Se(t,e){return je(mf.concat(t,e))}function pf(t){return t[Symbol.asyncIterator]!=null}function yf(t){if(pf(t))return(async()=>{let n=new Uint8Array(0);for await(let i of t)n=Se([n,i],n.length+i.length);return n})();let e=[],r=0;for(let n of t)e.push(n),r+=n.byteLength;return Se(e,r)}var S=yf;function gt(t){return t==null?!1:k.asCID(t)===t}function wt(t,e){let r,n=0,i="";for(;n<e.length;){let o=e[n];if(n++,!Object.hasOwnProperty.call(t,o))throw new ht(`Object did not have key "${o}"`);if(i+=`/${o}`,r=t[o],t=r,gt(r))break}return{value:r,rest:e.slice(n),path:i.substring(1)}}async function*Kn(t,e,r,n){let i=await S(r.get(t,n)),o=We(i),s=wt(o,e);yield{cid:gt(s.value)?s.value:t,name:s.path,rest:s.rest}}async function*Os(t,e,r,n){let i=await S(r.get(t,n)),o=Ur(i),s=wt(o,e);yield{cid:gt(s.value)?s.value:t,name:s.path,rest:s.rest}}function Te(t,e){let r=t.lo+e.lo>>>0,n=t.hi+e.hi+(r<t.lo?1:0)>>>0;return{lo:r,hi:n}}function gf(t,e){return t+e>>>0}function Z(t,e){let r=t.lo&65535,n=t.lo>>>16,i=e.lo&65535,o=e.lo>>>16,s=r*i,a=r*o,c=n*i,u=n*o,f=(s>>>16)+(a&65535)+(c&65535)>>>0,d=(f<<16|s&65535)>>>0,m=u+(a>>>16)+(c>>>16)+(f>>>16),w=Math.imul(t.lo,e.hi),x=Math.imul(t.hi,e.lo),b=m+w+x>>>0;return{lo:d,hi:b}}function Ye(t,e){return Math.imul(t,e)>>>0}function bt(t,e){if(e===0)return t;if(e===32)return{lo:t.hi,hi:t.lo};if(e<32){let i=(t.lo<<e|t.hi>>>32-e)>>>0,o=(t.hi<<e|t.lo>>>32-e)>>>0;return{lo:i,hi:o}}e-=32;let r=(t.hi<<e|t.lo>>>32-e)>>>0,n=(t.lo<<e|t.hi>>>32-e)>>>0;return{lo:r,hi:n}}function T(t,e){return{lo:(t.lo^e.lo)>>>0,hi:(t.hi^e.hi)>>>0}}function Jn(t,e){if(e===0)return t;if(e<32){let r=(t.lo>>>e|t.hi<<32-e)>>>0,n=t.hi>>>e;return{lo:r,hi:n}}return{lo:t.hi>>>e-32,hi:0}}function I(t,e){return{lo:t>>>0,hi:e>>>0}}function Xn(t,e){return(t<<e|t>>>32-e)>>>0}function $s(t,e){let r=e*8,n=t[r]|t[r+1]<<8|t[r+2]<<16|t[r+3]<<24,i=t[r+4]|t[r+5]<<8|t[r+6]<<16|t[r+7]<<24;return{lo:n>>>0,hi:i>>>0}}function wf(t,e){let r=e*4;return(t[r]|t[r+1]<<8|t[r+2]<<16|t[r+3]<<24)>>>0}function Ms(t){return t=T(t,Jn(t,33)),t=Z(t,I(3981806797,4283543511)),t=T(t,Jn(t,33)),t=Z(t,I(444984403,3301882366)),t=T(t,Jn(t,33)),t}function bf(t){return t^=t>>>16,t=Ye(t,2246822507),t^=t>>>13,t=Ye(t,3266489909),t^=t>>>16,t}function Zn(t,e=0){let r=I(e,0),n=I(e,0),i=t.length,o=Math.floor(i/16),s=I(289559509,2277735313),a=I(658871167,1291169091);for(let m=0;m<o;m++){let w=$s(t,m*2),x=$s(t,m*2+1);w=Z(w,s),w=bt(w,31),w=Z(w,a),r=T(r,w),r=bt(r,27),r=Te(r,n),r=Te(Z(r,I(5,0)),I(1390208809,0)),x=Z(x,a),x=bt(x,33),x=Z(x,s),n=T(n,x),n=bt(n,31),n=Te(n,r),n=Te(Z(n,I(5,0)),I(944331445,0))}let c=I(0,0),u=I(0,0),f=t.slice(o*16);switch(f.length){case 15:u=T(u,I(0,f[14]<<16));case 14:u=T(u,I(0,f[13]<<8));case 13:u=T(u,I(0,f[12]));case 12:u=T(u,I(f[11]<<24,0));case 11:u=T(u,I(f[10]<<16,0));case 10:u=T(u,I(f[9]<<8,0));case 9:u=T(u,I(f[8],0)),u=Z(u,a),u=bt(u,33),u=Z(u,s),n=T(n,u);case 8:c=T(c,I(0,f[7]<<24));case 7:c=T(c,I(0,f[6]<<16));case 6:c=T(c,I(0,f[5]<<8));case 5:c=T(c,I(0,f[4]));case 4:c=T(c,I(f[3]<<24,0));case 3:c=T(c,I(f[2]<<16,0));case 2:c=T(c,I(f[1]<<8,0));case 1:c=T(c,I(f[0],0)),c=Z(c,s),c=bt(c,31),c=Z(c,a),r=T(r,c)}let d=I(i,0);return r=T(r,d),n=T(n,d),r=Te(r,n),n=Te(n,r),r=Ms(r),n=Ms(n),r=Te(r,n),n=Te(n,r),new Uint8Array([r.hi>>>24&255,r.hi>>>16&255,r.hi>>>8&255,r.hi&255,r.lo>>>24&255,r.lo>>>16&255,r.lo>>>8&255,r.lo&255,n.hi>>>24&255,n.hi>>>16&255,n.hi>>>8&255,n.hi&255,n.lo>>>24&255,n.lo>>>16&255,n.lo>>>8&255,n.lo&255])}function Hs(t,e=0){let r=e>>>0,n=t.length,i=Math.floor(n/4),o=3432918353,s=461845907;for(let u=0;u<i;u++){let f=wf(t,u);f=Ye(f,o),f=Xn(f,15),f=Ye(f,s),r^=f,r=Xn(r,13),r=gf(Ye(r,5),3864292196)}let a=t.slice(i*4),c=0;switch(a.length){case 3:c^=a[2]<<16;case 2:c^=a[1]<<8;case 1:c^=a[0],c=Ye(c,o),c=Xn(c,15),c=Ye(c,s),r^=c}return r^=n,r=bf(r),r}function kf(t){let e=new Array(4);for(let r=0;r<4;r++)e[r]=t&255,t=t>>8;return new Uint8Array(e)}var Tp=Oe({name:"murmur3-32",code:35,encode:t=>kf(Hs(t))}),$r=Oe({name:"murmur3-128",code:34,encode:t=>Zn(t)}),vp=Oe({name:"murmur3-x64-64",code:34,encode:t=>Zn(t).subarray(0,8)});var Zs=At(qs(),1);import{Buffer as zf}from"node:buffer";var Qn={};ee(Qn,{base10:()=>If});var If=Yi({prefix:"9",name:"base10",alphabet:"0123456789"});var ei={};ee(ei,{base16:()=>Sf,base16upper:()=>Tf});var Sf=J({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4,caseInsensitive:!0}),Tf=J({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4,caseInsensitive:!0});var ti={};ee(ti,{base2:()=>vf});var vf=J({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var ri={};ee(ri,{base256emoji:()=>Nf});var Gs=Array.from("\u{1F680}\u{1FA90}\u2604\u{1F6F0}\u{1F30C}\u{1F311}\u{1F312}\u{1F313}\u{1F314}\u{1F315}\u{1F316}\u{1F317}\u{1F318}\u{1F30D}\u{1F30F}\u{1F30E}\u{1F409}\u2600\u{1F4BB}\u{1F5A5}\u{1F4BE}\u{1F4BF}\u{1F602}\u2764\u{1F60D}\u{1F923}\u{1F60A}\u{1F64F}\u{1F495}\u{1F62D}\u{1F618}\u{1F44D}\u{1F605}\u{1F44F}\u{1F601}\u{1F525}\u{1F970}\u{1F494}\u{1F496}\u{1F499}\u{1F622}\u{1F914}\u{1F606}\u{1F644}\u{1F4AA}\u{1F609}\u263A\u{1F44C}\u{1F917}\u{1F49C}\u{1F614}\u{1F60E}\u{1F607}\u{1F339}\u{1F926}\u{1F389}\u{1F49E}\u270C\u2728\u{1F937}\u{1F631}\u{1F60C}\u{1F338}\u{1F64C}\u{1F60B}\u{1F497}\u{1F49A}\u{1F60F}\u{1F49B}\u{1F642}\u{1F493}\u{1F929}\u{1F604}\u{1F600}\u{1F5A4}\u{1F603}\u{1F4AF}\u{1F648}\u{1F447}\u{1F3B6}\u{1F612}\u{1F92D}\u2763\u{1F61C}\u{1F48B}\u{1F440}\u{1F62A}\u{1F611}\u{1F4A5}\u{1F64B}\u{1F61E}\u{1F629}\u{1F621}\u{1F92A}\u{1F44A}\u{1F973}\u{1F625}\u{1F924}\u{1F449}\u{1F483}\u{1F633}\u270B\u{1F61A}\u{1F61D}\u{1F634}\u{1F31F}\u{1F62C}\u{1F643}\u{1F340}\u{1F337}\u{1F63B}\u{1F613}\u2B50\u2705\u{1F97A}\u{1F308}\u{1F608}\u{1F918}\u{1F4A6}\u2714\u{1F623}\u{1F3C3}\u{1F490}\u2639\u{1F38A}\u{1F498}\u{1F620}\u261D\u{1F615}\u{1F33A}\u{1F382}\u{1F33B}\u{1F610}\u{1F595}\u{1F49D}\u{1F64A}\u{1F639}\u{1F5E3}\u{1F4AB}\u{1F480}\u{1F451}\u{1F3B5}\u{1F91E}\u{1F61B}\u{1F534}\u{1F624}\u{1F33C}\u{1F62B}\u26BD\u{1F919}\u2615\u{1F3C6}\u{1F92B}\u{1F448}\u{1F62E}\u{1F646}\u{1F37B}\u{1F343}\u{1F436}\u{1F481}\u{1F632}\u{1F33F}\u{1F9E1}\u{1F381}\u26A1\u{1F31E}\u{1F388}\u274C\u270A\u{1F44B}\u{1F630}\u{1F928}\u{1F636}\u{1F91D}\u{1F6B6}\u{1F4B0}\u{1F353}\u{1F4A2}\u{1F91F}\u{1F641}\u{1F6A8}\u{1F4A8}\u{1F92C}\u2708\u{1F380}\u{1F37A}\u{1F913}\u{1F619}\u{1F49F}\u{1F331}\u{1F616}\u{1F476}\u{1F974}\u25B6\u27A1\u2753\u{1F48E}\u{1F4B8}\u2B07\u{1F628}\u{1F31A}\u{1F98B}\u{1F637}\u{1F57A}\u26A0\u{1F645}\u{1F61F}\u{1F635}\u{1F44E}\u{1F932}\u{1F920}\u{1F927}\u{1F4CC}\u{1F535}\u{1F485}\u{1F9D0}\u{1F43E}\u{1F352}\u{1F617}\u{1F911}\u{1F30A}\u{1F92F}\u{1F437}\u260E\u{1F4A7}\u{1F62F}\u{1F486}\u{1F446}\u{1F3A4}\u{1F647}\u{1F351}\u2744\u{1F334}\u{1F4A3}\u{1F438}\u{1F48C}\u{1F4CD}\u{1F940}\u{1F922}\u{1F445}\u{1F4A1}\u{1F4A9}\u{1F450}\u{1F4F8}\u{1F47B}\u{1F910}\u{1F92E}\u{1F3BC}\u{1F975}\u{1F6A9}\u{1F34E}\u{1F34A}\u{1F47C}\u{1F48D}\u{1F4E3}\u{1F942}"),Bf=Gs.reduce((t,e,r)=>(t[r]=e,t),[]),Cf=Gs.reduce((t,e,r)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return t[n]=r,t},[]);function Df(t){return t.reduce((e,r)=>(e+=Bf[r],e),"")}function Lf(t){let e=[];for(let r of t){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let i=Cf[n];if(i==null)throw new Error(`Non-base256emoji character: ${r}`);e.push(i)}return new Uint8Array(e)}var Nf=sr({prefix:"\u{1F680}",name:"base256emoji",encode:Df,decode:Lf});var ni={};ee(ni,{base8:()=>Rf});var Rf=J({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var ii={};ee(ii,{identity:()=>Uf});var Uf=sr({prefix:"\0",name:"identity",encode:t=>ji(te(t)),decode:t=>te(Gi(t))});var oi={};ee(oi,{sha256:()=>Ke,sha512:()=>Pf});import js from"node:crypto";var Ke=Oe({name:"sha2-256",code:18,encode:t=>te(js.createHash("sha256").update(t).digest())}),Pf=Oe({name:"sha2-512",code:19,encode:t=>te(js.createHash("sha512").update(t).digest())});var si={...ii,...ti,...ni,...Qn,...ei,...Ki,...Ji,...Xi,...Vn,...ri},Gp={...oi,...Yn};import{Buffer as Ys}from"node:buffer";function me(t=0){return je(Ys.alloc(t))}function ne(t=0){return je(Ys.allocUnsafe(t))}function Js(t,e,r,n){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:n}}}var Ks=Js("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),ai=Js("ascii","a",t=>{let e="a";for(let r=0;r<t.length;r++)e+=String.fromCharCode(t[r]);return e},t=>{t=t.substring(1);let e=ne(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}),Ff={utf8:Ks,"utf-8":Ks,hex:si.base16,latin1:ai,ascii:ai,binary:ai,...si},Xs=Ff;function ve(t,e="utf8"){let r=Xs[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return e==="utf8"||e==="utf-8"?je(zf.from(t,"utf-8")):r.decoder.decode(`${r.prefix}${t}`)}var ue=class t{_options;_popCount;_parent;_posAtParent;_children;key;constructor(e,r,n=0){this._options=e,this._popCount=0,this._parent=r,this._posAtParent=n,this._children=new Zs.default,this.key=null}async put(e,r){let n=await this._findNewBucketAndPos(e);n.bucket._putAt(n,e,r)}async get(e){let r=await this._findChild(e);if(r!=null)return r.value}async del(e){let r=await this._findPlace(e),n=r.bucket._at(r.pos);n!=null&&n.key===e&&r.bucket._delAt(r.pos)}leafCount(){return this._children.compactArray().reduce((r,n)=>n instanceof t?r+n.leafCount():r+1,0)}childrenCount(){return this._children.length}onlyChild(){return this._children.get(0)}*eachLeafSeries(){let e=this._children.compactArray();for(let r of e)r instanceof t?yield*r.eachLeafSeries():yield r}serialize(e,r){let n=[];return r(this._children.reduce((i,o,s)=>(o!=null&&(o instanceof t?i.push(o.serialize(e,r)):i.push(e(o,s))),i),n))}async asyncTransform(e,r){return Qs(this,e,r)}toJSON(){return this.serialize($f,Mf)}prettyPrint(){return JSON.stringify(this.toJSON(),null," ")}tableSize(){return Math.pow(2,this._options.bits)}async _findChild(e){let r=await this._findPlace(e),n=r.bucket._at(r.pos);if(!(n instanceof t)&&n!=null&&n.key===e)return n}async _findPlace(e){let r=this._options.hash(typeof e=="string"?ve(e):e),n=await r.take(this._options.bits),i=this._children.get(n);return i instanceof t?i._findPlace(r):{bucket:this,pos:n,hash:r,existingChild:i}}async _findNewBucketAndPos(e){let r=await this._findPlace(e);if(r.existingChild!=null&&r.existingChild.key!==e){let n=new t(this._options,r.bucket,r.pos);r.bucket._putObjectAt(r.pos,n);let i=await n._findPlace(r.existingChild.hash);return i.bucket._putAt(i,r.existingChild.key,r.existingChild.value),n._findNewBucketAndPos(r.hash)}return r}_putAt(e,r,n){this._putObjectAt(e.pos,{key:r,value:n,hash:e.hash})}_putObjectAt(e,r){this._children.get(e)==null&&this._popCount++,this._children.set(e,r)}_delAt(e){if(e===-1)throw new Error("Invalid position");this._children.get(e)!=null&&this._popCount--,this._children.unset(e),this._level()}_level(){if(this._parent!=null&&this._popCount<=1)if(this._popCount===1){let e=this._children.find(Of);if(e!=null&&!(e instanceof t)){let r=e.hash;r.untake(this._options.bits);let n={pos:this._posAtParent,hash:r,bucket:this._parent};this._parent._putAt(n,e.key,e.value)}}else this._parent._delAt(this._posAtParent)}_at(e){return this._children.get(e)}};function Of(t){return!!t}function $f(t,e){return t.key}function Mf(t){return t}async function Qs(t,e,r){let n=[];for(let i of t._children.compactArray())if(i instanceof ue)await Qs(i,e,r);else{let o=await e(i);n.push({bitField:t._children.bitField(),children:o})}return r(n)}var Hf=[255,254,252,248,240,224,192,128],Vf=[1,3,7,15,31,63,127,255],Mr=class{_value;_currentBytePos;_currentBitPos;constructor(e){this._value=e,this._currentBytePos=e.length-1,this._currentBitPos=7}availableBits(){return this._currentBitPos+1+this._currentBytePos*8}totalBits(){return this._value.length*8}take(e){let r=e,n=0;for(;r>0&&this._haveBits();){let i=this._value[this._currentBytePos],o=this._currentBitPos+1,s=Math.min(o,r),a=Wf(i,o-s,s);n=(n<<s)+a,r-=s,this._currentBitPos-=s,this._currentBitPos<0&&(this._currentBitPos=7,this._currentBytePos--)}return n}untake(e){for(this._currentBitPos+=e;this._currentBitPos>7;)this._currentBitPos-=8,this._currentBytePos+=1}_haveBits(){return this._currentBytePos>=0}};function Wf(t,e,r){let n=qf(e,r);return(t&n)>>>e}function qf(t,e){return Hf[t]&Vf[Math.min(e+t-1,7)]}function ea(t){function e(r){return r instanceof Hr?r:new Hr(r,t)}return e}var Hr=class{_value;_hashFn;_depth;_availableBits;_currentBufferIndex;_buffers;constructor(e,r){if(!(e instanceof Uint8Array))throw new Error("can only hash Uint8Arrays");this._value=e,this._hashFn=r,this._depth=-1,this._availableBits=0,this._currentBufferIndex=0,this._buffers=[]}async take(e){let r=e;for(;this._availableBits<r;)await this._produceMoreBits();let n=0;for(;r>0;){let i=this._buffers[this._currentBufferIndex],o=Math.min(i.availableBits(),r),s=i.take(o);n=(n<<o)+s,r-=o,this._availableBits-=o,i.availableBits()===0&&this._currentBufferIndex++}return n}untake(e){let r=e;for(;r>0;){let n=this._buffers[this._currentBufferIndex],i=Math.min(n.totalBits()-n.availableBits(),r);n.untake(i),r-=i,this._availableBits+=i,this._currentBufferIndex>0&&n.totalBits()===n.availableBits()&&(this._depth--,this._currentBufferIndex--)}}async _produceMoreBits(){this._depth++;let e=this._depth>0?Se([this._value,Uint8Array.from([this._depth])]):this._value,r=await this._hashFn(e),n=new Mr(r);this._buffers.push(n),this._availableBits+=n.availableBits()}};function Vr(t){if(t==null||t.hashFn==null)throw new Error("please define an options.hashFn");let e={bits:t.bits??8,hash:ea(t.hashFn)};return new ue(e)}function Gf(t){return t.buffer instanceof ArrayBuffer}function Wr(t){return Gf(t)?t:t.slice()}var Kt=class t extends Error{static name="InvalidTypeError";static code="ERR_INVALID_TYPE";name=t.name;code=t.code;constructor(e="Invalid type"){super(e)}};var jf=Math.pow(2,7),Yf=Math.pow(2,14),Kf=Math.pow(2,21),ta=Math.pow(2,28),ra=Math.pow(2,35),na=Math.pow(2,42),ia=Math.pow(2,49),$=128,Be=127;function Jt(t){if(t<jf)return 1;if(t<Yf)return 2;if(t<Kf)return 3;if(t<ta)return 4;if(t<ra)return 5;if(t<na)return 6;if(t<ia)return 7;if(Number.MAX_SAFE_INTEGER!=null&&t>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function oa(t,e,r=0){switch(Jt(t)){case 8:e[r++]=t&255|$,t/=128;case 7:e[r++]=t&255|$,t/=128;case 6:e[r++]=t&255|$,t/=128;case 5:e[r++]=t&255|$,t/=128;case 4:e[r++]=t&255|$,t>>>=7;case 3:e[r++]=t&255|$,t>>>=7;case 2:e[r++]=t&255|$,t>>>=7;case 1:{e[r++]=t&255,t>>>=7;break}default:throw new Error("unreachable")}return e}function sa(t,e){let r=t[e],n=0;if(n+=r&Be,r<$||(r=t[e+1],n+=(r&Be)<<7,r<$)||(r=t[e+2],n+=(r&Be)<<14,r<$)||(r=t[e+3],n+=(r&Be)<<21,r<$)||(r=t[e+4],n+=(r&Be)*ta,r<$)||(r=t[e+5],n+=(r&Be)*ra,r<$)||(r=t[e+6],n+=(r&Be)*na,r<$)||(r=t[e+7],n+=(r&Be)*ia,r<$))return n;throw new RangeError("Could not decode varint")}var ci=new Float32Array([-0]),Ce=new Uint8Array(ci.buffer);function aa(t,e,r){ci[0]=t,e[r]=Ce[0],e[r+1]=Ce[1],e[r+2]=Ce[2],e[r+3]=Ce[3]}function ca(t,e){return Ce[0]=t[e],Ce[1]=t[e+1],Ce[2]=t[e+2],Ce[3]=t[e+3],ci[0]}var ui=new Float64Array([-0]),z=new Uint8Array(ui.buffer);function ua(t,e,r){ui[0]=t,e[r]=z[0],e[r+1]=z[1],e[r+2]=z[2],e[r+3]=z[3],e[r+4]=z[4],e[r+5]=z[5],e[r+6]=z[6],e[r+7]=z[7]}function fa(t,e){return z[0]=t[e],z[1]=t[e+1],z[2]=t[e+2],z[3]=t[e+3],z[4]=t[e+4],z[5]=t[e+5],z[6]=t[e+6],z[7]=t[e+7],ui[0]}var Jf=BigInt(Number.MAX_SAFE_INTEGER),Xf=BigInt(Number.MIN_SAFE_INTEGER),K=class t{lo;hi;constructor(e,r){this.lo=e>>>0,this.hi=r>>>0}toNumber(e=!1){if(!e&&this.hi>>>31>0){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(r+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(e=!1){if(e)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(BigInt(r)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(e=!1){return this.toBigInt(e).toString()}zzEncode(){let e=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^e)>>>0,this.lo=(this.lo<<1^e)>>>0,this}zzDecode(){let e=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^e)>>>0,this.hi=(this.hi>>>1^e)>>>0,this}length(){let e=this.lo,r=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?r===0?e<16384?e<128?1:2:e<2097152?3:4:r<16384?r<128?5:6:r<2097152?7:8:n<128?9:10}static fromBigInt(e){if(e===0n)return Je;if(e<Jf&&e>Xf)return this.fromNumber(Number(e));let r=e<0n;r&&(e=-e);let n=e>>32n,i=e-(n<<32n);return r&&(n=~n|0n,i=~i|0n,++i>la&&(i=0n,++n>la&&(n=0n))),new t(Number(i),Number(n))}static fromNumber(e){if(e===0)return Je;let r=e<0;r&&(e=-e);let n=e>>>0,i=(e-n)/4294967296>>>0;return r&&(i=~i>>>0,n=~n>>>0,++n>4294967295&&(n=0,++i>4294967295&&(i=0))),new t(n,i)}static from(e){return typeof e=="number"?t.fromNumber(e):typeof e=="bigint"?t.fromBigInt(e):typeof e=="string"?t.fromBigInt(BigInt(e)):e.low!=null||e.high!=null?new t(e.low>>>0,e.high>>>0):Je}},Je=new K(0,0);Je.toBigInt=function(){return 0n};Je.zzEncode=Je.zzDecode=function(){return this};Je.length=function(){return 1};var la=4294967296n;function da(t){let e=0,r=0;for(let n=0;n<t.length;++n)r=t.charCodeAt(n),r<128?e+=1:r<2048?e+=2:(r&64512)===55296&&(t.charCodeAt(n+1)&64512)===56320?(++n,e+=4):e+=3;return e}function ha(t,e,r){if(r-e<1)return"";let i,o=[],s=0,a;for(;e<r;)a=t[e++],a<128?o[s++]=a:a>191&&a<224?o[s++]=(a&31)<<6|t[e++]&63:a>239&&a<365?(a=((a&7)<<18|(t[e++]&63)<<12|(t[e++]&63)<<6|t[e++]&63)-65536,o[s++]=55296+(a>>10),o[s++]=56320+(a&1023)):o[s++]=(a&15)<<12|(t[e++]&63)<<6|t[e++]&63,s>8191&&((i??(i=[])).push(String.fromCharCode.apply(String,o)),s=0);return i!=null?(s>0&&i.push(String.fromCharCode.apply(String,o.slice(0,s))),i.join("")):String.fromCharCode.apply(String,o.slice(0,s))}function fi(t,e,r){let n=r,i,o;for(let s=0;s<t.length;++s)i=t.charCodeAt(s),i<128?e[r++]=i:i<2048?(e[r++]=i>>6|192,e[r++]=i&63|128):(i&64512)===55296&&((o=t.charCodeAt(s+1))&64512)===56320?(i=65536+((i&1023)<<10)+(o&1023),++s,e[r++]=i>>18|240,e[r++]=i>>12&63|128,e[r++]=i>>6&63|128,e[r++]=i&63|128):(e[r++]=i>>12|224,e[r++]=i>>6&63|128,e[r++]=i&63|128);return r-n}function ie(t,e){return RangeError(`index out of range: ${t.pos} + ${e??1} > ${t.len}`)}function qr(t,e){return(t[e-4]|t[e-3]<<8|t[e-2]<<16|t[e-1]<<24)>>>0}var li=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(e){this.buf=Wr(e),this.pos=0,this.len=e.length}uint32(){let e=4294967295;if(e=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(e=(e|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return e;if((this.pos+=5)>this.len)throw this.pos=this.len,ie(this,10);return e}int32(){return this.uint32()|0}sint32(){let e=this.uint32();return e>>>1^-(e&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw ie(this,4);return qr(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw ie(this,4);return qr(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw ie(this,4);let e=ca(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw ie(this,4);let e=fa(this.buf,this.pos);return this.pos+=8,e}bytes(){let e=this.uint32(),r=this.pos,n=this.pos+e;if(n>this.len)throw ie(this,e);return this.pos+=e,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let e=this.bytes();return ha(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw ie(this,e);this.pos+=e}else do if(this.pos>=this.len)throw ie(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(e){switch(e){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(e=this.uint32()&7)!==4;)this.skipType(e);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${e} at offset ${this.pos}`)}return this}readLongVarint(){let e=new K(0,0),r=0;if(this.len-this.pos>4){for(;r<4;++r)if(e.lo=(e.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return e;if(e.lo=(e.lo|(this.buf[this.pos]&127)<<28)>>>0,e.hi=(e.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return e;r=0}else{for(;r<3;++r){if(this.pos>=this.len)throw ie(this);if(e.lo=(e.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return e}return e.lo=(e.lo|(this.buf[this.pos++]&127)<<r*7)>>>0,e}if(this.len-this.pos>4){for(;r<5;++r)if(e.hi=(e.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return e}else for(;r<5;++r){if(this.pos>=this.len)throw ie(this);if(e.hi=(e.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return e}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw ie(this,8);let e=qr(this.buf,this.pos+=4),r=qr(this.buf,this.pos+=4);return new K(e,r)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let e=sa(this.buf,this.pos);return this.pos+=Jt(e),e}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function Xt(t){return new li(t instanceof Uint8Array?t:t.subarray())}function De(t,e,r){let n=Xt(t);return e.decode(n,void 0,r)}function di(t){let e=t??8192,r=e>>>1,n,i=e;return function(s){if(s<1||s>r)return ne(s);i+s>e&&(n=ne(e),i=0);let a=n.subarray(i,i+=s);return(i&7)!==0&&(i=(i|7)+1),a}}var Xe=class{fn;len;next;val;constructor(e,r,n){this.fn=e,this.len=r,this.next=void 0,this.val=n}};function hi(){}var pi=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},Zf=di();function Qf(t){return globalThis.Buffer!=null?ne(t):Zf(t)}var Qt=class{len;head;tail;states;constructor(){this.len=0,this.head=new Xe(hi,0,0),this.tail=this.head,this.states=null}_push(e,r,n){return this.tail=this.tail.next=new Xe(e,r,n),this.len+=r,this}uint32(e){return this.len+=(this.tail=this.tail.next=new yi((e=e>>>0)<128?1:e<16384?2:e<2097152?3:e<268435456?4:5,e)).len,this}int32(e){return e<0?this._push(Gr,10,K.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){let r=K.fromBigInt(e);return this._push(Gr,r.length(),r)}uint64Number(e){return this._push(oa,Jt(e),e)}uint64String(e){return this.uint64(BigInt(e))}int64(e){return this.uint64(e)}int64Number(e){return this.uint64Number(e)}int64String(e){return this.uint64String(e)}sint64(e){let r=K.fromBigInt(e).zzEncode();return this._push(Gr,r.length(),r)}sint64Number(e){let r=K.fromNumber(e).zzEncode();return this._push(Gr,r.length(),r)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(mi,1,e?1:0)}fixed32(e){return this._push(Zt,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let r=K.fromBigInt(e);return this._push(Zt,4,r.lo)._push(Zt,4,r.hi)}fixed64Number(e){let r=K.fromNumber(e);return this._push(Zt,4,r.lo)._push(Zt,4,r.hi)}fixed64String(e){return this.fixed64(BigInt(e))}sfixed64(e){return this.fixed64(e)}sfixed64Number(e){return this.fixed64Number(e)}sfixed64String(e){return this.fixed64String(e)}float(e){return this._push(aa,4,e)}double(e){return this._push(ua,8,e)}bytes(e){let r=e.length>>>0;return r===0?this._push(mi,1,0):this.uint32(r)._push(tl,r,e)}string(e){let r=da(e);return r!==0?this.uint32(r)._push(fi,r,e):this._push(mi,1,0)}fork(){return this.states=new pi(this),this.head=this.tail=new Xe(hi,0,0),this.len=0,this}reset(){return this.states!=null?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new Xe(hi,0,0),this.len=0),this}ldelim(){let e=this.head,r=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=e.next,this.tail=r,this.len+=n),this}finish(){let e=this.head.next,r=Qf(this.len),n=0;for(;e!=null;)e.fn(e.val,r,n),n+=e.len,e=e.next;return r}};function mi(t,e,r){e[r]=t&255}function el(t,e,r){for(;t>127;)e[r++]=t&127|128,t>>>=7;e[r]=t}var yi=class extends Xe{next;constructor(e,r){super(el,e,r),this.next=void 0}};function Gr(t,e,r){for(;t.hi!==0;)e[r++]=t.lo&127|128,t.lo=(t.lo>>>7|t.hi<<25)>>>0,t.hi>>>=7;for(;t.lo>127;)e[r++]=t.lo&127|128,t.lo=t.lo>>>7;e[r++]=t.lo}function Zt(t,e,r){e[r]=t&255,e[r+1]=t>>>8&255,e[r+2]=t>>>16&255,e[r+3]=t>>>24}function tl(t,e,r){e.set(t,r)}globalThis.Buffer!=null&&(Qt.prototype.bytes=function(t){let e=t.length>>>0;return this.uint32(e),e>0&&this._push(rl,e,t),this},Qt.prototype.string=function(t){let e=globalThis.Buffer.byteLength(t);return this.uint32(e),e>0&&this._push(nl,e,t),this});function rl(t,e,r){e.set(t,r)}function nl(t,e,r){t.length<40?fi(t,e,r):e.utf8Write!=null?e.utf8Write(t,r):e.set(ve(t),r)}function gi(){return new Qt}function Le(t,e){let r=gi();return e.encode(t,r,{lengthDelimited:!1}),r.finish()}function*Ne(t,e,r){let n=Xt(t);yield*e.stream(n,void 0,".",r)}var jr={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function Yr(t,e,r,n,i){return{name:t,type:e,encode:r,decode:n,stream:i}}function wi(t){function e(o){if(t[o.toString()]==null)throw new Error("Invalid enum value");return t[o]}let r=function(s,a){let c=e(s);a.int32(c)},n=function(s){let a=s.int32();return e(a)},i=function*(s,a){};return Yr("enum",jr.VARINT,r,n,i)}function Re(t,e,r){return Yr("message",jr.LENGTH_DELIMITED,t,e,r)}var pe=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var U;(function(t){let e;(function(a){a.RAW="RAW",a.DIRECTORY="DIRECTORY",a.FILE="FILE",a.METADATA="METADATA",a.SYMLINK="SYMLINK",a.HAMT_SHARD="HAMT_SHARD"})(e=t.Type||(t.Type={}));let r;(function(a){a[a.RAW=0]="RAW",a[a.DIRECTORY=1]="DIRECTORY",a[a.FILE=2]="FILE",a[a.METADATA=3]="METADATA",a[a.SYMLINK=4]="SYMLINK",a[a.HAMT_SHARD=5]="HAMT_SHARD"})(r||(r={})),(function(a){a.codec=()=>wi(r)})(e=t.Type||(t.Type={}));let n;t.codec=()=>(n==null&&(n=Re((a,c,u={})=>{if(u.lengthDelimited!==!1&&c.fork(),a.type!=null&&(c.uint32(8),t.Type.codec().encode(a.type,c)),a.data!=null&&(c.uint32(18),c.bytes(a.data)),a.fileSize!=null&&(c.uint32(24),c.uint64(a.fileSize)),a.blockSizes!=null&&a.blockSizes.length>0)for(let f of a.blockSizes)c.uint32(32),c.uint64(f);a.hashType!=null&&(c.uint32(40),c.uint64(a.hashType)),a.fanOut!=null&&(c.uint32(48),c.uint64(a.fanOut)),a.mode!=null&&(c.uint32(56),c.uint32(a.mode)),a.mtime!=null&&(c.uint32(66),er.codec().encode(a.mtime,c)),u.lengthDelimited!==!1&&c.ldelim()},(a,c,u={})=>{let f={blockSizes:[]},d=c==null?a.len:a.pos+c;for(;a.pos<d;){let m=a.uint32();switch(m>>>3){case 1:{f.type=t.Type.codec().decode(a);break}case 2:{f.data=a.bytes();break}case 3:{f.fileSize=a.uint64();break}case 4:{if(u.limits?.blockSizes!=null&&f.blockSizes.length===u.limits.blockSizes)throw new pe('Decode error - repeated field "blockSizes" had too many elements');f.blockSizes.push(a.uint64());break}case 5:{f.hashType=a.uint64();break}case 6:{f.fanOut=a.uint64();break}case 7:{f.mode=a.uint32();break}case 8:{f.mtime=er.codec().decode(a,a.uint32(),{limits:u.limits?.mtime});break}default:{a.skipType(m&7);break}}}return f},function*(a,c,u,f={}){let d={blockSizes:0},m=c==null?a.len:a.pos+c;for(u!=="."&&(yield{field:u.endsWith(".")?u.substring(0,u.length-1):u,type:"start",message:"UnixFS"});a.pos<m;){let w=a.uint32();switch(w>>>3){case 1:{yield{field:`${u}type`,value:t.Type.codec().decode(a)};break}case 2:{yield{field:`${u}data`,value:a.bytes()};break}case 3:{yield{field:`${u}fileSize`,value:a.uint64()};break}case 4:{if(f.limits?.blockSizes!=null&&d.blockSizes===f.limits.blockSizes)throw new pe('Streaming decode error - repeated field "blockSizes" had too many elements');yield{field:`${u}blockSizes[]`,index:d.blockSizes,value:a.uint64()},d.blockSizes++;break}case 5:{yield{field:`${u}hashType`,value:a.uint64()};break}case 6:{yield{field:`${u}fanOut`,value:a.uint64()};break}case 7:{yield{field:`${u}mode`,value:a.uint32()};break}case 8:{yield*er.codec().stream(a,a.uint32(),`${u}mtime.`,{limits:f.limits?.mtime});break}default:{a.skipType(w&7);break}}}u!=="."&&(yield{field:u.endsWith(".")?u.substring(0,u.length-1):u,type:"end",message:"UnixFS"})})),n);function i(a){return Le(a,t.codec())}t.encode=i;function o(a,c){return De(a,t.codec(),c)}t.decode=o;function s(a,c){return Ne(a,t.codec(),c)}t.stream=s})(U||(U={}));var er;(function(t){let e;t.codec=()=>(e==null&&(e=Re((o,s,a={})=>{a.lengthDelimited!==!1&&s.fork(),o.seconds!=null&&(s.uint32(8),s.int64(o.seconds)),o.fractionalNanoseconds!=null&&(s.uint32(21),s.fixed32(o.fractionalNanoseconds)),a.lengthDelimited!==!1&&s.ldelim()},(o,s)=>{let a={},c=s==null?o.len:o.pos+s;for(;o.pos<c;){let u=o.uint32();switch(u>>>3){case 1:{a.seconds=o.int64();break}case 2:{a.fractionalNanoseconds=o.fixed32();break}default:{o.skipType(u&7);break}}}return a},function*(o,s,a){let c=s==null?o.len:o.pos+s;for(a!=="."&&(yield{field:a.endsWith(".")?a.substring(0,a.length-1):a,type:"start",message:"UnixTime"});o.pos<c;){let u=o.uint32();switch(u>>>3){case 1:{yield{field:`${a}seconds`,value:o.int64()};break}case 2:{yield{field:`${a}fractionalNanoseconds`,value:o.fixed32()};break}default:{o.skipType(u&7);break}}}a!=="."&&(yield{field:a.endsWith(".")?a.substring(0,a.length-1):a,type:"end",message:"UnixTime"})})),e);function r(o){return Le(o,t.codec())}t.encode=r;function n(o,s){return De(o,t.codec(),s)}t.decode=n;function i(o,s){return Ne(o,t.codec(),s)}t.stream=i})(er||(er={}));var pa;(function(t){let e;t.codec=()=>(e==null&&(e=Re((o,s,a={})=>{a.lengthDelimited!==!1&&s.fork(),o.mimeType!=null&&(s.uint32(10),s.string(o.mimeType)),a.lengthDelimited!==!1&&s.ldelim()},(o,s)=>{let a={},c=s==null?o.len:o.pos+s;for(;o.pos<c;){let u=o.uint32();u>>>3===1?a.mimeType=o.string():o.skipType(u&7)}return a},function*(o,s,a){let c=s==null?o.len:o.pos+s;for(a!=="."&&(yield{field:a.endsWith(".")?a.substring(0,a.length-1):a,type:"start",message:"Metadata"});o.pos<c;){let u=o.uint32();u>>>3===1?yield{field:`${a}mimeType`,value:o.string()}:o.skipType(u&7)}a!=="."&&(yield{field:a.endsWith(".")?a.substring(0,a.length-1):a,type:"end",message:"Metadata"})})),e);function r(o){return Le(o,t.codec())}t.encode=r;function n(o,s){return De(o,t.codec(),s)}t.decode=n;function i(o,s){return Ne(o,t.codec(),s)}t.stream=i})(pa||(pa={}));var Ue;(function(t){let e;t.codec=()=>(e==null&&(e=Re((o,s,a={})=>{a.lengthDelimited!==!1&&s.fork(),o.hash!=null&&(s.uint32(10),s.bytes(o.hash)),o.name!=null&&(s.uint32(18),s.string(o.name)),o.tSize!=null&&(s.uint32(24),s.uint64(o.tSize)),a.lengthDelimited!==!1&&s.ldelim()},(o,s)=>{let a={},c=s==null?o.len:o.pos+s;for(;o.pos<c;){let u=o.uint32();switch(u>>>3){case 1:{a.hash=o.bytes();break}case 2:{a.name=o.string();break}case 3:{a.tSize=o.uint64();break}default:{o.skipType(u&7);break}}}return a},function*(o,s,a){let c=s==null?o.len:o.pos+s;for(a!=="."&&(yield{field:a.endsWith(".")?a.substring(0,a.length-1):a,type:"start",message:"Link"});o.pos<c;){let u=o.uint32();switch(u>>>3){case 1:{yield{field:`${a}hash`,value:o.bytes()};break}case 2:{yield{field:`${a}name`,value:o.string()};break}case 3:{yield{field:`${a}tSize`,value:o.uint64()};break}default:{o.skipType(u&7);break}}}a!=="."&&(yield{field:a.endsWith(".")?a.substring(0,a.length-1):a,type:"end",message:"Link"})})),e);function r(o){return Le(o,t.codec())}t.encode=r;function n(o,s){return De(o,t.codec(),s)}t.decode=n;function i(o,s){return Ne(o,t.codec(),s)}t.stream=i})(Ue||(Ue={}));var xt;(function(t){let e;t.codec=()=>(e==null&&(e=Re((o,s,a={})=>{if(a.lengthDelimited!==!1&&s.fork(),o.data!=null&&(s.uint32(10),U.codec().encode(o.data,s)),o.links!=null&&o.links.length>0)for(let c of o.links)s.uint32(18),Ue.codec().encode(c,s);a.lengthDelimited!==!1&&s.ldelim()},(o,s,a={})=>{let c={links:[]},u=s==null?o.len:o.pos+s;for(;o.pos<u;){let f=o.uint32();switch(f>>>3){case 1:{c.data=U.codec().decode(o,o.uint32(),{limits:a.limits?.data});break}case 2:{if(a.limits?.links!=null&&c.links.length===a.limits.links)throw new pe('Decode error - repeated field "links" had too many elements');c.links.push(Ue.codec().decode(o,o.uint32(),{limits:a.limits?.links$}));break}default:{o.skipType(f&7);break}}}return c},function*(o,s,a,c={}){let u={links:0},f=s==null?o.len:o.pos+s;for(a!=="."&&(yield{field:a.endsWith(".")?a.substring(0,a.length-1):a,type:"start",message:"Node"});o.pos<f;){let d=o.uint32();switch(d>>>3){case 1:{yield*U.codec().stream(o,o.uint32(),`${a}data.`,{limits:c.limits?.data});break}case 2:{if(c.limits?.links!=null&&u.links===c.limits.links)throw new pe('Streaming decode error - repeated field "links" had too many elements');for(let m of Ue.codec().stream(o,o.uint32(),`${a}links[].`,{limits:c.limits?.links$}))yield{...m,index:u.links};u.links++;break}default:{o.skipType(d&7);break}}}a!=="."&&(yield{field:a.endsWith(".")?a.substring(0,a.length-1):a,type:"end",message:"Node"})})),e);function r(o){return Le(o,t.codec())}t.encode=r;function n(o,s){return De(o,t.codec(),s)}t.decode=n;function i(o,s){return Ne(o,t.codec(),s)}t.stream=i})(xt||(xt={}));var ya;(function(t){let e;t.codec=()=>(e==null&&(e=Re((o,s,a={})=>{if(a.lengthDelimited!==!1&&s.fork(),o.links!=null&&o.links.length>0)for(let c of o.links)s.uint32(18),Ue.codec().encode(c,s);o.data!=null&&(s.uint32(10),U.codec().encode(o.data,s)),a.lengthDelimited!==!1&&s.ldelim()},(o,s,a={})=>{let c={links:[]},u=s==null?o.len:o.pos+s;for(;o.pos<u;){let f=o.uint32();switch(f>>>3){case 2:{if(a.limits?.links!=null&&c.links.length===a.limits.links)throw new pe('Decode error - repeated field "links" had too many elements');c.links.push(Ue.codec().decode(o,o.uint32(),{limits:a.limits?.links$}));break}case 1:{c.data=U.codec().decode(o,o.uint32(),{limits:a.limits?.data});break}default:{o.skipType(f&7);break}}}return c},function*(o,s,a,c={}){let u={links:0},f=s==null?o.len:o.pos+s;for(a!=="."&&(yield{field:a.endsWith(".")?a.substring(0,a.length-1):a,type:"start",message:"LegacyNode"});o.pos<f;){let d=o.uint32();switch(d>>>3){case 2:{if(c.limits?.links!=null&&u.links===c.limits.links)throw new pe('Streaming decode error - repeated field "links" had too many elements');for(let m of Ue.codec().stream(o,o.uint32(),`${a}links[].`,{limits:c.limits?.links$}))yield{...m,index:u.links};u.links++;break}case 1:{yield*U.codec().stream(o,o.uint32(),`${a}data.`,{limits:c.limits?.data});break}default:{o.skipType(d&7);break}}}a!=="."&&(yield{field:a.endsWith(".")?a.substring(0,a.length-1):a,type:"end",message:"LegacyNode"})})),e);function r(o){return Le(o,t.codec())}t.encode=r;function n(o,s){return De(o,t.codec(),s)}t.decode=n;function i(o,s){return Ne(o,t.codec(),s)}t.stream=i})(ya||(ya={}));var ga={RAW:"raw",DIRECTORY:"directory",FILE:"file",METADATA:"metadata",SYMLINK:"symlink",HAMT_SHARD:"hamt-sharded-directory"},il=["directory","hamt-sharded-directory"],wa=parseInt("0644",8),ba=parseInt("0755",8),B=class t{static unmarshal(e){let r=U.decode(e),n=new t({type:ga[r.type!=null?r.type.toString():"FILE"],data:r.data,blockSizes:r.blockSizes,mode:r.mode,mtime:r.mtime!=null?{secs:r.mtime.seconds??0n,nsecs:r.mtime.fractionalNanoseconds}:void 0,fanout:r.fanOut});return n._originalMode=r.mode??0,n}type;data;blockSizes;hashType;fanout;mtime;_mode;_originalMode;constructor(e={type:"file"}){let{type:r,data:n,blockSizes:i,hashType:o,fanout:s,mtime:a,mode:c}=e;if(r!=null&&!Object.values(ga).includes(r))throw new Kt("Type: "+r+" is not valid");this.type=r??"file",this.hashType=o,this.fanout=s,this.blockSizes=i??[],this._originalMode=0,this.mode=c,this.mtime=a,n!=null&&(this.data=Wr(n))}set mode(e){e==null?this._mode=this.isDirectory()?ba:wa:this._mode=e&4095}get mode(){return this._mode}isDirectory(){return il.includes(this.type)}addBlockSize(e){this.blockSizes.push(e)}removeBlockSize(e){this.blockSizes.splice(e,1)}fileSize(){if(this.isDirectory())return 0n;let e=0n;return this.blockSizes.forEach(r=>{e+=r}),this.data!=null&&(e+=BigInt(this.data.length)),e}marshal(){let e;switch(this.type){case"raw":e=U.Type.RAW;break;case"directory":e=U.Type.DIRECTORY;break;case"file":e=U.Type.FILE;break;case"metadata":e=U.Type.METADATA;break;case"symlink":e=U.Type.SYMLINK;break;case"hamt-sharded-directory":e=U.Type.HAMT_SHARD;break;default:throw new Kt(`Type: ${e} is not valid`)}let r=this.data;(this.data==null||this.data.length===0)&&(r=void 0);let n;this.mode!=null&&(n=this._originalMode&4294963200|(this.mode??0),n===wa&&!this.isDirectory()&&(n=void 0),n===ba&&this.isDirectory()&&(n=void 0));let i;return this.mtime!=null&&(i={seconds:this.mtime.secs,fractionalNanoseconds:this.mtime.nsecs}),U.encode({type:e,data:r,fileSize:this.type==="file"||this.type==="raw"?this.fileSize():void 0,blockSizes:this.blockSizes,hashType:this.hashType,fanOut:this.fanout,mode:n,mtime:i})}};function Kr(t){return t.type==="DIRECTORY"}function bi(t){return t.type==="FILE"}function xi(t){return t.type==="RAW"}function ki(t){return t.type==="SYMLINK"}function Pe(t){return t.type==="HAMT_SHARD"&&t.data instanceof Uint8Array&&typeof t.fanOut=="bigint"&&typeof t.hashType=="bigint"}function ye(t){return typeof t.name=="string"&&k.asCID(t.hash)===t.hash}function*Jr(t){let e={},r={};for(let n of xt.stream(t))switch(n.field){case".data":{if(n.type==="start"&&(r={}),n.type==="end"){if(Kr(r)||Pe(r)||bi(r)||xi(r)||ki(r)){yield r;return}throw new v("PBNode Data was not a valid UnixFS type")}break}case".data.type":{r.type=n.value;break}case".data.data":{r.data=n.value;break}case".data.fanOut":{r.fanOut=n.value;break}case".data.hashType":{r.hashType=n.value;break}case".links[]":{n.type==="start"&&(e={type:"LINK"}),n.type==="end"&&ye(e)&&(yield e);break}case".links[].name":{e.name=n.value;break}case".links[].hash":{e.hash=k.decode(n.value);break}default:}}var xa=(t,e)=>t.toString(16).toUpperCase().padStart(e,"0").substring(0,e),ol=t=>{let e=t.bucket,r=[];for(;e._parent!=null;)r.push(e),e=e._parent;return r.push(e),r.reverse()};async function*Xr(t,e,r,n,i,o,s){let a=(o.lastBucket.tableSize()-1).toString(16).length,c=[];for(let y of e){if(!ye(y))throw new v("Invalid link");if(c.push(y),y.name.length===a){let _=parseInt(y.name,16);o.lastBucket._putObjectAt(_,new ue({hash:o.lastBucket._options.hash,bits:o.lastBucket._options.bits},o.lastBucket,_))}if(y.name.substring(a)===r){yield{cid:y.hash,name:r,rest:n};return}await o.rootBucket.put(y.name.substring(a),!0)}let u=await o.rootBucket._findNewBucketAndPos(r),f=xa(u.pos,a),d=ol(u);d.length>o.hamtDepth&&(o.lastBucket=d[o.hamtDepth],f=xa(o.lastBucket._posAtParent,a));let m=c.find(y=>y.name==null?!1:y.name===f);if(m==null)return;o.hamtDepth++;let w=await S(i.get(m.hash,s));s?.yieldSubShards===!0&&(yield{cid:m.hash,name:m.name,rest:[r,...n]});let x=Jr(w),{value:b}=x.next();if(c=[],b!=null){if(Pe(b)){yield*Xr(b,x,r,n,i,o,s);return}if(!ye(b))throw new v("Did not read Link or Data from dag-pb block");c.push(b);for(let y of x){if(Pe(y)){yield*Xr(y,c,r,n,i,o,s);return}if(!ye(y))throw new v("Did not read Link or Data from dag-pb block");c.push(y)}}}function*ka(t,e,r){for(let n of t){if(!ye(n))throw new v("Invalid link");if(n.name===e[0]){yield{cid:n.hash,name:e[0],rest:e.slice(1)};return}}throw new H(`No link "${e[0]}" found under ${r}`)}var sl=async function(t){return(await $r.encode(t)).slice(0,8).reverse()};async function*Ea(t,e,r,n,i,o){let s=Vr({hashFn:sl,bits:Math.log2(Number(t.fanOut))}),a={rootBucket:s,hamtDepth:1,lastBucket:s};for await(let c of Xr(t,e,r[0],r.slice(1),i,a,o))if(yield c,c.name===r[0])return;throw new H(`No link "${r[0]}" found under ${n}`)}async function*_a(t,e,r,n){let i=await S(r.get(t,n)),o=[],s=Jr(i),{value:a}=s.next(),c=!1,u=!1;if(a!=null){if(u=Kr(a),c=Pe(a),bi(a)||xi(a)||ki(a)){yield{cid:t,name:e[0],rest:e.slice(1)};return}if(u||c&&n?.translateHAMTPath===!1){yield*ka(s,e,t);return}if(c){yield*Ea(a,s,e,t,r,n);return}if(!ye(a))throw new v("Did not read Link or Data from dag-pb block");o.push(a);for(let f of s){if(u=Kr(f),c=Pe(f),u||c&&n?.translateHAMTPath===!1){yield*ka(o,e,t);return}if(Pe(f)){yield*Ea(f,o,e,t,r,n);return}if(!ye(f))throw new v("Did not read Link or Data from dag-pb block");o.push(f)}}throw new H(`No link "${e[0]}" found under ${t}`)}async function*Aa(t,e,r,n){if(e.length!==0)throw new ht(`Cannot load path /${e.join("/")} from identity block`)}async function*Ia(t,e,r,n){let i=await S(r.get(t,n)),o=Or(i),s=wt(o,e);yield{cid:t,name:s.path,rest:s.rest}}async function*Sa(t,e,r,n){if(e.length!==0)throw new H(`Cannot load path /${e.join("/")} from raw block`)}var cl={[Ge]:_a,[ce]:Sa,[Sr]:Kn,81:Kn,[Rr]:Os,[Yt.code]:Aa,[zr]:Ia};async function*Ta(t,e,r={}){for(t=t.toString(),t.startsWith("/ipfs/")&&(t=t.substring(6));t.endsWith("/");)t=t.substring(0,t.length-1);let[n,...i]=t.split(/(?<!\\)\//g).filter(Boolean),o=k.parse(n),s=[o],a=`${o}`;for(yield{cid:o,name:a,path:a,roots:s,remainder:i};i.length>0;){let c=cl[o.code];if(c==null)throw new mt(`No resolver for code ${o.code}`);let u=!1;for await(let f of c(o,i,e,r)){if(o=f.cid,u=!s[s.length-1].equals(o),i=f.rest,!u)break;s=[...s,f.cid],a=`${a}/${f.name}`,yield{cid:f.cid,name:f.name,path:a,roots:s,remainder:f.rest}}if(!u)break}if(r?.signal?.throwIfAborted(),i.length!==0)throw new H(`Could not resolve path /${i.join("/")} under ${t}`)}function ul(t){return t[Symbol.asyncIterator]!=null}function fl(t){if(ul(t))return(async()=>{let r;for await(let n of t)r=n;return r})();let e;for(let r of t)e=r;return e}var va=fl;async function Ei(t,e,r,n,i){let o=await S(n.get(t,i)),s=We(o);return{type:"object",cid:t,name:e,path:r,object:s,node:o,size:BigInt(o.byteLength)}}async function Ba(t,e,r,n,i){let o=await S(n.get(t,i)),s=Ur(o);return{type:"object",cid:t,name:e,path:r,object:s,node:o,size:BigInt(o.byteLength)}}var N=class extends Event{type;detail;constructor(e,r){super(e),this.type=e,this.detail=r}};function tr(t,e,r,n){let i=BigInt(t.length),o=BigInt(e+i);return r>=o||n<e?new Uint8Array(0):(n>=e&&n<o&&(t=t.subarray(0,Number(n-e))),r>=e&&r<o&&(t=t.subarray(Number(r-e))),t)}var Zr=(t,e=0,r=t)=>{let n=BigInt(t),i=BigInt(e??0),o=BigInt(r);if(o!==n&&(o=i+o),o>n&&(o=n),i<0n)throw new he("Offset must be greater than or equal to 0");if(i>n)throw new he("Offset must be less than the file size");if(o<0n)throw new he("Length must be greater than or equal to 0");if(o>n)throw new he("Length must be less than the file size");return{start:i,end:o}};function Qr(t,e){async function*r(n={}){let{start:i,end:o}=Zr(t.length,n.offset,n.length),s=tr(t,0n,i,o);n.onProgress?.(new N(e,{bytesRead:BigInt(s.byteLength),totalBytes:o-i,fileSize:BigInt(t.byteLength)})),yield s}return r}async function Ca(t,e,r,n,i){let o=et(t.multihash.bytes);return{type:"identity",cid:t,name:e,path:r,content:Qr(o.digest,"unixfs:exporter:progress:identity"),size:BigInt(o.bytes.byteLength),node:o.bytes}}async function Da(t,e,r,n,i){let o=await S(n.get(t,i)),s=Or(o);return{type:"object",cid:t,name:e,path:r,object:s,size:BigInt(o.byteLength),node:o}}async function La(t,e,r,n,i){let o=await S(n.get(t,i));return{type:"raw",cid:t,name:e,path:r,content:Qr(o,"unixfs:exporter:progress:raw"),size:BigInt(o.length),node:o}}function Na(t,e,r,n){async function*i(o={}){let s=o.offset??0,a=o.length??e.Links.length,c=e.Links.slice(s,s+a);o.onProgress?.(new N("unixfs:exporter:walk:directory",{cid:t})),yield*c.map(u=>({cid:u.Hash,name:u.Name??"",path:`${n}/${u.Name??""}`,size:BigInt(u.Tsize??0)}))}return i}function ll(t){let[e,r]=t[Symbol.asyncIterator]!=null?[t[Symbol.asyncIterator](),Symbol.asyncIterator]:[t[Symbol.iterator](),Symbol.iterator],n=[];return{peek:()=>e.next(),push:i=>{n.push(i)},next:()=>n.length>0?{done:!1,value:n.shift()}:e.next(),[r](){return this}}}var Ra=ll;function dl(t){return t[Symbol.asyncIterator]!=null}function hl(t,e){let r=0;if(dl(t))return(async function*(){for await(let c of t)yield e(c,r++)})();let n=Ra(t),{value:i,done:o}=n.next();if(o===!0)return(function*(){})();let s=e(i,r++);if(typeof s.then=="function")return(async function*(){yield await s;for(let c of n)yield e(c,r++)})();let a=e;return(function*(){yield s;for(let c of n)yield a(c,r++)})()}var Ua=hl;function V(){let t={};return t.promise=new Promise((e,r)=>{t.resolve=e,t.reject=r}),t}var en=globalThis.CustomEvent??Event;async function*_i(t,e={}){let r=e.concurrency??1/0;r<1&&(r=1/0);let n=e.ordered??!1,i=new EventTarget,o=[],s=V(),a=V(),c=!1,u,f=!1,d=!1;i.addEventListener("task-complete",()=>{a.resolve()}),Promise.resolve().then(async()=>{try{for await(let b of t){if(o.length===r&&(s=V(),await s.promise),f||d)break;let y={done:!1};o.push(y),b().then(_=>{y.done=!0,y.ok=!0,y.value=_,i.dispatchEvent(new en("task-complete"))},_=>{y.done=!0,y.err=_,i.dispatchEvent(new en("task-complete"))})}c=!0,i.dispatchEvent(new en("task-complete"))}catch(b){u=b,i.dispatchEvent(new en("task-complete"))}});function m(){return n?o[0]?.done:!!o.find(b=>b.done)}function*w(){for(;o.length>0&&o[0].done;){let b=o[0];if(o.shift(),b.ok)yield b.value;else throw f=!0,s.resolve(),b.err;s.resolve()}}function*x(){for(;m();)for(let b=0;b<o.length;b++)if(o[b].done){let y=o[b];if(o.splice(b,1),b--,y.ok)yield y.value;else throw f=!0,s.resolve(),y.err;s.resolve()}}try{for(;;){if(m()||(a=V(),await a.promise),u!=null||(n?yield*w():yield*x(),u!=null))throw u;if(c&&o.length===0)break}}finally{d=!0,s.resolve()}}var tn=class{buffer;mask;top;btm;next;constructor(e){if(!(e>0)||(e-1&e)!==0)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(e),this.mask=e-1,this.top=0,this.btm=0,this.next=null}push(e){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=e,this.top=this.top+1&this.mask,!0)}shift(){let e=this.buffer[this.btm];if(e!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,e}isEmpty(){return this.buffer[this.btm]===void 0}},kt=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new tn(this.hwm),this.tail=this.head,this.size=0}calculateSize(e){return e?.byteLength!=null?e.byteLength:1}push(e){if(e?.value!=null&&(this.size+=this.calculateSize(e.value)),!this.head.push(e)){let r=this.head;this.head=r.next=new tn(2*this.head.buffer.length),this.head.push(e)}}shift(){let e=this.tail.shift();if(e===void 0&&this.tail.next!=null){let r=this.tail.next;this.tail.next=null,this.tail=r,e=this.tail.shift()}return e?.value!=null&&(this.size-=this.calculateSize(e.value)),e}isEmpty(){return this.head.isEmpty()}};var Ai=class extends Error{type;code;constructor(e,r){super(e??"The operation was aborted"),this.type="aborted",this.code=r??"ABORT_ERR"}};function rn(t={}){return ml(r=>{let n=r.shift();if(n==null)return{done:!0};if(n.error!=null)throw n.error;return{done:n.done===!0,value:n.value}},t)}function ml(t,e){e=e??{};let r=e.onEnd,n=new kt,i,o,s,a=V(),c=async()=>{try{return n.isEmpty()?s?{done:!0}:await new Promise((y,_)=>{o=C=>{o=null,n.push(C);try{y(t(n))}catch(E){_(E)}return i}}):t(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=V()})}},u=y=>o!=null?o(y):(n.push(y),i),f=y=>(n=new kt,o!=null?o({error:y}):(n.push({error:y}),i)),d=y=>{if(s)return i;if(e?.objectMode!==!0&&y?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return u({done:!1,value:y})},m=y=>s?i:(s=!0,y!=null?f(y):u({done:!0})),w=()=>(n=new kt,m(),{done:!0}),x=y=>(m(y),{done:!0});if(i={[Symbol.asyncIterator](){return this},next:c,return:w,throw:x,push:d,end:m,get readableLength(){return n.size},onEmpty:async y=>{let _=y?.signal;if(_?.throwIfAborted(),n.isEmpty())return;let C,E;_!=null&&(C=new Promise((ze,Q)=>{E=()=>{Q(new Ai)},_.addEventListener("abort",E)}));try{await Promise.race([a.promise,C])}finally{E!=null&&_!=null&&_?.removeEventListener("abort",E)}}},r==null)return i;let b=i;return i={[Symbol.asyncIterator](){return this},next(){return b.next()},throw(y){return b.throw(y),r!=null&&(r(y),r=void 0),{done:!0}},return(){return b.return(),r!=null&&(r(),r=void 0),{done:!0}},push:d,end(y){return b.end(y),r!=null&&(r(y),r=void 0),i},get readableLength(){return b.readableLength},onEmpty:y=>b.onEmpty(y)},i}function pl(t){return t.reason}function Pa(t,e,r){if(e==null||t==null)return t;let n=r?.translateError??pl;if(e.aborted)return t.catch(()=>{}),Promise.reject(n(e));let i;return Promise.race([t,new Promise((o,s)=>{i=()=>{s(n(e))},e.addEventListener("abort",i)})]).finally(()=>{i!=null&&e.removeEventListener("abort",i)})}var Ii=class{readNext;haveNext;ended;nextResult;error;constructor(){this.ended=!1,this.readNext=V(),this.haveNext=V()}[Symbol.asyncIterator](){return this}async next(){if(this.nextResult==null&&await this.haveNext.promise,this.nextResult==null)throw new Error("HaveNext promise resolved but nextResult was undefined");let e=this.nextResult;return this.nextResult=void 0,this.readNext.resolve(),this.readNext=V(),e}async throw(e){return this.ended=!0,this.error=e,e!=null&&(this.haveNext.promise.catch(()=>{}),this.haveNext.reject(e)),{done:!0,value:void 0}}async return(){let e={done:!0,value:void 0};return this.ended=!0,this.nextResult=e,this.haveNext.resolve(),e}async push(e,r){await this._push(e,r)}async end(e,r){e!=null?await this.throw(e):await this._push(void 0,r)}async _push(e,r){if(e!=null&&this.ended)throw this.error??new Error("Cannot push value onto an ended pushable");for(;this.nextResult!=null;)await this.readNext.promise;e!=null?this.nextResult={done:!1,value:e}:(this.ended=!0,this.nextResult={done:!0,value:void 0}),this.haveNext.resolve(),this.haveNext=V(),await Pa(this.readNext.promise,r?.signal,r)}};function Fa(){return new Ii}function za(t){return t[Symbol.asyncIterator]!=null}async function yl(t,e,r){try{await Promise.all(t.map(async n=>{for(;;){let{value:i,done:o}=await n.next();if(o===!0)break;await e.push(i,{signal:r}),r.throwIfAborted()}})),await e.end(void 0,{signal:r})}catch(n){await e.end(n,{signal:r}).catch(()=>{})}}async function*gl(t){let e=new AbortController,r=Fa(),n=t.map(i=>za(i)?i[Symbol.asyncIterator]():i[Symbol.iterator]());yl(n,r,e.signal).catch(()=>{});try{yield*r}finally{e.abort();for(let i of n)try{Promise.resolve(i.return?.()).catch(()=>{})}catch{}}}function*wl(t){for(let e of t)yield*e}function bl(...t){let e=[];for(let r of t)za(r)||e.push(r);return e.length===t.length?wl(e):gl(t)}var Oa=bl;function $a(t,...e){if(t==null)throw new Error("Empty pipeline");if(Si(t)){let n=t;t=()=>n.source}else if(Ha(t)||Ma(t)){let n=t;t=()=>n}let r=[t,...e];if(r.length>1&&Si(r[r.length-1])&&(r[r.length-1]=r[r.length-1].sink),r.length>2)for(let n=1;n<r.length-1;n++)Si(r[n])&&(r[n]=kl(r[n]));return xl(...r)}var xl=(...t)=>{let e;for(;t.length>0;)e=t.shift()(e);return e},Ma=t=>t?.[Symbol.asyncIterator]!=null,Ha=t=>t?.[Symbol.iterator]!=null,Si=t=>t==null?!1:t.sink!=null&&t.source!=null,kl=t=>e=>{let r=t.sink(e);if(r?.then!=null){let n=rn({objectMode:!0});r.then(()=>{n.end()},s=>{n.end(s)});let i,o=t.source;if(Ma(o))i=async function*(){yield*o,n.end()};else if(Ha(o))i=function*(){yield*o,n.end()};else throw new Error("Unknown duplex source type - must be Iterable or AsyncIterable");return Oa(n,i())}return t.source};var vi=At(Wa(),1);var Bi=class t extends Error{name="TimeoutError";constructor(e,r){super(e,r),Error.captureStackTrace?.(this,t)}},qa=t=>t.reason??new DOMException("This operation was aborted.","AbortError");function Ci(t,e){let{milliseconds:r,fallback:n,message:i,customTimers:o={setTimeout,clearTimeout},signal:s}=e,a,c,f=new Promise((d,m)=>{if(typeof r!="number"||Math.sign(r)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${r}\``);if(s?.aborted){m(qa(s)),t.then(d,m);return}if(s&&(c=()=>{m(qa(s))},s.addEventListener("abort",c,{once:!0})),t.then(d,m),r===Number.POSITIVE_INFINITY)return;let w=new Bi;a=o.setTimeout.call(void 0,()=>{if(n){try{d(n())}catch(x){m(x)}return}typeof t.cancel=="function"&&t.cancel(),i===!1?d():i instanceof Error?m(i):(w.message=i??`Promise timed out after ${r} milliseconds`,m(w))},r)}).finally(()=>{f.clear(),c&&s&&s.removeEventListener("abort",c)});return f.clear=()=>{o.clearTimeout.call(void 0,a),a=void 0},f}function Di(t,e,r){let n=0,i=t.length;for(;i>0;){let o=Math.trunc(i/2),s=n+o;r(t[s],e)<=0?(n=++s,i-=o+1):i=o}return n}var Al=100,Et=class{#t=[];#e=0;enqueue(e,r){let{priority:n=0,id:i}=r??{},{size:o}=this,s={priority:n,id:i,run:e};if(o===0){this.#t.length=0,this.#e=0,this.#t.push(s);return}if(this.#t.at(-1).priority>=n){this.#t.push(s);return}this.#o();let a=Di(this.#t,s,(c,u)=>u.priority-c.priority);this.#t.splice(a,0,s)}setPriority(e,r){let n=this.#t.findIndex((o,s)=>s>=this.#e&&o.id===e);if(n===-1)throw new ReferenceError(`No promise function with the id "${e}" exists in the queue.`);let[i]=this.#t.splice(n,1);this.enqueue(i.run,{priority:r,id:e})}remove(e){let r=this.#t.findIndex((n,i)=>i<this.#e?!1:typeof e=="string"?n.id===e:n.run===e);r!==-1&&this.#t.splice(r,1)}dequeue(){if(this.#e===this.#t.length)return;let e=this.#t[this.#e];return this.#e++,this.#e===this.#t.length?(this.#t.length=0,this.#e=0):this.#e>Al&&this.#e>this.#t.length/2&&this.#o(),e?.run}filter(e){let r=[];for(let n=this.#e;n<this.#t.length;n++){let i=this.#t[n];i.priority===e.priority&&r.push(i.run)}return r}get size(){return this.#t.length-this.#e}#o(){this.#e!==0&&(this.#t.splice(0,this.#e),this.#e=0)}};var nr=class extends vi.default{#t;#e;#o=0;#h;#p=!1;#b=!1;#u;#x=0;#c;#f;#a;#s=[];#i=0;#r;#S;#n=0;#y;#l;#L=1n;#g=new Map;#k=new Set;timeout;constructor(e){if(super(),e={carryoverIntervalCount:!1,intervalCap:Number.POSITIVE_INFINITY,interval:0,concurrency:Number.POSITIVE_INFINITY,autoStart:!0,queueClass:Et,strict:!1,...e},!(typeof e.intervalCap=="number"&&e.intervalCap>=1))throw new TypeError(`Expected \`intervalCap\` to be a number from 1 and up, got \`${e.intervalCap?.toString()??""}\` (${typeof e.intervalCap})`);if(e.interval===void 0||!(Number.isFinite(e.interval)&&e.interval>=0))throw new TypeError(`Expected \`interval\` to be a finite number >= 0, got \`${e.interval?.toString()??""}\` (${typeof e.interval})`);if(e.strict&&e.interval===0)throw new TypeError("The `strict` option requires a non-zero `interval`");if(e.strict&&e.intervalCap===Number.POSITIVE_INFINITY)throw new TypeError("The `strict` option requires a finite `intervalCap`");if(this.#t=e.carryoverIntervalCount??e.carryoverConcurrencyCount??!1,this.#e=e.intervalCap===Number.POSITIVE_INFINITY||e.interval===0,this.#h=e.intervalCap,this.#u=e.interval,this.#a=e.strict,this.#r=new e.queueClass,this.#S=e.queueClass,this.concurrency=e.concurrency,e.timeout!==void 0&&!(Number.isFinite(e.timeout)&&e.timeout>0))throw new TypeError(`Expected \`timeout\` to be a positive finite number, got \`${e.timeout}\` (${typeof e.timeout})`);this.timeout=e.timeout,this.#l=e.autoStart===!1,this.#$()}#E(e){for(;this.#i<this.#s.length;){let n=this.#s[this.#i];if(n!==void 0&&e-n>=this.#u)this.#i++;else break}(this.#i>100&&this.#i>this.#s.length/2||this.#i===this.#s.length)&&(this.#s=this.#s.slice(this.#i),this.#i=0)}#N(e){this.#a?this.#s.push(e):this.#o++}#R(){this.#a?this.#s.length>this.#i&&this.#s.pop():this.#o>0&&this.#o--}#_(){return this.#s.length-this.#i}get#U(){return this.#e?!0:this.#a?this.#_()<this.#h:this.#o<this.#h}get#P(){return this.#n<this.#y}#F(){this.#n--,this.#n===0&&this.emit("pendingZero"),this.#w(),this.emit("next")}#z(){this.#f=void 0,this.#C(),this.#B()}#O(e){if(this.#a){if(this.#E(e),this.#_()>=this.#h){let n=this.#s[this.#i],i=this.#u-(e-n);return this.#T(i),!0}return!1}if(this.#c===void 0){let r=this.#x-e;if(r<0)this.#o=this.#t?this.#n:0;else return this.#T(r),!0}return!1}#T(e){this.#f===void 0&&(this.#f=setTimeout(()=>{this.#z()},e))}#A(){this.#c&&(clearInterval(this.#c),this.#c=void 0)}#v(){this.#f&&(clearTimeout(this.#f),this.#f=void 0)}#w(){if(this.#r.size===0){if(this.#A(),this.emit("empty"),this.#n===0){if(this.#v(),this.#a&&this.#i>0){let r=Date.now();this.#E(r)}this.emit("idle")}return!1}let e=!1;if(!this.#l){let r=Date.now(),n=!this.#O(r);if(this.#U&&this.#P){let i=this.#r.dequeue();this.#e||(this.#N(r),this.#m()),n&&this.#B(),this.emit("active"),i(),e=!0}}return e}#B(){this.#e||this.#c!==void 0||this.#a||(this.#c=setInterval(()=>{this.#C()},this.#u),this.#x=Date.now()+this.#u)}#C(){this.#a||(this.#c!==void 0&&(this.#o===0&&this.#n===0?this.#A():this.#x=Date.now()+this.#u),this.#o=this.#t?this.#n:0),this.#I(),this.#m()}#I(){for(;this.#w(););}get concurrency(){return this.#y}set concurrency(e){if(!(typeof e=="number"&&e>=1))throw new TypeError(`Expected \`concurrency\` to be a number from 1 and up, got \`${e}\` (${typeof e})`);this.#y=e,this.#I()}setPriority(e,r){if(typeof r!="number"||!Number.isFinite(r))throw new TypeError(`Expected \`priority\` to be a finite number, got \`${r}\` (${typeof r})`);this.#r.setPriority(e,r)}async add(e,r={}){if(r={timeout:this.timeout,...r,id:r.id??(this.#L++).toString()},r.timeout!==void 0&&!(Number.isFinite(r.timeout)&&r.timeout>0))throw new TypeError(`Expected \`timeout\` to be a positive finite number, got \`${r.timeout}\` (${typeof r.timeout})`);return new Promise((n,i)=>{let o=Symbol(`task-${r.id}`),s=()=>{},a=async()=>{s(),this.#n++,this.#g.set(o,{id:r.id,priority:r.priority??0,startTime:Date.now(),timeout:r.timeout});let u;try{try{r.signal?.throwIfAborted()}catch(m){throw this.#M(),this.#g.delete(o),m}let f=e({signal:r.signal});if(r.timeout!==void 0&&(f=Ci(Promise.resolve(f),{milliseconds:r.timeout,message:`Task timed out after ${r.timeout}ms (queue has ${this.#n} running, ${this.#r.size} waiting)`})),r.signal){let{signal:m}=r;f=Promise.race([f,new Promise((w,x)=>{u=()=>{x(m.reason)},m.addEventListener("abort",u,{once:!0})})])}let d=await f;n(d),this.emit("completed",d)}catch(f){i(f),this.emit("error",f)}finally{u&&r.signal?.removeEventListener("abort",u),this.#g.delete(o),queueMicrotask(()=>{this.#F()})}};this.#r.enqueue(a,r);let c=()=>{if(this.#r instanceof Et){this.#r.remove(a);return}this.#r.remove?.(r.id)};if(r.signal){let{signal:u}=r,f=()=>{s(),c(),i(u.reason),this.#w(),this.emit("next")};if(s=()=>{u.removeEventListener("abort",f),this.#k.delete(s)},u.aborted){f();return}u.addEventListener("abort",f,{once:!0}),this.#k.add(s)}this.emit("add"),this.#w()})}async addAll(e,r){return Promise.all(e.map(async n=>this.add(n,r)))}start(){return this.#l?(this.#l=!1,this.#I(),this):this}pause(){this.#l=!0}clear(){for(let e of this.#k)e();this.#r=new this.#S,this.#A(),this.#D(),this.emit("empty"),this.#n===0&&(this.#v(),this.emit("idle")),this.emit("next")}async onEmpty(){this.#r.size!==0&&await this.#d("empty")}async onSizeLessThan(e){this.#r.size<e||await this.#d(["next","active"],()=>this.#r.size<e)}async onIdle(){this.#n===0&&this.#r.size===0||await this.#d("idle")}async onPendingZero(){this.#n!==0&&await this.#d("pendingZero")}async onRateLimit(){this.isRateLimited||await this.#d("rateLimit")}async onRateLimitCleared(){this.isRateLimited&&await this.#d("rateLimitCleared")}onError(){return new Promise((e,r)=>{let n=i=>{this.off("error",n),r(i)};this.on("error",n)})}async#d(e,r){let n=Array.isArray(e)?e:[e];return new Promise(i=>{let o=()=>{if(!(r&&!r())){for(let s of n)this.off(s,o);i()}};for(let s of n)this.on(s,o)})}get size(){return this.#r.size}sizeBy(e){return this.#r.filter(e).length}get pending(){return this.#n}get isPaused(){return this.#l}#$(){this.#e||(this.on("add",()=>{this.#r.size>0&&this.#m()}),this.on("next",()=>{this.#m()}))}#m(){this.#e||this.#b||(this.#b=!0,queueMicrotask(()=>{this.#b=!1,this.#D()}))}#M(){this.#e||(this.#R(),this.#m())}#D(){let e=this.#p;if(this.#e||this.#r.size===0){e&&(this.#p=!1,this.emit("rateLimitCleared"));return}let r;if(this.#a){let i=Date.now();this.#E(i),r=this.#_()}else r=this.#o;let n=r>=this.#h;n!==e&&(this.#p=n,this.emit(n?"rateLimit":"rateLimitCleared"))}get isRateLimited(){return this.#p}get isSaturated(){return this.#n===this.#y&&this.#r.size>0||this.isRateLimited&&this.#r.size>0}get runningTasks(){return[...this.#g.values()].map(e=>({...e,timeoutRemaining:e.timeout?Math.max(0,e.startTime+e.timeout-Date.now()):void 0}))}};async function Ga(t,e,r,n,i,o,s){if(e instanceof Uint8Array){let u=tr(e,n,i,o);r.push(u);return}if(e.Data==null)throw new v("no data in PBNode");let a;try{a=B.unmarshal(e.Data)}catch(u){throw new v(u.message)}if(a.data!=null){let u=a.data,f=tr(u,n,i,o);r.push(f),n+=BigInt(f.byteLength)}let c=[];if(e.Links.length!==a.blockSizes.length)throw new v("Inconsistent block sizes and dag links");for(let u=0;u<e.Links.length;u++){let f=e.Links[u],d=n,m=d+a.blockSizes[u];if((i>=d&&i<m||o>=d&&o<=m||i<d&&o>m)&&c.push({link:f,blockStart:n}),n=m,n>o)break}await $a(c,u=>Ua(u,f=>async()=>{let d=await S(t.get(f.link.Hash,s));return{...f,block:d}}),u=>_i(u,{ordered:!0,concurrency:s.blockReadConcurrency??10}),async u=>{for await(let{link:f,block:d,blockStart:m}of u){let w;switch(f.Hash.code){case Ge:w=Gt(d);break;case ce:w=d;break;default:r.end(new v(`Unsupported codec: ${f.Hash.code}`));return}let x=new nr({concurrency:1});x.on("error",b=>{r.end(b)}),x.add(async()=>{s.onProgress?.(new N("unixfs:exporter:walk:file",{cid:f.Hash})),await Ga(t,w,r,m,i,o,s)}),await x.onIdle()}}),n>=o&&r.end()}function Li(t,e,r,n,i){async function*o(s={}){let a=r.fileSize();if(a===void 0)throw new Error("File was a directory");let{start:c,end:u}=Zr(a,s.offset,s.length);if(u===0n)return;let f=0n,d=u-c,m=rn();s.onProgress?.(new N("unixfs:exporter:walk:file",{cid:t})),Ga(i,e,m,0n,c,u,s).catch(w=>{m.end(w)});for await(let w of m)if(w!=null){if(f+=BigInt(w.byteLength),f>d)throw m.end(),new Lr("Read too many bytes - the file size reported by the UnixFS data in the root node may be incorrect");f===d&&m.end(),s.onProgress?.(new N("unixfs:exporter:progress:unixfs:file",{bytesRead:f,totalBytes:d,fileSize:a})),yield w}if(f<d)throw new Nr("Traversed entire DAG but did not read enough bytes")}return o}async function*Il(t,e,r,n){let i=-1,o=0;for await(let s of ja(t,e,r,n))if(i++,!(n.offset!=null&&n.offset<i)&&(yield s,o++,n.length!=null&&n.length===o))return}async function*ja(t,e,r,n){let i=await S(r.get(t,n)),o=xt.decode(i);if(o.data?.fanOut==null)throw new v("missing fanout");let s=(o.data.fanOut-1n).toString(16).length;for(let a of o.links){if(a.name==null||a.hash==null)continue;let c=k.decode(a.hash);if(a.name.length===s)yield*ja(c,e,r,n);else{let u=a.name.substring(s);yield{cid:c,name:a.name.substring(s),path:`${e}/${u}`,size:BigInt(a.tSize??0)}}}}function Ya(t,e,r,n,i){function o(s={}){return s.onProgress?.(new N("unixfs:exporter:walk:hamt-sharded-directory",{cid:t})),Il(t,n,i,s)}return o}var Sl={raw:Li,file:Li,directory:Na,"hamt-sharded-directory":Ya,metadata:(t,e,r,n)=>()=>[],symlink:(t,e,r,n)=>()=>[]};async function Ka(t,e,r,n,i){let o=await S(n.get(t,i)),s;try{s=Gt(o)}catch(u){throw new v(u.message)}if(s.Data==null)throw new v("no data in PBNode");let a;try{a=B.unmarshal(s.Data)}catch(u){throw new v(u.message)}let c=Sl[a.type](t,s,a,r,n);if(c==null)throw new H("could not find content exporter");return a.isDirectory()?{type:"directory",cid:t,name:e,path:r,entries:c,unixfs:a,node:s,size:BigInt(o.byteLength)}:{type:"file",cid:t,name:e,path:r,content:c,unixfs:a,node:s,size:a.fileSize()}}var Tl={[Ge]:Ka,[ce]:La,[Sr]:Ei,81:Ei,[Rr]:Ba,[Yt.code]:Ca,[zr]:Da};async function Ja(t,e,r={}){let n,i;if(t instanceof String||typeof t=="string"){let s=await va(Ta(t,e,r));if(s==null)throw new H(`Could not walk path to ${t}`);n=s.cid,i=s.name,t=s.path}else if(k.asCID(t)===t||t instanceof k)n=t,i=t=n.toString();else throw new he("Path must be string or CID");let o=Tl[n.code];if(o==null)throw new mt(`No resolver for code ${n.code}`);return o(n,i,t,e,r)}function vl(t){return t[Symbol.asyncIterator]!=null}function Bl(t,e=1){return e=Number(e),vl(t)?(async function*(){let r=[];if(e<1&&(e=1),e!==Math.round(e))throw new Error("Batch size must be an integer");for await(let n of t)for(r.push(n);r.length>=e;)yield r.slice(0,e),r=r.slice(e);for(;r.length>0;)yield r.slice(0,e),r=r.slice(e)})():(function*(){let r=[];if(e<1&&(e=1),e!==Math.round(e))throw new Error("Batch size must be an integer");for(let n of t)for(r.push(n);r.length>=e;)yield r.slice(0,e),r=r.slice(e);for(;r.length>0;)yield r.slice(0,e),r=r.slice(e)})()}var on=Bl;async function*ir(t,e=1){for await(let r of on(t,e)){let n=r.map(async i=>i().then(o=>({ok:!0,value:o}),o=>({ok:!1,err:o})));for(let i=0;i<n.length;i++){let o=await n[i];if(o.ok)yield o.value;else throw o.err}}}function Xa(t,e){if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;for(let r=0;r<t.byteLength;r++)if(t[r]!==e[r])return!1;return!0}var Qa=Symbol.for("@achingbrain/uint8arraylist");function Za(t,e){if(e==null||e<0)throw new RangeError("index is out of bounds");let r=0;for(let n of t){let i=r+n.byteLength;if(e<i)return{buf:n,index:e-r};r=i}throw new RangeError("index is out of bounds")}function sn(t){return!!t?.[Qa]}var _t=class t{bufs;length;[Qa]=!0;constructor(...e){this.bufs=[],this.length=0,e.length>0&&this.appendAll(e)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...e){this.appendAll(e)}appendAll(e){let r=0;for(let n of e)if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.push(n);else if(sn(n)){r+=n.byteLength;for(let i of n.bufs)this.bufs.push(i)}else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}prepend(...e){this.prependAll(e)}prependAll(e){let r=0;for(let n of e.reverse())if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.unshift(n);else if(sn(n))r+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}get(e){let r=Za(this.bufs,e);return r.buf[r.index]}set(e,r){let n=Za(this.bufs,e);n.buf[n.index]=r}write(e,r=0){if(e instanceof Uint8Array)for(let n=0;n<e.length;n++)this.set(r+n,e[n]);else if(sn(e))for(let n=0;n<e.length;n++)this.set(r+n,e.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(e){if(e=Math.trunc(e),!(Number.isNaN(e)||e<=0)){if(e===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(e>=this.bufs[0].byteLength)e-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(e),this.length-=e;break}}}slice(e,r){let{bufs:n,length:i}=this._subList(e,r);return Se(n,i)}subarray(e,r){let{bufs:n,length:i}=this._subList(e,r);return n.length===1?n[0]:Se(n,i)}sublist(e,r){let{bufs:n,length:i}=this._subList(e,r),o=new t;return o.length=i,o.bufs=n,o}_subList(e,r){if(e=e??0,r=r??this.length,e<0&&(e=this.length+e),r<0&&(r=this.length+r),e<0||r>this.length)throw new RangeError("index is out of bounds");if(e===r)return{bufs:[],length:0};if(e===0&&r===this.length)return{bufs:[...this.bufs],length:this.length};let n=[],i=0;for(let o=0;o<this.bufs.length;o++){let s=this.bufs[o],a=i,c=a+s.byteLength;if(i=c,e>=c)continue;let u=e>=a&&e<c,f=r>a&&r<=c;if(u&&f){if(e===a&&r===c){n.push(s);break}let d=e-a;n.push(s.subarray(d,d+(r-e)));break}if(u){if(e===0){n.push(s);continue}n.push(s.subarray(e-a));continue}if(f){if(r===c){n.push(s);break}n.push(s.subarray(0,r-a));break}n.push(s)}return{bufs:n,length:r-e}}indexOf(e,r=0){if(!sn(e)&&!(e instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=e instanceof Uint8Array?e:e.subarray();if(r=Number(r??0),isNaN(r)&&(r=0),r<0&&(r=this.length+r),r<0&&(r=0),e.length===0)return r>this.length?this.length:r;let i=n.byteLength;if(i===0)throw new TypeError("search must be at least 1 byte long");let o=256,s=new Int32Array(o);for(let d=0;d<o;d++)s[d]=-1;for(let d=0;d<i;d++)s[n[d]]=d;let a=s,c=this.byteLength-n.byteLength,u=n.byteLength-1,f;for(let d=r;d<=c;d+=f){f=0;for(let m=u;m>=0;m--){let w=this.get(d+m);if(n[m]!==w){f=Math.max(1,m-a[w]);break}}if(f===0)return d}return-1}getInt8(e){let r=this.subarray(e,e+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt8(0)}setInt8(e,r){let n=ne(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,r),this.write(n,e)}getInt16(e,r){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,r)}setInt16(e,r,n){let i=me(2);new DataView(i.buffer,i.byteOffset,i.byteLength).setInt16(0,r,n),this.write(i,e)}getInt32(e,r){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,r)}setInt32(e,r,n){let i=me(4);new DataView(i.buffer,i.byteOffset,i.byteLength).setInt32(0,r,n),this.write(i,e)}getBigInt64(e,r){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,r)}setBigInt64(e,r,n){let i=me(8);new DataView(i.buffer,i.byteOffset,i.byteLength).setBigInt64(0,r,n),this.write(i,e)}getUint8(e){let r=this.subarray(e,e+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getUint8(0)}setUint8(e,r){let n=ne(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,r),this.write(n,e)}getUint16(e,r){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,r)}setUint16(e,r,n){let i=me(2);new DataView(i.buffer,i.byteOffset,i.byteLength).setUint16(0,r,n),this.write(i,e)}getUint32(e,r){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,r)}setUint32(e,r,n){let i=me(4);new DataView(i.buffer,i.byteOffset,i.byteLength).setUint32(0,r,n),this.write(i,e)}getBigUint64(e,r){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,r)}setBigUint64(e,r,n){let i=me(8);new DataView(i.buffer,i.byteOffset,i.byteLength).setBigUint64(0,r,n),this.write(i,e)}getFloat32(e,r){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,r)}setFloat32(e,r,n){let i=me(4);new DataView(i.buffer,i.byteOffset,i.byteLength).setFloat32(0,r,n),this.write(i,e)}getFloat64(e,r){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,r)}setFloat64(e,r,n){let i=me(8);new DataView(i.buffer,i.byteOffset,i.byteLength).setFloat64(0,r,n),this.write(i,e)}equals(e){if(e==null||!(e instanceof t)||e.bufs.length!==this.bufs.length)return!1;for(let r=0;r<this.bufs.length;r++)if(!Xa(this.bufs[r],e.bufs[r]))return!1;return!0}static fromUint8Arrays(e,r){let n=new t;return n.bufs=e,r==null&&(r=e.reduce((i,o)=>i+o.byteLength,0)),n.length=r,n}};var Ni=BigInt(34),an=8,cn=262144,ec="links-bytes",un=262144,tc=1048576,rc=50,nc=10,ic=!0,oc=!0,sc=!1,ac="file",cc="links-first";var uc=(t={})=>{let e=t.chunkSize??un;return async function*(n){let i=new _t,o=0,s=!1;for await(let a of n)for(i.append(a),o+=a.length;o>=e;)if(yield i.subarray(0,e),s=!0,e===i.length)i=new _t,o=0;else{let u=new _t;u.append(i.sublist(e)),i=u,o-=e}(!s||o>0)&&(yield i.subarray(0,o))}};var W=async(t,e,r)=>{r.codec==null&&(r.codec=Ae);let n=await Ke.digest(t),i=k.create(r.cidVersion??1,r.codec.code,n);return await e.put(i,t,r),i};function lc(t){return async function*(r,n){let i=0n;for await(let o of r.content)yield async()=>{let s,a={codec:Ae,cidVersion:t.cidVersion,onProgress:t.onProgress};t.rawLeaves?(a.codec=Ie,a.cidVersion=1):(s=new B({type:t.leafType,data:o}),o=F({Data:s.marshal(),Links:[]},t));let c=await W(o,n,a);return i+=BigInt(o.byteLength),t.onProgress?.(new N("unixfs:importer:progress:file:write",{bytesWritten:i,cid:c,path:r.path})),{cid:c,unixfs:s,size:BigInt(o.length),block:o}}}}var fe=class t extends Error{static name="InvalidContentError";static code="ERR_INVALID_CONTENT";name=t.name;code=t.code;constructor(e="Invalid content"){super(e)}},or=class extends Error{static name="InvalidShardingStrategyError";static code="ERR_SHARDING_STRATEGY";name=fe.name;code=fe.code};var dc=async(t,e,r)=>{let n=new B({type:"directory",mtime:t.mtime,mode:t.mode}),i=F(P({Data:n.marshal()}),r),o=await W(i,e,r),s=t.path;return{cid:o,path:s,unixfs:n,size:BigInt(i.length),originalPath:t.originalPath,block:i}};async function*Cl(t,e,r){let n=-1,i;for await(let o of ir(r.bufferImporter(t,e),r.blockWriteConcurrency)){if(n++,n===0){i={...o,single:!0};continue}else n===1&&i!=null&&(yield{...i,block:void 0,single:void 0},i=void 0);yield{...o,block:void 0}}i!=null&&(yield i)}function hc(t){return t.single===!0}var Dl=(t,e,r)=>async function(i){if(i.length===1&&hc(i[0])&&r.reduceSingleLeafToSelf){let f=i[0],d=f.block;return hc(f)&&(t.mtime!==void 0||t.mode!==void 0)&&(f.unixfs=new B({type:"file",mtime:t.mtime,mode:t.mode,data:f.block}),d={Data:f.unixfs.marshal(),Links:[]},f.block=F(P(d),r),f.cid=await W(f.block,e,{...r,cidVersion:r.cidVersion}),f.size=BigInt(f.block.length)),r.onProgress?.(new N("unixfs:importer:progress:file:layout",{cid:f.cid,path:t.originalPath})),{cid:f.cid,path:t.path,unixfs:f.unixfs,size:f.size,originalPath:t.originalPath}}let o=new B({type:"file",mtime:t.mtime,mode:t.mode}),s=i.filter(f=>f.cid.code===ce&&f.size>0||f.unixfs!=null&&f.unixfs.data==null&&f.unixfs.fileSize()>0n?!0:!!f.unixfs?.data?.length).map(f=>f.cid.code===ce?(o.addBlockSize(f.size),{Name:"",Tsize:Number(f.size),Hash:f.cid}):(f.unixfs?.data==null?o.addBlockSize(f.unixfs?.fileSize()??0n):o.addBlockSize(BigInt(f.unixfs.data.length)),{Name:"",Tsize:Number(f.size),Hash:f.cid})),a={Data:o.marshal(),Links:s},c=F(P(a),r),u=await W(c,e,r);return r.onProgress?.(new N("unixfs:importer:progress:file:layout",{cid:u,path:t.originalPath})),{cid:u,path:t.path,unixfs:o,size:BigInt(c.length+a.Links.reduce((f,d)=>f+(d.Tsize??0),0)),originalPath:t.originalPath,block:c}},mc=async(t,e,r)=>r.layout(Cl(t,e,r),Dl(t,e,r));var pc=async(t,e,r)=>{let n=new B({type:"symlink",data:ve(t.link),mtime:t.mtime,mode:t.mode}),i=F(P({Data:n.marshal()})),o=await W(i,e,r),s=t.path;return{cid:o,path:s,unixfs:n,size:BigInt(i.length),originalPath:t.originalPath,block:i}};function Ll(t){return Symbol.iterator in t}function Nl(t){return Symbol.asyncIterator in t}function Rl(t){try{if(t instanceof Uint8Array)return(async function*(){yield t})();if(Ll(t))return(async function*(){yield*t})();if(Nl(t))return t}catch{throw new fe("Content was invalid")}throw new fe("Content was invalid")}function Ul(t){return typeof t.path=="string"}function yc(t){return async function*(r,n){for await(let i of r){let o;if(Ul(i)&&(o=i.path,i.path=i.path.split("/").filter(s=>s!=null&&s!==".").join("/")),Pl(i)){let s={path:i.path,mtime:i.mtime,mode:i.mode,content:(async function*(){let c=0n;for await(let u of t.chunker(t.chunkValidator(Rl(i.content)))){let f=BigInt(u.byteLength);c+=f,t.onProgress?.(new N("unixfs:importer:progress:file:read",{bytesRead:c,chunkSize:f,path:i.path})),yield u}})(),originalPath:o},a=t.fileBuilder??mc;yield async()=>a(s,n,t)}else if(Fl(i)){let s={path:i.path,link:i.link,mtime:i.mtime,mode:i.mode,originalPath:o},a=t.symlinkBuilder??pc;yield async()=>a(s,n,t)}else if(i.path!=null){let s={path:i.path,mtime:i.mtime,mode:i.mode,originalPath:o},a=t.dirBuilder??dc;yield async()=>a(s,n,t)}else throw new Error("Import candidate must have content or path or both")}}}function Pl(t){return t.content!=null}function Fl(t){return t.link!=null}var gc=()=>async function*(e){for await(let r of e){if(r.length===void 0)throw new fe("Content was invalid");if(typeof r=="string"||r instanceof String)yield ve(r.toString());else if(Array.isArray(r))yield Uint8Array.from(r);else if(r instanceof Uint8Array)yield r;else throw new fe("Content was invalid")}};var zl=174;function Ri(t){let e=t?.maxChildrenPerNode??zl;return async function r(n,i){let o=[];for await(let s of on(n,e))o.push(await i(s));return o.length>1?r(o,i):o[0]}}var le=class{options;root;dir;path;dirty;flat;parent;parentKey;unixfs;mode;mtime;cid;size;nodeSize;constructor(e,r){this.options=r??{},this.root=e.root,this.dir=e.dir,this.path=e.path,this.dirty=e.dirty,this.flat=e.flat,this.parent=e.parent,this.parentKey=e.parentKey,this.unixfs=e.unixfs,this.mode=e.mode,this.mtime=e.mtime}};var Ol=[0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8];function $l(t){let e=0;return t>=4294967296&&(t=Math.floor(t/4294967296),e=32),t>=65536&&(t>>>=16,e+=16),t>=256&&(t>>>=8,e+=8),e+Ol[t]}function Fe(t){return t%2===0&&t++,Math.floor(($l(t)+6)/7)}function fn(t){let e=0;for(let r=0;r<t.length;r++){let n=t.charCodeAt(r);n<128?e++:n<2048?e+=2:n>=55296&&n<=56319&&r+1<t.length?(r++,e+=4):e+=3}return e}function wc(t,e,r){let n=1+Fe(e)+e;return n+=1+Fe(t)+t,n+=1+Fe(r),1+Fe(n)+n}var Ml=493;function bc(t,e){let r=2;if(t!==void 0&&t!==Ml&&(r+=1+Fe(t)),e!=null){let n=0,i=Number(e.secs);i<0?n+=11:n+=1+Fe(i),e.nsecs!=null&&(n+=5),r+=1+Fe(n)+n}return 1+Fe(r)+r}function Ui(t,e){return e?.cid!=null&&e?.size!=null?t+e.cid.byteLength:0}function Pi(t,e){return e?.cid!=null&&e?.size!=null?wc(t,e.cid.byteLength,Number(e.size)):0}var Ze=class extends le{_children;constructor(e,r){super(e,r),this._children=new Map}async put(e,r){if(this.nodeSize!==void 0){let n=this._children.get(e),i=fn(e),o=this.options?.shardSplitStrategy;if(o==="links-bytes")this.nodeSize-=Ui(i,n),this.nodeSize+=Ui(i,r);else if(o==="block-bytes")this.nodeSize-=Pi(i,n),this.nodeSize+=Pi(i,r);else throw new or(`Invalid shardSplitStrategy: ${o}`);this.nodeSize<0&&(this.nodeSize=void 0)}this.cid=void 0,this.size=void 0,this._children.set(e,r)}async get(e){return Promise.resolve(this._children.get(e))}childCount(){return this._children.size}directChildrenCount(){return this.childCount()}onlyChild(){return this._children.values().next().value}*eachChildSeries(){for(let[e,r]of this._children.entries())yield{key:e,child:r}}marshal(){let e=new B({type:"directory",mtime:this.mtime,mode:this.mode}),r=[];for(let[i,o]of this._children.entries())if(!(o.size==null||o.cid==null)){if(o.cid==null)throw new Error("Directory contents must be flushed before marshaling");r.push({Hash:o.cid,Name:i,Tsize:o.size==null?void 0:Number(o.size)})}let n={Data:e.marshal(),Links:r};return F(P(n),this.options)}async estimateNodeSize(){if(this.nodeSize!==void 0)return this.nodeSize;let e=this.options?.shardSplitStrategy;if(e==="links-bytes"){this.nodeSize=0;for(let[r,n]of this._children.entries())this.nodeSize+=Ui(fn(r),n)}else if(e==="block-bytes"){this.nodeSize=bc(this.mode,this.mtime);for(let[r,n]of this._children.entries())this.nodeSize+=Pi(fn(r),n)}else throw new or(`Invalid shardSplitStrategy: ${e}`);return this.nodeSize}async*flush(e){let r=[];for(let[c,u]of this._children.entries()){let f=u;if(u instanceof le)for await(let d of u.flush(e))f=d,yield d;f.size!=null&&f.cid!=null&&r.push({Name:c,Tsize:Number(f.size),Hash:f.cid})}let n=new B({type:"directory",mtime:this.mtime,mode:this.mode}),i={Data:n.marshal(),Links:r},o=F(P(i),this.options),s=await W(o,e,this.options),a=o.length+i.Links.reduce((c,u)=>c+(u.Tsize??0),0);this.cid=s,this.size=a,yield{cid:s,unixfs:n,path:this.path,size:BigInt(a)}}};var ln=class t extends Error{static name="NotFoundError";name=t.name;static code="ERR_NOT_FOUND";code=t.code;constructor(e="Not Found"){super(e)}};var dn=class{has(e,r){return Promise.reject(new Error(".has is not implemented"))}put(e,r,n){return Promise.reject(new Error(".put is not implemented"))}async*putMany(e,r){for await(let{cid:n,bytes:i}of e)await this.put(n,i,r),yield n}get(e,r){throw new Error(".get is not implemented")}async*getMany(e,r){for await(let n of e)yield{cid:n,bytes:this.get(n,r)}}delete(e,r){return Promise.reject(new Error(".delete is not implemented"))}async*deleteMany(e,r){for await(let n of e)await this.delete(n,r),yield n}async*getAll(e){throw new Error(".getAll is not implemented")}};var hn=class extends dn{put(e,r,n){return n?.signal?.throwIfAborted(),e}get(e,r){throw r?.signal?.throwIfAborted(),new ln}has(e,r){return r?.signal?.throwIfAborted(),!1}async delete(e,r){r?.signal?.throwIfAborted()}async*getAll(e){e?.signal?.throwIfAborted()}};async function Hl(t){return(await $r.encode(t)).slice(0,8).reverse()}var Fi=class extends le{bucket;constructor(e,r){super(e,r),this.bucket=Vr({hashFn:Hl,bits:r.shardFanoutBits??an})}async put(e,r){this.cid=void 0,this.size=void 0,this.nodeSize=void 0,await this.bucket.put(e,r)}async get(e){return this.bucket.get(e)}childCount(){return this.bucket.leafCount()}directChildrenCount(){return this.bucket.childrenCount()}onlyChild(){return this.bucket.onlyChild()}*eachChildSeries(){for(let{key:e,value:r}of this.bucket.eachLeafSeries())yield{key:e,child:r}}async estimateNodeSize(){if(this.nodeSize!==void 0)return this.nodeSize;let e=new hn,r=await _c(this.bucket,this,e,this.options);return this.nodeSize=r.size,this.nodeSize}async*flush(e){for await(let r of kc(this.bucket,e,this,this.options))yield{...r,path:this.path}}},xc=Fi;async function*kc(t,e,r,n){let i=t._children,o=(t.tableSize()-1).toString(16).length,s=[],a=0n;for(let x=0;x<i.length;x++){let b=i.get(x);if(b==null)continue;let y=x.toString(16).toUpperCase().padStart(o,"0");if(b instanceof ue){let _;for await(let C of kc(b,e,null,n))_=C;if(_==null)throw new Error("Could not flush sharded directory, no sub-shard found");s.push({Name:y,Tsize:Number(_.size),Hash:_.cid}),a+=_.size}else if(Ec(b.value)){let _=b.value,C;for await(let ze of _.flush(e))C=ze,yield C;if(C==null)throw new Error("Did not flush dir");let E=y+b.key;s.push({Name:E,Tsize:Number(C.size),Hash:C.cid}),a+=C.size}else{let _=b.value;if(_.cid==null)continue;let C=y+b.key,E=_.size;s.push({Name:C,Tsize:Number(E),Hash:_.cid}),a+=BigInt(E??0)}}let c=Uint8Array.from(i.bitField().reverse()),u=new B({type:"hamt-sharded-directory",data:c,fanout:BigInt(t.tableSize()),hashType:Ni,mtime:r?.mtime,mode:r?.mode}),f={Data:u.marshal(),Links:s},d=F(P(f),n),m=await W(d,e,n),w=BigInt(d.byteLength)+a;yield{cid:m,unixfs:u,size:w}}function Ec(t){return typeof t.flush=="function"}async function _c(t,e,r,n){let i=t._children,o=(t.tableSize()-1).toString(16).length,s=[],a=0;for(let m=0;m<i.length;m++){let w=i.get(m);if(w==null)continue;let x=m.toString(16).toUpperCase().padStart(o,"0");if(w instanceof ue){let{size:b,cid:y}=await _c(w,null,r,n);s.push({Name:x,Tsize:Number(b),Hash:y}),a+=x.length+y.byteLength}else if(Ec(w.value)){let b=w.value,y=b.nodeSize;if(b.cid==null)throw new Error("Child directory has not been persisted");s.push({Name:x+w.key,Tsize:Number(y),Hash:b.cid}),a+=x.length+b.cid.byteLength}else{let b=w.value,y=x+w.key,_=b.size;s.push({Name:y,Tsize:Number(_),Hash:b.cid}),a+=x.length+b.cid.byteLength}}let c=Uint8Array.from(i.bitField().reverse()),u=new B({type:"hamt-sharded-directory",data:c,fanout:BigInt(t.tableSize()),hashType:Ni,mtime:e?.mtime,mode:e?.mode}),f=F(P({Data:u.marshal(),Links:s}),n);return{cid:await W(f,r,n),size:n.shardSplitStrategy==="links-bytes"?a:f.length}}async function zi(t,e){let r=e,n=e.options.shardSplitThresholdBytes??cn;e instanceof Ze&&await e.estimateNodeSize()>n&&(r=await Vl(e));let i=r.parent;if(i!=null){if(r!==e){if(t!=null&&(t.parent=r),r.parentKey==null)throw new Error("No parent key found");await i.put(r.parentKey,r)}return zi(r,i)}return r}async function Vl(t){let e=new xc({root:t.root,dir:!0,parent:t.parent,parentKey:t.parentKey,path:t.path,dirty:t.dirty,flat:!1,mtime:t.mtime,mode:t.mode},t.options);for(let{key:r,child:n}of t.eachChildSeries())await e.put(r,n);return e}var Ac=(t="")=>t.split(/(?<!\\)\//).filter(Boolean);async function Wl(t,e,r){let n=Ac(t.path??""),i=n.length-1,o=e,s="";for(let a=0;a<n.length;a++){let c=n[a];s+=`${s!==""?"/":""}${c}`;let u=a===i;if(o.dirty=!0,o.cid=void 0,o.size=void 0,u)await o.put(c,t),e=await zi(null,o);else{let f=await o.get(c);(f==null||!(f instanceof le))&&(f=new Ze({root:!1,dir:!0,parent:o,parentKey:c,path:s,dirty:!0,flat:!0,mtime:f?.unixfs?.mtime,mode:f?.unixfs?.mode},r)),await o.put(c,f),o=f}}return e}async function*Ic(t,e){if(!(t instanceof le)){t.unixfs?.isDirectory()===!0&&(yield t);return}yield*t.flush(e)}function Sc(t){return async function*(r,n){let i=new Ze({root:!0,dir:!0,path:"",dirty:!0,flat:!0},t),o,s=!1;for await(let a of r){if(a==null)continue;let c=`${a.originalPath??""}`.split("/")[0];c!=null&&c!==""&&(o==null?(o=c,s=!0):o!==c&&(s=!1)),i=await Wl(a,i,t),a.unixfs?.isDirectory()!==!0&&(yield a)}if(t.wrapWithDirectory||s&&i.childCount()>1)yield*Ic(i,n);else for(let a of i.eachChildSeries())a!=null&&(yield*Ic(a.child,n))}}async function*Tc(t,e,r={}){let n;Symbol.asyncIterator in t||Symbol.iterator in t?n=t:n=[t];let i,o;r.profile==="unixfs-v0-2015"?(r.shardSplitStrategy=r.shardSplitStrategy??"links-bytes",r.cidVersion=r.cidVersion??0,r.rawLeaves=r.rawLeaves??!1,i=un,o=174,r.fieldOrder="links-first"):r.profile==="unixfs-v1-2025"&&(r.shardSplitStrategy=r.shardSplitStrategy??"block-bytes",r.cidVersion=r.cidVersion??1,r.rawLeaves=r.rawLeaves??!0,i=tc,o=1024,r.fieldOrder="links-first");let s=r.wrapWithDirectory??sc,a=r.shardSplitThresholdBytes??cn,c=r.shardSplitStrategy??ec,u=r.shardFanoutBits??an,f=r.cidVersion??1,d=r.rawLeaves??oc,m=r.leafType??ac,w=r.fileImportConcurrency??rc,x=r.blockWriteConcurrency??nc,b=r.reduceSingleLeafToSelf??ic,y=r.fieldOrder??cc,_=r.chunker??uc({chunkSize:i}),C=r.chunkValidator??gc(),E=r.dagBuilder??yc({chunker:_,chunkValidator:C,wrapWithDirectory:s,layout:r.layout??Ri({maxChildrenPerNode:o}),bufferImporter:r.bufferImporter??lc({cidVersion:f,rawLeaves:d,leafType:m,onProgress:r.onProgress}),blockWriteConcurrency:x,reduceSingleLeafToSelf:b,cidVersion:f,onProgress:r.onProgress,dirBuilder:r.dirBuilder,fileBuilder:r.fileBuilder,fieldOrder:y}),ze=r.treeBuilder??Sc({wrapWithDirectory:s,shardSplitThresholdBytes:a,shardSplitStrategy:c,shardFanoutBits:u,cidVersion:f,onProgress:r.onProgress,fieldOrder:y});for await(let Q of ze(ir(E(n,e),w),e))yield{cid:Q.cid,path:Q.path,unixfs:Q.unixfs,size:Q.size}}var Ql={profile:"unixfs-v1-2025"};async function ed(t){let e=[],r=[];async function n(i){let o=(await jl(i)).sort();for(let s of o){if(s.startsWith("."))continue;let a=Cc(i,s),c=await Bc(a),u=Xl(t,a).split(Dc).join("/");if(c.isSymbolicLink())throw Wi(`Symlinks are not supported: ${u}`,"path");c.isDirectory()?(r.push(u),await n(a)):c.isFile()&&e.push({path:u,size:c.size})}}return await n(t),{files:e,directories:r}}function td(){return k.create(1,112,ar(Ke.code,new Uint8Array(32)))}async function Tx(t,e){let r=Mi(t),n=Jl(r),{files:i,directories:o}=await ed(r),s=e&&`${e}.tmp`;e&&await mn($i(e),{recursive:!0});let a=0,c=s?Oi(s):new Zl({write(E,ze,Q){a+=E.length,Q()}}),{writer:u,out:f}=dt.create([td()]),d=Vi(Hi.from(f),c),m=new Set,w={async put(E,ze){let Q=E.toString();return m.has(Q)||(m.add(Q),await u.put({cid:E,bytes:ze})),E}},x=new Set([...i.map(E=>E.path),...o].map(E=>E.includes("/")?E.slice(0,E.lastIndexOf("/")):""));function*b(){x.has("")||(yield{path:n});for(let E of o)x.has(E)||(yield{path:`${n}/${E}`});for(let E of i)yield{path:`${n}/${E.path}`,content:ql(Cc(r,E.path))}}let y;try{for await(let E of Tc(b(),w,Ql))E.path===n&&(y=E.cid);await u.close(),await d}catch(E){throw await u.close().catch(()=>{}),await d.catch(()=>{}),s&&await Kl(s,{force:!0}),E}if(!y)throw new Error(`Packing ${t} produced no root.`);if(!(e&&s))return{rootCid:y,size:a,files:i.length};let _=await Gl(s,"r+");try{await dt.updateRootsInFile(_,[y])}finally{await _.close()}let{size:C}=await Bc(s);return await Yl(s,e),{rootCid:y,size:C,files:i.length}}var vc=8*1024*1024;async function*rd(t,e){for(let r=0;r<e;r+=vc)yield*t.content({offset:r,length:Math.min(vc,e-r)})}var nd=0;async function id(t,e){let{code:r,digest:n}=t.multihash,i;if(r===Ke.code)i=(await Ke.digest(e)).digest;else if(r===nd)i=e;else throw new It({code:St.verificationFailed,message:`Unsupported multihash 0x${r.toString(16)} in block ${t}.`});if(!qi(i,n))throw new It({code:St.verificationFailed,message:`Block ${t} does not match its CID.`})}async function vx(t,e,r={}){let n=r.verifyBlocks??!0,i=await Vt.fromFile(t);try{let[o]=await i.getRoots();if(!o)throw new Error("CAR has no root.");let s=k.decode(o.bytes),a={async*get(d){let m=await i.get(d);if(!m)throw new Error(`Block ${d} missing from CAR.`);n&&await id(d,m.bytes),yield m.bytes}},c=Mi(e),u=0;async function f(d,m){if(m!==c&&!m.startsWith(c+Dc))throw new It({code:St.unsafePath,message:`Refusing to write outside ${e}: ${m}`});let w=await Ja(d,a);if(w.type==="directory"){await mn(m,{recursive:!0});for await(let x of w.entries()){if(x.name.includes("/")||x.name.includes("\\"))throw new It({code:St.unsafePath,message:`Refusing entry name with a path separator: ${x.name}`});await f(x.cid,Mi(m,x.name))}}else w.type==="file"?(await mn($i(m),{recursive:!0}),await Vi(Hi.from(rd(w,Number(w.unixfs.fileSize()))),Oi(m)),u++):(w.type==="raw"||w.type==="identity")&&(await mn($i(m),{recursive:!0}),await Vi(Hi.from(w.content()),Oi(m)),u++)}return await f(s,c),{rootCid:s,files:u}}finally{await i.close()}}export{Tx as a,vx as b};
3
+ //# sourceMappingURL=chunk-SVWQJYA5.js.map