@eggjs/controller-decorator 4.0.0-beta.6 → 4.0.0-beta.8

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 (55) hide show
  1. package/dist/index.d.ts +247 -23
  2. package/dist/index.js +749 -28
  3. package/package.json +6 -6
  4. package/dist/builder/ControllerMetaBuilderFactory.d.ts +0 -11
  5. package/dist/builder/ControllerMetaBuilderFactory.js +0 -37
  6. package/dist/builder/index.js +0 -3
  7. package/dist/decorator/Acl.d.ts +0 -4
  8. package/dist/decorator/Acl.js +0 -24
  9. package/dist/decorator/Context.d.ts +0 -4
  10. package/dist/decorator/Context.js +0 -16
  11. package/dist/decorator/Middleware.d.ts +0 -6
  12. package/dist/decorator/Middleware.js +0 -57
  13. package/dist/decorator/http/HTTPController.d.ts +0 -6
  14. package/dist/decorator/http/HTTPController.js +0 -23
  15. package/dist/decorator/http/HTTPMethod.d.ts +0 -6
  16. package/dist/decorator/http/HTTPMethod.js +0 -21
  17. package/dist/decorator/http/HTTPParam.d.ts +0 -12
  18. package/dist/decorator/http/HTTPParam.js +0 -77
  19. package/dist/decorator/http/Host.d.ts +0 -6
  20. package/dist/decorator/http/Host.js +0 -27
  21. package/dist/decorator/http/index.js +0 -6
  22. package/dist/decorator/index.js +0 -10
  23. package/dist/impl/http/HTTPControllerMetaBuilder.d.ts +0 -13
  24. package/dist/impl/http/HTTPControllerMetaBuilder.js +0 -63
  25. package/dist/impl/http/HTTPControllerMethodMetaBuilder.d.ts +0 -15
  26. package/dist/impl/http/HTTPControllerMethodMetaBuilder.js +0 -80
  27. package/dist/impl/http/index.js +0 -4
  28. package/dist/impl/index.js +0 -5
  29. package/dist/model/HTTPControllerMeta.d.ts +0 -25
  30. package/dist/model/HTTPControllerMeta.js +0 -53
  31. package/dist/model/HTTPCookies.d.ts +0 -6
  32. package/dist/model/HTTPCookies.js +0 -7
  33. package/dist/model/HTTPMethodMeta.d.ts +0 -59
  34. package/dist/model/HTTPMethodMeta.js +0 -102
  35. package/dist/model/HTTPRequest.d.ts +0 -8
  36. package/dist/model/HTTPRequest.js +0 -5
  37. package/dist/model/HTTPResponse.d.ts +0 -11
  38. package/dist/model/HTTPResponse.js +0 -5
  39. package/dist/model/index.js +0 -7
  40. package/dist/util/ControllerInfoUtil.d.ts +0 -20
  41. package/dist/util/ControllerInfoUtil.js +0 -48
  42. package/dist/util/ControllerMetadataUtil.d.ts +0 -9
  43. package/dist/util/ControllerMetadataUtil.js +0 -21
  44. package/dist/util/HTTPInfoUtil.d.ts +0 -20
  45. package/dist/util/HTTPInfoUtil.js +0 -53
  46. package/dist/util/HTTPPriorityUtil.d.ts +0 -22
  47. package/dist/util/HTTPPriorityUtil.js +0 -38
  48. package/dist/util/MethodInfoUtil.d.ts +0 -23
  49. package/dist/util/MethodInfoUtil.js +0 -62
  50. package/dist/util/index.js +0 -10
  51. package/dist/util/validator/ControllerValidator.d.ts +0 -8
  52. package/dist/util/validator/ControllerValidator.js +0 -16
  53. package/dist/util/validator/MethodValidator.d.ts +0 -8
  54. package/dist/util/validator/MethodValidator.js +0 -31
  55. package/dist/util/validator/index.js +0 -4
