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

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 (368) hide show
  1. package/README.md +403 -21
  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 +87 -66
  6. package/bin/installgen.js +19 -10
  7. package/dist/cli.d.ts +4 -4
  8. package/dist/cli.js +18 -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 +39 -13
  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 +18 -8
  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 +8 -4
  26. package/dist/emit/csharp/errors.js +4 -4
  27. package/dist/emit/csharp/json.js +8 -8
  28. package/dist/emit/csharp/realtime.d.ts +1 -8
  29. package/dist/emit/csharp/realtime.js +26 -26
  30. package/dist/emit/csharp/sdk-answer.d.ts +10 -2
  31. package/dist/emit/csharp/sdk-answer.js +4 -4
  32. package/dist/emit/csharp/sdk-body.js +8 -6
  33. package/dist/emit/csharp/sdk-client.d.ts +3 -3
  34. package/dist/emit/csharp/sdk-client.js +2 -2
  35. package/dist/emit/csharp/sdk-csproj.d.ts +7 -9
  36. package/dist/emit/csharp/sdk-csproj.js +10 -10
  37. package/dist/emit/csharp/sdk-doc.js +1 -1
  38. package/dist/emit/csharp/sdk-method.d.ts +0 -1
  39. package/dist/emit/csharp/sdk-method.js +19 -8
  40. package/dist/emit/csharp/sdk-plan.js +0 -1
  41. package/dist/emit/csharp/sdk.js +3 -3
  42. package/dist/emit/csharp/sse.d.ts +0 -13
  43. package/dist/emit/csharp/sse.js +92 -11
  44. package/dist/emit/csharp/transport.js +9 -9
  45. package/dist/emit/csharp/types-enum.js +3 -1
  46. package/dist/emit/csharp/types-messages.d.ts +47 -0
  47. package/dist/emit/csharp/types-messages.js +172 -0
  48. package/dist/emit/csharp/types-names.js +13 -14
  49. package/dist/emit/csharp/types-record.js +3 -3
  50. package/dist/emit/csharp/types-union.d.ts +1 -1
  51. package/dist/emit/csharp/types.d.ts +0 -1
  52. package/dist/emit/csharp/types.js +3 -3
  53. package/dist/emit/csharp/ws.d.ts +0 -15
  54. package/dist/emit/csharp/ws.js +26 -5
  55. package/dist/emit/go/errors.js +1 -1
  56. package/dist/emit/go/http.js +2 -2
  57. package/dist/emit/go/module-path.js +2 -2
  58. package/dist/emit/go/sdk-answer.d.ts +24 -1
  59. package/dist/emit/go/sdk-answer.js +1 -1
  60. package/dist/emit/go/sdk-body.js +11 -7
  61. package/dist/emit/go/sdk-client.js +1 -1
  62. package/dist/emit/go/sdk-method.d.ts +3 -0
  63. package/dist/emit/go/sdk-method.js +18 -12
  64. package/dist/emit/go/sdk-mirror.js +2 -2
  65. package/dist/emit/go/sdk-opts.d.ts +0 -2
  66. package/dist/emit/go/sdk-opts.js +3 -3
  67. package/dist/emit/go/sdk.d.ts +1 -1
  68. package/dist/emit/go/sdk.js +9 -9
  69. package/dist/emit/go/sse.d.ts +2 -10
  70. package/dist/emit/go/sse.js +88 -13
  71. package/dist/emit/go/types-names.js +5 -0
  72. package/dist/emit/go/types-struct.d.ts +2 -1
  73. package/dist/emit/go/types-struct.js +1 -1
  74. package/dist/emit/go/types-union.d.ts +3 -2
  75. package/dist/emit/go/types-union.js +2 -0
  76. package/dist/emit/go/types.d.ts +6 -0
  77. package/dist/emit/go/types.js +20 -9
  78. package/dist/emit/go/ws.d.ts +4 -11
  79. package/dist/emit/go/ws.js +215 -59
  80. package/dist/emit/java/gradle.d.ts +7 -9
  81. package/dist/emit/java/gradle.js +8 -8
  82. package/dist/emit/java/json.d.ts +3 -0
  83. package/dist/emit/java/json.js +1 -1
  84. package/dist/emit/java/layout-ast.d.ts +4 -1
  85. package/dist/emit/java/layout-ast.js +1 -1
  86. package/dist/emit/java/layout-decl.js +5 -4
  87. package/dist/emit/java/layout-doc.js +13 -7
  88. package/dist/emit/java/layout-dot.js +1 -1
  89. package/dist/emit/java/layout-strings.js +4 -5
  90. package/dist/emit/java/layout-types.js +7 -5
  91. package/dist/emit/java/layout-visitor.js +4 -3
  92. package/dist/emit/java/layout.js +5 -4
  93. package/dist/emit/java/models-names.d.ts +2 -0
  94. package/dist/emit/java/models-names.js +6 -4
  95. package/dist/emit/java/models-record.d.ts +0 -1
  96. package/dist/emit/java/models-record.js +3 -3
  97. package/dist/emit/java/models-union.d.ts +13 -2
  98. package/dist/emit/java/models-union.js +12 -6
  99. package/dist/emit/java/models.d.ts +5 -1
  100. package/dist/emit/java/models.js +44 -20
  101. package/dist/emit/java/realtime.d.ts +34 -26
  102. package/dist/emit/java/realtime.js +45 -10
  103. package/dist/emit/java/sdk-client.d.ts +6 -6
  104. package/dist/emit/java/sdk-client.js +1 -1
  105. package/dist/emit/java/sdk-decl.js +2 -2
  106. package/dist/emit/java/sdk-errors.js +1 -1
  107. package/dist/emit/java/sdk-headers.js +2 -2
  108. package/dist/emit/java/sdk-mirror.js +7 -6
  109. package/dist/emit/java/sdk-models.d.ts +1 -1
  110. package/dist/emit/java/sdk-models.js +7 -7
  111. package/dist/emit/java/sdk-op.d.ts +1 -10
  112. package/dist/emit/java/sdk-op.js +9 -9
  113. package/dist/emit/java/sdk-params.d.ts +5 -5
  114. package/dist/emit/java/sdk-params.js +3 -2
  115. package/dist/emit/java/sdk-plan.js +0 -1
  116. package/dist/emit/java/sdk.d.ts +1 -1
  117. package/dist/emit/java/sdk.js +14 -13
  118. package/dist/emit/java/sse.d.ts +12 -13
  119. package/dist/emit/java/sse.js +105 -6
  120. package/dist/emit/java/ws.d.ts +48 -9
  121. package/dist/emit/java/ws.js +88 -4
  122. package/dist/emit/mcp/annotations.js +8 -4
  123. package/dist/emit/mcp/files.js +9 -9
  124. package/dist/emit/mcp/mounted.js +2 -2
  125. package/dist/emit/mcp/output-schema.d.ts +4 -2
  126. package/dist/emit/mcp/output-schema.js +58 -14
  127. package/dist/emit/mcp/registry.d.ts +0 -2
  128. package/dist/emit/mcp/registry.js +5 -4
  129. package/dist/emit/mcp/runtime.js +2 -2
  130. package/dist/emit/mcp/schema.js +22 -11
  131. package/dist/emit/mcp/server.d.ts +7 -7
  132. package/dist/emit/mcp/server.js +7 -6
  133. package/dist/emit/mcp/tools.js +7 -6
  134. package/dist/emit/python/errors.js +3 -3
  135. package/dist/emit/python/realtime.d.ts +9 -6
  136. package/dist/emit/python/realtime.js +22 -20
  137. package/dist/emit/python/sdk-answer.d.ts +8 -8
  138. package/dist/emit/python/sdk-answer.js +2 -2
  139. package/dist/emit/python/sdk-body.js +4 -5
  140. package/dist/emit/python/sdk-client.js +5 -5
  141. package/dist/emit/python/sdk-doc.js +2 -2
  142. package/dist/emit/python/sdk-method.d.ts +1 -1
  143. package/dist/emit/python/sdk-method.js +38 -11
  144. package/dist/emit/python/sdk-plan.js +0 -1
  145. package/dist/emit/python/sdk-pyproject.d.ts +0 -2
  146. package/dist/emit/python/sdk-pyproject.js +8 -8
  147. package/dist/emit/python/sdk.d.ts +1 -1
  148. package/dist/emit/python/sdk.js +28 -8
  149. package/dist/emit/python/sse.d.ts +0 -7
  150. package/dist/emit/python/sse.js +36 -6
  151. package/dist/emit/python/transport.js +4 -4
  152. package/dist/emit/python/types-dict.d.ts +2 -2
  153. package/dist/emit/python/types-dict.js +1 -1
  154. package/dist/emit/python/types-names.js +2 -2
  155. package/dist/emit/python/types-union.js +1 -1
  156. package/dist/emit/python/types.d.ts +7 -0
  157. package/dist/emit/python/types.js +23 -6
  158. package/dist/emit/python/ws.d.ts +21 -10
  159. package/dist/emit/python/ws.js +69 -3
  160. package/dist/emit/rust/errors.js +3 -3
  161. package/dist/emit/rust/http.js +4 -4
  162. package/dist/emit/rust/realtime.d.ts +7 -5
  163. package/dist/emit/rust/realtime.js +15 -18
  164. package/dist/emit/rust/sdk-body.js +8 -5
  165. package/dist/emit/rust/sdk-cargo.d.ts +16 -18
  166. package/dist/emit/rust/sdk-cargo.js +12 -12
  167. package/dist/emit/rust/sdk-client.d.ts +1 -1
  168. package/dist/emit/rust/sdk-client.js +3 -3
  169. package/dist/emit/rust/sdk-method.js +3 -3
  170. package/dist/emit/rust/sdk-opts.d.ts +2 -1
  171. package/dist/emit/rust/sdk-opts.js +2 -2
  172. package/dist/emit/rust/sdk-plan.js +0 -1
  173. package/dist/emit/rust/sdk.d.ts +1 -1
  174. package/dist/emit/rust/sdk.js +5 -5
  175. package/dist/emit/rust/sse.d.ts +11 -12
  176. package/dist/emit/rust/sse.js +54 -8
  177. package/dist/emit/rust/types-names.js +3 -3
  178. package/dist/emit/rust/types-struct.js +1 -1
  179. package/dist/emit/rust/types-union.d.ts +10 -2
  180. package/dist/emit/rust/types-union.js +4 -0
  181. package/dist/emit/rust/types.d.ts +9 -0
  182. package/dist/emit/rust/types.js +20 -12
  183. package/dist/emit/rust/ws.d.ts +22 -15
  184. package/dist/emit/rust/ws.js +60 -10
  185. package/dist/emit/shared/escape.js +17 -17
  186. package/dist/emit/shared/format.js +1 -1
  187. package/dist/emit/shared/gofmt.js +1 -1
  188. package/dist/emit/shared/lang.js +10 -10
  189. package/dist/emit/shared/literals.d.ts +5 -0
  190. package/dist/emit/shared/literals.js +8 -0
  191. package/dist/emit/shared/metadata.d.ts +0 -6
  192. package/dist/emit/shared/metadata.js +8 -7
  193. package/dist/emit/shared/ruff.js +1 -1
  194. package/dist/emit/shared/rustfmt.js +1 -1
  195. package/dist/emit/shared/type-emitter.js +37 -20
  196. package/dist/emit/shared/unknown-type.constants.d.ts +2 -0
  197. package/dist/emit/shared/unknown-type.constants.js +2 -0
  198. package/dist/emit/ts/http.d.ts +0 -2
  199. package/dist/emit/ts/http.js +4 -4
  200. package/dist/emit/ts/package.d.ts +14 -12
  201. package/dist/emit/ts/package.js +9 -8
  202. package/dist/emit/ts/route-tree.js +2 -2
  203. package/dist/emit/ts/sdk-types-preamble.d.ts +1 -1
  204. package/dist/emit/ts/sdk-types-preamble.js +6 -2
  205. package/dist/emit/ts/sdk-types.js +59 -20
  206. package/dist/emit/ts/sdk.js +6 -6
  207. package/dist/emit/ts/service-map.d.ts +10 -3
  208. package/dist/emit/ts/service-map.js +30 -2
  209. package/dist/emit/ts/tanstack-query.js +6 -6
  210. package/dist/emit/ts/type-gen.js +36 -21
  211. package/dist/emit/ts/webhooks.d.ts +0 -2
  212. package/dist/emit/ts/webhooks.js +3 -3
  213. package/dist/extract/chain.js +5 -4
  214. package/dist/extract/extract.js +5 -5
  215. package/dist/extract/serialize.d.ts +0 -2
  216. package/dist/extract/serialize.js +14 -15
  217. package/dist/extract/walk.js +15 -12
  218. package/dist/gen/args.js +9 -5
  219. package/dist/gen/formatters.js +5 -3
  220. package/dist/gen/shipped.js +2 -2
  221. package/dist/gen/targets.d.ts +2 -4
  222. package/dist/gen/targets.js +8 -4
  223. package/dist/gen/write.js +4 -2
  224. package/dist/index.js +2 -2
  225. package/dist/installers/cli.d.ts +4 -4
  226. package/dist/installers/cli.js +24 -24
  227. package/dist/installers/commands/build.d.ts +4 -4
  228. package/dist/installers/commands/build.js +2 -3
  229. package/dist/installers/commands/check.d.ts +2 -2
  230. package/dist/installers/commands/check.js +11 -10
  231. package/dist/installers/commands/init.d.ts +2 -2
  232. package/dist/installers/commands/init.js +1 -2
  233. package/dist/installers/config/define-config.d.ts +16 -16
  234. package/dist/installers/config/define-config.js +1 -1
  235. package/dist/installers/config/hooks/bun.d.ts +6 -6
  236. package/dist/installers/config/hooks/node.js +1 -1
  237. package/dist/installers/config/load.d.ts +6 -8
  238. package/dist/installers/config/load.js +7 -8
  239. package/dist/installers/config/resolve.d.ts +1 -2
  240. package/dist/installers/config/resolve.js +28 -33
  241. package/dist/installers/config/types.d.ts +6 -6
  242. package/dist/installers/config/types.js +0 -1
  243. package/dist/installers/render/quote.js +3 -5
  244. package/dist/installers/render/render.d.ts +6 -6
  245. package/dist/installers/render/render.js +26 -26
  246. package/dist/installers/ui.d.ts +4 -4
  247. package/dist/installers/ui.js +3 -3
  248. package/dist/ir/build.d.ts +3 -3
  249. package/dist/ir/build.js +12 -5
  250. package/dist/ir/load.js +9 -10
  251. package/dist/ir/model.d.ts +16 -1
  252. package/dist/ir/model.js +0 -1
  253. package/dist/ir/resolve-refs.js +2 -2
  254. package/dist/ir/resource-tree.js +2 -1
  255. package/dist/ir/route-tree-intern.js +1 -1
  256. package/dist/ir/schema.js +3 -3
  257. package/dist/ir/sdk-model.d.ts +25 -1
  258. package/dist/ir/sdk-model.js +38 -8
  259. package/dist/ir/slots.d.ts +1 -1
  260. package/dist/ir/slots.js +22 -11
  261. package/dist/ir/streams.d.ts +16 -0
  262. package/dist/ir/streams.js +40 -0
  263. package/dist/release/bootstrap.d.ts +3 -3
  264. package/dist/release/bootstrap.js +7 -7
  265. package/dist/release/bump-args.js +4 -4
  266. package/dist/release/bump-command.d.ts +1 -1
  267. package/dist/release/bump-command.js +9 -10
  268. package/dist/release/bump.d.ts +5 -4
  269. package/dist/release/bump.js +2 -2
  270. package/dist/release/cli.d.ts +4 -4
  271. package/dist/release/cli.js +4 -4
  272. package/dist/release/codegen.js +1 -1
  273. package/dist/release/digest.js +5 -7
  274. package/dist/release/git.js +5 -8
  275. package/dist/release/load.js +3 -3
  276. package/dist/release/manifest.js +9 -10
  277. package/dist/release/oasdiff.d.ts +10 -15
  278. package/dist/release/oasdiff.js +5 -6
  279. package/dist/release/registries.d.ts +0 -11
  280. package/dist/release/registries.js +17 -17
  281. package/dist/release/release-state.d.ts +16 -13
  282. package/dist/release/release-workflow.js +5 -7
  283. package/dist/release/repo-settings.d.ts +2 -1
  284. package/dist/release/spec-gate.d.ts +0 -2
  285. package/dist/release/spec-gate.js +6 -10
  286. package/dist/release/sync-command.d.ts +2 -2
  287. package/dist/release/sync-command.js +1 -1
  288. package/dist/release/sync-tree.js +9 -13
  289. package/dist/release/sync.d.ts +6 -6
  290. package/dist/release/sync.js +12 -13
  291. package/dist/release/types.d.ts +22 -22
  292. package/dist/release/types.js +0 -1
  293. package/dist/release/version-files.d.ts +3 -4
  294. package/dist/release/version-files.js +4 -5
  295. package/dist/runtime/.oxfmtrc.jsonc +8 -0
  296. package/dist/runtime/cli/socket.go +107 -13
  297. package/dist/runtime/cli/stream.go +18 -11
  298. package/dist/runtime/csharp/Adapters.cs +12 -11
  299. package/dist/runtime/csharp/Events.cs +22 -17
  300. package/dist/runtime/csharp/Realtime.cs +50 -23
  301. package/dist/runtime/csharp/RealtimeLoop.cs +1 -1
  302. package/dist/runtime/csharp/TransportSse.cs +3 -3
  303. package/dist/runtime/csharp/Ws.cs +1 -1
  304. package/dist/runtime/csharp/WsDial.cs +19 -1
  305. package/dist/runtime/csharp/WsTyped.cs +109 -0
  306. package/dist/runtime/go/realtime.go +125 -41
  307. package/dist/runtime/go/realtime_loop.go +21 -18
  308. package/dist/runtime/go/result.go +2 -1
  309. package/dist/runtime/go/sse.go +11 -0
  310. package/dist/runtime/go/stream.go +29 -13
  311. package/dist/runtime/go/transport.go +15 -21
  312. package/dist/runtime/go/transport_longpoll.go +3 -4
  313. package/dist/runtime/go/transport_sse.go +6 -6
  314. package/dist/runtime/go/ws.go +157 -61
  315. package/dist/runtime/java/EventStream.java +47 -29
  316. package/dist/runtime/java/Exchange.java +5 -5
  317. package/dist/runtime/java/Flight.java +3 -3
  318. package/dist/runtime/java/Realtime.java +45 -11
  319. package/dist/runtime/java/ResumableConnection.java +77 -32
  320. package/dist/runtime/java/Socket.java +8 -4
  321. package/dist/runtime/java/SseAdapter.java +1 -1
  322. package/dist/runtime/java/TypedWebSocket.java +81 -24
  323. package/dist/runtime/java/WsAdapter.java +4 -2
  324. package/dist/runtime/java/WsDial.java +12 -5
  325. package/dist/runtime/mcp/files.ts +1 -1
  326. package/dist/runtime/mcp/http.ts +6 -2
  327. package/dist/runtime/mcp/listen.ts +1 -1
  328. package/dist/runtime/mcp/mount.ts +2 -2
  329. package/dist/runtime/mcp/protocol.ts +1 -1
  330. package/dist/runtime/python/events.py +25 -11
  331. package/dist/runtime/python/operation.py +6 -1
  332. package/dist/runtime/python/realtime.py +47 -33
  333. package/dist/runtime/python/send_async.py +1 -0
  334. package/dist/runtime/python/transport_sse.py +2 -2
  335. package/dist/runtime/python/transport_ws.py +1 -1
  336. package/dist/runtime/python/ws.py +100 -39
  337. package/dist/runtime/rust/events.rs +64 -41
  338. package/dist/runtime/rust/realtime.rs +80 -34
  339. package/dist/runtime/rust/realtime_loop.rs +37 -12
  340. package/dist/runtime/rust/sse.rs +3 -2
  341. package/dist/runtime/rust/transport_sse.rs +1 -1
  342. package/dist/runtime/rust/transport_ws.rs +3 -2
  343. package/dist/runtime/rust/ws.rs +122 -50
  344. package/dist/runtime/ts/realtime-connection.ts +22 -0
  345. package/dist/runtime/ts/realtime-transports.ts +13 -4
  346. package/dist/runtime/ts/realtime.ts +27 -3
  347. package/dist/runtime/ts/sdk-realtime.ts +1 -1
  348. package/dist/runtime/ts/sdk-sse.ts +31 -14
  349. package/dist/runtime/ts/sdk-ws.ts +2 -1
  350. package/dist/runtime/ts/sdk.ts +9 -2
  351. package/dist/runtime/ts/sse.ts +8 -0
  352. package/dist/runtime/ts/ws.ts +88 -50
  353. package/dist/runtime/ts-tanstack-query/query.ts +0 -2
  354. package/package.json +12 -40
  355. package/dist/emit/cli/index.d.ts +0 -1
  356. package/dist/emit/cli/index.js +0 -1
  357. package/dist/emit/csharp/index.d.ts +0 -1
  358. package/dist/emit/csharp/index.js +0 -1
  359. package/dist/emit/go/index.d.ts +0 -1
  360. package/dist/emit/go/index.js +0 -1
  361. package/dist/emit/java/index.d.ts +0 -2
  362. package/dist/emit/java/index.js +0 -2
  363. package/dist/emit/mcp/index.d.ts +0 -3
  364. package/dist/emit/mcp/index.js +0 -3
  365. package/dist/emit/python/index.d.ts +0 -1
  366. package/dist/emit/python/index.js +0 -1
  367. package/dist/emit/rust/index.d.ts +0 -1
  368. package/dist/emit/rust/index.js +0 -1
