@xylabs/axios 5.0.28 → 5.0.30

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,17 +1,26 @@
1
1
  import type { Logger } from '@xylabs/logger';
2
- import type { AxiosInstance, AxiosResponse, RawAxiosRequestConfig } from 'axios';
3
- import { Axios } from 'axios';
4
- import type { AxiosClassType } from './AxiosClassType.ts';
2
+ import type { AxiosRequestConfig, AxiosResponse, RawAxiosRequestConfig } from 'axios';
5
3
  export type RawAxiosJsonRequestConfig<D = any> = RawAxiosRequestConfig<D> & {
6
4
  compressLength?: number;
7
5
  };
8
- export type AxiosType = typeof Axios;
9
- export declare class AxiosJson extends Axios implements AxiosClassType {
6
+ export declare class AxiosJson {
10
7
  static defaultLogger?: Logger;
8
+ private axios;
11
9
  constructor(config?: RawAxiosJsonRequestConfig);
12
10
  static finalPath(response: AxiosResponse): any;
13
11
  private static axiosConfig;
14
12
  private static buildHeaders;
13
+ delete<T = any, R = AxiosResponse<T>, D = any>(url: string, config?: AxiosRequestConfig<D>): Promise<R>;
14
+ get<T = any, R = AxiosResponse<T>, D = any>(url: string, config?: AxiosRequestConfig<D>): Promise<R>;
15
+ getUri(config?: AxiosRequestConfig): string;
16
+ head<T = any, R = AxiosResponse<T>, D = any>(url: string, config?: AxiosRequestConfig<D>): Promise<R>;
17
+ options<T = any, R = AxiosResponse<T>, D = any>(url: string, config?: AxiosRequestConfig<D>): Promise<R>;
18
+ patch<T = any, R = AxiosResponse<T>, D = any>(url: string, data?: D, config?: AxiosRequestConfig<D>): Promise<R>;
19
+ patchForm<T = any, R = AxiosResponse<T>, D = any>(url: string, data?: D, config?: AxiosRequestConfig<D>): Promise<R>;
20
+ post<T = any, R = AxiosResponse<T>, D = any>(url: string, data?: D, config?: AxiosRequestConfig<D>): Promise<R>;
21
+ postForm<T = any, R = AxiosResponse<T>, D = any>(url: string, data?: D, config?: AxiosRequestConfig<D>): Promise<R>;
22
+ put<T = any, R = AxiosResponse<T>, D = any>(url: string, data?: D, config?: AxiosRequestConfig<D>): Promise<R>;
23
+ putForm<T = any, R = AxiosResponse<T>, D = any>(url: string, data?: D, config?: AxiosRequestConfig<D>): Promise<R>;
24
+ request<T = any, R = AxiosResponse<T>, D = any>(config: AxiosRequestConfig<D>): Promise<R>;
15
25
  }
16
- export declare const createAxiosJson: (config?: RawAxiosJsonRequestConfig) => AxiosInstance;
17
26
  //# sourceMappingURL=AxiosJson.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"AxiosJson.d.ts","sourceRoot":"","sources":["../../src/AxiosJson.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AAC5C,OAAO,KAAK,EACV,aAAa,EAAE,aAAa,EAAE,qBAAqB,EACpD,MAAM,OAAO,CAAA;AACd,OAAO,EAAE,KAAK,EAAgB,MAAM,OAAO,CAAA;AAG3C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AAGzD,MAAM,MAAM,yBAAyB,CAAC,CAAC,GAAG,GAAG,IAAI,qBAAqB,CAAC,CAAC,CAAC,GAAG;IAAE,cAAc,CAAC,EAAE,MAAM,CAAA;CAAE,CAAA;AAEvG,MAAM,MAAM,SAAS,GAAG,OAAO,KAAK,CAAA;AAEpC,qBAAa,SAAU,SAAQ,KAAM,YAAW,cAAc;IAC5D,MAAM,CAAC,aAAa,CAAC,EAAE,MAAM,CAAA;gBAEjB,MAAM,CAAC,EAAE,yBAAyB;IAI9C,MAAM,CAAC,SAAS,CAAC,QAAQ,EAAE,aAAa;IAYxC,OAAO,CAAC,MAAM,CAAC,WAAW;IAwB1B,OAAO,CAAC,MAAM,CAAC,YAAY;CAO5B;AAED,eAAO,MAAM,eAAe,GAAI,SAAS,yBAAyB,KAA8B,aAAa,CAAA"}
1
+ {"version":3,"file":"AxiosJson.d.ts","sourceRoot":"","sources":["../../src/AxiosJson.ts"],"names":[],"mappings":"AAC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CAAC,GAAG,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC,EAAE,kBAAkB,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;IAI9G,OAAO,CAAC,CAAC,GAAG,GAAG,EAAE,CAAC,GAAG,aAAa,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC,EAAE,kBAAkB,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;IAIlH,OAAO,CAAC,CAAC,GAAG,GAAG,EAAE,CAAC,GAAG,aAAa,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,GAAG,EAAE,MAAM,EAAE,kBAAkB,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;CAG3F"}
@@ -1,11 +1,11 @@
1
1
  import type { Logger } from '@xylabs/logger';
2
- import type { AxiosResponse, RawAxiosRequestConfig } from 'axios';
2
+ import type { AxiosRequestConfig, AxiosResponse } from 'axios';
3
3
  import { Axios } from 'axios';
4
- import type { AxiosClassType } from './AxiosClassType.ts';
5
- export type RawAxiosJsonRequestUncompressedConfig<D = any> = RawAxiosRequestConfig<D>;
6
- export declare class AxiosJsonUncompressed extends Axios implements AxiosClassType {
4
+ export type AxiosJsonRequestUncompressedConfig<D = any> = AxiosRequestConfig<D>;
5
+ export declare class AxiosJsonUncompressed extends Axios {
7
6
  static defaultLogger?: Logger;
8
- constructor(config?: RawAxiosJsonRequestUncompressedConfig);
7
+ constructor(config?: AxiosJsonRequestUncompressedConfig);
8
+ static create(config?: AxiosJsonRequestUncompressedConfig): Axios;
9
9
  static finalPath(response: AxiosResponse): any;
10
10
  private static axiosConfig;
11
11
  private static buildHeaders;
@@ -1 +1 @@
1
- {"version":3,"file":"AxiosJsonUncompressed.d.ts","sourceRoot":"","sources":["../../src/AxiosJ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CAAC,MAAM,CAAC,WAAW;IAkB1B,OAAO,CAAC,MAAM,CAAC,YAAY;CAO5B"}
@@ -1,6 +1,5 @@
1
1
  import { AxiosJson } from './AxiosJson.ts';
2
2
  import { AxiosJsonUncompressed } from './AxiosJsonUncompressed.ts';
3
- export * from './AxiosClassType.ts';
4
3
  export * from './AxiosJson.ts';
5
4
  export * from './AxiosJsonUncompressed.ts';
6
5
  export { gzip } from 'pako';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC1C,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAA;AAElE,cAAc,qBAAqB,CAAA;AACnC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,4BAA4B,CAAA;AAC1C,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAA;AAE3B,eAAO,MAAM,KAAK,WAAkB,CAAA;AACpC,eAAO,MAAM,iBAAiB,uBAA8B,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC1C,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAA;AAElE,cAAc,gBAAgB,CAAA;AAC9B,cAAc,4BAA4B,CAAA;AAC1C,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAA;AAE3B,eAAO,MAAM,KAAK,WAAkB,CAAA;AACpC,eAAO,MAAM,iBAAiB,uBAA8B,CAAA"}
@@ -1,10 +1,11 @@
1
1
  // src/AxiosJson.ts
2
2
  import { Axios, AxiosHeaders } from "axios";
3
3
  import { gzip } from "pako";
4
- var AxiosJson = class _AxiosJson extends Axios {
4
+ var AxiosJson = class _AxiosJson {
5
5
  static defaultLogger;
6
+ axios = new Axios(_AxiosJson.axiosConfig());
6
7
  constructor(config) {
7
- super(_AxiosJson.axiosConfig(config));
8
+ this.axios = new Axios(_AxiosJson.axiosConfig(config));
8
9
  }
9
10
  static finalPath(response) {
10
11
  if (response.request.path) {
@@ -47,8 +48,43 @@ var AxiosJson = class _AxiosJson extends Axios {
47
48
  for (const [key, value] of Object.entries(headers ?? {})) axiosHeaders.set(key, value);
48
49
  return axiosHeaders;
49
50
  }
51
+ delete(url, config) {
52
+ return this.axios.delete(url, config);
53
+ }
54
+ get(url, config) {
55
+ return this.axios.get(url, config);
56
+ }
57
+ getUri(config) {
58
+ return this.axios.getUri(config);
59
+ }
60
+ head(url, config) {
61
+ return this.axios.head(url, config);
62
+ }
63
+ options(url, config) {
64
+ return this.axios.options(url, config);
65
+ }
66
+ patch(url, data, config) {
67
+ return this.axios.patch(url, data, config);
68
+ }
69
+ patchForm(url, data, config) {
70
+ return this.axios.patch(url, data, config);
71
+ }
72
+ post(url, data, config) {
73
+ return this.axios.post(url, data, config);
74
+ }
75
+ postForm(url, data, config) {
76
+ return this.axios.post(url, data, config);
77
+ }
78
+ put(url, data, config) {
79
+ return this.axios.put(url, data, config);
80
+ }
81
+ putForm(url, data, config) {
82
+ return this.axios.put(url, data, config);
83
+ }
84
+ request(config) {
85
+ return this.axios.request(config);
86
+ }
50
87
  };
51
- var createAxiosJson = (config) => new AxiosJson(config);
52
88
 
53
89
  // src/AxiosJsonUncompressed.ts
54
90
  import { Axios as Axios2, AxiosHeaders as AxiosHeaders2 } from "axios";
@@ -57,6 +93,9 @@ var AxiosJsonUncompressed = class _AxiosJsonUncompressed extends Axios2 {
57
93
  constructor(config) {
58
94
  super(_AxiosJsonUncompressed.axiosConfig(config));
59
95
  }
96
+ static create(config) {
97
+ return new this(config);
98
+ }
60
99
  static finalPath(response) {
61
100
  if (response.request.path) {
62
101
  return response.request.path.split("/").pop();
@@ -101,7 +140,6 @@ export {
101
140
  AxiosJsonUncompressed,
102
141
  axios,
103
142
  axiosUncompressed,
104
- createAxiosJson,
105
143
  gzip2 as gzip
106
144
  };
107
145
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/AxiosJson.ts","../../src/AxiosJsonUncompressed.ts","../../src/index.ts"],"sourcesContent":["import type { Logger } from '@xylabs/logger'\nimport type {\n AxiosInstance, AxiosResponse, RawAxiosRequestConfig,\n} from 'axios'\nimport { Axios, AxiosHeaders } from 'axios'\nimport { gzip } from 'pako'\n\nimport type { AxiosClassType } from './AxiosClassType.ts'\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type RawAxiosJsonRequestConfig<D = any> = RawAxiosRequestConfig<D> & { compressLength?: number }\n\nexport type AxiosType = typeof Axios\n\nexport class AxiosJson extends Axios implements AxiosClassType {\n static defaultLogger?: Logger\n\n constructor(config?: RawAxiosJsonRequestConfig) {\n super(AxiosJson.axiosConfig(config))\n }\n\n static finalPath(response: AxiosResponse) {\n if (response.request.path) {\n // nodejs\n return response.request.path.split('/').pop()\n } else if (response.request.responseURL) {\n // browser\n return response.request.responseURL.split('/').pop()\n } else {\n this.defaultLogger?.warn('Failed to get final path from response')\n }\n }\n\n private static axiosConfig({\n compressLength, headers, ...config\n }: RawAxiosJsonRequestConfig = {}): RawAxiosJsonRequestConfig {\n return {\n headers: this.buildHeaders(headers),\n transformRequest: (data, headers) => {\n const json = JSON.stringify(data)\n if (headers !== undefined && data && json.length > (compressLength ?? 1024)) {\n headers.set('Content-Encoding', 'gzip')\n return gzip(json).buffer\n }\n return json\n },\n transformResponse: (data) => {\n try {\n return JSON.parse(data)\n } catch {\n return null\n }\n },\n ...config,\n }\n }\n\n private static buildHeaders(headers: RawAxiosJsonRequestConfig['headers']) {\n const axiosHeaders = new AxiosHeaders()\n axiosHeaders.set('Accept', 'application/json, text/plain, *.*')\n axiosHeaders.set('Content-Type', 'application/json')\n for (const [key, value] of Object.entries(headers ?? {})) axiosHeaders.set(key, value)\n return axiosHeaders\n }\n}\n\nexport const createAxiosJson = (config?: RawAxiosJsonRequestConfig) => new AxiosJson(config) as AxiosInstance\n","import type { Logger } from '@xylabs/logger'\nimport type { AxiosResponse, RawAxiosRequestConfig } from 'axios'\nimport { Axios, AxiosHeaders } from 'axios'\n\nimport type { AxiosClassType } from './AxiosClassType.ts'\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type RawAxiosJsonRequestUncompressedConfig<D = any> = RawAxiosRequestConfig<D>\n\nexport class AxiosJsonUncompressed extends Axios implements AxiosClassType {\n static defaultLogger?: Logger\n\n constructor(config?: RawAxiosJsonRequestUncompressedConfig) {\n super(AxiosJsonUncompressed.axiosConfig(config))\n }\n\n static finalPath(response: AxiosResponse) {\n if (response.request.path) {\n // nodejs\n return response.request.path.split('/').pop()\n } else if (response.request.responseURL) {\n // browser\n return response.request.responseURL.split('/').pop()\n } else {\n this.defaultLogger?.warn('Failed to get final path from response')\n }\n }\n\n private static axiosConfig({ headers, ...config }: RawAxiosJsonRequestUncompressedConfig = {}): RawAxiosJsonRequestUncompressedConfig {\n return {\n headers: this.buildHeaders(headers),\n transformRequest: (data) => {\n const json = JSON.stringify(data)\n return JSON.stringify(json)\n },\n transformResponse: (data) => {\n try {\n return JSON.parse(data)\n } catch {\n return null\n }\n },\n ...config,\n }\n }\n\n private static buildHeaders(headers: RawAxiosJsonRequestUncompressedConfig['headers']) {\n const axiosHeaders = new AxiosHeaders()\n axiosHeaders.set('Accept', 'application/json, text/plain, *.*')\n axiosHeaders.set('Content-Type', 'application/json')\n for (const [key, value] of Object.entries(headers ?? {})) axiosHeaders.set(key, value)\n return axiosHeaders\n }\n}\n","import { AxiosJson } from './AxiosJson.ts'\nimport { AxiosJsonUncompressed } from './AxiosJsonUncompressed.ts'\n\nexport * from './AxiosClassType.ts'\nexport * from './AxiosJson.ts'\nexport * from './AxiosJsonUncompressed.ts'\nexport { gzip } from 'pako'\n\nexport const axios = new AxiosJson()\nexport const axiosUncompressed = new AxiosJsonUncompressed()\n"],"mappings":";AAIA,SAAS,OAAO,oBAAoB;AACp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QAAQ,IAAI,UAAU;AAC5B,IAAM,oBAAoB,IAAI,sBAAsB;","names":["headers","Axios","AxiosHeaders","gzip"]}
1
+ {"version":3,"sources":["../../src/AxiosJson.ts","../../src/AxiosJsonUncompressed.ts","../../src/index.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport type { Logger } from '@xylabs/logger'\nimport type {\n AxiosRequestConfig, AxiosResponse, RawAxiosRequestConfig,\n} from 'axios'\nimport { Axios, AxiosHeaders } from 'axios'\nimport { gzip } from 'pako'\n\nexport type RawAxiosJsonRequestConfig<D = any> = RawAxiosRequestConfig<D> & { compressLength?: number }\n\nexport class AxiosJson {\n static defaultLogger?: Logger\n\n private axios: Axios = new Axios(AxiosJson.axiosConfig())\n\n constructor(config?: RawAxiosJsonRequestConfig) {\n this.axios = new Axios(AxiosJson.axiosConfig(config))\n }\n\n static finalPath(response: AxiosResponse) {\n if (response.request.path) {\n // nodejs\n return response.request.path.split('/').pop()\n } else if (response.request.responseURL) {\n // browser\n return response.request.responseURL.split('/').pop()\n } else {\n this.defaultLogger?.warn('Failed to get final path from response')\n }\n }\n\n private static axiosConfig({\n compressLength, headers, ...config\n }: RawAxiosJsonRequestConfig = {}): RawAxiosJsonRequestConfig {\n return {\n headers: this.buildHeaders(headers),\n transformRequest: (data, headers) => {\n const json = JSON.stringify(data)\n if (headers !== undefined && data && json.length > (compressLength ?? 1024)) {\n headers.set('Content-Encoding', 'gzip')\n return gzip(json).buffer\n }\n return json\n },\n transformResponse: (data) => {\n try {\n return JSON.parse(data)\n } catch {\n return null\n }\n },\n ...config,\n }\n }\n\n private static buildHeaders(headers: RawAxiosJsonRequestConfig['headers']) {\n const axiosHeaders = new AxiosHeaders()\n axiosHeaders.set('Accept', 'application/json, text/plain, *.*')\n axiosHeaders.set('Content-Type', 'application/json')\n for (const [key, value] of Object.entries(headers ?? {})) axiosHeaders.set(key, value)\n return axiosHeaders\n }\n\n delete<T = any, R = AxiosResponse<T>, D = any>(url: string, config?: AxiosRequestConfig<D>): Promise<R> {\n return this.axios.delete<T, R, D>(url, config)\n }\n\n get<T = any, R = AxiosResponse<T>, D = any>(url: string, config?: AxiosRequestConfig<D>): Promise<R> {\n return this.axios.get<T, R, D>(url, config)\n }\n\n getUri(config?: AxiosRequestConfig): string {\n return this.axios.getUri(config)\n }\n\n head<T = any, R = AxiosResponse<T>, D = any>(url: string, config?: AxiosRequestConfig<D>): Promise<R> {\n return this.axios.head<T, R, D>(url, config)\n }\n\n options<T = any, R = AxiosResponse<T>, D = any>(url: string, config?: AxiosRequestConfig<D>): Promise<R> {\n return this.axios.options<T, R, D>(url, config)\n }\n\n patch<T = any, R = AxiosResponse<T>, D = any>(url: string, data?: D, config?: AxiosRequestConfig<D>): Promise<R> {\n return this.axios.patch<T, R, D>(url, data, config)\n }\n\n patchForm<T = any, R = AxiosResponse<T>, D = any>(url: string, data?: D, config?: AxiosRequestConfig<D>): Promise<R> {\n return this.axios.patch<T, R, D>(url, data, config)\n }\n\n post<T = any, R = AxiosResponse<T>, D = any>(url: string, data?: D, config?: AxiosRequestConfig<D>): Promise<R> {\n return this.axios.post<T, R, D>(url, data, config)\n }\n\n postForm<T = any, R = AxiosResponse<T>, D = any>(url: string, data?: D, config?: AxiosRequestConfig<D>): Promise<R> {\n return this.axios.post<T, R, D>(url, data, config)\n }\n\n put<T = any, R = AxiosResponse<T>, D = any>(url: string, data?: D, config?: AxiosRequestConfig<D>): Promise<R> {\n return this.axios.put<T, R, D>(url, data, config)\n }\n\n putForm<T = any, R = AxiosResponse<T>, D = any>(url: string, data?: D, config?: AxiosRequestConfig<D>): Promise<R> {\n return this.axios.put<T, R, D>(url, data, config)\n }\n\n request<T = any, R = AxiosResponse<T>, D = any>(config: AxiosRequestConfig<D>): Promise<R> {\n return this.axios.request<T, R, D>(config)\n }\n}\n","import type { Logger } from '@xylabs/logger'\nimport type { AxiosRequestConfig, AxiosResponse } from 'axios'\nimport { Axios, AxiosHeaders } from 'axios'\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type AxiosJsonRequestUncompressedConfig<D = any> = AxiosRequestConfig<D>\n\nexport class AxiosJsonUncompressed extends Axios {\n static defaultLogger?: Logger\n\n constructor(config?: AxiosJsonRequestUncompressedConfig) {\n super(AxiosJsonUncompressed.axiosConfig(config))\n }\n\n static create(config?: AxiosJsonRequestUncompressedConfig) {\n return new this(config) as Axios\n }\n\n static finalPath(response: AxiosResponse) {\n if (response.request.path) {\n // nodejs\n return response.request.path.split('/').pop()\n } else if (response.request.responseURL) {\n // browser\n return response.request.responseURL.split('/').pop()\n } else {\n this.defaultLogger?.warn('Failed to get final path from response')\n }\n }\n\n private static axiosConfig({ headers, ...config }: AxiosJsonRequestUncompressedConfig = {}): AxiosJsonRequestUncompressedConfig {\n return {\n headers: this.buildHeaders(headers),\n transformRequest: (data) => {\n const json = JSON.stringify(data)\n return JSON.stringify(json)\n },\n transformResponse: (data) => {\n try {\n return JSON.parse(data)\n } catch {\n return null\n }\n },\n ...config,\n }\n }\n\n private static buildHeaders(headers: AxiosJsonRequestUncompressedConfig['headers']) {\n const axiosHeaders = new AxiosHeaders()\n axiosHeaders.set('Accept', 'application/json, text/plain, *.*')\n axiosHeaders.set('Content-Type', 'application/json')\n for (const [key, value] of Object.entries(headers ?? {})) axiosHeaders.set(key, value)\n return axiosHeaders\n }\n}\n","import { AxiosJson } from './AxiosJson.ts'\nimport { AxiosJsonUncompressed } from './AxiosJsonUncompressed.ts'\n\nexport * from './AxiosJson.ts'\nexport * from './AxiosJsonUncompressed.ts'\nexport { gzip } from 'pako'\n\nexport const axios = new AxiosJson()\nexport const axiosUncompressed = new AxiosJsonUncompressed()\n"],"mappings":";AAKA,SAAS,OAAO,oBAAoB;AACpC,SAAS,YAAY;AAId,IAAM,YAAN,MAAM,WAAU;AAAA,EACrB,OAAO;AAAA,EAEC,QAAe,IAAI,MAAM,WAAU,YAAY,CAAC;AAAA,EAExD,YAAY,QAAoC;AAC9C,SAAK,QAAQ,IAA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,WAAO,IAAI,KAAK,MAAM;AAAA,EACxB;AAAA,EAEA,OAAO,UAAU,UAAyB;AACxC,QAAI,SAAS,QAAQ,MAAM;AAEzB,aAAO,SAAS,QAAQ,KAAK,MAAM,GAAG,EAAE,IAAI;AAAA,IAC9C,WAAW,SAAS,QAAQ,aAAa;AAEvC,aAAO,SAAS,QAAQ,YAAY,MAAM,GAAG,EAAE,IAAI;AAAA,IACrD,OAAO;AACL,WAAK,eAAe,KAAK,wCAAwC;AAAA,IACnE;AAAA,EACF;AAAA,EAEA,OAAe,YAAY,EAAE,SAAS,GAAG,OAAO,IAAwC,CAAC,GAAuC;AAC9H,WAAO;AAAA,MACL,SAAS,KAAK,aAAa,OAAO;AAAA,MAClC,kBAAkB,CAAC,SAAS;AAC1B,cAAM,OAAO,KAAK,UAAU,IAAI;AAChC,eAAO,KAAK,UAAU,IAAI;AAAA,MAC5B;AAAA,MACA,mBAAmB,CAAC,SAAS;AAC3B,YAAI;AACF,iBAAO,KAAK,MAAM,IAAI;AAAA,QACxB,QAAQ;AACN,iBAAO;AAAA,QACT;AAAA,MACF;AAAA,MACA,GAAG;AAAA,IACL;AAAA,EACF;AAAA,EAEA,OAAe,aAAa,SAAwD;AAClF,UAAM,eAAe,IAAIC,cAAa;AACtC,iBAAa,IAAI,UAAU,mCAAmC;AAC9D,iBAAa,IAAI,gBAAgB,kBAAkB;AACnD,eAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,WAAW,CAAC,CAAC,EAAG,cAAa,IAAI,KAAK,KAAK;AACrF,WAAO;AAAA,EACT;AACF;;;AClDA,SAAS,QAAAC,aAAY;AAEd,IAAM,QAAQ,IAAI,UAAU;AAC5B,IAAM,oBAAoB,IAAI,sBAAsB;","names":["headers","Axios","AxiosHeaders","gzip"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xylabs/axios",
3
- "version": "5.0.28",
3
+ "version": "5.0.30",
4
4
  "description": "Base functionality used throughout XY Labs TypeScript/JavaScript libraries",
5
5
  "keywords": [
6
6
  "axios",
@@ -42,7 +42,7 @@
42
42
  "src"
43
43
  ],
44
44
  "dependencies": {
45
- "@xylabs/logger": "~5.0.28",
45
+ "@xylabs/logger": "~5.0.30",
46
46
  "pako": "~2.1.0"
47
47
  },
48
48
  "devDependencies": {
package/src/AxiosJson.ts CHANGED
@@ -1,22 +1,20 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
1
2
  import type { Logger } from '@xylabs/logger'
2
3
  import type {
3
- AxiosInstance, AxiosResponse, RawAxiosRequestConfig,
4
+ AxiosRequestConfig, AxiosResponse, RawAxiosRequestConfig,
4
5
  } from 'axios'
5
6
  import { Axios, AxiosHeaders } from 'axios'
6
7
  import { gzip } from 'pako'
7
8
 
8
- import type { AxiosClassType } from './AxiosClassType.ts'
9
-
10
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
11
9
  export type RawAxiosJsonRequestConfig<D = any> = RawAxiosRequestConfig<D> & { compressLength?: number }
12
10
 
13
- export type AxiosType = typeof Axios
14
-
15
- export class AxiosJson extends Axios implements AxiosClassType {
11
+ export class AxiosJson {
16
12
  static defaultLogger?: Logger
17
13
 
14
+ private axios: Axios = new Axios(AxiosJson.axiosConfig())
15
+
18
16
  constructor(config?: RawAxiosJsonRequestConfig) {
19
- super(AxiosJson.axiosConfig(config))
17
+ this.axios = new Axios(AxiosJson.axiosConfig(config))
20
18
  }
21
19
 
22
20
  static finalPath(response: AxiosResponse) {
@@ -62,6 +60,52 @@ export class AxiosJson extends Axios implements AxiosClassType {
62
60
  for (const [key, value] of Object.entries(headers ?? {})) axiosHeaders.set(key, value)
63
61
  return axiosHeaders
64
62
  }
65
- }
66
63
 
67
- export const createAxiosJson = (config?: RawAxiosJsonRequestConfig) => new AxiosJson(config) as AxiosInstance
64
+ delete<T = any, R = AxiosResponse<T>, D = any>(url: string, config?: AxiosRequestConfig<D>): Promise<R> {
65
+ return this.axios.delete<T, R, D>(url, config)
66
+ }
67
+
68
+ get<T = any, R = AxiosResponse<T>, D = any>(url: string, config?: AxiosRequestConfig<D>): Promise<R> {
69
+ return this.axios.get<T, R, D>(url, config)
70
+ }
71
+
72
+ getUri(config?: AxiosRequestConfig): string {
73
+ return this.axios.getUri(config)
74
+ }
75
+
76
+ head<T = any, R = AxiosResponse<T>, D = any>(url: string, config?: AxiosRequestConfig<D>): Promise<R> {
77
+ return this.axios.head<T, R, D>(url, config)
78
+ }
79
+
80
+ options<T = any, R = AxiosResponse<T>, D = any>(url: string, config?: AxiosRequestConfig<D>): Promise<R> {
81
+ return this.axios.options<T, R, D>(url, config)
82
+ }
83
+
84
+ patch<T = any, R = AxiosResponse<T>, D = any>(url: string, data?: D, config?: AxiosRequestConfig<D>): Promise<R> {
85
+ return this.axios.patch<T, R, D>(url, data, config)
86
+ }
87
+
88
+ patchForm<T = any, R = AxiosResponse<T>, D = any>(url: string, data?: D, config?: AxiosRequestConfig<D>): Promise<R> {
89
+ return this.axios.patch<T, R, D>(url, data, config)
90
+ }
91
+
92
+ post<T = any, R = AxiosResponse<T>, D = any>(url: string, data?: D, config?: AxiosRequestConfig<D>): Promise<R> {
93
+ return this.axios.post<T, R, D>(url, data, config)
94
+ }
95
+
96
+ postForm<T = any, R = AxiosResponse<T>, D = any>(url: string, data?: D, config?: AxiosRequestConfig<D>): Promise<R> {
97
+ return this.axios.post<T, R, D>(url, data, config)
98
+ }
99
+
100
+ put<T = any, R = AxiosResponse<T>, D = any>(url: string, data?: D, config?: AxiosRequestConfig<D>): Promise<R> {
101
+ return this.axios.put<T, R, D>(url, data, config)
102
+ }
103
+
104
+ putForm<T = any, R = AxiosResponse<T>, D = any>(url: string, data?: D, config?: AxiosRequestConfig<D>): Promise<R> {
105
+ return this.axios.put<T, R, D>(url, data, config)
106
+ }
107
+
108
+ request<T = any, R = AxiosResponse<T>, D = any>(config: AxiosRequestConfig<D>): Promise<R> {
109
+ return this.axios.request<T, R, D>(config)
110
+ }
111
+ }
@@ -1,19 +1,21 @@
1
1
  import type { Logger } from '@xylabs/logger'
2
- import type { AxiosResponse, RawAxiosRequestConfig } from 'axios'
2
+ import type { AxiosRequestConfig, AxiosResponse } from 'axios'
3
3
  import { Axios, AxiosHeaders } from 'axios'
4
4
 
5
- import type { AxiosClassType } from './AxiosClassType.ts'
6
-
7
5
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
8
- export type RawAxiosJsonRequestUncompressedConfig<D = any> = RawAxiosRequestConfig<D>
6
+ export type AxiosJsonRequestUncompressedConfig<D = any> = AxiosRequestConfig<D>
9
7
 
10
- export class AxiosJsonUncompressed extends Axios implements AxiosClassType {
8
+ export class AxiosJsonUncompressed extends Axios {
11
9
  static defaultLogger?: Logger
12
10
 
13
- constructor(config?: RawAxiosJsonRequestUncompressedConfig) {
11
+ constructor(config?: AxiosJsonRequestUncompressedConfig) {
14
12
  super(AxiosJsonUncompressed.axiosConfig(config))
15
13
  }
16
14
 
15
+ static create(config?: AxiosJsonRequestUncompressedConfig) {
16
+ return new this(config) as Axios
17
+ }
18
+
17
19
  static finalPath(response: AxiosResponse) {
18
20
  if (response.request.path) {
19
21
  // nodejs
@@ -26,7 +28,7 @@ export class AxiosJsonUncompressed extends Axios implements AxiosClassType {
26
28
  }
27
29
  }
28
30
 
29
- private static axiosConfig({ headers, ...config }: RawAxiosJsonRequestUncompressedConfig = {}): RawAxiosJsonRequestUncompressedConfig {
31
+ private static axiosConfig({ headers, ...config }: AxiosJsonRequestUncompressedConfig = {}): AxiosJsonRequestUncompressedConfig {
30
32
  return {
31
33
  headers: this.buildHeaders(headers),
32
34
  transformRequest: (data) => {
@@ -44,7 +46,7 @@ export class AxiosJsonUncompressed extends Axios implements AxiosClassType {
44
46
  }
45
47
  }
46
48
 
47
- private static buildHeaders(headers: RawAxiosJsonRequestUncompressedConfig['headers']) {
49
+ private static buildHeaders(headers: AxiosJsonRequestUncompressedConfig['headers']) {
48
50
  const axiosHeaders = new AxiosHeaders()
49
51
  axiosHeaders.set('Accept', 'application/json, text/plain, *.*')
50
52
  axiosHeaders.set('Content-Type', 'application/json')
package/src/index.ts CHANGED
@@ -1,7 +1,6 @@
1
1
  import { AxiosJson } from './AxiosJson.ts'
2
2
  import { AxiosJsonUncompressed } from './AxiosJsonUncompressed.ts'
3
3
 
4
- export * from './AxiosClassType.ts'
5
4
  export * from './AxiosJson.ts'
6
5
  export * from './AxiosJsonUncompressed.ts'
7
6
  export { gzip } from 'pako'
@@ -1,16 +0,0 @@
1
- import type { AxiosRequestConfig, AxiosResponse } from 'axios';
2
- export interface AxiosClassType {
3
- delete<T = any, R = AxiosResponse<T>, D = any>(url: string, config?: AxiosRequestConfig<D>): Promise<R>;
4
- get<T = any, R = AxiosResponse<T>, D = any>(url: string, config?: AxiosRequestConfig<D>): Promise<R>;
5
- getUri(config?: AxiosRequestConfig): string;
6
- head<T = any, R = AxiosResponse<T>, D = any>(url: string, config?: AxiosRequestConfig<D>): Promise<R>;
7
- options<T = any, R = AxiosResponse<T>, D = any>(url: string, config?: AxiosRequestConfig<D>): Promise<R>;
8
- patch<T = any, R = AxiosResponse<T>, D = any>(url: string, data?: D, config?: AxiosRequestConfig<D>): Promise<R>;
9
- patchForm<T = any, R = AxiosResponse<T>, D = any>(url: string, data?: D, config?: AxiosRequestConfig<D>): Promise<R>;
10
- post<T = any, R = AxiosResponse<T>, D = any>(url: string, data?: D, config?: AxiosRequestConfig<D>): Promise<R>;
11
- postForm<T = any, R = AxiosResponse<T>, D = any>(url: string, data?: D, config?: AxiosRequestConfig<D>): Promise<R>;
12
- put<T = any, R = AxiosResponse<T>, D = any>(url: string, data?: D, config?: AxiosRequestConfig<D>): Promise<R>;
13
- putForm<T = any, R = AxiosResponse<T>, D = any>(url: string, data?: D, config?: AxiosRequestConfig<D>): Promise<R>;
14
- request<T = any, R = AxiosResponse<T>, D = any>(config: AxiosRequestConfig<D>): Promise<R>;
15
- }
16
- //# sourceMappingURL=AxiosClassType.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"A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,EAAE,kBAAkB,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAA;IAClH,OAAO,CAAC,CAAC,GAAG,GAAG,EAAE,CAAC,GAAG,aAAa,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,GAAG,EAAE,MAAM,EAAE,kBAAkB,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAA;CAC3F"}
@@ -1,17 +0,0 @@
1
- /* eslint-disable @typescript-eslint/no-explicit-any */
2
- import type { AxiosRequestConfig, AxiosResponse } from 'axios'
3
-
4
- export interface AxiosClassType {
5
- delete<T = any, R = AxiosResponse<T>, D = any>(url: string, config?: AxiosRequestConfig<D>): Promise<R>
6
- get<T = any, R = AxiosResponse<T>, D = any>(url: string, config?: AxiosRequestConfig<D>): Promise<R>
7
- getUri(config?: AxiosRequestConfig): string
8
- head<T = any, R = AxiosResponse<T>, D = any>(url: string, config?: AxiosRequestConfig<D>): Promise<R>
9
- options<T = any, R = AxiosResponse<T>, D = any>(url: string, config?: AxiosRequestConfig<D>): Promise<R>
10
- patch<T = any, R = AxiosResponse<T>, D = any>(url: string, data?: D, config?: AxiosRequestConfig<D>): Promise<R>
11
- patchForm<T = any, R = AxiosResponse<T>, D = any>(url: string, data?: D, config?: AxiosRequestConfig<D>): Promise<R>
12
- post<T = any, R = AxiosResponse<T>, D = any>(url: string, data?: D, config?: AxiosRequestConfig<D>): Promise<R>
13
- postForm<T = any, R = AxiosResponse<T>, D = any>(url: string, data?: D, config?: AxiosRequestConfig<D>): Promise<R>
14
- put<T = any, R = AxiosResponse<T>, D = any>(url: string, data?: D, config?: AxiosRequestConfig<D>): Promise<R>
15
- putForm<T = any, R = AxiosResponse<T>, D = any>(url: string, data?: D, config?: AxiosRequestConfig<D>): Promise<R>
16
- request<T = any, R = AxiosResponse<T>, D = any>(config: AxiosRequestConfig<D>): Promise<R>
17
- }