@distilled.cloud/core 1.0.0-rc.15 → 1.0.0-rc.16

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 (312) hide show
  1. package/lib/api.d.ts +118 -13
  2. package/lib/api.d.ts.map +1 -1
  3. package/lib/api.js +755 -147
  4. package/lib/api.js.map +1 -1
  5. package/lib/category.d.ts.map +1 -1
  6. package/lib/category.js +146 -146
  7. package/lib/category.js.map +1 -1
  8. package/lib/chunks.d.ts +3 -0
  9. package/lib/chunks.d.ts.map +1 -0
  10. package/lib/chunks.js +11 -0
  11. package/lib/chunks.js.map +1 -0
  12. package/lib/codegen/boolean-string-enums.js +36 -36
  13. package/lib/codegen/chunk.d.ts +7 -0
  14. package/lib/codegen/chunk.d.ts.map +1 -0
  15. package/lib/codegen/chunk.js +139 -0
  16. package/lib/codegen/chunk.js.map +1 -0
  17. package/lib/codegen/cli.d.ts.map +1 -1
  18. package/lib/codegen/cli.js +28 -14
  19. package/lib/codegen/cli.js.map +1 -1
  20. package/lib/codegen/datafy.d.ts +14 -0
  21. package/lib/codegen/datafy.d.ts.map +1 -0
  22. package/lib/codegen/datafy.js +853 -0
  23. package/lib/codegen/datafy.js.map +1 -0
  24. package/lib/codegen/dedupe.d.ts +5 -0
  25. package/lib/codegen/dedupe.d.ts.map +1 -0
  26. package/lib/codegen/dedupe.js +153 -0
  27. package/lib/codegen/dedupe.js.map +1 -0
  28. package/lib/codegen/emit.js +56 -56
  29. package/lib/codegen/format.js +18 -18
  30. package/lib/codegen/generated-at.js +29 -29
  31. package/lib/codegen/generator.d.ts.map +1 -1
  32. package/lib/codegen/generator.js +92 -84
  33. package/lib/codegen/generator.js.map +1 -1
  34. package/lib/codegen/graph.js +36 -36
  35. package/lib/codegen/graphql-client.d.ts +2 -0
  36. package/lib/codegen/graphql-client.d.ts.map +1 -1
  37. package/lib/codegen/graphql-client.js +55 -26
  38. package/lib/codegen/graphql-client.js.map +1 -1
  39. package/lib/codegen/graphql.js +113 -113
  40. package/lib/codegen/latin1.d.ts +3 -0
  41. package/lib/codegen/latin1.d.ts.map +1 -0
  42. package/lib/codegen/latin1.js +126 -0
  43. package/lib/codegen/latin1.js.map +1 -0
  44. package/lib/codegen/members.d.ts +7 -0
  45. package/lib/codegen/members.d.ts.map +1 -1
  46. package/lib/codegen/members.js +26 -19
  47. package/lib/codegen/members.js.map +1 -1
  48. package/lib/codegen/model-diff.js +6 -6
  49. package/lib/codegen/naming.js +19 -19
  50. package/lib/codegen/openapi-cli.js +15 -15
  51. package/lib/codegen/openapi.d.ts +17 -0
  52. package/lib/codegen/openapi.d.ts.map +1 -1
  53. package/lib/codegen/openapi.js +323 -169
  54. package/lib/codegen/openapi.js.map +1 -1
  55. package/lib/codegen/operations.js +14 -14
  56. package/lib/codegen/pagination.js +11 -11
  57. package/lib/codegen/patch-audit.js +57 -57
  58. package/lib/codegen/patches.js +79 -79
  59. package/lib/codegen/prelude.js +19 -19
  60. package/lib/codegen/privatize.d.ts +21 -0
  61. package/lib/codegen/privatize.d.ts.map +1 -0
  62. package/lib/codegen/privatize.js +176 -0
  63. package/lib/codegen/privatize.js.map +1 -0
  64. package/lib/codegen/proto.js +25 -25
  65. package/lib/codegen/pure.d.ts +6 -0
  66. package/lib/codegen/pure.d.ts.map +1 -0
  67. package/lib/codegen/pure.js +91 -0
  68. package/lib/codegen/pure.js.map +1 -0
  69. package/lib/codegen/rewrite-operation-ids.js +108 -108
  70. package/lib/codegen/spec-path.js +57 -57
  71. package/lib/codegen/table.d.ts +5 -0
  72. package/lib/codegen/table.d.ts.map +1 -0
  73. package/lib/codegen/table.js +249 -0
  74. package/lib/codegen/table.js.map +1 -0
  75. package/lib/config.d.ts +27 -0
  76. package/lib/config.d.ts.map +1 -0
  77. package/lib/config.js +161 -0
  78. package/lib/config.js.map +1 -0
  79. package/lib/crypto.d.ts +76 -0
  80. package/lib/crypto.d.ts.map +1 -0
  81. package/lib/crypto.js +130 -0
  82. package/lib/crypto.js.map +1 -0
  83. package/lib/debug.d.ts +2 -0
  84. package/lib/debug.d.ts.map +1 -0
  85. package/lib/debug.js +8 -0
  86. package/lib/debug.js.map +1 -0
  87. package/lib/error-category.d.ts +1 -1
  88. package/lib/error-category.d.ts.map +1 -1
  89. package/lib/error-category.js +7 -6
  90. package/lib/error-category.js.map +1 -1
  91. package/lib/errors.d.ts +62 -62
  92. package/lib/errors.d.ts.map +1 -1
  93. package/lib/errors.js +117 -114
  94. package/lib/errors.js.map +1 -1
  95. package/lib/graphql.d.ts +31 -20
  96. package/lib/graphql.d.ts.map +1 -1
  97. package/lib/graphql.js +150 -119
  98. package/lib/graphql.js.map +1 -1
  99. package/lib/graphql.types.js +4 -3
  100. package/lib/graphql.types.js.map +1 -1
  101. package/lib/index.d.ts +3 -2
  102. package/lib/index.d.ts.map +1 -1
  103. package/lib/index.js +15 -14
  104. package/lib/index.js.map +1 -1
  105. package/lib/json-patch.d.ts +2 -2
  106. package/lib/json-patch.js +28 -28
  107. package/lib/pagination.d.ts +9 -25
  108. package/lib/pagination.d.ts.map +1 -1
  109. package/lib/pagination.js +95 -90
  110. package/lib/pagination.js.map +1 -1
  111. package/lib/plain-values.d.ts +10 -0
  112. package/lib/plain-values.d.ts.map +1 -0
  113. package/lib/plain-values.js +40 -0
  114. package/lib/plain-values.js.map +1 -0
  115. package/lib/protocol-http.d.ts +50 -14
  116. package/lib/protocol-http.d.ts.map +1 -1
  117. package/lib/protocol-http.js +351 -178
  118. package/lib/protocol-http.js.map +1 -1
  119. package/lib/protocol-rest.d.ts +38 -25
  120. package/lib/protocol-rest.d.ts.map +1 -1
  121. package/lib/protocol-rest.js +238 -130
  122. package/lib/protocol-rest.js.map +1 -1
  123. package/lib/query.js +16 -16
  124. package/lib/response-validation-strict.d.ts +48 -0
  125. package/lib/response-validation-strict.d.ts.map +1 -0
  126. package/lib/response-validation-strict.js +284 -0
  127. package/lib/response-validation-strict.js.map +1 -0
  128. package/lib/response-validation.d.ts +43 -25
  129. package/lib/response-validation.d.ts.map +1 -1
  130. package/lib/response-validation.js +112 -70
  131. package/lib/response-validation.js.map +1 -1
  132. package/lib/retry-after.d.ts +3 -3
  133. package/lib/retry-after.js +49 -49
  134. package/lib/retry.d.ts +48 -29
  135. package/lib/retry.d.ts.map +1 -1
  136. package/lib/retry.js +142 -154
  137. package/lib/retry.js.map +1 -1
  138. package/lib/schema-lite-impl.d.ts +158 -0
  139. package/lib/schema-lite-impl.d.ts.map +1 -0
  140. package/lib/schema-lite-impl.js +341 -0
  141. package/lib/schema-lite-impl.js.map +1 -0
  142. package/lib/schema-lite-typed.d.ts +41 -0
  143. package/lib/schema-lite-typed.d.ts.map +1 -0
  144. package/lib/schema-lite-typed.js +27 -0
  145. package/lib/schema-lite-typed.js.map +1 -0
  146. package/lib/schema-lite.d.ts +40 -0
  147. package/lib/schema-lite.d.ts.map +1 -0
  148. package/lib/schema-lite.js +31 -0
  149. package/lib/schema-lite.js.map +1 -0
  150. package/lib/schema.d.ts +20 -6
  151. package/lib/schema.d.ts.map +1 -1
  152. package/lib/schema.js +202 -30
  153. package/lib/schema.js.map +1 -1
  154. package/lib/testing.d.ts +3 -2
  155. package/lib/testing.d.ts.map +1 -1
  156. package/lib/testing.js +22 -21
  157. package/lib/testing.js.map +1 -1
  158. package/lib/trait.d.ts +13 -13
  159. package/lib/trait.d.ts.map +1 -1
  160. package/lib/trait.js +80 -80
  161. package/lib/trait.js.map +1 -1
  162. package/lib/xml.d.ts +1 -1
  163. package/lib/xml.d.ts.map +1 -1
  164. package/lib/xml.js +38 -26
  165. package/lib/xml.js.map +1 -1
  166. package/package.json +9 -7
  167. package/src/api.ts +1079 -180
  168. package/src/category.ts +33 -33
  169. package/src/chunks.ts +30 -0
  170. package/src/codegen/chunk.ts +147 -0
  171. package/src/codegen/cli.ts +27 -1
  172. package/src/codegen/datafy.ts +874 -0
  173. package/src/codegen/dedupe.ts +173 -0
  174. package/src/codegen/generator.ts +10 -3
  175. package/src/codegen/graphql-client.ts +49 -15
  176. package/src/codegen/latin1.ts +131 -0
  177. package/src/codegen/members.ts +8 -0
  178. package/src/codegen/openapi.ts +194 -3
  179. package/src/codegen/privatize.ts +200 -0
  180. package/src/codegen/pure.ts +94 -0
  181. package/src/codegen/table.ts +254 -0
  182. package/src/config.ts +216 -0
  183. package/src/crypto.ts +202 -0
  184. package/src/debug.ts +8 -0
  185. package/src/error-category.ts +2 -1
  186. package/src/errors.ts +65 -56
  187. package/src/graphql.ts +109 -62
  188. package/src/graphql.types.ts +9 -7
  189. package/src/index.ts +3 -2
  190. package/src/json-patch.ts +2 -2
  191. package/src/pagination.ts +37 -18
  192. package/src/plain-values.ts +41 -0
  193. package/src/protocol-http.ts +378 -145
  194. package/src/protocol-rest.ts +337 -169
  195. package/src/response-validation-strict.ts +327 -0
  196. package/src/response-validation.ts +101 -50
  197. package/src/retry-after.ts +3 -3
  198. package/src/retry.ts +94 -93
  199. package/src/schema-lite-impl.ts +550 -0
  200. package/src/schema-lite-typed.ts +44 -0
  201. package/src/schema-lite.ts +44 -0
  202. package/src/schema.ts +258 -14
  203. package/src/testing.ts +4 -2
  204. package/src/trait.ts +36 -28
  205. package/src/xml.ts +31 -17
  206. package/lib/codegen/boolean-string-enums.test.d.ts +0 -2
  207. package/lib/codegen/boolean-string-enums.test.d.ts.map +0 -1
  208. package/lib/codegen/boolean-string-enums.test.js +0 -275
  209. package/lib/codegen/boolean-string-enums.test.js.map +0 -1
  210. package/lib/codegen/defer-naming.test.d.ts +0 -2
  211. package/lib/codegen/defer-naming.test.d.ts.map +0 -1
  212. package/lib/codegen/defer-naming.test.js +0 -105
  213. package/lib/codegen/defer-naming.test.js.map +0 -1
  214. package/lib/codegen/generated-at.test.d.ts +0 -2
  215. package/lib/codegen/generated-at.test.d.ts.map +0 -1
  216. package/lib/codegen/generated-at.test.js +0 -81
  217. package/lib/codegen/generated-at.test.js.map +0 -1
  218. package/lib/codegen/generator.test.d.ts +0 -2
  219. package/lib/codegen/generator.test.d.ts.map +0 -1
  220. package/lib/codegen/generator.test.js +0 -121
  221. package/lib/codegen/generator.test.js.map +0 -1
  222. package/lib/codegen/graphql-client.test.d.ts +0 -2
  223. package/lib/codegen/graphql-client.test.d.ts.map +0 -1
  224. package/lib/codegen/graphql-client.test.js +0 -171
  225. package/lib/codegen/graphql-client.test.js.map +0 -1
  226. package/lib/codegen/openapi-binary.test.d.ts +0 -2
  227. package/lib/codegen/openapi-binary.test.d.ts.map +0 -1
  228. package/lib/codegen/openapi-binary.test.js +0 -67
  229. package/lib/codegen/openapi-binary.test.js.map +0 -1
  230. package/lib/codegen/patch-audit.test.d.ts +0 -2
  231. package/lib/codegen/patch-audit.test.d.ts.map +0 -1
  232. package/lib/codegen/patch-audit.test.js +0 -141
  233. package/lib/codegen/patch-audit.test.js.map +0 -1
  234. package/lib/codegen/patches.test.d.ts +0 -2
  235. package/lib/codegen/patches.test.d.ts.map +0 -1
  236. package/lib/codegen/patches.test.js +0 -155
  237. package/lib/codegen/patches.test.js.map +0 -1
  238. package/lib/codegen/protocol-imports.test.d.ts +0 -2
  239. package/lib/codegen/protocol-imports.test.d.ts.map +0 -1
  240. package/lib/codegen/protocol-imports.test.js +0 -36
  241. package/lib/codegen/protocol-imports.test.js.map +0 -1
  242. package/lib/codegen/rewrite-operation-ids.test.d.ts +0 -2
  243. package/lib/codegen/rewrite-operation-ids.test.d.ts.map +0 -1
  244. package/lib/codegen/rewrite-operation-ids.test.js +0 -451
  245. package/lib/codegen/rewrite-operation-ids.test.js.map +0 -1
  246. package/lib/codegen/untagged-unions.test.d.ts +0 -2
  247. package/lib/codegen/untagged-unions.test.d.ts.map +0 -1
  248. package/lib/codegen/untagged-unions.test.js +0 -80
  249. package/lib/codegen/untagged-unions.test.js.map +0 -1
  250. package/lib/fixtures/xml/upstream-validator.json +0 -397
  251. package/lib/graphql.test.d.ts +0 -2
  252. package/lib/graphql.test.d.ts.map +0 -1
  253. package/lib/graphql.test.js +0 -151
  254. package/lib/graphql.test.js.map +0 -1
  255. package/lib/json-patch.test.d.ts +0 -2
  256. package/lib/json-patch.test.d.ts.map +0 -1
  257. package/lib/json-patch.test.js +0 -65
  258. package/lib/json-patch.test.js.map +0 -1
  259. package/lib/pagination.test.d.ts +0 -2
  260. package/lib/pagination.test.d.ts.map +0 -1
  261. package/lib/pagination.test.js +0 -131
  262. package/lib/pagination.test.js.map +0 -1
  263. package/lib/protocol-http.test.d.ts +0 -2
  264. package/lib/protocol-http.test.d.ts.map +0 -1
  265. package/lib/protocol-http.test.js +0 -228
  266. package/lib/protocol-http.test.js.map +0 -1
  267. package/lib/protocol-rest.test.d.ts +0 -2
  268. package/lib/protocol-rest.test.d.ts.map +0 -1
  269. package/lib/protocol-rest.test.js +0 -498
  270. package/lib/protocol-rest.test.js.map +0 -1
  271. package/lib/response-validation.test.d.ts +0 -2
  272. package/lib/response-validation.test.d.ts.map +0 -1
  273. package/lib/response-validation.test.js +0 -72
  274. package/lib/response-validation.test.js.map +0 -1
  275. package/lib/retry-after.test.d.ts +0 -2
  276. package/lib/retry-after.test.d.ts.map +0 -1
  277. package/lib/retry-after.test.js +0 -204
  278. package/lib/retry-after.test.js.map +0 -1
  279. package/lib/retry.test.d.ts +0 -2
  280. package/lib/retry.test.d.ts.map +0 -1
  281. package/lib/retry.test.js +0 -407
  282. package/lib/retry.test.js.map +0 -1
  283. package/lib/sdks.test.d.ts +0 -2
  284. package/lib/sdks.test.d.ts.map +0 -1
  285. package/lib/sdks.test.js +0 -76
  286. package/lib/sdks.test.js.map +0 -1
  287. package/lib/xml.test.d.ts +0 -2
  288. package/lib/xml.test.d.ts.map +0 -1
  289. package/lib/xml.test.js +0 -210
  290. package/lib/xml.test.js.map +0 -1
  291. package/src/codegen/boolean-string-enums.test.ts +0 -299
  292. package/src/codegen/defer-naming.test.ts +0 -113
  293. package/src/codegen/generated-at.test.ts +0 -89
  294. package/src/codegen/generator.test.ts +0 -137
  295. package/src/codegen/graphql-client.test.ts +0 -189
  296. package/src/codegen/openapi-binary.test.ts +0 -91
  297. package/src/codegen/patch-audit.test.ts +0 -160
  298. package/src/codegen/patches.test.ts +0 -188
  299. package/src/codegen/protocol-imports.test.ts +0 -39
  300. package/src/codegen/rewrite-operation-ids.test.ts +0 -472
  301. package/src/codegen/untagged-unions.test.ts +0 -85
  302. package/src/fixtures/xml/upstream-validator.json +0 -397
  303. package/src/graphql.test.ts +0 -198
  304. package/src/json-patch.test.ts +0 -77
  305. package/src/pagination.test.ts +0 -169
  306. package/src/protocol-http.test.ts +0 -276
  307. package/src/protocol-rest.test.ts +0 -703
  308. package/src/response-validation.test.ts +0 -89
  309. package/src/retry-after.test.ts +0 -267
  310. package/src/retry.test.ts +0 -566
  311. package/src/sdks.test.ts +0 -87
  312. package/src/xml.test.ts +0 -251
