@learncard/ceramic-plugin 1.0.8 → 1.0.9

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.
@@ -814,7 +814,7 @@ HEXDIG = DIGIT / "A" / "B" / "C" / "D" / "E" / "F"
814
814
  `)}o(PL,"asString");var Yu=class extends Ju{toMessage(){return super.toMessage("Ethereum")}signMessage(){let e;switch(this.type){case Xu.PERSONAL_SIGNATURE:{e=this.toMessage();break}default:{e=this.toMessage();break}}return e}};o(Yu,"SiweMessage");var jd=class extends Ju{toMessage(){return super.toMessage("Solana")}signMessage(){let e;switch(this.type){case Xu.PERSONAL_SIGNATURE:{e=new TextEncoder().encode(this.toMessage());break}default:{e=new TextEncoder().encode(this.toMessage());break}}return e}};o(jd,"SiwsMessage");var LL=5*60,BL=new Date("2022-09-20").valueOf(),Zu;(function(t){function e(c){let u={h:{t:"eip4361"},p:{domain:c.domain,iat:c.issuedAt,iss:`did:pkh:eip155:${c.chainId}:${c.address}`,aud:c.uri,version:c.version,nonce:c.nonce}};return c.signature&&(u.s={t:"eip191",s:c.signature}),c.notBefore&&(u.p.nbf=c.notBefore),c.expirationTime&&(u.p.exp=c.expirationTime),c.statement&&(u.p.statement=c.statement),c.requestId&&(u.p.requestId=c.requestId),c.resources&&(u.p.resources=c.resources),u}o(e,"fromSiweMessage");let r=o(function(c){try{return Promise.resolve(Xx({bytes:c,codec:Hi,hasher:Ss})).then(function(u){return u.value})}catch(u){return Promise.reject(u)}},"fromBlockBytes");t.fromSiweMessage=e;function n(c){let u={h:{t:"caip122"},p:{domain:c.domain,iat:c.issuedAt,iss:`did:pkh:solana:${c.chainId}:${c.address}`,aud:c.uri,version:c.version,nonce:c.nonce}};return c.signature&&(u.s={t:"solana:ed25519",s:c.signature}),c.notBefore&&(u.p.nbf=c.notBefore),c.expirationTime&&(u.p.exp=c.expirationTime),c.statement&&(u.p.statement=c.statement),c.requestId&&(u.p.requestId=c.requestId),c.resources&&(u.p.resources=c.resources),u}o(n,"fromSiwsMessage"),t.fromSiwsMessage=n,t.fromBlockBytes=r;function i(c,u={}){var m,v;if(((m=c.s)==null?void 0:m.t)==="eip191")return a(c,u);if(((v=c.s)==null?void 0:v.t)==="solana:ed25519")return UL(c,u);throw new Error("Unsupported CACAO signature type")}o(i,"verify"),t.verify=i;function a(c,u){if(!c.s)throw new Error("CACAO does not have a signature");let m=u.atTime?u.atTime.getTime():Date.now(),v=(u.clockSkewSecs??LL)*1e3;if(Date.parse(c.p.iat)>m+v||Date.parse(c.p.nbf)>m+v)throw new Error("CACAO is not valid yet");let x=u.revocationPhaseOutSecs?u.revocationPhaseOutSecs*1e3:0;if(!u.disableExpirationCheck&&Date.parse(c.p.exp)+x+v<m)throw new Error("CACAO has expired");let O=[Ib(Yu.fromCacao(c).toMessage(),c.s.s).toLowerCase()];if(Date.parse(c.p.iat)<=BL){let D=Ib(NL(Yu.fromCacao(c),"Ethereum"),c.s.s).toLowerCase();O.push(D)}let R=zs.parse(c.p.iss.replace("did:pkh:","")).address.toLowerCase();if(!O.includes(R))throw new Error("Signature does not belong to issuer")}o(a,"verifyEIP191Signature"),t.verifyEIP191Signature=a})(Zu||(Zu={}));function UL(t,e){if(!t.s)throw new Error("CACAO does not have a signature");let r=e.atTime?e.atTime.getTime():Date.now();if(Date.parse(t.p.iat)>r||Date.parse(t.p.nbf)>r)throw new Error("CACAO is not valid yet");let n=e.revocationPhaseOutSecs?e.revocationPhaseOutSecs*1e3:0;if(!e.disableExpirationCheck&&Date.parse(t.p.exp)+n<r)throw new Error("CACAO has expired");let i=jd.fromCacao(t),a=t.s.s,c=i.signMessage(),u=Ot(a,"base58btc"),m=zs.parse(t.p.iss.replace("did:pkh:","")).address,v=Ot(m,"base58btc");if(!(0,z5.verify)(v,c,u))throw new Error("Signature does not belong to issuer")}o(UL,"verifySolanaSignature");var Qu;(function(t){function e(r){return Ua({value:r,codec:Hi,hasher:Ss})}o(e,"fromCacao"),t.fromCacao=e})(Qu||(Qu={}));Ff();pu();var K5=Lt(Oa(),1);Ff();function j5(){return kt((0,K5.randomBytes)(16),"base64")}o(j5,"randomString");var G5="base64pad",V5="base64url";function W5(t){return kt(t,G5)}o(W5,"encodeBase64");function J5(t){return kt(t,V5)}o(J5,"encodeBase64Url");function Y5(t){return Ot(t,G5)}o(Y5,"decodeBase64");function Gd(t){return JSON.parse(kt(Ot(t,V5)))}o(Gd,"base64urlToJSON");function X5(t){if(t.signatures.length>1)throw new Error("Cant convert to compact jws");return`${t.signatures[0].protected}.${t.payload}.${t.signatures[0].signature}`}o(X5,"fromDagJWS");function Z5(t,e){if(e){let r=e.toISOString().split(".")[0]+"Z";return`${t}?versionTime=${r}`}else return t}o(Z5,"didWithTime");function Q5(t){return t?Array.isArray(t)?t:[t]:[]}o(Q5,"extractControllers");function $L(t){return"registry"in t&&"cache"in t}o($L,"isResolver");var Va=class{constructor({provider:e,resolver:r={},resolverOptions:n,capability:i,parent:a}={}){if(e!=null&&(this._client=new cc(e)),i){if(this._capability=i,this._parentId=this._capability.p.iss,a&&this._parentId!==a)throw new Error("Capability issuer and parent not equal")}else a&&(this._parentId=a);this.setResolver(r,n)}get capability(){if(!this._capability)throw new Error("DID has no capability attached");return this._capability}get hasCapability(){return this._capability!=null}get parent(){if(!this._parentId)throw new Error("DID has no parent DID");return this._parentId}get hasParent(){return this._parentId!=null}get id(){if(this._id==null)throw new Error("DID is not authenticated");return this._id}get authenticated(){return this._id!=null}withCapability(e){return new Va({provider:this._client?.connection,resolver:this._resolver,capability:e,parent:this._parentId})}setProvider(e){if(this._client==null)this._client=new cc(e);else if(this._client.connection!==e)throw new Error("A different provider is already set, create a new DID instance to use another provider")}setResolver(e,r){this._resolver=$L(e)?e:new ou(e,r)}async authenticate({provider:e,paths:r=[],aud:n}={}){if(e!=null&&this.setProvider(e),this._client==null)throw new Error("No provider available");let i=j5(),a=await this._client.request("did_authenticate",{nonce:i,aud:n,paths:r}),{kid:c}=await this.verifyJWS(a),u=Gd(a.payload);if(!c.includes(u.did))throw new Error("Invalid authencation response, kid mismatch");if(u.nonce!==i)throw new Error("Invalid authencation response, wrong nonce");if(u.aud!==n)throw new Error("Invalid authencation response, wrong aud");if(u.exp<Date.now()/1e3)throw new Error("Invalid authencation response, expired");return this._id=u.did,this._id}async createJWS(e,r={}){if(this._client==null)throw new Error("No provider available");if(this._id==null)throw new Error("DID is not authenticated");if(this._capability){let i=await Qu.fromCacao(this._capability),a=We.asCID(i.cid);if(!a)throw new Error("Capability CID of the JWS cannot be set to the capability payload cid as they are incompatible");r.protected=r.protected||{},r.protected.cap=`ipfs://${a?.toString()}`}let{jws:n}=await this._client.request("did_createJWS",{did:this._id,...r,payload:e});return n}async createDagJWS(e,r={}){let{cid:n,linkedBlock:i}=await i4(e),a=J5(n.bytes);Object.assign(r,{linkedBlock:W5(i)});let c=await this.createJWS(a,r),u=We.asCID(n);if(!u)throw new Error("CID of the JWS cannot be set to the encoded payload cid as they are incompatible");if(c.link=u,this._capability){let m=await Qu.fromCacao(this._capability);return{jws:c,linkedBlock:i,cacaoBlock:m.bytes}}return{jws:c,linkedBlock:i}}async verifyJWS(e,r={}){typeof e!="string"&&(e=X5(e));let n=Gd(e.split(".")[0]).kid;if(!n)throw new Error('No "kid" found in jws');let i=await this.resolve(n);if(!r.disableTimecheck){let v=i.didDocumentMetadata?.nextUpdate;if(v){let S=r.revocationPhaseOutSecs?r.revocationPhaseOutSecs*1e3:0,O=new Date(v).valueOf()+S;if(!(r.atTime&&r.atTime.getTime()<O))throw new Error(`invalid_jws: signature authored with a revoked DID version: ${n}`)}let x=i.didDocumentMetadata?.updated;if(x&&r.atTime&&r.atTime.getTime()<new Date(x).valueOf())throw new Error(`invalid_jws: signature authored before creation of DID version: ${n}`)}let c=i.didDocument?.id;if(r.issuer&&r.issuer===r.capability?.p.iss&&c===r.capability.p.aud)Zu.verify(r.capability,{atTime:r.atTime?r.atTime:void 0,revocationPhaseOutSecs:r.revocationPhaseOutSecs});else if(r.issuer&&r.issuer!==c){let v=Z5(r.issuer,r.atTime),S=(await this.resolve(v)).didDocument?.controller,O=Q5(S);if(r.capability?.s&&r.capability.p.aud===c&&O.includes(r.capability.p.iss))Zu.verify(r.capability,{atTime:r.atTime?r.atTime:void 0,revocationPhaseOutSecs:r.revocationPhaseOutSecs});else if(!(c?O.includes(c):!1))throw new Error(`invalid_jws: not a valid verificationMethod for issuer: ${n}`)}let u=i.didDocument?.verificationMethod||[];jx(e,u);let m;try{m=Gd(e.split(".")[1])}catch{}return{kid:n,payload:m,didResolutionResult:i}}async createJWE(e,r,n={}){let i=await Wx(r,this._resolver);return Vx(e,i,n.protectedHeader,n.aad)}async createDagJWE(e,r,n={}){let i=await o4(e);return this.createJWE(i,r,n)}async decryptJWE(e,r={}){if(this._client==null)throw new Error("No provider available");if(this._id==null)throw new Error("DID is not authenticated");let{cleartext:n}=await this._client.request("did_decryptJWE",{did:this._id,...r,jwe:e});return Y5(n)}async decryptDagJWE(e){let r=await this.decryptJWE(e);return s4(r)}async resolve(e){let r=await this._resolver.resolve(e);if(r.didResolutionMetadata.error){let{error:n,message:i}=r.didResolutionMetadata,a=i?`, ${i}`:"";throw new Error(`Failed to resolve ${e}: ${n}${a}`)}return r}};o(Va,"DID");function e8(t){var e=0,r=t.length,n=[];if(r%2)throw new Error("invalid hex:"+t);for(;e<r;e+=2)n.push(parseInt(t.substr(e,2),16));return new Uint8Array(n)}o(e8,"toUint8Array");var Hb=Lt(el(),1);Ah();var Rb={};Jt(Rb,{keyToDidDoc:()=>QL});function QL(t,e){let r=`did:key:${e}`,n=`${r}#${e}`;return{id:r,verificationMethod:[{id:n,type:"Secp256k1VerificationKey2018",controller:r,publicKeyBase58:kt(t,"base58btc")}],authentication:[n],assertionMethod:[n],capabilityDelegation:[n],capabilityInvocation:[n]}}o(QL,"keyToDidDoc");var Nb={};Jt(Nb,{keyToDidDoc:()=>tB});Ff();var u8=Lt(Au(),1);function eB(t){let e=new Uint8Array(t.length+2);return e[0]=236,e[1]=1,e.set(t,2),`z${kt(e,"base58btc")}`}o(eB,"encodeKey");function tB(t,e){let r=`did:key:${e}`,n=`${r}#${e}`,i=(0,u8.convertPublicKeyToX25519)(t),a=`${r}#${eB(i)}`;return{id:r,verificationMethod:[{id:n,type:"Ed25519VerificationKey2018",controller:r,publicKeyBase58:kt(t,"base58btc")}],authentication:[n],assertionMethod:[n],capabilityDelegation:[n],capabilityInvocation:[n],keyAgreement:[{id:a,type:"X25519KeyAgreementKey2019",controller:r,publicKeyBase58:kt(i,"base58btc")}]}}o(tB,"keyToDidDoc");var $b={};Jt($b,{keyToDidDoc:()=>lB,pubKeyBytesToXY:()=>d8});var Vd={};Jt(Vd,{ECPointDecompress:()=>fB});function rB(t){return t>=0?t:-t}o(rB,"n");function nB(t,e){if(typeof t=="number"&&(t=BigInt(t)),typeof e=="number"&&(e=BigInt(e)),t<=0n||e<=0n)throw new RangeError("a and b MUST be > 0");let r=0n,n=1n,i=1n,a=0n;for(;t!==0n;){let c=e/t,u=e%t,m=r-i*c,v=n-a*c;e=t,t=u,r=i,n=a,i=m,a=v}return{g:e,x:r,y:n}}o(nB,"r");function Pb(t,e){if(typeof t=="number"&&(t=BigInt(t)),typeof e=="number"&&(e=BigInt(e)),e<=0n)throw new RangeError("n must be > 0");let r=t%e;return r<0n?r+e:r}o(Pb,"f");function iB(t,e){let r=nB(Pb(t,e),e);if(r.g!==1n)throw new RangeError(`${t.toString()} does not have inverse modulo ${e.toString()}`);return Pb(r.x,e)}o(iB,"g");function Wa(t,e,r){if(typeof t=="number"&&(t=BigInt(t)),typeof e=="number"&&(e=BigInt(e)),typeof r=="number"&&(r=BigInt(r)),r<=0n)throw new RangeError("n must be > 0");if(r===1n)return 0n;if(t=Pb(t,r),e<0n)return iB(Wa(t,rB(e),r),r);let n=1n;for(;e>0;)e%2n===1n&&(n=n*t%r),e/=2n,t=t**2n%r;return n}o(Wa,"b");var vr={};Jt(vr,{pubKeyBytesToHex:()=>oB,publicKeyHexToUint8ArrayPointPair:()=>l8,publicKeyIntToUint8ArrayPointPair:()=>h8,publicKeyIntToXY:()=>aB,publicKeyToXY:()=>sB,testHexString:()=>Bb,testUint8Array:()=>Vs});Sh();function oB(t){if(!Vs(t))throw new TypeError("input must be a Uint8Array");return kt(t,"base16")}o(oB,"pubKeyBytesToHex");function sB(t){if(!Bb(t))throw new TypeError("input must be string with characters 0-9,A-F,a-f");let e=l8(t),r=_a.encode(e.xOctet).slice(1),n=_a.encode(e.yOctet).slice(1);return{xm:r,ym:n}}o(sB,"publicKeyToXY");function l8(t){if(!Bb(t))throw new TypeError("input must be string with characters 0-9,A-F,a-f");let e=t.slice(0,t.length/2),r=t.slice(t.length/2,t.length),n=Ot(e,"base16"),i=Ot(r,"base16");return{xOctet:n,yOctet:i}}o(l8,"publicKeyHexToUint8ArrayPointPair");function Bb(t){let e=/^[A-Fa-f0-9]+$/i;return!!(e.exec(t)!==null&&e.test(t)&&typeof t=="string")}o(Bb,"testHexString");function Vs(t){return t==null?!1:t.constructor===Uint8Array}o(Vs,"testUint8Array");function aB(t){if(t==null)throw new TypeError("input cannot be null or undefined.");if(typeof t!="object")throw new TypeError("Input must be an object with properties x and y");if(!Object.prototype.hasOwnProperty.call(t,"x")||!Object.prototype.hasOwnProperty.call(t,"y"))throw new Error("Input must have properties x and y");if(typeof t.x!="bigint"&&typeof t.y!="bigint")throw new Error("Input coordinates must be BigInt");let e=h8(t),r=_a.encode(e.xOctet).slice(1),n=_a.encode(e.yOctet).slice(1);return{xm:r,ym:n}}o(aB,"publicKeyIntToXY");function h8(t){if(t==null)throw new TypeError("input cannot be null or undefined.");if(typeof t!="object")throw new TypeError("Input must be an object with properties x and y");if(!Object.prototype.hasOwnProperty.call(t,"x")||!Object.prototype.hasOwnProperty.call(t,"y"))throw new Error("Input must have properties x and y");if(typeof t.x!="bigint"&&typeof t.y!="bigint")throw new Error("Input coordinates must be BigInt");let e=t.x.toString(),r=t.y.toString(),n=Ot(e,"base10"),i=Ot(r,"base10");return{xOctet:n,yOctet:i}}o(h8,"publicKeyIntToUint8ArrayPointPair");function fB(t){if(!Vs(t))throw new TypeError("input must be a Uint8Array");let e=BigInt(2),r=e**256n-e**224n+e**192n+e**96n-1n,n=41058363725152142129326129780047268409114441015993725554835256314039467401291n,i=(r+1n)/4n,a=BigInt(t[0]-2),c=t.subarray(1),u=BigInt(kt(c,"base10")),m=u**3n-u*3n+n,v=Wa(m,i,r);return v%2n!==a&&(v=r-v),{x:u,y:v}}o(fB,"ECPointDecompress");var Wd={};Jt(Wd,{ECPointDecompress:()=>cB});function cB(t){if(!Vs(t))throw new TypeError("input must be a Uint8Array");let e=BigInt(2),r=e**384n-e**128n-e**96n+e**32n-1n,n=27580193559959705877849011840389048093056905856361568521428707301988689241309860865136260764883745107765439761230575n,i=(r+1n)/4n,a=BigInt(t[0]-2),c=t.subarray(1),u=BigInt(kt(c,"base10")),m=u**3n-u*3n+n,v=Wa(m,i,r);return v%2n!==a&&(v=r-v),{x:u,y:v}}o(cB,"ECPointDecompress");var Jd={};Jt(Jd,{ECPointDecompress:()=>uB});function uB(t){if(!Vs(t))throw new TypeError("input must be a Uint8Array");let r=BigInt(2)**521n-1n,n=1093849038073734274511112390766805569936207598951683748994586394495953116150735016013708737573759623248592132296706313309438452531591012912142327488478985984n,i=(r+1n)/4n,a=BigInt(t[0]-2),c=t.subarray(1),u=BigInt(kt(c,"base10")),m=u**3n-u*3n+n,v=Wa(m,i,r);return v%2n!==a&&(v=r-v),{x:u,y:v}}o(uB,"ECPointDecompress");function lB(t,e){let r=`did:key:${e}`,n=`${r}#${e}`,i=d8(t);return{id:r,verificationMethod:[{id:n,type:"JsonWebKey2020",controller:r,publicKeyJwk:{kty:"EC",crv:"P-256",x:i.xm,y:i.ym}}],authentication:[n],assertionMethod:[n],capabilityDelegation:[n],capabilityInvocation:[n]}}o(lB,"keyToDidDoc");function d8(t){if(!vr.testUint8Array(t))throw new TypeError("input must be a Uint8Array");let e=vr.pubKeyBytesToHex(t),r=e.length/2;if(r==64)return vr.publicKeyToXY(e);if(r==65&&e.slice(0,2)=="04"){let n=e.slice(2);return vr.publicKeyToXY(n)}if(r==33&&(e.slice(0,2)=="03"||e.slice(0,2)=="02")){let n=Ot(e,"base16"),i=Vd.ECPointDecompress(n);return vr.publicKeyIntToXY(i)}throw new Error("Unexpected pubKeyBytes")}o(d8,"pubKeyBytesToXY");var Fb={};Jt(Fb,{keyToDidDoc:()=>hB,pubKeyBytesToXY:()=>p8});function hB(t,e){let r=`did:key:${e}`,n=`${r}#${e}`,i=p8(t);return{id:r,verificationMethod:[{id:n,type:"JsonWebKey2020",controller:r,publicKeyJwk:{kty:"EC",crv:"P-384",x:i.xm,y:i.ym}}],authentication:[n],assertionMethod:[n],capabilityDelegation:[n],capabilityInvocation:[n]}}o(hB,"keyToDidDoc");function p8(t){if(!vr.testUint8Array(t))throw new TypeError("input must be a Uint8Array");let e=vr.pubKeyBytesToHex(t),r=e.length/2;if(r==96)return vr.publicKeyToXY(e);if(r==97&&e.slice(0,2)=="04"){let n=e.slice(2);return vr.publicKeyToXY(n)}if(r==49&&(e.slice(0,2)=="03"||e.slice(0,2)=="02")){let n=Ot(e,"base16"),i=Wd.ECPointDecompress(n);return vr.publicKeyIntToXY(i)}throw new Error("Unexpected pubKeyBytes")}o(p8,"pubKeyBytesToXY");var qb={};Jt(qb,{keyToDidDoc:()=>dB,pubKeyBytesToXY:()=>m8});function dB(t,e){let r=`did:key:${e}`,n=`${r}#${e}`,i=m8(t);return{id:r,verificationMethod:[{id:n,type:"JsonWebKey2020",controller:r,publicKeyJwk:{kty:"EC",crv:"P-521",x:i.xm,y:i.ym}}],authentication:[n],assertionMethod:[n],capabilityDelegation:[n],capabilityInvocation:[n]}}o(dB,"keyToDidDoc");function m8(t){if(!vr.testUint8Array(t))throw new TypeError("input must be a Uint8Array");let e=vr.pubKeyBytesToHex(t);if(132<=e.length&&e.length<=134&&(e.slice(0,2)=="03"||e.slice(0,2)=="02")){let r=Ot(e,"base16"),n=Jd.ECPointDecompress(r);return vr.publicKeyIntToXY(n)}throw new Error("Unexpected pubKeyBytes")}o(m8,"pubKeyBytesToXY");var pB="application/did+ld+json",b8="application/did+json",mB={231:Rb,237:Nb,4608:$b,4609:Fb,4610:qb};function bB(){return{key:async(t,e,r,n)=>{let i=n.accept||b8,a={didResolutionMetadata:{contentType:i},didDocument:null,didDocumentMetadata:{}};try{let c=ui.decode(e.id),u=Hb.default.decode(c),m=c.slice(Hb.default.decode.bytes),v=await mB[u].keyToDidDoc(m,e.id);i===pB?(v["@context"]="https://w3id.org/did/v1",a.didDocument=v):i===b8?a.didDocument=v:(delete a.didResolutionMetadata.contentType,a.didResolutionMetadata.error="representationNotSupported")}catch(c){a.didResolutionMetadata.error="invalidDid",a.didResolutionMetadata.message=c.toString()}return a}}}o(bB,"getResolver");var g8={getResolver:bB};var Yd=Lt(Au(),1);var E8=Lt(y8(),1);var gB="base64pad";function x8(t){return JSON.parse((0,E8.default)(t))}o(x8,"toStableObject");function vB(t){let e=new Uint8Array(t.length+2);return e[0]=237,e[1]=1,e.set(t,2),`did:key:z${kt(e,"base58btc")}`}o(vB,"encodeDID");function w8(t){let[e,r,n]=t.split(".");return{payload:r,signatures:[{protected:e,signature:n}]}}o(w8,"toGeneralJWS");var _8=o(async(t,e,r,n={})=>{let i=`${e}#${e.split(":")[2]}`,a=Fx(r),c=x8(Object.assign(n,{kid:i,alg:"EdDSA"}));return Kx(typeof t=="string"?t:x8(t),a,c)},"sign"),yB={did_authenticate:async({did:t,secretKey:e},r)=>{let n=await _8({did:t,aud:r.aud,nonce:r.nonce,paths:r.paths,exp:Math.floor(Date.now()/1e3)+600},t,e);return w8(n)},did_createJWS:async({did:t,secretKey:e},r)=>{if(r.did.split("#")[0]!==t)throw new wn(4100,`Unknown DID: ${t}`);let i=await _8(r.payload,t,e,r.protected);return{jws:w8(i)}},did_decryptJWE:async({secretKey:t},e)=>{let r=Yx((0,Yd.convertSecretKeyToX25519)(t));try{let n=await Gx(e.jwe,r);return{cleartext:kt(n,gB)}}catch(n){throw new wn(-32e3,n.message)}}},tl=class{constructor(e){let{secretKey:r,publicKey:n}=(0,Yd.generateKeyPairFromSeed)(e),i=vB(n),a=d4(yB);this._handle=async c=>await a({did:i,secretKey:r},c)}get isDidProvider(){return!0}async send(e){return await this._handle(e)}};o(tl,"Ed25519Provider");var zb={};Jt(zb,{JsonPatchError:()=>dr,_areEquals:()=>il,applyOperation:()=>Ja,applyPatch:()=>n0,applyReducer:()=>AB,deepClone:()=>_B,getValueByPointer:()=>t0,validate:()=>S8,validator:()=>r0});var xB=function(){var t=o(function(e,r){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(n,i){n.__proto__=i}||function(n,i){for(var a in i)i.hasOwnProperty(a)&&(n[a]=i[a])},t(e,r)},"extendStatics");return function(e,r){t(e,r);function n(){this.constructor=e}o(n,"__"),e.prototype=r===null?Object.create(r):(n.prototype=r.prototype,new n)}}(),wB=Object.prototype.hasOwnProperty;function Zd(t,e){return wB.call(t,e)}o(Zd,"hasOwnProperty");function Qd(t){if(Array.isArray(t)){for(var e=new Array(t.length),r=0;r<e.length;r++)e[r]=""+r;return e}if(Object.keys)return Object.keys(t);var n=[];for(var i in t)Zd(t,i)&&n.push(i);return n}o(Qd,"_objectKeys");function qr(t){switch(typeof t){case"object":return JSON.parse(JSON.stringify(t));case"undefined":return null;default:return t}}o(qr,"_deepClone");function e0(t){for(var e=0,r=t.length,n;e<r;){if(n=t.charCodeAt(e),n>=48&&n<=57){e++;continue}return!1}return!0}o(e0,"isInteger");function vo(t){return t.indexOf("/")===-1&&t.indexOf("~")===-1?t:t.replace(/~/g,"~0").replace(/\//g,"~1")}o(vo,"escapePathComponent");function rl(t){return t.replace(/~1/g,"/").replace(/~0/g,"~")}o(rl,"unescapePathComponent");function Xd(t){if(t===void 0)return!0;if(t){if(Array.isArray(t)){for(var e=0,r=t.length;e<r;e++)if(Xd(t[e]))return!0}else if(typeof t=="object"){for(var n=Qd(t),i=n.length,a=0;a<i;a++)if(Xd(t[n[a]]))return!0}}return!1}o(Xd,"hasUndefined");function A8(t,e){var r=[t];for(var n in e){var i=typeof e[n]=="object"?JSON.stringify(e[n],null,2):e[n];typeof i<"u"&&r.push(n+": "+i)}return r.join(`
815
815
  `)}o(A8,"patchErrorMessageFormatter");var nl=function(t){xB(e,t);function e(r,n,i,a,c){var u=this.constructor,m=t.call(this,A8(r,{name:n,index:i,operation:a,tree:c}))||this;return m.name=n,m.index=i,m.operation=a,m.tree=c,Object.setPrototypeOf(m,u.prototype),m.message=A8(r,{name:n,index:i,operation:a,tree:c}),m}return o(e,"PatchError"),e}(Error);var dr=nl,_B=qr,yc={add:function(t,e,r){return t[e]=this.value,{newDocument:r}},remove:function(t,e,r){var n=t[e];return delete t[e],{newDocument:r,removed:n}},replace:function(t,e,r){var n=t[e];return t[e]=this.value,{newDocument:r,removed:n}},move:function(t,e,r){var n=t0(r,this.path);n&&(n=qr(n));var i=Ja(r,{op:"remove",path:this.from}).removed;return Ja(r,{op:"add",path:this.path,value:i}),{newDocument:r,removed:n}},copy:function(t,e,r){var n=t0(r,this.from);return Ja(r,{op:"add",path:this.path,value:qr(n)}),{newDocument:r}},test:function(t,e,r){return{newDocument:r,test:il(t[e],this.value)}},_get:function(t,e,r){return this.value=t[e],{newDocument:r}}},EB={add:function(t,e,r){return e0(e)?t.splice(e,0,this.value):t[e]=this.value,{newDocument:r,index:e}},remove:function(t,e,r){var n=t.splice(e,1);return{newDocument:r,removed:n[0]}},replace:function(t,e,r){var n=t[e];return t[e]=this.value,{newDocument:r,removed:n}},move:yc.move,copy:yc.copy,test:yc.test,_get:yc._get};function t0(t,e){if(e=="")return t;var r={op:"_get",path:e};return Ja(t,r),r.value}o(t0,"getValueByPointer");function Ja(t,e,r,n,i,a){if(r===void 0&&(r=!1),n===void 0&&(n=!0),i===void 0&&(i=!0),a===void 0&&(a=0),r&&(typeof r=="function"?r(e,0,t,e.path):r0(e,0)),e.path===""){var c={newDocument:t};if(e.op==="add")return c.newDocument=e.value,c;if(e.op==="replace")return c.newDocument=e.value,c.removed=t,c;if(e.op==="move"||e.op==="copy")return c.newDocument=t0(t,e.from),e.op==="move"&&(c.removed=t),c;if(e.op==="test"){if(c.test=il(t,e.value),c.test===!1)throw new dr("Test operation failed","TEST_OPERATION_FAILED",a,e,t);return c.newDocument=t,c}else{if(e.op==="remove")return c.removed=t,c.newDocument=null,c;if(e.op==="_get")return e.value=t,c;if(r)throw new dr("Operation `op` property is not one of operations defined in RFC-6902","OPERATION_OP_INVALID",a,e,t);return c}}else{n||(t=qr(t));var u=e.path||"",m=u.split("/"),v=t,x=1,S=m.length,O=void 0,R=void 0,D=void 0;for(typeof r=="function"?D=r:D=r0;;){if(R=m[x],R&&R.indexOf("~")!=-1&&(R=rl(R)),i&&(R=="__proto__"||R=="prototype"&&x>0&&m[x-1]=="constructor"))throw new TypeError("JSON-Patch: modifying `__proto__` or `constructor/prototype` prop is banned for security reasons, if this was on purpose, please set `banPrototypeModifications` flag false and pass it to this function. More info in fast-json-patch README");if(r&&O===void 0&&(v[R]===void 0?O=m.slice(0,x).join("/"):x==S-1&&(O=e.path),O!==void 0&&D(e,0,t,O)),x++,Array.isArray(v)){if(R==="-")R=v.length;else{if(r&&!e0(R))throw new dr("Expected an unsigned base-10 integer value, making the new referenced value the array element with the zero-based index","OPERATION_PATH_ILLEGAL_ARRAY_INDEX",a,e,t);e0(R)&&(R=~~R)}if(x>=S){if(r&&e.op==="add"&&R>v.length)throw new dr("The specified index MUST NOT be greater than the number of elements in the array","OPERATION_VALUE_OUT_OF_BOUNDS",a,e,t);var c=EB[e.op].call(e,v,R,t);if(c.test===!1)throw new dr("Test operation failed","TEST_OPERATION_FAILED",a,e,t);return c}}else if(x>=S){var c=yc[e.op].call(e,v,R,t);if(c.test===!1)throw new dr("Test operation failed","TEST_OPERATION_FAILED",a,e,t);return c}if(v=v[R],r&&x<S&&(!v||typeof v!="object"))throw new dr("Cannot perform operation at the desired path","OPERATION_PATH_UNRESOLVABLE",a,e,t)}}}o(Ja,"applyOperation");function n0(t,e,r,n,i){if(n===void 0&&(n=!0),i===void 0&&(i=!0),r&&!Array.isArray(e))throw new dr("Patch sequence must be an array","SEQUENCE_NOT_AN_ARRAY");n||(t=qr(t));for(var a=new Array(e.length),c=0,u=e.length;c<u;c++)a[c]=Ja(t,e[c],r,!0,i,c),t=a[c].newDocument;return a.newDocument=t,a}o(n0,"applyPatch");function AB(t,e,r){var n=Ja(t,e);if(n.test===!1)throw new dr("Test operation failed","TEST_OPERATION_FAILED",r,e,t);return n.newDocument}o(AB,"applyReducer");function r0(t,e,r,n){if(typeof t!="object"||t===null||Array.isArray(t))throw new dr("Operation is not an object","OPERATION_NOT_AN_OBJECT",e,t,r);if(yc[t.op]){if(typeof t.path!="string")throw new dr("Operation `path` property is not a string","OPERATION_PATH_INVALID",e,t,r);if(t.path.indexOf("/")!==0&&t.path.length>0)throw new dr('Operation `path` property must start with "/"',"OPERATION_PATH_INVALID",e,t,r);if((t.op==="move"||t.op==="copy")&&typeof t.from!="string")throw new dr("Operation `from` property is not present (applicable in `move` and `copy` operations)","OPERATION_FROM_REQUIRED",e,t,r);if((t.op==="add"||t.op==="replace"||t.op==="test")&&t.value===void 0)throw new dr("Operation `value` property is not present (applicable in `add`, `replace` and `test` operations)","OPERATION_VALUE_REQUIRED",e,t,r);if((t.op==="add"||t.op==="replace"||t.op==="test")&&Xd(t.value))throw new dr("Operation `value` property is not present (applicable in `add`, `replace` and `test` operations)","OPERATION_VALUE_CANNOT_CONTAIN_UNDEFINED",e,t,r);if(r){if(t.op=="add"){var i=t.path.split("/").length,a=n.split("/").length;if(i!==a+1&&i!==a)throw new dr("Cannot perform an `add` operation at the desired path","OPERATION_PATH_CANNOT_ADD",e,t,r)}else if(t.op==="replace"||t.op==="remove"||t.op==="_get"){if(t.path!==n)throw new dr("Cannot perform the operation at a path that does not exist","OPERATION_PATH_UNRESOLVABLE",e,t,r)}else if(t.op==="move"||t.op==="copy"){var c={op:"_get",path:t.from,value:void 0},u=S8([c],r);if(u&&u.name==="OPERATION_PATH_UNRESOLVABLE")throw new dr("Cannot perform the operation from a path that does not exist","OPERATION_FROM_UNRESOLVABLE",e,t,r)}}}else throw new dr("Operation `op` property is not one of operations defined in RFC-6902","OPERATION_OP_INVALID",e,t,r)}o(r0,"validator");function S8(t,e,r){try{if(!Array.isArray(t))throw new dr("Patch sequence must be an array","SEQUENCE_NOT_AN_ARRAY");if(e)n0(qr(e),qr(t),r||!0);else{r=r||r0;for(var n=0;n<t.length;n++)r(t[n],n,e,void 0)}}catch(i){if(i instanceof dr)return i;throw i}}o(S8,"validate");function il(t,e){if(t===e)return!0;if(t&&e&&typeof t=="object"&&typeof e=="object"){var r=Array.isArray(t),n=Array.isArray(e),i,a,c;if(r&&n){if(a=t.length,a!=e.length)return!1;for(i=a;i--!==0;)if(!il(t[i],e[i]))return!1;return!0}if(r!=n)return!1;var u=Object.keys(t);if(a=u.length,a!==Object.keys(e).length)return!1;for(i=a;i--!==0;)if(!e.hasOwnProperty(u[i]))return!1;for(i=a;i--!==0;)if(c=u[i],!il(t[c],e[c]))return!1;return!0}return t!==t&&e!==e}o(il,"_areEquals");var Vb={};Jt(Vb,{compare:()=>OB,generate:()=>Kb,observe:()=>DB,unobserve:()=>IB});var jb=new WeakMap,SB=function(){function t(e){this.observers=new Map,this.obj=e}return o(t,"Mirror"),t}(),MB=function(){function t(e,r){this.callback=e,this.observer=r}return o(t,"ObserverInfo"),t}();function TB(t){return jb.get(t)}o(TB,"getMirror");function CB(t,e){return t.observers.get(e)}o(CB,"getObserverFromMirror");function kB(t,e){t.observers.delete(e.callback)}o(kB,"removeObserverFromMirror");function IB(t,e){e.unobserve()}o(IB,"unobserve");function DB(t,e){var r=[],n,i=TB(t);if(!i)i=new SB(t),jb.set(t,i);else{var a=CB(i,e);n=a&&a.observer}if(n)return n;if(n={},i.value=qr(t),e){n.callback=e,n.next=null;var c=o(function(){Kb(n)},"dirtyCheck"),u=o(function(){clearTimeout(n.next),n.next=setTimeout(c)},"fastCheck");typeof window<"u"&&(window.addEventListener("mouseup",u),window.addEventListener("keyup",u),window.addEventListener("mousedown",u),window.addEventListener("keydown",u),window.addEventListener("change",u))}return n.patches=r,n.object=t,n.unobserve=function(){Kb(n),clearTimeout(n.next),kB(i,n),typeof window<"u"&&(window.removeEventListener("mouseup",u),window.removeEventListener("keyup",u),window.removeEventListener("mousedown",u),window.removeEventListener("keydown",u),window.removeEventListener("change",u))},i.observers.set(e,new MB(e,n)),n}o(DB,"observe");function Kb(t,e){e===void 0&&(e=!1);var r=jb.get(t.object);Gb(r.value,t.object,t.patches,"",e),t.patches.length&&n0(r.value,t.patches);var n=t.patches;return n.length>0&&(t.patches=[],t.callback&&t.callback(n)),n}o(Kb,"generate");function Gb(t,e,r,n,i){if(e!==t){typeof e.toJSON=="function"&&(e=e.toJSON());for(var a=Qd(e),c=Qd(t),u=!1,m=!1,v=c.length-1;v>=0;v--){var x=c[v],S=t[x];if(Zd(e,x)&&!(e[x]===void 0&&S!==void 0&&Array.isArray(e)===!1)){var O=e[x];typeof S=="object"&&S!=null&&typeof O=="object"&&O!=null&&Array.isArray(S)===Array.isArray(O)?Gb(S,O,r,n+"/"+vo(x),i):S!==O&&(u=!0,i&&r.push({op:"test",path:n+"/"+vo(x),value:qr(S)}),r.push({op:"replace",path:n+"/"+vo(x),value:qr(O)}))}else Array.isArray(t)===Array.isArray(e)?(i&&r.push({op:"test",path:n+"/"+vo(x),value:qr(S)}),r.push({op:"remove",path:n+"/"+vo(x)}),m=!0):(i&&r.push({op:"test",path:n,value:t}),r.push({op:"replace",path:n,value:e}),u=!0)}if(!(!m&&a.length==c.length))for(var v=0;v<a.length;v++){var x=a[v];!Zd(t,x)&&e[x]!==void 0&&r.push({op:"add",path:n+"/"+vo(x),value:qr(e[x])})}}}o(Gb,"_generate");function OB(t,e,r){r===void 0&&(r=!1);var n=[];return Gb(t,e,n,"",r),n}o(OB,"compare");var i0=Object.assign({},zb,Vb,{JsonPatchError:nl,deepClone:qr,escapePathComponent:vo,unescapePathComponent:rl});var pE=Lt(Ac(),1);var mE=Lt(Oa(),1);var yr;(function(t){t[t.PREFER_CACHE=0]="PREFER_CACHE",t[t.SYNC_ALWAYS=1]="SYNC_ALWAYS",t[t.NEVER_SYNC=2]="NEVER_SYNC"})(yr||(yr={}));var kg=Lt(Ac(),1);Pi();Bf();var d_={tile:0,"caip10-link":1,model:2,MID:3,UNLOADABLE:4};function s$(t){let e=d_[t];if(typeof e<"u")return e;throw new Error(`No stream type registered for name ${t}`)}o(s$,"codeByName");function a$(t){let e=Object.entries(d_).find(([,r])=>r===t);if(e)return e[0];throw new Error(`No stream type registered for index ${t}`)}o(a$,"nameByCode");var En=class{};o(En,"StreamType");En.nameByCode=a$;En.codeByName=s$;var mg=Lt(el(),1);function zn(t){let e,r,n;return typeof t=="object"?(e=t.hashFunction,r=t.expiring,n=t.tags):e=t,(i,a,c)=>{if(c.value!=null)c.value=p_(c.value,e,r,n);else if(c.get!=null)c.get=p_(c.get,e,r,n);else throw"Only put a Memoize() decorator on a method or get accessor."}}o(zn,"Memoize");var fg=new Map;function p_(t,e,r=0,n){let i=Symbol("__memoized_map__");return function(...a){let c;this.hasOwnProperty(i)||Object.defineProperty(this,i,{configurable:!1,enumerable:!1,writable:!1,value:new Map});let u=this[i];if(Array.isArray(n))for(let m of n)fg.has(m)?fg.get(m).push(u):fg.set(m,[u]);if(e||a.length>0||r>0){let m;e===!0?m=a.map(S=>S.toString()).join("!"):e?m=e.apply(this,a):m=a[0];let v=`${m}__timestamp`,x=!1;if(r>0)if(!u.has(v))x=!0;else{let S=u.get(v);x=Date.now()-S>r}u.has(m)&&!x?c=u.get(m):(c=t.apply(this,a),u.set(m,c),r>0&&u.set(v,Date.now()))}else{let m=this;u.has(m)?c=u.get(m):(c=t.apply(this,a),u.set(m,c))}return c}}o(p_,"getNewFunction");Pi();Bf();lu();var dg=Lt(el(),1);function Sc(t){try{return t()}catch(e){return e}}o(Sc,"tryCatch");Pi();var cg=Lt(el(),1);Aa();function Qa(t){let e=cg.default.decode(t),r=cg.default.decode.bytes,n=t.subarray(r);return[e,n,r]}o(Qa,"readVarint");function f$(t){return t===0||t===1}o(f$,"isCidVersion");function ug(t){let[e,r]=Qa(t);if(!f$(e))throw new Error(`Unknown CID version ${e}`);let[n,i]=Qa(r),[,a,c]=Qa(i),[u,,m]=Qa(a),v=i.subarray(0,c+m+u),x=i.subarray(c+m+u);return[We.create(e,n,Ch(v)),x]}o(ug,"readCid");Pi();Bf();function ef(t,e="StreamRef"){let[r,n]=Qa(t);if(r!==206)throw new Error(`Invalid ${e}, does not include streamid codec`);let[i,a]=Qa(n),c=ug(a),[u,m]=c;if(m.length===0)return{kind:"stream-id",type:i,genesis:u};if(m.length===1&&m[0]===0)return{kind:"commit-id",type:i,genesis:u,commit:null};{let[v]=ug(m);return{kind:"commit-id",type:i,genesis:u,commit:v}}}o(ef,"fromBytes");var c$=/(ceramic:\/\/|\/ceramic\/)?([a-zA-Z0-9]+)(\?commit=([a-zA-Z0-9]+))?/;function Mc(t,e="StreamRef"){let r=c$.exec(t)||[],n=r[2];if(!n)throw new Error(`Malformed ${e} string: ${t}`);let i=Ni.decode(n),a=ef(i),c=r[4];return c?{kind:"commit-id",type:a.type,genesis:a.genesis,commit:lg(a.genesis,c)}:a}o(Mc,"fromString");function u$(t){try{return typeof t=="string"?We.parse(t):We.asCID(t)}catch{return null}}o(u$,"parseCID");function lg(t,e=null){if(!e||e==="0")return null;let r=u$(e);if(r)return t.equals(r)?null:r;throw new Error("Cannot specify commit as a number except to request commit 0 (the genesis commit)")}o(lg,"parseCommit");var fl=function(t,e,r,n){var i=arguments.length,a=i<3?e:n===null?n=Object.getOwnPropertyDescriptor(e,r):n,c;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")a=Reflect.decorate(t,e,r,n);else for(var u=t.length-1;u>=0;u--)(c=t[u])&&(a=(i<3?c(a):i>3?c(e,r,a):c(e,r))||a);return i>3&&a&&Object.defineProperty(e,r,a),a},Ei=function(t,e){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(t,e)},d0=class extends Error{constructor(e){super(`Invalid StreamID bytes ${Ni.encode(e)}: contains commit`)}};o(d0,"InvalidStreamIDBytesError");var p0=class extends Error{constructor(e){super(`Invalid StreamID string ${e}: contains commit`)}};o(p0,"InvalidStreamIDStringError");function g_(t){let e=ef(t,"StreamID");if(e.kind==="stream-id")return new rt(e.type,e.genesis);throw new d0(t)}o(g_,"fromBytes");function l$(t){return Sc(()=>g_(t))}o(l$,"fromBytesNoThrow");function v_(t){let e=Mc(t,"StreamID");if(e.kind==="stream-id")return new rt(e.type,e.genesis);throw new p0(t)}o(v_,"fromString");function h$(t){return Sc(()=>v_(t))}o(h$,"fromStringNoThrow");var b_=Symbol.for("@ceramicnetwork/streamid/StreamID"),rt=class{constructor(e,r){if(this._tag=b_,!(e||e===0))throw new Error("StreamID constructor: type required");if(!r)throw new Error("StreamID constructor: cid required");this._type=typeof e=="string"?En.codeByName(e):e,this._cid=typeof r=="string"?We.parse(r):r}static isInstance(e){return typeof e=="object"&&"_tag"in e&&e._tag===b_}static async fromGenesis(e,r){let n=await Ua({value:r,codec:Hi,hasher:Ss});return new rt(e,n.cid)}get type(){return this._type}get typeName(){return En.nameByCode(this._type)}get cid(){return this._cid}get bytes(){let e=dg.default.encode(206),r=dg.default.encode(this.type);return Oi([e,r,this.cid.bytes])}get baseID(){return new rt(this._type,this._cid)}equals(e){return rt.isInstance(e)?this.type===e.type&&this.cid.equals(e.cid):!1}toString(){return Ni.encode(this.bytes)}toUrl(){return`ceramic://${this.toString()}`}[Symbol.for("nodejs.util.inspect.custom")](){return`StreamID(${this.toString()})`}[Symbol.toPrimitive](){return this.toString()}};o(rt,"StreamID");rt.fromBytes=g_;rt.fromBytesNoThrow=l$;rt.fromString=v_;rt.fromStringNoThrow=h$;fl([zn(),Ei("design:type",String),Ei("design:paramtypes",[])],rt.prototype,"typeName",null);fl([zn(),Ei("design:type",Uint8Array),Ei("design:paramtypes",[])],rt.prototype,"bytes",null);fl([zn(),Ei("design:type",rt),Ei("design:paramtypes",[])],rt.prototype,"baseID",null);fl([zn(),Ei("design:type",Function),Ei("design:paramtypes",[]),Ei("design:returntype",String)],rt.prototype,"toString",null);fl([zn(),Ei("design:type",Function),Ei("design:paramtypes",[]),Ei("design:returntype",String)],rt.prototype,"toUrl",null);var Cc=function(t,e,r,n){var i=arguments.length,a=i<3?e:n===null?n=Object.getOwnPropertyDescriptor(e,r):n,c;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")a=Reflect.decorate(t,e,r,n);else for(var u=t.length-1;u>=0;u--)(c=t[u])&&(a=(i<3?c(a):i>3?c(e,r,a):c(e,r))||a);return i>3&&a&&Object.defineProperty(e,r,a),a},An=function(t,e){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(t,e)},pg=function(t,e,r,n,i){if(n==="m")throw new TypeError("Private method is not writable");if(n==="a"&&!i)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?t!==e||!i:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return n==="a"?i.call(t,r):i?i.value=r:e.set(t,r),r},is=function(t,e,r,n){if(r==="a"&&!n)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?t!==e||!n:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return r==="m"?n:r==="a"?n.call(t):n?n.value:e.get(t)},Tc,tf,cl,m0=class extends Error{constructor(e){super(`Error while parsing CommitID from bytes ${Ni.encode(e)}: no commit information provided`)}};o(m0,"InvalidCommitIDBytesError");var b0=class extends Error{constructor(e){super(`Error while parsing CommitID from string ${e}: no commit information provided`)}};o(b0,"InvalidCommitIDStringError");function x_(t){let e=ef(t,"CommitID");if(e.kind==="commit-id")return new Pt(e.type,e.genesis,e.commit);throw new m0(t)}o(x_,"fromBytes");function d$(t){return Sc(()=>x_(t))}o(d$,"fromBytesNoThrow");function w_(t){let e=Mc(t,"CommitID");if(e.kind==="commit-id")return new Pt(e.type,e.genesis,e.commit);throw new b0(t)}o(w_,"fromString");function p$(t){return Sc(()=>w_(t))}o(p$,"fromStringNoThrow");var y_=Symbol.for("@ceramicnetwork/streamid/CommitID");function m$(t,e){return new Pt(t.type,t.cid,e)}o(m$,"make");var Pt=class{constructor(e,r,n=null){if(this._tag=y_,Tc.set(this,void 0),tf.set(this,void 0),cl.set(this,void 0),!e&&e!==0)throw new Error("constructor: type required");if(!r)throw new Error("constructor: cid required");pg(this,Tc,typeof e=="string"?En.codeByName(e):e,"f"),pg(this,tf,typeof r=="string"?We.parse(r):r,"f"),pg(this,cl,lg(is(this,tf,"f"),n),"f")}static isInstance(e){return typeof e=="object"&&"_tag"in e&&e._tag===y_}get baseID(){return new rt(is(this,Tc,"f"),is(this,tf,"f"))}get type(){return is(this,Tc,"f")}get typeName(){return En.nameByCode(is(this,Tc,"f"))}get cid(){return is(this,tf,"f")}get commit(){return is(this,cl,"f")||is(this,tf,"f")}get bytes(){let e=mg.default.encode(206),r=mg.default.encode(this.type),n=is(this,cl,"f")?.bytes||new Uint8Array([0]);return Oi([e,r,this.cid.bytes,n])}equals(e){return this.type===e.type&&this.cid.equals(e.cid)&&this.commit.equals(e.commit)}toString(){return Ni.encode(this.bytes)}toUrl(){return`ceramic://${this.toString()}`}[(Tc=new WeakMap,tf=new WeakMap,cl=new WeakMap,Symbol.for("nodejs.util.inspect.custom"))](){return`CommitID(${this.toString()})`}[Symbol.toPrimitive](){return this.toString()}};o(Pt,"CommitID");Pt.fromBytes=x_;Pt.fromBytesNoThrow=d$;Pt.fromString=w_;Pt.fromStringNoThrow=p$;Pt.make=m$;Cc([zn(),An("design:type",rt),An("design:paramtypes",[])],Pt.prototype,"baseID",null);Cc([zn(),An("design:type",String),An("design:paramtypes",[])],Pt.prototype,"typeName",null);Cc([zn(),An("design:type",We),An("design:paramtypes",[])],Pt.prototype,"commit",null);Cc([zn(),An("design:type",Uint8Array),An("design:paramtypes",[])],Pt.prototype,"bytes",null);Cc([zn(),An("design:type",Function),An("design:paramtypes",[]),An("design:returntype",String)],Pt.prototype,"toString",null);Cc([zn(),An("design:type",Function),An("design:paramtypes",[]),An("design:returntype",String)],Pt.prototype,"toUrl",null);Bf();var fn;(function(t){function e(i){let a=ef(i);switch(a.kind){case"commit-id":return new Pt(a.type,a.genesis,a.commit);case"stream-id":return new rt(a.type,a.genesis);default:throw new Error(`Malformed StreamRef bytes: ${Ni.encode(i)}`)}}o(e,"fromBytes"),t.fromBytes=e;function r(i){let a=Mc(i);switch(a.kind){case"commit-id":return new Pt(a.type,a.genesis,a.commit);case"stream-id":return new rt(a.type,a.genesis);default:throw new Error(`Malformed StreamRef string: ${i}`)}}o(r,"fromString"),t.fromString=r;function n(i){if(rt.isInstance(i)||Pt.isInstance(i))return i;if(i instanceof Uint8Array)return e(i);if(typeof i=="string")return r(i);throw new Error(`Can not build CommitID or StreamID from ${JSON.stringify(i)}`)}o(n,"from"),t.from=n})(fn||(fn={}));var bg=o(function(t,e){return bg=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(r,n){r.__proto__=n}||function(r,n){for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&(r[i]=n[i])},bg(t,e)},"extendStatics");function Qr(t,e){if(typeof e!="function"&&e!==null)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");bg(t,e);function r(){this.constructor=t}o(r,"__"),t.prototype=e===null?Object.create(e):(r.prototype=e.prototype,new r)}o(Qr,"__extends");function __(t,e,r,n){function i(a){return a instanceof r?a:new r(function(c){c(a)})}return o(i,"adopt"),new(r||(r=Promise))(function(a,c){function u(x){try{v(n.next(x))}catch(S){c(S)}}o(u,"fulfilled");function m(x){try{v(n.throw(x))}catch(S){c(S)}}o(m,"rejected");function v(x){x.done?a(x.value):i(x.value).then(u,m)}o(v,"step"),v((n=n.apply(t,e||[])).next())})}o(__,"__awaiter");function g0(t,e){var r={label:0,sent:function(){if(a[0]&1)throw a[1];return a[1]},trys:[],ops:[]},n,i,a,c;return c={next:u(0),throw:u(1),return:u(2)},typeof Symbol=="function"&&(c[Symbol.iterator]=function(){return this}),c;function u(v){return function(x){return m([v,x])}}function m(v){if(n)throw new TypeError("Generator is already executing.");for(;c&&(c=0,v[0]&&(r=0)),r;)try{if(n=1,i&&(a=v[0]&2?i.return:v[0]?i.throw||((a=i.return)&&a.call(i),0):i.next)&&!(a=a.call(i,v[1])).done)return a;switch(i=0,a&&(v=[v[0]&2,a.value]),v[0]){case 0:case 1:a=v;break;case 4:return r.label++,{value:v[1],done:!1};case 5:r.label++,i=v[1],v=[0];continue;case 7:v=r.ops.pop(),r.trys.pop();continue;default:if(a=r.trys,!(a=a.length>0&&a[a.length-1])&&(v[0]===6||v[0]===2)){r=0;continue}if(v[0]===3&&(!a||v[1]>a[0]&&v[1]<a[3])){r.label=v[1];break}if(v[0]===6&&r.label<a[1]){r.label=a[1],a=v;break}if(a&&r.label<a[2]){r.label=a[2],r.ops.push(v);break}a[2]&&r.ops.pop(),r.trys.pop();continue}v=e.call(t,r)}catch(x){v=[6,x],i=0}finally{n=a=0}if(v[0]&5)throw v[1];return{value:v[0]?v[1]:void 0,done:!0}}}o(g0,"__generator");function os(t){var e=typeof Symbol=="function"&&Symbol.iterator,r=e&&t[e],n=0;if(r)return r.call(t);if(t&&typeof t.length=="number")return{next:function(){return t&&n>=t.length&&(t=void 0),{value:t&&t[n++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}o(os,"__values");function Kn(t,e){var r=typeof Symbol=="function"&&t[Symbol.iterator];if(!r)return t;var n=r.call(t),i,a=[],c;try{for(;(e===void 0||e-- >0)&&!(i=n.next()).done;)a.push(i.value)}catch(u){c={error:u}}finally{try{i&&!i.done&&(r=n.return)&&r.call(n)}finally{if(c)throw c.error}}return a}o(Kn,"__read");function Vi(t,e,r){if(r||arguments.length===2)for(var n=0,i=e.length,a;n<i;n++)(a||!(n in e))&&(a||(a=Array.prototype.slice.call(e,0,n)),a[n]=e[n]);return t.concat(a||Array.prototype.slice.call(e))}o(Vi,"__spreadArray");function rf(t){return this instanceof rf?(this.v=t,this):new rf(t)}o(rf,"__await");function E_(t,e,r){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var n=r.apply(t,e||[]),i,a=[];return i={},c("next"),c("throw"),c("return"),i[Symbol.asyncIterator]=function(){return this},i;function c(O){n[O]&&(i[O]=function(R){return new Promise(function(D,P){a.push([O,R,D,P])>1||u(O,R)})})}function u(O,R){try{m(n[O](R))}catch(D){S(a[0][3],D)}}function m(O){O.value instanceof rf?Promise.resolve(O.value.v).then(v,x):S(a[0][2],O)}function v(O){u("next",O)}function x(O){u("throw",O)}function S(O,R){O(R),a.shift(),a.length&&u(a[0][0],a[0][1])}}o(E_,"__asyncGenerator");function A_(t){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var e=t[Symbol.asyncIterator],r;return e?e.call(t):(t=typeof os=="function"?os(t):t[Symbol.iterator](),r={},n("next"),n("throw"),n("return"),r[Symbol.asyncIterator]=function(){return this},r);function n(a){r[a]=t[a]&&function(c){return new Promise(function(u,m){c=t[a](c),i(u,m,c.done,c.value)})}}function i(a,c,u,m){Promise.resolve(m).then(function(v){a({value:v,done:u})},c)}}o(A_,"__asyncValues");function At(t){return typeof t=="function"}o(At,"isFunction");function kc(t){var e=o(function(n){Error.call(n),n.stack=new Error().stack},"_super"),r=t(e);return r.prototype=Object.create(Error.prototype),r.prototype.constructor=r,r}o(kc,"createErrorClass");var v0=kc(function(t){return o(function(r){t(this),this.message=r?r.length+` errors occurred during unsubscription:
816
816
  `+r.map(function(n,i){return i+1+") "+n.toString()}).join(`
817
- `):"",this.name="UnsubscriptionError",this.errors=r},"UnsubscriptionErrorImpl")});function nf(t,e){if(t){var r=t.indexOf(e);0<=r&&t.splice(r,1)}}o(nf,"arrRemove");var Js=function(){function t(e){this.initialTeardown=e,this.closed=!1,this._parentage=null,this._finalizers=null}return o(t,"Subscription"),t.prototype.unsubscribe=function(){var e,r,n,i,a;if(!this.closed){this.closed=!0;var c=this._parentage;if(c)if(this._parentage=null,Array.isArray(c))try{for(var u=os(c),m=u.next();!m.done;m=u.next()){var v=m.value;v.remove(this)}}catch(P){e={error:P}}finally{try{m&&!m.done&&(r=u.return)&&r.call(u)}finally{if(e)throw e.error}}else c.remove(this);var x=this.initialTeardown;if(At(x))try{x()}catch(P){a=P instanceof v0?P.errors:[P]}var S=this._finalizers;if(S){this._finalizers=null;try{for(var O=os(S),R=O.next();!R.done;R=O.next()){var D=R.value;try{S_(D)}catch(P){a=a??[],P instanceof v0?a=Vi(Vi([],Kn(a)),Kn(P.errors)):a.push(P)}}}catch(P){n={error:P}}finally{try{R&&!R.done&&(i=O.return)&&i.call(O)}finally{if(n)throw n.error}}}if(a)throw new v0(a)}},t.prototype.add=function(e){var r;if(e&&e!==this)if(this.closed)S_(e);else{if(e instanceof t){if(e.closed||e._hasParent(this))return;e._addParent(this)}(this._finalizers=(r=this._finalizers)!==null&&r!==void 0?r:[]).push(e)}},t.prototype._hasParent=function(e){var r=this._parentage;return r===e||Array.isArray(r)&&r.includes(e)},t.prototype._addParent=function(e){var r=this._parentage;this._parentage=Array.isArray(r)?(r.push(e),r):r?[r,e]:e},t.prototype._removeParent=function(e){var r=this._parentage;r===e?this._parentage=null:Array.isArray(r)&&nf(r,e)},t.prototype.remove=function(e){var r=this._finalizers;r&&nf(r,e),e instanceof t&&e._removeParent(this)},t.EMPTY=function(){var e=new t;return e.closed=!0,e}(),t}();var gg=Js.EMPTY;function y0(t){return t instanceof Js||t&&"closed"in t&&At(t.remove)&&At(t.add)&&At(t.unsubscribe)}o(y0,"isSubscription");function S_(t){At(t)?t():t.unsubscribe()}o(S_,"execFinalizer");var Wi={onUnhandledError:null,onStoppedNotification:null,Promise:void 0,useDeprecatedSynchronousErrorHandling:!1,useDeprecatedNextContext:!1};var Ic={setTimeout:function(t,e){for(var r=[],n=2;n<arguments.length;n++)r[n-2]=arguments[n];var i=Ic.delegate;return i?.setTimeout?i.setTimeout.apply(i,Vi([t,e],Kn(r))):setTimeout.apply(void 0,Vi([t,e],Kn(r)))},clearTimeout:function(t){var e=Ic.delegate;return(e?.clearTimeout||clearTimeout)(t)},delegate:void 0};function x0(t){Ic.setTimeout(function(){var e=Wi.onUnhandledError;if(e)e(t);else throw t})}o(x0,"reportUnhandledError");function vg(){}o(vg,"noop");var M_=function(){return yg("C",void 0,void 0)}();function T_(t){return yg("E",void 0,t)}o(T_,"errorNotification");function C_(t){return yg("N",t,void 0)}o(C_,"nextNotification");function yg(t,e,r){return{kind:t,value:e,error:r}}o(yg,"createNotification");var of=null;function Dc(t){if(Wi.useDeprecatedSynchronousErrorHandling){var e=!of;if(e&&(of={errorThrown:!1,error:null}),t(),e){var r=of,n=r.errorThrown,i=r.error;if(of=null,n)throw i}}else t()}o(Dc,"errorContext");function k_(t){Wi.useDeprecatedSynchronousErrorHandling&&of&&(of.errorThrown=!0,of.error=t)}o(k_,"captureError");var ul=function(t){Qr(e,t);function e(r){var n=t.call(this)||this;return n.isStopped=!1,r?(n.destination=r,y0(r)&&r.add(n)):n.destination=y$,n}return o(e,"Subscriber"),e.create=function(r,n,i){return new _0(r,n,i)},e.prototype.next=function(r){this.isStopped?wg(C_(r),this):this._next(r)},e.prototype.error=function(r){this.isStopped?wg(T_(r),this):(this.isStopped=!0,this._error(r))},e.prototype.complete=function(){this.isStopped?wg(M_,this):(this.isStopped=!0,this._complete())},e.prototype.unsubscribe=function(){this.closed||(this.isStopped=!0,t.prototype.unsubscribe.call(this),this.destination=null)},e.prototype._next=function(r){this.destination.next(r)},e.prototype._error=function(r){try{this.destination.error(r)}finally{this.unsubscribe()}},e.prototype._complete=function(){try{this.destination.complete()}finally{this.unsubscribe()}},e}(Js);var b$=Function.prototype.bind;function xg(t,e){return b$.call(t,e)}o(xg,"bind");var g$=function(){function t(e){this.partialObserver=e}return o(t,"ConsumerObserver"),t.prototype.next=function(e){var r=this.partialObserver;if(r.next)try{r.next(e)}catch(n){w0(n)}},t.prototype.error=function(e){var r=this.partialObserver;if(r.error)try{r.error(e)}catch(n){w0(n)}else w0(e)},t.prototype.complete=function(){var e=this.partialObserver;if(e.complete)try{e.complete()}catch(r){w0(r)}},t}(),_0=function(t){Qr(e,t);function e(r,n,i){var a=t.call(this)||this,c;if(At(r)||!r)c={next:r??void 0,error:n??void 0,complete:i??void 0};else{var u;a&&Wi.useDeprecatedNextContext?(u=Object.create(r),u.unsubscribe=function(){return a.unsubscribe()},c={next:r.next&&xg(r.next,u),error:r.error&&xg(r.error,u),complete:r.complete&&xg(r.complete,u)}):c=r}return a.destination=new g$(c),a}return o(e,"SafeSubscriber"),e}(ul);function w0(t){Wi.useDeprecatedSynchronousErrorHandling?k_(t):x0(t)}o(w0,"handleUnhandledError");function v$(t){throw t}o(v$,"defaultErrorHandler");function wg(t,e){var r=Wi.onStoppedNotification;r&&Ic.setTimeout(function(){return r(t,e)})}o(wg,"handleStoppedNotification");var y$={closed:!0,next:vg,error:v$,complete:vg};var Oc=function(){return typeof Symbol=="function"&&Symbol.observable||"@@observable"}();function Rc(t){return t}o(Rc,"identity");function I_(t){return t.length===0?Rc:t.length===1?t[0]:o(function(r){return t.reduce(function(n,i){return i(n)},r)},"piped")}o(I_,"pipeFromArray");var Wt=function(){function t(e){e&&(this._subscribe=e)}return o(t,"Observable"),t.prototype.lift=function(e){var r=new t;return r.source=this,r.operator=e,r},t.prototype.subscribe=function(e,r,n){var i=this,a=w$(e)?e:new _0(e,r,n);return Dc(function(){var c=i,u=c.operator,m=c.source;a.add(u?u.call(a,m):m?i._subscribe(a):i._trySubscribe(a))}),a},t.prototype._trySubscribe=function(e){try{return this._subscribe(e)}catch(r){e.error(r)}},t.prototype.forEach=function(e,r){var n=this;return r=D_(r),new r(function(i,a){var c=new _0({next:function(u){try{e(u)}catch(m){a(m),c.unsubscribe()}},error:a,complete:i});n.subscribe(c)})},t.prototype._subscribe=function(e){var r;return(r=this.source)===null||r===void 0?void 0:r.subscribe(e)},t.prototype[Oc]=function(){return this},t.prototype.pipe=function(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];return I_(e)(this)},t.prototype.toPromise=function(e){var r=this;return e=D_(e),new e(function(n,i){var a;r.subscribe(function(c){return a=c},function(c){return i(c)},function(){return n(a)})})},t.create=function(e){return new t(e)},t}();function D_(t){var e;return(e=t??Wi.Promise)!==null&&e!==void 0?e:Promise}o(D_,"getPromiseCtor");function x$(t){return t&&At(t.next)&&At(t.error)&&At(t.complete)}o(x$,"isObserver");function w$(t){return t&&t instanceof ul||x$(t)&&y0(t)}o(w$,"isSubscriber");function _$(t){return At(t?.lift)}o(_$,"hasLift");function Dr(t){return function(e){if(_$(e))return e.lift(function(r){try{return t(r,this)}catch(n){this.error(n)}});throw new TypeError("Unable to lift unknown Observable type")}}o(Dr,"operate");function Or(t,e,r,n,i){return new E$(t,e,r,n,i)}o(Or,"createOperatorSubscriber");var E$=function(t){Qr(e,t);function e(r,n,i,a,c,u){var m=t.call(this,r)||this;return m.onFinalize=c,m.shouldUnsubscribe=u,m._next=n?function(v){try{n(v)}catch(x){r.error(x)}}:t.prototype._next,m._error=a?function(v){try{a(v)}catch(x){r.error(x)}finally{this.unsubscribe()}}:t.prototype._error,m._complete=i?function(){try{i()}catch(v){r.error(v)}finally{this.unsubscribe()}}:t.prototype._complete,m}return o(e,"OperatorSubscriber"),e.prototype.unsubscribe=function(){var r;if(!this.shouldUnsubscribe||this.shouldUnsubscribe()){var n=this.closed;t.prototype.unsubscribe.call(this),!n&&((r=this.onFinalize)===null||r===void 0||r.call(this))}},e}(ul);var O_=kc(function(t){return o(function(){t(this),this.name="ObjectUnsubscribedError",this.message="object unsubscribed"},"ObjectUnsubscribedErrorImpl")});var _g=function(t){Qr(e,t);function e(){var r=t.call(this)||this;return r.closed=!1,r.currentObservers=null,r.observers=[],r.isStopped=!1,r.hasError=!1,r.thrownError=null,r}return o(e,"Subject"),e.prototype.lift=function(r){var n=new R_(this,this);return n.operator=r,n},e.prototype._throwIfClosed=function(){if(this.closed)throw new O_},e.prototype.next=function(r){var n=this;Dc(function(){var i,a;if(n._throwIfClosed(),!n.isStopped){n.currentObservers||(n.currentObservers=Array.from(n.observers));try{for(var c=os(n.currentObservers),u=c.next();!u.done;u=c.next()){var m=u.value;m.next(r)}}catch(v){i={error:v}}finally{try{u&&!u.done&&(a=c.return)&&a.call(c)}finally{if(i)throw i.error}}}})},e.prototype.error=function(r){var n=this;Dc(function(){if(n._throwIfClosed(),!n.isStopped){n.hasError=n.isStopped=!0,n.thrownError=r;for(var i=n.observers;i.length;)i.shift().error(r)}})},e.prototype.complete=function(){var r=this;Dc(function(){if(r._throwIfClosed(),!r.isStopped){r.isStopped=!0;for(var n=r.observers;n.length;)n.shift().complete()}})},e.prototype.unsubscribe=function(){this.isStopped=this.closed=!0,this.observers=this.currentObservers=null},Object.defineProperty(e.prototype,"observed",{get:function(){var r;return((r=this.observers)===null||r===void 0?void 0:r.length)>0},enumerable:!1,configurable:!0}),e.prototype._trySubscribe=function(r){return this._throwIfClosed(),t.prototype._trySubscribe.call(this,r)},e.prototype._subscribe=function(r){return this._throwIfClosed(),this._checkFinalizedStatuses(r),this._innerSubscribe(r)},e.prototype._innerSubscribe=function(r){var n=this,i=this,a=i.hasError,c=i.isStopped,u=i.observers;return a||c?gg:(this.currentObservers=null,u.push(r),new Js(function(){n.currentObservers=null,nf(u,r)}))},e.prototype._checkFinalizedStatuses=function(r){var n=this,i=n.hasError,a=n.thrownError,c=n.isStopped;i?r.error(a):c&&r.complete()},e.prototype.asObservable=function(){var r=new Wt;return r.source=this,r},e.create=function(r,n){return new R_(r,n)},e}(Wt);var R_=function(t){Qr(e,t);function e(r,n){var i=t.call(this)||this;return i.destination=r,i.source=n,i}return o(e,"AnonymousSubject"),e.prototype.next=function(r){var n,i;(i=(n=this.destination)===null||n===void 0?void 0:n.next)===null||i===void 0||i.call(n,r)},e.prototype.error=function(r){var n,i;(i=(n=this.destination)===null||n===void 0?void 0:n.error)===null||i===void 0||i.call(n,r)},e.prototype.complete=function(){var r,n;(n=(r=this.destination)===null||r===void 0?void 0:r.complete)===null||n===void 0||n.call(r)},e.prototype._subscribe=function(r){var n,i;return(i=(n=this.source)===null||n===void 0?void 0:n.subscribe(r))!==null&&i!==void 0?i:gg},e}(_g);var Eg=function(t){Qr(e,t);function e(r){var n=t.call(this)||this;return n._value=r,n}return o(e,"BehaviorSubject"),Object.defineProperty(e.prototype,"value",{get:function(){return this.getValue()},enumerable:!1,configurable:!0}),e.prototype._subscribe=function(r){var n=t.prototype._subscribe.call(this,r);return!n.closed&&r.next(this._value),n},e.prototype.getValue=function(){var r=this,n=r.hasError,i=r.thrownError,a=r._value;if(n)throw i;return this._throwIfClosed(),a},e.prototype.next=function(r){t.prototype.next.call(this,this._value=r)},e}(_g);var Ag={now:function(){return(Ag.delegate||Date).now()},delegate:void 0};var N_=function(t){Qr(e,t);function e(r,n){return t.call(this)||this}return o(e,"Action"),e.prototype.schedule=function(r,n){return n===void 0&&(n=0),this},e}(Js);var ll={setInterval:function(t,e){for(var r=[],n=2;n<arguments.length;n++)r[n-2]=arguments[n];var i=ll.delegate;return i?.setInterval?i.setInterval.apply(i,Vi([t,e],Kn(r))):setInterval.apply(void 0,Vi([t,e],Kn(r)))},clearInterval:function(t){var e=ll.delegate;return(e?.clearInterval||clearInterval)(t)},delegate:void 0};var P_=function(t){Qr(e,t);function e(r,n){var i=t.call(this,r,n)||this;return i.scheduler=r,i.work=n,i.pending=!1,i}return o(e,"AsyncAction"),e.prototype.schedule=function(r,n){var i;if(n===void 0&&(n=0),this.closed)return this;this.state=r;var a=this.id,c=this.scheduler;return a!=null&&(this.id=this.recycleAsyncId(c,a,n)),this.pending=!0,this.delay=n,this.id=(i=this.id)!==null&&i!==void 0?i:this.requestAsyncId(c,this.id,n),this},e.prototype.requestAsyncId=function(r,n,i){return i===void 0&&(i=0),ll.setInterval(r.flush.bind(r,this),i)},e.prototype.recycleAsyncId=function(r,n,i){if(i===void 0&&(i=0),i!=null&&this.delay===i&&this.pending===!1)return n;n!=null&&ll.clearInterval(n)},e.prototype.execute=function(r,n){if(this.closed)return new Error("executing a cancelled action");this.pending=!1;var i=this._execute(r,n);if(i)return i;this.pending===!1&&this.id!=null&&(this.id=this.recycleAsyncId(this.scheduler,this.id,null))},e.prototype._execute=function(r,n){var i=!1,a;try{this.work(r)}catch(c){i=!0,a=c||new Error("Scheduled action threw falsy error")}if(i)return this.unsubscribe(),a},e.prototype.unsubscribe=function(){if(!this.closed){var r=this,n=r.id,i=r.scheduler,a=i.actions;this.work=this.state=this.scheduler=null,this.pending=!1,nf(a,this),n!=null&&(this.id=this.recycleAsyncId(i,n,null)),this.delay=null,t.prototype.unsubscribe.call(this)}},e}(N_);var Sg=function(){function t(e,r){r===void 0&&(r=t.now),this.schedulerActionCtor=e,this.now=r}return o(t,"Scheduler"),t.prototype.schedule=function(e,r,n){return r===void 0&&(r=0),new this.schedulerActionCtor(this,e).schedule(n,r)},t.now=Ag.now,t}();var L_=function(t){Qr(e,t);function e(r,n){n===void 0&&(n=Sg.now);var i=t.call(this,r,n)||this;return i.actions=[],i._active=!1,i}return o(e,"AsyncScheduler"),e.prototype.flush=function(r){var n=this.actions;if(this._active){n.push(r);return}var i;this._active=!0;do if(i=r.execute(r.state,r.delay))break;while(r=n.shift());if(this._active=!1,i){for(;r=n.shift();)r.unsubscribe();throw i}},e}(Sg);var A$=new L_(P_),B_=A$;var E0=new Wt(function(t){return t.complete()});function A0(t){return t&&At(t.schedule)}o(A0,"isScheduler");function U_(t){return t[t.length-1]}o(U_,"last");function $_(t){return A0(U_(t))?t.pop():void 0}o($_,"popScheduler");function F_(t,e){return typeof U_(t)=="number"?t.pop():e}o(F_,"popNumber");var Nc=o(function(t){return t&&typeof t.length=="number"&&typeof t!="function"},"isArrayLike");function S0(t){return At(t?.then)}o(S0,"isPromise");function M0(t){return At(t[Oc])}o(M0,"isInteropObservable");function T0(t){return Symbol.asyncIterator&&At(t?.[Symbol.asyncIterator])}o(T0,"isAsyncIterable");function C0(t){return new TypeError("You provided "+(t!==null&&typeof t=="object"?"an invalid object":"'"+t+"'")+" where a stream was expected. You can provide an Observable, Promise, ReadableStream, Array, AsyncIterable, or Iterable.")}o(C0,"createInvalidObservableTypeError");function S$(){return typeof Symbol!="function"||!Symbol.iterator?"@@iterator":Symbol.iterator}o(S$,"getSymbolIterator");var k0=S$();function I0(t){return At(t?.[k0])}o(I0,"isIterable");function D0(t){return E_(this,arguments,o(function(){var r,n,i,a;return g0(this,function(c){switch(c.label){case 0:r=t.getReader(),c.label=1;case 1:c.trys.push([1,,9,10]),c.label=2;case 2:return[4,rf(r.read())];case 3:return n=c.sent(),i=n.value,a=n.done,a?[4,rf(void 0)]:[3,5];case 4:return[2,c.sent()];case 5:return[4,rf(i)];case 6:return[4,c.sent()];case 7:return c.sent(),[3,2];case 8:return[3,10];case 9:return r.releaseLock(),[7];case 10:return[2]}})},"readableStreamLikeToAsyncGenerator_1"))}o(D0,"readableStreamLikeToAsyncGenerator");function O0(t){return At(t?.getReader)}o(O0,"isReadableStreamLike");function en(t){if(t instanceof Wt)return t;if(t!=null){if(M0(t))return M$(t);if(Nc(t))return T$(t);if(S0(t))return C$(t);if(T0(t))return q_(t);if(I0(t))return k$(t);if(O0(t))return I$(t)}throw C0(t)}o(en,"innerFrom");function M$(t){return new Wt(function(e){var r=t[Oc]();if(At(r.subscribe))return r.subscribe(e);throw new TypeError("Provided object does not correctly implement Symbol.observable")})}o(M$,"fromInteropObservable");function T$(t){return new Wt(function(e){for(var r=0;r<t.length&&!e.closed;r++)e.next(t[r]);e.complete()})}o(T$,"fromArrayLike");function C$(t){return new Wt(function(e){t.then(function(r){e.closed||(e.next(r),e.complete())},function(r){return e.error(r)}).then(null,x0)})}o(C$,"fromPromise");function k$(t){return new Wt(function(e){var r,n;try{for(var i=os(t),a=i.next();!a.done;a=i.next()){var c=a.value;if(e.next(c),e.closed)return}}catch(u){r={error:u}}finally{try{a&&!a.done&&(n=i.return)&&n.call(i)}finally{if(r)throw r.error}}e.complete()})}o(k$,"fromIterable");function q_(t){return new Wt(function(e){D$(t,e).catch(function(r){return e.error(r)})})}o(q_,"fromAsyncIterable");function I$(t){return q_(D0(t))}o(I$,"fromReadableStreamLike");function D$(t,e){var r,n,i,a;return __(this,void 0,void 0,function(){var c,u;return g0(this,function(m){switch(m.label){case 0:m.trys.push([0,5,6,11]),r=A_(t),m.label=1;case 1:return[4,r.next()];case 2:if(n=m.sent(),!!n.done)return[3,4];if(c=n.value,e.next(c),e.closed)return[2];m.label=3;case 3:return[3,1];case 4:return[3,11];case 5:return u=m.sent(),i={error:u},[3,11];case 6:return m.trys.push([6,,9,10]),n&&!n.done&&(a=r.return)?[4,a.call(r)]:[3,8];case 7:m.sent(),m.label=8;case 8:return[3,10];case 9:if(i)throw i.error;return[7];case 10:return[7];case 11:return e.complete(),[2]}})})}o(D$,"process");function Ai(t,e,r,n,i){n===void 0&&(n=0),i===void 0&&(i=!1);var a=e.schedule(function(){r(),i?t.add(this.schedule(null,n)):this.unsubscribe()},n);if(t.add(a),!i)return a}o(Ai,"executeSchedule");function R0(t,e){return e===void 0&&(e=0),Dr(function(r,n){r.subscribe(Or(n,function(i){return Ai(n,t,function(){return n.next(i)},e)},function(){return Ai(n,t,function(){return n.complete()},e)},function(i){return Ai(n,t,function(){return n.error(i)},e)}))})}o(R0,"observeOn");function N0(t,e){return e===void 0&&(e=0),Dr(function(r,n){n.add(t.schedule(function(){return r.subscribe(n)},e))})}o(N0,"subscribeOn");function H_(t,e){return en(t).pipe(N0(e),R0(e))}o(H_,"scheduleObservable");function z_(t,e){return en(t).pipe(N0(e),R0(e))}o(z_,"schedulePromise");function K_(t,e){return new Wt(function(r){var n=0;return e.schedule(function(){n===t.length?r.complete():(r.next(t[n++]),r.closed||this.schedule())})})}o(K_,"scheduleArray");function j_(t,e){return new Wt(function(r){var n;return Ai(r,e,function(){n=t[k0](),Ai(r,e,function(){var i,a,c;try{i=n.next(),a=i.value,c=i.done}catch(u){r.error(u);return}c?r.complete():r.next(a)},0,!0)}),function(){return At(n?.return)&&n.return()}})}o(j_,"scheduleIterable");function P0(t,e){if(!t)throw new Error("Iterable cannot be null");return new Wt(function(r){Ai(r,e,function(){var n=t[Symbol.asyncIterator]();Ai(r,e,function(){n.next().then(function(i){i.done?r.complete():r.next(i.value)})},0,!0)})})}o(P0,"scheduleAsyncIterable");function G_(t,e){return P0(D0(t),e)}o(G_,"scheduleReadableStreamLike");function V_(t,e){if(t!=null){if(M0(t))return H_(t,e);if(Nc(t))return K_(t,e);if(S0(t))return z_(t,e);if(T0(t))return P0(t,e);if(I0(t))return j_(t,e);if(O0(t))return G_(t,e)}throw C0(t)}o(V_,"scheduled");function W_(t,e){return e?V_(t,e):en(t)}o(W_,"from");var L0=kc(function(t){return o(function(){t(this),this.name="EmptyError",this.message="no elements in sequence"},"EmptyErrorImpl")});function J_(t){return t instanceof Date&&!isNaN(t)}o(J_,"isValidDate");function B0(t,e){return Dr(function(r,n){var i=0;r.subscribe(Or(n,function(a){n.next(t.call(e,a,i++))}))})}o(B0,"map");var O$=Array.isArray;function R$(t,e){return O$(e)?t.apply(void 0,Vi([],Kn(e))):t(e)}o(R$,"callOrApply");function Y_(t){return B0(function(e){return R$(t,e)})}o(Y_,"mapOneOrManyArgs");function X_(t,e,r,n,i,a,c,u){var m=[],v=0,x=0,S=!1,O=o(function(){S&&!m.length&&!v&&e.complete()},"checkComplete"),R=o(function(P){return v<n?D(P):m.push(P)},"outerNext"),D=o(function(P){a&&e.next(P),v++;var J=!1;en(r(P,x++)).subscribe(Or(e,function(L){i?.(L),a?R(L):e.next(L)},function(){J=!0},void 0,function(){if(J)try{v--;for(var L=o(function(){var W=m.shift();c?Ai(e,c,function(){return D(W)}):D(W)},"_loop_1");m.length&&v<n;)L();O()}catch(W){e.error(W)}}))},"doInnerSub");return t.subscribe(Or(e,R,function(){S=!0,O()})),function(){u?.()}}o(X_,"mergeInternals");function hl(t,e,r){return r===void 0&&(r=1/0),At(e)?hl(function(n,i){return B0(function(a,c){return e(n,a,i,c)})(en(t(n,i)))},r):(typeof e=="number"&&(r=e),Dr(function(n,i){return X_(n,i,t,r)}))}o(hl,"mergeMap");function Z_(t){return t===void 0&&(t=1/0),hl(Rc,t)}o(Z_,"mergeAll");var N$=["addListener","removeListener"],P$=["addEventListener","removeEventListener"],L$=["on","off"];function dl(t,e,r,n){if(At(r)&&(n=r,r=void 0),n)return dl(t,e,r).pipe(Y_(n));var i=Kn($$(t)?P$.map(function(u){return function(m){return t[u](e,m,r)}}):B$(t)?N$.map(Q_(t,e)):U$(t)?L$.map(Q_(t,e)):[],2),a=i[0],c=i[1];if(!a&&Nc(t))return hl(function(u){return dl(u,e,r)})(en(t));if(!a)throw new TypeError("Invalid event target");return new Wt(function(u){var m=o(function(){for(var v=[],x=0;x<arguments.length;x++)v[x]=arguments[x];return u.next(1<v.length?v:v[0])},"handler");return a(m),function(){return c(m)}})}o(dl,"fromEvent");function Q_(t,e){return function(r){return function(n){return t[r](e,n)}}}o(Q_,"toCommonHandlerRegistry");function B$(t){return At(t.addListener)&&At(t.removeListener)}o(B$,"isNodeStyleEventEmitter");function U$(t){return At(t.on)&&At(t.off)}o(U$,"isJQueryStyleEventEmitter");function $$(t){return At(t.addEventListener)&&At(t.removeEventListener)}o($$,"isEventTarget");function pl(t,e,r){t===void 0&&(t=0),r===void 0&&(r=B_);var n=-1;return e!=null&&(A0(e)?r=e:n=e),new Wt(function(i){var a=J_(t)?+t-r.now():t;a<0&&(a=0);var c=0;return r.schedule(function(){i.closed||(i.next(c++),0<=n?this.schedule(void 0,n):i.complete())},a)})}o(pl,"timer");function Mg(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var r=$_(t),n=F_(t,1/0),i=t;return i.length?i.length===1?en(i[0]):Z_(n)(W_(i,r)):E0}o(Mg,"merge");function eE(t,e){return Dr(function(r,n){var i=0;r.subscribe(Or(n,function(a){return t.call(e,a,i++)&&n.next(a)}))})}o(eE,"filter");function tE(t){return Dr(function(e,r){var n=!1;e.subscribe(Or(r,function(i){n=!0,r.next(i)},function(){n||r.next(t),r.complete()}))})}o(tE,"defaultIfEmpty");function rE(t){return t<=0?function(){return E0}:Dr(function(e,r){var n=0;e.subscribe(Or(r,function(i){++n<=t&&(r.next(i),t<=n&&r.complete())}))})}o(rE,"take");function nE(t){return t===void 0&&(t=F$),Dr(function(e,r){var n=!1;e.subscribe(Or(r,function(i){n=!0,r.next(i)},function(){return n?r.complete():r.error(t())}))})}o(nE,"throwIfEmpty");function F$(){return new L0}o(F$,"defaultErrorFactory");function Tg(t,e){var r=arguments.length>=2;return function(n){return n.pipe(t?eE(function(i,a){return t(i,a,n)}):Rc,rE(1),r?tE(e):nE(function(){return new L0}))}}o(Tg,"first");function Cg(t,e){return Dr(function(r,n){var i=e??{},a=i.leading,c=a===void 0?!0:a,u=i.trailing,m=u===void 0?!1:u,v=!1,x=null,S=null,O=!1,R=o(function(){S?.unsubscribe(),S=null,m&&(J(),O&&n.complete())},"endThrottling"),D=o(function(){S=null,O&&n.complete()},"cleanupThrottling"),P=o(function(L){return S=en(t(L)).subscribe(Or(n,R,D))},"startThrottle"),J=o(function(){if(v){v=!1;var L=x;x=null,n.next(L),!O&&P(L)}},"send");r.subscribe(Or(n,function(L){v=!0,x=L,!(S&&!S.closed)&&(c?J():P(L))},function(){O=!0,!(m&&v&&S&&!S.closed)&&n.complete()}))})}o(Cg,"throttle");var iE;(function(t){t[t.GENESIS=0]="GENESIS",t[t.PARTIAL=1]="PARTIAL",t[t.SIGNED=2]="SIGNED"})(iE||(iE={}));var ml;(function(t){t[t.NOT_REQUESTED=0]="NOT_REQUESTED",t[t.PENDING=1]="PENDING",t[t.PROCESSING=2]="PROCESSING",t[t.ANCHORED=3]="ANCHORED",t[t.FAILED=4]="FAILED"})(ml||(ml={}));var Ig;(function(t){t[t.GENESIS=0]="GENESIS",t[t.SIGNED=1]="SIGNED",t[t.ANCHOR=2]="ANCHOR"})(Ig||(Ig={}));var ss=class extends Wt{constructor(e,r){super(n=>{e.subscribe(n)}),this.state$=e,this._context=r}get id(){return new rt(this.state$.value.type,this.state$.value.log[0].cid)}get api(){return this._context.api}get content(){let{next:e,content:r}=this.state$.value;return(0,kg.default)(e?.content??r)}get tip(){return this.state$.value.log[this.state$.value.log.length-1].cid}get commitId(){return Pt.make(this.id,this.tip)}get allCommitIds(){return this.state$.value.log.map(({cid:e})=>Pt.make(this.id,e))}get anchorCommitIds(){return this.state$.value.log.filter(({type:e})=>e===Ig.ANCHOR).map(({cid:e})=>Pt.make(this.id,e))}get state(){return(0,kg.default)(this.state$.value)}async sync(e={}){e={sync:yr.PREFER_CACHE,...e};let r=await this.api.loadStream(this.id,e);this.state$.next(r.state)}async requestAnchor(){return this.api.requestAnchor(this.id)}};o(ss,"Stream");function Pc(){return t=>{}}o(Pc,"StreamStatic");var uE=Lt(aE(),1);function fE(t){let e=new AbortController;if(t.length===0)throw Error("Need abort signals to create a merged abort signal");return t.some(r=>r.aborted)?(e.abort(),e.signal):(Mg(...t.map(r=>dl(r,"abort"))).pipe(Tg()).subscribe(()=>{e.abort()}),e.signal)}o(fE,"mergeAbortSignals");var bl=class{constructor(e){let r=new AbortController;if(this.signal=r.signal,e<=0){r.abort();return}this._subscription=pl(e).subscribe(()=>{r.abort()})}clear(){this._subscription?.unsubscribe()}};o(bl,"TimedAbortSignal");async function cE(t,e){let r=new AbortController,n=o(()=>{r.abort()},"onAbort");return t.addEventListener("abort",n),t.aborted&&r.abort(),e(r.signal).finally(()=>{t.removeEventListener("abort",n)})}o(cE,"abortable");var q$=60*1e3*3;async function Hr(t,e={}){e.body&&Object.assign(e,{body:JSON.stringify(e.body),headers:{...e.headers,"Content-Type":"application/json"}});let r=e.timeout||q$,n=new bl(r),i=e.signal?fE([e.signal,n.signal]):n.signal,a=await cE(i,c=>(0,uE.default)(String(t),{...e,signal:c})).finally(()=>n.clear());if(!a.ok){let c=await a.text();throw new Error(`HTTP request to '${t}' failed with status '${a.statusText}': ${c}`)}return a.json()}o(Hr,"fetchJson");var gl=Lt(Ac(),1);Pi();function fs(t){let e=We.asCID(t);if(e)return e;if(typeof t=="string")return We.parse(t);if(t instanceof Uint8Array)return We.decode(t);throw new Error(`${t} cannot be converted to a CID`)}o(fs,"toCID");var lE=0,Xt=class{static streamIdFromState(e){return new rt(e.type,e.log[0].cid)}static serializeCommit(e){let r=(0,gl.default)(e);return Xt.isSignedCommitContainer(r)?(r.jws.link=r.jws.link.toString(),r.linkedBlock=kt(r.linkedBlock,"base64"),r.cacaoBlock&&(r.cacaoBlock=kt(r.cacaoBlock,"base64")),r):(Xt.isSignedCommit(e)&&(r.link=r.link.toString()),Xt.isAnchorCommit(e)&&(r.proof=r.proof.toString()),r.id&&(r.id=r.id.toString()),r.prev&&(r.prev=r.prev.toString()),e.header?.model&&(r.header.model=kt(e.header.model,"base64")),r)}static deserializeCommit(e){let r=(0,gl.default)(e);return Xt.isSignedCommitContainer(r)?(r.jws.link=fs(r.jws.link),r.linkedBlock=Ot(r.linkedBlock,"base64"),r.cacaoBlock&&(r.cacaoBlock=Ot(r.cacaoBlock,"base64")),r):(Xt.isSignedCommit(r)&&(r.link=fs(r.link)),Xt.isAnchorCommit(r)&&(r.proof=fs(r.proof)),r.id&&(r.id=fs(r.id)),r.prev&&(r.prev=fs(r.prev)),r.header?.model&&(r.header.model=Ot(r.header.model,"base64")),r)}static serializeState(e){let r=(0,gl.default)(e);return r.log=r.log.map(n=>({...n,cid:n.cid.toString()})),r.anchorStatus!=null&&(r.anchorStatus=ml[r.anchorStatus]),r.anchorProof!=null&&(r.anchorProof.txHash=r.anchorProof.txHash.toString(),r.anchorProof.root=r.anchorProof.root.toString()),e.metadata?.model&&(r.metadata.model=e.metadata.model.toString()),e.next?.metadata?.model&&(r.next.metadata.model=e.next.metadata.model.toString()),e.metadata?.unique&&e.type!=lE&&(r.metadata.unique=kt(r.metadata.unique,"base64")),r.doctype=En.nameByCode(r.type),r}static deserializeState(e){if(!e)return null;let r=(0,gl.default)(e);return r.doctype&&(r.type=En.codeByName(r.doctype),delete r.doctype),r.log=r.log.map(n=>({...n,cid:fs(n.cid)})),r.anchorProof&&(r.anchorProof.txHash=fs(r.anchorProof.txHash),r.anchorProof.root=fs(r.anchorProof.root)),r.anchorStatus&&(r.anchorStatus=ml[r.anchorStatus]),e.metadata?.model&&(r.metadata.model=rt.fromString(e.metadata.model)),e.next?.metadata?.model&&(r.next.metadata.model=rt.fromString(e.next.metadata.model)),e.metadata?.unique&&e.type!=lE&&(r.metadata.unique=Ot(e.metadata.unique,"base64")),r}static statesEqual(e,r){return JSON.stringify(Xt.serializeState(e))===JSON.stringify(Xt.serializeState(r))}static isStateSupersetOf(e,r){if(e.log.length<r.log.length)return!1;for(let n in r.log)if(!e.log[n].cid.equals(r.log[n].cid))return!1;return!(e.log.length===r.log.length&&e.anchorStatus!=r.anchorStatus)}static assertCommitLinksToState(e,r){let n=this.streamIdFromState(e);if(r.id&&!r.id.equals(e.log[0].cid))throw new Error(`Invalid genesis CID in commit for StreamID ${n.toString()}. Found: ${r.id}, expected ${e.log[0].cid}`);let i=e.log[e.log.length-1].cid;if(!r.prev.equals(i))throw new Error(`Commit doesn't properly point to previous commit in log. Expected ${i}, found 'prev' ${r.prev}`)}static async convertCommitToSignedCommitContainer(e,r){if(Xt.isSignedCommit(e)){let n=await r.block.get(e.link);return{jws:e,linkedBlock:n}}return e}static isSignedCommitContainer(e){return e&&e.jws!==void 0}static isSignedCommit(e){return e&&e.link!==void 0}static isAnchorCommit(e){return e&&e.proof!==void 0}static isSignedCommitData(e){return e&&e.envelope!==void 0}static isAnchorCommitData(e){return e&&e.proof!==void 0}};o(Xt,"StreamUtils");var vl=class extends Eg{next(e){let r=this.value;Xt.statesEqual(r,e)||super.next(e)}};o(vl,"StreamStateSubject");var H$=function(t,e,r,n){var i=arguments.length,a=i<3?e:n===null?n=Object.getOwnPropertyDescriptor(e,r):n,c;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")a=Reflect.decorate(t,e,r,n);else for(var u=t.length-1;u>=0;u--)(c=t[u])&&(a=(i<3?c(a):i>3?c(e,r,a):c(e,r))||a);return i>3&&a&&Object.defineProperty(e,r,a),a},jn,Dg={anchor:!0,publish:!0,pin:!0,sync:yr.PREFER_CACHE},z$={sync:yr.PREFER_CACHE},hE={anchor:!0,publish:!0,throwOnInvalidCommit:!0};function Og(t,e){if(typeof t?.schema=="string")try{Pt.fromString(t.schema)}catch{throw new Error("Schema must be a CommitID")}let r={controllers:t?.controllers,family:t?.family,schema:t?.schema?.toString(),tags:t?.tags};if(e)t?.deterministic||(r.unique=kt((0,mE.randomBytes)(12),"base64")),t?.forbidControllerChange&&(r.forbidControllerChange=!0);else{if(t?.deterministic!==void 0||t?.unique!==void 0)throw new Error("Cannot change 'deterministic' or 'unique' properties on existing Streams");if(t?.forbidControllerChange!==void 0)throw new Error("Cannot change 'forbidControllerChange' property on existing Streams")}return Object.keys(r).forEach(n=>r[n]===void 0&&delete r[n]),r}o(Og,"headerFromMetadata");async function dE(t){if(!t.did)throw new Error("No DID provided");return t.did.authenticated||(await t.did.authenticate(),t.loggerProvider&&t.loggerProvider.getDiagnosticsLogger().imp(`Now authenticated as DID ${t.did.id}`)),t.did}o(dE,"getAuthenticatedDID");async function Rg(){throw new Error("Historical stream commits cannot be modified. Load the stream without specifying a commit to make updates.")}o(Rg,"throwReadOnlyError");var Gn=jn=o(class extends ss{constructor(){super(...arguments),this._isReadOnly=!1}get content(){return super.content}get metadata(){let{next:e,metadata:r}=this.state$.value;return(0,pE.default)(e?.metadata??r)}get controllers(){return this.metadata.controllers}static async create(e,r,n,i={}){i={...Dg,...i},!n?.deterministic&&i.syncTimeoutSeconds==null&&(i.syncTimeoutSeconds=0);let a=i.asDID?{did:i.asDID}:e,c=await jn.makeGenesis(a,r,n);return e.createStreamFromGenesis(jn.STREAM_TYPE_ID,c,i)}static async createFromGenesis(e,r,n={}){n={...Dg,...n},r.header?.unique&&n.syncTimeoutSeconds==null&&(n.syncTimeoutSeconds=0);let i=r.data?await jn._signDagJWS(e,r):r;return e.createStreamFromGenesis(jn.STREAM_TYPE_ID,i,n)}static async deterministic(e,r,n={}){if(n={...Dg,...n},r={...r,deterministic:!0},r.family==null&&r.tags==null)throw new Error("Family and/or tags are required when creating a deterministic tile document");let i=await jn.makeGenesis(e,null,r);return e.createStreamFromGenesis(jn.STREAM_TYPE_ID,i,n)}static async load(e,r,n={}){n={...z$,...n};let i=fn.from(r);if(i.type!=jn.STREAM_TYPE_ID)throw new Error(`StreamID ${i.toString()} does not refer to a '${jn.STREAM_TYPE_NAME}' stream, but to a ${i.typeName}`);return e.loadStream(i,n)}async update(e,r,n={}){n={...hE,...n};let i=n.asDID?{did:n.asDID}:this.api,a=await this.makeCommit(i,e,r),c=await this.api.applyCommit(this.id,a,n);this.state$.next(c.state)}async patch(e,r={}){r={...hE,...r};let i={header:Og(this.metadata,!1),data:e,prev:this.tip,id:this.id.cid},a=await jn._signDagJWS(this.api,i),c=await this.api.applyCommit(this.id,a,r);this.state$.next(c.state)}makeReadOnly(){this.update=Rg,this.patch=Rg,this.sync=Rg,this._isReadOnly=!0}get isReadOnly(){return this._isReadOnly}async makeCommit(e,r,n){let i=await this._makeRawCommit(r,n);return jn._signDagJWS(e,i)}async _makeRawCommit(e,r){r||(r={});let n=Og(r,!1);if(e==null&&(e=this.content),n.controllers){if(n.controllers.length!==1)throw new Error("Exactly one controller must be specified");if(!n.controllers[0])throw new Error("Controller cannot be updated to an undefined value.")}let i=i0.compare(this.content,e),a=this.state.log[0];return{header:n,data:i,prev:this.tip,id:a.cid}}static async makeGenesis(e,r,n){if(n||(n={}),!n.controllers||n.controllers.length===0)if(e.did){let c=await dE(e);n.controllers=[c.hasParent?c.parent:c.id]}else throw new Error("No controllers specified");if(n.controllers?.length!==1)throw new Error("Exactly one controller must be specified");let i=Og(n,!0);if(n?.deterministic&&r)throw new Error("Initial content must be null when creating a deterministic Tile document");if(r==null){let c={header:i};return qa(c),c}let a={data:r,header:i};return jn._signDagJWS(e,a)}static async _signDagJWS(e,r){return(await dE(e)).createDagJWS(r)}},"TileDocument");Gn.STREAM_TYPE_NAME="tile";Gn.STREAM_TYPE_ID=0;Gn=jn=H$([Pc()],Gn);var _E=Lt(vE(),1);function Q$(t,e){if(e.has(t))throw new TypeError("Cannot initialize the same private elements twice on an object")}o(Q$,"_checkPrivateRedeclaration");function eF(t,e){return e.get?e.get.call(t):e.value}o(eF,"_classApplyDescriptorGet");function tF(t,e,r){if(e.set)e.set.call(t,r);else{if(!e.writable)throw new TypeError("attempted to set read only private field");e.value=r}}o(tF,"_classApplyDescriptorSet");function wE(t,e,r){if(!e.has(t))throw new TypeError("attempted to "+r+" private field on non-instance");return e.get(t)}o(wE,"_classExtractFieldDescriptor");function Bg(t,e){var r=wE(t,e,"get");return eF(t,r)}o(Bg,"_classPrivateFieldGet");function yE(t,e,r){Q$(t,e),e.set(t,r)}o(yE,"_classPrivateFieldInit");function xE(t,e,r){var n=wE(t,e,"set");return tF(t,n,r),r}o(xE,"_classPrivateFieldSet");function rF(t){return typeof t=="string"||Pt.isInstance(t)||rt.isInstance(t)?{streamId:t}:{streamId:t.streamId,genesis:t.genesis}}o(rF,"keyToQuery");function Ug(t){return typeof t=="string"?fn.from(t).toString():Pt.isInstance(t)||rt.isInstance(t)?t.toString():t.streamId.toString()}o(Ug,"keyToString");async function nF(t){let e=await Gn.makeGenesis({},null,{...t,deterministic:!0}),r=await rt.fromGenesis("tile",e);return{genesis:e,streamId:r}}o(nF,"getDeterministicQuery");var iF=o(()=>Promise.resolve([]),"tempBatchLoadFn"),$0=new WeakMap,$g=new WeakMap,yl=class extends _E.default{cache(e){if(!Bg(this,$g))return!1;let r=e.id.toString();return this.clear(r).prime(r,e),!0}async create(e,r,n){let i=await Gn.create(Bg(this,$0),e,r,n);return this.cache(i),i}async deterministic(e,r){let n=await nF(e);try{return await super.load(n)}catch{let a=await Gn.createFromGenesis(Bg(this,$0),n.genesis,r);return this.cache(a),a}}async load(e){return await super.load(e)}async update(e,r,n,i){let a=Ug(e);this.clear(a);let c=await this.load({streamId:a});return await c.update(r,n,i),c}constructor(e){super(iF,{cache:!0,cacheKeyFn:Ug,cacheMap:e.cache!=null&&typeof e.cache!="boolean"?e.cache:void 0}),yE(this,$0,{writable:!0,value:void 0}),yE(this,$g,{writable:!0,value:void 0}),this._batchLoadFn=async r=>{e.cache||this.clearAll();let n=await e.ceramic.multiQuery(r.map(rF),e.multiqueryTimeout);return r.map(i=>{let a=Ug(i),c=n[a];return c||new Error(`Failed to load stream: ${a}`)})},xE(this,$0,e.ceramic),xE(this,$g,!!e.cache)}};o(yl,"TileLoader");function Fg(t){return typeof t=="string"?rt.fromString(t):t}o(Fg,"typeStreamID");function EE(t,e){let r=new URL(t);for(let[n,i]of Object.entries(e))rt.isInstance(i)?r.searchParams.set(n,i.toString()):typeof i=="object"?r.searchParams.set(n,JSON.stringify(i)):r.searchParams.set(n,i);return r}o(EE,"serializeObjectToSearchParams");function qg(t){let e={};for(let[r,n]of Object.entries(t))rt.isInstance(n)?e[r]=n.toString():e[r]=n;return e}o(qg,"serializeObjectForHttpPost");var tn=class extends Wt{constructor(e,r,n){super(i=>{this.state$.observers.length===0&&(this.periodicSubscription=pl(0,n).pipe(Cg(()=>this._syncState(this.id,{sync:yr.PREFER_CACHE}))).subscribe()),this.state$.subscribe(i).add(()=>{this.state$.observers.length===0&&this.periodicSubscription?.unsubscribe()})}),this.state$=new vl(e),this._apiUrl=new URL(r)}get value(){return this.state$.value}get state(){return this.state$.value}next(e){this.state$.next(e)}async _syncState(e,r){let n=await tn._load(e,this._apiUrl,r);this.state$.next(Xt.deserializeState(n))}get id(){return new rt(this.state$.value.type,this.state$.value.log[0].cid)}static async createFromGenesis(e,r,n,i,a){let c=new URL("./streams",e),{state:u}=await Hr(c,{method:"post",body:{type:r,genesis:Xt.serializeCommit(n),opts:i}});return new tn(Xt.deserializeState(u),e,a)}static async applyCommit(e,r,n,i,a){let c=new URL("./commits",e),{state:u}=await Hr(c,{method:"post",body:{streamId:r.toString(),commit:Xt.serializeCommit(n),opts:i}});return new tn(Xt.deserializeState(u),e,a)}static async _load(e,r,n){let i=EE(new URL(`./streams/${e}`,r),n),{state:a}=await Hr(i);return a}static async load(e,r,n,i){let a=await tn._load(e,r,i);return new tn(Xt.deserializeState(a),r,n)}static async loadStreamCommits(e,r){let n=new URL(`./commits/${e}`,r),{commits:i}=await Hr(n);return i.map(a=>({cid:a.cid,value:Xt.deserializeCommit(a.value)}))}complete(){this.state$.complete()}};o(tn,"Document");var sf;(function(t){t[t.PREFER_CACHE=0]="PREFER_CACHE",t[t.SYNC_ALWAYS=1]="SYNC_ALWAYS",t[t.NEVER_SYNC=2]="NEVER_SYNC",t[t.SYNC_ON_ERROR=3]="SYNC_ON_ERROR"})(sf||(sf={}));var Hg=Lt(Ac(),1);var AE;(function(t){t[t.GENESIS=0]="GENESIS",t[t.PARTIAL=1]="PARTIAL",t[t.SIGNED=2]="SIGNED"})(AE||(AE={}));var zg;(function(t){t[t.GENESIS=0]="GENESIS",t[t.SIGNED=1]="SIGNED",t[t.ANCHOR=2]="ANCHOR"})(zg||(zg={}));var xl=class extends Wt{constructor(e,r){super(n=>{e.subscribe(n)}),this.state$=e,this._context=r}get id(){return new rt(this.state$.value.type,this.state$.value.log[0].cid)}get api(){return this._context.api}get content(){let{next:e,content:r}=this.state$.value;return(0,Hg.default)(e?.content??r)}get tip(){return this.state$.value.log[this.state$.value.log.length-1].cid}get commitId(){return Pt.make(this.id,this.tip)}get allCommitIds(){return this.state$.value.log.map(({cid:e})=>Pt.make(this.id,e))}get anchorCommitIds(){return this.state$.value.log.filter(({type:e})=>e===zg.ANCHOR).map(({cid:e})=>Pt.make(this.id,e))}get state(){return(0,Hg.default)(this.state$.value)}async sync(e={}){e={sync:sf.PREFER_CACHE,...e};let r=await this.api.loadStream(this.id,e);this.state$.next(r.state)}async requestAnchor(){return this.api.requestAnchor(this.id)}};o(xl,"Stream");function SE(){return t=>{}}o(SE,"StreamStatic");function ME(t){if(typeof t=="string"&&t.includes("@")){let[e,r]=t.split("@");if(!e||!r)throw new Error("Invalid accountId provided");return new zs({address:e,chainId:r})}return new zs(t)}o(ME,"normalizeAccountId");var oF="(?:%[0-9a-fA-F]{2})",TE=`(?:[a-zA-Z0-9._-]|${oF})`,sF="([a-z0-9]+)",aF=`((?:${TE}*:)*(${TE}+))`,CE="[a-zA-Z0-9_.:%-]",fF=`;${CE}+=${CE}*`,cF=`((${fF})*)`,uF="(/[^#?]*)?",lF="([?][^#]*)?",hF="(#.*)?",dF=new RegExp(`^did:${sF}:${aF}${cF}${uF}${lF}${hF}$`);function kE(t){if(t===""||!t)return null;let e=t.match(dF);if(e){let r={did:`did:${e[1]}:${e[2]}`,method:e[1],id:e[2],didUrl:t};if(e[4]){let n=e[4].slice(1).split(";");r.params={};for(let i of n){let a=i.split("=");r.params[a[0]]=a[1]}}return e[6]&&(r.path=e[6]),e[7]&&(r.query=e[7].slice(1)),e[8]&&(r.fragment=e[8].slice(1)),r}return null}o(kE,"parse");var DE=Lt(Ac(),1),pF=function(t,e,r,n){var i=arguments.length,a=i<3?e:n===null?n=Object.getOwnPropertyDescriptor(e,r):n,c;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")a=Reflect.decorate(t,e,r,n);else for(var u=t.length-1;u>=0;u--)(c=t[u])&&(a=(i<3?c(a):i>3?c(e,r,a):c(e,r))||a);return i>3&&a&&Object.defineProperty(e,r,a),a},af,Kg=o(()=>{throw new Error("Historical stream commits cannot be modified. Load the stream without specifying a commit to make updates.")},"throwReadOnlyError"),IE={anchor:!1,publish:!0,sync:sf.PREFER_CACHE},jg={anchor:!0,publish:!0},mF={sync:sf.PREFER_CACHE},ff=af=o(class extends xl{constructor(){super(...arguments),this._isReadOnly=!1}get did(){return this.content}get metadata(){let{next:e,metadata:r}=this.state$.value;return(0,DE.default)(e?.metadata??r)}get controllers(){return this.metadata.controllers}static async fromAccount(e,r,n={}){n={...IE,...n};let i=ME(r),a=af.makeGenesis(i);return af.fromGenesis(e,a,n)}static async fromGenesis(e,r,n={}){return n={...IE,...n},e.createStreamFromGenesis(af.STREAM_TYPE_ID,r,n)}async setDid(e,r,n={}){n={...jg,...n};let i=typeof e=="string"?e.trim():e.id;if(kE(i)?.did!==i)throw new Error(`DID is not valid: '${i}'`);let c=await r.createLink(i);return this.setDidProof(c,n)}async setDidProof(e,r={}){r={...jg,...r};let n=this.makeCommit(e),i=await this.api.applyCommit(this.id,n,r);this.state$.next(i.state)}async clearDid(e,r={}){r={...jg,...r};let n=await e.createLink("");return this.setDidProof(n,r)}static async load(e,r,n={}){n={...mF,...n};let i=fn.from(r);if(i.type!=af.STREAM_TYPE_ID)throw new Error(`StreamID ${i.toString()} does not refer to a '${af.STREAM_TYPE_NAME}' stream, but to a ${i.typeName}`);return e.loadStream(i,n)}static makeGenesis(e){return e.chainId.namespace==="eip155"&&(e.address=e.address.toLowerCase()),{header:{controllers:[`${e.address}@${e.chainId.toString()}`],family:`caip10-${e.chainId.toString()}`}}}makeCommit(e){return{data:e,prev:this.tip,id:this.id.cid}}makeReadOnly(){this.setDidProof=Kg,this.setDid=Kg,this.sync=Kg,this._isReadOnly=!0}get isReadOnly(){return this._isReadOnly}},"Caip10Link");ff.STREAM_TYPE_NAME="caip10-link";ff.STREAM_TYPE_ID=1;ff=af=pF([SE()],ff);Pi();Aa();var d9=Lt(l9(),1),fq=function(t,e,r,n){var i=arguments.length,a=i<3?e:n===null?n=Object.getOwnPropertyDescriptor(e,r):n,c;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")a=Reflect.decorate(t,e,r,n);else for(var u=t.length-1;u>=0;u--)(c=t[u])&&(a=(i<3?c(a):i>3?c(e,r,a):c(e,r))||a);return i>3&&a&&Object.defineProperty(e,r,a),a},yo,cq={sync:yr.PREFER_CACHE};async function h9(t){if(t.did==null)throw new Error("No DID provided");t.did.authenticated||(await t.did.authenticate(),t.loggerProvider&&t.loggerProvider.getDiagnosticsLogger().imp(`Now authenticated as DID ${t.did.id}`))}o(h9,"_ensureAuthenticated");async function uq(){throw new Error("Historical stream commits cannot be modified. Load the stream without specifying a commit to make updates.")}o(uq,"throwReadOnlyError");var Ys=yo=o(class extends ss{constructor(){super(...arguments),this._isReadOnly=!1}get content(){return super.content}get metadata(){return{controller:this.state$.value.metadata.controllers[0],model:yo.MODEL}}static async create(e,r,n){yo.assertComplete(r);let i={publish:!0,anchor:!0,pin:!0,sync:yr.NEVER_SYNC,throwOnInvalidCommit:!0},a=await yo._makeGenesis(e,r,n);return await e.createStreamFromGenesis(yo.STREAM_TYPE_ID,a,i)}static assertComplete(e,r){if(!e.name)throw r?new Error(`Model with StreamID ${r.toString()} is missing a 'name' field`):new Error("Model is missing a 'name' field");if(!e.schema)throw r?new Error(`Model ${e.name} (${r.toString()}) is missing a 'schema' field`):new Error(`Model ${e.name} is missing a 'schema' field`);if(!e.accountRelation)throw r?new Error(`Model ${e.name} (${r.toString()}) is missing a 'accountRelation' field`):new Error(`Model ${e.name} is missing a 'accountRelation' field`)}static async load(e,r,n={}){n={...cq,...n};let i=fn.from(r);if(i.type!=yo.STREAM_TYPE_ID)throw new Error(`StreamID ${i.toString()} does not refer to a '${yo.STREAM_TYPE_NAME}' stream, but to a ${i.typeName}`);return await e.loadStream(i,n)}static async _makeGenesis(e,r,n){let i=await this._makeRawGenesis(e,r,n);return yo._signDagJWS(e,i)}static async _makeRawGenesis(e,r,n){if(r==null)throw new Error("Genesis content cannot be null");if(!n||!n.controller)if(e.did)await h9(e),n={controller:e.did.hasParent?e.did.parent:e.did.id};else throw new Error("No controller specified");let i={controllers:[n.controller],model:yo.MODEL.bytes};return{data:r,header:i}}makeReadOnly(){this.sync=uq,this._isReadOnly=!0}get isReadOnly(){return this._isReadOnly}static async _signDagJWS(e,r){return await h9(e),e.did.createDagJWS(r)}},"Model");Ys.STREAM_TYPE_NAME="model";Ys.STREAM_TYPE_ID=2;Ys.MODEL=function(){let t=qa("model-v1"),e=d9.default.encode(t,"identity"),r=qo(fc,e),n=We.createV1(fc,r);return new rt("UNLOADABLE",n)}();Ys=yo=fq([Pc()],Ys);var b9=Lt(Oa(),1);var lq=function(t,e,r,n){var i=arguments.length,a=i<3?e:n===null?n=Object.getOwnPropertyDescriptor(e,r):n,c;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")a=Reflect.decorate(t,e,r,n);else for(var u=t.length-1;u>=0;u--)(c=t[u])&&(a=(i<3?c(a):i>3?c(e,r,a):c(e,r))||a);return i>3&&a&&Object.defineProperty(e,r,a),a},Ji,hq={anchor:!0,publish:!0,pin:!0,sync:yr.NEVER_SYNC,syncTimeoutSeconds:0},dq={anchor:!1,publish:!1,pin:!0,sync:yr.PREFER_CACHE},pq={sync:yr.PREFER_CACHE},p9={anchor:!0,publish:!0,throwOnInvalidCommit:!0};async function m9(t){if(t.did==null)throw new Error("No DID provided");t.did.authenticated||(await t.did.authenticate(),t.loggerProvider&&t.loggerProvider.getDiagnosticsLogger().imp(`Now authenticated as DID ${t.did.id}`))}o(m9,"_ensureAuthenticated");async function Wg(){throw new Error("Historical stream commits cannot be modified. Load the stream without specifying a commit to make updates.")}o(Wg,"throwReadOnlyError");var uf=Ji=o(class extends ss{constructor(){super(...arguments),this._isReadOnly=!1}get content(){return super.content}get metadata(){let e=this.state$.value.metadata;return{controller:e.controllers[0],model:e.model}}static async create(e,r,n,i={}){i={...hq,...i};let a=i.asDID?{did:i.asDID}:e,c=await Ji._makeGenesis(a,r,n);return e.createStreamFromGenesis(Ji.STREAM_TYPE_ID,c,i)}static async single(e,r,n={}){n={...dq,...n};let i=n.asDID?{did:n.asDID}:e;r={...r,deterministic:!0};let a=await Ji._makeGenesis(i,null,r);return e.createStreamFromGenesis(Ji.STREAM_TYPE_ID,a,n)}static async load(e,r,n={}){n={...pq,...n};let i=fn.from(r);if(i.type!=Ji.STREAM_TYPE_ID)throw new Error(`StreamID ${i.toString()} does not refer to a '${Ji.STREAM_TYPE_NAME}' stream, but to a ${i.typeName}`);return e.loadStream(i,n)}async replace(e,r={}){r={...p9,...r};let n=r.asDID?{did:r.asDID}:this.api,i=await this._makeCommit(n,e),a=await this.api.applyCommit(this.id,i,r);this.state$.next(a.state)}async patch(e,r={}){r={...p9,...r};let n={data:e,prev:this.tip,id:this.id.cid},i=await Ji._signDagJWS(this.api,n),a=await this.api.applyCommit(this.id,i,r);this.state$.next(a.state)}makeReadOnly(){this.replace=Wg,this.patch=Wg,this.sync=Wg,this._isReadOnly=!0}get isReadOnly(){return this._isReadOnly}_makeCommit(e,r){let n=this._makeRawCommit(r);return Ji._signDagJWS(e,n)}_makeRawCommit(e){return{data:i0.compare(this.content,e||{}),prev:this.tip,id:this.state.log[0].cid}}static async _makeGenesis(e,r,n){let i=await this._makeRawGenesis(e,r,n);return n.deterministic?(qa(i),i):Ji._signDagJWS(e,i)}static async _makeRawGenesis(e,r,n){if(!n.model)throw new Error("Must specify a 'model' when creating a ModelInstanceDocument");let i=n.controller;if(!i)if(e.did)await m9(e),i=e.did.hasParent?e.did.parent:e.did.id;else throw new Error("No controller specified");let a={controllers:[i],model:n.model.bytes};return n.deterministic||(a.unique=(0,b9.randomBytes)(12)),{data:r,header:a}}static async _signDagJWS(e,r){return await m9(e),e.did.createDagJWS(r)}},"ModelInstanceDocument");uf.STREAM_TYPE_NAME="MID";uf.STREAM_TYPE_ID=3;uf=Ji=lq([Pc()],uf);var El=class{constructor(e){this._apiUrl=e}async add(e,r){let n={};r&&(n.force=!0);let i=new URL(`./pins/${e}`,this._apiUrl);await Hr(i,{method:"post",body:n})}async rm(e,r){let n=new URL(`./pins/${e}`,this._apiUrl);await Hr(n,{method:"delete",body:{opts:r}})}async ls(e){let r=new URL("./pins",this._apiUrl);e&&(r=new URL(`./pins/${e.toString()}`,this._apiUrl));let n=await Hr(r),{pinnedStreamIds:i}=n;return{[Symbol.asyncIterator](){let a=0;return{next(){return a===i.length?Promise.resolve({value:null,done:!0}):Promise.resolve({value:i[a++],done:!1})}}}}}};o(El,"RemotePinApi");var Al=class{constructor(e){this._fetchJson=Hr,this._collectionURL=new URL("./collection",e),this._countURL=new URL("./collection/count",e)}async count(e){return(await this._fetchJson(this._countURL,{method:"POST",body:qg(e)})).count}async query(e){let r=await this._fetchJson(this._collectionURL,{method:"POST",body:qg(e)});return{edges:r.edges.map(i=>({cursor:i.cursor,node:Xt.deserializeState(i.node)})),pageInfo:r.pageInfo}}};o(Al,"RemoteIndexApi");var Sl=class{constructor(e,r){this._apiUrl=e,this._getDidFn=r,this._fetchJson=Hr,this.modelsPath="./admin/models",this.getCodePath="./admin/getCode"}getCodeUrl(){return new URL(this.getCodePath,this._apiUrl)}getModelsUrl(){return new URL(this.modelsPath,this._apiUrl)}async buildJWS(e,r,n){let i=n?{models:n.map(c=>c.toString())}:void 0,a=await e.createJWS({code:r,requestPath:this.getModelsUrl().pathname,requestBody:i});return`${a.signatures[0].protected}.${a.payload}.${a.signatures[0].signature}`}async generateCode(){return(await this._fetchJson(this.getCodeUrl())).code}async startIndexingModels(e){let r=await this.generateCode();await this._fetchJson(this.getModelsUrl(),{method:"post",body:{jws:await this.buildJWS(this._getDidFn(),r,e)}})}async getIndexedModels(){let e=await this.generateCode();return(await this._fetchJson(this.getModelsUrl(),{headers:{Authorization:`Basic ${await this.buildJWS(this._getDidFn(),e)}`}})).models.map(n=>rt.fromString(n))}async stopIndexingModels(e){let r=await this.generateCode();await this._fetchJson(this.getModelsUrl(),{method:"delete",body:{jws:await this.buildJWS(this._getDidFn(),r,e)}})}};o(Sl,"RemoteAdminApi");var mq="/api/v0/",bq="http://localhost:7007",gq={syncInterval:5e3},vq={anchor:!0,publish:!0,sync:yr.PREFER_CACHE},yq={anchor:!0,publish:!0,sync:yr.PREFER_CACHE},g9={sync:yr.PREFER_CACHE},Ml=class{constructor(e=bq,r={}){this._config={...gq,...r},this._apiUrl=new URL(mq,e),this._streamCache=new Map,this.context={api:this},this.pin=new El(this._apiUrl),this.index=new Al(this._apiUrl);let n=(()=>this.did).bind(this);this.admin=new Sl(this._apiUrl,n),this._streamConstructors={[ff.STREAM_TYPE_ID]:ff,[Ys.STREAM_TYPE_ID]:Ys,[uf.STREAM_TYPE_ID]:uf,[Gn.STREAM_TYPE_ID]:Gn}}get did(){return this.context.did}set did(e){this.context.did=e}async createStreamFromGenesis(e,r,n={}){n={...yq,...n};let i=await tn.createFromGenesis(this._apiUrl,e,r,n,this._config.syncInterval),a=this._streamCache.get(i.id.toString());return a?(Xt.statesEqual(i.state,a.state)||a.next(i.state),this.buildStreamFromDocument(a)):(this._streamCache.set(i.id.toString(),i),this.buildStreamFromDocument(i))}async loadStream(e,r={}){r={...g9,...r};let n=fn.from(e),i=this._streamCache.get(n.baseID.toString());return i?await i._syncState(n,r):(i=await tn.load(n,this._apiUrl,this._config.syncInterval,r),this._streamCache.set(i.id.toString(),i)),this.buildStreamFromDocument(i)}async multiQuery(e,r){let n=e.map(c=>({...c,streamId:typeof c.streamId=="string"?c.streamId:c.streamId.toString()})),i=new URL("./multiqueries",this._apiUrl),a=await Hr(i,{method:"post",body:{queries:n,timeout:r}});return Object.entries(a).reduce((c,u)=>{let[m,v]=u,x=Xt.deserializeState(v),S=new tn(x,this._apiUrl,this._config.syncInterval);return c[m]=this.buildStreamFromDocument(S),c},{})}loadStreamCommits(e){let r=Fg(e);return tn.loadStreamCommits(r,this._apiUrl)}async applyCommit(e,r,n={}){n={...vq,...n};let i=Fg(e),a=await tn.applyCommit(this._apiUrl,i,r,n,this._config.syncInterval),c=this._streamCache.get(i.toString());return c?(c.next(a.state),this.buildStreamFromDocument(a)):(this._streamCache.set(i.toString(),a),this.buildStreamFromDocument(a))}async requestAnchor(e,r={}){r={...g9,...r};let{anchorStatus:n}=await Hr(`${this._apiUrl}/streams/${e.toString()}/anchor`,{method:"post",body:{opts:r}});return n}addStreamHandler(e){this._streamConstructors[e.name]=e.stream_constructor}buildStreamFromState(e){let r=new tn(e,this._apiUrl,this._config.syncInterval);return this.buildStreamFromDocument(r)}buildStreamFromDocument(e){let r=e.state.type,n=this._streamConstructors[r];if(!n)throw new Error(`Failed to find constructor for stream ${r}`);return new n(e,this.context)}async setDID(e){this.context.did=e}async getSupportedChains(){if(this._supportedChains)return this._supportedChains;let{supportedChains:e}=await Hr(this._apiUrl+"/node/chains");return this._supportedChains=e,e}async close(){Array.from(this._streamCache).map(([,e])=>{e.complete()}),this._streamCache.clear()}};o(Ml,"CeramicClient");var Ut;(function(t){t.assertEqual=i=>i;function e(i){}o(e,"assertIs"),t.assertIs=e;function r(i){throw new Error}o(r,"assertNever"),t.assertNever=r,t.arrayToEnum=i=>{let a={};for(let c of i)a[c]=c;return a},t.getValidEnumValues=i=>{let a=t.objectKeys(i).filter(u=>typeof i[i[u]]!="number"),c={};for(let u of a)c[u]=i[u];return t.objectValues(c)},t.objectValues=i=>t.objectKeys(i).map(function(a){return i[a]}),t.objectKeys=typeof Object.keys=="function"?i=>Object.keys(i):i=>{let a=[];for(let c in i)Object.prototype.hasOwnProperty.call(i,c)&&a.push(c);return a},t.find=(i,a)=>{for(let c of i)if(a(c))return c},t.isInteger=typeof Number.isInteger=="function"?i=>Number.isInteger(i):i=>typeof i=="number"&&isFinite(i)&&Math.floor(i)===i;function n(i,a=" | "){return i.map(c=>typeof c=="string"?`'${c}'`:c).join(a)}o(n,"joinValues"),t.joinValues=n,t.jsonStringifyReplacer=(i,a)=>typeof a=="bigint"?a.toString():a})(Ut||(Ut={}));var Fe=Ut.arrayToEnum(["string","nan","number","integer","float","boolean","date","bigint","symbol","function","undefined","null","array","object","unknown","promise","void","never","map","set"]),Xs=o(t=>{switch(typeof t){case"undefined":return Fe.undefined;case"string":return Fe.string;case"number":return isNaN(t)?Fe.nan:Fe.number;case"boolean":return Fe.boolean;case"function":return Fe.function;case"bigint":return Fe.bigint;case"symbol":return Fe.symbol;case"object":return Array.isArray(t)?Fe.array:t===null?Fe.null:t.then&&typeof t.then=="function"&&t.catch&&typeof t.catch=="function"?Fe.promise:typeof Map<"u"&&t instanceof Map?Fe.map:typeof Set<"u"&&t instanceof Set?Fe.set:typeof Date<"u"&&t instanceof Date?Fe.date:Fe.object;default:return Fe.unknown}},"getParsedType"),Ne=Ut.arrayToEnum(["invalid_type","invalid_literal","custom","invalid_union","invalid_union_discriminator","invalid_enum_value","unrecognized_keys","invalid_arguments","invalid_return_type","invalid_date","invalid_string","too_small","too_big","invalid_intersection_types","not_multiple_of","not_finite"]),xq=o(t=>JSON.stringify(t,null,2).replace(/"([^"]+)":/g,"$1:"),"quotelessJson"),Si=class extends Error{constructor(e){super(),this.issues=[],this.addIssue=n=>{this.issues=[...this.issues,n]},this.addIssues=(n=[])=>{this.issues=[...this.issues,...n]};let r=new.target.prototype;Object.setPrototypeOf?Object.setPrototypeOf(this,r):this.__proto__=r,this.name="ZodError",this.issues=e}get errors(){return this.issues}format(e){let r=e||function(a){return a.message},n={_errors:[]},i=o(a=>{for(let c of a.issues)if(c.code==="invalid_union")c.unionErrors.map(i);else if(c.code==="invalid_return_type")i(c.returnTypeError);else if(c.code==="invalid_arguments")i(c.argumentsError);else if(c.path.length===0)n._errors.push(r(c));else{let u=n,m=0;for(;m<c.path.length;){let v=c.path[m];m===c.path.length-1?(u[v]=u[v]||{_errors:[]},u[v]._errors.push(r(c))):u[v]=u[v]||{_errors:[]},u=u[v],m++}}},"processError");return i(this),n}toString(){return this.message}get message(){return JSON.stringify(this.issues,Ut.jsonStringifyReplacer,2)}get isEmpty(){return this.issues.length===0}flatten(e=r=>r.message){let r={},n=[];for(let i of this.issues)i.path.length>0?(r[i.path[0]]=r[i.path[0]]||[],r[i.path[0]].push(e(i))):n.push(e(i));return{formErrors:n,fieldErrors:r}}get formErrors(){return this.flatten()}};o(Si,"ZodError");Si.create=t=>new Si(t);var Cl=o((t,e)=>{let r;switch(t.code){case Ne.invalid_type:t.received===Fe.undefined?r="Required":r=`Expected ${t.expected}, received ${t.received}`;break;case Ne.invalid_literal:r=`Invalid literal value, expected ${JSON.stringify(t.expected,Ut.jsonStringifyReplacer)}`;break;case Ne.unrecognized_keys:r=`Unrecognized key(s) in object: ${Ut.joinValues(t.keys,", ")}`;break;case Ne.invalid_union:r="Invalid input";break;case Ne.invalid_union_discriminator:r=`Invalid discriminator value. Expected ${Ut.joinValues(t.options)}`;break;case Ne.invalid_enum_value:r=`Invalid enum value. Expected ${Ut.joinValues(t.options)}, received '${t.received}'`;break;case Ne.invalid_arguments:r="Invalid function arguments";break;case Ne.invalid_return_type:r="Invalid function return type";break;case Ne.invalid_date:r="Invalid date";break;case Ne.invalid_string:typeof t.validation=="object"?"startsWith"in t.validation?r=`Invalid input: must start with "${t.validation.startsWith}"`:"endsWith"in t.validation?r=`Invalid input: must end with "${t.validation.endsWith}"`:Ut.assertNever(t.validation):t.validation!=="regex"?r=`Invalid ${t.validation}`:r="Invalid";break;case Ne.too_small:t.type==="array"?r=`Array must contain ${t.exact?"exactly":t.inclusive?"at least":"more than"} ${t.minimum} element(s)`:t.type==="string"?r=`String must contain ${t.exact?"exactly":t.inclusive?"at least":"over"} ${t.minimum} character(s)`:t.type==="number"?r=`Number must be ${t.exact?"exactly equal to ":t.inclusive?"greater than or equal to ":"greater than "}${t.minimum}`:t.type==="date"?r=`Date must be ${t.exact?"exactly equal to ":t.inclusive?"greater than or equal to ":"greater than "}${new Date(t.minimum)}`:r="Invalid input";break;case Ne.too_big:t.type==="array"?r=`Array must contain ${t.exact?"exactly":t.inclusive?"at most":"less than"} ${t.maximum} element(s)`:t.type==="string"?r=`String must contain ${t.exact?"exactly":t.inclusive?"at most":"under"} ${t.maximum} character(s)`:t.type==="number"?r=`Number must be ${t.exact?"exactly":t.inclusive?"less than or equal to":"less than"} ${t.maximum}`:t.type==="date"?r=`Date must be ${t.exact?"exactly":t.inclusive?"smaller than or equal to":"smaller than"} ${new Date(t.maximum)}`:r="Invalid input";break;case Ne.custom:r="Invalid input";break;case Ne.invalid_intersection_types:r="Intersection results could not be merged";break;case Ne.not_multiple_of:r=`Number must be a multiple of ${t.multipleOf}`;break;case Ne.not_finite:r="Number must be finite";break;default:r=e.defaultError,Ut.assertNever(t)}return{message:r}},"errorMap"),w9=Cl;function wq(t){w9=t}o(wq,"setErrorMap");function j0(){return w9}o(j0,"getErrorMap");var G0=o(t=>{let{data:e,path:r,errorMaps:n,issueData:i}=t,a=[...r,...i.path||[]],c={...i,path:a},u="",m=n.filter(v=>!!v).slice().reverse();for(let v of m)u=v(c,{data:e,defaultError:u}).message;return{...i,path:a,message:i.message||u}},"makeIssue"),_q=[];function Ke(t,e){let r=G0({issueData:e,data:t.data,path:t.path,errorMaps:[t.common.contextualErrorMap,t.schemaErrorMap,j0(),Cl].filter(n=>!!n)});t.common.issues.push(r)}o(Ke,"addIssueToContext");var Rr=class{constructor(){this.value="valid"}dirty(){this.value==="valid"&&(this.value="dirty")}abort(){this.value!=="aborted"&&(this.value="aborted")}static mergeArray(e,r){let n=[];for(let i of r){if(i.status==="aborted")return gt;i.status==="dirty"&&e.dirty(),n.push(i.value)}return{status:e.value,value:n}}static async mergeObjectAsync(e,r){let n=[];for(let i of r)n.push({key:await i.key,value:await i.value});return Rr.mergeObjectSync(e,n)}static mergeObjectSync(e,r){let n={};for(let i of r){let{key:a,value:c}=i;if(a.status==="aborted"||c.status==="aborted")return gt;a.status==="dirty"&&e.dirty(),c.status==="dirty"&&e.dirty(),(typeof c.value<"u"||i.alwaysSet)&&(n[a.value]=c.value)}return{status:e.value,value:n}}};o(Rr,"ParseStatus");var gt=Object.freeze({status:"aborted"}),_9=o(t=>({status:"dirty",value:t}),"DIRTY"),rn=o(t=>({status:"valid",value:t}),"OK"),Jg=o(t=>t.status==="aborted","isAborted"),Yg=o(t=>t.status==="dirty","isDirty"),V0=o(t=>t.status==="valid","isValid"),W0=o(t=>typeof Promise!==void 0&&t instanceof Promise,"isAsync"),Rt;(function(t){t.errToObj=e=>typeof e=="string"?{message:e}:e||{},t.toString=e=>typeof e=="string"?e:e?.message})(Rt||(Rt={}));var Vn=class{constructor(e,r,n,i){this.parent=e,this.data=r,this._path=n,this._key=i}get path(){return this._path.concat(this._key)}};o(Vn,"ParseInputLazyPath");var v9=o((t,e)=>{if(V0(e))return{success:!0,data:e.value};{if(!t.common.issues.length)throw new Error("Validation failed but no issues detected.");let r=new Si(t.common.issues);return{success:!1,error:r}}},"handleResult");function Tt(t){if(!t)return{};let{errorMap:e,invalid_type_error:r,required_error:n,description:i}=t;if(e&&(r||n))throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);return e?{errorMap:e,description:i}:{errorMap:o((c,u)=>c.code!=="invalid_type"?{message:u.defaultError}:typeof u.data>"u"?{message:n??u.defaultError}:{message:r??u.defaultError},"customMap"),description:i}}o(Tt,"processCreateParams");var xt=class{constructor(e){this.spa=this.safeParseAsync,this._def=e,this.parse=this.parse.bind(this),this.safeParse=this.safeParse.bind(this),this.parseAsync=this.parseAsync.bind(this),this.safeParseAsync=this.safeParseAsync.bind(this),this.spa=this.spa.bind(this),this.refine=this.refine.bind(this),this.refinement=this.refinement.bind(this),this.superRefine=this.superRefine.bind(this),this.optional=this.optional.bind(this),this.nullable=this.nullable.bind(this),this.nullish=this.nullish.bind(this),this.array=this.array.bind(this),this.promise=this.promise.bind(this),this.or=this.or.bind(this),this.and=this.and.bind(this),this.transform=this.transform.bind(this),this.brand=this.brand.bind(this),this.default=this.default.bind(this),this.catch=this.catch.bind(this),this.describe=this.describe.bind(this),this.pipe=this.pipe.bind(this),this.isNullable=this.isNullable.bind(this),this.isOptional=this.isOptional.bind(this)}get description(){return this._def.description}_getType(e){return Xs(e.data)}_getOrReturnCtx(e,r){return r||{common:e.parent.common,data:e.data,parsedType:Xs(e.data),schemaErrorMap:this._def.errorMap,path:e.path,parent:e.parent}}_processInputParams(e){return{status:new Rr,ctx:{common:e.parent.common,data:e.data,parsedType:Xs(e.data),schemaErrorMap:this._def.errorMap,path:e.path,parent:e.parent}}}_parseSync(e){let r=this._parse(e);if(W0(r))throw new Error("Synchronous parse encountered promise.");return r}_parseAsync(e){let r=this._parse(e);return Promise.resolve(r)}parse(e,r){let n=this.safeParse(e,r);if(n.success)return n.data;throw n.error}safeParse(e,r){var n;let i={common:{issues:[],async:(n=r?.async)!==null&&n!==void 0?n:!1,contextualErrorMap:r?.errorMap},path:r?.path||[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:Xs(e)},a=this._parseSync({data:e,path:i.path,parent:i});return v9(i,a)}async parseAsync(e,r){let n=await this.safeParseAsync(e,r);if(n.success)return n.data;throw n.error}async safeParseAsync(e,r){let n={common:{issues:[],contextualErrorMap:r?.errorMap,async:!0},path:r?.path||[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:Xs(e)},i=this._parse({data:e,path:n.path,parent:n}),a=await(W0(i)?i:Promise.resolve(i));return v9(n,a)}refine(e,r){let n=o(i=>typeof r=="string"||typeof r>"u"?{message:r}:typeof r=="function"?r(i):r,"getIssueProperties");return this._refinement((i,a)=>{let c=e(i),u=o(()=>a.addIssue({code:Ne.custom,...n(i)}),"setError");return typeof Promise<"u"&&c instanceof Promise?c.then(m=>m?!0:(u(),!1)):c?!0:(u(),!1)})}refinement(e,r){return this._refinement((n,i)=>e(n)?!0:(i.addIssue(typeof r=="function"?r(n,i):r),!1))}_refinement(e){return new Mn({schema:this,typeName:pt.ZodEffects,effect:{type:"refinement",refinement:e}})}superRefine(e){return this._refinement(e)}optional(){return Jn.create(this)}nullable(){return Eo.create(this)}nullish(){return this.optional().nullable()}array(){return Sn.create(this)}promise(){return hs.create(this)}or(e){return ra.create([this,e])}and(e){return na.create(this,e)}transform(e){return new Mn({schema:this,typeName:pt.ZodEffects,effect:{type:"transform",transform:e}})}default(e){let r=typeof e=="function"?e:()=>e;return new ca({innerType:this,defaultValue:r,typeName:pt.ZodDefault})}brand(){return new Tl({typeName:pt.ZodBranded,type:this,...Tt(void 0)})}catch(e){let r=typeof e=="function"?e:()=>e;return new mf({innerType:this,defaultValue:r,typeName:pt.ZodCatch})}describe(e){let r=this.constructor;return new r({...this._def,description:e})}pipe(e){return ua.create(this,e)}isOptional(){return this.safeParse(void 0).success}isNullable(){return this.safeParse(null).success}};o(xt,"ZodType");var Eq=/^c[^\s-]{8,}$/i,Aq=/^([a-f0-9]{8}-[a-f0-9]{4}-[1-5][a-f0-9]{3}-[a-f0-9]{4}-[a-f0-9]{12}|00000000-0000-0000-0000-000000000000)$/i,Sq=/^(([^<>()[\]\.,;:\s@\"]+(\.[^<>()[\]\.,;:\s@\"]+)*)|(\".+\"))@(([^<>()[\]\.,;:\s@\"]+\.)+[^<>()[\]\.,;:\s@\"]{2,})$/i,Mq=o(t=>t.precision?t.offset?new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d{${t.precision}}(([+-]\\d{2}:\\d{2})|Z)$`):new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d{${t.precision}}Z$`):t.precision===0?t.offset?new RegExp("^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(([+-]\\d{2}:\\d{2})|Z)$"):new RegExp("^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}Z$"):t.offset?new RegExp("^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?(([+-]\\d{2}:\\d{2})|Z)$"):new RegExp("^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?Z$"),"datetimeRegex"),Mi=class extends xt{constructor(){super(...arguments),this._regex=(e,r,n)=>this.refinement(i=>e.test(i),{validation:r,code:Ne.invalid_string,...Rt.errToObj(n)}),this.nonempty=e=>this.min(1,Rt.errToObj(e)),this.trim=()=>new Mi({...this._def,checks:[...this._def.checks,{kind:"trim"}]})}_parse(e){if(this._def.coerce&&(e.data=String(e.data)),this._getType(e)!==Fe.string){let a=this._getOrReturnCtx(e);return Ke(a,{code:Ne.invalid_type,expected:Fe.string,received:a.parsedType}),gt}let n=new Rr,i;for(let a of this._def.checks)if(a.kind==="min")e.data.length<a.value&&(i=this._getOrReturnCtx(e,i),Ke(i,{code:Ne.too_small,minimum:a.value,type:"string",inclusive:!0,exact:!1,message:a.message}),n.dirty());else if(a.kind==="max")e.data.length>a.value&&(i=this._getOrReturnCtx(e,i),Ke(i,{code:Ne.too_big,maximum:a.value,type:"string",inclusive:!0,exact:!1,message:a.message}),n.dirty());else if(a.kind==="length"){let c=e.data.length>a.value,u=e.data.length<a.value;(c||u)&&(i=this._getOrReturnCtx(e,i),c?Ke(i,{code:Ne.too_big,maximum:a.value,type:"string",inclusive:!0,exact:!0,message:a.message}):u&&Ke(i,{code:Ne.too_small,minimum:a.value,type:"string",inclusive:!0,exact:!0,message:a.message}),n.dirty())}else if(a.kind==="email")Sq.test(e.data)||(i=this._getOrReturnCtx(e,i),Ke(i,{validation:"email",code:Ne.invalid_string,message:a.message}),n.dirty());else if(a.kind==="uuid")Aq.test(e.data)||(i=this._getOrReturnCtx(e,i),Ke(i,{validation:"uuid",code:Ne.invalid_string,message:a.message}),n.dirty());else if(a.kind==="cuid")Eq.test(e.data)||(i=this._getOrReturnCtx(e,i),Ke(i,{validation:"cuid",code:Ne.invalid_string,message:a.message}),n.dirty());else if(a.kind==="url")try{new URL(e.data)}catch{i=this._getOrReturnCtx(e,i),Ke(i,{validation:"url",code:Ne.invalid_string,message:a.message}),n.dirty()}else a.kind==="regex"?(a.regex.lastIndex=0,a.regex.test(e.data)||(i=this._getOrReturnCtx(e,i),Ke(i,{validation:"regex",code:Ne.invalid_string,message:a.message}),n.dirty())):a.kind==="trim"?e.data=e.data.trim():a.kind==="startsWith"?e.data.startsWith(a.value)||(i=this._getOrReturnCtx(e,i),Ke(i,{code:Ne.invalid_string,validation:{startsWith:a.value},message:a.message}),n.dirty()):a.kind==="endsWith"?e.data.endsWith(a.value)||(i=this._getOrReturnCtx(e,i),Ke(i,{code:Ne.invalid_string,validation:{endsWith:a.value},message:a.message}),n.dirty()):a.kind==="datetime"?Mq(a).test(e.data)||(i=this._getOrReturnCtx(e,i),Ke(i,{code:Ne.invalid_string,validation:"datetime",message:a.message}),n.dirty()):Ut.assertNever(a);return{status:n.value,value:e.data}}_addCheck(e){return new Mi({...this._def,checks:[...this._def.checks,e]})}email(e){return this._addCheck({kind:"email",...Rt.errToObj(e)})}url(e){return this._addCheck({kind:"url",...Rt.errToObj(e)})}uuid(e){return this._addCheck({kind:"uuid",...Rt.errToObj(e)})}cuid(e){return this._addCheck({kind:"cuid",...Rt.errToObj(e)})}datetime(e){var r;return typeof e=="string"?this._addCheck({kind:"datetime",precision:null,offset:!1,message:e}):this._addCheck({kind:"datetime",precision:typeof e?.precision>"u"?null:e?.precision,offset:(r=e?.offset)!==null&&r!==void 0?r:!1,...Rt.errToObj(e?.message)})}regex(e,r){return this._addCheck({kind:"regex",regex:e,...Rt.errToObj(r)})}startsWith(e,r){return this._addCheck({kind:"startsWith",value:e,...Rt.errToObj(r)})}endsWith(e,r){return this._addCheck({kind:"endsWith",value:e,...Rt.errToObj(r)})}min(e,r){return this._addCheck({kind:"min",value:e,...Rt.errToObj(r)})}max(e,r){return this._addCheck({kind:"max",value:e,...Rt.errToObj(r)})}length(e,r){return this._addCheck({kind:"length",value:e,...Rt.errToObj(r)})}get isDatetime(){return!!this._def.checks.find(e=>e.kind==="datetime")}get isEmail(){return!!this._def.checks.find(e=>e.kind==="email")}get isURL(){return!!this._def.checks.find(e=>e.kind==="url")}get isUUID(){return!!this._def.checks.find(e=>e.kind==="uuid")}get isCUID(){return!!this._def.checks.find(e=>e.kind==="cuid")}get minLength(){let e=null;for(let r of this._def.checks)r.kind==="min"&&(e===null||r.value>e)&&(e=r.value);return e}get maxLength(){let e=null;for(let r of this._def.checks)r.kind==="max"&&(e===null||r.value<e)&&(e=r.value);return e}};o(Mi,"ZodString");Mi.create=t=>{var e;return new Mi({checks:[],typeName:pt.ZodString,coerce:(e=t?.coerce)!==null&&e!==void 0?e:!1,...Tt(t)})};function Tq(t,e){let r=(t.toString().split(".")[1]||"").length,n=(e.toString().split(".")[1]||"").length,i=r>n?r:n,a=parseInt(t.toFixed(i).replace(".","")),c=parseInt(e.toFixed(i).replace(".",""));return a%c/Math.pow(10,i)}o(Tq,"floatSafeRemainder");var Yi=class extends xt{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte,this.step=this.multipleOf}_parse(e){if(this._def.coerce&&(e.data=Number(e.data)),this._getType(e)!==Fe.number){let a=this._getOrReturnCtx(e);return Ke(a,{code:Ne.invalid_type,expected:Fe.number,received:a.parsedType}),gt}let n,i=new Rr;for(let a of this._def.checks)a.kind==="int"?Ut.isInteger(e.data)||(n=this._getOrReturnCtx(e,n),Ke(n,{code:Ne.invalid_type,expected:"integer",received:"float",message:a.message}),i.dirty()):a.kind==="min"?(a.inclusive?e.data<a.value:e.data<=a.value)&&(n=this._getOrReturnCtx(e,n),Ke(n,{code:Ne.too_small,minimum:a.value,type:"number",inclusive:a.inclusive,exact:!1,message:a.message}),i.dirty()):a.kind==="max"?(a.inclusive?e.data>a.value:e.data>=a.value)&&(n=this._getOrReturnCtx(e,n),Ke(n,{code:Ne.too_big,maximum:a.value,type:"number",inclusive:a.inclusive,exact:!1,message:a.message}),i.dirty()):a.kind==="multipleOf"?Tq(e.data,a.value)!==0&&(n=this._getOrReturnCtx(e,n),Ke(n,{code:Ne.not_multiple_of,multipleOf:a.value,message:a.message}),i.dirty()):a.kind==="finite"?Number.isFinite(e.data)||(n=this._getOrReturnCtx(e,n),Ke(n,{code:Ne.not_finite,message:a.message}),i.dirty()):Ut.assertNever(a);return{status:i.value,value:e.data}}gte(e,r){return this.setLimit("min",e,!0,Rt.toString(r))}gt(e,r){return this.setLimit("min",e,!1,Rt.toString(r))}lte(e,r){return this.setLimit("max",e,!0,Rt.toString(r))}lt(e,r){return this.setLimit("max",e,!1,Rt.toString(r))}setLimit(e,r,n,i){return new Yi({...this._def,checks:[...this._def.checks,{kind:e,value:r,inclusive:n,message:Rt.toString(i)}]})}_addCheck(e){return new Yi({...this._def,checks:[...this._def.checks,e]})}int(e){return this._addCheck({kind:"int",message:Rt.toString(e)})}positive(e){return this._addCheck({kind:"min",value:0,inclusive:!1,message:Rt.toString(e)})}negative(e){return this._addCheck({kind:"max",value:0,inclusive:!1,message:Rt.toString(e)})}nonpositive(e){return this._addCheck({kind:"max",value:0,inclusive:!0,message:Rt.toString(e)})}nonnegative(e){return this._addCheck({kind:"min",value:0,inclusive:!0,message:Rt.toString(e)})}multipleOf(e,r){return this._addCheck({kind:"multipleOf",value:e,message:Rt.toString(r)})}finite(e){return this._addCheck({kind:"finite",message:Rt.toString(e)})}get minValue(){let e=null;for(let r of this._def.checks)r.kind==="min"&&(e===null||r.value>e)&&(e=r.value);return e}get maxValue(){let e=null;for(let r of this._def.checks)r.kind==="max"&&(e===null||r.value<e)&&(e=r.value);return e}get isInt(){return!!this._def.checks.find(e=>e.kind==="int")}};o(Yi,"ZodNumber");Yi.create=t=>new Yi({checks:[],typeName:pt.ZodNumber,coerce:t?.coerce||!1,...Tt(t)});var Zs=class extends xt{_parse(e){if(this._def.coerce&&(e.data=BigInt(e.data)),this._getType(e)!==Fe.bigint){let n=this._getOrReturnCtx(e);return Ke(n,{code:Ne.invalid_type,expected:Fe.bigint,received:n.parsedType}),gt}return rn(e.data)}};o(Zs,"ZodBigInt");Zs.create=t=>{var e;return new Zs({typeName:pt.ZodBigInt,coerce:(e=t?.coerce)!==null&&e!==void 0?e:!1,...Tt(t)})};var Qs=class extends xt{_parse(e){if(this._def.coerce&&(e.data=Boolean(e.data)),this._getType(e)!==Fe.boolean){let n=this._getOrReturnCtx(e);return Ke(n,{code:Ne.invalid_type,expected:Fe.boolean,received:n.parsedType}),gt}return rn(e.data)}};o(Qs,"ZodBoolean");Qs.create=t=>new Qs({typeName:pt.ZodBoolean,coerce:t?.coerce||!1,...Tt(t)});var xo=class extends xt{_parse(e){if(this._def.coerce&&(e.data=new Date(e.data)),this._getType(e)!==Fe.date){let a=this._getOrReturnCtx(e);return Ke(a,{code:Ne.invalid_type,expected:Fe.date,received:a.parsedType}),gt}if(isNaN(e.data.getTime())){let a=this._getOrReturnCtx(e);return Ke(a,{code:Ne.invalid_date}),gt}let n=new Rr,i;for(let a of this._def.checks)a.kind==="min"?e.data.getTime()<a.value&&(i=this._getOrReturnCtx(e,i),Ke(i,{code:Ne.too_small,message:a.message,inclusive:!0,exact:!1,minimum:a.value,type:"date"}),n.dirty()):a.kind==="max"?e.data.getTime()>a.value&&(i=this._getOrReturnCtx(e,i),Ke(i,{code:Ne.too_big,message:a.message,inclusive:!0,exact:!1,maximum:a.value,type:"date"}),n.dirty()):Ut.assertNever(a);return{status:n.value,value:new Date(e.data.getTime())}}_addCheck(e){return new xo({...this._def,checks:[...this._def.checks,e]})}min(e,r){return this._addCheck({kind:"min",value:e.getTime(),message:Rt.toString(r)})}max(e,r){return this._addCheck({kind:"max",value:e.getTime(),message:Rt.toString(r)})}get minDate(){let e=null;for(let r of this._def.checks)r.kind==="min"&&(e===null||r.value>e)&&(e=r.value);return e!=null?new Date(e):null}get maxDate(){let e=null;for(let r of this._def.checks)r.kind==="max"&&(e===null||r.value<e)&&(e=r.value);return e!=null?new Date(e):null}};o(xo,"ZodDate");xo.create=t=>new xo({checks:[],coerce:t?.coerce||!1,typeName:pt.ZodDate,...Tt(t)});var lf=class extends xt{_parse(e){if(this._getType(e)!==Fe.symbol){let n=this._getOrReturnCtx(e);return Ke(n,{code:Ne.invalid_type,expected:Fe.symbol,received:n.parsedType}),gt}return rn(e.data)}};o(lf,"ZodSymbol");lf.create=t=>new lf({typeName:pt.ZodSymbol,...Tt(t)});var ea=class extends xt{_parse(e){if(this._getType(e)!==Fe.undefined){let n=this._getOrReturnCtx(e);return Ke(n,{code:Ne.invalid_type,expected:Fe.undefined,received:n.parsedType}),gt}return rn(e.data)}};o(ea,"ZodUndefined");ea.create=t=>new ea({typeName:pt.ZodUndefined,...Tt(t)});var ta=class extends xt{_parse(e){if(this._getType(e)!==Fe.null){let n=this._getOrReturnCtx(e);return Ke(n,{code:Ne.invalid_type,expected:Fe.null,received:n.parsedType}),gt}return rn(e.data)}};o(ta,"ZodNull");ta.create=t=>new ta({typeName:pt.ZodNull,...Tt(t)});var us=class extends xt{constructor(){super(...arguments),this._any=!0}_parse(e){return rn(e.data)}};o(us,"ZodAny");us.create=t=>new us({typeName:pt.ZodAny,...Tt(t)});var wo=class extends xt{constructor(){super(...arguments),this._unknown=!0}_parse(e){return rn(e.data)}};o(wo,"ZodUnknown");wo.create=t=>new wo({typeName:pt.ZodUnknown,...Tt(t)});var Ti=class extends xt{_parse(e){let r=this._getOrReturnCtx(e);return Ke(r,{code:Ne.invalid_type,expected:Fe.never,received:r.parsedType}),gt}};o(Ti,"ZodNever");Ti.create=t=>new Ti({typeName:pt.ZodNever,...Tt(t)});var hf=class extends xt{_parse(e){if(this._getType(e)!==Fe.undefined){let n=this._getOrReturnCtx(e);return Ke(n,{code:Ne.invalid_type,expected:Fe.void,received:n.parsedType}),gt}return rn(e.data)}};o(hf,"ZodVoid");hf.create=t=>new hf({typeName:pt.ZodVoid,...Tt(t)});var Sn=class extends xt{_parse(e){let{ctx:r,status:n}=this._processInputParams(e),i=this._def;if(r.parsedType!==Fe.array)return Ke(r,{code:Ne.invalid_type,expected:Fe.array,received:r.parsedType}),gt;if(i.exactLength!==null){let c=r.data.length>i.exactLength.value,u=r.data.length<i.exactLength.value;(c||u)&&(Ke(r,{code:c?Ne.too_big:Ne.too_small,minimum:u?i.exactLength.value:void 0,maximum:c?i.exactLength.value:void 0,type:"array",inclusive:!0,exact:!0,message:i.exactLength.message}),n.dirty())}if(i.minLength!==null&&r.data.length<i.minLength.value&&(Ke(r,{code:Ne.too_small,minimum:i.minLength.value,type:"array",inclusive:!0,exact:!1,message:i.minLength.message}),n.dirty()),i.maxLength!==null&&r.data.length>i.maxLength.value&&(Ke(r,{code:Ne.too_big,maximum:i.maxLength.value,type:"array",inclusive:!0,exact:!1,message:i.maxLength.message}),n.dirty()),r.common.async)return Promise.all(r.data.map((c,u)=>i.type._parseAsync(new Vn(r,c,r.path,u)))).then(c=>Rr.mergeArray(n,c));let a=r.data.map((c,u)=>i.type._parseSync(new Vn(r,c,r.path,u)));return Rr.mergeArray(n,a)}get element(){return this._def.type}min(e,r){return new Sn({...this._def,minLength:{value:e,message:Rt.toString(r)}})}max(e,r){return new Sn({...this._def,maxLength:{value:e,message:Rt.toString(r)}})}length(e,r){return new Sn({...this._def,exactLength:{value:e,message:Rt.toString(r)}})}nonempty(e){return this.min(1,e)}};o(Sn,"ZodArray");Sn.create=(t,e)=>new Sn({type:t,minLength:null,maxLength:null,exactLength:null,typeName:pt.ZodArray,...Tt(e)});var J0;(function(t){t.mergeShapes=(e,r)=>({...e,...r})})(J0||(J0={}));var y9=o(t=>e=>new er({...t,shape:()=>({...t.shape(),...e})}),"AugmentFactory");function Fc(t){if(t instanceof er){let e={};for(let r in t.shape){let n=t.shape[r];e[r]=Jn.create(Fc(n))}return new er({...t._def,shape:()=>e})}else return t instanceof Sn?Sn.create(Fc(t.element)):t instanceof Jn?Jn.create(Fc(t.unwrap())):t instanceof Eo?Eo.create(Fc(t.unwrap())):t instanceof Wn?Wn.create(t.items.map(e=>Fc(e))):t}o(Fc,"deepPartialify");var er=class extends xt{constructor(){super(...arguments),this._cached=null,this.nonstrict=this.passthrough,this.augment=y9(this._def),this.extend=y9(this._def)}_getCached(){if(this._cached!==null)return this._cached;let e=this._def.shape(),r=Ut.objectKeys(e);return this._cached={shape:e,keys:r}}_parse(e){if(this._getType(e)!==Fe.object){let v=this._getOrReturnCtx(e);return Ke(v,{code:Ne.invalid_type,expected:Fe.object,received:v.parsedType}),gt}let{status:n,ctx:i}=this._processInputParams(e),{shape:a,keys:c}=this._getCached(),u=[];if(!(this._def.catchall instanceof Ti&&this._def.unknownKeys==="strip"))for(let v in i.data)c.includes(v)||u.push(v);let m=[];for(let v of c){let x=a[v],S=i.data[v];m.push({key:{status:"valid",value:v},value:x._parse(new Vn(i,S,i.path,v)),alwaysSet:v in i.data})}if(this._def.catchall instanceof Ti){let v=this._def.unknownKeys;if(v==="passthrough")for(let x of u)m.push({key:{status:"valid",value:x},value:{status:"valid",value:i.data[x]}});else if(v==="strict")u.length>0&&(Ke(i,{code:Ne.unrecognized_keys,keys:u}),n.dirty());else if(v!=="strip")throw new Error("Internal ZodObject error: invalid unknownKeys value.")}else{let v=this._def.catchall;for(let x of u){let S=i.data[x];m.push({key:{status:"valid",value:x},value:v._parse(new Vn(i,S,i.path,x)),alwaysSet:x in i.data})}}return i.common.async?Promise.resolve().then(async()=>{let v=[];for(let x of m){let S=await x.key;v.push({key:S,value:await x.value,alwaysSet:x.alwaysSet})}return v}).then(v=>Rr.mergeObjectSync(n,v)):Rr.mergeObjectSync(n,m)}get shape(){return this._def.shape()}strict(e){return Rt.errToObj,new er({...this._def,unknownKeys:"strict",...e!==void 0?{errorMap:(r,n)=>{var i,a,c,u;let m=(c=(a=(i=this._def).errorMap)===null||a===void 0?void 0:a.call(i,r,n).message)!==null&&c!==void 0?c:n.defaultError;return r.code==="unrecognized_keys"?{message:(u=Rt.errToObj(e).message)!==null&&u!==void 0?u:m}:{message:m}}}:{}})}strip(){return new er({...this._def,unknownKeys:"strip"})}passthrough(){return new er({...this._def,unknownKeys:"passthrough"})}setKey(e,r){return this.augment({[e]:r})}merge(e){return new er({unknownKeys:e._def.unknownKeys,catchall:e._def.catchall,shape:()=>J0.mergeShapes(this._def.shape(),e._def.shape()),typeName:pt.ZodObject})}catchall(e){return new er({...this._def,catchall:e})}pick(e){let r={};return Ut.objectKeys(e).map(n=>{this.shape[n]&&(r[n]=this.shape[n])}),new er({...this._def,shape:()=>r})}omit(e){let r={};return Ut.objectKeys(this.shape).map(n=>{Ut.objectKeys(e).indexOf(n)===-1&&(r[n]=this.shape[n])}),new er({...this._def,shape:()=>r})}deepPartial(){return Fc(this)}partial(e){let r={};if(e)return Ut.objectKeys(this.shape).map(n=>{Ut.objectKeys(e).indexOf(n)===-1?r[n]=this.shape[n]:r[n]=this.shape[n].optional()}),new er({...this._def,shape:()=>r});for(let n in this.shape){let i=this.shape[n];r[n]=i.optional()}return new er({...this._def,shape:()=>r})}required(e){let r={};if(e)Ut.objectKeys(this.shape).map(n=>{if(Ut.objectKeys(e).indexOf(n)===-1)r[n]=this.shape[n];else{let a=this.shape[n];for(;a instanceof Jn;)a=a._def.innerType;r[n]=a}});else for(let n in this.shape){let a=this.shape[n];for(;a instanceof Jn;)a=a._def.innerType;r[n]=a}return new er({...this._def,shape:()=>r})}keyof(){return E9(Ut.objectKeys(this.shape))}};o(er,"ZodObject");er.create=(t,e)=>new er({shape:()=>t,unknownKeys:"strip",catchall:Ti.create(),typeName:pt.ZodObject,...Tt(e)});er.strictCreate=(t,e)=>new er({shape:()=>t,unknownKeys:"strict",catchall:Ti.create(),typeName:pt.ZodObject,...Tt(e)});er.lazycreate=(t,e)=>new er({shape:t,unknownKeys:"strip",catchall:Ti.create(),typeName:pt.ZodObject,...Tt(e)});var ra=class extends xt{_parse(e){let{ctx:r}=this._processInputParams(e),n=this._def.options;function i(a){for(let u of a)if(u.result.status==="valid")return u.result;for(let u of a)if(u.result.status==="dirty")return r.common.issues.push(...u.ctx.common.issues),u.result;let c=a.map(u=>new Si(u.ctx.common.issues));return Ke(r,{code:Ne.invalid_union,unionErrors:c}),gt}if(o(i,"handleResults"),r.common.async)return Promise.all(n.map(async a=>{let c={...r,common:{...r.common,issues:[]},parent:null};return{result:await a._parseAsync({data:r.data,path:r.path,parent:c}),ctx:c}})).then(i);{let a,c=[];for(let m of n){let v={...r,common:{...r.common,issues:[]},parent:null},x=m._parseSync({data:r.data,path:r.path,parent:v});if(x.status==="valid")return x;x.status==="dirty"&&!a&&(a={result:x,ctx:v}),v.common.issues.length&&c.push(v.common.issues)}if(a)return r.common.issues.push(...a.ctx.common.issues),a.result;let u=c.map(m=>new Si(m));return Ke(r,{code:Ne.invalid_union,unionErrors:u}),gt}}get options(){return this._def.options}};o(ra,"ZodUnion");ra.create=(t,e)=>new ra({options:t,typeName:pt.ZodUnion,...Tt(e)});var K0=o(t=>t instanceof oa?K0(t.schema):t instanceof Mn?K0(t.innerType()):t instanceof sa?[t.value]:t instanceof aa?t.options:t instanceof fa?Object.keys(t.enum):t instanceof ca?K0(t._def.innerType):t instanceof ea?[void 0]:t instanceof ta?[null]:null,"getDiscriminator"),df=class extends xt{_parse(e){let{ctx:r}=this._processInputParams(e);if(r.parsedType!==Fe.object)return Ke(r,{code:Ne.invalid_type,expected:Fe.object,received:r.parsedType}),gt;let n=this.discriminator,i=r.data[n],a=this.optionsMap.get(i);return a?r.common.async?a._parseAsync({data:r.data,path:r.path,parent:r}):a._parseSync({data:r.data,path:r.path,parent:r}):(Ke(r,{code:Ne.invalid_union_discriminator,options:Array.from(this.optionsMap.keys()),path:[n]}),gt)}get discriminator(){return this._def.discriminator}get options(){return this._def.options}get optionsMap(){return this._def.optionsMap}static create(e,r,n){let i=new Map;for(let a of r){let c=K0(a.shape[e]);if(!c)throw new Error(`A discriminator value for key \`${e}\` could not be extracted from all schema options`);for(let u of c){if(i.has(u))throw new Error(`Discriminator property ${String(e)} has duplicate value ${String(u)}`);i.set(u,a)}}return new df({typeName:pt.ZodDiscriminatedUnion,discriminator:e,options:r,optionsMap:i,...Tt(n)})}};o(df,"ZodDiscriminatedUnion");function Xg(t,e){let r=Xs(t),n=Xs(e);if(t===e)return{valid:!0,data:t};if(r===Fe.object&&n===Fe.object){let i=Ut.objectKeys(e),a=Ut.objectKeys(t).filter(u=>i.indexOf(u)!==-1),c={...t,...e};for(let u of a){let m=Xg(t[u],e[u]);if(!m.valid)return{valid:!1};c[u]=m.data}return{valid:!0,data:c}}else if(r===Fe.array&&n===Fe.array){if(t.length!==e.length)return{valid:!1};let i=[];for(let a=0;a<t.length;a++){let c=t[a],u=e[a],m=Xg(c,u);if(!m.valid)return{valid:!1};i.push(m.data)}return{valid:!0,data:i}}else return r===Fe.date&&n===Fe.date&&+t==+e?{valid:!0,data:t}:{valid:!1}}o(Xg,"mergeValues");var na=class extends xt{_parse(e){let{status:r,ctx:n}=this._processInputParams(e),i=o((a,c)=>{if(Jg(a)||Jg(c))return gt;let u=Xg(a.value,c.value);return u.valid?((Yg(a)||Yg(c))&&r.dirty(),{status:r.value,value:u.data}):(Ke(n,{code:Ne.invalid_intersection_types}),gt)},"handleParsed");return n.common.async?Promise.all([this._def.left._parseAsync({data:n.data,path:n.path,parent:n}),this._def.right._parseAsync({data:n.data,path:n.path,parent:n})]).then(([a,c])=>i(a,c)):i(this._def.left._parseSync({data:n.data,path:n.path,parent:n}),this._def.right._parseSync({data:n.data,path:n.path,parent:n}))}};o(na,"ZodIntersection");na.create=(t,e,r)=>new na({left:t,right:e,typeName:pt.ZodIntersection,...Tt(r)});var Wn=class extends xt{_parse(e){let{status:r,ctx:n}=this._processInputParams(e);if(n.parsedType!==Fe.array)return Ke(n,{code:Ne.invalid_type,expected:Fe.array,received:n.parsedType}),gt;if(n.data.length<this._def.items.length)return Ke(n,{code:Ne.too_small,minimum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),gt;!this._def.rest&&n.data.length>this._def.items.length&&(Ke(n,{code:Ne.too_big,maximum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),r.dirty());let a=n.data.map((c,u)=>{let m=this._def.items[u]||this._def.rest;return m?m._parse(new Vn(n,c,n.path,u)):null}).filter(c=>!!c);return n.common.async?Promise.all(a).then(c=>Rr.mergeArray(r,c)):Rr.mergeArray(r,a)}get items(){return this._def.items}rest(e){return new Wn({...this._def,rest:e})}};o(Wn,"ZodTuple");Wn.create=(t,e)=>{if(!Array.isArray(t))throw new Error("You must pass an array of schemas to z.tuple([ ... ])");return new Wn({items:t,typeName:pt.ZodTuple,rest:null,...Tt(e)})};var ia=class extends xt{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(e){let{status:r,ctx:n}=this._processInputParams(e);if(n.parsedType!==Fe.object)return Ke(n,{code:Ne.invalid_type,expected:Fe.object,received:n.parsedType}),gt;let i=[],a=this._def.keyType,c=this._def.valueType;for(let u in n.data)i.push({key:a._parse(new Vn(n,u,n.path,u)),value:c._parse(new Vn(n,n.data[u],n.path,u))});return n.common.async?Rr.mergeObjectAsync(r,i):Rr.mergeObjectSync(r,i)}get element(){return this._def.valueType}static create(e,r,n){return r instanceof xt?new ia({keyType:e,valueType:r,typeName:pt.ZodRecord,...Tt(n)}):new ia({keyType:Mi.create(),valueType:e,typeName:pt.ZodRecord,...Tt(r)})}};o(ia,"ZodRecord");var pf=class extends xt{_parse(e){let{status:r,ctx:n}=this._processInputParams(e);if(n.parsedType!==Fe.map)return Ke(n,{code:Ne.invalid_type,expected:Fe.map,received:n.parsedType}),gt;let i=this._def.keyType,a=this._def.valueType,c=[...n.data.entries()].map(([u,m],v)=>({key:i._parse(new Vn(n,u,n.path,[v,"key"])),value:a._parse(new Vn(n,m,n.path,[v,"value"]))}));if(n.common.async){let u=new Map;return Promise.resolve().then(async()=>{for(let m of c){let v=await m.key,x=await m.value;if(v.status==="aborted"||x.status==="aborted")return gt;(v.status==="dirty"||x.status==="dirty")&&r.dirty(),u.set(v.value,x.value)}return{status:r.value,value:u}})}else{let u=new Map;for(let m of c){let v=m.key,x=m.value;if(v.status==="aborted"||x.status==="aborted")return gt;(v.status==="dirty"||x.status==="dirty")&&r.dirty(),u.set(v.value,x.value)}return{status:r.value,value:u}}}};o(pf,"ZodMap");pf.create=(t,e,r)=>new pf({valueType:e,keyType:t,typeName:pt.ZodMap,...Tt(r)});var _o=class extends xt{_parse(e){let{status:r,ctx:n}=this._processInputParams(e);if(n.parsedType!==Fe.set)return Ke(n,{code:Ne.invalid_type,expected:Fe.set,received:n.parsedType}),gt;let i=this._def;i.minSize!==null&&n.data.size<i.minSize.value&&(Ke(n,{code:Ne.too_small,minimum:i.minSize.value,type:"set",inclusive:!0,exact:!1,message:i.minSize.message}),r.dirty()),i.maxSize!==null&&n.data.size>i.maxSize.value&&(Ke(n,{code:Ne.too_big,maximum:i.maxSize.value,type:"set",inclusive:!0,exact:!1,message:i.maxSize.message}),r.dirty());let a=this._def.valueType;function c(m){let v=new Set;for(let x of m){if(x.status==="aborted")return gt;x.status==="dirty"&&r.dirty(),v.add(x.value)}return{status:r.value,value:v}}o(c,"finalizeSet");let u=[...n.data.values()].map((m,v)=>a._parse(new Vn(n,m,n.path,v)));return n.common.async?Promise.all(u).then(m=>c(m)):c(u)}min(e,r){return new _o({...this._def,minSize:{value:e,message:Rt.toString(r)}})}max(e,r){return new _o({...this._def,maxSize:{value:e,message:Rt.toString(r)}})}size(e,r){return this.min(e,r).max(e,r)}nonempty(e){return this.min(1,e)}};o(_o,"ZodSet");_o.create=(t,e)=>new _o({valueType:t,minSize:null,maxSize:null,typeName:pt.ZodSet,...Tt(e)});var ls=class extends xt{constructor(){super(...arguments),this.validate=this.implement}_parse(e){let{ctx:r}=this._processInputParams(e);if(r.parsedType!==Fe.function)return Ke(r,{code:Ne.invalid_type,expected:Fe.function,received:r.parsedType}),gt;function n(u,m){return G0({data:u,path:r.path,errorMaps:[r.common.contextualErrorMap,r.schemaErrorMap,j0(),Cl].filter(v=>!!v),issueData:{code:Ne.invalid_arguments,argumentsError:m}})}o(n,"makeArgsIssue");function i(u,m){return G0({data:u,path:r.path,errorMaps:[r.common.contextualErrorMap,r.schemaErrorMap,j0(),Cl].filter(v=>!!v),issueData:{code:Ne.invalid_return_type,returnTypeError:m}})}o(i,"makeReturnsIssue");let a={errorMap:r.common.contextualErrorMap},c=r.data;return this._def.returns instanceof hs?rn(async(...u)=>{let m=new Si([]),v=await this._def.args.parseAsync(u,a).catch(O=>{throw m.addIssue(n(u,O)),m}),x=await c(...v);return await this._def.returns._def.type.parseAsync(x,a).catch(O=>{throw m.addIssue(i(x,O)),m})}):rn((...u)=>{let m=this._def.args.safeParse(u,a);if(!m.success)throw new Si([n(u,m.error)]);let v=c(...m.data),x=this._def.returns.safeParse(v,a);if(!x.success)throw new Si([i(v,x.error)]);return x.data})}parameters(){return this._def.args}returnType(){return this._def.returns}args(...e){return new ls({...this._def,args:Wn.create(e).rest(wo.create())})}returns(e){return new ls({...this._def,returns:e})}implement(e){return this.parse(e)}strictImplement(e){return this.parse(e)}static create(e,r,n){return new ls({args:e||Wn.create([]).rest(wo.create()),returns:r||wo.create(),typeName:pt.ZodFunction,...Tt(n)})}};o(ls,"ZodFunction");var oa=class extends xt{get schema(){return this._def.getter()}_parse(e){let{ctx:r}=this._processInputParams(e);return this._def.getter()._parse({data:r.data,path:r.path,parent:r})}};o(oa,"ZodLazy");oa.create=(t,e)=>new oa({getter:t,typeName:pt.ZodLazy,...Tt(e)});var sa=class extends xt{_parse(e){if(e.data!==this._def.value){let r=this._getOrReturnCtx(e);return Ke(r,{code:Ne.invalid_literal,expected:this._def.value}),gt}return{status:"valid",value:e.data}}get value(){return this._def.value}};o(sa,"ZodLiteral");sa.create=(t,e)=>new sa({value:t,typeName:pt.ZodLiteral,...Tt(e)});function E9(t,e){return new aa({values:t,typeName:pt.ZodEnum,...Tt(e)})}o(E9,"createZodEnum");var aa=class extends xt{_parse(e){if(typeof e.data!="string"){let r=this._getOrReturnCtx(e),n=this._def.values;return Ke(r,{expected:Ut.joinValues(n),received:r.parsedType,code:Ne.invalid_type}),gt}if(this._def.values.indexOf(e.data)===-1){let r=this._getOrReturnCtx(e),n=this._def.values;return Ke(r,{received:r.data,code:Ne.invalid_enum_value,options:n}),gt}return rn(e.data)}get options(){return this._def.values}get enum(){let e={};for(let r of this._def.values)e[r]=r;return e}get Values(){let e={};for(let r of this._def.values)e[r]=r;return e}get Enum(){let e={};for(let r of this._def.values)e[r]=r;return e}};o(aa,"ZodEnum");aa.create=E9;var fa=class extends xt{_parse(e){let r=Ut.getValidEnumValues(this._def.values),n=this._getOrReturnCtx(e);if(n.parsedType!==Fe.string&&n.parsedType!==Fe.number){let i=Ut.objectValues(r);return Ke(n,{expected:Ut.joinValues(i),received:n.parsedType,code:Ne.invalid_type}),gt}if(r.indexOf(e.data)===-1){let i=Ut.objectValues(r);return Ke(n,{received:n.data,code:Ne.invalid_enum_value,options:i}),gt}return rn(e.data)}get enum(){return this._def.values}};o(fa,"ZodNativeEnum");fa.create=(t,e)=>new fa({values:t,typeName:pt.ZodNativeEnum,...Tt(e)});var hs=class extends xt{_parse(e){let{ctx:r}=this._processInputParams(e);if(r.parsedType!==Fe.promise&&r.common.async===!1)return Ke(r,{code:Ne.invalid_type,expected:Fe.promise,received:r.parsedType}),gt;let n=r.parsedType===Fe.promise?r.data:Promise.resolve(r.data);return rn(n.then(i=>this._def.type.parseAsync(i,{path:r.path,errorMap:r.common.contextualErrorMap})))}};o(hs,"ZodPromise");hs.create=(t,e)=>new hs({type:t,typeName:pt.ZodPromise,...Tt(e)});var Mn=class extends xt{innerType(){return this._def.schema}sourceType(){return this._def.schema._def.typeName===pt.ZodEffects?this._def.schema.sourceType():this._def.schema}_parse(e){let{status:r,ctx:n}=this._processInputParams(e),i=this._def.effect||null;if(i.type==="preprocess"){let c=i.transform(n.data);return n.common.async?Promise.resolve(c).then(u=>this._def.schema._parseAsync({data:u,path:n.path,parent:n})):this._def.schema._parseSync({data:c,path:n.path,parent:n})}let a={addIssue:c=>{Ke(n,c),c.fatal?r.abort():r.dirty()},get path(){return n.path}};if(a.addIssue=a.addIssue.bind(a),i.type==="refinement"){let c=o(u=>{let m=i.refinement(u,a);if(n.common.async)return Promise.resolve(m);if(m instanceof Promise)throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");return u},"executeRefinement");if(n.common.async===!1){let u=this._def.schema._parseSync({data:n.data,path:n.path,parent:n});return u.status==="aborted"?gt:(u.status==="dirty"&&r.dirty(),c(u.value),{status:r.value,value:u.value})}else return this._def.schema._parseAsync({data:n.data,path:n.path,parent:n}).then(u=>u.status==="aborted"?gt:(u.status==="dirty"&&r.dirty(),c(u.value).then(()=>({status:r.value,value:u.value}))))}if(i.type==="transform")if(n.common.async===!1){let c=this._def.schema._parseSync({data:n.data,path:n.path,parent:n});if(!V0(c))return c;let u=i.transform(c.value,a);if(u instanceof Promise)throw new Error("Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.");return{status:r.value,value:u}}else return this._def.schema._parseAsync({data:n.data,path:n.path,parent:n}).then(c=>V0(c)?Promise.resolve(i.transform(c.value,a)).then(u=>({status:r.value,value:u})):c);Ut.assertNever(i)}};o(Mn,"ZodEffects");Mn.create=(t,e,r)=>new Mn({schema:t,typeName:pt.ZodEffects,effect:e,...Tt(r)});Mn.createWithPreprocess=(t,e,r)=>new Mn({schema:e,effect:{type:"preprocess",transform:t},typeName:pt.ZodEffects,...Tt(r)});var Jn=class extends xt{_parse(e){return this._getType(e)===Fe.undefined?rn(void 0):this._def.innerType._parse(e)}unwrap(){return this._def.innerType}};o(Jn,"ZodOptional");Jn.create=(t,e)=>new Jn({innerType:t,typeName:pt.ZodOptional,...Tt(e)});var Eo=class extends xt{_parse(e){return this._getType(e)===Fe.null?rn(null):this._def.innerType._parse(e)}unwrap(){return this._def.innerType}};o(Eo,"ZodNullable");Eo.create=(t,e)=>new Eo({innerType:t,typeName:pt.ZodNullable,...Tt(e)});var ca=class extends xt{_parse(e){let{ctx:r}=this._processInputParams(e),n=r.data;return r.parsedType===Fe.undefined&&(n=this._def.defaultValue()),this._def.innerType._parse({data:n,path:r.path,parent:r})}removeDefault(){return this._def.innerType}};o(ca,"ZodDefault");ca.create=(t,e)=>new ca({innerType:t,typeName:pt.ZodDefault,defaultValue:typeof e.default=="function"?e.default:()=>e.default,...Tt(e)});var mf=class extends xt{_parse(e){let{ctx:r}=this._processInputParams(e),n=this._def.innerType._parse({data:r.data,path:r.path,parent:r});return W0(n)?n.then(i=>({status:"valid",value:i.status==="valid"?i.value:this._def.defaultValue()})):{status:"valid",value:n.status==="valid"?n.value:this._def.defaultValue()}}removeDefault(){return this._def.innerType}};o(mf,"ZodCatch");mf.create=(t,e)=>new mf({innerType:t,typeName:pt.ZodCatch,defaultValue:typeof e.default=="function"?e.default:()=>e.default,...Tt(e)});var bf=class extends xt{_parse(e){if(this._getType(e)!==Fe.nan){let n=this._getOrReturnCtx(e);return Ke(n,{code:Ne.invalid_type,expected:Fe.nan,received:n.parsedType}),gt}return{status:"valid",value:e.data}}};o(bf,"ZodNaN");bf.create=t=>new bf({typeName:pt.ZodNaN,...Tt(t)});var Cq=Symbol("zod_brand"),Tl=class extends xt{_parse(e){let{ctx:r}=this._processInputParams(e),n=r.data;return this._def.type._parse({data:n,path:r.path,parent:r})}unwrap(){return this._def.type}};o(Tl,"ZodBranded");var ua=class extends xt{_parse(e){let{status:r,ctx:n}=this._processInputParams(e);if(n.common.async)return o(async()=>{let a=await this._def.in._parseAsync({data:n.data,path:n.path,parent:n});return a.status==="aborted"?gt:a.status==="dirty"?(r.dirty(),_9(a.value)):this._def.out._parseAsync({data:a.value,path:n.path,parent:n})},"handleAsync")();{let i=this._def.in._parseSync({data:n.data,path:n.path,parent:n});return i.status==="aborted"?gt:i.status==="dirty"?(r.dirty(),{status:"dirty",value:i.value}):this._def.out._parseSync({data:i.value,path:n.path,parent:n})}}static create(e,r){return new ua({in:e,out:r,typeName:pt.ZodPipeline})}};o(ua,"ZodPipeline");var A9=o((t,e={},r)=>t?us.create().superRefine((n,i)=>{if(!t(n)){let a=typeof e=="function"?e(n):e,c=typeof a=="string"?{message:a}:a;i.addIssue({code:"custom",...c,fatal:r})}}):us.create(),"custom"),kq={object:er.lazycreate},pt;(function(t){t.ZodString="ZodString",t.ZodNumber="ZodNumber",t.ZodNaN="ZodNaN",t.ZodBigInt="ZodBigInt",t.ZodBoolean="ZodBoolean",t.ZodDate="ZodDate",t.ZodSymbol="ZodSymbol",t.ZodUndefined="ZodUndefined",t.ZodNull="ZodNull",t.ZodAny="ZodAny",t.ZodUnknown="ZodUnknown",t.ZodNever="ZodNever",t.ZodVoid="ZodVoid",t.ZodArray="ZodArray",t.ZodObject="ZodObject",t.ZodUnion="ZodUnion",t.ZodDiscriminatedUnion="ZodDiscriminatedUnion",t.ZodIntersection="ZodIntersection",t.ZodTuple="ZodTuple",t.ZodRecord="ZodRecord",t.ZodMap="ZodMap",t.ZodSet="ZodSet",t.ZodFunction="ZodFunction",t.ZodLazy="ZodLazy",t.ZodLiteral="ZodLiteral",t.ZodEnum="ZodEnum",t.ZodEffects="ZodEffects",t.ZodNativeEnum="ZodNativeEnum",t.ZodOptional="ZodOptional",t.ZodNullable="ZodNullable",t.ZodDefault="ZodDefault",t.ZodCatch="ZodCatch",t.ZodPromise="ZodPromise",t.ZodBranded="ZodBranded",t.ZodPipeline="ZodPipeline"})(pt||(pt={}));var Iq=o((t,e={message:`Input not instance of ${t.name}`})=>A9(r=>r instanceof t,e,!0),"instanceOfType"),S9=Mi.create,M9=Yi.create,Dq=bf.create,Oq=Zs.create,T9=Qs.create,Rq=xo.create,Nq=lf.create,Pq=ea.create,Lq=ta.create,Bq=us.create,Uq=wo.create,$q=Ti.create,Fq=hf.create,qq=Sn.create,Hq=er.create,zq=er.strictCreate,Kq=ra.create,jq=df.create,Gq=na.create,Vq=Wn.create,Wq=ia.create,Jq=pf.create,Yq=_o.create,Xq=ls.create,Zq=oa.create,Qq=sa.create,eH=aa.create,tH=fa.create,rH=hs.create,x9=Mn.create,nH=Jn.create,iH=Eo.create,oH=Mn.createWithPreprocess,sH=ua.create,aH=o(()=>S9().optional(),"ostring"),fH=o(()=>M9().optional(),"onumber"),cH=o(()=>T9().optional(),"oboolean"),uH={string:t=>Mi.create({...t,coerce:!0}),number:t=>Yi.create({...t,coerce:!0}),boolean:t=>Qs.create({...t,coerce:!0}),bigint:t=>Zs.create({...t,coerce:!0}),date:t=>xo.create({...t,coerce:!0})},lH=gt,U=Object.freeze({__proto__:null,defaultErrorMap:Cl,setErrorMap:wq,getErrorMap:j0,makeIssue:G0,EMPTY_PATH:_q,addIssueToContext:Ke,ParseStatus:Rr,INVALID:gt,DIRTY:_9,OK:rn,isAborted:Jg,isDirty:Yg,isValid:V0,isAsync:W0,get util(){return Ut},ZodParsedType:Fe,getParsedType:Xs,ZodType:xt,ZodString:Mi,ZodNumber:Yi,ZodBigInt:Zs,ZodBoolean:Qs,ZodDate:xo,ZodSymbol:lf,ZodUndefined:ea,ZodNull:ta,ZodAny:us,ZodUnknown:wo,ZodNever:Ti,ZodVoid:hf,ZodArray:Sn,get objectUtil(){return J0},ZodObject:er,ZodUnion:ra,ZodDiscriminatedUnion:df,ZodIntersection:na,ZodTuple:Wn,ZodRecord:ia,ZodMap:pf,ZodSet:_o,ZodFunction:ls,ZodLazy:oa,ZodLiteral:sa,ZodEnum:aa,ZodNativeEnum:fa,ZodPromise:hs,ZodEffects:Mn,ZodTransformer:Mn,ZodOptional:Jn,ZodNullable:Eo,ZodDefault:ca,ZodCatch:mf,ZodNaN:bf,BRAND:Cq,ZodBranded:Tl,ZodPipeline:ua,custom:A9,Schema:xt,ZodSchema:xt,late:kq,get ZodFirstPartyTypeKind(){return pt},coerce:uH,any:Bq,array:qq,bigint:Oq,boolean:T9,date:Rq,discriminatedUnion:jq,effect:x9,enum:eH,function:Xq,instanceof:Iq,intersection:Gq,lazy:Zq,literal:Qq,map:Jq,nan:Dq,nativeEnum:tH,never:$q,null:Lq,nullable:iH,number:M9,object:Hq,oboolean:cH,onumber:fH,optional:nH,ostring:aH,pipeline:sH,preprocess:oH,promise:rH,record:Wq,set:Yq,strictObject:zq,string:S9,symbol:Nq,transformer:x9,tuple:Vq,undefined:Pq,union:Kq,unknown:Uq,void:Fq,NEVER:lH,ZodIssueCode:Ne,quotelessJson:xq,ZodError:Si});var k9=U.array(U.string().or(U.record(U.any()))),Jte=U.object({type:U.string().optional(),narrative:U.string().optional()}),X0=U.string().or(U.object({id:U.string(),type:U.string(),caption:U.string().optional()})),hH=U.object({type:U.string().min(1).or(U.string().array().nonempty()),latitude:U.number(),longitude:U.number()}),dH=U.object({type:U.string().min(1).or(U.string().array().nonempty()),addressCountry:U.string().optional(),addressCountryCode:U.string().optional(),addressRegion:U.string().optional(),addressLocality:U.string().optional(),streetAddress:U.string().optional(),postOfficeBoxNumber:U.string().optional(),postalCode:U.string().optional(),geo:hH.optional()}),pH=U.enum(["sourcedId","systemId","productId","userName","accountId","emailAddress","nationalIdentityNumber","isbn","issn","lisSourcedId","oneRosterSourcedId","sisSourcedId","ltiContextId","ltiDeploymentId","ltiToolId","ltiPlatformId","ltiUserId","identifier"]).or(U.string()),I9=U.object({type:U.string().min(1).or(U.string().array().nonempty()),identifier:U.string(),identifierType:pH}),kl=U.string().or(U.object({id:U.string().optional(),type:U.string().or(U.string().array().nonempty().optional()),name:U.string().optional(),url:U.string().optional(),phone:U.string().optional(),description:U.string().optional(),endorsement:U.any().array().optional(),image:X0.optional(),email:U.string().email().optional(),address:dH.optional(),otherIdentifier:I9.array().optional(),official:U.string().optional(),parentOrg:U.any().optional(),familyName:U.string().optional(),givenName:U.string().optional(),additionalName:U.string().optional(),patronymicName:U.string().optional(),honorificPrefix:U.string().optional(),honorificSuffix:U.string().optional(),familyNamePrefix:U.string().optional(),dateOfBirth:U.string().optional()}).catchall(U.any())),Zg=U.object({id:U.string().optional()}).catchall(U.any()),mH=U.object({type:U.string(),id:U.string()}).catchall(U.any()),bH=U.object({id:U.string(),type:U.string()}).catchall(U.any()),gH=U.object({id:U.string(),type:U.string()}).catchall(U.any()),Y0=U.object({"@context":k9,id:U.string().optional(),type:U.string().array().nonempty(),issuer:kl,issuanceDate:U.string(),expirationDate:U.string().optional(),credentialSubject:Zg.or(Zg.array()),credentialStatus:mH.optional(),credentialSchema:bH.array().optional(),refreshService:gH.optional()}).catchall(U.any()),la=U.object({type:U.string(),created:U.string(),challenge:U.string().optional(),domain:U.string().optional(),nonce:U.string().optional(),proofPurpose:U.string(),verificationMethod:U.string(),jws:U.string().optional()}).catchall(U.any()),Il=Y0.extend({proof:la.or(la.array())}),vH=U.object({"@context":k9,id:U.string().optional(),type:U.string().or(U.string().array().nonempty()),verifiableCredential:Il.or(Il.array()).optional(),holder:U.string().optional()}).catchall(U.any()),e2=vH.extend({proof:la.or(la.array())}),yH=U.enum(["ceasn:Competency","ceterms:Credential","CFItem","CFRubric","CFRubricCriterion","CFRubricCriterionLevel","CTDL"]).or(U.string()),Z0=U.object({type:U.string().array().nonempty(),targetCode:U.string().optional(),targetDescription:U.string().optional(),targetName:U.string(),targetFramework:U.string().optional(),targetType:yH.optional(),targetUrl:U.string()}),xH=U.enum(["Achievement","ApprenticeshipCertificate","Assessment","Assignment","AssociateDegree","Award","Badge","BachelorDegree","Certificate","CertificateOfCompletion","Certification","CommunityService","Competency","Course","CoCurricular","Degree","Diploma","DoctoralDegree","Fieldwork","GeneralEducationDevelopment","JourneymanCertificate","LearningProgram","License","Membership","ProfessionalDoctorate","QualityAssuranceCredential","MasterCertificate","MasterDegree","MicroCredential","ResearchDoctorate","SecondarySchoolDiploma"]),wH=xH.or(U.string()),_H=U.object({id:U.string().optional(),narrative:U.string().optional()}).catchall(U.any()),EH=U.object({id:U.string(),type:U.string().array().nonempty(),endorsementComment:U.string().optional()}),AH=Y0.extend({credentialSubject:EH,proof:la.or(la.array()).optional()}),SH=U.object({id:U.string(),"@language":U.string().optional(),version:U.string().optional()}),MH=U.enum(["GradePointAverage","LetterGrade","Percent","PerformanceLevel","PredictedScore","RawScore","Result","RubricCriterion","RubricCriterionLevel","RubricScore","ScaledScore","Status"]).or(U.string()),TH=U.object({id:U.string(),type:U.string().array().nonempty(),alignment:Z0.array().optional(),description:U.string().optional(),level:U.string().optional(),name:U.string(),points:U.string().optional()}).catchall(U.any()),CH=U.object({id:U.string(),type:U.string().array().nonempty(),alignment:Z0.array().optional(),allowedValue:U.string().array().optional(),name:U.string(),requiredLevel:U.string().optional(),requiredValue:U.string().optional(),resultType:MH,rubricCriterionLevel:TH.array().optional(),valueMax:U.string().optional(),valueMin:U.string().optional()}).catchall(U.any()),kH=U.object({id:U.string().optional(),type:U.string().array().nonempty(),alignment:Z0.array().optional(),achievementType:wH.optional(),creator:kl.optional(),creditsAvailable:U.number().optional(),criteria:_H,description:U.string(),endorsement:AH.array().optional(),fieldOfStudy:U.string().optional(),humanCode:U.string().optional(),image:X0.optional(),"@language":U.string().optional(),name:U.string(),otherIdentifier:I9.array().optional(),related:SH.array().optional(),resultDescription:CH.array().optional(),specialization:U.string().optional(),tag:U.string().array().optional(),version:U.string().optional()}).catchall(U.any()),IH=U.object({type:U.string(),hashed:U.boolean(),identityHash:U.string(),identityType:U.string(),salt:U.string().optional()}),DH=U.enum(["Completed","Enrolled","Failed","InProgress","OnHold","Withdrew"]),OH=U.object({type:U.string().array().nonempty(),achievedLevel:U.string().optional(),alignment:Z0.array().optional(),resultDescription:U.string().optional(),status:DH.optional(),value:U.string().optional()}).catchall(U.any()),C9=U.object({id:U.string().optional(),type:U.string().array().nonempty(),activityEndDate:U.string().optional(),activityStartDate:U.string().optional(),creditsEarned:U.number().optional(),achievement:kH.optional(),identifier:IH.array().optional(),image:X0.optional(),licenseNumber:U.string().optional(),narrative:U.string().optional(),result:OH.array().optional(),role:U.string().optional(),source:kl.optional(),term:U.string().optional()}).catchall(U.any()),RH=U.object({id:U.string().optional(),type:U.string().array().nonempty(),narrative:U.string().optional(),name:U.string().optional(),description:U.string().optional(),genre:U.string().optional(),audience:U.string().optional()}).catchall(U.any()),NH=Y0.extend({name:U.string().optional(),description:U.string().optional(),image:X0.optional(),credentialSubject:C9.or(C9.array()),endorsement:Y0.array().optional(),evidence:RH.array().optional()}),Xte=NH.extend({proof:la.or(la.array())}),Qte=U.object({checks:U.string().array(),warnings:U.string().array(),errors:U.string().array()}),D9=U.enum(["Success","Failed","Error"]),ere=D9.enum,tre=U.object({check:U.string(),status:D9,message:U.string().optional(),details:U.string().optional()}),rre=U.object({title:U.string().optional(),createdAt:U.string().optional(),issuer:kl.optional(),issuee:kl.optional(),credentialSubject:Zg.optional()}),nre=U.object({id:U.string(),uri:U.string()}).catchall(U.any()),sre=U.object({limit:U.number(),cursor:U.string().optional()}),gf=U.object({cursor:U.string().optional(),hasMore:U.boolean()}),PH=U.object({kty:U.string(),crv:U.string(),x:U.string(),y:U.string().optional(),n:U.string().optional(),d:U.string()}),LH=U.object({alg:U.string(),iv:U.string(),tag:U.string(),epk:PH.partial().optional(),kid:U.string().optional(),apv:U.string().optional(),apu:U.string().optional()}),BH=U.object({header:LH,encrypted_key:U.string()}),UH=U.object({protected:U.string(),iv:U.string(),ciphertext:U.string(),tag:U.string(),aad:U.string().optional(),recipients:BH.array().optional()}),O9=U.object({encryptedRecord:UH,fields:U.string().array()}).catchall(U.any()),fre=gf.extend({records:O9.array()}),$H=O9.extend({id:U.string()}),cre=gf.extend({records:$H.array()}),qc=U.object({profileId:U.string().min(3).max(40),displayName:U.string().default(""),bio:U.string().default(""),did:U.string(),email:U.string().optional(),image:U.string().optional(),isServiceProfile:U.boolean().default(!1).optional(),notificationsWebhook:U.string().url().startsWith("https://").optional()}),lre=gf.extend({records:qc.array()}),hre=U.enum(["CONNECTED","PENDING_REQUEST_SENT","PENDING_REQUEST_RECEIVED","NOT_CONNECTED"]),dre=U.object({uri:U.string(),to:U.string(),from:U.string(),sent:U.string().datetime(),received:U.string().datetime().optional()}),FH=U.enum(["DRAFT","LIVE"]),pre=U.object({uri:U.string(),name:U.string().optional(),type:U.string().optional(),category:U.string().optional(),status:FH.optional(),autoConnectRecipients:U.boolean().optional()}),mre=U.object({to:qc,from:U.string(),received:U.string().optional()}),qH=U.enum(["CONNECTION_REQUEST","CONNECTION_ACCEPTED","CREDENTIAL_RECEIVED","CREDENTIAL_ACCEPTED","BOOST_RECEIVED","BOOST_ACCEPTED","PRESENTATION_REQUEST","PRESENTATION_RECEIVED"]),HH=U.object({title:U.string().optional(),body:U.string().optional()}),zH=U.object({vcUris:U.array(U.string()).optional(),vpUris:U.array(U.string()).optional()}),bre=U.object({type:qH,to:qc.partial().and(U.object({did:U.string()})),from:qc.partial().and(U.object({did:U.string()})),message:HH.optional(),data:zH.optional(),sent:U.string().datetime().optional()}),gre=U.object({endpoint:U.string(),name:U.string(),did:U.string().optional()}),vre=U.object({ttlSeconds:U.number().optional(),totalUses:U.number().optional()}),KH=U.object({endpoint:U.string()}),yre=U.object({signingAuthority:KH,relationship:U.object({name:U.string().max(15).regex(/^[a-z0-9-]+$/,{message:"The input string must contain only lowercase letters, numbers, and hyphens."}),did:U.string()})}),jH=U.enum(["live","stale","withdrawn"]),GH=U.object({read:U.object({anonymize:U.boolean().optional(),credentials:U.object({categories:U.record(U.object({required:U.boolean()})).default({})}).default({}),personal:U.record(U.object({required:U.boolean()})).default({})}).default({}),write:U.object({credentials:U.object({categories:U.record(U.object({required:U.boolean()})).default({})}).default({}),personal:U.record(U.object({required:U.boolean()})).default({})}).default({})}),R9=U.object({contract:GH,owner:qc,name:U.string(),subtitle:U.string().optional(),description:U.string().optional(),reasonForAccessing:U.string().optional(),image:U.string().optional(),uri:U.string(),createdAt:U.string(),updatedAt:U.string(),expiresAt:U.string().optional()}),xre=gf.extend({records:R9.omit({owner:!0}).array()}),VH=U.object({credentials:U.object({categories:U.record(U.string().array()).default({})}),personal:U.record(U.string()).default({}),date:U.string()}),wre=gf.extend({records:VH.array()}),N9=U.object({read:U.object({anonymize:U.boolean().optional(),credentials:U.object({shareAll:U.boolean().optional(),sharing:U.boolean().optional(),categories:U.record(U.object({sharing:U.boolean().optional(),shared:U.string().array().optional(),shareAll:U.boolean().optional()})).default({})}).default({}),personal:U.record(U.string()).default({})}).default({}),write:U.object({credentials:U.object({categories:U.record(U.boolean()).default({})}).default({}),personal:U.record(U.boolean()).default({})}).default({})}),_re=gf.extend({records:U.object({expiresAt:U.string().optional(),oneTime:U.boolean().optional(),terms:N9,contract:R9,uri:U.string(),consenter:qc,status:jH}).array()}),Ere=U.object({read:U.object({anonymize:U.boolean().optional(),credentials:U.object({categories:U.record(U.object({required:U.boolean().optional()})).optional()}).optional(),personal:U.record(U.object({required:U.boolean().optional()})).optional()}).optional(),write:U.object({credentials:U.object({categories:U.record(U.object({required:U.boolean().optional()})).optional()}).optional(),personal:U.record(U.object({required:U.boolean().optional()})).optional()}).optional()}),WH=U.object({read:U.object({anonymize:U.boolean().optional(),credentials:U.object({shareAll:U.boolean().optional(),sharing:U.boolean().optional(),categories:U.record(U.object({sharing:U.boolean().optional(),shared:U.string().array().optional(),shareAll:U.boolean().optional()}).optional()).optional()}).optional(),personal:U.record(U.string()).optional()}).optional(),write:U.object({credentials:U.object({categories:U.record(U.boolean()).optional()}).optional(),personal:U.record(U.boolean()).optional()}).optional()}),Qg=U.enum(["consent","update","sync","withdraw"]),Are=U.object({terms:WH.optional(),action:Qg.or(Qg.array()).optional(),date:U.object({$gt:U.string()}).or(U.object({$lt:U.string()})).or(U.object({$eq:U.string()})).optional(),expiresAt:U.object({$gt:U.string()}).or(U.object({$lt:U.string()})).or(U.object({$eq:U.string()})).optional(),oneTime:U.boolean().optional()}),JH=U.object({expiresAt:U.string().optional(),oneTime:U.boolean().optional(),terms:N9.optional(),id:U.string(),action:Qg,date:U.string()}),Sre=gf.extend({records:JH.array()});var Q0=o(t=>`lc:ceramic:${t}`,"streamIdToCeramicURI");var t2=U.string().refine(t=>t.split(":").length===3&&t.split(":")[0]==="lc","URI must be of the form lc:${storage}:${url}").refine(t=>t.split(":")[1]==="ceramic","URI must use storage type ceramic (i.e. must be lc:ceramic:${streamID})");var ep=o(async(t,{ceramicEndpoint:e,defaultContentFamily:r})=>{let n=new Ml(e),i=o(async(R,D,P,J)=>t.invoke.didResolver(R,J),"learnCardResolver"),a={...g8.getResolver(),web:i},c=new Va({resolver:a});n.did=c;let u=t.invoke.getKey(),m=new tl(e8(u));n.did.setProvider(m),await n.did.authenticate();let v=new yl({ceramic:n}),x=o(async(R,D={},P={},J)=>{if(!R)throw new Error("content is required");if(D.controllers||(D.controllers=[n.did.id]),D.family||(D.family=r),"pin"in P||(P.pin=!0),J?.encrypt){t.debug?.("learnCard.store.Ceramic.upload.publishContentToCeramic - encrypt enabled",J);let W=J?.recipients||[];J?.controllersCanDecrypt&&(W=[...W,...D.controllers]),R=await n?.did?.createDagJWE(R,P9.default.uniq(W))}return t.debug?.("learnCard.store.Ceramic.upload.publishContentToCeramic - content to upload",R,D,P),(await Gn.create(n,R,D,P)).id.toString()},"publishContentToCeramic"),S=o(async R=>{let D=(await v.load(R))?.content;if(t.debug?.("learnCard.read.get.readContentFromCeramic",D),D?.ciphertext)try{return await c.decryptDagJWE(D)}catch(P){throw t.debug?.("learnCard.read.get.readContentFromCeramic - Could not decrypt credential - DID not authorized.",P),new Error("Could not decrypt credential - DID not authorized.")}return D},"readContentFromCeramic"),O=o(async(R,D)=>(await Il.or(e2).parseAsync(R),Q0(await x(R,{},{},D))),"uploadCredential");return{name:"Ceramic",displayName:"Ceramic",description:"Uploads/resolves credentials using the Ceramic Network (https://ceramic.network/)",store:{upload:async(R,D)=>(R.debug?.("learnCard.store.Ceramic.upload"),O(D)),uploadEncrypted:async(R,D,P)=>(R.debug?.("learnCard.store.Ceramic.uploadEncrypted"),O(D,{encrypt:!0,controllersCanDecrypt:!0,...P?{recipients:P.recipients}:{}}))},read:{get:async(R,D)=>{if(R.debug?.("learnCard.read.Ceramic.get"),!D)return;let P=await t2.spa(D);if(!P.success)return;let J=P.data.split(":")[2];try{return await Il.or(e2).parseAsync(await S(J))}catch(L){R.debug?.(L);return}}},methods:{publishContentToCeramic:async(R,D,P)=>Q0(await x(D,{},{},P)),readContentFromCeramic:async(R,D)=>S(D),getCeramicClient:()=>n,getDIDObject:()=>n.did}}},"getCeramicPlugin");var YH=ep;
817
+ `):"",this.name="UnsubscriptionError",this.errors=r},"UnsubscriptionErrorImpl")});function nf(t,e){if(t){var r=t.indexOf(e);0<=r&&t.splice(r,1)}}o(nf,"arrRemove");var Js=function(){function t(e){this.initialTeardown=e,this.closed=!1,this._parentage=null,this._finalizers=null}return o(t,"Subscription"),t.prototype.unsubscribe=function(){var e,r,n,i,a;if(!this.closed){this.closed=!0;var c=this._parentage;if(c)if(this._parentage=null,Array.isArray(c))try{for(var u=os(c),m=u.next();!m.done;m=u.next()){var v=m.value;v.remove(this)}}catch(P){e={error:P}}finally{try{m&&!m.done&&(r=u.return)&&r.call(u)}finally{if(e)throw e.error}}else c.remove(this);var x=this.initialTeardown;if(At(x))try{x()}catch(P){a=P instanceof v0?P.errors:[P]}var S=this._finalizers;if(S){this._finalizers=null;try{for(var O=os(S),R=O.next();!R.done;R=O.next()){var D=R.value;try{S_(D)}catch(P){a=a??[],P instanceof v0?a=Vi(Vi([],Kn(a)),Kn(P.errors)):a.push(P)}}}catch(P){n={error:P}}finally{try{R&&!R.done&&(i=O.return)&&i.call(O)}finally{if(n)throw n.error}}}if(a)throw new v0(a)}},t.prototype.add=function(e){var r;if(e&&e!==this)if(this.closed)S_(e);else{if(e instanceof t){if(e.closed||e._hasParent(this))return;e._addParent(this)}(this._finalizers=(r=this._finalizers)!==null&&r!==void 0?r:[]).push(e)}},t.prototype._hasParent=function(e){var r=this._parentage;return r===e||Array.isArray(r)&&r.includes(e)},t.prototype._addParent=function(e){var r=this._parentage;this._parentage=Array.isArray(r)?(r.push(e),r):r?[r,e]:e},t.prototype._removeParent=function(e){var r=this._parentage;r===e?this._parentage=null:Array.isArray(r)&&nf(r,e)},t.prototype.remove=function(e){var r=this._finalizers;r&&nf(r,e),e instanceof t&&e._removeParent(this)},t.EMPTY=function(){var e=new t;return e.closed=!0,e}(),t}();var gg=Js.EMPTY;function y0(t){return t instanceof Js||t&&"closed"in t&&At(t.remove)&&At(t.add)&&At(t.unsubscribe)}o(y0,"isSubscription");function S_(t){At(t)?t():t.unsubscribe()}o(S_,"execFinalizer");var Wi={onUnhandledError:null,onStoppedNotification:null,Promise:void 0,useDeprecatedSynchronousErrorHandling:!1,useDeprecatedNextContext:!1};var Ic={setTimeout:function(t,e){for(var r=[],n=2;n<arguments.length;n++)r[n-2]=arguments[n];var i=Ic.delegate;return i?.setTimeout?i.setTimeout.apply(i,Vi([t,e],Kn(r))):setTimeout.apply(void 0,Vi([t,e],Kn(r)))},clearTimeout:function(t){var e=Ic.delegate;return(e?.clearTimeout||clearTimeout)(t)},delegate:void 0};function x0(t){Ic.setTimeout(function(){var e=Wi.onUnhandledError;if(e)e(t);else throw t})}o(x0,"reportUnhandledError");function vg(){}o(vg,"noop");var M_=function(){return yg("C",void 0,void 0)}();function T_(t){return yg("E",void 0,t)}o(T_,"errorNotification");function C_(t){return yg("N",t,void 0)}o(C_,"nextNotification");function yg(t,e,r){return{kind:t,value:e,error:r}}o(yg,"createNotification");var of=null;function Dc(t){if(Wi.useDeprecatedSynchronousErrorHandling){var e=!of;if(e&&(of={errorThrown:!1,error:null}),t(),e){var r=of,n=r.errorThrown,i=r.error;if(of=null,n)throw i}}else t()}o(Dc,"errorContext");function k_(t){Wi.useDeprecatedSynchronousErrorHandling&&of&&(of.errorThrown=!0,of.error=t)}o(k_,"captureError");var ul=function(t){Qr(e,t);function e(r){var n=t.call(this)||this;return n.isStopped=!1,r?(n.destination=r,y0(r)&&r.add(n)):n.destination=y$,n}return o(e,"Subscriber"),e.create=function(r,n,i){return new _0(r,n,i)},e.prototype.next=function(r){this.isStopped?wg(C_(r),this):this._next(r)},e.prototype.error=function(r){this.isStopped?wg(T_(r),this):(this.isStopped=!0,this._error(r))},e.prototype.complete=function(){this.isStopped?wg(M_,this):(this.isStopped=!0,this._complete())},e.prototype.unsubscribe=function(){this.closed||(this.isStopped=!0,t.prototype.unsubscribe.call(this),this.destination=null)},e.prototype._next=function(r){this.destination.next(r)},e.prototype._error=function(r){try{this.destination.error(r)}finally{this.unsubscribe()}},e.prototype._complete=function(){try{this.destination.complete()}finally{this.unsubscribe()}},e}(Js);var b$=Function.prototype.bind;function xg(t,e){return b$.call(t,e)}o(xg,"bind");var g$=function(){function t(e){this.partialObserver=e}return o(t,"ConsumerObserver"),t.prototype.next=function(e){var r=this.partialObserver;if(r.next)try{r.next(e)}catch(n){w0(n)}},t.prototype.error=function(e){var r=this.partialObserver;if(r.error)try{r.error(e)}catch(n){w0(n)}else w0(e)},t.prototype.complete=function(){var e=this.partialObserver;if(e.complete)try{e.complete()}catch(r){w0(r)}},t}(),_0=function(t){Qr(e,t);function e(r,n,i){var a=t.call(this)||this,c;if(At(r)||!r)c={next:r??void 0,error:n??void 0,complete:i??void 0};else{var u;a&&Wi.useDeprecatedNextContext?(u=Object.create(r),u.unsubscribe=function(){return a.unsubscribe()},c={next:r.next&&xg(r.next,u),error:r.error&&xg(r.error,u),complete:r.complete&&xg(r.complete,u)}):c=r}return a.destination=new g$(c),a}return o(e,"SafeSubscriber"),e}(ul);function w0(t){Wi.useDeprecatedSynchronousErrorHandling?k_(t):x0(t)}o(w0,"handleUnhandledError");function v$(t){throw t}o(v$,"defaultErrorHandler");function wg(t,e){var r=Wi.onStoppedNotification;r&&Ic.setTimeout(function(){return r(t,e)})}o(wg,"handleStoppedNotification");var y$={closed:!0,next:vg,error:v$,complete:vg};var Oc=function(){return typeof Symbol=="function"&&Symbol.observable||"@@observable"}();function Rc(t){return t}o(Rc,"identity");function I_(t){return t.length===0?Rc:t.length===1?t[0]:o(function(r){return t.reduce(function(n,i){return i(n)},r)},"piped")}o(I_,"pipeFromArray");var Wt=function(){function t(e){e&&(this._subscribe=e)}return o(t,"Observable"),t.prototype.lift=function(e){var r=new t;return r.source=this,r.operator=e,r},t.prototype.subscribe=function(e,r,n){var i=this,a=w$(e)?e:new _0(e,r,n);return Dc(function(){var c=i,u=c.operator,m=c.source;a.add(u?u.call(a,m):m?i._subscribe(a):i._trySubscribe(a))}),a},t.prototype._trySubscribe=function(e){try{return this._subscribe(e)}catch(r){e.error(r)}},t.prototype.forEach=function(e,r){var n=this;return r=D_(r),new r(function(i,a){var c=new _0({next:function(u){try{e(u)}catch(m){a(m),c.unsubscribe()}},error:a,complete:i});n.subscribe(c)})},t.prototype._subscribe=function(e){var r;return(r=this.source)===null||r===void 0?void 0:r.subscribe(e)},t.prototype[Oc]=function(){return this},t.prototype.pipe=function(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];return I_(e)(this)},t.prototype.toPromise=function(e){var r=this;return e=D_(e),new e(function(n,i){var a;r.subscribe(function(c){return a=c},function(c){return i(c)},function(){return n(a)})})},t.create=function(e){return new t(e)},t}();function D_(t){var e;return(e=t??Wi.Promise)!==null&&e!==void 0?e:Promise}o(D_,"getPromiseCtor");function x$(t){return t&&At(t.next)&&At(t.error)&&At(t.complete)}o(x$,"isObserver");function w$(t){return t&&t instanceof ul||x$(t)&&y0(t)}o(w$,"isSubscriber");function _$(t){return At(t?.lift)}o(_$,"hasLift");function Dr(t){return function(e){if(_$(e))return e.lift(function(r){try{return t(r,this)}catch(n){this.error(n)}});throw new TypeError("Unable to lift unknown Observable type")}}o(Dr,"operate");function Or(t,e,r,n,i){return new E$(t,e,r,n,i)}o(Or,"createOperatorSubscriber");var E$=function(t){Qr(e,t);function e(r,n,i,a,c,u){var m=t.call(this,r)||this;return m.onFinalize=c,m.shouldUnsubscribe=u,m._next=n?function(v){try{n(v)}catch(x){r.error(x)}}:t.prototype._next,m._error=a?function(v){try{a(v)}catch(x){r.error(x)}finally{this.unsubscribe()}}:t.prototype._error,m._complete=i?function(){try{i()}catch(v){r.error(v)}finally{this.unsubscribe()}}:t.prototype._complete,m}return o(e,"OperatorSubscriber"),e.prototype.unsubscribe=function(){var r;if(!this.shouldUnsubscribe||this.shouldUnsubscribe()){var n=this.closed;t.prototype.unsubscribe.call(this),!n&&((r=this.onFinalize)===null||r===void 0||r.call(this))}},e}(ul);var O_=kc(function(t){return o(function(){t(this),this.name="ObjectUnsubscribedError",this.message="object unsubscribed"},"ObjectUnsubscribedErrorImpl")});var _g=function(t){Qr(e,t);function e(){var r=t.call(this)||this;return r.closed=!1,r.currentObservers=null,r.observers=[],r.isStopped=!1,r.hasError=!1,r.thrownError=null,r}return o(e,"Subject"),e.prototype.lift=function(r){var n=new R_(this,this);return n.operator=r,n},e.prototype._throwIfClosed=function(){if(this.closed)throw new O_},e.prototype.next=function(r){var n=this;Dc(function(){var i,a;if(n._throwIfClosed(),!n.isStopped){n.currentObservers||(n.currentObservers=Array.from(n.observers));try{for(var c=os(n.currentObservers),u=c.next();!u.done;u=c.next()){var m=u.value;m.next(r)}}catch(v){i={error:v}}finally{try{u&&!u.done&&(a=c.return)&&a.call(c)}finally{if(i)throw i.error}}}})},e.prototype.error=function(r){var n=this;Dc(function(){if(n._throwIfClosed(),!n.isStopped){n.hasError=n.isStopped=!0,n.thrownError=r;for(var i=n.observers;i.length;)i.shift().error(r)}})},e.prototype.complete=function(){var r=this;Dc(function(){if(r._throwIfClosed(),!r.isStopped){r.isStopped=!0;for(var n=r.observers;n.length;)n.shift().complete()}})},e.prototype.unsubscribe=function(){this.isStopped=this.closed=!0,this.observers=this.currentObservers=null},Object.defineProperty(e.prototype,"observed",{get:function(){var r;return((r=this.observers)===null||r===void 0?void 0:r.length)>0},enumerable:!1,configurable:!0}),e.prototype._trySubscribe=function(r){return this._throwIfClosed(),t.prototype._trySubscribe.call(this,r)},e.prototype._subscribe=function(r){return this._throwIfClosed(),this._checkFinalizedStatuses(r),this._innerSubscribe(r)},e.prototype._innerSubscribe=function(r){var n=this,i=this,a=i.hasError,c=i.isStopped,u=i.observers;return a||c?gg:(this.currentObservers=null,u.push(r),new Js(function(){n.currentObservers=null,nf(u,r)}))},e.prototype._checkFinalizedStatuses=function(r){var n=this,i=n.hasError,a=n.thrownError,c=n.isStopped;i?r.error(a):c&&r.complete()},e.prototype.asObservable=function(){var r=new Wt;return r.source=this,r},e.create=function(r,n){return new R_(r,n)},e}(Wt);var R_=function(t){Qr(e,t);function e(r,n){var i=t.call(this)||this;return i.destination=r,i.source=n,i}return o(e,"AnonymousSubject"),e.prototype.next=function(r){var n,i;(i=(n=this.destination)===null||n===void 0?void 0:n.next)===null||i===void 0||i.call(n,r)},e.prototype.error=function(r){var n,i;(i=(n=this.destination)===null||n===void 0?void 0:n.error)===null||i===void 0||i.call(n,r)},e.prototype.complete=function(){var r,n;(n=(r=this.destination)===null||r===void 0?void 0:r.complete)===null||n===void 0||n.call(r)},e.prototype._subscribe=function(r){var n,i;return(i=(n=this.source)===null||n===void 0?void 0:n.subscribe(r))!==null&&i!==void 0?i:gg},e}(_g);var Eg=function(t){Qr(e,t);function e(r){var n=t.call(this)||this;return n._value=r,n}return o(e,"BehaviorSubject"),Object.defineProperty(e.prototype,"value",{get:function(){return this.getValue()},enumerable:!1,configurable:!0}),e.prototype._subscribe=function(r){var n=t.prototype._subscribe.call(this,r);return!n.closed&&r.next(this._value),n},e.prototype.getValue=function(){var r=this,n=r.hasError,i=r.thrownError,a=r._value;if(n)throw i;return this._throwIfClosed(),a},e.prototype.next=function(r){t.prototype.next.call(this,this._value=r)},e}(_g);var Ag={now:function(){return(Ag.delegate||Date).now()},delegate:void 0};var N_=function(t){Qr(e,t);function e(r,n){return t.call(this)||this}return o(e,"Action"),e.prototype.schedule=function(r,n){return n===void 0&&(n=0),this},e}(Js);var ll={setInterval:function(t,e){for(var r=[],n=2;n<arguments.length;n++)r[n-2]=arguments[n];var i=ll.delegate;return i?.setInterval?i.setInterval.apply(i,Vi([t,e],Kn(r))):setInterval.apply(void 0,Vi([t,e],Kn(r)))},clearInterval:function(t){var e=ll.delegate;return(e?.clearInterval||clearInterval)(t)},delegate:void 0};var P_=function(t){Qr(e,t);function e(r,n){var i=t.call(this,r,n)||this;return i.scheduler=r,i.work=n,i.pending=!1,i}return o(e,"AsyncAction"),e.prototype.schedule=function(r,n){var i;if(n===void 0&&(n=0),this.closed)return this;this.state=r;var a=this.id,c=this.scheduler;return a!=null&&(this.id=this.recycleAsyncId(c,a,n)),this.pending=!0,this.delay=n,this.id=(i=this.id)!==null&&i!==void 0?i:this.requestAsyncId(c,this.id,n),this},e.prototype.requestAsyncId=function(r,n,i){return i===void 0&&(i=0),ll.setInterval(r.flush.bind(r,this),i)},e.prototype.recycleAsyncId=function(r,n,i){if(i===void 0&&(i=0),i!=null&&this.delay===i&&this.pending===!1)return n;n!=null&&ll.clearInterval(n)},e.prototype.execute=function(r,n){if(this.closed)return new Error("executing a cancelled action");this.pending=!1;var i=this._execute(r,n);if(i)return i;this.pending===!1&&this.id!=null&&(this.id=this.recycleAsyncId(this.scheduler,this.id,null))},e.prototype._execute=function(r,n){var i=!1,a;try{this.work(r)}catch(c){i=!0,a=c||new Error("Scheduled action threw falsy error")}if(i)return this.unsubscribe(),a},e.prototype.unsubscribe=function(){if(!this.closed){var r=this,n=r.id,i=r.scheduler,a=i.actions;this.work=this.state=this.scheduler=null,this.pending=!1,nf(a,this),n!=null&&(this.id=this.recycleAsyncId(i,n,null)),this.delay=null,t.prototype.unsubscribe.call(this)}},e}(N_);var Sg=function(){function t(e,r){r===void 0&&(r=t.now),this.schedulerActionCtor=e,this.now=r}return o(t,"Scheduler"),t.prototype.schedule=function(e,r,n){return r===void 0&&(r=0),new this.schedulerActionCtor(this,e).schedule(n,r)},t.now=Ag.now,t}();var L_=function(t){Qr(e,t);function e(r,n){n===void 0&&(n=Sg.now);var i=t.call(this,r,n)||this;return i.actions=[],i._active=!1,i}return o(e,"AsyncScheduler"),e.prototype.flush=function(r){var n=this.actions;if(this._active){n.push(r);return}var i;this._active=!0;do if(i=r.execute(r.state,r.delay))break;while(r=n.shift());if(this._active=!1,i){for(;r=n.shift();)r.unsubscribe();throw i}},e}(Sg);var A$=new L_(P_),B_=A$;var E0=new Wt(function(t){return t.complete()});function A0(t){return t&&At(t.schedule)}o(A0,"isScheduler");function U_(t){return t[t.length-1]}o(U_,"last");function $_(t){return A0(U_(t))?t.pop():void 0}o($_,"popScheduler");function F_(t,e){return typeof U_(t)=="number"?t.pop():e}o(F_,"popNumber");var Nc=o(function(t){return t&&typeof t.length=="number"&&typeof t!="function"},"isArrayLike");function S0(t){return At(t?.then)}o(S0,"isPromise");function M0(t){return At(t[Oc])}o(M0,"isInteropObservable");function T0(t){return Symbol.asyncIterator&&At(t?.[Symbol.asyncIterator])}o(T0,"isAsyncIterable");function C0(t){return new TypeError("You provided "+(t!==null&&typeof t=="object"?"an invalid object":"'"+t+"'")+" where a stream was expected. You can provide an Observable, Promise, ReadableStream, Array, AsyncIterable, or Iterable.")}o(C0,"createInvalidObservableTypeError");function S$(){return typeof Symbol!="function"||!Symbol.iterator?"@@iterator":Symbol.iterator}o(S$,"getSymbolIterator");var k0=S$();function I0(t){return At(t?.[k0])}o(I0,"isIterable");function D0(t){return E_(this,arguments,o(function(){var r,n,i,a;return g0(this,function(c){switch(c.label){case 0:r=t.getReader(),c.label=1;case 1:c.trys.push([1,,9,10]),c.label=2;case 2:return[4,rf(r.read())];case 3:return n=c.sent(),i=n.value,a=n.done,a?[4,rf(void 0)]:[3,5];case 4:return[2,c.sent()];case 5:return[4,rf(i)];case 6:return[4,c.sent()];case 7:return c.sent(),[3,2];case 8:return[3,10];case 9:return r.releaseLock(),[7];case 10:return[2]}})},"readableStreamLikeToAsyncGenerator_1"))}o(D0,"readableStreamLikeToAsyncGenerator");function O0(t){return At(t?.getReader)}o(O0,"isReadableStreamLike");function en(t){if(t instanceof Wt)return t;if(t!=null){if(M0(t))return M$(t);if(Nc(t))return T$(t);if(S0(t))return C$(t);if(T0(t))return q_(t);if(I0(t))return k$(t);if(O0(t))return I$(t)}throw C0(t)}o(en,"innerFrom");function M$(t){return new Wt(function(e){var r=t[Oc]();if(At(r.subscribe))return r.subscribe(e);throw new TypeError("Provided object does not correctly implement Symbol.observable")})}o(M$,"fromInteropObservable");function T$(t){return new Wt(function(e){for(var r=0;r<t.length&&!e.closed;r++)e.next(t[r]);e.complete()})}o(T$,"fromArrayLike");function C$(t){return new Wt(function(e){t.then(function(r){e.closed||(e.next(r),e.complete())},function(r){return e.error(r)}).then(null,x0)})}o(C$,"fromPromise");function k$(t){return new Wt(function(e){var r,n;try{for(var i=os(t),a=i.next();!a.done;a=i.next()){var c=a.value;if(e.next(c),e.closed)return}}catch(u){r={error:u}}finally{try{a&&!a.done&&(n=i.return)&&n.call(i)}finally{if(r)throw r.error}}e.complete()})}o(k$,"fromIterable");function q_(t){return new Wt(function(e){D$(t,e).catch(function(r){return e.error(r)})})}o(q_,"fromAsyncIterable");function I$(t){return q_(D0(t))}o(I$,"fromReadableStreamLike");function D$(t,e){var r,n,i,a;return __(this,void 0,void 0,function(){var c,u;return g0(this,function(m){switch(m.label){case 0:m.trys.push([0,5,6,11]),r=A_(t),m.label=1;case 1:return[4,r.next()];case 2:if(n=m.sent(),!!n.done)return[3,4];if(c=n.value,e.next(c),e.closed)return[2];m.label=3;case 3:return[3,1];case 4:return[3,11];case 5:return u=m.sent(),i={error:u},[3,11];case 6:return m.trys.push([6,,9,10]),n&&!n.done&&(a=r.return)?[4,a.call(r)]:[3,8];case 7:m.sent(),m.label=8;case 8:return[3,10];case 9:if(i)throw i.error;return[7];case 10:return[7];case 11:return e.complete(),[2]}})})}o(D$,"process");function Ai(t,e,r,n,i){n===void 0&&(n=0),i===void 0&&(i=!1);var a=e.schedule(function(){r(),i?t.add(this.schedule(null,n)):this.unsubscribe()},n);if(t.add(a),!i)return a}o(Ai,"executeSchedule");function R0(t,e){return e===void 0&&(e=0),Dr(function(r,n){r.subscribe(Or(n,function(i){return Ai(n,t,function(){return n.next(i)},e)},function(){return Ai(n,t,function(){return n.complete()},e)},function(i){return Ai(n,t,function(){return n.error(i)},e)}))})}o(R0,"observeOn");function N0(t,e){return e===void 0&&(e=0),Dr(function(r,n){n.add(t.schedule(function(){return r.subscribe(n)},e))})}o(N0,"subscribeOn");function H_(t,e){return en(t).pipe(N0(e),R0(e))}o(H_,"scheduleObservable");function z_(t,e){return en(t).pipe(N0(e),R0(e))}o(z_,"schedulePromise");function K_(t,e){return new Wt(function(r){var n=0;return e.schedule(function(){n===t.length?r.complete():(r.next(t[n++]),r.closed||this.schedule())})})}o(K_,"scheduleArray");function j_(t,e){return new Wt(function(r){var n;return Ai(r,e,function(){n=t[k0](),Ai(r,e,function(){var i,a,c;try{i=n.next(),a=i.value,c=i.done}catch(u){r.error(u);return}c?r.complete():r.next(a)},0,!0)}),function(){return At(n?.return)&&n.return()}})}o(j_,"scheduleIterable");function P0(t,e){if(!t)throw new Error("Iterable cannot be null");return new Wt(function(r){Ai(r,e,function(){var n=t[Symbol.asyncIterator]();Ai(r,e,function(){n.next().then(function(i){i.done?r.complete():r.next(i.value)})},0,!0)})})}o(P0,"scheduleAsyncIterable");function G_(t,e){return P0(D0(t),e)}o(G_,"scheduleReadableStreamLike");function V_(t,e){if(t!=null){if(M0(t))return H_(t,e);if(Nc(t))return K_(t,e);if(S0(t))return z_(t,e);if(T0(t))return P0(t,e);if(I0(t))return j_(t,e);if(O0(t))return G_(t,e)}throw C0(t)}o(V_,"scheduled");function W_(t,e){return e?V_(t,e):en(t)}o(W_,"from");var L0=kc(function(t){return o(function(){t(this),this.name="EmptyError",this.message="no elements in sequence"},"EmptyErrorImpl")});function J_(t){return t instanceof Date&&!isNaN(t)}o(J_,"isValidDate");function B0(t,e){return Dr(function(r,n){var i=0;r.subscribe(Or(n,function(a){n.next(t.call(e,a,i++))}))})}o(B0,"map");var O$=Array.isArray;function R$(t,e){return O$(e)?t.apply(void 0,Vi([],Kn(e))):t(e)}o(R$,"callOrApply");function Y_(t){return B0(function(e){return R$(t,e)})}o(Y_,"mapOneOrManyArgs");function X_(t,e,r,n,i,a,c,u){var m=[],v=0,x=0,S=!1,O=o(function(){S&&!m.length&&!v&&e.complete()},"checkComplete"),R=o(function(P){return v<n?D(P):m.push(P)},"outerNext"),D=o(function(P){a&&e.next(P),v++;var J=!1;en(r(P,x++)).subscribe(Or(e,function(L){i?.(L),a?R(L):e.next(L)},function(){J=!0},void 0,function(){if(J)try{v--;for(var L=o(function(){var W=m.shift();c?Ai(e,c,function(){return D(W)}):D(W)},"_loop_1");m.length&&v<n;)L();O()}catch(W){e.error(W)}}))},"doInnerSub");return t.subscribe(Or(e,R,function(){S=!0,O()})),function(){u?.()}}o(X_,"mergeInternals");function hl(t,e,r){return r===void 0&&(r=1/0),At(e)?hl(function(n,i){return B0(function(a,c){return e(n,a,i,c)})(en(t(n,i)))},r):(typeof e=="number"&&(r=e),Dr(function(n,i){return X_(n,i,t,r)}))}o(hl,"mergeMap");function Z_(t){return t===void 0&&(t=1/0),hl(Rc,t)}o(Z_,"mergeAll");var N$=["addListener","removeListener"],P$=["addEventListener","removeEventListener"],L$=["on","off"];function dl(t,e,r,n){if(At(r)&&(n=r,r=void 0),n)return dl(t,e,r).pipe(Y_(n));var i=Kn($$(t)?P$.map(function(u){return function(m){return t[u](e,m,r)}}):B$(t)?N$.map(Q_(t,e)):U$(t)?L$.map(Q_(t,e)):[],2),a=i[0],c=i[1];if(!a&&Nc(t))return hl(function(u){return dl(u,e,r)})(en(t));if(!a)throw new TypeError("Invalid event target");return new Wt(function(u){var m=o(function(){for(var v=[],x=0;x<arguments.length;x++)v[x]=arguments[x];return u.next(1<v.length?v:v[0])},"handler");return a(m),function(){return c(m)}})}o(dl,"fromEvent");function Q_(t,e){return function(r){return function(n){return t[r](e,n)}}}o(Q_,"toCommonHandlerRegistry");function B$(t){return At(t.addListener)&&At(t.removeListener)}o(B$,"isNodeStyleEventEmitter");function U$(t){return At(t.on)&&At(t.off)}o(U$,"isJQueryStyleEventEmitter");function $$(t){return At(t.addEventListener)&&At(t.removeEventListener)}o($$,"isEventTarget");function pl(t,e,r){t===void 0&&(t=0),r===void 0&&(r=B_);var n=-1;return e!=null&&(A0(e)?r=e:n=e),new Wt(function(i){var a=J_(t)?+t-r.now():t;a<0&&(a=0);var c=0;return r.schedule(function(){i.closed||(i.next(c++),0<=n?this.schedule(void 0,n):i.complete())},a)})}o(pl,"timer");function Mg(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var r=$_(t),n=F_(t,1/0),i=t;return i.length?i.length===1?en(i[0]):Z_(n)(W_(i,r)):E0}o(Mg,"merge");function eE(t,e){return Dr(function(r,n){var i=0;r.subscribe(Or(n,function(a){return t.call(e,a,i++)&&n.next(a)}))})}o(eE,"filter");function tE(t){return Dr(function(e,r){var n=!1;e.subscribe(Or(r,function(i){n=!0,r.next(i)},function(){n||r.next(t),r.complete()}))})}o(tE,"defaultIfEmpty");function rE(t){return t<=0?function(){return E0}:Dr(function(e,r){var n=0;e.subscribe(Or(r,function(i){++n<=t&&(r.next(i),t<=n&&r.complete())}))})}o(rE,"take");function nE(t){return t===void 0&&(t=F$),Dr(function(e,r){var n=!1;e.subscribe(Or(r,function(i){n=!0,r.next(i)},function(){return n?r.complete():r.error(t())}))})}o(nE,"throwIfEmpty");function F$(){return new L0}o(F$,"defaultErrorFactory");function Tg(t,e){var r=arguments.length>=2;return function(n){return n.pipe(t?eE(function(i,a){return t(i,a,n)}):Rc,rE(1),r?tE(e):nE(function(){return new L0}))}}o(Tg,"first");function Cg(t,e){return Dr(function(r,n){var i=e??{},a=i.leading,c=a===void 0?!0:a,u=i.trailing,m=u===void 0?!1:u,v=!1,x=null,S=null,O=!1,R=o(function(){S?.unsubscribe(),S=null,m&&(J(),O&&n.complete())},"endThrottling"),D=o(function(){S=null,O&&n.complete()},"cleanupThrottling"),P=o(function(L){return S=en(t(L)).subscribe(Or(n,R,D))},"startThrottle"),J=o(function(){if(v){v=!1;var L=x;x=null,n.next(L),!O&&P(L)}},"send");r.subscribe(Or(n,function(L){v=!0,x=L,!(S&&!S.closed)&&(c?J():P(L))},function(){O=!0,!(m&&v&&S&&!S.closed)&&n.complete()}))})}o(Cg,"throttle");var iE;(function(t){t[t.GENESIS=0]="GENESIS",t[t.PARTIAL=1]="PARTIAL",t[t.SIGNED=2]="SIGNED"})(iE||(iE={}));var ml;(function(t){t[t.NOT_REQUESTED=0]="NOT_REQUESTED",t[t.PENDING=1]="PENDING",t[t.PROCESSING=2]="PROCESSING",t[t.ANCHORED=3]="ANCHORED",t[t.FAILED=4]="FAILED"})(ml||(ml={}));var Ig;(function(t){t[t.GENESIS=0]="GENESIS",t[t.SIGNED=1]="SIGNED",t[t.ANCHOR=2]="ANCHOR"})(Ig||(Ig={}));var ss=class extends Wt{constructor(e,r){super(n=>{e.subscribe(n)}),this.state$=e,this._context=r}get id(){return new rt(this.state$.value.type,this.state$.value.log[0].cid)}get api(){return this._context.api}get content(){let{next:e,content:r}=this.state$.value;return(0,kg.default)(e?.content??r)}get tip(){return this.state$.value.log[this.state$.value.log.length-1].cid}get commitId(){return Pt.make(this.id,this.tip)}get allCommitIds(){return this.state$.value.log.map(({cid:e})=>Pt.make(this.id,e))}get anchorCommitIds(){return this.state$.value.log.filter(({type:e})=>e===Ig.ANCHOR).map(({cid:e})=>Pt.make(this.id,e))}get state(){return(0,kg.default)(this.state$.value)}async sync(e={}){e={sync:yr.PREFER_CACHE,...e};let r=await this.api.loadStream(this.id,e);this.state$.next(r.state)}async requestAnchor(){return this.api.requestAnchor(this.id)}};o(ss,"Stream");function Pc(){return t=>{}}o(Pc,"StreamStatic");var uE=Lt(aE(),1);function fE(t){let e=new AbortController;if(t.length===0)throw Error("Need abort signals to create a merged abort signal");return t.some(r=>r.aborted)?(e.abort(),e.signal):(Mg(...t.map(r=>dl(r,"abort"))).pipe(Tg()).subscribe(()=>{e.abort()}),e.signal)}o(fE,"mergeAbortSignals");var bl=class{constructor(e){let r=new AbortController;if(this.signal=r.signal,e<=0){r.abort();return}this._subscription=pl(e).subscribe(()=>{r.abort()})}clear(){this._subscription?.unsubscribe()}};o(bl,"TimedAbortSignal");async function cE(t,e){let r=new AbortController,n=o(()=>{r.abort()},"onAbort");return t.addEventListener("abort",n),t.aborted&&r.abort(),e(r.signal).finally(()=>{t.removeEventListener("abort",n)})}o(cE,"abortable");var q$=60*1e3*3;async function Hr(t,e={}){e.body&&Object.assign(e,{body:JSON.stringify(e.body),headers:{...e.headers,"Content-Type":"application/json"}});let r=e.timeout||q$,n=new bl(r),i=e.signal?fE([e.signal,n.signal]):n.signal,a=await cE(i,c=>(0,uE.default)(String(t),{...e,signal:c})).finally(()=>n.clear());if(!a.ok){let c=await a.text();throw new Error(`HTTP request to '${t}' failed with status '${a.statusText}': ${c}`)}return a.json()}o(Hr,"fetchJson");var gl=Lt(Ac(),1);Pi();function fs(t){let e=We.asCID(t);if(e)return e;if(typeof t=="string")return We.parse(t);if(t instanceof Uint8Array)return We.decode(t);throw new Error(`${t} cannot be converted to a CID`)}o(fs,"toCID");var lE=0,Xt=class{static streamIdFromState(e){return new rt(e.type,e.log[0].cid)}static serializeCommit(e){let r=(0,gl.default)(e);return Xt.isSignedCommitContainer(r)?(r.jws.link=r.jws.link.toString(),r.linkedBlock=kt(r.linkedBlock,"base64"),r.cacaoBlock&&(r.cacaoBlock=kt(r.cacaoBlock,"base64")),r):(Xt.isSignedCommit(e)&&(r.link=r.link.toString()),Xt.isAnchorCommit(e)&&(r.proof=r.proof.toString()),r.id&&(r.id=r.id.toString()),r.prev&&(r.prev=r.prev.toString()),e.header?.model&&(r.header.model=kt(e.header.model,"base64")),r)}static deserializeCommit(e){let r=(0,gl.default)(e);return Xt.isSignedCommitContainer(r)?(r.jws.link=fs(r.jws.link),r.linkedBlock=Ot(r.linkedBlock,"base64"),r.cacaoBlock&&(r.cacaoBlock=Ot(r.cacaoBlock,"base64")),r):(Xt.isSignedCommit(r)&&(r.link=fs(r.link)),Xt.isAnchorCommit(r)&&(r.proof=fs(r.proof)),r.id&&(r.id=fs(r.id)),r.prev&&(r.prev=fs(r.prev)),r.header?.model&&(r.header.model=Ot(r.header.model,"base64")),r)}static serializeState(e){let r=(0,gl.default)(e);return r.log=r.log.map(n=>({...n,cid:n.cid.toString()})),r.anchorStatus!=null&&(r.anchorStatus=ml[r.anchorStatus]),r.anchorProof!=null&&(r.anchorProof.txHash=r.anchorProof.txHash.toString(),r.anchorProof.root=r.anchorProof.root.toString()),e.metadata?.model&&(r.metadata.model=e.metadata.model.toString()),e.next?.metadata?.model&&(r.next.metadata.model=e.next.metadata.model.toString()),e.metadata?.unique&&e.type!=lE&&(r.metadata.unique=kt(r.metadata.unique,"base64")),r.doctype=En.nameByCode(r.type),r}static deserializeState(e){if(!e)return null;let r=(0,gl.default)(e);return r.doctype&&(r.type=En.codeByName(r.doctype),delete r.doctype),r.log=r.log.map(n=>({...n,cid:fs(n.cid)})),r.anchorProof&&(r.anchorProof.txHash=fs(r.anchorProof.txHash),r.anchorProof.root=fs(r.anchorProof.root)),r.anchorStatus&&(r.anchorStatus=ml[r.anchorStatus]),e.metadata?.model&&(r.metadata.model=rt.fromString(e.metadata.model)),e.next?.metadata?.model&&(r.next.metadata.model=rt.fromString(e.next.metadata.model)),e.metadata?.unique&&e.type!=lE&&(r.metadata.unique=Ot(e.metadata.unique,"base64")),r}static statesEqual(e,r){return JSON.stringify(Xt.serializeState(e))===JSON.stringify(Xt.serializeState(r))}static isStateSupersetOf(e,r){if(e.log.length<r.log.length)return!1;for(let n in r.log)if(!e.log[n].cid.equals(r.log[n].cid))return!1;return!(e.log.length===r.log.length&&e.anchorStatus!=r.anchorStatus)}static assertCommitLinksToState(e,r){let n=this.streamIdFromState(e);if(r.id&&!r.id.equals(e.log[0].cid))throw new Error(`Invalid genesis CID in commit for StreamID ${n.toString()}. Found: ${r.id}, expected ${e.log[0].cid}`);let i=e.log[e.log.length-1].cid;if(!r.prev.equals(i))throw new Error(`Commit doesn't properly point to previous commit in log. Expected ${i}, found 'prev' ${r.prev}`)}static async convertCommitToSignedCommitContainer(e,r){if(Xt.isSignedCommit(e)){let n=await r.block.get(e.link);return{jws:e,linkedBlock:n}}return e}static isSignedCommitContainer(e){return e&&e.jws!==void 0}static isSignedCommit(e){return e&&e.link!==void 0}static isAnchorCommit(e){return e&&e.proof!==void 0}static isSignedCommitData(e){return e&&e.envelope!==void 0}static isAnchorCommitData(e){return e&&e.proof!==void 0}};o(Xt,"StreamUtils");var vl=class extends Eg{next(e){let r=this.value;Xt.statesEqual(r,e)||super.next(e)}};o(vl,"StreamStateSubject");var H$=function(t,e,r,n){var i=arguments.length,a=i<3?e:n===null?n=Object.getOwnPropertyDescriptor(e,r):n,c;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")a=Reflect.decorate(t,e,r,n);else for(var u=t.length-1;u>=0;u--)(c=t[u])&&(a=(i<3?c(a):i>3?c(e,r,a):c(e,r))||a);return i>3&&a&&Object.defineProperty(e,r,a),a},jn,Dg={anchor:!0,publish:!0,pin:!0,sync:yr.PREFER_CACHE},z$={sync:yr.PREFER_CACHE},hE={anchor:!0,publish:!0,throwOnInvalidCommit:!0};function Og(t,e){if(typeof t?.schema=="string")try{Pt.fromString(t.schema)}catch{throw new Error("Schema must be a CommitID")}let r={controllers:t?.controllers,family:t?.family,schema:t?.schema?.toString(),tags:t?.tags};if(e)t?.deterministic||(r.unique=kt((0,mE.randomBytes)(12),"base64")),t?.forbidControllerChange&&(r.forbidControllerChange=!0);else{if(t?.deterministic!==void 0||t?.unique!==void 0)throw new Error("Cannot change 'deterministic' or 'unique' properties on existing Streams");if(t?.forbidControllerChange!==void 0)throw new Error("Cannot change 'forbidControllerChange' property on existing Streams")}return Object.keys(r).forEach(n=>r[n]===void 0&&delete r[n]),r}o(Og,"headerFromMetadata");async function dE(t){if(!t.did)throw new Error("No DID provided");return t.did.authenticated||(await t.did.authenticate(),t.loggerProvider&&t.loggerProvider.getDiagnosticsLogger().imp(`Now authenticated as DID ${t.did.id}`)),t.did}o(dE,"getAuthenticatedDID");async function Rg(){throw new Error("Historical stream commits cannot be modified. Load the stream without specifying a commit to make updates.")}o(Rg,"throwReadOnlyError");var Gn=jn=o(class extends ss{constructor(){super(...arguments),this._isReadOnly=!1}get content(){return super.content}get metadata(){let{next:e,metadata:r}=this.state$.value;return(0,pE.default)(e?.metadata??r)}get controllers(){return this.metadata.controllers}static async create(e,r,n,i={}){i={...Dg,...i},!n?.deterministic&&i.syncTimeoutSeconds==null&&(i.syncTimeoutSeconds=0);let a=i.asDID?{did:i.asDID}:e,c=await jn.makeGenesis(a,r,n);return e.createStreamFromGenesis(jn.STREAM_TYPE_ID,c,i)}static async createFromGenesis(e,r,n={}){n={...Dg,...n},r.header?.unique&&n.syncTimeoutSeconds==null&&(n.syncTimeoutSeconds=0);let i=r.data?await jn._signDagJWS(e,r):r;return e.createStreamFromGenesis(jn.STREAM_TYPE_ID,i,n)}static async deterministic(e,r,n={}){if(n={...Dg,...n},r={...r,deterministic:!0},r.family==null&&r.tags==null)throw new Error("Family and/or tags are required when creating a deterministic tile document");let i=await jn.makeGenesis(e,null,r);return e.createStreamFromGenesis(jn.STREAM_TYPE_ID,i,n)}static async load(e,r,n={}){n={...z$,...n};let i=fn.from(r);if(i.type!=jn.STREAM_TYPE_ID)throw new Error(`StreamID ${i.toString()} does not refer to a '${jn.STREAM_TYPE_NAME}' stream, but to a ${i.typeName}`);return e.loadStream(i,n)}async update(e,r,n={}){n={...hE,...n};let i=n.asDID?{did:n.asDID}:this.api,a=await this.makeCommit(i,e,r),c=await this.api.applyCommit(this.id,a,n);this.state$.next(c.state)}async patch(e,r={}){r={...hE,...r};let i={header:Og(this.metadata,!1),data:e,prev:this.tip,id:this.id.cid},a=await jn._signDagJWS(this.api,i),c=await this.api.applyCommit(this.id,a,r);this.state$.next(c.state)}makeReadOnly(){this.update=Rg,this.patch=Rg,this.sync=Rg,this._isReadOnly=!0}get isReadOnly(){return this._isReadOnly}async makeCommit(e,r,n){let i=await this._makeRawCommit(r,n);return jn._signDagJWS(e,i)}async _makeRawCommit(e,r){r||(r={});let n=Og(r,!1);if(e==null&&(e=this.content),n.controllers){if(n.controllers.length!==1)throw new Error("Exactly one controller must be specified");if(!n.controllers[0])throw new Error("Controller cannot be updated to an undefined value.")}let i=i0.compare(this.content,e),a=this.state.log[0];return{header:n,data:i,prev:this.tip,id:a.cid}}static async makeGenesis(e,r,n){if(n||(n={}),!n.controllers||n.controllers.length===0)if(e.did){let c=await dE(e);n.controllers=[c.hasParent?c.parent:c.id]}else throw new Error("No controllers specified");if(n.controllers?.length!==1)throw new Error("Exactly one controller must be specified");let i=Og(n,!0);if(n?.deterministic&&r)throw new Error("Initial content must be null when creating a deterministic Tile document");if(r==null){let c={header:i};return qa(c),c}let a={data:r,header:i};return jn._signDagJWS(e,a)}static async _signDagJWS(e,r){return(await dE(e)).createDagJWS(r)}},"TileDocument");Gn.STREAM_TYPE_NAME="tile";Gn.STREAM_TYPE_ID=0;Gn=jn=H$([Pc()],Gn);var _E=Lt(vE(),1);function Q$(t,e){if(e.has(t))throw new TypeError("Cannot initialize the same private elements twice on an object")}o(Q$,"_checkPrivateRedeclaration");function eF(t,e){return e.get?e.get.call(t):e.value}o(eF,"_classApplyDescriptorGet");function tF(t,e,r){if(e.set)e.set.call(t,r);else{if(!e.writable)throw new TypeError("attempted to set read only private field");e.value=r}}o(tF,"_classApplyDescriptorSet");function wE(t,e,r){if(!e.has(t))throw new TypeError("attempted to "+r+" private field on non-instance");return e.get(t)}o(wE,"_classExtractFieldDescriptor");function Bg(t,e){var r=wE(t,e,"get");return eF(t,r)}o(Bg,"_classPrivateFieldGet");function yE(t,e,r){Q$(t,e),e.set(t,r)}o(yE,"_classPrivateFieldInit");function xE(t,e,r){var n=wE(t,e,"set");return tF(t,n,r),r}o(xE,"_classPrivateFieldSet");function rF(t){return typeof t=="string"||Pt.isInstance(t)||rt.isInstance(t)?{streamId:t}:{streamId:t.streamId,genesis:t.genesis}}o(rF,"keyToQuery");function Ug(t){return typeof t=="string"?fn.from(t).toString():Pt.isInstance(t)||rt.isInstance(t)?t.toString():t.streamId.toString()}o(Ug,"keyToString");async function nF(t){let e=await Gn.makeGenesis({},null,{...t,deterministic:!0}),r=await rt.fromGenesis("tile",e);return{genesis:e,streamId:r}}o(nF,"getDeterministicQuery");var iF=o(()=>Promise.resolve([]),"tempBatchLoadFn"),$0=new WeakMap,$g=new WeakMap,yl=class extends _E.default{cache(e){if(!Bg(this,$g))return!1;let r=e.id.toString();return this.clear(r).prime(r,e),!0}async create(e,r,n){let i=await Gn.create(Bg(this,$0),e,r,n);return this.cache(i),i}async deterministic(e,r){let n=await nF(e);try{return await super.load(n)}catch{let a=await Gn.createFromGenesis(Bg(this,$0),n.genesis,r);return this.cache(a),a}}async load(e){return await super.load(e)}async update(e,r,n,i){let a=Ug(e);this.clear(a);let c=await this.load({streamId:a});return await c.update(r,n,i),c}constructor(e){super(iF,{cache:!0,cacheKeyFn:Ug,cacheMap:e.cache!=null&&typeof e.cache!="boolean"?e.cache:void 0}),yE(this,$0,{writable:!0,value:void 0}),yE(this,$g,{writable:!0,value:void 0}),this._batchLoadFn=async r=>{e.cache||this.clearAll();let n=await e.ceramic.multiQuery(r.map(rF),e.multiqueryTimeout);return r.map(i=>{let a=Ug(i),c=n[a];return c||new Error(`Failed to load stream: ${a}`)})},xE(this,$0,e.ceramic),xE(this,$g,!!e.cache)}};o(yl,"TileLoader");function Fg(t){return typeof t=="string"?rt.fromString(t):t}o(Fg,"typeStreamID");function EE(t,e){let r=new URL(t);for(let[n,i]of Object.entries(e))rt.isInstance(i)?r.searchParams.set(n,i.toString()):typeof i=="object"?r.searchParams.set(n,JSON.stringify(i)):r.searchParams.set(n,i);return r}o(EE,"serializeObjectToSearchParams");function qg(t){let e={};for(let[r,n]of Object.entries(t))rt.isInstance(n)?e[r]=n.toString():e[r]=n;return e}o(qg,"serializeObjectForHttpPost");var tn=class extends Wt{constructor(e,r,n){super(i=>{this.state$.observers.length===0&&(this.periodicSubscription=pl(0,n).pipe(Cg(()=>this._syncState(this.id,{sync:yr.PREFER_CACHE}))).subscribe()),this.state$.subscribe(i).add(()=>{this.state$.observers.length===0&&this.periodicSubscription?.unsubscribe()})}),this.state$=new vl(e),this._apiUrl=new URL(r)}get value(){return this.state$.value}get state(){return this.state$.value}next(e){this.state$.next(e)}async _syncState(e,r){let n=await tn._load(e,this._apiUrl,r);this.state$.next(Xt.deserializeState(n))}get id(){return new rt(this.state$.value.type,this.state$.value.log[0].cid)}static async createFromGenesis(e,r,n,i,a){let c=new URL("./streams",e),{state:u}=await Hr(c,{method:"post",body:{type:r,genesis:Xt.serializeCommit(n),opts:i}});return new tn(Xt.deserializeState(u),e,a)}static async applyCommit(e,r,n,i,a){let c=new URL("./commits",e),{state:u}=await Hr(c,{method:"post",body:{streamId:r.toString(),commit:Xt.serializeCommit(n),opts:i}});return new tn(Xt.deserializeState(u),e,a)}static async _load(e,r,n){let i=EE(new URL(`./streams/${e}`,r),n),{state:a}=await Hr(i);return a}static async load(e,r,n,i){let a=await tn._load(e,r,i);return new tn(Xt.deserializeState(a),r,n)}static async loadStreamCommits(e,r){let n=new URL(`./commits/${e}`,r),{commits:i}=await Hr(n);return i.map(a=>({cid:a.cid,value:Xt.deserializeCommit(a.value)}))}complete(){this.state$.complete()}};o(tn,"Document");var sf;(function(t){t[t.PREFER_CACHE=0]="PREFER_CACHE",t[t.SYNC_ALWAYS=1]="SYNC_ALWAYS",t[t.NEVER_SYNC=2]="NEVER_SYNC",t[t.SYNC_ON_ERROR=3]="SYNC_ON_ERROR"})(sf||(sf={}));var Hg=Lt(Ac(),1);var AE;(function(t){t[t.GENESIS=0]="GENESIS",t[t.PARTIAL=1]="PARTIAL",t[t.SIGNED=2]="SIGNED"})(AE||(AE={}));var zg;(function(t){t[t.GENESIS=0]="GENESIS",t[t.SIGNED=1]="SIGNED",t[t.ANCHOR=2]="ANCHOR"})(zg||(zg={}));var xl=class extends Wt{constructor(e,r){super(n=>{e.subscribe(n)}),this.state$=e,this._context=r}get id(){return new rt(this.state$.value.type,this.state$.value.log[0].cid)}get api(){return this._context.api}get content(){let{next:e,content:r}=this.state$.value;return(0,Hg.default)(e?.content??r)}get tip(){return this.state$.value.log[this.state$.value.log.length-1].cid}get commitId(){return Pt.make(this.id,this.tip)}get allCommitIds(){return this.state$.value.log.map(({cid:e})=>Pt.make(this.id,e))}get anchorCommitIds(){return this.state$.value.log.filter(({type:e})=>e===zg.ANCHOR).map(({cid:e})=>Pt.make(this.id,e))}get state(){return(0,Hg.default)(this.state$.value)}async sync(e={}){e={sync:sf.PREFER_CACHE,...e};let r=await this.api.loadStream(this.id,e);this.state$.next(r.state)}async requestAnchor(){return this.api.requestAnchor(this.id)}};o(xl,"Stream");function SE(){return t=>{}}o(SE,"StreamStatic");function ME(t){if(typeof t=="string"&&t.includes("@")){let[e,r]=t.split("@");if(!e||!r)throw new Error("Invalid accountId provided");return new zs({address:e,chainId:r})}return new zs(t)}o(ME,"normalizeAccountId");var oF="(?:%[0-9a-fA-F]{2})",TE=`(?:[a-zA-Z0-9._-]|${oF})`,sF="([a-z0-9]+)",aF=`((?:${TE}*:)*(${TE}+))`,CE="[a-zA-Z0-9_.:%-]",fF=`;${CE}+=${CE}*`,cF=`((${fF})*)`,uF="(/[^#?]*)?",lF="([?][^#]*)?",hF="(#.*)?",dF=new RegExp(`^did:${sF}:${aF}${cF}${uF}${lF}${hF}$`);function kE(t){if(t===""||!t)return null;let e=t.match(dF);if(e){let r={did:`did:${e[1]}:${e[2]}`,method:e[1],id:e[2],didUrl:t};if(e[4]){let n=e[4].slice(1).split(";");r.params={};for(let i of n){let a=i.split("=");r.params[a[0]]=a[1]}}return e[6]&&(r.path=e[6]),e[7]&&(r.query=e[7].slice(1)),e[8]&&(r.fragment=e[8].slice(1)),r}return null}o(kE,"parse");var DE=Lt(Ac(),1),pF=function(t,e,r,n){var i=arguments.length,a=i<3?e:n===null?n=Object.getOwnPropertyDescriptor(e,r):n,c;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")a=Reflect.decorate(t,e,r,n);else for(var u=t.length-1;u>=0;u--)(c=t[u])&&(a=(i<3?c(a):i>3?c(e,r,a):c(e,r))||a);return i>3&&a&&Object.defineProperty(e,r,a),a},af,Kg=o(()=>{throw new Error("Historical stream commits cannot be modified. Load the stream without specifying a commit to make updates.")},"throwReadOnlyError"),IE={anchor:!1,publish:!0,sync:sf.PREFER_CACHE},jg={anchor:!0,publish:!0},mF={sync:sf.PREFER_CACHE},ff=af=o(class extends xl{constructor(){super(...arguments),this._isReadOnly=!1}get did(){return this.content}get metadata(){let{next:e,metadata:r}=this.state$.value;return(0,DE.default)(e?.metadata??r)}get controllers(){return this.metadata.controllers}static async fromAccount(e,r,n={}){n={...IE,...n};let i=ME(r),a=af.makeGenesis(i);return af.fromGenesis(e,a,n)}static async fromGenesis(e,r,n={}){return n={...IE,...n},e.createStreamFromGenesis(af.STREAM_TYPE_ID,r,n)}async setDid(e,r,n={}){n={...jg,...n};let i=typeof e=="string"?e.trim():e.id;if(kE(i)?.did!==i)throw new Error(`DID is not valid: '${i}'`);let c=await r.createLink(i);return this.setDidProof(c,n)}async setDidProof(e,r={}){r={...jg,...r};let n=this.makeCommit(e),i=await this.api.applyCommit(this.id,n,r);this.state$.next(i.state)}async clearDid(e,r={}){r={...jg,...r};let n=await e.createLink("");return this.setDidProof(n,r)}static async load(e,r,n={}){n={...mF,...n};let i=fn.from(r);if(i.type!=af.STREAM_TYPE_ID)throw new Error(`StreamID ${i.toString()} does not refer to a '${af.STREAM_TYPE_NAME}' stream, but to a ${i.typeName}`);return e.loadStream(i,n)}static makeGenesis(e){return e.chainId.namespace==="eip155"&&(e.address=e.address.toLowerCase()),{header:{controllers:[`${e.address}@${e.chainId.toString()}`],family:`caip10-${e.chainId.toString()}`}}}makeCommit(e){return{data:e,prev:this.tip,id:this.id.cid}}makeReadOnly(){this.setDidProof=Kg,this.setDid=Kg,this.sync=Kg,this._isReadOnly=!0}get isReadOnly(){return this._isReadOnly}},"Caip10Link");ff.STREAM_TYPE_NAME="caip10-link";ff.STREAM_TYPE_ID=1;ff=af=pF([SE()],ff);Pi();Aa();var d9=Lt(l9(),1),fq=function(t,e,r,n){var i=arguments.length,a=i<3?e:n===null?n=Object.getOwnPropertyDescriptor(e,r):n,c;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")a=Reflect.decorate(t,e,r,n);else for(var u=t.length-1;u>=0;u--)(c=t[u])&&(a=(i<3?c(a):i>3?c(e,r,a):c(e,r))||a);return i>3&&a&&Object.defineProperty(e,r,a),a},yo,cq={sync:yr.PREFER_CACHE};async function h9(t){if(t.did==null)throw new Error("No DID provided");t.did.authenticated||(await t.did.authenticate(),t.loggerProvider&&t.loggerProvider.getDiagnosticsLogger().imp(`Now authenticated as DID ${t.did.id}`))}o(h9,"_ensureAuthenticated");async function uq(){throw new Error("Historical stream commits cannot be modified. Load the stream without specifying a commit to make updates.")}o(uq,"throwReadOnlyError");var Ys=yo=o(class extends ss{constructor(){super(...arguments),this._isReadOnly=!1}get content(){return super.content}get metadata(){return{controller:this.state$.value.metadata.controllers[0],model:yo.MODEL}}static async create(e,r,n){yo.assertComplete(r);let i={publish:!0,anchor:!0,pin:!0,sync:yr.NEVER_SYNC,throwOnInvalidCommit:!0},a=await yo._makeGenesis(e,r,n);return await e.createStreamFromGenesis(yo.STREAM_TYPE_ID,a,i)}static assertComplete(e,r){if(!e.name)throw r?new Error(`Model with StreamID ${r.toString()} is missing a 'name' field`):new Error("Model is missing a 'name' field");if(!e.schema)throw r?new Error(`Model ${e.name} (${r.toString()}) is missing a 'schema' field`):new Error(`Model ${e.name} is missing a 'schema' field`);if(!e.accountRelation)throw r?new Error(`Model ${e.name} (${r.toString()}) is missing a 'accountRelation' field`):new Error(`Model ${e.name} is missing a 'accountRelation' field`)}static async load(e,r,n={}){n={...cq,...n};let i=fn.from(r);if(i.type!=yo.STREAM_TYPE_ID)throw new Error(`StreamID ${i.toString()} does not refer to a '${yo.STREAM_TYPE_NAME}' stream, but to a ${i.typeName}`);return await e.loadStream(i,n)}static async _makeGenesis(e,r,n){let i=await this._makeRawGenesis(e,r,n);return yo._signDagJWS(e,i)}static async _makeRawGenesis(e,r,n){if(r==null)throw new Error("Genesis content cannot be null");if(!n||!n.controller)if(e.did)await h9(e),n={controller:e.did.hasParent?e.did.parent:e.did.id};else throw new Error("No controller specified");let i={controllers:[n.controller],model:yo.MODEL.bytes};return{data:r,header:i}}makeReadOnly(){this.sync=uq,this._isReadOnly=!0}get isReadOnly(){return this._isReadOnly}static async _signDagJWS(e,r){return await h9(e),e.did.createDagJWS(r)}},"Model");Ys.STREAM_TYPE_NAME="model";Ys.STREAM_TYPE_ID=2;Ys.MODEL=function(){let t=qa("model-v1"),e=d9.default.encode(t,"identity"),r=qo(fc,e),n=We.createV1(fc,r);return new rt("UNLOADABLE",n)}();Ys=yo=fq([Pc()],Ys);var b9=Lt(Oa(),1);var lq=function(t,e,r,n){var i=arguments.length,a=i<3?e:n===null?n=Object.getOwnPropertyDescriptor(e,r):n,c;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")a=Reflect.decorate(t,e,r,n);else for(var u=t.length-1;u>=0;u--)(c=t[u])&&(a=(i<3?c(a):i>3?c(e,r,a):c(e,r))||a);return i>3&&a&&Object.defineProperty(e,r,a),a},Ji,hq={anchor:!0,publish:!0,pin:!0,sync:yr.NEVER_SYNC,syncTimeoutSeconds:0},dq={anchor:!1,publish:!1,pin:!0,sync:yr.PREFER_CACHE},pq={sync:yr.PREFER_CACHE},p9={anchor:!0,publish:!0,throwOnInvalidCommit:!0};async function m9(t){if(t.did==null)throw new Error("No DID provided");t.did.authenticated||(await t.did.authenticate(),t.loggerProvider&&t.loggerProvider.getDiagnosticsLogger().imp(`Now authenticated as DID ${t.did.id}`))}o(m9,"_ensureAuthenticated");async function Wg(){throw new Error("Historical stream commits cannot be modified. Load the stream without specifying a commit to make updates.")}o(Wg,"throwReadOnlyError");var uf=Ji=o(class extends ss{constructor(){super(...arguments),this._isReadOnly=!1}get content(){return super.content}get metadata(){let e=this.state$.value.metadata;return{controller:e.controllers[0],model:e.model}}static async create(e,r,n,i={}){i={...hq,...i};let a=i.asDID?{did:i.asDID}:e,c=await Ji._makeGenesis(a,r,n);return e.createStreamFromGenesis(Ji.STREAM_TYPE_ID,c,i)}static async single(e,r,n={}){n={...dq,...n};let i=n.asDID?{did:n.asDID}:e;r={...r,deterministic:!0};let a=await Ji._makeGenesis(i,null,r);return e.createStreamFromGenesis(Ji.STREAM_TYPE_ID,a,n)}static async load(e,r,n={}){n={...pq,...n};let i=fn.from(r);if(i.type!=Ji.STREAM_TYPE_ID)throw new Error(`StreamID ${i.toString()} does not refer to a '${Ji.STREAM_TYPE_NAME}' stream, but to a ${i.typeName}`);return e.loadStream(i,n)}async replace(e,r={}){r={...p9,...r};let n=r.asDID?{did:r.asDID}:this.api,i=await this._makeCommit(n,e),a=await this.api.applyCommit(this.id,i,r);this.state$.next(a.state)}async patch(e,r={}){r={...p9,...r};let n={data:e,prev:this.tip,id:this.id.cid},i=await Ji._signDagJWS(this.api,n),a=await this.api.applyCommit(this.id,i,r);this.state$.next(a.state)}makeReadOnly(){this.replace=Wg,this.patch=Wg,this.sync=Wg,this._isReadOnly=!0}get isReadOnly(){return this._isReadOnly}_makeCommit(e,r){let n=this._makeRawCommit(r);return Ji._signDagJWS(e,n)}_makeRawCommit(e){return{data:i0.compare(this.content,e||{}),prev:this.tip,id:this.state.log[0].cid}}static async _makeGenesis(e,r,n){let i=await this._makeRawGenesis(e,r,n);return n.deterministic?(qa(i),i):Ji._signDagJWS(e,i)}static async _makeRawGenesis(e,r,n){if(!n.model)throw new Error("Must specify a 'model' when creating a ModelInstanceDocument");let i=n.controller;if(!i)if(e.did)await m9(e),i=e.did.hasParent?e.did.parent:e.did.id;else throw new Error("No controller specified");let a={controllers:[i],model:n.model.bytes};return n.deterministic||(a.unique=(0,b9.randomBytes)(12)),{data:r,header:a}}static async _signDagJWS(e,r){return await m9(e),e.did.createDagJWS(r)}},"ModelInstanceDocument");uf.STREAM_TYPE_NAME="MID";uf.STREAM_TYPE_ID=3;uf=Ji=lq([Pc()],uf);var El=class{constructor(e){this._apiUrl=e}async add(e,r){let n={};r&&(n.force=!0);let i=new URL(`./pins/${e}`,this._apiUrl);await Hr(i,{method:"post",body:n})}async rm(e,r){let n=new URL(`./pins/${e}`,this._apiUrl);await Hr(n,{method:"delete",body:{opts:r}})}async ls(e){let r=new URL("./pins",this._apiUrl);e&&(r=new URL(`./pins/${e.toString()}`,this._apiUrl));let n=await Hr(r),{pinnedStreamIds:i}=n;return{[Symbol.asyncIterator](){let a=0;return{next(){return a===i.length?Promise.resolve({value:null,done:!0}):Promise.resolve({value:i[a++],done:!1})}}}}}};o(El,"RemotePinApi");var Al=class{constructor(e){this._fetchJson=Hr,this._collectionURL=new URL("./collection",e),this._countURL=new URL("./collection/count",e)}async count(e){return(await this._fetchJson(this._countURL,{method:"POST",body:qg(e)})).count}async query(e){let r=await this._fetchJson(this._collectionURL,{method:"POST",body:qg(e)});return{edges:r.edges.map(i=>({cursor:i.cursor,node:Xt.deserializeState(i.node)})),pageInfo:r.pageInfo}}};o(Al,"RemoteIndexApi");var Sl=class{constructor(e,r){this._apiUrl=e,this._getDidFn=r,this._fetchJson=Hr,this.modelsPath="./admin/models",this.getCodePath="./admin/getCode"}getCodeUrl(){return new URL(this.getCodePath,this._apiUrl)}getModelsUrl(){return new URL(this.modelsPath,this._apiUrl)}async buildJWS(e,r,n){let i=n?{models:n.map(c=>c.toString())}:void 0,a=await e.createJWS({code:r,requestPath:this.getModelsUrl().pathname,requestBody:i});return`${a.signatures[0].protected}.${a.payload}.${a.signatures[0].signature}`}async generateCode(){return(await this._fetchJson(this.getCodeUrl())).code}async startIndexingModels(e){let r=await this.generateCode();await this._fetchJson(this.getModelsUrl(),{method:"post",body:{jws:await this.buildJWS(this._getDidFn(),r,e)}})}async getIndexedModels(){let e=await this.generateCode();return(await this._fetchJson(this.getModelsUrl(),{headers:{Authorization:`Basic ${await this.buildJWS(this._getDidFn(),e)}`}})).models.map(n=>rt.fromString(n))}async stopIndexingModels(e){let r=await this.generateCode();await this._fetchJson(this.getModelsUrl(),{method:"delete",body:{jws:await this.buildJWS(this._getDidFn(),r,e)}})}};o(Sl,"RemoteAdminApi");var mq="/api/v0/",bq="http://localhost:7007",gq={syncInterval:5e3},vq={anchor:!0,publish:!0,sync:yr.PREFER_CACHE},yq={anchor:!0,publish:!0,sync:yr.PREFER_CACHE},g9={sync:yr.PREFER_CACHE},Ml=class{constructor(e=bq,r={}){this._config={...gq,...r},this._apiUrl=new URL(mq,e),this._streamCache=new Map,this.context={api:this},this.pin=new El(this._apiUrl),this.index=new Al(this._apiUrl);let n=(()=>this.did).bind(this);this.admin=new Sl(this._apiUrl,n),this._streamConstructors={[ff.STREAM_TYPE_ID]:ff,[Ys.STREAM_TYPE_ID]:Ys,[uf.STREAM_TYPE_ID]:uf,[Gn.STREAM_TYPE_ID]:Gn}}get did(){return this.context.did}set did(e){this.context.did=e}async createStreamFromGenesis(e,r,n={}){n={...yq,...n};let i=await tn.createFromGenesis(this._apiUrl,e,r,n,this._config.syncInterval),a=this._streamCache.get(i.id.toString());return a?(Xt.statesEqual(i.state,a.state)||a.next(i.state),this.buildStreamFromDocument(a)):(this._streamCache.set(i.id.toString(),i),this.buildStreamFromDocument(i))}async loadStream(e,r={}){r={...g9,...r};let n=fn.from(e),i=this._streamCache.get(n.baseID.toString());return i?await i._syncState(n,r):(i=await tn.load(n,this._apiUrl,this._config.syncInterval,r),this._streamCache.set(i.id.toString(),i)),this.buildStreamFromDocument(i)}async multiQuery(e,r){let n=e.map(c=>({...c,streamId:typeof c.streamId=="string"?c.streamId:c.streamId.toString()})),i=new URL("./multiqueries",this._apiUrl),a=await Hr(i,{method:"post",body:{queries:n,timeout:r}});return Object.entries(a).reduce((c,u)=>{let[m,v]=u,x=Xt.deserializeState(v),S=new tn(x,this._apiUrl,this._config.syncInterval);return c[m]=this.buildStreamFromDocument(S),c},{})}loadStreamCommits(e){let r=Fg(e);return tn.loadStreamCommits(r,this._apiUrl)}async applyCommit(e,r,n={}){n={...vq,...n};let i=Fg(e),a=await tn.applyCommit(this._apiUrl,i,r,n,this._config.syncInterval),c=this._streamCache.get(i.toString());return c?(c.next(a.state),this.buildStreamFromDocument(a)):(this._streamCache.set(i.toString(),a),this.buildStreamFromDocument(a))}async requestAnchor(e,r={}){r={...g9,...r};let{anchorStatus:n}=await Hr(`${this._apiUrl}/streams/${e.toString()}/anchor`,{method:"post",body:{opts:r}});return n}addStreamHandler(e){this._streamConstructors[e.name]=e.stream_constructor}buildStreamFromState(e){let r=new tn(e,this._apiUrl,this._config.syncInterval);return this.buildStreamFromDocument(r)}buildStreamFromDocument(e){let r=e.state.type,n=this._streamConstructors[r];if(!n)throw new Error(`Failed to find constructor for stream ${r}`);return new n(e,this.context)}async setDID(e){this.context.did=e}async getSupportedChains(){if(this._supportedChains)return this._supportedChains;let{supportedChains:e}=await Hr(this._apiUrl+"/node/chains");return this._supportedChains=e,e}async close(){Array.from(this._streamCache).map(([,e])=>{e.complete()}),this._streamCache.clear()}};o(Ml,"CeramicClient");var Ut;(function(t){t.assertEqual=i=>i;function e(i){}o(e,"assertIs"),t.assertIs=e;function r(i){throw new Error}o(r,"assertNever"),t.assertNever=r,t.arrayToEnum=i=>{let a={};for(let c of i)a[c]=c;return a},t.getValidEnumValues=i=>{let a=t.objectKeys(i).filter(u=>typeof i[i[u]]!="number"),c={};for(let u of a)c[u]=i[u];return t.objectValues(c)},t.objectValues=i=>t.objectKeys(i).map(function(a){return i[a]}),t.objectKeys=typeof Object.keys=="function"?i=>Object.keys(i):i=>{let a=[];for(let c in i)Object.prototype.hasOwnProperty.call(i,c)&&a.push(c);return a},t.find=(i,a)=>{for(let c of i)if(a(c))return c},t.isInteger=typeof Number.isInteger=="function"?i=>Number.isInteger(i):i=>typeof i=="number"&&isFinite(i)&&Math.floor(i)===i;function n(i,a=" | "){return i.map(c=>typeof c=="string"?`'${c}'`:c).join(a)}o(n,"joinValues"),t.joinValues=n,t.jsonStringifyReplacer=(i,a)=>typeof a=="bigint"?a.toString():a})(Ut||(Ut={}));var Fe=Ut.arrayToEnum(["string","nan","number","integer","float","boolean","date","bigint","symbol","function","undefined","null","array","object","unknown","promise","void","never","map","set"]),Xs=o(t=>{switch(typeof t){case"undefined":return Fe.undefined;case"string":return Fe.string;case"number":return isNaN(t)?Fe.nan:Fe.number;case"boolean":return Fe.boolean;case"function":return Fe.function;case"bigint":return Fe.bigint;case"symbol":return Fe.symbol;case"object":return Array.isArray(t)?Fe.array:t===null?Fe.null:t.then&&typeof t.then=="function"&&t.catch&&typeof t.catch=="function"?Fe.promise:typeof Map<"u"&&t instanceof Map?Fe.map:typeof Set<"u"&&t instanceof Set?Fe.set:typeof Date<"u"&&t instanceof Date?Fe.date:Fe.object;default:return Fe.unknown}},"getParsedType"),Ne=Ut.arrayToEnum(["invalid_type","invalid_literal","custom","invalid_union","invalid_union_discriminator","invalid_enum_value","unrecognized_keys","invalid_arguments","invalid_return_type","invalid_date","invalid_string","too_small","too_big","invalid_intersection_types","not_multiple_of","not_finite"]),xq=o(t=>JSON.stringify(t,null,2).replace(/"([^"]+)":/g,"$1:"),"quotelessJson"),Si=class extends Error{constructor(e){super(),this.issues=[],this.addIssue=n=>{this.issues=[...this.issues,n]},this.addIssues=(n=[])=>{this.issues=[...this.issues,...n]};let r=new.target.prototype;Object.setPrototypeOf?Object.setPrototypeOf(this,r):this.__proto__=r,this.name="ZodError",this.issues=e}get errors(){return this.issues}format(e){let r=e||function(a){return a.message},n={_errors:[]},i=o(a=>{for(let c of a.issues)if(c.code==="invalid_union")c.unionErrors.map(i);else if(c.code==="invalid_return_type")i(c.returnTypeError);else if(c.code==="invalid_arguments")i(c.argumentsError);else if(c.path.length===0)n._errors.push(r(c));else{let u=n,m=0;for(;m<c.path.length;){let v=c.path[m];m===c.path.length-1?(u[v]=u[v]||{_errors:[]},u[v]._errors.push(r(c))):u[v]=u[v]||{_errors:[]},u=u[v],m++}}},"processError");return i(this),n}toString(){return this.message}get message(){return JSON.stringify(this.issues,Ut.jsonStringifyReplacer,2)}get isEmpty(){return this.issues.length===0}flatten(e=r=>r.message){let r={},n=[];for(let i of this.issues)i.path.length>0?(r[i.path[0]]=r[i.path[0]]||[],r[i.path[0]].push(e(i))):n.push(e(i));return{formErrors:n,fieldErrors:r}}get formErrors(){return this.flatten()}};o(Si,"ZodError");Si.create=t=>new Si(t);var Cl=o((t,e)=>{let r;switch(t.code){case Ne.invalid_type:t.received===Fe.undefined?r="Required":r=`Expected ${t.expected}, received ${t.received}`;break;case Ne.invalid_literal:r=`Invalid literal value, expected ${JSON.stringify(t.expected,Ut.jsonStringifyReplacer)}`;break;case Ne.unrecognized_keys:r=`Unrecognized key(s) in object: ${Ut.joinValues(t.keys,", ")}`;break;case Ne.invalid_union:r="Invalid input";break;case Ne.invalid_union_discriminator:r=`Invalid discriminator value. Expected ${Ut.joinValues(t.options)}`;break;case Ne.invalid_enum_value:r=`Invalid enum value. Expected ${Ut.joinValues(t.options)}, received '${t.received}'`;break;case Ne.invalid_arguments:r="Invalid function arguments";break;case Ne.invalid_return_type:r="Invalid function return type";break;case Ne.invalid_date:r="Invalid date";break;case Ne.invalid_string:typeof t.validation=="object"?"startsWith"in t.validation?r=`Invalid input: must start with "${t.validation.startsWith}"`:"endsWith"in t.validation?r=`Invalid input: must end with "${t.validation.endsWith}"`:Ut.assertNever(t.validation):t.validation!=="regex"?r=`Invalid ${t.validation}`:r="Invalid";break;case Ne.too_small:t.type==="array"?r=`Array must contain ${t.exact?"exactly":t.inclusive?"at least":"more than"} ${t.minimum} element(s)`:t.type==="string"?r=`String must contain ${t.exact?"exactly":t.inclusive?"at least":"over"} ${t.minimum} character(s)`:t.type==="number"?r=`Number must be ${t.exact?"exactly equal to ":t.inclusive?"greater than or equal to ":"greater than "}${t.minimum}`:t.type==="date"?r=`Date must be ${t.exact?"exactly equal to ":t.inclusive?"greater than or equal to ":"greater than "}${new Date(t.minimum)}`:r="Invalid input";break;case Ne.too_big:t.type==="array"?r=`Array must contain ${t.exact?"exactly":t.inclusive?"at most":"less than"} ${t.maximum} element(s)`:t.type==="string"?r=`String must contain ${t.exact?"exactly":t.inclusive?"at most":"under"} ${t.maximum} character(s)`:t.type==="number"?r=`Number must be ${t.exact?"exactly":t.inclusive?"less than or equal to":"less than"} ${t.maximum}`:t.type==="date"?r=`Date must be ${t.exact?"exactly":t.inclusive?"smaller than or equal to":"smaller than"} ${new Date(t.maximum)}`:r="Invalid input";break;case Ne.custom:r="Invalid input";break;case Ne.invalid_intersection_types:r="Intersection results could not be merged";break;case Ne.not_multiple_of:r=`Number must be a multiple of ${t.multipleOf}`;break;case Ne.not_finite:r="Number must be finite";break;default:r=e.defaultError,Ut.assertNever(t)}return{message:r}},"errorMap"),w9=Cl;function wq(t){w9=t}o(wq,"setErrorMap");function j0(){return w9}o(j0,"getErrorMap");var G0=o(t=>{let{data:e,path:r,errorMaps:n,issueData:i}=t,a=[...r,...i.path||[]],c={...i,path:a},u="",m=n.filter(v=>!!v).slice().reverse();for(let v of m)u=v(c,{data:e,defaultError:u}).message;return{...i,path:a,message:i.message||u}},"makeIssue"),_q=[];function Ke(t,e){let r=G0({issueData:e,data:t.data,path:t.path,errorMaps:[t.common.contextualErrorMap,t.schemaErrorMap,j0(),Cl].filter(n=>!!n)});t.common.issues.push(r)}o(Ke,"addIssueToContext");var Rr=class{constructor(){this.value="valid"}dirty(){this.value==="valid"&&(this.value="dirty")}abort(){this.value!=="aborted"&&(this.value="aborted")}static mergeArray(e,r){let n=[];for(let i of r){if(i.status==="aborted")return gt;i.status==="dirty"&&e.dirty(),n.push(i.value)}return{status:e.value,value:n}}static async mergeObjectAsync(e,r){let n=[];for(let i of r)n.push({key:await i.key,value:await i.value});return Rr.mergeObjectSync(e,n)}static mergeObjectSync(e,r){let n={};for(let i of r){let{key:a,value:c}=i;if(a.status==="aborted"||c.status==="aborted")return gt;a.status==="dirty"&&e.dirty(),c.status==="dirty"&&e.dirty(),(typeof c.value<"u"||i.alwaysSet)&&(n[a.value]=c.value)}return{status:e.value,value:n}}};o(Rr,"ParseStatus");var gt=Object.freeze({status:"aborted"}),_9=o(t=>({status:"dirty",value:t}),"DIRTY"),rn=o(t=>({status:"valid",value:t}),"OK"),Jg=o(t=>t.status==="aborted","isAborted"),Yg=o(t=>t.status==="dirty","isDirty"),V0=o(t=>t.status==="valid","isValid"),W0=o(t=>typeof Promise!==void 0&&t instanceof Promise,"isAsync"),Rt;(function(t){t.errToObj=e=>typeof e=="string"?{message:e}:e||{},t.toString=e=>typeof e=="string"?e:e?.message})(Rt||(Rt={}));var Vn=class{constructor(e,r,n,i){this.parent=e,this.data=r,this._path=n,this._key=i}get path(){return this._path.concat(this._key)}};o(Vn,"ParseInputLazyPath");var v9=o((t,e)=>{if(V0(e))return{success:!0,data:e.value};{if(!t.common.issues.length)throw new Error("Validation failed but no issues detected.");let r=new Si(t.common.issues);return{success:!1,error:r}}},"handleResult");function Tt(t){if(!t)return{};let{errorMap:e,invalid_type_error:r,required_error:n,description:i}=t;if(e&&(r||n))throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);return e?{errorMap:e,description:i}:{errorMap:o((c,u)=>c.code!=="invalid_type"?{message:u.defaultError}:typeof u.data>"u"?{message:n??u.defaultError}:{message:r??u.defaultError},"customMap"),description:i}}o(Tt,"processCreateParams");var xt=class{constructor(e){this.spa=this.safeParseAsync,this._def=e,this.parse=this.parse.bind(this),this.safeParse=this.safeParse.bind(this),this.parseAsync=this.parseAsync.bind(this),this.safeParseAsync=this.safeParseAsync.bind(this),this.spa=this.spa.bind(this),this.refine=this.refine.bind(this),this.refinement=this.refinement.bind(this),this.superRefine=this.superRefine.bind(this),this.optional=this.optional.bind(this),this.nullable=this.nullable.bind(this),this.nullish=this.nullish.bind(this),this.array=this.array.bind(this),this.promise=this.promise.bind(this),this.or=this.or.bind(this),this.and=this.and.bind(this),this.transform=this.transform.bind(this),this.brand=this.brand.bind(this),this.default=this.default.bind(this),this.catch=this.catch.bind(this),this.describe=this.describe.bind(this),this.pipe=this.pipe.bind(this),this.isNullable=this.isNullable.bind(this),this.isOptional=this.isOptional.bind(this)}get description(){return this._def.description}_getType(e){return Xs(e.data)}_getOrReturnCtx(e,r){return r||{common:e.parent.common,data:e.data,parsedType:Xs(e.data),schemaErrorMap:this._def.errorMap,path:e.path,parent:e.parent}}_processInputParams(e){return{status:new Rr,ctx:{common:e.parent.common,data:e.data,parsedType:Xs(e.data),schemaErrorMap:this._def.errorMap,path:e.path,parent:e.parent}}}_parseSync(e){let r=this._parse(e);if(W0(r))throw new Error("Synchronous parse encountered promise.");return r}_parseAsync(e){let r=this._parse(e);return Promise.resolve(r)}parse(e,r){let n=this.safeParse(e,r);if(n.success)return n.data;throw n.error}safeParse(e,r){var n;let i={common:{issues:[],async:(n=r?.async)!==null&&n!==void 0?n:!1,contextualErrorMap:r?.errorMap},path:r?.path||[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:Xs(e)},a=this._parseSync({data:e,path:i.path,parent:i});return v9(i,a)}async parseAsync(e,r){let n=await this.safeParseAsync(e,r);if(n.success)return n.data;throw n.error}async safeParseAsync(e,r){let n={common:{issues:[],contextualErrorMap:r?.errorMap,async:!0},path:r?.path||[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:Xs(e)},i=this._parse({data:e,path:n.path,parent:n}),a=await(W0(i)?i:Promise.resolve(i));return v9(n,a)}refine(e,r){let n=o(i=>typeof r=="string"||typeof r>"u"?{message:r}:typeof r=="function"?r(i):r,"getIssueProperties");return this._refinement((i,a)=>{let c=e(i),u=o(()=>a.addIssue({code:Ne.custom,...n(i)}),"setError");return typeof Promise<"u"&&c instanceof Promise?c.then(m=>m?!0:(u(),!1)):c?!0:(u(),!1)})}refinement(e,r){return this._refinement((n,i)=>e(n)?!0:(i.addIssue(typeof r=="function"?r(n,i):r),!1))}_refinement(e){return new Mn({schema:this,typeName:pt.ZodEffects,effect:{type:"refinement",refinement:e}})}superRefine(e){return this._refinement(e)}optional(){return Jn.create(this)}nullable(){return Eo.create(this)}nullish(){return this.optional().nullable()}array(){return Sn.create(this)}promise(){return hs.create(this)}or(e){return ra.create([this,e])}and(e){return na.create(this,e)}transform(e){return new Mn({schema:this,typeName:pt.ZodEffects,effect:{type:"transform",transform:e}})}default(e){let r=typeof e=="function"?e:()=>e;return new ca({innerType:this,defaultValue:r,typeName:pt.ZodDefault})}brand(){return new Tl({typeName:pt.ZodBranded,type:this,...Tt(void 0)})}catch(e){let r=typeof e=="function"?e:()=>e;return new mf({innerType:this,defaultValue:r,typeName:pt.ZodCatch})}describe(e){let r=this.constructor;return new r({...this._def,description:e})}pipe(e){return ua.create(this,e)}isOptional(){return this.safeParse(void 0).success}isNullable(){return this.safeParse(null).success}};o(xt,"ZodType");var Eq=/^c[^\s-]{8,}$/i,Aq=/^([a-f0-9]{8}-[a-f0-9]{4}-[1-5][a-f0-9]{3}-[a-f0-9]{4}-[a-f0-9]{12}|00000000-0000-0000-0000-000000000000)$/i,Sq=/^(([^<>()[\]\.,;:\s@\"]+(\.[^<>()[\]\.,;:\s@\"]+)*)|(\".+\"))@(([^<>()[\]\.,;:\s@\"]+\.)+[^<>()[\]\.,;:\s@\"]{2,})$/i,Mq=o(t=>t.precision?t.offset?new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d{${t.precision}}(([+-]\\d{2}:\\d{2})|Z)$`):new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d{${t.precision}}Z$`):t.precision===0?t.offset?new RegExp("^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(([+-]\\d{2}:\\d{2})|Z)$"):new RegExp("^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}Z$"):t.offset?new RegExp("^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?(([+-]\\d{2}:\\d{2})|Z)$"):new RegExp("^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?Z$"),"datetimeRegex"),Mi=class extends xt{constructor(){super(...arguments),this._regex=(e,r,n)=>this.refinement(i=>e.test(i),{validation:r,code:Ne.invalid_string,...Rt.errToObj(n)}),this.nonempty=e=>this.min(1,Rt.errToObj(e)),this.trim=()=>new Mi({...this._def,checks:[...this._def.checks,{kind:"trim"}]})}_parse(e){if(this._def.coerce&&(e.data=String(e.data)),this._getType(e)!==Fe.string){let a=this._getOrReturnCtx(e);return Ke(a,{code:Ne.invalid_type,expected:Fe.string,received:a.parsedType}),gt}let n=new Rr,i;for(let a of this._def.checks)if(a.kind==="min")e.data.length<a.value&&(i=this._getOrReturnCtx(e,i),Ke(i,{code:Ne.too_small,minimum:a.value,type:"string",inclusive:!0,exact:!1,message:a.message}),n.dirty());else if(a.kind==="max")e.data.length>a.value&&(i=this._getOrReturnCtx(e,i),Ke(i,{code:Ne.too_big,maximum:a.value,type:"string",inclusive:!0,exact:!1,message:a.message}),n.dirty());else if(a.kind==="length"){let c=e.data.length>a.value,u=e.data.length<a.value;(c||u)&&(i=this._getOrReturnCtx(e,i),c?Ke(i,{code:Ne.too_big,maximum:a.value,type:"string",inclusive:!0,exact:!0,message:a.message}):u&&Ke(i,{code:Ne.too_small,minimum:a.value,type:"string",inclusive:!0,exact:!0,message:a.message}),n.dirty())}else if(a.kind==="email")Sq.test(e.data)||(i=this._getOrReturnCtx(e,i),Ke(i,{validation:"email",code:Ne.invalid_string,message:a.message}),n.dirty());else if(a.kind==="uuid")Aq.test(e.data)||(i=this._getOrReturnCtx(e,i),Ke(i,{validation:"uuid",code:Ne.invalid_string,message:a.message}),n.dirty());else if(a.kind==="cuid")Eq.test(e.data)||(i=this._getOrReturnCtx(e,i),Ke(i,{validation:"cuid",code:Ne.invalid_string,message:a.message}),n.dirty());else if(a.kind==="url")try{new URL(e.data)}catch{i=this._getOrReturnCtx(e,i),Ke(i,{validation:"url",code:Ne.invalid_string,message:a.message}),n.dirty()}else a.kind==="regex"?(a.regex.lastIndex=0,a.regex.test(e.data)||(i=this._getOrReturnCtx(e,i),Ke(i,{validation:"regex",code:Ne.invalid_string,message:a.message}),n.dirty())):a.kind==="trim"?e.data=e.data.trim():a.kind==="startsWith"?e.data.startsWith(a.value)||(i=this._getOrReturnCtx(e,i),Ke(i,{code:Ne.invalid_string,validation:{startsWith:a.value},message:a.message}),n.dirty()):a.kind==="endsWith"?e.data.endsWith(a.value)||(i=this._getOrReturnCtx(e,i),Ke(i,{code:Ne.invalid_string,validation:{endsWith:a.value},message:a.message}),n.dirty()):a.kind==="datetime"?Mq(a).test(e.data)||(i=this._getOrReturnCtx(e,i),Ke(i,{code:Ne.invalid_string,validation:"datetime",message:a.message}),n.dirty()):Ut.assertNever(a);return{status:n.value,value:e.data}}_addCheck(e){return new Mi({...this._def,checks:[...this._def.checks,e]})}email(e){return this._addCheck({kind:"email",...Rt.errToObj(e)})}url(e){return this._addCheck({kind:"url",...Rt.errToObj(e)})}uuid(e){return this._addCheck({kind:"uuid",...Rt.errToObj(e)})}cuid(e){return this._addCheck({kind:"cuid",...Rt.errToObj(e)})}datetime(e){var r;return typeof e=="string"?this._addCheck({kind:"datetime",precision:null,offset:!1,message:e}):this._addCheck({kind:"datetime",precision:typeof e?.precision>"u"?null:e?.precision,offset:(r=e?.offset)!==null&&r!==void 0?r:!1,...Rt.errToObj(e?.message)})}regex(e,r){return this._addCheck({kind:"regex",regex:e,...Rt.errToObj(r)})}startsWith(e,r){return this._addCheck({kind:"startsWith",value:e,...Rt.errToObj(r)})}endsWith(e,r){return this._addCheck({kind:"endsWith",value:e,...Rt.errToObj(r)})}min(e,r){return this._addCheck({kind:"min",value:e,...Rt.errToObj(r)})}max(e,r){return this._addCheck({kind:"max",value:e,...Rt.errToObj(r)})}length(e,r){return this._addCheck({kind:"length",value:e,...Rt.errToObj(r)})}get isDatetime(){return!!this._def.checks.find(e=>e.kind==="datetime")}get isEmail(){return!!this._def.checks.find(e=>e.kind==="email")}get isURL(){return!!this._def.checks.find(e=>e.kind==="url")}get isUUID(){return!!this._def.checks.find(e=>e.kind==="uuid")}get isCUID(){return!!this._def.checks.find(e=>e.kind==="cuid")}get minLength(){let e=null;for(let r of this._def.checks)r.kind==="min"&&(e===null||r.value>e)&&(e=r.value);return e}get maxLength(){let e=null;for(let r of this._def.checks)r.kind==="max"&&(e===null||r.value<e)&&(e=r.value);return e}};o(Mi,"ZodString");Mi.create=t=>{var e;return new Mi({checks:[],typeName:pt.ZodString,coerce:(e=t?.coerce)!==null&&e!==void 0?e:!1,...Tt(t)})};function Tq(t,e){let r=(t.toString().split(".")[1]||"").length,n=(e.toString().split(".")[1]||"").length,i=r>n?r:n,a=parseInt(t.toFixed(i).replace(".","")),c=parseInt(e.toFixed(i).replace(".",""));return a%c/Math.pow(10,i)}o(Tq,"floatSafeRemainder");var Yi=class extends xt{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte,this.step=this.multipleOf}_parse(e){if(this._def.coerce&&(e.data=Number(e.data)),this._getType(e)!==Fe.number){let a=this._getOrReturnCtx(e);return Ke(a,{code:Ne.invalid_type,expected:Fe.number,received:a.parsedType}),gt}let n,i=new Rr;for(let a of this._def.checks)a.kind==="int"?Ut.isInteger(e.data)||(n=this._getOrReturnCtx(e,n),Ke(n,{code:Ne.invalid_type,expected:"integer",received:"float",message:a.message}),i.dirty()):a.kind==="min"?(a.inclusive?e.data<a.value:e.data<=a.value)&&(n=this._getOrReturnCtx(e,n),Ke(n,{code:Ne.too_small,minimum:a.value,type:"number",inclusive:a.inclusive,exact:!1,message:a.message}),i.dirty()):a.kind==="max"?(a.inclusive?e.data>a.value:e.data>=a.value)&&(n=this._getOrReturnCtx(e,n),Ke(n,{code:Ne.too_big,maximum:a.value,type:"number",inclusive:a.inclusive,exact:!1,message:a.message}),i.dirty()):a.kind==="multipleOf"?Tq(e.data,a.value)!==0&&(n=this._getOrReturnCtx(e,n),Ke(n,{code:Ne.not_multiple_of,multipleOf:a.value,message:a.message}),i.dirty()):a.kind==="finite"?Number.isFinite(e.data)||(n=this._getOrReturnCtx(e,n),Ke(n,{code:Ne.not_finite,message:a.message}),i.dirty()):Ut.assertNever(a);return{status:i.value,value:e.data}}gte(e,r){return this.setLimit("min",e,!0,Rt.toString(r))}gt(e,r){return this.setLimit("min",e,!1,Rt.toString(r))}lte(e,r){return this.setLimit("max",e,!0,Rt.toString(r))}lt(e,r){return this.setLimit("max",e,!1,Rt.toString(r))}setLimit(e,r,n,i){return new Yi({...this._def,checks:[...this._def.checks,{kind:e,value:r,inclusive:n,message:Rt.toString(i)}]})}_addCheck(e){return new Yi({...this._def,checks:[...this._def.checks,e]})}int(e){return this._addCheck({kind:"int",message:Rt.toString(e)})}positive(e){return this._addCheck({kind:"min",value:0,inclusive:!1,message:Rt.toString(e)})}negative(e){return this._addCheck({kind:"max",value:0,inclusive:!1,message:Rt.toString(e)})}nonpositive(e){return this._addCheck({kind:"max",value:0,inclusive:!0,message:Rt.toString(e)})}nonnegative(e){return this._addCheck({kind:"min",value:0,inclusive:!0,message:Rt.toString(e)})}multipleOf(e,r){return this._addCheck({kind:"multipleOf",value:e,message:Rt.toString(r)})}finite(e){return this._addCheck({kind:"finite",message:Rt.toString(e)})}get minValue(){let e=null;for(let r of this._def.checks)r.kind==="min"&&(e===null||r.value>e)&&(e=r.value);return e}get maxValue(){let e=null;for(let r of this._def.checks)r.kind==="max"&&(e===null||r.value<e)&&(e=r.value);return e}get isInt(){return!!this._def.checks.find(e=>e.kind==="int")}};o(Yi,"ZodNumber");Yi.create=t=>new Yi({checks:[],typeName:pt.ZodNumber,coerce:t?.coerce||!1,...Tt(t)});var Zs=class extends xt{_parse(e){if(this._def.coerce&&(e.data=BigInt(e.data)),this._getType(e)!==Fe.bigint){let n=this._getOrReturnCtx(e);return Ke(n,{code:Ne.invalid_type,expected:Fe.bigint,received:n.parsedType}),gt}return rn(e.data)}};o(Zs,"ZodBigInt");Zs.create=t=>{var e;return new Zs({typeName:pt.ZodBigInt,coerce:(e=t?.coerce)!==null&&e!==void 0?e:!1,...Tt(t)})};var Qs=class extends xt{_parse(e){if(this._def.coerce&&(e.data=Boolean(e.data)),this._getType(e)!==Fe.boolean){let n=this._getOrReturnCtx(e);return Ke(n,{code:Ne.invalid_type,expected:Fe.boolean,received:n.parsedType}),gt}return rn(e.data)}};o(Qs,"ZodBoolean");Qs.create=t=>new Qs({typeName:pt.ZodBoolean,coerce:t?.coerce||!1,...Tt(t)});var xo=class extends xt{_parse(e){if(this._def.coerce&&(e.data=new Date(e.data)),this._getType(e)!==Fe.date){let a=this._getOrReturnCtx(e);return Ke(a,{code:Ne.invalid_type,expected:Fe.date,received:a.parsedType}),gt}if(isNaN(e.data.getTime())){let a=this._getOrReturnCtx(e);return Ke(a,{code:Ne.invalid_date}),gt}let n=new Rr,i;for(let a of this._def.checks)a.kind==="min"?e.data.getTime()<a.value&&(i=this._getOrReturnCtx(e,i),Ke(i,{code:Ne.too_small,message:a.message,inclusive:!0,exact:!1,minimum:a.value,type:"date"}),n.dirty()):a.kind==="max"?e.data.getTime()>a.value&&(i=this._getOrReturnCtx(e,i),Ke(i,{code:Ne.too_big,message:a.message,inclusive:!0,exact:!1,maximum:a.value,type:"date"}),n.dirty()):Ut.assertNever(a);return{status:n.value,value:new Date(e.data.getTime())}}_addCheck(e){return new xo({...this._def,checks:[...this._def.checks,e]})}min(e,r){return this._addCheck({kind:"min",value:e.getTime(),message:Rt.toString(r)})}max(e,r){return this._addCheck({kind:"max",value:e.getTime(),message:Rt.toString(r)})}get minDate(){let e=null;for(let r of this._def.checks)r.kind==="min"&&(e===null||r.value>e)&&(e=r.value);return e!=null?new Date(e):null}get maxDate(){let e=null;for(let r of this._def.checks)r.kind==="max"&&(e===null||r.value<e)&&(e=r.value);return e!=null?new Date(e):null}};o(xo,"ZodDate");xo.create=t=>new xo({checks:[],coerce:t?.coerce||!1,typeName:pt.ZodDate,...Tt(t)});var lf=class extends xt{_parse(e){if(this._getType(e)!==Fe.symbol){let n=this._getOrReturnCtx(e);return Ke(n,{code:Ne.invalid_type,expected:Fe.symbol,received:n.parsedType}),gt}return rn(e.data)}};o(lf,"ZodSymbol");lf.create=t=>new lf({typeName:pt.ZodSymbol,...Tt(t)});var ea=class extends xt{_parse(e){if(this._getType(e)!==Fe.undefined){let n=this._getOrReturnCtx(e);return Ke(n,{code:Ne.invalid_type,expected:Fe.undefined,received:n.parsedType}),gt}return rn(e.data)}};o(ea,"ZodUndefined");ea.create=t=>new ea({typeName:pt.ZodUndefined,...Tt(t)});var ta=class extends xt{_parse(e){if(this._getType(e)!==Fe.null){let n=this._getOrReturnCtx(e);return Ke(n,{code:Ne.invalid_type,expected:Fe.null,received:n.parsedType}),gt}return rn(e.data)}};o(ta,"ZodNull");ta.create=t=>new ta({typeName:pt.ZodNull,...Tt(t)});var us=class extends xt{constructor(){super(...arguments),this._any=!0}_parse(e){return rn(e.data)}};o(us,"ZodAny");us.create=t=>new us({typeName:pt.ZodAny,...Tt(t)});var wo=class extends xt{constructor(){super(...arguments),this._unknown=!0}_parse(e){return rn(e.data)}};o(wo,"ZodUnknown");wo.create=t=>new wo({typeName:pt.ZodUnknown,...Tt(t)});var Ti=class extends xt{_parse(e){let r=this._getOrReturnCtx(e);return Ke(r,{code:Ne.invalid_type,expected:Fe.never,received:r.parsedType}),gt}};o(Ti,"ZodNever");Ti.create=t=>new Ti({typeName:pt.ZodNever,...Tt(t)});var hf=class extends xt{_parse(e){if(this._getType(e)!==Fe.undefined){let n=this._getOrReturnCtx(e);return Ke(n,{code:Ne.invalid_type,expected:Fe.void,received:n.parsedType}),gt}return rn(e.data)}};o(hf,"ZodVoid");hf.create=t=>new hf({typeName:pt.ZodVoid,...Tt(t)});var Sn=class extends xt{_parse(e){let{ctx:r,status:n}=this._processInputParams(e),i=this._def;if(r.parsedType!==Fe.array)return Ke(r,{code:Ne.invalid_type,expected:Fe.array,received:r.parsedType}),gt;if(i.exactLength!==null){let c=r.data.length>i.exactLength.value,u=r.data.length<i.exactLength.value;(c||u)&&(Ke(r,{code:c?Ne.too_big:Ne.too_small,minimum:u?i.exactLength.value:void 0,maximum:c?i.exactLength.value:void 0,type:"array",inclusive:!0,exact:!0,message:i.exactLength.message}),n.dirty())}if(i.minLength!==null&&r.data.length<i.minLength.value&&(Ke(r,{code:Ne.too_small,minimum:i.minLength.value,type:"array",inclusive:!0,exact:!1,message:i.minLength.message}),n.dirty()),i.maxLength!==null&&r.data.length>i.maxLength.value&&(Ke(r,{code:Ne.too_big,maximum:i.maxLength.value,type:"array",inclusive:!0,exact:!1,message:i.maxLength.message}),n.dirty()),r.common.async)return Promise.all(r.data.map((c,u)=>i.type._parseAsync(new Vn(r,c,r.path,u)))).then(c=>Rr.mergeArray(n,c));let a=r.data.map((c,u)=>i.type._parseSync(new Vn(r,c,r.path,u)));return Rr.mergeArray(n,a)}get element(){return this._def.type}min(e,r){return new Sn({...this._def,minLength:{value:e,message:Rt.toString(r)}})}max(e,r){return new Sn({...this._def,maxLength:{value:e,message:Rt.toString(r)}})}length(e,r){return new Sn({...this._def,exactLength:{value:e,message:Rt.toString(r)}})}nonempty(e){return this.min(1,e)}};o(Sn,"ZodArray");Sn.create=(t,e)=>new Sn({type:t,minLength:null,maxLength:null,exactLength:null,typeName:pt.ZodArray,...Tt(e)});var J0;(function(t){t.mergeShapes=(e,r)=>({...e,...r})})(J0||(J0={}));var y9=o(t=>e=>new er({...t,shape:()=>({...t.shape(),...e})}),"AugmentFactory");function Fc(t){if(t instanceof er){let e={};for(let r in t.shape){let n=t.shape[r];e[r]=Jn.create(Fc(n))}return new er({...t._def,shape:()=>e})}else return t instanceof Sn?Sn.create(Fc(t.element)):t instanceof Jn?Jn.create(Fc(t.unwrap())):t instanceof Eo?Eo.create(Fc(t.unwrap())):t instanceof Wn?Wn.create(t.items.map(e=>Fc(e))):t}o(Fc,"deepPartialify");var er=class extends xt{constructor(){super(...arguments),this._cached=null,this.nonstrict=this.passthrough,this.augment=y9(this._def),this.extend=y9(this._def)}_getCached(){if(this._cached!==null)return this._cached;let e=this._def.shape(),r=Ut.objectKeys(e);return this._cached={shape:e,keys:r}}_parse(e){if(this._getType(e)!==Fe.object){let v=this._getOrReturnCtx(e);return Ke(v,{code:Ne.invalid_type,expected:Fe.object,received:v.parsedType}),gt}let{status:n,ctx:i}=this._processInputParams(e),{shape:a,keys:c}=this._getCached(),u=[];if(!(this._def.catchall instanceof Ti&&this._def.unknownKeys==="strip"))for(let v in i.data)c.includes(v)||u.push(v);let m=[];for(let v of c){let x=a[v],S=i.data[v];m.push({key:{status:"valid",value:v},value:x._parse(new Vn(i,S,i.path,v)),alwaysSet:v in i.data})}if(this._def.catchall instanceof Ti){let v=this._def.unknownKeys;if(v==="passthrough")for(let x of u)m.push({key:{status:"valid",value:x},value:{status:"valid",value:i.data[x]}});else if(v==="strict")u.length>0&&(Ke(i,{code:Ne.unrecognized_keys,keys:u}),n.dirty());else if(v!=="strip")throw new Error("Internal ZodObject error: invalid unknownKeys value.")}else{let v=this._def.catchall;for(let x of u){let S=i.data[x];m.push({key:{status:"valid",value:x},value:v._parse(new Vn(i,S,i.path,x)),alwaysSet:x in i.data})}}return i.common.async?Promise.resolve().then(async()=>{let v=[];for(let x of m){let S=await x.key;v.push({key:S,value:await x.value,alwaysSet:x.alwaysSet})}return v}).then(v=>Rr.mergeObjectSync(n,v)):Rr.mergeObjectSync(n,m)}get shape(){return this._def.shape()}strict(e){return Rt.errToObj,new er({...this._def,unknownKeys:"strict",...e!==void 0?{errorMap:(r,n)=>{var i,a,c,u;let m=(c=(a=(i=this._def).errorMap)===null||a===void 0?void 0:a.call(i,r,n).message)!==null&&c!==void 0?c:n.defaultError;return r.code==="unrecognized_keys"?{message:(u=Rt.errToObj(e).message)!==null&&u!==void 0?u:m}:{message:m}}}:{}})}strip(){return new er({...this._def,unknownKeys:"strip"})}passthrough(){return new er({...this._def,unknownKeys:"passthrough"})}setKey(e,r){return this.augment({[e]:r})}merge(e){return new er({unknownKeys:e._def.unknownKeys,catchall:e._def.catchall,shape:()=>J0.mergeShapes(this._def.shape(),e._def.shape()),typeName:pt.ZodObject})}catchall(e){return new er({...this._def,catchall:e})}pick(e){let r={};return Ut.objectKeys(e).map(n=>{this.shape[n]&&(r[n]=this.shape[n])}),new er({...this._def,shape:()=>r})}omit(e){let r={};return Ut.objectKeys(this.shape).map(n=>{Ut.objectKeys(e).indexOf(n)===-1&&(r[n]=this.shape[n])}),new er({...this._def,shape:()=>r})}deepPartial(){return Fc(this)}partial(e){let r={};if(e)return Ut.objectKeys(this.shape).map(n=>{Ut.objectKeys(e).indexOf(n)===-1?r[n]=this.shape[n]:r[n]=this.shape[n].optional()}),new er({...this._def,shape:()=>r});for(let n in this.shape){let i=this.shape[n];r[n]=i.optional()}return new er({...this._def,shape:()=>r})}required(e){let r={};if(e)Ut.objectKeys(this.shape).map(n=>{if(Ut.objectKeys(e).indexOf(n)===-1)r[n]=this.shape[n];else{let a=this.shape[n];for(;a instanceof Jn;)a=a._def.innerType;r[n]=a}});else for(let n in this.shape){let a=this.shape[n];for(;a instanceof Jn;)a=a._def.innerType;r[n]=a}return new er({...this._def,shape:()=>r})}keyof(){return E9(Ut.objectKeys(this.shape))}};o(er,"ZodObject");er.create=(t,e)=>new er({shape:()=>t,unknownKeys:"strip",catchall:Ti.create(),typeName:pt.ZodObject,...Tt(e)});er.strictCreate=(t,e)=>new er({shape:()=>t,unknownKeys:"strict",catchall:Ti.create(),typeName:pt.ZodObject,...Tt(e)});er.lazycreate=(t,e)=>new er({shape:t,unknownKeys:"strip",catchall:Ti.create(),typeName:pt.ZodObject,...Tt(e)});var ra=class extends xt{_parse(e){let{ctx:r}=this._processInputParams(e),n=this._def.options;function i(a){for(let u of a)if(u.result.status==="valid")return u.result;for(let u of a)if(u.result.status==="dirty")return r.common.issues.push(...u.ctx.common.issues),u.result;let c=a.map(u=>new Si(u.ctx.common.issues));return Ke(r,{code:Ne.invalid_union,unionErrors:c}),gt}if(o(i,"handleResults"),r.common.async)return Promise.all(n.map(async a=>{let c={...r,common:{...r.common,issues:[]},parent:null};return{result:await a._parseAsync({data:r.data,path:r.path,parent:c}),ctx:c}})).then(i);{let a,c=[];for(let m of n){let v={...r,common:{...r.common,issues:[]},parent:null},x=m._parseSync({data:r.data,path:r.path,parent:v});if(x.status==="valid")return x;x.status==="dirty"&&!a&&(a={result:x,ctx:v}),v.common.issues.length&&c.push(v.common.issues)}if(a)return r.common.issues.push(...a.ctx.common.issues),a.result;let u=c.map(m=>new Si(m));return Ke(r,{code:Ne.invalid_union,unionErrors:u}),gt}}get options(){return this._def.options}};o(ra,"ZodUnion");ra.create=(t,e)=>new ra({options:t,typeName:pt.ZodUnion,...Tt(e)});var K0=o(t=>t instanceof oa?K0(t.schema):t instanceof Mn?K0(t.innerType()):t instanceof sa?[t.value]:t instanceof aa?t.options:t instanceof fa?Object.keys(t.enum):t instanceof ca?K0(t._def.innerType):t instanceof ea?[void 0]:t instanceof ta?[null]:null,"getDiscriminator"),df=class extends xt{_parse(e){let{ctx:r}=this._processInputParams(e);if(r.parsedType!==Fe.object)return Ke(r,{code:Ne.invalid_type,expected:Fe.object,received:r.parsedType}),gt;let n=this.discriminator,i=r.data[n],a=this.optionsMap.get(i);return a?r.common.async?a._parseAsync({data:r.data,path:r.path,parent:r}):a._parseSync({data:r.data,path:r.path,parent:r}):(Ke(r,{code:Ne.invalid_union_discriminator,options:Array.from(this.optionsMap.keys()),path:[n]}),gt)}get discriminator(){return this._def.discriminator}get options(){return this._def.options}get optionsMap(){return this._def.optionsMap}static create(e,r,n){let i=new Map;for(let a of r){let c=K0(a.shape[e]);if(!c)throw new Error(`A discriminator value for key \`${e}\` could not be extracted from all schema options`);for(let u of c){if(i.has(u))throw new Error(`Discriminator property ${String(e)} has duplicate value ${String(u)}`);i.set(u,a)}}return new df({typeName:pt.ZodDiscriminatedUnion,discriminator:e,options:r,optionsMap:i,...Tt(n)})}};o(df,"ZodDiscriminatedUnion");function Xg(t,e){let r=Xs(t),n=Xs(e);if(t===e)return{valid:!0,data:t};if(r===Fe.object&&n===Fe.object){let i=Ut.objectKeys(e),a=Ut.objectKeys(t).filter(u=>i.indexOf(u)!==-1),c={...t,...e};for(let u of a){let m=Xg(t[u],e[u]);if(!m.valid)return{valid:!1};c[u]=m.data}return{valid:!0,data:c}}else if(r===Fe.array&&n===Fe.array){if(t.length!==e.length)return{valid:!1};let i=[];for(let a=0;a<t.length;a++){let c=t[a],u=e[a],m=Xg(c,u);if(!m.valid)return{valid:!1};i.push(m.data)}return{valid:!0,data:i}}else return r===Fe.date&&n===Fe.date&&+t==+e?{valid:!0,data:t}:{valid:!1}}o(Xg,"mergeValues");var na=class extends xt{_parse(e){let{status:r,ctx:n}=this._processInputParams(e),i=o((a,c)=>{if(Jg(a)||Jg(c))return gt;let u=Xg(a.value,c.value);return u.valid?((Yg(a)||Yg(c))&&r.dirty(),{status:r.value,value:u.data}):(Ke(n,{code:Ne.invalid_intersection_types}),gt)},"handleParsed");return n.common.async?Promise.all([this._def.left._parseAsync({data:n.data,path:n.path,parent:n}),this._def.right._parseAsync({data:n.data,path:n.path,parent:n})]).then(([a,c])=>i(a,c)):i(this._def.left._parseSync({data:n.data,path:n.path,parent:n}),this._def.right._parseSync({data:n.data,path:n.path,parent:n}))}};o(na,"ZodIntersection");na.create=(t,e,r)=>new na({left:t,right:e,typeName:pt.ZodIntersection,...Tt(r)});var Wn=class extends xt{_parse(e){let{status:r,ctx:n}=this._processInputParams(e);if(n.parsedType!==Fe.array)return Ke(n,{code:Ne.invalid_type,expected:Fe.array,received:n.parsedType}),gt;if(n.data.length<this._def.items.length)return Ke(n,{code:Ne.too_small,minimum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),gt;!this._def.rest&&n.data.length>this._def.items.length&&(Ke(n,{code:Ne.too_big,maximum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),r.dirty());let a=n.data.map((c,u)=>{let m=this._def.items[u]||this._def.rest;return m?m._parse(new Vn(n,c,n.path,u)):null}).filter(c=>!!c);return n.common.async?Promise.all(a).then(c=>Rr.mergeArray(r,c)):Rr.mergeArray(r,a)}get items(){return this._def.items}rest(e){return new Wn({...this._def,rest:e})}};o(Wn,"ZodTuple");Wn.create=(t,e)=>{if(!Array.isArray(t))throw new Error("You must pass an array of schemas to z.tuple([ ... ])");return new Wn({items:t,typeName:pt.ZodTuple,rest:null,...Tt(e)})};var ia=class extends xt{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(e){let{status:r,ctx:n}=this._processInputParams(e);if(n.parsedType!==Fe.object)return Ke(n,{code:Ne.invalid_type,expected:Fe.object,received:n.parsedType}),gt;let i=[],a=this._def.keyType,c=this._def.valueType;for(let u in n.data)i.push({key:a._parse(new Vn(n,u,n.path,u)),value:c._parse(new Vn(n,n.data[u],n.path,u))});return n.common.async?Rr.mergeObjectAsync(r,i):Rr.mergeObjectSync(r,i)}get element(){return this._def.valueType}static create(e,r,n){return r instanceof xt?new ia({keyType:e,valueType:r,typeName:pt.ZodRecord,...Tt(n)}):new ia({keyType:Mi.create(),valueType:e,typeName:pt.ZodRecord,...Tt(r)})}};o(ia,"ZodRecord");var pf=class extends xt{_parse(e){let{status:r,ctx:n}=this._processInputParams(e);if(n.parsedType!==Fe.map)return Ke(n,{code:Ne.invalid_type,expected:Fe.map,received:n.parsedType}),gt;let i=this._def.keyType,a=this._def.valueType,c=[...n.data.entries()].map(([u,m],v)=>({key:i._parse(new Vn(n,u,n.path,[v,"key"])),value:a._parse(new Vn(n,m,n.path,[v,"value"]))}));if(n.common.async){let u=new Map;return Promise.resolve().then(async()=>{for(let m of c){let v=await m.key,x=await m.value;if(v.status==="aborted"||x.status==="aborted")return gt;(v.status==="dirty"||x.status==="dirty")&&r.dirty(),u.set(v.value,x.value)}return{status:r.value,value:u}})}else{let u=new Map;for(let m of c){let v=m.key,x=m.value;if(v.status==="aborted"||x.status==="aborted")return gt;(v.status==="dirty"||x.status==="dirty")&&r.dirty(),u.set(v.value,x.value)}return{status:r.value,value:u}}}};o(pf,"ZodMap");pf.create=(t,e,r)=>new pf({valueType:e,keyType:t,typeName:pt.ZodMap,...Tt(r)});var _o=class extends xt{_parse(e){let{status:r,ctx:n}=this._processInputParams(e);if(n.parsedType!==Fe.set)return Ke(n,{code:Ne.invalid_type,expected:Fe.set,received:n.parsedType}),gt;let i=this._def;i.minSize!==null&&n.data.size<i.minSize.value&&(Ke(n,{code:Ne.too_small,minimum:i.minSize.value,type:"set",inclusive:!0,exact:!1,message:i.minSize.message}),r.dirty()),i.maxSize!==null&&n.data.size>i.maxSize.value&&(Ke(n,{code:Ne.too_big,maximum:i.maxSize.value,type:"set",inclusive:!0,exact:!1,message:i.maxSize.message}),r.dirty());let a=this._def.valueType;function c(m){let v=new Set;for(let x of m){if(x.status==="aborted")return gt;x.status==="dirty"&&r.dirty(),v.add(x.value)}return{status:r.value,value:v}}o(c,"finalizeSet");let u=[...n.data.values()].map((m,v)=>a._parse(new Vn(n,m,n.path,v)));return n.common.async?Promise.all(u).then(m=>c(m)):c(u)}min(e,r){return new _o({...this._def,minSize:{value:e,message:Rt.toString(r)}})}max(e,r){return new _o({...this._def,maxSize:{value:e,message:Rt.toString(r)}})}size(e,r){return this.min(e,r).max(e,r)}nonempty(e){return this.min(1,e)}};o(_o,"ZodSet");_o.create=(t,e)=>new _o({valueType:t,minSize:null,maxSize:null,typeName:pt.ZodSet,...Tt(e)});var ls=class extends xt{constructor(){super(...arguments),this.validate=this.implement}_parse(e){let{ctx:r}=this._processInputParams(e);if(r.parsedType!==Fe.function)return Ke(r,{code:Ne.invalid_type,expected:Fe.function,received:r.parsedType}),gt;function n(u,m){return G0({data:u,path:r.path,errorMaps:[r.common.contextualErrorMap,r.schemaErrorMap,j0(),Cl].filter(v=>!!v),issueData:{code:Ne.invalid_arguments,argumentsError:m}})}o(n,"makeArgsIssue");function i(u,m){return G0({data:u,path:r.path,errorMaps:[r.common.contextualErrorMap,r.schemaErrorMap,j0(),Cl].filter(v=>!!v),issueData:{code:Ne.invalid_return_type,returnTypeError:m}})}o(i,"makeReturnsIssue");let a={errorMap:r.common.contextualErrorMap},c=r.data;return this._def.returns instanceof hs?rn(async(...u)=>{let m=new Si([]),v=await this._def.args.parseAsync(u,a).catch(O=>{throw m.addIssue(n(u,O)),m}),x=await c(...v);return await this._def.returns._def.type.parseAsync(x,a).catch(O=>{throw m.addIssue(i(x,O)),m})}):rn((...u)=>{let m=this._def.args.safeParse(u,a);if(!m.success)throw new Si([n(u,m.error)]);let v=c(...m.data),x=this._def.returns.safeParse(v,a);if(!x.success)throw new Si([i(v,x.error)]);return x.data})}parameters(){return this._def.args}returnType(){return this._def.returns}args(...e){return new ls({...this._def,args:Wn.create(e).rest(wo.create())})}returns(e){return new ls({...this._def,returns:e})}implement(e){return this.parse(e)}strictImplement(e){return this.parse(e)}static create(e,r,n){return new ls({args:e||Wn.create([]).rest(wo.create()),returns:r||wo.create(),typeName:pt.ZodFunction,...Tt(n)})}};o(ls,"ZodFunction");var oa=class extends xt{get schema(){return this._def.getter()}_parse(e){let{ctx:r}=this._processInputParams(e);return this._def.getter()._parse({data:r.data,path:r.path,parent:r})}};o(oa,"ZodLazy");oa.create=(t,e)=>new oa({getter:t,typeName:pt.ZodLazy,...Tt(e)});var sa=class extends xt{_parse(e){if(e.data!==this._def.value){let r=this._getOrReturnCtx(e);return Ke(r,{code:Ne.invalid_literal,expected:this._def.value}),gt}return{status:"valid",value:e.data}}get value(){return this._def.value}};o(sa,"ZodLiteral");sa.create=(t,e)=>new sa({value:t,typeName:pt.ZodLiteral,...Tt(e)});function E9(t,e){return new aa({values:t,typeName:pt.ZodEnum,...Tt(e)})}o(E9,"createZodEnum");var aa=class extends xt{_parse(e){if(typeof e.data!="string"){let r=this._getOrReturnCtx(e),n=this._def.values;return Ke(r,{expected:Ut.joinValues(n),received:r.parsedType,code:Ne.invalid_type}),gt}if(this._def.values.indexOf(e.data)===-1){let r=this._getOrReturnCtx(e),n=this._def.values;return Ke(r,{received:r.data,code:Ne.invalid_enum_value,options:n}),gt}return rn(e.data)}get options(){return this._def.values}get enum(){let e={};for(let r of this._def.values)e[r]=r;return e}get Values(){let e={};for(let r of this._def.values)e[r]=r;return e}get Enum(){let e={};for(let r of this._def.values)e[r]=r;return e}};o(aa,"ZodEnum");aa.create=E9;var fa=class extends xt{_parse(e){let r=Ut.getValidEnumValues(this._def.values),n=this._getOrReturnCtx(e);if(n.parsedType!==Fe.string&&n.parsedType!==Fe.number){let i=Ut.objectValues(r);return Ke(n,{expected:Ut.joinValues(i),received:n.parsedType,code:Ne.invalid_type}),gt}if(r.indexOf(e.data)===-1){let i=Ut.objectValues(r);return Ke(n,{received:n.data,code:Ne.invalid_enum_value,options:i}),gt}return rn(e.data)}get enum(){return this._def.values}};o(fa,"ZodNativeEnum");fa.create=(t,e)=>new fa({values:t,typeName:pt.ZodNativeEnum,...Tt(e)});var hs=class extends xt{_parse(e){let{ctx:r}=this._processInputParams(e);if(r.parsedType!==Fe.promise&&r.common.async===!1)return Ke(r,{code:Ne.invalid_type,expected:Fe.promise,received:r.parsedType}),gt;let n=r.parsedType===Fe.promise?r.data:Promise.resolve(r.data);return rn(n.then(i=>this._def.type.parseAsync(i,{path:r.path,errorMap:r.common.contextualErrorMap})))}};o(hs,"ZodPromise");hs.create=(t,e)=>new hs({type:t,typeName:pt.ZodPromise,...Tt(e)});var Mn=class extends xt{innerType(){return this._def.schema}sourceType(){return this._def.schema._def.typeName===pt.ZodEffects?this._def.schema.sourceType():this._def.schema}_parse(e){let{status:r,ctx:n}=this._processInputParams(e),i=this._def.effect||null;if(i.type==="preprocess"){let c=i.transform(n.data);return n.common.async?Promise.resolve(c).then(u=>this._def.schema._parseAsync({data:u,path:n.path,parent:n})):this._def.schema._parseSync({data:c,path:n.path,parent:n})}let a={addIssue:c=>{Ke(n,c),c.fatal?r.abort():r.dirty()},get path(){return n.path}};if(a.addIssue=a.addIssue.bind(a),i.type==="refinement"){let c=o(u=>{let m=i.refinement(u,a);if(n.common.async)return Promise.resolve(m);if(m instanceof Promise)throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");return u},"executeRefinement");if(n.common.async===!1){let u=this._def.schema._parseSync({data:n.data,path:n.path,parent:n});return u.status==="aborted"?gt:(u.status==="dirty"&&r.dirty(),c(u.value),{status:r.value,value:u.value})}else return this._def.schema._parseAsync({data:n.data,path:n.path,parent:n}).then(u=>u.status==="aborted"?gt:(u.status==="dirty"&&r.dirty(),c(u.value).then(()=>({status:r.value,value:u.value}))))}if(i.type==="transform")if(n.common.async===!1){let c=this._def.schema._parseSync({data:n.data,path:n.path,parent:n});if(!V0(c))return c;let u=i.transform(c.value,a);if(u instanceof Promise)throw new Error("Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.");return{status:r.value,value:u}}else return this._def.schema._parseAsync({data:n.data,path:n.path,parent:n}).then(c=>V0(c)?Promise.resolve(i.transform(c.value,a)).then(u=>({status:r.value,value:u})):c);Ut.assertNever(i)}};o(Mn,"ZodEffects");Mn.create=(t,e,r)=>new Mn({schema:t,typeName:pt.ZodEffects,effect:e,...Tt(r)});Mn.createWithPreprocess=(t,e,r)=>new Mn({schema:e,effect:{type:"preprocess",transform:t},typeName:pt.ZodEffects,...Tt(r)});var Jn=class extends xt{_parse(e){return this._getType(e)===Fe.undefined?rn(void 0):this._def.innerType._parse(e)}unwrap(){return this._def.innerType}};o(Jn,"ZodOptional");Jn.create=(t,e)=>new Jn({innerType:t,typeName:pt.ZodOptional,...Tt(e)});var Eo=class extends xt{_parse(e){return this._getType(e)===Fe.null?rn(null):this._def.innerType._parse(e)}unwrap(){return this._def.innerType}};o(Eo,"ZodNullable");Eo.create=(t,e)=>new Eo({innerType:t,typeName:pt.ZodNullable,...Tt(e)});var ca=class extends xt{_parse(e){let{ctx:r}=this._processInputParams(e),n=r.data;return r.parsedType===Fe.undefined&&(n=this._def.defaultValue()),this._def.innerType._parse({data:n,path:r.path,parent:r})}removeDefault(){return this._def.innerType}};o(ca,"ZodDefault");ca.create=(t,e)=>new ca({innerType:t,typeName:pt.ZodDefault,defaultValue:typeof e.default=="function"?e.default:()=>e.default,...Tt(e)});var mf=class extends xt{_parse(e){let{ctx:r}=this._processInputParams(e),n=this._def.innerType._parse({data:r.data,path:r.path,parent:r});return W0(n)?n.then(i=>({status:"valid",value:i.status==="valid"?i.value:this._def.defaultValue()})):{status:"valid",value:n.status==="valid"?n.value:this._def.defaultValue()}}removeDefault(){return this._def.innerType}};o(mf,"ZodCatch");mf.create=(t,e)=>new mf({innerType:t,typeName:pt.ZodCatch,defaultValue:typeof e.default=="function"?e.default:()=>e.default,...Tt(e)});var bf=class extends xt{_parse(e){if(this._getType(e)!==Fe.nan){let n=this._getOrReturnCtx(e);return Ke(n,{code:Ne.invalid_type,expected:Fe.nan,received:n.parsedType}),gt}return{status:"valid",value:e.data}}};o(bf,"ZodNaN");bf.create=t=>new bf({typeName:pt.ZodNaN,...Tt(t)});var Cq=Symbol("zod_brand"),Tl=class extends xt{_parse(e){let{ctx:r}=this._processInputParams(e),n=r.data;return this._def.type._parse({data:n,path:r.path,parent:r})}unwrap(){return this._def.type}};o(Tl,"ZodBranded");var ua=class extends xt{_parse(e){let{status:r,ctx:n}=this._processInputParams(e);if(n.common.async)return o(async()=>{let a=await this._def.in._parseAsync({data:n.data,path:n.path,parent:n});return a.status==="aborted"?gt:a.status==="dirty"?(r.dirty(),_9(a.value)):this._def.out._parseAsync({data:a.value,path:n.path,parent:n})},"handleAsync")();{let i=this._def.in._parseSync({data:n.data,path:n.path,parent:n});return i.status==="aborted"?gt:i.status==="dirty"?(r.dirty(),{status:"dirty",value:i.value}):this._def.out._parseSync({data:i.value,path:n.path,parent:n})}}static create(e,r){return new ua({in:e,out:r,typeName:pt.ZodPipeline})}};o(ua,"ZodPipeline");var A9=o((t,e={},r)=>t?us.create().superRefine((n,i)=>{if(!t(n)){let a=typeof e=="function"?e(n):e,c=typeof a=="string"?{message:a}:a;i.addIssue({code:"custom",...c,fatal:r})}}):us.create(),"custom"),kq={object:er.lazycreate},pt;(function(t){t.ZodString="ZodString",t.ZodNumber="ZodNumber",t.ZodNaN="ZodNaN",t.ZodBigInt="ZodBigInt",t.ZodBoolean="ZodBoolean",t.ZodDate="ZodDate",t.ZodSymbol="ZodSymbol",t.ZodUndefined="ZodUndefined",t.ZodNull="ZodNull",t.ZodAny="ZodAny",t.ZodUnknown="ZodUnknown",t.ZodNever="ZodNever",t.ZodVoid="ZodVoid",t.ZodArray="ZodArray",t.ZodObject="ZodObject",t.ZodUnion="ZodUnion",t.ZodDiscriminatedUnion="ZodDiscriminatedUnion",t.ZodIntersection="ZodIntersection",t.ZodTuple="ZodTuple",t.ZodRecord="ZodRecord",t.ZodMap="ZodMap",t.ZodSet="ZodSet",t.ZodFunction="ZodFunction",t.ZodLazy="ZodLazy",t.ZodLiteral="ZodLiteral",t.ZodEnum="ZodEnum",t.ZodEffects="ZodEffects",t.ZodNativeEnum="ZodNativeEnum",t.ZodOptional="ZodOptional",t.ZodNullable="ZodNullable",t.ZodDefault="ZodDefault",t.ZodCatch="ZodCatch",t.ZodPromise="ZodPromise",t.ZodBranded="ZodBranded",t.ZodPipeline="ZodPipeline"})(pt||(pt={}));var Iq=o((t,e={message:`Input not instance of ${t.name}`})=>A9(r=>r instanceof t,e,!0),"instanceOfType"),S9=Mi.create,M9=Yi.create,Dq=bf.create,Oq=Zs.create,T9=Qs.create,Rq=xo.create,Nq=lf.create,Pq=ea.create,Lq=ta.create,Bq=us.create,Uq=wo.create,$q=Ti.create,Fq=hf.create,qq=Sn.create,Hq=er.create,zq=er.strictCreate,Kq=ra.create,jq=df.create,Gq=na.create,Vq=Wn.create,Wq=ia.create,Jq=pf.create,Yq=_o.create,Xq=ls.create,Zq=oa.create,Qq=sa.create,eH=aa.create,tH=fa.create,rH=hs.create,x9=Mn.create,nH=Jn.create,iH=Eo.create,oH=Mn.createWithPreprocess,sH=ua.create,aH=o(()=>S9().optional(),"ostring"),fH=o(()=>M9().optional(),"onumber"),cH=o(()=>T9().optional(),"oboolean"),uH={string:t=>Mi.create({...t,coerce:!0}),number:t=>Yi.create({...t,coerce:!0}),boolean:t=>Qs.create({...t,coerce:!0}),bigint:t=>Zs.create({...t,coerce:!0}),date:t=>xo.create({...t,coerce:!0})},lH=gt,U=Object.freeze({__proto__:null,defaultErrorMap:Cl,setErrorMap:wq,getErrorMap:j0,makeIssue:G0,EMPTY_PATH:_q,addIssueToContext:Ke,ParseStatus:Rr,INVALID:gt,DIRTY:_9,OK:rn,isAborted:Jg,isDirty:Yg,isValid:V0,isAsync:W0,get util(){return Ut},ZodParsedType:Fe,getParsedType:Xs,ZodType:xt,ZodString:Mi,ZodNumber:Yi,ZodBigInt:Zs,ZodBoolean:Qs,ZodDate:xo,ZodSymbol:lf,ZodUndefined:ea,ZodNull:ta,ZodAny:us,ZodUnknown:wo,ZodNever:Ti,ZodVoid:hf,ZodArray:Sn,get objectUtil(){return J0},ZodObject:er,ZodUnion:ra,ZodDiscriminatedUnion:df,ZodIntersection:na,ZodTuple:Wn,ZodRecord:ia,ZodMap:pf,ZodSet:_o,ZodFunction:ls,ZodLazy:oa,ZodLiteral:sa,ZodEnum:aa,ZodNativeEnum:fa,ZodPromise:hs,ZodEffects:Mn,ZodTransformer:Mn,ZodOptional:Jn,ZodNullable:Eo,ZodDefault:ca,ZodCatch:mf,ZodNaN:bf,BRAND:Cq,ZodBranded:Tl,ZodPipeline:ua,custom:A9,Schema:xt,ZodSchema:xt,late:kq,get ZodFirstPartyTypeKind(){return pt},coerce:uH,any:Bq,array:qq,bigint:Oq,boolean:T9,date:Rq,discriminatedUnion:jq,effect:x9,enum:eH,function:Xq,instanceof:Iq,intersection:Gq,lazy:Zq,literal:Qq,map:Jq,nan:Dq,nativeEnum:tH,never:$q,null:Lq,nullable:iH,number:M9,object:Hq,oboolean:cH,onumber:fH,optional:nH,ostring:aH,pipeline:sH,preprocess:oH,promise:rH,record:Wq,set:Yq,strictObject:zq,string:S9,symbol:Nq,transformer:x9,tuple:Vq,undefined:Pq,union:Kq,unknown:Uq,void:Fq,NEVER:lH,ZodIssueCode:Ne,quotelessJson:xq,ZodError:Si});var k9=U.array(U.string().or(U.record(U.any()))),Jte=U.object({type:U.string().optional(),narrative:U.string().optional()}),X0=U.string().or(U.object({id:U.string(),type:U.string(),caption:U.string().optional()})),hH=U.object({type:U.string().min(1).or(U.string().array().nonempty()),latitude:U.number(),longitude:U.number()}),dH=U.object({type:U.string().min(1).or(U.string().array().nonempty()),addressCountry:U.string().optional(),addressCountryCode:U.string().optional(),addressRegion:U.string().optional(),addressLocality:U.string().optional(),streetAddress:U.string().optional(),postOfficeBoxNumber:U.string().optional(),postalCode:U.string().optional(),geo:hH.optional()}),pH=U.enum(["sourcedId","systemId","productId","userName","accountId","emailAddress","nationalIdentityNumber","isbn","issn","lisSourcedId","oneRosterSourcedId","sisSourcedId","ltiContextId","ltiDeploymentId","ltiToolId","ltiPlatformId","ltiUserId","identifier"]).or(U.string()),I9=U.object({type:U.string().min(1).or(U.string().array().nonempty()),identifier:U.string(),identifierType:pH}),kl=U.string().or(U.object({id:U.string().optional(),type:U.string().or(U.string().array().nonempty().optional()),name:U.string().optional(),url:U.string().optional(),phone:U.string().optional(),description:U.string().optional(),endorsement:U.any().array().optional(),image:X0.optional(),email:U.string().email().optional(),address:dH.optional(),otherIdentifier:I9.array().optional(),official:U.string().optional(),parentOrg:U.any().optional(),familyName:U.string().optional(),givenName:U.string().optional(),additionalName:U.string().optional(),patronymicName:U.string().optional(),honorificPrefix:U.string().optional(),honorificSuffix:U.string().optional(),familyNamePrefix:U.string().optional(),dateOfBirth:U.string().optional()}).catchall(U.any())),Zg=U.object({id:U.string().optional()}).catchall(U.any()),mH=U.object({type:U.string(),id:U.string()}).catchall(U.any()),bH=U.object({id:U.string(),type:U.string()}).catchall(U.any()),gH=U.object({id:U.string(),type:U.string()}).catchall(U.any()),Y0=U.object({"@context":k9,id:U.string().optional(),type:U.string().array().nonempty(),issuer:kl,issuanceDate:U.string(),expirationDate:U.string().optional(),credentialSubject:Zg.or(Zg.array()),credentialStatus:mH.optional(),credentialSchema:bH.array().optional(),refreshService:gH.optional()}).catchall(U.any()),la=U.object({type:U.string(),created:U.string(),challenge:U.string().optional(),domain:U.string().optional(),nonce:U.string().optional(),proofPurpose:U.string(),verificationMethod:U.string(),jws:U.string().optional()}).catchall(U.any()),Il=Y0.extend({proof:la.or(la.array())}),vH=U.object({"@context":k9,id:U.string().optional(),type:U.string().or(U.string().array().nonempty()),verifiableCredential:Il.or(Il.array()).optional(),holder:U.string().optional()}).catchall(U.any()),e2=vH.extend({proof:la.or(la.array())}),yH=U.enum(["ceasn:Competency","ceterms:Credential","CFItem","CFRubric","CFRubricCriterion","CFRubricCriterionLevel","CTDL"]).or(U.string()),Z0=U.object({type:U.string().array().nonempty(),targetCode:U.string().optional(),targetDescription:U.string().optional(),targetName:U.string(),targetFramework:U.string().optional(),targetType:yH.optional(),targetUrl:U.string()}),xH=U.enum(["Achievement","ApprenticeshipCertificate","Assessment","Assignment","AssociateDegree","Award","Badge","BachelorDegree","Certificate","CertificateOfCompletion","Certification","CommunityService","Competency","Course","CoCurricular","Degree","Diploma","DoctoralDegree","Fieldwork","GeneralEducationDevelopment","JourneymanCertificate","LearningProgram","License","Membership","ProfessionalDoctorate","QualityAssuranceCredential","MasterCertificate","MasterDegree","MicroCredential","ResearchDoctorate","SecondarySchoolDiploma"]),wH=xH.or(U.string()),_H=U.object({id:U.string().optional(),narrative:U.string().optional()}).catchall(U.any()),EH=U.object({id:U.string(),type:U.string().array().nonempty(),endorsementComment:U.string().optional()}),AH=Y0.extend({credentialSubject:EH,proof:la.or(la.array()).optional()}),SH=U.object({id:U.string(),"@language":U.string().optional(),version:U.string().optional()}),MH=U.enum(["GradePointAverage","LetterGrade","Percent","PerformanceLevel","PredictedScore","RawScore","Result","RubricCriterion","RubricCriterionLevel","RubricScore","ScaledScore","Status"]).or(U.string()),TH=U.object({id:U.string(),type:U.string().array().nonempty(),alignment:Z0.array().optional(),description:U.string().optional(),level:U.string().optional(),name:U.string(),points:U.string().optional()}).catchall(U.any()),CH=U.object({id:U.string(),type:U.string().array().nonempty(),alignment:Z0.array().optional(),allowedValue:U.string().array().optional(),name:U.string(),requiredLevel:U.string().optional(),requiredValue:U.string().optional(),resultType:MH,rubricCriterionLevel:TH.array().optional(),valueMax:U.string().optional(),valueMin:U.string().optional()}).catchall(U.any()),kH=U.object({id:U.string().optional(),type:U.string().array().nonempty(),alignment:Z0.array().optional(),achievementType:wH.optional(),creator:kl.optional(),creditsAvailable:U.number().optional(),criteria:_H,description:U.string(),endorsement:AH.array().optional(),fieldOfStudy:U.string().optional(),humanCode:U.string().optional(),image:X0.optional(),"@language":U.string().optional(),name:U.string(),otherIdentifier:I9.array().optional(),related:SH.array().optional(),resultDescription:CH.array().optional(),specialization:U.string().optional(),tag:U.string().array().optional(),version:U.string().optional()}).catchall(U.any()),IH=U.object({type:U.string(),hashed:U.boolean(),identityHash:U.string(),identityType:U.string(),salt:U.string().optional()}),DH=U.enum(["Completed","Enrolled","Failed","InProgress","OnHold","Withdrew"]),OH=U.object({type:U.string().array().nonempty(),achievedLevel:U.string().optional(),alignment:Z0.array().optional(),resultDescription:U.string().optional(),status:DH.optional(),value:U.string().optional()}).catchall(U.any()),C9=U.object({id:U.string().optional(),type:U.string().array().nonempty(),activityEndDate:U.string().optional(),activityStartDate:U.string().optional(),creditsEarned:U.number().optional(),achievement:kH.optional(),identifier:IH.array().optional(),image:X0.optional(),licenseNumber:U.string().optional(),narrative:U.string().optional(),result:OH.array().optional(),role:U.string().optional(),source:kl.optional(),term:U.string().optional()}).catchall(U.any()),RH=U.object({id:U.string().optional(),type:U.string().array().nonempty(),narrative:U.string().optional(),name:U.string().optional(),description:U.string().optional(),genre:U.string().optional(),audience:U.string().optional()}).catchall(U.any()),NH=Y0.extend({name:U.string().optional(),description:U.string().optional(),image:X0.optional(),credentialSubject:C9.or(C9.array()),endorsement:Y0.array().optional(),evidence:RH.array().optional()}),Xte=NH.extend({proof:la.or(la.array())}),Qte=U.object({checks:U.string().array(),warnings:U.string().array(),errors:U.string().array()}),D9=U.enum(["Success","Failed","Error"]),ere=D9.enum,tre=U.object({check:U.string(),status:D9,message:U.string().optional(),details:U.string().optional()}),rre=U.object({title:U.string().optional(),createdAt:U.string().optional(),issuer:kl.optional(),issuee:kl.optional(),credentialSubject:Zg.optional()}),nre=U.object({id:U.string(),uri:U.string()}).catchall(U.any()),sre=U.object({limit:U.number(),cursor:U.string().optional(),sort:U.string().optional()}),gf=U.object({cursor:U.string().optional(),hasMore:U.boolean()}),PH=U.object({kty:U.string(),crv:U.string(),x:U.string(),y:U.string().optional(),n:U.string().optional(),d:U.string()}),LH=U.object({alg:U.string(),iv:U.string(),tag:U.string(),epk:PH.partial().optional(),kid:U.string().optional(),apv:U.string().optional(),apu:U.string().optional()}),BH=U.object({header:LH,encrypted_key:U.string()}),UH=U.object({protected:U.string(),iv:U.string(),ciphertext:U.string(),tag:U.string(),aad:U.string().optional(),recipients:BH.array().optional()}),O9=U.object({encryptedRecord:UH,fields:U.string().array()}).catchall(U.any()),fre=gf.extend({records:O9.array()}),$H=O9.extend({id:U.string()}),cre=gf.extend({records:$H.array()}),qc=U.object({profileId:U.string().min(3).max(40),displayName:U.string().default(""),bio:U.string().default(""),did:U.string(),email:U.string().optional(),image:U.string().optional(),isServiceProfile:U.boolean().default(!1).optional(),notificationsWebhook:U.string().url().startsWith("https://").optional()}),lre=gf.extend({records:qc.array()}),hre=U.enum(["CONNECTED","PENDING_REQUEST_SENT","PENDING_REQUEST_RECEIVED","NOT_CONNECTED"]),dre=U.object({uri:U.string(),to:U.string(),from:U.string(),sent:U.string().datetime(),received:U.string().datetime().optional()}),FH=U.enum(["DRAFT","LIVE"]),pre=U.object({uri:U.string(),name:U.string().optional(),type:U.string().optional(),category:U.string().optional(),status:FH.optional(),autoConnectRecipients:U.boolean().optional()}),mre=U.object({to:qc,from:U.string(),received:U.string().optional()}),qH=U.enum(["CONNECTION_REQUEST","CONNECTION_ACCEPTED","CREDENTIAL_RECEIVED","CREDENTIAL_ACCEPTED","BOOST_RECEIVED","BOOST_ACCEPTED","PRESENTATION_REQUEST","PRESENTATION_RECEIVED"]),HH=U.object({title:U.string().optional(),body:U.string().optional()}),zH=U.object({vcUris:U.array(U.string()).optional(),vpUris:U.array(U.string()).optional()}),bre=U.object({type:qH,to:qc.partial().and(U.object({did:U.string()})),from:qc.partial().and(U.object({did:U.string()})),message:HH.optional(),data:zH.optional(),sent:U.string().datetime().optional()}),gre=U.object({endpoint:U.string(),name:U.string(),did:U.string().optional()}),vre=U.object({ttlSeconds:U.number().optional(),totalUses:U.number().optional()}),KH=U.object({endpoint:U.string()}),yre=U.object({signingAuthority:KH,relationship:U.object({name:U.string().max(15).regex(/^[a-z0-9-]+$/,{message:"The input string must contain only lowercase letters, numbers, and hyphens."}),did:U.string()})}),jH=U.enum(["live","stale","withdrawn"]),GH=U.object({read:U.object({anonymize:U.boolean().optional(),credentials:U.object({categories:U.record(U.object({required:U.boolean()})).default({})}).default({}),personal:U.record(U.object({required:U.boolean()})).default({})}).default({}),write:U.object({credentials:U.object({categories:U.record(U.object({required:U.boolean()})).default({})}).default({}),personal:U.record(U.object({required:U.boolean()})).default({})}).default({})}),R9=U.object({contract:GH,owner:qc,name:U.string(),subtitle:U.string().optional(),description:U.string().optional(),reasonForAccessing:U.string().optional(),image:U.string().optional(),uri:U.string(),createdAt:U.string(),updatedAt:U.string(),expiresAt:U.string().optional()}),xre=gf.extend({records:R9.omit({owner:!0}).array()}),VH=U.object({credentials:U.object({categories:U.record(U.string().array()).default({})}),personal:U.record(U.string()).default({}),date:U.string()}),wre=gf.extend({records:VH.array()}),N9=U.object({read:U.object({anonymize:U.boolean().optional(),credentials:U.object({shareAll:U.boolean().optional(),sharing:U.boolean().optional(),categories:U.record(U.object({sharing:U.boolean().optional(),shared:U.string().array().optional(),shareAll:U.boolean().optional()})).default({})}).default({}),personal:U.record(U.string()).default({})}).default({}),write:U.object({credentials:U.object({categories:U.record(U.boolean()).default({})}).default({}),personal:U.record(U.boolean()).default({})}).default({})}),_re=gf.extend({records:U.object({expiresAt:U.string().optional(),oneTime:U.boolean().optional(),terms:N9,contract:R9,uri:U.string(),consenter:qc,status:jH}).array()}),Ere=U.object({read:U.object({anonymize:U.boolean().optional(),credentials:U.object({categories:U.record(U.object({required:U.boolean().optional()})).optional()}).optional(),personal:U.record(U.object({required:U.boolean().optional()})).optional()}).optional(),write:U.object({credentials:U.object({categories:U.record(U.object({required:U.boolean().optional()})).optional()}).optional(),personal:U.record(U.object({required:U.boolean().optional()})).optional()}).optional()}),WH=U.object({read:U.object({anonymize:U.boolean().optional(),credentials:U.object({shareAll:U.boolean().optional(),sharing:U.boolean().optional(),categories:U.record(U.object({sharing:U.boolean().optional(),shared:U.string().array().optional(),shareAll:U.boolean().optional()}).optional()).optional()}).optional(),personal:U.record(U.string()).optional()}).optional(),write:U.object({credentials:U.object({categories:U.record(U.boolean()).optional()}).optional(),personal:U.record(U.boolean()).optional()}).optional()}),Qg=U.enum(["consent","update","sync","withdraw"]),Are=U.object({terms:WH.optional(),action:Qg.or(Qg.array()).optional(),date:U.object({$gt:U.string()}).or(U.object({$lt:U.string()})).or(U.object({$eq:U.string()})).optional(),expiresAt:U.object({$gt:U.string()}).or(U.object({$lt:U.string()})).or(U.object({$eq:U.string()})).optional(),oneTime:U.boolean().optional()}),JH=U.object({expiresAt:U.string().optional(),oneTime:U.boolean().optional(),terms:N9.optional(),id:U.string(),action:Qg,date:U.string()}),Sre=gf.extend({records:JH.array()});var Q0=o(t=>`lc:ceramic:${t}`,"streamIdToCeramicURI");var t2=U.string().refine(t=>t.split(":").length===3&&t.split(":")[0]==="lc","URI must be of the form lc:${storage}:${url}").refine(t=>t.split(":")[1]==="ceramic","URI must use storage type ceramic (i.e. must be lc:ceramic:${streamID})");var ep=o(async(t,{ceramicEndpoint:e,defaultContentFamily:r})=>{let n=new Ml(e),i=o(async(R,D,P,J)=>t.invoke.didResolver(R,J),"learnCardResolver"),a={...g8.getResolver(),web:i},c=new Va({resolver:a});n.did=c;let u=t.invoke.getKey(),m=new tl(e8(u));n.did.setProvider(m),await n.did.authenticate();let v=new yl({ceramic:n}),x=o(async(R,D={},P={},J)=>{if(!R)throw new Error("content is required");if(D.controllers||(D.controllers=[n.did.id]),D.family||(D.family=r),"pin"in P||(P.pin=!0),J?.encrypt){t.debug?.("learnCard.store.Ceramic.upload.publishContentToCeramic - encrypt enabled",J);let W=J?.recipients||[];J?.controllersCanDecrypt&&(W=[...W,...D.controllers]),R=await n?.did?.createDagJWE(R,P9.default.uniq(W))}return t.debug?.("learnCard.store.Ceramic.upload.publishContentToCeramic - content to upload",R,D,P),(await Gn.create(n,R,D,P)).id.toString()},"publishContentToCeramic"),S=o(async R=>{let D=(await v.load(R))?.content;if(t.debug?.("learnCard.read.get.readContentFromCeramic",D),D?.ciphertext)try{return await c.decryptDagJWE(D)}catch(P){throw t.debug?.("learnCard.read.get.readContentFromCeramic - Could not decrypt credential - DID not authorized.",P),new Error("Could not decrypt credential - DID not authorized.")}return D},"readContentFromCeramic"),O=o(async(R,D)=>(await Il.or(e2).parseAsync(R),Q0(await x(R,{},{},D))),"uploadCredential");return{name:"Ceramic",displayName:"Ceramic",description:"Uploads/resolves credentials using the Ceramic Network (https://ceramic.network/)",store:{upload:async(R,D)=>(R.debug?.("learnCard.store.Ceramic.upload"),O(D)),uploadEncrypted:async(R,D,P)=>(R.debug?.("learnCard.store.Ceramic.uploadEncrypted"),O(D,{encrypt:!0,controllersCanDecrypt:!0,...P?{recipients:P.recipients}:{}}))},read:{get:async(R,D)=>{if(R.debug?.("learnCard.read.Ceramic.get"),!D)return;let P=await t2.spa(D);if(!P.success)return;let J=P.data.split(":")[2];try{return await Il.or(e2).parseAsync(await S(J))}catch(L){R.debug?.(L);return}}},methods:{publishContentToCeramic:async(R,D,P)=>Q0(await x(D,{},{},P)),readContentFromCeramic:async(R,D)=>S(D),getCeramicClient:()=>n,getDIDObject:()=>n.did}}},"getCeramicPlugin");var YH=ep;
818
818
  /*!
819
819
  * https://github.com/Starcounter-Jack/JSON-Patch
820
820
  * (c) 2017-2021 Joachim Wester