@lostgradient/weft 0.24.1 → 0.24.2
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/README.md +1 -1
- package/dist/core/engine/bulk-operations-purge.d.ts +1 -1
- package/dist/core/engine/bulk-operations-purge.js +3 -2
- package/dist/core/engine/bulk-operations-retry.d.ts +16 -1
- package/dist/core/engine/bulk-operations-retry.js +19 -6
- package/dist/core/engine/bulk-operations.d.ts +3 -2
- package/dist/core/engine/bulk-operations.js +2 -2
- package/dist/core/engine/callback-creators-bundles.js +1 -1
- package/dist/core/engine/callback-creators-schedule.js +2 -2
- package/dist/core/engine/child-workflow.d.ts +13 -1
- package/dist/core/engine/child-workflow.js +22 -4
- package/dist/core/engine/generation-codec.d.ts +22 -0
- package/dist/core/engine/generation-codec.js +2 -0
- package/dist/core/engine/index.js +1 -1
- package/dist/core/engine/lifecycle/recovery-isolation.d.ts +20 -0
- package/dist/core/engine/lifecycle/recovery-isolation.js +26 -0
- package/dist/core/engine/lifecycle/resume-body.d.ts +44 -0
- package/dist/core/engine/lifecycle/resume-body.js +211 -0
- package/dist/core/engine/lifecycle/resume.d.ts +46 -3
- package/dist/core/engine/lifecycle/resume.js +21 -210
- package/dist/core/engine/lifecycle/standalone-claim-acquire.d.ts +68 -2
- package/dist/core/engine/lifecycle/standalone-claim-acquire.js +14 -4
- package/dist/core/engine/lifecycle/start-commit.d.ts +2 -0
- package/dist/core/engine/lifecycle/start-commit.js +16 -8
- package/dist/core/engine/lifecycle/start-or-signal-resolution.d.ts +8 -2
- package/dist/core/engine/lifecycle/start-or-signal-resolution.js +11 -3
- package/dist/core/engine/lifecycle/start-precondition-attribution.d.ts +10 -4
- package/dist/core/engine/lifecycle/start-schedule-timing.d.ts +11 -0
- package/dist/core/engine/lifecycle/start-schedule-timing.js +21 -0
- package/dist/core/engine/lifecycle/start-terminal-conflict-purge.d.ts +90 -11
- package/dist/core/engine/lifecycle/start-terminal-conflict-purge.js +24 -5
- package/dist/core/engine/lifecycle/start.d.ts +40 -3
- package/dist/core/engine/lifecycle/start.js +19 -26
- package/dist/core/engine/lifecycle/transition.d.ts +9 -0
- package/dist/core/engine/lifecycle/transition.js +20 -25
- package/dist/core/engine/lifecycle.d.ts +2 -1
- package/dist/core/engine/lifecycle.js +2 -1
- package/dist/core/engine/schedule-overlap.js +2 -1
- package/dist/core/engine/schedule-run.d.ts +10 -0
- package/dist/core/engine/schedule-run.js +1 -1
- package/dist/core/engine/schedules.d.ts +11 -2
- package/dist/core/engine/termination/complete.js +1 -1
- package/dist/core/engine/termination/suspend.js +3 -0
- package/dist/core/engine/validation/schedule.d.ts +25 -1
- package/dist/core/engine/validation/schedule.js +4 -10
- package/dist/core/engine/validation.js +10 -17
- package/dist/core/engine/workflow-claim-reclaim-target.js +6 -6
- package/dist/core/engine/workflow-claim-registry.d.ts +79 -75
- package/dist/core/engine/workflow-claim-registry.js +15 -2
- package/dist/core/engine/workflow-generation-fence.d.ts +74 -0
- package/dist/core/engine/workflow-generation-fence.js +19 -0
- package/dist/core/start-workflow-validation.d.ts +15 -0
- package/dist/core/start-workflow-validation.js +11 -1
- package/dist/core/workflow-identifiers.d.ts +37 -0
- package/dist/core/workflow-identifiers.js +19 -1
- package/dist/http.js +2 -2
- package/dist/indexeddb.js +1 -1
- package/dist/server/fleet-event-feed.js +6 -6
- package/dist/server/rest-binding.d.ts +11 -0
- package/dist/server/runtime/task-dispatch-envelope.d.ts +32 -5
- package/dist/server/runtime/task-dispatch-envelope.js +23 -1
- package/dist/server/runtime/task-dispatch.d.ts +3 -1
- package/dist/server/runtime/task-dispatch.js +9 -8
- package/dist/server/task-ledger-codec.d.ts +19 -0
- package/dist/server/task-ledger-codec.js +3 -0
- package/dist/server/task-ledger.d.ts +1 -1
- package/dist/server/task-ledger.js +1 -0
- package/dist/storage/bun-sql.js +132 -99
- package/dist/storage/compressed-storage.js +1 -1
- package/dist/storage/generation-keys.d.ts +52 -0
- package/dist/storage/generation-keys.js +4 -0
- package/dist/storage/index.d.ts +76 -65
- package/dist/storage/interface.d.ts +24 -232
- 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/lease-keys.d.ts +48 -0
- package/dist/storage/lease-keys.js +8 -0
- package/dist/storage/lmdb.js +1 -1
- package/dist/storage/memory.js +1 -1
- package/dist/storage/neon.js +3 -3
- package/dist/storage/node-sqlite.js +132 -99
- package/dist/storage/postgres.js +3 -3
- package/dist/storage/resolve.js +1 -1
- package/dist/storage/scoped-storage.js +1 -1
- package/dist/storage/signal-keys.d.ts +23 -0
- package/dist/storage/signal-keys.js +9 -0
- package/dist/storage/testing.js +1 -1
- package/dist/storage/turso.js +2 -2
- package/dist/storage/workflow-lifecycle-keys.d.ts +128 -0
- package/dist/storage/workflow-lifecycle-keys.js +46 -0
- package/dist/storage/workflow-record-keys.d.ts +98 -0
- package/dist/storage/workflow-record-keys.js +47 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/web-extension.js +1 -1
- package/package.json +1 -1
package/dist/http.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
async function*
|
|
2
|
-
`);o=C.pop()??"";for(let Y of C)yield Y}if(o+=i.decode(),o.length>0)yield o}finally{if(!u)try{await r.cancel()}catch{}r.releaseLock()}}function b(e){let t=[];for(let r=0;r<e.length;r+=512)t.push(String.fromCharCode(...e.subarray(r,r+512)));return btoa(t.join(""))}function R(e){let t=atob(e),r=new Uint8Array(t.length);for(let i=0;i<t.length;i+=1)r[i]=t.charCodeAt(i);return r}function S(e){return typeof e==="object"&&e!==null&&!Array.isArray(e)}async function f(e,t){return await e.get(t)!==null}async function*c(e,t,r){for await(let[i]of e.scan(t,r))yield i}async function m(e,t){let r=0;for await(let i of c(e,t))r++;return r}async function y(e,t){let r=[];for await(let i of c(e,t))r.push({type:"delete",key:i});if(r.length===0)return 0;return await e.batch(r),r.length}async function h(e,t,r){let i=[];for await(let o of c(e,t,r))i.push({type:"delete",key:o});if(i.length===0)return 0;return await e.batch(i),i.length}function P(e,t,r){if(!e.capabilities()[t])throw Error(`Feature "${r}" requires storage capability "${t}", but this storage backend does not provide it.`)}function n(e){return encodeURIComponent(e)}function s(e){return String(e).padStart(16,"0")}var k={catalogEntry:(e,t)=>`catalog-entry:${n(e)}:${n(t)}`,catalogEntryPrefix:(e)=>`catalog-entry:${n(e)}:`,catalogActive:(e)=>`catalog-active:${n(e)}`,catalogTombstone:(e,t)=>`catalog-tombstone:${n(e)}:${n(t)}`,catalogTombstonePrefix:()=>"catalog-tombstone:"};var T="default";var E={applicationMailbox:(e,t)=>`appmbx:v1:${n(e)}:${n(t)}`,applicationMailboxSinkProbe:(e,t,r)=>`appprobe:v1:${n(e)}:${n(t)}:${n(r)}`,applicationCommandPrefix:(e,t)=>`appcmd:v1:${n(e)}:${n(t)}:`,applicationCommand:(e,t,r)=>`appcmd:v1:${n(e)}:${n(t)}:${n(r)}`,applicationCommandReadyPrefix:(e,t)=>`appready:v1:${n(e)}:${n(t)}:`,applicationCommandReady:(e,t,r)=>`appready:v1:${n(e)}:${n(t)}:${s(r)}`,applicationCommandIdempotency:(e,t,r)=>`appidem:v1:${n(e)}:${n(t)}:${n(r)}`,applicationCommandBySequencePrefix:(e,t)=>`appseq:v1:${n(e)}:${n(t)}:`,applicationCommandBySequence:(e,t,r)=>`appseq:v1:${n(e)}:${n(t)}:${s(r)}`,applicationCommandTerminalPrefix:(e,t)=>`appterm:v1:${n(e)}:${n(t)}:`,applicationCommandTerminal:(e,t,r,i)=>`appterm:v1:${n(e)}:${n(t)}:${s(r)}:${n(i)}`};var A={applicationOutbox:(e,t)=>`appobx:v1:${n(e)}:${n(t)}`,applicationOutboxSinkProbe:(e,t,r)=>`appprobe:v1:outbox:${n(e)}:${n(t)}:${n(r)}`,applicationDeliveryPrefix:(e,t)=>`appdlv:v1:${n(e)}:${n(t)}:`,applicationDelivery:(e,t,r)=>`appdlv:v1:${n(e)}:${n(t)}:${n(r)}`,applicationDeliveryDuePrefix:(e,t)=>`appdue:v1:${n(e)}:${n(t)}:`,applicationDeliveryDue:(e,t,r,i)=>`appdue:v1:${n(e)}:${n(t)}:${s(r)}:${n(i)}`,applicationDeliveryIdempotency:(e,t,r)=>`appdidem:v1:${n(e)}:${n(t)}:${n(r)}`,applicationDeliveryBySequencePrefix:(e,t)=>`appdseq:v1:${n(e)}:${n(t)}:`,applicationDeliveryBySequence:(e,t,r)=>`appdseq:v1:${n(e)}:${n(t)}:${s(r)}`,applicationDeliveryTerminalPrefix:(e,t)=>`appdterm:v1:${n(e)}:${n(t)}:`,applicationDeliveryTerminal:(e,t,r,i)=>`appdterm:v1:${n(e)}:${n(t)}:${s(r)}:${n(i)}`};var D={workflowOwnerEpoch:(e)=>`wf-owner-epoch:${n(e)}`,workflowOwnerHolder:(e)=>`wf-owner-holder:${n(e)}`,ownershipModeMarker:()=>"ownership-mode-marker"};var w=1e4;class I extends Error{code="StorageBatchOperationLimitExceededError";cap=w;count;target;constructor(e,t){super(`${e} count ${t} exceeds MAX_BATCH_OPERATIONS (${w}).`);this.name="StorageBatchOperationLimitExceededError",this.target=e,this.count=t}}function g(e,t){if(t>w)throw new I(e,t)}function L(e){return e.length>0?e.slice(0,-1)+String.fromCharCode(e.charCodeAt(e.length-1)+1):"ÿ"}function Re(e,t={}){if(t.gt!==void 0&&e<=t.gt)return!1;if(t.gte!==void 0&&e<t.gte)return!1;if(t.lt!==void 0&&e>=t.lt)return!1;if(t.lte!==void 0&&e>t.lte)return!1;return!0}function Pe(e,t){if(e===null||t===null)return e===t;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}async function _(e,t){if(e.has)return e.has(t);return f(e,t)}function K(e,t,r){if(e.keys)return e.keys(t,r);return c(e,t,r)}async function N(e,t){if(e.count)return e.count(t);return m(e,t)}async function H(e,t){if(e.deletePrefix)return e.deletePrefix(t);return y(e,t)}async function z(e,t,r){if(g("conditionalBatch conditions",t.length),g("conditionalBatch operations",r.length),P(e,"conditionalBatch","storageConditionalBatch"),!e.conditionalBatch)throw Error("This storage backend reports conditionalBatch capability but does not implement the conditionalBatch() method.");return e.conditionalBatch(t,r)}var a=s,G="0",j="1",U=(e,t,r,i)=>`sig:${n(e)}:${n(t)}:${i}:${n(r)}`,ke={workflow:(e)=>`wf:${n(e)}`,checkpoint:(e)=>`wf:${n(e)}:ckpt`,checkpointHistory:(e,t)=>`wf:${n(e)}:ckpt:${String(t).padStart(10,"0")}`,timelinePrefix:(e)=>`wf:${n(e)}:timeline:`,timeline:(e,t)=>`wf:${n(e)}:timeline:${String(t).padStart(10,"0")}`,schedule:(e)=>`schedule:${n(e)}`,scheduleTick:(e,t)=>`schedule-due:${String(e).padStart(16,"0")}:${n(t)}`,scheduleRun:(e)=>`schedule-run:${n(e)}`,scheduleRunLink:(e)=>`schedule-run-link:${n(e)}`,scheduleRunBySchedulePrefix:(e)=>`schedule-run-by-schedule:${n(e)}:`,scheduleRunBySchedule:(e,t)=>`schedule-run-by-schedule:${n(e)}:${n(t)}`,operation:(e,t,r)=>`op:${e}:${a(t)}:${r}`,operationInflight:(e)=>`op:inflight:${e}`,operationQueued:(e)=>`op:queued:${e}`,operationResolved:(e)=>`op:resolved:${e}`,bulkOperationAuditPrefix:()=>"audit:bulk:",bulkOperationAudit:(e,t,r)=>`audit:bulk:${a(e)}:${n(t)}:${n(r)}`,operationResolvedByTimePrefix:()=>"op:resolved-by-time:",operationResolvedByTime:(e,t)=>`op:resolved-by-time:${a(e)}:${n(t)}`,asyncActivity:(e,t)=>`async-act:v1:${n(e)}:${n(t)}`,asyncActivityResolution:(e,t)=>`async-act:v1:${n(e)}:${n(t)}:resolution`,activityReconciliationPrefix:(e)=>`actrec:v1:${n(e)}:`,activityReconciliation:(e,t,r)=>`actrec:v1:${n(e)}:${n(t)}:${r}`,eventPrefix:(e)=>`ev:${n(e)}:`,event:(e,t)=>`ev:${n(e)}:${String(t).padStart(10,"0")}`,eventHead:(e)=>`ev:${n(e)}:head`,eventWatermark:(e)=>`ev:${n(e)}:watermark`,fleetEventPrefix:()=>"fleet-event:",fleetEvent:(e)=>`fleet-event:${String(e).padStart(10,"0")}`,fleetEventTail:()=>"fleet-event-tail",fleetEventWatermark:()=>"fleet-event-watermark",fleetEventByWorkflowPrefix:(e)=>`fleet-event-by-workflow:${n(e)}:`,fleetEventByWorkflow:(e,t)=>`fleet-event-by-workflow:${n(e)}:${String(t).padStart(10,"0")}`,signal:(e,t,r)=>U(e,t,r,j),startSignal:(e,t,r)=>U(e,t,r,G),signalSequence:(e)=>`sigseq:v1:${n(e)}`,signalAcceptedResponsePrefix:(e)=>`sigres:v1:${n(e)}:`,signalAcceptedResponse:(e,t,r)=>`sigres:v1:${n(e)}:${n(t)}:${n(r)}`,deadline:(e,t)=>`wf-deadline:${a(e)}:${n(t)}`,terminalCleanup:(e,t)=>`wf-cleanup:${a(e)}:${n(t)}`,teardownTimer:(e,t)=>`wf-teardown:${a(e)}:${n(t)}`,delayedStart:(e,t)=>`wf-delayed:${a(e)}:${n(t)}`,terminalWorkflowPrefix:()=>"wf-terminal:",terminalWorkflow:(e,t)=>`wf-terminal:${a(e)}:${n(t)}`,attribute:(e)=>`attr:${n(e)}`,attributeIndex:(e,t,r)=>`idx:${e}:${t}:${n(r)}`,tagIndex:(e,t)=>`tag:${n(e)}:${n(t)}`,updatePrefix:(e)=>`upd:${n(e)}:`,update:(e,t)=>`upd:${n(e)}:${t}`,updateResponse:(e)=>`upr:${e}`,updateIdempotency:(e,t)=>`upk:${n(e)}:${t}`,startIdempotency:(e)=>`start-idem:${n(e)}`,startIdempotencySignalId:(e)=>`start-idem:${e}`,livenessPrefix:()=>"liveness:",liveness:(e)=>`liveness:${n(e)}`,leasePrefix:()=>"lease:",leaseEpoch:()=>"lease:epoch",leaseHolder:()=>"lease:holder",...E,...A,...D,...k,budget:(e,t,r)=>`budget:${e}:${t}:${r}`,review:(e,t)=>`review:${n(e)}:${t}`,workflowHeaders:(e)=>`wf-headers:${n(e)}`,childCancellationPrefix:(e)=>`child-cancel:${n(e)}:`,childCancellation:(e,t)=>`child-cancel:${n(e)}:${n(t)}`,childWorkflowByParentPrefix:(e,t)=>`child-by-parent:${n(e)}:${t===void 0?"":`${n(t)}:`}`,childWorkflowByParent:(e,t,r)=>`child-by-parent:${n(e)}:${t===void 0?"":`${n(t)}:`}${n(r)}`,terminalCleanupNeeded:(e)=>`wf-cleanup-needed:${n(e)}`,workflowConcurrency:(e,t)=>`wf-concurrency:${n(e)}:${n(t)}`,workflowConcurrencyHolder:(e)=>`wf-concurrency-holder:${n(e)}`,workflowHasServices:(e)=>`wf-has-services:${n(e)}`,finalizerState:(e)=>`wf-finalizer-state:${n(e)}`,teardownOwed:(e)=>`wf-teardown-needed:${n(e)}`,teardownSucceeded:(e)=>`wf-teardown-succeeded:${n(e)}`,teardownDeadLetter:(e)=>`wf-teardown-deadletter:${n(e)}`,offload:(e,t)=>`offload:${n(e)}:${t}`,archive:(e,t)=>`archive:${n(e)}:${t}`,stateExecution:(e,t)=>`state:execution:${n(e)}:${n(t)}`,stateWorkflow:(e,t)=>`state:workflow-scope:${T}:${n(e)}:${n(t)}`,streamChunkPrefix:(e,t)=>`blob:${n(e)}:${t}:chunk:`,streamChunk:(e,t,r)=>`blob:${n(e)}:${t}:chunk:${String(r).padStart(10,"0")}`,streamTail:(e,t)=>`blob:${n(e)}:${t}:tail`,streamMetadata:(e,t)=>`blob:${n(e)}:${t}:meta`,budgetCharged:(e)=>`budget-charged:${e}`,toolEffect:(e,t,r)=>`tool-effect:${n(e)}:${t}:${r}`,workflowVisibilityStatus:(e,t)=>`wf-idx-status:${n(e)}:${n(t)}`,workflowVisibilityType:(e,t)=>`wf-idx-type:${n(e)}:${n(t)}`,workflowVisibilityCreated:(e,t)=>`wf-idx-created:${a(e)}:${n(t)}`,workflowVisibilityUpdated:(e,t)=>`wf-idx-updated:${a(e)}:${n(t)}`,workflowVisibilityDeadline:(e,t)=>`wf-idx-deadline:${a(e)}:${n(t)}`,workflowVisibilityManifest:(e)=>`wf-idx-manifest:${n(e)}`,workflowVisibilityMetaVersion:()=>"wf-idx-meta:version",workflowVisibilityMetaBuiltAt:()=>"wf-idx-meta:built-at",workflowVisibilityMetaCursor:()=>"wf-idx-meta:cursor"};function F(e){if(e===void 0)return;if(typeof e!=="number"||!Number.isInteger(e)||e<0)throw Error("deleteRange limit must be a finite non-negative integer");return e===0?0:e}function p(e){let t={},r=!1;for(let o of["gt","gte","lt","lte"]){let l=e[o];if(l===void 0)continue;if(typeof l!=="string")throw Error("deleteRange bounds must be strings");t[o]=l,r=!0}if(!r)throw Error("deleteRange requires at least one of gt/gte/lt/lte; use deletePrefix to delete a whole prefix");let i=F(e.limit);if(i!==void 0)t.limit=i;return t}async function q(e,t,r){let i=p(r);if(e.deleteRange)return e.deleteRange(t,i);return h(e,t,i)}function X(e,t){let r={key:e,open:!1};if(t.gte!==void 0&&t.gte>r.key)r.key=t.gte,r.open=!1;if(t.gt!==void 0&&t.gt>=r.key)r.key=t.gt,r.open=!0;return r}function J(e,t){let r={key:L(e),open:!0};if(t.lt!==void 0&&t.lt<=r.key)r.key=t.lt,r.open=!0;if(t.lte!==void 0&&t.lte<r.key)r.key=t.lte,r.open=!1;return r}function De(e,t){let r=X(e,t),i=J(e,t);if(r.key>i.key||r.key===i.key&&(r.open||i.open))return null;return{lower:r,upper:i}}function x(e){return e.replaceAll(/:+$/g,"")}function Z(e,t){let r=x(e),i=x(t);if(r.length===0)return i;if(i.length===0)return r;return`${r}:${i}`}class v{#e;#n;constructor(e,t){this.#e=e,this.#n=x(t)}#t(e){if(this.#n.length===0)return e;return e.length===0?`${this.#n}:`:`${this.#n}:${e}`}#i(e){return e.map((t)=>{if(t.type==="put")return{type:"put",key:this.#t(t.key),value:t.value};return{type:"delete",key:this.#t(t.key)}})}#o(e){if(this.#n.length===0)return e;return e.slice(this.#n.length+1)}#a(e){let t={};if(e.limit!==void 0)t.limit=e.limit;if(e.gt!==void 0)t.gt=this.#t(e.gt);if(e.gte!==void 0)t.gte=this.#t(e.gte);if(e.lt!==void 0)t.lt=this.#t(e.lt);if(e.lte!==void 0)t.lte=this.#t(e.lte);return t}#r(e={}){let t=this.#a(e);if(e.reverse!==void 0)t.reverse=e.reverse;return t}#s(e){return this.#a(e)}capabilities(){return this.#e.capabilities()}scoped(e){return new v(this.#e,Z(this.#n,e))}async get(e){return this.#e.get(this.#t(e))}async put(e,t){await this.#e.put(this.#t(e),t)}async delete(e){await this.#e.delete(this.#t(e))}async*scan(e,t){for await(let[r,i]of this.#e.scan(this.#t(e),this.#r(t)))yield[this.#o(r),i]}async batch(e){g("batch operations",e.length),await this.#e.batch(this.#i(e))}async conditionalBatch(e,t){return z(this.#e,e.map((r)=>({key:this.#t(r.key),expectedValue:r.expectedValue})),this.#i(t))}async has(e){return _(this.#e,this.#t(e))}async deletePrefix(e){return H(this.#e,this.#t(e))}async deleteRange(e,t){let r=this.#s(p(t));return q(this.#e,this.#t(e),r)}async*keys(e,t){for await(let r of K(this.#e,this.#t(e),this.#r(t)))yield this.#o(r)}async count(e){return N(this.#e,this.#t(e))}[Symbol.dispose](){this.#e[Symbol.dispose]()}}function W(e,t){return new v(e,t)}var Q=67108864;function M(e){if(e.type==="put")return{type:"put",key:e.key,value:b(e.value)};return{type:"delete",key:e.key}}function ee(e){return{key:e.key,expectedValue:e.expectedValue===null?null:b(e.expectedValue)}}function te(e){if(!S(e)||typeof e.key!=="string"||typeof e.value!=="string")throw Error("HTTPStorage scan response contained an invalid NDJSON entry.");return{key:e.key,value:e.value}}function ne(e){if(!S(e)||typeof e.applied!=="boolean")throw Error('HTTPStorage conditional batch response must include a boolean "applied" field.');return e.applied}function d(e,t,r){if(r!==void 0)e.searchParams.set(t,String(r))}function re(e){if(e.trim().length===0)return null;let t=te(JSON.parse(e));return[t.key,R(t.value)]}class ie{#e;#n;#t;constructor(e){this.#e=e.baseUrl instanceof URL?e.baseUrl:new URL(e.baseUrl),this.#n={...e.headers},this.#t=e.remoteConditionalBatch??!1}capabilities(){return{persistence:"remote",readAfterWrite:"eventual",scanConsistency:"best-effort",atomicBatch:!0,conditionalBatch:this.#t,boundedRangeDelete:!1}}#i(e){let t=this.#e.href.endsWith("/")?this.#e.href:`${this.#e.href}/`;return new URL(e.replace(/^\/+/,""),t)}#o(e){return this.#i(`/v1/storage/${encodeURIComponent(e)}`)}#a(e,t){let r=this.#i("/v1/storage");return r.searchParams.set("prefix",e),d(r,"limit",t.limit),d(r,"reverse",t.reverse),d(r,"gt",t.gt),d(r,"gte",t.gte),d(r,"lt",t.lt),d(r,"lte",t.lte),r}async#r(e,t={},r=[]){let i=new Headers(this.#n);for(let[l,u]of new Headers(t.headers).entries())i.set(l,u);let o=await fetch(e,{...t,headers:i});if(!o.ok&&!r.includes(o.status))throw Error(`HTTPStorage request failed: ${t.method??"GET"} ${e.pathname} returned ${String(o.status)}.`);return o}async get(e){let t=await this.#r(this.#o(e),{method:"GET"},[404]);if(t.status===404)return null;return new Uint8Array(await t.arrayBuffer())}async put(e,t){await this.#r(this.#o(e),{method:"PUT",headers:{"content-type":"application/octet-stream"},body:new Blob([new Uint8Array(t)])})}async delete(e){await this.#r(this.#o(e),{method:"DELETE"})}async*scan(e,t={}){let r=await this.#r(this.#a(e,t),{method:"GET",headers:{accept:"application/x-ndjson"}});for await(let i of B(r,{maximumBytes:Q,sizeLimitError:()=>Error("HTTPStorage scan response exceeded the maximum allowed size.")})){let o=re(i);if(o!==null)yield o}}async batch(e){g("batch operations",e.length),await this.#r(this.#i("/v1/storage/-/batch"),{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({operations:e.map(M)})})}async conditionalBatch(e,t){g("conditionalBatch conditions",e.length),g("conditionalBatch operations",t.length);let r=await this.#r(this.#i("/v1/storage/-/conditional-batch"),{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({conditions:e.map(ee),operations:t.map(M)})});return ne(await r.json())}has(e){return f(this,e)}async*keys(e,t){yield*c(this,e,t)}count(e){return m(this,e)}deletePrefix(e){return y(this,e)}deleteRange(e,t){return h(this,e,p(t))}scoped(e){return W(this,e)}[Symbol.dispose](){}}export{ie as HTTPStorage};
|
|
1
|
+
async function*v(e,t){if(e.body===null)return;let r=e.body.getReader(),i=new TextDecoder,o="",s=0,u=!1;try{while(!0){let{done:Q,value:C}=await r.read();if(Q){u=!0;break}if(s+=C.byteLength,s>t.maximumBytes)throw t.sizeLimitError();o+=i.decode(C,{stream:!0});let x=o.split(`
|
|
2
|
+
`);o=x.pop()??"";for(let ee of x)yield ee}if(o+=i.decode(),o.length>0)yield o}finally{if(!u)try{await r.cancel()}catch{}r.releaseLock()}}function S(e){let t=[];for(let r=0;r<e.length;r+=512)t.push(String.fromCharCode(...e.subarray(r,r+512)));return btoa(t.join(""))}function B(e){let t=atob(e),r=new Uint8Array(t.length);for(let i=0;i<t.length;i+=1)r[i]=t.charCodeAt(i);return r}function b(e){return typeof e==="object"&&e!==null&&!Array.isArray(e)}async function f(e,t){return await e.get(t)!==null}async function*c(e,t,r){for await(let[i]of e.scan(t,r))yield i}async function m(e,t){let r=0;for await(let i of c(e,t))r++;return r}async function y(e,t){let r=[];for await(let i of c(e,t))r.push({type:"delete",key:i});if(r.length===0)return 0;return await e.batch(r),r.length}async function h(e,t,r){let i=[];for await(let o of c(e,t,r))i.push({type:"delete",key:o});if(i.length===0)return 0;return await e.batch(i),i.length}function P(e,t,r){if(!e.capabilities()[t])throw Error(`Feature "${r}" requires storage capability "${t}", but this storage backend does not provide it.`)}function n(e){return encodeURIComponent(e)}function a(e){return String(e).padStart(16,"0")}var k={catalogEntry:(e,t)=>`catalog-entry:${n(e)}:${n(t)}`,catalogEntryPrefix:(e)=>`catalog-entry:${n(e)}:`,catalogActive:(e)=>`catalog-active:${n(e)}`,catalogTombstone:(e,t)=>`catalog-tombstone:${n(e)}:${n(t)}`,catalogTombstonePrefix:()=>"catalog-tombstone:"};var T={workflowGeneration:(e)=>`wf-gen:${n(e)}`};var _={livenessPrefix:()=>"liveness:",liveness:(e)=>`liveness:${n(e)}`,leasePrefix:()=>"lease:",leaseEpoch:()=>"lease:epoch",leaseHolder:()=>"lease:holder"};var D={applicationMailbox:(e,t)=>`appmbx:v1:${n(e)}:${n(t)}`,applicationMailboxSinkProbe:(e,t,r)=>`appprobe:v1:${n(e)}:${n(t)}:${n(r)}`,applicationCommandPrefix:(e,t)=>`appcmd:v1:${n(e)}:${n(t)}:`,applicationCommand:(e,t,r)=>`appcmd:v1:${n(e)}:${n(t)}:${n(r)}`,applicationCommandReadyPrefix:(e,t)=>`appready:v1:${n(e)}:${n(t)}:`,applicationCommandReady:(e,t,r)=>`appready:v1:${n(e)}:${n(t)}:${a(r)}`,applicationCommandIdempotency:(e,t,r)=>`appidem:v1:${n(e)}:${n(t)}:${n(r)}`,applicationCommandBySequencePrefix:(e,t)=>`appseq:v1:${n(e)}:${n(t)}:`,applicationCommandBySequence:(e,t,r)=>`appseq:v1:${n(e)}:${n(t)}:${a(r)}`,applicationCommandTerminalPrefix:(e,t)=>`appterm:v1:${n(e)}:${n(t)}:`,applicationCommandTerminal:(e,t,r,i)=>`appterm:v1:${n(e)}:${n(t)}:${a(r)}:${n(i)}`};var A={applicationOutbox:(e,t)=>`appobx:v1:${n(e)}:${n(t)}`,applicationOutboxSinkProbe:(e,t,r)=>`appprobe:v1:outbox:${n(e)}:${n(t)}:${n(r)}`,applicationDeliveryPrefix:(e,t)=>`appdlv:v1:${n(e)}:${n(t)}:`,applicationDelivery:(e,t,r)=>`appdlv:v1:${n(e)}:${n(t)}:${n(r)}`,applicationDeliveryDuePrefix:(e,t)=>`appdue:v1:${n(e)}:${n(t)}:`,applicationDeliveryDue:(e,t,r,i)=>`appdue:v1:${n(e)}:${n(t)}:${a(r)}:${n(i)}`,applicationDeliveryIdempotency:(e,t,r)=>`appdidem:v1:${n(e)}:${n(t)}:${n(r)}`,applicationDeliveryBySequencePrefix:(e,t)=>`appdseq:v1:${n(e)}:${n(t)}:`,applicationDeliveryBySequence:(e,t,r)=>`appdseq:v1:${n(e)}:${n(t)}:${a(r)}`,applicationDeliveryTerminalPrefix:(e,t)=>`appdterm:v1:${n(e)}:${n(t)}:`,applicationDeliveryTerminal:(e,t,r,i)=>`appdterm:v1:${n(e)}:${n(t)}:${a(r)}:${n(i)}`};var L={workflowOwnerEpoch:(e)=>`wf-owner-epoch:${n(e)}`,workflowOwnerHolder:(e)=>`wf-owner-holder:${n(e)}`,ownershipModeMarker:()=>"ownership-mode-marker"};var te="0",ne="1",K=(e,t,r,i)=>`sig:${n(e)}:${n(t)}:${i}:${n(r)}`,I={signal:(e,t,r)=>K(e,t,r,ne),startSignal:(e,t,r)=>K(e,t,r,te),signalSequence:(e)=>`sigseq:v1:${n(e)}`,signalAcceptedResponsePrefix:(e)=>`sigres:v1:${n(e)}:`,signalAcceptedResponse:(e,t,r)=>`sigres:v1:${n(e)}:${n(t)}:${n(r)}`};var U="default";var l=a,N={deadline:(e,t)=>`wf-deadline:${l(e)}:${n(t)}`,terminalCleanup:(e,t)=>`wf-cleanup:${l(e)}:${n(t)}`,teardownTimer:(e,t)=>`wf-teardown:${l(e)}:${n(t)}`,delayedStart:(e,t)=>`wf-delayed:${l(e)}:${n(t)}`,terminalWorkflowPrefix:()=>"wf-terminal:",terminalWorkflow:(e,t)=>`wf-terminal:${l(e)}:${n(t)}`},W={budget:(e,t,r)=>`budget:${e}:${t}:${r}`,review:(e,t)=>`review:${n(e)}:${t}`,workflowHeaders:(e)=>`wf-headers:${n(e)}`,childCancellationPrefix:(e)=>`child-cancel:${n(e)}:`,childCancellation:(e,t)=>`child-cancel:${n(e)}:${n(t)}`,childWorkflowByParentPrefix:(e,t)=>`child-by-parent:${n(e)}:${t===void 0?"":`${n(t)}:`}`,childWorkflowByParent:(e,t,r)=>`child-by-parent:${n(e)}:${t===void 0?"":`${n(t)}:`}${n(r)}`,terminalCleanupNeeded:(e)=>`wf-cleanup-needed:${n(e)}`,workflowConcurrency:(e,t)=>`wf-concurrency:${n(e)}:${n(t)}`,workflowConcurrencyHolder:(e)=>`wf-concurrency-holder:${n(e)}`,workflowHasServices:(e)=>`wf-has-services:${n(e)}`,finalizerState:(e)=>`wf-finalizer-state:${n(e)}`,teardownOwed:(e)=>`wf-teardown-needed:${n(e)}`,teardownSucceeded:(e)=>`wf-teardown-succeeded:${n(e)}`,teardownDeadLetter:(e)=>`wf-teardown-deadletter:${n(e)}`,offload:(e,t)=>`offload:${n(e)}:${t}`,archive:(e,t)=>`archive:${n(e)}:${t}`,stateExecution:(e,t)=>`state:execution:${n(e)}:${n(t)}`,stateWorkflow:(e,t)=>`state:workflow-scope:${U}:${n(e)}:${n(t)}`,streamChunkPrefix:(e,t)=>`blob:${n(e)}:${t}:chunk:`,streamChunk:(e,t,r)=>`blob:${n(e)}:${t}:chunk:${String(r).padStart(10,"0")}`,streamTail:(e,t)=>`blob:${n(e)}:${t}:tail`,streamMetadata:(e,t)=>`blob:${n(e)}:${t}:meta`,budgetCharged:(e)=>`budget-charged:${e}`,toolEffect:(e,t,r)=>`tool-effect:${n(e)}:${t}:${r}`,workflowVisibilityStatus:(e,t)=>`wf-idx-status:${n(e)}:${n(t)}`,workflowVisibilityType:(e,t)=>`wf-idx-type:${n(e)}:${n(t)}`,workflowVisibilityCreated:(e,t)=>`wf-idx-created:${l(e)}:${n(t)}`,workflowVisibilityUpdated:(e,t)=>`wf-idx-updated:${l(e)}:${n(t)}`,workflowVisibilityDeadline:(e,t)=>`wf-idx-deadline:${l(e)}:${n(t)}`,workflowVisibilityManifest:(e)=>`wf-idx-manifest:${n(e)}`,workflowVisibilityMetaVersion:()=>"wf-idx-meta:version",workflowVisibilityMetaBuiltAt:()=>"wf-idx-meta:built-at",workflowVisibilityMetaCursor:()=>"wf-idx-meta:cursor"};var O=a,Y={workflow:(e)=>`wf:${n(e)}`,checkpoint:(e)=>`wf:${n(e)}:ckpt`,checkpointHistory:(e,t)=>`wf:${n(e)}:ckpt:${String(t).padStart(10,"0")}`,timelinePrefix:(e)=>`wf:${n(e)}:timeline:`,timeline:(e,t)=>`wf:${n(e)}:timeline:${String(t).padStart(10,"0")}`,schedule:(e)=>`schedule:${n(e)}`,scheduleTick:(e,t)=>`schedule-due:${String(e).padStart(16,"0")}:${n(t)}`,scheduleRun:(e)=>`schedule-run:${n(e)}`,scheduleRunLink:(e)=>`schedule-run-link:${n(e)}`,scheduleRunBySchedulePrefix:(e)=>`schedule-run-by-schedule:${n(e)}:`,scheduleRunBySchedule:(e,t)=>`schedule-run-by-schedule:${n(e)}:${n(t)}`,operation:(e,t,r)=>`op:${e}:${O(t)}:${r}`,operationInflight:(e)=>`op:inflight:${e}`,operationQueued:(e)=>`op:queued:${e}`,operationResolved:(e)=>`op:resolved:${e}`,bulkOperationAuditPrefix:()=>"audit:bulk:",bulkOperationAudit:(e,t,r)=>`audit:bulk:${O(e)}:${n(t)}:${n(r)}`,operationResolvedByTimePrefix:()=>"op:resolved-by-time:",operationResolvedByTime:(e,t)=>`op:resolved-by-time:${O(e)}:${n(t)}`,asyncActivity:(e,t)=>`async-act:v1:${n(e)}:${n(t)}`,asyncActivityResolution:(e,t)=>`async-act:v1:${n(e)}:${n(t)}:resolution`,activityReconciliationPrefix:(e)=>`actrec:v1:${n(e)}:`,activityReconciliation:(e,t,r)=>`actrec:v1:${n(e)}:${n(t)}:${r}`,eventPrefix:(e)=>`ev:${n(e)}:`,event:(e,t)=>`ev:${n(e)}:${String(t).padStart(10,"0")}`,eventHead:(e)=>`ev:${n(e)}:head`,eventWatermark:(e)=>`ev:${n(e)}:watermark`,fleetEventPrefix:()=>"fleet-event:",fleetEvent:(e)=>`fleet-event:${String(e).padStart(10,"0")}`,fleetEventTail:()=>"fleet-event-tail",fleetEventWatermark:()=>"fleet-event-watermark",fleetEventByWorkflowPrefix:(e)=>`fleet-event-by-workflow:${n(e)}:`,fleetEventByWorkflow:(e,t)=>`fleet-event-by-workflow:${n(e)}:${String(t).padStart(10,"0")}`},H={attribute:(e)=>`attr:${n(e)}`,attributeIndex:(e,t,r)=>`idx:${e}:${t}:${n(r)}`,tagIndex:(e,t)=>`tag:${n(e)}:${n(t)}`,updatePrefix:(e)=>`upd:${n(e)}:`,update:(e,t)=>`upd:${n(e)}:${t}`,updateResponse:(e)=>`upr:${e}`,updateIdempotency:(e,t)=>`upk:${n(e)}:${t}`,startIdempotency:(e)=>`start-idem:${n(e)}`,startIdempotencySignalId:(e)=>`start-idem:${e}`};var w=1e4;class F extends Error{code="StorageBatchOperationLimitExceededError";cap=w;count;target;constructor(e,t){super(`${e} count ${t} exceeds MAX_BATCH_OPERATIONS (${w}).`);this.name="StorageBatchOperationLimitExceededError",this.target=e,this.count=t}}function g(e,t){if(t>w)throw new F(e,t)}function z(e){return e.length>0?e.slice(0,-1)+String.fromCharCode(e.charCodeAt(e.length-1)+1):"ÿ"}function Xe(e,t={}){if(t.gt!==void 0&&e<=t.gt)return!1;if(t.gte!==void 0&&e<t.gte)return!1;if(t.lt!==void 0&&e>=t.lt)return!1;if(t.lte!==void 0&&e>t.lte)return!1;return!0}function je(e,t){if(e===null||t===null)return e===t;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}async function q(e,t){if(e.has)return e.has(t);return f(e,t)}function G(e,t,r){if(e.keys)return e.keys(t,r);return c(e,t,r)}async function M(e,t){if(e.count)return e.count(t);return m(e,t)}async function V(e,t){if(e.deletePrefix)return e.deletePrefix(t);return y(e,t)}async function X(e,t,r){if(g("conditionalBatch conditions",t.length),g("conditionalBatch operations",r.length),P(e,"conditionalBatch","storageConditionalBatch"),!e.conditionalBatch)throw Error("This storage backend reports conditionalBatch capability but does not implement the conditionalBatch() method.");return e.conditionalBatch(t,r)}var Je={...Y,...I,...N,...H,..._,...D,...A,...L,...k,...T,...W};function re(e){if(e===void 0)return;if(typeof e!=="number"||!Number.isInteger(e)||e<0)throw Error("deleteRange limit must be a finite non-negative integer");return e===0?0:e}function d(e){let t={},r=!1;for(let o of["gt","gte","lt","lte"]){let s=e[o];if(s===void 0)continue;if(typeof s!=="string")throw Error("deleteRange bounds must be strings");t[o]=s,r=!0}if(!r)throw Error("deleteRange requires at least one of gt/gte/lt/lte; use deletePrefix to delete a whole prefix");let i=re(e.limit);if(i!==void 0)t.limit=i;return t}async function j(e,t,r){let i=d(r);if(e.deleteRange)return e.deleteRange(t,i);return h(e,t,i)}function ie(e,t){let r={key:e,open:!1};if(t.gte!==void 0&&t.gte>r.key)r.key=t.gte,r.open=!1;if(t.gt!==void 0&&t.gt>=r.key)r.key=t.gt,r.open=!0;return r}function oe(e,t){let r={key:z(e),open:!0};if(t.lt!==void 0&&t.lt<=r.key)r.key=t.lt,r.open=!0;if(t.lte!==void 0&&t.lte<r.key)r.key=t.lte,r.open=!1;return r}function tt(e,t){let r=ie(e,t),i=oe(e,t);if(r.key>i.key||r.key===i.key&&(r.open||i.open))return null;return{lower:r,upper:i}}function E(e){return e.replaceAll(/:+$/g,"")}function ae(e,t){let r=E(e),i=E(t);if(r.length===0)return i;if(i.length===0)return r;return`${r}:${i}`}class R{#e;#n;constructor(e,t){this.#e=e,this.#n=E(t)}#t(e){if(this.#n.length===0)return e;return e.length===0?`${this.#n}:`:`${this.#n}:${e}`}#i(e){return e.map((t)=>{if(t.type==="put")return{type:"put",key:this.#t(t.key),value:t.value};return{type:"delete",key:this.#t(t.key)}})}#o(e){if(this.#n.length===0)return e;return e.slice(this.#n.length+1)}#a(e){let t={};if(e.limit!==void 0)t.limit=e.limit;if(e.gt!==void 0)t.gt=this.#t(e.gt);if(e.gte!==void 0)t.gte=this.#t(e.gte);if(e.lt!==void 0)t.lt=this.#t(e.lt);if(e.lte!==void 0)t.lte=this.#t(e.lte);return t}#r(e={}){let t=this.#a(e);if(e.reverse!==void 0)t.reverse=e.reverse;return t}#s(e){return this.#a(e)}capabilities(){return this.#e.capabilities()}scoped(e){return new R(this.#e,ae(this.#n,e))}async get(e){return this.#e.get(this.#t(e))}async put(e,t){await this.#e.put(this.#t(e),t)}async delete(e){await this.#e.delete(this.#t(e))}async*scan(e,t){for await(let[r,i]of this.#e.scan(this.#t(e),this.#r(t)))yield[this.#o(r),i]}async batch(e){g("batch operations",e.length),await this.#e.batch(this.#i(e))}async conditionalBatch(e,t){return X(this.#e,e.map((r)=>({key:this.#t(r.key),expectedValue:r.expectedValue})),this.#i(t))}async has(e){return q(this.#e,this.#t(e))}async deletePrefix(e){return V(this.#e,this.#t(e))}async deleteRange(e,t){let r=this.#s(d(t));return j(this.#e,this.#t(e),r)}async*keys(e,t){for await(let r of G(this.#e,this.#t(e),this.#r(t)))yield this.#o(r)}async count(e){return M(this.#e,this.#t(e))}[Symbol.dispose](){this.#e[Symbol.dispose]()}}function J(e,t){return new R(e,t)}var se=67108864;function Z(e){if(e.type==="put")return{type:"put",key:e.key,value:S(e.value)};return{type:"delete",key:e.key}}function le(e){return{key:e.key,expectedValue:e.expectedValue===null?null:S(e.expectedValue)}}function ge(e){if(!b(e)||typeof e.key!=="string"||typeof e.value!=="string")throw Error("HTTPStorage scan response contained an invalid NDJSON entry.");return{key:e.key,value:e.value}}function ce(e){if(!b(e)||typeof e.applied!=="boolean")throw Error('HTTPStorage conditional batch response must include a boolean "applied" field.');return e.applied}function p(e,t,r){if(r!==void 0)e.searchParams.set(t,String(r))}function pe(e){if(e.trim().length===0)return null;let t=ge(JSON.parse(e));return[t.key,B(t.value)]}class de{#e;#n;#t;constructor(e){this.#e=e.baseUrl instanceof URL?e.baseUrl:new URL(e.baseUrl),this.#n={...e.headers},this.#t=e.remoteConditionalBatch??!1}capabilities(){return{persistence:"remote",readAfterWrite:"eventual",scanConsistency:"best-effort",atomicBatch:!0,conditionalBatch:this.#t,boundedRangeDelete:!1}}#i(e){let t=this.#e.href.endsWith("/")?this.#e.href:`${this.#e.href}/`;return new URL(e.replace(/^\/+/,""),t)}#o(e){return this.#i(`/v1/storage/${encodeURIComponent(e)}`)}#a(e,t){let r=this.#i("/v1/storage");return r.searchParams.set("prefix",e),p(r,"limit",t.limit),p(r,"reverse",t.reverse),p(r,"gt",t.gt),p(r,"gte",t.gte),p(r,"lt",t.lt),p(r,"lte",t.lte),r}async#r(e,t={},r=[]){let i=new Headers(this.#n);for(let[s,u]of new Headers(t.headers).entries())i.set(s,u);let o=await fetch(e,{...t,headers:i});if(!o.ok&&!r.includes(o.status))throw Error(`HTTPStorage request failed: ${t.method??"GET"} ${e.pathname} returned ${String(o.status)}.`);return o}async get(e){let t=await this.#r(this.#o(e),{method:"GET"},[404]);if(t.status===404)return null;return new Uint8Array(await t.arrayBuffer())}async put(e,t){await this.#r(this.#o(e),{method:"PUT",headers:{"content-type":"application/octet-stream"},body:new Blob([new Uint8Array(t)])})}async delete(e){await this.#r(this.#o(e),{method:"DELETE"})}async*scan(e,t={}){let r=await this.#r(this.#a(e,t),{method:"GET",headers:{accept:"application/x-ndjson"}});for await(let i of v(r,{maximumBytes:se,sizeLimitError:()=>Error("HTTPStorage scan response exceeded the maximum allowed size.")})){let o=pe(i);if(o!==null)yield o}}async batch(e){g("batch operations",e.length),await this.#r(this.#i("/v1/storage/-/batch"),{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({operations:e.map(Z)})})}async conditionalBatch(e,t){g("conditionalBatch conditions",e.length),g("conditionalBatch operations",t.length);let r=await this.#r(this.#i("/v1/storage/-/conditional-batch"),{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({conditions:e.map(le),operations:t.map(Z)})});return ce(await r.json())}has(e){return f(this,e)}async*keys(e,t){yield*c(this,e,t)}count(e){return m(this,e)}deletePrefix(e){return y(this,e)}deleteRange(e,t){return h(this,e,d(t))}scoped(e){return J(this,e)}[Symbol.dispose](){}}export{de as HTTPStorage};
|
package/dist/indexeddb.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
async function I(e,t){return await e.get(t)!==null}async function*C(e,t,r){for await(let[i]of e.scan(t,r))yield i}async function A(e,t){let r=0;for await(let i of C(e,t))r++;return r}async function E(e,t){let r=[];for await(let i of C(e,t))r.push({type:"delete",key:i});if(r.length===0)return 0;return await e.batch(r),r.length}async function T(e,t,r){let i=[];for await(let o of C(e,t,r))i.push({type:"delete",key:o});if(i.length===0)return 0;return await e.batch(i),i.length}function K(e,t,r){if(!e.capabilities()[t])throw Error(`Feature "${r}" requires storage capability "${t}", but this storage backend does not provide it.`)}function n(e){return encodeURIComponent(e)}function y(e){return String(e).padStart(16,"0")}var _={catalogEntry:(e,t)=>`catalog-entry:${n(e)}:${n(t)}`,catalogEntryPrefix:(e)=>`catalog-entry:${n(e)}:`,catalogActive:(e)=>`catalog-active:${n(e)}`,catalogTombstone:(e,t)=>`catalog-tombstone:${n(e)}:${n(t)}`,catalogTombstonePrefix:()=>"catalog-tombstone:"};var L="default";var z={applicationMailbox:(e,t)=>`appmbx:v1:${n(e)}:${n(t)}`,applicationMailboxSinkProbe:(e,t,r)=>`appprobe:v1:${n(e)}:${n(t)}:${n(r)}`,applicationCommandPrefix:(e,t)=>`appcmd:v1:${n(e)}:${n(t)}:`,applicationCommand:(e,t,r)=>`appcmd:v1:${n(e)}:${n(t)}:${n(r)}`,applicationCommandReadyPrefix:(e,t)=>`appready:v1:${n(e)}:${n(t)}:`,applicationCommandReady:(e,t,r)=>`appready:v1:${n(e)}:${n(t)}:${y(r)}`,applicationCommandIdempotency:(e,t,r)=>`appidem:v1:${n(e)}:${n(t)}:${n(r)}`,applicationCommandBySequencePrefix:(e,t)=>`appseq:v1:${n(e)}:${n(t)}:`,applicationCommandBySequence:(e,t,r)=>`appseq:v1:${n(e)}:${n(t)}:${y(r)}`,applicationCommandTerminalPrefix:(e,t)=>`appterm:v1:${n(e)}:${n(t)}:`,applicationCommandTerminal:(e,t,r,i)=>`appterm:v1:${n(e)}:${n(t)}:${y(r)}:${n(i)}`};var U={applicationOutbox:(e,t)=>`appobx:v1:${n(e)}:${n(t)}`,applicationOutboxSinkProbe:(e,t,r)=>`appprobe:v1:outbox:${n(e)}:${n(t)}:${n(r)}`,applicationDeliveryPrefix:(e,t)=>`appdlv:v1:${n(e)}:${n(t)}:`,applicationDelivery:(e,t,r)=>`appdlv:v1:${n(e)}:${n(t)}:${n(r)}`,applicationDeliveryDuePrefix:(e,t)=>`appdue:v1:${n(e)}:${n(t)}:`,applicationDeliveryDue:(e,t,r,i)=>`appdue:v1:${n(e)}:${n(t)}:${y(r)}:${n(i)}`,applicationDeliveryIdempotency:(e,t,r)=>`appdidem:v1:${n(e)}:${n(t)}:${n(r)}`,applicationDeliveryBySequencePrefix:(e,t)=>`appdseq:v1:${n(e)}:${n(t)}:`,applicationDeliveryBySequence:(e,t,r)=>`appdseq:v1:${n(e)}:${n(t)}:${y(r)}`,applicationDeliveryTerminalPrefix:(e,t)=>`appdterm:v1:${n(e)}:${n(t)}:`,applicationDeliveryTerminal:(e,t,r,i)=>`appdterm:v1:${n(e)}:${n(t)}:${y(r)}:${n(i)}`};var q={workflowOwnerEpoch:(e)=>`wf-owner-epoch:${n(e)}`,workflowOwnerHolder:(e)=>`wf-owner-holder:${n(e)}`,ownershipModeMarker:()=>"ownership-mode-marker"};var O=1e4;class M extends Error{code="StorageBatchOperationLimitExceededError";cap=O;count;target;constructor(e,t){super(`${e} count ${t} exceeds MAX_BATCH_OPERATIONS (${O}).`);this.name="StorageBatchOperationLimitExceededError",this.target=e,this.count=t}}function h(e,t){if(t>O)throw new M(e,t)}function w(e){return e.length>0?e.slice(0,-1)+String.fromCharCode(e.charCodeAt(e.length-1)+1):"ÿ"}function W(e,t={}){if(t.gt!==void 0&&e<=t.gt)return!1;if(t.gte!==void 0&&e<t.gte)return!1;if(t.lt!==void 0&&e>=t.lt)return!1;if(t.lte!==void 0&&e>t.lte)return!1;return!0}function N(e,t){if(e===null||t===null)return e===t;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}async function j(e,t){if(e.has)return e.has(t);return I(e,t)}function H(e,t,r){if(e.keys)return e.keys(t,r);return C(e,t,r)}async function F(e,t){if(e.count)return e.count(t);return A(e,t)}async function Y(e,t){if(e.deletePrefix)return e.deletePrefix(t);return E(e,t)}async function X(e,t,r){if(h("conditionalBatch conditions",t.length),h("conditionalBatch operations",r.length),K(e,"conditionalBatch","storageConditionalBatch"),!e.conditionalBatch)throw Error("This storage backend reports conditionalBatch capability but does not implement the conditionalBatch() method.");return e.conditionalBatch(t,r)}var f=y,te="0",ne="1",V=(e,t,r,i)=>`sig:${n(e)}:${n(t)}:${i}:${n(r)}`,ke={workflow:(e)=>`wf:${n(e)}`,checkpoint:(e)=>`wf:${n(e)}:ckpt`,checkpointHistory:(e,t)=>`wf:${n(e)}:ckpt:${String(t).padStart(10,"0")}`,timelinePrefix:(e)=>`wf:${n(e)}:timeline:`,timeline:(e,t)=>`wf:${n(e)}:timeline:${String(t).padStart(10,"0")}`,schedule:(e)=>`schedule:${n(e)}`,scheduleTick:(e,t)=>`schedule-due:${String(e).padStart(16,"0")}:${n(t)}`,scheduleRun:(e)=>`schedule-run:${n(e)}`,scheduleRunLink:(e)=>`schedule-run-link:${n(e)}`,scheduleRunBySchedulePrefix:(e)=>`schedule-run-by-schedule:${n(e)}:`,scheduleRunBySchedule:(e,t)=>`schedule-run-by-schedule:${n(e)}:${n(t)}`,operation:(e,t,r)=>`op:${e}:${f(t)}:${r}`,operationInflight:(e)=>`op:inflight:${e}`,operationQueued:(e)=>`op:queued:${e}`,operationResolved:(e)=>`op:resolved:${e}`,bulkOperationAuditPrefix:()=>"audit:bulk:",bulkOperationAudit:(e,t,r)=>`audit:bulk:${f(e)}:${n(t)}:${n(r)}`,operationResolvedByTimePrefix:()=>"op:resolved-by-time:",operationResolvedByTime:(e,t)=>`op:resolved-by-time:${f(e)}:${n(t)}`,asyncActivity:(e,t)=>`async-act:v1:${n(e)}:${n(t)}`,asyncActivityResolution:(e,t)=>`async-act:v1:${n(e)}:${n(t)}:resolution`,activityReconciliationPrefix:(e)=>`actrec:v1:${n(e)}:`,activityReconciliation:(e,t,r)=>`actrec:v1:${n(e)}:${n(t)}:${r}`,eventPrefix:(e)=>`ev:${n(e)}:`,event:(e,t)=>`ev:${n(e)}:${String(t).padStart(10,"0")}`,eventHead:(e)=>`ev:${n(e)}:head`,eventWatermark:(e)=>`ev:${n(e)}:watermark`,fleetEventPrefix:()=>"fleet-event:",fleetEvent:(e)=>`fleet-event:${String(e).padStart(10,"0")}`,fleetEventTail:()=>"fleet-event-tail",fleetEventWatermark:()=>"fleet-event-watermark",fleetEventByWorkflowPrefix:(e)=>`fleet-event-by-workflow:${n(e)}:`,fleetEventByWorkflow:(e,t)=>`fleet-event-by-workflow:${n(e)}:${String(t).padStart(10,"0")}`,signal:(e,t,r)=>V(e,t,r,ne),startSignal:(e,t,r)=>V(e,t,r,te),signalSequence:(e)=>`sigseq:v1:${n(e)}`,signalAcceptedResponsePrefix:(e)=>`sigres:v1:${n(e)}:`,signalAcceptedResponse:(e,t,r)=>`sigres:v1:${n(e)}:${n(t)}:${n(r)}`,deadline:(e,t)=>`wf-deadline:${f(e)}:${n(t)}`,terminalCleanup:(e,t)=>`wf-cleanup:${f(e)}:${n(t)}`,teardownTimer:(e,t)=>`wf-teardown:${f(e)}:${n(t)}`,delayedStart:(e,t)=>`wf-delayed:${f(e)}:${n(t)}`,terminalWorkflowPrefix:()=>"wf-terminal:",terminalWorkflow:(e,t)=>`wf-terminal:${f(e)}:${n(t)}`,attribute:(e)=>`attr:${n(e)}`,attributeIndex:(e,t,r)=>`idx:${e}:${t}:${n(r)}`,tagIndex:(e,t)=>`tag:${n(e)}:${n(t)}`,updatePrefix:(e)=>`upd:${n(e)}:`,update:(e,t)=>`upd:${n(e)}:${t}`,updateResponse:(e)=>`upr:${e}`,updateIdempotency:(e,t)=>`upk:${n(e)}:${t}`,startIdempotency:(e)=>`start-idem:${n(e)}`,startIdempotencySignalId:(e)=>`start-idem:${e}`,livenessPrefix:()=>"liveness:",liveness:(e)=>`liveness:${n(e)}`,leasePrefix:()=>"lease:",leaseEpoch:()=>"lease:epoch",leaseHolder:()=>"lease:holder",...z,...U,...q,..._,budget:(e,t,r)=>`budget:${e}:${t}:${r}`,review:(e,t)=>`review:${n(e)}:${t}`,workflowHeaders:(e)=>`wf-headers:${n(e)}`,childCancellationPrefix:(e)=>`child-cancel:${n(e)}:`,childCancellation:(e,t)=>`child-cancel:${n(e)}:${n(t)}`,childWorkflowByParentPrefix:(e,t)=>`child-by-parent:${n(e)}:${t===void 0?"":`${n(t)}:`}`,childWorkflowByParent:(e,t,r)=>`child-by-parent:${n(e)}:${t===void 0?"":`${n(t)}:`}${n(r)}`,terminalCleanupNeeded:(e)=>`wf-cleanup-needed:${n(e)}`,workflowConcurrency:(e,t)=>`wf-concurrency:${n(e)}:${n(t)}`,workflowConcurrencyHolder:(e)=>`wf-concurrency-holder:${n(e)}`,workflowHasServices:(e)=>`wf-has-services:${n(e)}`,finalizerState:(e)=>`wf-finalizer-state:${n(e)}`,teardownOwed:(e)=>`wf-teardown-needed:${n(e)}`,teardownSucceeded:(e)=>`wf-teardown-succeeded:${n(e)}`,teardownDeadLetter:(e)=>`wf-teardown-deadletter:${n(e)}`,offload:(e,t)=>`offload:${n(e)}:${t}`,archive:(e,t)=>`archive:${n(e)}:${t}`,stateExecution:(e,t)=>`state:execution:${n(e)}:${n(t)}`,stateWorkflow:(e,t)=>`state:workflow-scope:${L}:${n(e)}:${n(t)}`,streamChunkPrefix:(e,t)=>`blob:${n(e)}:${t}:chunk:`,streamChunk:(e,t,r)=>`blob:${n(e)}:${t}:chunk:${String(r).padStart(10,"0")}`,streamTail:(e,t)=>`blob:${n(e)}:${t}:tail`,streamMetadata:(e,t)=>`blob:${n(e)}:${t}:meta`,budgetCharged:(e)=>`budget-charged:${e}`,toolEffect:(e,t,r)=>`tool-effect:${n(e)}:${t}:${r}`,workflowVisibilityStatus:(e,t)=>`wf-idx-status:${n(e)}:${n(t)}`,workflowVisibilityType:(e,t)=>`wf-idx-type:${n(e)}:${n(t)}`,workflowVisibilityCreated:(e,t)=>`wf-idx-created:${f(e)}:${n(t)}`,workflowVisibilityUpdated:(e,t)=>`wf-idx-updated:${f(e)}:${n(t)}`,workflowVisibilityDeadline:(e,t)=>`wf-idx-deadline:${f(e)}:${n(t)}`,workflowVisibilityManifest:(e)=>`wf-idx-manifest:${n(e)}`,workflowVisibilityMetaVersion:()=>"wf-idx-meta:version",workflowVisibilityMetaBuiltAt:()=>"wf-idx-meta:built-at",workflowVisibilityMetaCursor:()=>"wf-idx-meta:cursor"};function re(e){if(e===void 0)return;if(typeof e!=="number"||!Number.isInteger(e)||e<0)throw Error("deleteRange limit must be a finite non-negative integer");return e===0?0:e}function D(e){let t={},r=!1;for(let o of["gt","gte","lt","lte"]){let a=e[o];if(a===void 0)continue;if(typeof a!=="string")throw Error("deleteRange bounds must be strings");t[o]=a,r=!0}if(!r)throw Error("deleteRange requires at least one of gt/gte/lt/lte; use deletePrefix to delete a whole prefix");let i=re(e.limit);if(i!==void 0)t.limit=i;return t}async function G(e,t,r){let i=D(r);if(e.deleteRange)return e.deleteRange(t,i);return T(e,t,i)}function ie(e,t){let r={key:e,open:!1};if(t.gte!==void 0&&t.gte>r.key)r.key=t.gte,r.open=!1;if(t.gt!==void 0&&t.gt>=r.key)r.key=t.gt,r.open=!0;return r}function oe(e,t){let r={key:w(e),open:!0};if(t.lt!==void 0&&t.lt<=r.key)r.key=t.lt,r.open=!0;if(t.lte!==void 0&&t.lte<r.key)r.key=t.lte,r.open=!1;return r}function Q(e,t){let r=ie(e,t),i=oe(e,t);if(r.key>i.key||r.key===i.key&&(r.open||i.open))return null;return{lower:r,upper:i}}function P(e){return e.replaceAll(/:+$/g,"")}function ae(e,t){let r=P(e),i=P(t);if(r.length===0)return i;if(i.length===0)return r;return`${r}:${i}`}class k{#t;#n;constructor(e,t){this.#t=e,this.#n=P(t)}#e(e){if(this.#n.length===0)return e;return e.length===0?`${this.#n}:`:`${this.#n}:${e}`}#r(e){return e.map((t)=>{if(t.type==="put")return{type:"put",key:this.#e(t.key),value:t.value};return{type:"delete",key:this.#e(t.key)}})}#i(e){if(this.#n.length===0)return e;return e.slice(this.#n.length+1)}#o(e){let t={};if(e.limit!==void 0)t.limit=e.limit;if(e.gt!==void 0)t.gt=this.#e(e.gt);if(e.gte!==void 0)t.gte=this.#e(e.gte);if(e.lt!==void 0)t.lt=this.#e(e.lt);if(e.lte!==void 0)t.lte=this.#e(e.lte);return t}#a(e={}){let t=this.#o(e);if(e.reverse!==void 0)t.reverse=e.reverse;return t}#s(e){return this.#o(e)}capabilities(){return this.#t.capabilities()}scoped(e){return new k(this.#t,ae(this.#n,e))}async get(e){return this.#t.get(this.#e(e))}async put(e,t){await this.#t.put(this.#e(e),t)}async delete(e){await this.#t.delete(this.#e(e))}async*scan(e,t){for await(let[r,i]of this.#t.scan(this.#e(e),this.#a(t)))yield[this.#i(r),i]}async batch(e){h("batch operations",e.length),await this.#t.batch(this.#r(e))}async conditionalBatch(e,t){return X(this.#t,e.map((r)=>({key:this.#e(r.key),expectedValue:r.expectedValue})),this.#r(t))}async has(e){return j(this.#t,this.#e(e))}async deletePrefix(e){return Y(this.#t,this.#e(e))}async deleteRange(e,t){let r=this.#s(D(t));return G(this.#t,this.#e(e),r)}async*keys(e,t){for await(let r of H(this.#t,this.#e(e),this.#a(t)))yield this.#i(r)}async count(e){return F(this.#t,this.#e(e))}[Symbol.dispose](){this.#t[Symbol.dispose]()}}function J(e,t){return new k(e,t)}var l="kv";function se(e=globalThis){let{indexedDB:t,IDBKeyRange:r}=e;if(t===void 0||r===void 0)throw Error("IndexedDBStorage requires both indexedDB and IDBKeyRange runtime globals.");return{indexedDB:t,IDBKeyRange:r}}function x(e){return new Promise((t,r)=>{e.onsuccess=()=>t(e.result),e.onerror=()=>r(e.error)})}function le(e,t){let r=null,i=null,o=null,a=(s,c)=>{let u=s??Error(c);if(i){let d=i;r=null,i=null,d(u);return}o=u};return e.onsuccess=()=>{if(!r)return;let s=r;r=null,i=null,s(e.result)},e.onerror=()=>{a(e.error,"IndexedDB cursor request failed.")},t.onerror=()=>{a(t.error,"IndexedDB transaction failed.")},t.onabort=()=>{a(t.error,"IndexedDB transaction aborted.")},()=>new Promise((s,c)=>{if(o){let u=o;o=null,c(u);return}if(r=s,i=c,e.readyState==="done"){let u=r;r=null,i=null,u?.(e.result)}})}async function*Z(e,t,r,i,o,a){let{limit:s,reverse:c}=i,u=w(r),d=t.bound(r,u,!1,!0),b=c?"prev":"next",p=e.transaction(l,"readonly"),g=p.objectStore(l),m=o(g,d,b),S=le(m,p),v=0,R=!1;try{let B=await S();while(B){if(s!==void 0&&v>=s)break;let ee=B.key;if(W(ee,i))yield a(B),v++;B.continue(),B=await S()}R=!0}finally{if(!R)try{p.abort()}catch{}}}class ce{#t;#n=null;#e;#r;constructor(e="weft",t=se()){this.#t=e,this.#r=t,this.#e=this.#i()}capabilities(){return{persistence:"local",readAfterWrite:"linearizable",scanConsistency:"best-effort",atomicBatch:!0,conditionalBatch:!0,boundedRangeDelete:!0}}#i(){let e=this.#r.indexedDB.open(this.#t,1);return e.onupgradeneeded=()=>{let t=e.result;if(!t.objectStoreNames.contains(l))t.createObjectStore(l)},x(e).then((t)=>(this.#n=t,t))}async get(e){let i=(await this.#e).transaction(l,"readonly").objectStore(l),o=await x(i.get(e));return o===void 0?null:new Uint8Array(o)}async put(e,t){let o=(await this.#e).transaction(l,"readwrite").objectStore(l);await x(o.put(t,e))}async delete(e){let i=(await this.#e).transaction(l,"readwrite").objectStore(l);await x(i.delete(e))}async has(e){let i=(await this.#e).transaction(l,"readonly").objectStore(l);return await x(i.count(e))>0}async deletePrefix(e){let t=await this.#e,r=w(e),i=this.#r.IDBKeyRange.bound(e,r,!1,!0);return new Promise((o,a)=>{let s=t.transaction(l,"readwrite"),c=s.objectStore(l),u=0,d=c.count(i);d.onsuccess=()=>{u=d.result,c.delete(i)},s.oncomplete=()=>o(u),s.onerror=()=>a(s.error)})}async deleteRange(e,t){let r=D(t),i=Q(e,r);if(i===null)return 0;let o=this.#r.IDBKeyRange.bound(i.lower.key,i.upper.key,i.lower.open,i.upper.open),a=await this.#e,{limit:s}=r;return new Promise((c,u)=>{let d=a.transaction(l,"readwrite"),b=d.objectStore(l),p=0;if(s===void 0){let g=b.count(o);g.onsuccess=()=>{p=g.result,b.delete(o)}}else{let g=b.openCursor(o,"next");g.onsuccess=()=>{let m=g.result;if(m===null||p>=s)return;if(m.delete(),p++,p<s)m.continue()}}d.oncomplete=()=>c(p),d.onerror=()=>u(d.error)})}async*scan(e,t={}){let r=await this.#e;yield*Z(r,this.#r.IDBKeyRange,e,t,(i,o,a)=>i.openCursor(o,a),(i)=>[i.key,new Uint8Array(i.value)])}async batch(e){if(h("batch operations",e.length),e.length===0)return;let t=await this.#e;return new Promise((r,i)=>{let o=t.transaction(l,"readwrite"),a=o.objectStore(l);for(let s of e)if(s.type==="put")a.put(s.value,s.key);else a.delete(s.key);o.oncomplete=()=>r(),o.onerror=()=>i(o.error)})}async conditionalBatch(e,t){h("conditionalBatch conditions",e.length),h("conditionalBatch operations",t.length);let r=await this.#e;return new Promise((i,o)=>{let a=r.transaction(l,"readwrite"),s=a.objectStore(l),c=!1,u=!1,d=(g,m)=>{if(c)return;c=!0,o(g??Error(m))};a.oncomplete=()=>{if(c)return;c=!0,i(!0)},a.onerror=()=>{d(a.error,"IndexedDB conditionalBatch transaction failed.")},a.onabort=()=>{if(c)return;if(c=!0,u){i(!1);return}o(a.error??Error("IndexedDB conditionalBatch transaction aborted."))};let b=()=>{for(let g of t)if(g.type==="put")s.put(g.value,g.key);else s.delete(g.key)},p=(g)=>{if(g>=e.length){b();return}let m=e[g],S=s.get(m.key);S.onsuccess=()=>{let v=S.result,R=v===void 0?null:new Uint8Array(v);if(!N(R,m.expectedValue)){u=!0,a.abort();return}p(g+1)},S.onerror=()=>{d(S.error,"IndexedDB conditionalBatch condition check failed.")}};p(0)})}async*keys(e,t={}){let r=await this.#e;yield*Z(r,this.#r.IDBKeyRange,e,t,(i,o,a)=>i.openKeyCursor(o,a),(i)=>i.key)}async count(e){let t=await this.#e,r=w(e),o=t.transaction(l,"readonly").objectStore(l);return x(o.count(this.#r.IDBKeyRange.bound(e,r,!1,!0)))}scoped(e){return J(this,e)}[Symbol.dispose](){if(this.#n)this.#n.close(),this.#n=null}}export{ce as IndexedDBStorage};
|
|
1
|
+
async function I(e,t){return await e.get(t)!==null}async function*R(e,t,r){for await(let[i]of e.scan(t,r))yield i}async function K(e,t){let r=0;for await(let i of R(e,t))r++;return r}async function _(e,t){let r=[];for await(let i of R(e,t))r.push({type:"delete",key:i});if(r.length===0)return 0;return await e.batch(r),r.length}async function A(e,t,r){let i=[];for await(let o of R(e,t,r))i.push({type:"delete",key:o});if(i.length===0)return 0;return await e.batch(i),i.length}function T(e,t,r){if(!e.capabilities()[t])throw Error(`Feature "${r}" requires storage capability "${t}", but this storage backend does not provide it.`)}function n(e){return encodeURIComponent(e)}function f(e){return String(e).padStart(16,"0")}var L={catalogEntry:(e,t)=>`catalog-entry:${n(e)}:${n(t)}`,catalogEntryPrefix:(e)=>`catalog-entry:${n(e)}:`,catalogActive:(e)=>`catalog-active:${n(e)}`,catalogTombstone:(e,t)=>`catalog-tombstone:${n(e)}:${n(t)}`,catalogTombstonePrefix:()=>"catalog-tombstone:"};var W={workflowGeneration:(e)=>`wf-gen:${n(e)}`};var Y={livenessPrefix:()=>"liveness:",liveness:(e)=>`liveness:${n(e)}`,leasePrefix:()=>"lease:",leaseEpoch:()=>"lease:epoch",leaseHolder:()=>"lease:holder"};var N={applicationMailbox:(e,t)=>`appmbx:v1:${n(e)}:${n(t)}`,applicationMailboxSinkProbe:(e,t,r)=>`appprobe:v1:${n(e)}:${n(t)}:${n(r)}`,applicationCommandPrefix:(e,t)=>`appcmd:v1:${n(e)}:${n(t)}:`,applicationCommand:(e,t,r)=>`appcmd:v1:${n(e)}:${n(t)}:${n(r)}`,applicationCommandReadyPrefix:(e,t)=>`appready:v1:${n(e)}:${n(t)}:`,applicationCommandReady:(e,t,r)=>`appready:v1:${n(e)}:${n(t)}:${f(r)}`,applicationCommandIdempotency:(e,t,r)=>`appidem:v1:${n(e)}:${n(t)}:${n(r)}`,applicationCommandBySequencePrefix:(e,t)=>`appseq:v1:${n(e)}:${n(t)}:`,applicationCommandBySequence:(e,t,r)=>`appseq:v1:${n(e)}:${n(t)}:${f(r)}`,applicationCommandTerminalPrefix:(e,t)=>`appterm:v1:${n(e)}:${n(t)}:`,applicationCommandTerminal:(e,t,r,i)=>`appterm:v1:${n(e)}:${n(t)}:${f(r)}:${n(i)}`};var F={applicationOutbox:(e,t)=>`appobx:v1:${n(e)}:${n(t)}`,applicationOutboxSinkProbe:(e,t,r)=>`appprobe:v1:outbox:${n(e)}:${n(t)}:${n(r)}`,applicationDeliveryPrefix:(e,t)=>`appdlv:v1:${n(e)}:${n(t)}:`,applicationDelivery:(e,t,r)=>`appdlv:v1:${n(e)}:${n(t)}:${n(r)}`,applicationDeliveryDuePrefix:(e,t)=>`appdue:v1:${n(e)}:${n(t)}:`,applicationDeliveryDue:(e,t,r,i)=>`appdue:v1:${n(e)}:${n(t)}:${f(r)}:${n(i)}`,applicationDeliveryIdempotency:(e,t,r)=>`appdidem:v1:${n(e)}:${n(t)}:${n(r)}`,applicationDeliveryBySequencePrefix:(e,t)=>`appdseq:v1:${n(e)}:${n(t)}:`,applicationDeliveryBySequence:(e,t,r)=>`appdseq:v1:${n(e)}:${n(t)}:${f(r)}`,applicationDeliveryTerminalPrefix:(e,t)=>`appdterm:v1:${n(e)}:${n(t)}:`,applicationDeliveryTerminal:(e,t,r,i)=>`appdterm:v1:${n(e)}:${n(t)}:${f(r)}:${n(i)}`};var U={workflowOwnerEpoch:(e)=>`wf-owner-epoch:${n(e)}`,workflowOwnerHolder:(e)=>`wf-owner-holder:${n(e)}`,ownershipModeMarker:()=>"ownership-mode-marker"};var ce="0",ge="1",z=(e,t,r,i)=>`sig:${n(e)}:${n(t)}:${i}:${n(r)}`,q={signal:(e,t,r)=>z(e,t,r,ge),startSignal:(e,t,r)=>z(e,t,r,ce),signalSequence:(e)=>`sigseq:v1:${n(e)}`,signalAcceptedResponsePrefix:(e)=>`sigres:v1:${n(e)}:`,signalAcceptedResponse:(e,t,r)=>`sigres:v1:${n(e)}:${n(t)}:${n(r)}`};var M="default";var y=f,V={deadline:(e,t)=>`wf-deadline:${y(e)}:${n(t)}`,terminalCleanup:(e,t)=>`wf-cleanup:${y(e)}:${n(t)}`,teardownTimer:(e,t)=>`wf-teardown:${y(e)}:${n(t)}`,delayedStart:(e,t)=>`wf-delayed:${y(e)}:${n(t)}`,terminalWorkflowPrefix:()=>"wf-terminal:",terminalWorkflow:(e,t)=>`wf-terminal:${y(e)}:${n(t)}`},j={budget:(e,t,r)=>`budget:${e}:${t}:${r}`,review:(e,t)=>`review:${n(e)}:${t}`,workflowHeaders:(e)=>`wf-headers:${n(e)}`,childCancellationPrefix:(e)=>`child-cancel:${n(e)}:`,childCancellation:(e,t)=>`child-cancel:${n(e)}:${n(t)}`,childWorkflowByParentPrefix:(e,t)=>`child-by-parent:${n(e)}:${t===void 0?"":`${n(t)}:`}`,childWorkflowByParent:(e,t,r)=>`child-by-parent:${n(e)}:${t===void 0?"":`${n(t)}:`}${n(r)}`,terminalCleanupNeeded:(e)=>`wf-cleanup-needed:${n(e)}`,workflowConcurrency:(e,t)=>`wf-concurrency:${n(e)}:${n(t)}`,workflowConcurrencyHolder:(e)=>`wf-concurrency-holder:${n(e)}`,workflowHasServices:(e)=>`wf-has-services:${n(e)}`,finalizerState:(e)=>`wf-finalizer-state:${n(e)}`,teardownOwed:(e)=>`wf-teardown-needed:${n(e)}`,teardownSucceeded:(e)=>`wf-teardown-succeeded:${n(e)}`,teardownDeadLetter:(e)=>`wf-teardown-deadletter:${n(e)}`,offload:(e,t)=>`offload:${n(e)}:${t}`,archive:(e,t)=>`archive:${n(e)}:${t}`,stateExecution:(e,t)=>`state:execution:${n(e)}:${n(t)}`,stateWorkflow:(e,t)=>`state:workflow-scope:${M}:${n(e)}:${n(t)}`,streamChunkPrefix:(e,t)=>`blob:${n(e)}:${t}:chunk:`,streamChunk:(e,t,r)=>`blob:${n(e)}:${t}:chunk:${String(r).padStart(10,"0")}`,streamTail:(e,t)=>`blob:${n(e)}:${t}:tail`,streamMetadata:(e,t)=>`blob:${n(e)}:${t}:meta`,budgetCharged:(e)=>`budget-charged:${e}`,toolEffect:(e,t,r)=>`tool-effect:${n(e)}:${t}:${r}`,workflowVisibilityStatus:(e,t)=>`wf-idx-status:${n(e)}:${n(t)}`,workflowVisibilityType:(e,t)=>`wf-idx-type:${n(e)}:${n(t)}`,workflowVisibilityCreated:(e,t)=>`wf-idx-created:${y(e)}:${n(t)}`,workflowVisibilityUpdated:(e,t)=>`wf-idx-updated:${y(e)}:${n(t)}`,workflowVisibilityDeadline:(e,t)=>`wf-idx-deadline:${y(e)}:${n(t)}`,workflowVisibilityManifest:(e)=>`wf-idx-manifest:${n(e)}`,workflowVisibilityMetaVersion:()=>"wf-idx-meta:version",workflowVisibilityMetaBuiltAt:()=>"wf-idx-meta:built-at",workflowVisibilityMetaCursor:()=>"wf-idx-meta:cursor"};var B=f,H={workflow:(e)=>`wf:${n(e)}`,checkpoint:(e)=>`wf:${n(e)}:ckpt`,checkpointHistory:(e,t)=>`wf:${n(e)}:ckpt:${String(t).padStart(10,"0")}`,timelinePrefix:(e)=>`wf:${n(e)}:timeline:`,timeline:(e,t)=>`wf:${n(e)}:timeline:${String(t).padStart(10,"0")}`,schedule:(e)=>`schedule:${n(e)}`,scheduleTick:(e,t)=>`schedule-due:${String(e).padStart(16,"0")}:${n(t)}`,scheduleRun:(e)=>`schedule-run:${n(e)}`,scheduleRunLink:(e)=>`schedule-run-link:${n(e)}`,scheduleRunBySchedulePrefix:(e)=>`schedule-run-by-schedule:${n(e)}:`,scheduleRunBySchedule:(e,t)=>`schedule-run-by-schedule:${n(e)}:${n(t)}`,operation:(e,t,r)=>`op:${e}:${B(t)}:${r}`,operationInflight:(e)=>`op:inflight:${e}`,operationQueued:(e)=>`op:queued:${e}`,operationResolved:(e)=>`op:resolved:${e}`,bulkOperationAuditPrefix:()=>"audit:bulk:",bulkOperationAudit:(e,t,r)=>`audit:bulk:${B(e)}:${n(t)}:${n(r)}`,operationResolvedByTimePrefix:()=>"op:resolved-by-time:",operationResolvedByTime:(e,t)=>`op:resolved-by-time:${B(e)}:${n(t)}`,asyncActivity:(e,t)=>`async-act:v1:${n(e)}:${n(t)}`,asyncActivityResolution:(e,t)=>`async-act:v1:${n(e)}:${n(t)}:resolution`,activityReconciliationPrefix:(e)=>`actrec:v1:${n(e)}:`,activityReconciliation:(e,t,r)=>`actrec:v1:${n(e)}:${n(t)}:${r}`,eventPrefix:(e)=>`ev:${n(e)}:`,event:(e,t)=>`ev:${n(e)}:${String(t).padStart(10,"0")}`,eventHead:(e)=>`ev:${n(e)}:head`,eventWatermark:(e)=>`ev:${n(e)}:watermark`,fleetEventPrefix:()=>"fleet-event:",fleetEvent:(e)=>`fleet-event:${String(e).padStart(10,"0")}`,fleetEventTail:()=>"fleet-event-tail",fleetEventWatermark:()=>"fleet-event-watermark",fleetEventByWorkflowPrefix:(e)=>`fleet-event-by-workflow:${n(e)}:`,fleetEventByWorkflow:(e,t)=>`fleet-event-by-workflow:${n(e)}:${String(t).padStart(10,"0")}`},X={attribute:(e)=>`attr:${n(e)}`,attributeIndex:(e,t,r)=>`idx:${e}:${t}:${n(r)}`,tagIndex:(e,t)=>`tag:${n(e)}:${n(t)}`,updatePrefix:(e)=>`upd:${n(e)}:`,update:(e,t)=>`upd:${n(e)}:${t}`,updateResponse:(e)=>`upr:${e}`,updateIdempotency:(e,t)=>`upk:${n(e)}:${t}`,startIdempotency:(e)=>`start-idem:${n(e)}`,startIdempotencySignalId:(e)=>`start-idem:${e}`};var v=1e4;class G extends Error{code="StorageBatchOperationLimitExceededError";cap=v;count;target;constructor(e,t){super(`${e} count ${t} exceeds MAX_BATCH_OPERATIONS (${v}).`);this.name="StorageBatchOperationLimitExceededError",this.target=e,this.count=t}}function b(e,t){if(t>v)throw new G(e,t)}function w(e){return e.length>0?e.slice(0,-1)+String.fromCharCode(e.charCodeAt(e.length-1)+1):"ÿ"}function Q(e,t={}){if(t.gt!==void 0&&e<=t.gt)return!1;if(t.gte!==void 0&&e<t.gte)return!1;if(t.lt!==void 0&&e>=t.lt)return!1;if(t.lte!==void 0&&e>t.lte)return!1;return!0}function J(e,t){if(e===null||t===null)return e===t;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}async function Z(e,t){if(e.has)return e.has(t);return I(e,t)}function ee(e,t,r){if(e.keys)return e.keys(t,r);return R(e,t,r)}async function te(e,t){if(e.count)return e.count(t);return K(e,t)}async function ne(e,t){if(e.deletePrefix)return e.deletePrefix(t);return _(e,t)}async function re(e,t,r){if(b("conditionalBatch conditions",t.length),b("conditionalBatch operations",r.length),T(e,"conditionalBatch","storageConditionalBatch"),!e.conditionalBatch)throw Error("This storage backend reports conditionalBatch capability but does not implement the conditionalBatch() method.");return e.conditionalBatch(t,r)}var Je={...H,...q,...V,...X,...Y,...N,...F,...U,...L,...W,...j};function ue(e){if(e===void 0)return;if(typeof e!=="number"||!Number.isInteger(e)||e<0)throw Error("deleteRange limit must be a finite non-negative integer");return e===0?0:e}function D(e){let t={},r=!1;for(let o of["gt","gte","lt","lte"]){let a=e[o];if(a===void 0)continue;if(typeof a!=="string")throw Error("deleteRange bounds must be strings");t[o]=a,r=!0}if(!r)throw Error("deleteRange requires at least one of gt/gte/lt/lte; use deletePrefix to delete a whole prefix");let i=ue(e.limit);if(i!==void 0)t.limit=i;return t}async function ie(e,t,r){let i=D(r);if(e.deleteRange)return e.deleteRange(t,i);return A(e,t,i)}function de(e,t){let r={key:e,open:!1};if(t.gte!==void 0&&t.gte>r.key)r.key=t.gte,r.open=!1;if(t.gt!==void 0&&t.gt>=r.key)r.key=t.gt,r.open=!0;return r}function pe(e,t){let r={key:w(e),open:!0};if(t.lt!==void 0&&t.lt<=r.key)r.key=t.lt,r.open=!0;if(t.lte!==void 0&&t.lte<r.key)r.key=t.lte,r.open=!1;return r}function oe(e,t){let r=de(e,t),i=pe(e,t);if(r.key>i.key||r.key===i.key&&(r.open||i.open))return null;return{lower:r,upper:i}}function P(e){return e.replaceAll(/:+$/g,"")}function fe(e,t){let r=P(e),i=P(t);if(r.length===0)return i;if(i.length===0)return r;return`${r}:${i}`}class k{#t;#n;constructor(e,t){this.#t=e,this.#n=P(t)}#e(e){if(this.#n.length===0)return e;return e.length===0?`${this.#n}:`:`${this.#n}:${e}`}#r(e){return e.map((t)=>{if(t.type==="put")return{type:"put",key:this.#e(t.key),value:t.value};return{type:"delete",key:this.#e(t.key)}})}#i(e){if(this.#n.length===0)return e;return e.slice(this.#n.length+1)}#o(e){let t={};if(e.limit!==void 0)t.limit=e.limit;if(e.gt!==void 0)t.gt=this.#e(e.gt);if(e.gte!==void 0)t.gte=this.#e(e.gte);if(e.lt!==void 0)t.lt=this.#e(e.lt);if(e.lte!==void 0)t.lte=this.#e(e.lte);return t}#a(e={}){let t=this.#o(e);if(e.reverse!==void 0)t.reverse=e.reverse;return t}#s(e){return this.#o(e)}capabilities(){return this.#t.capabilities()}scoped(e){return new k(this.#t,fe(this.#n,e))}async get(e){return this.#t.get(this.#e(e))}async put(e,t){await this.#t.put(this.#e(e),t)}async delete(e){await this.#t.delete(this.#e(e))}async*scan(e,t){for await(let[r,i]of this.#t.scan(this.#e(e),this.#a(t)))yield[this.#i(r),i]}async batch(e){b("batch operations",e.length),await this.#t.batch(this.#r(e))}async conditionalBatch(e,t){return re(this.#t,e.map((r)=>({key:this.#e(r.key),expectedValue:r.expectedValue})),this.#r(t))}async has(e){return Z(this.#t,this.#e(e))}async deletePrefix(e){return ne(this.#t,this.#e(e))}async deleteRange(e,t){let r=this.#s(D(t));return ie(this.#t,this.#e(e),r)}async*keys(e,t){for await(let r of ee(this.#t,this.#e(e),this.#a(t)))yield this.#i(r)}async count(e){return te(this.#t,this.#e(e))}[Symbol.dispose](){this.#t[Symbol.dispose]()}}function ae(e,t){return new k(e,t)}var l="kv";function me(e=globalThis){let{indexedDB:t,IDBKeyRange:r}=e;if(t===void 0||r===void 0)throw Error("IndexedDBStorage requires both indexedDB and IDBKeyRange runtime globals.");return{indexedDB:t,IDBKeyRange:r}}function C(e){return new Promise((t,r)=>{e.onsuccess=()=>t(e.result),e.onerror=()=>r(e.error)})}function ye(e,t){let r=null,i=null,o=null,a=(s,c)=>{let u=s??Error(c);if(i){let d=i;r=null,i=null,d(u);return}o=u};return e.onsuccess=()=>{if(!r)return;let s=r;r=null,i=null,s(e.result)},e.onerror=()=>{a(e.error,"IndexedDB cursor request failed.")},t.onerror=()=>{a(t.error,"IndexedDB transaction failed.")},t.onabort=()=>{a(t.error,"IndexedDB transaction aborted.")},()=>new Promise((s,c)=>{if(o){let u=o;o=null,c(u);return}if(r=s,i=c,e.readyState==="done"){let u=r;r=null,i=null,u?.(e.result)}})}async function*se(e,t,r,i,o,a){let{limit:s,reverse:c}=i,u=w(r),d=t.bound(r,u,!1,!0),h=c?"prev":"next",p=e.transaction(l,"readonly"),g=p.objectStore(l),m=o(g,d,h),S=ye(m,p),O=0,E=!1;try{let x=await S();while(x){if(s!==void 0&&O>=s)break;let le=x.key;if(Q(le,i))yield a(x),O++;x.continue(),x=await S()}E=!0}finally{if(!E)try{p.abort()}catch{}}}class be{#t;#n=null;#e;#r;constructor(e="weft",t=me()){this.#t=e,this.#r=t,this.#e=this.#i()}capabilities(){return{persistence:"local",readAfterWrite:"linearizable",scanConsistency:"best-effort",atomicBatch:!0,conditionalBatch:!0,boundedRangeDelete:!0}}#i(){let e=this.#r.indexedDB.open(this.#t,1);return e.onupgradeneeded=()=>{let t=e.result;if(!t.objectStoreNames.contains(l))t.createObjectStore(l)},C(e).then((t)=>(this.#n=t,t))}async get(e){let i=(await this.#e).transaction(l,"readonly").objectStore(l),o=await C(i.get(e));return o===void 0?null:new Uint8Array(o)}async put(e,t){let o=(await this.#e).transaction(l,"readwrite").objectStore(l);await C(o.put(t,e))}async delete(e){let i=(await this.#e).transaction(l,"readwrite").objectStore(l);await C(i.delete(e))}async has(e){let i=(await this.#e).transaction(l,"readonly").objectStore(l);return await C(i.count(e))>0}async deletePrefix(e){let t=await this.#e,r=w(e),i=this.#r.IDBKeyRange.bound(e,r,!1,!0);return new Promise((o,a)=>{let s=t.transaction(l,"readwrite"),c=s.objectStore(l),u=0,d=c.count(i);d.onsuccess=()=>{u=d.result,c.delete(i)},s.oncomplete=()=>o(u),s.onerror=()=>a(s.error)})}async deleteRange(e,t){let r=D(t),i=oe(e,r);if(i===null)return 0;let o=this.#r.IDBKeyRange.bound(i.lower.key,i.upper.key,i.lower.open,i.upper.open),a=await this.#e,{limit:s}=r;return new Promise((c,u)=>{let d=a.transaction(l,"readwrite"),h=d.objectStore(l),p=0;if(s===void 0){let g=h.count(o);g.onsuccess=()=>{p=g.result,h.delete(o)}}else{let g=h.openCursor(o,"next");g.onsuccess=()=>{let m=g.result;if(m===null||p>=s)return;if(m.delete(),p++,p<s)m.continue()}}d.oncomplete=()=>c(p),d.onerror=()=>u(d.error)})}async*scan(e,t={}){let r=await this.#e;yield*se(r,this.#r.IDBKeyRange,e,t,(i,o,a)=>i.openCursor(o,a),(i)=>[i.key,new Uint8Array(i.value)])}async batch(e){if(b("batch operations",e.length),e.length===0)return;let t=await this.#e;return new Promise((r,i)=>{let o=t.transaction(l,"readwrite"),a=o.objectStore(l);for(let s of e)if(s.type==="put")a.put(s.value,s.key);else a.delete(s.key);o.oncomplete=()=>r(),o.onerror=()=>i(o.error)})}async conditionalBatch(e,t){b("conditionalBatch conditions",e.length),b("conditionalBatch operations",t.length);let r=await this.#e;return new Promise((i,o)=>{let a=r.transaction(l,"readwrite"),s=a.objectStore(l),c=!1,u=!1,d=(g,m)=>{if(c)return;c=!0,o(g??Error(m))};a.oncomplete=()=>{if(c)return;c=!0,i(!0)},a.onerror=()=>{d(a.error,"IndexedDB conditionalBatch transaction failed.")},a.onabort=()=>{if(c)return;if(c=!0,u){i(!1);return}o(a.error??Error("IndexedDB conditionalBatch transaction aborted."))};let h=()=>{for(let g of t)if(g.type==="put")s.put(g.value,g.key);else s.delete(g.key)},p=(g)=>{if(g>=e.length){h();return}let m=e[g],S=s.get(m.key);S.onsuccess=()=>{let O=S.result,E=O===void 0?null:new Uint8Array(O);if(!J(E,m.expectedValue)){u=!0,a.abort();return}p(g+1)},S.onerror=()=>{d(S.error,"IndexedDB conditionalBatch condition check failed.")}};p(0)})}async*keys(e,t={}){let r=await this.#e;yield*se(r,this.#r.IDBKeyRange,e,t,(i,o,a)=>i.openKeyCursor(o,a),(i)=>i.key)}async count(e){let t=await this.#e,r=w(e),o=t.transaction(l,"readonly").objectStore(l);return C(o.count(this.#r.IDBKeyRange.bound(e,r,!1,!0)))}scoped(e){return ae(this,e)}[Symbol.dispose](){if(this.#n)this.#n.close(),this.#n=null}}export{be as IndexedDBStorage};
|
|
@@ -82,12 +82,12 @@ export function createFleetEventFeed(storage, feedOptions) {
|
|
|
82
82
|
throw new PersistedDataCorruptError(KEYS.fleetEventTail());
|
|
83
83
|
if (isTailRecord(decodedTail))
|
|
84
84
|
return decodedTail.sequence;
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
}
|
|
85
|
+
const highest = await highestFleetEventSequence(storage);
|
|
86
|
+
if (highest !== -1)
|
|
87
|
+
return highest;
|
|
88
|
+
try {
|
|
89
|
+
await storageConditionalBatch(storage, [{ key: KEYS.fleetEventTail(), expectedValue: null }], [{ type: "put", key: KEYS.fleetEventTail(), value: encode({ sequence: -1 }) }]);
|
|
90
|
+
} catch {}
|
|
91
91
|
return -1;
|
|
92
92
|
}
|
|
93
93
|
async function snapshotRetentionFloor() {
|
|
@@ -146,6 +146,17 @@ export type RestBinding<Input, Output> = {
|
|
|
146
146
|
* path param would propagate to the engine as a confusingly-shaped
|
|
147
147
|
* "missing" identifier, and surfacing the shape error at the router
|
|
148
148
|
* (404) produces a cleaner wire response than a downstream 400.
|
|
149
|
+
*
|
|
150
|
+
* WHATWG URL path normalization collapses `.` and `..` path segments (and
|
|
151
|
+
* their percent-encoded forms) before `handleRequest()` ever sees
|
|
152
|
+
* `url.pathname` — this function never observes those segments as literal
|
|
153
|
+
* text, so a single trailing `:id`/`:operationId` segment can never match a
|
|
154
|
+
* resource whose id is literally `.` or `..`, no matter how it is encoded.
|
|
155
|
+
* This is no longer just a documented gap: `assertValidWorkflowId` (WFT-95)
|
|
156
|
+
* and `isValidOperationId` reject those exact strings at admission, so a
|
|
157
|
+
* caller-facing workflow or operation id can never legitimately be `.` or
|
|
158
|
+
* `..` in the first place — this URL-normalization quirk is closed by
|
|
159
|
+
* validation rather than left as something callers must work around.
|
|
149
160
|
*/
|
|
150
161
|
export declare function bindingPathMatches(pattern: string, actualPath: string): Record<string, string> | null;
|
|
151
162
|
/**
|
|
@@ -1,14 +1,41 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Build the durable task-ledger envelope a fresh dispatch would create if no
|
|
3
|
-
* ledger record exists yet
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
3
|
+
* ledger record exists yet, and the fresh-dispatch admission checks
|
|
4
|
+
* `dispatchTaskImpl` runs before that — split out of `task-dispatch.ts`
|
|
5
|
+
* purely to stay under this repository's 500-line-per-file ceiling, matching
|
|
6
|
+
* the existing `task-dispatch-revision.ts` precedent. There is no behavioral
|
|
7
|
+
* reason to import this module directly instead of `task-dispatch.ts`, which
|
|
8
|
+
* calls `buildCreateQueuedInput` from both `selectAndReserveWorker` and
|
|
9
|
+
* `enqueueTaskForLongPoll`, and calls the admission helpers from
|
|
10
|
+
* `dispatchTaskImpl` itself.
|
|
8
11
|
*
|
|
9
12
|
* @module server/runtime/task-dispatch-envelope
|
|
10
13
|
*/
|
|
11
14
|
import type { TaskDispatch } from '../index.ts';
|
|
12
15
|
import type { CreateQueuedInput } from '../task-ledger-transitions.ts';
|
|
16
|
+
import type { ServerContext } from './context.ts';
|
|
17
|
+
/**
|
|
18
|
+
* Wait for startup task-ledger recovery (WFT-23) — covers both the public
|
|
19
|
+
* `WeftServer.dispatchTask` entry point and `scheduleDelayedDispatch`'s timer
|
|
20
|
+
* callback, which also calls `dispatchTaskImpl` directly. A rejected gate
|
|
21
|
+
* means the recovery scan itself failed; propagate that failure loudly
|
|
22
|
+
* rather than silently returning false, which callers would read as an
|
|
23
|
+
* ordinary "no worker available" outcome.
|
|
24
|
+
*/
|
|
25
|
+
export declare function awaitTaskLedgerRecoveryReady(context: ServerContext, task: TaskDispatch): Promise<void>;
|
|
26
|
+
/**
|
|
27
|
+
* Reject an invalid caller-supplied operationId before it reaches a ledger
|
|
28
|
+
* write (WFT-95). `dispatchTask()` is a public same-process API taking a
|
|
29
|
+
* caller-controlled operationId; an id equal to the exact string "." or
|
|
30
|
+
* ".." can never be addressed again over REST (a single trailing
|
|
31
|
+
* `:operationId` path segment is collapsed away by WHATWG URL path
|
|
32
|
+
* normalization before the route matcher ever sees it), so fresh-dispatch
|
|
33
|
+
* admission rejects it up front instead of writing a ledger record that
|
|
34
|
+
* becomes unreachable by id. Skipped for `redispatch` — reconstructing and
|
|
35
|
+
* redispatching an already-decoded, previously persisted ledger record
|
|
36
|
+
* (`scheduleDelayedDispatch`/`taskDispatchFromLedgerRecord`) must not
|
|
37
|
+
* re-apply an admission-only check to data that was valid when written.
|
|
38
|
+
*/
|
|
39
|
+
export declare function assertFreshDispatchOperationIdAdmissible(task: TaskDispatch, redispatch: boolean): void;
|
|
13
40
|
/** The durable envelope every fresh dispatch would create if no ledger record exists yet. */
|
|
14
41
|
export declare function buildCreateQueuedInput(task: TaskDispatch, queue: string, visibilityTimeout: number): CreateQueuedInput;
|
|
@@ -1,5 +1,27 @@
|
|
|
1
1
|
import { isJSONValue } from "../../core/json.js";
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
isValidOperationId,
|
|
4
|
+
isValidWorkflowRevision,
|
|
5
|
+
REMOTE_TASK_RECORD_VERSION
|
|
6
|
+
} from "../task-ledger.js";
|
|
7
|
+
export async function awaitTaskLedgerRecoveryReady(context, task) {
|
|
8
|
+
try {
|
|
9
|
+
await context.taskLedgerRecovery.ready;
|
|
10
|
+
} catch (error) {
|
|
11
|
+
throw Error(`Cannot dispatch task "${task.operationId}" \u2014 startup task-ledger recovery failed: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
export function assertFreshDispatchOperationIdAdmissible(task, redispatch) {
|
|
15
|
+
if (redispatch || isValidOperationId(task.operationId))
|
|
16
|
+
return;
|
|
17
|
+
let formattedOperationId;
|
|
18
|
+
try {
|
|
19
|
+
formattedOperationId = JSON.stringify(task.operationId) ?? String(task.operationId);
|
|
20
|
+
} catch {
|
|
21
|
+
formattedOperationId = `<${typeof task.operationId}>`;
|
|
22
|
+
}
|
|
23
|
+
throw Error(`TaskDispatch has an invalid "operationId" (${formattedOperationId}) \u2014 it must be a non-empty, bounded identifier other than "." or "..".`);
|
|
24
|
+
}
|
|
3
25
|
function buildOptionalCreateQueuedFields(task) {
|
|
4
26
|
return {
|
|
5
27
|
...task.workflowId !== void 0 ? { workflowId: task.workflowId } : {},
|
|
@@ -9,6 +9,8 @@ import type { ServerContext } from './context.ts';
|
|
|
9
9
|
*/
|
|
10
10
|
export declare function scheduleDelayedDispatch(context: ServerContext, options: ServeOptions, task: TaskDispatch, delay: number): void;
|
|
11
11
|
export declare function resolveTaskPriority(_context: ServerContext, _options: ServeOptions, task: TaskDispatch): number | undefined;
|
|
12
|
-
export declare function dispatchTaskImpl(context: ServerContext, options: ServeOptions, task: TaskDispatch
|
|
12
|
+
export declare function dispatchTaskImpl(context: ServerContext, options: ServeOptions, task: TaskDispatch, { redispatch }?: {
|
|
13
|
+
redispatch?: boolean;
|
|
14
|
+
}): Promise<boolean>;
|
|
13
15
|
/** Send a cancel message to the worker handling a specific operation. */
|
|
14
16
|
export declare function cancelTask(context: ServerContext, operationId: string): boolean;
|
|
@@ -8,7 +8,11 @@ import {
|
|
|
8
8
|
decodeRemoteTaskRecord,
|
|
9
9
|
taskLedgerKey
|
|
10
10
|
} from "../task-ledger.js";
|
|
11
|
-
import {
|
|
11
|
+
import {
|
|
12
|
+
assertFreshDispatchOperationIdAdmissible,
|
|
13
|
+
awaitTaskLedgerRecoveryReady,
|
|
14
|
+
buildCreateQueuedInput
|
|
15
|
+
} from "./task-dispatch-envelope.js";
|
|
12
16
|
import { assertDispatchTargetsFreshRevision } from "./task-dispatch-revision.js";
|
|
13
17
|
import { commitTaskLedgerTransition } from "./task-ledger-runtime.js";
|
|
14
18
|
import {
|
|
@@ -27,7 +31,7 @@ export function scheduleDelayedDispatch(context, options, task, delay) {
|
|
|
27
31
|
return;
|
|
28
32
|
const timer = setTimeout(() => {
|
|
29
33
|
context.pendingTimers.delete(timer);
|
|
30
|
-
dispatchTaskImpl(context, options, task).catch((err) => console.error(`[weft] Delayed redispatch failed for "${task.operationId}":`, err));
|
|
34
|
+
dispatchTaskImpl(context, options, task, { redispatch: !0 }).catch((err) => console.error(`[weft] Delayed redispatch failed for "${task.operationId}":`, err));
|
|
31
35
|
}, delay);
|
|
32
36
|
context.pendingTimers.add(timer);
|
|
33
37
|
}
|
|
@@ -181,12 +185,9 @@ async function enqueueTaskForLongPoll(context, options, task, queue, visibilityT
|
|
|
181
185
|
recordTaskBacklogMetric(context.metricsCollector, context.taskQueue);
|
|
182
186
|
return enqueued;
|
|
183
187
|
}
|
|
184
|
-
export async function dispatchTaskImpl(context, options, task) {
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
} catch (error) {
|
|
188
|
-
throw Error(`Cannot dispatch task "${task.operationId}" \u2014 startup task-ledger recovery failed: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
|
|
189
|
-
}
|
|
188
|
+
export async function dispatchTaskImpl(context, options, task, { redispatch = !1 } = {}) {
|
|
189
|
+
await awaitTaskLedgerRecoveryReady(context, task);
|
|
190
|
+
assertFreshDispatchOperationIdAdmissible(task, redispatch);
|
|
190
191
|
if (!task.workflowType)
|
|
191
192
|
throw Error(`TaskDispatch for operation "${task.operationId}" is missing required field "workflowType".`);
|
|
192
193
|
const revisionFenceConditions = await assertDispatchTargetsFreshRevision(options, task), dotIndex = task.activityName.indexOf(".");
|
|
@@ -24,6 +24,25 @@ import type { RemoteTaskCancelling, RemoteTaskCompleting, RemoteTaskDeadLettered
|
|
|
24
24
|
* that later fails to decode.
|
|
25
25
|
*/
|
|
26
26
|
export declare function isValidWorkflowRevision(value: unknown): value is string;
|
|
27
|
+
/**
|
|
28
|
+
* Whether `value` is a valid caller-facing task `operationId` — a non-empty,
|
|
29
|
+
* bounded identifier per the ledger's own contract, and not the exact string
|
|
30
|
+
* `.` or `..` (WFT-95). WHATWG URL path normalization collapses `.`/`..`
|
|
31
|
+
* path segments (and their percent-encoded forms) before `handleRequest()`
|
|
32
|
+
* ever sees `url.pathname`, so a REST route with a single trailing
|
|
33
|
+
* `:operationId` segment (e.g. `weft.tasks.get`'s
|
|
34
|
+
* `/v1/tasks/detail/:operationId`) can never address a record whose
|
|
35
|
+
* operationId is literally `.` or `..`. Exported so fresh-dispatch admission
|
|
36
|
+
* (`task-dispatch.ts`'s `dispatchTaskImpl`) can reject an invalid
|
|
37
|
+
* caller-supplied `operationId` before it ever reaches a ledger write,
|
|
38
|
+
* closing that URL-normalization quirk as an enforced admission-time
|
|
39
|
+
* guarantee instead of an assumption. Deliberately NOT applied when
|
|
40
|
+
* redispatching an already-decoded, previously persisted ledger record —
|
|
41
|
+
* see `dispatchTaskImpl`'s `redispatch` option — since such an id was valid
|
|
42
|
+
* under the pre-WFT-95 decode contract and may already be durably
|
|
43
|
+
* persisted. Does not reject an id that merely contains a dot character.
|
|
44
|
+
*/
|
|
45
|
+
export declare function isValidOperationId(value: unknown): value is string;
|
|
27
46
|
/** Bounded header map: at most {@link MAX_TASK_HEADER_COUNT} entries, each key/value at most {@link MAX_TASK_HEADER_VALUE_BYTES}. */
|
|
28
47
|
export declare function isValidTaskHeaders(value: unknown): value is Readonly<Record<string, string>>;
|
|
29
48
|
export declare function isRemoteTaskQueued(value: unknown): value is RemoteTaskQueued;
|
|
@@ -17,6 +17,9 @@ function isBoundedIdentifier(value, maxBytes = MAX_TASK_IDENTIFIER_BYTES) {
|
|
|
17
17
|
export function isValidWorkflowRevision(value) {
|
|
18
18
|
return isBoundedIdentifier(value);
|
|
19
19
|
}
|
|
20
|
+
export function isValidOperationId(value) {
|
|
21
|
+
return isBoundedIdentifier(value) && value !== "." && value !== "..";
|
|
22
|
+
}
|
|
20
23
|
function isBoundedOptionalIdentifier(value, maxBytes = MAX_TASK_IDENTIFIER_BYTES) {
|
|
21
24
|
return value === void 0 || isBoundedIdentifier(value, maxBytes);
|
|
22
25
|
}
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
*
|
|
11
11
|
* @module server/task-ledger
|
|
12
12
|
*/
|
|
13
|
-
export { decodeRemoteTaskRecord, encodeRemoteTaskRecord, isRemoteTaskCancelling, isRemoteTaskCompleting, isRemoteTaskDeadLettered, isRemoteTaskLeased, isRemoteTaskQueued, isRemoteTaskRecord, isRemoteTaskTerminal, isRemoteTaskTerminalCancelled, isRemoteTaskTerminalResolved, isRemoteTaskTerminalRetryExhausted, isValidTaskHeaders, isValidWorkflowRevision, } from './task-ledger-codec.ts';
|
|
13
|
+
export { decodeRemoteTaskRecord, encodeRemoteTaskRecord, isRemoteTaskCancelling, isRemoteTaskCompleting, isRemoteTaskDeadLettered, isRemoteTaskLeased, isRemoteTaskQueued, isRemoteTaskRecord, isRemoteTaskTerminal, isRemoteTaskTerminalCancelled, isRemoteTaskTerminalResolved, isRemoteTaskTerminalRetryExhausted, isValidOperationId, isValidTaskHeaders, isValidWorkflowRevision, } from './task-ledger-codec.ts';
|
|
14
14
|
export { taskLedgerKey } from './task-ledger-keys.ts';
|
|
15
15
|
export { MAX_TASK_HEADER_COUNT, MAX_TASK_HEADER_VALUE_BYTES, MAX_TASK_IDENTIFIER_BYTES, MAX_TASK_REASON_BYTES, utf8ByteLength, } from './task-ledger-limits.ts';
|
|
16
16
|
export { REMOTE_TASK_RECORD_VERSION } from './task-ledger-types.ts';
|