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

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,4 +1,4 @@
1
- import { describe, expect, test } from "bun:test";
1
+ import { describe, expect, test } from "vitest";
2
2
  import { generateService, type SdkSpec } from "./generator.ts";
3
3
 
4
4
  const primitiveUnionModel = (kind: "enum" | "intEnum", request: boolean) => ({
@@ -67,17 +67,11 @@ describe("operation protocol overrides", () => {
67
67
  protocol: "ExampleProtocol",
68
68
  retry,
69
69
  overrides: () =>
70
- overridden
71
- ? { contextType: "PublicContext", protocol: "PublicProtocol" }
72
- : undefined,
70
+ overridden ? { contextType: "PublicContext", protocol: "PublicProtocol" } : undefined,
73
71
  },
74
72
  });
75
- expect(code).toContain(
76
- ` protocol: ${overridden ? "PublicProtocol" : "ExampleProtocol"},`,
77
- );
78
- expect(code).toContain(
79
- ` ${overridden ? "PublicContext" : "ExampleContext"}\n>`,
80
- );
73
+ expect(code).toContain(` protocol: ${overridden ? "PublicProtocol" : "ExampleProtocol"},`);
74
+ expect(code).toContain(` ${overridden ? "PublicContext" : "ExampleContext"}\n>`);
81
75
  if (retry) expect(code).toContain(` retry: ${retry},`);
82
76
  else expect(code).not.toContain(" retry:");
83
77
  });
