@distilled.cloud/core 1.0.0-rc.14 → 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.
- package/lib/api.d.ts +118 -13
- package/lib/api.d.ts.map +1 -1
- package/lib/api.js +755 -147
- package/lib/api.js.map +1 -1
- package/lib/category.d.ts.map +1 -1
- package/lib/category.js +146 -146
- package/lib/category.js.map +1 -1
- package/lib/chunks.d.ts +3 -0
- package/lib/chunks.d.ts.map +1 -0
- package/lib/chunks.js +11 -0
- package/lib/chunks.js.map +1 -0
- package/lib/codegen/boolean-string-enums.js +36 -36
- package/lib/codegen/chunk.d.ts +7 -0
- package/lib/codegen/chunk.d.ts.map +1 -0
- package/lib/codegen/chunk.js +139 -0
- package/lib/codegen/chunk.js.map +1 -0
- package/lib/codegen/cli.d.ts.map +1 -1
- package/lib/codegen/cli.js +28 -14
- package/lib/codegen/cli.js.map +1 -1
- package/lib/codegen/datafy.d.ts +14 -0
- package/lib/codegen/datafy.d.ts.map +1 -0
- package/lib/codegen/datafy.js +853 -0
- package/lib/codegen/datafy.js.map +1 -0
- package/lib/codegen/dedupe.d.ts +5 -0
- package/lib/codegen/dedupe.d.ts.map +1 -0
- package/lib/codegen/dedupe.js +153 -0
- package/lib/codegen/dedupe.js.map +1 -0
- package/lib/codegen/emit.js +56 -56
- package/lib/codegen/format.js +18 -18
- package/lib/codegen/generated-at.js +29 -29
- package/lib/codegen/generator.d.ts.map +1 -1
- package/lib/codegen/generator.js +92 -84
- package/lib/codegen/generator.js.map +1 -1
- package/lib/codegen/graph.js +36 -36
- package/lib/codegen/graphql-client.d.ts +2 -0
- package/lib/codegen/graphql-client.d.ts.map +1 -1
- package/lib/codegen/graphql-client.js +55 -26
- package/lib/codegen/graphql-client.js.map +1 -1
- package/lib/codegen/graphql.js +113 -113
- package/lib/codegen/latin1.d.ts +3 -0
- package/lib/codegen/latin1.d.ts.map +1 -0
- package/lib/codegen/latin1.js +126 -0
- package/lib/codegen/latin1.js.map +1 -0
- package/lib/codegen/members.d.ts +7 -0
- package/lib/codegen/members.d.ts.map +1 -1
- package/lib/codegen/members.js +26 -19
- package/lib/codegen/members.js.map +1 -1
- package/lib/codegen/model-diff.js +6 -6
- package/lib/codegen/naming.js +19 -19
- package/lib/codegen/openapi-cli.js +15 -15
- package/lib/codegen/openapi.d.ts +17 -0
- package/lib/codegen/openapi.d.ts.map +1 -1
- package/lib/codegen/openapi.js +323 -169
- package/lib/codegen/openapi.js.map +1 -1
- package/lib/codegen/operations.js +14 -14
- package/lib/codegen/pagination.js +11 -11
- package/lib/codegen/patch-audit.js +57 -57
- package/lib/codegen/patches.js +79 -79
- package/lib/codegen/prelude.js +19 -19
- package/lib/codegen/privatize.d.ts +21 -0
- package/lib/codegen/privatize.d.ts.map +1 -0
- package/lib/codegen/privatize.js +176 -0
- package/lib/codegen/privatize.js.map +1 -0
- package/lib/codegen/proto.js +25 -25
- package/lib/codegen/pure.d.ts +6 -0
- package/lib/codegen/pure.d.ts.map +1 -0
- package/lib/codegen/pure.js +91 -0
- package/lib/codegen/pure.js.map +1 -0
- package/lib/codegen/rewrite-operation-ids.js +108 -108
- package/lib/codegen/spec-path.js +57 -57
- package/lib/codegen/table.d.ts +5 -0
- package/lib/codegen/table.d.ts.map +1 -0
- package/lib/codegen/table.js +249 -0
- package/lib/codegen/table.js.map +1 -0
- package/lib/config.d.ts +27 -0
- package/lib/config.d.ts.map +1 -0
- package/lib/config.js +161 -0
- package/lib/config.js.map +1 -0
- package/lib/crypto.d.ts +76 -0
- package/lib/crypto.d.ts.map +1 -0
- package/lib/crypto.js +130 -0
- package/lib/crypto.js.map +1 -0
- package/lib/debug.d.ts +2 -0
- package/lib/debug.d.ts.map +1 -0
- package/lib/debug.js +8 -0
- package/lib/debug.js.map +1 -0
- package/lib/error-category.d.ts +1 -1
- package/lib/error-category.d.ts.map +1 -1
- package/lib/error-category.js +7 -6
- package/lib/error-category.js.map +1 -1
- package/lib/errors.d.ts +62 -62
- package/lib/errors.d.ts.map +1 -1
- package/lib/errors.js +117 -114
- package/lib/errors.js.map +1 -1
- package/lib/graphql.d.ts +31 -20
- package/lib/graphql.d.ts.map +1 -1
- package/lib/graphql.js +150 -119
- package/lib/graphql.js.map +1 -1
- package/lib/graphql.types.js +4 -3
- package/lib/graphql.types.js.map +1 -1
- package/lib/index.d.ts +3 -2
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +15 -14
- package/lib/index.js.map +1 -1
- package/lib/json-patch.d.ts +2 -2
- package/lib/json-patch.js +28 -28
- package/lib/pagination.d.ts +9 -25
- package/lib/pagination.d.ts.map +1 -1
- package/lib/pagination.js +95 -90
- package/lib/pagination.js.map +1 -1
- package/lib/plain-values.d.ts +10 -0
- package/lib/plain-values.d.ts.map +1 -0
- package/lib/plain-values.js +40 -0
- package/lib/plain-values.js.map +1 -0
- package/lib/protocol-http.d.ts +50 -14
- package/lib/protocol-http.d.ts.map +1 -1
- package/lib/protocol-http.js +351 -178
- package/lib/protocol-http.js.map +1 -1
- package/lib/protocol-rest.d.ts +38 -25
- package/lib/protocol-rest.d.ts.map +1 -1
- package/lib/protocol-rest.js +238 -130
- package/lib/protocol-rest.js.map +1 -1
- package/lib/query.js +16 -16
- package/lib/response-validation-strict.d.ts +48 -0
- package/lib/response-validation-strict.d.ts.map +1 -0
- package/lib/response-validation-strict.js +284 -0
- package/lib/response-validation-strict.js.map +1 -0
- package/lib/response-validation.d.ts +43 -25
- package/lib/response-validation.d.ts.map +1 -1
- package/lib/response-validation.js +112 -70
- package/lib/response-validation.js.map +1 -1
- package/lib/retry-after.d.ts +3 -3
- package/lib/retry-after.js +49 -49
- package/lib/retry.d.ts +48 -29
- package/lib/retry.d.ts.map +1 -1
- package/lib/retry.js +142 -154
- package/lib/retry.js.map +1 -1
- package/lib/schema-lite-impl.d.ts +158 -0
- package/lib/schema-lite-impl.d.ts.map +1 -0
- package/lib/schema-lite-impl.js +341 -0
- package/lib/schema-lite-impl.js.map +1 -0
- package/lib/schema-lite-typed.d.ts +41 -0
- package/lib/schema-lite-typed.d.ts.map +1 -0
- package/lib/schema-lite-typed.js +27 -0
- package/lib/schema-lite-typed.js.map +1 -0
- package/lib/schema-lite.d.ts +40 -0
- package/lib/schema-lite.d.ts.map +1 -0
- package/lib/schema-lite.js +31 -0
- package/lib/schema-lite.js.map +1 -0
- package/lib/schema.d.ts +20 -6
- package/lib/schema.d.ts.map +1 -1
- package/lib/schema.js +202 -30
- package/lib/schema.js.map +1 -1
- package/lib/testing.d.ts +3 -2
- package/lib/testing.d.ts.map +1 -1
- package/lib/testing.js +22 -21
- package/lib/testing.js.map +1 -1
- package/lib/trait.d.ts +13 -13
- package/lib/trait.d.ts.map +1 -1
- package/lib/trait.js +80 -80
- package/lib/trait.js.map +1 -1
- package/lib/xml.d.ts +1 -1
- package/lib/xml.d.ts.map +1 -1
- package/lib/xml.js +38 -26
- package/lib/xml.js.map +1 -1
- package/package.json +9 -7
- package/src/api.ts +1079 -180
- package/src/category.ts +33 -33
- package/src/chunks.ts +30 -0
- package/src/codegen/chunk.ts +147 -0
- package/src/codegen/cli.ts +27 -1
- package/src/codegen/datafy.ts +874 -0
- package/src/codegen/dedupe.ts +173 -0
- package/src/codegen/generator.ts +10 -3
- package/src/codegen/graphql-client.ts +49 -15
- package/src/codegen/latin1.ts +131 -0
- package/src/codegen/members.ts +8 -0
- package/src/codegen/openapi.ts +194 -3
- package/src/codegen/privatize.ts +200 -0
- package/src/codegen/pure.ts +94 -0
- package/src/codegen/table.ts +254 -0
- package/src/config.ts +216 -0
- package/src/crypto.ts +202 -0
- package/src/debug.ts +8 -0
- package/src/error-category.ts +2 -1
- package/src/errors.ts +65 -56
- package/src/graphql.ts +109 -62
- package/src/graphql.types.ts +9 -7
- package/src/index.ts +3 -2
- package/src/json-patch.ts +2 -2
- package/src/pagination.ts +37 -18
- package/src/plain-values.ts +41 -0
- package/src/protocol-http.ts +378 -145
- package/src/protocol-rest.ts +337 -169
- package/src/response-validation-strict.ts +327 -0
- package/src/response-validation.ts +101 -50
- package/src/retry-after.ts +3 -3
- package/src/retry.ts +94 -93
- package/src/schema-lite-impl.ts +550 -0
- package/src/schema-lite-typed.ts +44 -0
- package/src/schema-lite.ts +44 -0
- package/src/schema.ts +258 -14
- package/src/testing.ts +4 -2
- package/src/trait.ts +36 -28
- package/src/xml.ts +31 -17
- package/lib/codegen/boolean-string-enums.test.d.ts +0 -2
- package/lib/codegen/boolean-string-enums.test.d.ts.map +0 -1
- package/lib/codegen/boolean-string-enums.test.js +0 -275
- package/lib/codegen/boolean-string-enums.test.js.map +0 -1
- package/lib/codegen/defer-naming.test.d.ts +0 -2
- package/lib/codegen/defer-naming.test.d.ts.map +0 -1
- package/lib/codegen/defer-naming.test.js +0 -105
- package/lib/codegen/defer-naming.test.js.map +0 -1
- package/lib/codegen/generated-at.test.d.ts +0 -2
- package/lib/codegen/generated-at.test.d.ts.map +0 -1
- package/lib/codegen/generated-at.test.js +0 -81
- package/lib/codegen/generated-at.test.js.map +0 -1
- package/lib/codegen/generator.test.d.ts +0 -2
- package/lib/codegen/generator.test.d.ts.map +0 -1
- package/lib/codegen/generator.test.js +0 -121
- package/lib/codegen/generator.test.js.map +0 -1
- package/lib/codegen/graphql-client.test.d.ts +0 -2
- package/lib/codegen/graphql-client.test.d.ts.map +0 -1
- package/lib/codegen/graphql-client.test.js +0 -171
- package/lib/codegen/graphql-client.test.js.map +0 -1
- package/lib/codegen/openapi-binary.test.d.ts +0 -2
- package/lib/codegen/openapi-binary.test.d.ts.map +0 -1
- package/lib/codegen/openapi-binary.test.js +0 -67
- package/lib/codegen/openapi-binary.test.js.map +0 -1
- package/lib/codegen/patch-audit.test.d.ts +0 -2
- package/lib/codegen/patch-audit.test.d.ts.map +0 -1
- package/lib/codegen/patch-audit.test.js +0 -141
- package/lib/codegen/patch-audit.test.js.map +0 -1
- package/lib/codegen/patches.test.d.ts +0 -2
- package/lib/codegen/patches.test.d.ts.map +0 -1
- package/lib/codegen/patches.test.js +0 -155
- package/lib/codegen/patches.test.js.map +0 -1
- package/lib/codegen/protocol-imports.test.d.ts +0 -2
- package/lib/codegen/protocol-imports.test.d.ts.map +0 -1
- package/lib/codegen/protocol-imports.test.js +0 -36
- package/lib/codegen/protocol-imports.test.js.map +0 -1
- package/lib/codegen/rewrite-operation-ids.test.d.ts +0 -2
- package/lib/codegen/rewrite-operation-ids.test.d.ts.map +0 -1
- package/lib/codegen/rewrite-operation-ids.test.js +0 -451
- package/lib/codegen/rewrite-operation-ids.test.js.map +0 -1
- package/lib/codegen/untagged-unions.test.d.ts +0 -2
- package/lib/codegen/untagged-unions.test.d.ts.map +0 -1
- package/lib/codegen/untagged-unions.test.js +0 -80
- package/lib/codegen/untagged-unions.test.js.map +0 -1
- package/lib/fixtures/xml/upstream-validator.json +0 -397
- package/lib/graphql.test.d.ts +0 -2
- package/lib/graphql.test.d.ts.map +0 -1
- package/lib/graphql.test.js +0 -151
- package/lib/graphql.test.js.map +0 -1
- package/lib/json-patch.test.d.ts +0 -2
- package/lib/json-patch.test.d.ts.map +0 -1
- package/lib/json-patch.test.js +0 -65
- package/lib/json-patch.test.js.map +0 -1
- package/lib/pagination.test.d.ts +0 -2
- package/lib/pagination.test.d.ts.map +0 -1
- package/lib/pagination.test.js +0 -131
- package/lib/pagination.test.js.map +0 -1
- package/lib/protocol-http.test.d.ts +0 -2
- package/lib/protocol-http.test.d.ts.map +0 -1
- package/lib/protocol-http.test.js +0 -228
- package/lib/protocol-http.test.js.map +0 -1
- package/lib/protocol-rest.test.d.ts +0 -2
- package/lib/protocol-rest.test.d.ts.map +0 -1
- package/lib/protocol-rest.test.js +0 -498
- package/lib/protocol-rest.test.js.map +0 -1
- package/lib/response-validation.test.d.ts +0 -2
- package/lib/response-validation.test.d.ts.map +0 -1
- package/lib/response-validation.test.js +0 -72
- package/lib/response-validation.test.js.map +0 -1
- package/lib/retry-after.test.d.ts +0 -2
- package/lib/retry-after.test.d.ts.map +0 -1
- package/lib/retry-after.test.js +0 -204
- package/lib/retry-after.test.js.map +0 -1
- package/lib/retry.test.d.ts +0 -2
- package/lib/retry.test.d.ts.map +0 -1
- package/lib/retry.test.js +0 -407
- package/lib/retry.test.js.map +0 -1
- package/lib/sdks.test.d.ts +0 -2
- package/lib/sdks.test.d.ts.map +0 -1
- package/lib/sdks.test.js +0 -76
- package/lib/sdks.test.js.map +0 -1
- package/lib/xml.test.d.ts +0 -2
- package/lib/xml.test.d.ts.map +0 -1
- package/lib/xml.test.js +0 -210
- package/lib/xml.test.js.map +0 -1
- package/src/codegen/boolean-string-enums.test.ts +0 -299
- package/src/codegen/defer-naming.test.ts +0 -113
- package/src/codegen/generated-at.test.ts +0 -89
- package/src/codegen/generator.test.ts +0 -137
- package/src/codegen/graphql-client.test.ts +0 -189
- package/src/codegen/openapi-binary.test.ts +0 -91
- package/src/codegen/patch-audit.test.ts +0 -160
- package/src/codegen/patches.test.ts +0 -188
- package/src/codegen/protocol-imports.test.ts +0 -39
- package/src/codegen/rewrite-operation-ids.test.ts +0 -472
- package/src/codegen/untagged-unions.test.ts +0 -85
- package/src/fixtures/xml/upstream-validator.json +0 -397
- package/src/graphql.test.ts +0 -198
- package/src/json-patch.test.ts +0 -77
- package/src/pagination.test.ts +0 -169
- package/src/protocol-http.test.ts +0 -276
- package/src/protocol-rest.test.ts +0 -703
- package/src/response-validation.test.ts +0 -89
- package/src/retry-after.test.ts +0 -267
- package/src/retry.test.ts +0 -566
- package/src/sdks.test.ts +0 -87
- package/src/xml.test.ts +0 -251
package/lib/protocol-http.js
CHANGED
|
@@ -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
|
|
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
|
-
|
|
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
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
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
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
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
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
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
|
-
|
|
297
|
-
|
|
298
|
-
|
|
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
|
-
|
|
329
|
-
|
|
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
|
|
338
|
-
const
|
|
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
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
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
|
-
|
|
362
|
-
|
|
363
|
-
|
|
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
|
-
|
|
376
|
-
|
|
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
|
-
|
|
442
|
+
bind = "query";
|
|
443
|
+
name = nameOf(prop, querySymbol);
|
|
383
444
|
}
|
|
384
445
|
else if (hasPropAnn(prop, deepQuerySymbol)) {
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
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
|
-
|
|
400
|
-
|
|
401
|
-
|
|
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
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
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
|
|
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
|
|
422
|
-
if (
|
|
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}
|
|
432
|
-
if (
|
|
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
|
-
|
|
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
|
-
|
|
650
|
+
return HttpClientRequest.setBody(request, HttpBody.formData(form));
|
|
476
651
|
}
|
|
477
|
-
|
|
652
|
+
if (http.contentType === "form-urlencoded" && bodied) {
|
|
478
653
|
// application/x-www-form-urlencoded with Stripe-style deepObject bracket
|
|
479
|
-
// notation: { shipping: { address: { city } } }
|
|
480
|
-
// arrays indexed ({ expand: ["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
|
-
|
|
662
|
+
return HttpClientRequest.setBody(request, HttpBody.text(params.toString(), "application/x-www-form-urlencoded"));
|
|
488
663
|
}
|
|
489
|
-
|
|
490
|
-
// Whole-body member (raw arrays/scalars)
|
|
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
|
-
|
|
678
|
+
return HttpClientRequest.setBody(request, HttpBody.raw(rawBody, { contentType: mediaType }));
|
|
504
679
|
}
|
|
505
|
-
|
|
506
|
-
|
|
680
|
+
if (rawBody instanceof Uint8Array) {
|
|
681
|
+
return HttpClientRequest.setBody(request, HttpBody.uint8Array(rawBody, mediaType));
|
|
507
682
|
}
|
|
508
|
-
|
|
509
|
-
|
|
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
|
-
|
|
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
|
-
//
|
|
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
|
|
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
|
-
|
|
528
|
-
(hasBodyMembers &&
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
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}` }];
|