diff --git a/package.json b/package.json index 060fc5c..ae37d3c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@kevisual/api", - "version": "0.0.43", + "version": "0.0.44", "description": "", "main": "mod.ts", "scripts": { diff --git a/query/query-proxy/proxy.ts b/query/query-proxy/proxy.ts index cf884d3..9c0cf7a 100644 --- a/query/query-proxy/proxy.ts +++ b/query/query-proxy/proxy.ts @@ -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')) {