@chzky/reqwest 0.0.1 → 0.1.0
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/README.md +314 -0
- package/esm/_dnt.polyfills.d.ts +11 -0
- package/esm/_dnt.polyfills.d.ts.map +1 -10
- package/esm/_dnt.polyfills.js +24 -66
- package/esm/_dnt.shims.d.ts +1 -13
- package/esm/_dnt.shims.d.ts.map +1 -1
- package/esm/_dnt.shims.js +57 -1
- package/esm/lib/mod.d.ts +1 -1
- package/esm/lib/mod.d.ts.map +1 -1
- package/esm/lib/mod.js +1 -1
- package/esm/lib/reqwest/class.d.ts +116 -78
- package/esm/lib/reqwest/class.d.ts.map +1 -1
- package/esm/lib/reqwest/class.js +175 -1
- package/esm/lib/reqwest/core.d.ts +5 -0
- package/esm/lib/reqwest/core.d.ts.map +1 -1
- package/esm/lib/reqwest/core.js +154 -244
- package/esm/lib/reqwest/factor.d.ts +2 -2
- package/esm/lib/reqwest/factor.d.ts.map +1 -1
- package/esm/lib/reqwest/factor.js +32 -1
- package/esm/lib/reqwest/interface.d.ts +166 -42
- package/esm/lib/reqwest/interface.d.ts.map +1 -1
- package/esm/lib/reqwest/interface.js +1 -1
- package/esm/lib/reqwest/mod.d.ts +1 -1
- package/esm/lib/reqwest/mod.d.ts.map +1 -1
- package/esm/lib/reqwest/mod.js +2 -2
- package/esm/lib/{helper → utils}/mod.d.ts +1 -0
- package/esm/lib/utils/mod.d.ts.map +1 -0
- package/esm/lib/{helper → utils}/mod.js +1 -0
- package/esm/lib/utils/other/mod.d.ts +2 -0
- package/esm/lib/utils/other/mod.d.ts.map +1 -0
- package/esm/lib/utils/other/mod.js +1 -0
- package/esm/lib/utils/other/sseParse.d.ts +34 -0
- package/esm/lib/utils/other/sseParse.d.ts.map +1 -0
- package/esm/lib/utils/other/sseParse.js +42 -0
- package/{script/lib/helper → esm/lib/utils}/request/RESTful.d.ts +43 -11
- package/esm/lib/utils/request/RESTful.d.ts.map +1 -0
- package/esm/lib/utils/request/RESTful.js +129 -0
- package/esm/lib/utils/request/baseConf.d.ts +22 -0
- package/esm/lib/utils/request/baseConf.d.ts.map +1 -0
- package/esm/lib/utils/request/baseConf.js +37 -0
- package/esm/lib/utils/request/factors.d.ts +30 -0
- package/esm/lib/utils/request/factors.d.ts.map +1 -0
- package/esm/lib/utils/request/factors.js +39 -0
- package/esm/lib/{helper → utils}/request/input.d.ts +4 -3
- package/esm/lib/utils/request/input.d.ts.map +1 -0
- package/esm/lib/utils/request/input.js +24 -0
- package/esm/lib/utils/request/mod.d.ts +7 -0
- package/esm/lib/utils/request/mod.d.ts.map +1 -0
- package/esm/lib/utils/request/mod.js +6 -0
- package/esm/lib/utils/request/process.d.ts +16 -0
- package/esm/lib/utils/request/process.d.ts.map +1 -0
- package/esm/lib/utils/request/process.js +37 -0
- package/esm/lib/utils/request/wait.d.ts +10 -0
- package/esm/lib/utils/request/wait.d.ts.map +1 -0
- package/esm/lib/utils/request/wait.js +14 -0
- package/esm/lib/utils/response/blobToUrl.d.ts +10 -0
- package/esm/lib/utils/response/blobToUrl.d.ts.map +1 -0
- package/esm/lib/utils/response/blobToUrl.js +21 -0
- package/esm/lib/utils/response/mod.d.ts +5 -0
- package/esm/lib/utils/response/mod.d.ts.map +1 -0
- package/esm/lib/utils/response/mod.js +4 -0
- package/esm/lib/utils/response/openLink.d.ts +7 -0
- package/esm/lib/utils/response/openLink.d.ts.map +1 -0
- package/esm/lib/utils/response/openLink.js +20 -0
- package/esm/lib/utils/response/output.d.ts +16 -0
- package/esm/lib/utils/response/output.d.ts.map +1 -0
- package/esm/lib/utils/response/output.js +24 -0
- package/esm/lib/utils/response/pick.d.ts +23 -0
- package/esm/lib/utils/response/pick.d.ts.map +1 -0
- package/esm/lib/utils/response/pick.js +25 -0
- package/esm/lib/utils/use/mod.d.ts.map +1 -0
- package/esm/lib/utils/use/mod.js +2 -0
- package/esm/lib/utils/use/useCancel.d.ts +33 -0
- package/esm/lib/utils/use/useCancel.d.ts.map +1 -0
- package/esm/lib/utils/use/useCancel.js +41 -0
- package/esm/lib/utils/use/useLoading.d.ts +34 -0
- package/esm/lib/utils/use/useLoading.d.ts.map +1 -0
- package/esm/lib/utils/use/useLoading.js +57 -0
- package/package.json +4 -11
- package/script/_dnt.polyfills.d.ts +11 -0
- package/script/_dnt.polyfills.d.ts.map +1 -1
- package/script/_dnt.polyfills.js +15 -0
- package/script/_dnt.shims.d.ts +1 -13
- package/script/_dnt.shims.d.ts.map +1 -1
- package/script/_dnt.shims.js +2 -21
- package/script/lib/mod.d.ts +1 -1
- package/script/lib/mod.d.ts.map +1 -1
- package/script/lib/mod.js +1 -1
- package/script/lib/reqwest/class.d.ts +116 -78
- package/script/lib/reqwest/class.d.ts.map +1 -1
- package/script/lib/reqwest/class.js +135 -25
- package/script/lib/reqwest/core.d.ts +5 -0
- package/script/lib/reqwest/core.d.ts.map +1 -1
- package/script/lib/reqwest/core.js +119 -23
- package/script/lib/reqwest/factor.d.ts +2 -2
- package/script/lib/reqwest/factor.d.ts.map +1 -1
- package/script/lib/reqwest/factor.js +2 -2
- package/script/lib/reqwest/interface.d.ts +160 -11
- package/script/lib/reqwest/interface.d.ts.map +1 -1
- package/script/lib/reqwest/mod.d.ts +1 -1
- package/script/lib/reqwest/mod.d.ts.map +1 -1
- package/script/lib/{helper → utils}/mod.d.ts +1 -0
- package/script/lib/utils/mod.d.ts.map +1 -0
- package/script/lib/{helper → utils}/mod.js +1 -0
- package/script/lib/utils/other/mod.d.ts +2 -0
- package/script/lib/utils/other/mod.d.ts.map +1 -0
- package/script/lib/{helper/response → utils/other}/mod.js +1 -2
- package/script/lib/utils/other/sseParse.d.ts +34 -0
- package/script/lib/utils/other/sseParse.d.ts.map +1 -0
- package/script/lib/utils/other/sseParse.js +45 -0
- package/{esm/lib/helper → script/lib/utils}/request/RESTful.d.ts +43 -11
- package/script/lib/utils/request/RESTful.d.ts.map +1 -0
- package/script/lib/utils/request/RESTful.js +140 -0
- package/script/lib/utils/request/baseConf.d.ts +22 -0
- package/script/lib/utils/request/baseConf.d.ts.map +1 -0
- package/script/lib/utils/request/baseConf.js +42 -0
- package/script/lib/utils/request/factors.d.ts +30 -0
- package/script/lib/utils/request/factors.d.ts.map +1 -0
- package/script/lib/utils/request/factors.js +42 -0
- package/script/lib/{helper → utils}/request/input.d.ts +4 -3
- package/script/lib/utils/request/input.d.ts.map +1 -0
- package/script/lib/{helper → utils}/request/input.js +10 -10
- package/script/lib/utils/request/mod.d.ts +7 -0
- package/script/lib/utils/request/mod.d.ts.map +1 -0
- package/script/lib/utils/request/mod.js +22 -0
- package/script/lib/utils/request/process.d.ts +16 -0
- package/script/lib/utils/request/process.d.ts.map +1 -0
- package/script/lib/utils/request/process.js +41 -0
- package/script/lib/utils/request/wait.d.ts +10 -0
- package/script/lib/utils/request/wait.d.ts.map +1 -0
- package/script/lib/utils/request/wait.js +17 -0
- package/script/lib/utils/response/blobToUrl.d.ts +10 -0
- package/script/lib/utils/response/blobToUrl.d.ts.map +1 -0
- package/script/lib/utils/response/blobToUrl.js +24 -0
- package/script/lib/utils/response/mod.d.ts +5 -0
- package/script/lib/utils/response/mod.d.ts.map +1 -0
- package/script/lib/{helper/request → utils/response}/mod.js +4 -3
- package/script/lib/utils/response/openLink.d.ts +7 -0
- package/script/lib/utils/response/openLink.d.ts.map +1 -0
- package/script/lib/{helper/use/useLoading.js → utils/response/openLink.js} +17 -22
- package/script/lib/utils/response/output.d.ts +16 -0
- package/script/lib/utils/response/output.d.ts.map +1 -0
- package/script/lib/utils/response/output.js +28 -0
- package/script/lib/utils/response/pick.d.ts +23 -0
- package/script/lib/utils/response/pick.d.ts.map +1 -0
- package/script/lib/utils/response/pick.js +28 -0
- package/script/lib/utils/use/mod.d.ts.map +1 -0
- package/script/lib/{helper → utils}/use/mod.js +2 -2
- package/script/lib/utils/use/useCancel.d.ts +33 -0
- package/script/lib/utils/use/useCancel.d.ts.map +1 -0
- package/script/lib/utils/use/useCancel.js +44 -0
- package/script/lib/utils/use/useLoading.d.ts +34 -0
- package/script/lib/utils/use/useLoading.d.ts.map +1 -0
- package/script/lib/utils/use/useLoading.js +60 -0
- package/esm/lib/helper/mod.d.ts.map +0 -1
- package/esm/lib/helper/request/RESTful.d.ts.map +0 -1
- package/esm/lib/helper/request/RESTful.js +0 -1
- package/esm/lib/helper/request/baseConf.d.ts +0 -15
- package/esm/lib/helper/request/baseConf.d.ts.map +0 -1
- package/esm/lib/helper/request/baseConf.js +0 -1
- package/esm/lib/helper/request/input.d.ts.map +0 -1
- package/esm/lib/helper/request/input.js +0 -1
- package/esm/lib/helper/request/mod.d.ts +0 -4
- package/esm/lib/helper/request/mod.d.ts.map +0 -1
- package/esm/lib/helper/request/mod.js +0 -3
- package/esm/lib/helper/response/mod.d.ts +0 -3
- package/esm/lib/helper/response/mod.d.ts.map +0 -1
- package/esm/lib/helper/response/mod.js +0 -2
- package/esm/lib/helper/response/output.d.ts +0 -5
- package/esm/lib/helper/response/output.d.ts.map +0 -1
- package/esm/lib/helper/response/output.js +0 -1
- package/esm/lib/helper/response/pick.d.ts +0 -7
- package/esm/lib/helper/response/pick.d.ts.map +0 -1
- package/esm/lib/helper/response/pick.js +0 -1
- package/esm/lib/helper/use/mod.d.ts.map +0 -1
- package/esm/lib/helper/use/mod.js +0 -2
- package/esm/lib/helper/use/useCancel.d.ts +0 -4
- package/esm/lib/helper/use/useCancel.d.ts.map +0 -1
- package/esm/lib/helper/use/useCancel.js +0 -1
- package/esm/lib/helper/use/useLoading.d.ts +0 -15
- package/esm/lib/helper/use/useLoading.d.ts.map +0 -1
- package/esm/lib/helper/use/useLoading.js +0 -1
- package/script/lib/helper/mod.d.ts.map +0 -1
- package/script/lib/helper/request/RESTful.d.ts.map +0 -1
- package/script/lib/helper/request/RESTful.js +0 -86
- package/script/lib/helper/request/baseConf.d.ts +0 -15
- package/script/lib/helper/request/baseConf.d.ts.map +0 -1
- package/script/lib/helper/request/baseConf.js +0 -27
- package/script/lib/helper/request/input.d.ts.map +0 -1
- package/script/lib/helper/request/mod.d.ts +0 -4
- package/script/lib/helper/request/mod.d.ts.map +0 -1
- package/script/lib/helper/response/mod.d.ts +0 -3
- package/script/lib/helper/response/mod.d.ts.map +0 -1
- package/script/lib/helper/response/output.d.ts +0 -5
- package/script/lib/helper/response/output.d.ts.map +0 -1
- package/script/lib/helper/response/output.js +0 -15
- package/script/lib/helper/response/pick.d.ts +0 -7
- package/script/lib/helper/response/pick.d.ts.map +0 -1
- package/script/lib/helper/response/pick.js +0 -12
- package/script/lib/helper/use/mod.d.ts.map +0 -1
- package/script/lib/helper/use/useCancel.d.ts +0 -4
- package/script/lib/helper/use/useCancel.d.ts.map +0 -1
- package/script/lib/helper/use/useCancel.js +0 -15
- package/script/lib/helper/use/useLoading.d.ts +0 -15
- package/script/lib/helper/use/useLoading.d.ts.map +0 -1
- /package/esm/lib/{helper → utils}/use/mod.d.ts +0 -0
- /package/script/lib/{helper → utils}/use/mod.d.ts +0 -0
|
@@ -1,40 +1,72 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { JsonXObject } from '@chzky/core';
|
|
2
2
|
import type { RequestInterceptor } from '../../../mod.js';
|
|
3
3
|
/** ### `post` : post请求
|
|
4
|
-
@param
|
|
4
|
+
@param `string` - 请求地址
|
|
5
5
|
@param [data={}] `unknown` - 请求数据
|
|
6
6
|
@param [query={}] `Record<string, unknown>` - URL形式的请求参数
|
|
7
|
-
@
|
|
8
|
-
@category `Request`
|
|
7
|
+
@category `RequestInterceptor`
|
|
9
8
|
*/
|
|
10
9
|
export declare function post(url: string, data?: unknown, query?: JsonXObject): RequestInterceptor<never>;
|
|
11
10
|
/** ### `get` : get请求
|
|
12
11
|
@param url `string` - 请求地址
|
|
13
12
|
@param [query={}] `Record<string, unknown>` - URL形式的请求参数
|
|
14
|
-
@
|
|
15
|
-
@category `Request`
|
|
13
|
+
@category `RequestInterceptor`
|
|
16
14
|
*/
|
|
17
15
|
export declare function get(url: string, query?: JsonXObject): RequestInterceptor<never>;
|
|
18
16
|
/** ### `put` : put请求
|
|
19
17
|
@param url `string` - 请求地址
|
|
20
18
|
@param [data={}] `unknown` - 请求数据
|
|
21
19
|
@param [query={}] `Record<string, unknown>` - URL形式的请求参数
|
|
22
|
-
@
|
|
23
|
-
@category `Request`
|
|
20
|
+
@category `RequestInterceptor`
|
|
24
21
|
*/
|
|
25
22
|
export declare function put(url: string, data?: unknown, query?: JsonXObject): RequestInterceptor<never>;
|
|
26
23
|
/** ### `del` : delete请求
|
|
27
24
|
@param url `string` - 请求地址
|
|
28
25
|
@param [query={}] `Record<string, unknown>` - query形式的请求参数
|
|
29
|
-
@
|
|
30
|
-
@category `Request`
|
|
26
|
+
@category `RequestInterceptor`
|
|
31
27
|
*/
|
|
32
28
|
export declare function del(url: string, query?: JsonXObject): RequestInterceptor<never>;
|
|
33
29
|
/** ### `form` : FormData形式请求
|
|
34
30
|
@param url `string` - 请求地址
|
|
35
31
|
@param data `Record<string, string | Blob>` - 请求数据
|
|
36
|
-
@type `Interceptor` - `Request`
|
|
37
32
|
@category `Request`
|
|
38
33
|
*/
|
|
39
34
|
export declare function form(url: string, data: Record<string | number, string | Blob>): RequestInterceptor<never>;
|
|
35
|
+
/** ### `set_body` : 覆盖Body参数
|
|
36
|
+
该方法会覆盖请求的Body参数
|
|
37
|
+
@example Usage
|
|
38
|
+
```ts
|
|
39
|
+
const request = post('/api')
|
|
40
|
+
request.use(set_body({ foo: 'bar' })) // Will override request body
|
|
41
|
+
```
|
|
42
|
+
@param data `unknown` - 请求数据
|
|
43
|
+
@category `RequestInterceptor`
|
|
44
|
+
*/
|
|
45
|
+
export declare function set_body(data: unknown): RequestInterceptor<never>;
|
|
46
|
+
/** ### `set_params` : 覆盖URL参数
|
|
47
|
+
该方法会覆盖请求的URL参数
|
|
48
|
+
@example Usage
|
|
49
|
+
```ts
|
|
50
|
+
const request = get('/api')
|
|
51
|
+
request.use(set_params({ foo: 'bar' })) // Will override request params
|
|
52
|
+
```
|
|
53
|
+
@param params `Record<string, unknown>` - URL形式的请求参数
|
|
54
|
+
@type `Interceptor` - `Request`
|
|
55
|
+
@category `RequestInterceptor`
|
|
56
|
+
*/
|
|
57
|
+
export declare function set_params(params: JsonXObject): RequestInterceptor<never>;
|
|
58
|
+
/** ### `append_url` : URL
|
|
59
|
+
该方法会将url添加到请求地址的后面;如果没有url,则直接添加
|
|
60
|
+
@param url `string` - 请求地址
|
|
61
|
+
@type `Interceptor` - `Request`
|
|
62
|
+
@category `RequestInterceptor`
|
|
63
|
+
*/
|
|
64
|
+
export declare function append_url(url: string): RequestInterceptor<never>;
|
|
65
|
+
/** ## `RESTful` : `RESTful`请求 */
|
|
66
|
+
export declare const RESTful: {
|
|
67
|
+
readonly Get: typeof get;
|
|
68
|
+
readonly Post: typeof post;
|
|
69
|
+
readonly Put: typeof put;
|
|
70
|
+
readonly Del: typeof del;
|
|
71
|
+
};
|
|
40
72
|
//# sourceMappingURL=RESTful.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RESTful.d.ts","sourceRoot":"","sources":["../../../../src/lib/utils/request/RESTful.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAC9C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAA;AAIzD;;;;;EAKE;AACF,wBAAgB,IAAI,CACnB,GAAG,EAAE,MAAM,EACX,IAAI,GAAE,OAAY,EAClB,KAAK,GAAE,WAAgB,GACrB,kBAAkB,CAAC,KAAK,CAAC,CAQ3B;AAED;;;;EAIE;AACF,wBAAgB,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,GAAE,WAAgB,GAAG,kBAAkB,CAAC,KAAK,CAAC,CAOnF;AAED;;;;;GAKG;AACH,wBAAgB,GAAG,CAClB,GAAG,EAAE,MAAM,EACX,IAAI,GAAE,OAAY,EAClB,KAAK,GAAE,WAAgB,GACrB,kBAAkB,CAAC,KAAK,CAAC,CAQ3B;AAED;;;;EAIE;AACF,wBAAgB,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,GAAE,WAAgB,GAAG,kBAAkB,CAAC,KAAK,CAAC,CAOnF;AAED;;;;EAIE;AACF,wBAAgB,IAAI,CACnB,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,MAAM,CAAC,MAAM,GAAG,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC,GAC1C,kBAAkB,CAAC,KAAK,CAAC,CAW3B;AAED;;;;;;;;;EASE;AACF,wBAAgB,QAAQ,CAAC,IAAI,EAAE,OAAO,GAAG,kBAAkB,CAAC,KAAK,CAAC,CAKjE;AAED;;;;;;;;;;EAUE;AACF,wBAAgB,UAAU,CAAC,MAAM,EAAE,WAAW,GAAG,kBAAkB,CAAC,KAAK,CAAC,CAKzE;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,kBAAkB,CAAC,KAAK,CAAC,CAMjE;AAED,kCAAkC;AAClC,eAAO,MAAM,OAAO;;;;;CAKV,CAAA"}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RESTful = void 0;
|
|
4
|
+
exports.post = post;
|
|
5
|
+
exports.get = get;
|
|
6
|
+
exports.put = put;
|
|
7
|
+
exports.del = del;
|
|
8
|
+
exports.form = form;
|
|
9
|
+
exports.set_body = set_body;
|
|
10
|
+
exports.set_params = set_params;
|
|
11
|
+
exports.append_url = append_url;
|
|
12
|
+
const core_1 = require("@chzky/core");
|
|
13
|
+
/** ### `post` : post请求
|
|
14
|
+
@param `string` - 请求地址
|
|
15
|
+
@param [data={}] `unknown` - 请求数据
|
|
16
|
+
@param [query={}] `Record<string, unknown>` - URL形式的请求参数
|
|
17
|
+
@category `RequestInterceptor`
|
|
18
|
+
*/
|
|
19
|
+
function post(url, data = {}, query = {}) {
|
|
20
|
+
return conf => {
|
|
21
|
+
conf.method = 'post';
|
|
22
|
+
conf.url = url;
|
|
23
|
+
conf.data = data;
|
|
24
|
+
conf.params = query;
|
|
25
|
+
return (0, core_1.Ok)();
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
/** ### `get` : get请求
|
|
29
|
+
@param url `string` - 请求地址
|
|
30
|
+
@param [query={}] `Record<string, unknown>` - URL形式的请求参数
|
|
31
|
+
@category `RequestInterceptor`
|
|
32
|
+
*/
|
|
33
|
+
function get(url, query = {}) {
|
|
34
|
+
return conf => {
|
|
35
|
+
conf.method = 'get';
|
|
36
|
+
conf.url = url;
|
|
37
|
+
conf.params = query;
|
|
38
|
+
return (0, core_1.Ok)();
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
/** ### `put` : put请求
|
|
42
|
+
@param url `string` - 请求地址
|
|
43
|
+
@param [data={}] `unknown` - 请求数据
|
|
44
|
+
@param [query={}] `Record<string, unknown>` - URL形式的请求参数
|
|
45
|
+
@category `RequestInterceptor`
|
|
46
|
+
*/
|
|
47
|
+
function put(url, data = {}, query = {}) {
|
|
48
|
+
return conf => {
|
|
49
|
+
conf.method = 'put';
|
|
50
|
+
conf.url = url;
|
|
51
|
+
conf.data = data;
|
|
52
|
+
conf.params = query;
|
|
53
|
+
return (0, core_1.Ok)();
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
/** ### `del` : delete请求
|
|
57
|
+
@param url `string` - 请求地址
|
|
58
|
+
@param [query={}] `Record<string, unknown>` - query形式的请求参数
|
|
59
|
+
@category `RequestInterceptor`
|
|
60
|
+
*/
|
|
61
|
+
function del(url, query = {}) {
|
|
62
|
+
return conf => {
|
|
63
|
+
conf.method = 'delete';
|
|
64
|
+
conf.url = url;
|
|
65
|
+
conf.params = query;
|
|
66
|
+
return (0, core_1.Ok)();
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
/** ### `form` : FormData形式请求
|
|
70
|
+
@param url `string` - 请求地址
|
|
71
|
+
@param data `Record<string, string | Blob>` - 请求数据
|
|
72
|
+
@category `Request`
|
|
73
|
+
*/
|
|
74
|
+
function form(url, data) {
|
|
75
|
+
return conf => {
|
|
76
|
+
conf.method = 'post';
|
|
77
|
+
conf.url = url;
|
|
78
|
+
const fdata = new FormData();
|
|
79
|
+
Object.entries(data).forEach(([key, value]) => {
|
|
80
|
+
fdata.append(key, value);
|
|
81
|
+
});
|
|
82
|
+
conf.data = fdata;
|
|
83
|
+
return (0, core_1.Ok)();
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
/** ### `set_body` : 覆盖Body参数
|
|
87
|
+
该方法会覆盖请求的Body参数
|
|
88
|
+
@example Usage
|
|
89
|
+
```ts
|
|
90
|
+
const request = post('/api')
|
|
91
|
+
request.use(set_body({ foo: 'bar' })) // Will override request body
|
|
92
|
+
```
|
|
93
|
+
@param data `unknown` - 请求数据
|
|
94
|
+
@category `RequestInterceptor`
|
|
95
|
+
*/
|
|
96
|
+
function set_body(data) {
|
|
97
|
+
return conf => {
|
|
98
|
+
conf.data = data;
|
|
99
|
+
return (0, core_1.Ok)();
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
/** ### `set_params` : 覆盖URL参数
|
|
103
|
+
该方法会覆盖请求的URL参数
|
|
104
|
+
@example Usage
|
|
105
|
+
```ts
|
|
106
|
+
const request = get('/api')
|
|
107
|
+
request.use(set_params({ foo: 'bar' })) // Will override request params
|
|
108
|
+
```
|
|
109
|
+
@param params `Record<string, unknown>` - URL形式的请求参数
|
|
110
|
+
@type `Interceptor` - `Request`
|
|
111
|
+
@category `RequestInterceptor`
|
|
112
|
+
*/
|
|
113
|
+
function set_params(params) {
|
|
114
|
+
return conf => {
|
|
115
|
+
conf.params = params;
|
|
116
|
+
return (0, core_1.Ok)();
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
/** ### `append_url` : URL
|
|
120
|
+
该方法会将url添加到请求地址的后面;如果没有url,则直接添加
|
|
121
|
+
@param url `string` - 请求地址
|
|
122
|
+
@type `Interceptor` - `Request`
|
|
123
|
+
@category `RequestInterceptor`
|
|
124
|
+
*/
|
|
125
|
+
function append_url(url) {
|
|
126
|
+
return conf => {
|
|
127
|
+
if (!conf.url)
|
|
128
|
+
conf.url = url;
|
|
129
|
+
else
|
|
130
|
+
conf.url = `${url}/${conf.url}`.replace(/\/{2,}/g, '/');
|
|
131
|
+
return (0, core_1.Ok)();
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
/** ## `RESTful` : `RESTful`请求 */
|
|
135
|
+
exports.RESTful = {
|
|
136
|
+
Get: get,
|
|
137
|
+
Post: post,
|
|
138
|
+
Put: put,
|
|
139
|
+
Del: del,
|
|
140
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { PositiveInteger } from '@chzky/core';
|
|
2
|
+
import type { RequestInterceptor } from '../../../mod.js';
|
|
3
|
+
import type { AxiosRequestHeaders, ResponseType } from 'axios';
|
|
4
|
+
/** ## `header` : 修改请求头数据
|
|
5
|
+
@param head `AxiosRequestHeaders` - 请求头数据
|
|
6
|
+
@type `Interceptor` - `Request`
|
|
7
|
+
@category `Request`
|
|
8
|
+
*/
|
|
9
|
+
export declare function header(head: AxiosRequestHeaders): RequestInterceptor<never>;
|
|
10
|
+
/** ## `response_type` : 修改响应数据类型
|
|
11
|
+
@param type `ResponseType` - 响应数据类型
|
|
12
|
+
@type `Interceptor` - `Request`
|
|
13
|
+
@category `Request`
|
|
14
|
+
*/
|
|
15
|
+
export declare function response_type(type: ResponseType): RequestInterceptor<never>;
|
|
16
|
+
/** ## `timeout` : 修改请求超时时间
|
|
17
|
+
@param time `PositiveInteger<N>` - 请求超时时间
|
|
18
|
+
@type `Interceptor` - `Request`
|
|
19
|
+
@category `Request`
|
|
20
|
+
*/
|
|
21
|
+
export declare function timeout<N extends number>(time: PositiveInteger<N>): RequestInterceptor<never>;
|
|
22
|
+
//# sourceMappingURL=baseConf.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"baseConf.d.ts","sourceRoot":"","sources":["../../../../src/lib/utils/request/baseConf.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAClD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAA;AACzD,OAAO,KAAK,EAAE,mBAAmB,EAAE,YAAY,EAAE,MAAM,OAAO,CAAA;AAI9D;;;;GAIG;AACH,wBAAgB,MAAM,CAAC,IAAI,EAAE,mBAAmB,GAAG,kBAAkB,CAAC,KAAK,CAAC,CAO3E;AAED;;;;EAIE;AACF,wBAAgB,aAAa,CAAC,IAAI,EAAE,YAAY,GAAG,kBAAkB,CAAC,KAAK,CAAC,CAK3E;AAED;;;;EAIE;AACF,wBAAgB,OAAO,CAAC,CAAC,SAAS,MAAM,EAAE,IAAI,EAAE,eAAe,CAAC,CAAC,CAAC,GAAG,kBAAkB,CAAC,KAAK,CAAC,CAK7F"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.header = header;
|
|
4
|
+
exports.response_type = response_type;
|
|
5
|
+
exports.timeout = timeout;
|
|
6
|
+
const core_1 = require("@chzky/core");
|
|
7
|
+
/** ## `header` : 修改请求头数据
|
|
8
|
+
@param head `AxiosRequestHeaders` - 请求头数据
|
|
9
|
+
@type `Interceptor` - `Request`
|
|
10
|
+
@category `Request`
|
|
11
|
+
*/
|
|
12
|
+
function header(head) {
|
|
13
|
+
return conf => {
|
|
14
|
+
for (const key in head) {
|
|
15
|
+
if (Object.hasOwn(head, key))
|
|
16
|
+
conf.headers.set(String(key), head[key]);
|
|
17
|
+
}
|
|
18
|
+
return (0, core_1.Ok)();
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
/** ## `response_type` : 修改响应数据类型
|
|
22
|
+
@param type `ResponseType` - 响应数据类型
|
|
23
|
+
@type `Interceptor` - `Request`
|
|
24
|
+
@category `Request`
|
|
25
|
+
*/
|
|
26
|
+
function response_type(type) {
|
|
27
|
+
return conf => {
|
|
28
|
+
conf.responseType = type;
|
|
29
|
+
return (0, core_1.Ok)();
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
/** ## `timeout` : 修改请求超时时间
|
|
33
|
+
@param time `PositiveInteger<N>` - 请求超时时间
|
|
34
|
+
@type `Interceptor` - `Request`
|
|
35
|
+
@category `Request`
|
|
36
|
+
*/
|
|
37
|
+
function timeout(time) {
|
|
38
|
+
return conf => {
|
|
39
|
+
conf.timeout = time;
|
|
40
|
+
return (0, core_1.Ok)();
|
|
41
|
+
};
|
|
42
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { Fn, JsonXObject, zod } from '@chzky/core';
|
|
2
|
+
import type { RequestInterceptor } from '../../../mod.js';
|
|
3
|
+
import { CheckingError } from '@chzky/core';
|
|
4
|
+
type Methods = 'get' | 'post' | 'put' | 'delete' | 'form';
|
|
5
|
+
/** ## `restful_request` : `url配置` + `类型校验` + `数据输入`
|
|
6
|
+
+ 对于`get`请求 , data传数据到`query`上
|
|
7
|
+
+ 对于`post`|`put`|`delete`|`form`请求 , data传数据到`body`上
|
|
8
|
+
@example Usage
|
|
9
|
+
```ts
|
|
10
|
+
// GET请求 - 验证
|
|
11
|
+
const get_user = restful_request('get', '/api/users', z.object({ id: z.number() }))
|
|
12
|
+
get_user({ id: 1 }) // params: { id: 1 }
|
|
13
|
+
|
|
14
|
+
// POST请求 - 验证
|
|
15
|
+
const create_user = restful_request('post', '/api/users', z.object({ name: z.string() }))
|
|
16
|
+
create_user({ name: 'john' }) // body: { name: 'john' }
|
|
17
|
+
|
|
18
|
+
// PUT请求 - 无验证
|
|
19
|
+
const update_user = restful_request('put', '/api/users')
|
|
20
|
+
update_user({ name: 'john' }) // body: { name: 'john' }
|
|
21
|
+
|
|
22
|
+
// 表单请求 - 无验证
|
|
23
|
+
const upload = restful_request('form', '/api/upload')
|
|
24
|
+
upload(new FormData()) // body: FormData
|
|
25
|
+
```
|
|
26
|
+
@cataegory Reqwest - Helper
|
|
27
|
+
*/
|
|
28
|
+
export declare function restful_request<T extends JsonXObject & Record<string | number, string | Blob> = never>(method: Methods, url: string, validate?: zod.Schema<T>): Fn<T, RequestInterceptor<T extends never ? never : CheckingError>>;
|
|
29
|
+
export {};
|
|
30
|
+
//# sourceMappingURL=factors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"factors.d.ts","sourceRoot":"","sources":["../../../../src/lib/utils/request/factors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,WAAW,EAAE,GAAG,EAAE,MAAM,aAAa,CAAA;AACvD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAA;AAEzD,OAAO,EAAE,aAAa,EAAS,MAAM,aAAa,CAAA;AAGlD,KAAK,OAAO,GAAG,KAAK,GAAG,MAAM,GAAG,KAAK,GAAG,QAAQ,GAAG,MAAM,CAAA;AAGzD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,eAAe,CAC9B,CAAC,SAAS,WAAW,GAAG,MAAM,CAAC,MAAM,GAAG,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC,GAAG,KAAK,EAEtE,MAAM,EAAE,OAAO,EACf,GAAG,EAAE,MAAM,EACX,QAAQ,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,GACtB,EAAE,CAAC,CAAC,EAAE,kBAAkB,CAAC,CAAC,SAAS,KAAK,GAAG,KAAK,GAAG,aAAa,CAAC,CAAC,CAYpE"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.restful_request = restful_request;
|
|
4
|
+
const core_1 = require("@chzky/core");
|
|
5
|
+
const mod_js_1 = require("../../../mod.js");
|
|
6
|
+
const ERROR_MSG = `param checktype must be 'data' or 'params`;
|
|
7
|
+
/** ## `restful_request` : `url配置` + `类型校验` + `数据输入`
|
|
8
|
+
+ 对于`get`请求 , data传数据到`query`上
|
|
9
|
+
+ 对于`post`|`put`|`delete`|`form`请求 , data传数据到`body`上
|
|
10
|
+
@example Usage
|
|
11
|
+
```ts
|
|
12
|
+
// GET请求 - 验证
|
|
13
|
+
const get_user = restful_request('get', '/api/users', z.object({ id: z.number() }))
|
|
14
|
+
get_user({ id: 1 }) // params: { id: 1 }
|
|
15
|
+
|
|
16
|
+
// POST请求 - 验证
|
|
17
|
+
const create_user = restful_request('post', '/api/users', z.object({ name: z.string() }))
|
|
18
|
+
create_user({ name: 'john' }) // body: { name: 'john' }
|
|
19
|
+
|
|
20
|
+
// PUT请求 - 无验证
|
|
21
|
+
const update_user = restful_request('put', '/api/users')
|
|
22
|
+
update_user({ name: 'john' }) // body: { name: 'john' }
|
|
23
|
+
|
|
24
|
+
// 表单请求 - 无验证
|
|
25
|
+
const upload = restful_request('form', '/api/upload')
|
|
26
|
+
upload(new FormData()) // body: FormData
|
|
27
|
+
```
|
|
28
|
+
@cataegory Reqwest - Helper
|
|
29
|
+
*/
|
|
30
|
+
function restful_request(method, url, validate) {
|
|
31
|
+
return ((data) => {
|
|
32
|
+
const METHOD = (0, core_1.match)(method)
|
|
33
|
+
.case('delete', mod_js_1.del)
|
|
34
|
+
.case('get', mod_js_1.get)
|
|
35
|
+
.case('post', mod_js_1.post)
|
|
36
|
+
.case('put', mod_js_1.put)
|
|
37
|
+
.case('form', mod_js_1.form)
|
|
38
|
+
.done()
|
|
39
|
+
.expect(core_1.CheckingError.new(ERROR_MSG));
|
|
40
|
+
return validate ? (0, mod_js_1.merge_request)(METHOD(url, data), (0, mod_js_1.input_validate)(validate)) : METHOD(url, data);
|
|
41
|
+
});
|
|
42
|
+
}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { zod } from '@chzky/core';
|
|
2
2
|
import type { RequestInterceptor } from '../../../mod.js';
|
|
3
|
-
|
|
3
|
+
import { CheckingError } from '@chzky/core';
|
|
4
|
+
/** ## `input_validate` : 使用`zod`对输入的data数据进行解析校验(使用`zod.parse`)
|
|
4
5
|
+ 该方法会返回一个`RequestInterceptor`拦截器,如果校验失败会返回`CheckingError`
|
|
5
6
|
@param schema `zod.Schema<unknown>` - 校验规则
|
|
6
7
|
@param [checktype] `'data' | 'params'` - 校验类型,如果是`get`请求则默认为`params`,其他类型的请求默认为`data`,
|
|
7
8
|
@type `Interceptor` - `Request`
|
|
8
9
|
@category `Request`
|
|
9
10
|
*/
|
|
10
|
-
export declare function
|
|
11
|
+
export declare function input_validate(schema: zod.Schema<unknown>, checktype?: 'data' | 'params'): RequestInterceptor<CheckingError>;
|
|
11
12
|
//# sourceMappingURL=input.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"input.d.ts","sourceRoot":"","sources":["../../../../src/lib/utils/request/input.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,aAAa,CAAA;AACtC,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAA;AAEzD,OAAO,EAAE,aAAa,EAAM,MAAM,aAAa,CAAA;AAI/C;;;;;;EAME;AACF,wBAAgB,cAAc,CAC7B,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,EAC3B,SAAS,CAAC,EAAE,MAAM,GAAG,QAAQ,GAC3B,kBAAkB,CAAC,aAAa,CAAC,CAYnC"}
|
|
@@ -1,27 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
const
|
|
3
|
+
exports.input_validate = input_validate;
|
|
4
|
+
const core_1 = require("@chzky/core");
|
|
5
5
|
const ERROR_MSG = `param checktype must be 'data' or 'params'`;
|
|
6
|
-
/** ## `
|
|
6
|
+
/** ## `input_validate` : 使用`zod`对输入的data数据进行解析校验(使用`zod.parse`)
|
|
7
7
|
+ 该方法会返回一个`RequestInterceptor`拦截器,如果校验失败会返回`CheckingError`
|
|
8
8
|
@param schema `zod.Schema<unknown>` - 校验规则
|
|
9
9
|
@param [checktype] `'data' | 'params'` - 校验类型,如果是`get`请求则默认为`params`,其他类型的请求默认为`data`,
|
|
10
10
|
@type `Interceptor` - `Request`
|
|
11
11
|
@category `Request`
|
|
12
12
|
*/
|
|
13
|
-
function
|
|
14
|
-
return
|
|
13
|
+
function input_validate(schema, checktype) {
|
|
14
|
+
return conf => {
|
|
15
15
|
conf.timeout;
|
|
16
|
-
const ct = checktype || conf.method
|
|
16
|
+
const ct = checktype || conf.method === 'get' ? 'params' : 'data';
|
|
17
17
|
if (ct !== 'data' && ct !== 'params')
|
|
18
|
-
return
|
|
18
|
+
return core_1.CheckingError.err(ERROR_MSG);
|
|
19
19
|
try {
|
|
20
|
-
schema.parse(ct
|
|
21
|
-
return (0,
|
|
20
|
+
schema.parse(ct === 'data' ? conf.data : conf.params);
|
|
21
|
+
return (0, core_1.Ok)();
|
|
22
22
|
}
|
|
23
23
|
catch (e) {
|
|
24
|
-
return
|
|
24
|
+
return core_1.CheckingError.err(e);
|
|
25
25
|
}
|
|
26
26
|
};
|
|
27
27
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../../../src/lib/utils/request/mod.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAA;AAC7B,cAAc,cAAc,CAAA;AAC5B,cAAc,YAAY,CAAA;AAC1B,cAAc,cAAc,CAAA;AAC5B,cAAc,cAAc,CAAA;AAC5B,cAAc,WAAW,CAAA"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./baseConf.js"), exports); /* 提供基础配置 */
|
|
18
|
+
__exportStar(require("./factors.js"), exports); /* 请求集合 */
|
|
19
|
+
__exportStar(require("./input.js"), exports); /* 请求参数校验 */
|
|
20
|
+
__exportStar(require("./process.js"), exports); /* 进度 */
|
|
21
|
+
__exportStar(require("./RESTful.js"), exports); /* 提供restful配置 */
|
|
22
|
+
__exportStar(require("./wait.js"), exports); /* 请求等待 */
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { RequestInterceptor } from '../../../mod.js';
|
|
2
|
+
/** ## `upload_process` : 上传进度查询(浏览器专属)
|
|
3
|
+
+ 进度只保留两位小数,即`xx.yy%`
|
|
4
|
+
+ 存在两种情况,进度不可计算时,返回`-1%`
|
|
5
|
+
+ `event.lengthComputable`为`false` (长度不可计算)
|
|
6
|
+
+ `event.total`为`0`(数据的总大小不可知)
|
|
7
|
+
*/
|
|
8
|
+
export default function upload_process(progress: (percent: number) => void): RequestInterceptor<never>;
|
|
9
|
+
/** ## `download_process` : 下载进度查询(浏览器专属)
|
|
10
|
+
+ 进度只保留两位小数,即`xx.yy%`
|
|
11
|
+
+ 存在两种情况,进度不可计算时,返回`-1%`
|
|
12
|
+
+ `event.lengthComputable`为`false` (长度不可计算)
|
|
13
|
+
+ `event.total`为`0`(数据的总大小不可知)
|
|
14
|
+
*/
|
|
15
|
+
export declare function download_process(progress: (percent: number) => void): RequestInterceptor<never>;
|
|
16
|
+
//# sourceMappingURL=process.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"process.d.ts","sourceRoot":"","sources":["../../../../src/lib/utils/request/process.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAA;AAEpD;;;;;EAKE;AACF,MAAM,CAAC,OAAO,UAAU,cAAc,CACrC,QAAQ,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,GACjC,kBAAkB,CAAC,KAAK,CAAC,CAS3B;AAED;;;;;EAKE;AACF,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,GAAG,kBAAkB,CAAC,KAAK,CAAC,CAU/F"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = upload_process;
|
|
4
|
+
exports.download_process = download_process;
|
|
5
|
+
const core_1 = require("@chzky/core");
|
|
6
|
+
/** ## `upload_process` : 上传进度查询(浏览器专属)
|
|
7
|
+
+ 进度只保留两位小数,即`xx.yy%`
|
|
8
|
+
+ 存在两种情况,进度不可计算时,返回`-1%`
|
|
9
|
+
+ `event.lengthComputable`为`false` (长度不可计算)
|
|
10
|
+
+ `event.total`为`0`(数据的总大小不可知)
|
|
11
|
+
*/
|
|
12
|
+
function upload_process(progress) {
|
|
13
|
+
return conf => {
|
|
14
|
+
conf.onUploadProgress = event => {
|
|
15
|
+
if (event.lengthComputable && event.total) {
|
|
16
|
+
progress(Number.parseFloat(((event.loaded * 100) / event.total).toFixed(2)));
|
|
17
|
+
}
|
|
18
|
+
else
|
|
19
|
+
progress(-1);
|
|
20
|
+
};
|
|
21
|
+
return (0, core_1.Ok)();
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
/** ## `download_process` : 下载进度查询(浏览器专属)
|
|
25
|
+
+ 进度只保留两位小数,即`xx.yy%`
|
|
26
|
+
+ 存在两种情况,进度不可计算时,返回`-1%`
|
|
27
|
+
+ `event.lengthComputable`为`false` (长度不可计算)
|
|
28
|
+
+ `event.total`为`0`(数据的总大小不可知)
|
|
29
|
+
*/
|
|
30
|
+
function download_process(progress) {
|
|
31
|
+
return conf => {
|
|
32
|
+
conf.onDownloadProgress = event => {
|
|
33
|
+
if (event.lengthComputable && event.total) {
|
|
34
|
+
progress(Number.parseFloat(((event.loaded * 100) / event.total).toFixed(2)));
|
|
35
|
+
}
|
|
36
|
+
else
|
|
37
|
+
progress(-1);
|
|
38
|
+
};
|
|
39
|
+
return (0, core_1.Ok)();
|
|
40
|
+
};
|
|
41
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { PositiveInteger } from '@chzky/core';
|
|
2
|
+
import type { RequestInterceptor } from '../../../mod.js';
|
|
3
|
+
/** ## `wait` : 等待指定时间后继续执行请求
|
|
4
|
+
* @param time `PositiveInteger<N>` - The time to wait in milliseconds (must be a positive integer)
|
|
5
|
+
* @type `RequestInterceptor` - `Request`
|
|
6
|
+
* @category `Request`
|
|
7
|
+
* @returns A Promise that resolves after the specified time delay
|
|
8
|
+
*/
|
|
9
|
+
export declare function wait<N extends number>(time: PositiveInteger<N>): RequestInterceptor<never>;
|
|
10
|
+
//# sourceMappingURL=wait.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wait.d.ts","sourceRoot":"","sources":["../../../../src/lib/utils/request/wait.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAClD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAA;AAIzD;;;;;GAKG;AACH,wBAAgB,IAAI,CAAC,CAAC,SAAS,MAAM,EAAE,IAAI,EAAE,eAAe,CAAC,CAAC,CAAC,GAAG,kBAAkB,CAAC,KAAK,CAAC,CAO1F"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.wait = wait;
|
|
4
|
+
const core_1 = require("@chzky/core");
|
|
5
|
+
/** ## `wait` : 等待指定时间后继续执行请求
|
|
6
|
+
* @param time `PositiveInteger<N>` - The time to wait in milliseconds (must be a positive integer)
|
|
7
|
+
* @type `RequestInterceptor` - `Request`
|
|
8
|
+
* @category `Request`
|
|
9
|
+
* @returns A Promise that resolves after the specified time delay
|
|
10
|
+
*/
|
|
11
|
+
function wait(time) {
|
|
12
|
+
return () => new Promise(res => {
|
|
13
|
+
setTimeout(() => {
|
|
14
|
+
res((0, core_1.Ok)());
|
|
15
|
+
}, time);
|
|
16
|
+
});
|
|
17
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ResponseInterceptor } from '../../../mod.js';
|
|
2
|
+
/** ## blob2url : `blob`转化成`url`,赋值在`src`字段上
|
|
3
|
+
+ 一般用于
|
|
4
|
+
1. 图片显示
|
|
5
|
+
2. 显示PDF
|
|
6
|
+
@returns [`revoke`:用于取消对`ObjectURL`对象的引用, `interceptor`:拦截器]
|
|
7
|
+
@category ResponseInterceptor
|
|
8
|
+
*/
|
|
9
|
+
export declare function blob2url(): [() => void, ResponseInterceptor<Blob, string, never>];
|
|
10
|
+
//# sourceMappingURL=blobToUrl.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"blobToUrl.d.ts","sourceRoot":"","sources":["../../../../src/lib/utils/response/blobToUrl.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAA;AAI1D;;;;;;EAME;AACF,wBAAgB,QAAQ,IAAI,CAAC,MAAM,IAAI,EAAE,mBAAmB,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC,CAWjF"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.blob2url = blob2url;
|
|
4
|
+
const core_1 = require("@chzky/core");
|
|
5
|
+
/** ## blob2url : `blob`转化成`url`,赋值在`src`字段上
|
|
6
|
+
+ 一般用于
|
|
7
|
+
1. 图片显示
|
|
8
|
+
2. 显示PDF
|
|
9
|
+
@returns [`revoke`:用于取消对`ObjectURL`对象的引用, `interceptor`:拦截器]
|
|
10
|
+
@category ResponseInterceptor
|
|
11
|
+
*/
|
|
12
|
+
function blob2url() {
|
|
13
|
+
let object_url;
|
|
14
|
+
return [
|
|
15
|
+
() => {
|
|
16
|
+
if (object_url)
|
|
17
|
+
URL.revokeObjectURL(object_url);
|
|
18
|
+
},
|
|
19
|
+
blob => {
|
|
20
|
+
object_url = URL.createObjectURL(blob);
|
|
21
|
+
return (0, core_1.Ok)(object_url);
|
|
22
|
+
},
|
|
23
|
+
];
|
|
24
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../../../src/lib/utils/response/mod.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAA;AAC9B,cAAc,eAAe,CAAA;AAC7B,cAAc,aAAa,CAAA;AAC3B,cAAc,WAAW,CAAA"}
|
|
@@ -14,6 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./
|
|
18
|
-
__exportStar(require("./
|
|
19
|
-
__exportStar(require("./
|
|
17
|
+
__exportStar(require("./blobToUrl.js"), exports); /* blob赋值src */
|
|
18
|
+
__exportStar(require("./openLink.js"), exports); /* blob下载 */
|
|
19
|
+
__exportStar(require("./output.js"), exports); /* 输出校验|输出map */
|
|
20
|
+
__exportStar(require("./pick.js"), exports); /* 字段提取 */
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ResponseInterceptor } from '../../../mod.js';
|
|
2
|
+
/** ### `open_link` : 将获取到的blob文件直接进行下载
|
|
3
|
+
@tips : 只能在浏览器环境下使用,在非浏览器环境下会直接返回blob
|
|
4
|
+
@category ResponseInterceptor
|
|
5
|
+
*/
|
|
6
|
+
export declare function open_link(name: string): ResponseInterceptor<Blob, Blob, never>;
|
|
7
|
+
//# sourceMappingURL=openLink.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openLink.d.ts","sourceRoot":"","sources":["../../../../src/lib/utils/response/openLink.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAA;AAI1D;;;EAGE;AACF,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,mBAAmB,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,CAAC,CAY9E"}
|