viell-effect-schema-http 0.1.0-rc.1 → 0.2.0

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.
Files changed (62) hide show
  1. package/README.md +93 -48
  2. package/dist/concurrency/Interaction.d.ts +39 -6
  3. package/dist/concurrency/Interaction.d.ts.map +1 -1
  4. package/dist/concurrency/Interaction.js +25 -4
  5. package/dist/concurrency/Interaction.js.map +1 -1
  6. package/dist/http/Body.d.ts +142 -22
  7. package/dist/http/Body.d.ts.map +1 -1
  8. package/dist/http/Body.js +118 -14
  9. package/dist/http/Body.js.map +1 -1
  10. package/dist/http/Operation.d.ts +332 -12
  11. package/dist/http/Operation.d.ts.map +1 -1
  12. package/dist/http/Operation.js +255 -9
  13. package/dist/http/Operation.js.map +1 -1
  14. package/dist/http/Policy.d.ts +49 -13
  15. package/dist/http/Policy.d.ts.map +1 -1
  16. package/dist/http/Policy.js +32 -10
  17. package/dist/http/Policy.js.map +1 -1
  18. package/dist/http/Request.d.ts +661 -79
  19. package/dist/http/Request.d.ts.map +1 -1
  20. package/dist/http/Request.js +762 -120
  21. package/dist/http/Request.js.map +1 -1
  22. package/dist/http/Response.d.ts +200 -11
  23. package/dist/http/Response.d.ts.map +1 -1
  24. package/dist/http/Response.js +149 -10
  25. package/dist/http/Response.js.map +1 -1
  26. package/dist/http/Transport.d.ts +59 -11
  27. package/dist/http/Transport.d.ts.map +1 -1
  28. package/dist/http/Transport.js +46 -9
  29. package/dist/http/Transport.js.map +1 -1
  30. package/dist/http/UrlEncoding.d.ts +81 -9
  31. package/dist/http/UrlEncoding.d.ts.map +1 -1
  32. package/dist/http/UrlEncoding.js +41 -5
  33. package/dist/http/UrlEncoding.js.map +1 -1
  34. package/dist/http/internal/fields.d.ts +17 -4
  35. package/dist/http/internal/fields.d.ts.map +1 -1
  36. package/dist/http/internal/fields.js +11 -6
  37. package/dist/http/internal/fields.js.map +1 -1
  38. package/dist/http/internal/input.d.ts +39 -0
  39. package/dist/http/internal/input.d.ts.map +1 -0
  40. package/dist/http/internal/input.js +40 -0
  41. package/dist/http/internal/input.js.map +1 -0
  42. package/dist/http/internal/shape.d.ts +44 -0
  43. package/dist/http/internal/shape.d.ts.map +1 -0
  44. package/dist/http/internal/shape.js +179 -0
  45. package/dist/http/internal/shape.js.map +1 -0
  46. package/dist/main.d.ts +24 -0
  47. package/dist/main.d.ts.map +1 -1
  48. package/dist/main.js +24 -0
  49. package/dist/main.js.map +1 -1
  50. package/package.json +13 -13
  51. package/src/concurrency/Interaction.ts +39 -6
  52. package/src/http/Body.ts +158 -27
  53. package/src/http/Operation.ts +530 -32
  54. package/src/http/Policy.ts +49 -13
  55. package/src/http/Request.ts +1241 -227
  56. package/src/http/Response.ts +316 -28
  57. package/src/http/Transport.ts +59 -11
  58. package/src/http/UrlEncoding.ts +89 -10
  59. package/src/http/internal/fields.ts +37 -9
  60. package/src/http/internal/input.ts +123 -0
  61. package/src/http/internal/shape.ts +279 -0
  62. package/src/main.ts +24 -0
package/README.md CHANGED
@@ -1,58 +1,103 @@
1
1
  # Effect Schema HTTP
2
2
 
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`.
3
+ Define what your application sends to an HTTP service and what it expects back. Effect Schema
4
+ validates and transforms values, and your Effect HTTP client sends the request. The contract belongs
5
+ to your application; the server does not need to use this library or Effect.
6
6
 
7
- Agents write and maintain this project. Its code is not human-reviewed.
7
+ ## Example
8
8
 
9
- ## Status and scope
9
+ Describe a user lookup and the JSON response your application understands. The constructor's path
10
+ and `Request.path` add together, so the example passes `""` and the template holds the whole path;
11
+ `Request.get("/users")` with the same template would ask for `/users/users/42`. A base URL is joined
12
+ to a relative path, and an absolute URL in the request bypasses it:
10
13
 
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).
14
+ ```ts
15
+ import { Effect, Schema } from "effect";
16
+ import { FetchHttpClient } from "effect/http";
17
+ import { Body, Operation, Request, Response } from "viell-effect-schema-http";
16
18
 
