@distilled.cloud/core 1.0.0-rc.13 → 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.
- package/lib/api.d.ts +4 -4
- package/lib/api.d.ts.map +1 -1
- package/lib/api.js +3 -5
- package/lib/api.js.map +1 -1
- package/lib/category.d.ts.map +1 -1
- package/lib/category.js +3 -5
- package/lib/category.js.map +1 -1
- package/lib/codegen/boolean-string-enums.d.ts.map +1 -1
- package/lib/codegen/boolean-string-enums.js +2 -6
- package/lib/codegen/boolean-string-enums.js.map +1 -1
- package/lib/codegen/boolean-string-enums.test.js +3 -5
- package/lib/codegen/boolean-string-enums.test.js.map +1 -1
- package/lib/codegen/cli.d.ts +5 -4
- package/lib/codegen/cli.d.ts.map +1 -1
- package/lib/codegen/cli.js +12 -9
- package/lib/codegen/cli.js.map +1 -1
- package/lib/codegen/defer-naming.test.d.ts +2 -0
- package/lib/codegen/defer-naming.test.d.ts.map +1 -0
- package/lib/codegen/defer-naming.test.js +105 -0
- package/lib/codegen/defer-naming.test.js.map +1 -0
- package/lib/codegen/emit.d.ts.map +1 -1
- package/lib/codegen/emit.js +1 -3
- package/lib/codegen/emit.js.map +1 -1
- package/lib/codegen/format.d.ts +0 -12
- package/lib/codegen/format.d.ts.map +1 -1
- package/lib/codegen/format.js +10 -6
- package/lib/codegen/format.js.map +1 -1
- package/lib/codegen/generated-at.d.ts +29 -0
- package/lib/codegen/generated-at.d.ts.map +1 -0
- package/lib/codegen/generated-at.js +78 -0
- package/lib/codegen/generated-at.js.map +1 -0
- package/lib/codegen/generated-at.test.d.ts +2 -0
- package/lib/codegen/generated-at.test.d.ts.map +1 -0
- package/lib/codegen/generated-at.test.js +81 -0
- package/lib/codegen/generated-at.test.js.map +1 -0
- package/lib/codegen/generator.d.ts +4 -2
- package/lib/codegen/generator.d.ts.map +1 -1
- package/lib/codegen/generator.js +37 -75
- package/lib/codegen/generator.js.map +1 -1
- package/lib/codegen/generator.test.js +4 -9
- package/lib/codegen/generator.test.js.map +1 -1
- package/lib/codegen/graphql-client.d.ts.map +1 -1
- package/lib/codegen/graphql-client.js +12 -33
- package/lib/codegen/graphql-client.js.map +1 -1
- package/lib/codegen/graphql-client.test.js +4 -12
- package/lib/codegen/graphql-client.test.js.map +1 -1
- package/lib/codegen/graphql.d.ts.map +1 -1
- package/lib/codegen/graphql.js +7 -20
- package/lib/codegen/graphql.js.map +1 -1
- package/lib/codegen/model-diff.d.ts +10 -0
- package/lib/codegen/model-diff.d.ts.map +1 -0
- package/lib/codegen/model-diff.js +67 -0
- package/lib/codegen/model-diff.js.map +1 -0
- package/lib/codegen/naming.d.ts.map +1 -1
- package/lib/codegen/naming.js.map +1 -1
- package/lib/codegen/openapi-binary.test.js +1 -1
- package/lib/codegen/openapi-binary.test.js.map +1 -1
- package/lib/codegen/openapi-cli.d.ts +11 -11
- package/lib/codegen/openapi-cli.d.ts.map +1 -1
- package/lib/codegen/openapi-cli.js +26 -51
- package/lib/codegen/openapi-cli.js.map +1 -1
- package/lib/codegen/openapi.d.ts +9 -1
- package/lib/codegen/openapi.d.ts.map +1 -1
- package/lib/codegen/openapi.js +48 -42
- package/lib/codegen/openapi.js.map +1 -1
- package/lib/codegen/operations.d.ts.map +1 -1
- package/lib/codegen/operations.js.map +1 -1
- package/lib/codegen/pagination.d.ts.map +1 -1
- package/lib/codegen/pagination.js +2 -4
- package/lib/codegen/pagination.js.map +1 -1
- package/lib/codegen/patch-audit.d.ts +84 -0
- package/lib/codegen/patch-audit.d.ts.map +1 -0
- package/lib/codegen/patch-audit.js +366 -0
- package/lib/codegen/patch-audit.js.map +1 -0
- package/lib/codegen/patch-audit.test.d.ts +2 -0
- package/lib/codegen/patch-audit.test.d.ts.map +1 -0
- package/lib/codegen/patch-audit.test.js +141 -0
- package/lib/codegen/patch-audit.test.js.map +1 -0
- package/lib/codegen/patches.d.ts +59 -10
- package/lib/codegen/patches.d.ts.map +1 -1
- package/lib/codegen/patches.js +233 -63
- package/lib/codegen/patches.js.map +1 -1
- package/lib/codegen/patches.test.js +8 -4
- package/lib/codegen/patches.test.js.map +1 -1
- package/lib/codegen/prelude.js +1 -1
- package/lib/codegen/prelude.js.map +1 -1
- package/lib/codegen/proto.d.ts.map +1 -1
- package/lib/codegen/proto.js +2 -4
- package/lib/codegen/proto.js.map +1 -1
- package/lib/codegen/protocol-imports.test.d.ts +2 -0
- package/lib/codegen/protocol-imports.test.d.ts.map +1 -0
- package/lib/codegen/protocol-imports.test.js +36 -0
- package/lib/codegen/protocol-imports.test.js.map +1 -0
- package/lib/codegen/rewrite-operation-ids.d.ts +23 -0
- package/lib/codegen/rewrite-operation-ids.d.ts.map +1 -1
- package/lib/codegen/rewrite-operation-ids.js +97 -59
- package/lib/codegen/rewrite-operation-ids.js.map +1 -1
- package/lib/codegen/rewrite-operation-ids.test.js +19 -101
- package/lib/codegen/rewrite-operation-ids.test.js.map +1 -1
- package/lib/codegen/spec-path.d.ts +1 -1
- package/lib/codegen/spec-path.d.ts.map +1 -1
- package/lib/codegen/spec-path.js +1 -1
- package/lib/codegen/spec-path.js.map +1 -1
- package/lib/codegen/untagged-unions.test.js +1 -1
- package/lib/codegen/untagged-unions.test.js.map +1 -1
- package/lib/error-category.d.ts.map +1 -1
- package/lib/error-category.js.map +1 -1
- package/lib/errors.d.ts.map +1 -1
- package/lib/errors.js +7 -5
- package/lib/errors.js.map +1 -1
- package/lib/graphql.d.ts +4 -8
- package/lib/graphql.d.ts.map +1 -1
- package/lib/graphql.js +20 -48
- package/lib/graphql.js.map +1 -1
- package/lib/graphql.test.js +6 -6
- package/lib/graphql.test.js.map +1 -1
- package/lib/graphql.types.d.ts.map +1 -1
- package/lib/graphql.types.js.map +1 -1
- package/lib/json-patch.d.ts +13 -6
- package/lib/json-patch.d.ts.map +1 -1
- package/lib/json-patch.js +34 -19
- package/lib/json-patch.js.map +1 -1
- package/lib/json-patch.test.d.ts +2 -0
- package/lib/json-patch.test.d.ts.map +1 -0
- package/lib/json-patch.test.js +65 -0
- package/lib/json-patch.test.js.map +1 -0
- package/lib/pagination.d.ts.map +1 -1
- package/lib/pagination.js +6 -16
- package/lib/pagination.js.map +1 -1
- package/lib/pagination.test.js +3 -6
- package/lib/pagination.test.js.map +1 -1
- package/lib/protocol-http.d.ts +20 -1
- package/lib/protocol-http.d.ts.map +1 -1
- package/lib/protocol-http.js +41 -47
- package/lib/protocol-http.js.map +1 -1
- package/lib/protocol-http.test.js +20 -10
- package/lib/protocol-http.test.js.map +1 -1
- package/lib/protocol-rest.d.ts.map +1 -1
- package/lib/protocol-rest.js +9 -18
- package/lib/protocol-rest.js.map +1 -1
- package/lib/protocol-rest.test.d.ts +2 -0
- package/lib/protocol-rest.test.d.ts.map +1 -0
- package/lib/protocol-rest.test.js +498 -0
- package/lib/protocol-rest.test.js.map +1 -0
- package/lib/response-validation.d.ts.map +1 -1
- package/lib/response-validation.js.map +1 -1
- package/lib/response-validation.test.js +10 -5
- package/lib/response-validation.test.js.map +1 -1
- package/lib/retry-after.d.ts.map +1 -1
- package/lib/retry-after.js +1 -1
- package/lib/retry-after.js.map +1 -1
- package/lib/retry-after.test.d.ts +2 -0
- package/lib/retry-after.test.d.ts.map +1 -0
- package/lib/retry-after.test.js +204 -0
- package/lib/retry-after.test.js.map +1 -0
- package/lib/retry.d.ts.map +1 -1
- package/lib/retry.js +1 -2
- package/lib/retry.js.map +1 -1
- package/lib/retry.test.d.ts +2 -0
- package/lib/retry.test.d.ts.map +1 -0
- package/lib/retry.test.js +407 -0
- package/lib/retry.test.js.map +1 -0
- package/lib/sdks.test.d.ts +2 -0
- package/lib/sdks.test.d.ts.map +1 -0
- package/lib/sdks.test.js +76 -0
- package/lib/sdks.test.js.map +1 -0
- package/lib/testing.d.ts +2 -2
- package/lib/testing.d.ts.map +1 -1
- package/lib/testing.js +1 -1
- package/lib/testing.js.map +1 -1
- package/lib/trait.d.ts.map +1 -1
- package/lib/trait.js.map +1 -1
- package/lib/xml.d.ts.map +1 -1
- package/lib/xml.js +3 -7
- package/lib/xml.js.map +1 -1
- package/lib/xml.test.js +11 -12
- package/lib/xml.test.js.map +1 -1
- package/package.json +7 -10
- package/src/api.ts +38 -55
- package/src/category.ts +21 -50
- package/src/codegen/boolean-string-enums.test.ts +12 -28
- package/src/codegen/boolean-string-enums.ts +2 -10
- package/src/codegen/cli.ts +29 -47
- package/src/codegen/defer-naming.test.ts +113 -0
- package/src/codegen/emit.ts +2 -5
- package/src/codegen/format.ts +12 -10
- package/src/codegen/generated-at.test.ts +89 -0
- package/src/codegen/generated-at.ts +88 -0
- package/src/codegen/generator.test.ts +8 -22
- package/src/codegen/generator.ts +72 -191
- package/src/codegen/graphql-client.test.ts +12 -42
- package/src/codegen/graphql-client.ts +30 -95
- package/src/codegen/graphql.ts +22 -94
- package/src/codegen/model-diff.ts +67 -0
- package/src/codegen/naming.ts +1 -2
- package/src/codegen/openapi-binary.test.ts +5 -12
- package/src/codegen/openapi-cli.ts +38 -79
- package/src/codegen/openapi.ts +79 -136
- package/src/codegen/operations.ts +2 -5
- package/src/codegen/pagination.ts +4 -11
- package/src/codegen/patch-audit.test.ts +160 -0
- package/src/codegen/patch-audit.ts +480 -0
- package/src/codegen/patches.test.ts +14 -21
- package/src/codegen/patches.ts +313 -103
- package/src/codegen/prelude.ts +1 -1
- package/src/codegen/proto.ts +18 -54
- package/src/codegen/protocol-imports.test.ts +39 -0
- package/src/codegen/rewrite-operation-ids.test.ts +23 -114
- package/src/codegen/rewrite-operation-ids.ts +111 -98
- package/src/codegen/spec-path.ts +3 -6
- package/src/codegen/untagged-unions.test.ts +3 -7
- package/src/error-category.ts +5 -17
- package/src/errors.ts +16 -31
- package/src/graphql.test.ts +6 -8
- package/src/graphql.ts +76 -219
- package/src/graphql.types.ts +10 -25
- package/src/json-patch.test.ts +77 -0
- package/src/json-patch.ts +54 -60
- package/src/pagination.test.ts +13 -35
- package/src/pagination.ts +44 -111
- package/src/protocol-http.test.ts +36 -30
- package/src/protocol-http.ts +73 -138
- package/src/protocol-rest.test.ts +703 -0
- package/src/protocol-rest.ts +24 -62
- package/src/response-validation.test.ts +12 -18
- package/src/response-validation.ts +3 -12
- package/src/retry-after.test.ts +267 -0
- package/src/retry-after.ts +4 -10
- package/src/retry.test.ts +566 -0
- package/src/retry.ts +6 -21
- package/src/sdks.test.ts +87 -0
- package/src/testing.ts +4 -10
- package/src/trait.ts +21 -67
- package/src/xml.test.ts +15 -33
- package/src/xml.ts +9 -25
package/src/protocol-http.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import * as HttpBody from "effect/http/HttpBody";
|
|
2
|
+
import * as HttpClientRequest from "effect/http/HttpClientRequest";
|
|
1
3
|
/**
|
|
2
4
|
* Generic REST protocol machinery, shared by SDK protocol layers.
|
|
3
5
|
*
|
|
@@ -9,8 +11,6 @@
|
|
|
9
11
|
* {@link matchTypedError}).
|
|
10
12
|
*/
|
|
11
13
|
import type * as AST from "effect/SchemaAST";
|
|
12
|
-
import * as HttpBody from "effect/http/HttpBody";
|
|
13
|
-
import * as HttpClientRequest from "effect/http/HttpClientRequest";
|
|
14
14
|
import {
|
|
15
15
|
bodySymbol,
|
|
16
16
|
deepQuerySymbol,
|
|
@@ -37,39 +37,29 @@ import {
|
|
|
37
37
|
export const getProps = (ast: AST.AST): readonly AST.PropertySignature[] => {
|
|
38
38
|
if (ast._tag === "Objects") return ast.propertySignatures;
|
|
39
39
|
if (ast._tag === "Suspend") return getProps(ast.thunk());
|
|
40
|
-
if (ast.encoding && ast.encoding.length > 0)
|
|
41
|
-
return getProps(ast.encoding[0]!.to);
|
|
40
|
+
if (ast.encoding && ast.encoding.length > 0) return getProps(ast.encoding[0]!.to);
|
|
42
41
|
return [];
|
|
43
42
|
};
|
|
44
43
|
|
|
45
44
|
export const getAnn = (ast: AST.AST, symbol: symbol): unknown => {
|
|
46
|
-
const direct = (ast.annotations as Record<symbol, unknown> | undefined)?.[
|
|
47
|
-
symbol
|
|
48
|
-
];
|
|
45
|
+
const direct = (ast.annotations as Record<symbol, unknown> | undefined)?.[symbol];
|
|
49
46
|
if (direct !== undefined) return direct;
|
|
50
47
|
if (ast._tag === "Suspend") return getAnn(ast.thunk(), symbol);
|
|
51
|
-
if (ast.encoding && ast.encoding.length > 0)
|
|
52
|
-
return getAnn(ast.encoding[0]!.to, symbol);
|
|
48
|
+
if (ast.encoding && ast.encoding.length > 0) return getAnn(ast.encoding[0]!.to, symbol);
|
|
53
49
|
// S.optional → Union[self, Undefined]; descend into the single real member.
|
|
54
50
|
if (ast._tag === "Union") {
|
|
55
51
|
const real = (ast as AST.Union).types.filter(
|
|
56
|
-
(t) =>
|
|
57
|
-
t._tag !== "Undefined" &&
|
|
58
|
-
!(t._tag === "Literal" && (t as any).literal === null),
|
|
52
|
+
(t) => t._tag !== "Undefined" && !(t._tag === "Literal" && (t as any).literal === null),
|
|
59
53
|
);
|
|
60
54
|
if (real.length === 1) return getAnn(real[0]!, symbol);
|
|
61
55
|
}
|
|
62
56
|
return undefined;
|
|
63
57
|
};
|
|
64
58
|
|
|
65
|
-
export const getPropAnn = (
|
|
66
|
-
prop
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
export const hasPropAnn = (
|
|
70
|
-
prop: AST.PropertySignature,
|
|
71
|
-
symbol: symbol,
|
|
72
|
-
): boolean => getPropAnn(prop, symbol) !== undefined;
|
|
59
|
+
export const getPropAnn = (prop: AST.PropertySignature, symbol: symbol): unknown =>
|
|
60
|
+
getAnn(prop.type, symbol);
|
|
61
|
+
export const hasPropAnn = (prop: AST.PropertySignature, symbol: symbol): boolean =>
|
|
62
|
+
getPropAnn(prop, symbol) !== undefined;
|
|
73
63
|
export const nameOf = (prop: AST.PropertySignature, symbol: symbol): string => {
|
|
74
64
|
const v = getPropAnn(prop, symbol);
|
|
75
65
|
return typeof v === "string" ? v : String(prop.name);
|
|
@@ -78,8 +68,7 @@ export const nameOf = (prop: AST.PropertySignature, symbol: symbol): string => {
|
|
|
78
68
|
/** Resolve wrappers to the real node: Suspend, encoding, optional/null unions. */
|
|
79
69
|
export const resolveNode = (ast: AST.AST): AST.AST => {
|
|
80
70
|
if (ast._tag === "Suspend") return resolveNode(ast.thunk());
|
|
81
|
-
if (ast.encoding && ast.encoding.length > 0)
|
|
82
|
-
return resolveNode(ast.encoding[0]!.to);
|
|
71
|
+
if (ast.encoding && ast.encoding.length > 0) return resolveNode(ast.encoding[0]!.to);
|
|
83
72
|
if (ast._tag === "Union") {
|
|
84
73
|
const real = (ast as AST.Union).types.filter(
|
|
85
74
|
(t) =>
|
|
@@ -123,9 +112,7 @@ export const mapKeysByDictionary = (
|
|
|
123
112
|
direction === "decode"
|
|
124
113
|
? Object.fromEntries(
|
|
125
114
|
Object.entries(dict).flatMap(([ts, wire]) =>
|
|
126
|
-
typeof wire === "string"
|
|
127
|
-
? [[wire, ts] as const]
|
|
128
|
-
: wire.map((w) => [w, ts] as const),
|
|
115
|
+
typeof wire === "string" ? [[wire, ts] as const] : wire.map((w) => [w, ts] as const),
|
|
129
116
|
),
|
|
130
117
|
)
|
|
131
118
|
: Object.fromEntries(
|
|
@@ -157,11 +144,7 @@ export const mapKeysByDictionary = (
|
|
|
157
144
|
* flag as `"true" | "false"` still means "unset" by null, not `"null"`.
|
|
158
145
|
*/
|
|
159
146
|
const stringEncode = (value: unknown): unknown =>
|
|
160
|
-
value === null
|
|
161
|
-
? null
|
|
162
|
-
: Array.isArray(value)
|
|
163
|
-
? value.map(stringEncode)
|
|
164
|
-
: String(value);
|
|
147
|
+
value === null ? null : Array.isArray(value) ? value.map(stringEncode) : String(value);
|
|
165
148
|
|
|
166
149
|
export const mapKeys = (
|
|
167
150
|
ast: AST.AST,
|
|
@@ -169,17 +152,10 @@ export const mapKeys = (
|
|
|
169
152
|
direction: "encode" | "decode",
|
|
170
153
|
fallback?: KeyDictionaryEntries,
|
|
171
154
|
): unknown => {
|
|
172
|
-
if (
|
|
173
|
-
value === null ||
|
|
174
|
-
value === undefined ||
|
|
175
|
-
typeof value !== "object" ||
|
|
176
|
-
isOpaqueValue(value)
|
|
177
|
-
) {
|
|
155
|
+
if (value === null || value === undefined || typeof value !== "object" || isOpaqueValue(value)) {
|
|
178
156
|
return value;
|
|
179
157
|
}
|
|
180
|
-
const dict =
|
|
181
|
-
(getAnn(ast, keyDictionarySymbol) as KeyDictionaryEntries | undefined) ??
|
|
182
|
-
fallback;
|
|
158
|
+
const dict = (getAnn(ast, keyDictionarySymbol) as KeyDictionaryEntries | undefined) ?? fallback;
|
|
183
159
|
|
|
184
160
|
// Discriminated union whose cases the API returns merged (every case's
|
|
185
161
|
// keys present, `null` for the inactive ones). Map wire names, then keep
|
|
@@ -198,18 +174,15 @@ export const mapKeys = (
|
|
|
198
174
|
}
|
|
199
175
|
| undefined;
|
|
200
176
|
if (unionCases && direction === "decode" && !Array.isArray(value)) {
|
|
201
|
-
const obj = (
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
);
|
|
177
|
+
const obj = (dict ? mapKeysByDictionary(dict, value, "decode") : value) as Record<
|
|
178
|
+
string,
|
|
179
|
+
unknown
|
|
180
|
+
>;
|
|
181
|
+
const present = Object.keys(obj).filter((k) => obj[k] !== undefined && obj[k] !== null);
|
|
207
182
|
const disc = unionCases.discriminator;
|
|
208
183
|
const tag = disc ? obj[disc.key] : undefined;
|
|
209
184
|
const tagged = typeof tag === "string" ? disc!.values.indexOf(tag) : -1;
|
|
210
|
-
let best:
|
|
211
|
-
| { keys: ReadonlyArray<string>; score: number; matched: number }
|
|
212
|
-
| undefined;
|
|
185
|
+
let best: { keys: ReadonlyArray<string>; score: number; matched: number } | undefined;
|
|
213
186
|
if (tagged >= 0) {
|
|
214
187
|
best = { keys: unionCases.cases[tagged]!, score: 0, matched: 0 };
|
|
215
188
|
} else {
|
|
@@ -224,9 +197,7 @@ export const mapKeys = (
|
|
|
224
197
|
const score = matched - excess;
|
|
225
198
|
if (
|
|
226
199
|
matched > 0 &&
|
|
227
|
-
(!best ||
|
|
228
|
-
score > best.score ||
|
|
229
|
-
(score === best.score && matched > best.matched))
|
|
200
|
+
(!best || score > best.score || (score === best.score && matched > best.matched))
|
|
230
201
|
) {
|
|
231
202
|
best = { keys, score, matched };
|
|
232
203
|
}
|
|
@@ -262,10 +233,8 @@ export const mapKeys = (
|
|
|
262
233
|
for (const t of arms) {
|
|
263
234
|
if (t._tag !== "Objects") continue;
|
|
264
235
|
let score = 0;
|
|
265
|
-
for (const p of (t as any)
|
|
266
|
-
|
|
267
|
-
const from =
|
|
268
|
-
direction === "encode" ? String(p.name) : nameOf(p, bodySymbol);
|
|
236
|
+
for (const p of (t as any).propertySignatures as readonly AST.PropertySignature[]) {
|
|
237
|
+
const from = direction === "encode" ? String(p.name) : nameOf(p, bodySymbol);
|
|
269
238
|
if ((value as Record<string, unknown>)[from] !== undefined) score++;
|
|
270
239
|
}
|
|
271
240
|
if (score > bestScore) {
|
|
@@ -289,11 +258,8 @@ export const mapKeys = (
|
|
|
289
258
|
}
|
|
290
259
|
|
|
291
260
|
if (node._tag === "Objects" && !Array.isArray(value)) {
|
|
292
|
-
const props = (node as any)
|
|
293
|
-
|
|
294
|
-
const isigs = (node as any).indexSignatures as
|
|
295
|
-
| readonly { type: AST.AST }[]
|
|
296
|
-
| undefined;
|
|
261
|
+
const props = (node as any).propertySignatures as readonly AST.PropertySignature[];
|
|
262
|
+
const isigs = (node as any).indexSignatures as readonly { type: AST.AST }[] | undefined;
|
|
297
263
|
if (props.length === 0 && !(isigs && isigs.length)) {
|
|
298
264
|
// opaque object — dictionary fallback or verbatim
|
|
299
265
|
return dict ? mapKeysByDictionary(dict, value, direction) : value;
|
|
@@ -354,18 +320,10 @@ const BODYLESS = new Set(["GET", "HEAD"]);
|
|
|
354
320
|
* filter matching nothing — the call "succeeds" with zero results and the
|
|
355
321
|
* bug is invisible to the caller.
|
|
356
322
|
*/
|
|
357
|
-
const appendQuery = (
|
|
358
|
-
query: URLSearchParams,
|
|
359
|
-
name: string,
|
|
360
|
-
value: unknown,
|
|
361
|
-
): void => {
|
|
323
|
+
const appendQuery = (query: URLSearchParams, name: string, value: unknown): void => {
|
|
362
324
|
if (Array.isArray(value)) {
|
|
363
325
|
for (const v of value) appendQuery(query, name, v);
|
|
364
|
-
} else if (
|
|
365
|
-
value !== null &&
|
|
366
|
-
typeof value === "object" &&
|
|
367
|
-
!(value instanceof Date)
|
|
368
|
-
) {
|
|
326
|
+
} else if (value !== null && typeof value === "object" && !(value instanceof Date)) {
|
|
369
327
|
for (const [k, v] of Object.entries(value as Record<string, unknown>)) {
|
|
370
328
|
if (v !== undefined) appendQuery(query, `${name}.${k}`, v);
|
|
371
329
|
}
|
|
@@ -406,15 +364,21 @@ export interface BuildRequestOptions {
|
|
|
406
364
|
* Throws when the input schema is missing the `Http()` trait — a codegen
|
|
407
365
|
* bug, surfaced as a defect by the calling protocol's Effect context.
|
|
408
366
|
*/
|
|
367
|
+
/**
|
|
368
|
+
* Encode a greedy `{name+}` label: the value may span several path
|
|
369
|
+
* segments (e.g. an Azure scope `/subscriptions/{id}/resourceGroups/{rg}`),
|
|
370
|
+
* so each segment is encoded on its own and the `/` separators are kept.
|
|
371
|
+
* Leading slashes are dropped because the URI template already supplies one.
|
|
372
|
+
*/
|
|
373
|
+
export const encodeGreedyLabel = (value: string): string =>
|
|
374
|
+
value.replace(/^\/+/, "").split("/").map(encodeURIComponent).join("/");
|
|
375
|
+
|
|
409
376
|
/**
|
|
410
377
|
* Flatten a nested object into Stripe-style bracket notation pairs for
|
|
411
378
|
* form-urlencoded bodies: nested objects become `a[b][c]`, arrays index as
|
|
412
379
|
* `a[0]`; null/undefined dropped, booleans as "true"/"false".
|
|
413
380
|
*/
|
|
414
|
-
const flattenToFormPairs = (
|
|
415
|
-
obj: Record<string, unknown>,
|
|
416
|
-
prefix = "",
|
|
417
|
-
): Array<[string, string]> => {
|
|
381
|
+
const flattenToFormPairs = (obj: Record<string, unknown>, prefix = ""): Array<[string, string]> => {
|
|
418
382
|
const pairs: Array<[string, string]> = [];
|
|
419
383
|
for (const [key, value] of Object.entries(obj)) {
|
|
420
384
|
if (value === undefined || value === null) continue;
|
|
@@ -424,20 +388,13 @@ const flattenToFormPairs = (
|
|
|
424
388
|
const item = value[i];
|
|
425
389
|
if (item === undefined || item === null) continue;
|
|
426
390
|
if (typeof item === "object" && !Array.isArray(item)) {
|
|
427
|
-
pairs.push(
|
|
428
|
-
...flattenToFormPairs(
|
|
429
|
-
item as Record<string, unknown>,
|
|
430
|
-
`${fullKey}[${i}]`,
|
|
431
|
-
),
|
|
432
|
-
);
|
|
391
|
+
pairs.push(...flattenToFormPairs(item as Record<string, unknown>, `${fullKey}[${i}]`));
|
|
433
392
|
} else {
|
|
434
393
|
pairs.push([`${fullKey}[${i}]`, String(item)]);
|
|
435
394
|
}
|
|
436
395
|
}
|
|
437
396
|
} else if (typeof value === "object") {
|
|
438
|
-
pairs.push(
|
|
439
|
-
...flattenToFormPairs(value as Record<string, unknown>, fullKey),
|
|
440
|
-
);
|
|
397
|
+
pairs.push(...flattenToFormPairs(value as Record<string, unknown>, fullKey));
|
|
441
398
|
} else {
|
|
442
399
|
pairs.push([fullKey, String(value)]);
|
|
443
400
|
}
|
|
@@ -460,9 +417,7 @@ export const buildRequest = ({
|
|
|
460
417
|
}
|
|
461
418
|
// Root key dictionary: fallback wire mapping for opaque/unknown content
|
|
462
419
|
// the schema doesn't model.
|
|
463
|
-
const rootDict = getAnn(inputAst, keyDictionarySymbol) as
|
|
464
|
-
| KeyDictionaryEntries
|
|
465
|
-
| undefined;
|
|
420
|
+
const rootDict = getAnn(inputAst, keyDictionarySymbol) as KeyDictionaryEntries | undefined;
|
|
466
421
|
|
|
467
422
|
const headers: Record<string, string> = { ...baseHeaders };
|
|
468
423
|
const body: Record<string, unknown> = {};
|
|
@@ -472,6 +427,9 @@ export const buildRequest = ({
|
|
|
472
427
|
let uri = http.uri;
|
|
473
428
|
const consumed = new Set<string>();
|
|
474
429
|
let hasBodyMembers = false;
|
|
430
|
+
// Value of a modeled `Content-Type` header member, e.g. R2 putObject's
|
|
431
|
+
// `contentType`. A raw body is sent under it (see below).
|
|
432
|
+
let memberContentType: string | undefined;
|
|
475
433
|
|
|
476
434
|
for (const prop of getProps(inputAst)) {
|
|
477
435
|
const key = String(prop.name);
|
|
@@ -492,17 +450,18 @@ export const buildRequest = ({
|
|
|
492
450
|
const label =
|
|
493
451
|
typeof preserve === "string"
|
|
494
452
|
? encoded.replace(/%[0-9A-F]{2}/g, (escape) => {
|
|
495
|
-
const character = String.fromCharCode(
|
|
496
|
-
Number.parseInt(escape.slice(1), 16),
|
|
497
|
-
);
|
|
453
|
+
const character = String.fromCharCode(Number.parseInt(escape.slice(1), 16));
|
|
498
454
|
return preserve.includes(character) ? character : escape;
|
|
499
455
|
})
|
|
500
456
|
: encoded;
|
|
501
|
-
uri = uri.
|
|
457
|
+
uri = uri.includes(`{${token}+}`)
|
|
458
|
+
? uri.replace(`{${token}+}`, () => encodeGreedyLabel(String(value)))
|
|
459
|
+
: uri.replace(`{${token}}`, () => label);
|
|
502
460
|
} else if (hasPropAnn(prop, headerSymbol)) {
|
|
503
461
|
const hName = nameOf(prop, headerSymbol).toLowerCase();
|
|
504
462
|
const hVal = String(value);
|
|
505
463
|
headers[hName] = mapMemberHeader ? mapMemberHeader(hName, hVal) : hVal;
|
|
464
|
+
if (hName === "content-type") memberContentType = headers[hName];
|
|
506
465
|
} else if (hasPropAnn(prop, querySymbol)) {
|
|
507
466
|
appendQuery(query, nameOf(prop, querySymbol), value);
|
|
508
467
|
} else if (hasPropAnn(prop, deepQuerySymbol)) {
|
|
@@ -513,9 +472,7 @@ export const buildRequest = ({
|
|
|
513
472
|
const base = nameOf(prop, deepQuerySymbol);
|
|
514
473
|
const mapped = mapKeys(prop.type, value, "encode", rootDict);
|
|
515
474
|
if (mapped !== null && typeof mapped === "object") {
|
|
516
|
-
for (const [k, v] of Object.entries(
|
|
517
|
-
mapped as Record<string, unknown>,
|
|
518
|
-
)) {
|
|
475
|
+
for (const [k, v] of Object.entries(mapped as Record<string, unknown>)) {
|
|
519
476
|
if (v !== undefined && v !== null) {
|
|
520
477
|
appendQuery(query, `${base}.${k}`, v);
|
|
521
478
|
}
|
|
@@ -544,8 +501,7 @@ export const buildRequest = ({
|
|
|
544
501
|
// the key, otherwise `unknownKeyToWire` decides the wire name.
|
|
545
502
|
for (const [key, value] of Object.entries(inputObj)) {
|
|
546
503
|
if (consumed.has(key) || value === undefined) continue;
|
|
547
|
-
const wire =
|
|
548
|
-
rootDict?.[key] ?? (unknownKeyToWire ? unknownKeyToWire(key) : key);
|
|
504
|
+
const wire = rootDict?.[key] ?? (unknownKeyToWire ? unknownKeyToWire(key) : key);
|
|
549
505
|
body[typeof wire === "string" ? wire : wire[0]] = rootDict
|
|
550
506
|
? mapKeysByDictionary(rootDict, value, "encode")
|
|
551
507
|
: value;
|
|
@@ -572,21 +528,15 @@ export const buildRequest = ({
|
|
|
572
528
|
rawBody !== undefined && typeof rawBody === "object"
|
|
573
529
|
? (rawBody as Record<string, unknown>)
|
|
574
530
|
: body;
|
|
575
|
-
const isFileOrBlob = (v: unknown): v is Blob =>
|
|
576
|
-
v instanceof Blob || v instanceof File;
|
|
531
|
+
const isFileOrBlob = (v: unknown): v is Blob => v instanceof Blob || v instanceof File;
|
|
577
532
|
for (const [key, value] of Object.entries(parts)) {
|
|
578
533
|
if (value === undefined || value === null) continue;
|
|
579
534
|
if (isFileOrBlob(value)) {
|
|
580
535
|
form.append(key, value, value instanceof File ? value.name : key);
|
|
581
536
|
} else if (value instanceof Uint8Array || value instanceof ArrayBuffer) {
|
|
582
|
-
const bytes =
|
|
583
|
-
value instanceof Uint8Array ? new Uint8Array(value).buffer : value;
|
|
537
|
+
const bytes = value instanceof Uint8Array ? new Uint8Array(value).buffer : value;
|
|
584
538
|
form.append(key, new Blob([bytes]), key);
|
|
585
|
-
} else if (
|
|
586
|
-
Array.isArray(value) &&
|
|
587
|
-
value.length > 0 &&
|
|
588
|
-
isFileOrBlob(value[0])
|
|
589
|
-
) {
|
|
539
|
+
} else if (Array.isArray(value) && value.length > 0 && isFileOrBlob(value[0])) {
|
|
590
540
|
for (const file of value as Blob[]) {
|
|
591
541
|
if (isFileOrBlob(file)) {
|
|
592
542
|
form.append(
|
|
@@ -607,10 +557,7 @@ export const buildRequest = ({
|
|
|
607
557
|
form.append(filename, f, filename);
|
|
608
558
|
}
|
|
609
559
|
request = request.pipe(HttpClientRequest.bodyFormData(form));
|
|
610
|
-
} else if (
|
|
611
|
-
http.contentType === "form-urlencoded" &&
|
|
612
|
-
!BODYLESS.has(http.method)
|
|
613
|
-
) {
|
|
560
|
+
} else if (http.contentType === "form-urlencoded" && !BODYLESS.has(http.method)) {
|
|
614
561
|
// application/x-www-form-urlencoded with Stripe-style deepObject bracket
|
|
615
562
|
// notation: { shipping: { address: { city } } } → shipping[address][city],
|
|
616
563
|
// arrays indexed ({ expand: ["a"] } → expand[0]=a).
|
|
@@ -628,33 +575,28 @@ export const buildRequest = ({
|
|
|
628
575
|
} else if (rawBody !== undefined && !BODYLESS.has(http.method)) {
|
|
629
576
|
// Whole-body member (raw arrays/scalars) — sent as the body itself.
|
|
630
577
|
// Binary payloads (Blob / ArrayBuffer / Uint8Array) send verbatim
|
|
631
|
-
// (raw object uploads
|
|
632
|
-
//
|
|
633
|
-
//
|
|
634
|
-
//
|
|
635
|
-
//
|
|
578
|
+
// (raw object uploads). With a bodyMediaType, the member is a
|
|
579
|
+
// preserialized payload (string / bytes) sent verbatim; otherwise it's
|
|
580
|
+
// JSON.
|
|
581
|
+
//
|
|
582
|
+
// `setBody` overwrites the Content-Type header with the body's media
|
|
583
|
+
// type (and removes it when that is undefined), so the body carries the
|
|
584
|
+
// modeled Content-Type member when the caller set one, else the declared
|
|
585
|
+
// bodyMediaType (e.g. application/x-ndjson for Vectorize insert/upsert).
|
|
586
|
+
const mediaType = memberContentType ?? http.bodyMediaType;
|
|
636
587
|
if (rawBody instanceof Blob || rawBody instanceof ArrayBuffer) {
|
|
637
|
-
//
|
|
638
|
-
// Vectorize insert/upsert) — without it the server may fall back to
|
|
639
|
-
// JSON parsing. When no bodyMediaType is modeled the header is left
|
|
640
|
-
// untouched (a modeled Content-Type header member rides alongside).
|
|
588
|
+
// With no media type at all, fetch falls back to the Blob's own type.
|
|
641
589
|
request = request.pipe(
|
|
642
|
-
HttpClientRequest.setBody(
|
|
643
|
-
HttpBody.raw(rawBody, { contentType: http.bodyMediaType }),
|
|
644
|
-
),
|
|
590
|
+
HttpClientRequest.setBody(HttpBody.raw(rawBody, { contentType: mediaType })),
|
|
645
591
|
);
|
|
646
592
|
} else if (rawBody instanceof Uint8Array) {
|
|
647
|
-
request = request.pipe(
|
|
648
|
-
HttpClientRequest.setBody(
|
|
649
|
-
HttpBody.uint8Array(rawBody, http.bodyMediaType),
|
|
650
|
-
),
|
|
651
|
-
);
|
|
593
|
+
request = request.pipe(HttpClientRequest.setBody(HttpBody.uint8Array(rawBody, mediaType)));
|
|
652
594
|
} else if (http.bodyMediaType) {
|
|
653
595
|
request = request.pipe(
|
|
654
596
|
HttpClientRequest.setBody(
|
|
655
597
|
typeof rawBody === "string"
|
|
656
|
-
? HttpBody.text(rawBody,
|
|
657
|
-
: HttpBody.uint8Array(rawBody as Uint8Array,
|
|
598
|
+
? HttpBody.text(rawBody, mediaType)
|
|
599
|
+
: HttpBody.uint8Array(rawBody as Uint8Array, mediaType),
|
|
658
600
|
),
|
|
659
601
|
);
|
|
660
602
|
} else {
|
|
@@ -747,10 +689,7 @@ export const matchesExpression = (
|
|
|
747
689
|
if (m.body !== undefined) {
|
|
748
690
|
for (const [pointer, expected] of Object.entries(m.body)) {
|
|
749
691
|
const actual = atPointer(response.body, pointer);
|
|
750
|
-
if (
|
|
751
|
-
typeof expected === "string" ||
|
|
752
|
-
(expected !== null && typeof expected === "object")
|
|
753
|
-
) {
|
|
692
|
+
if (typeof expected === "string" || (expected !== null && typeof expected === "object")) {
|
|
754
693
|
if (!matchesText(expected, actual)) return false;
|
|
755
694
|
} else if (actual !== expected) return false;
|
|
756
695
|
}
|
|
@@ -781,18 +720,14 @@ export const matchTypedError = (
|
|
|
781
720
|
errors: ReadonlyArray<{ code?: number; message: string }>,
|
|
782
721
|
response: ErrorResponse = {},
|
|
783
722
|
): unknown | undefined => {
|
|
784
|
-
let best:
|
|
785
|
-
|
|
786
|
-
| undefined;
|
|
787
|
-
const wireErrors =
|
|
788
|
-
errors.length > 0 ? errors : [{ message: `HTTP ${status}` }];
|
|
723
|
+
let best: { cls: unknown; specificity: number; code?: number; message: string } | undefined;
|
|
724
|
+
const wireErrors = errors.length > 0 ? errors : [{ message: `HTTP ${status}` }];
|
|
789
725
|
for (const cls of errorClasses) {
|
|
790
726
|
const matchers = getErrorMatchers(cls);
|
|
791
727
|
if (!matchers) continue;
|
|
792
728
|
for (const m of matchers) {
|
|
793
729
|
for (const e of wireErrors) {
|
|
794
|
-
if (!matchesExpression(m, e.code, status, e.message, response))
|
|
795
|
-
continue;
|
|
730
|
+
if (!matchesExpression(m, e.code, status, e.message, response)) continue;
|
|
796
731
|
const specificity = matcherSpecificity(m);
|
|
797
732
|
if (!best || specificity > best.specificity) {
|
|
798
733
|
best = { cls, specificity, code: e.code, message: e.message };
|