imean-service-engine 2.0.0 → 2.0.2
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/dist/index.d.mts +77 -52
- package/dist/index.d.ts +77 -52
- package/dist/index.js +2078 -1945
- package/dist/index.mjs +2076 -1944
- package/package.json +9 -2
- package/.vscode/settings.json +0 -8
- package/src/core/checker.ts +0 -33
- package/src/core/decorators.test.ts +0 -96
- package/src/core/decorators.ts +0 -68
- package/src/core/engine.test.ts +0 -218
- package/src/core/engine.ts +0 -635
- package/src/core/errors.ts +0 -28
- package/src/core/factory.test.ts +0 -73
- package/src/core/factory.ts +0 -92
- package/src/core/logger.ts +0 -65
- package/src/core/testing.ts +0 -73
- package/src/core/types.ts +0 -191
- package/src/index.ts +0 -49
- package/src/metadata/README.md +0 -422
- package/src/metadata/metadata.test.ts +0 -369
- package/src/metadata/metadata.ts +0 -512
- package/src/plugins/action/action-plugin.test.ts +0 -660
- package/src/plugins/action/decorator.ts +0 -14
- package/src/plugins/action/index.ts +0 -4
- package/src/plugins/action/plugin.ts +0 -349
- package/src/plugins/action/types.ts +0 -49
- package/src/plugins/action/utils.test.ts +0 -196
- package/src/plugins/action/utils.ts +0 -111
- package/src/plugins/cache/adapter.test.ts +0 -689
- package/src/plugins/cache/adapter.ts +0 -324
- package/src/plugins/cache/cache-plugin.test.ts +0 -269
- package/src/plugins/cache/decorator.ts +0 -26
- package/src/plugins/cache/index.ts +0 -20
- package/src/plugins/cache/plugin.ts +0 -299
- package/src/plugins/cache/types.ts +0 -69
- package/src/plugins/client-code/client-code-plugin.test.ts +0 -511
- package/src/plugins/client-code/format.ts +0 -9
- package/src/plugins/client-code/generator.test.ts +0 -52
- package/src/plugins/client-code/generator.ts +0 -263
- package/src/plugins/client-code/index.ts +0 -15
- package/src/plugins/client-code/plugin.ts +0 -158
- package/src/plugins/client-code/types.ts +0 -52
- package/src/plugins/client-code/utils.ts +0 -164
- package/src/plugins/graceful-shutdown/graceful-shutdown-plugin.test.ts +0 -401
- package/src/plugins/graceful-shutdown/index.ts +0 -3
- package/src/plugins/graceful-shutdown/plugin.ts +0 -279
- package/src/plugins/graceful-shutdown/types.ts +0 -17
- package/src/plugins/rate-limit/rate-limit-plugin.example.ts +0 -171
- package/src/plugins/route/components/Layout.tsx +0 -42
- package/src/plugins/route/components/ServiceStatusPage.tsx +0 -141
- package/src/plugins/route/decorator.ts +0 -50
- package/src/plugins/route/index.ts +0 -16
- package/src/plugins/route/plugin.ts +0 -218
- package/src/plugins/route/route-plugin.test.ts +0 -759
- package/src/plugins/route/types.ts +0 -72
- package/src/plugins/schedule/README.md +0 -309
- package/src/plugins/schedule/decorator.ts +0 -25
- package/src/plugins/schedule/index.ts +0 -12
- package/src/plugins/schedule/mock-etcd.ts +0 -145
- package/src/plugins/schedule/plugin.ts +0 -164
- package/src/plugins/schedule/schedule-plugin.test.ts +0 -312
- package/src/plugins/schedule/scheduler.ts +0 -164
- package/src/plugins/schedule/types.ts +0 -94
- package/src/plugins/schedule/utils.test.ts +0 -163
- package/src/plugins/schedule/utils.ts +0 -41
- package/tests/integration/client.test.ts +0 -203
- package/tests/integration/dev-service.ts +0 -301
- package/tests/integration/generated/client.ts +0 -123
- package/tests/integration/start-service.ts +0 -21
- package/tsconfig.json +0 -27
- package/tsup.config.ts +0 -16
- package/vitest.config.ts +0 -19
package/dist/index.d.mts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { Hono, MiddlewareHandler } from 'hono';
|
|
2
2
|
export { Context, MiddlewareHandler } from 'hono';
|
|
3
|
-
import { ContentfulStatusCode } from 'hono/utils/http-status';
|
|
4
3
|
import * as hono_utils_html from 'hono/utils/html';
|
|
4
|
+
import * as hono_jsx_jsx_dev_runtime from 'hono/jsx/jsx-dev-runtime';
|
|
5
|
+
import { ContentfulStatusCode } from 'hono/utils/http-status';
|
|
5
6
|
import { z } from 'zod';
|
|
6
7
|
export { z } from 'zod';
|
|
7
8
|
|
|
@@ -51,10 +52,6 @@ declare class Microservice<ModuleOptions = Record<string, any>> {
|
|
|
51
52
|
* 在所有插件执行完 onHandlerLoad 后调用
|
|
52
53
|
*/
|
|
53
54
|
private applyWrapperChains;
|
|
54
|
-
/**
|
|
55
|
-
* 检查端口是否可用
|
|
56
|
-
*/
|
|
57
|
-
private isPortAvailable;
|
|
58
55
|
/**
|
|
59
56
|
* 寻找一个随机的可用端口
|
|
60
57
|
*/
|
|
@@ -313,6 +310,37 @@ interface PreStartChecker {
|
|
|
313
310
|
}
|
|
314
311
|
declare function startCheck(checkers: PreStartChecker[], pass?: () => void | Promise<void>): Promise<void>;
|
|
315
312
|
|
|
313
|
+
declare const BaseLayout: (props?: {
|
|
314
|
+
children?: any;
|
|
315
|
+
title?: string;
|
|
316
|
+
heads?: any;
|
|
317
|
+
}) => hono_utils_html.HtmlEscapedString | Promise<hono_utils_html.HtmlEscapedString>;
|
|
318
|
+
declare const HtmxLayout: (props?: {
|
|
319
|
+
children?: any;
|
|
320
|
+
title: string;
|
|
321
|
+
favicon?: any;
|
|
322
|
+
}) => hono_utils_html.HtmlEscapedString | Promise<hono_utils_html.HtmlEscapedString>;
|
|
323
|
+
|
|
324
|
+
/**
|
|
325
|
+
* 服务状态信息接口
|
|
326
|
+
* 基于 MicroserviceOptions,并添加运行时信息
|
|
327
|
+
*/
|
|
328
|
+
interface ServiceStatusInfo {
|
|
329
|
+
name: string;
|
|
330
|
+
version: string;
|
|
331
|
+
prefix?: string;
|
|
332
|
+
hostname?: string;
|
|
333
|
+
port?: number;
|
|
334
|
+
env?: string;
|
|
335
|
+
status?: string;
|
|
336
|
+
}
|
|
337
|
+
declare const ServiceInfoCards: ({ serviceInfo, }: {
|
|
338
|
+
serviceInfo: ServiceStatusInfo;
|
|
339
|
+
}) => hono_jsx_jsx_dev_runtime.JSX.Element;
|
|
340
|
+
declare const ServiceStatusPage: ({ serviceInfo, }: {
|
|
341
|
+
serviceInfo: ServiceStatusInfo;
|
|
342
|
+
}) => hono_jsx_jsx_dev_runtime.JSX.Element;
|
|
343
|
+
|
|
316
344
|
type HTTPMethod = "GET" | "POST" | "PUT" | "DELETE" | "PATCH" | "HEAD" | "OPTIONS";
|
|
317
345
|
/**
|
|
318
346
|
* Route装饰器配置选项
|
|
@@ -365,6 +393,12 @@ interface RouteModuleOptions {
|
|
|
365
393
|
* RoutePlugin 配置选项
|
|
366
394
|
*/
|
|
367
395
|
interface RoutePluginOptions {
|
|
396
|
+
/**
|
|
397
|
+
* 全局路径前缀(应用于所有路由)
|
|
398
|
+
* 路径拼接顺序:全局前缀 + 模块前缀 + 路由路径
|
|
399
|
+
* 例如:prefix="/api", routePrefix="/v1", path="/users" => "/api/v1/users"
|
|
400
|
+
*/
|
|
401
|
+
prefix?: string;
|
|
368
402
|
/**
|
|
369
403
|
* 全局中间件(应用于所有路由)
|
|
370
404
|
* 执行顺序:全局中间件 -> 模块级中间件 -> 路由级中间件
|
|
@@ -373,19 +407,54 @@ interface RoutePluginOptions {
|
|
|
373
407
|
globalMiddlewares?: MiddlewareHandler[];
|
|
374
408
|
}
|
|
375
409
|
|
|
410
|
+
/**
|
|
411
|
+
* Route装饰器(Handler的语法糖封装)
|
|
412
|
+
* 固定type="route",简化HTTP路由标注
|
|
413
|
+
* 使用最新的 Stage 3 装饰器标准
|
|
414
|
+
*
|
|
415
|
+
* @example
|
|
416
|
+
* ```typescript
|
|
417
|
+
* @Route({ method: "GET", path: "/users" })
|
|
418
|
+
* async getUsers(ctx: Context) {
|
|
419
|
+
* return ctx.json({ users: [] });
|
|
420
|
+
* }
|
|
421
|
+
*
|
|
422
|
+
* // 支持多个路径
|
|
423
|
+
* @Route({ path: ["/", "/home", "/dashboard"] })
|
|
424
|
+
* async homePage(ctx: Context) {
|
|
425
|
+
* return <HomePage />;
|
|
426
|
+
* }
|
|
427
|
+
* ```
|
|
428
|
+
*/
|
|
429
|
+
declare function Route(options: RouteOptions): (target: Function, context: ClassMethodDecoratorContext) => void;
|
|
430
|
+
/**
|
|
431
|
+
* Page装饰器(Route的别名,用于向后兼容)
|
|
432
|
+
* 专门用于页面路由,默认使用 GET 方法
|
|
433
|
+
*
|
|
434
|
+
* @example
|
|
435
|
+
* ```typescript
|
|
436
|
+
* @Page({ path: ["/", "/home"] })
|
|
437
|
+
* async adminPage(ctx: Context) {
|
|
438
|
+
* return HtmxLayout({ title: "Admin", children: <AdminLayout /> });
|
|
439
|
+
* }
|
|
440
|
+
* ```
|
|
441
|
+
*/
|
|
442
|
+
declare function Page(options: RouteOptions): (target: Function, context: ClassMethodDecoratorContext) => void;
|
|
443
|
+
|
|
376
444
|
/**
|
|
377
445
|
* RoutePlugin - 核心路由插件
|
|
378
446
|
* 负责解析type="route"的Handler元数据,注册HTTP路由到Hono实例
|
|
379
447
|
*
|
|
380
448
|
* @example
|
|
381
449
|
* ```typescript
|
|
382
|
-
* //
|
|
450
|
+
* // 使用全局前缀和中间件
|
|
383
451
|
* const authMiddleware = async (ctx, next) => {
|
|
384
452
|
* // 验证 token
|
|
385
453
|
* await next();
|
|
386
454
|
* };
|
|
387
455
|
*
|
|
388
456
|
* const routePlugin = new RoutePlugin({
|
|
457
|
+
* prefix: "/api", // 全局路径前缀,所有路由都会加上这个前缀
|
|
389
458
|
* globalMiddlewares: [authMiddleware],
|
|
390
459
|
* });
|
|
391
460
|
* ```
|
|
@@ -394,6 +463,7 @@ declare class RoutePlugin implements Plugin<RouteModuleOptions> {
|
|
|
394
463
|
readonly name = "route-plugin";
|
|
395
464
|
readonly priority = PluginPriority.ROUTE;
|
|
396
465
|
private engine;
|
|
466
|
+
private globalPrefix;
|
|
397
467
|
private globalMiddlewares;
|
|
398
468
|
/**
|
|
399
469
|
* 构造函数
|
|
@@ -414,51 +484,6 @@ declare class RoutePlugin implements Plugin<RouteModuleOptions> {
|
|
|
414
484
|
onHandlerLoad(handlers: HandlerMetadata[]): void;
|
|
415
485
|
}
|
|
416
486
|
|
|
417
|
-
/**
|
|
418
|
-
* Route装饰器(Handler的语法糖封装)
|
|
419
|
-
* 固定type="route",简化HTTP路由标注
|
|
420
|
-
* 使用最新的 Stage 3 装饰器标准
|
|
421
|
-
*
|
|
422
|
-
* @example
|
|
423
|
-
* ```typescript
|
|
424
|
-
* @Route({ method: "GET", path: "/users" })
|
|
425
|
-
* async getUsers(ctx: Context) {
|
|
426
|
-
* return ctx.json({ users: [] });
|
|
427
|
-
* }
|
|
428
|
-
*
|
|
429
|
-
* // 支持多个路径
|
|
430
|
-
* @Route({ path: ["/", "/home", "/dashboard"] })
|
|
431
|
-
* async homePage(ctx: Context) {
|
|
432
|
-
* return <HomePage />;
|
|
433
|
-
* }
|
|
434
|
-
* ```
|
|
435
|
-
*/
|
|
436
|
-
declare function Route(options: RouteOptions): (target: Function, context: ClassMethodDecoratorContext) => void;
|
|
437
|
-
/**
|
|
438
|
-
* Page装饰器(Route的别名,用于向后兼容)
|
|
439
|
-
* 专门用于页面路由,默认使用 GET 方法
|
|
440
|
-
*
|
|
441
|
-
* @example
|
|
442
|
-
* ```typescript
|
|
443
|
-
* @Page({ path: ["/", "/home"] })
|
|
444
|
-
* async adminPage(ctx: Context) {
|
|
445
|
-
* return HtmxLayout({ title: "Admin", children: <AdminLayout /> });
|
|
446
|
-
* }
|
|
447
|
-
* ```
|
|
448
|
-
*/
|
|
449
|
-
declare function Page(options: RouteOptions): (target: Function, context: ClassMethodDecoratorContext) => void;
|
|
450
|
-
|
|
451
|
-
declare const BaseLayout: (props?: {
|
|
452
|
-
children?: any;
|
|
453
|
-
title?: string;
|
|
454
|
-
heads?: any;
|
|
455
|
-
}) => hono_utils_html.HtmlEscapedString | Promise<hono_utils_html.HtmlEscapedString>;
|
|
456
|
-
declare const HtmxLayout: (props?: {
|
|
457
|
-
children?: any;
|
|
458
|
-
title: string;
|
|
459
|
-
favicon?: any;
|
|
460
|
-
}) => hono_utils_html.HtmlEscapedString | Promise<hono_utils_html.HtmlEscapedString>;
|
|
461
|
-
|
|
462
487
|
/**
|
|
463
488
|
* Action装饰器配置选项
|
|
464
489
|
*/
|
|
@@ -1306,4 +1331,4 @@ declare const Testing: {
|
|
|
1306
1331
|
readonly wait: typeof wait;
|
|
1307
1332
|
};
|
|
1308
1333
|
|
|
1309
|
-
export { Action, type ActionInfo, type ActionModuleOptions, type ActionOptions, ActionPlugin, BaseLayout, Cache, type CacheAdapter, type CacheItem, type CacheModuleOptions, type CacheOptions, CachePlugin, type Campaign, type Class, type ClassDecoratorContext, type ClassMethodDecoratorContext$1 as ClassMethodDecoratorContext, ClientCodePlugin, type ClientCodePluginOptions, DEFAULT_TEST_OPTIONS, DuplicateModuleError, type Election, type Etcd3, Factory, GracefulShutdownPlugin, type GracefulShutdownPluginOptions, type HTTPMethod, Handler, type HandlerMetadata, type HandlerWrapper, HtmxLayout, MemoryCacheAdapter, Microservice, type MicroserviceOptions, MockEtcd3, ModuleConfigValidationError, type ModuleDecorator, type ModuleInfo, type ModuleMetadata, type Observer, Page, type Plugin, type PluginModuleOptionsSchema, PluginNameRequiredError, PluginPriority, type PreStartChecker, RedisCacheAdapter, type RedisCacheAdapterOptions, Route, type RouteModuleOptions, type RouteOptions, RoutePlugin, type RoutePluginOptions, Schedule, type ScheduleMetadata, ScheduleMode, type ScheduleOptions, SchedulePlugin, type SchedulePluginOptions, Scheduler, Testing, convertHandlersToModuleInfo, convertHandlersToModuleInfoWithMetadata, generateClientCode, getZodTypeString, startCheck };
|
|
1334
|
+
export { Action, type ActionInfo, type ActionModuleOptions, type ActionOptions, ActionPlugin, BaseLayout, Cache, type CacheAdapter, type CacheItem, type CacheModuleOptions, type CacheOptions, CachePlugin, type Campaign, type Class, type ClassDecoratorContext, type ClassMethodDecoratorContext$1 as ClassMethodDecoratorContext, ClientCodePlugin, type ClientCodePluginOptions, DEFAULT_TEST_OPTIONS, DuplicateModuleError, type Election, type Etcd3, Factory, GracefulShutdownPlugin, type GracefulShutdownPluginOptions, type HTTPMethod, Handler, type HandlerMetadata, type HandlerWrapper, HtmxLayout, MemoryCacheAdapter, Microservice, type MicroserviceOptions, MockEtcd3, ModuleConfigValidationError, type ModuleDecorator, type ModuleInfo, type ModuleMetadata, type Observer, Page, type Plugin, type PluginModuleOptionsSchema, PluginNameRequiredError, PluginPriority, type PreStartChecker, RedisCacheAdapter, type RedisCacheAdapterOptions, Route, type RouteModuleOptions, type RouteOptions, RoutePlugin, type RoutePluginOptions, Schedule, type ScheduleMetadata, ScheduleMode, type ScheduleOptions, SchedulePlugin, type SchedulePluginOptions, Scheduler, ServiceInfoCards, type ServiceStatusInfo, ServiceStatusPage, Testing, convertHandlersToModuleInfo, convertHandlersToModuleInfoWithMetadata, generateClientCode, getZodTypeString, startCheck };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { Hono, MiddlewareHandler } from 'hono';
|
|
2
2
|
export { Context, MiddlewareHandler } from 'hono';
|
|
3
|
-
import { ContentfulStatusCode } from 'hono/utils/http-status';
|
|
4
3
|
import * as hono_utils_html from 'hono/utils/html';
|
|
4
|
+
import * as hono_jsx_jsx_dev_runtime from 'hono/jsx/jsx-dev-runtime';
|
|
5
|
+
import { ContentfulStatusCode } from 'hono/utils/http-status';
|
|
5
6
|
import { z } from 'zod';
|
|
6
7
|
export { z } from 'zod';
|
|
7
8
|
|
|
@@ -51,10 +52,6 @@ declare class Microservice<ModuleOptions = Record<string, any>> {
|
|
|
51
52
|
* 在所有插件执行完 onHandlerLoad 后调用
|
|
52
53
|
*/
|
|
53
54
|
private applyWrapperChains;
|
|
54
|
-
/**
|
|
55
|
-
* 检查端口是否可用
|
|
56
|
-
*/
|
|
57
|
-
private isPortAvailable;
|
|
58
55
|
/**
|
|
59
56
|
* 寻找一个随机的可用端口
|
|
60
57
|
*/
|
|
@@ -313,6 +310,37 @@ interface PreStartChecker {
|
|
|
313
310
|
}
|
|
314
311
|
declare function startCheck(checkers: PreStartChecker[], pass?: () => void | Promise<void>): Promise<void>;
|
|
315
312
|
|
|
313
|
+
declare const BaseLayout: (props?: {
|
|
314
|
+
children?: any;
|
|
315
|
+
title?: string;
|
|
316
|
+
heads?: any;
|
|
317
|
+
}) => hono_utils_html.HtmlEscapedString | Promise<hono_utils_html.HtmlEscapedString>;
|
|
318
|
+
declare const HtmxLayout: (props?: {
|
|
319
|
+
children?: any;
|
|
320
|
+
title: string;
|
|
321
|
+
favicon?: any;
|
|
322
|
+
}) => hono_utils_html.HtmlEscapedString | Promise<hono_utils_html.HtmlEscapedString>;
|
|
323
|
+
|
|
324
|
+
/**
|
|
325
|
+
* 服务状态信息接口
|
|
326
|
+
* 基于 MicroserviceOptions,并添加运行时信息
|
|
327
|
+
*/
|
|
328
|
+
interface ServiceStatusInfo {
|
|
329
|
+
name: string;
|
|
330
|
+
version: string;
|
|
331
|
+
prefix?: string;
|
|
332
|
+
hostname?: string;
|
|
333
|
+
port?: number;
|
|
334
|
+
env?: string;
|
|
335
|
+
status?: string;
|
|
336
|
+
}
|
|
337
|
+
declare const ServiceInfoCards: ({ serviceInfo, }: {
|
|
338
|
+
serviceInfo: ServiceStatusInfo;
|
|
339
|
+
}) => hono_jsx_jsx_dev_runtime.JSX.Element;
|
|
340
|
+
declare const ServiceStatusPage: ({ serviceInfo, }: {
|
|
341
|
+
serviceInfo: ServiceStatusInfo;
|
|
342
|
+
}) => hono_jsx_jsx_dev_runtime.JSX.Element;
|
|
343
|
+
|
|
316
344
|
type HTTPMethod = "GET" | "POST" | "PUT" | "DELETE" | "PATCH" | "HEAD" | "OPTIONS";
|
|
317
345
|
/**
|
|
318
346
|
* Route装饰器配置选项
|
|
@@ -365,6 +393,12 @@ interface RouteModuleOptions {
|
|
|
365
393
|
* RoutePlugin 配置选项
|
|
366
394
|
*/
|
|
367
395
|
interface RoutePluginOptions {
|
|
396
|
+
/**
|
|
397
|
+
* 全局路径前缀(应用于所有路由)
|
|
398
|
+
* 路径拼接顺序:全局前缀 + 模块前缀 + 路由路径
|
|
399
|
+
* 例如:prefix="/api", routePrefix="/v1", path="/users" => "/api/v1/users"
|
|
400
|
+
*/
|
|
401
|
+
prefix?: string;
|
|
368
402
|
/**
|
|
369
403
|
* 全局中间件(应用于所有路由)
|
|
370
404
|
* 执行顺序:全局中间件 -> 模块级中间件 -> 路由级中间件
|
|
@@ -373,19 +407,54 @@ interface RoutePluginOptions {
|
|
|
373
407
|
globalMiddlewares?: MiddlewareHandler[];
|
|
374
408
|
}
|
|
375
409
|
|
|
410
|
+
/**
|
|
411
|
+
* Route装饰器(Handler的语法糖封装)
|
|
412
|
+
* 固定type="route",简化HTTP路由标注
|
|
413
|
+
* 使用最新的 Stage 3 装饰器标准
|
|
414
|
+
*
|
|
415
|
+
* @example
|
|
416
|
+
* ```typescript
|
|
417
|
+
* @Route({ method: "GET", path: "/users" })
|
|
418
|
+
* async getUsers(ctx: Context) {
|
|
419
|
+
* return ctx.json({ users: [] });
|
|
420
|
+
* }
|
|
421
|
+
*
|
|
422
|
+
* // 支持多个路径
|
|
423
|
+
* @Route({ path: ["/", "/home", "/dashboard"] })
|
|
424
|
+
* async homePage(ctx: Context) {
|
|
425
|
+
* return <HomePage />;
|
|
426
|
+
* }
|
|
427
|
+
* ```
|
|
428
|
+
*/
|
|
429
|
+
declare function Route(options: RouteOptions): (target: Function, context: ClassMethodDecoratorContext) => void;
|
|
430
|
+
/**
|
|
431
|
+
* Page装饰器(Route的别名,用于向后兼容)
|
|
432
|
+
* 专门用于页面路由,默认使用 GET 方法
|
|
433
|
+
*
|
|
434
|
+
* @example
|
|
435
|
+
* ```typescript
|
|
436
|
+
* @Page({ path: ["/", "/home"] })
|
|
437
|
+
* async adminPage(ctx: Context) {
|
|
438
|
+
* return HtmxLayout({ title: "Admin", children: <AdminLayout /> });
|
|
439
|
+
* }
|
|
440
|
+
* ```
|
|
441
|
+
*/
|
|
442
|
+
declare function Page(options: RouteOptions): (target: Function, context: ClassMethodDecoratorContext) => void;
|
|
443
|
+
|
|
376
444
|
/**
|
|
377
445
|
* RoutePlugin - 核心路由插件
|
|
378
446
|
* 负责解析type="route"的Handler元数据,注册HTTP路由到Hono实例
|
|
379
447
|
*
|
|
380
448
|
* @example
|
|
381
449
|
* ```typescript
|
|
382
|
-
* //
|
|
450
|
+
* // 使用全局前缀和中间件
|
|
383
451
|
* const authMiddleware = async (ctx, next) => {
|
|
384
452
|
* // 验证 token
|
|
385
453
|
* await next();
|
|
386
454
|
* };
|
|
387
455
|
*
|
|
388
456
|
* const routePlugin = new RoutePlugin({
|
|
457
|
+
* prefix: "/api", // 全局路径前缀,所有路由都会加上这个前缀
|
|
389
458
|
* globalMiddlewares: [authMiddleware],
|
|
390
459
|
* });
|
|
391
460
|
* ```
|
|
@@ -394,6 +463,7 @@ declare class RoutePlugin implements Plugin<RouteModuleOptions> {
|
|
|
394
463
|
readonly name = "route-plugin";
|
|
395
464
|
readonly priority = PluginPriority.ROUTE;
|
|
396
465
|
private engine;
|
|
466
|
+
private globalPrefix;
|
|
397
467
|
private globalMiddlewares;
|
|
398
468
|
/**
|
|
399
469
|
* 构造函数
|
|
@@ -414,51 +484,6 @@ declare class RoutePlugin implements Plugin<RouteModuleOptions> {
|
|
|
414
484
|
onHandlerLoad(handlers: HandlerMetadata[]): void;
|
|
415
485
|
}
|
|
416
486
|
|
|
417
|
-
/**
|
|
418
|
-
* Route装饰器(Handler的语法糖封装)
|
|
419
|
-
* 固定type="route",简化HTTP路由标注
|
|
420
|
-
* 使用最新的 Stage 3 装饰器标准
|
|
421
|
-
*
|
|
422
|
-
* @example
|
|
423
|
-
* ```typescript
|
|
424
|
-
* @Route({ method: "GET", path: "/users" })
|
|
425
|
-
* async getUsers(ctx: Context) {
|
|
426
|
-
* return ctx.json({ users: [] });
|
|
427
|
-
* }
|
|
428
|
-
*
|
|
429
|
-
* // 支持多个路径
|
|
430
|
-
* @Route({ path: ["/", "/home", "/dashboard"] })
|
|
431
|
-
* async homePage(ctx: Context) {
|
|
432
|
-
* return <HomePage />;
|
|
433
|
-
* }
|
|
434
|
-
* ```
|
|
435
|
-
*/
|
|
436
|
-
declare function Route(options: RouteOptions): (target: Function, context: ClassMethodDecoratorContext) => void;
|
|
437
|
-
/**
|
|
438
|
-
* Page装饰器(Route的别名,用于向后兼容)
|
|
439
|
-
* 专门用于页面路由,默认使用 GET 方法
|
|
440
|
-
*
|
|
441
|
-
* @example
|
|
442
|
-
* ```typescript
|
|
443
|
-
* @Page({ path: ["/", "/home"] })
|
|
444
|
-
* async adminPage(ctx: Context) {
|
|
445
|
-
* return HtmxLayout({ title: "Admin", children: <AdminLayout /> });
|
|
446
|
-
* }
|
|
447
|
-
* ```
|
|
448
|
-
*/
|
|
449
|
-
declare function Page(options: RouteOptions): (target: Function, context: ClassMethodDecoratorContext) => void;
|
|
450
|
-
|
|
451
|
-
declare const BaseLayout: (props?: {
|
|
452
|
-
children?: any;
|
|
453
|
-
title?: string;
|
|
454
|
-
heads?: any;
|
|
455
|
-
}) => hono_utils_html.HtmlEscapedString | Promise<hono_utils_html.HtmlEscapedString>;
|
|
456
|
-
declare const HtmxLayout: (props?: {
|
|
457
|
-
children?: any;
|
|
458
|
-
title: string;
|
|
459
|
-
favicon?: any;
|
|
460
|
-
}) => hono_utils_html.HtmlEscapedString | Promise<hono_utils_html.HtmlEscapedString>;
|
|
461
|
-
|
|
462
487
|
/**
|
|
463
488
|
* Action装饰器配置选项
|
|
464
489
|
*/
|
|
@@ -1306,4 +1331,4 @@ declare const Testing: {
|
|
|
1306
1331
|
readonly wait: typeof wait;
|
|
1307
1332
|
};
|
|
1308
1333
|
|
|
1309
|
-
export { Action, type ActionInfo, type ActionModuleOptions, type ActionOptions, ActionPlugin, BaseLayout, Cache, type CacheAdapter, type CacheItem, type CacheModuleOptions, type CacheOptions, CachePlugin, type Campaign, type Class, type ClassDecoratorContext, type ClassMethodDecoratorContext$1 as ClassMethodDecoratorContext, ClientCodePlugin, type ClientCodePluginOptions, DEFAULT_TEST_OPTIONS, DuplicateModuleError, type Election, type Etcd3, Factory, GracefulShutdownPlugin, type GracefulShutdownPluginOptions, type HTTPMethod, Handler, type HandlerMetadata, type HandlerWrapper, HtmxLayout, MemoryCacheAdapter, Microservice, type MicroserviceOptions, MockEtcd3, ModuleConfigValidationError, type ModuleDecorator, type ModuleInfo, type ModuleMetadata, type Observer, Page, type Plugin, type PluginModuleOptionsSchema, PluginNameRequiredError, PluginPriority, type PreStartChecker, RedisCacheAdapter, type RedisCacheAdapterOptions, Route, type RouteModuleOptions, type RouteOptions, RoutePlugin, type RoutePluginOptions, Schedule, type ScheduleMetadata, ScheduleMode, type ScheduleOptions, SchedulePlugin, type SchedulePluginOptions, Scheduler, Testing, convertHandlersToModuleInfo, convertHandlersToModuleInfoWithMetadata, generateClientCode, getZodTypeString, startCheck };
|
|
1334
|
+
export { Action, type ActionInfo, type ActionModuleOptions, type ActionOptions, ActionPlugin, BaseLayout, Cache, type CacheAdapter, type CacheItem, type CacheModuleOptions, type CacheOptions, CachePlugin, type Campaign, type Class, type ClassDecoratorContext, type ClassMethodDecoratorContext$1 as ClassMethodDecoratorContext, ClientCodePlugin, type ClientCodePluginOptions, DEFAULT_TEST_OPTIONS, DuplicateModuleError, type Election, type Etcd3, Factory, GracefulShutdownPlugin, type GracefulShutdownPluginOptions, type HTTPMethod, Handler, type HandlerMetadata, type HandlerWrapper, HtmxLayout, MemoryCacheAdapter, Microservice, type MicroserviceOptions, MockEtcd3, ModuleConfigValidationError, type ModuleDecorator, type ModuleInfo, type ModuleMetadata, type Observer, Page, type Plugin, type PluginModuleOptionsSchema, PluginNameRequiredError, PluginPriority, type PreStartChecker, RedisCacheAdapter, type RedisCacheAdapterOptions, Route, type RouteModuleOptions, type RouteOptions, RoutePlugin, type RoutePluginOptions, Schedule, type ScheduleMetadata, ScheduleMode, type ScheduleOptions, SchedulePlugin, type SchedulePluginOptions, Scheduler, ServiceInfoCards, type ServiceStatusInfo, ServiceStatusPage, Testing, convertHandlersToModuleInfo, convertHandlersToModuleInfoWithMetadata, generateClientCode, getZodTypeString, startCheck };
|