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

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
@@ -208,7 +208,7 @@ interface CapturedQueueMessage {
208
208
  attempts: number;
209
209
  /** The message body (JSON-encoded + capped by the catcher). */
210
210
  body: unknown;
211
- /** `true` when this failed delivery was the message's last (its retries are exhausted the broker dead-letters it). */
211
+ /** `true` when this failed delivery was the message's last (its retries are exhausted) AND the queue declares a `deadLetterQueue` for it to land in. Stays `false` for a queue with no DLQ, where the broker drops the exhausted message instead — `attempts > maxRetries` with `outcome !== "ack"` is what identifies that case. */
212
212
  deadLettered: boolean;
213
213
  /** Handler error message when `outcome` is `error`; absent otherwise. */
214
214
  error?: string;
package/dist/index.d.ts CHANGED
@@ -208,7 +208,7 @@ interface CapturedQueueMessage {
208
208
  attempts: number;
209
209
  /** The message body (JSON-encoded + capped by the catcher). */
210
210
  body: unknown;
211
- /** `true` when this failed delivery was the message's last (its retries are exhausted the broker dead-letters it). */
211
+ /** `true` when this failed delivery was the message's last (its retries are exhausted) AND the queue declares a `deadLetterQueue` for it to land in. Stays `false` for a queue with no DLQ, where the broker drops the exhausted message instead — `attempts > maxRetries` with `outcome !== "ack"` is what identifies that case. */
212
212
  deadLettered: boolean;
213
213
  /** Handler error message when `outcome` is `error`; absent otherwise. */
214
214
  error?: string;
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-x_PWzYXq.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-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};
@@ -0,0 +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};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lunora/queue",
3
- "version": "1.0.0-alpha.41",
3
+ "version": "1.0.0-alpha.42",
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.28",
48
- "@lunora/platform": "1.0.0-alpha.23"
47
+ "@lunora/errors": "1.0.0-alpha.29",
48
+ "@lunora/platform": "1.0.0-alpha.24"
49
49
  },
50
50
  "engines": {
51
51
  "node": "^22.15.0 || >=24.11.0"
@@ -1 +0,0 @@
1
- import{c as m,B as w,M as h}from"./run-context-Bz18TJFU.mjs";import{LunoraError as y,toErrorBody as v}from"@lunora/errors";const x=3,q=e=>{if(e instanceof Date)return e.getTime();const r=typeof e=="number"?e:Number(e);return Number.isFinite(r)?r:0},b=(e,r)=>{let t=0;return(n,o,i)=>(t+=1,e(n,o,{...i,dedupId:`${r}#${String(t)}`,messageId:r}))},k=(e,r,t)=>{const n=b(t,e.id);return new Proxy(e,{get:(o,i)=>i==="ack"?()=>{r.set(o,"ack"),o.ack()}:i==="retry"?c=>{r.set(o,"retry"),o.retry(c)}:i==="run"?n:Reflect.get(o,i,o)})},g=(e,r,t)=>new Proxy(e,{get:(n,o)=>o==="ackAll"?()=>{t("ack"),n.ackAll()}:o==="retryAll"?i=>{t("retry"),n.retryAll(i)}:o==="messages"?r:Reflect.get(n,o,n)}),N=(e,r)=>{const t=new Map,n=e.messages,o=n.map(a=>k(a,t,r)),c=g(e,o,a=>{for(const d of n)t.has(d)||t.set(d,a)});return{dispositions:t,originals:n,wrappedBatch:c}},$=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)},R=(e,r,t,n,o,i)=>{const c=n?$(o):void 0,a=typeof r.definition.maxRetries=="number"?r.definition.maxRetries:x,d=n?"error":"ack";return e.originals.map(s=>{const l=s===i,u=e.dispositions.get(s),f=l?"error":u??d,p=typeof s.attempts=="number"?s.attempts:1;return{attempts:p,body:s.body,deadLettered:!l&&f!=="ack"&&p>a,error:f==="error"?c:void 0,exportName:r.exportName,messageId:s.id,outcome:f,queue:t,timestamp:q(s.timestamp)}})},A=(e,r,t)=>{if(!r||!w(t))return;const n=h(t);if(n===void 0)return;const o=e.originals.find(i=>i.id===n);if(!(o===void 0||e.dispositions.has(o)))return o},M=(e,r)=>{r.ack();for(const t of e.originals)t!==r&&!e.dispositions.has(t)&&(e.dispositions.set(t,"retry"),t.retry())},I=async(e,r,t)=>{const n=Object.hasOwn(r,e.queue)?r[e.queue]:void 0;if(n===void 0){const u=Object.keys(r),f=u.length===0?"no push queues are declared":`known push queues: ${u.join(", ")}`;throw new y("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:t.env,exportName:n.exportName,fetchImpl:t.fetchImpl}),c=N(e,i.run);let a=!1,d;try{await o(i,c.wrappedBatch)}catch(u){a=!0,d=u}const s=A(c,a,d);if(s!==void 0){M(c,s);const{body:u,status:f}=v(d,{redactedMessage:"internal error"});console.error(`@lunora/queue: dropped message ${s.id} on queue "${e.queue}" (${n.exportName}) — a dispatch it made failed with a deterministic ${String(f)} (${u.code}: ${u.message}), so it was acked, not retried. Its retries are NOT exhausted and it is not dead-lettered — it will never be redelivered.`)}const l=a&&s===void 0;if(t.capture!==void 0)try{await t.capture(R(c,n,e.queue,a,d,s))}catch(u){console.warn("@lunora/queue: capture sink failed (delivery unaffected):",u)}if(l)throw d};export{I as dispatchQueueBatch};