@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
@@ -0,0 +1,141 @@
1
+ import { existsSync, mkdirSync, mkdtempSync, readdirSync, 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 { auditPackage } from "./patch-audit.js";
6
+ const dirs = [];
7
+ afterEach(() => {
8
+ for (const d of dirs.splice(0))
9
+ rmSync(d, { recursive: true, force: true });
10
+ });
11
+ // ---------------------------------------------------------------------------
12
+ const PATCHES_TS = join(import.meta.dirname, "patches.ts");
13
+ /**
14
+ * A package: `spec.json` lists field names, and every field becomes a
15
+ * member of `x#Thing`. `patches/spec/` edit the spec in the convert script
16
+ * itself (the way Railway patches its GraphQL schema, out of
17
+ * finalizeConvert's reach); `patches/svc/` are Smithy ops applied in
18
+ * finalizeConvert, whose transform drops a member named `dropped`.
19
+ */
20
+ const convertFixture = (patches) => {
21
+ const parent = mkdtempSync(join(tmpdir(), "patch-audit-convert-"));
22
+ dirs.push(parent);
23
+ const root = join(parent, "pkg");
24
+ mkdirSync(join(root, "scripts"), { recursive: true });
25
+ writeFileSync(join(root, "package.json"), JSON.stringify({ name: "fixture", scripts: { convert: "node scripts/convert.ts" } }));
26
+ writeFileSync(join(root, "spec.json"), JSON.stringify({ fields: { a: true } }));
27
+ writeFileSync(join(root, "scripts", "convert.ts"), `
28
+ import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
29
+ import { join } from "node:path";
30
+ import { applyRfc6902Files, finalizeConvert, isSmithyPatchPath, listRfc6902PatchFiles } from ${JSON.stringify(PATCHES_TS)};
31
+ const root = join(import.meta.dirname, "..");
32
+ const spec = JSON.parse(readFileSync(join(root, "spec.json"), "utf8"));
33
+ const files = await listRfc6902PatchFiles(join(root, "patches", "spec"));
34
+ const applied = await applyRfc6902Files(spec, files, { include: (op) => !isSmithyPatchPath(op.path) });
35
+ if (applied.errors.length) throw new Error(applied.errors.join("\\n"));
36
+ const members = Object.fromEntries(Object.keys(spec.fields).map((k) => [k, { target: "smithy.api#String" }]));
37
+ mkdirSync(join(root, ".generated-specs"), { recursive: true });
38
+ writeFileSync(join(root, ".generated-specs", "svc.json"), JSON.stringify({ smithy: "2.0", shapes: { "x#Thing": { type: "structure", members } } }));
39
+ await finalizeConvert({
40
+ root,
41
+ operationNaming: "as-is",
42
+ transform: (model) => { delete model.shapes["x#Thing"].members.dropped; },
43
+ });
44
+ `);
45
+ for (const [key, ops] of Object.entries(patches)) {
46
+ const dir = key.startsWith("spec/") ? "spec" : "svc";
47
+ mkdirSync(join(root, "patches", dir), { recursive: true });
48
+ const name = key.replace(/^spec\//, "");
49
+ writeFileSync(join(root, "patches", dir, name), JSON.stringify({ patches: ops }));
50
+ }
51
+ mkdirSync(join(root, ".generated-specs"));
52
+ writeFileSync(join(root, ".generated-specs", "svc.json"), "committed\n");
53
+ return root;
54
+ };
55
+ const addField = (name) => ({ op: "add", path: `/fields/${name}`, value: true });
56
+ const addMember = (name) => ({
57
+ op: "add",
58
+ path: `/shapes/x#Thing/members/${name}`,
59
+ value: { target: "smithy.api#String" },
60
+ });
61
+ describe("convert-stage patch audit", () => {
62
+ test("judges Smithy files in memory and the rest by convert", async () => {
63
+ const root = convertFixture({
64
+ "spec/1-spec.json": [addField("s")],
65
+ "2-member.json": [addMember("b")],
66
+ "3-noop.json": [{ op: "replace", path: "/shapes/x#Thing/type", value: "structure" }],
67
+ "4-dropped.json": [addMember("dropped")],
68
+ "5-uses-b.json": [{ op: "add", path: "/shapes/x#Thing/members/b/traits", value: {} }],
69
+ });
70
+ const result = await auditPackage(root, { jobs: 2 });
71
+ if (result.kind !== "audited")
72
+ throw new Error(result.reason);
73
+ expect(Object.fromEntries(result.files.map((f) => [f.file.key, f.verdict]))).toEqual({
74
+ "spec/1-spec.json": { kind: "needed", diff: ["+ Thing/members/s"] },
75
+ "svc/2-member.json": { kind: "depended", error: expect.stringMatching(/members\/b/) },
76
+ "svc/3-noop.json": { kind: "unused" },
77
+ // The transform removes it again, so it changes nothing.
78
+ "svc/4-dropped.json": { kind: "unused" },
79
+ "svc/5-uses-b.json": { kind: "needed", diff: ["+ Thing/members/b/traits"] },
80
+ });
81
+ expect(result.judged).toEqual({ inMemory: 4, perFile: 1 });
82
+ });
83
+ test("--ops in memory finds the dead op", async () => {
84
+ const root = convertFixture({
85
+ "mixed.json": [
86
+ addMember("b"),
87
+ { op: "replace", path: "/shapes/x#Thing/type", value: "structure" },
88
+ ],
89
+ });
90
+ const result = await auditPackage(root, { ops: true, jobs: 1 });
91
+ if (result.kind !== "audited")
92
+ throw new Error(result.reason);
93
+ expect(result.files[0].deadOps).toEqual([1]);
94
+ });
95
+ test("a file that only orders keys is needed", async () => {
96
+ const root = convertFixture({
97
+ "1-member.json": [addMember("b")],
98
+ "2-order.json": [
99
+ {
100
+ op: "move",
101
+ from: "/shapes/x#Thing/members/b",
102
+ path: "/shapes/x#Thing/members/b",
103
+ before: "a",
104
+ },
105
+ ],
106
+ });
107
+ const result = await auditPackage(root, { jobs: 1 });
108
+ if (result.kind !== "audited")
109
+ throw new Error(result.reason);
110
+ expect(result.files.find((f) => f.file.key === "svc/2-order.json").verdict).toEqual({
111
+ kind: "needed",
112
+ diff: ["(key order only)"],
113
+ });
114
+ });
115
+ test("leaves the package as it was and removes its scratch copies", async () => {
116
+ const root = convertFixture({
117
+ "member.json": [addMember("b")],
118
+ "spec/s.json": [addField("s")],
119
+ });
120
+ const result = await auditPackage(root, { jobs: 2 });
121
+ expect(result.kind).toBe("audited");
122
+ expect(readFileSync(join(root, ".generated-specs", "svc.json"), "utf8")).toBe("committed\n");
123
+ expect(readdirSync(join(root, ".."))).toEqual(["pkg"]);
124
+ expect(existsSync(join(root, ".audit-request.json"))).toBe(false);
125
+ });
126
+ test("a patch that changes nothing has no effect", async () => {
127
+ const root = convertFixture({
128
+ "noop.json": [{ op: "replace", path: "/shapes/x#Thing/type", value: "structure" }],
129
+ });
130
+ const result = await auditPackage(root, { jobs: 1 });
131
+ if (result.kind !== "audited")
132
+ throw new Error(result.reason);
133
+ expect(result.files[0].verdict).toEqual({ kind: "unused" });
134
+ });
135
+ test("a baseline that fails to convert is skipped", async () => {
136
+ const root = convertFixture({ "stale.json": [{ op: "remove", path: "/shapes/x#Gone" }] });
137
+ const result = await auditPackage(root, { jobs: 1 });
138
+ expect(result.kind).toBe("skipped");
139
+ });
140
+ });
141
+ //# sourceMappingURL=patch-audit.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"patch-audit.test.js","sourceRoot":"","sources":["../../src/codegen/patch-audit.test.ts"],"names":[],"mappings":"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CAAC,CAAC"}
@@ -51,6 +51,22 @@ export declare const syncServiceOperations: (model: {
51
51
  export declare const danglingTargets: (model: {
52
52
  shapes?: Record<string, any>;
53
53
  }) => string[];
54
+ export interface FinalizeOptions {
55
+ readonly root: string;
56
+ readonly outDir?: string;
57
+ readonly patchesDir?: string | false;
58
+ /**
59
+ * The directory holding a model's patches, relative to `patchesDir`.
60
+ * Default `<resource>`; `""` for a single-model package whose patches sit
61
+ * at the root of `patchesDir`; `undefined` for none.
62
+ */
63
+ readonly patchesFor?: (resource: string) => string | undefined;
64
+ readonly exclude?: (file: string) => boolean;
65
+ readonly include?: (resource: string) => boolean;
66
+ readonly transform?: (model: any, resource: string) => string | void;
67
+ readonly operationNaming?: "as-is" | "verbNoun";
68
+ readonly onStalePatch?: OnStalePatch;
69
+ }
54
70
  /**
55
71
  * Last step of every convert: Smithy RFC-6902 patches, then verbNoun
56
72
  * operation names, then an optional model transform, then a reference
@@ -61,17 +77,50 @@ export declare const danglingTargets: (model: {
61
77
  * ops that are not idempotent, and a `transform` may not be either, so
62
78
  * running this over a model that already went through it is an error —
63
79
  * re-run the package's `convert` instead.
80
+ *
81
+ * Under {@link PATCH_AUDIT_ENV} it also judges the requested patch files
82
+ * in memory (see `./patch-audit.ts`).
64
83
  */
65
- export declare const finalizeConvert: (o: {
66
- readonly root: string;
67
- readonly outDir?: string;
68
- readonly patchesDir?: string | false;
69
- readonly exclude?: (file: string) => boolean;
70
- readonly include?: (resource: string) => boolean;
71
- readonly transform?: (model: any, resource: string) => string | void;
72
- readonly operationNaming?: "as-is" | "verbNoun";
73
- readonly onStalePatch?: OnStalePatch;
74
- }) => Promise<void>;
84
+ export declare const finalizeConvert: (o: FinalizeOptions) => Promise<void>;
85
+ /**
86
+ * Path of a JSON file finalizeConvert adds each model's deferred rename to
87
+ * (`{ <model>: { <upstream id>: <final id> } }`). Set by
88
+ * `pnpm patches:names`, which tells a patch author the upstream name of a
89
+ * shape they see in `.generated-specs`.
90
+ */
91
+ export declare const RENAME_MAP_ENV = "DISTILLED_RENAME_MAP";
92
+ /**
93
+ * Path of a JSON request (`{ keys: string[], ops: boolean }`) asking
94
+ * finalizeConvert to judge those patch files in memory. Set only by
95
+ * `pnpm patches:audit` on a scratch copy of the package; the models it
96
+ * writes are the normal, fully patched ones.
97
+ *
98
+ * Each verdict is printed to stdout as one line, {@link PATCH_AUDIT_MARKER}
99
+ * followed by JSON. A requested key no finalizeConvert call owns (its ops
100
+ * are applied somewhere else, e.g. before conversion) gets no line, and the
101
+ * audit judges it by re-running convert.
102
+ */
103
+ export declare const PATCH_AUDIT_ENV = "DISTILLED_PATCH_AUDIT";
104
+ export declare const PATCH_AUDIT_MARKER = "@@distilled-patch-audit ";
105
+ /** One finalizeConvert's answer for one patch file. */
106
+ export interface InMemoryVerdict {
107
+ readonly key: string;
108
+ /** Path of the model relative to the package's `.generated-specs`. */
109
+ readonly model: string;
110
+ readonly verdict: {
111
+ readonly kind: "unused";
112
+ } | {
113
+ readonly kind: "needed";
114
+ readonly diff: readonly string[];
115
+ } | {
116
+ readonly kind: "depended";
117
+ readonly error: string;
118
+ } | {
119
+ readonly kind: "baseline";
120
+ readonly error: string;
121
+ };
122
+ readonly deadOps: readonly number[];
123
+ }
75
124
  /**
76
125
  * Metadata marker stamped by {@link finalizeConvert}. Guards against a
77
126
  * second pass over the same file (see the note on finalizeConvert).
@@ -1 +1 @@
1
- {"version":3,"file":"patches.d.ts","sourceRoot":"","sources":["../../src/codegen/patches.ts"],"names":[],"mappings":"AAUA,OAAO,EAGL,KAAK,kBAAkB,EAExB,MAAM,kBAAkB,CAAC;AAG1B,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,MAAM,CAAC;AAE3C,MAAM,WAAW,kBAAkB;IACjC,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB;AAED,kEAAkE;AAClE,eAAO,M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,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,sEAAsE;IACtE,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,OAAO,EACZ;QAAE,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAA;KAAE,GAC3B;QAAE,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;QAAC,QAAQ,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,CAAA;KAAE,GAC7D;QAAE,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC;QAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;KAAE,GACrD;QAAE,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC;QAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;IAC1D,QAAQ,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;CACrC;AA+DD;;;GAGG;AACH,eAAO,MAAM,aAAa,wBAAwB,CAAC"}
@@ -1,19 +1,18 @@
1
1
  /**
2
- * RFC-6902 patch application for convert (dev-time only).
3
- *
4
- * OpenAPI ops (`/paths`, `/components`, …) apply to the spec before
5
- * conversion; Smithy ops (`/shapes`, `/metadata`, `/smithy`) apply to the
6
- * model after conversion. `.generated-specs` is the patched model.
7
- * `scripts/generate.ts` does not apply patches.
2
+ * RFC-6902 patch application (dev-time only). Every package's convert ends
3
+ * in {@link finalizeConvert}, which applies the Smithy ops (`/shapes`,
4
+ * `/metadata`, `/smithy`) of `patches/<model>/` to the freshly converted
5
+ * model, under the names the spec gives, then the deferred names; so
6
+ * `.generated-specs` is the patched model and generate never patches.
8
7
  */
8
+ import { existsSync, readFileSync, writeFileSync } from "node:fs";
9
9
  import * as fs from "node:fs/promises";
10
10
  import * as path from "node:path";
11
11
  import { applyOperation, isStaleTargetError, } from "../json-patch.js";
12
- import { verbNounSmithyModel } from "./rewrite-operation-ids.js";
12
+ import { diffModels } from "./model-diff.js";
13
+ import { applyDeferredRename, RENAME_METADATA_KEY, verbNounSmithyModel, } from "./rewrite-operation-ids.js";
13
14
  /** Smithy-model JSON pointers — OpenAPI has no `/shapes` tree. */
14
- export const isSmithyPatchPath = (pointer) => pointer.startsWith("/shapes") ||
15
- pointer.startsWith("/metadata") ||
16
- pointer.startsWith("/smithy");
15
+ export const isSmithyPatchPath = (pointer) => pointer.startsWith("/shapes") || pointer.startsWith("/metadata") || pointer.startsWith("/smithy");
17
16
  const exists = async (p) => {
18
17
  try {
19
18
  await fs.access(p);
@@ -72,8 +71,7 @@ const skipList = () => {
72
71
  }
73
72
  return list;
74
73
  };
75
- const skipsFile = (list, file) => list !== undefined &&
76
- (list.all || list.files.some((entry) => skipMatches(file, entry)));
74
+ const skipsFile = (list, file) => list !== undefined && (list.all || list.files.some((entry) => skipMatches(file, entry)));
77
75
  const skipsOp = (list, file, index) => {
78
76
  if (list === undefined)
79
77
  return false;
@@ -94,8 +92,8 @@ export const listRfc6902PatchFiles = async (dir) => {
94
92
  const skip = skipList();
95
93
  return (await fs.readdir(dir))
96
94
  .filter((f) => f.endsWith(".json"))
97
- .sort((a, b) => Number(a.endsWith(".manual.json")) -
98
- Number(b.endsWith(".manual.json")) || a.localeCompare(b))
95
+ .sort((a, b) => Number(a.endsWith(".manual.json")) - Number(b.endsWith(".manual.json")) ||
96
+ a.localeCompare(b))
99
97
  .map((f) => path.join(dir, f))
100
98
  .filter((f) => !skipsFile(skip, f));
101
99
  };
@@ -158,10 +156,7 @@ export const syncServiceOperations = (model) => {
158
156
  const current = def.operations ?? [];
159
157
  const kept = current.filter((o) => shapes[o.target]?.type === "operation");
160
158
  const listed = new Set(kept.map((o) => o.target));
161
- const after = [
162
- ...kept,
163
- ...opIds.filter((id) => !listed.has(id)).map((target) => ({ target })),
164
- ];
159
+ const after = [...kept, ...opIds.filter((id) => !listed.has(id)).map((target) => ({ target }))];
165
160
  if (JSON.stringify(current) !== JSON.stringify(after)) {
166
161
  def.operations = after;
167
162
  changed++;
@@ -202,6 +197,125 @@ export const danglingTargets = (model) => {
202
197
  walk(id, def);
203
198
  return out;
204
199
  };
200
+ const loadSmithyPatches = async (patchesDir, dir) => {
201
+ if (dir === undefined)
202
+ return [];
203
+ const out = [];
204
+ for (const file of await listRfc6902PatchFiles(path.join(patchesDir, dir))) {
205
+ const parsed = JSON.parse(await fs.readFile(file, "utf8"));
206
+ const key = path.relative(patchesDir, file).split(path.sep).join("/");
207
+ const spec = (parsed.patches ?? []).find((op) => !isSmithyPatchPath(op.path));
208
+ if (spec) {
209
+ // Patches edit the converted model under upstream names, never the
210
+ // spec: one kind of patch, and one the audit can judge in memory.
211
+ throw new Error(`patches/${key} [${spec.op} ${spec.path}]: patches target the Smithy model (/shapes, /metadata), not the spec — see the distilled-sdk-patch skill`);
212
+ }
213
+ out.push({ key, file, ops: parsed.patches ?? [] });
214
+ }
215
+ return out;
216
+ };
217
+ /**
218
+ * One model through the finalize steps: Smithy patches, verbNoun names,
219
+ * the package's transform, the service operation list, and the reference
220
+ * check. `skip` leaves out a patch file (`key`) or one of its ops
221
+ * (`key:index`); `quiet` silences the progress lines for audit re-runs.
222
+ */
223
+ const finalizeModel = (model, resource, patches, o, skip, quiet) => {
224
+ const log = quiet ? () => { } : console.log;
225
+ const deferred = model.metadata?.[RENAME_METADATA_KEY];
226
+ if (deferred && !quiet)
227
+ recordRename(resource, deferred);
228
+ const envSkip = skipList();
229
+ let files = 0;
230
+ let applied = 0;
231
+ let stale = 0;
232
+ const errors = [];
233
+ for (const p of patches) {
234
+ if (skip && skip.key === p.key && skip.index === undefined)
235
+ continue;
236
+ files++;
237
+ for (const [index, op] of p.ops.entries()) {
238
+ if (skip && skip.key === p.key && skip.index === index)
239
+ continue;
240
+ if (skipsOp(envSkip, p.file, index))
241
+ continue;
242
+ try {
243
+ // A cloned op: `add`/`replace` insert the value by reference, and
244
+ // the audit applies the same parsed ops to many fresh models.
245
+ applyOperation(model, structuredClone(op));
246
+ applied++;
247
+ }
248
+ catch (e) {
249
+ const line = `${p.key} [${op.op} ${op.path}]`;
250
+ const msg = e instanceof Error ? e.message : String(e);
251
+ if (isStaleTargetError(e) && o.onStalePatch === "warn") {
252
+ stale++;
253
+ if (!quiet)
254
+ console.warn(` ⚠️ stale: ${line}`);
255
+ }
256
+ else {
257
+ errors.push(`${line}: ${isStaleTargetError(e) ? `stale target (${msg})` : msg}`);
258
+ }
259
+ }
260
+ }
261
+ }
262
+ if (errors.length) {
263
+ if (!quiet)
264
+ for (const err of errors)
265
+ console.error(`❌ bad patch: ${err}`);
266
+ return {
267
+ ok: false,
268
+ stage: "patch",
269
+ error: `${errors.length} patch operation(s) failed for ${resource}: ${errors[0]}`,
270
+ };
271
+ }
272
+ if (applied > 0) {
273
+ log(` patched ${resource}: ${files} file(s), ${applied} op(s)` +
274
+ (stale ? `, ${stale} stale` : ""));
275
+ }
276
+ try {
277
+ const renamed = applyDeferredRename(model);
278
+ if (renamed > 0)
279
+ log(` named ${resource}: ${renamed} shape(s)`);
280
+ }
281
+ catch (e) {
282
+ const error = `${resource}: ${e instanceof Error ? e.message : String(e)}`;
283
+ if (!quiet)
284
+ console.error(`❌ ${error}`);
285
+ return { ok: false, stage: "rename", error };
286
+ }
287
+ if ((o.operationNaming ?? "verbNoun") === "verbNoun") {
288
+ const { renamed, collisions } = verbNounSmithyModel(model);
289
+ if (renamed > 0)
290
+ log(` verbNoun ${resource}: renamed ${renamed} operation(s)`);
291
+ if (!quiet) {
292
+ for (const c of collisions) {
293
+ console.warn(` ⚠️ verbNoun collision ${resource}: ${c} (kept original)`);
294
+ }
295
+ }
296
+ }
297
+ const note = o.transform?.(model, resource);
298
+ if (note)
299
+ log(` ${note}`);
300
+ syncServiceOperations(model);
301
+ const dangling = danglingTargets(model);
302
+ if (dangling.length) {
303
+ if (!quiet) {
304
+ for (const d of dangling.slice(0, 5))
305
+ console.error(` ❌ ${d}`);
306
+ if (dangling.length > 5)
307
+ console.error(` … ${dangling.length - 5} more`);
308
+ }
309
+ return {
310
+ ok: false,
311
+ stage: "dangling",
312
+ error: `${resource}: ${dangling.length} dangling target(s), e.g. ${dangling[0]}`,
313
+ };
314
+ }
315
+ model.metadata = { ...model.metadata, [FINALIZED_KEY]: true };
316
+ return { ok: true, model };
317
+ };
318
+ const modelText = (model) => `${JSON.stringify(model, null, 2)}\n`;
205
319
  /**
206
320
  * Last step of every convert: Smithy RFC-6902 patches, then verbNoun
207
321
  * operation names, then an optional model transform, then a reference
@@ -212,15 +326,17 @@ export const danglingTargets = (model) => {
212
326
  * ops that are not idempotent, and a `transform` may not be either, so
213
327
  * running this over a model that already went through it is an error —
214
328
  * re-run the package's `convert` instead.
329
+ *
330
+ * Under {@link PATCH_AUDIT_ENV} it also judges the requested patch files
331
+ * in memory (see `./patch-audit.ts`).
215
332
  */
216
333
  export const finalizeConvert = async (o) => {
334
+ const specsRoot = path.resolve(o.root, ".generated-specs");
217
335
  const specsDir = path.resolve(o.root, o.outDir ?? ".generated-specs");
218
336
  if (!(await exists(specsDir)))
219
337
  return;
220
- const patchesDir = o.patchesDir === false
221
- ? undefined
222
- : path.resolve(o.root, o.patchesDir ?? "patches");
223
- const naming = o.operationNaming ?? "verbNoun";
338
+ const patchesDir = o.patchesDir === false ? undefined : path.resolve(o.root, o.patchesDir ?? "patches");
339
+ const audit = patchesDir ? await readAuditRequest() : undefined;
224
340
  const walk = async (dir) => {
225
341
  const out = [];
226
342
  for (const ent of await fs.readdir(dir, { withFileTypes: true })) {
@@ -228,8 +344,7 @@ export const finalizeConvert = async (o) => {
228
344
  if (ent.isDirectory()) {
229
345
  out.push(...(await walk(p)));
230
346
  }
231
- else if (ent.name.endsWith(".json") &&
232
- !(o.exclude?.(ent.name) ?? false)) {
347
+ else if (ent.name.endsWith(".json") && !(o.exclude?.(ent.name) ?? false)) {
233
348
  out.push(p);
234
349
  }
235
350
  }
@@ -241,59 +356,114 @@ export const finalizeConvert = async (o) => {
241
356
  const resource = path.basename(modelPath, ".json");
242
357
  if (o.include && !o.include(resource))
243
358
  continue;
244
- const model = JSON.parse(await fs.readFile(modelPath, "utf8"));
359
+ const text = await fs.readFile(modelPath, "utf8");
360
+ const model = JSON.parse(text);
245
361
  if (model.metadata?.[FINALIZED_KEY]) {
246
362
  throw new Error(`${path.relative(o.root, modelPath)} was already finalized — finalizeConvert is not idempotent; re-run this package's convert from the spec instead`);
247
363
  }
248
- if (patchesDir) {
249
- const patchFiles = await listRfc6902PatchFiles(path.join(patchesDir, resource));
250
- const applied = await applyRfc6902Files(model, patchFiles, {
251
- onStalePatch: o.onStalePatch,
252
- include: (op) => isSmithyPatchPath(op.path),
253
- label: (f) => `${resource}/${path.basename(f)}`,
254
- });
255
- if (applied.errors.length) {
256
- for (const err of applied.errors)
257
- console.error(`❌ bad patch: ${err}`);
258
- throw new Error(`${applied.errors.length} patch operation(s) failed for ${resource} — fix the pointers or delete the patch`);
364
+ const patches = patchesDir
365
+ ? await loadSmithyPatches(patchesDir, o.patchesFor ? o.patchesFor(resource) : resource)
366
+ : [];
367
+ const run = finalizeModel(model, resource, patches, o, undefined, false);
368
+ const label = path.relative(specsRoot, modelPath).split(path.sep).join("/");
369
+ if (!run.ok) {
370
+ if (audit)
371
+ auditModel(audit, label, resource, text, patches, o, run);
372
+ if (run.stage === "patch") {
373
+ throw new Error(`${run.error.split(": ")[0]} — fix the pointers or delete the patch`);
259
374
  }
260
- if (applied.applied > 0) {
261
- console.log(` patched ${resource}: ${applied.files} file(s), ${applied.applied} op(s)` +
262
- (applied.stale ? `, ${applied.stale} stale` : ""));
263
- }
264
- }
265
- if (naming === "verbNoun") {
266
- const { renamed, collisions } = verbNounSmithyModel(model);
267
- if (renamed > 0) {
268
- console.log(` verbNoun ${resource}: renamed ${renamed} operation(s)`);
269
- }
270
- for (const c of collisions) {
271
- console.warn(` ⚠️ verbNoun collision ${resource}: ${c} (kept original)`);
272
- }
273
- }
274
- const note = o.transform?.(model, resource);
275
- if (note)
276
- console.log(` ${note}`);
277
- syncServiceOperations(model);
278
- const dangling = danglingTargets(model);
279
- if (dangling.length) {
280
- broken.push(`${resource}: ${dangling.length} dangling target(s)`);
281
- for (const d of dangling.slice(0, 5))
282
- console.error(` ❌ ${d}`);
283
- if (dangling.length > 5) {
284
- console.error(` … ${dangling.length - 5} more`);
375
+ if (run.stage === "rename") {
376
+ throw new Error(`${run.error} — a patch added a shape under a name the rename needs`);
285
377
  }
378
+ broken.push(run.error.split(", e.g.")[0]);
286
379
  // Leave the unfinalized model on disk for inspection; never stamp
287
380
  // a model that generate cannot compile.
288
381
  continue;
289
382
  }
290
- model.metadata = { ...model.metadata, [FINALIZED_KEY]: true };
291
- await fs.writeFile(modelPath, `${JSON.stringify(model, null, 2)}\n`);
383
+ const finalized = modelText(run.model);
384
+ await fs.writeFile(modelPath, finalized);
385
+ if (audit)
386
+ auditModel(audit, label, resource, text, patches, o, { ok: true, text: finalized });
292
387
  }
293
388
  if (broken.length) {
294
389
  throw new Error(`finalizeConvert: ${broken.length} model(s) reference shapes that do not exist:\n ${broken.join("\n ")}`);
295
390
  }
296
391
  };
392
+ /**
393
+ * Path of a JSON file finalizeConvert adds each model's deferred rename to
394
+ * (`{ <model>: { <upstream id>: <final id> } }`). Set by
395
+ * `pnpm patches:names`, which tells a patch author the upstream name of a
396
+ * shape they see in `.generated-specs`.
397
+ */
398
+ export const RENAME_MAP_ENV = "DISTILLED_RENAME_MAP";
399
+ const recordRename = (resource, rename) => {
400
+ const file = process.env[RENAME_MAP_ENV];
401
+ if (!file)
402
+ return;
403
+ const all = existsSync(file) ? JSON.parse(readFileSync(file, "utf8")) : {};
404
+ all[resource] = { ...all[resource], ...rename };
405
+ writeFileSync(file, JSON.stringify(all));
406
+ };
407
+ // ---------------------------------------------------------------------------
408
+ // in-memory patch audit
409
+ /**
410
+ * Path of a JSON request (`{ keys: string[], ops: boolean }`) asking
411
+ * finalizeConvert to judge those patch files in memory. Set only by
412
+ * `pnpm patches:audit` on a scratch copy of the package; the models it
413
+ * writes are the normal, fully patched ones.
414
+ *
415
+ * Each verdict is printed to stdout as one line, {@link PATCH_AUDIT_MARKER}
416
+ * followed by JSON. A requested key no finalizeConvert call owns (its ops
417
+ * are applied somewhere else, e.g. before conversion) gets no line, and the
418
+ * audit judges it by re-running convert.
419
+ */
420
+ export const PATCH_AUDIT_ENV = "DISTILLED_PATCH_AUDIT";
421
+ export const PATCH_AUDIT_MARKER = "@@distilled-patch-audit ";
422
+ const readAuditRequest = async () => {
423
+ const file = process.env[PATCH_AUDIT_ENV];
424
+ if (!file)
425
+ return undefined;
426
+ const raw = JSON.parse(await fs.readFile(file, "utf8"));
427
+ return { keys: new Set(raw.keys), ops: raw.ops === true };
428
+ };
429
+ const emitVerdict = (v) => {
430
+ process.stdout.write(`${PATCH_AUDIT_MARKER}${JSON.stringify(v)}\n`);
431
+ };
432
+ const auditModel = (audit, model, resource, text, patches, o, baseline) => {
433
+ const owned = patches.filter((p) => audit.keys.has(p.key) && p.ops.length > 0);
434
+ for (const p of owned) {
435
+ if (!baseline.ok) {
436
+ emitVerdict({
437
+ key: p.key,
438
+ model,
439
+ verdict: { kind: "baseline", error: baseline.error },
440
+ deadOps: [],
441
+ });
442
+ continue;
443
+ }
444
+ const judge = (index) => {
445
+ const run = finalizeModel(JSON.parse(text), resource, patches, o, { key: p.key, index }, true);
446
+ if (!run.ok)
447
+ return { kind: "depended", error: run.error };
448
+ const without = modelText(run.model);
449
+ if (without === baseline.text)
450
+ return { kind: "unused" };
451
+ const diff = diffModels(new Map([[model, baseline.text]]), new Map([[model, without]]));
452
+ // The committed model is compared byte for byte, so a patch that only
453
+ // orders keys (`before`, a `move` onto itself) is needed too.
454
+ return { kind: "needed", diff: diff.length === 0 ? ["(key order only)"] : diff };
455
+ };
456
+ const verdict = judge();
457
+ const deadOps = [];
458
+ if (audit.ops && verdict.kind === "needed" && p.ops.length > 1) {
459
+ for (let index = 0; index < p.ops.length; index++) {
460
+ if (judge(index).kind === "unused")
461
+ deadOps.push(index);
462
+ }
463
+ }
464
+ emitVerdict({ key: p.key, model, verdict, deadOps });
465
+ }
466
+ };
297
467
  /**
298
468
  * Metadata marker stamped by {@link finalizeConvert}. Guards against a
299
469
  * second pass over the same file (see the note on finalizeConvert).