@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-rest.ts
CHANGED
|
@@ -1,3 +1,30 @@
|
|
|
1
|
+
import * as Context from "effect/Context";
|
|
2
|
+
import * as Effect from "effect/Effect";
|
|
3
|
+
import * as HttpClient from "effect/http/HttpClient";
|
|
4
|
+
import type * as HttpClientRequest from "effect/http/HttpClientRequest";
|
|
5
|
+
import type * as HttpClientResponse from "effect/http/HttpClientResponse";
|
|
6
|
+
import * as Layer from "effect/Layer";
|
|
7
|
+
import type * as AST from "effect/SchemaAST";
|
|
8
|
+
import { rawResponseRootSymbol, resolveNode } from "./annotations.ts";
|
|
9
|
+
import * as API from "./api.ts";
|
|
10
|
+
import { HTTP_STATUS_MAP, InternalServerError } from "./errors.ts";
|
|
11
|
+
import { recordPageHeaders } from "./pagination.ts";
|
|
12
|
+
import { unwrapRedactedDeep } from "./plain-values.ts";
|
|
13
|
+
import {
|
|
14
|
+
buildRequest,
|
|
15
|
+
getAnn,
|
|
16
|
+
getProps,
|
|
17
|
+
hasPropAnn,
|
|
18
|
+
mapKeys,
|
|
19
|
+
mapsVerbatim,
|
|
20
|
+
matchTypedError,
|
|
21
|
+
responseHeaderMembers,
|
|
22
|
+
withResponseHeaders,
|
|
23
|
+
type ResponseHeaderMember,
|
|
24
|
+
} from "./protocol-http.ts";
|
|
25
|
+
import { checkResponse, withholdActual } from "./response-validation.ts";
|
|
26
|
+
import { parseRetryAfterForStatus } from "./retry-after.ts";
|
|
27
|
+
import { holdsSensitive, sensitiveValueSymbol, wrapSensitive } from "./sensitive.ts";
|
|
1
28
|
/**
|
|
2
29
|
* Generic REST protocol factory for simple bearer/header-auth JSON APIs
|
|
3
30
|
* (Neon, Fly.io, PlanetScale, Supabase, Turso, ...).
|
|
@@ -16,7 +43,8 @@
|
|
|
16
43
|
* failing with the provider's `parseError` (see
|
|
17
44
|
* `core/response-validation`) -> `Redacted` wrapping of members
|
|
18
45
|
* marked with {@link SensitiveValue}; non-2xx -> typed error:
|
|
19
|
-
*
|
|
46
|
+
* the provider's `classifyError`, then per-op matcher
|
|
47
|
+
* classes (`matchTypedError`), then the status
|
|
20
48
|
* map (default `HTTP_STATUS_MAP`), then an `InternalServerError`
|
|
21
49
|
* for unmapped 5xx, then the provider's `unknownError` fallback
|
|
22
50
|
* -- with `retryAfter` durations stamped from the standard hint
|
|
@@ -25,45 +53,18 @@
|
|
|
25
53
|
* Anything provider-specific (envelope quirks, bespoke error codes) belongs
|
|
26
54
|
* in the provider package -- via these options or a hand-written protocol.
|
|
27
55
|
*/
|
|
28
|
-
import * as
|
|
29
|
-
import * as Effect from "effect/Effect";
|
|
30
|
-
import * as HttpClient from "effect/http/HttpClient";
|
|
31
|
-
import type * as HttpClientRequest from "effect/http/HttpClientRequest";
|
|
32
|
-
import type * as HttpClientResponse from "effect/http/HttpClientResponse";
|
|
33
|
-
import * as Layer from "effect/Layer";
|
|
34
|
-
import * as Redacted from "effect/Redacted";
|
|
35
|
-
import type * as AST from "effect/SchemaAST";
|
|
36
|
-
import * as API from "./api.ts";
|
|
37
|
-
import { debugHttp } from "./debug.ts";
|
|
38
|
-
import { HTTP_STATUS_MAP, InternalServerError } from "./errors.ts";
|
|
39
|
-
import { isOpaqueValue, unwrapRedactedDeep } from "./plain-values.ts";
|
|
40
|
-
import {
|
|
41
|
-
buildRequest,
|
|
42
|
-
getAnn,
|
|
43
|
-
getPropAnn,
|
|
44
|
-
getProps,
|
|
45
|
-
mapKeys,
|
|
46
|
-
mapsVerbatim,
|
|
47
|
-
matchTypedError,
|
|
48
|
-
resolveNode,
|
|
49
|
-
responseHeaderMembers,
|
|
50
|
-
withResponseHeaders,
|
|
51
|
-
type ResponseHeaderMember,
|
|
52
|
-
} from "./protocol-http.ts";
|
|
53
|
-
import { checkResponse, withholdActual } from "./response-validation.ts";
|
|
54
|
-
import { parseRetryAfterForStatus } from "./retry-after.ts";
|
|
56
|
+
import * as Telemetry from "./telemetry.ts";
|
|
55
57
|
import { httpSymbol, makeAnnotation, type HttpTrait } from "./trait.ts";
|
|
56
58
|
|
|
57
59
|
// =============================================================================
|
|
58
60
|
// Traits
|
|
59
61
|
// =============================================================================
|
|
60
62
|
|
|
61
|
-
export
|
|
62
|
-
"@distilled.cloud/core/sensitive-value",
|
|
63
|
-
);
|
|
63
|
+
export { sensitiveValueSymbol };
|
|
64
64
|
/**
|
|
65
|
-
* Marks a string member as sensitive (mirrors
|
|
66
|
-
* The REST protocol wraps decoded values in
|
|
65
|
+
* Marks a string member, map value or list element as sensitive (mirrors
|
|
66
|
+
* `smithy.api#sensitive`). The REST protocol wraps decoded values in
|
|
67
|
+
* `Redacted` on the way out (an untyped `S.Unknown` value whole) and
|
|
67
68
|
* accepts `string | Redacted<string>` on the way in (unwrapped before
|
|
68
69
|
* serialization). Takes an ignored argument so generators can inline the
|
|
69
70
|
* smithy trait value (`T.SensitiveValue({})`).
|
|
@@ -77,15 +78,13 @@ export const rawResponseSymbol = /*@__PURE__*/ Symbol.for("@distilled.cloud/core
|
|
|
77
78
|
*/
|
|
78
79
|
export const RawResponse = (_value?: unknown) => makeAnnotation(rawResponseSymbol, true);
|
|
79
80
|
|
|
80
|
-
export const rawResponseRootSymbol = /*@__PURE__*/ Symbol.for(
|
|
81
|
-
"@distilled.cloud/core/raw-response-root",
|
|
82
|
-
);
|
|
83
81
|
/**
|
|
84
82
|
* Marks a response schema whose ENTIRE value is the response body (the
|
|
85
83
|
* generator's `rootPipe` for synthesized bare-payload wrappers): the emitted
|
|
86
84
|
* response type IS the payload type and the protocol returns the mapped body
|
|
87
85
|
* directly.
|
|
88
86
|
*/
|
|
87
|
+
export { rawResponseRootSymbol };
|
|
89
88
|
export const RawResponseRoot = () => makeAnnotation(rawResponseRootSymbol, true);
|
|
90
89
|
|
|
91
90
|
export const binaryResponseSymbol = /*@__PURE__*/ Symbol.for(
|
|
@@ -101,76 +100,15 @@ export const BinaryResponse = () => makeAnnotation(binaryResponseSymbol, true);
|
|
|
101
100
|
|
|
102
101
|
export { unwrapRedactedDeep };
|
|
103
102
|
|
|
104
|
-
|
|
105
|
-
* Walk a decoded (TS-named) value alongside its schema AST, wrapping members
|
|
106
|
-
* marked {@link SensitiveValue} in `Redacted`. Keys the schema doesn't model
|
|
107
|
-
* pass through verbatim.
|
|
108
|
-
*/
|
|
109
|
-
export const wrapSensitive = (ast: AST.AST, value: unknown): unknown => {
|
|
110
|
-
if (value === null || typeof value !== "object" || isOpaqueValue(value)) {
|
|
111
|
-
return value;
|
|
112
|
-
}
|
|
113
|
-
const node = resolveNode(ast);
|
|
114
|
-
if (node._tag === "Union") {
|
|
115
|
-
// Redact every possible sensitive member, including in partial responses.
|
|
116
|
-
return node.types.reduce<unknown>((redacted, arm) => wrapSensitive(arm, redacted), value);
|
|
117
|
-
}
|
|
118
|
-
if (node._tag === "Arrays") {
|
|
119
|
-
if (!Array.isArray(value)) return value;
|
|
120
|
-
const elem = (node as any).rest?.[0] as AST.AST | undefined;
|
|
121
|
-
return elem ? value.map((v) => wrapSensitive(elem, v)) : value;
|
|
122
|
-
}
|
|
123
|
-
if (node._tag === "Objects" && !Array.isArray(value)) {
|
|
124
|
-
const props = getProps(node);
|
|
125
|
-
if (props.length === 0) return value;
|
|
126
|
-
const byName = new Map(props.map((p) => [String(p.name), p]));
|
|
127
|
-
const out: Record<string, unknown> = {};
|
|
128
|
-
for (const [k, v] of Object.entries(value as Record<string, unknown>)) {
|
|
129
|
-
if (v === undefined) continue;
|
|
130
|
-
const prop = byName.get(k);
|
|
131
|
-
if (!prop) {
|
|
132
|
-
out[k] = v;
|
|
133
|
-
} else if (getPropAnn(prop, sensitiveValueSymbol) !== undefined && typeof v === "string") {
|
|
134
|
-
out[k] = Redacted.make(v);
|
|
135
|
-
} else {
|
|
136
|
-
out[k] = wrapSensitive(prop.type, v);
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
return out;
|
|
140
|
-
}
|
|
141
|
-
return value;
|
|
142
|
-
};
|
|
143
|
-
|
|
144
|
-
const sensitiveOutputs = /*@__PURE__*/ new WeakMap<AST.AST, boolean>();
|
|
103
|
+
export { wrapSensitive };
|
|
145
104
|
|
|
146
105
|
/**
|
|
147
|
-
* Whether any member reachable from `ast` is
|
|
148
|
-
*
|
|
149
|
-
* {@link
|
|
106
|
+
* Whether any member, map value or list element reachable from `ast` is
|
|
107
|
+
* marked {@link SensitiveValue}. Such an output is decoded through
|
|
108
|
+
* {@link wrapSensitive}, and its parse errors withhold the response body (see
|
|
109
|
+
* {@link checkSuccess}, which every REST-style protocol's success path uses).
|
|
150
110
|
*/
|
|
151
|
-
export const hasSensitiveMember
|
|
152
|
-
const cached = sensitiveOutputs.get(ast);
|
|
153
|
-
if (cached !== undefined) return cached;
|
|
154
|
-
const seen = new Set<AST.AST>();
|
|
155
|
-
const visit = (node: AST.AST): boolean => {
|
|
156
|
-
node = resolveNode(node);
|
|
157
|
-
if (seen.has(node)) return false;
|
|
158
|
-
seen.add(node);
|
|
159
|
-
if (node._tag === "Union") return node.types.some(visit);
|
|
160
|
-
if (node._tag === "Arrays") {
|
|
161
|
-
return [...node.elements, ...node.rest].some(
|
|
162
|
-
(e) => getAnn(e, sensitiveValueSymbol) !== undefined || visit(e),
|
|
163
|
-
);
|
|
164
|
-
}
|
|
165
|
-
if (node._tag !== "Objects") return false;
|
|
166
|
-
return [...node.propertySignatures, ...node.indexSignatures].some(
|
|
167
|
-
(member) => getAnn(member.type, sensitiveValueSymbol) !== undefined || visit(member.type),
|
|
168
|
-
);
|
|
169
|
-
};
|
|
170
|
-
const result = visit(ast);
|
|
171
|
-
sensitiveOutputs.set(ast, result);
|
|
172
|
-
return result;
|
|
173
|
-
};
|
|
111
|
+
export const hasSensitiveMember: (ast: AST.AST) => boolean = holdsSensitive;
|
|
174
112
|
|
|
175
113
|
// =============================================================================
|
|
176
114
|
// Protocol factory
|
|
@@ -243,6 +181,13 @@ export interface RestProtocolOptions<C> {
|
|
|
243
181
|
* else to {@link unknownError}.
|
|
244
182
|
*/
|
|
245
183
|
readonly statusMap?: Readonly<Record<number, new (args: any) => any>>;
|
|
184
|
+
/**
|
|
185
|
+
* The provider's own reading of a failure, consulted before per-op typed
|
|
186
|
+
* matching and the status map: return the error to fail with, or
|
|
187
|
+
* `undefined` to decode the failure as usual. For rules a status alone
|
|
188
|
+
* can't express, e.g. a 403 that is a rate limit because of its headers.
|
|
189
|
+
*/
|
|
190
|
+
readonly classifyError?: (info: RestErrorInfo) => unknown;
|
|
246
191
|
/** Fallback error for failures nothing else matched. */
|
|
247
192
|
readonly unknownError: (info: RestErrorInfo) => unknown;
|
|
248
193
|
/**
|
|
@@ -261,6 +206,8 @@ export interface RestProtocolOptions<C> {
|
|
|
261
206
|
readonly mapMemberHeader?: (name: string, value: string) => string;
|
|
262
207
|
/** Passed through to `buildRequest` (wire names for unmodeled input keys). */
|
|
263
208
|
readonly unknownKeyToWire?: (key: string) => string;
|
|
209
|
+
/** Passed through to `buildRequest`: send `{}` when a bodied call has no body members. */
|
|
210
|
+
readonly emptyJsonBody?: boolean;
|
|
264
211
|
}
|
|
265
212
|
|
|
266
213
|
const defaultErrorEnvelope = (body: unknown): RestErrorEnvelope | undefined => {
|
|
@@ -278,45 +225,88 @@ const defaultErrorEnvelope = (body: unknown): RestErrorEnvelope | undefined => {
|
|
|
278
225
|
// here; the generated operation annotations reintroduce it for callers.
|
|
279
226
|
const fail = (e: unknown): Effect.Effect<never> => Effect.fail(e) as Effect.Effect<never>;
|
|
280
227
|
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
228
|
+
// =============================================================================
|
|
229
|
+
// 2xx bodies
|
|
230
|
+
// =============================================================================
|
|
231
|
+
|
|
232
|
+
/** A 2xx body a protocol read, for {@link checkSuccess}. */
|
|
233
|
+
export interface SuccessBody {
|
|
234
|
+
/** The value to check and return: the body mapped onto the output's TS names. */
|
|
235
|
+
readonly value: unknown;
|
|
236
|
+
/** What a parse error reports as `body` for an output without sensitive members. */
|
|
237
|
+
readonly body: unknown;
|
|
238
|
+
/** Whether the body was not JSON. */
|
|
239
|
+
readonly nonJson: boolean;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/** The outcome of {@link checkSuccess}: the value, or the parse error's fields. */
|
|
243
|
+
export type SuccessCheck =
|
|
244
|
+
| { readonly ok: true; readonly value: unknown }
|
|
245
|
+
| { readonly ok: false; readonly error: RestParseErrorInfo };
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* Check a 2xx body against the operation's output schema and deliver its
|
|
249
|
+
* sensitive values as `Redacted`. Every REST-style protocol ends its success
|
|
250
|
+
* path here, so all of them treat a body that can hold a secret alike:
|
|
251
|
+
*
|
|
252
|
+
* - The checked value comes back through {@link wrapSensitive}.
|
|
253
|
+
* - A mismatch (validating modes, see `core/response-validation`) reports
|
|
254
|
+
* `read.body` and the schema error.
|
|
255
|
+
* - For an output with sensitive members ({@link hasSensitiveMember}), a
|
|
256
|
+
* non-JSON body fails in every mode with `"Invalid JSON response"`, and a
|
|
257
|
+
* mismatch reports `body: "[REDACTED]"` and the schema error without the
|
|
258
|
+
* value it found (`withholdActual`).
|
|
259
|
+
*
|
|
260
|
+
* Synchronous, for protocols that already hold the calling fiber's context;
|
|
261
|
+
* {@link validateSuccess} is the `Effect` form.
|
|
262
|
+
*/
|
|
263
|
+
export const checkSuccess = (
|
|
264
|
+
context: Context.Context<any>,
|
|
265
|
+
outputAst: AST.AST,
|
|
266
|
+
read: SuccessBody,
|
|
267
|
+
): SuccessCheck => {
|
|
268
|
+
const sensitive = hasSensitiveMember(outputAst);
|
|
269
|
+
if (read.nonJson && sensitive) {
|
|
270
|
+
return { ok: false, error: { body: "[REDACTED]", cause: "Invalid JSON response" } };
|
|
271
|
+
}
|
|
272
|
+
const invalid = checkResponse(context, outputAst, read.value);
|
|
273
|
+
if (invalid !== undefined) {
|
|
274
|
+
return {
|
|
275
|
+
ok: false,
|
|
276
|
+
error: sensitive
|
|
277
|
+
? { body: "[REDACTED]", cause: withholdActual(invalid) }
|
|
278
|
+
: { body: read.body, cause: invalid },
|
|
279
|
+
};
|
|
307
280
|
}
|
|
308
|
-
|
|
309
|
-
return result;
|
|
281
|
+
return { ok: true, value: sensitive ? wrapSensitive(outputAst, read.value) : read.value };
|
|
310
282
|
};
|
|
311
|
-
|
|
283
|
+
|
|
284
|
+
/**
|
|
285
|
+
* {@link checkSuccess} on the calling fiber, failing with `parseError` (the
|
|
286
|
+
* SDK's `<Sdk>ParseError`) built from the withheld-or-not fields.
|
|
287
|
+
*/
|
|
288
|
+
export const validateSuccess = <E>(
|
|
289
|
+
outputAst: AST.AST,
|
|
290
|
+
read: SuccessBody,
|
|
291
|
+
parseError: (info: RestParseErrorInfo) => E,
|
|
292
|
+
): Effect.Effect<unknown, E> =>
|
|
293
|
+
Effect.withFiber((fiber) => {
|
|
294
|
+
const checked = checkSuccess(fiber.context as Context.Context<any>, outputAst, read);
|
|
295
|
+
return checked.ok ? Effect.succeed(checked.value) : Effect.fail(parseError(checked.error));
|
|
296
|
+
});
|
|
312
297
|
|
|
313
298
|
/** Per-operation decode facts, read from the output schema once. */
|
|
314
299
|
interface DecodePlan {
|
|
315
300
|
readonly binary: boolean;
|
|
316
301
|
readonly verbatim: boolean;
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
302
|
+
/**
|
|
303
|
+
* A member of a structure output that receives the whole body
|
|
304
|
+
* (`T.RawResponse()` next to header members), e.g. a bare JSON array with
|
|
305
|
+
* its next-page token in a response header.
|
|
306
|
+
*/
|
|
307
|
+
readonly bodyMember: AST.PropertySignature | undefined;
|
|
308
|
+
/** The output is a bare string, so an empty body decodes to `""`. */
|
|
309
|
+
readonly text: boolean;
|
|
320
310
|
/** Members read from response headers (`T.Header`). */
|
|
321
311
|
readonly headers: ReadonlyArray<ResponseHeaderMember>;
|
|
322
312
|
}
|
|
@@ -328,9 +318,9 @@ const decodePlanFor = (outputAst: AST.AST): DecodePlan => {
|
|
|
328
318
|
plan = {
|
|
329
319
|
binary: getAnn(outputAst, binaryResponseSymbol) !== undefined,
|
|
330
320
|
verbatim: mapsVerbatim(outputAst, "decode"),
|
|
331
|
-
|
|
332
|
-
withholdBody: hasSensitiveMember(outputAst),
|
|
321
|
+
text: resolveNode(outputAst)._tag === "String",
|
|
333
322
|
headers: responseHeaderMembers(outputAst),
|
|
323
|
+
bodyMember: getProps(outputAst).find((prop) => hasPropAnn(prop, rawResponseSymbol)),
|
|
334
324
|
};
|
|
335
325
|
decodePlans.set(outputAst, plan);
|
|
336
326
|
}
|
|
@@ -369,12 +359,15 @@ export const makeRestProtocol = <C>(options: RestProtocolOptions<C>): Layer.Laye
|
|
|
369
359
|
f,
|
|
370
360
|
);
|
|
371
361
|
|
|
372
|
-
/**
|
|
362
|
+
/**
|
|
363
|
+
* The request; fails with the error a refusing `baseUrl` threw, or with
|
|
364
|
+
* `InvalidInput` for a label that would address another resource.
|
|
365
|
+
*/
|
|
373
366
|
const requestFor = (
|
|
374
367
|
creds: C,
|
|
375
368
|
input: unknown,
|
|
376
369
|
inputAst: AST.AST,
|
|
377
|
-
): HttpClientRequest.HttpClientRequest
|
|
370
|
+
): Effect.Effect<HttpClientRequest.HttpClientRequest> => {
|
|
378
371
|
const http = getAnn(inputAst, httpSymbol) as HttpTrait | undefined;
|
|
379
372
|
let baseUrl: string;
|
|
380
373
|
try {
|
|
@@ -386,7 +379,7 @@ export const makeRestProtocol = <C>(options: RestProtocolOptions<C>): Layer.Laye
|
|
|
386
379
|
// A baseUrl that refuses the route (missing scope in the
|
|
387
380
|
// credentials) fails the call with that error, typed for callers by
|
|
388
381
|
// the operation's declared error channel.
|
|
389
|
-
return
|
|
382
|
+
return fail(e);
|
|
390
383
|
}
|
|
391
384
|
return buildRequest({
|
|
392
385
|
input: unwrapRedactedDeep(input),
|
|
@@ -395,7 +388,8 @@ export const makeRestProtocol = <C>(options: RestProtocolOptions<C>): Layer.Laye
|
|
|
395
388
|
headers: options.headers(creds),
|
|
396
389
|
mapMemberHeader: options.mapMemberHeader,
|
|
397
390
|
unknownKeyToWire: options.unknownKeyToWire,
|
|
398
|
-
|
|
391
|
+
emptyJsonBody: options.emptyJsonBody,
|
|
392
|
+
}) as Effect.Effect<HttpClientRequest.HttpClientRequest>;
|
|
399
393
|
};
|
|
400
394
|
|
|
401
395
|
/** Map a read response body to the call's outcome. */
|
|
@@ -408,9 +402,6 @@ export const makeRestProtocol = <C>(options: RestProtocolOptions<C>): Layer.Laye
|
|
|
408
402
|
errorClasses: ReadonlyArray<unknown>,
|
|
409
403
|
): Decoded => {
|
|
410
404
|
// Read as text and parse tolerantly -- error pages are often non-JSON.
|
|
411
|
-
if (debugHttp()) {
|
|
412
|
-
console.error(`[distilled] <- ${status}`);
|
|
413
|
-
}
|
|
414
405
|
let json: unknown;
|
|
415
406
|
let nonJson = false;
|
|
416
407
|
if (text.trim().length > 0) {
|
|
@@ -425,6 +416,18 @@ export const makeRestProtocol = <C>(options: RestProtocolOptions<C>): Layer.Laye
|
|
|
425
416
|
const env = (nonJson ? undefined : errorEnvelope(json)) ?? {};
|
|
426
417
|
const message = env.message ?? (nonJson && text.trim() ? text.trim() : `HTTP ${status}`);
|
|
427
418
|
|
|
419
|
+
// 0. The provider's own reading of the failure.
|
|
420
|
+
if (options.classifyError) {
|
|
421
|
+
const classified = options.classifyError({
|
|
422
|
+
status,
|
|
423
|
+
code: env.code,
|
|
424
|
+
message,
|
|
425
|
+
body: nonJson ? text : json,
|
|
426
|
+
headers,
|
|
427
|
+
});
|
|
428
|
+
if (classified !== undefined) return { ok: false, error: classified };
|
|
429
|
+
}
|
|
430
|
+
|
|
428
431
|
// 1. Per-operation typed error (matcher metadata on the class).
|
|
429
432
|
const typed = matchTypedError(
|
|
430
433
|
errorClasses,
|
|
@@ -486,30 +489,20 @@ export const makeRestProtocol = <C>(options: RestProtocolOptions<C>): Layer.Laye
|
|
|
486
489
|
// with sensitive members, a non-JSON body fails in every mode and parse
|
|
487
490
|
// errors withhold the body.
|
|
488
491
|
const plan = decodePlanFor(outputAst);
|
|
489
|
-
|
|
490
|
-
return {
|
|
491
|
-
ok: false,
|
|
492
|
-
error: options.parseError({ body: "[REDACTED]", cause: "Invalid JSON response" }),
|
|
493
|
-
};
|
|
494
|
-
}
|
|
495
|
-
let body: unknown = nonJson ? text : (json ?? {});
|
|
492
|
+
let body: unknown = nonJson ? text : (json ?? (plan.text ? "" : {}));
|
|
496
493
|
if (options.transformResponse) body = options.transformResponse(body);
|
|
497
|
-
const mapped =
|
|
498
|
-
plan.
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
}),
|
|
510
|
-
};
|
|
511
|
-
}
|
|
512
|
-
return { ok: true, value: plan.sensitive ? wrapSensitive(outputAst, mapped) : mapped };
|
|
494
|
+
const mapped =
|
|
495
|
+
plan.bodyMember !== undefined
|
|
496
|
+
? { [plan.bodyMember.name]: mapKeys(plan.bodyMember.type, body, "decode") }
|
|
497
|
+
: plan.verbatim
|
|
498
|
+
? body
|
|
499
|
+
: mapKeys(outputAst, body, "decode");
|
|
500
|
+
const checked = checkSuccess(context, outputAst, {
|
|
501
|
+
value: withResponseHeaders(plan.headers, mapped, headers),
|
|
502
|
+
body: nonJson ? text : json,
|
|
503
|
+
nonJson,
|
|
504
|
+
});
|
|
505
|
+
return checked.ok ? checked : { ok: false, error: options.parseError(checked.error) };
|
|
513
506
|
};
|
|
514
507
|
|
|
515
508
|
const decodeResponse = (
|
|
@@ -518,32 +511,32 @@ export const makeRestProtocol = <C>(options: RestProtocolOptions<C>): Layer.Laye
|
|
|
518
511
|
outputAst: AST.AST,
|
|
519
512
|
errorClasses: ReadonlyArray<unknown>,
|
|
520
513
|
): Effect.Effect<unknown> =>
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
})
|
|
514
|
+
// A body read that fails (reset or abort mid-body) fails the call with
|
|
515
|
+
// its `HttpClientError`, which every operation's error channel declares.
|
|
516
|
+
(response.status >= 200 && response.status < 300 && decodePlanFor(outputAst).binary
|
|
517
|
+
? Effect.map(response.arrayBuffer, (bytes) => new Uint8Array(bytes))
|
|
518
|
+
: Effect.flatMap(response.text, (text) => {
|
|
519
|
+
recordPageHeaders(context, response.headers);
|
|
520
|
+
const decoded = decodeText(
|
|
521
|
+
context,
|
|
522
|
+
response.status,
|
|
523
|
+
response.headers as Record<string, string | undefined>,
|
|
524
|
+
text ?? "",
|
|
525
|
+
outputAst,
|
|
526
|
+
errorClasses,
|
|
527
|
+
);
|
|
528
|
+
return decoded.ok ? Effect.succeed(decoded.value) : fail(decoded.error);
|
|
529
|
+
})) as Effect.Effect<unknown>;
|
|
537
530
|
|
|
538
531
|
const call = (op: API.PreparedOperation, input: unknown): Effect.Effect<unknown> =>
|
|
539
532
|
Effect.withFiber((fiber) => {
|
|
540
533
|
const context = fiber.context as Context.Context<any>;
|
|
541
534
|
return withCredentials(context, (creds) => {
|
|
542
|
-
const request = requestFor(creds, input, op.inputAst);
|
|
543
|
-
if ("refused" in request) return fail(request.refused);
|
|
544
535
|
const client = Context.get(context, HttpClient.HttpClient);
|
|
545
|
-
return Effect.flatMap(
|
|
546
|
-
|
|
536
|
+
return Effect.flatMap(requestFor(creds, input, op.inputAst), (request) =>
|
|
537
|
+
Effect.flatMap(Telemetry.execute(context, client, request), (response) =>
|
|
538
|
+
decodeResponse(context, response, op.outputAst, op.errors),
|
|
539
|
+
),
|
|
547
540
|
);
|
|
548
541
|
});
|
|
549
542
|
}) as Effect.Effect<unknown>;
|
|
@@ -555,10 +548,9 @@ export const makeRestProtocol = <C>(options: RestProtocolOptions<C>): Layer.Laye
|
|
|
555
548
|
// fiber; see RestProtocolOptions.credentials).
|
|
556
549
|
encode: ({ input, inputAst }) =>
|
|
557
550
|
Effect.withFiber((fiber) =>
|
|
558
|
-
withCredentials(fiber.context as Context.Context<any>, (creds) =>
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
}),
|
|
551
|
+
withCredentials(fiber.context as Context.Context<any>, (creds) =>
|
|
552
|
+
requestFor(creds, input, inputAst),
|
|
553
|
+
),
|
|
562
554
|
) as Effect.Effect<HttpClientRequest.HttpClientRequest>,
|
|
563
555
|
decode: ({ response, outputAst, errors }) =>
|
|
564
556
|
Effect.withFiber((fiber) =>
|
|
@@ -7,9 +7,10 @@
|
|
|
7
7
|
* lenient (default): the response is returned as the protocol read it.
|
|
8
8
|
* A body that does not match the declared output type
|
|
9
9
|
* (a missing member, a wrong primitive, a non-JSON
|
|
10
|
-
* body) still succeeds, except that
|
|
11
|
-
*
|
|
12
|
-
*
|
|
10
|
+
* body) still succeeds, except that a non-JSON body for
|
|
11
|
+
* an output with sensitive members fails in every mode
|
|
12
|
+
* (REST-style protocols through core's `checkSuccess`
|
|
13
|
+
* in `protocol-rest`, plus ZeroSSL and AWS).
|
|
13
14
|
* additionalProperties: the response is checked against the output
|
|
14
15
|
* schema, and a mismatch fails the call with the SDK's
|
|
15
16
|
* `<Sdk>ParseError` (AWS: `ParseError`). Keys the
|
|
@@ -40,7 +41,7 @@ import * as Context from "effect/Context";
|
|
|
40
41
|
import * as Effect from "effect/Effect";
|
|
41
42
|
import * as Layer from "effect/Layer";
|
|
42
43
|
import type * as AST from "effect/SchemaAST";
|
|
43
|
-
import { type Decode, decoderFor,
|
|
44
|
+
import { type Decode, decoderFor, SchemaMismatch } from "./response-validation-strict.ts";
|
|
44
45
|
|
|
45
46
|
export { SchemaMismatch, withholdActual } from "./response-validation-strict.ts";
|
|
46
47
|
|
|
@@ -142,7 +143,9 @@ export const checkResponse = (
|
|
|
142
143
|
if (mode === "lenient") return undefined;
|
|
143
144
|
const decoderOf = Context.get(context, StrictDecoder);
|
|
144
145
|
if (!decoderOf) {
|
|
145
|
-
|
|
146
|
+
// The mode was set without the layer that brings its decoder: the
|
|
147
|
+
// response can't be checked, so the call fails as a mismatch.
|
|
148
|
+
return new SchemaMismatch([], `the ResponseValidation.${mode} layer`, mode);
|
|
146
149
|
}
|
|
147
150
|
return decoderOf(outputAst, mode === "strict")(value);
|
|
148
151
|
};
|
package/src/sdk-error.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The error an operation fails with when the SDK itself cannot make the
|
|
3
|
+
* call: its generated config or a core module is broken (a paginated
|
|
4
|
+
* operation without the fields its strategy reads, a gRPC operation
|
|
5
|
+
* without a descriptor, ...), or one of its own modules fails to load. No
|
|
6
|
+
* input or response causes it; the generator refuses the configs that
|
|
7
|
+
* would. It is typed, so it fails the call instead of crashing the fiber,
|
|
8
|
+
* and it is never retried.
|
|
9
|
+
*
|
|
10
|
+
* Defined on its own, in core's `base` bundle group, so pagination and
|
|
11
|
+
* the protocols fail with it without importing the REST modules.
|
|
12
|
+
*/
|
|
13
|
+
import * as Effect from "effect/Effect";
|
|
14
|
+
import * as Schema from "./schema-lite-typed.ts";
|
|
15
|
+
|
|
16
|
+
export class SdkError
|
|
17
|
+
extends /*@__PURE__*/ Schema.TaggedError<SdkError>()("SdkError", {
|
|
18
|
+
message: Schema.String,
|
|
19
|
+
}) {}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Load one of the SDK's own modules on first use (`() => import("./x.ts")`).
|
|
23
|
+
* A rejected import -- a chunk missing from a bundle, a browser chunk that
|
|
24
|
+
* fails to download -- fails with {@link SdkError}.
|
|
25
|
+
*/
|
|
26
|
+
export const loadModule = <A>(load: () => PromiseLike<A>): Effect.Effect<A, SdkError> =>
|
|
27
|
+
Effect.tryPromise({
|
|
28
|
+
try: () => load(),
|
|
29
|
+
catch: (cause) =>
|
|
30
|
+
new SdkError({
|
|
31
|
+
message: `an SDK module failed to load: ${cause instanceof Error ? cause.message : String(cause)}`,
|
|
32
|
+
}),
|
|
33
|
+
});
|