@kevisual/query 0.0.52 → 0.0.53
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.
- package/dist/query-api.d.ts +1 -0
- package/dist/query-api.js +17 -13
- package/dist/query-browser.d.ts +1 -0
- package/dist/query-browser.js +10 -6
- package/dist/query.d.ts +1 -0
- package/dist/query.js +10 -6
- package/package.json +4 -4
- package/src/query.ts +13 -7
package/dist/query-api.d.ts
CHANGED
package/dist/query-api.js
CHANGED
|
@@ -203,6 +203,10 @@ 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
|
+
}
|
|
206
210
|
} catch (e) {
|
|
207
211
|
console.error("request beforeFn error", e, req);
|
|
208
212
|
return wrapperError({
|
|
@@ -263,20 +267,20 @@ class Query {
|
|
|
263
267
|
this.afterResponse = fn;
|
|
264
268
|
}
|
|
265
269
|
async fetchText(urlOrOptions, options) {
|
|
266
|
-
let _options = { ...options };
|
|
270
|
+
let _options = { method: "GET", ...options };
|
|
267
271
|
if (typeof urlOrOptions === "string" && !_options.url) {
|
|
268
272
|
_options.url = urlOrOptions;
|
|
269
273
|
}
|
|
270
274
|
if (typeof urlOrOptions === "object") {
|
|
271
275
|
_options = { ...urlOrOptions, ..._options };
|
|
272
276
|
}
|
|
277
|
+
const headers = { ...this.headers, ..._options.headers };
|
|
278
|
+
if (options?.token && !headers["Authorization"] && _options.method !== "GET") {
|
|
279
|
+
headers["Authorization"] = `Bearer ${options.token}`;
|
|
280
|
+
}
|
|
273
281
|
const res = await adapter({
|
|
274
|
-
method: "GET",
|
|
275
282
|
..._options,
|
|
276
|
-
headers
|
|
277
|
-
...this.headers,
|
|
278
|
-
..._options?.headers || {}
|
|
279
|
-
}
|
|
283
|
+
headers
|
|
280
284
|
});
|
|
281
285
|
if (res && !res.code) {
|
|
282
286
|
return {
|
|
@@ -288,7 +292,7 @@ class Query {
|
|
|
288
292
|
}
|
|
289
293
|
}
|
|
290
294
|
|
|
291
|
-
// node_modules/.pnpm/@kevisual+router@0.0.
|
|
295
|
+
// node_modules/.pnpm/@kevisual+router@0.0.85/node_modules/@kevisual/router/dist/router-browser.js
|
|
292
296
|
var __create = Object.create;
|
|
293
297
|
var __getProtoOf = Object.getPrototypeOf;
|
|
294
298
|
var __defProp = Object.defineProperty;
|
|
@@ -14092,13 +14096,13 @@ function generateApiCode(obj) {
|
|
|
14092
14096
|
const paths = Object.keys(obj);
|
|
14093
14097
|
for (let i = 0;i < paths.length; i++) {
|
|
14094
14098
|
const path = paths[i];
|
|
14095
|
-
const
|
|
14099
|
+
const methods2 = obj[path];
|
|
14096
14100
|
code += ` "${path}": {
|
|
14097
14101
|
`;
|
|
14098
|
-
const keys = Object.keys(
|
|
14102
|
+
const keys = Object.keys(methods2);
|
|
14099
14103
|
for (let j = 0;j < keys.length; j++) {
|
|
14100
14104
|
const key = keys[j];
|
|
14101
|
-
const route =
|
|
14105
|
+
const route = methods2[key];
|
|
14102
14106
|
if (route?.id) {
|
|
14103
14107
|
if (route.id.startsWith("rand-")) {
|
|
14104
14108
|
delete route.id;
|
|
@@ -14180,7 +14184,7 @@ function generateApiCode(obj) {
|
|
|
14180
14184
|
return code;
|
|
14181
14185
|
}
|
|
14182
14186
|
|
|
14183
|
-
// node_modules/.pnpm/es-toolkit@1.
|
|
14187
|
+
// node_modules/.pnpm/es-toolkit@1.45.1/node_modules/es-toolkit/dist/object/pick.mjs
|
|
14184
14188
|
function pick(obj, keys) {
|
|
14185
14189
|
const result = {};
|
|
14186
14190
|
for (let i = 0;i < keys.length; i++) {
|
|
@@ -14211,13 +14215,13 @@ class QueryApi {
|
|
|
14211
14215
|
const that = this;
|
|
14212
14216
|
const apiEntries = Object.entries(api);
|
|
14213
14217
|
const keepPaths = ["createApi", "query", "post"];
|
|
14214
|
-
for (const [path,
|
|
14218
|
+
for (const [path, methods2] of apiEntries) {
|
|
14215
14219
|
if (keepPaths.includes(path))
|
|
14216
14220
|
continue;
|
|
14217
14221
|
if (!that[path]) {
|
|
14218
14222
|
that[path] = {};
|
|
14219
14223
|
}
|
|
14220
|
-
for (const [key, pos] of Object.entries(
|
|
14224
|
+
for (const [key, pos] of Object.entries(methods2)) {
|
|
14221
14225
|
that[path][key] = (data, opts = {}) => {
|
|
14222
14226
|
const _pos = pick(pos, ["path", "key", "id"]);
|
|
14223
14227
|
if (pos.metadata?.viewItem?.api?.url && !opts.url) {
|
package/dist/query-browser.d.ts
CHANGED
package/dist/query-browser.js
CHANGED
|
@@ -400,6 +400,10 @@ 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
|
+
}
|
|
403
407
|
} catch (e) {
|
|
404
408
|
console.error("request beforeFn error", e, req);
|
|
405
409
|
return wrapperError({
|
|
@@ -460,20 +464,20 @@ class Query {
|
|
|
460
464
|
this.afterResponse = fn;
|
|
461
465
|
}
|
|
462
466
|
async fetchText(urlOrOptions, options) {
|
|
463
|
-
let _options = { ...options };
|
|
467
|
+
let _options = { method: "GET", ...options };
|
|
464
468
|
if (typeof urlOrOptions === "string" && !_options.url) {
|
|
465
469
|
_options.url = urlOrOptions;
|
|
466
470
|
}
|
|
467
471
|
if (typeof urlOrOptions === "object") {
|
|
468
472
|
_options = { ...urlOrOptions, ..._options };
|
|
469
473
|
}
|
|
474
|
+
const headers = { ...this.headers, ..._options.headers };
|
|
475
|
+
if (options?.token && !headers["Authorization"] && _options.method !== "GET") {
|
|
476
|
+
headers["Authorization"] = `Bearer ${options.token}`;
|
|
477
|
+
}
|
|
470
478
|
const res = await adapter({
|
|
471
|
-
method: "GET",
|
|
472
479
|
..._options,
|
|
473
|
-
headers
|
|
474
|
-
...this.headers,
|
|
475
|
-
..._options?.headers || {}
|
|
476
|
-
}
|
|
480
|
+
headers
|
|
477
481
|
});
|
|
478
482
|
if (res && !res.code) {
|
|
479
483
|
return {
|
package/dist/query.d.ts
CHANGED
package/dist/query.js
CHANGED
|
@@ -203,6 +203,10 @@ 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
|
+
}
|
|
206
210
|
} catch (e) {
|
|
207
211
|
console.error("request beforeFn error", e, req);
|
|
208
212
|
return wrapperError({
|
|
@@ -263,20 +267,20 @@ class Query {
|
|
|
263
267
|
this.afterResponse = fn;
|
|
264
268
|
}
|
|
265
269
|
async fetchText(urlOrOptions, options) {
|
|
266
|
-
let _options = { ...options };
|
|
270
|
+
let _options = { method: "GET", ...options };
|
|
267
271
|
if (typeof urlOrOptions === "string" && !_options.url) {
|
|
268
272
|
_options.url = urlOrOptions;
|
|
269
273
|
}
|
|
270
274
|
if (typeof urlOrOptions === "object") {
|
|
271
275
|
_options = { ...urlOrOptions, ..._options };
|
|
272
276
|
}
|
|
277
|
+
const headers = { ...this.headers, ..._options.headers };
|
|
278
|
+
if (options?.token && !headers["Authorization"] && _options.method !== "GET") {
|
|
279
|
+
headers["Authorization"] = `Bearer ${options.token}`;
|
|
280
|
+
}
|
|
273
281
|
const res = await adapter({
|
|
274
|
-
method: "GET",
|
|
275
282
|
..._options,
|
|
276
|
-
headers
|
|
277
|
-
...this.headers,
|
|
278
|
-
..._options?.headers || {}
|
|
279
|
-
}
|
|
283
|
+
headers
|
|
280
284
|
});
|
|
281
285
|
if (res && !res.code) {
|
|
282
286
|
return {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kevisual/query",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.53",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "npm run clean && bun run bun.config.ts",
|
|
@@ -19,10 +19,10 @@
|
|
|
19
19
|
"description": "",
|
|
20
20
|
"devDependencies": {
|
|
21
21
|
"@kevisual/code-builder": "^0.0.6",
|
|
22
|
-
"@kevisual/router": "^0.0.
|
|
23
|
-
"@types/node": "^25.3.
|
|
22
|
+
"@kevisual/router": "^0.0.85",
|
|
23
|
+
"@types/node": "^25.3.5",
|
|
24
24
|
"typescript": "^5.9.3",
|
|
25
|
-
"es-toolkit": "^1.
|
|
25
|
+
"es-toolkit": "^1.45.1",
|
|
26
26
|
"zod": "^4.3.6",
|
|
27
27
|
"zustand": "^5.0.11"
|
|
28
28
|
},
|
package/src/query.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { adapter, Method, AdapterOpts } from './adapter.ts';
|
|
1
|
+
import { adapter, Method, AdapterOpts, methods } from './adapter.ts';
|
|
2
2
|
import type { QueryWs } from './ws.ts';
|
|
3
3
|
/**
|
|
4
4
|
* 请求前处理函数
|
|
@@ -15,6 +15,7 @@ export type Fn = (opts: {
|
|
|
15
15
|
|
|
16
16
|
export type QueryOpts = {
|
|
17
17
|
adapter?: typeof adapter;
|
|
18
|
+
token?: string;
|
|
18
19
|
[key: string]: any;
|
|
19
20
|
} & AdapterOpts;
|
|
20
21
|
|
|
@@ -155,6 +156,7 @@ export class Query {
|
|
|
155
156
|
const _beforeRequest = beforeRequest || this.beforeRequest;
|
|
156
157
|
const _afterResponse = afterResponse || this.afterResponse;
|
|
157
158
|
const _timeout = timeout || this.timeout;
|
|
159
|
+
|
|
158
160
|
const req = {
|
|
159
161
|
url: url,
|
|
160
162
|
headers: _headers,
|
|
@@ -182,6 +184,10 @@ export class Query {
|
|
|
182
184
|
});
|
|
183
185
|
}
|
|
184
186
|
}
|
|
187
|
+
const headers = req.headers || {};
|
|
188
|
+
if (options?.token && !headers['Authorization']) {
|
|
189
|
+
headers['Authorization'] = `Bearer ${options.token}`;
|
|
190
|
+
}
|
|
185
191
|
} catch (e) {
|
|
186
192
|
console.error('request beforeFn error', e, req);
|
|
187
193
|
return wrapperError({
|
|
@@ -254,20 +260,20 @@ export class Query {
|
|
|
254
260
|
this.afterResponse = fn;
|
|
255
261
|
}
|
|
256
262
|
async fetchText(urlOrOptions?: string | QueryOpts, options?: QueryOpts): Promise<Result<any>> {
|
|
257
|
-
let _options = { ...options };
|
|
263
|
+
let _options = { method: 'GET' as const, ...options };
|
|
258
264
|
if (typeof urlOrOptions === 'string' && !_options.url) {
|
|
259
265
|
_options.url = urlOrOptions;
|
|
260
266
|
}
|
|
261
267
|
if (typeof urlOrOptions === 'object') {
|
|
262
268
|
_options = { ...urlOrOptions, ..._options };
|
|
263
269
|
}
|
|
270
|
+
const headers = { ...this.headers, ..._options.headers };
|
|
271
|
+
if (options?.token && !headers['Authorization'] && _options.method !== 'GET') {
|
|
272
|
+
headers['Authorization'] = `Bearer ${options.token}`;
|
|
273
|
+
}
|
|
264
274
|
const res = await adapter({
|
|
265
|
-
method: 'GET',
|
|
266
275
|
..._options,
|
|
267
|
-
headers
|
|
268
|
-
...this.headers,
|
|
269
|
-
...(_options?.headers || {}),
|
|
270
|
-
},
|
|
276
|
+
headers,
|
|
271
277
|
});
|
|
272
278
|
if (res && !res.code) {
|
|
273
279
|
return {
|