@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
@@ -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;
@@ -196,6 +169,8 @@ export interface SdkSpec {
196
169
  readonly prelude?: Record<string, string>;
197
170
  /** Prelude scalar → TS type map. Default {@link TS_JSON_PRELUDE}. */
198
171
  readonly tsPrelude?: Record<string, string>;
172
+ /** Use Codec for service-free, same-type schemas; Schema leaves services unspecified. */
173
+ readonly schemaType?: "Schema" | "Codec";
199
174
  /** Wire member name → TS-facing name. Default: identity. */
200
175
  readonly memberName?: (name: string) => string;
201
176
  /** Operation shape name → exported const name. Default: lowerFirst. */
@@ -212,10 +187,7 @@ export interface SdkSpec {
212
187
  * fields reference schema consts); the error shapes themselves are still
213
188
  * emitted as error classes, not schemas.
214
189
  */
215
- readonly extraRoots?: (
216
- selected: readonly OpEntry[],
217
- shapes: ShapeMap,
218
- ) => Iterable<string>;
190
+ readonly extraRoots?: (selected: readonly OpEntry[], shapes: ShapeMap) => Iterable<string>;
219
191
 
220
192
  /**
221
193
  * Provider member bindings as data, checked in order between the generic
@@ -242,9 +214,7 @@ export interface SdkSpec {
242
214
  * Which wire-name rule a binding follows. Defaults: the three generic
243
215
  * kinds map to themselves, everything else to `"other"` (jsonName).
244
216
  */
245
- readonly wireKind?: (
246
- binding: MemberBinding,
247
- ) => "label" | "query" | "header" | "other";
217
+ readonly wireKind?: (binding: MemberBinding) => "label" | "query" | "header" | "other";
248
218
  /** Trait id marking a member nullable (`S.NullOr` + `| null`). */
249
219
  readonly nullableTrait?: string;
250
220
  /**
@@ -272,6 +242,8 @@ export interface SdkSpec {
272
242
  readonly memberExtraPipes?: (m: EmittedMember) => string[];
273
243
  /** Full override of member pipe emission (rarely needed). */
274
244
  readonly memberPipes?: (m: EmittedMember) => string[];
245
+ /** Override the value schema before nullability, bindings and optionality. */
246
+ readonly memberSchema?: (m: EmittedMember, ref: (target: string) => string) => string | undefined;
275
247
  /** Function override for member TS types beyond the binding table. */
276
248
  readonly memberTsType?: (
277
249
  m: EmittedMember,
@@ -286,6 +258,8 @@ export interface SdkSpec {
286
258
  readonly id: string;
287
259
  readonly isOpIo: boolean;
288
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;
289
263
  }) => string[];
290
264
 
291
265
  /**
@@ -302,10 +276,7 @@ export interface SdkSpec {
302
276
  * trait / shape). Default: the sole declared profile; with several
303
277
  * profiles this becomes required for ops to paginate.
304
278
  */
305
- readonly paginationProfileFor?: (
306
- trait: any,
307
- op: OpEntry,
308
- ) => string | undefined;
279
+ readonly paginationProfileFor?: (trait: any, op: OpEntry) => string | undefined;
309
280
 
310
281
  /**
311
282
  * Service-wide fallback key dictionary stamped on op I/O roots (emitted
@@ -353,8 +324,10 @@ export interface SdkSpec {
353
324
  * and the schema is `S.Unknown.pipe(T.UnionCases([...case key sets]))` —
354
325
  * the protocol discriminates by key-set at decode time (for APIs that
355
326
  * return every case's keys with nulls, like Cloudflare's).
327
+ * `"untagged"`: validate the value directly against the case schemas.
328
+ * `"primitive"`: emit unwrapped unions of primitive or enum values.
356
329
  */
357
- readonly unionStyle?: "opaque-cases";
330
+ readonly unionStyle?: "opaque-cases" | "untagged" | "primitive";
358
331
  /** Full override of union emission. */
359
332
  readonly union?: (ctx: {
360
333
  readonly name: string;
@@ -389,9 +362,7 @@ export interface SdkSpec {
389
362
  /** Field line for a declared member. Default: prelude-mapped schema. */
390
363
  readonly field?: (name: string, target: string) => string;
391
364
  /** Optional wrapper (e.g. matcher application) from the shape's traits. */
392
- readonly wrap?: (
393
- traits: Record<string, any>,
394
- ) => ((cls: string) => string) | undefined;
365
+ readonly wrap?: (traits: Record<string, any>) => ((cls: string) => string) | undefined;
395
366
  };
396
367
 
397
368
  /**
@@ -407,13 +378,26 @@ export interface SdkSpec {
407
378
  /** Error classes appended to every op's `errors: [...]` list. */
408
379
  readonly commonErrorClasses: readonly string[];
409
380
  readonly protocol: string;
410
- /** The retry tag expression (e.g. `Retry.Retry`). */
411
- readonly retry: string;
381
+ /** The retry tag expression (e.g. `Retry.Retry`). Omit to disable retries. */
382
+ readonly retry?: string;
412
383
  /**
413
384
  * Extra config lines inserted before the pagination entry (e.g. AWS's
414
385
  * `operationName` and `endpointHostPrefix`).
415
386
  */
416
387
  readonly extraConfig?: (ctx: OperationEmit) => string[];
388
+ /**
389
+ * Per-operation `protocol` / `contextType` replacing the declared
390
+ * defaults, e.g. an unauthenticated login endpoint on a public protocol
391
+ * whose context has no credentials. Return `undefined` for the defaults.
392
+ * The header only imports the defaults; a spec that overrides must add
393
+ * the extra imports itself (see {@link SdkSpec.postProcess}).
394
+ */
395
+ readonly overrides?: (ctx: OperationEmit) =>
396
+ | {
397
+ readonly protocol?: string;
398
+ readonly contextType?: string;
399
+ }
400
+ | undefined;
417
401
  };
418
402
  /** Full override of operation const emission. */
419
403
  readonly operation?: (ctx: OperationEmit) => string;
@@ -425,10 +409,7 @@ export interface SdkSpec {
425
409
  * `../retry.ts`), re-exports the op error/context types, and emits the
426
410
  * `KEY_DICTIONARY` const when {@link SdkSpec.rootKeyDictionary} is set.
427
411
  */
428
- readonly header?: (ctx: {
429
- readonly hasPaginated: boolean;
430
- readonly model: any;
431
- }) => string;
412
+ readonly header?: (ctx: { readonly hasPaginated: boolean; readonly model: any }) => string;
432
413
 
433
414
  /** Final pass over the assembled module (e.g. pruning unused imports). */
434
415
  readonly postProcess?: (code: string) => string;
@@ -447,10 +428,7 @@ export interface GeneratedService {
447
428
  }
448
429
 
449
430
  /** Compile one Smithy model into a service module. */
450
- export const generateService = (
451
- model: any,
452
- spec: SdkSpec,
453
- ): GeneratedService => {
431
+ export const generateService = (model: any, spec: SdkSpec): GeneratedService => {
454
432
  // `"true" | "false"` request members become real booleans that travel as
455
433
  // their string spelling (see boolean-string-enums.ts).
456
434
  booleanStringEnums(model);
@@ -465,11 +443,8 @@ export const generateService = (
465
443
  // operation has an input shape that can carry operation-level traits.
466
444
  const operations = collectOperations(shapes);
467
445
  const httpFor: Record<string, any> = {}; // input shape id → http trait
468
- const ns = modelNamespace(
469
- operations,
470
- shapes,
471
- spec.namespaceFallback ?? "smithy.unknown",
472
- );
446
+ const opTraitsFor: Record<string, Record<string, unknown>> = {}; // input shape id → op traits
447
+ const ns = modelNamespace(operations, shapes, spec.namespaceFallback ?? "smithy.unknown");
473
448
 
474
449
  const selected: OpEntry[] = [];
475
450
  for (const op of operations) {
@@ -481,6 +456,7 @@ export const generateService = (
481
456
 
482
457
  const http = op.def.traits?.["smithy.api#http"];
483
458
  if (http) httpFor[input] = http;
459
+ if (op.def.traits) opTraitsFor[input] = op.def.traits;
484
460
  }
485
461
 
486
462
  if (selected.length === 0) return { code: "", operations: 0 };
@@ -512,8 +488,7 @@ export const generateService = (
512
488
 
513
489
  const rawRef = makeSchemaRef(prelude, indexOf);
514
490
  const rawTsRef = makeTsRef(tsPrelude);
515
- const ref = (target: string, selfIdx: number) =>
516
- rawRef(canon(target), selfIdx);
491
+ const ref = (target: string, selfIdx: number) => rawRef(canon(target), selfIdx);
517
492
  const tsRef = (target: string) => rawTsRef(canon(target));
518
493
 
519
494
  // Direction classification for enum openness. Enum ALIASES are emitted
@@ -569,18 +544,10 @@ export const generateService = (
569
544
  const wireKind =
570
545
  spec.wireKind ??
571
546
  ((b: MemberBinding): "label" | "query" | "header" | "other" =>
572
- b === "label"
573
- ? "label"
574
- : b === "query"
575
- ? "query"
576
- : b === "header"
577
- ? "header"
578
- : "other");
547
+ b === "label" ? "label" : b === "query" ? "query" : b === "header" ? "header" : "other");
579
548
 
580
549
  // The generic binding cascade; provider bindings slot in after headers.
581
- const extraBindingOf = (
582
- traits: Record<string, any>,
583
- ): MemberBinding | undefined => {
550
+ const extraBindingOf = (traits: Record<string, any>): MemberBinding | undefined => {
584
551
  for (const b of spec.extraBindings ?? []) {
585
552
  if (b.trait in traits) return b.binding;
586
553
  }
@@ -593,8 +560,7 @@ export const generateService = (
593
560
  ? "query"
594
561
  : "smithy.api#httpHeader" in traits
595
562
  ? "header"
596
- : (extraBindingOf(traits) ??
597
- ("smithy.api#httpPayload" in traits ? "rawBody" : "body"));
563
+ : (extraBindingOf(traits) ?? ("smithy.api#httpPayload" in traits ? "rawBody" : "body"));
598
564
 
599
565
  // Shapes reachable from any response/error root — used to scope the
600
566
  // blanket-nullable-optionals rule to reads (the wire returns explicit
@@ -603,10 +569,7 @@ export const generateService = (
603
569
  spec.optionalsNullable === true
604
570
  ? reachableFrom(
605
571
  shapes,
606
- [
607
- ...selected.map((op) => op.def.__output),
608
- ...collectOpErrorIds(selected, shapes),
609
- ],
572
+ [...selected.map((op) => op.def.__output), ...collectOpErrorIds(selected, shapes)],
610
573
  shapeDeps,
611
574
  )
612
575
  : undefined;
@@ -639,9 +602,7 @@ export const generateService = (
639
602
  const values = Object.values(d.members ?? {}).map(
640
603
  (m: any) => m.traits?.["smithy.api#enumValue"],
641
604
  );
642
- return values.length === 1 && typeof values[0] === "string"
643
- ? values[0]
644
- : undefined;
605
+ return values.length === 1 && typeof values[0] === "string" ? values[0] : undefined;
645
606
  };
646
607
 
647
608
  /**
@@ -682,19 +643,11 @@ export const generateService = (
682
643
  const genericPipes = (info: EmittedMember): string[] => {
683
644
  switch (info.binding) {
684
645
  case "label":
685
- return [
686
- info.wire === info.tsName ? "T.Label()" : `T.Label(${q(info.wire)})`,
687
- ];
646
+ return [info.wire === info.tsName ? "T.Label()" : `T.Label(${q(info.wire)})`];
688
647
  case "query":
689
- return [
690
- info.wire === info.tsName ? "T.Query()" : `T.Query(${q(info.wire)})`,
691
- ];
648
+ return [info.wire === info.tsName ? "T.Query()" : `T.Query(${q(info.wire)})`];
692
649
  case "header":
693
- return [
694
- info.wire === info.tsName
695
- ? "T.Header()"
696
- : `T.Header(${q(info.wire)})`,
697
- ];
650
+ return [info.wire === info.tsName ? "T.Header()" : `T.Header(${q(info.wire)})`];
698
651
  case "rawBody":
699
652
  return ["T.HttpBody()"];
700
653
  case "body":
@@ -715,10 +668,7 @@ export const generateService = (
715
668
  // Trait-table pipes: trait value JSON-inlined as the argument.
716
669
  ...Object.entries(spec.memberTraitPipes ?? {})
717
670
  .filter(([trait]) => info.traits[trait] !== undefined)
718
- .map(
719
- ([trait, builder]) =>
720
- `${builder}(${JSON.stringify(info.traits[trait])})`,
721
- ),
671
+ .map(([trait, builder]) => `${builder}(${JSON.stringify(info.traits[trait])})`),
722
672
  ...(STRING_ENCODED_TRAIT in info.traits ? ["T.StringEncoded()"] : []),
723
673
  ...(spec.memberExtraPipes?.(info) ?? []),
724
674
  ]);
@@ -728,12 +678,12 @@ export const generateService = (
728
678
  tsRefFn: (target: string) => string,
729
679
  ): string | undefined =>
730
680
  spec.memberTsType?.(info, tsRefFn) ??
731
- (spec.extraBindings ?? []).find(
732
- (b) => b.binding === info.binding && b.tsType !== undefined,
733
- )?.tsType;
681
+ (spec.extraBindings ?? []).find((b) => b.binding === info.binding && b.tsType !== undefined)
682
+ ?.tsType;
734
683
 
735
684
  const emitMember = (info: EmittedMember, selfIdx: number): string => {
736
- let expr = ref(info.target, selfIdx);
685
+ let expr =
686
+ spec.memberSchema?.(info, (target) => ref(target, selfIdx)) ?? ref(info.target, selfIdx);
737
687
  if (info.nullable) expr = `S.NullOr(${expr})`;
738
688
  const pipes = memberPipes(info);
739
689
  if (pipes.length) expr = `${expr}.pipe(${pipes.join(", ")})`;
@@ -769,16 +719,10 @@ export const generateService = (
769
719
  const profileName =
770
720
  spec.paginationProfileFor?.(pg, op) ??
771
721
  (profileNames.length === 1 ? profileNames[0] : undefined);
772
- const profile = profileName
773
- ? spec.paginationProfiles![profileName]
774
- : undefined;
722
+ const profile = profileName ? spec.paginationProfiles![profileName] : undefined;
775
723
  if (!profile) continue;
776
- const inNames = new Set(
777
- memberInfos(shapes[op.def.__input] ?? {}).map((m) => m.tsName),
778
- );
779
- const outNames = new Set(
780
- memberInfos(shapes[op.def.__output] ?? {}).map((m) => m.tsName),
781
- );
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));
782
726
  const { ok, itemsRoot } = validatePaginated({
783
727
  trait: pg,
784
728
  inputNames: inNames,
@@ -790,10 +734,7 @@ export const generateService = (
790
734
  op.def.__pagination = pg;
791
735
  paginatedOutputs.add(op.def.__output);
792
736
  paginatedItemsRoot.set(op.def.__output, itemsRoot);
793
- paginatedItemsPath.set(
794
- op.id,
795
- String(pg.items ?? profile.itemsFallback ?? ""),
796
- );
737
+ paginatedItemsPath.set(op.id, String(pg.items ?? profile.itemsFallback ?? ""));
797
738
  outputProfile.set(op.def.__output, profile);
798
739
  opProfile.set(op.id, profile);
799
740
  usedProfiles.add(profile);
@@ -809,7 +750,6 @@ export const generateService = (
809
750
  // pipes. References are already resolved to names at this point, so a
810
751
  // difference anywhere in the tree shows up as different text.
811
752
  const structBodies = new Map<string, { id: string; name: string }>();
812
- let aliased = 0;
813
753
  // Set when any error carries CATEGORY_TRAIT, so the header only imports
814
754
  // the category module when something actually uses it.
815
755
  let usesCategories = false;
@@ -831,34 +771,26 @@ export const generateService = (
831
771
  }
832
772
  const errorField =
833
773
  spec.errors?.field ??
834
- ((mn: string, target: string) =>
835
- ` ${tsKey(mn)}: ${prelude[local(target)] ?? "S.Unknown"},`);
774
+ ((mn: string, target: string) => ` ${tsKey(mn)}: ${prelude[local(target)] ?? "S.Unknown"},`);
836
775
  const fields =
837
776
  d.members && Object.keys(d.members).length
838
- ? Object.entries(d.members).map(([mn, m]: [string, any]) =>
839
- errorField(mn, m.target),
840
- )
777
+ ? Object.entries(d.members).map(([mn, m]: [string, any]) => errorField(mn, m.target))
841
778
  : (spec.errors?.defaultFields?.(prelude) ?? [
842
779
  errorField("code", "smithy.api#Integer"),
843
780
  errorField("message", "smithy.api#String"),
844
781
  ]);
845
- const matchers = spec.errorMatchersTrait
846
- ? d.traits?.[spec.errorMatchersTrait]
847
- : undefined;
782
+ const matchers = spec.errorMatchersTrait ? d.traits?.[spec.errorMatchersTrait] : undefined;
848
783
  const categories = categoryPipes(d.traits);
849
784
  if (categories.length) usesCategories = true;
850
785
  out.push(
851
786
  errorClass({
852
787
  name,
853
788
  fields,
854
- pipes: categories.length
855
- ? `.pipe(${categories.join(", ")})`
856
- : undefined,
789
+ pipes: categories.length ? `.pipe(${categories.join(", ")})` : undefined,
857
790
  wrap:
858
791
  spec.errors?.wrap?.(d.traits ?? {}) ??
859
792
  (matchers
860
- ? (cls) =>
861
- `T.applyErrorMatchers(\n${cls},\n${JSON.stringify(matchers)},\n)`
793
+ ? (cls) => `T.applyErrorMatchers(\n${cls},\n${JSON.stringify(matchers)},\n)`
862
794
  : undefined),
863
795
  }),
864
796
  );
@@ -918,6 +850,7 @@ export const generateService = (
918
850
  pure,
919
851
  multiline: true,
920
852
  annotateIdentifier: true,
853
+ castTo: `S.${spec.schemaType ?? "Schema"}<${name}>`,
921
854
  expr: `${ref(m.target, i)}.pipe(${rootPipes.join(", ")})`,
922
855
  }),
923
856
  );
@@ -945,21 +878,16 @@ export const generateService = (
945
878
  fields.push(...inject.interfaceLines);
946
879
  members.push(inject.structLine);
947
880
  }
948
- const struct = members.length
949
- ? `S.Struct({\n${members.join("\n")}\n})`
950
- : `S.Struct({})`;
881
+ const struct = members.length ? `S.Struct({\n${members.join("\n")}\n})` : `S.Struct({})`;
951
882
  const structCtx = {
952
883
  id,
953
884
  isOpIo: opIoShapes.has(id),
954
885
  httpTrait: httpFor[id],
886
+ opTraits: opTraitsFor[id],
955
887
  };
956
888
  const pipes = spec.structPipes?.(structCtx) ?? [
957
- ...(structCtx.httpTrait
958
- ? [`T.Http(${JSON.stringify(structCtx.httpTrait)})`]
959
- : []),
960
- ...(spec.rootKeyDictionary && structCtx.isOpIo
961
- ? [`T.KeyDictionary(KEY_DICTIONARY)`]
962
- : []),
889
+ ...(structCtx.httpTrait ? [`T.Http(${JSON.stringify(structCtx.httpTrait)})`] : []),
890
+ ...(spec.rootKeyDictionary && structCtx.isOpIo ? [`T.KeyDictionary(KEY_DICTIONARY)`] : []),
963
891
  ];
964
892
  const tail = pipes.map((p) => `.pipe(${p})`).join("");
965
893
 
@@ -975,16 +903,13 @@ export const generateService = (
975
903
  // Operation I/O is excluded: those carry the operation's Http trait and
976
904
  // must never be merged onto one another.
977
905
  const bodyKey = `${JSON.stringify(fields)}|${struct}${tail}`;
978
- const canonical = structCtx.isOpIo
979
- ? undefined
980
- : structBodies.get(bodyKey);
906
+ const canonical = structCtx.isOpIo ? undefined : structBodies.get(bodyKey);
981
907
  if (canonical !== undefined) {
982
908
  out.push(`export type ${name} = ${canonical.name};`);
983
909
  out.push(`export const ${name} = ${canonical.name};\n`);
984
910
  // Later shapes referencing this one now render the canonical name,
985
911
  // which is what lets their bodies collapse too.
986
912
  canonicalId.set(id, canonical.id);
987
- aliased++;
988
913
  } else {
989
914
  if (!structCtx.isOpIo) {
990
915
  structBodies.set(bodyKey, { id, name });
@@ -996,31 +921,30 @@ export const generateService = (
996
921
  pure,
997
922
  multiline: true,
998
923
  annotateIdentifier: true,
924
+ castTo: `S.${spec.schemaType ?? "Schema"}<${name}>`,
999
925
  expr: `${struct}${tail}`,
1000
926
  }),
1001
927
  );
1002
928
  }
1003
929
  } else if (d.type === "list") {
1004
930
  const nullable =
1005
- spec.nullableTrait !== undefined &&
1006
- spec.nullableTrait in (d.member.traits ?? {});
931
+ spec.nullableTrait !== undefined && spec.nullableTrait in (d.member.traits ?? {});
1007
932
  const item = ref(d.member.target, i);
1008
933
  out.push(
1009
934
  `export type ${name} = Array<${tsRefAt(d.member.target, id)}${nullable ? " | null" : ""}>;`,
1010
935
  );
1011
936
  out.push(
1012
- `export const ${name} = ${pure}S.Array(${nullable ? `S.NullOr(${item})` : item}) as any as S.Schema<${name}>;\n`,
937
+ `export const ${name} = ${pure}S.Array(${nullable ? `S.NullOr(${item})` : item}) as any as S.${spec.schemaType ?? "Schema"}<${name}>;\n`,
1013
938
  );
1014
939
  } else if (d.type === "map") {
1015
940
  const nullable =
1016
- spec.nullableTrait !== undefined &&
1017
- spec.nullableTrait in (d.value.traits ?? {});
941
+ spec.nullableTrait !== undefined && spec.nullableTrait in (d.value.traits ?? {});
1018
942
  const value = ref(d.value.target, i);
1019
943
  out.push(
1020
944
  `export type ${name} = { [key: string]: ${tsRefAt(d.value.target, id)}${nullable ? " | null" : ""} | undefined };`,
1021
945
  );
1022
946
  out.push(
1023
- `export const ${name} = ${pure}S.Record(S.String, ${nullable ? `S.NullOr(${value})` : value}) as any as S.Schema<${name}>;\n`,
947
+ `export const ${name} = ${pure}S.Record(S.String, ${nullable ? `S.NullOr(${value})` : value}) as any as S.${spec.schemaType ?? "Schema"}<${name}>;\n`,
1024
948
  );
1025
949
  } else if (d.type === "union") {
1026
950
  // A union arm targeting the union itself carries no information
@@ -1033,12 +957,36 @@ export const generateService = (
1033
957
  .filter((t: string) => t !== id);
1034
958
  const caseKeys = caseTargets.map((t: string) => {
1035
959
  const cd = shapes[t];
1036
- return cd?.type === "structure"
1037
- ? memberInfos(cd).map((mi) => mi.tsName)
1038
- : [];
960
+ return cd?.type === "structure" ? memberInfos(cd).map((mi) => mi.tsName) : [];
1039
961
  });
1040
962
  if (spec.union) {
1041
963
  out.push(...spec.union({ name, caseTargets, caseKeys, tsRef }));
964
+ } else if (spec.unionStyle === "untagged") {
965
+ out.push(
966
+ `export type ${name} = ${caseTargets.map((t) => tsRefAt(t, id)).join(" | ") || "never"};`,
967
+ `export const ${name} = ${pure}S.Union([${caseTargets.map((t) => ref(t, i)).join(", ")}]) as any as S.${spec.schemaType ?? "Schema"}<${name}>;\n`,
968
+ );
969
+ } else if (
970
+ spec.unionStyle === "primitive" &&
971
+ caseTargets.length > 0 &&
972
+ caseTargets.every(
973
+ (target) =>
974
+ ["string", "number", "boolean"].includes(tsRef(target)) ||
975
+ shapes[target]?.type === "enum" ||
976
+ shapes[target]?.type === "intEnum",
977
+ )
978
+ ) {
979
+ // Primitive unions keep response enums open to match S.String/S.Number.
980
+ const primitiveType = (target: string) => {
981
+ const type = tsRef(target);
982
+ if (shapes[target]?.type === "enum") return `${type} | (string & {})`;
983
+ if (shapes[target]?.type === "intEnum") return `${type} | (number & {})`;
984
+ return type;
985
+ };
986
+ out.push(
987
+ `export type ${name} = ${caseTargets.map(primitiveType).join(" | ")};`,
988
+ `export const ${name}: S.Codec<${name}> = ${pure}S.Union([${caseTargets.map((t) => ref(t, i)).join(", ")}]);\n`,
989
+ );
1042
990
  } else if (spec.unionStyle === "opaque-cases") {
1043
991
  const disc = unionDiscriminator(caseTargets);
1044
992
  out.push(
@@ -1046,9 +994,7 @@ export const generateService = (
1046
994
  `export const ${name} = ${pure}S.Unknown.pipe(T.UnionCases(${JSON.stringify(caseKeys)}${disc ? `, ${JSON.stringify(disc)}` : ""}));\n`,
1047
995
  );
1048
996
  } else {
1049
- throw new Error(
1050
- `no union emission configured for shape ${id} — set unionStyle or union`,
1051
- );
997
+ throw new Error(`no union emission configured for shape ${id} — set unionStyle or union`);
1052
998
  }
1053
999
  } else if (d.type === "enum") {
1054
1000
  const values = Object.values(d.members ?? {})
@@ -1063,10 +1009,7 @@ export const generateService = (
1063
1009
  .map((m: any) => m.traits?.["smithy.api#enumValue"])
1064
1010
  .filter((v: unknown): v is number => typeof v === "number");
1065
1011
  const union = values.length ? values.join(" | ") : "number";
1066
- out.push(
1067
- `export type ${name} = ${union};`,
1068
- `export const ${name} = S.Number;\n`,
1069
- );
1012
+ out.push(`export type ${name} = ${union};`, `export const ${name} = S.Number;\n`);
1070
1013
  }
1071
1014
  });
1072
1015
 
@@ -1086,10 +1029,7 @@ export const generateService = (
1086
1029
  * the annotation on the structural fallback rather than asserting a type
1087
1030
  * the shape doesn't support.
1088
1031
  */
1089
- const paginatedItemTsType = (
1090
- outputId: string,
1091
- itemsPath: string,
1092
- ): string | undefined => {
1032
+ const paginatedItemTsType = (outputId: string, itemsPath: string): string | undefined => {
1093
1033
  // No items path: `.items()` is a page passthrough at runtime, so an
1094
1034
  // item IS a whole response.
1095
1035
  if (!itemsPath) return tsRef(outputId);
@@ -1115,6 +1055,7 @@ export const generateService = (
1115
1055
  return fannedOut ? tsRef(id) : undefined;
1116
1056
  };
1117
1057
 
1058
+ const usedProtocols = new Set<string>();
1118
1059
  const emitOperation =
1119
1060
  spec.operation ??
1120
1061
  ((ctx: OperationEmit): string => {
@@ -1123,32 +1064,32 @@ export const generateService = (
1123
1064
  throw new Error("SdkSpec needs either operationDecl or operation");
1124
1065
  }
1125
1066
  const errList = [...ctx.errorNames, ...decl.commonErrorClasses];
1067
+ const overrides = decl.overrides?.(ctx);
1068
+ const contextType = overrides?.contextType ?? decl.contextType;
1126
1069
  const paginated = ctx.pagination !== undefined;
1127
1070
  const itemTsType = paginated
1128
- ? paginatedItemTsType(
1129
- ctx.op.def.__output,
1130
- paginatedItemsPath.get(ctx.op.id) ?? "",
1131
- )
1071
+ ? paginatedItemTsType(ctx.op.def.__output, paginatedItemsPath.get(ctx.op.id) ?? "")
1132
1072
  : undefined;
1133
1073
  const typeAnnotation =
1134
1074
  `API.${paginated ? "PaginatedOperationMethod" : "OperationMethod"}<\n` +
1135
1075
  ` ${ctx.inputName},\n` +
1136
1076
  ` ${ctx.outputTsType},\n` +
1137
1077
  ` ${ctx.opName}Error,\n` +
1138
- ` ${decl.contextType}` +
1078
+ ` ${contextType}` +
1139
1079
  (itemTsType ? `,\n ${itemTsType}\n` : `\n`) +
1140
1080
  `>`;
1081
+ const protocol =
1082
+ (paginated && opProfile.get(ctx.op.id)?.protocol) || overrides?.protocol || decl.protocol;
1083
+ usedProtocols.add(protocol);
1141
1084
  const config =
1142
1085
  `{\n` +
1143
1086
  ` input: ${ctx.inputName},\n` +
1144
1087
  ` output: ${ctx.outputSchema},\n` +
1145
1088
  ` errors: [${errList.join(", ")}],\n` +
1146
- ` protocol: ${(paginated && opProfile.get(ctx.op.id)?.protocol) || decl.protocol},\n` +
1147
- ` retry: ${decl.retry},\n` +
1089
+ ` protocol: ${protocol},\n` +
1090
+ (decl.retry ? ` retry: ${decl.retry},\n` : "") +
1148
1091
  (decl.extraConfig?.(ctx) ?? []).map((l) => ` ${l},\n`).join("") +
1149
- (paginated
1150
- ? ` pagination: ${JSON.stringify(ctx.pagination)} as const,\n`
1151
- : "") +
1092
+ (paginated ? ` pagination: ${JSON.stringify(ctx.pagination)} as const,\n` : "") +
1152
1093
  `}`;
1153
1094
  return [
1154
1095
  errorUnionAlias(ctx.opName, ctx.errorNames, decl.commonErrorType),
@@ -1214,11 +1155,9 @@ export const generateService = (
1214
1155
  const defaultHeader = (ctx: { hasPaginated: boolean }): string => {
1215
1156
  const decl = spec.operationDecl;
1216
1157
  if (!decl) {
1217
- throw new Error(
1218
- "the default header needs operationDecl — or pass header",
1219
- );
1158
+ throw new Error("the default header needs operationDecl — or pass header");
1220
1159
  }
1221
- const retryNs = decl.retry.split(".")[0];
1160
+ const retryNs = decl.retry?.split(".")[0];
1222
1161
  // Imports the used pagination profiles pull in: their protocol consts
1223
1162
  // (from the protocol module) and strategy/injected-member names (from
1224
1163
  // the pagination module).
@@ -1243,12 +1182,10 @@ export const generateService = (
1243
1182
  }. Do not edit.\n` +
1244
1183
  `import * as S from "@distilled.cloud/core/schema";\n` +
1245
1184
  `import * as API from "@distilled.cloud/core/api";\n` +
1246
- (usesCategories
1247
- ? `import * as C from "@distilled.cloud/core/category";\n`
1248
- : "") +
1185
+ (usesCategories ? `import * as C from "@distilled.cloud/core/category";\n` : "") +
1249
1186
  `import * as T from "../traits.ts";\n` +
1250
1187
  `import {\n` +
1251
- ` ${decl.protocol},\n` +
1188
+ (spec.operation || usedProtocols.has(decl.protocol) ? ` ${decl.protocol},\n` : "") +
1252
1189
  profileProtocols.map((p) => ` ${p},\n`).join("") +
1253
1190
  ` type ${decl.commonErrorType},\n` +
1254
1191
  ` type ${decl.contextType},\n` +
@@ -1256,8 +1193,10 @@ export const generateService = (
1256
1193
  (ctx.hasPaginated && pagImports.length
1257
1194
  ? `import { ${pagImports.join(", ")} } from "../pagination.ts";\n`
1258
1195
  : "") +
1259
- `import { ${[...decl.commonErrorClasses].sort().join(", ")} } from "../errors.ts";\n` +
1260
- `import * as ${retryNs} from "../retry.ts";\n\n` +
1196
+ (decl.commonErrorClasses.length
1197
+ ? `import { ${[...decl.commonErrorClasses].sort().join(", ")} } from "../errors.ts";\n`
1198
+ : "") +
1199
+ (retryNs ? `import * as ${retryNs} from "../retry.ts";\n\n` : "\n") +
1261
1200
  // Re-exported so inferred provider types downstream can always name them.
1262
1201
  `export type { ${decl.commonErrorType}, ${decl.contextType} };\n\n` +
1263
1202
  (spec.rootKeyDictionary