@distilled.cloud/core 1.0.0-rc.12 → 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 (276) 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 +8 -8
  9. package/lib/codegen/boolean-string-enums.d.ts.map +1 -1
  10. package/lib/codegen/boolean-string-enums.js +83 -30
  11. package/lib/codegen/boolean-string-enums.js.map +1 -1
  12. package/lib/codegen/boolean-string-enums.test.js +130 -2
  13. package/lib/codegen/boolean-string-enums.test.js.map +1 -1
  14. package/lib/codegen/cli.d.ts +5 -4
  15. package/lib/codegen/cli.d.ts.map +1 -1
  16. package/lib/codegen/cli.js +12 -9
  17. package/lib/codegen/cli.js.map +1 -1
  18. package/lib/codegen/defer-naming.test.d.ts +2 -0
  19. package/lib/codegen/defer-naming.test.d.ts.map +1 -0
  20. package/lib/codegen/defer-naming.test.js +105 -0
  21. package/lib/codegen/defer-naming.test.js.map +1 -0
  22. package/lib/codegen/emit.d.ts.map +1 -1
  23. package/lib/codegen/emit.js +1 -3
  24. package/lib/codegen/emit.js.map +1 -1
  25. package/lib/codegen/format.d.ts +0 -12
  26. package/lib/codegen/format.d.ts.map +1 -1
  27. package/lib/codegen/format.js +10 -6
  28. package/lib/codegen/format.js.map +1 -1
  29. package/lib/codegen/generated-at.d.ts +29 -0
  30. package/lib/codegen/generated-at.d.ts.map +1 -0
  31. package/lib/codegen/generated-at.js +78 -0
  32. package/lib/codegen/generated-at.js.map +1 -0
  33. package/lib/codegen/generated-at.test.d.ts +2 -0
  34. package/lib/codegen/generated-at.test.d.ts.map +1 -0
  35. package/lib/codegen/generated-at.test.js +81 -0
  36. package/lib/codegen/generated-at.test.js.map +1 -0
  37. package/lib/codegen/generator.d.ts +24 -5
  38. package/lib/codegen/generator.d.ts.map +1 -1
  39. package/lib/codegen/generator.js +69 -80
  40. package/lib/codegen/generator.js.map +1 -1
  41. package/lib/codegen/generator.test.d.ts +2 -0
  42. package/lib/codegen/generator.test.d.ts.map +1 -0
  43. package/lib/codegen/generator.test.js +121 -0
  44. package/lib/codegen/generator.test.js.map +1 -0
  45. package/lib/codegen/graphql-client.d.ts +7 -1
  46. package/lib/codegen/graphql-client.d.ts.map +1 -1
  47. package/lib/codegen/graphql-client.js +264 -148
  48. package/lib/codegen/graphql-client.js.map +1 -1
  49. package/lib/codegen/graphql-client.test.js +98 -238
  50. package/lib/codegen/graphql-client.test.js.map +1 -1
  51. package/lib/codegen/graphql.d.ts.map +1 -1
  52. package/lib/codegen/graphql.js +7 -20
  53. package/lib/codegen/graphql.js.map +1 -1
  54. package/lib/codegen/model-diff.d.ts +10 -0
  55. package/lib/codegen/model-diff.d.ts.map +1 -0
  56. package/lib/codegen/model-diff.js +67 -0
  57. package/lib/codegen/model-diff.js.map +1 -0
  58. package/lib/codegen/naming.d.ts.map +1 -1
  59. package/lib/codegen/naming.js.map +1 -1
  60. package/lib/codegen/openapi-binary.test.d.ts +2 -0
  61. package/lib/codegen/openapi-binary.test.d.ts.map +1 -0
  62. package/lib/codegen/openapi-binary.test.js +67 -0
  63. package/lib/codegen/openapi-binary.test.js.map +1 -0
  64. package/lib/codegen/openapi-cli.d.ts +11 -11
  65. package/lib/codegen/openapi-cli.d.ts.map +1 -1
  66. package/lib/codegen/openapi-cli.js +26 -51
  67. package/lib/codegen/openapi-cli.js.map +1 -1
  68. package/lib/codegen/openapi.d.ts +16 -2
  69. package/lib/codegen/openapi.d.ts.map +1 -1
  70. package/lib/codegen/openapi.js +56 -39
  71. package/lib/codegen/openapi.js.map +1 -1
  72. package/lib/codegen/operations.d.ts.map +1 -1
  73. package/lib/codegen/operations.js.map +1 -1
  74. package/lib/codegen/pagination.d.ts.map +1 -1
  75. package/lib/codegen/pagination.js +2 -4
  76. package/lib/codegen/pagination.js.map +1 -1
  77. package/lib/codegen/patch-audit.d.ts +84 -0
  78. package/lib/codegen/patch-audit.d.ts.map +1 -0
  79. package/lib/codegen/patch-audit.js +366 -0
  80. package/lib/codegen/patch-audit.js.map +1 -0
  81. package/lib/codegen/patch-audit.test.d.ts +2 -0
  82. package/lib/codegen/patch-audit.test.d.ts.map +1 -0
  83. package/lib/codegen/patch-audit.test.js +141 -0
  84. package/lib/codegen/patch-audit.test.js.map +1 -0
  85. package/lib/codegen/patches.d.ts +75 -11
  86. package/lib/codegen/patches.d.ts.map +1 -1
  87. package/lib/codegen/patches.js +301 -65
  88. package/lib/codegen/patches.js.map +1 -1
  89. package/lib/codegen/patches.test.js +55 -5
  90. package/lib/codegen/patches.test.js.map +1 -1
  91. package/lib/codegen/prelude.js +1 -1
  92. package/lib/codegen/prelude.js.map +1 -1
  93. package/lib/codegen/proto.d.ts.map +1 -1
  94. package/lib/codegen/proto.js +2 -4
  95. package/lib/codegen/proto.js.map +1 -1
  96. package/lib/codegen/protocol-imports.test.d.ts +2 -0
  97. package/lib/codegen/protocol-imports.test.d.ts.map +1 -0
  98. package/lib/codegen/protocol-imports.test.js +36 -0
  99. package/lib/codegen/protocol-imports.test.js.map +1 -0
  100. package/lib/codegen/rewrite-operation-ids.d.ts +23 -0
  101. package/lib/codegen/rewrite-operation-ids.d.ts.map +1 -1
  102. package/lib/codegen/rewrite-operation-ids.js +97 -59
  103. package/lib/codegen/rewrite-operation-ids.js.map +1 -1
  104. package/lib/codegen/rewrite-operation-ids.test.js +19 -101
  105. package/lib/codegen/rewrite-operation-ids.test.js.map +1 -1
  106. package/lib/codegen/spec-path.d.ts +1 -1
  107. package/lib/codegen/spec-path.d.ts.map +1 -1
  108. package/lib/codegen/spec-path.js +1 -1
  109. package/lib/codegen/spec-path.js.map +1 -1
  110. package/lib/codegen/untagged-unions.test.d.ts +2 -0
  111. package/lib/codegen/untagged-unions.test.d.ts.map +1 -0
  112. package/lib/codegen/untagged-unions.test.js +80 -0
  113. package/lib/codegen/untagged-unions.test.js.map +1 -0
  114. package/lib/error-category.d.ts.map +1 -1
  115. package/lib/error-category.js.map +1 -1
  116. package/lib/errors.d.ts +2 -1
  117. package/lib/errors.d.ts.map +1 -1
  118. package/lib/errors.js +9 -4
  119. package/lib/errors.js.map +1 -1
  120. package/lib/fixtures/xml/upstream-validator.json +397 -0
  121. package/lib/graphql.d.ts +292 -205
  122. package/lib/graphql.d.ts.map +1 -1
  123. package/lib/graphql.js +945 -636
  124. package/lib/graphql.js.map +1 -1
  125. package/lib/graphql.test.js +135 -764
  126. package/lib/graphql.test.js.map +1 -1
  127. package/lib/graphql.types.d.ts +10 -0
  128. package/lib/graphql.types.d.ts.map +1 -1
  129. package/lib/graphql.types.js +4 -44
  130. package/lib/graphql.types.js.map +1 -1
  131. package/lib/index.d.ts +27 -0
  132. package/lib/index.d.ts.map +1 -0
  133. package/lib/index.js +27 -0
  134. package/lib/index.js.map +1 -0
  135. package/lib/json-patch.d.ts +13 -6
  136. package/lib/json-patch.d.ts.map +1 -1
  137. package/lib/json-patch.js +34 -19
  138. package/lib/json-patch.js.map +1 -1
  139. package/lib/json-patch.test.d.ts +2 -0
  140. package/lib/json-patch.test.d.ts.map +1 -0
  141. package/lib/json-patch.test.js +65 -0
  142. package/lib/json-patch.test.js.map +1 -0
  143. package/lib/pagination.d.ts +2 -1
  144. package/lib/pagination.d.ts.map +1 -1
  145. package/lib/pagination.js +28 -30
  146. package/lib/pagination.js.map +1 -1
  147. package/lib/pagination.test.d.ts +2 -0
  148. package/lib/pagination.test.d.ts.map +1 -0
  149. package/lib/pagination.test.js +131 -0
  150. package/lib/pagination.test.js.map +1 -0
  151. package/lib/protocol-http.d.ts +30 -16
  152. package/lib/protocol-http.d.ts.map +1 -1
  153. package/lib/protocol-http.js +133 -84
  154. package/lib/protocol-http.js.map +1 -1
  155. package/lib/protocol-http.test.js +141 -1
  156. package/lib/protocol-http.test.js.map +1 -1
  157. package/lib/protocol-rest.d.ts +18 -1
  158. package/lib/protocol-rest.d.ts.map +1 -1
  159. package/lib/protocol-rest.js +32 -21
  160. package/lib/protocol-rest.js.map +1 -1
  161. package/lib/protocol-rest.test.d.ts +2 -0
  162. package/lib/protocol-rest.test.d.ts.map +1 -0
  163. package/lib/protocol-rest.test.js +498 -0
  164. package/lib/protocol-rest.test.js.map +1 -0
  165. package/lib/query.d.ts +29 -0
  166. package/lib/query.d.ts.map +1 -0
  167. package/lib/query.js +27 -0
  168. package/lib/query.js.map +1 -0
  169. package/lib/response-validation.d.ts +67 -0
  170. package/lib/response-validation.d.ts.map +1 -0
  171. package/lib/response-validation.js +76 -0
  172. package/lib/response-validation.js.map +1 -0
  173. package/lib/response-validation.test.d.ts +2 -0
  174. package/lib/response-validation.test.d.ts.map +1 -0
  175. package/lib/response-validation.test.js +72 -0
  176. package/lib/response-validation.test.js.map +1 -0
  177. package/lib/retry-after.d.ts.map +1 -1
  178. package/lib/retry-after.js +1 -1
  179. package/lib/retry-after.js.map +1 -1
  180. package/lib/retry-after.test.d.ts +2 -0
  181. package/lib/retry-after.test.d.ts.map +1 -0
  182. package/lib/retry-after.test.js +204 -0
  183. package/lib/retry-after.test.js.map +1 -0
  184. package/lib/retry.d.ts.map +1 -1
  185. package/lib/retry.js +1 -2
  186. package/lib/retry.js.map +1 -1
  187. package/lib/retry.test.d.ts +2 -0
  188. package/lib/retry.test.d.ts.map +1 -0
  189. package/lib/retry.test.js +407 -0
  190. package/lib/retry.test.js.map +1 -0
  191. package/lib/sdks.test.d.ts +2 -0
  192. package/lib/sdks.test.d.ts.map +1 -0
  193. package/lib/sdks.test.js +76 -0
  194. package/lib/sdks.test.js.map +1 -0
  195. package/lib/testing.d.ts +39 -0
  196. package/lib/testing.d.ts.map +1 -0
  197. package/lib/testing.js +41 -0
  198. package/lib/testing.js.map +1 -0
  199. package/lib/trait.d.ts +29 -9
  200. package/lib/trait.d.ts.map +1 -1
  201. package/lib/trait.js +8 -0
  202. package/lib/trait.js.map +1 -1
  203. package/lib/xml.d.ts +44 -0
  204. package/lib/xml.d.ts.map +1 -0
  205. package/lib/xml.js +311 -0
  206. package/lib/xml.js.map +1 -0
  207. package/lib/xml.test.d.ts +2 -0
  208. package/lib/xml.test.d.ts.map +1 -0
  209. package/lib/xml.test.js +210 -0
  210. package/lib/xml.test.js.map +1 -0
  211. package/package.json +8 -11
  212. package/src/api.ts +38 -55
  213. package/src/category.ts +21 -50
  214. package/src/codegen/boolean-string-enums.test.ts +148 -17
  215. package/src/codegen/boolean-string-enums.ts +81 -32
  216. package/src/codegen/cli.ts +29 -47
  217. package/src/codegen/defer-naming.test.ts +113 -0
  218. package/src/codegen/emit.ts +2 -5
  219. package/src/codegen/format.ts +12 -10
  220. package/src/codegen/generated-at.test.ts +89 -0
  221. package/src/codegen/generated-at.ts +88 -0
  222. package/src/codegen/generator.test.ts +137 -0
  223. package/src/codegen/generator.ts +132 -193
  224. package/src/codegen/graphql-client.test.ts +100 -297
  225. package/src/codegen/graphql-client.ts +302 -210
  226. package/src/codegen/graphql.ts +22 -94
  227. package/src/codegen/model-diff.ts +67 -0
  228. package/src/codegen/naming.ts +1 -2
  229. package/src/codegen/openapi-binary.test.ts +91 -0
  230. package/src/codegen/openapi-cli.ts +38 -79
  231. package/src/codegen/openapi.ts +98 -133
  232. package/src/codegen/operations.ts +2 -5
  233. package/src/codegen/pagination.ts +4 -11
  234. package/src/codegen/patch-audit.test.ts +160 -0
  235. package/src/codegen/patch-audit.ts +480 -0
  236. package/src/codegen/patches.test.ts +73 -15
  237. package/src/codegen/patches.ts +389 -99
  238. package/src/codegen/prelude.ts +1 -1
  239. package/src/codegen/proto.ts +18 -54
  240. package/src/codegen/protocol-imports.test.ts +39 -0
  241. package/src/codegen/rewrite-operation-ids.test.ts +23 -114
  242. package/src/codegen/rewrite-operation-ids.ts +111 -98
  243. package/src/codegen/spec-path.ts +3 -6
  244. package/src/codegen/untagged-unions.test.ts +85 -0
  245. package/src/error-category.ts +5 -17
  246. package/src/errors.ts +18 -30
  247. package/src/fixtures/xml/upstream-validator.json +397 -0
  248. package/src/graphql.test.ts +173 -949
  249. package/src/graphql.ts +1468 -1186
  250. package/src/graphql.types.ts +78 -164
  251. package/src/index.ts +26 -0
  252. package/src/json-patch.test.ts +77 -0
  253. package/src/json-patch.ts +54 -60
  254. package/src/pagination.test.ts +169 -0
  255. package/src/pagination.ts +46 -103
  256. package/src/protocol-http.test.ts +178 -9
  257. package/src/protocol-http.ts +174 -163
  258. package/src/protocol-rest.test.ts +703 -0
  259. package/src/protocol-rest.ts +76 -65
  260. package/src/query.ts +39 -0
  261. package/src/response-validation.test.ts +89 -0
  262. package/src/response-validation.ts +107 -0
  263. package/src/retry-after.test.ts +267 -0
  264. package/src/retry-after.ts +4 -10
  265. package/src/retry.test.ts +566 -0
  266. package/src/retry.ts +6 -21
  267. package/src/sdks.test.ts +87 -0
  268. package/src/testing.ts +72 -0
  269. package/src/trait.ts +48 -63
  270. package/src/xml.test.ts +251 -0
  271. package/src/xml.ts +323 -0
  272. package/lib/graphql.fixture.d.ts +0 -249
  273. package/lib/graphql.fixture.d.ts.map +0 -1
  274. package/lib/graphql.fixture.js +0 -240
  275. package/lib/graphql.fixture.js.map +0 -1
  276. package/src/graphql.fixture.ts +0 -371
