@lunora/queue 1.0.0-alpha.42 → 1.0.0-alpha.43

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/index.d.mts CHANGED
@@ -139,7 +139,7 @@ interface QueueConsumerTuning {
139
139
  maxBatchSize?: number;
140
140
  /** Max seconds to wait before delivering a partial batch (0–60, default 5). */
141
141
  maxBatchTimeout?: number;
142
- /** Max delivery attempts before a message is dropped / dead-lettered (default 3). */
142
+ /** Retries **after** the initial delivery, before a message is dropped / dead-lettered. Default 3, so up to 4 deliveries in total. */
143
143
  maxRetries?: number;
144
144
  /** Delay in seconds before a failed batch is retried. */
145
145
  retryDelay?: number;
package/dist/index.d.ts CHANGED
@@ -139,7 +139,7 @@ interface QueueConsumerTuning {
139
139
  maxBatchSize?: number;
140
140
  /** Max seconds to wait before delivering a partial batch (0–60, default 5). */
141
141
  maxBatchTimeout?: number;
142
- /** Max delivery attempts before a message is dropped / dead-lettered (default 3). */
142
+ /** Retries **after** the initial delivery, before a message is dropped / dead-lettered. Default 3, so up to 4 deliveries in total. */
143
143
  maxRetries?: number;
144
144
  /** Delay in seconds before a failed batch is retried. */
145
145
  retryDelay?: number;
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- import{createQueueCaptureSink as t,shouldCaptureQueue as r}from"./packem_shared/createQueueCaptureSink-CSOPftvj.mjs";import{createQueueContext as a}from"./packem_shared/createQueueContext-B9PgIzBM.mjs";import{default as i}from"./packem_shared/createQueues-FpKDoLFX.mjs";import{defineQueue as p,isQueueDefinition as m,queueBindingName as x,queueDefaultName as Q}from"./packem_shared/defineQueue-TY4-i3nG.mjs";import{dispatchQueueBatch as s}from"./packem_shared/dispatchQueueBatch-Bug1M0yA.mjs";import{c as C}from"./packem_shared/run-context-Bz18TJFU.mjs";export{t as createQueueCaptureSink,a as createQueueContext,C as createQueueRunContext,i as createQueues,p as defineQueue,s as dispatchQueueBatch,m as isQueueDefinition,x as queueBindingName,Q as queueDefaultName,r as shouldCaptureQueue};
1
+ import{createQueueCaptureSink as t,shouldCaptureQueue as r}from"./packem_shared/createQueueCaptureSink-CSOPftvj.mjs";import{createQueueContext as a}from"./packem_shared/createQueueContext-BszRoc-a.mjs";import{default as i}from"./packem_shared/createQueues-CMitFS1K.mjs";import{defineQueue as p,isQueueDefinition as m,queueBindingName as x,queueDefaultName as Q}from"./packem_shared/defineQueue-TY4-i3nG.mjs";import{dispatchQueueBatch as s}from"./packem_shared/dispatchQueueBatch-CfAjk1IM.mjs";import{c as C}from"./packem_shared/run-context-CCkMyGrO.mjs";export{t as createQueueCaptureSink,a as createQueueContext,C as createQueueRunContext,i as createQueues,p as defineQueue,s as dispatchQueueBatch,m as isQueueDefinition,x as queueBindingName,Q as queueDefaultName,r as shouldCaptureQueue};
@@ -1 +1 @@
1
- import i from"./createQueues-FpKDoLFX.mjs";const s=(o,c)=>{const n={};for(const t of c){const e=o[t.binding];e&&typeof e.send=="function"&&typeof e.sendBatch=="function"&&(n[t.exportName]=e)}return i({bindings:n})};export{s as createQueueContext};
1
+ import i from"./createQueues-CMitFS1K.mjs";const s=(o,c)=>{const n={};for(const t of c){const e=o[t.binding];e&&typeof e.send=="function"&&typeof e.sendBatch=="function"&&(n[t.exportName]=e)}return i({bindings:n})};export{s as createQueueContext};
@@ -0,0 +1 @@
1
+ import{c as o}from"./run-context-CCkMyGrO.mjs";export{o as createQueueRunContext};
@@ -0,0 +1 @@
1
+ import{LunoraError as l}from"@lunora/errors";const d=100,i=43200,u=(n,t)=>{if(n!==void 0&&n>i)throw new l("VALIDATION_ERROR",`@lunora/queue: ${t} delaySeconds is ${String(n)}, over the Cloudflare Queues ceiling of ${String(i)} (12 hours) — use @lunora/scheduler for longer schedules`)},g=n=>({send:async(t,e)=>{u(e?.delaySeconds,"send"),await n.send(t,e)},sendBatch:async(t,e)=>{u(e?.delaySeconds,"sendBatch");const o=[...t];if(o.length>d)throw new l("VALIDATION_ERROR",`@lunora/queue: sendBatch exceeds ${String(d)} (got ${String(o.length)}) — split across calls`);for(const[c,s]of o.entries())u(s.delaySeconds,`sendBatch message ${String(c)}`);await n.sendBatch(o,e)}}),f=n=>{const t=n.bindings??{},e=Object.create(null);for(const[s,r]of Object.entries(t))e[s]=g(r);const o=Object.keys(e),c=s=>{const r=o.length===0?"no queues are declared":`known queues: ${o.join(", ")}`,a=()=>Promise.reject(new Error(`@lunora/queue: no queue named "${s}" (${r})`));return{send:a,sendBatch:a}};return new Proxy(e,{get(s,r){if(typeof r=="string")return Object.hasOwn(s,r)?s[r]:c(r)}})};export{f as default};
@@ -1 +1 @@
1
- import{c as w,B as h,M as y}from"./run-context-Bz18TJFU.mjs";import{LunoraError as v,toErrorBody as x}from"@lunora/errors";const g=3,q=e=>{if(e instanceof Date)return e.getTime();const t=typeof e=="number"?e:Number(e);return Number.isFinite(t)?t:0},b=(e,t)=>{let r=0;return(n,i,o)=>(r+=1,e(n,i,{...o,dedupId:`${t}#${String(r)}`,messageId:t}))},k=(e,t,r)=>{const n=b(r,e.id);return new Proxy(e,{get:(i,o)=>o==="ack"?()=>{t.set(i,"ack"),i.ack()}:o==="retry"?u=>{t.set(i,"retry"),i.retry(u)}:o==="run"?n:Reflect.get(i,o,i)})},N=(e,t,r)=>new Proxy(e,{get:(n,i)=>i==="ackAll"?()=>{r("ack"),n.ackAll()}:i==="retryAll"?o=>{r("retry"),n.retryAll(o)}:i==="messages"?t:Reflect.get(n,i,n)}),$=(e,t)=>{const r=new Map,n=e.messages,i=n.map(c=>k(c,r,t)),u=N(e,i,c=>{for(const a of n)r.has(a)||r.set(a,c)});return{dispositions:r,originals:n,wrappedBatch:u}},R=e=>{if(e instanceof Error)return e.message;if(typeof e=="string")return e;if(e!==null&&typeof e=="object")try{return JSON.stringify(e)}catch{return"[unserializable thrown value]"}return String(e)},A=(e,t,r,n,i,o)=>{const u=n?R(i):void 0,c=typeof t.definition.maxRetries=="number"?t.definition.maxRetries:g,a=n?"error":"ack",f=typeof t.definition.deadLetterQueue=="string"&&t.definition.deadLetterQueue.length>0;return e.originals.map(d=>{const s=d===o,l=e.dispositions.get(d),p=s?"error":l??a,m=typeof d.attempts=="number"?d.attempts:1;return{attempts:m,body:d.body,deadLettered:f&&!s&&p!=="ack"&&m>c,error:p==="error"?u:void 0,exportName:t.exportName,messageId:d.id,outcome:p,queue:r,timestamp:q(d.timestamp)}})},M=(e,t,r)=>{if(!t||!h(r))return;const n=y(r);if(n===void 0)return;const i=e.originals.find(o=>o.id===n);if(!(i===void 0||e.dispositions.has(i)))return i},T=(e,t)=>{t.ack();for(const r of e.originals)r!==t&&!e.dispositions.has(r)&&(e.dispositions.set(r,"retry"),r.retry())},L=async(e,t,r)=>{const n=Object.hasOwn(t,e.queue)?t[e.queue]:void 0;if(n===void 0){const s=Object.keys(t),l=s.length===0?"no push queues are declared":`known push queues: ${s.join(", ")}`;throw new v("INTERNAL",`@lunora/queue: received a batch for queue "${e.queue}" but no push handler is registered (${l})`)}const{handler:i}=n.definition;if(typeof i!="function")throw new TypeError(`@lunora/queue: queue "${e.queue}" (${n.exportName}) has no push handler — it is declared as a pull consumer`);const o=w({env:r.env,exportName:n.exportName,fetchImpl:r.fetchImpl}),u=$(e,o.run);let c=!1,a;try{await i(o,u.wrappedBatch)}catch(s){c=!0,a=s}const f=M(u,c,a);if(f!==void 0){T(u,f);const{body:s,status:l}=x(a,{redactedMessage:"internal error"});console.error(`@lunora/queue: dropped message ${f.id} on queue "${e.queue}" (${n.exportName}) — a dispatch it made failed with a deterministic ${String(l)} (${s.code}: ${s.message}), so it was acked, not retried. Its retries are NOT exhausted and it is not dead-lettered — it will never be redelivered.`)}const d=c&&f===void 0;if(r.capture!==void 0)try{await r.capture(A(u,n,e.queue,c,a,f))}catch(s){console.warn("@lunora/queue: capture sink failed (delivery unaffected):",s)}if(d)throw a};export{L as dispatchQueueBatch};
1
+ import{c as w,k as h,B as y}from"./run-context-CCkMyGrO.mjs";import{LunoraError as v,toErrorBody as x}from"@lunora/errors";const g=3,k=e=>{if(e instanceof Date)return e.getTime();const t=typeof e=="number"?e:Number(e);return Number.isFinite(t)?t:0},q=(e,t)=>{let r=0;return(n,i,o)=>(r+=1,e(n,i,{...o,dedupId:`${t}#${String(r)}`,messageId:t}))},b=(e,t,r)=>{const n=q(r,e.id);return new Proxy(e,{get:(i,o)=>o==="ack"?()=>{t.set(i,"ack"),i.ack()}:o==="retry"?u=>{t.set(i,"retry"),i.retry(u)}:o==="run"?n:Reflect.get(i,o,i)})},N=(e,t,r)=>new Proxy(e,{get:(n,i)=>i==="ackAll"?()=>{r("ack"),n.ackAll()}:i==="retryAll"?o=>{r("retry"),n.retryAll(o)}:i==="messages"?t:Reflect.get(n,i,n)}),$=(e,t)=>{const r=new Map,n=e.messages,i=n.map(c=>b(c,r,t)),u=N(e,i,c=>{for(const a of n)r.has(a)||r.set(a,c)});return{dispositions:r,originals:n,wrappedBatch:u}},R=e=>{if(e instanceof Error)return e.message;if(typeof e=="string")return e;if(e!==null&&typeof e=="object")try{return JSON.stringify(e)}catch{return"[unserializable thrown value]"}return String(e)},A=(e,t,r,n,i,o)=>{const u=n?R(i):void 0,c=typeof t.definition.maxRetries=="number"?t.definition.maxRetries:g,a=n?"error":"ack",f=typeof t.definition.deadLetterQueue=="string"&&t.definition.deadLetterQueue.length>0;return e.originals.map(d=>{const s=d===o,l=e.dispositions.get(d),p=s?"error":l??a,m=typeof d.attempts=="number"?d.attempts:1;return{attempts:m,body:d.body,deadLettered:f&&!s&&p!=="ack"&&m>c,error:p==="error"?u:void 0,exportName:t.exportName,messageId:d.id,outcome:p,queue:r,timestamp:k(d.timestamp)}})},M=(e,t,r)=>{if(!t||!h(r))return;const n=y(r);if(n===void 0)return;const i=e.originals.find(o=>o.id===n);if(!(i===void 0||e.dispositions.has(i)))return i},T=(e,t)=>{t.ack();for(const r of e.originals)r!==t&&!e.dispositions.has(r)&&(e.dispositions.set(r,"retry"),r.retry())},L=async(e,t,r)=>{const n=Object.hasOwn(t,e.queue)?t[e.queue]:void 0;if(n===void 0){const s=Object.keys(t),l=s.length===0?"no push queues are declared":`known push queues: ${s.join(", ")}`;throw new v("INTERNAL",`@lunora/queue: received a batch for queue "${e.queue}" but no push handler is registered (${l})`)}const{handler:i}=n.definition;if(typeof i!="function")throw new TypeError(`@lunora/queue: queue "${e.queue}" (${n.exportName}) has no push handler — it is declared as a pull consumer`);const o=w({env:r.env,exportName:n.exportName,fetchImpl:r.fetchImpl}),u=$(e,o.run);let c=!1,a;try{await i(o,u.wrappedBatch)}catch(s){c=!0,a=s}const f=M(u,c,a);if(f!==void 0){T(u,f);const{body:s,status:l}=x(a,{redactedMessage:"internal error"});console.error(`@lunora/queue: dropped message ${f.id} on queue "${e.queue}" (${n.exportName}) — a dispatch it made failed with a deterministic ${String(l)} (${s.code}: ${s.message}), so it was acked, not retried. Its retries are NOT exhausted and it is not dead-lettered — it will never be redelivered.`)}const d=c&&f===void 0;if(r.capture!==void 0)try{await r.capture(A(u,n,e.queue,c,a,f))}catch(s){console.warn("@lunora/queue: capture sink failed (delivery unaffected):",s)}if(d)throw a};export{L as dispatchQueueBatch};
@@ -0,0 +1 @@
1
+ import{LunoraError as d,isLunoraError as w}from"@lunora/errors";const O=t=>({debug:(e,...n)=>{console.debug(t,e,...n)},error:(e,...n)=>{console.error(t,e,...n)},info:(e,...n)=>{console.info(t,e,...n)},warn:(e,...n)=>{console.warn(t,e,...n)}}),R=(t,e,n)=>{if(e===void 0)return{dispose:()=>{},signal:t};const s=new AbortController,o=setTimeout(()=>{s.abort(n())},e);return{dispose:()=>{clearTimeout(o)},signal:s.signal}},a="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",A=t=>{let e="",n=0;const s=t.length-2;for(;n<s;n+=3){const r=t[n]<<16|t[n+1]<<8|t[n+2];e+=a.charAt(r>>18&63)+a.charAt(r>>12&63)+a.charAt(r>>6&63)+a.charAt(r&63)}const o=t.length-n;if(o===1){const r=t[n]<<16;e+=a.charAt(r>>18&63)+a.charAt(r>>12&63)}else if(o===2){const r=t[n]<<16|t[n+1]<<8;e+=a.charAt(r>>18&63)+a.charAt(r>>12&63)+a.charAt(r>>6&63)}return e};new TextDecoder;const I=new TextEncoder,N="=",S=t=>{for(let e=0;e<t.length;e+=1)if(t.charCodeAt(e)>255)return!1;return!0},L=t=>A(I.encode(JSON.stringify(t))),_=t=>!t.startsWith(N)&&S(t)?t:`${N}${A(I.encode(t))}`,x="/_lunora/scheduler/dispatch",D=3e4,U=t=>{let e=t.length;for(;e>0&&t[e-1]==="/";)e-=1;return t.slice(0,e)},b=Symbol("lunoraDispatchFailure"),T=Symbol("lunoraDispatchMessageId"),v=(t,e)=>(e!==void 0&&Object.defineProperty(t,T,{value:e}),t),C=(t,e)=>(Object.defineProperty(t,b,{value:!0}),v(t,e)),H=t=>w(t)?t[T]:void 0,J=(t,e,n,s)=>{try{const o=JSON.parse(n)?.error;if(typeof o=="object"&&o!==null&&typeof o.code=="string"){const{code:r,data:u,message:l}=o;return C(new d(r,typeof l=="string"?l:void 0,{data:u,status:e}),s)}}catch{}return v(new d("INTERNAL",`${t}: function dispatch failed (${String(e)}): ${n}`,{status:e}),s)},M=new Set([400,403,404,422]),P=new Set(["DISPATCH_UNAUTHENTICATED"]),W=t=>w(t)&&t[b]===!0&&M.has(t.status)&&!P.has(t.code),k=(t,e,n)=>new d("INTERNAL",`${t}: function dispatch to "${e}" timed out after ${String(n)}ms`,{status:503}),j=t=>{const{label:e}=t,n=globalThis.fetch,s=t.fetchImpl??(typeof n=="function"?n.bind(globalThis):void 0);return async(o,r,u={})=>{if(typeof s!="function")throw new TypeError(`${e}: no fetch implementation available — pass fetchImpl or run on a platform with global fetch`);const l=t.env.LUNORA_ORIGIN_URL;if(typeof l!="string"||l.length===0)throw new d("INTERNAL",`${e}: \`LUNORA_ORIGIN_URL\` must be set on the Worker env so a handler can call back into Lunora functions`);const f=t.env.LUNORA_ADMIN_TOKEN;if(typeof f!="string"||f.length===0)throw new d("INTERNAL",`${e}: \`LUNORA_ADMIN_TOKEN\` must be set on the Worker env to authenticate function dispatch`);const $=`${U(l)}${x}`,p={authorization:`Bearer ${f}`,"content-type":"application/json"};t.identity?.userId!==void 0&&(p["x-lunora-userid"]=_(t.identity.userId)),t.identity?.claims!==void 0&&(p["x-lunora-identity"]=L(t.identity.claims));const y=u.timeoutMs??D,m=R(void 0,y,()=>new DOMException(`dispatch timed out after ${String(y)}ms`,"TimeoutError")),g=c=>{throw c instanceof Error&&c.name==="TimeoutError"?k(e,o.__lunoraRef,y):c};let i;try{try{i=await s($,{body:JSON.stringify({args:r??{},functionPath:o.__lunoraRef,id:u.dedupId,shardKey:u.shardKey}),headers:p,method:"POST",signal:m.signal})}catch(h){return g(h)}if(!i.ok){let h;try{h=await i.text()}catch(E){return g(E)}throw J(e,i.status,h,u.messageId)}let c;try{c=await i.text()}catch(h){return g(h)}if(c.length===0)return;try{return JSON.parse(c)}catch{throw new d("INTERNAL",`${e}: function dispatch returned a non-JSON body (${String(i.status)}): ${c}`,{status:i.status})}}finally{m.dispose()}}},q=t=>({env:t.env,log:O(`[queue:${t.exportName}]`),run:j({env:t.env,fetchImpl:t.fetchImpl,label:"@lunora/queue"})});export{H as B,q as c,W as k};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lunora/queue",
3
- "version": "1.0.0-alpha.42",
3
+ "version": "1.0.0-alpha.43",
4
4
  "description": "Cloudflare Queues for Lunora: defineQueue producers + consumers, the ctx.queues surface, and the generated queue() worker handler",
5
5
  "keywords": [
6
6
  "background-jobs",
@@ -44,8 +44,8 @@
44
44
  "access": "public"
45
45
  },
46
46
  "dependencies": {
47
- "@lunora/errors": "1.0.0-alpha.29",
48
- "@lunora/platform": "1.0.0-alpha.24"
47
+ "@lunora/errors": "1.0.0-alpha.30",
48
+ "@lunora/platform": "1.0.0-alpha.25"
49
49
  },
50
50
  "engines": {
51
51
  "node": "^22.15.0 || >=24.11.0"
@@ -1 +0,0 @@
1
- import{c as o}from"./run-context-Bz18TJFU.mjs";export{o as createQueueRunContext};
@@ -1 +0,0 @@
1
- import{LunoraError as i}from"@lunora/errors";const u=100,d=o=>({send:async(r,n)=>{await o.send(r,n)},sendBatch:async(r,n)=>{const t=[...r];if(t.length>u)throw new i("VALIDATION_ERROR",`@lunora/queue: sendBatch exceeds ${String(u)} (got ${String(t.length)}) — split across calls`);await o.sendBatch(t,n)}}),g=o=>{const r=o.bindings??{},n=Object.create(null);for(const[s,e]of Object.entries(r))n[s]=d(e);const t=Object.keys(n),a=s=>{const e=t.length===0?"no queues are declared":`known queues: ${t.join(", ")}`,c=()=>Promise.reject(new Error(`@lunora/queue: no queue named "${s}" (${e})`));return{send:c,sendBatch:c}};return new Proxy(n,{get(s,e){if(typeof e=="string")return Object.hasOwn(s,e)?s[e]:a(e)}})};export{g as default};
@@ -1 +0,0 @@
1
- import{LunoraError as d,isLunoraError as A}from"@lunora/errors";const R=t=>({debug:(e,...n)=>{console.debug(t,e,...n)},error:(e,...n)=>{console.error(t,e,...n)},info:(e,...n)=>{console.info(t,e,...n)},warn:(e,...n)=>{console.warn(t,e,...n)}}),E=(t,e,n)=>{if(e===void 0)return{dispose:()=>{},signal:t};const s=new AbortController,o=setTimeout(()=>{s.abort(n())},e);return{dispose:()=>{clearTimeout(o)},signal:s.signal}},a="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",b=t=>{let e="",n=0;const s=t.length-2;for(;n<s;n+=3){const r=t[n]<<16|t[n+1]<<8|t[n+2];e+=a.charAt(r>>18&63)+a.charAt(r>>12&63)+a.charAt(r>>6&63)+a.charAt(r&63)}const o=t.length-n;if(o===1){const r=t[n]<<16;e+=a.charAt(r>>18&63)+a.charAt(r>>12&63)}else if(o===2){const r=t[n]<<16|t[n+1]<<8;e+=a.charAt(r>>18&63)+a.charAt(r>>12&63)+a.charAt(r>>6&63)}return e};new TextDecoder;const I=new TextEncoder,N="=",L=t=>{for(let e=0;e<t.length;e+=1)if(t.charCodeAt(e)>255)return!1;return!0},_=t=>b(I.encode(JSON.stringify(t))),S=t=>!t.startsWith(N)&&L(t)?t:`${N}${b(I.encode(t))}`,x="/_lunora/scheduler/dispatch",D=3e4,U=t=>{let e=t.length;for(;e>0&&t[e-1]==="/";)e-=1;return t.slice(0,e)},v=Symbol("lunoraDispatchFailure"),$=Symbol("lunoraDispatchMessageId"),w=(t,e)=>(Object.defineProperty(t,v,{value:!0}),e!==void 0&&Object.defineProperty(t,$,{value:e}),t),C=t=>A(t)?t[$]:void 0,M=(t,e,n,s)=>{try{const o=JSON.parse(n)?.error;if(typeof o=="object"&&o!==null&&typeof o.code=="string"){const{code:r,data:u,message:l}=o;return w(new d(r,typeof l=="string"?l:void 0,{data:u,status:e}),s)}}catch{}return w(new d("INTERNAL",`${t}: function dispatch failed (${String(e)}): ${n}`,{status:e}),s)},J=new Set([400,403,404,422]),K=t=>A(t)&&t[v]===!0&&J.has(t.status),P=(t,e,n)=>new d("INTERNAL",`${t}: function dispatch to "${e}" timed out after ${String(n)}ms`,{status:503}),j=t=>{const{label:e}=t,n=globalThis.fetch,s=t.fetchImpl??(typeof n=="function"?n.bind(globalThis):void 0);return async(o,r,u={})=>{if(typeof s!="function")throw new TypeError(`${e}: no fetch implementation available — pass fetchImpl or run on a platform with global fetch`);const l=t.env.LUNORA_ORIGIN_URL;if(typeof l!="string"||l.length===0)throw new d("INTERNAL",`${e}: \`LUNORA_ORIGIN_URL\` must be set on the Worker env so a handler can call back into Lunora functions`);const f=t.env.LUNORA_ADMIN_TOKEN;if(typeof f!="string"||f.length===0)throw new d("INTERNAL",`${e}: \`LUNORA_ADMIN_TOKEN\` must be set on the Worker env to authenticate function dispatch`);const O=`${U(l)}${x}`,p={authorization:`Bearer ${f}`,"content-type":"application/json"};t.identity?.userId!==void 0&&(p["x-lunora-userid"]=S(t.identity.userId)),t.identity?.claims!==void 0&&(p["x-lunora-identity"]=_(t.identity.claims));const g=u.timeoutMs??D,m=E(void 0,g,()=>new DOMException(`dispatch timed out after ${String(g)}ms`,"TimeoutError")),y=c=>{throw c instanceof Error&&c.name==="TimeoutError"?P(e,o.__lunoraRef,g):c};let i;try{try{i=await s(O,{body:JSON.stringify({args:r??{},functionPath:o.__lunoraRef,id:u.dedupId,shardKey:u.shardKey}),headers:p,method:"POST",signal:m.signal})}catch(h){return y(h)}if(!i.ok){let h;try{h=await i.text()}catch(T){return y(T)}throw M(e,i.status,h,u.messageId)}let c;try{c=await i.text()}catch(h){return y(h)}if(c.length===0)return;try{return JSON.parse(c)}catch{throw new d("INTERNAL",`${e}: function dispatch returned a non-JSON body (${String(i.status)}): ${c}`,{status:i.status})}}finally{m.dispose()}}},W=t=>({env:t.env,log:R(`[queue:${t.exportName}]`),run:j({env:t.env,fetchImpl:t.fetchImpl,label:"@lunora/queue"})});export{K as B,C as M,W as c};