@npora/request 1.21.4 → 1.22.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.
Files changed (133) hide show
  1. package/README.md +2 -1
  2. package/dist/{MockAdapter-Hi5uqQ8K.d.ts → MockAdapter-B0p0_AIH.d.cts} +44 -5
  3. package/dist/MockAdapter-BZwg5VWz.cjs +2 -0
  4. package/dist/{MockAdapter-CDWlJKqY.d.cts → MockAdapter-Cm79wcJx.d.ts} +44 -5
  5. package/dist/MockAdapter-DCnauo5Q.js +2 -0
  6. package/dist/{Plugin-BG4NQC3T.d.ts → Plugin-BQcrWrNm.d.cts} +1 -9
  7. package/dist/{Plugin-CCFavD-_.d.cts → Plugin-C3xZTHbG.d.ts} +1 -9
  8. package/dist/{PluginError-DVP3pUt_.d.cts → PluginError-Cq0DhZCF.d.cts} +0 -2
  9. package/dist/{PluginError-DVP3pUt_.d.ts → PluginError-Cq0DhZCF.d.ts} +0 -2
  10. package/dist/{SchemaValidationError-DV3aqGe0.d.cts → SchemaValidationError-B2fAMMkM.d.ts} +4 -18
  11. package/dist/{SchemaValidationError-D-Bg0Wc9.d.ts → SchemaValidationError-ClFDgxry.d.cts} +4 -18
  12. package/dist/{adapter-CcfItVkl.d.ts → adapter-B-L43hnj.d.ts} +1 -3
  13. package/dist/{adapter-Cq9y_Fww.d.cts → adapter-Q6uDyqF2.d.cts} +1 -3
  14. package/dist/{authPlugin-DRCFibHZ.d.ts → authPlugin-BCkcwFcq.d.ts} +1 -3
  15. package/dist/{authPlugin-DWpsWoVD.d.cts → authPlugin-DzMlmEGT.d.cts} +1 -3
  16. package/dist/{cachePlugin-D2ONW9sl.d.ts → cachePlugin-CnAMq7UC.d.ts} +2 -14
  17. package/dist/cachePlugin-JU-Rob4m.js +1 -0
  18. package/dist/{cachePlugin-BlsRZKN2.d.cts → cachePlugin-XF9k2IyP.d.cts} +2 -14
  19. package/dist/cachePlugin-XacR7ADG.cjs +1 -0
  20. package/dist/{circuitBreakerPlugin-DUyVrQlA.d.ts → circuitBreakerPlugin-CiH1p3kW.d.ts} +2 -4
  21. package/dist/{circuitBreakerPlugin-BL5Pxslz.d.cts → circuitBreakerPlugin-De7zlDeV.d.cts} +2 -4
  22. package/dist/{concurrencyPlugin-DM66h5PD.d.ts → concurrencyPlugin-DMkVFc5N.d.cts} +2 -4
  23. package/dist/{concurrencyPlugin-DId5qkk9.d.cts → concurrencyPlugin-lcwDZPqe.d.ts} +2 -4
  24. package/dist/core.cjs +1 -1
  25. package/dist/core.d.cts +6 -6
  26. package/dist/core.d.ts +6 -6
  27. package/dist/core.js +1 -1
  28. package/dist/createClient-B5Oxq2Fj.js +1 -0
  29. package/dist/createClient-CXvspA_F.cjs +1 -0
  30. package/dist/{downloadPlugin-BY3BVNw4.d.ts → downloadPlugin-BxIWgvyl.d.ts} +1 -3
  31. package/dist/{downloadPlugin-DtOzKGt_.d.cts → downloadPlugin-Cj2Zfocy.d.cts} +1 -3
  32. package/dist/errorResponseTimeout-CLPv3sv8.js +5 -0
  33. package/dist/errorResponseTimeout-CZWn7IpX.cjs +5 -0
  34. package/dist/index.cjs +1 -1
  35. package/dist/index.d.cts +19 -19
  36. package/dist/index.d.ts +19 -19
  37. package/dist/index.js +1 -1
  38. package/dist/loggerPlugin-BtV0PYwO.d.ts +4 -0
  39. package/dist/loggerPlugin-Ck_c7bz8.d.cts +4 -0
  40. package/dist/{openTelemetryMetricsPlugin-BEoeRl3q.d.ts → openTelemetryMetricsPlugin-ClUnV57s.d.ts} +2 -4
  41. package/dist/{openTelemetryMetricsPlugin-DuF9OWoT.d.cts → openTelemetryMetricsPlugin-DrkR3Zpi.d.cts} +2 -4
  42. package/dist/{openTelemetryPlugin-DOhBE_uZ.d.ts → openTelemetryPlugin-BHs7ZJau.d.ts} +2 -4
  43. package/dist/{openTelemetryPlugin-Dpz6-bEj.d.cts → openTelemetryPlugin-Cd26lwLW.d.cts} +2 -4
  44. package/dist/plugins/auth.cjs +1 -1
  45. package/dist/plugins/auth.d.cts +1 -1
  46. package/dist/plugins/auth.d.ts +1 -1
  47. package/dist/plugins/auth.js +1 -1
  48. package/dist/plugins/cache.cjs +1 -1
  49. package/dist/plugins/cache.d.cts +1 -1
  50. package/dist/plugins/cache.d.ts +1 -1
  51. package/dist/plugins/cache.js +1 -1
  52. package/dist/plugins/circuit-breaker.cjs +1 -1
  53. package/dist/plugins/circuit-breaker.d.cts +1 -1
  54. package/dist/plugins/circuit-breaker.d.ts +1 -1
  55. package/dist/plugins/circuit-breaker.js +1 -1
  56. package/dist/plugins/concurrency.cjs +1 -1
  57. package/dist/plugins/concurrency.d.cts +1 -1
  58. package/dist/plugins/concurrency.d.ts +1 -1
  59. package/dist/plugins/concurrency.js +1 -1
  60. package/dist/plugins/download.cjs +1 -1
  61. package/dist/plugins/download.d.cts +1 -1
  62. package/dist/plugins/download.d.ts +1 -1
  63. package/dist/plugins/download.js +1 -1
  64. package/dist/plugins/logger.cjs +1 -1
  65. package/dist/plugins/logger.d.cts +1 -1
  66. package/dist/plugins/logger.d.ts +1 -1
  67. package/dist/plugins/logger.js +1 -1
  68. package/dist/plugins/memory-cache.cjs +1 -1
  69. package/dist/plugins/memory-cache.d.cts +4 -7
  70. package/dist/plugins/memory-cache.d.ts +4 -7
  71. package/dist/plugins/memory-cache.js +1 -1
  72. package/dist/plugins/opentelemetry-metrics.cjs +1 -1
  73. package/dist/plugins/opentelemetry-metrics.d.cts +1 -1
  74. package/dist/plugins/opentelemetry-metrics.d.ts +1 -1
  75. package/dist/plugins/opentelemetry-metrics.js +1 -1
  76. package/dist/plugins/opentelemetry.cjs +1 -1
  77. package/dist/plugins/opentelemetry.d.cts +1 -1
  78. package/dist/plugins/opentelemetry.d.ts +1 -1
  79. package/dist/plugins/opentelemetry.js +1 -1
  80. package/dist/plugins/rate-limit.cjs +1 -1
  81. package/dist/plugins/rate-limit.d.cts +1 -1
  82. package/dist/plugins/rate-limit.d.ts +1 -1
  83. package/dist/plugins/rate-limit.js +1 -1
  84. package/dist/plugins/retry.cjs +1 -1
  85. package/dist/plugins/retry.d.cts +1 -1
  86. package/dist/plugins/retry.d.ts +1 -1
  87. package/dist/plugins/retry.js +1 -1
  88. package/dist/plugins/upload.cjs +1 -1
  89. package/dist/plugins/upload.d.cts +1 -1
  90. package/dist/plugins/upload.d.ts +1 -1
  91. package/dist/plugins/upload.js +1 -1
  92. package/dist/plugins.cjs +1 -1
  93. package/dist/plugins.d.cts +13 -13
  94. package/dist/plugins.d.ts +13 -13
  95. package/dist/plugins.js +1 -1
  96. package/dist/rateLimitPlugin-C9CKjRyU.js +1 -0
  97. package/dist/{rateLimitPlugin-Ce3bjrRw.d.ts → rateLimitPlugin-Cbsw-Sxy.d.ts} +2 -4
  98. package/dist/rateLimitPlugin-D4to499s.cjs +1 -0
  99. package/dist/{rateLimitPlugin-CRpne4Qz.d.cts → rateLimitPlugin-D4zu4Jn2.d.cts} +2 -4
  100. package/dist/{response-BhOBjarL.d.ts → response-BepuyaMD.d.ts} +1 -9
  101. package/dist/{response-CXF5lNlw.d.cts → response-DFr_buHv.d.cts} +1 -9
  102. package/dist/retryPlugin-0I4ijOYE.d.ts +4 -0
  103. package/dist/retryPlugin-CA9VnS6H.d.cts +4 -0
  104. package/dist/schema-errors.d.cts +3 -6
  105. package/dist/schema-errors.d.ts +3 -6
  106. package/dist/{standardSchema-CjWI0T2o.d.cts → standardSchema-DkCdVLKc.d.cts} +0 -2
  107. package/dist/{standardSchema-CjWI0T2o.d.ts → standardSchema-DkCdVLKc.d.ts} +0 -2
  108. package/dist/testing.cjs +1 -1
  109. package/dist/testing.d.cts +2 -2
  110. package/dist/testing.d.ts +2 -2
  111. package/dist/testing.js +1 -1
  112. package/dist/uploadPlugin-CpVEqYGb.d.cts +3 -0
  113. package/dist/uploadPlugin-DOpXTqGy.d.ts +3 -0
  114. package/dist/waitForSignal-DXgmbuoa.js +1 -0
  115. package/dist/xhrTransport-B1vH5k3x.js +1 -0
  116. package/dist/{xhrTransport-BeC2XSM2.cjs → xhrTransport-CdBsCzpX.cjs} +1 -1
  117. package/package.json +3 -3
  118. package/dist/cachePlugin-BGfwCJRI.js +0 -1
  119. package/dist/cachePlugin-C9gu5JD0.cjs +0 -1
  120. package/dist/createClient-BQ1PXox6.cjs +0 -1
  121. package/dist/createClient-CVcpypA9.js +0 -1
  122. package/dist/errorResponseTimeout-BEEJV0xA.js +0 -5
  123. package/dist/errorResponseTimeout-zXdbsbDE.cjs +0 -5
  124. package/dist/loggerPlugin-ChJJN0ZA.d.ts +0 -6
  125. package/dist/loggerPlugin-DDEGhC31.d.cts +0 -6
  126. package/dist/rateLimitPlugin--8oHGS7_.js +0 -1
  127. package/dist/rateLimitPlugin-D8KaOpyW.cjs +0 -1
  128. package/dist/retryPlugin-5vYHV92i.d.ts +0 -6
  129. package/dist/retryPlugin-uC02f2sm.d.cts +0 -6
  130. package/dist/uploadPlugin-CNdvddnT.d.ts +0 -5
  131. package/dist/uploadPlugin-_xtlBLNY.d.cts +0 -5
  132. package/dist/waitForSignal-BcVEtAgx.js +0 -1
  133. package/dist/xhrTransport--NHaimro.js +0 -1