17
- Download the tarball, then install it in an ESM project:
19
+ const api = Request.baseUrl("https://api.example.test");
20
+ const userId = Request.pathValue("userId", Schema.FiniteFromString);
21
+
22
+ const getUser = Operation.make(
23
+ Request.get("").pipe(api, Request.path`/users/${userId}`),
24
+ Response.status(
25
+ 200,
26
+ Body.jsonSchema(Schema.Struct({ id: Schema.Number, name: Schema.String })),
27
+ ),
28
+ );
29
+
30
+ const program = getUser
31
+ .execute({ path: { userId: 42 } })
32
+ .pipe(Effect.provide(FetchHttpClient.layer));
33
+ // Replace the example endpoint with your service, then: await Effect.runPromise(program).
34
+
35
+ // Adjust the definition where it is used. getUser itself does not change.
36
+ const inFrench = Request.setHeader("accept-language", "fr");
37
+ const getUserInFrench = getUser.pipe(Operation.mapRequest(inFrench));
38
+ ```
39
+
40
+ Reuse `api` across requests to share the base URL. The path value's schema turns the number into URL
41
+ text, and the library escapes it. The response schema validates the returned JSON. Constructing
42
+ `program` sends nothing; evaluating it produces a typed user or an Effect failure.
43
+
44
+ A definition describes the most common request, not the only one. Write it once, near the
45
+ integration, and let each part of your application adjust its request, response or options. [Getting
46
+ started](https://viell-dev.github.io/slop-effect-schema-http/getting-started) supplies a complete
47
+ in-memory example you can run without a server or credentials.
48
+
49
+ ## Install
50
+
51
+ In an existing Node.js 24 or 26 ESM project with Effect `^4.0.7`, add the library:
18
52
 
19
53
  ```sh
