@npora/request 1.14.4 → 1.15.1
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 +231 -5
- package/dist/MockAdapter-ChWzzSnH.d.cts +71 -0
- package/dist/MockAdapter-H50LoFDu.d.ts +71 -0
- package/dist/Plugin-0Eh51_et.d.ts +124 -0
- package/dist/Plugin-YysllE6z.d.cts +124 -0
- package/dist/PluginError-CcuPSIRv.js +1 -0
- package/dist/PluginError-DT3VnlUB.cjs +1 -0
- package/dist/PluginError-DVP3pUt_.d.cts +18 -0
- package/dist/PluginError-DVP3pUt_.d.ts +18 -0
- package/dist/RequestError-BH6V64XR.js +1 -0
- package/dist/RequestError-DPSv-HVF.cjs +1 -0
- package/dist/SchemaValidationError-CjvWT8YA.d.ts +166 -0
- package/dist/SchemaValidationError-WMTfqSBV.d.cts +166 -0
- package/dist/adapter-BeVVCcNG.d.cts +21 -0
- package/dist/adapter-ODzpt_dM.d.ts +21 -0
- package/dist/authPlugin-6E6_0dAO.d.ts +53 -0
- package/dist/authPlugin-B_YpkyC8.d.cts +53 -0
- package/dist/buildRequest-BRZwRLoN.cjs +1 -0
- package/dist/buildRequest-Cwt8XEWO.js +1 -0
- package/dist/cachePlugin-B9Hvsprg.d.cts +297 -0
- package/dist/cachePlugin-CSHwJYwI.js +1 -0
- package/dist/cachePlugin-CvH26DBo.d.ts +297 -0
- package/dist/cachePlugin-ZPYdHbsM.cjs +1 -0
- package/dist/circuitBreakerPlugin-B45xghq9.d.cts +59 -0
- package/dist/circuitBreakerPlugin-DsH6YCNe.d.ts +59 -0
- package/dist/concurrencyPlugin-CuJMua41.d.cts +48 -0
- package/dist/concurrencyPlugin-dwGNFYrM.d.ts +48 -0
- package/dist/core.cjs +1 -0
- package/dist/core.d.cts +6 -0
- package/dist/core.d.ts +6 -0
- package/dist/core.js +1 -0
- package/dist/createAbortError-D4rRBq2B.js +1 -0
- package/dist/createAbortError-DJqbdYgk.cjs +1 -0
- package/dist/createClient-CibOTVAy.cjs +1 -0
- package/dist/createClient-I13D6XsD.js +1 -0
- package/dist/downloadPlugin-CEXXJiDo.d.cts +17 -0
- package/dist/downloadPlugin-s8VS8t9r.d.ts +17 -0
- package/dist/index.cjs +1 -4
- package/dist/index.d.cts +15 -1028
- package/dist/index.d.ts +15 -1028
- package/dist/index.js +1 -4
- package/dist/isPromiseLike-BuAv3bAe.js +1 -0
- package/dist/isPromiseLike-C8e95Or2.cjs +1 -0
- package/dist/isURLSearchParams-B93cMCGj.js +1 -0
- package/dist/isURLSearchParams-o-c8Q42t.cjs +1 -0
- package/dist/loggerPlugin-C15EW7Sc.d.ts +6 -0
- package/dist/loggerPlugin-uOFiUtBi.d.cts +6 -0
- package/dist/maxTimerDelay-Hn7X0Wuh.js +1 -0
- package/dist/maxTimerDelay-NH5XeTXb.cjs +1 -0
- package/dist/plugins/auth.cjs +1 -0
- package/dist/plugins/auth.d.cts +2 -0
- package/dist/plugins/auth.d.ts +2 -0
- package/dist/plugins/auth.js +1 -0
- package/dist/plugins/cache.cjs +1 -0
- package/dist/plugins/cache.d.cts +2 -0
- package/dist/plugins/cache.d.ts +2 -0
- package/dist/plugins/cache.js +1 -0
- package/dist/plugins/circuit-breaker.cjs +1 -0
- package/dist/plugins/circuit-breaker.d.cts +2 -0
- package/dist/plugins/circuit-breaker.d.ts +2 -0
- package/dist/plugins/circuit-breaker.js +1 -0
- package/dist/plugins/concurrency.cjs +1 -0
- package/dist/plugins/concurrency.d.cts +2 -0
- package/dist/plugins/concurrency.d.ts +2 -0
- package/dist/plugins/concurrency.js +1 -0
- package/dist/plugins/download.cjs +1 -0
- package/dist/plugins/download.d.cts +2 -0
- package/dist/plugins/download.d.ts +2 -0
- package/dist/plugins/download.js +1 -0
- package/dist/plugins/logger.cjs +1 -0
- package/dist/plugins/logger.d.cts +2 -0
- package/dist/plugins/logger.d.ts +2 -0
- package/dist/plugins/logger.js +1 -0
- package/dist/plugins/retry.cjs +1 -0
- package/dist/plugins/retry.d.cts +2 -0
- package/dist/plugins/retry.d.ts +2 -0
- package/dist/plugins/retry.js +1 -0
- package/dist/plugins/upload.cjs +1 -0
- package/dist/plugins/upload.d.cts +2 -0
- package/dist/plugins/upload.d.ts +2 -0
- package/dist/plugins/upload.js +1 -0
- package/dist/plugins.cjs +1 -0
- package/dist/plugins.d.cts +11 -0
- package/dist/plugins.d.ts +11 -0
- package/dist/plugins.js +1 -0
- package/dist/resolveExtensionConfig-BHHfQwjF.cjs +1 -0
- package/dist/resolveExtensionConfig-QAFHZVte.js +1 -0
- package/dist/resolveRequestOrigin-BndIJeZ7.js +1 -0
- package/dist/resolveRequestOrigin-CRATeWff.cjs +1 -0
- package/dist/response-BhyS3PAL.d.cts +441 -0
- package/dist/response-BhyS3PAL.d.ts +441 -0
- package/dist/retryPlugin-2mYKvWy3.d.ts +6 -0
- package/dist/retryPlugin-BqlUpmd0.d.cts +6 -0
- package/dist/testing.cjs +1 -0
- package/dist/testing.d.cts +2 -0
- package/dist/testing.d.ts +2 -0
- package/dist/testing.js +1 -0
- package/dist/uploadPlugin-AfhFIsO7.d.cts +5 -0
- package/dist/uploadPlugin-Bb7EawRX.d.ts +5 -0
- package/dist/validateResponseStatus-Dqzr342t.js +4 -0
- package/dist/validateResponseStatus-QAjcah2i.cjs +4 -0
- package/dist/waitForSignal-DyyPvJd5.js +1 -0
- package/dist/waitForSignal-yR1BeU8f.cjs +1 -0
- package/dist/xhrTransport-C0pg00i5.js +1 -0
- package/dist/xhrTransport-CeW2DDzo.cjs +1 -0
- package/package.json +65 -2
package/README.md
CHANGED
|
@@ -31,6 +31,20 @@ authentication, and upload/download progress.
|
|
|
31
31
|
verifies public exports, browser behavior, security regressions, and size
|
|
32
32
|
budgets before release.
|
|
33
33
|
|
|
34
|
+
## Design focus
|
|
35
|
+
|
|
36
|
+
Npora Request combines runtime validation, incremental streaming, persistent
|
|
37
|
+
cache correctness, resilience, observability, and cancellation under one
|
|
38
|
+
typed, deterministic lifecycle. It keeps the standard Fetch model, ships with
|
|
39
|
+
zero runtime dependencies, supports ESM and CommonJS, and exposes optional
|
|
40
|
+
capabilities through tree-shakeable subpath exports.
|
|
41
|
+
|
|
42
|
+
The current stress gate completed **10,000,000 logical operations at concurrency
|
|
43
|
+
256 with zero unexpected failures**, followed by **100,000 real localhost HTTP
|
|
44
|
+
requests at concurrency 256**. These are reproducible engineering checks, not
|
|
45
|
+
claims about every remote workload; commands and limitations are in the
|
|
46
|
+
[benchmark documentation](docs/benchmark.md).
|
|
47
|
+
|
|
34
48
|
## Features
|
|
35
49
|
|
|
36
50
|
- Data-first and complete-response APIs with TypeScript inference.
|
|
@@ -232,6 +246,20 @@ api.ndjsonResponse(url, config)
|
|
|
232
246
|
|
|
233
247
|
## Plugins
|
|
234
248
|
|
|
249
|
+
Applications can keep using the backward-compatible root entry, or import
|
|
250
|
+
only the client and plugins they need:
|
|
251
|
+
|
|
252
|
+
```ts
|
|
253
|
+
import { createClient } from '@npora/request/core'
|
|
254
|
+
import { retryPlugin } from '@npora/request/plugins/retry'
|
|
255
|
+
|
|
256
|
+
const request = createClient().use(retryPlugin({ retries: 2 }))
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
`MockAdapter` is also available from `@npora/request/testing` and
|
|
260
|
+
`@npora/request/adapters/mock` so test-only utilities do not need to be
|
|
261
|
+
imported through the production entry point.
|
|
262
|
+
|
|
235
263
|
```ts
|
|
236
264
|
import {
|
|
237
265
|
authPlugin,
|
|
@@ -277,13 +305,211 @@ connect an external storage system:
|
|
|
277
305
|
```ts
|
|
278
306
|
const cache = cachePlugin({
|
|
279
307
|
store: sharedStore,
|
|
280
|
-
dedupe: true
|
|
308
|
+
dedupe: true,
|
|
309
|
+
onEvent(event) {
|
|
310
|
+
metrics.increment(`cache.${event.type}`)
|
|
311
|
+
}
|
|
312
|
+
})
|
|
313
|
+
```
|
|
314
|
+
|
|
315
|
+
Use `cache.getStats()` for a snapshot of hits, misses, bypasses,
|
|
316
|
+
invalidations, deduplication, revalidation, stale recovery, and background
|
|
317
|
+
refresh outcomes.
|
|
318
|
+
`cache.resetStats()` resets only these counters; it does not clear entries.
|
|
319
|
+
Events contain only a decision type and timestamp, never URLs, cache keys, or
|
|
320
|
+
headers. Observer failures do not affect requests.
|
|
321
|
+
Failed manual or automatic invalidations are counted in
|
|
322
|
+
`invalidationErrors` and emit `invalidation-error` without exposing the error.
|
|
323
|
+
|
|
324
|
+
Seed or optimistically update parsed cache data without a network request:
|
|
325
|
+
|
|
326
|
+
```ts
|
|
327
|
+
await cache.set({ url: '/users/1' }, user, {
|
|
328
|
+
ttl: 30000,
|
|
329
|
+
tags: ['user:1']
|
|
330
|
+
})
|
|
331
|
+
|
|
332
|
+
await cache.update<User>({ url: '/users/1' }, current => ({
|
|
333
|
+
...current,
|
|
334
|
+
name: 'Updated locally'
|
|
335
|
+
}))
|
|
336
|
+
```
|
|
337
|
+
|
|
338
|
+
Return `undefined` from `update` to delete the entry. It returns `false` when
|
|
339
|
+
no entry exists. These operations use the same effective cache key as requests,
|
|
340
|
+
wait for overlapping asynchronous store operations, and prevent older
|
|
341
|
+
same-key responses from overwriting the new value.
|
|
342
|
+
|
|
343
|
+
Delete one entry without flushing unrelated cached responses:
|
|
344
|
+
|
|
345
|
+
```ts
|
|
346
|
+
await cache.delete({
|
|
347
|
+
url: '/users/1',
|
|
348
|
+
baseURL: '/api',
|
|
349
|
+
extensions: {
|
|
350
|
+
cache: { enabled: true }
|
|
351
|
+
}
|
|
352
|
+
})
|
|
353
|
+
```
|
|
354
|
+
|
|
355
|
+
Pass the effective request configuration used to create the entry, including
|
|
356
|
+
merged `baseURL`, query, response type, and representation headers. A custom
|
|
357
|
+
`extensions.cache.key` can be deleted without reproducing those dimensions.
|
|
358
|
+
|
|
359
|
+
Group related entries with bounded cache tags and invalidate them together:
|
|
360
|
+
|
|
361
|
+
```ts
|
|
362
|
+
await request.get('/users/1', {
|
|
363
|
+
extensions: {
|
|
364
|
+
cache: {
|
|
365
|
+
enabled: true,
|
|
366
|
+
tags: ['user:1', 'users']
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
})
|
|
370
|
+
|
|
371
|
+
await cache.invalidateTags('user:1')
|
|
372
|
+
```
|
|
373
|
+
|
|
374
|
+
The default memory store supports tags directly. Custom stores must implement
|
|
375
|
+
the optional `CacheStore.invalidateTags()` capability.
|
|
376
|
+
|
|
377
|
+
Persist JSON-compatible cached data across client instances with isolated
|
|
378
|
+
browser storage:
|
|
379
|
+
|
|
380
|
+
```ts
|
|
381
|
+
import { WebStorageCacheStore } from '@npora/request/plugins/cache'
|
|
382
|
+
|
|
383
|
+
const cache = cachePlugin({
|
|
384
|
+
store: new WebStorageCacheStore(sessionStorage, {
|
|
385
|
+
namespace: 'dashboard-v1',
|
|
386
|
+
maxEntries: 250
|
|
387
|
+
})
|
|
388
|
+
})
|
|
389
|
+
```
|
|
390
|
+
|
|
391
|
+
Use `localStorage` only when responses may safely survive browser restarts and
|
|
392
|
+
sign-out boundaries. The adapter never persists native `Response` objects;
|
|
393
|
+
`getResponse()` refetches when raw bytes are required.
|
|
394
|
+
|
|
395
|
+
For larger values and non-blocking storage, use IndexedDB instead:
|
|
396
|
+
|
|
397
|
+
```ts
|
|
398
|
+
import { IndexedDBCacheStore } from '@npora/request/plugins/cache'
|
|
399
|
+
|
|
400
|
+
const store = new IndexedDBCacheStore(indexedDB, {
|
|
401
|
+
databaseName: 'dashboard-cache',
|
|
402
|
+
namespace: 'account:1',
|
|
403
|
+
schemaVersion: 2,
|
|
404
|
+
maxEntries: 500,
|
|
405
|
+
maxBytes: 20 * 1024 * 1024,
|
|
406
|
+
shouldPersist: (entry, bytes) => (
|
|
407
|
+
entry.status === 200 && bytes < 2 * 1024 * 1024
|
|
408
|
+
),
|
|
409
|
+
onEvent: event => metrics.record('persistent-cache', event)
|
|
410
|
+
})
|
|
411
|
+
const cache = cachePlugin({ store })
|
|
412
|
+
```
|
|
413
|
+
|
|
414
|
+
IndexedDB uses structured cloning, preserving values such as `Blob`, `Date`,
|
|
415
|
+
`Map`, typed arrays, and `BigInt` while still omitting native `Response` bodies.
|
|
416
|
+
Increment the positive integer `schemaVersion` whenever the cached data shape
|
|
417
|
+
becomes incompatible. Older records are isolated and pruned automatically;
|
|
418
|
+
the default version `1` continues to read records created before this option
|
|
419
|
+
existed. Older clients preserve every higher-version record without validating
|
|
420
|
+
its envelope, including during writes, clearing, compaction, and quota
|
|
421
|
+
recovery, so rolling deployments remain safe when the persisted structure
|
|
422
|
+
changes completely.
|
|
423
|
+
`maxBytes` adds an approximate structured-clone byte budget alongside
|
|
424
|
+
`maxEntries`. Oversized entries are skipped and older entries are evicted by
|
|
425
|
+
LRU. Quota-exceeded writes remove the oldest half of the current schema cache
|
|
426
|
+
and retry once by default; set `quotaRecovery: false` to report the first quota
|
|
427
|
+
failure without recovery.
|
|
428
|
+
Use `await store.getUsage()` to inspect the current schema's aggregate entry
|
|
429
|
+
count and estimated bytes. The optional `onEvent` observer reports aggregated
|
|
430
|
+
eviction, recovery, cleanup, and oversized-entry rejection events without
|
|
431
|
+
exposing keys, namespaces, URLs, or response data. Observer failures never
|
|
432
|
+
affect cache operations.
|
|
433
|
+
Use `shouldPersist(entry, estimatedBytes)` for application-specific admission,
|
|
434
|
+
such as excluding sensitive payloads, one-hit responses, or large low-value
|
|
435
|
+
objects. It may return a boolean or promise. Returning `false` removes an older
|
|
436
|
+
same-key value and emits an aggregate `admission-policy` rejection; thrown
|
|
437
|
+
errors are reported to the caller and leave the old value unchanged.
|
|
438
|
+
Run bounded maintenance without loading the namespace into memory:
|
|
439
|
+
|
|
440
|
+
```ts
|
|
441
|
+
const result = await store.compact({
|
|
442
|
+
// Preserve seven days for stale-if-error recovery.
|
|
443
|
+
expiredBefore: Date.now() - 7 * 24 * 60 * 60 * 1000,
|
|
444
|
+
maxRemovals: 500
|
|
281
445
|
})
|
|
282
446
|
```
|
|
283
447
|
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
448
|
+
`compact()` removes current-schema entries beyond the chosen stale boundary,
|
|
449
|
+
reports aggregate scan/removal/byte counts, and emits privacy-safe `expired`
|
|
450
|
+
events. Repeat while `hasMore` is true when using `maxRemovals`. Usage
|
|
451
|
+
inspection now streams records through an IndexedDB cursor, avoiding a
|
|
452
|
+
namespace-sized result array.
|
|
453
|
+
|
|
454
|
+
Combine memory speed with persistence through a read-through, write-through
|
|
455
|
+
store:
|
|
456
|
+
|
|
457
|
+
```ts
|
|
458
|
+
const persistent = new IndexedDBCacheStore(indexedDB, {
|
|
459
|
+
namespace: 'account:1',
|
|
460
|
+
schemaVersion: 2
|
|
461
|
+
})
|
|
462
|
+
const channel = new BroadcastChannel('dashboard-cache:account:1:v1')
|
|
463
|
+
const store = new TieredCacheStore({
|
|
464
|
+
primary: new MemoryCacheStore({ maxEntries: 100 }),
|
|
465
|
+
secondary: persistent,
|
|
466
|
+
broadcast: { channel },
|
|
467
|
+
coordination: {
|
|
468
|
+
locks: navigator.locks,
|
|
469
|
+
namespace: 'dashboard-cache:account:1:v1'
|
|
470
|
+
}
|
|
471
|
+
})
|
|
472
|
+
const cache = cachePlugin({
|
|
473
|
+
store
|
|
474
|
+
})
|
|
475
|
+
```
|
|
476
|
+
|
|
477
|
+
Hot reads remain synchronous. Cold secondary hits are promoted to memory, and
|
|
478
|
+
writes reach the persistent tier before becoming visible in memory. The
|
|
479
|
+
optional channel evicts stale primary entries in other tabs without sending
|
|
480
|
+
URLs, headers, response data, or complete cache keys. Call `store.dispose()`
|
|
481
|
+
and `channel.close()` when the context is torn down. Optional Web Locks
|
|
482
|
+
coordination serializes same-key refreshes across tabs; waiters reread the
|
|
483
|
+
shared secondary cache instead of issuing a duplicate request. Omit
|
|
484
|
+
`coordination` where `navigator.locks` is unavailable.
|
|
485
|
+
Mutation requests can invalidate tags automatically after their final success:
|
|
486
|
+
|
|
487
|
+
```ts
|
|
488
|
+
await request.patch('/users/1', {
|
|
489
|
+
json: update,
|
|
490
|
+
extensions: {
|
|
491
|
+
cache: {
|
|
492
|
+
invalidateTags: ['user:1', 'users']
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
})
|
|
496
|
+
```
|
|
497
|
+
|
|
498
|
+
Final HTTP, Schema, interceptor, cancellation, and exhausted-retry failures do
|
|
499
|
+
not invalidate entries.
|
|
500
|
+
|
|
501
|
+
The default memory store keeps up to 1,000 entries using LRU eviction. Expired
|
|
502
|
+
entries with `ETag` or `Last-Modified` validators are conditionally revalidated;
|
|
503
|
+
set `maxEntries` to tune the bound, use `0` to disable storage, or use `Infinity`
|
|
504
|
+
for an explicitly unbounded store.
|
|
505
|
+
|
|
506
|
+
Request `Cache-Control: no-cache` or `max-age=0` to force validation, and use
|
|
507
|
+
`Cache-Control: no-store` to bypass cache reads, writes, and request sharing.
|
|
508
|
+
Response `stale-if-error` can serve an expired entry after network, timeout, or
|
|
509
|
+
5xx failure; `extensions.cache.staleIfError` sets an application limit in
|
|
510
|
+
milliseconds.
|
|
511
|
+
Response `stale-while-revalidate` can return stale data immediately while one
|
|
512
|
+
deduplicated refresh runs through the same client pipeline in the background.
|
|
287
513
|
|
|
288
514
|
Built-in plugins:
|
|
289
515
|
|
|
@@ -409,6 +635,7 @@ Stable request error codes:
|
|
|
409
635
|
- `ABORT_ERROR`
|
|
410
636
|
- `PARSER_ERROR`
|
|
411
637
|
- `SCHEMA_ERROR`
|
|
638
|
+
- `REQUEST_TOO_LARGE`
|
|
412
639
|
- `RESPONSE_TOO_LARGE`
|
|
413
640
|
- `CIRCUIT_OPEN`
|
|
414
641
|
- `CONCURRENCY_LIMIT`
|
|
@@ -432,7 +659,6 @@ allowlist, and size budgets.
|
|
|
432
659
|
- [Architecture](https://github.com/npora/request/blob/main/docs/architecture.md)
|
|
433
660
|
- [Migration from 0.x](https://github.com/npora/request/blob/main/docs/migration.md)
|
|
434
661
|
- [Migration from Axios or Ky](https://github.com/npora/request/blob/main/docs/migration-from-axios-and-ky.md)
|
|
435
|
-
- [HTTP client comparison](https://github.com/npora/request/blob/main/docs/comparison.md)
|
|
436
662
|
- [Security model](https://github.com/npora/request/blob/main/docs/security.md)
|
|
437
663
|
- [Testing and release gates](https://github.com/npora/request/blob/main/docs/testing.md)
|
|
438
664
|
- [Performance benchmarks](https://github.com/npora/request/blob/main/docs/benchmark.md)
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { i as QueryParams, j as HttpMethod, o as RequestConfig, t as NporaResponse } from "./response-BhyS3PAL.cjs";
|
|
2
|
+
import { t as Adapter } from "./adapter-BeVVCcNG.cjs";
|
|
3
|
+
//#region src/adapters/MockAdapter.d.ts
|
|
4
|
+
type MockHandler<T = unknown> = (config: RequestConfig) => T | Promise<T>;
|
|
5
|
+
type MockURLMatcher = string | RegExp;
|
|
6
|
+
interface MockRequestMatcher {
|
|
7
|
+
url: MockURLMatcher;
|
|
8
|
+
query?: QueryParams;
|
|
9
|
+
searchParams?: URLSearchParams;
|
|
10
|
+
headers?: HeadersInit;
|
|
11
|
+
}
|
|
12
|
+
interface MockReply<T = unknown> {
|
|
13
|
+
status: number;
|
|
14
|
+
data?: T;
|
|
15
|
+
headers?: HeadersInit;
|
|
16
|
+
statusText?: string;
|
|
17
|
+
delay?: number;
|
|
18
|
+
}
|
|
19
|
+
type MockReplyHandler<T = unknown> = (config: RequestConfig) => MockReply<T> | Promise<MockReply<T>>;
|
|
20
|
+
interface MockResponseOptions {
|
|
21
|
+
headers?: HeadersInit;
|
|
22
|
+
statusText?: string;
|
|
23
|
+
delay?: number;
|
|
24
|
+
}
|
|
25
|
+
interface MockRoute {
|
|
26
|
+
reply<T = unknown>(handler: MockReplyHandler<T>): MockAdapter;
|
|
27
|
+
reply<T = unknown>(status: number, data?: T, options?: MockResponseOptions): MockAdapter;
|
|
28
|
+
replyOnce<T = unknown>(handler: MockReplyHandler<T>): MockAdapter;
|
|
29
|
+
replyOnce<T = unknown>(status: number, data?: T, options?: MockResponseOptions): MockAdapter;
|
|
30
|
+
networkError(message?: string): MockAdapter;
|
|
31
|
+
networkErrorOnce(message?: string): MockAdapter;
|
|
32
|
+
timeout(message?: string): MockAdapter;
|
|
33
|
+
timeoutOnce(message?: string): MockAdapter;
|
|
34
|
+
}
|
|
35
|
+
interface MockAdapterOptions {
|
|
36
|
+
handlers?: Record<string, MockHandler>;
|
|
37
|
+
/**
|
|
38
|
+
* Default delay for mock handlers and routes.
|
|
39
|
+
*
|
|
40
|
+
* @default 0
|
|
41
|
+
*/
|
|
42
|
+
delay?: number;
|
|
43
|
+
}
|
|
44
|
+
declare class MockAdapter implements Adapter {
|
|
45
|
+
private readonly handlers;
|
|
46
|
+
private readonly rules;
|
|
47
|
+
private readonly requests;
|
|
48
|
+
private readonly delay;
|
|
49
|
+
constructor(options?: MockAdapterOptions);
|
|
50
|
+
get history(): readonly RequestConfig[];
|
|
51
|
+
/**
|
|
52
|
+
* Register a legacy URL-only data handler.
|
|
53
|
+
*/
|
|
54
|
+
on<T = unknown>(url: string, handler: MockHandler<T>): this;
|
|
55
|
+
onMethod(method: HttpMethod, matcher: MockURLMatcher | MockRequestMatcher): MockRoute;
|
|
56
|
+
onGet(matcher: MockURLMatcher | MockRequestMatcher): MockRoute;
|
|
57
|
+
onPost(matcher: MockURLMatcher | MockRequestMatcher): MockRoute;
|
|
58
|
+
onPut(matcher: MockURLMatcher | MockRequestMatcher): MockRoute;
|
|
59
|
+
onPatch(matcher: MockURLMatcher | MockRequestMatcher): MockRoute;
|
|
60
|
+
onDelete(matcher: MockURLMatcher | MockRequestMatcher): MockRoute;
|
|
61
|
+
onHead(matcher: MockURLMatcher | MockRequestMatcher): MockRoute;
|
|
62
|
+
onOptions(matcher: MockURLMatcher | MockRequestMatcher): MockRoute;
|
|
63
|
+
resetHistory(): this;
|
|
64
|
+
resetHandlers(): this;
|
|
65
|
+
reset(): this;
|
|
66
|
+
request<T = unknown>(config: RequestConfig): Promise<NporaResponse<T>>;
|
|
67
|
+
private registerReply;
|
|
68
|
+
private registerError;
|
|
69
|
+
}
|
|
70
|
+
//#endregion
|
|
71
|
+
export { MockReplyHandler as a, MockRoute as c, MockReply as i, MockURLMatcher as l, MockAdapterOptions as n, MockRequestMatcher as o, MockHandler as r, MockResponseOptions as s, MockAdapter as t };
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { i as QueryParams, j as HttpMethod, o as RequestConfig, t as NporaResponse } from "./response-BhyS3PAL.js";
|
|
2
|
+
import { t as Adapter } from "./adapter-ODzpt_dM.js";
|
|
3
|
+
//#region src/adapters/MockAdapter.d.ts
|
|
4
|
+
type MockHandler<T = unknown> = (config: RequestConfig) => T | Promise<T>;
|
|
5
|
+
type MockURLMatcher = string | RegExp;
|
|
6
|
+
interface MockRequestMatcher {
|
|
7
|
+
url: MockURLMatcher;
|
|
8
|
+
query?: QueryParams;
|
|
9
|
+
searchParams?: URLSearchParams;
|
|
10
|
+
headers?: HeadersInit;
|
|
11
|
+
}
|
|
12
|
+
interface MockReply<T = unknown> {
|
|
13
|
+
status: number;
|
|
14
|
+
data?: T;
|
|
15
|
+
headers?: HeadersInit;
|
|
16
|
+
statusText?: string;
|
|
17
|
+
delay?: number;
|
|
18
|
+
}
|
|
19
|
+
type MockReplyHandler<T = unknown> = (config: RequestConfig) => MockReply<T> | Promise<MockReply<T>>;
|
|
20
|
+
interface MockResponseOptions {
|
|
21
|
+
headers?: HeadersInit;
|
|
22
|
+
statusText?: string;
|
|
23
|
+
delay?: number;
|
|
24
|
+
}
|
|
25
|
+
interface MockRoute {
|
|
26
|
+
reply<T = unknown>(handler: MockReplyHandler<T>): MockAdapter;
|
|
27
|
+
reply<T = unknown>(status: number, data?: T, options?: MockResponseOptions): MockAdapter;
|
|
28
|
+
replyOnce<T = unknown>(handler: MockReplyHandler<T>): MockAdapter;
|
|
29
|
+
replyOnce<T = unknown>(status: number, data?: T, options?: MockResponseOptions): MockAdapter;
|
|
30
|
+
networkError(message?: string): MockAdapter;
|
|
31
|
+
networkErrorOnce(message?: string): MockAdapter;
|
|
32
|
+
timeout(message?: string): MockAdapter;
|
|
33
|
+
timeoutOnce(message?: string): MockAdapter;
|
|
34
|
+
}
|
|
35
|
+
interface MockAdapterOptions {
|
|
36
|
+
handlers?: Record<string, MockHandler>;
|
|
37
|
+
/**
|
|
38
|
+
* Default delay for mock handlers and routes.
|
|
39
|
+
*
|
|
40
|
+
* @default 0
|
|
41
|
+
*/
|
|
42
|
+
delay?: number;
|
|
43
|
+
}
|
|
44
|
+
declare class MockAdapter implements Adapter {
|
|
45
|
+
private readonly handlers;
|
|
46
|
+
private readonly rules;
|
|
47
|
+
private readonly requests;
|
|
48
|
+
private readonly delay;
|
|
49
|
+
constructor(options?: MockAdapterOptions);
|
|
50
|
+
get history(): readonly RequestConfig[];
|
|
51
|
+
/**
|
|
52
|
+
* Register a legacy URL-only data handler.
|
|
53
|
+
*/
|
|
54
|
+
on<T = unknown>(url: string, handler: MockHandler<T>): this;
|
|
55
|
+
onMethod(method: HttpMethod, matcher: MockURLMatcher | MockRequestMatcher): MockRoute;
|
|
56
|
+
onGet(matcher: MockURLMatcher | MockRequestMatcher): MockRoute;
|
|
57
|
+
onPost(matcher: MockURLMatcher | MockRequestMatcher): MockRoute;
|
|
58
|
+
onPut(matcher: MockURLMatcher | MockRequestMatcher): MockRoute;
|
|
59
|
+
onPatch(matcher: MockURLMatcher | MockRequestMatcher): MockRoute;
|
|
60
|
+
onDelete(matcher: MockURLMatcher | MockRequestMatcher): MockRoute;
|
|
61
|
+
onHead(matcher: MockURLMatcher | MockRequestMatcher): MockRoute;
|
|
62
|
+
onOptions(matcher: MockURLMatcher | MockRequestMatcher): MockRoute;
|
|
63
|
+
resetHistory(): this;
|
|
64
|
+
resetHandlers(): this;
|
|
65
|
+
reset(): this;
|
|
66
|
+
request<T = unknown>(config: RequestConfig): Promise<NporaResponse<T>>;
|
|
67
|
+
private registerReply;
|
|
68
|
+
private registerError;
|
|
69
|
+
}
|
|
70
|
+
//#endregion
|
|
71
|
+
export { MockReplyHandler as a, MockRoute as c, MockReply as i, MockURLMatcher as l, MockAdapterOptions as n, MockRequestMatcher as o, MockHandler as r, MockResponseOptions as s, MockAdapter as t };
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { o as RequestConfig, t as NporaResponse } from "./response-BhyS3PAL.js";
|
|
2
|
+
//#region src/interceptors/InterceptorManager.d.ts
|
|
3
|
+
type Interceptor<T> = (value: T) => T | Promise<T>;
|
|
4
|
+
interface InterceptorOptions {
|
|
5
|
+
/**
|
|
6
|
+
* Higher priority interceptors run first.
|
|
7
|
+
*
|
|
8
|
+
* @default 0
|
|
9
|
+
*/
|
|
10
|
+
priority?: number;
|
|
11
|
+
}
|
|
12
|
+
declare class InterceptorManager<T> {
|
|
13
|
+
private id;
|
|
14
|
+
private readonly interceptors;
|
|
15
|
+
private orderedInterceptors;
|
|
16
|
+
get active(): boolean;
|
|
17
|
+
use(interceptor: Interceptor<T>, options?: InterceptorOptions): number;
|
|
18
|
+
eject(id: number): void;
|
|
19
|
+
clear(): void;
|
|
20
|
+
run(value: T): Promise<T>;
|
|
21
|
+
private runMaybeAsync;
|
|
22
|
+
private refreshOrder;
|
|
23
|
+
}
|
|
24
|
+
//#endregion
|
|
25
|
+
//#region src/core/RequestContext.d.ts
|
|
26
|
+
declare class RequestContext<T = unknown> {
|
|
27
|
+
readonly preserveRaw: boolean;
|
|
28
|
+
/** @internal */
|
|
29
|
+
readonly background: boolean;
|
|
30
|
+
config: RequestConfig;
|
|
31
|
+
/** @internal Request input before interceptors and hooks mutate it. */
|
|
32
|
+
readonly initialConfig: RequestConfig;
|
|
33
|
+
response?: NporaResponse<T>;
|
|
34
|
+
/** @internal Candidate used only after retry handling declines another attempt. */
|
|
35
|
+
fallbackResponse?: NporaResponse<T>;
|
|
36
|
+
error?: unknown;
|
|
37
|
+
readonly startTime: number;
|
|
38
|
+
endTime?: number;
|
|
39
|
+
attempt: number;
|
|
40
|
+
constructor(config: RequestConfig, preserveRaw?: boolean,
|
|
41
|
+
/** @internal */
|
|
42
|
+
background?: boolean);
|
|
43
|
+
}
|
|
44
|
+
//#endregion
|
|
45
|
+
//#region src/interceptors/PluginHooks.d.ts
|
|
46
|
+
interface RetryDecision {
|
|
47
|
+
retry: boolean;
|
|
48
|
+
delay?: number;
|
|
49
|
+
}
|
|
50
|
+
interface HookOptions {
|
|
51
|
+
/**
|
|
52
|
+
* Higher priority hooks run first.
|
|
53
|
+
*
|
|
54
|
+
* @default 0
|
|
55
|
+
*/
|
|
56
|
+
priority?: number;
|
|
57
|
+
/** @internal Response hooks may opt out when they never inspect raw. */
|
|
58
|
+
requiresRawResponse?: boolean;
|
|
59
|
+
}
|
|
60
|
+
type HookDisposer = () => void;
|
|
61
|
+
type RequestHook = (context: RequestContext<unknown>) => void | Promise<void>;
|
|
62
|
+
type RetryHook = (context: RequestContext<unknown>, attempt: number) => RetryDecision | undefined | Promise<RetryDecision | undefined>;
|
|
63
|
+
//#endregion
|
|
64
|
+
//#region src/plugins/Plugin.d.ts
|
|
65
|
+
interface PluginInterceptorManager<T> {
|
|
66
|
+
use(interceptor: Interceptor<T>, options?: InterceptorOptions): number;
|
|
67
|
+
eject(id: number): void;
|
|
68
|
+
}
|
|
69
|
+
interface PluginHookManager {
|
|
70
|
+
onRequest(hook: RequestHook, options?: HookOptions): HookDisposer;
|
|
71
|
+
/**
|
|
72
|
+
* Provide an alternative transport for the current attempt.
|
|
73
|
+
*
|
|
74
|
+
* Transport hooks run inside the retry loop. A hook that handles the
|
|
75
|
+
* request assigns `context.response`; later transport hooks and the client
|
|
76
|
+
* adapter are then skipped for that attempt.
|
|
77
|
+
*/
|
|
78
|
+
onTransport(hook: RequestHook, options?: HookOptions): HookDisposer;
|
|
79
|
+
onResponse(hook: RequestHook, options?: HookOptions): HookDisposer;
|
|
80
|
+
onError(hook: RequestHook, options?: HookOptions): HookDisposer;
|
|
81
|
+
/**
|
|
82
|
+
* Observe the final request outcome after retries and interceptors finish.
|
|
83
|
+
*
|
|
84
|
+
* Settled hook failures are isolated from the request result.
|
|
85
|
+
*/
|
|
86
|
+
onSettled(hook: RequestHook, options?: HookOptions): HookDisposer;
|
|
87
|
+
onRetry(hook: RetryHook, options?: HookOptions): HookDisposer;
|
|
88
|
+
}
|
|
89
|
+
interface PluginContext {
|
|
90
|
+
interceptors: {
|
|
91
|
+
request: PluginInterceptorManager<RequestConfig>;
|
|
92
|
+
response: PluginInterceptorManager<NporaResponse>;
|
|
93
|
+
error: PluginInterceptorManager<unknown>;
|
|
94
|
+
};
|
|
95
|
+
hooks: PluginHookManager;
|
|
96
|
+
/** @internal Dispatch a request through the owning client pipeline. */
|
|
97
|
+
dispatch<T = unknown>(config: RequestConfig, options?: PluginDispatchOptions): Promise<NporaResponse<T>>;
|
|
98
|
+
}
|
|
99
|
+
interface PluginDispatchOptions {
|
|
100
|
+
background?: boolean;
|
|
101
|
+
preserveRaw?: boolean;
|
|
102
|
+
}
|
|
103
|
+
type PluginCleanup = () => void;
|
|
104
|
+
interface Plugin {
|
|
105
|
+
name: string;
|
|
106
|
+
/**
|
|
107
|
+
* Default priority for interceptors and hooks registered by this plugin.
|
|
108
|
+
* Higher priority registrations run first.
|
|
109
|
+
*
|
|
110
|
+
* @default 0
|
|
111
|
+
*/
|
|
112
|
+
priority?: number;
|
|
113
|
+
/**
|
|
114
|
+
* Plugins that must already be installed.
|
|
115
|
+
*/
|
|
116
|
+
requires?: readonly string[];
|
|
117
|
+
/**
|
|
118
|
+
* Plugins that cannot be installed on the same client.
|
|
119
|
+
*/
|
|
120
|
+
conflicts?: readonly string[];
|
|
121
|
+
install: (context: PluginContext) => void | PluginCleanup;
|
|
122
|
+
}
|
|
123
|
+
//#endregion
|
|
124
|
+
export { PluginInterceptorManager as a, InterceptorOptions as c, PluginHookManager as i, PluginCleanup as n, Interceptor as o, PluginContext as r, InterceptorManager as s, Plugin as t };
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { o as RequestConfig, t as NporaResponse } from "./response-BhyS3PAL.cjs";
|
|
2
|
+
//#region src/interceptors/InterceptorManager.d.ts
|
|
3
|
+
type Interceptor<T> = (value: T) => T | Promise<T>;
|
|
4
|
+
interface InterceptorOptions {
|
|
5
|
+
/**
|
|
6
|
+
* Higher priority interceptors run first.
|
|
7
|
+
*
|
|
8
|
+
* @default 0
|
|
9
|
+
*/
|
|
10
|
+
priority?: number;
|
|
11
|
+
}
|
|
12
|
+
declare class InterceptorManager<T> {
|
|
13
|
+
private id;
|
|
14
|
+
private readonly interceptors;
|
|
15
|
+
private orderedInterceptors;
|
|
16
|
+
get active(): boolean;
|
|
17
|
+
use(interceptor: Interceptor<T>, options?: InterceptorOptions): number;
|
|
18
|
+
eject(id: number): void;
|
|
19
|
+
clear(): void;
|
|
20
|
+
run(value: T): Promise<T>;
|
|
21
|
+
private runMaybeAsync;
|
|
22
|
+
private refreshOrder;
|
|
23
|
+
}
|
|
24
|
+
//#endregion
|
|
25
|
+
//#region src/core/RequestContext.d.ts
|
|
26
|
+
declare class RequestContext<T = unknown> {
|
|
27
|
+
readonly preserveRaw: boolean;
|
|
28
|
+
/** @internal */
|
|
29
|
+
readonly background: boolean;
|
|
30
|
+
config: RequestConfig;
|
|
31
|
+
/** @internal Request input before interceptors and hooks mutate it. */
|
|
32
|
+
readonly initialConfig: RequestConfig;
|
|
33
|
+
response?: NporaResponse<T>;
|
|
34
|
+
/** @internal Candidate used only after retry handling declines another attempt. */
|
|
35
|
+
fallbackResponse?: NporaResponse<T>;
|
|
36
|
+
error?: unknown;
|
|
37
|
+
readonly startTime: number;
|
|
38
|
+
endTime?: number;
|
|
39
|
+
attempt: number;
|
|
40
|
+
constructor(config: RequestConfig, preserveRaw?: boolean,
|
|
41
|
+
/** @internal */
|
|
42
|
+
background?: boolean);
|
|
43
|
+
}
|
|
44
|
+
//#endregion
|
|
45
|
+
//#region src/interceptors/PluginHooks.d.ts
|
|
46
|
+
interface RetryDecision {
|
|
47
|
+
retry: boolean;
|
|
48
|
+
delay?: number;
|
|
49
|
+
}
|
|
50
|
+
interface HookOptions {
|
|
51
|
+
/**
|
|
52
|
+
* Higher priority hooks run first.
|
|
53
|
+
*
|
|
54
|
+
* @default 0
|
|
55
|
+
*/
|
|
56
|
+
priority?: number;
|
|
57
|
+
/** @internal Response hooks may opt out when they never inspect raw. */
|
|
58
|
+
requiresRawResponse?: boolean;
|
|
59
|
+
}
|
|
60
|
+
type HookDisposer = () => void;
|
|
61
|
+
type RequestHook = (context: RequestContext<unknown>) => void | Promise<void>;
|
|
62
|
+
type RetryHook = (context: RequestContext<unknown>, attempt: number) => RetryDecision | undefined | Promise<RetryDecision | undefined>;
|
|
63
|
+
//#endregion
|
|
64
|
+
//#region src/plugins/Plugin.d.ts
|
|
65
|
+
interface PluginInterceptorManager<T> {
|
|
66
|
+
use(interceptor: Interceptor<T>, options?: InterceptorOptions): number;
|
|
67
|
+
eject(id: number): void;
|
|
68
|
+
}
|
|
69
|
+
interface PluginHookManager {
|
|
70
|
+
onRequest(hook: RequestHook, options?: HookOptions): HookDisposer;
|
|
71
|
+
/**
|
|
72
|
+
* Provide an alternative transport for the current attempt.
|
|
73
|
+
*
|
|
74
|
+
* Transport hooks run inside the retry loop. A hook that handles the
|
|
75
|
+
* request assigns `context.response`; later transport hooks and the client
|
|
76
|
+
* adapter are then skipped for that attempt.
|
|
77
|
+
*/
|
|
78
|
+
onTransport(hook: RequestHook, options?: HookOptions): HookDisposer;
|
|
79
|
+
onResponse(hook: RequestHook, options?: HookOptions): HookDisposer;
|
|
80
|
+
onError(hook: RequestHook, options?: HookOptions): HookDisposer;
|
|
81
|
+
/**
|
|
82
|
+
* Observe the final request outcome after retries and interceptors finish.
|
|
83
|
+
*
|
|
84
|
+
* Settled hook failures are isolated from the request result.
|
|
85
|
+
*/
|
|
86
|
+
onSettled(hook: RequestHook, options?: HookOptions): HookDisposer;
|
|
87
|
+
onRetry(hook: RetryHook, options?: HookOptions): HookDisposer;
|
|
88
|
+
}
|
|
89
|
+
interface PluginContext {
|
|
90
|
+
interceptors: {
|
|
91
|
+
request: PluginInterceptorManager<RequestConfig>;
|
|
92
|
+
response: PluginInterceptorManager<NporaResponse>;
|
|
93
|
+
error: PluginInterceptorManager<unknown>;
|
|
94
|
+
};
|
|
95
|
+
hooks: PluginHookManager;
|
|
96
|
+
/** @internal Dispatch a request through the owning client pipeline. */
|
|
97
|
+
dispatch<T = unknown>(config: RequestConfig, options?: PluginDispatchOptions): Promise<NporaResponse<T>>;
|
|
98
|
+
}
|
|
99
|
+
interface PluginDispatchOptions {
|
|
100
|
+
background?: boolean;
|
|
101
|
+
preserveRaw?: boolean;
|
|
102
|
+
}
|
|
103
|
+
type PluginCleanup = () => void;
|
|
104
|
+
interface Plugin {
|
|
105
|
+
name: string;
|
|
106
|
+
/**
|
|
107
|
+
* Default priority for interceptors and hooks registered by this plugin.
|
|
108
|
+
* Higher priority registrations run first.
|
|
109
|
+
*
|
|
110
|
+
* @default 0
|
|
111
|
+
*/
|
|
112
|
+
priority?: number;
|
|
113
|
+
/**
|
|
114
|
+
* Plugins that must already be installed.
|
|
115
|
+
*/
|
|
116
|
+
requires?: readonly string[];
|
|
117
|
+
/**
|
|
118
|
+
* Plugins that cannot be installed on the same client.
|
|
119
|
+
*/
|
|
120
|
+
conflicts?: readonly string[];
|
|
121
|
+
install: (context: PluginContext) => void | PluginCleanup;
|
|
122
|
+
}
|
|
123
|
+
//#endregion
|
|
124
|
+
export { PluginInterceptorManager as a, InterceptorOptions as c, PluginHookManager as i, PluginCleanup as n, Interceptor as o, PluginContext as r, InterceptorManager as s, Plugin as t };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var PluginError=class extends Error{constructor(e,t){super(e),this.name=`PluginError`,this.code=t.code,this.plugin=t.plugin,this.relatedPlugin=t.relatedPlugin,Object.setPrototypeOf(this,new.target.prototype)}};export{PluginError as t};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var PluginError=class extends Error{constructor(e,t){super(e),this.name=`PluginError`,this.code=t.code,this.plugin=t.plugin,this.relatedPlugin=t.relatedPlugin,Object.setPrototypeOf(this,new.target.prototype)}};Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return PluginError}});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
//#region src/plugins/PluginError.d.ts
|
|
2
|
+
type PluginErrorCode = 'MISSING_DEPENDENCY' | 'PLUGIN_CONFLICT' | 'DEPENDENCY_IN_USE';
|
|
3
|
+
interface PluginErrorOptions {
|
|
4
|
+
code: PluginErrorCode;
|
|
5
|
+
plugin: string;
|
|
6
|
+
relatedPlugin: string;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Stable error thrown for invalid plugin lifecycle operations.
|
|
10
|
+
*/
|
|
11
|
+
declare class PluginError extends Error {
|
|
12
|
+
readonly code: PluginErrorCode;
|
|
13
|
+
readonly plugin: string;
|
|
14
|
+
readonly relatedPlugin: string;
|
|
15
|
+
constructor(message: string, options: PluginErrorOptions);
|
|
16
|
+
}
|
|
17
|
+
//#endregion
|
|
18
|
+
export { PluginErrorCode as n, PluginErrorOptions as r, PluginError as t };
|