@distilled.cloud/core 1.0.0-rc.15 → 1.0.0-rc.16
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 +118 -13
- package/lib/api.d.ts.map +1 -1
- package/lib/api.js +755 -147
- package/lib/api.js.map +1 -1
- package/lib/category.d.ts.map +1 -1
- package/lib/category.js +146 -146
- package/lib/category.js.map +1 -1
- package/lib/chunks.d.ts +3 -0
- package/lib/chunks.d.ts.map +1 -0
- package/lib/chunks.js +11 -0
- package/lib/chunks.js.map +1 -0
- package/lib/codegen/boolean-string-enums.js +36 -36
- package/lib/codegen/chunk.d.ts +7 -0
- package/lib/codegen/chunk.d.ts.map +1 -0
- package/lib/codegen/chunk.js +139 -0
- package/lib/codegen/chunk.js.map +1 -0
- package/lib/codegen/cli.d.ts.map +1 -1
- package/lib/codegen/cli.js +28 -14
- package/lib/codegen/cli.js.map +1 -1
- package/lib/codegen/datafy.d.ts +14 -0
- package/lib/codegen/datafy.d.ts.map +1 -0
- package/lib/codegen/datafy.js +853 -0
- package/lib/codegen/datafy.js.map +1 -0
- package/lib/codegen/dedupe.d.ts +5 -0
- package/lib/codegen/dedupe.d.ts.map +1 -0
- package/lib/codegen/dedupe.js +153 -0
- package/lib/codegen/dedupe.js.map +1 -0
- package/lib/codegen/emit.js +56 -56
- package/lib/codegen/format.js +18 -18
- package/lib/codegen/generated-at.js +29 -29
- package/lib/codegen/generator.d.ts.map +1 -1
- package/lib/codegen/generator.js +92 -84
- package/lib/codegen/generator.js.map +1 -1
- package/lib/codegen/graph.js +36 -36
- package/lib/codegen/graphql-client.d.ts +2 -0
- package/lib/codegen/graphql-client.d.ts.map +1 -1
- package/lib/codegen/graphql-client.js +55 -26
- package/lib/codegen/graphql-client.js.map +1 -1
- package/lib/codegen/graphql.js +113 -113
- package/lib/codegen/latin1.d.ts +3 -0
- package/lib/codegen/latin1.d.ts.map +1 -0
- package/lib/codegen/latin1.js +126 -0
- package/lib/codegen/latin1.js.map +1 -0
- package/lib/codegen/members.d.ts +7 -0
- package/lib/codegen/members.d.ts.map +1 -1
- package/lib/codegen/members.js +26 -19
- package/lib/codegen/members.js.map +1 -1
- package/lib/codegen/model-diff.js +6 -6
- package/lib/codegen/naming.js +19 -19
- package/lib/codegen/openapi-cli.js +15 -15
- package/lib/codegen/openapi.d.ts +17 -0
- package/lib/codegen/openapi.d.ts.map +1 -1
- package/lib/codegen/openapi.js +323 -169
- package/lib/codegen/openapi.js.map +1 -1
- package/lib/codegen/operations.js +14 -14
- package/lib/codegen/pagination.js +11 -11
- package/lib/codegen/patch-audit.js +57 -57
- package/lib/codegen/patches.js +79 -79
- package/lib/codegen/prelude.js +19 -19
- package/lib/codegen/privatize.d.ts +21 -0
- package/lib/codegen/privatize.d.ts.map +1 -0
- package/lib/codegen/privatize.js +176 -0
- package/lib/codegen/privatize.js.map +1 -0
- package/lib/codegen/proto.js +25 -25
- package/lib/codegen/pure.d.ts +6 -0
- package/lib/codegen/pure.d.ts.map +1 -0
- package/lib/codegen/pure.js +91 -0
- package/lib/codegen/pure.js.map +1 -0
- package/lib/codegen/rewrite-operation-ids.js +108 -108
- package/lib/codegen/spec-path.js +57 -57
- package/lib/codegen/table.d.ts +5 -0
- package/lib/codegen/table.d.ts.map +1 -0
- package/lib/codegen/table.js +249 -0
- package/lib/codegen/table.js.map +1 -0
- package/lib/config.d.ts +27 -0
- package/lib/config.d.ts.map +1 -0
- package/lib/config.js +161 -0
- package/lib/config.js.map +1 -0
- package/lib/crypto.d.ts +76 -0
- package/lib/crypto.d.ts.map +1 -0
- package/lib/crypto.js +130 -0
- package/lib/crypto.js.map +1 -0
- package/lib/debug.d.ts +2 -0
- package/lib/debug.d.ts.map +1 -0
- package/lib/debug.js +8 -0
- package/lib/debug.js.map +1 -0
- package/lib/error-category.d.ts +1 -1
- package/lib/error-category.d.ts.map +1 -1
- package/lib/error-category.js +7 -6
- package/lib/error-category.js.map +1 -1
- package/lib/errors.d.ts +62 -62
- package/lib/errors.d.ts.map +1 -1
- package/lib/errors.js +117 -114
- package/lib/errors.js.map +1 -1
- package/lib/graphql.d.ts +31 -20
- package/lib/graphql.d.ts.map +1 -1
- package/lib/graphql.js +150 -119
- package/lib/graphql.js.map +1 -1
- package/lib/graphql.types.js +4 -3
- package/lib/graphql.types.js.map +1 -1
- package/lib/index.d.ts +3 -2
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +15 -14
- package/lib/index.js.map +1 -1
- package/lib/json-patch.d.ts +2 -2
- package/lib/json-patch.js +28 -28
- package/lib/pagination.d.ts +9 -25
- package/lib/pagination.d.ts.map +1 -1
- package/lib/pagination.js +95 -90
- package/lib/pagination.js.map +1 -1
- package/lib/plain-values.d.ts +10 -0
- package/lib/plain-values.d.ts.map +1 -0
- package/lib/plain-values.js +40 -0
- package/lib/plain-values.js.map +1 -0
- package/lib/protocol-http.d.ts +50 -14
- package/lib/protocol-http.d.ts.map +1 -1
- package/lib/protocol-http.js +351 -178
- package/lib/protocol-http.js.map +1 -1
- package/lib/protocol-rest.d.ts +38 -25
- package/lib/protocol-rest.d.ts.map +1 -1
- package/lib/protocol-rest.js +238 -130
- package/lib/protocol-rest.js.map +1 -1
- package/lib/query.js +16 -16
- package/lib/response-validation-strict.d.ts +48 -0
- package/lib/response-validation-strict.d.ts.map +1 -0
- package/lib/response-validation-strict.js +284 -0
- package/lib/response-validation-strict.js.map +1 -0
- package/lib/response-validation.d.ts +43 -25
- package/lib/response-validation.d.ts.map +1 -1
- package/lib/response-validation.js +112 -70
- package/lib/response-validation.js.map +1 -1
- package/lib/retry-after.d.ts +3 -3
- package/lib/retry-after.js +49 -49
- package/lib/retry.d.ts +48 -29
- package/lib/retry.d.ts.map +1 -1
- package/lib/retry.js +142 -154
- package/lib/retry.js.map +1 -1
- package/lib/schema-lite-impl.d.ts +158 -0
- package/lib/schema-lite-impl.d.ts.map +1 -0
- package/lib/schema-lite-impl.js +341 -0
- package/lib/schema-lite-impl.js.map +1 -0
- package/lib/schema-lite-typed.d.ts +41 -0
- package/lib/schema-lite-typed.d.ts.map +1 -0
- package/lib/schema-lite-typed.js +27 -0
- package/lib/schema-lite-typed.js.map +1 -0
- package/lib/schema-lite.d.ts +40 -0
- package/lib/schema-lite.d.ts.map +1 -0
- package/lib/schema-lite.js +31 -0
- package/lib/schema-lite.js.map +1 -0
- package/lib/schema.d.ts +20 -6
- package/lib/schema.d.ts.map +1 -1
- package/lib/schema.js +202 -30
- package/lib/schema.js.map +1 -1
- package/lib/testing.d.ts +3 -2
- package/lib/testing.d.ts.map +1 -1
- package/lib/testing.js +22 -21
- package/lib/testing.js.map +1 -1
- package/lib/trait.d.ts +13 -13
- package/lib/trait.d.ts.map +1 -1
- package/lib/trait.js +80 -80
- package/lib/trait.js.map +1 -1
- package/lib/xml.d.ts +1 -1
- package/lib/xml.d.ts.map +1 -1
- package/lib/xml.js +38 -26
- package/lib/xml.js.map +1 -1
- package/package.json +9 -7
- package/src/api.ts +1079 -180
- package/src/category.ts +33 -33
- package/src/chunks.ts +30 -0
- package/src/codegen/chunk.ts +147 -0
- package/src/codegen/cli.ts +27 -1
- package/src/codegen/datafy.ts +874 -0
- package/src/codegen/dedupe.ts +173 -0
- package/src/codegen/generator.ts +10 -3
- package/src/codegen/graphql-client.ts +49 -15
- package/src/codegen/latin1.ts +131 -0
- package/src/codegen/members.ts +8 -0
- package/src/codegen/openapi.ts +194 -3
- package/src/codegen/privatize.ts +200 -0
- package/src/codegen/pure.ts +94 -0
- package/src/codegen/table.ts +254 -0
- package/src/config.ts +216 -0
- package/src/crypto.ts +202 -0
- package/src/debug.ts +8 -0
- package/src/error-category.ts +2 -1
- package/src/errors.ts +65 -56
- package/src/graphql.ts +109 -62
- package/src/graphql.types.ts +9 -7
- package/src/index.ts +3 -2
- package/src/json-patch.ts +2 -2
- package/src/pagination.ts +37 -18
- package/src/plain-values.ts +41 -0
- package/src/protocol-http.ts +378 -145
- package/src/protocol-rest.ts +337 -169
- package/src/response-validation-strict.ts +327 -0
- package/src/response-validation.ts +101 -50
- package/src/retry-after.ts +3 -3
- package/src/retry.ts +94 -93
- package/src/schema-lite-impl.ts +550 -0
- package/src/schema-lite-typed.ts +44 -0
- package/src/schema-lite.ts +44 -0
- package/src/schema.ts +258 -14
- package/src/testing.ts +4 -2
- package/src/trait.ts +36 -28
- package/src/xml.ts +31 -17
- package/lib/codegen/boolean-string-enums.test.d.ts +0 -2
- package/lib/codegen/boolean-string-enums.test.d.ts.map +0 -1
- package/lib/codegen/boolean-string-enums.test.js +0 -275
- package/lib/codegen/boolean-string-enums.test.js.map +0 -1
- package/lib/codegen/defer-naming.test.d.ts +0 -2
- package/lib/codegen/defer-naming.test.d.ts.map +0 -1
- package/lib/codegen/defer-naming.test.js +0 -105
- package/lib/codegen/defer-naming.test.js.map +0 -1
- package/lib/codegen/generated-at.test.d.ts +0 -2
- package/lib/codegen/generated-at.test.d.ts.map +0 -1
- package/lib/codegen/generated-at.test.js +0 -81
- package/lib/codegen/generated-at.test.js.map +0 -1
- package/lib/codegen/generator.test.d.ts +0 -2
- package/lib/codegen/generator.test.d.ts.map +0 -1
- package/lib/codegen/generator.test.js +0 -121
- package/lib/codegen/generator.test.js.map +0 -1
- package/lib/codegen/graphql-client.test.d.ts +0 -2
- package/lib/codegen/graphql-client.test.d.ts.map +0 -1
- package/lib/codegen/graphql-client.test.js +0 -171
- package/lib/codegen/graphql-client.test.js.map +0 -1
- package/lib/codegen/openapi-binary.test.d.ts +0 -2
- package/lib/codegen/openapi-binary.test.d.ts.map +0 -1
- package/lib/codegen/openapi-binary.test.js +0 -67
- package/lib/codegen/openapi-binary.test.js.map +0 -1
- package/lib/codegen/patch-audit.test.d.ts +0 -2
- package/lib/codegen/patch-audit.test.d.ts.map +0 -1
- package/lib/codegen/patch-audit.test.js +0 -141
- package/lib/codegen/patch-audit.test.js.map +0 -1
- package/lib/codegen/patches.test.d.ts +0 -2
- package/lib/codegen/patches.test.d.ts.map +0 -1
- package/lib/codegen/patches.test.js +0 -155
- package/lib/codegen/patches.test.js.map +0 -1
- package/lib/codegen/protocol-imports.test.d.ts +0 -2
- package/lib/codegen/protocol-imports.test.d.ts.map +0 -1
- package/lib/codegen/protocol-imports.test.js +0 -36
- package/lib/codegen/protocol-imports.test.js.map +0 -1
- package/lib/codegen/rewrite-operation-ids.test.d.ts +0 -2
- package/lib/codegen/rewrite-operation-ids.test.d.ts.map +0 -1
- package/lib/codegen/rewrite-operation-ids.test.js +0 -451
- package/lib/codegen/rewrite-operation-ids.test.js.map +0 -1
- package/lib/codegen/untagged-unions.test.d.ts +0 -2
- package/lib/codegen/untagged-unions.test.d.ts.map +0 -1
- package/lib/codegen/untagged-unions.test.js +0 -80
- package/lib/codegen/untagged-unions.test.js.map +0 -1
- package/lib/fixtures/xml/upstream-validator.json +0 -397
- package/lib/graphql.test.d.ts +0 -2
- package/lib/graphql.test.d.ts.map +0 -1
- package/lib/graphql.test.js +0 -151
- package/lib/graphql.test.js.map +0 -1
- package/lib/json-patch.test.d.ts +0 -2
- package/lib/json-patch.test.d.ts.map +0 -1
- package/lib/json-patch.test.js +0 -65
- package/lib/json-patch.test.js.map +0 -1
- package/lib/pagination.test.d.ts +0 -2
- package/lib/pagination.test.d.ts.map +0 -1
- package/lib/pagination.test.js +0 -131
- package/lib/pagination.test.js.map +0 -1
- package/lib/protocol-http.test.d.ts +0 -2
- package/lib/protocol-http.test.d.ts.map +0 -1
- package/lib/protocol-http.test.js +0 -228
- package/lib/protocol-http.test.js.map +0 -1
- package/lib/protocol-rest.test.d.ts +0 -2
- package/lib/protocol-rest.test.d.ts.map +0 -1
- package/lib/protocol-rest.test.js +0 -498
- package/lib/protocol-rest.test.js.map +0 -1
- package/lib/response-validation.test.d.ts +0 -2
- package/lib/response-validation.test.d.ts.map +0 -1
- package/lib/response-validation.test.js +0 -72
- package/lib/response-validation.test.js.map +0 -1
- package/lib/retry-after.test.d.ts +0 -2
- package/lib/retry-after.test.d.ts.map +0 -1
- package/lib/retry-after.test.js +0 -204
- package/lib/retry-after.test.js.map +0 -1
- package/lib/retry.test.d.ts +0 -2
- package/lib/retry.test.d.ts.map +0 -1
- package/lib/retry.test.js +0 -407
- package/lib/retry.test.js.map +0 -1
- package/lib/sdks.test.d.ts +0 -2
- package/lib/sdks.test.d.ts.map +0 -1
- package/lib/sdks.test.js +0 -76
- package/lib/sdks.test.js.map +0 -1
- package/lib/xml.test.d.ts +0 -2
- package/lib/xml.test.d.ts.map +0 -1
- package/lib/xml.test.js +0 -210
- package/lib/xml.test.js.map +0 -1
- package/src/codegen/boolean-string-enums.test.ts +0 -299
- package/src/codegen/defer-naming.test.ts +0 -113
- package/src/codegen/generated-at.test.ts +0 -89
- package/src/codegen/generator.test.ts +0 -137
- package/src/codegen/graphql-client.test.ts +0 -189
- package/src/codegen/openapi-binary.test.ts +0 -91
- package/src/codegen/patch-audit.test.ts +0 -160
- package/src/codegen/patches.test.ts +0 -188
- package/src/codegen/protocol-imports.test.ts +0 -39
- package/src/codegen/rewrite-operation-ids.test.ts +0 -472
- package/src/codegen/untagged-unions.test.ts +0 -85
- package/src/fixtures/xml/upstream-validator.json +0 -397
- package/src/graphql.test.ts +0 -198
- package/src/json-patch.test.ts +0 -77
- package/src/pagination.test.ts +0 -169
- package/src/protocol-http.test.ts +0 -276
- package/src/protocol-rest.test.ts +0 -703
- package/src/response-validation.test.ts +0 -89
- package/src/retry-after.test.ts +0 -267
- package/src/retry.test.ts +0 -566
- package/src/sdks.test.ts +0 -87
- package/src/xml.test.ts +0 -251
package/src/retry.ts
CHANGED
|
@@ -7,7 +7,6 @@
|
|
|
7
7
|
* so that callers can install a blanket retry policy at the layer level
|
|
8
8
|
* for that SDK without wrapping every call with `Effect.retry`.
|
|
9
9
|
*/
|
|
10
|
-
import * as Config from "effect/Config";
|
|
11
10
|
import * as Context from "effect/Context";
|
|
12
11
|
import * as Duration from "effect/Duration";
|
|
13
12
|
import * as Effect from "effect/Effect";
|
|
@@ -25,6 +24,27 @@ import { isThrottling, isTransientError } from "./category.ts";
|
|
|
25
24
|
/**
|
|
26
25
|
* Retry policy options that match the Effect.retry contract.
|
|
27
26
|
*/
|
|
27
|
+
/**
|
|
28
|
+
* Capped exponential backoff, as plain data: the built-in policies use this
|
|
29
|
+
* instead of an Effect `Schedule`, so bundles do not carry the Schedule
|
|
30
|
+
* machinery unless a caller supplies a schedule of their own.
|
|
31
|
+
*
|
|
32
|
+
* Delay before retry `n` (0-based): `min(baseMs * factor^n, capMs)`; a
|
|
33
|
+
* server `retryAfter` hint replaces it when `serverHint` is set (capped by
|
|
34
|
+
* {@link ServerRetryHintCapMs}); otherwise throttling errors wait at least
|
|
35
|
+
* `minThrottleMs`. Then up to `jitterMs` of random jitter is added.
|
|
36
|
+
*/
|
|
37
|
+
export interface Backoff {
|
|
38
|
+
readonly baseMs: number;
|
|
39
|
+
readonly factor: number;
|
|
40
|
+
readonly capMs: number;
|
|
41
|
+
/** Stop after this many retries; unlimited when absent. */
|
|
42
|
+
readonly maxRetries?: number;
|
|
43
|
+
readonly jitterMs?: number;
|
|
44
|
+
readonly minThrottleMs?: number;
|
|
45
|
+
readonly serverHint?: boolean;
|
|
46
|
+
}
|
|
47
|
+
|
|
28
48
|
export interface Options {
|
|
29
49
|
/**
|
|
30
50
|
* Predicate to determine if an error should trigger a retry.
|
|
@@ -34,6 +54,8 @@ export interface Options {
|
|
|
34
54
|
* The schedule to use for retrying.
|
|
35
55
|
*/
|
|
36
56
|
readonly schedule?: Schedule.Schedule<unknown>;
|
|
57
|
+
/** Used when no `schedule` is given. */
|
|
58
|
+
readonly backoff?: Backoff;
|
|
37
59
|
}
|
|
38
60
|
|
|
39
61
|
/**
|
|
@@ -73,7 +95,7 @@ export const makeRetryService = (name: string) => Context.Service<any, Policy>()
|
|
|
73
95
|
* Custom jittered schedule helper.
|
|
74
96
|
* Adds random jitter between 0-50ms to avoid thundering herd.
|
|
75
97
|
*/
|
|
76
|
-
export const jittered = Schedule.addDelay(() =>
|
|
98
|
+
export const jittered = /*@__PURE__*/ Schedule.addDelay(() =>
|
|
77
99
|
Effect.succeed(Duration.millis(Math.random() * 50)),
|
|
78
100
|
);
|
|
79
101
|
|
|
@@ -110,7 +132,7 @@ const ENV_SERVER_RETRY_HINT_CAP_MS = "DISTILLED_SERVER_RETRY_HINT_CAP_MS";
|
|
|
110
132
|
* )
|
|
111
133
|
* ```
|
|
112
134
|
*/
|
|
113
|
-
export const ServerRetryHintCapMs = Context.Service<number>(
|
|
135
|
+
export const ServerRetryHintCapMs = /*@__PURE__*/ Context.Service<number>(
|
|
114
136
|
"@distilled.cloud/core/ServerRetryHintCapMs",
|
|
115
137
|
);
|
|
116
138
|
|
|
@@ -120,41 +142,57 @@ export const ServerRetryHintCapMs = Context.Service<number>(
|
|
|
120
142
|
export const serverRetryHintCapLayer = (capMs: number) =>
|
|
121
143
|
Layer.succeed(ServerRetryHintCapMs, capMs);
|
|
122
144
|
|
|
123
|
-
const serverRetryHintCapMsConfig: Config.Config<number> = Config.String(
|
|
124
|
-
ENV_SERVER_RETRY_HINT_CAP_MS,
|
|
125
|
-
).pipe(
|
|
126
|
-
Config.map((raw) => {
|
|
127
|
-
if (raw === "") return DEFAULT_SERVER_RETRY_HINT_CAP_MS;
|
|
128
|
-
const n = Number(raw);
|
|
129
|
-
if (!Number.isFinite(n) || n < 0) return DEFAULT_SERVER_RETRY_HINT_CAP_MS;
|
|
130
|
-
return Math.trunc(n);
|
|
131
|
-
}),
|
|
132
|
-
Config.withDefault(DEFAULT_SERVER_RETRY_HINT_CAP_MS),
|
|
133
|
-
);
|
|
134
|
-
|
|
135
145
|
/**
|
|
136
146
|
* Effective cap when neither {@link ServerRetryHintCapMs} nor
|
|
137
147
|
* `DISTILLED_SERVER_RETRY_HINT_CAP_MS` is set: {@link DEFAULT_SERVER_RETRY_HINT_CAP_MS}.
|
|
138
148
|
*
|
|
139
|
-
* Reads the `DISTILLED_SERVER_RETRY_HINT_CAP_MS` environment variable
|
|
140
|
-
*
|
|
141
|
-
*
|
|
149
|
+
* Reads the `DISTILLED_SERVER_RETRY_HINT_CAP_MS` environment variable (must
|
|
150
|
+
* be a non-negative finite number; invalid values fall back to the default).
|
|
151
|
+
* It reads `process.env` directly: Effect's `Config` would add about 5 KB
|
|
152
|
+
* gzip to every bundle for this one optional knob. Use
|
|
153
|
+
* {@link ServerRetryHintCapMs} to set the cap from code.
|
|
142
154
|
*/
|
|
143
155
|
export const readServerRetryHintCapMsFromEnv = (): number =>
|
|
144
|
-
|
|
145
|
-
|
|
156
|
+
parseCapMs(
|
|
157
|
+
(globalThis as { process?: { env?: Record<string, string | undefined> } }).process?.env?.[
|
|
158
|
+
ENV_SERVER_RETRY_HINT_CAP_MS
|
|
159
|
+
],
|
|
146
160
|
);
|
|
147
161
|
|
|
148
|
-
const
|
|
162
|
+
const parseCapMs = (raw: string | undefined): number => {
|
|
163
|
+
if (raw === undefined || raw === "") return DEFAULT_SERVER_RETRY_HINT_CAP_MS;
|
|
164
|
+
const n = Number(raw);
|
|
165
|
+
return Number.isFinite(n) && n >= 0 ? Math.trunc(n) : DEFAULT_SERVER_RETRY_HINT_CAP_MS;
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* The `ConfigProvider` the caller provided, looked up by its context key.
|
|
170
|
+
* Importing `effect/Config` / `effect/ConfigProvider` to read one optional
|
|
171
|
+
* env var would add about 5 KB gzip to every bundle; a provider object
|
|
172
|
+
* carries its own `load`, so neither module is needed.
|
|
173
|
+
*/
|
|
174
|
+
const CONFIG_PROVIDER_KEY = "effect/ConfigProvider";
|
|
175
|
+
interface ProvidedConfigProvider {
|
|
176
|
+
readonly load: (
|
|
177
|
+
path: ReadonlyArray<string>,
|
|
178
|
+
) => Effect.Effect<{ readonly _tag: string; readonly value?: string } | undefined, unknown>;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
export const resolveServerRetryHintCapMs = (): Effect.Effect<number, never, never> =>
|
|
149
182
|
Effect.gen(function* () {
|
|
150
183
|
const fromLayer = yield* Effect.serviceOption(ServerRetryHintCapMs);
|
|
151
184
|
if (Option.isSome(fromLayer)) {
|
|
152
185
|
const n = fromLayer.value;
|
|
153
186
|
if (Number.isFinite(n) && n >= 0) return Math.trunc(n);
|
|
154
187
|
}
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
188
|
+
const provider = (yield* Effect.context<never>()).mapUnsafe.get(CONFIG_PROVIDER_KEY) as
|
|
189
|
+
| ProvidedConfigProvider
|
|
190
|
+
| undefined;
|
|
191
|
+
if (!provider) return readServerRetryHintCapMsFromEnv();
|
|
192
|
+
const node = yield* provider
|
|
193
|
+
.load([ENV_SERVER_RETRY_HINT_CAP_MS])
|
|
194
|
+
.pipe(Effect.orElseSucceed(() => undefined));
|
|
195
|
+
return parseCapMs(node?._tag === "Value" ? node.value : undefined);
|
|
158
196
|
});
|
|
159
197
|
|
|
160
198
|
/**
|
|
@@ -164,7 +202,7 @@ const resolveServerRetryHintCapMs = (): Effect.Effect<number, never, never> =>
|
|
|
164
202
|
*
|
|
165
203
|
* Returns `undefined` when the error doesn't carry a hint.
|
|
166
204
|
*/
|
|
167
|
-
const serverHintMillis = (error: unknown, capMs: number): number | undefined => {
|
|
205
|
+
export const serverHintMillis = (error: unknown, capMs: number): number | undefined => {
|
|
168
206
|
const hint = (error as { retryAfter?: unknown } | null | undefined)?.retryAfter;
|
|
169
207
|
if (!Duration.isDuration(hint)) return undefined;
|
|
170
208
|
return Math.min(Duration.toMillis(hint), capMs);
|
|
@@ -214,80 +252,43 @@ const honorServerHint = (
|
|
|
214
252
|
* high request concurrency routinely outlast a short 5-attempt/3s policy
|
|
215
253
|
* while a genuinely broken credential still fails within seconds.
|
|
216
254
|
*/
|
|
217
|
-
|
|
255
|
+
/** The policy used when the context provides none. */
|
|
256
|
+
export const defaultOptions: Options = {
|
|
218
257
|
while: (error) => isTransientError(error),
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
return Duration.millis(500);
|
|
230
|
-
}
|
|
231
|
-
return duration;
|
|
232
|
-
}),
|
|
233
|
-
jittered,
|
|
234
|
-
),
|
|
235
|
-
Schedule.recurs(8),
|
|
236
|
-
]),
|
|
237
|
-
});
|
|
258
|
+
backoff: {
|
|
259
|
+
baseMs: 250,
|
|
260
|
+
factor: 2,
|
|
261
|
+
capMs: 5000,
|
|
262
|
+
maxRetries: 8,
|
|
263
|
+
jitterMs: 50,
|
|
264
|
+
minThrottleMs: 500,
|
|
265
|
+
serverHint: true,
|
|
266
|
+
},
|
|
267
|
+
};
|
|
238
268
|
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
269
|
+
export const makeDefault: Factory = () => defaultOptions;
|
|
270
|
+
|
|
271
|
+
const slowBackoff: Backoff = {
|
|
272
|
+
baseMs: 1000,
|
|
273
|
+
factor: 2,
|
|
274
|
+
capMs: 5000,
|
|
275
|
+
jitterMs: 50,
|
|
276
|
+
serverHint: true,
|
|
277
|
+
};
|
|
278
|
+
const slowBackoffNoHint: Backoff = { baseMs: 1000, factor: 2, capMs: 5000, jitterMs: 50 };
|
|
279
|
+
|
|
280
|
+
export const throttlingFactory: Factory = () => throttlingFactoryOptions;
|
|
281
|
+
const throttlingFactoryOptions: Options = {
|
|
244
282
|
while: (error) => isThrottling(error),
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
capped(Duration.seconds(5)),
|
|
248
|
-
honorServerHint(lastError),
|
|
249
|
-
jittered,
|
|
250
|
-
),
|
|
251
|
-
});
|
|
283
|
+
backoff: slowBackoff,
|
|
284
|
+
};
|
|
252
285
|
|
|
253
|
-
/**
|
|
254
|
-
* Retry options that retries all throttling errors indefinitely.
|
|
255
|
-
*
|
|
256
|
-
* Note: prefer {@link throttlingFactory} when you want server-hint honoring.
|
|
257
|
-
* This static `Options` form does not have access to `lastError` and so
|
|
258
|
-
* cannot read `error.retryAfter`.
|
|
259
|
-
*/
|
|
260
286
|
export const throttlingOptions: Options = {
|
|
261
287
|
while: (error) => isThrottling(error),
|
|
262
|
-
|
|
288
|
+
backoff: slowBackoffNoHint,
|
|
263
289
|
};
|
|
264
290
|
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
* so callers using `<SDK>.Retry.transient` get correct backoff.
|
|
268
|
-
*/
|
|
269
|
-
export const transientFactory: Factory = (lastError) => ({
|
|
270
|
-
while: isTransientError,
|
|
271
|
-
schedule: pipe(
|
|
272
|
-
Schedule.exponential(1000, 2),
|
|
273
|
-
capped(Duration.seconds(5)),
|
|
274
|
-
honorServerHint(lastError),
|
|
275
|
-
jittered,
|
|
276
|
-
),
|
|
277
|
-
});
|
|
291
|
+
export const transientFactory: Factory = () => transientFactoryOptions;
|
|
292
|
+
const transientFactoryOptions: Options = { while: isTransientError, backoff: slowBackoff };
|
|
278
293
|
|
|
279
|
-
|
|
280
|
-
* Retry options that retries all transient errors indefinitely.
|
|
281
|
-
*
|
|
282
|
-
* This includes:
|
|
283
|
-
* 1. Throttling errors
|
|
284
|
-
* 2. Server errors
|
|
285
|
-
* 3. Network errors
|
|
286
|
-
* 4. Locked errors (423)
|
|
287
|
-
*
|
|
288
|
-
* Note: prefer {@link transientFactory} when you want server-hint honoring.
|
|
289
|
-
*/
|
|
290
|
-
export const transientOptions: Options = {
|
|
291
|
-
while: isTransientError,
|
|
292
|
-
schedule: pipe(Schedule.exponential(1000, 2), capped(Duration.seconds(5)), jittered),
|
|
293
|
-
};
|
|
294
|
+
export const transientOptions: Options = { while: isTransientError, backoff: slowBackoffNoHint };
|