更新版本至 0.0.44,新增从 JSON Schema 转换的功能,并优化路由初始化逻辑

This commit is contained in:
2026-02-03 02:54:52 +08:00
parent 2fec4dd04e
commit 2d7375e32d
2 changed files with 15 additions and 9 deletions

View File

@@ -1,6 +1,6 @@
{ {
"name": "@kevisual/api", "name": "@kevisual/api",
"version": "0.0.43", "version": "0.0.44",
"description": "", "description": "",
"main": "mod.ts", "main": "mod.ts",
"scripts": { "scripts": {

View File

@@ -1,5 +1,5 @@
import { QueryClient as Query, Result } from '@kevisual/query'; 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 { filter } from '@kevisual/js-filter'
import { EventEmitter } from 'eventemitter3'; import { EventEmitter } from 'eventemitter3';
import { initApi } from './router-api-proxy.ts'; import { initApi } from './router-api-proxy.ts';
@@ -190,6 +190,7 @@ export class QueryProxy {
/** /**
* 初始化路由 * 初始化路由
* main
* @returns * @returns
*/ */
async init() { async init() {
@@ -246,6 +247,8 @@ export class QueryProxy {
return return
} }
const routes = router.getList(); const routes = router.getList();
// TODO: args
// const args = fromJSONSchema(r);
for (const r of routes) { for (const r of routes) {
console.debug(`注册路由: [${r.path}] ${r?.key}`, 'Context'); console.debug(`注册路由: [${r.path}] ${r?.key}`, 'Context');
let metadata = r.metadata || {}; let metadata = r.metadata || {};
@@ -378,6 +381,13 @@ export class QueryProxy {
return; return;
} }
} }
getQueryByViewId(viewId: string): string | undefined {
const view = this.views.find(v => v.id === viewId);
if (view) {
return view.query;
}
return undefined;
}
/** /**
* 列出路由 * 列出路由
* @param filter * @param filter
@@ -386,14 +396,10 @@ export class QueryProxy {
*/ */
async listRoutes(filterFn?: (item: Route) => boolean, opts?: { viewId?: string, query?: string }) { async listRoutes(filterFn?: (item: Route) => boolean, opts?: { viewId?: string, query?: string }) {
let query = opts?.query; let query = opts?.query;
if (opts?.viewId) { if (opts?.viewId && !query) {
const view = this.views.find(v => v.id === opts.viewId); query = this.getQueryByViewId(opts.viewId);
if (view) {
query = view.query;
}
} if (opts?.query) {
query = opts.query;
} }
const routes = this.router.routes.filter(filterFn || (() => true)); const routes = this.router.routes.filter(filterFn || (() => true));
if (query) { if (query) {
if (query.toLocaleUpperCase().startsWith('WHERE')) { if (query.toLocaleUpperCase().startsWith('WHERE')) {