ts-procedures 9.2.0 → 10.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (161) hide show
  1. package/CHANGELOG.md +54 -0
  2. package/build/adapters/hono/envelope-parity.test.js +17 -6
  3. package/build/adapters/hono/envelope-parity.test.js.map +1 -1
  4. package/build/codegen/bin/cli.js +1 -1
  5. package/build/codegen/bin/cli.js.map +1 -1
  6. package/build/codegen/constants.js +2 -2
  7. package/build/codegen/constants.js.map +1 -1
  8. package/build/codegen/emit/api-route.js +1 -1
  9. package/build/codegen/emit/api-route.js.map +1 -1
  10. package/build/codegen/emit/scope-file.js +1 -1
  11. package/build/codegen/emit/scope-file.js.map +1 -1
  12. package/build/codegen/emit-errors.integration.test.js +2 -2
  13. package/build/codegen/emit-errors.integration.test.js.map +1 -1
  14. package/build/codegen/resolve-envelope.js +1 -1
  15. package/build/codegen/resolve-envelope.js.map +1 -1
  16. package/build/codegen/test-helpers/run-tsc.js +1 -1
  17. package/build/codegen/test-helpers/run-tsc.js.map +1 -1
  18. package/build/exports.d.ts +1 -0
  19. package/build/exports.js +4 -0
  20. package/build/exports.js.map +1 -1
  21. package/build/server/doc-registry.js +3 -0
  22. package/build/server/doc-registry.js.map +1 -1
  23. package/build/server/doc-registry.test.js +31 -0
  24. package/build/server/doc-registry.test.js.map +1 -1
  25. package/build/server/index.d.ts +1 -0
  26. package/build/server/index.js +1 -0
  27. package/build/server/index.js.map +1 -1
  28. package/build/server/spec-version.d.ts +24 -0
  29. package/build/server/spec-version.js +26 -0
  30. package/build/server/spec-version.js.map +1 -0
  31. package/build/server/types.d.ts +15 -0
  32. package/build/version.d.ts +9 -0
  33. package/build/version.js +11 -0
  34. package/build/version.js.map +1 -0
  35. package/docs/doc-envelope-spec.md +291 -0
  36. package/docs/doc-envelope.schema.json +253 -0
  37. package/docs/http-integrations.md +27 -1
  38. package/package.json +8 -8
  39. package/src/adapters/hono/envelope-parity.test.ts +18 -6
  40. package/src/codegen/bin/cli.ts +1 -1
  41. package/src/codegen/constants.ts +2 -2
  42. package/src/codegen/emit/api-route.ts +1 -1
  43. package/src/codegen/emit/scope-file.ts +2 -1
  44. package/src/codegen/emit-errors.integration.test.ts +2 -2
  45. package/src/codegen/resolve-envelope.ts +1 -1
  46. package/src/codegen/test-helpers/run-tsc.ts +1 -0
  47. package/src/exports.ts +4 -0
  48. package/src/server/doc-registry.test.ts +34 -0
  49. package/src/server/doc-registry.ts +3 -0
  50. package/src/server/index.ts +1 -0
  51. package/src/server/spec-version.ts +27 -0
  52. package/src/server/types.ts +15 -0
  53. package/src/version.ts +11 -0
  54. package/build/errors.d.ts +0 -33
  55. package/build/errors.js +0 -91
  56. package/build/errors.js.map +0 -1
  57. package/build/errors.test.d.ts +0 -1
  58. package/build/errors.test.js +0 -122
  59. package/build/errors.test.js.map +0 -1
  60. package/build/implementations/http/doc-registry.d.ts +0 -28
  61. package/build/implementations/http/doc-registry.js +0 -96
  62. package/build/implementations/http/doc-registry.js.map +0 -1
  63. package/build/implementations/http/doc-registry.test.d.ts +0 -1
  64. package/build/implementations/http/doc-registry.test.js +0 -516
  65. package/build/implementations/http/doc-registry.test.js.map +0 -1
  66. package/build/implementations/http/error-taxonomy.d.ts +0 -249
  67. package/build/implementations/http/error-taxonomy.js +0 -252
  68. package/build/implementations/http/error-taxonomy.js.map +0 -1
  69. package/build/implementations/http/error-taxonomy.test.d.ts +0 -1
  70. package/build/implementations/http/error-taxonomy.test.js +0 -399
  71. package/build/implementations/http/error-taxonomy.test.js.map +0 -1
  72. package/build/implementations/http/express-rpc/error-taxonomy.test.d.ts +0 -1
  73. package/build/implementations/http/express-rpc/error-taxonomy.test.js +0 -83
  74. package/build/implementations/http/express-rpc/error-taxonomy.test.js.map +0 -1
  75. package/build/implementations/http/express-rpc/index.d.ts +0 -125
  76. package/build/implementations/http/express-rpc/index.js +0 -216
  77. package/build/implementations/http/express-rpc/index.js.map +0 -1
  78. package/build/implementations/http/express-rpc/index.test.d.ts +0 -1
  79. package/build/implementations/http/express-rpc/index.test.js +0 -684
  80. package/build/implementations/http/express-rpc/index.test.js.map +0 -1
  81. package/build/implementations/http/express-rpc/types.d.ts +0 -11
  82. package/build/implementations/http/express-rpc/types.js +0 -2
  83. package/build/implementations/http/express-rpc/types.js.map +0 -1
  84. package/build/implementations/http/hono-api/error-taxonomy.test.d.ts +0 -1
  85. package/build/implementations/http/hono-api/error-taxonomy.test.js +0 -137
  86. package/build/implementations/http/hono-api/error-taxonomy.test.js.map +0 -1
  87. package/build/implementations/http/hono-api/index.d.ts +0 -151
  88. package/build/implementations/http/hono-api/index.js +0 -344
  89. package/build/implementations/http/hono-api/index.js.map +0 -1
  90. package/build/implementations/http/hono-api/index.test.d.ts +0 -1
  91. package/build/implementations/http/hono-api/index.test.js +0 -992
  92. package/build/implementations/http/hono-api/index.test.js.map +0 -1
  93. package/build/implementations/http/hono-api/types.d.ts +0 -13
  94. package/build/implementations/http/hono-api/types.js +0 -2
  95. package/build/implementations/http/hono-api/types.js.map +0 -1
  96. package/build/implementations/http/hono-rpc/error-taxonomy.test.d.ts +0 -1
  97. package/build/implementations/http/hono-rpc/error-taxonomy.test.js +0 -64
  98. package/build/implementations/http/hono-rpc/error-taxonomy.test.js.map +0 -1
  99. package/build/implementations/http/hono-rpc/index.d.ts +0 -130
  100. package/build/implementations/http/hono-rpc/index.js +0 -209
  101. package/build/implementations/http/hono-rpc/index.js.map +0 -1
  102. package/build/implementations/http/hono-rpc/index.test.d.ts +0 -1
  103. package/build/implementations/http/hono-rpc/index.test.js +0 -828
  104. package/build/implementations/http/hono-rpc/index.test.js.map +0 -1
  105. package/build/implementations/http/hono-rpc/types.d.ts +0 -11
  106. package/build/implementations/http/hono-rpc/types.js +0 -2
  107. package/build/implementations/http/hono-rpc/types.js.map +0 -1
  108. package/build/implementations/http/hono-stream/error-taxonomy.test.d.ts +0 -1
  109. package/build/implementations/http/hono-stream/error-taxonomy.test.js +0 -159
  110. package/build/implementations/http/hono-stream/error-taxonomy.test.js.map +0 -1
  111. package/build/implementations/http/hono-stream/index.d.ts +0 -171
  112. package/build/implementations/http/hono-stream/index.js +0 -415
  113. package/build/implementations/http/hono-stream/index.js.map +0 -1
  114. package/build/implementations/http/hono-stream/index.test.d.ts +0 -1
  115. package/build/implementations/http/hono-stream/index.test.js +0 -1383
  116. package/build/implementations/http/hono-stream/index.test.js.map +0 -1
  117. package/build/implementations/http/hono-stream/types.d.ts +0 -15
  118. package/build/implementations/http/hono-stream/types.js +0 -2
  119. package/build/implementations/http/hono-stream/types.js.map +0 -1
  120. package/build/implementations/http/on-request-error.test.d.ts +0 -1
  121. package/build/implementations/http/on-request-error.test.js +0 -173
  122. package/build/implementations/http/on-request-error.test.js.map +0 -1
  123. package/build/implementations/http/route-errors.test.d.ts +0 -1
  124. package/build/implementations/http/route-errors.test.js +0 -139
  125. package/build/implementations/http/route-errors.test.js.map +0 -1
  126. package/build/implementations/types.d.ts +0 -192
  127. package/build/implementations/types.js +0 -2
  128. package/build/implementations/types.js.map +0 -1
  129. package/build/index.d.ts +0 -165
  130. package/build/index.js +0 -258
  131. package/build/index.js.map +0 -1
  132. package/build/index.test.d.ts +0 -1
  133. package/build/index.test.js +0 -920
  134. package/build/index.test.js.map +0 -1
  135. package/build/schema/extract-json-schema.d.ts +0 -2
  136. package/build/schema/extract-json-schema.js +0 -12
  137. package/build/schema/extract-json-schema.js.map +0 -1
  138. package/build/schema/extract-json-schema.test.d.ts +0 -1
  139. package/build/schema/extract-json-schema.test.js +0 -23
  140. package/build/schema/extract-json-schema.test.js.map +0 -1
  141. package/build/schema/parser.d.ts +0 -28
  142. package/build/schema/parser.js +0 -170
  143. package/build/schema/parser.js.map +0 -1
  144. package/build/schema/parser.test.d.ts +0 -1
  145. package/build/schema/parser.test.js +0 -120
  146. package/build/schema/parser.test.js.map +0 -1
  147. package/build/schema/resolve-schema-lib.d.ts +0 -12
  148. package/build/schema/resolve-schema-lib.js +0 -11
  149. package/build/schema/resolve-schema-lib.js.map +0 -1
  150. package/build/schema/resolve-schema-lib.test.d.ts +0 -1
  151. package/build/schema/resolve-schema-lib.test.js +0 -17
  152. package/build/schema/resolve-schema-lib.test.js.map +0 -1
  153. package/build/schema/types.d.ts +0 -8
  154. package/build/schema/types.js +0 -2
  155. package/build/schema/types.js.map +0 -1
  156. package/build/stack-utils.d.ts +0 -25
  157. package/build/stack-utils.js +0 -95
  158. package/build/stack-utils.js.map +0 -1
  159. package/build/stack-utils.test.d.ts +0 -1
  160. package/build/stack-utils.test.js +0 -80
  161. package/build/stack-utils.test.js.map +0 -1
