@distilled.cloud/core 0.30.2 → 1.0.0-rc.1

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 (132) hide show
  1. package/lib/api.d.ts +165 -0
  2. package/lib/api.d.ts.map +1 -0
  3. package/lib/api.js +178 -0
  4. package/lib/api.js.map +1 -0
  5. package/lib/codegen/cli.d.ts +29 -0
  6. package/lib/codegen/cli.d.ts.map +1 -0
  7. package/lib/codegen/cli.js +165 -0
  8. package/lib/codegen/cli.js.map +1 -0
  9. package/lib/codegen/emit.d.ts +129 -0
  10. package/lib/codegen/emit.d.ts.map +1 -0
  11. package/lib/codegen/emit.js +105 -0
  12. package/lib/codegen/emit.js.map +1 -0
  13. package/lib/codegen/format.d.ts +23 -0
  14. package/lib/codegen/format.d.ts.map +1 -0
  15. package/lib/codegen/format.js +28 -0
  16. package/lib/codegen/format.js.map +1 -0
  17. package/lib/codegen/generator.d.ts +334 -0
  18. package/lib/codegen/generator.d.ts.map +1 -0
  19. package/lib/codegen/generator.js +691 -0
  20. package/lib/codegen/generator.js.map +1 -0
  21. package/lib/codegen/graph.d.ts +36 -0
  22. package/lib/codegen/graph.d.ts.map +1 -0
  23. package/lib/codegen/graph.js +136 -0
  24. package/lib/codegen/graph.js.map +1 -0
  25. package/lib/codegen/members.d.ts +25 -0
  26. package/lib/codegen/members.d.ts.map +1 -0
  27. package/lib/codegen/members.js +55 -0
  28. package/lib/codegen/members.js.map +1 -0
  29. package/lib/codegen/naming.d.ts +29 -0
  30. package/lib/codegen/naming.d.ts.map +1 -0
  31. package/lib/codegen/naming.js +74 -0
  32. package/lib/codegen/naming.js.map +1 -0
  33. package/lib/codegen/openapi-cli.d.ts +38 -0
  34. package/lib/codegen/openapi-cli.d.ts.map +1 -0
  35. package/lib/codegen/openapi-cli.js +107 -0
  36. package/lib/codegen/openapi-cli.js.map +1 -0
  37. package/lib/codegen/openapi.d.ts +115 -0
  38. package/lib/codegen/openapi.d.ts.map +1 -0
  39. package/lib/codegen/openapi.js +1220 -0
  40. package/lib/codegen/openapi.js.map +1 -0
  41. package/lib/codegen/operations.d.ts +24 -0
  42. package/lib/codegen/operations.d.ts.map +1 -0
  43. package/lib/codegen/operations.js +56 -0
  44. package/lib/codegen/operations.js.map +1 -0
  45. package/lib/codegen/pagination.d.ts +39 -0
  46. package/lib/codegen/pagination.d.ts.map +1 -0
  47. package/lib/codegen/pagination.js +33 -0
  48. package/lib/codegen/pagination.js.map +1 -0
  49. package/lib/codegen/prelude.d.ts +15 -0
  50. package/lib/codegen/prelude.d.ts.map +1 -0
  51. package/lib/codegen/prelude.js +60 -0
  52. package/lib/codegen/prelude.js.map +1 -0
  53. package/lib/error-category.d.ts +28 -0
  54. package/lib/error-category.d.ts.map +1 -0
  55. package/lib/error-category.js +46 -0
  56. package/lib/error-category.js.map +1 -0
  57. package/lib/errors.d.ts +1 -0
  58. package/lib/errors.d.ts.map +1 -1
  59. package/lib/errors.js +1 -0
  60. package/lib/errors.js.map +1 -1
  61. package/lib/json-patch.d.ts +25 -32
  62. package/lib/json-patch.d.ts.map +1 -1
  63. package/lib/json-patch.js +23 -95
  64. package/lib/json-patch.js.map +1 -1
  65. package/lib/pagination.d.ts +37 -51
  66. package/lib/pagination.d.ts.map +1 -1
  67. package/lib/pagination.js +72 -90
  68. package/lib/pagination.js.map +1 -1
  69. package/lib/protocol-http.d.ts +74 -0
  70. package/lib/protocol-http.d.ts.map +1 -0
  71. package/lib/protocol-http.js +554 -0
  72. package/lib/protocol-http.js.map +1 -0
  73. package/lib/protocol-rest.d.ts +124 -0
  74. package/lib/protocol-rest.d.ts.map +1 -0
  75. package/lib/protocol-rest.js +242 -0
  76. package/lib/protocol-rest.js.map +1 -0
  77. package/lib/retry.d.ts +8 -2
  78. package/lib/retry.d.ts.map +1 -1
  79. package/lib/retry.js +21 -15
  80. package/lib/retry.js.map +1 -1
  81. package/lib/schema.d.ts +7 -8
  82. package/lib/schema.d.ts.map +1 -1
  83. package/lib/schema.js +7 -8
  84. package/lib/schema.js.map +1 -1
  85. package/lib/trait.d.ts +150 -0
  86. package/lib/trait.d.ts.map +1 -0
  87. package/lib/trait.js +107 -0
  88. package/lib/trait.js.map +1 -0
  89. package/package.json +18 -75
  90. package/src/api.ts +446 -0
  91. package/src/codegen/cli.ts +268 -0
  92. package/src/codegen/emit.ts +207 -0
  93. package/src/codegen/format.ts +47 -0
  94. package/src/codegen/generator.ts +1153 -0
  95. package/src/codegen/graph.ts +151 -0
  96. package/src/codegen/members.ts +71 -0
  97. package/src/codegen/naming.ts +86 -0
  98. package/src/codegen/openapi-cli.ts +166 -0
  99. package/src/codegen/openapi.ts +1450 -0
  100. package/src/codegen/operations.ts +76 -0
  101. package/src/codegen/pagination.ts +71 -0
  102. package/src/codegen/prelude.ts +70 -0
  103. package/src/error-category.ts +84 -0
  104. package/src/errors.ts +2 -0
  105. package/src/json-patch.ts +26 -110
  106. package/src/pagination.ts +86 -142
  107. package/src/protocol-http.ts +699 -0
  108. package/src/protocol-rest.ts +367 -0
  109. package/src/retry.ts +20 -21
  110. package/src/schema.ts +7 -8
  111. package/src/trait.ts +238 -0
  112. package/README.md +0 -30
  113. package/lib/client.d.ts +0 -167
  114. package/lib/client.d.ts.map +0 -1
  115. package/lib/client.js +0 -659
  116. package/lib/client.js.map +0 -1
  117. package/lib/schemas.d.ts +0 -60
  118. package/lib/schemas.d.ts.map +0 -1
  119. package/lib/schemas.js +0 -79
  120. package/lib/schemas.js.map +0 -1
  121. package/lib/sensitive.d.ts +0 -71
  122. package/lib/sensitive.d.ts.map +0 -1
  123. package/lib/sensitive.js +0 -96
  124. package/lib/sensitive.js.map +0 -1
  125. package/lib/traits.d.ts +0 -421
  126. package/lib/traits.d.ts.map +0 -1
  127. package/lib/traits.js +0 -737
  128. package/lib/traits.js.map +0 -1
  129. package/src/client.ts +0 -1177
  130. package/src/schemas.ts +0 -128
  131. package/src/sensitive.ts +0 -119
  132. package/src/traits.ts +0 -996
