@ahoo-wang/fetcher 0.9.2 → 0.9.5

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.
@@ -1,13 +1,28 @@
1
- import { Interceptor } from './interceptor';
1
+ import { RequestInterceptor } from './interceptor';
2
2
  import { FetchExchange } from './fetchExchange';
3
+ /**
4
+ * The name of the UrlResolveInterceptor.
5
+ */
6
+ export declare const URL_RESOLVE_INTERCEPTOR_NAME = "UrlResolveInterceptor";
7
+ /**
8
+ * The order of the UrlResolveInterceptor.
9
+ * Set to Number.MIN_SAFE_INTEGER + 1000 to ensure it runs earliest among request interceptors.
10
+ */
11
+ export declare const URL_RESOLVE_INTERCEPTOR_ORDER: number;
3
12
  /**
4
13
  * Interceptor responsible for resolving the final URL for a request.
5
14
  *
6
15
  * This interceptor combines the base URL, path parameters, and query parameters
7
- * to create the final URL for a request. It should be executed early in
16
+ * to create the final URL for a request. It should be executed earliest in
8
17
  * the interceptor chain to ensure the URL is properly resolved before other interceptors
9
18
  * process the request.
10
19
  *
20
+ * @remarks
21
+ * This interceptor runs at the very beginning of the request interceptor chain to ensure
22
+ * URL resolution happens before any other request processing. The order is set to
23
+ * URL_RESOLVE_INTERCEPTOR_ORDER to ensure it executes before all other request interceptors,
24
+ * establishing the foundation for subsequent processing.
25
+ *
11
26
  * @example
12
27
  * // With baseURL: 'https://api.example.com'
13
28
  * // Request URL: '/users/{id}'
@@ -15,20 +30,20 @@ import { FetchExchange } from './fetchExchange';
15
30
  * // Query params: { filter: 'active' }
16
31
  * // Final URL: 'https://api.example.com/users/123?filter=active'
17
32
  */
