From ac32ff9d4ab248ca86a36f843597c42fc7a7cfa8 Mon Sep 17 00:00:00 2001 From: abearxiong Date: Fri, 24 Oct 2025 03:04:06 +0800 Subject: [PATCH] udpate --- package.json | 10 +++++----- src/app.ts | 15 ++++++++++++++- src/route.ts | 14 +++++++++++++- 3 files changed, 32 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index 490abde..5fbe150 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "$schema": "https://json.schemastore.org/package", "name": "@kevisual/router", - "version": "0.0.30", + "version": "0.0.31", "description": "", "type": "module", "main": "./dist/router.js", @@ -24,18 +24,18 @@ "@kevisual/local-proxy": "^0.0.6", "@kevisual/query": "^0.0.29", "@rollup/plugin-alias": "^5.1.1", - "@rollup/plugin-commonjs": "28.0.6", + "@rollup/plugin-commonjs": "28.0.8", "@rollup/plugin-node-resolve": "^16.0.3", - "@rollup/plugin-typescript": "^12.1.4", + "@rollup/plugin-typescript": "^12.3.0", "@types/lodash-es": "^4.17.12", - "@types/node": "^24.7.2", + "@types/node": "^24.9.1", "@types/send": "^1.2.0", "@types/ws": "^8.18.1", "@types/xml2js": "^0.4.14", "cookie": "^1.0.2", "lodash-es": "^4.17.21", "nanoid": "^5.1.6", - "rollup": "^4.52.4", + "rollup": "^4.52.5", "rollup-plugin-dts": "^6.2.3", "ts-loader": "^9.5.4", "ts-node": "^10.9.2", diff --git a/src/app.ts b/src/app.ts index 0e13700..548a6a6 100644 --- a/src/app.ts +++ b/src/app.ts @@ -5,7 +5,7 @@ import { CustomError } from './result/error.ts'; import { handleServer } from './server/handle-server.ts'; import { IncomingMessage, ServerResponse } from 'http'; -type RouterHandle = (msg: { path: string; [key: string]: any }) => { code: string; data?: any; message?: string; [key: string]: any }; +type RouterHandle = (msg: { path: string;[key: string]: any }) => { code: string; data?: any; message?: string;[key: string]: any }; type AppOptions = { router?: QueryRouter; server?: Server; @@ -82,6 +82,19 @@ export class App { } return new Route(path, key, opts); } + prompt(description: string): Route>; + prompt(description: Function): Route>; + prompt(...args: any[]) { + const [desc] = args; + let description = '' + if (typeof desc === 'string') { + description = desc; + } else if (typeof desc === 'function') { + description = desc() || ''; // 如果是Promise,需要addTo App之前就要获取应有的函数了。 + } + return new Route('', '', { description }); + } + async call(message: { id?: string, path?: string; key?: string; payload?: any }, ctx?: RouteContext & { [key: string]: any }) { const router = this.router; return await router.call(message, ctx); diff --git a/src/route.ts b/src/route.ts index 368d2ba..4cccd11 100644 --- a/src/route.ts +++ b/src/route.ts @@ -133,7 +133,7 @@ export class Route { * 是否开启debug,开启后会打印错误信息 */ isDebug?: boolean; - constructor(path: string, key: string = '', opts?: RouteOpts) { + constructor(path: string = '', key: string = '', opts?: RouteOpts) { if (!path) { path = nanoid(8) } @@ -767,6 +767,18 @@ export class QueryRouterServer extends QueryRouter { } return new Route(path, key, opts); } + prompt(description: string): Route>; + prompt(description: Function): Route>; + prompt(...args: any[]) { + const [desc] = args; + let description = '' + if (typeof desc === 'string') { + description = desc; + } else if (typeof desc === 'function') { + description = desc() || ''; // 如果是Promise,需要addTo App之前就要获取应有的函数了。 + } + return new Route('', '', { description }); + } /** * 等于queryRoute,但是调用了handle