viell-effect-schema-http 0.0.0-stage → 0.1.0-rc.1
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 +21 -0
- package/README.md +57 -2
- package/dist/concurrency/Interaction.d.ts +32 -0
- package/dist/concurrency/Interaction.d.ts.map +1 -0
- package/dist/concurrency/Interaction.js +78 -0
- package/dist/concurrency/Interaction.js.map +1 -0
- package/dist/http/Body.d.ts +52 -0
- package/dist/http/Body.d.ts.map +1 -0
- package/dist/http/Body.js +90 -0
- package/dist/http/Body.js.map +1 -0
- package/dist/http/Operation.d.ts +34 -0
- package/dist/http/Operation.d.ts.map +1 -0
- package/dist/http/Operation.js +99 -0
- package/dist/http/Operation.js.map +1 -0
- package/dist/http/Policy.d.ts +47 -0
- package/dist/http/Policy.d.ts.map +1 -0
- package/dist/http/Policy.js +55 -0
- package/dist/http/Policy.js.map +1 -0
- package/dist/http/Request.d.ts +134 -0
- package/dist/http/Request.d.ts.map +1 -0
- package/dist/http/Request.js +229 -0
- package/dist/http/Request.js.map +1 -0
- package/dist/http/Response.d.ts +51 -0
- package/dist/http/Response.d.ts.map +1 -0
- package/dist/http/Response.js +42 -0
- package/dist/http/Response.js.map +1 -0
- package/dist/http/Transport.d.ts +27 -0
- package/dist/http/Transport.d.ts.map +1 -0
- package/dist/http/Transport.js +54 -0
- package/dist/http/Transport.js.map +1 -0
- package/dist/http/UrlEncoding.d.ts +22 -0
- package/dist/http/UrlEncoding.d.ts.map +1 -0
- package/dist/http/UrlEncoding.js +32 -0
- package/dist/http/UrlEncoding.js.map +1 -0
- package/dist/http/internal/fields.d.ts +12 -0
- package/dist/http/internal/fields.d.ts.map +1 -0
- package/dist/http/internal/fields.js +21 -0
- package/dist/http/internal/fields.js.map +1 -0
- package/dist/main.d.ts +9 -0
- package/dist/main.d.ts.map +1 -0
- package/dist/main.js +9 -0
- package/dist/main.js.map +1 -0
- package/package.json +125 -4
- package/src/concurrency/Interaction.ts +159 -0
- package/src/http/Body.ts +208 -0
- package/src/http/Operation.ts +237 -0
- package/src/http/Policy.ts +95 -0
- package/src/http/Request.ts +510 -0
- package/src/http/Response.ts +126 -0
- package/src/http/Transport.ts +95 -0
- package/src/http/UrlEncoding.ts +63 -0
- package/src/http/internal/fields.ts +46 -0
- package/src/main.ts +8 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 viell
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,58 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Effect Schema HTTP
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Consumer-owned HTTP contracts composed with Effect. Describe what an external service accepts and
|
|
4
|
+
returns, encode application values with Schema, and execute through the `HttpClient` service of
|
|
5
|
+
`effect/http`.
|
|
6
|
+
|
|
7
|
+
Agents write and maintain this project. Its code is not human-reviewed.
|
|
8
|
+
|
|
9
|
+
## Status and scope
|
|
10
|
+
|
|
11
|
+
`0.1.0-rc.1` is the first release candidate, intended to become `0.1.0` after qualification and
|
|
12
|
+
publication prerequisites. It is distributed on [GitHub
|
|
13
|
+
Releases](https://github.com/viell-dev/slop-effect-schema-http/releases/tag/0.1.0-rc.1), with an
|
|
14
|
+
installable tarball and SHA-256 checksums. It is not published on npm. The source is
|
|
15
|
+
[MIT-licensed](./LICENSE).
|
|
16
|
+
|
|
17
|
+
Download the tarball, then install it in an ESM project:
|
|
18
|
+
|
|
19
|
+
```sh
|
|
20
|
+
npm install ./viell-effect-schema-http-0.1.0-rc.1.tgz effect@4.1.1
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
The initial environment scope is Node.js 24 on Windows/Linux and browser Fetch in Chromium, with
|
|
24
|
+
Effect `^4.0.7`. Isolated consumers check Effect 4.0.7 and 4.1.1, and TypeScript 6.0.3 and 7.0.2.
|
|
25
|
+
See [compatibility and limits](https://viell-dev.github.io/slop-effect-schema-http/limits) for the
|
|
26
|
+
qualification boundaries. Compatible fixes use `0.1.x`; breaking API changes require `0.2.0` and
|
|
27
|
+
migration guidance.
|
|
28
|
+
|
|
29
|
+
The [documentation site](https://viell-dev.github.io/slop-effect-schema-http/) provides local
|
|
30
|
+
installation, a runnable example, API links, and limits and recovery guidance. It describes the
|
|
31
|
+
latest installable release, including this candidate until a stable release exists. The [release
|
|
32
|
+
tracker](https://github.com/viell-dev/slop-effect-schema-http/issues/2) records qualification and
|
|
33
|
+
remaining publication steps.
|
|
34
|
+
|
|
35
|
+
The existing modules describe request URLs, headers, query parameters and bodies; select and decode
|
|
36
|
+
responses; compose operations with execution policies; and integrate with Effect's HTTP client. They
|
|
37
|
+
describe an external service from the consumer's perspective. This project does not generate a
|
|
38
|
+
server or replace the HTTP client's transport.
|
|
39
|
+
|
|
40
|
+
The public entry point exports `Body`, `Interaction`, `Operation`, `Policy`, `Request`, `Response`,
|
|
41
|
+
`Transport`, and `UrlEncoding`. Their TypeScript source and doc comments are the current API
|
|
42
|
+
reference. [docs/design.md](./docs/design.md) records the design decisions: what the library
|
|
43
|
+
promises, and what it leaves to the consumer, to Effect, or to the transport.
|
|
44
|
+
|
|
45
|
+
See the [verification guide](./CONTRIBUTING.md#behavior-tests) for the module tests, separate
|
|
46
|
+
hostile-server suite, and their coverage limits. Confirmed defects remain discoverable in the [open
|
|
47
|
+
bug
|
|
48
|
+
issues](https://github.com/viell-dev/slop-effect-schema-http/issues?q=is%3Aissue+is%3Aopen+label%3A%22Type%3A+Bug%22).
|
|
49
|
+
|
|
50
|
+
## Development
|
|
51
|
+
|
|
52
|
+
Follow [CONTRIBUTING.md](./CONTRIBUTING.md#development-and-verification) for setup, commands, tests,
|
|
53
|
+
and pull requests. Report defects and proposed changes in the [issue
|
|
54
|
+
tracker](https://github.com/viell-dev/slop-effect-schema-http/issues), with synthetic inputs, the
|
|
55
|
+
commit and tool versions, reproduction commands, and expected and actual results. Do not include
|
|
56
|
+
credentials or private service data. For a sensitive security report, use [GitHub private
|
|
57
|
+
vulnerability
|
|
58
|
+
reporting](https://github.com/viell-dev/slop-effect-schema-http/security/advisories/new).
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Effect, type Equivalence, Scope } from "effect";
|
|
2
|
+
declare const Closed_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
|
|
3
|
+
readonly _tag: "InteractionClosed";
|
|
4
|
+
} & Readonly<A>;
|
|
5
|
+
/** The interaction was closed; it admits no further work. */
|
|
6
|
+
export declare class Closed extends Closed_base {
|
|
7
|
+
}
|
|
8
|
+
export interface RunOptions {
|
|
9
|
+
/** Start fresh work, superseding active work and bypassing the retained result. */
|
|
10
|
+
readonly force?: boolean | undefined;
|
|
11
|
+
}
|
|
12
|
+
/** One user-facing interaction: at most one active execution and one retained success. */
|
|
13
|
+
export interface Interaction<in I, out A, out E = never> {
|
|
14
|
+
/** Equal input joins active work or reuses the retained success; different input supersedes active work. */
|
|
15
|
+
readonly run: (input: I, options?: RunOptions) => Effect.Effect<A, E | Closed>;
|
|
16
|
+
/** Permanent and idempotent. Every caller waits for all owned finalizers, including superseded work. */
|
|
17
|
+
readonly close: Effect.Effect<void>;
|
|
18
|
+
}
|
|
19
|
+
export interface Options<I, A> {
|
|
20
|
+
/** Defaults to `Equal.equals`, which compares plain objects and arrays structurally. */
|
|
21
|
+
readonly equivalence?: Equivalence.Equivalence<I> | undefined;
|
|
22
|
+
/** Whether a successful result is retained for reuse. The result is returned either way. */
|
|
23
|
+
readonly retain?: ((value: A, input: I) => boolean) | undefined;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Acquire an interaction in the current Scope. Services are captured at acquisition, like a Layer. Every
|
|
27
|
+
* execution belongs to the interaction rather than to a caller, and runs in its own child Scope, so
|
|
28
|
+
* interrupting one waiter never cancels work another waiter shares.
|
|
29
|
+
*/
|
|
30
|
+
export declare const make: <I, A, E, R>(execute: (input: I) => Effect.Effect<A, E, R>, options?: Options<I, A> | undefined) => Effect.Effect<Interaction<I, A, E>, never, R | Scope.Scope>;
|
|
31
|
+
export {};
|
|
32
|
+
//# sourceMappingURL=Interaction.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Interaction.d.ts","sourceRoot":"","sources":["../../src/concurrency/Interaction.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,MAAM,EAEN,KAAK,WAAW,EAGhB,KAAK,EAEN,MAAM,QAAQ,CAAC;;;;AAEhB,6DAA6D;AAC7D,qBAAa,MAAO,SAAQ,WAAqC;CAAG;AAEpE,MAAM,WAAW,UAAU;IACzB,mFAAmF;IACnF,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;CACtC;AAED,0FAA0F;AAC1F,MAAM,WAAW,WAAW,CAAC,EAAE,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,GAAG,KAAK;IACrD,4GAA4G;IAC5G,QAAQ,CAAC,GAAG,EAAE,CACZ,KAAK,EAAE,CAAC,EACR,OAAO,CAAC,EAAE,UAAU,KACjB,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,CAAC;IAClC,wGAAwG;IACxG,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;CACrC;AAED,MAAM,WAAW,OAAO,CAAC,CAAC,EAAE,CAAC;IAC3B,wFAAwF;IACxF,QAAQ,CAAC,WAAW,CAAC,EAAE,WAAW,CAAC,WAAW,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC;IAC9D,4FAA4F;IAC5F,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,KAAK,OAAO,CAAC,GAAG,SAAS,CAAC;CACjE;AAQD;;;;GAIG;AACH,eAAO,MAAM,IAAI,GAAgC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,mBACxC,CAAC,KAAK,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,qGA2G7C,CAAC"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { Context, Data, Deferred, Effect, Equal, Exit, Scope, Semaphore, } from "effect";
|
|
2
|
+
/** The interaction was closed; it admits no further work. */
|
|
3
|
+
export class Closed extends Data.TaggedError("InteractionClosed") {
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Acquire an interaction in the current Scope. Services are captured at acquisition, like a Layer. Every
|
|
7
|
+
* execution belongs to the interaction rather than to a caller, and runs in its own child Scope, so
|
|
8
|
+
* interrupting one waiter never cancels work another waiter shares.
|
|
9
|
+
*/
|
|
10
|
+
export const make = Effect.fnUntraced(function* (execute, options) {
|
|
11
|
+
const context = yield* Effect.context();
|
|
12
|
+
const owned = yield* Scope.make("parallel");
|
|
13
|
+
const lock = yield* Semaphore.make(1);
|
|
14
|
+
const closing = yield* Deferred.make();
|
|
15
|
+
const equivalent = options?.equivalence ?? Equal.equals;
|
|
16
|
+
let closed = false;
|
|
17
|
+
let flight;
|
|
18
|
+
let retained;
|
|
19
|
+
const close = Effect.uninterruptible(Effect.gen(function* () {
|
|
20
|
+
const first = yield* lock.withPermit(Effect.sync(() => {
|
|
21
|
+
if (closed)
|
|
22
|
+
return false;
|
|
23
|
+
closed = true;
|
|
24
|
+
flight = undefined;
|
|
25
|
+
retained = undefined;
|
|
26
|
+
return true;
|
|
27
|
+
}));
|
|
28
|
+
if (first)
|
|
29
|
+
yield* Deferred.done(closing, yield* Effect.exit(Scope.close(owned, Exit.void)));
|
|
30
|
+
yield* Deferred.await(closing);
|
|
31
|
+
}));
|
|
32
|
+
yield* Effect.addFinalizer(() => close);
|
|
33
|
+
// State transitions hold the lock briefly; it is never held while waiting for work or finalizers.
|
|
34
|
+
const publish = (input, shared, exit) => lock.withPermit(Effect.sync(() => {
|
|
35
|
+
if (flight?.result !== shared)
|
|
36
|
+
return;
|
|
37
|
+
try {
|
|
38
|
+
if (Exit.isSuccess(exit)) {
|
|
39
|
+
if (options?.retain?.(exit.value, input) ?? true)
|
|
40
|
+
retained = { input, value: exit.value };
|
|
41
|
+
else if (retained !== undefined &&
|
|
42
|
+
equivalent(retained.input, input))
|
|
43
|
+
retained = undefined;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
finally {
|
|
47
|
+
flight = undefined;
|
|
48
|
+
}
|
|
49
|
+
}));
|
|
50
|
+
// Forked uninterruptibly so that publication always happens, even when superseded before starting.
|
|
51
|
+
const worker = Effect.fnUntraced(function* (input, shared) {
|
|
52
|
+
const exit = yield* Effect.exit(Effect.interruptible(Effect.scopedWith((scope) => Effect.suspend(() => execute(input)).pipe(Effect.provideContext(Context.add(context, Scope.Scope, scope))))));
|
|
53
|
+
// A retention predicate defect still releases every waiter and clears the active flight.
|
|
54
|
+
const publication = yield* Effect.exit(publish(input, shared, exit));
|
|
55
|
+
yield* Deferred.done(shared, Exit.isFailure(publication) ? Exit.failCause(publication.cause) : exit);
|
|
56
|
+
});
|
|
57
|
+
const admit = Effect.fnUntraced(function* (input, force) {
|
|
58
|
+
if (closed)
|
|
59
|
+
return yield* new Closed();
|
|
60
|
+
if (!force && flight !== undefined && equivalent(flight.input, input))
|
|
61
|
+
return Deferred.await(flight.result);
|
|
62
|
+
if (flight !== undefined) {
|
|
63
|
+
flight.fiber.interruptUnsafe();
|
|
64
|
+
flight = undefined;
|
|
65
|
+
}
|
|
66
|
+
if (!force && retained !== undefined && equivalent(retained.input, input))
|
|
67
|
+
return Effect.succeed(retained.value);
|
|
68
|
+
const shared = yield* Deferred.make();
|
|
69
|
+
const fiber = yield* Effect.forkIn(worker(input, shared), owned, {
|
|
70
|
+
uninterruptible: true,
|
|
71
|
+
});
|
|
72
|
+
flight = { input, result: shared, fiber };
|
|
73
|
+
return Deferred.await(shared);
|
|
74
|
+
});
|
|
75
|
+
const run = (input, settings) => Effect.uninterruptibleMask((restore) => Effect.flatMap(lock.withPermit(admit(input, settings?.force === true)), (result) => restore(result)));
|
|
76
|
+
return { run, close };
|
|
77
|
+
});
|
|
78
|
+
//# sourceMappingURL=Interaction.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Interaction.js","sourceRoot":"","sources":["../../src/concurrency/Interaction.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EACP,IAAI,EACJ,QAAQ,EACR,MAAM,EACN,KAAK,EAEL,IAAI,EAEJ,KAAK,EACL,SAAS,GACV,MAAM,QAAQ,CAAC;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,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,EAAE,KAAK,EAAE;YAC/D,eAAe,EAAE,IAAI;SACtB,CAAC,CAAC;QACH,MAAM,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC;QAC1C,OAAO,QAAQ,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IAChC,CAAC,CAAC,CAAC;IAEH,MAAM,GAAG,GAAG,CAAC,KAAQ,EAAE,QAAqB,EAAgC,EAAE,CAC5E,MAAM,CAAC,mBAAmB,CAAC,CAAC,OAAO,EAAE,EAAE,CACrC,MAAM,CAAC,OAAO,CACZ,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,KAAK,EAAE,QAAQ,EAAE,KAAK,KAAK,IAAI,CAAC,CAAC,EACvD,CAAC,MAAM,EAAE,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,CAC5B,CACF,CAAC;IAEJ,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC;AACxB,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { Effect, Pipeable, Schema } from "effect";
|
|
2
|
+
import { HttpBody, HttpClientError, type HttpClientResponse, type UrlParams } from "effect/http";
|
|
3
|
+
/** A finite outgoing representation, encoded once per operation evaluation. */
|
|
4
|
+
export interface Encoder<in A, out E = never, out R = never> extends Pipeable.Pipeable {
|
|
5
|
+
readonly encode: (value: A) => Effect.Effect<HttpBody.HttpBody, E, R>;
|
|
6
|
+
}
|
|
7
|
+
/** A finite incoming representation. The decoder owns the selected response body. */
|
|
8
|
+
export interface Decoder<out A, out E = never, out R = never> extends Pipeable.Pipeable {
|
|
9
|
+
readonly decode: (response: HttpClientResponse.HttpClientResponse) => Effect.Effect<A, E, R>;
|
|
10
|
+
/** Contributes to the automatic `Accept` header of an operation. */
|
|
11
|
+
readonly mediaType: string | undefined;
|
|
12
|
+
}
|
|
13
|
+
/** Both directions of one representation. Errors and services stay separate per direction. */
|
|
14
|
+
export interface Codec<A, EncodeError = never, DecodeError = never, EncodeServices = never, DecodeServices = never> extends Encoder<A, EncodeError, EncodeServices>, Decoder<A, DecodeError, DecodeServices> {
|
|
15
|
+
}
|
|
16
|
+
export declare const encoder: <A, E = never, R = never>(encode: (value: A) => Effect.Effect<HttpBody.HttpBody, E, R>) => Encoder<A, E, R>;
|
|
17
|
+
export declare const decoder: <A, E = never, R = never>(decode: (response: HttpClientResponse.HttpClientResponse) => Effect.Effect<A, E, R>, mediaType?: string) => Decoder<A, E, R>;
|
|
18
|
+
export declare const make: <A, EncodeError = never, DecodeError = never, EncodeServices = never, DecodeServices = never>(options: {
|
|
19
|
+
readonly encode: (value: A) => Effect.Effect<HttpBody.HttpBody, EncodeError, EncodeServices>;
|
|
20
|
+
readonly decode: (response: HttpClientResponse.HttpClientResponse) => Effect.Effect<A, DecodeError, DecodeServices>;
|
|
21
|
+
readonly mediaType?: string | undefined;
|
|
22
|
+
}) => Codec<A, EncodeError, DecodeError, EncodeServices, DecodeServices>;
|
|
23
|
+
/**
|
|
24
|
+
* Any JSON value, encoded with `HttpBody.json`. Like it, a value `JSON.stringify` omits, such as `undefined`,
|
|
25
|
+
* encodes as an empty body; use {@link jsonSchema} to validate first. Unlike `response.json`, an empty
|
|
26
|
+
* response body is a decoding failure rather than `null`.
|
|
27
|
+
*/
|
|
28
|
+
export declare const json: Codec<unknown, HttpBody.HttpBodyError, HttpClientError.HttpClientError>;
|
|
29
|
+
/**
|
|
30
|
+
* UTF-8 text. Incoming decoding delegates to `response.text`. Fetch-backed providers ignore charset
|
|
31
|
+
* parameters, strip a leading UTF-8 BOM, and replace malformed bytes with U+FFFD without failing.
|
|
32
|
+
* Use {@link bytes} with a schema or custom decoder for strict or non-UTF-8 decoding.
|
|
33
|
+
*/
|
|
34
|
+
export declare const text: Codec<string, never, HttpClientError.HttpClientError>;
|
|
35
|
+
export declare const bytes: Codec<Uint8Array, never, HttpClientError.HttpClientError>;
|
|
36
|
+
/** Multipart form data. The transport owns the boundary and its Content-Type. */
|
|
37
|
+
export declare const formData: Codec<FormData, never, HttpClientError.HttpClientError>;
|
|
38
|
+
export declare const urlEncoded: Codec<UrlParams.UrlParams, never, HttpClientError.HttpClientError>;
|
|
39
|
+
/** No outgoing body. Incoming bytes, including unexpected ones, are drained without buffering. */
|
|
40
|
+
export declare const empty: Codec<void, never, HttpClientError.HttpClientError>;
|
|
41
|
+
export declare const map: <A, B>(f: (value: A) => B) => <E, R>(self: Decoder<A, E, R>) => Decoder<B, E, R>;
|
|
42
|
+
export declare const mapEffect: <A, B, E2, R2>(f: (value: A) => Effect.Effect<B, E2, R2>) => <E, R>(self: Decoder<A, E, R>) => Decoder<B, E | E2, R | R2>;
|
|
43
|
+
/** Validate a decoded value with a schema. A failure is final: it never falls through to another response case. */
|
|
44
|
+
export declare const schema: <S extends Schema.Constraint>(contract: S) => <A, E, R>(self: Decoder<A, E, R>) => Decoder<S["Type"], E | Schema.SchemaError, R | S["DecodingServices"]>;
|
|
45
|
+
/** Validate application input with a schema and encode it with the selected wire encoder. */
|
|
46
|
+
export declare const encodeSchema: <S extends Schema.Constraint>(contract: S) => <E, R>(self: Encoder<S["Encoded"], E, R>) => Encoder<S["Type"], E | Schema.SchemaError, R | S["EncodingServices"]>;
|
|
47
|
+
/**
|
|
48
|
+
* Bidirectional JSON through the schema's canonical JSON codec (`Schema.toCodecJson`), as in Effect's own
|
|
49
|
+
* JSON body helpers.
|
|
50
|
+
*/
|
|
51
|
+
export declare const jsonSchema: <S extends Schema.Constraint>(contract: S) => Codec<S["Type"], Schema.SchemaError | HttpBody.HttpBodyError, Schema.SchemaError | HttpClientError.HttpClientError, S["EncodingServices"], S["DecodingServices"]>;
|
|
52
|
+
//# sourceMappingURL=Body.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Body.d.ts","sourceRoot":"","sources":["../../src/http/Body.ts"],"names":[],"m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EAAE,CAAC,EAAE,CAAC,CAAC,KACrB,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,WAAW,EAAE,CAAC,GAAG,CAAC,CAAC,kBAAkB,CAAC,CAExE,CAAC;AAEF,6FAA6F;AAC7F,eAAO,MAAM,YAAY,GAAI,CAAC,SAAS,MAAM,CAAC,UAAU,EAAE,UAAU,CAAC,MAE3D,CAAC,EAAE,CAAC,EACV,MAAM,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,KAChC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,WAAW,EAAE,CAAC,GAAG,CAAC,CAAC,kBAAkB,CAAC,CAExE,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,UAAU,GAAI,CAAC,SAAS,MAAM,CAAC,UAAU,EACpD,UAAU,CAAC,KACV,KAAK,CACN,CAAC,CAAC,MAAM,CAAC,EACT,MAAM,CAAC,WAAW,GAAG,QAAQ,CAAC,aAAa,EAC3C,MAAM,CAAC,WAAW,GAAG,eAAe,CAAC,eAAe,EACpD,CAAC,CAAC,kBAAkB,CAAC,EACrB,CAAC,CAAC,kBAAkB,CAAC,CAQtB,CAAC"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { Effect, Pipeable, Schema, Stream } from "effect";
|
|
2
|
+
import { HttpBody, HttpClientError, } from "effect/http";
|
|
3
|
+
export const encoder = (encode) => ({
|
|
4
|
+
...Pipeable.Prototype,
|
|
5
|
+
encode,
|
|
6
|
+
});
|
|
7
|
+
export const decoder = (decode, mediaType) => ({ ...Pipeable.Prototype, decode, mediaType });
|
|
8
|
+
export const make = (options) => ({
|
|
9
|
+
...Pipeable.Prototype,
|
|
10
|
+
encode: options.encode,
|
|
11
|
+
decode: options.decode,
|
|
12
|
+
mediaType: options.mediaType,
|
|
13
|
+
});
|
|
14
|
+
const decodeFailure = (response, cause) => new HttpClientError.HttpClientError({
|
|
15
|
+
reason: new HttpClientError.DecodeError({
|
|
16
|
+
request: response.request,
|
|
17
|
+
response,
|
|
18
|
+
cause,
|
|
19
|
+
}),
|
|
20
|
+
});
|
|
21
|
+
/**
|
|
22
|
+
* Any JSON value, encoded with `HttpBody.json`. Like it, a value `JSON.stringify` omits, such as `undefined`,
|
|
23
|
+
* encodes as an empty body; use {@link jsonSchema} to validate first. Unlike `response.json`, an empty
|
|
24
|
+
* response body is a decoding failure rather than `null`.
|
|
25
|
+
*/
|
|
26
|
+
export const json = make({
|
|
27
|
+
encode: (value) => HttpBody.json(value),
|
|
28
|
+
decode: (response) => Effect.flatMap(response.text, (text) => Effect.try({
|
|
29
|
+
try: () => JSON.parse(text),
|
|
30
|
+
catch: (cause) => decodeFailure(response, cause),
|
|
31
|
+
})),
|
|
32
|
+
mediaType: "application/json",
|
|
33
|
+
});
|
|
34
|
+
/**
|
|
35
|
+
* UTF-8 text. Incoming decoding delegates to `response.text`. Fetch-backed providers ignore charset
|
|
36
|
+
* parameters, strip a leading UTF-8 BOM, and replace malformed bytes with U+FFFD without failing.
|
|
37
|
+
* Use {@link bytes} with a schema or custom decoder for strict or non-UTF-8 decoding.
|
|
38
|
+
*/
|
|
39
|
+
export const text = make({
|
|
40
|
+
encode: (value) => Effect.sync(() => HttpBody.text(value)),
|
|
41
|
+
decode: (response) => response.text,
|
|
42
|
+
mediaType: "text/plain",
|
|
43
|
+
});
|
|
44
|
+
export const bytes = make({
|
|
45
|
+
encode: (value) => Effect.sync(() => HttpBody.uint8Array(value)),
|
|
46
|
+
decode: (response) => Effect.map(response.arrayBuffer, (buffer) => new Uint8Array(buffer)),
|
|
47
|
+
mediaType: "application/octet-stream",
|
|
48
|
+
});
|
|
49
|
+
/** Multipart form data. The transport owns the boundary and its Content-Type. */
|
|
50
|
+
export const formData = make({
|
|
51
|
+
encode: (value) => Effect.sync(() => HttpBody.formData(value)),
|
|
52
|
+
decode: (response) => response.formData,
|
|
53
|
+
mediaType: "multipart/form-data",
|
|
54
|
+
});
|
|
55
|
+
export const urlEncoded = make({
|
|
56
|
+
encode: (value) => Effect.sync(() => HttpBody.urlParams(value)),
|
|
57
|
+
decode: (response) => response.urlParamsBody,
|
|
58
|
+
mediaType: "application/x-www-form-urlencoded",
|
|
59
|
+
});
|
|
60
|
+
const isEmptyBody = (error) => error.reason._tag === "EmptyBodyError";
|
|
61
|
+
/** No outgoing body. Incoming bytes, including unexpected ones, are drained without buffering. */
|
|
62
|
+
export const empty = make({
|
|
63
|
+
encode: () => Effect.succeed(HttpBody.empty),
|
|
64
|
+
decode: (response) => Stream.runDrain(response.stream).pipe(Effect.catchIf(isEmptyBody, () => Effect.void)),
|
|
65
|
+
});
|
|
66
|
+
export const map = (f) => (self) => decoder((response) => Effect.map(self.decode(response), f), self.mediaType);
|
|
67
|
+
export const mapEffect = (f) => (self) => decoder((response) => Effect.flatMap(self.decode(response), f), self.mediaType);
|
|
68
|
+
/** Validate a decoded value with a schema. A failure is final: it never falls through to another response case. */
|
|
69
|
+
export const schema = (contract) => {
|
|
70
|
+
const decode = Schema.decodeUnknownEffect(contract);
|
|
71
|
+
return (self) => self.pipe(mapEffect((value) => decode(value)));
|
|
72
|
+
};
|
|
73
|
+
/** Validate application input with a schema and encode it with the selected wire encoder. */
|
|
74
|
+
export const encodeSchema = (contract) => {
|
|
75
|
+
const encode = Schema.encodeEffect(contract);
|
|
76
|
+
return (self) => encoder((value) => Effect.flatMap(encode(value), self.encode));
|
|
77
|
+
};
|
|
78
|
+
/**
|
|
79
|
+
* Bidirectional JSON through the schema's canonical JSON codec (`Schema.toCodecJson`), as in Effect's own
|
|
80
|
+
* JSON body helpers.
|
|
81
|
+
*/
|
|
82
|
+
export const jsonSchema = (contract) => {
|
|
83
|
+
const codec = Schema.toCodecJson(contract);
|
|
84
|
+
return make({
|
|
85
|
+
encode: encodeSchema(codec)(json).encode,
|
|
86
|
+
decode: json.pipe(schema(codec)).decode,
|
|
87
|
+
mediaType: json.mediaType,
|
|
88
|
+
});
|
|
89
|
+
};
|
|
90
|
+
//# sourceMappingURL=Body.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Body.js","sourceRoot":"","sources":["../../src/http/Body.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC1D,OAAO,EACL,QAAQ,EACR,eAAe,GAGhB,MAAM,aAAa,CAAC;AA8BrB,MAAM,CAAC,MAAM,OAAO,GAAG,CACrB,MAA4D,EAC1C,EAAE,CAAC,CAAC;IACtB,GAAG,QAAQ,CAAC,SAAS;IACrB,MAAM;CACP,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,OAAO,GAAG,CACrB,MAE2B,EAC3B,SAAkB,EACA,EAAE,CAAC,CAAC,EAAE,GAAG,QAAQ,CAAC,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC,CAAC;AAEtE,MAAM,CAAC,MAAM,IAAI,GAAG,CAMlB,OAQD,EAAsE,EAAE,CAAC,CAAC;IACzE,GAAG,QAAQ,CAAC,SAAS;IACrB,MAAM,EAAE,OAAO,CAAC,MAAM;IACtB,MAAM,EAAE,OAAO,CAAC,MAAM;IACtB,SAAS,EAAE,OAAO,CAAC,SAAS;CAC7B,CAAC,CAAC;AAEH,MAAM,aAAa,GAAG,CACpB,QAA+C,EAC/C,KAAc,EACd,EAAE,CACF,IAAI,eAAe,CAAC,eAAe,CAAC;IAClC,MAAM,EAAE,IAAI,eAAe,CAAC,WAAW,CAAC;QACtC,OAAO,EAAE,QAAQ,CAAC,OAAO;QACzB,QAAQ;QACR,KAAK;KACN,CAAC;CACH,CAAC,CAAC;AAEL;;;;GAIG;AACH,MAAM,CAAC,MAAM,IAAI,GAIb,IAAI,CAAC;IACP,MAAM,EAAE,CAAC,KAAc,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,C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S;KAC1B,CAAC,CAAC;AACL,CAAC,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Cause, Effect, Pipeable, type Scope } from "effect";
|
|
2
|
+
import { HttpClient, HttpClientError } from "effect/http";
|
|
3
|
+
import * as Policy from "./Policy.js";
|
|
4
|
+
import * as Request from "./Request.js";
|
|
5
|
+
import * as Response from "./Response.js";
|
|
6
|
+
/** A request paired with its response contract. Execution returns an ordinary cold Effect. */
|
|
7
|
+
export interface Operation<in I, out A, out E = never, out R = never> extends Pipeable.Pipeable {
|
|
8
|
+
readonly execute: (input: I) => Effect.Effect<A, E, R>;
|
|
9
|
+
}
|
|
10
|
+
/** Adapt an Effect-returning function. Each execution is suspended, so construction stays pure. */
|
|
11
|
+
export declare const fromEffect: <I, A, E, R>(execute: (input: I) => Effect.Effect<A, E, R>) => Operation<I, A, E, R>;
|
|
12
|
+
export interface Options<E = HttpClientError.HttpClientError, R = never, EP = never, RP = never> {
|
|
13
|
+
readonly policy?: Policy.Policy<EP, RP> | undefined;
|
|
14
|
+
/**
|
|
15
|
+
* A native client transformation applied inside each attempt, after request materialization, suitable
|
|
16
|
+
* for nonces and URL-dependent signatures. Run a signer after other request edits it must cover.
|
|
17
|
+
* Appending native URL parameters can reserialize the entire query as form data, changing bare keys and
|
|
18
|
+
* escapes. Prefer Request query combinators, or preserve the query text when editing the URL directly.
|
|
19
|
+
*/
|
|
20
|
+
readonly transformClient?: ((client: HttpClient.HttpClient) => HttpClient.HttpClient.With<E, R>) | undefined;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Materialize the request once, then run attempts under the policy. Each attempt owns a Scope that covers
|
|
24
|
+
* dispatch and decoding; it closes before the outcome is classified or a retry delay begins.
|
|
25
|
+
*/
|
|
26
|
+
export declare const make: <I, E, R, H extends boolean, Q extends boolean, A, E2, R2, E3 = HttpClientError.HttpClientError, R3 = never, EP = never, RP = never>(request: Request.Request<I, E, R, H, Q>, response: Response.Response<A, E2, R2>, options?: Options<E3, R3, EP, RP>) => Operation<I, A, E | E3 | EP | Request.InvalidRequest | HttpClientError.HttpClientError | Response.UnexpectedResponse | Response.DecodeError<E2 | HttpClientError.HttpClientError> | Cause.TimeoutError, R | RP | Exclude<R2 | R3, Scope.Scope> | HttpClient.HttpClient>;
|
|
27
|
+
export declare const execute: {
|
|
28
|
+
<I>(input: I): <A, E, R>(self: Operation<I, A, E, R>) => Effect.Effect<A, E, R>;
|
|
29
|
+
<I, A, E, R>(self: Operation<I, A, E, R>, input: I): Effect.Effect<A, E, R>;
|
|
30
|
+
};
|
|
31
|
+
/** Interpret a successful result, for example to move a recognized outcome into the failure channel. */
|
|
32
|
+
export declare const map: <A, B>(f: (value: A) => B) => <I, E, R>(self: Operation<I, A, E, R>) => Operation<I, B, E, R>;
|
|
33
|
+
export declare const mapEffect: <A, B, E2, R2>(f: (value: A) => Effect.Effect<B, E2, R2>) => <I, E, R>(self: Operation<I, A, E, R>) => Operation<I, B, E | E2, R | R2>;
|
|
34
|
+
//# sourceMappingURL=Operation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Operation.d.ts","sourceRoot":"","sources":["../../src/http/Operation.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,EAGL,MAAM,EAIN,QAAQ,EAGR,KAAK,KAAK,EACX,MAAM,QAAQ,CAAC;AAChB,OAAO,EACL,UAAU,EACV,eAAe,EAGhB,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AACtC,OAAO,KAAK,OAAO,MAAM,cAAc,CAAC;AACxC,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAC;AAG1C,8FAA8F;AAC9F,MAAM,WAAW,SAAS,CAAC,EAAE,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,GAAG,KAAK,EAAE,GAAG,CAAC,CAAC,GAAG,KAAK,CAClE,SAAQ,QAAQ,CAAC,QAAQ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,CACD,CAAC;AAE9D,eAAO,MAAM,SAAS,GACnB,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,GAAG,CAAC,KAAK,EAAE,CAAC,KAAK,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,EAAE,EAAE,EAAE,CAAC,MACvD,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,MAAM,SAAS,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,KAAG,SAAS,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,EAAE,CACP,CAAC"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { Cause, Clock, Duration, Effect, Exit, Function, Option, Pipeable, Pull, Schedule, } from "effect";
|
|
2
|
+
import { HttpClient, HttpClientError, HttpClientRequest, } from "effect/http";
|
|
3
|
+
import * as Policy from "./Policy.js";
|
|
4
|
+
import * as Request from "./Request.js";
|
|
5
|
+
import * as Response from "./Response.js";
|
|
6
|
+
import * as Transport from "./Transport.js";
|
|
7
|
+
/** Adapt an Effect-returning function. Each execution is suspended, so construction stays pure. */
|
|
8
|
+
export const fromEffect = (execute) => ({
|
|
9
|
+
...Pipeable.Prototype,
|
|
10
|
+
execute: (input) => Effect.suspend(() => execute(input)),
|
|
11
|
+
});
|
|
12
|
+
/** Outcome categories only: errors can contain credentials, response text or schema input. */
|
|
13
|
+
const outcome = (exit) => Exit.isSuccess(exit)
|
|
14
|
+
? "success"
|
|
15
|
+
: Cause.hasInterrupts(exit.cause)
|
|
16
|
+
? "interrupted"
|
|
17
|
+
: Cause.hasDies(exit.cause)
|
|
18
|
+
? "defect"
|
|
19
|
+
: "failure";
|
|
20
|
+
/**
|
|
21
|
+
* Materialize the request once, then run attempts under the policy. Each attempt owns a Scope that covers
|
|
22
|
+
* dispatch and decoding; it closes before the outcome is classified or a retry delay begins.
|
|
23
|
+
*/
|
|
24
|
+
export const make = (request, response, options) => {
|
|
25
|
+
const policy = options?.policy ?? Policy.none;
|
|
26
|
+
const accept = response.accepts.join(", ");
|
|
27
|
+
const execute = Effect.fnUntraced(function* (input) {
|
|
28
|
+
const compiled = yield* Request.compile(request, input);
|
|
29
|
+
const prepared = accept !== "" && compiled.request.headers.accept === undefined
|
|
30
|
+
? HttpClientRequest.setHeader(compiled.request, "accept", accept)
|
|
31
|
+
: compiled.request;
|
|
32
|
+
const client = yield* HttpClient.HttpClient;
|
|
33
|
+
const step = yield* Schedule.toStep(policy.schedule);
|
|
34
|
+
const method = prepared.method;
|
|
35
|
+
let attempt = 0;
|
|
36
|
+
while (true) {
|
|
37
|
+
attempt++;
|
|
38
|
+
yield* Effect.logDebug("HTTP attempt started").pipe(Effect.annotateLogs({
|
|
39
|
+
"http.method": method,
|
|
40
|
+
"http.attempt": attempt,
|
|
41
|
+
}));
|
|
42
|
+
let metadata;
|
|
43
|
+
const execution = Effect.scoped(Effect.gen(function* () {
|
|
44
|
+
const send = options?.transformClient === undefined
|
|
45
|
+
? HttpClient.withScope(client).execute
|
|
46
|
+
: HttpClient.withScope(options.transformClient(client)).execute;
|
|
47
|
+
// A fresh request identity keeps the scoped abort controller of this attempt separate.
|
|
48
|
+
const received = yield* send(HttpClientRequest.setHeaders(prepared, {})).pipe(Effect.provideService(Transport.HeaderLines, compiled.headerLines),
|
|
49
|
+
// Client middleware can reject a response, such as filterStatusOk; its metadata still classifies the attempt.
|
|
50
|
+
Effect.tapError((error) => Effect.sync(() => {
|
|
51
|
+
if (HttpClientError.isHttpClientError(error) &&
|
|
52
|
+
error.response !== undefined)
|
|
53
|
+
metadata = Response.metadata(error.response);
|
|
54
|
+
})));
|
|
55
|
+
metadata = Response.metadata(received);
|
|
56
|
+
return yield* Response.decode(response, received);
|
|
57
|
+
}));
|
|
58
|
+
const exit = yield* Effect.exit(policy.attemptTimeout === undefined
|
|
59
|
+
? execution
|
|
60
|
+
: Effect.timeout(execution, policy.attemptTimeout));
|
|
61
|
+
yield* Effect.logDebug("HTTP attempt completed").pipe(Effect.annotateLogs({
|
|
62
|
+
"http.method": method,
|
|
63
|
+
"http.attempt": attempt,
|
|
64
|
+
"http.outcome": outcome(exit),
|
|
65
|
+
...(metadata === undefined
|
|
66
|
+
? {}
|
|
67
|
+
: { "http.status": metadata.status }),
|
|
68
|
+
}));
|
|
69
|
+
if (Exit.isFailure(exit) &&
|
|
70
|
+
(Cause.hasInterrupts(exit.cause) || Cause.hasDies(exit.cause)))
|
|
71
|
+
return yield* exit;
|
|
72
|
+
const reason = Exit.isFailure(exit)
|
|
73
|
+
? { _tag: "Failure", cause: exit.cause, metadata }
|
|
74
|
+
: { _tag: "Response", metadata: metadata };
|
|
75
|
+
if (!policy.while(reason))
|
|
76
|
+
return yield* exit;
|
|
77
|
+
const now = yield* Clock.currentTimeMillis;
|
|
78
|
+
const delay = yield* Pull.matchEffect(step(now, reason), {
|
|
79
|
+
onSuccess: ([, scheduled]) => Effect.succeed(Option.some(scheduled)),
|
|
80
|
+
onFailure: Effect.failCause,
|
|
81
|
+
onDone: () => Effect.succeed(Option.none()),
|
|
82
|
+
});
|
|
83
|
+
if (Option.isNone(delay)) {
|
|
84
|
+
yield* Effect.logDebug("HTTP retry budget exhausted").pipe(Effect.annotateLogs({ "http.attempt": attempt }));
|
|
85
|
+
return yield* exit;
|
|
86
|
+
}
|
|
87
|
+
yield* Effect.sleep(policy.retryAfter && reason.metadata !== undefined
|
|
88
|
+
? Duration.max(delay.value, Policy.retryAfterDelay(reason.metadata, now))
|
|
89
|
+
: delay.value);
|
|
90
|
+
yield* Effect.logDebug("HTTP retrying").pipe(Effect.annotateLogs({ "http.attempt": attempt + 1 }));
|
|
91
|
+
}
|
|
92
|
+
}, Effect.onExit((exit) => Effect.logDebug("HTTP operation completed").pipe(Effect.annotateLogs({ "http.outcome": outcome(exit) }))), Effect.withLogSpan("schema-http.operation"));
|
|
93
|
+
return { ...Pipeable.Prototype, execute };
|
|
94
|
+
};
|
|
95
|
+
export const execute = Function.dual(2, (self, input) => self.execute(input));
|
|
96
|
+
/** Interpret a successful result, for example to move a recognized outcome into the failure channel. */
|
|
97
|
+
export const map = (f) => (self) => fromEffect((input) => Effect.map(self.execute(input), f));
|
|
98
|
+
export const mapEffect = (f) => (self) => fromEffect((input) => Effect.flatMap(self.execute(input), f));
|
|
99
|
+
//# sourceMappingURL=Operation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Operation.js","sourceRoot":"","sources":["../../src/http/Operation.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,EACL,KAAK,EACL,QAAQ,EACR,MAAM,EACN,IAAI,EACJ,QAAQ,EACR,MAAM,EACN,QAAQ,EACR,IAAI,EACJ,QAAQ,GAET,MAAM,QAAQ,CAAC;AAChB,OAAO,EACL,UAAU,EACV,eAAe,EACf,iBAAiB,GAElB,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AACtC,OAAO,KAAK,OAAO,MAAM,cAAc,CAAC;AACxC,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAC;AAC1C,OAAO,KAAK,SAAS,MAAM,gBAAgB,CAAC;AAQ5C,mGAAmG;AACnG,MAAM,CAAC,MAAM,UAAU,GAAG,CACxB,OAA6C,EACtB,EAAE,CAAC,CAAC;IAC3B,GAAG,QAAQ,CAAC,SAAS;IACrB,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;CACzD,CAAC,CAAC;AAoBH,8FAA8F;AAC9F,MAAM,OAAO,GAAG,CAAC,IAAiC,EAAU,EAAE,CAC5D,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC;IAClB,CAAC,CAAC,SAAS;IACX,CAAC,CAAC,KAAK,CAAC,aAAa,CAAC,IAAI,CAAC,KAAK,CAAC;QAC/B,CAAC,CAAC,aAAa;QACf,CAAC,CAAC,KAAK,CA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AAC,SAAS,EAAE,OAAO,EAAE,CAAC;AAC5C,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,OAAO,GAKhB,QAAQ,CAAC,IAAI,CACf,CAAC,EACD,CAAa,IAA2B,EAAE,KAAQ,EAA0B,EAAE,CAC5E,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CACtB,CAAC;AAEF,wGAAwG;AACxG,MAAM,CAAC,MAAM,GAAG,GACd,CAAO,CAAkB,EAAE,EAAE,CAC7B,CAAU,IAA2B,EAAyB,EAAE,CAC9D,UAAU,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;AAE9D,MAAM,CAAC,MAAM,SAAS,GACpB,CAAe,CAAyC,EAAE,EAAE,CAC5D,CAAU,IAA2B,EAAmC,EAAE,CACxE,UAAU,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Cause, Duration, Schedule } from "effect";
|
|
2
|
+
import type * as Response from "./Response.js";
|
|
3
|
+
/**
|
|
4
|
+
* What a completed attempt produced. Reasons hold no live body or transport resource and expose no
|
|
5
|
+
* request-method or decoded-result field. A classifier can close over the operation's known method.
|
|
6
|
+
*/
|
|
7
|
+
export type Reason = {
|
|
8
|
+
readonly _tag: "Response";
|
|
9
|
+
readonly metadata: Response.Metadata;
|
|
10
|
+
} | {
|
|
11
|
+
readonly _tag: "Failure";
|
|
12
|
+
readonly cause: Cause.Cause<unknown>;
|
|
13
|
+
/** Present when a response arrived before the failure: a decoding failure, or middleware rejecting it. */
|
|
14
|
+
readonly metadata?: Response.Metadata | undefined;
|
|
15
|
+
};
|
|
16
|
+
/** Attempt retries for one operation evaluation. One schedule owns the budget across every retry reason. */
|
|
17
|
+
export interface Policy<out E = never, out R = never> {
|
|
18
|
+
readonly schedule: Schedule.Schedule<unknown, Reason, E, R>;
|
|
19
|
+
readonly while: (reason: Reason) => boolean;
|
|
20
|
+
readonly attemptTimeout: Duration.Input | undefined;
|
|
21
|
+
readonly retryAfter: boolean;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* The classification of `HttpClient.retryTransient`: timeouts, transport failures and transient statuses.
|
|
25
|
+
* It does not check the request method or idempotency. A declared, successfully decoded response with a
|
|
26
|
+
* transient status is still retryable. A transport failure does not prove the server took no action.
|
|
27
|
+
*/
|
|
28
|
+
export declare const transient: (reason: Reason) => boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Opt into retries. The default {@link transient} classifier can repeat non-idempotent requests and
|
|
31
|
+
* declared transient responses; supply `while` for the operation's repeat semantics, or use {@link none}
|
|
32
|
+
* for one attempt. `while` receives metadata and failures, not the request method or decoded result.
|
|
33
|
+
* `Retry-After` is honoured by default.
|
|
34
|
+
*/
|
|
35
|
+
export declare const make: <Out, E = never, R = never>(schedule: Schedule.Schedule<Out, Reason, E, R>, options?: {
|
|
36
|
+
readonly while?: ((reason: Reason) => boolean) | undefined;
|
|
37
|
+
readonly attemptTimeout?: Duration.Input | undefined;
|
|
38
|
+
readonly retryAfter?: boolean | undefined;
|
|
39
|
+
}) => Policy<E, R>;
|
|
40
|
+
/** A single attempt. */
|
|
41
|
+
export declare const none: Policy;
|
|
42
|
+
/**
|
|
43
|
+
* The minimum delay a response requests through `Retry-After` (delay seconds or an HTTP date). Absent,
|
|
44
|
+
* malformed, or unrepresentable values request no delay.
|
|
45
|
+
*/
|
|
46
|
+
export declare const retryAfterDelay: (metadata: Response.Metadata, now: number) => Duration.Duration;
|
|
47
|
+
//# sourceMappingURL=Policy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Policy.d.ts","sourceRoot":"","sources":["../../src/http/Policy.ts"],"names":[],"mapp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