@@ -0,0 +1,253 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema#",
3
+ "$id": "https://ts-procedures.dev/schemas/doc-envelope.schema.json",
4
+ "title": "ts-procedures DocEnvelope",
5
+ "description": "The JSON document a ts-procedures server exposes (via builder.toDocEnvelope() / DocRegistry.toJSON()). Describes every procedure/route the server serves, the global error catalog, and global headers. Payload schemas embedded under each route's `jsonSchema` are arbitrary JSON Schema (Draft-07) objects and are intentionally left unconstrained here.",
6
+ "type": "object",
7
+ "required": ["basePath", "headers", "errors", "routes"],
8
+ "properties": {
9
+ "specVersion": {
10
+ "type": "integer",
11
+ "minimum": 1,
12
+ "description": "Wire-format version of the envelope. A small monotonic integer, bumped ONLY when the envelope shape changes — not on every package release. Branch on this to pick a parser. ABSENT means treat as 1 (envelopes predating this field). Emitted by ts-procedures servers; optional here so older/hand-built documents still validate."
13
+ },
14
+ "generatorVersion": {
15
+ "type": "string",
16
+ "description": "ts-procedures package version that produced the envelope, e.g. \"10.0.0\". Informational only (telemetry/debugging) — do NOT use it for parse-compatibility decisions; use specVersion."
17
+ },
18
+ "basePath": {
19
+ "type": "string",
20
+ "description": "Path prefix shared by all routes, e.g. \"/api\". May be the empty string."
21
+ },
22
+ "headers": {
23
+ "type": "array",
24
+ "description": "Global HTTP headers documented for the whole API.",
25
+ "items": { "$ref": "#/definitions/HeaderDoc" }
26
+ },
27
+ "errors": {
28
+ "type": "array",
29
+ "description": "Catalog of every error the API may return (framework defaults + user-defined taxonomy). Routes reference these by name via their `errors` array.",
30
+ "items": { "$ref": "#/definitions/ErrorDoc" }
31
+ },
32
+ "routes": {
33
+ "type": "array",
34
+ "description": "All procedures/routes. Discriminated union on `kind`.",
35
+ "items": { "$ref": "#/definitions/AnyRouteDoc" }
36
+ }
37
+ },
38
+ "additionalProperties": true,
39
+ "definitions": {
40
+ "JsonSchema": {
41
+ "description": "An embedded JSON Schema (Draft-07) object describing a payload. Left unconstrained on purpose — render it generically.",
42
+ "type": "object",
43
+ "additionalProperties": true
44
+ },
45
+ "HeaderDoc": {
46
+ "type": "object",
47
+ "required": ["name"],
48
+ "properties": {
49
+ "name": { "type": "string" },
50
+ "description": { "type": "string" },
51
+ "required": { "type": "boolean" },
52
+ "example": { "type": "string" }
53
+ },
54
+ "additionalProperties": true
55
+ },
56
+ "ErrorDoc": {
57
+ "type": "object",
58
+ "required": ["name", "statusCode", "description"],
59
+ "properties": {
60
+ "name": {
61
+ "type": "string",
62
+ "description": "Unique error name. Routes link to it via their `errors` array."
63
+ },
64
+ "statusCode": {
65
+ "type": "integer",
66
+ "description": "HTTP status code returned for this error.",
67
+ "minimum": 100,
68
+ "maximum": 599
69
+ },
70
+ "description": { "type": "string" },
71
+ "schema": {
72
+ "$ref": "#/definitions/JsonSchema",
73
+ "description": "JSON Schema of the error response body. Optional."
74
+ }
75
+ },
76
+ "additionalProperties": true
77
+ },
78
+
79
+ "AnyRouteDoc": {
80
+ "oneOf": [
81
+ { "$ref": "#/definitions/RPCRouteDoc" },
82
+ { "$ref": "#/definitions/StreamRouteDoc" },
83
+ { "$ref": "#/definitions/APIRouteDoc" },
84
+ { "$ref": "#/definitions/HttpStreamRouteDoc" }
85
+ ]
86
+ },
87
+
88
+ "HttpMethod": {
89
+ "description": "HTTP method. Canonical wire form is lowercase; treat case-insensitively when rendering.",
90
+ "type": "string",
91
+ "enum": ["get", "post", "put", "delete", "patch", "head", "GET", "POST", "PUT", "DELETE", "PATCH", "HEAD"]
92
+ },
93
+
94
+ "StreamMode": {
95
+ "type": "string",
96
+ "enum": ["sse", "text"],
97
+ "description": "Stream transport. `sse` = Server-Sent Events; `text` = raw text chunks."
98
+ },
99
+
100
+ "Scope": {
101
+ "description": "Logical grouping. A single segment or an array of segments.",
102
+ "oneOf": [
103
+ { "type": "string" },
104
+ { "type": "array", "items": { "type": "string" } }
105
+ ]
106
+ },
107
+
108
+ "RPCRouteDoc": {
109
+ "title": "RPC route (kind = rpc)",
110
+ "description": "JSON-RPC-style procedure. Always POST. Path embeds scope + version.",
111
+ "type": "object",
112
+ "required": ["kind", "name", "path", "method", "scope", "version", "jsonSchema"],
113
+ "properties": {
114
+ "kind": { "const": "rpc" },
115
+ "name": { "type": "string" },
116
+ "path": { "type": "string", "description": "Full path incl. basePath + version, e.g. /api/users/get-user/1" },
117
+ "method": { "const": "post" },
118
+ "scope": { "$ref": "#/definitions/Scope" },
119
+ "version": { "type": "number" },
120
+ "errors": { "type": "array", "items": { "type": "string" } },
121
+ "jsonSchema": {
122
+ "type": "object",
123
+ "properties": {
124
+ "body": { "$ref": "#/definitions/JsonSchema", "description": "Request body schema (validated)." },
125
+ "response": { "$ref": "#/definitions/JsonSchema", "description": "Response body schema (doc only)." }
126
+ },
127
+ "additionalProperties": true
128
+ }
129
+ },
130
+ "additionalProperties": true
131
+ },
132
+
133
+ "StreamRouteDoc": {
134
+ "title": "RPC stream route (kind = stream)",
135
+ "description": "Streaming RPC procedure. Served over both POST and GET. Path embeds scope + version.",
136
+ "type": "object",
137
+ "required": ["kind", "name", "path", "methods", "streamMode", "scope", "version", "jsonSchema"],
138
+ "properties": {
139
+ "kind": { "const": "stream" },
140
+ "name": { "type": "string" },
141
+ "path": { "type": "string" },
142
+ "methods": {
143
+ "type": "array",
144
+ "description": "Allowed methods, conventionally [\"post\", \"get\"].",
145
+ "items": { "type": "string", "enum": ["get", "post"] }
146
+ },
147
+ "streamMode": { "$ref": "#/definitions/StreamMode" },
148
+ "scope": { "$ref": "#/definitions/Scope" },
149
+ "version": { "type": "number" },
150
+ "errors": { "type": "array", "items": { "type": "string" }, "description": "Pre-stream errors only." },
151
+ "jsonSchema": {
152
+ "type": "object",
153
+ "properties": {
154
+ "params": { "$ref": "#/definitions/JsonSchema", "description": "Query params (GET) or body (POST)." },
155
+ "yieldType": {
156
+ "$ref": "#/definitions/JsonSchema",
157
+ "description": "Schema for each streamed value. In `sse` mode this is the SSE envelope { data, event, id, retry } whose `data` holds the user's yield schema; in `text` mode it is the raw yield schema."
158
+ },
159
+ "returnType": { "$ref": "#/definitions/JsonSchema", "description": "Final return value schema." }
160
+ },
161
+ "additionalProperties": true
162
+ }
163
+ },
164
+ "additionalProperties": true
165
+ },
166
+
167
+ "APIRouteDoc": {
168
+ "title": "REST route (kind = api)",
169
+ "description": "REST-style HTTP endpoint with explicit method + path.",
170
+ "type": "object",
171
+ "required": ["kind", "name", "method", "fullPath", "jsonSchema"],
172
+ "properties": {
173
+ "kind": { "const": "api" },
174
+ "name": { "type": "string" },
175
+ "scope": { "type": "string" },
176
+ "path": { "type": "string", "description": "Path as registered (may include :params), e.g. /users/:id. May be omitted in some envelopes; prefer fullPath." },
177
+ "method": { "$ref": "#/definitions/HttpMethod" },
178
+ "fullPath": { "type": "string", "description": "Resolved path incl. basePath prefix, e.g. /api/users/:id." },
179
+ "successStatus": { "type": "integer", "description": "Status on success. Defaults: POST→201, DELETE→204, else 200." },
180
+ "errors": { "type": "array", "items": { "type": "string" } },
181
+ "jsonSchema": {
182
+ "type": "object",
183
+ "properties": {
184
+ "req": {
185
+ "type": "object",
186
+ "properties": {
187
+ "pathParams": { "$ref": "#/definitions/JsonSchema" },
188
+ "query": { "$ref": "#/definitions/JsonSchema" },
189
+ "body": { "$ref": "#/definitions/JsonSchema" },
190
+ "headers": { "$ref": "#/definitions/JsonSchema" }
191
+ },
192
+ "additionalProperties": true
193
+ },
194
+ "res": {
195
+ "type": "object",
196
+ "properties": {
197
+ "body": { "$ref": "#/definitions/JsonSchema" },
198
+ "headers": { "$ref": "#/definitions/JsonSchema" }
199
+ },
200
+ "additionalProperties": true
201
+ }
202
+ },
203
+ "additionalProperties": true
204
+ }
205
+ },
206
+ "additionalProperties": true
207
+ },
208
+
209
+ "HttpStreamRouteDoc": {
210
+ "title": "REST stream route (kind = http-stream)",
211
+ "description": "REST-style streaming endpoint. Response has no single body; values arrive via `yield`. Currently always SSE.",
212
+ "type": "object",
213
+ "required": ["kind", "name", "method", "fullPath", "streamMode", "jsonSchema"],
214
+ "properties": {
215
+ "kind": { "const": "http-stream" },
216
+ "name": { "type": "string" },
217
+ "scope": { "type": "string" },
218
+ "path": { "type": "string" },
219
+ "method": { "$ref": "#/definitions/HttpMethod" },
220
+ "fullPath": { "type": "string" },
221
+ "streamMode": { "$ref": "#/definitions/StreamMode" },
222
+ "errors": { "type": "array", "items": { "type": "string" } },
223
+ "jsonSchema": {
224
+ "type": "object",
225
+ "properties": {
226
+ "req": {
227
+ "type": "object",
228
+ "properties": {
229
+ "pathParams": { "$ref": "#/definitions/JsonSchema" },
230
+ "query": { "$ref": "#/definitions/JsonSchema" },
231
+ "body": { "$ref": "#/definitions/JsonSchema" },
232
+ "headers": { "$ref": "#/definitions/JsonSchema" }
233
+ },
234
+ "additionalProperties": true
235
+ },
236
+ "res": {
237
+ "type": "object",
238
+ "description": "Response headers only — streaming responses have no single body.",
239
+ "properties": {
240
+ "headers": { "$ref": "#/definitions/JsonSchema" }
241
+ },
242
+ "additionalProperties": true
243
+ },
244
+ "yield": { "$ref": "#/definitions/JsonSchema", "description": "Schema for each streamed value. NOT wrapped in an SSE envelope (unlike kind=stream)." },
245
+ "returnType": { "$ref": "#/definitions/JsonSchema", "description": "Final return value schema." }
246
+ },
247
+ "additionalProperties": true
248
+ }
249
+ },
250
+ "additionalProperties": true
251
+ }
252
+ }
253
+ }
@@ -311,7 +311,33 @@ const docs = new DocRegistry({ errors: appErrors, basePath: '/api' })
311
311
 
