brass-runtime 1.16.1 → 1.18.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 +40 -8
- package/dist/agent/cli/main.cjs +31 -32
- package/dist/agent/cli/main.js +3 -4
- package/dist/agent/cli/main.mjs +3 -4
- package/dist/agent/index.cjs +4 -5
- package/dist/agent/index.d.ts +1 -1
- package/dist/agent/index.js +3 -4
- package/dist/agent/index.mjs +3 -4
- package/dist/{chunk-GYM3LLGS.mjs → chunk-2QNREG6K.mjs} +188 -5
- package/dist/{chunk-4ROBZFL6.cjs → chunk-2SLT3X6G.cjs} +6 -8
- package/dist/{chunk-KZJQ723N.cjs → chunk-3PFZGP23.cjs} +13 -15
- package/dist/{chunk-AVNQLJ5V.js → chunk-3PHU7FWS.js} +528 -23
- package/dist/{chunk-CIZFIMK5.js → chunk-4YQHPIWJ.js} +60 -11
- package/dist/chunk-5XADBMSU.cjs +33 -0
- package/dist/{chunk-DNFJLJMW.mjs → chunk-6MLAZPBL.mjs} +48 -24
- package/dist/chunk-7TKI527D.cjs +123 -0
- package/dist/{chunk-AGR5B2BC.cjs → chunk-7TXQJFZX.cjs} +564 -12
- package/dist/{chunk-RKGKFN2A.js → chunk-AADFFVYS.js} +1 -1
- package/dist/{chunk-52PPNNI4.cjs → chunk-AJMKZXRB.cjs} +2 -2
- package/dist/{chunk-3AYM6WPJ.js → chunk-BG5RNEA2.js} +20 -299
- package/dist/{chunk-2HQTDLHF.mjs → chunk-ELLF55ER.mjs} +555 -3
- package/dist/{chunk-EOC4UHBS.mjs → chunk-G5JTCFMI.mjs} +2 -2
- package/dist/chunk-H5GYX7RZ.js +6126 -0
- package/dist/{chunk-C3MDXTRZ.js → chunk-HCJ4S3YB.js} +48 -24
- package/dist/{chunk-6IXXWIUM.js → chunk-IBRHSH5H.js} +555 -3
- package/dist/{chunk-Q2I37RP3.cjs → chunk-IFRBVMWJ.cjs} +44 -323
- package/dist/{chunk-52OB2ROS.js → chunk-ITG6I7ZS.js} +2 -4
- package/dist/chunk-ITZQ526U.mjs +33 -0
- package/dist/{chunk-7JIJOVCT.js → chunk-JH4GI3DW.js} +2 -4
- package/dist/{chunk-76YMRMH2.cjs → chunk-KHACHFBQ.cjs} +583 -78
- package/dist/{chunk-MT3OWDPC.mjs → chunk-KRYP6CAE.mjs} +60 -11
- package/dist/chunk-KTGDLBLD.mjs +123 -0
- package/dist/{chunk-ENKODRU3.cjs → chunk-LXBU5E77.cjs} +143 -94
- package/dist/{chunk-PD4EJTQC.cjs → chunk-N6QNSTWD.cjs} +5 -5
- package/dist/{chunk-HLWLMW2F.mjs → chunk-OI4ESUMC.mjs} +9 -11
- package/dist/{chunk-EJ6BPYVR.mjs → chunk-OT2TESZU.mjs} +1 -1
- package/dist/{chunk-BABBZK4Y.js → chunk-PSEU65ND.js} +9 -11
- package/dist/{chunk-DNFO2EIZ.mjs → chunk-QCOLAHU3.mjs} +528 -23
- package/dist/{chunk-KH4SYAOS.mjs → chunk-QZ6QFJNM.mjs} +20 -299
- package/dist/{chunk-MBEJI5HF.mjs → chunk-R6WDSZA6.mjs} +2 -4
- package/dist/{chunk-FHQGHPMO.mjs → chunk-RREBJX2S.mjs} +2 -4
- package/dist/{chunk-5QC7LRZ3.js → chunk-S4HHFUYP.js} +2 -2
- package/dist/{chunk-GLE2WY7Z.cjs → chunk-SSQJKDN3.cjs} +194 -11
- package/dist/{chunk-CZIVE6NT.cjs → chunk-UUMKZJRJ.cjs} +48 -24
- package/dist/chunk-VIFA4DPN.cjs +6126 -0
- package/dist/chunk-W6WR37HN.js +33 -0
- package/dist/{chunk-FH2X7BVP.js → chunk-XSAHV5HQ.js} +188 -5
- package/dist/chunk-YM3EDNYD.js +123 -0
- package/dist/{chunk-VN44DYYT.cjs → chunk-YTX2JYYP.cjs} +18 -20
- package/dist/chunk-Z3PSSXP3.mjs +6126 -0
- package/dist/core/index.cjs +31 -9
- package/dist/core/index.d.ts +19 -152
- package/dist/core/index.js +80 -58
- package/dist/core/index.mjs +80 -58
- package/dist/defaultClient-DhpCQW9m.d.ts +1623 -0
- package/dist/{effect-DIUHZ9IN.d.ts → effect-CtUDl5M5.d.ts} +1 -1
- package/dist/http/index.cjs +202 -59
- package/dist/http/index.d.ts +55 -819
- package/dist/http/index.js +216 -73
- package/dist/http/index.mjs +216 -73
- package/dist/http/testing.cjs +31 -10
- package/dist/http/testing.d.ts +16 -5
- package/dist/http/testing.js +29 -8
- package/dist/http/testing.mjs +29 -8
- package/dist/index.cjs +110 -88
- package/dist/index.d.ts +9 -8
- package/dist/index.js +81 -59
- package/dist/index.mjs +81 -59
- package/dist/{schedule-CK3Ml_7p.d.ts → layer-BalPI6cN.d.ts} +176 -2
- package/dist/observability/index.cjs +22 -7
- package/dist/observability/index.d.ts +32 -8
- package/dist/observability/index.js +21 -6
- package/dist/observability/index.mjs +21 -6
- package/dist/perf/cli.cjs +26 -28
- package/dist/perf/cli.js +11 -13
- package/dist/perf/cli.mjs +11 -13
- package/dist/perf/index.cjs +13 -15
- package/dist/perf/index.js +11 -13
- package/dist/perf/index.mjs +11 -13
- package/dist/schema/index.cjs +2 -2
- package/dist/schema/index.js +1 -1
- package/dist/schema/index.mjs +1 -1
- package/dist/{server-GJPg8ZSG.d.ts → server-C1zVmqE6.d.ts} +16 -5
- package/dist/{stream-B4oK9JFP.d.ts → stream-Bb4FTejt.d.ts} +1 -1
- package/dist/{tracer-Hwt1cl7h.d.ts → tracer-DzfuE6um.d.ts} +2 -2
- package/dist/{tracing-DqbTKGcf.d.ts → tracing-BABA5arE.d.ts} +1 -1
- package/docs/README.md +4 -0
- package/docs/ai/PUBLIC_API.md +31 -7
- package/docs/articles/brass-runtime-http-observability.md +467 -0
- package/docs/framework-integrations.md +38 -0
- package/docs/frameworks/angular.md +204 -0
- package/docs/frameworks/express.md +183 -0
- package/docs/frameworks/fastify.md +173 -0
- package/docs/frameworks/nestjs.md +335 -0
- package/docs/frameworks/nextjs.md +202 -0
- package/docs/frameworks/react.md +183 -0
- package/docs/frameworks/vanilla.md +280 -0
- package/docs/guides/layers.md +130 -0
- package/docs/http-recipes.md +31 -1
- package/docs/http.md +50 -1
- package/docs/nestjs.md +6 -0
- package/docs/observability-framework-examples.md +12 -0
- package/docs/observability.md +239 -0
- package/docs/performance-profiler.md +6 -2
- package/docs/recipes/layers.md +46 -2
- package/docs/recipes/testing.md +25 -0
- package/package.json +4 -1
- package/dist/chunk-3LOYJFRR.cjs +0 -300
- package/dist/chunk-3Y2RIUMM.js +0 -300
- package/dist/chunk-5EC274J5.cjs +0 -2874
- package/dist/chunk-5VRJNBLZ.mjs +0 -2874
- package/dist/chunk-62AZW6UT.cjs +0 -313
- package/dist/chunk-74ZTY6CP.js +0 -2871
- package/dist/chunk-7CMJS3QE.mjs +0 -2871
- package/dist/chunk-A2OM6NEH.mjs +0 -194
- package/dist/chunk-B33ICAKP.js +0 -313
- package/dist/chunk-JF5WGYJJ.cjs +0 -194
- package/dist/chunk-KN32XNTH.mjs +0 -313
- package/dist/chunk-KQLYONSE.cjs +0 -2871
- package/dist/chunk-L2SYFEBS.js +0 -194
- package/dist/chunk-MIIYDLGM.js +0 -2874
- package/dist/chunk-PWC3RBQE.mjs +0 -300
- package/dist/client-CZHU674n.d.ts +0 -820
|
@@ -1,820 +0,0 @@
|
|
|
1
|
-
import { A as Async } from './effect-DIUHZ9IN.js';
|
|
2
|
-
import { Z as ZStream } from './stream-B4oK9JFP.js';
|
|
3
|
-
import { S as Schedule, a as ScheduleObserver, C as CircuitBreakerError } from './schedule-CK3Ml_7p.js';
|
|
4
|
-
import { SchemaIssue, JsonSchemaLike } from './schema/index.js';
|
|
5
|
-
|
|
6
|
-
type HttpRetryScheduleInput = {
|
|
7
|
-
readonly attempt: number;
|
|
8
|
-
readonly elapsedMs: number;
|
|
9
|
-
readonly request: HttpRequest;
|
|
10
|
-
readonly error?: HttpError;
|
|
11
|
-
readonly status?: number;
|
|
12
|
-
readonly retryAfterMs?: number;
|
|
13
|
-
};
|
|
14
|
-
type HttpRequestRetryOverride = false | {
|
|
15
|
-
readonly maxRetries?: number;
|
|
16
|
-
readonly baseDelayMs?: number;
|
|
17
|
-
readonly maxDelayMs?: number;
|
|
18
|
-
readonly schedule?: Schedule<HttpRetryScheduleInput, unknown>;
|
|
19
|
-
readonly retryOnStatus?: (status: number) => boolean;
|
|
20
|
-
};
|
|
21
|
-
type HttpRequestPolicy = {
|
|
22
|
-
readonly preset?: string;
|
|
23
|
-
readonly lane?: string;
|
|
24
|
-
readonly dedupKey?: string;
|
|
25
|
-
readonly priority?: number;
|
|
26
|
-
readonly retry?: HttpRequestRetryOverride;
|
|
27
|
-
readonly poolKey?: string;
|
|
28
|
-
};
|
|
29
|
-
type HttpRequestPolicyRef = HttpRequestPolicy | string;
|
|
30
|
-
type HttpPolicyPreset = HttpRequestPolicy | ((request: HttpRequest, presetName: string) => HttpRequestPolicy);
|
|
31
|
-
type HttpPolicyPresets = Record<string, HttpPolicyPreset>;
|
|
32
|
-
type ResolveHttpRequestPolicyOptions = {
|
|
33
|
-
readonly presets?: HttpPolicyPresets;
|
|
34
|
-
};
|
|
35
|
-
declare const defineHttpPolicyPresets: <Presets extends HttpPolicyPresets>(presets: Presets) => Presets;
|
|
36
|
-
declare const httpPolicy: Readonly<{
|
|
37
|
-
preset: (preset: string, overrides?: Omit<HttpRequestPolicy, "preset">) => HttpRequestPolicy;
|
|
38
|
-
lane: (lane: string, overrides?: Omit<HttpRequestPolicy, "preset" | "lane">) => HttpRequestPolicy;
|
|
39
|
-
define: <Presets extends HttpPolicyPresets>(presets: Presets) => Presets;
|
|
40
|
-
}>;
|
|
41
|
-
declare const getHttpRequestPolicy: (req: HttpRequest, options?: ResolveHttpRequestPolicyOptions) => HttpRequestPolicy;
|
|
42
|
-
declare const withHttpRequestPolicy: (req: HttpRequest, patch: Partial<HttpRequestPolicy>) => HttpRequest;
|
|
43
|
-
declare const resolveHttpRequestPolicyPresets: (req: HttpRequest, presets: HttpPolicyPresets) => HttpRequest;
|
|
44
|
-
declare const withHttpPolicyPresets: (presets: HttpPolicyPresets) => HttpMiddleware;
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Observable event emitted on each retry attempt via the `onRetry` callback.
|
|
48
|
-
*/
|
|
49
|
-
type RetryEvent = {
|
|
50
|
-
/** Zero-based attempt number (0 = first retry, not the initial request). */
|
|
51
|
-
attempt: number;
|
|
52
|
-
/** Computed delay in milliseconds before the next attempt. */
|
|
53
|
-
delayMs: number;
|
|
54
|
-
/** The error that triggered this retry, if the request failed with an HttpError. */
|
|
55
|
-
error?: HttpError;
|
|
56
|
-
/** The HTTP status code that triggered this retry, if the request returned a retryable status. */
|
|
57
|
-
status?: number;
|
|
58
|
-
/** The request URL. */
|
|
59
|
-
url: string;
|
|
60
|
-
/** The request HTTP method. */
|
|
61
|
-
method: HttpMethod;
|
|
62
|
-
/** Timestamp (ms since epoch) when the retry decision was made. */
|
|
63
|
-
timestamp: number;
|
|
64
|
-
};
|
|
65
|
-
type RetryScheduleInput = HttpRetryScheduleInput;
|
|
66
|
-
/**
|
|
67
|
-
* Per-request retry override. Prefer `req.policy.retry`; legacy top-level `req.retry`
|
|
68
|
-
* is still supported.
|
|
69
|
-
* - `false` disables retry entirely for this request.
|
|
70
|
-
* - A partial policy object merges with the middleware-level policy (per-request wins).
|
|
71
|
-
*/
|
|
72
|
-
type PerRequestRetryOverride = HttpRequestRetryOverride;
|
|
73
|
-
type RetryPolicy = {
|
|
74
|
-
maxRetries: number;
|
|
75
|
-
baseDelayMs: number;
|
|
76
|
-
maxDelayMs: number;
|
|
77
|
-
/** Optional declarative schedule. When present, it provides retry delays. */
|
|
78
|
-
schedule?: Schedule<RetryScheduleInput, unknown>;
|
|
79
|
-
/** Optional observer for declarative schedule decisions. */
|
|
80
|
-
onScheduleDecision?: ScheduleObserver<RetryScheduleInput, unknown>;
|
|
81
|
-
/** Optional total retry budget, including request attempts and sleeps. */
|
|
82
|
-
maxElapsedMs?: number;
|
|
83
|
-
/** Defaults to true. When true, Retry-After is honored but capped by maxDelayMs/budget. */
|
|
84
|
-
respectRetryAfter?: boolean;
|
|
85
|
-
retryOnMethods?: HttpMethod[];
|
|
86
|
-
retryOnStatus?: (status: number) => boolean;
|
|
87
|
-
retryOnError?: (e: HttpError) => boolean;
|
|
88
|
-
/** Strict engine selector for retry planning. Defaults to ts. */
|
|
89
|
-
engine?: "ts" | "wasm";
|
|
90
|
-
/** Back-compat knob: wasm=true maps to engine="wasm", wasm=false maps to engine="ts". */
|
|
91
|
-
wasm?: boolean;
|
|
92
|
-
/** Called synchronously before each retry delay begins. Zero overhead when omitted. */
|
|
93
|
-
onRetry?: (event: RetryEvent) => void;
|
|
94
|
-
};
|
|
95
|
-
declare const defaultRetryableMethods: HttpMethod[];
|
|
96
|
-
declare const defaultRetryOnStatus: (s: number) => s is 408 | 429 | 500 | 502 | 503 | 504;
|
|
97
|
-
declare const defaultRetryOnError: (e: HttpError) => boolean;
|
|
98
|
-
declare const backoffDelayMs: (attempt: number, base: number, cap: number) => number;
|
|
99
|
-
declare const retryAfterMs: (headers: Record<string, string>) => number | undefined;
|
|
100
|
-
declare const normalizeRetryBudget: (ms: number | undefined) => number | undefined;
|
|
101
|
-
declare const withRetry: (p: RetryPolicy) => HttpMiddleware;
|
|
102
|
-
|
|
103
|
-
type HttpPoolKeyResolver = "global" | "origin" | "host" | ((req: HttpRequest, url: URL) => string);
|
|
104
|
-
type HttpPoolConfig = {
|
|
105
|
-
/** Max concurrent downstream calls per resolved key. */
|
|
106
|
-
readonly concurrency?: number;
|
|
107
|
-
/** Max queued waiters per key. `0` means fail fast when the pool is full. */
|
|
108
|
-
readonly maxQueue?: number;
|
|
109
|
-
/** Max time a request may wait for a pool slot before failing fast. */
|
|
110
|
-
readonly queueTimeoutMs?: number;
|
|
111
|
-
/** How to isolate pools. Default: `origin`; useful values: `global`, `host`, `origin`. */
|
|
112
|
-
readonly key?: HttpPoolKeyResolver;
|
|
113
|
-
/**
|
|
114
|
-
* Strict engine selector for permit governance. Defaults to ts.
|
|
115
|
-
* - ts: TypeScript permit pool.
|
|
116
|
-
* - wasm: require BrassWasmHttpPermitPool from wasm/pkg; never falls back.
|
|
117
|
-
*/
|
|
118
|
-
readonly engine?: "ts" | "wasm";
|
|
119
|
-
/** Back-compat knob: wasm=true maps to engine="wasm", wasm=false maps to engine="ts". */
|
|
120
|
-
readonly wasm?: boolean;
|
|
121
|
-
};
|
|
122
|
-
type HttpPoolKeyStats = {
|
|
123
|
-
readonly key: string;
|
|
124
|
-
readonly running: number;
|
|
125
|
-
readonly queued: number;
|
|
126
|
-
readonly concurrency: number;
|
|
127
|
-
readonly maxQueue: number;
|
|
128
|
-
readonly acquired: number;
|
|
129
|
-
readonly released: number;
|
|
130
|
-
readonly rejected: number;
|
|
131
|
-
readonly queueTimeouts: number;
|
|
132
|
-
readonly abortedWhileQueued: number;
|
|
133
|
-
};
|
|
134
|
-
type HttpPoolStats = {
|
|
135
|
-
readonly running: number;
|
|
136
|
-
readonly queued: number;
|
|
137
|
-
readonly acquired: number;
|
|
138
|
-
readonly released: number;
|
|
139
|
-
readonly rejected: number;
|
|
140
|
-
readonly queueTimeouts: number;
|
|
141
|
-
readonly abortedWhileQueued: number;
|
|
142
|
-
readonly wasm?: unknown;
|
|
143
|
-
readonly keys: HttpPoolKeyStats[];
|
|
144
|
-
};
|
|
145
|
-
type HttpPoolLease = {
|
|
146
|
-
readonly key: string;
|
|
147
|
-
release: () => void;
|
|
148
|
-
};
|
|
149
|
-
declare function resolveHttpPoolKey(resolver: HttpPoolKeyResolver | undefined, req: HttpRequest, url: URL): string;
|
|
150
|
-
declare class HttpConcurrencyPool {
|
|
151
|
-
private readonly states;
|
|
152
|
-
private readonly concurrency;
|
|
153
|
-
private readonly maxQueue;
|
|
154
|
-
private readonly queueTimeoutMs;
|
|
155
|
-
readonly keyResolver: HttpPoolKeyResolver | undefined;
|
|
156
|
-
private readonly wasm;
|
|
157
|
-
private readonly wasmWaiters;
|
|
158
|
-
private wasmTimer;
|
|
159
|
-
private nextSubjectId;
|
|
160
|
-
constructor(config?: HttpPoolConfig);
|
|
161
|
-
acquire(key: string, signal: AbortSignal): Promise<HttpPoolLease>;
|
|
162
|
-
stats(): HttpPoolStats;
|
|
163
|
-
private acquireJs;
|
|
164
|
-
private acquireWasm;
|
|
165
|
-
private getState;
|
|
166
|
-
private makeLease;
|
|
167
|
-
private drain;
|
|
168
|
-
private handleWasmGrants;
|
|
169
|
-
private handleWasmTimeouts;
|
|
170
|
-
private scheduleWasmTimeoutPump;
|
|
171
|
-
private cleanupWaiter;
|
|
172
|
-
private removeWaiter;
|
|
173
|
-
private allocateSubjectId;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
type AdaptiveHeadroomMode = "stable" | "probe" | "warmup" | "slow-start" | "circuit-open";
|
|
177
|
-
type AdaptiveHeadroomContext = {
|
|
178
|
-
readonly key: string;
|
|
179
|
-
readonly currentLimit: number;
|
|
180
|
-
readonly minLimit: number;
|
|
181
|
-
readonly maxLimit: number;
|
|
182
|
-
readonly gradient: number;
|
|
183
|
-
readonly mode: AdaptiveHeadroomMode;
|
|
184
|
-
};
|
|
185
|
-
type AdaptiveHeadroomStrategy = number | "fixed" | "proportional" | {
|
|
186
|
-
readonly type: "fixed";
|
|
187
|
-
readonly value?: number;
|
|
188
|
-
} | {
|
|
189
|
-
readonly type: "proportional";
|
|
190
|
-
readonly ratio?: number;
|
|
191
|
-
readonly min?: number;
|
|
192
|
-
readonly max?: number;
|
|
193
|
-
} | ((context: AdaptiveHeadroomContext) => number);
|
|
194
|
-
type AdaptiveBaselineStrategy = "min" | "p5" | "ema-low";
|
|
195
|
-
type AdaptiveQueueStrategy = "fifo" | "priority";
|
|
196
|
-
type AdaptiveQueueLoadShedding = "reject-new" | "priority-evict";
|
|
197
|
-
type AdaptiveLimiterPreset = "conservative" | "balanced" | "aggressive";
|
|
198
|
-
type AdaptiveAcquireOptions = {
|
|
199
|
-
/** Request priority from 0 (highest) to 9 (lowest). Default: 5. */
|
|
200
|
-
readonly priority?: number;
|
|
201
|
-
};
|
|
202
|
-
type AdaptiveReleaseInfo = {
|
|
203
|
-
/** HTTP response status, used by the error signal when >= 500 by default. */
|
|
204
|
-
readonly status?: number;
|
|
205
|
-
/** Marks a failed request without an HTTP response, e.g. fetch error or timeout. */
|
|
206
|
-
readonly error?: boolean;
|
|
207
|
-
};
|
|
208
|
-
/**
|
|
209
|
-
* Configuration for the adaptive concurrency limiter.
|
|
210
|
-
* All fields are optional with sensible defaults.
|
|
211
|
-
*/
|
|
212
|
-
type AdaptiveLimiterConfig = {
|
|
213
|
-
/** Named production preset used before caller overrides are applied. */
|
|
214
|
-
readonly preset?: AdaptiveLimiterPreset;
|
|
215
|
-
/** Initial concurrency limit. Default: 10. */
|
|
216
|
-
readonly initialLimit?: number;
|
|
217
|
-
/** Minimum concurrency limit. Default: 1. */
|
|
218
|
-
readonly minLimit?: number;
|
|
219
|
-
/** Maximum concurrency limit. Default: 200. */
|
|
220
|
-
readonly maxLimit?: number;
|
|
221
|
-
/** EMA smoothing factor in (0, 1]. Default: 0.5. */
|
|
222
|
-
readonly smoothingFactor?: number;
|
|
223
|
-
/** Number of completions between probes. Default: 10. */
|
|
224
|
-
readonly probeInterval?: number;
|
|
225
|
-
/** Random probe interval spread. 0 disables jitter, 0.2 means ±20%. Default: 0.2. */
|
|
226
|
-
readonly probeJitterRatio?: number;
|
|
227
|
-
/** Sliding window size for latency samples. Default: 100. */
|
|
228
|
-
readonly windowSize?: number;
|
|
229
|
-
/** Minimum samples before the limiter may change its limit. Default: 10. */
|
|
230
|
-
readonly minSamples?: number;
|
|
231
|
-
/** Baseline used for gradient computation. Default: "min". */
|
|
232
|
-
readonly baselineStrategy?: AdaptiveBaselineStrategy;
|
|
233
|
-
/** Samples to wait after a decrease before allowing another decrease. Default: 0. */
|
|
234
|
-
readonly decreaseCooldownSamples?: number;
|
|
235
|
-
/** Number of limit-change events retained per key for diagnostics. Default: 32. */
|
|
236
|
-
readonly historySize?: number;
|
|
237
|
-
/** Exponential decay applied to percentile windows. 1 disables weighting. Default: 1. */
|
|
238
|
-
readonly windowDecayFactor?: number;
|
|
239
|
-
/** Error signal weight blended with latency gradient. 0 disables. Default: 0. */
|
|
240
|
-
readonly errorWeight?: number;
|
|
241
|
-
/** EMA smoothing factor for the error rate signal. Defaults to smoothingFactor. */
|
|
242
|
-
readonly errorSmoothingFactor?: number;
|
|
243
|
-
/** HTTP status at/above which responses count as downstream errors. Default: 500. */
|
|
244
|
-
readonly errorStatusThreshold?: number;
|
|
245
|
-
/** Internal queue ordering. Default: "fifo". */
|
|
246
|
-
readonly queueStrategy?: AdaptiveQueueStrategy;
|
|
247
|
-
/** Queue-full behavior. Default: "reject-new". */
|
|
248
|
-
readonly queueLoadShedding?: AdaptiveQueueLoadShedding;
|
|
249
|
-
/** Rejection streak before PoolRejected carries retryAfterMs. Default: 3. */
|
|
250
|
-
readonly rejectionBackoffThreshold?: number;
|
|
251
|
-
/** Backoff hint for sustained PoolRejected errors. Default: undefined. */
|
|
252
|
-
readonly rejectionBackoffMs?: number;
|
|
253
|
-
/** Remove inactive per-key state after this idle period. Use false to disable. Default: 300000. */
|
|
254
|
-
readonly stateTtlMs?: number | false;
|
|
255
|
-
/** Number of valid completions used for explicit linear warmup. 0 disables. Default: 0. */
|
|
256
|
-
readonly warmupRequests?: number;
|
|
257
|
-
/** Gradient below which the limiter decreases concurrency. Default: 0.75. */
|
|
258
|
-
readonly decreaseThreshold?: number;
|
|
259
|
-
/** Gradient at or above which the limiter may increase concurrency. Default: 1.0. */
|
|
260
|
-
readonly increaseThreshold?: number;
|
|
261
|
-
/** Maximum fraction of the current limit that can be removed in one adjustment. Default: 0.2. */
|
|
262
|
-
readonly maxDecreaseRatio?: number;
|
|
263
|
-
/** Fixed, proportional, or custom headroom added on stable growth/probes. Default: 1. */
|
|
264
|
-
readonly headroomStrategy?: AdaptiveHeadroomStrategy;
|
|
265
|
-
/** Enable fast recovery after sustained saturation. Default: true. */
|
|
266
|
-
readonly slowStartRecovery?: boolean;
|
|
267
|
-
/** Gradient at/below which samples count as strong saturation. Default: 0.5. */
|
|
268
|
-
readonly slowStartSaturationThreshold?: number;
|
|
269
|
-
/** Consecutive strong-saturation samples before slow-start recovery arms. Default: 3. */
|
|
270
|
-
readonly slowStartSaturationSamples?: number;
|
|
271
|
-
/** Key resolver for isolation scope. Default: "origin". */
|
|
272
|
-
readonly key?: HttpPoolKeyResolver;
|
|
273
|
-
/** Maximum queue depth per key. Default: 256. */
|
|
274
|
-
readonly maxQueue?: number;
|
|
275
|
-
/** Queue timeout in ms. Default: undefined (no timeout). */
|
|
276
|
-
readonly queueTimeoutMs?: number;
|
|
277
|
-
/** Callback invoked when the limit changes. */
|
|
278
|
-
readonly onLimitChange?: (event: LimitChangeEvent) => void;
|
|
279
|
-
/** Which percentile to use for gradient computation. Default: "p50". */
|
|
280
|
-
readonly percentile?: "p50" | "p99";
|
|
281
|
-
};
|
|
282
|
-
/**
|
|
283
|
-
* Event emitted when the concurrency limit changes.
|
|
284
|
-
*/
|
|
285
|
-
type LimitChangeEvent = {
|
|
286
|
-
readonly key: string;
|
|
287
|
-
readonly previousLimit: number;
|
|
288
|
-
readonly newLimit: number;
|
|
289
|
-
readonly gradient: number;
|
|
290
|
-
readonly latencyGradient: number;
|
|
291
|
-
readonly errorRate: number;
|
|
292
|
-
readonly smoothedLatency: number;
|
|
293
|
-
readonly minLatency: number;
|
|
294
|
-
readonly baselineLatency: number;
|
|
295
|
-
readonly p5: number | undefined;
|
|
296
|
-
readonly timestamp: number;
|
|
297
|
-
readonly reason?: "gradient" | "probe" | "warmup" | "slow-start" | "circuit-open";
|
|
298
|
-
};
|
|
299
|
-
/**
|
|
300
|
-
* Snapshot of the adaptive limiter's current state for a given key.
|
|
301
|
-
*/
|
|
302
|
-
type AdaptiveLimiterStats = {
|
|
303
|
-
readonly limit: number;
|
|
304
|
-
readonly inFlight: number;
|
|
305
|
-
readonly queueDepth: number;
|
|
306
|
-
readonly gradient: number | undefined;
|
|
307
|
-
readonly latencyGradient: number | undefined;
|
|
308
|
-
readonly errorRate: number | undefined;
|
|
309
|
-
readonly smoothedLatency: number | undefined;
|
|
310
|
-
readonly minLatency: number | undefined;
|
|
311
|
-
readonly baselineLatency: number | undefined;
|
|
312
|
-
readonly p5: number | undefined;
|
|
313
|
-
readonly p50: number | undefined;
|
|
314
|
-
readonly p99: number | undefined;
|
|
315
|
-
readonly probeCount: number;
|
|
316
|
-
readonly windowSize: number;
|
|
317
|
-
readonly warmupCompletions?: number;
|
|
318
|
-
readonly slowStart?: boolean;
|
|
319
|
-
readonly cooldownSamplesRemaining?: number;
|
|
320
|
-
readonly utilization?: number;
|
|
321
|
-
readonly requestsPerSecond?: number;
|
|
322
|
-
readonly completionsPerSecond?: number;
|
|
323
|
-
readonly rejectionRate?: number;
|
|
324
|
-
readonly suggestedBackoffMs?: number;
|
|
325
|
-
readonly stateCount?: number;
|
|
326
|
-
readonly keys?: readonly string[];
|
|
327
|
-
};
|
|
328
|
-
type AdaptiveLimiterKeySnapshot = AdaptiveLimiterStats & {
|
|
329
|
-
readonly key: string;
|
|
330
|
-
readonly createdAt: number;
|
|
331
|
-
readonly createdTimestamp: number;
|
|
332
|
-
readonly lastActivityAt: number;
|
|
333
|
-
readonly lastActivityTimestamp: number;
|
|
334
|
-
readonly nextProbeAt: number;
|
|
335
|
-
readonly warmupDone: boolean;
|
|
336
|
-
readonly saturationStreak: number;
|
|
337
|
-
readonly slowStartRecoveryStarted: boolean;
|
|
338
|
-
readonly history: readonly LimitChangeEvent[];
|
|
339
|
-
readonly acquired: number;
|
|
340
|
-
readonly released: number;
|
|
341
|
-
readonly rejected: number;
|
|
342
|
-
readonly queueTimeouts: number;
|
|
343
|
-
readonly abortedWhileQueued: number;
|
|
344
|
-
readonly evictedWhileQueued: number;
|
|
345
|
-
};
|
|
346
|
-
type AdaptiveLimiterDiagnostics = {
|
|
347
|
-
readonly stateCount: number;
|
|
348
|
-
readonly keys: readonly string[];
|
|
349
|
-
readonly aggregate: AdaptiveLimiterStats;
|
|
350
|
-
readonly states: readonly AdaptiveLimiterKeySnapshot[];
|
|
351
|
-
readonly history: readonly LimitChangeEvent[];
|
|
352
|
-
};
|
|
353
|
-
/**
|
|
354
|
-
* A lease representing an acquired concurrency slot.
|
|
355
|
-
* Call `release(latencyMs)` when the request completes to record latency and free the slot.
|
|
356
|
-
*/
|
|
357
|
-
type AdaptiveLease = {
|
|
358
|
-
readonly key: string;
|
|
359
|
-
release(latencyMs: number, info?: AdaptiveReleaseInfo): void;
|
|
360
|
-
};
|
|
361
|
-
/** Resolved (non-optional) configuration with defaults applied. */
|
|
362
|
-
type ResolvedConfig = {
|
|
363
|
-
readonly preset: AdaptiveLimiterPreset | undefined;
|
|
364
|
-
readonly initialLimit: number;
|
|
365
|
-
readonly minLimit: number;
|
|
366
|
-
readonly maxLimit: number;
|
|
367
|
-
readonly smoothingFactor: number;
|
|
368
|
-
readonly probeInterval: number;
|
|
369
|
-
readonly probeJitterRatio: number;
|
|
370
|
-
readonly windowSize: number;
|
|
371
|
-
readonly minSamples: number;
|
|
372
|
-
readonly baselineStrategy: AdaptiveBaselineStrategy;
|
|
373
|
-
readonly decreaseCooldownSamples: number;
|
|
374
|
-
readonly historySize: number;
|
|
375
|
-
readonly windowDecayFactor: number;
|
|
376
|
-
readonly errorWeight: number;
|
|
377
|
-
readonly errorSmoothingFactor: number;
|
|
378
|
-
readonly errorStatusThreshold: number;
|
|
379
|
-
readonly queueStrategy: AdaptiveQueueStrategy;
|
|
380
|
-
readonly queueLoadShedding: AdaptiveQueueLoadShedding;
|
|
381
|
-
readonly rejectionBackoffThreshold: number;
|
|
382
|
-
readonly rejectionBackoffMs: number | undefined;
|
|
383
|
-
readonly stateTtlMs: number | undefined;
|
|
384
|
-
readonly warmupRequests: number;
|
|
385
|
-
readonly decreaseThreshold: number;
|
|
386
|
-
readonly increaseThreshold: number;
|
|
387
|
-
readonly maxDecreaseRatio: number;
|
|
388
|
-
readonly headroomStrategy: AdaptiveHeadroomStrategy;
|
|
389
|
-
readonly slowStartRecovery: boolean;
|
|
390
|
-
readonly slowStartSaturationThreshold: number;
|
|
391
|
-
readonly slowStartSaturationSamples: number;
|
|
392
|
-
readonly key: HttpPoolKeyResolver;
|
|
393
|
-
readonly maxQueue: number;
|
|
394
|
-
readonly queueTimeoutMs: number | undefined;
|
|
395
|
-
readonly onLimitChange: ((event: LimitChangeEvent) => void) | undefined;
|
|
396
|
-
readonly percentile: "p50" | "p99";
|
|
397
|
-
};
|
|
398
|
-
declare const adaptiveLimiterPresets: Readonly<{
|
|
399
|
-
conservative: Readonly<{
|
|
400
|
-
initialLimit: 8;
|
|
401
|
-
minLimit: 2;
|
|
402
|
-
maxLimit: 64;
|
|
403
|
-
maxQueue: 256;
|
|
404
|
-
queueTimeoutMs: 30000;
|
|
405
|
-
smoothingFactor: 0.3;
|
|
406
|
-
probeInterval: 40;
|
|
407
|
-
probeJitterRatio: 0.2;
|
|
408
|
-
windowSize: 100;
|
|
409
|
-
minSamples: 80;
|
|
410
|
-
baselineStrategy: "p5";
|
|
411
|
-
windowDecayFactor: 0.99;
|
|
412
|
-
errorWeight: 0.2;
|
|
413
|
-
decreaseThreshold: 0.65;
|
|
414
|
-
maxDecreaseRatio: 0.08;
|
|
415
|
-
headroomStrategy: "fixed";
|
|
416
|
-
queueStrategy: "priority";
|
|
417
|
-
queueLoadShedding: "priority-evict";
|
|
418
|
-
rejectionBackoffThreshold: 2;
|
|
419
|
-
rejectionBackoffMs: 150;
|
|
420
|
-
percentile: "p50";
|
|
421
|
-
}>;
|
|
422
|
-
balanced: Readonly<{
|
|
423
|
-
initialLimit: 16;
|
|
424
|
-
minLimit: 4;
|
|
425
|
-
maxLimit: 128;
|
|
426
|
-
maxQueue: 512;
|
|
427
|
-
queueTimeoutMs: 30000;
|
|
428
|
-
smoothingFactor: 0.35;
|
|
429
|
-
probeInterval: 25;
|
|
430
|
-
probeJitterRatio: 0.2;
|
|
431
|
-
windowSize: 100;
|
|
432
|
-
minSamples: 50;
|
|
433
|
-
baselineStrategy: "p5";
|
|
434
|
-
windowDecayFactor: 0.98;
|
|
435
|
-
errorWeight: 0.25;
|
|
436
|
-
decreaseThreshold: 0.5;
|
|
437
|
-
maxDecreaseRatio: 0.1;
|
|
438
|
-
headroomStrategy: {
|
|
439
|
-
type: "proportional";
|
|
440
|
-
ratio: number;
|
|
441
|
-
};
|
|
442
|
-
queueStrategy: "priority";
|
|
443
|
-
queueLoadShedding: "priority-evict";
|
|
444
|
-
rejectionBackoffThreshold: 3;
|
|
445
|
-
rejectionBackoffMs: 100;
|
|
446
|
-
percentile: "p50";
|
|
447
|
-
}>;
|
|
448
|
-
aggressive: Readonly<{
|
|
449
|
-
initialLimit: 32;
|
|
450
|
-
minLimit: 8;
|
|
451
|
-
maxLimit: 256;
|
|
452
|
-
maxQueue: 1024;
|
|
453
|
-
queueTimeoutMs: 30000;
|
|
454
|
-
smoothingFactor: 0.35;
|
|
455
|
-
probeInterval: 20;
|
|
456
|
-
probeJitterRatio: 0.2;
|
|
457
|
-
windowSize: 160;
|
|
458
|
-
minSamples: 100;
|
|
459
|
-
baselineStrategy: "p5";
|
|
460
|
-
windowDecayFactor: 0.98;
|
|
461
|
-
errorWeight: 0.25;
|
|
462
|
-
decreaseThreshold: 0.5;
|
|
463
|
-
maxDecreaseRatio: 0.1;
|
|
464
|
-
headroomStrategy: {
|
|
465
|
-
type: "proportional";
|
|
466
|
-
ratio: number;
|
|
467
|
-
};
|
|
468
|
-
queueStrategy: "priority";
|
|
469
|
-
queueLoadShedding: "priority-evict";
|
|
470
|
-
rejectionBackoffThreshold: 3;
|
|
471
|
-
rejectionBackoffMs: 100;
|
|
472
|
-
percentile: "p50";
|
|
473
|
-
}>;
|
|
474
|
-
}>;
|
|
475
|
-
declare function makeAdaptiveLimiterConfig(preset: AdaptiveLimiterPreset, overrides?: AdaptiveLimiterConfig): AdaptiveLimiterConfig;
|
|
476
|
-
/**
|
|
477
|
-
* Validates the adaptive limiter configuration.
|
|
478
|
-
* Throws a descriptive error for invalid combinations.
|
|
479
|
-
*/
|
|
480
|
-
declare function validateConfig(config: AdaptiveLimiterConfig): void;
|
|
481
|
-
/**
|
|
482
|
-
* Resolves a partial configuration into a fully-resolved configuration with defaults applied.
|
|
483
|
-
* Handles minLimit > maxLimit by treating minLimit as the effective maxLimit.
|
|
484
|
-
*/
|
|
485
|
-
declare function resolveConfig(config?: AdaptiveLimiterConfig): ResolvedConfig;
|
|
486
|
-
|
|
487
|
-
/**
|
|
488
|
-
* Adaptive concurrency limiter that dynamically adjusts the number of concurrent
|
|
489
|
-
* requests based on observed latency patterns using a gradient-based algorithm.
|
|
490
|
-
*/
|
|
491
|
-
declare class AdaptiveLimiter {
|
|
492
|
-
private readonly config;
|
|
493
|
-
private readonly states;
|
|
494
|
-
private destroyed;
|
|
495
|
-
constructor(config?: AdaptiveLimiterConfig);
|
|
496
|
-
/** Key resolver for external use by the HTTP client. */
|
|
497
|
-
get keyResolver(): HttpPoolKeyResolver | undefined;
|
|
498
|
-
/**
|
|
499
|
-
* Acquire a concurrency slot for the given key.
|
|
500
|
-
* Resolves immediately if under the limit, otherwise queues the request.
|
|
501
|
-
* Rejects with PoolRejected if the queue is full, or PoolTimeout if the queue timeout expires.
|
|
502
|
-
*/
|
|
503
|
-
acquire(key: string, signal: AbortSignal, options?: AdaptiveAcquireOptions): Promise<AdaptiveLease>;
|
|
504
|
-
/**
|
|
505
|
-
* Get stats for a specific key, or aggregate stats if no key is provided.
|
|
506
|
-
*/
|
|
507
|
-
stats(key?: string): AdaptiveLimiterStats;
|
|
508
|
-
/** Return the currently retained per-key state identifiers. */
|
|
509
|
-
keys(): readonly string[];
|
|
510
|
-
/** Return a diagnostic snapshot for one retained key, if present. */
|
|
511
|
-
snapshot(key: string): AdaptiveLimiterKeySnapshot | undefined;
|
|
512
|
-
/** Return a full diagnostic dump across all retained keys. */
|
|
513
|
-
dump(): AdaptiveLimiterDiagnostics;
|
|
514
|
-
/** Return retained limit-change history for one key, or all keys if omitted. */
|
|
515
|
-
history(key?: string): readonly LimitChangeEvent[];
|
|
516
|
-
/**
|
|
517
|
-
* Circuit-breaker feedback hook. When a circuit is already open for `key`,
|
|
518
|
-
* collapse that key's limit to minLimit immediately instead of waiting for
|
|
519
|
-
* latency gradients to discover the saturation indirectly.
|
|
520
|
-
*/
|
|
521
|
-
markCircuitOpen(key: string): void;
|
|
522
|
-
/** Destroy the limiter, reject queued waiters, clear timers, and drop state. */
|
|
523
|
-
destroy(): void;
|
|
524
|
-
/** Alias for destroy(), useful for graceful shutdown code paths. */
|
|
525
|
-
shutdown(): void;
|
|
526
|
-
private getOrCreateState;
|
|
527
|
-
private makeLease;
|
|
528
|
-
private recordAndAdjust;
|
|
529
|
-
private tryWarmup;
|
|
530
|
-
private baselineLatency;
|
|
531
|
-
private lowLatencySample;
|
|
532
|
-
private isErrorSignal;
|
|
533
|
-
private combineGradientWithErrors;
|
|
534
|
-
private windowPercentile;
|
|
535
|
-
private recordSaturation;
|
|
536
|
-
private applyLimit;
|
|
537
|
-
private recordLimitChange;
|
|
538
|
-
private resolveHeadroom;
|
|
539
|
-
private nextProbeInterval;
|
|
540
|
-
private enqueueWaiter;
|
|
541
|
-
private dequeueWaiter;
|
|
542
|
-
private tryEvictLowerPriorityWaiter;
|
|
543
|
-
private suggestedBackoffMs;
|
|
544
|
-
private drain;
|
|
545
|
-
private currentLatency;
|
|
546
|
-
private touch;
|
|
547
|
-
private scheduleIdleEviction;
|
|
548
|
-
private clearIdleTimer;
|
|
549
|
-
private evictIdleStates;
|
|
550
|
-
private evictIdleState;
|
|
551
|
-
private cleanupWaiter;
|
|
552
|
-
private removeWaiter;
|
|
553
|
-
private stateToStats;
|
|
554
|
-
private stateToKeySnapshot;
|
|
555
|
-
}
|
|
556
|
-
|
|
557
|
-
type ValidationError = {
|
|
558
|
-
readonly _tag: "ValidationError";
|
|
559
|
-
readonly message: string;
|
|
560
|
-
readonly body: string;
|
|
561
|
-
readonly issues: readonly SchemaIssue[];
|
|
562
|
-
readonly phase?: "request" | "response";
|
|
563
|
-
readonly schema?: string;
|
|
564
|
-
};
|
|
565
|
-
type JsonDecodeResult<A> = {
|
|
566
|
-
readonly success: true;
|
|
567
|
-
readonly data: A;
|
|
568
|
-
} | {
|
|
569
|
-
readonly success: false;
|
|
570
|
-
readonly error: ValidationError;
|
|
571
|
-
};
|
|
572
|
-
declare function decodeJsonBody<A = unknown>(bodyText: string, validator?: JsonSchemaLike<A>, options?: {
|
|
573
|
-
readonly schemaName?: string;
|
|
574
|
-
}): JsonDecodeResult<A>;
|
|
575
|
-
declare function encodeJsonBodyEffect(bodyObj: unknown, validator?: JsonSchemaLike<any>, options?: {
|
|
576
|
-
readonly schemaName?: string;
|
|
577
|
-
}): Async<unknown, ValidationError, string>;
|
|
578
|
-
declare function decodeJsonBodyEffect<A = unknown>(bodyText: string, validator?: JsonSchemaLike<A>, options?: {
|
|
579
|
-
readonly schemaName?: string;
|
|
580
|
-
}): Async<unknown, ValidationError, A>;
|
|
581
|
-
declare function validatedJson<A>(client: HttpClientFn, validator: JsonSchemaLike<A>): (req: Parameters<HttpClientFn>[0]) => Async<unknown, HttpError | ValidationError, A>;
|
|
582
|
-
declare function validatedJsonResponse<A>(client: HttpClientFn, validator: JsonSchemaLike<A>): (req: Parameters<HttpClientFn>[0]) => Async<unknown, HttpError | ValidationError, HttpWireResponse & {
|
|
583
|
-
readonly body: A;
|
|
584
|
-
}>;
|
|
585
|
-
|
|
586
|
-
type KnownHttpError = HttpError | ValidationError | CircuitBreakerError;
|
|
587
|
-
type KnownHttpErrorTag = KnownHttpError["_tag"];
|
|
588
|
-
type ToHttpErrorOptions = {
|
|
589
|
-
readonly signal?: AbortSignal;
|
|
590
|
-
readonly timeoutMs?: number;
|
|
591
|
-
readonly phase?: "request" | "queue" | "retry";
|
|
592
|
-
readonly message?: string | ((error: unknown) => string);
|
|
593
|
-
};
|
|
594
|
-
type RetryableHttpErrorOptions = {
|
|
595
|
-
readonly retryOnStatus?: (status: number) => boolean;
|
|
596
|
-
};
|
|
597
|
-
type HttpErrorHandlers<R> = {
|
|
598
|
-
readonly [K in KnownHttpErrorTag]?: (error: Extract<KnownHttpError, {
|
|
599
|
-
readonly _tag: K;
|
|
600
|
-
}>) => R;
|
|
601
|
-
} & {
|
|
602
|
-
readonly default?: (error: unknown) => R;
|
|
603
|
-
};
|
|
604
|
-
declare function isHttpError(error: unknown): error is HttpError;
|
|
605
|
-
declare function isValidationError(error: unknown): error is ValidationError;
|
|
606
|
-
declare function isCircuitBreakerOpen(error: unknown): error is CircuitBreakerError;
|
|
607
|
-
declare function isKnownHttpError(error: unknown): error is KnownHttpError;
|
|
608
|
-
declare function isAbortHttpError(error: unknown): error is Extract<HttpError, {
|
|
609
|
-
readonly _tag: "Abort";
|
|
610
|
-
}>;
|
|
611
|
-
declare function isTimeoutHttpError(error: unknown): error is Extract<HttpError, {
|
|
612
|
-
readonly _tag: "Timeout" | "PoolTimeout";
|
|
613
|
-
}>;
|
|
614
|
-
declare function isFetchHttpError(error: unknown): error is Extract<HttpError, {
|
|
615
|
-
readonly _tag: "FetchError";
|
|
616
|
-
}>;
|
|
617
|
-
declare function httpErrorStatus(error: unknown): number | undefined;
|
|
618
|
-
declare function isRetryableHttpStatus(status: number): boolean;
|
|
619
|
-
declare function isRetryableHttpError(error: unknown, options?: RetryableHttpErrorOptions): boolean;
|
|
620
|
-
declare function isExternalAbortError(error: unknown): boolean;
|
|
621
|
-
declare function isExternalTimeoutError(error: unknown): boolean;
|
|
622
|
-
declare function toHttpError(error: unknown, options?: ToHttpErrorOptions): HttpError;
|
|
623
|
-
declare function matchHttpError<R>(error: unknown, handlers: HttpErrorHandlers<R>): R | undefined;
|
|
624
|
-
declare function formatHttpError(error: unknown): string;
|
|
625
|
-
|
|
626
|
-
type HttpTransportContext = {
|
|
627
|
-
readonly request: HttpRequest;
|
|
628
|
-
readonly url: URL;
|
|
629
|
-
readonly signal: AbortSignal;
|
|
630
|
-
};
|
|
631
|
-
type HttpTransport = (context: HttpTransportContext) => Async<unknown, HttpError, HttpWireResponse>;
|
|
632
|
-
type HttpStreamTransport = (context: HttpTransportContext) => Async<unknown, HttpError, HttpWireResponseStream>;
|
|
633
|
-
type HttpTransportTiming = {
|
|
634
|
-
readonly startedAt: number;
|
|
635
|
-
readonly durationMs: number;
|
|
636
|
-
};
|
|
637
|
-
type PromiseHttpTransportResponse = Omit<HttpWireResponse, "ms"> & {
|
|
638
|
-
readonly ms?: number;
|
|
639
|
-
};
|
|
640
|
-
type PromiseHttpTransportConfig<Response> = {
|
|
641
|
-
readonly request: (context: HttpTransportContext) => Promise<Response>;
|
|
642
|
-
readonly response: (response: Response, context: HttpTransportContext, timing: HttpTransportTiming) => PromiseHttpTransportResponse | Promise<PromiseHttpTransportResponse>;
|
|
643
|
-
readonly error?: (error: unknown, context: HttpTransportContext) => HttpError;
|
|
644
|
-
};
|
|
645
|
-
type PromiseHttpTransportResponseInfo<Meta = unknown> = {
|
|
646
|
-
readonly status?: number;
|
|
647
|
-
readonly statusText?: string;
|
|
648
|
-
readonly headers?: unknown;
|
|
649
|
-
readonly ms?: number;
|
|
650
|
-
readonly transportMeta?: Meta;
|
|
651
|
-
};
|
|
652
|
-
type PromiseHttpTransportResponseInfoMapper<Response, Meta = unknown> = (response: Response, context: HttpTransportContext, timing: HttpTransportTiming) => PromiseHttpTransportResponseInfo<Meta> | Promise<PromiseHttpTransportResponseInfo<Meta>>;
|
|
653
|
-
type PromiseHttpTransportBodySelector<Response, Body = unknown> = (response: Response, context: HttpTransportContext, timing: HttpTransportTiming) => Body | Promise<Body>;
|
|
654
|
-
type PromiseHttpTransportRequestConfigContext = Omit<HttpTransportContext, "signal">;
|
|
655
|
-
type PromiseHttpTransportRequestConfigMapper<Config> = (context: PromiseHttpTransportRequestConfigContext) => Config | Promise<Config>;
|
|
656
|
-
type PromiseHttpTransportConfigWithSignal<Config> = Config extends object ? Config & {
|
|
657
|
-
readonly signal: AbortSignal;
|
|
658
|
-
} : Config;
|
|
659
|
-
type PromiseHttpTransportRequestConfigBuilder<Config> = {
|
|
660
|
-
readonly send: <Response>(send: (config: PromiseHttpTransportConfigWithSignal<Config>) => Promise<Response>) => PromiseHttpTransportBodyBuilder<Response>;
|
|
661
|
-
};
|
|
662
|
-
type PromiseHttpTransportFluentResponseBuilder<Response> = {
|
|
663
|
-
readonly response: (response?: PromiseHttpTransportResponseInfoMapper<Response>) => HttpTransport;
|
|
664
|
-
readonly error: (error: NonNullable<PromiseHttpTransportConfig<Response>["error"]>) => PromiseHttpTransportFluentResponseBuilder<Response>;
|
|
665
|
-
};
|
|
666
|
-
type PromiseHttpTransportBodyBuilder<Response> = {
|
|
667
|
-
readonly response: (response: PromiseHttpTransportConfig<Response>["response"]) => HttpTransport;
|
|
668
|
-
readonly json: <Body = unknown>(body?: PromiseHttpTransportBodySelector<Response, Body>, response?: PromiseHttpTransportResponseInfoMapper<Response>) => HttpTransport;
|
|
669
|
-
readonly text: (body?: PromiseHttpTransportBodySelector<Response, unknown>, response?: PromiseHttpTransportResponseInfoMapper<Response>) => HttpTransport;
|
|
670
|
-
readonly fromJson: <Body = unknown>(body?: PromiseHttpTransportBodySelector<Response, Body>) => PromiseHttpTransportFluentResponseBuilder<Response>;
|
|
671
|
-
readonly fromText: (body?: PromiseHttpTransportBodySelector<Response, unknown>) => PromiseHttpTransportFluentResponseBuilder<Response>;
|
|
672
|
-
readonly error: (error: NonNullable<PromiseHttpTransportConfig<Response>["error"]>) => PromiseHttpTransportBodyBuilder<Response>;
|
|
673
|
-
};
|
|
674
|
-
type PromiseHttpTransportStartBuilder = {
|
|
675
|
-
readonly request: <Response>(request: PromiseHttpTransportConfig<Response>["request"]) => PromiseHttpTransportBodyBuilder<Response>;
|
|
676
|
-
readonly requestConfig: <Config>(request: PromiseHttpTransportRequestConfigMapper<Config>) => PromiseHttpTransportRequestConfigBuilder<Config>;
|
|
677
|
-
};
|
|
678
|
-
declare const isTaggedHttpError: (error: unknown) => error is HttpError;
|
|
679
|
-
declare const isAbortError: (error: unknown) => boolean;
|
|
680
|
-
declare const normalizeHttpError: (error: unknown, options?: ToHttpErrorOptions) => HttpError;
|
|
681
|
-
declare const headersOf: (response: Response) => Record<string, string>;
|
|
682
|
-
declare function normalizeHttpHeaders(headers: unknown): Record<string, string>;
|
|
683
|
-
declare const abortErrorForSignal: (signal: AbortSignal) => HttpError;
|
|
684
|
-
declare const linkAbortSignals: (...signals: readonly (AbortSignal | undefined)[]) => {
|
|
685
|
-
signal: AbortSignal;
|
|
686
|
-
cleanup: () => void;
|
|
687
|
-
};
|
|
688
|
-
declare function makePromiseHttpTransport<Response>(config: PromiseHttpTransportConfig<Response>): HttpTransport;
|
|
689
|
-
declare function promiseHttpTransport(): PromiseHttpTransportStartBuilder;
|
|
690
|
-
declare function makeFetchTransport(): HttpTransport;
|
|
691
|
-
declare function makeFetchStreamTransport(): HttpStreamTransport;
|
|
692
|
-
|
|
693
|
-
type HttpError = {
|
|
694
|
-
_tag: "Abort";
|
|
695
|
-
} | {
|
|
696
|
-
_tag: "BadUrl";
|
|
697
|
-
message: string;
|
|
698
|
-
} | {
|
|
699
|
-
_tag: "FetchError";
|
|
700
|
-
message: string;
|
|
701
|
-
code?: string;
|
|
702
|
-
status?: number;
|
|
703
|
-
statusText?: string;
|
|
704
|
-
retryAfterMs?: number;
|
|
705
|
-
cause?: unknown;
|
|
706
|
-
} | {
|
|
707
|
-
_tag: "Timeout";
|
|
708
|
-
timeoutMs: number;
|
|
709
|
-
message: string;
|
|
710
|
-
phase?: "request" | "queue" | "retry";
|
|
711
|
-
} | {
|
|
712
|
-
_tag: "PoolRejected";
|
|
713
|
-
key: string;
|
|
714
|
-
limit: number;
|
|
715
|
-
message: string;
|
|
716
|
-
retryAfterMs?: number;
|
|
717
|
-
} | {
|
|
718
|
-
_tag: "PoolTimeout";
|
|
719
|
-
key: string;
|
|
720
|
-
timeoutMs: number;
|
|
721
|
-
message: string;
|
|
722
|
-
} | {
|
|
723
|
-
_tag: "PoolClosed";
|
|
724
|
-
key: string;
|
|
725
|
-
message: string;
|
|
726
|
-
} | {
|
|
727
|
-
_tag: "BatchSplitError";
|
|
728
|
-
expected: number;
|
|
729
|
-
actual: number;
|
|
730
|
-
message: string;
|
|
731
|
-
};
|
|
732
|
-
type HttpMethod = "GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "HEAD" | "OPTIONS";
|
|
733
|
-
type HttpInit = Omit<RequestInit, "method" | "body" | "headers">;
|
|
734
|
-
type HttpBody = string | Uint8Array | ArrayBuffer;
|
|
735
|
-
type HttpRequest = {
|
|
736
|
-
method: HttpMethod;
|
|
737
|
-
url: string;
|
|
738
|
-
headers?: Record<string, string>;
|
|
739
|
-
body?: HttpBody;
|
|
740
|
-
init?: HttpInit;
|
|
741
|
-
/** Structured per-request execution policy. Legacy top-level fields are still read. */
|
|
742
|
-
policy?: HttpRequestPolicyRef;
|
|
743
|
-
/** Per-request override for `MakeHttpConfig.timeoutMs`. */
|
|
744
|
-
timeoutMs?: number;
|
|
745
|
-
/** Optional stable key for downstream isolation. When omitted, the pool uses origin/host/global config. */
|
|
746
|
-
poolKey?: string;
|
|
747
|
-
/** @deprecated Use `policy.lane`. Kept for middleware interop. */
|
|
748
|
-
lane?: string;
|
|
749
|
-
/** @deprecated Use `policy.dedupKey`. Kept for middleware interop. */
|
|
750
|
-
dedupKey?: string;
|
|
751
|
-
/** @deprecated Use `policy.priority`. Kept for middleware interop. */
|
|
752
|
-
priority?: number;
|
|
753
|
-
/** @deprecated Use `policy.retry`. Kept for middleware interop. */
|
|
754
|
-
retry?: HttpRequestRetryOverride;
|
|
755
|
-
};
|
|
756
|
-
type HttpWireResponse<Meta = unknown> = {
|
|
757
|
-
status: number;
|
|
758
|
-
statusText: string;
|
|
759
|
-
headers: Record<string, string>;
|
|
760
|
-
bodyText: string;
|
|
761
|
-
ms: number;
|
|
762
|
-
transportMeta?: Meta;
|
|
763
|
-
};
|
|
764
|
-
type HttpClientStats = {
|
|
765
|
-
readonly inFlight: number;
|
|
766
|
-
readonly started: number;
|
|
767
|
-
readonly succeeded: number;
|
|
768
|
-
readonly failed: number;
|
|
769
|
-
readonly aborted: number;
|
|
770
|
-
readonly timedOut: number;
|
|
771
|
-
readonly poolRejected: number;
|
|
772
|
-
readonly poolTimeouts: number;
|
|
773
|
-
readonly lastDurationMs?: number;
|
|
774
|
-
readonly pool?: HttpPoolStats;
|
|
775
|
-
readonly adaptiveLimiter?: AdaptiveLimiterStats;
|
|
776
|
-
};
|
|
777
|
-
type MakeHttpConfig = {
|
|
778
|
-
baseUrl?: string;
|
|
779
|
-
headers?: Record<string, string>;
|
|
780
|
-
/** Request budget covering pool wait + fetch + body read. Disabled when omitted. */
|
|
781
|
-
timeoutMs?: number;
|
|
782
|
-
/** Effect-based transport. Defaults to `fetch`; provide one for axios/undici/test transports. */
|
|
783
|
-
transport?: HttpTransport;
|
|
784
|
-
/** Effect-based streaming transport. Defaults to `fetch` streaming. */
|
|
785
|
-
streamTransport?: HttpStreamTransport;
|
|
786
|
-
/** Downstream pool/concurrency limiter. Disabled by default to preserve existing behavior. */
|
|
787
|
-
pool?: false | HttpPoolConfig;
|
|
788
|
-
/** Adaptive concurrency limiter. Replaces fixed pool when enabled. */
|
|
789
|
-
adaptiveLimiter?: false | AdaptiveLimiterConfig;
|
|
790
|
-
};
|
|
791
|
-
type HttpWireResponseStream<Meta = unknown> = {
|
|
792
|
-
status: number;
|
|
793
|
-
statusText: string;
|
|
794
|
-
headers: Record<string, string>;
|
|
795
|
-
body: ZStream<unknown, HttpError, Uint8Array>;
|
|
796
|
-
ms: number;
|
|
797
|
-
transportMeta?: Meta;
|
|
798
|
-
};
|
|
799
|
-
type HttpClientStreamFn = (req: HttpRequest) => Async<unknown, HttpError, HttpWireResponseStream>;
|
|
800
|
-
type HttpClientStream = HttpClientStreamFn & {
|
|
801
|
-
stats: () => HttpClientStats;
|
|
802
|
-
};
|
|
803
|
-
type HttpClientFn = (req: HttpRequest) => Async<unknown, HttpError, HttpWireResponse>;
|
|
804
|
-
type HttpMiddleware = (next: HttpClientFn) => HttpClientFn;
|
|
805
|
-
type HttpClient = HttpClientFn & {
|
|
806
|
-
with: (mw: HttpMiddleware) => HttpClient;
|
|
807
|
-
stats: () => HttpClientStats;
|
|
808
|
-
adaptiveLimiter?: AdaptiveLimiter;
|
|
809
|
-
destroy?: () => void;
|
|
810
|
-
shutdown?: () => void;
|
|
811
|
-
};
|
|
812
|
-
type HttpClientMetadata = Pick<HttpClient, "adaptiveLimiter" | "destroy" | "shutdown">;
|
|
813
|
-
declare const decorate: (run: HttpClientFn, stats?: () => HttpClientStats, metadata?: HttpClientMetadata) => HttpClient;
|
|
814
|
-
declare const withMiddleware: (mw: HttpMiddleware) => (c: HttpClient) => HttpClient;
|
|
815
|
-
declare const normalizeHeadersInit: (h: any) => Record<string, string> | undefined;
|
|
816
|
-
declare function makeHttpStream(cfg?: MakeHttpConfig): HttpClientStream;
|
|
817
|
-
declare function makeHttp(cfg?: MakeHttpConfig): HttpClient;
|
|
818
|
-
declare const withRetryStream: (p: RetryPolicy) => (next: HttpClientStream) => HttpClientStream;
|
|
819
|
-
|
|
820
|
-
export { type PromiseHttpTransportBodyBuilder as $, type AdaptiveLimiterStats as A, type AdaptiveQueueStrategy as B, type AdaptiveReleaseInfo as C, type HttpBody as D, type HttpClientStreamFn as E, HttpConcurrencyPool as F, type HttpErrorHandlers as G, type HttpClient as H, type HttpInit as I, type HttpPolicyPreset as J, type HttpPoolKeyResolver as K, type HttpPoolKeyStats as L, type MakeHttpConfig as M, type HttpPoolLease as N, type HttpPoolStats as O, type HttpRequestPolicy as P, type HttpRetryScheduleInput as Q, type RetryPolicy as R, type HttpStreamTransport as S, type HttpTransportContext as T, type HttpTransportTiming as U, type ValidationError as V, type JsonDecodeResult as W, type KnownHttpError as X, type KnownHttpErrorTag as Y, type LimitChangeEvent as Z, type PerRequestRetryOverride as _, type HttpRequest as a, toHttpError as a$, type PromiseHttpTransportBodySelector as a0, type PromiseHttpTransportConfig as a1, type PromiseHttpTransportConfigWithSignal as a2, type PromiseHttpTransportFluentResponseBuilder as a3, type PromiseHttpTransportRequestConfigBuilder as a4, type PromiseHttpTransportRequestConfigContext as a5, type PromiseHttpTransportRequestConfigMapper as a6, type PromiseHttpTransportResponse as a7, type PromiseHttpTransportResponseInfo as a8, type PromiseHttpTransportResponseInfoMapper as a9, isExternalAbortError as aA, isExternalTimeoutError as aB, isFetchHttpError as aC, isHttpError as aD, isKnownHttpError as aE, isRetryableHttpError as aF, isRetryableHttpStatus as aG, isTaggedHttpError as aH, isTimeoutHttpError as aI, isValidationError as aJ, linkAbortSignals as aK, makeAdaptiveLimiterConfig as aL, makeFetchStreamTransport as aM, makeFetchTransport as aN, makeHttp as aO, makeHttpStream as aP, makePromiseHttpTransport as aQ, matchHttpError as aR, normalizeHeadersInit as aS, normalizeHttpError as aT, normalizeHttpHeaders as aU, normalizeRetryBudget as aV, promiseHttpTransport as aW, resolveConfig as aX, resolveHttpPoolKey as aY, resolveHttpRequestPolicyPresets as aZ, retryAfterMs as a_, type PromiseHttpTransportStartBuilder as aa, type ResolveHttpRequestPolicyOptions as ab, type ResolvedConfig as ac, type RetryEvent as ad, type RetryScheduleInput as ae, type RetryableHttpErrorOptions as af, type ToHttpErrorOptions as ag, abortErrorForSignal as ah, adaptiveLimiterPresets as ai, backoffDelayMs as aj, decodeJsonBody as ak, decodeJsonBodyEffect as al, decorate as am, defaultRetryOnError as an, defaultRetryOnStatus as ao, defaultRetryableMethods as ap, defineHttpPolicyPresets as aq, encodeJsonBodyEffect as ar, formatHttpError as as, getHttpRequestPolicy as at, headersOf as au, httpErrorStatus as av, httpPolicy as aw, isAbortError as ax, isAbortHttpError as ay, isCircuitBreakerOpen as az, type HttpWireResponse as b, validateConfig as b0, validatedJson as b1, validatedJsonResponse as b2, withHttpPolicyPresets as b3, withHttpRequestPolicy as b4, withMiddleware as b5, withRetry as b6, withRetryStream as b7, type HttpError as c, type HttpMiddleware as d, type HttpRequestPolicyRef as e, type HttpRequestRetryOverride as f, type HttpWireResponseStream as g, type HttpClientStream as h, type HttpClientStats as i, AdaptiveLimiter as j, type HttpClientFn as k, type AdaptiveLimiterConfig as l, type HttpMethod as m, type HttpPolicyPresets as n, type HttpTransport as o, type AdaptiveLimiterPreset as p, type HttpPoolConfig as q, type AdaptiveAcquireOptions as r, type AdaptiveBaselineStrategy as s, type AdaptiveHeadroomContext as t, type AdaptiveHeadroomMode as u, type AdaptiveHeadroomStrategy as v, type AdaptiveLease as w, type AdaptiveLimiterDiagnostics as x, type AdaptiveLimiterKeySnapshot as y, type AdaptiveQueueLoadShedding as z };
|