@seayoo-web/request 4.0.5 → 4.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/dist/wx.js CHANGED
@@ -1,70 +1,64 @@
1
- import { h as l, r as p, c as y, E as R, R as u, f as x, a as h, t as c, N as w } from "./retry-LYfsjIVg.js";
2
- import { g as O } from "./retry-LYfsjIVg.js";
3
- const m = async function(s, o, n) {
4
- return l(await p(q, s, o, n), s, o, n);
5
- }, q = async function(s, o, n) {
6
- const t = await y(s, o, n), r = t.method;
7
- return !R() || r === "PATCH" ? {
8
- url: t.url,
9
- method: r,
10
- status: -1,
11
- error: u.NotSupport,
12
- statusText: u.NotSupport,
13
- body: ""
14
- } : new Promise((f) => {
15
- wx.request({
16
- url: t.url,
17
- data: t.body,
18
- header: t.headers,
19
- method: r,
20
- dataType: "raw",
21
- timeout: t.timeout,
22
- responseType: t.asBuffer ? "arraybuffer" : "text",
23
- fail({ errMsg: e, errno: d, exception: i }) {
24
- f({
25
- url: t.url,
26
- method: r,
27
- status: -1,
28
- error: u.Unknown,
29
- statusText: e,
30
- body: JSON.stringify({ errMsg: e, errno: d, exception: i })
31
- });
32
- },
33
- async success(e) {
34
- f(
35
- await x(
36
- {
37
- url: t.url,
38
- method: r,
39
- status: e.statusCode,
40
- statusText: `WxRequest${e.statusCode}`,
41
- headers: { ...e.header },
42
- body: null
43
- },
44
- {
45
- asBuffer: t.asBuffer,
46
- text: () => c(e.data),
47
- buffer: async () => e.data instanceof ArrayBuffer ? e.data : await h(c(e.data))
48
- }
49
- )
50
- );
51
- }
52
- });
53
- });
1
+ import { a as e, d as t, g as n, i as r, l as i, n as a, r as o, s, t as c, u as l } from "./retry-x0AqZ13h.js";
2
+ //#region src/inc/request.wx.ts
3
+ var u = async function(e, t, n) {
4
+ return o(await c(d, e, t, n), e, t, n);
5
+ }, d = async function(r, o, c) {
6
+ let l = await e(r, o, c), u = l.method;
7
+ return !n() || u === "PATCH" ? {
8
+ url: l.url,
9
+ method: u,
10
+ status: -1,
11
+ error: t.NotSupport,
12
+ statusText: t.NotSupport,
13
+ body: ""
14
+ } : new Promise((e) => {
15
+ let n = wx.request({
16
+ url: l.url,
17
+ data: l.body,
18
+ header: l.headers,
19
+ method: u,
20
+ dataType: "raw",
21
+ timeout: l.timeout,
22
+ responseType: l.asBuffer ? "arraybuffer" : "text",
23
+ fail({ errMsg: n, errno: r, exception: i }) {
24
+ e({
25
+ url: l.url,
26
+ method: u,
27
+ status: -1,
28
+ error: t.Unknown,
29
+ statusText: n,
30
+ body: JSON.stringify({
31
+ errMsg: n,
32
+ errno: r,
33
+ exception: i
34
+ })
35
+ });
36
+ },
37
+ async success(t) {
38
+ e(await a({
39
+ url: l.url,
40
+ method: u,
41
+ status: t.statusCode,
42
+ statusText: `WxRequest${t.statusCode}`,
43
+ headers: { ...t.header },
44
+ body: null
45
+ }, {
46
+ asBuffer: l.asBuffer,
47
+ text: () => i(t.data),
48
+ buffer: async () => t.data instanceof ArrayBuffer ? t.data : await s(i(t.data))
49
+ }));
50
+ }
51
+ });
52
+ l.abort?.addEventListener("abort", () => {
53
+ n.abort();
54
+ });
55
+ });
54
56
  };
55
- // @__NO_SIDE_EFFECTS__
56
- function b(s) {
57
- return new w(m, s);
57
+ //#endregion
58
+ //#region src/wx.ts
59
+ function f(e) {
60
+ return new l(u, e);
58
61
  }
59
- const a = /* @__PURE__ */ b(), T = a.setConfig, N = a.head, B = a.get, C = a.post, S = a.del, A = a.put;
60
- export {
61
- b as NetRequest,
62
- u as RequestInternalError,
63
- S as del,
64
- B as get,
65
- O as getResponseRulesDescription,
66
- N as head,
67
- C as post,
68
- A as put,
69
- T as setGlobalConfig
70
- };
62
+ var p = f(), m = p.setConfig, h = p.head, g = p.get, _ = p.post, v = p.del, y = p.put;
63
+ //#endregion
64
+ export { f as NetRequest, t as RequestInternalError, v as del, g as get, r as getResponseRulesDescription, h as head, _ as post, y as put, m as setGlobalConfig };
package/package.json CHANGED
@@ -1,13 +1,25 @@
1
1
  {
2
2
  "name": "@seayoo-web/request",
3
- "version": "4.0.5",
3
+ "version": "4.1.0",
4
4
  "description": "request tools for seayoo web",
5
- "type": "module",
5
+ "keywords": [
6
+ "fetch",
7
+ "request",
8
+ "upload"
9
+ ],
10
+ "license": "ISC",
11
+ "author": "web@seayoo.com",
6
12
  "source": "./src/index.ts",
13
+ "files": [
14
+ "dist",
15
+ "types",
16
+ "README.md"
17
+ ],
18
+ "type": "module",
19
+ "sideEffects": false,
7
20
  "main": "./dist/index.js",
8
21
  "module": "./dist/index.js",
9
22
  "types": "./types/index.d.ts",
10
- "sideEffects": false,
11
23
  "exports": {
12
24
  ".": {
13
25
  "types": "./types/index.d.ts",
@@ -18,52 +30,45 @@
18
30
  "browser": null,
19
31
  "types": "./types/node.d.ts",
20
32
  "import": "./dist/node.js",
21
- "default": "./dist/node.cjs"
33
+ "default": "./dist/node.js"
22
34
  },
23
35
  "./dist/node": {
24
36
  "browser": null,
25
37
  "types": "./types/node.d.ts",
26
38
  "import": "./dist/node.js",
27
- "default": "./dist/node.cjs"
39
+ "default": "./dist/node.js"
28
40
  },
29
41
  "./wx": {
30
42
  "types": "./types/wx.d.ts",
31
43
  "import": "./dist/wx.js",
32
44
  "default": "./dist/wx.js"
45
+ },
46
+ "./uni": {
47
+ "types": "./types/uni.d.ts",
48
+ "import": "./dist/uni.js",
49
+ "default": "./dist/uni.js"
33
50
  }
34
51
  },
35
- "files": [
36
- "dist",
37
- "types",
38
- "README.md"
39
- ],
40
52
  "publishConfig": {
41
53
  "access": "public"
42
54
  },
43
- "engines": {
44
- "node": ">=22"
45
- },
46
- "keywords": [
47
- "request",
48
- "fetch",
49
- "upload"
50
- ],
51
- "author": "web@seayoo.com",
52
- "license": "ISC",
53
55
  "devDependencies": {
54
- "@vitest/browser": "^3.2.4",
55
- "@vitest/coverage-istanbul": "^3.2.4",
56
+ "@vitest/browser": "^4.1.0",
57
+ "@vitest/coverage-istanbul": "^4.1.0",
56
58
  "happy-dom": "^12.10.3",
57
59
  "msw": "^2.10.5",
58
- "vitest": "^3.2.4",
60
+ "vitest": "^4.1.0",
59
61
  "@seayoo-web/utils": "^4.4.1"
60
62
  },
63
+ "engines": {
64
+ "node": ">=22"
65
+ },
61
66
  "scripts": {
62
67
  "prebuild": "pnpm --F utils build",
63
68
  "build": "vite build && tsc --emitDeclarationOnly",
64
69
  "type-check": "tsc --noEmit",
65
- "lint": "eslint ./src/**/*.ts",
66
- "lint:fix": "eslint \"./src/**/*.{ts,js}\" --fix",
70
+ "lint": "oxlint -c ../../oxlint.config.mjs",
71
+ "lint:fix": "oxlint -c ../../oxlint.config.mjs --fix",
67
72
  "prepublish": "pnpm lint:fix && pnpm build",
68
73
  "test": "vitest --typecheck --dom",
69
74
  "coverage": "vitest run --coverage"
@@ -0,0 +1,5 @@
1
+ import type { NetRequestAgent } from "./type";
2
+ /**
3
+ * 基于 uni.request 的网络请求包装函数,该方法必定 resolve,限制在 uniapp 环境中使用
4
+ */
5
+ export declare const uniRequest: NetRequestAgent;
package/types/index.d.ts CHANGED
@@ -26,60 +26,60 @@ export declare const setGlobalConfig: (config: RequestGlobalConfig) => void;
26
26
  export declare const request: {
27
27
  (op: {
28
28
  url: string;
29
- options?: import("./inc/type").RequestOptions;
30
- }): Promise<import("./inc/type").ResponseResult<unknown>>;
29
+ options?: import(".").RequestOptions;
30
+ }): Promise<import(".").ResponseResult<unknown>>;
31
31
  <T>(op: {
32
32
  url: string;
33
- options?: import("./inc/type").RequestOptions;
33
+ options?: import(".").RequestOptions;
34
34
  guard: import("./inc/type").DataGuard<T>;
35
- }): Promise<import("./inc/type").ResponseResult<T>>;
35
+ }): Promise<import(".").ResponseResult<T>>;
36
36
  };
