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

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 (312) hide show
  1. package/lib/api.d.ts +118 -13
  2. package/lib/api.d.ts.map +1 -1
  3. package/lib/api.js +755 -147
  4. package/lib/api.js.map +1 -1
  5. package/lib/category.d.ts.map +1 -1
  6. package/lib/category.js +146 -146
  7. package/lib/category.js.map +1 -1
  8. package/lib/chunks.d.ts +3 -0
  9. package/lib/chunks.d.ts.map +1 -0
  10. package/lib/chunks.js +11 -0
  11. package/lib/chunks.js.map +1 -0
  12. package/lib/codegen/boolean-string-enums.js +36 -36
  13. package/lib/codegen/chunk.d.ts +7 -0
  14. package/lib/codegen/chunk.d.ts.map +1 -0
  15. package/lib/codegen/chunk.js +139 -0
  16. package/lib/codegen/chunk.js.map +1 -0
  17. package/lib/codegen/cli.d.ts.map +1 -1
  18. package/lib/codegen/cli.js +28 -14
  19. package/lib/codegen/cli.js.map +1 -1
  20. package/lib/codegen/datafy.d.ts +14 -0
  21. package/lib/codegen/datafy.d.ts.map +1 -0
  22. package/lib/codegen/datafy.js +853 -0
  23. package/lib/codegen/datafy.js.map +1 -0
  24. package/lib/codegen/dedupe.d.ts +5 -0
  25. package/lib/codegen/dedupe.d.ts.map +1 -0
  26. package/lib/codegen/dedupe.js +153 -0
  27. package/lib/codegen/dedupe.js.map +1 -0
  28. package/lib/codegen/emit.js +56 -56
  29. package/lib/codegen/format.js +18 -18
  30. package/lib/codegen/generated-at.js +29 -29
  31. package/lib/codegen/generator.d.ts.map +1 -1
  32. package/lib/codegen/generator.js +92 -84
  33. package/lib/codegen/generator.js.map +1 -1
  34. package/lib/codegen/graph.js +36 -36
  35. package/lib/codegen/graphql-client.d.ts +2 -0
  36. package/lib/codegen/graphql-client.d.ts.map +1 -1
  37. package/lib/codegen/graphql-client.js +55 -26
  38. package/lib/codegen/graphql-client.js.map +1 -1
  39. package/lib/codegen/graphql.js +113 -113
  40. package/lib/codegen/latin1.d.ts +3 -0
  41. package/lib/codegen/latin1.d.ts.map +1 -0
  42. package/lib/codegen/latin1.js +126 -0
  43. package/lib/codegen/latin1.js.map +1 -0
  44. package/lib/codegen/members.d.ts +7 -0
  45. package/lib/codegen/members.d.ts.map +1 -1
  46. package/lib/codegen/members.js +26 -19
  47. package/lib/codegen/members.js.map +1 -1
  48. package/lib/codegen/model-diff.js +6 -6
  49. package/lib/codegen/naming.js +19 -19
  50. package/lib/codegen/openapi-cli.js +15 -15
  51. package/lib/codegen/openapi.d.ts +17 -0
  52. package/lib/codegen/openapi.d.ts.map +1 -1
  53. package/lib/codegen/openapi.js +323 -169
  54. package/lib/codegen/openapi.js.map +1 -1
  55. package/lib/codegen/operations.js +14 -14
  56. package/lib/codegen/pagination.js +11 -11
  57. package/lib/codegen/patch-audit.js +57 -57
  58. package/lib/codegen/patches.js +79 -79
  59. package/lib/codegen/prelude.js +19 -19
  60. package/lib/codegen/privatize.d.ts +21 -0
  61. package/lib/codegen/privatize.d.ts.map +1 -0
  62. package/lib/codegen/privatize.js +176 -0
  63. package/lib/codegen/privatize.js.map +1 -0
  64. package/lib/codegen/proto.js +25 -25
  65. package/lib/codegen/pure.d.ts +6 -0
  66. package/lib/codegen/pure.d.ts.map +1 -0
  67. package/lib/codegen/pure.js +91 -0
  68. package/lib/codegen/pure.js.map +1 -0
  69. package/lib/codegen/rewrite-operation-ids.js +108 -108
  70. package/lib/codegen/spec-path.js +57 -57
  71. package/lib/codegen/table.d.ts +5 -0
  72. package/lib/codegen/table.d.ts.map +1 -0
  73. package/lib/codegen/table.js +249 -0
  74. package/lib/codegen/table.js.map +1 -0
  75. package/lib/config.d.ts +27 -0
  76. package/lib/config.d.ts.map +1 -0
  77. package/lib/config.js +161 -0
  78. package/lib/config.js.map +1 -0
  79. package/lib/crypto.d.ts +76 -0
  80. package/lib/crypto.d.ts.map +1 -0
  81. package/lib/crypto.js +130 -0
  82. package/lib/crypto.js.map +1 -0
  83. package/lib/debug.d.ts +2 -0
  84. package/lib/debug.d.ts.map +1 -0
  85. package/lib/debug.js +8 -0
  86. package/lib/debug.js.map +1 -0
  87. package/lib/error-category.d.ts +1 -1
  88. package/lib/error-category.d.ts.map +1 -1
  89. package/lib/error-category.js +7 -6
  90. package/lib/error-category.js.map +1 -1
  91. package/lib/errors.d.ts +62 -62
  92. package/lib/errors.d.ts.map +1 -1
  93. package/lib/errors.js +117 -114
  94. package/lib/errors.js.map +1 -1
  95. package/lib/graphql.d.ts +31 -20
  96. package/lib/graphql.d.ts.map +1 -1
  97. package/lib/graphql.js +150 -119
  98. package/lib/graphql.js.map +1 -1
  99. package/lib/graphql.types.js +4 -3
  100. package/lib/graphql.types.js.map +1 -1
  101. package/lib/index.d.ts +3 -2
  102. package/lib/index.d.ts.map +1 -1
  103. package/lib/index.js +15 -14
  104. package/lib/index.js.map +1 -1
  105. package/lib/json-patch.d.ts +2 -2
  106. package/lib/json-patch.js +28 -28
  107. package/lib/pagination.d.ts +9 -25
  108. package/lib/pagination.d.ts.map +1 -1
  109. package/lib/pagination.js +95 -90
  110. package/lib/pagination.js.map +1 -1
  111. package/lib/plain-values.d.ts +10 -0
  112. package/lib/plain-values.d.ts.map +1 -0
  113. package/lib/plain-values.js +40 -0
  114. package/lib/plain-values.js.map +1 -0
  115. package/lib/protocol-http.d.ts +50 -14
  116. package/lib/protocol-http.d.ts.map +1 -1
  117. package/lib/protocol-http.js +351 -178
  118. package/lib/protocol-http.js.map +1 -1
  119. package/lib/protocol-rest.d.ts +38 -25
  120. package/lib/protocol-rest.d.ts.map +1 -1
  121. package/lib/protocol-rest.js +238 -130
  122. package/lib/protocol-rest.js.map +1 -1
  123. package/lib/query.js +16 -16
  124. package/lib/response-validation-strict.d.ts +48 -0
  125. package/lib/response-validation-strict.d.ts.map +1 -0
  126. package/lib/response-validation-strict.js +284 -0
  127. package/lib/response-validation-strict.js.map +1 -0
  128. package/lib/response-validation.d.ts +43 -25
  129. package/lib/response-validation.d.ts.map +1 -1
  130. package/lib/response-validation.js +112 -70
  131. package/lib/response-validation.js.map +1 -1
  132. package/lib/retry-after.d.ts +3 -3
  133. package/lib/retry-after.js +49 -49
  134. package/lib/retry.d.ts +48 -29
  135. package/lib/retry.d.ts.map +1 -1
  136. package/lib/retry.js +142 -154
  137. package/lib/retry.js.map +1 -1
  138. package/lib/schema-lite-impl.d.ts +158 -0
  139. package/lib/schema-lite-impl.d.ts.map +1 -0
  140. package/lib/schema-lite-impl.js +341 -0
  141. package/lib/schema-lite-impl.js.map +1 -0
  142. package/lib/schema-lite-typed.d.ts +41 -0
  143. package/lib/schema-lite-typed.d.ts.map +1 -0
  144. package/lib/schema-lite-typed.js +27 -0
  145. package/lib/schema-lite-typed.js.map +1 -0
  146. package/lib/schema-lite.d.ts +40 -0
  147. package/lib/schema-lite.d.ts.map +1 -0
  148. package/lib/schema-lite.js +31 -0
  149. package/lib/schema-lite.js.map +1 -0
  150. package/lib/schema.d.ts +20 -6
  151. package/lib/schema.d.ts.map +1 -1
  152. package/lib/schema.js +202 -30
  153. package/lib/schema.js.map +1 -1
  154. package/lib/testing.d.ts +3 -2
  155. package/lib/testing.d.ts.map +1 -1
  156. package/lib/testing.js +22 -21
  157. package/lib/testing.js.map +1 -1
  158. package/lib/trait.d.ts +13 -13
  159. package/lib/trait.d.ts.map +1 -1
  160. package/lib/trait.js +80 -80
  161. package/lib/trait.js.map +1 -1
  162. package/lib/xml.d.ts +1 -1
  163. package/lib/xml.d.ts.map +1 -1
  164. package/lib/xml.js +38 -26
  165. package/lib/xml.js.map +1 -1
  166. package/package.json +9 -7
  167. package/src/api.ts +1079 -180
  168. package/src/category.ts +33 -33
  169. package/src/chunks.ts +30 -0
  170. package/src/codegen/chunk.ts +147 -0
  171. package/src/codegen/cli.ts +27 -1
  172. package/src/codegen/datafy.ts +874 -0
  173. package/src/codegen/dedupe.ts +173 -0
  174. package/src/codegen/generator.ts +10 -3
  175. package/src/codegen/graphql-client.ts +49 -15
  176. package/src/codegen/latin1.ts +131 -0
  177. package/src/codegen/members.ts +8 -0
  178. package/src/codegen/openapi.ts +194 -3
  179. package/src/codegen/privatize.ts +200 -0
  180. package/src/codegen/pure.ts +94 -0
  181. package/src/codegen/table.ts +254 -0
  182. package/src/config.ts +216 -0
  183. package/src/crypto.ts +202 -0
  184. package/src/debug.ts +8 -0
  185. package/src/error-category.ts +2 -1
  186. package/src/errors.ts +65 -56
  187. package/src/graphql.ts +109 -62
  188. package/src/graphql.types.ts +9 -7
  189. package/src/index.ts +3 -2
  190. package/src/json-patch.ts +2 -2
  191. package/src/pagination.ts +37 -18
  192. package/src/plain-values.ts +41 -0
  193. package/src/protocol-http.ts +378 -145
  194. package/src/protocol-rest.ts +337 -169
  195. package/src/response-validation-strict.ts +327 -0
  196. package/src/response-validation.ts +101 -50
  197. package/src/retry-after.ts +3 -3
  198. package/src/retry.ts +94 -93
  199. package/src/schema-lite-impl.ts +550 -0
  200. package/src/schema-lite-typed.ts +44 -0
  201. package/src/schema-lite.ts +44 -0
  202. package/src/schema.ts +258 -14
  203. package/src/testing.ts +4 -2
  204. package/src/trait.ts +36 -28
  205. package/src/xml.ts +31 -17
  206. package/lib/codegen/boolean-string-enums.test.d.ts +0 -2
  207. package/lib/codegen/boolean-string-enums.test.d.ts.map +0 -1
  208. package/lib/codegen/boolean-string-enums.test.js +0 -275
  209. package/lib/codegen/boolean-string-enums.test.js.map +0 -1
  210. package/lib/codegen/defer-naming.test.d.ts +0 -2
  211. package/lib/codegen/defer-naming.test.d.ts.map +0 -1
  212. package/lib/codegen/defer-naming.test.js +0 -105
  213. package/lib/codegen/defer-naming.test.js.map +0 -1
  214. package/lib/codegen/generated-at.test.d.ts +0 -2
  215. package/lib/codegen/generated-at.test.d.ts.map +0 -1
  216. package/lib/codegen/generated-at.test.js +0 -81
  217. package/lib/codegen/generated-at.test.js.map +0 -1
  218. package/lib/codegen/generator.test.d.ts +0 -2
  219. package/lib/codegen/generator.test.d.ts.map +0 -1
  220. package/lib/codegen/generator.test.js +0 -121
  221. package/lib/codegen/generator.test.js.map +0 -1
  222. package/lib/codegen/graphql-client.test.d.ts +0 -2
  223. package/lib/codegen/graphql-client.test.d.ts.map +0 -1
  224. package/lib/codegen/graphql-client.test.js +0 -171
  225. package/lib/codegen/graphql-client.test.js.map +0 -1
  226. package/lib/codegen/openapi-binary.test.d.ts +0 -2
  227. package/lib/codegen/openapi-binary.test.d.ts.map +0 -1
  228. package/lib/codegen/openapi-binary.test.js +0 -67
  229. package/lib/codegen/openapi-binary.test.js.map +0 -1
  230. package/lib/codegen/patch-audit.test.d.ts +0 -2
  231. package/lib/codegen/patch-audit.test.d.ts.map +0 -1
  232. package/lib/codegen/patch-audit.test.js +0 -141
  233. package/lib/codegen/patch-audit.test.js.map +0 -1
  234. package/lib/codegen/patches.test.d.ts +0 -2
  235. package/lib/codegen/patches.test.d.ts.map +0 -1
  236. package/lib/codegen/patches.test.js +0 -155
  237. package/lib/codegen/patches.test.js.map +0 -1
  238. package/lib/codegen/protocol-imports.test.d.ts +0 -2
  239. package/lib/codegen/protocol-imports.test.d.ts.map +0 -1
  240. package/lib/codegen/protocol-imports.test.js +0 -36
  241. package/lib/codegen/protocol-imports.test.js.map +0 -1
  242. package/lib/codegen/rewrite-operation-ids.test.d.ts +0 -2
  243. package/lib/codegen/rewrite-operation-ids.test.d.ts.map +0 -1
  244. package/lib/codegen/rewrite-operation-ids.test.js +0 -451
  245. package/lib/codegen/rewrite-operation-ids.test.js.map +0 -1
  246. package/lib/codegen/untagged-unions.test.d.ts +0 -2
  247. package/lib/codegen/untagged-unions.test.d.ts.map +0 -1
  248. package/lib/codegen/untagged-unions.test.js +0 -80
  249. package/lib/codegen/untagged-unions.test.js.map +0 -1
  250. package/lib/fixtures/xml/upstream-validator.json +0 -397
  251. package/lib/graphql.test.d.ts +0 -2
  252. package/lib/graphql.test.d.ts.map +0 -1
  253. package/lib/graphql.test.js +0 -151
  254. package/lib/graphql.test.js.map +0 -1
  255. package/lib/json-patch.test.d.ts +0 -2
  256. package/lib/json-patch.test.d.ts.map +0 -1
  257. package/lib/json-patch.test.js +0 -65
  258. package/lib/json-patch.test.js.map +0 -1
  259. package/lib/pagination.test.d.ts +0 -2
  260. package/lib/pagination.test.d.ts.map +0 -1
  261. package/lib/pagination.test.js +0 -131
  262. package/lib/pagination.test.js.map +0 -1
  263. package/lib/protocol-http.test.d.ts +0 -2
  264. package/lib/protocol-http.test.d.ts.map +0 -1
  265. package/lib/protocol-http.test.js +0 -228
  266. package/lib/protocol-http.test.js.map +0 -1
  267. package/lib/protocol-rest.test.d.ts +0 -2
  268. package/lib/protocol-rest.test.d.ts.map +0 -1
  269. package/lib/protocol-rest.test.js +0 -498
  270. package/lib/protocol-rest.test.js.map +0 -1
  271. package/lib/response-validation.test.d.ts +0 -2
  272. package/lib/response-validation.test.d.ts.map +0 -1
  273. package/lib/response-validation.test.js +0 -72
  274. package/lib/response-validation.test.js.map +0 -1
  275. package/lib/retry-after.test.d.ts +0 -2
  276. package/lib/retry-after.test.d.ts.map +0 -1
  277. package/lib/retry-after.test.js +0 -204
  278. package/lib/retry-after.test.js.map +0 -1
  279. package/lib/retry.test.d.ts +0 -2
  280. package/lib/retry.test.d.ts.map +0 -1
  281. package/lib/retry.test.js +0 -407
  282. package/lib/retry.test.js.map +0 -1
  283. package/lib/sdks.test.d.ts +0 -2
  284. package/lib/sdks.test.d.ts.map +0 -1
  285. package/lib/sdks.test.js +0 -76
  286. package/lib/sdks.test.js.map +0 -1
  287. package/lib/xml.test.d.ts +0 -2
  288. package/lib/xml.test.d.ts.map +0 -1
  289. package/lib/xml.test.js +0 -210
  290. package/lib/xml.test.js.map +0 -1
  291. package/src/codegen/boolean-string-enums.test.ts +0 -299
  292. package/src/codegen/defer-naming.test.ts +0 -113
  293. package/src/codegen/generated-at.test.ts +0 -89
  294. package/src/codegen/generator.test.ts +0 -137
  295. package/src/codegen/graphql-client.test.ts +0 -189
  296. package/src/codegen/openapi-binary.test.ts +0 -91
  297. package/src/codegen/patch-audit.test.ts +0 -160
  298. package/src/codegen/patches.test.ts +0 -188
  299. package/src/codegen/protocol-imports.test.ts +0 -39
  300. package/src/codegen/rewrite-operation-ids.test.ts +0 -472
  301. package/src/codegen/untagged-unions.test.ts +0 -85
  302. package/src/fixtures/xml/upstream-validator.json +0 -397
  303. package/src/graphql.test.ts +0 -198
  304. package/src/json-patch.test.ts +0 -77
  305. package/src/pagination.test.ts +0 -169
  306. package/src/protocol-http.test.ts +0 -276
  307. package/src/protocol-rest.test.ts +0 -703
  308. package/src/response-validation.test.ts +0 -89
  309. package/src/retry-after.test.ts +0 -267
  310. package/src/retry.test.ts +0 -566
  311. package/src/sdks.test.ts +0 -87
  312. package/src/xml.test.ts +0 -251
