@workerstack/clients 1.0.0-rc.29 → 1.0.0-rc.31

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 (375) hide show
  1. package/README.md +548 -35
  2. package/assets/installers/examples/github.config.ts +17 -19
  3. package/assets/installers/examples/goreleaser.config.ts +16 -18
  4. package/assets/installers/examples/raw.config.ts +13 -15
  5. package/bin/clients.js +88 -68
  6. package/bin/installgen.js +18 -13
  7. package/dist/cli.d.ts +4 -4
  8. package/dist/cli.js +20 -12
  9. package/dist/emit/cli/channels.d.ts +2 -2
  10. package/dist/emit/cli/channels.js +18 -13
  11. package/dist/emit/cli/commands.d.ts +1 -1
  12. package/dist/emit/cli/commands.js +14 -8
  13. package/dist/emit/cli/discovery.d.ts +0 -6
  14. package/dist/emit/cli/discovery.js +9 -7
  15. package/dist/emit/cli/flags.d.ts +1 -3
  16. package/dist/emit/cli/flags.js +11 -5
  17. package/dist/emit/cli/install.d.ts +0 -8
  18. package/dist/emit/cli/install.js +3 -3
  19. package/dist/emit/cli/layout.d.ts +1 -1
  20. package/dist/emit/cli/layout.js +13 -10
  21. package/dist/emit/cli/module.d.ts +6 -6
  22. package/dist/emit/cli/module.js +10 -10
  23. package/dist/emit/cli/release.d.ts +0 -11
  24. package/dist/emit/cli/release.js +4 -4
  25. package/dist/emit/cli/skills.js +3 -3
  26. package/dist/emit/csharp/errors.js +4 -4
  27. package/dist/emit/csharp/json.js +8 -8
  28. package/dist/emit/csharp/realtime.js +3 -3
  29. package/dist/emit/csharp/sdk-answer.js +4 -4
  30. package/dist/emit/csharp/sdk-body.js +8 -6
  31. package/dist/emit/csharp/sdk-client.d.ts +3 -3
  32. package/dist/emit/csharp/sdk-client.js +2 -2
  33. package/dist/emit/csharp/sdk-csproj.d.ts +7 -9
  34. package/dist/emit/csharp/sdk-csproj.js +10 -10
  35. package/dist/emit/csharp/sdk-doc.js +1 -1
  36. package/dist/emit/csharp/sdk-method.d.ts +18 -2
  37. package/dist/emit/csharp/sdk-method.js +24 -9
  38. package/dist/emit/csharp/sdk-plan.js +0 -1
  39. package/dist/emit/csharp/sdk.js +7 -4
  40. package/dist/emit/csharp/sse.d.ts +0 -2
  41. package/dist/emit/csharp/sse.js +7 -7
  42. package/dist/emit/csharp/transport.js +7 -7
  43. package/dist/emit/csharp/types-enum.js +3 -1
  44. package/dist/emit/csharp/types-messages.js +3 -3
  45. package/dist/emit/csharp/types-names.js +10 -12
  46. package/dist/emit/csharp/types-record.js +3 -3
  47. package/dist/emit/csharp/types-union.d.ts +1 -1
  48. package/dist/emit/csharp/types.d.ts +0 -1
  49. package/dist/emit/csharp/types.js +3 -3
  50. package/dist/emit/csharp/ws.js +2 -2
  51. package/dist/emit/go/errors.js +1 -1
  52. package/dist/emit/go/http.js +2 -2
  53. package/dist/emit/go/module-path.js +2 -2
  54. package/dist/emit/go/sdk-answer.js +1 -1
  55. package/dist/emit/go/sdk-body.js +11 -7
  56. package/dist/emit/go/sdk-client.js +1 -1
  57. package/dist/emit/go/sdk-method.d.ts +9 -0
  58. package/dist/emit/go/sdk-method.js +12 -3
  59. package/dist/emit/go/sdk-mirror.js +2 -2
  60. package/dist/emit/go/sdk-opts.d.ts +0 -2
  61. package/dist/emit/go/sdk-opts.js +3 -3
  62. package/dist/emit/go/sdk.d.ts +1 -1
  63. package/dist/emit/go/sdk.js +12 -11
  64. package/dist/emit/go/sse.js +1 -1
  65. package/dist/emit/go/types-names.js +5 -0
  66. package/dist/emit/go/types-struct.d.ts +2 -1
  67. package/dist/emit/go/types-struct.js +1 -1
  68. package/dist/emit/go/types.js +9 -9
  69. package/dist/emit/go/ws.js +6 -6
  70. package/dist/emit/java/gradle.d.ts +7 -9
  71. package/dist/emit/java/gradle.js +8 -8
  72. package/dist/emit/java/json.js +1 -1
  73. package/dist/emit/java/layout-ast.js +1 -1
  74. package/dist/emit/java/layout-decl.js +5 -4
  75. package/dist/emit/java/layout-doc.js +13 -7
  76. package/dist/emit/java/layout-dot.js +1 -1
  77. package/dist/emit/java/layout-strings.js +4 -5
  78. package/dist/emit/java/layout-types.js +7 -5
  79. package/dist/emit/java/layout-visitor.js +4 -3
  80. package/dist/emit/java/layout.js +5 -4
  81. package/dist/emit/java/models-names.js +5 -4
  82. package/dist/emit/java/models-record.d.ts +0 -1
  83. package/dist/emit/java/models-record.js +3 -3
  84. package/dist/emit/java/models-union.d.ts +1 -1
  85. package/dist/emit/java/models-union.js +1 -1
  86. package/dist/emit/java/models.d.ts +1 -2
  87. package/dist/emit/java/models.js +25 -16
  88. package/dist/emit/java/realtime.d.ts +5 -17
  89. package/dist/emit/java/realtime.js +1 -1
  90. package/dist/emit/java/sdk-client.d.ts +6 -6
  91. package/dist/emit/java/sdk-client.js +2 -1
  92. package/dist/emit/java/sdk-decl.js +2 -2
  93. package/dist/emit/java/sdk-errors.js +1 -1
  94. package/dist/emit/java/sdk-headers.js +2 -2
  95. package/dist/emit/java/sdk-mirror.js +2 -2
  96. package/dist/emit/java/sdk-models.d.ts +1 -1
  97. package/dist/emit/java/sdk-models.js +7 -7
  98. package/dist/emit/java/sdk-op.d.ts +7 -11
  99. package/dist/emit/java/sdk-op.js +22 -10
  100. package/dist/emit/java/sdk-params.d.ts +5 -5
  101. package/dist/emit/java/sdk-params.js +3 -2
  102. package/dist/emit/java/sdk-plan.js +0 -1
  103. package/dist/emit/java/sdk.d.ts +1 -1
  104. package/dist/emit/java/sdk.js +21 -14
  105. package/dist/emit/java/sse.d.ts +2 -4
  106. package/dist/emit/java/sse.js +6 -6
  107. package/dist/emit/java/ws.d.ts +2 -2
  108. package/dist/emit/java/ws.js +3 -4
  109. package/dist/emit/mcp/annotations.js +8 -4
  110. package/dist/emit/mcp/files.js +9 -9
  111. package/dist/emit/mcp/mounted.js +2 -2
  112. package/dist/emit/mcp/output-schema.js +3 -3
  113. package/dist/emit/mcp/registry.d.ts +0 -2
  114. package/dist/emit/mcp/registry.js +5 -4
  115. package/dist/emit/mcp/runtime.js +2 -2
  116. package/dist/emit/mcp/schema.js +22 -11
  117. package/dist/emit/mcp/server.d.ts +7 -7
  118. package/dist/emit/mcp/server.js +7 -6
  119. package/dist/emit/mcp/tools.js +7 -6
  120. package/dist/emit/python/errors.js +3 -3
  121. package/dist/emit/python/realtime.js +2 -2
  122. package/dist/emit/python/sdk-answer.d.ts +3 -7
  123. package/dist/emit/python/sdk-answer.js +2 -2
  124. package/dist/emit/python/sdk-body.js +4 -5
  125. package/dist/emit/python/sdk-client.js +5 -5
  126. package/dist/emit/python/sdk-doc.js +2 -2
  127. package/dist/emit/python/sdk-method.d.ts +11 -0
  128. package/dist/emit/python/sdk-method.js +20 -5
  129. package/dist/emit/python/sdk-plan.js +0 -1
  130. package/dist/emit/python/sdk-pyproject.d.ts +0 -2
  131. package/dist/emit/python/sdk-pyproject.js +8 -8
  132. package/dist/emit/python/sdk.d.ts +1 -1
  133. package/dist/emit/python/sdk.js +12 -8
  134. package/dist/emit/python/sse.d.ts +0 -2
  135. package/dist/emit/python/sse.js +2 -2
  136. package/dist/emit/python/transport.js +4 -4
  137. package/dist/emit/python/types-dict.d.ts +2 -2
  138. package/dist/emit/python/types-dict.js +1 -1
  139. package/dist/emit/python/types-names.js +2 -2
  140. package/dist/emit/python/types-union.js +1 -1
  141. package/dist/emit/python/types.js +3 -3
  142. package/dist/emit/python/ws.d.ts +2 -5
  143. package/dist/emit/python/ws.js +4 -4
  144. package/dist/emit/rust/errors.js +3 -3
  145. package/dist/emit/rust/http.js +4 -4
  146. package/dist/emit/rust/realtime.js +2 -2
  147. package/dist/emit/rust/sdk-body.js +8 -5
  148. package/dist/emit/rust/sdk-cargo.d.ts +16 -18
  149. package/dist/emit/rust/sdk-cargo.js +12 -12
  150. package/dist/emit/rust/sdk-client.d.ts +1 -1
  151. package/dist/emit/rust/sdk-client.js +3 -3
  152. package/dist/emit/rust/sdk-method.d.ts +12 -1
  153. package/dist/emit/rust/sdk-method.js +12 -4
  154. package/dist/emit/rust/sdk-opts.d.ts +2 -1
  155. package/dist/emit/rust/sdk-opts.js +2 -2
  156. package/dist/emit/rust/sdk-plan.js +0 -1
  157. package/dist/emit/rust/sdk.d.ts +1 -1
  158. package/dist/emit/rust/sdk.js +9 -6
  159. package/dist/emit/rust/sse.d.ts +0 -5
  160. package/dist/emit/rust/sse.js +2 -2
  161. package/dist/emit/rust/types-names.js +3 -3
  162. package/dist/emit/rust/types-struct.js +1 -1
  163. package/dist/emit/rust/types-union.d.ts +1 -1
  164. package/dist/emit/rust/types.js +7 -5
  165. package/dist/emit/rust/ws.d.ts +0 -11
  166. package/dist/emit/rust/ws.js +5 -5
  167. package/dist/emit/shared/escape.js +17 -17
  168. package/dist/emit/shared/format.js +1 -1
  169. package/dist/emit/shared/gofmt.js +1 -1
  170. package/dist/emit/shared/lang.js +10 -10
  171. package/dist/emit/shared/literals.d.ts +5 -0
  172. package/dist/emit/shared/literals.js +8 -0
  173. package/dist/emit/shared/metadata.d.ts +0 -6
  174. package/dist/emit/shared/metadata.js +8 -7
  175. package/dist/emit/shared/ruff.js +1 -1
  176. package/dist/emit/shared/rustfmt.js +1 -1
  177. package/dist/emit/shared/type-emitter.js +37 -20
  178. package/dist/emit/shared/unknown-type.constants.d.ts +2 -0
  179. package/dist/emit/shared/unknown-type.constants.js +2 -0
  180. package/dist/emit/ts/http.d.ts +8 -2
  181. package/dist/emit/ts/http.js +51 -6
  182. package/dist/emit/ts/package.d.ts +14 -12
  183. package/dist/emit/ts/package.js +10 -8
  184. package/dist/emit/ts/route-tree.js +2 -2
  185. package/dist/emit/ts/sdk-types-preamble.d.ts +1 -1
  186. package/dist/emit/ts/sdk-types-preamble.js +12 -4
  187. package/dist/emit/ts/sdk-types.d.ts +0 -5
  188. package/dist/emit/ts/sdk-types.js +63 -19
  189. package/dist/emit/ts/sdk.d.ts +3 -1
  190. package/dist/emit/ts/sdk.js +44 -12
  191. package/dist/emit/ts/service-map.d.ts +7 -1
  192. package/dist/emit/ts/service-map.js +10 -1
  193. package/dist/emit/ts/single-flight-text.d.ts +3 -0
  194. package/dist/emit/ts/single-flight-text.js +38 -0
  195. package/dist/emit/ts/tanstack-query.d.ts +3 -2
  196. package/dist/emit/ts/tanstack-query.js +60 -35
  197. package/dist/emit/ts/type-gen.js +31 -18
  198. package/dist/emit/ts/webhooks.d.ts +0 -2
  199. package/dist/emit/ts/webhooks.js +3 -3
  200. package/dist/extract/chain.js +5 -4
  201. package/dist/extract/extract.js +5 -5
  202. package/dist/extract/serialize.d.ts +0 -2
  203. package/dist/extract/serialize.js +14 -15
  204. package/dist/extract/walk.js +15 -12
  205. package/dist/gen/args.js +9 -5
  206. package/dist/gen/formatters.js +5 -3
  207. package/dist/gen/process.js +2 -1
  208. package/dist/gen/shipped.js +2 -2
  209. package/dist/gen/switch-on.constants.d.ts +2 -0
  210. package/dist/gen/switch-on.constants.js +2 -0
  211. package/dist/gen/targets.d.ts +6 -7
  212. package/dist/gen/targets.js +11 -6
  213. package/dist/gen/write.js +4 -2
  214. package/dist/index.js +2 -2
  215. package/dist/installers/cli.d.ts +4 -4
  216. package/dist/installers/cli.js +24 -24
  217. package/dist/installers/commands/build.d.ts +4 -4
  218. package/dist/installers/commands/build.js +2 -3
  219. package/dist/installers/commands/check.d.ts +2 -2
  220. package/dist/installers/commands/check.js +11 -10
  221. package/dist/installers/commands/init.d.ts +2 -2
  222. package/dist/installers/commands/init.js +1 -2
  223. package/dist/installers/config/define-config.d.ts +16 -16
  224. package/dist/installers/config/define-config.js +1 -1
  225. package/dist/installers/config/hooks/bun.d.ts +6 -6
  226. package/dist/installers/config/hooks/node.js +1 -1
  227. package/dist/installers/config/load.d.ts +6 -8
  228. package/dist/installers/config/load.js +7 -8
  229. package/dist/installers/config/resolve.d.ts +1 -2
  230. package/dist/installers/config/resolve.js +28 -33
  231. package/dist/installers/config/types.d.ts +6 -6
  232. package/dist/installers/config/types.js +0 -1
  233. package/dist/installers/render/quote.js +3 -5
  234. package/dist/installers/render/render.d.ts +6 -6
  235. package/dist/installers/render/render.js +26 -26
  236. package/dist/installers/ui.d.ts +4 -4
  237. package/dist/installers/ui.js +3 -3
  238. package/dist/ir/build.d.ts +3 -3
  239. package/dist/ir/build.js +8 -5
  240. package/dist/ir/invalidate-reads.d.ts +17 -0
  241. package/dist/ir/invalidate-reads.js +104 -0
  242. package/dist/ir/load.d.ts +10 -0
  243. package/dist/ir/load.js +65 -18
  244. package/dist/ir/model.d.ts +2 -1
  245. package/dist/ir/model.js +0 -1
  246. package/dist/ir/read-method.constants.d.ts +2 -0
  247. package/dist/ir/read-method.constants.js +2 -0
  248. package/dist/ir/resolve-refs.js +2 -2
  249. package/dist/ir/resource-tree.js +2 -1
  250. package/dist/ir/route-tree-intern.js +1 -1
  251. package/dist/ir/schema.js +3 -3
  252. package/dist/ir/sdk-model.js +3 -3
  253. package/dist/ir/slots.js +13 -8
  254. package/dist/ir/streams.js +1 -1
  255. package/dist/release/bootstrap.d.ts +3 -3
  256. package/dist/release/bootstrap.js +7 -7
  257. package/dist/release/bump-args.js +4 -4
  258. package/dist/release/bump-command.d.ts +1 -1
  259. package/dist/release/bump-command.js +9 -10
  260. package/dist/release/bump.d.ts +5 -4
  261. package/dist/release/bump.js +2 -2
  262. package/dist/release/cli.d.ts +4 -4
  263. package/dist/release/cli.js +4 -4
  264. package/dist/release/codegen.js +1 -1
  265. package/dist/release/digest.js +5 -7
  266. package/dist/release/git.js +5 -8
  267. package/dist/release/load.js +4 -4
  268. package/dist/release/manifest.js +9 -10
  269. package/dist/release/oasdiff.d.ts +10 -15
  270. package/dist/release/oasdiff.js +5 -6
  271. package/dist/release/registries.d.ts +0 -11
  272. package/dist/release/registries.js +17 -17
  273. package/dist/release/release-state.d.ts +16 -13
  274. package/dist/release/release-workflow.js +5 -7
  275. package/dist/release/repo-settings.d.ts +2 -1
  276. package/dist/release/spec-gate.d.ts +0 -2
  277. package/dist/release/spec-gate.js +6 -10
  278. package/dist/release/sync-command.d.ts +2 -2
  279. package/dist/release/sync-command.js +1 -1
  280. package/dist/release/sync-tree.js +9 -13
  281. package/dist/release/sync.d.ts +6 -6
  282. package/dist/release/sync.js +12 -13
  283. package/dist/release/types.d.ts +22 -22
  284. package/dist/release/types.js +0 -1
  285. package/dist/release/version-files.d.ts +3 -4
  286. package/dist/release/version-files.js +4 -5
  287. package/dist/runtime/.oxfmtrc.jsonc +8 -0
  288. package/dist/runtime/csharp/Config.cs +9 -1
  289. package/dist/runtime/csharp/Exchange.cs +56 -4
  290. package/dist/runtime/csharp/Hooks.cs +9 -0
  291. package/dist/runtime/csharp/Operation.cs +6 -1
  292. package/dist/runtime/csharp/WsDial.cs +3 -1
  293. package/dist/runtime/go/config.go +5 -0
  294. package/dist/runtime/go/hooks.go +70 -0
  295. package/dist/runtime/go/request.go +6 -2
  296. package/dist/runtime/go/stream.go +4 -1
  297. package/dist/runtime/go/ws.go +3 -1
  298. package/dist/runtime/java/ClientConfig.java +11 -0
  299. package/dist/runtime/java/Flight.java +2 -12
  300. package/dist/runtime/java/Hooks.java +45 -0
  301. package/dist/runtime/java/InvalidateEvent.java +10 -0
  302. package/dist/runtime/java/InvalidateHook.java +12 -0
  303. package/dist/runtime/java/InvalidateTarget.java +7 -0
  304. package/dist/runtime/java/Operation.java +23 -3
  305. package/dist/runtime/java/Realtime.java +3 -1
  306. package/dist/runtime/java/WsDial.java +3 -0
  307. package/dist/runtime/mcp/files.ts +1 -1
  308. package/dist/runtime/mcp/http.ts +6 -2
  309. package/dist/runtime/mcp/listen.ts +1 -1
  310. package/dist/runtime/mcp/mount.ts +2 -2
  311. package/dist/runtime/mcp/protocol.ts +1 -1
  312. package/dist/runtime/python/config.py +8 -2
  313. package/dist/runtime/python/exchange.py +3 -1
  314. package/dist/runtime/python/hooks.py +110 -5
  315. package/dist/runtime/python/operation.py +2 -0
  316. package/dist/runtime/python/send_async.py +14 -2
  317. package/dist/runtime/python/send_sync.py +4 -2
  318. package/dist/runtime/python/ws.py +5 -1
  319. package/dist/runtime/rust/config.rs +6 -1
  320. package/dist/runtime/rust/exchange.rs +15 -3
  321. package/dist/runtime/rust/hooks.rs +127 -2
  322. package/dist/runtime/rust/log.rs +11 -3
  323. package/dist/runtime/rust/request.rs +17 -0
  324. package/dist/runtime/rust/ws.rs +9 -1
  325. package/dist/runtime/ts/config.ts +69 -0
  326. package/dist/runtime/ts/http.ts +12 -10
  327. package/dist/runtime/ts/request.ts +2 -0
  328. package/dist/runtime/ts/response.ts +7 -0
  329. package/dist/runtime/ts/sdk-invalidate.ts +82 -0
  330. package/dist/runtime/ts/sdk-single-flight.constants.ts +25 -0
  331. package/dist/runtime/ts/sdk-single-flight.ts +203 -0
  332. package/dist/runtime/ts/sdk-sse.ts +5 -1
  333. package/dist/runtime/ts/sdk-ws.ts +9 -3
  334. package/dist/runtime/ts/sdk.ts +55 -31
  335. package/dist/runtime/ts/single-flight-batch.ts +184 -0
  336. package/dist/runtime/ts/single-flight-body.ts +59 -0
  337. package/dist/runtime/ts/single-flight-run.ts +160 -0
  338. package/dist/runtime/ts/single-flight.constants.ts +31 -0
  339. package/dist/runtime/ts/single-flight.ts +158 -0
  340. package/dist/runtime/ts-tanstack-query/invalidate.ts +96 -92
  341. package/dist/runtime/ts-tanstack-query/query.ts +140 -170
  342. package/package.json +12 -17
  343. package/references/INDEX.md +31 -0
  344. package/references/cli.md +33 -0
  345. package/references/configuring.md +29 -0
  346. package/references/documentation.md +15 -0
  347. package/references/errors.md +23 -0
  348. package/references/flags.md +104 -0
  349. package/references/gates.md +46 -0
  350. package/references/generate.md +29 -0
  351. package/references/install-scripts.md +28 -0
  352. package/references/install.md +38 -0
  353. package/references/license.md +8 -0
  354. package/references/mcp.md +76 -0
  355. package/references/output.md +45 -0
  356. package/references/overview.md +14 -0
  357. package/references/release-tooling.md +34 -0
  358. package/references/release.md +305 -0
  359. package/references/sdks.md +393 -0
  360. package/references/start.md +22 -0
  361. package/references/tdd.md +16 -0
  362. package/dist/emit/cli/index.d.ts +0 -1
  363. package/dist/emit/cli/index.js +0 -1
  364. package/dist/emit/csharp/index.d.ts +0 -1
  365. package/dist/emit/csharp/index.js +0 -1
  366. package/dist/emit/go/index.d.ts +0 -1
  367. package/dist/emit/go/index.js +0 -1
  368. package/dist/emit/java/index.d.ts +0 -2
  369. package/dist/emit/java/index.js +0 -2
  370. package/dist/emit/mcp/index.d.ts +0 -3
  371. package/dist/emit/mcp/index.js +0 -3
  372. package/dist/emit/python/index.d.ts +0 -1
  373. package/dist/emit/python/index.js +0 -1
  374. package/dist/emit/rust/index.d.ts +0 -1
  375. package/dist/emit/rust/index.js +0 -1