37
37
  /**
38
38
  * 发送一个 HEAD 请求
39
39
  */
40
- export declare const head: (url: string, params?: import("./inc/type").RequestQueryParams | null, options?: Omit<import("./inc/type").RequestOptions, "asBuffer">) => import("./inc/type").ResponseWithoutType;
40
+ export declare const head: (url: string, params?: import(".").RequestQueryParams | null, options?: Omit<import(".").RequestOptions, "asBuffer">) => import("./inc/type").ResponseWithoutType;
41
41
  /**
42
42
  * 发送一个 GET 请求,请求自带 500ms 缓冲控制以应对并发场景,可选 typeGuard 用于检查数据类型
43
43
  */
44
44
  export declare const get: {
45
- (url: string, params?: import("./inc/type").RequestQueryParams): import("./inc/type").ResponseWithoutType;
46
- (url: string, params: import("./inc/type").RequestQueryParams | null, guard: null, options: import("./inc/main").BufferRequestOptions): import("./inc/type").ResponseWithType<ArrayBuffer>;
47
- (url: string, params: import("./inc/type").RequestQueryParams | null, guard: null, options?: import("./inc/type").RequestOptions): import("./inc/type").ResponseWithoutType;
48
- <T>(url: string, params: import("./inc/type").RequestQueryParams | null, guard: import("./inc/type").DataGuard<T>, options?: import("./inc/type").RequestOptions): import("./inc/type").ResponseWithType<T>;
45
+ (url: string, params?: import(".").RequestQueryParams): import("./inc/type").ResponseWithoutType;
46
+ (url: string, params: import(".").RequestQueryParams | null, guard: null, options: import(".").BufferRequestOptions): import("./inc/type").ResponseWithType<ArrayBuffer>;
47
+ (url: string, params: import(".").RequestQueryParams | null, guard: null, options?: import(".").RequestOptions): import("./inc/type").ResponseWithoutType;
48
+ <T>(url: string, params: import(".").RequestQueryParams | null, guard: import("./inc/type").DataGuard<T>, options?: import(".").RequestOptions): import("./inc/type").ResponseWithType<T>;
49
49
  };
