@distilled.cloud/core 1.0.0-rc.13 → 1.0.0-rc.14

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 (235) hide show
  1. package/lib/api.d.ts +4 -4
  2. package/lib/api.d.ts.map +1 -1
  3. package/lib/api.js +3 -5
  4. package/lib/api.js.map +1 -1
  5. package/lib/category.d.ts.map +1 -1
  6. package/lib/category.js +3 -5
  7. package/lib/category.js.map +1 -1
  8. package/lib/codegen/boolean-string-enums.d.ts.map +1 -1
  9. package/lib/codegen/boolean-string-enums.js +2 -6
  10. package/lib/codegen/boolean-string-enums.js.map +1 -1
  11. package/lib/codegen/boolean-string-enums.test.js +3 -5
  12. package/lib/codegen/boolean-string-enums.test.js.map +1 -1
  13. package/lib/codegen/cli.d.ts +5 -4
  14. package/lib/codegen/cli.d.ts.map +1 -1
  15. package/lib/codegen/cli.js +12 -9
  16. package/lib/codegen/cli.js.map +1 -1
  17. package/lib/codegen/defer-naming.test.d.ts +2 -0
  18. package/lib/codegen/defer-naming.test.d.ts.map +1 -0
  19. package/lib/codegen/defer-naming.test.js +105 -0
  20. package/lib/codegen/defer-naming.test.js.map +1 -0
  21. package/lib/codegen/emit.d.ts.map +1 -1
  22. package/lib/codegen/emit.js +1 -3
  23. package/lib/codegen/emit.js.map +1 -1
  24. package/lib/codegen/format.d.ts +0 -12
  25. package/lib/codegen/format.d.ts.map +1 -1
  26. package/lib/codegen/format.js +10 -6
  27. package/lib/codegen/format.js.map +1 -1
  28. package/lib/codegen/generated-at.d.ts +29 -0
  29. package/lib/codegen/generated-at.d.ts.map +1 -0
  30. package/lib/codegen/generated-at.js +78 -0
  31. package/lib/codegen/generated-at.js.map +1 -0
  32. package/lib/codegen/generated-at.test.d.ts +2 -0
  33. package/lib/codegen/generated-at.test.d.ts.map +1 -0
  34. package/lib/codegen/generated-at.test.js +81 -0
  35. package/lib/codegen/generated-at.test.js.map +1 -0
  36. package/lib/codegen/generator.d.ts +4 -2
  37. package/lib/codegen/generator.d.ts.map +1 -1
  38. package/lib/codegen/generator.js +37 -75
  39. package/lib/codegen/generator.js.map +1 -1
  40. package/lib/codegen/generator.test.js +4 -9
  41. package/lib/codegen/generator.test.js.map +1 -1
  42. package/lib/codegen/graphql-client.d.ts.map +1 -1
  43. package/lib/codegen/graphql-client.js +12 -33
  44. package/lib/codegen/graphql-client.js.map +1 -1
  45. package/lib/codegen/graphql-client.test.js +4 -12
  46. package/lib/codegen/graphql-client.test.js.map +1 -1
  47. package/lib/codegen/graphql.d.ts.map +1 -1
  48. package/lib/codegen/graphql.js +7 -20
  49. package/lib/codegen/graphql.js.map +1 -1
  50. package/lib/codegen/model-diff.d.ts +10 -0
  51. package/lib/codegen/model-diff.d.ts.map +1 -0
  52. package/lib/codegen/model-diff.js +67 -0
  53. package/lib/codegen/model-diff.js.map +1 -0
  54. package/lib/codegen/naming.d.ts.map +1 -1
  55. package/lib/codegen/naming.js.map +1 -1
  56. package/lib/codegen/openapi-binary.test.js +1 -1
  57. package/lib/codegen/openapi-binary.test.js.map +1 -1
  58. package/lib/codegen/openapi-cli.d.ts +11 -11
  59. package/lib/codegen/openapi-cli.d.ts.map +1 -1
  60. package/lib/codegen/openapi-cli.js +26 -51
  61. package/lib/codegen/openapi-cli.js.map +1 -1
  62. package/lib/codegen/openapi.d.ts +9 -1
  63. package/lib/codegen/openapi.d.ts.map +1 -1
  64. package/lib/codegen/openapi.js +48 -42
  65. package/lib/codegen/openapi.js.map +1 -1
  66. package/lib/codegen/operations.d.ts.map +1 -1
  67. package/lib/codegen/operations.js.map +1 -1
  68. package/lib/codegen/pagination.d.ts.map +1 -1
  69. package/lib/codegen/pagination.js +2 -4
  70. package/lib/codegen/pagination.js.map +1 -1
  71. package/lib/codegen/patch-audit.d.ts +84 -0
  72. package/lib/codegen/patch-audit.d.ts.map +1 -0
  73. package/lib/codegen/patch-audit.js +366 -0
  74. package/lib/codegen/patch-audit.js.map +1 -0
  75. package/lib/codegen/patch-audit.test.d.ts +2 -0
  76. package/lib/codegen/patch-audit.test.d.ts.map +1 -0
  77. package/lib/codegen/patch-audit.test.js +141 -0
  78. package/lib/codegen/patch-audit.test.js.map +1 -0
  79. package/lib/codegen/patches.d.ts +59 -10
  80. package/lib/codegen/patches.d.ts.map +1 -1
  81. package/lib/codegen/patches.js +233 -63
  82. package/lib/codegen/patches.js.map +1 -1
  83. package/lib/codegen/patches.test.js +8 -4
  84. package/lib/codegen/patches.test.js.map +1 -1
  85. package/lib/codegen/prelude.js +1 -1
  86. package/lib/codegen/prelude.js.map +1 -1
  87. package/lib/codegen/proto.d.ts.map +1 -1
  88. package/lib/codegen/proto.js +2 -4
  89. package/lib/codegen/proto.js.map +1 -1
  90. package/lib/codegen/protocol-imports.test.d.ts +2 -0
  91. package/lib/codegen/protocol-imports.test.d.ts.map +1 -0
  92. package/lib/codegen/protocol-imports.test.js +36 -0
  93. package/lib/codegen/protocol-imports.test.js.map +1 -0
  94. package/lib/codegen/rewrite-operation-ids.d.ts +23 -0
  95. package/lib/codegen/rewrite-operation-ids.d.ts.map +1 -1
  96. package/lib/codegen/rewrite-operation-ids.js +97 -59
  97. package/lib/codegen/rewrite-operation-ids.js.map +1 -1
  98. package/lib/codegen/rewrite-operation-ids.test.js +19 -101
  99. package/lib/codegen/rewrite-operation-ids.test.js.map +1 -1
  100. package/lib/codegen/spec-path.d.ts +1 -1
  101. package/lib/codegen/spec-path.d.ts.map +1 -1
  102. package/lib/codegen/spec-path.js +1 -1
  103. package/lib/codegen/spec-path.js.map +1 -1
  104. package/lib/codegen/untagged-unions.test.js +1 -1
  105. package/lib/codegen/untagged-unions.test.js.map +1 -1
  106. package/lib/error-category.d.ts.map +1 -1
  107. package/lib/error-category.js.map +1 -1
  108. package/lib/errors.d.ts.map +1 -1
  109. package/lib/errors.js +7 -5
  110. package/lib/errors.js.map +1 -1
  111. package/lib/graphql.d.ts +4 -8
  112. package/lib/graphql.d.ts.map +1 -1
  113. package/lib/graphql.js +20 -48
  114. package/lib/graphql.js.map +1 -1
  115. package/lib/graphql.test.js +6 -6
  116. package/lib/graphql.test.js.map +1 -1
  117. package/lib/graphql.types.d.ts.map +1 -1
  118. package/lib/graphql.types.js.map +1 -1
  119. package/lib/json-patch.d.ts +13 -6
  120. package/lib/json-patch.d.ts.map +1 -1
  121. package/lib/json-patch.js +34 -19
  122. package/lib/json-patch.js.map +1 -1
  123. package/lib/json-patch.test.d.ts +2 -0
  124. package/lib/json-patch.test.d.ts.map +1 -0
  125. package/lib/json-patch.test.js +65 -0
  126. package/lib/json-patch.test.js.map +1 -0
  127. package/lib/pagination.d.ts.map +1 -1
  128. package/lib/pagination.js +6 -16
  129. package/lib/pagination.js.map +1 -1
  130. package/lib/pagination.test.js +3 -6
  131. package/lib/pagination.test.js.map +1 -1
  132. package/lib/protocol-http.d.ts +20 -1
  133. package/lib/protocol-http.d.ts.map +1 -1
  134. package/lib/protocol-http.js +41 -47
  135. package/lib/protocol-http.js.map +1 -1
  136. package/lib/protocol-http.test.js +20 -10
  137. package/lib/protocol-http.test.js.map +1 -1
  138. package/lib/protocol-rest.d.ts.map +1 -1
  139. package/lib/protocol-rest.js +9 -18
  140. package/lib/protocol-rest.js.map +1 -1
  141. package/lib/protocol-rest.test.d.ts +2 -0
  142. package/lib/protocol-rest.test.d.ts.map +1 -0
  143. package/lib/protocol-rest.test.js +498 -0
  144. package/lib/protocol-rest.test.js.map +1 -0
  145. package/lib/response-validation.d.ts.map +1 -1
  146. package/lib/response-validation.js.map +1 -1
  147. package/lib/response-validation.test.js +10 -5
  148. package/lib/response-validation.test.js.map +1 -1
  149. package/lib/retry-after.d.ts.map +1 -1
  150. package/lib/retry-after.js +1 -1
  151. package/lib/retry-after.js.map +1 -1
  152. package/lib/retry-after.test.d.ts +2 -0
  153. package/lib/retry-after.test.d.ts.map +1 -0
  154. package/lib/retry-after.test.js +204 -0
  155. package/lib/retry-after.test.js.map +1 -0
  156. package/lib/retry.d.ts.map +1 -1
  157. package/lib/retry.js +1 -2
  158. package/lib/retry.js.map +1 -1
  159. package/lib/retry.test.d.ts +2 -0
  160. package/lib/retry.test.d.ts.map +1 -0
  161. package/lib/retry.test.js +407 -0
  162. package/lib/retry.test.js.map +1 -0
  163. package/lib/sdks.test.d.ts +2 -0
  164. package/lib/sdks.test.d.ts.map +1 -0
  165. package/lib/sdks.test.js +76 -0
  166. package/lib/sdks.test.js.map +1 -0
  167. package/lib/testing.d.ts +2 -2
  168. package/lib/testing.d.ts.map +1 -1
  169. package/lib/testing.js +1 -1
  170. package/lib/testing.js.map +1 -1
  171. package/lib/trait.d.ts.map +1 -1
  172. package/lib/trait.js.map +1 -1
  173. package/lib/xml.d.ts.map +1 -1
  174. package/lib/xml.js +3 -7
  175. package/lib/xml.js.map +1 -1
  176. package/lib/xml.test.js +11 -12
  177. package/lib/xml.test.js.map +1 -1
  178. package/package.json +7 -10
  179. package/src/api.ts +38 -55
  180. package/src/category.ts +21 -50
  181. package/src/codegen/boolean-string-enums.test.ts +12 -28
  182. package/src/codegen/boolean-string-enums.ts +2 -10
  183. package/src/codegen/cli.ts +29 -47
  184. package/src/codegen/defer-naming.test.ts +113 -0
  185. package/src/codegen/emit.ts +2 -5
  186. package/src/codegen/format.ts +12 -10
  187. package/src/codegen/generated-at.test.ts +89 -0
  188. package/src/codegen/generated-at.ts +88 -0
  189. package/src/codegen/generator.test.ts +8 -22
  190. package/src/codegen/generator.ts +72 -191
  191. package/src/codegen/graphql-client.test.ts +12 -42
  192. package/src/codegen/graphql-client.ts +30 -95
  193. package/src/codegen/graphql.ts +22 -94
  194. package/src/codegen/model-diff.ts +67 -0
  195. package/src/codegen/naming.ts +1 -2
  196. package/src/codegen/openapi-binary.test.ts +5 -12
  197. package/src/codegen/openapi-cli.ts +38 -79
  198. package/src/codegen/openapi.ts +79 -136
  199. package/src/codegen/operations.ts +2 -5
  200. package/src/codegen/pagination.ts +4 -11
  201. package/src/codegen/patch-audit.test.ts +160 -0
  202. package/src/codegen/patch-audit.ts +480 -0
  203. package/src/codegen/patches.test.ts +14 -21
  204. package/src/codegen/patches.ts +313 -103
  205. package/src/codegen/prelude.ts +1 -1
  206. package/src/codegen/proto.ts +18 -54
  207. package/src/codegen/protocol-imports.test.ts +39 -0
  208. package/src/codegen/rewrite-operation-ids.test.ts +23 -114
  209. package/src/codegen/rewrite-operation-ids.ts +111 -98
  210. package/src/codegen/spec-path.ts +3 -6
  211. package/src/codegen/untagged-unions.test.ts +3 -7
  212. package/src/error-category.ts +5 -17
  213. package/src/errors.ts +16 -31
  214. package/src/graphql.test.ts +6 -8
  215. package/src/graphql.ts +76 -219
  216. package/src/graphql.types.ts +10 -25
  217. package/src/json-patch.test.ts +77 -0
  218. package/src/json-patch.ts +54 -60
  219. package/src/pagination.test.ts +13 -35
  220. package/src/pagination.ts +44 -111
  221. package/src/protocol-http.test.ts +36 -30
  222. package/src/protocol-http.ts +73 -138
  223. package/src/protocol-rest.test.ts +703 -0
  224. package/src/protocol-rest.ts +24 -62
  225. package/src/response-validation.test.ts +12 -18
  226. package/src/response-validation.ts +3 -12
  227. package/src/retry-after.test.ts +267 -0
  228. package/src/retry-after.ts +4 -10
  229. package/src/retry.test.ts +566 -0
  230. package/src/retry.ts +6 -21
  231. package/src/sdks.test.ts +87 -0
  232. package/src/testing.ts +4 -10
  233. package/src/trait.ts +21 -67
  234. package/src/xml.test.ts +15 -33
  235. package/src/xml.ts +9 -25