@@ -3,13 +3,13 @@ import { isJsonMedia, mediaEssence } from "../../ir/sdk-model.js";
3
3
  import { bodiesOf } from "../../ir/slots.js";
4
4
  import { tsString } from "../shared/escape.js";
5
5
  import { compareCodeUnits } from "../shared/lang.js";
6
- import { literalType, quoteKey } from "../shared/literals.js";
6
+ import { literalType, optionalType, quoteKey } from "../shared/literals.js";
7
7
  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
- /* the names the file declares, which a component schema never takes */
10
+ // the names the file declares, which a component schema never takes
11
11
  const RESERVED = ["HttpContext", "HttpError", "HttpMeta", "Omit", "Partial", "Readonly", "Record", "Routes"];
12
- /* the v1 error-factory signature of a key without a schema (core errors.ts ErrorFactoryOpts) */
12
+ // the v1 error-factory signature of a key without a schema (core errors.ts ErrorFactoryOpts)
13
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";
14
14
  const EXTRACTORS = [
15
15
  ["RouteInput", "input"],
@@ -32,7 +32,7 @@ function routesOf(ir, report) {
32
32
  continue;
33
33
  if (id === undefined)
34
34
  missing.push(`${op.method} ${op.path}: no x-backend-route; left out of Routes`);
35
- /* `all()` and an optional param document one route as several operations: the first speaks for it */
35
+ // `all()` and an optional param document one route as several operations: the first speaks for it
36
36
  if (id !== undefined && !routes.has(id))
37
37
  routes.set(id, op);
38
38
  }
@@ -49,18 +49,24 @@ function paramsOf(pattern) {
49
49
  function wireInput(op, ctx) {
50
50
  const group = (params) => objectText([...params]
51
51
  .sort((a, b) => compareCodeUnits(a.name, b.name))
52
- .map((p) => [`${quoteKey(p.name)}${p.required === true ? "" : "?"}`, ctx.resolve(p.schema)]));
52
+ .map((p) => p.required === true
53
+ ? [quoteKey(p.name), ctx.resolve(p.schema)]
54
+ : [`${quoteKey(p.name)}?`, optionalType(ctx.resolve(p.schema))]));
53
55
  const fields = [];
54
56
  if (op.params.query.length > 0)
55
57
  fields.push(["search", group(op.params.query)]);
56
58
  if (op.params.header.length > 0)
57
59
  fields.push(["headers", group(op.params.header)]);
58
- /* the IR sets `cookie` only when the operation declares one */
60
+ // the IR sets `cookie` only when the operation declares one
59
61
  if (op.params.cookie !== undefined)
60
62
  fields.push(["cookies", group(op.params.cookie)]);
61
63
  const body = bodiesOf(op)[0];
62
- if (body?.kind === "stream")
63
- fields.push(["binary", `{ readonly bytes: Uint8Array<ArrayBuffer>; readonly type: ${tsString(body.contentType)} }`]);
64
+ if (body?.kind === "stream") {
65
+ fields.push([
66
+ "binary",
67
+ `{ readonly bytes: Uint8Array<ArrayBuffer>; readonly type: ${tsString(body.contentType)} }`,
68
+ ]);
69
+ }
64
70
  else if (body !== undefined) {
65
71
  const essence = mediaEssence(body.contentType);
66
72
  const field = isJsonMedia(body.contentType) ? "json" : "form";
@@ -136,12 +142,12 @@ function errorsOf(op, ctx) {
136
142
  * Without an extracted declaration (no ts-morph, or an app that declares no meta) the literals are all there is.
137
143
  */
138
144
  function ctxMeta(extracted, literal) {
139
- /* with nothing extracted, the tree's literals are all there is */
145
+ // with nothing extracted, the tree's literals are all there is
140
146
  if (extracted === null || extracted === undefined)
141
147
  return literal;
142
- /* the OpenAPI keys the declared meta does not redefine: a consumer that types `security` its own way holds
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()\` */
148
+ // the OpenAPI keys the declared meta does not redefine: a consumer that types `security` its own way holds
149
+ // that type in the handler, and intersecting backend's would conflict with it. An app that declares none
150
+ // holds them all, each widened by \`.meta()\`
145
151
  const declared = extracted.meta;
146
152
  return declared === null ? "Partial<HttpMeta>" : `Partial<Omit<HttpMeta, keyof ${declared}>> & ${declared}`;
147
153
  }
@@ -168,7 +174,7 @@ function routeEntry(id, op, options, ctx) {
168
174
  const params = ctxParams(extracted, id, pattern);
169
175
  const { factories, fields } = errorsOf(op, ctx);
170
176
  const mt = options.tree.routes[id]?.mt;
171
- /* the values the tree carries, as literals: what a consumer reads a route's configuration from */
177
+ // the values the tree carries, as literals: what a consumer reads a route's configuration from
172
178
  const literal = mt && Object.keys(mt).length > 0 ? literalType(mt) : "{}";
173
179
  const output = outputOf(op, ctx);
174
180
  const own = [];
@@ -209,7 +215,7 @@ function baseCtx(extracted, name) {
209
215
  */
210
216
  function wsCtx(op, id, options, ctx) {
211
217
  const own = [];
212
- /* the upgrade request's validated search, headers and cookies, as core's `WithInput` holds them */
218
+ // the upgrade request's validated search, headers and cookies, as core's `WithInput` holds them
213
219
  const input = wireInput(op, ctx).filter(([key]) => key === "search" || key === "headers" || key === "cookies");
214
220
  if (input.length > 0)
215
221
  own.push(["readonly input", objectText(input)]);
@@ -275,15 +281,21 @@ export function generateTypes(options) {
275
281
  const ir = toIR(options.document, { deriveOperationIds: true });
276
282
  const routes = routesOf(ir, options.report);
277
283
  const extra = Object.keys(options.extracted?.routes ?? {}).filter((id) => !routes.has(id));
278
- for (const id of extra.sort(compareCodeUnits))
284
+ for (const id of extra.sort(compareCodeUnits)) {
279
285
  options.report(`${id}: extracted ctx additions match no documented operation (internal and filtered routes are not documented); not typed`);
286
+ }
280
287
  const name = options.baseCtxName ?? "BaseCtx";
281
288
  const names = { refName: componentNames(ir, [...RESERVED, name]) };
282
289
  const ctx = { names, resolve: (schema) => irToTs(schema, names) };
283
290
  const hasErrors = [...routes.values()].some((op) => Object.keys(op.extensions.errors ?? {}).length > 0);
284
- /* HttpMeta once a route's ctx reads it: with anything extracted, the ctx's meta is built from its keys */
291
+ // HttpMeta once a route's ctx reads it: with anything extracted, the ctx's meta is built from its keys
285
292
  const readsMeta = options.extracted !== null && options.extracted !== undefined && routes.size > 0;
286
- const imports = ["HttpContext", "WithOutput", ...(hasErrors ? ["HttpError"] : []), ...(readsMeta ? ["HttpMeta"] : [])];
293
+ const imports = [
294
+ "HttpContext",
295
+ "WithOutput",
296
+ ...(hasErrors ? ["HttpError"] : []),
297
+ ...(readsMeta ? ["HttpMeta"] : []),
298
+ ];
287
299
  const out = [`import type { ${imports.join(", ")} } from "@workerstack/backend/http"`];
288
300
  out.push(baseCtx(options.extracted, name));
289
301
  const slot = operationSlot(ir, options, ctx);
@@ -292,7 +304,8 @@ export function generateTypes(options) {
292
304
  for (const schema of Object.keys(ir.schemas).sort(compareCodeUnits))
293
305
  out.push(`type ${names.refName?.(schema)} = ${ctx.resolve(ir.schemas[schema])}`);
294
306
  out.push(routesType(routes, options, ctx));
295
- for (const [type, field] of EXTRACTORS)
307
+ for (const [type, field] of EXTRACTORS) {
296
308
  out.push(`export type ${type}<TPath extends keyof Routes, TMethod extends keyof Routes[TPath] & string> = Routes[TPath][TMethod] extends { ${field}: infer T } ? T : never`);
309
+ }
297
310
  return `${out.join("\n\n")}\n`;
298
311
  }
@@ -5,8 +5,6 @@
5
5
  */
6
6
  import type { IR } from "../../ir/model.ts";
7
7
  import { type TypeOptions } from "../shared/type-emitter.ts";
8
- /** The catch-all event and the union, declared beside the events. */
9
- export declare const WEBHOOK_TYPES: readonly ["UnknownWebhookEvent", "WebhookEvent"];
10
8
  /** The type names `ir`'s events declare, for the component names to stay clear of; none without events. */
11
9
  export declare function webhookTypeNames(ir: IR): string[];
12
10
  /** The event types and their union, for `types.gen.ts`; empty for a document without events. */
@@ -3,7 +3,7 @@ import { compareCodeUnits, pascalWords } from "../shared/lang.js";
3
3
  import { irToTs } from "../shared/type-emitter.js";
4
4
  import { webhookSource } from "./http.js";
5
5
  /** The catch-all event and the union, declared beside the events. */
6
- export const WEBHOOK_TYPES = ["UnknownWebhookEvent", "WebhookEvent"];
6
+ const WEBHOOK_TYPES = ["UnknownWebhookEvent", "WebhookEvent"];
7
7
  /** `ir`'s events in code-unit order of their type, each named; two that name one type throw, naming both. */
8
8
  function namedEvents(ir) {
9
9
  const named = ir.webhooks
@@ -45,7 +45,7 @@ export type WebhookEvent = ${[...named.map(({ name }) => name), "UnknownWebhookE
45
45
 
46
46
  `;
47
47
  }
48
- /* the runtime verifier's untyped core, which `verifyWebhook` wraps: kept inside the file, out of a receiver's imports */
48
+ // the runtime verifier's untyped core, which `verifyWebhook` wraps: kept inside the file, out of a receiver's imports
49
49
  const INTERNAL = /^export ((?:async function verifyStandardWebhook|type VerifiedWebhook)\b)/gm;
50
50
  /**
51
51
  * The `${stem}.webhook.gen.ts` text of `ir`: the runtime's verifier, its untyped core unexported, then `verifyWebhook`
@@ -60,7 +60,7 @@ export function webhooksText(ir, stem) {
60
60
 
61
61
  export type { ${types.join(", ")} } from "./${stem}.types.gen.js"
62
62
 
63
- ${webhookSource().replace(INTERNAL, "$1")}
63
+ ${webhookSource().replaceAll(INTERNAL, "$1")}
64
64
 
65
65
  const KNOWN: ReadonlySet<string> = new Set([${known.join(", ")}])
66
66
 
@@ -16,7 +16,7 @@ function declaredRef(decl, ser) {
16
16
  const variable = checker.getShorthandAssignmentValueSymbol(decl)?.valueDeclaration;
17
17
  if (variable === undefined || !compiler.isBindingElement(variable))
18
18
  return ser.refFromDeclaration(variable);
19
- /* `const { db } = open()`: the pattern's own declaration; a parameter or a nested pattern names nothing */
19
+ // `const { db } = open()`: the pattern's own declaration; a parameter or a nested pattern names nothing
20
20
  const holder = variable.parent.parent;
21
21
  const init = compiler.isVariableDeclaration(holder) ? holder.initializer : undefined;
22
22
  const source = init === undefined ? undefined : checker.getTypeAtLocation(init).getProperty(decl.name.text);
@@ -28,7 +28,7 @@ function declaredRef(decl, ser) {
28
28
  /** The props of `ctx` the framework class does not own, in the ctx's order. */
29
29
  export function addedProps(ctx, owner, ser) {
30
30
  const { checker, compiler } = ser;
31
- /* a prop with no declaration (a mapped type's) is no member of anything */
31
+ // a prop with no declaration (a mapped type's) is no member of anything
32
32
  const owned = (decls) => owner !== undefined && decls.length > 0 && decls.every((d) => d.parent === owner);
33
33
  return ctx
34
34
  .getProperties()
@@ -36,7 +36,7 @@ export function addedProps(ctx, owner, ser) {
36
36
  .map((p) => {
37
37
  const decls = p.declarations ?? [];
38
38
  const optional = (p.flags & compiler.SymbolFlags.Optional) !== 0;
39
- /* a prop several middleware add is their intersection: only the checker's type says it */
39
+ // a prop several middleware add is their intersection: only the checker's type says it
40
40
  const ref = decls.length === 1 ? declaredRef(decls[0], ser) : undefined;
41
41
  const type = checker.getTypeOfSymbol(p);
42
42
  return { name: p.getName(), optional, type: ref ?? (optional ? ser.optional(type) : ser.text(type)) };
@@ -54,8 +54,9 @@ export function routeAdditions(found, ser, options) {
54
54
  const key = JSON.stringify(props);
55
55
  for (const id of ids) {
56
56
  const seen = byId.get(id);
57
- if (seen === undefined)
57
+ if (seen === undefined) {
58
58
  byId.set(id, { key, props });
59
+ }
59
60
  else if (seen.key !== key && !conflicted.has(id)) {
60
61
  conflicted.add(id);
61
62
  report(`${JSON.stringify(id)} is registered with different middleware; ${SKIPPED}`);
@@ -18,9 +18,9 @@ import { compareCodeUnits } from "../emit/shared/lang.js";
18
18
  import { addedProps, frameworkClass, routeAdditions, SKIPPED } from "./chain.js";
19
19
  import { Serializer } from "./serialize.js";
20
20
  import { loadEntry, registrations } from "./walk.js";
21
- /* the type-only members every backend app carries */
21
+ // the type-only members every backend app carries
22
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
+ // the declared meta, read when the app carries it: an app from an older backend has no $meta and still extracts
24
24
  const META_MEMBER = "$meta";
25
25
  /** The nearest named package.json above `file` (one without a name only marks a module type). */
26
26
  function nearestPackage(file, cache) {
@@ -111,7 +111,7 @@ function moduleSpecifier(file, outputDir, cache) {
111
111
  }
112
112
  /** `import("/abs/file.ts").X` → a specifier the output resolves (lib types are never referenced: they are global). */
113
113
  function resolvable(text, outputDir, cache) {
114
- return text.replace(/import\("([^"]+)"\)\./g, (_, file) => `import("${moduleSpecifier(file, outputDir, cache)}").`);
114
+ return text.replaceAll(/import\("([^"]+)"\)\./g, (_, file) => `import("${moduleSpecifier(file, outputDir, cache)}").`);
115
115
  }
116
116
  /**
117
117
  * Each registration with its route ids, methods by paths. A registration whose path is no literal, or a path the
@@ -187,8 +187,8 @@ export function extractTypes(options) {
187
187
  const base = new Set(middleware.map((p) => p.name));
188
188
  const found = routed(registrations(entry, report), routeId, report);
189
189
  const routes = routeAdditions(found, ser, { base, owner, report });
190
- /* what `metaType<AppMeta>()` declared, written out: the ctx's meta is this and the OpenAPI keys, never the tree's
191
- literal values, so a handler may pass its own ctx to a function typed with the generated ctx (bit 22 a) */
190
+ // what `metaType<AppMeta>()` declared, written out: the ctx's meta is this and the OpenAPI keys, never the tree's
191
+ // literal values, so a handler may pass its own ctx to a function typed with the generated ctx (bit 22 a)
192
192
  const meta = metaType === undefined ? "{}" : ser.shape(metaType);
193
193
  const cache = new Map();
194
194
  const text = (t) => resolvable(t, options.outputDir, cache);
@@ -11,8 +11,6 @@
11
11
  */
12
12
  import type { ts } from "ts-morph";
13
13
  export type Compiler = typeof ts;
14
- /** Lib types every program has in scope: written by name, never imported. */
15
- export declare function isLibFile(fileName: string): boolean;
16
14
  export declare class Serializer {
17
15
  #private;
18
16
  readonly checker: ts.TypeChecker;
@@ -1,7 +1,7 @@
1
- import { quoteKey } from "../emit/shared/literals.js";
1
+ import { optionalType, quoteKey } from "../emit/shared/literals.js";
2
2
  import { arrayOf, intersectionOf, unionOf } from "../emit/shared/type-emitter.js";
3
3
  /** Lib types every program has in scope: written by name, never imported. */
4
- export function isLibFile(fileName) {
4
+ function isLibFile(fileName) {
5
5
  return /(?:^|[\\/])lib\.[\w.-]*\.d\.ts$/.test(fileName) || /[\\/]typescript[\\/]lib[\\/]/.test(fileName);
6
6
  }
7
7
  /** Whether a declaring module exports `sym` (a declaration file's types are always reachable). */
@@ -15,7 +15,7 @@ function isExported(sym, file, checker) {
15
15
  function isScript(file) {
16
16
  return file.externalModuleIndicator === undefined;
17
17
  }
18
- /* checked in order: `boolean` is a union of its literals, so it is named before unions are split */
18
+ // checked in order: `boolean` is a union of its literals, so it is named before unions are split
19
19
  const KEYWORDS = [
20
20
  ["String", "string"],
21
21
  ["Number", "number"],
@@ -30,7 +30,7 @@ const KEYWORDS = [
30
30
  ["Unknown", "unknown"],
31
31
  ["Any", "unknown"],
32
32
  ["NonPrimitive", "object"],
33
- /* deferred generic forms (`T extends U ? X : Y`, `T[K]`, `keyof T`) are written as their bound */
33
+ // deferred generic forms (`T extends U ? X : Y`, `T[K]`, `keyof T`) are written as their bound
34
34
  ["StringMapping", "string"],
35
35
  ["Conditional", "unknown"],
36
36
  ["Substitution", "unknown"],
@@ -41,7 +41,7 @@ export class Serializer {
41
41
  checker;
42
42
  compiler;
43
43
  #active = new Set();
44
- /* type parameters of the signatures being written: inside them a parameter keeps its name */
44
+ // type parameters of the signatures being written: inside them a parameter keeps its name
45
45
  #bound = new Set();
46
46
  constructor(checker, compiler) {
47
47
  this.checker = checker;
@@ -57,9 +57,8 @@ export class Serializer {
57
57
  while (sym !== undefined && sym.flags & compiler.SymbolFlags.Alias)
58
58
  sym = checker.getAliasedSymbol(sym);
59
59
  const file = sym?.declarations?.[0]?.getSourceFile();
60
- if (sym === undefined || file === undefined || isLibFile(file.fileName) || !isExported(sym, file, checker)) {
60
+ if (sym === undefined || file === undefined || isLibFile(file.fileName) || !isExported(sym, file, checker))
61
61
  return undefined;
62
- }
63
62
  const args = (typeRef.typeArguments ?? []).map((a) => this.text(checker.getTypeFromTypeNode(a)));
64
63
  return `import("${file.fileName}").${sym.getName()}${args.length > 0 ? `<${args.join(", ")}>` : ""}`;
65
64
  }
@@ -79,7 +78,7 @@ export class Serializer {
79
78
  const globalName = this.#globalName(sym, decl);
80
79
  if (globalName !== null)
81
80
  return this.#withArgs(globalName, type, decl);
82
- /* an ambient module's member has no import() path here, and import() of an unexported type is `any` */
81
+ // an ambient module's member has no import() path here, and import() of an unexported type is `any`
83
82
  if (isScript(file) || !isExported(sym, file, this.checker))
84
83
  return null;
85
84
  return this.#withArgs(`import("${file.fileName}").${sym.getName()}`, type, decl);
@@ -108,7 +107,7 @@ export class Serializer {
108
107
  if (compiler.isSourceFile(n))
109
108
  global = isScript(n);
110
109
  }
111
- /* a `declare global` member is qualified as `global.Name`; in scope it is `Name` */
110
+ // a `declare global` member is qualified as `global.Name`; in scope it is `Name`
112
111
  const name = this.checker.getFullyQualifiedName(sym).replace(/^global\./, "");
113
112
  return global && /^[A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*)*$/.test(name) ? name : null;
114
113
  }
@@ -126,7 +125,7 @@ export class Serializer {
126
125
  }
127
126
  #serialize(type) {
128
127
  const { compiler } = this;
129
- /* an enum is nominal: its name when it can be referenced */
128
+ // an enum is nominal: its name when it can be referenced
130
129
  const enumRef = (type.getSymbol()?.flags ?? 0) & compiler.SymbolFlags.Enum ? this.asRef(type) : null;
131
130
  return (enumRef ??
132
131
  this.#keyword(type) ??
@@ -157,7 +156,7 @@ export class Serializer {
157
156
  /** A template literal type as written: its text escaped where a template would read it, each hole serialized. */
158
157
  #template(type) {
159
158
  const holes = type.types.map((hole) => `\${${this.serialize(hole)}}`);
160
- const texts = type.texts.map((text) => text.replace(/[`\\]|\$(?=\{)/g, (c) => `\\${c}`));
159
+ const texts = type.texts.map((text) => text.replaceAll(/[`\\]|\$(?=\{)/g, (c) => `\\${c}`));
161
160
  return `\`${texts.map((text, i) => text + (holes[i] ?? "")).join("")}\``;
162
161
  }
163
162
  /** By name inside the signature that declares it, else its constraint, else unknown. */
@@ -218,20 +217,20 @@ export class Serializer {
218
217
  const { checker, compiler } = this;
219
218
  const index = type.getStringIndexType();
220
219
  const props = type.getProperties().filter((p) => isPublicName(p.getName()));
221
- if (index !== undefined && props.length === 0 && type.getCallSignatures().length === 0) {
220
+ if (index !== undefined && props.length === 0 && type.getCallSignatures().length === 0)
222
221
  return `Record<string, ${this.serialize(index)}>`;
223
- }
224
222
  const M = compiler.ModifierFlags;
225
223
  const entries = [];
226
224
  for (const p of props) {
227
- /* a mapped type's prop has no declaration */
225
+ // a mapped type's prop has no declaration
228
226
  const decls = p.getDeclarations() ?? [];
229
227
  if (decls.some((d) => compiler.getCombinedModifierFlags(d) & (M.Private | M.Protected)))
230
228
  continue;
231
229
  const readonly = decls.some((d) => compiler.getCombinedModifierFlags(d) & M.Readonly);
232
230
  const optional = (p.flags & compiler.SymbolFlags.Optional) !== 0;
233
231
  const member = checker.getTypeOfSymbol(p);
234
- const value = optional ? this.optional(member) : this.serialize(member);
232
+ // `| undefined` said out loud: under exactOptionalPropertyTypes a bare `k?: T` refuses the undefined zod infers
233
+ const value = optional ? optionalType(this.optional(member)) : this.serialize(member);
235
234
  entries.push(`${readonly ? "readonly " : ""}${quoteKey(p.getName())}${optional ? "?" : ""}: ${value}`);
236
235
  }
237
236
  if (index !== undefined)
@@ -8,9 +8,9 @@
8
8
  import { existsSync } from "node:fs";
9
9
  import { dirname, resolve } from "node:path";
10
10
  import { compareCodeUnits } from "../emit/shared/lang.js";
11
- /* the type-only members every route builder carries */
11
+ // the type-only members every route builder carries
12
12
  const BUILDER_MEMBERS = ["$ctx", "$method", "$path"];
13
- /* the type-only members every app carries */
13
+ // the type-only members every app carries
14
14
  const APP_MEMBERS = ["$ctx", "$env"];
15
15
  /**
16
16
  * The tsconfig that governs `fromPath`: the nearest one walking up, but never past the project root
@@ -32,7 +32,10 @@ export function findTsConfig(fromPath) {
32
32
  */
33
33
  export function loadEntry(tsMorph, options) {
34
34
  const tsConfigFilePath = options.tsconfigPath ?? findTsConfig(options.entryPath);
35
- const project = new tsMorph.Project({ skipAddingFilesFromTsConfig: true, tsConfigFilePath });
35
+ const project = new tsMorph.Project({
36
+ skipAddingFilesFromTsConfig: true,
37
+ ...(tsConfigFilePath === undefined ? {} : { tsConfigFilePath }),
38
+ });
36
39
  project.addSourceFilesAtPaths(options.entryPath);
37
40
  if (tsConfigFilePath !== undefined) {
38
41
  const { ts } = tsMorph;
@@ -48,7 +51,7 @@ export function loadEntry(tsMorph, options) {
48
51
  if (decl === undefined)
49
52
  throw new Error(`Export "${options.exportName}" not found in ${options.entryPath}`);
50
53
  const checker = project.getTypeChecker().compilerObject;
51
- /* for `export default <expr>` the declaration is the expression itself */
54
+ // for `export default <expr>` the declaration is the expression itself
52
55
  return {
53
56
  appNode: decl.compilerNode,
54
57
  appType: checker.getTypeAtLocation(decl.compilerNode),
@@ -116,7 +119,7 @@ function appOrigins(entry) {
116
119
  const known = memo.get(expr);
117
120
  if (known !== undefined)
118
121
  return known;
119
- /* a binding that reads itself ends at the expression */
122
+ // a binding that reads itself ends at the expression
120
123
  memo.set(expr, expr);
121
124
  const found = step(expr);
122
125
  memo.set(expr, found);
@@ -127,7 +130,7 @@ function appOrigins(entry) {
127
130
  /** The receiver's base path: its `HttpApp` type argument `TBasePath`, when that is one literal. */
128
131
  function basePathOf(entry, app) {
129
132
  const { checker, compiler } = entry;
130
- /* a class's instance type is a reference to it: its type arguments are the app's */
133
+ // a class's instance type is a reference to it: its type arguments are the app's
131
134
  const decl = app.getSymbol()?.declarations?.find((d) => compiler.isClassDeclaration(d));
132
135
  const index = decl?.typeParameters?.findIndex((p) => p.name.text === "TBasePath") ?? -1;
133
136
  const arg = index < 0 ? undefined : checker.getTypeArguments(app)[index];
@@ -143,8 +146,8 @@ function mountOf(entry, call, origin, report) {
143
146
  const sub = call.arguments.at(-1);
144
147
  if (sub === undefined || call.arguments.length > 2 || APP_MEMBERS.some((m) => app.getProperty(m) === undefined))
145
148
  return null;
146
- /* core mounts nothing when the sub is the receiver's own app (`register.ts` `mount`): the groups that share one
147
- app keep their own ids */
149
+ // core mounts nothing when the sub is the receiver's own app (`register.ts` `mount`): the groups that share one
150
+ // app keep their own ids
148
151
  const [into, from] = [origin(receiver), origin(sub)];
149
152
  if (into === from)
150
153
  return null;
@@ -193,13 +196,13 @@ function registrationOf(entry, call) {
193
196
  if (phantoms.includes(undefined))
194
197
  return null;
195
198
  const [ctx, method, path] = phantoms;
196
- /* the handler callback's ctx parameter carries `input`, which the builder's `$ctx` phantom leaves out */
199
+ // the handler callback's ctx parameter carries `input`, which the builder's `$ctx` phantom leaves out
197
200
  const handler = checker.getResolvedSignature(call)?.parameters[0];
198
201
  const param = handler && checker.getTypeOfSymbol(handler).getCallSignatures()[0]?.parameters[0];
199
202
  const input = param && checker.getTypeOfSymbol(param).getProperty("input");
200
203
  const params = param && checker.getTypeOfSymbol(param).getProperty("params");
201
204
  const paramsType = params && checker.getTypeOfSymbol(params);
202
- /* a param schema shows as a key that is not a string: only then does the path's own typing fall short */
205
+ // a param schema shows as a key that is not a string: only then does the path's own typing fall short
203
206
  const typed = paramsType
204
207
  ?.getProperties()
205
208
  .some((key) => !(checker.getTypeOfSymbol(key).flags & compiler.TypeFlags.String));
@@ -209,7 +212,7 @@ function registrationOf(entry, call) {
209
212
  ctx: ctx,
210
213
  input: input ? checker.getTypeOfSymbol(input) : null,
211
214
  params: typed === true ? paramsType : null,
212
- /* `.on()`'s methods are literals by its signature; a path is one only as a single literal */
215
+ // `.on()`'s methods are literals by its signature; a path is one only as a single literal
213
216
  methods: literals(method),
214
217
  path: literalOf(path),
215
218
  };
@@ -241,7 +244,7 @@ export function registrations(entry, report) {
241
244
  .sort((a, b) => compareCodeUnits(a.fileName, b.fileName));
242
245
  for (const file of files)
243
246
  visit(file);
244
- /* the export resolves as any binding of it does: through its name, or as the default export's expression */
247
+ // the export resolves as any binding of it does: through its name, or as the default export's expression
245
248
  const prefixes = servedPrefixes(mounts, origin(compiler.isVariableDeclaration(appNode) ? appNode.name : appNode));
246
249
  return found.map(({ builder, path, ...registration }) => ({
247
250
  ...registration,
package/dist/gen/args.js CHANGED
@@ -44,7 +44,7 @@ Nothing outside <out>/<target> is written or deleted, and no symlink is followed
44
44
  export class UsageError extends Error {
45
45
  }
46
46
  function kebab(key) {
47
- return key.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`);
47
+ return key.replaceAll(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`);
48
48
  }
49
49
  /** The `--<target>-<option>` flag `flag` names: its target and its option's name; none for another flag. */
50
50
  function optionFlag(flag) {
@@ -72,14 +72,18 @@ function booleanOf(flag, inline) {
72
72
  /** One flag of `generate` into `into`. */
73
73
  function takeFlag(arg, rest, into) {
74
74
  const [flag, inline] = arg.slice(2).split(/=(.*)/s, 2);
75
- if (flag === "spec")
75
+ if (flag === "spec") {
76
76
  into.spec = valueOf(flag, inline, rest);
77
- else if (flag === "app")
77
+ }
78
+ else if (flag === "app") {
78
79
  into.app = valueOf(flag, inline, rest);
79
- else if (flag === "out")
80
+ }
81
+ else if (flag === "out") {
80
82
  into.out = valueOf(flag, inline, rest);
81
- else if (flag === "watch")
83
+ }
84
+ else if (flag === "watch") {
82
85
  into.watch = booleanOf(flag, inline);
86
+ }
83
87
  else if (flag === "target") {
84
88
  const target = valueOf(flag, inline, rest);
85
89
  if (!TARGETS.includes(target))
@@ -121,10 +121,12 @@ export async function formatterFor(target, where) {
121
121
  const rustfmt = findRustfmt(env);
122
122
  return rustfmt === undefined ? undefined : rustfmtFormatter(rustfmt);
123
123
  }
124
- case "ts":
124
+ case "ts": {
125
125
  return await loadOxfmt(oxfmt);
126
- default:
126
+ }
127
+ default: {
127
128
  return undefined;
129
+ }
128
130
  }
129
131
  }
130
132
  /**
@@ -138,7 +140,7 @@ export async function formatterFor(target, where) {
138
140
  */
139
141
  export function missingFormatter(target, pass, env, report) {
140
142
  const said = `${pass.tool} was not found, so the ${target} output is not formatted (${pass.install})`;
141
- /* an explicit demand is honoured for every target, quiet or not: the caller asked to be stopped */
143
+ // an explicit demand is honoured for every target, quiet or not: the caller asked to be stopped
142
144
  if (env.CLIENTS_REQUIRE_FORMATTERS === "1")
143
145
  throw new Error(said);
144
146
  if (pass.quiet !== true)
@@ -1,7 +1,8 @@
1
1
  /**
2
2
  * The generate CLI's child process (bit 17 phase h): watch mode runs each generation as a fresh `clients`, so
3
3
  * nothing one run loads outlives it. The child is the package's own bin on this runtime, which picks the entry as it
4
- * does for a user (Bun the TypeScript source, a checkout the source through jiti, an install the compiled one).
4
+ * does for a user (Bun the TypeScript source, a checkout the source by Node's type stripping, an install the compiled
5
+ * one).
5
6
  */
6
7
  import { spawn } from "node:child_process";
7
8
  import { fileURLToPath } from "node:url";
@@ -8,9 +8,9 @@
8
8
  import { iconName, LICENSE, README } from "../emit/shared/metadata.js";
9
9
  // per-process-constant: text-codec
10
10
  const UTF8 = /* @__PURE__ */ new TextDecoder("utf-8", { fatal: true });
11
- /* NuGet's cap on a package icon */
11
+ // NuGet's cap on a package icon
12
12
  const ICON_BYTES = 1024 * 1024;
13
- /* the signature each image format opens with, by the extensions that name it */
13
+ // the signature each image format opens with, by the extensions that name it
14
14
  const PNG = [0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a];
15
15
  const JPEG = [0xff, 0xd8, 0xff];
16
16
  /** The bytes of the file `metadata[field]` names, or a refusal naming the field. */
@@ -0,0 +1,2 @@
1
+ /** A switch option's value when it is on (bare `--ts-single-flight`, or `=true`); anything else is off. */
2
+ export declare const SWITCH_ON = "true";
@@ -0,0 +1,2 @@
1
+ /** A switch option's value when it is on (bare `--ts-single-flight`, or `=true`); anything else is off. */
2
+ export const SWITCH_ON = "true";
@@ -14,7 +14,8 @@ export declare const TARGETS: readonly ["cli", "csharp", "go", "java", "mcp", "p
14
14
  export type Target = (typeof TARGETS)[number];
15
15
  /**
16
16
  * Each target and the names of its generate function's options, which `--<target>-<option>` carries as strings.
17
- * `--ts-tanstack-query` is the one switch that takes no value: it turns the TanStack Query adapter on.
17
+ * `--ts-tanstack-query` and `--ts-single-flight` are the switches that take no value: they turn the TanStack Query
18
+ * adapter and the single-flight handler on.
18
19
  */
19
20
  export declare const TARGET_OPTIONS: {
20
21
  readonly cli: readonly ["aur", "baseUrl", "binaryName", "description", "envPrefix", "homebrewTap", "homepage", "installUrl", "license", "maintainer", "modulePath", "packages", "repo", "scoopBucket", "version", "wingetFork", "wingetPublisher"];
@@ -24,7 +25,7 @@ export declare const TARGET_OPTIONS: {
24
25
  readonly mcp: readonly ["envPrefix", "mcpName", "name", "packageName", "version"];
25
26
  readonly python: readonly ["packageName", "version"];
26
27
  readonly rust: readonly ["categories", "crateName", "description", "documentation", "homepage", "keywords", "license", "repository", "version"];
27
- readonly ts: readonly ["name", "packageName", "stem", "tanstackQuery", "version"];
28
+ readonly ts: readonly ["name", "packageName", "singleFlight", "stem", "tanstackQuery", "version"];
28
29
  };
29
30
  /**
30
31
  * The target options that take no value, since their name already says what they turn on
@@ -34,7 +35,7 @@ export declare const TARGET_OPTIONS: {
34
35
  */
35
36
  declare const BOOLEAN_OPTIONS: {
36
37
  readonly cli: readonly ["aur"];
37
- readonly ts: readonly ["tanstackQuery"];
38
+ readonly ts: readonly ["singleFlight", "tanstackQuery"];
38
39
  };
39
40
  /** The switches among `T`'s options: the ones `TargetOptions<T>` types as `"true"` or `"false"`. */
40
41
  type BooleanOption<T extends Target> = T extends keyof typeof BOOLEAN_OPTIONS ? (typeof BOOLEAN_OPTIONS)[T][number] : never;
@@ -45,14 +46,14 @@ export type TargetOptions<T extends Target> = {
45
46
  /** Any target's options by name, as the CLI parses and each generator reads them. */
46
47
  export type Options = Readonly<Record<string, string>>;
47
48
  /** One problem a schema found: what is wrong, and the option it is about. */
48
- export type OptionsIssue = {
49
+ type OptionsIssue = {
49
50
  /** What is wrong, naming the target and the option. */
50
51
  readonly message: string;
51
52
  /** The option's name, as the only segment; absent when the value is not an object at all. */
52
53
  readonly path?: readonly PropertyKey[];
53
54
  };
54
55
  /** What `validate` answers: the options it accepted, or every issue it found. */
55
- export type OptionsResult<T extends Target> = {
56
+ type OptionsResult<T extends Target> = {
56
57
  /** The options, as given. */
57
58
  readonly value: TargetOptions<T>;
58
59
  /** Absent: no issue was found. */
@@ -86,8 +87,6 @@ export declare function isBooleanOption(target: Target, key: string): boolean;
86
87
  export declare const targetOptionSchemas: {
87
88
  readonly [T in Target]: TargetOptionsSchema<T>;
88
89
  };
89
- /** `value` as `target`'s options, or an error naming every problem its schema found. */
90
- export declare function checkedOptions(target: Target, value: unknown): Options;
91
90
  /** `target`'s options: those `metadata` fills, under the ones the run gives the target itself, checked. */
92
91
  export declare function optionsFor(target: Target, metadata: Metadata, options: unknown): Options;
93
92
  export {};