50
50
  /**
51
51
  * 发送一个 POST 请求,可选 typeGuard 用于检查数据类型
52
52
  */
53
53
  export declare const post: {
54
- (url: import("./inc/main").URLPlus, data?: string | object | unknown[] | ArrayBuffer | Blob | FormData | URLSearchParams): import("./inc/type").ResponseWithoutType;
55
- (url: import("./inc/main").URLPlus, body: string | object | unknown[] | ArrayBuffer | Blob | FormData | URLSearchParams, guard: null, options: import("./inc/main").BufferRequestOptions): import("./inc/type").ResponseWithType<ArrayBuffer>;
56
- (url: import("./inc/main").URLPlus, body: string | object | unknown[] | ArrayBuffer | Blob | FormData | URLSearchParams, guard: null, options?: import("./inc/type").RequestOptions): import("./inc/type").ResponseWithoutType;
57
- <T>(url: import("./inc/main").URLPlus, body: string | object | unknown[] | ArrayBuffer | Blob | FormData | URLSearchParams, guard: import("./inc/type").DataGuard<T>, options?: import("./inc/type").RequestOptions): import("./inc/type").ResponseWithType<T>;
54
+ (url: import(".").URLPlus, data?: string | object | unknown[] | ArrayBuffer | Blob | FormData | URLSearchParams): import("./inc/type").ResponseWithoutType;
55
+ (url: import(".").URLPlus, body: string | object | unknown[] | ArrayBuffer | Blob | FormData | URLSearchParams, guard: null, options: import(".").BufferRequestOptions): import("./inc/type").ResponseWithType<ArrayBuffer>;
56
+ (url: import(".").URLPlus, body: string | object | unknown[] | ArrayBuffer | Blob | FormData | URLSearchParams, guard: null, options?: import(".").RequestOptions): import("./inc/type").ResponseWithoutType;
57
+ <T>(url: import(".").URLPlus, body: string | object | unknown[] | ArrayBuffer | Blob | FormData | URLSearchParams, guard: import("./inc/type").DataGuard<T>, options?: import(".").RequestOptions): import("./inc/type").ResponseWithType<T>;
58
58
  };
59
59
  /**
60
60
  * 发送一个 DELETE 请求,可选 typeGuard 用于检查数据类型
61
61
  */
62
62
  export declare const del: {
63
- (url: string, params?: import("./inc/type").RequestQueryParams): import("./inc/type").ResponseWithoutType;
64
- (url: string, params: import("./inc/type").RequestQueryParams | null, guard: null, options: import("./inc/main").BufferRequestOptions): import("./inc/type").ResponseWithType<ArrayBuffer>;
65
- (url: string, params: import("./inc/type").RequestQueryParams | null, guard: null, options?: import("./inc/type").RequestOptions): import("./inc/type").ResponseWithoutType;
66
- <T>(url: string, params: import("./inc/type").RequestQueryParams | null, guard: import("./inc/type").DataGuard<T>, options?: import("./inc/type").RequestOptions): import("./inc/type").ResponseWithType<T>;
63
+ (url: string, params?: import(".").RequestQueryParams): import("./inc/type").ResponseWithoutType;
64
+ (url: string, params: import(".").RequestQueryParams | null, guard: null, options: import(".").BufferRequestOptions): import("./inc/type").ResponseWithType<ArrayBuffer>;
65
+ (url: string, params: import(".").RequestQueryParams | null, guard: null, options?: import(".").RequestOptions): import("./inc/type").ResponseWithoutType;
66
+ <T>(url: string, params: import(".").RequestQueryParams | null, guard: import("./inc/type").DataGuard<T>, options?: import(".").RequestOptions): import("./inc/type").ResponseWithType<T>;
67
67
  };
68
68
  /**
69
69
  * 发送一个 PUT 请求,可选 typeGuard 用于检查数据类型
70
70
  */
71
71
  export declare const put: {
72
- (url: import("./inc/main").URLPlus, body?: string | object | unknown[] | ArrayBuffer | Blob | FormData | URLSearchParams): import("./inc/type").ResponseWithoutType;
73
- (url: import("./inc/main").URLPlus, body: string | object | unknown[] | ArrayBuffer | Blob | FormData | URLSearchParams, guard: null, options: import("./inc/main").BufferRequestOptions): import("./inc/type").ResponseWithType<ArrayBuffer>;
74
- (url: import("./inc/main").URLPlus, body: string | object | unknown[] | ArrayBuffer | Blob | FormData | URLSearchParams, guard: null, options?: import("./inc/type").RequestOptions): import("./inc/type").ResponseWithoutType;
75
- <T>(url: import("./inc/main").URLPlus, body: string | object | unknown[] | ArrayBuffer | Blob | FormData | URLSearchParams, guard: import("./inc/type").DataGuard<T>, options?: import("./inc/type").RequestOptions): import("./inc/type").ResponseWithType<T>;
72
+ (url: import(".").URLPlus, body?: string | object | unknown[] | ArrayBuffer | Blob | FormData | URLSearchParams): import("./inc/type").ResponseWithoutType;
73
+ (url: import(".").URLPlus, body: string | object | unknown[] | ArrayBuffer | Blob | FormData | URLSearchParams, guard: null, options: import(".").BufferRequestOptions): import("./inc/type").ResponseWithType<ArrayBuffer>;
74
+ (url: import(".").URLPlus, body: string | object | unknown[] | ArrayBuffer | Blob | FormData | URLSearchParams, guard: null, options?: import(".").RequestOptions): import("./inc/type").ResponseWithoutType;
75
+ <T>(url: import(".").URLPlus, body: string | object | unknown[] | ArrayBuffer | Blob | FormData | URLSearchParams, guard: import("./inc/type").DataGuard<T>, options?: import(".").RequestOptions): import("./inc/type").ResponseWithType<T>;
76
76
  };
