@lostgradient/weft 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli-main.js +77 -77
- package/dist/core/context/index.d.ts +1 -0
- package/dist/core/context/index.js +3 -0
- package/dist/core/context/internals.d.ts +1 -0
- package/dist/core/context/internals.js +2 -1
- package/dist/core/context/speculative-child.js +2 -0
- package/dist/core/context/types.d.ts +6 -0
- package/dist/core/engine/bulk-operations-purge.js +1 -0
- package/dist/core/engine/callback-creators-bundles.js +2 -1
- package/dist/core/engine/callback-creators-core.js +2 -1
- package/dist/core/engine/construction.d.ts +1 -0
- package/dist/core/engine/construction.js +5 -2
- package/dist/core/engine/engine-internal-types.d.ts +5 -0
- package/dist/core/engine/index.d.ts +26 -0
- package/dist/core/engine/index.js +7 -1
- package/dist/core/engine/internals.d.ts +8 -0
- package/dist/core/engine/lifecycle/recovered-services.d.ts +45 -0
- package/dist/core/engine/lifecycle/recovered-services.js +34 -0
- package/dist/core/engine/lifecycle/resume.js +8 -1
- package/dist/core/engine/lifecycle/shared.d.ts +8 -0
- package/dist/core/engine/lifecycle/start-batch.js +23 -12
- package/dist/core/engine/lifecycle/start.js +11 -0
- package/dist/core/engine/operations-data.d.ts +16 -0
- package/dist/core/engine/operations-data.js +6 -0
- package/dist/core/engine/operations-time.d.ts +3 -2
- package/dist/core/engine/operations-time.js +6 -1
- package/dist/core/engine/termination/cleanup.js +2 -0
- package/dist/core/inline-execution-strategy.d.ts +5 -0
- package/dist/core/inline-execution-strategy.js +2 -1
- package/dist/core/types/options.d.ts +89 -0
- package/dist/core/types/workflow-context.d.ts +25 -0
- package/dist/core/weft-error.d.ts +45 -13
- package/dist/core/weft-error.js +9 -0
- package/dist/index.d.ts +7 -2
- package/dist/index.js +1 -1
- package/dist/json-schema.js +3 -3
- package/dist/mcp/cli.js +17 -17
- package/dist/server/handler.js +12 -12
- package/dist/server/index.js +24 -24
- package/dist/service-worker/index.js +12 -12
- package/dist/storage/http.js +1 -1
- package/dist/storage/index.d.ts +2 -1
- package/dist/storage/indexeddb.js +1 -1
- package/dist/storage/interface.d.ts +14 -0
- package/dist/storage/interface.js +1 -1
- package/dist/storage/key-prefixes.d.ts +1 -1
- package/dist/storage/key-prefixes.js +1 -0
- package/dist/storage/lmdb.js +1 -1
- package/dist/storage/memory.js +1 -1
- package/dist/storage/resolve.js +1 -1
- package/dist/storage/scoped-storage.js +1 -1
- package/dist/storage/text-value-store.d.ts +4 -1
- package/dist/storage/turso.js +1 -1
- package/dist/storage/typed-storage.js +1 -1
- package/dist/storage/web-extension.js +1 -1
- package/dist/testing/event-loop.d.ts +36 -2
- package/dist/testing/index.d.ts +31 -1
- package/dist/testing/index.js +17 -17
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
var wW=Object.defineProperty;var jW=(W)=>W;function hW(W,$){this[W]=jW.bind(null,$)}var b0=(W,$)=>{for(var Z in $)wW(W,Z,{get:$[Z],enumerable:!0,configurable:!0,set:hW.bind($,Z)})};var X=(W,$)=>()=>(W&&($=W(W=0)),$);function v(W,$,Z){if(!W.capabilities()[$])throw Error(`Feature "${Z}" requires storage capability "${$}", but this storage backend does not provide it.`)}function mW(W){let $=W.capabilities(),Z=[];if($.persistence!=="local")Z.push(`persistence must be "local" (got "${$.persistence}")`);if($.readAfterWrite!=="linearizable")Z.push(`readAfterWrite must be "linearizable" (got "${$.readAfterWrite}")`);if($.scanConsistency!=="snapshot")Z.push(`scanConsistency must be "snapshot" (got "${$.scanConsistency}")`);if(!$.atomicBatch)Z.push("atomicBatch must be true");if(!$.conditionalBatch)Z.push("conditionalBatch must be true");if(Z.length>0)throw Error(`Storage is not durable enough for recovery: ${Z.join("; ")}.`)}var b="default";async function r(W,$){return await W.get($)!==null}async function*z(W,$,Z){for await(let[G]of W.scan($,Z))yield G}async function s(W,$){let Z=0;for await(let G of z(W,$))Z++;return Z}async function a(W,$){let Z=[];for await(let G of z(W,$))Z.push({type:"delete",key:G});if(Z.length===0)return 0;return await W.batch(Z),Z.length}async function o(W,$,Z){let G=[];for await(let J of z(W,$,Z))G.push({type:"delete",key:J});if(G.length===0)return 0;return await W.batch(G),G.length}var gW;var t=X(()=>{gW=["actrec:","archive:","async-act:","attr:","audit:bulk:","blob:","budget:","budget-charged:","ev:","idx:","offload:","op:","review:","schedule:","schedule-due:","schedule-run:","sig:","sigres:","sigseq:","state:","tag:","tool-effect:","upd:","upk:","upr:","wf:","wf-cleanup:","wf-cleanup-needed:","wf-deadline:","wf-delayed:","wf-headers:","wf-idx-","wf-terminal:"]});function i0(W){return W.length>0?W.slice(0,-1)+String.fromCharCode(W.charCodeAt(W.length-1)+1):"\xFF"}function r0(W,$={}){if($.gt!==void 0&&W<=$.gt)return!1;if($.gte!==void 0&&W<$.gte)return!1;if($.lt!==void 0&&W>=$.lt)return!1;if($.lte!==void 0&&W>$.lte)return!1;return!0}function s0(W,$){if(W===null||$===null)return W===$;if(W.byteLength!==$.byteLength)return!1;for(let Z=0;Z<W.byteLength;Z++)if(W[Z]!==$[Z])return!1;return!0}async function e(W,$){if(W.has)return W.has($);return r(W,$)}function WW(W,$,Z){if(W.keys)return W.keys($,Z);return z(W,$,Z)}async function $W(W,$){if(W.count)return W.count($);return s(W,$)}async function ZW(W,$){if(W.deletePrefix)return W.deletePrefix($);return a(W,$)}async function GW(W,$,Z){if(v(W,"conditionalBatch","storageConditionalBatch"),!W.conditionalBatch)throw Error("This storage backend reports conditionalBatch capability but does not implement the conditionalBatch() method.");return W.conditionalBatch($,Z)}function q(W){return encodeURIComponent(W)}function a0(W){return decodeURIComponent(W)}function o0(W){try{return decodeURIComponent(W)}catch{return null}}var N=(W)=>String(W).padStart(16,"0"),t0;var JW=X(()=>{t();t0={workflow:(W)=>`wf:${q(W)}`,checkpoint:(W)=>`wf:${q(W)}:ckpt`,checkpointHistory:(W,$)=>`wf:${q(W)}:ckpt:${String($).padStart(10,"0")}`,timelinePrefix:(W)=>`wf:${q(W)}:timeline:`,timeline:(W,$)=>`wf:${q(W)}:timeline:${String($).padStart(10,"0")}`,schedule:(W)=>`schedule:${q(W)}`,scheduleTick:(W,$)=>`schedule-due:${String(W).padStart(16,"0")}:${q($)}`,scheduleRun:(W)=>`schedule-run:${q(W)}`,operation:(W,$,Z)=>`op:${W}:${N($)}:${Z}`,operationInflight:(W)=>`op:inflight:${W}`,operationQueued:(W)=>`op:queued:${W}`,operationResolved:(W)=>`op:resolved:${W}`,bulkOperationAuditPrefix:()=>"audit:bulk:",bulkOperationAudit:(W,$,Z)=>`audit:bulk:${N(W)}:${q($)}:${q(Z)}`,operationResolvedByTimePrefix:()=>"op:resolved-by-time:",operationResolvedByTime:(W,$)=>`op:resolved-by-time:${N(W)}:${q($)}`,asyncActivity:(W,$)=>`async-act:v1:${q(W)}:${q($)}`,activityReconciliationPrefix:(W)=>`actrec:v1:${q(W)}:`,activityReconciliation:(W,$,Z)=>`actrec:v1:${q(W)}:${q($)}:${Z}`,eventPrefix:(W)=>`ev:${q(W)}:`,event:(W,$)=>`ev:${q(W)}:${String($).padStart(10,"0")}`,eventHead:(W)=>`ev:${q(W)}:head`,eventWatermark:(W)=>`ev:${q(W)}:watermark`,signal:(W,$,Z)=>`sig:${q(W)}:${$}:${q(Z)}`,signalSequence:(W)=>`sigseq:v1:${q(W)}`,signalAcceptedResponsePrefix:(W)=>`sigres:v1:${q(W)}:`,signalAcceptedResponse:(W,$,Z)=>`sigres:v1:${q(W)}:${q($)}:${q(Z)}`,deadline:(W,$)=>`wf-deadline:${N(W)}:${q($)}`,terminalCleanup:(W,$)=>`wf-cleanup:${N(W)}:${q($)}`,delayedStart:(W,$)=>`wf-delayed:${N(W)}:${q($)}`,terminalWorkflowPrefix:()=>"wf-terminal:",terminalWorkflow:(W,$)=>`wf-terminal:${N(W)}:${q($)}`,attribute:(W)=>`attr:${q(W)}`,attributeIndex:(W,$,Z)=>`idx:${W}:${$}:${q(Z)}`,tagIndex:(W,$)=>`tag:${q(W)}:${q($)}`,updatePrefix:(W)=>`upd:${q(W)}:`,update:(W,$)=>`upd:${q(W)}:${$}`,updateResponse:(W)=>`upr:${W}`,updateIdempotency:(W,$)=>`upk:${q(W)}:${$}`,budget:(W,$,Z)=>`budget:${W}:${$}:${Z}`,review:(W,$)=>`review:${q(W)}:${$}`,workflowHeaders:(W)=>`wf-headers:${q(W)}`,terminalCleanupNeeded:(W)=>`wf-cleanup-needed:${q(W)}`,offload:(W,$)=>`offload:${q(W)}:${$}`,archive:(W,$)=>`archive:${q(W)}:${$}`,stateExecution:(W,$)=>`state:execution:${q(W)}:${q($)}`,stateWorkflow:(W,$)=>`state:workflow-scope:${b}:${q(W)}:${q($)}`,streamChunkPrefix:(W,$)=>`blob:${q(W)}:${$}:chunk:`,streamChunk:(W,$,Z)=>`blob:${q(W)}:${$}:chunk:${String(Z).padStart(10,"0")}`,streamMetadata:(W,$)=>`blob:${q(W)}:${$}:meta`,budgetCharged:(W)=>`budget-charged:${W}`,toolEffect:(W,$,Z)=>`tool-effect:${q(W)}:${$}:${Z}`,workflowVisibilityStatus:(W,$)=>`wf-idx-status:${q(W)}:${q($)}`,workflowVisibilityType:(W,$)=>`wf-idx-type:${q(W)}:${q($)}`,workflowVisibilityCreated:(W,$)=>`wf-idx-created:${N(W)}:${q($)}`,workflowVisibilityUpdated:(W,$)=>`wf-idx-updated:${N(W)}:${q($)}`,workflowVisibilityDeadline:(W,$)=>`wf-idx-deadline:${N(W)}:${q($)}`,workflowVisibilityManifest:(W)=>`wf-idx-manifest:${q(W)}`,workflowVisibilityMetaVersion:()=>"wf-idx-meta:version",workflowVisibilityMetaBuiltAt:()=>"wf-idx-meta:built-at",workflowVisibilityMetaCursor:()=>"wf-idx-meta:cursor"}});function QW(W){let $=W.length,Z=0,G=0;while(G<$){let J=W.charCodeAt(G++);if((J&4294967168)===0){Z++;continue}else if((J&4294965248)===0)Z+=2;else{if(J>=55296&&J<=56319){if(G<$){let Q=W.charCodeAt(G);if((Q&64512)===56320)++G,J=((J&1023)<<10)+(Q&1023)+65536}}if((J&4294901760)===0)Z+=3;else Z+=4}}return Z}function vW(W,$,Z){let G=W.length,J=Z,Q=0;while(Q<G){let F=W.charCodeAt(Q++);if((F&4294967168)===0){$[J++]=F;continue}else if((F&4294965248)===0)$[J++]=F>>6&31|192;else{if(F>=55296&&F<=56319){if(Q<G){let H=W.charCodeAt(Q);if((H&64512)===56320)++Q,F=((F&1023)<<10)+(H&1023)+65536}}if((F&4294901760)===0)$[J++]=F>>12&15|224,$[J++]=F>>6&63|128;else $[J++]=F>>18&7|240,$[J++]=F>>12&63|128,$[J++]=F>>6&63|128}$[J++]=F&63|128}}function fW(W,$,Z){bW.encodeInto(W,$.subarray(Z))}function qW(W,$,Z){if(W.length>yW)fW(W,$,Z);else vW(W,$,Z)}function y(W,$,Z){let G=$,J=G+Z,Q=[],F="";while(G<J){let H=W[G++];if((H&128)===0)Q.push(H);else if((H&224)===192){let A=W[G++]&63;Q.push((H&31)<<6|A)}else if((H&240)===224){let A=W[G++]&63,g=W[G++]&63;Q.push((H&31)<<12|A<<6|g)}else if((H&248)===240){let A=W[G++]&63,g=W[G++]&63,kW=W[G++]&63,B=(H&7)<<18|A<<12|g<<6|kW;if(B>65535)B-=65536,Q.push(B>>>10&1023|55296),B=56320|B&1023;Q.push(B)}else Q.push(H);if(Q.length>=lW)F+=String.fromCharCode(...Q),Q.length=0}if(Q.length>0)F+=String.fromCharCode(...Q);return F}function cW(W,$,Z){let G=W.subarray($,$+Z);return pW.decode(G)}function FW(W,$,Z){if(Z>uW)return cW(W,$,Z);else return y(W,$,Z)}var bW,yW=50,lW=4096,pW,uW=200;var C=X(()=>{bW=new TextEncoder;pW=new TextDecoder});class K{type;data;constructor(W,$){this.type=W,this.data=$}}var V;var f=X(()=>{V=class V extends Error{constructor(W){super(W);let $=Object.create(V.prototype);Object.setPrototypeOf(this,$),Object.defineProperty(this,"name",{configurable:!0,enumerable:!1,value:V.name})}}});function XW(W,$,Z){let G=Z/4294967296,J=Z;W.setUint32($,G),W.setUint32($+4,J)}function x(W,$,Z){let G=Math.floor(Z/4294967296),J=Z;W.setUint32($,G),W.setUint32($+4,J)}function S(W,$){let Z=W.getInt32($),G=W.getUint32($+4);return Z*4294967296+G}function YW(W,$){let Z=W.getUint32($),G=W.getUint32($+4);return Z*4294967296+G}var O=4294967295;function rW({sec:W,nsec:$}){if(W>=0&&$>=0&&W<=iW)if($===0&&W<=nW){let Z=new Uint8Array(4);return new DataView(Z.buffer).setUint32(0,W),Z}else{let Z=W/4294967296,G=W&4294967295,J=new Uint8Array(8),Q=new DataView(J.buffer);return Q.setUint32(0,$<<2|Z&3),Q.setUint32(4,G),J}else{let Z=new Uint8Array(12),G=new DataView(Z.buffer);return G.setUint32(0,$),x(G,4,W),Z}}function sW(W){let $=W.getTime(),Z=Math.floor($/1000),G=($-Z*1000)*1e6,J=Math.floor(G/1e9);return{sec:Z+J,nsec:G-J*1e9}}function aW(W){if(W instanceof Date){let $=sW(W);return rW($)}else return null}function oW(W){let $=new DataView(W.buffer,W.byteOffset,W.byteLength);switch(W.byteLength){case 4:{let Z=$.getUint32(0),G=0;return{sec:Z,nsec:0}}case 8:{let Z=$.getUint32(0),G=$.getUint32(4),J=(Z&3)*4294967296+G,Q=Z>>>2;return{sec:J,nsec:Q}}case 12:{let Z=S($,4),G=$.getUint32(0);return{sec:Z,nsec:G}}default:throw new V(`Unrecognized data size for timestamp (expected 4, 8, or 12): ${W.length}`)}}function tW(W){let $=oW(W);return new Date($.sec*1000+$.nsec/1e6)}var dW=-1,nW=4294967295,iW=17179869183,HW;var VW=X(()=>{f();HW={type:dW,encode:aW,decode:tW}});var R;var E=X(()=>{VW();R=class R{static defaultCodec=new R;__brand;builtInEncoders=[];builtInDecoders=[];encoders=[];decoders=[];constructor(){this.register(HW)}register({type:W,encode:$,decode:Z}){if(W>=0)this.encoders[W]=$,this.decoders[W]=Z;else{let G=-1-W;this.builtInEncoders[G]=$,this.builtInDecoders[G]=Z}}tryToEncode(W,$){for(let Z=0;Z<this.builtInEncoders.length;Z++){let G=this.builtInEncoders[Z];if(G!=null){let J=G(W,$);if(J!=null){let Q=-1-Z;return new K(Q,J)}}}for(let Z=0;Z<this.encoders.length;Z++){let G=this.encoders[Z];if(G!=null){let J=G(W,$);if(J!=null)return new K(Z,J)}}if(W instanceof K)return W;return null}decode(W,$,Z){let G=$<0?this.builtInDecoders[-1-$]:this.decoders[$];if(G)return G(W,$,Z);else return new K($,W)}}});function eW(W){return W instanceof ArrayBuffer||typeof SharedArrayBuffer<"u"&&W instanceof SharedArrayBuffer}function T(W){if(W instanceof Uint8Array)return W;else if(ArrayBuffer.isView(W))return new Uint8Array(W.buffer,W.byteOffset,W.byteLength);else if(eW(W))return new Uint8Array(W);else return Uint8Array.from(W)}class k{extensionCodec;context;useBigInt64;maxDepth;initialBufferSize;sortKeys;forceFloat32;ignoreUndefined;forceIntegerToFloat;pos;view;bytes;entered=!1;constructor(W){this.extensionCodec=W?.extensionCodec??R.defaultCodec,this.context=W?.context,this.useBigInt64=W?.useBigInt64??!1,this.maxDepth=W?.maxDepth??W0,this.initialBufferSize=W?.initialBufferSize??$0,this.sortKeys=W?.sortKeys??!1,this.forceFloat32=W?.forceFloat32??!1,this.ignoreUndefined=W?.ignoreUndefined??!1,this.forceIntegerToFloat=W?.forceIntegerToFloat??!1,this.pos=0,this.view=new DataView(new ArrayBuffer(this.initialBufferSize)),this.bytes=new Uint8Array(this.view.buffer)}clone(){return new k({extensionCodec:this.extensionCodec,context:this.context,useBigInt64:this.useBigInt64,maxDepth:this.maxDepth,initialBufferSize:this.initialBufferSize,sortKeys:this.sortKeys,forceFloat32:this.forceFloat32,ignoreUndefined:this.ignoreUndefined,forceIntegerToFloat:this.forceIntegerToFloat})}reinitializeState(){this.pos=0}encodeSharedRef(W){if(this.entered)return this.clone().encodeSharedRef(W);try{return this.entered=!0,this.reinitializeState(),this.doEncode(W,1),this.bytes.subarray(0,this.pos)}finally{this.entered=!1}}encode(W){if(this.entered)return this.clone().encode(W);try{return this.entered=!0,this.reinitializeState(),this.doEncode(W,1),this.bytes.slice(0,this.pos)}finally{this.entered=!1}}doEncode(W,$){if($>this.maxDepth)throw Error(`Too deep objects in depth ${$}`);if(W==null)this.encodeNil();else if(typeof W==="boolean")this.encodeBoolean(W);else if(typeof W==="number")if(!this.forceIntegerToFloat)this.encodeNumber(W);else this.encodeNumberAsFloat(W);else if(typeof W==="string")this.encodeString(W);else if(this.useBigInt64&&typeof W==="bigint")this.encodeBigInt64(W);else this.encodeObject(W,$)}ensureBufferSizeToWrite(W){let $=this.pos+W;if(this.view.byteLength<$)this.resizeBuffer($*2)}resizeBuffer(W){let $=new ArrayBuffer(W),Z=new Uint8Array($),G=new DataView($);Z.set(this.bytes),this.view=G,this.bytes=Z}encodeNil(){this.writeU8(192)}encodeBoolean(W){if(W===!1)this.writeU8(194);else this.writeU8(195)}encodeNumber(W){if(!this.forceIntegerToFloat&&Number.isSafeInteger(W))if(W>=0)if(W<128)this.writeU8(W);else if(W<256)this.writeU8(204),this.writeU8(W);else if(W<65536)this.writeU8(205),this.writeU16(W);else if(W<4294967296)this.writeU8(206),this.writeU32(W);else if(!this.useBigInt64)this.writeU8(207),this.writeU64(W);else this.encodeNumberAsFloat(W);else if(W>=-32)this.writeU8(224|W+32);else if(W>=-128)this.writeU8(208),this.writeI8(W);else if(W>=-32768)this.writeU8(209),this.writeI16(W);else if(W>=-2147483648)this.writeU8(210),this.writeI32(W);else if(!this.useBigInt64)this.writeU8(211),this.writeI64(W);else this.encodeNumberAsFloat(W);else this.encodeNumberAsFloat(W)}encodeNumberAsFloat(W){if(this.forceFloat32)this.writeU8(202),this.writeF32(W);else this.writeU8(203),this.writeF64(W)}encodeBigInt64(W){if(W>=BigInt(0))this.writeU8(207),this.writeBigUint64(W);else this.writeU8(211),this.writeBigInt64(W)}writeStringHeader(W){if(W<32)this.writeU8(160+W);else if(W<256)this.writeU8(217),this.writeU8(W);else if(W<65536)this.writeU8(218),this.writeU16(W);else if(W<4294967296)this.writeU8(219),this.writeU32(W);else throw Error(`Too long string: ${W} bytes in UTF-8`)}encodeString(W){let Z=QW(W);this.ensureBufferSizeToWrite(5+Z),this.writeStringHeader(Z),qW(W,this.bytes,this.pos),this.pos+=Z}encodeObject(W,$){let Z=this.extensionCodec.tryToEncode(W,this.context);if(Z!=null)this.encodeExtension(Z);else if(Array.isArray(W))this.encodeArray(W,$);else if(ArrayBuffer.isView(W))this.encodeBinary(W);else if(typeof W==="object")this.encodeMap(W,$);else throw Error(`Unrecognized object: ${Object.prototype.toString.apply(W)}`)}encodeBinary(W){let $=W.byteLength;if($<256)this.writeU8(196),this.writeU8($);else if($<65536)this.writeU8(197),this.writeU16($);else if($<4294967296)this.writeU8(198),this.writeU32($);else throw Error(`Too large binary: ${$}`);let Z=T(W);this.writeU8a(Z)}encodeArray(W,$){let Z=W.length;if(Z<16)this.writeU8(144+Z);else if(Z<65536)this.writeU8(220),this.writeU16(Z);else if(Z<4294967296)this.writeU8(221),this.writeU32(Z);else throw Error(`Too large array: ${Z}`);for(let G of W)this.doEncode(G,$+1)}countWithoutUndefined(W,$){let Z=0;for(let G of $)if(W[G]!==void 0)Z++;return Z}encodeMap(W,$){let Z=Object.keys(W);if(this.sortKeys)Z.sort();let G=this.ignoreUndefined?this.countWithoutUndefined(W,Z):Z.length;if(G<16)this.writeU8(128+G);else if(G<65536)this.writeU8(222),this.writeU16(G);else if(G<4294967296)this.writeU8(223),this.writeU32(G);else throw Error(`Too large map object: ${G}`);for(let J of Z){let Q=W[J];if(!(this.ignoreUndefined&&Q===void 0))this.encodeString(J),this.doEncode(Q,$+1)}}encodeExtension(W){if(typeof W.data==="function"){let Z=W.data(this.pos+6),G=Z.length;if(G>=4294967296)throw Error(`Too large extension object: ${G}`);this.writeU8(201),this.writeU32(G),this.writeI8(W.type),this.writeU8a(Z);return}let $=W.data.length;if($===1)this.writeU8(212);else if($===2)this.writeU8(213);else if($===4)this.writeU8(214);else if($===8)this.writeU8(215);else if($===16)this.writeU8(216);else if($<256)this.writeU8(199),this.writeU8($);else if($<65536)this.writeU8(200),this.writeU16($);else if($<4294967296)this.writeU8(201),this.writeU32($);else throw Error(`Too large extension object: ${$}`);this.writeI8(W.type),this.writeU8a(W.data)}writeU8(W){this.ensureBufferSizeToWrite(1),this.view.setUint8(this.pos,W),this.pos++}writeU8a(W){let $=W.length;this.ensureBufferSizeToWrite($),this.bytes.set(W,this.pos),this.pos+=$}writeI8(W){this.ensureBufferSizeToWrite(1),this.view.setInt8(this.pos,W),this.pos++}writeU16(W){this.ensureBufferSizeToWrite(2),this.view.setUint16(this.pos,W),this.pos+=2}writeI16(W){this.ensureBufferSizeToWrite(2),this.view.setInt16(this.pos,W),this.pos+=2}writeU32(W){this.ensureBufferSizeToWrite(4),this.view.setUint32(this.pos,W),this.pos+=4}writeI32(W){this.ensureBufferSizeToWrite(4),this.view.setInt32(this.pos,W),this.pos+=4}writeF32(W){this.ensureBufferSizeToWrite(4),this.view.setFloat32(this.pos,W),this.pos+=4}writeF64(W){this.ensureBufferSizeToWrite(8),this.view.setFloat64(this.pos,W),this.pos+=8}writeU64(W){this.ensureBufferSizeToWrite(8),XW(this.view,this.pos,W),this.pos+=8}writeI64(W){this.ensureBufferSizeToWrite(8),x(this.view,this.pos,W),this.pos+=8}writeBigUint64(W){this.ensureBufferSizeToWrite(8),this.view.setBigUint64(this.pos,W),this.pos+=8}writeBigInt64(W){this.ensureBufferSizeToWrite(8),this.view.setBigInt64(this.pos,W),this.pos+=8}}var W0=100,$0=2048;var PW=X(()=>{C();E()});function M(W,$){return new k($).encodeSharedRef(W)}var NW=X(()=>{PW()});function w(W){return`${W<0?"-":""}0x${Math.abs(W).toString(16).padStart(2,"0")}`}class l{hit=0;miss=0;caches;maxKeyLength;maxLengthPerKey;constructor(W=Z0,$=G0){this.maxKeyLength=W,this.maxLengthPerKey=$,this.caches=[];for(let Z=0;Z<this.maxKeyLength;Z++)this.caches.push([])}canBeCached(W){return W>0&&W<=this.maxKeyLength}find(W,$,Z){let G=this.caches[Z-1];W:for(let J of G){let Q=J.bytes;for(let F=0;F<Z;F++)if(Q[F]!==W[$+F])continue W;return J.str}return null}store(W,$){let Z=this.caches[W.length-1],G={bytes:W,str:$};if(Z.length>=this.maxLengthPerKey)Z[Math.random()*Z.length|0]=G;else Z.push(G)}decode(W,$,Z){let G=this.find(W,$,Z);if(G!=null)return this.hit++,G;this.miss++;let J=y(W,$,Z),Q=Uint8Array.prototype.slice.call(W,$,$+Z);return this.store(Q,J),J}}var Z0=16,G0=16;var RW=X(()=>{C()});class _W{stack=[];stackHeadPosition=-1;get length(){return this.stackHeadPosition+1}top(){return this.stack[this.stackHeadPosition]}pushArrayState(W){let $=this.getUninitializedStateFromPool();$.type=p,$.position=0,$.size=W,$.array=Array(W)}pushMapState(W){let $=this.getUninitializedStateFromPool();$.type=L,$.readCount=0,$.size=W,$.map={}}getUninitializedStateFromPool(){if(this.stackHeadPosition++,this.stackHeadPosition===this.stack.length){let W={type:void 0,size:0,array:void 0,position:0,readCount:0,map:void 0,key:null};this.stack.push(W)}return this.stack[this.stackHeadPosition]}release(W){if(this.stack[this.stackHeadPosition]!==W)throw Error("Invalid stack state. Released state is not on top of the stack.");if(W.type===p){let Z=W;Z.size=0,Z.array=void 0,Z.position=0,Z.type=void 0}if(W.type===L||W.type===UW){let Z=W;Z.size=0,Z.map=void 0,Z.readCount=0,Z.type=void 0}this.stackHeadPosition--}reset(){this.stack.length=0,this.stackHeadPosition=-1}}class j{extensionCodec;context;useBigInt64;rawStrings;maxStrLength;maxBinLength;maxArrayLength;maxMapLength;maxExtLength;keyDecoder;mapKeyConverter;totalPos=0;pos=0;view=u;bytes=Q0;headByte=D;stack=new _W;entered=!1;constructor(W){this.extensionCodec=W?.extensionCodec??R.defaultCodec,this.context=W?.context,this.useBigInt64=W?.useBigInt64??!1,this.rawStrings=W?.rawStrings??!1,this.maxStrLength=W?.maxStrLength??O,this.maxBinLength=W?.maxBinLength??O,this.maxArrayLength=W?.maxArrayLength??O,this.maxMapLength=W?.maxMapLength??O,this.maxExtLength=W?.maxExtLength??O,this.keyDecoder=W?.keyDecoder!==void 0?W.keyDecoder:q0,this.mapKeyConverter=W?.mapKeyConverter??J0}clone(){return new j({extensionCodec:this.extensionCodec,context:this.context,useBigInt64:this.useBigInt64,rawStrings:this.rawStrings,maxStrLength:this.maxStrLength,maxBinLength:this.maxBinLength,maxArrayLength:this.maxArrayLength,maxMapLength:this.maxMapLength,maxExtLength:this.maxExtLength,keyDecoder:this.keyDecoder})}reinitializeState(){this.totalPos=0,this.headByte=D,this.stack.reset()}setBuffer(W){let $=T(W);this.bytes=$,this.view=new DataView($.buffer,$.byteOffset,$.byteLength),this.pos=0}appendBuffer(W){if(this.headByte===D&&!this.hasRemaining(1))this.setBuffer(W);else{let $=this.bytes.subarray(this.pos),Z=T(W),G=new Uint8Array($.length+Z.length);G.set($),G.set(Z,$.length),this.setBuffer(G)}}hasRemaining(W){return this.view.byteLength-this.pos>=W}createExtraByteError(W){let{view:$,pos:Z}=this;return RangeError(`Extra ${$.byteLength-Z} of ${$.byteLength} byte(s) found at buffer[${W}]`)}decode(W){if(this.entered)return this.clone().decode(W);try{this.entered=!0,this.reinitializeState(),this.setBuffer(W);let $=this.doDecodeSync();if(this.hasRemaining(1))throw this.createExtraByteError(this.pos);return $}finally{this.entered=!1}}*decodeMulti(W){if(this.entered){yield*this.clone().decodeMulti(W);return}try{this.entered=!0,this.reinitializeState(),this.setBuffer(W);while(this.hasRemaining(1))yield this.doDecodeSync()}finally{this.entered=!1}}async decodeAsync(W){if(this.entered)return this.clone().decodeAsync(W);try{this.entered=!0;let $=!1,Z;for await(let F of W){if($)throw this.entered=!1,this.createExtraByteError(this.totalPos);this.appendBuffer(F);try{Z=this.doDecodeSync(),$=!0}catch(H){if(!(H instanceof RangeError))throw H}this.totalPos+=this.pos}if($){if(this.hasRemaining(1))throw this.createExtraByteError(this.totalPos);return Z}let{headByte:G,pos:J,totalPos:Q}=this;throw RangeError(`Insufficient data in parsing ${w(G)} at ${Q} (${J} in the current buffer)`)}finally{this.entered=!1}}decodeArrayStream(W){return this.decodeMultiAsync(W,!0)}decodeStream(W){return this.decodeMultiAsync(W,!1)}async*decodeMultiAsync(W,$){if(this.entered){yield*this.clone().decodeMultiAsync(W,$);return}try{this.entered=!0;let Z=$,G=-1;for await(let J of W){if($&&G===0)throw this.createExtraByteError(this.totalPos);if(this.appendBuffer(J),Z)G=this.readArraySize(),Z=!1,this.complete();try{while(!0)if(yield this.doDecodeSync(),--G===0)break}catch(Q){if(!(Q instanceof RangeError))throw Q}this.totalPos+=this.pos}}finally{this.entered=!1}}doDecodeSync(){W:while(!0){let W=this.readHeadByte(),$;if(W>=224)$=W-256;else if(W<192)if(W<128)$=W;else if(W<144){let G=W-128;if(G!==0){this.pushMapState(G),this.complete();continue W}else $={}}else if(W<160){let G=W-144;if(G!==0){this.pushArrayState(G),this.complete();continue W}else $=[]}else{let G=W-160;$=this.decodeString(G,0)}else if(W===192)$=null;else if(W===194)$=!1;else if(W===195)$=!0;else if(W===202)$=this.readF32();else if(W===203)$=this.readF64();else if(W===204)$=this.readU8();else if(W===205)$=this.readU16();else if(W===206)$=this.readU32();else if(W===207)if(this.useBigInt64)$=this.readU64AsBigInt();else $=this.readU64();else if(W===208)$=this.readI8();else if(W===209)$=this.readI16();else if(W===210)$=this.readI32();else if(W===211)if(this.useBigInt64)$=this.readI64AsBigInt();else $=this.readI64();else if(W===217){let G=this.lookU8();$=this.decodeString(G,1)}else if(W===218){let G=this.lookU16();$=this.decodeString(G,2)}else if(W===219){let G=this.lookU32();$=this.decodeString(G,4)}else if(W===220){let G=this.readU16();if(G!==0){this.pushArrayState(G),this.complete();continue W}else $=[]}else if(W===221){let G=this.readU32();if(G!==0){this.pushArrayState(G),this.complete();continue W}else $=[]}else if(W===222){let G=this.readU16();if(G!==0){this.pushMapState(G),this.complete();continue W}else $={}}else if(W===223){let G=this.readU32();if(G!==0){this.pushMapState(G),this.complete();continue W}else $={}}else if(W===196){let G=this.lookU8();$=this.decodeBinary(G,1)}else if(W===197){let G=this.lookU16();$=this.decodeBinary(G,2)}else if(W===198){let G=this.lookU32();$=this.decodeBinary(G,4)}else if(W===212)$=this.decodeExtension(1,0);else if(W===213)$=this.decodeExtension(2,0);else if(W===214)$=this.decodeExtension(4,0);else if(W===215)$=this.decodeExtension(8,0);else if(W===216)$=this.decodeExtension(16,0);else if(W===199){let G=this.lookU8();$=this.decodeExtension(G,1)}else if(W===200){let G=this.lookU16();$=this.decodeExtension(G,2)}else if(W===201){let G=this.lookU32();$=this.decodeExtension(G,4)}else throw new V(`Unrecognized type byte: ${w(W)}`);this.complete();let Z=this.stack;while(Z.length>0){let G=Z.top();if(G.type===p)if(G.array[G.position]=$,G.position++,G.position===G.size)$=G.array,Z.release(G);else continue W;else if(G.type===L){if($==="__proto__")throw new V("The key __proto__ is not allowed");G.key=this.mapKeyConverter($),G.type=UW;continue W}else if(G.map[G.key]=$,G.readCount++,G.readCount===G.size)$=G.map,Z.release(G);else{G.key=null,G.type=L;continue W}}return $}}readHeadByte(){if(this.headByte===D)this.headByte=this.readU8();return this.headByte}complete(){this.headByte=D}readArraySize(){let W=this.readHeadByte();switch(W){case 220:return this.readU16();case 221:return this.readU32();default:if(W<160)return W-144;else throw new V(`Unrecognized array type byte: ${w(W)}`)}}pushMapState(W){if(W>this.maxMapLength)throw new V(`Max length exceeded: map length (${W}) > maxMapLengthLength (${this.maxMapLength})`);this.stack.pushMapState(W)}pushArrayState(W){if(W>this.maxArrayLength)throw new V(`Max length exceeded: array length (${W}) > maxArrayLength (${this.maxArrayLength})`);this.stack.pushArrayState(W)}decodeString(W,$){if(!this.rawStrings||this.stateIsMapKey())return this.decodeUtf8String(W,$);return this.decodeBinary(W,$)}decodeUtf8String(W,$){if(W>this.maxStrLength)throw new V(`Max length exceeded: UTF-8 byte length (${W}) > maxStrLength (${this.maxStrLength})`);if(this.bytes.byteLength<this.pos+$+W)throw MW;let Z=this.pos+$,G;if(this.stateIsMapKey()&&this.keyDecoder?.canBeCached(W))G=this.keyDecoder.decode(this.bytes,Z,W);else G=FW(this.bytes,Z,W);return this.pos+=$+W,G}stateIsMapKey(){if(this.stack.length>0)return this.stack.top().type===L;return!1}decodeBinary(W,$){if(W>this.maxBinLength)throw new V(`Max length exceeded: bin length (${W}) > maxBinLength (${this.maxBinLength})`);if(!this.hasRemaining(W+$))throw MW;let Z=this.pos+$,G=this.bytes.subarray(Z,Z+W);return this.pos+=$+W,G}decodeExtension(W,$){if(W>this.maxExtLength)throw new V(`Max length exceeded: ext length (${W}) > maxExtLength (${this.maxExtLength})`);let Z=this.view.getInt8(this.pos+$),G=this.decodeBinary(W,$+1);return this.extensionCodec.decode(G,Z,this.context)}lookU8(){return this.view.getUint8(this.pos)}lookU16(){return this.view.getUint16(this.pos)}lookU32(){return this.view.getUint32(this.pos)}readU8(){let W=this.view.getUint8(this.pos);return this.pos++,W}readI8(){let W=this.view.getInt8(this.pos);return this.pos++,W}readU16(){let W=this.view.getUint16(this.pos);return this.pos+=2,W}readI16(){let W=this.view.getInt16(this.pos);return this.pos+=2,W}readU32(){let W=this.view.getUint32(this.pos);return this.pos+=4,W}readI32(){let W=this.view.getInt32(this.pos);return this.pos+=4,W}readU64(){let W=YW(this.view,this.pos);return this.pos+=8,W}readI64(){let W=S(this.view,this.pos);return this.pos+=8,W}readU64AsBigInt(){let W=this.view.getBigUint64(this.pos);return this.pos+=8,W}readI64AsBigInt(){let W=this.view.getBigInt64(this.pos);return this.pos+=8,W}readF32(){let W=this.view.getFloat32(this.pos);return this.pos+=4,W}readF64(){let W=this.view.getFloat64(this.pos);return this.pos+=8,W}}var p="array",L="map_key",UW="map_value",J0=(W)=>{if(typeof W==="string"||typeof W==="number")return W;throw new V("The type of key must be string or number but "+typeof W)},D=-1,u,Q0,MW,q0;var BW=X(()=>{E();C();RW();f();u=new DataView(new ArrayBuffer(0)),Q0=new Uint8Array(u.buffer);try{u.getInt8(0)}catch(W){if(!(W instanceof RangeError))throw Error("This module is not supported in the current JavaScript engine because DataView does not throw RangeError on out-of-bounds access")}MW=RangeError("Insufficient data"),q0=new l});function U(W,$){return new j($).decode(W)}var KW=X(()=>{BW()});var c=X(()=>{NW();KW();E()});function d(W){if(typeof W==="object"&&W!==null&&!Array.isArray(W))return W;return{}}function h(W){return Array.isArray(W)?W:[]}function OW(W){if(!(W instanceof Date))return null;let $=new ArrayBuffer(8);return new DataView($).setFloat64(0,W.getTime()),new Uint8Array($)}function AW(W){let $=new DataView(W.buffer,W.byteOffset,W.byteLength).getFloat64(0);return new Date($)}function R0(W){return typeof W==="object"&&W!==null&&"__tag"in W&&W.__tag===zW}function _(W,$){if(W===void 0)return N0;if(W===null||typeof W!=="object")return W;if($.has(W))return W;$.add(W);try{return M0(W,$)}finally{$.delete(W)}}function M0(W,$){if(Array.isArray(W))return U0(W,$);if(W instanceof Map)return _0(W,$);if(W instanceof Set)return B0(W,$);if(K0(W))return W;return O0(W,$)}function U0(W,$){let Z=Array.from({length:W.length});for(let G=0;G<W.length;G++)Z[G]=_(W[G],$);return Z}function _0(W,$){let Z=new Map;for(let[G,J]of W)Z.set(_(G,$),_(J,$));return Z}function B0(W,$){let Z=new Set;for(let G of W)Z.add(_(G,$));return Z}function K0(W){return W instanceof Date||W instanceof RegExp||W instanceof Error||W instanceof Uint8Array||W instanceof ArrayBuffer}function O0(W,$){let Z=W,G={};for(let J of Object.keys(Z))G[J]=_(Z[J],$);return G}var F0=1,X0=2,Y0=3,H0=4,V0=5,P0=6,P,zW,N0;var TW=X(()=>{c();P=new R;P.register({type:F0,encode:OW,decode:AW});P.register({type:X0,encode(W){if(W instanceof RegExp)return M({source:W.source,flags:W.flags});return null},decode(W){let $=d(U(W)),Z=typeof $.source==="string"?$.source:"",G=typeof $.flags==="string"?$.flags:"";return new RegExp(Z,G)}});P.register({type:Y0,encode(W){if(W instanceof Map){let $=[...W.entries()];return M($,{extensionCodec:P})}return null},decode(W){let Z=h(U(W,{extensionCodec:P})).map((G)=>{let J=h(G);return[J[0],J[1]]});return new Map(Z)}});P.register({type:H0,encode(W){if(W instanceof Set){let $=[...W.values()];return M($,{extensionCodec:P})}return null},decode(W){let $=h(U(W,{extensionCodec:P}));return new Set($)}});zW=Symbol("UndefinedSentinel"),N0=Object.freeze({__tag:zW});P.register({type:V0,encode(W){if(R0(W))return new Uint8Array(0);return null},decode(){return}});P.register({type:P0,encode(W){if(W instanceof Error)return M({name:W.name,message:W.message,stack:W.stack});return null},decode(W){let $=d(U(W)),Z=typeof $.name==="string"?$.name:"Error",G=typeof $.message==="string"?$.message:"",J=typeof $.stack==="string"?$.stack:void 0,Q=Error(G);if(Q.name=Z,J!==void 0)Q.stack=J;return Q}})});function n(W){let $=_(W,new Set);return M($,{extensionCodec:P})}function i(W){return U(W,{extensionCodec:P})}var DW=X(()=>{c();TW()});function m(W,$=""){let Z=[];return I(W,$,Z,new Set),{valid:Z.length===0,errors:Z}}function A0(W){let $=Object.getPrototypeOf(W);return z0($)&&!T0(W)&&D0($)}function z0(W){return W!==Object.prototype&&W!==null}function T0(W){return Array.isArray(W)||W instanceof Date||W instanceof RegExp||W instanceof Map||W instanceof Set||W instanceof Error||W instanceof Uint8Array||W instanceof ArrayBuffer}function D0(W){if(typeof W!=="object"||W===null)return!1;return Object.getOwnPropertyNames(W).some((Z)=>{if(Z==="constructor")return!1;let G=Object.getOwnPropertyDescriptor(W,Z);return G!==void 0&&typeof G.value==="function"})}function LW(W,$,Z,G){W.push({path:$,value:Z,reason:G.reason,suggestion:G.suggestion})}function L0(W){if(typeof W==="function")return{reason:"Functions cannot be serialized.",suggestion:"Move this into ctx.run() or reconstruct it on resume."};if(typeof W==="symbol")return{reason:"Symbols cannot be serialized.",suggestion:"Use a string identifier instead of a Symbol."};return null}function I0(W,$){if(W instanceof WeakRef)return{reason:"WeakRef cannot be serialized.",suggestion:"Store the referenced value directly instead of using a WeakRef."};if(W instanceof WeakMap)return{reason:"WeakMap cannot be serialized.",suggestion:"Use a Map instead of a WeakMap."};if(W instanceof WeakSet)return{reason:"WeakSet cannot be serialized.",suggestion:"Use a Set instead of a WeakSet."};if($.has(W))return{reason:"Circular reference detected.",suggestion:"Remove the circular reference or restructure the data."};if(A0(W))return{reason:"Class instances with methods cannot be serialized.",suggestion:"Store only the data and reconstruct the instance."};return null}function C0(W){return W instanceof Date||W instanceof RegExp||W instanceof Error||W instanceof Uint8Array||W instanceof ArrayBuffer}function x0(W,$,Z,G){for(let[J,Q]of W){let F=String(J);I(Q,$?`${$}.${F}`:F,Z,G)}}function S0(W,$,Z,G){let J=0;for(let Q of W){let F=$?`${$}[${J}]`:`[${J}]`;I(Q,F,Z,G),J++}}function E0(W,$,Z,G){for(let J=0;J<W.length;J++){let Q=$?`${$}[${J}]`:`[${J}]`;I(W[J],Q,Z,G)}}function k0(W,$,Z,G){for(let J of Object.keys(W)){let Q=$?`${$}.${J}`:J;I(W[J],Q,Z,G)}}function I(W,$,Z,G){if(W===null||W===void 0)return;let J=L0(W);if(J){LW(Z,$,W,J);return}if(typeof W!=="object")return;let Q=I0(W,G);if(Q){LW(Z,$,W,Q);return}G.add(W);try{if(C0(W))return;if(W instanceof Map){x0(W,$,Z,G);return}if(W instanceof Set){S0(W,$,Z,G);return}if(Array.isArray(W)){E0(W,$,Z,G);return}k0(W,$,Z,G)}finally{G.delete(W)}}var IW=X(()=>{DW()});var CW=X(()=>{IW()});function w0(W){if(W===void 0)return;if(typeof W!=="number"||!Number.isInteger(W)||W<0)throw Error("deleteRange limit must be a finite non-negative integer");return W===0?0:W}function j0(W){let $={},Z=!1;for(let J of["gt","gte","lt","lte"]){let Q=W[J];if(Q===void 0)continue;if(typeof Q!=="string")throw Error("deleteRange bounds must be strings");$[J]=Q,Z=!0}if(!Z)throw Error("deleteRange requires at least one of gt/gte/lt/lte; use deletePrefix to delete a whole prefix");let G=w0(W.limit);if(G!==void 0)$.limit=G;return $}async function xW(W,$,Z){let G=j0(Z);if(W.deleteRange)return W.deleteRange($,G);return o(W,$,G)}var SW=()=>{};CW();SW();JW();class EW{#W;#$;#Z;constructor(W,$,Z={}){this.#W=W,this.#$=$,this.#Z=Z.disposeUnderlyingStorage??!0}async get(W){let $=await this.#W.get(W);return $===null?null:this.#$.decode($)}async put(W,$){await this.#W.put(W,this.#$.encode($))}async delete(W){await this.#W.delete(W)}async*scan(W,$){for await(let[Z,G]of this.#W.scan(W,$))yield[Z,this.#$.decode(G)]}async batch(W){await this.#W.batch(this.#G(W))}#G(W){return W.map((Z)=>{if(Z.type==="put")return{type:"put",key:Z.key,value:this.#$.encode(Z.value)};return Z})}#J(W){return W.map(($)=>({key:$.key,expectedValue:$.expectedValue===null?null:this.#$.encode($.expectedValue)}))}async conditionalBatch(W,$){return GW(this.#W,this.#J(W),this.#G($))}async has(W){return e(this.#W,W)}async deletePrefix(W){return ZW(this.#W,W)}async deleteRange(W,$){return xW(this.#W,W,$)}keys(W,$){return WW(this.#W,W,$)}async count(W){return $W(this.#W,W)}[Symbol.dispose](){if(!this.#Z)return;this.#W[Symbol.dispose]()}}function z6(W,$,Z={}){return new EW(W,$,Z)}function h0(W){try{let $=JSON.stringify(W);if($===void 0)throw TypeError("jsonCodec only supports JSON-serializable values.");return new TextEncoder().encode($)}catch($){throw TypeError("jsonCodec only supports JSON-serializable values.",{cause:$})}}function m0(W){let $=m(W);if(!$.valid)throw TypeError(`msgpackCodec only supports structuredClone-compatible values. ${$.errors[0]?.reason??""}`.trim());return n(W)}function g0(W){return JSON.parse(new TextDecoder().decode(W))}function v0(W){let $=i(W),Z=m($);if(!Z.valid)throw TypeError(`msgpackCodec decoded a non-cloneable value. ${Z.errors[0]?.reason??""}`.trim());return $}function T6(W){return{encode($){return h0($)},decode($){let Z=g0($);return W?W(Z):Z}}}function D6(W){return{encode($){return m0($)},decode($){let Z=v0($);return W?W(Z):Z}}}export{z6 as withCodec,D6 as msgpackCodec,T6 as jsonCodec};
|
|
2
|
+
var wW=Object.defineProperty;var jW=(W)=>W;function hW(W,$){this[W]=jW.bind(null,$)}var b0=(W,$)=>{for(var Z in $)wW(W,Z,{get:$[Z],enumerable:!0,configurable:!0,set:hW.bind($,Z)})};var X=(W,$)=>()=>(W&&($=W(W=0)),$);function v(W,$,Z){if(!W.capabilities()[$])throw Error(`Feature "${Z}" requires storage capability "${$}", but this storage backend does not provide it.`)}function mW(W){let $=W.capabilities(),Z=[];if($.persistence!=="local")Z.push(`persistence must be "local" (got "${$.persistence}")`);if($.readAfterWrite!=="linearizable")Z.push(`readAfterWrite must be "linearizable" (got "${$.readAfterWrite}")`);if($.scanConsistency!=="snapshot")Z.push(`scanConsistency must be "snapshot" (got "${$.scanConsistency}")`);if(!$.atomicBatch)Z.push("atomicBatch must be true");if(!$.conditionalBatch)Z.push("conditionalBatch must be true");if(Z.length>0)throw Error(`Storage is not durable enough for recovery: ${Z.join("; ")}.`)}var b="default";async function r(W,$){return await W.get($)!==null}async function*z(W,$,Z){for await(let[G]of W.scan($,Z))yield G}async function s(W,$){let Z=0;for await(let G of z(W,$))Z++;return Z}async function a(W,$){let Z=[];for await(let G of z(W,$))Z.push({type:"delete",key:G});if(Z.length===0)return 0;return await W.batch(Z),Z.length}async function o(W,$,Z){let G=[];for await(let J of z(W,$,Z))G.push({type:"delete",key:J});if(G.length===0)return 0;return await W.batch(G),G.length}var gW;var t=X(()=>{gW=["actrec:","archive:","async-act:","attr:","audit:bulk:","blob:","budget:","budget-charged:","ev:","idx:","offload:","op:","review:","schedule:","schedule-due:","schedule-run:","sig:","sigres:","sigseq:","state:","tag:","tool-effect:","upd:","upk:","upr:","wf:","wf-cleanup:","wf-cleanup-needed:","wf-deadline:","wf-delayed:","wf-has-services:","wf-headers:","wf-idx-","wf-terminal:"]});function i0(W){return W.length>0?W.slice(0,-1)+String.fromCharCode(W.charCodeAt(W.length-1)+1):"\xFF"}function r0(W,$={}){if($.gt!==void 0&&W<=$.gt)return!1;if($.gte!==void 0&&W<$.gte)return!1;if($.lt!==void 0&&W>=$.lt)return!1;if($.lte!==void 0&&W>$.lte)return!1;return!0}function s0(W,$){if(W===null||$===null)return W===$;if(W.byteLength!==$.byteLength)return!1;for(let Z=0;Z<W.byteLength;Z++)if(W[Z]!==$[Z])return!1;return!0}async function e(W,$){if(W.has)return W.has($);return r(W,$)}function WW(W,$,Z){if(W.keys)return W.keys($,Z);return z(W,$,Z)}async function $W(W,$){if(W.count)return W.count($);return s(W,$)}async function ZW(W,$){if(W.deletePrefix)return W.deletePrefix($);return a(W,$)}async function GW(W,$,Z){if(v(W,"conditionalBatch","storageConditionalBatch"),!W.conditionalBatch)throw Error("This storage backend reports conditionalBatch capability but does not implement the conditionalBatch() method.");return W.conditionalBatch($,Z)}function Q(W){return encodeURIComponent(W)}function a0(W){return decodeURIComponent(W)}function o0(W){try{return decodeURIComponent(W)}catch{return null}}var N=(W)=>String(W).padStart(16,"0"),t0;var JW=X(()=>{t();t0={workflow:(W)=>`wf:${Q(W)}`,checkpoint:(W)=>`wf:${Q(W)}:ckpt`,checkpointHistory:(W,$)=>`wf:${Q(W)}:ckpt:${String($).padStart(10,"0")}`,timelinePrefix:(W)=>`wf:${Q(W)}:timeline:`,timeline:(W,$)=>`wf:${Q(W)}:timeline:${String($).padStart(10,"0")}`,schedule:(W)=>`schedule:${Q(W)}`,scheduleTick:(W,$)=>`schedule-due:${String(W).padStart(16,"0")}:${Q($)}`,scheduleRun:(W)=>`schedule-run:${Q(W)}`,operation:(W,$,Z)=>`op:${W}:${N($)}:${Z}`,operationInflight:(W)=>`op:inflight:${W}`,operationQueued:(W)=>`op:queued:${W}`,operationResolved:(W)=>`op:resolved:${W}`,bulkOperationAuditPrefix:()=>"audit:bulk:",bulkOperationAudit:(W,$,Z)=>`audit:bulk:${N(W)}:${Q($)}:${Q(Z)}`,operationResolvedByTimePrefix:()=>"op:resolved-by-time:",operationResolvedByTime:(W,$)=>`op:resolved-by-time:${N(W)}:${Q($)}`,asyncActivity:(W,$)=>`async-act:v1:${Q(W)}:${Q($)}`,activityReconciliationPrefix:(W)=>`actrec:v1:${Q(W)}:`,activityReconciliation:(W,$,Z)=>`actrec:v1:${Q(W)}:${Q($)}:${Z}`,eventPrefix:(W)=>`ev:${Q(W)}:`,event:(W,$)=>`ev:${Q(W)}:${String($).padStart(10,"0")}`,eventHead:(W)=>`ev:${Q(W)}:head`,eventWatermark:(W)=>`ev:${Q(W)}:watermark`,signal:(W,$,Z)=>`sig:${Q(W)}:${$}:${Q(Z)}`,signalSequence:(W)=>`sigseq:v1:${Q(W)}`,signalAcceptedResponsePrefix:(W)=>`sigres:v1:${Q(W)}:`,signalAcceptedResponse:(W,$,Z)=>`sigres:v1:${Q(W)}:${Q($)}:${Q(Z)}`,deadline:(W,$)=>`wf-deadline:${N(W)}:${Q($)}`,terminalCleanup:(W,$)=>`wf-cleanup:${N(W)}:${Q($)}`,delayedStart:(W,$)=>`wf-delayed:${N(W)}:${Q($)}`,terminalWorkflowPrefix:()=>"wf-terminal:",terminalWorkflow:(W,$)=>`wf-terminal:${N(W)}:${Q($)}`,attribute:(W)=>`attr:${Q(W)}`,attributeIndex:(W,$,Z)=>`idx:${W}:${$}:${Q(Z)}`,tagIndex:(W,$)=>`tag:${Q(W)}:${Q($)}`,updatePrefix:(W)=>`upd:${Q(W)}:`,update:(W,$)=>`upd:${Q(W)}:${$}`,updateResponse:(W)=>`upr:${W}`,updateIdempotency:(W,$)=>`upk:${Q(W)}:${$}`,budget:(W,$,Z)=>`budget:${W}:${$}:${Z}`,review:(W,$)=>`review:${Q(W)}:${$}`,workflowHeaders:(W)=>`wf-headers:${Q(W)}`,terminalCleanupNeeded:(W)=>`wf-cleanup-needed:${Q(W)}`,workflowHasServices:(W)=>`wf-has-services:${Q(W)}`,offload:(W,$)=>`offload:${Q(W)}:${$}`,archive:(W,$)=>`archive:${Q(W)}:${$}`,stateExecution:(W,$)=>`state:execution:${Q(W)}:${Q($)}`,stateWorkflow:(W,$)=>`state:workflow-scope:${b}:${Q(W)}:${Q($)}`,streamChunkPrefix:(W,$)=>`blob:${Q(W)}:${$}:chunk:`,streamChunk:(W,$,Z)=>`blob:${Q(W)}:${$}:chunk:${String(Z).padStart(10,"0")}`,streamMetadata:(W,$)=>`blob:${Q(W)}:${$}:meta`,budgetCharged:(W)=>`budget-charged:${W}`,toolEffect:(W,$,Z)=>`tool-effect:${Q(W)}:${$}:${Z}`,workflowVisibilityStatus:(W,$)=>`wf-idx-status:${Q(W)}:${Q($)}`,workflowVisibilityType:(W,$)=>`wf-idx-type:${Q(W)}:${Q($)}`,workflowVisibilityCreated:(W,$)=>`wf-idx-created:${N(W)}:${Q($)}`,workflowVisibilityUpdated:(W,$)=>`wf-idx-updated:${N(W)}:${Q($)}`,workflowVisibilityDeadline:(W,$)=>`wf-idx-deadline:${N(W)}:${Q($)}`,workflowVisibilityManifest:(W)=>`wf-idx-manifest:${Q(W)}`,workflowVisibilityMetaVersion:()=>"wf-idx-meta:version",workflowVisibilityMetaBuiltAt:()=>"wf-idx-meta:built-at",workflowVisibilityMetaCursor:()=>"wf-idx-meta:cursor"}});function QW(W){let $=W.length,Z=0,G=0;while(G<$){let J=W.charCodeAt(G++);if((J&4294967168)===0){Z++;continue}else if((J&4294965248)===0)Z+=2;else{if(J>=55296&&J<=56319){if(G<$){let q=W.charCodeAt(G);if((q&64512)===56320)++G,J=((J&1023)<<10)+(q&1023)+65536}}if((J&4294901760)===0)Z+=3;else Z+=4}}return Z}function vW(W,$,Z){let G=W.length,J=Z,q=0;while(q<G){let F=W.charCodeAt(q++);if((F&4294967168)===0){$[J++]=F;continue}else if((F&4294965248)===0)$[J++]=F>>6&31|192;else{if(F>=55296&&F<=56319){if(q<G){let H=W.charCodeAt(q);if((H&64512)===56320)++q,F=((F&1023)<<10)+(H&1023)+65536}}if((F&4294901760)===0)$[J++]=F>>12&15|224,$[J++]=F>>6&63|128;else $[J++]=F>>18&7|240,$[J++]=F>>12&63|128,$[J++]=F>>6&63|128}$[J++]=F&63|128}}function fW(W,$,Z){bW.encodeInto(W,$.subarray(Z))}function qW(W,$,Z){if(W.length>yW)fW(W,$,Z);else vW(W,$,Z)}function y(W,$,Z){let G=$,J=G+Z,q=[],F="";while(G<J){let H=W[G++];if((H&128)===0)q.push(H);else if((H&224)===192){let A=W[G++]&63;q.push((H&31)<<6|A)}else if((H&240)===224){let A=W[G++]&63,g=W[G++]&63;q.push((H&31)<<12|A<<6|g)}else if((H&248)===240){let A=W[G++]&63,g=W[G++]&63,kW=W[G++]&63,B=(H&7)<<18|A<<12|g<<6|kW;if(B>65535)B-=65536,q.push(B>>>10&1023|55296),B=56320|B&1023;q.push(B)}else q.push(H);if(q.length>=lW)F+=String.fromCharCode(...q),q.length=0}if(q.length>0)F+=String.fromCharCode(...q);return F}function cW(W,$,Z){let G=W.subarray($,$+Z);return pW.decode(G)}function FW(W,$,Z){if(Z>uW)return cW(W,$,Z);else return y(W,$,Z)}var bW,yW=50,lW=4096,pW,uW=200;var C=X(()=>{bW=new TextEncoder;pW=new TextDecoder});class O{type;data;constructor(W,$){this.type=W,this.data=$}}var V;var f=X(()=>{V=class V extends Error{constructor(W){super(W);let $=Object.create(V.prototype);Object.setPrototypeOf(this,$),Object.defineProperty(this,"name",{configurable:!0,enumerable:!1,value:V.name})}}});function XW(W,$,Z){let G=Z/4294967296,J=Z;W.setUint32($,G),W.setUint32($+4,J)}function x(W,$,Z){let G=Math.floor(Z/4294967296),J=Z;W.setUint32($,G),W.setUint32($+4,J)}function S(W,$){let Z=W.getInt32($),G=W.getUint32($+4);return Z*4294967296+G}function YW(W,$){let Z=W.getUint32($),G=W.getUint32($+4);return Z*4294967296+G}var K=4294967295;function rW({sec:W,nsec:$}){if(W>=0&&$>=0&&W<=iW)if($===0&&W<=nW){let Z=new Uint8Array(4);return new DataView(Z.buffer).setUint32(0,W),Z}else{let Z=W/4294967296,G=W&4294967295,J=new Uint8Array(8),q=new DataView(J.buffer);return q.setUint32(0,$<<2|Z&3),q.setUint32(4,G),J}else{let Z=new Uint8Array(12),G=new DataView(Z.buffer);return G.setUint32(0,$),x(G,4,W),Z}}function sW(W){let $=W.getTime(),Z=Math.floor($/1000),G=($-Z*1000)*1e6,J=Math.floor(G/1e9);return{sec:Z+J,nsec:G-J*1e9}}function aW(W){if(W instanceof Date){let $=sW(W);return rW($)}else return null}function oW(W){let $=new DataView(W.buffer,W.byteOffset,W.byteLength);switch(W.byteLength){case 4:{let Z=$.getUint32(0),G=0;return{sec:Z,nsec:0}}case 8:{let Z=$.getUint32(0),G=$.getUint32(4),J=(Z&3)*4294967296+G,q=Z>>>2;return{sec:J,nsec:q}}case 12:{let Z=S($,4),G=$.getUint32(0);return{sec:Z,nsec:G}}default:throw new V(`Unrecognized data size for timestamp (expected 4, 8, or 12): ${W.length}`)}}function tW(W){let $=oW(W);return new Date($.sec*1000+$.nsec/1e6)}var dW=-1,nW=4294967295,iW=17179869183,HW;var VW=X(()=>{f();HW={type:dW,encode:aW,decode:tW}});var R;var E=X(()=>{VW();R=class R{static defaultCodec=new R;__brand;builtInEncoders=[];builtInDecoders=[];encoders=[];decoders=[];constructor(){this.register(HW)}register({type:W,encode:$,decode:Z}){if(W>=0)this.encoders[W]=$,this.decoders[W]=Z;else{let G=-1-W;this.builtInEncoders[G]=$,this.builtInDecoders[G]=Z}}tryToEncode(W,$){for(let Z=0;Z<this.builtInEncoders.length;Z++){let G=this.builtInEncoders[Z];if(G!=null){let J=G(W,$);if(J!=null){let q=-1-Z;return new O(q,J)}}}for(let Z=0;Z<this.encoders.length;Z++){let G=this.encoders[Z];if(G!=null){let J=G(W,$);if(J!=null)return new O(Z,J)}}if(W instanceof O)return W;return null}decode(W,$,Z){let G=$<0?this.builtInDecoders[-1-$]:this.decoders[$];if(G)return G(W,$,Z);else return new O($,W)}}});function eW(W){return W instanceof ArrayBuffer||typeof SharedArrayBuffer<"u"&&W instanceof SharedArrayBuffer}function T(W){if(W instanceof Uint8Array)return W;else if(ArrayBuffer.isView(W))return new Uint8Array(W.buffer,W.byteOffset,W.byteLength);else if(eW(W))return new Uint8Array(W);else return Uint8Array.from(W)}class k{extensionCodec;context;useBigInt64;maxDepth;initialBufferSize;sortKeys;forceFloat32;ignoreUndefined;forceIntegerToFloat;pos;view;bytes;entered=!1;constructor(W){this.extensionCodec=W?.extensionCodec??R.defaultCodec,this.context=W?.context,this.useBigInt64=W?.useBigInt64??!1,this.maxDepth=W?.maxDepth??W0,this.initialBufferSize=W?.initialBufferSize??$0,this.sortKeys=W?.sortKeys??!1,this.forceFloat32=W?.forceFloat32??!1,this.ignoreUndefined=W?.ignoreUndefined??!1,this.forceIntegerToFloat=W?.forceIntegerToFloat??!1,this.pos=0,this.view=new DataView(new ArrayBuffer(this.initialBufferSize)),this.bytes=new Uint8Array(this.view.buffer)}clone(){return new k({extensionCodec:this.extensionCodec,context:this.context,useBigInt64:this.useBigInt64,maxDepth:this.maxDepth,initialBufferSize:this.initialBufferSize,sortKeys:this.sortKeys,forceFloat32:this.forceFloat32,ignoreUndefined:this.ignoreUndefined,forceIntegerToFloat:this.forceIntegerToFloat})}reinitializeState(){this.pos=0}encodeSharedRef(W){if(this.entered)return this.clone().encodeSharedRef(W);try{return this.entered=!0,this.reinitializeState(),this.doEncode(W,1),this.bytes.subarray(0,this.pos)}finally{this.entered=!1}}encode(W){if(this.entered)return this.clone().encode(W);try{return this.entered=!0,this.reinitializeState(),this.doEncode(W,1),this.bytes.slice(0,this.pos)}finally{this.entered=!1}}doEncode(W,$){if($>this.maxDepth)throw Error(`Too deep objects in depth ${$}`);if(W==null)this.encodeNil();else if(typeof W==="boolean")this.encodeBoolean(W);else if(typeof W==="number")if(!this.forceIntegerToFloat)this.encodeNumber(W);else this.encodeNumberAsFloat(W);else if(typeof W==="string")this.encodeString(W);else if(this.useBigInt64&&typeof W==="bigint")this.encodeBigInt64(W);else this.encodeObject(W,$)}ensureBufferSizeToWrite(W){let $=this.pos+W;if(this.view.byteLength<$)this.resizeBuffer($*2)}resizeBuffer(W){let $=new ArrayBuffer(W),Z=new Uint8Array($),G=new DataView($);Z.set(this.bytes),this.view=G,this.bytes=Z}encodeNil(){this.writeU8(192)}encodeBoolean(W){if(W===!1)this.writeU8(194);else this.writeU8(195)}encodeNumber(W){if(!this.forceIntegerToFloat&&Number.isSafeInteger(W))if(W>=0)if(W<128)this.writeU8(W);else if(W<256)this.writeU8(204),this.writeU8(W);else if(W<65536)this.writeU8(205),this.writeU16(W);else if(W<4294967296)this.writeU8(206),this.writeU32(W);else if(!this.useBigInt64)this.writeU8(207),this.writeU64(W);else this.encodeNumberAsFloat(W);else if(W>=-32)this.writeU8(224|W+32);else if(W>=-128)this.writeU8(208),this.writeI8(W);else if(W>=-32768)this.writeU8(209),this.writeI16(W);else if(W>=-2147483648)this.writeU8(210),this.writeI32(W);else if(!this.useBigInt64)this.writeU8(211),this.writeI64(W);else this.encodeNumberAsFloat(W);else this.encodeNumberAsFloat(W)}encodeNumberAsFloat(W){if(this.forceFloat32)this.writeU8(202),this.writeF32(W);else this.writeU8(203),this.writeF64(W)}encodeBigInt64(W){if(W>=BigInt(0))this.writeU8(207),this.writeBigUint64(W);else this.writeU8(211),this.writeBigInt64(W)}writeStringHeader(W){if(W<32)this.writeU8(160+W);else if(W<256)this.writeU8(217),this.writeU8(W);else if(W<65536)this.writeU8(218),this.writeU16(W);else if(W<4294967296)this.writeU8(219),this.writeU32(W);else throw Error(`Too long string: ${W} bytes in UTF-8`)}encodeString(W){let Z=QW(W);this.ensureBufferSizeToWrite(5+Z),this.writeStringHeader(Z),qW(W,this.bytes,this.pos),this.pos+=Z}encodeObject(W,$){let Z=this.extensionCodec.tryToEncode(W,this.context);if(Z!=null)this.encodeExtension(Z);else if(Array.isArray(W))this.encodeArray(W,$);else if(ArrayBuffer.isView(W))this.encodeBinary(W);else if(typeof W==="object")this.encodeMap(W,$);else throw Error(`Unrecognized object: ${Object.prototype.toString.apply(W)}`)}encodeBinary(W){let $=W.byteLength;if($<256)this.writeU8(196),this.writeU8($);else if($<65536)this.writeU8(197),this.writeU16($);else if($<4294967296)this.writeU8(198),this.writeU32($);else throw Error(`Too large binary: ${$}`);let Z=T(W);this.writeU8a(Z)}encodeArray(W,$){let Z=W.length;if(Z<16)this.writeU8(144+Z);else if(Z<65536)this.writeU8(220),this.writeU16(Z);else if(Z<4294967296)this.writeU8(221),this.writeU32(Z);else throw Error(`Too large array: ${Z}`);for(let G of W)this.doEncode(G,$+1)}countWithoutUndefined(W,$){let Z=0;for(let G of $)if(W[G]!==void 0)Z++;return Z}encodeMap(W,$){let Z=Object.keys(W);if(this.sortKeys)Z.sort();let G=this.ignoreUndefined?this.countWithoutUndefined(W,Z):Z.length;if(G<16)this.writeU8(128+G);else if(G<65536)this.writeU8(222),this.writeU16(G);else if(G<4294967296)this.writeU8(223),this.writeU32(G);else throw Error(`Too large map object: ${G}`);for(let J of Z){let q=W[J];if(!(this.ignoreUndefined&&q===void 0))this.encodeString(J),this.doEncode(q,$+1)}}encodeExtension(W){if(typeof W.data==="function"){let Z=W.data(this.pos+6),G=Z.length;if(G>=4294967296)throw Error(`Too large extension object: ${G}`);this.writeU8(201),this.writeU32(G),this.writeI8(W.type),this.writeU8a(Z);return}let $=W.data.length;if($===1)this.writeU8(212);else if($===2)this.writeU8(213);else if($===4)this.writeU8(214);else if($===8)this.writeU8(215);else if($===16)this.writeU8(216);else if($<256)this.writeU8(199),this.writeU8($);else if($<65536)this.writeU8(200),this.writeU16($);else if($<4294967296)this.writeU8(201),this.writeU32($);else throw Error(`Too large extension object: ${$}`);this.writeI8(W.type),this.writeU8a(W.data)}writeU8(W){this.ensureBufferSizeToWrite(1),this.view.setUint8(this.pos,W),this.pos++}writeU8a(W){let $=W.length;this.ensureBufferSizeToWrite($),this.bytes.set(W,this.pos),this.pos+=$}writeI8(W){this.ensureBufferSizeToWrite(1),this.view.setInt8(this.pos,W),this.pos++}writeU16(W){this.ensureBufferSizeToWrite(2),this.view.setUint16(this.pos,W),this.pos+=2}writeI16(W){this.ensureBufferSizeToWrite(2),this.view.setInt16(this.pos,W),this.pos+=2}writeU32(W){this.ensureBufferSizeToWrite(4),this.view.setUint32(this.pos,W),this.pos+=4}writeI32(W){this.ensureBufferSizeToWrite(4),this.view.setInt32(this.pos,W),this.pos+=4}writeF32(W){this.ensureBufferSizeToWrite(4),this.view.setFloat32(this.pos,W),this.pos+=4}writeF64(W){this.ensureBufferSizeToWrite(8),this.view.setFloat64(this.pos,W),this.pos+=8}writeU64(W){this.ensureBufferSizeToWrite(8),XW(this.view,this.pos,W),this.pos+=8}writeI64(W){this.ensureBufferSizeToWrite(8),x(this.view,this.pos,W),this.pos+=8}writeBigUint64(W){this.ensureBufferSizeToWrite(8),this.view.setBigUint64(this.pos,W),this.pos+=8}writeBigInt64(W){this.ensureBufferSizeToWrite(8),this.view.setBigInt64(this.pos,W),this.pos+=8}}var W0=100,$0=2048;var PW=X(()=>{C();E()});function M(W,$){return new k($).encodeSharedRef(W)}var NW=X(()=>{PW()});function w(W){return`${W<0?"-":""}0x${Math.abs(W).toString(16).padStart(2,"0")}`}class l{hit=0;miss=0;caches;maxKeyLength;maxLengthPerKey;constructor(W=Z0,$=G0){this.maxKeyLength=W,this.maxLengthPerKey=$,this.caches=[];for(let Z=0;Z<this.maxKeyLength;Z++)this.caches.push([])}canBeCached(W){return W>0&&W<=this.maxKeyLength}find(W,$,Z){let G=this.caches[Z-1];W:for(let J of G){let q=J.bytes;for(let F=0;F<Z;F++)if(q[F]!==W[$+F])continue W;return J.str}return null}store(W,$){let Z=this.caches[W.length-1],G={bytes:W,str:$};if(Z.length>=this.maxLengthPerKey)Z[Math.random()*Z.length|0]=G;else Z.push(G)}decode(W,$,Z){let G=this.find(W,$,Z);if(G!=null)return this.hit++,G;this.miss++;let J=y(W,$,Z),q=Uint8Array.prototype.slice.call(W,$,$+Z);return this.store(q,J),J}}var Z0=16,G0=16;var RW=X(()=>{C()});class _W{stack=[];stackHeadPosition=-1;get length(){return this.stackHeadPosition+1}top(){return this.stack[this.stackHeadPosition]}pushArrayState(W){let $=this.getUninitializedStateFromPool();$.type=p,$.position=0,$.size=W,$.array=Array(W)}pushMapState(W){let $=this.getUninitializedStateFromPool();$.type=L,$.readCount=0,$.size=W,$.map={}}getUninitializedStateFromPool(){if(this.stackHeadPosition++,this.stackHeadPosition===this.stack.length){let W={type:void 0,size:0,array:void 0,position:0,readCount:0,map:void 0,key:null};this.stack.push(W)}return this.stack[this.stackHeadPosition]}release(W){if(this.stack[this.stackHeadPosition]!==W)throw Error("Invalid stack state. Released state is not on top of the stack.");if(W.type===p){let Z=W;Z.size=0,Z.array=void 0,Z.position=0,Z.type=void 0}if(W.type===L||W.type===UW){let Z=W;Z.size=0,Z.map=void 0,Z.readCount=0,Z.type=void 0}this.stackHeadPosition--}reset(){this.stack.length=0,this.stackHeadPosition=-1}}class j{extensionCodec;context;useBigInt64;rawStrings;maxStrLength;maxBinLength;maxArrayLength;maxMapLength;maxExtLength;keyDecoder;mapKeyConverter;totalPos=0;pos=0;view=u;bytes=Q0;headByte=D;stack=new _W;entered=!1;constructor(W){this.extensionCodec=W?.extensionCodec??R.defaultCodec,this.context=W?.context,this.useBigInt64=W?.useBigInt64??!1,this.rawStrings=W?.rawStrings??!1,this.maxStrLength=W?.maxStrLength??K,this.maxBinLength=W?.maxBinLength??K,this.maxArrayLength=W?.maxArrayLength??K,this.maxMapLength=W?.maxMapLength??K,this.maxExtLength=W?.maxExtLength??K,this.keyDecoder=W?.keyDecoder!==void 0?W.keyDecoder:q0,this.mapKeyConverter=W?.mapKeyConverter??J0}clone(){return new j({extensionCodec:this.extensionCodec,context:this.context,useBigInt64:this.useBigInt64,rawStrings:this.rawStrings,maxStrLength:this.maxStrLength,maxBinLength:this.maxBinLength,maxArrayLength:this.maxArrayLength,maxMapLength:this.maxMapLength,maxExtLength:this.maxExtLength,keyDecoder:this.keyDecoder})}reinitializeState(){this.totalPos=0,this.headByte=D,this.stack.reset()}setBuffer(W){let $=T(W);this.bytes=$,this.view=new DataView($.buffer,$.byteOffset,$.byteLength),this.pos=0}appendBuffer(W){if(this.headByte===D&&!this.hasRemaining(1))this.setBuffer(W);else{let $=this.bytes.subarray(this.pos),Z=T(W),G=new Uint8Array($.length+Z.length);G.set($),G.set(Z,$.length),this.setBuffer(G)}}hasRemaining(W){return this.view.byteLength-this.pos>=W}createExtraByteError(W){let{view:$,pos:Z}=this;return RangeError(`Extra ${$.byteLength-Z} of ${$.byteLength} byte(s) found at buffer[${W}]`)}decode(W){if(this.entered)return this.clone().decode(W);try{this.entered=!0,this.reinitializeState(),this.setBuffer(W);let $=this.doDecodeSync();if(this.hasRemaining(1))throw this.createExtraByteError(this.pos);return $}finally{this.entered=!1}}*decodeMulti(W){if(this.entered){yield*this.clone().decodeMulti(W);return}try{this.entered=!0,this.reinitializeState(),this.setBuffer(W);while(this.hasRemaining(1))yield this.doDecodeSync()}finally{this.entered=!1}}async decodeAsync(W){if(this.entered)return this.clone().decodeAsync(W);try{this.entered=!0;let $=!1,Z;for await(let F of W){if($)throw this.entered=!1,this.createExtraByteError(this.totalPos);this.appendBuffer(F);try{Z=this.doDecodeSync(),$=!0}catch(H){if(!(H instanceof RangeError))throw H}this.totalPos+=this.pos}if($){if(this.hasRemaining(1))throw this.createExtraByteError(this.totalPos);return Z}let{headByte:G,pos:J,totalPos:q}=this;throw RangeError(`Insufficient data in parsing ${w(G)} at ${q} (${J} in the current buffer)`)}finally{this.entered=!1}}decodeArrayStream(W){return this.decodeMultiAsync(W,!0)}decodeStream(W){return this.decodeMultiAsync(W,!1)}async*decodeMultiAsync(W,$){if(this.entered){yield*this.clone().decodeMultiAsync(W,$);return}try{this.entered=!0;let Z=$,G=-1;for await(let J of W){if($&&G===0)throw this.createExtraByteError(this.totalPos);if(this.appendBuffer(J),Z)G=this.readArraySize(),Z=!1,this.complete();try{while(!0)if(yield this.doDecodeSync(),--G===0)break}catch(q){if(!(q instanceof RangeError))throw q}this.totalPos+=this.pos}}finally{this.entered=!1}}doDecodeSync(){W:while(!0){let W=this.readHeadByte(),$;if(W>=224)$=W-256;else if(W<192)if(W<128)$=W;else if(W<144){let G=W-128;if(G!==0){this.pushMapState(G),this.complete();continue W}else $={}}else if(W<160){let G=W-144;if(G!==0){this.pushArrayState(G),this.complete();continue W}else $=[]}else{let G=W-160;$=this.decodeString(G,0)}else if(W===192)$=null;else if(W===194)$=!1;else if(W===195)$=!0;else if(W===202)$=this.readF32();else if(W===203)$=this.readF64();else if(W===204)$=this.readU8();else if(W===205)$=this.readU16();else if(W===206)$=this.readU32();else if(W===207)if(this.useBigInt64)$=this.readU64AsBigInt();else $=this.readU64();else if(W===208)$=this.readI8();else if(W===209)$=this.readI16();else if(W===210)$=this.readI32();else if(W===211)if(this.useBigInt64)$=this.readI64AsBigInt();else $=this.readI64();else if(W===217){let G=this.lookU8();$=this.decodeString(G,1)}else if(W===218){let G=this.lookU16();$=this.decodeString(G,2)}else if(W===219){let G=this.lookU32();$=this.decodeString(G,4)}else if(W===220){let G=this.readU16();if(G!==0){this.pushArrayState(G),this.complete();continue W}else $=[]}else if(W===221){let G=this.readU32();if(G!==0){this.pushArrayState(G),this.complete();continue W}else $=[]}else if(W===222){let G=this.readU16();if(G!==0){this.pushMapState(G),this.complete();continue W}else $={}}else if(W===223){let G=this.readU32();if(G!==0){this.pushMapState(G),this.complete();continue W}else $={}}else if(W===196){let G=this.lookU8();$=this.decodeBinary(G,1)}else if(W===197){let G=this.lookU16();$=this.decodeBinary(G,2)}else if(W===198){let G=this.lookU32();$=this.decodeBinary(G,4)}else if(W===212)$=this.decodeExtension(1,0);else if(W===213)$=this.decodeExtension(2,0);else if(W===214)$=this.decodeExtension(4,0);else if(W===215)$=this.decodeExtension(8,0);else if(W===216)$=this.decodeExtension(16,0);else if(W===199){let G=this.lookU8();$=this.decodeExtension(G,1)}else if(W===200){let G=this.lookU16();$=this.decodeExtension(G,2)}else if(W===201){let G=this.lookU32();$=this.decodeExtension(G,4)}else throw new V(`Unrecognized type byte: ${w(W)}`);this.complete();let Z=this.stack;while(Z.length>0){let G=Z.top();if(G.type===p)if(G.array[G.position]=$,G.position++,G.position===G.size)$=G.array,Z.release(G);else continue W;else if(G.type===L){if($==="__proto__")throw new V("The key __proto__ is not allowed");G.key=this.mapKeyConverter($),G.type=UW;continue W}else if(G.map[G.key]=$,G.readCount++,G.readCount===G.size)$=G.map,Z.release(G);else{G.key=null,G.type=L;continue W}}return $}}readHeadByte(){if(this.headByte===D)this.headByte=this.readU8();return this.headByte}complete(){this.headByte=D}readArraySize(){let W=this.readHeadByte();switch(W){case 220:return this.readU16();case 221:return this.readU32();default:if(W<160)return W-144;else throw new V(`Unrecognized array type byte: ${w(W)}`)}}pushMapState(W){if(W>this.maxMapLength)throw new V(`Max length exceeded: map length (${W}) > maxMapLengthLength (${this.maxMapLength})`);this.stack.pushMapState(W)}pushArrayState(W){if(W>this.maxArrayLength)throw new V(`Max length exceeded: array length (${W}) > maxArrayLength (${this.maxArrayLength})`);this.stack.pushArrayState(W)}decodeString(W,$){if(!this.rawStrings||this.stateIsMapKey())return this.decodeUtf8String(W,$);return this.decodeBinary(W,$)}decodeUtf8String(W,$){if(W>this.maxStrLength)throw new V(`Max length exceeded: UTF-8 byte length (${W}) > maxStrLength (${this.maxStrLength})`);if(this.bytes.byteLength<this.pos+$+W)throw MW;let Z=this.pos+$,G;if(this.stateIsMapKey()&&this.keyDecoder?.canBeCached(W))G=this.keyDecoder.decode(this.bytes,Z,W);else G=FW(this.bytes,Z,W);return this.pos+=$+W,G}stateIsMapKey(){if(this.stack.length>0)return this.stack.top().type===L;return!1}decodeBinary(W,$){if(W>this.maxBinLength)throw new V(`Max length exceeded: bin length (${W}) > maxBinLength (${this.maxBinLength})`);if(!this.hasRemaining(W+$))throw MW;let Z=this.pos+$,G=this.bytes.subarray(Z,Z+W);return this.pos+=$+W,G}decodeExtension(W,$){if(W>this.maxExtLength)throw new V(`Max length exceeded: ext length (${W}) > maxExtLength (${this.maxExtLength})`);let Z=this.view.getInt8(this.pos+$),G=this.decodeBinary(W,$+1);return this.extensionCodec.decode(G,Z,this.context)}lookU8(){return this.view.getUint8(this.pos)}lookU16(){return this.view.getUint16(this.pos)}lookU32(){return this.view.getUint32(this.pos)}readU8(){let W=this.view.getUint8(this.pos);return this.pos++,W}readI8(){let W=this.view.getInt8(this.pos);return this.pos++,W}readU16(){let W=this.view.getUint16(this.pos);return this.pos+=2,W}readI16(){let W=this.view.getInt16(this.pos);return this.pos+=2,W}readU32(){let W=this.view.getUint32(this.pos);return this.pos+=4,W}readI32(){let W=this.view.getInt32(this.pos);return this.pos+=4,W}readU64(){let W=YW(this.view,this.pos);return this.pos+=8,W}readI64(){let W=S(this.view,this.pos);return this.pos+=8,W}readU64AsBigInt(){let W=this.view.getBigUint64(this.pos);return this.pos+=8,W}readI64AsBigInt(){let W=this.view.getBigInt64(this.pos);return this.pos+=8,W}readF32(){let W=this.view.getFloat32(this.pos);return this.pos+=4,W}readF64(){let W=this.view.getFloat64(this.pos);return this.pos+=8,W}}var p="array",L="map_key",UW="map_value",J0=(W)=>{if(typeof W==="string"||typeof W==="number")return W;throw new V("The type of key must be string or number but "+typeof W)},D=-1,u,Q0,MW,q0;var BW=X(()=>{E();C();RW();f();u=new DataView(new ArrayBuffer(0)),Q0=new Uint8Array(u.buffer);try{u.getInt8(0)}catch(W){if(!(W instanceof RangeError))throw Error("This module is not supported in the current JavaScript engine because DataView does not throw RangeError on out-of-bounds access")}MW=RangeError("Insufficient data"),q0=new l});function U(W,$){return new j($).decode(W)}var OW=X(()=>{BW()});var c=X(()=>{NW();OW();E()});function d(W){if(typeof W==="object"&&W!==null&&!Array.isArray(W))return W;return{}}function h(W){return Array.isArray(W)?W:[]}function KW(W){if(!(W instanceof Date))return null;let $=new ArrayBuffer(8);return new DataView($).setFloat64(0,W.getTime()),new Uint8Array($)}function AW(W){let $=new DataView(W.buffer,W.byteOffset,W.byteLength).getFloat64(0);return new Date($)}function R0(W){return typeof W==="object"&&W!==null&&"__tag"in W&&W.__tag===zW}function _(W,$){if(W===void 0)return N0;if(W===null||typeof W!=="object")return W;if($.has(W))return W;$.add(W);try{return M0(W,$)}finally{$.delete(W)}}function M0(W,$){if(Array.isArray(W))return U0(W,$);if(W instanceof Map)return _0(W,$);if(W instanceof Set)return B0(W,$);if(O0(W))return W;return K0(W,$)}function U0(W,$){let Z=Array.from({length:W.length});for(let G=0;G<W.length;G++)Z[G]=_(W[G],$);return Z}function _0(W,$){let Z=new Map;for(let[G,J]of W)Z.set(_(G,$),_(J,$));return Z}function B0(W,$){let Z=new Set;for(let G of W)Z.add(_(G,$));return Z}function O0(W){return W instanceof Date||W instanceof RegExp||W instanceof Error||W instanceof Uint8Array||W instanceof ArrayBuffer}function K0(W,$){let Z=W,G={};for(let J of Object.keys(Z))G[J]=_(Z[J],$);return G}var F0=1,X0=2,Y0=3,H0=4,V0=5,P0=6,P,zW,N0;var TW=X(()=>{c();P=new R;P.register({type:F0,encode:KW,decode:AW});P.register({type:X0,encode(W){if(W instanceof RegExp)return M({source:W.source,flags:W.flags});return null},decode(W){let $=d(U(W)),Z=typeof $.source==="string"?$.source:"",G=typeof $.flags==="string"?$.flags:"";return new RegExp(Z,G)}});P.register({type:Y0,encode(W){if(W instanceof Map){let $=[...W.entries()];return M($,{extensionCodec:P})}return null},decode(W){let Z=h(U(W,{extensionCodec:P})).map((G)=>{let J=h(G);return[J[0],J[1]]});return new Map(Z)}});P.register({type:H0,encode(W){if(W instanceof Set){let $=[...W.values()];return M($,{extensionCodec:P})}return null},decode(W){let $=h(U(W,{extensionCodec:P}));return new Set($)}});zW=Symbol("UndefinedSentinel"),N0=Object.freeze({__tag:zW});P.register({type:V0,encode(W){if(R0(W))return new Uint8Array(0);return null},decode(){return}});P.register({type:P0,encode(W){if(W instanceof Error)return M({name:W.name,message:W.message,stack:W.stack});return null},decode(W){let $=d(U(W)),Z=typeof $.name==="string"?$.name:"Error",G=typeof $.message==="string"?$.message:"",J=typeof $.stack==="string"?$.stack:void 0,q=Error(G);if(q.name=Z,J!==void 0)q.stack=J;return q}})});function n(W){let $=_(W,new Set);return M($,{extensionCodec:P})}function i(W){return U(W,{extensionCodec:P})}var DW=X(()=>{c();TW()});function m(W,$=""){let Z=[];return I(W,$,Z,new Set),{valid:Z.length===0,errors:Z}}function A0(W){let $=Object.getPrototypeOf(W);return z0($)&&!T0(W)&&D0($)}function z0(W){return W!==Object.prototype&&W!==null}function T0(W){return Array.isArray(W)||W instanceof Date||W instanceof RegExp||W instanceof Map||W instanceof Set||W instanceof Error||W instanceof Uint8Array||W instanceof ArrayBuffer}function D0(W){if(typeof W!=="object"||W===null)return!1;return Object.getOwnPropertyNames(W).some((Z)=>{if(Z==="constructor")return!1;let G=Object.getOwnPropertyDescriptor(W,Z);return G!==void 0&&typeof G.value==="function"})}function LW(W,$,Z,G){W.push({path:$,value:Z,reason:G.reason,suggestion:G.suggestion})}function L0(W){if(typeof W==="function")return{reason:"Functions cannot be serialized.",suggestion:"Move this into ctx.run() or reconstruct it on resume."};if(typeof W==="symbol")return{reason:"Symbols cannot be serialized.",suggestion:"Use a string identifier instead of a Symbol."};return null}function I0(W,$){if(W instanceof WeakRef)return{reason:"WeakRef cannot be serialized.",suggestion:"Store the referenced value directly instead of using a WeakRef."};if(W instanceof WeakMap)return{reason:"WeakMap cannot be serialized.",suggestion:"Use a Map instead of a WeakMap."};if(W instanceof WeakSet)return{reason:"WeakSet cannot be serialized.",suggestion:"Use a Set instead of a WeakSet."};if($.has(W))return{reason:"Circular reference detected.",suggestion:"Remove the circular reference or restructure the data."};if(A0(W))return{reason:"Class instances with methods cannot be serialized.",suggestion:"Store only the data and reconstruct the instance."};return null}function C0(W){return W instanceof Date||W instanceof RegExp||W instanceof Error||W instanceof Uint8Array||W instanceof ArrayBuffer}function x0(W,$,Z,G){for(let[J,q]of W){let F=String(J);I(q,$?`${$}.${F}`:F,Z,G)}}function S0(W,$,Z,G){let J=0;for(let q of W){let F=$?`${$}[${J}]`:`[${J}]`;I(q,F,Z,G),J++}}function E0(W,$,Z,G){for(let J=0;J<W.length;J++){let q=$?`${$}[${J}]`:`[${J}]`;I(W[J],q,Z,G)}}function k0(W,$,Z,G){for(let J of Object.keys(W)){let q=$?`${$}.${J}`:J;I(W[J],q,Z,G)}}function I(W,$,Z,G){if(W===null||W===void 0)return;let J=L0(W);if(J){LW(Z,$,W,J);return}if(typeof W!=="object")return;let q=I0(W,G);if(q){LW(Z,$,W,q);return}G.add(W);try{if(C0(W))return;if(W instanceof Map){x0(W,$,Z,G);return}if(W instanceof Set){S0(W,$,Z,G);return}if(Array.isArray(W)){E0(W,$,Z,G);return}k0(W,$,Z,G)}finally{G.delete(W)}}var IW=X(()=>{DW()});var CW=X(()=>{IW()});function w0(W){if(W===void 0)return;if(typeof W!=="number"||!Number.isInteger(W)||W<0)throw Error("deleteRange limit must be a finite non-negative integer");return W===0?0:W}function j0(W){let $={},Z=!1;for(let J of["gt","gte","lt","lte"]){let q=W[J];if(q===void 0)continue;if(typeof q!=="string")throw Error("deleteRange bounds must be strings");$[J]=q,Z=!0}if(!Z)throw Error("deleteRange requires at least one of gt/gte/lt/lte; use deletePrefix to delete a whole prefix");let G=w0(W.limit);if(G!==void 0)$.limit=G;return $}async function xW(W,$,Z){let G=j0(Z);if(W.deleteRange)return W.deleteRange($,G);return o(W,$,G)}var SW=()=>{};CW();SW();JW();class EW{#W;#$;#Z;constructor(W,$,Z={}){this.#W=W,this.#$=$,this.#Z=Z.disposeUnderlyingStorage??!0}async get(W){let $=await this.#W.get(W);return $===null?null:this.#$.decode($)}async put(W,$){await this.#W.put(W,this.#$.encode($))}async delete(W){await this.#W.delete(W)}async*scan(W,$){for await(let[Z,G]of this.#W.scan(W,$))yield[Z,this.#$.decode(G)]}async batch(W){await this.#W.batch(this.#G(W))}#G(W){return W.map((Z)=>{if(Z.type==="put")return{type:"put",key:Z.key,value:this.#$.encode(Z.value)};return Z})}#J(W){return W.map(($)=>({key:$.key,expectedValue:$.expectedValue===null?null:this.#$.encode($.expectedValue)}))}async conditionalBatch(W,$){return GW(this.#W,this.#J(W),this.#G($))}async has(W){return e(this.#W,W)}async deletePrefix(W){return ZW(this.#W,W)}async deleteRange(W,$){return xW(this.#W,W,$)}keys(W,$){return WW(this.#W,W,$)}async count(W){return $W(this.#W,W)}[Symbol.dispose](){if(!this.#Z)return;this.#W[Symbol.dispose]()}}function z6(W,$,Z={}){return new EW(W,$,Z)}function h0(W){try{let $=JSON.stringify(W);if($===void 0)throw TypeError("jsonCodec only supports JSON-serializable values.");return new TextEncoder().encode($)}catch($){throw TypeError("jsonCodec only supports JSON-serializable values.",{cause:$})}}function m0(W){let $=m(W);if(!$.valid)throw TypeError(`msgpackCodec only supports structuredClone-compatible values. ${$.errors[0]?.reason??""}`.trim());return n(W)}function g0(W){return JSON.parse(new TextDecoder().decode(W))}function v0(W){let $=i(W),Z=m($);if(!Z.valid)throw TypeError(`msgpackCodec decoded a non-cloneable value. ${Z.errors[0]?.reason??""}`.trim());return $}function T6(W){return{encode($){return h0($)},decode($){let Z=g0($);return W?W(Z):Z}}}function D6(W){return{encode($){return m0($)},decode($){let Z=v0($);return W?W(Z):Z}}}export{z6 as withCodec,D6 as msgpackCodec,T6 as jsonCodec};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var p=Object.defineProperty;var s=(J)=>J;function a(J,X){this[J]=s.bind(null,X)}var UJ=(J,X)=>{for(var Z in X)p(J,Z,{get:X[Z],enumerable:!0,configurable:!0,set:a.bind(X,Z)})};function K(J){let X=[];for(let Z=0;Z<J.length;Z+=512)X.push(String.fromCharCode(...J.subarray(Z,Z+512)));return btoa(X.join(""))}function b(J){let X=atob(J),Z=new Uint8Array(X.length);for(let F=0;F<X.length;F+=1)Z[F]=X.charCodeAt(F);return Z}function B(J){return typeof J==="object"&&J!==null&&!Array.isArray(J)}async function _(J,X){return await J.get(X)!==null}async function*M(J,X,Z){for await(let[F]of J.scan(X,Z))yield F}async function L(J,X){let Z=0;for await(let F of M(J,X))Z++;return Z}async function D(J,X){let Z=[];for await(let F of M(J,X))Z.push({type:"delete",key:F});if(Z.length===0)return 0;return await J.batch(Z),Z.length}async function W(J,X,Z){let F=[];for await(let V of M(J,X,Z))F.push({type:"delete",key:V});if(F.length===0)return 0;return await J.batch(F),F.length}function O(J,X,Z){if(!J.capabilities()[X])throw Error(`Feature "${Z}" requires storage capability "${X}", but this storage backend does not provide it.`)}var I="default";function S(J){return J.length>0?J.slice(0,-1)+String.fromCharCode(J.charCodeAt(J.length-1)+1):"ÿ"}function x(J,X={}){if(X.gt!==void 0&&J<=X.gt)return!1;if(X.gte!==void 0&&J<X.gte)return!1;if(X.lt!==void 0&&J>=X.lt)return!1;if(X.lte!==void 0&&J>X.lte)return!1;return!0}function WJ(J,X){if(J===null||X===null)return J===X;if(J.byteLength!==X.byteLength)return!1;for(let Z=0;Z<J.byteLength;Z++)if(J[Z]!==X[Z])return!1;return!0}async function v(J,X){if(J.has)return J.has(X);return _(J,X)}function w(J,X,Z){if(J.keys)return J.keys(X,Z);return M(J,X,Z)}async function u(J,X){if(J.count)return J.count(X);return L(J,X)}async function m(J,X){if(J.deletePrefix)return J.deletePrefix(X);return D(J,X)}async function k(J,X,Z){if(O(J,"conditionalBatch","storageConditionalBatch"),!J.conditionalBatch)throw Error("This storage backend reports conditionalBatch capability but does not implement the conditionalBatch() method.");return J.conditionalBatch(X,Z)}function $(J){return encodeURIComponent(J)}function zJ(J){try{return decodeURIComponent(J)}catch{return null}}var G=(J)=>String(J).padStart(16,"0"),BJ={workflow:(J)=>`wf:${$(J)}`,checkpoint:(J)=>`wf:${$(J)}:ckpt`,checkpointHistory:(J,X)=>`wf:${$(J)}:ckpt:${String(X).padStart(10,"0")}`,timelinePrefix:(J)=>`wf:${$(J)}:timeline:`,timeline:(J,X)=>`wf:${$(J)}:timeline:${String(X).padStart(10,"0")}`,schedule:(J)=>`schedule:${$(J)}`,scheduleTick:(J,X)=>`schedule-due:${String(J).padStart(16,"0")}:${$(X)}`,scheduleRun:(J)=>`schedule-run:${$(J)}`,operation:(J,X,Z)=>`op:${J}:${G(X)}:${Z}`,operationInflight:(J)=>`op:inflight:${J}`,operationQueued:(J)=>`op:queued:${J}`,operationResolved:(J)=>`op:resolved:${J}`,bulkOperationAuditPrefix:()=>"audit:bulk:",bulkOperationAudit:(J,X,Z)=>`audit:bulk:${G(J)}:${$(X)}:${$(Z)}`,operationResolvedByTimePrefix:()=>"op:resolved-by-time:",operationResolvedByTime:(J,X)=>`op:resolved-by-time:${G(J)}:${$(X)}`,asyncActivity:(J,X)=>`async-act:v1:${$(J)}:${$(X)}`,activityReconciliationPrefix:(J)=>`actrec:v1:${$(J)}:`,activityReconciliation:(J,X,Z)=>`actrec:v1:${$(J)}:${$(X)}:${Z}`,eventPrefix:(J)=>`ev:${$(J)}:`,event:(J,X)=>`ev:${$(J)}:${String(X).padStart(10,"0")}`,eventHead:(J)=>`ev:${$(J)}:head`,eventWatermark:(J)=>`ev:${$(J)}:watermark`,signal:(J,X,Z)=>`sig:${$(J)}:${X}:${$(Z)}`,signalSequence:(J)=>`sigseq:v1:${$(J)}`,signalAcceptedResponsePrefix:(J)=>`sigres:v1:${$(J)}:`,signalAcceptedResponse:(J,X,Z)=>`sigres:v1:${$(J)}:${$(X)}:${$(Z)}`,deadline:(J,X)=>`wf-deadline:${G(J)}:${$(X)}`,terminalCleanup:(J,X)=>`wf-cleanup:${G(J)}:${$(X)}`,delayedStart:(J,X)=>`wf-delayed:${G(J)}:${$(X)}`,terminalWorkflowPrefix:()=>"wf-terminal:",terminalWorkflow:(J,X)=>`wf-terminal:${G(J)}:${$(X)}`,attribute:(J)=>`attr:${$(J)}`,attributeIndex:(J,X,Z)=>`idx:${J}:${X}:${$(Z)}`,tagIndex:(J,X)=>`tag:${$(J)}:${$(X)}`,updatePrefix:(J)=>`upd:${$(J)}:`,update:(J,X)=>`upd:${$(J)}:${X}`,updateResponse:(J)=>`upr:${J}`,updateIdempotency:(J,X)=>`upk:${$(J)}:${X}`,budget:(J,X,Z)=>`budget:${J}:${X}:${Z}`,review:(J,X)=>`review:${$(J)}:${X}`,workflowHeaders:(J)=>`wf-headers:${$(J)}`,terminalCleanupNeeded:(J)=>`wf-cleanup-needed:${$(J)}`,offload:(J,X)=>`offload:${$(J)}:${X}`,archive:(J,X)=>`archive:${$(J)}:${X}`,stateExecution:(J,X)=>`state:execution:${$(J)}:${$(X)}`,stateWorkflow:(J,X)=>`state:workflow-scope:${I}:${$(J)}:${$(X)}`,streamChunkPrefix:(J,X)=>`blob:${$(J)}:${X}:chunk:`,streamChunk:(J,X,Z)=>`blob:${$(J)}:${X}:chunk:${String(Z).padStart(10,"0")}`,streamMetadata:(J,X)=>`blob:${$(J)}:${X}:meta`,budgetCharged:(J)=>`budget-charged:${J}`,toolEffect:(J,X,Z)=>`tool-effect:${$(J)}:${X}:${Z}`,workflowVisibilityStatus:(J,X)=>`wf-idx-status:${$(J)}:${$(X)}`,workflowVisibilityType:(J,X)=>`wf-idx-type:${$(J)}:${$(X)}`,workflowVisibilityCreated:(J,X)=>`wf-idx-created:${G(J)}:${$(X)}`,workflowVisibilityUpdated:(J,X)=>`wf-idx-updated:${G(J)}:${$(X)}`,workflowVisibilityDeadline:(J,X)=>`wf-idx-deadline:${G(J)}:${$(X)}`,workflowVisibilityManifest:(J)=>`wf-idx-manifest:${$(J)}`,workflowVisibilityMetaVersion:()=>"wf-idx-meta:version",workflowVisibilityMetaBuiltAt:()=>"wf-idx-meta:built-at",workflowVisibilityMetaCursor:()=>"wf-idx-meta:cursor"};function i(J){if(J===void 0)return;if(typeof J!=="number"||!Number.isInteger(J)||J<0)throw Error("deleteRange limit must be a finite non-negative integer");return J===0?0:J}function N(J){let X={},Z=!1;for(let V of["gt","gte","lt","lte"]){let H=J[V];if(H===void 0)continue;if(typeof H!=="string")throw Error("deleteRange bounds must be strings");X[V]=H,Z=!0}if(!Z)throw Error("deleteRange requires at least one of gt/gte/lt/lte; use deletePrefix to delete a whole prefix");let F=i(J.limit);if(F!==void 0)X.limit=F;return X}async function f(J,X,Z){let F=N(Z);if(J.deleteRange)return J.deleteRange(X,F);return W(J,X,F)}function n(J,X){let Z={key:J,open:!1};if(X.gte!==void 0&&X.gte>Z.key)Z.key=X.gte,Z.open=!1;if(X.gt!==void 0&&X.gt>=Z.key)Z.key=X.gt,Z.open=!0;return Z}function r(J,X){let Z={key:S(J),open:!0};if(X.lt!==void 0&&X.lt<=Z.key)Z.key=X.lt,Z.open=!0;if(X.lte!==void 0&&X.lte<Z.key)Z.key=X.lte,Z.open=!1;return Z}function TJ(J,X){let Z=n(J,X),F=r(J,X);if(Z.key>F.key||Z.key===F.key&&(Z.open||F.open))return null;return{lower:Z,upper:F}}function A(J){return J.replaceAll(/:+$/g,"")}function t(J,X){let Z=A(J),F=A(X);if(Z.length===0)return F;if(F.length===0)return Z;return`${Z}:${F}`}class R{#X;#Z;constructor(J,X){this.#X=J,this.#Z=A(X)}#J(J){if(this.#Z.length===0)return J;return J.length===0?`${this.#Z}:`:`${this.#Z}:${J}`}#$(J){if(this.#Z.length===0)return J;return J.slice(this.#Z.length+1)}#F(J={}){let X={};if(J.limit!==void 0)X.limit=J.limit;if(J.reverse!==void 0)X.reverse=J.reverse;if(J.gt!==void 0)X.gt=this.#J(J.gt);if(J.gte!==void 0)X.gte=this.#J(J.gte);if(J.lt!==void 0)X.lt=this.#J(J.lt);if(J.lte!==void 0)X.lte=this.#J(J.lte);return X}#H(J){let X={};if(J.limit!==void 0)X.limit=J.limit;if(J.gt!==void 0)X.gt=this.#J(J.gt);if(J.gte!==void 0)X.gte=this.#J(J.gte);if(J.lt!==void 0)X.lt=this.#J(J.lt);if(J.lte!==void 0)X.lte=this.#J(J.lte);return X}capabilities(){return this.#X.capabilities()}scoped(J){return new R(this.#X,t(this.#Z,J))}async get(J){return this.#X.get(this.#J(J))}async put(J,X){await this.#X.put(this.#J(J),X)}async delete(J){await this.#X.delete(this.#J(J))}async*scan(J,X){for await(let[Z,F]of this.#X.scan(this.#J(J),this.#F(X)))yield[this.#$(Z),F]}async batch(J){await this.#X.batch(J.map((X)=>{if(X.type==="put")return{type:"put",key:this.#J(X.key),value:X.value};return{type:"delete",key:this.#J(X.key)}}))}async conditionalBatch(J,X){return k(this.#X,J.map((Z)=>({key:this.#J(Z.key),expectedValue:Z.expectedValue})),X.map((Z)=>{if(Z.type==="put")return{type:"put",key:this.#J(Z.key),value:Z.value};return{type:"delete",key:this.#J(Z.key)}}))}async has(J){return v(this.#X,this.#J(J))}async deletePrefix(J){return m(this.#X,this.#J(J))}async deleteRange(J,X){let Z=this.#H(N(X));return f(this.#X,this.#J(J),Z)}async*keys(J,X){for await(let Z of w(this.#X,this.#J(J),this.#F(X)))yield this.#$(Z)}async count(J){return u(this.#X,this.#J(J))}[Symbol.dispose](){this.#X[Symbol.dispose]()}}function c(J,X){return new R(J,X)}var d=1,Y="__weftStorageKeyspace",o=102400,e=8192;function JJ(J){return typeof J==="object"&&J!==null&&"then"in J&&typeof J.then==="function"}function E(J){if(!B(J))return!1;if(J.__weftStorage!==d)return!1;return typeof J.value==="string"}function XJ(J){if(!B(J))return!1;return Object.values(J).every(E)}function z(J){if(J!==Y)return;throw Error(`WebExtensionStorage key "${Y}" is reserved for adapter metadata.`)}function ZJ(J){for(let X of J)z(X.key)}function g(J){return{__weftStorage:d,value:K(J)}}function y(J){if(!E(J))return null;return b(J.value)}function $J(J){return E(J)}function P(J){return new TextEncoder().encode(JSON.stringify(J)).byteLength}function FJ(){let J=globalThis,X=J.browser??J.chrome;if(X?.storage===void 0)throw Error("WebExtensionStorage requires globalThis.browser.storage or globalThis.chrome.storage.");return X}function HJ(J,X){let Z=J.storage?.[X];if(Z===void 0)throw Error(`WebExtensionStorage area "${X}" is not available.`);return Z}function VJ(J){if(J==="session")return"ephemeral";if(J==="sync"||J==="managed")return"remote";return"local"}function GJ(J){let X=J.runtime?.lastError?.message;return X===void 0?null:Error(X)}async function T(J,X,Z){return new Promise((F,V)=>{let H=!1,q=(U)=>{if(H)return;let C=GJ(J);if(H=!0,C!==null)V(C);else F(U)},h=(U)=>{if(H)return;H=!0,V(U)},l=(U)=>q(U),Q;try{Q=X(l)}catch{try{Q=Z()}catch(U){h(U);return}}if(JJ(Q))Q.then(q,h)})}class j{static#X=new WeakMap;#Z;#J;#$;#F;#H;constructor(J={}){this.#$=J.area??"local",this.#F=VJ(this.#$),this.#Z=FJ(),this.#J=HJ(this.#Z,this.#$),this.#H=()=>{},this.#Z.storage?.onChanged?.addListener?.(this.#H)}capabilities(){return{persistence:this.#F,readAfterWrite:"session",scanConsistency:"best-effort",atomicBatch:!0,conditionalBatch:!1,boundedRangeDelete:!1}}async#q(J){return T(this.#Z,(X)=>this.#J.get(J,X),()=>this.#J.get(J))}async#j(J){await T(this.#Z,(X)=>this.#J.set(J,X),()=>this.#J.set(J))}async#N(J){if(this.#J.getBytesInUse===void 0)return null;return T(this.#Z,(X)=>this.#J.getBytesInUse?.(J,X),()=>this.#J.getBytesInUse?.(J))}async#V(){let X=(await this.#q(Y))[Y];if(X===void 0)return{};if(!XJ(X))throw Error("WebExtensionStorage keyspace is not a valid storage envelope map.");return{...X}}async#U(J){let X={[Y]:J};await this.#_(X),await this.#j(X)}async#M(J){let X=j.#X.get(this.#J)??Promise.resolve(),Z={},F=new Promise((H)=>{Z.release=H}),V=X.catch(()=>{return}).then(()=>F);j.#X.set(this.#J,V),await X.catch(()=>{return});try{return await J()}finally{if(Z.release?.(),j.#X.get(this.#J)===V)j.#X.delete(this.#J)}}#G(){if(this.#$==="managed")throw Error('WebExtensionStorage area "managed" is read-only.')}#Y(J){let X=this.#J.QUOTA_BYTES_PER_ITEM??e;for(let[Z,F]of Object.entries(J)){let V=P({[Z]:F});if(V>X)throw Error(`WebExtensionStorage sync item quota exceeded for "${Z}": ${String(V)} > ${String(X)}.`)}}async#Q(J){let X=Object.keys(J),Z=await this.#N(null),F=await this.#N(X);if(Z!==null&&F!==null)return Z-F+P(J);let V=await this.#q(null);return P({...V,...J})}async#_(J){if(this.#$!=="sync")return;this.#Y(J);let X=this.#J.QUOTA_BYTES??o,Z=await this.#Q(J);if(Z>X)throw Error(`WebExtensionStorage sync total quota exceeded: ${String(Z)} > ${String(X)}.`)}async get(J){z(J);let X=await this.#V();return y(X[J])}async put(J,X){this.#G(),z(J),await this.#M(async()=>{let Z=await this.#V();Z[J]=g(X),await this.#U(Z)})}async delete(J){this.#G(),z(J),await this.#M(async()=>{let X=await this.#V();if(!(J in X))return;delete X[J],await this.#U(X)})}async*scan(J,X={}){let Z=await this.#V(),F=Object.keys(Z).filter((H)=>H.startsWith(J)).filter((H)=>x(H,X)).filter((H)=>$J(Z[H])).toSorted();if(X.reverse)F=F.toReversed();let V=0;for(let H of F){if(X.limit!==void 0&&V>=X.limit)break;let q=y(Z[H]);if(q===null)continue;yield[H,q],V+=1}}async batch(J){if(this.#G(),J.length===0)return;ZJ(J),await this.#M(async()=>{let X=await this.#V();for(let Z of J)if(Z.type==="put")X[Z.key]=g(Z.value);else delete X[Z.key];await this.#U(X)})}has(J){return _(this,J)}async*keys(J,X){yield*M(this,J,X)}count(J){return L(this,J)}async deletePrefix(J){return this.#G(),D(this,J)}async deleteRange(J,X){let Z=N(X);return this.#G(),W(this,J,Z)}scoped(J){return c(this,J)}[Symbol.dispose](){this.#Z.storage?.onChanged?.removeListener?.(this.#H)}}export{j as WebExtensionStorage};
|
|
1
|
+
var p=Object.defineProperty;var s=(J)=>J;function a(J,X){this[J]=s.bind(null,X)}var UJ=(J,X)=>{for(var Z in X)p(J,Z,{get:X[Z],enumerable:!0,configurable:!0,set:a.bind(X,Z)})};function b(J){let X=[];for(let Z=0;Z<J.length;Z+=512)X.push(String.fromCharCode(...J.subarray(Z,Z+512)));return btoa(X.join(""))}function K(J){let X=atob(J),Z=new Uint8Array(X.length);for(let F=0;F<X.length;F+=1)Z[F]=X.charCodeAt(F);return Z}function B(J){return typeof J==="object"&&J!==null&&!Array.isArray(J)}async function _(J,X){return await J.get(X)!==null}async function*M(J,X,Z){for await(let[F]of J.scan(X,Z))yield F}async function L(J,X){let Z=0;for await(let F of M(J,X))Z++;return Z}async function D(J,X){let Z=[];for await(let F of M(J,X))Z.push({type:"delete",key:F});if(Z.length===0)return 0;return await J.batch(Z),Z.length}async function W(J,X,Z){let F=[];for await(let V of M(J,X,Z))F.push({type:"delete",key:V});if(F.length===0)return 0;return await J.batch(F),F.length}function O(J,X,Z){if(!J.capabilities()[X])throw Error(`Feature "${Z}" requires storage capability "${X}", but this storage backend does not provide it.`)}var I="default";function S(J){return J.length>0?J.slice(0,-1)+String.fromCharCode(J.charCodeAt(J.length-1)+1):"ÿ"}function x(J,X={}){if(X.gt!==void 0&&J<=X.gt)return!1;if(X.gte!==void 0&&J<X.gte)return!1;if(X.lt!==void 0&&J>=X.lt)return!1;if(X.lte!==void 0&&J>X.lte)return!1;return!0}function WJ(J,X){if(J===null||X===null)return J===X;if(J.byteLength!==X.byteLength)return!1;for(let Z=0;Z<J.byteLength;Z++)if(J[Z]!==X[Z])return!1;return!0}async function v(J,X){if(J.has)return J.has(X);return _(J,X)}function w(J,X,Z){if(J.keys)return J.keys(X,Z);return M(J,X,Z)}async function u(J,X){if(J.count)return J.count(X);return L(J,X)}async function m(J,X){if(J.deletePrefix)return J.deletePrefix(X);return D(J,X)}async function k(J,X,Z){if(O(J,"conditionalBatch","storageConditionalBatch"),!J.conditionalBatch)throw Error("This storage backend reports conditionalBatch capability but does not implement the conditionalBatch() method.");return J.conditionalBatch(X,Z)}function $(J){return encodeURIComponent(J)}function zJ(J){try{return decodeURIComponent(J)}catch{return null}}var G=(J)=>String(J).padStart(16,"0"),BJ={workflow:(J)=>`wf:${$(J)}`,checkpoint:(J)=>`wf:${$(J)}:ckpt`,checkpointHistory:(J,X)=>`wf:${$(J)}:ckpt:${String(X).padStart(10,"0")}`,timelinePrefix:(J)=>`wf:${$(J)}:timeline:`,timeline:(J,X)=>`wf:${$(J)}:timeline:${String(X).padStart(10,"0")}`,schedule:(J)=>`schedule:${$(J)}`,scheduleTick:(J,X)=>`schedule-due:${String(J).padStart(16,"0")}:${$(X)}`,scheduleRun:(J)=>`schedule-run:${$(J)}`,operation:(J,X,Z)=>`op:${J}:${G(X)}:${Z}`,operationInflight:(J)=>`op:inflight:${J}`,operationQueued:(J)=>`op:queued:${J}`,operationResolved:(J)=>`op:resolved:${J}`,bulkOperationAuditPrefix:()=>"audit:bulk:",bulkOperationAudit:(J,X,Z)=>`audit:bulk:${G(J)}:${$(X)}:${$(Z)}`,operationResolvedByTimePrefix:()=>"op:resolved-by-time:",operationResolvedByTime:(J,X)=>`op:resolved-by-time:${G(J)}:${$(X)}`,asyncActivity:(J,X)=>`async-act:v1:${$(J)}:${$(X)}`,activityReconciliationPrefix:(J)=>`actrec:v1:${$(J)}:`,activityReconciliation:(J,X,Z)=>`actrec:v1:${$(J)}:${$(X)}:${Z}`,eventPrefix:(J)=>`ev:${$(J)}:`,event:(J,X)=>`ev:${$(J)}:${String(X).padStart(10,"0")}`,eventHead:(J)=>`ev:${$(J)}:head`,eventWatermark:(J)=>`ev:${$(J)}:watermark`,signal:(J,X,Z)=>`sig:${$(J)}:${X}:${$(Z)}`,signalSequence:(J)=>`sigseq:v1:${$(J)}`,signalAcceptedResponsePrefix:(J)=>`sigres:v1:${$(J)}:`,signalAcceptedResponse:(J,X,Z)=>`sigres:v1:${$(J)}:${$(X)}:${$(Z)}`,deadline:(J,X)=>`wf-deadline:${G(J)}:${$(X)}`,terminalCleanup:(J,X)=>`wf-cleanup:${G(J)}:${$(X)}`,delayedStart:(J,X)=>`wf-delayed:${G(J)}:${$(X)}`,terminalWorkflowPrefix:()=>"wf-terminal:",terminalWorkflow:(J,X)=>`wf-terminal:${G(J)}:${$(X)}`,attribute:(J)=>`attr:${$(J)}`,attributeIndex:(J,X,Z)=>`idx:${J}:${X}:${$(Z)}`,tagIndex:(J,X)=>`tag:${$(J)}:${$(X)}`,updatePrefix:(J)=>`upd:${$(J)}:`,update:(J,X)=>`upd:${$(J)}:${X}`,updateResponse:(J)=>`upr:${J}`,updateIdempotency:(J,X)=>`upk:${$(J)}:${X}`,budget:(J,X,Z)=>`budget:${J}:${X}:${Z}`,review:(J,X)=>`review:${$(J)}:${X}`,workflowHeaders:(J)=>`wf-headers:${$(J)}`,terminalCleanupNeeded:(J)=>`wf-cleanup-needed:${$(J)}`,workflowHasServices:(J)=>`wf-has-services:${$(J)}`,offload:(J,X)=>`offload:${$(J)}:${X}`,archive:(J,X)=>`archive:${$(J)}:${X}`,stateExecution:(J,X)=>`state:execution:${$(J)}:${$(X)}`,stateWorkflow:(J,X)=>`state:workflow-scope:${I}:${$(J)}:${$(X)}`,streamChunkPrefix:(J,X)=>`blob:${$(J)}:${X}:chunk:`,streamChunk:(J,X,Z)=>`blob:${$(J)}:${X}:chunk:${String(Z).padStart(10,"0")}`,streamMetadata:(J,X)=>`blob:${$(J)}:${X}:meta`,budgetCharged:(J)=>`budget-charged:${J}`,toolEffect:(J,X,Z)=>`tool-effect:${$(J)}:${X}:${Z}`,workflowVisibilityStatus:(J,X)=>`wf-idx-status:${$(J)}:${$(X)}`,workflowVisibilityType:(J,X)=>`wf-idx-type:${$(J)}:${$(X)}`,workflowVisibilityCreated:(J,X)=>`wf-idx-created:${G(J)}:${$(X)}`,workflowVisibilityUpdated:(J,X)=>`wf-idx-updated:${G(J)}:${$(X)}`,workflowVisibilityDeadline:(J,X)=>`wf-idx-deadline:${G(J)}:${$(X)}`,workflowVisibilityManifest:(J)=>`wf-idx-manifest:${$(J)}`,workflowVisibilityMetaVersion:()=>"wf-idx-meta:version",workflowVisibilityMetaBuiltAt:()=>"wf-idx-meta:built-at",workflowVisibilityMetaCursor:()=>"wf-idx-meta:cursor"};function i(J){if(J===void 0)return;if(typeof J!=="number"||!Number.isInteger(J)||J<0)throw Error("deleteRange limit must be a finite non-negative integer");return J===0?0:J}function N(J){let X={},Z=!1;for(let V of["gt","gte","lt","lte"]){let H=J[V];if(H===void 0)continue;if(typeof H!=="string")throw Error("deleteRange bounds must be strings");X[V]=H,Z=!0}if(!Z)throw Error("deleteRange requires at least one of gt/gte/lt/lte; use deletePrefix to delete a whole prefix");let F=i(J.limit);if(F!==void 0)X.limit=F;return X}async function f(J,X,Z){let F=N(Z);if(J.deleteRange)return J.deleteRange(X,F);return W(J,X,F)}function n(J,X){let Z={key:J,open:!1};if(X.gte!==void 0&&X.gte>Z.key)Z.key=X.gte,Z.open=!1;if(X.gt!==void 0&&X.gt>=Z.key)Z.key=X.gt,Z.open=!0;return Z}function r(J,X){let Z={key:S(J),open:!0};if(X.lt!==void 0&&X.lt<=Z.key)Z.key=X.lt,Z.open=!0;if(X.lte!==void 0&&X.lte<Z.key)Z.key=X.lte,Z.open=!1;return Z}function TJ(J,X){let Z=n(J,X),F=r(J,X);if(Z.key>F.key||Z.key===F.key&&(Z.open||F.open))return null;return{lower:Z,upper:F}}function A(J){return J.replaceAll(/:+$/g,"")}function t(J,X){let Z=A(J),F=A(X);if(Z.length===0)return F;if(F.length===0)return Z;return`${Z}:${F}`}class R{#X;#Z;constructor(J,X){this.#X=J,this.#Z=A(X)}#J(J){if(this.#Z.length===0)return J;return J.length===0?`${this.#Z}:`:`${this.#Z}:${J}`}#$(J){if(this.#Z.length===0)return J;return J.slice(this.#Z.length+1)}#F(J={}){let X={};if(J.limit!==void 0)X.limit=J.limit;if(J.reverse!==void 0)X.reverse=J.reverse;if(J.gt!==void 0)X.gt=this.#J(J.gt);if(J.gte!==void 0)X.gte=this.#J(J.gte);if(J.lt!==void 0)X.lt=this.#J(J.lt);if(J.lte!==void 0)X.lte=this.#J(J.lte);return X}#H(J){let X={};if(J.limit!==void 0)X.limit=J.limit;if(J.gt!==void 0)X.gt=this.#J(J.gt);if(J.gte!==void 0)X.gte=this.#J(J.gte);if(J.lt!==void 0)X.lt=this.#J(J.lt);if(J.lte!==void 0)X.lte=this.#J(J.lte);return X}capabilities(){return this.#X.capabilities()}scoped(J){return new R(this.#X,t(this.#Z,J))}async get(J){return this.#X.get(this.#J(J))}async put(J,X){await this.#X.put(this.#J(J),X)}async delete(J){await this.#X.delete(this.#J(J))}async*scan(J,X){for await(let[Z,F]of this.#X.scan(this.#J(J),this.#F(X)))yield[this.#$(Z),F]}async batch(J){await this.#X.batch(J.map((X)=>{if(X.type==="put")return{type:"put",key:this.#J(X.key),value:X.value};return{type:"delete",key:this.#J(X.key)}}))}async conditionalBatch(J,X){return k(this.#X,J.map((Z)=>({key:this.#J(Z.key),expectedValue:Z.expectedValue})),X.map((Z)=>{if(Z.type==="put")return{type:"put",key:this.#J(Z.key),value:Z.value};return{type:"delete",key:this.#J(Z.key)}}))}async has(J){return v(this.#X,this.#J(J))}async deletePrefix(J){return m(this.#X,this.#J(J))}async deleteRange(J,X){let Z=this.#H(N(X));return f(this.#X,this.#J(J),Z)}async*keys(J,X){for await(let Z of w(this.#X,this.#J(J),this.#F(X)))yield this.#$(Z)}async count(J){return u(this.#X,this.#J(J))}[Symbol.dispose](){this.#X[Symbol.dispose]()}}function c(J,X){return new R(J,X)}var d=1,Y="__weftStorageKeyspace",o=102400,e=8192;function JJ(J){return typeof J==="object"&&J!==null&&"then"in J&&typeof J.then==="function"}function E(J){if(!B(J))return!1;if(J.__weftStorage!==d)return!1;return typeof J.value==="string"}function XJ(J){if(!B(J))return!1;return Object.values(J).every(E)}function z(J){if(J!==Y)return;throw Error(`WebExtensionStorage key "${Y}" is reserved for adapter metadata.`)}function ZJ(J){for(let X of J)z(X.key)}function g(J){return{__weftStorage:d,value:b(J)}}function y(J){if(!E(J))return null;return K(J.value)}function $J(J){return E(J)}function P(J){return new TextEncoder().encode(JSON.stringify(J)).byteLength}function FJ(){let J=globalThis,X=J.browser??J.chrome;if(X?.storage===void 0)throw Error("WebExtensionStorage requires globalThis.browser.storage or globalThis.chrome.storage.");return X}function HJ(J,X){let Z=J.storage?.[X];if(Z===void 0)throw Error(`WebExtensionStorage area "${X}" is not available.`);return Z}function VJ(J){if(J==="session")return"ephemeral";if(J==="sync"||J==="managed")return"remote";return"local"}function GJ(J){let X=J.runtime?.lastError?.message;return X===void 0?null:Error(X)}async function T(J,X,Z){return new Promise((F,V)=>{let H=!1,q=(U)=>{if(H)return;let C=GJ(J);if(H=!0,C!==null)V(C);else F(U)},h=(U)=>{if(H)return;H=!0,V(U)},l=(U)=>q(U),Q;try{Q=X(l)}catch{try{Q=Z()}catch(U){h(U);return}}if(JJ(Q))Q.then(q,h)})}class j{static#X=new WeakMap;#Z;#J;#$;#F;#H;constructor(J={}){this.#$=J.area??"local",this.#F=VJ(this.#$),this.#Z=FJ(),this.#J=HJ(this.#Z,this.#$),this.#H=()=>{},this.#Z.storage?.onChanged?.addListener?.(this.#H)}capabilities(){return{persistence:this.#F,readAfterWrite:"session",scanConsistency:"best-effort",atomicBatch:!0,conditionalBatch:!1,boundedRangeDelete:!1}}async#q(J){return T(this.#Z,(X)=>this.#J.get(J,X),()=>this.#J.get(J))}async#j(J){await T(this.#Z,(X)=>this.#J.set(J,X),()=>this.#J.set(J))}async#N(J){if(this.#J.getBytesInUse===void 0)return null;return T(this.#Z,(X)=>this.#J.getBytesInUse?.(J,X),()=>this.#J.getBytesInUse?.(J))}async#V(){let X=(await this.#q(Y))[Y];if(X===void 0)return{};if(!XJ(X))throw Error("WebExtensionStorage keyspace is not a valid storage envelope map.");return{...X}}async#U(J){let X={[Y]:J};await this.#_(X),await this.#j(X)}async#M(J){let X=j.#X.get(this.#J)??Promise.resolve(),Z={},F=new Promise((H)=>{Z.release=H}),V=X.catch(()=>{return}).then(()=>F);j.#X.set(this.#J,V),await X.catch(()=>{return});try{return await J()}finally{if(Z.release?.(),j.#X.get(this.#J)===V)j.#X.delete(this.#J)}}#G(){if(this.#$==="managed")throw Error('WebExtensionStorage area "managed" is read-only.')}#Y(J){let X=this.#J.QUOTA_BYTES_PER_ITEM??e;for(let[Z,F]of Object.entries(J)){let V=P({[Z]:F});if(V>X)throw Error(`WebExtensionStorage sync item quota exceeded for "${Z}": ${String(V)} > ${String(X)}.`)}}async#Q(J){let X=Object.keys(J),Z=await this.#N(null),F=await this.#N(X);if(Z!==null&&F!==null)return Z-F+P(J);let V=await this.#q(null);return P({...V,...J})}async#_(J){if(this.#$!=="sync")return;this.#Y(J);let X=this.#J.QUOTA_BYTES??o,Z=await this.#Q(J);if(Z>X)throw Error(`WebExtensionStorage sync total quota exceeded: ${String(Z)} > ${String(X)}.`)}async get(J){z(J);let X=await this.#V();return y(X[J])}async put(J,X){this.#G(),z(J),await this.#M(async()=>{let Z=await this.#V();Z[J]=g(X),await this.#U(Z)})}async delete(J){this.#G(),z(J),await this.#M(async()=>{let X=await this.#V();if(!(J in X))return;delete X[J],await this.#U(X)})}async*scan(J,X={}){let Z=await this.#V(),F=Object.keys(Z).filter((H)=>H.startsWith(J)).filter((H)=>x(H,X)).filter((H)=>$J(Z[H])).toSorted();if(X.reverse)F=F.toReversed();let V=0;for(let H of F){if(X.limit!==void 0&&V>=X.limit)break;let q=y(Z[H]);if(q===null)continue;yield[H,q],V+=1}}async batch(J){if(this.#G(),J.length===0)return;ZJ(J),await this.#M(async()=>{let X=await this.#V();for(let Z of J)if(Z.type==="put")X[Z.key]=g(Z.value);else delete X[Z.key];await this.#U(X)})}has(J){return _(this,J)}async*keys(J,X){yield*M(this,J,X)}count(J){return L(this,J)}async deletePrefix(J){return this.#G(),D(this,J)}async deleteRange(J,X){let Z=N(X);return this.#G(),W(this,J,Z)}scoped(J){return c(this,J)}[Symbol.dispose](){this.#Z.storage?.onChanged?.removeListener?.(this.#H)}}export{j as WebExtensionStorage};
|
|
@@ -1,4 +1,38 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
|
+
* Let promise continuations and queued microtasks settle without advancing time
|
|
3
|
+
* or yielding a full event-loop turn. Awaits `Promise.resolve()` `turns` times,
|
|
4
|
+
* which is enough to drain chained `.then()` continuations. Use it when a test
|
|
5
|
+
* needs queued microtasks to run but does not need a macrotask boundary.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* import { flushPortableMicrotasks } from '@lostgradient/weft/testing';
|
|
10
|
+
*
|
|
11
|
+
* let ran = false;
|
|
12
|
+
* void Promise.resolve().then(() => {
|
|
13
|
+
* ran = true;
|
|
14
|
+
* });
|
|
15
|
+
* await flushPortableMicrotasks();
|
|
16
|
+
* console.log(ran); // true
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
2
19
|
export declare function flushPortableMicrotasks(turns?: number): Promise<void>;
|
|
3
|
-
/**
|
|
20
|
+
/**
|
|
21
|
+
* Yield one full event-loop turn without importing test-runner-only timer APIs,
|
|
22
|
+
* then drain microtasks. Prefers a `MessageChannel` postMessage (a macrotask)
|
|
23
|
+
* and falls back to `setTimeout(0)` where `MessageChannel` is unavailable.
|
|
24
|
+
*
|
|
25
|
+
* Use it in an `afterEach` to drain a prior test's deferred inline workflow
|
|
26
|
+
* launch: under a shared-process runner (Bun, Jest, Vitest), an engine disposed
|
|
27
|
+
* mid-workflow can leave a queued inline start that would otherwise starve the
|
|
28
|
+
* next test's timers.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```ts
|
|
32
|
+
* import { afterEach } from 'bun:test';
|
|
33
|
+
* import { yieldToPortableEventLoop } from '@lostgradient/weft/testing';
|
|
34
|
+
*
|
|
35
|
+
* afterEach(yieldToPortableEventLoop);
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
4
38
|
export declare function yieldToPortableEventLoop(): Promise<void>;
|
package/dist/testing/index.d.ts
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
* @module @lostgradient/weft/testing
|
|
9
9
|
*/
|
|
10
10
|
import { ChaosNonRetryableError, ChaosTimeoutError, ChaosTransientError, withChaos } from './chaos';
|
|
11
|
+
import { flushPortableMicrotasks, yieldToPortableEventLoop } from './event-loop';
|
|
11
12
|
import { ActivityMockRegistry } from './mocks';
|
|
12
13
|
import { killAndReboot, spawnServerSubprocess, withSubprocessServer } from './subprocess-engine';
|
|
13
14
|
import { TestEngine } from './test-engine';
|
|
@@ -119,8 +120,37 @@ declare const exportedKillAndReboot: typeof killAndReboot;
|
|
|
119
120
|
* ```
|
|
120
121
|
*/
|
|
121
122
|
declare const exportedWithSubprocessServer: typeof withSubprocessServer;
|
|
123
|
+
/**
|
|
124
|
+
* Re-exported {@link yieldToPortableEventLoop}. See the original declaration for full docs.
|
|
125
|
+
*
|
|
126
|
+
* Yields one event-loop turn without test-runner-only timer APIs. Use it in an
|
|
127
|
+
* `afterEach` to drain a prior test's deferred inline workflow launch: under a
|
|
128
|
+
* shared-process runner (Bun, Jest, Vitest), an engine disposed mid-workflow can
|
|
129
|
+
* otherwise leave a queued inline start that starves the next test.
|
|
130
|
+
*
|
|
131
|
+
* @example
|
|
132
|
+
* ```ts
|
|
133
|
+
* import { yieldToPortableEventLoop } from '@lostgradient/weft/testing';
|
|
134
|
+
* afterEach(yieldToPortableEventLoop);
|
|
135
|
+
* ```
|
|
136
|
+
*/
|
|
137
|
+
declare const exportedYieldToPortableEventLoop: typeof yieldToPortableEventLoop;
|
|
138
|
+
/**
|
|
139
|
+
* Re-exported {@link flushPortableMicrotasks}. See the original declaration for full docs.
|
|
140
|
+
*
|
|
141
|
+
* Lets queued microtasks settle without advancing time or yielding a full
|
|
142
|
+
* event-loop turn — the cheaper drain when you only need promise continuations
|
|
143
|
+
* to run.
|
|
144
|
+
*
|
|
145
|
+
* @example
|
|
146
|
+
* ```ts
|
|
147
|
+
* import { flushPortableMicrotasks } from '@lostgradient/weft/testing';
|
|
148
|
+
* await flushPortableMicrotasks();
|
|
149
|
+
* ```
|
|
150
|
+
*/
|
|
151
|
+
declare const exportedFlushPortableMicrotasks: typeof flushPortableMicrotasks;
|
|
122
152
|
export type { ChaosScenario, FaultClass } from './chaos';
|
|
123
153
|
export type { MockCall, MockedActivity, MockHandle } from './mocks';
|
|
124
154
|
export type { SubprocessServerHandle, SubprocessServerOptions, SubprocessServerProcess, SubprocessSignal, } from './subprocess-engine';
|
|
125
155
|
export type { RunNOptions, RunNResult } from './test-engine';
|
|
126
|
-
export { exportedActivityMockRegistry as ActivityMockRegistry, exportedChaosNonRetryableError as ChaosNonRetryableError, exportedChaosTimeoutError as ChaosTimeoutError, exportedChaosTransientError as ChaosTransientError, exportedKillAndReboot as killAndReboot, exportedSpawnServerSubprocess as spawnServerSubprocess, exportedTestEngine as TestEngine, exportedTimeControl as TimeControl, exportedWithChaos as withChaos, exportedWithSubprocessServer as withSubprocessServer, };
|
|
156
|
+
export { exportedActivityMockRegistry as ActivityMockRegistry, exportedChaosNonRetryableError as ChaosNonRetryableError, exportedChaosTimeoutError as ChaosTimeoutError, exportedChaosTransientError as ChaosTransientError, exportedFlushPortableMicrotasks as flushPortableMicrotasks, exportedKillAndReboot as killAndReboot, exportedSpawnServerSubprocess as spawnServerSubprocess, exportedTestEngine as TestEngine, exportedTimeControl as TimeControl, exportedWithChaos as withChaos, exportedWithSubprocessServer as withSubprocessServer, exportedYieldToPortableEventLoop as yieldToPortableEventLoop, };
|