From 15fd2d3dc805939603a60d158be052e74a60f80e Mon Sep 17 00:00:00 2001 From: abearxiong Date: Sat, 21 Feb 2026 02:24:07 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=9B=B4=E6=96=B0=E7=89=88=E6=9C=AC?= =?UTF-8?q?=E8=87=B3=200.0.55=EF=BC=8C=E5=A2=9E=E5=BC=BA=E7=B1=BB=E5=9E=8B?= =?UTF-8?q?=E6=94=AF=E6=8C=81=EF=BC=8C=E4=BC=98=E5=8C=96=E7=99=BB=E5=BD=95?= =?UTF-8?q?=E7=BC=93=E5=AD=98=E7=9B=B8=E5=85=B3=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- query/query-login/login-cache.ts | 12 ++++++------ query/query-login/login-node-cache.ts | 10 ++-------- query/query-login/query-login-node.ts | 2 +- query/query-login/query-login.ts | 12 ++++++------ 5 files changed, 16 insertions(+), 22 deletions(-) diff --git a/package.json b/package.json index eaacde1..252ad84 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@kevisual/api", - "version": "0.0.54", + "version": "0.0.55", "description": "", "main": "mod.ts", "scripts": { diff --git a/query/query-login/login-cache.ts b/query/query-login/login-cache.ts index 31d6012..4eeee34 100644 --- a/query/query-login/login-cache.ts +++ b/query/query-login/login-cache.ts @@ -38,7 +38,7 @@ type CacheLogin = { loginUsers: CacheLoginUser[]; } & CacheLoginUser; -export type CacheStore = { +export type CacheStore = { name: string; /** * 缓存数据 @@ -85,15 +85,15 @@ export type CacheStore = { init(): Promise; }; -export type LoginCacheStoreOpts = { +export type LoginCacheStoreOpts = { name: string; - cache: Cache; + cache: T; }; -export class LoginCacheStore implements CacheStore { - cache: Cache; +export class LoginCacheStore implements CacheStore { + cache: T; name: string; cacheData: CacheLogin; - constructor(opts: LoginCacheStoreOpts) { + constructor(opts: LoginCacheStoreOpts) { if (!opts.cache) { throw new Error('cache is required'); } diff --git a/query/query-login/login-node-cache.ts b/query/query-login/login-node-cache.ts index e71438d..359cd0f 100644 --- a/query/query-login/login-node-cache.ts +++ b/query/query-login/login-node-cache.ts @@ -51,7 +51,6 @@ export class StorageNode implements Storage { cacheData: any; filePath: string = ''; hostname: string = ''; - isLoaded: boolean = false; constructor(opts?: { baseURL?: string, load?: boolean }) { this.cacheData = {}; const hostname = getHostName(opts?.baseURL); @@ -70,13 +69,11 @@ export class StorageNode implements Storage { this.loadCache(); } } - loadCache(force?: boolean) { - if (this.isLoaded && !force) return; + loadCache() { const filePath = this.filePath; try { const data = readConfigFile(filePath); this.cacheData = data; - this.isLoaded = true; } catch (error) { this.cacheData = {}; writeFileSync(filePath, JSON.stringify(this.cacheData, null, 2)); @@ -106,7 +103,6 @@ export class StorageNode implements Storage { } export class LoginNodeCache implements Cache { filepath: string; - isLoaded: boolean = false; constructor(opts?: { baseURL?: string, load?: boolean }) { this.filepath = join(homedir(), '.config', 'envision', 'config', `${getHostName(opts?.baseURL)}-login.json`); fileExists(this.filepath, { isFile: true }); @@ -136,12 +132,10 @@ export class LoginNodeCache implements Cache { async del() { unlinkSync(this.filepath); } - loadCache(filePath: string, force?: boolean) { - if (this.isLoaded && !force) return; + loadCache(filePath: string) { try { const data = readFileSync(filePath, 'utf-8'); const jsonData = JSON.parse(data); - this.isLoaded = true; return jsonData; } catch (error) { // console.log('loadCache error', error); diff --git a/query/query-login/query-login-node.ts b/query/query-login/query-login-node.ts index 9ca5cd1..099a072 100644 --- a/query/query-login/query-login-node.ts +++ b/query/query-login/query-login-node.ts @@ -3,7 +3,7 @@ import { LoginNodeCache, StorageNode } from './login-node-cache.ts'; type QueryLoginNodeOptsWithoutCache = Omit; export { StorageNode } export const cache = new LoginNodeCache(); -export class QueryLoginNode extends QueryLogin { +export class QueryLoginNode extends QueryLogin { declare storage: StorageNode; constructor(opts: QueryLoginNodeOptsWithoutCache) { const baseURL = opts?.query?.baseURL; diff --git a/query/query-login/query-login.ts b/query/query-login/query-login.ts index f9d7fb7..ea08c8b 100644 --- a/query/query-login/query-login.ts +++ b/query/query-login/query-login.ts @@ -3,12 +3,12 @@ import type { Result, DataOpts } from '@kevisual/query/query'; import { LoginCacheStore, CacheStore } from './login-cache.ts'; import { Cache } from './login-cache.ts'; import { BaseLoad } from '@kevisual/load'; -export type QueryLoginOpts = { +export type QueryLoginOpts = { query?: Query; isBrowser?: boolean; onLoad?: () => void; storage?: Storage; - cache: Cache; + cache: T; }; export type QueryLoginData = { username?: string; @@ -20,21 +20,21 @@ export type QueryLoginResult = { refreshToken: string; }; -export class QueryLogin extends BaseQuery { +export class QueryLogin extends BaseQuery { /** * query login cache, 非实际操作, 一个cache的包裹模块 */ - cacheStore: CacheStore; + cacheStore: CacheStore; isBrowser: boolean; load?: boolean; storage: Storage; onLoad?: () => void; - constructor(opts?: QueryLoginOpts) { + constructor(opts?: QueryLoginOpts) { super({ query: opts?.query || new Query(), }); - this.cacheStore = new LoginCacheStore({ name: 'login', cache: opts?.cache! }); + this.cacheStore = new LoginCacheStore({ name: 'login', cache: opts?.cache! }); this.isBrowser = opts?.isBrowser ?? true; this.init(); this.onLoad = opts?.onLoad;