@lunora/queue 1.0.0-alpha.61 → 1.0.0-alpha.63
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-DTHNR23e.mjs +1 -0
- package/dist/packem_shared/{dispatchQueueBatch-DKAdSIjq.mjs → dispatchQueueBatch-wUA8PKG3.mjs} +1 -1
- package/dist/packem_shared/{run-context-D3vstU6K.mjs → run-context-CBHEX5iy.mjs} +1 -1
- package/package.json +3 -3
- package/dist/packem_shared/createQueueRunContext-zKrCsNS-.mjs +0 -1
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-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-
|
|
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-wUA8PKG3.mjs";import{c as C}from"./packem_shared/run-context-CBHEX5iy.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-CBHEX5iy.mjs";export{o as createQueueRunContext};
|
package/dist/packem_shared/{dispatchQueueBatch-DKAdSIjq.mjs → dispatchQueueBatch-wUA8PKG3.mjs}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{c as w,e as h,r as v}from"./run-context-
|
|
1
|
+
import{c as w,e as h,r as v}from"./run-context-CBHEX5iy.mjs";import{LunoraError as y,toErrorBody as x}from"@lunora/errors";const g=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,i,o)=>(t+=1,e(n,i,{...o,dedupId:`${r}#${String(t)}`,messageId:r}))},k=(e,r,t)=>{const n=b(t,e.id);return new Proxy(e,{get:(i,o)=>o==="ack"?()=>{r.set(i,"ack"),i.ack()}:o==="retry"?u=>{r.set(i,"retry"),i.retry(u)}:o==="run"?n:Reflect.get(i,o,i)})},N=(e,r,t)=>new Proxy(e,{get:(n,i)=>i==="ackAll"?()=>{t("ack"),n.ackAll()}:i==="retryAll"?o=>{t("retry"),n.retryAll(o)}:i==="messages"?r:Reflect.get(n,i,n)}),$=(e,r)=>{const t=new Map,n=e.messages,i=n.map(a=>k(a,t,r)),u=N(e,i,a=>{for(const c of n)t.has(c)||t.set(c,a)});return{dispositions:t,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,r,t,n,i,o)=>{const u=n?R(i):void 0,a=typeof r.definition.maxRetries=="number"?r.definition.maxRetries:g,c=n?"error":"ack",f=typeof r.definition.deadLetterQueue=="string"&&r.definition.deadLetterQueue.length>0;return e.originals.map(d=>{const s=d===o,l=e.dispositions.get(d),p=s?"error":l??c,m=typeof d.attempts=="number"?d.attempts:1;return{attempts:m,body:d.body,deadLettered:f&&!s&&p!=="ack"&&m>a,error:p==="error"?u:void 0,exportName:r.exportName,messageId:d.id,outcome:p,queue:t,timestamp:q(d.timestamp)}})},M=(e,r,t)=>{if(!r||!h(t))return;const n=v(t);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,r)=>{r.ack();for(const t of e.originals)t!==r&&!e.dispositions.has(t)&&(e.dispositions.set(t,"retry"),t.retry())},L=async(e,r,t)=>{const n=Object.hasOwn(r,e.queue)?r[e.queue]:void 0;if(n===void 0){const s=Object.keys(r),l=s.length===0?"no push queues are declared":`known push queues: ${s.join(", ")}`;throw new y("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:t.env,exportName:n.exportName,fetchImpl:t.fetchImpl,...t.traceparent===void 0?{}:{traceparent:t.traceparent}}),u=$(e,o.run);let a=!1,c;try{await i(o,u.wrappedBatch)}catch(s){a=!0,c=s}const f=M(u,a,c);if(f!==void 0){T(u,f);const{body:s,status:l}=x(c,{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=a&&f===void 0;if(t.capture!==void 0)try{await t.capture(A(u,n,e.queue,a,c,f))}catch(s){console.warn("@lunora/queue: capture sink failed (delivery unaffected):",s)}if(d)throw c};export{L as dispatchQueueBatch};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{LunoraError as b,isLunoraError as j}from"@lunora/errors";const B=e=>({debug:(t,...o)=>{console.debug(e,t,...o)},error:(t,...o)=>{console.error(e,t,...o)},info:(t,...o)=>{console.info(e,t,...o)},warn:(t,...o)=>{console.warn(e,t,...o)}}),C=(e,t,o)=>{if(t===void 0)return{dispose:()=>{},signal:e};const a=new AbortController,n=setTimeout(()=>{a.abort(o())},t);return{dispose:()=>{clearTimeout(n)},signal:a.signal}},A=e=>{let t="";for(let o=0;o<e.length;o+=32768)t+=String.fromCharCode(...e.subarray(o,o+32768));return btoa(t)},M=e=>{const t=atob(e),o=new Uint8Array(t.length);for(let a=0;a<t.length;a+=1)o[a]=t.codePointAt(a)??0;return o},p="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",L=e=>{let t="",o=0;const a=e.length-2;for(;o<a;o+=3){const r=e[o]<<16|e[o+1]<<8|e[o+2];t+=p.charAt(r>>18&63)+p.charAt(r>>12&63)+p.charAt(r>>6&63)+p.charAt(r&63)}const n=e.length-o;if(n===1){const r=e[o]<<16;t+=p.charAt(r>>18&63)+p.charAt(r>>12&63)}else if(n===2){const r=e[o]<<16|e[o+1]<<8;t+=p.charAt(r>>18&63)+p.charAt(r>>12&63)+p.charAt(r>>6&63)}return t};new TextDecoder;const U=new TextEncoder
|
|
1
|
+
import{LunoraError as b,isLunoraError as j}from"@lunora/errors";const B=e=>({debug:(t,...o)=>{console.debug(e,t,...o)},error:(t,...o)=>{console.error(e,t,...o)},info:(t,...o)=>{console.info(e,t,...o)},warn:(t,...o)=>{console.warn(e,t,...o)}}),C=(e,t,o)=>{if(t===void 0)return{dispose:()=>{},signal:e};const a=new AbortController,n=setTimeout(()=>{a.abort(o())},t);return{dispose:()=>{clearTimeout(n)},signal:a.signal}},A=e=>{let t="";for(let o=0;o<e.length;o+=32768)t+=String.fromCharCode(...e.subarray(o,o+32768));return btoa(t)},M=e=>{const t=atob(e),o=new Uint8Array(t.length);for(let a=0;a<t.length;a+=1)o[a]=t.codePointAt(a)??0;return o},p="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",L=e=>{let t="",o=0;const a=e.length-2;for(;o<a;o+=3){const r=e[o]<<16|e[o+1]<<8|e[o+2];t+=p.charAt(r>>18&63)+p.charAt(r>>12&63)+p.charAt(r>>6&63)+p.charAt(r&63)}const n=e.length-o;if(n===1){const r=e[o]<<16;t+=p.charAt(r>>18&63)+p.charAt(r>>12&63)}else if(n===2){const r=e[o]<<16|e[o+1]<<8;t+=p.charAt(r>>18&63)+p.charAt(r>>12&63)+p.charAt(r>>6&63)}return t};new TextDecoder;const U=new TextEncoder,I="=",J=e=>{for(let t=0;t<e.length;t+=1)if(e.charCodeAt(t)>255)return!1;return!0},K=e=>L(U.encode(JSON.stringify(e))),F=e=>!e.startsWith(I)&&J(e)?e:`${I}${L(U.encode(e))}`,u="$lunora.wire$",E=64,$=1024,v="__proto__",R={BigInt64Array,BigUint64Array,Float32Array,Float64Array,Int8Array,Int16Array,Int32Array,Uint8Array,Uint8ClampedArray,Uint16Array,Uint32Array},S={Error,EvalError,RangeError,ReferenceError,SyntaxError,TypeError,URIError},G=e=>{if(e===null||typeof e!="object")return!1;const t=Object.getPrototypeOf(e);return t===null||t===Object.prototype},h=(e,t=0)=>{if(t>E)throw new RangeError(`wire-codec: value nesting exceeds the ${E}-level limit`);if(e===void 0)return[u,"undefined"];if(e===null)return null;const o=typeof e;if(o==="bigint")return[u,"bigint",e.toString()];if(o==="number"){const r=e;return Number.isNaN(r)?[u,"nan"]:r===1/0?[u,"inf"]:r===-1/0?[u,"-inf"]:r}if(o!=="object")return e;if(e instanceof Date)return[u,"date",h(e.getTime(),t+1)];if(e instanceof Error){const r=e,s={};for(const i of Object.keys(r)){if(r[i]===void 0)continue;const f=h(r[i],t+1);i===v?Object.defineProperty(s,i,{configurable:!0,enumerable:!0,value:f,writable:!0}):s[i]=f}const c=[u,"error",String(r.name),String(r.message),s];return r.cause!==void 0&&c.push(h(r.cause,t+1)),c}if(e instanceof URL)return[u,"url",e.href];if(e instanceof Map)return[u,"map",[...e.entries()].map(([r,s])=>[h(r,t+1),h(s,t+1)])];if(e instanceof Set)return[u,"set",[...e].map(r=>h(r,t+1))];if(e instanceof ArrayBuffer)return[u,"bytes",A(new Uint8Array(e)),"ArrayBuffer"];if(ArrayBuffer.isView(e)){const r=e,s=r.constructor.name,c=new Uint8Array(r.buffer,r.byteOffset,r.byteLength);return s==="Uint8Array"?[u,"bytes",A(c)]:[u,"bytes",A(c),s]}if(Array.isArray(e)){const r=e.map(s=>h(s,t+1));return r.length>0&&r[0]===u?[u,"arr",r]:r}if(!G(e)){const r=e.constructor?.name??"value";throw new TypeError(`wire-codec: cannot encode a ${r} over the Lunora wire — only plain objects, arrays, and the supported built-ins (Date, Error, URL, Map, Set, ArrayBuffer/typed arrays, bigint) round-trip`)}const a=e,n={};for(const r of Object.keys(a)){const s=a[r];if(s===void 0)continue;const c=h(s,t+1);r===v?Object.defineProperty(n,r,{configurable:!0,enumerable:!0,value:c,writable:!0}):n[r]=c}return n},l=(e,t=0)=>{if(t>E)throw new RangeError(`wire-codec: value nesting exceeds the ${E}-level limit`);if(e===null||typeof e!="object")return e;if(Array.isArray(e)){if(e[0]===u)switch(e[1]){case"-inf":return-1/0;case"arr":return e[2].map(n=>l(n,t+1));case"bigint":{const n=e[2];if(typeof n!="string"||n.length>$||!/^-?\d+$/.test(n))throw new RangeError(`wire-codec: invalid or over-long bigint (max ${$} digits)`);return BigInt(n)}case"date":{const n=l(e[2],t+1);if(typeof n!="number")throw new TypeError("wire-codec: malformed date — epoch must be a number");return new Date(n)}case"map":{const n=e[2];return new Map(n.map(r=>{if(!Array.isArray(r)||r.length!==2)throw new TypeError("wire-codec: malformed map entry — expected a [key, value] pair");return[l(r[0],t+1),l(r[1],t+1)]}))}case"set":return new Set(e[2].map(n=>l(n,t+1)));case"url":{const n=e[2];if(typeof n!="string")throw new TypeError("wire-codec: malformed url — href must be a string");return new URL(n)}case"error":{const n=e[2],r=e[3];if(typeof n!="string"||typeof r!="string")throw new TypeError("wire-codec: malformed error — name and message must be strings");const s=(Object.hasOwn(S,n)?S[n]:void 0)??Error,c=new s(r);c.name!==n&&Object.defineProperty(c,"name",{configurable:!0,value:n,writable:!0});const i=l(e[4],t+1);if(i===null||typeof i!="object"||Array.isArray(i))throw new TypeError("wire-codec: malformed error — props must be an object");for(const f of Object.keys(i))f===v?Object.defineProperty(c,f,{configurable:!0,enumerable:!0,value:i[f],writable:!0}):c[f]=i[f];return e.length>5&&Object.defineProperty(c,"cause",{configurable:!0,value:l(e[5],t+1),writable:!0}),c}case"bytes":{const n=e[2];if(typeof n!="string")throw new TypeError("wire-codec: malformed bytes — payload must be a base64 string");const r=M(n);if(A(r)!==n)throw new TypeError("wire-codec: malformed bytes — payload must be canonical padded base64");const s=e[3]??"Uint8Array";if(s==="ArrayBuffer")return r.buffer.byteLength===r.byteLength?r.buffer:r.slice().buffer;const c=Object.hasOwn(R,s)?R[s]:void 0;return c?new c(r.slice().buffer):r}case"inf":return 1/0;case"nan":return Number.NaN;case"undefined":return;default:return e.map(n=>l(n,t+1))}return e.map(n=>l(n,t+1))}const o=e,a={};for(const n of Object.keys(o)){const r=l(o[n],t+1);n===v?Object.defineProperty(a,n,{configurable:!0,enumerable:!0,value:r,writable:!0}):a[n]=r}return a},H=(e,t,o)=>{try{return h(o)}catch(a){throw new TypeError(`${e}: cannot encode args for '${t}' — ${a instanceof Error?a.message:String(a)}`,a instanceof Error?{cause:a}:void 0)}},W="/_lunora/scheduler/dispatch",q=3e4,z=e=>{let t=e.length;for(;t>0&&e[t-1]==="/";)t-=1;return e.slice(0,t)},_=Symbol("lunoraDispatchFailure"),x=Symbol("lunoraDispatchMessageId"),P=(e,t)=>(t!==void 0&&Object.defineProperty(e,x,{value:t}),e),Q=(e,t)=>(Object.defineProperty(e,_,{value:!0}),P(e,t)),re=e=>j(e)?e[x]:void 0,V=(e,t,o,a)=>{try{const n=JSON.parse(o)?.error;if(typeof n=="object"&&n!==null&&typeof n.code=="string"){const{code:r,data:s,message:c}=n;return Q(new b(r,typeof c=="string"?c:void 0,{data:s,status:t}),a)}}catch{}return P(new b("INTERNAL",`${e}: function dispatch failed (${String(t)}): ${o}`,{status:t}),a)},X=new Set([400,403,404,422]),Y=new Set(["DISPATCH_IN_PROGRESS","DISPATCH_UNAUTHENTICATED"]),ne=e=>j(e)&&e[_]===!0&&X.has(e.status)&&!Y.has(e.code),Z=(e,t,o)=>new b("INTERNAL",`${e}: function dispatch to "${t}" timed out after ${String(o)}ms`,{status:503}),ee=e=>{const{label:t}=e,o=globalThis.fetch,a=e.fetchImpl??(typeof o=="function"?o.bind(globalThis):void 0);return async(n,r,s={})=>{if(typeof a!="function")throw new TypeError(`${t}: no fetch implementation available — pass fetchImpl or run on a platform with global fetch`);const c=()=>e.argsAlreadyEncoded===!0?r??{}:H(t,n.__lunoraRef,r??{}),i=e.env.LUNORA_ORIGIN_URL;if(typeof i!="string"||i.length===0)throw new b("INTERNAL",`${t}: \`LUNORA_ORIGIN_URL\` must be set on the Worker env so a handler can call back into Lunora functions`);const f=e.env.LUNORA_ADMIN_TOKEN;if(typeof f!="string"||f.length===0)throw new b("INTERNAL",`${t}: \`LUNORA_ADMIN_TOKEN\` must be set on the Worker env to authenticate function dispatch`);const D=`${z(i)}${W}`,m={authorization:`Bearer ${f}`,"content-type":"application/json"};e.traceparent!==void 0&&e.traceparent.length>0&&(m.traceparent=e.traceparent),e.identity?.userId!==void 0&&(m["x-lunora-userid"]=F(e.identity.userId)),e.identity?.claims!==void 0&&(m["x-lunora-identity"]=K(e.identity.claims));const N=s.timeoutMs??q,T=C(void 0,N,()=>new DOMException(`dispatch timed out after ${String(N)}ms`,"TimeoutError")),O=y=>{throw y instanceof Error&&y.name==="TimeoutError"?Z(t,n.__lunoraRef,N):y};let d;try{try{d=await a(D,{body:JSON.stringify({args:c(),functionPath:n.__lunoraRef,id:s.dedupId,shardKey:s.shardKey}),headers:m,method:"POST",signal:T.signal})}catch(w){return O(w)}if(!d.ok){let w;try{w=await d.text()}catch(k){return O(k)}throw V(t,d.status,w,s.messageId)}let y;try{y=await d.text()}catch(w){return O(w)}if(y.length===0)return;let g;try{g=JSON.parse(y)}catch{throw new b("INTERNAL",`${t}: function dispatch returned a non-JSON body (${String(d.status)}): ${y}`,{status:d.status})}if(g===null||typeof g!="object"||Array.isArray(g)||!("result"in g))throw new b("INTERNAL",`${t}: function dispatch returned a JSON body that is not a { result } envelope (${String(d.status)}): ${y}`,{status:d.status});return l(g.result)}finally{T.dispose()}}},oe=e=>({env:e.env,log:B(`[queue:${e.exportName}]`),run:ee({env:e.env,fetchImpl:e.fetchImpl,label:"@lunora/queue",...e.traceparent===void 0?{}:{traceparent:e.traceparent}})});export{oe as c,ne as e,re as r};
|
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.63",
|
|
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.41",
|
|
48
|
+
"@lunora/platform": "1.0.0-alpha.34"
|
|
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-D3vstU6K.mjs";export{o as createQueueRunContext};
|