20
- npm install ./viell-effect-schema-http-0.1.0-rc.1.tgz effect@4.1.1
54
+ npm install viell-effect-schema-http
21
55
  ```
22
56
 
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).
57
+ `0.2.0` is the current release. The same package is available as a checksummed [GitHub release
58
+ tarball](https://github.com/viell-dev/slop-effect-schema-http/releases/tag/0.2.0). It changes
59
+ existing behavior, so read [What's in
60
+ 0.2](https://viell-dev.github.io/slop-effect-schema-http/release-notes/0.2) before you update from
61
+ `0.1`.
62
+
63
+ TypeScript declarations and editor documentation are included. The supported environments are Node
64
+ 24 or 26 on Windows/Linux and browser Fetch in Chromium. See [compatibility and
65
+ limits](https://viell-dev.github.io/slop-effect-schema-http/limits) for tested Effect/compiler
66
+ versions and provider boundaries.
67
+
68
+ ## Documentation
69
+
70
+ - [Getting started](https://viell-dev.github.io/slop-effect-schema-http/getting-started):
71
+ installation, a runnable example and the expected output.
72
+ - [Usage](https://viell-dev.github.io/slop-effect-schema-http/usage): add PATCH and DELETE actions,
73
+ share URL descriptions, adjust a definition and connect an operation to your HTTP client.
74
+ - [Recipes](https://viell-dev.github.io/slop-effect-schema-http/recipes): everyday tasks that
75
+ combine the modules, such as adjusting a definition for one component.
76
+ - [Module guides](https://viell-dev.github.io/slop-effect-schema-http/api): Request, Body, Response,
77
+ Operation, Policy, Interaction, UrlEncoding and Transport, from basic use to advanced behavior.
78
+ - [Limits and recovery](https://viell-dev.github.io/slop-effect-schema-http/limits): compatibility,
79
+ where the library's promise stops, failure stages and bug reporting.
80
+ - [What's in 0.2](https://viell-dev.github.io/slop-effect-schema-http/release-notes/0.2) introduces
81
+ the release and how to update, and [What's in
82
+ 0.1](https://viell-dev.github.io/slop-effect-schema-http/release-notes/0.1) the one before it;
83
+ [Versions](https://viell-dev.github.io/slop-effect-schema-http/versions) covers updates and
84
+ compatibility policy. [CHANGELOG.md](./CHANGELOG.md) records the detailed history.
85
+
86
+ The library provides finite-body codecs, typed contracts you can adjust where they are used, ordered
87
+ response selection, retry policies and scoped interaction coordination. It uses the application's
88
+ HTTP transport and Effect runtime. Streaming bodies, server generation and a general cache are
89
+ outside its scope. The [design contract](https://viell-dev.github.io/slop-effect-schema-http/design)
90
+ explains the precise guarantees.
91
+
92
+ ## Project and contribution
93
+
94
+ Agents write and maintain this project. Its code is not human-reviewed. The source is
95
+ [MIT-licensed](./LICENSE). The [release
96
+ tracker](https://github.com/viell-dev/slop-effect-schema-http/issues/2) records the first stable
97
+ release's qualification and publication.
98
+
99
+ Use [CONTRIBUTING.md](./CONTRIBUTING.md) for checkout setup, verification and pull requests. [Report
100
+ a defect](https://github.com/viell-dev/slop-effect-schema-http/issues/new?template=bug_report.yml)
101
+ with a small synthetic reproduction and library, Effect and environment versions. Include expected
102
+ and actual results; keep credentials and private service data out. For sensitive security reports,
103
+ follow the [security policy](./SECURITY.md).
@@ -2,30 +2,63 @@ import { Effect, type Equivalence, Scope } from "effect";
2
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
3
  readonly _tag: "InteractionClosed";
4
4
  } & Readonly<A>;
5
- /** The interaction was closed; it admits no further work. */
5
+ /**
6
+ * A call tried to start work after the interaction had permanently closed.
7
+ *
8
+ * @remarks
9
+ * The error's `_tag` is `"InteractionClosed"`.
10
+ */
6
11
  export declare class Closed extends Closed_base {
7
12
  }
13
+ /**
14
+ * Options for one call to an interaction.
15
+ */
8
16
  export interface RunOptions {
9
17
  /** Start fresh work, superseding active work and bypassing the retained result. */
10
18
  readonly force?: boolean | undefined;
11
19
  }
12
- /** One user-facing interaction: at most one active execution and one retained success. */
20
+ /**
21
+ * Coordinate one active execution and one retained successful result.
22
+ *
23
+ * @remarks
24
+ * Use for one user-facing activity, such as a search field. Equal input shares work or reuses a
25
+ * success; different input supersedes active work. This is not a cache of all previous inputs.
26
+ */
13
27
  export interface Interaction<in I, out A, out E = never> {
14
28
  /** Equal input joins active work or reuses the retained success; different input supersedes active work. */
15
29
  readonly run: (input: I, options?: RunOptions) => Effect.Effect<A, E | Closed>;
16
30
  /** Permanent and idempotent. Every caller waits for all owned finalizers, including superseded work. */
17
31
  readonly close: Effect.Effect<void>;
18
32
  }
33
+ /**
34
+ * Choose how inputs compare and which successful results are retained.
35
+ */
19
36
  export interface Options<I, A> {
20
37
  /** Defaults to `Equal.equals`, which compares plain objects and arrays structurally. */
21
38
  readonly equivalence?: Equivalence.Equivalence<I> | undefined;
22
- /** Whether a successful result is retained for reuse. The result is returned either way. */
39
+ /** Whether to retain a success. Defaults to retaining; the result is returned either way. */
23
40
  readonly retain?: ((value: A, input: I) => boolean) | undefined;
24
41
  }
25
42
  /**
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.
43
+ * Acquire a scoped interaction around an Effect-returning function.
44
+ *
45
+ * @example
46
+ * ```ts
47
+ * import { Effect } from "effect";
48
+ * import { Interaction } from "viell-effect-schema-http";
49
+ * const program = Effect.scoped(Effect.gen(function* () {
50
+ * const lookup = yield* Interaction.make((id: number) => Effect.succeed({ id }));
51
+ * const first = yield* lookup.run(42);
52
+ * const reused = yield* lookup.run(42);
53
+ * return [first, reused];
54
+ * }));
55
+ * ```
56
+ *
57
+ * @remarks
58
+ * Keep the acquiring scope alive while calls should be accepted. Required services are captured
59
+ * at acquisition. Each execution belongs to the interaction in its own child scope; cancelling
60
+ * one waiter does not cancel shared work. Closing the acquiring scope closes the interaction
61
+ * and waits for all owned cleanup.
29
62
  */
30
63
  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
64
  export {};
@@ -1 +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,OAA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CAAC;CACtC;AAED;;;;;;GAMG;AACH,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;;GAEG;AACH,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,6FAA6F;IAC7F,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,KAAK,OAAO,CAAC,GAAG,SAAS,CAAC;CACjE;AAQD;;;;;;;;;;;;;;;;;;;;GAoBG;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"}
@@ -1,11 +1,32 @@
1
1
  import { Context, Data, Deferred, Effect, Equal, Exit, Scope, Semaphore, } from "effect";
2
- /** The interaction was closed; it admits no further work. */
2
+ /**
3
+ * A call tried to start work after the interaction had permanently closed.
4
+ *
5
+ * @remarks
6
+ * The error's `_tag` is `"InteractionClosed"`.
7
+ */
3
8
  export class Closed extends Data.TaggedError("InteractionClosed") {
4
9
  }
5
10
  /**
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.
11
+ * Acquire a scoped interaction around an Effect-returning function.
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * import { Effect } from "effect";
16
+ * import { Interaction } from "viell-effect-schema-http";
17
+ * const program = Effect.scoped(Effect.gen(function* () {
18
+ * const lookup = yield* Interaction.make((id: number) => Effect.succeed({ id }));
19
+ * const first = yield* lookup.run(42);
20
+ * const reused = yield* lookup.run(42);
21
+ * return [first, reused];
22
+ * }));
23
+ * ```
24
+ *
25
+ * @remarks
26
+ * Keep the acquiring scope alive while calls should be accepted. Required services are captured
27
+ * at acquisition. Each execution belongs to the interaction in its own child scope; cancelling
28
+ * one waiter does not cancel shared work. Closing the acquiring scope closes the interaction
29
+ * and waits for all owned cleanup.
9
30
  */