@@ -44,6 +44,7 @@
44
44
  * (with the non-standard `mode` member the core runtime dispatches on)
45
45
  */
46
46
 
47
+ import { ADDITIONAL_PROPERTIES_TRAIT } from "./members.ts";
47
48
  import {
48
49
  isMechanicalOperationId,
49
50
  isVerbatimRouteId,
@@ -178,6 +179,23 @@ export interface OpenApiConvertOptions {
178
179
  * otherwise generate as a `void` output.
179
180
  */
180
181
  readonly successStatuses?: readonly string[];
182
+ /**
183
+ * Response headers (matched case-insensitively) to add to an operation's
184
+ * output as optional `smithy.api#httpHeader` members wherever one of its
185
+ * 2xx responses declares them -- bodiless ones such as `202 Accepted`
186
+ * included. An allowlist for the same reason as {@link headerParams}:
187
+ * specs declare noise headers (request ids, ETags) on most responses.
188
+ * Azure lists its long-running-operation status monitor
189
+ * (`Azure-AsyncOperation`, `Location`, `Retry-After`), which callers need
190
+ * to follow the operation themselves.
191
+ *
192
+ * An operation whose output reuses a named component gets its own output
193
+ * structure (the component's members plus the headers), so the headers
194
+ * never leak into other operations sharing that component. A header whose
195
+ * member name a body member already uses is suffixed `Header`
196
+ * (`Location` → `locationHeader` next to ARM's `location` region).
197
+ */
198
+ readonly responseHeaders?: readonly string[];
181
199
  /**
182
200
  * Azure-style fixed `api-version`: drops `api-version` query params and
183
201
  * stamps {@link API_VERSION_TRAIT} on every operation.
@@ -781,7 +799,10 @@ const convertSchema = (
781
799
  }
782
800
  const members = buildMembers(ctx, flat.properties, flat.required, hint, depth + 1, dir);
783
801
  return {
784
- target: emit({ type: "structure", members, traits: docTraits }, hint),
802
+ target: emit(
803
+ { type: "structure", members, traits: structTraits(docTraits, flat.additionalProperties) },
804
+ hint,
805
+ ),
785
806
  nullable,
786
807
  };
787
808
  }
@@ -862,7 +883,14 @@ const convertSchema = (
862
883
  const required = new Set<string>(Array.isArray(def.required) ? def.required : []);
863
884
  const members = buildMembers(ctx, def.properties, required, hint, depth + 1, dir);
864
885
  return {
865
- target: emit({ type: "structure", members, traits: docTraits }, hint),
886
+ target: emit(
887
+ {
888
+ type: "structure",
889
+ members,
890
+ traits: structTraits(docTraits, def.additionalProperties),
891
+ },
892
+ hint,
893
+ ),
866
894
  nullable,
867
895
  };
868
896
  }
@@ -911,6 +939,17 @@ const convertSchema = (
911
939
  }
912
940
  };
913
941
 
942
+ /**
943
+ * A structure's traits: its docs, plus the open-object marker when the spec
944
+ * explicitly allows keys beyond `properties` (`additionalProperties: true`
945
+ * or a schema). An absent `additionalProperties` stays closed: most specs
946
+ * omit it without meaning "any key".
947
+ */
948
+ const structTraits = (docTraits: Record<string, unknown>, ap: unknown): Record<string, unknown> =>
949
+ ap !== undefined && ap !== false
950
+ ? { ...docTraits, [ADDITIONAL_PROPERTIES_TRAIT]: {} }
951
+ : docTraits;
952
+
914
953
  /** Whether a property is a sensitive string (x-sensitive or name pattern). */
915
954
  const isSensitiveProperty = (ctx: Ctx, name: string, def: any): boolean => {
916
955
  const r = deref(ctx, def);
@@ -1081,6 +1120,58 @@ const opDoc = (op: any): string | undefined => {
1081
1120
  // Responses
1082
1121
  // ============================================================================
1083
1122
 
1123
+ /**
1124
+ * The allowed headers any 2xx response declares, in status order; the first
1125
+ * declaration of a header (case-insensitively) wins. Swagger 2.0 headers are
1126
+ * schemas themselves; OpenAPI 3 headers carry a `schema`.
1127
+ */
1128
+ const successHeaders = (
1129
+ ctx: Ctx,
1130
+ responses: any,
1131
+ allowed: ReadonlySet<string>,
1132
+ ): Array<{ name: string; schema: any; description?: string }> => {
1133
+ const out: Array<{ name: string; schema: any; description?: string }> = [];
1134
+ const seen = new Set<string>();
1135
+ for (const code of Object.keys(responses ?? {}).sort()) {
1136
+ if (!/^2\d\d$/.test(code)) continue;
1137
+ const raw = responses[code];
1138
+ const resp = raw?.$ref ? resolvePointer(ctx.spec, raw.$ref) : raw;
1139
+ for (const [name, rawHeader] of Object.entries<any>(resp?.headers ?? {})) {
1140
+ const lower = name.toLowerCase();
1141
+ if (!allowed.has(lower) || seen.has(lower)) continue;
1142
+ seen.add(lower);
1143
+ const header = rawHeader?.$ref ? resolvePointer(ctx.spec, rawHeader.$ref) : rawHeader;
1144
+ if (!header || typeof header !== "object") continue;
1145
+ out.push({
1146
+ name,
1147
+ schema: ctx.version === "2.0" ? header : (header.schema ?? {}),
1148
+ ...(typeof header.description === "string" ? { description: header.description } : {}),
1149
+ });
1150
+ }
1151
+ }
1152
+ return out;
1153
+ };
1154
+
1155
+ /** How many times each shape id is the `target` of a member or op input/output. */
1156
+ const targetCounts = (shapes: Record<string, any>): Map<string, number> => {
1157
+ const counts = new Map<string, number>();
1158
+ const visit = (node: any): void => {
1159
+ if (node === null || typeof node !== "object") return;
1160
+ if (Array.isArray(node)) {
1161
+ for (const item of node) visit(item);
1162
+ return;
1163
+ }
1164
+ if (typeof node.target === "string") {
1165
+ counts.set(node.target, (counts.get(node.target) ?? 0) + 1);
1166
+ }
1167
+ for (const [key, value] of Object.entries(node)) {
1168
+ if (key !== "traits") visit(value);
1169
+ }
1170
+ };
1171
+ for (const shape of Object.values(shapes)) visit(shape);
1172
+ return counts;
1173
+ };
1174
+
1084
1175
  /** First declared status wins; resolve response refs and preserve JSON or binary bodies. */
1085
1176
  const successSchema = (
1086
1177
  ctx: Ctx,
@@ -1306,6 +1397,14 @@ const convertOnce = (spec: unknown, options: OpenApiConvertOptions): SmithyModel
1306
1397
 
1307
1398
  const usedErrors = new Map<string, number>(); // class name → first status
1308
1399
  const serviceOps: Array<{ target: string }> = [];
1400
+ const componentHeaders: Array<{
1401
+ readonly opId: string;
1402
+ readonly opName: string;
1403
+ readonly members: Record<string, any>;
1404
+ }> = [];
1405
+ const allowedResponseHeaders = new Set(
1406
+ (options.responseHeaders ?? []).map((name) => name.toLowerCase()),
1407
+ );
1309
1408
 
1310
1409
  for (const [rawPath, pathItem] of Object.entries(doc.paths ?? {})) {
1311
1410
  if (!pathItem || typeof pathItem !== "object") continue;
@@ -1436,7 +1535,9 @@ const convertOnce = (spec: unknown, options: OpenApiConvertOptions): SmithyModel
1436
1535
  bodySchema = bodyParam?.schema;
1437
1536
  bodyRequired = bodyParam?.required === true;
1438
1537
  } else if (op.requestBody) {
1439
- const rb = op.requestBody.$ref ? resolvePointer(doc, op.requestBody.$ref) : op.requestBody;
1538
+ // A components/requestBodies entry can itself be a $ref to another
1539
+ // (1Password Events: AuditEventsRequest → CursorRequest).
1540
+ const rb = deref(ctx, op.requestBody);
1440
1541
  bodyRequired = rb?.required === true;
1441
1542
  const content = rb?.content ?? {};
1442
1543
  if (content["application/json"]) {
@@ -1559,6 +1660,58 @@ const convertOnce = (spec: unknown, options: OpenApiConvertOptions): SmithyModel
1559
1660
  }
1560
1661
  }
1561
1662
 
1663
+ // ---- Response headers (opt-in) ----
1664
+ let pendingHeaders: Record<string, any> | undefined;
1665
+ if (allowedResponseHeaders.size > 0 && method !== "head") {
1666
+ const headers = successHeaders(ctx, op.responses, allowedResponseHeaders);
1667
+ const current = outputTarget === PRELUDE.Unit ? undefined : ctx.shapes[outputTarget];
1668
+ // A raw-root wrapper collapses to its payload, so it has nowhere to
1669
+ // carry headers.
1670
+ const rawRoot = Object.values<any>(current?.members ?? {}).some(
1671
+ (m) => m?.traits?.[RAW_RESPONSE_TRAIT] !== undefined,
1672
+ );
1673
+ if (
1674
+ headers.length > 0 &&
1675
+ (current === undefined || current.type === "structure") &&
1676
+ !rawRoot
1677
+ ) {
1678
+ const taken = new Set(Object.keys(current?.members ?? {}));
1679
+ const members: Record<string, any> = {};
1680
+ for (const header of headers) {
1681
+ let name = headerMemberName(header.name);
1682
+ if (taken.has(name)) name = `${name}Header`;
1683
+ if (taken.has(name)) continue;
1684
+ taken.add(name);
1685
+ members[name] = {
1686
+ target: convertSchema(
1687
+ ctx,
1688
+ header.schema,
1689
+ `${opName}Response${pascal(header.name)}`,
1690
+ 0,
1691
+ "out",
1692
+ ).target,
1693
+ traits: {
1694
+ "smithy.api#httpHeader": header.name,
1695
+ ...(header.description ? { "smithy.api#documentation": header.description } : {}),
1696
+ },
1697
+ };
1698
+ }
1699
+ if (current === undefined) {
1700
+ outputTarget = addShape(ctx, `${opName}Response`, {
1701
+ type: "structure",
1702
+ members,
1703
+ traits: { "smithy.api#output": {} },
1704
+ });
1705
+ } else if (current.traits?.["smithy.api#output"] !== undefined) {
1706
+ current.members = { ...current.members, ...members };
1707
+ } else {
1708
+ // A named component: whether it can take the headers itself
1709
+ // depends on what else uses it, known once every op is converted.
1710
+ pendingHeaders = members;
1711
+ }
1712
+ }
1713
+ }
1714
+
1562
1715
  // ---- Errors ----
1563
1716
  const errors: Array<{ target: string }> = [];
1564
1717
  for (const status of Object.keys(op.responses ?? {})) {
@@ -1598,6 +1751,44 @@ const convertOnce = (spec: unknown, options: OpenApiConvertOptions): SmithyModel
1598
1751
  traits,
1599
1752
  });
1600
1753
  serviceOps.push({ target: opId });
1754
+ if (pendingHeaders !== undefined) {
1755
+ componentHeaders.push({ opId, opName, members: pendingHeaders });
1756
+ }
1757
+ }
1758
+ }
1759
+
1760
+ // ---- Response headers on named components ----
1761
+ // A component returned only by ops that declare headers takes them itself
1762
+ // (all optional) and keeps its name. A component that other shapes, or ops
1763
+ // without those headers, also use is copied into an op-specific output, so
1764
+ // the headers never leak into them.
1765
+ if (componentHeaders.length > 0) {
1766
+ const uses = targetCounts(ctx.shapes);
1767
+ const outputs = new Map<string, number>();
1768
+ for (const { opId } of componentHeaders) {
1769
+ const id: string = ctx.shapes[opId].output.target;
1770
+ outputs.set(id, (outputs.get(id) ?? 0) + 1);
1771
+ }
1772
+ for (const { opId, opName, members } of componentHeaders) {
1773
+ const opShape = ctx.shapes[opId];
1774
+ const componentId: string = opShape.output.target;
1775
+ const component = ctx.shapes[componentId];
1776
+ if (uses.get(componentId) === outputs.get(componentId)) {
1777
+ component.members = { ...component.members, ...members };
1778
+ } else {
1779
+ opShape.output.target = addShape(ctx, `${opName}Response`, {
1780
+ type: "structure",
1781
+ members: { ...component.members, ...members },
1782
+ traits: {
1783
+ ...(component.traits?.["smithy.api#documentation"]
1784
+ ? {
1785
+ "smithy.api#documentation": component.traits["smithy.api#documentation"],
1786
+ }
1787
+ : {}),
1788
+ "smithy.api#output": {},
1789
+ },
1790
+ });
1791
+ }
1601
1792
  }
1602
1793
  }
1603
1794
 
@@ -0,0 +1,200 @@
1
+ /**
2
+ * Make schema consts module-private and drop the ones nothing uses
3
+ * (dev-time only).
4
+ *
5
+ * Every `export` costs memory in each process that imports the module: V8
6
+ * keeps a binding cell, a namespace accessor and the export's name string
7
+ * for it, about 280 bytes each. Stripe's service module exported 14,224
8
+ * names; exporting only its operations and errors cut its import heap from
9
+ * 6.6 MB to 2.7 MB. The types (`export interface` / `export type`) stay
10
+ * exported -- they cost nothing at runtime -- and an operation's schemas
11
+ * stay reachable as `op.input` / `op.output`.
12
+ *
13
+ * After un-exporting, a schema const that no operation, error class or
14
+ * other remaining code references is deleted, repeated to a fixpoint.
15
+ */
16
+ import { parseAst } from "rolldown/parseAst";
17
+
18
+ type Node = { readonly type: string; readonly start: number; readonly end: number } & Record<
19
+ string,
20
+ unknown
21
+ >;
22
+
23
+ const isNode = (value: unknown): value is Node =>
24
+ value !== null && typeof value === "object" && typeof (value as Node).type === "string";
25
+
26
+ /** Value-position identifier names under `node` (type annotations, keys and member names excluded). */
27
+ export const valueRefs = (
28
+ node: unknown,
29
+ out: Set<string>,
30
+ parent?: Node,
31
+ parentKey?: string,
32
+ ): Set<string> => {
33
+ if (Array.isArray(node)) {
34
+ for (const child of node) valueRefs(child, out, parent, parentKey);
35
+ return out;
36
+ }
37
+ if (!isNode(node)) return out;
38
+ if (node.type.startsWith("TS")) {
39
+ // Only the expression side of a cast or assertion is a value.
40
+ if (
41
+ node.type === "TSAsExpression" ||
42
+ node.type === "TSSatisfiesExpression" ||
43
+ node.type === "TSNonNullExpression"
44
+ )
45
+ valueRefs(node.expression, out, node, "expression");
46
+ return out;
47
+ }
48
+ if (node.type === "Identifier") {
49
+ const isKey =
50
+ parent?.type === "Property" && parentKey === "key" && !parent.computed && !parent.shorthand;
51
+ const isMember =
52
+ parent?.type === "MemberExpression" && parentKey === "property" && !parent.computed;
53
+ if (!isKey && !isMember) out.add(node.name as string);
54
+ return out;
55
+ }
56
+ for (const [key, value] of Object.entries(node)) {
57
+ if (
58
+ key === "type" ||
59
+ key === "start" ||
60
+ key === "end" ||
61
+ key === "typeAnnotation" ||
62
+ key === "typeArguments" ||
63
+ key === "typeParameters" ||
64
+ key === "returnType"
65
+ )
66
+ continue;
67
+ if (value !== null && typeof value === "object") valueRefs(value, out, node, key);
68
+ }
69
+ return out;
70
+ };
71
+
72
+ const isOperation = (init: Node, code: string) =>
73
+ /\bAPI\.make(Paginated)?\(/.test(code.slice(init.start, init.end));
74
+
75
+ export const privatizeSchemas = (
76
+ code: string,
77
+ filename = "generated.ts",
78
+ ): { code: string; privatized: number; removed: number } => {
79
+ const program = parseAst(code, { sourceType: "module", lang: "ts" }, filename);
80
+ interface Decl {
81
+ name: string;
82
+ stmt: Node;
83
+ exportStart: number;
84
+ refs: Set<string>;
85
+ }
86
+ const schemaDecls = new Map<string, Decl>();
87
+ const roots = new Set<string>();
88
+
89
+ // Operation names, so an operation alias (`export const listObjects =
90
+ // listBucketObjects`) stays an exported operation and is not taken for a schema.
91
+ const operations = new Set<string>();
92
+ for (const raw of program.body as unknown as Node[]) {
93
+ if (raw.type !== "ExportNamedDeclaration" || !isNode(raw.declaration)) continue;
94
+ const stmt = raw.declaration as Node;
95
+ if (stmt.type !== "VariableDeclaration") continue;
96
+ for (const d of stmt.declarations as Node[]) {
97
+ const id = d.id as Node;
98
+ if (id.type === "Identifier" && isNode(d.init) && isOperation(d.init, code))
99
+ operations.add(id.name as string);
100
+ }
101
+ }
102
+ const isOperationAlias = (init: Node) =>
103
+ init.type === "Identifier" && operations.has(init.name as string);
104
+
105
+ for (const raw of program.body as unknown as Node[]) {
106
+ const exported = raw.type === "ExportNamedDeclaration" && isNode(raw.declaration);
107
+ const stmt = exported ? (raw.declaration as Node) : raw;
108
+ if (
109
+ exported &&
110
+ stmt.type === "VariableDeclaration" &&
111
+ (stmt.declarations as Node[]).length === 1
112
+ ) {
113
+ const d = (stmt.declarations as Node[])[0]!;
114
+ const id = d.id as Node;
115
+ if (
116
+ id.type === "Identifier" &&
117
+ isNode(d.init) &&
118
+ !isOperation(d.init, code) &&
119
+ !isOperationAlias(d.init)
120
+ ) {
121
+ schemaDecls.set(id.name as string, {
122
+ name: id.name as string,
123
+ stmt: raw,
124
+ exportStart: raw.start,
125
+ refs: valueRefs(d.init, new Set()),
126
+ });
127
+ continue;
128
+ }
129
+ }
130
+ // Everything else (operations, classes, imports, plain statements) keeps what it references alive.
131
+ if (
132
+ stmt.type === "ImportDeclaration" ||
133
+ stmt.type === "TSInterfaceDeclaration" ||
134
+ stmt.type === "TSTypeAliasDeclaration"
135
+ )
136
+ continue;
137
+ if (raw.type === "ExportNamedDeclaration" && !isNode(raw.declaration)) {
138
+ // `export { A, B }` / `export type { ... }`
139
+ if (raw.exportKind !== "type")
140
+ for (const s of raw.specifiers as Node[])
141
+ roots.add(((s.local as Node).name as string) ?? "");
142
+ continue;
143
+ }
144
+ for (const r of valueRefs(stmt, new Set())) roots.add(r);
145
+ }
146
+
147
+ // Reachability from the roots through schema references.
148
+ const live = new Set<string>();
149
+ const stack = [...roots].filter((n) => schemaDecls.has(n));
150
+ while (stack.length) {
151
+ const n = stack.pop()!;
152
+ if (live.has(n)) continue;
153
+ live.add(n);
154
+ for (const r of schemaDecls.get(n)!.refs) if (schemaDecls.has(r) && !live.has(r)) stack.push(r);
155
+ }
156
+
157
+ // Rewrite back to front: drop dead consts (with their leading doc comment), un-export live ones.
158
+ const decls = [...schemaDecls.values()].sort((a, b) => b.stmt.start - a.stmt.start);
159
+ let out = code;
160
+ let removed = 0;
161
+ for (const d of decls) {
162
+ if (live.has(d.name)) {
163
+ out = out.slice(0, d.stmt.start) + out.slice(d.stmt.start).replace(/^export\s+/, "");
164
+ } else {
165
+ let start = d.stmt.start;
166
+ const before = out.slice(0, start);
167
+ const doc = /\/\*\*(?:(?!\*\/)[\s\S])*\*\/\s*$/.exec(before);
168
+ if (doc) start = doc.index;
169
+ let end = d.stmt.end;
170
+ while (out[end] === "\n") end++;
171
+ out = out.slice(0, start) + out.slice(end);
172
+ removed++;
173
+ }
174
+ }
175
+ return { code: out, privatized: live.size, removed };
176
+ };
177
+
178
+ /**
179
+ * `import * as X` whose namespace is used only in type positions becomes
180
+ * `import type * as X`. The generator's `oxlint --fix` otherwise deletes it
181
+ * as unused once the schema consts that used it as a value are gone, and the
182
+ * types that still name it stop compiling.
183
+ */
184
+ export const typeOnlyNamespaceImports = (code: string, filename = "generated.ts"): string => {
185
+ const program = parseAst(code, { sourceType: "module", lang: "ts" }, filename);
186
+ const body = program.body as unknown as Node[];
187
+ const used = new Set<string>();
188
+ for (const st of body) if (st.type !== "ImportDeclaration") valueRefs(st, used);
189
+ let out = code;
190
+ for (const st of [...body].reverse()) {
191
+ if (st.type !== "ImportDeclaration" || st.importKind === "type") continue;
192
+ const specs = st.specifiers as Node[];
193
+ if (specs.length !== 1 || specs[0]!.type !== "ImportNamespaceSpecifier") continue;
194
+ const name = (specs[0]!.local as Node).name as string;
195
+ if (used.has(name)) continue;
196
+ const text = code.slice(st.start, st.end).replace(/^import \*/, "import type *");
197
+ out = out.slice(0, st.start) + text + out.slice(st.end);
198
+ }
199
+ return out;
200
+ };
@@ -0,0 +1,94 @@
1
+ /**
2
+ * Deep `/*@__PURE__*​/` annotation for generated modules (dev-time only).
3
+ *
4
+ * A PURE marker lets a bundler drop a call whose result is unused — but the
5
+ * call's ARGUMENTS are still evaluated, and an unannotated call among them
6
+ * counts as a side effect. So
7
+ *
8
+ * export const TagList = /*@__PURE__*​/ S.Array(Tag.pipe(T.XmlName("item")));
9
+ *
10
+ * keeps `Tag` (and everything `Tag` references) alive in every bundle that
11
+ * imports the module, even when nothing uses `TagList`. In EC2 that chain
12
+ * retained 1,695 schemas — 62 KB gzip — for a program calling one
13
+ * operation.
14
+ *
15
+ * {@link annotateNestedCalls} marks every call and `new` inside a top-level
16
+ * initializer (and class `extends` clause), skipping function bodies: code
17
+ * in a thunk only runs when called, so it never pins anything at import.
18
+ * One marker per start position covers a whole method chain
19
+ * (`X.pipe(a).annotate(b)`).
20
+ */
21
+ import { parseAst } from "rolldown/parseAst";
22
+
23
+ const MARKER = "/*@__PURE__*/ ";
24
+ const ALREADY_MARKED = /\/\*\s*[@#]__PURE__\s*\*\/\s*$/;
25
+
26
+ type Node = { readonly type: string; readonly start: number; readonly end: number } & Record<
27
+ string,
28
+ unknown
29
+ >;
30
+
31
+ const isNode = (value: unknown): value is Node =>
32
+ value !== null && typeof value === "object" && typeof (value as Node).type === "string";
33
+
34
+ /** Call/new positions in an initializer expression, outside function bodies. */
35
+ const collectCalls = (node: unknown, out: Set<number>): void => {
36
+ if (Array.isArray(node)) {
37
+ for (const child of node) collectCalls(child, out);
38
+ return;
39
+ }
40
+ if (!isNode(node)) return;
41
+ switch (node.type) {
42
+ case "ArrowFunctionExpression":
43
+ case "FunctionExpression":
44
+ case "ClassBody":
45
+ return;
46
+ case "TSAsExpression":
47
+ case "TSSatisfiesExpression":
48
+ case "TSNonNullExpression":
49
+ collectCalls(node.expression, out);
50
+ return;
51
+ case "CallExpression": {
52
+ const callee = node.callee as Node;
53
+ // An IIFE runs its body at import; leave it alone.
54
+ if (callee.type !== "ArrowFunctionExpression" && callee.type !== "FunctionExpression") {
55
+ out.add(callee.start);
56
+ }
57
+ break;
58
+ }
59
+ case "NewExpression":
60
+ out.add(node.start);
61
+ break;
62
+ }
63
+ for (const [key, value] of Object.entries(node)) {
64
+ if (key === "type" || key === "start" || key === "end") continue;
65
+ if (value !== null && typeof value === "object") collectCalls(value, out);
66
+ }
67
+ };
68
+
69
+ /**
70
+ * Returns `code` with a PURE marker before every unmarked call in a
71
+ * top-level `const`/`let`/`var` initializer or class `extends` clause.
72
+ */
73
+ export const annotateNestedCalls = (code: string, filename = "generated.ts"): string => {
74
+ const program = parseAst(code, { sourceType: "module", lang: "ts" }, filename);
75
+ const positions = new Set<number>();
76
+ for (let statement of program.body as unknown as Node[]) {
77
+ if (statement.type === "ExportNamedDeclaration" && isNode(statement.declaration)) {
78
+ statement = statement.declaration;
79
+ }
80
+ if (statement.type === "VariableDeclaration") {
81
+ for (const declaration of statement.declarations as Node[]) {
82
+ collectCalls(declaration.init, positions);
83
+ }
84
+ } else if (statement.type === "ClassDeclaration") {
85
+ collectCalls(statement.superClass, positions);
86
+ }
87
+ }
88
+ let out = code;
89
+ for (const position of [...positions].sort((a, b) => b - a)) {
90
+ if (ALREADY_MARKED.test(out.slice(Math.max(0, position - 32), position))) continue;
91
+ out = `${out.slice(0, position)}${MARKER}${out.slice(position)}`;
92
+ }
93
+ return out;
94
+ };