package/README.md CHANGED
@@ -600,7 +600,8 @@ first; equal priorities preserve registration order.
600
600
 
601
601
  ## Request testing
602
602
 
603
- `MockAdapter` supports method-aware routes, dynamic or one-time responses,
603
+ `MockAdapter` supports opt-in response recording and replay scripts,
604
+ method-aware routes, dynamic or one-time responses,
604
605
  query/header matching, delay, timeout and network-error simulation, and request
605
606
  history:
606
607
 
@@ -1,6 +1,37 @@
1
- import { K as HttpMethod, f as QueryParams, h as RequestConfig, t as NporaResponse } from "./response-BhOBjarL.js";
2
- import { t as Adapter } from "./adapter-CcfItVkl.js";
3
- //#region src/adapters/MockAdapter.d.ts
1
+ import { K as HttpMethod, f as QueryParams, h as RequestConfig, t as NporaResponse } from "./response-DFr_buHv.cjs";
2
+ import { t as Adapter } from "./adapter-Q6uDyqF2.cjs";
3
+ /** JSON values that can be replayed without constructors or live streams. */
4
+ type MockRecordedData = null | boolean | number | string | MockRecordedData[] | {
5
+ [key: string]: MockRecordedData;
6
+ };
7
+ interface MockRecording {
8
+ method: HttpMethod;
9
+ matcher: {
10
+ url: string;
11
+ query?: QueryParams;
12
+ searchParams?: Array<[string, string]>;
13
+ };
14
+ response: {
15
+ status: number;
16
+ statusText: string;
17
+ headers: Record<string, string>;
18
+ data?: MockRecordedData;
19
+ };
20
+ }
21
+ interface MockRecordOptions {
22
+ /** Unmatched requests are explicitly forwarded to this adapter. */
23
+ adapter: Adapter;
24
+ /** Maximum retained responses, in request invocation order. Default: 100. */
25
+ maxEntries?: number;
26
+ /** Maximum UTF-8 JSON bytes per complete recording. Default: 262144. */
27
+ maxRecordSize?: number;
28
+ /** Synchronous final redaction/filter. Return undefined to skip a recording. */
29
+ transform?: (recording: MockRecording) => MockRecording | undefined;
30
+ }
31
+ interface MockRecordingStats {
32
+ recorded: number;
33
+ skipped: number;
34
+ }
4
35
  type MockHandler<T = unknown> = (config: RequestConfig) => T | Promise<T>;
5
36
  type MockURLMatcher = string | RegExp;
