@kevisual/api 0.0.8 → 0.0.10
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 +2 -1
- package/query/query-proxy/index.ts +37 -6
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kevisual/api",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.10",
|
|
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.2",
|
|
35
36
|
"@kevisual/load": "^0.0.6",
|
|
36
37
|
"es-toolkit": "^1.43.0",
|
|
37
38
|
"nanoid": "^5.1.6"
|
|
@@ -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
|
* 运行路由
|