@@ -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
@@ -0,0 +1,91 @@
1
+ import { describe, expect, test } from "vitest";
2
+ import { convertOpenApiToSmithy } from "./openapi.ts";
3
+
4
+ const model = (
5
+ schema: unknown,
6
+ mediaType = "multipart/form-data",
7
+ responseSchema: unknown = { type: "string", format: "binary" },
8
+ components: Record<string, unknown> = {},
9
+ options: { binaryTypes?: boolean } = { binaryTypes: true },
10
+ ) =>
11
+ convertOpenApiToSmithy(
12
+ {
13
+ openapi: "3.0.3",
14
+ info: { title: "Binary", version: "1" },
15
+ components,
16
+ paths: {
17
+ "/files": {
18
+ post: {
19
+ operationId: "uploadFile",
20
+ requestBody: { content: { [mediaType]: { schema } } },
21
+ responses: {
22
+ "200": {
23
+ content: {
24
+ "application/octet-stream": {
25
+ schema: responseSchema,
26
+ },
27
+ },
28
+ },
29
+ },
30
+ },
31
+ },
32
+ },
33
+ },
34
+ { namespace: "com.example.binary", serviceName: "Binary", ...options },
35
+ );
36
+
37
+ describe("OpenAPI binary contracts", () => {
38
+ for (const options of [{}, { binaryTypes: false }]) {
39
+ test(`binary conversion preserves existing contracts with ${JSON.stringify(options)}`, () => {
40
+ const result = model(
41
+ {
42
+ type: "object",
43
+ properties: {
44
+ zip: { type: "string", format: "binary" },
45
+ archive: { $ref: "#/components/schemas/Archive" },
46
+ },
47
+ },
48
+ "multipart/form-data",
49
+ { $ref: "#/components/schemas/Archive" },
50
+ { schemas: { Archive: { type: "string", format: "binary" } } },
51
+ options,
52
+ );
53
+ const request = result.shapes["com.example.binary#UploadFileRequest"];
54
+ expect(request.members.zip.target).toBe("smithy.api#String");
55
+ expect(request.members.archive.target).toBe("smithy.api#String");
56
+ expect(result.shapes["com.example.binary#UploadFile"].output.target).toBe("smithy.api#Unit");
57
+ expect(result.shapes["com.example.binary#UploadFileResponse"]).toBeUndefined();
58
+ });
59
+ }
60
+
61
+ test("component-referenced binary responses retain the original reference's nullability", () => {
62
+ const result = model(
63
+ { type: "object" },
64
+ "application/json",
65
+ { $ref: "#/components/schemas/Archive", nullable: true },
66
+ { schemas: { Archive: { type: "string", format: "binary" } } },
67
+ );
68
+ const body = result.shapes["com.example.binary#UploadFileResponse"].members.body;
69
+ expect(body.target).toBe("smithy.api#Blob");
70
+ expect(body.traits["com.distilled.openapi#rawResponse"]).toEqual({});
71
+ expect(body.traits["com.distilled.openapi#nullable"]).toEqual({});
72
+ });
73
+
74
+ test("multipart binary fields become blobs, not text or base64", () => {
75
+ const result = model({
76
+ type: "object",
77
+ properties: {
78
+ zip: { type: "string", format: "binary" },
79
+ encoded: { type: "string", format: "byte" },
80
+ environment: { type: "string" },
81
+ },
82
+ });
83
+ const request = result.shapes["com.example.binary#UploadFileRequest"];
84
+ expect(request.members.zip.target).toBe("smithy.api#Blob");
85
+ expect(request.members.encoded.target).toBe("smithy.api#String");
86
+ expect(request.members.environment.target).toBe("smithy.api#String");
87
+ const response = result.shapes["com.example.binary#UploadFileResponse"];
88
+ expect(response.members.body.target).toBe("smithy.api#Blob");
89
+ expect(response.members.body.traits["com.distilled.openapi#rawResponse"]).toEqual({});
90
+ });
91
+ });
@@ -2,11 +2,11 @@
2
2
  * OpenAPI → Smithy pipeline helper (dev-time only, provider-agnostic).
