@workerstack/clients 1.0.0-rc.29 → 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 (291) hide show
  1. package/README.md +373 -14
  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 +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 +0 -1
  37. package/dist/emit/csharp/sdk-method.js +10 -6
  38. package/dist/emit/csharp/sdk-plan.js +0 -1
  39. package/dist/emit/csharp/sdk.js +3 -3
  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.js +2 -2
  58. package/dist/emit/go/sdk-mirror.js +2 -2
  59. package/dist/emit/go/sdk-opts.d.ts +0 -2
  60. package/dist/emit/go/sdk-opts.js +3 -3
  61. package/dist/emit/go/sdk.d.ts +1 -1
  62. package/dist/emit/go/sdk.js +9 -9
  63. package/dist/emit/go/sse.js +1 -1
  64. package/dist/emit/go/types-names.js +5 -0
  65. package/dist/emit/go/types-struct.d.ts +2 -1
  66. package/dist/emit/go/types-struct.js +1 -1
  67. package/dist/emit/go/types.js +9 -9
  68. package/dist/emit/go/ws.js +6 -6
  69. package/dist/emit/java/gradle.d.ts +7 -9
  70. package/dist/emit/java/gradle.js +8 -8
  71. package/dist/emit/java/json.js +1 -1
  72. package/dist/emit/java/layout-ast.js +1 -1
  73. package/dist/emit/java/layout-decl.js +5 -4
  74. package/dist/emit/java/layout-doc.js +13 -7
  75. package/dist/emit/java/layout-dot.js +1 -1
  76. package/dist/emit/java/layout-strings.js +4 -5
  77. package/dist/emit/java/layout-types.js +7 -5
  78. package/dist/emit/java/layout-visitor.js +4 -3
  79. package/dist/emit/java/layout.js +5 -4
  80. package/dist/emit/java/models-names.js +5 -4
  81. package/dist/emit/java/models-record.d.ts +0 -1
  82. package/dist/emit/java/models-record.js +3 -3
  83. package/dist/emit/java/models-union.d.ts +1 -1
  84. package/dist/emit/java/models-union.js +1 -1
  85. package/dist/emit/java/models.d.ts +1 -2
  86. package/dist/emit/java/models.js +25 -16
  87. package/dist/emit/java/realtime.d.ts +5 -17
  88. package/dist/emit/java/realtime.js +1 -1
  89. package/dist/emit/java/sdk-client.d.ts +6 -6
  90. package/dist/emit/java/sdk-client.js +1 -1
  91. package/dist/emit/java/sdk-decl.js +2 -2
  92. package/dist/emit/java/sdk-errors.js +1 -1
  93. package/dist/emit/java/sdk-headers.js +2 -2
  94. package/dist/emit/java/sdk-mirror.js +2 -2
  95. package/dist/emit/java/sdk-models.d.ts +1 -1
  96. package/dist/emit/java/sdk-models.js +7 -7
  97. package/dist/emit/java/sdk-op.d.ts +1 -10
  98. package/dist/emit/java/sdk-op.js +8 -8
  99. package/dist/emit/java/sdk-params.d.ts +5 -5
  100. package/dist/emit/java/sdk-params.js +3 -2
  101. package/dist/emit/java/sdk-plan.js +0 -1
  102. package/dist/emit/java/sdk.d.ts +1 -1
  103. package/dist/emit/java/sdk.js +14 -13
  104. package/dist/emit/java/sse.d.ts +2 -4
  105. package/dist/emit/java/sse.js +6 -6
  106. package/dist/emit/java/ws.d.ts +2 -2
  107. package/dist/emit/java/ws.js +3 -4
  108. package/dist/emit/mcp/annotations.js +8 -4
  109. package/dist/emit/mcp/files.js +9 -9
  110. package/dist/emit/mcp/mounted.js +2 -2
  111. package/dist/emit/mcp/output-schema.js +3 -3
  112. package/dist/emit/mcp/registry.d.ts +0 -2
  113. package/dist/emit/mcp/registry.js +5 -4
  114. package/dist/emit/mcp/runtime.js +2 -2
  115. package/dist/emit/mcp/schema.js +22 -11
  116. package/dist/emit/mcp/server.d.ts +7 -7
  117. package/dist/emit/mcp/server.js +7 -6
  118. package/dist/emit/mcp/tools.js +7 -6
  119. package/dist/emit/python/errors.js +3 -3
  120. package/dist/emit/python/realtime.js +2 -2
  121. package/dist/emit/python/sdk-answer.d.ts +3 -7
  122. package/dist/emit/python/sdk-answer.js +2 -2
  123. package/dist/emit/python/sdk-body.js +4 -5
  124. package/dist/emit/python/sdk-client.js +5 -5
  125. package/dist/emit/python/sdk-doc.js +2 -2
  126. package/dist/emit/python/sdk-method.js +5 -5
  127. package/dist/emit/python/sdk-plan.js +0 -1
  128. package/dist/emit/python/sdk-pyproject.d.ts +0 -2
  129. package/dist/emit/python/sdk-pyproject.js +8 -8
  130. package/dist/emit/python/sdk.d.ts +1 -1
  131. package/dist/emit/python/sdk.js +7 -7
  132. package/dist/emit/python/sse.d.ts +0 -2
  133. package/dist/emit/python/sse.js +2 -2
  134. package/dist/emit/python/transport.js +4 -4
  135. package/dist/emit/python/types-dict.d.ts +2 -2
  136. package/dist/emit/python/types-dict.js +1 -1
  137. package/dist/emit/python/types-names.js +2 -2
  138. package/dist/emit/python/types-union.js +1 -1
  139. package/dist/emit/python/types.js +3 -3
  140. package/dist/emit/python/ws.d.ts +2 -5
  141. package/dist/emit/python/ws.js +4 -4
  142. package/dist/emit/rust/errors.js +3 -3
  143. package/dist/emit/rust/http.js +4 -4
  144. package/dist/emit/rust/realtime.js +2 -2
  145. package/dist/emit/rust/sdk-body.js +8 -5
  146. package/dist/emit/rust/sdk-cargo.d.ts +16 -18
  147. package/dist/emit/rust/sdk-cargo.js +12 -12
  148. package/dist/emit/rust/sdk-client.d.ts +1 -1
  149. package/dist/emit/rust/sdk-client.js +3 -3
  150. package/dist/emit/rust/sdk-method.js +2 -2
  151. package/dist/emit/rust/sdk-opts.d.ts +2 -1
  152. package/dist/emit/rust/sdk-opts.js +2 -2
  153. package/dist/emit/rust/sdk-plan.js +0 -1
  154. package/dist/emit/rust/sdk.d.ts +1 -1
  155. package/dist/emit/rust/sdk.js +5 -5
  156. package/dist/emit/rust/sse.d.ts +0 -5
  157. package/dist/emit/rust/sse.js +2 -2
  158. package/dist/emit/rust/types-names.js +3 -3
  159. package/dist/emit/rust/types-struct.js +1 -1
  160. package/dist/emit/rust/types-union.d.ts +1 -1
  161. package/dist/emit/rust/types.js +7 -5
  162. package/dist/emit/rust/ws.d.ts +0 -11
  163. package/dist/emit/rust/ws.js +5 -5
  164. package/dist/emit/shared/escape.js +17 -17
  165. package/dist/emit/shared/format.js +1 -1
  166. package/dist/emit/shared/gofmt.js +1 -1
  167. package/dist/emit/shared/lang.js +10 -10
  168. package/dist/emit/shared/literals.d.ts +5 -0
  169. package/dist/emit/shared/literals.js +8 -0
  170. package/dist/emit/shared/metadata.d.ts +0 -6
  171. package/dist/emit/shared/metadata.js +8 -7
  172. package/dist/emit/shared/ruff.js +1 -1
  173. package/dist/emit/shared/rustfmt.js +1 -1
  174. package/dist/emit/shared/type-emitter.js +37 -20
  175. package/dist/emit/shared/unknown-type.constants.d.ts +2 -0
  176. package/dist/emit/shared/unknown-type.constants.js +2 -0
  177. package/dist/emit/ts/http.d.ts +0 -2
  178. package/dist/emit/ts/http.js +4 -4
  179. package/dist/emit/ts/package.d.ts +14 -12
  180. package/dist/emit/ts/package.js +9 -8
  181. package/dist/emit/ts/route-tree.js +2 -2
  182. package/dist/emit/ts/sdk-types-preamble.d.ts +1 -1
  183. package/dist/emit/ts/sdk-types-preamble.js +2 -2
  184. package/dist/emit/ts/sdk-types.js +11 -11
  185. package/dist/emit/ts/sdk.js +4 -4
  186. package/dist/emit/ts/service-map.d.ts +2 -1
  187. package/dist/emit/ts/tanstack-query.js +6 -6
  188. package/dist/emit/ts/type-gen.js +31 -18
  189. package/dist/emit/ts/webhooks.d.ts +0 -2
  190. package/dist/emit/ts/webhooks.js +3 -3
  191. package/dist/extract/chain.js +5 -4
  192. package/dist/extract/extract.js +5 -5
  193. package/dist/extract/serialize.d.ts +0 -2
  194. package/dist/extract/serialize.js +14 -15
  195. package/dist/extract/walk.js +15 -12
  196. package/dist/gen/args.js +9 -5
  197. package/dist/gen/formatters.js +5 -3
  198. package/dist/gen/shipped.js +2 -2
  199. package/dist/gen/targets.d.ts +2 -4
  200. package/dist/gen/targets.js +8 -4
  201. package/dist/gen/write.js +4 -2
  202. package/dist/index.js +2 -2
  203. package/dist/installers/cli.d.ts +4 -4
  204. package/dist/installers/cli.js +24 -24
  205. package/dist/installers/commands/build.d.ts +4 -4
  206. package/dist/installers/commands/build.js +2 -3
  207. package/dist/installers/commands/check.d.ts +2 -2
  208. package/dist/installers/commands/check.js +11 -10
  209. package/dist/installers/commands/init.d.ts +2 -2
  210. package/dist/installers/commands/init.js +1 -2
  211. package/dist/installers/config/define-config.d.ts +16 -16
  212. package/dist/installers/config/define-config.js +1 -1
  213. package/dist/installers/config/hooks/bun.d.ts +6 -6
  214. package/dist/installers/config/hooks/node.js +1 -1
  215. package/dist/installers/config/load.d.ts +6 -8
  216. package/dist/installers/config/load.js +7 -8
  217. package/dist/installers/config/resolve.d.ts +1 -2
  218. package/dist/installers/config/resolve.js +28 -33
  219. package/dist/installers/config/types.d.ts +6 -6
  220. package/dist/installers/config/types.js +0 -1
  221. package/dist/installers/render/quote.js +3 -5
  222. package/dist/installers/render/render.d.ts +6 -6
  223. package/dist/installers/render/render.js +26 -26
  224. package/dist/installers/ui.d.ts +4 -4
  225. package/dist/installers/ui.js +3 -3
  226. package/dist/ir/build.d.ts +3 -3
  227. package/dist/ir/build.js +8 -5
  228. package/dist/ir/load.js +9 -10
  229. package/dist/ir/model.d.ts +2 -1
  230. package/dist/ir/model.js +0 -1
  231. package/dist/ir/resolve-refs.js +2 -2
  232. package/dist/ir/resource-tree.js +2 -1
  233. package/dist/ir/route-tree-intern.js +1 -1
  234. package/dist/ir/schema.js +3 -3
  235. package/dist/ir/sdk-model.js +3 -3
  236. package/dist/ir/slots.js +13 -8
  237. package/dist/ir/streams.js +1 -1
  238. package/dist/release/bootstrap.d.ts +3 -3
  239. package/dist/release/bootstrap.js +7 -7
  240. package/dist/release/bump-args.js +4 -4
  241. package/dist/release/bump-command.d.ts +1 -1
  242. package/dist/release/bump-command.js +9 -10
  243. package/dist/release/bump.d.ts +5 -4
  244. package/dist/release/bump.js +2 -2
  245. package/dist/release/cli.d.ts +4 -4
  246. package/dist/release/cli.js +4 -4
  247. package/dist/release/codegen.js +1 -1
  248. package/dist/release/digest.js +5 -7
  249. package/dist/release/git.js +5 -8
  250. package/dist/release/load.js +3 -3
  251. package/dist/release/manifest.js +9 -10
  252. package/dist/release/oasdiff.d.ts +10 -15
  253. package/dist/release/oasdiff.js +5 -6
  254. package/dist/release/registries.d.ts +0 -11
  255. package/dist/release/registries.js +17 -17
  256. package/dist/release/release-state.d.ts +16 -13
  257. package/dist/release/release-workflow.js +5 -7
  258. package/dist/release/repo-settings.d.ts +2 -1
  259. package/dist/release/spec-gate.d.ts +0 -2
  260. package/dist/release/spec-gate.js +6 -10
  261. package/dist/release/sync-command.d.ts +2 -2
  262. package/dist/release/sync-command.js +1 -1
  263. package/dist/release/sync-tree.js +9 -13
  264. package/dist/release/sync.d.ts +6 -6
  265. package/dist/release/sync.js +12 -13
  266. package/dist/release/types.d.ts +22 -22
  267. package/dist/release/types.js +0 -1
  268. package/dist/release/version-files.d.ts +3 -4
  269. package/dist/release/version-files.js +4 -5
  270. package/dist/runtime/.oxfmtrc.jsonc +8 -0
  271. package/dist/runtime/mcp/files.ts +1 -1
  272. package/dist/runtime/mcp/http.ts +6 -2
  273. package/dist/runtime/mcp/listen.ts +1 -1
  274. package/dist/runtime/mcp/mount.ts +2 -2
  275. package/dist/runtime/mcp/protocol.ts +1 -1
  276. package/dist/runtime/ts-tanstack-query/query.ts +0 -2
  277. package/package.json +10 -7
  278. package/dist/emit/cli/index.d.ts +0 -1
  279. package/dist/emit/cli/index.js +0 -1
  280. package/dist/emit/csharp/index.d.ts +0 -1
  281. package/dist/emit/csharp/index.js +0 -1
  282. package/dist/emit/go/index.d.ts +0 -1
  283. package/dist/emit/go/index.js +0 -1
  284. package/dist/emit/java/index.d.ts +0 -2
  285. package/dist/emit/java/index.js +0 -2
  286. package/dist/emit/mcp/index.d.ts +0 -3
  287. package/dist/emit/mcp/index.js +0 -3
  288. package/dist/emit/python/index.d.ts +0 -1
  289. package/dist/emit/python/index.js +0 -1
  290. package/dist/emit/rust/index.d.ts +0 -1
  291. package/dist/emit/rust/index.js +0 -1