312
312
  `http-stream` route docs include the route's `yield` and `res.headers` schemas. (Through v8, live envelopes silently dropped these for `http-stream` routes, so generated clients lost those types unless the envelope was hand-authored; v9 fixed this.)
313
313
 
314
- The `DocRegistry` output is the input for [Client Code Generation](./client-and-codegen.md).
314
+ ### Envelope versioning
315
+
316
+ Every envelope carries two top-level metadata fields so downstream consumers (docs viewers, codegen, dashboards) can reason about format compatibility:
317
+
318
+ ```jsonc
319
+ {
320
+ "specVersion": 1, // wire-format version of the envelope itself
321
+ "generatorVersion": "10.0.0", // ts-procedures package version that produced it
322
+ "basePath": "/api",
323
+ "headers": [],
324
+ "errors": [ /* ... */ ],
325
+ "routes": [ /* ... */ ]
326
+ }
327
+ ```
328
+
329
+ - **`specVersion`** is a small monotonic integer, bumped **only** when the envelope shape changes in a way parsers must react to — never on ordinary package releases. Branch on it. An envelope with no `specVersion` predates the field and must be treated as `1`. The current value is exported as `DOC_ENVELOPE_SPEC_VERSION` from `ts-procedures` and `ts-procedures/server`.
330
+ - **`generatorVersion`** is the producing package version (`DOC_ENVELOPE_GENERATOR_VERSION`, exported from `ts-procedures/server`). It is informational only — for telemetry and "which release served this?" — and must **not** drive parse-compatibility decisions, since it churns on every release regardless of the envelope format.
331
+
332
+ If you'd rather not advertise the exact package version on a public docs endpoint, strip it with the `transform` hook:
333
+
334
+ ```typescript
335
+ app.get('/docs', (c) => c.json(
336
+ builder.toDocEnvelope({ transform: ({ generatorVersion, ...env }) => env }),
337
+ ))
338
+ ```
339
+
340
+ The `DocRegistry` output is the input for [Client Code Generation](./client-and-codegen.md). Building a third-party docs viewer or other tool that consumes the served envelope? The full wire contract — every field, per-kind shapes, and a validatable JSON Schema — is in [DocEnvelope Spec](./doc-envelope-spec.md) (`doc-envelope.schema.json`).
315
341
 