77
77
  /**
78
78
  * 发送一个 PATCH 请求,可选 typeGuard 用于检查数据类型
79
79
  */
80
80
  export declare const patch: {
81
- (url: import("./inc/main").URLPlus, data?: string | object | unknown[] | ArrayBuffer | Blob | FormData | URLSearchParams): import("./inc/type").ResponseWithoutType;
82
- (url: import("./inc/main").URLPlus, body: string | object | unknown[] | ArrayBuffer | Blob | FormData | URLSearchParams, guard: null, options: import("./inc/main").BufferRequestOptions): import("./inc/type").ResponseWithType<ArrayBuffer>;
83
- (url: import("./inc/main").URLPlus, body: string | object | unknown[] | ArrayBuffer | Blob | FormData | URLSearchParams, guard: null, options?: import("./inc/type").RequestOptions): import("./inc/type").ResponseWithoutType;
84
- <T>(url: import("./inc/main").URLPlus, body: string | object | unknown[] | ArrayBuffer | Blob | FormData | URLSearchParams, guard: import("./inc/type").DataGuard<T>, options?: import("./inc/type").RequestOptions): import("./inc/type").ResponseWithType<T>;
81
+ (url: import(".").URLPlus, data?: string | object | unknown[] | ArrayBuffer | Blob | FormData | URLSearchParams): import("./inc/type").ResponseWithoutType;
82
+ (url: import(".").URLPlus, body: string | object | unknown[] | ArrayBuffer | Blob | FormData | URLSearchParams, guard: null, options: import(".").BufferRequestOptions): import("./inc/type").ResponseWithType<ArrayBuffer>;
83
+ (url: import(".").URLPlus, body: string | object | unknown[] | ArrayBuffer | Blob | FormData | URLSearchParams, guard: null, options?: import(".").RequestOptions): import("./inc/type").ResponseWithoutType;
84
+ <T>(url: import(".").URLPlus, body: string | object | unknown[] | ArrayBuffer | Blob | FormData | URLSearchParams, guard: import("./inc/type").DataGuard<T>, options?: import(".").RequestOptions): import("./inc/type").ResponseWithType<T>;
85
85
  };
package/types/node.d.ts CHANGED
@@ -15,49 +15,49 @@ export declare const setGlobalConfig: (config: RequestGlobalConfig) => void;
15
15
  /**
16
16
  * 发送一个 HEAD 请求
17
17
  */
18
- export declare const head: (url: string, params?: import("./inc/type").RequestQueryParams | null, options?: Omit<import("./inc/type").RequestOptions, "asBuffer">) => import("./inc/type").ResponseWithoutType;
18
+ export declare const head: (url: string, params?: import(".").RequestQueryParams | null, options?: Omit<import(".").RequestOptions, "asBuffer">) => import("./inc/type").ResponseWithoutType;
19
19
  /**
20
20
  * 发送一个 GET 请求,请求自带 500ms 缓冲控制以应对并发场景,可选 typeGuard 用于检查数据类型
21
21
  */
22
22
  export declare const get: {
23
- (url: string, params?: import("./inc/type").RequestQueryParams): import("./inc/type").ResponseWithoutType;
24
- (url: string, params: import("./inc/type").RequestQueryParams | null, guard: null, options: import("./inc/main").BufferRequestOptions): import("./inc/type").ResponseWithType<ArrayBuffer>;
25
- (url: string, params: import("./inc/type").RequestQueryParams | null, guard: null, options?: import("./inc/type").RequestOptions): import("./inc/type").ResponseWithoutType;
26
- <T>(url: string, params: import("./inc/type").RequestQueryParams | null, guard: import("./inc/type").DataGuard<T>, options?: import("./inc/type").RequestOptions): import("./inc/type").ResponseWithType<T>;
23
+ (url: string, params?: import(".").RequestQueryParams): import("./inc/type").ResponseWithoutType;
24
+ (url: string, params: import(".").RequestQueryParams | null, guard: null, options: import(".").BufferRequestOptions): import("./inc/type").ResponseWithType<ArrayBuffer>;
25
+ (url: string, params: import(".").RequestQueryParams | null, guard: null, options?: import(".").RequestOptions): import("./inc/type").ResponseWithoutType;
26
+ <T>(url: string, params: import(".").RequestQueryParams | null, guard: import("./inc/type").DataGuard<T>, options?: import(".").RequestOptions): import("./inc/type").ResponseWithType<T>;
27
27
  };
28
28
  /**
29
29
  * 发送一个 POST 请求,可选 typeGuard 用于检查数据类型
30
30
  */
