@eggjs/controller-decorator 4.0.0-beta.9 → 4.0.1-beta.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/README.md +1 -1
- package/dist/builder/ControllerMetaBuilderFactory.d.ts +10 -6
- package/dist/builder/ControllerMetaBuilderFactory.js +37 -41
- package/dist/builder/index.d.ts +1 -1
- package/dist/builder/index.js +3 -2
- package/dist/decorator/Acl.d.ts +4 -1
- package/dist/decorator/Acl.js +23 -21
- package/dist/decorator/Context.d.ts +4 -1
- package/dist/decorator/Context.js +15 -10
- package/dist/decorator/Middleware.d.ts +6 -2
- package/dist/decorator/Middleware.js +51 -64
- package/dist/decorator/http/HTTPController.d.ts +6 -2
- package/dist/decorator/http/HTTPController.js +23 -28
- package/dist/decorator/http/HTTPMethod.d.ts +6 -2
- package/dist/decorator/http/HTTPMethod.js +21 -16
- package/dist/decorator/http/HTTPParam.d.ts +159 -8
- package/dist/decorator/http/HTTPParam.js +216 -68
- package/dist/decorator/http/Host.d.ts +6 -2
- package/dist/decorator/http/Host.js +26 -24
- package/dist/decorator/http/index.d.ts +5 -4
- package/dist/decorator/http/index.js +7 -5
- package/dist/decorator/index.d.ts +14 -4
- package/dist/decorator/index.js +16 -5
- package/dist/decorator/mcp/Extra.d.ts +4 -0
- package/dist/decorator/mcp/Extra.js +13 -0
- package/dist/decorator/mcp/MCPController.d.ts +6 -0
- package/dist/decorator/mcp/MCPController.js +24 -0
- package/dist/decorator/mcp/MCPPrompt.d.ts +8 -0
- package/dist/decorator/mcp/MCPPrompt.js +31 -0
- package/dist/decorator/mcp/MCPResource.d.ts +6 -0
- package/dist/decorator/mcp/MCPResource.js +21 -0
- package/dist/decorator/mcp/MCPTool.d.ts +8 -0
- package/dist/decorator/mcp/MCPTool.js +31 -0
- package/dist/decorator/mcp/index.d.ts +5 -0
- package/dist/decorator/mcp/index.js +7 -0
- package/dist/impl/http/HTTPControllerMetaBuilder.d.ts +13 -8
- package/dist/impl/http/HTTPControllerMetaBuilder.js +58 -55
- package/dist/impl/http/HTTPControllerMethodMetaBuilder.d.ts +15 -10
- package/dist/impl/http/HTTPControllerMethodMetaBuilder.js +81 -100
- package/dist/impl/http/index.d.ts +2 -2
- package/dist/impl/http/index.js +4 -3
- package/dist/impl/index.d.ts +8 -1
- package/dist/impl/index.js +10 -2
- package/dist/impl/mcp/MCPControllerMetaBuilder.d.ts +15 -0
- package/dist/impl/mcp/MCPControllerMetaBuilder.js +67 -0
- package/dist/impl/mcp/MCPControllerPromptMetaBuilder.d.ts +13 -0
- package/dist/impl/mcp/MCPControllerPromptMetaBuilder.js +37 -0
- package/dist/impl/mcp/MCPControllerResourceMetaBuilder.d.ts +13 -0
- package/dist/impl/mcp/MCPControllerResourceMetaBuilder.js +35 -0
- package/dist/impl/mcp/MCPControllerToolMetaBuilder.d.ts +13 -0
- package/dist/impl/mcp/MCPControllerToolMetaBuilder.js +37 -0
- package/dist/impl/mcp/index.d.ts +4 -0
- package/dist/impl/mcp/index.js +6 -0
- package/dist/index.d.ts +42 -6
- package/dist/index.js +44 -7
- package/dist/model/HTTPControllerMeta.d.ts +26 -21
- package/dist/model/HTTPControllerMeta.js +58 -60
- package/dist/model/HTTPCookies.d.ts +2 -3
- package/dist/model/HTTPCookies.js +3 -4
- package/dist/model/HTTPMethodMeta.d.ts +60 -56
- package/dist/model/HTTPMethodMeta.js +104 -124
- package/dist/model/HTTPResponse.d.ts +6 -9
- package/dist/model/HTTPResponse.js +6 -3
- package/dist/model/MCPControllerMeta.d.ts +29 -0
- package/dist/model/MCPControllerMeta.js +51 -0
- package/dist/model/MCPPromptMeta.d.ts +28 -0
- package/dist/model/MCPPromptMeta.js +26 -0
- package/dist/model/MCPResourceMeta.d.ts +28 -0
- package/dist/model/MCPResourceMeta.js +28 -0
- package/dist/model/MCPToolMeta.d.ts +26 -0
- package/dist/model/MCPToolMeta.js +24 -0
- package/dist/model/index.d.ts +8 -5
- package/dist/model/index.js +10 -6
- package/dist/util/ControllerInfoUtil.d.ts +21 -16
- package/dist/util/ControllerInfoUtil.js +54 -46
- package/dist/util/ControllerMetadataUtil.d.ts +8 -4
- package/dist/util/ControllerMetadataUtil.js +21 -20
- package/dist/util/HTTPInfoUtil.d.ts +19 -15
- package/dist/util/HTTPInfoUtil.js +53 -64
- package/dist/util/HTTPPriorityUtil.d.ts +22 -18
- package/dist/util/HTTPPriorityUtil.js +39 -42
- package/dist/util/MCPInfoUtil.d.ts +52 -0
- package/dist/util/MCPInfoUtil.js +87 -0
- package/dist/util/MethodInfoUtil.d.ts +24 -19
- package/dist/util/MethodInfoUtil.js +68 -72
- package/dist/util/index.d.ts +9 -6
- package/dist/util/index.js +11 -7
- package/dist/util/validator/ControllerValidator.d.ts +7 -3
- package/dist/util/validator/ControllerValidator.js +15 -14
- package/dist/util/validator/MethodValidator.d.ts +7 -3
- package/dist/util/validator/MethodValidator.js +30 -30
- package/dist/util/validator/index.d.ts +2 -2
- package/dist/util/validator/index.js +4 -3
- package/package.json +36 -39
- package/dist/model/HTTPRequest.d.ts +0 -7
- package/dist/model/HTTPRequest.js +0 -3
|
@@ -1,8 +1,159 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import { InjectContext } from "../Context.js";
|
|
2
|
+
import { HTTPParamParams, HTTPQueriesParams, HTTPQueryParams } from "@eggjs/tegg-types";
|
|
3
|
+
|
|
4
|
+
//#region src/decorator/http/HTTPParam.d.ts
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Inject the request body.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* import { HTTPController, HTTPMethod, HTTPMethodEnum, HTTPBody } from 'egg';
|
|
12
|
+
*
|
|
13
|
+
* @HTTPController()
|
|
14
|
+
* export class FooController {
|
|
15
|
+
* @HTTPMethod({
|
|
16
|
+
* path: '/foo',
|
|
17
|
+
* method: HTTPMethodEnum.GET,
|
|
18
|
+
* })
|
|
19
|
+
* // POST /foo -H 'Content-Type: application/json' -d '{"foo": "bar"}'
|
|
20
|
+
* // body = { "foo": "bar" }
|
|
21
|
+
* async bar(@HTTPBody() body: any): Promise<void> {
|
|
22
|
+
* console.log(body);
|
|
23
|
+
* }
|
|
24
|
+
* }
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
declare function HTTPBody(): (target: any, propertyKey: PropertyKey, parameterIndex: number) => void;
|
|
28
|
+
/**
|
|
29
|
+
* Inject the request headers.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```typescript
|
|
33
|
+
* import { HTTPController, HTTPMethod, HTTPMethodEnum, HTTPHeaders, type IncomingHttpHeaders } from 'egg';
|
|
34
|
+
*
|
|
35
|
+
* @HTTPController()
|
|
36
|
+
* export class FooController {
|
|
37
|
+
* @HTTPMethod({
|
|
38
|
+
* path: '/foo',
|
|
39
|
+
* method: HTTPMethodEnum.GET,
|
|
40
|
+
* })
|
|
41
|
+
* // GET /foo -H 'X-Custom: custom'
|
|
42
|
+
* // headers['x-custom'] = 'custom'
|
|
43
|
+
* async bar(@HTTPHeaders() headers: IncomingHttpHeaders): Promise<void> {
|
|
44
|
+
* console.log(headers);
|
|
45
|
+
* }
|
|
46
|
+
* }
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
declare function HTTPHeaders(): (target: any, propertyKey: PropertyKey, parameterIndex: number) => void;
|
|
50
|
+
/**
|
|
51
|
+
* Inject the request query string, the value is string type.
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```typescript
|
|
55
|
+
* import { HTTPController, HTTPMethod, HTTPMethodEnum, HTTPQuery } from 'egg';
|
|
56
|
+
*
|
|
57
|
+
* @HTTPController()
|
|
58
|
+
* export class FooController {
|
|
59
|
+
* @HTTPMethod({
|
|
60
|
+
* path: '/foo',
|
|
61
|
+
* method: HTTPMethodEnum.GET,
|
|
62
|
+
* })
|
|
63
|
+
* // GET /foo?user=asd
|
|
64
|
+
* // user = 'asd'
|
|
65
|
+
* async bar(@HTTPQuery() user?: string): Promise<void> {
|
|
66
|
+
* console.log(user);
|
|
67
|
+
* }
|
|
68
|
+
* }
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
declare function HTTPQuery(param?: HTTPQueryParams): (target: any, propertyKey: PropertyKey, parameterIndex: number) => void;
|
|
72
|
+
/**
|
|
73
|
+
* Inject the request query strings, all value are Array type.
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* ```typescript
|
|
77
|
+
* import { HTTPController, HTTPMethod, HTTPMethodEnum, HTTPQueries } from 'egg';
|
|
78
|
+
*
|
|
79
|
+
* @HTTPController()
|
|
80
|
+
* export class FooController {
|
|
81
|
+
* @HTTPMethod({
|
|
82
|
+
* path: '/foo',
|
|
83
|
+
* method: HTTPMethodEnum.GET,
|
|
84
|
+
* })
|
|
85
|
+
* // GET /foo?user=asd&user=fgh
|
|
86
|
+
* // user = ['asd', 'fgh']
|
|
87
|
+
* async bar(@HTTPQueries({ name: 'user' }) users?: string[]): Promise<void> {
|
|
88
|
+
* console.log(users);
|
|
89
|
+
* }
|
|
90
|
+
* }
|
|
91
|
+
* ```
|
|
92
|
+
*/
|
|
93
|
+
declare function HTTPQueries(param?: HTTPQueriesParams): (target: any, propertyKey: PropertyKey, parameterIndex: number) => void;
|
|
94
|
+
/**
|
|
95
|
+
* Inject the request path parameter, the value is string type.
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* ```typescript
|
|
99
|
+
* import { HTTPController, HTTPMethod, HTTPMethodEnum, HTTPParam } from 'egg';
|
|
100
|
+
*
|
|
101
|
+
* @HTTPController()
|
|
102
|
+
* export class FooController {
|
|
103
|
+
* @HTTPMethod({
|
|
104
|
+
* path: '/foo/:id',
|
|
105
|
+
* method: HTTPMethodEnum.GET,
|
|
106
|
+
* })
|
|
107
|
+
* // GET /foo/123
|
|
108
|
+
* // id = '123'
|
|
109
|
+
* async bar(@HTTPParam() id: string): Promise<void> {
|
|
110
|
+
* console.log(id);
|
|
111
|
+
* }
|
|
112
|
+
* }
|
|
113
|
+
* ```
|
|
114
|
+
*/
|
|
115
|
+
declare function HTTPParam(param?: HTTPParamParams): (target: any, propertyKey: PropertyKey, parameterIndex: number) => void;
|
|
116
|
+
/**
|
|
117
|
+
* Inject the request object.
|
|
118
|
+
*
|
|
119
|
+
* @example
|
|
120
|
+
* ```typescript
|
|
121
|
+
* import { HTTPController, HTTPMethod, HTTPMethodEnum, HTTPRequest } from 'egg';
|
|
122
|
+
*
|
|
123
|
+
* @HTTPController()
|
|
124
|
+
* export class FooController {
|
|
125
|
+
* @HTTPMethod({
|
|
126
|
+
* path: '/foo',
|
|
127
|
+
* method: HTTPMethodEnum.GET,
|
|
128
|
+
* })
|
|
129
|
+
* async bar(@HTTPRequest() request: Request): Promise<void> {
|
|
130
|
+
* console.log(request);
|
|
131
|
+
* }
|
|
132
|
+
* }
|
|
133
|
+
* ```
|
|
134
|
+
*/
|
|
135
|
+
declare function HTTPRequest(): (target: any, propertyKey: PropertyKey, parameterIndex: number) => void;
|
|
136
|
+
/**
|
|
137
|
+
* Inject the request cookies.
|
|
138
|
+
*
|
|
139
|
+
* @example
|
|
140
|
+
* ```typescript
|
|
141
|
+
* import { HTTPController, HTTPMethod, HTTPMethodEnum, HTTPCookies, type Cookies } from 'egg';
|
|
142
|
+
*
|
|
143
|
+
* @HTTPController()
|
|
144
|
+
* export class FooController {
|
|
145
|
+
* @HTTPMethod({
|
|
146
|
+
* path: '/foo',
|
|
147
|
+
* method: HTTPMethodEnum.GET,
|
|
148
|
+
* })
|
|
149
|
+
* // GET /foo -H 'Cookie: foo=bar; bar=baz'
|
|
150
|
+
* // cookies = cookies
|
|
151
|
+
* async bar(@HTTPCookies() cookies: Cookies): Promise<void> {
|
|
152
|
+
* console.log(cookies);
|
|
153
|
+
* }
|
|
154
|
+
* }
|
|
155
|
+
* ```
|
|
156
|
+
*/
|
|
157
|
+
declare function HTTPCookies(): (target: any, propertyKey: PropertyKey, parameterIndex: number) => void;
|
|
158
|
+
//#endregion
|
|
159
|
+
export { HTTPBody, HTTPCookies, HTTPHeaders, HTTPParam, HTTPQueries, HTTPQuery, HTTPRequest };
|
|
@@ -1,75 +1,223 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
1
|
+
import { HTTPInfoUtil } from "../../util/HTTPInfoUtil.js";
|
|
2
|
+
import "../../util/index.js";
|
|
3
|
+
import { InjectContext } from "../Context.js";
|
|
4
|
+
import { HTTPParamType } from "@eggjs/tegg-types";
|
|
5
|
+
import { ObjectUtils } from "@eggjs/tegg-common-util";
|
|
6
|
+
import assert from "node:assert";
|
|
7
|
+
|
|
8
|
+
//#region src/decorator/http/HTTPParam.ts
|
|
9
|
+
/**
|
|
10
|
+
* Inject the request body.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* import { HTTPController, HTTPMethod, HTTPMethodEnum, HTTPBody } from 'egg';
|
|
15
|
+
*
|
|
16
|
+
* @HTTPController()
|
|
17
|
+
* export class FooController {
|
|
18
|
+
* @HTTPMethod({
|
|
19
|
+
* path: '/foo',
|
|
20
|
+
* method: HTTPMethodEnum.GET,
|
|
21
|
+
* })
|
|
22
|
+
* // POST /foo -H 'Content-Type: application/json' -d '{"foo": "bar"}'
|
|
23
|
+
* // body = { "foo": "bar" }
|
|
24
|
+
* async bar(@HTTPBody() body: any): Promise<void> {
|
|
25
|
+
* console.log(body);
|
|
26
|
+
* }
|
|
27
|
+
* }
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
function HTTPBody() {
|
|
31
|
+
return function(target, propertyKey, parameterIndex) {
|
|
32
|
+
assert.equal(typeof propertyKey, "string", `[controller/${target.name}] expect method name be typeof string, but now is ${String(propertyKey)}`);
|
|
33
|
+
const methodName = propertyKey;
|
|
34
|
+
const controllerClazz = target.constructor;
|
|
35
|
+
HTTPInfoUtil.setHTTPMethodParamType(HTTPParamType.BODY, parameterIndex, controllerClazz, methodName);
|
|
36
|
+
};
|
|
15
37
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
38
|
+
/**
|
|
39
|
+
* Inject the request headers.
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```typescript
|
|
43
|
+
* import { HTTPController, HTTPMethod, HTTPMethodEnum, HTTPHeaders, type IncomingHttpHeaders } from 'egg';
|
|
44
|
+
*
|
|
45
|
+
* @HTTPController()
|
|
46
|
+
* export class FooController {
|
|
47
|
+
* @HTTPMethod({
|
|
48
|
+
* path: '/foo',
|
|
49
|
+
* method: HTTPMethodEnum.GET,
|
|
50
|
+
* })
|
|
51
|
+
* // GET /foo -H 'X-Custom: custom'
|
|
52
|
+
* // headers['x-custom'] = 'custom'
|
|
53
|
+
* async bar(@HTTPHeaders() headers: IncomingHttpHeaders): Promise<void> {
|
|
54
|
+
* console.log(headers);
|
|
55
|
+
* }
|
|
56
|
+
* }
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
function HTTPHeaders() {
|
|
60
|
+
return function(target, propertyKey, parameterIndex) {
|
|
61
|
+
assert.equal(typeof propertyKey, "string", `[controller/${target.name}] expect method name be typeof string, but now is ${String(propertyKey)}`);
|
|
62
|
+
const methodName = propertyKey;
|
|
63
|
+
const controllerClazz = target.constructor;
|
|
64
|
+
HTTPInfoUtil.setHTTPMethodParamType(HTTPParamType.HEADERS, parameterIndex, controllerClazz, methodName);
|
|
65
|
+
};
|
|
23
66
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
67
|
+
/**
|
|
68
|
+
* Inject the request query string, the value is string type.
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* ```typescript
|
|
72
|
+
* import { HTTPController, HTTPMethod, HTTPMethodEnum, HTTPQuery } from 'egg';
|
|
73
|
+
*
|
|
74
|
+
* @HTTPController()
|
|
75
|
+
* export class FooController {
|
|
76
|
+
* @HTTPMethod({
|
|
77
|
+
* path: '/foo',
|
|
78
|
+
* method: HTTPMethodEnum.GET,
|
|
79
|
+
* })
|
|
80
|
+
* // GET /foo?user=asd
|
|
81
|
+
* // user = 'asd'
|
|
82
|
+
* async bar(@HTTPQuery() user?: string): Promise<void> {
|
|
83
|
+
* console.log(user);
|
|
84
|
+
* }
|
|
85
|
+
* }
|
|
86
|
+
* ```
|
|
87
|
+
*/
|
|
88
|
+
function HTTPQuery(param) {
|
|
89
|
+
return function(target, propertyKey, parameterIndex) {
|
|
90
|
+
assert.equal(typeof propertyKey, "string", `[controller/${target.name}] expect method name be typeof string, but now is ${String(propertyKey)}`);
|
|
91
|
+
const methodName = propertyKey;
|
|
92
|
+
const controllerClazz = target.constructor;
|
|
93
|
+
const argNames = ObjectUtils.getFunctionArgNameList(target[propertyKey]);
|
|
94
|
+
const name = param?.name || argNames[parameterIndex];
|
|
95
|
+
HTTPInfoUtil.setHTTPMethodParamType(HTTPParamType.QUERY, parameterIndex, controllerClazz, methodName);
|
|
96
|
+
HTTPInfoUtil.setHTTPMethodParamName(name, parameterIndex, controllerClazz, methodName);
|
|
97
|
+
};
|
|
34
98
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
99
|
+
/**
|
|
100
|
+
* Inject the request query strings, all value are Array type.
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* ```typescript
|
|
104
|
+
* import { HTTPController, HTTPMethod, HTTPMethodEnum, HTTPQueries } from 'egg';
|
|
105
|
+
*
|
|
106
|
+
* @HTTPController()
|
|
107
|
+
* export class FooController {
|
|
108
|
+
* @HTTPMethod({
|
|
109
|
+
* path: '/foo',
|
|
110
|
+
* method: HTTPMethodEnum.GET,
|
|
111
|
+
* })
|
|
112
|
+
* // GET /foo?user=asd&user=fgh
|
|
113
|
+
* // user = ['asd', 'fgh']
|
|
114
|
+
* async bar(@HTTPQueries({ name: 'user' }) users?: string[]): Promise<void> {
|
|
115
|
+
* console.log(users);
|
|
116
|
+
* }
|
|
117
|
+
* }
|
|
118
|
+
* ```
|
|
119
|
+
*/
|
|
120
|
+
function HTTPQueries(param) {
|
|
121
|
+
return function(target, propertyKey, parameterIndex) {
|
|
122
|
+
assert.equal(typeof propertyKey, "string", `[controller/${target.name}] expect method name be typeof string, but now is ${String(propertyKey)}`);
|
|
123
|
+
const methodName = propertyKey;
|
|
124
|
+
const controllerClazz = target.constructor;
|
|
125
|
+
const argNames = ObjectUtils.getFunctionArgNameList(target[propertyKey]);
|
|
126
|
+
const name = param?.name || argNames[parameterIndex];
|
|
127
|
+
HTTPInfoUtil.setHTTPMethodParamType(HTTPParamType.QUERIES, parameterIndex, controllerClazz, methodName);
|
|
128
|
+
HTTPInfoUtil.setHTTPMethodParamName(name, parameterIndex, controllerClazz, methodName);
|
|
129
|
+
};
|
|
45
130
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
131
|
+
/**
|
|
132
|
+
* Inject the request path parameter, the value is string type.
|
|
133
|
+
*
|
|
134
|
+
* @example
|
|
135
|
+
* ```typescript
|
|
136
|
+
* import { HTTPController, HTTPMethod, HTTPMethodEnum, HTTPParam } from 'egg';
|
|
137
|
+
*
|
|
138
|
+
* @HTTPController()
|
|
139
|
+
* export class FooController {
|
|
140
|
+
* @HTTPMethod({
|
|
141
|
+
* path: '/foo/:id',
|
|
142
|
+
* method: HTTPMethodEnum.GET,
|
|
143
|
+
* })
|
|
144
|
+
* // GET /foo/123
|
|
145
|
+
* // id = '123'
|
|
146
|
+
* async bar(@HTTPParam() id: string): Promise<void> {
|
|
147
|
+
* console.log(id);
|
|
148
|
+
* }
|
|
149
|
+
* }
|
|
150
|
+
* ```
|
|
151
|
+
*/
|
|
152
|
+
function HTTPParam(param) {
|
|
153
|
+
return function(target, propertyKey, parameterIndex) {
|
|
154
|
+
assert.equal(typeof propertyKey, "string", `[controller/${target.name}] expect method name be typeof string, but now is ${String(propertyKey)}`);
|
|
155
|
+
const methodName = propertyKey;
|
|
156
|
+
const controllerClazz = target.constructor;
|
|
157
|
+
const argNames = ObjectUtils.getFunctionArgNameList(target[propertyKey]);
|
|
158
|
+
const name = param?.name || argNames[parameterIndex];
|
|
159
|
+
HTTPInfoUtil.setHTTPMethodParamType(HTTPParamType.PARAM, parameterIndex, controllerClazz, methodName);
|
|
160
|
+
HTTPInfoUtil.setHTTPMethodParamName(name, parameterIndex, controllerClazz, methodName);
|
|
161
|
+
};
|
|
56
162
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
163
|
+
/**
|
|
164
|
+
* Inject the request object.
|
|
165
|
+
*
|
|
166
|
+
* @example
|
|
167
|
+
* ```typescript
|
|
168
|
+
* import { HTTPController, HTTPMethod, HTTPMethodEnum, HTTPRequest } from 'egg';
|
|
169
|
+
*
|
|
170
|
+
* @HTTPController()
|
|
171
|
+
* export class FooController {
|
|
172
|
+
* @HTTPMethod({
|
|
173
|
+
* path: '/foo',
|
|
174
|
+
* method: HTTPMethodEnum.GET,
|
|
175
|
+
* })
|
|
176
|
+
* async bar(@HTTPRequest() request: Request): Promise<void> {
|
|
177
|
+
* console.log(request);
|
|
178
|
+
* }
|
|
179
|
+
* }
|
|
180
|
+
* ```
|
|
181
|
+
*/
|
|
182
|
+
function HTTPRequest() {
|
|
183
|
+
return function(target, propertyKey, parameterIndex) {
|
|
184
|
+
const [nodeMajor] = process.versions.node.split(".").map((v) => Number(v));
|
|
185
|
+
assert(nodeMajor >= 16, `[controller/${target.name}] expect node version >=16, but now is ${nodeMajor}`);
|
|
186
|
+
assert.equal(typeof propertyKey, "string", `[controller/${target.name}] expect method name be typeof string, but now is ${String(propertyKey)}`);
|
|
187
|
+
const methodName = propertyKey;
|
|
188
|
+
const controllerClazz = target.constructor;
|
|
189
|
+
HTTPInfoUtil.setHTTPMethodParamType(HTTPParamType.REQUEST, parameterIndex, controllerClazz, methodName);
|
|
190
|
+
};
|
|
66
191
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
192
|
+
/**
|
|
193
|
+
* Inject the request cookies.
|
|
194
|
+
*
|
|
195
|
+
* @example
|
|
196
|
+
* ```typescript
|
|
197
|
+
* import { HTTPController, HTTPMethod, HTTPMethodEnum, HTTPCookies, type Cookies } from 'egg';
|
|
198
|
+
*
|
|
199
|
+
* @HTTPController()
|
|
200
|
+
* export class FooController {
|
|
201
|
+
* @HTTPMethod({
|
|
202
|
+
* path: '/foo',
|
|
203
|
+
* method: HTTPMethodEnum.GET,
|
|
204
|
+
* })
|
|
205
|
+
* // GET /foo -H 'Cookie: foo=bar; bar=baz'
|
|
206
|
+
* // cookies = cookies
|
|
207
|
+
* async bar(@HTTPCookies() cookies: Cookies): Promise<void> {
|
|
208
|
+
* console.log(cookies);
|
|
209
|
+
* }
|
|
210
|
+
* }
|
|
211
|
+
* ```
|
|
212
|
+
*/
|
|
213
|
+
function HTTPCookies() {
|
|
214
|
+
return function(target, propertyKey, parameterIndex) {
|
|
215
|
+
assert.equal(typeof propertyKey, "string", `[controller/${target.name}] expect method name be typeof string, but now is ${String(propertyKey)}`);
|
|
216
|
+
const methodName = propertyKey;
|
|
217
|
+
const controllerClazz = target.constructor;
|
|
218
|
+
HTTPInfoUtil.setHTTPMethodParamType(HTTPParamType.COOKIES, parameterIndex, controllerClazz, methodName);
|
|
219
|
+
};
|
|
74
220
|
}
|
|
75
|
-
|
|
221
|
+
|
|
222
|
+
//#endregion
|
|
223
|
+
export { HTTPBody, HTTPCookies, HTTPHeaders, HTTPParam, HTTPQueries, HTTPQuery, HTTPRequest };
|
|
@@ -1,2 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import { HostType } from "@eggjs/tegg-types";
|
|
2
|
+
|
|
3
|
+
//#region src/decorator/http/Host.d.ts
|
|
4
|
+
declare function Host(host: HostType): (target: any, propertyKey?: PropertyKey) => void;
|
|
5
|
+
//#endregion
|
|
6
|
+
export { Host };
|
|
@@ -1,25 +1,27 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
1
|
+
import { ControllerInfoUtil } from "../../util/ControllerInfoUtil.js";
|
|
2
|
+
import { MethodInfoUtil } from "../../util/MethodInfoUtil.js";
|
|
3
|
+
import "../../util/index.js";
|
|
4
|
+
import assert from "node:assert";
|
|
5
|
+
|
|
6
|
+
//#region src/decorator/http/Host.ts
|
|
7
|
+
function Host(host) {
|
|
8
|
+
function parseHost() {
|
|
9
|
+
return Array.isArray(host) ? host : [host];
|
|
10
|
+
}
|
|
11
|
+
function classHost(constructor) {
|
|
12
|
+
ControllerInfoUtil.addControllerHosts(parseHost(), constructor);
|
|
13
|
+
}
|
|
14
|
+
function methodHost(target, propertyKey) {
|
|
15
|
+
assert(typeof propertyKey === "string", `[controller/${target.name}] expect method name be typeof string, but now is ${String(propertyKey)}`);
|
|
16
|
+
const controllerClazz = target.constructor;
|
|
17
|
+
const methodName = propertyKey;
|
|
18
|
+
MethodInfoUtil.setMethodHosts(parseHost(), controllerClazz, methodName);
|
|
19
|
+
}
|
|
20
|
+
return function(target, propertyKey) {
|
|
21
|
+
if (propertyKey === void 0) classHost(target);
|
|
22
|
+
else methodHost(target, propertyKey);
|
|
23
|
+
};
|
|
24
24
|
}
|
|
25
|
-
|
|
25
|
+
|
|
26
|
+
//#endregion
|
|
27
|
+
export { Host };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { Host } from "./Host.js";
|
|
2
|
+
import { HTTPController } from "./HTTPController.js";
|
|
3
|
+
import { HTTPMethod } from "./HTTPMethod.js";
|
|
4
|
+
import { InjectContext } from "../Context.js";
|
|
5
|
+
import { HTTPBody, HTTPCookies, HTTPHeaders, HTTPParam, HTTPQueries, HTTPQuery, HTTPRequest } from "./HTTPParam.js";
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { Host } from "./Host.js";
|
|
2
|
+
import { HTTPController } from "./HTTPController.js";
|
|
3
|
+
import { HTTPMethod } from "./HTTPMethod.js";
|
|
4
|
+
import { InjectContext } from "../Context.js";
|
|
5
|
+
import { HTTPBody, HTTPCookies, HTTPHeaders, HTTPParam, HTTPQueries, HTTPQuery, HTTPRequest } from "./HTTPParam.js";
|
|
6
|
+
|
|
7
|
+
export { };
|
|
@@ -1,4 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { Host } from "./http/Host.js";
|
|
2
|
+
import { HTTPController } from "./http/HTTPController.js";
|
|
3
|
+
import { HTTPMethod } from "./http/HTTPMethod.js";
|
|
4
|
+
import { InjectContext } from "./Context.js";
|
|
5
|
+
import { HTTPBody, HTTPCookies, HTTPHeaders, HTTPParam, HTTPQueries, HTTPQuery, HTTPRequest } from "./http/HTTPParam.js";
|
|
6
|
+
import "./http/index.js";
|
|
7
|
+
import { Extra } from "./mcp/Extra.js";
|
|
8
|
+
import { MCPController } from "./mcp/MCPController.js";
|
|
9
|
+
import { MCPPrompt, PromptArgsSchema } from "./mcp/MCPPrompt.js";
|
|
10
|
+
import { MCPResource } from "./mcp/MCPResource.js";
|
|
11
|
+
import { MCPTool, ToolArgsSchema } from "./mcp/MCPTool.js";
|
|
12
|
+
import "./mcp/index.js";
|
|
13
|
+
import { Acl } from "./Acl.js";
|
|
14
|
+
import { Middleware } from "./Middleware.js";
|
package/dist/decorator/index.js
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { Host } from "./http/Host.js";
|
|
2
|
+
import { HTTPController } from "./http/HTTPController.js";
|
|
3
|
+
import { HTTPMethod } from "./http/HTTPMethod.js";
|
|
4
|
+
import { InjectContext } from "./Context.js";
|
|
5
|
+
import { HTTPBody, HTTPCookies, HTTPHeaders, HTTPParam, HTTPQueries, HTTPQuery, HTTPRequest } from "./http/HTTPParam.js";
|
|
6
|
+
import "./http/index.js";
|
|
7
|
+
import { Extra } from "./mcp/Extra.js";
|
|
8
|
+
import { MCPController } from "./mcp/MCPController.js";
|
|
9
|
+
import { MCPPrompt, PromptArgsSchema } from "./mcp/MCPPrompt.js";
|
|
10
|
+
import { MCPResource } from "./mcp/MCPResource.js";
|
|
11
|
+
import { MCPTool, ToolArgsSchema } from "./mcp/MCPTool.js";
|
|
12
|
+
import "./mcp/index.js";
|
|
13
|
+
import { Acl } from "./Acl.js";
|
|
14
|
+
import { Middleware } from "./Middleware.js";
|
|
15
|
+
|
|
16
|
+
export { };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { MCPInfoUtil } from "../../util/MCPInfoUtil.js";
|
|
2
|
+
|
|
3
|
+
//#region src/decorator/mcp/Extra.ts
|
|
4
|
+
function Extra() {
|
|
5
|
+
return function(target, propertyKey, parameterIndex) {
|
|
6
|
+
const controllerClazz = target.constructor;
|
|
7
|
+
const methodName = propertyKey;
|
|
8
|
+
MCPInfoUtil.setMCPExtra(parameterIndex, controllerClazz, methodName);
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
//#endregion
|
|
13
|
+
export { Extra };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { EggProtoImplClass, MCPControllerParams } from "@eggjs/tegg-types";
|
|
2
|
+
|
|
3
|
+
//#region src/decorator/mcp/MCPController.d.ts
|
|
4
|
+
declare function MCPController(param?: MCPControllerParams): (constructor: EggProtoImplClass) => void;
|
|
5
|
+
//#endregion
|
|
6
|
+
export { MCPController };
|