@kevisual/query 0.0.53 → 0.0.55

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.
@@ -102,7 +102,6 @@ type Fn = (opts: {
102
102
  }) => Promise<Record<string, any> | false>;
103
103
  type QueryOpts$1 = {
104
104
  adapter?: typeof adapter;
105
- token?: string;
106
105
  [key: string]: any;
107
106
  } & AdapterOpts;
108
107
  type QueryOptions = {
@@ -109,7 +109,7 @@ var adapter = async (opts = {}, overloadOpts) => {
109
109
  });
110
110
  };
111
111
 
112
- // node_modules/.pnpm/zustand@5.0.11/node_modules/zustand/esm/vanilla.mjs
112
+ // ../../node_modules/.pnpm/zustand@5.0.12_@types+react@19.2.14_react@19.2.4_use-sync-external-store@1.6.0_react@19.2.4_/node_modules/zustand/esm/vanilla.mjs
113
113
  var createStoreImpl = (createState) => {
114
114
  let state;
115
115
  const listeners = /* @__PURE__ */ new Set;
@@ -400,10 +400,6 @@ class Query {
400
400
  });
401
401
  }
402
402
  }
403
- const headers2 = req.headers || {};
404
- if (options?.token && !headers2["Authorization"]) {
405
- headers2["Authorization"] = `Bearer ${options.token}`;
406
- }
407
403
  } catch (e) {
408
404
  console.error("request beforeFn error", e, req);
409
405
  return wrapperError({
@@ -464,20 +460,20 @@ class Query {
464
460
  this.afterResponse = fn;
465
461
  }
466
462
  async fetchText(urlOrOptions, options) {
467
- let _options = { method: "GET", ...options };
463
+ let _options = { ...options };
468
464
  if (typeof urlOrOptions === "string" && !_options.url) {
469
465
  _options.url = urlOrOptions;
470
466
  }
471
467
  if (typeof urlOrOptions === "object") {
472
468
  _options = { ...urlOrOptions, ..._options };
473
469
  }
474
- const headers = { ...this.headers, ..._options.headers };
475
- if (options?.token && !headers["Authorization"] && _options.method !== "GET") {
476
- headers["Authorization"] = `Bearer ${options.token}`;
477
- }
478
470
  const res = await adapter({
471
+ method: "GET",
479
472
  ..._options,
480
- headers
473
+ headers: {
474
+ ...this.headers,
475
+ ..._options?.headers || {}
476
+ }
481
477
  });
482
478
  if (res && !res.code) {
483
479
  return {
package/dist/query-ws.js CHANGED
@@ -1,4 +1,4 @@
1
- // node_modules/.pnpm/zustand@5.0.11/node_modules/zustand/esm/vanilla.mjs
1
+ // ../../node_modules/.pnpm/zustand@5.0.12_@types+react@19.2.14_react@19.2.4_use-sync-external-store@1.6.0_react@19.2.4_/node_modules/zustand/esm/vanilla.mjs
2
2
  var createStoreImpl = (createState) => {
3
3
  let state;
4
4
  const listeners = /* @__PURE__ */ new Set;
package/dist/query.d.ts CHANGED
@@ -102,7 +102,6 @@ type Fn = (opts: {
102
102
  }) => Promise<Record<string, any> | false>;
103
103
  type QueryOpts = {
104
104
  adapter?: typeof adapter;
105
- token?: string;
106
105
  [key: string]: any;
107
106
  } & AdapterOpts;
108
107
  type QueryOptions = {
package/dist/query.js CHANGED
@@ -203,10 +203,6 @@ class Query {
203
203
  });
204
204
  }
205
205
  }
206
- const headers2 = req.headers || {};
207
- if (options?.token && !headers2["Authorization"]) {
208
- headers2["Authorization"] = `Bearer ${options.token}`;
209
- }
210
206
  } catch (e) {
211
207
  console.error("request beforeFn error", e, req);
212
208
  return wrapperError({
@@ -267,20 +263,20 @@ class Query {
267
263
  this.afterResponse = fn;
268
264
  }
269
265
  async fetchText(urlOrOptions, options) {
270
- let _options = { method: "GET", ...options };
266
+ let _options = { ...options };
271
267
  if (typeof urlOrOptions === "string" && !_options.url) {
272
268
  _options.url = urlOrOptions;
273
269
  }
274
270
  if (typeof urlOrOptions === "object") {
275
271
  _options = { ...urlOrOptions, ..._options };
276
272
  }
277
- const headers = { ...this.headers, ..._options.headers };
278
- if (options?.token && !headers["Authorization"] && _options.method !== "GET") {
279
- headers["Authorization"] = `Bearer ${options.token}`;
280
- }
281
273
  const res = await adapter({
274
+ method: "GET",
282
275
  ..._options,
283
- headers
276
+ headers: {
277
+ ...this.headers,
278
+ ..._options?.headers || {}
279
+ }
284
280
  });
285
281
  if (res && !res.code) {
286
282
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kevisual/query",
3
- "version": "0.0.53",
3
+ "version": "0.0.55",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "build": "npm run clean && bun run bun.config.ts",
@@ -19,12 +19,12 @@
19
19
  "description": "",
20
20
  "devDependencies": {
21
21
  "@kevisual/code-builder": "^0.0.6",
22
- "@kevisual/router": "^0.0.85",
23
- "@types/node": "^25.3.5",
22
+ "@kevisual/router": "^0.1.6",
23
+ "@types/node": "^25.5.0",
24
24
  "typescript": "^5.9.3",
25
25
  "es-toolkit": "^1.45.1",
26
26
  "zod": "^4.3.6",
27
- "zustand": "^5.0.11"
27
+ "zustand": "^5.0.12"
28
28
  },
29
29
  "publishConfig": {
30
30
  "access": "public"
@@ -8,6 +8,7 @@ type RouteInfo = {
8
8
  metadata?: {
9
9
  summary?: string;
10
10
  args?: Record<string, any>;
11
+ returns?: Record<string, any>;
11
12
  viewItem?: {
12
13
  type?: string;
13
14
  api?: {
@@ -46,12 +47,17 @@ const removeViewItemCotnextFromRoutes = (list: RouteInfo[], options?: CreateQuer
46
47
  }
47
48
  type CreateQueryOptions = {
48
49
  removeViewItem?: boolean,
50
+ removeId?: boolean,
49
51
  before?: string,
50
52
  after?: string,
51
53
  }
52
54
  export const createQueryByRoutes = (list: RouteInfo[], options?: CreateQueryOptions) => {
53
55
  const obj: any = {};
54
56
  list = removeViewItemCotnextFromRoutes(list, options);
57
+ list = options?.removeId ? list.map(route => {
58
+ const { id, ...rest } = route;
59
+ return rest as RouteInfo;
60
+ }) : list;
55
61
  for (const route of list) {
56
62
  if (!obj[route.path]) {
57
63
  obj[route.path] = {};
@@ -64,6 +70,14 @@ export const createQueryByRoutes = (list: RouteInfo[], options?: CreateQueryOpti
64
70
  route.metadata.args = toJSONSchema(jsonSchema);
65
71
  }
66
72
  }
73
+ if (route.metadata?.returns) {
74
+ const returns = route.metadata.returns;
75
+ if (returns?.$schema) {
76
+ // 将 returns 转换为 JSON Schema
77
+ const jsonSchema = fromJSONSchema(returns);
78
+ route.metadata.returns = toJSONSchema(jsonSchema);
79
+ }
80
+ }
67
81
  obj[route.path][route.key] = route;
68
82
  }
69
83
  const before = options?.before || `import { createQueryApi } from '@kevisual/query/api';`;
package/src/query.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { adapter, Method, AdapterOpts, methods } from './adapter.ts';
1
+ import { adapter, Method, AdapterOpts } from './adapter.ts';
2
2
  import type { QueryWs } from './ws.ts';
3
3
  /**
4
4
  * 请求前处理函数
@@ -15,7 +15,6 @@ export type Fn = (opts: {
15
15
 
16
16
  export type QueryOpts = {
17
17
  adapter?: typeof adapter;
18
- token?: string;
19
18
  [key: string]: any;
20
19
  } & AdapterOpts;
21
20
 
@@ -156,7 +155,6 @@ export class Query {
156
155
  const _beforeRequest = beforeRequest || this.beforeRequest;
157
156
  const _afterResponse = afterResponse || this.afterResponse;
158
157
  const _timeout = timeout || this.timeout;
159
-
160
158
  const req = {
161
159
  url: url,
162
160
  headers: _headers,
@@ -184,10 +182,6 @@ export class Query {
184
182
  });
185
183
  }
186
184
  }
187
- const headers = req.headers || {};
188
- if (options?.token && !headers['Authorization']) {
189
- headers['Authorization'] = `Bearer ${options.token}`;
190
- }
191
185
  } catch (e) {
192
186
  console.error('request beforeFn error', e, req);
193
187
  return wrapperError({
@@ -260,20 +254,20 @@ export class Query {
260
254
  this.afterResponse = fn;
261
255
  }
262
256
  async fetchText(urlOrOptions?: string | QueryOpts, options?: QueryOpts): Promise<Result<any>> {
263
- let _options = { method: 'GET' as const, ...options };
257
+ let _options = { ...options };
264
258
  if (typeof urlOrOptions === 'string' && !_options.url) {
265
259
  _options.url = urlOrOptions;
266
260
  }
267
261
  if (typeof urlOrOptions === 'object') {
268
262
  _options = { ...urlOrOptions, ..._options };
269
263
  }
270
- const headers = { ...this.headers, ..._options.headers };
271
- if (options?.token && !headers['Authorization'] && _options.method !== 'GET') {
272
- headers['Authorization'] = `Bearer ${options.token}`;
273
- }
274
264
  const res = await adapter({
265
+ method: 'GET',
275
266
  ..._options,
276
- headers,
267
+ headers: {
268
+ ...this.headers,
269
+ ...(_options?.headers || {}),
270
+ },
277
271
  });
278
272
  if (res && !res.code) {
279
273
  return {