@distilled.cloud/core 1.0.0-rc.17 → 1.0.0-rc.19

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 (314) hide show
  1. package/lib/_bundle/base.js +2 -2
  2. package/lib/_bundle/base.js.map +1 -1
  3. package/lib/_bundle/graphql.js +2 -2
  4. package/lib/_bundle/graphql.js.map +1 -1
  5. package/lib/_bundle/grpc.js +2 -0
  6. package/lib/_bundle/grpc.js.map +1 -0
  7. package/lib/_bundle/rest.js +1 -1
  8. package/lib/_bundle/rest.js.map +1 -1
  9. package/lib/_bundle/xml.js +1 -1
  10. package/lib/_bundle/xml.js.map +1 -1
  11. package/lib/annotations.d.ts +17 -0
  12. package/lib/annotations.d.ts.map +1 -0
  13. package/lib/annotations.js +2 -0
  14. package/lib/annotations.js.map +1 -0
  15. package/lib/api.d.ts +52 -1
  16. package/lib/api.d.ts.map +1 -1
  17. package/lib/api.js +1 -1
  18. package/lib/category.d.ts.map +1 -1
  19. package/lib/config.d.ts +54 -13
  20. package/lib/config.d.ts.map +1 -1
  21. package/lib/config.js +1 -1
  22. package/lib/error-category.d.ts.map +1 -1
  23. package/lib/errors.d.ts +3 -13
  24. package/lib/errors.d.ts.map +1 -1
  25. package/lib/errors.js +1 -1
  26. package/lib/graphql.d.ts +26 -5
  27. package/lib/graphql.d.ts.map +1 -1
  28. package/lib/graphql.types.d.ts.map +1 -1
  29. package/lib/grpc-transport-cloudflare-http2.d.ts +7 -0
  30. package/lib/grpc-transport-cloudflare-http2.d.ts.map +1 -0
  31. package/lib/grpc-transport-cloudflare-http2.js +6 -0
  32. package/lib/grpc-transport-cloudflare-http2.js.map +1 -0
  33. package/lib/grpc-transport-cloudflare-sockets.d.ts +7 -0
  34. package/lib/grpc-transport-cloudflare-sockets.d.ts.map +1 -0
  35. package/lib/grpc-transport-cloudflare-sockets.js +5 -0
  36. package/lib/grpc-transport-cloudflare-sockets.js.map +1 -0
  37. package/lib/grpc-transport-node-http2.d.ts +19 -0
  38. package/lib/grpc-transport-node-http2.d.ts.map +1 -0
  39. package/lib/grpc-transport-node-http2.js +2 -0
  40. package/lib/grpc-transport-node-http2.js.map +1 -0
  41. package/lib/grpc-transport.d.ts +76 -0
  42. package/lib/grpc-transport.d.ts.map +1 -0
  43. package/lib/grpc-transport.js +1 -0
  44. package/lib/hpack.d.ts +34 -0
  45. package/lib/hpack.d.ts.map +1 -0
  46. package/lib/hpack.js +2 -0
  47. package/lib/hpack.js.map +1 -0
  48. package/lib/index.d.ts +6 -2
  49. package/lib/index.d.ts.map +1 -1
  50. package/lib/index.js +4 -0
  51. package/lib/pagination.d.ts +55 -3
  52. package/lib/pagination.d.ts.map +1 -1
  53. package/lib/pagination.js +1 -1
  54. package/lib/protobuf.d.ts +92 -0
  55. package/lib/protobuf.d.ts.map +1 -0
  56. package/lib/protobuf.js +1 -0
  57. package/lib/protocol-grpc.d.ts +86 -0
  58. package/lib/protocol-grpc.d.ts.map +1 -0
  59. package/lib/protocol-grpc.js +1 -0
  60. package/lib/protocol-http.d.ts +38 -9
  61. package/lib/protocol-http.d.ts.map +1 -1
  62. package/lib/protocol-http.js +1 -1
  63. package/lib/protocol-rest.d.ts +60 -42
  64. package/lib/protocol-rest.d.ts.map +1 -1
  65. package/lib/protocol-rest.js +1 -1
  66. package/lib/response-validation.d.ts +5 -4
  67. package/lib/response-validation.d.ts.map +1 -1
  68. package/lib/schema-lite-typed.js +1 -2
  69. package/lib/sdk-error.d.ts +27 -0
  70. package/lib/sdk-error.d.ts.map +1 -0
  71. package/lib/sdk-error.js +1 -0
  72. package/lib/sensitive.d.ts +28 -0
  73. package/lib/sensitive.d.ts.map +1 -0
  74. package/lib/sensitive.js +2 -0
  75. package/lib/sensitive.js.map +1 -0
  76. package/lib/telemetry-debug.d.ts +6 -0
  77. package/lib/telemetry-debug.d.ts.map +1 -0
  78. package/lib/telemetry-debug.js +2 -0
  79. package/lib/telemetry-debug.js.map +1 -0
  80. package/lib/telemetry-hooks.d.ts +32 -0
  81. package/lib/telemetry-hooks.d.ts.map +1 -0
  82. package/lib/telemetry-hooks.js +2 -0
  83. package/lib/telemetry-hooks.js.map +1 -0
  84. package/lib/telemetry-host-rules.d.ts +23 -0
  85. package/lib/telemetry-host-rules.d.ts.map +1 -0
  86. package/lib/telemetry-host-rules.js +2 -0
  87. package/lib/telemetry-host-rules.js.map +1 -0
  88. package/lib/telemetry-lambda-context.d.ts +17 -0
  89. package/lib/telemetry-lambda-context.d.ts.map +1 -0
  90. package/lib/telemetry-lambda-context.js +2 -0
  91. package/lib/telemetry-lambda-context.js.map +1 -0
  92. package/lib/telemetry-message-context.d.ts +52 -0
  93. package/lib/telemetry-message-context.d.ts.map +1 -0
  94. package/lib/telemetry-message-context.js +2 -0
  95. package/lib/telemetry-message-context.js.map +1 -0
  96. package/lib/telemetry-metrics.d.ts +6 -0
  97. package/lib/telemetry-metrics.d.ts.map +1 -0
  98. package/lib/telemetry-metrics.js +2 -0
  99. package/lib/telemetry-metrics.js.map +1 -0
  100. package/lib/telemetry-name-template.d.ts +13 -0
  101. package/lib/telemetry-name-template.d.ts.map +1 -0
  102. package/lib/telemetry-name-template.js +2 -0
  103. package/lib/telemetry-name-template.js.map +1 -0
  104. package/lib/telemetry-stream.d.ts +11 -0
  105. package/lib/telemetry-stream.d.ts.map +1 -0
  106. package/lib/telemetry-stream.js +2 -0
  107. package/lib/telemetry-stream.js.map +1 -0
  108. package/lib/telemetry-xray.d.ts +28 -0
  109. package/lib/telemetry-xray.d.ts.map +1 -0
  110. package/lib/telemetry-xray.js +2 -0
  111. package/lib/telemetry-xray.js.map +1 -0
  112. package/lib/telemetry.d.ts +288 -0
  113. package/lib/telemetry.d.ts.map +1 -0
  114. package/lib/telemetry.js +3 -0
  115. package/lib/telemetry.js.map +1 -0
  116. package/lib/trait.d.ts +7 -0
  117. package/lib/trait.d.ts.map +1 -1
  118. package/lib/trait.js +1 -1
  119. package/lib/xml.d.ts.map +1 -1
  120. package/package.json +3 -5
  121. package/src/annotations.ts +53 -0
  122. package/src/api.ts +316 -43
  123. package/src/category.ts +21 -22
  124. package/src/config.ts +58 -29
  125. package/src/error-category.ts +12 -14
  126. package/src/errors.ts +11 -7
  127. package/src/graphql.ts +191 -63
  128. package/src/graphql.types.ts +5 -1
  129. package/src/grpc-transport-cloudflare-http2.ts +494 -0
  130. package/src/grpc-transport-cloudflare-sockets.ts +299 -0
  131. package/src/grpc-transport-node-http2.ts +234 -0
  132. package/src/grpc-transport.ts +118 -0
  133. package/src/hpack.ts +331 -0
  134. package/src/index.ts +6 -2
  135. package/src/pagination.ts +193 -8
  136. package/src/protobuf.ts +1332 -0
  137. package/src/protocol-grpc.ts +641 -0
  138. package/src/protocol-http.ts +87 -67
  139. package/src/protocol-rest.ts +183 -191
  140. package/src/response-validation.ts +8 -5
  141. package/src/sdk-error.ts +33 -0
  142. package/src/sensitive.ts +154 -0
  143. package/src/telemetry-debug.ts +179 -0
  144. package/src/telemetry-hooks.ts +33 -0
  145. package/src/telemetry-host-rules.ts +39 -0
  146. package/src/telemetry-lambda-context.ts +46 -0
  147. package/src/telemetry-message-context.ts +170 -0
  148. package/src/telemetry-metrics.ts +69 -0
  149. package/src/telemetry-name-template.ts +26 -0
  150. package/src/telemetry-stream.ts +100 -0
  151. package/src/telemetry-xray.ts +66 -0
  152. package/src/telemetry.ts +832 -0
  153. package/src/trait.ts +10 -0
  154. package/src/xml.ts +10 -1
  155. package/lib/codegen/boolean-string-enums.d.ts +0 -36
  156. package/lib/codegen/boolean-string-enums.d.ts.map +0 -1
  157. package/lib/codegen/boolean-string-enums.js +0 -147
  158. package/lib/codegen/boolean-string-enums.js.map +0 -1
  159. package/lib/codegen/chunk.d.ts +0 -7
  160. package/lib/codegen/chunk.d.ts.map +0 -1
  161. package/lib/codegen/chunk.js +0 -139
  162. package/lib/codegen/chunk.js.map +0 -1
  163. package/lib/codegen/cli.d.ts +0 -80
  164. package/lib/codegen/cli.d.ts.map +0 -1
  165. package/lib/codegen/cli.js +0 -166
  166. package/lib/codegen/cli.js.map +0 -1
  167. package/lib/codegen/datafy.d.ts +0 -14
  168. package/lib/codegen/datafy.d.ts.map +0 -1
  169. package/lib/codegen/datafy.js +0 -853
  170. package/lib/codegen/datafy.js.map +0 -1
  171. package/lib/codegen/dedupe.d.ts +0 -5
  172. package/lib/codegen/dedupe.d.ts.map +0 -1
  173. package/lib/codegen/dedupe.js +0 -153
  174. package/lib/codegen/dedupe.js.map +0 -1
  175. package/lib/codegen/emit.d.ts +0 -125
  176. package/lib/codegen/emit.d.ts.map +0 -1
  177. package/lib/codegen/emit.js +0 -99
  178. package/lib/codegen/emit.js.map +0 -1
  179. package/lib/codegen/format.d.ts +0 -11
  180. package/lib/codegen/format.d.ts.map +0 -1
  181. package/lib/codegen/format.js +0 -32
  182. package/lib/codegen/format.js.map +0 -1
  183. package/lib/codegen/generated-at.d.ts +0 -29
  184. package/lib/codegen/generated-at.d.ts.map +0 -1
  185. package/lib/codegen/generated-at.js +0 -78
  186. package/lib/codegen/generated-at.js.map +0 -1
  187. package/lib/codegen/generator.d.ts +0 -353
  188. package/lib/codegen/generator.d.ts.map +0 -1
  189. package/lib/codegen/generator.js +0 -810
  190. package/lib/codegen/generator.js.map +0 -1
  191. package/lib/codegen/graph.d.ts +0 -36
  192. package/lib/codegen/graph.d.ts.map +0 -1
  193. package/lib/codegen/graph.js +0 -136
  194. package/lib/codegen/graph.js.map +0 -1
  195. package/lib/codegen/graphql-client.d.ts +0 -70
  196. package/lib/codegen/graphql-client.d.ts.map +0 -1
  197. package/lib/codegen/graphql-client.js +0 -439
  198. package/lib/codegen/graphql-client.js.map +0 -1
  199. package/lib/codegen/graphql.d.ts +0 -207
  200. package/lib/codegen/graphql.d.ts.map +0 -1
  201. package/lib/codegen/graphql.js +0 -786
  202. package/lib/codegen/graphql.js.map +0 -1
  203. package/lib/codegen/latin1.d.ts +0 -3
  204. package/lib/codegen/latin1.d.ts.map +0 -1
  205. package/lib/codegen/latin1.js +0 -126
  206. package/lib/codegen/latin1.js.map +0 -1
  207. package/lib/codegen/members.d.ts +0 -32
  208. package/lib/codegen/members.d.ts.map +0 -1
  209. package/lib/codegen/members.js +0 -62
  210. package/lib/codegen/members.js.map +0 -1
  211. package/lib/codegen/model-diff.d.ts +0 -10
  212. package/lib/codegen/model-diff.d.ts.map +0 -1
  213. package/lib/codegen/model-diff.js +0 -67
  214. package/lib/codegen/model-diff.js.map +0 -1
  215. package/lib/codegen/naming.d.ts +0 -29
  216. package/lib/codegen/naming.d.ts.map +0 -1
  217. package/lib/codegen/naming.js +0 -74
  218. package/lib/codegen/naming.js.map +0 -1
  219. package/lib/codegen/openapi-cli.d.ts +0 -52
  220. package/lib/codegen/openapi-cli.d.ts.map +0 -1
  221. package/lib/codegen/openapi-cli.js +0 -84
  222. package/lib/codegen/openapi-cli.js.map +0 -1
  223. package/lib/codegen/openapi.d.ts +0 -209
  224. package/lib/codegen/openapi.d.ts.map +0 -1
  225. package/lib/codegen/openapi.js +0 -1548
  226. package/lib/codegen/openapi.js.map +0 -1
  227. package/lib/codegen/operations.d.ts +0 -24
  228. package/lib/codegen/operations.d.ts.map +0 -1
  229. package/lib/codegen/operations.js +0 -56
  230. package/lib/codegen/operations.js.map +0 -1
  231. package/lib/codegen/pagination.d.ts +0 -39
  232. package/lib/codegen/pagination.d.ts.map +0 -1
  233. package/lib/codegen/pagination.js +0 -31
  234. package/lib/codegen/pagination.js.map +0 -1
  235. package/lib/codegen/patch-audit.d.ts +0 -84
  236. package/lib/codegen/patch-audit.d.ts.map +0 -1
  237. package/lib/codegen/patch-audit.js +0 -366
  238. package/lib/codegen/patch-audit.js.map +0 -1
  239. package/lib/codegen/patches.d.ts +0 -129
  240. package/lib/codegen/patches.d.ts.map +0 -1
  241. package/lib/codegen/patches.js +0 -472
  242. package/lib/codegen/patches.js.map +0 -1
  243. package/lib/codegen/prelude.d.ts +0 -15
  244. package/lib/codegen/prelude.d.ts.map +0 -1
  245. package/lib/codegen/prelude.js +0 -60
  246. package/lib/codegen/prelude.js.map +0 -1
  247. package/lib/codegen/privatize.d.ts +0 -21
  248. package/lib/codegen/privatize.d.ts.map +0 -1
  249. package/lib/codegen/privatize.js +0 -176
  250. package/lib/codegen/privatize.js.map +0 -1
  251. package/lib/codegen/proto.d.ts +0 -121
  252. package/lib/codegen/proto.d.ts.map +0 -1
  253. package/lib/codegen/proto.js +0 -960
  254. package/lib/codegen/proto.js.map +0 -1
  255. package/lib/codegen/pure.d.ts +0 -6
  256. package/lib/codegen/pure.d.ts.map +0 -1
  257. package/lib/codegen/pure.js +0 -91
  258. package/lib/codegen/pure.js.map +0 -1
  259. package/lib/codegen/rewrite-operation-ids.d.ts +0 -154
  260. package/lib/codegen/rewrite-operation-ids.d.ts.map +0 -1
  261. package/lib/codegen/rewrite-operation-ids.js +0 -1117
  262. package/lib/codegen/rewrite-operation-ids.js.map +0 -1
  263. package/lib/codegen/spec-path.d.ts +0 -16
  264. package/lib/codegen/spec-path.d.ts.map +0 -1
  265. package/lib/codegen/spec-path.js +0 -101
  266. package/lib/codegen/spec-path.js.map +0 -1
  267. package/lib/codegen/table.d.ts +0 -5
  268. package/lib/codegen/table.d.ts.map +0 -1
  269. package/lib/codegen/table.js +0 -249
  270. package/lib/codegen/table.js.map +0 -1
  271. package/lib/debug.d.ts +0 -2
  272. package/lib/debug.d.ts.map +0 -1
  273. package/lib/debug.js +0 -1
  274. package/lib/json-patch.d.ts +0 -58
  275. package/lib/json-patch.d.ts.map +0 -1
  276. package/lib/json-patch.js +0 -2
  277. package/lib/json-patch.js.map +0 -1
  278. package/lib/schema-lite-typed.js.map +0 -1
  279. package/lib/testing.d.ts +0 -40
  280. package/lib/testing.d.ts.map +0 -1
  281. package/lib/testing.js +0 -2
  282. package/lib/testing.js.map +0 -1
  283. package/src/codegen/boolean-string-enums.ts +0 -155
  284. package/src/codegen/chunk.ts +0 -147
  285. package/src/codegen/cli.ts +0 -293
  286. package/src/codegen/datafy.ts +0 -874
  287. package/src/codegen/dedupe.ts +0 -173
  288. package/src/codegen/emit.ts +0 -200
  289. package/src/codegen/format.ts +0 -49
  290. package/src/codegen/generated-at.ts +0 -88
  291. package/src/codegen/generator.ts +0 -1229
  292. package/src/codegen/graph.ts +0 -151
  293. package/src/codegen/graphql-client.ts +0 -545
  294. package/src/codegen/graphql.ts +0 -1145
  295. package/src/codegen/latin1.ts +0 -131
  296. package/src/codegen/members.ts +0 -79
  297. package/src/codegen/model-diff.ts +0 -67
  298. package/src/codegen/naming.ts +0 -85
  299. package/src/codegen/openapi-cli.ts +0 -141
  300. package/src/codegen/openapi.ts +0 -1845
  301. package/src/codegen/operations.ts +0 -73
  302. package/src/codegen/pagination.ts +0 -64
  303. package/src/codegen/patch-audit.ts +0 -480
  304. package/src/codegen/patches.ts +0 -581
  305. package/src/codegen/prelude.ts +0 -70
  306. package/src/codegen/privatize.ts +0 -200
  307. package/src/codegen/proto.ts +0 -1092
  308. package/src/codegen/pure.ts +0 -94
  309. package/src/codegen/rewrite-operation-ids.ts +0 -1219
  310. package/src/codegen/spec-path.ts +0 -112
  311. package/src/codegen/table.ts +0 -254
  312. package/src/debug.ts +0 -8
  313. package/src/json-patch.ts +0 -273
  314. package/src/testing.ts +0 -74