package/dist/index.d.ts CHANGED
@@ -1,24 +1,248 @@
1
- import { ControllerMetaBuilderFactory } from "./builder/ControllerMetaBuilderFactory.js";
2
- import { Host } from "./decorator/http/Host.js";
3
- import { HTTPController } from "./decorator/http/HTTPController.js";
4
- import { HTTPMethod } from "./decorator/http/HTTPMethod.js";
5
- import { Cookies, HTTPBody, HTTPHeaders, HTTPParam, HTTPQueries, HTTPQuery, Request } from "./decorator/http/HTTPParam.js";
6
- import { Acl } from "./decorator/Acl.js";
7
- import { Context } from "./decorator/Context.js";
8
- import { Middleware } from "./decorator/Middleware.js";
9
- import { BodyParamMeta, CookiesParamMeta, HTTPMethodMeta, HeadersParamMeta, ParamMeta, ParamMetaUtil, PathParamMeta, QueriesParamMeta, QueryParamMeta, RequestParamMeta } from "./model/HTTPMethodMeta.js";
10
- import { HTTPControllerMeta } from "./model/HTTPControllerMeta.js";
11
- import { HTTPCookies } from "./model/HTTPCookies.js";
12
- import { HTTPRequest } from "./model/HTTPRequest.js";
13
- import { HTTPResponse } from "./model/HTTPResponse.js";
14
- import { HTTPControllerMetaBuilder } from "./impl/http/HTTPControllerMetaBuilder.js";
15
- import { HTTPControllerMethodMetaBuilder } from "./impl/http/HTTPControllerMethodMetaBuilder.js";
16
- import { ControllerValidator } from "./util/validator/ControllerValidator.js";
17
- import { MethodValidator } from "./util/validator/MethodValidator.js";
18
- import { ControllerInfoUtil } from "./util/ControllerInfoUtil.js";
19
- import { ControllerMetadataUtil } from "./util/ControllerMetadataUtil.js";
20
- import { HTTPInfoUtil } from "./util/HTTPInfoUtil.js";
21
- import { HTTPPriorityUtil } from "./util/HTTPPriorityUtil.js";
22
- import { MethodInfoUtil } from "./util/MethodInfoUtil.js";
1
+ import { ControllerMetaBuilder, ControllerMetaBuilderCreator, ControllerMetadata, ControllerType, ControllerTypeLike, EggProtoImplClass, EggPrototypeName, HTTPControllerParams, HTTPMethodEnum, HTTPMethodParams, HTTPParamParams, HTTPParamType, HTTPQueriesParams, HTTPQueryParams, HostType, IAdvice, MethodMeta, MiddlewareFunc } from "@eggjs/tegg-types";
2
+ import { Cookies as Cookies$1 } from "@eggjs/cookies";
23
3
  export * from "@eggjs/tegg-types/controller-decorator";
