@workerstack/clients 1.0.0-rc.26 → 1.0.0-rc.28

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 (277) hide show
  1. package/README.md +43 -43
  2. package/bin/{honey-clients.js → clients.js} +12 -12
  3. package/dist/cli.d.ts +3 -3
  4. package/dist/cli.js +14 -14
  5. package/dist/emit/cli/discovery.js +1 -1
  6. package/dist/emit/cli/install.js +2 -2
  7. package/dist/emit/cli/layout.js +1 -1
  8. package/dist/emit/cli/module.js +1 -1
  9. package/dist/emit/cli/release.js +1 -1
  10. package/dist/emit/csharp/errors.js +1 -1
  11. package/dist/emit/csharp/sdk-client.js +1 -1
  12. package/dist/emit/csharp/sdk-csproj.d.ts +1 -1
  13. package/dist/emit/csharp/sdk-csproj.js +2 -2
  14. package/dist/emit/csharp/sdk.d.ts +1 -1
  15. package/dist/emit/csharp/sdk.js +2 -2
  16. package/dist/emit/csharp/transport.js +2 -2
  17. package/dist/emit/csharp/types-record.d.ts +1 -1
  18. package/dist/emit/go/sdk-client.js +1 -1
  19. package/dist/emit/go/sdk.js +1 -1
  20. package/dist/emit/java/sdk-errors.js +5 -5
  21. package/dist/emit/java/sdk-op.d.ts +1 -1
  22. package/dist/emit/java/sdk.js +3 -3
  23. package/dist/emit/mcp/files.d.ts +1 -1
  24. package/dist/emit/mcp/mounted.js +2 -2
  25. package/dist/emit/mcp/runtime.js +1 -1
  26. package/dist/emit/mcp/server.js +1 -1
  27. package/dist/emit/python/errors.js +1 -1
  28. package/dist/emit/python/sdk-client.js +2 -2
  29. package/dist/emit/python/sdk-pyproject.js +4 -4
  30. package/dist/emit/python/sdk.d.ts +1 -1
  31. package/dist/emit/python/sdk.js +11 -11
  32. package/dist/emit/python/transport.js +1 -1
  33. package/dist/emit/rust/errors.js +2 -2
  34. package/dist/emit/rust/sdk-cargo.js +3 -3
  35. package/dist/emit/rust/sdk.d.ts +1 -1
  36. package/dist/emit/rust/sdk.js +2 -2
  37. package/dist/emit/shared/format.d.ts +1 -1
  38. package/dist/emit/shared/metadata.d.ts +1 -1
  39. package/dist/emit/shared/status-keys.d.ts +1 -1
  40. package/dist/emit/shared/status-keys.js +1 -1
  41. package/dist/emit/ts/app-client.js +2 -2
  42. package/dist/emit/ts/route-tree.d.ts +1 -1
  43. package/dist/emit/ts/route-tree.js +1 -12
  44. package/dist/emit/ts/sdk-types-preamble.js +16 -16
  45. package/dist/emit/ts/sdk-types.js +6 -6
  46. package/dist/emit/ts/tanstack-query.js +5 -5
  47. package/dist/emit/ts/type-gen.d.ts +4 -3
  48. package/dist/emit/ts/type-gen.js +86 -45
  49. package/dist/extract/chain.d.ts +10 -6
  50. package/dist/extract/chain.js +5 -19
  51. package/dist/extract/extract.d.ts +2 -2
  52. package/dist/extract/extract.js +40 -26
  53. package/dist/extract/serialize.js +1 -1
  54. package/dist/extract/walk.d.ts +15 -4
  55. package/dist/extract/walk.js +159 -15
  56. package/dist/gen/args.js +3 -3
  57. package/dist/gen/formatters.d.ts +6 -6
  58. package/dist/gen/formatters.js +7 -7
  59. package/dist/gen/process.d.ts +3 -3
  60. package/dist/gen/process.js +7 -7
  61. package/dist/gen/targets.d.ts +3 -3
  62. package/dist/gen/targets.js +3 -3
  63. package/dist/gen/write.d.ts +1 -1
  64. package/dist/gen/write.js +1 -1
  65. package/dist/index.d.ts +1 -1
  66. package/dist/index.js +1 -1
  67. package/dist/ir/load.js +10 -10
  68. package/dist/ir/model.d.ts +6 -4
  69. package/dist/ir/sdk-model.d.ts +1 -1
  70. package/dist/ir/sdk-model.js +1 -1
  71. package/dist/ir/slots.d.ts +3 -3
  72. package/dist/ir/slots.js +12 -10
  73. package/dist/release/bootstrap.js +1 -1
  74. package/dist/release/bump-command.js +1 -1
  75. package/dist/release/cli.d.ts +4 -4
  76. package/dist/release/cli.js +6 -6
  77. package/dist/release/context.d.ts +1 -1
  78. package/dist/release/context.js +1 -1
  79. package/dist/release/digest.d.ts +1 -1
  80. package/dist/release/digest.js +2 -2
  81. package/dist/release/index.d.ts +1 -1
  82. package/dist/release/load.js +1 -1
  83. package/dist/release/manifest.js +1 -1
  84. package/dist/release/registries.js +3 -3
  85. package/dist/release/release-workflow.js +1 -1
  86. package/dist/release/spec-gate.d.ts +2 -2
  87. package/dist/release/spec-gate.js +2 -2
  88. package/dist/release/sync-command.d.ts +1 -1
  89. package/dist/release/sync-command.js +1 -1
  90. package/dist/release/sync-tree.js +1 -1
  91. package/dist/release/types.d.ts +6 -6
  92. package/dist/runtime/cli/body.go +1 -1
  93. package/dist/runtime/cli/config.go +3 -3
  94. package/dist/runtime/cli/discovery.go +1 -1
  95. package/dist/runtime/cli/format.go +1 -1
  96. package/dist/runtime/cli/log.go +1 -1
  97. package/dist/runtime/cli/output.go +1 -1
  98. package/dist/runtime/cli/params.go +1 -1
  99. package/dist/runtime/cli/run.go +1 -1
  100. package/dist/runtime/cli/socket.go +1 -1
  101. package/dist/runtime/cli/stream.go +1 -1
  102. package/dist/runtime/cli/target.go +1 -1
  103. package/dist/runtime/csharp/Adapters.cs +2 -2
  104. package/dist/runtime/csharp/Auth.cs +2 -2
  105. package/dist/runtime/csharp/Body.cs +3 -3
  106. package/dist/runtime/csharp/Config.cs +2 -2
  107. package/dist/runtime/csharp/Envelope.cs +3 -3
  108. package/dist/runtime/csharp/Errors.cs +10 -10
  109. package/dist/runtime/csharp/Events.cs +2 -2
  110. package/dist/runtime/csharp/Exchange.cs +4 -4
  111. package/dist/runtime/csharp/Handler.cs +3 -3
  112. package/dist/runtime/csharp/Hooks.cs +3 -3
  113. package/dist/runtime/csharp/Invalidation.cs +2 -2
  114. package/dist/runtime/csharp/Json.cs +2 -2
  115. package/dist/runtime/csharp/Log.cs +2 -2
  116. package/dist/runtime/csharp/Operation.cs +2 -2
  117. package/dist/runtime/csharp/Path.cs +2 -2
  118. package/dist/runtime/csharp/Query.cs +2 -2
  119. package/dist/runtime/csharp/Realtime.cs +2 -2
  120. package/dist/runtime/csharp/RealtimeLoop.cs +3 -3
  121. package/dist/runtime/csharp/Redirect.cs +2 -2
  122. package/dist/runtime/csharp/Result.cs +2 -2
  123. package/dist/runtime/csharp/Sse.cs +2 -2
  124. package/dist/runtime/csharp/Stale.cs +2 -2
  125. package/dist/runtime/csharp/Transport.cs +2 -2
  126. package/dist/runtime/csharp/TransportLongPoll.cs +2 -2
  127. package/dist/runtime/csharp/TransportSse.cs +2 -2
  128. package/dist/runtime/csharp/TransportWs.cs +2 -2
  129. package/dist/runtime/csharp/Wire.cs +2 -2
  130. package/dist/runtime/csharp/Ws.cs +2 -2
  131. package/dist/runtime/csharp/WsDial.cs +2 -2
  132. package/dist/runtime/go/auth.go +1 -1
  133. package/dist/runtime/go/body.go +2 -2
  134. package/dist/runtime/go/config.go +1 -1
  135. package/dist/runtime/go/errors.go +5 -5
  136. package/dist/runtime/go/export.go +10 -10
  137. package/dist/runtime/go/hooks.go +2 -2
  138. package/dist/runtime/go/invalidation.go +2 -2
  139. package/dist/runtime/go/log.go +1 -1
  140. package/dist/runtime/go/nullable.go +1 -1
  141. package/dist/runtime/go/options.go +1 -1
  142. package/dist/runtime/go/path.go +1 -1
  143. package/dist/runtime/go/query.go +2 -2
  144. package/dist/runtime/go/realtime.go +4 -4
  145. package/dist/runtime/go/realtime_loop.go +1 -1
  146. package/dist/runtime/go/redirect.go +2 -2
  147. package/dist/runtime/go/request.go +9 -9
  148. package/dist/runtime/go/result.go +2 -2
  149. package/dist/runtime/go/sse.go +3 -3
  150. package/dist/runtime/go/stale.go +1 -1
  151. package/dist/runtime/go/stream.go +2 -2
  152. package/dist/runtime/go/transport.go +2 -2
  153. package/dist/runtime/go/transport_longpoll.go +1 -1
  154. package/dist/runtime/go/transport_sse.go +2 -2
  155. package/dist/runtime/go/ws.go +1 -1
  156. package/dist/runtime/java/Answer.java +2 -2
  157. package/dist/runtime/java/ApiException.java +2 -2
  158. package/dist/runtime/java/BinaryBody.java +2 -2
  159. package/dist/runtime/java/Body.java +4 -4
  160. package/dist/runtime/java/Call.java +2 -2
  161. package/dist/runtime/java/CallLog.java +2 -2
  162. package/dist/runtime/java/ClientConfig.java +2 -2
  163. package/dist/runtime/java/ConnectionState.java +2 -2
  164. package/dist/runtime/java/Credential.java +2 -2
  165. package/dist/runtime/java/Deadline.java +2 -2
  166. package/dist/runtime/java/Decode.java +2 -2
  167. package/dist/runtime/java/Envelope.java +2 -2
  168. package/dist/runtime/java/ErrorEnvelope.java +3 -3
  169. package/dist/runtime/java/EventStream.java +2 -2
  170. package/dist/runtime/java/Exchange.java +2 -2
  171. package/dist/runtime/java/FilePart.java +2 -2
  172. package/dist/runtime/java/Flight.java +3 -3
  173. package/dist/runtime/java/Hooks.java +3 -3
  174. package/dist/runtime/java/Hops.java +2 -2
  175. package/dist/runtime/java/{HoneyException.java → HttpException.java} +4 -4
  176. package/dist/runtime/java/InvalidationConfig.java +2 -2
  177. package/dist/runtime/java/Json.java +3 -3
  178. package/dist/runtime/java/Keepalive.java +2 -2
  179. package/dist/runtime/java/LogEntry.java +2 -2
  180. package/dist/runtime/java/LongPollAdapter.java +2 -2
  181. package/dist/runtime/java/Operation.java +2 -2
  182. package/dist/runtime/java/Opt.java +2 -2
  183. package/dist/runtime/java/Pump.java +2 -2
  184. package/dist/runtime/java/RawResponse.java +2 -2
  185. package/dist/runtime/java/Realtime.java +2 -2
  186. package/dist/runtime/java/RealtimeLoop.java +4 -4
  187. package/dist/runtime/java/RedirectPolicy.java +2 -2
  188. package/dist/runtime/java/Redirects.java +2 -2
  189. package/dist/runtime/java/RequestContext.java +2 -2
  190. package/dist/runtime/java/RequestHook.java +2 -2
  191. package/dist/runtime/java/RequestOptions.java +2 -2
  192. package/dist/runtime/java/ResponseContext.java +2 -2
  193. package/dist/runtime/java/ResponseHook.java +2 -2
  194. package/dist/runtime/java/Result.java +2 -2
  195. package/dist/runtime/java/ResumableConnection.java +2 -2
  196. package/dist/runtime/java/SdkException.java +3 -3
  197. package/dist/runtime/java/Socket.java +2 -2
  198. package/dist/runtime/java/Sse.java +2 -2
  199. package/dist/runtime/java/SseAdapter.java +2 -2
  200. package/dist/runtime/java/SseEvent.java +2 -2
  201. package/dist/runtime/java/StaleMeta.java +2 -2
  202. package/dist/runtime/java/StaleTracker.java +2 -2
  203. package/dist/runtime/java/Transport.java +2 -2
  204. package/dist/runtime/java/TransportAdapter.java +2 -2
  205. package/dist/runtime/java/TransportConnection.java +2 -2
  206. package/dist/runtime/java/TransportKind.java +2 -2
  207. package/dist/runtime/java/TransportMessage.java +2 -2
  208. package/dist/runtime/java/TransportOptions.java +2 -2
  209. package/dist/runtime/java/TypedWebSocket.java +2 -2
  210. package/dist/runtime/java/UrlPath.java +2 -2
  211. package/dist/runtime/java/UrlQuery.java +2 -2
  212. package/dist/runtime/java/WsAdapter.java +2 -2
  213. package/dist/runtime/java/WsClose.java +2 -2
  214. package/dist/runtime/java/WsDial.java +2 -2
  215. package/dist/runtime/java/WsMessage.java +2 -2
  216. package/dist/runtime/mcp/call.ts +3 -3
  217. package/dist/runtime/mcp/result.ts +2 -2
  218. package/dist/runtime/python/__init__.py +1 -1
  219. package/dist/runtime/python/auth.py +1 -1
  220. package/dist/runtime/python/body.py +1 -1
  221. package/dist/runtime/python/config.py +1 -1
  222. package/dist/runtime/python/errors.py +11 -11
  223. package/dist/runtime/python/events.py +4 -4
  224. package/dist/runtime/python/exchange.py +1 -1
  225. package/dist/runtime/python/hooks.py +4 -4
  226. package/dist/runtime/python/invalidation.py +1 -1
  227. package/dist/runtime/python/log.py +1 -1
  228. package/dist/runtime/python/operation.py +1 -1
  229. package/dist/runtime/python/path.py +1 -1
  230. package/dist/runtime/python/query.py +1 -1
  231. package/dist/runtime/python/realtime.py +5 -5
  232. package/dist/runtime/python/redirect.py +1 -1
  233. package/dist/runtime/python/result.py +1 -1
  234. package/dist/runtime/python/send_async.py +4 -4
  235. package/dist/runtime/python/send_sync.py +3 -3
  236. package/dist/runtime/python/sse.py +1 -1
  237. package/dist/runtime/python/stale.py +1 -1
  238. package/dist/runtime/python/transport.py +1 -1
  239. package/dist/runtime/python/transport_longpoll.py +1 -1
  240. package/dist/runtime/python/transport_sse.py +1 -1
  241. package/dist/runtime/python/transport_ws.py +1 -1
  242. package/dist/runtime/python/ws.py +3 -3
  243. package/dist/runtime/rust/Cargo.lock +1 -1
  244. package/dist/runtime/rust/answer.rs +1 -1
  245. package/dist/runtime/rust/auth.rs +1 -1
  246. package/dist/runtime/rust/body.rs +2 -2
  247. package/dist/runtime/rust/call.rs +1 -1
  248. package/dist/runtime/rust/config.rs +1 -1
  249. package/dist/runtime/rust/envelope.rs +3 -3
  250. package/dist/runtime/rust/errors.rs +3 -3
  251. package/dist/runtime/rust/events.rs +1 -1
  252. package/dist/runtime/rust/exchange.rs +1 -1
  253. package/dist/runtime/rust/hooks.rs +1 -1
  254. package/dist/runtime/rust/invalidation.rs +1 -1
  255. package/dist/runtime/rust/log.rs +1 -1
  256. package/dist/runtime/rust/nullable.rs +1 -1
  257. package/dist/runtime/rust/path.rs +1 -1
  258. package/dist/runtime/rust/query.rs +1 -1
  259. package/dist/runtime/rust/realtime.rs +1 -1
  260. package/dist/runtime/rust/realtime_loop.rs +1 -1
  261. package/dist/runtime/rust/redirect.rs +1 -1
  262. package/dist/runtime/rust/request.rs +1 -1
  263. package/dist/runtime/rust/result.rs +1 -1
  264. package/dist/runtime/rust/sse.rs +1 -1
  265. package/dist/runtime/rust/stale.rs +1 -1
  266. package/dist/runtime/rust/transport.rs +1 -1
  267. package/dist/runtime/rust/transport_longpoll.rs +1 -1
  268. package/dist/runtime/rust/transport_sse.rs +1 -1
  269. package/dist/runtime/rust/transport_ws.rs +1 -1
  270. package/dist/runtime/rust/ws.rs +1 -1
  271. package/dist/runtime/ts/app-types.ts +5 -5
  272. package/dist/runtime/ts/app.ts +5 -5
  273. package/dist/runtime/ts/http.ts +3 -3
  274. package/dist/runtime/ts/path.ts +1 -1
  275. package/dist/runtime/ts/request.ts +1 -1
  276. package/dist/runtime/ts/sdk.ts +1 -1
  277. package/package.json +2 -29