10
31
  export const make = Effect.fnUntraced(function* (execute, options) {
11
32
  const context = yield* Effect.context();
@@ -1 +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;AAEhB,6DAA6D;AAC7D,MAAM,OAAO,MAAO,SAAQ,IAAI,CAAC,WAAW,CAAC,mBAAmB,CAAC;CAAG;AA+BpE;;;;GAIG;AACH,MAAM,CAAC,MAAM,IAAI,GAAG,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,EAC7C,OAA6C,EAC7C,OAAuB;IAEvB,MAAM,OAAO,GAAG,KAAK,CAAC,CAAC,MAAM,CAAC,OAAO,EAAK,CAAC;IAC3C,MAAM,KAAK,GAAG,KAAK,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IAC5C,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,CA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ClientResponse, type UrlParams } from "effect/http";
3
- /** A finite outgoing representation, encoded once per operation evaluation. */
3
+ import * as Inputs from "./internal/input.js";
4
+ /**
5
+ * Turn an application value into a finite outgoing HTTP body.
6
+ *
7
+ * @remarks
8
+ * Use with `Request.body`. Encoding occurs once per operation evaluation, before dispatch.
9
+ */
4
10
  export interface Encoder<in A, out E = never, out R = never> extends Pipeable.Pipeable {
5
11
  readonly encode: (value: A) => Effect.Effect<HttpBody.HttpBody, E, R>;
6
12
  }
7
- /** A finite incoming representation. The decoder owns the selected response body. */
13
+ /**
14
+ * Read a finite response body into an application value.
15
+ *
16
+ * @remarks
17
+ * Use with `Response.status` or `Response.when`. Read the body within the returned Effect;
18
+ * `Operation.make` closes the attempt's resources before returning the decoded result.
19
+ */
8
20
  export interface Decoder<out A, out E = never, out R = never> extends Pipeable.Pipeable {
9
21
  readonly decode: (response: HttpClientResponse.HttpClientResponse) => Effect.Effect<A, E, R>;
10
- /** Contributes to the automatic `Accept` header of an operation. */
22
+ /** Contributes to automatic `Accept`; it does not validate response Content-Type. */
11
23
  readonly mediaType: string | undefined;
12
24
  }
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> {
25
+ /**
26
+ * An encoder and decoder for the same application value.
27
+ *
28
+ * @remarks
29
+ * Encoding and decoding errors and required services are tracked separately. `In` is what encoding
30
+ * takes, which is `A` unless the codec accepts more than it decodes to, as {@link jsonSchema} does.
31
+ */
32
+ export interface Codec<A, EncodeError = never, DecodeError = never, EncodeServices = never, DecodeServices = never, In = A> extends Encoder<In, EncodeError, EncodeServices>, Decoder<A, DecodeError, DecodeServices> {
15
33
  }
34
+ /**
35
+ * Create a custom outgoing body encoder from an Effect-returning function.
36
+ *
37
+ * @remarks
38
+ * Return an Effect `HttpBody` with the representation and content metadata your service needs.
39
+ */
16
40
  export declare const encoder: <A, E = never, R = never>(encode: (value: A) => Effect.Effect<HttpBody.HttpBody, E, R>) => Encoder<A, E, R>;
41
+ /**
42
+ * Create a custom response-body decoder from an Effect-returning function.
43
+ *
44
+ * @remarks
45
+ * `mediaType` contributes to automatic `Accept`; it does not validate response Content-Type.
46
+ * Return typed failures through the Effect error channel; thrown exceptions are defects.
47
+ */
17
48
  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>;
49
+ /**
50
+ * Combine custom encoding and decoding functions into one body codec.
51
+ *
52
+ * @remarks
53
+ * `mediaType` describes the accepted response representation. Outgoing content metadata comes
54
+ * from the `HttpBody` returned by `encode`. `encode` may take more than `decode` returns.
55
+ */
56
+ export declare const make: <A, EncodeError = never, DecodeError = never, EncodeServices = never, DecodeServices = never, In = A>(options: {
57
+ readonly encode: (value: In) => Effect.Effect<HttpBody.HttpBody, EncodeError, EncodeServices>;
20
58
  readonly decode: (response: HttpClientResponse.HttpClientResponse) => Effect.Effect<A, DecodeError, DecodeServices>;
21
59
  readonly mediaType?: string | undefined;
22
- }) => Codec<A, EncodeError, DecodeError, EncodeServices, DecodeServices>;
60
+ }) => Codec<A, EncodeError, DecodeError, EncodeServices, DecodeServices, In>;
23
61
  /**
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`.
62
+ * Read and write JSON without schema validation.
63
+ *
64
+ * @remarks
65
+ * Encoding uses Effect's `HttpBody.json`. Values omitted by `JSON.stringify`, such as
66
+ * `undefined`, produce an empty outgoing body. An empty incoming body is a decoding failure,
67
+ * not `null`. Use {@link jsonSchema} to validate and transform application values.
27
68
  */
