@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,5 +1,5 @@
1
- import { describe, expect, test } from "bun:test";
2
- import { buildSchema, introspectionFromSchema } from "graphql";
1
+ import { stripTypeScriptTypes } from "node:module";
2
+ import { describe, expect, test } from "vitest";
3
3
  import { applyOperation } from "../json-patch.ts";
4
4
  import {
5
5
  convertGraphQLClient,
@@ -70,10 +70,7 @@ const fixture = {
70
70
  kind: "OBJECT",
71
71
  name: "ProjectConnection",
72
72
  fields: [
73
- field(
74
- "edges",
75
- required({ kind: "LIST", ofType: named("ProjectEdge") }),
76
- ),
73
+ field("edges", required({ kind: "LIST", ofType: named("ProjectEdge") })),
77
74
  field("pageInfo", required(named("PageInfo"))),
78
75
  ],
79
76
  },
@@ -110,21 +107,13 @@ describe("GraphQL Query SDK generator", () => {
110
107
  const output = generateGraphQLClient(model, options);
111
108
  expect(output).toContain("export interface Project");
112
109
  expect(output).toContain("export interface User");
113
- expect(output).toContain(
114
- 'export const Project: TypeMeta = { name: "Project", fields: {} };',
115
- );
110
+ expect(output).toContain('export const Project: TypeMeta = { name: "Project", fields: {} };');
116
111
  expect(output).toContain("export const Railway = {");
117
- expect(output).toContain(
118
- 'root("query", "me", User, undefined, undefined, globalErrors)',
119
- );
112
+ expect(output).toContain('root("query", "me", User, undefined, undefined, globalErrors)');
120
113
  expect(output).toContain('root("query", "project", Project');
121
114
  expect(output).toContain('rootConnection("query", "projects", Project');
122
- expect(output).toContain(
123
- "Query<ReadonlyArray<Project>, RailwayGlobalError>",
124
- );
125
- expect(output).toContain(
126
- 'connectionField("projects", Project, { first: "Int" })',
127
- );
115
+ expect(output).toContain("Query<ReadonlyArray<Project>, RailwayGlobalError>");
116
+ expect(output).toContain('connectionField("projects", Project, { first: "Int" })');
128
117
  expect(output).toContain('root("mutation", "projectCreate", Project');
129
118
  // Nullable GraphQL types include null; non-null ones do not.
130
119
  expect(output).toContain("readonly name: string | null;");
@@ -132,9 +121,7 @@ describe("GraphQL Query SDK generator", () => {
132
121
  expect(output).toContain("Query<Project | null, RailwayGlobalError>");
133
122
  expect(output).toContain("args?: { readonly first?: number | null }");
134
123
  expect(output).toContain('from "@distilled.cloud/core/graphql"');
135
- expect(() =>
136
- new Bun.Transpiler({ loader: "ts" }).transformSync(output),
137
- ).not.toThrow();
124
+ expect(() => stripTypeScriptTypes(output)).not.toThrow();
138
125
  });
139
126
 
140
127
  test("emits error classes and scopes them to roots", () => {
@@ -180,17 +167,11 @@ describe("GraphQL Query SDK generator", () => {
180
167
  expect(output).toContain(
181
168
  'errorSpec(RailwayRateLimited, "RailwayRateLimited", [{"code":"RATE_LIMITED"}], { retryable: true, global: true })',
182
169
  );
183
- expect(output).toContain(
184
- "export type RailwayGlobalError = RailwayRateLimited;",
185
- );
186
- expect(output).toContain(
187
- "Query<Project, RailwayNotFound | RailwayGlobalError>",
188
- );
170
+ expect(output).toContain("export type RailwayGlobalError = RailwayRateLimited;");
171
+ expect(output).toContain("Query<Project, RailwayNotFound | RailwayGlobalError>");
189
172
  expect(output).toContain("[RailwayNotFoundSpec, ...globalErrors]");
190
173
  expect(output).toContain("Query<User, RailwayGlobalError>");
191
- expect(() =>
192
- new Bun.Transpiler({ loader: "ts" }).transformSync(output),
193
- ).not.toThrow();
174
+ expect(() => stripTypeScriptTypes(output)).not.toThrow();
194
175
  });
195
176
 
196
177
  test("unknown coordinates fail validateGraphQLModel", () => {
@@ -203,17 +184,6 @@ describe("GraphQL Query SDK generator", () => {
203
184
  expect(() => validateGraphQLModel(model)).toThrow(
204
185
  "Project.id: unknown GraphQL error MissingError",
205
186
  );
206
- expect(() => graphqlTypeString({ kind: "NON_NULL" })).toThrow(
207
- "Incomplete GraphQL NON_NULL",
208
- );
209
- });
210
-
211
- test("SDL round-trip through convert still produces a model", () => {
212
- const source = buildSchema(`
213
- type Query { ping: String }
214
- `);
215
- const model = convertGraphQLClient(introspectionFromSchema(source));
216
- expect(model.queryType).toBe("Query");
217
- expect(model.types.Query?.fields?.ping?.type).toBe("String");
187
+ expect(() => graphqlTypeString({ kind: "NON_NULL" })).toThrow("Incomplete GraphQL NON_NULL");
218
188
  });
219
189
  });
@@ -46,8 +46,7 @@ export interface GraphQLModel {
46
46
 
47
47
  export const graphqlTypeString = (ref: TypeRef): string => {
48
48
  if (ref.kind === "NON_NULL" || ref.kind === "LIST") {
49
- if (!ref.ofType)
50
- throw new Error(`Incomplete GraphQL ${ref.kind} reference`);
49
+ if (!ref.ofType) throw new Error(`Incomplete GraphQL ${ref.kind} reference`);
51
50
  const inner = graphqlTypeString(ref.ofType);
52
51
  return ref.kind === "NON_NULL" ? `${inner}!` : `[${inner}]`;
53
52
  }
@@ -79,9 +78,7 @@ export const convertGraphQLClient = (
79
78
  ...(value.defaultValue != null ? { defaultValue: value.defaultValue } : {}),
80
79
  });
81
80
  const types: Record<string, GraphQLType> = {};
82
- for (const type of [...schema.types].sort((a, b) =>
83
- a.name.localeCompare(b.name),
84
- )) {
81
+ for (const type of [...schema.types].sort((a, b) => a.name.localeCompare(b.name))) {
85
82
  if (type.name.startsWith("__")) continue;
86
83
  types[type.name] = {
87
84
  kind: type.kind,
@@ -98,13 +95,9 @@ export const convertGraphQLClient = (
98
95
  field.name,
99
96
  {
100
97
  type: graphqlTypeString(field.type),
101
- args: Object.fromEntries(
102
- field.args.map((arg) => [arg.name, argument(arg)]),
103
- ),
98
+ args: Object.fromEntries(field.args.map((arg) => [arg.name, argument(arg)])),
104
99
  errors: [],
105
- ...(field.description
106
- ? { description: field.description }
107
- : {}),
100
+ ...(field.description ? { description: field.description } : {}),
108
101
  ...(field.isDeprecated
109
102
  ? {
110
103
  deprecated:
@@ -127,17 +120,11 @@ export const convertGraphQLClient = (
127
120
  ),
128
121
  }
129
122
  : {}),
130
- ...(type.enumValues
131
- ? { enumValues: type.enumValues.map((value) => value.name) }
132
- : {}),
133
- ...(type.possibleTypes
134
- ? { possibleTypes: type.possibleTypes.map((ref) => ref.name!) }
135
- : {}),
123
+ ...(type.enumValues ? { enumValues: type.enumValues.map((value) => value.name) } : {}),
124
+ ...(type.possibleTypes ? { possibleTypes: type.possibleTypes.map((ref) => ref.name!) } : {}),
136
125
  ...("interfaces" in type && Array.isArray(type.interfaces)
137
126
  ? {
138
- interfaces: type.interfaces.map(
139
- (ref: { name: string }) => ref.name,
140
- ),
127
+ interfaces: type.interfaces.map((ref: { name: string }) => ref.name),
141
128
  }
142
129
  : {}),
143
130
  };
@@ -146,9 +133,7 @@ export const convertGraphQLClient = (
146
133
  version: 1,
147
134
  queryType: schema.queryType.name,
148
135
  ...(schema.mutationType ? { mutationType: schema.mutationType.name } : {}),
149
- ...(schema.subscriptionType
150
- ? { subscriptionType: schema.subscriptionType.name }
151
- : {}),
136
+ ...(schema.subscriptionType ? { subscriptionType: schema.subscriptionType.name } : {}),
152
137
  types,
153
138
  errors: {},
154
139
  globalErrors: [],
@@ -158,21 +143,14 @@ export const convertGraphQLClient = (
158
143
  /** Reject dangling schema/error references after patches, before generating code. */
159
144
  export const validateGraphQLModel = (model: GraphQLModel): void => {
160
145
  const checkType = (ref: string, coordinate: string) => {
161
- const name = ref.replace(/[\[\]!]/g, "");
162
- if (!model.types[name])
163
- throw new Error(`${coordinate}: unknown GraphQL type ${name}`);
146
+ const name = ref.replace(/[[\]!]/g, "");
147
+ if (!model.types[name]) throw new Error(`${coordinate}: unknown GraphQL type ${name}`);
164
148
  };
165
149
  const checkError = (error: string, coordinate: string) => {
166
- if (!model.errors[error])
167
- throw new Error(`${coordinate}: unknown GraphQL error ${error}`);
150
+ if (!model.errors[error]) throw new Error(`${coordinate}: unknown GraphQL error ${error}`);
168
151
  };
169
- for (const name of [
170
- model.queryType,
171
- model.mutationType,
172
- model.subscriptionType,
173
- ]) {
174
- if (name && !model.types[name])
175
- throw new Error(`Unknown GraphQL root ${name}`);
152
+ for (const name of [model.queryType, model.mutationType, model.subscriptionType]) {
153
+ if (name && !model.types[name]) throw new Error(`Unknown GraphQL root ${name}`);
176
154
  }
177
155
  for (const error of model.globalErrors) checkError(error, "globalErrors");
178
156
  for (const [name, type] of Object.entries(model.types)) {
@@ -185,17 +163,13 @@ export const validateGraphQLModel = (model: GraphQLModel): void => {
185
163
  }
186
164
  for (const [fieldName, field] of Object.entries(type.inputFields ?? {}))
187
165
  checkType(field.type, `${name}.${fieldName}`);
188
- for (const member of [
189
- ...(type.possibleTypes ?? []),
190
- ...(type.interfaces ?? []),
191
- ])
166
+ for (const member of [...(type.possibleTypes ?? []), ...(type.interfaces ?? [])])
192
167
  checkType(member, name);
193
168
  }
194
169
  };
195
170
 
196
171
  const literal = (value: unknown): string => JSON.stringify(value);
197
- const union = (values: readonly string[]): string =>
198
- values.length ? values.join(" | ") : "never";
172
+ const union = (values: readonly string[]): string => (values.length ? values.join(" | ") : "never");
199
173
  const documentation = (description?: string): string =>
200
174
  description ? `/** ${description.replaceAll("*/", "* /")} */\n` : "";
201
175
 
@@ -210,9 +184,7 @@ export interface GenerateGraphQLClientOptions {
210
184
  readonly sdkName?: string;
211
185
  }
212
186
 
213
- const peelRef = (
214
- ref: string,
215
- ): { name: string; list: boolean; nonNull: boolean } => {
187
+ const peelRef = (ref: string): { name: string; list: boolean; nonNull: boolean } => {
216
188
  let text = ref;
217
189
  let nonNull = false;
218
190
  let list = false;
@@ -249,15 +221,9 @@ export const generateGraphQLClient = (
249
221
  if (!type) return "unknown";
250
222
  if (type.kind === "SCALAR") return type.scalar ?? "unknown";
251
223
  if (type.kind === "ENUM")
252
- return (
253
- (type.enumValues ?? [])
254
- .map((value) => JSON.stringify(value))
255
- .join(" | ") || "string"
256
- );
224
+ return (type.enumValues ?? []).map((value) => JSON.stringify(value)).join(" | ") || "string";
257
225
  if (type.kind === "UNION")
258
- return (
259
- (type.possibleTypes ?? []).filter(Boolean).join(" | ") || "unknown"
260
- );
226
+ return (type.possibleTypes ?? []).filter(Boolean).join(" | ") || "unknown";
261
227
  return name;
262
228
  };
263
229
  /** Relay `edges { node }` → node type name, else undefined. */
@@ -340,8 +306,7 @@ export const generateGraphQLClient = (
340
306
  if (!/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(tag))
341
307
  throw new Error(`GraphQL error tag ${tag} is not a valid identifier`);
342
308
  for (const name of [tag, `${tag}Spec`])
343
- if (reserved.has(name))
344
- throw new Error(`GraphQL error ${tag} collides with ${name}`);
309
+ if (reserved.has(name)) throw new Error(`GraphQL error ${tag} collides with ${name}`);
345
310
  }
346
311
  const globalErrors = [...model.globalErrors].sort();
347
312
  const rootErrors = (field: GraphQLField) => {
@@ -354,11 +319,7 @@ export const generateGraphQLClient = (
354
319
  : "globalErrors";
355
320
  return { type, specs };
356
321
  };
357
- const rootFn = (
358
- kind: "query" | "mutation",
359
- fieldName: string,
360
- field: GraphQLField,
361
- ): string => {
322
+ const rootFn = (kind: "query" | "mutation", fieldName: string, field: GraphQLField): string => {
362
323
  const errors = rootErrors(field);
363
324
  const { name, list } = peelRef(field.type);
364
325
  const node = !list ? connectionNode(name) : undefined;
@@ -371,12 +332,8 @@ export const generateGraphQLClient = (
371
332
  const required = argEntries.filter(([, arg]) => arg.type.endsWith("!"));
372
333
  const optional = argEntries.filter(([, arg]) => !arg.type.endsWith("!"));
373
334
  const argFields = [
374
- ...required.map(
375
- ([argName, arg]) => `readonly ${argName}: ${tsArg(arg.type)}`,
376
- ),
377
- ...optional.map(
378
- ([argName, arg]) => `readonly ${argName}?: ${tsArg(arg.type)}`,
379
- ),
335
+ ...required.map(([argName, arg]) => `readonly ${argName}: ${tsArg(arg.type)}`),
336
+ ...optional.map(([argName, arg]) => `readonly ${argName}?: ${tsArg(arg.type)}`),
380
337
  ].join("; ");
381
338
  const sig =
382
339
  argEntries.length === 0
@@ -448,9 +405,7 @@ export const generateGraphQLClient = (
448
405
  for (const tag of errorTags) {
449
406
  const error = model.errors[tag]!;
450
407
  if (error.category && !categories[error.category])
451
- throw new Error(
452
- `GraphQL error ${tag}: unknown category ${error.category}`,
453
- );
408
+ throw new Error(`GraphQL error ${tag}: unknown category ${error.category}`);
454
409
  const pipes = [
455
410
  error.category ? `Category.${categories[error.category]}` : undefined,
456
411
  error.retryable
@@ -493,12 +448,7 @@ export const generateGraphQLClient = (
493
448
  ([fieldName, field]) =>
494
449
  ` readonly ${fieldName}${field.type.endsWith("!") ? "" : "?"}: ${tsArg(field.type)};`,
495
450
  );
496
- lines.push(
497
- documentation(type.description) + `export interface ${name} {`,
498
- ...fields,
499
- "}",
500
- "",
501
- );
451
+ lines.push(documentation(type.description) + `export interface ${name} {`, ...fields, "}", "");
502
452
  }
503
453
 
504
454
  for (const name of unions) {
@@ -513,21 +463,13 @@ export const generateGraphQLClient = (
513
463
  for (const name of objects) {
514
464
  const type = model.types[name]!;
515
465
  const fields = Object.entries(type.fields ?? {}).map(
516
- ([fieldName, field]) =>
517
- ` readonly ${fieldName}: ${tsOutput(field.type)};`,
518
- );
519
- lines.push(
520
- documentation(type.description) + `export interface ${name} {`,
521
- ...fields,
522
- "}",
523
- "",
466
+ ([fieldName, field]) => ` readonly ${fieldName}: ${tsOutput(field.type)};`,
524
467
  );
468
+ lines.push(documentation(type.description) + `export interface ${name} {`, ...fields, "}", "");
525
469
  }
526
470
 
527
471
  for (const name of [...objects, ...unions]) {
528
- lines.push(
529
- `export const ${name}: TypeMeta = { name: ${JSON.stringify(name)}, fields: {} };`,
530
- );
472
+ lines.push(`export const ${name}: TypeMeta = { name: ${JSON.stringify(name)}, fields: {} };`);
531
473
  }
532
474
  lines.push("");
533
475
 
@@ -540,10 +482,7 @@ export const generateGraphQLClient = (
540
482
  lines.push("});", "");
541
483
  }
542
484
  for (const name of unions) {
543
- lines.push(
544
- `Object.assign(${name}.fields, { __typename: scalarField("__typename") });`,
545
- "",
546
- );
485
+ lines.push(`Object.assign(${name}.fields, { __typename: scalarField("__typename") });`, "");
547
486
  }
548
487
 
549
488
  lines.push(`export const ${sdkName} = {`);
@@ -559,14 +498,10 @@ export const generateGraphQLClient = (
559
498
  const mutationType = model.types[model.mutationType];
560
499
  if (mutationType?.fields) {
561
500
  for (const [fieldName, field] of Object.entries(mutationType.fields)) {
562
- const exportName = queryNames.has(fieldName)
563
- ? `${fieldName}Mutation`
564
- : fieldName;
501
+ const exportName = queryNames.has(fieldName) ? `${fieldName}Mutation` : fieldName;
565
502
  const line = rootFn("mutation", fieldName, field);
566
503
  lines.push(
567
- exportName === fieldName
568
- ? line
569
- : line.replace(` ${fieldName}:`, ` ${exportName}:`),
504
+ exportName === fieldName ? line : line.replace(` ${fieldName}:`, ` ${exportName}:`),
570
505
  );
571
506
  }
572
507
  }
@@ -104,8 +104,7 @@ export const readIntrospection = (json: unknown): IntrospectionSchema => {
104
104
  __schema?: IntrospectionSchema;
105
105
  types?: unknown;
106
106
  };
107
- const schema =
108
- j?.data?.__schema ?? j?.__schema ?? (j?.types ? (j as any) : undefined);
107
+ const schema = j?.data?.__schema ?? j?.__schema ?? (j?.types ? (j as any) : undefined);
109
108
  if (!schema) {
110
109
  throw new Error(
111
110
  "introspection JSON has none of `data.__schema`, `__schema`, or a top-level `types`",
@@ -249,8 +248,7 @@ export interface GraphQLConvertResult {
249
248
  // Small helpers
250
249
  // ============================================================================
251
250
 
252
- const capitalize = (s: string): string =>
253
- s.charAt(0).toUpperCase() + s.slice(1);
251
+ const capitalize = (s: string): string => s.charAt(0).toUpperCase() + s.slice(1);
254
252
 
255
253
  const toPascalCase = (s: string): string =>
256
254
  capitalize(s.replace(/[^a-zA-Z0-9]+(.)/g, (_, c: string) => c.toUpperCase()));
@@ -325,10 +323,7 @@ interface RelayCtx {
325
323
  readonly isPageInfo: (name: string | null | undefined) => boolean;
326
324
  }
327
325
 
328
- const makeRelayCtx = (
329
- cfg: Relay,
330
- typeMap: Map<string, IntrospectionType>,
331
- ): RelayCtx => {
326
+ const makeRelayCtx = (cfg: Relay, typeMap: Map<string, IntrospectionType>): RelayCtx => {
332
327
  const connections = new Map<string, boolean>();
333
328
  const edges = new Set<string>();
334
329
  const pageInfos = new Set<string>();
@@ -354,9 +349,7 @@ const makeRelayCtx = (
354
349
 
355
350
  const pageInfoName = namedType(pageInfoField.type).name;
356
351
  const pageInfoType = pageInfoName ? typeMap.get(pageInfoName) : undefined;
357
- const hasCursor = (pageInfoType?.fields ?? []).some(
358
- (f) => f.name === cfg.endCursor,
359
- );
352
+ const hasCursor = (pageInfoType?.fields ?? []).some((f) => f.name === cfg.endCursor);
360
353
  if (!hasCursor) return false;
361
354
 
362
355
  connections.set(name, true);
@@ -548,8 +541,7 @@ const collectOperationPaths = (
548
541
  }
549
542
 
550
543
  const isObject =
551
- (actualReturn.kind === "OBJECT" || actualReturn.kind === "INTERFACE") &&
552
- !!actualReturn.name;
544
+ (actualReturn.kind === "OBJECT" || actualReturn.kind === "INTERFACE") && !!actualReturn.name;
553
545
 
554
546
  if (!isObject || chain.length >= maxNamespaceDepth) {
555
547
  return [chain];
@@ -563,15 +555,7 @@ const collectOperationPaths = (
563
555
  const paths: OperationStep[][] = [];
564
556
  for (const subfield of namespaceType.fields) {
565
557
  if (skipDeprecated && subfield.isDeprecated) continue;
566
- paths.push(
567
- ...collectOperationPaths(
568
- subfield,
569
- chain,
570
- ctx,
571
- maxNamespaceDepth,
572
- skipDeprecated,
573
- ),
574
- );
558
+ paths.push(...collectOperationPaths(subfield, chain, ctx, maxNamespaceDepth, skipDeprecated));
575
559
  }
576
560
 
577
561
  return paths.length > 0 ? paths : [chain];
@@ -641,11 +625,7 @@ const buildPathDocument = (
641
625
  ? `${type} ${operationName}(${varDefs.join(", ")})`
642
626
  : `${type} ${operationName}`;
643
627
 
644
- const renderStep = (
645
- step: OperationStep,
646
- inner: string,
647
- indent: string,
648
- ): string => {
628
+ const renderStep = (step: OperationStep, inner: string, indent: string): string => {
649
629
  const argList = step.args
650
630
  .map((arg) => {
651
631
  const varName = argRenames.get(`${step.name}.${arg.name}`) ?? arg.name;
@@ -753,9 +733,7 @@ const makeConverter = (
753
733
  return id;
754
734
  };
755
735
 
756
- const inputTypeTarget = (
757
- ref: TypeRef,
758
- ): { target: string; nullable: boolean } => {
736
+ const inputTypeTarget = (ref: TypeRef): { target: string; nullable: boolean } => {
759
737
  const { type, nonNull } = unwrapNonNull(ref);
760
738
  const nullable = !nonNull;
761
739
  if (type.kind === "LIST" && type.ofType) {
@@ -850,11 +828,7 @@ const buildOutputTarget = (
850
828
  if (type.kind === "ENUM" && type.name) {
851
829
  return { target: conv.enumShape(type.name), nullable };
852
830
  }
853
- if (
854
- (type.kind === "OBJECT" || type.kind === "INTERFACE") &&
855
- children &&
856
- children.length > 0
857
- ) {
831
+ if ((type.kind === "OBJECT" || type.kind === "INTERFACE") && children && children.length > 0) {
858
832
  const members = buildSelectionMembers(conv, children, hint);
859
833
  const target = addShape(conv.bag, hint, { type: "structure", members });
860
834
  return { target, nullable };
@@ -875,12 +849,7 @@ const buildSelectionMembers = (
875
849
  ): Record<string, any> => {
876
850
  const members: Record<string, any> = {};
877
851
  for (const f of fields) {
878
- const sub = buildOutputTarget(
879
- conv,
880
- f.type,
881
- f.children,
882
- `${hint}${toPascalCase(f.name)}`,
883
- );
852
+ const sub = buildOutputTarget(conv, f.type, f.children, `${hint}${toPascalCase(f.name)}`);
884
853
  const memberTraits: Record<string, any> = { "smithy.api#required": {} };
885
854
  if (sub.nullable) memberTraits[conv.traits.nullable] = {};
886
855
  members[memberIdent(f.name)] = { target: sub.target, traits: memberTraits };
@@ -907,9 +876,7 @@ interface PendingOp {
907
876
  * `POST /graphql` request/response pair, and nothing in the generated SDK
908
877
  * could speak them.
909
878
  */
910
- export const convertGraphQLToSmithy = (
911
- options: GraphQLConvertOptions,
912
- ): GraphQLConvertResult => {
879
+ export const convertGraphQLToSmithy = (options: GraphQLConvertOptions): GraphQLConvertResult => {
913
880
  const {
914
881
  schema,
915
882
  namespace,
@@ -931,9 +898,7 @@ export const convertGraphQLToSmithy = (
931
898
  const typeMap = new Map<string, IntrospectionType>();
932
899
  for (const t of schema.types) typeMap.set(t.name, t);
933
900
 
934
- const relayCfg: Relay | undefined = relay
935
- ? { ...RELAY_DEFAULTS, ...relay }
936
- : undefined;
901
+ const relayCfg: Relay | undefined = relay ? { ...RELAY_DEFAULTS, ...relay } : undefined;
937
902
  const ctx: SchemaCtx = {
938
903
  typeMap,
939
904
  relay: relayCfg ? makeRelayCtx(relayCfg, typeMap) : undefined,
@@ -950,19 +915,10 @@ export const convertGraphQLToSmithy = (
950
915
  for (const field of rootType.fields) {
951
916
  if (skipDeprecated && field.isDeprecated) continue;
952
917
  if (skipRootField(field.name)) continue;
953
- const paths = collectOperationPaths(
954
- field,
955
- [],
956
- ctx,
957
- maxNamespaceDepth,
958
- skipDeprecated,
959
- );
918
+ const paths = collectOperationPaths(field, [], ctx, maxNamespaceDepth, skipDeprecated);
960
919
  for (const opPath of paths) {
961
920
  const functionName = pathToFunctionName(opPath);
962
- const sdkName =
963
- operationNaming === "verbNoun"
964
- ? toVerbNoun(functionName)
965
- : functionName;
921
+ const sdkName = operationNaming === "verbNoun" ? toVerbNoun(functionName) : functionName;
966
922
  if (seenNames.has(sdkName)) {
967
923
  // Two schema fields (or the same field under two paths) map to
968
924
  // one SDK name; the first wins. Silent drops hide real ops.
@@ -979,8 +935,7 @@ export const convertGraphQLToSmithy = (
979
935
  opName: toPascalCase(sdkName),
980
936
  type,
981
937
  path: opPath,
982
- description:
983
- opPath.length === 1 ? oneLineDoc(field.description) : undefined,
938
+ description: opPath.length === 1 ? oneLineDoc(field.description) : undefined,
984
939
  });
985
940
  }
986
941
  }
@@ -1011,20 +966,8 @@ export const convertGraphQLToSmithy = (
1011
966
  try {
1012
967
  const argRenames = buildArgRenames(op.path);
1013
968
  const leaf = op.path[op.path.length - 1]!;
1014
- const selection = expandSelection(
1015
- leaf.returnType,
1016
- ctx,
1017
- 1,
1018
- maxDepth,
1019
- new Set(),
1020
- );
1021
- const document = buildPathDocument(
1022
- op.type,
1023
- op.functionName,
1024
- op.path,
1025
- selection,
1026
- argRenames,
1027
- );
969
+ const selection = expandSelection(leaf.returnType, ctx, 1, maxDepth, new Set());
970
+ const document = buildPathDocument(op.type, op.functionName, op.path, selection, argRenames);
1028
971
  const responsePath = op.path.map((s) => s.name).join(".");
1029
972
 
1030
973
  // ---- Input (the GraphQL variables) ----
@@ -1041,9 +984,7 @@ export const convertGraphQLToSmithy = (
1041
984
  if (adoc) memberTraits["smithy.api#documentation"] = adoc;
1042
985
  inputMembers[memberIdent(varName)] = {
1043
986
  target,
1044
- ...(Object.keys(memberTraits).length
1045
- ? { traits: memberTraits }
1046
- : {}),
987
+ ...(Object.keys(memberTraits).length ? { traits: memberTraits } : {}),
1047
988
  };
1048
989
  }
1049
990
  }
@@ -1072,11 +1013,7 @@ export const convertGraphQLToSmithy = (
1072
1013
  // Object result: the response struct's members ARE the selection.
1073
1014
  outputId = addExact(bag, `${op.opName}Response`, {
1074
1015
  type: "structure",
1075
- members: buildSelectionMembers(
1076
- conv,
1077
- selection!,
1078
- `${op.opName}Response`,
1079
- ),
1016
+ members: buildSelectionMembers(conv, selection!, `${op.opName}Response`),
1080
1017
  traits: {
1081
1018
  "smithy.api#output": {},
1082
1019
  [traits.responsePath]: responsePath,
@@ -1087,12 +1024,7 @@ export const convertGraphQLToSmithy = (
1087
1024
  // List/scalar/enum/opaque result: a sole `result` member carries the
1088
1025
  // whole value; the payload trait makes the generated response type
1089
1026
  // the value itself.
1090
- const inner = buildOutputTarget(
1091
- conv,
1092
- leaf.returnType,
1093
- selection,
1094
- `${op.opName}Result`,
1095
- );
1027
+ const inner = buildOutputTarget(conv, leaf.returnType, selection, `${op.opName}Result`);
1096
1028
  outputId = addExact(bag, `${op.opName}Response`, {
1097
1029
  type: "structure",
1098
1030
  members: {
@@ -1127,9 +1059,7 @@ export const convertGraphQLToSmithy = (
1127
1059
  // list, a connection reached through a namespace hop whose leaf we
1128
1060
  // didn't select) stays a one-shot call.
1129
1061
  const pg =
1130
- relayCfg && isBareObject
1131
- ? relayPaginatedTrait(relayCfg, ctx, leaf, argRenames)
1132
- : undefined;
1062
+ relayCfg && isBareObject ? relayPaginatedTrait(relayCfg, ctx, leaf, argRenames) : undefined;
1133
1063
  if (pg) {
1134
1064
  opTraits["smithy.api#paginated"] = pg;
1135
1065
  paginated++;
@@ -1155,9 +1085,7 @@ export const convertGraphQLToSmithy = (
1155
1085
  operations: serviceOps,
1156
1086
  traits: {
1157
1087
  "smithy.api#title": serviceTitle,
1158
- ...(serviceDocumentation
1159
- ? { "smithy.api#documentation": serviceDocumentation }
1160
- : {}),
1088
+ ...(serviceDocumentation ? { "smithy.api#documentation": serviceDocumentation } : {}),
1161
1089
  },
1162
1090
  });
1163
1091
 
@@ -0,0 +1,67 @@
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
+ };
@@ -75,8 +75,7 @@ export const lowerFirst = (s: string): string => {
75
75
  };
76
76
 
77
77
  /** Upper-case the first character. */
78
- export const upperFirst = (s: string): string =>
79
- s.charAt(0).toUpperCase() + s.slice(1);
78
+ export const upperFirst = (s: string): string => s.charAt(0).toUpperCase() + s.slice(1);
80
79
 
81
80
  /**
82
81
  * Collapse a smithy documentation string to a single safe line for a