@rotorsoft/act-http 1.4.0 → 1.5.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.
- package/README.md +33 -0
- package/dist/.tsbuildinfo +1 -1
- package/dist/@types/openapi/index.d.ts +191 -0
- package/dist/@types/openapi/index.d.ts.map +1 -0
- package/dist/api/index.js +1 -0
- package/dist/chunk-PZ5AY32C.js +10 -0
- package/dist/chunk-PZ5AY32C.js.map +1 -0
- package/dist/hono/index.js +1 -0
- package/dist/hono/index.js.map +1 -1
- package/dist/openapi/index.cjs +14682 -0
- package/dist/openapi/index.cjs.map +1 -0
- package/dist/openapi/index.js +14659 -0
- package/dist/openapi/index.js.map +1 -0
- package/dist/receiver/express/index.js +1 -0
- package/dist/receiver/express/index.js.map +1 -1
- package/dist/receiver/fastify/index.js +1 -0
- package/dist/receiver/fastify/index.js.map +1 -1
- package/dist/receiver/hono/index.js +1 -0
- package/dist/receiver/index.js +1 -0
- package/dist/receiver/index.js.map +1 -1
- package/dist/receiver/trpc/index.js +1 -0
- package/dist/receiver/trpc/index.js.map +1 -1
- package/dist/sse/index.js +2 -0
- package/dist/sse/index.js.map +1 -1
- package/dist/trpc/index.js +1 -0
- package/dist/trpc/index.js.map +1 -1
- package/dist/webhook/index.js +2 -0
- package/dist/webhook/index.js.map +1 -1
- package/package.json +6 -1
package/README.md
CHANGED
|
@@ -210,6 +210,31 @@ api.use("*", authenticated((c) => resolveActorFromJwt(c)));
|
|
|
210
210
|
// Hand-written routes alongside the generated ones now see c.get("actor") typed.
|
|
211
211
|
```
|
|
212
212
|
|
|
213
|
+
### `openapi` — OpenAPI 3.1 document emitter
|
|
214
|
+
|
|
215
|
+
```ts
|
|
216
|
+
import { openapi } from "@rotorsoft/act-http/openapi";
|
|
217
|
+
|
|
218
|
+
const doc = openapi(app, {
|
|
219
|
+
info: { title: "Wolfdesk API", version: "1.0.0" },
|
|
220
|
+
servers: [{ url: "https://api.example.com" }],
|
|
221
|
+
// Document the optional cross-cutting headers that the live REST API accepts.
|
|
222
|
+
idempotency: true,
|
|
223
|
+
expectedVersion: true,
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
// Serve alongside the Hono adapter:
|
|
227
|
+
api.get("/openapi.json", (c) => c.json(doc));
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
Pure data emit — no runtime dep on Hono or tRPC. The doc walks `app.registry.actions` once at function call and emits one `POST <basePath>/actions/<actionName>` operation per action, deriving the request-body schema from each action's Zod definition via Zod 4's native `z.toJSONSchema` (OpenAPI 3.1 uses JSON Schema 2020-12 as its schema dialect — no conversion layer needed).
|
|
231
|
+
|
|
232
|
+
**The doc describes the Hono REST surface, not tRPC.** tRPC's URL convention (`POST /trpc/<procedure>`, JSON-RPC-style body framing, batching) doesn't model cleanly as OpenAPI operations; tRPC consumers share types directly via `typeof router` and don't need a doc. The path shape this emitter produces matches `@rotorsoft/act-http/hono` by construction: same default `basePath` (`/api`), same request/response shapes, same error envelope. If the operator overrides `basePath` on the Hono adapter, pass the same value here so the doc keeps describing the live routes. tRPC and Hono can run side-by-side at different mount points on the same Act instance.
|
|
233
|
+
|
|
234
|
+
The same shared `ApiError` envelope underwrites cross-transport consistency: it's referenced once from `components.responses` and every error code (`400`, `409`, `410`, `412`, `422`, `500`) points at it. The doc and the live REST API agree on framework-error shapes by construction.
|
|
235
|
+
|
|
236
|
+
Output is deterministic given the same registry — entries land in `Object.entries(app.registry.actions)` iteration order. CI can snapshot the result to catch unintended API-surface changes; one merge that quietly changes a Zod schema or adds a new action surfaces as a doc diff in the same PR.
|
|
237
|
+
|
|
213
238
|
### `sse` — live state broadcast
|
|
214
239
|
|
|
215
240
|
```ts
|
|
@@ -292,6 +317,14 @@ Auto-generated REST surface for the act-http-api epic (#835).
|
|
|
292
317
|
- **`HonoOptions`** — `{ actor, stream, expectedVersion?, idempotency?, basePath? }`. `actor` is the `ActorExtractor`. `stream` returns the target stream per call. `expectedVersion` threads `Target.expectedVersion` for optimistic concurrency — returning `undefined` skips the check. `idempotency` is optional — `{ store: IdempotencyStore; keyFrom?: (c) => string | undefined }` — when set, the route honors `Idempotency-Key` via `withIdempotency`; default `keyFrom` reads the `Idempotency-Key` header. Duplicate claims return `409 / CONFLICT`. `basePath` defaults to `/api`.
|
|
293
318
|
- **`ActMiddlewareVariables`** — `{ actor: Actor }`. Use as the `Variables` generic on a host Hono instance to get `c.get("actor")` typed downstream of `authenticated`.
|
|
294
319
|
|
|
320
|
+
### `/openapi` subpath
|
|
321
|
+
|
|
322
|
+
OpenAPI 3.1 document emitter for the act-http-api epic (#835).
|
|
323
|
+
|
|
324
|
+
- **`openapi(app, options) → OpenAPIDocument`** — generator function. Walks `app.registry.actions` once and returns a valid OpenAPI 3.1 document object. Each action becomes a `POST <basePath>/actions/<actionName>` operation; the request-body schema comes from Zod 4's `z.toJSONSchema` against the action's registered schema. Error responses reference the shared `#/components/responses/ApiError`. Output is pure data — serve as `/openapi.json`, write to disk during CI, pipe to client codegen.
|
|
325
|
+
- **`OpenAPIOptions`** — `{ info, servers?, basePath?, idempotency?, expectedVersion? }`. `info.title` and `info.version` are required non-empty strings. `servers[].url` may contain `{variable}` template syntax; bare URLs are validated through `URL`'s parser. `basePath` defaults to `/api` (mirrors the Hono sibling). `idempotency` and `expectedVersion` are booleans (default `false`); when `true`, every mutation operation documents the corresponding optional header (`Idempotency-Key` / `If-Match`).
|
|
326
|
+
- **`OpenAPIDocument`** + a structural subset of the OpenAPI 3.1 types (`OpenAPIInfo`, `OpenAPIServer`, `OpenAPIPathItem`, `OpenAPIOperation`, `OpenAPIParameter`, `OpenAPIRequestBody`, `OpenAPIResponse`, `OpenAPIComponents`). Intentionally lighter than the full `openapi-types` package so post-processing doesn't fight the type system; cast to a fuller type when downstream consumers need it.
|
|
327
|
+
|
|
295
328
|
### `/sse` subpath
|
|
296
329
|
|
|
297
330
|
- **`BroadcastChannel<S>`** — server-side broadcast manager with per-stream subscriber sets and an LRU state cache.
|