@doracli/define-server 0.0.1 → 0.0.3

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/lib/cjs/index.js CHANGED
@@ -54,6 +54,8 @@ _defineProperty(ComponentBaseImpl, "handlerServer", void 0);
54
54
  _defineProperty(ComponentBaseImpl, "defineType", void 0);
55
55
  /** 默认的方法处理类型 */
56
56
  _defineProperty(ComponentBaseImpl, "defaultHandlerType", void 0);
57
+ /** 文件名到路由的映射,默认 "/" */
58
+ _defineProperty(ComponentBaseImpl, "fileRoute", void 0);
57
59
  /** 类的子路由与方法名进行绑定 */
58
60
  _defineProperty(ComponentBaseImpl, "routeFunNameMap", void 0);
59
61
  /** 方法名 -> 请求类型 */
@@ -82,7 +84,7 @@ var alias = function alias(name) {
82
84
  var component = function component(type) {
83
85
  return function (Target) {
84
86
  Target.handlerServer = true;
85
- Target.type = type || 'CLASS';
87
+ Target.defineType = type || 'CLASS';
86
88
  };
87
89
  };
88
90
 
@@ -99,6 +101,17 @@ var controller = function controller() {
99
101
  };
100
102
  };
101
103
 
104
+ /**
105
+ * 类装饰器
106
+ * @param fileRoute 文件路由名称
107
+ * @returns
108
+ */
109
+ var fileRoute = function fileRoute(_fileRoute) {
110
+ return function (Target) {
111
+ Target.fileRoute = _fileRoute;
112
+ };
113
+ };
114
+
102
115
  var method = function method() {
103
116
  for (var _len = arguments.length, methods = new Array(_len), _key = 0; _key < _len; _key++) {
104
117
  methods[_key] = arguments[_key];
@@ -166,6 +179,7 @@ exports.alias = alias;
166
179
  exports.component = component;
167
180
  exports.controller = controller;
168
181
  exports.defineControllerFun = defineControllerFun;
182
+ exports.fileRoute = fileRoute;
169
183
  exports.method = method;
170
184
  exports.restController = restController;
171
185
  exports.route = route;
package/lib/esm/index.js CHANGED
@@ -52,6 +52,8 @@ _defineProperty(ComponentBaseImpl, "handlerServer", void 0);
52
52
  _defineProperty(ComponentBaseImpl, "defineType", void 0);
53
53
  /** 默认的方法处理类型 */
54
54
  _defineProperty(ComponentBaseImpl, "defaultHandlerType", void 0);
55
+ /** 文件名到路由的映射,默认 "/" */
56
+ _defineProperty(ComponentBaseImpl, "fileRoute", void 0);
55
57
  /** 类的子路由与方法名进行绑定 */
56
58
  _defineProperty(ComponentBaseImpl, "routeFunNameMap", void 0);
57
59
  /** 方法名 -> 请求类型 */
@@ -80,7 +82,7 @@ var alias = function alias(name) {
80
82
  var component = function component(type) {
81
83
  return function (Target) {
82
84
  Target.handlerServer = true;
83
- Target.type = type || 'CLASS';
85
+ Target.defineType = type || 'CLASS';
84
86
  };
85
87
  };
86
88
 
@@ -97,6 +99,17 @@ var controller = function controller() {
97
99
  };
98
100
  };
99
101
 
102
+ /**
103
+ * 类装饰器
104
+ * @param fileRoute 文件路由名称
105
+ * @returns
106
+ */
107
+ var fileRoute = function fileRoute(_fileRoute) {
108
+ return function (Target) {
109
+ Target.fileRoute = _fileRoute;
110
+ };
111
+ };
112
+
100
113
  var method = function method() {
101
114
  for (var _len = arguments.length, methods = new Array(_len), _key = 0; _key < _len; _key++) {
102
115
  methods[_key] = arguments[_key];
@@ -158,4 +171,4 @@ var defineControllerFun = function defineControllerFun(cb) {
158
171
  return HandlerClass;
159
172
  };
160
173
 
161
- export { ComponentBaseImpl, DefaultHandlerName, alias, component, controller, defineControllerFun, method, restController, route };
174
+ export { ComponentBaseImpl, DefaultHandlerName, alias, component, controller, defineControllerFun, fileRoute, method, restController, route };
@@ -1,4 +1,4 @@
1
- import { TPlainObject, TPlainFunction, TAny } from '@cclr/lang';
1
+ import { TPlainFunction, TAny } from '@cclr/lang';
2
2
  import { Request, Response } from 'express';
3
3
  export { Request, Response } from 'express';
4
4
 
@@ -12,21 +12,7 @@ type TRoutesMap = {
12
12
  [route: string]: Record<TMethod, string>;
13
13
  };
14
14
 
15
- type TRouterHandlerFun = (req: Request, res: Response) => void | Promise<void>;
16
- type THandlerConfig = {
17
- /** 路由前缀 */
18
- route: string;
19
- /** handler文件相对路径 */
20
- relativeFilePath: string;
21
- /** 文件后缀 */
22
- fileExt: string;
23
- /** 文件名称 */
24
- fileName: string;
25
- /** 文件原始内容,类,函数,json */
26
- orange: TPlainObject;
27
- /** 统一后的类型 */
28
- Controller: TController;
29
- };
15
+ type TControllerFun = (req: Request, res: Response) => void | Promise<void>;
30
16
 
31
17
  type TController = typeof ComponentBaseImpl;
32
18
  declare class ComponentBaseImpl {
@@ -36,6 +22,8 @@ declare class ComponentBaseImpl {
36
22
  static defineType: TDefineType;
37
23
  /** 默认的方法处理类型 */
38
24
  static defaultHandlerType: TControllerType;
25
+ /** 文件名到路由的映射,默认 "/" */
26
+ static fileRoute: string;
39
27
  /** 类的子路由与方法名进行绑定 */
40
28
  static routeFunNameMap: {
41
29
  [route: string]: string;
@@ -59,7 +47,7 @@ declare const alias: (name: string) => <T extends TypedPropertyDescriptor<TPlain
59
47
  * @param type 决定解析方法,不需要传,默认就是`类`解析
60
48
  * @returns
61
49
  */
62
- declare const component: (type?: TControllerType) => <T extends new (...args: TAny[]) => TAny>(Target: T) => void;
50
+ declare const component: (type?: TDefineType) => <T extends new (...args: TAny[]) => TAny>(Target: T) => void;
63
51
 
64
52
  /**
65
53
  * 类装饰器,标记为服务组件
@@ -67,6 +55,13 @@ declare const component: (type?: TControllerType) => <T extends new (...args: TA
67
55
  */
68
56
  declare const controller: (defineType?: TDefineType) => <T extends new (...args: TAny[]) => TAny>(Target: T) => void;
69
57
 
58
+ /**
59
+ * 类装饰器
60
+ * @param fileRoute 文件路由名称
61
+ * @returns
62
+ */
63
+ declare const fileRoute: (fileRoute: string) => <T extends new (...args: TAny[]) => TAny>(Target: T) => void;
64
+
70
65
  declare const method: (...methods: TMethod[]) => <T extends TypedPropertyDescriptor<TPlainFunction>>(target: TAny, propertyKey: string, descriptor: T) => T;
71
66
 
72
67
  /**
@@ -82,11 +77,11 @@ declare const restController: () => <T extends new (...args: TAny[]) => TAny>(Ta
82
77
  */
83
78
  declare const route: (name?: string) => <T extends TypedPropertyDescriptor<TAny>>(target: TAny, propertyKey: string, descriptor: T) => T;
84
79
 
85
- declare const defineControllerFun: (cb: TRouterHandlerFun) => {
80
+ declare const defineControllerFun: (cb: TControllerFun) => {
86
81
  new (): {
87
82
  handlerFun(...args: any[]): any;
88
83
  };
89
84
  };
90
85
 
91
- export { ComponentBaseImpl, DefaultHandlerName, alias, component, controller, defineControllerFun, method, restController, route };
92
- export type { TController, TControllerType, TDefineType, THandlerConfig, TMethod, TRouterHandlerFun, TRoutesMap };
86
+ export { ComponentBaseImpl, DefaultHandlerName, alias, component, controller, defineControllerFun, fileRoute, method, restController, route };
87
+ export type { TController, TControllerFun, TControllerType, TDefineType, TMethod, TRoutesMap };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@doracli/define-server",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
4
4
  "description": "",
5
5
  "author": "cclr <18843152354@163.com>",
6
6
  "homepage": "",
@@ -27,7 +27,7 @@
27
27
  },
28
28
  "dependencies": {
29
29
  "@cclr/lang": "^0.1.28",
30
- "@types/express": "^5.0.3"
30
+ "@types/express": "^5.0.4"
31
31
  },
32
- "gitHead": "40ab496f25042487a671979074515f3345c96453"
32
+ "gitHead": "c89b02be8c385738ad80749447133d30e00b1f75"
33
33
  }