@eggjs/controller-decorator 4.0.0-beta.3 → 4.0.0-beta.5

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.
Files changed (118) hide show
  1. package/README.md +12 -0
  2. package/dist/builder/ControllerMetaBuilderFactory.d.ts +11 -0
  3. package/dist/builder/ControllerMetaBuilderFactory.js +37 -0
  4. package/dist/builder/index.js +3 -0
  5. package/dist/decorator/Acl.d.ts +4 -0
  6. package/dist/decorator/Acl.js +24 -0
  7. package/dist/decorator/Context.d.ts +4 -0
  8. package/dist/decorator/Context.js +16 -0
  9. package/dist/decorator/Middleware.d.ts +6 -0
  10. package/dist/decorator/Middleware.js +57 -0
  11. package/dist/decorator/http/HTTPController.d.ts +6 -0
  12. package/dist/decorator/http/HTTPController.js +23 -0
  13. package/dist/decorator/http/HTTPMethod.d.ts +6 -0
  14. package/dist/decorator/http/HTTPMethod.js +21 -0
  15. package/dist/decorator/http/HTTPParam.d.ts +12 -0
  16. package/dist/decorator/http/HTTPParam.js +77 -0
  17. package/dist/decorator/http/Host.d.ts +6 -0
  18. package/dist/decorator/http/Host.js +27 -0
  19. package/dist/decorator/http/index.js +6 -0
  20. package/dist/decorator/index.js +10 -0
  21. package/dist/impl/http/HTTPControllerMetaBuilder.d.ts +13 -0
  22. package/dist/impl/http/HTTPControllerMetaBuilder.js +63 -0
  23. package/dist/impl/http/HTTPControllerMethodMetaBuilder.d.ts +15 -0
  24. package/dist/impl/http/HTTPControllerMethodMetaBuilder.js +80 -0
  25. package/dist/impl/http/index.js +4 -0
  26. package/dist/impl/index.js +5 -0
  27. package/dist/index.d.ts +24 -0
  28. package/dist/index.js +31 -0
  29. package/dist/model/HTTPControllerMeta.d.ts +25 -0
  30. package/dist/model/HTTPControllerMeta.js +53 -0
  31. package/dist/model/HTTPCookies.d.ts +6 -0
  32. package/dist/model/HTTPCookies.js +7 -0
  33. package/dist/model/HTTPMethodMeta.d.ts +59 -0
  34. package/dist/model/HTTPMethodMeta.js +102 -0
  35. package/dist/model/HTTPRequest.d.ts +8 -0
  36. package/dist/model/HTTPRequest.js +5 -0
  37. package/dist/model/HTTPResponse.d.ts +11 -0
  38. package/dist/model/HTTPResponse.js +5 -0
  39. package/dist/model/index.js +7 -0
  40. package/dist/util/ControllerInfoUtil.d.ts +20 -0
  41. package/dist/util/ControllerInfoUtil.js +48 -0
  42. package/dist/util/ControllerMetadataUtil.d.ts +9 -0
  43. package/dist/util/ControllerMetadataUtil.js +21 -0
  44. package/dist/util/HTTPInfoUtil.d.ts +20 -0
  45. package/dist/util/HTTPInfoUtil.js +53 -0
  46. package/dist/util/HTTPPriorityUtil.d.ts +22 -0
  47. package/dist/util/HTTPPriorityUtil.js +38 -0
  48. package/dist/util/MethodInfoUtil.d.ts +23 -0
  49. package/dist/util/MethodInfoUtil.js +62 -0
  50. package/dist/util/index.js +10 -0
  51. package/dist/util/validator/ControllerValidator.d.ts +8 -0
  52. package/dist/util/validator/ControllerValidator.js +16 -0
  53. package/dist/util/validator/MethodValidator.d.ts +8 -0
  54. package/dist/util/validator/MethodValidator.js +31 -0
  55. package/dist/util/validator/index.js +4 -0
  56. package/package.json +26 -28
  57. package/src/builder/ControllerMetaBuilderFactory.d.ts +0 -7
  58. package/src/builder/ControllerMetaBuilderFactory.js +0 -41
  59. package/src/builder/index.d.ts +0 -1
  60. package/src/builder/index.js +0 -2
  61. package/src/decorator/Acl.d.ts +0 -1
  62. package/src/decorator/Acl.js +0 -22
  63. package/src/decorator/Context.d.ts +0 -1
  64. package/src/decorator/Context.js +0 -11
  65. package/src/decorator/Middleware.d.ts +0 -2
  66. package/src/decorator/Middleware.js +0 -69
  67. package/src/decorator/http/HTTPController.d.ts +0 -2
  68. package/src/decorator/http/HTTPController.js +0 -29
  69. package/src/decorator/http/HTTPMethod.d.ts +0 -2
  70. package/src/decorator/http/HTTPMethod.js +0 -17
  71. package/src/decorator/http/HTTPParam.d.ts +0 -8
  72. package/src/decorator/http/HTTPParam.js +0 -75
  73. package/src/decorator/http/Host.d.ts +0 -2
  74. package/src/decorator/http/Host.js +0 -25
  75. package/src/decorator/http/index.d.ts +0 -4
  76. package/src/decorator/http/index.js +0 -5
  77. package/src/decorator/index.d.ts +0 -4
  78. package/src/decorator/index.js +0 -5
  79. package/src/impl/http/HTTPControllerMetaBuilder.d.ts +0 -9
  80. package/src/impl/http/HTTPControllerMetaBuilder.js +0 -57
  81. package/src/impl/http/HTTPControllerMethodMetaBuilder.d.ts +0 -11
  82. package/src/impl/http/HTTPControllerMethodMetaBuilder.js +0 -100
  83. package/src/impl/http/index.d.ts +0 -2
  84. package/src/impl/http/index.js +0 -3
  85. package/src/impl/index.d.ts +0 -1
  86. package/src/impl/index.js +0 -2
  87. package/src/index.d.ts +0 -6
  88. package/src/index.js +0 -7
  89. package/src/model/HTTPControllerMeta.d.ts +0 -22
  90. package/src/model/HTTPControllerMeta.js +0 -59
  91. package/src/model/HTTPCookies.d.ts +0 -3
  92. package/src/model/HTTPCookies.js +0 -4
  93. package/src/model/HTTPMethodMeta.d.ts +0 -56
  94. package/src/model/HTTPMethodMeta.js +0 -124
  95. package/src/model/HTTPRequest.d.ts +0 -7
  96. package/src/model/HTTPRequest.js +0 -3
  97. package/src/model/HTTPResponse.d.ts +0 -10
  98. package/src/model/HTTPResponse.js +0 -3
  99. package/src/model/index.d.ts +0 -5
  100. package/src/model/index.js +0 -6
  101. package/src/util/ControllerInfoUtil.d.ts +0 -17
  102. package/src/util/ControllerInfoUtil.js +0 -46
  103. package/src/util/ControllerMetadataUtil.d.ts +0 -5
  104. package/src/util/ControllerMetadataUtil.js +0 -20
  105. package/src/util/HTTPInfoUtil.d.ts +0 -16
  106. package/src/util/HTTPInfoUtil.js +0 -64
  107. package/src/util/HTTPPriorityUtil.d.ts +0 -19
  108. package/src/util/HTTPPriorityUtil.js +0 -42
  109. package/src/util/MethodInfoUtil.d.ts +0 -20
  110. package/src/util/MethodInfoUtil.js +0 -72
  111. package/src/util/index.d.ts +0 -6
  112. package/src/util/index.js +0 -7
  113. package/src/util/validator/ControllerValidator.d.ts +0 -4
  114. package/src/util/validator/ControllerValidator.js +0 -15
  115. package/src/util/validator/MethodValidator.d.ts +0 -4
  116. package/src/util/validator/MethodValidator.js +0 -31
  117. package/src/util/validator/index.d.ts +0 -2
  118. package/src/util/validator/index.js +0 -3