28
69
  export declare const json: Codec<unknown, HttpBody.HttpBodyError, HttpClientError.HttpClientError>;
29
70
  /**
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.
71
+ * Read and write text, with `text/plain` as the media type.
72
+ *
73
+ * @remarks
74
+ * Outgoing text is UTF-8. Incoming decoding delegates to the provider's `response.text`.
75
+ * Fetch-backed providers ignore charset parameters, strip a leading UTF-8 BOM, and replace
76
+ * malformed bytes with U+FFFD. Use {@link bytes} for strict or non-UTF-8 decoding.
33
77
  */
34
78
  export declare const text: Codec<string, never, HttpClientError.HttpClientError>;
79
+ /**
80
+ * Read and write `Uint8Array` bodies as `application/octet-stream`.
81
+ *
82
+ * @remarks
83
+ * Incoming bytes are buffered. Use a schema or custom decoder to interpret another encoding.
84
+ */
35
85
  export declare const bytes: Codec<Uint8Array, never, HttpClientError.HttpClientError>;
36
- /** Multipart form data. The transport owns the boundary and its Content-Type. */
86
+ /**
87
+ * Read and write Web `FormData` as multipart form data.
88
+ *
89
+ * @remarks
90
+ * The transport supplies the outgoing multipart boundary and its Content-Type. A Content-Type the
91
+ * request declares replaces it, and without the boundary the body cannot be read. Decoding
92
+ * delegates to the HTTP provider.
93
+ */
37
94
  export declare const formData: Codec<FormData, never, HttpClientError.HttpClientError>;
95
+ /**
96
+ * Read and write form bodies using Effect's `UrlParams.UrlParams`.
97
+ *
98
+ * @remarks
99
+ * Construct values with `UrlParams.fromInput` from `effect/http`. The media type is
100
+ * `application/x-www-form-urlencoded`.
101
+ */
38
102
  export declare const urlEncoded: Codec<UrlParams.UrlParams, never, HttpClientError.HttpClientError>;
