kizunajs 2.0.0-beta.29 → 2.0.0-beta.30

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/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  A spec-driven framework for building fully typed REST APIs in TypeScript, where your route declarations produce the validation, the documentation, the clients, and the AI tools.
6
6
 
7
- [![npm](https://img.shields.io/npm/v/kizunajs/beta?color=blue&label=npm)](https://www.npmjs.com/package/kizunajs/v/2.0.0-beta.29)
7
+ [![npm](https://img.shields.io/npm/v/kizunajs/beta?color=blue&label=npm)](https://www.npmjs.com/package/kizunajs/v/2.0.0-beta.30)
8
8
  ![license](https://img.shields.io/badge/license-MIT-blue)
9
9
 
10
10
  [Documentation](https://kizunajs.com)
@@ -64,6 +64,7 @@ Follow the [quickstart](https://kizunajs.com/docs/quickstart), which goes from a
64
64
  | `@kizunajs/kotlin` | Kotlin client generation |
65
65
  | `@kizunajs/mcp` | MCP endpoint for AI assistants |
66
66
  | `@kizunajs/resend` | Email, newsletters and webhooks through Resend |
67
+ | `@kizunajs/pgmq` | pgmq job transport |
67
68
  | `@kizunajs/eslint-plugin` | ESLint rules |
68
69
  | `@kizunajs/cli` | Command line tooling |
69
70
 
@@ -92,9 +92,11 @@ const startJobs = (api, options) => {
92
92
  *
93
93
  * Returns `undefined` when the transport does not implement `start`.
94
94
  *
95
- * Each message goes through the same runner `queue` writes to, so its input is
96
- * validated against the schema it lands on rather than the one it left, and a
97
- * rejection propagates for the transport to retry.
95
+ * Each message's input is validated against the schema it lands on.
96
+ *
97
+ * A handler that throws, or returns a status of 400 or more, rejects. A
98
+ * returned status rejects as a `ResponseError`, so a transport can tell a `422`
99
+ * from a `503`.
98
100
  *
99
101
  * @example
100
102
  * const worker = await startJobWorker(api);
@@ -125,7 +127,8 @@ const startJobWorker = async (api, options) => {
125
127
  run: async (message) => {
126
128
  const jobFn = require_adapter.jobFnAt(runner, message.job);
127
129
  if (!jobFn) throw new Error(`No handler is bound for job "${message.job}" on this api.`);
128
- await jobFn.run(message.input);
130
+ const response = await jobFn.run(message.input);
131
+ if (response.status >= 400) throw new require_adapter.ResponseError(response);
129
132
  }
130
133
  });
131
134
  };
@@ -74,9 +74,11 @@ interface StartJobWorkerOptions {
74
74
  *
75
75
  * Returns `undefined` when the transport does not implement `start`.
76
76
  *
77
- * Each message goes through the same runner `queue` writes to, so its input is
78
- * validated against the schema it lands on rather than the one it left, and a
79
- * rejection propagates for the transport to retry.
77
+ * Each message's input is validated against the schema it lands on.
78
+ *
79
+ * A handler that throws, or returns a status of 400 or more, rejects. A
80
+ * returned status rejects as a `ResponseError`, so a transport can tell a `422`
81
+ * from a `503`.
80
82
  *
81
83
  * @example
82
84
  * const worker = await startJobWorker(api);
@@ -74,9 +74,11 @@ interface StartJobWorkerOptions {
74
74
  *
75
75
  * Returns `undefined` when the transport does not implement `start`.
76
76
  *
77
- * Each message goes through the same runner `queue` writes to, so its input is
78
- * validated against the schema it lands on rather than the one it left, and a
79
- * rejection propagates for the transport to retry.
77
+ * Each message's input is validated against the schema it lands on.
78
+ *
79
+ * A handler that throws, or returns a status of 400 or more, rejects. A
80
+ * returned status rejects as a `ResponseError`, so a transport can tell a `422`
81
+ * from a `503`.
80
82
  *
81
83
  * @example
82
84
  * const worker = await startJobWorker(api);
@@ -1,5 +1,5 @@
1
1
  import { D as scheduleExpression, O as scheduleTimezone, m as flattenJobs, w as nextRun } from "./plugin-server-D8XrYDQU.mjs";
2
- import { $ as waitUntil, Q as jobFnAt, h as boundJobKeys, k as jobRunnerFrom, o as JOBS_META } from "./adapter-cRyeEuKZ.mjs";
2
+ import { $ as waitUntil, Q as jobFnAt, et as ResponseError, h as boundJobKeys, k as jobRunnerFrom, o as JOBS_META } from "./adapter-cRyeEuKZ.mjs";
3
3
  //#region src/start-jobs.ts
4
4
  /**
5
5
  * The dedupe key an occurrence gets. Every instance ticking the same minute
@@ -91,9 +91,11 @@ const startJobs = (api, options) => {
91
91
  *
92
92
  * Returns `undefined` when the transport does not implement `start`.
93
93
  *
94
- * Each message goes through the same runner `queue` writes to, so its input is
95
- * validated against the schema it lands on rather than the one it left, and a
96
- * rejection propagates for the transport to retry.
94
+ * Each message's input is validated against the schema it lands on.
95
+ *
96
+ * A handler that throws, or returns a status of 400 or more, rejects. A
97
+ * returned status rejects as a `ResponseError`, so a transport can tell a `422`
98
+ * from a `503`.
97
99
  *
98
100
  * @example
99
101
  * const worker = await startJobWorker(api);
@@ -124,7 +126,8 @@ const startJobWorker = async (api, options) => {
124
126
  run: async (message) => {
125
127
  const jobFn = jobFnAt(runner, message.job);
126
128
  if (!jobFn) throw new Error(`No handler is bound for job "${message.job}" on this api.`);
127
- await jobFn.run(message.input);
129
+ const response = await jobFn.run(message.input);
130
+ if (response.status >= 400) throw new ResponseError(response);
128
131
  }
129
132
  });
130
133
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kizunajs",
3
- "version": "2.0.0-beta.29",
3
+ "version": "2.0.0-beta.30",
4
4
  "description": "Route declaration, validation, and the adapter API for Kizuna.js",
5
5
  "keywords": [
6
6
  "kizunajs",
@@ -8,6 +8,7 @@ import {
8
8
  type JobsMeta,
9
9
  type JobWorker,
10
10
  } from './adapter.js';
11
+ import { ResponseError } from './response-error.js';
11
12
 
12
13
  export interface StartJobWorkerOptions {
13
14
  /**
@@ -31,9 +32,11 @@ export interface StartJobWorkerOptions {
31
32
  *
32
33
  * Returns `undefined` when the transport does not implement `start`.
33
34
  *
34
- * Each message goes through the same runner `queue` writes to, so its input is
35
- * validated against the schema it lands on rather than the one it left, and a
36
- * rejection propagates for the transport to retry.
35
+ * Each message's input is validated against the schema it lands on.
36
+ *
37
+ * A handler that throws, or returns a status of 400 or more, rejects. A
38
+ * returned status rejects as a `ResponseError`, so a transport can tell a `422`
39
+ * from a `503`.
37
40
  *
38
41
  * @example
39
42
  * const worker = await startJobWorker(api);
@@ -74,7 +77,12 @@ export const startJobWorker = async (api: unknown, options?: StartJobWorkerOptio
74
77
  run: async (message) => {
75
78
  const jobFn = jobFnAt(runner, message.job);
76
79
  if (!jobFn) throw new Error(`No handler is bound for job "${message.job}" on this api.`);
77
- await jobFn.run(message.input);
80
+ const response = (await jobFn.run(message.input)) as {
81
+ status: number;
82
+ body: unknown;
83
+ };
84
+ // A returned 503 asks for a retry as plainly as a thrown one does.
85
+ if (response.status >= 400) throw new ResponseError(response);
78
86
  },
79
87
  });
80
88
  };