@tsed/platform-mcp 8.36.0 → 8.37.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/lib/esm/fn/definePrompt.js +2 -2
- package/lib/esm/fn/defineTool.js +5 -5
- package/lib/esm/index.js +1 -1
- package/lib/esm/services/McpServerFactory.js +1 -1
- package/lib/esm/services/PlatformMcpModule.js +2 -2
- package/lib/esm/utils/fromJsonSchema.js +17 -0
- package/lib/tsconfig.esm.tsbuildinfo +1 -1
- package/lib/types/decorators/resource.d.ts +1 -1
- package/lib/types/fn/definePrompt.d.ts +4 -5
- package/lib/types/fn/defineResource.d.ts +17 -18
- package/lib/types/fn/defineTool.d.ts +2 -3
- package/lib/types/index.d.ts +1 -1
- package/lib/types/interfaces/PlatformMcpSettings.d.ts +2 -3
- package/lib/types/services/McpServerFactory.d.ts +1 -1
- package/lib/types/services/PlatformMcpModule.d.ts +1 -1
- package/lib/types/utils/asResourceResponse.d.ts +1 -1
- package/lib/types/utils/asToolResponse.d.ts +1 -1
- package/lib/types/utils/fromJsonSchema.d.ts +10 -0
- package/package.json +11 -12
- package/readme.md +1 -1
- package/src/decorators/resource.ts +1 -1
- package/src/fn/definePrompt.ts +5 -6
- package/src/fn/defineResource.ts +1 -2
- package/src/fn/defineTool.spec.ts +3 -5
- package/src/fn/defineTool.ts +7 -8
- package/src/index.ts +1 -1
- package/src/interfaces/PlatformMcpSettings.ts +2 -3
- package/src/services/McpServerFactory.ts +1 -2
- package/src/services/PlatformMcpModule.spec.ts +2 -2
- package/src/services/PlatformMcpModule.ts +3 -3
- package/src/utils/asResourceResponse.ts +1 -1
- package/src/utils/asToolResponse.ts +1 -1
- package/src/utils/fromJsonSchema.spec.ts +68 -0
- package/src/utils/fromJsonSchema.ts +20 -0
- package/vitest.config.mts +0 -1
- package/lib/esm/utils/toZod.js +0 -19
- package/lib/types/utils/toZod.d.ts +0 -12
- package/src/utils/toZod.spec.ts +0 -63
- package/src/utils/toZod.ts +0 -24
package/src/utils/toZod.spec.ts
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import {JsonSchema, Property, s, string} from "@tsed/schema";
|
|
2
|
-
import {toZod} from "./toZod.js";
|
|
3
|
-
|
|
4
|
-
describe("toZod", () => {
|
|
5
|
-
it("should transform JsonSchema to Zod instance", async () => {
|
|
6
|
-
const schema = s.object({
|
|
7
|
-
prop1: string()
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
const result = toZod(schema);
|
|
11
|
-
|
|
12
|
-
expect(result?.toJSONSchema).toBeDefined();
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
it("should preserve aliases when useAlias is enabled", () => {
|
|
16
|
-
const schema = new JsonSchema({
|
|
17
|
-
type: "object",
|
|
18
|
-
properties: {
|
|
19
|
-
prop: {
|
|
20
|
-
type: "string"
|
|
21
|
-
}
|
|
22
|
-
},
|
|
23
|
-
required: ["prop"]
|
|
24
|
-
}).addAlias("prop", "aliasProp");
|
|
25
|
-
|
|
26
|
-
const result = toZod(schema, {useAlias: true});
|
|
27
|
-
|
|
28
|
-
expect(result?.toJSONSchema()).toEqual({
|
|
29
|
-
$schema: "https://json-schema.org/draft/2020-12/schema",
|
|
30
|
-
type: "object",
|
|
31
|
-
properties: {
|
|
32
|
-
aliasProp: {
|
|
33
|
-
type: "string"
|
|
34
|
-
}
|
|
35
|
-
},
|
|
36
|
-
required: ["aliasProp"],
|
|
37
|
-
additionalProperties: false
|
|
38
|
-
});
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
it("should inline local schema references before converting to Zod", () => {
|
|
42
|
-
class Child {
|
|
43
|
-
@Property()
|
|
44
|
-
id: string;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
const result = toZod(s.object({child: s.from(Child)}));
|
|
48
|
-
|
|
49
|
-
expect(result?.toJSONSchema()).toMatchObject({
|
|
50
|
-
type: "object",
|
|
51
|
-
properties: {
|
|
52
|
-
child: {
|
|
53
|
-
type: "object",
|
|
54
|
-
properties: {
|
|
55
|
-
id: {
|
|
56
|
-
type: "string"
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
});
|
|
62
|
-
});
|
|
63
|
-
});
|
package/src/utils/toZod.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import {JsonSchema, JsonSchemaOptions, s} from "@tsed/schema";
|
|
2
|
-
import {z, type ZodObject} from "zod";
|
|
3
|
-
import {jsonSchemaToZod} from "json-schema-to-zod";
|
|
4
|
-
|
|
5
|
-
function transform(schema: JsonSchema, opts?: JsonSchemaOptions): ZodObject {
|
|
6
|
-
const schemaFactory = new Function("z", `return ${jsonSchemaToZod(s.compile(schema, {inlineRefs: true, ...opts}), {zodVersion: 4})}`) as (
|
|
7
|
-
zod: unknown
|
|
8
|
-
) => ZodObject;
|
|
9
|
-
|
|
10
|
-
return schemaFactory(z);
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Converts a {@link JsonSchema} produced by Ts.ED into an executable Zod validation object.
|
|
15
|
-
*
|
|
16
|
-
* @param schema JsonSchema instance or a pre-built Zod schema.
|
|
17
|
-
* @param opts
|
|
18
|
-
* @returns A Zod object when conversion is possible, otherwise the original schema.
|
|
19
|
-
* @module platform/mcp
|
|
20
|
-
* @since 8.17.0
|
|
21
|
-
*/
|
|
22
|
-
export function toZod(schema: unknown, opts?: JsonSchemaOptions): ZodObject | undefined {
|
|
23
|
-
return schema && schema instanceof JsonSchema ? transform(schema, opts) : (schema as ZodObject | undefined);
|
|
24
|
-
}
|