@@ -1,8 +1,5 @@
1
- import { describe, expect, test } from "bun:test";
2
- import {
3
- booleanStringEnums,
4
- STRING_ENCODED_TRAIT,
5
- } from "./boolean-string-enums.ts";
1
+ import { describe, expect, test } from "vitest";
2
+ import { booleanStringEnums, STRING_ENCODED_TRAIT } from "./boolean-string-enums.ts";
6
3
  import { generateService } from "./generator.ts";
7
4
 
8
5
  const boolEnum = {
@@ -46,9 +43,7 @@ describe("booleanStringEnums", () => {
46
43
  },
47
44
  });
48
45
  expect(booleanStringEnums(m)).toEqual({ members: 0, lists: 0 });
49
- expect(m.shapes["com.example.x#Response"].members.active.target).toBe(
50
- "com.example.x#Flag",
51
- );
46
+ expect(m.shapes["com.example.x#Response"].members.active.target).toBe("com.example.x#Flag");
52
47
  });
53
48
 
54
49
  test("retargets a request-only list's element type", () => {
@@ -65,9 +60,7 @@ describe("booleanStringEnums", () => {
65
60
  },
66
61
  });
67
62
  expect(booleanStringEnums(m)).toEqual({ members: 1, lists: 1 });
68
- expect(m.shapes["com.example.x#FlagList"].member.target).toBe(
69
- "smithy.api#Boolean",
70
- );
63
+ expect(m.shapes["com.example.x#FlagList"].member.target).toBe("smithy.api#Boolean");
71
64
  });