31
31
  export declare const post: {
32
- (url: import("./inc/main").URLPlus, data?: string | object | unknown[] | ArrayBuffer | Blob | FormData | URLSearchParams): import("./inc/type").ResponseWithoutType;
33
- (url: import("./inc/main").URLPlus, body: string | object | unknown[] | ArrayBuffer | Blob | FormData | URLSearchParams, guard: null, options: import("./inc/main").BufferRequestOptions): import("./inc/type").ResponseWithType<ArrayBuffer>;
34
- (url: import("./inc/main").URLPlus, body: string | object | unknown[] | ArrayBuffer | Blob | FormData | URLSearchParams, guard: null, options?: import("./inc/type").RequestOptions): import("./inc/type").ResponseWithoutType;
35
- <T>(url: import("./inc/main").URLPlus, body: string | object | unknown[] | ArrayBuffer | Blob | FormData | URLSearchParams, guard: import("./inc/type").DataGuard<T>, options?: import("./inc/type").RequestOptions): import("./inc/type").ResponseWithType<T>;
32
+ (url: import(".").URLPlus, data?: string | object | unknown[] | ArrayBuffer | Blob | FormData | URLSearchParams): import("./inc/type").ResponseWithoutType;
33
+ (url: import(".").URLPlus, body: string | object | unknown[] | ArrayBuffer | Blob | FormData | URLSearchParams, guard: null, options: import(".").BufferRequestOptions): import("./inc/type").ResponseWithType<ArrayBuffer>;
34
+ (url: import(".").URLPlus, body: string | object | unknown[] | ArrayBuffer | Blob | FormData | URLSearchParams, guard: null, options?: import(".").RequestOptions): import("./inc/type").ResponseWithoutType;
35
+ <T>(url: import(".").URLPlus, body: string | object | unknown[] | ArrayBuffer | Blob | FormData | URLSearchParams, guard: import("./inc/type").DataGuard<T>, options?: import(".").RequestOptions): import("./inc/type").ResponseWithType<T>;
36
36
  };
37
37
  /**
38
38
  * 发送一个 DELETE 请求,可选 typeGuard 用于检查数据类型
39
39
  */
40
40
  export declare const del: {
41
- (url: string, params?: import("./inc/type").RequestQueryParams): import("./inc/type").ResponseWithoutType;
42
- (url: string, params: import("./inc/type").RequestQueryParams | null, guard: null, options: import("./inc/main").BufferRequestOptions): import("./inc/type").ResponseWithType<ArrayBuffer>;
43
- (url: string, params: import("./inc/type").RequestQueryParams | null, guard: null, options?: import("./inc/type").RequestOptions): import("./inc/type").ResponseWithoutType;
44
- <T>(url: string, params: import("./inc/type").RequestQueryParams | null, guard: import("./inc/type").DataGuard<T>, options?: import("./inc/type").RequestOptions): import("./inc/type").ResponseWithType<T>;
41
+ (url: string, params?: import(".").RequestQueryParams): import("./inc/type").ResponseWithoutType;
42
+ (url: string, params: import(".").RequestQueryParams | null, guard: null, options: import(".").BufferRequestOptions): import("./inc/type").ResponseWithType<ArrayBuffer>;
43
+ (url: string, params: import(".").RequestQueryParams | null, guard: null, options?: import(".").RequestOptions): import("./inc/type").ResponseWithoutType;
44
+ <T>(url: string, params: import(".").RequestQueryParams | null, guard: import("./inc/type").DataGuard<T>, options?: import(".").RequestOptions): import("./inc/type").ResponseWithType<T>;
45
45
  };
46
46
  /**
47
47
  * 发送一个 PUT 请求,可选 typeGuard 用于检查数据类型
48
48
  */
49
49
  export declare const put: {
50
- (url: import("./inc/main").URLPlus, body?: string | object | unknown[] | ArrayBuffer | Blob | FormData | URLSearchParams): import("./inc/type").ResponseWithoutType;
51
- (url: import("./inc/main").URLPlus, body: string | object | unknown[] | ArrayBuffer | Blob | FormData | URLSearchParams, guard: null, options: import("./inc/main").BufferRequestOptions): import("./inc/type").ResponseWithType<ArrayBuffer>;
52
- (url: import("./inc/main").URLPlus, body: string | object | unknown[] | ArrayBuffer | Blob | FormData | URLSearchParams, guard: null, options?: import("./inc/type").RequestOptions): import("./inc/type").ResponseWithoutType;
53
- <T>(url: import("./inc/main").URLPlus, body: string | object | unknown[] | ArrayBuffer | Blob | FormData | URLSearchParams, guard: import("./inc/type").DataGuard<T>, options?: import("./inc/type").RequestOptions): import("./inc/type").ResponseWithType<T>;
50
+ (url: import(".").URLPlus, body?: string | object | unknown[] | ArrayBuffer | Blob | FormData | URLSearchParams): import("./inc/type").ResponseWithoutType;
51
+ (url: import(".").URLPlus, body: string | object | unknown[] | ArrayBuffer | Blob | FormData | URLSearchParams, guard: null, options: import(".").BufferRequestOptions): import("./inc/type").ResponseWithType<ArrayBuffer>;
52
+ (url: import(".").URLPlus, body: string | object | unknown[] | ArrayBuffer | Blob | FormData | URLSearchParams, guard: null, options?: import(".").RequestOptions): import("./inc/type").ResponseWithoutType;
53
+ <T>(url: import(".").URLPlus, body: string | object | unknown[] | ArrayBuffer | Blob | FormData | URLSearchParams, guard: import("./inc/type").DataGuard<T>, options?: import(".").RequestOptions): import("./inc/type").ResponseWithType<T>;
54
54
  };
55
55
  /**
56
56
  * 发送一个 PATCH 请求,可选 typeGuard 用于检查数据类型
57
57
  */
