@kevisual/query 0.0.29 → 0.0.31

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.
@@ -3,11 +3,26 @@ type Method = (typeof methods)[number];
3
3
  type AdapterOpts = {
4
4
  url?: string;
5
5
  headers?: Record<string, string>;
6
+ /**
7
+ * 只用户POST请求,传递的查询参数,
8
+ * GET请求默认方body自己转化为查询参数
9
+ */
10
+ params?: Record<string, any>;
6
11
  body?: Record<string, any> | FormData;
7
12
  timeout?: number;
8
13
  method?: Method;
14
+ /**
15
+ * @deprecated use responseType
16
+ */
9
17
  isBlob?: boolean;
18
+ /**
19
+ * @deprecated use responseType
20
+ */
10
21
  isText?: boolean;
22
+ /**
23
+ * 响应类型,
24
+ * */
25
+ responseType?: 'json' | 'text' | 'blob';
11
26
  isPostFile?: boolean;
12
27
  };
13
28
  declare const isTextForContentType: (contentType: string | null) => boolean;
@@ -2,7 +2,7 @@ const methods = ['GET', 'POST'];
2
2
  const isTextForContentType = (contentType) => {
3
3
  if (!contentType)
4
4
  return false;
5
- const textTypes = ['text/', 'xml', 'html', 'javascript', 'css', 'csv', 'plain', 'x-www-form-urlencoded'];
5
+ const textTypes = ['text/', 'xml', 'html', 'javascript', 'css', 'csv', 'plain', 'x-www-form-urlencoded', 'md'];
6
6
  return textTypes.some((type) => contentType.includes(type));
7
7
  };
8
8
  /**
@@ -14,9 +14,14 @@ const isTextForContentType = (contentType) => {
14
14
  const adapter = async (opts = {}, overloadOpts) => {
15
15
  const controller = new AbortController();
16
16
  const signal = controller.signal;
17
- const isBlob = opts.isBlob || false; // 是否返回 Blob 对象
18
- const isText = opts.isText || false; // 是否返回文本内容
19
17
  const isPostFile = opts.isPostFile || false; // 是否为文件上传
18
+ let responseType = opts.responseType || 'json'; // 响应类型
19
+ if (opts.isBlob) {
20
+ responseType = 'blob';
21
+ }
22
+ else if (opts.isText) {
23
+ responseType = 'text';
24
+ }
20
25
  const timeout = opts.timeout || 60000 * 3; // 默认超时时间为 60s * 3
21
26
  const timer = setTimeout(() => {
22
27
  controller.abort();
@@ -36,6 +41,10 @@ const adapter = async (opts = {}, overloadOpts) => {
36
41
  if (isGet) {
37
42
  url.search = new URLSearchParams(opts.body).toString();
38
43
  }
44
+ else {
45
+ const params = opts.params || {};
46
+ url.search = new URLSearchParams(params).toString();
47
+ }
39
48
  let body = undefined;
40
49
  if (isGet) {
41
50
  body = undefined;
@@ -60,9 +69,10 @@ const adapter = async (opts = {}, overloadOpts) => {
60
69
  .then(async (response) => {
61
70
  // 获取 Content-Type 头部信息
62
71
  const contentType = response.headers.get('Content-Type');
63
- if (isBlob) {
72
+ if (responseType === 'blob') {
64
73
  return await response.blob(); // 直接返回 Blob 对象
65
74
  }
75
+ const isText = responseType === 'text';
66
76
  const isJson = contentType && contentType.includes('application/json');
67
77
  // 判断返回的数据类型
68
78
  if (isJson && !isText) {
@@ -5,11 +5,26 @@ type Method = (typeof methods)[number];
5
5
  type AdapterOpts = {
6
6
  url?: string;
7
7
  headers?: Record<string, string>;
8
+ /**
9
+ * 只用户POST请求,传递的查询参数,
10
+ * GET请求默认方body自己转化为查询参数
11
+ */
12
+ params?: Record<string, any>;
8
13
  body?: Record<string, any> | FormData;
9
14
  timeout?: number;
10
15
  method?: Method;
16
+ /**
17
+ * @deprecated use responseType
18
+ */
11
19
  isBlob?: boolean;
20
+ /**
21
+ * @deprecated use responseType
22
+ */
12
23
  isText?: boolean;
24
+ /**
25
+ * 响应类型,
26
+ * */
27
+ responseType?: 'json' | 'text' | 'blob';
13
28
  isPostFile?: boolean;
14
29
  };
15
30
  /**
@@ -154,7 +169,13 @@ declare const wrapperError: ({ code, message }: {
154
169
  declare class Query {
155
170
  adapter: typeof adapter;
156
171
  url: string;
172
+ /**
173
+ * 请求前处理函数
174
+ */
157
175
  beforeRequest?: DataOpts['beforeRequest'];
