api-def 0.10.1 → 0.10.2

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.
@@ -14,13 +14,14 @@ export declare const RequestErrorCode: {
14
14
  readonly VALIDATION_RESPONSE_VALIDATE_ERROR: "validation/response-validate-error";
15
15
  };
16
16
  export type RequestErrorCode = EnumOf<typeof RequestErrorCode>;
17
+ declare const REQUEST_ERROR_SYMBOL: unique symbol;
17
18
  export interface RequestError extends Error {
18
- isRequestError: true;
19
+ [REQUEST_ERROR_SYMBOL]: true;
19
20
  response: ApiResponse | undefined | null;
20
21
  code: string;
21
22
  attempts: number;
22
23
  }
23
- export declare const isRequestError: (error: Error) => error is RequestError;
24
+ export declare const isRequestError: (error: any) => error is RequestError;
24
25
  export interface RequestErrorConfig {
25
26
  error: Error;
26
27
  code: string;
@@ -28,3 +29,4 @@ export interface RequestErrorConfig {
28
29
  response?: ApiResponse | null;
29
30
  }
30
31
  export declare const convertToRequestError: (config: RequestErrorConfig) => RequestError;
32
+ export {};
@@ -13,26 +13,35 @@ exports.RequestErrorCode = {
13
13
  VALIDATION_BODY_VALIDATE_ERROR: "validation/body-validate-error",
14
14
  VALIDATION_RESPONSE_VALIDATE_ERROR: "validation/response-validate-error",
15
15
  };
16
+ var REQUEST_ERROR_SYMBOL = Symbol("isRequestError");
16
17
  var isRequestError = function (error) {
17
- return "isRequestError" in error;
18
+ if (!error) {
19
+ return false;
20
+ }
21
+ if (typeof error !== "object") {
22
+ return false;
23
+ }
24
+ return error[REQUEST_ERROR_SYMBOL] === true;
18
25
  };
19
26
  exports.isRequestError = isRequestError;
20
27
  var convertToRequestError = function (config) {
28
+ var _a;
21
29
  var error = config.error, context = config.context, response = config.response, code = config.code;
22
30
  var body = context.getParsedBody();
23
- var resultError = Object.assign(error, {
24
- name: "RequestError",
25
- response: response,
26
- code: code,
27
- isRequestError: true,
28
- attempts: context.stats.attempt,
29
- request: {
31
+ var resultError = Object.assign(error, (_a = {
32
+ name: "RequestError",
33
+ response: response,
34
+ code: code
35
+ },
36
+ _a[REQUEST_ERROR_SYMBOL] = true,
37
+ _a.attempts = context.stats.attempt,
38
+ _a.request = {
30
39
  url: context.requestUrl.href,
31
40
  query: context.computedConfig.queryObject,
32
41
  headers: context.computedConfig.headers,
33
42
  body: body,
34
43
  },
35
- });
44
+ _a));
36
45
  try {
37
46
  Object.defineProperty(resultError, "message", {
38
47
  value: "Request failed".concat((response === null || response === void 0 ? void 0 : response.status) ? " with status code ".concat(response.status) : "", " [").concat(code, "]: ").concat(resultError.message),
package/cjs/index.d.ts CHANGED
@@ -2,8 +2,8 @@ export * from "./Api";
2
2
  export * from "./ApiTypes";
3
3
  export * from "./UtilTypes";
4
4
  export * from "./ApiConstants";
5
- export { isRequestError } from "./RequestError";
6
- export { default as Endpoint, EndpointConfig } from "./Endpoint";
5
+ export { isRequestError, type RequestError } from "./RequestError";
6
+ export { default as Endpoint, type EndpointConfig } from "./Endpoint";
7
7
  export { clearCache, setCacheBackend } from "./cache/Caching";
8
8
  export { default as LocalStorageCacheBackend } from "./cache/LocalStorageCacheBackend";
9
9
  export { default as LocaleForageCacheBackend } from "./cache/LocalForageCacheBackend";
@@ -14,13 +14,14 @@ export declare const RequestErrorCode: {
14
14
  readonly VALIDATION_RESPONSE_VALIDATE_ERROR: "validation/response-validate-error";
15
15
  };
16
16
  export type RequestErrorCode = EnumOf<typeof RequestErrorCode>;
17
+ declare const REQUEST_ERROR_SYMBOL: unique symbol;
17
18
  export interface RequestError extends Error {
18
- isRequestError: true;
19
+ [REQUEST_ERROR_SYMBOL]: true;
19
20
  response: ApiResponse | undefined | null;
20
21
  code: string;
21
22
  attempts: number;
22
23
  }
23
- export declare const isRequestError: (error: Error) => error is RequestError;
24
+ export declare const isRequestError: (error: any) => error is RequestError;
24
25
  export interface RequestErrorConfig {
25
26
  error: Error;
26
27
  code: string;
@@ -28,3 +29,4 @@ export interface RequestErrorConfig {
28
29
  response?: ApiResponse | null;
29
30
  }
30
31
  export declare const convertToRequestError: (config: RequestErrorConfig) => RequestError;
32
+ export {};
@@ -10,8 +10,15 @@ export const RequestErrorCode = {
10
10
  VALIDATION_BODY_VALIDATE_ERROR: "validation/body-validate-error",
11
11
  VALIDATION_RESPONSE_VALIDATE_ERROR: "validation/response-validate-error",
12
12
  };
13
+ const REQUEST_ERROR_SYMBOL = Symbol("isRequestError");
13
14
  export const isRequestError = (error) => {
14
- return "isRequestError" in error;
15
+ if (!error) {
16
+ return false;
17
+ }
18
+ if (typeof error !== "object") {
19
+ return false;
20
+ }
21
+ return error[REQUEST_ERROR_SYMBOL] === true;
15
22
  };
16
23
  export const convertToRequestError = (config) => {
17
24
  const { error, context, response, code } = config;
@@ -20,7 +27,7 @@ export const convertToRequestError = (config) => {
20
27
  name: "RequestError",
21
28
  response: response,
22
29
  code: code,
23
- isRequestError: true,
30
+ [REQUEST_ERROR_SYMBOL]: true,
24
31
  attempts: context.stats.attempt,
25
32
  request: {
26
33
  url: context.requestUrl.href,
package/esm/index.d.ts CHANGED
@@ -2,8 +2,8 @@ export * from "./Api";
2
2
  export * from "./ApiTypes";
3
3
  export * from "./UtilTypes";
4
4
  export * from "./ApiConstants";
5
- export { isRequestError } from "./RequestError";
6
- export { default as Endpoint, EndpointConfig } from "./Endpoint";
5
+ export { isRequestError, type RequestError } from "./RequestError";
6
+ export { default as Endpoint, type EndpointConfig } from "./Endpoint";
7
7
  export { clearCache, setCacheBackend } from "./cache/Caching";
8
8
  export { default as LocalStorageCacheBackend } from "./cache/LocalStorageCacheBackend";
9
9
  export { default as LocaleForageCacheBackend } from "./cache/LocalForageCacheBackend";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "api-def",
3
- "version": "0.10.1",
3
+ "version": "0.10.2",
4
4
  "description": "Typed API definitions with middleware support",
5
5
  "main": "cjs/index.js",
6
6
  "types": "esm/index.d.ts",
@@ -30,19 +30,19 @@
30
30
  },
31
31
  "repository": "https://github.com/Censkh/api-def",
32
32
  "devDependencies": {
33
- "@biomejs/biome": "1.7.3",
33
+ "@biomejs/biome": "1.8.1",
34
34
  "@swc/core": "latest",
35
35
  "@swc/jest": "latest",
36
36
  "@types/axios": "0.14.0",
37
37
  "@types/jest": "^29.5.12",
38
- "@types/node": "20.12.11",
38
+ "@types/node": "20.14.2",
39
39
  "@types/qs": "6.9.15",
40
- "axios": "1.6.8",
40
+ "axios": "1.7.2",
41
41
  "cross-env": "7.0.3",
42
42
  "jest": "latest",
43
43
  "npm-run-all": "4.1.5",
44
44
  "qs": "6.12.1",
45
- "rimraf": "5.0.6",
45
+ "rimraf": "5.0.7",
46
46
  "typescript": "5.4.5",
47
47
  "zod": "3.23.8"
48
48
  }