@@ -4,12 +4,12 @@ import { NameScope, rustTypeIdent } from "../shared/lang.js";
4
4
  import { typeAt } from "./sdk-body.js";
5
5
  import { variantOf } from "./types-enum.js";
6
6
  /** The resume cursor's id, which the SSE and realtime Opts carry. */
7
- export const LAST_EVENT_ID = { ident: "last_event_id", type: "Option<String>" };
7
+ const LAST_EVENT_ID = { ident: "last_event_id", type: "Option<String>" };
8
8
  /** Whether a declared param is the Last-Event-ID header (any casing), the resume channel an SSE dial sends. */
9
9
  export const isLastEventIdHeader = (param, where) => where === "header" && param.toLowerCase() === "last-event-id";
10
10
  /** The type of the events `op` declares as `events`. */
11
11
  export const eventType = (op, events, at) => typeAt(events, op.id, "Event", at);
12
- /* Last-Event-ID, sent only when set: an empty cursor names no position */
12
+ // Last-Event-ID, sent only when set: an empty cursor names no position
13
13
  const SSE = {
14
14
  carries: isLastEventIdHeader,
15
15
  fields: [LAST_EVENT_ID],
@@ -14,7 +14,7 @@ function runtimeIdentifiers() {
14
14
  }
15
15
  /** The style parameter every resource and its methods' `Call` take (bit 21 i4): no type may be named it. */
16
16
  export const STYLE = "S";
17
- /* the crate-root types the emitter itself declares beside the runtime's (errors.ts's enum), and the style parameter */
17
+ // the crate-root types the emitter itself declares beside the runtime's (errors.ts's enum), and the style parameter
18
18
  const EMITTED = ["ErrorKey", STYLE];
19
19
  /** Names for one schema on its own: each as asked for, no cycles, refs left unresolved. */
20
20
  export function plainNames() {
@@ -22,8 +22,8 @@ export function plainNames() {
22
22
  claim: (base) => base,
23
23
  cyclic: new Set(),
24
24
  hoist: (_key, base) => base,
25
- renamed: new Map(),
26
25
  ref: rustTypeIdent,
26
+ renamed: new Map(),
27
27
  resolve: (schema) => schema,
28
28
  };
29
29
  }
@@ -45,7 +45,7 @@ export function irNames(ir) {
45
45
  if (taken)
46
46
  renamed.set(name, claimed);
47
47
  }
48
- /* a joined name can spell a prelude one (`Hash` + `map`): that one is taken too, so the claim moves on */
48
+ // a joined name can spell a prelude one (`Hash` + `map`): that one is taken too, so the claim moves on
49
49
  const claim = (base) => {
50
50
  const name = scope.claim(base);
51
51
  return isRustPreludeType(name) ? scope.claim(base) : name;
@@ -2,7 +2,7 @@ import { rustString } from "../shared/escape.js";
2
2
  import { compareCodeUnits, NameScope, rustValueIdent } from "../shared/lang.js";
3
3
  export const DERIVE = "#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]";
4
4
  const SKIP = 'skip_serializing_if = "Option::is_none"';
5
- /* absent, null and a value: `default` for absent, the runtime's deserializer keeping null as Some(None) */
5
+ // absent, null and a value: `default` for absent, the runtime's deserializer keeping null as Some(None)
6
6
  const TRI_STATE = ["default", 'deserialize_with = "crate::nullable::deserialize"', SKIP];
7
7
  /** A field's lines: its serde keys in one attribute when it has any, then `pub <ident>: <type>,`. */
8
8
  const fieldLines = ({ ident, type, serde }) => [
@@ -12,7 +12,7 @@ type Of<K extends IRSchema["kind"]> = Extract<IRSchema, {
12
12
  kind: K;
13
13
  }>;
14
14
  /** Declares `schema` once under `names.hoist(key, base)`; its name. */
15
- export type Declare = (schema: IRSchema, key: string, base: string) => string;
15
+ type Declare = (schema: IRSchema, key: string, base: string) => string;
16
16
  /** What a union's declaration reaches: the names, its members' types, and the hoist. */
17
17
  export type UnionScope = {
18
18
  names: RustTypeNames;
@@ -5,7 +5,7 @@ import { allOfDecl, DERIVE, objectDecl, unboxed } from "./types-struct.js";
5
5
  import { unionDecl, unionVariants } from "./types-union.js";
6
6
  const VALUE = "serde_json::Value";
7
7
  const MAP = "std::collections::HashMap";
8
- /* deeper than this, a schema is any JSON value */
8
+ // deeper than this, a schema is any JSON value
9
9
  const MAX_DEPTH = 12;
10
10
  const SCALARS = {
11
11
  boolean: "bool",
@@ -22,7 +22,7 @@ export function rustTypeContext(ir) {
22
22
  export function rustHoisted(ir, at, key, base) {
23
23
  const name = at.names.hoist(key, base);
24
24
  if (!at.decls.has(name)) {
25
- /* claimed before its body: what the body hoists in turn comes after it */
25
+ // claimed before its body: what the body hoists in turn comes after it
26
26
  at.decls.set(name, "");
27
27
  at.decls.set(name, rustTopLevel(name, ir, at));
28
28
  }
@@ -33,7 +33,9 @@ const hoist = (ir, at) => rustHoisted(ir, at, `${at.parentName}.${at.fieldName}`
33
33
  const deeper = (at, fieldName = at.fieldName) => ({ ...at, depth: at.depth + 1, fieldName });
34
34
  /** Whether a scalar is a string or integer enum with a value of its kind: a declared enum. */
35
35
  const isEnum = (ir) => ir.enum !== undefined &&
36
- (ir.type === "string" ? stringValues(ir.enum).length > 0 : ir.type === "integer" && integerValues(ir.enum).length > 0);
36
+ (ir.type === "string"
37
+ ? stringValues(ir.enum).length > 0
38
+ : ir.type === "integer" && integerValues(ir.enum).length > 0);
37
39
  /** A const's Rust type: its value's, a declared `number` making an integral value f64. */
38
40
  function constType({ type, value }) {
39
41
  if (typeof value === "number")
@@ -70,7 +72,7 @@ const USES = {
70
72
  ref: refUse,
71
73
  scalar: (ir, at) => (isEnum(ir) ? hoist(ir, at) : SCALARS[ir.type]),
72
74
  tuple: () => `Vec<${VALUE}>`,
73
- /* a union in use position is any JSON value; a component union is declared as an enum */
75
+ // a union in use position is any JSON value; a component union is declared as an enum
74
76
  union: () => VALUE,
75
77
  unknown: () => VALUE,
76
78
  };
@@ -102,7 +104,7 @@ export function rustTopLevel(name, ir, at) {
102
104
  return [DERIVE, `pub struct ${name}(pub ${constType(ir)});`].join("\n");
103
105
  if (ir.kind === "allOf")
104
106
  return allOfDecl(name, ir, member, at.names.ref);
105
- /* a closed object without fields is a struct too: `{}` on the wire, where a map alias would admit any key */
107
+ // a closed object without fields is a struct too: `{}` on the wire, where a map alias would admit any key
106
108
  if (ir.kind === "object" && (ir.fields.length > 0 || ir.additional === false))
107
109
  return objectDecl(name, ir, member);
108
110
  if (ir.kind === "union" && ir.variants.length > 0)
@@ -10,17 +10,6 @@ import type { IRSchema } from "../../ir/model.ts";
10
10
  import { type SdkOp } from "../../ir/sdk-model.ts";
11
11
  import type { OptsField, StreamAnswer } from "./sdk-opts.ts";
12
12
  import { type RustTypeContext } from "./types.ts";
13
- /** The resume cursor's token, which the WebSocket and realtime Opts carry. */
14
- export declare const RECONNECT_TOKEN: {
15
- ident: string;
16
- type: string;
17
- };
18
- /** The subprotocols a WebSocket or realtime dial offers. */
19
- export declare const PROTOCOLS: {
20
- doc: string;
21
- ident: string;
22
- type: string;
23
- };
24
13
  /** Whether a declared param is the `reconnect_token` query param, the resume channel a socket dial sends. */
25
14
  export declare const isReconnectToken: (param: string, where: OptsField["in"]) => boolean;
26
15
  /** One direction of `op`'s messages as its Rust type: an inline union is declared as `<Op><side>`. */
@@ -4,12 +4,12 @@ import { NameScope, rustTypeIdent, rustValueIdent } from "../shared/lang.js";
4
4
  import { typeAt } from "./sdk-body.js";
5
5
  import { rustHoisted, rustUnionVariants } from "./types.js";
6
6
  /** The resume cursor's token, which the WebSocket and realtime Opts carry. */
7
- export const RECONNECT_TOKEN = { ident: "reconnect_token", type: "Option<String>" };
7
+ const RECONNECT_TOKEN = { ident: "reconnect_token", type: "Option<String>" };
8
8
  /** The subprotocols a WebSocket or realtime dial offers. */
9
- export const PROTOCOLS = { doc: "The subprotocols the dial offers.", ident: "protocols", type: "Vec<String>" };
9
+ const PROTOCOLS = { doc: "The subprotocols the dial offers.", ident: "protocols", type: "Vec<String>" };
10
10
  /** Whether a declared param is the `reconnect_token` query param, the resume channel a socket dial sends. */
11
11
  export const isReconnectToken = (param, where) => where === "query" && param === "reconnect_token";
12
- /* reconnect_token, sent only when set: an empty cursor names no position */
12
+ // reconnect_token, sent only when set: an empty cursor names no position
13
13
  const WS = {
14
14
  carries: isReconnectToken,
15
15
  fields: [RECONNECT_TOKEN, PROTOCOLS],
@@ -54,7 +54,7 @@ export function valueHandlers(base, handlers, read, at) {
54
54
  }
55
55
  /** The type params of a socket reading `read` and sending `write`, the defaults left out. */
56
56
  export const typeParams = (read, write, untyped) => write === undefined ? (read === undefined ? "" : `<${read}>`) : `<${read ?? untyped}, ${write}>`;
57
- /* the handlers a socket takes: a member whose on_<value> one of them names gets none */
57
+ // the handlers a socket takes: a member whose on_<value> one of them names gets none
58
58
  const HANDLERS = ["on_message", "on_close", "on_error"];
59
59
  /** The WebSocket operation `op`'s answer, its message types hoisted into `at`. */
60
60
  export function wsAnswer(op, at) {
@@ -64,7 +64,7 @@ export function wsAnswer(op, at) {
64
64
  if (send !== undefined && read !== undefined)
65
65
  valueHandlers("TypedWebSocket", HANDLERS, { schema: send, type: read }, at);
66
66
  const params = typeParams(read, write, "Vec<u8>");
67
- /* the answer type fixes both params: a socket without a read type reads bytes */
67
+ // the answer type fixes both params: a socket without a read type reads bytes
68
68
  const run = `crate::ws::${read === undefined ? "dial" : "typed"}(opts.protocols.clone())`;
69
69
  return { doc: DOC, run, stream: WS, type: `TypedWebSocket${params}` };
70
70
  }
@@ -6,7 +6,7 @@
6
6
  */
7
7
  /** `text` with each unpaired UTF-16 surrogate as U+FFFD: no target can carry a lone surrogate to the wire. */
8
8
  export function wellFormed(text) {
9
- return text.replace(/[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]/g, "\uFFFD");
9
+ return text.replaceAll(/[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]/g, "\uFFFD");
10
10
  }
11
11
  const hex = (cp, width) => cp.toString(16).padStart(width, "0");
12
12
  /**
@@ -19,10 +19,10 @@ export const invisible = (cp) => (cp >= 0x80 && cp <= 0x9f) ||
19
19
  cp === 0x200f ||
20
20
  (cp >= 0x202a && cp <= 0x202e) ||
21
21
  (cp >= 0x2066 && cp <= 0x2069);
22
- /* the escapes every target spells alike */
23
- const NAMED = { 0x09: "\\t", 0x0a: "\\n", 0x0d: "\\r", 0x22: '\\"', 0x5c: "\\\\" };
22
+ // the escapes every target spells alike
23
+ const NAMED = { 0x0a: "\\n", 0x0d: "\\r", 0x22: '\\"', 0x09: "\\t", 0x5c: "\\\\" };
24
24
  const POLICIES = {
25
- /* C#'s \x takes one to four hex digits, so it is never written: \uHHHH, fixed width, for every escape */
25
+ // C#'s \x takes one to four hex digits, so it is never written: \uHHHH, fixed width, for every escape
26
26
  csharp: (cp) => cp < 0x20 || cp === 0x7f || cp === 0x2028 || cp === 0x2029 || cp === 0xfeff || invisible(cp)
27
27
  ? `\\u${hex(cp, 4)}`
28
28
  : null,
@@ -31,13 +31,13 @@ const POLICIES = {
31
31
  return `\\x${hex(cp, 2)}`;
32
32
  return cp === 0xfeff || invisible(cp) ? `\\u${hex(cp, 4)}` : null;
33
33
  },
34
- /* Java has no \x: \uHHHH for every other control, DEL and the BOM. The apostrophe stays raw: javac takes it in
35
- * "…", and the backslash's own escape keeps every \u in the text from becoming one (JLS 3.3) */
34
+ // Java has no \x: \uHHHH for every other control, DEL and the BOM. The apostrophe stays raw: javac takes it in
35
+ // "…", and the backslash's own escape keeps every \u in the text from becoming one (JLS 3.3)
36
36
  java: (cp) => (cp < 0x20 || cp === 0x7f || cp === 0xfeff || invisible(cp) ? `\\u${hex(cp, 4)}` : null),
37
37
  python: (cp) => {
38
38
  if (cp < 0x20 || cp === 0x7f)
39
39
  return `\\x${hex(cp, 2)}`;
40
- /* line separators and the BOM read as line ends or vanish in some tools: never raw */
40
+ // line separators and the BOM read as line ends or vanish in some tools: never raw
41
41
  return cp === 0x2028 || cp === 0x2029 || cp === 0xfeff || invisible(cp) ? `\\u${hex(cp, 4)}` : null;
42
42
  },
43
43
  rust: (cp) => {
@@ -89,8 +89,8 @@ export function commentText(text) {
89
89
  }
90
90
  return out;
91
91
  }
92
- /* every line break a comment writer splits at: a C# or JS lexer ends a line at U+2028 and U+2029 too (U+0085, C1,
93
- never reaches a writer raw: commentText shows it) */
92
+ // every line break a comment writer splits at: a C# or JS lexer ends a line at U+2028 and U+2029 too (U+0085, C1,
93
+ // never reaches a writer raw: commentText shows it)
94
94
  const LINE_BREAKS = /\r\n|\r|\n|\u2028|\u2029/;
95
95
  /** Comment lines of `text` behind `marker` (`//`, `///`, `#`): each line break in it starts a new comment line. */
96
96
  export function lineComment(text, marker, indent = "") {
@@ -100,13 +100,13 @@ export function lineComment(text, marker, indent = "") {
100
100
  }
101
101
  /** Text that stays inside a `/* … *\/` comment. */
102
102
  export function blockCommentText(text) {
103
- return commentText(text).replace(/\*\//g, "* /").replace(/\/\*/g, "/ *");
103
+ return commentText(text).replaceAll("*/", "* /").replaceAll("/*", "/ *");
104
104
  }
105
105
  /** Docstring body lines: backslashes and quotes escaped, so `"""`, a trailing `"` and `C:\users` are inert. */
106
106
  export function pyDocLines(text) {
107
107
  return commentText(text)
108
108
  .split(LINE_BREAKS)
109
- .map((line) => line.replace(/\\/g, "\\\\").replace(/"/g, '\\"'));
109
+ .map((line) => line.replaceAll("\\", "\\\\").replaceAll('"', '\\"'));
110
110
  }
111
111
  /**
112
112
  * XML doc text lines (C#'s `///`): split at every line break, `&`, `<` and `>` as entities, and U+FFFE and U+FFFF,
@@ -114,9 +114,9 @@ export function pyDocLines(text) {
114
114
  */
115
115
  export function csDocLines(text) {
116
116
  return commentText(text)
117
- .replace(/[\uFFFE\uFFFF]/g, (ch) => `\\u${hex(ch.codePointAt(0), 4)}`)
117
+ .replaceAll(/[\uFFFE\uFFFF]/g, (ch) => `\\u${hex(ch.codePointAt(0), 4)}`)
118
118
  .split(LINE_BREAKS)
119
- .map((line) => line.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;"));
119
+ .map((line) => line.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;"));
120
120
  }
121
121
  /**
122
122
  * Comment text for Java: javac turns an eligible `\uXXXX` into its character in ANY source text before it lexes
@@ -124,7 +124,7 @@ export function csDocLines(text) {
124
124
  * backslashes before a `u` is doubled, which leaves none of them eligible; `commentText` then shows the hidden
125
125
  * characters as escapes it means javac to read.
126
126
  */
127
- export const javaCommentText = (text) => commentText(wellFormed(text).replace(/\\+(?=u)/g, (run) => run + run));
127
+ export const javaCommentText = (text) => commentText(wellFormed(text).replaceAll(/\\+(?=u)/g, (run) => run + run));
128
128
  /** Java `//` lines of `text`: each line break starts a new line, the `\u` rule kept. */
129
129
  export function javaLineComment(text, indent = "") {
130
130
  return javaCommentText(text)
@@ -137,8 +137,8 @@ export function javaLineComment(text, indent = "") {
137
137
  */
138
138
  export function javaDocLines(text) {
139
139
  return javaCommentText(text)
140
- .replace(/\*\//g, "* /")
141
- .replace(/\/\*/g, "/ *")
140
+ .replaceAll("*/", "* /")
141
+ .replaceAll("/*", "/ *")
142
142
  .split(LINE_BREAKS)
143
- .map((line) => line.replace(/^(\s*)@/, "$1&#64;").replace(/\{@/g, "{&#64;"));
143
+ .map((line) => line.replace(/^(\s*)@/, "$1&#64;").replaceAll("{@", "{&#64;"));
144
144
  }
@@ -14,7 +14,7 @@ export async function formatFiles(files, formatters) {
14
14
  if (formatter === undefined)
15
15
  continue;
16
16
  const { code, errors } = await formatter(name, text, EMIT_STYLE);
17
- /* an emitter wrote text that does not parse: a bug to surface, never a file to write */
17
+ // an emitter wrote text that does not parse: a bug to surface, never a file to write
18
18
  if (errors.length > 0)
19
19
  throw new Error(`could not format ${name}: ${JSON.stringify(errors[0])}`);
20
20
  out[name] = code;
@@ -19,7 +19,7 @@ export function gofmtFormatter(gofmt) {
19
19
  child.on("error", (error) => resolve({ code: source, errors: [error.message] }));
20
20
  child.on("close", (status) => resolve(status === 0 ? { code: stdout, errors: [] } : { code: source, errors: [stderr.trim()] }));
21
21
  child.stdin.on("error", () => {
22
- /* a gofmt that never started: its spawn error answers */
22
+ // a gofmt that never started: its spawn error answers
23
23
  });
24
24
  child.stdin.end(source);
25
25
  });
@@ -11,8 +11,8 @@ export function compareCodeUnits(a, b) {
11
11
  /** The ASCII alphanumeric words of `raw`: `user-id`, `user_id` and `userId` are all [user, id]. */
12
12
  export function words(raw) {
13
13
  return raw
14
- .replace(/([a-z0-9])([A-Z])/g, "$1 $2")
15
- .replace(/([A-Z]+)([A-Z][a-z])/g, "$1 $2")
14
+ .replaceAll(/([a-z0-9])([A-Z])/g, "$1 $2")
15
+ .replaceAll(/([A-Z]+)([A-Z][a-z])/g, "$1 $2")
16
16
  .split(/[^A-Za-z0-9]+/)
17
17
  .filter((word) => word.length > 0);
18
18
  }
@@ -78,22 +78,22 @@ export class NameTable {
78
78
  /** Whether `word` is one of the space-separated `list`. */
79
79
  const listed = (list, word) => ` ${list} `.includes(` ${word} `);
80
80
  const GO_RESERVED =
81
- /* keywords */
81
+ // keywords
82
82
  "break case chan const continue default defer else fallthrough for func go goto if import interface map package range return select struct switch type var " +
83
- /* predeclared identifiers */
83
+ // predeclared identifiers
84
84
  "any append bool byte cap clear close comparable complex complex128 complex64 copy delete error false float32 float64 imag int int16 int32 int64 int8 iota len make max min new nil panic print println real recover rune string true uint uint16 uint32 uint64 uint8 uintptr " +
85
- /* the packages generated Go imports */
85
+ // the packages generated Go imports
86
86
  "bytes context errors fmt http io iter json multipart os slices strconv strings sync textproto time url websocket cobra cli sdk";
87
87
  const RUST_KEYWORDS = "as break const continue crate else enum extern false fn for if impl in let loop match mod move mut pub ref return self Self static struct super trait true type unsafe use where while async await dyn abstract become box do final macro override priv typeof unsized virtual yield try gen";
88
- /* keywords that cannot be raw identifiers: `r#self` is invalid */
88
+ // keywords that cannot be raw identifiers: `r#self` is invalid
89
89
  const RUST_NON_RAW = "crate self Self super extern _";
90
90
  const RUST_PRELUDE = "Box Clone Copy Default Drop Eq Err Fn From HashMap Into Iterator None Ok Option Ord PartialEq PartialOrd Result Send Sized Some String Sync ToOwned ToString Vec Deserialize Serialize Deserialize_repr Serialize_repr Stream Arc";
91
91
  const PY_RESERVED = "False None True and as assert async await break class continue def del elif else except finally for from global if import in is lambda nonlocal not or pass raise return try while with yield " +
92
- /* soft keywords and names generated code relies on */
92
+ // soft keywords and names generated code relies on
93
93
  "match case type _ self cls";
94
- /* C#'s 77 reserved keywords (contract 45 §4.1): no identifier may be one unless `@`-escaped */
94
+ // C#'s 77 reserved keywords (contract 45 §4.1): no identifier may be one unless `@`-escaped
95
95
  const CS_RESERVED = "abstract as base bool break byte case catch char checked class const continue decimal default delegate do double else enum event explicit extern false finally fixed float for foreach goto if implicit in int interface internal is lock long namespace new null object operator out override params private protected public readonly ref return sbyte sealed short sizeof stackalloc static string struct switch this throw true try typeof uint ulong unchecked unsafe ushort using virtual void volatile while";
96
- /* C#'s contextual keywords: legal identifiers, `@`-escaped all the same so none reads as a keyword where it is one */
96
+ // C#'s contextual keywords: legal identifiers, `@`-escaped all the same so none reads as a keyword where it is one
97
97
  const CS_CONTEXTUAL = "add allows and args async await by descending dynamic equals extension field file from get global group init into join let managed nameof nint not notnull nuint on or orderby partial record remove required scoped select set unmanaged value var when where with yield";
98
98
  /** `name` unless empty (then `empty`), prefixed by `digitPrefix` when it starts with a digit. */
99
99
  function guarded(name, empty, digitPrefix) {
@@ -141,7 +141,7 @@ export function pyClassName(raw) {
141
141
  const name = guarded(pascalWords(raw), "Model", "N");
142
142
  return listed(PY_RESERVED, name) ? `${name}_` : name;
143
143
  }
144
- /* Java's keywords (JLS 3.9), its literals, `_`, and the restricted identifiers that cannot name a type */
144
+ // Java's keywords (JLS 3.9), its literals, `_`, and the restricted identifiers that cannot name a type
145
145
  const JAVA_RESERVED = [
146
146
  "abstract",
147
147
  "assert",
@@ -1,3 +1,8 @@
1
+ /**
2
+ * An optional property's type: under `exactOptionalPropertyTypes` a `k?: T` refuses the `undefined` a zod
3
+ * `.optional()` infers, so the generated type says it too; `unknown` already holds it.
4
+ */
5
+ export declare function optionalType(type: string): string;
1
6
  /** A property key in a type or object literal: bare when it is an identifier, a string literal otherwise. */
2
7
  export declare function quoteKey(key: string): string;
3
8
  /** The TypeScript literal type of a JSON `value` (an array as a tuple, an object field by field); else its type, or `unknown`. */
@@ -3,7 +3,15 @@
3
3
  * escape layer (F2), never `JSON.stringify` alone.
4
4
  */
5
5
  import { tsString } from "./escape.js";
6
+ import { UNKNOWN_TYPE } from "./unknown-type.constants.js";
6
7
  const IDENTIFIER = /^[A-Za-z_$][A-Za-z0-9_$]*$/;
8
+ /**
9
+ * An optional property's type: under `exactOptionalPropertyTypes` a `k?: T` refuses the `undefined` a zod
10
+ * `.optional()` infers, so the generated type says it too; `unknown` already holds it.
11
+ */
12
+ export function optionalType(type) {
13
+ return type === UNKNOWN_TYPE ? type : `${type} | undefined`;
14
+ }
7
15
  /** A property key in a type or object literal: bare when it is an identifier, a string literal otherwise. */
8
16
  export function quoteKey(key) {
9
17
  return IDENTIFIER.test(key) ? key : tsString(key);
@@ -28,12 +28,6 @@ export declare function personOf(value: string): {
28
28
  };
29
29
  /** One author: a name with no comma, angle bracket or control character, or that name then ` <email>`. */
30
30
  export declare const AUTHOR: RegExp;
31
- /** A path to a Markdown file: the README every registry renders, NuGet only in Markdown. */
32
- export declare const MARKDOWN_PATH: RegExp;
33
- /** A path to a PNG or JPEG image: the package icon, in the formats NuGet takes. */
34
- export declare const IMAGE_PATH: RegExp;
35
- /** One keyword: no space, comma or control character, at most 50 characters; a registry may hold it to less. */
36
- export declare const KEYWORD: RegExp;
37
31
  /**
38
32
  * The fields of the package metadata block a run gives once (plan 39 8.2), which every target that publishes reads
39
33
  * where its registry has a place for it; a target's own option of the same meaning wins. `--metadata-<field>` sets one
@@ -35,11 +35,11 @@ export function personOf(value) {
35
35
  /** One author: a name with no comma, angle bracket or control character, or that name then ` <email>`. */
36
36
  export const AUTHOR = /^(?=[^\p{Cc}\p{Cs}]{1,4000}$)[^<>,]*[^<>,\s][^<>,]*?(?: <[^\s<>@]+@[^\s<>@]+\.[^\s<>@]+>)?$/u;
37
37
  /** A path to a Markdown file: the README every registry renders, NuGet only in Markdown. */
38
- export const MARKDOWN_PATH = /^(?=[^\p{Cc}\p{Cs}]{1,4000}$).*\.md$/iu;
38
+ const MARKDOWN_PATH = /^(?=[^\p{Cc}\p{Cs}]{1,4000}$).*\.md$/iu;
39
39
  /** A path to a PNG or JPEG image: the package icon, in the formats NuGet takes. */
40
- export const IMAGE_PATH = /^(?=[^\p{Cc}\p{Cs}]{1,4000}$).*\.(?:png|jpe?g)$/iu;
40
+ const IMAGE_PATH = /^(?=[^\p{Cc}\p{Cs}]{1,4000}$).*\.(?:png|jpe?g)$/iu;
41
41
  /** One keyword: no space, comma or control character, at most 50 characters; a registry may hold it to less. */
42
- export const KEYWORD = /^[^\s,\p{Cc}\p{Cs}]{1,50}$/u;
42
+ const KEYWORD = /^[^\s,\p{Cc}\p{Cs}]{1,50}$/u;
43
43
  /**
44
44
  * The fields of the package metadata block a run gives once (plan 39 8.2), which every target that publishes reads
45
45
  * where its registry has a place for it; a target's own option of the same meaning wins. `--metadata-<field>` sets one
@@ -91,8 +91,9 @@ export function checkedMetadata(metadata) {
91
91
  throw new Error("Invalid metadata: want an object of fields");
92
92
  const entries = Object.entries(metadata).filter(([, value]) => value !== undefined);
93
93
  for (const [field, value] of entries) {
94
- if (!Object.hasOwn(GRAMMARS, field))
94
+ if (!Object.hasOwn(GRAMMARS, field)) {
95
95
  throw new Error(`Invalid metadata: unknown field ${JSON.stringify(field)}, want one of ${METADATA_FIELDS.join(", ")}`);
96
+ }
96
97
  const grammar = GRAMMARS[field];
97
98
  if (!isListField(field)) {
98
99
  if (typeof value !== "string" || !grammar.test(value))
@@ -107,12 +108,12 @@ export function checkedMetadata(metadata) {
107
108
  }
108
109
  return Object.fromEntries(entries);
109
110
  }
110
- /* the names the README and the license file the block names take in every package's root: those each registry and
111
- * forge reads (plan 39 8.7) */
111
+ // the names the README and the license file the block names take in every package's root: those each registry and
112
+ // forge reads (plan 39 8.7)
112
113
  export const README = "README.md";
113
114
  export const LICENSE = "LICENSE";
114
115
  /** The name the icon at `path` ships under: `icon`, then its own extension in lower case. */
115
- /* IMAGE_PATH holds every icon path to an extension, so the last dot starts it */
116
+ // IMAGE_PATH holds every icon path to an extension, so the last dot starts it
116
117
  export const iconName = (path) => `icon${path.slice(path.lastIndexOf(".")).toLowerCase()}`;
117
118
  /** What `metadata` ships beside the code. */
118
119
  export const shippedOf = (metadata) => ({
@@ -24,7 +24,7 @@ export function ruffFormatter(ruff) {
24
24
  resolve(status === 0 ? { code: stdout, errors: [] } : { code: source, errors: [failure] });
25
25
  });
26
26
  child.stdin.on("error", () => {
27
- /* a ruff that never started or stopped reading: its spawn error or exit status answers */
27
+ // a ruff that never started or stopped reading: its spawn error or exit status answers
28
28
  });
29
29
  child.stdin.end(source);
30
30
  });
@@ -25,7 +25,7 @@ export function rustfmtFormatter(rustfmt, edition = "2024") {
25
25
  resolve(status === 0 ? { code: stdout, errors: [] } : { code: source, errors: [failure] });
26
26
  });
27
27
  child.stdin.on("error", () => {
28
- /* a rustfmt that never started or stopped reading: its spawn error or exit status answers */
28
+ // a rustfmt that never started or stopped reading: its spawn error or exit status answers
29
29
  });
30
30
  child.stdin.end(source);
31
31
  });
@@ -1,6 +1,6 @@
1
1
  import { compareCodeUnits } from "./lang.js";
2
- import { literalType, quoteKey } from "./literals.js";
3
- /* a cycle guard only: resolved documents carry no cycles, so legitimately deep nesting is kept */
2
+ import { literalType, optionalType, quoteKey } from "./literals.js";
3
+ // a cycle guard only: resolved documents carry no cycles, so legitimately deep nesting is kept
4
4
  const MAX_DEPTH = 64;
5
5
  /** Whether `type` holds `token` outside every bracket and string: `A | B` does, `{ a: A | B }` does not. */
6
6
  function topLevel(type, token) {
@@ -14,14 +14,18 @@ function topLevel(type, token) {
14
14
  else if (c === quote)
15
15
  quote = null;
16
16
  }
17
- else if (c === '"' || c === "'" || c === "`")
17
+ else if (c === '"' || c === "'" || c === "`") {
18
18
  quote = c;
19
- else if ("({[<".includes(c))
19
+ }
20
+ else if ("({[<".includes(c)) {
20
21
  depth++;
21
- else if (")}]".includes(c) || (c === ">" && type[at - 1] !== "="))
22
+ }
23
+ else if (")}]".includes(c) || (c === ">" && type[at - 1] !== "=")) {
22
24
  depth--;
23
- else if (depth === 0 && type.startsWith(token, at))
25
+ }
26
+ else if (depth === 0 && type.startsWith(token, at)) {
24
27
  return true;
28
+ }
25
29
  }
26
30
  return false;
27
31
  }
@@ -48,14 +52,16 @@ function scalarOf(ir) {
48
52
  }
49
53
  function objectOf(ir, emit) {
50
54
  const extra = ir.additional === undefined || ir.additional === false ? null : emit(ir.additional);
51
- /* closed with nothing in it (z.object({})): the empty object, never an open record */
55
+ // closed with nothing in it (z.object({})): the empty object, never an open record
52
56
  if (ir.fields.length === 0)
53
57
  return ir.additional === false ? "{}" : `Record<string, ${extra ?? "unknown"}>`;
54
58
  const fields = [...ir.fields]
55
59
  .sort((a, b) => compareCodeUnits(a.name, b.name))
56
- .map((field) => `${quoteKey(field.name)}${field.required ? "" : "?"}: ${emit(field.schema)}`);
60
+ .map((field) => field.required
61
+ ? `${quoteKey(field.name)}: ${emit(field.schema)}`
62
+ : `${quoteKey(field.name)}?: ${optionalType(emit(field.schema))}`);
57
63
  const shape = `{ ${fields.join("; ")} }`;
58
- /* an index signature beside fields of other types is TS2411; an intersection says the same */
64
+ // an index signature beside fields of other types is TS2411; an intersection says the same
59
65
  return extra === null ? shape : `${shape} & { [k: string]: ${extra} }`;
60
66
  }
61
67
  function tupleOf(ir, emit) {
@@ -70,28 +76,39 @@ function emitAt(ir, options, depth) {
70
76
  return "unknown";
71
77
  const emit = (child) => emitAt(child, options, depth + 1);
72
78
  switch (ir.kind) {
73
- case "scalar":
79
+ case "scalar": {
74
80
  return scalarOf(ir);
75
- case "const":
81
+ }
82
+ case "const": {
76
83
  return literalType(ir.value);
77
- case "object":
84
+ }
85
+ case "object": {
78
86
  return objectOf(ir, emit);
79
- case "array":
87
+ }
88
+ case "array": {
80
89
  return arrayOf(emit(ir.items));
81
- case "tuple":
90
+ }
91
+ case "tuple": {
82
92
  return tupleOf(ir, emit);
83
- case "union":
93
+ }
94
+ case "union": {
84
95
  return unionOf(ir.variants.map(emit));
85
- case "allOf":
96
+ }
97
+ case "allOf": {
86
98
  return intersectionOf(ir.parts.map(emit));
87
- case "nullable":
99
+ }
100
+ case "nullable": {
88
101
  return unionOf([emit(ir.inner), "null"]);
89
- case "ref":
102
+ }
103
+ case "ref": {
90
104
  return options.refName?.(ir.name) ?? "unknown";
91
- case "binary":
105
+ }
106
+ case "binary": {
92
107
  return options.binary ?? "string";
93
- default:
108
+ }
109
+ default: {
94
110
  return "unknown";
111
+ }
95
112
  }
96
113
  }
97
114
  /** The TypeScript type of `ir`. */
@@ -0,0 +1,2 @@
1
+ /** The TypeScript type of a value nothing is known about, which already holds `undefined`. */
2
+ export declare const UNKNOWN_TYPE = "unknown";
@@ -0,0 +1,2 @@
1
+ /** The TypeScript type of a value nothing is known about, which already holds `undefined`. */
2
+ export const UNKNOWN_TYPE = "unknown";
@@ -10,8 +10,6 @@ export type TsRuntimeFeatures = {
10
10
  export declare const FULL_RUNTIME: TsRuntimeFeatures;
11
11
  /** The runtime modules under `runtime/ts`, each after the ones it imports. */
12
12
  export declare const RUNTIME_MODULES: readonly string[];
13
- /** The runtime modules an SDK with `features` ships, in `RUNTIME_MODULES` order. */
14
- export declare function runtimeModules(features: TsRuntimeFeatures): string[];
15
13
  /** What the SDK of `ir` needs from the runtime: its operations' transports, never the app client. */
16
14
  export declare function runtimeFeatures(ir: IR): TsRuntimeFeatures;
17
15
  /** The Standard Webhooks verifier: it imports nothing, so the webhook file that carries it stands alone. */
@@ -37,13 +37,13 @@ export const RUNTIME_MODULES = [
37
37
  "sdk-ws",
38
38
  "sdk-realtime",
39
39
  ];
40
- /* the modules each transport adds; realtime dials over an event stream and a WebSocket, so it ships both */
40
+ // the modules each transport adds; realtime dials over an event stream and a WebSocket, so it ships both
41
41
  const SSE = ["sse", "stream", "sdk-sse"];
42
42
  const WS = ["ws", "sdk-ws"];
43
43
  const REALTIME = ["realtime", "realtime-connection", "realtime-transports", "sdk-realtime"];
44
44
  const APP = ["app-types", "app"];
45
45
  /** The runtime modules an SDK with `features` ships, in `RUNTIME_MODULES` order. */
46
- export function runtimeModules(features) {
46
+ function runtimeModules(features) {
47
47
  const left = new Set([
48
48
  ...(features.sse || features.realtime ? [] : SSE),
49
49
  ...(features.ws || features.realtime ? [] : WS),
@@ -57,12 +57,12 @@ export function runtimeFeatures(ir) {
57
57
  const streams = new Set(sdkModel(ir).ops.map((op) => op.stream));
58
58
  return { app: false, realtime: streams.has("realtime"), sse: streams.has("sse"), ws: streams.has("ws") };
59
59
  }
60
- /* an import of a sibling runtime module, on one line or several */
60
+ // an import of a sibling runtime module, on one line or several
61
61
  const SIBLING_IMPORT = /^import\s+(?:type\s+)?\{[^}]*\}\s+from\s+"\.\/[\w-]+\.ts"\n/gm;
62
62
  /** One runtime module's source, without its imports of its siblings. */
63
63
  function moduleSource(name) {
64
64
  const text = readFileSync(new URL(`../../runtime/ts/${name}.ts`, import.meta.url), "utf8");
65
- return text.replace(SIBLING_IMPORT, "").trim();
65
+ return text.replaceAll(SIBLING_IMPORT, "").trim();
66
66
  }
67
67
  /** The Standard Webhooks verifier: it imports nothing, so the webhook file that carries it stands alone. */
68
68
  export function webhookSource() {
@@ -15,19 +15,21 @@ export declare function compiled(path: string, source: string, declaration: bool
15
15
  code: string;
16
16
  declaration: string;
17
17
  };
18
- /** The package.json fields the metadata fills, each only when given: the TS SDK's and the MCP server's. */
19
- export declare function npmFields(metadata: Metadata): {
20
- description?: string | undefined;
21
- keywords?: readonly string[] | undefined;
22
- homepage?: string | undefined;
23
- bugs?: string | undefined;
24
- license?: string | undefined;
25
- author?: string | undefined;
26
- repository?: {
27
- type: string;
28
- url: string;
29
- } | undefined;
18
+ /** The package.json fields the metadata fills: the TS SDK's and the MCP server's. */
19
+ export type NpmFields = {
20
+ readonly description?: string;
21
+ readonly keywords?: readonly string[];
22
+ readonly homepage?: string;
23
+ readonly bugs?: string;
24
+ readonly license?: string;
25
+ readonly author?: string;
26
+ readonly repository?: {
27
+ readonly type: "git";
28
+ readonly url: string;
29
+ };
30
30
  };
31
+ /** The package.json fields the metadata fills, each only when given: the TS SDK's and the MCP server's. */
32
+ export declare function npmFields(metadata: Metadata): NpmFields;
31
33
  /** The SDK with its package files, and the package as npm lists it, and JSR too when its name is scoped. */
32
34
  export type GeneratedSdkPackage = GeneratedSdk & {
33
35
  readonly packages: readonly PackageIdentity[];