58
58
  export declare const patch: {
59
- (url: import("./inc/main").URLPlus, data?: string | object | unknown[] | ArrayBuffer | Blob | FormData | URLSearchParams): import("./inc/type").ResponseWithoutType;
60
- (url: import("./inc/main").URLPlus, body: string | object | unknown[] | ArrayBuffer | Blob | FormData | URLSearchParams, guard: null, options: import("./inc/main").BufferRequestOptions): import("./inc/type").ResponseWithType<ArrayBuffer>;
61
- (url: import("./inc/main").URLPlus, body: string | object | unknown[] | ArrayBuffer | Blob | FormData | URLSearchParams, guard: null, options?: import("./inc/type").RequestOptions): import("./inc/type").ResponseWithoutType;
62
- <T>(url: import("./inc/main").URLPlus, body: string | object | unknown[] | ArrayBuffer | Blob | FormData | URLSearchParams, guard: import("./inc/type").DataGuard<T>, options?: import("./inc/type").RequestOptions): import("./inc/type").ResponseWithType<T>;
59
+ (url: import(".").URLPlus, data?: string | object | unknown[] | ArrayBuffer | Blob | FormData | URLSearchParams): import("./inc/type").ResponseWithoutType;
60
+ (url: import(".").URLPlus, body: string | object | unknown[] | ArrayBuffer | Blob | FormData | URLSearchParams, guard: null, options: import(".").BufferRequestOptions): import("./inc/type").ResponseWithType<ArrayBuffer>;
61
+ (url: import(".").URLPlus, body: string | object | unknown[] | ArrayBuffer | Blob | FormData | URLSearchParams, guard: null, options?: import(".").RequestOptions): import("./inc/type").ResponseWithoutType;
62
+ <T>(url: import(".").URLPlus, body: string | object | unknown[] | ArrayBuffer | Blob | FormData | URLSearchParams, guard: import("./inc/type").DataGuard<T>, options?: import(".").RequestOptions): import("./inc/type").ResponseWithType<T>;
63
63
  };
package/types/uni.d.ts ADDED
@@ -0,0 +1,60 @@
1
+ import { INetRequestHandler } from "./inc/main";
2
+ import type { RequestGlobalConfig } from "./inc/type";
3
+ export { getResponseRulesDescription } from "./inc/rule";
4
+ export { RequestInternalError } from "./inc/type";
5
+ export type { NetRequestHandler, INetRequestHandler, URLPlus, BufferRequestOptions } from "./inc/main";
6
+ export type { RequestOptions, RequestGlobalConfig, ResponseRule, ResponseResult, RequestLog, RequestMethod, RequestQueryParams, } from "./inc/type";
7
+ /**
8
+ * 创建新的实例空间,配置和缓存跟全局默认实例是隔离的
9
+ */
10
+ export declare function NetRequest(config?: RequestGlobalConfig): INetRequestHandler;
11
+ /**
12
+ * 设置全局默认的 Request Config
13
+ */
14
+ export declare const setGlobalConfig: (config: RequestGlobalConfig) => void;
15
+ /**
16
+ * 发送一个 HEAD 请求
17
+ *
18
+ * 支持环境:微信小程序、百度小程序
19
+ */
20
+ export declare const head: (url: string, params?: import(".").RequestQueryParams | null, options?: Omit<import(".").RequestOptions, "asBuffer">) => import("./inc/type").ResponseWithoutType;
21
+ /**
22
+ * 发送一个 GET 请求,请求自带 500ms 缓冲控制以应对并发场景,可选 typeGuard 用于检查数据类型
23
+ */
24
+ export declare const get: {
25
+ (url: string, params?: import(".").RequestQueryParams): import("./inc/type").ResponseWithoutType;
26
+ (url: string, params: import(".").RequestQueryParams | null, guard: null, options: import(".").BufferRequestOptions): import("./inc/type").ResponseWithType<ArrayBuffer>;
27
+ (url: string, params: import(".").RequestQueryParams | null, guard: null, options?: import(".").RequestOptions): import("./inc/type").ResponseWithoutType;
28
+ <T>(url: string, params: import(".").RequestQueryParams | null, guard: import("./inc/type").DataGuard<T>, options?: import(".").RequestOptions): import("./inc/type").ResponseWithType<T>;
29
+ };
30
+ /**
31
+ * 发送一个 POST 请求,可选 typeGuard 用于检查数据类型
32
+ */
33
+ export declare const post: {
34
+ (url: import(".").URLPlus, data?: string | object | unknown[] | ArrayBuffer | Blob | FormData | URLSearchParams): import("./inc/type").ResponseWithoutType;
35
+ (url: import(".").URLPlus, body: string | object | unknown[] | ArrayBuffer | Blob | FormData | URLSearchParams, guard: null, options: import(".").BufferRequestOptions): import("./inc/type").ResponseWithType<ArrayBuffer>;
36
+ (url: import(".").URLPlus, body: string | object | unknown[] | ArrayBuffer | Blob | FormData | URLSearchParams, guard: null, options?: import(".").RequestOptions): import("./inc/type").ResponseWithoutType;
37
+ <T>(url: import(".").URLPlus, body: string | object | unknown[] | ArrayBuffer | Blob | FormData | URLSearchParams, guard: import("./inc/type").DataGuard<T>, options?: import(".").RequestOptions): import("./inc/type").ResponseWithType<T>;
38
+ };
39
+ /**
40
+ * 发送一个 DELETE 请求,可选 typeGuard 用于检查数据类型
41
+ *
42
+ * 支持环境:微信小程序、百度小程序
43
+ */
44
+ export declare const del: {
45
+ (url: string, params?: import(".").RequestQueryParams): import("./inc/type").ResponseWithoutType;
46
+ (url: string, params: import(".").RequestQueryParams | null, guard: null, options: import(".").BufferRequestOptions): import("./inc/type").ResponseWithType<ArrayBuffer>;
47
+ (url: string, params: import(".").RequestQueryParams | null, guard: null, options?: import(".").RequestOptions): import("./inc/type").ResponseWithoutType;
48
+ <T>(url: string, params: import(".").RequestQueryParams | null, guard: import("./inc/type").DataGuard<T>, options?: import(".").RequestOptions): import("./inc/type").ResponseWithType<T>;
49
+ };
50
+ /**
51
+ * 发送一个 PUT 请求,可选 typeGuard 用于检查数据类型
52
+ *
53
+ * 支持环境:微信小程序、百度小程序、抖音小程序、飞书小程序
54
+ */
55
+ export declare const put: {
56
+ (url: import(".").URLPlus, body?: string | object | unknown[] | ArrayBuffer | Blob | FormData | URLSearchParams): import("./inc/type").ResponseWithoutType;
57
+ (url: import(".").URLPlus, body: string | object | unknown[] | ArrayBuffer | Blob | FormData | URLSearchParams, guard: null, options: import(".").BufferRequestOptions): import("./inc/type").ResponseWithType<ArrayBuffer>;
58
+ (url: import(".").URLPlus, body: string | object | unknown[] | ArrayBuffer | Blob | FormData | URLSearchParams, guard: null, options?: import(".").RequestOptions): import("./inc/type").ResponseWithoutType;
59
+ <T>(url: import(".").URLPlus, body: string | object | unknown[] | ArrayBuffer | Blob | FormData | URLSearchParams, guard: import("./inc/type").DataGuard<T>, options?: import(".").RequestOptions): import("./inc/type").ResponseWithType<T>;
60
+ };
package/types/wx.d.ts CHANGED
@@ -15,40 +15,40 @@ export declare const setGlobalConfig: (config: RequestGlobalConfig) => void;
15
15
  /**
16
16
  * 发送一个 HEAD 请求
17
17
  */