316
342
  ## Type Exports
317
343
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ts-procedures",
3
- "version": "9.2.0",
3
+ "version": "10.1.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",
@@ -76,15 +76,15 @@
76
76
  "typebox": "^1.0.30"
77
77
  },
78
78
  "devDependencies": {
79
- "@eslint/js": "^9.17.0",
80
- "astro": "^6.3.1",
81
- "eslint": "^9.17.0",
82
- "globals": "^15.0.0",
83
- "hono": "^4.7.4",
84
- "typescript": "^5.7.0",
85
- "typescript-eslint": "^8.53.0",
79
+ "@eslint/js": "^10.0.1",
86
80
  "@typescript-eslint/eslint-plugin": "^8.53.0",
87
81
  "@typescript-eslint/parser": "^8.53.0",
82
+ "astro": "^7.0.2",
83
+ "eslint": "^10.5.0",
84
+ "globals": "^17.7.0",
85
+ "hono": "^4.7.4",
86
+ "typescript": "^6.0.3",
87
+ "typescript-eslint": "^8.53.0",
88
88
  "vitest": "^4.0.18"
89
89
  }
90
90
  }
@@ -3,8 +3,10 @@ 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' }
6
7
  import { Procedures } from '../../core/procedures.js'
7
8
  import { HonoAppBuilder, defineErrorTaxonomy } from './index.js'
