@kevisual/api 0.0.53 → 0.0.55
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-login-node.d.ts +9 -11
- package/dist/query-login-node.js +2 -10
- package/dist/query-login.d.ts +6 -6
- package/package.json +2 -1
- package/query/query-login/login-cache.ts +6 -6
- package/query/query-login/login-node-cache.ts +2 -8
- package/query/query-login/query-login-node.ts +1 -1
- package/query/query-login/query-login.ts +6 -6
|
@@ -39,7 +39,7 @@ type CacheLoginUser = {
|
|
|
39
39
|
type CacheLogin = {
|
|
40
40
|
loginUsers: CacheLoginUser[];
|
|
41
41
|
} & CacheLoginUser;
|
|
42
|
-
type CacheStore<T = Cache> = {
|
|
42
|
+
type CacheStore<T extends Cache = Cache> = {
|
|
43
43
|
name: string;
|
|
44
44
|
/**
|
|
45
45
|
* 缓存数据
|
|
@@ -84,12 +84,12 @@ type CacheStore<T = Cache> = {
|
|
|
84
84
|
init(): Promise<any>;
|
|
85
85
|
};
|
|
86
86
|
|
|
87
|
-
type QueryLoginOpts = {
|
|
87
|
+
type QueryLoginOpts<T extends Cache = Cache> = {
|
|
88
88
|
query?: Query;
|
|
89
89
|
isBrowser?: boolean;
|
|
90
90
|
onLoad?: () => void;
|
|
91
91
|
storage?: Storage;
|
|
92
|
-
cache:
|
|
92
|
+
cache: T;
|
|
93
93
|
};
|
|
94
94
|
type QueryLoginData = {
|
|
95
95
|
username?: string;
|
|
@@ -100,16 +100,16 @@ type QueryLoginResult = {
|
|
|
100
100
|
accessToken: string;
|
|
101
101
|
refreshToken: string;
|
|
102
102
|
};
|
|
103
|
-
declare class QueryLogin extends BaseQuery {
|
|
103
|
+
declare class QueryLogin<T extends Cache = Cache> extends BaseQuery {
|
|
104
104
|
/**
|
|
105
105
|
* query login cache, 非实际操作, 一个cache的包裹模块
|
|
106
106
|
*/
|
|
107
|
-
cacheStore: CacheStore
|
|
107
|
+
cacheStore: CacheStore<T>;
|
|
108
108
|
isBrowser: boolean;
|
|
109
109
|
load?: boolean;
|
|
110
110
|
storage: Storage;
|
|
111
111
|
onLoad?: () => void;
|
|
112
|
-
constructor(opts?: QueryLoginOpts);
|
|
112
|
+
constructor(opts?: QueryLoginOpts<T>);
|
|
113
113
|
setQuery(query: Query): void;
|
|
114
114
|
private init;
|
|
115
115
|
post<T = any>(data: any, opts?: DataOpts): Promise<any>;
|
|
@@ -299,7 +299,6 @@ declare class StorageNode implements Storage {
|
|
|
299
299
|
cacheData: any;
|
|
300
300
|
filePath: string;
|
|
301
301
|
hostname: string;
|
|
302
|
-
isLoaded: boolean;
|
|
303
302
|
constructor(opts?: {
|
|
304
303
|
baseURL?: string;
|
|
305
304
|
load?: boolean;
|
|
@@ -307,7 +306,7 @@ declare class StorageNode implements Storage {
|
|
|
307
306
|
setHostName(hostname: string, opts?: {
|
|
308
307
|
load?: boolean;
|
|
309
308
|
}): void;
|
|
310
|
-
loadCache(
|
|
309
|
+
loadCache(): void;
|
|
311
310
|
get length(): number;
|
|
312
311
|
getItem(key: string): any;
|
|
313
312
|
setItem(key: string, value: any): void;
|
|
@@ -317,7 +316,6 @@ declare class StorageNode implements Storage {
|
|
|
317
316
|
}
|
|
318
317
|
declare class LoginNodeCache implements Cache {
|
|
319
318
|
filepath: string;
|
|
320
|
-
isLoaded: boolean;
|
|
321
319
|
constructor(opts?: {
|
|
322
320
|
baseURL?: string;
|
|
323
321
|
load?: boolean;
|
|
@@ -325,14 +323,14 @@ declare class LoginNodeCache implements Cache {
|
|
|
325
323
|
get(_key: string): Promise<any>;
|
|
326
324
|
set(_key: string, value: any): Promise<void>;
|
|
327
325
|
del(): Promise<void>;
|
|
328
|
-
loadCache(filePath: string
|
|
326
|
+
loadCache(filePath: string): any;
|
|
329
327
|
init(): any;
|
|
330
328
|
}
|
|
331
329
|
|
|
332
330
|
type QueryLoginNodeOptsWithoutCache = Omit<QueryLoginOpts, 'cache'>;
|
|
333
331
|
|
|
334
332
|
declare const cache: LoginNodeCache;
|
|
335
|
-
declare class QueryLoginNode extends QueryLogin {
|
|
333
|
+
declare class QueryLoginNode extends QueryLogin<LoginNodeCache> {
|
|
336
334
|
storage: StorageNode;
|
|
337
335
|
constructor(opts: QueryLoginNodeOptsWithoutCache);
|
|
338
336
|
}
|
package/dist/query-login-node.js
CHANGED
|
@@ -1244,7 +1244,6 @@ class StorageNode {
|
|
|
1244
1244
|
cacheData;
|
|
1245
1245
|
filePath = "";
|
|
1246
1246
|
hostname = "";
|
|
1247
|
-
isLoaded = false;
|
|
1248
1247
|
constructor(opts) {
|
|
1249
1248
|
this.cacheData = {};
|
|
1250
1249
|
const hostname = getHostName(opts?.baseURL);
|
|
@@ -1263,14 +1262,11 @@ class StorageNode {
|
|
|
1263
1262
|
this.loadCache();
|
|
1264
1263
|
}
|
|
1265
1264
|
}
|
|
1266
|
-
loadCache(
|
|
1267
|
-
if (this.isLoaded && !force)
|
|
1268
|
-
return;
|
|
1265
|
+
loadCache() {
|
|
1269
1266
|
const filePath = this.filePath;
|
|
1270
1267
|
try {
|
|
1271
1268
|
const data = readConfigFile(filePath);
|
|
1272
1269
|
this.cacheData = data;
|
|
1273
|
-
this.isLoaded = true;
|
|
1274
1270
|
} catch (error) {
|
|
1275
1271
|
this.cacheData = {};
|
|
1276
1272
|
writeFileSync(filePath, JSON.stringify(this.cacheData, null, 2));
|
|
@@ -1301,7 +1297,6 @@ class StorageNode {
|
|
|
1301
1297
|
|
|
1302
1298
|
class LoginNodeCache {
|
|
1303
1299
|
filepath;
|
|
1304
|
-
isLoaded = false;
|
|
1305
1300
|
constructor(opts) {
|
|
1306
1301
|
this.filepath = join(homedir(), ".config", "envision", "config", `${getHostName(opts?.baseURL)}-login.json`);
|
|
1307
1302
|
fileExists(this.filepath, { isFile: true });
|
|
@@ -1331,13 +1326,10 @@ class LoginNodeCache {
|
|
|
1331
1326
|
async del() {
|
|
1332
1327
|
unlinkSync(this.filepath);
|
|
1333
1328
|
}
|
|
1334
|
-
loadCache(filePath
|
|
1335
|
-
if (this.isLoaded && !force)
|
|
1336
|
-
return;
|
|
1329
|
+
loadCache(filePath) {
|
|
1337
1330
|
try {
|
|
1338
1331
|
const data = readFileSync(filePath, "utf-8");
|
|
1339
1332
|
const jsonData = JSON.parse(data);
|
|
1340
|
-
this.isLoaded = true;
|
|
1341
1333
|
return jsonData;
|
|
1342
1334
|
} catch (error) {
|
|
1343
1335
|
console.log("create new cache file:", filePath);
|
package/dist/query-login.d.ts
CHANGED
|
@@ -39,7 +39,7 @@ type CacheLoginUser = {
|
|
|
39
39
|
type CacheLogin = {
|
|
40
40
|
loginUsers: CacheLoginUser[];
|
|
41
41
|
} & CacheLoginUser;
|
|
42
|
-
type CacheStore<T = Cache> = {
|
|
42
|
+
type CacheStore<T extends Cache = Cache> = {
|
|
43
43
|
name: string;
|
|
44
44
|
/**
|
|
45
45
|
* 缓存数据
|
|
@@ -84,12 +84,12 @@ type CacheStore<T = Cache> = {
|
|
|
84
84
|
init(): Promise<any>;
|
|
85
85
|
};
|
|
86
86
|
|
|
87
|
-
type QueryLoginOpts = {
|
|
87
|
+
type QueryLoginOpts<T extends Cache = Cache> = {
|
|
88
88
|
query?: Query;
|
|
89
89
|
isBrowser?: boolean;
|
|
90
90
|
onLoad?: () => void;
|
|
91
91
|
storage?: Storage;
|
|
92
|
-
cache:
|
|
92
|
+
cache: T;
|
|
93
93
|
};
|
|
94
94
|
type QueryLoginData = {
|
|
95
95
|
username?: string;
|
|
@@ -100,16 +100,16 @@ type QueryLoginResult = {
|
|
|
100
100
|
accessToken: string;
|
|
101
101
|
refreshToken: string;
|
|
102
102
|
};
|
|
103
|
-
declare class QueryLogin extends BaseQuery {
|
|
103
|
+
declare class QueryLogin<T extends Cache = Cache> extends BaseQuery {
|
|
104
104
|
/**
|
|
105
105
|
* query login cache, 非实际操作, 一个cache的包裹模块
|
|
106
106
|
*/
|
|
107
|
-
cacheStore: CacheStore
|
|
107
|
+
cacheStore: CacheStore<T>;
|
|
108
108
|
isBrowser: boolean;
|
|
109
109
|
load?: boolean;
|
|
110
110
|
storage: Storage;
|
|
111
111
|
onLoad?: () => void;
|
|
112
|
-
constructor(opts?: QueryLoginOpts);
|
|
112
|
+
constructor(opts?: QueryLoginOpts<T>);
|
|
113
113
|
setQuery(query: Query): void;
|
|
114
114
|
private init;
|
|
115
115
|
post<T = any>(data: any, opts?: DataOpts): Promise<any>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kevisual/api",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.55",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "mod.ts",
|
|
6
6
|
"scripts": {
|
|
@@ -58,6 +58,7 @@
|
|
|
58
58
|
"./secret": "./query/query-secret/index.ts",
|
|
59
59
|
"./resources": "./query/query-resources/index.ts",
|
|
60
60
|
"./utils-node": "./dist/utils-node.js",
|
|
61
|
+
"./query-login-node": "./dist/query-login-node.js",
|
|
61
62
|
"./utils": "./dist/utils.js",
|
|
62
63
|
"./query-secret": "./dist/query-secret.js",
|
|
63
64
|
"./query-mark": "./dist/query-mark.js",
|
|
@@ -38,7 +38,7 @@ type CacheLogin = {
|
|
|
38
38
|
loginUsers: CacheLoginUser[];
|
|
39
39
|
} & CacheLoginUser;
|
|
40
40
|
|
|
41
|
-
export type CacheStore<T = Cache> = {
|
|
41
|
+
export type CacheStore<T extends Cache = Cache> = {
|
|
42
42
|
name: string;
|
|
43
43
|
/**
|
|
44
44
|
* 缓存数据
|
|
@@ -85,15 +85,15 @@ export type CacheStore<T = Cache> = {
|
|
|
85
85
|
init(): Promise<any>;
|
|
86
86
|
};
|
|
87
87
|
|
|
88
|
-
export type LoginCacheStoreOpts = {
|
|
88
|
+
export type LoginCacheStoreOpts<T extends Cache = Cache> = {
|
|
89
89
|
name: string;
|
|
90
|
-
cache:
|
|
90
|
+
cache: T;
|
|
91
91
|
};
|
|
92
|
-
export class LoginCacheStore implements CacheStore<
|
|
93
|
-
cache:
|
|
92
|
+
export class LoginCacheStore<T extends Cache = Cache> implements CacheStore<T> {
|
|
93
|
+
cache: T;
|
|
94
94
|
name: string;
|
|
95
95
|
cacheData: CacheLogin;
|
|
96
|
-
constructor(opts: LoginCacheStoreOpts) {
|
|
96
|
+
constructor(opts: LoginCacheStoreOpts<T>) {
|
|
97
97
|
if (!opts.cache) {
|
|
98
98
|
throw new Error('cache is required');
|
|
99
99
|
}
|
|
@@ -51,7 +51,6 @@ export class StorageNode implements Storage {
|
|
|
51
51
|
cacheData: any;
|
|
52
52
|
filePath: string = '';
|
|
53
53
|
hostname: string = '';
|
|
54
|
-
isLoaded: boolean = false;
|
|
55
54
|
constructor(opts?: { baseURL?: string, load?: boolean }) {
|
|
56
55
|
this.cacheData = {};
|
|
57
56
|
const hostname = getHostName(opts?.baseURL);
|
|
@@ -70,13 +69,11 @@ export class StorageNode implements Storage {
|
|
|
70
69
|
this.loadCache();
|
|
71
70
|
}
|
|
72
71
|
}
|
|
73
|
-
loadCache(
|
|
74
|
-
if (this.isLoaded && !force) return;
|
|
72
|
+
loadCache() {
|
|
75
73
|
const filePath = this.filePath;
|
|
76
74
|
try {
|
|
77
75
|
const data = readConfigFile(filePath);
|
|
78
76
|
this.cacheData = data;
|
|
79
|
-
this.isLoaded = true;
|
|
80
77
|
} catch (error) {
|
|
81
78
|
this.cacheData = {};
|
|
82
79
|
writeFileSync(filePath, JSON.stringify(this.cacheData, null, 2));
|
|
@@ -106,7 +103,6 @@ export class StorageNode implements Storage {
|
|
|
106
103
|
}
|
|
107
104
|
export class LoginNodeCache implements Cache {
|
|
108
105
|
filepath: string;
|
|
109
|
-
isLoaded: boolean = false;
|
|
110
106
|
constructor(opts?: { baseURL?: string, load?: boolean }) {
|
|
111
107
|
this.filepath = join(homedir(), '.config', 'envision', 'config', `${getHostName(opts?.baseURL)}-login.json`);
|
|
112
108
|
fileExists(this.filepath, { isFile: true });
|
|
@@ -136,12 +132,10 @@ export class LoginNodeCache implements Cache {
|
|
|
136
132
|
async del() {
|
|
137
133
|
unlinkSync(this.filepath);
|
|
138
134
|
}
|
|
139
|
-
loadCache(filePath: string
|
|
140
|
-
if (this.isLoaded && !force) return;
|
|
135
|
+
loadCache(filePath: string) {
|
|
141
136
|
try {
|
|
142
137
|
const data = readFileSync(filePath, 'utf-8');
|
|
143
138
|
const jsonData = JSON.parse(data);
|
|
144
|
-
this.isLoaded = true;
|
|
145
139
|
return jsonData;
|
|
146
140
|
} catch (error) {
|
|
147
141
|
// console.log('loadCache error', error);
|
|
@@ -3,7 +3,7 @@ import { LoginNodeCache, StorageNode } from './login-node-cache.ts';
|
|
|
3
3
|
type QueryLoginNodeOptsWithoutCache = Omit<QueryLoginOpts, 'cache'>;
|
|
4
4
|
export { StorageNode }
|
|
5
5
|
export const cache = new LoginNodeCache();
|
|
6
|
-
export class QueryLoginNode extends QueryLogin {
|
|
6
|
+
export class QueryLoginNode extends QueryLogin<LoginNodeCache> {
|
|
7
7
|
declare storage: StorageNode;
|
|
8
8
|
constructor(opts: QueryLoginNodeOptsWithoutCache) {
|
|
9
9
|
const baseURL = opts?.query?.baseURL;
|
|
@@ -3,12 +3,12 @@ import type { Result, DataOpts } from '@kevisual/query/query';
|
|
|
3
3
|
import { LoginCacheStore, CacheStore } from './login-cache.ts';
|
|
4
4
|
import { Cache } from './login-cache.ts';
|
|
5
5
|
import { BaseLoad } from '@kevisual/load';
|
|
6
|
-
export type QueryLoginOpts = {
|
|
6
|
+
export type QueryLoginOpts<T extends Cache = Cache> = {
|
|
7
7
|
query?: Query;
|
|
8
8
|
isBrowser?: boolean;
|
|
9
9
|
onLoad?: () => void;
|
|
10
10
|
storage?: Storage;
|
|
11
|
-
cache:
|
|
11
|
+
cache: T;
|
|
12
12
|
};
|
|
13
13
|
export type QueryLoginData = {
|
|
14
14
|
username?: string;
|
|
@@ -20,21 +20,21 @@ export type QueryLoginResult = {
|
|
|
20
20
|
refreshToken: string;
|
|
21
21
|
};
|
|
22
22
|
|
|
23
|
-
export class QueryLogin extends BaseQuery {
|
|
23
|
+
export class QueryLogin<T extends Cache = Cache> extends BaseQuery {
|
|
24
24
|
/**
|
|
25
25
|
* query login cache, 非实际操作, 一个cache的包裹模块
|
|
26
26
|
*/
|
|
27
|
-
cacheStore: CacheStore
|
|
27
|
+
cacheStore: CacheStore<T>;
|
|
28
28
|
isBrowser: boolean;
|
|
29
29
|
load?: boolean;
|
|
30
30
|
storage: Storage;
|
|
31
31
|
onLoad?: () => void;
|
|
32
32
|
|
|
33
|
-
constructor(opts?: QueryLoginOpts) {
|
|
33
|
+
constructor(opts?: QueryLoginOpts<T>) {
|
|
34
34
|
super({
|
|
35
35
|
query: opts?.query || new Query(),
|
|
36
36
|
});
|
|
37
|
-
this.cacheStore = new LoginCacheStore({ name: 'login', cache: opts?.cache! });
|
|
37
|
+
this.cacheStore = new LoginCacheStore<T>({ name: 'login', cache: opts?.cache! });
|
|
38
38
|
this.isBrowser = opts?.isBrowser ?? true;
|
|
39
39
|
this.init();
|
|
40
40
|
this.onLoad = opts?.onLoad;
|