@lunora/workflow 1.0.0-alpha.60 → 1.0.0-alpha.61
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/do/index.mjs +1 -1
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.mjs +1 -1
- package/dist/packem_shared/{createRunStep-DPafHcOc.mjs → createRunStep-DITrH01N.mjs} +1 -1
- package/dist/packem_shared/createWorkflowRunContext-Dk5nhB1e.mjs +1 -0
- package/dist/packem_shared/run-step-bKFJhP--.mjs +1 -0
- package/package.json +1 -1
- package/dist/packem_shared/createWorkflowRunContext-DhzM_oYZ.mjs +0 -1
- package/dist/packem_shared/run-step-IuqYPWKG.mjs +0 -1
package/dist/do/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{WorkflowEntrypoint as p}from"cloudflare:workers";import{NonRetryableError as i}from"cloudflare:workflows";import{convertNonRetryableError as m}from"../packem_shared/NonRetryableError-BPu01mU8.mjs";import{extractBranchMarker as f,stripBranchMarker as h,signalBranchParentSafe as l,errorOutcome as u,okOutcome as y}from"../packem_shared/MAX_BRANCHES-j59ZUUSu.mjs";import{createWorkflowRunContext as d}from"../packem_shared/createWorkflowRunContext-
|
|
1
|
+
import{WorkflowEntrypoint as p}from"cloudflare:workers";import{NonRetryableError as i}from"cloudflare:workflows";import{convertNonRetryableError as m}from"../packem_shared/NonRetryableError-BPu01mU8.mjs";import{extractBranchMarker as f,stripBranchMarker as h,signalBranchParentSafe as l,errorOutcome as u,okOutcome as y}from"../packem_shared/MAX_BRANCHES-j59ZUUSu.mjs";import{createWorkflowRunContext as d}from"../packem_shared/createWorkflowRunContext-Dk5nhB1e.mjs";class N extends p{#r;#t;constructor(t,e,o,r){super(t,e),this.#t=o,this.#r=r??"workflow"}async run(t,e){const o=e,r=f(t.payload),c=r?{...t,payload:h(t.payload)}:t,a=d({env:this.env,event:c,exportName:this.#r,nonRetryableErrorClass:i,step:o});let n;try{n=await this.#t.handler(a)}catch(s){return r&&await l({env:this.env,log:a.log,step:o},r,u(s)),m(s,i)}return r&&await l({env:this.env,log:a.log,step:o},r,y(n)),n}}export{N as default};
|
package/dist/index.d.mts
CHANGED
|
@@ -294,10 +294,10 @@ declare const createWorkflowRunContext: <Params = Record<string, unknown>>(optio
|
|
|
294
294
|
declare const validateStepArgs: (validators: StepArgsValidator, source: Record<string, unknown>) => Record<string, unknown>;
|
|
295
295
|
/** Dependencies needed to run a step: the native step API plus the workflow's env / runner / logger. */
|
|
296
296
|
interface RunStepDeps {
|
|
297
|
+
/** The instance's `dedupNamespace(exportName, instanceId)` — the prefix of the replay-dedup ids the steps' dispatches carry (see `dedup-id.ts`). */
|
|
298
|
+
dedupNamespace: string;
|
|
297
299
|
/** The Worker environment bindings, surfaced on the step context. */
|
|
298
300
|
env: Record<string, unknown>;
|
|
299
|
-
/** This workflow instance's id — the namespace for the replay-dedup ids the steps' dispatches carry. */
|
|
300
|
-
instanceId: string;
|
|
301
301
|
/** Structured logger surfaced on the step context. */
|
|
302
302
|
log: WorkflowLogger;
|
|
303
303
|
/** Native `cloudflare:workflows` `NonRetryableError` constructor — injected by `src/do`; absent in Node tests. */
|
package/dist/index.d.ts
CHANGED
|
@@ -294,10 +294,10 @@ declare const createWorkflowRunContext: <Params = Record<string, unknown>>(optio
|
|
|
294
294
|
declare const validateStepArgs: (validators: StepArgsValidator, source: Record<string, unknown>) => Record<string, unknown>;
|
|
295
295
|
/** Dependencies needed to run a step: the native step API plus the workflow's env / runner / logger. */
|
|
296
296
|
interface RunStepDeps {
|
|
297
|
+
/** The instance's `dedupNamespace(exportName, instanceId)` — the prefix of the replay-dedup ids the steps' dispatches carry (see `dedup-id.ts`). */
|
|
298
|
+
dedupNamespace: string;
|
|
297
299
|
/** The Worker environment bindings, surfaced on the step context. */
|
|
298
300
|
env: Record<string, unknown>;
|
|
299
|
-
/** This workflow instance's id — the namespace for the replay-dedup ids the steps' dispatches carry. */
|
|
300
|
-
instanceId: string;
|
|
301
301
|
/** Structured logger surfaced on the step context. */
|
|
302
302
|
log: WorkflowLogger;
|
|
303
303
|
/** Native `cloudflare:workflows` `NonRetryableError` constructor — injected by `src/do`; absent in Node tests. */
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createWorkflowContext as e}from"./packem_shared/createWorkflowContext-zQR_9N-v.mjs";import{default as f}from"./packem_shared/createWorkflows-LvAyUyKq.mjs";import{defineWorkflowEvent as a,isWorkflowEventDefinition as i}from"./packem_shared/defineWorkflowEvent-suERPEEV.mjs";import{defineStep as p,isStepDefinition as s}from"./packem_shared/defineStep-D1-9eOnA.mjs";import{defineWorkflow as w,isWorkflowDefinition as x,workflowBindingName as k,workflowClassName as c,workflowDefaultName as E}from"./packem_shared/defineWorkflow-tKaIifbZ.mjs";import{NonRetryableError as N,convertNonRetryableError as R,isNonRetryableError as v,toNativeNonRetryableError as d}from"./packem_shared/NonRetryableError-BPu01mU8.mjs";import{MAX_BRANCHES as u,branch as C}from"./packem_shared/MAX_BRANCHES-j59ZUUSu.mjs";import{WorkflowsRestError as S,createWorkflowsRestClient as y}from"./packem_shared/WorkflowsRestError-Ccq1FUR1.mjs";import{createWorkflowRunContext as g}from"./packem_shared/createWorkflowRunContext-
|
|
1
|
+
import{createWorkflowContext as e}from"./packem_shared/createWorkflowContext-zQR_9N-v.mjs";import{default as f}from"./packem_shared/createWorkflows-LvAyUyKq.mjs";import{defineWorkflowEvent as a,isWorkflowEventDefinition as i}from"./packem_shared/defineWorkflowEvent-suERPEEV.mjs";import{defineStep as p,isStepDefinition as s}from"./packem_shared/defineStep-D1-9eOnA.mjs";import{defineWorkflow as w,isWorkflowDefinition as x,workflowBindingName as k,workflowClassName as c,workflowDefaultName as E}from"./packem_shared/defineWorkflow-tKaIifbZ.mjs";import{NonRetryableError as N,convertNonRetryableError as R,isNonRetryableError as v,toNativeNonRetryableError as d}from"./packem_shared/NonRetryableError-BPu01mU8.mjs";import{MAX_BRANCHES as u,branch as C}from"./packem_shared/MAX_BRANCHES-j59ZUUSu.mjs";import{WorkflowsRestError as S,createWorkflowsRestClient as y}from"./packem_shared/WorkflowsRestError-Ccq1FUR1.mjs";import{createWorkflowRunContext as g}from"./packem_shared/createWorkflowRunContext-Dk5nhB1e.mjs";import{c as h,v as F}from"./packem_shared/run-step-bKFJhP--.mjs";import{createWaitForEvent as I}from"./packem_shared/createWaitForEvent-D5Ohn2Pz.mjs";import{isDuplicateInstanceError as X}from"./packem_shared/isDuplicateInstanceError-CecnqNAa.mjs";export{u as MAX_BRANCHES,N as NonRetryableError,S as WorkflowsRestError,C as branch,R as convertNonRetryableError,h as createRunStep,I as createWaitForEvent,e as createWorkflowContext,g as createWorkflowRunContext,f as createWorkflows,y as createWorkflowsRestClient,p as defineStep,w as defineWorkflow,a as defineWorkflowEvent,X as isDuplicateInstanceError,v as isNonRetryableError,s as isStepDefinition,x as isWorkflowDefinition,i as isWorkflowEventDefinition,d as toNativeNonRetryableError,F as validateStepArgs,k as workflowBindingName,c as workflowClassName,E as workflowDefaultName};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{c as p,v as o}from"./run-step-
|
|
1
|
+
import{c as p,v as o}from"./run-step-bKFJhP--.mjs";import"./defineWorkflowEvent-suERPEEV.mjs";import"./NonRetryableError-BPu01mU8.mjs";export{p as createRunStep,o as validateStepArgs};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{u as I,I as R,l as C,d as N,c as T,p as k}from"./run-step-bKFJhP--.mjs";import{LunoraError as S}from"@lunora/errors";import{workflowBindingName as y}from"./defineWorkflow-tKaIifbZ.mjs";import{raiseNonRetryable as _}from"./NonRetryableError-BPu01mU8.mjs";import{createSpawn as O,createParallel as v}from"./MAX_BRANCHES-j59ZUUSu.mjs";import{createWaitForEvent as $}from"./createWaitForEvent-D5Ohn2Pz.mjs";const x=e=>({debug:(t,...o)=>{console.debug(e,t,...o)},error:(t,...o)=>{console.error(e,t,...o)},info:(t,...o)=>{console.info(e,t,...o)},warn:(t,...o)=>{console.warn(e,t,...o)}}),j=e=>{let t="";for(let a=0;a<e.length;a+=32768)t+=String.fromCharCode(...e.subarray(a,a+32768));return btoa(t)},P=e=>{const t=atob(e),o=new Uint8Array(t.length);for(let a=0;a<t.length;a+=1)o[a]=t.codePointAt(a)??0;return o},B="$lunora.wire$",b=64,p=1024,g="__proto__",E={BigInt64Array,BigUint64Array,Float32Array,Float64Array,Int8Array,Int16Array,Int32Array,Uint8Array,Uint8ClampedArray,Uint16Array,Uint32Array},h={Error,EvalError,RangeError,ReferenceError,SyntaxError,TypeError,URIError},l=(e,t=0)=>{if(t>b)throw new RangeError(`wire-codec: value nesting exceeds the ${b}-level limit`);if(e===null||typeof e!="object")return e;if(Array.isArray(e)){if(e[0]===B)switch(e[1]){case"-inf":return-1/0;case"arr":return e[2].map(r=>l(r,t+1));case"bigint":{const r=e[2];if(typeof r!="string"||r.length>p||!/^-?\d+$/.test(r))throw new RangeError(`wire-codec: invalid or over-long bigint (max ${p} digits)`);return BigInt(r)}case"date":{const r=l(e[2],t+1);if(typeof r!="number")throw new TypeError("wire-codec: malformed date — epoch must be a number");return new Date(r)}case"map":{const r=e[2];return new Map(r.map(n=>{if(!Array.isArray(n)||n.length!==2)throw new TypeError("wire-codec: malformed map entry — expected a [key, value] pair");return[l(n[0],t+1),l(n[1],t+1)]}))}case"set":return new Set(e[2].map(r=>l(r,t+1)));case"url":{const r=e[2];if(typeof r!="string")throw new TypeError("wire-codec: malformed url — href must be a string");return new URL(r)}case"error":{const r=e[2],n=e[3];if(typeof r!="string"||typeof n!="string")throw new TypeError("wire-codec: malformed error — name and message must be strings");const i=(Object.hasOwn(h,r)?h[r]:void 0)??Error,c=new i(n);c.name!==r&&Object.defineProperty(c,"name",{configurable:!0,value:r,writable:!0});const f=l(e[4],t+1);if(f===null||typeof f!="object"||Array.isArray(f))throw new TypeError("wire-codec: malformed error — props must be an object");for(const d of Object.keys(f))d===g?Object.defineProperty(c,d,{configurable:!0,enumerable:!0,value:f[d],writable:!0}):c[d]=f[d];return e.length>5&&Object.defineProperty(c,"cause",{configurable:!0,value:l(e[5],t+1),writable:!0}),c}case"bytes":{const r=e[2];if(typeof r!="string")throw new TypeError("wire-codec: malformed bytes — payload must be a base64 string");const n=P(r);if(j(n)!==r)throw new TypeError("wire-codec: malformed bytes — payload must be canonical padded base64");const i=e[3]??"Uint8Array";if(i==="ArrayBuffer")return n.buffer.byteLength===n.byteLength?n.buffer:n.slice().buffer;const c=Object.hasOwn(E,i)?E[i]:void 0;return c?new c(n.slice().buffer):n}case"inf":return 1/0;case"nan":return Number.NaN;case"undefined":return;default:return e.map(r=>l(r,t+1))}return e.map(s=>l(s,t+1))}const o=e,a={};for(const s of Object.keys(o)){const r=l(o[s],t+1);s===g?Object.defineProperty(a,s,{configurable:!0,enumerable:!0,value:r,writable:!0}):a[s]=r}return a},U=1e3,D=3e4,M=async e=>{await new Promise(t=>{setTimeout(t,e)})},F=e=>async(t,o,a)=>{const s=async(r,n)=>{try{return await e(t,o,a)}catch(i){if(!I(i))throw i;const c=Date.now(),f=r??c,d=f+R-c;if(d<=0)throw i;return await M(Math.min(n,d)),s(f,Math.min(n*2,D))}};return s(void 0,U)},Y=e=>{const t=x(`[workflow:${e.exportName}]`),o=F(C({env:e.env,fetchImpl:e.fetchImpl,label:"@lunora/workflow"})),a=N(e.exportName,e.event.instanceId),s=k(o,`${a}#body`),r=u=>{const m=y(u),w=e.env[m];if(!w||typeof w.create!="function"||typeof w.get!="function")throw new S("INTERNAL",`@lunora/workflow: cannot spawn child workflow "${u}" — no Workflow binding "${m}" on env (is it declared in lunora/workflows.ts?)`);return w},n=e.exportName.replaceAll(/\W/gu,"_");let i=0;const c=u=>{if(u!==void 0)return u;const m=`${e.event.instanceId}-${n}-c${String(i)}`;return i+=1,m},f={env:e.env,instanceId:e.event.instanceId,log:t,nextChildId:c,parentBinding:y(e.exportName),resolveBinding:r,step:e.step},A=(()=>{try{return l(e.event.payload)}catch(u){return _(`@lunora/workflow: workflow "${e.exportName}" params could not be decoded — ${u instanceof Error?u.message:String(u)}`,u,e.nonRetryableErrorClass)}})();return{env:e.env,event:e.event,...e.fetchImpl===void 0?{}:{fetchImpl:e.fetchImpl},log:t,parallel:v(f),params:A,run:s,runStep:T({dedupNamespace:a,env:e.env,log:t,nonRetryableErrorClass:e.nonRetryableErrorClass,run:o,step:e.step}),spawn:O(f),step:e.step,waitForEvent:$({nonRetryableErrorClass:e.nonRetryableErrorClass,step:e.step})}};export{Y as createWorkflowRunContext};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{LunoraError as w,isLunoraError as J}from"@lunora/errors";import{parseValidatorMap as H}from"@lunora/values";import{RESERVED_EVENT_TYPE_PREFIX as T}from"./defineWorkflowEvent-suERPEEV.mjs";import{raiseNonRetryable as R,convertNonRetryableError as K}from"./NonRetryableError-BPu01mU8.mjs";const pr=9e5,V="DISPATCH_IN_PROGRESS",W="x-lunora-dispatch-declined",F=(r,t,o)=>{if(t===void 0)return{dispose:()=>{},signal:r};const a=new AbortController,n=setTimeout(()=>{a.abort(o())},t);return{dispose:()=>{clearTimeout(n)},signal:a.signal}},$=r=>{let t="";for(let o=0;o<r.length;o+=32768)t+=String.fromCharCode(...r.subarray(o,o+32768));return btoa(t)},G=r=>{const t=atob(r),o=new Uint8Array(t.length);for(let a=0;a<t.length;a+=1)o[a]=t.codePointAt(a)??0;return o},b="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",k=r=>{let t="",o=0;const a=r.length-2;for(;o<a;o+=3){const e=r[o]<<16|r[o+1]<<8|r[o+2];t+=b.charAt(e>>18&63)+b.charAt(e>>12&63)+b.charAt(e>>6&63)+b.charAt(e&63)}const n=r.length-o;if(n===1){const e=r[o]<<16;t+=b.charAt(e>>18&63)+b.charAt(e>>12&63)}else if(n===2){const e=r[o]<<16|r[o+1]<<8;t+=b.charAt(e>>18&63)+b.charAt(e>>12&63)+b.charAt(e>>6&63)}return t};new TextDecoder;const P=new TextEncoder,I="=",z=r=>{for(let t=0;t<r.length;t+=1)if(r.charCodeAt(t)>255)return!1;return!0},X=r=>k(P.encode(JSON.stringify(r))),Y=r=>!r.startsWith(I)&&z(r)?r:`${I}${k(P.encode(r))}`,f="$lunora.wire$",O=64,j=1024,S="__proto__",_={BigInt64Array,BigUint64Array,Float32Array,Float64Array,Int8Array,Int16Array,Int32Array,Uint8Array,Uint8ClampedArray,Uint16Array,Uint32Array},U={Error,EvalError,RangeError,ReferenceError,SyntaxError,TypeError,URIError},q=r=>{if(r===null||typeof r!="object")return!1;const t=Object.getPrototypeOf(r);return t===null||t===Object.prototype},g=(r,t=0)=>{if(t>O)throw new RangeError(`wire-codec: value nesting exceeds the ${O}-level limit`);if(r===void 0)return[f,"undefined"];if(r===null)return null;const o=typeof r;if(o==="bigint")return[f,"bigint",r.toString()];if(o==="number"){const e=r;return Number.isNaN(e)?[f,"nan"]:e===1/0?[f,"inf"]:e===-1/0?[f,"-inf"]:e}if(o!=="object")return r;if(r instanceof Date)return[f,"date",g(r.getTime(),t+1)];if(r instanceof Error){const e=r,s={};for(const c of Object.keys(e)){if(e[c]===void 0)continue;const l=g(e[c],t+1);c===S?Object.defineProperty(s,c,{configurable:!0,enumerable:!0,value:l,writable:!0}):s[c]=l}const i=[f,"error",String(e.name),String(e.message),s];return e.cause!==void 0&&i.push(g(e.cause,t+1)),i}if(r instanceof URL)return[f,"url",r.href];if(r instanceof Map)return[f,"map",[...r.entries()].map(([e,s])=>[g(e,t+1),g(s,t+1)])];if(r instanceof Set)return[f,"set",[...r].map(e=>g(e,t+1))];if(r instanceof ArrayBuffer)return[f,"bytes",$(new Uint8Array(r)),"ArrayBuffer"];if(ArrayBuffer.isView(r)){const e=r,s=e.constructor.name,i=new Uint8Array(e.buffer,e.byteOffset,e.byteLength);return s==="Uint8Array"?[f,"bytes",$(i)]:[f,"bytes",$(i),s]}if(Array.isArray(r)){const e=r.map(s=>g(s,t+1));return e.length>0&&e[0]===f?[f,"arr",e]:e}if(!q(r)){const e=r.constructor?.name??"value";throw new TypeError(`wire-codec: cannot encode a ${e} over the Lunora wire — only plain objects, arrays, and the supported built-ins (Date, Error, URL, Map, Set, ArrayBuffer/typed arrays, bigint) round-trip`)}const a=r,n={};for(const e of Object.keys(a)){const s=a[e];if(s===void 0)continue;const i=g(s,t+1);e===S?Object.defineProperty(n,e,{configurable:!0,enumerable:!0,value:i,writable:!0}):n[e]=i}return n},y=(r,t=0)=>{if(t>O)throw new RangeError(`wire-codec: value nesting exceeds the ${O}-level limit`);if(r===null||typeof r!="object")return r;if(Array.isArray(r)){if(r[0]===f)switch(r[1]){case"-inf":return-1/0;case"arr":return r[2].map(n=>y(n,t+1));case"bigint":{const n=r[2];if(typeof n!="string"||n.length>j||!/^-?\d+$/.test(n))throw new RangeError(`wire-codec: invalid or over-long bigint (max ${j} digits)`);return BigInt(n)}case"date":{const n=y(r[2],t+1);if(typeof n!="number")throw new TypeError("wire-codec: malformed date — epoch must be a number");return new Date(n)}case"map":{const n=r[2];return new Map(n.map(e=>{if(!Array.isArray(e)||e.length!==2)throw new TypeError("wire-codec: malformed map entry — expected a [key, value] pair");return[y(e[0],t+1),y(e[1],t+1)]}))}case"set":return new Set(r[2].map(n=>y(n,t+1)));case"url":{const n=r[2];if(typeof n!="string")throw new TypeError("wire-codec: malformed url — href must be a string");return new URL(n)}case"error":{const n=r[2],e=r[3];if(typeof n!="string"||typeof e!="string")throw new TypeError("wire-codec: malformed error — name and message must be strings");const s=(Object.hasOwn(U,n)?U[n]:void 0)??Error,i=new s(e);i.name!==n&&Object.defineProperty(i,"name",{configurable:!0,value:n,writable:!0});const c=y(r[4],t+1);if(c===null||typeof c!="object"||Array.isArray(c))throw new TypeError("wire-codec: malformed error — props must be an object");for(const l of Object.keys(c))l===S?Object.defineProperty(i,l,{configurable:!0,enumerable:!0,value:c[l],writable:!0}):i[l]=c[l];return r.length>5&&Object.defineProperty(i,"cause",{configurable:!0,value:y(r[5],t+1),writable:!0}),i}case"bytes":{const n=r[2];if(typeof n!="string")throw new TypeError("wire-codec: malformed bytes — payload must be a base64 string");const e=G(n);if($(e)!==n)throw new TypeError("wire-codec: malformed bytes — payload must be canonical padded base64");const s=r[3]??"Uint8Array";if(s==="ArrayBuffer")return e.buffer.byteLength===e.byteLength?e.buffer:e.slice().buffer;const i=Object.hasOwn(_,s)?_[s]:void 0;return i?new i(e.slice().buffer):e}case"inf":return 1/0;case"nan":return Number.NaN;case"undefined":return;default:return r.map(n=>y(n,t+1))}return r.map(n=>y(n,t+1))}const o=r,a={};for(const n of Object.keys(o)){const e=y(o[n],t+1);n===S?Object.defineProperty(a,n,{configurable:!0,enumerable:!0,value:e,writable:!0}):a[n]=e}return a},Q=(r,t,o)=>{try{return g(o)}catch(a){throw new TypeError(`${r}: cannot encode args for '${t}' — ${a instanceof Error?a.message:String(a)}`,a instanceof Error?{cause:a}:void 0)}},Z="/_lunora/scheduler/dispatch",rr=3e4,tr=r=>{let t=r.length;for(;t>0&&r[t-1]==="/";)t-=1;return r.slice(0,t)},D=Symbol("lunoraDispatchFailure"),x=Symbol("lunoraDispatchDecline"),er=Symbol("lunoraDispatchMessageId"),C=(r,t)=>(t!==void 0&&Object.defineProperty(r,er,{value:t}),r),nr=(r,t)=>(Object.defineProperty(r,D,{value:!0}),C(r,t)),or=(r,t,o,a)=>{const{status:n}=t;try{const e=JSON.parse(o)?.error;if(typeof e=="object"&&e!==null&&typeof e.code=="string"){const{code:s,data:i,message:c}=e,l=nr(new w(s,typeof c=="string"?c:void 0,{data:i,status:n}),a);return t.headers.get(W)==="1"&&Object.defineProperty(l,x,{value:!0}),l}}catch{}return C(new w("INTERNAL",`${r}: function dispatch failed (${String(n)}): ${o}`,{status:n}),a)},ar=new Set([400,403,404,422]),sr=new Set([V,"DISPATCH_UNAUTHENTICATED"]),B=r=>J(r)&&r[D]===!0,ir=r=>B(r)&&ar.has(r.status)&&!sr.has(r.code),br=r=>B(r)&&r[x]===!0,cr=(r,t,o)=>new w("INTERNAL",`${r}: function dispatch to "${t}" timed out after ${String(o)}ms`,{status:503}),gr=r=>{const{label:t}=r,o=globalThis.fetch,a=r.fetchImpl??(typeof o=="function"?o.bind(globalThis):void 0);return async(n,e,s={})=>{if(typeof a!="function")throw new TypeError(`${t}: no fetch implementation available — pass fetchImpl or run on a platform with global fetch`);const i=()=>r.argsAlreadyEncoded===!0?e??{}:Q(t,n.__lunoraRef,e??{}),c=r.env.LUNORA_ORIGIN_URL;if(typeof c!="string"||c.length===0)throw new w("INTERNAL",`${t}: \`LUNORA_ORIGIN_URL\` must be set on the Worker env so a handler can call back into Lunora functions`);const l=r.env.LUNORA_ADMIN_TOKEN;if(typeof l!="string"||l.length===0)throw new w("INTERNAL",`${t}: \`LUNORA_ADMIN_TOKEN\` must be set on the Worker env to authenticate function dispatch`);const v=`${tr(c)}${Z}`,h={authorization:`Bearer ${l}`,"content-type":"application/json"};r.traceparent!==void 0&&r.traceparent.length>0&&(h.traceparent=r.traceparent),r.identity?.userId!==void 0&&(h["x-lunora-userid"]=Y(r.identity.userId)),r.identity?.claims!==void 0&&(h["x-lunora-identity"]=X(r.identity.claims));const p=s.timeoutMs??rr,N=F(void 0,p,()=>new DOMException(`dispatch timed out after ${String(p)}ms`,"TimeoutError")),m=d=>{throw d instanceof Error&&d.name==="TimeoutError"?cr(t,n.__lunoraRef,p):d};let u;try{try{u=await a(v,{body:JSON.stringify({args:i(),functionPath:n.__lunoraRef,id:s.dedupId,shardKey:s.shardKey}),headers:h,method:"POST",signal:N.signal})}catch(E){return m(E)}if(!u.ok){let E;try{E=await u.text()}catch(M){return m(M)}throw or(t,u,E,s.messageId)}let d;try{d=await u.text()}catch(E){return m(E)}if(d.length===0)return;let A;try{A=JSON.parse(d)}catch{throw new w("INTERNAL",`${t}: function dispatch returned a non-JSON body (${String(u.status)}): ${d}`,{status:u.status})}if(A===null||typeof A!="object"||Array.isArray(A)||!("result"in A))throw new w("INTERNAL",`${t}: function dispatch returned a JSON body that is not a { result } envelope (${String(u.status)}): ${d}`,{status:u.status});return y(A.result)}finally{N.dispose()}}},hr=(r,t)=>`${r}/${t}`,L=(r,t)=>{let o=0;return(a,n,e)=>(o+=1,r(a,n,{...e,dedupId:e?.dedupId??`${t}.${String(o)}`}))},ur=(r,t)=>H(r,t,"step args"),mr=r=>{let t=0;return async(o,a,n)=>{const e=`${r.dedupNamespace}#step${String(t)}`;t+=1;const s=n?.config??o.config,i=n?.name??o.name;if(i.startsWith(T))return R(`@lunora/workflow: ctx.runStep step name "${i}" is reserved — the "${T}" prefix is used by the framework's own steps`,void 0,r.nonRetryableErrorClass);const c=ur(o.args,a),l=async p=>{const N={attempt:p.attempt,config:p.config,env:r.env,log:r.log,run:L(r.run,e),step:p.step};let m;try{m=await o.handler(N,c)}catch(u){return ir(u)?R(u.message,u,r.nonRetryableErrorClass):K(u,r.nonRetryableErrorClass)}if(!o.returns)return m;try{return o.returns.parse(m)}catch(u){const d=u instanceof Error?u.message:String(u);return R(`step "${o.name}" returns validation failed: ${d}`,u,r.nonRetryableErrorClass)}},v=o.rollback,h=v?{rollback:async p=>{await v({args:c,env:r.env,error:p.error,log:r.log,output:p.output,run:L(r.run,`${e}rollback`)})},rollbackConfig:o.rollbackConfig}:void 0;return s===void 0?r.step.do(i,l,h):r.step.do(i,s,l,h)}};export{pr as I,mr as c,hr as d,gr as l,L as p,br as u,ur as v};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lunora/workflow",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.61",
|
|
4
4
|
"description": "Durable workflows for Lunora: defineWorkflow over Cloudflare Workflows, generated WorkflowEntrypoint classes, and the ctx.workflows surface",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cloudflare",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{t as h,p as A,c as I}from"./run-step-IuqYPWKG.mjs";import{LunoraError as R}from"@lunora/errors";import{workflowBindingName as y}from"./defineWorkflow-tKaIifbZ.mjs";import{raiseNonRetryable as k}from"./NonRetryableError-BPu01mU8.mjs";import{createSpawn as T,createParallel as C}from"./MAX_BRANCHES-j59ZUUSu.mjs";import{createWaitForEvent as v}from"./createWaitForEvent-D5Ohn2Pz.mjs";const N=r=>({debug:(n,...t)=>{console.debug(r,n,...t)},error:(n,...t)=>{console.error(r,n,...t)},info:(n,...t)=>{console.info(r,n,...t)},warn:(n,...t)=>{console.warn(r,n,...t)}}),O=r=>{let n="";for(let c=0;c<r.length;c+=32768)n+=String.fromCharCode(...r.subarray(c,c+32768));return btoa(n)},$=r=>{const n=atob(r),t=new Uint8Array(n.length);for(let c=0;c<n.length;c+=1)t[c]=n.codePointAt(c)??0;return t},S="$lunora.wire$",w=64,b=1024,g="__proto__",p={BigInt64Array,BigUint64Array,Float32Array,Float64Array,Int8Array,Int16Array,Int32Array,Uint8Array,Uint8ClampedArray,Uint16Array,Uint32Array},E={Error,EvalError,RangeError,ReferenceError,SyntaxError,TypeError,URIError},s=(r,n=0)=>{if(n>w)throw new RangeError(`wire-codec: value nesting exceeds the ${w}-level limit`);if(r===null||typeof r!="object")return r;if(Array.isArray(r)){if(r[0]===S)switch(r[1]){case"-inf":return-1/0;case"arr":return r[2].map(e=>s(e,n+1));case"bigint":{const e=r[2];if(typeof e!="string"||e.length>b||!/^-?\d+$/.test(e))throw new RangeError(`wire-codec: invalid or over-long bigint (max ${b} digits)`);return BigInt(e)}case"date":{const e=s(r[2],n+1);if(typeof e!="number")throw new TypeError("wire-codec: malformed date — epoch must be a number");return new Date(e)}case"map":{const e=r[2];return new Map(e.map(o=>{if(!Array.isArray(o)||o.length!==2)throw new TypeError("wire-codec: malformed map entry — expected a [key, value] pair");return[s(o[0],n+1),s(o[1],n+1)]}))}case"set":return new Set(r[2].map(e=>s(e,n+1)));case"url":{const e=r[2];if(typeof e!="string")throw new TypeError("wire-codec: malformed url — href must be a string");return new URL(e)}case"error":{const e=r[2],o=r[3];if(typeof e!="string"||typeof o!="string")throw new TypeError("wire-codec: malformed error — name and message must be strings");const l=(Object.hasOwn(E,e)?E[e]:void 0)??Error,i=new l(o);i.name!==e&&Object.defineProperty(i,"name",{configurable:!0,value:e,writable:!0});const d=s(r[4],n+1);if(d===null||typeof d!="object"||Array.isArray(d))throw new TypeError("wire-codec: malformed error — props must be an object");for(const a of Object.keys(d))a===g?Object.defineProperty(i,a,{configurable:!0,enumerable:!0,value:d[a],writable:!0}):i[a]=d[a];return r.length>5&&Object.defineProperty(i,"cause",{configurable:!0,value:s(r[5],n+1),writable:!0}),i}case"bytes":{const e=r[2];if(typeof e!="string")throw new TypeError("wire-codec: malformed bytes — payload must be a base64 string");const o=$(e);if(O(o)!==e)throw new TypeError("wire-codec: malformed bytes — payload must be canonical padded base64");const l=r[3]??"Uint8Array";if(l==="ArrayBuffer")return o.buffer.byteLength===o.byteLength?o.buffer:o.slice().buffer;const i=Object.hasOwn(p,l)?p[l]:void 0;return i?new i(o.slice().buffer):o}case"inf":return 1/0;case"nan":return Number.NaN;case"undefined":return;default:return r.map(e=>s(e,n+1))}return r.map(f=>s(f,n+1))}const t=r,c={};for(const f of Object.keys(t)){const e=s(t[f],n+1);f===g?Object.defineProperty(c,f,{configurable:!0,enumerable:!0,value:e,writable:!0}):c[f]=e}return c},D=r=>{const n=N(`[workflow:${r.exportName}]`),t=h({env:r.env,fetchImpl:r.fetchImpl,label:"@lunora/workflow"}),c=A(t,`${r.event.instanceId}#body`),f=a=>{const u=y(a),m=r.env[u];if(!m||typeof m.create!="function"||typeof m.get!="function")throw new R("INTERNAL",`@lunora/workflow: cannot spawn child workflow "${a}" — no Workflow binding "${u}" on env (is it declared in lunora/workflows.ts?)`);return m};let e=0;const o=a=>{if(a!==void 0)return a;const u=`${r.event.instanceId}-c${String(e)}`;return e+=1,u},l={env:r.env,instanceId:r.event.instanceId,log:n,nextChildId:o,parentBinding:y(r.exportName),resolveBinding:f,step:r.step},d=(()=>{try{return s(r.event.payload)}catch(a){return k(`@lunora/workflow: workflow "${r.exportName}" params could not be decoded — ${a instanceof Error?a.message:String(a)}`,a,r.nonRetryableErrorClass)}})();return{env:r.env,event:r.event,...r.fetchImpl===void 0?{}:{fetchImpl:r.fetchImpl},log:n,parallel:C(l),params:d,run:c,runStep:I({env:r.env,instanceId:r.event.instanceId,log:n,nonRetryableErrorClass:r.nonRetryableErrorClass,run:t,step:r.step}),spawn:T(l),step:r.step,waitForEvent:v({nonRetryableErrorClass:r.nonRetryableErrorClass,step:r.step})}};export{D as createWorkflowRunContext};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{LunoraError as w,isLunoraError as B}from"@lunora/errors";import{parseValidatorMap as M}from"@lunora/values";import{RESERVED_EVENT_TYPE_PREFIX as S}from"./defineWorkflowEvent-suERPEEV.mjs";import{raiseNonRetryable as T,convertNonRetryableError as J}from"./NonRetryableError-BPu01mU8.mjs";const F=(e,t,o)=>{if(t===void 0)return{dispose:()=>{},signal:e};const a=new AbortController,n=setTimeout(()=>{a.abort(o())},t);return{dispose:()=>{clearTimeout(n)},signal:a.signal}},$=e=>{let t="";for(let o=0;o<e.length;o+=32768)t+=String.fromCharCode(...e.subarray(o,o+32768));return btoa(t)},K=e=>{const t=atob(e),o=new Uint8Array(t.length);for(let a=0;a<t.length;a+=1)o[a]=t.codePointAt(a)??0;return o},b="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",k=e=>{let t="",o=0;const a=e.length-2;for(;o<a;o+=3){const r=e[o]<<16|e[o+1]<<8|e[o+2];t+=b.charAt(r>>18&63)+b.charAt(r>>12&63)+b.charAt(r>>6&63)+b.charAt(r&63)}const n=e.length-o;if(n===1){const r=e[o]<<16;t+=b.charAt(r>>18&63)+b.charAt(r>>12&63)}else if(n===2){const r=e[o]<<16|e[o+1]<<8;t+=b.charAt(r>>18&63)+b.charAt(r>>12&63)+b.charAt(r>>6&63)}return t};new TextDecoder;const P=new TextEncoder,I="=",V=e=>{for(let t=0;t<e.length;t+=1)if(e.charCodeAt(t)>255)return!1;return!0},W=e=>k(P.encode(JSON.stringify(e))),H=e=>!e.startsWith(I)&&V(e)?e:`${I}${k(P.encode(e))}`,l="$lunora.wire$",O=64,j=1024,R="__proto__",_={BigInt64Array,BigUint64Array,Float32Array,Float64Array,Int8Array,Int16Array,Int32Array,Uint8Array,Uint8ClampedArray,Uint16Array,Uint32Array},L={Error,EvalError,RangeError,ReferenceError,SyntaxError,TypeError,URIError},G=e=>{if(e===null||typeof e!="object")return!1;const t=Object.getPrototypeOf(e);return t===null||t===Object.prototype},g=(e,t=0)=>{if(t>O)throw new RangeError(`wire-codec: value nesting exceeds the ${O}-level limit`);if(e===void 0)return[l,"undefined"];if(e===null)return null;const o=typeof e;if(o==="bigint")return[l,"bigint",e.toString()];if(o==="number"){const r=e;return Number.isNaN(r)?[l,"nan"]:r===1/0?[l,"inf"]:r===-1/0?[l,"-inf"]:r}if(o!=="object")return e;if(e instanceof Date)return[l,"date",g(e.getTime(),t+1)];if(e instanceof Error){const r=e,s={};for(const c of Object.keys(r)){if(r[c]===void 0)continue;const f=g(r[c],t+1);c===R?Object.defineProperty(s,c,{configurable:!0,enumerable:!0,value:f,writable:!0}):s[c]=f}const i=[l,"error",String(r.name),String(r.message),s];return r.cause!==void 0&&i.push(g(r.cause,t+1)),i}if(e instanceof URL)return[l,"url",e.href];if(e instanceof Map)return[l,"map",[...e.entries()].map(([r,s])=>[g(r,t+1),g(s,t+1)])];if(e instanceof Set)return[l,"set",[...e].map(r=>g(r,t+1))];if(e instanceof ArrayBuffer)return[l,"bytes",$(new Uint8Array(e)),"ArrayBuffer"];if(ArrayBuffer.isView(e)){const r=e,s=r.constructor.name,i=new Uint8Array(r.buffer,r.byteOffset,r.byteLength);return s==="Uint8Array"?[l,"bytes",$(i)]:[l,"bytes",$(i),s]}if(Array.isArray(e)){const r=e.map(s=>g(s,t+1));return r.length>0&&r[0]===l?[l,"arr",r]:r}if(!G(e)){const r=e.constructor?.name??"value";throw new TypeError(`wire-codec: cannot encode a ${r} over the Lunora wire — only plain objects, arrays, and the supported built-ins (Date, Error, URL, Map, Set, ArrayBuffer/typed arrays, bigint) round-trip`)}const a=e,n={};for(const r of Object.keys(a)){const s=a[r];if(s===void 0)continue;const i=g(s,t+1);r===R?Object.defineProperty(n,r,{configurable:!0,enumerable:!0,value:i,writable:!0}):n[r]=i}return n},y=(e,t=0)=>{if(t>O)throw new RangeError(`wire-codec: value nesting exceeds the ${O}-level limit`);if(e===null||typeof e!="object")return e;if(Array.isArray(e)){if(e[0]===l)switch(e[1]){case"-inf":return-1/0;case"arr":return e[2].map(n=>y(n,t+1));case"bigint":{const n=e[2];if(typeof n!="string"||n.length>j||!/^-?\d+$/.test(n))throw new RangeError(`wire-codec: invalid or over-long bigint (max ${j} digits)`);return BigInt(n)}case"date":{const n=y(e[2],t+1);if(typeof n!="number")throw new TypeError("wire-codec: malformed date — epoch must be a number");return new Date(n)}case"map":{const n=e[2];return new Map(n.map(r=>{if(!Array.isArray(r)||r.length!==2)throw new TypeError("wire-codec: malformed map entry — expected a [key, value] pair");return[y(r[0],t+1),y(r[1],t+1)]}))}case"set":return new Set(e[2].map(n=>y(n,t+1)));case"url":{const n=e[2];if(typeof n!="string")throw new TypeError("wire-codec: malformed url — href must be a string");return new URL(n)}case"error":{const n=e[2],r=e[3];if(typeof n!="string"||typeof r!="string")throw new TypeError("wire-codec: malformed error — name and message must be strings");const s=(Object.hasOwn(L,n)?L[n]:void 0)??Error,i=new s(r);i.name!==n&&Object.defineProperty(i,"name",{configurable:!0,value:n,writable:!0});const c=y(e[4],t+1);if(c===null||typeof c!="object"||Array.isArray(c))throw new TypeError("wire-codec: malformed error — props must be an object");for(const f of Object.keys(c))f===R?Object.defineProperty(i,f,{configurable:!0,enumerable:!0,value:c[f],writable:!0}):i[f]=c[f];return e.length>5&&Object.defineProperty(i,"cause",{configurable:!0,value:y(e[5],t+1),writable:!0}),i}case"bytes":{const n=e[2];if(typeof n!="string")throw new TypeError("wire-codec: malformed bytes — payload must be a base64 string");const r=K(n);if($(r)!==n)throw new TypeError("wire-codec: malformed bytes — payload must be canonical padded base64");const s=e[3]??"Uint8Array";if(s==="ArrayBuffer")return r.buffer.byteLength===r.byteLength?r.buffer:r.slice().buffer;const i=Object.hasOwn(_,s)?_[s]:void 0;return i?new i(r.slice().buffer):r}case"inf":return 1/0;case"nan":return Number.NaN;case"undefined":return;default:return e.map(n=>y(n,t+1))}return e.map(n=>y(n,t+1))}const o=e,a={};for(const n of Object.keys(o)){const r=y(o[n],t+1);n===R?Object.defineProperty(a,n,{configurable:!0,enumerable:!0,value:r,writable:!0}):a[n]=r}return a},z=(e,t,o)=>{try{return g(o)}catch(a){throw new TypeError(`${e}: cannot encode args for '${t}' — ${a instanceof Error?a.message:String(a)}`,a instanceof Error?{cause:a}:void 0)}},X="/_lunora/scheduler/dispatch",Y=3e4,q=e=>{let t=e.length;for(;t>0&&e[t-1]==="/";)t-=1;return e.slice(0,t)},x=Symbol("lunoraDispatchFailure"),Q=Symbol("lunoraDispatchMessageId"),D=(e,t)=>(t!==void 0&&Object.defineProperty(e,Q,{value:t}),e),Z=(e,t)=>(Object.defineProperty(e,x,{value:!0}),D(e,t)),ee=(e,t,o,a)=>{try{const n=JSON.parse(o)?.error;if(typeof n=="object"&&n!==null&&typeof n.code=="string"){const{code:r,data:s,message:i}=n;return Z(new w(r,typeof i=="string"?i:void 0,{data:s,status:t}),a)}}catch{}return D(new w("INTERNAL",`${e}: function dispatch failed (${String(t)}): ${o}`,{status:t}),a)},te=new Set([400,403,404,422]),re=new Set(["DISPATCH_UNAUTHENTICATED"]),ne=e=>B(e)&&e[x]===!0&&te.has(e.status)&&!re.has(e.code),oe=(e,t,o)=>new w("INTERNAL",`${e}: function dispatch to "${t}" timed out after ${String(o)}ms`,{status:503}),le=e=>{const{label:t}=e,o=globalThis.fetch,a=e.fetchImpl??(typeof o=="function"?o.bind(globalThis):void 0);return async(n,r,s={})=>{if(typeof a!="function")throw new TypeError(`${t}: no fetch implementation available — pass fetchImpl or run on a platform with global fetch`);const i=()=>e.argsAlreadyEncoded===!0?r??{}:z(t,n.__lunoraRef,r??{}),c=e.env.LUNORA_ORIGIN_URL;if(typeof c!="string"||c.length===0)throw new w("INTERNAL",`${t}: \`LUNORA_ORIGIN_URL\` must be set on the Worker env so a handler can call back into Lunora functions`);const f=e.env.LUNORA_ADMIN_TOKEN;if(typeof f!="string"||f.length===0)throw new w("INTERNAL",`${t}: \`LUNORA_ADMIN_TOKEN\` must be set on the Worker env to authenticate function dispatch`);const v=`${q(c)}${X}`,h={authorization:`Bearer ${f}`,"content-type":"application/json"};e.traceparent!==void 0&&e.traceparent.length>0&&(h.traceparent=e.traceparent),e.identity?.userId!==void 0&&(h["x-lunora-userid"]=H(e.identity.userId)),e.identity?.claims!==void 0&&(h["x-lunora-identity"]=W(e.identity.claims));const p=s.timeoutMs??Y,N=F(void 0,p,()=>new DOMException(`dispatch timed out after ${String(p)}ms`,"TimeoutError")),m=d=>{throw d instanceof Error&&d.name==="TimeoutError"?oe(t,n.__lunoraRef,p):d};let u;try{try{u=await a(v,{body:JSON.stringify({args:i(),functionPath:n.__lunoraRef,id:s.dedupId,shardKey:s.shardKey}),headers:h,method:"POST",signal:N.signal})}catch(E){return m(E)}if(!u.ok){let E;try{E=await u.text()}catch(C){return m(C)}throw ee(t,u.status,E,s.messageId)}let d;try{d=await u.text()}catch(E){return m(E)}if(d.length===0)return;let A;try{A=JSON.parse(d)}catch{throw new w("INTERNAL",`${t}: function dispatch returned a non-JSON body (${String(u.status)}): ${d}`,{status:u.status})}if(A===null||typeof A!="object"||Array.isArray(A)||!("result"in A))throw new w("INTERNAL",`${t}: function dispatch returned a JSON body that is not a { result } envelope (${String(u.status)}): ${d}`,{status:u.status});return y(A.result)}finally{N.dispose()}}},U=(e,t)=>{let o=0;return(a,n,r)=>(o+=1,e(a,n,{...r,dedupId:r?.dedupId??`${t}.${String(o)}`}))},ae=(e,t)=>M(e,t,"step args"),fe=e=>{let t=0;return async(o,a,n)=>{const r=`${e.instanceId}#step${String(t)}`;t+=1;const s=n?.config??o.config,i=n?.name??o.name;if(i.startsWith(S))return T(`@lunora/workflow: ctx.runStep step name "${i}" is reserved — the "${S}" prefix is used by the framework's own steps`,void 0,e.nonRetryableErrorClass);const c=ae(o.args,a),f=async p=>{const N={attempt:p.attempt,config:p.config,env:e.env,log:e.log,run:U(e.run,r),step:p.step};let m;try{m=await o.handler(N,c)}catch(u){return ne(u)?T(u.message,u,e.nonRetryableErrorClass):J(u,e.nonRetryableErrorClass)}if(!o.returns)return m;try{return o.returns.parse(m)}catch(u){const d=u instanceof Error?u.message:String(u);return T(`step "${o.name}" returns validation failed: ${d}`,u,e.nonRetryableErrorClass)}},v=o.rollback,h=v?{rollback:async p=>{await v({args:c,env:e.env,error:p.error,log:e.log,output:p.output,run:U(e.run,`${r}rollback`)})},rollbackConfig:o.rollbackConfig}:void 0;return s===void 0?e.step.do(i,f,h):e.step.do(i,s,f,h)}};export{fe as c,U as p,le as t,ae as v};
|