@@ -1,5 +1,8 @@
1
+ import * as Headers from "effect/http/Headers";
1
2
  import * as HttpBody from "effect/http/HttpBody";
2
3
  import * as HttpClientRequest from "effect/http/HttpClientRequest";
4
+ import { debugHttp } from "./debug.js";
5
+ import { isOpaqueValue } from "./plain-values.js";
3
6
  import { bodySymbol, deepQuerySymbol, formDataFileSymbol, getErrorMatchers, headerSymbol, httpBodySymbol, httpSymbol, keyDictionarySymbol, labelSymbol, labelEncodingSymbol, querySymbol, stringEncodedSymbol, unionCasesSymbol, } from "./trait.js";
4
7
  //#region AST helpers (survive S.optional / Suspend / transforms)
5
8
  export const getProps = (ast) => {
@@ -19,7 +22,7 @@ export const getAnn = (ast, symbol) => {
19
22
  return getAnn(ast.thunk(), symbol);
20
23
  if (ast.encoding && ast.encoding.length > 0)
21
24
  return getAnn(ast.encoding[0].to, symbol);
22
- // S.optional → Union[self, Undefined]; descend into the single real member.
25
+ // S.optional -> Union[self, Undefined]; descend into the single real member.
23
26
  if (ast._tag === "Union") {
24
27
  const real = ast.types.filter((t) => t._tag !== "Undefined" && !(t._tag === "Literal" && t.literal === null));
25
28
  if (real.length === 1)
@@ -33,7 +36,7 @@ export const nameOf = (prop, symbol) => {
33
36
  const v = getPropAnn(prop, symbol);
34
37
  return typeof v === "string" ? v : String(prop.name);
35
38
  };
36
- /** Resolve wrappers to the real node: Suspend, encoding, optional/null unions. */
39
+
37
40
  export const resolveNode = (ast) => {
38
41
  if (ast._tag === "Suspend")
39
42
  return resolveNode(ast.thunk());
@@ -48,19 +51,56 @@ export const resolveNode = (ast) => {
48
51
  }
49
52
  return ast;
50
53
  };
54
+ const noHeaderMembers = [];
55
+ const headerMemberCache = /*@__PURE__*/ new WeakMap();
56
+
57
+ export const responseHeaderMembers = (outputAst) => {
58
+ let members = headerMemberCache.get(outputAst);
59
+ if (members !== undefined)
60
+ return members;
61
+ const found = [];
62
+ for (const prop of getProps(outputAst)) {
63
+ if (!hasPropAnn(prop, headerSymbol))
64
+ continue;
65
+ found.push({
66
+ key: String(prop.name),
67
+ wire: nameOf(prop, headerSymbol).toLowerCase(),
68
+ number: resolveNode(prop.type)._tag === "Number",
69
+ });
70
+ }
71
+ members = found.length === 0 ? noHeaderMembers : found;
72
+ headerMemberCache.set(outputAst, members);
73
+ return members;
74
+ };
75
+
76
+
77
+
78
+
79
+
80
+
81
+ export const withResponseHeaders = (members, body, headers) => {
82
+ if (members.length === 0 || body === null || typeof body !== "object" || Array.isArray(body)) {
83
+ return body;
84
+ }
85
+ let result;
86
+ for (const m of members) {
87
+ const raw = headers[m.wire];
88
+ if (raw === undefined)
89
+ continue;
90
+ result ??= { ...body };
91
+ const parsed = m.number && raw.trim() !== "" ? Number(raw) : Number.NaN;
92
+ result[m.key] = Number.isNaN(parsed) ? raw : parsed;
93
+ }
94
+ return result ?? body;
95
+ };
51
96
  //#endregion
52
97
  //#region Recursive wire-name mapping
53
- /** Binary/opaque values that must never be treated as key-value objects. */
54
- export const isOpaqueValue = (v) => v instanceof Blob ||
55
- v instanceof File ||
56
- v instanceof ArrayBuffer ||
57
- v instanceof Uint8Array ||
58
- v instanceof Date;
59
- /**
60
- * Deep-rename keys via a plain dictionary (see `T.KeyDictionary`). An entry
61
- * may list several wire spellings; encode uses the first (canonical) one and
62
- * decode maps every listed spelling back to the TS name.
63
- */
98
+ export { isOpaqueValue };
99
+
100
+
101
+
102
+
103
+
64
104
  export const mapKeysByDictionary = (dict, value, direction) => {
65
105
  if (value === null || typeof value !== "object" || isOpaqueValue(value)) {
66
106
  return value;
@@ -82,21 +122,78 @@ export const mapKeysByDictionary = (dict, value, direction) => {
82
122
  }
83
123
  return out;
84
124
  };
85
- /**
86
- * Recursively rename keys between TS names and wire names, per the schema.
87
- *
88
- * `fallback` is the nearest ancestor `T.KeyDictionary` — schema-known members
89
- * always map via their own annotations, but opaque values (Document members,
90
- * keys the schema doesn't know) deep-rename via the dictionary so nested
91
- * TS-cased content still reaches the wire in wire case. Content with no
92
- * dictionary in scope passes through verbatim.
93
- */
94
- /**
95
- * Value form for a `StringEncoded()` member: the string spelling of the
96
- * value, element-wise for lists. `null` stays `null` — an API that models a
97
- * flag as `"true" | "false"` still means "unset" by null, not `"null"`.
98
- */
125
+
126
+
127
+
128
+
129
+
130
+
131
+
132
+
133
+
134
+
135
+
136
+
137
+
138
+
99
139
  const stringEncode = (value) => value === null ? null : Array.isArray(value) ? value.map(stringEncode) : String(value);
140
+
141
+
142
+
143
+
144
+
145
+
146
+
147
+ export const mapsVerbatim = (root, direction) => {
148
+ const cache = direction === "encode" ? verbatimEncode : verbatimDecode;
149
+ let result = cache.get(root);
150
+ if (result !== undefined)
151
+ return result;
152
+ result = true;
153
+ const seen = new Set();
154
+ const stack = [root];
155
+ walk: while (stack.length > 0) {
156
+ const ast = stack.pop();
157
+ if (seen.has(ast))
158
+ continue;
159
+ seen.add(ast);
160
+ if (getAnn(ast, keyDictionarySymbol) !== undefined) {
161
+ result = false;
162
+ break;
163
+ }
164
+ if (direction === "decode" && getAnn(ast, unionCasesSymbol) !== undefined) {
165
+ result = false;
166
+ break;
167
+ }
168
+ const node = resolveNode(ast);
169
+ if (node._tag === "Union") {
170
+ for (const t of node.types)
171
+ stack.push(resolveNode(t));
172
+ }
173
+ else if (node._tag === "Arrays") {
174
+ const elem = node.rest?.[0];
175
+ if (elem)
176
+ stack.push(elem);
177
+ }
178
+ else if (node._tag === "Objects") {
179
+ for (const p of node.propertySignatures) {
180
+ if (nameOf(p, bodySymbol) !== String(p.name) ||
181
+ (direction === "encode" && hasPropAnn(p, stringEncodedSymbol))) {
182
+ result = false;
183
+ break walk;
184
+ }
185
+ stack.push(p.type);
186
+ }
187
+ for (const s of (node.indexSignatures ?? [])) {
188
+ stack.push(s.type);
189
+ }
190
+ }
191
+ }
192
+ cache.set(root, result);
193
+ return result;
194
+ };
195
+ const verbatimEncode = /*@__PURE__*/ new WeakMap();
196
+ const verbatimDecode = /*@__PURE__*/ new WeakMap();
100
197
  export const mapKeys = (ast, value, direction, fallback) => {
101
198
  if (value === null || value === undefined || typeof value !== "object" || isOpaqueValue(value)) {
102
199
  return value;
@@ -105,10 +202,10 @@ export const mapKeys = (ast, value, direction, fallback) => {
105
202
  // Discriminated union whose cases the API returns merged (every case's
106
203
  // keys present, `null` for the inactive ones). Map wire names, then keep
107
204
  // only the active case's keys. The case is read off the union's
108
- // discriminator when it has one — cases that share a key set (every
205
+ // discriminator when it has one -- cases that share a key set (every
109
206
  // resource kind of `resource_tagging`, every page-rule action) are
110
207
  // indistinguishable by keys alone. Without one, a case does NOT need every
111
- // key present — arms carry optional members the wire may omit — so the
208
+ // key present -- arms carry optional members the wire may omit -- so the
112
209
  // active case is the one that best EXPLAINS the value: most present,
113
210
  // non-null keys covered, minus present keys the case cannot explain (ties
114
211
  // break by coverage, then declaration order).
@@ -151,12 +248,12 @@ export const mapKeys = (ast, value, direction, fallback) => {
151
248
  }
152
249
  const node = resolveNode(ast);
153
250
  // Schema-level union member (a merged response struct whose arms disagree
154
- // on a member's type — see the codegen's response-union merge): pick the
251
+ // on a member's type -- see the codegen's response-union merge): pick the
155
252
  // arm that explains the value best and map with it. Object values score
156
253
  // arms by how many of their declared keys are present; array values take
157
254
  // the first array arm. Anything unmatched deep-renames via the dictionary
158
- // fallback, like other opaque content. (Single-real-member unions —
159
- // optional/null wrappers — were already collapsed by resolveNode; the
255
+ // fallback, like other opaque content. (Single-real-member unions --
256
+ // optional/null wrappers -- were already collapsed by resolveNode; the
160
257
  // opaque `T.UnionCases` mechanism never produces a Union node and is
161
258
  // handled above.)
162
259
  if (node._tag === "Union") {
@@ -202,7 +299,7 @@ export const mapKeys = (ast, value, direction, fallback) => {
202
299
  const props = node.propertySignatures;
203
300
  const isigs = node.indexSignatures;
204
301
  if (props.length === 0 && !(isigs && isigs.length)) {
205
- // opaque object — dictionary fallback or verbatim
302
+ // opaque object -- dictionary fallback or verbatim
206
303
  return dict ? mapKeysByDictionary(dict, value, direction) : value;
207
304
  }
208
305
  const out = {};
@@ -217,7 +314,7 @@ export const mapKeys = (ast, value, direction, fallback) => {
217
314
  if (v === undefined)
218
315
  continue;
219
316
  // A `StringEncoded()` member nested in a body struct (e.g. Azure's
220
- // `hardwareProfile.dynamicMemoryEnabled`) stringifies here — the
317
+ // `hardwareProfile.dynamicMemoryEnabled`) stringifies here -- the
221
318
  // top-level pass in `buildRequest` only sees the outermost member.
222
319
  out[to] =
223
320
  direction === "encode" && hasPropAnn(p, stringEncodedSymbol)
@@ -241,23 +338,23 @@ export const mapKeys = (ast, value, direction, fallback) => {
241
338
  }
242
339
  return out;
243
340
  }
244
- // Scalar-typed schema node holding object content (spec drift) —
341
+ // Scalar-typed schema node holding object content (spec drift) --
245
342
  // dictionary fallback or verbatim.
246
343
  return dict ? mapKeysByDictionary(dict, value, direction) : value;
247
344
  };
248
345
  //#endregion
249
346
  //#region Request building
250
- const BODYLESS = new Set(["GET", "HEAD"]);
251
- /**
252
- * Serialize one query member. Scalars go as `k=v`, arrays as repeated `k=v`
253
- * pairs, and nested plain objects recurse as DOTTED params — several list
254
- * endpoints model their filters as structs (e.g. Cloudflare DNS listRecords
255
- * takes `name: { exact, contains, ... }`) that must go over the wire as
256
- * `name.exact=value`. Without this they fell through to `String(value)` and
257
- * were sent as `name=[object Object]`, which servers happily treat as a
258
- * filter matching nothing — the call "succeeds" with zero results and the
259
- * bug is invisible to the caller.
260
- */
347
+ const BODYLESS = /*@__PURE__*/ new Set(["GET", "HEAD"]);
348
+
349
+
350
+
351
+
352
+
353
+
354
+
355
+
356
+
357
+
261
358
  const appendQuery = (query, name, value) => {
262
359
  if (Array.isArray(value)) {
263
360
  for (const v of value)
@@ -273,30 +370,18 @@ const appendQuery = (query, name, value) => {
273
370
  query.append(name, String(value));
274
371
  }
275
372
  };
276
- /**
277
- * Build an HTTP request from an operation input and its schema, driven by
278
- * the trait annotations: `Http()` supplies method + URI template, `Label()`
279
- * members fill URI placeholders, `Header()`/`Query()` members bind to
280
- * headers/query params, `DeepQuery()` struct members expand into dotted
281
- * query params, `HttpBody()` sends the member as the whole body,
282
- * `FormDataFile()` members become multipart file parts, and everything else
283
- * is a JSON body field (wire-named via `Body()` / `KeyDictionary`).
284
- *
285
- * Throws when the input schema is missing the `Http()` trait — a codegen
286
- * bug, surfaced as a defect by the calling protocol's Effect context.
287
- */
288
- /**
289
- * Encode a greedy `{name+}` label: the value may span several path
290
- * segments (e.g. an Azure scope `/subscriptions/{id}/resourceGroups/{rg}`),
291
- * so each segment is encoded on its own and the `/` separators are kept.
292
- * Leading slashes are dropped because the URI template already supplies one.
293
- */
373
+
374
+
375
+
376
+
377
+
378
+
294
379
  export const encodeGreedyLabel = (value) => value.replace(/^\/+/, "").split("/").map(encodeURIComponent).join("/");
295
- /**
296
- * Flatten a nested object into Stripe-style bracket notation pairs for
297
- * form-urlencoded bodies: nested objects become `a[b][c]`, arrays index as
298
- * `a[0]`; null/undefined dropped, booleans as "true"/"false".
299
- */
380
+
381
+
382
+
383
+
384
+
300
385
  const flattenToFormPairs = (obj, prefix = "") => {
301
386
  const pairs = [];
302
387
  for (const [key, value] of Object.entries(obj)) {
@@ -325,114 +410,204 @@ const flattenToFormPairs = (obj, prefix = "") => {
325
410
  }
326
411
  return pairs;
327
412
  };
328
- export const buildRequest = ({ input, inputAst, baseUrl, headers: baseHeaders, mapMemberHeader, unknownKeyToWire, }) => {
329
- const inputObj = (input ?? {});
413
+ const plans = /*@__PURE__*/ new WeakMap();
414
+ const planFor = (inputAst) => {
415
+ let plan = plans.get(inputAst);
416
+ if (plan !== undefined)
417
+ return plan;
330
418
  const http = getAnn(inputAst, httpSymbol);
331
419
  if (!http) {
332
420
  throw new Error("operation input is missing the Http() trait");
333
421
  }
334
- // Root key dictionary: fallback wire mapping for opaque/unknown content
335
- // the schema doesn't model.
336
422
  const rootDict = getAnn(inputAst, keyDictionarySymbol);
337
- const headers = { ...baseHeaders };
338
- const body = {};
339
- let rawBody; // whole-body member (T.HttpBody) — sent as-is
340
- const files = [];
341
- const query = new URLSearchParams();
342
- let uri = http.uri;
343
- const consumed = new Set();
423
+ const members = [];
424
+ const known = new Set();
344
425
  let hasBodyMembers = false;
345
- // Value of a modeled `Content-Type` header member, e.g. R2 putObject's
346
- // `contentType`. A raw body is sent under it (see below).
347
- let memberContentType;
348
426
  for (const prop of getProps(inputAst)) {
349
427
  const key = String(prop.name);
350
- consumed.add(key);
351
- const value = inputObj[key];
352
- const isBodyMember = !hasPropAnn(prop, labelSymbol) &&
353
- !hasPropAnn(prop, headerSymbol) &&
354
- !hasPropAnn(prop, querySymbol) &&
355
- !hasPropAnn(prop, deepQuerySymbol);
356
- if (isBodyMember)
357
- hasBodyMembers = true;
358
- if (value === undefined)
359
- continue;
428
+ known.add(key);
429
+ let bind;
430
+ let name;
431
+ let greedy = false;
360
432
  if (hasPropAnn(prop, labelSymbol)) {
361
- const token = nameOf(prop, labelSymbol);
362
- const preserve = getPropAnn(prop, labelEncodingSymbol);
363
- const encoded = encodeURIComponent(String(value));
364
- const label = typeof preserve === "string"
365
- ? encoded.replace(/%[0-9A-F]{2}/g, (escape) => {
366
- const character = String.fromCharCode(Number.parseInt(escape.slice(1), 16));
367
- return preserve.includes(character) ? character : escape;
368
- })
369
- : encoded;
370
- uri = uri.includes(`{${token}+}`)
371
- ? uri.replace(`{${token}+}`, () => encodeGreedyLabel(String(value)))
372
- : uri.replace(`{${token}}`, () => label);
433
+ bind = "label";
434
+ name = nameOf(prop, labelSymbol);
435
+ greedy = http.uri.includes(`{${name}+}`);
373
436
  }
374
437
  else if (hasPropAnn(prop, headerSymbol)) {
375
- const hName = nameOf(prop, headerSymbol).toLowerCase();
376
- const hVal = String(value);
377
- headers[hName] = mapMemberHeader ? mapMemberHeader(hName, hVal) : hVal;
378
- if (hName === "content-type")
379
- memberContentType = headers[hName];
438
+ bind = "header";
439
+ name = nameOf(prop, headerSymbol).toLowerCase();
380
440
  }
381
441
  else if (hasPropAnn(prop, querySymbol)) {
382
- appendQuery(query, nameOf(prop, querySymbol), value);
442
+ bind = "query";
443
+ name = nameOf(prop, querySymbol);
383
444
  }
384
445
  else if (hasPropAnn(prop, deepQuerySymbol)) {
385
- // Deep-object query member (T.DeepQuery): a nested struct expands into
386
- // dotted query keys (`account.id=…`) under the member's wire name.
387
- // Wire-name the nested content via the schema first, skip null/
388
- // undefined entries; deeper nesting recurses through appendQuery.
389
- const base = nameOf(prop, deepQuerySymbol);
390
- const mapped = mapKeys(prop.type, value, "encode", rootDict);
391
- if (mapped !== null && typeof mapped === "object") {
392
- for (const [k, v] of Object.entries(mapped)) {
393
- if (v !== undefined && v !== null) {
394
- appendQuery(query, `${base}.${k}`, v);
395
- }
446
+ bind = "deepQuery";
447
+ name = nameOf(prop, deepQuerySymbol);
448
+ }
449
+ else {
450
+ hasBodyMembers = true;
451
+ bind = hasPropAnn(prop, formDataFileSymbol)
452
+ ? "file"
453
+ : hasPropAnn(prop, httpBodySymbol)
454
+ ? "httpBody"
455
+ : "body";
456
+ name = nameOf(prop, bodySymbol);
457
+ }
458
+ const preserve = getPropAnn(prop, labelEncodingSymbol);
459
+ members.push({
460
+ key,
461
+ bind,
462
+ name,
463
+ type: prop.type,
464
+ preserve: typeof preserve === "string" ? preserve : undefined,
465
+ greedy,
466
+ stringEncoded: hasPropAnn(prop, stringEncodedSymbol),
467
+ verbatim: rootDict === undefined && mapsVerbatim(prop.type, "encode"),
468
+ });
469
+ }
470
+ plan = { http, rootDict, members, known, hasBodyMembers };
471
+ plans.set(inputAst, plan);
472
+ return plan;
473
+ };
474
+ const emptyRequest = /*@__PURE__*/ HttpClientRequest.get("");
475
+
476
+
477
+
478
+
479
+
480
+ export const makeRequest = (method, url, headers) => HttpClientRequest.makeWith(method, url, emptyRequest.urlParams, emptyRequest.hash, Headers.fromInput(headers), HttpBody.empty);
481
+
482
+
483
+
484
+
485
+
486
+
487
+
488
+
489
+
490
+
491
+
492
+
493
+
494
+
495
+
496
+
497
+
498
+ export const buildRequest = ({ input, inputAst, baseUrl, headers: baseHeaders, mapMemberHeader, unknownKeyToWire, }) => {
499
+ const inputObj = (input ?? {});
500
+ const plan = planFor(inputAst);
501
+ const { http, rootDict, members, known } = plan;
502
+ let hasBodyMembers = plan.hasBodyMembers;
503
+ const headers = { ...baseHeaders };
504
+ const body = {};
505
+ let bodyKeys = 0;
506
+ let rawBody; // whole-body member (T.HttpBody) -- sent as-is
507
+ let files;
508
+ let query;
509
+ let uri = http.uri;
510
+ // Value of a modeled `Content-Type` header member, e.g. R2 putObject's
511
+ // `contentType`. A raw body is sent under it (see below).
512
+ let memberContentType;
513
+ for (let i = 0; i < members.length; i++) {
514
+ const m = members[i];
515
+ const value = inputObj[m.key];
516
+ if (value === undefined)
517
+ continue;
518
+ switch (m.bind) {
519
+ case "label": {
520
+ // The URL parser resolves a `.` or `..` segment, percent-encoded or
521
+ // not, so no encoding can carry one: it would address another path
522
+ // (`/projects/p1/branches/..` -> `/projects/p1/`). A greedy label keeps
523
+ // its `/`, so each of its segments counts.
524
+ if ((m.greedy ? String(value).split("/") : [String(value)]).some((s) => s === "." || s === "..")) {
525
+ throw new Error(`invalid value for input HTTP label: ${m.key}`);
396
526
  }
527
+ const encoded = encodeURIComponent(String(value));
528
+ const preserve = m.preserve;
529
+ const label = preserve !== undefined
530
+ ? encoded.replace(/%[0-9A-F]{2}/g, (escape) => {
531
+ const character = String.fromCharCode(Number.parseInt(escape.slice(1), 16));
532
+ return preserve.includes(character) ? character : escape;
533
+ })
534
+ : encoded;
535
+ uri = m.greedy
536
+ ? uri.replace(`{${m.name}+}`, () => encodeGreedyLabel(String(value)))
537
+ : uri.replace(`{${m.name}}`, () => label);
538
+ break;
397
539
  }
398
- }
399
- else if (hasPropAnn(prop, formDataFileSymbol)) {
400
- for (const f of Array.isArray(value) ? value : [value]) {
401
- files.push(f);
540
+ case "header": {
541
+ const hVal = String(value);
542
+ headers[m.name] = mapMemberHeader ? mapMemberHeader(m.name, hVal) : hVal;
543
+ if (m.name === "content-type")
544
+ memberContentType = headers[m.name];
545
+ break;
402
546
  }
403
- }
404
- else if (hasPropAnn(prop, httpBodySymbol)) {
405
- rawBody = mapKeys(prop.type, value, "encode", rootDict);
406
- }
407
- else {
408
- // T.StringEncoded(): the API takes this member's value only as its
409
- // string spelling (`true` → `"true"`), while the TS surface keeps the
410
- // natural type. Explicit here so a JSON body carries the string too,
411
- // rather than relying on the multipart encoder's own `String()`.
412
- body[nameOf(prop, bodySymbol)] = hasPropAnn(prop, stringEncodedSymbol)
413
- ? stringEncode(value)
414
- : mapKeys(prop.type, value, "encode", rootDict);
547
+ case "query":
548
+ appendQuery((query ??= new URLSearchParams()), m.name, value);
549
+ break;
550
+ case "deepQuery": {
551
+ // Deep-object query member (T.DeepQuery): a nested struct expands into
552
+ // dotted query keys (`account.id=...`) under the member's wire name.
553
+ // Wire-name the nested content via the schema first, skip null/
554
+ // undefined entries; deeper nesting recurses through appendQuery.
555
+ const mapped = m.verbatim ? value : mapKeys(m.type, value, "encode", rootDict);
556
+ if (mapped !== null && typeof mapped === "object") {
557
+ for (const [k, v] of Object.entries(mapped)) {
558
+ if (v !== undefined && v !== null) {
559
+ appendQuery((query ??= new URLSearchParams()), `${m.name}.${k}`, v);
560
+ }
561
+ }
562
+ }
563
+ break;
564
+ }
565
+ case "file":
566
+ files ??= [];
567
+ for (const f of Array.isArray(value) ? value : [value]) {
568
+ files.push(f);
569
+ }
570
+ break;
571
+ case "httpBody":
572
+ rawBody = m.verbatim ? value : mapKeys(m.type, value, "encode", rootDict);
573
+ break;
574
+ default:
575
+ // T.StringEncoded(): the API takes this member's value only as its
576
+ // string spelling (`true` -> `"true"`), while the TS surface keeps the
577
+ // natural type. Explicit here so a JSON body carries the string too,
578
+ // rather than relying on the multipart encoder's own `String()`.
579
+ body[m.name] = m.stringEncoded
580
+ ? stringEncode(value)
581
+ : m.verbatim
582
+ ? value
583
+ : mapKeys(m.type, value, "encode", rootDict);
584
+ bodyKeys++;
415
585
  }
416
586
  }
417
- // Input keys the schema doesn't know pass through as body fields — the
587
+ // Input keys the schema doesn't know pass through as body fields -- the
418
588
  // generated schemas can lag the real API, and silently dropping them
419
589
  // would break working callers. The key dictionary maps them when it knows
420
590
  // the key, otherwise `unknownKeyToWire` decides the wire name.
421
- for (const [key, value] of Object.entries(inputObj)) {
422
- if (consumed.has(key) || value === undefined)
591
+ for (const key in inputObj) {
592
+ if (known.has(key) || !Object.hasOwn(inputObj, key))
593
+ continue;
594
+ const value = inputObj[key];
595
+ if (value === undefined)
423
596
  continue;
424
597
  const wire = rootDict?.[key] ?? (unknownKeyToWire ? unknownKeyToWire(key) : key);
425
598
  body[typeof wire === "string" ? wire : wire[0]] = rootDict
426
599
  ? mapKeysByDictionary(rootDict, value, "encode")
427
600
  : value;
601
+ bodyKeys++;
428
602
  hasBodyMembers = true;
429
603
  }
430
- const qs = query.toString();
431
- const url = `${baseUrl}${uri}${qs ? `?${qs}` : ""}`;
432
- if (process.env.DISTILLED_DEBUG_HTTP) {
604
+ const qs = query === undefined ? "" : query.toString();
605
+ const url = qs ? `${baseUrl}${uri}?${qs}` : `${baseUrl}${uri}`;
606
+ if (debugHttp()) {
433
607
  console.error(`[distilled] -> ${http.method} ${http.uri}`);
434
608
  }
435
- let request = HttpClientRequest.make(http.method)(url).pipe(HttpClientRequest.setHeaders(headers));
609
+ const request = makeRequest(http.method, url, headers);
610
+ const bodied = !BODYLESS.has(http.method);
436
611
  if (http.contentType === "multipart") {
437
612
  // Multipart upload: each body member is a form part (objects
438
613
  // JSON-encoded under their wire name), each file appends under its own
@@ -468,26 +643,26 @@ export const buildRequest = ({ input, inputAst, baseUrl, headers: baseHeaders, m
468
643
  form.append(key, String(value));
469
644
  }
470
645
  }
471
- for (const f of files) {
646
+ for (const f of files ?? []) {
472
647
  const filename = f.name ?? "file";
473
648
  form.append(filename, f, filename);
474
649
  }
475
- request = request.pipe(HttpClientRequest.bodyFormData(form));
650
+ return HttpClientRequest.setBody(request, HttpBody.formData(form));
476
651
  }
477
- else if (http.contentType === "form-urlencoded" && !BODYLESS.has(http.method)) {
652
+ if (http.contentType === "form-urlencoded" && bodied) {
478
653
  // application/x-www-form-urlencoded with Stripe-style deepObject bracket
479
- // notation: { shipping: { address: { city } } } → shipping[address][city],
480
- // arrays indexed ({ expand: ["a"] } → expand[0]=a).
654
+ // notation: { shipping: { address: { city } } } -> shipping[address][city],
655
+ // arrays indexed ({ expand: ["a"] } -> expand[0]=a).
481
656
  const source = rawBody !== undefined && typeof rawBody === "object"
482
657
  ? rawBody
483
658
  : body;
484
659
  const params = new URLSearchParams();
485
660
  for (const [k, v] of flattenToFormPairs(source))
486
661
  params.append(k, v);
487
- request = request.pipe(HttpClientRequest.setBody(HttpBody.text(params.toString(), "application/x-www-form-urlencoded")));
662
+ return HttpClientRequest.setBody(request, HttpBody.text(params.toString(), "application/x-www-form-urlencoded"));
488
663
  }
489
- else if (rawBody !== undefined && !BODYLESS.has(http.method)) {
490
- // Whole-body member (raw arrays/scalars) — sent as the body itself.
664
+ if (rawBody !== undefined && bodied) {
665
+ // Whole-body member (raw arrays/scalars) -- sent as the body itself.
491
666
  // Binary payloads (Blob / ArrayBuffer / Uint8Array) send verbatim
492
667
  // (raw object uploads). With a bodyMediaType, the member is a
493
668
  // preserialized payload (string / bytes) sent verbatim; otherwise it's
@@ -500,35 +675,33 @@ export const buildRequest = ({ input, inputAst, baseUrl, headers: baseHeaders, m
500
675
  const mediaType = memberContentType ?? http.bodyMediaType;
501
676
  if (rawBody instanceof Blob || rawBody instanceof ArrayBuffer) {
502
677
  // With no media type at all, fetch falls back to the Blob's own type.
503
- request = request.pipe(HttpClientRequest.setBody(HttpBody.raw(rawBody, { contentType: mediaType })));
678
+ return HttpClientRequest.setBody(request, HttpBody.raw(rawBody, { contentType: mediaType }));
504
679
  }
505
- else if (rawBody instanceof Uint8Array) {
506
- request = request.pipe(HttpClientRequest.setBody(HttpBody.uint8Array(rawBody, mediaType)));
680
+ if (rawBody instanceof Uint8Array) {
681
+ return HttpClientRequest.setBody(request, HttpBody.uint8Array(rawBody, mediaType));
507
682
  }
508
- else if (http.bodyMediaType) {
509
- request = request.pipe(HttpClientRequest.setBody(typeof rawBody === "string"
683
+ if (http.bodyMediaType) {
684
+ return HttpClientRequest.setBody(request, typeof rawBody === "string"
510
685
  ? HttpBody.text(rawBody, mediaType)
511
- : HttpBody.uint8Array(rawBody, mediaType)));
512
- }
513
- else {
514
- request = request.pipe(HttpClientRequest.bodyJsonUnsafe(rawBody));
686
+ : HttpBody.uint8Array(rawBody, mediaType));
515
687
  }
688
+ return HttpClientRequest.setBody(request, HttpBody.jsonUnsafe(rawBody));
516
689
  }
517
- else if (
690
+ if (
518
691
  // A GET/HEAD sends a body only when body members actually carry values.
519
692
  // Some APIs really do document GET-with-body: MongoDB Atlas's
520
- // `…/lineItems:search` declares a `requestBody` on `get`, and AWS EFS's
693
+ // `.../lineItems:search` declares a `requestBody` on `get`, and AWS EFS's
521
694
  // DescribeAccountPreferences takes `{ MaxResults, NextToken }` on a GET.
522
- // Suppressing it outright dropped those members silently — the request
695
+ // Suppressing it outright dropped those members silently -- the request
523
696
  // succeeded, unfiltered, with nothing on the wire to show why.
524
697
  //
525
698
  // The `{}`-when-empty rule below stays limited to methods that expect a
526
699
  // body, so a bodyless method with nothing set still sends nothing.
527
- Object.keys(body).length > 0 ||
528
- (hasBodyMembers && !BODYLESS.has(http.method) && http.method !== "DELETE")) {
529
- // Send `{}` rather than no body when the schema declares body members —
700
+ bodyKeys > 0 ||
701
+ (hasBodyMembers && bodied && http.method !== "DELETE")) {
702
+ // Send `{}` rather than no body when the schema declares body members --
530
703
  // some endpoints reject a missing JSON body outright.
531
- request = request.pipe(HttpClientRequest.bodyJsonUnsafe(body));
704
+ return HttpClientRequest.setBody(request, HttpBody.jsonUnsafe(body));
532
705
  }
533
706
  return request;
534
707
  };
@@ -565,7 +738,7 @@ const matcherSpecificity = (m) => (m.code !== undefined ? 1 : 0) +
565
738
  (m.message !== undefined ? 1 : 0) +
566
739
  (m.body === undefined ? 0 : Object.keys(m.body).length) +
567
740
  (m.headers === undefined ? 0 : Object.keys(m.headers).length);
568
- /** Every supplied constraint must match; an unconstrained matcher matches nothing. */
741
+
569
742
  export const matchesExpression = (m, code, status, message, response = {}) => {
570
743
  if (m.code === undefined &&
571
744
  m.status === undefined &&
@@ -600,14 +773,14 @@ export const matchesExpression = (m, code, status, message, response = {}) => {
600
773
  }
601
774
  return true;
602
775
  };
603
- /**
604
- * Pick the operation's typed error class for a failed response: among all
605
- * declared classes whose matchers (see `applyErrorMatchers`) match the wire
606
- * failure, the most specific matcher wins (ties break by declaration order).
607
- * Empty error lists use an HTTP-status message so body/header-only failures can
608
- * still match. The constructor receives the raw body and headers as well as
609
- * code/message; error schemas can declare these fields to expose them to callers.
610
- */
776
+
777
+
778
+
779
+
780
+
781
+
782
+
783
+
611
784
  export const matchTypedError = (errorClasses, status, errors, response = {}) => {
612
785
  let best;
613
786
  const wireErrors = errors.length > 0 ? errors : [{ message: `HTTP ${status}` }];