From 013a399b7f9bdcbf5b011b17bf7d54f398da9aac Mon Sep 17 00:00:00 2001 From: abearxiong Date: Fri, 6 Mar 2026 23:11:10 +0800 Subject: [PATCH] chore: bump version to 0.0.53, update dependencies, and enhance query handling with token support --- package.json | 8 ++++---- pnpm-lock.yaml | 32 ++++++++++++++++---------------- src/query.ts | 20 +++++++++++++------- 3 files changed, 33 insertions(+), 27 deletions(-) diff --git a/package.json b/package.json index 2b1e78a..45c7dcd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@kevisual/query", - "version": "0.0.52", + "version": "0.0.53", "type": "module", "scripts": { "build": "npm run clean && bun run bun.config.ts", @@ -19,10 +19,10 @@ "description": "", "devDependencies": { "@kevisual/code-builder": "^0.0.6", - "@kevisual/router": "^0.0.84", - "@types/node": "^25.3.0", + "@kevisual/router": "^0.0.85", + "@types/node": "^25.3.5", "typescript": "^5.9.3", - "es-toolkit": "^1.44.0", + "es-toolkit": "^1.45.1", "zod": "^4.3.6", "zustand": "^5.0.11" }, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 0b6f2e4..6867f7b 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -12,14 +12,14 @@ importers: specifier: ^0.0.6 version: 0.0.6 '@kevisual/router': - specifier: ^0.0.84 - version: 0.0.84 + specifier: ^0.0.85 + version: 0.0.85 '@types/node': - specifier: ^25.3.0 - version: 25.3.0 + specifier: ^25.3.5 + version: 25.3.5 es-toolkit: - specifier: ^1.44.0 - version: 1.44.0 + specifier: ^1.45.1 + version: 1.45.1 typescript: specifier: ^5.9.3 version: 5.9.3 @@ -36,14 +36,14 @@ packages: resolution: {integrity: sha512-0aqATB31/yw4k4s5/xKnfr4DKbUnx8e3Z3BmKbiXTrc+CqWiWTdlGe9bKI9dZ2Df+xNp6g11W4xM2NICNyyCCw==} hasBin: true - '@kevisual/router@0.0.84': - resolution: {integrity: sha512-l/TUFuqTJegB/S3FZQRBMUoz0Spvg8EzV3C/kBi/VO9KKCzjqZDVvhZJJbTQh9879CBY6vUy1ajo9WcLYnwbNA==} + '@kevisual/router@0.0.85': + resolution: {integrity: sha512-ihSzPXHOMSOnZD/+Eso4yZMt4MoUXyLdfRHhXJGg90+sJBr/BjsmgAokit4pI9gWU+Rs/3JqQ2/aqA43FHtGoA==} - '@types/node@25.3.0': - resolution: {integrity: sha512-4K3bqJpXpqfg2XKGK9bpDTc6xO/xoUP/RBWS7AtRMug6zZFaRekiLzjVtAoZMquxoAbzBvy5nxQ7veS5eYzf8A==} + '@types/node@25.3.5': + resolution: {integrity: sha512-oX8xrhvpiyRCQkG1MFchB09f+cXftgIXb3a7UUa4Y3wpmZPw5tyZGTLWhlESOLq1Rq6oDlc8npVU2/9xiCuXMA==} - es-toolkit@1.44.0: - resolution: {integrity: sha512-6penXeZalaV88MM3cGkFZZfOoLGWshWWfdy0tWw/RlVVyhvMaWSBTOvXNeiW3e5FwdS5ePW0LGEu17zT139ktg==} + es-toolkit@1.45.1: + resolution: {integrity: sha512-/jhoOj/Fx+A+IIyDNOvO3TItGmlMKhtX8ISAHKE90c4b/k1tqaqEZ+uUqfpU8DMnW5cgNJv606zS55jGvza0Xw==} typescript@5.9.3: resolution: {integrity: sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw==} @@ -78,15 +78,15 @@ snapshots: '@kevisual/code-builder@0.0.6': {} - '@kevisual/router@0.0.84': + '@kevisual/router@0.0.85': dependencies: - es-toolkit: 1.44.0 + es-toolkit: 1.45.1 - '@types/node@25.3.0': + '@types/node@25.3.5': dependencies: undici-types: 7.18.2 - es-toolkit@1.44.0: {} + es-toolkit@1.45.1: {} typescript@5.9.3: {} diff --git a/src/query.ts b/src/query.ts index 9a45178..a8f4608 100644 --- a/src/query.ts +++ b/src/query.ts @@ -1,4 +1,4 @@ -import { adapter, Method, AdapterOpts } from './adapter.ts'; +import { adapter, Method, AdapterOpts, methods } from './adapter.ts'; import type { QueryWs } from './ws.ts'; /** * 请求前处理函数 @@ -15,6 +15,7 @@ export type Fn = (opts: { export type QueryOpts = { adapter?: typeof adapter; + token?: string; [key: string]: any; } & AdapterOpts; @@ -155,6 +156,7 @@ export class Query { const _beforeRequest = beforeRequest || this.beforeRequest; const _afterResponse = afterResponse || this.afterResponse; const _timeout = timeout || this.timeout; + const req = { url: url, headers: _headers, @@ -182,6 +184,10 @@ export class Query { }); } } + const headers = req.headers || {}; + if (options?.token && !headers['Authorization']) { + headers['Authorization'] = `Bearer ${options.token}`; + } } catch (e) { console.error('request beforeFn error', e, req); return wrapperError({ @@ -254,20 +260,20 @@ export class Query { this.afterResponse = fn; } async fetchText(urlOrOptions?: string | QueryOpts, options?: QueryOpts): Promise> { - let _options = { ...options }; + let _options = { method: 'GET' as const, ...options }; if (typeof urlOrOptions === 'string' && !_options.url) { _options.url = urlOrOptions; } if (typeof urlOrOptions === 'object') { _options = { ...urlOrOptions, ..._options }; } + const headers = { ...this.headers, ..._options.headers }; + if (options?.token && !headers['Authorization'] && _options.method !== 'GET') { + headers['Authorization'] = `Bearer ${options.token}`; + } const res = await adapter({ - method: 'GET', ..._options, - headers: { - ...this.headers, - ...(_options?.headers || {}), - }, + headers, }); if (res && !res.code) { return {