24
- 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 };
4
+
5
+ //#region src/builder/ControllerMetaBuilderFactory.d.ts
6
+ declare class ControllerMetaBuilderFactory {
7
+ private static builderCreatorMap;
8
+ static registerControllerMetaBuilder(controllerType: ControllerTypeLike, controllerBuilderCreator: ControllerMetaBuilderCreator): void;
9
+ static createControllerMetaBuilder(clazz: EggProtoImplClass, controllerType?: ControllerTypeLike): ControllerMetaBuilder | undefined;
10
+ static build(clazz: EggProtoImplClass, controllerType?: ControllerTypeLike): ControllerMetadata | undefined;
11
+ }
12
+ //#endregion
13
+ //#region src/decorator/http/Host.d.ts
14
+ declare function Host(host: HostType): (target: any, propertyKey?: PropertyKey) => void;
15
+ //#endregion
16
+ //#region src/decorator/http/HTTPController.d.ts
17
+ declare function HTTPController(param?: HTTPControllerParams): (constructor: EggProtoImplClass) => void;
18
+ //#endregion
19
+ //#region src/decorator/http/HTTPMethod.d.ts
20
+ declare function HTTPMethod(param: HTTPMethodParams): (target: any, propertyKey: PropertyKey) => void;
21
+ //#endregion
22
+ //#region src/decorator/http/HTTPParam.d.ts
23
+ declare function HTTPBody(): (target: any, propertyKey: PropertyKey, parameterIndex: number) => void;
24
+ declare function HTTPHeaders(): (target: any, propertyKey: PropertyKey, parameterIndex: number) => void;
25
+ declare function HTTPQuery(param?: HTTPQueryParams): (target: any, propertyKey: PropertyKey, parameterIndex: number) => void;
26
+ declare function HTTPQueries(param?: HTTPQueriesParams): (target: any, propertyKey: PropertyKey, parameterIndex: number) => void;
27
+ declare function HTTPParam(param?: HTTPParamParams): (target: any, propertyKey: PropertyKey, parameterIndex: number) => void;
28
+ declare function Request$1(): (target: any, propertyKey: PropertyKey, parameterIndex: number) => void;
29
+ declare function Cookies(): (target: any, propertyKey: PropertyKey, parameterIndex: number) => void;
30
+ //#endregion
31
+ //#region src/decorator/Acl.d.ts
32
+ declare function Acl(code?: string): (target: any, propertyKey?: PropertyKey) => void;
33
+ //#endregion
34
+ //#region src/decorator/Context.d.ts
35
+ declare function Context(): (target: any, propertyKey: PropertyKey, parameterIndex: number) => void;
36
+ //#endregion
37
+ //#region src/decorator/Middleware.d.ts
38
+ declare function Middleware(...middlewares: Array<MiddlewareFunc> | Array<EggProtoImplClass<IAdvice>>): (target: any, propertyKey?: PropertyKey) => void;
39
+ //#endregion
40
+ //#region src/model/HTTPMethodMeta.d.ts
41
+ declare abstract class ParamMeta {
42
+ type: HTTPParamType;
43
+ abstract validate(httpPath: string): void;
44
+ }
45
+ declare class RequestParamMeta extends ParamMeta {
46
+ type: HTTPParamType;
47
+ validate(): void;
48
+ }
49
+ declare class BodyParamMeta extends ParamMeta {
50
+ type: HTTPParamType;
51
+ validate(): void;
52
+ }
53
+ declare class HeadersParamMeta extends ParamMeta {
54
+ type: HTTPParamType;
55
+ validate(): void;
56
+ }
57
+ declare class QueryParamMeta extends ParamMeta {
58
+ type: HTTPParamType;
59
+ name: string;
60
+ constructor(name: string);
61
+ validate(): void;
62
+ }
63
+ declare class QueriesParamMeta extends ParamMeta {
64
+ type: HTTPParamType;
65
+ name: string;
66
+ constructor(name: string);
67
+ validate(): void;
68
+ }
69
+ declare class PathParamMeta extends ParamMeta {
70
+ type: HTTPParamType;
71
+ name: string;
72
+ constructor(name: string);
73
+ validate(httpPath: string): void;
74
+ }
75
+ declare class CookiesParamMeta extends ParamMeta {
76
+ type: HTTPParamType;
77
+ validate(): void;
78
+ }
79
+ declare class HTTPMethodMeta implements MethodMeta {
80
+ readonly name: string;
81
+ readonly path: string;
82
+ readonly method: HTTPMethodEnum;
83
+ readonly middlewares: readonly MiddlewareFunc[];
84
+ readonly contextParamIndex: number | undefined;
85
+ readonly paramMap: Map<number, ParamMeta>;
86
+ readonly priority: number;
87
+ readonly needAcl: boolean;
88
+ readonly aclCode: string | undefined;
89
+ readonly hosts: string[] | undefined;
90
+ 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);
91
+ }
92
+ declare class ParamMetaUtil {
93
+ static createParam(type: HTTPParamType, name?: string): RequestParamMeta | BodyParamMeta | HeadersParamMeta | QueryParamMeta | QueriesParamMeta | PathParamMeta | CookiesParamMeta;
94
+ }
95
+ //#endregion
96
+ //#region src/model/HTTPControllerMeta.d.ts
97
+ declare class HTTPControllerMeta implements ControllerMetadata {
98
+ readonly protoName: EggPrototypeName;
99
+ readonly controllerName: string;
100
+ readonly className: string;
101
+ readonly type = ControllerType.HTTP;
102
+ readonly path?: string;
103
+ readonly middlewares: readonly MiddlewareFunc[];
104
+ readonly methods: readonly HTTPMethodMeta[];
105
+ readonly needAcl: boolean;
106
+ readonly aclCode?: string;
107
+ readonly hosts?: string[];
108
+ constructor(className: string, protoName: EggPrototypeName, controllerName: string, path: string | undefined, middlewares: MiddlewareFunc[], methods: HTTPMethodMeta[], needAcl: boolean, aclCode: string | undefined, hosts: string[] | undefined);
109
+ getMethodRealPath(method: HTTPMethodMeta): string;
110
+ getMethodHosts(method: HTTPMethodMeta): string[] | undefined;
111
+ getMethodName(method: HTTPMethodMeta): string;
112
+ getMethodMiddlewares(method: HTTPMethodMeta): MiddlewareFunc[];
113
+ hasMethodAcl(method: HTTPMethodMeta): boolean;
114
+ getMethodAcl(method: HTTPMethodMeta): string | undefined;
115
+ }
116
+ //#endregion
117
+ //#region src/model/HTTPCookies.d.ts
118
+ declare class HTTPCookies extends Cookies$1 {}
119
+ //#endregion
120
+ //#region src/model/HTTPRequest.d.ts
121
+ declare const HTTPRequest_base: ObjectConstructor | {
122
+ new (input: RequestInfo | URL, init?: RequestInit): Request;
123
+ prototype: Request;
124
+ };
125
+ declare class HTTPRequest extends HTTPRequest_base {}
126
+ //#endregion
127
+ //#region src/model/HTTPResponse.d.ts
128
+ declare const HTTPResponse_base: {
129
+ new (body?: BodyInit | null, init?: ResponseInit): Response;
130
+ prototype: Response;
131
+ error(): Response;
132
+ json(data: any, init?: ResponseInit): Response;
133
+ redirect(url: string | URL, status?: number): Response;
134
+ } | ObjectConstructor;
135
+ declare class HTTPResponse extends HTTPResponse_base {}
136
+ //#endregion
137
+ //#region src/impl/http/HTTPControllerMetaBuilder.d.ts
138
+ declare class HTTPControllerMetaBuilder {
139
+ private readonly clazz;
140
+ constructor(clazz: EggProtoImplClass);
141
+ private buildMethod;
142
+ build(): HTTPControllerMeta;
143
+ static create(clazz: EggProtoImplClass): HTTPControllerMetaBuilder;
144
+ }
145
+ //#endregion
146
+ //#region src/impl/http/HTTPControllerMethodMetaBuilder.d.ts
147
+ declare class HTTPControllerMethodMetaBuilder {
148
+ private readonly clazz;
149
+ private readonly methodName;
150
+ constructor(clazz: EggProtoImplClass, methodName: string);
151
+ private checkParamDecorators;
152
+ private buildParamType;
153
+ getPriority(): number;
154
+ build(): HTTPMethodMeta | undefined;
155
+ }
156
+ //#endregion
157
+ //#region src/util/validator/ControllerValidator.d.ts
158
+ declare class ControllerValidator {
159
+ static validate(clazz: EggProtoImplClass): void;
160
+ }
161
+ //#endregion
162
+ //#region src/util/validator/MethodValidator.d.ts
163
+ declare class MethodValidator {
164
+ static validate(clazz: EggProtoImplClass, methodName: string): void;
165
+ }
166
+ //#endregion
167
+ //#region src/util/ControllerInfoUtil.d.ts
168
+ declare class ControllerInfoUtil {
169
+ static addControllerMiddleware(middleware: MiddlewareFunc, clazz: EggProtoImplClass): void;
170
+ static addControllerAopMiddleware(middleware: EggProtoImplClass<IAdvice>, clazz: EggProtoImplClass): void;
171
+ static getControllerMiddlewares(clazz: EggProtoImplClass): MiddlewareFunc[];
172
+ static getControllerAopMiddlewares(clazz: EggProtoImplClass): EggProtoImplClass<IAdvice>[];
173
+ static setControllerType(clazz: EggProtoImplClass, controllerType: ControllerTypeLike): void;
174
+ static setControllerName(clazz: EggProtoImplClass, controllerName: string): void;
175
+ static getControllerName(clazz: EggProtoImplClass): string | undefined;
176
+ static getControllerType(clazz: EggProtoImplClass): ControllerTypeLike | undefined;
177
+ static setControllerAcl(code: string | undefined, clazz: EggProtoImplClass): void;
178
+ static hasControllerAcl(clazz: EggProtoImplClass): boolean;
179
+ static getControllerAcl(clazz: EggProtoImplClass): string | undefined;
180
+ static addControllerHosts(hosts: string[], clazz: EggProtoImplClass): void;
181
+ static getControllerHosts(clazz: EggProtoImplClass): string[] | undefined;
182
+ }
183
+ //#endregion
184
+ //#region src/util/ControllerMetadataUtil.d.ts
185
+ declare class ControllerMetadataUtil {
186
+ static setControllerMetadata(clazz: EggProtoImplClass, metaData: ControllerMetadata): void;
187
+ static getControllerMetadata(clazz: EggProtoImplClass): ControllerMetadata | undefined;
188
+ }
189
+ //#endregion
190
+ //#region src/util/HTTPInfoUtil.d.ts
191
+ declare class HTTPInfoUtil {
192
+ static setHTTPPath(path: string, clazz: EggProtoImplClass): void;
193
+ static getHTTPPath(clazz: EggProtoImplClass): string | undefined;
194
+ static setHTTPMethodPath(path: string, clazz: EggProtoImplClass, methodName: string): void;
195
+ static getHTTPMethodPath(clazz: EggProtoImplClass, methodName: string): string | undefined;
196
+ static setHTTPMethodMethod(method: HTTPMethodEnum, clazz: EggProtoImplClass, methodName: string): void;
197
+ static getHTTPMethodMethod(clazz: EggProtoImplClass, methodName: string): HTTPMethodEnum | undefined;
198
+ static setHTTPMethodParamType(paramType: HTTPParamType, parameterIndex: number, clazz: EggProtoImplClass, methodName: string): void;
199
+ static getParamIndexList(clazz: EggProtoImplClass, methodName: string): number[];
200
+ static getHTTPMethodParamType(parameterIndex: number, clazz: EggProtoImplClass, methodName: string): HTTPParamType | undefined;
201
+ static setHTTPMethodParamName(paramName: string, parameterIndex: number, clazz: EggProtoImplClass, methodName: string): void;
202
+ static getHTTPMethodParamName(parameterIndex: number, clazz: EggProtoImplClass, methodName: string): string | undefined;
203
+ static getHTTPMethodPriority(clazz: EggProtoImplClass, methodName: string): number | undefined;
204
+ static setHTTPMethodPriority(priority: number, clazz: EggProtoImplClass, methodName: string): void;
205
+ }
206
+ //#endregion
207
+ //#region src/util/HTTPPriorityUtil.d.ts
208
+ declare class HTTPPriorityUtil {
209
+ static readonly DEFAULT_PRIORITY = 100000;
210
+ private static readonly TOKEN_PRIORITY;
211
+ /**
212
+ * | Path | RegExp index | priority |
213
+ * | --- | --- | --- |
214
+ * | /* | [0] | 0 |
215
+ * | /hello/:name | [1] | 1000 |
216
+ * | /hello/world/message/:message | [3] | 3000 |
217
+ * | /hello/:name/message/:message | [1, 3] | 4000 |
218
+ * | /hello/world | [] | 100000/Infinity? |
219
+ *
220
+ * priority = hasRegExp
221
+ * : regexpIndex.reduce((p,c) => p + c * 1000, 0)
222
+ * : 100000;
223
+ * @param {string} path -
224
+ */
225
+ static calcPathPriority(path: string): number;
226
+ }
227
+ //#endregion
228
+ //#region src/util/MethodInfoUtil.d.ts
229
+ declare class MethodInfoUtil {
230
+ static setMethodControllerType(clazz: EggProtoImplClass, methodName: string, controllerType: ControllerTypeLike): void;
231
+ static getMethodControllerType(clazz: EggProtoImplClass, methodName: string): ControllerTypeLike | undefined;
232
+ static setMethodContextIndexInArgs(index: number, clazz: EggProtoImplClass, methodName: string): void;
233
+ static getMethodContextIndex(clazz: EggProtoImplClass, methodName: string): number | undefined;
234
+ static addMethodMiddleware(middleware: MiddlewareFunc, clazz: EggProtoImplClass, methodName: string): void;
235
+ static getMethodMiddlewares(clazz: EggProtoImplClass, methodName: string): MiddlewareFunc[];
236
+ static addMethodAopMiddleware(middleware: EggProtoImplClass<IAdvice>, clazz: EggProtoImplClass, methodName: string): void;
237
+ static getMethodAopMiddlewares(clazz: EggProtoImplClass, methodName: string): EggProtoImplClass<IAdvice>[];
238
+ static setMethodAcl(code: string | undefined, clazz: EggProtoImplClass, methodName: string): void;
239
+ static hasMethodAcl(clazz: EggProtoImplClass, methodName: string): boolean;
240
+ static getMethodAcl(clazz: EggProtoImplClass, methodName: string): string | undefined;
241
+ static setMethodHosts(hosts: string[], clazz: EggProtoImplClass, methodName: string): void;
242
+ static getMethodHosts(clazz: EggProtoImplClass, methodName: string): string[] | undefined;
243
+ static getMethods(clazz: EggProtoImplClass): string[];
244
+ static shouldRegisterAopMiddlewarePointCut(clazz: EggProtoImplClass, methodName: string): boolean;
245
+ static registerAopMiddlewarePointcut(clazz: EggProtoImplClass, methodName: string): void;
246
+ }
247
+ //#endregion
248
+ 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$1 as Request, RequestParamMeta };