@distilled.cloud/core 1.0.0-rc.13 → 1.0.0-rc.14
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/lib/api.d.ts +4 -4
- package/lib/api.d.ts.map +1 -1
- package/lib/api.js +3 -5
- package/lib/api.js.map +1 -1
- package/lib/category.d.ts.map +1 -1
- package/lib/category.js +3 -5
- package/lib/category.js.map +1 -1
- package/lib/codegen/boolean-string-enums.d.ts.map +1 -1
- package/lib/codegen/boolean-string-enums.js +2 -6
- package/lib/codegen/boolean-string-enums.js.map +1 -1
- package/lib/codegen/boolean-string-enums.test.js +3 -5
- package/lib/codegen/boolean-string-enums.test.js.map +1 -1
- package/lib/codegen/cli.d.ts +5 -4
- package/lib/codegen/cli.d.ts.map +1 -1
- package/lib/codegen/cli.js +12 -9
- package/lib/codegen/cli.js.map +1 -1
- package/lib/codegen/defer-naming.test.d.ts +2 -0
- package/lib/codegen/defer-naming.test.d.ts.map +1 -0
- package/lib/codegen/defer-naming.test.js +105 -0
- package/lib/codegen/defer-naming.test.js.map +1 -0
- package/lib/codegen/emit.d.ts.map +1 -1
- package/lib/codegen/emit.js +1 -3
- package/lib/codegen/emit.js.map +1 -1
- package/lib/codegen/format.d.ts +0 -12
- package/lib/codegen/format.d.ts.map +1 -1
- package/lib/codegen/format.js +10 -6
- package/lib/codegen/format.js.map +1 -1
- package/lib/codegen/generated-at.d.ts +29 -0
- package/lib/codegen/generated-at.d.ts.map +1 -0
- package/lib/codegen/generated-at.js +78 -0
- package/lib/codegen/generated-at.js.map +1 -0
- package/lib/codegen/generated-at.test.d.ts +2 -0
- package/lib/codegen/generated-at.test.d.ts.map +1 -0
- package/lib/codegen/generated-at.test.js +81 -0
- package/lib/codegen/generated-at.test.js.map +1 -0
- package/lib/codegen/generator.d.ts +4 -2
- package/lib/codegen/generator.d.ts.map +1 -1
- package/lib/codegen/generator.js +37 -75
- package/lib/codegen/generator.js.map +1 -1
- package/lib/codegen/generator.test.js +4 -9
- package/lib/codegen/generator.test.js.map +1 -1
- package/lib/codegen/graphql-client.d.ts.map +1 -1
- package/lib/codegen/graphql-client.js +12 -33
- package/lib/codegen/graphql-client.js.map +1 -1
- package/lib/codegen/graphql-client.test.js +4 -12
- package/lib/codegen/graphql-client.test.js.map +1 -1
- package/lib/codegen/graphql.d.ts.map +1 -1
- package/lib/codegen/graphql.js +7 -20
- package/lib/codegen/graphql.js.map +1 -1
- package/lib/codegen/model-diff.d.ts +10 -0
- package/lib/codegen/model-diff.d.ts.map +1 -0
- package/lib/codegen/model-diff.js +67 -0
- package/lib/codegen/model-diff.js.map +1 -0
- package/lib/codegen/naming.d.ts.map +1 -1
- package/lib/codegen/naming.js.map +1 -1
- package/lib/codegen/openapi-binary.test.js +1 -1
- package/lib/codegen/openapi-binary.test.js.map +1 -1
- package/lib/codegen/openapi-cli.d.ts +11 -11
- package/lib/codegen/openapi-cli.d.ts.map +1 -1
- package/lib/codegen/openapi-cli.js +26 -51
- package/lib/codegen/openapi-cli.js.map +1 -1
- package/lib/codegen/openapi.d.ts +9 -1
- package/lib/codegen/openapi.d.ts.map +1 -1
- package/lib/codegen/openapi.js +48 -42
- package/lib/codegen/openapi.js.map +1 -1
- package/lib/codegen/operations.d.ts.map +1 -1
- package/lib/codegen/operations.js.map +1 -1
- package/lib/codegen/pagination.d.ts.map +1 -1
- package/lib/codegen/pagination.js +2 -4
- package/lib/codegen/pagination.js.map +1 -1
- package/lib/codegen/patch-audit.d.ts +84 -0
- package/lib/codegen/patch-audit.d.ts.map +1 -0
- package/lib/codegen/patch-audit.js +366 -0
- package/lib/codegen/patch-audit.js.map +1 -0
- package/lib/codegen/patch-audit.test.d.ts +2 -0
- package/lib/codegen/patch-audit.test.d.ts.map +1 -0
- package/lib/codegen/patch-audit.test.js +141 -0
- package/lib/codegen/patch-audit.test.js.map +1 -0
- package/lib/codegen/patches.d.ts +59 -10
- package/lib/codegen/patches.d.ts.map +1 -1
- package/lib/codegen/patches.js +233 -63
- package/lib/codegen/patches.js.map +1 -1
- package/lib/codegen/patches.test.js +8 -4
- package/lib/codegen/patches.test.js.map +1 -1
- package/lib/codegen/prelude.js +1 -1
- package/lib/codegen/prelude.js.map +1 -1
- package/lib/codegen/proto.d.ts.map +1 -1
- package/lib/codegen/proto.js +2 -4
- package/lib/codegen/proto.js.map +1 -1
- package/lib/codegen/protocol-imports.test.d.ts +2 -0
- package/lib/codegen/protocol-imports.test.d.ts.map +1 -0
- package/lib/codegen/protocol-imports.test.js +36 -0
- package/lib/codegen/protocol-imports.test.js.map +1 -0
- package/lib/codegen/rewrite-operation-ids.d.ts +23 -0
- package/lib/codegen/rewrite-operation-ids.d.ts.map +1 -1
- package/lib/codegen/rewrite-operation-ids.js +97 -59
- package/lib/codegen/rewrite-operation-ids.js.map +1 -1
- package/lib/codegen/rewrite-operation-ids.test.js +19 -101
- package/lib/codegen/rewrite-operation-ids.test.js.map +1 -1
- package/lib/codegen/spec-path.d.ts +1 -1
- package/lib/codegen/spec-path.d.ts.map +1 -1
- package/lib/codegen/spec-path.js +1 -1
- package/lib/codegen/spec-path.js.map +1 -1
- package/lib/codegen/untagged-unions.test.js +1 -1
- package/lib/codegen/untagged-unions.test.js.map +1 -1
- package/lib/error-category.d.ts.map +1 -1
- package/lib/error-category.js.map +1 -1
- package/lib/errors.d.ts.map +1 -1
- package/lib/errors.js +7 -5
- package/lib/errors.js.map +1 -1
- package/lib/graphql.d.ts +4 -8
- package/lib/graphql.d.ts.map +1 -1
- package/lib/graphql.js +20 -48
- package/lib/graphql.js.map +1 -1
- package/lib/graphql.test.js +6 -6
- package/lib/graphql.test.js.map +1 -1
- package/lib/graphql.types.d.ts.map +1 -1
- package/lib/graphql.types.js.map +1 -1
- package/lib/json-patch.d.ts +13 -6
- package/lib/json-patch.d.ts.map +1 -1
- package/lib/json-patch.js +34 -19
- package/lib/json-patch.js.map +1 -1
- package/lib/json-patch.test.d.ts +2 -0
- package/lib/json-patch.test.d.ts.map +1 -0
- package/lib/json-patch.test.js +65 -0
- package/lib/json-patch.test.js.map +1 -0
- package/lib/pagination.d.ts.map +1 -1
- package/lib/pagination.js +6 -16
- package/lib/pagination.js.map +1 -1
- package/lib/pagination.test.js +3 -6
- package/lib/pagination.test.js.map +1 -1
- package/lib/protocol-http.d.ts +20 -1
- package/lib/protocol-http.d.ts.map +1 -1
- package/lib/protocol-http.js +41 -47
- package/lib/protocol-http.js.map +1 -1
- package/lib/protocol-http.test.js +20 -10
- package/lib/protocol-http.test.js.map +1 -1
- package/lib/protocol-rest.d.ts.map +1 -1
- package/lib/protocol-rest.js +9 -18
- package/lib/protocol-rest.js.map +1 -1
- package/lib/protocol-rest.test.d.ts +2 -0
- package/lib/protocol-rest.test.d.ts.map +1 -0
- package/lib/protocol-rest.test.js +498 -0
- package/lib/protocol-rest.test.js.map +1 -0
- package/lib/response-validation.d.ts.map +1 -1
- package/lib/response-validation.js.map +1 -1
- package/lib/response-validation.test.js +10 -5
- package/lib/response-validation.test.js.map +1 -1
- package/lib/retry-after.d.ts.map +1 -1
- package/lib/retry-after.js +1 -1
- package/lib/retry-after.js.map +1 -1
- package/lib/retry-after.test.d.ts +2 -0
- package/lib/retry-after.test.d.ts.map +1 -0
- package/lib/retry-after.test.js +204 -0
- package/lib/retry-after.test.js.map +1 -0
- package/lib/retry.d.ts.map +1 -1
- package/lib/retry.js +1 -2
- package/lib/retry.js.map +1 -1
- package/lib/retry.test.d.ts +2 -0
- package/lib/retry.test.d.ts.map +1 -0
- package/lib/retry.test.js +407 -0
- package/lib/retry.test.js.map +1 -0
- package/lib/sdks.test.d.ts +2 -0
- package/lib/sdks.test.d.ts.map +1 -0
- package/lib/sdks.test.js +76 -0
- package/lib/sdks.test.js.map +1 -0
- package/lib/testing.d.ts +2 -2
- package/lib/testing.d.ts.map +1 -1
- package/lib/testing.js +1 -1
- package/lib/testing.js.map +1 -1
- package/lib/trait.d.ts.map +1 -1
- package/lib/trait.js.map +1 -1
- package/lib/xml.d.ts.map +1 -1
- package/lib/xml.js +3 -7
- package/lib/xml.js.map +1 -1
- package/lib/xml.test.js +11 -12
- package/lib/xml.test.js.map +1 -1
- package/package.json +7 -10
- package/src/api.ts +38 -55
- package/src/category.ts +21 -50
- package/src/codegen/boolean-string-enums.test.ts +12 -28
- package/src/codegen/boolean-string-enums.ts +2 -10
- package/src/codegen/cli.ts +29 -47
- package/src/codegen/defer-naming.test.ts +113 -0
- package/src/codegen/emit.ts +2 -5
- package/src/codegen/format.ts +12 -10
- package/src/codegen/generated-at.test.ts +89 -0
- package/src/codegen/generated-at.ts +88 -0
- package/src/codegen/generator.test.ts +8 -22
- package/src/codegen/generator.ts +72 -191
- package/src/codegen/graphql-client.test.ts +12 -42
- package/src/codegen/graphql-client.ts +30 -95
- package/src/codegen/graphql.ts +22 -94
- package/src/codegen/model-diff.ts +67 -0
- package/src/codegen/naming.ts +1 -2
- package/src/codegen/openapi-binary.test.ts +5 -12
- package/src/codegen/openapi-cli.ts +38 -79
- package/src/codegen/openapi.ts +79 -136
- package/src/codegen/operations.ts +2 -5
- package/src/codegen/pagination.ts +4 -11
- package/src/codegen/patch-audit.test.ts +160 -0
- package/src/codegen/patch-audit.ts +480 -0
- package/src/codegen/patches.test.ts +14 -21
- package/src/codegen/patches.ts +313 -103
- package/src/codegen/prelude.ts +1 -1
- package/src/codegen/proto.ts +18 -54
- package/src/codegen/protocol-imports.test.ts +39 -0
- package/src/codegen/rewrite-operation-ids.test.ts +23 -114
- package/src/codegen/rewrite-operation-ids.ts +111 -98
- package/src/codegen/spec-path.ts +3 -6
- package/src/codegen/untagged-unions.test.ts +3 -7
- package/src/error-category.ts +5 -17
- package/src/errors.ts +16 -31
- package/src/graphql.test.ts +6 -8
- package/src/graphql.ts +76 -219
- package/src/graphql.types.ts +10 -25
- package/src/json-patch.test.ts +77 -0
- package/src/json-patch.ts +54 -60
- package/src/pagination.test.ts +13 -35
- package/src/pagination.ts +44 -111
- package/src/protocol-http.test.ts +36 -30
- package/src/protocol-http.ts +73 -138
- package/src/protocol-rest.test.ts +703 -0
- package/src/protocol-rest.ts +24 -62
- package/src/response-validation.test.ts +12 -18
- package/src/response-validation.ts +3 -12
- package/src/retry-after.test.ts +267 -0
- package/src/retry-after.ts +4 -10
- package/src/retry.test.ts +566 -0
- package/src/retry.ts +6 -21
- package/src/sdks.test.ts +87 -0
- package/src/testing.ts +4 -10
- package/src/trait.ts +21 -67
- package/src/xml.test.ts +15 -33
- package/src/xml.ts +9 -25
|
@@ -0,0 +1,566 @@
|
|
|
1
|
+
import * as Clock from "effect/Clock";
|
|
2
|
+
import * as ConfigProvider from "effect/ConfigProvider";
|
|
3
|
+
import * as Duration from "effect/Duration";
|
|
4
|
+
import * as Effect from "effect/Effect";
|
|
5
|
+
import * as Fiber from "effect/Fiber";
|
|
6
|
+
import * as HttpClient from "effect/http/HttpClient";
|
|
7
|
+
import * as HttpClientError from "effect/http/HttpClientError";
|
|
8
|
+
import * as HttpClientRequest from "effect/http/HttpClientRequest";
|
|
9
|
+
import * as HttpClientResponse from "effect/http/HttpClientResponse";
|
|
10
|
+
import * as Layer from "effect/Layer";
|
|
11
|
+
import * as Ref from "effect/Ref";
|
|
12
|
+
import * as Schedule from "effect/Schedule";
|
|
13
|
+
import * as Schema from "effect/Schema";
|
|
14
|
+
import * as TestClock from "effect/testing/TestClock";
|
|
15
|
+
import { afterEach, beforeEach, describe, expect, test, vi } from "vitest";
|
|
16
|
+
import * as API from "./api.ts";
|
|
17
|
+
import * as Category from "./category.ts";
|
|
18
|
+
import {
|
|
19
|
+
BadGateway,
|
|
20
|
+
BadRequest,
|
|
21
|
+
Conflict,
|
|
22
|
+
Forbidden,
|
|
23
|
+
GatewayTimeout,
|
|
24
|
+
InternalServerError,
|
|
25
|
+
Locked,
|
|
26
|
+
NotFound,
|
|
27
|
+
ServiceUnavailable,
|
|
28
|
+
TooManyRequests,
|
|
29
|
+
Unauthorized,
|
|
30
|
+
} from "./errors.ts";
|
|
31
|
+
import { makeRestProtocol } from "./protocol-rest.ts";
|
|
32
|
+
import * as Retry from "./retry.ts";
|
|
33
|
+
import * as S from "./schema.ts";
|
|
34
|
+
import * as T from "./trait.ts";
|
|
35
|
+
|
|
36
|
+
// =============================================================================
|
|
37
|
+
// Fixtures
|
|
38
|
+
// =============================================================================
|
|
39
|
+
|
|
40
|
+
class TestRetry extends Retry.makeRetryService("RetryTest/Retry") {}
|
|
41
|
+
class OtherRetry extends Retry.makeRetryService("RetryTest/OtherRetry") {}
|
|
42
|
+
|
|
43
|
+
class UnknownTestError extends Schema.TaggedError<UnknownTestError>()("UnknownTestError", {
|
|
44
|
+
message: Schema.String,
|
|
45
|
+
}) {}
|
|
46
|
+
|
|
47
|
+
const TestProtocol = makeRestProtocol<{}>({
|
|
48
|
+
credentials: Effect.succeed({}),
|
|
49
|
+
baseUrl: () => "https://api.test",
|
|
50
|
+
headers: () => ({}),
|
|
51
|
+
unknownError: ({ message }) => new UnknownTestError({ message }),
|
|
52
|
+
parseError: ({ body }) => new UnknownTestError({ message: String(body) }),
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
const Output = S.Struct({ ok: S.optional(S.Boolean) });
|
|
56
|
+
|
|
57
|
+
type Call = (input: Record<string, unknown>) => Effect.Effect<any, any, any>;
|
|
58
|
+
|
|
59
|
+
const operation = (method: "GET" | "POST", retry?: typeof TestRetry): Call =>
|
|
60
|
+
API.make(() => ({
|
|
61
|
+
input: S.Struct({}).pipe(T.Http({ method, uri: "/thing" })),
|
|
62
|
+
output: Output,
|
|
63
|
+
protocol: TestProtocol,
|
|
64
|
+
...(retry ? { retry } : {}),
|
|
65
|
+
})) as unknown as Call;
|
|
66
|
+
|
|
67
|
+
const getThing = operation("GET", TestRetry);
|
|
68
|
+
const createThing = operation("POST", TestRetry);
|
|
69
|
+
const getThingWithoutRetry = operation("GET");
|
|
70
|
+
|
|
71
|
+
type Reply = Response | "transport";
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Fake HttpClient replying from `script` by attempt number (0-based) and
|
|
75
|
+
* recording the TestClock time of every attempt.
|
|
76
|
+
*/
|
|
77
|
+
const scripted = (script: (attempt: number) => Reply) => {
|
|
78
|
+
const attempts: Array<{ readonly at: number; readonly method: string }> = [];
|
|
79
|
+
const layer = Layer.succeed(
|
|
80
|
+
HttpClient.HttpClient,
|
|
81
|
+
HttpClient.make((request) =>
|
|
82
|
+
Effect.gen(function* () {
|
|
83
|
+
const at = yield* Clock.currentTimeMillis;
|
|
84
|
+
const reply = script(attempts.length);
|
|
85
|
+
attempts.push({ at, method: request.method });
|
|
86
|
+
if (reply === "transport") {
|
|
87
|
+
return yield* Effect.fail(
|
|
88
|
+
new HttpClientError.HttpClientError({
|
|
89
|
+
reason: new HttpClientError.TransportError({ request, description: "reset" }),
|
|
90
|
+
}),
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
return HttpClientResponse.fromWeb(request, reply);
|
|
94
|
+
}),
|
|
95
|
+
),
|
|
96
|
+
);
|
|
97
|
+
return { attempts, layer, times: () => attempts.map((a) => a.at) };
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
const status = (code: number, headers: Record<string, string> = {}) =>
|
|
101
|
+
new Response(JSON.stringify({ message: `status ${code}` }), { status: code, headers });
|
|
102
|
+
const ok = () => new Response(JSON.stringify({ ok: true }), { status: 200 });
|
|
103
|
+
|
|
104
|
+
/** Fail `n` times with `reply`, then succeed. */
|
|
105
|
+
const failTimes = (n: number, reply: () => Reply) => (attempt: number) =>
|
|
106
|
+
attempt < n ? reply() : ok();
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Run `effect` under a TestClock, advancing virtual time far enough for any
|
|
110
|
+
* finite retry sequence in these tests to complete.
|
|
111
|
+
*/
|
|
112
|
+
const runVirtual = <A, E>(effect: Effect.Effect<A, E, any>, layer: Layer.Layer<any>) =>
|
|
113
|
+
Effect.runPromise(
|
|
114
|
+
Effect.gen(function* () {
|
|
115
|
+
const fiber = yield* Effect.forkChild(Effect.result(effect));
|
|
116
|
+
yield* TestClock.adjust(Duration.hours(1));
|
|
117
|
+
return yield* Fiber.join(fiber);
|
|
118
|
+
}).pipe(Effect.provide(Layer.mergeAll(layer, TestClock.layer()))) as Effect.Effect<
|
|
119
|
+
any,
|
|
120
|
+
never,
|
|
121
|
+
never
|
|
122
|
+
>,
|
|
123
|
+
);
|
|
124
|
+
|
|
125
|
+
const delays = (times: ReadonlyArray<number>) => times.slice(1).map((t, i) => t - times[i]!);
|
|
126
|
+
|
|
127
|
+
const withPolicy =
|
|
128
|
+
(policy: Retry.Policy) =>
|
|
129
|
+
<A, E, R>(effect: Effect.Effect<A, E, R>) =>
|
|
130
|
+
effect.pipe(Effect.provideService(TestRetry, policy));
|
|
131
|
+
|
|
132
|
+
const none: Retry.Options = { while: () => false };
|
|
133
|
+
|
|
134
|
+
beforeEach(() => {
|
|
135
|
+
// Pin jitter (Math.random * 50ms) to zero so delays are exact.
|
|
136
|
+
vi.spyOn(Math, "random").mockReturnValue(0);
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
afterEach(() => {
|
|
140
|
+
vi.restoreAllMocks();
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
// The default ConfigProvider snapshots process.env on first use, so env
|
|
144
|
+
// overrides are supplied through an explicit provider.
|
|
145
|
+
const env = (vars: Record<string, string>) =>
|
|
146
|
+
ConfigProvider.layer(ConfigProvider.fromEnv({ env: vars }));
|
|
147
|
+
|
|
148
|
+
// =============================================================================
|
|
149
|
+
// Error categories
|
|
150
|
+
// =============================================================================
|
|
151
|
+
|
|
152
|
+
const request = HttpClientRequest.get("https://api.test/thing");
|
|
153
|
+
const transportError = new HttpClientError.HttpClientError({
|
|
154
|
+
reason: new HttpClientError.TransportError({ request }),
|
|
155
|
+
});
|
|
156
|
+
const decodeError = new HttpClientError.HttpClientError({
|
|
157
|
+
reason: new HttpClientError.DecodeError({
|
|
158
|
+
request,
|
|
159
|
+
response: HttpClientResponse.fromWeb(request, new Response("x")),
|
|
160
|
+
}),
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
class CategorizedNetworkError extends Schema.TaggedError<CategorizedNetworkError>()(
|
|
164
|
+
"CategorizedNetworkError",
|
|
165
|
+
{ message: Schema.String },
|
|
166
|
+
).pipe(Category.withCategory(Category.NetworkError)) {}
|
|
167
|
+
|
|
168
|
+
class CategorizedTimeoutError extends Schema.TaggedError<CategorizedTimeoutError>()(
|
|
169
|
+
"CategorizedTimeoutError",
|
|
170
|
+
{ message: Schema.String },
|
|
171
|
+
).pipe(Category.withCategory(Category.TimeoutError)) {}
|
|
172
|
+
|
|
173
|
+
class RetryableMarked extends Schema.TaggedError<RetryableMarked>()("RetryableMarked", {
|
|
174
|
+
message: Schema.String,
|
|
175
|
+
}).pipe(Category.withRetryable()) {}
|
|
176
|
+
|
|
177
|
+
const transient = [
|
|
178
|
+
new TooManyRequests({ message: "" }),
|
|
179
|
+
new Locked({ message: "" }),
|
|
180
|
+
new InternalServerError({ message: "" }),
|
|
181
|
+
new BadGateway({ message: "" }),
|
|
182
|
+
new ServiceUnavailable({ message: "" }),
|
|
183
|
+
new GatewayTimeout({ message: "" }),
|
|
184
|
+
new CategorizedNetworkError({ message: "" }),
|
|
185
|
+
new CategorizedTimeoutError({ message: "" }),
|
|
186
|
+
new RetryableMarked({ message: "" }),
|
|
187
|
+
transportError,
|
|
188
|
+
];
|
|
189
|
+
|
|
190
|
+
const permanent = [
|
|
191
|
+
new BadRequest({ message: "" }),
|
|
192
|
+
new Unauthorized({ message: "" }),
|
|
193
|
+
new Forbidden({ message: "" }),
|
|
194
|
+
new NotFound({ message: "" }),
|
|
195
|
+
new Conflict({ message: "" }),
|
|
196
|
+
new UnknownTestError({ message: "" }),
|
|
197
|
+
decodeError,
|
|
198
|
+
new Error("plain"),
|
|
199
|
+
undefined,
|
|
200
|
+
];
|
|
201
|
+
|
|
202
|
+
const nameOf = (e: unknown) =>
|
|
203
|
+
(e as { _tag?: string } | undefined)?._tag === "HttpClientError"
|
|
204
|
+
? `HttpClientError(${(e as HttpClientError.HttpClientError).reason._tag})`
|
|
205
|
+
: ((e as { _tag?: string } | undefined)?._tag ?? String(e));
|
|
206
|
+
|
|
207
|
+
describe("retry predicates by error category", () => {
|
|
208
|
+
const lastError = Effect.runSync(Ref.make<unknown>(undefined));
|
|
209
|
+
const policies = {
|
|
210
|
+
makeDefault: Retry.makeDefault(lastError),
|
|
211
|
+
transientFactory: Retry.transientFactory(lastError),
|
|
212
|
+
transientOptions: Retry.transientOptions,
|
|
213
|
+
throttlingFactory: Retry.throttlingFactory(lastError),
|
|
214
|
+
throttlingOptions: Retry.throttlingOptions,
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
for (const error of transient) {
|
|
218
|
+
test(`default and transient policies retry ${nameOf(error)}`, () => {
|
|
219
|
+
expect(policies.makeDefault.while!(error)).toBe(true);
|
|
220
|
+
expect(policies.transientFactory.while!(error)).toBe(true);
|
|
221
|
+
expect(policies.transientOptions.while!(error)).toBe(true);
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
for (const error of permanent) {
|
|
226
|
+
test(`no policy retries ${nameOf(error)}`, () => {
|
|
227
|
+
for (const policy of Object.values(policies)) {
|
|
228
|
+
expect(policy.while!(error)).toBe(false);
|
|
229
|
+
}
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
test("throttling policies retry only throttling errors", () => {
|
|
234
|
+
for (const policy of [policies.throttlingFactory, policies.throttlingOptions]) {
|
|
235
|
+
expect(policy.while!(new TooManyRequests({ message: "" }))).toBe(true);
|
|
236
|
+
for (const error of transient.filter((e) => !(e instanceof TooManyRequests))) {
|
|
237
|
+
expect(policy.while!(error)).toBe(false);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
});
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
// =============================================================================
|
|
244
|
+
// Default policy
|
|
245
|
+
// =============================================================================
|
|
246
|
+
|
|
247
|
+
describe("makeDefault schedule", () => {
|
|
248
|
+
test("backs off exponentially from 250ms, capped at 5s, and gives up after 8 retries", async () => {
|
|
249
|
+
const http = scripted(() => status(503));
|
|
250
|
+
const result = await runVirtual(getThing({}), http.layer);
|
|
251
|
+
expect(result._tag).toBe("Failure");
|
|
252
|
+
expect(result.failure).toBeInstanceOf(ServiceUnavailable);
|
|
253
|
+
expect(http.attempts).toHaveLength(9);
|
|
254
|
+
expect(delays(http.times())).toEqual([250, 500, 1000, 2000, 4000, 5000, 5000, 5000]);
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
test("succeeds as soon as a retry succeeds", async () => {
|
|
258
|
+
const http = scripted(failTimes(2, () => status(500)));
|
|
259
|
+
const result = await runVirtual(getThing({}), http.layer);
|
|
260
|
+
expect(result).toMatchObject({ _tag: "Success", success: { ok: true } });
|
|
261
|
+
expect(http.attempts).toHaveLength(3);
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
test("throttling errors wait at least 500ms", async () => {
|
|
265
|
+
const http = scripted(failTimes(3, () => status(429)));
|
|
266
|
+
await runVirtual(getThing({}), http.layer);
|
|
267
|
+
expect(delays(http.times())).toEqual([500, 500, 1000]);
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
test("retries wire-level transport failures", async () => {
|
|
271
|
+
const http = scripted(failTimes(2, () => "transport"));
|
|
272
|
+
const result = await runVirtual(getThing({}), http.layer);
|
|
273
|
+
expect(result._tag).toBe("Success");
|
|
274
|
+
expect(delays(http.times())).toEqual([250, 500]);
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
test("does not retry non-transient failures", async () => {
|
|
278
|
+
for (const code of [400, 401, 403, 404, 409, 422, 402]) {
|
|
279
|
+
const http = scripted(() => status(code));
|
|
280
|
+
const result = await runVirtual(getThing({}), http.layer);
|
|
281
|
+
expect(result._tag).toBe("Failure");
|
|
282
|
+
expect(http.attempts).toHaveLength(1);
|
|
283
|
+
}
|
|
284
|
+
});
|
|
285
|
+
|
|
286
|
+
test("does not distinguish mutations from reads", async () => {
|
|
287
|
+
const reads = scripted(failTimes(2, () => status(503)));
|
|
288
|
+
const writes = scripted(failTimes(2, () => status(503)));
|
|
289
|
+
await runVirtual(getThing({}), reads.layer);
|
|
290
|
+
await runVirtual(createThing({}), writes.layer);
|
|
291
|
+
expect(writes.attempts.map((a) => a.method)).toEqual(["POST", "POST", "POST"]);
|
|
292
|
+
expect(writes.times()).toEqual(reads.times());
|
|
293
|
+
});
|
|
294
|
+
|
|
295
|
+
test("jitter adds up to 50ms to each delay", async () => {
|
|
296
|
+
vi.spyOn(Math, "random").mockReturnValue(0.5);
|
|
297
|
+
const http = scripted(failTimes(2, () => status(503)));
|
|
298
|
+
await runVirtual(getThing({}), http.layer);
|
|
299
|
+
expect(delays(http.times())).toEqual([275, 525]);
|
|
300
|
+
});
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
describe("server retry hints", () => {
|
|
304
|
+
test("the default policy honors retryAfter over its own backoff", async () => {
|
|
305
|
+
const http = scripted(failTimes(2, () => status(503, { "retry-after": "2" })));
|
|
306
|
+
await runVirtual(getThing({}), http.layer);
|
|
307
|
+
expect(delays(http.times())).toEqual([2000, 2000]);
|
|
308
|
+
});
|
|
309
|
+
|
|
310
|
+
test("a hint longer than the 5s backoff cap is honored in full", async () => {
|
|
311
|
+
const http = scripted(failTimes(1, () => status(429, { "retry-after": "30" })));
|
|
312
|
+
await runVirtual(getThing({}), http.layer);
|
|
313
|
+
expect(delays(http.times())).toEqual([30_000]);
|
|
314
|
+
});
|
|
315
|
+
|
|
316
|
+
test("a hint shorter than the throttling floor still wins", async () => {
|
|
317
|
+
const http = scripted(failTimes(1, () => status(429, { "retry-after": "0" })));
|
|
318
|
+
await runVirtual(getThing({}), http.layer);
|
|
319
|
+
expect(delays(http.times())).toEqual([0]);
|
|
320
|
+
});
|
|
321
|
+
|
|
322
|
+
test("hints are capped at DEFAULT_SERVER_RETRY_HINT_CAP_MS", async () => {
|
|
323
|
+
expect(Retry.DEFAULT_SERVER_RETRY_HINT_CAP_MS).toBe(60_000);
|
|
324
|
+
const http = scripted(failTimes(1, () => status(429, { "retry-after": "600" })));
|
|
325
|
+
await runVirtual(getThing({}), http.layer);
|
|
326
|
+
expect(delays(http.times())).toEqual([60_000]);
|
|
327
|
+
});
|
|
328
|
+
|
|
329
|
+
test("serverRetryHintCapLayer overrides the cap", async () => {
|
|
330
|
+
const http = scripted(failTimes(1, () => status(429, { "retry-after": "600" })));
|
|
331
|
+
await runVirtual(
|
|
332
|
+
getThing({}),
|
|
333
|
+
Layer.mergeAll(http.layer, Retry.serverRetryHintCapLayer(1_500)),
|
|
334
|
+
);
|
|
335
|
+
expect(delays(http.times())).toEqual([1_500]);
|
|
336
|
+
});
|
|
337
|
+
|
|
338
|
+
test("DISTILLED_SERVER_RETRY_HINT_CAP_MS overrides the cap", async () => {
|
|
339
|
+
const http = scripted(failTimes(1, () => status(429, { "retry-after": "600" })));
|
|
340
|
+
await runVirtual(
|
|
341
|
+
getThing({}),
|
|
342
|
+
Layer.mergeAll(http.layer, env({ DISTILLED_SERVER_RETRY_HINT_CAP_MS: "2500" })),
|
|
343
|
+
);
|
|
344
|
+
expect(delays(http.times())).toEqual([2_500]);
|
|
345
|
+
});
|
|
346
|
+
|
|
347
|
+
test("an invalid DISTILLED_SERVER_RETRY_HINT_CAP_MS falls back to the default cap", async () => {
|
|
348
|
+
for (const raw of ["-1", "soon", "Infinity", ""]) {
|
|
349
|
+
const http = scripted(failTimes(1, () => status(429, { "retry-after": "600" })));
|
|
350
|
+
await runVirtual(
|
|
351
|
+
getThing({}),
|
|
352
|
+
Layer.mergeAll(http.layer, env({ DISTILLED_SERVER_RETRY_HINT_CAP_MS: raw })),
|
|
353
|
+
);
|
|
354
|
+
expect(delays(http.times())).toEqual([60_000]);
|
|
355
|
+
}
|
|
356
|
+
});
|
|
357
|
+
|
|
358
|
+
test("DISTILLED_SERVER_RETRY_HINT_CAP_MS is truncated to whole milliseconds", async () => {
|
|
359
|
+
const http = scripted(failTimes(1, () => status(429, { "retry-after": "600" })));
|
|
360
|
+
await runVirtual(
|
|
361
|
+
getThing({}),
|
|
362
|
+
Layer.mergeAll(http.layer, env({ DISTILLED_SERVER_RETRY_HINT_CAP_MS: "1234.9" })),
|
|
363
|
+
);
|
|
364
|
+
expect(delays(http.times())).toEqual([1_234]);
|
|
365
|
+
});
|
|
366
|
+
|
|
367
|
+
test("the layer cap wins over the environment cap", async () => {
|
|
368
|
+
const http = scripted(failTimes(1, () => status(429, { "retry-after": "600" })));
|
|
369
|
+
await runVirtual(
|
|
370
|
+
getThing({}),
|
|
371
|
+
Layer.mergeAll(
|
|
372
|
+
http.layer,
|
|
373
|
+
Retry.serverRetryHintCapLayer(1_000),
|
|
374
|
+
env({ DISTILLED_SERVER_RETRY_HINT_CAP_MS: "2500" }),
|
|
375
|
+
),
|
|
376
|
+
);
|
|
377
|
+
expect(delays(http.times())).toEqual([1_000]);
|
|
378
|
+
});
|
|
379
|
+
|
|
380
|
+
test("an invalid layer cap falls back to the environment cap", async () => {
|
|
381
|
+
const http = scripted(failTimes(1, () => status(429, { "retry-after": "600" })));
|
|
382
|
+
await runVirtual(
|
|
383
|
+
getThing({}),
|
|
384
|
+
Layer.mergeAll(
|
|
385
|
+
http.layer,
|
|
386
|
+
Retry.serverRetryHintCapLayer(-1),
|
|
387
|
+
env({ DISTILLED_SERVER_RETRY_HINT_CAP_MS: "2500" }),
|
|
388
|
+
),
|
|
389
|
+
);
|
|
390
|
+
expect(delays(http.times())).toEqual([2_500]);
|
|
391
|
+
});
|
|
392
|
+
|
|
393
|
+
test("factory policies honor hints; static Options policies cannot", async () => {
|
|
394
|
+
const factory = scripted(failTimes(1, () => status(429, { "retry-after": "3" })));
|
|
395
|
+
await runVirtual(getThing({}).pipe(withPolicy(Retry.throttlingFactory)), factory.layer);
|
|
396
|
+
expect(delays(factory.times())).toEqual([3_000]);
|
|
397
|
+
|
|
398
|
+
const options = scripted(failTimes(1, () => status(429, { "retry-after": "3" })));
|
|
399
|
+
await runVirtual(getThing({}).pipe(withPolicy(Retry.throttlingOptions)), options.layer);
|
|
400
|
+
expect(delays(options.times())).toEqual([1_000]);
|
|
401
|
+
});
|
|
402
|
+
});
|
|
403
|
+
|
|
404
|
+
describe("readServerRetryHintCapMsFromEnv", () => {
|
|
405
|
+
test("returns the default cap when the variable is unset", () => {
|
|
406
|
+
expect(process.env.DISTILLED_SERVER_RETRY_HINT_CAP_MS).toBeUndefined();
|
|
407
|
+
expect(Retry.readServerRetryHintCapMsFromEnv()).toBe(Retry.DEFAULT_SERVER_RETRY_HINT_CAP_MS);
|
|
408
|
+
});
|
|
409
|
+
});
|
|
410
|
+
|
|
411
|
+
// =============================================================================
|
|
412
|
+
// Other built-in policies
|
|
413
|
+
// =============================================================================
|
|
414
|
+
|
|
415
|
+
describe("throttling and transient policies", () => {
|
|
416
|
+
test("transient policies back off from 1s, cap at 5s, and keep retrying past 8 attempts", async () => {
|
|
417
|
+
for (const policy of [Retry.transientFactory, Retry.transientOptions]) {
|
|
418
|
+
const http = scripted(failTimes(10, () => status(502)));
|
|
419
|
+
const result = await runVirtual(getThing({}).pipe(withPolicy(policy)), http.layer);
|
|
420
|
+
expect(result._tag).toBe("Success");
|
|
421
|
+
expect(delays(http.times())).toEqual([
|
|
422
|
+
1000, 2000, 4000, 5000, 5000, 5000, 5000, 5000, 5000, 5000,
|
|
423
|
+
]);
|
|
424
|
+
}
|
|
425
|
+
});
|
|
426
|
+
|
|
427
|
+
test("throttling policies do not retry server errors", async () => {
|
|
428
|
+
const http = scripted(() => status(503));
|
|
429
|
+
const result = await runVirtual(
|
|
430
|
+
getThing({}).pipe(withPolicy(Retry.throttlingFactory)),
|
|
431
|
+
http.layer,
|
|
432
|
+
);
|
|
433
|
+
expect(result.failure).toBeInstanceOf(ServiceUnavailable);
|
|
434
|
+
expect(http.attempts).toHaveLength(1);
|
|
435
|
+
});
|
|
436
|
+
});
|
|
437
|
+
|
|
438
|
+
describe("schedule helpers", () => {
|
|
439
|
+
const delaysOf = async (schedule: Schedule.Schedule<unknown>, failures: number) => {
|
|
440
|
+
const http = scripted(failTimes(failures, () => status(503)));
|
|
441
|
+
await runVirtual(getThing({}).pipe(withPolicy({ while: () => true, schedule })), http.layer);
|
|
442
|
+
return delays(http.times());
|
|
443
|
+
};
|
|
444
|
+
|
|
445
|
+
test("capped clamps each delay to the maximum", async () => {
|
|
446
|
+
expect(
|
|
447
|
+
await delaysOf(Schedule.exponential(1000, 3).pipe(Retry.capped(Duration.seconds(2))), 3),
|
|
448
|
+
).toEqual([1000, 2000, 2000]);
|
|
449
|
+
});
|
|
450
|
+
|
|
451
|
+
test("jittered adds Math.random() * 50ms", async () => {
|
|
452
|
+
vi.spyOn(Math, "random").mockReturnValue(0.2);
|
|
453
|
+
expect(await delaysOf(Schedule.spaced(100).pipe(Retry.jittered), 2)).toEqual([110, 110]);
|
|
454
|
+
});
|
|
455
|
+
});
|
|
456
|
+
|
|
457
|
+
// =============================================================================
|
|
458
|
+
// Policy resolution from context
|
|
459
|
+
// =============================================================================
|
|
460
|
+
|
|
461
|
+
describe("retry policy resolution", () => {
|
|
462
|
+
test("operations without a retry tag never retry", async () => {
|
|
463
|
+
const http = scripted(() => status(503));
|
|
464
|
+
await runVirtual(getThingWithoutRetry({}).pipe(withPolicy(Retry.transientOptions)), http.layer);
|
|
465
|
+
expect(http.attempts).toHaveLength(1);
|
|
466
|
+
});
|
|
467
|
+
|
|
468
|
+
test("with no policy in context the default policy applies", async () => {
|
|
469
|
+
const http = scripted(failTimes(1, () => status(503)));
|
|
470
|
+
const result = await runVirtual(getThing({}), http.layer);
|
|
471
|
+
expect(result._tag).toBe("Success");
|
|
472
|
+
expect(http.attempts).toHaveLength(2);
|
|
473
|
+
});
|
|
474
|
+
|
|
475
|
+
test("a policy that never retries disables the default", async () => {
|
|
476
|
+
const http = scripted(() => status(503));
|
|
477
|
+
await runVirtual(getThing({}).pipe(withPolicy(none)), http.layer);
|
|
478
|
+
expect(http.attempts).toHaveLength(1);
|
|
479
|
+
});
|
|
480
|
+
|
|
481
|
+
test("a policy without `while` disables retrying", async () => {
|
|
482
|
+
const http = scripted(() => status(503));
|
|
483
|
+
await runVirtual(getThing({}).pipe(withPolicy({ schedule: Schedule.recurs(5) })), http.layer);
|
|
484
|
+
expect(http.attempts).toHaveLength(1);
|
|
485
|
+
});
|
|
486
|
+
|
|
487
|
+
test("a policy without a schedule retries immediately while its predicate holds", async () => {
|
|
488
|
+
const http = scripted(failTimes(3, () => status(400)));
|
|
489
|
+
const result = await runVirtual(
|
|
490
|
+
getThing({}).pipe(withPolicy({ while: (e) => e instanceof BadRequest })),
|
|
491
|
+
http.layer,
|
|
492
|
+
);
|
|
493
|
+
expect(result._tag).toBe("Success");
|
|
494
|
+
expect(http.times()).toEqual([0, 0, 0, 0]);
|
|
495
|
+
});
|
|
496
|
+
|
|
497
|
+
test("a custom schedule bounds the attempts", async () => {
|
|
498
|
+
const http = scripted(() => status(503));
|
|
499
|
+
await runVirtual(
|
|
500
|
+
getThing({}).pipe(withPolicy({ while: () => true, schedule: Schedule.recurs(2) })),
|
|
501
|
+
http.layer,
|
|
502
|
+
);
|
|
503
|
+
expect(http.attempts).toHaveLength(3);
|
|
504
|
+
});
|
|
505
|
+
|
|
506
|
+
test("factory policies get a ref holding the latest failure", async () => {
|
|
507
|
+
const seen: Array<unknown> = [];
|
|
508
|
+
const factory: Retry.Factory = (lastError) => ({
|
|
509
|
+
while: () => true,
|
|
510
|
+
schedule: Schedule.recurs(2).pipe(
|
|
511
|
+
Schedule.tap(() =>
|
|
512
|
+
Effect.flatMap(Ref.get(lastError), (e) => Effect.sync(() => seen.push(e))),
|
|
513
|
+
),
|
|
514
|
+
),
|
|
515
|
+
});
|
|
516
|
+
let n = 0;
|
|
517
|
+
const http = scripted(() => status([500, 502, 503][n++]!));
|
|
518
|
+
const result = await runVirtual(getThing({}).pipe(withPolicy(factory)), http.layer);
|
|
519
|
+
// One schedule step per retry decision, each seeing the failure it retries.
|
|
520
|
+
expect(seen.map((e) => (e as { _tag: string })._tag)).toEqual([
|
|
521
|
+
"InternalServerError",
|
|
522
|
+
"BadGateway",
|
|
523
|
+
]);
|
|
524
|
+
expect(result.failure).toBeInstanceOf(ServiceUnavailable);
|
|
525
|
+
});
|
|
526
|
+
|
|
527
|
+
test("an outer policy applies to every call beneath it", async () => {
|
|
528
|
+
const http = scripted(() => status(503));
|
|
529
|
+
await runVirtual(
|
|
530
|
+
Effect.all([Effect.result(getThing({})), Effect.result(createThing({}))]).pipe(
|
|
531
|
+
withPolicy(none),
|
|
532
|
+
),
|
|
533
|
+
http.layer,
|
|
534
|
+
);
|
|
535
|
+
expect(http.attempts.map((a) => a.method)).toEqual(["GET", "POST"]);
|
|
536
|
+
});
|
|
537
|
+
|
|
538
|
+
test("an inner policy overrides the outer one for its own subtree only", async () => {
|
|
539
|
+
const http = scripted(() => status(503));
|
|
540
|
+
const inner = getThing({}).pipe(withPolicy(none));
|
|
541
|
+
const sibling = createThing({});
|
|
542
|
+
await runVirtual(
|
|
543
|
+
Effect.all([Effect.result(inner), Effect.result(sibling)]).pipe(
|
|
544
|
+
withPolicy({ while: () => true, schedule: Schedule.recurs(2) }),
|
|
545
|
+
),
|
|
546
|
+
http.layer,
|
|
547
|
+
);
|
|
548
|
+
expect(http.attempts.map((a) => a.method)).toEqual(["GET", "POST", "POST", "POST"]);
|
|
549
|
+
});
|
|
550
|
+
|
|
551
|
+
test("a policy under another SDK's tag does not apply", async () => {
|
|
552
|
+
const http = scripted(failTimes(1, () => status(503)));
|
|
553
|
+
const result = await runVirtual(
|
|
554
|
+
getThing({}).pipe(Effect.provideService(OtherRetry, none)),
|
|
555
|
+
http.layer,
|
|
556
|
+
);
|
|
557
|
+
expect(result._tag).toBe("Success");
|
|
558
|
+
expect(http.attempts).toHaveLength(2);
|
|
559
|
+
});
|
|
560
|
+
|
|
561
|
+
test("a policy installed as a layer applies like provideService", async () => {
|
|
562
|
+
const http = scripted(() => status(503));
|
|
563
|
+
await runVirtual(getThing({}), Layer.mergeAll(http.layer, Layer.succeed(TestRetry, none)));
|
|
564
|
+
expect(http.attempts).toHaveLength(1);
|
|
565
|
+
});
|
|
566
|
+
});
|
package/src/retry.ts
CHANGED
|
@@ -63,8 +63,7 @@ export type Policy = Options | Factory;
|
|
|
63
63
|
* export class Retry extends makeRetryService("PlanetScaleRetry") {}
|
|
64
64
|
* ```
|
|
65
65
|
*/
|
|
66
|
-
export const makeRetryService = (name: string) =>
|
|
67
|
-
Context.Service<any, Policy>()(name);
|
|
66
|
+
export const makeRetryService = (name: string) => Context.Service<any, Policy>()(name);
|
|
68
67
|
|
|
69
68
|
// ============================================================================
|
|
70
69
|
// Retry Schedule Utilities
|
|
@@ -143,9 +142,7 @@ const serverRetryHintCapMsConfig: Config.Config<number> = Config.String(
|
|
|
143
142
|
*/
|
|
144
143
|
export const readServerRetryHintCapMsFromEnv = (): number =>
|
|
145
144
|
Effect.runSync(
|
|
146
|
-
serverRetryHintCapMsConfig.pipe(
|
|
147
|
-
Effect.orElseSucceed(() => DEFAULT_SERVER_RETRY_HINT_CAP_MS),
|
|
148
|
-
),
|
|
145
|
+
serverRetryHintCapMsConfig.pipe(Effect.orElseSucceed(() => DEFAULT_SERVER_RETRY_HINT_CAP_MS)),
|
|
149
146
|
);
|
|
150
147
|
|
|
151
148
|
const resolveServerRetryHintCapMs = (): Effect.Effect<number, never, never> =>
|
|
@@ -167,12 +164,8 @@ const resolveServerRetryHintCapMs = (): Effect.Effect<number, never, never> =>
|
|
|
167
164
|
*
|
|
168
165
|
* Returns `undefined` when the error doesn't carry a hint.
|
|
169
166
|
*/
|
|
170
|
-
const serverHintMillis = (
|
|
171
|
-
error
|
|
172
|
-
capMs: number,
|
|
173
|
-
): number | undefined => {
|
|
174
|
-
const hint = (error as { retryAfter?: unknown } | null | undefined)
|
|
175
|
-
?.retryAfter;
|
|
167
|
+
const serverHintMillis = (error: unknown, capMs: number): number | undefined => {
|
|
168
|
+
const hint = (error as { retryAfter?: unknown } | null | undefined)?.retryAfter;
|
|
176
169
|
if (!Duration.isDuration(hint)) return undefined;
|
|
177
170
|
return Math.min(Duration.toMillis(hint), capMs);
|
|
178
171
|
};
|
|
@@ -266,11 +259,7 @@ export const throttlingFactory: Factory = (lastError) => ({
|
|
|
266
259
|
*/
|
|
267
260
|
export const throttlingOptions: Options = {
|
|
268
261
|
while: (error) => isThrottling(error),
|
|
269
|
-
schedule: pipe(
|
|
270
|
-
Schedule.exponential(1000, 2),
|
|
271
|
-
capped(Duration.seconds(5)),
|
|
272
|
-
jittered,
|
|
273
|
-
),
|
|
262
|
+
schedule: pipe(Schedule.exponential(1000, 2), capped(Duration.seconds(5)), jittered),
|
|
274
263
|
};
|
|
275
264
|
|
|
276
265
|
/**
|
|
@@ -300,9 +289,5 @@ export const transientFactory: Factory = (lastError) => ({
|
|
|
300
289
|
*/
|
|
301
290
|
export const transientOptions: Options = {
|
|
302
291
|
while: isTransientError,
|
|
303
|
-
schedule: pipe(
|
|
304
|
-
Schedule.exponential(1000, 2),
|
|
305
|
-
capped(Duration.seconds(5)),
|
|
306
|
-
jittered,
|
|
307
|
-
),
|
|
292
|
+
schedule: pipe(Schedule.exponential(1000, 2), capped(Duration.seconds(5)), jittered),
|
|
308
293
|
};
|