@@ -10,8 +10,8 @@
10
10
  import { escapeText } from "../shared/escape.js";
11
11
  import { AUTHOR, authorOf, checked, HTTPS_URL, SPDX_ID, TEXT } from "../shared/metadata.js";
12
12
  /** The one runtime dependency, its coordinates pinned with the test classpath's (java-pins.json). */
13
- export const JACKSON = "tools.jackson.core:jackson-databind:3.2.4";
14
- /* Java's keywords and literals (JLS 3.9, 3.10.3, 3.10.7): no package segment may be one, and `_` is one since 9 */
13
+ const JACKSON = "tools.jackson.core:jackson-databind:3.2.4";
14
+ // Java's keywords and literals (JLS 3.9, 3.10.3, 3.10.7): no package segment may be one, and `_` is one since 9
15
15
  const RESERVED = [
16
16
  "abstract",
17
17
  "assert",
@@ -68,15 +68,15 @@ const RESERVED = [
68
68
  "null",
69
69
  "_",
70
70
  ];
71
- /* the type names the client file spells or imports, and its nested Builder: a client of one of these clashes */
71
+ // the type names the client file spells or imports, and its nested Builder: a client of one of these clashes
72
72
  const SPELLED = ["Builder", "IllegalStateException", "String", "Transport", "URI"];
73
- /* a Maven group: lowercase dotted words; an artifact: lowercase words joined by `-`; a package segment: a lowercase
74
- * identifier; a client: a PascalCase type */
73
+ // a Maven group: lowercase dotted words; an artifact: lowercase words joined by `-`; a package segment: a lowercase
74
+ // identifier; a client: a PascalCase type
75
75
  const GROUP_ID = /^[a-z][a-z0-9_]*(?:\.[a-z][a-z0-9_]*)*$/;
76
76
  const ARTIFACT_ID = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/;
77
77
  const SEGMENT = /^[a-z_][a-z0-9_]*$/;
78
78
  const CLIENT_NAME = /^[A-Z][A-Za-z0-9_]*$/;
79
- /* SemVer 2 (semver.org's recommended pattern), as the C# and Rust packages take it */
79
+ // SemVer 2 (semver.org's recommended pattern), as the C# and Rust packages take it
80
80
  const SEMVER = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/;
81
81
  const refuse = (option, value) => {
82
82
  throw new Error(`Invalid ${option}: ${JSON.stringify(value)}`);
@@ -95,7 +95,7 @@ export function validatePackageName(value) {
95
95
  export const validateClientName = (value) => CLIENT_NAME.test(value) && !SPELLED.includes(value) ? value : refuse("clientName", value);
96
96
  /** A SemVer 2 version. */
97
97
  export const validateVersion = (value) => (SEMVER.test(value) ? value : refuse("version", value));
98
- /* a repository is a path on its host: `https://host/owner/name` */
98
+ // a repository is a path on its host: `https://host/owner/name`
99
99
  const REPOSITORY_PATH = /^https:\/\/[^/]+\/[^/]/;
100
100
  /** The developers option as one author each, or a refusal of the whole value when any is not a name or `Name <email>`. */
101
101
  function developersOf(value) {
@@ -128,7 +128,7 @@ export function pomOf(options, info) {
128
128
  * text neither interpolates (no `$` in `'…'`) nor ends the string.
129
129
  */
130
130
  const groovyString = (text) => `'${escapeText(text, "java").replaceAll("'", "\\'")}'`;
131
- /* the indent of the `pom { … }` block's members, and of one level in */
131
+ // the indent of the `pom { … }` block's members, and of one level in
132
132
  const POM = " ";
133
133
  const IN = " ";
134
134
  /** `key = '…'` lines at `indent`, each value a Groovy string. */
@@ -1,8 +1,11 @@
1
1
  /** One dispatch: the values that select a wrapper, the wrapper, and the payload type it reads. */
2
+ /** A keyed union's arm: the values that select it, its wrapper, its payload, and what its first value spells. */
2
3
  export type Dispatch = {
3
4
  readonly values: readonly string[];
4
5
  readonly wrapper: string;
5
6
  readonly payload: string;
7
+ /** its first value as a Java type name, `Variant<index>` when none selects it */
8
+ readonly spelled: string;
6
9
  };
7
10
  /** A union's nested `Deserializer`, two spaces in: from its `final class` line to its closing brace. */
8
11
  export declare function deserializerLines(name: string, property: string, dispatch: readonly Dispatch[], unknown: string): string[];
@@ -5,7 +5,7 @@
5
5
  */
6
6
  import { javaString } from "../shared/escape.js";
7
7
  import { bin, call, classOf, forOpen, ifOpen, lit, local, methodHeader, newOf, param, returnStmt, rule, statement, throwStmt, typeHeader, } from "./layout.js";
8
- /* a payload's erasure: `Class` takes no type arguments */
8
+ // a payload's erasure: `Class` takes no type arguments
9
9
  const erased = (type) => type.replace(/<.*$/, "");
10
10
  /** One switch arm, `case label -> value;` (`default` for no label), in the switch's body. */
11
11
  const arm = (label, value) => statement(8, rule(label === null ? null : lit(label), value));
@@ -129,7 +129,10 @@ type Header = {
129
129
  readonly name: string;
130
130
  readonly end: "{" | "{}";
131
131
  };
132
- /** A type declaration's header: a record's components and interface, a class's superclass, an interface's permits. */
132
+ /**
133
+ * A type declaration's header: a record's components and interface, a class's superclass, an interface's permits (none
134
+ * when its subtypes are nested in it).
135
+ */
133
136
  export type TypeHeader = Header & ({
134
137
  readonly kind: "enum";
135
138
  } | {
@@ -52,7 +52,7 @@ export const id = (path) => path
52
52
  /** A literal or any token kept whole: `"GET"`, `null`, `true`, `16L`. */
53
53
  export const lit = (text) => ({ k: "lit", text });
54
54
  /** A string as an expression: an identifier path, else a token kept whole. */
55
- export const expr = (e) => typeof e !== "string" ? e : /^[A-Za-z_$][\w$]*(\.[A-Za-z_$][\w$]*)*$/.test(e) ? id(e) : lit(e);
55
+ export const expr = (e) => typeof e === "string" ? (/^[A-Za-z_$][\w$]*(\.[A-Za-z_$][\w$]*)*$/.test(e) ? id(e) : lit(e)) : e;
56
56
  /** `of.name(args)`, or `name(args)` with no receiver; a string receiver is an identifier path. */
57
57
  export const call = (of, name, args = []) => ({
58
58
  args: args.map(expr),
@@ -125,15 +125,16 @@ export function method(v, m) {
125
125
  /** The return type and the name with its `(`, the break before the name tagged. */
126
126
  function nameScope(v, m, beforeName) {
127
127
  v.b.open(0);
128
- if (m.returns !== undefined) {
128
+ if (m.returns === undefined) {
129
+ v.b.open(0);
130
+ }
131
+ else {
129
132
  v.b.open(0);
130
133
  v.b.open(0);
131
134
  v.type(type(m.returns));
132
135
  v.b.close();
133
136
  v.b.brk("independent", " ", 0, beforeName);
134
- }
135
- else
136
- v.b.open(0); /* a constructor's name scope opens with its name */
137
+ } /* a constructor's name scope opens with its name */
137
138
  v.b.token(m.name);
138
139
  v.b.token("(");
139
140
  v.b.close();
@@ -8,7 +8,7 @@
8
8
  */
9
9
  /** google-java-format's line width. */
10
10
  export const WIDTH = 100;
11
- /* a forced break is "wider" than any line (Doc.MAX_LINE_WIDTH) */
11
+ // a forced break is "wider" than any line (Doc.MAX_LINE_WIDTH)
12
12
  const MAX = 1000;
13
13
  const evalIndent = (indent) => typeof indent === "number" ? indent : indent.tag.taken ? indent.onBreak : indent.onFlat;
14
14
  /** Indent.If: `onBreak` when `tag`'s break was taken, else `onFlat`. */
@@ -50,8 +50,9 @@ function computeBroken(doc, start) {
50
50
  doc.breaks.push(child);
51
51
  doc.splits.push([]);
52
52
  }
53
- else
53
+ else {
54
54
  doc.splits.at(-1).push(child);
55
+ }
55
56
  }
56
57
  return doc.splits.reduce((state, split, i) => breakAndSplit(state, i === 0 ? undefined : doc.breaks[i - 1], split), start);
57
58
  }
@@ -68,8 +69,9 @@ function breakAndSplit(state, brk, split) {
68
69
  brk.newIndent = Math.max(state.lastIndent + evalIndent(brk.indent), 0);
69
70
  next = { ...state, column: brk.newIndent };
70
71
  }
71
- else
72
+ else {
72
73
  next = { ...state, column: state.column + brk.flat.length };
74
+ }
73
75
  }
74
76
  const room = next.column + splitWidth <= WIDTH;
75
77
  next = { ...next, mustBreak: false };
@@ -78,20 +80,24 @@ function breakAndSplit(state, brk, split) {
78
80
  return room ? next : { ...next, mustBreak: true };
79
81
  }
80
82
  function write(doc, out) {
81
- if (doc.k === "text")
83
+ if (doc.k === "text") {
82
84
  put(doc, out);
83
- else if (doc.k === "break")
85
+ }
86
+ else if (doc.k === "break") {
84
87
  out.text += doc.broken ? `\n${" ".repeat(doc.newIndent)}` : doc.flat;
85
- else if (doc.oneLine)
88
+ }
89
+ else if (doc.oneLine) {
86
90
  for (const child of doc.docs)
87
91
  writeFlat(child, out);
88
- else
92
+ }
93
+ else {
89
94
  doc.splits.forEach((split, i) => {
90
95
  if (i > 0)
91
96
  write(doc.breaks[i - 1], out);
92
97
  for (const child of split)
93
98
  write(child, out);
94
99
  });
100
+ }
95
101
  }
96
102
  function writeFlat(doc, out) {
97
103
  if (doc.k === "level")
@@ -59,7 +59,7 @@ function regularDot(v, items) {
59
59
  }
60
60
  v.b.token(e.name);
61
61
  argsAndParen(v, e, 0);
62
- /* the last item is the chain itself, and no dot follows it */
62
+ // the last item is the chain itself, and no dot follows it
63
63
  if (i < items.length - 1)
64
64
  length += v.flat(e).length;
65
65
  });
@@ -4,10 +4,8 @@
4
4
  * `+` chain (or stands alone), else under its own quote.
5
5
  */
6
6
  import { WIDTH } from "./layout-doc.js";
7
- /*
8
- * StringWrapper.stringComponents: a literal's body cut before each whitespace character (and a `\t`), a run of
9
- * `\n`/`\r` escapes ending the piece it closes
10
- */
7
+ // StringWrapper.stringComponents: a literal's body cut before each whitespace character (and a `\t`), a run of
8
+ // `\n`/`\r` escapes ending the piece it closes
11
9
  function piecesOf(body) {
12
10
  const out = [];
13
11
  let start = 0;
@@ -19,8 +17,9 @@ function piecesOf(body) {
19
17
  while (body.startsWith("\\r", i) || body.startsWith("\\n", i))
20
18
  i += 2;
21
19
  }
22
- else
20
+ else {
23
21
  continue;
22
+ }
24
23
  out.push(body.slice(start, i));
25
24
  start = i;
26
25
  }
@@ -31,8 +31,9 @@ function typeList(v, word, types) {
31
31
  v.b.open(4);
32
32
  v.b.token(word);
33
33
  types.forEach((t, i) => {
34
- if (i === 0)
34
+ if (i === 0) {
35
35
  v.b.space();
36
+ }
36
37
  else {
37
38
  v.b.token(",");
38
39
  v.b.breakOp(" ");
@@ -44,7 +45,7 @@ function typeList(v, word, types) {
44
45
  /** A type declaration's header, through its `{` (or `{}`). */
45
46
  export function typeDeclaration(v, h) {
46
47
  if (h.kind === "enum") {
47
- /* visitEnumDeclaration's header: a level of its own, `enum` and a unified break before the name at +4 */
48
+ // visitEnumDeclaration's header: a level of its own, `enum` and a unified break before the name at +4
48
49
  v.b.open(0);
49
50
  typeModifiers(v, h);
50
51
  v.b.open(4);
@@ -61,7 +62,7 @@ export function typeDeclaration(v, h) {
61
62
  v.b.token(h.name);
62
63
  v.b.open(4);
63
64
  if (h.kind === "record") {
64
- /* visitRecordDeclaration's components as formals, then its interface */
65
+ // visitRecordDeclaration's components as formals, then its interface
65
66
  v.b.token("(");
66
67
  if (h.components.length > 0) {
67
68
  v.b.breakToFill("");
@@ -79,15 +80,16 @@ export function typeDeclaration(v, h) {
79
80
  }
80
81
  else if (h.kind === "class") {
81
82
  if (h.extends !== undefined) {
82
- /* classDeclarationTypeList of one superclass, in no level of its own */
83
+ // classDeclarationTypeList of one superclass, in no level of its own
83
84
  v.b.breakToFill(" ");
84
85
  v.b.token("extends");
85
86
  v.b.space();
86
87
  v.type(type(h.extends));
87
88
  }
88
89
  }
89
- else
90
+ else if (h.permits.length > 0) {
90
91
  typeList(v, "permits", h.permits);
92
+ }
91
93
  v.b.close();
92
94
  }
93
95
  v.b.space();
@@ -59,7 +59,7 @@ export class Visitor {
59
59
  new Visitor(b).expr(e);
60
60
  return b.flat();
61
61
  }
62
- /* hasOnlyShortItems: every item under MAX_ITEM_LENGTH_FOR_FILLING (10) characters */
62
+ // hasOnlyShortItems: every item under MAX_ITEM_LENGTH_FOR_FILLING (10) characters
63
63
  shortItems(items) {
64
64
  return items.every((item) => this.flat(item).length < 10);
65
65
  }
@@ -78,8 +78,9 @@ export class Visitor {
78
78
  const dims = t.dims > 0;
79
79
  if (dims)
80
80
  this.b.open(4);
81
- if (t.args.length === 0)
81
+ if (t.args.length === 0) {
82
82
  this.typeName(t.name);
83
+ }
83
84
  else {
84
85
  this.b.open(4);
85
86
  this.typeName(t.name);
@@ -220,7 +221,7 @@ export class Visitor {
220
221
  this.b.brk(fill, " ");
221
222
  this.b.token(e.op);
222
223
  this.b.space();
223
- /* a literal in a `+` after a non-literal operand reflows under its own quote */
224
+ // a literal in a `+` after a non-literal operand reflows under its own quote
224
225
  const later = e.op === "+" && isString(operand) && !e.operands.slice(0, i + 1).every(isString);
225
226
  if (later)
226
227
  this.b.literal(this.flat(operand), true);
@@ -5,7 +5,7 @@
5
5
  * (GJF's Doc and DocBuilder), the visitor layout-visitor.ts, layout-dot.ts and layout-decl.ts (JavaInputAstVisitor),
6
6
  * and a long string literal is reflowed as StringWrapper reflows it (layout-strings.ts).
7
7
  */
8
- import { expr } from "./layout-ast.js";
8
+ import { expr, } from "./layout-ast.js";
9
9
  import { annotation, declareOne, method } from "./layout-decl.js";
10
10
  import { Builder } from "./layout-doc.js";
11
11
  import { wrapStrings } from "./layout-strings.js";
@@ -26,7 +26,7 @@ const STATEMENTS = {
26
26
  v.b.token(";");
27
27
  },
28
28
  for: (v, s) => {
29
- /* visitEnhancedForLoop: the variable declared with `:` before its iterable */
29
+ // visitEnhancedForLoop: the variable declared with `:` before its iterable
30
30
  v.b.open(0);
31
31
  v.b.token("for");
32
32
  v.b.space();
@@ -53,10 +53,11 @@ const STATEMENTS = {
53
53
  local: (v, s) => declareOne(v, s.decl, { kind: "variable", trailing: ";" }),
54
54
  return: (v, s) => keyword(v, "return", s.expr),
55
55
  rule: (v, s) => {
56
- /* visitCase, a rule: `case label ->` or `default ->`, a unified break, the value at +4 */
56
+ // visitCase, a rule: `case label ->` or `default ->`, a unified break, the value at +4
57
57
  v.b.open(4);
58
- if (s.label === null)
58
+ if (s.label === null) {
59
59
  v.b.token("default");
60
+ }
60
61
  else {
61
62
  v.b.token("case");
62
63
  v.b.open(0);
@@ -11,6 +11,8 @@ export type JavaTypeNames = {
11
11
  /** the schema of the component `name` when Java declares nothing for it, so a ref to it is its use type */
12
12
  alias(name: string): IRSchema | undefined;
13
13
  resolve(schema: IRSchema): IRSchema;
14
+ /** whether `name` is held: by the runtime, a type the SDK spells, `taken`, or a declaration claimed so far */
15
+ has(name: string): boolean;
14
16
  /** each component emitted under another name than its own (`<Name>Model`), for the generation's notices */
15
17
  readonly renamed: readonly Rename[];
16
18
  };
@@ -9,7 +9,7 @@ import { irResolver } from "../../ir/schema.js";
9
9
  import { compareCodeUnits, javaTypeName, NameScope } from "../shared/lang.js";
10
10
  /** The type a value without a schema is, and the one a nullable open value is. */
11
11
  export const JSON_NODE = "JsonNode";
12
- /* the type names the emitted models and the client spell, which no runtime file holds: each is reserved */
12
+ // the type names the emitted models and the client spell, which no runtime file holds: each is reserved
13
13
  const SPELLED = [
14
14
  "Boolean",
15
15
  "Builder",
@@ -39,7 +39,7 @@ const SPELLED = [
39
39
  * The code text a scan reads: comments dropped and string and char literals emptied, in one left-to-right pass, so a
40
40
  * `//` inside a string opens no comment and a quote inside a comment opens no string.
41
41
  */
42
- export const codeOf = (code) => code.replace(/\/\*[\s\S]*?\*\/|\/\/.*$|"(?:[^"\\\n]|\\.)*"|'(?:[^'\\\n]|\\.)'/gm, (token) => token.startsWith("/") ? "" : token[0] === '"' ? '""' : "''");
42
+ export const codeOf = (code) => code.replaceAll(/\/\*[\s\S]*?\*\/|\/\/.*$|"(?:[^"\\\n]|\\.)*"|'(?:[^'\\\n]|\\.)'/gm, (token) => token.startsWith("/") ? "" : token[0] === '"' ? '""' : "''");
43
43
  /** The type names `code` spells: each imported type by its simple name, and each capitalized identifier that is not a member access. */
44
44
  export function spelledIn(code) {
45
45
  const text = codeOf(code);
@@ -70,13 +70,14 @@ export function javaNames(schemas, taken, declares) {
70
70
  const base = javaTypeName(name);
71
71
  const taken = scope.has(base);
72
72
  components.set(name, scope.claim(taken ? `${base}Model` : base));
73
- if (taken)
73
+ if (taken) {
74
74
  renamed.push({
75
75
  because: `"${base}" is a name the SDK's runtime, the JDK or another declaration holds`,
76
76
  name,
77
77
  renamed: components.get(name),
78
78
  what: "component",
79
79
  });
80
+ }
80
81
  }
81
82
  const hoisted = new Map();
82
83
  return {
@@ -84,12 +85,13 @@ export function javaNames(schemas, taken, declares) {
84
85
  const schema = schemas[name] ?? UNKNOWN;
85
86
  return declares(schema) ? undefined : schema;
86
87
  },
88
+ has: (name) => scope.has(name),
87
89
  hoist: (key, base) => {
88
90
  const name = hoisted.get(key) ?? scope.claim(base);
89
91
  hoisted.set(key, name);
90
92
  return name;
91
93
  },
92
- /* a ref reaches here only for a declared component: `alias` answers for every other one */
94
+ // a ref reaches here only for a declared component: `alias` answers for every other one
93
95
  ref: (name) => components.get(name),
94
96
  renamed,
95
97
  resolve: irResolver(schemas),
@@ -10,7 +10,6 @@
10
10
  */
11
11
  import type { IRField, IRSchema } from "../../ir/model.ts";
12
12
  import type { JavaTypeContext, Member } from "./models.ts";
13
- export declare const RECORD_MEMBERS: readonly string[];
14
13
  /** A record's members: its fields, and whether it keeps every other member (it declares `additionalProperties`). */
15
14
  export type RecordShape = {
16
15
  readonly fields: readonly IRField[];
@@ -2,8 +2,8 @@ import { javaString } from "../shared/escape.js";
2
2
  import { camelWords, compareCodeUnits, isJavaReserved, NameScope } from "../shared/lang.js";
3
3
  import { typeHeader } from "./layout.js";
4
4
  import { JSON_NODE } from "./models-names.js";
5
- /* every member name a record component collides with: java.lang.Record's and Object's synthesized and final methods */
6
- export const RECORD_MEMBERS = [
5
+ // every member name a record component collides with: java.lang.Record's and Object's synthesized and final methods
6
+ const RECORD_MEMBERS = [
7
7
  "clone",
8
8
  "equals",
9
9
  "finalize",
@@ -16,7 +16,7 @@ export const RECORD_MEMBERS = [
16
16
  ];
17
17
  const NON_NULL = { args: ["JsonInclude.Include.NON_NULL"], name: "JsonInclude" };
18
18
  const NON_EMPTY = { args: ["JsonInclude.Include.NON_EMPTY"], name: "JsonInclude" };
19
- /* a required, non-nullable use of these is written primitive */
19
+ // a required, non-nullable use of these is written primitive
20
20
  const PRIMITIVE = { Boolean: "boolean", Double: "double", Long: "long" };
21
21
  /** Whether an object, or any object part of an allOf (refs followed), declares `additionalProperties`. */
22
22
  export function isOpen(schema, resolve) {
@@ -5,13 +5,17 @@
5
5
  * `<Union><Value>Body`. The nested `Deserializer` (json.ts) dispatches on the discriminator's value. Every permit and
6
6
  * wrapper is `@JsonDeserialize` with no argument; no `@JsonTypeInfo` is ever written.
7
7
  */
8
- import type { IRSchema } from "../../ir/model.ts";
8
+ import type { IRDiscriminator, IRSchema } from "../../ir/model.ts";
9
+ import { type Dispatch } from "./json.ts";
9
10
  import type { JavaTypeContext, Member } from "./models.ts";
10
11
  type Of<K extends IRSchema["kind"]> = Extract<IRSchema, {
11
12
  kind: K;
12
13
  }>;
14
+ type Discriminated = Of<"union"> & {
15
+ discriminator: IRDiscriminator;
16
+ };
13
17
  /** Declares `schema` once under `key` and `base`; its name. */
14
- export type Declare = (schema: IRSchema, key: string, base: string) => string;
18
+ type Declare = (schema: IRSchema, key: string, base: string) => string;
15
19
  /** What a union's declaration reaches: the context, its members' types, and the hoist. */
16
20
  export type UnionScope = {
17
21
  at: JavaTypeContext;
@@ -22,6 +26,13 @@ export type UnionScope = {
22
26
  export declare const isLiteral: (variant: IRSchema) => variant is Of<"const"> & {
23
27
  value: string;
24
28
  };
29
+ /** Whether `union` is keyed on one field, so Java declares it as a sealed interface of wrappers. */
30
+ export declare const isKeyed: (union: Of<"union">) => union is Discriminated;
31
+ /**
32
+ * Each selectable variant's payload, wrapper and selecting values, in the Deserializer's order; the wrappers are
33
+ * declared here, under the same names however often it runs.
34
+ */
35
+ export declare function dispatchOf(name: string, union: Discriminated, scope: UnionScope): Dispatch[];
25
36
  /** The declaration of a union `declares`: a string enum of its const strings, or a discriminated interface. */
26
37
  export declare function unionDecl(name: string, union: Of<"union">, scope: UnionScope): string;
27
38
  export {};
@@ -2,8 +2,8 @@ import { compareCodeUnits, javaTypeName } from "../shared/lang.js";
2
2
  import { deserializerLines } from "./json.js";
3
3
  import { classOf, typeHeader } from "./layout.js";
4
4
  import { enumValues, stringEnumDecl } from "./models-enum.js";
5
- import { fieldsOf } from "./models-record.js";
6
5
  import { JSON_NODE } from "./models-names.js";
6
+ import { fieldsOf } from "./models-record.js";
7
7
  /** Whether a variant is a const string: a union of these alone is a string enum. */
8
8
  export const isLiteral = (variant) => variant.kind === "const" && typeof variant.value === "string";
9
9
  /** The values that select `variant`: its mapping keys, else its property's const or enum, else its ref's name. */
@@ -45,16 +45,22 @@ const wrapperText = (wrapper, union, payload) => typeHeader(0, {
45
45
  modifiers: ["public"],
46
46
  name: wrapper,
47
47
  }).join("\n");
48
- /** Each selectable variant's payload, wrapper and selecting values; the wrappers are declared here. */
49
- function dispatchOf(name, union, scope) {
48
+ /** Whether `union` is keyed on one field, so Java declares it as a sealed interface of wrappers. */
49
+ export const isKeyed = (union) => union.discriminator !== undefined && union.variants.length > 0 && !union.variants.every(isLiteral);
50
+ /**
51
+ * Each selectable variant's payload, wrapper and selecting values, in the Deserializer's order; the wrappers are
52
+ * declared here, under the same names however often it runs.
53
+ */
54
+ export function dispatchOf(name, union, scope) {
50
55
  return selectedBy(union, scope.at).map(({ index, schema, values }) => {
51
56
  const first = values[0] ?? `Variant${index}`;
57
+ const spelled = javaTypeName(first);
52
58
  const payload = schema.kind === "ref"
53
59
  ? scope.member(schema, first)
54
- : scope.declare(schema, `${name}.variant${index}`, `${name}${javaTypeName(first)}Body`);
55
- const wrapper = scope.at.names.hoist(`${name}.wrap${index}`, `${name}${javaTypeName(first)}`);
60
+ : scope.declare(schema, `${name}.variant${index}`, `${name}${spelled}Body`);
61
+ const wrapper = scope.at.names.hoist(`${name}.wrap${index}`, `${name}${spelled}`);
56
62
  scope.at.decls.set(wrapper, wrapperText(wrapper, name, payload));
57
- return { payload, values, wrapper };
63
+ return { payload, spelled, values, wrapper };
58
64
  });
59
65
  }
60
66
  /** The sealed interface of `union`'s wrappers, its nested Deserializer, then the `<Union>Unknown` wrapper. */
@@ -5,8 +5,8 @@
5
5
  * type name is reserved where it collides (models-names.ts).
6
6
  */
7
7
  import type { IR, IRSchema } from "../../ir/model.ts";
8
+ import type { Dispatch } from "./json.ts";
8
9
  import { type JavaTypeNames } from "./models-names.ts";
9
- export type { JavaTypeNames } from "./models-names.ts";
10
10
  /** Where a type is being written, the declarations it hoists, and the names. */
11
11
  export type JavaTypeContext = {
12
12
  parentName: string;
@@ -24,5 +24,9 @@ export declare function javaTypeContext(ir: IR, taken?: readonly string[]): Java
24
24
  export declare function declares(ir: IRSchema): boolean;
25
25
  /** The Java type of `ir` at a use position of `at`. */
26
26
  export declare function javaTypeOf(ir: IRSchema, at: JavaTypeContext): string;
27
+ /** The Java type of `ir` at `at`, a schema that declares hoisted as `<Parent><Field>`: an inline keyed union too. */
28
+ export declare function declaredTypeOf(ir: IRSchema, at: JavaTypeContext): string;
29
+ /** The wrappers of `name`, the keyed union `ir` resolves to, in its Deserializer's order; none when `ir` is not one. */
30
+ export declare function keyedArms(name: string, ir: IRSchema, ctx: JavaTypeContext): readonly Dispatch[];
27
31
  /** The top-level declaration of the type `name` (a Java name already) for `ir`, which `declares`. */
28
32
  export declare function javaTopLevel(name: string, ir: IRSchema, ctx: JavaTypeContext): string;
@@ -1,9 +1,9 @@
1
1
  import { pascalWords, javaTypeName } from "../shared/lang.js";
2
2
  import { enumDecl, enumValues } from "./models-enum.js";
3
- import { fieldsOf, isOpen, recordDecl } from "./models-record.js";
4
3
  import { javaNames, JSON_NODE } from "./models-names.js";
5
- import { isLiteral, unionDecl } from "./models-union.js";
6
- /* deeper than this, a schema is any JSON value */
4
+ import { fieldsOf, isOpen, recordDecl } from "./models-record.js";
5
+ import { dispatchOf, isKeyed, isLiteral, unionDecl } from "./models-union.js";
6
+ // deeper than this, a schema is any JSON value
7
7
  const MAX_DEPTH = 12;
8
8
  const SCALARS = {
9
9
  boolean: "Boolean",
@@ -32,7 +32,7 @@ export function declares(ir) {
32
32
  function declare(ir, at, key, base) {
33
33
  const name = at.names.hoist(key, base);
34
34
  if (!at.decls.has(name)) {
35
- /* claimed before its body: what the body hoists in turn comes after it */
35
+ // claimed before its body: what the body hoists in turn comes after it
36
36
  at.decls.set(name, "");
37
37
  at.decls.set(name, javaTopLevel(name, ir, at));
38
38
  }
@@ -75,44 +75,68 @@ function use(ir, at) {
75
75
  if (at.depth > MAX_DEPTH)
76
76
  return JSON_NODE;
77
77
  switch (ir.kind) {
78
- case "allOf":
78
+ case "allOf": {
79
79
  return allOfUse(ir, at);
80
- case "array":
80
+ }
81
+ case "array": {
81
82
  return `List<${use(ir.items, deeper(at, `${at.fieldName}Item`, "[]"))}>`;
82
- case "binary":
83
+ }
84
+ case "binary": {
83
85
  return "String";
84
- case "const":
86
+ }
87
+ case "const": {
85
88
  return constType(ir);
86
- case "nullable":
89
+ }
90
+ case "nullable": {
87
91
  return use(ir.inner, deeper(at));
88
- case "object":
92
+ }
93
+ case "object": {
89
94
  return objectUse(ir, at);
90
- case "ref":
95
+ }
96
+ case "ref": {
91
97
  return refUse(ir, at);
92
- case "scalar":
98
+ }
99
+ case "scalar": {
93
100
  return enumValues(ir).length > 0 ? hoist(ir, at) : SCALARS[ir.type];
94
- case "tuple":
101
+ }
102
+ case "tuple": {
95
103
  return `List<${JSON_NODE}>`;
96
- /* a union in use position is any JSON value; a component union is declared */
104
+ }
105
+ // a union in use position is any JSON value; a component union is declared
97
106
  case "union":
98
- case "unknown":
107
+ case "unknown": {
99
108
  return JSON_NODE;
109
+ }
100
110
  }
101
111
  }
102
112
  /** The Java type of `ir` at a use position of `at`. */
103
113
  export function javaTypeOf(ir, at) {
104
114
  return use(ir, { ...at, depth: 0, path: "" });
105
115
  }
116
+ /** The Java type of `ir` at `at`, a schema that declares hoisted as `<Parent><Field>`: an inline keyed union too. */
117
+ export function declaredTypeOf(ir, at) {
118
+ return ir.kind !== "ref" && declares(ir) ? hoist(ir, { ...at, depth: 0, path: "" }) : javaTypeOf(ir, at);
119
+ }
120
+ /** The members of the declaration `name` (a Java name already) and what its variants hoist, in `ctx`. */
121
+ const scopeOf = (name, ctx) => ({
122
+ at: ctx,
123
+ declare: (schema, key, base) => declare(schema, ctx, key, base),
124
+ member: (schema, fieldName) => javaTypeOf(schema, { ...ctx, fieldName, parentName: name }),
125
+ });
126
+ /** The wrappers of `name`, the keyed union `ir` resolves to, in its Deserializer's order; none when `ir` is not one. */
127
+ export function keyedArms(name, ir, ctx) {
128
+ const union = ctx.names.resolve(ir);
129
+ return union.kind === "union" && isKeyed(union) ? dispatchOf(name, union, scopeOf(name, ctx)) : [];
130
+ }
106
131
  /** The top-level declaration of the type `name` (a Java name already) for `ir`, which `declares`. */
107
132
  export function javaTopLevel(name, ir, ctx) {
108
- const member = (schema, fieldName) => javaTypeOf(schema, { ...ctx, fieldName, parentName: name });
133
+ const scope = scopeOf(name, ctx);
109
134
  if (ir.kind === "scalar")
110
135
  return enumDecl(name, ir);
111
136
  const open = isOpen(ir, ctx.names.resolve);
112
137
  if (ir.kind === "object")
113
- return recordDecl(name, { fields: ir.fields, open }, member, ctx);
138
+ return recordDecl(name, { fields: ir.fields, open }, scope.member, ctx);
114
139
  if (ir.kind === "allOf")
115
- return recordDecl(name, { fields: fieldsOf(ir, ctx.names.resolve), open }, member, ctx);
116
- const declareVariant = (schema, key, base) => declare(schema, ctx, key, base);
117
- return unionDecl(name, ir, { at: ctx, declare: declareVariant, member });
140
+ return recordDecl(name, { fields: fieldsOf(ir, ctx.names.resolve), open }, scope.member, ctx);
141
+ return unionDecl(name, ir, scope);
118
142
  }