viell-effect-schema-http 0.1.0 → 0.3.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.
- package/README.md +44 -29
- package/dist/concurrency/Interaction.d.ts +7 -1
- package/dist/concurrency/Interaction.d.ts.map +1 -1
- package/dist/concurrency/Interaction.js.map +1 -1
- package/dist/http/Body.d.ts +25 -13
- package/dist/http/Body.d.ts.map +1 -1
- package/dist/http/Body.js +18 -8
- package/dist/http/Body.js.map +1 -1
- package/dist/http/Operation.d.ts +276 -13
- package/dist/http/Operation.d.ts.map +1 -1
- package/dist/http/Operation.js +210 -11
- package/dist/http/Operation.js.map +1 -1
- package/dist/http/Policy.d.ts +28 -2
- package/dist/http/Policy.d.ts.map +1 -1
- package/dist/http/Policy.js +28 -2
- package/dist/http/Policy.js.map +1 -1
- package/dist/http/Request.d.ts +520 -85
- package/dist/http/Request.d.ts.map +1 -1
- package/dist/http/Request.js +658 -143
- package/dist/http/Request.js.map +1 -1
- package/dist/http/Response.d.ts +130 -6
- package/dist/http/Response.d.ts.map +1 -1
- package/dist/http/Response.js +88 -7
- package/dist/http/Response.js.map +1 -1
- package/dist/http/UrlEncoding.d.ts +24 -7
- package/dist/http/UrlEncoding.d.ts.map +1 -1
- package/dist/http/UrlEncoding.js +7 -3
- package/dist/http/UrlEncoding.js.map +1 -1
- package/dist/http/internal/excess.d.ts +44 -0
- package/dist/http/internal/excess.d.ts.map +1 -0
- package/dist/http/internal/excess.js +231 -0
- package/dist/http/internal/excess.js.map +1 -0
- package/dist/http/internal/fields.d.ts +17 -4
- package/dist/http/internal/fields.d.ts.map +1 -1
- package/dist/http/internal/fields.js +11 -6
- package/dist/http/internal/fields.js.map +1 -1
- package/dist/http/internal/input.d.ts +70 -0
- package/dist/http/internal/input.d.ts.map +1 -0
- package/dist/http/internal/input.js +93 -0
- package/dist/http/internal/input.js.map +1 -0
- package/dist/http/internal/shape.d.ts +63 -0
- package/dist/http/internal/shape.d.ts.map +1 -0
- package/dist/http/internal/shape.js +225 -0
- package/dist/http/internal/shape.js.map +1 -0
- package/package.json +13 -12
- package/src/concurrency/Interaction.ts +7 -1
- package/src/http/Body.ts +41 -18
- package/src/http/Operation.ts +474 -33
- package/src/http/Policy.ts +30 -2
- package/src/http/Request.ts +1176 -253
- package/src/http/Response.ts +246 -23
- package/src/http/UrlEncoding.ts +32 -8
- package/src/http/internal/excess.ts +333 -0
- package/src/http/internal/fields.ts +37 -9
- package/src/http/internal/input.ts +228 -0
- package/src/http/internal/shape.ts +359 -0
package/README.md
CHANGED
|
@@ -6,7 +6,10 @@ to your application; the server does not need to use this library or Effect.
|
|
|
6
6
|
|
|
7
7
|
## Example
|
|
8
8
|
|
|
9
|
-
Describe a user lookup and the JSON response your application understands
|
|
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
14
|
```ts
|
|
12
15
|
import { Effect, Schema } from "effect";
|
|
@@ -14,12 +17,10 @@ import { FetchHttpClient } from "effect/http";
|
|
|
14
17
|
import { Body, Operation, Request, Response } from "viell-effect-schema-http";
|
|
15
18
|
|
|
16
19
|
const api = Request.baseUrl("https://api.example.test");
|
|
20
|
+
const userId = Request.pathValue("userId", Schema.FiniteFromString);
|
|
17
21
|
|
|
18
22
|
const getUser = Operation.make(
|
|
19
|
-
Request.get("").pipe(
|
|
20
|
-
api,
|
|
21
|
-
Request.path(Schema.NumberFromString, (id, encode) => `/users/${encode(id)}`),
|
|
22
|
-
),
|
|
23
|
+
Request.get("").pipe(api, Request.path`/users/${userId}`),
|
|
23
24
|
Response.status(
|
|
24
25
|
200,
|
|
25
26
|
Body.jsonSchema(Schema.Struct({ id: Schema.Number, name: Schema.String })),
|
|
@@ -27,31 +28,40 @@ const getUser = Operation.make(
|
|
|
27
28
|
);
|
|
28
29
|
|
|
29
30
|
const program = getUser
|
|
30
|
-
.execute({ path: 42 })
|
|
31
|
+
.execute({ path: { userId: 42 } })
|
|
31
32
|
.pipe(Effect.provide(FetchHttpClient.layer));
|
|
32
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));
|
|
33
38
|
```
|
|
34
39
|
|
|
35
|
-
Reuse `api` across requests to share the base URL. The path
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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
|
|
39
46
|
started](https://viell-dev.github.io/slop-effect-schema-http/getting-started) supplies a complete
|
|
40
47
|
in-memory example you can run without a server or credentials.
|
|
41
48
|
|
|
42
49
|
## Install
|
|
43
50
|
|
|
44
|
-
In an existing Node.js 24 ESM project with Effect `^4.0.7`, add the library:
|
|
51
|
+
In an existing Node.js 24 or 26 ESM project with Effect `^4.0.7`, add the library:
|
|
45
52
|
|
|
46
53
|
```sh
|
|
47
54
|
npm install viell-effect-schema-http
|
|
48
55
|
```
|
|
49
56
|
|
|
50
|
-
`0.
|
|
51
|
-
tarball](https://github.com/viell-dev/slop-effect-schema-http/releases/tag/0.
|
|
57
|
+
`0.3.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.3.0). It changes
|
|
59
|
+
existing behavior, so read [What's in
|
|
60
|
+
0.3](https://viell-dev.github.io/slop-effect-schema-http/release-notes/0.3) before you update from
|
|
61
|
+
`0.2`.
|
|
52
62
|
|
|
53
63
|
TypeScript declarations and editor documentation are included. The supported environments are Node
|
|
54
|
-
24 on Windows/Linux and browser Fetch in Chromium. See [compatibility and
|
|
64
|
+
24 or 26 on Windows/Linux and browser Fetch in Chromium. See [compatibility and
|
|
55
65
|
limits](https://viell-dev.github.io/slop-effect-schema-http/limits) for tested Effect/compiler
|
|
56
66
|
versions and provider boundaries.
|
|
57
67
|
|
|
@@ -60,20 +70,25 @@ versions and provider boundaries.
|
|
|
60
70
|
- [Getting started](https://viell-dev.github.io/slop-effect-schema-http/getting-started):
|
|
61
71
|
installation, a runnable example and the expected output.
|
|
62
72
|
- [Usage](https://viell-dev.github.io/slop-effect-schema-http/usage): add PATCH and DELETE actions,
|
|
63
|
-
share URL descriptions and connect an operation to your HTTP client.
|
|
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.
|
|
64
76
|
- [Module guides](https://viell-dev.github.io/slop-effect-schema-http/api): Request, Body, Response,
|
|
65
77
|
Operation, Policy, Interaction, UrlEncoding and Transport, from basic use to advanced behavior.
|
|
66
78
|
- [Limits and recovery](https://viell-dev.github.io/slop-effect-schema-http/limits): compatibility,
|
|
67
|
-
failure stages and bug reporting.
|
|
68
|
-
- [What's in 0.
|
|
69
|
-
the release
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
79
|
+
where the library's promise stops, failure stages and bug reporting.
|
|
80
|
+
- [What's in 0.3](https://viell-dev.github.io/slop-effect-schema-http/release-notes/0.3) introduces
|
|
81
|
+
the release and how to update, and [What's in
|
|
82
|
+
0.2](https://viell-dev.github.io/slop-effect-schema-http/release-notes/0.2) and [What's in
|
|
83
|
+
0.1](https://viell-dev.github.io/slop-effect-schema-http/release-notes/0.1) the earlier ones;
|
|
84
|
+
[Versions](https://viell-dev.github.io/slop-effect-schema-http/versions) covers updates and
|
|
85
|
+
compatibility policy. [CHANGELOG.md](./CHANGELOG.md) records the detailed history.
|
|
86
|
+
|
|
87
|
+
The library provides finite-body codecs, typed contracts you can adjust where they are used, ordered
|
|
88
|
+
response selection, retry policies and scoped interaction coordination. It uses the application's
|
|
89
|
+
HTTP transport and Effect runtime. Streaming bodies, server generation and a general cache are
|
|
90
|
+
outside its scope. The [design contract](https://viell-dev.github.io/slop-effect-schema-http/design)
|
|
91
|
+
explains the precise guarantees.
|
|
77
92
|
|
|
78
93
|
## Project and contribution
|
|
79
94
|
|
|
@@ -83,7 +98,7 @@ tracker](https://github.com/viell-dev/slop-effect-schema-http/issues/2) records
|
|
|
83
98
|
release's qualification and publication.
|
|
84
99
|
|
|
85
100
|
Use [CONTRIBUTING.md](./CONTRIBUTING.md) for checkout setup, verification and pull requests. [Report
|
|
86
|
-
a defect](https://github.com/viell-dev/slop-effect-schema-http/issues)
|
|
87
|
-
reproduction and library, Effect and environment versions. Include expected
|
|
88
|
-
credentials and private service data out. For sensitive security reports,
|
|
89
|
-
|
|
101
|
+
a defect](https://github.com/viell-dev/slop-effect-schema-http/issues/new?template=bug_report.yml)
|
|
102
|
+
with a small synthetic reproduction and library, Effect and environment versions. Include expected
|
|
103
|
+
and actual results; keep credentials and private service data out. For sensitive security reports,
|
|
104
|
+
follow the [security policy](./SECURITY.md).
|
|
@@ -36,7 +36,13 @@ export interface Interaction<in I, out A, out E = never> {
|
|
|
36
36
|
export interface Options<I, A> {
|
|
37
37
|
/** Defaults to `Equal.equals`, which compares plain objects and arrays structurally. */
|
|
38
38
|
readonly equivalence?: Equivalence.Equivalence<I> | undefined;
|
|
39
|
-
/**
|
|
39
|
+
/**
|
|
40
|
+
* Whether to retain a success. Defaults to retaining; the result is returned either way.
|
|
41
|
+
*
|
|
42
|
+
* @remarks
|
|
43
|
+
* Rejecting a result also drops an earlier retained success for equal input, which it replaces.
|
|
44
|
+
* Another input's retained success stays.
|
|
45
|
+
*/
|
|
40
46
|
readonly retain?: ((value: A, input: I) => boolean) | undefined;
|
|
41
47
|
}
|
|
42
48
|
/**
|
|
@@ -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;;;;;GAKG;AACH,qBAAa,MAAO,SAAQ,WAAqC;CAAG;AAEpE;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,mFAAmF;IACnF,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,GAAG,SAAS,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
|
|
1
|
+
{"version":3,"file":"Interaction.d.ts","sourceRoot":"","sources":["../../src/concurrency/Interaction.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,MAAM,EAEN,KAAK,WA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ect";
|
|
2
2
|
import { HttpBody, HttpClientError, type HttpClientResponse, type UrlParams } from "effect/http";
|
|
3
|
+
import * as Inputs from "./internal/input.js";
|
|
3
4
|
/**
|
|
4
5
|
* Turn an application value into a finite outgoing HTTP body.
|
|
5
6
|
*
|
|
@@ -7,6 +8,7 @@ import { HttpBody, HttpClientError, type HttpClientResponse, type UrlParams } fr
|
|
|
7
8
|
* Use with `Request.body`. Encoding occurs once per operation evaluation, before dispatch.
|
|
8
9
|
*/
|
|
9
10
|
export interface Encoder<in A, out E = never, out R = never> extends Pipeable.Pipeable {
|
|
11
|
+
/** Turn a value into an outgoing body. */
|
|
10
12
|
readonly encode: (value: A) => Effect.Effect<HttpBody.HttpBody, E, R>;
|
|
11
13
|
}
|
|
12
14
|
/**
|
|
@@ -17,6 +19,7 @@ export interface Encoder<in A, out E = never, out R = never> extends Pipeable.Pi
|
|
|
17
19
|
* `Operation.make` closes the attempt's resources before returning the decoded result.
|
|
18
20
|
*/
|
|
19
21
|
export interface Decoder<out A, out E = never, out R = never> extends Pipeable.Pipeable {
|
|
22
|
+
/** Read a response's body into a value. */
|
|
20
23
|
readonly decode: (response: HttpClientResponse.HttpClientResponse) => Effect.Effect<A, E, R>;
|
|
21
24
|
/** Contributes to automatic `Accept`; it does not validate response Content-Type. */
|
|
22
25
|
readonly mediaType: string | undefined;
|
|
@@ -25,9 +28,10 @@ export interface Decoder<out A, out E = never, out R = never> extends Pipeable.P
|
|
|
25
28
|
* An encoder and decoder for the same application value.
|
|
26
29
|
*
|
|
27
30
|
* @remarks
|
|
28
|
-
* Encoding and decoding errors and required services are tracked separately.
|
|
31
|
+
* Encoding and decoding errors and required services are tracked separately. `In` is what encoding
|
|
32
|
+
* takes, which is `A` unless the codec accepts more than it decodes to, as {@link jsonSchema} does.
|
|
29
33
|
*/
|
|
30
|
-
export interface Codec<A, EncodeError = never, DecodeError = never, EncodeServices = never, DecodeServices = never> extends Encoder<
|
|
34
|
+
export interface Codec<A, EncodeError = never, DecodeError = never, EncodeServices = never, DecodeServices = never, In = A> extends Encoder<In, EncodeError, EncodeServices>, Decoder<A, DecodeError, DecodeServices> {
|
|
31
35
|
}
|
|
32
36
|
/**
|
|
33
37
|
* Create a custom outgoing body encoder from an Effect-returning function.
|
|
@@ -49,13 +53,13 @@ export declare const decoder: <A, E = never, R = never>(decode: (response: HttpC
|
|
|
49
53
|
*
|
|
50
54
|
* @remarks
|
|
51
55
|
* `mediaType` describes the accepted response representation. Outgoing content metadata comes
|
|
52
|
-
* from the `HttpBody` returned by `encode`.
|
|
56
|
+
* from the `HttpBody` returned by `encode`. `encode` may take more than `decode` returns.
|
|
53
57
|
*/
|
|
54
|
-
export declare const make: <A, EncodeError = never, DecodeError = never, EncodeServices = never, DecodeServices = never>(options: {
|
|
55
|
-
readonly encode: (value:
|
|
58
|
+
export declare const make: <A, EncodeError = never, DecodeError = never, EncodeServices = never, DecodeServices = never, In = A>(options: {
|
|
59
|
+
readonly encode: (value: In) => Effect.Effect<HttpBody.HttpBody, EncodeError, EncodeServices>;
|
|
56
60
|
readonly decode: (response: HttpClientResponse.HttpClientResponse) => Effect.Effect<A, DecodeError, DecodeServices>;
|
|
57
61
|
readonly mediaType?: string | undefined;
|
|
58
|
-
}) => Codec<A, EncodeError, DecodeError, EncodeServices, DecodeServices>;
|
|
62
|
+
}) => Codec<A, EncodeError, DecodeError, EncodeServices, DecodeServices, In>;
|
|
59
63
|
/**
|
|
60
64
|
* Read and write JSON without schema validation.
|
|
61
65
|
*
|
|
@@ -85,8 +89,9 @@ export declare const bytes: Codec<Uint8Array, never, HttpClientError.HttpClientE
|
|
|
85
89
|
* Read and write Web `FormData` as multipart form data.
|
|
86
90
|
*
|
|
87
91
|
* @remarks
|
|
88
|
-
* The transport supplies the outgoing multipart boundary and its Content-Type.
|
|
89
|
-
*
|
|
92
|
+
* The transport supplies the outgoing multipart boundary and its Content-Type. A Content-Type the
|
|
93
|
+
* request declares replaces it, and without the boundary the body cannot be read. Decoding
|
|
94
|
+
* delegates to the HTTP provider.
|
|
90
95
|
*/
|
|
91
96
|
export declare const formData: Codec<FormData, never, HttpClientError.HttpClientError>;
|
|
92
97
|
/**
|
|
@@ -127,7 +132,7 @@ export declare const mapEffect: <A, B, E2, R2>(f: (value: A) => Effect.Effect<B,
|
|
|
127
132
|
* ```ts
|
|
128
133
|
* import { Schema } from "effect";
|
|
129
134
|
* import { Body } from "viell-effect-schema-http";
|
|
130
|
-
* const numberFromText = Body.text.pipe(Body.schema(Schema.
|
|
135
|
+
* const numberFromText = Body.text.pipe(Body.schema(Schema.FiniteFromString));
|
|
131
136
|
* // Decodes the text "42" to the number 42.
|
|
132
137
|
* ```
|
|
133
138
|
*
|
|
@@ -141,11 +146,13 @@ export declare const schema: <S extends Schema.Constraint>(contract: S) => <A, E
|
|
|
141
146
|
*
|
|
142
147
|
* @remarks
|
|
143
148
|
* The schema's encoded type must match the underlying encoder's input. Returns an encoder only;
|
|
144
|
-
* use {@link schema} for the decoding direction.
|
|
149
|
+
* use {@link schema} for the decoding direction. The input takes either side of the schema, or a
|
|
150
|
+
* mix by field, as `Request.Input` describes, so a plain object works for a `Schema.Class`, and
|
|
151
|
+
* the underlying encoder receives what the schema writes.
|
|
145
152
|
*/
|
|
146
|
-
export declare const encodeSchema: <S extends Schema.
|
|
153
|
+
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"]>;
|
|
147
154
|
/**
|
|
148
|
-
* Read and write schema-validated JSON
|
|
155
|
+
* Read and write schema-validated JSON, returning the schema's application type.
|
|
149
156
|
*
|
|
150
157
|
* @example
|
|
151
158
|
* ```ts
|
|
@@ -157,6 +164,11 @@ export declare const encodeSchema: <S extends Schema.Constraint>(contract: S) =>
|
|
|
157
164
|
* @remarks
|
|
158
165
|
* Uses `Schema.toCodecJson` to obtain the schema's canonical JSON codec. Encoding failures occur
|
|
159
166
|
* before dispatch; an operation wraps response decoding failures in `Response.DecodeError`.
|
|
167
|
+
*
|
|
168
|
+
* Encoding takes either side of the schema, or a mix by field, as `Request.Input` describes, and
|
|
169
|
+
* writes the canonical JSON. The encoded side is the schema's own, so a `Schema.Date` field takes a
|
|
170
|
+
* `Date`, not the ISO text JSON carries. Decoding returns the schema's application type, so a class
|
|
171
|
+
* comes back as an instance.
|
|
160
172
|
*/
|
|
161
|
-
export declare const jsonSchema: <S extends Schema.
|
|
173
|
+
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>>;
|
|
162
174
|
//# sourceMappingURL=Body.d.ts.map
|
package/dist/http/Body.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Body.d.ts","sourceRoot":"","sources":["../../src/http/Body.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAU,MAAM,QAAQ,CAAC;AAC1D,OAAO,EACL,QAAQ,EACR,eAAe,EACf,KAAK,kBAAkB,EACvB,KAAK,SAAS,EACf,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"Body.d.ts","sourceRoot":"","sources":["../../src/http/Body.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAU,MAAM,QAAQ,CAAC;AAC1D,OAAO,EACL,QAAQ,EACR,eAAe,EACf,KAAK,kBAAkB,EACvB,KAAK,SAAS,EACf,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,MAAM,MAAM,qBAAqB,CAAC;AAE9C;;;;;GAKG;AACH,MAAM,WAAW,OAAO,CAAC,EAAE,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,GAAG,KAAK,EAAE,GAAG,CAAC,CAAC,GAAG,KA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E,CAAC,GAAG,MAAM,CAAC,WAAW,EAAE,CAAC,GAAG,CAAC,CAAC,kBAAkB,CAAC,CAExE,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,YAAY,GAAI,CAAC,SAAS,MAAM,CAAC,GAAG,EAAE,UAAU,CAAC,MAEpD,CAAC,EAAE,CAAC,EACV,MAAM,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,KAChC,OAAO,CACR,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,EACf,CAAC,GAAG,MAAM,CAAC,WAAW,EACtB,CAAC,GAAG,CAAC,CAAC,kBAAkB,CAAC,GAAG,CAAC,CAAC,kBAAkB,CAAC,CAKpD,CAAC;AAEF;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,UAAU,GAAI,CAAC,SAAS,MAAM,CAAC,GAAG,EAC7C,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,GAAG,CAAC,CAAC,kBAAkB,CAAC,EAC7C,CAAC,CAAC,kBAAkB,CAAC,EACrB,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAUhB,CAAC"}
|
package/dist/http/Body.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Effect, Pipeable, Schema, Stream } from "effect";
|
|
2
2
|
import { HttpBody, HttpClientError, } from "effect/http";
|
|
3
|
+
import * as Inputs from "./internal/input.js";
|
|
3
4
|
/**
|
|
4
5
|
* Create a custom outgoing body encoder from an Effect-returning function.
|
|
5
6
|
*
|
|
@@ -23,7 +24,7 @@ export const decoder = (decode, mediaType) => ({ ...Pipeable.Prototype, decode,
|
|
|
23
24
|
*
|
|
24
25
|
* @remarks
|
|
25
26
|
* `mediaType` describes the accepted response representation. Outgoing content metadata comes
|
|
26
|
-
* from the `HttpBody` returned by `encode`.
|
|
27
|
+
* from the `HttpBody` returned by `encode`. `encode` may take more than `decode` returns.
|
|
27
28
|
*/
|
|
28
29
|
export const make = (options) => ({
|
|
29
30
|
...Pipeable.Prototype,
|
|
@@ -82,8 +83,9 @@ export const bytes = make({
|
|
|
82
83
|
* Read and write Web `FormData` as multipart form data.
|
|
83
84
|
*
|
|
84
85
|
* @remarks
|
|
85
|
-
* The transport supplies the outgoing multipart boundary and its Content-Type.
|
|
86
|
-
*
|
|
86
|
+
* The transport supplies the outgoing multipart boundary and its Content-Type. A Content-Type the
|
|
87
|
+
* request declares replaces it, and without the boundary the body cannot be read. Decoding
|
|
88
|
+
* delegates to the HTTP provider.
|
|
87
89
|
*/
|
|
88
90
|
export const formData = make({
|
|
89
91
|
encode: (value) => Effect.sync(() => HttpBody.formData(value)),
|
|
@@ -136,7 +138,7 @@ export const mapEffect = (f) => (self) => decoder((response) => Effect.flatMap(s
|
|
|
136
138
|
* ```ts
|
|
137
139
|
* import { Schema } from "effect";
|
|
138
140
|
* import { Body } from "viell-effect-schema-http";
|
|
139
|
-
* const numberFromText = Body.text.pipe(Body.schema(Schema.
|
|
141
|
+
* const numberFromText = Body.text.pipe(Body.schema(Schema.FiniteFromString));
|
|
140
142
|
* // Decodes the text "42" to the number 42.
|
|
141
143
|
* ```
|
|
142
144
|
*
|
|
@@ -153,14 +155,16 @@ export const schema = (contract) => {
|
|
|
153
155
|
*
|
|
154
156
|
* @remarks
|
|
155
157
|
* The schema's encoded type must match the underlying encoder's input. Returns an encoder only;
|
|
156
|
-
* use {@link schema} for the decoding direction.
|
|
158
|
+
* use {@link schema} for the decoding direction. The input takes either side of the schema, or a
|
|
159
|
+
* mix by field, as `Request.Input` describes, so a plain object works for a `Schema.Class`, and
|
|
160
|
+
* the underlying encoder receives what the schema writes.
|
|
157
161
|
*/
|
|
158
162
|
export const encodeSchema = (contract) => {
|
|
159
|
-
const encode = Schema.encodeEffect(contract);
|
|
163
|
+
const encode = Inputs.encoder(contract, Schema.encodeEffect(contract));
|
|
160
164
|
return (self) => encoder((value) => Effect.flatMap(encode(value), self.encode));
|
|
161
165
|
};
|
|
162
166
|
/**
|
|
163
|
-
* Read and write schema-validated JSON
|
|
167
|
+
* Read and write schema-validated JSON, returning the schema's application type.
|
|
164
168
|
*
|
|
165
169
|
* @example
|
|
166
170
|
* ```ts
|
|
@@ -172,11 +176,17 @@ export const encodeSchema = (contract) => {
|
|
|
172
176
|
* @remarks
|
|
173
177
|
* Uses `Schema.toCodecJson` to obtain the schema's canonical JSON codec. Encoding failures occur
|
|
174
178
|
* before dispatch; an operation wraps response decoding failures in `Response.DecodeError`.
|
|
179
|
+
*
|
|
180
|
+
* Encoding takes either side of the schema, or a mix by field, as `Request.Input` describes, and
|
|
181
|
+
* writes the canonical JSON. The encoded side is the schema's own, so a `Schema.Date` field takes a
|
|
182
|
+
* `Date`, not the ISO text JSON carries. Decoding returns the schema's application type, so a class
|
|
183
|
+
* comes back as an instance.
|
|
175
184
|
*/
|
|
176
185
|
export const jsonSchema = (contract) => {
|
|
177
186
|
const codec = Schema.toCodecJson(contract);
|
|
187
|
+
const encode = Inputs.encoder(contract, Schema.encodeEffect(codec));
|
|
178
188
|
return make({
|
|
179
|
-
encode:
|
|
189
|
+
encode: (value) => Effect.flatMap(encode(value), json.encode),
|
|
180
190
|
decode: json.pipe(schema(codec)).decode,
|
|
181
191
|
mediaType: json.mediaType,
|
|
182
192
|
});
|
package/dist/http/Body.js.map
CHANGED
|
@@ -1 +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;
|
|
1
|
+
{"version":3,"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