72
65
 
73
66
  test("leaves a list a response also uses", () => {
@@ -88,9 +81,7 @@ describe("booleanStringEnums", () => {
88
81
  },
89
82
  });
90
83
  expect(booleanStringEnums(m)).toEqual({ members: 0, lists: 0 });
91
- expect(m.shapes["com.example.x#FlagList"].member.target).toBe(
92
- "com.example.x#Flag",
93
- );
84
+ expect(m.shapes["com.example.x#FlagList"].member.target).toBe("com.example.x#Flag");
94
85
  });
95
86
 
96
87
  test("leaves an enum that is not exactly true/false", () => {
@@ -220,9 +211,7 @@ describe("generateService", () => {
220
211
  expect(code).toContain(`as any as S.Codec<${name}>`);
221
212
  }
222
213
  expect(code).not.toContain("S.Schema<");
223
- expect(generateService(input, spec).code).toContain(
224
- "as any as S.Schema<Input>",
225
- );
214
+ expect(generateService(input, spec).code).toContain("as any as S.Schema<Input>");
226
215
  });
227
216
 
228
217
  test("emits a boolean piped through T.StringEncoded()", () => {
@@ -261,9 +250,7 @@ describe("generateService", () => {
261
250
  },
262
251
  },
263
252
  );
264
- expect(code).toContain(
265
- '"verbose": S.optional(S.Boolean.pipe(T.Query(), T.StringEncoded())),',
266
- );
253
+ expect(code).toContain('"verbose": S.optional(S.Boolean.pipe(T.Query(), T.StringEncoded())),');
267
254
  expect(code).toContain("verbose?: boolean;");
268
255
  expect(code).not.toContain('"true" | "false"');
269
256
  });