@@ -4,7 +4,7 @@
4
4
  * file beside the SDK, plus the types that make its surfaces exact for this document.
5
5
  *
6
6
  * The vendoring mirrors `http.ts`'s `runtimeSource`, with one difference it cannot share: those modules
7
- * import only each other, so dropping every sibling import is enough. These import honey's runtime too
7
+ * import only each other, so dropping every sibling import is enough. These import clients' runtime too
8
8
  * (`../ts/sdk.ts`), and the emitted file needs those names from `./<stem>.runtime.gen`, so the specifier is
9
9
  * rewritten rather than dropped.
10
10
  */
@@ -16,7 +16,7 @@ import { memberTree } from "./service-map.js";
16
16
  const QUERY_MODULES = ["invalidate", "query"];
17
17
  /* an import of a module beside this one: now the same file, so the names are already in scope */
18
18
  const SIBLING_IMPORT = /^import\s+(?:type\s+)?\{[^}]*\}\s+from\s+"\.\/[\w-]+\.ts"\n/gm;
19
- /* an import of honey's own runtime, which the emitted file reads from `<stem>.runtime.gen` */
19
+ /* an import of clients' own runtime, which the emitted file reads from `<stem>.runtime.gen` */
20
20
  const RUNTIME_IMPORT = /^import\s+(type\s+)?\{([^}]*)\}\s+from\s+"\.\.\/ts\/[\w-]+\.ts"\n/gm;
