更新版本至 0.0.44,新增从 JSON Schema 转换的功能,并优化路由初始化逻辑
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@kevisual/api",
|
||||
"version": "0.0.43",
|
||||
"version": "0.0.44",
|
||||
"description": "",
|
||||
"main": "mod.ts",
|
||||
"scripts": {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { QueryClient as Query, Result } from '@kevisual/query';
|
||||
import { QueryRouterServer, type App, type Route } from '@kevisual/router/browser';
|
||||
import { QueryRouterServer, type App, type Route, fromJSONSchema, toJSONSchema } from '@kevisual/router/browser';
|
||||
import { filter } from '@kevisual/js-filter'
|
||||
import { EventEmitter } from 'eventemitter3';
|
||||
import { initApi } from './router-api-proxy.ts';
|
||||
@@ -190,6 +190,7 @@ export class QueryProxy {
|
||||
|
||||
/**
|
||||
* 初始化路由
|
||||
* main
|
||||
* @returns
|
||||
*/
|
||||
async init() {
|
||||
@@ -246,6 +247,8 @@ export class QueryProxy {
|
||||
return
|
||||
}
|
||||
const routes = router.getList();
|
||||
// TODO: args
|
||||
// const args = fromJSONSchema(r);
|
||||
for (const r of routes) {
|
||||
console.debug(`注册路由: [${r.path}] ${r?.key}`, 'Context');
|
||||
let metadata = r.metadata || {};
|
||||
@@ -378,6 +381,13 @@ export class QueryProxy {
|
||||
return;
|
||||
}
|
||||
}
|
||||
getQueryByViewId(viewId: string): string | undefined {
|
||||
const view = this.views.find(v => v.id === viewId);
|
||||
if (view) {
|
||||
return view.query;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
/**
|
||||
* 列出路由
|
||||
* @param filter
|
||||
@@ -386,14 +396,10 @@ export class QueryProxy {
|
||||
*/
|
||||
async listRoutes(filterFn?: (item: Route) => boolean, opts?: { viewId?: string, query?: string }) {
|
||||
let query = opts?.query;
|
||||
if (opts?.viewId) {
|
||||
const view = this.views.find(v => v.id === opts.viewId);
|
||||
if (view) {
|
||||
query = view.query;
|
||||
}
|
||||
} if (opts?.query) {
|
||||
query = opts.query;
|
||||
if (opts?.viewId && !query) {
|
||||
query = this.getQueryByViewId(opts.viewId);
|
||||
}
|
||||
|
||||
const routes = this.router.routes.filter(filterFn || (() => true));
|
||||
if (query) {
|
||||
if (query.toLocaleUpperCase().startsWith('WHERE')) {
|
||||
|
||||
Reference in New Issue
Block a user