@kevisual/query 0.0.24 → 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 {
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 {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kevisual/query",
3
- "version": "0.0.24",
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
+ ```