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

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 (306) hide show
  1. package/lib/_bundle/aws.js +2 -0
  2. package/lib/_bundle/aws.js.map +1 -0
  3. package/lib/_bundle/base.js +5 -0
  4. package/lib/_bundle/base.js.map +1 -0
  5. package/lib/_bundle/graphql.js +3 -0
  6. package/lib/_bundle/graphql.js.map +1 -0
  7. package/lib/_bundle/rest.js +2 -0
  8. package/lib/_bundle/rest.js.map +1 -0
  9. package/lib/_bundle/xml.js +4 -0
  10. package/lib/_bundle/xml.js.map +1 -0
  11. package/lib/annotations.d.ts +15 -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 +15 -0
  16. package/lib/api.d.ts.map +1 -1
  17. package/lib/api.js +1 -796
  18. package/lib/category.d.ts.map +1 -1
  19. package/lib/category.js +1 -278
  20. package/lib/chunks.js +1 -11
  21. package/lib/config.d.ts +54 -13
  22. package/lib/config.d.ts.map +1 -1
  23. package/lib/config.js +1 -161
  24. package/lib/crypto.js +1 -130
  25. package/lib/debug.d.ts.map +1 -1
  26. package/lib/debug.js +1 -8
  27. package/lib/error-category.d.ts.map +1 -1
  28. package/lib/error-category.js +1 -47
  29. package/lib/errors.d.ts +2 -13
  30. package/lib/errors.d.ts.map +1 -1
  31. package/lib/errors.js +1 -198
  32. package/lib/graphql.d.ts +14 -0
  33. package/lib/graphql.d.ts.map +1 -1
  34. package/lib/graphql.js +1 -1058
  35. package/lib/graphql.types.js +1 -6
  36. package/lib/index.d.ts +3 -2
  37. package/lib/index.d.ts.map +1 -1
  38. package/lib/index.js +1 -15
  39. package/lib/pagination.d.ts +34 -2
  40. package/lib/pagination.d.ts.map +1 -1
  41. package/lib/pagination.js +1 -271
  42. package/lib/plain-values.js +1 -39
  43. package/lib/plain-values.js.map +1 -1
  44. package/lib/protocol-http.d.ts +30 -6
  45. package/lib/protocol-http.d.ts.map +1 -1
  46. package/lib/protocol-http.js +1 -812
  47. package/lib/protocol-rest.d.ts +53 -39
  48. package/lib/protocol-rest.d.ts.map +1 -1
  49. package/lib/protocol-rest.js +1 -375
  50. package/lib/query.js +1 -27
  51. package/lib/response-validation-strict.js +1 -284
  52. package/lib/response-validation.d.ts +4 -3
  53. package/lib/response-validation.d.ts.map +1 -1
  54. package/lib/response-validation.js +1 -118
  55. package/lib/retry-after.js +1 -112
  56. package/lib/retry.js +1 -197
  57. package/lib/schema-lite-impl.js +1 -341
  58. package/lib/schema-lite-typed.js +1 -27
  59. package/lib/schema-lite.js +1 -31
  60. package/lib/schema.js +1 -220
  61. package/lib/telemetry-debug.d.ts +14 -0
  62. package/lib/telemetry-debug.d.ts.map +1 -0
  63. package/lib/telemetry-debug.js +2 -0
  64. package/lib/telemetry-debug.js.map +1 -0
  65. package/lib/telemetry-hooks.d.ts +32 -0
  66. package/lib/telemetry-hooks.d.ts.map +1 -0
  67. package/lib/telemetry-hooks.js +2 -0
  68. package/lib/telemetry-hooks.js.map +1 -0
  69. package/lib/telemetry-host-rules.d.ts +23 -0
  70. package/lib/telemetry-host-rules.d.ts.map +1 -0
  71. package/lib/telemetry-host-rules.js +2 -0
  72. package/lib/telemetry-host-rules.js.map +1 -0
  73. package/lib/telemetry-lambda-context.d.ts +17 -0
  74. package/lib/telemetry-lambda-context.d.ts.map +1 -0
  75. package/lib/telemetry-lambda-context.js +2 -0
  76. package/lib/telemetry-lambda-context.js.map +1 -0
  77. package/lib/telemetry-message-context.d.ts +52 -0
  78. package/lib/telemetry-message-context.d.ts.map +1 -0
  79. package/lib/telemetry-message-context.js +2 -0
  80. package/lib/telemetry-message-context.js.map +1 -0
  81. package/lib/telemetry-metrics.d.ts +6 -0
  82. package/lib/telemetry-metrics.d.ts.map +1 -0
  83. package/lib/telemetry-metrics.js +2 -0
  84. package/lib/telemetry-metrics.js.map +1 -0
  85. package/lib/telemetry-name-template.d.ts +13 -0
  86. package/lib/telemetry-name-template.d.ts.map +1 -0
  87. package/lib/telemetry-name-template.js +2 -0
  88. package/lib/telemetry-name-template.js.map +1 -0
  89. package/lib/telemetry-stream.d.ts +9 -0
  90. package/lib/telemetry-stream.d.ts.map +1 -0
  91. package/lib/telemetry-stream.js +2 -0
  92. package/lib/telemetry-stream.js.map +1 -0
  93. package/lib/telemetry-xray.d.ts +28 -0
  94. package/lib/telemetry-xray.d.ts.map +1 -0
  95. package/lib/telemetry-xray.js +2 -0
  96. package/lib/telemetry-xray.js.map +1 -0
  97. package/lib/telemetry.d.ts +269 -0
  98. package/lib/telemetry.d.ts.map +1 -0
  99. package/lib/telemetry.js +3 -0
  100. package/lib/telemetry.js.map +1 -0
  101. package/lib/trait.js +1 -131
  102. package/lib/xml.js +1 -323
  103. package/package.json +1 -3
  104. package/src/annotations.ts +37 -0
  105. package/src/api.ts +130 -30
  106. package/src/category.ts +21 -22
  107. package/src/config.ts +58 -29
  108. package/src/debug.ts +9 -6
  109. package/src/error-category.ts +12 -14
  110. package/src/errors.ts +7 -7
  111. package/src/graphql.ts +123 -18
  112. package/src/index.ts +3 -2
  113. package/src/pagination.ts +119 -6
  114. package/src/protocol-http.ts +63 -43
  115. package/src/protocol-rest.ts +201 -140
  116. package/src/response-validation.ts +4 -3
  117. package/src/telemetry-debug.ts +135 -0
  118. package/src/telemetry-hooks.ts +33 -0
  119. package/src/telemetry-host-rules.ts +39 -0
  120. package/src/telemetry-lambda-context.ts +46 -0
  121. package/src/telemetry-message-context.ts +170 -0
  122. package/src/telemetry-metrics.ts +69 -0
  123. package/src/telemetry-name-template.ts +26 -0
  124. package/src/telemetry-stream.ts +91 -0
  125. package/src/telemetry-xray.ts +66 -0
  126. package/src/telemetry.ts +768 -0
  127. package/lib/api.js.map +0 -1
  128. package/lib/category.js.map +0 -1
  129. package/lib/chunks.js.map +0 -1
  130. package/lib/codegen/boolean-string-enums.d.ts +0 -36
  131. package/lib/codegen/boolean-string-enums.d.ts.map +0 -1
  132. package/lib/codegen/boolean-string-enums.js +0 -147
  133. package/lib/codegen/boolean-string-enums.js.map +0 -1
  134. package/lib/codegen/chunk.d.ts +0 -7
  135. package/lib/codegen/chunk.d.ts.map +0 -1
  136. package/lib/codegen/chunk.js +0 -139
  137. package/lib/codegen/chunk.js.map +0 -1
  138. package/lib/codegen/cli.d.ts +0 -80
  139. package/lib/codegen/cli.d.ts.map +0 -1
  140. package/lib/codegen/cli.js +0 -166
  141. package/lib/codegen/cli.js.map +0 -1
  142. package/lib/codegen/datafy.d.ts +0 -14
  143. package/lib/codegen/datafy.d.ts.map +0 -1
  144. package/lib/codegen/datafy.js +0 -853
  145. package/lib/codegen/datafy.js.map +0 -1
  146. package/lib/codegen/dedupe.d.ts +0 -5
  147. package/lib/codegen/dedupe.d.ts.map +0 -1
  148. package/lib/codegen/dedupe.js +0 -153
  149. package/lib/codegen/dedupe.js.map +0 -1
  150. package/lib/codegen/emit.d.ts +0 -125
  151. package/lib/codegen/emit.d.ts.map +0 -1
  152. package/lib/codegen/emit.js +0 -99
  153. package/lib/codegen/emit.js.map +0 -1
  154. package/lib/codegen/format.d.ts +0 -11
  155. package/lib/codegen/format.d.ts.map +0 -1
  156. package/lib/codegen/format.js +0 -32
  157. package/lib/codegen/format.js.map +0 -1
  158. package/lib/codegen/generated-at.d.ts +0 -29
  159. package/lib/codegen/generated-at.d.ts.map +0 -1
  160. package/lib/codegen/generated-at.js +0 -78
  161. package/lib/codegen/generated-at.js.map +0 -1
  162. package/lib/codegen/generator.d.ts +0 -353
  163. package/lib/codegen/generator.d.ts.map +0 -1
  164. package/lib/codegen/generator.js +0 -810
  165. package/lib/codegen/generator.js.map +0 -1
  166. package/lib/codegen/graph.d.ts +0 -36
  167. package/lib/codegen/graph.d.ts.map +0 -1
  168. package/lib/codegen/graph.js +0 -136
  169. package/lib/codegen/graph.js.map +0 -1
  170. package/lib/codegen/graphql-client.d.ts +0 -70
  171. package/lib/codegen/graphql-client.d.ts.map +0 -1
  172. package/lib/codegen/graphql-client.js +0 -439
  173. package/lib/codegen/graphql-client.js.map +0 -1
  174. package/lib/codegen/graphql.d.ts +0 -207
  175. package/lib/codegen/graphql.d.ts.map +0 -1
  176. package/lib/codegen/graphql.js +0 -786
  177. package/lib/codegen/graphql.js.map +0 -1
  178. package/lib/codegen/latin1.d.ts +0 -3
  179. package/lib/codegen/latin1.d.ts.map +0 -1
  180. package/lib/codegen/latin1.js +0 -126
  181. package/lib/codegen/latin1.js.map +0 -1
  182. package/lib/codegen/members.d.ts +0 -32
  183. package/lib/codegen/members.d.ts.map +0 -1
  184. package/lib/codegen/members.js +0 -62
  185. package/lib/codegen/members.js.map +0 -1
  186. package/lib/codegen/model-diff.d.ts +0 -10
  187. package/lib/codegen/model-diff.d.ts.map +0 -1
  188. package/lib/codegen/model-diff.js +0 -67
  189. package/lib/codegen/model-diff.js.map +0 -1
  190. package/lib/codegen/naming.d.ts +0 -29
  191. package/lib/codegen/naming.d.ts.map +0 -1
  192. package/lib/codegen/naming.js +0 -74
  193. package/lib/codegen/naming.js.map +0 -1
  194. package/lib/codegen/openapi-cli.d.ts +0 -52
  195. package/lib/codegen/openapi-cli.d.ts.map +0 -1
  196. package/lib/codegen/openapi-cli.js +0 -84
  197. package/lib/codegen/openapi-cli.js.map +0 -1
  198. package/lib/codegen/openapi.d.ts +0 -209
  199. package/lib/codegen/openapi.d.ts.map +0 -1
  200. package/lib/codegen/openapi.js +0 -1548
  201. package/lib/codegen/openapi.js.map +0 -1
  202. package/lib/codegen/operations.d.ts +0 -24
  203. package/lib/codegen/operations.d.ts.map +0 -1
  204. package/lib/codegen/operations.js +0 -56
  205. package/lib/codegen/operations.js.map +0 -1
  206. package/lib/codegen/pagination.d.ts +0 -39
  207. package/lib/codegen/pagination.d.ts.map +0 -1
  208. package/lib/codegen/pagination.js +0 -31
  209. package/lib/codegen/pagination.js.map +0 -1
  210. package/lib/codegen/patch-audit.d.ts +0 -84
  211. package/lib/codegen/patch-audit.d.ts.map +0 -1
  212. package/lib/codegen/patch-audit.js +0 -366
  213. package/lib/codegen/patch-audit.js.map +0 -1
  214. package/lib/codegen/patches.d.ts +0 -129
  215. package/lib/codegen/patches.d.ts.map +0 -1
  216. package/lib/codegen/patches.js +0 -472
  217. package/lib/codegen/patches.js.map +0 -1
  218. package/lib/codegen/prelude.d.ts +0 -15
  219. package/lib/codegen/prelude.d.ts.map +0 -1
  220. package/lib/codegen/prelude.js +0 -60
  221. package/lib/codegen/prelude.js.map +0 -1
  222. package/lib/codegen/privatize.d.ts +0 -21
  223. package/lib/codegen/privatize.d.ts.map +0 -1
  224. package/lib/codegen/privatize.js +0 -176
  225. package/lib/codegen/privatize.js.map +0 -1
  226. package/lib/codegen/proto.d.ts +0 -121
  227. package/lib/codegen/proto.d.ts.map +0 -1
  228. package/lib/codegen/proto.js +0 -960
  229. package/lib/codegen/proto.js.map +0 -1
  230. package/lib/codegen/pure.d.ts +0 -6
  231. package/lib/codegen/pure.d.ts.map +0 -1
  232. package/lib/codegen/pure.js +0 -91
  233. package/lib/codegen/pure.js.map +0 -1
  234. package/lib/codegen/rewrite-operation-ids.d.ts +0 -154
  235. package/lib/codegen/rewrite-operation-ids.d.ts.map +0 -1
  236. package/lib/codegen/rewrite-operation-ids.js +0 -1117
  237. package/lib/codegen/rewrite-operation-ids.js.map +0 -1
  238. package/lib/codegen/spec-path.d.ts +0 -16
  239. package/lib/codegen/spec-path.d.ts.map +0 -1
  240. package/lib/codegen/spec-path.js +0 -101
  241. package/lib/codegen/spec-path.js.map +0 -1
  242. package/lib/codegen/table.d.ts +0 -5
  243. package/lib/codegen/table.d.ts.map +0 -1
  244. package/lib/codegen/table.js +0 -249
  245. package/lib/codegen/table.js.map +0 -1
  246. package/lib/config.js.map +0 -1
  247. package/lib/crypto.js.map +0 -1
  248. package/lib/debug.js.map +0 -1
  249. package/lib/error-category.js.map +0 -1
  250. package/lib/errors.js.map +0 -1
  251. package/lib/graphql.js.map +0 -1
  252. package/lib/graphql.types.js.map +0 -1
  253. package/lib/index.js.map +0 -1
  254. package/lib/json-patch.d.ts +0 -58
  255. package/lib/json-patch.d.ts.map +0 -1
  256. package/lib/json-patch.js +0 -227
  257. package/lib/json-patch.js.map +0 -1
  258. package/lib/pagination.js.map +0 -1
  259. package/lib/protocol-http.js.map +0 -1
  260. package/lib/protocol-rest.js.map +0 -1
  261. package/lib/query.js.map +0 -1
  262. package/lib/response-validation-strict.js.map +0 -1
  263. package/lib/response-validation.js.map +0 -1
  264. package/lib/retry-after.js.map +0 -1
  265. package/lib/retry.js.map +0 -1
  266. package/lib/schema-lite-impl.js.map +0 -1
  267. package/lib/schema-lite-typed.js.map +0 -1
  268. package/lib/schema-lite.js.map +0 -1
  269. package/lib/schema.js.map +0 -1
  270. package/lib/testing.d.ts +0 -40
  271. package/lib/testing.d.ts.map +0 -1
  272. package/lib/testing.js +0 -42
  273. package/lib/testing.js.map +0 -1
  274. package/lib/trait.js.map +0 -1
  275. package/lib/xml.js.map +0 -1
  276. package/src/codegen/boolean-string-enums.ts +0 -155
  277. package/src/codegen/chunk.ts +0 -147
  278. package/src/codegen/cli.ts +0 -293
  279. package/src/codegen/datafy.ts +0 -874
  280. package/src/codegen/dedupe.ts +0 -173
  281. package/src/codegen/emit.ts +0 -200
  282. package/src/codegen/format.ts +0 -49
  283. package/src/codegen/generated-at.ts +0 -88
  284. package/src/codegen/generator.ts +0 -1229
  285. package/src/codegen/graph.ts +0 -151
  286. package/src/codegen/graphql-client.ts +0 -545
  287. package/src/codegen/graphql.ts +0 -1145
  288. package/src/codegen/latin1.ts +0 -131
  289. package/src/codegen/members.ts +0 -79
  290. package/src/codegen/model-diff.ts +0 -67
  291. package/src/codegen/naming.ts +0 -85
  292. package/src/codegen/openapi-cli.ts +0 -141
  293. package/src/codegen/openapi.ts +0 -1845
  294. package/src/codegen/operations.ts +0 -73
  295. package/src/codegen/pagination.ts +0 -64
  296. package/src/codegen/patch-audit.ts +0 -480
  297. package/src/codegen/patches.ts +0 -581
  298. package/src/codegen/prelude.ts +0 -70
  299. package/src/codegen/privatize.ts +0 -200
  300. package/src/codegen/proto.ts +0 -1092
  301. package/src/codegen/pure.ts +0 -94
  302. package/src/codegen/rewrite-operation-ids.ts +0 -1219
  303. package/src/codegen/spec-path.ts +0 -112
  304. package/src/codegen/table.ts +0 -254
  305. package/src/json-patch.ts +0 -273
  306. 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
- };