arthron 0.1.0 → 1.0.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 +120 -48
- package/dist/index.cjs +679 -261
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +306 -83
- package/dist/index.d.mts +306 -83
- package/dist/index.mjs +679 -262
- package/dist/index.mjs.map +1 -1
- package/llms.txt +46 -30
- package/package.json +2 -2
package/dist/index.d.cts
CHANGED
|
@@ -1,11 +1,86 @@
|
|
|
1
|
-
//#region src/
|
|
2
|
-
|
|
1
|
+
//#region src/types/request.types.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* What plugins see and return. `init.headers` is always a plain record with
|
|
4
|
+
* lowercased names — spread it, read it, add to it — and the pipeline puts
|
|
5
|
+
* it back into that shape after every request interceptor.
|
|
6
|
+
*/
|
|
7
|
+
interface RequestContext {
|
|
8
|
+
url: string;
|
|
9
|
+
init: Omit<RequestInit, "headers"> & {
|
|
10
|
+
headers: Record<string, string>;
|
|
11
|
+
};
|
|
12
|
+
/** Per-call settings for plugins (`RequestOptions.meta`); never sent. */
|
|
13
|
+
meta: ArthronMeta;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Per-call settings for plugins, passed as `api.get(path, { meta })` and
|
|
17
|
+
* carried next to `init` — never sent to fetch. The built-in plugins read
|
|
18
|
+
* `retry` and `timeout`; your own add keys by augmentation:
|
|
19
|
+
*
|
|
20
|
+
* ```ts
|
|
21
|
+
* declare module "arthron" {
|
|
22
|
+
* interface ArthronMeta { skipAuth?: boolean }
|
|
23
|
+
* }
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
interface ArthronMeta {
|
|
27
|
+
/** `false` turns `retry()` off for this call; an object overrides its options. */
|
|
28
|
+
retry?: false | Omit<RetryOptions, "sleep">;
|
|
29
|
+
/** Deadline for this call in ms, overriding `timeout(ms)`. `Infinity` lifts it. */
|
|
30
|
+
timeout?: number;
|
|
31
|
+
}
|
|
32
|
+
type RetryOptions = {
|
|
33
|
+
/** Number of retries after the first attempt. Default 2 (3 requests total). */
|
|
34
|
+
retries?: number;
|
|
35
|
+
/** Statuses worth retrying. Network errors (status 0) always are. */
|
|
36
|
+
retryOn?: readonly number[];
|
|
37
|
+
/** Methods safe to repeat (QUERY is, per RFC 10008). Compared case-insensitively. */
|
|
38
|
+
methods?: readonly string[];
|
|
39
|
+
/**
|
|
40
|
+
* Backoff in ms for retry number `retry` (0-based). Default "full jitter":
|
|
41
|
+
* a random share of 300 · 2^retry, so clients that failed together do not
|
|
42
|
+
* retry together.
|
|
43
|
+
*/
|
|
44
|
+
delay?: (retry: number, error: unknown) => number;
|
|
45
|
+
/**
|
|
46
|
+
* Your own verdict on one failure: `true` retries, `false` stops,
|
|
47
|
+
* `undefined` leaves it to `retryOn`/`methods`. It sees every error — a
|
|
48
|
+
* TimeoutError from a `timeout()` placed after `retry()` included — but
|
|
49
|
+
* cannot exceed `retries`, resend a `ReadableStream` body, or retry a call
|
|
50
|
+
* the caller aborted.
|
|
51
|
+
*/
|
|
52
|
+
shouldRetry?: (error: unknown, attempt: number, ctx: RequestContext) => boolean | undefined;
|
|
53
|
+
/** Called before each wait, for logs and metrics. */
|
|
54
|
+
onRetry?: (error: unknown, attempt: number, waitMs: number) => void;
|
|
55
|
+
/** Injectable for tests. Default `setTimeout`; rejects with the abort reason. */
|
|
56
|
+
sleep?: (ms: number, signal?: AbortSignal | null) => Promise<void>;
|
|
57
|
+
/**
|
|
58
|
+
* Longest `Retry-After` (ms) worth honouring. Beyond it the request is not
|
|
59
|
+
* retried at all. Default 60 000.
|
|
60
|
+
*/
|
|
61
|
+
maxRetryAfter?: number;
|
|
62
|
+
};
|
|
63
|
+
type QueryValue = string | number | boolean | null | undefined;
|
|
64
|
+
/**
|
|
65
|
+
* Query parameters. `null`/`undefined` values are skipped, an array becomes
|
|
66
|
+
* repeated keys (`ids=1&ids=2`), and a `URLSearchParams` is used as is.
|
|
67
|
+
*/
|
|
68
|
+
type QueryParams = Record<string, QueryValue | readonly QueryValue[]> | URLSearchParams;
|
|
69
|
+
/**
|
|
70
|
+
* Headers as config and per-call options accept them: any `HeadersInit`, or a
|
|
71
|
+
* plain object whose `null`/`undefined` values delete that header from the
|
|
72
|
+
* layer underneath (a client default, an inherited header).
|
|
73
|
+
*/
|
|
74
|
+
type HeadersOption = HeadersInit | Record<string, string | null | undefined>;
|
|
75
|
+
//#endregion
|
|
76
|
+
//#region src/error/arthron-error.d.ts
|
|
3
77
|
type ArthronErrorInit = {
|
|
4
78
|
message: string;
|
|
5
79
|
status: number;
|
|
6
80
|
statusText: string;
|
|
7
81
|
headers: Headers;
|
|
8
82
|
data: unknown;
|
|
83
|
+
detail?: string | undefined;
|
|
9
84
|
request: RequestContext;
|
|
10
85
|
response?: Response;
|
|
11
86
|
cause?: unknown;
|
|
@@ -20,42 +95,47 @@ export declare class ArthronError extends Error {
|
|
|
20
95
|
/** HTTP status of the failed response; `0` when fetch itself failed (network). */
|
|
21
96
|
readonly status: number;
|
|
22
97
|
readonly statusText: string;
|
|
23
|
-
/** Response headers; empty for network failures. */
|
|
98
|
+
/** Response headers; empty for network failures. Not enumerable — kept out of logs. */
|
|
24
99
|
readonly headers: Headers;
|
|
25
100
|
/** Parsed body: JSON if it parses, else the text, else `undefined`. */
|
|
26
101
|
readonly data: unknown;
|
|
27
|
-
/**
|
|
102
|
+
/**
|
|
103
|
+
* The server's own explanation, picked out of `data` (by default
|
|
104
|
+
* `message` → `error` → `error.message` → `detail`; see the `errorDetail`
|
|
105
|
+
* config). `undefined` when the body had none. Untrusted server text: show
|
|
106
|
+
* it to users as text, never as HTML. `message`, by contrast, is written by
|
|
107
|
+
* arthron — method, URL without query, status — and is meant for logs.
|
|
108
|
+
*/
|
|
109
|
+
readonly detail: string | undefined;
|
|
110
|
+
/**
|
|
111
|
+
* The context that was sent — url and init after request interceptors.
|
|
112
|
+
* Not enumerable: it holds credentials, so `JSON.stringify`, `console.error`
|
|
113
|
+
* and error trackers leave it out. Read it directly when you need it.
|
|
114
|
+
*/
|
|
28
115
|
readonly request: RequestContext;
|
|
29
|
-
/** The
|
|
116
|
+
/** The failed Response, still readable — its body holds what arthron read (at most 64 KiB). Absent for network failures. Not enumerable. */
|
|
30
117
|
readonly response: Response | undefined;
|
|
31
118
|
/** The underlying error for network failures. */
|
|
32
119
|
readonly cause: unknown;
|
|
33
120
|
constructor(init: ArthronErrorInit);
|
|
121
|
+
/** `instanceof ArthronError` holds for an error from any copy of the package. */
|
|
122
|
+
static [Symbol.hasInstance](value: unknown): boolean;
|
|
123
|
+
/** What serializers see: no headers, no body, no query or userinfo. */
|
|
124
|
+
toJSON(): {
|
|
125
|
+
name: string;
|
|
126
|
+
message: string;
|
|
127
|
+
detail: string | undefined;
|
|
128
|
+
status: number;
|
|
129
|
+
statusText: string;
|
|
130
|
+
method: string;
|
|
131
|
+
url: string;
|
|
132
|
+
data: unknown;
|
|
133
|
+
};
|
|
34
134
|
}
|
|
35
135
|
/** `true` for errors arthron produced: a `!ok` response or a network failure. Cancellations and plugin bugs are not ArthronErrors. */
|
|
36
136
|
export declare function isArthronError(error: unknown): error is ArthronError;
|
|
37
137
|
//#endregion
|
|
38
|
-
//#region src/
|
|
39
|
-
/** One server-sent event, as described by the WHATWG EventSource spec. */
|
|
40
|
-
type SseEvent = {
|
|
41
|
-
/** The `event:` field, when the server sent one. */
|
|
42
|
-
event?: string;
|
|
43
|
-
/** All `data:` lines of the block, joined with `\n`. */
|
|
44
|
-
data: string;
|
|
45
|
-
/** The `id:` field, when present. */
|
|
46
|
-
id?: string;
|
|
47
|
-
/** The `retry:` field in ms, when present and numeric. */
|
|
48
|
-
retry?: number;
|
|
49
|
-
};
|
|
50
|
-
//#endregion
|
|
51
|
-
//#region src/url.d.ts
|
|
52
|
-
type QueryParams = Record<string, string | number | boolean | null | undefined>;
|
|
53
|
-
//#endregion
|
|
54
|
-
//#region src/types.d.ts
|
|
55
|
-
type RequestContext = {
|
|
56
|
-
url: string;
|
|
57
|
-
init: RequestInit;
|
|
58
|
-
};
|
|
138
|
+
//#region src/types/plugin.types.d.ts
|
|
59
139
|
/** Runs before each attempt. Returns the context to send (may be a new object). */
|
|
60
140
|
type RequestInterceptor = (ctx: RequestContext) => RequestContext | Promise<RequestContext>;
|
|
61
141
|
/** Runs after a successful attempt. The body is single-use — `clone()` to peek. */
|
|
@@ -69,67 +149,199 @@ type ErrorInterceptor = (err: ArthronError, ctx: RequestContext) => ArthronError
|
|
|
69
149
|
* failure was a cancellation or a bug in a plugin.
|
|
70
150
|
*/
|
|
71
151
|
type Middleware = (ctx: RequestContext, next: (ctx: RequestContext) => Promise<Response>) => Promise<Response>;
|
|
72
|
-
|
|
73
|
-
/**
|
|
152
|
+
interface Plugin {
|
|
153
|
+
/**
|
|
154
|
+
* Identity within a client: `use`/`extend` replace the plugin of the same
|
|
155
|
+
* name in place, `without(name)` removes it. The built-ins are named
|
|
156
|
+
* "retry", "timeout" and "logging". Leave it out to always append.
|
|
157
|
+
*/
|
|
74
158
|
name?: string;
|
|
75
159
|
middleware?: Middleware;
|
|
76
160
|
request?: RequestInterceptor;
|
|
77
161
|
response?: ResponseInterceptor;
|
|
78
162
|
error?: ErrorInterceptor;
|
|
163
|
+
}
|
|
164
|
+
//#endregion
|
|
165
|
+
//#region src/types/response.types.d.ts
|
|
166
|
+
interface ArthronPromise extends Promise<Response> {
|
|
167
|
+
/** The body as JSON. `T` is a cast — nothing checks it. */
|
|
168
|
+
json<T = unknown>(): Promise<T>;
|
|
169
|
+
/**
|
|
170
|
+
* The body as JSON, validated by a Standard Schema (Zod, Valibot, ArkType…)
|
|
171
|
+
* and typed by it. A mismatch rejects with a `SchemaError`.
|
|
172
|
+
*/
|
|
173
|
+
json<S extends StandardSchemaV1>(schema: S): Promise<InferOutput<S>>;
|
|
174
|
+
text(): Promise<string>;
|
|
175
|
+
blob(): Promise<Blob>;
|
|
176
|
+
arrayBuffer(): Promise<ArrayBuffer>;
|
|
177
|
+
formData(): Promise<FormData>;
|
|
178
|
+
/** Iterate a `text/event-stream` body as events. */
|
|
179
|
+
sse(options?: SseOptions): AsyncIterable<SseEvent>;
|
|
180
|
+
/** Iterate a newline-delimited JSON body, one parsed value per line. */
|
|
181
|
+
ndjson<T = unknown>(options?: NdjsonOptions): AsyncIterable<T>;
|
|
182
|
+
}
|
|
183
|
+
/** One server-sent event, as described by the WHATWG EventSource spec. */
|
|
184
|
+
type SseEvent = {
|
|
185
|
+
/** The `event:` field, when the server sent one. */
|
|
186
|
+
event?: string;
|
|
187
|
+
/** All `data:` lines of the block, joined with `\n`. */
|
|
188
|
+
data: string;
|
|
189
|
+
/** The `id:` field of this event's own block, when it had one. */
|
|
190
|
+
id?: string;
|
|
191
|
+
/**
|
|
192
|
+
* The last event ID so far, as EventSource's `lastEventId`: it persists
|
|
193
|
+
* across events (a block with only `id:` updates it too) and is "" until
|
|
194
|
+
* the server sends one. Send it as `Last-Event-ID` to resume a stream.
|
|
195
|
+
*/
|
|
196
|
+
lastEventId: string;
|
|
197
|
+
/** The reconnection time in ms the server last set with `retry:`; carried on every event after it. */
|
|
198
|
+
retry?: number;
|
|
79
199
|
};
|
|
80
|
-
type
|
|
81
|
-
|
|
200
|
+
type NdjsonOptions = {
|
|
201
|
+
/**
|
|
202
|
+
* Longest line accepted, in characters. A longer one rejects the iteration
|
|
203
|
+
* with a RangeError and cancels the body. Default 8 Mi.
|
|
204
|
+
*/
|
|
205
|
+
maxLineLength?: number;
|
|
82
206
|
};
|
|
83
|
-
type
|
|
84
|
-
|
|
85
|
-
|
|
207
|
+
type SseOptions = NdjsonOptions & {
|
|
208
|
+
/**
|
|
209
|
+
* Most `data` one event may collect before its blank line, in characters.
|
|
210
|
+
* More rejects the iteration with a RangeError and cancels the body.
|
|
211
|
+
* Default 8 Mi.
|
|
212
|
+
*/
|
|
213
|
+
maxEventSize?: number;
|
|
214
|
+
};
|
|
215
|
+
/**
|
|
216
|
+
* The Standard Schema interface (https://standardschema.dev), vendored as
|
|
217
|
+
* types only so arthron keeps zero dependencies. Zod, Valibot, ArkType and
|
|
218
|
+
* others implement it, so their schemas can be passed to `.json(schema)`.
|
|
219
|
+
*/
|
|
220
|
+
interface StandardSchemaV1<Input = unknown, Output = Input> {
|
|
221
|
+
readonly "~standard": {
|
|
222
|
+
readonly version: 1;
|
|
223
|
+
readonly vendor: string;
|
|
224
|
+
readonly validate: (value: unknown) => SchemaResult<Output> | Promise<SchemaResult<Output>>;
|
|
225
|
+
readonly types?: {
|
|
226
|
+
readonly input: Input;
|
|
227
|
+
readonly output: Output;
|
|
228
|
+
} | undefined;
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
type SchemaResult<Output> = {
|
|
232
|
+
readonly value: Output;
|
|
233
|
+
readonly issues?: undefined;
|
|
234
|
+
} | {
|
|
235
|
+
readonly issues: readonly SchemaIssue[];
|
|
86
236
|
};
|
|
87
|
-
|
|
237
|
+
interface SchemaIssue {
|
|
238
|
+
readonly message: string;
|
|
239
|
+
readonly path?: readonly (PropertyKey | {
|
|
240
|
+
readonly key: PropertyKey;
|
|
241
|
+
})[] | undefined;
|
|
242
|
+
}
|
|
243
|
+
/** The type a schema produces. */
|
|
244
|
+
type InferOutput<S extends StandardSchemaV1> = NonNullable<S["~standard"]["types"]>["output"];
|
|
245
|
+
type ErrorDetailResolver = (data: unknown, response: Response) => string | undefined;
|
|
246
|
+
//#endregion
|
|
247
|
+
//#region src/client/client.types.d.ts
|
|
248
|
+
/**
|
|
249
|
+
* The methods arthron knows by name; any other string is sent as written.
|
|
250
|
+
* The standard ones go out uppercased whatever their case — fetch itself
|
|
251
|
+
* only normalizes six of them, so a lowercase "patch" would draw a 405.
|
|
252
|
+
*/
|
|
253
|
+
type HttpMethod = "GET" | "HEAD" | "POST" | "PUT" | "PATCH" | "DELETE" | "OPTIONS" | "QUERY" | (string & {});
|
|
254
|
+
/**
|
|
255
|
+
* Per-call options. Public types are interfaces, so a plugin package can add
|
|
256
|
+
* its own options by augmentation (`declare module "arthron"`).
|
|
257
|
+
*/
|
|
258
|
+
interface RequestOptions extends Omit<RequestInit, "body" | "method" | "headers"> {
|
|
259
|
+
/** Per-call headers; a `null`/`undefined` value drops a client default. */
|
|
260
|
+
headers?: HeadersOption;
|
|
261
|
+
params?: QueryParams;
|
|
262
|
+
/**
|
|
263
|
+
* Values for `{name}` placeholders in the path, each encoded into its own
|
|
264
|
+
* segment: `get("/users/{id}", { path: { id } })`. Interpolating ids into
|
|
265
|
+
* the path string yourself lets "../" or "?" escape the segment.
|
|
266
|
+
*/
|
|
267
|
+
path?: Record<string, string | number>;
|
|
268
|
+
/** Settings for plugins on this call only (see `ArthronMeta`). Not sent. */
|
|
269
|
+
meta?: ArthronMeta;
|
|
270
|
+
/** Which non-ok responses reject on this call; overrides the client's `throwOn`. */
|
|
271
|
+
throwOn?: (res: Response) => boolean;
|
|
272
|
+
}
|
|
273
|
+
/** `request()`'s options: any method, with the same body rules as `post`. */
|
|
274
|
+
interface RequestInitWithBody extends RequestOptions {
|
|
275
|
+
method: HttpMethod;
|
|
276
|
+
body?: unknown;
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* The fetch options a client can set as defaults: the same `RequestInit`
|
|
280
|
+
* fields per-call options take, minus what only makes sense per call —
|
|
281
|
+
* `body`, `method`, `signal` (one client-wide signal, once aborted, would
|
|
282
|
+
* fail every later call) and `window`. `headers` has its own merge rules.
|
|
283
|
+
*/
|
|
284
|
+
type FetchDefaults = Omit<RequestInit, "body" | "method" | "headers" | "signal" | "window">;
|
|
285
|
+
/**
|
|
286
|
+
* Client config. Besides arthron's own keys it takes any fetch option as a
|
|
287
|
+
* default (`credentials`, `cache`, `redirect`, `mode`, …), flat like per-call
|
|
288
|
+
* options; a per-call value wins.
|
|
289
|
+
*/
|
|
290
|
+
interface ArthronConfig extends FetchDefaults {
|
|
88
291
|
/** Prefix for relative paths. Without it only absolute URLs are accepted. */
|
|
89
292
|
baseURL?: string;
|
|
90
|
-
/**
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
293
|
+
/**
|
|
294
|
+
* Let an absolute URL on another origin than `baseURL` through. Off by
|
|
295
|
+
* default, so a path from user input or an API response cannot send the
|
|
296
|
+
* client's headers elsewhere; config `headers` are never sent to another
|
|
297
|
+
* origin even when this is on.
|
|
298
|
+
*/
|
|
299
|
+
allowAbsoluteUrls?: boolean;
|
|
300
|
+
/** Default headers. Per-call headers win, compared case-insensitively; `extend` can drop one with `null`. */
|
|
301
|
+
headers?: HeadersOption;
|
|
94
302
|
/** Injection point for tests and polyfills. Defaults to `globalThis.fetch`. */
|
|
95
303
|
fetch?: typeof fetch;
|
|
96
304
|
use?: Plugin[];
|
|
97
305
|
/** How to pick a message out of an error body. */
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
/** Iterate a newline-delimited JSON body, one parsed value per line. */
|
|
109
|
-
ndjson<T = unknown>(): AsyncIterable<T>;
|
|
110
|
-
};
|
|
111
|
-
type Arthron = {
|
|
306
|
+
errorDetail?: ErrorDetailResolver;
|
|
307
|
+
/**
|
|
308
|
+
* Which non-ok responses reject with an ArthronError — return `false` to
|
|
309
|
+
* get the Response instead (a 404 that is data, say). An ok response never
|
|
310
|
+
* rejects. Default: every non-ok response except an opaque one
|
|
311
|
+
* (`mode: "no-cors"`) and the 3xx of `redirect: "manual"`.
|
|
312
|
+
*/
|
|
313
|
+
throwOn?: (res: Response) => boolean;
|
|
314
|
+
}
|
|
315
|
+
interface Arthron {
|
|
112
316
|
get(path: string, init?: RequestOptions): ArthronPromise;
|
|
113
317
|
delete(path: string, init?: RequestOptions): ArthronPromise;
|
|
114
318
|
head(path: string, init?: RequestOptions): ArthronPromise;
|
|
115
319
|
post(path: string, body?: unknown, init?: RequestOptions): ArthronPromise;
|
|
116
320
|
put(path: string, body?: unknown, init?: RequestOptions): ArthronPromise;
|
|
117
321
|
patch(path: string, body?: unknown, init?: RequestOptions): ArthronPromise;
|
|
322
|
+
/** RFC 10008 QUERY: safe and idempotent like GET, but the query travels in the body. */
|
|
323
|
+
query(path: string, body?: unknown, init?: RequestOptions): ArthronPromise;
|
|
324
|
+
/** Any method — the extension point for verbs without their own helper. */
|
|
118
325
|
request(path: string, init: RequestInitWithBody): ArthronPromise;
|
|
119
|
-
/**
|
|
326
|
+
/**
|
|
327
|
+
* New client with these plugins added: a named one replaces the plugin of
|
|
328
|
+
* that name in place, an unnamed one appends. The receiver is untouched.
|
|
329
|
+
*/
|
|
120
330
|
use(...plugins: Plugin[]): Arthron;
|
|
121
|
-
/** New client with config shallow-merged, headers merged, plugins
|
|
331
|
+
/** New client with config shallow-merged, headers merged, plugins added as `use` adds them. */
|
|
122
332
|
extend(config: Partial<ArthronConfig>): Arthron;
|
|
123
|
-
|
|
333
|
+
/** New client without the plugins of these names. The receiver is untouched. */
|
|
334
|
+
without(...names: string[]): Arthron;
|
|
335
|
+
}
|
|
124
336
|
//#endregion
|
|
125
|
-
//#region src/client.d.ts
|
|
337
|
+
//#region src/client/client.d.ts
|
|
126
338
|
/**
|
|
127
339
|
* Build a client from config. The result is immutable — `use` and `extend`
|
|
128
340
|
* return new clients and never touch the one they were called on.
|
|
129
341
|
*/
|
|
130
342
|
export declare function arthron(config?: ArthronConfig): Arthron;
|
|
131
343
|
//#endregion
|
|
132
|
-
//#region src/define.d.ts
|
|
344
|
+
//#region src/pipeline/define-plugin.d.ts
|
|
133
345
|
/** Identity helper: gives a middleware written in its own file the right parameter types. */
|
|
134
346
|
export declare const defineMiddleware: (middleware: Middleware) => Middleware;
|
|
135
347
|
/** Identity helpers for each interceptor kind — `defineInterceptor.request(fn)` etc. */
|
|
@@ -141,7 +353,7 @@ export declare const defineInterceptor: {
|
|
|
141
353
|
/** Identity helper: type-checks a plugin object literal without an annotation. */
|
|
142
354
|
export declare const definePlugin: (plugin: Plugin) => Plugin;
|
|
143
355
|
//#endregion
|
|
144
|
-
//#region src/plugins/logging.d.ts
|
|
356
|
+
//#region src/plugins/logging/logging.types.d.ts
|
|
145
357
|
type LogEventBase = {
|
|
146
358
|
method: string;
|
|
147
359
|
path: string;
|
|
@@ -168,6 +380,8 @@ type LoggingOptions = {
|
|
|
168
380
|
/** Clock in ms. Injectable for tests. */
|
|
169
381
|
now?: () => number;
|
|
170
382
|
};
|
|
383
|
+
//#endregion
|
|
384
|
+
//#region src/plugins/logging/logging.d.ts
|
|
171
385
|
/**
|
|
172
386
|
* One event when a request starts, one when it settles, with status and
|
|
173
387
|
* elapsed time. Wraps the whole call, so retries are included in the time.
|
|
@@ -176,44 +390,53 @@ type LoggingOptions = {
|
|
|
176
390
|
*/
|
|
177
391
|
export declare function logging(options?: LoggingOptions): Plugin;
|
|
178
392
|
//#endregion
|
|
179
|
-
//#region src/plugins/retry.d.ts
|
|
180
|
-
type RetryOptions = {
|
|
181
|
-
/** Number of retries after the first attempt. Default 2 (3 requests total). */
|
|
182
|
-
retries?: number;
|
|
183
|
-
/** Statuses worth retrying. Network errors (status 0) always are. */
|
|
184
|
-
retryOn?: readonly number[];
|
|
185
|
-
/** Methods safe to repeat. Compared case-insensitively. */
|
|
186
|
-
methods?: readonly string[];
|
|
187
|
-
/** Backoff in ms for retry number `retry` (0-based). Default 300 · 2^retry. */
|
|
188
|
-
delay?: (retry: number, error: ArthronError) => number;
|
|
189
|
-
/** Injectable for tests. Default `setTimeout`; rejects with the abort reason. */
|
|
190
|
-
sleep?: (ms: number, signal?: AbortSignal | null) => Promise<void>;
|
|
191
|
-
/**
|
|
192
|
-
* Longest `Retry-After` (ms) worth honouring. Beyond it the request is not
|
|
193
|
-
* retried at all. Default 60 000. Also guards `setTimeout`'s 2^31-1 ms cap,
|
|
194
|
-
* past which timers fire immediately.
|
|
195
|
-
*/
|
|
196
|
-
maxRetryAfter?: number;
|
|
197
|
-
};
|
|
393
|
+
//#region src/plugins/retry/retry.d.ts
|
|
198
394
|
/**
|
|
199
395
|
* Retry on network errors and the configured statuses by calling `next`
|
|
200
396
|
* again — the whole attempt (request interceptors included) is re-run.
|
|
201
397
|
* Only `ArthronError` is considered; cancellation and plugin bugs pass through.
|
|
398
|
+
* A call can turn it off or override its options with `meta.retry`.
|
|
202
399
|
*/
|
|
203
400
|
export declare function retry(options?: RetryOptions): Plugin;
|
|
204
401
|
//#endregion
|
|
205
|
-
//#region src/plugins/timeout.d.ts
|
|
402
|
+
//#region src/plugins/timeout/timeout.types.d.ts
|
|
403
|
+
type TimeoutOptions = {
|
|
404
|
+
/**
|
|
405
|
+
* Also abort when no data has arrived for this many ms — while waiting for
|
|
406
|
+
* the headers and between body chunks. Unlike the total deadline, a stream
|
|
407
|
+
* that keeps flowing is never cut off: `timeout(Infinity, { idle: 30_000 })`.
|
|
408
|
+
*/
|
|
409
|
+
idle?: number;
|
|
410
|
+
};
|
|
411
|
+
//#endregion
|
|
412
|
+
//#region src/plugins/timeout/timeout.d.ts
|
|
206
413
|
/**
|
|
207
414
|
* Abort the request when it takes longer than `ms` — counted from the start
|
|
208
415
|
* of the attempt until the body has been fully read, so a server that sends
|
|
209
|
-
* headers and then stalls still trips it.
|
|
416
|
+
* headers and then stalls still trips it. With `idle`, also abort once no
|
|
417
|
+
* data has arrived for that long. Rejects with a `TimeoutError` (a
|
|
210
418
|
* `DOMException`, like `AbortSignal.timeout()` would give); it is not an
|
|
211
419
|
* `ArthronError`, so error interceptors and `retry` leave it alone.
|
|
212
420
|
*
|
|
213
|
-
*
|
|
214
|
-
*
|
|
421
|
+
* A call can change the total deadline with `meta.timeout`.
|
|
422
|
+
*
|
|
423
|
+
* Deadlines are timers on an AbortController — not `AbortSignal.timeout`,
|
|
424
|
+
* since the idle one restarts — joined to the caller's signal with
|
|
425
|
+
* `AbortSignal.any`.
|
|
215
426
|
*/
|
|
216
|
-
export declare function timeout(ms: number): Plugin;
|
|
427
|
+
export declare function timeout(ms: number, options?: TimeoutOptions): Plugin;
|
|
428
|
+
//#endregion
|
|
429
|
+
//#region src/response/schema-validation.d.ts
|
|
430
|
+
/**
|
|
431
|
+
* `.json(schema)` got a body that does not match. Not an ArthronError: the
|
|
432
|
+
* request succeeded — the data is what is wrong.
|
|
433
|
+
*/
|
|
434
|
+
export declare class SchemaError extends Error {
|
|
435
|
+
readonly name = "SchemaError";
|
|
436
|
+
/** Every problem the validator reported, with the path to it. */
|
|
437
|
+
readonly issues: readonly SchemaIssue[];
|
|
438
|
+
constructor(issues: readonly SchemaIssue[]);
|
|
439
|
+
}
|
|
217
440
|
//#endregion
|
|
218
|
-
export type { Arthron, ArthronConfig, ArthronPromise, ErrorInterceptor,
|
|
441
|
+
export type { Arthron, ArthronConfig, ArthronMeta, ArthronPromise, ErrorDetailResolver, ErrorInterceptor, HeadersOption, HttpMethod, InferOutput, LogEvent, LoggingOptions, Middleware, NdjsonOptions, Plugin, QueryParams, RequestContext, RequestInitWithBody, RequestInterceptor, RequestOptions, ResponseInterceptor, RetryOptions, SchemaIssue, SseEvent, SseOptions, StandardSchemaV1, TimeoutOptions };
|
|
219
442
|
//# sourceMappingURL=index.d.cts.map
|