@@ -285,9 +272,7 @@ describe("nested structures", () => {
285
272
  "com.example.x#GetThingResponse": {
286
273
  type: "structure",
287
274
  traits: { "smithy.api#output": {} },
288
- members: sharedWithResponse
289
- ? { profile: { target: "com.example.x#Profile" } }
290
- : {},
275
+ members: sharedWithResponse ? { profile: { target: "com.example.x#Profile" } } : {},
291
276
  },
292
277
  "com.example.x#Profile": {
293
278
  type: "structure",
@@ -299,8 +284,7 @@ describe("nested structures", () => {
299
284
  test("retargets a member of a structure only requests reach", () => {
300
285
  const m = nested(false);
301
286
  expect(booleanStringEnums(m)).toEqual({ members: 1, lists: 0 });
302
- const member =
303
- m.shapes["com.example.x#Profile"].members.dynamicMemoryEnabled;
287
+ const member = m.shapes["com.example.x#Profile"].members.dynamicMemoryEnabled;
304
288
  expect(member.target).toBe("smithy.api#Boolean");
305
289
  expect(member.traits[STRING_ENCODED_TRAIT]).toEqual({});
306
290
  });
@@ -308,8 +292,8 @@ describe("nested structures", () => {
308
292
  test("leaves a structure a response also delivers", () => {
309
293
  const m = nested(true);
310
294
  expect(booleanStringEnums(m)).toEqual({ members: 0, lists: 0 });
311
- expect(
312
- m.shapes["com.example.x#Profile"].members.dynamicMemoryEnabled.target,
313
- ).toBe("com.example.x#Flag");
295
+ expect(m.shapes["com.example.x#Profile"].members.dynamicMemoryEnabled.target).toBe(
296
+ "com.example.x#Flag",
297
+ );
314
298
  });
315
299
  });
@@ -45,11 +45,7 @@ const booleanEnumIds = (shapes: Record<string, any>): Set<string> => {
45
45
  const values = Object.values(shape.members ?? {}).map(
46
46
  (m: any) => m?.traits?.["smithy.api#enumValue"],
47
47
  );
48
- if (
49
- values.length === 2 &&
50
- values.includes("true") &&
51
- values.includes("false")
52
- ) {
48
+ if (values.length === 2 && values.includes("true") && values.includes("false")) {
53
49
  out.add(id);
54
50
  }
55
51
  }
@@ -132,11 +128,7 @@ export const booleanStringEnums = (model: any): BooleanStringEnumResult => {
132
128
  const requestOnly = requestOnlyShapes(shapes);
133
129
  const boolLists = new Set<string>();
134
130
  for (const [id, shape] of Object.entries(shapes)) {
135
- if (
136
- shape?.type === "list" &&
137
- boolEnums.has(shape.member?.target) &&
138
- requestOnly.has(id)
139
- ) {
131
+ if (shape?.type === "list" && boolEnums.has(shape.member?.target) && requestOnly.has(id)) {
140
132
  boolLists.add(id);
141
133
  }
142
134
  }
@@ -4,26 +4,27 @@
4
4
  * Owns the smithy→SDK pipeline every SDK package shares: scan the model
5
5
  * directory (plus optional hand-authored manual specs), compile each model
6
6
  * through {@link generateService} with the provider's {@link SdkSpec}, write
7
- * the service modules and the namespaced barrel. RFC-6902 patches apply in
8
- * convert so `.generated-specs` is already the patched model.
7
+ * the service modules and the namespaced barrel. Patches are already in
8
+ * `.generated-specs` (convert applies them, see `codegen/patches`).
9
9
  *
10
10
  * A provider's `scripts/generate.ts` is: trait consts + an SdkSpec + a
11
11
  * `runGeneratorCli` call.
12
12
  */
13
- import { BunRuntime, BunServices } from "@effect/platform-bun";
13
+ import { NodeRuntime, NodeServices } from "@effect/platform-node";
14
14
  import { Console, Effect } from "effect";
15
- import * as FileSystem from "effect/FileSystem";
16
- import * as Path from "effect/Path";
17
15
  import { Flag } from "effect/cli";
18
16
  import { Command } from "effect/cli";
17
+ import * as FileSystem from "effect/FileSystem";
18
+ import * as Path from "effect/Path";
19
19
  import { barrel } from "./emit.ts";
20
20
  import { formatGenerated } from "./format.ts";
21
+ import { stampGeneratedAt } from "./generated-at.ts";
21
22
  import { generateService, type SdkSpec } from "./generator.ts";
22
23
 
23
24
  export interface GeneratorCliOptions {
24
25
  /** Command description shown in --help. */
25
26
  readonly description: string;
26
- /** Absolute package root (usually `path.resolve(import.meta.dir, "..")`). */
27
+ /** Absolute package root (usually `path.resolve(import.meta.dirname, "..")`). */
27
28
  readonly root: string;
28
29
  /** Model directory default (relative to root). Default `.generated-specs`. */
29
30
  readonly smithyDir?: string;
@@ -59,10 +60,7 @@ export interface GeneratorCliOptions {
59
60
  * modules after the service's `aws.api#service` sdkId (`amazon-s3.json` →
60
61
  * `s3.ts`), so the public surface reads `AWS.S3.getObject`.
61
62
  */
62
- readonly resourceName?: (ctx: {
63
- readonly model: any;
64
- readonly file: string;
65
- }) => string;
63
+ readonly resourceName?: (ctx: { readonly model: any; readonly file: string }) => string;
66
64
  /** Barrel export name for a resource. Default: the resource name itself. */
67
65
  readonly barrelExportName?: (resource: string) => string;
68
66
  /**
@@ -80,8 +78,9 @@ export interface GeneratorCliOptions {
80
78
  /** Directory of hand-authored models merged after the generated ones. */
81
79
  readonly manualSpecsDir?: string;
82
80
  /**
83
- * RFC-6902 patches apply in convert, never here. Only `false` is accepted
84
- * so a string is a type error rather than a silently ignored setting.
81
+ * Generate never applies patches: convert does, so `.generated-specs` is
82
+ * the patched model. Only `false` is accepted so a path is a type error
83
+ * rather than a silently ignored setting.
85
84
  */
86
85
  readonly patchesDir?: false;
87
86
  /**
@@ -94,7 +93,7 @@ export interface GeneratorCliOptions {
94
93
  readonly spec: (model: any) => SdkSpec;
95
94
  }
96
95
 
97
- /** Run the generator CLI (BunRuntime main — call at module top level). */
96
+ /** Run the generator CLI (NodeRuntime main — call at module top level). */
98
97
  export const runGeneratorCli = (options: GeneratorCliOptions): void => {
99
98
  const command = Command.make(
100
99
  "generate",
@@ -132,10 +131,7 @@ export const runGeneratorCli = (options: GeneratorCliOptions): void => {
132
131
  const generated = options.discoverModels
133
132
  ? yield* options.discoverModels({ smithyDir })
134
133
  : (yield* fs.readDirectory(smithyDir))
135
- .filter(
136
- (f) =>
137
- f.endsWith(".json") && !(options.excludeModel?.(f) ?? false),
138
- )
134
+ .filter((f) => f.endsWith(".json") && !(options.excludeModel?.(f) ?? false))
139
135
  .map((f) => ({ file: f, dir: smithyDir }));
140
136
  const manualDir = options.manualSpecsDir
141
137
  ? path.resolve(root, options.manualSpecsDir)
@@ -155,9 +151,7 @@ export const runGeneratorCli = (options: GeneratorCliOptions): void => {
155
151
  );
156
152
  }
157
153
  }
158
- const entries = [...generated, ...manual].sort((a, b) =>
159
- a.file.localeCompare(b.file),
160
- );
154
+ const entries = [...generated, ...manual].sort((a, b) => a.file.localeCompare(b.file));
161
155
 
162
156
  yield* fs.makeDirectory(outDir, { recursive: true });
163
157
 
@@ -166,14 +160,10 @@ export const runGeneratorCli = (options: GeneratorCliOptions): void => {
166
160
  let totalOps = 0;
167
161
 
168
162
  for (const { file, dir } of entries) {
169
- const model = JSON.parse(
170
- yield* fs.readFileString(path.join(dir, file)),
171
- );
163
+ const model = JSON.parse(yield* fs.readFileString(path.join(dir, file)));
172
164
  // The module's name — the model's filename unless the provider
173
165
  // derives it from the model itself (AWS: the service's sdkId).
174
- const resource =
175
- options.resourceName?.({ model, file }) ??
176
- file.replace(/\.json$/, "");
166
+ const resource = options.resourceName?.({ model, file }) ?? file.replace(/\.json$/, "");
177
167
  if (config.resource && resource !== config.resource) continue;
178
168
 
179
169
  if (options.transformModel) {
@@ -190,9 +180,7 @@ export const runGeneratorCli = (options: GeneratorCliOptions): void => {
190
180
  generated = generateService(model, options.spec(model));
191
181
  } catch (e) {
192
182
  if (!options.continueOnModelError) throw e;
193
- failedModels.push(
194
- `${resource}: ${e instanceof Error ? e.message : String(e)}`,
195
- );
183
+ failedModels.push(`${resource}: ${e instanceof Error ? e.message : String(e)}`);
196
184
  yield* Console.error(`❌ ${resource}`);
197
185
  continue;
198
186
  }
@@ -220,19 +208,14 @@ export const runGeneratorCli = (options: GeneratorCliOptions): void => {
220
208
  // Sorted, not in generation order: a provider that discovers models
221
209
  // in some other order (AWS walks Amazon's directory tree) would
222
210
  // otherwise reshuffle the barrel on every run.
223
- let resources = [...written].sort((a, b) =>
224
- `${a}.json`.localeCompare(`${b}.json`),
225
- );
211
+ let resources = [...written].sort((a, b) => `${a}.json`.localeCompare(`${b}.json`));
226
212
  if (filtered && (yield* fs.exists(barrelPath))) {
227
213
  // Recover the RESOURCE from each export line's path, not its name:
228
214
  // the two differ when barrelExportName renames (AWS exports
229
215
  // `S3` from `./s3.ts`).
230
216
  const existing = (yield* fs.readFileString(barrelPath))
231
217
  .split("\n")
232
- .map(
233
- (line) =>
234
- /^export \* as \S+ from "\.\/(.+)\.ts";/.exec(line)?.[1],
235
- )
218
+ .map((line) => /^export \* as \S+ from "\.\/(.+)\.ts";/.exec(line)?.[1])
236
219
  .filter((name): name is string => name !== undefined);
237
220
  // Ordered exactly as a full run orders it: by MODEL FILENAME, so
238
221
  // the `.json` takes part in the collation (`ai_gateway.json` sorts
@@ -265,21 +248,20 @@ export const runGeneratorCli = (options: GeneratorCliOptions): void => {
265
248
  // at the end, and the run FAILS — a generate that couldn't produce
266
249
  // a module must not exit 0 with the failure buried in the log.
267
250
  if (failedModels.length) {
268
- yield* Console.error(
269
- `\n❌ ${failedModels.length} model(s) failed to generate:`,
270
- );
251
+ yield* Console.error(`\n❌ ${failedModels.length} model(s) failed to generate:`);
271
252
  for (const f of failedModels) yield* Console.error(` ${f}`);
272
- return yield* Effect.die(
273
- new Error(`${failedModels.length} model(s) failed to generate`),
274
- );
253
+ return yield* Effect.die(new Error(`${failedModels.length} model(s) failed to generate`));
275
254
  }
255
+
256
+ const stamp = yield* Effect.sync(() => stampGeneratedAt(root));
257
+ yield* Console.log(` package.json distilled.generatedAt = ${stamp.generatedAt}`);
258
+ yield* Console.log(
259
+ ` package.json distilled.specUpdatedAt = ${stamp.specUpdatedAt ?? "(unknown, unchanged)"}`,
260
+ );
276
261
  }),
277
262
  ).pipe(Command.withDescription(options.description));
278
263
 
279
- BunRuntime.runMain(
280
- Effect.provide(
281
- Command.run(command, { version: "1.0.0" }),
282
- BunServices.layer,
283
- ),
264
+ NodeRuntime.runMain(
265
+ Effect.provide(Command.run(command, { version: "1.0.0" }), NodeServices.layer),
284
266
  );
285
267
  };
@@ -0,0 +1,113 @@
1
+ import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
2
+ import { tmpdir } from "node:os";
3
+ import { join } from "node:path";
4
+ import { afterEach, describe, expect, test } from "vitest";
5
+ import { convertOpenApiToSmithy, RENAME_METADATA_KEY } from "./openapi.ts";
6
+ import { FINALIZED_KEY, finalizeConvert } from "./patches.ts";
7
+
8
+ const spec = {
9
+ openapi: "3.0.3",
10
+ info: { title: "Apps", version: "1" },
11
+ paths: {
12
+ "/apps": {
13
+ get: {
14
+ operationId: "Apps_list",
15
+ responses: {
16
+ "200": {
17
+ content: {
18
+ "application/json": {
19
+ schema: { type: "array", items: { $ref: "#/components/schemas/App" } },
20
+ },
21
+ },
22
+ },
23
+ },
24
+ },
25
+ },
26
+ "/apps/{id}": {
27
+ get: {
28
+ operationId: "Apps_get",
29
+ parameters: [{ name: "id", in: "path", required: true, schema: { type: "string" } }],
30
+ responses: {
31
+ "200": {
32
+ content: { "application/json": { schema: { $ref: "#/components/schemas/App" } } },
33
+ },
34
+ },
35
+ },
36
+ },
37
+ },
38
+ components: {
39
+ schemas: {
40
+ App: { type: "object", properties: { name: { type: "string" } } },
41
+ // Takes the name the final-named run gives `Apps_list`'s response, so
42
+ // the two runs disagree on which shape gets the `2` suffix.
43
+ ListAppsResponse: { type: "object", properties: { n: { type: "integer" } } },
44
+ },
45
+ },
46
+ };
47
+
48
+ const options = { namespace: "ns", serviceName: "Apps" };
49
+
50
+ const dirs: string[] = [];
51
+ afterEach(() => {
52
+ for (const d of dirs.splice(0)) rmSync(d, { recursive: true, force: true });
53
+ });
54
+
55
+ /** Write `model` as `.generated-specs/apps.json`, with optional patch files. */
56
+ const finalize = async (model: unknown, patches: Record<string, unknown[]> = {}) => {
57
+ const root = mkdtempSync(join(tmpdir(), "defer-naming-"));
58
+ dirs.push(root);
59
+ mkdirSync(join(root, ".generated-specs"));
60
+ writeFileSync(join(root, ".generated-specs", "apps.json"), JSON.stringify(model));
61
+ mkdirSync(join(root, "patches", "apps"), { recursive: true });
62
+ for (const [name, ops] of Object.entries(patches)) {
63
+ writeFileSync(join(root, "patches", "apps", name), JSON.stringify({ patches: ops }));
64
+ }
65
+ await finalizeConvert({ root, operationNaming: "as-is" });
66
+ return JSON.parse(readFileSync(join(root, ".generated-specs", "apps.json"), "utf8"));
67
+ };
68
+
69
+ describe("deferNaming", () => {
70
+ test("names shapes from the spec and records the final names", () => {
71
+ const model = convertOpenApiToSmithy(spec, { ...options, deferNaming: true });
72
+ expect(model.shapes["ns#AppsList"]?.type).toBe("operation");
73
+ expect(model.shapes["ns#ListApps"]).toBeUndefined();
74
+ expect(model.metadata[RENAME_METADATA_KEY]).toMatchObject({
75
+ "ns#AppsList": "ns#ListApps",
76
+ "ns#AppsGet": "ns#GetApp",
77
+ });
78
+ });
79
+
80
+ test("finalize renames to exactly the model converted with final names", async () => {
81
+ const named = convertOpenApiToSmithy(spec, options);
82
+ const deferred = convertOpenApiToSmithy(spec, { ...options, deferNaming: true });
83
+ const finalized = await finalize(deferred);
84
+ expect(finalized).toEqual({
85
+ ...named,
86
+ metadata: { ...named.metadata, [FINALIZED_KEY]: true },
87
+ });
88
+ expect(Object.keys(finalized.shapes)).toEqual(Object.keys(named.shapes));
89
+ });
90
+
91
+ test("a Smithy patch targets the upstream name", async () => {
92
+ const deferred = convertOpenApiToSmithy(spec, { ...options, deferNaming: true });
93
+ const finalized = await finalize(deferred, {
94
+ "doc.json": [
95
+ {
96
+ op: "add",
97
+ path: "/shapes/ns#AppsList/traits/smithy.api#documentation",
98
+ value: "Every app.",
99
+ },
100
+ ],
101
+ });
102
+ expect(finalized.shapes["ns#ListApps"].traits["smithy.api#documentation"]).toBe("Every app.");
103
+ });
104
+
105
+ test("a patch that takes a final name fails the rename", async () => {
106
+ const deferred = convertOpenApiToSmithy(spec, { ...options, deferNaming: true });
107
+ await expect(
108
+ finalize(deferred, {
109
+ "clash.json": [{ op: "add", path: "/shapes/ns#GetApp", value: { type: "structure" } }],
110
+ }),
111
+ ).rejects.toThrow(/already taken/);
112
+ });
113
+ });
@@ -190,14 +190,11 @@ export const errorUnionAlias = (
190
190
  opName: string,
191
191
  errorNames: readonly string[],
192
192
  commonRef: string,
193
- ): string =>
194
- `export type ${opName}Error = ${[...errorNames, commonRef].join(" | ")};`;
193
+ ): string => `export type ${opName}Error = ${[...errorNames, commonRef].join(" | ")};`;
195
194
 
196
195
  /** Namespaced barrel: `export * as name from "./file.ts";` per entry. */
197
196
  export const barrel = (
198
197
  header: string,
199
198
  entries: ReadonlyArray<{ name: string; path: string }>,
200
199
  ): string =>
201
- header +
202
- entries.map((e) => `export * as ${e.name} from ${q(e.path)};`).join("\n") +
203
- "\n";
200
+ header + entries.map((e) => `export * as ${e.name} from ${q(e.path)};`).join("\n") + "\n";
@@ -10,21 +10,23 @@
10
10
  * Lives here so the shared {@link runGeneratorCli} and the providers with
11
11
  * their own pipelines run the identical step.
12
12
  */
13
+ import { spawn } from "node:child_process";
13
14
  import { Console, Effect } from "effect";
14
15
 
15
16
  /** Run a dev-time tool, failing the generate run if it does. */
16
- export const runTool = (
17
- argv: readonly string[],
18
- ): Effect.Effect<void, never, never> =>
17
+ export const runTool = (argv: readonly string[]): Effect.Effect<void, never, never> =>
19
18
  Effect.tryPromise({
20
19
  try: () =>
21
- Bun.spawn([...argv], { stdout: "inherit", stderr: "inherit" }).exited,
20
+ new Promise<number | null>((resolve, reject) => {
21
+ const [command, ...args] = argv;
22
+ spawn(command!, args, { stdio: ["ignore", "inherit", "inherit"] })
23
+ .on("error", reject)
24
+ .on("exit", resolve);
25
+ }),
22
26
  catch: (cause) => new Error(`${argv[0]} failed to start: ${cause}`),
23
27
  }).pipe(
24
28
  Effect.flatMap((code) =>
25
- code === 0
26
- ? Effect.void
27
- : Effect.die(new Error(`${argv.join(" ")} exited with ${code}`)),
29
+ code === 0 ? Effect.void : Effect.die(new Error(`${argv.join(" ")} exited with ${code}`)),
28
30
  ),
29
31
  Effect.catchCause((cause) => Effect.die(cause)),
30
32
  );
@@ -32,7 +34,7 @@ export const runTool = (
32
34
  /** Format a generated directory in place. */
33
35
  export const formatGenerated = (dir: string) =>
34
36
  Effect.flatMap(Console.log(`\n🧹 Formatting ${dir}`), () =>
35
- runTool(["bunx", "oxfmt", dir]),
37
+ runTool(["pnpm", "exec", "oxfmt", dir]),
36
38
  );
37
39
 
38
40
  /**
@@ -41,7 +43,7 @@ export const formatGenerated = (dir: string) =>
41
43
  */
42
44
  export const lintAndFormatGenerated = (dir: string) =>
43
45
  Effect.flatMap(Console.log(`\n🧹 Linting and formatting ${dir}`), () =>
44
- Effect.flatMap(runTool(["bunx", "oxlint", "--fix", dir]), () =>
45
- runTool(["bunx", "oxfmt", dir]),
46
+ Effect.flatMap(runTool(["pnpm", "exec", "oxlint", "--fix", dir]), () =>
47
+ runTool(["pnpm", "exec", "oxfmt", dir]),
46
48
  ),
47
49
  );
@@ -0,0 +1,89 @@
1
+ import { execFileSync } from "node:child_process";
2
+ import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
3
+ import { tmpdir } from "node:os";
4
+ import { dirname, join } from "node:path";
5
+ import { afterEach, describe, expect, it } from "vitest";
6
+ import { lastChangeDate, specUpdatedAt, stampGeneratedAt } from "./generated-at.ts";
7
+
8
+ describe("stampGeneratedAt", () => {
9
+ let dir: string;
10
+ afterEach(() => rmSync(dir, { recursive: true, force: true }));
11
+
12
+ const setup = (pkg: object) => {
13
+ dir = mkdtempSync(join(tmpdir(), "generated-at-"));
14
+ writeFileSync(join(dir, "package.json"), `${JSON.stringify(pkg, null, 2)}\n`);
15
+ };
16
+ const read = () => readFileSync(join(dir, "package.json"), "utf8");
17
+
18
+ it("adds distilled.generatedAt as a UTC date and keeps the other fields in order", () => {
19
+ setup({ name: "@distilled.cloud/x", version: "1.0.0", scripts: { generate: "g" } });
20
+ const stamp = stampGeneratedAt(dir, {
21
+ now: new Date("2026-10-08T23:30:00-05:00"),
22
+ specUpdatedAt: "2026-10-03",
23
+ });
24
+ expect(stamp).toEqual({ generatedAt: "2026-10-09", specUpdatedAt: "2026-10-03" });
25
+ const text = read();
26
+ expect(Object.keys(JSON.parse(text))).toEqual(["name", "version", "scripts", "distilled"]);
27
+ expect(JSON.parse(text).distilled).toEqual({
28
+ generatedAt: "2026-10-09",
29
+ specUpdatedAt: "2026-10-03",
30
+ });
31
+ expect(text.endsWith("}\n")).toBe(true);
32
+ });
33
+
34
+ it("updates existing dates and keeps other distilled fields", () => {
35
+ setup({ name: "x", distilled: { other: true, generatedAt: "2025-01-01" } });
36
+ stampGeneratedAt(dir, { now: new Date("2026-10-08T12:00:00Z"), specUpdatedAt: "2026-10-01" });
37
+ expect(JSON.parse(read()).distilled).toEqual({
38
+ other: true,
39
+ generatedAt: "2026-10-08",
40
+ specUpdatedAt: "2026-10-01",
41
+ });
42
+ });
43
+
44
+ it("keeps the existing spec date when the spec date is unknown", () => {
45
+ setup({ name: "x", distilled: { generatedAt: "2025-01-01", specUpdatedAt: "2024-12-31" } });
46
+ stampGeneratedAt(dir, { now: new Date("2026-10-08T12:00:00Z"), specUpdatedAt: undefined });
47
+ expect(JSON.parse(read()).distilled).toEqual({
48
+ generatedAt: "2026-10-08",
49
+ specUpdatedAt: "2024-12-31",
50
+ });
51
+ });
52
+
53
+ it("finds no spec date for a package without specs/", () => {
54
+ setup({ name: "x" });
55
+ expect(specUpdatedAt(dir)).toBeUndefined();
56
+ });
57
+ });
58
+
59
+ describe("lastChangeDate", () => {
60
+ let dir: string;
61
+ afterEach(() => rmSync(dir, { recursive: true, force: true }));
62
+
63
+ const sh = (cwd: string, ...args: string[]) => execFileSync("git", args, { cwd, stdio: "pipe" });
64
+ const commit = (cwd: string, file: string, date: string) => {
65
+ mkdirSync(join(cwd, dirname(file)), { recursive: true });
66
+ writeFileSync(join(cwd, file), date);
67
+ sh(cwd, "add", "-A");
68
+ execFileSync("git", ["commit", "-qm", file], {
69
+ cwd,
70
+ env: { ...process.env, GIT_COMMITTER_DATE: date, GIT_AUTHOR_DATE: date },
71
+ });
72
+ };
73
+
74
+ it("deepens a shallow clone past commits that do not touch the path", () => {
75
+ dir = mkdtempSync(join(tmpdir(), "spec-date-"));
76
+ const upstream = join(dir, "upstream");
77
+ mkdirSync(upstream);
78
+ sh(upstream, "init", "-q", "-b", "main");
79
+ sh(upstream, "config", "user.email", "t@t");
80
+ sh(upstream, "config", "user.name", "t");
81
+ sh(upstream, "config", "uploadpack.allowFilter", "true");
82
+ commit(upstream, "specs/a.json", "2026-09-30T10:00:00Z");
83
+ commit(upstream, "specs/a.json", "2026-10-03T23:30:00-05:00");
84
+ commit(upstream, ".meta/x.ts", "2026-10-05T10:00:00Z");
85
+ sh(dir, "clone", "-q", "--depth=1", `file://${upstream}`, "mirror");
86
+ // 23:30 at UTC-5 is the next day in UTC.
87
+ expect(lastChangeDate(join(dir, "mirror"), "specs")).toBe("2026-10-04");
88
+ });
89
+ });
@@ -0,0 +1,88 @@
1
+ /**
2
+ * Records, in the package's `package.json`, two UTC `YYYY-MM-DD` dates:
3
+ *
4
+ * - `distilled.generatedAt` — when the SDK was last generated.
5
+ * - `distilled.specUpdatedAt` — when the spec it was generated from last
6
+ * changed: the newest commit at or before the pinned mirror commit that
7
+ * touched the mirror's `specs/` directory.
8
+ *
9
+ * Every successful generator run calls this, so both dates land in the same
10
+ * commit as the regenerated code and ship to npm with the package. Dates (not
11
+ * timestamps) keep repeat runs on the same day from churning the manifest.
12
+ */
13
+ import { execFileSync } from "node:child_process";
14
+ import { existsSync, readdirSync, readFileSync, writeFileSync } from "node:fs";
15
+ import { join } from "node:path";
16
+ import { isLocalSpecs } from "./spec-path.ts";
17
+
18
+ /** A date in UTC, `YYYY-MM-DD`. */
19
+ export const generatedAtDate = (now: Date = new Date()): string => now.toISOString().slice(0, 10);
20
+
21
+ const git = (cwd: string, ...args: string[]): string =>
22
+ execFileSync("git", args, { cwd, encoding: "utf8", stdio: ["ignore", "pipe", "pipe"] }).trim();
23
+
24
+ /** Commits at a shallow boundary; git shows them as adding every file. */
25
+ const shallowCommits = (cwd: string): Set<string> => {
26
+ const file = git(cwd, "rev-parse", "--path-format=absolute", "--git-path", "shallow");
27
+ return new Set(existsSync(file) ? readFileSync(file, "utf8").split("\n").filter(Boolean) : []);
28
+ };
29
+
30
+ /**
31
+ * Date of the newest commit at or before `HEAD` of the repository at `cwd`
32
+ * that changed `pathspec`. Mirrors are checked out `--depth=1`, so this
33
+ * deepens the history (commits and trees only, no file content) until the
34
+ * answer is a real commit and not the shallow boundary.
35
+ */
36
+ export const lastChangeDate = (cwd: string, pathspec: string): string => {
37
+ for (let round = 0; round < 20; round++) {
38
+ const [sha, date] = git(cwd, "log", "-1", "--format=%H %cI", "HEAD", "--", pathspec).split(" ");
39
+ if (!sha) throw new Error(`no commit in ${cwd} touches ${pathspec}`);
40
+ if (!shallowCommits(cwd).has(sha)) return generatedAtDate(new Date(date!));
41
+ git(cwd, "fetch", "--quiet", "--deepen=50", "--filter=blob:none", "origin");
42
+ }
43
+ throw new Error(`gave up deepening ${cwd} to find the last change to ${pathspec}`);
44
+ };
45
+
46
+ /**
47
+ * When the package's spec last changed, or `undefined` if that cannot be
48
+ * known here: no `specs/` directory (a hand-written SDK), the mirror is not
49
+ * checked out, or specs come from the untracked `specs/.local` copy.
50
+ */
51
+ export const specUpdatedAt = (root: string): string | undefined => {
52
+ const specs = join(root, "specs");
53
+ if (isLocalSpecs() || !existsSync(specs)) return undefined;
54
+ const mirror = readdirSync(specs).find((d) => d.startsWith("spec-mirror-"));
55
+ if (mirror === undefined) return lastChangeDate(root, "specs");
56
+ const dir = join(specs, mirror);
57
+ // An uninitialised submodule is an empty directory with no `.git`.
58
+ return existsSync(join(dir, ".git")) ? lastChangeDate(dir, "specs") : undefined;
59
+ };
60
+
61
+ export interface GeneratedAtStamp {
62
+ readonly generatedAt: string;
63
+ /** `undefined` when unknown; the existing value in `package.json` is kept. */
64
+ readonly specUpdatedAt: string | undefined;
65
+ }
66
+
67
+ /**
68
+ * Set `distilled.generatedAt` and `distilled.specUpdatedAt` in
69
+ * `<root>/package.json`; returns the dates written.
70
+ */
71
+ export const stampGeneratedAt = (
72
+ root: string,
73
+ options: { readonly now?: Date; readonly specUpdatedAt?: string | undefined } = {},
74
+ ): GeneratedAtStamp => {
75
+ const generatedAt = generatedAtDate(options.now);
76
+ const spec = "specUpdatedAt" in options ? options.specUpdatedAt : specUpdatedAt(root);
77
+ const file = join(root, "package.json");
78
+ const text = readFileSync(file, "utf8");
79
+ const pkg = JSON.parse(text);
80
+ pkg.distilled = {
81
+ ...pkg.distilled,
82
+ generatedAt,
83
+ ...(spec === undefined ? {} : { specUpdatedAt: spec }),
84
+ };
85
+ const next = `${JSON.stringify(pkg, null, 2)}\n`;
86
+ if (next !== text) writeFileSync(file, next);
87
+ return { generatedAt, specUpdatedAt: spec };
88
+ };