18
- export declare const head: (url: string, params?: import("./inc/type").RequestQueryParams | null, options?: Omit<import("./inc/type").RequestOptions, "asBuffer">) => import("./inc/type").ResponseWithoutType;
18
+ export declare const head: (url: string, params?: import(".").RequestQueryParams | null, options?: Omit<import(".").RequestOptions, "asBuffer">) => import("./inc/type").ResponseWithoutType;
19
19
  /**
20
20
  * 发送一个 GET 请求,请求自带 500ms 缓冲控制以应对并发场景,可选 typeGuard 用于检查数据类型
21
21
  */
22
22
  export declare const get: {
23
- (url: string, params?: import("./inc/type").RequestQueryParams): import("./inc/type").ResponseWithoutType;
24
- (url: string, params: import("./inc/type").RequestQueryParams | null, guard: null, options: import("./inc/main").BufferRequestOptions): import("./inc/type").ResponseWithType<ArrayBuffer>;
25
- (url: string, params: import("./inc/type").RequestQueryParams | null, guard: null, options?: import("./inc/type").RequestOptions): import("./inc/type").ResponseWithoutType;
26
- <T>(url: string, params: import("./inc/type").RequestQueryParams | null, guard: import("./inc/type").DataGuard<T>, options?: import("./inc/type").RequestOptions): import("./inc/type").ResponseWithType<T>;
23
+ (url: string, params?: import(".").RequestQueryParams): import("./inc/type").ResponseWithoutType;
24
+ (url: string, params: import(".").RequestQueryParams | null, guard: null, options: import(".").BufferRequestOptions): import("./inc/type").ResponseWithType<ArrayBuffer>;
25
+ (url: string, params: import(".").RequestQueryParams | null, guard: null, options?: import(".").RequestOptions): import("./inc/type").ResponseWithoutType;
26
+ <T>(url: string, params: import(".").RequestQueryParams | null, guard: import("./inc/type").DataGuard<T>, options?: import(".").RequestOptions): import("./inc/type").ResponseWithType<T>;
27
27
  };
28
28
  /**
29
29
  * 发送一个 POST 请求,可选 typeGuard 用于检查数据类型
30
30
  */
31
31
  export declare const post: {
32
- (url: import("./inc/main").URLPlus, data?: string | object | unknown[] | ArrayBuffer | Blob | FormData | URLSearchParams): import("./inc/type").ResponseWithoutType;
33
- (url: import("./inc/main").URLPlus, body: string | object | unknown[] | ArrayBuffer | Blob | FormData | URLSearchParams, guard: null, options: import("./inc/main").BufferRequestOptions): import("./inc/type").ResponseWithType<ArrayBuffer>;
34
- (url: import("./inc/main").URLPlus, body: string | object | unknown[] | ArrayBuffer | Blob | FormData | URLSearchParams, guard: null, options?: import("./inc/type").RequestOptions): import("./inc/type").ResponseWithoutType;
35
- <T>(url: import("./inc/main").URLPlus, body: string | object | unknown[] | ArrayBuffer | Blob | FormData | URLSearchParams, guard: import("./inc/type").DataGuard<T>, options?: import("./inc/type").RequestOptions): import("./inc/type").ResponseWithType<T>;
32
+ (url: import(".").URLPlus, data?: string | object | unknown[] | ArrayBuffer | Blob | FormData | URLSearchParams): import("./inc/type").ResponseWithoutType;
33
+ (url: import(".").URLPlus, body: string | object | unknown[] | ArrayBuffer | Blob | FormData | URLSearchParams, guard: null, options: import(".").BufferRequestOptions): import("./inc/type").ResponseWithType<ArrayBuffer>;
34
+ (url: import(".").URLPlus, body: string | object | unknown[] | ArrayBuffer | Blob | FormData | URLSearchParams, guard: null, options?: import(".").RequestOptions): import("./inc/type").ResponseWithoutType;
35
+ <T>(url: import(".").URLPlus, body: string | object | unknown[] | ArrayBuffer | Blob | FormData | URLSearchParams, guard: import("./inc/type").DataGuard<T>, options?: import(".").RequestOptions): import("./inc/type").ResponseWithType<T>;
36
36
  };
