@kevisual/query 0.0.35 → 0.0.36

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.
@@ -34,16 +34,28 @@ const adapter = async (opts = {}, overloadOpts) => {
34
34
  url = new URL(opts.url);
35
35
  }
36
36
  else {
37
- origin = window?.location?.origin || 'http://localhost:51015';
37
+ origin = window?.location?.origin || 'http://localhost:51515';
38
38
  url = new URL(opts.url, origin);
39
39
  }
40
40
  const isGet = method === 'GET';
41
41
  if (isGet) {
42
- url.search = new URLSearchParams(opts.body).toString();
42
+ let searchParams = new URLSearchParams(opts.body);
43
+ url.search = searchParams.toString();
43
44
  }
44
45
  else {
45
46
  const params = opts.params || {};
46
- url.search = new URLSearchParams(params).toString();
47
+ const searchParams = new URLSearchParams(params);
48
+ if (typeof opts.body === 'object' && opts.body !== null) {
49
+ // 浏览器环境下,自动将 body 中的 path 和 key 提取到查询参数中, 更容易排查问题
50
+ let body = opts.body || {};
51
+ if (!params.path && body?.path) {
52
+ params.path = body.path;
53
+ if (body?.key) {
54
+ params.key = body.key;
55
+ }
56
+ }
57
+ }
58
+ url.search = searchParams.toString();
47
59
  }
48
60
  let body = undefined;
49
61
  if (isGet) {
@@ -33,16 +33,28 @@ const adapter = async (opts = {}, overloadOpts) => {
33
33
  url = new URL(opts.url);
34
34
  }
35
35
  else {
36
- origin = window?.location?.origin || 'http://localhost:51015';
36
+ origin = window?.location?.origin || 'http://localhost:51515';
37
37
  url = new URL(opts.url, origin);
38
38
  }
39
39
  const isGet = method === 'GET';
40
40
  if (isGet) {
41
- url.search = new URLSearchParams(opts.body).toString();
41
+ let searchParams = new URLSearchParams(opts.body);
42
+ url.search = searchParams.toString();
42
43
  }
43
44
  else {
44
45
  const params = opts.params || {};
45
- url.search = new URLSearchParams(params).toString();
46
+ const searchParams = new URLSearchParams(params);
47
+ if (typeof opts.body === 'object' && opts.body !== null) {
48
+ // 浏览器环境下,自动将 body 中的 path 和 key 提取到查询参数中, 更容易排查问题
49
+ let body = opts.body || {};
50
+ if (!params.path && body?.path) {
51
+ params.path = body.path;
52
+ if (body?.key) {
53
+ params.key = body.key;
54
+ }
55
+ }
56
+ }
57
+ url.search = searchParams.toString();
46
58
  }
47
59
  let body = undefined;
48
60
  if (isGet) {
package/dist/query.js CHANGED
@@ -33,16 +33,28 @@ const adapter = async (opts = {}, overloadOpts) => {
33
33
  url = new URL(opts.url);
34
34
  }
35
35
  else {
36
- origin = window?.location?.origin || 'http://localhost:51015';
36
+ origin = window?.location?.origin || 'http://localhost:51515';
37
37
  url = new URL(opts.url, origin);
38
38
  }
39
39
  const isGet = method === 'GET';
40
40
  if (isGet) {
41
- url.search = new URLSearchParams(opts.body).toString();
41
+ let searchParams = new URLSearchParams(opts.body);
42
+ url.search = searchParams.toString();
42
43
  }
43
44
  else {
44
45
  const params = opts.params || {};
45
- url.search = new URLSearchParams(params).toString();
46
+ const searchParams = new URLSearchParams(params);
47
+ if (typeof opts.body === 'object' && opts.body !== null) {
48
+ // 浏览器环境下,自动将 body 中的 path 和 key 提取到查询参数中, 更容易排查问题
49
+ let body = opts.body || {};
50
+ if (!params.path && body?.path) {
51
+ params.path = body.path;
52
+ if (body?.key) {
53
+ params.key = body.key;
54
+ }
55
+ }
56
+ }
57
+ url.search = searchParams.toString();
46
58
  }
47
59
  let body = undefined;
48
60
  if (isGet) {
package/package.json CHANGED
@@ -1,12 +1,11 @@
1
1
  {
2
2
  "name": "@kevisual/query",
3
- "version": "0.0.35",
3
+ "version": "0.0.36",
4
4
  "main": "dist/query-browser.js",
5
5
  "private": false,
6
6
  "type": "module",
7
7
  "scripts": {
8
8
  "build": "npm run clean && rollup -c",
9
- "build:app": "npm run build && rsync dist/* ../deploy/dist",
10
9
  "dev:lib": "rollup -c -w",
11
10
  "clean": "rm -rf dist"
12
11
  },
@@ -24,10 +23,10 @@
24
23
  "devDependencies": {
25
24
  "@rollup/plugin-node-resolve": "^16.0.3",
26
25
  "@rollup/plugin-typescript": "^12.3.0",
27
- "rollup": "^4.54.0",
26
+ "rollup": "^4.55.3",
28
27
  "rollup-plugin-dts": "^6.3.0",
29
28
  "typescript": "^5.9.3",
30
- "zustand": "^5.0.9"
29
+ "zustand": "^5.0.10"
31
30
  },
32
31
  "publishConfig": {
33
32
  "access": "public"
package/src/adapter.ts CHANGED
@@ -60,15 +60,27 @@ export const adapter = async (opts: AdapterOpts = {}, overloadOpts?: RequestInit
60
60
  if (opts?.url?.startsWith('http')) {
61
61
  url = new URL(opts.url);
62
62
  } else {
63
- origin = window?.location?.origin || 'http://localhost:51015';
63
+ origin = window?.location?.origin || 'http://localhost:51515';
64
64
  url = new URL(opts.url, origin);
65
65
  }
66
66
  const isGet = method === 'GET';
67
67
  if (isGet) {
68
- url.search = new URLSearchParams(opts.body as SimpleObject).toString();
68
+ let searchParams = new URLSearchParams(opts.body as SimpleObject);
69
+ url.search = searchParams.toString();
69
70
  } else {
70
71
  const params = opts.params || {};
71
- url.search = new URLSearchParams(params as SimpleObject).toString();
72
+ const searchParams = new URLSearchParams(params as SimpleObject);
73
+ if (typeof opts.body === 'object' && opts.body !== null) {
74
+ // 浏览器环境下,自动将 body 中的 path 和 key 提取到查询参数中, 更容易排查问题
75
+ let body = opts.body as Record<string, any> || {};
76
+ if (!params.path && body?.path) {
77
+ params.path = body.path;
78
+ if (body?.key) {
79
+ params.key = body.key;
80
+ }
81
+ }
82
+ }
83
+ url.search = searchParams.toString();
72
84
  }
73
85
  let body: string | FormData | undefined = undefined;
74
86
  if (isGet) {