176
+ /**
177
+ * 请求后处理函数
178
+ */
158
179
  afterResponse?: DataOpts['afterResponse'];
159
180
  headers?: Record<string, string>;
160
181
  timeout?: number;
@@ -188,12 +209,12 @@ declare class Query {
188
209
  */
189
210
  post<R = any, P = any>(body: Data & P, options?: DataOpts): Promise<Result<R>>;
190
211
  /**
191
- * 请求前处理,设置请求前处理函数
212
+ * 设置请求前处理,设置请求前处理函数
192
213
  * @param fn 处理函数
193
214
  */
194
215
  before(fn: DataOpts['beforeRequest']): void;
195
216
  /**
196
- * 请求后处理,设置请求后处理函数
217
+ * 设置请求后处理,设置请求后处理函数
197
218
  * @param fn 处理函数
198
219
  */
199
220
  after(fn: DataOpts['afterResponse']): void;
@@ -1,7 +1,7 @@
1
1
  const isTextForContentType = (contentType) => {
2
2
  if (!contentType)
3
3
  return false;
4
- const textTypes = ['text/', 'xml', 'html', 'javascript', 'css', 'csv', 'plain', 'x-www-form-urlencoded'];
4
+ const textTypes = ['text/', 'xml', 'html', 'javascript', 'css', 'csv', 'plain', 'x-www-form-urlencoded', 'md'];
5
5
  return textTypes.some((type) => contentType.includes(type));
6
6
  };
7
7
  /**
@@ -13,9 +13,14 @@ const isTextForContentType = (contentType) => {
13
13
  const adapter = async (opts = {}, overloadOpts) => {
14
14
  const controller = new AbortController();
15
15
  const signal = controller.signal;
16
- const isBlob = opts.isBlob || false; // 是否返回 Blob 对象
17
- const isText = opts.isText || false; // 是否返回文本内容
18
16
  const isPostFile = opts.isPostFile || false; // 是否为文件上传
17
+ let responseType = opts.responseType || 'json'; // 响应类型
18
+ if (opts.isBlob) {
19
+ responseType = 'blob';
20
+ }
21
+ else if (opts.isText) {
22
+ responseType = 'text';
23
+ }
19
24
  const timeout = opts.timeout || 60000 * 3; // 默认超时时间为 60s * 3
20
25
  const timer = setTimeout(() => {
21
26
  controller.abort();
@@ -35,6 +40,10 @@ const adapter = async (opts = {}, overloadOpts) => {
35
40
  if (isGet) {
36
41
  url.search = new URLSearchParams(opts.body).toString();
37
42
  }
43
+ else {
44
+ const params = opts.params || {};
45
+ url.search = new URLSearchParams(params).toString();
46
+ }
38
47
  let body = undefined;
39
48
  if (isGet) {
40
49
  body = undefined;
@@ -59,9 +68,10 @@ const adapter = async (opts = {}, overloadOpts) => {
59
68
  .then(async (response) => {
60
69
  // 获取 Content-Type 头部信息
61
70
  const contentType = response.headers.get('Content-Type');
62
- if (isBlob) {
71
+ if (responseType === 'blob') {
63
72
  return await response.blob(); // 直接返回 Blob 对象
64
73
  }
74
+ const isText = responseType === 'text';
65
75
  const isJson = contentType && contentType.includes('application/json');
66
76
  // 判断返回的数据类型
67
77
  if (isJson && !isText) {
@@ -113,7 +123,7 @@ const createStoreImpl = (createState) => {
113
123
  const initialState = state = createState(setState, getState, api);
114
124
  return api;
115
125
  };
116
- const createStore = (createState) => createState ? createStoreImpl(createState) : createStoreImpl;
126
+ const createStore = ((createState) => createState ? createStoreImpl(createState) : createStoreImpl);
117
127
 
118
128
  const parseWsUrl = (url) => {
119
129
  try {
@@ -351,7 +361,13 @@ const wrapperError = ({ code, message }) => {
351
361
  class Query {
352
362
  adapter;
353
363
  url;
364
+ /**
365
+ * 请求前处理函数
366
+ */
354
367
  beforeRequest;
368
+ /**
369
+ * 请求后处理函数
370
+ */
355
371
  afterResponse;
356
372
  headers;
357
373
  timeout;
@@ -468,14 +484,14 @@ class Query {
468
484
  });
469
485
  }
470
486
  /**
471
- * 请求前处理,设置请求前处理函数
487
+ * 设置请求前处理,设置请求前处理函数
472
488
  * @param fn 处理函数
473
489
  */
474
490
  before(fn) {
475
491
  this.beforeRequest = fn;
476
492
  }