21
21
  /* query-core, which stays exactly as written: type-only, so nothing has to resolve at run time */
22
22
  const QUERY_CORE_IMPORT = /^import\s+type\s+\{([^}]*)\}\s+from\s+"@tanstack\/query-core"\n/gm;
@@ -36,7 +36,7 @@ function namesOf(clauses) {
36
36
  */
37
37
  export function tanstackQuerySource(runtime) {
38
38
  const core = [];
39
- const honey = [];
39
+ const runtimeNames = [];
40
40
  const bodies = QUERY_MODULES.map((name) => {
41
41
  const text = readFileSync(new URL(`../../runtime/ts-tanstack-query/${name}.ts`, import.meta.url), "utf8");
42
42
  return text
@@ -45,7 +45,7 @@ export function tanstackQuerySource(runtime) {
45
45
  return "";
46
46
  })
47
47
  .replace(RUNTIME_IMPORT, (_, __, named) => {
48
- honey.push(named);
48
+ runtimeNames.push(named);
49
49
  return "";
50
50
  })
51
51
  .replace(SIBLING_IMPORT, "")
@@ -53,7 +53,7 @@ export function tanstackQuerySource(runtime) {
53
53
  });
54
54
  const imports = [
55
55
  `import type { ${namesOf(core).join(", ")} } from "@tanstack/query-core"`,
56
- `import type { ${namesOf(honey).join(", ")} } from "./${runtime}.js"`,
56
+ `import type { ${namesOf(runtimeNames).join(", ")} } from "./${runtime}.js"`,
57
57
  ];
58
58
  return `${imports.join("\n")}\n\n${bodies.join("\n\n")}\n`;
59
59
  }
@@ -1,8 +1,9 @@
1
1
  /**
2
2
  * `generateTypes` (F3): an app's `_gen/types.gen.d.ts` — the `Routes` map, each route's ctx,
3
- * input, output, errors and meta, the route selectors with the `HoneyCodegen` augmentation, and
4
- * `BaseCtx`. Read from the app's OpenAPI document (the IR), its route tree (meta, O1) and the
5
- * extracted ctx types (middleware, env, taps, parsed inputs, O3), joined on `x-honey-route`.
3
+ * input, output, errors and meta, the `HttpCodegen` `operationId` slot mapping each declared id
4
+ * to its context, and `BaseCtx`. Read from the app's OpenAPI document (the IR), its route tree
5
+ * (meta, O1) and the extracted ctx types (middleware, env, parsed inputs, O3), joined on
6
+ * `x-backend-route`.
6
7
  */
7
8
  import type { ExtractedTypes } from "../../extract/extract.ts";
8
9
  import type { RouteTree } from "./route-tree.ts";
@@ -8,22 +8,10 @@ import { statusKeyOf } from "../shared/status-keys.js";
8
8
  import { irToTs } from "../shared/type-emitter.js";
9
9
  import { componentNames } from "./sdk-types.js";
10
10
  /* the names the file declares, which a component schema never takes */
11
- const RESERVED = [
12
- "HoneyContext",
13
- "HoneyError",
14
- "HoneyMeta",
15
- "Omit",
16
- "Partial",
17
- "Readonly",
18
- "Record",
19
- "Routes",
20
- "RouteSelector",
21
- "TapMap",
22
- ];
11
+ const RESERVED = ["HttpContext", "HttpError", "HttpMeta", "Omit", "Partial", "Readonly", "Record", "Routes"];
23
12
  /* the v1 error-factory signature of a key without a schema (core errors.ts ErrorFactoryOpts) */
24
- const STANDARD_FACTORY = "(opts?: { cause?: unknown; fields?: Record<string, { error_key: string; message: string; path: string }[]>; headers?: Record<string, string>; vars?: Record<string, number | string> }) => HoneyError";
13
+ const STANDARD_FACTORY = "(opts?: { cause?: unknown; fields?: Record<string, { error_key: string; message: string; path: string }[]>; headers?: Record<string, string>; vars?: Record<string, number | string> }) => HttpError";
25
14
  const EXTRACTORS = [
26
- ["RouteCtx", "ctx"],
27
15
  ["RouteInput", "input"],
28
16
  ["RouteOutput", "output"],
29
17
  ["RouteErrors", "errors"],
@@ -34,7 +22,7 @@ const EXTRACTORS = [
34
22
  /** `{ k: T; … }`, or `{}` when there is nothing in it. */
35
23
  const objectText = (fields) => fields.length === 0 ? "{}" : `{ ${fields.map(([key, type]) => `${key}: ${type}`).join("; ")} }`;
36
24
  const propsText = (props) => objectText(props.map((p) => [`${quoteKey(p.name)}${p.optional ? "?" : ""}`, p.type]));
37
- /** The documented routes by route id; an operation without `x-honey-route` is reported and left out. */
25
+ /** The documented routes by route id; an operation without `x-backend-route` is reported and left out. */
38
26
  function routesOf(ir, report) {
39
27
  const routes = new Map();
40
28
  const missing = [];
@@ -43,7 +31,7 @@ function routesOf(ir, report) {
43
31
  if (op.extensions.websocket === true)
44
32
  continue;
45
33
  if (id === undefined)
46
- missing.push(`${op.method} ${op.path}: no x-honey-route; left out of Routes`);
34
+ missing.push(`${op.method} ${op.path}: no x-backend-route; left out of Routes`);
47
35
  /* `all()` and an optional param document one route as several operations: the first speaks for it */
48
36
  if (id !== undefined && !routes.has(id))
49
37
  routes.set(id, op);
@@ -131,7 +119,7 @@ function errorsOf(op, ctx) {
131
119
  .map(([code, shapes]) => [String(code), [...shapes].join(" | ")]);
132
120
  const factory = (key) => shape(key) === "null"
133
121
  ? STANDARD_FACTORY
134
- : `(data: ${shape(key)}, opts?: { cause?: unknown; headers?: Record<string, string> }) => HoneyError`;
122
+ : `(data: ${shape(key)}, opts?: { cause?: unknown; headers?: Record<string, string> }) => HttpError`;
135
123
  return {
136
124
  factories: keys.map((key) => [quoteKey(key), factory(key)]),
137
125
  fields: [
@@ -148,15 +136,29 @@ function errorsOf(op, ctx) {
148
136
  * Without an extracted declaration (no ts-morph, or an app that declares no meta) the literals are all there is.
149
137
  */
150
138
  function ctxMeta(extracted, literal) {
151
- const declared = extracted?.meta ?? null;
139
+ /* with nothing extracted, the tree's literals are all there is */
140
+ if (extracted === null || extracted === undefined)
141
+ return literal;
152
142
  /* the OpenAPI keys the declared meta does not redefine: a consumer that types `security` its own way holds
153
- that type in the handler, and intersecting honey's would conflict with it */
154
- return declared === null ? literal : `Partial<Omit<HoneyMeta, keyof ${declared}>> & ${declared}`;
143
+ that type in the handler, and intersecting backend's would conflict with it. An app that declares none
144
+ holds them all, each widened by \`.meta()\` */
145
+ const declared = extracted.meta;
146
+ return declared === null ? "Partial<HttpMeta>" : `Partial<Omit<HttpMeta, keyof ${declared}>> & ${declared}`;
155
147
  }
156
148
  /** `ctx.params`: the type a param schema gives it as extracted, else each of the pattern's params a string. */
157
149
  function ctxParams(extracted, id, pattern) {
158
150
  return extracted?.params[id] ?? objectText(paramsOf(pattern));
159
151
  }
152
+ /**
153
+ * The ctx's `meta` and `routePattern`. A mounted route's handler types the path it was registered at, never the one
154
+ * it is served at, so its ctx keeps the base's `string` and that handler's own ctx still fits.
155
+ */
156
+ function routeFields(extracted, id, literal) {
157
+ const fields = [["readonly meta", `Readonly<${ctxMeta(extracted, literal)}>`]];
158
+ if (!extracted?.mounted.includes(id))
159
+ fields.push(["readonly routePattern", tsString(id.slice(id.indexOf(" ") + 1))]);
160
+ return fields;
161
+ }
160
162
  /** One `Routes[pattern][method]` entry. */
161
163
  function routeEntry(id, op, options, ctx) {
162
164
  const pattern = id.slice(id.indexOf(" ") + 1);
@@ -168,7 +170,6 @@ function routeEntry(id, op, options, ctx) {
168
170
  const mt = options.tree.routes[id]?.mt;
169
171
  /* the values the tree carries, as literals: what a consumer reads a route's configuration from */
170
172
  const literal = mt && Object.keys(mt).length > 0 ? literalType(mt) : "{}";
171
- const meta = ctxMeta(extracted, literal);
172
173
  const output = outputOf(op, ctx);
173
174
  const own = [];
174
175
  if (input !== "{}")
@@ -177,7 +178,7 @@ function routeEntry(id, op, options, ctx) {
177
178
  own.push(["readonly params", params]);
178
179
  if (factories.length > 0)
179
180
  own.push(["readonly errors", objectText(factories)]);
180
- own.push(["readonly meta", `Readonly<${meta}>`], ["readonly routePattern", tsString(pattern)]);
181
+ own.push(...routeFields(extracted, id, literal));
181
182
  const base = options.baseCtxName ?? "BaseCtx";
182
183
  const parts = [factories.length > 0 ? `Omit<${base}, "errors">` : base];
183
184
  const adds = extracted?.routes[id];
@@ -193,18 +194,65 @@ function routeEntry(id, op, options, ctx) {
193
194
  ];
194
195
  return entry.map(([key, type]) => `\t\t\t${key}: ${type}`).join("\n");
195
196
  }
196
- /** `BaseCtx`: the app's context over its env, the middleware's additions and its typed taps. */
197
+ /** `BaseCtx`: the app's context over its env, with the middleware's additions. */
197
198
  function baseCtx(extracted, name) {
198
- const env = extracted?.env ?? "Record<string, unknown>";
199
- const taps = extracted?.taps ?? null;
200
- const parts = [taps === null ? `HoneyContext<${env}>` : `Omit<HoneyContext<${env}>, "tap">`];
199
+ const parts = [`HttpContext<${extracted?.env ?? "Record<string, unknown>"}>`];
201
200
  const middleware = extracted?.middleware ?? [];
202
201
  if (middleware.length > 0)
203
202
  parts.push(propsText(middleware));
204
- if (taps !== null)
205
- parts.push("{ tap<K extends keyof TapMap>(key: K, payload: TapMap[K]): void }");
206
- const lines = taps === null ? [] : [`type TapMap = ${taps}`];
207
- return [...lines, `export type ${name} = ${parts.join(" & ")}`];
203
+ return `export type ${name} = ${parts.join(" & ")}`;
204
+ }
205
+ /**
206
+ * A WebSocket route's ctx, as core's `WSRouteCtx` types its callbacks: the base with the pattern's params, and the
207
+ * search input `.input()` declares. Extracted additions are keyed by HTTP routes only, so none join here.
208
+ */
209
+ function wsCtx(op, id, options, ctx) {
210
+ const own = [];
211
+ const search = wireInput(op, ctx).find(([key]) => key === "search");
212
+ if (search !== undefined)
213
+ own.push(["readonly input", objectText([search])]);
214
+ const params = ctxParams(options.extracted, id, pathOf(id));
215
+ if (params !== "{}")
216
+ own.push(["readonly params", params]);
217
+ const base = options.baseCtxName ?? "BaseCtx";
218
+ return own.length === 0 ? base : `${base} & ${objectText(own)}`;
219
+ }
220
+ /**
221
+ * The `HttpCodegen` augmentation: each declared id (the route's own, before core's suffix) to its kind and ctx, in
222
+ * code-unit order. An HTTP id names its `Routes` entry's ctx, a declared id over several routes its first route's in
223
+ * code-unit order (D3: no union of contexts). An operation without `x-backend-route` has no entry: `routesOf`
224
+ * reports an HTTP one, this a WebSocket one. Null with no operations, so core's plain string ids apply.
225
+ */
226
+ function operationSlot(ir, options, ctx) {
227
+ const routeIds = new Map();
228
+ const missing = [];
229
+ for (const op of ir.operations) {
230
+ const route = op.extensions.route;
231
+ if (route === undefined) {
232
+ if (op.extensions.websocket === true)
233
+ missing.push(`${op.method} ${op.path}: no x-backend-route; left out of the operationId slot`);
234
+ continue;
235
+ }
236
+ const declared = op.extensions.declaredId ?? op.id;
237
+ const entry = routeIds.get(declared) ?? { op, routes: [] };
238
+ if (!entry.routes.includes(route))
239
+ entry.routes.push(route);
240
+ routeIds.set(declared, entry);
241
+ }
242
+ for (const message of missing.sort(compareCodeUnits))
243
+ options.report(message);
244
+ if (routeIds.size === 0)
245
+ return null;
246
+ const entries = [...routeIds].sort(([a], [b]) => compareCodeUnits(a, b));
247
+ const lines = entries.map(([declared, { op, routes }]) => {
248
+ const id = routes.sort(compareCodeUnits)[0];
249
+ const method = id.slice(0, id.indexOf(" ")).toLowerCase();
250
+ const entry = op.extensions.websocket === true
251
+ ? `kind: "ws"; ctx: ${wsCtx(op, id, options, ctx)}`
252
+ : `kind: "http"; ctx: Routes[${tsString(pathOf(id))}][${tsString(method)}]["ctx"]`;
253
+ return `\t\t\t${tsString(declared)}: { ${entry} }`;
254
+ });
255
+ return `declare module "@workerstack/backend/http" {\n\tinterface HttpCodegen {\n\t\toperationId: {\n${lines.join("\n")}\n\t\t}\n\t}\n}`;
208
256
  }
209
257
  /** A route id's path: `GET /a` → `/a`. */
210
258
  const pathOf = (id) => id.slice(id.indexOf(" ") + 1);
@@ -231,21 +279,14 @@ export function generateTypes(options) {
231
279
  const names = { refName: componentNames(ir, [...RESERVED, name]) };
232
280
  const ctx = { names, resolve: (schema) => irToTs(schema, names) };
233
281
  const hasErrors = [...routes.values()].some((op) => Object.keys(op.extensions.errors ?? {}).length > 0);
234
- const selectors = [...routes.keys()].sort(compareCodeUnits);
235
- /* HoneyMeta only when a declared meta is emitted: the ctx's meta is that type and the keys a route may add */
236
- const declaredMeta = options.extracted?.meta ?? null;
237
- const imports = [
238
- "HoneyContext",
239
- "WithOutput",
240
- ...(hasErrors ? ["HoneyError"] : []),
241
- ...(declaredMeta === null ? [] : ["HoneyMeta"]),
242
- ];
243
- const out = [`import type { ${imports.join(", ")} } from "@workerstack/backend"`];
244
- out.push(...baseCtx(options.extracted, name));
245
- if (selectors.length > 0) {
246
- out.push(`export type RouteSelector = ${selectors.map(tsString).join(" | ")}`);
247
- out.push('declare module "@workerstack/backend" {\n\tinterface HoneyCodegen {\n\t\trouteSelector: RouteSelector\n\t}\n}');
248
- }
282
+ /* HttpMeta once a route's ctx reads it: with anything extracted, the ctx's meta is built from its keys */
283
+ const readsMeta = options.extracted !== null && options.extracted !== undefined && routes.size > 0;
284
+ const imports = ["HttpContext", "WithOutput", ...(hasErrors ? ["HttpError"] : []), ...(readsMeta ? ["HttpMeta"] : [])];
285
+ const out = [`import type { ${imports.join(", ")} } from "@workerstack/backend/http"`];
286
+ out.push(baseCtx(options.extracted, name));
287
+ const slot = operationSlot(ir, options, ctx);
288
+ if (slot !== null)
289
+ out.push(slot);
249
290
  for (const schema of Object.keys(ir.schemas).sort(compareCodeUnits))
250
291
  out.push(`type ${names.refName?.(schema)} = ${ctx.resolve(ir.schemas[schema])}`);
251
292
  out.push(routesType(routes, options, ctx));
@@ -7,6 +7,12 @@
7
7
  import type { ts } from "ts-morph";
8
8
  import { type Serializer } from "./serialize.ts";
9
9
  import type { Registration } from "./walk.ts";
10
+ /** A registration with the route ids its methods and paths give: the router's, never guessed. */
11
+ export type Routed = Registration & {
12
+ ids: string[];
13
+ /** the ids among `ids` served through a mount, at a path other than `own` */
14
+ mounted: string[];
15
+ };
10
16
  /** One property on `ctx` that the framework's context class does not declare: what the middleware added. */
11
17
  export type ExtractedProp = {
12
18
  /** Its name on `ctx`. */
@@ -25,10 +31,8 @@ export type RouteOptions = {
25
31
  base: ReadonlySet<string>;
26
32
  owner: ts.Node | undefined;
27
33
  report: (message: string) => void;
28
- routeId: (method: string, path: string) => string;
29
34
  };
30
- /**
31
- * Each route's own additions by route id. A route whose path is no literal, or one the router
32
- * refuses, is skipped; an id two registrations give different additions is dropped, never guessed.
33
- */
34
- export declare function routeAdditions(found: readonly Registration[], ser: Serializer, options: RouteOptions): Record<string, ExtractedProp[]>;
35
+ /** What a skip says of the route it skips. */
36
+ export declare const SKIPPED = "its ctx is not extracted";
37
+ /** Each route's own additions by route id. An id two registrations give different additions is dropped, never guessed. */
38
+ export declare function routeAdditions(found: readonly Routed[], ser: Serializer, options: RouteOptions): Record<string, ExtractedProp[]>;
@@ -42,28 +42,14 @@ export function addedProps(ctx, owner, ser) {
42
42
  return { name: p.getName(), optional, type: ref ?? (optional ? ser.optional(type) : ser.text(type)) };
43
43
  });
44
44
  }
45
- const SKIPPED = "its ctx is not extracted";
46
- /**
47
- * Each route's own additions by route id. A route whose path is no literal, or one the router
48
- * refuses, is skipped; an id two registrations give different additions is dropped, never guessed.
49
- */
45
+ /** What a skip says of the route it skips. */
46
+ export const SKIPPED = "its ctx is not extracted";
47
+ /** Each route's own additions by route id. An id two registrations give different additions is dropped, never guessed. */
50
48
  export function routeAdditions(found, ser, options) {
51
- const { base, owner, report, routeId } = options;
49
+ const { base, owner, report } = options;
52
50
  const byId = new Map();
53
51
  const conflicted = new Set();
54
- for (const { at, ctx, methods, path } of found) {
55
- if (path === null) {
56
- report(`${at}: the route's path is not a literal type; ${SKIPPED}`);
57
- continue;
58
- }
59
- let ids;
60
- try {
61
- ids = methods.map((method) => routeId(method, path));
62
- }
63
- catch (error) {
64
- report(`${at}: the router refuses ${JSON.stringify(path)} (${error.message}); ${SKIPPED}`);
65
- continue;
66
- }
52
+ for (const { ctx, ids } of found) {
67
53
  const props = addedProps(ctx, owner, ser).filter((p) => !base.has(p.name));
68
54
  const key = JSON.stringify(props);
69
55
  for (const id of ids) {
@@ -30,10 +30,10 @@ export type ExtractedTypes = {
30
30
  params: Record<string, string>;
31
31
  /** the meta type the app declares (`metaType<AppMeta>()`), or null when it declares none */
32
32
  meta: string | null;
33
+ /** the route ids served through a mount, at a path other than the one their handler's ctx types; code-unit sorted */
34
+ mounted: string[];
33
35
  /** per route id, what the route's middleware added beyond `middleware`; a route that added nothing has none */
34
36
  routes: Record<string, ExtractedProp[]>;
35
- /** the declared tap payloads, or null when none are */
36
- taps: string | null;
37
37
  };
38
38
  /** ts-morph, the optional peer, when installed; else undefined, which `extractTypes` reports once. */
39
39
  export declare function loadTsMorph(specifier?: string): Promise<TsMorph | undefined>;
@@ -8,18 +8,19 @@ var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExte
8
8
  };
9
9
  /**
10
10
  * Extract the types a generated file needs from the app's source: its env, what its middleware
11
- * added (the app's own, and each route's beyond them), and its taps. Written inline, so the
11
+ * added (the app's own, and each route's beyond them), its parsed inputs and meta. Written inline, so the
12
12
  * generated file imports nothing from the app but the named types it references by `import()`,
13
13
  * each through a specifier the output can resolve. ts-morph is the caller's, passed in.
14
14
  */
15
15
  import { existsSync, readFileSync } from "node:fs";
16
16
  import { dirname, join, relative, sep } from "node:path";
17
- import { addedProps, frameworkClass, routeAdditions } from "./chain.js";
17
+ import { compareCodeUnits } from "../emit/shared/lang.js";
18
+ import { addedProps, frameworkClass, routeAdditions, SKIPPED } from "./chain.js";
18
19
  import { Serializer } from "./serialize.js";
19
20
  import { loadEntry, registrations } from "./walk.js";
20
- /* the type-only members every honey app carries */
21
- const APP_MEMBERS = ["$ctx", "$env", "$taps"];
22
- /* the declared meta, read when the app carries it: an app from an older honey has no $meta and still extracts */
21
+ /* the type-only members every backend app carries */
22
+ const APP_MEMBERS = ["$ctx", "$env"];
23
+ /* the declared meta, read when the app carries it: an app from an older backend has no $meta and still extracts */
23
24
  const META_MEMBER = "$meta";
24
25
  /** The nearest named package.json above `file` (one without a name only marks a module type). */
25
26
  function nearestPackage(file, cache) {
@@ -112,26 +113,40 @@ function moduleSpecifier(file, outputDir, cache) {
112
113
  function resolvable(text, outputDir, cache) {
113
114
  return text.replace(/import\("([^"]+)"\)\./g, (_, file) => `import("${moduleSpecifier(file, outputDir, cache)}").`);
114
115
  }
116
+ /**
117
+ * Each registration with its route ids, methods by paths. A registration whose path is no literal, or a path the
118
+ * router refuses, is said once and gives no id.
119
+ */
120
+ function routed(found, routeId, report) {
121
+ return found.map((registration) => {
122
+ const { at, methods, paths } = registration;
123
+ if (paths === null) {
124
+ report(`${at}: the route's path is not a literal type; ${SKIPPED}`);
125
+ return { ...registration, ids: [], mounted: [] };
126
+ }
127
+ const served = paths.map((path) => {
128
+ try {
129
+ return { ids: methods.map((method) => routeId(method, path)), moved: path !== registration.own };
130
+ }
131
+ catch (error) {
132
+ report(`${at}: the router refuses ${JSON.stringify(path)} (${error.message}); ${SKIPPED}`);
133
+ return { ids: [], moved: false };
134
+ }
135
+ });
136
+ const ids = served.flatMap((s) => s.ids);
137
+ return { ...registration, ids, mounted: served.flatMap((s) => (s.moved ? s.ids : [])) };
138
+ });
139
+ }
115
140
  /** Each route's `pick` type (its parsed `ctx.input`, its `ctx.params`) as text by route id; an id two registrations type differently is left out. */
116
- function routeTypes(found, pick, serialize, routeId) {
141
+ function routeTypes(found, pick, serialize) {
117
142
  const byId = new Map();
118
143
  for (const registration of found) {
119
- const { methods, path } = registration;
120
144
  const type = pick(registration);
121
- if (type === null || path === null)
145
+ if (type === null)
122
146
  continue;
123
147
  const text = serialize(type);
124
- for (const method of methods) {
125
- let id;
126
- try {
127
- id = routeId(method, path);
128
- }
129
- catch {
130
- /* the router refuses the path: routeAdditions said so once */
131
- continue;
132
- }
148
+ for (const id of registration.ids)
133
149
  byId.set(id, byId.has(id) && byId.get(id) !== text ? null : text);
134
- }
135
150
  }
136
151
  return Object.fromEntries([...byId].filter((entry) => entry[1] !== null));
137
152
  }
@@ -162,17 +177,16 @@ export function extractTypes(options) {
162
177
  });
163
178
  if (members.includes(undefined)) {
164
179
  const missing = APP_MEMBERS.filter((_, index) => members[index] === undefined);
165
- throw new Error(`Export "${exportName}" is not a honey app: it carries no ${missing.join(", ")}`);
180
+ throw new Error(`Export "${exportName}" is not a backend app: it carries no ${missing.join(", ")}`);
166
181
  }
167
- const [ctx, env, tapsType] = members;
182
+ const [ctx, env] = members;
168
183
  const metaSym = appType.getProperty(META_MEMBER);
169
184
  const metaType = metaSym === undefined ? undefined : checker.getTypeOfSymbol(metaSym);
170
185
  const owner = frameworkClass(ctx, compiler);
171
186
  const middleware = addedProps(ctx, owner, ser);
172
187
  const base = new Set(middleware.map((p) => p.name));
173
- const found = registrations(entry);
174
- const routes = routeAdditions(found, ser, { base, owner, report, routeId });
175
- const taps = ser.serialize(tapsType);
188
+ const found = routed(registrations(entry, report), routeId, report);
189
+ const routes = routeAdditions(found, ser, { base, owner, report });
176
190
  /* what `metaType<AppMeta>()` declared, written out: the ctx's meta is this and the OpenAPI keys, never the tree's
177
191
  literal values, so a handler may pass its own ctx to a function typed with the generated ctx (bit 22 a) */
178
192
  const meta = metaType === undefined ? "{}" : ser.shape(metaType);
@@ -181,11 +195,11 @@ export function extractTypes(options) {
181
195
  const props = (list) => list.map((p) => ({ ...p, type: text(p.type) }));
182
196
  return {
183
197
  env: text(ser.serialize(env)),
184
- inputs: routeTypes(found, (r) => r.input, (type) => text(ser.shape(type)), routeId),
198
+ inputs: routeTypes(found, (r) => r.input, (type) => text(ser.shape(type))),
185
199
  meta: meta === "{}" ? null : text(meta),
186
200
  middleware: props(middleware),
187
- params: routeTypes(found, (r) => r.params, (type) => text(ser.shape(type)), routeId),
201
+ mounted: [...new Set(found.flatMap((r) => r.mounted))].sort(compareCodeUnits),
202
+ params: routeTypes(found, (r) => r.params, (type) => text(ser.shape(type))),
188
203
  routes: Object.fromEntries(Object.entries(routes).map(([id, list]) => [id, props(list)])),
189
- taps: taps === "{}" ? null : text(taps),
190
204
  };
191
205
  }
@@ -249,7 +249,7 @@ export class Serializer {
249
249
  #resolved(type) {
250
250
  if (type.intrinsicName !== "error")
251
251
  return;
252
- throw new Error(`type ${this.checker.typeToString(type)} does not resolve in the program honey reads: the entry, its imports and its tsconfig's .d.ts files`);
252
+ throw new Error(`type ${this.checker.typeToString(type)} does not resolve in the program clients reads: the entry, its imports and its tsconfig's .d.ts files`);
253
253
  }
254
254
  /** An optional member's type, without the `| undefined` its `?` already says (a `null` stays). */
255
255
  optional(type) {
@@ -15,13 +15,15 @@ export type EntryOptions = {
15
15
  tsconfigPath?: string;
16
16
  };
17
17
  export type LoadedEntry = {
18
+ /** the exported declaration: a variable, or for `export default <expr>` the expression */
19
+ appNode: ts.Node;
18
20
  /** the app's type */
19
21
  appType: ts.Type;
20
22
  checker: ts.TypeChecker;
21
23
  compiler: Compiler;
22
24
  project: Project;
23
25
  };
24
- /** One route a `.handler()` call registers: where, its methods, its full path (null if not a literal) and its ctx. */
26
+ /** One route a `.handler()` call registers: where, its methods, the full paths it is served at and its ctx. */
25
27
  export type Registration = {
26
28
  at: string;
27
29
  ctx: ts.Type;
@@ -30,7 +32,13 @@ export type Registration = {
30
32
  /** `ctx.params` as the handler receives it, or null when every param is the path's string */
31
33
  params: ts.Type | null;
32
34
  methods: string[];
33
- path: string | null;
35
+ /**
36
+ * the full paths the route is served at: under each chain of mounts that carries its app, else the path it was
37
+ * registered at; null when that path is not a literal. Code-unit sorted, without duplicates.
38
+ */
39
+ paths: string[] | null;
40
+ /** the full path its own app registered it at, the one its handler's `ctx.routePattern` types; null as `paths` */
41
+ own: string | null;
34
42
  };
35
43
  /**
36
44
  * The tsconfig that governs `fromPath`: the nearest one walking up, but never past the project root
@@ -43,5 +51,8 @@ export declare function findTsConfig(fromPath: string): string | undefined;
43
51
  * `include` names (wrangler's `worker-configuration.d.ts`) declares globals the app's types use, as under `tsc -p`.
44
52
  */
45
53
  export declare function loadEntry(tsMorph: TsMorph, options: EntryOptions): LoadedEntry;
46
- /** Every route the program's own files register (not declaration files, not packages), in file order then source order. */
47
- export declare function registrations(entry: LoadedEntry): Registration[];
54
+ /**
55
+ * Every route the program's own files register (not declaration files, not packages), in file order then source order,
56
+ * at the paths the program's mounts serve it at. A mount whose path is no literal is said through `report`.
57
+ */
58
+ export declare function registrations(entry: LoadedEntry, report: (message: string) => void): Registration[];