@kevisual/query 0.0.32 → 0.0.33

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.
@@ -80,7 +80,7 @@ const adapter = async (opts = {}, overloadOpts) => {
80
80
  }
81
81
  else if (isTextForContentType(contentType)) {
82
82
  return {
83
- code: 200,
83
+ code: response.status,
84
84
  status: response.status,
85
85
  data: await response.text(), // 直接返回文本内容
86
86
  };
@@ -112,6 +112,13 @@ type QueryOpts$1 = {
112
112
  adapter?: typeof adapter;
113
113
  [key: string]: any;
114
114
  } & AdapterOpts;
115
+ type QueryOptions = {
116
+ url?: string;
117
+ adapter?: typeof adapter;
118
+ headers?: Record<string, string>;
119
+ timeout?: number;
120
+ isClient?: boolean;
121
+ };
115
122
  type Data = {
116
123
  path?: string;
117
124
  key?: string;
@@ -172,7 +179,8 @@ declare class Query {
172
179
  */
173
180
  stop?: boolean;
174
181
  qws: QueryWs;
175
- constructor(opts?: QueryOpts$1);
182
+ isClient: boolean;
183
+ constructor(opts?: QueryOptions);
176
184
  setQueryWs(qws: QueryWs): void;
177
185
  /**
178
186
  * 突然停止请求
@@ -228,6 +236,10 @@ declare class BaseQuery<T extends Query = Query, R extends {
228
236
  post<R = any, P = any>(data: P, options?: DataOpts): Promise<Result<R>>;
229
237
  get<R = any, P = any>(data: P, options?: DataOpts): Promise<Result<R>>;
230
238
  }
239
+ /**
240
+ * @deprecated
241
+ * 前端调用后端QueryRouter, 默认路径 /client/router
242
+ */
231
243
  declare class ClientQuery extends Query {
232
244
  constructor(opts?: QueryOpts$1);
233
245
  }
@@ -237,6 +249,7 @@ type QueryOpts = {
237
249
  adapter?: typeof adapter;
238
250
  headers?: Record<string, string>;
239
251
  timeout?: number;
252
+ isClient?: boolean;
240
253
  };
241
254
  /**
242
255
  * 前端调用后端QueryRouter, 封装 beforeRequest 和 wss
@@ -245,7 +258,7 @@ declare class QueryClient extends Query {
245
258
  tokenName: string;
246
259
  storage: Storage;
247
260
  token: string;
248
- constructor(opts?: QueryOpts & {
261
+ constructor(opts?: QueryOptions & {
249
262
  tokenName?: string;
250
263
  storage?: Storage;
251
264
  io?: boolean;
@@ -257,4 +270,4 @@ declare class QueryClient extends Query {
257
270
  }
258
271
 
259
272
  export { BaseQuery, ClientQuery, Query, QueryClient, QueryWs, adapter, wrapperError };
260
- export type { Data, DataOpts, QueryOpts, QueryWsOpts, Result };
273
+ export type { Data, DataOpts, QueryOptions, QueryOpts, QueryWsOpts, Result };
@@ -79,7 +79,7 @@ const adapter = async (opts = {}, overloadOpts) => {
79
79
  }
80
80
  else if (isTextForContentType(contentType)) {
81
81
  return {
82
- code: 200,
82
+ code: response.status,
83
83
  status: response.status,
84
84
  data: await response.text(), // 直接返回文本内容
85
85
  };
@@ -358,9 +358,11 @@ class Query {
358
358
  stop;
359
359
  // 默认不使用ws
360
360
  qws;
361
+ isClient = false;
361
362
  constructor(opts) {
362
363
  this.adapter = opts?.adapter || adapter;
363
- this.url = opts?.url || '/api/router';
364
+ const defaultURL = opts?.isClient ? '/client/router' : '/api/router';
365
+ this.url = opts?.url || defaultURL;
364
366
  this.headers = opts?.headers || {
365
367
  'Content-Type': 'application/json',
366
368
  };
@@ -528,6 +530,10 @@ class BaseQuery {
528
530
  return this.query.get(data, options);
529
531
  }
530
532
  }
533
+ /**
534
+ * @deprecated
535
+ * 前端调用后端QueryRouter, 默认路径 /client/router
536
+ */
531
537
  class ClientQuery extends Query {
532
538
  constructor(opts) {
533
539
  super({ ...opts, url: opts?.url || '/client/router' });
package/dist/query.d.ts CHANGED
@@ -112,6 +112,13 @@ type QueryOpts = {
112
112
  adapter?: typeof adapter;
113
113
  [key: string]: any;
114
114
  } & AdapterOpts;
115
+ type QueryOptions = {
116
+ url?: string;
117
+ adapter?: typeof adapter;
118
+ headers?: Record<string, string>;
119
+ timeout?: number;
120
+ isClient?: boolean;
121
+ };
115
122
  type Data = {
116
123
  path?: string;
117
124
  key?: string;
@@ -183,7 +190,8 @@ declare class Query {
183
190
  */
184
191
  stop?: boolean;
185
192
  qws: QueryWs;
186
- constructor(opts?: QueryOpts);
193
+ isClient: boolean;
194
+ constructor(opts?: QueryOptions);
187
195
  setQueryWs(qws: QueryWs): void;
188
196
  /**
189
197
  * 突然停止请求
@@ -239,9 +247,13 @@ declare class BaseQuery<T extends Query = Query, R extends {
239
247
  post<R = any, P = any>(data: P, options?: DataOpts): Promise<Result<R>>;
240
248
  get<R = any, P = any>(data: P, options?: DataOpts): Promise<Result<R>>;
241
249
  }
250
+ /**
251
+ * @deprecated
252
+ * 前端调用后端QueryRouter, 默认路径 /client/router
253
+ */
242
254
  declare class ClientQuery extends Query {
243
255
  constructor(opts?: QueryOpts);
244
256
  }
245
257
 
246
258
  export { BaseQuery, ClientQuery, Query, adapter, setBaseResponse, wrapperError };
247
- export type { Data, DataOpts, Fn, QueryOpts, Result };
259
+ export type { Data, DataOpts, Fn, QueryOptions, QueryOpts, Result };
package/dist/query.js CHANGED
@@ -79,7 +79,7 @@ const adapter = async (opts = {}, overloadOpts) => {
79
79
  }
80
80
  else if (isTextForContentType(contentType)) {
81
81
  return {
82
- code: 200,
82
+ code: response.status,
83
83
  status: response.status,
84
84
  data: await response.text(), // 直接返回文本内容
85
85
  };
@@ -161,9 +161,11 @@ class Query {
161
161
  stop;
162
162
  // 默认不使用ws
163
163
  qws;
164
+ isClient = false;
164
165
  constructor(opts) {
165
166
  this.adapter = opts?.adapter || adapter;
166
- this.url = opts?.url || '/api/router';
167
+ const defaultURL = opts?.isClient ? '/client/router' : '/api/router';
168
+ this.url = opts?.url || defaultURL;
167
169
  this.headers = opts?.headers || {
168
170
  'Content-Type': 'application/json',
169
171
  };
@@ -331,6 +333,10 @@ class BaseQuery {
331
333
  return this.query.get(data, options);
332
334
  }
333
335
  }
336
+ /**
337
+ * @deprecated
338
+ * 前端调用后端QueryRouter, 默认路径 /client/router
339
+ */
334
340
  class ClientQuery extends Query {
335
341
  constructor(opts) {
336
342
  super({ ...opts, url: opts?.url || '/client/router' });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kevisual/query",
3
- "version": "0.0.32",
3
+ "version": "0.0.33",
4
4
  "main": "dist/query-browser.js",
5
5
  "private": false,
6
6
  "type": "module",
@@ -23,7 +23,7 @@
23
23
  "devDependencies": {
24
24
  "@rollup/plugin-node-resolve": "^16.0.3",
25
25
  "@rollup/plugin-typescript": "^12.3.0",
26
- "rollup": "^4.53.3",
26
+ "rollup": "^4.53.5",
27
27
  "rollup-plugin-dts": "^6.3.0",
28
28
  "typescript": "^5.9.3",
29
29
  "zustand": "^5.0.9"
@@ -47,10 +47,6 @@
47
47
  "./ws": {
48
48
  "import": "./dist/query-ws.js",
49
49
  "require": "./dist/query-ws.js"
50
- },
51
- "./query-ai": {
52
- "import": "./dist/query-ai.js",
53
- "require": "./dist/query-ai.js"
54
50
  }
55
51
  }
56
52
  }