@distilled.cloud/core 1.0.0-rc.2 → 1.0.0-rc.21
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/LICENSE +201 -0
- package/README.md +33 -0
- package/lib/_bundle/aws.js +2 -0
- package/lib/_bundle/aws.js.map +1 -0
- package/lib/_bundle/base.js +5 -0
- package/lib/_bundle/base.js.map +1 -0
- package/lib/_bundle/graphql.js +3 -0
- package/lib/_bundle/graphql.js.map +1 -0
- package/lib/_bundle/grpc.js +3 -0
- package/lib/_bundle/grpc.js.map +1 -0
- package/lib/_bundle/rest.js +2 -0
- package/lib/_bundle/rest.js.map +1 -0
- package/lib/_bundle/xml.js +4 -0
- package/lib/_bundle/xml.js.map +1 -0
- 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 +220 -51
- package/lib/api.d.ts.map +1 -1
- package/lib/api.js +1 -178
- package/lib/category.d.ts +19 -16
- package/lib/category.d.ts.map +1 -1
- package/lib/category.js +1 -280
- package/lib/chunks.d.ts +3 -0
- package/lib/chunks.d.ts.map +1 -0
- package/lib/chunks.js +1 -0
- package/lib/config.d.ts +81 -0
- package/lib/config.d.ts.map +1 -0
- package/lib/config.js +1 -0
- package/lib/crypto.d.ts +76 -0
- package/lib/crypto.d.ts.map +1 -0
- package/lib/crypto.js +1 -0
- package/lib/error-category.d.ts +1 -1
- package/lib/error-category.d.ts.map +1 -1
- package/lib/error-category.js +1 -46
- package/lib/errors.d.ts +99 -74
- package/lib/errors.d.ts.map +1 -1
- package/lib/errors.js +1 -186
- package/lib/graphql.d.ts +420 -0
- package/lib/graphql.d.ts.map +1 -0
- package/lib/graphql.js +1 -0
- package/lib/graphql.types.d.ts +11 -0
- package/lib/graphql.types.d.ts.map +1 -0
- package/lib/graphql.types.js +1 -0
- 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 +111 -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 +32 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +17 -0
- package/lib/max-message-bytes.d.ts +42 -0
- package/lib/max-message-bytes.d.ts.map +1 -0
- package/lib/max-message-bytes.js +2 -0
- package/lib/max-message-bytes.js.map +1 -0
- package/lib/ndjson.d.ts +3 -0
- package/lib/ndjson.d.ts.map +1 -0
- package/lib/ndjson.js +2 -0
- package/lib/ndjson.js.map +1 -0
- package/lib/pagination.d.ts +105 -25
- package/lib/pagination.d.ts.map +1 -1
- package/lib/pagination.js +1 -182
- package/lib/plain-values.d.ts +21 -0
- package/lib/plain-values.d.ts.map +1 -0
- package/lib/plain-values.js +2 -0
- package/lib/plain-values.js.map +1 -0
- package/lib/protobuf.d.ts +85 -0
- package/lib/protobuf.d.ts.map +1 -0
- package/lib/protobuf.js +1 -0
- package/lib/protocol-grpc.d.ts +123 -0
- package/lib/protocol-grpc.d.ts.map +1 -0
- package/lib/protocol-grpc.js +1 -0
- package/lib/protocol-http.d.ts +206 -25
- package/lib/protocol-http.d.ts.map +1 -1
- package/lib/protocol-http.js +1 -554
- package/lib/protocol-rest.d.ts +258 -64
- package/lib/protocol-rest.d.ts.map +1 -1
- package/lib/protocol-rest.js +1 -242
- package/lib/protocol.d.ts +113 -0
- package/lib/protocol.d.ts.map +1 -0
- package/lib/protocol.js +0 -0
- package/lib/query.d.ts +29 -0
- package/lib/query.d.ts.map +1 -0
- package/lib/query.js +1 -0
- 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 +1 -0
- package/lib/response-validation.d.ts +86 -0
- package/lib/response-validation.d.ts.map +1 -0
- package/lib/response-validation.js +1 -0
- package/lib/retry-after.d.ts +4 -4
- package/lib/retry-after.d.ts.map +1 -1
- package/lib/retry-after.js +1 -112
- package/lib/retry-state.d.ts +26 -0
- package/lib/retry-state.d.ts.map +1 -0
- package/lib/retry-state.js +2 -0
- package/lib/retry-state.js.map +1 -0
- package/lib/retry.d.ts +141 -42
- package/lib/retry.d.ts.map +1 -1
- package/lib/retry.js +1 -210
- package/lib/schema-lite-impl.d.ts +179 -0
- package/lib/schema-lite-impl.d.ts.map +1 -0
- package/lib/schema-lite-impl.js +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 +1 -0
- package/lib/schema-lite.d.ts +41 -0
- package/lib/schema-lite.d.ts.map +1 -0
- package/lib/schema-lite.js +1 -0
- package/lib/schema.d.ts +21 -7
- package/lib/schema.d.ts.map +1 -1
- package/lib/schema.js +1 -48
- package/lib/sdk-error.d.ts +31 -0
- package/lib/sdk-error.d.ts.map +1 -0
- package/lib/sdk-error.js +1 -0
- package/lib/send.d.ts +37 -0
- package/lib/send.d.ts.map +1 -0
- package/lib/send.js +2 -0
- package/lib/send.js.map +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 +317 -0
- package/lib/telemetry.d.ts.map +1 -0
- package/lib/telemetry.js +3 -0
- package/lib/telemetry.js.map +1 -0
- package/lib/token-cache.d.ts +31 -0
- package/lib/token-cache.d.ts.map +1 -0
- package/lib/token-cache.js +2 -0
- package/lib/token-cache.js.map +1 -0
- package/lib/trait.d.ts +94 -20
- package/lib/trait.d.ts.map +1 -1
- package/lib/trait.js +1 -107
- package/lib/unknown-error.d.ts +18 -0
- package/lib/unknown-error.d.ts.map +1 -0
- package/lib/unknown-error.js +1 -0
- package/lib/xml.d.ts +44 -0
- package/lib/xml.d.ts.map +1 -0
- package/lib/xml.js +1 -0
- package/package.json +13 -13
- package/src/annotations.ts +53 -0
- package/src/api.ts +1597 -234
- package/src/category.ts +97 -134
- package/src/chunks.ts +30 -0
- package/src/config.ts +261 -0
- package/src/crypto.ts +202 -0
- package/src/error-category.ts +16 -29
- package/src/errors.ts +99 -77
- package/src/graphql.ts +1817 -0
- package/src/graphql.types.ts +120 -0
- package/src/grpc-transport-cloudflare-http2.ts +569 -0
- package/src/grpc-transport-cloudflare-sockets.ts +368 -0
- package/src/grpc-transport-node-http2.ts +307 -0
- package/src/grpc-transport.ts +287 -0
- package/src/hpack.ts +331 -0
- package/src/index.ts +31 -0
- package/src/max-message-bytes.ts +58 -0
- package/src/ndjson.ts +55 -0
- package/src/pagination.ts +379 -94
- package/src/plain-values.ts +70 -0
- package/src/protobuf.ts +1367 -0
- package/src/protocol-grpc.ts +811 -0
- package/src/protocol-http.ts +1045 -371
- package/src/protocol-rest.ts +908 -255
- package/src/protocol.ts +150 -0
- package/src/query.ts +39 -0
- package/src/response-validation-strict.ts +333 -0
- package/src/response-validation.ts +161 -0
- package/src/retry-after.ts +8 -14
- package/src/retry-state.ts +105 -0
- package/src/retry.ts +260 -145
- package/src/schema-lite-impl.ts +621 -0
- package/src/schema-lite-typed.ts +44 -0
- package/src/schema-lite.ts +45 -0
- package/src/schema.ts +259 -15
- package/src/sdk-error.ts +37 -0
- package/src/send.ts +156 -0
- package/src/sensitive.ts +188 -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 +800 -0
- package/src/token-cache.ts +117 -0
- package/src/trait.ts +139 -67
- package/src/unknown-error.ts +38 -0
- package/src/xml.ts +346 -0
- package/lib/api.js.map +0 -1
- package/lib/category.js.map +0 -1
- package/lib/codegen/cli.d.ts +0 -29
- package/lib/codegen/cli.d.ts.map +0 -1
- package/lib/codegen/cli.js +0 -165
- package/lib/codegen/cli.js.map +0 -1
- package/lib/codegen/emit.d.ts +0 -129
- package/lib/codegen/emit.d.ts.map +0 -1
- package/lib/codegen/emit.js +0 -105
- package/lib/codegen/emit.js.map +0 -1
- package/lib/codegen/format.d.ts +0 -23
- package/lib/codegen/format.d.ts.map +0 -1
- package/lib/codegen/format.js +0 -28
- package/lib/codegen/format.js.map +0 -1
- package/lib/codegen/generator.d.ts +0 -334
- package/lib/codegen/generator.d.ts.map +0 -1
- package/lib/codegen/generator.js +0 -691
- 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/members.d.ts +0 -25
- package/lib/codegen/members.d.ts.map +0 -1
- package/lib/codegen/members.js +0 -55
- package/lib/codegen/members.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 -38
- package/lib/codegen/openapi-cli.d.ts.map +0 -1
- package/lib/codegen/openapi-cli.js +0 -107
- package/lib/codegen/openapi-cli.js.map +0 -1
- package/lib/codegen/openapi.d.ts +0 -115
- package/lib/codegen/openapi.d.ts.map +0 -1
- package/lib/codegen/openapi.js +0 -1220
- 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 -33
- package/lib/codegen/pagination.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/error-category.js.map +0 -1
- package/lib/errors.js.map +0 -1
- package/lib/json-patch.d.ts +0 -44
- package/lib/json-patch.d.ts.map +0 -1
- package/lib/json-patch.js +0 -174
- package/lib/json-patch.js.map +0 -1
- package/lib/pagination.js.map +0 -1
- package/lib/protocol-http.js.map +0 -1
- package/lib/protocol-rest.js.map +0 -1
- package/lib/retry-after.js.map +0 -1
- package/lib/retry.js.map +0 -1
- package/lib/schema.js.map +0 -1
- package/lib/trait.js.map +0 -1
- package/src/codegen/cli.ts +0 -268
- package/src/codegen/emit.ts +0 -207
- package/src/codegen/format.ts +0 -47
- package/src/codegen/generator.ts +0 -1153
- package/src/codegen/graph.ts +0 -151
- package/src/codegen/members.ts +0 -71
- package/src/codegen/naming.ts +0 -86
- package/src/codegen/openapi-cli.ts +0 -166
- package/src/codegen/openapi.ts +0 -1450
- package/src/codegen/operations.ts +0 -76
- package/src/codegen/pagination.ts +0 -71
- package/src/codegen/prelude.ts +0 -70
- package/src/json-patch.ts +0 -222
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Effect Schema's API surface for generated code, backed by lite schemas
|
|
3
|
+
* (see `schema-lite-impl.ts`): the same names and types as
|
|
4
|
+
* `@distilled.cloud/core/schema`, without importing Effect Schema at runtime.
|
|
5
|
+
*/
|
|
6
|
+
import type * as S from "effect/Schema";
|
|
7
|
+
import * as L from "./schema-lite-impl.ts";
|
|
8
|
+
|
|
9
|
+
export type * from "effect/Schema";
|
|
10
|
+
export type AnyFn = (...args: any[]) => any;
|
|
11
|
+
|
|
12
|
+
export const optional: AnyFn = L.optional;
|
|
13
|
+
export const Struct: AnyFn = L.Struct;
|
|
14
|
+
export const StructWithRest: AnyFn = L.StructWithRest;
|
|
15
|
+
export const Extend: AnyFn = L.Extend;
|
|
16
|
+
export const suspend: AnyFn = L.suspend;
|
|
17
|
+
export const Array: AnyFn = L.Array;
|
|
18
|
+
export const Record: AnyFn = L.Record;
|
|
19
|
+
export const Union: AnyFn = L.Union;
|
|
20
|
+
export const Literal: AnyFn = L.Literal;
|
|
21
|
+
export const Literals: AnyFn = L.Literals;
|
|
22
|
+
export const NullOr: AnyFn = L.NullOr;
|
|
23
|
+
export const Tuple: AnyFn = L.Tuple;
|
|
24
|
+
export const encodeKeys: AnyFn = L.encodeKeys;
|
|
25
|
+
export const declare: typeof S.declare = L.declare as unknown as typeof S.declare;
|
|
26
|
+
export const instanceOf: AnyFn = L.instanceOf;
|
|
27
|
+
export const Redacted: AnyFn = L.Redacted;
|
|
28
|
+
|
|
29
|
+
export const String: any = L.String;
|
|
30
|
+
export const Number: any = L.Number;
|
|
31
|
+
export const Int: any = L.Number;
|
|
32
|
+
export const Boolean: any = L.Boolean;
|
|
33
|
+
export const Date: any = L.Date;
|
|
34
|
+
export const Duration: any = L.Duration;
|
|
35
|
+
export const Unknown: any = L.Unknown;
|
|
36
|
+
export const Null: any = L.Null;
|
|
37
|
+
export const Void: any = L.Void;
|
|
38
|
+
export const Any: any = L.Any;
|
|
39
|
+
|
|
40
|
+
export const TaggedError = L.TaggedError as unknown as L.TaggedErrorFactory;
|
|
41
|
+
export type { TaggedErrorClass, TaggedErrorFactory } from "./schema-lite-impl.ts";
|
|
42
|
+
|
|
43
|
+
/** Lite `chunks.at`: generated services name this module `__L`. */
|
|
44
|
+
export const at = L.at;
|
|
45
|
+
export { liteKey, toEffect } from "./schema-lite-impl.ts";
|
package/src/schema.ts
CHANGED
|
@@ -5,32 +5,39 @@
|
|
|
5
5
|
* provider package via `@distilled.cloud/core/schema`. Do not copy it into
|
|
6
6
|
* individual packages.
|
|
7
7
|
*
|
|
8
|
-
* Every real TYPE (`Schema`, `Codec`, `Top`,
|
|
8
|
+
* Every real TYPE (`Schema`, `Codec`, `Top`, ...) is re-exported untouched, so
|
|
9
9
|
* the `Schema.Schema<Foo>` annotations on generated consts (and the public
|
|
10
10
|
* `.d.ts`) stay precise. The schema *construction surface* (`Struct`,
|
|
11
|
-
* `optional`, `suspend`,
|
|
11
|
+
* `optional`, `suspend`, ...) and the leaf scalar schemas are retyped to `any`,
|
|
12
12
|
* so the compiler instantiates none of the heavy Schema generics while
|
|
13
|
-
* building a service file
|
|
13
|
+
* building a service file -- the explicit annotations carry the real types.
|
|
14
14
|
*
|
|
15
15
|
* Overriding a *value* export never affects the same-named *type* export (they
|
|
16
16
|
* live in separate namespaces and continue to flow through `export *`), so
|
|
17
17
|
* `Schema.Literal<"x">`-style type usages remain precise.
|
|
18
18
|
*
|
|
19
|
-
* Runtime behaviour is identical
|
|
20
|
-
* runtime value from `effect/Schema
|
|
19
|
+
* Runtime behaviour is identical. Every override aliases the exact same
|
|
20
|
+
* runtime value from `effect/Schema`, except `suspend`, `Array` and
|
|
21
|
+
* `Record`, which build the same schema lazily (see "Lazy schemas").
|
|
21
22
|
*/
|
|
22
|
-
export
|
|
23
|
+
// Types only: a value `export *` costs one binding per Effect Schema export
|
|
24
|
+
// (345 of them, ~70 KB) in every process that imports an SDK. The values
|
|
25
|
+
// generated and hand-written code use are re-exported explicitly below.
|
|
26
|
+
export type * from "effect/Schema";
|
|
27
|
+
export { declare, Duration, instanceOf, Redacted } from "effect/Schema";
|
|
23
28
|
|
|
29
|
+
import { pipeArguments } from "effect/Pipeable";
|
|
24
30
|
import * as S from "effect/Schema";
|
|
25
31
|
|
|
26
|
-
type AnyFn = (...args: any[]) => any;
|
|
32
|
+
export type AnyFn = (...args: any[]) => any;
|
|
27
33
|
|
|
28
|
-
// Construction surface
|
|
34
|
+
// Construction surface -- collapse to `any` so generics are never instantiated.
|
|
29
35
|
export const optional: AnyFn = S.optional as AnyFn;
|
|
30
36
|
export const Struct: AnyFn = S.Struct as AnyFn;
|
|
31
|
-
export const
|
|
32
|
-
export const
|
|
33
|
-
export const
|
|
37
|
+
export const StructWithRest: AnyFn = S.StructWithRest as AnyFn;
|
|
38
|
+
export const suspend: AnyFn = (f: () => S.Top) => lazySuspend(f);
|
|
39
|
+
export const Array: AnyFn = (item: S.Top) => lazyArray(item);
|
|
40
|
+
export const Record: AnyFn = (key: S.Top, value: S.Top) => lazyRecord(key, value);
|
|
34
41
|
export const Union: AnyFn = S.Union as AnyFn;
|
|
35
42
|
export const Literal: AnyFn = S.Literal as AnyFn;
|
|
36
43
|
export const Literals: AnyFn = S.Literals as AnyFn;
|
|
@@ -38,7 +45,7 @@ export const NullOr: AnyFn = S.NullOr as AnyFn;
|
|
|
38
45
|
export const Tuple: AnyFn = S.Tuple as AnyFn;
|
|
39
46
|
export const encodeKeys: AnyFn = S.encodeKeys as AnyFn;
|
|
40
47
|
|
|
41
|
-
// Leaf schemas
|
|
48
|
+
// Leaf schemas -- collapse to `any` so `.pipe(...)` on them is free.
|
|
42
49
|
export const String: any = S.String;
|
|
43
50
|
export const Number: any = S.Number;
|
|
44
51
|
export const Boolean: any = S.Boolean;
|
|
@@ -48,6 +55,243 @@ export const Null: any = S.Null;
|
|
|
48
55
|
export const Void: any = S.Void;
|
|
49
56
|
export const Any: any = S.Any;
|
|
50
57
|
|
|
51
|
-
// NOTE: `Schema` / `Codec` (types)
|
|
52
|
-
//
|
|
53
|
-
//
|
|
58
|
+
// NOTE: `Schema` / `Codec` (types) are intentionally NOT overridden -- they
|
|
59
|
+
// flow through `export *` with real types so cast targets stay precise.
|
|
60
|
+
// `TaggedError` is overridden with the same type (see "Lazy error classes").
|
|
61
|
+
|
|
62
|
+
//#region Lazy schemas
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Schemas whose real Effect schema is built on first use instead of at
|
|
66
|
+
* import.
|
|
67
|
+
*
|
|
68
|
+
* A service module declares every schema as a top-level const, and
|
|
69
|
+
* importing it constructs all of them: EC2 has 2,575 `S.suspend(...)` and
|
|
70
|
+
* 784 `S.Array(...)` consts, Elasticsearch 3,272 and 2,265. An Effect schema
|
|
71
|
+
* is a function object plus an AST node (a `suspend` also a wrapper
|
|
72
|
+
* closure), and `.annotate` copies both: about 550 bytes per suspend, more
|
|
73
|
+
* for an array whose item it forces. A lazy schema is one small object
|
|
74
|
+
* holding how to build the real one and any annotations added before then:
|
|
75
|
+
* about 180 bytes.
|
|
76
|
+
*
|
|
77
|
+
* It inherits Effect's own schema prototype, so `pipe`, `annotate`, `make`,
|
|
78
|
+
* `isSchema` and every combinator see a schema. On first use of `.ast` (or
|
|
79
|
+
* of an own member such as an array's `value`) it builds the real schema --
|
|
80
|
+
* `build().annotate(annotations)`, exactly what eager code would have made --
|
|
81
|
+
* and copies the real schema's own properties onto itself, so from then on
|
|
82
|
+
* it IS that schema: same AST (memoized, stable identity), same rebuild
|
|
83
|
+
* options for later `.annotate` / `.check` calls.
|
|
84
|
+
*/
|
|
85
|
+
const SchemaProto: object = /*@__PURE__*/ Object.getPrototypeOf(S.String);
|
|
86
|
+
const buildKey = /*@__PURE__*/ Symbol.for("@distilled.cloud/core/schema/build");
|
|
87
|
+
const annotationsKey = /*@__PURE__*/ Symbol.for("@distilled.cloud/core/schema/annotations");
|
|
88
|
+
|
|
89
|
+
type Annotations = Record<string, unknown>;
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* How a lazy schema builds itself: a closure, or a shared builder plus data
|
|
93
|
+
* stored on the schema object (no closure per schema; see packed.ts).
|
|
94
|
+
*/
|
|
95
|
+
export interface LazyBuilder {
|
|
96
|
+
readonly build: (data: unknown) => S.Top;
|
|
97
|
+
}
|
|
98
|
+
const dataKey = /*@__PURE__*/ Symbol.for("@distilled.cloud/core/schema/data");
|
|
99
|
+
|
|
100
|
+
interface LazySchema {
|
|
101
|
+
[buildKey]?: (() => S.Top) | LazyBuilder;
|
|
102
|
+
[dataKey]?: unknown;
|
|
103
|
+
[annotationsKey]?: Annotations;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** Build the real schema and become it. */
|
|
107
|
+
const force = (self: LazySchema): void => {
|
|
108
|
+
const build = self[buildKey];
|
|
109
|
+
if (!build) return;
|
|
110
|
+
const annotations = self[annotationsKey];
|
|
111
|
+
const built = typeof build === "function" ? build() : build.build(self[dataKey]);
|
|
112
|
+
const real = annotations ? built.annotate(annotations) : built;
|
|
113
|
+
delete self[buildKey];
|
|
114
|
+
delete self[dataKey];
|
|
115
|
+
delete self[annotationsKey];
|
|
116
|
+
Object.defineProperties(self, Object.getOwnPropertyDescriptors(real));
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
/** Members a built schema carries as own properties (array item, record key/value). */
|
|
120
|
+
const forwarded = (name: string): PropertyDescriptor => ({
|
|
121
|
+
configurable: true,
|
|
122
|
+
get(this: LazySchema & Record<string, unknown>) {
|
|
123
|
+
if (!this[buildKey]) return undefined;
|
|
124
|
+
force(this);
|
|
125
|
+
return this[name];
|
|
126
|
+
},
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
const LazyProto: object = /*@__PURE__*/ Object.create(SchemaProto, {
|
|
130
|
+
ast: /*@__PURE__*/ forwarded("ast"),
|
|
131
|
+
value: /*@__PURE__*/ forwarded("value"),
|
|
132
|
+
key: /*@__PURE__*/ forwarded("key"),
|
|
133
|
+
annotate: {
|
|
134
|
+
configurable: true,
|
|
135
|
+
writable: true,
|
|
136
|
+
value(this: LazySchema, annotations: Annotations) {
|
|
137
|
+
const build = this[buildKey];
|
|
138
|
+
// Once built, annotate like any schema (a rebuilt copy).
|
|
139
|
+
if (!build) return (SchemaProto as { annotate: Function }).annotate.call(this, annotations);
|
|
140
|
+
const previous = this[annotationsKey];
|
|
141
|
+
return lazy(build, previous ? { ...previous, ...annotations } : annotations, this[dataKey]);
|
|
142
|
+
},
|
|
143
|
+
},
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
// Effect detects schemas by this key on the prototype; if a future Effect
|
|
147
|
+
// moves it, build eagerly.
|
|
148
|
+
const supported = (SchemaProto as Record<string, unknown>)["~effect/Schema/Schema"] !== undefined;
|
|
149
|
+
|
|
150
|
+
const lazy = (
|
|
151
|
+
build: (() => S.Top) | LazyBuilder,
|
|
152
|
+
annotations?: Annotations,
|
|
153
|
+
data?: unknown,
|
|
154
|
+
): S.Top => {
|
|
155
|
+
if (!supported) {
|
|
156
|
+
const built = typeof build === "function" ? build() : build.build(data);
|
|
157
|
+
return annotations ? built.annotate(annotations) : built;
|
|
158
|
+
}
|
|
159
|
+
const self = Object.create(LazyProto);
|
|
160
|
+
self[buildKey] = build;
|
|
161
|
+
if (data !== undefined) self[dataKey] = data;
|
|
162
|
+
if (annotations) self[annotationsKey] = annotations;
|
|
163
|
+
return self;
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
/** A schema built on first use by `builder.build(data)`. */
|
|
167
|
+
export const lazyFrom = (builder: LazyBuilder, data: unknown): S.Top =>
|
|
168
|
+
lazy(builder, undefined, data);
|
|
169
|
+
|
|
170
|
+
const lazySuspend = (f: () => S.Top): S.Top => lazy(() => S.suspend(f));
|
|
171
|
+
const lazyArray = (item: S.Top): S.Top => lazy(() => S.Array(item));
|
|
172
|
+
const lazyRecord = (key: S.Top, value: S.Top): S.Top => lazy(() => S.Record(key as any, value));
|
|
173
|
+
|
|
174
|
+
//#endregion
|
|
175
|
+
|
|
176
|
+
//#region Lazy error classes
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* `S.TaggedError` whose Effect class is built on first use instead of at
|
|
180
|
+
* import.
|
|
181
|
+
*
|
|
182
|
+
* Every error class Effect builds carries its own copies of about fifteen
|
|
183
|
+
* static methods plus a tagged struct schema: about 4.6 KB per class, and
|
|
184
|
+
* AWS EC2 alone declares 248 of them. This returns a small constructor that
|
|
185
|
+
* stands in for the class until something needs it -- constructing an
|
|
186
|
+
* instance, or a schema static such as `ast` / `fields` / `make`. Then it
|
|
187
|
+
* builds the real class with `S.TaggedError` and puts it underneath: the
|
|
188
|
+
* lazy class's prototype starts inheriting from the real prototype, and
|
|
189
|
+
* statics forward to the real class with `this` bound to the lazy class, so
|
|
190
|
+
* decoding produces instances of the lazy class (and of its subclasses).
|
|
191
|
+
*
|
|
192
|
+
* `pipe` (used to attach error categories), `identifier` and the schema
|
|
193
|
+
* marker answer without building. Instances behave as before: same
|
|
194
|
+
* `_tag`, fields, validation, `instanceof`, stack and `Effect.catchTag`.
|
|
195
|
+
*/
|
|
196
|
+
const lazyErrorKey = /*@__PURE__*/ Symbol.for("@distilled.cloud/core/schema/lazyError");
|
|
197
|
+
|
|
198
|
+
interface LazyErrorState {
|
|
199
|
+
readonly identifier: string | undefined;
|
|
200
|
+
readonly args: ReadonlyArray<unknown>;
|
|
201
|
+
readonly lazy: Function;
|
|
202
|
+
real?: Function;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
const SchemaTypeId = "~effect/Schema/Schema";
|
|
206
|
+
|
|
207
|
+
// The base every Effect error class extends (`core.Error`, a yieldable
|
|
208
|
+
// Error). Found on first use, so bundles without error classes do not keep
|
|
209
|
+
// Effect's class machinery.
|
|
210
|
+
let errorBase: Function | undefined;
|
|
211
|
+
const ErrorBase = (): Function =>
|
|
212
|
+
(errorBase ??= Object.getPrototypeOf(S.TaggedError()("Probe", {})) as Function);
|
|
213
|
+
|
|
214
|
+
const realErrorClass = (cls: Function): Function => {
|
|
215
|
+
const state = (cls as unknown as Record<symbol, LazyErrorState>)[lazyErrorKey];
|
|
216
|
+
if (!state.real) {
|
|
217
|
+
const real = (S.TaggedError as Function)(state.identifier)(...state.args) as Function;
|
|
218
|
+
state.real = real;
|
|
219
|
+
Object.setPrototypeOf(state.lazy.prototype, real.prototype);
|
|
220
|
+
}
|
|
221
|
+
return state.real;
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
/** Effect's class statics that need the real class. */
|
|
225
|
+
const FORWARDED_STATICS = [
|
|
226
|
+
"ast",
|
|
227
|
+
"fields",
|
|
228
|
+
"make",
|
|
229
|
+
"makeOption",
|
|
230
|
+
"makeEffect",
|
|
231
|
+
"annotate",
|
|
232
|
+
"annotateKey",
|
|
233
|
+
"check",
|
|
234
|
+
"rebuild",
|
|
235
|
+
"extend",
|
|
236
|
+
"mapFields",
|
|
237
|
+
];
|
|
238
|
+
|
|
239
|
+
let lazyErrorStatics: object | undefined;
|
|
240
|
+
const LazyErrorStatics = (): object =>
|
|
241
|
+
(lazyErrorStatics ??= Object.create(ErrorBase(), {
|
|
242
|
+
[SchemaTypeId]: { value: SchemaTypeId, configurable: true },
|
|
243
|
+
identifier: {
|
|
244
|
+
configurable: true,
|
|
245
|
+
get(this: Record<symbol, LazyErrorState>) {
|
|
246
|
+
const state = this[lazyErrorKey];
|
|
247
|
+
return state.identifier ?? state.args[0];
|
|
248
|
+
},
|
|
249
|
+
},
|
|
250
|
+
pipe: {
|
|
251
|
+
configurable: true,
|
|
252
|
+
writable: true,
|
|
253
|
+
value(this: unknown) {
|
|
254
|
+
return pipeArguments(this, arguments);
|
|
255
|
+
},
|
|
256
|
+
},
|
|
257
|
+
...Object.fromEntries(
|
|
258
|
+
FORWARDED_STATICS.map((name) => [
|
|
259
|
+
name,
|
|
260
|
+
{
|
|
261
|
+
configurable: true,
|
|
262
|
+
get(this: Function) {
|
|
263
|
+
let owner: object | null = realErrorClass(this);
|
|
264
|
+
let descriptor: PropertyDescriptor | undefined;
|
|
265
|
+
while (owner && !(descriptor = Object.getOwnPropertyDescriptor(owner, name))) {
|
|
266
|
+
owner = Object.getPrototypeOf(owner);
|
|
267
|
+
}
|
|
268
|
+
if (!descriptor) return undefined;
|
|
269
|
+
if (descriptor.get) return descriptor.get.call(this);
|
|
270
|
+
return typeof descriptor.value === "function"
|
|
271
|
+
? descriptor.value.bind(this)
|
|
272
|
+
: descriptor.value;
|
|
273
|
+
},
|
|
274
|
+
},
|
|
275
|
+
]),
|
|
276
|
+
),
|
|
277
|
+
}));
|
|
278
|
+
|
|
279
|
+
const lazyTaggedError =
|
|
280
|
+
(identifier?: string) =>
|
|
281
|
+
(...args: ReadonlyArray<unknown>): Function => {
|
|
282
|
+
function LazyTaggedError(this: unknown, input?: unknown, options?: unknown) {
|
|
283
|
+
if (!new.target) throw new TypeError("Class constructor cannot be invoked without 'new'");
|
|
284
|
+
return Reflect.construct(realErrorClass(new.target), [input, options], new.target);
|
|
285
|
+
}
|
|
286
|
+
Object.setPrototypeOf(LazyTaggedError, LazyErrorStatics());
|
|
287
|
+
LazyTaggedError.prototype = Object.create(ErrorBase().prototype, {
|
|
288
|
+
constructor: { value: LazyTaggedError, writable: true, configurable: true },
|
|
289
|
+
});
|
|
290
|
+
const state: LazyErrorState = { identifier, args, lazy: LazyTaggedError };
|
|
291
|
+
Object.defineProperty(LazyTaggedError, lazyErrorKey, { value: state });
|
|
292
|
+
return LazyTaggedError;
|
|
293
|
+
};
|
|
294
|
+
|
|
295
|
+
export const TaggedError: typeof S.TaggedError = lazyTaggedError as typeof S.TaggedError;
|
|
296
|
+
|
|
297
|
+
//#endregion
|
package/src/sdk-error.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
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
|
+
* It is also what a call fails with when something under it threw (the
|
|
11
|
+
* defect boundary, `failed` in `./api.ts`): the message names the operation
|
|
12
|
+
* and what was thrown, and `cause` is the thrown value.
|
|
13
|
+
*
|
|
14
|
+
* Defined on its own, in core's `base` bundle group, so pagination and
|
|
15
|
+
* the protocols fail with it without importing the REST modules.
|
|
16
|
+
*/
|
|
17
|
+
import * as Effect from "effect/Effect";
|
|
18
|
+
import * as Schema from "./schema-lite-typed.ts";
|
|
19
|
+
|
|
20
|
+
export class SdkError
|
|
21
|
+
extends /*@__PURE__*/ Schema.TaggedError<SdkError>()("SdkError", {
|
|
22
|
+
message: Schema.String,
|
|
23
|
+
}) {}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Load one of the SDK's own modules on first use (`() => import("./x.ts")`).
|
|
27
|
+
* A rejected import -- a chunk missing from a bundle, a browser chunk that
|
|
28
|
+
* fails to download -- fails with {@link SdkError}.
|
|
29
|
+
*/
|
|
30
|
+
export const loadModule = <A>(load: () => PromiseLike<A>): Effect.Effect<A, SdkError> =>
|
|
31
|
+
Effect.tryPromise({
|
|
32
|
+
try: () => load(),
|
|
33
|
+
catch: (cause) =>
|
|
34
|
+
new SdkError({
|
|
35
|
+
message: `an SDK module failed to load: ${cause instanceof Error ? cause.message : String(cause)}`,
|
|
36
|
+
}),
|
|
37
|
+
});
|
package/src/send.ts
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Send one HTTP request for an operation: `Telemetry.execute` (spans, trace
|
|
3
|
+
* headers, debug output), plus the facts the retry layer reads after a
|
|
4
|
+
* failure (see `./retry-state.ts`): which host the request went to, whether
|
|
5
|
+
* it succeeded, and the response's bounded retry hint.
|
|
6
|
+
*
|
|
7
|
+
* Every protocol sends through this, so the retry budget and the
|
|
8
|
+
* `x-amz-retry-after` / `x-distilled-retry-after` headers work for all of
|
|
9
|
+
* them. A protocol that calls `client.execute` directly still retries, on
|
|
10
|
+
* the plain backoff, outside the budget.
|
|
11
|
+
*
|
|
12
|
+
* A body it cannot send twice (the caller's own stream) makes the call
|
|
13
|
+
* `oneShot`: the retry layer then never sends it again. A stream body is
|
|
14
|
+
* one-shot unless the protocol says otherwise (S3 replays a Blob's stream).
|
|
15
|
+
*
|
|
16
|
+
* Redirects are followed here, not by `fetch`. `fetch` removes only
|
|
17
|
+
* `Authorization` and `Cookie` when a redirect goes to another origin, so
|
|
18
|
+
* an API key in `x-api-key`, `DD-API-KEY` or `X-Auth-Token` would reach the
|
|
19
|
+
* new host. A hop to the same origin keeps every header; a hop to another
|
|
20
|
+
* origin keeps only {@link CROSS_ORIGIN_HEADERS}. Every `HttpClient` gets
|
|
21
|
+
* the same rule: the Node clients hand a `3xx` back too.
|
|
22
|
+
*/
|
|
23
|
+
import * as Context from "effect/Context";
|
|
24
|
+
import * as Effect from "effect/Effect";
|
|
25
|
+
import * as FetchHttpClient from "effect/http/FetchHttpClient";
|
|
26
|
+
import * as Headers from "effect/http/Headers";
|
|
27
|
+
import * as HttpBody from "effect/http/HttpBody";
|
|
28
|
+
import type * as HttpClient from "effect/http/HttpClient";
|
|
29
|
+
import type * as HttpClientError from "effect/http/HttpClientError";
|
|
30
|
+
import * as HttpClientRequest from "effect/http/HttpClientRequest";
|
|
31
|
+
import type * as HttpClientResponse from "effect/http/HttpClientResponse";
|
|
32
|
+
import * as Url from "effect/http/Url";
|
|
33
|
+
import * as UrlParams from "effect/http/UrlParams";
|
|
34
|
+
import * as Option from "effect/Option";
|
|
35
|
+
import * as Result from "effect/Result";
|
|
36
|
+
import * as RetryState from "./retry-state.ts";
|
|
37
|
+
import * as Telemetry from "./telemetry.ts";
|
|
38
|
+
|
|
39
|
+
/** Redirects followed before the last `3xx` is returned as the response. */
|
|
40
|
+
export const MAX_REDIRECTS = 5;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* The only request headers a redirect to another origin keeps. Credentials,
|
|
44
|
+
* signatures and provider headers are all dropped.
|
|
45
|
+
*/
|
|
46
|
+
export const CROSS_ORIGIN_HEADERS: ReadonlySet<string> = new Set([
|
|
47
|
+
"accept",
|
|
48
|
+
"accept-encoding",
|
|
49
|
+
"accept-language",
|
|
50
|
+
"cache-control",
|
|
51
|
+
"content-language",
|
|
52
|
+
"content-length",
|
|
53
|
+
"content-type",
|
|
54
|
+
"if-match",
|
|
55
|
+
"if-modified-since",
|
|
56
|
+
"if-none-match",
|
|
57
|
+
"if-range",
|
|
58
|
+
"if-unmodified-since",
|
|
59
|
+
"range",
|
|
60
|
+
"user-agent",
|
|
61
|
+
]);
|
|
62
|
+
|
|
63
|
+
// A browser returns an opaque response with no `Location` for
|
|
64
|
+
// `redirect: "manual"`, so there the browser's own redirect rule stays.
|
|
65
|
+
const isBrowser =
|
|
66
|
+
typeof (globalThis as { document?: unknown }).document !== "undefined" ||
|
|
67
|
+
typeof (globalThis as { importScripts?: unknown }).importScripts === "function";
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* The caller's `RequestInit` with `redirect: "manual"`, unless the caller
|
|
71
|
+
* chose a redirect mode. Only the fetch client reads it.
|
|
72
|
+
*/
|
|
73
|
+
const manualRedirects = (context: Context.Context<any>): globalThis.RequestInit | undefined => {
|
|
74
|
+
if (isBrowser) return undefined;
|
|
75
|
+
const init = Context.getOrUndefined(context, FetchHttpClient.RequestInit);
|
|
76
|
+
return init?.redirect !== undefined ? undefined : { ...init, redirect: "manual" };
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* The request for the next hop of a redirect, or `undefined` when the
|
|
81
|
+
* response is not one to follow.
|
|
82
|
+
*/
|
|
83
|
+
const nextHop = (
|
|
84
|
+
request: HttpClientRequest.HttpClientRequest,
|
|
85
|
+
response: HttpClientResponse.HttpClientResponse,
|
|
86
|
+
replayable: boolean,
|
|
87
|
+
): HttpClientRequest.HttpClientRequest | undefined => {
|
|
88
|
+
const status = response.status;
|
|
89
|
+
const location = response.headers.location;
|
|
90
|
+
if (status < 300 || status >= 400 || status === 304 || location === undefined) return undefined;
|
|
91
|
+
const parsed = Url.fromString(location, request.url);
|
|
92
|
+
if (Result.isFailure(parsed)) return undefined;
|
|
93
|
+
const url = parsed.success;
|
|
94
|
+
url.hash = "";
|
|
95
|
+
|
|
96
|
+
let method = request.method;
|
|
97
|
+
let body = request.body;
|
|
98
|
+
let headers = request.headers;
|
|
99
|
+
if (
|
|
100
|
+
((status === 301 || status === 302) && method === "POST") ||
|
|
101
|
+
(status === 303 && method !== "GET" && method !== "HEAD")
|
|
102
|
+
) {
|
|
103
|
+
method = "GET";
|
|
104
|
+
body = HttpBody.empty;
|
|
105
|
+
headers = Headers.remove(headers, "content-type");
|
|
106
|
+
headers = Headers.remove(headers, "content-length");
|
|
107
|
+
headers = Headers.remove(headers, "content-encoding");
|
|
108
|
+
} else if (body._tag !== "Empty" && !replayable) {
|
|
109
|
+
// A 307 or 308 sends the body again, and the caller's stream is spent.
|
|
110
|
+
return undefined;
|
|
111
|
+
}
|
|
112
|
+
if (url.origin !== new URL(request.url).origin) {
|
|
113
|
+
headers = Headers.fromInput(
|
|
114
|
+
Object.entries(headers).filter(([name]) => CROSS_ORIGIN_HEADERS.has(name)),
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
// The `Location` as sent: a `URL` object would re-encode a signed query.
|
|
118
|
+
return HttpClientRequest.makeWith(
|
|
119
|
+
method,
|
|
120
|
+
url.href,
|
|
121
|
+
UrlParams.empty,
|
|
122
|
+
Option.none(),
|
|
123
|
+
headers,
|
|
124
|
+
body,
|
|
125
|
+
);
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
export const send = (
|
|
129
|
+
context: Context.Context<any>,
|
|
130
|
+
client: HttpClient.HttpClient,
|
|
131
|
+
request: HttpClientRequest.HttpClientRequest,
|
|
132
|
+
oneShot?: boolean,
|
|
133
|
+
): Effect.Effect<HttpClientResponse.HttpClientResponse, HttpClientError.HttpClientError> => {
|
|
134
|
+
const once = oneShot ?? request.body._tag === "Stream";
|
|
135
|
+
const hop = (
|
|
136
|
+
request: HttpClientRequest.HttpClientRequest,
|
|
137
|
+
redirects: number,
|
|
138
|
+
): Effect.Effect<HttpClientResponse.HttpClientResponse, HttpClientError.HttpClientError> =>
|
|
139
|
+
// Inside `suspend`: the retry layer runs this same effect again for each
|
|
140
|
+
// attempt, and each attempt must record its own request.
|
|
141
|
+
Effect.suspend(() => {
|
|
142
|
+
RetryState.recordRequest(request.url, once);
|
|
143
|
+
return Effect.flatMap(Telemetry.execute(context, client, request), (response) => {
|
|
144
|
+
const next = redirects < MAX_REDIRECTS ? nextHop(request, response, !once) : undefined;
|
|
145
|
+
if (next !== undefined) return hop(next, redirects + 1);
|
|
146
|
+
RetryState.recordResponse(
|
|
147
|
+
response.status,
|
|
148
|
+
response.headers as Readonly<Record<string, string | undefined>>,
|
|
149
|
+
);
|
|
150
|
+
return Effect.succeed(response);
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
const init = manualRedirects(context);
|
|
154
|
+
const sent = hop(request, 0);
|
|
155
|
+
return init === undefined ? sent : Effect.provideService(sent, FetchHttpClient.RequestInit, init);
|
|
156
|
+
};
|