@@ -89,21 +83,14 @@ describe("primitive union generation", () => {
89
83
  for (const kind of ["enum", "intEnum"] as const) {
90
84
  for (const request of [false, true]) {
91
85
  test(`${kind}/Boolean stays open when ${request ? "request-reachable" : "response-only"}`, () => {
92
- const { code } = generateService(
93
- primitiveUnionModel(kind, request),
94
- spec,
95
- );
86
+ const { code } = generateService(primitiveUnionModel(kind, request), spec);
96
87
  const primitive = kind === "enum" ? "string" : "number";
97
- expect(code).toContain(
98
- `export type Value = Mode | (${primitive} & {}) | boolean;`,
99
- );
88
+ expect(code).toContain(`export type Value = Mode | (${primitive} & {}) | boolean;`);
100
89
  expect(code).toContain(
101
90
  "export const Value: S.Codec<Value> = /*@__PURE__*/ S.Union([Mode, S.Boolean]);",
102
91
  );
103
92
  expect(code).toContain(
104
- kind === "enum"
105
- ? "export const Mode = S.String;"
106
- : "export const Mode = S.Number;",
93
+ kind === "enum" ? "export const Mode = S.String;" : "export const Mode = S.Number;",
107
94
  );
108
95
  expect(code).not.toContain("export type Value = Mode | boolean;");
109
96
  });
@@ -133,8 +120,7 @@ describe("primitive union generation", () => {
133
120
 
134
121
  test("primitive style rejects object cases", () => {
135
122
  const model = primitiveUnionModel("enum", false);
136
- model.shapes["com.example.union#Value"].members.mode.target =
137
- "com.example.union#Request";
123
+ model.shapes["com.example.union#Value"].members.mode.target = "com.example.union#Request";
138
124
  expect(() => generateService(model, spec)).toThrow(
139
125
  "no union emission configured for shape com.example.union#Value",
140
126
  );
@@ -1,3 +1,16 @@
1
+ import { booleanStringEnums, STRING_ENCODED_TRAIT } from "./boolean-string-enums.ts";
2
+ import {
3
+ enumDecl,
4
+ errorClass,
5
+ errorUnionAlias,
6
+ interfaceDecl,
7
+ interfaceField,
8
+ operationConst,
9
+ PURE,
10
+ suspendConst,
11
+ } from "./emit.ts";
12
+ import { orderIndex, reachableFrom, shapeDeps, topoOrder, type ShapeMap } from "./graph.ts";
13
+ import { memberBases, smithyWireName } from "./members.ts";
1
14
  /**
2
15
  * The generic smithy→SDK service generator (dev-time only).
3
16
  *
@@ -14,38 +27,7 @@
14
27
  * pipeline — docs-derived specs, patches, …), define its {@link SdkSpec},
15
28
  * call {@link generateService} per model, write files.
16
29
  */
17
- import {
18
- camel as _camel,
19
- local,
20
- lowerFirst,
21
- oneLine,
22
- q,
23
- tsKey,
24
- upperFirst,
25
- } from "./naming.ts";
26
- import {
27
- orderIndex,
28
- reachableFrom,
29
- shapeDeps,
30
- topoOrder,
31
- type ShapeMap,
32
- } from "./graph.ts";
33
- import {
34
- enumDecl,
35
- errorClass,
36
- errorUnionAlias,
37
- interfaceDecl,
38
- interfaceField,
39
- operationConst,
40
- PURE,
41
- suspendConst,
42
- } from "./emit.ts";
43
- import {
44
- JSON_PRELUDE,
45
- makeSchemaRef,
46
- makeTsRef,
47
- TS_JSON_PRELUDE,
48
- } from "./prelude.ts";
30
+ import { camel as _camel, local, lowerFirst, oneLine, q, tsKey, upperFirst } from "./naming.ts";
49
31
  import {
50
32
  collectOperations,
51
33
  collectOpErrorIds,
@@ -53,12 +35,8 @@ import {
53
35
  modelNamespace,
54
36
  type OpEntry,
55
37
  } from "./operations.ts";
56
- import { memberBases, smithyWireName } from "./members.ts";
57
38
  import { validatePaginated } from "./pagination.ts";
58
- import {
59
- booleanStringEnums,
60
- STRING_ENCODED_TRAIT,
61
- } from "./boolean-string-enums.ts";
39
+ import { JSON_PRELUDE, makeSchemaRef, makeTsRef, TS_JSON_PRELUDE } from "./prelude.ts";
62
40
 
63
41
  const PAGINATED_TRAIT = "smithy.api#paginated";
64
42
 
@@ -122,12 +100,7 @@ const categoryPipes = (traits: Record<string, any> | undefined): string[] =>
122
100
  errorCategories(traits).map((name) => `C.with${name}`);
123
101
 
124
102
  /** A member's resolved binding. The four generic kinds plus provider extras. */
125
- export type MemberBinding =
126
- | "label"
127
- | "query"
128
- | "header"
129
- | "body"
130
- | (string & {});
103
+ export type MemberBinding = "label" | "query" | "header" | "body" | (string & {});
131
104
 
132
105
  export interface EmittedMember {
133
106
  readonly name: string;
@@ -214,10 +187,7 @@ export interface SdkSpec {
214
187
  * fields reference schema consts); the error shapes themselves are still
215
188
  * emitted as error classes, not schemas.
216
189
  */
217
- readonly extraRoots?: (
218
- selected: readonly OpEntry[],
219
- shapes: ShapeMap,
220
- ) => Iterable<string>;
190
+ readonly extraRoots?: (selected: readonly OpEntry[], shapes: ShapeMap) => Iterable<string>;
221
191
 
222
192
  /**
223
193
  * Provider member bindings as data, checked in order between the generic
@@ -244,9 +214,7 @@ export interface SdkSpec {
244
214
  * Which wire-name rule a binding follows. Defaults: the three generic
245
215
  * kinds map to themselves, everything else to `"other"` (jsonName).
246
216
  */
247
- readonly wireKind?: (
248
- binding: MemberBinding,
249
- ) => "label" | "query" | "header" | "other";
217
+ readonly wireKind?: (binding: MemberBinding) => "label" | "query" | "header" | "other";
250
218
  /** Trait id marking a member nullable (`S.NullOr` + `| null`). */
251
219
  readonly nullableTrait?: string;
252
220
  /**
@@ -275,10 +243,7 @@ export interface SdkSpec {
275
243
  /** Full override of member pipe emission (rarely needed). */
276
244
  readonly memberPipes?: (m: EmittedMember) => string[];
277
245
  /** Override the value schema before nullability, bindings and optionality. */
278
- readonly memberSchema?: (
279
- m: EmittedMember,
280
- ref: (target: string) => string,
281
- ) => string | undefined;
246
+ readonly memberSchema?: (m: EmittedMember, ref: (target: string) => string) => string | undefined;
282
247
  /** Function override for member TS types beyond the binding table. */
283
248
  readonly memberTsType?: (
284
249
  m: EmittedMember,
@@ -293,6 +258,8 @@ export interface SdkSpec {
293
258
  readonly id: string;
294
259
  readonly isOpIo: boolean;
295
260
  readonly httpTrait: unknown | undefined;
261
+ /** Traits of the operation whose INPUT this shape is (undefined otherwise). */
262
+ readonly opTraits: Readonly<Record<string, unknown>> | undefined;
296
263
  }) => string[];
297
264
 
298
265
  /**
@@ -309,10 +276,7 @@ export interface SdkSpec {
309
276
  * trait / shape). Default: the sole declared profile; with several
310
277
  * profiles this becomes required for ops to paginate.
311
278
  */
312
- readonly paginationProfileFor?: (
313
- trait: any,
314
- op: OpEntry,
315
- ) => string | undefined;
279
+ readonly paginationProfileFor?: (trait: any, op: OpEntry) => string | undefined;
316
280
 
317
281
  /**
318
282
  * Service-wide fallback key dictionary stamped on op I/O roots (emitted
@@ -398,9 +362,7 @@ export interface SdkSpec {
398
362
  /** Field line for a declared member. Default: prelude-mapped schema. */
399
363
  readonly field?: (name: string, target: string) => string;
400
364
  /** Optional wrapper (e.g. matcher application) from the shape's traits. */
401
- readonly wrap?: (
402
- traits: Record<string, any>,
403
- ) => ((cls: string) => string) | undefined;
365
+ readonly wrap?: (traits: Record<string, any>) => ((cls: string) => string) | undefined;
404
366
  };
405
367
 
406
368
  /**
@@ -447,10 +409,7 @@ export interface SdkSpec {
447
409
  * `../retry.ts`), re-exports the op error/context types, and emits the
448
410
  * `KEY_DICTIONARY` const when {@link SdkSpec.rootKeyDictionary} is set.
449
411
  */
450
- readonly header?: (ctx: {
451
- readonly hasPaginated: boolean;
452
- readonly model: any;
453
- }) => string;
412
+ readonly header?: (ctx: { readonly hasPaginated: boolean; readonly model: any }) => string;
454
413
 
455
414
  /** Final pass over the assembled module (e.g. pruning unused imports). */
456
415
  readonly postProcess?: (code: string) => string;
@@ -469,10 +428,7 @@ export interface GeneratedService {
469
428
  }
470
429
 
471
430
  /** Compile one Smithy model into a service module. */
472
- export const generateService = (
473
- model: any,
474
- spec: SdkSpec,
475
- ): GeneratedService => {
431
+ export const generateService = (model: any, spec: SdkSpec): GeneratedService => {
476
432
  // `"true" | "false"` request members become real booleans that travel as
477
433
  // their string spelling (see boolean-string-enums.ts).
478
434
  booleanStringEnums(model);
@@ -487,11 +443,8 @@ export const generateService = (
487
443
  // operation has an input shape that can carry operation-level traits.
488
444
  const operations = collectOperations(shapes);
489
445
  const httpFor: Record<string, any> = {}; // input shape id → http trait
490
- const ns = modelNamespace(
491
- operations,
492
- shapes,
493
- spec.namespaceFallback ?? "smithy.unknown",
494
- );
446
+ const opTraitsFor: Record<string, Record<string, unknown>> = {}; // input shape id → op traits
447
+ const ns = modelNamespace(operations, shapes, spec.namespaceFallback ?? "smithy.unknown");
495
448
 
496
449
  const selected: OpEntry[] = [];
497
450
  for (const op of operations) {
@@ -503,6 +456,7 @@ export const generateService = (
503
456
 
504
457
  const http = op.def.traits?.["smithy.api#http"];
505
458
  if (http) httpFor[input] = http;
459
+ if (op.def.traits) opTraitsFor[input] = op.def.traits;
506
460
  }
507
461
 
508
462
  if (selected.length === 0) return { code: "", operations: 0 };
@@ -534,8 +488,7 @@ export const generateService = (
534
488
 
535
489
  const rawRef = makeSchemaRef(prelude, indexOf);
536
490
  const rawTsRef = makeTsRef(tsPrelude);
537
- const ref = (target: string, selfIdx: number) =>
538
- rawRef(canon(target), selfIdx);
491
+ const ref = (target: string, selfIdx: number) => rawRef(canon(target), selfIdx);
539
492
  const tsRef = (target: string) => rawTsRef(canon(target));
540
493
 
541
494
  // Direction classification for enum openness. Enum ALIASES are emitted
@@ -591,18 +544,10 @@ export const generateService = (
591
544
  const wireKind =
592
545
  spec.wireKind ??
593
546
  ((b: MemberBinding): "label" | "query" | "header" | "other" =>
594
- b === "label"
595
- ? "label"
596
- : b === "query"
597
- ? "query"
598
- : b === "header"
599
- ? "header"
600
- : "other");
547
+ b === "label" ? "label" : b === "query" ? "query" : b === "header" ? "header" : "other");
601
548
 
602
549
  // The generic binding cascade; provider bindings slot in after headers.
603
- const extraBindingOf = (
604
- traits: Record<string, any>,
605
- ): MemberBinding | undefined => {
550
+ const extraBindingOf = (traits: Record<string, any>): MemberBinding | undefined => {
606
551
  for (const b of spec.extraBindings ?? []) {
607
552
  if (b.trait in traits) return b.binding;
608
553
  }
@@ -615,8 +560,7 @@ export const generateService = (
615
560
  ? "query"
616
561
  : "smithy.api#httpHeader" in traits
617
562
  ? "header"
618
- : (extraBindingOf(traits) ??
619
- ("smithy.api#httpPayload" in traits ? "rawBody" : "body"));
563
+ : (extraBindingOf(traits) ?? ("smithy.api#httpPayload" in traits ? "rawBody" : "body"));
620
564
 
621
565
  // Shapes reachable from any response/error root — used to scope the
622
566
  // blanket-nullable-optionals rule to reads (the wire returns explicit
@@ -625,10 +569,7 @@ export const generateService = (
625
569
  spec.optionalsNullable === true
626
570
  ? reachableFrom(
627
571
  shapes,
628
- [
629
- ...selected.map((op) => op.def.__output),
630
- ...collectOpErrorIds(selected, shapes),
631
- ],
572
+ [...selected.map((op) => op.def.__output), ...collectOpErrorIds(selected, shapes)],
632
573
  shapeDeps,
633
574
  )
634
575
  : undefined;
@@ -661,9 +602,7 @@ export const generateService = (
661
602
  const values = Object.values(d.members ?? {}).map(
662
603
  (m: any) => m.traits?.["smithy.api#enumValue"],
663
604
  );
664
- return values.length === 1 && typeof values[0] === "string"
665
- ? values[0]
666
- : undefined;
605
+ return values.length === 1 && typeof values[0] === "string" ? values[0] : undefined;
667
606
  };
668
607
 
669
608
  /**
@@ -704,19 +643,11 @@ export const generateService = (
704
643
  const genericPipes = (info: EmittedMember): string[] => {
705
644
  switch (info.binding) {
706
645
  case "label":
707
- return [
708
- info.wire === info.tsName ? "T.Label()" : `T.Label(${q(info.wire)})`,
709
- ];
646
+ return [info.wire === info.tsName ? "T.Label()" : `T.Label(${q(info.wire)})`];
710
647
  case "query":
711
- return [
712
- info.wire === info.tsName ? "T.Query()" : `T.Query(${q(info.wire)})`,
713
- ];
648
+ return [info.wire === info.tsName ? "T.Query()" : `T.Query(${q(info.wire)})`];
714
649
  case "header":
715
- return [
716
- info.wire === info.tsName
717
- ? "T.Header()"
718
- : `T.Header(${q(info.wire)})`,
719
- ];
650
+ return [info.wire === info.tsName ? "T.Header()" : `T.Header(${q(info.wire)})`];
720
651
  case "rawBody":
721
652
  return ["T.HttpBody()"];
722
653
  case "body":
@@ -737,10 +668,7 @@ export const generateService = (
737
668
  // Trait-table pipes: trait value JSON-inlined as the argument.
738
669
  ...Object.entries(spec.memberTraitPipes ?? {})
739
670
  .filter(([trait]) => info.traits[trait] !== undefined)
740
- .map(
741
- ([trait, builder]) =>
742
- `${builder}(${JSON.stringify(info.traits[trait])})`,
743
- ),
671
+ .map(([trait, builder]) => `${builder}(${JSON.stringify(info.traits[trait])})`),
744
672
  ...(STRING_ENCODED_TRAIT in info.traits ? ["T.StringEncoded()"] : []),
745
673
  ...(spec.memberExtraPipes?.(info) ?? []),
746
674
  ]);
@@ -750,14 +678,12 @@ export const generateService = (
750
678
  tsRefFn: (target: string) => string,
751
679
  ): string | undefined =>
752
680
  spec.memberTsType?.(info, tsRefFn) ??
753
- (spec.extraBindings ?? []).find(
754
- (b) => b.binding === info.binding && b.tsType !== undefined,
755
- )?.tsType;
681
+ (spec.extraBindings ?? []).find((b) => b.binding === info.binding && b.tsType !== undefined)
682
+ ?.tsType;
756
683
 
757
684
  const emitMember = (info: EmittedMember, selfIdx: number): string => {
758
685
  let expr =
759
- spec.memberSchema?.(info, (target) => ref(target, selfIdx)) ??
760
- ref(info.target, selfIdx);
686
+ spec.memberSchema?.(info, (target) => ref(target, selfIdx)) ?? ref(info.target, selfIdx);
761
687
  if (info.nullable) expr = `S.NullOr(${expr})`;
762
688
  const pipes = memberPipes(info);
763
689
  if (pipes.length) expr = `${expr}.pipe(${pipes.join(", ")})`;
@@ -793,16 +719,10 @@ export const generateService = (
793
719
  const profileName =
794
720
  spec.paginationProfileFor?.(pg, op) ??
795
721
  (profileNames.length === 1 ? profileNames[0] : undefined);
796
- const profile = profileName
797
- ? spec.paginationProfiles![profileName]
798
- : undefined;
722
+ const profile = profileName ? spec.paginationProfiles![profileName] : undefined;
799
723
  if (!profile) continue;
800
- const inNames = new Set(
801
- memberInfos(shapes[op.def.__input] ?? {}).map((m) => m.tsName),
802
- );
803
- const outNames = new Set(
804
- memberInfos(shapes[op.def.__output] ?? {}).map((m) => m.tsName),
805
- );
724
+ const inNames = new Set(memberInfos(shapes[op.def.__input] ?? {}).map((m) => m.tsName));
725
+ const outNames = new Set(memberInfos(shapes[op.def.__output] ?? {}).map((m) => m.tsName));
806
726
  const { ok, itemsRoot } = validatePaginated({
807
727
  trait: pg,
808
728
  inputNames: inNames,
@@ -814,10 +734,7 @@ export const generateService = (
814
734
  op.def.__pagination = pg;
815
735
  paginatedOutputs.add(op.def.__output);
816
736
  paginatedItemsRoot.set(op.def.__output, itemsRoot);
817
- paginatedItemsPath.set(
818
- op.id,
819
- String(pg.items ?? profile.itemsFallback ?? ""),
820
- );
737
+ paginatedItemsPath.set(op.id, String(pg.items ?? profile.itemsFallback ?? ""));
821
738
  outputProfile.set(op.def.__output, profile);
822
739
  opProfile.set(op.id, profile);
823
740
  usedProfiles.add(profile);
@@ -833,7 +750,6 @@ export const generateService = (
833
750
  // pipes. References are already resolved to names at this point, so a
834
751
  // difference anywhere in the tree shows up as different text.
835
752
  const structBodies = new Map<string, { id: string; name: string }>();
836
- let aliased = 0;
837
753
  // Set when any error carries CATEGORY_TRAIT, so the header only imports
838
754
  // the category module when something actually uses it.
839
755
  let usesCategories = false;
@@ -855,34 +771,26 @@ export const generateService = (
855
771
  }
856
772
  const errorField =
857
773
  spec.errors?.field ??
858
- ((mn: string, target: string) =>
859
- ` ${tsKey(mn)}: ${prelude[local(target)] ?? "S.Unknown"},`);
774
+ ((mn: string, target: string) => ` ${tsKey(mn)}: ${prelude[local(target)] ?? "S.Unknown"},`);
860
775
  const fields =
861
776
  d.members && Object.keys(d.members).length
862
- ? Object.entries(d.members).map(([mn, m]: [string, any]) =>
863
- errorField(mn, m.target),
864
- )
777
+ ? Object.entries(d.members).map(([mn, m]: [string, any]) => errorField(mn, m.target))
865
778
  : (spec.errors?.defaultFields?.(prelude) ?? [
866
779
  errorField("code", "smithy.api#Integer"),
867
780
  errorField("message", "smithy.api#String"),
868
781
  ]);
869
- const matchers = spec.errorMatchersTrait
870
- ? d.traits?.[spec.errorMatchersTrait]
871
- : undefined;
782
+ const matchers = spec.errorMatchersTrait ? d.traits?.[spec.errorMatchersTrait] : undefined;
872
783
  const categories = categoryPipes(d.traits);
873
784
  if (categories.length) usesCategories = true;
874
785
  out.push(
875
786
  errorClass({
876
787
  name,
877
788
  fields,
878
- pipes: categories.length
879
- ? `.pipe(${categories.join(", ")})`
880
- : undefined,
789
+ pipes: categories.length ? `.pipe(${categories.join(", ")})` : undefined,
881
790
  wrap:
882
791
  spec.errors?.wrap?.(d.traits ?? {}) ??
883
792
  (matchers
884
- ? (cls) =>
885
- `T.applyErrorMatchers(\n${cls},\n${JSON.stringify(matchers)},\n)`
793
+ ? (cls) => `T.applyErrorMatchers(\n${cls},\n${JSON.stringify(matchers)},\n)`
886
794
  : undefined),
887
795
  }),
888
796
  );
@@ -970,21 +878,16 @@ export const generateService = (
970
878
  fields.push(...inject.interfaceLines);
971
879
  members.push(inject.structLine);
972
880
  }
973
- const struct = members.length
974
- ? `S.Struct({\n${members.join("\n")}\n})`
975
- : `S.Struct({})`;
881
+ const struct = members.length ? `S.Struct({\n${members.join("\n")}\n})` : `S.Struct({})`;
976
882
  const structCtx = {
977
883
  id,
978
884
  isOpIo: opIoShapes.has(id),
979
885
  httpTrait: httpFor[id],
886
+ opTraits: opTraitsFor[id],
980
887
  };
981
888
  const pipes = spec.structPipes?.(structCtx) ?? [
982
- ...(structCtx.httpTrait
983
- ? [`T.Http(${JSON.stringify(structCtx.httpTrait)})`]
984
- : []),
985
- ...(spec.rootKeyDictionary && structCtx.isOpIo
986
- ? [`T.KeyDictionary(KEY_DICTIONARY)`]
987
- : []),
889
+ ...(structCtx.httpTrait ? [`T.Http(${JSON.stringify(structCtx.httpTrait)})`] : []),
890
+ ...(spec.rootKeyDictionary && structCtx.isOpIo ? [`T.KeyDictionary(KEY_DICTIONARY)`] : []),
988
891
  ];
989
892
  const tail = pipes.map((p) => `.pipe(${p})`).join("");
990
893
 
@@ -1000,16 +903,13 @@ export const generateService = (
1000
903
  // Operation I/O is excluded: those carry the operation's Http trait and
1001
904
  // must never be merged onto one another.
1002
905
  const bodyKey = `${JSON.stringify(fields)}|${struct}${tail}`;
1003
- const canonical = structCtx.isOpIo
1004
- ? undefined
1005
- : structBodies.get(bodyKey);
906
+ const canonical = structCtx.isOpIo ? undefined : structBodies.get(bodyKey);
1006
907
  if (canonical !== undefined) {
1007
908
  out.push(`export type ${name} = ${canonical.name};`);
1008
909
  out.push(`export const ${name} = ${canonical.name};\n`);
1009
910
  // Later shapes referencing this one now render the canonical name,
1010
911
  // which is what lets their bodies collapse too.
1011
912
  canonicalId.set(id, canonical.id);
1012
- aliased++;
1013
913
  } else {
1014
914
  if (!structCtx.isOpIo) {
1015
915
  structBodies.set(bodyKey, { id, name });
@@ -1028,8 +928,7 @@ export const generateService = (
1028
928
  }
1029
929
  } else if (d.type === "list") {
1030
930
  const nullable =
1031
- spec.nullableTrait !== undefined &&
1032
- spec.nullableTrait in (d.member.traits ?? {});
931
+ spec.nullableTrait !== undefined && spec.nullableTrait in (d.member.traits ?? {});
1033
932
  const item = ref(d.member.target, i);
1034
933
  out.push(
1035
934
  `export type ${name} = Array<${tsRefAt(d.member.target, id)}${nullable ? " | null" : ""}>;`,
@@ -1039,8 +938,7 @@ export const generateService = (
1039
938
  );
1040
939
  } else if (d.type === "map") {
1041
940
  const nullable =
1042
- spec.nullableTrait !== undefined &&
1043
- spec.nullableTrait in (d.value.traits ?? {});
941
+ spec.nullableTrait !== undefined && spec.nullableTrait in (d.value.traits ?? {});
1044
942
  const value = ref(d.value.target, i);
1045
943
  out.push(
1046
944
  `export type ${name} = { [key: string]: ${tsRefAt(d.value.target, id)}${nullable ? " | null" : ""} | undefined };`,
@@ -1059,9 +957,7 @@ export const generateService = (
1059
957
  .filter((t: string) => t !== id);
1060
958
  const caseKeys = caseTargets.map((t: string) => {
1061
959
  const cd = shapes[t];
1062
- return cd?.type === "structure"
1063
- ? memberInfos(cd).map((mi) => mi.tsName)
1064
- : [];
960
+ return cd?.type === "structure" ? memberInfos(cd).map((mi) => mi.tsName) : [];
1065
961
  });
1066
962
  if (spec.union) {
1067
963
  out.push(...spec.union({ name, caseTargets, caseKeys, tsRef }));
@@ -1084,8 +980,7 @@ export const generateService = (
1084
980
  const primitiveType = (target: string) => {
1085
981
  const type = tsRef(target);
1086
982
  if (shapes[target]?.type === "enum") return `${type} | (string & {})`;
1087
- if (shapes[target]?.type === "intEnum")
1088
- return `${type} | (number & {})`;
983
+ if (shapes[target]?.type === "intEnum") return `${type} | (number & {})`;
1089
984
  return type;
1090
985
  };
1091
986
  out.push(
@@ -1099,9 +994,7 @@ export const generateService = (
1099
994
  `export const ${name} = ${pure}S.Unknown.pipe(T.UnionCases(${JSON.stringify(caseKeys)}${disc ? `, ${JSON.stringify(disc)}` : ""}));\n`,
1100
995
  );
1101
996
  } else {
1102
- throw new Error(
1103
- `no union emission configured for shape ${id} — set unionStyle or union`,
1104
- );
997
+ throw new Error(`no union emission configured for shape ${id} — set unionStyle or union`);
1105
998
  }
1106
999
  } else if (d.type === "enum") {
1107
1000
  const values = Object.values(d.members ?? {})
@@ -1116,10 +1009,7 @@ export const generateService = (
1116
1009
  .map((m: any) => m.traits?.["smithy.api#enumValue"])
1117
1010
  .filter((v: unknown): v is number => typeof v === "number");
1118
1011
  const union = values.length ? values.join(" | ") : "number";
1119
- out.push(
1120
- `export type ${name} = ${union};`,
1121
- `export const ${name} = S.Number;\n`,
1122
- );
1012
+ out.push(`export type ${name} = ${union};`, `export const ${name} = S.Number;\n`);
1123
1013
  }
1124
1014
  });
1125
1015
 
@@ -1139,10 +1029,7 @@ export const generateService = (
1139
1029
  * the annotation on the structural fallback rather than asserting a type
1140
1030
  * the shape doesn't support.
1141
1031
  */
1142
- const paginatedItemTsType = (
1143
- outputId: string,
1144
- itemsPath: string,
1145
- ): string | undefined => {
1032
+ const paginatedItemTsType = (outputId: string, itemsPath: string): string | undefined => {
1146
1033
  // No items path: `.items()` is a page passthrough at runtime, so an
1147
1034
  // item IS a whole response.
1148
1035
  if (!itemsPath) return tsRef(outputId);
@@ -1168,6 +1055,7 @@ export const generateService = (
1168
1055
  return fannedOut ? tsRef(id) : undefined;
1169
1056
  };
1170
1057
 
1058
+ const usedProtocols = new Set<string>();
1171
1059
  const emitOperation =
1172
1060
  spec.operation ??
1173
1061
  ((ctx: OperationEmit): string => {
@@ -1178,13 +1066,9 @@ export const generateService = (
1178
1066
  const errList = [...ctx.errorNames, ...decl.commonErrorClasses];
1179
1067
  const overrides = decl.overrides?.(ctx);
1180
1068
  const contextType = overrides?.contextType ?? decl.contextType;
1181
- const protocol = overrides?.protocol ?? decl.protocol;
1182
1069
  const paginated = ctx.pagination !== undefined;
1183
1070
  const itemTsType = paginated
1184
- ? paginatedItemTsType(
1185
- ctx.op.def.__output,
1186
- paginatedItemsPath.get(ctx.op.id) ?? "",
1187
- )
1071
+ ? paginatedItemTsType(ctx.op.def.__output, paginatedItemsPath.get(ctx.op.id) ?? "")
1188
1072
  : undefined;
1189
1073
  const typeAnnotation =
1190
1074
  `API.${paginated ? "PaginatedOperationMethod" : "OperationMethod"}<\n` +
@@ -1194,17 +1078,18 @@ export const generateService = (
1194
1078
  ` ${contextType}` +
1195
1079
  (itemTsType ? `,\n ${itemTsType}\n` : `\n`) +
1196
1080
  `>`;
1081
+ const protocol =
1082
+ (paginated && opProfile.get(ctx.op.id)?.protocol) || overrides?.protocol || decl.protocol;
1083
+ usedProtocols.add(protocol);
1197
1084
  const config =
1198
1085
  `{\n` +
1199
1086
  ` input: ${ctx.inputName},\n` +
1200
1087
  ` output: ${ctx.outputSchema},\n` +
1201
1088
  ` errors: [${errList.join(", ")}],\n` +
1202
- ` protocol: ${(paginated && opProfile.get(ctx.op.id)?.protocol) || protocol},\n` +
1089
+ ` protocol: ${protocol},\n` +
1203
1090
  (decl.retry ? ` retry: ${decl.retry},\n` : "") +
1204
1091
  (decl.extraConfig?.(ctx) ?? []).map((l) => ` ${l},\n`).join("") +
1205
- (paginated
1206
- ? ` pagination: ${JSON.stringify(ctx.pagination)} as const,\n`
1207
- : "") +
1092
+ (paginated ? ` pagination: ${JSON.stringify(ctx.pagination)} as const,\n` : "") +
1208
1093
  `}`;
1209
1094
  return [
1210
1095
  errorUnionAlias(ctx.opName, ctx.errorNames, decl.commonErrorType),
@@ -1270,9 +1155,7 @@ export const generateService = (
1270
1155
  const defaultHeader = (ctx: { hasPaginated: boolean }): string => {
1271
1156
  const decl = spec.operationDecl;
1272
1157
  if (!decl) {
1273
- throw new Error(
1274
- "the default header needs operationDecl — or pass header",
1275
- );
1158
+ throw new Error("the default header needs operationDecl — or pass header");
1276
1159
  }
1277
1160
  const retryNs = decl.retry?.split(".")[0];
1278
1161
  // Imports the used pagination profiles pull in: their protocol consts
@@ -1299,12 +1182,10 @@ export const generateService = (
1299
1182
  }. Do not edit.\n` +
1300
1183
  `import * as S from "@distilled.cloud/core/schema";\n` +
1301
1184
  `import * as API from "@distilled.cloud/core/api";\n` +
1302
- (usesCategories
1303
- ? `import * as C from "@distilled.cloud/core/category";\n`
1304
- : "") +
1185
+ (usesCategories ? `import * as C from "@distilled.cloud/core/category";\n` : "") +
1305
1186
  `import * as T from "../traits.ts";\n` +
1306
1187
  `import {\n` +
1307
- ` ${decl.protocol},\n` +
1188
+ (spec.operation || usedProtocols.has(decl.protocol) ? ` ${decl.protocol},\n` : "") +
1308
1189
  profileProtocols.map((p) => ` ${p},\n`).join("") +
1309
1190
  ` type ${decl.commonErrorType},\n` +
1310
1191
  ` type ${decl.contextType},\n` +