@almighty-shogun/utils 1.4.0 → 1.4.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.
@@ -1,6 +1,6 @@
1
1
  import type { InternalAxiosRequestConfig, AxiosInstance, AxiosRequestConfig } from 'axios';
2
- export interface RegisterInstance {
3
- name: string;
2
+ type RegisterInstance<Name extends string = string> = {
3
+ name: Name;
4
4
  url: string;
5
5
  responseInterceptors?: [
6
6
  (response: any) => any,
@@ -11,6 +11,9 @@ export interface RegisterInstance {
11
11
  (error: any) => any
12
12
  ];
13
13
  config?: AxiosRequestConfig;
14
- }
15
- export default function (instances: RegisterInstance[]): Record<string, AxiosInstance>;
14
+ };
15
+ export default function <const T extends readonly RegisterInstance[]>(instances: T): {
16
+ [K in T[number]['name']]: AxiosInstance;
17
+ };
18
+ export {};
16
19
  //# sourceMappingURL=axiosInstancesRegister.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"axiosInstancesRegister.d.ts","sourceRoot":"","sources":["../src/axiosInstancesRegister.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,0BAA0B,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,OAAO,CAAA;AAE1F,MAAM,WAAW,gBAAgB;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,oBAAoB,CAAC,EAAE;QACnB,CAAC,QAAQ,EAAE,GAAG,KAAK,GAAG;QACtB,CAAC,KAAK,EAAE,GAAG,KAAK,GAAG;KACtB,CAAC;IACF,mBAAmB,CAAC,EAAE;QAClB,CAAC,MAAM,EAAE,0BAA0B,KAAK,0BAA0B;QAClE,CAAC,KAAK,EAAE,GAAG,KAAK,GAAG;KACtB,CAAA;IACD,MAAM,CAAC,EAAE,kBAAkB,CAAC;CAC/B;AAED,MAAM,CAAC,OAAO,WAAW,SAAS,EAAE,gBAAgB,EAAE,GAAG,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAuBrF"}
1
+ {"version":3,"file":"axiosInstancesRegister.d.ts","sourceRoot":"","sources":["../src/axiosInstancesRegister.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,0BAA0B,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,OAAO,CAAA;AAE1F,KAAK,gBAAgB,CAAC,IAAI,SAAS,MAAM,GAAG,MAAM,IAAI;IAClD,IAAI,EAAE,IAAI,CAAC;IACX,GAAG,EAAE,MAAM,CAAC;IACZ,oBAAoB,CAAC,EAAE;QACnB,CAAC,QAAQ,EAAE,GAAG,KAAK,GAAG;QACtB,CAAC,KAAK,EAAE,GAAG,KAAK,GAAG;KACtB,CAAC;IACF,mBAAmB,CAAC,EAAE;QAClB,CAAC,MAAM,EAAE,0BAA0B,KAAK,0BAA0B;QAClE,CAAC,KAAK,EAAE,GAAG,KAAK,GAAG;KACtB,CAAC;IACF,MAAM,CAAC,EAAE,kBAAkB,CAAC;CAC/B,CAAA;AAED,MAAM,CAAC,OAAO,WAAU,KAAK,CAAC,CAAC,SAAS,SAAS,gBAAgB,EAAE,EAAE,SAAS,EAAE,CAAC,GAAG;KAAG,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,GAAG,aAAa;CAAE,CAuB9H"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@almighty-shogun/utils",
3
3
  "description": "A small package that contains common utilities used in all my projects.",
4
- "version": "1.4.0",
4
+ "version": "1.4.1",
5
5
  "type": "module",
6
6
  "license": "MIT",
7
7
  "scripts": {
@@ -1,22 +1,22 @@
1
1
  import axios from 'axios'
2
2
  import type { InternalAxiosRequestConfig, AxiosInstance, AxiosRequestConfig } from 'axios'
3
3
 
4
- export interface RegisterInstance {
5
- name: string;
4
+ type RegisterInstance<Name extends string = string> = {
5
+ name: Name;
6
6
  url: string;
7
7
  responseInterceptors?: [
8
8
  (response: any) => any,
9
9
  (error: any) => any
10
- ],
10
+ ];
11
11
  requestInterceptors?: [
12
12
  (config: InternalAxiosRequestConfig) => InternalAxiosRequestConfig,
13
13
  (error: any) => any
14
- ]
14
+ ];
15
15
  config?: AxiosRequestConfig;
16
16
  }
17
17
 
18
- export default function (instances: RegisterInstance[]): Record<string, AxiosInstance> {
19
- const instancesMap: Record<string, AxiosInstance> = {};
18
+ export default function<const T extends readonly RegisterInstance[]>(instances: T): { [K in T[number]['name']]: AxiosInstance } {
19
+ const instancesMap = {} as { [K in T[number]['name']]: AxiosInstance };
20
20
 
21
21
  instances.forEach(instance => {
22
22
  const axiosInstance = axios.create({
@@ -34,7 +34,7 @@ export default function (instances: RegisterInstance[]): Record<string, AxiosIns
34
34
  axiosInstance.interceptors.request.use(onSuccess, onError);
35
35
  }
36
36
 
37
- instancesMap[instance.name] = axiosInstance;
37
+ instancesMap[instance.name as T[number]['name']] = axiosInstance;
38
38
  });
39
39
 
40
40
  return instancesMap;