@moku-labs/worker 0.7.3 → 0.8.0

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.
@@ -739,7 +739,8 @@ const createQueuesApi = (ctx) => {
739
739
  kind: "queue",
740
740
  name: instance.name,
741
741
  binding: instance.binding,
742
- ...instance.onMessage ? { consumer: true } : {}
742
+ ...instance.onMessage ? { consumer: true } : {},
743
+ ...instance.maxBatchTimeout === void 0 ? {} : { maxBatchTimeout: instance.maxBatchTimeout }
743
744
  }))
744
745
  };
745
746
  };
@@ -2611,13 +2612,14 @@ const buildD1Databases = (resources, ids) => resources.filter((resource) => reso
2611
2612
  * Every queue is a `producer`; a queue flagged `consumer: true` (it declares an `onMessage` handler)
2612
2613
  * is ALSO registered as a `consumer` so wrangler delivers its messages to this Worker's queue()
2613
2614
  * handler — both locally under `wrangler dev` and in production. Without the consumer entry the
2614
- * handler never runs (the bug that silently drops a queue-driven activity feed).
2615
+ * handler never runs (the bug that silently drops a queue-driven activity feed). A consumer that
2616
+ * sets `maxBatchTimeout` carries it through as wrangler's `max_batch_timeout` (lower delivery latency).
2615
2617
  *
2616
2618
  * @param resources - All resource descriptors from the manifest.
2617
2619
  * @returns The queues section (producers, plus consumers when any), or undefined when there are none.
2618
2620
  * @example
2619
2621
  * ```ts
2620
- * const q = buildQueues([{ kind: "queue", name: "tracker-activity", binding: "ACTIVITY", consumer: true }]);
2622
+ * const q = buildQueues([{ kind: "queue", name: "tracker-activity", binding: "ACTIVITY", consumer: true, maxBatchTimeout: 1 }]);
2621
2623
  * ```
2622
2624
  */
2623
2625
  const buildQueues = (resources) => {
@@ -2627,7 +2629,11 @@ const buildQueues = (resources) => {
2627
2629
  queue: resource.name,
2628
2630
  binding: resource.binding
2629
2631
  }));
2630
- const consumers = queueResources.filter((resource) => resource.consumer === true).map((resource) => ({ queue: resource.name }));
2632
+ const consumers = queueResources.filter((resource) => resource.consumer === true).map((resource) => {
2633
+ const entry = { queue: resource.name };
2634
+ if (resource.maxBatchTimeout !== void 0) entry.max_batch_timeout = resource.maxBatchTimeout;
2635
+ return entry;
2636
+ });
2631
2637
  return consumers.length > 0 ? {
2632
2638
  producers,
2633
2639
  consumers
@@ -762,7 +762,8 @@ const createQueuesApi = (ctx) => {
762
762
  kind: "queue",
763
763
  name: instance.name,
764
764
  binding: instance.binding,
765
- ...instance.onMessage ? { consumer: true } : {}
765
+ ...instance.onMessage ? { consumer: true } : {},
766
+ ...instance.maxBatchTimeout === void 0 ? {} : { maxBatchTimeout: instance.maxBatchTimeout }
766
767
  }))
767
768
  };
768
769
  };
@@ -2634,13 +2635,14 @@ const buildD1Databases = (resources, ids) => resources.filter((resource) => reso
2634
2635
  * Every queue is a `producer`; a queue flagged `consumer: true` (it declares an `onMessage` handler)
2635
2636
  * is ALSO registered as a `consumer` so wrangler delivers its messages to this Worker's queue()
2636
2637
  * handler — both locally under `wrangler dev` and in production. Without the consumer entry the
2637
- * handler never runs (the bug that silently drops a queue-driven activity feed).
2638
+ * handler never runs (the bug that silently drops a queue-driven activity feed). A consumer that
2639
+ * sets `maxBatchTimeout` carries it through as wrangler's `max_batch_timeout` (lower delivery latency).
2638
2640
  *
2639
2641
  * @param resources - All resource descriptors from the manifest.
2640
2642
  * @returns The queues section (producers, plus consumers when any), or undefined when there are none.
2641
2643
  * @example
2642
2644
  * ```ts
2643
- * const q = buildQueues([{ kind: "queue", name: "tracker-activity", binding: "ACTIVITY", consumer: true }]);
2645
+ * const q = buildQueues([{ kind: "queue", name: "tracker-activity", binding: "ACTIVITY", consumer: true, maxBatchTimeout: 1 }]);
2644
2646
  * ```
2645
2647
  */
2646
2648
  const buildQueues = (resources) => {
@@ -2650,7 +2652,11 @@ const buildQueues = (resources) => {
2650
2652
  queue: resource.name,
2651
2653
  binding: resource.binding
2652
2654
  }));
