@lunora/queue 1.0.0-alpha.144 → 1.0.0-alpha.145

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
@@ -475,6 +475,27 @@ declare const queueDefaultName: (exportName: string) => string;
475
475
  declare const defineQueue: <Body = unknown>(config: QueueConfig<Body>) => QueueDefinition<Body>;
476
476
  /** True when a value is a `defineQueue` result (the runtime brand check). */
477
477
  declare const isQueueDefinition: (value: unknown) => value is QueueDefinition;
478
+ /** A batch as the platform consumer forwards it (`QueueForwardBatch` in `@lunora/runtime`). */
479
+ interface ForwardedQueueBatch {
480
+ /** `attempts` is the platform's delivery attempt; absent from a platform that does not send it, which counts as the first. */
481
+ messages: ReadonlyArray<{
482
+ attempts?: number;
483
+ body: unknown;
484
+ id: string;
485
+ }>;
486
+ queue: string;
487
+ }
488
+ /** What a forwarded batch answers: the ids to retry, and the delay each retry asked for, in seconds. */
489
+ interface ForwardedQueueResult {
490
+ retry: string[];
491
+ retryDelays?: Record<string, number>;
492
+ }
493
+ /**
494
+ * Dispatch a forwarded batch and answer the ids to retry. A message the handler
495
+ * left alone is acked, as Cloudflare acks one on a clean return; when the
496
+ * handler fails the whole batch, every message it did not ack is retried.
497
+ */
498
+ declare const dispatchForwardedQueueBatch: (forwarded: ForwardedQueueBatch, registry: QueueRegistry, options: DispatchOptions) => Promise<ForwardedQueueResult>;
478
499
  interface RunContextOptions {
479
500
  env: Record<string, unknown>;
480
501
  exportName: string;
@@ -506,4 +527,4 @@ declare const defineSubscription: <Payload>(topic: TopicDefinition<Payload>, con
506
527
  * unbound subscription rejects every publish (see {@link unboundPublisher}).
507
528
  */
508
529
  declare const createTopicContext: <Name extends string>(env: Record<string, unknown>, specs: ReadonlyArray<TopicBindingSpec<Name>>) => Topics<Name>;
509
- export { type ArgsOf, type CapturedQueueMessage, type FunctionReference, type LunoraQueuesOptions, type QueueBindingSpec, type QueueCaptureOptions, type QueueCaptureSink, type QueueConfig, type QueueConsumerMode, type QueueConsumerTuning, type QueueDefinition, type QueueEnv, type QueueHandler, type QueueLivePublisher, type DispatchLogger as QueueLogger, type QueueMessage, type QueueMessageBatch, type QueueProducer, type QueueRegistry, type QueueRegistryEntry, type QueueRunContext, type DispatchRunFunction as QueueRunFunction, type Queues, type RunFunctionOptions, type SubscriptionConfig, type SubscriptionDefinition, type TopicBindingSpec, type TopicDefinition, type TopicPublisher, type Topics, createQueueCaptureSink, createQueueContext, createQueueRunContext, createQueues, createTopicContext, defineQueue, defineSubscription, defineTopic, dispatchQueueBatch, isQueueDefinition, queueBindingName, queueDefaultName, shouldCaptureQueue };
530
+ export { type ArgsOf, type CapturedQueueMessage, type ForwardedQueueBatch, type ForwardedQueueResult, type FunctionReference, type LunoraQueuesOptions, type QueueBindingSpec, type QueueCaptureOptions, type QueueCaptureSink, type QueueConfig, type QueueConsumerMode, type QueueConsumerTuning, type QueueDefinition, type QueueEnv, type QueueHandler, type QueueLivePublisher, type DispatchLogger as QueueLogger, type QueueMessage, type QueueMessageBatch, type QueueProducer, type QueueRegistry, type QueueRegistryEntry, type QueueRunContext, type DispatchRunFunction as QueueRunFunction, type Queues, type RunFunctionOptions, type SubscriptionConfig, type SubscriptionDefinition, type TopicBindingSpec, type TopicDefinition, type TopicPublisher, type Topics, createQueueCaptureSink, createQueueContext, createQueueRunContext, createQueues, createTopicContext, defineQueue, defineSubscription, defineTopic, dispatchForwardedQueueBatch, dispatchQueueBatch, isQueueDefinition, queueBindingName, queueDefaultName, shouldCaptureQueue };
package/dist/index.d.ts CHANGED
@@ -475,6 +475,27 @@ declare const queueDefaultName: (exportName: string) => string;
475
475
  declare const defineQueue: <Body = unknown>(config: QueueConfig<Body>) => QueueDefinition<Body>;
476
476
  /** True when a value is a `defineQueue` result (the runtime brand check). */
477
477
  declare const isQueueDefinition: (value: unknown) => value is QueueDefinition;
478
+ /** A batch as the platform consumer forwards it (`QueueForwardBatch` in `@lunora/runtime`). */
479
+ interface ForwardedQueueBatch {
480
+ /** `attempts` is the platform's delivery attempt; absent from a platform that does not send it, which counts as the first. */
481
+ messages: ReadonlyArray<{
482
+ attempts?: number;
483
+ body: unknown;
484
+ id: string;
485
+ }>;
486
+ queue: string;
487
+ }
488
+ /** What a forwarded batch answers: the ids to retry, and the delay each retry asked for, in seconds. */
489
+ interface ForwardedQueueResult {
490
+ retry: string[];
491
+ retryDelays?: Record<string, number>;
492
+ }
493
+ /**
494
+ * Dispatch a forwarded batch and answer the ids to retry. A message the handler
495
+ * left alone is acked, as Cloudflare acks one on a clean return; when the
496
+ * handler fails the whole batch, every message it did not ack is retried.
497
+ */
498
+ declare const dispatchForwardedQueueBatch: (forwarded: ForwardedQueueBatch, registry: QueueRegistry, options: DispatchOptions) => Promise<ForwardedQueueResult>;
478
499
  interface RunContextOptions {
479
500
  env: Record<string, unknown>;
480
501
  exportName: string;
@@ -506,4 +527,4 @@ declare const defineSubscription: <Payload>(topic: TopicDefinition<Payload>, con
506
527
  * unbound subscription rejects every publish (see {@link unboundPublisher}).
507
528
  */
508
529
  declare const createTopicContext: <Name extends string>(env: Record<string, unknown>, specs: ReadonlyArray<TopicBindingSpec<Name>>) => Topics<Name>;
509
- export { type ArgsOf, type CapturedQueueMessage, type FunctionReference, type LunoraQueuesOptions, type QueueBindingSpec, type QueueCaptureOptions, type QueueCaptureSink, type QueueConfig, type QueueConsumerMode, type QueueConsumerTuning, type QueueDefinition, type QueueEnv, type QueueHandler, type QueueLivePublisher, type DispatchLogger as QueueLogger, type QueueMessage, type QueueMessageBatch, type QueueProducer, type QueueRegistry, type QueueRegistryEntry, type QueueRunContext, type DispatchRunFunction as QueueRunFunction, type Queues, type RunFunctionOptions, type SubscriptionConfig, type SubscriptionDefinition, type TopicBindingSpec, type TopicDefinition, type TopicPublisher, type Topics, createQueueCaptureSink, createQueueContext, createQueueRunContext, createQueues, createTopicContext, defineQueue, defineSubscription, defineTopic, dispatchQueueBatch, isQueueDefinition, queueBindingName, queueDefaultName, shouldCaptureQueue };
530
+ export { type ArgsOf, type CapturedQueueMessage, type ForwardedQueueBatch, type ForwardedQueueResult, type FunctionReference, type LunoraQueuesOptions, type QueueBindingSpec, type QueueCaptureOptions, type QueueCaptureSink, type QueueConfig, type QueueConsumerMode, type QueueConsumerTuning, type QueueDefinition, type QueueEnv, type QueueHandler, type QueueLivePublisher, type DispatchLogger as QueueLogger, type QueueMessage, type QueueMessageBatch, type QueueProducer, type QueueRegistry, type QueueRegistryEntry, type QueueRunContext, type DispatchRunFunction as QueueRunFunction, type Queues, type RunFunctionOptions, type SubscriptionConfig, type SubscriptionDefinition, type TopicBindingSpec, type TopicDefinition, type TopicPublisher, type Topics, createQueueCaptureSink, createQueueContext, createQueueRunContext, createQueues, createTopicContext, defineQueue, defineSubscription, defineTopic, dispatchForwardedQueueBatch, dispatchQueueBatch, isQueueDefinition, queueBindingName, queueDefaultName, shouldCaptureQueue };
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-Btzt_Mgt.mjs";import{createQueues as n}from"./packem_shared/createQueues-Bx_WZn7K.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-DlMvIQmd.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-CXR2jbCM.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};
1
+ import{createQueueCaptureSink as u,shouldCaptureQueue as r}from"./packem_shared/createQueueCaptureSink-CSOPftvj.mjs";import{createQueueContext as a}from"./packem_shared/createQueueContext-Btzt_Mgt.mjs";import{createQueues as p}from"./packem_shared/createQueues-Bx_WZn7K.mjs";import{defineQueue as f,isQueueDefinition as n,queueBindingName as x,queueDefaultName as m}from"./packem_shared/defineQueue-TY4-i3nG.mjs";import{dispatchQueueBatch as Q}from"./packem_shared/dispatchQueueBatch-DlMvIQmd.mjs";import{dispatchForwardedQueueBatch as h}from"./packem_shared/dispatchForwardedQueueBatch-D2V1SGtG.mjs";import{c as B}from"./packem_shared/run-context-C2uF0PXy.mjs";import{createTopicContext as q,defineSubscription as D,defineTopic as N}from"./packem_shared/createTopicContext-CXR2jbCM.mjs";export{u as createQueueCaptureSink,a as createQueueContext,B as createQueueRunContext,p as createQueues,q as createTopicContext,f as defineQueue,D as defineSubscription,N as defineTopic,h as dispatchForwardedQueueBatch,Q as dispatchQueueBatch,n as isQueueDefinition,x as queueBindingName,m as queueDefaultName,r as shouldCaptureQueue};
@@ -0,0 +1 @@
1
+ import{toErrorBody as f}from"@lunora/errors";import{dispatchQueueBatch as y}from"./dispatchQueueBatch-DlMvIQmd.mjs";const l=t=>t.toLowerCase().replaceAll("_","-"),b=(t,n)=>{if(Object.hasOwn(n,t))return t;const a=l(t),r=Object.entries(n).find(([,o])=>o.binding!==void 0&&l(o.binding)===a);return r===void 0?t:r[0]},u=(t,n)=>{const a=Object.fromEntries(t.flatMap(r=>{const o=n.get(r);return o===void 0?[]:[[r,o]]}));return Object.keys(a).length===0?{retry:t}:{retry:t,retryDelays:a}},g=async(t,n,a)=>{const r=new Map,o=new Map,i=(e,s)=>{r.set(e,"retry"),s===void 0?o.delete(e):o.set(e,s)},m=new Date,c=t.messages.map(e=>({ack:()=>{r.set(e.id,"ack")},attempts:e.attempts??1,body:e.body,id:e.id,retry:s=>{i(e.id,s?.delaySeconds)},timestamp:m})),p={ackAll:()=>{for(const e of c)r.set(e.id,"ack")},messages:c,queue:b(t.queue,n),retryAll:e=>{for(const s of c)i(s.id,e?.delaySeconds)}};try{await y(p,n,a)}catch(e){const{body:s}=f(e,{redactedMessage:"internal error"});return console.error(`@lunora/queue: forwarded batch on queue "${t.queue}" failed (${s.code}: ${s.message}); retrying its unacked messages.`),u(c.filter(d=>r.get(d.id)!=="ack").map(d=>d.id),o)}return u(c.filter(e=>r.get(e.id)==="retry").map(e=>e.id),o)};export{g as dispatchForwardedQueueBatch};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lunora/queue",
3
- "version": "1.0.0-alpha.144",
3
+ "version": "1.0.0-alpha.145",
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",
@@ -45,7 +45,7 @@
45
45
  },
46
46
  "dependencies": {
47
47
  "@lunora/errors": ">=1.0.0-alpha.51 <2.0.0-0",
48
- "@lunora/platform": "1.0.0-alpha.80",
48
+ "@lunora/platform": "^1.0.0-alpha.81",
49
49
  "@lunora/wire": "1.0.0-alpha.6"
50
50
  },
51
51
  "engines": {