477
493
  /**
478
- * 请求后处理,设置请求后处理函数
494
+ * 设置请求后处理,设置请求后处理函数
479
495
  * @param fn 处理函数
480
496
  */
481
497
  after(fn) {
package/dist/query-ws.js CHANGED
@@ -19,7 +19,7 @@ const createStoreImpl = (createState) => {
19
19
  const initialState = state = createState(setState, getState, api);
20
20
  return api;
21
21
  };
22
- const createStore = (createState) => createState ? createStoreImpl(createState) : createStoreImpl;
22
+ const createStore = ((createState) => createState ? createStoreImpl(createState) : createStoreImpl);
23
23
 
24
24
  const parseWsUrl = (url) => {
25
25
  try {
package/dist/query.d.ts CHANGED
@@ -5,11 +5,26 @@ type Method = (typeof methods)[number];
5
5
  type AdapterOpts = {
6
6
  url?: string;
7
7
  headers?: Record<string, string>;
8
+ /**
9
+ * 只用户POST请求,传递的查询参数,
10
+ * GET请求默认方body自己转化为查询参数
11
+ */
12
+ params?: Record<string, any>;
8
13
  body?: Record<string, any> | FormData;
9
14
  timeout?: number;
10
15
  method?: Method;
16
+ /**
17
+ * @deprecated use responseType
18
+ */
11
19
  isBlob?: boolean;
20
+ /**
21
+ * @deprecated use responseType
22
+ */
12
23
  isText?: boolean;
24
+ /**
25
+ * 响应类型,
26
+ * */
27
+ responseType?: 'json' | 'text' | 'blob';
13
28
  isPostFile?: boolean;
14
29
  };
15
30
  /**
@@ -161,7 +176,13 @@ declare const wrapperError: ({ code, message }: {
161
176
  declare class Query {
162
177
  adapter: typeof adapter;
163
178
  url: string;
179
+ /**
180
+ * 请求前处理函数
181
+ */
164
182
  beforeRequest?: DataOpts['beforeRequest'];
183
+ /**
184
+ * 请求后处理函数
185
+ */
165
186
  afterResponse?: DataOpts['afterResponse'];
166
187
  headers?: Record<string, string>;
167
188
  timeout?: number;
@@ -195,12 +216,12 @@ declare class Query {
195
216
  */
196
217
  post<R = any, P = any>(body: Data & P, options?: DataOpts): Promise<Result<R>>;
197
218
  /**
198
- * 请求前处理,设置请求前处理函数
219
+ * 设置请求前处理,设置请求前处理函数
199
220
  * @param fn 处理函数
200
221
  */
201
222
  before(fn: DataOpts['beforeRequest']): void;
202
223
  /**
203
- * 请求后处理,设置请求后处理函数
224
+ * 设置请求后处理,设置请求后处理函数
204
225
  * @param fn 处理函数
205
226
  */
206
227
  after(fn: DataOpts['afterResponse']): void;
package/dist/query.js CHANGED
@@ -1,7 +1,7 @@
1
1
  const isTextForContentType = (contentType) => {
2
2
  if (!contentType)
3
3
  return false;
4
- const textTypes = ['text/', 'xml', 'html', 'javascript', 'css', 'csv', 'plain', 'x-www-form-urlencoded'];
4
+ const textTypes = ['text/', 'xml', 'html', 'javascript', 'css', 'csv', 'plain', 'x-www-form-urlencoded', 'md'];
5
5
  return textTypes.some((type) => contentType.includes(type));
6
6
  };
7
7
  /**
@@ -13,9 +13,14 @@ const isTextForContentType = (contentType) => {
13
13
  const adapter = async (opts = {}, overloadOpts) => {
14
14
  const controller = new AbortController();
15
15
  const signal = controller.signal;
16
- const isBlob = opts.isBlob || false; // 是否返回 Blob 对象
17
- const isText = opts.isText || false; // 是否返回文本内容
18
16
  const isPostFile = opts.isPostFile || false; // 是否为文件上传
17
+ let responseType = opts.responseType || 'json'; // 响应类型
18
+ if (opts.isBlob) {
19
+ responseType = 'blob';
20
+ }
21
+ else if (opts.isText) {
22
+ responseType = 'text';
23
+ }
19
24
  const timeout = opts.timeout || 60000 * 3; // 默认超时时间为 60s * 3
20
25
  const timer = setTimeout(() => {
21
26
  controller.abort();
@@ -35,6 +40,10 @@ const adapter = async (opts = {}, overloadOpts) => {
35
40
  if (isGet) {
36
41
  url.search = new URLSearchParams(opts.body).toString();
37
42
  }
43
+ else {
44
+ const params = opts.params || {};
45
+ url.search = new URLSearchParams(params).toString();
46
+ }
38
47
  let body = undefined;
39
48
  if (isGet) {
40
49
  body = undefined;
@@ -59,9 +68,10 @@ const adapter = async (opts = {}, overloadOpts) => {
59
68
  .then(async (response) => {
60
69
  // 获取 Content-Type 头部信息
61
70
  const contentType = response.headers.get('Content-Type');
62
- if (isBlob) {
71
+ if (responseType === 'blob') {
63
72
  return await response.blob(); // 直接返回 Blob 对象
64
73
  }
74
+ const isText = responseType === 'text';
65
75
  const isJson = contentType && contentType.includes('application/json');
66
76
  // 判断返回的数据类型
67
77
  if (isJson && !isText) {
@@ -135,7 +145,13 @@ const wrapperError = ({ code, message }) => {
135
145
  class Query {
136
146
  adapter;
137
147
  url;
148
+ /**
149
+ * 请求前处理函数
150
+ */
138
151
  beforeRequest;
152
+ /**
153
+ * 请求后处理函数
154
+ */
139
155
  afterResponse;
140
156
  headers;
141
157
  timeout;
@@ -252,14 +268,14 @@ class Query {
252
268
  });
253
269
  }
254
270
  /**
255
- * 请求前处理,设置请求前处理函数
271
+ * 设置请求前处理,设置请求前处理函数
256
272
  * @param fn 处理函数
257
273
  */
258
274
  before(fn) {
259
275
  this.beforeRequest = fn;
260
276
  }
261
277
  /**
262
- * 请求后处理,设置请求后处理函数
278
+ * 设置请求后处理,设置请求后处理函数
263
279
  * @param fn 处理函数
264
280
  */
265
281
  after(fn) {
package/package.json CHANGED
@@ -1,9 +1,7 @@
1
1
  {
2
2
  "name": "@kevisual/query",
3
- "version": "0.0.29",
4
- "main": "dist/index.js",
5
- "module": "dist/index.js",
6
- "types": "dist/index.d.ts",
3
+ "version": "0.0.31",
4
+ "main": "dist/query-browser.js",
7
5
  "private": false,
8
6
  "type": "module",
9
7
  "scripts": {
@@ -23,16 +21,13 @@
23
21
  "license": "ISC",
24
22
  "description": "",
25
23
  "devDependencies": {
26
- "@rollup/plugin-node-resolve": "^16.0.1",
27
- "@rollup/plugin-typescript": "^12.1.2",
28
- "rollup": "^4.41.1",
29
- "rollup-plugin-dts": "^6.2.1",
30
- "ts-node": "^10.9.2",
31
- "tslib": "^2.8.1",
32
- "typescript": "^5.8.3",
33
- "zustand": "^5.0.5"
24
+ "@rollup/plugin-node-resolve": "^16.0.3",
25
+ "@rollup/plugin-typescript": "^12.3.0",
26
+ "rollup": "^4.53.3",
27
+ "rollup-plugin-dts": "^6.3.0",
28
+ "typescript": "^5.9.3",
29
+ "zustand": "^5.0.9"
34
30
  },
35
- "packageManager": "yarn@1.22.22",
36
31
  "publishConfig": {
37
32
  "access": "public"
38
33
  },
@@ -57,8 +52,5 @@
57
52
  "import": "./dist/query-ai.js",
58
53
  "require": "./dist/query-ai.js"
59
54
  }
60
- },
61
- "dependencies": {
62
- "openai": "^5.0.1"
63
55
  }
64
56
  }
@@ -1,30 +0,0 @@
1
- import OpenAI, { ClientOptions } from 'openai';
2
- export { default as OpenAI } from 'openai';
3
- import { RequestOptions } from 'openai/core.mjs';
4
-
5
- type QueryOpts = {
6
- /**
7
- * OpenAI model name, example: deepseek-chat
8
- */
9
- model: string;
10
- /**
11
- * OpenAI client options
12
- * QueryAi.init() will be called with these options
13
- */
14
- openAiOpts?: ClientOptions;
15
- openai?: OpenAI;
16
- };
17
- declare class QueryAI {
18
- private openai;
19
- model?: string;
20
- constructor(opts?: QueryOpts);
21
- init(opts: ClientOptions): void;
22
- query(prompt: string, opts?: RequestOptions): Promise<OpenAI.Chat.Completions.ChatCompletion & {
23
- _request_id?: string | null;
24
- }>;
25
- queryAsync(prompt: string, opts?: RequestOptions): Promise<OpenAI.Chat.Completions.ChatCompletion & {
26
- _request_id?: string | null;
27
- }>;
28
- }
29
-
30
- export { QueryAI };