18
- export declare class UrlResolveInterceptor implements Interceptor {
33
+ export declare class UrlResolveInterceptor implements RequestInterceptor {
19
34
  /**
20
35
  * The name of this interceptor.
21
36
  */
22
- name: string;
37
+ readonly name = "UrlResolveInterceptor";
23
38
  /**
24
- * The order of this interceptor (executed first).
39
+ * The order of this interceptor (executed earliest).
25
40
  *
26
- * This interceptor should run first in the request interceptor chain to ensure
41
+ * This interceptor should run at the very beginning of the request interceptor chain to ensure
27
42
  * URL resolution happens before any other request processing. The order is set to
28
- * Number.MIN_SAFE_INTEGER + 100 to allow for other interceptors that need to run
29
- * even earlier while still maintaining a high priority.
43
+ * URL_RESOLVE_INTERCEPTOR_ORDER to ensure it executes before all other request interceptors,
44
+ * establishing the foundation for subsequent processing.
30
45
  */
31
- order: number;
46
+ readonly order: number;
32
47
  /**
33
48
  * Resolves the final URL by combining the base URL, path parameters, and query parameters.
34
49
  *
@@ -1 +1 @@
1
- {"version":3,"file":"urlResolveInterceptor.d.ts","sourceRoot":"","sources":["../src/urlResolveInterceptor.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD;;;;;;;;;;;;;;GAcG;AACH,qBAAa,qBAAsB,YAAW,WAAW;IACvD;;OAEG;IACH,IAAI,SAA2B;IAE/B;;;;;;;OAOG;IACH,KAAK,SAAiC;IAEtC;;;;OAIG;IACH,SAAS,CAAC,QAAQ,EAAE,aAAa;CAIlC"}
1
+ {"version":3,"file":"urlResolveInterceptor.d.ts","sourceRoot":"","sources":["../src/urlResolveInterceptor.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD;;GAEG;AACH,eAAO,MAAM,4BAA4B,0BAA0B,CAAC;AAEpE;;;GAGG;AACH,eAAO,MAAM,6BAA6B,QAAiC,CAAC;AAE5E;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,qBAAa,qBAAsB,YAAW,kBAAkB;IAC9D;;OAEG;IACH,QAAQ,CAAC,IAAI,2BAAgC;IAE7C;;;;;;;OAOG;IACH,QAAQ,CAAC,KAAK,SAAiC;IAE/C;;;;OAIG;IACH,SAAS,CAAC,QAAQ,EAAE,aAAa;CAIlC"}
@@ -0,0 +1,112 @@
1
+ import { ResponseInterceptor } from './interceptor';
2
+ import { FetchExchange } from './fetchExchange';
3
+ import { FetcherError } from './fetcherError';
4
+ /**
5
+ * Error thrown when response status validation fails.
6
+ *
7
+ * This error is thrown by ValidateStatusInterceptor when the response status
8
+ * does not pass the validation defined by the validateStatus function.
9
+ */
10
+ export declare class HttpStatusValidationError extends FetcherError {
11
+ readonly exchange: FetchExchange;
12
+ constructor(exchange: FetchExchange);
13
+ }
14
+ /**
15
+ * Defines whether to resolve or reject the promise for a given HTTP response status code.
16
+ * If `validateStatus` returns `true` (or is set to `null` or `undefined`), the promise will be resolved;
17
+ * otherwise, the promise will be rejected.
18
+ *
19
+ * @param status - HTTP response status code
20
+ * @returns true to resolve the promise, false to reject it
21
+ *
22
+ * @example
23
+ * ```typescript
24
+ * // Default behavior (2xx status codes are resolved)
25
+ * const fetcher = new Fetcher();
26
+ *
27
+ * // Custom behavior (only 200 status code is resolved)
28
+ * const fetcher = new Fetcher({
29
+ * validateStatus: (status) => status === 200
30
+ * });
31
+ *
32
+ * // Always resolve (never reject based on status)
33
+ * const fetcher = new Fetcher({
34
+ * validateStatus: (status) => true
35
+ * });
36
+ * ```
37
+ */
38
+ type ValidateStatus = (status: number) => boolean;
39
+ /**
40
+ * The name of the ValidateStatusInterceptor.
41
+ */
42
+ export declare const VALIDATE_STATUS_INTERCEPTOR_NAME = "ValidateStatusInterceptor";
43
+ /**
44
+ * The order of the ValidateStatusInterceptor.
45
+ * Set to Number.MAX_SAFE_INTEGER - 1000 to ensure it runs latest among response interceptors,
46
+ * but still allows other interceptors to run after it if needed.
47
+ */
48
+ export declare const VALIDATE_STATUS_INTERCEPTOR_ORDER: number;
49
+ /**
50
+ * Response interceptor that validates HTTP status codes.
51
+ *
52
+ * This interceptor implements behavior similar to axios's validateStatus option.
53
+ * It checks the response status code against a validation function and throws
54
+ * an error if the status is not valid.
55
+ *
56
+ * @remarks
57
+ * This interceptor runs at the very beginning of the response interceptor chain to ensure
58
+ * status validation happens before any other response processing. The order is set to
59
+ * VALIDATE_STATUS_INTERCEPTOR_ORDER to ensure it executes early in the response chain,
60
+ * allowing for other response interceptors to run after it if needed. This positioning
61
+ * ensures that invalid responses are caught and handled early in the response processing
62
+ * pipeline, before other response handlers attempt to process them.
63
+ *
64
+ * @example
65
+ * ```typescript
66
+ * // Default behavior (2xx status codes are valid)
67
+ * const interceptor = new ValidateStatusInterceptor();
68
+ *
69
+ * // Custom validation (only 200 status code is valid)
70
+ * const interceptor = new ValidateStatusInterceptor((status) => status === 200);
71
+ *
72
+ * // Always valid (never throws based on status)
73
+ * const interceptor = new ValidateStatusInterceptor((status) => true);
74
+ * ```
75
+ */
76
+ export declare class ValidateStatusInterceptor implements ResponseInterceptor {
77
+ private readonly validateStatus;
78
+ /**
79
+ * Gets the name of this interceptor.
80
+ *
81
+ * @returns The name of this interceptor
82
+ */
83
+ get name(): string;
84
+ /**
85
+ * Gets the order of this interceptor.
86
+ *
87
+ * @returns VALIDATE_STATUS_INTERCEPTOR_ORDER, indicating this interceptor should execute early
88
+ */
89
+ get order(): number;
90
+ /**
91
+ * Creates a new ValidateStatusInterceptor instance.
92
+ *
93
+ * @param validateStatus - Function that determines if a status code is valid
94
+ */
95
+ constructor(validateStatus?: ValidateStatus);
96
+ /**
97
+ * Validates the response status code.
98
+ *
99
+ * @param exchange - The exchange containing the response to validate
100
+ * @throws HttpStatusValidationError if the status code is not valid
101
+ *
102
+ * @remarks
103
+ * This method runs at the beginning of the response interceptor chain to ensure
104
+ * status validation happens before any other response processing. Invalid responses
105
+ * are caught and converted to HttpStatusValidationError early in the pipeline,
106
+ * preventing other response handlers from attempting to process them. Valid responses
107
+ * proceed through the rest of the response interceptor chain normally.
108
+ */
109
+ intercept(exchange: FetchExchange): void;
110
+ }
111
+ export {};
112
+ //# sourceMappingURL=validateStatusInterceptor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validateStatusInterceptor.d.ts","sourceRoot":"","sources":["../src/validateStatusInterceptor.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C;;;;;GAKG;AACH,qBAAa,yBAA0B,SAAQ,YAAY;aAC7B,QAAQ,EAAE,aAAa;gBAAvB,QAAQ,EAAE,aAAa;CAOpD;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,KAAK,cAAc,GAAG,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC;AAKlD;;GAEG;AACH,eAAO,MAAM,gCAAgC,8BAA8B,CAAC;AAE5E;;;;GAIG;AACH,eAAO,MAAM,iCAAiC,QAAiC,CAAC;AAEhF;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,qBAAa,yBAA0B,YAAW,mBAAmB;IAyBjE,OAAO,CAAC,QAAQ,CAAC,cAAc;IAxBjC;;;;OAIG;IACH,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED;;;;OAIG;IACH,IAAI,KAAK,IAAI,MAAM,CAElB;IAED;;;;OAIG;gBAEgB,cAAc,GAAE,cAAwC;IAI3E;;;;;;;;;;;;OAYG;IACH,SAAS,CAAC,QAAQ,EAAE,aAAa;CAalC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ahoo-wang/fetcher",
3
- "version": "0.9.2",
3
+ "version": "0.9.5",
4
4
  "description": "Ultra-lightweight (1.9kB) HTTP client with built-in path parameters and Axios-like API",
5
5
  "keywords": [
6
6
  "fetch",