@@ -1,131 +0,0 @@
1
- /**
2
- * Keep module source Latin-1 only (dev-time only).
3
- *
4
- * V8 keeps every module's source text alive (for lazy compilation and
5
- * `Function.prototype.toString`), and stores a string as one byte per
6
- * character only while every character is Latin-1. A single `—` in a doc
7
- * comment doubles the whole file: importing AWS S3's compiled service module
8
- * retained 2,240 KB of heap, and 1,570 KB with its 3 non-Latin-1 comment
9
- * characters replaced.
10
- *
11
- * {@link toLatin1} leaves values intact: inside string and template literals
12
- * a character becomes a `\u` escape (the same value). Elsewhere — comments,
13
- * in practice — typographic punctuation becomes its ASCII form and anything
14
- * else becomes `U+XXXX`.
15
- */
16
- import { parseAst } from "rolldown/parseAst";
17
-
18
- const NON_LATIN1 = /[^\x00-\xff]/;
19
- const NON_LATIN1_ALL = /[^\x00-\xff]/g;
20
-
21
- /** ASCII forms for the punctuation that shows up in API descriptions. */
22
- const ASCII: Record<string, string> = {
23
- "\u2010": "-",
24
- "\u2011": "-",
25
- "\u2012": "-",
26
- "\u2013": "-",
27
- "\u2014": "--",
28
- "\u2015": "--",
29
- "\u2018": "'",
30
- "\u2019": "'",
31
- "\u201a": "'",
32
- "\u201b": "'",
33
- "\u201c": '"',
34
- "\u201d": '"',
35
- "\u201e": '"',
36
- "\u2022": "*",
37
- "\u2026": "...",
38
- "\u2032": "'",
39
- "\u2033": '"',
40
- "\u2122": "(TM)",
41
- "\u2190": "<-",
42
- "\u2192": "->",
43
- "\u2194": "<->",
44
- "\u21d2": "=>",
45
- "\u2212": "-",
46
- "\u2248": "~",
47
- "\u2260": "!=",
48
- "\u2264": "<=",
49
- "\u2265": ">=",
50
- "\u00a0": " ",
51
- "\u200b": "",
52
- "\u200d": "",
53
- "\ufe0f": "",
54
- "\ufeff": "",
55
- };
56
-
57
- const escapeChar = (c: string): string => `\\u${c.charCodeAt(0).toString(16).padStart(4, "0")}`;
58
-
59
- const describeChar = (c: string): string => {
60
- const ascii = ASCII[c];
61
- if (ascii !== undefined) return ascii;
62
- const cp = c.codePointAt(0)!;
63
- return `U+${cp.toString(16).toUpperCase().padStart(4, "0")}`;
64
- };
65
-
66
- type Node = { readonly type: string; readonly start: number; readonly end: number } & Record<
67
- string,
68
- unknown
69
- >;
70
-
71
- const isNode = (value: unknown): value is Node =>
72
- value !== null && typeof value === "object" && typeof (value as Node).type === "string";
73
-
74
- /** [start, end) ranges of string, template and regex literals. */
75
- const literalRanges = (code: string, filename: string): Array<[number, number]> => {
76
- const program = parseAst(code, { sourceType: "module", lang: "ts" }, filename);
77
- const ranges: Array<[number, number]> = [];
78
- const visit = (node: unknown): void => {
79
- if (Array.isArray(node)) {
80
- for (const child of node) visit(child);
81
- return;
82
- }
83
- if (!isNode(node)) return;
84
- if (node.type === "Literal" || node.type === "TemplateElement" || node.type === "Directive") {
85
- ranges.push([node.start, node.end]);
86
- if (node.type !== "Directive") return;
87
- }
88
- for (const [key, value] of Object.entries(node)) {
89
- if (key === "type" || key === "start" || key === "end") continue;
90
- if (value !== null && typeof value === "object") visit(value);
91
- }
92
- };
93
- visit(program);
94
- return ranges.sort((a, b) => a[0] - b[0]);
95
- };
96
-
97
- /** `code` with every non-Latin-1 character escaped (literals) or spelled in ASCII (elsewhere). */
98
- export const toLatin1 = (code: string, filename = "module.ts"): string => {
99
- if (!NON_LATIN1.test(code)) return code;
100
- const ranges = literalRanges(code, filename);
101
- let out = "";
102
- let pos = 0;
103
- let r = 0;
104
- for (const match of code.matchAll(NON_LATIN1_ALL)) {
105
- const i = match.index;
106
- while (r < ranges.length && ranges[r]![1] <= i) r++;
107
- const inLiteral = r < ranges.length && ranges[r]![0] <= i;
108
- let c = match[0];
109
- // A lone low surrogate was handled with its high surrogate below.
110
- if (
111
- c >= "\udc00" &&
112
- c <= "\udfff" &&
113
- i > 0 &&
114
- code.charCodeAt(i - 1) >= 0xd800 &&
115
- code.charCodeAt(i - 1) <= 0xdbff
116
- ) {
117
- pos = i + 1;
118
- continue;
119
- }
120
- if (c >= "\ud800" && c <= "\udbff" && i + 1 < code.length) c = code.slice(i, i + 2);
121
- out += code.slice(pos, i);
122
- out += inLiteral
123
- ? [...c]
124
- .flatMap((ch) => (ch.length === 2 ? [ch[0]!, ch[1]!] : [ch]))
125
- .map(escapeChar)
126
- .join("")
127
- : describeChar(c);
128
- pos = i + c.length;
129
- }
130
- return out + code.slice(pos);
131
- };
@@ -1,79 +0,0 @@
1
- /**
2
- * Structure-member analysis for the SDK generators (dev-time only).
3
- *
4
- * The TS-facing name policy is the provider's (cloudflare camelCases wire
5
- * names, AWS keeps them) — supplied as `nameFn`. Wire-name resolution from
6
- * the smithy HTTP binding traits is generic smithy semantics.
7
- */
8
- import { oneLine } from "./naming.ts";
9
-
10
- /**
11
- * Structure-level marker: the object also carries keys it does not declare
12
- * (OpenAPI `additionalProperties` next to `properties`). The generator adds
13
- * `[key: string]: unknown` to the interface and an `unknown`-valued index
14
- * signature to the schema (`S.StructWithRest`).
15
- */
16
- export const ADDITIONAL_PROPERTIES_TRAIT = "com.distilled.openapi#additionalProperties";
17
-
18
- export interface MemberBase {
19
- /** Original smithy member name. */
20
- readonly name: string;
21
- /** TS-facing name (per `nameFn`, deduplicated within the structure). */
22
- readonly tsName: string;
23
- readonly target: string;
24
- readonly required: boolean;
25
- readonly doc: string | undefined;
26
- readonly traits: Record<string, any>;
27
- }
28
-
29
- /**
30
- * Base analysis of a structure's members: TS naming (with collision
31
- * dedup — a clashing name falls back to the original, then a numeric
32
- * suffix), required-ness, and one-line docs. Binding classification and
33
- * anything provider-specific layer on top via `traits`.
34
- */
35
- export const memberBases = (
36
- def: any,
37
- nameFn: (memberName: string) => string = (n) => n,
38
- ): MemberBase[] => {
39
- const used = new Set<string>();
40
- return Object.entries(def.members ?? {}).map(([mn, m]: [string, any]) => {
41
- const traits = m.traits ?? {};
42
- let tsName = nameFn(mn);
43
- if (used.has(tsName)) tsName = mn;
44
- let k = 2;
45
- while (used.has(tsName)) tsName = `${nameFn(mn)}${k++}`;
46
- used.add(tsName);
47
- return {
48
- name: mn,
49
- tsName,
50
- target: m.target,
51
- required: "smithy.api#required" in traits,
52
- doc: oneLine(traits["smithy.api#documentation"]),
53
- traits,
54
- };
55
- });
56
- };
57
-
58
- /**
59
- * The wire name a bound member serializes under, per the smithy HTTP
60
- * binding traits: labels use the member name (URI placeholders), query and
61
- * header use the trait value when it's a non-empty string, everything else
62
- * uses `jsonName` when present.
63
- */
64
- export const smithyWireName = (
65
- traits: Record<string, any>,
66
- memberName: string,
67
- binding: "label" | "query" | "header" | "other",
68
- ): string => {
69
- if (binding === "label") return memberName;
70
- if (binding === "query") {
71
- const v = traits["smithy.api#httpQuery"];
72
- return typeof v === "string" && v ? v : memberName;
73
- }
74
- if (binding === "header") {
75
- const v = traits["smithy.api#httpHeader"];
76
- return typeof v === "string" && v ? v : memberName;
77
- }
78
- return traits["smithy.api#jsonName"] ?? memberName;
79
- };
@@ -1,67 +0,0 @@
1
- /**
2
- * Human-readable delta between two Smithy model snapshots (dev-time only),
3
- * as JSON pointers. Used by the patch audit to say what a patch changes.
4
- */
5
-
6
- /** Model files keyed by path relative to `.generated-specs`, as text. */
7
- export type Models = Map<string, string>;
8
-
9
- export const MAX_DIFF_LINES = 12;
10
-
11
- const isObject = (v: unknown): v is Record<string, unknown> =>
12
- v !== null && typeof v === "object" && !Array.isArray(v);
13
-
14
- const show = (v: unknown): string => {
15
- const text = JSON.stringify(v);
16
- return text.length > 60 ? text.slice(0, 57) + "…" : text;
17
- };
18
-
19
- /** JSON pointers at which `a` (with the patch) and `b` (without) differ. */
20
- const diffPointers = (a: unknown, b: unknown, pointer: string, out: string[]): void => {
21
- if (out.length > MAX_DIFF_LINES) return;
22
- if (isObject(a) && isObject(b)) {
23
- for (const key of new Set([...Object.keys(a), ...Object.keys(b)])) {
24
- const child = `${pointer}/${key.replace(/~/g, "~0").replace(/\//g, "~1")}`;
25
- if (!(key in b)) out.push(`+ ${child}`);
26
- else if (!(key in a)) out.push(`- ${child}`);
27
- else diffPointers(a[key], b[key], child, out);
28
- }
29
- return;
30
- }
31
- if (Array.isArray(a) && Array.isArray(b)) {
32
- const n = Math.max(a.length, b.length);
33
- for (let i = 0; i < n; i++) {
34
- const child = `${pointer}/${i}`;
35
- if (i >= b.length) out.push(`+ ${child} ${show(a[i])}`);
36
- else if (i >= a.length) out.push(`- ${child} ${show(b[i])}`);
37
- else diffPointers(a[i], b[i], child, out);
38
- }
39
- return;
40
- }
41
- if (JSON.stringify(a) !== JSON.stringify(b)) {
42
- out.push(`~ ${pointer} ${show(a)} → ${show(b)}`);
43
- }
44
- };
45
-
46
- /** Human-readable delta between two model snapshots, `[]` when identical. */
47
- export const diffModels = (withPatch: Models, without: Models): string[] => {
48
- const out: string[] = [];
49
- const many = withPatch.size > 1;
50
- for (const rel of new Set([...withPatch.keys(), ...without.keys()])) {
51
- const a = withPatch.get(rel);
52
- const b = without.get(rel);
53
- if (a === b) continue;
54
- if (a === undefined || b === undefined) {
55
- out.push(`${a === undefined ? "-" : "+"} ${rel}`);
56
- continue;
57
- }
58
- const lines: string[] = [];
59
- diffPointers(JSON.parse(a), JSON.parse(b), "", lines);
60
- for (const line of lines) {
61
- // `+ /shapes/com.x.api#Foo/members/…` → `+ Foo/members/…`
62
- const short = line.replace(/^(. )\/shapes\/[^/#]*#/, "$1");
63
- out.push((many ? `${rel}: ` : "") + short);
64
- }
65
- }
66
- return out;
67
- };
@@ -1,85 +0,0 @@
1
- /**
2
- * Shared naming utilities for the SDK generators (dev-time only — imported by
3
- * `packages/<sdk>/scripts/generate.ts`, never by runtime code).
4
- */
5
-
6
- /** JSON-string-quote a value for emission into generated source. */
7
- export const q = (s: string): string => JSON.stringify(s);
8
-
9
- /** Smithy shape id → local name (`ns#Shape` → `Shape`). */
10
- export const local = (id: string): string => id.split("#")[1] ?? id;
11
-
12
- /** Whether a shape id is a smithy prelude shape (`smithy.api#…`). */
13
- export const isPrelude = (id: string): boolean => id.startsWith("smithy.api#");
14
-
15
- const IDENT = /^[A-Za-z_$][A-Za-z0-9_$]*$/;
16
-
17
- /** Emit a TS object key: bare when a valid identifier, quoted otherwise. */
18
- export const tsKey = (s: string): string => (IDENT.test(s) ? s : q(s));
19
-
20
- /** snake_case / kebab-case wire name → camelCase TS-facing name. */
21
- export const camel = (s: string): string =>
22
- s.replace(/[_-]+([A-Za-z0-9])/g, (_, c: string) => c.toUpperCase());
23
-
24
- /** Reserved words that can't be `const` names. */
25
- export const RESERVED = new Set([
26
- "break",
27
- "case",
28
- "catch",
29
- "class",
30
- "const",
31
- "continue",
32
- "debugger",
33
- "default",
34
- "delete",
35
- "do",
36
- "else",
37
- "enum",
38
- "export",
39
- "extends",
40
- "false",
41
- "finally",
42
- "for",
43
- "function",
44
- "if",
45
- "import",
46
- "in",
47
- "instanceof",
48
- "let",
49
- "new",
50
- "null",
51
- "package",
52
- "return",
53
- "static",
54
- "super",
55
- "switch",
56
- "this",
57
- "throw",
58
- "true",
59
- "try",
60
- "typeof",
61
- "var",
62
- "void",
63
- "while",
64
- "with",
65
- "yield",
66
- ]);
67
-
68
- /**
69
- * Lower-case the first character for an exported operation name — unless the
70
- * result is a reserved word, in which case the original casing is kept.
71
- */
72
- export const lowerFirst = (s: string): string => {
73
- const lowered = s.charAt(0).toLowerCase() + s.slice(1);
74
- return RESERVED.has(lowered) ? s : lowered;
75
- };
76
-
77
- /** Upper-case the first character. */
78
- export const upperFirst = (s: string): string => s.charAt(0).toUpperCase() + s.slice(1);
79
-
80
- /**
81
- * Collapse a smithy documentation string to a single safe line for a
82
- * `/** … *​/` comment.
83
- */
84
- export const oneLine = (s: string | undefined): string | undefined =>
85
- s ? s.replace(/\s+/g, " ").replace(/\*\//g, "*\\/").trim() : undefined;
@@ -1,141 +0,0 @@
1
- /**
2
- * OpenAPI → Smithy pipeline helper (dev-time only, provider-agnostic).
3
- *
4
- * Owns the spec-side pipeline every OpenAPI-sourced provider shares: read the
5
- * spec file, convert it with {@link convertOpenApiToSmithy} (upstream names,
6
- * the verbNoun names deferred), and write `.generated-specs/<name>.json`;
7
- * then {@link finalizeConvert} applies the package's RFC-6902 patches (Smithy
8
- * ops only: `/shapes`, `/metadata`) and the deferred names, so patches target
9
- * the names the spec gives. Stale targets fail unless `onStalePatch: "warn"`.
10
- *
11
- * A provider's `scripts/convert.ts` is: a `runOpenApiConvert` call.
12
- * `scripts/generate.ts` compiles the already-patched models and does not
13
- * apply patches.
14
- */
15
- import * as fs from "node:fs/promises";
16
- import * as path from "node:path";
17
- import { convertOpenApiToSmithy, type OpenApiConvertOptions } from "./openapi.ts";
18
- import { finalizeConvert } from "./patches.ts";
19
- import { resolveSpecPath } from "./spec-path.ts";
20
-
21
- export interface OpenApiSpecEntry {
22
- /** Output model name — written to `<outDir>/<name>.json`. */
23
- readonly name: string;
24
- /** Spec file path, relative to `root` (or absolute). */
25
- readonly specPath: string;
26
- /**
27
- * Hook between reading and conversion (e.g. path prefixing, server
28
- * rewrites). May mutate the spec in place or return a replacement.
29
- */
30
- readonly preprocess?: (spec: any) => unknown | void | Promise<unknown | void>;
31
- /** Per-spec converter option overrides (merged over the shared options). */
32
- readonly options?: Partial<OpenApiConvertOptions>;
33
- }
34
-
35
- export interface RunOpenApiConvertOptions {
36
- /** Absolute package root (usually `path.resolve(import.meta.dirname, "..")`). */
37
- readonly root: string;
38
- readonly specs: readonly OpenApiSpecEntry[];
39
- /**
40
- * RFC-6902 patch root, relative to `root`. Default `"patches"`; `false`
41
- * disables. Layout: `<patchesDir>/<name>/*.json` when the per-spec
42
- * directory exists; for single-spec providers a flat `<patchesDir>/*.json`
43
- * also works. Every op targets the Smithy model (`/shapes`, `/metadata`).
44
- */
45
- readonly patchesDir?: string | false;
46
- /** Output directory, relative to `root`. Default `".generated-specs"`. */
47
- readonly outDir?: string;
48
- /**
49
- * Spec text parser. Default `JSON.parse` — the seam for YAML specs
50
- * (`parse: (text) => YAML.parse(text)`).
51
- */
52
- readonly parse?: (text: string, specPath: string) => unknown;
53
- /** Shared converter options (per-spec `options` merge over these). */
54
- readonly options: OpenApiConvertOptions;
55
- /**
56
- * What to do when a patch JSON pointer does not resolve. Default `"fail"`:
57
- * silent skip is how a whole patch chain can vanish after an upstream path
58
- * prefix change. `"warn"` restores the old skip-and-continue behaviour.
59
- */
60
- readonly onStalePatch?: "fail" | "warn";
61
- /**
62
- * Run {@link finalizeConvert} on the written models (Smithy patches,
63
- * deferred names, reference check, finalized marker). Default true. Pass
64
- * false when the caller finalizes once after several convert steps (Fly
65
- * machines + sprites + addons); its finalizeConvert must then apply the
66
- * Smithy patches, from `patches/<name>/`.
67
- */
68
- readonly finalize?: boolean;
69
- }
70
-
71
- const exists = async (p: string): Promise<boolean> => {
72
- try {
73
- await fs.access(p);
74
- return true;
75
- } catch {
76
- return false;
77
- }
78
- };
79
-
80
- /** Run the OpenAPI→Smithy conversion pipeline (plain async — call from a script). */
81
- export const runOpenApiConvert = async (o: RunOpenApiConvertOptions): Promise<void> => {
82
- const outDir = path.resolve(o.root, o.outDir ?? ".generated-specs");
83
- const patchRoot =
84
- o.patchesDir === false ? undefined : path.resolve(o.root, o.patchesDir ?? "patches");
85
- const parse = o.parse ?? ((text: string) => JSON.parse(text));
86
- const onStalePatch = o.onStalePatch ?? "fail";
87
-
88
- await fs.mkdir(outDir, { recursive: true });
89
-
90
- console.log("🛠️ openapi → smithy");
91
- console.log(` Output: ${outDir}`);
92
-
93
- // Each spec's patch dir, relative to the patch root: `<name>/` when it
94
- // exists, else the root itself for a single-spec provider.
95
- const patchDirs = new Map<string, string>();
96
- if (patchRoot && (await exists(patchRoot))) {
97
- for (const entry of o.specs) {
98
- if (await exists(path.join(patchRoot, entry.name))) patchDirs.set(entry.name, entry.name);
99
- else if (o.specs.length === 1) patchDirs.set(entry.name, "");
100
- }
101
- }
102
-
103
- for (const entry of o.specs) {
104
- // Production path by default; `specs/.local` under DISTILLED_SPECS_LOCAL.
105
- const specPath = resolveSpecPath(o.root, entry.specPath);
106
- let spec: any = parse(await fs.readFile(specPath, "utf8"), specPath);
107
-
108
- // ---- Preprocess hook ----
109
- if (entry.preprocess) {
110
- const replaced = await entry.preprocess(spec);
111
- if (replaced !== undefined) spec = replaced;
112
- }
113
-
114
- // ---- Convert, write ----
115
- const model = convertOpenApiToSmithy(spec, {
116
- deferNaming: true,
117
- ...o.options,
118
- ...entry.options,
119
- });
120
- const opCount = Object.values(model.shapes).filter((s: any) => s.type === "operation").length;
121
- const outPath = path.join(outDir, `${entry.name}.json`);
122
- await fs.writeFile(outPath, JSON.stringify(model, null, 2) + "\n");
123
- console.log(
124
- ` ✅ ${entry.name}: ${opCount} operations, ${Object.keys(model.shapes).length} shapes`,
125
- );
126
- }
127
-
128
- if (o.finalize !== false) {
129
- const written = new Set(o.specs.map((s) => s.name));
130
- await finalizeConvert({
131
- root: o.root,
132
- outDir,
133
- patchesDir: patchRoot ?? false,
134
- patchesFor: (resource) => patchDirs.get(resource),
135
- onStalePatch,
136
- // The converter computed the names; finalize only applies them.
137
- operationNaming: "as-is",
138
- include: (resource) => written.has(resource),
139
- });
140
- }
141
- };