2653
- const consumers = queueResources.filter((resource) => resource.consumer === true).map((resource) => ({ queue: resource.name }));
2655
+ const consumers = queueResources.filter((resource) => resource.consumer === true).map((resource) => {
2656
+ const entry = { queue: resource.name };
2657
+ if (resource.maxBatchTimeout !== void 0) entry.max_batch_timeout = resource.maxBatchTimeout;
2658
+ return entry;
2659
+ });
2654
2660
  return consumers.length > 0 ? {
2655
2661
  producers,
2656
2662
  consumers
package/dist/cli.cjs CHANGED
@@ -1,4 +1,4 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_cli = require("./cli-DQcpvh2s.cjs");
2
+ const require_cli = require("./cli-DkoPBbJC.cjs");
3
3
  exports.cliPlugin = require_cli.cliPlugin;
4
4
  exports.deployPlugin = require_cli.deployPlugin;
package/dist/cli.d.cts CHANGED
@@ -1,2 +1,2 @@
1
- import { i as ResourceManifest, n as cliPlugin, r as ExternalManifest, t as deployPlugin } from "./index-DCweBI9s.cjs";
1
+ import { i as ResourceManifest, n as cliPlugin, r as ExternalManifest, t as deployPlugin } from "./index-BuY9o1u0.cjs";
2
2
  export { type ExternalManifest, type ResourceManifest, cliPlugin, deployPlugin };
package/dist/cli.d.mts CHANGED
@@ -1,2 +1,2 @@
1
- import { i as ResourceManifest, n as cliPlugin, r as ExternalManifest, t as deployPlugin } from "./index-DCweBI9s.mjs";
1
+ import { i as ResourceManifest, n as cliPlugin, r as ExternalManifest, t as deployPlugin } from "./index-BuY9o1u0.mjs";
2
2
  export { type ExternalManifest, type ResourceManifest, cliPlugin, deployPlugin };
package/dist/cli.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import { n as deployPlugin, t as cliPlugin } from "./cli-MICK1cvv.mjs";
1
+ import { n as deployPlugin, t as cliPlugin } from "./cli-By06KF-9.mjs";
2
2
  export { cliPlugin, deployPlugin };
@@ -179,6 +179,7 @@ type ResourceManifest = {
179
179
  name: string;
180
180
  binding: string;
181
181
  consumer?: boolean;
182
+ maxBatchTimeout?: number;
182
183
  } | {
183
184
  kind: "do";
184
185
  binding: string;
@@ -179,6 +179,7 @@ type ResourceManifest = {
179
179
  name: string;
180
180
  binding: string;
181
181
  consumer?: boolean;
182
+ maxBatchTimeout?: number;
182
183
  } | {
183
184
  kind: "do";
184
185
  binding: string;
package/dist/index.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_cli = require("./cli-DQcpvh2s.cjs");
2
+ const require_cli = require("./cli-DkoPBbJC.cjs");
3
3
  let _moku_labs_common = require("@moku-labs/common");
4
4
  //#region src/env-provider.ts
5
5
  /**
package/dist/index.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { a as WorkerConfig, c as WorkerPluginCtx, i as ResourceManifest, n as cliPlugin, o as WorkerEnv, r as ExternalManifest, s as WorkerEvents, t as deployPlugin } from "./index-DCweBI9s.cjs";
1
+ import { a as WorkerConfig, c as WorkerPluginCtx, i as ResourceManifest, n as cliPlugin, o as WorkerEnv, r as ExternalManifest, s as WorkerEvents, t as deployPlugin } from "./index-BuY9o1u0.cjs";
2
2
  import { envPlugin, logPlugin } from "@moku-labs/common";
3
3
  import { PluginCtx, PluginCtx as PluginCtx$1, PluginInstance } from "@moku-labs/core";
4
4
 
@@ -774,7 +774,14 @@ declare namespace types_d_exports$3 {
774
774
  type QueueInstance = {
775
775
  /** Base Cloudflare queue name (stage-suffixed at deploy, e.g. `tracker-activity-dev`). */name: string; /** Producer env binding the Queue resolves off the per-request `env` (e.g. `env.ACTIVITY`). */
776
776
  binding: string; /** Per-instance consumer handler — awaited once per message in `consume()`. Optional → no-op. */
777
- onMessage?: (message: Message, env: WorkerEnv) => Promise<void>; /** Marks this instance the default when more than one is configured. */
777
+ onMessage?: (message: Message, env: WorkerEnv) => Promise<void>;
778
+ /**
779
+ * Max seconds the consumer waits to fill a batch before delivering it (Cloudflare's
780
+ * `max_batch_timeout`, 0–60). Lower means lower delivery latency and smaller batches; omit to use
781
+ * Cloudflare's default (~5s). Written to the generated wrangler `consumers` entry, so it only has
782
+ * an effect on an instance that also declares an `onMessage` handler.
783
+ */
784
+ maxBatchTimeout?: number; /** Marks this instance the default when more than one is configured. */
778
785
  default?: boolean;
779
786
  };
780
787
  /**
@@ -861,6 +868,7 @@ type Api = QueueProducerApi & {
861
868
  name: string;
862
869
  binding: string;
863
870
  consumer?: boolean;
871
+ maxBatchTimeout?: number;
864
872
  }>;
865
873
  };
866
874
  /**
package/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { a as WorkerConfig, c as WorkerPluginCtx, i as ResourceManifest, n as cliPlugin, o as WorkerEnv, r as ExternalManifest, s as WorkerEvents, t as deployPlugin } from "./index-DCweBI9s.mjs";
1
+ import { a as WorkerConfig, c as WorkerPluginCtx, i as ResourceManifest, n as cliPlugin, o as WorkerEnv, r as ExternalManifest, s as WorkerEvents, t as deployPlugin } from "./index-BuY9o1u0.mjs";
2
2
  import { envPlugin, logPlugin } from "@moku-labs/common";
3
3
  import { PluginCtx, PluginCtx as PluginCtx$1, PluginInstance } from "@moku-labs/core";
4
4
 
@@ -774,7 +774,14 @@ declare namespace types_d_exports$3 {
774
774
  type QueueInstance = {
775
775
  /** Base Cloudflare queue name (stage-suffixed at deploy, e.g. `tracker-activity-dev`). */name: string; /** Producer env binding the Queue resolves off the per-request `env` (e.g. `env.ACTIVITY`). */
776
776
  binding: string; /** Per-instance consumer handler — awaited once per message in `consume()`. Optional → no-op. */
777
- onMessage?: (message: Message, env: WorkerEnv) => Promise<void>; /** Marks this instance the default when more than one is configured. */
777
+ onMessage?: (message: Message, env: WorkerEnv) => Promise<void>;
778
+ /**
779
+ * Max seconds the consumer waits to fill a batch before delivering it (Cloudflare's
780
+ * `max_batch_timeout`, 0–60). Lower means lower delivery latency and smaller batches; omit to use
781
+ * Cloudflare's default (~5s). Written to the generated wrangler `consumers` entry, so it only has
782
+ * an effect on an instance that also declares an `onMessage` handler.
783
+ */
784
+ maxBatchTimeout?: number; /** Marks this instance the default when more than one is configured. */
778
785
  default?: boolean;
779
786
  };
780
787
  /**
@@ -861,6 +868,7 @@ type Api = QueueProducerApi & {
861
868
  name: string;
862
869
  binding: string;
863
870
  consumer?: boolean;
871
+ maxBatchTimeout?: number;
864
872
  }>;
865
873
  };
866
874
  /**
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { a as kvPlugin, c as d1Plugin, d as createCore, f as createPlugin$1, i as queuesPlugin, l as bindingsPlugin, n as deployPlugin, o as durableObjectsPlugin, p as stagePlugin, r as storagePlugin, s as defineDurableObject, t as cliPlugin, u as coreConfig } from "./cli-MICK1cvv.mjs";
1
+ import { a as kvPlugin, c as d1Plugin, d as createCore, f as createPlugin$1, i as queuesPlugin, l as bindingsPlugin, n as deployPlugin, o as durableObjectsPlugin, p as stagePlugin, r as storagePlugin, s as defineDurableObject, t as cliPlugin, u as coreConfig } from "./cli-By06KF-9.mjs";
2
2
  import { envPlugin, logPlugin } from "@moku-labs/common";
3
3
  //#region src/env-provider.ts
4
4
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@moku-labs/worker",
3
- "version": "0.7.3",
3
+ "version": "0.8.0",
4
4
  "description": "Cloudflare Worker framework for Moku — Durable Objects, Queues, R2, D1, and KV plugins that compose with Moku Web.",
5
5
  "repository": {
6
6
  "type": "git",