ts-procedures 10.1.1 → 10.2.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/CHANGELOG.md +26 -65
- package/README.md +2 -0
- package/agent_config/claude-code/skills/ts-procedures/anti-patterns.md +8 -0
- package/agent_config/claude-code/skills/ts-procedures/api-reference.md +25 -22
- package/agent_config/claude-code/skills/ts-procedures/patterns.md +24 -13
- package/agent_config/copilot/copilot-instructions.md +1 -1
- package/agent_config/cursor/cursorrules +1 -1
- package/build/adapters/hono/envelope-parity.test.js +6 -17
- package/build/adapters/hono/envelope-parity.test.js.map +1 -1
- package/build/adapters/hono/handlers/http-stream.d.ts +2 -1
- package/build/adapters/hono/handlers/http-stream.js +9 -2
- package/build/adapters/hono/handlers/http-stream.js.map +1 -1
- package/build/adapters/hono/handlers/http.d.ts +2 -1
- package/build/adapters/hono/handlers/http.js +9 -2
- package/build/adapters/hono/handlers/http.js.map +1 -1
- package/build/adapters/hono/handlers/rpc.d.ts +2 -1
- package/build/adapters/hono/handlers/rpc.js +9 -2
- package/build/adapters/hono/handlers/rpc.js.map +1 -1
- package/build/adapters/hono/handlers/stream.d.ts +2 -1
- package/build/adapters/hono/handlers/stream.js +9 -2
- package/build/adapters/hono/handlers/stream.js.map +1 -1
- package/build/adapters/hono/index.d.ts +14 -7
- package/build/adapters/hono/index.js +45 -5
- package/build/adapters/hono/index.js.map +1 -1
- package/build/adapters/hono/index.test.js +55 -0
- package/build/adapters/hono/index.test.js.map +1 -1
- package/build/adapters/hono/request.d.ts +7 -0
- package/build/adapters/hono/request.js +15 -0
- package/build/adapters/hono/request.js.map +1 -1
- package/build/adapters/hono/types.d.ts +31 -0
- package/build/adapters/hono/types.js.map +1 -1
- package/build/codegen/bin/cli.js +1 -1
- package/build/codegen/bin/cli.js.map +1 -1
- package/build/codegen/constants.js +2 -2
- package/build/codegen/constants.js.map +1 -1
- package/build/codegen/emit/api-route.js +1 -1
- package/build/codegen/emit/api-route.js.map +1 -1
- package/build/codegen/emit/scope-file.js +1 -1
- package/build/codegen/emit/scope-file.js.map +1 -1
- package/build/codegen/emit-errors.integration.test.js +2 -2
- package/build/codegen/emit-errors.integration.test.js.map +1 -1
- package/build/codegen/resolve-envelope.js +1 -1
- package/build/codegen/resolve-envelope.js.map +1 -1
- package/build/codegen/test-helpers/run-tsc.js +1 -1
- package/build/codegen/test-helpers/run-tsc.js.map +1 -1
- package/build/core/create-http-stream.d.ts +3 -14
- package/build/core/create-http-stream.js +4 -2
- package/build/core/create-http-stream.js.map +1 -1
- package/build/core/create-http.d.ts +2 -9
- package/build/core/create-http.js +3 -2
- package/build/core/create-http.js.map +1 -1
- package/build/core/create-http.test-d.d.ts +1 -0
- package/build/core/create-http.test-d.js +104 -0
- package/build/core/create-http.test-d.js.map +1 -0
- package/build/core/create-stream.js +6 -2
- package/build/core/create-stream.js.map +1 -1
- package/build/core/create.js +5 -4
- package/build/core/create.js.map +1 -1
- package/build/core/create.test.js +63 -0
- package/build/core/create.test.js.map +1 -1
- package/build/core/internal.d.ts +16 -0
- package/build/core/internal.js +22 -0
- package/build/core/internal.js.map +1 -1
- package/build/core/procedures.d.ts +9 -16
- package/build/core/procedures.js +4 -0
- package/build/core/procedures.js.map +1 -1
- package/build/core/types.d.ts +85 -4
- package/build/errors.d.ts +33 -0
- package/build/errors.js +91 -0
- package/build/errors.js.map +1 -0
- package/build/errors.test.d.ts +1 -0
- package/build/errors.test.js +122 -0
- package/build/errors.test.js.map +1 -0
- package/build/exports.d.ts +1 -2
- package/build/exports.js +0 -4
- package/build/exports.js.map +1 -1
- package/build/implementations/http/doc-registry.d.ts +28 -0
- package/build/implementations/http/doc-registry.js +96 -0
- package/build/implementations/http/doc-registry.js.map +1 -0
- package/build/implementations/http/doc-registry.test.d.ts +1 -0
- package/build/implementations/http/doc-registry.test.js +516 -0
- package/build/implementations/http/doc-registry.test.js.map +1 -0
- package/build/implementations/http/error-taxonomy.d.ts +249 -0
- package/build/implementations/http/error-taxonomy.js +252 -0
- package/build/implementations/http/error-taxonomy.js.map +1 -0
- package/build/implementations/http/error-taxonomy.test.d.ts +1 -0
- package/build/implementations/http/error-taxonomy.test.js +399 -0
- package/build/implementations/http/error-taxonomy.test.js.map +1 -0
- package/build/implementations/http/express-rpc/error-taxonomy.test.d.ts +1 -0
- package/build/implementations/http/express-rpc/error-taxonomy.test.js +83 -0
- package/build/implementations/http/express-rpc/error-taxonomy.test.js.map +1 -0
- package/build/implementations/http/express-rpc/index.d.ts +125 -0
- package/build/implementations/http/express-rpc/index.js +216 -0
- package/build/implementations/http/express-rpc/index.js.map +1 -0
- package/build/implementations/http/express-rpc/index.test.d.ts +1 -0
- package/build/implementations/http/express-rpc/index.test.js +684 -0
- package/build/implementations/http/express-rpc/index.test.js.map +1 -0
- package/build/implementations/http/express-rpc/types.d.ts +11 -0
- package/build/implementations/http/express-rpc/types.js +2 -0
- package/build/implementations/http/express-rpc/types.js.map +1 -0
- package/build/implementations/http/hono-api/error-taxonomy.test.d.ts +1 -0
- package/build/implementations/http/hono-api/error-taxonomy.test.js +137 -0
- package/build/implementations/http/hono-api/error-taxonomy.test.js.map +1 -0
- package/build/implementations/http/hono-api/index.d.ts +151 -0
- package/build/implementations/http/hono-api/index.js +344 -0
- package/build/implementations/http/hono-api/index.js.map +1 -0
- package/build/implementations/http/hono-api/index.test.d.ts +1 -0
- package/build/implementations/http/hono-api/index.test.js +992 -0
- package/build/implementations/http/hono-api/index.test.js.map +1 -0
- package/build/implementations/http/hono-api/types.d.ts +13 -0
- package/build/implementations/http/hono-api/types.js +2 -0
- package/build/implementations/http/hono-api/types.js.map +1 -0
- package/build/implementations/http/hono-rpc/error-taxonomy.test.d.ts +1 -0
- package/build/implementations/http/hono-rpc/error-taxonomy.test.js +64 -0
- package/build/implementations/http/hono-rpc/error-taxonomy.test.js.map +1 -0
- package/build/implementations/http/hono-rpc/index.d.ts +130 -0
- package/build/implementations/http/hono-rpc/index.js +209 -0
- package/build/implementations/http/hono-rpc/index.js.map +1 -0
- package/build/implementations/http/hono-rpc/index.test.d.ts +1 -0
- package/build/implementations/http/hono-rpc/index.test.js +828 -0
- package/build/implementations/http/hono-rpc/index.test.js.map +1 -0
- package/build/implementations/http/hono-rpc/types.d.ts +11 -0
- package/build/implementations/http/hono-rpc/types.js +2 -0
- package/build/implementations/http/hono-rpc/types.js.map +1 -0
- package/build/implementations/http/hono-stream/error-taxonomy.test.d.ts +1 -0
- package/build/implementations/http/hono-stream/error-taxonomy.test.js +159 -0
- package/build/implementations/http/hono-stream/error-taxonomy.test.js.map +1 -0
- package/build/implementations/http/hono-stream/index.d.ts +171 -0
- package/build/implementations/http/hono-stream/index.js +415 -0
- package/build/implementations/http/hono-stream/index.js.map +1 -0
- package/build/implementations/http/hono-stream/index.test.d.ts +1 -0
- package/build/implementations/http/hono-stream/index.test.js +1383 -0
- package/build/implementations/http/hono-stream/index.test.js.map +1 -0
- package/build/implementations/http/hono-stream/types.d.ts +15 -0
- package/build/implementations/http/hono-stream/types.js +2 -0
- package/build/implementations/http/hono-stream/types.js.map +1 -0
- package/build/implementations/http/on-request-error.test.d.ts +1 -0
- package/build/implementations/http/on-request-error.test.js +173 -0
- package/build/implementations/http/on-request-error.test.js.map +1 -0
- package/build/implementations/http/route-errors.test.d.ts +1 -0
- package/build/implementations/http/route-errors.test.js +139 -0
- package/build/implementations/http/route-errors.test.js.map +1 -0
- package/build/implementations/types.d.ts +192 -0
- package/build/implementations/types.js +2 -0
- package/build/implementations/types.js.map +1 -0
- package/build/index.d.ts +165 -0
- package/build/index.js +258 -0
- package/build/index.js.map +1 -0
- package/build/index.test.d.ts +1 -0
- package/build/index.test.js +920 -0
- package/build/index.test.js.map +1 -0
- package/build/schema/extract-json-schema.d.ts +2 -0
- package/build/schema/extract-json-schema.js +12 -0
- package/build/schema/extract-json-schema.js.map +1 -0
- package/build/schema/extract-json-schema.test.d.ts +1 -0
- package/build/schema/extract-json-schema.test.js +23 -0
- package/build/schema/extract-json-schema.test.js.map +1 -0
- package/build/schema/parser.d.ts +28 -0
- package/build/schema/parser.js +170 -0
- package/build/schema/parser.js.map +1 -0
- package/build/schema/parser.test.d.ts +1 -0
- package/build/schema/parser.test.js +120 -0
- package/build/schema/parser.test.js.map +1 -0
- package/build/schema/resolve-schema-lib.d.ts +12 -0
- package/build/schema/resolve-schema-lib.js +11 -0
- package/build/schema/resolve-schema-lib.js.map +1 -0
- package/build/schema/resolve-schema-lib.test.d.ts +1 -0
- package/build/schema/resolve-schema-lib.test.js +17 -0
- package/build/schema/resolve-schema-lib.test.js.map +1 -0
- package/build/schema/typebox.d.ts +1 -1
- package/build/schema/typebox.js +2 -20
- package/build/schema/typebox.js.map +1 -1
- package/build/schema/typebox.test.js +0 -10
- package/build/schema/typebox.test.js.map +1 -1
- package/build/schema/types.d.ts +8 -0
- package/build/schema/types.js +2 -0
- package/build/schema/types.js.map +1 -0
- package/build/server/context.d.ts +12 -2
- package/build/server/context.js +49 -4
- package/build/server/context.js.map +1 -1
- package/build/server/context.test.js +32 -1
- package/build/server/context.test.js.map +1 -1
- package/build/server/doc-registry.js +0 -3
- package/build/server/doc-registry.js.map +1 -1
- package/build/server/doc-registry.test.js +0 -31
- package/build/server/doc-registry.test.js.map +1 -1
- package/build/server/index.d.ts +0 -1
- package/build/server/index.js +0 -1
- package/build/server/index.js.map +1 -1
- package/build/server/types.d.ts +6 -27
- package/build/stack-utils.d.ts +25 -0
- package/build/stack-utils.js +95 -0
- package/build/stack-utils.js.map +1 -0
- package/build/stack-utils.test.d.ts +1 -0
- package/build/stack-utils.test.js +80 -0
- package/build/stack-utils.test.js.map +1 -0
- package/docs/core.md +8 -0
- package/docs/http-integrations.md +41 -27
- package/package.json +8 -8
- package/src/adapters/astro/README.md +2 -0
- package/src/adapters/hono/envelope-parity.test.ts +6 -18
- package/src/adapters/hono/handlers/http-stream.ts +12 -3
- package/src/adapters/hono/handlers/http.ts +12 -3
- package/src/adapters/hono/handlers/rpc.ts +12 -3
- package/src/adapters/hono/handlers/stream.ts +12 -3
- package/src/adapters/hono/index.test.ts +70 -0
- package/src/adapters/hono/index.ts +53 -11
- package/src/adapters/hono/request.ts +18 -0
- package/src/adapters/hono/types.ts +37 -0
- package/src/codegen/bin/cli.ts +1 -1
- package/src/codegen/constants.ts +2 -2
- package/src/codegen/emit/api-route.ts +1 -1
- package/src/codegen/emit/scope-file.ts +1 -2
- package/src/codegen/emit-errors.integration.test.ts +2 -2
- package/src/codegen/resolve-envelope.ts +1 -1
- package/src/codegen/test-helpers/run-tsc.ts +0 -1
- package/src/core/create-http-stream.ts +20 -13
- package/src/core/create-http.test-d.ts +154 -0
- package/src/core/create-http.ts +19 -8
- package/src/core/create-stream.ts +12 -4
- package/src/core/create.test.ts +74 -0
- package/src/core/create.ts +10 -5
- package/src/core/internal.ts +35 -0
- package/src/core/procedures.ts +4 -0
- package/src/core/types.ts +99 -4
- package/src/exports.ts +6 -4
- package/src/schema/typebox.test.ts +0 -12
- package/src/schema/typebox.ts +2 -21
- package/src/server/context.test.ts +39 -1
- package/src/server/context.ts +54 -4
- package/src/server/doc-registry.test.ts +0 -34
- package/src/server/doc-registry.ts +0 -3
- package/src/server/index.ts +0 -1
- package/src/server/types.ts +8 -27
- package/build/server/spec-version.d.ts +0 -24
- package/build/server/spec-version.js +0 -26
- package/build/server/spec-version.js.map +0 -1
- package/build/version.d.ts +0 -9
- package/build/version.js +0 -11
- package/build/version.js.map +0 -1
- package/docs/doc-envelope-spec-v1.md +0 -296
- package/docs/doc-envelope-v1.schema.json +0 -253
- package/src/server/spec-version.ts +0 -27
- package/src/version.ts +0 -11
package/CHANGELOG.md
CHANGED
|
@@ -4,85 +4,46 @@ All notable changes to **ts-procedures** are documented in this file.
|
|
|
4
4
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
6
6
|
|
|
7
|
-
##
|
|
7
|
+
## Unreleased
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
change to generated output, docs, or validation behavior.
|
|
9
|
+
## 10.2.0 — 2026-06-25
|
|
11
10
|
|
|
12
|
-
###
|
|
13
|
-
|
|
14
|
-
- **Top-level `Type.Unsafe(...)` channel schemas are recognized again.** TypeBox
|
|
15
|
-
1.2.0 tags `Type.Unsafe(...)` with a `~unsafe` marker *instead of* `~kind`, so
|
|
16
|
-
the built-in TypeBox adapter — which only looked for `~kind` — failed to detect
|
|
17
|
-
a bare top-level `Type.Unsafe(...)` used as a channel schema (e.g.
|
|
18
|
-
`schema: { params: Type.Unsafe(...) }`), throwing a `ProcedureRegistrationError`
|
|
19
|
-
at registration. Detection now keys off TypeBox v1's `~`-prefix marker
|
|
20
|
-
*convention* (via `Reflect.ownKeys`, since the markers are non-enumerable)
|
|
21
|
-
rather than a fixed list of names, so current and future `~*` markers are
|
|
22
|
-
recognized without further changes. `Type.Unsafe` nested inside a
|
|
23
|
-
`Type.Object(...)` was never affected.
|
|
24
|
-
|
|
25
|
-
### Notes
|
|
26
|
-
|
|
27
|
-
- Serialized JSON Schema was never affected: TypeBox's `~` markers are
|
|
28
|
-
non-enumerable, so they never reached `JSON.stringify` (DocEnvelope, codegen)
|
|
29
|
-
or AJV. The frozen codegen goldens and DocEnvelope parity fixtures are
|
|
30
|
-
unchanged. App devs only need to upgrade; no code changes required.
|
|
11
|
+
### Added
|
|
31
12
|
|
|
32
|
-
|
|
13
|
+
- **Factory middleware via `Procedures({ middleware })`.** Declare middleware at the factory level that runs with the *final* resolved context (your `TContext` + injected `error()` + `signal`) and the validated incoming call data. Enables "parse the incoming call" patterns for authorization, tenancy enforcement, enrichment, etc.
|
|
33
14
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
15
|
+
```ts
|
|
16
|
+
const Protected = Procedures<Ctx>({
|
|
17
|
+
middleware: [({ ctx, input, next }) => {
|
|
18
|
+
// ctx is fully resolved; input is schema-validated
|
|
19
|
+
if (input && 'orgId' in input && !ctx.user.tenants.includes(input.orgId)) {
|
|
20
|
+
throw ctx.error('tenant violation')
|
|
21
|
+
}
|
|
22
|
+
return next({ ctx: { ...ctx, checked: true } }) // optional augmentation
|
|
23
|
+
}]
|
|
24
|
+
})
|
|
25
|
+
```
|
|
37
26
|
|
|
38
|
-
|
|
27
|
+
Works for `Create*` / `CreateHttp*`, direct calls, and all adapters. Complements (runs after) builder-level middleware.
|
|
39
28
|
|
|
40
|
-
-
|
|
41
|
-
identifying the envelope wire format, emitted on every envelope produced by
|
|
42
|
-
`DocRegistry.toJSON()` / `builder.toDocEnvelope()`. Bumped **only** when the
|
|
43
|
-
envelope shape changes — never on routine package releases — so consumers get
|
|
44
|
-
a stable signal to branch their parser on. An absent `specVersion` MUST be
|
|
45
|
-
treated as `1`. Exported as `DOC_ENVELOPE_SPEC_VERSION` from `ts-procedures`
|
|
46
|
-
and `ts-procedures/server`.
|
|
47
|
-
- **`DocEnvelope.generatorVersion`** — the ts-procedures package version that
|
|
48
|
-
produced the envelope (e.g. `"10.1.0"`), for telemetry/debugging only; not a
|
|
49
|
-
parse-compatibility signal. Exported as `DOC_ENVELOPE_GENERATOR_VERSION` from
|
|
50
|
-
`ts-procedures/server`. Strippable via the `transform` hook for servers that
|
|
51
|
-
don't want to advertise the version on a public docs endpoint.
|
|
52
|
-
- **DocEnvelope wire-contract docs** — `docs/doc-envelope-spec-v1.md` plus a
|
|
53
|
-
validatable JSON Schema at `docs/doc-envelope-v1.schema.json` (filenames pinned
|
|
54
|
-
to the envelope `specVersion`), for building third-party tools against the
|
|
55
|
-
served envelope.
|
|
29
|
+
- **HonoAppBuilder middleware & context composition.** First-class support on the builder:
|
|
56
30
|
|
|
57
|
-
|
|
31
|
+
- `new HonoAppBuilder({ middleware: [mw...] })`
|
|
32
|
+
- `builder.use(mw)` (or `use(pattern, mw)`)
|
|
33
|
+
- `.register(factory, ctx, { middleware: [...], context?: extraLayer })`
|
|
58
34
|
|
|
59
|
-
|
|
60
|
-
both the codegen file header and the doc-envelope metadata.
|
|
35
|
+
Added `HonoRequestMiddleware`, `RegisterOptions`, and improved server `resolveFactoryContext` / `composeContextInits` to support arrays of context initializers (left-to-right shallow merge).
|
|
61
36
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
A maintenance major: the toolchain and supported peer ranges move up a major
|
|
65
|
-
across the board. There are **no source API changes** — every public export,
|
|
66
|
-
the codegen output (byte-identical against the frozen goldens), the client
|
|
67
|
-
runtime, and the DocEnvelope shape are unchanged. The version is bumped to major
|
|
68
|
-
purely to signal the dependency floor shift below.
|
|
37
|
+
- Updated documentation in `docs/core.md`, `docs/http-integrations.md`, `README.md`, and agent guidance to cover both layers and the recommended patterns (replacing manual `app.use` + stashing for protected surfaces).
|
|
69
38
|
|
|
70
39
|
### Changed
|
|
71
40
|
|
|
72
|
-
-
|
|
73
|
-
9 → 10, `globals` 15 → 17. The full gate (typecheck + 1251 tests including the
|
|
74
|
-
frozen codegen goldens + lint) passes on the new versions. The only code touched
|
|
75
|
-
was lint conformance for ESLint 10's newly-recommended rules
|
|
76
|
-
(`preserve-caught-error`, `no-useless-assignment`) — internal, no behavior change.
|
|
77
|
-
- **Astro optional peer: 6 → 7.** The optional peer range remains
|
|
78
|
-
`6.x.x || 7.x.x`, so existing Astro 6 consumers are unaffected; Astro 7 is now
|
|
79
|
-
tested and supported.
|
|
41
|
+
- Agent config now recommends "Prefer middleware + layered context for access levels" instead of always using separate factories.
|
|
80
42
|
|
|
81
|
-
|
|
43
|
+
## 9.3.0 — 2026-06-25
|
|
82
44
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
now targets TypeScript 6.
|
|
45
|
+
### Improved
|
|
46
|
+
- **DX: autocomplete for HTTP procedure schema channels.** `CreateHttp` and `CreateHttpStream` now surface `THttpReqInput` (and its alias `APIInput`) / `THttpResInput` inside `TCreateHttpConfig` so IDEs offer `pathParams | query | body | headers` (and `body | headers` for res) when writing `schema: { req: { ... }, res: { ... } }`. A small `HttpSchemaInput` helper keeps the public bag generics (`TReq`/`TRes`) while making literal keys visible. `satisfies APIInput` continues to work for extra checking. Same shapes are reused by `CreateHttpStream` for consistency.
|
|
86
47
|
|
|
87
48
|
## 9.2.0 — 2026-06-19
|
|
88
49
|
|
package/README.md
CHANGED
|
@@ -155,6 +155,8 @@ for await (const event of api.users.WatchUsers({})) { ... } // TypedStream
|
|
|
155
155
|
still fail fast at registration).
|
|
156
156
|
- Plug in another schema library with a 3-line `SchemaAdapter`
|
|
157
157
|
(`Procedures({ schema: { adapters: [zodAdapter] } })`).
|
|
158
|
+
- Factory middleware (ctx + input aware, runs for all procedures):
|
|
159
|
+
`Procedures({ middleware: [({ ctx, input, next }) => ...] })`.
|
|
158
160
|
|
|
159
161
|
## Streaming
|
|
160
162
|
|
|
@@ -725,6 +725,14 @@ const { CreateUser } = CreateHttp('CreateUser', {
|
|
|
725
725
|
|
|
726
726
|
**Fix:** Leave validation on for any factory whose handlers can be reached from untrusted callers. Only opt out when the factory is purely internal (e.g., a back-of-house procedure registry called from another already-validated procedure or a fully type-checked compile step).
|
|
727
727
|
|
|
728
|
+
---
|
|
729
|
+
|
|
730
|
+
## Raw `app.use` + stashing for auth/tenant (instead of builder middleware)
|
|
731
|
+
|
|
732
|
+
**Problem:** Manually doing `app.use('/api/*', authenticate(...))` before `HonoAppBuilder` + having ctx factories read "stashed" values leads to ordering issues, duplicated path logic, and hard-to-follow public vs protected surfaces.
|
|
733
|
+
|
|
734
|
+
**Fix:** Declare auth/tenant as `middleware` on the builder (config, `.use(mw)`, or per-`register({ middleware })`). Use `register(..., { context: extraLayer })` for augmentation. The old separate-factory + raw use style still works but is no longer the recommended default for this concern.
|
|
735
|
+
|
|
728
736
|
```typescript
|
|
729
737
|
// GOOD — public factory keeps runtime validation
|
|
730
738
|
const { Create: CreatePublic } = Procedures()
|
|
@@ -183,26 +183,15 @@ Registers a unary HTTP procedure (v8+). First-class surface for REST-style route
|
|
|
183
183
|
```typescript
|
|
184
184
|
function CreateHttp<
|
|
185
185
|
TName extends string,
|
|
186
|
-
TReq extends
|
|
187
|
-
TRes extends
|
|
186
|
+
TReq extends THttpReqInput | undefined = undefined,
|
|
187
|
+
TRes extends THttpResInput | undefined = undefined,
|
|
188
188
|
TErrorKey extends string = string
|
|
189
189
|
>(
|
|
190
190
|
name: TName,
|
|
191
|
-
config:
|
|
192
|
-
path: string
|
|
193
|
-
method: HttpMethod
|
|
194
|
-
successStatus?: number
|
|
195
|
-
scope?: string
|
|
196
|
-
errors?: TErrorKey[]
|
|
197
|
-
description?: string
|
|
198
|
-
schema: {
|
|
199
|
-
req?: TReq
|
|
200
|
-
res?: TRes
|
|
201
|
-
}
|
|
202
|
-
},
|
|
191
|
+
config: TCreateHttpConfig<TReq, TRes, TErrorKey>,
|
|
203
192
|
handler: (
|
|
204
193
|
ctx: TContext & TLocalContext,
|
|
205
|
-
req:
|
|
194
|
+
req: HttpReq<TReq>
|
|
206
195
|
) => Promise<HttpReturn<TRes>>
|
|
207
196
|
): {
|
|
208
197
|
[K in TName]: typeof handler
|
|
@@ -215,7 +204,7 @@ function CreateHttp<
|
|
|
215
204
|
|
|
216
205
|
- `config.path` — Route path. Supports Hono-style path params (`:id`).
|
|
217
206
|
- `config.method` — HTTP method.
|
|
218
|
-
- `config.schema.req` — Per-channel input schemas.
|
|
207
|
+
- `config.schema.req` — Per-channel input schemas. The keys `pathParams`, `query`, `body`, `headers` are surfaced by `THttpReqInput` (and `APIInput`) for autocomplete and `satisfies` checks. Each channel independently validated.
|
|
219
208
|
- `config.schema.res.body` — Response body schema (documentation; not runtime-validated).
|
|
220
209
|
- `config.schema.res.headers` — When declared, handler **must** return `{ body, headers }` instead of the body bare. The builder reads `headers` and forwards them to the HTTP response.
|
|
221
210
|
- `config.errors` — Taxonomy keys this route may emit (populates DocEnvelope for codegen).
|
|
@@ -1010,26 +999,40 @@ interface StreamHttpRouteDoc extends RPCConfig {
|
|
|
1010
999
|
}
|
|
1011
1000
|
```
|
|
1012
1001
|
|
|
1013
|
-
### TCreateHttpConfig
|
|
1002
|
+
### TCreateHttpConfig
|
|
1014
1003
|
|
|
1015
1004
|
Config type for `CreateHttp`. HTTP fields are first-class — no `APIConfig` type parameter needed on the factory.
|
|
1016
1005
|
|
|
1006
|
+
The `schema.req` and `schema.res` use special input shapes (`THttpReqInput`, `THttpResInput`) so that object literals get autocomplete for the channel keys (`pathParams`, `query`, `body`, `headers`). `TReq` / `TRes` carry the user's concrete schema types for inference.
|
|
1007
|
+
|
|
1017
1008
|
```typescript
|
|
1018
|
-
type TCreateHttpConfig<
|
|
1009
|
+
type TCreateHttpConfig<
|
|
1010
|
+
TReq extends THttpReqInput | undefined = undefined,
|
|
1011
|
+
TRes extends THttpResInput | undefined = undefined,
|
|
1012
|
+
TErrorKey extends string = string,
|
|
1013
|
+
> = {
|
|
1019
1014
|
path: string
|
|
1020
1015
|
method: HttpMethod
|
|
1021
1016
|
successStatus?: number
|
|
1022
1017
|
scope?: string
|
|
1023
1018
|
errors?: TErrorKey[]
|
|
1024
1019
|
description?: string
|
|
1025
|
-
schema
|
|
1026
|
-
req?: TReq
|
|
1027
|
-
res?: TRes
|
|
1020
|
+
schema?: {
|
|
1021
|
+
req?: HttpSchemaInput<THttpReqInput, TReq>
|
|
1022
|
+
res?: HttpSchemaInput<THttpResInput, TRes>
|
|
1028
1023
|
}
|
|
1029
1024
|
}
|
|
1030
1025
|
```
|
|
1031
1026
|
|
|
1032
|
-
|
|
1027
|
+
`APIInput` (re-exported from `ts-procedures/http`) is an alias for `THttpReqInput` and is the recommended type for `satisfies` checks on `req`:
|
|
1028
|
+
|
|
1029
|
+
```ts
|
|
1030
|
+
req: { pathParams: ..., query: ... } satisfies APIInput
|
|
1031
|
+
```
|
|
1032
|
+
|
|
1033
|
+
See also `THttpReqInput`, `THttpResInput`, `HttpSchemaInput`, and `APIInput`.
|
|
1034
|
+
|
|
1035
|
+
### APIHttpRouteDoc
|
|
1033
1036
|
|
|
1034
1037
|
```typescript
|
|
1035
1038
|
interface APIHttpRouteDoc {
|
|
@@ -796,28 +796,39 @@ const docs = getProcedures().map(proc => ({
|
|
|
796
796
|
|
|
797
797
|
---
|
|
798
798
|
|
|
799
|
-
##
|
|
799
|
+
## Access Control with Middleware + Layered Context (preferred)
|
|
800
|
+
|
|
801
|
+
Use builder middleware (`.use()`, config `middleware`, or per-register) + context composition for cross-cutting concerns like auth/tenant. This keeps surfaces on fewer factories/builders and makes ordering explicit.
|
|
800
802
|
|
|
801
803
|
```typescript
|
|
802
|
-
|
|
803
|
-
type AuthContext = { userId: string; requestId: string }
|
|
804
|
+
import { HonoAppBuilder, type HonoRequestMiddleware } from 'ts-procedures/hono'
|
|
804
805
|
|
|
805
|
-
|
|
806
|
-
|
|
806
|
+
type Base = { requestId: string }
|
|
807
|
+
type Authed = Base & { userId: string; tenant: string }
|
|
807
808
|
|
|
808
|
-
|
|
809
|
-
AuthRPC.Create('GetProfile', { scope: 'users', version: 1 }, async (ctx) => fetchProfile(ctx.userId))
|
|
809
|
+
const RPC = Procedures<Authed | Base, RPCConfig>()
|
|
810
810
|
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
811
|
+
RPC.Create('HealthCheck', { scope: 'health', version: 1 }, async () => ({ status: 'ok' }))
|
|
812
|
+
RPC.Create('GetProfile', { scope: 'users', version: 1 }, async (ctx) => fetchProfile(ctx.userId))
|
|
813
|
+
|
|
814
|
+
const authenticate: HonoRequestMiddleware = async (c, next) => {
|
|
815
|
+
const token = c.req.header('authorization')
|
|
816
|
+
if (!token) throw new Error('unauthorized')
|
|
817
|
+
;(c as any).set?.('tenant', 'acme')
|
|
818
|
+
await next()
|
|
819
|
+
}
|
|
820
|
+
|
|
821
|
+
const app = new HonoAppBuilder({ pathPrefix: '/api', middleware: [authenticate] })
|
|
822
|
+
.register(RPC, (c) => ({
|
|
823
|
+
requestId: c.req.header('x-request-id') || 'req',
|
|
824
|
+
tenant: (c as any).get?.('tenant') ?? 'public',
|
|
825
|
+
userId: 'u-123',
|
|
817
826
|
}))
|
|
818
827
|
.build()
|
|
819
828
|
```
|
|
820
829
|
|
|
830
|
+
Separate factories remain valid for truly disjoint context shapes.
|
|
831
|
+
|
|
821
832
|
---
|
|
822
833
|
|
|
823
834
|
## Documentation Generation with extendProcedureDoc
|
|
@@ -55,7 +55,7 @@ import type { RequestSource } from 'ts-procedures/server'
|
|
|
55
55
|
|
|
56
56
|
5. **Use TypeBox for schemas** (`import { Type } from 'typebox'`). Plain JSON Schema objects are not recognized. TypeBox is the built-in schema library; other libraries plug in via the `SchemaAdapter` interface (`Procedures({ schema: { adapters: [myAdapter] } })` — `{ name, detect, toJsonSchema }`). Custom adapters get runtime validation + docs only; compile-time `Infer<T>` inference is TypeBox-only. Default AJV config: `allErrors: true`, `coerceTypes: true`, `removeAdditional: true` — customize per factory via `Procedures({ validation: { ajv } })` (options merged over defaults, or a configured Ajv instance). The bundled TypeBox does **not** export `Type.Composite` — compose schemas with a flat property spread (`Type.Object({ ...Base.properties, name: Type.String() })`), which also keeps the generated JSON Schema a single `object` instead of an `allOf`.
|
|
57
57
|
|
|
58
|
-
6. **
|
|
58
|
+
6. **Prefer middleware + layered context for access levels.** Use `HonoAppBuilder` `middleware`, `.use()`, or per-`register({ middleware, context })` for tenant/auth. Separate factories are still valid for truly disjoint `TContext` shapes.
|
|
59
59
|
|
|
60
60
|
7. **onCreate callback enables framework integration.** Use for route registration, OpenAPI generation, logging.
|
|
61
61
|
|
|
@@ -55,7 +55,7 @@ import type { RequestSource } from 'ts-procedures/server'
|
|
|
55
55
|
|
|
56
56
|
5. **Use TypeBox for schemas** (`import { Type } from 'typebox'`). Plain JSON Schema objects are not recognized. TypeBox is the built-in schema library; other libraries plug in via the `SchemaAdapter` interface (`Procedures({ schema: { adapters: [myAdapter] } })` — `{ name, detect, toJsonSchema }`). Custom adapters get runtime validation + docs only; compile-time `Infer<T>` inference is TypeBox-only. Default AJV config: `allErrors: true`, `coerceTypes: true`, `removeAdditional: true` — customize per factory via `Procedures({ validation: { ajv } })` (options merged over defaults, or a configured Ajv instance). The bundled TypeBox does **not** export `Type.Composite` — compose schemas with a flat property spread (`Type.Object({ ...Base.properties, name: Type.String() })`), which also keeps the generated JSON Schema a single `object` instead of an `allOf`.
|
|
57
57
|
|
|
58
|
-
6. **
|
|
58
|
+
6. **Prefer middleware + layered context for access levels.** Use `HonoAppBuilder` `middleware`, `.use()`, or per-`register({ middleware, context })` for tenant/auth. Separate factories are still valid for truly disjoint `TContext` shapes.
|
|
59
59
|
|
|
60
60
|
7. **onCreate callback enables framework integration.** Use for route registration, OpenAPI generation, logging.
|
|
61
61
|
|
|
@@ -3,10 +3,8 @@ import { dirname, resolve } from 'node:path';
|
|
|
3
3
|
import { fileURLToPath } from 'node:url';
|
|
4
4
|
import { describe, expect, it } from 'vitest';
|
|
5
5
|
import { Type } from 'typebox';
|
|
6
|
-
import pkg from '../../../package.json' with { type: 'json' };
|
|
7
6
|
import { Procedures } from '../../core/procedures.js';
|
|
8
7
|
import { HonoAppBuilder, defineErrorTaxonomy } from './index.js';
|
|
9
|
-
import { DOC_ENVELOPE_SPEC_VERSION } from '../../server/spec-version.js';
|
|
10
8
|
/**
|
|
11
9
|
* THE envelope contract test: the v9 builder must emit a DocEnvelope
|
|
12
10
|
* deep-equal to what v8.6.0 emitted for the same procedure set. The fixture
|
|
@@ -16,15 +14,12 @@ import { DOC_ENVELOPE_SPEC_VERSION } from '../../server/spec-version.js';
|
|
|
16
14
|
* The envelope is codegen's input; if this test fails, generated client output
|
|
17
15
|
* WILL drift.
|
|
18
16
|
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
* never emitted. These are asserted explicitly below, then stripped before
|
|
26
|
-
* the deep-equal so the rest stays byte-for-byte with the v8 capture.
|
|
27
|
-
* Everything else is the untouched v8 capture.
|
|
17
|
+
* ONE documented deviation from the raw v8 capture: v8's CreateHttpStream
|
|
18
|
+
* dropped the `yield` schema (and `res.headers`) from http-stream route docs —
|
|
19
|
+
* the registration stored `yieldType` while the doc builder read `yield`. v9
|
|
20
|
+
* fixes that, so the fixture's TailUser route was patched to include the
|
|
21
|
+
* `yield` schema the builder now (correctly) emits. Everything else is the
|
|
22
|
+
* untouched v8 capture.
|
|
28
23
|
*/
|
|
29
24
|
class TeapotError extends Error {
|
|
30
25
|
}
|
|
@@ -97,12 +92,6 @@ describe('DocEnvelope parity with v8.6.0', () => {
|
|
|
97
92
|
const fixturePath = resolve(dirname(fileURLToPath(import.meta.url)), '__fixtures__/parity-envelope.json');
|
|
98
93
|
const expected = JSON.parse(await readFile(fixturePath, 'utf-8'));
|
|
99
94
|
const actual = JSON.parse(JSON.stringify(builder.toDocEnvelope()));
|
|
100
|
-
// Deviation #2: assert the new v9 envelope metadata, then strip it so the
|
|
101
|
-
// remaining shape matches the untouched v8 capture.
|
|
102
|
-
expect(actual.specVersion).toBe(DOC_ENVELOPE_SPEC_VERSION);
|
|
103
|
-
expect(actual.generatorVersion).toBe(pkg.version);
|
|
104
|
-
delete actual.specVersion;
|
|
105
|
-
delete actual.generatorVersion;
|
|
106
95
|
expect(actual).toEqual(expected);
|
|
107
96
|
});
|
|
108
97
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"envelope-parity.test.js","sourceRoot":"","sources":["../../../src/adapters/hono/envelope-parity.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AAC3C,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AACxC,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAA;AAC7C,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAA;AAC9B,OAAO,
|
|
1
|
+
{"version":3,"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AI,cAAc,CAAC,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,CAAA;QAC5E,OAAO,CAAC,QAAQ,CAAC,OAAO,EAAE,EAAE,CAAC,CAAA;QAC7B,OAAO,CAAC,KAAK,EAAE,CAAA;QAEf,MAAM,WAAW,GAAG,OAAO,CACzB,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EACvC,mCAAmC,CACpC,CAAA;QACD,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,QAAQ,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC,CAAA;QACjE,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,aAAa,EAAE,CAAC,CAAC,CAAA;QAElE,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAA;IAClC,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import type { Hono } from 'hono';
|
|
2
2
|
import type { THttpStreamProcedureRegistration } from '../../../core/types.js';
|
|
3
|
-
import type { DocAccumulator, HonoAppBuilderConfig, HonoFactoryItem } from '../types.js';
|
|
3
|
+
import type { DocAccumulator, HonoAppBuilderConfig, HonoFactoryItem, HonoRequestMiddleware } from '../types.js';
|
|
4
4
|
export declare function installHttpStreamRoute(params: {
|
|
5
5
|
app: Hono;
|
|
6
6
|
procedure: THttpStreamProcedureRegistration<any>;
|
|
7
7
|
factoryItem: HonoFactoryItem;
|
|
8
8
|
cfg: HonoAppBuilderConfig;
|
|
9
9
|
docs: DocAccumulator;
|
|
10
|
+
builderMiddleware?: HonoRequestMiddleware[];
|
|
10
11
|
}): void;
|
|
@@ -5,16 +5,23 @@ import { resolveFactoryContext } from '../../../server/context.js';
|
|
|
5
5
|
import { extractReqChannels } from '../../../server/request/params.js';
|
|
6
6
|
import { parseQueryNative } from '../../../server/request/query.js';
|
|
7
7
|
import { SseEventSequencer } from '../../../server/sse.js';
|
|
8
|
-
import { honoRequestSource, respondToDispatch } from '../request.js';
|
|
8
|
+
import { honoRequestSource, respondToDispatch, runMiddlewareList } from '../request.js';
|
|
9
9
|
import { midStreamErrorConfig, preStreamErrorConfig } from '../types.js';
|
|
10
10
|
export function installHttpStreamRoute(params) {
|
|
11
|
-
const { app, procedure, factoryItem, cfg, docs } = params;
|
|
11
|
+
const { app, procedure, factoryItem, cfg, docs, builderMiddleware } = params;
|
|
12
12
|
const queryParser = cfg.api?.queryParser ?? parseQueryNative;
|
|
13
13
|
const route = buildHttpStreamRouteDoc(procedure, cfg.pathPrefix, factoryItem.extendProcedureDoc);
|
|
14
14
|
docs.push(route);
|
|
15
15
|
const reqSchema = procedure.config.schema?.req;
|
|
16
|
+
const combinedMw = [
|
|
17
|
+
...(builderMiddleware ?? []),
|
|
18
|
+
...(factoryItem.middleware ?? []),
|
|
19
|
+
];
|
|
16
20
|
app.on(procedure.config.method.toUpperCase(), route.fullPath, async (c) => {
|
|
17
21
|
try {
|
|
22
|
+
const early = await runMiddlewareList(c, combinedMw);
|
|
23
|
+
if (early)
|
|
24
|
+
return early;
|
|
18
25
|
const context = await resolveFactoryContext(factoryItem.factoryContext, c);
|
|
19
26
|
const reqParams = reqSchema
|
|
20
27
|
? await extractReqChannels(honoRequestSource(c), procedure.config.method, reqSchema, queryParser)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http-stream.js","sourceRoot":"","sources":["../../../../src/adapters/hono/handlers/http-stream.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAE1C,OAAO,EAAE,sBAAsB,EAAE,sBAAsB,EAAE,MAAM,oCAAoC,CAAA;AACnG,OAAO,EAAE,uBAAuB,EAAE,MAAM,yCAAyC,CAAA;AACjF,OAAO,EAAE,qBAAqB,EAAE,MAAM,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Registration } from '../../../core/types.js';
|
|
3
|
-
import type { DocAccumulator, HonoAppBuilderConfig, HonoFactoryItem } from '../types.js';
|
|
3
|
+
import type { DocAccumulator, HonoAppBuilderConfig, HonoFactoryItem, HonoRequestMiddleware } from '../types.js';
|
|
4
4
|
export declare function installHttpRoute(params: {
|
|
5
5
|
app: Hono;
|
|
6
6
|
procedure: THttpProcedureRegistration<any>;
|
|
7
7
|
factoryItem: HonoFactoryItem;
|
|
8
8
|
cfg: HonoAppBuilderConfig;
|
|
9
9
|
docs: DocAccumulator;
|
|
10
|
+
builderMiddleware?: HonoRequestMiddleware[];
|
|
10
11
|
}): void;
|
|
@@ -3,17 +3,24 @@ import { buildHttpRouteDoc } from '../../../server/docs/http-doc.js';
|
|
|
3
3
|
import { resolveFactoryContext } from '../../../server/context.js';
|
|
4
4
|
import { defaultSuccessStatus, extractReqChannels } from '../../../server/request/params.js';
|
|
5
5
|
import { parseQueryNative } from '../../../server/request/query.js';
|
|
6
|
-
import { honoRequestSource, respondToDispatch } from '../request.js';
|
|
6
|
+
import { honoRequestSource, respondToDispatch, runMiddlewareList } from '../request.js';
|
|
7
7
|
import { preStreamErrorConfig } from '../types.js';
|
|
8
8
|
export function installHttpRoute(params) {
|
|
9
|
-
const { app, procedure, factoryItem, cfg, docs } = params;
|
|
9
|
+
const { app, procedure, factoryItem, cfg, docs, builderMiddleware } = params;
|
|
10
10
|
const queryParser = cfg.api?.queryParser ?? parseQueryNative;
|
|
11
11
|
const route = buildHttpRouteDoc(procedure, cfg.pathPrefix, factoryItem.extendProcedureDoc);
|
|
12
12
|
docs.push(route);
|
|
13
13
|
const successStatus = procedure.config.successStatus ?? defaultSuccessStatus(procedure.config.method);
|
|
14
14
|
const reqSchema = procedure.config.schema?.req;
|
|
15
|
+
const combinedMw = [
|
|
16
|
+
...(builderMiddleware ?? []),
|
|
17
|
+
...(factoryItem.middleware ?? []),
|
|
18
|
+
];
|
|
15
19
|
app.on(procedure.config.method.toUpperCase(), route.fullPath, async (c) => {
|
|
16
20
|
try {
|
|
21
|
+
const early = await runMiddlewareList(c, combinedMw);
|
|
22
|
+
if (early)
|
|
23
|
+
return early;
|
|
17
24
|
const context = await resolveFactoryContext(factoryItem.factoryContext, c);
|
|
18
25
|
const reqParams = reqSchema
|
|
19
26
|
? await extractReqChannels(honoRequestSource(c), procedure.config.method, reqSchema, queryParser)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.js","sourceRoot":"","sources":["../../../../src/adapters/hono/handlers/http.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,sBAAsB,EAAE,MAAM,oCAAoC,CAAA;AAC3E,OAAO,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAA;AACpE,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAA;AAClE,OAAO,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,MAAM,mCAAmC,CAAA;AAC5F,OAAO,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAA;AACnE,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAA;
|
|
1
|
+
{"version":3,"file":"http.js","sourceRoot":"","sources":["../../../../src/adapters/hono/handlers/http.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,sBAAsB,EAAE,MAAM,oCAAoC,CAAA;AAC3E,OAAO,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAA;AACpE,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAA;AAClE,OAAO,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,MAAM,mCAAmC,CAAA;AAC5F,OAAO,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAA;AACnE,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAA;AACvF,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAA;AAGlD,MAAM,UAAU,gBAAgB,CAAC,MAOhC;IACC,MA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EAAE,CAAC,EAAE,GAAG,EAAE,oBAAoB,CAAC,GAAG,CAAC,EAAE,CAAC,CAChG,CAAA;QACH,CAAC;IACH,CAAC,CAAC,CAAA;AACJ,CAAC"}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import type { Hono } from 'hono';
|
|
2
2
|
import type { TProcedureRegistration } from '../../../core/types.js';
|
|
3
3
|
import type { RPCConfig } from '../../../server/types.js';
|
|
4
|
-
import type { DocAccumulator, HonoAppBuilderConfig, HonoFactoryItem } from '../types.js';
|
|
4
|
+
import type { DocAccumulator, HonoAppBuilderConfig, HonoFactoryItem, HonoRequestMiddleware } from '../types.js';
|
|
5
5
|
export declare function installRpcRoute(params: {
|
|
6
6
|
app: Hono;
|
|
7
7
|
procedure: TProcedureRegistration<any, RPCConfig>;
|
|
8
8
|
factoryItem: HonoFactoryItem;
|
|
9
9
|
cfg: HonoAppBuilderConfig;
|
|
10
10
|
docs: DocAccumulator;
|
|
11
|
+
builderMiddleware?: HonoRequestMiddleware[];
|
|
11
12
|
}): void;
|
|
@@ -1,14 +1,21 @@
|
|
|
1
1
|
import { dispatchPreStreamError } from '../../../server/errors/dispatch.js';
|
|
2
2
|
import { buildRpcRouteDoc } from '../../../server/docs/rpc-doc.js';
|
|
3
3
|
import { resolveFactoryContext } from '../../../server/context.js';
|
|
4
|
-
import { respondToDispatch } from '../request.js';
|
|
4
|
+
import { respondToDispatch, runMiddlewareList } from '../request.js';
|
|
5
5
|
import { preStreamErrorConfig } from '../types.js';
|
|
6
6
|
export function installRpcRoute(params) {
|
|
7
|
-
const { app, procedure, factoryItem, cfg, docs } = params;
|
|
7
|
+
const { app, procedure, factoryItem, cfg, docs, builderMiddleware } = params;
|
|
8
8
|
const route = buildRpcRouteDoc(procedure, cfg.pathPrefix, factoryItem.extendProcedureDoc);
|
|
9
9
|
docs.push(route);
|
|
10
|
+
const combinedMw = [
|
|
11
|
+
...(builderMiddleware ?? []),
|
|
12
|
+
...(factoryItem.middleware ?? []),
|
|
13
|
+
];
|
|
10
14
|
app.post(route.path, async (c) => {
|
|
11
15
|
try {
|
|
16
|
+
const early = await runMiddlewareList(c, combinedMw);
|
|
17
|
+
if (early)
|
|
18
|
+
return early;
|
|
12
19
|
const context = await resolveFactoryContext(factoryItem.factoryContext, c);
|
|
13
20
|
const body = await c.req.json().catch(() => ({}));
|
|
14
21
|
const result = await procedure.handler({ ...context, signal: c.req.raw.signal }, body);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rpc.js","sourceRoot":"","sources":["../../../../src/adapters/hono/handlers/rpc.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,sBAAsB,EAAE,MAAM,oCAAoC,CAAA;AAC3E,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAA;AAClE,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAA;AAClE,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAA;
|
|
1
|
+
{"version":3,"file":"rpc.js","sourceRoot":"","sources":["../../../../src/adapters/hono/handlers/rpc.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,sBAAsB,EAAE,MAAM,oCAAoC,CAAA;AAC3E,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAA;AAClE,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAA;AAClE,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAA;AACpE,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAA;AAGlD,MAAM,UAAU,eAAe,CAAC,MAO/B;IACC,MAAM,EAAE,GAAG,EAAE,SAAS,EAAE,WAAW,EAAE,GAAG,EAAE,IAAI,EAAE,iBAAiB,EAAE,GAAG,MAAM,CAAA;IAE5E,MAAM,KAAK,GAAG,gBAAgB,CAAC,SAAS,EAAE,GAAG,CAAC,UAAU,EAAE,WAAW,CAAC,kBAAyB,CAAC,CAAA;IAChG,IAAI,CAAC,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
|
|
2
2
|
import type { TStreamProcedureRegistration } from '../../../core/types.js';
|
|
3
3
|
import type { RPCConfig, StreamMode } from '../../../server/types.js';
|
|
4
|
-
import type { DocAccumulator, HonoAppBuilderConfig, HonoFactoryItem } from '../types.js';
|
|
4
|
+
import type { DocAccumulator, HonoAppBuilderConfig, HonoFactoryItem, HonoRequestMiddleware } from '../types.js';
|
|
5
5
|
export declare function installRpcStreamRoute(params: {
|
|
6
6
|
app: Hono;
|
|
7
7
|
procedure: TStreamProcedureRegistration<any, RPCConfig>;
|
|
@@ -9,4 +9,5 @@ export declare function installRpcStreamRoute(params: {
|
|
|
9
9
|
cfg: HonoAppBuilderConfig;
|
|
10
10
|
docs: DocAccumulator;
|
|
11
11
|
streamMode: StreamMode;
|
|
12
|
+
builderMiddleware?: HonoRequestMiddleware[];
|
|
12
13
|
}): void;
|
|
@@ -4,14 +4,21 @@ import { dispatchMidStreamError, dispatchPreStreamError } from '../../../server/
|
|
|
4
4
|
import { buildStreamRouteDoc } from '../../../server/docs/stream-doc.js';
|
|
5
5
|
import { resolveFactoryContext } from '../../../server/context.js';
|
|
6
6
|
import { SseEventSequencer } from '../../../server/sse.js';
|
|
7
|
-
import { respondToDispatch } from '../request.js';
|
|
7
|
+
import { respondToDispatch, runMiddlewareList } from '../request.js';
|
|
8
8
|
import { midStreamErrorConfig, preStreamErrorConfig } from '../types.js';
|
|
9
9
|
export function installRpcStreamRoute(params) {
|
|
10
|
-
const { app, procedure, factoryItem, cfg, docs, streamMode } = params;
|
|
10
|
+
const { app, procedure, factoryItem, cfg, docs, streamMode, builderMiddleware } = params;
|
|
11
11
|
const route = buildStreamRouteDoc(procedure, streamMode, cfg.pathPrefix, factoryItem.extendProcedureDoc);
|
|
12
12
|
docs.push(route);
|
|
13
|
+
const combinedMw = [
|
|
14
|
+
...(builderMiddleware ?? []),
|
|
15
|
+
...(factoryItem.middleware ?? []),
|
|
16
|
+
];
|
|
13
17
|
const handler = async (c) => {
|
|
14
18
|
try {
|
|
19
|
+
const early = await runMiddlewareList(c, combinedMw);
|
|
20
|
+
if (early)
|
|
21
|
+
return early;
|
|
15
22
|
const context = await resolveFactoryContext(factoryItem.factoryContext, c);
|
|
16
23
|
const reqParams = c.req.method === 'GET'
|
|
17
24
|
? Object.fromEntries(new URL(c.req.url).searchParams)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stream.js","sourceRoot":"","sources":["../../../../src/adapters/hono/handlers/stream.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAGtD,OAAO,EAAE,wBAAwB,EAAE,MAAM,yBAAyB,CAAA;AAClE,OAAO,EAAE,sBAAsB,EAAE,sBAAsB,EAAE,MAAM,oCAAoC,CAAA;AACnG,OAAO,EAAE,mBAAmB,EAAE,MAAM,oCAAoC,CAAA;AACxE,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAA;AAClE,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAC1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAA;
|
|
1
|
+
{"version":3,"file":"stream.js","sourceRoot":"","sources":["../../../../src/adapters/hono/handlers/stream.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAGtD,OAAO,EAAE,wBAAwB,EAAE,MAAM,yBAAyB,CAAA;AAClE,OAAO,EAAE,sBAAsB,EAAE,sBAAsB,EAAE,MAAM,oCAAoC,CAAA;AACnG,OAAO,EAAE,mBAAmB,EAAE,MAAM,oCAAoC,CAAA;AACxE,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAA;AAClE,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAC1D,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAA;AACpE,OAAO,EAAE,oBAAoB,EAAE,oBAA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