@kevisual/query 0.0.23 → 0.0.25

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.
@@ -43,22 +43,22 @@ const adapter = async (opts, overloadOpts) => {
43
43
  ...overloadOpts,
44
44
  body: isGet ? undefined : JSON.stringify(opts.body),
45
45
  })
46
- .then((response) => {
46
+ .then(async (response) => {
47
47
  // 获取 Content-Type 头部信息
48
48
  const contentType = response.headers.get('Content-Type');
49
49
  if (isBlob) {
50
- return response.blob(); // 直接返回 Blob 对象
50
+ return await response.blob(); // 直接返回 Blob 对象
51
51
  }
52
52
  const isJson = contentType && contentType.includes('application/json');
53
53
  // 判断返回的数据类型
54
54
  if (isJson) {
55
- return response.json(); // 解析为 JSON
55
+ return await response.json(); // 解析为 JSON
56
56
  }
57
57
  else if (isTextForContentType(contentType)) {
58
58
  return {
59
59
  code: 200,
60
60
  status: response.status,
61
- data: response.text(), // 直接返回文本内容
61
+ data: await response.text(), // 直接返回文本内容
62
62
  };
63
63
  }
64
64
  else {
@@ -42,22 +42,22 @@ const adapter = async (opts, overloadOpts) => {
42
42
  ...overloadOpts,
43
43
  body: isGet ? undefined : JSON.stringify(opts.body),
44
44
  })
45
- .then((response) => {
45
+ .then(async (response) => {
46
46
  // 获取 Content-Type 头部信息
47
47
  const contentType = response.headers.get('Content-Type');
48
48
  if (isBlob) {
49
- return response.blob(); // 直接返回 Blob 对象
49
+ return await response.blob(); // 直接返回 Blob 对象
50
50
  }
51
51
  const isJson = contentType && contentType.includes('application/json');
52
52
  // 判断返回的数据类型
53
53
  if (isJson) {
54
- return response.json(); // 解析为 JSON
54
+ return await response.json(); // 解析为 JSON
55
55
  }
56
56
  else if (isTextForContentType(contentType)) {
57
57
  return {
58
58
  code: 200,
59
59
  status: response.status,
60
- data: response.text(), // 直接返回文本内容
60
+ data: await response.text(), // 直接返回文本内容
61
61
  };
62
62
  }
63
63
  else {
@@ -483,34 +483,7 @@ class Query {
483
483
  ...(_options?.headers || {}),
484
484
  },
485
485
  });
486
- if (res.status !== 200) {
487
- return wrapperError({
488
- code: res.status,
489
- message: `fetch error: ${res.statusText}`,
490
- });
491
- }
492
- const contentType = res.headers.get('Content-Type');
493
- if (contentType && contentType.includes('application/json')) {
494
- const data = await res.json();
495
- const result = { code: res.status, data, success: res.ok };
496
- return setBaseResponse(result);
497
- }
498
- if (isTextForContentType(contentType)) {
499
- const text = await res.text();
500
- const result = {
501
- code: res.status || 200,
502
- data: text,
503
- success: res.ok,
504
- };
505
- return setBaseResponse(result);
506
- }
507
- const blob = await res.blob();
508
- const result = {
509
- code: res.status,
510
- data: blob,
511
- success: res.ok,
512
- };
513
- return setBaseResponse(result);
486
+ return setBaseResponse(res);
514
487
  }
515
488
  }
516
489
  class BaseQuery {
package/dist/query.js CHANGED
@@ -42,22 +42,22 @@ const adapter = async (opts, overloadOpts) => {
42
42
  ...overloadOpts,
43
43
  body: isGet ? undefined : JSON.stringify(opts.body),
44
44
  })
45
- .then((response) => {
45
+ .then(async (response) => {
46
46
  // 获取 Content-Type 头部信息
47
47
  const contentType = response.headers.get('Content-Type');
48
48
  if (isBlob) {
49
- return response.blob(); // 直接返回 Blob 对象
49
+ return await response.blob(); // 直接返回 Blob 对象
50
50
  }
51
51
  const isJson = contentType && contentType.includes('application/json');
52
52
  // 判断返回的数据类型
53
53
  if (isJson) {
54
- return response.json(); // 解析为 JSON
54
+ return await response.json(); // 解析为 JSON
55
55
  }
56
56
  else if (isTextForContentType(contentType)) {
57
57
  return {
58
58
  code: 200,
59
59
  status: response.status,
60
- data: response.text(), // 直接返回文本内容
60
+ data: await response.text(), // 直接返回文本内容
61
61
  };
62
62
  }
63
63
  else {
@@ -267,34 +267,7 @@ class Query {
267
267
  ...(_options?.headers || {}),
268
268
  },
269
269
  });
270
- if (res.status !== 200) {
271
- return wrapperError({
272
- code: res.status,
273
- message: `fetch error: ${res.statusText}`,
274
- });
275
- }
276
- const contentType = res.headers.get('Content-Type');
277
- if (contentType && contentType.includes('application/json')) {
278
- const data = await res.json();
279
- const result = { code: res.status, data, success: res.ok };
280
- return setBaseResponse(result);
281
- }
282
- if (isTextForContentType(contentType)) {
283
- const text = await res.text();
284
- const result = {
285
- code: res.status || 200,
286
- data: text,
287
- success: res.ok,
288
- };
289
- return setBaseResponse(result);
290
- }
291
- const blob = await res.blob();
292
- const result = {
293
- code: res.status,
294
- data: blob,
295
- success: res.ok,
296
- };
297
- return setBaseResponse(result);
270
+ return setBaseResponse(res);
298
271
  }
299
272
  }
300
273
  class BaseQuery {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kevisual/query",
3
- "version": "0.0.23",
3
+ "version": "0.0.25",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/readme.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # query
2
2
 
3
- 对应的 fetch 内容的一部分功能的封装。
3
+ fetch 功能的的一部分功能的封装。主要处理header的token的提交和response中的处理json。
4
4
 
5
5
  主要目的:请求路径默认`/api/router`,使用`post`,`post`的数据分流使用`path`和`key`.
6
6
 
@@ -8,7 +8,6 @@
8
8
 
9
9
  ## query
10
10
 
11
-
12
11
  ```ts
13
12
  const query = new Query();
14
13
  const res = await query.post({
@@ -35,4 +34,21 @@ type Data = {
35
34
  type DataOpts = Partial<QueryOpts> & {
36
35
  beforeRequest?: Fn;
37
36
  };
38
- ```
37
+ ```
38
+
39
+ ## 适配的@kevisual/router的代码
40
+
41
+ ```ts
42
+ import { App } from '@kevisual/router';
43
+ const app = new App();
44
+
45
+ app
46
+ .route({
47
+ path: 'demo',
48
+ key: '1',
49
+ })
50
+ .define(async (ctx) => {
51
+ ctx.body = 234;
52
+ })
53
+ .addTo(app);
54
+ ```