@kevisual/query 0.0.27 → 0.0.29

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.
@@ -7,6 +7,7 @@ type AdapterOpts = {
7
7
  timeout?: number;
8
8
  method?: Method;
9
9
  isBlob?: boolean;
10
+ isText?: boolean;
10
11
  isPostFile?: boolean;
11
12
  };
12
13
  declare const isTextForContentType: (contentType: string | null) => boolean;
@@ -15,6 +15,7 @@ const adapter = async (opts = {}, overloadOpts) => {
15
15
  const controller = new AbortController();
16
16
  const signal = controller.signal;
17
17
  const isBlob = opts.isBlob || false; // 是否返回 Blob 对象
18
+ const isText = opts.isText || false; // 是否返回文本内容
18
19
  const isPostFile = opts.isPostFile || false; // 是否为文件上传
19
20
  const timeout = opts.timeout || 60000 * 3; // 默认超时时间为 60s * 3
20
21
  const timer = setTimeout(() => {
@@ -64,7 +65,7 @@ const adapter = async (opts = {}, overloadOpts) => {
64
65
  }
65
66
  const isJson = contentType && contentType.includes('application/json');
66
67
  // 判断返回的数据类型
67
- if (isJson) {
68
+ if (isJson && !isText) {
68
69
  return await response.json(); // 解析为 JSON
69
70
  }
70
71
  else if (isTextForContentType(contentType)) {
@@ -9,6 +9,7 @@ type AdapterOpts = {
9
9
  timeout?: number;
10
10
  method?: Method;
11
11
  isBlob?: boolean;
12
+ isText?: boolean;
12
13
  isPostFile?: boolean;
13
14
  };
14
15
  /**
@@ -93,16 +94,9 @@ type Fn = (opts: {
93
94
  timeout?: number;
94
95
  }) => Promise<Record<string, any> | false>;
95
96
  type QueryOpts$1 = {
96
- url?: string;
97
- headers?: Record<string, string>;
98
- body?: Record<string, any> | FormData;
99
- timeout?: number;
100
- method?: Method;
101
- isBlob?: boolean;
102
- isPostFile?: boolean;
103
97
  adapter?: typeof adapter;
104
98
  [key: string]: any;
105
- };
99
+ } & AdapterOpts;
106
100
  type Data = {
107
101
  path?: string;
108
102
  key?: string;
@@ -133,6 +127,10 @@ type DataOpts = Partial<QueryOpts$1> & {
133
127
  res?: any;
134
128
  fetch?: any;
135
129
  }) => Promise<Result<S>>;
130
+ /**
131
+ * 是否在stop的时候不请求
132
+ */
133
+ noStop?: boolean;
136
134
  };
137
135
  declare const wrapperError: ({ code, message }: {
138
136
  code?: number;
@@ -14,6 +14,7 @@ const adapter = async (opts = {}, overloadOpts) => {
14
14
  const controller = new AbortController();
15
15
  const signal = controller.signal;
16
16
  const isBlob = opts.isBlob || false; // 是否返回 Blob 对象
17
+ const isText = opts.isText || false; // 是否返回文本内容
17
18
  const isPostFile = opts.isPostFile || false; // 是否为文件上传
18
19
  const timeout = opts.timeout || 60000 * 3; // 默认超时时间为 60s * 3
19
20
  const timer = setTimeout(() => {
@@ -63,7 +64,7 @@ const adapter = async (opts = {}, overloadOpts) => {
63
64
  }
64
65
  const isJson = contentType && contentType.includes('application/json');
65
66
  // 判断返回的数据类型
66
- if (isJson) {
67
+ if (isJson && !isText) {
67
68
  return await response.json(); // 解析为 JSON
68
69
  }
69
70
  else if (isTextForContentType(contentType)) {
@@ -430,7 +431,7 @@ class Query {
430
431
  code: 500,
431
432
  message: 'api request beforeFn error'});
432
433
  }
433
- if (this.stop) {
434
+ if (this.stop && !options?.noStop) {
434
435
  const that = this;
435
436
  await new Promise((resolve) => {
436
437
  let timer = 0;
package/dist/query.d.ts CHANGED
@@ -9,6 +9,7 @@ type AdapterOpts = {
9
9
  timeout?: number;
10
10
  method?: Method;
11
11
  isBlob?: boolean;
12
+ isText?: boolean;
12
13
  isPostFile?: boolean;
13
14
  };
14
15
  /**
@@ -93,16 +94,9 @@ type Fn = (opts: {
93
94
  timeout?: number;
94
95
  }) => Promise<Record<string, any> | false>;
95
96
  type QueryOpts = {
96
- url?: string;
97
- headers?: Record<string, string>;
98
- body?: Record<string, any> | FormData;
99
- timeout?: number;
100
- method?: Method;
101
- isBlob?: boolean;
102
- isPostFile?: boolean;
103
97
  adapter?: typeof adapter;
104
98
  [key: string]: any;
105
- };
99
+ } & AdapterOpts;
106
100
  type Data = {
107
101
  path?: string;
108
102
  key?: string;
@@ -133,6 +127,10 @@ type DataOpts = Partial<QueryOpts> & {
133
127
  res?: any;
134
128
  fetch?: any;
135
129
  }) => Promise<Result<S>>;
130
+ /**
131
+ * 是否在stop的时候不请求
132
+ */
133
+ noStop?: boolean;
136
134
  };
137
135
  /**
138
136
  * 设置基础响应, 设置 success 和 showError,
package/dist/query.js CHANGED
@@ -14,6 +14,7 @@ const adapter = async (opts = {}, overloadOpts) => {
14
14
  const controller = new AbortController();
15
15
  const signal = controller.signal;
16
16
  const isBlob = opts.isBlob || false; // 是否返回 Blob 对象
17
+ const isText = opts.isText || false; // 是否返回文本内容
17
18
  const isPostFile = opts.isPostFile || false; // 是否为文件上传
18
19
  const timeout = opts.timeout || 60000 * 3; // 默认超时时间为 60s * 3
19
20
  const timer = setTimeout(() => {
@@ -63,7 +64,7 @@ const adapter = async (opts = {}, overloadOpts) => {
63
64
  }
64
65
  const isJson = contentType && contentType.includes('application/json');
65
66
  // 判断返回的数据类型
66
- if (isJson) {
67
+ if (isJson && !isText) {
67
68
  return await response.json(); // 解析为 JSON
68
69
  }
69
70
  else if (isTextForContentType(contentType)) {
@@ -214,7 +215,7 @@ class Query {
214
215
  code: 500,
215
216
  message: 'api request beforeFn error'});
216
217
  }
217
- if (this.stop) {
218
+ if (this.stop && !options?.noStop) {
218
219
  const that = this;
219
220
  await new Promise((resolve) => {
220
221
  let timer = 0;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kevisual/query",
3
- "version": "0.0.27",
3
+ "version": "0.0.29",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.js",
6
6
  "types": "dist/index.d.ts",