@eggjs/controller-decorator 4.0.0-beta.8 → 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 +11 -0
- package/dist/builder/ControllerMetaBuilderFactory.js +37 -0
- package/dist/builder/index.d.ts +1 -0
- package/dist/builder/index.js +3 -0
- package/dist/decorator/Acl.d.ts +4 -0
- package/dist/decorator/Acl.js +24 -0
- package/dist/decorator/Context.d.ts +4 -0
- package/dist/decorator/Context.js +16 -0
- package/dist/decorator/Middleware.d.ts +6 -0
- package/dist/decorator/Middleware.js +56 -0
- package/dist/decorator/http/HTTPController.d.ts +6 -0
- package/dist/decorator/http/HTTPController.js +24 -0
- package/dist/decorator/http/HTTPMethod.d.ts +6 -0
- package/dist/decorator/http/HTTPMethod.js +22 -0
- package/dist/decorator/http/HTTPParam.d.ts +159 -0
- package/dist/decorator/http/HTTPParam.js +223 -0
- package/dist/decorator/http/Host.d.ts +6 -0
- package/dist/decorator/http/Host.js +27 -0
- package/dist/decorator/http/index.d.ts +5 -0
- package/dist/decorator/http/index.js +7 -0
- package/dist/decorator/index.d.ts +14 -0
- package/dist/decorator/index.js +16 -0
- 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 +14 -0
- package/dist/impl/http/HTTPControllerMetaBuilder.js +60 -0
- package/dist/impl/http/HTTPControllerMethodMetaBuilder.d.ts +16 -0
- package/dist/impl/http/HTTPControllerMethodMetaBuilder.js +81 -0
- package/dist/impl/http/index.d.ts +2 -0
- package/dist/impl/http/index.js +4 -0
- package/dist/impl/index.d.ts +8 -0
- package/dist/impl/index.js +10 -0
- 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 +41 -247
- package/dist/index.js +41 -749
- package/dist/model/HTTPControllerMeta.d.ts +27 -0
- package/dist/model/HTTPControllerMeta.js +58 -0
- package/dist/model/HTTPCookies.d.ts +2 -0
- package/dist/model/HTTPCookies.js +3 -0
- package/dist/model/HTTPMethodMeta.d.ts +60 -0
- package/dist/model/HTTPMethodMeta.js +104 -0
- package/dist/model/HTTPResponse.d.ts +7 -0
- package/dist/model/HTTPResponse.js +6 -0
- 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 -0
- package/dist/model/index.js +10 -0
- package/dist/util/ControllerInfoUtil.d.ts +22 -0
- package/dist/util/ControllerInfoUtil.js +54 -0
- package/dist/util/ControllerMetadataUtil.d.ts +9 -0
- package/dist/util/ControllerMetadataUtil.js +21 -0
- package/dist/util/HTTPInfoUtil.d.ts +20 -0
- package/dist/util/HTTPInfoUtil.js +53 -0
- package/dist/util/HTTPPriorityUtil.d.ts +23 -0
- package/dist/util/HTTPPriorityUtil.js +39 -0
- package/dist/util/MCPInfoUtil.d.ts +52 -0
- package/dist/util/MCPInfoUtil.js +87 -0
- package/dist/util/MethodInfoUtil.d.ts +25 -0
- package/dist/util/MethodInfoUtil.js +68 -0
- package/dist/util/index.d.ts +9 -0
- package/dist/util/index.js +11 -0
- package/dist/util/validator/ControllerValidator.d.ts +8 -0
- package/dist/util/validator/ControllerValidator.js +16 -0
- package/dist/util/validator/MethodValidator.d.ts +8 -0
- package/dist/util/validator/MethodValidator.js +31 -0
- package/dist/util/validator/index.d.ts +2 -0
- package/dist/util/validator/index.js +4 -0
- package/package.json +36 -39
|
@@ -0,0 +1,7 @@
|
|
|
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 { };
|
|
@@ -0,0 +1,14 @@
|
|
|
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";
|
|
@@ -0,0 +1,16 @@
|
|
|
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 };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { ControllerInfoUtil } from "../../util/ControllerInfoUtil.js";
|
|
2
|
+
import { MCPInfoUtil } from "../../util/MCPInfoUtil.js";
|
|
3
|
+
import { PrototypeUtil, SingletonProto } from "@eggjs/core-decorator";
|
|
4
|
+
import { AccessLevel, ControllerType } from "@eggjs/tegg-types";
|
|
5
|
+
import { StackUtil } from "@eggjs/tegg-common-util";
|
|
6
|
+
|
|
7
|
+
//#region src/decorator/mcp/MCPController.ts
|
|
8
|
+
function MCPController(param) {
|
|
9
|
+
return function(constructor) {
|
|
10
|
+
SingletonProto({
|
|
11
|
+
accessLevel: AccessLevel.PUBLIC,
|
|
12
|
+
name: param?.protoName
|
|
13
|
+
})(constructor);
|
|
14
|
+
ControllerInfoUtil.setControllerType(constructor, ControllerType.MCP);
|
|
15
|
+
if (param?.controllerName) ControllerInfoUtil.setControllerName(constructor, param?.controllerName);
|
|
16
|
+
PrototypeUtil.setFilePath(constructor, StackUtil.getCalleeFromStack(false, 5));
|
|
17
|
+
if (param?.name) MCPInfoUtil.setMCPName(param.name, constructor);
|
|
18
|
+
if (param?.version) MCPInfoUtil.setMCPVersion(param.version, constructor);
|
|
19
|
+
MCPInfoUtil.setMCPControllerParams(param, constructor);
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
//#endregion
|
|
24
|
+
export { MCPController };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { MCPPromptParams } from "@eggjs/tegg-types";
|
|
2
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
3
|
+
|
|
4
|
+
//#region src/decorator/mcp/MCPPrompt.d.ts
|
|
5
|
+
declare function MCPPrompt(params?: MCPPromptParams): (target: any, propertyKey: PropertyKey) => void;
|
|
6
|
+
declare function PromptArgsSchema(argsSchema: Parameters<McpServer["prompt"]>["2"]): (target: any, propertyKey: PropertyKey, parameterIndex: number) => void;
|
|
7
|
+
//#endregion
|
|
8
|
+
export { MCPPrompt, PromptArgsSchema };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { MethodInfoUtil } from "../../util/MethodInfoUtil.js";
|
|
2
|
+
import { MCPInfoUtil } from "../../util/MCPInfoUtil.js";
|
|
3
|
+
import { ControllerType } from "@eggjs/tegg-types";
|
|
4
|
+
|
|
5
|
+
//#region src/decorator/mcp/MCPPrompt.ts
|
|
6
|
+
function MCPPrompt(params) {
|
|
7
|
+
return function(target, propertyKey) {
|
|
8
|
+
const controllerClazz = target.constructor;
|
|
9
|
+
const methodName = propertyKey;
|
|
10
|
+
MethodInfoUtil.setMethodControllerType(controllerClazz, methodName, ControllerType.MCP);
|
|
11
|
+
MCPInfoUtil.setMCPPromptParams({
|
|
12
|
+
...params,
|
|
13
|
+
mcpName: params?.name,
|
|
14
|
+
name: methodName
|
|
15
|
+
}, controllerClazz, methodName);
|
|
16
|
+
MCPInfoUtil.setMCPPrompt(controllerClazz, methodName);
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
function PromptArgsSchema(argsSchema) {
|
|
20
|
+
return function(target, propertyKey, parameterIndex) {
|
|
21
|
+
const controllerClazz = target.constructor;
|
|
22
|
+
const methodName = propertyKey;
|
|
23
|
+
MCPInfoUtil.setMCPPromptArgsInArgs({
|
|
24
|
+
argsSchema,
|
|
25
|
+
index: parameterIndex
|
|
26
|
+
}, controllerClazz, methodName);
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
//#endregion
|
|
31
|
+
export { MCPPrompt, PromptArgsSchema };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { MethodInfoUtil } from "../../util/MethodInfoUtil.js";
|
|
2
|
+
import { MCPInfoUtil } from "../../util/MCPInfoUtil.js";
|
|
3
|
+
import { ControllerType } from "@eggjs/tegg-types";
|
|
4
|
+
|
|
5
|
+
//#region src/decorator/mcp/MCPResource.ts
|
|
6
|
+
function MCPResource(params) {
|
|
7
|
+
return function(target, propertyKey) {
|
|
8
|
+
const controllerClazz = target.constructor;
|
|
9
|
+
const methodName = propertyKey;
|
|
10
|
+
MethodInfoUtil.setMethodControllerType(controllerClazz, methodName, ControllerType.MCP);
|
|
11
|
+
MCPInfoUtil.setMCPResourceParams({
|
|
12
|
+
...params,
|
|
13
|
+
mcpName: params.name,
|
|
14
|
+
name: methodName
|
|
15
|
+
}, controllerClazz, methodName);
|
|
16
|
+
MCPInfoUtil.setMCPResource(controllerClazz, methodName);
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
//#endregion
|
|
21
|
+
export { MCPResource };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { MCPToolParams } from "@eggjs/tegg-types";
|
|
2
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
3
|
+
|
|
4
|
+
//#region src/decorator/mcp/MCPTool.d.ts
|
|
5
|
+
declare function MCPTool(params?: MCPToolParams): (target: any, propertyKey: PropertyKey) => void;
|
|
6
|
+
declare function ToolArgsSchema(argsSchema: Parameters<McpServer["tool"]>["2"]): (target: any, propertyKey: PropertyKey, parameterIndex: number) => void;
|
|
7
|
+
//#endregion
|
|
8
|
+
export { MCPTool, ToolArgsSchema };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { MethodInfoUtil } from "../../util/MethodInfoUtil.js";
|
|
2
|
+
import { MCPInfoUtil } from "../../util/MCPInfoUtil.js";
|
|
3
|
+
import { ControllerType } from "@eggjs/tegg-types";
|
|
4
|
+
|
|
5
|
+
//#region src/decorator/mcp/MCPTool.ts
|
|
6
|
+
function MCPTool(params) {
|
|
7
|
+
return function(target, propertyKey) {
|
|
8
|
+
const controllerClazz = target.constructor;
|
|
9
|
+
const methodName = propertyKey;
|
|
10
|
+
MethodInfoUtil.setMethodControllerType(controllerClazz, methodName, ControllerType.MCP);
|
|
11
|
+
MCPInfoUtil.setMCPToolParams({
|
|
12
|
+
...params,
|
|
13
|
+
mcpName: params?.name,
|
|
14
|
+
name: methodName
|
|
15
|
+
}, controllerClazz, methodName);
|
|
16
|
+
MCPInfoUtil.setMCPTool(controllerClazz, methodName);
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
function ToolArgsSchema(argsSchema) {
|
|
20
|
+
return function(target, propertyKey, parameterIndex) {
|
|
21
|
+
const controllerClazz = target.constructor;
|
|
22
|
+
const methodName = propertyKey;
|
|
23
|
+
MCPInfoUtil.setMCPToolArgsInArgs({
|
|
24
|
+
argsSchema,
|
|
25
|
+
index: parameterIndex
|
|
26
|
+
}, controllerClazz, methodName);
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
//#endregion
|
|
31
|
+
export { MCPTool, ToolArgsSchema };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Extra } from "./Extra.js";
|
|
2
|
+
import { MCPController } from "./MCPController.js";
|
|
3
|
+
import { MCPPrompt, PromptArgsSchema } from "./MCPPrompt.js";
|
|
4
|
+
import { MCPResource } from "./MCPResource.js";
|
|
5
|
+
import { MCPTool, ToolArgsSchema } from "./MCPTool.js";
|
|
6
|
+
|
|
7
|
+
export { };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { HTTPControllerMeta } from "../../model/HTTPControllerMeta.js";
|
|
2
|
+
import "../../model/index.js";
|
|
3
|
+
import { EggProtoImplClass } from "@eggjs/tegg-types";
|
|
4
|
+
|
|
5
|
+
//#region src/impl/http/HTTPControllerMetaBuilder.d.ts
|
|
6
|
+
declare class HTTPControllerMetaBuilder {
|
|
7
|
+
private readonly clazz;
|
|
8
|
+
constructor(clazz: EggProtoImplClass);
|
|
9
|
+
private buildMethod;
|
|
10
|
+
build(): HTTPControllerMeta;
|
|
11
|
+
static create(clazz: EggProtoImplClass): HTTPControllerMetaBuilder;
|
|
12
|
+
}
|
|
13
|
+
//#endregion
|
|
14
|
+
export { HTTPControllerMetaBuilder };
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { ControllerInfoUtil } from "../../util/ControllerInfoUtil.js";
|
|
2
|
+
import { ControllerValidator } from "../../util/validator/ControllerValidator.js";
|
|
3
|
+
import { ControllerMetadataUtil } from "../../util/ControllerMetadataUtil.js";
|
|
4
|
+
import { HTTPInfoUtil } from "../../util/HTTPInfoUtil.js";
|
|
5
|
+
import "../../util/index.js";
|
|
6
|
+
import { ControllerMetaBuilderFactory } from "../../builder/ControllerMetaBuilderFactory.js";
|
|
7
|
+
import "../../builder/index.js";
|
|
8
|
+
import { HTTPControllerMeta } from "../../model/HTTPControllerMeta.js";
|
|
9
|
+
import "../../model/index.js";
|
|
10
|
+
import { HTTPControllerMethodMetaBuilder } from "./HTTPControllerMethodMetaBuilder.js";
|
|
11
|
+
import { ClassUtil } from "@eggjs/metadata";
|
|
12
|
+
import { PrototypeUtil } from "@eggjs/core-decorator";
|
|
13
|
+
import { ControllerType } from "@eggjs/tegg-types";
|
|
14
|
+
import { ObjectUtils } from "@eggjs/tegg-common-util";
|
|
15
|
+
import assert from "node:assert";
|
|
16
|
+
|
|
17
|
+
//#region src/impl/http/HTTPControllerMetaBuilder.ts
|
|
18
|
+
var HTTPControllerMetaBuilder = class HTTPControllerMetaBuilder {
|
|
19
|
+
clazz;
|
|
20
|
+
constructor(clazz) {
|
|
21
|
+
this.clazz = clazz;
|
|
22
|
+
}
|
|
23
|
+
buildMethod() {
|
|
24
|
+
const methodNames = ObjectUtils.getProperties(this.clazz.prototype);
|
|
25
|
+
const methods = [];
|
|
26
|
+
for (const methodName of methodNames) {
|
|
27
|
+
const methodMeta = new HTTPControllerMethodMetaBuilder(this.clazz, methodName).build();
|
|
28
|
+
if (methodMeta) methods.push(methodMeta);
|
|
29
|
+
}
|
|
30
|
+
return methods;
|
|
31
|
+
}
|
|
32
|
+
build() {
|
|
33
|
+
ControllerValidator.validate(this.clazz);
|
|
34
|
+
const controllerType = ControllerInfoUtil.getControllerType(this.clazz);
|
|
35
|
+
assert.equal(controllerType, ControllerType.HTTP, "invalidate controller type");
|
|
36
|
+
const httpPath = HTTPInfoUtil.getHTTPPath(this.clazz);
|
|
37
|
+
const httpMiddlewares = ControllerInfoUtil.getControllerMiddlewares(this.clazz);
|
|
38
|
+
const methods = this.buildMethod();
|
|
39
|
+
const clazzName = this.clazz.name;
|
|
40
|
+
const controllerName = ControllerInfoUtil.getControllerName(this.clazz) || clazzName;
|
|
41
|
+
const protoName = PrototypeUtil.getProperty(this.clazz).name;
|
|
42
|
+
const metadata = new HTTPControllerMeta(clazzName, protoName, controllerName, httpPath, httpMiddlewares, methods, ControllerInfoUtil.hasControllerAcl(this.clazz), ControllerInfoUtil.getControllerAcl(this.clazz), ControllerInfoUtil.getControllerHosts(this.clazz), ControllerInfoUtil.getControllerTimeout(this.clazz));
|
|
43
|
+
ControllerMetadataUtil.setControllerMetadata(this.clazz, metadata);
|
|
44
|
+
for (const method of metadata.methods) {
|
|
45
|
+
const realPath = metadata.getMethodRealPath(method);
|
|
46
|
+
if (!realPath.startsWith("/")) {
|
|
47
|
+
const desc = ClassUtil.classDescription(this.clazz);
|
|
48
|
+
throw new Error(`class ${desc} method ${method.name} path ${realPath} not start with /`);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return metadata;
|
|
52
|
+
}
|
|
53
|
+
static create(clazz) {
|
|
54
|
+
return new HTTPControllerMetaBuilder(clazz);
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
ControllerMetaBuilderFactory.registerControllerMetaBuilder(ControllerType.HTTP, HTTPControllerMetaBuilder.create);
|
|
58
|
+
|
|
59
|
+
//#endregion
|
|
60
|
+
export { HTTPControllerMetaBuilder };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { HTTPMethodMeta } from "../../model/HTTPMethodMeta.js";
|
|
2
|
+
import "../../model/index.js";
|
|
3
|
+
import { EggProtoImplClass } from "@eggjs/tegg-types";
|
|
4
|
+
|
|
5
|
+
//#region src/impl/http/HTTPControllerMethodMetaBuilder.d.ts
|
|
6
|
+
declare class HTTPControllerMethodMetaBuilder {
|
|
7
|
+
private readonly clazz;
|
|
8
|
+
private readonly methodName;
|
|
9
|
+
constructor(clazz: EggProtoImplClass, methodName: string);
|
|
10
|
+
private checkParamDecorators;
|
|
11
|
+
private buildParamType;
|
|
12
|
+
getPriority(): number;
|
|
13
|
+
build(): HTTPMethodMeta | undefined;
|
|
14
|
+
}
|
|
15
|
+
//#endregion
|
|
16
|
+
export { HTTPControllerMethodMetaBuilder };
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { MethodInfoUtil } from "../../util/MethodInfoUtil.js";
|
|
2
|
+
import { MethodValidator } from "../../util/validator/MethodValidator.js";
|
|
3
|
+
import { HTTPInfoUtil } from "../../util/HTTPInfoUtil.js";
|
|
4
|
+
import { HTTPPriorityUtil } from "../../util/HTTPPriorityUtil.js";
|
|
5
|
+
import "../../util/index.js";
|
|
6
|
+
import { HTTPMethodMeta, ParamMetaUtil } from "../../model/HTTPMethodMeta.js";
|
|
7
|
+
import "../../model/index.js";
|
|
8
|
+
import { ClassUtil } from "@eggjs/metadata";
|
|
9
|
+
import path from "node:path";
|
|
10
|
+
|
|
11
|
+
//#region src/impl/http/HTTPControllerMethodMetaBuilder.ts
|
|
12
|
+
var HTTPControllerMethodMetaBuilder = class {
|
|
13
|
+
clazz;
|
|
14
|
+
methodName;
|
|
15
|
+
constructor(clazz, methodName) {
|
|
16
|
+
this.clazz = clazz;
|
|
17
|
+
this.methodName = methodName;
|
|
18
|
+
}
|
|
19
|
+
checkParamDecorators() {
|
|
20
|
+
const functionLength = this.clazz.prototype[this.methodName].length;
|
|
21
|
+
const paramIndexList = HTTPInfoUtil.getParamIndexList(this.clazz, this.methodName);
|
|
22
|
+
const contextIndex = MethodInfoUtil.getMethodContextIndex(this.clazz, this.methodName);
|
|
23
|
+
const hasAnnotationParamCount = typeof contextIndex === "undefined" ? paramIndexList.length : paramIndexList.length + 1;
|
|
24
|
+
const maxParamCount = Math.max(functionLength, hasAnnotationParamCount);
|
|
25
|
+
for (let i = 0; i < maxParamCount; ++i) {
|
|
26
|
+
if (i === contextIndex) continue;
|
|
27
|
+
if (!HTTPInfoUtil.getHTTPMethodParamType(i, this.clazz, this.methodName)) {
|
|
28
|
+
const classDesc = ClassUtil.classDescription(this.clazz);
|
|
29
|
+
throw new Error(`${classDesc}:${this.methodName} param ${i} has no http param type, Please add @HTTPBody, @HTTPParam, @HTTPQuery, @HTTPQueries`);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
buildParamType(httpPath) {
|
|
34
|
+
this.checkParamDecorators();
|
|
35
|
+
const paramTypeMap = /* @__PURE__ */ new Map();
|
|
36
|
+
const paramIndexList = HTTPInfoUtil.getParamIndexList(this.clazz, this.methodName);
|
|
37
|
+
for (const paramIndex of paramIndexList) {
|
|
38
|
+
const paramType = HTTPInfoUtil.getHTTPMethodParamType(paramIndex, this.clazz, this.methodName);
|
|
39
|
+
const paramName = HTTPInfoUtil.getHTTPMethodParamName(paramIndex, this.clazz, this.methodName);
|
|
40
|
+
const paramMeta = ParamMetaUtil.createParam(paramType, paramName);
|
|
41
|
+
try {
|
|
42
|
+
paramMeta.validate(httpPath);
|
|
43
|
+
} catch (e) {
|
|
44
|
+
e.message = `build controller ${ClassUtil.classDescription(this.clazz)} method ${this.methodName} param ${paramName} failed: ${e.message}`;
|
|
45
|
+
throw e;
|
|
46
|
+
}
|
|
47
|
+
paramTypeMap.set(paramIndex, paramMeta);
|
|
48
|
+
}
|
|
49
|
+
return paramTypeMap;
|
|
50
|
+
}
|
|
51
|
+
getPriority() {
|
|
52
|
+
const priority = HTTPInfoUtil.getHTTPMethodPriority(this.clazz, this.methodName);
|
|
53
|
+
if (priority !== void 0) return priority;
|
|
54
|
+
const controllerPath = HTTPInfoUtil.getHTTPPath(this.clazz);
|
|
55
|
+
const methodPath = HTTPInfoUtil.getHTTPMethodPath(this.clazz, this.methodName);
|
|
56
|
+
const realPath = controllerPath ? path.posix.join(controllerPath, methodPath) : methodPath;
|
|
57
|
+
const defaultPriority = HTTPPriorityUtil.calcPathPriority(realPath);
|
|
58
|
+
if (defaultPriority > HTTPPriorityUtil.DEFAULT_PRIORITY) throw new Error(`path ${realPath} is too long, should set priority manually`);
|
|
59
|
+
return defaultPriority;
|
|
60
|
+
}
|
|
61
|
+
build() {
|
|
62
|
+
MethodValidator.validate(this.clazz, this.methodName);
|
|
63
|
+
if (!MethodInfoUtil.getMethodControllerType(this.clazz, this.methodName)) return;
|
|
64
|
+
const httpMethod = HTTPInfoUtil.getHTTPMethodMethod(this.clazz, this.methodName);
|
|
65
|
+
const parentPath = HTTPInfoUtil.getHTTPPath(this.clazz);
|
|
66
|
+
const httpPath = HTTPInfoUtil.getHTTPMethodPath(this.clazz, this.methodName);
|
|
67
|
+
const contextIndex = MethodInfoUtil.getMethodContextIndex(this.clazz, this.methodName);
|
|
68
|
+
const middlewares = MethodInfoUtil.getMethodMiddlewares(this.clazz, this.methodName);
|
|
69
|
+
const needAcl = MethodInfoUtil.hasMethodAcl(this.clazz, this.methodName);
|
|
70
|
+
const aclCode = MethodInfoUtil.getMethodAcl(this.clazz, this.methodName);
|
|
71
|
+
const hosts = MethodInfoUtil.getMethodHosts(this.clazz, this.methodName);
|
|
72
|
+
const timeout = MethodInfoUtil.getMethodTimeout(this.clazz, this.methodName);
|
|
73
|
+
const realPath = parentPath ? path.posix.join(parentPath, httpPath) : httpPath;
|
|
74
|
+
const paramTypeMap = this.buildParamType(realPath);
|
|
75
|
+
const priority = this.getPriority();
|
|
76
|
+
return new HTTPMethodMeta(this.methodName, httpPath, httpMethod, middlewares, contextIndex, paramTypeMap, priority, needAcl, aclCode, hosts, timeout);
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
//#endregion
|
|
81
|
+
export { HTTPControllerMethodMetaBuilder };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { HTTPControllerMetaBuilder } from "./http/HTTPControllerMetaBuilder.js";
|
|
2
|
+
import { HTTPControllerMethodMetaBuilder } from "./http/HTTPControllerMethodMetaBuilder.js";
|
|
3
|
+
import "./http/index.js";
|
|
4
|
+
import { MCPControllerMetaBuilder } from "./mcp/MCPControllerMetaBuilder.js";
|
|
5
|
+
import { MCPControllerPromptMetaBuilder } from "./mcp/MCPControllerPromptMetaBuilder.js";
|
|
6
|
+
import { MCPControllerResourceMetaBuilder } from "./mcp/MCPControllerResourceMetaBuilder.js";
|
|
7
|
+
import { MCPControllerToolMetaBuilder } from "./mcp/MCPControllerToolMetaBuilder.js";
|
|
8
|
+
import "./mcp/index.js";
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { HTTPControllerMethodMetaBuilder } from "./http/HTTPControllerMethodMetaBuilder.js";
|
|
2
|
+
import { HTTPControllerMetaBuilder } from "./http/HTTPControllerMetaBuilder.js";
|
|
3
|
+
import "./http/index.js";
|
|
4
|
+
import { MCPControllerPromptMetaBuilder } from "./mcp/MCPControllerPromptMetaBuilder.js";
|
|
5
|
+
import { MCPControllerResourceMetaBuilder } from "./mcp/MCPControllerResourceMetaBuilder.js";
|
|
6
|
+
import { MCPControllerToolMetaBuilder } from "./mcp/MCPControllerToolMetaBuilder.js";
|
|
7
|
+
import { MCPControllerMetaBuilder } from "./mcp/MCPControllerMetaBuilder.js";
|
|
8
|
+
import "./mcp/index.js";
|
|
9
|
+
|
|
10
|
+
export { };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { MCPControllerMeta } from "../../model/MCPControllerMeta.js";
|
|
2
|
+
import { EggProtoImplClass } from "@eggjs/tegg-types";
|
|
3
|
+
|
|
4
|
+
//#region src/impl/mcp/MCPControllerMetaBuilder.d.ts
|
|
5
|
+
declare class MCPControllerMetaBuilder {
|
|
6
|
+
private readonly clazz;
|
|
7
|
+
constructor(clazz: EggProtoImplClass);
|
|
8
|
+
private buildResource;
|
|
9
|
+
private buildPrompt;
|
|
10
|
+
private buildTool;
|
|
11
|
+
build(): MCPControllerMeta;
|
|
12
|
+
static create(clazz: EggProtoImplClass): MCPControllerMetaBuilder;
|
|
13
|
+
}
|
|
14
|
+
//#endregion
|
|
15
|
+
export { MCPControllerMetaBuilder };
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { ControllerInfoUtil } from "../../util/ControllerInfoUtil.js";
|
|
2
|
+
import { ControllerValidator } from "../../util/validator/ControllerValidator.js";
|
|
3
|
+
import { MCPInfoUtil } from "../../util/MCPInfoUtil.js";
|
|
4
|
+
import { ControllerMetaBuilderFactory } from "../../builder/ControllerMetaBuilderFactory.js";
|
|
5
|
+
import { MCPControllerMeta } from "../../model/MCPControllerMeta.js";
|
|
6
|
+
import "../../model/index.js";
|
|
7
|
+
import { MCPControllerPromptMetaBuilder } from "./MCPControllerPromptMetaBuilder.js";
|
|
8
|
+
import { MCPControllerResourceMetaBuilder } from "./MCPControllerResourceMetaBuilder.js";
|
|
9
|
+
import { MCPControllerToolMetaBuilder } from "./MCPControllerToolMetaBuilder.js";
|
|
10
|
+
import { PrototypeUtil } from "@eggjs/core-decorator";
|
|
11
|
+
import { ControllerType } from "@eggjs/tegg-types";
|
|
12
|
+
import assert from "node:assert";
|
|
13
|
+
|
|
14
|
+
//#region src/impl/mcp/MCPControllerMetaBuilder.ts
|
|
15
|
+
var MCPControllerMetaBuilder = class MCPControllerMetaBuilder {
|
|
16
|
+
clazz;
|
|
17
|
+
constructor(clazz) {
|
|
18
|
+
this.clazz = clazz;
|
|
19
|
+
}
|
|
20
|
+
buildResource() {
|
|
21
|
+
const methodNames = MCPInfoUtil.getMCPResource(this.clazz);
|
|
22
|
+
const methods = [];
|
|
23
|
+
for (const methodName of methodNames) {
|
|
24
|
+
const methodMeta = new MCPControllerResourceMetaBuilder(this.clazz, methodName).build();
|
|
25
|
+
if (methodMeta) methods.push(methodMeta);
|
|
26
|
+
}
|
|
27
|
+
return methods;
|
|
28
|
+
}
|
|
29
|
+
buildPrompt() {
|
|
30
|
+
const methodNames = MCPInfoUtil.getMCPPrompt(this.clazz);
|
|
31
|
+
const methods = [];
|
|
32
|
+
for (const methodName of methodNames) {
|
|
33
|
+
const methodMeta = new MCPControllerPromptMetaBuilder(this.clazz, methodName).build();
|
|
34
|
+
if (methodMeta) methods.push(methodMeta);
|
|
35
|
+
}
|
|
36
|
+
return methods;
|
|
37
|
+
}
|
|
38
|
+
buildTool() {
|
|
39
|
+
const methodNames = MCPInfoUtil.getMCPTool(this.clazz);
|
|
40
|
+
const methods = [];
|
|
41
|
+
for (const methodName of methodNames) {
|
|
42
|
+
const methodMeta = new MCPControllerToolMetaBuilder(this.clazz, methodName).build();
|
|
43
|
+
if (methodMeta) methods.push(methodMeta);
|
|
44
|
+
}
|
|
45
|
+
return methods;
|
|
46
|
+
}
|
|
47
|
+
build() {
|
|
48
|
+
ControllerValidator.validate(this.clazz);
|
|
49
|
+
assert(ControllerInfoUtil.getControllerType(this.clazz) === ControllerType.MCP, "invalidate controller type");
|
|
50
|
+
const mcpMiddlewares = ControllerInfoUtil.getControllerMiddlewares(this.clazz);
|
|
51
|
+
const resources = this.buildResource();
|
|
52
|
+
const prompts = this.buildPrompt();
|
|
53
|
+
const tools = this.buildTool();
|
|
54
|
+
const protoName = PrototypeUtil.getProperty(this.clazz).name;
|
|
55
|
+
const clazzName = this.clazz.name;
|
|
56
|
+
const controllerName = ControllerInfoUtil.getControllerName(this.clazz) || clazzName;
|
|
57
|
+
const name = MCPInfoUtil.getMCPName(this.clazz);
|
|
58
|
+
return new MCPControllerMeta(clazzName, protoName, controllerName, MCPInfoUtil.getMCPVersion(this.clazz) || "1.0.0", tools, resources, prompts, mcpMiddlewares, name, ControllerInfoUtil.hasControllerAcl(this.clazz), ControllerInfoUtil.getControllerAcl(this.clazz), MCPInfoUtil.getMCPControllerParams(this.clazz));
|
|
59
|
+
}
|
|
60
|
+
static create(clazz) {
|
|
61
|
+
return new MCPControllerMetaBuilder(clazz);
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
ControllerMetaBuilderFactory.registerControllerMetaBuilder(ControllerType.MCP, MCPControllerMetaBuilder.create);
|
|
65
|
+
|
|
66
|
+
//#endregion
|
|
67
|
+
export { MCPControllerMetaBuilder };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { MCPPromptMeta } from "../../model/MCPPromptMeta.js";
|
|
2
|
+
import "../../model/index.js";
|
|
3
|
+
import { EggProtoImplClass } from "@eggjs/tegg-types";
|
|
4
|
+
|
|
5
|
+
//#region src/impl/mcp/MCPControllerPromptMetaBuilder.d.ts
|
|
6
|
+
declare class MCPControllerPromptMetaBuilder {
|
|
7
|
+
private readonly clazz;
|
|
8
|
+
private readonly methodName;
|
|
9
|
+
constructor(clazz: EggProtoImplClass, methodName: string);
|
|
10
|
+
build(): MCPPromptMeta | undefined;
|
|
11
|
+
}
|
|
12
|
+
//#endregion
|
|
13
|
+
export { MCPControllerPromptMetaBuilder };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { MethodInfoUtil } from "../../util/MethodInfoUtil.js";
|
|
2
|
+
import { MethodValidator } from "../../util/validator/MethodValidator.js";
|
|
3
|
+
import { MCPInfoUtil } from "../../util/MCPInfoUtil.js";
|
|
4
|
+
import { MCPPromptMeta } from "../../model/MCPPromptMeta.js";
|
|
5
|
+
import "../../model/index.js";
|
|
6
|
+
|
|
7
|
+
//#region src/impl/mcp/MCPControllerPromptMetaBuilder.ts
|
|
8
|
+
var MCPControllerPromptMetaBuilder = class {
|
|
9
|
+
clazz;
|
|
10
|
+
methodName;
|
|
11
|
+
constructor(clazz, methodName) {
|
|
12
|
+
this.clazz = clazz;
|
|
13
|
+
this.methodName = methodName;
|
|
14
|
+
}
|
|
15
|
+
build() {
|
|
16
|
+
MethodValidator.validate(this.clazz, this.methodName);
|
|
17
|
+
if (!MethodInfoUtil.getMethodControllerType(this.clazz, this.methodName)) return;
|
|
18
|
+
const middlewares = MethodInfoUtil.getMethodMiddlewares(this.clazz, this.methodName);
|
|
19
|
+
const needAcl = MethodInfoUtil.hasMethodAcl(this.clazz, this.methodName);
|
|
20
|
+
const aclCode = MethodInfoUtil.getMethodAcl(this.clazz, this.methodName);
|
|
21
|
+
const params = MCPInfoUtil.getMCPPromptParams(this.clazz, this.methodName);
|
|
22
|
+
const detail = MCPInfoUtil.getMCPPromptArgsIndex(this.clazz, this.methodName);
|
|
23
|
+
const extra = MCPInfoUtil.getMCPExtra(this.clazz, this.methodName);
|
|
24
|
+
return new MCPPromptMeta({
|
|
25
|
+
name: this.methodName,
|
|
26
|
+
middlewares,
|
|
27
|
+
needAcl,
|
|
28
|
+
aclCode,
|
|
29
|
+
detail,
|
|
30
|
+
extra,
|
|
31
|
+
...params
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
//#endregion
|
|
37
|
+
export { MCPControllerPromptMetaBuilder };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { MCPResourceMeta } from "../../model/MCPResourceMeta.js";
|
|
2
|
+
import "../../model/index.js";
|
|
3
|
+
import { EggProtoImplClass } from "@eggjs/tegg-types";
|
|
4
|
+
|
|
5
|
+
//#region src/impl/mcp/MCPControllerResourceMetaBuilder.d.ts
|
|
6
|
+
declare class MCPControllerResourceMetaBuilder {
|
|
7
|
+
private readonly clazz;
|
|
8
|
+
private readonly methodName;
|
|
9
|
+
constructor(clazz: EggProtoImplClass, methodName: string);
|
|
10
|
+
build(): MCPResourceMeta | undefined;
|
|
11
|
+
}
|
|
12
|
+
//#endregion
|
|
13
|
+
export { MCPControllerResourceMetaBuilder };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { MethodInfoUtil } from "../../util/MethodInfoUtil.js";
|
|
2
|
+
import { MethodValidator } from "../../util/validator/MethodValidator.js";
|
|
3
|
+
import { MCPInfoUtil } from "../../util/MCPInfoUtil.js";
|
|
4
|
+
import { MCPResourceMeta } from "../../model/MCPResourceMeta.js";
|
|
5
|
+
import "../../model/index.js";
|
|
6
|
+
|
|
7
|
+
//#region src/impl/mcp/MCPControllerResourceMetaBuilder.ts
|
|
8
|
+
var MCPControllerResourceMetaBuilder = class {
|
|
9
|
+
clazz;
|
|
10
|
+
methodName;
|
|
11
|
+
constructor(clazz, methodName) {
|
|
12
|
+
this.clazz = clazz;
|
|
13
|
+
this.methodName = methodName;
|
|
14
|
+
}
|
|
15
|
+
build() {
|
|
16
|
+
MethodValidator.validate(this.clazz, this.methodName);
|
|
17
|
+
if (!MethodInfoUtil.getMethodControllerType(this.clazz, this.methodName)) return;
|
|
18
|
+
const middlewares = MethodInfoUtil.getMethodMiddlewares(this.clazz, this.methodName);
|
|
19
|
+
const needAcl = MethodInfoUtil.hasMethodAcl(this.clazz, this.methodName);
|
|
20
|
+
const aclCode = MethodInfoUtil.getMethodAcl(this.clazz, this.methodName);
|
|
21
|
+
const params = MCPInfoUtil.getMCPResourceParams(this.clazz, this.methodName);
|
|
22
|
+
const extra = MCPInfoUtil.getMCPExtra(this.clazz, this.methodName);
|
|
23
|
+
return new MCPResourceMeta({
|
|
24
|
+
name: this.methodName,
|
|
25
|
+
middlewares,
|
|
26
|
+
needAcl,
|
|
27
|
+
aclCode,
|
|
28
|
+
extra,
|
|
29
|
+
...params
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
//#endregion
|
|
35
|
+
export { MCPControllerResourceMetaBuilder };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { MCPToolMeta } from "../../model/MCPToolMeta.js";
|
|
2
|
+
import "../../model/index.js";
|
|
3
|
+
import { EggProtoImplClass } from "@eggjs/tegg-types";
|
|
4
|
+
|
|
5
|
+
//#region src/impl/mcp/MCPControllerToolMetaBuilder.d.ts
|
|
6
|
+
declare class MCPControllerToolMetaBuilder {
|
|
7
|
+
private readonly clazz;
|
|
8
|
+
private readonly methodName;
|
|
9
|
+
constructor(clazz: EggProtoImplClass, methodName: string);
|
|
10
|
+
build(): MCPToolMeta | undefined;
|
|
11
|
+
}
|
|
12
|
+
//#endregion
|
|
13
|
+
export { MCPControllerToolMetaBuilder };
|