@dangao/bun-server 0.1.0
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/controller/controller.d.ts +63 -0
- package/dist/controller/controller.d.ts.map +1 -0
- package/dist/controller/decorators.d.ts +46 -0
- package/dist/controller/decorators.d.ts.map +1 -0
- package/dist/controller/index.d.ts +7 -0
- package/dist/controller/index.d.ts.map +1 -0
- package/dist/controller/metadata.d.ts +17 -0
- package/dist/controller/metadata.d.ts.map +1 -0
- package/dist/controller/param-binder.d.ts +51 -0
- package/dist/controller/param-binder.d.ts.map +1 -0
- package/dist/core/application.d.ts +80 -0
- package/dist/core/application.d.ts.map +1 -0
- package/dist/core/context.d.ts +117 -0
- package/dist/core/context.d.ts.map +1 -0
- package/dist/core/index.d.ts +4 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/server.d.ts +53 -0
- package/dist/core/server.d.ts.map +1 -0
- package/dist/core/types.d.ts +2 -0
- package/dist/core/types.d.ts.map +1 -0
- package/dist/di/container.d.ts +80 -0
- package/dist/di/container.d.ts.map +1 -0
- package/dist/di/decorators.d.ts +43 -0
- package/dist/di/decorators.d.ts.map +1 -0
- package/dist/di/index.d.ts +4 -0
- package/dist/di/index.d.ts.map +1 -0
- package/dist/di/module-registry.d.ts +27 -0
- package/dist/di/module-registry.d.ts.map +1 -0
- package/dist/di/module.d.ts +30 -0
- package/dist/di/module.d.ts.map +1 -0
- package/dist/di/types.d.ts +57 -0
- package/dist/di/types.d.ts.map +1 -0
- package/dist/error/filter.d.ts +18 -0
- package/dist/error/filter.d.ts.map +1 -0
- package/dist/error/handler.d.ts +6 -0
- package/dist/error/handler.d.ts.map +1 -0
- package/dist/error/http-exception.d.ts +24 -0
- package/dist/error/http-exception.d.ts.map +1 -0
- package/dist/error/index.d.ts +5 -0
- package/dist/error/index.d.ts.map +1 -0
- package/dist/extensions/index.d.ts +5 -0
- package/dist/extensions/index.d.ts.map +1 -0
- package/dist/extensions/logger-extension.d.ts +13 -0
- package/dist/extensions/logger-extension.d.ts.map +1 -0
- package/dist/extensions/types.d.ts +12 -0
- package/dist/extensions/types.d.ts.map +1 -0
- package/dist/files/index.d.ts +5 -0
- package/dist/files/index.d.ts.map +1 -0
- package/dist/files/static-middleware.d.ts +8 -0
- package/dist/files/static-middleware.d.ts.map +1 -0
- package/dist/files/storage.d.ts +10 -0
- package/dist/files/storage.d.ts.map +1 -0
- package/dist/files/types.d.ts +27 -0
- package/dist/files/types.d.ts.map +1 -0
- package/dist/files/upload-middleware.d.ts +7 -0
- package/dist/files/upload-middleware.d.ts.map +1 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2118 -0
- package/dist/middleware/builtin/cors.d.ts +14 -0
- package/dist/middleware/builtin/cors.d.ts.map +1 -0
- package/dist/middleware/builtin/error-handler.d.ts +23 -0
- package/dist/middleware/builtin/error-handler.d.ts.map +1 -0
- package/dist/middleware/builtin/file-upload.d.ts +9 -0
- package/dist/middleware/builtin/file-upload.d.ts.map +1 -0
- package/dist/middleware/builtin/index.d.ts +6 -0
- package/dist/middleware/builtin/index.d.ts.map +1 -0
- package/dist/middleware/builtin/logger.d.ts +26 -0
- package/dist/middleware/builtin/logger.d.ts.map +1 -0
- package/dist/middleware/builtin/static-file.d.ts +14 -0
- package/dist/middleware/builtin/static-file.d.ts.map +1 -0
- package/dist/middleware/decorators.d.ts +22 -0
- package/dist/middleware/decorators.d.ts.map +1 -0
- package/dist/middleware/index.d.ts +5 -0
- package/dist/middleware/index.d.ts.map +1 -0
- package/dist/middleware/middleware.d.ts +10 -0
- package/dist/middleware/middleware.d.ts.map +1 -0
- package/dist/middleware/pipeline.d.ts +38 -0
- package/dist/middleware/pipeline.d.ts.map +1 -0
- package/dist/request/body-parser.d.ts +37 -0
- package/dist/request/body-parser.d.ts.map +1 -0
- package/dist/request/file-handler.d.ts +13 -0
- package/dist/request/file-handler.d.ts.map +1 -0
- package/dist/request/index.d.ts +5 -0
- package/dist/request/index.d.ts.map +1 -0
- package/dist/request/request.d.ts +67 -0
- package/dist/request/request.d.ts.map +1 -0
- package/dist/request/response.d.ts +65 -0
- package/dist/request/response.d.ts.map +1 -0
- package/dist/router/decorators.d.ts +45 -0
- package/dist/router/decorators.d.ts.map +1 -0
- package/dist/router/index.d.ts +6 -0
- package/dist/router/index.d.ts.map +1 -0
- package/dist/router/registry.d.ts +54 -0
- package/dist/router/registry.d.ts.map +1 -0
- package/dist/router/route.d.ts +57 -0
- package/dist/router/route.d.ts.map +1 -0
- package/dist/router/router.d.ts +76 -0
- package/dist/router/router.d.ts.map +1 -0
- package/dist/router/types.d.ts +23 -0
- package/dist/router/types.d.ts.map +1 -0
- package/dist/testing/harness.d.ts +26 -0
- package/dist/testing/harness.d.ts.map +1 -0
- package/dist/validation/decorators.d.ts +20 -0
- package/dist/validation/decorators.d.ts.map +1 -0
- package/dist/validation/errors.d.ts +19 -0
- package/dist/validation/errors.d.ts.map +1 -0
- package/dist/validation/index.d.ts +5 -0
- package/dist/validation/index.d.ts.map +1 -0
- package/dist/validation/types.d.ts +29 -0
- package/dist/validation/types.d.ts.map +1 -0
- package/dist/validation/validator.d.ts +8 -0
- package/dist/validation/validator.d.ts.map +1 -0
- package/dist/websocket/decorators.d.ts +16 -0
- package/dist/websocket/decorators.d.ts.map +1 -0
- package/dist/websocket/index.d.ts +4 -0
- package/dist/websocket/index.d.ts.map +1 -0
- package/dist/websocket/registry.d.ts +22 -0
- package/dist/websocket/registry.d.ts.map +1 -0
- package/package.json +56 -0
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import type { Context } from '../core/context';
|
|
2
|
+
import { Route } from './route';
|
|
3
|
+
import type { HttpMethod, RouteHandler } from './types';
|
|
4
|
+
import type { Middleware } from '../middleware';
|
|
5
|
+
/**
|
|
6
|
+
* 路由器类
|
|
7
|
+
* 管理所有路由,提供路由注册和匹配功能
|
|
8
|
+
*/
|
|
9
|
+
export declare class Router {
|
|
10
|
+
/**
|
|
11
|
+
* 路由列表
|
|
12
|
+
*/
|
|
13
|
+
private readonly routes;
|
|
14
|
+
private readonly staticRoutes;
|
|
15
|
+
private readonly dynamicRoutes;
|
|
16
|
+
/**
|
|
17
|
+
* 注册路由
|
|
18
|
+
* @param method - HTTP 方法
|
|
19
|
+
* @param path - 路由路径
|
|
20
|
+
* @param handler - 路由处理器
|
|
21
|
+
*/
|
|
22
|
+
register(method: HttpMethod, path: string, handler: RouteHandler, middlewares?: Middleware[]): void;
|
|
23
|
+
/**
|
|
24
|
+
* 注册 GET 路由
|
|
25
|
+
* @param path - 路由路径
|
|
26
|
+
* @param handler - 路由处理器
|
|
27
|
+
*/
|
|
28
|
+
get(path: string, handler: RouteHandler, middlewares?: Middleware[]): void;
|
|
29
|
+
/**
|
|
30
|
+
* 注册 POST 路由
|
|
31
|
+
* @param path - 路由路径
|
|
32
|
+
* @param handler - 路由处理器
|
|
33
|
+
*/
|
|
34
|
+
post(path: string, handler: RouteHandler, middlewares?: Middleware[]): void;
|
|
35
|
+
/**
|
|
36
|
+
* 注册 PUT 路由
|
|
37
|
+
* @param path - 路由路径
|
|
38
|
+
* @param handler - 路由处理器
|
|
39
|
+
*/
|
|
40
|
+
put(path: string, handler: RouteHandler, middlewares?: Middleware[]): void;
|
|
41
|
+
/**
|
|
42
|
+
* 注册 DELETE 路由
|
|
43
|
+
* @param path - 路由路径
|
|
44
|
+
* @param handler - 路由处理器
|
|
45
|
+
*/
|
|
46
|
+
delete(path: string, handler: RouteHandler, middlewares?: Middleware[]): void;
|
|
47
|
+
/**
|
|
48
|
+
* 注册 PATCH 路由
|
|
49
|
+
* @param path - 路由路径
|
|
50
|
+
* @param handler - 路由处理器
|
|
51
|
+
*/
|
|
52
|
+
patch(path: string, handler: RouteHandler, middlewares?: Middleware[]): void;
|
|
53
|
+
/**
|
|
54
|
+
* 查找匹配的路由
|
|
55
|
+
* @param method - HTTP 方法
|
|
56
|
+
* @param path - 请求路径
|
|
57
|
+
* @returns 匹配的路由,如果没有找到则返回 undefined
|
|
58
|
+
*/
|
|
59
|
+
findRoute(method: HttpMethod, path: string): Route | undefined;
|
|
60
|
+
/**
|
|
61
|
+
* 处理请求
|
|
62
|
+
* @param context - 请求上下文
|
|
63
|
+
* @returns 响应对象,如果没有匹配的路由则返回 undefined
|
|
64
|
+
*/
|
|
65
|
+
handle(context: Context): Promise<Response | undefined>;
|
|
66
|
+
/**
|
|
67
|
+
* 获取所有路由
|
|
68
|
+
* @returns 路由列表
|
|
69
|
+
*/
|
|
70
|
+
getRoutes(): readonly Route[];
|
|
71
|
+
/**
|
|
72
|
+
* 清除所有已注册路由(主要用于测试环境)
|
|
73
|
+
*/
|
|
74
|
+
clear(): void;
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=router.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../../src/router/router.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACxD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAEhD;;;GAGG;AACH,qBAAa,MAAM;IACjB;;OAEG;IACH,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAe;IACtC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAA4B;IACzD,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAe;IAE7C;;;;;OAKG;IACI,QAAQ,CACb,MAAM,EAAE,UAAU,EAClB,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,YAAY,EACrB,WAAW,GAAE,UAAU,EAAO,GAC7B,IAAI;IAWP;;;;OAIG;IACI,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,EAAE,WAAW,GAAE,UAAU,EAAO,GAAG,IAAI;IAIrF;;;;OAIG;IACI,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,EAAE,WAAW,GAAE,UAAU,EAAO,GAAG,IAAI;IAItF;;;;OAIG;IACI,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,EAAE,WAAW,GAAE,UAAU,EAAO,GAAG,IAAI;IAIrF;;;;OAIG;IACI,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,EAAE,WAAW,GAAE,UAAU,EAAO,GAAG,IAAI;IAIxF;;;;OAIG;IACI,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,EAAE,WAAW,GAAE,UAAU,EAAO,GAAG,IAAI;IAIvF;;;;;OAKG;IACI,SAAS,CAAC,MAAM,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,GAAG,KAAK,GAAG,SAAS;IAerE;;;;OAIG;IACU,MAAM,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,GAAG,SAAS,CAAC;IAiBpE;;;OAGG;IACI,SAAS,IAAI,SAAS,KAAK,EAAE;IAIpC;;OAEG;IACI,KAAK,IAAI,IAAI;CAKrB"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Context } from '../core/context';
|
|
2
|
+
/**
|
|
3
|
+
* HTTP 方法类型
|
|
4
|
+
*/
|
|
5
|
+
export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'HEAD' | 'OPTIONS';
|
|
6
|
+
/**
|
|
7
|
+
* 路由处理器函数
|
|
8
|
+
*/
|
|
9
|
+
export type RouteHandler = (context: Context) => Response | Promise<Response>;
|
|
10
|
+
/**
|
|
11
|
+
* 路由匹配结果
|
|
12
|
+
*/
|
|
13
|
+
export interface RouteMatch {
|
|
14
|
+
/**
|
|
15
|
+
* 是否匹配
|
|
16
|
+
*/
|
|
17
|
+
matched: boolean;
|
|
18
|
+
/**
|
|
19
|
+
* 路径参数
|
|
20
|
+
*/
|
|
21
|
+
params: Record<string, string>;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/router/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAE/C;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG,KAAK,GAAG,MAAM,GAAG,KAAK,GAAG,QAAQ,GAAG,OAAO,GAAG,MAAM,GAAG,SAAS,CAAC;AAE1F;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG,CAAC,OAAO,EAAE,OAAO,KAAK,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;AAE9E;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB;;OAEG;IACH,OAAO,EAAE,OAAO,CAAC;IAEjB;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAChC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export interface BenchmarkResult {
|
|
2
|
+
name: string;
|
|
3
|
+
iterations: number;
|
|
4
|
+
durationMs: number;
|
|
5
|
+
opsPerSecond: number;
|
|
6
|
+
}
|
|
7
|
+
export interface StressResult {
|
|
8
|
+
name: string;
|
|
9
|
+
iterations: number;
|
|
10
|
+
concurrency: number;
|
|
11
|
+
durationMs: number;
|
|
12
|
+
errors: number;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* 简单性能压测工具,方便在 bun:test 中快速基准测试组件
|
|
16
|
+
*/
|
|
17
|
+
export declare class PerformanceHarness {
|
|
18
|
+
static benchmark(name: string, iterations: number, runner: (iteration: number) => void | Promise<void>): Promise<BenchmarkResult>;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* 简单压力测试运行器,支持并发执行任务并收集错误
|
|
22
|
+
*/
|
|
23
|
+
export declare class StressTester {
|
|
24
|
+
static run(name: string, iterations: number, concurrency: number, task: (iteration: number) => Promise<void>): Promise<StressResult>;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=harness.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"harness.d.ts","sourceRoot":"","sources":["../../src/testing/harness.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;GAEG;AACH,qBAAa,kBAAkB;WACT,SAAS,CAC3B,IAAI,EAAE,MAAM,EACZ,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,GAClD,OAAO,CAAC,eAAe,CAAC;CAmB5B;AAED;;GAEG;AACH,qBAAa,YAAY;WACH,GAAG,CACrB,IAAI,EAAE,MAAM,EACZ,UAAU,EAAE,MAAM,EAClB,WAAW,EAAE,MAAM,EACnB,IAAI,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,GACzC,OAAO,CAAC,YAAY,CAAC;CAuCzB"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import 'reflect-metadata';
|
|
2
|
+
import type { ValidationRuleDefinition, ValidationMetadata } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* 通用校验装饰器
|
|
5
|
+
* @param rules - 校验规则
|
|
6
|
+
*/
|
|
7
|
+
export declare function Validate(...rules: ValidationRuleDefinition[]): ParameterDecorator;
|
|
8
|
+
export interface RuleOption {
|
|
9
|
+
message?: string;
|
|
10
|
+
}
|
|
11
|
+
export declare function IsString(options?: RuleOption): ValidationRuleDefinition;
|
|
12
|
+
export declare function IsNumber(options?: RuleOption): ValidationRuleDefinition;
|
|
13
|
+
export declare function IsEmail(options?: RuleOption): ValidationRuleDefinition;
|
|
14
|
+
export declare function IsOptional(): ValidationRuleDefinition;
|
|
15
|
+
export declare function MinLength(min: number, options?: RuleOption): ValidationRuleDefinition;
|
|
16
|
+
/**
|
|
17
|
+
* 获取方法参数的验证元数据
|
|
18
|
+
*/
|
|
19
|
+
export declare function getValidationMetadata(target: object, propertyKey: string | symbol): ValidationMetadata[];
|
|
20
|
+
//# sourceMappingURL=decorators.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decorators.d.ts","sourceRoot":"","sources":["../../src/validation/decorators.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EAAE,wBAAwB,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAgB5E;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,GAAG,KAAK,EAAE,wBAAwB,EAAE,GAAG,kBAAkB,CAgBjF;AAED,MAAM,WAAW,UAAU;IACzB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,wBAAgB,QAAQ,CAAC,OAAO,GAAE,UAAe,GAAG,wBAAwB,CAM3E;AAED,wBAAgB,QAAQ,CAAC,OAAO,GAAE,UAAe,GAAG,wBAAwB,CAM3E;AAED,wBAAgB,OAAO,CAAC,OAAO,GAAE,UAAe,GAAG,wBAAwB,CAO1E;AAED,wBAAgB,UAAU,IAAI,wBAAwB,CAOrD;AAED,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,GAAE,UAAe,GAAG,wBAAwB,CAMzF;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,MAAM,GAAG,kBAAkB,EAAE,CAIxG"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export interface ValidationIssue {
|
|
2
|
+
/**
|
|
3
|
+
* 参数索引
|
|
4
|
+
*/
|
|
5
|
+
index: number;
|
|
6
|
+
/**
|
|
7
|
+
* 失败的规则名称
|
|
8
|
+
*/
|
|
9
|
+
rule: string;
|
|
10
|
+
/**
|
|
11
|
+
* 错误信息
|
|
12
|
+
*/
|
|
13
|
+
message: string;
|
|
14
|
+
}
|
|
15
|
+
export declare class ValidationError extends Error {
|
|
16
|
+
readonly issues: ValidationIssue[];
|
|
17
|
+
constructor(message: string, issues: ValidationIssue[]);
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/validation/errors.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,eAAe;IAC9B;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IAEd;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,qBAAa,eAAgB,SAAQ,KAAK;IACxC,SAAgB,MAAM,EAAE,eAAe,EAAE,CAAC;gBAEvB,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,eAAe,EAAE;CAK9D"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { Validate, IsString, IsNumber, IsEmail, IsOptional, MinLength, getValidationMetadata, } from './decorators';
|
|
2
|
+
export type { ValidationRuleDefinition, ValidationMetadata } from './types';
|
|
3
|
+
export { validateParameters } from './validator';
|
|
4
|
+
export { ValidationError, type ValidationIssue } from './errors';
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/validation/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EACR,QAAQ,EACR,QAAQ,EACR,OAAO,EACP,UAAU,EACV,SAAS,EACT,qBAAqB,GACtB,MAAM,cAAc,CAAC;AACtB,YAAY,EAAE,wBAAwB,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAC5E,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,eAAe,EAAE,KAAK,eAAe,EAAE,MAAM,UAAU,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export interface ValidationRuleDefinition {
|
|
2
|
+
/**
|
|
3
|
+
* 规则名称
|
|
4
|
+
*/
|
|
5
|
+
name: string;
|
|
6
|
+
/**
|
|
7
|
+
* 错误信息
|
|
8
|
+
*/
|
|
9
|
+
message: string;
|
|
10
|
+
/**
|
|
11
|
+
* 校验函数
|
|
12
|
+
*/
|
|
13
|
+
validate: (value: unknown) => boolean;
|
|
14
|
+
/**
|
|
15
|
+
* 是否为可选字段
|
|
16
|
+
*/
|
|
17
|
+
optional?: boolean;
|
|
18
|
+
}
|
|
19
|
+
export interface ValidationMetadata {
|
|
20
|
+
/**
|
|
21
|
+
* 参数索引
|
|
22
|
+
*/
|
|
23
|
+
index: number;
|
|
24
|
+
/**
|
|
25
|
+
* 规则列表
|
|
26
|
+
*/
|
|
27
|
+
rules: ValidationRuleDefinition[];
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/validation/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,wBAAwB;IACvC;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,QAAQ,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,OAAO,CAAC;IAEtC;;OAEG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,MAAM,WAAW,kBAAkB;IACjC;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IAEd;;OAEG;IACH,KAAK,EAAE,wBAAwB,EAAE,CAAC;CACnC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ValidationMetadata } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* 根据元数据验证参数
|
|
4
|
+
* @param params - 参数数组
|
|
5
|
+
* @param metadata - 验证元数据
|
|
6
|
+
*/
|
|
7
|
+
export declare function validateParameters(params: unknown[], metadata: ValidationMetadata[]): void;
|
|
8
|
+
//# sourceMappingURL=validator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validator.d.ts","sourceRoot":"","sources":["../../src/validation/validator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAA4B,MAAM,SAAS,CAAC;AA0B5E;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,OAAO,EAAE,EAAE,QAAQ,EAAE,kBAAkB,EAAE,GAAG,IAAI,CA6B1F"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import 'reflect-metadata';
|
|
2
|
+
export interface WebSocketGatewayMetadata {
|
|
3
|
+
path: string;
|
|
4
|
+
}
|
|
5
|
+
export interface WebSocketHandlerMetadata {
|
|
6
|
+
open?: string;
|
|
7
|
+
message?: string;
|
|
8
|
+
close?: string;
|
|
9
|
+
}
|
|
10
|
+
export declare function WebSocketGateway(path: string): ClassDecorator;
|
|
11
|
+
export declare const OnOpen: MethodDecorator;
|
|
12
|
+
export declare const OnMessage: MethodDecorator;
|
|
13
|
+
export declare const OnClose: MethodDecorator;
|
|
14
|
+
export declare function getGatewayMetadata(constructor: new (...args: unknown[]) => unknown): WebSocketGatewayMetadata | undefined;
|
|
15
|
+
export declare function getHandlerMetadata(target: object): WebSocketHandlerMetadata;
|
|
16
|
+
//# sourceMappingURL=decorators.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decorators.d.ts","sourceRoot":"","sources":["../../src/websocket/decorators.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,CAAC;AAK1B,MAAM,WAAW,wBAAwB;IACvC,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,wBAAwB;IACvC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,cAAc,CAI7D;AAeD,eAAO,MAAM,MAAM,iBAAiC,CAAC;AACrD,eAAO,MAAM,SAAS,iBAAoC,CAAC;AAC3D,eAAO,MAAM,OAAO,iBAAkC,CAAC;AAEvD,wBAAgB,kBAAkB,CAChC,WAAW,EAAE,KAAK,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,GAC/C,wBAAwB,GAAG,SAAS,CAEtC;AAED,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,wBAAwB,CAI3E"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/websocket/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,MAAM,EACN,SAAS,EACT,OAAO,EACP,kBAAkB,EAClB,kBAAkB,GACnB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,wBAAwB,EAAE,MAAM,YAAY,CAAC;AACtD,YAAY,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { ServerWebSocket } from 'bun';
|
|
2
|
+
import type { Constructor } from '@/core/types';
|
|
3
|
+
export interface WebSocketConnectionData {
|
|
4
|
+
path: string;
|
|
5
|
+
}
|
|
6
|
+
export declare class WebSocketGatewayRegistry {
|
|
7
|
+
private static instance;
|
|
8
|
+
private readonly container;
|
|
9
|
+
private readonly gateways;
|
|
10
|
+
private constructor();
|
|
11
|
+
static getInstance(): WebSocketGatewayRegistry;
|
|
12
|
+
register(gatewayClass: Constructor<unknown>): void;
|
|
13
|
+
hasGateway(path: string): boolean;
|
|
14
|
+
clear(): void;
|
|
15
|
+
private getGateway;
|
|
16
|
+
private getGatewayInstance;
|
|
17
|
+
private invokeHandler;
|
|
18
|
+
handleOpen(ws: ServerWebSocket<WebSocketConnectionData>): void;
|
|
19
|
+
handleMessage(ws: ServerWebSocket<WebSocketConnectionData>, message: string | ArrayBuffer | ArrayBufferView): void;
|
|
20
|
+
handleClose(ws: ServerWebSocket<WebSocketConnectionData>, code: number, reason: string): void;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/websocket/registry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,KAAK,CAAC;AAK3C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAa/C,MAAM,WAAW,uBAAuB;IACtC,IAAI,EAAE,MAAM,CAAC;CACd;AAED,qBAAa,wBAAwB;IACnC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAA2B;IAClD,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAY;IACtC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAwC;IAEjE,OAAO;WAIO,WAAW,IAAI,wBAAwB;IAO9C,QAAQ,CAAC,YAAY,EAAE,WAAW,CAAC,OAAO,CAAC,GAAG,IAAI;IAsBlD,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAIjC,KAAK,IAAI,IAAI;IAIpB,OAAO,CAAC,UAAU;IAIlB,OAAO,CAAC,kBAAkB;IAO1B,OAAO,CAAC,aAAa;IAgBd,UAAU,CAAC,EAAE,EAAE,eAAe,CAAC,uBAAuB,CAAC,GAAG,IAAI;IAU9D,aAAa,CAClB,EAAE,EAAE,eAAe,CAAC,uBAAuB,CAAC,EAC5C,OAAO,EAAE,MAAM,GAAG,WAAW,GAAG,eAAe,GAC9C,IAAI;IAUA,WAAW,CAChB,EAAE,EAAE,eAAe,CAAC,uBAAuB,CAAC,EAC5C,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,GACb,IAAI;CAQR"}
|
package/package.json
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@dangao/bun-server",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"import": "./dist/index.js",
|
|
11
|
+
"default": "./dist/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "https://github.com/dangaogit/@dangao/bun-server.git"
|
|
17
|
+
},
|
|
18
|
+
"keywords": [
|
|
19
|
+
"bun",
|
|
20
|
+
"server",
|
|
21
|
+
"framework",
|
|
22
|
+
"di",
|
|
23
|
+
"logger",
|
|
24
|
+
"middleware"
|
|
25
|
+
],
|
|
26
|
+
"files": [
|
|
27
|
+
"dist"
|
|
28
|
+
],
|
|
29
|
+
"author": "dangaogit",
|
|
30
|
+
"license": "MIT",
|
|
31
|
+
"homepage": "https://github.com/dangaogit/@dangao/bun-server",
|
|
32
|
+
"bugs": {
|
|
33
|
+
"url": "https://github.com/dangaogit/@dangao/bun-server/issues"
|
|
34
|
+
},
|
|
35
|
+
"engines": {
|
|
36
|
+
"bun": ">=1.3.3"
|
|
37
|
+
},
|
|
38
|
+
"scripts": {
|
|
39
|
+
"dev": "bun --watch src/index.ts",
|
|
40
|
+
"test": "bun test",
|
|
41
|
+
"type-check": "tsc --noEmit",
|
|
42
|
+
"clean": "rm -rf dist",
|
|
43
|
+
"bundle": "bun build src/index.ts --target=bun --format=esm --outfile=dist/index.js --external reflect-metadata --external @dangao/logsmith",
|
|
44
|
+
"dts": "tsc -p tsconfig.build.json",
|
|
45
|
+
"build": "bun run clean && bun run bundle && bun run dts",
|
|
46
|
+
"prepare": "bun run build"
|
|
47
|
+
},
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"typescript": "5.9.3",
|
|
50
|
+
"@types/bun": "latest"
|
|
51
|
+
},
|
|
52
|
+
"dependencies": {
|
|
53
|
+
"reflect-metadata": "^0.2.2",
|
|
54
|
+
"@dangao/logsmith": "0.1.0"
|
|
55
|
+
}
|
|
56
|
+
}
|