37
37
  /**
38
38
  * 发送一个 DELETE 请求,可选 typeGuard 用于检查数据类型
39
39
  */
40
40
  export declare const del: {
41
- (url: string, params?: import("./inc/type").RequestQueryParams): import("./inc/type").ResponseWithoutType;
42
- (url: string, params: import("./inc/type").RequestQueryParams | null, guard: null, options: import("./inc/main").BufferRequestOptions): import("./inc/type").ResponseWithType<ArrayBuffer>;
43
- (url: string, params: import("./inc/type").RequestQueryParams | null, guard: null, options?: import("./inc/type").RequestOptions): import("./inc/type").ResponseWithoutType;
44
- <T>(url: string, params: import("./inc/type").RequestQueryParams | null, guard: import("./inc/type").DataGuard<T>, options?: import("./inc/type").RequestOptions): import("./inc/type").ResponseWithType<T>;
41
+ (url: string, params?: import(".").RequestQueryParams): import("./inc/type").ResponseWithoutType;
42
+ (url: string, params: import(".").RequestQueryParams | null, guard: null, options: import(".").BufferRequestOptions): import("./inc/type").ResponseWithType<ArrayBuffer>;
43
+ (url: string, params: import(".").RequestQueryParams | null, guard: null, options?: import(".").RequestOptions): import("./inc/type").ResponseWithoutType;
44
+ <T>(url: string, params: import(".").RequestQueryParams | null, guard: import("./inc/type").DataGuard<T>, options?: import(".").RequestOptions): import("./inc/type").ResponseWithType<T>;
45
45
  };
46
46
  /**
47
47
  * 发送一个 PUT 请求,可选 typeGuard 用于检查数据类型
48
48
  */
49
49
  export declare const put: {
50
- (url: import("./inc/main").URLPlus, body?: string | object | unknown[] | ArrayBuffer | Blob | FormData | URLSearchParams): import("./inc/type").ResponseWithoutType;
51
- (url: import("./inc/main").URLPlus, body: string | object | unknown[] | ArrayBuffer | Blob | FormData | URLSearchParams, guard: null, options: import("./inc/main").BufferRequestOptions): import("./inc/type").ResponseWithType<ArrayBuffer>;
52
- (url: import("./inc/main").URLPlus, body: string | object | unknown[] | ArrayBuffer | Blob | FormData | URLSearchParams, guard: null, options?: import("./inc/type").RequestOptions): import("./inc/type").ResponseWithoutType;
53
- <T>(url: import("./inc/main").URLPlus, body: string | object | unknown[] | ArrayBuffer | Blob | FormData | URLSearchParams, guard: import("./inc/type").DataGuard<T>, options?: import("./inc/type").RequestOptions): import("./inc/type").ResponseWithType<T>;
50
+ (url: import(".").URLPlus, body?: string | object | unknown[] | ArrayBuffer | Blob | FormData | URLSearchParams): import("./inc/type").ResponseWithoutType;
51
+ (url: import(".").URLPlus, body: string | object | unknown[] | ArrayBuffer | Blob | FormData | URLSearchParams, guard: null, options: import(".").BufferRequestOptions): import("./inc/type").ResponseWithType<ArrayBuffer>;
52
+ (url: import(".").URLPlus, body: string | object | unknown[] | ArrayBuffer | Blob | FormData | URLSearchParams, guard: null, options?: import(".").RequestOptions): import("./inc/type").ResponseWithoutType;
53
+ <T>(url: import(".").URLPlus, body: string | object | unknown[] | ArrayBuffer | Blob | FormData | URLSearchParams, guard: import("./inc/type").DataGuard<T>, options?: import(".").RequestOptions): import("./inc/type").ResponseWithType<T>;
54
54
  };
@@ -1,54 +0,0 @@
1
- import { h as f, r as h, c as m, i as b, f as y, e as T, R as u } from "./retry-LYfsjIVg.js";
2
- const x = async function(o, a, s) {
3
- return f(await h(w, o, a, s), o, a, s);
4
- }, w = async function(o, a, s) {
5
- const t = await m(o, a, s), r = b() ? new AbortController() : null;
6
- function n(e) {
7
- r && !r.signal.aborted && r.abort(e);
8
- }
9
- t.abort?.addEventListener("abort", n);
10
- let i = !1;
11
- const l = t.timeout > 0 ? setTimeout(function() {
12
- i = !0, n("TimeoutTriggered");
13
- }, t.timeout) : null;
14
- return await fetch(t.url, {
15
- method: t.method,
16
- headers: Object.keys(t.headers).length > 0 ? new Headers(t.headers) : void 0,
17
- body: t.body,
18
- credentials: t.credentials,
19
- signal: r?.signal,
20
- redirect: "follow"
21
- }).then(
22
- async (e) => y(
23
- {
24
- url: t.url,
25
- method: t.method,
26
- status: e.status,
27
- statusText: e.statusText,
28
- headers: T([...e.headers.entries()]),
29
- body: null
30
- },
31
- {
32
- asBuffer: t.asBuffer,
33
- text: () => e.text(),
34
- buffer: () => e.arrayBuffer()
35
- }
36
- )
37
- ).catch((e) => {
38
- const c = r?.signal.aborted, d = i ? u.Timeout : c ? u.Aborted : u.NetworkError;
39
- return {
40
- url: t.url,
41
- method: t.method,
42
- status: -1,
43
- error: d,
44
- statusText: d,
45
- body: null,
46
- rawError: e
47
- };
48
- }).finally(() => {
49
- l !== null && clearTimeout(l), t.abort && t.abort.removeEventListener("abort", n);
50
- });
51
- };
52
- export {
53
- x as f
54
- };