@almighty-shogun/utils 1.4.0 → 1.4.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.
package/dist/axiosHttpLog.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { InternalAxiosRequestConfig, AxiosInstance, AxiosRequestConfig } from 'axios';
|
|
2
|
-
|
|
3
|
-
name:
|
|
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:
|
|
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,
|
|
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
package/src/axiosHttpLog.ts
CHANGED
|
@@ -7,5 +7,5 @@ type AxiosData = {
|
|
|
7
7
|
export default function (name: string, data: AxiosData, isRejected: boolean): void {
|
|
8
8
|
const logMethod = isRejected ? console.error : console.info;
|
|
9
9
|
|
|
10
|
-
logMethod(`${name}: [HTTP ${data.status}] ${data.url}${data.message}`);
|
|
10
|
+
logMethod(`${name}: [HTTP ${data.status}] ${data.url} ${data.message}`);
|
|
11
11
|
}
|
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
import axios from 'axios'
|
|
2
2
|
import type { InternalAxiosRequestConfig, AxiosInstance, AxiosRequestConfig } from 'axios'
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
name:
|
|
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:
|
|
19
|
-
const instancesMap
|
|
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;
|