package/dist/index.js ADDED
@@ -0,0 +1,31 @@
1
+ import { ControllerInfoUtil } from "./util/ControllerInfoUtil.js";
2
+ import { ControllerValidator } from "./util/validator/ControllerValidator.js";
3
+ import { MethodInfoUtil } from "./util/MethodInfoUtil.js";
4
+ import { MethodValidator } from "./util/validator/MethodValidator.js";
5
+ import { ControllerMetadataUtil } from "./util/ControllerMetadataUtil.js";
6
+ import { HTTPInfoUtil } from "./util/HTTPInfoUtil.js";
7
+ import { HTTPPriorityUtil } from "./util/HTTPPriorityUtil.js";
8
+ import "./util/index.js";
9
+ import { ControllerMetaBuilderFactory } from "./builder/ControllerMetaBuilderFactory.js";
10
+ import "./builder/index.js";
11
+ import { Host } from "./decorator/http/Host.js";
12
+ import { HTTPController } from "./decorator/http/HTTPController.js";
13
+ import { HTTPMethod } from "./decorator/http/HTTPMethod.js";
14
+ import { Cookies, HTTPBody, HTTPHeaders, HTTPParam, HTTPQueries, HTTPQuery, Request } from "./decorator/http/HTTPParam.js";
15
+ import { Acl } from "./decorator/Acl.js";
16
+ import { Context } from "./decorator/Context.js";
17
+ import { Middleware } from "./decorator/Middleware.js";
18
+ import "./decorator/index.js";
19
+ import { BodyParamMeta, CookiesParamMeta, HTTPMethodMeta, HeadersParamMeta, ParamMeta, ParamMetaUtil, PathParamMeta, QueriesParamMeta, QueryParamMeta, RequestParamMeta } from "./model/HTTPMethodMeta.js";
20
+ import { HTTPControllerMeta } from "./model/HTTPControllerMeta.js";
21
+ import { HTTPCookies } from "./model/HTTPCookies.js";
22
+ import { HTTPRequest } from "./model/HTTPRequest.js";
23
+ import { HTTPResponse } from "./model/HTTPResponse.js";
24
+ import "./model/index.js";
25
+ import { HTTPControllerMethodMetaBuilder } from "./impl/http/HTTPControllerMethodMetaBuilder.js";
26
+ import { HTTPControllerMetaBuilder } from "./impl/http/HTTPControllerMetaBuilder.js";
27
+ import "./impl/index.js";
28
+
29
+ export * from "@eggjs/tegg-types/controller-decorator"
30
+
31
+ export { Acl, BodyParamMeta, Context, ControllerInfoUtil, ControllerMetaBuilderFactory, ControllerMetadataUtil, ControllerValidator, Cookies, CookiesParamMeta, HTTPBody, HTTPController, HTTPControllerMeta, HTTPControllerMetaBuilder, HTTPControllerMethodMetaBuilder, HTTPCookies, HTTPHeaders, HTTPInfoUtil, HTTPMethod, HTTPMethodMeta, HTTPParam, HTTPPriorityUtil, HTTPQueries, HTTPQuery, HTTPRequest, HTTPResponse, HeadersParamMeta, Host, MethodInfoUtil, MethodValidator, Middleware, ParamMeta, ParamMetaUtil, PathParamMeta, QueriesParamMeta, QueryParamMeta, Request, RequestParamMeta };
@@ -0,0 +1,25 @@
1
+ import { HTTPMethodMeta } from "./HTTPMethodMeta.js";
2
+ import { ControllerMetadata, ControllerType, EggPrototypeName, MiddlewareFunc } from "@eggjs/tegg-types";
3
+
4
+ //#region src/model/HTTPControllerMeta.d.ts
5
+ declare class HTTPControllerMeta implements ControllerMetadata {
6
+ readonly protoName: EggPrototypeName;
7
+ readonly controllerName: string;
8
+ readonly className: string;
9
+ readonly type = ControllerType.HTTP;
10
+ readonly path?: string;
11
+ readonly middlewares: readonly MiddlewareFunc[];
12
+ readonly methods: readonly HTTPMethodMeta[];
13
+ readonly needAcl: boolean;
14
+ readonly aclCode?: string;
15
+ readonly hosts?: string[];
16
+ constructor(className: string, protoName: EggPrototypeName, controllerName: string, path: string | undefined, middlewares: MiddlewareFunc[], methods: HTTPMethodMeta[], needAcl: boolean, aclCode: string | undefined, hosts: string[] | undefined);
17
+ getMethodRealPath(method: HTTPMethodMeta): string;
18
+ getMethodHosts(method: HTTPMethodMeta): string[] | undefined;
19
+ getMethodName(method: HTTPMethodMeta): string;
20
+ getMethodMiddlewares(method: HTTPMethodMeta): MiddlewareFunc[];
21
+ hasMethodAcl(method: HTTPMethodMeta): boolean;
22
+ getMethodAcl(method: HTTPMethodMeta): string | undefined;
23
+ }
24
+ //#endregion
25
+ export { HTTPControllerMeta };
@@ -0,0 +1,53 @@
1
+ import "./HTTPMethodMeta.js";
2
+ import { ControllerType } from "@eggjs/tegg-types";
3
+ import path from "node:path";
4
+
5
+ //#region src/model/HTTPControllerMeta.ts
6
+ var HTTPControllerMeta = class {
7
+ protoName;
8
+ controllerName;
9
+ className;
10
+ type = ControllerType.HTTP;
11
+ path;
12
+ middlewares;
13
+ methods;
14
+ needAcl;
15
+ aclCode;
16
+ hosts;
17
+ constructor(className, protoName, controllerName, path$1, middlewares, methods, needAcl, aclCode, hosts) {
18
+ this.protoName = protoName;
19
+ this.controllerName = controllerName;
20
+ this.className = className;
21
+ this.path = path$1;
22
+ this.middlewares = middlewares;
23
+ this.methods = methods;
24
+ this.needAcl = needAcl;
25
+ this.aclCode = aclCode;
26
+ this.hosts = hosts;
27
+ }
28
+ getMethodRealPath(method) {
29
+ if (this.path) return path.posix.join(this.path, method.path);
30
+ return method.path;
31
+ }
32
+ getMethodHosts(method) {
33
+ if (this.hosts) return this.hosts;
34
+ return method.hosts;
35
+ }
36
+ getMethodName(method) {
37
+ return `${method.method} ${this.controllerName}.${method.name}`;
38
+ }
39
+ getMethodMiddlewares(method) {
40
+ if (this.middlewares.length) return [...this.middlewares, ...method.middlewares];
41
+ return [...method.middlewares];
42
+ }
43
+ hasMethodAcl(method) {
44
+ return method.needAcl || this.needAcl;
45
+ }
46
+ getMethodAcl(method) {
47
+ if (method.aclCode) return method.aclCode;
48
+ return this.aclCode;
49
+ }
50
+ };
51
+
52
+ //#endregion
53
+ export { HTTPControllerMeta };
@@ -0,0 +1,6 @@
1
+ import { Cookies } from "@eggjs/cookies";
2
+
3
+ //#region src/model/HTTPCookies.d.ts
4
+ declare class HTTPCookies extends Cookies {}
5
+ //#endregion
6
+ export { HTTPCookies };
@@ -0,0 +1,7 @@
1
+ import { Cookies } from "@eggjs/cookies";
2
+
3
+ //#region src/model/HTTPCookies.ts
4
+ var HTTPCookies = class extends Cookies {};
5
+
6
+ //#endregion
7
+ export { HTTPCookies };
@@ -0,0 +1,59 @@
1
+ import { HTTPMethodEnum, HTTPParamType, MethodMeta, MiddlewareFunc } from "@eggjs/tegg-types";
2
+
3
+ //#region src/model/HTTPMethodMeta.d.ts
4
+ declare abstract class ParamMeta {
5
+ type: HTTPParamType;
6
+ abstract validate(httpPath: string): void;
7
+ }
8
+ declare class RequestParamMeta extends ParamMeta {
9
+ type: HTTPParamType;
10
+ validate(): void;
11
+ }
12
+ declare class BodyParamMeta extends ParamMeta {
13
+ type: HTTPParamType;
14
+ validate(): void;
15
+ }
16
+ declare class HeadersParamMeta extends ParamMeta {
17
+ type: HTTPParamType;
18
+ validate(): void;
19
+ }
20
+ declare class QueryParamMeta extends ParamMeta {
21
+ type: HTTPParamType;
22
+ name: string;
23
+ constructor(name: string);
24
+ validate(): void;
25
+ }
26
+ declare class QueriesParamMeta extends ParamMeta {
27
+ type: HTTPParamType;
28
+ name: string;
29
+ constructor(name: string);
30
+ validate(): void;
31
+ }
32
+ declare class PathParamMeta extends ParamMeta {
33
+ type: HTTPParamType;
34
+ name: string;
35
+ constructor(name: string);
36
+ validate(httpPath: string): void;
37
+ }
38
+ declare class CookiesParamMeta extends ParamMeta {
39
+ type: HTTPParamType;
40
+ validate(): void;
41
+ }
42
+ declare class HTTPMethodMeta implements MethodMeta {
43
+ readonly name: string;
44
+ readonly path: string;
45
+ readonly method: HTTPMethodEnum;
46
+ readonly middlewares: readonly MiddlewareFunc[];
47
+ readonly contextParamIndex: number | undefined;
48
+ readonly paramMap: Map<number, ParamMeta>;
49
+ readonly priority: number;
50
+ readonly needAcl: boolean;
51
+ readonly aclCode: string | undefined;
52
+ readonly hosts: string[] | undefined;
53
+ constructor(name: string, path: string, method: HTTPMethodEnum, middlewares: MiddlewareFunc[], contextParamIndex: number | undefined, paramTypeMap: Map<number, ParamMeta>, priority: number, needAcl: boolean, aclCode: string | undefined, hosts: string[] | undefined);
54
+ }
55
+ declare class ParamMetaUtil {
56
+ static createParam(type: HTTPParamType, name?: string): RequestParamMeta | BodyParamMeta | HeadersParamMeta | QueryParamMeta | QueriesParamMeta | PathParamMeta | CookiesParamMeta;
57
+ }
58
+ //#endregion
59
+ export { BodyParamMeta, CookiesParamMeta, HTTPMethodMeta, HeadersParamMeta, ParamMeta, ParamMetaUtil, PathParamMeta, QueriesParamMeta, QueryParamMeta, RequestParamMeta };
@@ -0,0 +1,102 @@
1
+ import { HTTPParamType } from "@eggjs/tegg-types";
2
+ import pathToRegexp from "path-to-regexp";
3
+ import assert from "node:assert";
4
+
5
+ //#region src/model/HTTPMethodMeta.ts
6
+ var ParamMeta = class {
7
+ type;
8
+ };
9
+ var RequestParamMeta = class extends ParamMeta {
10
+ type = HTTPParamType.REQUEST;
11
+ validate() {}
12
+ };
13
+ var BodyParamMeta = class extends ParamMeta {
14
+ type = HTTPParamType.BODY;
15
+ validate() {}
16
+ };
17
+ var HeadersParamMeta = class extends ParamMeta {
18
+ type = HTTPParamType.HEADERS;
19
+ validate() {}
20
+ };
21
+ var QueryParamMeta = class extends ParamMeta {
22
+ type = HTTPParamType.QUERY;
23
+ name;
24
+ constructor(name) {
25
+ super();
26
+ this.name = name;
27
+ }
28
+ validate() {}
29
+ };
30
+ var QueriesParamMeta = class extends ParamMeta {
31
+ type = HTTPParamType.QUERIES;
32
+ name;
33
+ constructor(name) {
34
+ super();
35
+ this.name = name;
36
+ }
37
+ validate() {}
38
+ };
39
+ var PathParamMeta = class extends ParamMeta {
40
+ type = HTTPParamType.PARAM;
41
+ name;
42
+ constructor(name) {
43
+ super();
44
+ this.name = name;
45
+ }
46
+ validate(httpPath) {
47
+ const names = [];
48
+ pathToRegexp(httpPath, names);
49
+ if (!names.find((name) => String(name.name) === this.name)) throw new Error(`can not find param ${this.name} in path ${httpPath}`);
50
+ }
51
+ };
52
+ var CookiesParamMeta = class extends ParamMeta {
53
+ type = HTTPParamType.COOKIES;
54
+ validate() {}
55
+ };
56
+ var HTTPMethodMeta = class {
57
+ name;
58
+ path;
59
+ method;
60
+ middlewares;
61
+ contextParamIndex;
62
+ paramMap;
63
+ priority;
64
+ needAcl;
65
+ aclCode;
66
+ hosts;
67
+ constructor(name, path, method, middlewares, contextParamIndex, paramTypeMap, priority, needAcl, aclCode, hosts) {
68
+ this.name = name;
69
+ this.path = path;
70
+ this.method = method;
71
+ this.middlewares = middlewares;
72
+ this.contextParamIndex = contextParamIndex;
73
+ this.paramMap = paramTypeMap;
74
+ this.priority = priority;
75
+ this.needAcl = needAcl;
76
+ this.aclCode = aclCode;
77
+ this.hosts = hosts;
78
+ }
79
+ };
80
+ var ParamMetaUtil = class {
81
+ static createParam(type, name) {
82
+ switch (type) {
83
+ case HTTPParamType.PARAM:
84
+ assert(name, "path param must has name");
85
+ return new PathParamMeta(name);
86
+ case HTTPParamType.BODY: return new BodyParamMeta();
87
+ case HTTPParamType.HEADERS: return new HeadersParamMeta();
88
+ case HTTPParamType.QUERIES:
89
+ assert(name, "queries param must has name");
90
+ return new QueriesParamMeta(name);
91
+ case HTTPParamType.QUERY:
92
+ assert(name, "query param must has name");
93
+ return new QueryParamMeta(name);
94
+ case HTTPParamType.REQUEST: return new RequestParamMeta();
95
+ case HTTPParamType.COOKIES: return new CookiesParamMeta();
96
+ default: assert.fail("never arrive");
97
+ }
98
+ }
99
+ };
100
+
101
+ //#endregion
102
+ export { BodyParamMeta, CookiesParamMeta, HTTPMethodMeta, HeadersParamMeta, ParamMeta, ParamMetaUtil, PathParamMeta, QueriesParamMeta, QueryParamMeta, RequestParamMeta };
@@ -0,0 +1,8 @@
1
+ //#region src/model/HTTPRequest.d.ts
2
+ declare const HTTPRequest_base: ObjectConstructor | {
3
+ new (input: RequestInfo | URL, init?: RequestInit): Request;
4
+ prototype: Request;
5
+ };
6
+ declare class HTTPRequest extends HTTPRequest_base {}
7
+ //#endregion
8
+ export { HTTPRequest };
@@ -0,0 +1,5 @@
1
+ //#region src/model/HTTPRequest.ts
2
+ var HTTPRequest = class extends (Request || Object) {};
3
+
4
+ //#endregion
5
+ export { HTTPRequest };
@@ -0,0 +1,11 @@
1
+ //#region src/model/HTTPResponse.d.ts
2
+ declare const HTTPResponse_base: {
3
+ new (body?: BodyInit | null, init?: ResponseInit): Response;
4
+ prototype: Response;
5
+ error(): Response;
6
+ json(data: any, init?: ResponseInit): Response;
7
+ redirect(url: string | URL, status?: number): Response;
8
+ } | ObjectConstructor;
9
+ declare class HTTPResponse extends HTTPResponse_base {}
10
+ //#endregion
11
+ export { HTTPResponse };
@@ -0,0 +1,5 @@
1
+ //#region src/model/HTTPResponse.ts
2
+ var HTTPResponse = class extends (Response || Object) {};
3
+
4
+ //#endregion
5
+ export { HTTPResponse };
@@ -0,0 +1,7 @@
1
+ import { BodyParamMeta, CookiesParamMeta, HTTPMethodMeta, HeadersParamMeta, ParamMeta, ParamMetaUtil, PathParamMeta, QueriesParamMeta, QueryParamMeta, RequestParamMeta } from "./HTTPMethodMeta.js";
2
+ import { HTTPControllerMeta } from "./HTTPControllerMeta.js";
3
+ import { HTTPCookies } from "./HTTPCookies.js";
4
+ import { HTTPRequest } from "./HTTPRequest.js";
5
+ import { HTTPResponse } from "./HTTPResponse.js";
6
+
7
+ export { };
@@ -0,0 +1,20 @@
1
+ import { ControllerTypeLike, EggProtoImplClass, IAdvice, MiddlewareFunc } from "@eggjs/tegg-types";
2
+
3
+ //#region src/util/ControllerInfoUtil.d.ts
4
+ declare class ControllerInfoUtil {
5
+ static addControllerMiddleware(middleware: MiddlewareFunc, clazz: EggProtoImplClass): void;
6
+ static addControllerAopMiddleware(middleware: EggProtoImplClass<IAdvice>, clazz: EggProtoImplClass): void;
7
+ static getControllerMiddlewares(clazz: EggProtoImplClass): MiddlewareFunc[];
8
+ static getControllerAopMiddlewares(clazz: EggProtoImplClass): EggProtoImplClass<IAdvice>[];
9
+ static setControllerType(clazz: EggProtoImplClass, controllerType: ControllerTypeLike): void;
10
+ static setControllerName(clazz: EggProtoImplClass, controllerName: string): void;
11
+ static getControllerName(clazz: EggProtoImplClass): string | undefined;
12
+ static getControllerType(clazz: EggProtoImplClass): ControllerTypeLike | undefined;
13
+ static setControllerAcl(code: string | undefined, clazz: EggProtoImplClass): void;
14
+ static hasControllerAcl(clazz: EggProtoImplClass): boolean;
15
+ static getControllerAcl(clazz: EggProtoImplClass): string | undefined;
16
+ static addControllerHosts(hosts: string[], clazz: EggProtoImplClass): void;
17
+ static getControllerHosts(clazz: EggProtoImplClass): string[] | undefined;
18
+ }
19
+ //#endregion
20
+ export { ControllerInfoUtil };
@@ -0,0 +1,48 @@
1
+ import { CONTROLLER_ACL, CONTROLLER_AOP_MIDDLEWARES, CONTROLLER_HOST, CONTROLLER_MIDDLEWARES, CONTROLLER_NAME, CONTROLLER_TYPE } from "@eggjs/tegg-types";
2
+ import { MetadataUtil } from "@eggjs/core-decorator";
3
+
4
+ //#region src/util/ControllerInfoUtil.ts
5
+ var ControllerInfoUtil = class {
6
+ static addControllerMiddleware(middleware, clazz) {
7
+ MetadataUtil.initOwnArrayMetaData(CONTROLLER_MIDDLEWARES, clazz, []).push(middleware);
8
+ }
9
+ static addControllerAopMiddleware(middleware, clazz) {
10
+ MetadataUtil.initOwnArrayMetaData(CONTROLLER_AOP_MIDDLEWARES, clazz, []).push(middleware);
11
+ }
12
+ static getControllerMiddlewares(clazz) {
13
+ return MetadataUtil.getMetaData(CONTROLLER_MIDDLEWARES, clazz) || [];
14
+ }
15
+ static getControllerAopMiddlewares(clazz) {
16
+ return MetadataUtil.getMetaData(CONTROLLER_AOP_MIDDLEWARES, clazz) || [];
17
+ }
18
+ static setControllerType(clazz, controllerType) {
19
+ MetadataUtil.defineMetaData(CONTROLLER_TYPE, controllerType, clazz);
20
+ }
21
+ static setControllerName(clazz, controllerName) {
22
+ MetadataUtil.defineMetaData(CONTROLLER_NAME, controllerName, clazz);
23
+ }
24
+ static getControllerName(clazz) {
25
+ return MetadataUtil.getMetaData(CONTROLLER_NAME, clazz);
26
+ }
27
+ static getControllerType(clazz) {
28
+ return MetadataUtil.getMetaData(CONTROLLER_TYPE, clazz);
29
+ }
30
+ static setControllerAcl(code, clazz) {
31
+ MetadataUtil.defineMetaData(CONTROLLER_ACL, code, clazz);
32
+ }
33
+ static hasControllerAcl(clazz) {
34
+ return MetadataUtil.hasMetaData(CONTROLLER_ACL, clazz);
35
+ }
36
+ static getControllerAcl(clazz) {
37
+ return MetadataUtil.getMetaData(CONTROLLER_ACL, clazz);
38
+ }
39
+ static addControllerHosts(hosts, clazz) {
40
+ MetadataUtil.defineMetaData(CONTROLLER_HOST, hosts, clazz);
41
+ }
42
+ static getControllerHosts(clazz) {
43
+ return MetadataUtil.getMetaData(CONTROLLER_HOST, clazz);
44
+ }
45
+ };
46
+
47
+ //#endregion
48
+ export { ControllerInfoUtil };
@@ -0,0 +1,9 @@
1
+ import { ControllerMetadata, EggProtoImplClass } from "@eggjs/tegg-types";
2
+
3
+ //#region src/util/ControllerMetadataUtil.d.ts
4
+ declare class ControllerMetadataUtil {
5
+ static setControllerMetadata(clazz: EggProtoImplClass, metaData: ControllerMetadata): void;
6
+ static getControllerMetadata(clazz: EggProtoImplClass): ControllerMetadata | undefined;
7
+ }
8
+ //#endregion
9
+ export { ControllerMetadataUtil };
@@ -0,0 +1,21 @@
1
+ import { ControllerMetaBuilderFactory } from "../builder/ControllerMetaBuilderFactory.js";
2
+ import "../builder/index.js";
3
+ import { CONTROLLER_META_DATA } from "@eggjs/tegg-types";
4
+ import { MetadataUtil } from "@eggjs/core-decorator";
5
+
6
+ //#region src/util/ControllerMetadataUtil.ts
7
+ var ControllerMetadataUtil = class ControllerMetadataUtil {
8
+ static setControllerMetadata(clazz, metaData) {
9
+ MetadataUtil.defineMetaData(CONTROLLER_META_DATA, metaData, clazz);
10
+ }
11
+ static getControllerMetadata(clazz) {
12
+ let metadata = MetadataUtil.getOwnMetaData(CONTROLLER_META_DATA, clazz);
13
+ if (metadata) return metadata;
14
+ metadata = ControllerMetaBuilderFactory.build(clazz);
15
+ if (metadata) ControllerMetadataUtil.setControllerMetadata(clazz, metadata);
16
+ return metadata;
17
+ }
18
+ };
19
+
20
+ //#endregion
21
+ export { ControllerMetadataUtil };
@@ -0,0 +1,20 @@
1
+ import { EggProtoImplClass, HTTPMethodEnum, HTTPParamType } from "@eggjs/tegg-types";
2
+
3
+ //#region src/util/HTTPInfoUtil.d.ts
4
+ declare class HTTPInfoUtil {
5
+ static setHTTPPath(path: string, clazz: EggProtoImplClass): void;
6
+ static getHTTPPath(clazz: EggProtoImplClass): string | undefined;
7
+ static setHTTPMethodPath(path: string, clazz: EggProtoImplClass, methodName: string): void;
8
+ static getHTTPMethodPath(clazz: EggProtoImplClass, methodName: string): string | undefined;
9
+ static setHTTPMethodMethod(method: HTTPMethodEnum, clazz: EggProtoImplClass, methodName: string): void;
10
+ static getHTTPMethodMethod(clazz: EggProtoImplClass, methodName: string): HTTPMethodEnum | undefined;
11
+ static setHTTPMethodParamType(paramType: HTTPParamType, parameterIndex: number, clazz: EggProtoImplClass, methodName: string): void;
12
+ static getParamIndexList(clazz: EggProtoImplClass, methodName: string): number[];
13
+ static getHTTPMethodParamType(parameterIndex: number, clazz: EggProtoImplClass, methodName: string): HTTPParamType | undefined;
14
+ static setHTTPMethodParamName(paramName: string, parameterIndex: number, clazz: EggProtoImplClass, methodName: string): void;
15
+ static getHTTPMethodParamName(parameterIndex: number, clazz: EggProtoImplClass, methodName: string): string | undefined;
16
+ static getHTTPMethodPriority(clazz: EggProtoImplClass, methodName: string): number | undefined;
17
+ static setHTTPMethodPriority(priority: number, clazz: EggProtoImplClass, methodName: string): void;
18
+ }
19
+ //#endregion
20
+ export { HTTPInfoUtil };
@@ -0,0 +1,53 @@
1
+ import { CONTROLLER_HTTP_PATH, CONTROLLER_METHOD_METHOD_MAP, CONTROLLER_METHOD_PARAM_NAME_MAP, CONTROLLER_METHOD_PARAM_TYPE_MAP, CONTROLLER_METHOD_PATH_MAP, CONTROLLER_METHOD_PRIORITY } from "@eggjs/tegg-types";
2
+ import { MetadataUtil } from "@eggjs/core-decorator";
3
+ import { MapUtil } from "@eggjs/tegg-common-util";
4
+
5
+ //#region src/util/HTTPInfoUtil.ts
6
+ var HTTPInfoUtil = class {
7
+ static setHTTPPath(path, clazz) {
8
+ MetadataUtil.defineMetaData(CONTROLLER_HTTP_PATH, path, clazz);
9
+ }
10
+ static getHTTPPath(clazz) {
11
+ return MetadataUtil.getMetaData(CONTROLLER_HTTP_PATH, clazz);
12
+ }
13
+ static setHTTPMethodPath(path, clazz, methodName) {
14
+ MetadataUtil.initOwnMapMetaData(CONTROLLER_METHOD_PATH_MAP, clazz, /* @__PURE__ */ new Map()).set(methodName, path);
15
+ }
16
+ static getHTTPMethodPath(clazz, methodName) {
17
+ return MetadataUtil.getMetaData(CONTROLLER_METHOD_PATH_MAP, clazz)?.get(methodName);
18
+ }
19
+ static setHTTPMethodMethod(method, clazz, methodName) {
20
+ MetadataUtil.initOwnMapMetaData(CONTROLLER_METHOD_METHOD_MAP, clazz, /* @__PURE__ */ new Map()).set(methodName, method);
21
+ }
22
+ static getHTTPMethodMethod(clazz, methodName) {
23
+ return MetadataUtil.getMetaData(CONTROLLER_METHOD_METHOD_MAP, clazz)?.get(methodName);
24
+ }
25
+ static setHTTPMethodParamType(paramType, parameterIndex, clazz, methodName) {
26
+ const methodParamMap = MetadataUtil.initOwnMapMetaData(CONTROLLER_METHOD_PARAM_TYPE_MAP, clazz, /* @__PURE__ */ new Map());
27
+ MapUtil.getOrStore(methodParamMap, methodName, /* @__PURE__ */ new Map()).set(parameterIndex, paramType);
28
+ }
29
+ static getParamIndexList(clazz, methodName) {
30
+ const paramMap = MetadataUtil.getMetaData(CONTROLLER_METHOD_PARAM_TYPE_MAP, clazz)?.get(methodName);
31
+ if (!paramMap) return [];
32
+ return Array.from(paramMap.keys());
33
+ }
34
+ static getHTTPMethodParamType(parameterIndex, clazz, methodName) {
35
+ return (MetadataUtil.getMetaData(CONTROLLER_METHOD_PARAM_TYPE_MAP, clazz)?.get(methodName))?.get(parameterIndex);
36
+ }
37
+ static setHTTPMethodParamName(paramName, parameterIndex, clazz, methodName) {
38
+ const methodParamNameMap = MetadataUtil.initOwnMapMetaData(CONTROLLER_METHOD_PARAM_NAME_MAP, clazz, /* @__PURE__ */ new Map());
39
+ MapUtil.getOrStore(methodParamNameMap, methodName, /* @__PURE__ */ new Map()).set(parameterIndex, paramName);
40
+ }
41
+ static getHTTPMethodParamName(parameterIndex, clazz, methodName) {
42
+ return (MetadataUtil.getMetaData(CONTROLLER_METHOD_PARAM_NAME_MAP, clazz)?.get(methodName))?.get(parameterIndex);
43
+ }
44
+ static getHTTPMethodPriority(clazz, methodName) {
45
+ return MetadataUtil.getMetaData(CONTROLLER_METHOD_PRIORITY, clazz)?.get(methodName);
46
+ }
47
+ static setHTTPMethodPriority(priority, clazz, methodName) {
48
+ MetadataUtil.initOwnMapMetaData(CONTROLLER_METHOD_PRIORITY, clazz, /* @__PURE__ */ new Map()).set(methodName, priority);
49
+ }
50
+ };
51
+
52
+ //#endregion
53
+ export { HTTPInfoUtil };
@@ -0,0 +1,22 @@
1
+ //#region src/util/HTTPPriorityUtil.d.ts
2
+ declare class HTTPPriorityUtil {
3
+ static readonly DEFAULT_PRIORITY = 100000;
4
+ private static readonly TOKEN_PRIORITY;
5
+ /**
6
+ * | Path | RegExp index | priority |
7
+ * | --- | --- | --- |
8
+ * | /* | [0] | 0 |
9
+ * | /hello/:name | [1] | 1000 |
10
+ * | /hello/world/message/:message | [3] | 3000 |
11
+ * | /hello/:name/message/:message | [1, 3] | 4000 |
12
+ * | /hello/world | [] | 100000/Infinity? |
13
+ *
14
+ * priority = hasRegExp
15
+ * : regexpIndex.reduce((p,c) => p + c * 1000, 0)
16
+ * : 100000;
17
+ * @param {string} path -
18
+ */
19
+ static calcPathPriority(path: string): number;
20
+ }
21
+ //#endregion
22
+ export { HTTPPriorityUtil };
@@ -0,0 +1,38 @@
1
+ import { parse } from "path-to-regexp";
2
+
3
+ //#region src/util/HTTPPriorityUtil.ts
4
+ var HTTPPriorityUtil = class {
5
+ static DEFAULT_PRIORITY = 1e5;
6
+ static TOKEN_PRIORITY = 1e3;
7
+ /**
8
+ * | Path | RegExp index | priority |
9
+ * | --- | --- | --- |
10
+ * | /* | [0] | 0 |
11
+ * | /hello/:name | [1] | 1000 |
12
+ * | /hello/world/message/:message | [3] | 3000 |
13
+ * | /hello/:name/message/:message | [1, 3] | 4000 |
14
+ * | /hello/world | [] | 100000/Infinity? |
15
+ *
16
+ * priority = hasRegExp
17
+ * : regexpIndex.reduce((p,c) => p + c * 1000, 0)
18
+ * : 100000;
19
+ * @param {string} path -
20
+ */
21
+ static calcPathPriority(path) {
22
+ const tokens = parse(path);
23
+ let priority = 0;
24
+ let hasRegExp = false;
25
+ let index = 0;
26
+ let token;
27
+ while (token = tokens.shift()) if (typeof token === "string") index += token.split("/").length - 1;
28
+ else {
29
+ hasRegExp = true;
30
+ priority += index++ * this.TOKEN_PRIORITY;
31
+ }
32
+ if (!hasRegExp) return this.DEFAULT_PRIORITY;
33
+ return priority;
34
+ }
35
+ };
36
+
37
+ //#endregion
38
+ export { HTTPPriorityUtil };
@@ -0,0 +1,23 @@
1
+ import { ControllerTypeLike, EggProtoImplClass, IAdvice, MiddlewareFunc } from "@eggjs/tegg-types";
2
+
3
+ //#region src/util/MethodInfoUtil.d.ts
4
+ declare class MethodInfoUtil {
5
+ static setMethodControllerType(clazz: EggProtoImplClass, methodName: string, controllerType: ControllerTypeLike): void;
6
+ static getMethodControllerType(clazz: EggProtoImplClass, methodName: string): ControllerTypeLike | undefined;
7
+ static setMethodContextIndexInArgs(index: number, clazz: EggProtoImplClass, methodName: string): void;
8
+ static getMethodContextIndex(clazz: EggProtoImplClass, methodName: string): number | undefined;
9
+ static addMethodMiddleware(middleware: MiddlewareFunc, clazz: EggProtoImplClass, methodName: string): void;
10
+ static getMethodMiddlewares(clazz: EggProtoImplClass, methodName: string): MiddlewareFunc[];
11
+ static addMethodAopMiddleware(middleware: EggProtoImplClass<IAdvice>, clazz: EggProtoImplClass, methodName: string): void;
12
+ static getMethodAopMiddlewares(clazz: EggProtoImplClass, methodName: string): EggProtoImplClass<IAdvice>[];
13
+ static setMethodAcl(code: string | undefined, clazz: EggProtoImplClass, methodName: string): void;
14
+ static hasMethodAcl(clazz: EggProtoImplClass, methodName: string): boolean;
15
+ static getMethodAcl(clazz: EggProtoImplClass, methodName: string): string | undefined;
16
+ static setMethodHosts(hosts: string[], clazz: EggProtoImplClass, methodName: string): void;
17
+ static getMethodHosts(clazz: EggProtoImplClass, methodName: string): string[] | undefined;
18
+ static getMethods(clazz: EggProtoImplClass): string[];
19
+ static shouldRegisterAopMiddlewarePointCut(clazz: EggProtoImplClass, methodName: string): boolean;
20
+ static registerAopMiddlewarePointcut(clazz: EggProtoImplClass, methodName: string): void;
21
+ }
22
+ //#endregion
23
+ export { MethodInfoUtil };
@@ -0,0 +1,62 @@
1
+ import { METHOD_ACL, METHOD_AOP_MIDDLEWARES, METHOD_AOP_REGISTER_MAP, METHOD_CONTEXT_INDEX, METHOD_CONTROLLER_HOST, METHOD_CONTROLLER_TYPE_MAP, METHOD_MIDDLEWARES } from "@eggjs/tegg-types";
2
+ import { MetadataUtil } from "@eggjs/core-decorator";
3
+ import { MapUtil } from "@eggjs/tegg-common-util";
4
+
5
+ //#region src/util/MethodInfoUtil.ts
6
+ var MethodInfoUtil = class {
7
+ static setMethodControllerType(clazz, methodName, controllerType) {
8
+ MetadataUtil.initOwnMapMetaData(METHOD_CONTROLLER_TYPE_MAP, clazz, /* @__PURE__ */ new Map()).set(methodName, controllerType);
9
+ }
10
+ static getMethodControllerType(clazz, methodName) {
11
+ return MetadataUtil.getMetaData(METHOD_CONTROLLER_TYPE_MAP, clazz)?.get(methodName);
12
+ }
13
+ static setMethodContextIndexInArgs(index, clazz, methodName) {
14
+ MetadataUtil.initOwnMapMetaData(METHOD_CONTEXT_INDEX, clazz, /* @__PURE__ */ new Map()).set(methodName, index);
15
+ }
16
+ static getMethodContextIndex(clazz, methodName) {
17
+ return MetadataUtil.getMetaData(METHOD_CONTEXT_INDEX, clazz)?.get(methodName);
18
+ }
19
+ static addMethodMiddleware(middleware, clazz, methodName) {
20
+ const methodMiddlewareMap = MetadataUtil.initOwnMapMetaData(METHOD_MIDDLEWARES, clazz, /* @__PURE__ */ new Map());
21
+ MapUtil.getOrStore(methodMiddlewareMap, methodName, []).push(middleware);
22
+ }
23
+ static getMethodMiddlewares(clazz, methodName) {
24
+ return MetadataUtil.getMetaData(METHOD_MIDDLEWARES, clazz)?.get(methodName) || [];
25
+ }
26
+ static addMethodAopMiddleware(middleware, clazz, methodName) {
27
+ const methodMiddlewareMap = MetadataUtil.initOwnMapMetaData(METHOD_AOP_MIDDLEWARES, clazz, /* @__PURE__ */ new Map());
28
+ MapUtil.getOrStore(methodMiddlewareMap, methodName, []).push(middleware);
29
+ }
30
+ static getMethodAopMiddlewares(clazz, methodName) {
31
+ return MetadataUtil.getMetaData(METHOD_AOP_MIDDLEWARES, clazz)?.get(methodName) || [];
32
+ }
33
+ static setMethodAcl(code, clazz, methodName) {
34
+ MetadataUtil.initOwnMapMetaData(METHOD_ACL, clazz, /* @__PURE__ */ new Map()).set(methodName, code);
35
+ }
36
+ static hasMethodAcl(clazz, methodName) {
37
+ return !!MetadataUtil.getMetaData(METHOD_ACL, clazz)?.has(methodName);
38
+ }
39
+ static getMethodAcl(clazz, methodName) {
40
+ return MetadataUtil.getMetaData(METHOD_ACL, clazz)?.get(methodName);
41
+ }
42
+ static setMethodHosts(hosts, clazz, methodName) {
43
+ MetadataUtil.initOwnMapMetaData(METHOD_CONTROLLER_HOST, clazz, /* @__PURE__ */ new Map()).set(methodName, hosts);
44
+ }
45
+ static getMethodHosts(clazz, methodName) {
46
+ return MetadataUtil.getMetaData(METHOD_CONTROLLER_HOST, clazz)?.get(methodName);
47
+ }
48
+ static getMethods(clazz) {
49
+ const methodControllerMap = MetadataUtil.getMetaData(METHOD_CONTROLLER_TYPE_MAP, clazz);
50
+ return Array.from(methodControllerMap?.keys() || []);
51
+ }
52
+ static shouldRegisterAopMiddlewarePointCut(clazz, methodName) {
53
+ const methodControllerMap = MetadataUtil.getMetaData(METHOD_AOP_REGISTER_MAP, clazz);
54
+ return !(methodControllerMap && methodControllerMap.get(methodName));
55
+ }
56
+ static registerAopMiddlewarePointcut(clazz, methodName) {
57
+ MetadataUtil.initOwnMapMetaData(METHOD_AOP_REGISTER_MAP, clazz, /* @__PURE__ */ new Map()).set(methodName, true);
58
+ }
59
+ };
60
+
61
+ //#endregion
62
+ export { MethodInfoUtil };