@adhd/apigen-plugin-api-fastify 0.1.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.
@@ -0,0 +1,5 @@
1
+ import { HTTP_STATUS } from '@adhd/apigen-errors';
2
+ import { PluginInput, PluginOutput } from '@adhd/apigen-core';
3
+
4
+ export declare function generate(input: PluginInput): PluginOutput;
5
+ export { HTTP_STATUS };
@@ -0,0 +1,4 @@
1
+ import { OutputPlugin } from '@adhd/apigen-core';
2
+
3
+ export declare const apiFastifyPlugin: OutputPlugin;
4
+ export default apiFastifyPlugin;
package/lib/run.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ import { RunInput } from '@adhd/apigen-core';
2
+
3
+ export declare function run(input: RunInput): Promise<void>;
@@ -0,0 +1,24 @@
1
+ import { ApiStream } from '@adhd/apigen-runtime';
2
+ import { FastifyRequest, FastifyReply } from 'fastify';
3
+
4
+ /**
5
+ * Stream `apiStream` to the HTTP response as SSE.
6
+ *
7
+ * Sets `Content-Type: text/event-stream` and `Transfer-Encoding: chunked`.
8
+ * Each chunk is serialised as a `data: <JSON>\n\n` SSE frame.
9
+ *
10
+ * Error handling:
11
+ * - before first chunk: the reply status is set to the `ApiError` HTTP status
12
+ * (or 500) and the body is the `ApiError` JSON (normal §9 path).
13
+ * - after first chunk: a terminal `event: error\ndata: <JSON>\n\n` frame is
14
+ * flushed and the response is ended (Connect semantics).
15
+ *
16
+ * Cancellation: when the client disconnects (`req.raw` emits `'close'`), the
17
+ * in-flight stream is aborted via an internal `AbortController`. The stream
18
+ * terminates cleanly (end path — §11).
19
+ *
20
+ * @param stream - the `ApiStream` from the harness
21
+ * @param req - the Fastify request (used for client-disconnect detection)
22
+ * @param reply - the Fastify reply (raw `res` is used for direct writes)
23
+ */
24
+ export declare function sendStreamSse(stream: ApiStream<unknown>, req: FastifyRequest, reply: FastifyReply): Promise<void>;
package/package.json ADDED
@@ -0,0 +1,15 @@
1
+ {
2
+ "name": "@adhd/apigen-plugin-api-fastify",
3
+ "version": "0.1.0",
4
+ "main": "./index.js",
5
+ "dependencies": {
6
+ "@adhd/apigen-core": "^0.1.0",
7
+ "@adhd/apigen-runtime": "^0.1.0",
8
+ "fastify": "^4.0.0"
9
+ },
10
+ "publishConfig": {
11
+ "access": "public"
12
+ },
13
+ "module": "./index.mjs",
14
+ "types": "./index.d.ts"
15
+ }