6
37
  interface MockRequestMatcher {
@@ -33,6 +64,8 @@ interface MockRoute {
33
64
  timeoutOnce(message?: string): MockAdapter;
34
65
  }
35
66
  interface MockAdapterOptions {
67
+ /** Explicitly forward and record unmatched requests. Disabled by default. */
68
+ record?: MockRecordOptions;
36
69
  handlers?: Record<string, MockHandler>;
37
70
  /**
38
71
  * Default delay for mock handlers and routes.
@@ -45,9 +78,16 @@ declare class MockAdapter implements Adapter {
45
78
  private readonly handlers;
46
79
  private readonly rules;
47
80
  private readonly requests;
81
+ private readonly recorder?;
48
82
  private readonly delay;
49
83
  constructor(options?: MockAdapterOptions);
50
84
  get history(): readonly RequestConfig[];
85
+ /** Detached JSON snapshots, ordered by request invocation. */
86
+ get recordings(): readonly MockRecording[];
87
+ get recordingStats(): MockRecordingStats;
88
+ /** Export replyOnce registrations for a variable named `mock`. */
89
+ exportMocks(): string;
90
+ clearRecordings(): this;
51
91
  /**
52
92
  * Register a legacy URL-only data handler.
53
93
  */
@@ -67,5 +107,4 @@ declare class MockAdapter implements Adapter {
67
107
  private registerReply;
68
108
  private registerError;
69
109
  }
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 };
110
+ export { MockReplyHandler as a, MockRoute as c, MockRecordedData as d, MockRecording as f, MockReply as i, MockURLMatcher as l, MockAdapterOptions as n, MockRequestMatcher as o, MockRecordingStats as p, MockHandler as r, MockResponseOptions as s, MockAdapter as t, MockRecordOptions as u };
@@ -0,0 +1,2 @@
1
+ const e=require("./RequestError-DrCr_lwO.cjs"),t=require("./isBinaryBody-DNjjEzFS.cjs"),n=require("./validateResponseStatus-6FKeKyEV.cjs"),r=require("./isReadableStream-uWhOa7eR.cjs"),i=require("./isPromiseLike-B4LL7DlV.cjs"),a=require("./maxTimerDelay-NH5XeTXb.cjs");var MockRecorder=class{constructor(e){if(this.entries=new Map,this.skipped=0,this.sequence=0,this.generation=0,!e||typeof e.adapter?.request!=`function`)throw TypeError(`Mock recording requires an adapter`);if(this.maxEntries=s(e.maxEntries,100),this.maxRecordSize=s(e.maxRecordSize,262144),e.transform!==void 0&&typeof e.transform!=`function`)throw TypeError(`Mock recording transform must be a function`);this.adapter=e.adapter,this.transform=e.transform}get recordings(){return[...this.entries].sort(([e],[t])=>e-t).map(([,e])=>JSON.parse(e))}get stats(){return{recorded:this.entries.size,skipped:this.skipped}}clear(){this.generation++,this.entries.clear(),this.skipped=0}exportMocks(){return this.recordings.map(({method:e,matcher:t,response:n})=>{let r=t.searchParams?`, searchParams: new URLSearchParams(${d(t.searchParams)})`:``,i=`{ url: ${d(t.url)}${t.query?`, query: JSON.parse(${d(JSON.stringify(t.query))})`:``}${r} }`,a=n.data===void 0?`undefined`:`JSON.parse(${d(JSON.stringify(n.data))})`,o=JSON.stringify({headers:n.headers,statusText:n.statusText});return`mock.onMethod(${d(e)}, ${i}).replyOnce(${n.status}, ${a}, JSON.parse(${d(o)}));`}).join(`
2
+ `)}async request(t){let n=this.generation,r;try{r={id:this.sequence++,generation:n,method:t.method??`GET`,matcher:l(t,this.maxRecordSize)}}catch{this.skipped++}let i;try{i=await this.adapter.request(t)}catch(t){if(r&&n===this.generation)try{e.n(t)&&t.code===`HTTP_ERROR`&&t.response?this.record(r,t.response):this.skipped++}catch{this.skipped++}throw t}return r&&this.record(r,i),i}record(e,t){if(e.generation===this.generation)try{let n=Object.fromEntries([...t.headers].filter(([e])=>!c(e)&&!/^(content-length|content-encoding|transfer-encoding)$/i.test(e))),r={method:e.method,matcher:e.matcher,response:{status:t.status,statusText:t.statusText,headers:n}};t.data!==void 0&&(r.response.data=u(t.data,this.maxRecordSize));let a=this.transform?this.transform(r):r;if(i.t(a)){Promise.resolve(a).catch(()=>{}),e.generation===this.generation&&this.skipped++;return}if(e.generation!==this.generation)return;if(!a){this.skipped++;return}let s=u(a,this.maxRecordSize);o(s);let l=JSON.stringify(s);if(e.generation!==this.generation)return;this.entries.set(e.id,l),this.entries.size>this.maxEntries&&this.entries.delete([...this.entries.keys()].reduce((e,t)=>Math.min(e,t)))}catch{e.generation===this.generation&&this.skipped++}}};function o(e){if(![`GET`,`HEAD`,`POST`,`PUT`,`PATCH`,`DELETE`,`OPTIONS`,`QUERY`].includes(e.method)||typeof e.matcher?.url!=`string`||!Number.isInteger(e.response?.status)||e.response.status<200||e.response.status>599||typeof e.response.statusText!=`string`)throw TypeError(`Invalid recording`);if(l({...e.matcher,searchParams:e.matcher.searchParams?new URLSearchParams(e.matcher.searchParams):void 0},2**53-1),!e.response.headers||Object.values(e.response.headers).some(e=>typeof e!=`string`))throw TypeError(`Invalid recorded headers`);new Response(null,e.response)}function s(e,t){if(e===void 0)return t;if(!Number.isSafeInteger(e)||e<=0)throw TypeError(`Mock recording limits must be positive safe integers`);return e}function c(e){return/^(?:authorization|proxyauthorization|cookie|setcookie|password|passwd|secret|token|accesstoken|refreshtoken|apikey|xapikey|clientsecret|sessionid|csrftoken|xcsrftoken|xsrftoken|xxsrftoken|xauthtoken)$/i.test(e.replace(/[-_]/g,``))}function l(e,t){let n=String(e.url);if(/^(?:[a-z][a-z\d+.-]*:)?\/\/[^/?#]*@/i.test(n))throw TypeError(`Credential URL`);if(n.includes(`#`))throw TypeError(`Fragment URL`);let r=n.indexOf(`?`);if(r!==-1){let e=new URLSearchParams(n.slice(r+1).split(`#`,1)[0]);for(let t of e.keys())if(c(t))throw TypeError(`Sensitive URL query`)}let i={url:n};if(e.query){for(let t of Object.keys(e.query))if(c(t))throw TypeError(`Sensitive query`);i.query=u(Object.fromEntries(Object.entries(e.query).filter(([,e])=>e!==void 0).map(([e,t])=>[e,Array.isArray(t)?t.filter(e=>e!==void 0):t])),t)}if(e.searchParams){for(let t of e.searchParams.keys())if(c(t))throw TypeError(`Sensitive searchParams`);i.searchParams=[...e.searchParams]}return u(i,t)}function u(e,t){let n=new Set,r=new TextEncoder,i=t,a=e=>{if(e.length>i||(i-=r.encode(e).byteLength,i<0))throw TypeError(`Recording too large`)},o=(e,t)=>{if(t>64)throw TypeError(`Recording too deep`);if(e===null||typeof e==`boolean`)return a(String(e)),e;if(typeof e==`string`){if(e.length>i)throw TypeError(`Recording too large`);return a(JSON.stringify(e)),e}if(typeof e==`number`&&Number.isFinite(e)&&!Object.is(e,-0))return a(String(e)),e;if(typeof e!=`object`||n.has(e))throw TypeError(`Non-JSON recording`);let r=Array.isArray(e);if(r&&e.length>(i-2)/2)throw TypeError(`Recording too large`);if(!r&&Object.getPrototypeOf(e)!==Object.prototype&&Object.getPrototypeOf(e)!==null)throw TypeError(`Non-JSON recording`);if(Object.getOwnPropertySymbols(e).length)throw TypeError(`Symbol recording`);n.add(e),a(`[]`);let s=r?[]:Object.create(null),l=Object.keys(e);if(l.length>i/2)throw TypeError(`Recording too large`);for(let n of l){let l=Object.getOwnPropertyDescriptor(e,n);if(n.length>i)throw TypeError(`Recording too large`);if(!(`value`in l))throw TypeError(`Accessor recording`);if(r&&!/^(0|[1-9]\d*)$/.test(n))throw TypeError(`Non-JSON array`);a(`,`),r||a(`${JSON.stringify(n)}:`);let u=c(n)?`[REDACTED]`:l.value,d=o(u,t+1);r?s.push(d):s[n]=d}if(r&&s.length!==e.length)throw TypeError(`Sparse recording`);return n.delete(e),s};return o(e,0)}function d(e){return JSON.stringify(e).replace(/</g,`\\u003c`)}var MockAdapter=class{constructor(e={}){this.handlers=new Map,this.rules=[],this.requests=[],this.delay=T(e.delay),this.recorder=e.record===void 0?void 0:new MockRecorder(e.record),Object.entries(e.handlers??{}).forEach(([e,t])=>{this.handlers.set(e,t)})}get history(){return[...this.requests]}get recordings(){return this.recorder?.recordings??[]}get recordingStats(){return this.recorder?.stats??{recorded:0,skipped:0}}exportMocks(){return this.recorder?.exportMocks()??``}clearRecordings(){return this.recorder?.clear(),this}on(e,t){return this.handlers.set(e,t),this}onMethod(e,t){let n=f(t);return new RouteBuilder({reply:(t,r,i,a)=>this.registerReply(e,n,t,r,i,a),error:(t,r,i)=>this.registerError(e,n,t,r,i)})}onGet(e){return this.onMethod(`GET`,e)}onPost(e){return this.onMethod(`POST`,e)}onPut(e){return this.onMethod(`PUT`,e)}onPatch(e){return this.onMethod(`PATCH`,e)}onDelete(e){return this.onMethod(`DELETE`,e)}onHead(e){return this.onMethod(`HEAD`,e)}onOptions(e){return this.onMethod(`OPTIONS`,e)}resetHistory(){return this.requests.length=0,this}resetHandlers(){return this.handlers.clear(),this.rules.length=0,this}reset(){return this.resetHandlers().resetHistory().clearRecordings()}async request(e){this.requests.push(e);let t=e.method??`GET`,n=this.rules.findIndex(n=>(n.method===void 0||n.method===t)&&p(n.matcher,e));if(n!==-1){let t=this.rules[n];return t.once&&this.rules.splice(n,1),b(await t.respond(e),e)}let r=this.handlers.get(String(e.url));if(!r){if(this.recorder)return this.recorder.request(e);throw Error(`No mock handler found for ${e.url} (${t})`)}return await E(this.delay,e),b(y(e,{status:200,statusText:`OK`,data:await r(e)}),e)}registerReply(e,t,n,r,i,a={}){let o=typeof r==`function`?r:()=>({status:r,data:i,...a});return this.rules.push({method:e,matcher:t,once:n,respond:async e=>{let t=await o(e);return await E(T(t.delay??this.delay),e),y(e,t)}}),this}registerError(t,n,r,i,a){return this.rules.push({method:t,matcher:n,once:r,respond:async t=>{throw await E(this.delay,t),new e.t(a,{code:i,config:t})}}),this}},RouteBuilder=class{constructor(e){this.registrar=e}reply(e,t,n={}){return this.registrar.reply(!1,e,t,n)}replyOnce(e,t,n={}){return this.registrar.reply(!0,e,t,n)}networkError(e=`Mock network error`){return this.registrar.error(!1,`NETWORK_ERROR`,e)}networkErrorOnce(e=`Mock network error`){return this.registrar.error(!0,`NETWORK_ERROR`,e)}timeout(e=`Mock request timeout`){return this.registrar.error(!1,`TIMEOUT_ERROR`,e)}timeoutOnce(e=`Mock request timeout`){return this.registrar.error(!0,`TIMEOUT_ERROR`,e)}};function f(e){return typeof e==`string`||e instanceof RegExp?{url:e}:e}function p(e,t){return m(e.url,String(t.url))&&h(e.query,t.query)&&_(e.searchParams,t.searchParams)&&v(e.headers,t.headers)}function m(e,t){return typeof e==`string`?e===t:(e.lastIndex=0,e.test(t))}function h(e,t){return!e||g(e)===g(t)}function g(e){if(!e)return`[]`;let t=[];for(let n of Object.keys(e).sort()){let r=e[n],i=Array.isArray(r)?r:[r];for(let e of i)e!==void 0&&t.push([n,e===null?``:String(e)])}return JSON.stringify(t)}function _(e,t){return!e||JSON.stringify([...e.entries()])===JSON.stringify([...t?.entries()??[]])}function v(e,t){if(!e)return!0;let n=new Headers(e),r=new Headers(t);for(let[e,t]of n.entries())if(r.get(e)!==t)return!1;return!0}function y(e,t){let n=new Headers(t.headers),r=C(t.data,n,t.status),i=t.statusText??x(t.status),a=new Response(r,{status:t.status,statusText:i,headers:n});return{data:t.data,status:t.status,statusText:i,headers:a.headers,config:e,raw:a}}function b(t,r){if(!n.t(t.status,r))throw new e.t(t.statusText||`Mock request failed`,{code:`HTTP_ERROR`,response:t});return t}function x(e){return S[e]??``}const S={200:`OK`,201:`Created`,202:`Accepted`,204:`No Content`,400:`Bad Request`,401:`Unauthorized`,403:`Forbidden`,404:`Not Found`,408:`Request Timeout`,409:`Conflict`,422:`Unprocessable Content`,429:`Too Many Requests`,500:`Internal Server Error`,502:`Bad Gateway`,503:`Service Unavailable`,504:`Gateway Timeout`};function C(e,t,r){return e==null||n.n(void 0,r)?null:typeof e==`string`||w(e)?e:(t.has(`content-type`)||t.set(`content-type`,`application/json`),JSON.stringify(e))}function w(e){return t.n(e)||n.r(e)||t.r(e)||r.t(e)||t.t(e)||ArrayBuffer.isView(e)}function T(e){return Number.isFinite(e)?Math.min(Math.max(0,e??0),a.t):e&&e>0?a.t:0}function E(t,n){let r=n.signal;if(r?.aborted)return Promise.reject(D(r.reason,n));let i=n.timeout&&n.timeout>0?n.timeout:void 0,a=i!==void 0&&i<=t,o=a?i:t;return o<=0?Promise.resolve():new Promise((t,s)=>{let c,l=!1,u=()=>{c!==void 0&&(clearTimeout(c),c=void 0);try{r?.removeEventListener(`abort`,f)}catch{}},d=e=>{l||(l=!0,u(),s(e))},f=()=>{d(D(r?.reason,n))};try{r?.addEventListener(`abort`,f,{once:!0})}catch(e){d(e);return}if(r?.aborted&&f(),!l)try{c=setTimeout(()=>{a?d(new e.t(`Request timeout after ${i}ms`,{code:`TIMEOUT_ERROR`,config:n})):(l=!0,u(),t())},o)}catch(e){d(e)}})}function D(t,n){return new e.t(`Mock request aborted`,{code:`ABORT_ERROR`,config:n,cause:t})}Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return MockAdapter}});
@@ -1,6 +1,37 @@
1
- import { K as HttpMethod, f as QueryParams, h as RequestConfig, t as NporaResponse } from "./response-CXF5lNlw.cjs";
2
- import { t as Adapter } from "./adapter-Cq9y_Fww.cjs";
3
- //#region src/adapters/MockAdapter.d.ts
1
+ import { K as HttpMethod, f as QueryParams, h as RequestConfig, t as NporaResponse } from "./response-BepuyaMD.js";
2
+ import { t as Adapter } from "./adapter-B-L43hnj.js";
3
+ /** JSON values that can be replayed without constructors or live streams. */
4
+ type MockRecordedData = null | boolean | number | string | MockRecordedData[] | {
5
+ [key: string]: MockRecordedData;
6
+ };
7
+ interface MockRecording {
8
+ method: HttpMethod;
9
+ matcher: {
10
+ url: string;
11
+ query?: QueryParams;
12
+ searchParams?: Array<[string, string]>;
13
+ };
14
+ response: {
15
+ status: number;
16
+ statusText: string;
17
+ headers: Record<string, string>;
18
+ data?: MockRecordedData;
19
+ };
20
+ }
21
+ interface MockRecordOptions {
22
+ /** Unmatched requests are explicitly forwarded to this adapter. */
23
+ adapter: Adapter;
24
+ /** Maximum retained responses, in request invocation order. Default: 100. */
25
+ maxEntries?: number;
26
+ /** Maximum UTF-8 JSON bytes per complete recording. Default: 262144. */
27
+ maxRecordSize?: number;
28
+ /** Synchronous final redaction/filter. Return undefined to skip a recording. */
29
+ transform?: (recording: MockRecording) => MockRecording | undefined;
30
+ }
31
+ interface MockRecordingStats {
32
+ recorded: number;
33
+ skipped: number;
34
+ }
4
35
  type MockHandler<T = unknown> = (config: RequestConfig) => T | Promise<T>;
5
36
  type MockURLMatcher = string | RegExp;
6
37
  interface MockRequestMatcher {
@@ -33,6 +64,8 @@ interface MockRoute {
33
64
  timeoutOnce(message?: string): MockAdapter;
34
65
  }
35
66
  interface MockAdapterOptions {
67
+ /** Explicitly forward and record unmatched requests. Disabled by default. */
68
+ record?: MockRecordOptions;
36
69
  handlers?: Record<string, MockHandler>;
37
70
  /**
38
71
  * Default delay for mock handlers and routes.
@@ -45,9 +78,16 @@ declare class MockAdapter implements Adapter {
45
78
  private readonly handlers;
46
79
  private readonly rules;
47
80
  private readonly requests;
81
+ private readonly recorder?;
48
82
  private readonly delay;
49
83
  constructor(options?: MockAdapterOptions);
50
84
  get history(): readonly RequestConfig[];
85
+ /** Detached JSON snapshots, ordered by request invocation. */
86
+ get recordings(): readonly MockRecording[];
87
+ get recordingStats(): MockRecordingStats;
88
+ /** Export replyOnce registrations for a variable named `mock`. */
89
+ exportMocks(): string;
90
+ clearRecordings(): this;
51
91
  /**
52
92
  * Register a legacy URL-only data handler.
53
93
  */
@@ -67,5 +107,4 @@ declare class MockAdapter implements Adapter {
67
107
  private registerReply;
68
108
  private registerError;
69
109
  }
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 };
110
+ export { MockReplyHandler as a, MockRoute as c, MockRecordedData as d, MockRecording as f, MockReply as i, MockURLMatcher as l, MockAdapterOptions as n, MockRequestMatcher as o, MockRecordingStats as p, MockHandler as r, MockResponseOptions as s, MockAdapter as t, MockRecordOptions as u };
@@ -0,0 +1,2 @@
1
+ import{n as isRequestError,t as e}from"./RequestError-B0HIY1zK.js";import{n as t,r as n,t as r}from"./isBinaryBody-D-Wp2IPk.js";import{n as i,r as a,t as o}from"./validateResponseStatus-BzkEtZZi.js";import{t as s}from"./isReadableStream-DBMPCr6B.js";import{t as c}from"./isPromiseLike-B6ok3Q-C.js";import{t as l}from"./maxTimerDelay-Hn7X0Wuh.js";var MockRecorder=class{constructor(e){if(this.entries=new Map,this.skipped=0,this.sequence=0,this.generation=0,!e||typeof e.adapter?.request!=`function`)throw TypeError(`Mock recording requires an adapter`);if(this.maxEntries=d(e.maxEntries,100),this.maxRecordSize=d(e.maxRecordSize,262144),e.transform!==void 0&&typeof e.transform!=`function`)throw TypeError(`Mock recording transform must be a function`);this.adapter=e.adapter,this.transform=e.transform}get recordings(){return[...this.entries].sort(([e],[t])=>e-t).map(([,e])=>JSON.parse(e))}get stats(){return{recorded:this.entries.size,skipped:this.skipped}}clear(){this.generation++,this.entries.clear(),this.skipped=0}exportMocks(){return this.recordings.map(({method:e,matcher:t,response:n})=>{let r=t.searchParams?`, searchParams: new URLSearchParams(${h(t.searchParams)})`:``,i=`{ url: ${h(t.url)}${t.query?`, query: JSON.parse(${h(JSON.stringify(t.query))})`:``}${r} }`,a=n.data===void 0?`undefined`:`JSON.parse(${h(JSON.stringify(n.data))})`,o=JSON.stringify({headers:n.headers,statusText:n.statusText});return`mock.onMethod(${h(e)}, ${i}).replyOnce(${n.status}, ${a}, JSON.parse(${h(o)}));`}).join(`
2
+ `)}async request(e){let t=this.generation,n;try{n={id:this.sequence++,generation:t,method:e.method??`GET`,matcher:p(e,this.maxRecordSize)}}catch{this.skipped++}let r;try{r=await this.adapter.request(e)}catch(e){if(n&&t===this.generation)try{isRequestError(e)&&e.code===`HTTP_ERROR`&&e.response?this.record(n,e.response):this.skipped++}catch{this.skipped++}throw e}return n&&this.record(n,r),r}record(e,t){if(e.generation===this.generation)try{let n=Object.fromEntries([...t.headers].filter(([e])=>!f(e)&&!/^(content-length|content-encoding|transfer-encoding)$/i.test(e))),r={method:e.method,matcher:e.matcher,response:{status:t.status,statusText:t.statusText,headers:n}};t.data!==void 0&&(r.response.data=m(t.data,this.maxRecordSize));let i=this.transform?this.transform(r):r;if(c(i)){Promise.resolve(i).catch(()=>{}),e.generation===this.generation&&this.skipped++;return}if(e.generation!==this.generation)return;if(!i){this.skipped++;return}let a=m(i,this.maxRecordSize);u(a);let o=JSON.stringify(a);if(e.generation!==this.generation)return;this.entries.set(e.id,o),this.entries.size>this.maxEntries&&this.entries.delete([...this.entries.keys()].reduce((e,t)=>Math.min(e,t)))}catch{e.generation===this.generation&&this.skipped++}}};function u(e){if(![`GET`,`HEAD`,`POST`,`PUT`,`PATCH`,`DELETE`,`OPTIONS`,`QUERY`].includes(e.method)||typeof e.matcher?.url!=`string`||!Number.isInteger(e.response?.status)||e.response.status<200||e.response.status>599||typeof e.response.statusText!=`string`)throw TypeError(`Invalid recording`);if(p({...e.matcher,searchParams:e.matcher.searchParams?new URLSearchParams(e.matcher.searchParams):void 0},2**53-1),!e.response.headers||Object.values(e.response.headers).some(e=>typeof e!=`string`))throw TypeError(`Invalid recorded headers`);new Response(null,e.response)}function d(e,t){if(e===void 0)return t;if(!Number.isSafeInteger(e)||e<=0)throw TypeError(`Mock recording limits must be positive safe integers`);return e}function f(e){return/^(?:authorization|proxyauthorization|cookie|setcookie|password|passwd|secret|token|accesstoken|refreshtoken|apikey|xapikey|clientsecret|sessionid|csrftoken|xcsrftoken|xsrftoken|xxsrftoken|xauthtoken)$/i.test(e.replace(/[-_]/g,``))}function p(e,t){let n=String(e.url);if(/^(?:[a-z][a-z\d+.-]*:)?\/\/[^/?#]*@/i.test(n))throw TypeError(`Credential URL`);if(n.includes(`#`))throw TypeError(`Fragment URL`);let r=n.indexOf(`?`);if(r!==-1){let e=new URLSearchParams(n.slice(r+1).split(`#`,1)[0]);for(let t of e.keys())if(f(t))throw TypeError(`Sensitive URL query`)}let i={url:n};if(e.query){for(let t of Object.keys(e.query))if(f(t))throw TypeError(`Sensitive query`);i.query=m(Object.fromEntries(Object.entries(e.query).filter(([,e])=>e!==void 0).map(([e,t])=>[e,Array.isArray(t)?t.filter(e=>e!==void 0):t])),t)}if(e.searchParams){for(let t of e.searchParams.keys())if(f(t))throw TypeError(`Sensitive searchParams`);i.searchParams=[...e.searchParams]}return m(i,t)}function m(e,t){let n=new Set,r=new TextEncoder,i=t,a=e=>{if(e.length>i||(i-=r.encode(e).byteLength,i<0))throw TypeError(`Recording too large`)},o=(e,t)=>{if(t>64)throw TypeError(`Recording too deep`);if(e===null||typeof e==`boolean`)return a(String(e)),e;if(typeof e==`string`){if(e.length>i)throw TypeError(`Recording too large`);return a(JSON.stringify(e)),e}if(typeof e==`number`&&Number.isFinite(e)&&!Object.is(e,-0))return a(String(e)),e;if(typeof e!=`object`||n.has(e))throw TypeError(`Non-JSON recording`);let r=Array.isArray(e);if(r&&e.length>(i-2)/2)throw TypeError(`Recording too large`);if(!r&&Object.getPrototypeOf(e)!==Object.prototype&&Object.getPrototypeOf(e)!==null)throw TypeError(`Non-JSON recording`);if(Object.getOwnPropertySymbols(e).length)throw TypeError(`Symbol recording`);n.add(e),a(`[]`);let s=r?[]:Object.create(null),c=Object.keys(e);if(c.length>i/2)throw TypeError(`Recording too large`);for(let n of c){let c=Object.getOwnPropertyDescriptor(e,n);if(n.length>i)throw TypeError(`Recording too large`);if(!(`value`in c))throw TypeError(`Accessor recording`);if(r&&!/^(0|[1-9]\d*)$/.test(n))throw TypeError(`Non-JSON array`);a(`,`),r||a(`${JSON.stringify(n)}:`);let l=f(n)?`[REDACTED]`:c.value,u=o(l,t+1);r?s.push(u):s[n]=u}if(r&&s.length!==e.length)throw TypeError(`Sparse recording`);return n.delete(e),s};return o(e,0)}function h(e){return JSON.stringify(e).replace(/</g,`\\u003c`)}var MockAdapter=class{constructor(e={}){this.handlers=new Map,this.rules=[],this.requests=[],this.delay=k(e.delay),this.recorder=e.record===void 0?void 0:new MockRecorder(e.record),Object.entries(e.handlers??{}).forEach(([e,t])=>{this.handlers.set(e,t)})}get history(){return[...this.requests]}get recordings(){return this.recorder?.recordings??[]}get recordingStats(){return this.recorder?.stats??{recorded:0,skipped:0}}exportMocks(){return this.recorder?.exportMocks()??``}clearRecordings(){return this.recorder?.clear(),this}on(e,t){return this.handlers.set(e,t),this}onMethod(e,t){let n=g(t);return new RouteBuilder({reply:(t,r,i,a)=>this.registerReply(e,n,t,r,i,a),error:(t,r,i)=>this.registerError(e,n,t,r,i)})}onGet(e){return this.onMethod(`GET`,e)}onPost(e){return this.onMethod(`POST`,e)}onPut(e){return this.onMethod(`PUT`,e)}onPatch(e){return this.onMethod(`PATCH`,e)}onDelete(e){return this.onMethod(`DELETE`,e)}onHead(e){return this.onMethod(`HEAD`,e)}onOptions(e){return this.onMethod(`OPTIONS`,e)}resetHistory(){return this.requests.length=0,this}resetHandlers(){return this.handlers.clear(),this.rules.length=0,this}reset(){return this.resetHandlers().resetHistory().clearRecordings()}async request(e){this.requests.push(e);let t=e.method??`GET`,n=this.rules.findIndex(n=>(n.method===void 0||n.method===t)&&_(n.matcher,e));if(n!==-1){let t=this.rules[n];return t.once&&this.rules.splice(n,1),w(await t.respond(e),e)}let r=this.handlers.get(String(e.url));if(!r){if(this.recorder)return this.recorder.request(e);throw Error(`No mock handler found for ${e.url} (${t})`)}return await A(this.delay,e),w(C(e,{status:200,statusText:`OK`,data:await r(e)}),e)}registerReply(e,t,n,r,i,a={}){let o=typeof r==`function`?r:()=>({status:r,data:i,...a});return this.rules.push({method:e,matcher:t,once:n,respond:async e=>{let t=await o(e);return await A(k(t.delay??this.delay),e),C(e,t)}}),this}registerError(t,n,r,i,a){return this.rules.push({method:t,matcher:n,once:r,respond:async t=>{throw await A(this.delay,t),new e(a,{code:i,config:t})}}),this}},RouteBuilder=class{constructor(e){this.registrar=e}reply(e,t,n={}){return this.registrar.reply(!1,e,t,n)}replyOnce(e,t,n={}){return this.registrar.reply(!0,e,t,n)}networkError(e=`Mock network error`){return this.registrar.error(!1,`NETWORK_ERROR`,e)}networkErrorOnce(e=`Mock network error`){return this.registrar.error(!0,`NETWORK_ERROR`,e)}timeout(e=`Mock request timeout`){return this.registrar.error(!1,`TIMEOUT_ERROR`,e)}timeoutOnce(e=`Mock request timeout`){return this.registrar.error(!0,`TIMEOUT_ERROR`,e)}};function g(e){return typeof e==`string`||e instanceof RegExp?{url:e}:e}function _(e,t){return v(e.url,String(t.url))&&y(e.query,t.query)&&x(e.searchParams,t.searchParams)&&S(e.headers,t.headers)}function v(e,t){return typeof e==`string`?e===t:(e.lastIndex=0,e.test(t))}function y(e,t){return!e||b(e)===b(t)}function b(e){if(!e)return`[]`;let t=[];for(let n of Object.keys(e).sort()){let r=e[n],i=Array.isArray(r)?r:[r];for(let e of i)e!==void 0&&t.push([n,e===null?``:String(e)])}return JSON.stringify(t)}function x(e,t){return!e||JSON.stringify([...e.entries()])===JSON.stringify([...t?.entries()??[]])}function S(e,t){if(!e)return!0;let n=new Headers(e),r=new Headers(t);for(let[e,t]of n.entries())if(r.get(e)!==t)return!1;return!0}function C(e,t){let n=new Headers(t.headers),r=D(t.data,n,t.status),i=t.statusText??T(t.status),a=new Response(r,{status:t.status,statusText:i,headers:n});return{data:t.data,status:t.status,statusText:i,headers:a.headers,config:e,raw:a}}function w(t,n){if(!o(t.status,n))throw new e(t.statusText||`Mock request failed`,{code:`HTTP_ERROR`,response:t});return t}function T(e){return E[e]??``}const E={200:`OK`,201:`Created`,202:`Accepted`,204:`No Content`,400:`Bad Request`,401:`Unauthorized`,403:`Forbidden`,404:`Not Found`,408:`Request Timeout`,409:`Conflict`,422:`Unprocessable Content`,429:`Too Many Requests`,500:`Internal Server Error`,502:`Bad Gateway`,503:`Service Unavailable`,504:`Gateway Timeout`};function D(e,t,n){return e==null||i(void 0,n)?null:typeof e==`string`||O(e)?e:(t.has(`content-type`)||t.set(`content-type`,`application/json`),JSON.stringify(e))}function O(e){return t(e)||a(e)||n(e)||s(e)||r(e)||ArrayBuffer.isView(e)}function k(e){return Number.isFinite(e)?Math.min(Math.max(0,e??0),l):e&&e>0?l:0}function A(t,n){let r=n.signal;if(r?.aborted)return Promise.reject(j(r.reason,n));let i=n.timeout&&n.timeout>0?n.timeout:void 0,a=i!==void 0&&i<=t,o=a?i:t;return o<=0?Promise.resolve():new Promise((t,s)=>{let c,l=!1,u=()=>{c!==void 0&&(clearTimeout(c),c=void 0);try{r?.removeEventListener(`abort`,f)}catch{}},d=e=>{l||(l=!0,u(),s(e))},f=()=>{d(j(r?.reason,n))};try{r?.addEventListener(`abort`,f,{once:!0})}catch(e){d(e);return}if(r?.aborted&&f(),!l)try{c=setTimeout(()=>{a?d(new e(`Request timeout after ${i}ms`,{code:`TIMEOUT_ERROR`,config:n})):(l=!0,u(),t())},o)}catch(e){d(e)}})}function j(t,n){return new e(`Mock request aborted`,{code:`ABORT_ERROR`,config:n,cause:t})}export{MockAdapter as t};
@@ -1,5 +1,4 @@
1
- import { h as RequestConfig, t as NporaResponse } from "./response-BhOBjarL.js";
2
- //#region src/interceptors/InterceptorManager.d.ts
1
+ import { h as RequestConfig, t as NporaResponse } from "./response-DFr_buHv.cjs";
3
2
  type Interceptor<T> = (value: T) => T | Promise<T>;
4
3
  interface InterceptorOptions {
5
4
  /**
@@ -21,8 +20,6 @@ declare class InterceptorManager<T> {
21
20
  private runMaybeAsync;
22
21
  private refreshOrder;
23
22
  }
24
- //#endregion
25
- //#region src/core/RequestContext.d.ts
26
23
  declare class RequestContext<T = unknown> {
27
24
  readonly preserveRaw: boolean;
28
25
  /** @internal */
@@ -47,8 +44,6 @@ declare class RequestContext<T = unknown> {
47
44
  /** @internal */
48
45
  background?: boolean);
49
46
  }
50
- //#endregion
51
- //#region src/interceptors/PluginHooks.d.ts
52
47
  interface RetryDecision {
53
48
  retry: boolean;
54
49
  delay?: number;
@@ -66,8 +61,6 @@ interface HookOptions {
66
61
  type HookDisposer = () => void;
67
62
  type RequestHook = (context: RequestContext<unknown>) => void | Promise<void>;
68
63
  type RetryHook = (context: RequestContext<unknown>, attempt: number) => RetryDecision | undefined | Promise<RetryDecision | undefined>;
69
- //#endregion
70
- //#region src/plugins/Plugin.d.ts
71
64
  interface PluginInterceptorManager<T> {
72
65
  use(interceptor: Interceptor<T>, options?: InterceptorOptions): number;
73
66
  eject(id: number): void;
@@ -127,5 +120,4 @@ interface Plugin {
127
120
  conflicts?: readonly string[];
128
121
  install: (context: PluginContext) => void | PluginCleanup;
129
122
  }
130
- //#endregion
131
123
  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 };
@@ -1,5 +1,4 @@
1
- import { h as RequestConfig, t as NporaResponse } from "./response-CXF5lNlw.cjs";
2
- //#region src/interceptors/InterceptorManager.d.ts
1
+ import { h as RequestConfig, t as NporaResponse } from "./response-BepuyaMD.js";
3
2
  type Interceptor<T> = (value: T) => T | Promise<T>;
4
3
  interface InterceptorOptions {
5
4
  /**
@@ -21,8 +20,6 @@ declare class InterceptorManager<T> {
21
20
  private runMaybeAsync;
22
21
  private refreshOrder;
23
22
  }
24
- //#endregion
25
- //#region src/core/RequestContext.d.ts
26
23
  declare class RequestContext<T = unknown> {
27
24
  readonly preserveRaw: boolean;
28
25
  /** @internal */
@@ -47,8 +44,6 @@ declare class RequestContext<T = unknown> {
47
44
  /** @internal */
48
45
  background?: boolean);
49
46
  }
50
- //#endregion
51
- //#region src/interceptors/PluginHooks.d.ts
52
47
  interface RetryDecision {
53
48
  retry: boolean;
54
49
  delay?: number;
@@ -66,8 +61,6 @@ interface HookOptions {
66
61
  type HookDisposer = () => void;
67
62
  type RequestHook = (context: RequestContext<unknown>) => void | Promise<void>;
68
63
  type RetryHook = (context: RequestContext<unknown>, attempt: number) => RetryDecision | undefined | Promise<RetryDecision | undefined>;
69
- //#endregion
70
- //#region src/plugins/Plugin.d.ts
71
64
  interface PluginInterceptorManager<T> {
72
65
  use(interceptor: Interceptor<T>, options?: InterceptorOptions): number;
73
66
  eject(id: number): void;
@@ -127,5 +120,4 @@ interface Plugin {
127
120
  conflicts?: readonly string[];
128
121
  install: (context: PluginContext) => void | PluginCleanup;
129
122
  }
130
- //#endregion
131
123
  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 };
@@ -1,4 +1,3 @@
1
- //#region src/plugins/PluginError.d.ts
2
1
  type PluginErrorCode = 'MISSING_DEPENDENCY' | 'PLUGIN_CONFLICT' | 'DEPENDENCY_IN_USE';
3
2
  interface PluginErrorOptions {
4
3
  code: PluginErrorCode;
@@ -14,5 +13,4 @@ declare class PluginError extends Error {
14
13
  readonly relatedPlugin: string;
15
14
  constructor(message: string, options: PluginErrorOptions);
16
15
  }
17
- //#endregion
18
16
  export { PluginErrorCode as n, PluginErrorOptions as r, PluginError as t };
@@ -1,4 +1,3 @@
1
- //#region src/plugins/PluginError.d.ts
2
1
  type PluginErrorCode = 'MISSING_DEPENDENCY' | 'PLUGIN_CONFLICT' | 'DEPENDENCY_IN_USE';
3
2
  interface PluginErrorOptions {
4
3
  code: PluginErrorCode;
@@ -14,5 +13,4 @@ declare class PluginError extends Error {
14
13
  readonly relatedPlugin: string;
15
14
  constructor(message: string, options: PluginErrorOptions);
16
15
  }
17
- //#endregion
18
16
  export { PluginErrorCode as n, PluginErrorOptions as r, PluginError as t };
@@ -1,8 +1,7 @@
1
- import { _ as RequestInputConfig, a as SseStateObserver, h as RequestConfig, n as ServerSentEvent, o as StreamingSchemaLocation, r as SseReconnectOptions, t as NporaResponse, v as RequestURL } from "./response-CXF5lNlw.cjs";
2
- import { t as StandardSchemaV1 } from "./standardSchema-CjWI0T2o.cjs";
3
- import { t as Adapter } from "./adapter-Cq9y_Fww.cjs";
4
- import { s as InterceptorManager, t as Plugin } from "./Plugin-CCFavD-_.cjs";
5
- //#region src/types/client.d.ts
1
+ import { _ as RequestInputConfig, a as SseStateObserver, h as RequestConfig, n as ServerSentEvent, o as StreamingSchemaLocation, r as SseReconnectOptions, t as NporaResponse, v as RequestURL } from "./response-BepuyaMD.js";
2
+ import { t as StandardSchemaV1 } from "./standardSchema-DkCdVLKc.js";
3
+ import { t as Adapter } from "./adapter-B-L43hnj.js";
4
+ import { s as InterceptorManager, t as Plugin } from "./Plugin-C3xZTHbG.js";
6
5
  /**
7
6
  * Client creation options.
8
7
  */
@@ -14,8 +13,6 @@ interface ClientOptions extends Partial<Omit<RequestConfig, 'url' | 'method' | '
14
13
  */
15
14
  adapter?: Adapter;
16
15
  }
17
- //#endregion
18
- //#region src/client/methodTypes.d.ts
19
16
  type MethodConfig = Omit<RequestConfig, 'url' | 'method'>;
20
17
  type SchemaMethodConfig<Schema extends StandardSchemaV1> = Omit<MethodConfig, 'schema'> & {
21
18
  schema: Schema;
@@ -32,8 +29,6 @@ type SseSchemaMethodConfig<Schema extends StandardSchemaV1> = Omit<SseMethodConf
32
29
  type ItemSchemaMethodConfig<Schema extends StandardSchemaV1> = Omit<StreamingMethodConfig, 'itemSchema'> & {
33
30
  itemSchema: Schema;
34
31
  };
35
- //#endregion
36
- //#region src/client/Client.d.ts
37
32
  declare class Client {
38
33
  private readonly defaults;
39
34
  private readonly adapter;
@@ -126,21 +121,15 @@ declare class Client {
126
121
  private validatePlugin;
127
122
  private findDependent;
128
123
  }
129
- //#endregion
130
- //#region src/client/createClient.d.ts
131
124
  /**
132
125
  * Create an HTTP client instance.
133
126
  */
134
127
  declare function createClient(options?: ClientOptions): Client;
135
- //#endregion
136
- //#region src/adapters/FetchAdapter.d.ts
137
128
  declare class FetchAdapter implements Adapter {
138
129
  request<T = unknown>(config: RequestConfig): Promise<NporaResponse<T>>;
139
130
  requestValidated<T = unknown>(config: RequestConfig, validatedHeaders: Headers, preserveRaw?: boolean): Promise<NporaResponse<T>>;
140
131
  private execute;
141
132
  }
142
- //#endregion
143
- //#region src/errors/RequestError.d.ts
144
133
  /**
145
134
  * Public request error codes.
146
135
  */
@@ -199,8 +188,6 @@ declare class RequestError<T = unknown> extends Error {
199
188
  * Identify request errors across realms and duplicated package instances.
200
189
  */
201
190
  declare function isRequestError<T = unknown>(value: unknown): value is RequestError<T>;
202
- //#endregion
203
- //#region src/errors/SchemaValidationError.d.ts
204
191
  /**
205
192
  * Response failure reported by a Standard Schema compatible validator.
206
193
  */
@@ -221,5 +208,4 @@ declare class SchemaValidationError<T = unknown> extends RequestError<T> {
221
208
  * Identify schema validation errors across realms and package instances.
222
209
  */
223
210
  declare function isSchemaValidationError<T = unknown>(value: unknown): value is SchemaValidationError<T>;
224
- //#endregion
225
211
  export { RequestErrorOptions as a, createClient as c, RequestErrorCode as i, Client as l, isSchemaValidationError as n, isRequestError as o, RequestError as r, FetchAdapter as s, SchemaValidationError as t, ClientOptions as u };
@@ -1,8 +1,7 @@
1
- import { _ as RequestInputConfig, a as SseStateObserver, h as RequestConfig, n as ServerSentEvent, o as StreamingSchemaLocation, r as SseReconnectOptions, t as NporaResponse, v as RequestURL } from "./response-BhOBjarL.js";
2
- import { t as StandardSchemaV1 } from "./standardSchema-CjWI0T2o.js";
3
- import { t as Adapter } from "./adapter-CcfItVkl.js";
4
- import { s as InterceptorManager, t as Plugin } from "./Plugin-BG4NQC3T.js";
5
- //#region src/types/client.d.ts
1
+ import { _ as RequestInputConfig, a as SseStateObserver, h as RequestConfig, n as ServerSentEvent, o as StreamingSchemaLocation, r as SseReconnectOptions, t as NporaResponse, v as RequestURL } from "./response-DFr_buHv.cjs";
2
+ import { t as StandardSchemaV1 } from "./standardSchema-DkCdVLKc.cjs";
3
+ import { t as Adapter } from "./adapter-Q6uDyqF2.cjs";
4
+ import { s as InterceptorManager, t as Plugin } from "./Plugin-BQcrWrNm.cjs";
6
5
  /**
7
6
  * Client creation options.
8
7
  */
@@ -14,8 +13,6 @@ interface ClientOptions extends Partial<Omit<RequestConfig, 'url' | 'method' | '
14
13
  */
15
14
  adapter?: Adapter;
16
15
  }
17
- //#endregion
18
- //#region src/client/methodTypes.d.ts
19
16
  type MethodConfig = Omit<RequestConfig, 'url' | 'method'>;
20
17
  type SchemaMethodConfig<Schema extends StandardSchemaV1> = Omit<MethodConfig, 'schema'> & {
21
18
  schema: Schema;
@@ -32,8 +29,6 @@ type SseSchemaMethodConfig<Schema extends StandardSchemaV1> = Omit<SseMethodConf
32
29
  type ItemSchemaMethodConfig<Schema extends StandardSchemaV1> = Omit<StreamingMethodConfig, 'itemSchema'> & {
33
30
  itemSchema: Schema;
34
31
  };
35
- //#endregion
36
- //#region src/client/Client.d.ts
37
32
  declare class Client {
38
33
  private readonly defaults;
39
34
  private readonly adapter;
@@ -126,21 +121,15 @@ declare class Client {
126
121
  private validatePlugin;
127
122
  private findDependent;
128
123
  }
129
- //#endregion
130
- //#region src/client/createClient.d.ts
131
124
  /**
132
125
  * Create an HTTP client instance.
133
126
  */
134
127
  declare function createClient(options?: ClientOptions): Client;
135
- //#endregion
136
- //#region src/adapters/FetchAdapter.d.ts
137
128
  declare class FetchAdapter implements Adapter {
138
129
  request<T = unknown>(config: RequestConfig): Promise<NporaResponse<T>>;
139
130
  requestValidated<T = unknown>(config: RequestConfig, validatedHeaders: Headers, preserveRaw?: boolean): Promise<NporaResponse<T>>;
140
131
  private execute;
141
132
  }
142
- //#endregion
143
- //#region src/errors/RequestError.d.ts
144
133
  /**
145
134
  * Public request error codes.
146
135
  */
@@ -199,8 +188,6 @@ declare class RequestError<T = unknown> extends Error {
199
188
  * Identify request errors across realms and duplicated package instances.
200
189
  */
201
190
  declare function isRequestError<T = unknown>(value: unknown): value is RequestError<T>;
202
- //#endregion
203
- //#region src/errors/SchemaValidationError.d.ts
204
191
  /**
205
192
  * Response failure reported by a Standard Schema compatible validator.
206
193
  */
@@ -221,5 +208,4 @@ declare class SchemaValidationError<T = unknown> extends RequestError<T> {
221
208
  * Identify schema validation errors across realms and package instances.
222
209
  */
223
210
  declare function isSchemaValidationError<T = unknown>(value: unknown): value is SchemaValidationError<T>;
224
- //#endregion
225
211
  export { RequestErrorOptions as a, createClient as c, RequestErrorCode as i, Client as l, isSchemaValidationError as n, isRequestError as o, RequestError as r, FetchAdapter as s, SchemaValidationError as t, ClientOptions as u };
@@ -1,5 +1,4 @@
1
- import { h as RequestConfig, t as NporaResponse } from "./response-BhOBjarL.js";
2
- //#region src/types/adapter.d.ts
1
+ import { h as RequestConfig, t as NporaResponse } from "./response-BepuyaMD.js";
3
2
  /**
4
3
  * Request adapter.
5
4
  */
@@ -17,5 +16,4 @@ interface Adapter {
17
16
  */
18
17
  requestValidated?<T = unknown>(config: RequestConfig, validatedHeaders: Headers, preserveRaw?: boolean): Promise<NporaResponse<T>>;
19
18
  }
20
- //#endregion
21
19
  export { Adapter as t };
@@ -1,5 +1,4 @@
1
- import { h as RequestConfig, t as NporaResponse } from "./response-CXF5lNlw.cjs";
2
- //#region src/types/adapter.d.ts
1
+ import { h as RequestConfig, t as NporaResponse } from "./response-DFr_buHv.cjs";
3
2
  /**
4
3
  * Request adapter.
5
4
  */
@@ -17,5 +16,4 @@ interface Adapter {
17
16
  */
18
17
  requestValidated?<T = unknown>(config: RequestConfig, validatedHeaders: Headers, preserveRaw?: boolean): Promise<NporaResponse<T>>;
19
18
  }
20
- //#endregion
21
19
  export { Adapter as t };
@@ -1,5 +1,4 @@
1
- import { t as Plugin } from "./Plugin-BG4NQC3T.js";
2
- //#region src/plugins/authPlugin.d.ts
1
+ import { t as Plugin } from "./Plugin-C3xZTHbG.js";
3
2
  type MaybePromise<T> = T | Promise<T>;
4
3
  /**
5
4
  * Token storage used by the authentication extension.
@@ -49,5 +48,4 @@ interface AuthPluginOptions {
49
48
  * Authentication plugin.
50
49
  */
51
50
  declare function authPlugin(options?: AuthPluginOptions): Plugin;
52
- //#endregion
53
51
  export { AuthTokenStorage as n, authPlugin as r, AuthPluginOptions as t };
@@ -1,5 +1,4 @@
1
- import { t as Plugin } from "./Plugin-CCFavD-_.cjs";
2
- //#region src/plugins/authPlugin.d.ts
1
+ import { t as Plugin } from "./Plugin-BQcrWrNm.cjs";
3
2
  type MaybePromise<T> = T | Promise<T>;
4
3
  /**
5
4
  * Token storage used by the authentication extension.
@@ -49,5 +48,4 @@ interface AuthPluginOptions {
49
48
  * Authentication plugin.
50
49
  */
51
50
  declare function authPlugin(options?: AuthPluginOptions): Plugin;
52
- //#endregion
53
51
  export { AuthTokenStorage as n, authPlugin as r, AuthPluginOptions as t };
@@ -1,6 +1,5 @@
1
- import { K as HttpMethod, h as RequestConfig } from "./response-BhOBjarL.js";
2
- import { t as Plugin } from "./Plugin-BG4NQC3T.js";
3
- //#region src/plugins/cacheStores.d.ts
1
+ import { K as HttpMethod, h as RequestConfig } from "./response-BepuyaMD.js";
2
+ import { t as Plugin } from "./Plugin-C3xZTHbG.js";
4
3
  type MaybePromise$1<T> = T | Promise<T>;
5
4
  interface CacheEntry {
6
5
  data: unknown;
@@ -67,8 +66,6 @@ declare class WebStorageCacheStore implements CacheStore {
67
66
  private keys;
68
67
  private read;
69
68
  }
70
- //#endregion
71
- //#region src/plugins/cacheTypes.d.ts
72
69
  interface CachePluginOptions {
73
70
  /**
74
71
  * HTTP methods that may be cached.
@@ -151,8 +148,6 @@ interface CacheStats {
151
148
  backgroundRefreshSuccesses: number;
152
149
  backgroundRefreshErrors: number;
153
150
  }
154
- //#endregion
155
- //#region src/plugins/indexedDBCacheTypes.d.ts
156
151
  interface IndexedDBCacheStoreOptions {
157
152
  /** Database shared by cache namespaces. @default @npora/request-cache */
158
153
  databaseName?: string;
@@ -201,8 +196,6 @@ interface IndexedDBCacheStoreEvent {
201
196
  estimatedBytes: number;
202
197
  timestamp: number;
203
198
  }
204
- //#endregion
205
- //#region src/plugins/indexedDBCacheStore.d.ts
206
199
  /** A namespaced asynchronous cache backed by IndexedDB. */
207
200
  declare class IndexedDBCacheStore implements CacheStore {
208
201
  private readonly namespace;
@@ -235,8 +228,6 @@ declare class IndexedDBCacheStore implements CacheStore {
235
228
  private visitNamespace;
236
229
  private getDatabase;
237
230
  }
238
- //#endregion
239
- //#region src/plugins/tieredCacheStore.d.ts
240
231
  type MaybePromise<T> = T | Promise<T>;
241
232
  interface TieredCacheStoreOptions {
242
233
  /** Fast first-level store, usually MemoryCacheStore. */
@@ -296,8 +287,5 @@ declare class TieredCacheStore implements CacheStore {
296
287
  private afterSuccess;
297
288
  private afterSettled;
298
289
  }
299
- //#endregion
300
- //#region src/plugins/cachePlugin.d.ts
301
290
  declare function cachePlugin(options?: CachePluginOptions): CachePlugin;
302
- //#endregion
303
291
  export { WebStorageCacheStore as C, MemoryCacheStoreOptions as S, CacheStats as _, TieredCacheStoreOptions as a, CacheStore as b, IndexedDBCacheCompactionResult as c, IndexedDBCacheUsage as d, CacheEvent as f, CacheSetOptions as g, CachePluginOptions as h, TieredCacheStore as i, IndexedDBCacheStoreEvent as l, CachePlugin as m, TieredCacheBroadcastOptions as n, IndexedDBCacheStore as o, CacheEventType as p, TieredCacheCoordinationOptions as r, IndexedDBCacheCompactionOptions as s, cachePlugin as t, IndexedDBCacheStoreOptions as u, CacheEntry as v, WebStorageCacheStoreOptions as w, MemoryCacheStore as x, CacheRefreshLease as y };