@lunora/queue 1.0.0-alpha.133 → 1.0.0-alpha.134
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.mjs +1 -1
- package/dist/packem_shared/{createQueueContext-Dj2Usabi.mjs → createQueueContext-D92uMeXw.mjs} +1 -1
- package/dist/packem_shared/{createQueues-rJhF4-zP.mjs → createQueues-BJDpU8fF.mjs} +1 -1
- package/dist/packem_shared/{createTopicContext-BKwZyv9_.mjs → createTopicContext-BPiAT8uI.mjs} +1 -1
- package/dist/packem_shared/{dispatchQueueBatch-DGBHNaBQ.mjs → dispatchQueueBatch-C_3eHm9I.mjs} +1 -1
- package/dist/packem_shared/requeue-envelope-DqPmW3Ko.mjs +4 -0
- package/package.json +2 -2
- package/dist/packem_shared/requeue-envelope-CEZPo4JT.mjs +0 -4
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createQueueCaptureSink as t,shouldCaptureQueue as o}from"./packem_shared/createQueueCaptureSink-CSOPftvj.mjs";import{createQueueContext as i}from"./packem_shared/createQueueContext-
|
|
1
|
+
import{createQueueCaptureSink as t,shouldCaptureQueue as o}from"./packem_shared/createQueueCaptureSink-CSOPftvj.mjs";import{createQueueContext as i}from"./packem_shared/createQueueContext-D92uMeXw.mjs";import{createQueues as n}from"./packem_shared/createQueues-BJDpU8fF.mjs";import{defineQueue as f,isQueueDefinition as c,queueBindingName as x,queueDefaultName as m}from"./packem_shared/defineQueue-TY4-i3nG.mjs";import{dispatchQueueBatch as d}from"./packem_shared/dispatchQueueBatch-C_3eHm9I.mjs";import{c as C}from"./packem_shared/run-context-C2uF0PXy.mjs";import{createTopicContext as l,defineSubscription as q,defineTopic as B}from"./packem_shared/createTopicContext-BPiAT8uI.mjs";export{t as createQueueCaptureSink,i as createQueueContext,C as createQueueRunContext,n as createQueues,l as createTopicContext,f as defineQueue,q as defineSubscription,B as defineTopic,d as dispatchQueueBatch,c as isQueueDefinition,x as queueBindingName,m as queueDefaultName,o as shouldCaptureQueue};
|
package/dist/packem_shared/{createQueueContext-Dj2Usabi.mjs → createQueueContext-D92uMeXw.mjs}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{resolveQueueBinding as r,createQueues as s}from"./createQueues-
|
|
1
|
+
import{resolveQueueBinding as r,createQueues as s}from"./createQueues-BJDpU8fF.mjs";const u=(t,i)=>{const e={};for(const n of i){const o=r(t,n.binding);o&&(e[n.exportName]=o)}return s({bindings:e})};export{u as createQueueContext};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{LunoraError as a}from"@lunora/errors";import{h as g,R as h}from"./requeue-envelope-
|
|
1
|
+
import{LunoraError as a}from"@lunora/errors";import{h as g,R as h}from"./requeue-envelope-DqPmW3Ko.mjs";const i=100,d=43200,l=(t,n)=>{if(t!==void 0&&t>d)throw new a("VALIDATION_ERROR",`@lunora/queue: ${n} delaySeconds is ${String(t)}, over the Cloudflare Queues ceiling of ${String(d)} (12 hours) — use @lunora/scheduler for longer schedules`)},$=(t,n)=>{if(g(t))throw new a("VALIDATION_ERROR",`@lunora/queue: ${n} body may not contain the reserved key "${h}"`)},f=(t,n,e)=>{l(n?.delaySeconds,e),$(t,e)},E=(t,n,e)=>{l(n?.delaySeconds,e);const s=[...t];if(s.length>i)throw new a("VALIDATION_ERROR",`@lunora/queue: ${e} exceeds ${String(i)} (got ${String(s.length)}) — split across calls`);for(const[r,o]of s.entries())f(o.body,o,`${e} message ${String(r)}`);return s},O=t=>({send:async(n,e)=>{f(n,e,"send"),await t.send(n,e)},sendBatch:async(n,e)=>{await t.sendBatch(E(n,e,"sendBatch"),e)}}),y=(t,n)=>{const e=t[n];return e&&typeof e.send=="function"&&typeof e.sendBatch=="function"?e:void 0},R=(t,n,e)=>{const s=Object.assign(Object.create(null),t),r=Object.keys(s),o=r.length===0?`no ${n}s are declared`:`known ${n}s: ${r.join(", ")}`;return new Proxy(s,{get(u,c){if(typeof c=="string")return Object.hasOwn(u,c)?u[c]:e(()=>Promise.reject(new Error(`@lunora/queue: no ${n} named "${c}" (${o})`)))}})},w=t=>{const n=t.bindings??{},e={};for(const[s,r]of Object.entries(n))e[s]=O(r);return R(e,"queue",s=>({send:s,sendBatch:s}))};export{f as assertSendable,w as createQueues,R as namedLookup,E as prepareBatch,y as resolveQueueBinding};
|
package/dist/packem_shared/{createTopicContext-BKwZyv9_.mjs → createTopicContext-BPiAT8uI.mjs}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{resolveQueueBinding as c,namedLookup as p,prepareBatch as a,assertSendable as h}from"./createQueues-
|
|
1
|
+
import{resolveQueueBinding as c,namedLookup as p,prepareBatch as a,assertSendable as h}from"./createQueues-BJDpU8fF.mjs";const f=()=>({isLunoraTopic:!0}),b=n=>typeof n=="object"&&n!==null&&n.isLunoraTopic===!0,w=(n,e)=>{if(!b(n))throw new TypeError("defineSubscription: the first argument must be a `defineTopic()` result");if(typeof e.handler!="function")throw new TypeError("defineSubscription: `handler` must be a function");if(e.name!==void 0&&(typeof e.name!="string"||e.name.length===0))throw new TypeError("defineSubscription: `name` must be a non-empty string when provided");return{...e,isLunoraQueue:!0,mode:"push",topic:n}},l=n=>({publish:async(e,t)=>{h(e,t,"publish"),await Promise.all(n.map(async r=>r.send(e,t)))},publishBatch:async(e,t)=>{const r=a(e,t,"publishBatch");await Promise.all(n.map(async i=>i.sendBatch(r,t)))}}),d=n=>{const e=()=>Promise.reject(new Error(`@lunora/queue: missing queue binding(s) ${n.join(", ")} — add them to wrangler.jsonc (lunora dev reconciles them); nothing was published`));return{publish:e,publishBatch:e}},y=(n,e)=>{const t={};for(const r of e){const i=[],s=[];for(const o of r.subscriptions){const u=c(n,o.binding);u?i.push(u):s.push(o.binding)}t[r.exportName]=s.length>0?d(s):l(i)}return p(t,"topic",r=>({publish:r,publishBatch:r}))};export{y as createTopicContext,w as defineSubscription,f as defineTopic};
|
package/dist/packem_shared/{dispatchQueueBatch-DGBHNaBQ.mjs → dispatchQueueBatch-C_3eHm9I.mjs}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{c as h,r as x,e as N,t as q,n as k,X as R}from"./run-context-C2uF0PXy.mjs";import{LunoraError as $,toErrorBody as M}from"@lunora/errors";import{s as A,o as I}from"./requeue-envelope-
|
|
1
|
+
import{c as h,r as x,e as N,t as q,n as k,X as R}from"./run-context-C2uF0PXy.mjs";import{LunoraError as $,toErrorBody as M}from"@lunora/errors";import{s as A,o as I}from"./requeue-envelope-DqPmW3Ko.mjs";const b=e=>typeof e.definition.maxRetries=="number"?e.definition.maxRetries:R,O=e=>{if(e instanceof Date)return e.getTime();const t=typeof e=="number"?e:Number(e);return Number.isFinite(t)?t:0},T=async(e,t)=>{const n=await I(t,e.body).catch(()=>{});return n===void 0?{body:e.body,id:e.id,requeued:!1}:{...n,requeued:!0}},g=e=>{const t=e.LUNORA_ADMIN_TOKEN;return typeof t=="string"&&t.length>0?t:void 0},B=(e,t)=>{let n=0;return(i,o,r)=>(n+=1,e(i,o,{...r,dedupId:`${t}#${String(n)}`,messageId:t}))},L=(e,t,n,i)=>{const o=B(i,t.id);return new Proxy(e,{get:(r,s)=>s==="id"?t.id:s==="body"?t.body:s==="ack"?()=>{n.set(r,"ack"),r.ack()}:s==="retry"?f=>{n.set(r,"retry"),r.retry(f)}:s==="run"?o:Reflect.get(r,s,r)})},j=(e,t,n)=>new Proxy(e,{get:(i,o)=>o==="ackAll"?()=>{n("ack"),i.ackAll()}:o==="retryAll"?r=>{n("retry"),i.retryAll(r)}:o==="messages"?t:Reflect.get(i,o,i)}),S=async(e,t,n)=>{const i=new Map,o=e.messages,r=new Map,s=[];for(const c of o){const u=await T(c,n);r.set(c,u),s.push(L(c,u,i,t))}const l=j(e,s,c=>{for(const u of o)i.has(u)||i.set(u,c)});return{dispositions:i,originals:o,requeued:new Set,views:r,wrappedBatch:l}},m=(e,t)=>e.views.get(t)??{body:t.body,id:t.id,requeued:!1},v=(e,t)=>m(e,t).id,Q=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)},D=(e,t,n,i,o,r)=>{const s=i?Q(o):void 0,f=b(t),l=i?"error":"ack",c=typeof t.definition.deadLetterQueue=="string"&&t.definition.deadLetterQueue.length>0;return e.originals.map(u=>{const d=u===r,a=e.dispositions.get(u),p=d?"error":a??l,w=typeof u.attempts=="number"?u.attempts:1,y=m(e,u);return{attempts:w,body:y.body,deadLettered:c&&!d&&!e.requeued.has(u)&&p!=="ack"&&w>f,error:p==="error"?s:void 0,exportName:t.exportName,messageId:y.id,outcome:p,queue:n,timestamp:O(u.timestamp)}})},C=(e,t,n)=>{if(!t||!N(n))return;const i=q(n);if(i===void 0)return;const o=e.originals.find(r=>v(e,r)===i);if(!(o===void 0||e.dispositions.has(o)))return o},P=(e,t)=>{t.ack();for(const n of e.originals)n!==t&&!e.dispositions.has(n)&&(e.dispositions.set(n,"retry"),n.retry())},F=async(e,t,n,i,o)=>{const r=g(o),s=q(t),f=e.originals.find(d=>v(e,d)===s&&!e.dispositions.has(d)),l=`@lunora/queue: queue "${i}" (${n.exportName})`,c=n.binding===void 0?void 0:o[n.binding],u=[];for(const d of e.originals)if(!e.dispositions.has(d)){if(e.dispositions.set(d,"retry"),f!==void 0&&d!==f){d.retry();continue}u.push(d)}await Promise.all(u.map(async d=>{const a=m(e,d),p=typeof c?.send!="function"||a.requeued||r===void 0?void 0:async w=>{await c.send(await A(r,a.id,a.body),{contentType:"json",delaySeconds:w})};await k(d,{maxRetries:b(n),requeue:p,where:l})==="requeued"&&e.requeued.add(d)}))},E=async(e,t,n)=>{const i=Object.hasOwn(t,e.queue)?t[e.queue]:void 0;if(i===void 0){const a=Object.keys(t),p=a.length===0?"no push queues are declared":`known push queues: ${a.join(", ")}`;throw new $("INTERNAL",`@lunora/queue: received a batch for queue "${e.queue}" but no push handler is registered (${p}). Likely causes: the queue is declared \`pull\`, a renamed per-environment queue has no wrangler.jsonc producer with the declared binding, or codegen was not rerun.`)}const{handler:o}=i.definition;if(typeof o!="function")throw new TypeError(`@lunora/queue: queue "${e.queue}" (${i.exportName}) has no push handler — it is declared as a pull consumer`);const r=h({env:n.env,exportName:i.exportName,fetchImpl:n.fetchImpl,...n.traceparent===void 0?{}:{traceparent:n.traceparent},live:n.live}),s=await S(e,r.run,g(n.env));let f=!1,l;try{await o(r,s.wrappedBatch)}catch(a){f=!0,l=a}const c=C(s,f,l);if(c!==void 0){P(s,c);const{body:a,status:p}=M(l,{redactedMessage:"internal error"});console.error(`@lunora/queue: dropped message ${v(s,c)} on queue "${e.queue}" (${i.exportName}) — a dispatch it made failed with a deterministic ${String(p)} (${a.code}: ${a.message}), so it was acked, not retried. Its retries are NOT exhausted and it is not dead-lettered — it will never be redelivered.`)}const u=f&&x(l);u&&await F(s,l,i,e.queue,n.env);const d=f&&c===void 0&&!u;if(n.capture!==void 0)try{await n.capture(D(s,i,e.queue,f,l,c))}catch(a){console.warn("@lunora/queue: capture sink failed (delivery unaffected):",a)}if(d)throw l};export{E as dispatchQueueBatch};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import{encodeWire as f,parseWire as p}from"@lunora/wire";const g=(e,t)=>{if(e.size<t)return;const n=e.keys().next().value;n!==void 0&&e.delete(n)},w=(e,t,n,r)=>{const o=e.get(t);if(o!==void 0)return o;g(e,r);const s=n().catch(a=>{throw e.get(t)===s&&e.delete(t),a});return e.set(t,s),s},h=new TextEncoder,v=64,b=new Map,y=async e=>w(b,e,async()=>crypto.subtle.importKey("raw",h.encode(e),{hash:"SHA-256",name:"HMAC"},!1,["sign","verify"]),v),E="lunora.requeue.v1",m=new TextEncoder,d=(e,t,n)=>m.encode(`${E}
|
|
2
|
+
${e}
|
|
3
|
+
${t}
|
|
4
|
+
${n}`),S=e=>[...new Uint8Array(e)].map(t=>t.toString(16).padStart(2,"0")).join(""),A=/^[\da-f]{64}$/u,$=async(e,t,n,r)=>S(await crypto.subtle.sign("HMAC",await y(e),d(t,n,r))),q=async(e,t,n,r,o)=>{if(typeof o!="string"||!A.test(o))return!1;const s=Uint8Array.from({length:o.length/2},(a,i)=>Number.parseInt(o.slice(i*2,i*2+2),16));return crypto.subtle.verify("HMAC",await y(e),s,d(t,n,r))},c="$lunora.requeued$",l="queue",u=128*1024,M=e=>typeof e=="object"&&e!==null&&Object.hasOwn(e,c),x=async(e,t,n)=>{const r=JSON.stringify(f(n)),o={[c]:{body:r,id:t,mac:await $(e,l,t,r)}},s=new TextEncoder().encode(JSON.stringify(o)).byteLength;if(s>u)throw new RangeError(`the copy would be ${String(s)} bytes, over the ${String(u)}-byte queue message limit`);return o},C=async(e,t)=>{if(e===void 0||!M(t))return;const n=t[c];if(!(typeof n?.id!="string"||typeof n.body!="string")&&await q(e,l,n.id,n.body,n.mac))return{body:p(n.body),id:n.id}};export{c as R,M as h,C as o,x as s};
|
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.134",
|
|
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",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"dependencies": {
|
|
47
47
|
"@lunora/errors": ">=1.0.0-alpha.51 <2.0.0-0",
|
|
48
48
|
"@lunora/platform": "1.0.0-alpha.76",
|
|
49
|
-
"@lunora/wire": "1.0.0-alpha.
|
|
49
|
+
"@lunora/wire": "1.0.0-alpha.5"
|
|
50
50
|
},
|
|
51
51
|
"engines": {
|
|
52
52
|
"node": "^22.15.0 || >=24.11.0"
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import{encodeWire as f,decodeWire as p}from"@lunora/wire";const g=(e,t)=>{if(e.size<t)return;const n=e.keys().next().value;n!==void 0&&e.delete(n)},w=(e,t,n,r)=>{const o=e.get(t);if(o!==void 0)return o;g(e,r);const s=n().catch(a=>{throw e.get(t)===s&&e.delete(t),a});return e.set(t,s),s},h=new TextEncoder,v=64,b=new Map,y=async e=>w(b,e,async()=>crypto.subtle.importKey("raw",h.encode(e),{hash:"SHA-256",name:"HMAC"},!1,["sign","verify"]),v),E="lunora.requeue.v1",S=new TextEncoder,d=(e,t,n)=>S.encode(`${E}
|
|
2
|
-
${e}
|
|
3
|
-
${t}
|
|
4
|
-
${n}`),m=e=>[...new Uint8Array(e)].map(t=>t.toString(16).padStart(2,"0")).join(""),A=/^[\da-f]{64}$/u,$=async(e,t,n,r)=>m(await crypto.subtle.sign("HMAC",await y(e),d(t,n,r))),q=async(e,t,n,r,o)=>{if(typeof o!="string"||!A.test(o))return!1;const s=Uint8Array.from({length:o.length/2},(a,i)=>Number.parseInt(o.slice(i*2,i*2+2),16));return crypto.subtle.verify("HMAC",await y(e),s,d(t,n,r))},c="$lunora.requeued$",l="queue",u=128*1024,M=e=>typeof e=="object"&&e!==null&&Object.hasOwn(e,c),R=async(e,t,n)=>{const r=JSON.stringify(f(n)),o={[c]:{body:r,id:t,mac:await $(e,l,t,r)}},s=new TextEncoder().encode(JSON.stringify(o)).byteLength;if(s>u)throw new RangeError(`the copy would be ${String(s)} bytes, over the ${String(u)}-byte queue message limit`);return o},x=async(e,t)=>{if(e===void 0||!M(t))return;const n=t[c];if(!(typeof n?.id!="string"||typeof n.body!="string")&&await q(e,l,n.id,n.body,n.mac))return{body:p(JSON.parse(n.body)),id:n.id}};export{c as R,M as h,x as o,R as s};
|