3
3
  *
4
4
  * Owns the spec-side pipeline every OpenAPI-sourced provider shares: read the
5
- * spec file, apply OpenAPI RFC-6902 ops to the document, convert with
6
- * {@link convertOpenApiToSmithy} (which owns verbNoun naming), apply Smithy
7
- * RFC-6902 ops (`/shapes`, `/metadata`) to the model, and write
8
- * `.generated-specs/<name>.json`. Stale targets fail unless
9
- * `onStalePatch: "warn"`.
5
+ * spec file, convert it with {@link convertOpenApiToSmithy} (upstream names,
6
+ * the verbNoun names deferred), and write `.generated-specs/<name>.json`;
7
+ * then {@link finalizeConvert} applies the package's RFC-6902 patches (Smithy
8
+ * ops only: `/shapes`, `/metadata`) and the deferred names, so patches target
9
+ * the names the spec gives. Stale targets fail unless `onStalePatch: "warn"`.
10
10
  *
11
11
  * A provider's `scripts/convert.ts` is: a `runOpenApiConvert` call.
12
12
  * `scripts/generate.ts` compiles the already-patched models and does not
@@ -14,16 +14,8 @@
14
14
  */
15
15
  import * as fs from "node:fs/promises";
16
16
  import * as path from "node:path";