9
+ import { DOC_ENVELOPE_SPEC_VERSION } from '../../server/spec-version.js'
8
10
  import type { RPCConfig } from '../../server/types.js'
9
11
 
10
12
  /**
@@ -16,12 +18,15 @@ import type { RPCConfig } from '../../server/types.js'
16
18
  * The envelope is codegen's input; if this test fails, generated client output
17
19
  * WILL drift.
18
20
  *
19
- * ONE documented deviation from the raw v8 capture: v8's CreateHttpStream
20
- * dropped the `yield` schema (and `res.headers`) from http-stream route docs —
21
- * the registration stored `yieldType` while the doc builder read `yield`. v9
22
- * fixes that, so the fixture's TailUser route was patched to include the
23
- * `yield` schema the builder now (correctly) emits. Everything else is the
24
- * untouched v8 capture.
21
+ * TWO documented deviations from the raw v8 capture:
22
+ * 1. v8's CreateHttpStream dropped the `yield` schema (and `res.headers`) from
23
+ * http-stream route docs — the registration stored `yieldType` while the
24
+ * doc builder read `yield`. v9 fixes that, so the fixture's TailUser route
25
+ * was patched to include the `yield` schema the builder now emits.
26
+ * 2. v9 adds envelope-level `specVersion`/`generatorVersion` metadata that v8
27
+ * never emitted. These are asserted explicitly below, then stripped before
28
+ * the deep-equal so the rest stays byte-for-byte with the v8 capture.
29
+ * Everything else is the untouched v8 capture.
25
30
  */
