ts-procedures 8.5.0 → 8.6.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/build/codegen/emit-index.js +13 -0
- package/build/codegen/emit-index.js.map +1 -1
- package/build/codegen/emit-index.test.js +25 -0
- package/build/codegen/emit-index.test.js.map +1 -1
- package/build/codegen/emit-scope.js +45 -8
- package/build/codegen/emit-scope.js.map +1 -1
- package/build/codegen/emit-scope.test.js +86 -4
- package/build/codegen/emit-scope.test.js.map +1 -1
- package/docs/client-error-handling.md +87 -0
- package/docs/handoffs/2026-06-08-dx-round2-declines.md +45 -0
- package/docs/http-integrations.md +25 -0
- package/docs/superpowers/plans/2026-06-08-codegen-dx-surfacing.md +428 -0
- package/docs/superpowers/specs/2026-06-08-dx-feedback-round-2-design.md +376 -0
- package/package.json +1 -1
- package/src/codegen/__fixtures__/users-envelope.json +9 -0
- package/src/codegen/emit-index.test.ts +34 -0
- package/src/codegen/emit-index.ts +19 -0
- package/src/codegen/emit-scope.test.ts +94 -4
- package/src/codegen/emit-scope.ts +53 -8
- package/src/codegen/targets/kotlin/__fixtures__/users-golden.kt +6 -0
- package/src/codegen/targets/swift/__fixtures__/users-golden.swift +6 -0
|
@@ -0,0 +1,376 @@
|
|
|
1
|
+
# DX Feedback Round 2 — Design
|
|
2
|
+
|
|
3
|
+
**Date:** 2026-06-08
|
|
4
|
+
**Status:** Triage approved. **Workstream A ✅ shipped** (2026-06-08, commits `0d53329`,
|
|
5
|
+
`ec9ea04`, `ced4b86`, `8ad5e9f` on `master`; 1077 tests green). **Round closed 2026-06-08:**
|
|
6
|
+
B → docs (already authorable), C documented as a boundary (no API), D high-value docs shipped
|
|
7
|
+
(#6 recipe, #10/#8 prose; #7/#12/CORS deferred), E ✗ dropped, #13/#11 decline reply sent. Net:
|
|
8
|
+
Workstream A was the only *code* — everything else was already-shipped capability to document or
|
|
9
|
+
out of our lane. See roadmap for the per-item landing.
|
|
10
|
+
**Source:** Downstream-developer feedback from building the demo server (`src/server`)
|
|
11
|
+
and wiring its generated client into the client layer. Findings #6–#15 + three
|
|
12
|
+
cross-cutting notes. (Findings #1–#5 were resolved in 8.4.0 / 8.5.0 — see
|
|
13
|
+
`2026-06-05-dx-feedback-round-design.md`.)
|
|
14
|
+
|
|
15
|
+
This round is deliberately **not** a single spec. The findings sort by *boundary*,
|
|
16
|
+
not by the severity label the downstream assigned, and the boundary determines how
|
|
17
|
+
each is treated:
|
|
18
|
+
|
|
19
|
+
1. **"The capability exists; it's just invisible in the generated output."** Pure
|
|
20
|
+
codegen *surfacing*. Unambiguously ours, low-risk, high-value. → **Workstream A**.
|
|
21
|
+
2. **"The typed error survives our throw but is flattened downstream."** Cross-cutting
|
|
22
|
+
error-handling design; the actual blocker lives in mvc-kit, not here. → **Workstream
|
|
23
|
+
C** (a design brainstorm, not a code sprint).
|
|
24
|
+
3. **"Our codegen faithfully reflects a schema the downstream authored
|
|
25
|
+
inconsistently."** Mislabeled as a codegen gap; fixing it would mean codegen
|
|
26
|
+
*overriding* the author's contract. → **Declined** (documented, no code).
|
|
27
|
+
|
|
28
|
+
The guiding principle for this round: ts-procedures owns the *transport, schema, and
|
|
29
|
+
codegen surface*. It does **not** own the consumer's state-management ergonomics
|
|
30
|
+
(mvc-kit) or the consumer's schema-authoring choices. We surface and document what we
|
|
31
|
+
own; we decline to absorb the rest, with written rationale so downstream isn't left
|
|
32
|
+
guessing.
|
|
33
|
+
|
|
34
|
+
---
|
|
35
|
+
|
|
36
|
+
## Disposition at a glance
|
|
37
|
+
|
|
38
|
+
| # | Severity (theirs) | Disposition | Workstream |
|
|
39
|
+
|---|---|---|---|
|
|
40
|
+
| #8 | HIGH | **Do** — surface the per-call options bag (`signal`/`timeout`) in the generated per-route artifact | A |
|
|
41
|
+
| #9 | MEDIUM | **Do** — emit `void` for input-less routes instead of `unknown` | A |
|
|
42
|
+
| #10 | MEDIUM | **Do (shallow half)** — surface declared `Errors` + `isApiError` guard on the throwing path | A |
|
|
43
|
+
| #15 | LOW | **Do** — emit a per-scope client interface (`MessagesClient`, …) | A |
|
|
44
|
+
| #6 | LOW | **Document** — already authorable today (omit `res.body` → `Promise<void>`, no model, 204); fold into D | D |
|
|
45
|
+
| #14 | HIGH | **Brainstorm** — error-mapping seam; hold the line that flattening is mvc-kit's gap | C |
|
|
46
|
+
| #10 (deep half) | MEDIUM | **Brainstorm** — why `.safe()` is avoided ties into C | C |
|
|
47
|
+
| #7 | LOW | **Document** — `Type.Record` can't be `$id`-shared | D |
|
|
48
|
+
| #12 | LOW | **Document** — form Model owns a value type + `toBody()`; partly inherent | D |
|
|
49
|
+
| basePath/CORS | MEDIUM | **Document** (+ optional dev-time warning) | D |
|
|
50
|
+
| correlation-id | MEDIUM | **Dropped** — `onRequestStart` + function-form `factoryContext` + client headers already cover it; no new API earns its surface | — |
|
|
51
|
+
| #13 | MEDIUM | **Decline code** (document convention) — downstream schema inconsistency | — |
|
|
52
|
+
| #11 | LOW | **Decline code** (document the `as Partial` bridge) — relationship not in JSON Schema | — |
|
|
53
|
+
|
|
54
|
+
---
|
|
55
|
+
|
|
56
|
+
## Workstream A — Codegen DX surfacing (ready to plan)
|
|
57
|
+
|
|
58
|
+
Four findings, one cohesive batch: every one is "the capability already exists (or is
|
|
59
|
+
a one-line detection); make it visible/ergonomic in the generated output." All touch
|
|
60
|
+
`emit-scope.ts` / `emit-types.ts` / `emit-index.ts` and the client `types.ts`. Lowest
|
|
61
|
+
risk, highest signal. **This is the one workstream ready for a TDD plan now.**
|
|
62
|
+
|
|
63
|
+
### A.1 — #9: input-less routes are typed `unknown`, forcing a noise `({})` arg
|
|
64
|
+
|
|
65
|
+
**Problem.** Routes with no pathParams/query/body bind their first param as `unknown`
|
|
66
|
+
(`emit-scope.ts:536,679` — `paramsTypeName` defaults to `'unknown'`). Because the type
|
|
67
|
+
is `unknown` (not `void`/optional), consumers must pass a placeholder `({})` —
|
|
68
|
+
`api.auth.Me({})`, `api.users.ListUsers({})` — and worse, `unknown` accepts garbage
|
|
69
|
+
(`api.auth.Me({ nonsense: 1 })` type-checks). Six call sites across five files; the
|
|
70
|
+
single most-repeated papercut.
|
|
71
|
+
|
|
72
|
+
**Decision.** When a route has **zero present input channels**, emit `void` as the
|
|
73
|
+
param type — `bindCallable<void, T>` / `bindCallableTyped<void, T, E>` — so the callable
|
|
74
|
+
is `(params: void, options?) => Promise<T>`. Detection point is trivial: after
|
|
75
|
+
`presentChannels` is built (`emit-scope.ts:514-520` API, `664-670` http-stream; the RPC
|
|
76
|
+
`refs['Params'] ?? 'unknown'` path at `398-399,408-409`), branch on
|
|
77
|
+
`presentChannels.length === 0`. **No runtime change** — only the emitted `TParams` type
|
|
78
|
+
arg changes.
|
|
79
|
+
|
|
80
|
+
> **Verified (2026-06-08, `tsc --strict`).** A required parameter of type `void` *can*
|
|
81
|
+
> be omitted at the call site: `Me()` compiles, `Me({})` / `Me({ nonsense: 1 })` are type
|
|
82
|
+
> errors. So the existing `(params, options?)` shape needs no restructuring — `void` for
|
|
83
|
+
> `TParams` is sufficient. The one wart: passing options on a no-input route reads
|
|
84
|
+
> `Me(undefined, { signal })`. That awkwardness is rare (no-input + explicit signal) and
|
|
85
|
+
> is the price of a **uniform** call shape across all routes; the plan should call it out
|
|
86
|
+
> but I recommend keeping the uniform shape rather than special-casing no-input routes to
|
|
87
|
+
> `(options?) =>` (which would need runtime rewiring and break shape uniformity).
|
|
88
|
+
|
|
89
|
+
**Alternatives considered.** *Optional `params?: SomeEmptyObject`.* Rejected: still
|
|
90
|
+
accepts a stray object. *Drop params entirely → `(options?) => T` for no-input routes.*
|
|
91
|
+
Rejected: nicer `Me({ signal })` ergonomics but breaks call-shape uniformity and needs
|
|
92
|
+
runtime rewiring of the binder. *Leave as-is, document `({})`.* Rejected: highest-frequency
|
|
93
|
+
papercut, and the type fix is a single branch per route kind.
|
|
94
|
+
|
|
95
|
+
### A.2 — #8: the per-call `AbortSignal`/`timeout` seam is invisible in the generated artifact
|
|
96
|
+
|
|
97
|
+
**Problem.** Every bound callable is `(params, options?: ProcedureCallOptions) =>
|
|
98
|
+
Promise<T>` and `ProcedureCallOptions` carries `signal`/`timeout`/`headers`/`basePath`/
|
|
99
|
+
`meta` (`client/types.ts:218-230`). But the generated per-route namespace surfaces only
|
|
100
|
+
the first param (`.Req`); the JSDoc emitted at `emit-scope.ts:412-419,640-644,822-833`
|
|
101
|
+
never mentions the second `options` argument. The result is a real downstream
|
|
102
|
+
mis-modeling: resources state as fact "there's no per-call AbortSignal seam" and **every
|
|
103
|
+
resource omits cancellation**, violating their own P7. The seam was reachable all along
|
|
104
|
+
— just not through the surface they treat as the contract.
|
|
105
|
+
|
|
106
|
+
**Decision.** Surface the options bag in the generated per-route artifact — **JSDoc is
|
|
107
|
+
the primary, highest-value half**:
|
|
108
|
+
1. Add a JSDoc line to every bound callable mentioning `options?.signal` / `options?.timeout`
|
|
109
|
+
(and that the second arg is `ProcedureCallOptions`), so it shows on hover *at the call
|
|
110
|
+
site* — which is where the consumer reads the contract.
|
|
111
|
+
2. *(Open — likely drop.)* A per-route `export type Options = ProcedureCallOptions` alias
|
|
112
|
+
next to `.Req`. On reflection this is probably **over-production**: the alias is
|
|
113
|
+
byte-identical on every route, so it adds generated noise (`SendMessage.Options` is just
|
|
114
|
+
`ProcedureCallOptions`) without naming anything route-specific. The plan should default to
|
|
115
|
+
JSDoc-only and emit the alias only if a concrete discoverability gap remains after the
|
|
116
|
+
JSDoc lands. Readable generated output > a redundant alias on every route.
|
|
117
|
+
|
|
118
|
+
**Alternatives considered.** *Docs only (external).* Rejected: the whole finding is that the
|
|
119
|
+
capability is undiscoverable *from the generated namespace* — the place a consumer treats as
|
|
120
|
+
the contract. The JSDoc has to land in the generated code. *Per-route alias as the headline
|
|
121
|
+
fix.* Demoted (see above) — repetition isn't discoverability.
|
|
122
|
+
|
|
123
|
+
### A.3 — #10 (shallow half): declared typed errors are invisible on the throwing path
|
|
124
|
+
|
|
125
|
+
**Problem.** A route that declares `errors` already gets `export type Errors = <union>`
|
|
126
|
+
emitted (`emit-scope.ts:363-384`), but the `ETyped` union is wired **only** to `.safe()`
|
|
127
|
+
(`client/types.ts:293-298`); the throwing callable resolves to plain `Promise<TResponse>`.
|
|
128
|
+
Since the data layer uses the throwing form (per its P2/P5), TypeScript gives no signal
|
|
129
|
+
about which typed errors a call can throw — the declared `Conflict` on `CreateUser`/
|
|
130
|
+
`UpdateUser` is never handled. The route-level taxonomy codegen computes is dead weight
|
|
131
|
+
on the common path.
|
|
132
|
+
|
|
133
|
+
**Decision (shallow half only).** *Grounding correction (2026-06-08):* the per-route
|
|
134
|
+
`Errors` type is **already emitted and reachable** — `Users.GetUser.Errors` (namespace) /
|
|
135
|
+
`GetUserErrors` (flat), confirmed in `emit-scope.test.ts:740,750`. And because the generated
|
|
136
|
+
error classes are **real exported classes**, `if (e instanceof Api.Errors.Conflict)` already
|
|
137
|
+
works on the throwing path. So #10 is **not** a missing-type problem — it's pure
|
|
138
|
+
*discoverability*. That moves the bulk of #10 into the docs pass (Workstream D); the only
|
|
139
|
+
code in Workstream A is a one-line JSDoc breadcrumb:
|
|
140
|
+
1. The per-route callable's JSDoc names its declared errors and points at `Scope.Route.Errors`
|
|
141
|
+
+ "narrow with `instanceof` on the throwing path, or use `.safe()` for a `Result`."
|
|
142
|
+
2. *(Optional, deferred.)* A generic `isProcedureError(e, Cls)` guard in the client runtime
|
|
143
|
+
(sugar over `instanceof`; classes are tagged `__tsProceduresTyped` at `client/call.ts:170`).
|
|
144
|
+
Held back unless docs + the breadcrumb prove insufficient — `instanceof` already works, so
|
|
145
|
+
a guard is ergonomics, not capability. Don't over-produce.
|
|
146
|
+
|
|
147
|
+
**The deep half is Workstream C.** *Why* the data layer avoids `.safe()` at all (it
|
|
148
|
+
defeats mvc-kit's async tracking) is the cross-cutting error-handling question — not
|
|
149
|
+
solvable by a codegen tweak. Do **not** conflate the two.
|
|
150
|
+
|
|
151
|
+
**Alternatives considered.** *Attach `ETyped` to the throwing signature too.* Rejected:
|
|
152
|
+
TS can't express "throws X" — the union would have to ride a phantom return position and
|
|
153
|
+
would mislead. A guard + reachable `Errors` type is the honest surface.
|
|
154
|
+
|
|
155
|
+
### A.4 — #15: no per-scope client interface, forcing `as unknown as typeof api` casts
|
|
156
|
+
|
|
157
|
+
**Problem.** The aggregate client is the only exported shape, so a Resource that uses one
|
|
158
|
+
scope must type its dependency as the whole `typeof api`
|
|
159
|
+
(`users.resource.ts:26`), and every test fake force-casts a two-method partial
|
|
160
|
+
`as unknown as typeof api` (`thread-messages.resource.test.ts:16`,
|
|
161
|
+
`threads.resource.test.ts:30`). The double-cast is the tell that the injected port is far
|
|
162
|
+
wider than the dependency used — defeating the type safety the generated client exists to
|
|
163
|
+
provide, exactly at the DI seam.
|
|
164
|
+
|
|
165
|
+
**Decision.** Emit a per-scope client interface alongside the aggregate — the bound
|
|
166
|
+
callables for that scope as a named type — produced where `emit-index.ts` already
|
|
167
|
+
assembles the scope namespaces. A Resource then types its dependency as the narrow port
|
|
168
|
+
(`constructor(client: MessagesClient = api.messages)`) and a fake implements just that
|
|
169
|
+
interface with no cast.
|
|
170
|
+
|
|
171
|
+
> **Derive from the existing factory return type (verified 2026-06-08).** `emit-index.ts`
|
|
172
|
+
> already emits `create${Service}Bindings(client)` returning `{ users: …, posts: … }` and
|
|
173
|
+
> already uses `ReturnType<typeof ${factoryName}>` (lines 128,145). So the per-scope client
|
|
174
|
+
> type is just an indexed access into that — **zero duplication, reuses the pattern already in
|
|
175
|
+
> the file**:
|
|
176
|
+
> ```ts
|
|
177
|
+
> export type ${Service}Client = ReturnType<typeof create${Service}Bindings>
|
|
178
|
+
> export type UsersClient = ${Service}Client['users'] // one per scope
|
|
179
|
+
> ```
|
|
180
|
+
> This does **not** collide with the `Api.Users` *type* namespace (Params/Response/…) — that
|
|
181
|
+
> namespace is the route data types; `UsersClient` is the callable bundle. The `*Client` suffix
|
|
182
|
+
> cleanly distinguishes the two. No parallel scheme, no hand-written interface — the types fall
|
|
183
|
+
> out of the factory the file already emits. A Resource then writes
|
|
184
|
+
> `constructor(client: UsersClient = api.users)` and a two-method fake satisfies `UsersClient`
|
|
185
|
+
> with no cast.
|
|
186
|
+
|
|
187
|
+
**Alternatives considered.** *Hand-written per-Resource port type (consumer side).*
|
|
188
|
+
Works, but every consumer reinvents (and mis-scopes) it — codegen already knows the exact
|
|
189
|
+
scope shape, so it should emit it.
|
|
190
|
+
|
|
191
|
+
---
|
|
192
|
+
|
|
193
|
+
## Workstream B — No-content response (#6) — → DOCS (folded into D, 2026-06-08)
|
|
194
|
+
|
|
195
|
+
**Problem.** The downstream invented phantom bodies for naturally-empty responses:
|
|
196
|
+
`Logout` carries a dead-weight `LogoutResponse` model (call site discards it), `LeaveThread`
|
|
197
|
+
returns a `ThreadList` it didn't need. They believed an empty response couldn't be declared.
|
|
198
|
+
|
|
199
|
+
**Vetted (2026-06-08) — no-content is ALREADY fully authorable today; #6 is a docs gap, not a
|
|
200
|
+
build.** The capability exists end-to-end:
|
|
201
|
+
- **Authoring type:** `schema.res` and `res.body` are both optional (`src/types.ts:100-102`).
|
|
202
|
+
An author can omit `res` (or `res.body`) entirely.
|
|
203
|
+
- **Handler type:** `HttpReturn<TRes>` falls through to `void` when there's no body
|
|
204
|
+
(`src/create-http.ts:17-21`), so the handler types as `Promise<void>` and `return undefined`
|
|
205
|
+
type-checks (`create-http.test.ts:110-119`).
|
|
206
|
+
- **Envelope:** omitting `res.body` emits an absent/empty `res` (`hono/docs/http-doc.ts:14-27`).
|
|
207
|
+
- **Codegen:** empty `res` → `client.bindCallable<void, void>`, **no** response model
|
|
208
|
+
(`emit-scope.test.ts:1253-1256`).
|
|
209
|
+
- **Runtime:** `undefined` return → clean 204 (`hono/handlers/http.ts:126`;
|
|
210
|
+
`http.test.ts:70-82`).
|
|
211
|
+
|
|
212
|
+
So `CreateHttp('Logout', { /* no res */ }, async () => undefined)` already gives a
|
|
213
|
+
`Promise<void>` client, no model, 204 at runtime — exactly what they wanted. They invented a
|
|
214
|
+
body only because the "declare nothing" path **wasn't visible**. Same shape as Workstream E:
|
|
215
|
+
capability exists; the gap is discoverability. **No new API (no `Type.Void()` marker, no
|
|
216
|
+
status-only seam needed).** Fold a short recipe into the **D** docs pass: "for 204 / no-content,
|
|
217
|
+
omit `schema.res.body` and return `undefined` — you get `Promise<void>` and no generated model."
|
|
218
|
+
|
|
219
|
+
**Out of scope.** Consumer-side response *projection* (the `CreateThread` / `Pick`-one-field
|
|
220
|
+
observation) — the procedure's call, not the call site's; the Resource caches the full
|
|
221
|
+
projection anyway. Flagged in the feedback as "no action needed."
|
|
222
|
+
|
|
223
|
+
---
|
|
224
|
+
|
|
225
|
+
## Workstream C — Error-handling, cross-cutting (brainstorm, not a build)
|
|
226
|
+
|
|
227
|
+
**Covers:** #14 (fire-and-forget command error dead-ends) + the "typed errors flattened
|
|
228
|
+
by mvc-kit async tracking" cross-cutting note + the *deep* half of #10 (why `.safe()` is
|
|
229
|
+
avoided).
|
|
230
|
+
|
|
231
|
+
**Boundary stance (to defend in the brainstorm).** ts-procedures **already does its job
|
|
232
|
+
correctly**: it throws `instanceof`-catchable typed classes. The error "dead-ends"
|
|
233
|
+
because *mvc-kit's async tracker* collapses the typed instance into a closed 10-value
|
|
234
|
+
`code` union and keeps the original only on a private field. That is mvc-kit's gap — the
|
|
235
|
+
feedback itself says "either side alone closes the gap." We should not bolt on features to
|
|
236
|
+
paper over a downstream flattening problem.
|
|
237
|
+
|
|
238
|
+
**The one genuinely ts-procedures-side ask:** a client-level error **transform/map** seam.
|
|
239
|
+
We already have a global `onError` hook, but it is an *observer* (`client/hooks.ts`,
|
|
240
|
+
`client/types.ts:118-122`) — it cannot transform or swallow. The open question is whether
|
|
241
|
+
a transform hook (or `errorMap` on `createClient`) earns its surface area, or whether
|
|
242
|
+
mvc-kit surfacing `cause` on its `TaskState` is the cleaner fix that makes our side a
|
|
243
|
+
no-op.
|
|
244
|
+
|
|
245
|
+
**Why a brainstorm, not a plan.** This is a real API-design decision with overlap against
|
|
246
|
+
existing hooks and the error taxonomy. It needs the requirements explored before any code.
|
|
247
|
+
The brainstorm should produce either (a) a spec for a transform seam with a crisp boundary,
|
|
248
|
+
or (b) a documented decision that the fix is mvc-kit's, with our side limited to documenting
|
|
249
|
+
the existing typed-throw contract.
|
|
250
|
+
|
|
251
|
+
---
|
|
252
|
+
|
|
253
|
+
## Workstream D — Documentation pass (small session)
|
|
254
|
+
|
|
255
|
+
- **#7 — `Type.Record` opaque to `$id` sharing.** Accurate and inherent: a bare record has
|
|
256
|
+
no `$id`, so its value type is always re-inlined. Not a blocker (it rides inside an
|
|
257
|
+
`$id`-bearing parent like `Thread`). **Document** the limitation in the shared-models
|
|
258
|
+
docs; do **not** teach `--share-models` to synthesize names for records (scope creep for
|
|
259
|
+
a non-blocker).
|
|
260
|
+
- **basePath/CORS footgun.** A cross-origin absolute `basePath` issues a plain
|
|
261
|
+
cross-origin `fetch`; with no server CORS the first call fails with a generic `Failed to
|
|
262
|
+
fetch` and nothing on the client surface hints why. **Document** a one-line callout in the
|
|
263
|
+
codegen `basePath` docs (browser + different origin ⇒ server CORS *or* same-origin dev
|
|
264
|
+
proxy). *Optional small code add:* the fetch adapter detects a cross-origin `basePath` and
|
|
265
|
+
emits a clearer dev-time error than the browser's generic one. The HTTP↔WS auth-seam
|
|
266
|
+
asymmetry half is cross-logged with ts-channels; our half is the basePath/CORS doc.
|
|
267
|
+
- **#12 — form shape not derivable.** The feedback admits this is "partly inherent (draft
|
|
268
|
+
state ≠ request body)." **Document** that form Models are expected to own a value type +
|
|
269
|
+
`toBody()` mapper (`LocationFormModel.toBody` as the recommended shape). No codegen change.
|
|
270
|
+
|
|
271
|
+
---
|
|
272
|
+
|
|
273
|
+
## Workstream E — Framework-level correlation / request id — ✗ DROPPED (2026-06-08)
|
|
274
|
+
|
|
275
|
+
**Was:** promoted from the declined body-level `clientId` ask to a transport-level Hono-builder
|
|
276
|
+
feature (a `requestId` config block: read-or-mint an id, echo it on the response header for all
|
|
277
|
+
four kinds, expose `ctx.requestId`).
|
|
278
|
+
|
|
279
|
+
**Why dropped (brainstorm outcome).** The existing primitives already deliver the *entire*
|
|
280
|
+
feature with no new API — a dedicated block buys only ~6 saved lines and a named knob, which
|
|
281
|
+
doesn't earn permanent public surface on a transport library. Concretely:
|
|
282
|
+
- **Read + mint + echo (server):** `onRequestStart(c)` gets the Hono `Context` and can
|
|
283
|
+
`c.req.header(name) ?? crypto.randomUUID()`, `c.set(...)`, and `c.header(name, id)` — the
|
|
284
|
+
header set there persists onto every response, streams included.
|
|
285
|
+
- **Expose on `ctx` (server):** `factoryContext` already accepts a **function form** receiving
|
|
286
|
+
`c` (`hono/types.ts:42-49`), so `factoryContext: (c) => ({ ...base, requestId: c.get('requestId') })`
|
|
287
|
+
gives handlers `ctx.requestId` with zero framework change.
|
|
288
|
+
- **Outbound id (client):** function-valued `headers` (shipped 8.5.0) + `onBeforeRequest`
|
|
289
|
+
already attach/rotate a correlation header per request.
|
|
290
|
+
|
|
291
|
+
The gap was **discoverability, not capability** — and the user's call (2026-06-08) was that even
|
|
292
|
+
a docs recipe isn't warranted: the two-seam composition is a normal use of documented primitives.
|
|
293
|
+
Same boundary as #13/#11 — the library does not grow surface to wrap what it already enables.
|
|
294
|
+
|
|
295
|
+
**Decision: no feature, no recipe, no spec.** This consumes the original downstream
|
|
296
|
+
correlation-id ask (transport-level) in full.
|
|
297
|
+
|
|
298
|
+
---
|
|
299
|
+
|
|
300
|
+
## Declined (no code change) — with rationale
|
|
301
|
+
|
|
302
|
+
These are the "don't bend" set. We faithfully reflect the author's schema; we don't
|
|
303
|
+
override it.
|
|
304
|
+
|
|
305
|
+
- **#13 — Create/Update spell "empty" two ways (`undefined` vs `string | null`).** Root
|
|
306
|
+
cause is downstream schema inconsistency: `Type.Optional(Type.String())` on create vs
|
|
307
|
+
`Type.Optional(Type.Union([String, Null]))` on update (`user.schema.ts:40` vs `:53`;
|
|
308
|
+
`location.schema.ts:28` vs `:39`). Codegen reflects exactly what they wrote. The
|
|
309
|
+
suggested "codegen emits a per-body normalizer / widens the optional type" would have us
|
|
310
|
+
**override the author's contract** — the opposite of our job. **Decline the code change.**
|
|
311
|
+
Remedy is for the author to make the pair consistent (both `string | undefined` *or* both
|
|
312
|
+
`string | null`). We will document the convention so consumers stop rediscovering it
|
|
313
|
+
field-by-field.
|
|
314
|
+
|
|
315
|
+
- **#11 — `UpdateXBody extends Partial<Entity>`.** `collect-models.ts:61-94` does zero
|
|
316
|
+
structural inference and *cannot*: the Partial/subset relationship isn't expressible in
|
|
317
|
+
the JSON Schema we receive (it's flattened to an independent `$id` model before codegen
|
|
318
|
+
sees it). We can't synthesize a relationship the wire format doesn't carry. **Decline the
|
|
319
|
+
codegen change.** We will document the intended `as Partial<Entity>` bridge so consumers
|
|
320
|
+
don't each reinvent (and mis-scope) it.
|
|
321
|
+
|
|
322
|
+
---
|
|
323
|
+
|
|
324
|
+
## Session roadmap (sequencing)
|
|
325
|
+
|
|
326
|
+
1. ✅ **DONE — Workstream A** (`docs/superpowers/plans/2026-06-08-codegen-dx-surfacing.md`)
|
|
327
|
+
— #9, #8, #10-breadcrumb, #15 shipped 2026-06-08. **Process lesson (encode in future
|
|
328
|
+
plans):** changing `__fixtures__/users-envelope.json` is **cross-target** — it feeds every
|
|
329
|
+
target's e2e/integration tests, so a new route regenerates the Kotlin *and* Swift goldens
|
|
330
|
+
(`UPDATE_GOLDENS=1`), not just a 5→6 count bump. Pre-flight for any plan that inlines test
|
|
331
|
+
code should also grep the referenced test fixtures (the real `emit-index.test.ts` scopes are
|
|
332
|
+
`users`/`billing`/`adminUsers`, not the assumed `users`/`posts`), not only production-file
|
|
333
|
+
line anchors.
|
|
334
|
+
2. ✗ **DROPPED — Workstream E** (correlation id). Brainstormed 2026-06-08; existing primitives
|
|
335
|
+
cover it, no new API or docs warranted. See the Workstream E section above.
|
|
336
|
+
3. → **DOCS — Workstream B** (no-content #6). Vetted 2026-06-08; already authorable today,
|
|
337
|
+
folded into D as a recipe. See the Workstream B section above.
|
|
338
|
+
4. ✅ **DONE — Workstream C** (error-handling). Documented as a boundary, **no new API**:
|
|
339
|
+
`docs/client-error-handling.md` §11 "Design note: typed errors and your state layer" — we throw
|
|
340
|
+
instanceof-catchable classes; a state layer that flattens them is the state layer's concern;
|
|
341
|
+
`onError` is an observer by design.
|
|
342
|
+
5. ✅ **DONE (high-value) — Workstream D docs.** #6 no-content recipe →
|
|
343
|
+
`docs/http-integrations.md`; #10/#8 discoverability prose → `docs/client-error-handling.md`
|
|
344
|
+
§3a. **Deferred (optional follow-up):** #7 (`$id`/Record), #12 (form `toBody`), basePath/CORS
|
|
345
|
+
+ cross-origin adapter warning — lower-value, pull in on request.
|
|
346
|
+
6. ✅ **DONE — Decline reply** → `docs/handoffs/2026-06-08-dx-round2-declines.md` (#13/#11 with
|
|
347
|
+
the schema-authoring remedies, framed remedy-first).
|
|
348
|
+
|
|
349
|
+
**Net for the round:** Workstream A (codegen DX) was the only *code*; everything else is either
|
|
350
|
+
already-shipped capability that needs documenting (B, #6) or out of our lane (E dropped; #13/#11
|
|
351
|
+
declined; C likely mvc-kit's). That's the boundary holding — the library surfaces and documents
|
|
352
|
+
what it owns, and doesn't grow to wrap what it already enables.
|
|
353
|
+
|
|
354
|
+
Each workstream produces working, testable software (or a documented decision) on its own —
|
|
355
|
+
no cross-workstream barriers.
|
|
356
|
+
|
|
357
|
+
## Testing strategy (per workstream, filled in at plan time)
|
|
358
|
+
|
|
359
|
+
- **A:** fixture tests asserting (#9) input-less routes emit `void` and reject a stray
|
|
360
|
+
object; (#8) generated JSDoc + `Options` alias surface the options bag; (#10) `Errors`
|
|
361
|
+
type reachable at call site + `is${Service}Error` guard narrows; (#15) per-scope
|
|
362
|
+
interface satisfied by a two-method fake with no cast. Regression: routes *with* input
|
|
363
|
+
unchanged.
|
|
364
|
+
- **B:** no code — the no-content path already has coverage (`create-http.test.ts:110-119`,
|
|
365
|
+
`http.test.ts:70-82`, `emit-scope.test.ts:1253-1256`); the docs recipe should compile against
|
|
366
|
+
those existing behaviors.
|
|
367
|
+
- **C:** determined by the brainstorm outcome.
|
|
368
|
+
- **D:** doc review only.
|
|
369
|
+
|
|
370
|
+
## Out of scope (this round)
|
|
371
|
+
|
|
372
|
+
- mvc-kit's half of the error-flattening fix (surface `cause` on `TaskState`) — their repo.
|
|
373
|
+
- ts-channels WS correlation / `?token=` auth-seam asymmetry — cross-logged there.
|
|
374
|
+
- Consumer-side response projection (`Pick`-one-field) — procedure's call, not ours.
|
|
375
|
+
- A first-class body-level `clientId`/idempotency convention — superseded by Workstream E's
|
|
376
|
+
transport-level approach.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ts-procedures",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.6.0",
|
|
4
4
|
"description": "A TypeScript RPC framework that creates type-safe, schema-validated procedure calls with a single function definition. Define your procedures once and get full type inference, runtime validation, and framework integration hooks.",
|
|
5
5
|
"main": "build/exports.js",
|
|
6
6
|
"types": "build/exports.d.ts",
|
|
@@ -191,6 +191,15 @@
|
|
|
191
191
|
}
|
|
192
192
|
},
|
|
193
193
|
"errors": []
|
|
194
|
+
},
|
|
195
|
+
{
|
|
196
|
+
"kind": "api",
|
|
197
|
+
"name": "Heartbeat",
|
|
198
|
+
"scope": "users",
|
|
199
|
+
"method": "GET",
|
|
200
|
+
"fullPath": "/users/heartbeat",
|
|
201
|
+
"jsonSchema": { "req": {}, "res": {} },
|
|
202
|
+
"errors": []
|
|
194
203
|
}
|
|
195
204
|
],
|
|
196
205
|
"errors": [
|
|
@@ -180,6 +180,40 @@ describe('emitIndexFile', () => {
|
|
|
180
180
|
})
|
|
181
181
|
})
|
|
182
182
|
|
|
183
|
+
describe('per-scope client types (DX #15)', () => {
|
|
184
|
+
const groups = [usersGroup, billingGroup]
|
|
185
|
+
|
|
186
|
+
it('emits the aggregate client type from the factory return type', () => {
|
|
187
|
+
const out = emitIndexFile(groups, { serviceName: 'Api' })
|
|
188
|
+
expect(out).toContain('export type ApiClient = ReturnType<typeof createApiBindings>')
|
|
189
|
+
})
|
|
190
|
+
|
|
191
|
+
it('emits one per-scope client type as an indexed access into the aggregate', () => {
|
|
192
|
+
const out = emitIndexFile(groups, { serviceName: 'Api' })
|
|
193
|
+
expect(out).toContain("export type UsersClient = ApiClient['users']")
|
|
194
|
+
expect(out).toContain("export type BillingClient = ApiClient['billing']")
|
|
195
|
+
})
|
|
196
|
+
|
|
197
|
+
it('honors a custom serviceName in the client type names', () => {
|
|
198
|
+
const out = emitIndexFile(groups, { serviceName: 'Catalog' })
|
|
199
|
+
expect(out).toContain('export type CatalogClient = ReturnType<typeof createCatalogBindings>')
|
|
200
|
+
expect(out).toContain("export type UsersClient = CatalogClient['users']")
|
|
201
|
+
})
|
|
202
|
+
|
|
203
|
+
it('documents the aggregate and per-scope client types so the DI-seam intent is visible in the generated file', () => {
|
|
204
|
+
const out = emitIndexFile(groups, { serviceName: 'Api' })
|
|
205
|
+
// Aggregate type carries a one-line summary.
|
|
206
|
+
expect(out).toContain('/** Full typed client surface — every scope of `Api`. */')
|
|
207
|
+
// Each per-scope type names the scope and points at the DI use case.
|
|
208
|
+
expect(out).toContain(
|
|
209
|
+
'/** Narrow port for the `users` scope — inject as a DI seam without casting the aggregate client. */',
|
|
210
|
+
)
|
|
211
|
+
expect(out).toContain(
|
|
212
|
+
'/** Narrow port for the `billing` scope — inject as a DI seam without casting the aggregate client. */',
|
|
213
|
+
)
|
|
214
|
+
})
|
|
215
|
+
})
|
|
216
|
+
|
|
183
217
|
describe('clientImportPath', () => {
|
|
184
218
|
it('uses custom clientImportPath in both import statements', () => {
|
|
185
219
|
const output = emitIndexFile([usersGroup], { clientImportPath: '@my-app/client' })
|
|
@@ -106,6 +106,25 @@ export function emitIndexFile(groups: ScopeGroup[], options?: EmitIndexOptions):
|
|
|
106
106
|
'',
|
|
107
107
|
]
|
|
108
108
|
|
|
109
|
+
// Per-scope client interfaces, derived from the bindings factory's return type
|
|
110
|
+
// (DX #15). Reuses the `ReturnType<typeof factory>` pattern already used by the
|
|
111
|
+
// convenience client below. Lets a consumer type a dependency as the narrow scope
|
|
112
|
+
// port — `constructor(client: UsersClient = api.users)` — and a fake satisfies just
|
|
113
|
+
// that scope with no `as unknown as typeof api` cast. `${Service}Client` is the
|
|
114
|
+
// callable bundle; it does NOT collide with the `${Service}.<Scope>` type namespace.
|
|
115
|
+
// Each type carries a JSDoc line so the DI-seam intent is visible to a developer
|
|
116
|
+
// reading the generated file — not just in this emitter's source comment above.
|
|
117
|
+
const aggregateClientType = `${servicePascal}Client`
|
|
118
|
+
pieces.push(
|
|
119
|
+
`/** Full typed client surface — every scope of \`${servicePascal}\`. */`,
|
|
120
|
+
`export type ${aggregateClientType} = ReturnType<typeof ${factoryName}>`,
|
|
121
|
+
...groups.flatMap((g) => [
|
|
122
|
+
`/** Narrow port for the \`${g.camelCase}\` scope — inject as a DI seam without casting the aggregate client. */`,
|
|
123
|
+
`export type ${toPascalCase(g.camelCase)}Client = ${aggregateClientType}['${g.camelCase}']`,
|
|
124
|
+
]),
|
|
125
|
+
'',
|
|
126
|
+
)
|
|
127
|
+
|
|
109
128
|
// `createApiClient` is a convenience wrapper that wires `createClient` with
|
|
110
129
|
// the generated error registry baked in, then invokes the bindings factory.
|
|
111
130
|
// Consumers that want manual control over `createClient` still use the
|
|
@@ -1250,9 +1250,10 @@ describe('emitScopeFile API conditional return type', () => {
|
|
|
1250
1250
|
expect(out).toContain('{ headers: GetPreflightResponseHeaders }')
|
|
1251
1251
|
})
|
|
1252
1252
|
|
|
1253
|
-
it('neither body nor headers: return type is void', async () => {
|
|
1253
|
+
it('neither body nor headers: param type is void, return type is void', async () => {
|
|
1254
1254
|
const out = await emitScopeFile(apiGroupNoBody)
|
|
1255
|
-
expect(out).toContain('client.bindCallable<
|
|
1255
|
+
expect(out).toContain('client.bindCallable<void, void>')
|
|
1256
|
+
expect(out).not.toContain('client.bindCallable<unknown,')
|
|
1256
1257
|
})
|
|
1257
1258
|
})
|
|
1258
1259
|
|
|
@@ -1276,9 +1277,9 @@ describe('emitScopeFile API conditional return type', () => {
|
|
|
1276
1277
|
expect(out).toContain('{ headers: Preflight.GetPreflight.Response.Headers }')
|
|
1277
1278
|
})
|
|
1278
1279
|
|
|
1279
|
-
it('neither body nor headers: return type is void', async () => {
|
|
1280
|
+
it('neither body nor headers: param type is void, return type is void', async () => {
|
|
1280
1281
|
const out = await emitScopeFile(apiGroupNoBody, { namespaceTypes: true })
|
|
1281
|
-
expect(out).toContain('client.bindCallable<
|
|
1282
|
+
expect(out).toContain('client.bindCallable<void, void>')
|
|
1282
1283
|
})
|
|
1283
1284
|
})
|
|
1284
1285
|
})
|
|
@@ -1586,3 +1587,92 @@ describe('emitScopeFile http-stream kind', () => {
|
|
|
1586
1587
|
})
|
|
1587
1588
|
})
|
|
1588
1589
|
})
|
|
1590
|
+
|
|
1591
|
+
// Input-less RPC (no body) and stream (no params) — exercise the void-param fallback
|
|
1592
|
+
// across the RPC and stream emission paths, not just API.
|
|
1593
|
+
const rpcGroupNoInput: ScopeGroup = {
|
|
1594
|
+
scopeKey: 'session',
|
|
1595
|
+
camelCase: 'session',
|
|
1596
|
+
routes: [
|
|
1597
|
+
{
|
|
1598
|
+
kind: 'rpc',
|
|
1599
|
+
name: 'Logout',
|
|
1600
|
+
path: '/session/logout',
|
|
1601
|
+
method: 'post',
|
|
1602
|
+
scope: 'session',
|
|
1603
|
+
version: 1,
|
|
1604
|
+
jsonSchema: {
|
|
1605
|
+
response: { type: 'object', properties: { ok: { type: 'boolean' } }, required: ['ok'] },
|
|
1606
|
+
},
|
|
1607
|
+
} satisfies RPCHttpRouteDoc,
|
|
1608
|
+
],
|
|
1609
|
+
}
|
|
1610
|
+
|
|
1611
|
+
const streamGroupNoParams: ScopeGroup = {
|
|
1612
|
+
scopeKey: 'ticks',
|
|
1613
|
+
camelCase: 'ticks',
|
|
1614
|
+
routes: [
|
|
1615
|
+
{
|
|
1616
|
+
kind: 'stream',
|
|
1617
|
+
name: 'WatchTicks',
|
|
1618
|
+
path: '/ticks/stream',
|
|
1619
|
+
methods: ['get'],
|
|
1620
|
+
streamMode: 'sse',
|
|
1621
|
+
scope: 'ticks',
|
|
1622
|
+
version: 1,
|
|
1623
|
+
jsonSchema: {
|
|
1624
|
+
params: undefined,
|
|
1625
|
+
yieldType: { type: 'object', properties: { n: { type: 'number' } }, required: ['n'] },
|
|
1626
|
+
returnType: undefined,
|
|
1627
|
+
},
|
|
1628
|
+
} satisfies StreamHttpRouteDoc,
|
|
1629
|
+
],
|
|
1630
|
+
}
|
|
1631
|
+
|
|
1632
|
+
describe('emitScopeFile input-less routes (void params)', () => {
|
|
1633
|
+
it('RPC route with no body emits void as the params type arg', async () => {
|
|
1634
|
+
const out = await emitScopeFile(rpcGroupNoInput)
|
|
1635
|
+
expect(out).toContain('client.bindCallable<void,')
|
|
1636
|
+
expect(out).not.toContain('client.bindCallable<unknown,')
|
|
1637
|
+
})
|
|
1638
|
+
|
|
1639
|
+
it('stream route with no params emits void as the params type', async () => {
|
|
1640
|
+
const out = await emitScopeFile(streamGroupNoParams)
|
|
1641
|
+
// Stream callables are direct methods: WatchTicks(params: void, options?)
|
|
1642
|
+
expect(out).toContain('WatchTicks(params: void')
|
|
1643
|
+
expect(out).not.toContain('WatchTicks(params: unknown')
|
|
1644
|
+
})
|
|
1645
|
+
})
|
|
1646
|
+
|
|
1647
|
+
describe('emitScopeFile callable JSDoc surfaces options + errors', () => {
|
|
1648
|
+
it('mentions the per-call options bag on an RPC callable', async () => {
|
|
1649
|
+
const out = await emitScopeFile(rpcGroup)
|
|
1650
|
+
expect(out).toContain('POST') // existing method label preserved
|
|
1651
|
+
expect(out).toContain('@param options')
|
|
1652
|
+
expect(out).toContain('ProcedureCallOptions')
|
|
1653
|
+
expect(out).toContain('signal')
|
|
1654
|
+
})
|
|
1655
|
+
|
|
1656
|
+
it('mentions declared errors + Scope.Route.Errors on a route with errors (namespace)', async () => {
|
|
1657
|
+
const out = await emitScopeFile(rpcGroupWithErrors, {
|
|
1658
|
+
namespaceTypes: true,
|
|
1659
|
+
errorKeys: new Set(['NotFound']),
|
|
1660
|
+
serviceName: 'Api',
|
|
1661
|
+
})
|
|
1662
|
+
expect(out).toContain('@throws')
|
|
1663
|
+
expect(out).toContain('Users.GetUser.Errors')
|
|
1664
|
+
expect(out).toContain('instanceof')
|
|
1665
|
+
})
|
|
1666
|
+
|
|
1667
|
+
it('omits the @throws line when a route declares no errors', async () => {
|
|
1668
|
+
const out = await emitScopeFile(rpcGroupNoErrors, { serviceName: 'Api' })
|
|
1669
|
+
expect(out).not.toContain('@throws')
|
|
1670
|
+
expect(out).toContain('@param options') // options line still present
|
|
1671
|
+
})
|
|
1672
|
+
|
|
1673
|
+
it('mentions options on a stream callable but no @throws', async () => {
|
|
1674
|
+
const out = await emitScopeFile(streamGroup)
|
|
1675
|
+
expect(out).toContain('@param options')
|
|
1676
|
+
expect(out).not.toContain('@throws')
|
|
1677
|
+
})
|
|
1678
|
+
})
|