17
- import {
18
- convertOpenApiToSmithy,
19
- type OpenApiConvertOptions,
20
- } from "./openapi.ts";
21
- import {
22
- applyRfc6902Files,
23
- finalizeConvert,
24
- isSmithyPatchPath,
25
- listRfc6902PatchFiles,
26
- } from "./patches.ts";
17
+ import { convertOpenApiToSmithy, type OpenApiConvertOptions } from "./openapi.ts";
18
+ import { finalizeConvert } from "./patches.ts";
27
19
  import { resolveSpecPath } from "./spec-path.ts";
28
20
 
29
21
  export interface OpenApiSpecEntry {
@@ -32,7 +24,7 @@ export interface OpenApiSpecEntry {
32
24
  /** Spec file path, relative to `root` (or absolute). */
33
25
  readonly specPath: string;
34
26
  /**
35
- * Hook between patching and conversion (e.g. path prefixing, server
27
+ * Hook between reading and conversion (e.g. path prefixing, server
36
28
  * rewrites). May mutate the spec in place or return a replacement.
37
29
  */
38
30
  readonly preprocess?: (spec: any) => unknown | void | Promise<unknown | void>;
@@ -41,15 +33,14 @@ export interface OpenApiSpecEntry {
41
33
  }
42
34
 
43
35
  export interface RunOpenApiConvertOptions {
44
- /** Absolute package root (usually `path.resolve(import.meta.dir, "..")`). */
36
+ /** Absolute package root (usually `path.resolve(import.meta.dirname, "..")`). */
45
37
  readonly root: string;
46
38
  readonly specs: readonly OpenApiSpecEntry[];
47
39
  /**
48
- * RFC-6902 patch chain root, relative to `root`. Default `"patches"`;
49
- * `false` disables. Layout: `<patchesDir>/<name>/*.json` when the
50
- * per-spec directory exists; for single-spec providers a flat
51
- * `<patchesDir>/*.json` also works. Ops under `/shapes` or `/metadata`
52
- * apply to the Smithy model after conversion; the rest apply to OpenAPI.
40
+ * RFC-6902 patch root, relative to `root`. Default `"patches"`; `false`
41
+ * disables. Layout: `<patchesDir>/<name>/*.json` when the per-spec
42
+ * directory exists; for single-spec providers a flat `<patchesDir>/*.json`
43
+ * also works. Every op targets the Smithy model (`/shapes`, `/metadata`).
53
44
  */
54
45
  readonly patchesDir?: string | false;
55
46
  /** Output directory, relative to `root`. Default `".generated-specs"`. */
@@ -68,10 +59,11 @@ export interface RunOpenApiConvertOptions {
68
59
  */
69
60
  readonly onStalePatch?: "fail" | "warn";
70
61
  /**
71
- * Run {@link finalizeConvert} on the written models (reference check +
72
- * finalized marker; naming already happened in the converter). Default
73
- * true. Pass false when the caller finalizes once after several convert
74
- * steps (Fly machines + sprites + addons).
62
+ * Run {@link finalizeConvert} on the written models (Smithy patches,
63
+ * deferred names, reference check, finalized marker). Default true. Pass
64
+ * false when the caller finalizes once after several convert steps (Fly
65
+ * machines + sprites + addons); its finalizeConvert must then apply the
66
+ * Smithy patches, from `patches/<name>/`.
75
67
  */
76
68
  readonly finalize?: boolean;
77
69
  }
@@ -86,14 +78,10 @@ const exists = async (p: string): Promise<boolean> => {
86
78
  };
87
79
 
88
80
  /** Run the OpenAPI→Smithy conversion pipeline (plain async — call from a script). */
89
- export const runOpenApiConvert = async (
90
- o: RunOpenApiConvertOptions,
91
- ): Promise<void> => {
81
+ export const runOpenApiConvert = async (o: RunOpenApiConvertOptions): Promise<void> => {
92
82
  const outDir = path.resolve(o.root, o.outDir ?? ".generated-specs");
93
83
  const patchRoot =
94
- o.patchesDir === false
95
- ? undefined
96
- : path.resolve(o.root, o.patchesDir ?? "patches");
84
+ o.patchesDir === false ? undefined : path.resolve(o.root, o.patchesDir ?? "patches");
97
85
  const parse = o.parse ?? ((text: string) => JSON.parse(text));
98
86
  const onStalePatch = o.onStalePatch ?? "fail";
99
87
 
@@ -102,69 +90,38 @@ export const runOpenApiConvert = async (
102
90
  console.log("🛠️ openapi → smithy");
103
91
  console.log(` Output: ${outDir}`);
104
92
 
93
+ // Each spec's patch dir, relative to the patch root: `<name>/` when it
94
+ // exists, else the root itself for a single-spec provider.
95
+ const patchDirs = new Map<string, string>();
96
+ if (patchRoot && (await exists(patchRoot))) {
97
+ for (const entry of o.specs) {
98
+ if (await exists(path.join(patchRoot, entry.name))) patchDirs.set(entry.name, entry.name);
99
+ else if (o.specs.length === 1) patchDirs.set(entry.name, "");
100
+ }
101
+ }
102
+
105
103
  for (const entry of o.specs) {
106
104
  // Production path by default; `specs/.local` under DISTILLED_SPECS_LOCAL.
107
105
  const specPath = resolveSpecPath(o.root, entry.specPath);
108
106
  let spec: any = parse(await fs.readFile(specPath, "utf8"), specPath);
109
107
 
110
- // ---- RFC-6902: OpenAPI ops before convert, Smithy ops after ----
111
- let patchDir: string | undefined;
112
- if (patchRoot && (await exists(patchRoot))) {
113
- const perSpec = path.join(patchRoot, entry.name);
114
- if (await exists(perSpec)) {
115
- patchDir = perSpec;
116
- } else if (o.specs.length === 1) {
117
- patchDir = patchRoot;
118
- }
119
- }
120
- const patchFiles = patchDir ? await listRfc6902PatchFiles(patchDir) : [];
121
- const patchLabel = (file: string) => `${entry.name}/${path.basename(file)}`;
122
- const openapiPatches = await applyRfc6902Files(spec, patchFiles, {
123
- onStalePatch,
124
- include: (op) => !isSmithyPatchPath(op.path),
125
- label: patchLabel,
126
- });
127
- if (openapiPatches.errors.length) {
128
- for (const b of openapiPatches.errors)
129
- console.error(`❌ bad patch: ${b}`);
130
- throw new Error(
131
- `${openapiPatches.errors.length} patch operation(s) failed — fix the pointers or delete the patch`,
132
- );
133
- }
134
-
135
108
  // ---- Preprocess hook ----
136
109
  if (entry.preprocess) {
137
110
  const replaced = await entry.preprocess(spec);
138
111
  if (replaced !== undefined) spec = replaced;
139
112
  }
140
113
 
141
- // ---- Convert, Smithy patches, write ----
114
+ // ---- Convert, write ----
142
115
  const model = convertOpenApiToSmithy(spec, {
116
+ deferNaming: true,
143
117
  ...o.options,
144
118
  ...entry.options,
145
119
  });
146
- const smithyPatches = await applyRfc6902Files(model, patchFiles, {
147
- onStalePatch,
148
- include: (op) => isSmithyPatchPath(op.path),
149
- label: patchLabel,
150
- });
151
- if (smithyPatches.errors.length) {
152
- for (const b of smithyPatches.errors) console.error(`❌ bad patch: ${b}`);
153
- throw new Error(
154
- `${smithyPatches.errors.length} Smithy patch operation(s) failed — fix the pointers or delete the patch`,
155
- );
156
- }
157
- const opCount = Object.values(model.shapes).filter(
158
- (s: any) => s.type === "operation",
159
- ).length;
120
+ const opCount = Object.values(model.shapes).filter((s: any) => s.type === "operation").length;
160
121
  const outPath = path.join(outDir, `${entry.name}.json`);
161
122
  await fs.writeFile(outPath, JSON.stringify(model, null, 2) + "\n");
162
- const staleOps = openapiPatches.stale + smithyPatches.stale;
163
123
  console.log(
164
- ` ✅ ${entry.name}: ${opCount} operations, ${Object.keys(model.shapes).length} shapes` +
165
- (patchFiles.length
166
- ? ` (${patchFiles.length} patch file(s) applied${staleOps ? `, ${staleOps} stale op(s) skipped` : ""})`
167
- : ""),
124
+ ` ✅ ${entry.name}: ${opCount} operations, ${Object.keys(model.shapes).length} shapes`,
168
125
  );
169
126
  }
170
127
 
@@ -173,8 +130,10 @@ export const runOpenApiConvert = async (
173
130
  await finalizeConvert({
174
131
  root: o.root,
175
132
  outDir,
176
- // Patches and naming already ran above.
177
- patchesDir: false,
133
+ patchesDir: patchRoot ?? false,
134
+ patchesFor: (resource) => patchDirs.get(resource),
135
+ onStalePatch,
136
+ // The converter computed the names; finalize only applies them.
178
137
  operationNaming: "as-is",
179
138
  include: (resource) => written.has(resource),
180
139
  });