@@ -1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74 @@
1
+ /**
2
+ * Generic REST protocol machinery, shared by SDK protocol layers.
3
+ *
4
+ * Everything here is driven purely by the trait annotations in
5
+ * `core/trait.ts` — nothing is provider-specific. An SDK protocol (e.g.
6
+ * cloudflare's) supplies credentials/base-URL, calls {@link buildRequest} to
7
+ * encode, and layers its own response-envelope handling on top of the
8
+ * decode-side helpers ({@link getProps}/{@link mapKeys}/
9
+ * {@link matchTypedError}).
10
+ */
11
+ import type * as AST from "effect/SchemaAST";
12
+ import * as HttpClientRequest from "effect/unstable/http/HttpClientRequest";
13
+ import { type ErrorMatcher, type KeyDictionaryEntries } from "./trait.ts";
14
+ export declare const getProps: (ast: AST.AST) => readonly AST.PropertySignature[];
15
+ export declare const getAnn: (ast: AST.AST, symbol: symbol) => unknown;
16
+ export declare const getPropAnn: (prop: AST.PropertySignature, symbol: symbol) => unknown;
17
+ export declare const hasPropAnn: (prop: AST.PropertySignature, symbol: symbol) => boolean;
18
+ export declare const nameOf: (prop: AST.PropertySignature, symbol: symbol) => string;
19
+ /** Resolve wrappers to the real node: Suspend, encoding, optional/null unions. */
20
+ export declare const resolveNode: (ast: AST.AST) => AST.AST;
21
+ /** Binary/opaque values that must never be treated as key-value objects. */
22
+ export declare const isOpaqueValue: (v: unknown) => boolean;
23
+ /**
24
+ * Deep-rename keys via a plain dictionary (see `T.KeyDictionary`). An entry
25
+ * may list several wire spellings; encode uses the first (canonical) one and
26
+ * decode maps every listed spelling back to the TS name.
27
+ */
28
+ export declare const mapKeysByDictionary: (dict: KeyDictionaryEntries, value: unknown, direction: "encode" | "decode") => unknown;
29
+ /**
30
+ * Recursively rename keys between TS names and wire names, per the schema.
31
+ *
32
+ * `fallback` is the nearest ancestor `T.KeyDictionary` — schema-known members
33
+ * always map via their own annotations, but opaque values (Document members,
34
+ * keys the schema doesn't know) deep-rename via the dictionary so nested
35
+ * TS-cased content still reaches the wire in wire case. Content with no
36
+ * dictionary in scope passes through verbatim.
37
+ */
38
+ export declare const mapKeys: (ast: AST.AST, value: unknown, direction: "encode" | "decode", fallback?: KeyDictionaryEntries) => unknown;
39
+ export interface BuildRequestOptions {
40
+ readonly input: unknown;
41
+ readonly inputAst: AST.AST;
42
+ /** Base URL the operation's URI template is appended to. */
43
+ readonly baseUrl: string;
44
+ /** Headers applied before member-bound headers (credentials etc.). */
45
+ readonly headers?: Record<string, string>;
46
+ /**
47
+ * Transform a member-bound header value before it is set (e.g.
48
+ * Bearer-prefixing a raw token supplied as an Authorization member).
49
+ */
50
+ readonly mapMemberHeader?: (name: string, value: string) => string;
51
+ /**
52
+ * Wire name for input keys the schema doesn't declare (spec drift —
53
+ * unknown keys pass through as body fields rather than being dropped).
54
+ * Defaults to the key verbatim.
55
+ */
56
+ readonly unknownKeyToWire?: (key: string) => string;
57
+ }
58
+ export declare const buildRequest: ({ input, inputAst, baseUrl, headers: baseHeaders, mapMemberHeader, unknownKeyToWire, }: BuildRequestOptions) => HttpClientRequest.HttpClientRequest;
59
+ /**
60
+ * Whether one matcher matches one wire error: every present field must
61
+ * match; a matcher (or a message object) with no constraints matches
62
+ * nothing.
63
+ */
64
+ export declare const matchesExpression: (m: ErrorMatcher, code: number | undefined, status: number, message: string) => boolean;
65
+ /**
66
+ * Pick the operation's typed error class for a failed response: among all
67
+ * declared classes whose matchers (see `applyErrorMatchers`) match the wire
68
+ * failure, the most specific matcher wins (ties break by declaration order).
69
+ */
70
+ export declare const matchTypedError: (errorClasses: ReadonlyArray<unknown>, status: number, errors: ReadonlyArray<{
71
+ code?: number;
72
+ message: string;
73
+ }>) => unknown | undefined;
74
+ //# sourceMappingURL=protocol-http.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"protocol-http.d.ts","sourceRoot":"","sources":["../src/protocol-http.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,KAAK,KAAK,GAAG,MAAM,kBAAkB,CAAC;AAE7C,OAAO,KAAK,iBAAiB,MAAM,wCAAwC,CAAC;AAC5E,OAAO,EAYL,KAAK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,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,MAAM,CAAC;IACnE;;;;OAIG;IACH,QAAQ,CAAC,gBAAgB,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,MAAM,CAAC;CACrD;AAqDD,eAAO,MAAM,YAAY,2FAOtB,mBAAmB,KAAG,iBAAiB,CAAC,iBAgN1C,CAAC;AAKF;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,MACzB,YAAY,QACT,MAAM,GAAG,SAAS,UAChB,MAAM,WACL,MAAM,KACd,OAiBF,CAAC;AAOF;;;;GAIG;AACH,eAAO,MAAM,eAAe,iBACZ,aAAa,CAAC,OAAO,CAAC,UAC5B,MAAM,UACN,aAAa,CAAC;IAAE,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC,KACxD,OAAO,GAAG,SAsBZ,CAAC"}
@@ -0,0 +1,554 @@
1
+ import * as HttpBody from "effect/unstable/http/HttpBody";
2
+ import * as HttpClientRequest from "effect/unstable/http/HttpClientRequest";
3
+ import { bodySymbol, deepQuerySymbol, formDataFileSymbol, getErrorMatchers, headerSymbol, httpBodySymbol, httpSymbol, keyDictionarySymbol, labelSymbol, querySymbol, unionCasesSymbol, } from "./trait.js";
4
+ //#region AST helpers (survive S.optional / Suspend / transforms)
5
+ export const getProps = (ast) => {
6
+ if (ast._tag === "Objects")
7
+ return ast.propertySignatures;
8
+ if (ast._tag === "Suspend")
9
+ return getProps(ast.thunk());
10
+ if (ast.encoding && ast.encoding.length > 0)
11
+ return getProps(ast.encoding[0].to);
12
+ return [];
13
+ };
14
+ export const getAnn = (ast, symbol) => {
15
+ const direct = ast.annotations?.[symbol];
16
+ if (direct !== undefined)
17
+ return direct;
18
+ if (ast._tag === "Suspend")
19
+ return getAnn(ast.thunk(), symbol);
20
+ if (ast.encoding && ast.encoding.length > 0)
21
+ return getAnn(ast.encoding[0].to, symbol);
22
+ // S.optional → Union[self, Undefined]; descend into the single real member.
23
+ if (ast._tag === "Union") {
24
+ const real = ast.types.filter((t) => t._tag !== "Undefined" &&
25
+ !(t._tag === "Literal" && t.literal === null));
26
+ if (real.length === 1)
27
+ return getAnn(real[0], symbol);
28
+ }
29
+ return undefined;
30
+ };
31
+ export const getPropAnn = (prop, symbol) => getAnn(prop.type, symbol);
32
+ export const hasPropAnn = (prop, symbol) => getPropAnn(prop, symbol) !== undefined;
33
+ export const nameOf = (prop, symbol) => {
34
+ const v = getPropAnn(prop, symbol);
35
+ return typeof v === "string" ? v : String(prop.name);
36
+ };
37
+ /** Resolve wrappers to the real node: Suspend, encoding, optional/null unions. */
38
+ export const resolveNode = (ast) => {
39
+ if (ast._tag === "Suspend")
40
+ return resolveNode(ast.thunk());
41
+ if (ast.encoding && ast.encoding.length > 0)
42
+ return resolveNode(ast.encoding[0].to);
43
+ if (ast._tag === "Union") {
44
+ const real = ast.types.filter((t) => t._tag !== "Undefined" &&
45
+ t._tag !== "Null" &&
46
+ !(t._tag === "Literal" && t.literal === null));
47
+ if (real.length === 1)
48
+ return resolveNode(real[0]);
49
+ }
50
+ return ast;
51
+ };
52
+ //#endregion
53
+ //#region Recursive wire-name mapping
54
+ /** Binary/opaque values that must never be treated as key-value objects. */
55
+ export const isOpaqueValue = (v) => v instanceof Blob ||
56
+ v instanceof File ||
57
+ v instanceof ArrayBuffer ||
58
+ v instanceof Uint8Array ||
59
+ v instanceof Date;
60
+ /**
61
+ * Deep-rename keys via a plain dictionary (see `T.KeyDictionary`). An entry
62
+ * may list several wire spellings; encode uses the first (canonical) one and
63
+ * decode maps every listed spelling back to the TS name.
64
+ */
65
+ export const mapKeysByDictionary = (dict, value, direction) => {
66
+ if (value === null || typeof value !== "object" || isOpaqueValue(value)) {
67
+ return value;
68
+ }
69
+ if (Array.isArray(value)) {
70
+ return value.map((v) => mapKeysByDictionary(dict, v, direction));
71
+ }
72
+ const rename = direction === "decode"
73
+ ? Object.fromEntries(Object.entries(dict).flatMap(([ts, wire]) => typeof wire === "string"
74
+ ? [[wire, ts]]
75
+ : wire.map((w) => [w, ts])))
76
+ : Object.fromEntries(Object.entries(dict).map(([ts, wire]) => [
77
+ ts,
78
+ typeof wire === "string" ? wire : wire[0],
79
+ ]));
80
+ const out = {};
81
+ for (const [k, v] of Object.entries(value)) {
82
+ if (v === undefined)
83
+ continue;
84
+ out[rename[k] ?? k] = mapKeysByDictionary(dict, v, direction);
85
+ }
86
+ return out;
87
+ };
88
+ /**
89
+ * Recursively rename keys between TS names and wire names, per the schema.
90
+ *
91
+ * `fallback` is the nearest ancestor `T.KeyDictionary` — schema-known members
92
+ * always map via their own annotations, but opaque values (Document members,
93
+ * keys the schema doesn't know) deep-rename via the dictionary so nested
94
+ * TS-cased content still reaches the wire in wire case. Content with no
95
+ * dictionary in scope passes through verbatim.
96
+ */
97
+ export const mapKeys = (ast, value, direction, fallback) => {
98
+ if (value === null ||
99
+ value === undefined ||
100
+ typeof value !== "object" ||
101
+ isOpaqueValue(value)) {
102
+ return value;
103
+ }
104
+ const dict = getAnn(ast, keyDictionarySymbol) ??
105
+ fallback;
106
+ // Discriminated union whose cases the API returns merged (every case's
107
+ // keys present, `null` for the inactive ones). Map wire names, then keep
108
+ // only the active case's keys. A case does NOT need every key present —
109
+ // arms carry optional members the wire may omit — so the active case is
110
+ // the one that best EXPLAINS the value: most present, non-null keys
111
+ // covered, minus present keys the case cannot explain (ties break by
112
+ // coverage, then declaration order).
113
+ const unionCases = getAnn(ast, unionCasesSymbol);
114
+ if (unionCases && direction === "decode" && !Array.isArray(value)) {
115
+ const obj = (dict ? mapKeysByDictionary(dict, value, "decode") : value);
116
+ const present = Object.keys(obj).filter((k) => obj[k] !== undefined && obj[k] !== null);
117
+ let best;
118
+ for (const keys of unionCases) {
119
+ const set = new Set(keys);
120
+ let matched = 0;
121
+ let excess = 0;
122
+ for (const k of present) {
123
+ if (set.has(k))
124
+ matched++;
125
+ else
126
+ excess++;
127
+ }
128
+ const score = matched - excess;
129
+ if (matched > 0 &&
130
+ (!best ||
131
+ score > best.score ||
132
+ (score === best.score && matched > best.matched))) {
133
+ best = { keys, score, matched };
134
+ }
135
+ }
136
+ if (best) {
137
+ const out = {};
138
+ for (const k of best.keys)
139
+ out[k] = obj[k];
140
+ return out;
141
+ }
142
+ return obj;
143
+ }
144
+ const node = resolveNode(ast);
145
+ // Schema-level union member (a merged response struct whose arms disagree
146
+ // on a member's type — see the codegen's response-union merge): pick the
147
+ // arm that explains the value best and map with it. Object values score
148
+ // arms by how many of their declared keys are present; array values take
149
+ // the first array arm. Anything unmatched deep-renames via the dictionary
150
+ // fallback, like other opaque content. (Single-real-member unions —
151
+ // optional/null wrappers — were already collapsed by resolveNode; the
152
+ // opaque `T.UnionCases` mechanism never produces a Union node and is
153
+ // handled above.)
154
+ if (node._tag === "Union") {
155
+ const arms = node.types.map(resolveNode);
156
+ if (Array.isArray(value)) {
157
+ const arr = arms.find((t) => t._tag === "Arrays");
158
+ if (arr)
159
+ return mapKeys(arr, value, direction, dict);
160
+ }
161
+ else {
162
+ let best;
163
+ let bestScore = 0;
164
+ for (const t of arms) {
165
+ if (t._tag !== "Objects")
166
+ continue;
167
+ let score = 0;
168
+ for (const p of t
169
+ .propertySignatures) {
170
+ const from = direction === "encode" ? String(p.name) : nameOf(p, bodySymbol);
171
+ if (value[from] !== undefined)
172
+ score++;
173
+ }
174
+ if (score > bestScore) {
175
+ best = t;
176
+ bestScore = score;
177
+ }
178
+ }
179
+ if (best)
180
+ return mapKeys(best, value, direction, dict);
181
+ }
182
+ return dict ? mapKeysByDictionary(dict, value, direction) : value;
183
+ }
184
+ if (node._tag === "Arrays") {
185
+ if (!Array.isArray(value))
186
+ return value;
187
+ const elem = node.rest?.[0];
188
+ return elem
189
+ ? value.map((v) => mapKeys(elem, v, direction, dict))
190
+ : dict
191
+ ? mapKeysByDictionary(dict, value, direction)
192
+ : value;
193
+ }
194
+ if (node._tag === "Objects" && !Array.isArray(value)) {
195
+ const props = node
196
+ .propertySignatures;
197
+ const isigs = node.indexSignatures;
198
+ if (props.length === 0 && !(isigs && isigs.length)) {
199
+ // opaque object — dictionary fallback or verbatim
200
+ return dict ? mapKeysByDictionary(dict, value, direction) : value;
201
+ }
202
+ const out = {};
203
+ const consumed = new Set();
204
+ for (const p of props) {
205
+ const tsName = String(p.name);
206
+ const wire = nameOf(p, bodySymbol);
207
+ const from = direction === "encode" ? tsName : wire;
208
+ const to = direction === "encode" ? wire : tsName;
209
+ consumed.add(from);
210
+ const v = value[from];
211
+ if (v === undefined)
212
+ continue;
213
+ out[to] = mapKeys(p.type, v, direction, dict);
214
+ }
215
+ for (const [k, v] of Object.entries(value)) {
216
+ if (consumed.has(k) || v === undefined)
217
+ continue;
218
+ const renamed = dict
219
+ ? direction === "encode"
220
+ ? (dict[k] ?? k)
221
+ : (Object.entries(dict).find(([, w]) => w === k)?.[0] ?? k)
222
+ : k;
223
+ out[typeof renamed === "string" ? renamed : renamed[0]] =
224
+ isigs && isigs.length
225
+ ? mapKeys(isigs[0].type, v, direction, dict)
226
+ : dict
227
+ ? mapKeysByDictionary(dict, v, direction)
228
+ : v;
229
+ }
230
+ return out;
231
+ }
232
+ // Scalar-typed schema node holding object content (spec drift) —
233
+ // dictionary fallback or verbatim.
234
+ return dict ? mapKeysByDictionary(dict, value, direction) : value;
235
+ };
236
+ //#endregion
237
+ //#region Request building
238
+ const BODYLESS = new Set(["GET", "HEAD"]);
239
+ /**
240
+ * Serialize one query member. Scalars go as `k=v`, arrays as repeated `k=v`
241
+ * pairs, and nested plain objects recurse as DOTTED params — several list
242
+ * endpoints model their filters as structs (e.g. Cloudflare DNS listRecords
243
+ * takes `name: { exact, contains, ... }`) that must go over the wire as
244
+ * `name.exact=value`. Without this they fell through to `String(value)` and
245
+ * were sent as `name=[object Object]`, which servers happily treat as a
246
+ * filter matching nothing — the call "succeeds" with zero results and the
247
+ * bug is invisible to the caller.
248
+ */
249
+ const appendQuery = (query, name, value) => {
250
+ if (Array.isArray(value)) {
251
+ for (const v of value)
252
+ appendQuery(query, name, v);
253
+ }
254
+ else if (value !== null &&
255
+ typeof value === "object" &&
256
+ !(value instanceof Date)) {
257
+ for (const [k, v] of Object.entries(value)) {
258
+ if (v !== undefined)
259
+ appendQuery(query, `${name}.${k}`, v);
260
+ }
261
+ }
262
+ else {
263
+ query.append(name, String(value));
264
+ }
265
+ };
266
+ /**
267
+ * Build an HTTP request from an operation input and its schema, driven by
268
+ * the trait annotations: `Http()` supplies method + URI template, `Label()`
269
+ * members fill URI placeholders, `Header()`/`Query()` members bind to
270
+ * headers/query params, `DeepQuery()` struct members expand into dotted
271
+ * query params, `HttpBody()` sends the member as the whole body,
272
+ * `FormDataFile()` members become multipart file parts, and everything else
273
+ * is a JSON body field (wire-named via `Body()` / `KeyDictionary`).
274
+ *
275
+ * Throws when the input schema is missing the `Http()` trait — a codegen
276
+ * bug, surfaced as a defect by the calling protocol's Effect context.
277
+ */
278
+ /**
279
+ * Flatten a nested object into Stripe-style bracket notation pairs for
280
+ * form-urlencoded bodies: nested objects become `a[b][c]`, arrays index as
281
+ * `a[0]`; null/undefined dropped, booleans as "true"/"false".
282
+ */
283
+ const flattenToFormPairs = (obj, prefix = "") => {
284
+ const pairs = [];
285
+ for (const [key, value] of Object.entries(obj)) {
286
+ if (value === undefined || value === null)
287
+ continue;
288
+ const fullKey = prefix ? `${prefix}[${key}]` : key;
289
+ if (Array.isArray(value)) {
290
+ for (let i = 0; i < value.length; i++) {
291
+ const item = value[i];
292
+ if (item === undefined || item === null)
293
+ continue;
294
+ if (typeof item === "object" && !Array.isArray(item)) {
295
+ pairs.push(...flattenToFormPairs(item, `${fullKey}[${i}]`));
296
+ }
297
+ else {
298
+ pairs.push([`${fullKey}[${i}]`, String(item)]);
299
+ }
300
+ }
301
+ }
302
+ else if (typeof value === "object") {
303
+ pairs.push(...flattenToFormPairs(value, fullKey));
304
+ }
305
+ else {
306
+ pairs.push([fullKey, String(value)]);
307
+ }
308
+ }
309
+ return pairs;
310
+ };
311
+ export const buildRequest = ({ input, inputAst, baseUrl, headers: baseHeaders, mapMemberHeader, unknownKeyToWire, }) => {
312
+ const inputObj = (input ?? {});
313
+ const http = getAnn(inputAst, httpSymbol);
314
+ if (!http) {
315
+ throw new Error("operation input is missing the Http() trait");
316
+ }
317
+ // Root key dictionary: fallback wire mapping for opaque/unknown content
318
+ // the schema doesn't model.
319
+ const rootDict = getAnn(inputAst, keyDictionarySymbol);
320
+ const headers = { ...baseHeaders };
321
+ const body = {};
322
+ let rawBody; // whole-body member (T.HttpBody) — sent as-is
323
+ const files = [];
324
+ const query = new URLSearchParams();
325
+ let uri = http.uri;
326
+ const consumed = new Set();
327
+ let hasBodyMembers = false;
328
+ for (const prop of getProps(inputAst)) {
329
+ const key = String(prop.name);
330
+ consumed.add(key);
331
+ const value = inputObj[key];
332
+ const isBodyMember = !hasPropAnn(prop, labelSymbol) &&
333
+ !hasPropAnn(prop, headerSymbol) &&
334
+ !hasPropAnn(prop, querySymbol) &&
335
+ !hasPropAnn(prop, deepQuerySymbol);
336
+ if (isBodyMember)
337
+ hasBodyMembers = true;
338
+ if (value === undefined)
339
+ continue;
340
+ if (hasPropAnn(prop, labelSymbol)) {
341
+ const token = nameOf(prop, labelSymbol);
342
+ uri = uri.replace(`{${token}}`, encodeURIComponent(String(value)));
343
+ }
344
+ else if (hasPropAnn(prop, headerSymbol)) {
345
+ const hName = nameOf(prop, headerSymbol).toLowerCase();
346
+ const hVal = String(value);
347
+ headers[hName] = mapMemberHeader ? mapMemberHeader(hName, hVal) : hVal;
348
+ }
349
+ else if (hasPropAnn(prop, querySymbol)) {
350
+ appendQuery(query, nameOf(prop, querySymbol), value);
351
+ }
352
+ else if (hasPropAnn(prop, deepQuerySymbol)) {
353
+ // Deep-object query member (T.DeepQuery): a nested struct expands into
354
+ // dotted query keys (`account.id=…`) under the member's wire name.
355
+ // Wire-name the nested content via the schema first, skip null/
356
+ // undefined entries; deeper nesting recurses through appendQuery.
357
+ const base = nameOf(prop, deepQuerySymbol);
358
+ const mapped = mapKeys(prop.type, value, "encode", rootDict);
359
+ if (mapped !== null && typeof mapped === "object") {
360
+ for (const [k, v] of Object.entries(mapped)) {
361
+ if (v !== undefined && v !== null) {
362
+ appendQuery(query, `${base}.${k}`, v);
363
+ }
364
+ }
365
+ }
366
+ }
367
+ else if (hasPropAnn(prop, formDataFileSymbol)) {
368
+ for (const f of Array.isArray(value) ? value : [value]) {
369
+ files.push(f);
370
+ }
371
+ }
372
+ else if (hasPropAnn(prop, httpBodySymbol)) {
373
+ rawBody = mapKeys(prop.type, value, "encode", rootDict);
374
+ }
375
+ else {
376
+ body[nameOf(prop, bodySymbol)] = mapKeys(prop.type, value, "encode", rootDict);
377
+ }
378
+ }
379
+ // Input keys the schema doesn't know pass through as body fields — the
380
+ // generated schemas can lag the real API, and silently dropping them
381
+ // would break working callers. The key dictionary maps them when it knows
382
+ // the key, otherwise `unknownKeyToWire` decides the wire name.
383
+ for (const [key, value] of Object.entries(inputObj)) {
384
+ if (consumed.has(key) || value === undefined)
385
+ continue;
386
+ const wire = rootDict?.[key] ?? (unknownKeyToWire ? unknownKeyToWire(key) : key);
387
+ body[typeof wire === "string" ? wire : wire[0]] = rootDict
388
+ ? mapKeysByDictionary(rootDict, value, "encode")
389
+ : value;
390
+ hasBodyMembers = true;
391
+ }
392
+ const qs = query.toString();
393
+ const url = `${baseUrl}${uri}${qs ? `?${qs}` : ""}`;
394
+ if (process.env.DISTILLED_DEBUG_HTTP) {
395
+ console.error(`[distilled] ${http.method} ${url}` +
396
+ (Object.keys(body).length
397
+ ? ` body=${JSON.stringify(body).slice(0, 400)}`
398
+ : ""));
399
+ }
400
+ let request = HttpClientRequest.make(http.method)(url).pipe(HttpClientRequest.setHeaders(headers));
401
+ if (http.contentType === "multipart") {
402
+ // Multipart upload: each body member is a form part (objects
403
+ // JSON-encoded under their wire name), each file appends under its own
404
+ // filename. A whole-body member (T.HttpBody) that is a record of files
405
+ // becomes one part per entry (e.g. asset upload: { <hash>: File }).
406
+ // File/Blob → binary part (filename = File.name), array of files → each
407
+ // appended, object → JSON string, primitive → string.
408
+ const form = new FormData();
409
+ const parts = rawBody !== undefined && typeof rawBody === "object"
410
+ ? rawBody
411
+ : body;
412
+ const isFileOrBlob = (v) => v instanceof Blob || v instanceof File;
413
+ for (const [key, value] of Object.entries(parts)) {
414
+ if (value === undefined || value === null)
415
+ continue;
416
+ if (isFileOrBlob(value)) {
417
+ form.append(key, value, value instanceof File ? value.name : key);
418
+ }
419
+ else if (Array.isArray(value) &&
420
+ value.length > 0 &&
421
+ isFileOrBlob(value[0])) {
422
+ for (const file of value) {
423
+ if (isFileOrBlob(file)) {
424
+ form.append(file instanceof File ? file.name : key, file, file instanceof File ? file.name : undefined);
425
+ }
426
+ }
427
+ }
428
+ else if (typeof value === "object") {
429
+ form.append(key, JSON.stringify(value));
430
+ }
431
+ else {
432
+ form.append(key, String(value));
433
+ }
434
+ }
435
+ for (const f of files) {
436
+ const filename = f.name ?? "file";
437
+ form.append(filename, f, filename);
438
+ }
439
+ request = request.pipe(HttpClientRequest.bodyFormData(form));
440
+ }
441
+ else if (http.contentType === "form-urlencoded" &&
442
+ !BODYLESS.has(http.method)) {
443
+ // application/x-www-form-urlencoded with Stripe-style deepObject bracket
444
+ // notation: { shipping: { address: { city } } } → shipping[address][city],
445
+ // arrays indexed ({ expand: ["a"] } → expand[0]=a).
446
+ const source = rawBody !== undefined && typeof rawBody === "object"
447
+ ? rawBody
448
+ : body;
449
+ const params = new URLSearchParams();
450
+ for (const [k, v] of flattenToFormPairs(source))
451
+ params.append(k, v);
452
+ request = request.pipe(HttpClientRequest.setBody(HttpBody.text(params.toString(), "application/x-www-form-urlencoded")));
453
+ }
454
+ else if (rawBody !== undefined && !BODYLESS.has(http.method)) {
455
+ // Whole-body member (raw arrays/scalars) — sent as the body itself.
456
+ // Binary payloads (Blob / ArrayBuffer / Uint8Array) send verbatim
457
+ // (raw object uploads — the Content-Type header member, when modeled,
458
+ // rides alongside). With a bodyMediaType, the member is a
459
+ // preserialized payload (string / bytes) sent verbatim under that
460
+ // media type (e.g. application/x-ndjson for Vectorize
461
+ // insert/upsert); otherwise it's JSON.
462
+ if (rawBody instanceof Blob || rawBody instanceof ArrayBuffer) {
463
+ // Honor the declared media type (e.g. application/x-ndjson for
464
+ // Vectorize insert/upsert) — without it the server may fall back to
465
+ // JSON parsing. When no bodyMediaType is modeled the header is left
466
+ // untouched (a modeled Content-Type header member rides alongside).
467
+ request = request.pipe(HttpClientRequest.setBody(HttpBody.raw(rawBody, { contentType: http.bodyMediaType })));
468
+ }
469
+ else if (rawBody instanceof Uint8Array) {
470
+ request = request.pipe(HttpClientRequest.setBody(HttpBody.uint8Array(rawBody, http.bodyMediaType)));
471
+ }
472
+ else if (http.bodyMediaType) {
473
+ request = request.pipe(HttpClientRequest.setBody(typeof rawBody === "string"
474
+ ? HttpBody.text(rawBody, http.bodyMediaType)
475
+ : HttpBody.uint8Array(rawBody, http.bodyMediaType)));
476
+ }
477
+ else {
478
+ request = request.pipe(HttpClientRequest.bodyJsonUnsafe(rawBody));
479
+ }
480
+ }
481
+ else if (!BODYLESS.has(http.method) &&
482
+ (Object.keys(body).length > 0 ||
483
+ (hasBodyMembers && http.method !== "DELETE"))) {
484
+ // Send `{}` rather than no body when the schema declares body members —
485
+ // some endpoints reject a missing JSON body outright.
486
+ request = request.pipe(HttpClientRequest.bodyJsonUnsafe(body));
487
+ }
488
+ return request;
489
+ };
490
+ //#endregion
491
+ //#region Typed error matching
492
+ /**
493
+ * Whether one matcher matches one wire error: every present field must
494
+ * match; a matcher (or a message object) with no constraints matches
495
+ * nothing.
496
+ */
497
+ export const matchesExpression = (m, code, status, message) => {
498
+ if (m.code === undefined && m.status === undefined && m.message === undefined)
499
+ return false;
500
+ if (m.code !== undefined && m.code !== code)
501
+ return false;
502
+ if (m.status !== undefined && m.status !== status)
503
+ return false;
504
+ if (m.message !== undefined) {
505
+ if (typeof m.message === "string") {
506
+ if (m.message !== message)
507
+ return false;
508
+ }
509
+ else {
510
+ const { includes, matches } = m.message;
511
+ if (includes === undefined && matches === undefined)
512
+ return false;
513
+ if (includes !== undefined && !message.includes(includes))
514
+ return false;
515
+ if (matches !== undefined && !new RegExp(matches).test(message))
516
+ return false;
517
+ }
518
+ }
519
+ return true;
520
+ };
521
+ const matcherSpecificity = (m) => (m.code !== undefined ? 1 : 0) +
522
+ (m.status !== undefined ? 1 : 0) +
523
+ (m.message !== undefined ? 1 : 0);
524
+ /**
525
+ * Pick the operation's typed error class for a failed response: among all
526
+ * declared classes whose matchers (see `applyErrorMatchers`) match the wire
527
+ * failure, the most specific matcher wins (ties break by declaration order).
528
+ */
529
+ export const matchTypedError = (errorClasses, status, errors) => {
530
+ let best;
531
+ for (const cls of errorClasses) {
532
+ const matchers = getErrorMatchers(cls);
533
+ if (!matchers)
534
+ continue;
535
+ for (const m of matchers) {
536
+ for (const e of errors) {
537
+ if (!matchesExpression(m, e.code, status, e.message))
538
+ continue;
539
+ const specificity = matcherSpecificity(m);
540
+ if (!best || specificity > best.specificity) {
541
+ best = { cls, specificity, code: e.code, message: e.message };
542
+ }
543
+ }
544
+ }
545
+ }
546
+ if (!best)
547
+ return undefined;
548
+ return new best.cls({
549
+ code: best.code ?? 0,
550
+ message: best.message,
551
+ });
552
+ };
553
+ //#endregion
554
+ //# sourceMappingURL=protocol-http.js.map