viell-effect-schema-http 0.1.0 → 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.
- package/README.md +43 -29
- package/dist/http/Body.d.ts +23 -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 +270 -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 +3 -2
- package/dist/http/Policy.d.ts.map +1 -1
- package/dist/http/Policy.js +3 -2
- package/dist/http/Policy.js.map +1 -1
- package/dist/http/Request.d.ts +477 -85
- package/dist/http/Request.d.ts.map +1 -1
- package/dist/http/Request.js +621 -141
- package/dist/http/Request.js.map +1 -1
- package/dist/http/Response.d.ts +119 -5
- 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 +23 -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/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 +39 -0
- package/dist/http/internal/input.d.ts.map +1 -0
- package/dist/http/internal/input.js +40 -0
- package/dist/http/internal/input.js.map +1 -0
- package/dist/http/internal/shape.d.ts +44 -0
- package/dist/http/internal/shape.d.ts.map +1 -0
- package/dist/http/internal/shape.js +179 -0
- package/dist/http/internal/shape.js.map +1 -0
- package/package.json +12 -12
- package/src/http/Body.ts +39 -18
- package/src/http/Operation.ts +468 -33
- package/src/http/Policy.ts +3 -2
- package/src/http/Request.ts +1075 -251
- package/src/http/Response.ts +235 -22
- package/src/http/UrlEncoding.ts +31 -8
- package/src/http/internal/fields.ts +37 -9
- package/src/http/internal/input.ts +123 -0
- package/src/http/internal/shape.ts +279 -0
package/dist/http/Operation.d.ts
CHANGED
|
@@ -9,18 +9,59 @@ import * as Response from "./Response.js";
|
|
|
9
9
|
* @remarks
|
|
10
10
|
* `execute(input)` returns a cold Effect: work starts when it is evaluated, and each evaluation
|
|
11
11
|
* runs again. `Operation.make` supplies HTTP execution; `fromEffect` adapts an existing function.
|
|
12
|
-
* With `make`, the request bindings determine `I`.
|
|
13
|
-
*
|
|
12
|
+
* With `make`, the request bindings determine `I`. {@link InputOf} extracts it.
|
|
13
|
+
*
|
|
14
|
+
* `make` also keeps what it was built from in `parts`, which `P` describes, so {@link mapRequest},
|
|
15
|
+
* {@link mapResponse} and {@link mapOptions} can derive a variant. Annotating a value as
|
|
16
|
+
* `Operation<I, A, E, R>` leaves `P` unknown, which stops those functions compiling on it.
|
|
14
17
|
*/
|
|
15
|
-
export interface Operation<in I, out A, out E = never, out R = never> extends Pipeable.Pipeable {
|
|
18
|
+
export interface Operation<in I, out A, out E = never, out R = never, out P = unknown> extends Pipeable.Pipeable {
|
|
16
19
|
readonly execute: (input: I) => Effect.Effect<A, E, R>;
|
|
20
|
+
/** What the operation was built from. A value from {@link fromEffect} has no parts. */
|
|
21
|
+
readonly parts?: P;
|
|
17
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* The input an operation's `execute` takes.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```ts
|
|
28
|
+
* import { Schema } from "effect";
|
|
29
|
+
* import { Body, Operation, Request, Response } from "viell-effect-schema-http";
|
|
30
|
+
* const search = Operation.make(
|
|
31
|
+
* Request.get("https://api.example.test/things").pipe(
|
|
32
|
+
* Request.query(Schema.Struct({ sort: Schema.String })),
|
|
33
|
+
* ),
|
|
34
|
+
* Response.status(200, Body.json),
|
|
35
|
+
* );
|
|
36
|
+
* type SearchInput = Operation.InputOf<typeof search>;
|
|
37
|
+
* const searchAll = (input: SearchInput) => search.execute(input);
|
|
38
|
+
* ```
|
|
39
|
+
*
|
|
40
|
+
* @remarks
|
|
41
|
+
* `Request.InputOf` gives the same for a request.
|
|
42
|
+
*/
|
|
43
|
+
export type InputOf<O> = O extends Operation<infer I, unknown, unknown, unknown, unknown> ? I : never;
|
|
18
44
|
/**
|
|
19
45
|
* Adapt an Effect-returning function to the operation interface.
|
|
20
46
|
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```ts
|
|
49
|
+
* import { Body, Operation, Request, Response } from "viell-effect-schema-http";
|
|
50
|
+
* const health = Operation.make(
|
|
51
|
+
* Request.get("https://api.example.test/health"),
|
|
52
|
+
* Response.status(200, Body.text),
|
|
53
|
+
* );
|
|
54
|
+
* // Callers can run this and map its result, and cannot adjust what it sends.
|
|
55
|
+
* const sealed = Operation.fromEffect(health.execute);
|
|
56
|
+
* ```
|
|
57
|
+
*
|
|
21
58
|
* @remarks
|
|
22
59
|
* The function is suspended until evaluation. This adapter adds no HTTP dispatch, decoding,
|
|
23
60
|
* retry policy or scope management beyond what the supplied function already does.
|
|
61
|
+
*
|
|
62
|
+
* The result has no parts, at compile time or at run time. So
|
|
63
|
+
* `Operation.fromEffect(operation.execute)` seals a definition: it keeps the same types and offers
|
|
64
|
+
* no adjustment.
|
|
24
65
|
*/
|
|
25
66
|
export declare const fromEffect: <I, A, E, R>(execute: (input: I) => Effect.Effect<A, E, R>) => Operation<I, A, E, R>;
|
|
26
67
|
/**
|
|
@@ -36,10 +77,12 @@ export interface Options<E = HttpClientError.HttpClientError, R = never, EP = ne
|
|
|
36
77
|
* Applied after request preparation, suitable for fresh credentials or URL-dependent signatures.
|
|
37
78
|
* Run a signer after other request edits it must cover. Native status filters can reject responses
|
|
38
79
|
* before the declared response contract sees them.
|
|
80
|
+
* `attempt` starts at `1` and matches the `http.attempt` log annotation. A function with an optional
|
|
81
|
+
* second parameter of its own receives the number there, so wrap one in an arrow function.
|
|
39
82
|
* Appending native URL parameters can reserialize the entire query as form data, changing bare keys and
|
|
40
83
|
* escapes. Prefer Request query combinators, or preserve the query text when editing the URL directly.
|
|
41
84
|
*/
|
|
42
|
-
readonly transformClient?: ((client: HttpClient.HttpClient) => HttpClient.HttpClient.With<E, R>) | undefined;
|
|
85
|
+
readonly transformClient?: ((client: HttpClient.HttpClient, attempt: number) => HttpClient.HttpClient.With<E, R>) | undefined;
|
|
43
86
|
}
|
|
44
87
|
/**
|
|
45
88
|
* Combine a request and response contract into an executable HTTP operation.
|
|
@@ -64,9 +107,13 @@ export interface Options<E = HttpClientError.HttpClientError, R = never, EP = ne
|
|
|
64
107
|
* Each evaluation prepares input once. Each attempt then owns a scope covering client execution
|
|
65
108
|
* and body decoding; cleanup completes before classification or a retry delay. Decoder and
|
|
66
109
|
* client `Scope` requirements are supplied by the attempt. Interruption and defects never retry.
|
|
67
|
-
* An automatic `Accept` header is added only when the request has
|
|
110
|
+
* An automatic `Accept` header is added only when the request declares none and has not removed
|
|
111
|
+
* it with `Request.removeHeader`.
|
|
112
|
+
*
|
|
113
|
+
* The result keeps its parts, so a definition written once can be adjusted where it is used with
|
|
114
|
+
* {@link mapRequest}, {@link mapResponse} and {@link mapOptions}. The original never changes.
|
|
68
115
|
*/
|
|
69
|
-
export declare const make: <I, E, R,
|
|
116
|
+
export declare const make: <I, E, R, A, E2, R2, E3 = HttpClientError.HttpClientError, R3 = never, EP = never, RP = never, C extends Response.AnyCase = Response.AnyCase>(request: Request.Request<I, E, R>, response: Response.Response<A, E2, R2, C>, options?: Options<E3, R3, EP, RP>) => Http<Request.Request<I, E, R>, Response.Response<A, E2, R2, C>, Options<E3, R3, EP, RP>>;
|
|
70
117
|
/**
|
|
71
118
|
* Return the Effect for an operation's input, in direct or pipeable form.
|
|
72
119
|
*
|
|
@@ -77,21 +124,231 @@ export declare const execute: {
|
|
|
77
124
|
<I>(input: I): <A, E, R>(self: Operation<I, A, E, R>) => Effect.Effect<A, E, R>;
|
|
78
125
|
<I, A, E, R>(self: Operation<I, A, E, R>, input: I): Effect.Effect<A, E, R>;
|
|
79
126
|
};
|
|
127
|
+
/**
|
|
128
|
+
* The conversion {@link map} and {@link mapEffect} recorded, run once after the parts.
|
|
129
|
+
*
|
|
130
|
+
* @remarks
|
|
131
|
+
* Only its failures and services are in the type. Its result is the operation's own `A`, and what
|
|
132
|
+
* it was written for is what the response still produces, so neither is repeated here.
|
|
133
|
+
*/
|
|
134
|
+
export interface Step<out E = never, out R = never> {
|
|
135
|
+
readonly run: (value: never) => Effect.Effect<unknown, E, R>;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* What {@link make} keeps: the three parts as given, and any recorded {@link Step}.
|
|
139
|
+
*
|
|
140
|
+
* @remarks
|
|
141
|
+
* Read a part with `operation.parts?.request`. Each whole part is one type parameter, which keeps
|
|
142
|
+
* the parameter count down as `Schema.decodeTo` does.
|
|
143
|
+
*
|
|
144
|
+
* `S` is invariant: widening it by annotation could otherwise make any response look as if it fits
|
|
145
|
+
* a recorded step.
|
|
146
|
+
*
|
|
147
|
+
* {@link mapRequest}, {@link mapResponse}, {@link mapOptions} and {@link unmap} build from these,
|
|
148
|
+
* so they drop an `execute` replaced on the value. {@link map} and {@link mapEffect} wrap
|
|
149
|
+
* `execute` itself, and keep it.
|
|
150
|
+
*/
|
|
151
|
+
export interface Parts<out Q, in out S, out O, out T = undefined> {
|
|
152
|
+
readonly request: Q;
|
|
153
|
+
readonly response: S;
|
|
154
|
+
readonly options: O | undefined;
|
|
155
|
+
readonly step: T;
|
|
156
|
+
}
|
|
157
|
+
type RequestFailure<Q> = Q extends Request.Request<never, infer E, unknown> ? E : never;
|
|
158
|
+
type RequestServices<Q> = Q extends Request.Request<never, unknown, infer R> ? R : never;
|
|
159
|
+
type ValueOf<S> = S extends Response.Response<infer A, unknown, unknown, infer _C> ? A : never;
|
|
160
|
+
type ResponseFailure<S> = S extends Response.Response<unknown, infer E, unknown, infer _C> ? E : never;
|
|
161
|
+
type ResponseServices<S> = S extends Response.Response<unknown, unknown, infer R, infer _C> ? R : never;
|
|
162
|
+
type ClientFailure<O> = O extends Options<infer E, infer _R, infer _EP, infer _RP> ? E : never;
|
|
163
|
+
type ClientServices<O> = O extends Options<infer _E, infer R, infer _EP, infer _RP> ? R : never;
|
|
164
|
+
type PolicyFailure<O> = O extends Options<infer _E, infer _R, infer E, infer _RP> ? E : never;
|
|
165
|
+
type PolicyServices<O> = O extends Options<infer _E, infer _R, infer _EP, infer R> ? R : never;
|
|
166
|
+
type StepFailure<T> = T extends Step<infer E, unknown> ? E : never;
|
|
167
|
+
type StepServices<T> = T extends Step<unknown, infer R> ? R : never;
|
|
168
|
+
/** An operation fresh from {@link make}: three parts, no step, and the response's own result. */
|
|
169
|
+
export type Http<Q, S, O> = Derived<ValueOf<S>, Q, S, O>;
|
|
170
|
+
/**
|
|
171
|
+
* An operation built from parts, returning `B`.
|
|
172
|
+
*
|
|
173
|
+
* @remarks
|
|
174
|
+
* `B` comes first so that an editor hover shows the result before the parts. The unions stay
|
|
175
|
+
* inline: a named alias would print with all of `Q`, `S` and `O` repeated inside it.
|
|
176
|
+
*/
|
|
177
|
+
export type Derived<B, Q, S, O, T = undefined> = Operation<Request.InputOf<Q>, B, RequestFailure<Q> | ClientFailure<O> | PolicyFailure<O> | StepFailure<T> | Request.InvalidRequest | HttpClientError.HttpClientError | Response.UnexpectedResponse | Response.DecodeError<ResponseFailure<S> | HttpClientError.HttpClientError> | Cause.TimeoutError, RequestServices<Q> | PolicyServices<O> | StepServices<T> | Exclude<ResponseServices<S> | ClientServices<O>, Scope.Scope> | HttpClient.HttpClient, Parts<Q, S, O, T>>;
|
|
178
|
+
/**
|
|
179
|
+
* Any operation carrying the parts `P` and returning `B`.
|
|
180
|
+
*
|
|
181
|
+
* @remarks
|
|
182
|
+
* What {@link mapRequest}, {@link mapResponse}, {@link mapOptions} and {@link unmap} accept. The
|
|
183
|
+
* input, failures and services are left open because a variant works them out again from `P`.
|
|
184
|
+
*/
|
|
185
|
+
export type Adjustable<B, P> = Operation<never, B, unknown, unknown, P>;
|
|
186
|
+
/**
|
|
187
|
+
* Derive a variant with a changed request. A recorded result step stays.
|
|
188
|
+
*
|
|
189
|
+
* @example
|
|
190
|
+
* ```ts
|
|
191
|
+
* import { Body, Operation, Request, Response } from "viell-effect-schema-http";
|
|
192
|
+
* const getThings = Operation.make(
|
|
193
|
+
* Request.get("https://api.example.test/things?limit=25"),
|
|
194
|
+
* Response.status(200, Body.json),
|
|
195
|
+
* );
|
|
196
|
+
* const firstFive = Request.setQuery("limit", "5");
|
|
197
|
+
* const fewerThings = getThings.pipe(Operation.mapRequest(firstFive));
|
|
198
|
+
* // getThings still asks for 25.
|
|
199
|
+
* ```
|
|
200
|
+
*
|
|
201
|
+
* @remarks
|
|
202
|
+
* The function receives the current request, so every `Request` function works here, including a
|
|
203
|
+
* binding that changes the operation's input. The automatic `Accept` and the options carry over.
|
|
204
|
+
* The library cannot tell whether a change alters the shape of the answer: selecting fields or
|
|
205
|
+
* embedding relations usually does, and then needs {@link mapResponse} too.
|
|
206
|
+
*
|
|
207
|
+
* Works on any operation from {@link make}, mapped or not. A value from {@link fromEffect} has no
|
|
208
|
+
* parts, and one annotated as a plain `Operation<I, A, E, R>` hides them: both are compile errors.
|
|
209
|
+
*/
|
|
210
|
+
export declare const mapRequest: <I, E, R, I2, E2, R2>(f: (request: Request.Request<I, E, R>) => Request.Request<I2, E2, R2>) => <B, S, O, T>(self: Adjustable<B, Parts<Request.Request<I, E, R>, S, O, T>>) => Derived<B, Request.Request<I2, E2, R2>, S, O, T>;
|
|
211
|
+
interface NoLongerFits<A> {
|
|
212
|
+
readonly "Use Operation.unmap first, then map again: this response no longer fits the mapping.": A;
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* The rule {@link mapResponse} applies to a new result `A2`, given the current result `A`.
|
|
216
|
+
*
|
|
217
|
+
* @remarks
|
|
218
|
+
* With no step, `T` is `undefined` and anything fits. With a step, `A2` must be something the
|
|
219
|
+
* current response could produce. An `any` result proves nothing, so it does not fit either.
|
|
220
|
+
*
|
|
221
|
+
* `W` is everything the function returned, and stays `never` when nothing was inferred from it.
|
|
222
|
+
* That means the function itself does not compile, as with a key the contract lacks. `A2` then
|
|
223
|
+
* reads `unknown` for no reason of its own, so the rule stands aside and leaves the function's own
|
|
224
|
+
* error as the only one. A function that returns a response, or `any`, always gives `W` a value, so
|
|
225
|
+
* a result that really is `unknown` is still refused.
|
|
226
|
+
*/
|
|
227
|
+
export type Fits<A2, A, T, W = unknown> = [T] extends [undefined] ? unknown : [W] extends [never] ? unknown : 0 extends 1 & A2 ? NoLongerFits<A2> : [A2] extends [A] ? unknown : NoLongerFits<A2>;
|
|
228
|
+
/**
|
|
229
|
+
* Derive a variant with a changed response. A recorded result step stays, and has to fit.
|
|
230
|
+
*
|
|
231
|
+
* @example
|
|
232
|
+
* ```ts
|
|
233
|
+
* import { Schema } from "effect";
|
|
234
|
+
* import { Body, Operation, Request, Response } from "viell-effect-schema-http";
|
|
235
|
+
* const Thing = Schema.Struct({ id: Schema.Number, name: Schema.String });
|
|
236
|
+
* const ThingOption = Schema.Struct({ id: Schema.Number });
|
|
237
|
+
* const getThing = Operation.make(
|
|
238
|
+
* Request.get("https://api.example.test/things/1"),
|
|
239
|
+
* Response.status(200, Body.jsonSchema(Thing)),
|
|
240
|
+
* );
|
|
241
|
+
* const asOption = Response.replace(200, Body.jsonSchema(ThingOption));
|
|
242
|
+
* const thingOption = getThing.pipe(Operation.mapResponse(asOption));
|
|
243
|
+
* ```
|
|
244
|
+
*
|
|
245
|
+
* @remarks
|
|
246
|
+
* The function receives the current response, so {@link Response.replace},
|
|
247
|
+
* {@link Response.remove} and {@link Response.orElse} all work here. The automatic `Accept` follows
|
|
248
|
+
* the new response.
|
|
249
|
+
*
|
|
250
|
+
* On a mapped operation the new result must fit: it has to be assignable to the current response's
|
|
251
|
+
* result, and not `any`, because the recorded step was written for that result. So a same-shape
|
|
252
|
+
* replace or a removal works, and anything else is a compile error that names {@link unmap}.
|
|
253
|
+
* A narrowed result is the new baseline, so widening it back needs {@link unmap} as well.
|
|
254
|
+
* This is a compile-time rule: a cast gets past it, and the step then receives the wrong shape.
|
|
255
|
+
*/
|
|
256
|
+
export declare const mapResponse: <A, E, R, C extends Response.AnyCase, A2, E2, R2, C2 extends Response.AnyCase, W = never>(f: (response: Response.Response<A, E, R, C>) => Response.Response<A2, E2, R2, C2> & W) => <B, Q, O, T>(self: Adjustable<B, Parts<Q, Response.Response<A, E, R, C>, O, T>> & Fits<A2, A, T, W>) => Derived<[T] extends [undefined] ? A2 : B, Q, Response.Response<A2, E2, R2, C2>, O, T>;
|
|
257
|
+
/**
|
|
258
|
+
* Derive a variant with changed options. A recorded result step stays.
|
|
259
|
+
*
|
|
260
|
+
* @example
|
|
261
|
+
* ```ts
|
|
262
|
+
* import { Schedule } from "effect";
|
|
263
|
+
* import {
|
|
264
|
+
* Body,
|
|
265
|
+
* Operation,
|
|
266
|
+
* Policy,
|
|
267
|
+
* Request,
|
|
268
|
+
* Response,
|
|
269
|
+
* } from "viell-effect-schema-http";
|
|
270
|
+
* const getThings = Operation.make(
|
|
271
|
+
* Request.get("https://api.example.test/things"),
|
|
272
|
+
* Response.status(200, Body.json),
|
|
273
|
+
* );
|
|
274
|
+
* const retryTwice = Policy.make(Schedule.recurs(2));
|
|
275
|
+
* const patient = getThings.pipe(
|
|
276
|
+
* Operation.mapOptions((options) => ({ ...options, policy: retryTwice })),
|
|
277
|
+
* );
|
|
278
|
+
* ```
|
|
279
|
+
*
|
|
280
|
+
* @remarks
|
|
281
|
+
* The function receives the current options, or `undefined` if there are none, and its result
|
|
282
|
+
* replaces them. Spread them to keep what you do not change. A failure or service type that only
|
|
283
|
+
* a dropped option added leaves with it.
|
|
284
|
+
*/
|
|
285
|
+
export declare const mapOptions: <O, E = HttpClientError.HttpClientError, R = never, EP = never, RP = never>(f: (options: O | undefined) => Options<E, R, EP, RP>) => <B, Q, S, T>(self: Adjustable<B, Parts<Q, S, O, T>>) => Derived<B, Q, S, Options<E, R, EP, RP>, T>;
|
|
286
|
+
/**
|
|
287
|
+
* Remove every recorded result step, so the operation returns what its response decodes.
|
|
288
|
+
*
|
|
289
|
+
* @example
|
|
290
|
+
* ```ts
|
|
291
|
+
* import { Schema } from "effect";
|
|
292
|
+
* import { Body, Operation, Request, Response } from "viell-effect-schema-http";
|
|
293
|
+
* const Page = Schema.Struct({ data: Schema.Array(Schema.String) });
|
|
294
|
+
* const Names = Schema.Struct({ data: Schema.Array(Schema.Number) });
|
|
295
|
+
* const getThings = Operation.make(
|
|
296
|
+
* Request.get("https://api.example.test/things"),
|
|
297
|
+
* Response.status(200, Body.jsonSchema(Page)),
|
|
298
|
+
* ).pipe(Operation.map((page) => page.data));
|
|
299
|
+
*
|
|
300
|
+
* const asIds = Response.replace(200, Body.jsonSchema(Names));
|
|
301
|
+
* const thingIds = getThings.pipe(
|
|
302
|
+
* Operation.unmap,
|
|
303
|
+
* Operation.mapResponse(asIds),
|
|
304
|
+
* Operation.map((page) => page.data),
|
|
305
|
+
* );
|
|
306
|
+
* ```
|
|
307
|
+
*
|
|
308
|
+
* @remarks
|
|
309
|
+
* This is the route to a response {@link mapResponse} refuses: remove the mapping, change the
|
|
310
|
+
* response, then map again. The failures and services the steps added leave with them. On an
|
|
311
|
+
* operation with no step this changes nothing.
|
|
312
|
+
*/
|
|
313
|
+
export declare const unmap: <B, Q, S, O, T>(self: Adjustable<B, Parts<Q, S, O, T>>) => Http<Q, S, O>;
|
|
314
|
+
/**
|
|
315
|
+
* The parts after {@link map} or {@link mapEffect} records a step adding failures `E` and services
|
|
316
|
+
* `R`. An operation with no parts stays that way.
|
|
317
|
+
*
|
|
318
|
+
* @remarks
|
|
319
|
+
* The conditional lives here, in the fifth argument, because a conditional return type would stop
|
|
320
|
+
* `flow` composing these functions.
|
|
321
|
+
*/
|
|
322
|
+
export type Next<P, E, R> = [P] extends [
|
|
323
|
+
Parts<infer Q, infer S, infer O, infer T>
|
|
324
|
+
] ? Parts<Q, S, O, Step<StepFailure<T> | E, StepServices<T> | R>> : P;
|
|
80
325
|
/**
|
|
81
326
|
* Transform an operation's successful result with a pure function.
|
|
82
327
|
*
|
|
83
328
|
* @remarks
|
|
84
|
-
* Keeps the input, error and service types. Runs after the operation and its retry policy
|
|
85
|
-
* Use {@link mapEffect} to return a typed failure
|
|
329
|
+
* Keeps the input, error and service types. Runs once, after the operation and its retry policy
|
|
330
|
+
* finish, outside each attempt's scope and timeout. Use {@link mapEffect} to return a typed failure
|
|
331
|
+
* or perform further effectful work.
|
|
332
|
+
*
|
|
333
|
+
* The operation keeps its parts and records this as a step, so {@link mapRequest} and
|
|
334
|
+
* {@link mapOptions} still work on the result, and {@link mapResponse} works while the new result
|
|
335
|
+
* fits. Two maps combine into one step. The mapping applies to the whole result, whichever case
|
|
336
|
+
* produced it. For a conversion that belongs to one case, use `Body.map` on that case's decoder: a
|
|
337
|
+
* later `Response.replace` takes the conversion with the case.
|
|
86
338
|
*/
|
|
87
|
-
export declare const map: <A, B>(f: (value: A) => B) => <I, E, R>(self: Operation<I, A, E, R>) => Operation<I, B, E, R
|
|
339
|
+
export declare const map: <A, B>(f: (value: A) => B) => <I, E, R, P = unknown>(self: Operation<I, A, E, R, P>) => Operation<I, B, E, R, Next<P, never, never>>;
|
|
88
340
|
/**
|
|
89
341
|
* Transform an operation's successful result with an Effect.
|
|
90
342
|
*
|
|
91
343
|
* @remarks
|
|
92
|
-
* Adds the transformation's errors and required services. Runs after the operation's retry
|
|
93
|
-
* policy completes, so failures here do not trigger that
|
|
94
|
-
* response outcome into an application
|
|
344
|
+
* Adds the transformation's errors and required services. Runs once, after the operation's retry
|
|
345
|
+
* policy completes, outside each attempt's scope and timeout, so failures here do not trigger that
|
|
346
|
+
* policy and arrive as themselves. Use it to turn a recognized response outcome into an application
|
|
347
|
+
* error.
|
|
348
|
+
*
|
|
349
|
+
* The operation keeps its parts and records this as a step, as {@link map} describes. Its failures
|
|
350
|
+
* and services stay through a variant and leave with {@link unmap}.
|
|
95
351
|
*/
|
|
96
|
-
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
|
|
352
|
+
export declare const mapEffect: <A, B, E2, R2>(f: (value: A) => Effect.Effect<B, E2, R2>) => <I, E, R, P = unknown>(self: Operation<I, A, E, R, P>) => Operation<I, B, E | E2, R | R2, Next<P, E2, R2>>;
|
|
353
|
+
export {};
|
|
97
354
|
//# sourceMappingURL=Operation.d.ts.map
|
|
@@ -1 +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
|
|
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;;;;;;;;;;;GAWG;AACH,MAAM,WAAW,SAAS,CACxB,EAAE,CAAC,CAAC,EACJ,GAAG,CAAC,CAAC,EACL,GAAG,CAAC,CAAC,GAAG,KAAK,EACb,GAA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AAC,EAAE,CAAC,GAAG,OAAO,EACnB,MAAM,SAAS,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,KAC7B,SAAS,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,EAAE,EAAE,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,EAAE,CAAC,CACT,CAAC"}
|
package/dist/http/Operation.js
CHANGED
|
@@ -7,9 +7,24 @@ import * as Transport from "./Transport.js";
|
|
|
7
7
|
/**
|
|
8
8
|
* Adapt an Effect-returning function to the operation interface.
|
|
9
9
|
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* import { Body, Operation, Request, Response } from "viell-effect-schema-http";
|
|
13
|
+
* const health = Operation.make(
|
|
14
|
+
* Request.get("https://api.example.test/health"),
|
|
15
|
+
* Response.status(200, Body.text),
|
|
16
|
+
* );
|
|
17
|
+
* // Callers can run this and map its result, and cannot adjust what it sends.
|
|
18
|
+
* const sealed = Operation.fromEffect(health.execute);
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
10
21
|
* @remarks
|
|
11
22
|
* The function is suspended until evaluation. This adapter adds no HTTP dispatch, decoding,
|
|
12
23
|
* retry policy or scope management beyond what the supplied function already does.
|
|
24
|
+
*
|
|
25
|
+
* The result has no parts, at compile time or at run time. So
|
|
26
|
+
* `Operation.fromEffect(operation.execute)` seals a definition: it keeps the same types and offers
|
|
27
|
+
* no adjustment.
|
|
13
28
|
*/
|
|
14
29
|
export const fromEffect = (execute) => ({
|
|
15
30
|
...Pipeable.Prototype,
|
|
@@ -46,14 +61,20 @@ const outcome = (exit) => Exit.isSuccess(exit)
|
|
|
46
61
|
* Each evaluation prepares input once. Each attempt then owns a scope covering client execution
|
|
47
62
|
* and body decoding; cleanup completes before classification or a retry delay. Decoder and
|
|
48
63
|
* client `Scope` requirements are supplied by the attempt. Interruption and defects never retry.
|
|
49
|
-
* An automatic `Accept` header is added only when the request has
|
|
64
|
+
* An automatic `Accept` header is added only when the request declares none and has not removed
|
|
65
|
+
* it with `Request.removeHeader`.
|
|
66
|
+
*
|
|
67
|
+
* The result keeps its parts, so a definition written once can be adjusted where it is used with
|
|
68
|
+
* {@link mapRequest}, {@link mapResponse} and {@link mapOptions}. The original never changes.
|
|
50
69
|
*/
|
|
51
70
|
export const make = (request, response, options) => {
|
|
52
71
|
const policy = options?.policy ?? Policy.none;
|
|
53
72
|
const accept = response.accepts.join(", ");
|
|
54
73
|
const execute = Effect.fnUntraced(function* (input) {
|
|
55
74
|
const compiled = yield* Request.compile(request, input);
|
|
56
|
-
const prepared = accept !== "" &&
|
|
75
|
+
const prepared = accept !== "" &&
|
|
76
|
+
compiled.request.headers.accept === undefined &&
|
|
77
|
+
!compiled.removedHeaders.has("accept")
|
|
57
78
|
? HttpClientRequest.setHeader(compiled.request, "accept", accept)
|
|
58
79
|
: compiled.request;
|
|
59
80
|
const client = yield* HttpClient.HttpClient;
|
|
@@ -70,7 +91,8 @@ export const make = (request, response, options) => {
|
|
|
70
91
|
const execution = Effect.scoped(Effect.gen(function* () {
|
|
71
92
|
const send = options?.transformClient === undefined
|
|
72
93
|
? HttpClient.withScope(client).execute
|
|
73
|
-
: HttpClient.withScope(options.transformClient(client))
|
|
94
|
+
: HttpClient.withScope(options.transformClient(client, attempt))
|
|
95
|
+
.execute;
|
|
74
96
|
// A fresh request identity keeps the scoped abort controller of this attempt separate.
|
|
75
97
|
const received = yield* send(HttpClientRequest.setHeaders(prepared, {})).pipe(Effect.provideService(Transport.HeaderLines, compiled.headerLines),
|
|
76
98
|
// Client middleware can reject a response, such as filterStatusOk; its metadata still classifies the attempt.
|
|
@@ -117,7 +139,11 @@ export const make = (request, response, options) => {
|
|
|
117
139
|
yield* Effect.logDebug("HTTP retrying").pipe(Effect.annotateLogs({ "http.attempt": attempt + 1 }));
|
|
118
140
|
}
|
|
119
141
|
}, Effect.onExit((exit) => Effect.logDebug("HTTP operation completed").pipe(Effect.annotateLogs({ "http.outcome": outcome(exit) }))), Effect.withLogSpan("schema-http.operation"));
|
|
120
|
-
return {
|
|
142
|
+
return {
|
|
143
|
+
...Pipeable.Prototype,
|
|
144
|
+
execute,
|
|
145
|
+
parts: { request, response, options, step: undefined },
|
|
146
|
+
};
|
|
121
147
|
};
|
|
122
148
|
/**
|
|
123
149
|
* Return the Effect for an operation's input, in direct or pipeable form.
|
|
@@ -126,21 +152,194 @@ export const make = (request, response, options) => {
|
|
|
126
152
|
* Equivalent to `operation.execute(input)`. It does not itself evaluate the Effect.
|
|
127
153
|
*/
|
|
128
154
|
export const execute = Function.dual(2, (self, input) => self.execute(input));
|
|
155
|
+
/** The types refuse an operation with no parts; a cast or plain JavaScript gets a clear failure. */
|
|
156
|
+
const partsOf = (self) => {
|
|
157
|
+
if (self.parts === undefined)
|
|
158
|
+
throw new Error("This operation has no parts to adjust: it came from Operation.fromEffect");
|
|
159
|
+
return self.parts;
|
|
160
|
+
};
|
|
161
|
+
/** Rebuild through {@link make}, so the automatic `Accept` follows the response. */
|
|
162
|
+
const rebuild = (parts) => {
|
|
163
|
+
const { request, response, options, step } = parts;
|
|
164
|
+
const built = make(request, response, options);
|
|
165
|
+
const result = step === undefined
|
|
166
|
+
? built
|
|
167
|
+
: {
|
|
168
|
+
...built,
|
|
169
|
+
execute: (input) => Effect.flatMap(built.execute(input), step.run),
|
|
170
|
+
parts: { request, response, options, step },
|
|
171
|
+
};
|
|
172
|
+
return result;
|
|
173
|
+
};
|
|
174
|
+
/**
|
|
175
|
+
* Derive a variant with a changed request. A recorded result step stays.
|
|
176
|
+
*
|
|
177
|
+
* @example
|
|
178
|
+
* ```ts
|
|
179
|
+
* import { Body, Operation, Request, Response } from "viell-effect-schema-http";
|
|
180
|
+
* const getThings = Operation.make(
|
|
181
|
+
* Request.get("https://api.example.test/things?limit=25"),
|
|
182
|
+
* Response.status(200, Body.json),
|
|
183
|
+
* );
|
|
184
|
+
* const firstFive = Request.setQuery("limit", "5");
|
|
185
|
+
* const fewerThings = getThings.pipe(Operation.mapRequest(firstFive));
|
|
186
|
+
* // getThings still asks for 25.
|
|
187
|
+
* ```
|
|
188
|
+
*
|
|
189
|
+
* @remarks
|
|
190
|
+
* The function receives the current request, so every `Request` function works here, including a
|
|
191
|
+
* binding that changes the operation's input. The automatic `Accept` and the options carry over.
|
|
192
|
+
* The library cannot tell whether a change alters the shape of the answer: selecting fields or
|
|
193
|
+
* embedding relations usually does, and then needs {@link mapResponse} too.
|
|
194
|
+
*
|
|
195
|
+
* Works on any operation from {@link make}, mapped or not. A value from {@link fromEffect} has no
|
|
196
|
+
* parts, and one annotated as a plain `Operation<I, A, E, R>` hides them: both are compile errors.
|
|
197
|
+
*/
|
|
198
|
+
export const mapRequest = (f) => (self) => {
|
|
199
|
+
const parts = partsOf(self);
|
|
200
|
+
return rebuild({ ...parts, request: f(parts.request) });
|
|
201
|
+
};
|
|
202
|
+
/**
|
|
203
|
+
* Derive a variant with a changed response. A recorded result step stays, and has to fit.
|
|
204
|
+
*
|
|
205
|
+
* @example
|
|
206
|
+
* ```ts
|
|
207
|
+
* import { Schema } from "effect";
|
|
208
|
+
* import { Body, Operation, Request, Response } from "viell-effect-schema-http";
|
|
209
|
+
* const Thing = Schema.Struct({ id: Schema.Number, name: Schema.String });
|
|
210
|
+
* const ThingOption = Schema.Struct({ id: Schema.Number });
|
|
211
|
+
* const getThing = Operation.make(
|
|
212
|
+
* Request.get("https://api.example.test/things/1"),
|
|
213
|
+
* Response.status(200, Body.jsonSchema(Thing)),
|
|
214
|
+
* );
|
|
215
|
+
* const asOption = Response.replace(200, Body.jsonSchema(ThingOption));
|
|
216
|
+
* const thingOption = getThing.pipe(Operation.mapResponse(asOption));
|
|
217
|
+
* ```
|
|
218
|
+
*
|
|
219
|
+
* @remarks
|
|
220
|
+
* The function receives the current response, so {@link Response.replace},
|
|
221
|
+
* {@link Response.remove} and {@link Response.orElse} all work here. The automatic `Accept` follows
|
|
222
|
+
* the new response.
|
|
223
|
+
*
|
|
224
|
+
* On a mapped operation the new result must fit: it has to be assignable to the current response's
|
|
225
|
+
* result, and not `any`, because the recorded step was written for that result. So a same-shape
|
|
226
|
+
* replace or a removal works, and anything else is a compile error that names {@link unmap}.
|
|
227
|
+
* A narrowed result is the new baseline, so widening it back needs {@link unmap} as well.
|
|
228
|
+
* This is a compile-time rule: a cast gets past it, and the step then receives the wrong shape.
|
|
229
|
+
*/
|
|
230
|
+
export const mapResponse = (f) => (self) => {
|
|
231
|
+
const parts = partsOf(self);
|
|
232
|
+
return rebuild({ ...parts, response: f(parts.response) });
|
|
233
|
+
};
|
|
234
|
+
/**
|
|
235
|
+
* Derive a variant with changed options. A recorded result step stays.
|
|
236
|
+
*
|
|
237
|
+
* @example
|
|
238
|
+
* ```ts
|
|
239
|
+
* import { Schedule } from "effect";
|
|
240
|
+
* import {
|
|
241
|
+
* Body,
|
|
242
|
+
* Operation,
|
|
243
|
+
* Policy,
|
|
244
|
+
* Request,
|
|
245
|
+
* Response,
|
|
246
|
+
* } from "viell-effect-schema-http";
|
|
247
|
+
* const getThings = Operation.make(
|
|
248
|
+
* Request.get("https://api.example.test/things"),
|
|
249
|
+
* Response.status(200, Body.json),
|
|
250
|
+
* );
|
|
251
|
+
* const retryTwice = Policy.make(Schedule.recurs(2));
|
|
252
|
+
* const patient = getThings.pipe(
|
|
253
|
+
* Operation.mapOptions((options) => ({ ...options, policy: retryTwice })),
|
|
254
|
+
* );
|
|
255
|
+
* ```
|
|
256
|
+
*
|
|
257
|
+
* @remarks
|
|
258
|
+
* The function receives the current options, or `undefined` if there are none, and its result
|
|
259
|
+
* replaces them. Spread them to keep what you do not change. A failure or service type that only
|
|
260
|
+
* a dropped option added leaves with it.
|
|
261
|
+
*/
|
|
262
|
+
export const mapOptions = (f) => (self) => {
|
|
263
|
+
const parts = partsOf(self);
|
|
264
|
+
return rebuild({ ...parts, options: f(parts.options) });
|
|
265
|
+
};
|
|
266
|
+
/**
|
|
267
|
+
* Remove every recorded result step, so the operation returns what its response decodes.
|
|
268
|
+
*
|
|
269
|
+
* @example
|
|
270
|
+
* ```ts
|
|
271
|
+
* import { Schema } from "effect";
|
|
272
|
+
* import { Body, Operation, Request, Response } from "viell-effect-schema-http";
|
|
273
|
+
* const Page = Schema.Struct({ data: Schema.Array(Schema.String) });
|
|
274
|
+
* const Names = Schema.Struct({ data: Schema.Array(Schema.Number) });
|
|
275
|
+
* const getThings = Operation.make(
|
|
276
|
+
* Request.get("https://api.example.test/things"),
|
|
277
|
+
* Response.status(200, Body.jsonSchema(Page)),
|
|
278
|
+
* ).pipe(Operation.map((page) => page.data));
|
|
279
|
+
*
|
|
280
|
+
* const asIds = Response.replace(200, Body.jsonSchema(Names));
|
|
281
|
+
* const thingIds = getThings.pipe(
|
|
282
|
+
* Operation.unmap,
|
|
283
|
+
* Operation.mapResponse(asIds),
|
|
284
|
+
* Operation.map((page) => page.data),
|
|
285
|
+
* );
|
|
286
|
+
* ```
|
|
287
|
+
*
|
|
288
|
+
* @remarks
|
|
289
|
+
* This is the route to a response {@link mapResponse} refuses: remove the mapping, change the
|
|
290
|
+
* response, then map again. The failures and services the steps added leave with them. On an
|
|
291
|
+
* operation with no step this changes nothing.
|
|
292
|
+
*/
|
|
293
|
+
export const unmap = (self) => rebuild({ ...partsOf(self), step: undefined });
|
|
294
|
+
/**
|
|
295
|
+
* Wrap the operation's own `execute`, and record the step for a later {@link rebuild}. Two steps
|
|
296
|
+
* combine into one, so the type does not grow with each map.
|
|
297
|
+
*/
|
|
298
|
+
const addStep = (self, f) => {
|
|
299
|
+
const wrapped = fromEffect((input) => Effect.flatMap(self.execute(input), f));
|
|
300
|
+
const parts = self.parts;
|
|
301
|
+
const previous = parts?.step;
|
|
302
|
+
const result = parts === undefined
|
|
303
|
+
? wrapped
|
|
304
|
+
: {
|
|
305
|
+
...wrapped,
|
|
306
|
+
parts: {
|
|
307
|
+
...parts,
|
|
308
|
+
step: {
|
|
309
|
+
run: previous === undefined
|
|
310
|
+
? f
|
|
311
|
+
: (value) => Effect.flatMap(previous.run(value), f),
|
|
312
|
+
},
|
|
313
|
+
},
|
|
314
|
+
};
|
|
315
|
+
return result;
|
|
316
|
+
};
|
|
129
317
|
/**
|
|
130
318
|
* Transform an operation's successful result with a pure function.
|
|
131
319
|
*
|
|
132
320
|
* @remarks
|
|
133
|
-
* Keeps the input, error and service types. Runs after the operation and its retry policy
|
|
134
|
-
* Use {@link mapEffect} to return a typed failure
|
|
321
|
+
* Keeps the input, error and service types. Runs once, after the operation and its retry policy
|
|
322
|
+
* finish, outside each attempt's scope and timeout. Use {@link mapEffect} to return a typed failure
|
|
323
|
+
* or perform further effectful work.
|
|
324
|
+
*
|
|
325
|
+
* The operation keeps its parts and records this as a step, so {@link mapRequest} and
|
|
326
|
+
* {@link mapOptions} still work on the result, and {@link mapResponse} works while the new result
|
|
327
|
+
* fits. Two maps combine into one step. The mapping applies to the whole result, whichever case
|
|
328
|
+
* produced it. For a conversion that belongs to one case, use `Body.map` on that case's decoder: a
|
|
329
|
+
* later `Response.replace` takes the conversion with the case.
|
|
135
330
|
*/
|
|
136
|
-
export const map = (f) => (self) =>
|
|
331
|
+
export const map = (f) => (self) => addStep(self, (value) => Effect.succeed(f(value)));
|
|
137
332
|
/**
|
|
138
333
|
* Transform an operation's successful result with an Effect.
|
|
139
334
|
*
|
|
140
335
|
* @remarks
|
|
141
|
-
* Adds the transformation's errors and required services. Runs after the operation's retry
|
|
142
|
-
* policy completes, so failures here do not trigger that
|
|
143
|
-
* response outcome into an application
|
|
336
|
+
* Adds the transformation's errors and required services. Runs once, after the operation's retry
|
|
337
|
+
* policy completes, outside each attempt's scope and timeout, so failures here do not trigger that
|
|
338
|
+
* policy and arrive as themselves. Use it to turn a recognized response outcome into an application
|
|
339
|
+
* error.
|
|
340
|
+
*
|
|
341
|
+
* The operation keeps its parts and records this as a step, as {@link map} describes. Its failures
|
|
342
|
+
* and services stay through a variant and leave with {@link unmap}.
|
|
144
343
|
*/
|
|
145
|
-
export const mapEffect = (f) => (self) =>
|
|
344
|
+
export const mapEffect = (f) => (self) => addStep(self, (value) => f(value));
|
|
146
345
|
//# sourceMappingURL=Operation.js.map
|