@lunora/queue 0.0.0 → 1.0.0-alpha.2

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.
@@ -0,0 +1,18 @@
1
+ const queueBindingName = (exportName) => `QUEUE_${exportName.replaceAll(/(?<=[a-z0-9])(?=[A-Z])/g, "_").toUpperCase()}`;
2
+ const queueDefaultName = (exportName) => exportName.replaceAll(/(?<=[a-z0-9])(?=[A-Z])/g, "-").toLowerCase();
3
+ const defineQueue = (config) => {
4
+ const mode = config.mode ?? "push";
5
+ if (mode !== "push" && mode !== "pull") {
6
+ throw new TypeError(`defineQueue: \`mode\` must be "push" or "pull" (got ${JSON.stringify(config.mode)})`);
7
+ }
8
+ if (mode === "push" && typeof config.handler !== "function") {
9
+ throw new TypeError('defineQueue: `handler` must be a function for a push consumer (omit it only when `mode: "pull"`)');
10
+ }
11
+ if (config.name !== void 0 && (typeof config.name !== "string" || config.name.length === 0)) {
12
+ throw new TypeError("defineQueue: `name` must be a non-empty string when provided");
13
+ }
14
+ return { ...config, isLunoraQueue: true, mode };
15
+ };
16
+ const isQueueDefinition = (value) => typeof value === "object" && value !== null && value.isLunoraQueue === true;
17
+
18
+ export { defineQueue, isQueueDefinition, queueBindingName, queueDefaultName };
@@ -0,0 +1,18 @@
1
+ import { createQueueRunContext } from './createQueueRunContext-DVqG7Oyk.mjs';
2
+
3
+ const dispatchQueueBatch = async (batch, registry, options) => {
4
+ const entry = registry[batch.queue];
5
+ if (entry === void 0) {
6
+ const known = Object.keys(registry);
7
+ const suffix = known.length === 0 ? "no push queues are declared" : `known push queues: ${known.join(", ")}`;
8
+ throw new Error(`@lunora/queue: received a batch for queue "${batch.queue}" but no push handler is registered (${suffix})`);
9
+ }
10
+ const { handler } = entry.definition;
11
+ if (typeof handler !== "function") {
12
+ throw new TypeError(`@lunora/queue: queue "${batch.queue}" (${entry.exportName}) has no push handler — it is declared as a pull consumer`);
13
+ }
14
+ const context = createQueueRunContext({ env: options.env, exportName: entry.exportName, fetchImpl: options.fetchImpl });
15
+ await handler(context, batch);
16
+ };
17
+
18
+ export { dispatchQueueBatch };
package/package.json CHANGED
@@ -1,19 +1,49 @@
1
1
  {
2
2
  "name": "@lunora/queue",
3
- "version": "0.0.0",
4
- "description": "Placeholder to reserve the npm name. Real releases are published from CI install the latest version.",
3
+ "version": "1.0.0-alpha.2",
4
+ "description": "Cloudflare Queues for Lunora: defineQueue producers + consumers, the ctx.queues surface, and the generated queue() worker handler",
5
+ "keywords": [
6
+ "background-jobs",
7
+ "cloudflare",
8
+ "lunora",
9
+ "messaging",
10
+ "queues",
11
+ "workers"
12
+ ],
13
+ "homepage": "https://lunora.sh",
14
+ "bugs": "https://github.com/anolilab/lunora/issues",
5
15
  "license": "FSL-1.1-Apache-2.0",
6
16
  "author": {
7
17
  "name": "Daniel Bannert",
8
18
  "email": "d.bannert@anolilab.de"
9
19
  },
10
- "homepage": "https://lunora.sh",
11
20
  "repository": {
12
21
  "type": "git",
13
22
  "url": "git+https://github.com/anolilab/lunora.git",
14
23
  "directory": "packages/queue"
15
24
  },
25
+ "files": [
26
+ "./dist",
27
+ "README.md",
28
+ "LICENSE.md",
29
+ "__assets__"
30
+ ],
31
+ "type": "module",
32
+ "sideEffects": false,
33
+ "main": "./dist/index.mjs",
34
+ "module": "./dist/index.mjs",
35
+ "types": "./dist/index.d.ts",
36
+ "exports": {
37
+ ".": {
38
+ "types": "./dist/index.d.ts",
39
+ "import": "./dist/index.mjs"
40
+ },
41
+ "./package.json": "./package.json"
42
+ },
16
43
  "publishConfig": {
17
44
  "access": "public"
45
+ },
46
+ "engines": {
47
+ "node": "^22.15.0 || >=24.11.0"
18
48
  }
19
- }
49
+ }