@distilled.cloud/core 1.0.0-rc.17 → 1.0.0-rc.19
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/_bundle/base.js +2 -2
- package/lib/_bundle/base.js.map +1 -1
- package/lib/_bundle/graphql.js +2 -2
- package/lib/_bundle/graphql.js.map +1 -1
- package/lib/_bundle/grpc.js +2 -0
- package/lib/_bundle/grpc.js.map +1 -0
- package/lib/_bundle/rest.js +1 -1
- package/lib/_bundle/rest.js.map +1 -1
- package/lib/_bundle/xml.js +1 -1
- package/lib/_bundle/xml.js.map +1 -1
- package/lib/annotations.d.ts +17 -0
- package/lib/annotations.d.ts.map +1 -0
- package/lib/annotations.js +2 -0
- package/lib/annotations.js.map +1 -0
- package/lib/api.d.ts +52 -1
- package/lib/api.d.ts.map +1 -1
- package/lib/api.js +1 -1
- package/lib/category.d.ts.map +1 -1
- package/lib/config.d.ts +54 -13
- package/lib/config.d.ts.map +1 -1
- package/lib/config.js +1 -1
- package/lib/error-category.d.ts.map +1 -1
- package/lib/errors.d.ts +3 -13
- package/lib/errors.d.ts.map +1 -1
- package/lib/errors.js +1 -1
- package/lib/graphql.d.ts +26 -5
- package/lib/graphql.d.ts.map +1 -1
- package/lib/graphql.types.d.ts.map +1 -1
- package/lib/grpc-transport-cloudflare-http2.d.ts +7 -0
- package/lib/grpc-transport-cloudflare-http2.d.ts.map +1 -0
- package/lib/grpc-transport-cloudflare-http2.js +6 -0
- package/lib/grpc-transport-cloudflare-http2.js.map +1 -0
- package/lib/grpc-transport-cloudflare-sockets.d.ts +7 -0
- package/lib/grpc-transport-cloudflare-sockets.d.ts.map +1 -0
- package/lib/grpc-transport-cloudflare-sockets.js +5 -0
- package/lib/grpc-transport-cloudflare-sockets.js.map +1 -0
- package/lib/grpc-transport-node-http2.d.ts +19 -0
- package/lib/grpc-transport-node-http2.d.ts.map +1 -0
- package/lib/grpc-transport-node-http2.js +2 -0
- package/lib/grpc-transport-node-http2.js.map +1 -0
- package/lib/grpc-transport.d.ts +76 -0
- package/lib/grpc-transport.d.ts.map +1 -0
- package/lib/grpc-transport.js +1 -0
- package/lib/hpack.d.ts +34 -0
- package/lib/hpack.d.ts.map +1 -0
- package/lib/hpack.js +2 -0
- package/lib/hpack.js.map +1 -0
- package/lib/index.d.ts +6 -2
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +4 -0
- package/lib/pagination.d.ts +55 -3
- package/lib/pagination.d.ts.map +1 -1
- package/lib/pagination.js +1 -1
- package/lib/protobuf.d.ts +92 -0
- package/lib/protobuf.d.ts.map +1 -0
- package/lib/protobuf.js +1 -0
- package/lib/protocol-grpc.d.ts +86 -0
- package/lib/protocol-grpc.d.ts.map +1 -0
- package/lib/protocol-grpc.js +1 -0
- package/lib/protocol-http.d.ts +38 -9
- package/lib/protocol-http.d.ts.map +1 -1
- package/lib/protocol-http.js +1 -1
- package/lib/protocol-rest.d.ts +60 -42
- package/lib/protocol-rest.d.ts.map +1 -1
- package/lib/protocol-rest.js +1 -1
- package/lib/response-validation.d.ts +5 -4
- package/lib/response-validation.d.ts.map +1 -1
- package/lib/schema-lite-typed.js +1 -2
- package/lib/sdk-error.d.ts +27 -0
- package/lib/sdk-error.d.ts.map +1 -0
- package/lib/sdk-error.js +1 -0
- package/lib/sensitive.d.ts +28 -0
- package/lib/sensitive.d.ts.map +1 -0
- package/lib/sensitive.js +2 -0
- package/lib/sensitive.js.map +1 -0
- package/lib/telemetry-debug.d.ts +6 -0
- package/lib/telemetry-debug.d.ts.map +1 -0
- package/lib/telemetry-debug.js +2 -0
- package/lib/telemetry-debug.js.map +1 -0
- package/lib/telemetry-hooks.d.ts +32 -0
- package/lib/telemetry-hooks.d.ts.map +1 -0
- package/lib/telemetry-hooks.js +2 -0
- package/lib/telemetry-hooks.js.map +1 -0
- package/lib/telemetry-host-rules.d.ts +23 -0
- package/lib/telemetry-host-rules.d.ts.map +1 -0
- package/lib/telemetry-host-rules.js +2 -0
- package/lib/telemetry-host-rules.js.map +1 -0
- package/lib/telemetry-lambda-context.d.ts +17 -0
- package/lib/telemetry-lambda-context.d.ts.map +1 -0
- package/lib/telemetry-lambda-context.js +2 -0
- package/lib/telemetry-lambda-context.js.map +1 -0
- package/lib/telemetry-message-context.d.ts +52 -0
- package/lib/telemetry-message-context.d.ts.map +1 -0
- package/lib/telemetry-message-context.js +2 -0
- package/lib/telemetry-message-context.js.map +1 -0
- package/lib/telemetry-metrics.d.ts +6 -0
- package/lib/telemetry-metrics.d.ts.map +1 -0
- package/lib/telemetry-metrics.js +2 -0
- package/lib/telemetry-metrics.js.map +1 -0
- package/lib/telemetry-name-template.d.ts +13 -0
- package/lib/telemetry-name-template.d.ts.map +1 -0
- package/lib/telemetry-name-template.js +2 -0
- package/lib/telemetry-name-template.js.map +1 -0
- package/lib/telemetry-stream.d.ts +11 -0
- package/lib/telemetry-stream.d.ts.map +1 -0
- package/lib/telemetry-stream.js +2 -0
- package/lib/telemetry-stream.js.map +1 -0
- package/lib/telemetry-xray.d.ts +28 -0
- package/lib/telemetry-xray.d.ts.map +1 -0
- package/lib/telemetry-xray.js +2 -0
- package/lib/telemetry-xray.js.map +1 -0
- package/lib/telemetry.d.ts +288 -0
- package/lib/telemetry.d.ts.map +1 -0
- package/lib/telemetry.js +3 -0
- package/lib/telemetry.js.map +1 -0
- package/lib/trait.d.ts +7 -0
- package/lib/trait.d.ts.map +1 -1
- package/lib/trait.js +1 -1
- package/lib/xml.d.ts.map +1 -1
- package/package.json +3 -5
- package/src/annotations.ts +53 -0
- package/src/api.ts +316 -43
- package/src/category.ts +21 -22
- package/src/config.ts +58 -29
- package/src/error-category.ts +12 -14
- package/src/errors.ts +11 -7
- package/src/graphql.ts +191 -63
- package/src/graphql.types.ts +5 -1
- package/src/grpc-transport-cloudflare-http2.ts +494 -0
- package/src/grpc-transport-cloudflare-sockets.ts +299 -0
- package/src/grpc-transport-node-http2.ts +234 -0
- package/src/grpc-transport.ts +118 -0
- package/src/hpack.ts +331 -0
- package/src/index.ts +6 -2
- package/src/pagination.ts +193 -8
- package/src/protobuf.ts +1332 -0
- package/src/protocol-grpc.ts +641 -0
- package/src/protocol-http.ts +87 -67
- package/src/protocol-rest.ts +183 -191
- package/src/response-validation.ts +8 -5
- package/src/sdk-error.ts +33 -0
- package/src/sensitive.ts +154 -0
- package/src/telemetry-debug.ts +179 -0
- package/src/telemetry-hooks.ts +33 -0
- package/src/telemetry-host-rules.ts +39 -0
- package/src/telemetry-lambda-context.ts +46 -0
- package/src/telemetry-message-context.ts +170 -0
- package/src/telemetry-metrics.ts +69 -0
- package/src/telemetry-name-template.ts +26 -0
- package/src/telemetry-stream.ts +100 -0
- package/src/telemetry-xray.ts +66 -0
- package/src/telemetry.ts +832 -0
- package/src/trait.ts +10 -0
- package/src/xml.ts +10 -1
- package/lib/codegen/boolean-string-enums.d.ts +0 -36
- package/lib/codegen/boolean-string-enums.d.ts.map +0 -1
- package/lib/codegen/boolean-string-enums.js +0 -147
- package/lib/codegen/boolean-string-enums.js.map +0 -1
- package/lib/codegen/chunk.d.ts +0 -7
- package/lib/codegen/chunk.d.ts.map +0 -1
- package/lib/codegen/chunk.js +0 -139
- package/lib/codegen/chunk.js.map +0 -1
- package/lib/codegen/cli.d.ts +0 -80
- package/lib/codegen/cli.d.ts.map +0 -1
- package/lib/codegen/cli.js +0 -166
- package/lib/codegen/cli.js.map +0 -1
- package/lib/codegen/datafy.d.ts +0 -14
- package/lib/codegen/datafy.d.ts.map +0 -1
- package/lib/codegen/datafy.js +0 -853
- package/lib/codegen/datafy.js.map +0 -1
- package/lib/codegen/dedupe.d.ts +0 -5
- package/lib/codegen/dedupe.d.ts.map +0 -1
- package/lib/codegen/dedupe.js +0 -153
- package/lib/codegen/dedupe.js.map +0 -1
- package/lib/codegen/emit.d.ts +0 -125
- package/lib/codegen/emit.d.ts.map +0 -1
- package/lib/codegen/emit.js +0 -99
- package/lib/codegen/emit.js.map +0 -1
- package/lib/codegen/format.d.ts +0 -11
- package/lib/codegen/format.d.ts.map +0 -1
- package/lib/codegen/format.js +0 -32
- package/lib/codegen/format.js.map +0 -1
- package/lib/codegen/generated-at.d.ts +0 -29
- package/lib/codegen/generated-at.d.ts.map +0 -1
- package/lib/codegen/generated-at.js +0 -78
- package/lib/codegen/generated-at.js.map +0 -1
- package/lib/codegen/generator.d.ts +0 -353
- package/lib/codegen/generator.d.ts.map +0 -1
- package/lib/codegen/generator.js +0 -810
- package/lib/codegen/generator.js.map +0 -1
- package/lib/codegen/graph.d.ts +0 -36
- package/lib/codegen/graph.d.ts.map +0 -1
- package/lib/codegen/graph.js +0 -136
- package/lib/codegen/graph.js.map +0 -1
- package/lib/codegen/graphql-client.d.ts +0 -70
- package/lib/codegen/graphql-client.d.ts.map +0 -1
- package/lib/codegen/graphql-client.js +0 -439
- package/lib/codegen/graphql-client.js.map +0 -1
- package/lib/codegen/graphql.d.ts +0 -207
- package/lib/codegen/graphql.d.ts.map +0 -1
- package/lib/codegen/graphql.js +0 -786
- package/lib/codegen/graphql.js.map +0 -1
- package/lib/codegen/latin1.d.ts +0 -3
- package/lib/codegen/latin1.d.ts.map +0 -1
- package/lib/codegen/latin1.js +0 -126
- package/lib/codegen/latin1.js.map +0 -1
- package/lib/codegen/members.d.ts +0 -32
- package/lib/codegen/members.d.ts.map +0 -1
- package/lib/codegen/members.js +0 -62
- package/lib/codegen/members.js.map +0 -1
- package/lib/codegen/model-diff.d.ts +0 -10
- package/lib/codegen/model-diff.d.ts.map +0 -1
- package/lib/codegen/model-diff.js +0 -67
- package/lib/codegen/model-diff.js.map +0 -1
- package/lib/codegen/naming.d.ts +0 -29
- package/lib/codegen/naming.d.ts.map +0 -1
- package/lib/codegen/naming.js +0 -74
- package/lib/codegen/naming.js.map +0 -1
- package/lib/codegen/openapi-cli.d.ts +0 -52
- package/lib/codegen/openapi-cli.d.ts.map +0 -1
- package/lib/codegen/openapi-cli.js +0 -84
- package/lib/codegen/openapi-cli.js.map +0 -1
- package/lib/codegen/openapi.d.ts +0 -209
- package/lib/codegen/openapi.d.ts.map +0 -1
- package/lib/codegen/openapi.js +0 -1548
- package/lib/codegen/openapi.js.map +0 -1
- package/lib/codegen/operations.d.ts +0 -24
- package/lib/codegen/operations.d.ts.map +0 -1
- package/lib/codegen/operations.js +0 -56
- package/lib/codegen/operations.js.map +0 -1
- package/lib/codegen/pagination.d.ts +0 -39
- package/lib/codegen/pagination.d.ts.map +0 -1
- package/lib/codegen/pagination.js +0 -31
- package/lib/codegen/pagination.js.map +0 -1
- package/lib/codegen/patch-audit.d.ts +0 -84
- package/lib/codegen/patch-audit.d.ts.map +0 -1
- package/lib/codegen/patch-audit.js +0 -366
- package/lib/codegen/patch-audit.js.map +0 -1
- package/lib/codegen/patches.d.ts +0 -129
- package/lib/codegen/patches.d.ts.map +0 -1
- package/lib/codegen/patches.js +0 -472
- package/lib/codegen/patches.js.map +0 -1
- package/lib/codegen/prelude.d.ts +0 -15
- package/lib/codegen/prelude.d.ts.map +0 -1
- package/lib/codegen/prelude.js +0 -60
- package/lib/codegen/prelude.js.map +0 -1
- package/lib/codegen/privatize.d.ts +0 -21
- package/lib/codegen/privatize.d.ts.map +0 -1
- package/lib/codegen/privatize.js +0 -176
- package/lib/codegen/privatize.js.map +0 -1
- package/lib/codegen/proto.d.ts +0 -121
- package/lib/codegen/proto.d.ts.map +0 -1
- package/lib/codegen/proto.js +0 -960
- package/lib/codegen/proto.js.map +0 -1
- package/lib/codegen/pure.d.ts +0 -6
- package/lib/codegen/pure.d.ts.map +0 -1
- package/lib/codegen/pure.js +0 -91
- package/lib/codegen/pure.js.map +0 -1
- package/lib/codegen/rewrite-operation-ids.d.ts +0 -154
- package/lib/codegen/rewrite-operation-ids.d.ts.map +0 -1
- package/lib/codegen/rewrite-operation-ids.js +0 -1117
- package/lib/codegen/rewrite-operation-ids.js.map +0 -1
- package/lib/codegen/spec-path.d.ts +0 -16
- package/lib/codegen/spec-path.d.ts.map +0 -1
- package/lib/codegen/spec-path.js +0 -101
- package/lib/codegen/spec-path.js.map +0 -1
- package/lib/codegen/table.d.ts +0 -5
- package/lib/codegen/table.d.ts.map +0 -1
- package/lib/codegen/table.js +0 -249
- package/lib/codegen/table.js.map +0 -1
- package/lib/debug.d.ts +0 -2
- package/lib/debug.d.ts.map +0 -1
- package/lib/debug.js +0 -1
- package/lib/json-patch.d.ts +0 -58
- package/lib/json-patch.d.ts.map +0 -1
- package/lib/json-patch.js +0 -2
- package/lib/json-patch.js.map +0 -1
- package/lib/schema-lite-typed.js.map +0 -1
- package/lib/testing.d.ts +0 -40
- package/lib/testing.d.ts.map +0 -1
- package/lib/testing.js +0 -2
- package/lib/testing.js.map +0 -1
- package/src/codegen/boolean-string-enums.ts +0 -155
- package/src/codegen/chunk.ts +0 -147
- package/src/codegen/cli.ts +0 -293
- package/src/codegen/datafy.ts +0 -874
- package/src/codegen/dedupe.ts +0 -173
- package/src/codegen/emit.ts +0 -200
- package/src/codegen/format.ts +0 -49
- package/src/codegen/generated-at.ts +0 -88
- package/src/codegen/generator.ts +0 -1229
- package/src/codegen/graph.ts +0 -151
- package/src/codegen/graphql-client.ts +0 -545
- package/src/codegen/graphql.ts +0 -1145
- package/src/codegen/latin1.ts +0 -131
- package/src/codegen/members.ts +0 -79
- package/src/codegen/model-diff.ts +0 -67
- package/src/codegen/naming.ts +0 -85
- package/src/codegen/openapi-cli.ts +0 -141
- package/src/codegen/openapi.ts +0 -1845
- package/src/codegen/operations.ts +0 -73
- package/src/codegen/pagination.ts +0 -64
- package/src/codegen/patch-audit.ts +0 -480
- package/src/codegen/patches.ts +0 -581
- package/src/codegen/prelude.ts +0 -70
- package/src/codegen/privatize.ts +0 -200
- package/src/codegen/proto.ts +0 -1092
- package/src/codegen/pure.ts +0 -94
- package/src/codegen/rewrite-operation-ids.ts +0 -1219
- package/src/codegen/spec-path.ts +0 -112
- package/src/codegen/table.ts +0 -254
- package/src/debug.ts +0 -8
- package/src/json-patch.ts +0 -273
- package/src/testing.ts +0 -74
package/src/protocol-http.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import * as Effect from "effect/Effect";
|
|
1
2
|
import * as Headers from "effect/http/Headers";
|
|
2
3
|
import * as HttpBody from "effect/http/HttpBody";
|
|
3
4
|
import * as HttpClientRequest from "effect/http/HttpClientRequest";
|
|
@@ -12,10 +13,15 @@ import * as HttpClientRequest from "effect/http/HttpClientRequest";
|
|
|
12
13
|
* {@link matchTypedError}).
|
|
13
14
|
*/
|
|
14
15
|
import type * as AST from "effect/SchemaAST";
|
|
15
|
-
import {
|
|
16
|
+
import { getAnn, getProps, resolveNode } from "./annotations.ts";
|
|
17
|
+
import * as Category from "./category.ts";
|
|
16
18
|
import { isOpaqueValue } from "./plain-values.ts";
|
|
19
|
+
import * as Schema from "./schema-lite-typed.ts";
|
|
20
|
+
import { SdkError } from "./sdk-error.ts";
|
|
21
|
+
import { restoreStack, suppressStack } from "./telemetry.ts";
|
|
17
22
|
import {
|
|
18
23
|
bodySymbol,
|
|
24
|
+
commaDelimitedSymbol,
|
|
19
25
|
deepQuerySymbol,
|
|
20
26
|
formDataFileSymbol,
|
|
21
27
|
getErrorMatchers,
|
|
@@ -37,27 +43,7 @@ import {
|
|
|
37
43
|
|
|
38
44
|
//#region AST helpers (survive S.optional / Suspend / transforms)
|
|
39
45
|
|
|
40
|
-
export
|
|
41
|
-
if (ast._tag === "Objects") return ast.propertySignatures;
|
|
42
|
-
if (ast._tag === "Suspend") return getProps(ast.thunk());
|
|
43
|
-
if (ast.encoding && ast.encoding.length > 0) return getProps(ast.encoding[0]!.to);
|
|
44
|
-
return [];
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
export const getAnn = (ast: AST.AST, symbol: symbol): unknown => {
|
|
48
|
-
const direct = (ast.annotations as Record<symbol, unknown> | undefined)?.[symbol];
|
|
49
|
-
if (direct !== undefined) return direct;
|
|
50
|
-
if (ast._tag === "Suspend") return getAnn(ast.thunk(), symbol);
|
|
51
|
-
if (ast.encoding && ast.encoding.length > 0) return getAnn(ast.encoding[0]!.to, symbol);
|
|
52
|
-
// S.optional -> Union[self, Undefined]; descend into the single real member.
|
|
53
|
-
if (ast._tag === "Union") {
|
|
54
|
-
const real = (ast as AST.Union).types.filter(
|
|
55
|
-
(t) => t._tag !== "Undefined" && !(t._tag === "Literal" && (t as any).literal === null),
|
|
56
|
-
);
|
|
57
|
-
if (real.length === 1) return getAnn(real[0]!, symbol);
|
|
58
|
-
}
|
|
59
|
-
return undefined;
|
|
60
|
-
};
|
|
46
|
+
export { getAnn, getProps, resolveNode } from "./annotations.ts";
|
|
61
47
|
|
|
62
48
|
export const getPropAnn = (prop: AST.PropertySignature, symbol: symbol): unknown =>
|
|
63
49
|
getAnn(prop.type, symbol);
|
|
@@ -68,21 +54,6 @@ export const nameOf = (prop: AST.PropertySignature, symbol: symbol): string => {
|
|
|
68
54
|
return typeof v === "string" ? v : String(prop.name);
|
|
69
55
|
};
|
|
70
56
|
|
|
71
|
-
/** Resolve wrappers to the real node: Suspend, encoding, optional/null unions. */
|
|
72
|
-
export const resolveNode = (ast: AST.AST): AST.AST => {
|
|
73
|
-
if (ast._tag === "Suspend") return resolveNode(ast.thunk());
|
|
74
|
-
if (ast.encoding && ast.encoding.length > 0) return resolveNode(ast.encoding[0]!.to);
|
|
75
|
-
if (ast._tag === "Union") {
|
|
76
|
-
const real = (ast as AST.Union).types.filter(
|
|
77
|
-
(t) =>
|
|
78
|
-
t._tag !== "Undefined" &&
|
|
79
|
-
t._tag !== "Null" &&
|
|
80
|
-
!(t._tag === "Literal" && (t as any).literal === null),
|
|
81
|
-
);
|
|
82
|
-
if (real.length === 1) return resolveNode(real[0]!);
|
|
83
|
-
}
|
|
84
|
-
return ast;
|
|
85
|
-
};
|
|
86
57
|
//#endregion
|
|
87
58
|
|
|
88
59
|
//#region Response headers on outputs
|
|
@@ -459,6 +430,12 @@ export interface BuildRequestOptions {
|
|
|
459
430
|
* Defaults to the key verbatim.
|
|
460
431
|
*/
|
|
461
432
|
readonly unknownKeyToWire?: (key: string) => string;
|
|
433
|
+
/**
|
|
434
|
+
* Send `{}` on a method that takes a body even when the input declares no
|
|
435
|
+
* body members. Connect unary RPCs (E2B's envd) POST JSON for every call,
|
|
436
|
+
* and refuse a bodyless one with 415.
|
|
437
|
+
*/
|
|
438
|
+
readonly emptyJsonBody?: boolean;
|
|
462
439
|
}
|
|
463
440
|
|
|
464
441
|
/**
|
|
@@ -514,6 +491,8 @@ interface MemberPlan {
|
|
|
514
491
|
/** `{name+}` placeholder. */
|
|
515
492
|
readonly greedy: boolean;
|
|
516
493
|
readonly stringEncoded: boolean;
|
|
494
|
+
/** A list query member sent as one comma-separated parameter. */
|
|
495
|
+
readonly commaDelimited: boolean;
|
|
517
496
|
/** `mapKeys(type, value, "encode", rootDict)` returns the value unchanged. */
|
|
518
497
|
readonly verbatim: boolean;
|
|
519
498
|
}
|
|
@@ -530,12 +509,12 @@ interface RequestPlan {
|
|
|
530
509
|
|
|
531
510
|
const plans = /*@__PURE__*/ new WeakMap<AST.AST, RequestPlan>();
|
|
532
511
|
|
|
533
|
-
const planFor = (inputAst: AST.AST): RequestPlan => {
|
|
512
|
+
const planFor = (inputAst: AST.AST): RequestPlan | SdkError => {
|
|
534
513
|
let plan = plans.get(inputAst);
|
|
535
514
|
if (plan !== undefined) return plan;
|
|
536
515
|
const http = getAnn(inputAst, httpSymbol) as HttpTrait | undefined;
|
|
537
516
|
if (!http) {
|
|
538
|
-
|
|
517
|
+
return new SdkError({ message: "operation input is missing the Http() trait" });
|
|
539
518
|
}
|
|
540
519
|
const rootDict = getAnn(inputAst, keyDictionarySymbol) as KeyDictionaryEntries | undefined;
|
|
541
520
|
const members: MemberPlan[] = [];
|
|
@@ -578,6 +557,7 @@ const planFor = (inputAst: AST.AST): RequestPlan => {
|
|
|
578
557
|
preserve: typeof preserve === "string" ? preserve : undefined,
|
|
579
558
|
greedy,
|
|
580
559
|
stringEncoded: hasPropAnn(prop, stringEncodedSymbol),
|
|
560
|
+
commaDelimited: hasPropAnn(prop, commaDelimitedSymbol),
|
|
581
561
|
verbatim: rootDict === undefined && mapsVerbatim(prop.type, "encode"),
|
|
582
562
|
});
|
|
583
563
|
}
|
|
@@ -607,6 +587,38 @@ export const makeRequest = (
|
|
|
607
587
|
HttpBody.empty,
|
|
608
588
|
);
|
|
609
589
|
|
|
590
|
+
/**
|
|
591
|
+
* The input cannot be sent: a path label whose value would address another
|
|
592
|
+
* resource (`.` or `..`, which the URL parser resolves to the parent path).
|
|
593
|
+
* Raised before anything is sent.
|
|
594
|
+
*/
|
|
595
|
+
export class InvalidInput
|
|
596
|
+
extends /*@__PURE__*/ Schema.TaggedError<InvalidInput>()("InvalidInput", {
|
|
597
|
+
member: Schema.String,
|
|
598
|
+
message: Schema.String,
|
|
599
|
+
}).pipe(Category.withBadRequestError) {}
|
|
600
|
+
|
|
601
|
+
/**
|
|
602
|
+
* The refusal for a path label value that would address another resource,
|
|
603
|
+
* or `undefined`. The URL parser resolves a `.` or `..` segment,
|
|
604
|
+
* percent-encoded or not, so no encoding can carry one
|
|
605
|
+
* (`/projects/p1/branches/..` -> `/projects/p1/`). A greedy label keeps its
|
|
606
|
+
* `/`, so each of its segments counts.
|
|
607
|
+
*/
|
|
608
|
+
export const invalidLabel = (
|
|
609
|
+
member: string,
|
|
610
|
+
value: unknown,
|
|
611
|
+
greedy?: boolean,
|
|
612
|
+
): InvalidInput | undefined => {
|
|
613
|
+
const text = String(value);
|
|
614
|
+
return (greedy ? text.split("/") : [text]).some((s) => s === "." || s === "..")
|
|
615
|
+
? new InvalidInput({
|
|
616
|
+
member,
|
|
617
|
+
message: `Input member ${member} cannot be ${JSON.stringify(text)}: as a path label it would address another resource`,
|
|
618
|
+
})
|
|
619
|
+
: undefined;
|
|
620
|
+
};
|
|
621
|
+
|
|
610
622
|
/**
|
|
611
623
|
* Build an HTTP request from an operation input and its schema, driven by
|
|
612
624
|
* the trait annotations: `Http()` supplies method + URI template, `Label()`
|
|
@@ -619,21 +631,32 @@ export const makeRequest = (
|
|
|
619
631
|
* The schema is read once per input schema (see `planFor`); later calls only
|
|
620
632
|
* walk the input value.
|
|
621
633
|
*
|
|
622
|
-
*
|
|
623
|
-
*
|
|
624
|
-
*
|
|
625
|
-
*
|
|
634
|
+
* Fails with {@link InvalidInput}, before anything is sent, when a label is
|
|
635
|
+
* `.` or `..` (for a greedy `{name+}` label, when any of its segments is).
|
|
636
|
+
* Fails with {@link SdkError} when the input schema is missing the `Http()`
|
|
637
|
+
* trait (a codegen bug the generator refuses).
|
|
626
638
|
*/
|
|
627
|
-
export const buildRequest = (
|
|
639
|
+
export const buildRequest = (
|
|
640
|
+
options: BuildRequestOptions,
|
|
641
|
+
): Effect.Effect<HttpClientRequest.HttpClientRequest, InvalidInput | SdkError> => {
|
|
642
|
+
const request = requestOrInvalid(options);
|
|
643
|
+
return request instanceof InvalidInput || request instanceof SdkError
|
|
644
|
+
? Effect.fail(request)
|
|
645
|
+
: Effect.succeed(request);
|
|
646
|
+
};
|
|
647
|
+
|
|
648
|
+
const requestOrInvalid = ({
|
|
628
649
|
input,
|
|
629
650
|
inputAst,
|
|
630
651
|
baseUrl,
|
|
631
652
|
headers: baseHeaders,
|
|
632
653
|
mapMemberHeader,
|
|
633
654
|
unknownKeyToWire,
|
|
634
|
-
|
|
655
|
+
emptyJsonBody,
|
|
656
|
+
}: BuildRequestOptions): HttpClientRequest.HttpClientRequest | InvalidInput | SdkError => {
|
|
635
657
|
const inputObj = (input ?? {}) as Record<string, unknown>;
|
|
636
658
|
const plan = planFor(inputAst);
|
|
659
|
+
if (plan instanceof SdkError) return plan;
|
|
637
660
|
const { http, rootDict, members, known } = plan;
|
|
638
661
|
let hasBodyMembers = plan.hasBodyMembers;
|
|
639
662
|
|
|
@@ -654,17 +677,8 @@ export const buildRequest = ({
|
|
|
654
677
|
if (value === undefined) continue;
|
|
655
678
|
switch (m.bind) {
|
|
656
679
|
case "label": {
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
// (`/projects/p1/branches/..` -> `/projects/p1/`). A greedy label keeps
|
|
660
|
-
// its `/`, so each of its segments counts.
|
|
661
|
-
if (
|
|
662
|
-
(m.greedy ? String(value).split("/") : [String(value)]).some(
|
|
663
|
-
(s) => s === "." || s === "..",
|
|
664
|
-
)
|
|
665
|
-
) {
|
|
666
|
-
throw new Error(`invalid value for input HTTP label: ${m.key}`);
|
|
667
|
-
}
|
|
680
|
+
const invalid = invalidLabel(m.key, value, m.greedy);
|
|
681
|
+
if (invalid) return invalid;
|
|
668
682
|
const encoded = encodeURIComponent(String(value));
|
|
669
683
|
const preserve = m.preserve;
|
|
670
684
|
const label =
|
|
@@ -686,7 +700,11 @@ export const buildRequest = ({
|
|
|
686
700
|
break;
|
|
687
701
|
}
|
|
688
702
|
case "query":
|
|
689
|
-
|
|
703
|
+
if (m.commaDelimited && Array.isArray(value)) {
|
|
704
|
+
(query ??= new URLSearchParams()).append(m.name, value.map(String).join(","));
|
|
705
|
+
} else {
|
|
706
|
+
appendQuery((query ??= new URLSearchParams()), m.name, value);
|
|
707
|
+
}
|
|
690
708
|
break;
|
|
691
709
|
case "deepQuery": {
|
|
692
710
|
// Deep-object query member (T.DeepQuery): a nested struct expands into
|
|
@@ -744,9 +762,6 @@ export const buildRequest = ({
|
|
|
744
762
|
|
|
745
763
|
const qs = query === undefined ? "" : query.toString();
|
|
746
764
|
const url = qs ? `${baseUrl}${uri}?${qs}` : `${baseUrl}${uri}`;
|
|
747
|
-
if (debugHttp()) {
|
|
748
|
-
console.error(`[distilled] -> ${http.method} ${http.uri}`);
|
|
749
|
-
}
|
|
750
765
|
|
|
751
766
|
const request = makeRequest(http.method, url, headers);
|
|
752
767
|
const bodied = !BODYLESS.has(http.method);
|
|
@@ -846,7 +861,7 @@ export const buildRequest = ({
|
|
|
846
861
|
// The `{}`-when-empty rule below stays limited to methods that expect a
|
|
847
862
|
// body, so a bodyless method with nothing set still sends nothing.
|
|
848
863
|
bodyKeys > 0 ||
|
|
849
|
-
(hasBodyMembers && bodied && http.method !== "DELETE")
|
|
864
|
+
((hasBodyMembers || emptyJsonBody === true) && bodied && http.method !== "DELETE")
|
|
850
865
|
) {
|
|
851
866
|
// Send `{}` rather than no body when the schema declares body members --
|
|
852
867
|
// some endpoints reject a missing JSON body outright.
|
|
@@ -969,11 +984,16 @@ export const matchTypedError = (
|
|
|
969
984
|
}
|
|
970
985
|
}
|
|
971
986
|
if (!best) return undefined;
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
987
|
+
const saved = suppressStack();
|
|
988
|
+
try {
|
|
989
|
+
return new (best.cls as new (args: any) => unknown)({
|
|
990
|
+
code: best.code ?? 0,
|
|
991
|
+
message: best.message,
|
|
992
|
+
body: response.body,
|
|
993
|
+
headers: response.headers,
|
|
994
|
+
});
|
|
995
|
+
} finally {
|
|
996
|
+
restoreStack(saved);
|
|
997
|
+
}
|
|
978
998
|
};
|
|
979
999
|
//#endregion
|