@kevisual/api 0.0.7 → 0.0.9
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kevisual/api",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.9",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "mod.ts",
|
|
6
6
|
"scripts": {
|
|
@@ -32,6 +32,7 @@
|
|
|
32
32
|
"fast-glob": "^3.3.3"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
+
"@kevisual/js-filter": "^0.0.1",
|
|
35
36
|
"@kevisual/load": "^0.0.6",
|
|
36
37
|
"es-toolkit": "^1.43.0",
|
|
37
38
|
"nanoid": "^5.1.6"
|
|
@@ -40,6 +41,8 @@
|
|
|
40
41
|
".": "./mod.ts",
|
|
41
42
|
"./login": "./query/query-login/query-login-browser.ts",
|
|
42
43
|
"./login-node": "./query/query-login/query-login-node.ts",
|
|
44
|
+
"./config": "./query/query-config/query-config.ts",
|
|
45
|
+
"./proxy": "./query/query-proxy/index.ts",
|
|
43
46
|
"./query/**/*.ts": "./query/**/*.ts"
|
|
44
47
|
}
|
|
45
48
|
}
|
|
@@ -479,12 +479,13 @@ await pollLoginStatus(res.token, { tokenSecret: res.tokenSecret });
|
|
|
479
479
|
if (res.code === 200 && res.data?.code === 200) {
|
|
480
480
|
try {
|
|
481
481
|
console.log('网页登录成功');
|
|
482
|
-
return;
|
|
482
|
+
return true;
|
|
483
483
|
} catch (error) {
|
|
484
484
|
console.log('登录失败', error);
|
|
485
|
-
return;
|
|
485
|
+
return false;
|
|
486
486
|
}
|
|
487
487
|
}
|
|
488
488
|
console.log('登录失败', res);
|
|
489
|
+
return false;
|
|
489
490
|
}
|
|
490
491
|
}
|
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
import { Query } from '@kevisual/query/query';
|
|
2
2
|
import { QueryRouterServer, Route } from '@kevisual/router/src/route.ts';
|
|
3
|
+
import { filter } from '@kevisual/js-filter'
|
|
4
|
+
export type ProxyItem = {
|
|
5
|
+
title?: string;
|
|
6
|
+
type?: 'api' | 'context' | 'page';
|
|
7
|
+
description?: string;
|
|
8
|
+
api?: {
|
|
9
|
+
url: string;
|
|
10
|
+
},
|
|
11
|
+
context?: {
|
|
12
|
+
key: string;
|
|
13
|
+
},
|
|
14
|
+
page?: {},
|
|
15
|
+
where?: string;
|
|
16
|
+
whereList?: Array<{ title: string; where: string }>;
|
|
17
|
+
}
|
|
18
|
+
|
|
3
19
|
export class QueryProxy {
|
|
4
20
|
query: Query;
|
|
5
21
|
router: QueryRouterServer;
|
|
@@ -7,7 +23,16 @@ export class QueryProxy {
|
|
|
7
23
|
constructor(opts?: { query: Query, router?: QueryRouterServer, token?: string }) {
|
|
8
24
|
this.query = opts?.query || new Query();
|
|
9
25
|
this.router = opts?.router || new QueryRouterServer();
|
|
10
|
-
this.token = opts?.token;
|
|
26
|
+
this.token = opts?.token || this.getDefulatToken();
|
|
27
|
+
}
|
|
28
|
+
getDefulatToken() {
|
|
29
|
+
try {
|
|
30
|
+
if (localStorage) {
|
|
31
|
+
return localStorage.getItem('token') || undefined;
|
|
32
|
+
}
|
|
33
|
+
} catch (e) {
|
|
34
|
+
return undefined;
|
|
35
|
+
}
|
|
11
36
|
}
|
|
12
37
|
/**
|
|
13
38
|
* 初始化路由
|
|
@@ -22,11 +47,12 @@ export class QueryProxy {
|
|
|
22
47
|
}
|
|
23
48
|
const _list = res.data?.list || []
|
|
24
49
|
for (const item of _list) {
|
|
25
|
-
if (item.path
|
|
26
|
-
console.log(`Register route: [${item.path}] ${item
|
|
50
|
+
if (item.path || item.id) {
|
|
51
|
+
console.log(`Register route: [${item.path}] ${item?.key}`);
|
|
27
52
|
this.router.route({
|
|
28
53
|
path: item.path,
|
|
29
|
-
key: item.key,
|
|
54
|
+
key: item.key || '',
|
|
55
|
+
id: item.id,
|
|
30
56
|
description: item.description,
|
|
31
57
|
metadata: item.metadata,
|
|
32
58
|
}).define(async (ctx) => {
|
|
@@ -43,10 +69,15 @@ export class QueryProxy {
|
|
|
43
69
|
/**
|
|
44
70
|
* 列出路由
|
|
45
71
|
* @param filter
|
|
72
|
+
* @param query WHERE metadata.tags CONTAINS 'premium'
|
|
46
73
|
* @returns
|
|
47
74
|
*/
|
|
48
|
-
async listRoutes(
|
|
49
|
-
|
|
75
|
+
async listRoutes(filterFn?: (item: Route) => boolean, query?: string) {
|
|
76
|
+
const routes = this.router.routes.filter(filterFn || (() => true));
|
|
77
|
+
if (query) {
|
|
78
|
+
return filter(routes, query);
|
|
79
|
+
}
|
|
80
|
+
return routes;
|
|
50
81
|
}
|
|
51
82
|
/**
|
|
52
83
|
* 运行路由
|