26
31
  class TeapotError extends Error {}
27
32
 
@@ -121,6 +126,13 @@ describe('DocEnvelope parity with v8.6.0', () => {
121
126
  const expected = JSON.parse(await readFile(fixturePath, 'utf-8'))
122
127
  const actual = JSON.parse(JSON.stringify(builder.toDocEnvelope()))
123
128
 
129
+ // Deviation #2: assert the new v9 envelope metadata, then strip it so the
130
+ // remaining shape matches the untouched v8 capture.
131
+ expect(actual.specVersion).toBe(DOC_ENVELOPE_SPEC_VERSION)
132
+ expect(actual.generatorVersion).toBe(pkg.version)
133
+ delete actual.specVersion
134
+ delete actual.generatorVersion
135
+
124
136
  expect(actual).toEqual(expected)
125
137
  })
126
138
  })
@@ -79,7 +79,7 @@ export async function loadConfigFile(configPath?: string): Promise<CodegenConfig
79
79
  } catch (err) {
80
80
  if (configPath !== undefined) {
81
81
  // Explicit path — always throw
82
- throw new Error(`[ts-procedures-codegen] Failed to load config from ${filePath}: ${err instanceof Error ? err.message : err}`)
82
+ throw new Error(`[ts-procedures-codegen] Failed to load config from ${filePath}: ${err instanceof Error ? err.message : err}`, { cause: err })
83
83
  }
84
84
  // Default path — silently ignore if not found
85
85
  return undefined
@@ -1,4 +1,4 @@
1
- import pkg from '../../package.json' with { type: 'json' }
1
+ import { PACKAGE_VERSION } from '../version.js'
2
2
 
3
3
  /**
4
4
  * Stable, version-agnostic token embedded in every generated file (across all
@@ -7,4 +7,4 @@ import pkg from '../../package.json' with { type: 'json' }
7
7
  * the package version (an orphan left by an older release must still match).
8
8
  */
9
9
  export const CODEGEN_SIGNATURE = 'ts-procedures-codegen'
10
- export const CODEGEN_HEADER = `// Auto-generated by ${CODEGEN_SIGNATURE} (v${pkg.version}) — do not edit`
10
+ export const CODEGEN_HEADER = `// Auto-generated by ${CODEGEN_SIGNATURE} (v${PACKAGE_VERSION}) — do not edit`
@@ -62,7 +62,7 @@ export async function emitApiRoute(route: APIHttpRouteDoc, ctx: EmitRouteContext
62
62
 
63
63
  const declarations: string[] = []
64
64
  let paramsTypeName = 'void'
65
- let returnTypeName = 'void'
65
+ let returnTypeName: string
66
66
 
67
67
  // Track reserved names across all sub-namespaces. Model names are reserved
68
68
  // so an ajsc-extracted sub-type can't silently merge with a referenced model.
@@ -132,7 +132,8 @@ export async function emitScopeFile(
132
132
  } catch (err) {
133
133
  const msg = err instanceof Error ? err.message : String(err)
134
134
  throw new Error(
135
- `[ts-procedures-codegen] Failed to emit route "${route.name}" (kind: ${kind}, scope: ${group.scopeKey}): ${msg}`
135
+ `[ts-procedures-codegen] Failed to emit route "${route.name}" (kind: ${kind}, scope: ${group.scopeKey}): ${msg}`,
136
+ { cause: err }
136
137
  )
137
138
  }
138
139
 
@@ -91,7 +91,7 @@ describe('generated _errors.ts — runtime behavior', () => {
91
91
  const err = e as { stdout?: Buffer; stderr?: Buffer }
92
92
  const stdout = err.stdout?.toString() ?? ''
93
93
  const stderr = err.stderr?.toString() ?? ''
94
- throw new Error(`tsc failed in ${outDir}:\nSTDOUT:\n${stdout}\nSTDERR:\n${stderr}`)
94
+ throw new Error(`tsc failed in ${outDir}:\nSTDOUT:\n${stdout}\nSTDERR:\n${stderr}`, { cause: e })
95
95
  }
96
96
 
97
97
  // Dynamic import of the compiled output.
@@ -164,7 +164,7 @@ describe('generated _errors.ts — runtime behavior', () => {
164
164
  const err = e as { stdout?: Buffer; stderr?: Buffer }
165
165
  const stdout = err.stdout?.toString() ?? ''
166
166
  const stderr = err.stderr?.toString() ?? ''
167
- throw new Error(`tsc failed in ${outDir}:\nSTDOUT:\n${stdout}\nSTDERR:\n${stderr}`)
167
+ throw new Error(`tsc failed in ${outDir}:\nSTDOUT:\n${stdout}\nSTDERR:\n${stderr}`, { cause: e })
168
168
  }
169
169
 
170
170
  const errorsUrl = `file://${join(outDir, 'out', '_errors.js')}`
@@ -21,7 +21,7 @@ export async function resolveEnvelope(input: ResolveInput): Promise<DocEnvelope>
21
21
  response = await fetch(input.url)
22
22
  } catch (err) {
23
23
  const msg = err instanceof Error ? err.message : String(err)
24
- throw new Error(`[ts-procedures-codegen] Failed to connect to ${input.url}: ${msg}`)
24
+ throw new Error(`[ts-procedures-codegen] Failed to connect to ${input.url}: ${msg}`, { cause: err })
25
25
  }
26
26
  if (!response.ok) {
27
27
  throw new Error(`[ts-procedures-codegen] ${input.url} returned HTTP ${response.status} ${response.statusText}`)
@@ -51,6 +51,7 @@ export function runTsc(args: {
51
51
  const combined = [stdout, stderr].filter(Boolean).join('\n').trim()
52
52
  throw new Error(
53
53
  `[runTsc] tsc failed for ${tsconfigPath}:\n${combined || (e.message ?? '(no output)')}`,
54
+ { cause: err },
54
55
  )
55
56
  }
56
57
  }
package/src/exports.ts CHANGED
@@ -56,5 +56,9 @@ export type { Infer, TSchemaLib, TJSONSchema, Prettify } from './schema/json-sch
56
56
 
57
57
  // Doc envelope — offline codegen input
58
58
  export { writeDocEnvelope } from './server/doc-envelope.js'
59
+ // `generatorVersion` metadata lives on `ts-procedures/server`
60
+ // (DOC_ENVELOPE_GENERATOR_VERSION) — it's niche telemetry. The spec version is
61
+ // the one consumers branch on, so it gets the prominent top-level export.
62
+ export { DOC_ENVELOPE_SPEC_VERSION } from './server/spec-version.js'
59
63
  export type { DocEnvelopeSource } from './server/doc-envelope.js'
60
64
  export type { DocEnvelope } from './server/types.js'
@@ -5,7 +5,9 @@ import type {
5
5
  THttpStreamProcedureRegistration,
6
6
  TProcedureRegistration,
7
7
  } from '../core/types.js'
8
+ import pkg from '../../package.json' with { type: 'json' }
8
9
  import { DocRegistry } from './doc-registry.js'
10
+ import { DOC_ENVELOPE_SPEC_VERSION, DOC_ENVELOPE_GENERATOR_VERSION } from './spec-version.js'
9
11
  import { defineErrorTaxonomy } from './errors/taxonomy.js'
10
12
  import { buildRpcRouteDoc } from './docs/rpc-doc.js'
11
13
  import { buildHttpStreamRouteDoc } from './docs/http-stream-doc.js'
@@ -201,6 +203,38 @@ describe('DocRegistry', () => {
201
203
  })
202
204
  })
203
205
 
206
+ // --------------------------------------------------------------------------
207
+ // toJSON() spec metadata
208
+ // --------------------------------------------------------------------------
209
+ describe('toJSON() spec metadata', () => {
210
+ test('emits specVersion (the constant, a number) and generatorVersion (the package version)', () => {
211
+ const out = new DocRegistry().toJSON()
212
+ expect(out.specVersion).toBe(DOC_ENVELOPE_SPEC_VERSION)
213
+ expect(typeof out.specVersion).toBe('number')
214
+ expect(out.generatorVersion).toBe(pkg.version)
215
+ // the exported constant must track the real package version
216
+ expect(DOC_ENVELOPE_GENERATOR_VERSION).toBe(pkg.version)
217
+ })
218
+
219
+ test('metadata is present even on an otherwise-empty envelope', () => {
220
+ const out = new DocRegistry({ includeDefaults: false }).toJSON()
221
+ expect(out).toMatchObject({
222
+ specVersion: DOC_ENVELOPE_SPEC_VERSION,
223
+ generatorVersion: pkg.version,
224
+ })
225
+ })
226
+
227
+ test('transform receives the metadata on its envelope argument', () => {
228
+ const seen = new DocRegistry().toJSON({
229
+ transform: ({ specVersion, generatorVersion }) => ({ specVersion, generatorVersion }),
230
+ })
231
+ expect(seen).toEqual({
232
+ specVersion: DOC_ENVELOPE_SPEC_VERSION,
233
+ generatorVersion: pkg.version,
234
+ })
235
+ })
236
+ })
237
+
204
238
  // --------------------------------------------------------------------------
205
239
  // toJSON() filter
206
240
  // --------------------------------------------------------------------------
@@ -13,6 +13,7 @@ import {
13
13
  taxonomyToErrorDocs,
14
14
  type ErrorTaxonomy,
15
15
  } from './errors/taxonomy.js'
16
+ import { DOC_ENVELOPE_SPEC_VERSION, DOC_ENVELOPE_GENERATOR_VERSION } from './spec-version.js'
16
17
 
17
18
  export type {
18
19
  AnyHttpRouteDoc,
@@ -112,6 +113,8 @@ export class DocRegistry {
112
113
  }
113
114
 
114
115
  const envelope: DocEnvelope = {
116
+ specVersion: DOC_ENVELOPE_SPEC_VERSION,
117
+ generatorVersion: DOC_ENVELOPE_GENERATOR_VERSION,
115
118
  basePath: this.basePath,
116
119
  headers: [...this.headers],
117
120
  errors: [...this.errors],
@@ -25,5 +25,6 @@ export { buildStreamRouteDoc } from './docs/stream-doc.js'
25
25
  export { buildHttpRouteDoc } from './docs/http-doc.js'
26
26
  export { buildHttpStreamRouteDoc } from './docs/http-stream-doc.js'
27
27
  export { DocRegistry } from './doc-registry.js'
28
+ export { DOC_ENVELOPE_SPEC_VERSION, DOC_ENVELOPE_GENERATOR_VERSION } from './spec-version.js'
28
29
  export { writeDocEnvelope } from './doc-envelope.js'
29
30
  export type { DocEnvelopeSource } from './doc-envelope.js'
@@ -0,0 +1,27 @@
1
+ import { PACKAGE_VERSION } from '../version.js'
2
+
3
+ /**
4
+ * Spec version of the {@link DocEnvelope} wire format.
5
+ *
6
+ * Bump this ONLY when the envelope shape changes in a way downstream parsers
7
+ * must react to — field renames, nesting changes, or semantic changes. Do NOT
8
+ * bump it on ordinary package releases (dependency upgrades, bug fixes, new
9
+ * optional fields that older parsers can safely ignore). It is decoupled from
10
+ * the npm package version on purpose, so consumers get a small monotonic
11
+ * integer to branch on instead of having to interpret semver.
12
+ *
13
+ * Consumer contract: an envelope with no `specVersion` field predates this
14
+ * field and MUST be treated as spec version 1.
15
+ */
16
+ export const DOC_ENVELOPE_SPEC_VERSION = 1
17
+
18
+ /**
19
+ * The ts-procedures package version that produced an envelope (e.g. `"10.0.0"`).
20
+ * Populates the envelope's `generatorVersion` field.
21
+ *
22
+ * Informational only — for telemetry, debugging, and "which release served
23
+ * this?" questions. Do NOT use it to decide parse compatibility; it churns on
24
+ * every release regardless of whether the envelope format changed. Use
25
+ * {@link DOC_ENVELOPE_SPEC_VERSION} for compatibility decisions.
26
+ */
27
+ export const DOC_ENVELOPE_GENERATOR_VERSION: string = PACKAGE_VERSION
@@ -250,6 +250,21 @@ export interface DocRegistryOutputOptions<TEnvelope = DocEnvelope> {
250
250
  }
251
251
 
252
252
  export interface DocEnvelope {
253
+ /**
254
+ * Wire-format version of this envelope. Every envelope produced by
255
+ * `DocRegistry.toJSON()` / `builder.toDocEnvelope()` carries it. Downstream
256
+ * consumers branch on it to pick a parser; bumped only on envelope format
257
+ * changes, NOT on package releases. Optional on the type so hand-built
258
+ * envelopes and pre-existing documents remain valid — an absent value MUST be
259
+ * treated as spec version 1. See {@link DOC_ENVELOPE_SPEC_VERSION}.
260
+ */
261
+ specVersion?: number
262
+ /**
263
+ * ts-procedures package version that produced this envelope (e.g. `"10.0.0"`).
264
+ * Informational only — do not use for parse-compatibility decisions (use
265
+ * {@link specVersion} for that). See {@link DOC_ENVELOPE_GENERATOR_VERSION}.
266
+ */
267
+ generatorVersion?: string
253
268
  basePath: string
254
269
  headers: HeaderDoc[]
255
270
  errors: ErrorDoc[]
package/src/version.ts ADDED
@@ -0,0 +1,11 @@
1
+ import pkg from '../package.json' with { type: 'json' }
2
+
3
+ /**
4
+ * The ts-procedures package version (e.g. `"10.0.0"`), read from `package.json`.
5
+ *
6
+ * Single source of truth for "which version is this build?" — consumed by the
7
+ * codegen file header and the doc-envelope `generatorVersion`. Import this
8
+ * rather than re-importing `package.json`, so there's one place the version
9
+ * enters the source tree.
10
+ */
11
+ export const PACKAGE_VERSION: string = pkg.version
package/build/errors.d.ts DELETED
@@ -1,33 +0,0 @@
1
- import { TSchemaValidationError } from './schema/parser.js';
2
- import { DefinitionInfo, DefinitionLocation } from './stack-utils.js';
3
- export declare class ProcedureError extends Error {
4
- readonly procedureName: string;
5
- readonly message: string;
6
- readonly meta?: object | undefined;
7
- cause?: unknown;
8
- readonly definedAt?: DefinitionLocation;
9
- readonly definitionStack?: string;
10
- constructor(procedureName: string, message: string, meta?: object | undefined, definitionInfo?: DefinitionInfo);
11
- /**
12
- * Returns a formatted string showing where the procedure was defined.
13
- */
14
- getDefinitionLocation(): string | undefined;
15
- /**
16
- * Enhances the error stack with definition location information.
17
- */
18
- private enhanceStack;
19
- }
20
- export declare class ProcedureValidationError extends ProcedureError {
21
- readonly procedureName: string;
22
- readonly errors?: TSchemaValidationError[] | undefined;
23
- constructor(procedureName: string, message: string, errors?: TSchemaValidationError[] | undefined, definitionInfo?: DefinitionInfo);
24
- }
25
- export declare class ProcedureRegistrationError extends ProcedureError {
26
- readonly procedureName: string;
27
- constructor(procedureName: string, message: string, definitionInfo?: DefinitionInfo);
28
- }
29
- export declare class ProcedureYieldValidationError extends ProcedureError {
30
- readonly procedureName: string;
31
- readonly errors?: TSchemaValidationError[] | undefined;
32
- constructor(procedureName: string, message: string, errors?: TSchemaValidationError[] | undefined, definitionInfo?: DefinitionInfo);
33
- }