@lunora/queue 1.0.0-alpha.34 → 1.0.0-alpha.36
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/createQueueRunContext-ZSWNee5A.mjs +1 -0
- package/dist/packem_shared/{dispatchQueueBatch-BBouObEO.mjs → dispatchQueueBatch-CPCCaAKp.mjs} +1 -1
- package/dist/packem_shared/run-context-Bz18TJFU.mjs +1 -0
- package/package.json +3 -3
- package/dist/packem_shared/createQueueRunContext-Ar63ZVoQ.mjs +0 -1
- package/dist/packem_shared/run-context-CTBT7TNr.mjs +0 -1
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
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 s}from"./packem_shared/dispatchQueueBatch-
|
|
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 s}from"./packem_shared/dispatchQueueBatch-CPCCaAKp.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 o}from"./run-context-Bz18TJFU.mjs";export{o as createQueueRunContext};
|
package/dist/packem_shared/{dispatchQueueBatch-BBouObEO.mjs → dispatchQueueBatch-CPCCaAKp.mjs}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{c as m,
|
|
1
|
+
import{c as m,B as w,M as h}from"./run-context-Bz18TJFU.mjs";import{LunoraError as y}from"@lunora/errors";const v=3,x=e=>{if(e instanceof Date)return e.getTime();const n=typeof e=="number"?e:Number(e);return Number.isFinite(n)?n:0},b=(e,n)=>{let t=0;return(r,o,i)=>(t+=1,e(r,o,{...i,dedupId:`${n}#${String(t)}`,messageId:n}))},k=(e,n,t)=>{const r=b(t,e.id);return new Proxy(e,{get:(o,i)=>i==="ack"?()=>{n.set(o,"ack"),o.ack()}:i==="retry"?u=>{n.set(o,"retry"),o.retry(u)}:i==="run"?r:Reflect.get(o,i,o)})},q=(e,n,t)=>new Proxy(e,{get:(r,o)=>o==="ackAll"?()=>{t("ack"),r.ackAll()}:o==="retryAll"?i=>{t("retry"),r.retryAll(i)}:o==="messages"?n:Reflect.get(r,o,r)}),R=(e,n)=>{const t=new Map,r=e.messages,o=r.map(c=>k(c,t,n)),u=q(e,o,c=>{for(const a of r)t.has(a)||t.set(a,c)});return{dispositions:t,originals:r,wrappedBatch:u}},N=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,n,t,r,o,i)=>{const u=r?N(o):void 0,c=typeof n.definition.maxRetries=="number"?n.definition.maxRetries:v,a=r?"error":"ack";return e.originals.map(s=>{const p=s===i,d=e.dispositions.get(s),f=p?"error":d??a,l=typeof s.attempts=="number"?s.attempts:1;return{attempts:l,body:s.body,deadLettered:!p&&f!=="ack"&&l>c,error:f==="error"?u:void 0,exportName:n.exportName,messageId:s.id,outcome:f,queue:t,timestamp:x(s.timestamp)}})},g=(e,n,t)=>{if(!n||!w(t))return;const r=h(t);if(r===void 0)return;const o=e.originals.find(i=>i.id===r);if(!(o===void 0||e.dispositions.has(o)))return o},M=(e,n)=>{n.ack();for(const t of e.originals)t!==n&&!e.dispositions.has(t)&&(e.dispositions.set(t,"retry"),t.retry())},$=async(e,n,t)=>{const r=Object.hasOwn(n,e.queue)?n[e.queue]:void 0;if(r===void 0){const d=Object.keys(n),f=d.length===0?"no push queues are declared":`known push queues: ${d.join(", ")}`;throw new y("INTERNAL",`@lunora/queue: received a batch for queue "${e.queue}" but no push handler is registered (${f})`)}const{handler:o}=r.definition;if(typeof o!="function")throw new TypeError(`@lunora/queue: queue "${e.queue}" (${r.exportName}) has no push handler — it is declared as a pull consumer`);const i=m({env:t.env,exportName:r.exportName,fetchImpl:t.fetchImpl}),u=R(e,i.run);let c=!1,a;try{await o(i,u.wrappedBatch)}catch(d){c=!0,a=d}const s=g(u,c,a);s!==void 0&&M(u,s);const p=c&&s===void 0;if(t.capture!==void 0)try{await t.capture(A(u,r,e.queue,c,a,s))}catch(d){console.warn("@lunora/queue: capture sink failed (delivery unaffected):",d)}if(p)throw a};export{$ as dispatchQueueBatch};
|
|
@@ -0,0 +1 @@
|
|
|
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};
|
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.36",
|
|
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.24",
|
|
48
|
+
"@lunora/platform": "1.0.0-alpha.19"
|
|
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-CTBT7TNr.mjs";export{o as createQueueRunContext};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{LunoraError as u,isLunoraError as w}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,e,n)=>{if(e===void 0)return{dispose:()=>{},signal:t};const o=new AbortController,r=setTimeout(()=>{o.abort(n())},e);return{dispose:()=>{clearTimeout(r)},signal:o.signal}},E=t=>{let e="";for(let n=0;n<t.length;n+=32768)e+=String.fromCharCode(...t.subarray(n,n+32768));return btoa(e)},b=t=>E(t).replaceAll("+","-").replaceAll("/","_").replace(/=+$/,"");new TextDecoder;const I=new TextEncoder,m="=",L=t=>{for(let e=0;e<t.length;e+=1)if(t.charCodeAt(e)>255)return!1;return!0},S=t=>b(I.encode(JSON.stringify(t))),_=t=>!t.startsWith(m)&&L(t)?t:`${m}${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)},$=Symbol("lunoraDispatchFailure"),v=Symbol("lunoraDispatchMessageId"),N=(t,e)=>(Object.defineProperty(t,$,{value:!0}),e!==void 0&&Object.defineProperty(t,v,{value:e}),t),j=t=>w(t)?t[v]:void 0,C=(t,e,n,o)=>{try{const r=JSON.parse(n)?.error;if(typeof r=="object"&&r!==null&&typeof r.code=="string"){const{code:d,data:i,message:c}=r;return N(new u(d,typeof c=="string"?c:void 0,{data:i,status:e}),o)}}catch{}return N(new u("INTERNAL",`${t}: function dispatch failed (${String(e)}): ${n}`,{status:e}),o)},k=new Set([400,403,404,422]),K=t=>w(t)&&t[$]===!0&&k.has(t.status),J=(t,e,n)=>new u("INTERNAL",`${t}: function dispatch to "${e}" timed out after ${String(n)}ms`,{status:503}),M=t=>{const{label:e}=t,n=globalThis.fetch,o=t.fetchImpl??(typeof n=="function"?n.bind(globalThis):void 0);return async(r,d,i={})=>{if(typeof o!="function")throw new TypeError(`${e}: no fetch implementation available — pass fetchImpl or run on a platform with global fetch`);const c=t.env.LUNORA_ORIGIN_URL;if(typeof c!="string"||c.length===0)throw new u("INTERNAL",`${e}: \`LUNORA_ORIGIN_URL\` must be set on the Worker env so a handler can call back into Lunora functions`);const h=t.env.LUNORA_ADMIN_TOKEN;if(typeof h!="string"||h.length===0)throw new u("INTERNAL",`${e}: \`LUNORA_ADMIN_TOKEN\` must be set on the Worker env to authenticate function dispatch`);const O=`${U(c)}${x}`,f={authorization:`Bearer ${h}`,"content-type":"application/json"};t.identity?.userId!==void 0&&(f["x-lunora-userid"]=_(t.identity.userId)),t.identity?.claims!==void 0&&(f["x-lunora-identity"]=S(t.identity.claims));const p=i.timeoutMs??D,g=A(void 0,p,()=>new DOMException(`dispatch timed out after ${String(p)}ms`,"TimeoutError")),y=a=>{throw a instanceof Error&&a.name==="TimeoutError"?J(e,r.__lunoraRef,p):a};let s;try{try{s=await o(O,{body:JSON.stringify({args:d??{},functionPath:r.__lunoraRef,id:i.dedupId,shardKey:i.shardKey}),headers:f,method:"POST",signal:g.signal})}catch(l){return y(l)}if(!s.ok){let l;try{l=await s.text()}catch(T){return y(T)}throw C(e,s.status,l,i.messageId)}let a;try{a=await s.text()}catch(l){return y(l)}if(a.length===0)return;try{return JSON.parse(a)}catch{throw new u("INTERNAL",`${e}: function dispatch returned a non-JSON body (${String(s.status)}): ${a}`,{status:s.status})}}finally{g.dispose()}}},W=t=>({env:t.env,log:R(`[queue:${t.exportName}]`),run:M({env:t.env,fetchImpl:t.fetchImpl,label:"@lunora/queue"})});export{K as H,W as c,j as k};
|