@lunora/queue 1.0.0-alpha.26 → 1.0.0-alpha.28
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 +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.mjs +1 -1
- package/dist/packem_shared/createQueueCaptureSink-D8pUrrb_.mjs +1 -0
- package/dist/packem_shared/createQueueContext-B9PgIzBM.mjs +1 -0
- package/dist/packem_shared/createQueueRunContext-D3rlzWUO.mjs +1 -0
- package/dist/packem_shared/createQueues-FpKDoLFX.mjs +1 -0
- package/dist/packem_shared/{defineQueue-DJYVNfQY.mjs → defineQueue-TY4-i3nG.mjs} +1 -1
- package/dist/packem_shared/dispatchQueueBatch-CGI3kDNW.mjs +1 -0
- package/package.json +3 -3
- package/dist/packem_shared/createQueueCaptureSink-saac8Ywl.mjs +0 -1
- package/dist/packem_shared/createQueueContext-D7m3HzzL.mjs +0 -1
- package/dist/packem_shared/createQueueRunContext-Dg_fCCaC.mjs +0 -1
- package/dist/packem_shared/createQueues-lUaHm_Qo.mjs +0 -1
- package/dist/packem_shared/dispatchQueueBatch-BYb3OFCX.mjs +0 -1
package/dist/index.d.mts
CHANGED
|
@@ -16,6 +16,8 @@ type ArgsOf<F> = F extends FunctionReference ? Record<string, unknown> : never;
|
|
|
16
16
|
interface RunFunctionOptions {
|
|
17
17
|
/** Route the call to a specific shard (defaults to the worker's root shard). */
|
|
18
18
|
shardKey?: string;
|
|
19
|
+
/** Abort the dispatch after this many ms; the abort is retryable. Overrides the runner's default. */
|
|
20
|
+
timeoutMs?: number;
|
|
19
21
|
}
|
|
20
22
|
/** Invoke a Lunora function (query/mutation/action) by reference. The shape of `ctx.run`. */
|
|
21
23
|
type DispatchRunFunction = <F extends FunctionReference>(function_: F, args?: ArgsOf<F>, options?: RunFunctionOptions) => Promise<unknown>;
|
package/dist/index.d.ts
CHANGED
|
@@ -16,6 +16,8 @@ type ArgsOf<F> = F extends FunctionReference ? Record<string, unknown> : never;
|
|
|
16
16
|
interface RunFunctionOptions {
|
|
17
17
|
/** Route the call to a specific shard (defaults to the worker's root shard). */
|
|
18
18
|
shardKey?: string;
|
|
19
|
+
/** Abort the dispatch after this many ms; the abort is retryable. Overrides the runner's default. */
|
|
20
|
+
timeoutMs?: number;
|
|
19
21
|
}
|
|
20
22
|
/** Invoke a Lunora function (query/mutation/action) by reference. The shape of `ctx.run`. */
|
|
21
23
|
type DispatchRunFunction = <F extends FunctionReference>(function_: F, args?: ArgsOf<F>, options?: RunFunctionOptions) => Promise<unknown>;
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createQueueCaptureSink as t,shouldCaptureQueue as r}from"./packem_shared/createQueueCaptureSink-
|
|
1
|
+
import{createQueueCaptureSink as t,shouldCaptureQueue as r}from"./packem_shared/createQueueCaptureSink-D8pUrrb_.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 d}from"./packem_shared/dispatchQueueBatch-CGI3kDNW.mjs";import{createQueueRunContext as C}from"./packem_shared/createQueueRunContext-D3rlzWUO.mjs";export{t as createQueueCaptureSink,a as createQueueContext,C as createQueueRunContext,i as createQueues,p as defineQueue,d as dispatchQueueBatch,m as isQueueDefinition,x as queueBindingName,Q as queueDefaultName,r as shouldCaptureQueue};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{LunoraError as _}from"@lunora/errors";const l="__lunora_admin__:recordQueueMessage",N="__root__",p=/^(?:dev(?:elopment)?|local(?:host)?|test)$/iu,T=["CF_ENV","ENVIRONMENT","NODE_ENV","WORKER_ENV"],f=5e3,O=o=>{const t=o.LUNORA_QUEUE_CAPTURE;return typeof t=="string"?t==="1"||t.toLowerCase()==="true":T.some(i=>{const e=o[i];return typeof e=="string"&&p.test(e)})},R=(o,t={})=>{const i=t.rootShard??N;return async e=>{if(e.length===0)return;const n=o.SHARD,s=typeof o.LUNORA_ADMIN_TOKEN=="string"?o.LUNORA_ADMIN_TOKEN:void 0;if(n===void 0||s===void 0)return;let a=n;if(t.jurisdiction!==void 0){if(typeof n.jurisdiction!="function")throw new TypeError(`@lunora/queue: Durable Object namespace does not support jurisdiction("${t.jurisdiction}") — update @cloudflare/workers-types or remove the jurisdiction option`);a=n.jurisdiction(t.jurisdiction)}const d=a.get(a.idFromName(i)),u=new AbortController,E=setTimeout(()=>{u.abort()},f);try{const r=await d.fetch("https://shard.internal/rpc",{body:JSON.stringify({args:{messages:e},functionPath:l}),headers:{authorization:`Bearer ${s}`,"content-type":"application/json"},method:"POST",signal:u.signal});if(!r.ok){const c=await r.text().catch(()=>"");throw new _("INTERNAL",`@lunora/queue: capture write to the root shard failed (${String(r.status)} ${r.statusText})${c===""?"":`: ${c}`}`)}await r.body?.cancel()}finally{clearTimeout(E)}}};export{R as createQueueCaptureSink,O as shouldCaptureQueue};
|
|
@@ -0,0 +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};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{LunoraError as c}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)}}),A=t=>{let e="";for(let n=0;n<t.length;n+=32768)e+=String.fromCharCode(...t.subarray(n,n+32768));return btoa(e)},m=t=>A(t).replaceAll("+","-").replaceAll("/","_").replace(/=+$/,"");new TextDecoder;const w=new TextEncoder,g="=",O=t=>{for(let e=0;e<t.length;e+=1)if(t.charCodeAt(e)>255)return!1;return!0},v=t=>m(w.encode(JSON.stringify(t))),T=t=>!t.startsWith(g)&&O(t)?t:`${g}${m(w.encode(t))}`,L="/_lunora/scheduler/dispatch",_=3e4,E=t=>{let e=t.length;for(;e>0&&t[e-1]==="/";)e-=1;return t.slice(0,e)},S=Symbol("lunoraDispatchFailure"),N=t=>(Object.defineProperty(t,S,{value:!0}),t),x=(t,e,n)=>{try{const o=JSON.parse(n)?.error;if(typeof o=="object"&&o!==null&&typeof o.code=="string"){const{code:i,data:u,message:s}=o;return N(new c(i,typeof s=="string"?s:void 0,{data:u,status:e}))}}catch{}return N(new c("INTERNAL",`${t}: function dispatch failed (${String(e)}): ${n}`,{status:e}))},U=(t,e,n)=>new c("INTERNAL",`${t}: function dispatch to "${e}" timed out after ${String(n)}ms`,{status:503}),C=t=>{const{label:e}=t,n=globalThis.fetch,o=t.fetchImpl??(typeof n=="function"?n.bind(globalThis):void 0);return async(i,u,s={})=>{if(typeof o!="function")throw new TypeError(`${e}: no fetch implementation available — pass fetchImpl or run on a platform with global fetch`);const h=t.env.LUNORA_ORIGIN_URL;if(typeof h!="string"||h.length===0)throw new c("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 c("INTERNAL",`${e}: \`LUNORA_ADMIN_TOKEN\` must be set on the Worker env to authenticate function dispatch`);const b=`${E(h)}${L}`,d={authorization:`Bearer ${f}`,"content-type":"application/json"};t.identity?.userId!==void 0&&(d["x-lunora-userid"]=T(t.identity.userId)),t.identity?.claims!==void 0&&(d["x-lunora-identity"]=v(t.identity.claims));const y=s.timeoutMs??_,$=AbortSignal.timeout(y),p=r=>{throw r instanceof Error&&r.name==="TimeoutError"?U(e,i.__lunoraRef,y):r};let a;try{a=await o(b,{body:JSON.stringify({args:u??{},functionPath:i.__lunoraRef,shardKey:s.shardKey}),headers:d,method:"POST",signal:$})}catch(r){return p(r)}if(!a.ok){let r;try{r=await a.text()}catch(I){return p(I)}throw x(e,a.status,r)}let l;try{l=await a.text()}catch(r){return p(r)}if(l.length!==0)try{return JSON.parse(l)}catch{throw new c("INTERNAL",`${e}: function dispatch returned a non-JSON body (${String(a.status)}): ${l}`,{status:a.status})}}},J=t=>({env:t.env,log:R(`[queue:${t.exportName}]`),run:C({env:t.env,fetchImpl:t.fetchImpl,label:"@lunora/queue"})});export{J as createQueueRunContext};
|
|
@@ -0,0 +1 @@
|
|
|
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 +1 @@
|
|
|
1
|
-
const n=e=>`QUEUE_${e.replaceAll(/(?<=[a-z0-9])(?=[A-Z])/g,"_").toUpperCase()}`,
|
|
1
|
+
const n=e=>`QUEUE_${e.replaceAll(/(?<=[a-z0-9])(?=[A-Z])/g,"_").toUpperCase()}`,t=e=>e.replaceAll(/(?<=[a-z0-9])(?=[A-Z])/g,"-").toLowerCase(),o=e=>{const u=e.mode??"push";if(u!=="push"&&u!=="pull")throw new TypeError(`defineQueue: \`mode\` must be "push" or "pull" (got ${JSON.stringify(e.mode)})`);if(u==="push"&&typeof e.handler!="function")throw new TypeError('defineQueue: `handler` must be a function for a push consumer (omit it only when `mode: "pull"`)');if(e.name!==void 0&&(typeof e.name!="string"||e.name.length===0))throw new TypeError("defineQueue: `name` must be a non-empty string when provided");return{...e,isLunoraQueue:!0,mode:u}},r=e=>typeof e=="object"&&e!==null&&e.isLunoraQueue===!0;export{o as defineQueue,r as isQueueDefinition,n as queueBindingName,t as queueDefaultName};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{LunoraError as d}from"@lunora/errors";import{createQueueRunContext as m}from"./createQueueRunContext-D3rlzWUO.mjs";const p=3,l=e=>{if(e instanceof Date)return e.getTime();const t=typeof e=="number"?e:Number(e);return Number.isFinite(t)?t:0},w=(e,t)=>new Proxy(e,{get:(r,n)=>n==="ack"?()=>{t.set(r,"ack"),r.ack()}:n==="retry"?o=>{t.set(r,"retry"),r.retry(o)}:Reflect.get(r,n,r)}),y=(e,t,r)=>new Proxy(e,{get:(n,o)=>o==="ackAll"?()=>{r("ack"),n.ackAll()}:o==="retryAll"?i=>{r("retry"),n.retryAll(i)}:o==="messages"?t:Reflect.get(n,o,n)}),h=e=>{const t=new Map,r=e.messages,n=r.map(c=>w(c,t)),i=y(e,n,c=>{for(const s of r)t.has(s)||t.set(s,c)});return{dispositions:t,originals:r,wrappedBatch:i}},x=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)},k=(e,t,r,n,o)=>{const i=n?x(o):void 0,c=typeof t.definition.maxRetries=="number"?t.definition.maxRetries:p;return e.originals.map(s=>{const u=e.dispositions.get(s)??(n?"error":"ack"),f=typeof s.attempts=="number"?s.attempts:1;return{attempts:f,body:s.body,deadLettered:u!=="ack"&&f>c,error:u==="error"?i:void 0,exportName:t.exportName,messageId:s.id,outcome:u,queue:r,timestamp:l(s.timestamp)}})},R=async(e,t,r)=>{const n=Object.hasOwn(t,e.queue)?t[e.queue]:void 0;if(n===void 0){const u=Object.keys(t),f=u.length===0?"no push queues are declared":`known push queues: ${u.join(", ")}`;throw new d("INTERNAL",`@lunora/queue: received a batch for queue "${e.queue}" but no push handler is registered (${f})`)}const{handler:o}=n.definition;if(typeof o!="function")throw new TypeError(`@lunora/queue: queue "${e.queue}" (${n.exportName}) has no push handler — it is declared as a pull consumer`);const i=m({env:r.env,exportName:n.exportName,fetchImpl:r.fetchImpl});if(r.capture===void 0){await o(i,e);return}const c=h(e);let s=!1,a;try{await o(i,c.wrappedBatch)}catch(u){s=!0,a=u}try{const u=k(c,n,e.queue,s,a);await r.capture(u)}catch(u){console.warn("@lunora/queue: capture sink failed (delivery unaffected):",u)}if(s)throw a};export{R as dispatchQueueBatch};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lunora/queue",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.28",
|
|
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.
|
|
48
|
-
"@lunora/platform": "1.0.0-alpha.
|
|
47
|
+
"@lunora/errors": "1.0.0-alpha.22",
|
|
48
|
+
"@lunora/platform": "1.0.0-alpha.12"
|
|
49
49
|
},
|
|
50
50
|
"engines": {
|
|
51
51
|
"node": "^22.15.0 || >=24.11.0"
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{LunoraError as p}from"@lunora/errors";const N="__lunora_admin__:recordQueueMessage",_="__root__",f=/^(?:dev(?:elopment)?|local(?:host)?|test)$/iu,h=["CF_ENV","ENVIRONMENT","NODE_ENV","WORKER_ENV"],E=5e3,y=e=>{const t=e.LUNORA_QUEUE_CAPTURE;return typeof t=="string"?t==="1"||t.toLowerCase()==="true":h.some(n=>{const o=e[n];return typeof o=="string"&&f.test(o)})},g=(e,t={})=>{const n=t.rootShard??_;return async o=>{if(o.length===0)return;const i=e.SHARD,a=typeof e.LUNORA_ADMIN_TOKEN=="string"?e.LUNORA_ADMIN_TOKEN:void 0;if(i===void 0||a===void 0)return;let s=i;if(t.jurisdiction!==void 0){if(typeof i.jurisdiction!="function")throw new TypeError(`@lunora/queue: Durable Object namespace does not support jurisdiction("${t.jurisdiction}") — update @cloudflare/workers-types or remove the jurisdiction option`);s=i.jurisdiction(t.jurisdiction)}const d=s.get(s.idFromName(n)),u=new AbortController,l=setTimeout(()=>{u.abort()},E);try{const r=await d.fetch("https://shard.internal/rpc",{body:JSON.stringify({args:{messages:o},functionPath:N}),headers:{authorization:`Bearer ${a}`,"content-type":"application/json"},method:"POST",signal:u.signal});if(!r.ok){const c=await r.text().catch(()=>"");throw new p("INTERNAL",`@lunora/queue: capture write to the root shard failed (${String(r.status)} ${r.statusText})${c===""?"":`: ${c}`}`)}await r.body?.cancel()}finally{clearTimeout(l)}}};export{g as createQueueCaptureSink,y as shouldCaptureQueue};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import i from"./createQueues-lUaHm_Qo.mjs";const f=(e,c)=>{const t={};for(const o of c){const n=e[o.binding];n&&typeof n.send=="function"&&typeof n.sendBatch=="function"&&(t[o.exportName]=n)}return i({bindings:t})};export{f as createQueueContext};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{LunoraError as a}from"@lunora/errors";const g=e=>({debug:(t,...n)=>{console.debug(e,t,...n)},error:(t,...n)=>{console.error(e,t,...n)},info:(t,...n)=>{console.info(e,t,...n)},warn:(t,...n)=>{console.warn(e,t,...n)}}),w=e=>{let t="";for(let n=0;n<e.length;n+=32768)t+=String.fromCharCode(...e.subarray(n,n+32768));return btoa(t)},p=e=>w(e).replaceAll("+","-").replaceAll("/","_").replace(/=+$/,"");new TextDecoder;const y=new TextEncoder,d="=",b=e=>{for(let t=0;t<e.length;t+=1)if(e.charCodeAt(t)>255)return!1;return!0},m=e=>p(y.encode(JSON.stringify(e))),I=e=>!e.startsWith(d)&&b(e)?e:`${d}${p(y.encode(e))}`,R="/_lunora/scheduler/dispatch",A=e=>{let t=e.length;for(;t>0&&e[t-1]==="/";)t-=1;return e.slice(0,t)},O=(e,t,n)=>{try{const o=JSON.parse(n)?.error;if(typeof o=="object"&&o!==null&&typeof o.code=="string"){const{code:i,data:c,message:s}=o;return new a(i,typeof s=="string"?s:void 0,{data:c,status:t})}}catch{}return new a("INTERNAL",`${e}: function dispatch failed (${String(t)}): ${n}`,{status:t})},$=e=>{const{label:t}=e,n=globalThis.fetch,o=e.fetchImpl??(typeof n=="function"?n.bind(globalThis):void 0);return async(i,c,s={})=>{if(typeof o!="function")throw new TypeError(`${t}: no fetch implementation available — pass fetchImpl or run on a platform with global fetch`);const l=e.env.LUNORA_ORIGIN_URL;if(typeof l!="string"||l.length===0)throw new a("INTERNAL",`${t}: \`LUNORA_ORIGIN_URL\` must be set on the Worker env so a handler can call back into Lunora functions`);const u=e.env.LUNORA_ADMIN_TOKEN;if(typeof u!="string"||u.length===0)throw new a("INTERNAL",`${t}: \`LUNORA_ADMIN_TOKEN\` must be set on the Worker env to authenticate function dispatch`);const N=`${A(l)}${R}`,f={authorization:`Bearer ${u}`,"content-type":"application/json"};e.identity?.userId!==void 0&&(f["x-lunora-userid"]=I(e.identity.userId)),e.identity?.claims!==void 0&&(f["x-lunora-identity"]=m(e.identity.claims));const r=await o(N,{body:JSON.stringify({args:c??{},functionPath:i.__lunoraRef,shardKey:s.shardKey}),headers:f,method:"POST"});if(!r.ok)throw O(t,r.status,await r.text());const h=await r.text();if(h.length!==0)try{return JSON.parse(h)}catch{throw new a("INTERNAL",`${t}: function dispatch returned a non-JSON body (${String(r.status)}): ${h}`,{status:r.status})}}},L=e=>({env:e.env,log:g(`[queue:${e.exportName}]`),run:$({env:e.env,fetchImpl:e.fetchImpl,label:"@lunora/queue"})});export{L as createQueueRunContext};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{LunoraError as i}from"@lunora/errors";const c=100,d=o=>({send:async(s,n)=>{await o.send(s,n)},sendBatch:async(s,n)=>{const t=[...s];if(t.length>c)throw new i("VALIDATION_ERROR",`@lunora/queue: sendBatch exceeds ${String(c)} (got ${String(t.length)}) — split across calls`);await o.sendBatch(t,n)}}),g=o=>{const s=o.bindings??{},n=Object.create(null);for(const[r,e]of Object.entries(s))n[r]=d(e);const t=Object.keys(n),u=r=>{const e=t.length===0?"no queues are declared":`known queues: ${t.join(", ")}`,a=()=>Promise.reject(new Error(`@lunora/queue: no queue named "${r}" (${e})`));return{send:a,sendBatch:a}};return new Proxy(n,{get(r,e){if(typeof e=="string")return Object.hasOwn(r,e)?r[e]:u(e)}})};export{g as default};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{LunoraError as l}from"@lunora/errors";import{createQueueRunContext as f}from"./createQueueRunContext-Dg_fCCaC.mjs";const m=3,d=e=>{if(e instanceof Date)return e.getTime();const t=typeof e=="number"?e:Number(e);return Number.isFinite(t)?t:0},h=(e,t)=>new Proxy(e,{get:(r,a)=>a==="ack"?()=>{t.set(r,"ack"),r.ack()}:a==="retry"?o=>{t.set(r,"retry"),r.retry(o)}:Reflect.get(r,a,r)}),y=(e,t,r)=>new Proxy(e,{get:(a,o)=>o==="ackAll"?()=>{r("ack"),a.ackAll()}:o==="retryAll"?i=>{r("retry"),a.retryAll(i)}:o==="messages"?t:Reflect.get(a,o,a)}),g=e=>{const t=new Map,r=e.messages,a=r.map(i=>h(i,t)),o=y(e,a,i=>{for(const s of r)t.has(s)||t.set(s,i)});return{dispositions:t,originals:r,wrappedBatch:o}},w=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)},b=(e,t,r,a,o)=>{const i=a?w(o):void 0,s=typeof t.definition.maxRetries=="number"?t.definition.maxRetries:m;return e.originals.map(u=>{const c=e.dispositions.get(u)??(a?"error":"ack"),n=typeof u.attempts=="number"?u.attempts:1;return{attempts:n,body:u.body,deadLettered:c!=="ack"&&n>s,error:c==="error"?i:void 0,exportName:t.exportName,messageId:u.id,outcome:c,queue:r,timestamp:d(u.timestamp)}})},x=async(e,t,r)=>{const a=Object.hasOwn(t,e.queue)?t[e.queue]:void 0;if(a===void 0){const n=Object.keys(t),p=n.length===0?"no push queues are declared":`known push queues: ${n.join(", ")}`;throw new l("INTERNAL",`@lunora/queue: received a batch for queue "${e.queue}" but no push handler is registered (${p})`)}const{handler:o}=a.definition;if(typeof o!="function")throw new TypeError(`@lunora/queue: queue "${e.queue}" (${a.exportName}) has no push handler — it is declared as a pull consumer`);const i=f({env:r.env,exportName:a.exportName,fetchImpl:r.fetchImpl});if(r.capture===void 0){await o(i,e);return}const s=g(e);let u=!1,c;try{await o(i,s.wrappedBatch)}catch(n){u=!0,c=n}try{const n=b(s,a,e.queue,u,c);await r.capture(n)}catch(n){console.warn("@lunora/queue: capture sink failed (delivery unaffected):",n)}if(u)throw c};export{x as dispatchQueueBatch};
|