39
- /** No outgoing body. Incoming bytes, including unexpected ones, are drained without buffering. */
103
+ /**
104
+ * Send no body, or discard an incoming body when its content is not needed.
105
+ *
106
+ * @remarks
107
+ * Decoding drains even unexpected incoming bytes without buffering them. Draining has no
108
+ * intrinsic timeout; use an attempt or operation timeout for an unbounded response.
109
+ */
40
110
  export declare const empty: Codec<void, never, HttpClientError.HttpClientError>;
111
+ /**
112
+ * Transform a decoded value with a pure function, preserving its media type.
113
+ *
114
+ * @remarks
115
+ * Returns a decoder only. Use {@link mapEffect} if the transformation may fail or need services.
116
+ */
41
117
  export declare const map: <A, B>(f: (value: A) => B) => <E, R>(self: Decoder<A, E, R>) => Decoder<B, E, R>;
118
+ /**
119
+ * Transform a decoded value with an Effect, adding its errors and required services.
120
+ *
121
+ * @remarks
122
+ * Returns a decoder only and preserves the media type. When used in a response case, this work
123
+ * is part of that attempt's decoding and is covered by its timeout.
124
+ */
42
125
  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. */
126
+ /**
127
+ * Validate and transform a decoded value with an Effect schema.
128
+ *
129
+ * @example
130
+ * ```ts
131
+ * import { Schema } from "effect";
132
+ * import { Body } from "viell-effect-schema-http";
133
+ * const numberFromText = Body.text.pipe(Body.schema(Schema.FiniteFromString));
134
+ * // Decodes the text "42" to the number 42.
135
+ * ```
136
+ *
137
+ * @remarks
138
+ * Returns a decoder with the schema's application type. A failure in a selected response case
139
+ * is final for that attempt; it does not try a later response case.
140
+ */
44
141
  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
142
  /**
48
- * Bidirectional JSON through the schema's canonical JSON codec (`Schema.toCodecJson`), as in Effect's own
49
- * JSON body helpers.
143
+ * Validate and encode application input before passing it to a body encoder.
144
+ *
145
+ * @remarks
146
+ * The schema's encoded type must match the underlying encoder's input. Returns an encoder only;
147
+ * use {@link schema} for the decoding direction. The input takes either side of the schema, or a
148
+ * mix by field, as `Request.Input` describes, so a plain object works for a `Schema.Class`, and
149
+ * the underlying encoder receives what the schema writes.
150
+ */
151
+ export declare const encodeSchema: <S extends Schema.Top>(contract: S) => <E, R>(self: Encoder<S["Encoded"], E, R>) => Encoder<Inputs.Input<S>, E | Schema.SchemaError, R | S["EncodingServices"] | S["DecodingServices"]>;
152
+ /**
153
+ * Read and write schema-validated JSON, returning the schema's application type.
154
+ *
155
+ * @example
156
+ * ```ts
157
+ * import { Schema } from "effect";
158
+ * import { Body } from "viell-effect-schema-http";
159
+ * const user = Body.jsonSchema(Schema.Struct({ id: Schema.Number, name: Schema.String }));
160
+ * ```
161
+ *
162
+ * @remarks
163
+ * Uses `Schema.toCodecJson` to obtain the schema's canonical JSON codec. Encoding failures occur
164
+ * before dispatch; an operation wraps response decoding failures in `Response.DecodeError`.
165
+ *
166
+ * Encoding takes either side of the schema, or a mix by field, as `Request.Input` describes, and
167
+ * writes the canonical JSON. The encoded side is the schema's own, so a `Schema.Date` field takes a
168
+ * `Date`, not the ISO text JSON carries. Decoding returns the schema's application type, so a class
169
+ * comes back as an instance.
50
170
  */
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"]>;
171
+ export declare const jsonSchema: <S extends Schema.Top>(contract: S) => Codec<S["Type"], Schema.SchemaError | HttpBody.HttpBodyError, Schema.SchemaError | HttpClientError.HttpClientError, S["EncodingServices"] | S["DecodingServices"], S["DecodingServices"], Inputs.Input<S>>;
52
172
  //# sourceMappingURL=Body.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Body.d.ts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