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.
- package/README.md +93 -48
- package/dist/concurrency/Interaction.d.ts +39 -6
- package/dist/concurrency/Interaction.d.ts.map +1 -1
- package/dist/concurrency/Interaction.js +25 -4
- package/dist/concurrency/Interaction.js.map +1 -1
- package/dist/http/Body.d.ts +142 -22
- package/dist/http/Body.d.ts.map +1 -1
- package/dist/http/Body.js +118 -14
- package/dist/http/Body.js.map +1 -1
- package/dist/http/Operation.d.ts +332 -12
- package/dist/http/Operation.d.ts.map +1 -1
- package/dist/http/Operation.js +255 -9
- package/dist/http/Operation.js.map +1 -1
- package/dist/http/Policy.d.ts +49 -13
- package/dist/http/Policy.d.ts.map +1 -1
- package/dist/http/Policy.js +32 -10
- package/dist/http/Policy.js.map +1 -1
- package/dist/http/Request.d.ts +661 -79
- package/dist/http/Request.d.ts.map +1 -1
- package/dist/http/Request.js +762 -120
- package/dist/http/Request.js.map +1 -1
- package/dist/http/Response.d.ts +200 -11
- package/dist/http/Response.d.ts.map +1 -1
- package/dist/http/Response.js +149 -10
- package/dist/http/Response.js.map +1 -1
- package/dist/http/Transport.d.ts +59 -11
- package/dist/http/Transport.d.ts.map +1 -1
- package/dist/http/Transport.js +46 -9
- package/dist/http/Transport.js.map +1 -1
- package/dist/http/UrlEncoding.d.ts +81 -9
- package/dist/http/UrlEncoding.d.ts.map +1 -1
- package/dist/http/UrlEncoding.js +41 -5
- 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/dist/main.d.ts +24 -0
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +24 -0
- package/dist/main.js.map +1 -1
- package/package.json +13 -13
- package/src/concurrency/Interaction.ts +39 -6
- package/src/http/Body.ts +158 -27
- package/src/http/Operation.ts +530 -32
- package/src/http/Policy.ts +49 -13
- package/src/http/Request.ts +1241 -227
- package/src/http/Response.ts +316 -28
- package/src/http/Transport.ts +59 -11
- package/src/http/UrlEncoding.ts +89 -10
- 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/src/main.ts +24 -0
package/dist/http/Operation.js
CHANGED
|
@@ -4,7 +4,28 @@ import * as Policy from "./Policy.js";
|
|
|
4
4
|
import * as Request from "./Request.js";
|
|
5
5
|
import * as Response from "./Response.js";
|
|
6
6
|
import * as Transport from "./Transport.js";
|
|
7
|
-
/**
|
|
7
|
+
/**
|
|
8
|
+
* Adapt an Effect-returning function to the operation interface.
|
|
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
|
+
*
|
|
21
|
+
* @remarks
|
|
22
|
+
* The function is suspended until evaluation. This adapter adds no HTTP dispatch, decoding,
|
|
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.
|
|
28
|
+
*/
|
|
8
29
|
export const fromEffect = (execute) => ({
|
|
9
30
|
...Pipeable.Prototype,
|
|
10
31
|
execute: (input) => Effect.suspend(() => execute(input)),
|
|
@@ -18,15 +39,42 @@ const outcome = (exit) => Exit.isSuccess(exit)
|
|
|
18
39
|
? "defect"
|
|
19
40
|
: "failure";
|
|
20
41
|
/**
|
|
21
|
-
*
|
|
22
|
-
*
|
|
42
|
+
* Combine a request and response contract into an executable HTTP operation.
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```ts
|
|
46
|
+
* import { Effect } from "effect";
|
|
47
|
+
* import { FetchHttpClient } from "effect/http";
|
|
48
|
+
* import { Body, Operation, Request, Response } from "viell-effect-schema-http";
|
|
49
|
+
* const health = Operation.make(
|
|
50
|
+
* Request.get("https://api.example.test/health"),
|
|
51
|
+
* Response.status(200, Body.text),
|
|
52
|
+
* );
|
|
53
|
+
* const program = health.execute(undefined).pipe(Effect.provide(FetchHttpClient.layer));
|
|
54
|
+
* // Evaluate program only after choosing your real service URL.
|
|
55
|
+
* ```
|
|
56
|
+
*
|
|
57
|
+
* @remarks
|
|
58
|
+
* Defaults to one attempt with no library-imposed timeout. The caller supplies Effect's
|
|
59
|
+
* `HttpClient` service and evaluates `execute(input)`.
|
|
60
|
+
*
|
|
61
|
+
* Each evaluation prepares input once. Each attempt then owns a scope covering client execution
|
|
62
|
+
* and body decoding; cleanup completes before classification or a retry delay. Decoder and
|
|
63
|
+
* client `Scope` requirements are supplied by the attempt. Interruption and defects never retry.
|
|
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.
|
|
23
69
|
*/
|
|
24
70
|
export const make = (request, response, options) => {
|
|
25
71
|
const policy = options?.policy ?? Policy.none;
|
|
26
72
|
const accept = response.accepts.join(", ");
|
|
27
73
|
const execute = Effect.fnUntraced(function* (input) {
|
|
28
74
|
const compiled = yield* Request.compile(request, input);
|
|
29
|
-
const prepared = accept !== "" &&
|
|
75
|
+
const prepared = accept !== "" &&
|
|
76
|
+
compiled.request.headers.accept === undefined &&
|
|
77
|
+
!compiled.removedHeaders.has("accept")
|
|
30
78
|
? HttpClientRequest.setHeader(compiled.request, "accept", accept)
|
|
31
79
|
: compiled.request;
|
|
32
80
|
const client = yield* HttpClient.HttpClient;
|
|
@@ -43,7 +91,8 @@ export const make = (request, response, options) => {
|
|
|
43
91
|
const execution = Effect.scoped(Effect.gen(function* () {
|
|
44
92
|
const send = options?.transformClient === undefined
|
|
45
93
|
? HttpClient.withScope(client).execute
|
|
46
|
-
: HttpClient.withScope(options.transformClient(client))
|
|
94
|
+
: HttpClient.withScope(options.transformClient(client, attempt))
|
|
95
|
+
.execute;
|
|
47
96
|
// A fresh request identity keeps the scoped abort controller of this attempt separate.
|
|
48
97
|
const received = yield* send(HttpClientRequest.setHeaders(prepared, {})).pipe(Effect.provideService(Transport.HeaderLines, compiled.headerLines),
|
|
49
98
|
// Client middleware can reject a response, such as filterStatusOk; its metadata still classifies the attempt.
|
|
@@ -90,10 +139,207 @@ export const make = (request, response, options) => {
|
|
|
90
139
|
yield* Effect.logDebug("HTTP retrying").pipe(Effect.annotateLogs({ "http.attempt": attempt + 1 }));
|
|
91
140
|
}
|
|
92
141
|
}, Effect.onExit((exit) => Effect.logDebug("HTTP operation completed").pipe(Effect.annotateLogs({ "http.outcome": outcome(exit) }))), Effect.withLogSpan("schema-http.operation"));
|
|
93
|
-
return {
|
|
142
|
+
return {
|
|
143
|
+
...Pipeable.Prototype,
|
|
144
|
+
execute,
|
|
145
|
+
parts: { request, response, options, step: undefined },
|
|
146
|
+
};
|
|
94
147
|
};
|
|
148
|
+
/**
|
|
149
|
+
* Return the Effect for an operation's input, in direct or pipeable form.
|
|
150
|
+
*
|
|
151
|
+
* @remarks
|
|
152
|
+
* Equivalent to `operation.execute(input)`. It does not itself evaluate the Effect.
|
|
153
|
+
*/
|
|
95
154
|
export const execute = Function.dual(2, (self, input) => self.execute(input));
|
|
96
|
-
/**
|
|
97
|
-
|
|
98
|
-
|
|
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
|
+
};
|
|
317
|
+
/**
|
|
318
|
+
* Transform an operation's successful result with a pure function.
|
|
319
|
+
*
|
|
320
|
+
* @remarks
|
|
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.
|
|
330
|
+
*/
|
|
331
|
+
export const map = (f) => (self) => addStep(self, (value) => Effect.succeed(f(value)));
|
|
332
|
+
/**
|
|
333
|
+
* Transform an operation's successful result with an Effect.
|
|
334
|
+
*
|
|
335
|
+
* @remarks
|
|
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}.
|
|
343
|
+
*/
|
|
344
|
+
export const mapEffect = (f) => (self) => addStep(self, (value) => f(value));
|
|
99
345
|
//# sourceMappingURL=Operation.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Operation.js","sourceRoot":"","sources":["../../src/http/Operation.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,EACL,KAAK,EACL,QAAQ,EACR,MAAM,EACN,IAAI,EACJ,QAAQ,EACR,MAAM,EACN,QAAQ,EACR,IAAI,EACJ,QAAQ,GAET,MAAM,QAAQ,CAAC;AAChB,OAAO,EACL,UAAU,EACV,eAAe,EACf,iBAAiB,GAElB,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AACtC,OAAO,KAA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AAI,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CACvC,CAAC;IACF,MAAM,KAAK,GAAG,IAAI,CAAC,KAAgC,CAAC;IACpD,MAAM,QAAQ,GAAG,KAAK,EAAE,IAAI,CAAC;IAC7B,MAAM,MAAM,GACV,KAAK,KAAK,SAAS;QACjB,CAAC,CAAC,OAAO;QACT,CAAC,CAAC;YACE,GAAG,OAAO;YACV,KAAK,EAAE;gBACL,GAAG,KAAK;gBACR,IAAI,EAAE;oBACJ,GAAG,EACD,QAAQ,KAAK,SAAS;wBACpB,CAAC,CAAC,CAAC;wBACH,CAAC,CAAC,CAAC,KAAc,EAAE,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;iBACjE;aACF;SACF,CAAC;IACR,OAAO,MAAgB,CAAC;AAC1B,CAAC,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,MAAM,GAAG,GACd,CAAO,CAAkB,EAAE,EAAE,CAC7B,CACE,IAA8B,EACgB,EAAE,CAChD,OAAO,CAAC,IAAI,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,KAAU,CAAC,CAAC,CAAC,CAAC;AAE5D;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,MAAM,SAAS,GACpB,CAAe,CAAyC,EAAE,EAAE,CAC5D,CACE,IAA8B,EACoB,EAAE,CACpD,OAAO,CAAC,IAAI,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,CAAC,KAAU,CAAC,CAAC,CAAC"}
|
package/dist/http/Policy.d.ts
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import { Cause, Duration, Schedule } from "effect";
|
|
2
2
|
import type * as Response from "./Response.js";
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
4
|
+
* The completed attempt's response metadata or failure cause, used to decide whether to retry.
|
|
5
|
+
*
|
|
6
|
+
* @remarks
|
|
7
|
+
* Contains no live transport resource, request method or decoded result. A failure includes
|
|
8
|
+
* metadata when a response was available, such as a decoding failure or a middleware rejection.
|
|
9
|
+
* Capture the operation's method or repeat-safety decision in the classifier's closure.
|
|
6
10
|
*/
|
|
7
11
|
export type Reason = {
|
|
8
12
|
readonly _tag: "Response";
|
|
@@ -13,35 +17,67 @@ export type Reason = {
|
|
|
13
17
|
/** Present when a response arrived before the failure: a decoding failure, or middleware rejecting it. */
|
|
14
18
|
readonly metadata?: Response.Metadata | undefined;
|
|
15
19
|
};
|
|
16
|
-
/**
|
|
20
|
+
/**
|
|
21
|
+
* A retry schedule, outcome classifier and optional timeout for an operation.
|
|
22
|
+
*
|
|
23
|
+
* @remarks
|
|
24
|
+
* The classifier and schedule must both permit another attempt. One schedule owns the retry
|
|
25
|
+
* budget across all reasons for that evaluation.
|
|
26
|
+
*/
|
|
17
27
|
export interface Policy<out E = never, out R = never> {
|
|
28
|
+
/** Supplies each retry delay and the shared retry budget for one evaluation. */
|
|
18
29
|
readonly schedule: Schedule.Schedule<unknown, Reason, E, R>;
|
|
30
|
+
/** Classifies a completed outcome as eligible for retry; the schedule must also permit it. */
|
|
19
31
|
readonly while: (reason: Reason) => boolean;
|
|
32
|
+
/** Bounds client execution and body decoding per attempt. `undefined` imposes no timeout. */
|
|
20
33
|
readonly attemptTimeout: Duration.Input | undefined;
|
|
34
|
+
/** Whether `Retry-After` supplies a minimum delay in addition to the schedule. */
|
|
21
35
|
readonly retryAfter: boolean;
|
|
22
36
|
}
|
|
23
37
|
/**
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
38
|
+
* Recognize timeouts, transport failures and transient HTTP statuses.
|
|
39
|
+
*
|
|
40
|
+
* @remarks
|
|
41
|
+
* The statuses are 408, 429, 500, 502, 503 and 504, matching Effect's transient classification.
|
|
42
|
+
* A declared response with one of these statuses is eligible even when decoding succeeded.
|
|
43
|
+
* This does not check the method or whether repeating a remote action is safe.
|
|
27
44
|
*/
|
|
28
45
|
export declare const transient: (reason: Reason) => boolean;
|
|
29
46
|
/**
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
47
|
+
* Create a retry policy from an Effect schedule and optional settings.
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```ts
|
|
51
|
+
* import { Schedule } from "effect";
|
|
52
|
+
* import { Policy } from "viell-effect-schema-http";
|
|
53
|
+
* const retryRead = Policy.make(Schedule.recurs(2), { attemptTimeout: "5 seconds" });
|
|
54
|
+
* // At most three attempts; repeat only operations your service permits you to repeat.
|
|
55
|
+
* ```
|
|
56
|
+
*
|
|
57
|
+
* @remarks
|
|
58
|
+
* `Schedule.recurs(n)` permits up to `n` retries after the first attempt. Defaults to
|
|
59
|
+
* {@link transient}, honoring `Retry-After`, and no attempt timeout. Enable retries only when
|
|
60
|
+
* repeating the service action is acceptable; transport failure does not prove it was unapplied.
|
|
61
|
+
* `while` sees every completed outcome, so `while: () => true` also repeats a successful 200 until
|
|
62
|
+
* the schedule ends. The attempt timeout covers client execution and decoding, not initial request
|
|
63
|
+
* preparation or retry delays. Apply `Effect.timeout` around the operation for an overall limit.
|
|
34
64
|
*/
|
|
35
65
|
export declare const make: <Out, E = never, R = never>(schedule: Schedule.Schedule<Out, Reason, E, R>, options?: {
|
|
36
66
|
readonly while?: ((reason: Reason) => boolean) | undefined;
|
|
37
67
|
readonly attemptTimeout?: Duration.Input | undefined;
|
|
38
68
|
readonly retryAfter?: boolean | undefined;
|
|
39
69
|
}) => Policy<E, R>;
|
|
40
|
-
/**
|
|
70
|
+
/**
|
|
71
|
+
* One attempt, with no retry and no library-imposed timeout.
|
|
72
|
+
*/
|
|
41
73
|
export declare const none: Policy;
|
|
42
74
|
/**
|
|
43
|
-
*
|
|
44
|
-
*
|
|
75
|
+
* Read the minimum retry delay requested by a response's `Retry-After` header.
|
|
76
|
+
*
|
|
77
|
+
* @remarks
|
|
78
|
+
* `now` is milliseconds since the Unix epoch. Accepts delay seconds or an HTTP date. Missing,
|
|
79
|
+
* malformed or unrepresentable values produce zero. An operation takes the larger of this delay
|
|
80
|
+
* and its scheduled delay; this helper does not decide whether another attempt is allowed.
|
|
45
81
|
*/
|
|
46
82
|
export declare const retryAfterDelay: (metadata: Response.Metadata, now: number) => Duration.Duration;
|
|
47
83
|
//# sourceMappingURL=Policy.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Policy.d.ts","sourceRoot":"","sources":["../../src/http/Policy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAU,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAE3D,OAAO,KAAK,KAAK,QAAQ,MAAM,eAAe,CAAC;AAE/C
|
|
1
|
+
{"version":3,"file":"Policy.d.ts","sourceRoot":"","sources":["../../src/http/Policy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAU,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAE3D,OAAO,KAAK,KAAK,QAAQ,MAAM,eAAe,CAAC;AAE/C;;;;;;;GAOG;AACH,MAAM,MAAM,MAAM,GACd;IAAE,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC;IAAC,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC,QAAQ,CAAA;CAAE,GACnE;IACE,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IACzB,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IACrC,0GAA0G;IAC1G,QAAQ,CAAC,QAAQ,CAAC,EAAE,QAAQ,CAAC,QAAQ,GAAG,SAAS,CAAC;CACnD,CAAC;AAEN;;;;;;GAMG;AACH,MAAM,WAAW,MAAM,CAAC,GAAG,CAAC,CAAC,GAAG,KAAK,EAAE,GAAG,CAAC,CAAC,GAAG,KAAK;IAClD,gFA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error.reason._tag === "StatusCodeError" &&
|
|
13
13
|
isTransientStatus(error.reason.response.status))));
|
|
14
14
|
/**
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
15
|
+
* Recognize timeouts, transport failures and transient HTTP statuses.
|
|
16
|
+
*
|
|
17
|
+
* @remarks
|
|
18
|
+
* The statuses are 408, 429, 500, 502, 503 and 504, matching Effect's transient classification.
|
|
19
|
+
* A declared response with one of these statuses is eligible even when decoding succeeded.
|
|
20
|
+
* This does not check the method or whether repeating a remote action is safe.
|
|
18
21
|
*/
|
|
19
22
|
export const transient = (reason) => {
|
|
20
23
|
if (reason.metadata !== undefined &&
|
|
@@ -25,10 +28,23 @@ export const transient = (reason) => {
|
|
|
25
28
|
return reason.cause.reasons.some((failure) => Cause.isFailReason(failure) && isTransientError(failure.error));
|
|
26
29
|
};
|
|
27
30
|
/**
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
31
|
+
* Create a retry policy from an Effect schedule and optional settings.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```ts
|
|
35
|
+
* import { Schedule } from "effect";
|
|
36
|
+
* import { Policy } from "viell-effect-schema-http";
|
|
37
|
+
* const retryRead = Policy.make(Schedule.recurs(2), { attemptTimeout: "5 seconds" });
|
|
38
|
+
* // At most three attempts; repeat only operations your service permits you to repeat.
|
|
39
|
+
* ```
|
|
40
|
+
*
|
|
41
|
+
* @remarks
|
|
42
|
+
* `Schedule.recurs(n)` permits up to `n` retries after the first attempt. Defaults to
|
|
43
|
+
* {@link transient}, honoring `Retry-After`, and no attempt timeout. Enable retries only when
|
|
44
|
+
* repeating the service action is acceptable; transport failure does not prove it was unapplied.
|
|
45
|
+
* `while` sees every completed outcome, so `while: () => true` also repeats a successful 200 until
|
|
46
|
+
* the schedule ends. The attempt timeout covers client execution and decoding, not initial request
|
|
47
|
+
* preparation or retry delays. Apply `Effect.timeout` around the operation for an overall limit.
|
|
32
48
|
*/
|
|
33
49
|
export const make = (schedule, options) => ({
|
|
34
50
|
schedule,
|
|
@@ -36,11 +52,17 @@ export const make = (schedule, options) => ({
|
|
|
36
52
|
attemptTimeout: options?.attemptTimeout,
|
|
37
53
|
retryAfter: options?.retryAfter ?? true,
|
|
38
54
|
});
|
|
39
|
-
/**
|
|
55
|
+
/**
|
|
56
|
+
* One attempt, with no retry and no library-imposed timeout.
|
|
57
|
+
*/
|
|
40
58
|
export const none = make(Schedule.recurs(0));
|
|
41
59
|
/**
|
|
42
|
-
*
|
|
43
|
-
*
|
|
60
|
+
* Read the minimum retry delay requested by a response's `Retry-After` header.
|
|
61
|
+
*
|
|
62
|
+
* @remarks
|
|
63
|
+
* `now` is milliseconds since the Unix epoch. Accepts delay seconds or an HTTP date. Missing,
|
|
64
|
+
* malformed or unrepresentable values produce zero. An operation takes the larger of this delay
|
|
65
|
+
* and its scheduled delay; this helper does not decide whether another attempt is allowed.
|
|
44
66
|
*/
|
|
45
67
|
export const retryAfterDelay = (metadata, now) => {
|
|
46
68
|
const value = metadata.headers["retry-after"];
|
package/dist/http/Policy.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Policy.js","sourceRoot":"","sources":["../../src/http/Policy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAC3D,OAAO,EAAE,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"Policy.js","sourceRoot":"","sources":["../../src/http/Policy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAC3D,OAAO,EAAE,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAsCvD,MAAM,iBAAiB,GAAG,CAAC,MAAc,EAAW,EAAE,CACpD,MA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