@tsed/platform-mcp 8.28.6 → 8.28.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 (86) hide show
  1. package/lib/esm/index.js +0 -26
  2. package/lib/esm/utils/toZod.js +3 -2
  3. package/lib/tsconfig.esm.tsbuildinfo +1 -1
  4. package/lib/types/fn/defineResource.d.ts +4 -4
  5. package/lib/types/index.d.ts +0 -26
  6. package/package.json +8 -7
  7. package/src/index.ts +0 -26
  8. package/src/utils/toZod.ts +4 -3
  9. package/lib/esm/utils/json-schema-to-zod/Types.js +0 -1
  10. package/lib/esm/utils/json-schema-to-zod/cli.js +0 -83
  11. package/lib/esm/utils/json-schema-to-zod/index.js +0 -25
  12. package/lib/esm/utils/json-schema-to-zod/jsonSchemaToZod.js +0 -52
  13. package/lib/esm/utils/json-schema-to-zod/parsers/parseAllOf.js +0 -43
  14. package/lib/esm/utils/json-schema-to-zod/parsers/parseAnyOf.js +0 -17
  15. package/lib/esm/utils/json-schema-to-zod/parsers/parseArray.js +0 -22
  16. package/lib/esm/utils/json-schema-to-zod/parsers/parseBoolean.js +0 -9
  17. package/lib/esm/utils/json-schema-to-zod/parsers/parseConst.js +0 -9
  18. package/lib/esm/utils/json-schema-to-zod/parsers/parseDefault.js +0 -9
  19. package/lib/esm/utils/json-schema-to-zod/parsers/parseEnum.js +0 -21
  20. package/lib/esm/utils/json-schema-to-zod/parsers/parseIfThenElse.js +0 -26
  21. package/lib/esm/utils/json-schema-to-zod/parsers/parseMultipleType.js +0 -10
  22. package/lib/esm/utils/json-schema-to-zod/parsers/parseNot.js +0 -13
  23. package/lib/esm/utils/json-schema-to-zod/parsers/parseNull.js +0 -9
  24. package/lib/esm/utils/json-schema-to-zod/parsers/parseNullable.js +0 -11
  25. package/lib/esm/utils/json-schema-to-zod/parsers/parseNumber.js +0 -52
  26. package/lib/esm/utils/json-schema-to-zod/parsers/parseObject.js +0 -177
  27. package/lib/esm/utils/json-schema-to-zod/parsers/parseOneOf.js +0 -40
  28. package/lib/esm/utils/json-schema-to-zod/parsers/parseSchema.js +0 -153
  29. package/lib/esm/utils/json-schema-to-zod/parsers/parseString.js +0 -63
  30. package/lib/esm/utils/json-schema-to-zod/utils/cliTools.js +0 -126
  31. package/lib/esm/utils/json-schema-to-zod/utils/half.js +0 -9
  32. package/lib/esm/utils/json-schema-to-zod/utils/jsdocs.js +0 -24
  33. package/lib/esm/utils/json-schema-to-zod/utils/omit.js +0 -12
  34. package/lib/esm/utils/json-schema-to-zod/utils/withMessage.js +0 -28
  35. package/lib/types/utils/json-schema-to-zod/Types.d.ts +0 -116
  36. package/lib/types/utils/json-schema-to-zod/cli.d.ts +0 -2
  37. package/lib/types/utils/json-schema-to-zod/index.d.ts +0 -25
  38. package/lib/types/utils/json-schema-to-zod/jsonSchemaToZod.d.ts +0 -11
  39. package/lib/types/utils/json-schema-to-zod/parsers/parseAllOf.d.ts +0 -10
  40. package/lib/types/utils/json-schema-to-zod/parsers/parseAnyOf.d.ts +0 -10
  41. package/lib/types/utils/json-schema-to-zod/parsers/parseArray.d.ts +0 -10
  42. package/lib/types/utils/json-schema-to-zod/parsers/parseBoolean.d.ts +0 -10
  43. package/lib/types/utils/json-schema-to-zod/parsers/parseConst.d.ts +0 -10
  44. package/lib/types/utils/json-schema-to-zod/parsers/parseDefault.d.ts +0 -8
  45. package/lib/types/utils/json-schema-to-zod/parsers/parseEnum.d.ts +0 -10
  46. package/lib/types/utils/json-schema-to-zod/parsers/parseIfThenElse.d.ts +0 -12
  47. package/lib/types/utils/json-schema-to-zod/parsers/parseMultipleType.d.ts +0 -10
  48. package/lib/types/utils/json-schema-to-zod/parsers/parseNot.d.ts +0 -10
  49. package/lib/types/utils/json-schema-to-zod/parsers/parseNull.d.ts +0 -10
  50. package/lib/types/utils/json-schema-to-zod/parsers/parseNullable.d.ts +0 -10
  51. package/lib/types/utils/json-schema-to-zod/parsers/parseNumber.d.ts +0 -10
  52. package/lib/types/utils/json-schema-to-zod/parsers/parseObject.d.ts +0 -10
  53. package/lib/types/utils/json-schema-to-zod/parsers/parseOneOf.d.ts +0 -10
  54. package/lib/types/utils/json-schema-to-zod/parsers/parseSchema.d.ts +0 -61
  55. package/lib/types/utils/json-schema-to-zod/parsers/parseString.d.ts +0 -10
  56. package/lib/types/utils/json-schema-to-zod/utils/cliTools.d.ts +0 -67
  57. package/lib/types/utils/json-schema-to-zod/utils/half.d.ts +0 -7
  58. package/lib/types/utils/json-schema-to-zod/utils/jsdocs.d.ts +0 -15
  59. package/lib/types/utils/json-schema-to-zod/utils/omit.d.ts +0 -7
  60. package/lib/types/utils/json-schema-to-zod/utils/withMessage.d.ts +0 -19
  61. package/src/utils/json-schema-to-zod/Types.ts +0 -123
  62. package/src/utils/json-schema-to-zod/cli.ts +0 -88
  63. package/src/utils/json-schema-to-zod/index.ts +0 -26
  64. package/src/utils/json-schema-to-zod/jsonSchemaToZod.ts +0 -60
  65. package/src/utils/json-schema-to-zod/parsers/parseAllOf.ts +0 -50
  66. package/src/utils/json-schema-to-zod/parsers/parseAnyOf.ts +0 -19
  67. package/src/utils/json-schema-to-zod/parsers/parseArray.ts +0 -28
  68. package/src/utils/json-schema-to-zod/parsers/parseBoolean.ts +0 -11
  69. package/src/utils/json-schema-to-zod/parsers/parseConst.ts +0 -11
  70. package/src/utils/json-schema-to-zod/parsers/parseDefault.ts +0 -11
  71. package/src/utils/json-schema-to-zod/parsers/parseEnum.ts +0 -20
  72. package/src/utils/json-schema-to-zod/parsers/parseIfThenElse.ts +0 -35
  73. package/src/utils/json-schema-to-zod/parsers/parseMultipleType.ts +0 -12
  74. package/src/utils/json-schema-to-zod/parsers/parseNot.ts +0 -15
  75. package/src/utils/json-schema-to-zod/parsers/parseNull.ts +0 -11
  76. package/src/utils/json-schema-to-zod/parsers/parseNullable.ts +0 -13
  77. package/src/utils/json-schema-to-zod/parsers/parseNumber.ts +0 -56
  78. package/src/utils/json-schema-to-zod/parsers/parseObject.ts +0 -220
  79. package/src/utils/json-schema-to-zod/parsers/parseOneOf.ts +0 -44
  80. package/src/utils/json-schema-to-zod/parsers/parseSchema.ts +0 -190
  81. package/src/utils/json-schema-to-zod/parsers/parseString.ts +0 -73
  82. package/src/utils/json-schema-to-zod/utils/cliTools.ts +0 -189
  83. package/src/utils/json-schema-to-zod/utils/half.ts +0 -9
  84. package/src/utils/json-schema-to-zod/utils/jsdocs.ts +0 -29
  85. package/src/utils/json-schema-to-zod/utils/omit.ts +0 -14
  86. package/src/utils/json-schema-to-zod/utils/withMessage.ts +0 -42
@@ -1,177 +0,0 @@
1
- import { addJsdocs } from "../utils/jsdocs.js";
2
- import { parseAllOf } from "./parseAllOf.js";
3
- import { parseAnyOf } from "./parseAnyOf.js";
4
- import { parseOneOf } from "./parseOneOf.js";
5
- import { its, parseSchema } from "./parseSchema.js";
6
- // Helper for z.record() generation - Zod v4 requires explicit key type
7
- function emitRecord(valueSchema, refs) {
8
- if (refs.zodVersion === 3) {
9
- return `z.record(${valueSchema})`;
10
- }
11
- // Default to v4 syntax
12
- return `z.record(z.string(), ${valueSchema})`;
13
- }
14
- // Helper for error path in superRefine - Zod v4 uses simplified path
15
- function emitErrorPath(refs) {
16
- if (refs.zodVersion === 3) {
17
- return `path: [...ctx.path, key]`;
18
- }
19
- // Default to v4 syntax
20
- return `path: [key]`;
21
- }
22
- /**
23
- * Parses object schemas, wiring properties, patternProperties, and catchall behavior into the resulting Zod object.
24
- *
25
- * @module platform/mcp
26
- * @since 8.17.0
27
- */
28
- export function parseObject(objectSchema, refs) {
29
- let properties = undefined;
30
- if (objectSchema.properties) {
31
- if (!Object.keys(objectSchema.properties).length) {
32
- properties = "z.object({})";
33
- }
34
- else {
35
- properties = "z.object({ ";
36
- properties += Object.keys(objectSchema.properties)
37
- .map((key) => {
38
- const propSchema = objectSchema.properties[key];
39
- let result = `${JSON.stringify(key)}: ${parseSchema(propSchema, {
40
- ...refs,
41
- path: [...refs.path, "properties", key]
42
- })}`;
43
- if (refs.withJsdocs && typeof propSchema === "object") {
44
- result = addJsdocs(propSchema, result);
45
- }
46
- const hasDefault = typeof propSchema === "object" && propSchema.default !== undefined;
47
- const required = Array.isArray(objectSchema.required)
48
- ? objectSchema.required.includes(key)
49
- : typeof propSchema === "object" && propSchema.required === true;
50
- const optional = !hasDefault && !required;
51
- return optional ? `${result}.optional()` : result;
52
- })
53
- .join(", ");
54
- properties += " })";
55
- }
56
- }
57
- const additionalProperties = objectSchema.additionalProperties !== undefined
58
- ? parseSchema(objectSchema.additionalProperties, {
59
- ...refs,
60
- path: [...refs.path, "additionalProperties"]
61
- })
62
- : undefined;
63
- let patternProperties = undefined;
64
- if (objectSchema.patternProperties) {
65
- const parsedPatternProperties = Object.fromEntries(Object.entries(objectSchema.patternProperties).map(([key, value]) => {
66
- return [
67
- key,
68
- parseSchema(value, {
69
- ...refs,
70
- path: [...refs.path, "patternProperties", key]
71
- })
72
- ];
73
- }, {}));
74
- patternProperties = "";
75
- if (properties) {
76
- if (additionalProperties) {
77
- patternProperties += `.catchall(z.union([${[...Object.values(parsedPatternProperties), additionalProperties].join(", ")}]))`;
78
- }
79
- else if (Object.keys(parsedPatternProperties).length > 1) {
80
- patternProperties += `.catchall(z.union([${Object.values(parsedPatternProperties).join(", ")}]))`;
81
- }
82
- else {
83
- patternProperties += `.catchall(${Object.values(parsedPatternProperties)})`;
84
- }
85
- }
86
- else {
87
- if (additionalProperties) {
88
- patternProperties += emitRecord(`z.union([${[...Object.values(parsedPatternProperties), additionalProperties].join(", ")}])`, refs);
89
- }
90
- else if (Object.keys(parsedPatternProperties).length > 1) {
91
- patternProperties += emitRecord(`z.union([${Object.values(parsedPatternProperties).join(", ")}])`, refs);
92
- }
93
- else {
94
- patternProperties += emitRecord(`${Object.values(parsedPatternProperties)}`, refs);
95
- }
96
- }
97
- patternProperties += ".superRefine((value, ctx) => {\n";
98
- patternProperties += "for (const key in value) {\n";
99
- if (additionalProperties) {
100
- if (objectSchema.properties) {
101
- patternProperties += `let evaluated = [${Object.keys(objectSchema.properties)
102
- .map((key) => JSON.stringify(key))
103
- .join(", ")}].includes(key)\n`;
104
- }
105
- else {
106
- patternProperties += `let evaluated = false\n`;
107
- }
108
- }
109
- for (const key in objectSchema.patternProperties) {
110
- patternProperties += "if (key.match(new RegExp(" + JSON.stringify(key) + "))) {\n";
111
- if (additionalProperties) {
112
- patternProperties += "evaluated = true\n";
113
- }
114
- patternProperties += "const result = " + parsedPatternProperties[key] + ".safeParse(value[key])\n";
115
- patternProperties += "if (!result.success) {\n";
116
- patternProperties += `ctx.addIssue({
117
- ${emitErrorPath(refs)},
118
- code: 'custom',
119
- message: \`Invalid input: Key matching regex /\${key}/ must match schema\`,
120
- params: {
121
- issues: result.error.issues
122
- }
123
- })\n`;
124
- patternProperties += "}\n";
125
- patternProperties += "}\n";
126
- }
127
- if (additionalProperties) {
128
- patternProperties += "if (!evaluated) {\n";
129
- patternProperties += "const result = " + additionalProperties + ".safeParse(value[key])\n";
130
- patternProperties += "if (!result.success) {\n";
131
- patternProperties += `ctx.addIssue({
132
- ${emitErrorPath(refs)},
133
- code: 'custom',
134
- message: \`Invalid input: must match catchall schema\`,
135
- params: {
136
- issues: result.error.issues
137
- }
138
- })\n`;
139
- patternProperties += "}\n";
140
- patternProperties += "}\n";
141
- }
142
- patternProperties += "}\n";
143
- patternProperties += "})";
144
- }
145
- let output = properties
146
- ? patternProperties
147
- ? properties + patternProperties
148
- : additionalProperties
149
- ? additionalProperties === "z.never()"
150
- ? properties + ".strict()"
151
- : properties + `.catchall(${additionalProperties})`
152
- : properties
153
- : patternProperties
154
- ? patternProperties
155
- : additionalProperties
156
- ? emitRecord(additionalProperties, refs)
157
- : emitRecord("z.any()", refs);
158
- if (its.an.anyOf(objectSchema)) {
159
- output += `.and(${parseAnyOf({
160
- ...objectSchema,
161
- anyOf: objectSchema.anyOf.map((x) => typeof x === "object" && !x.type && (x.properties || x.additionalProperties || x.patternProperties) ? { ...x, type: "object" } : x)
162
- }, refs)})`;
163
- }
164
- if (its.a.oneOf(objectSchema)) {
165
- output += `.and(${parseOneOf({
166
- ...objectSchema,
167
- oneOf: objectSchema.oneOf.map((x) => typeof x === "object" && !x.type && (x.properties || x.additionalProperties || x.patternProperties) ? { ...x, type: "object" } : x)
168
- }, refs)})`;
169
- }
170
- if (its.an.allOf(objectSchema)) {
171
- output += `.and(${parseAllOf({
172
- ...objectSchema,
173
- allOf: objectSchema.allOf.map((x) => typeof x === "object" && !x.type && (x.properties || x.additionalProperties || x.patternProperties) ? { ...x, type: "object" } : x)
174
- }, refs)})`;
175
- }
176
- return output;
177
- }
@@ -1,40 +0,0 @@
1
- import { parseSchema } from "./parseSchema.js";
2
- /**
3
- * Parses `oneOf` schemas by generating super refinements that ensure exactly one child schema matches.
4
- *
5
- * @module platform/mcp
6
- * @since 8.17.0
7
- */
8
- export const parseOneOf = (schema, refs) => {
9
- return schema.oneOf.length
10
- ? schema.oneOf.length === 1
11
- ? parseSchema(schema.oneOf[0], {
12
- ...refs,
13
- path: [...refs.path, "oneOf", 0]
14
- })
15
- : `z.any().superRefine((x, ctx) => {
16
- const schemas = [${schema.oneOf
17
- .map((schema, i) => parseSchema(schema, {
18
- ...refs,
19
- path: [...refs.path, "oneOf", i]
20
- }))
21
- .join(", ")}];
22
- const errors = schemas.reduce<z.ZodError[]>(
23
- (errors, schema) =>
24
- ((result) =>
25
- result.error ? [...errors, result.error] : errors)(
26
- schema.safeParse(x),
27
- ),
28
- [],
29
- );
30
- if (schemas.length - errors.length !== 1) {
31
- ctx.addIssue({
32
- path: ctx.path,
33
- code: "invalid_union",
34
- unionErrors: errors,
35
- message: "Invalid input: Should pass single schema",
36
- });
37
- }
38
- })`
39
- : "z.any()";
40
- };
@@ -1,153 +0,0 @@
1
- import { parseAllOf } from "./parseAllOf.js";
2
- import { parseAnyOf } from "./parseAnyOf.js";
3
- import { parseArray } from "./parseArray.js";
4
- import { parseBoolean } from "./parseBoolean.js";
5
- import { parseConst } from "./parseConst.js";
6
- import { parseDefault } from "./parseDefault.js";
7
- import { parseEnum } from "./parseEnum.js";
8
- import { parseIfThenElse } from "./parseIfThenElse.js";
9
- import { parseMultipleType } from "./parseMultipleType.js";
10
- import { parseNot } from "./parseNot.js";
11
- import { parseNull } from "./parseNull.js";
12
- import { parseNullable } from "./parseNullable.js";
13
- import { parseNumber } from "./parseNumber.js";
14
- import { parseObject } from "./parseObject.js";
15
- import { parseOneOf } from "./parseOneOf.js";
16
- import { parseString } from "./parseString.js";
17
- /**
18
- * Recursively parses a JSON Schema node into a Zod expression string.
19
- *
20
- * @param schema JSON Schema node to inspect.
21
- * @param refs Shared parsing context and options.
22
- * @param blockMeta When true, skips describe/default annotations for nested invocations.
23
- * @module platform/mcp
24
- * @since 8.17.0
25
- */
26
- export const parseSchema = (schema, refs = { seen: new Map(), path: [] }, blockMeta) => {
27
- if (typeof schema !== "object")
28
- return schema ? "z.any()" : "z.never()";
29
- if (refs.parserOverride) {
30
- const custom = refs.parserOverride(schema, refs);
31
- if (typeof custom === "string") {
32
- return custom;
33
- }
34
- }
35
- let seen = refs.seen.get(schema);
36
- if (seen) {
37
- if (seen.r !== undefined) {
38
- return seen.r;
39
- }
40
- if (refs.depth === undefined || seen.n >= refs.depth) {
41
- return "z.any()";
42
- }
43
- seen.n += 1;
44
- }
45
- else {
46
- seen = { r: undefined, n: 0 };
47
- refs.seen.set(schema, seen);
48
- }
49
- let parsed = selectParser(schema, refs);
50
- if (!blockMeta) {
51
- if (!refs.withoutDescribes) {
52
- parsed = addDescribes(schema, parsed);
53
- }
54
- if (!refs.withoutDefaults) {
55
- parsed = addDefaults(schema, parsed);
56
- }
57
- parsed = addAnnotations(schema, parsed);
58
- }
59
- seen.r = parsed;
60
- return parsed;
61
- };
62
- const addDescribes = (schema, parsed) => {
63
- if (schema.description) {
64
- parsed += `.describe(${JSON.stringify(schema.description)})`;
65
- }
66
- return parsed;
67
- };
68
- const addDefaults = (schema, parsed) => {
69
- if (schema.default !== undefined) {
70
- parsed += `.default(${JSON.stringify(schema.default)})`;
71
- }
72
- return parsed;
73
- };
74
- const addAnnotations = (schema, parsed) => {
75
- if (schema.readOnly) {
76
- parsed += ".readonly()";
77
- }
78
- return parsed;
79
- };
80
- const selectParser = (schema, refs) => {
81
- if (its.a.nullable(schema)) {
82
- return parseNullable(schema, refs);
83
- }
84
- else if (its.an.object(schema)) {
85
- return parseObject(schema, refs);
86
- }
87
- else if (its.an.array(schema)) {
88
- return parseArray(schema, refs);
89
- }
90
- else if (its.an.anyOf(schema)) {
91
- return parseAnyOf(schema, refs);
92
- }
93
- else if (its.an.allOf(schema)) {
94
- return parseAllOf(schema, refs);
95
- }
96
- else if (its.a.oneOf(schema)) {
97
- return parseOneOf(schema, refs);
98
- }
99
- else if (its.a.not(schema)) {
100
- return parseNot(schema, refs);
101
- }
102
- else if (its.an.enum(schema)) {
103
- return parseEnum(schema); //<-- needs to come before primitives
104
- }
105
- else if (its.a.const(schema)) {
106
- return parseConst(schema);
107
- }
108
- else if (its.a.multipleType(schema)) {
109
- return parseMultipleType(schema, refs);
110
- }
111
- else if (its.a.primitive(schema, "string")) {
112
- return parseString(schema);
113
- }
114
- else if (its.a.primitive(schema, "number") || its.a.primitive(schema, "integer")) {
115
- return parseNumber(schema);
116
- }
117
- else if (its.a.primitive(schema, "boolean")) {
118
- return parseBoolean(schema);
119
- }
120
- else if (its.a.primitive(schema, "null")) {
121
- return parseNull(schema);
122
- }
123
- else if (its.a.conditional(schema)) {
124
- return parseIfThenElse(schema, refs);
125
- }
126
- else {
127
- return parseDefault(schema);
128
- }
129
- };
130
- /**
131
- * Type guards used by the schema parser to detect structural patterns.
132
- *
133
- * @module platform/mcp
134
- * @since 8.17.0
135
- */
136
- export const its = {
137
- an: {
138
- object: (x) => x.type === "object",
139
- array: (x) => x.type === "array",
140
- anyOf: (x) => x.anyOf !== undefined,
141
- allOf: (x) => x.allOf !== undefined,
142
- enum: (x) => x.enum !== undefined
143
- },
144
- a: {
145
- nullable: (x) => x.nullable === true,
146
- multipleType: (x) => Array.isArray(x.type),
147
- not: (x) => x.not !== undefined,
148
- const: (x) => x.const !== undefined,
149
- primitive: (x, p) => x.type === p,
150
- conditional: (x) => Boolean("if" in x && x.if && "then" in x && "else" in x && x.then && x.else),
151
- oneOf: (x) => x.oneOf !== undefined
152
- }
153
- };
@@ -1,63 +0,0 @@
1
- import { withMessage } from "../utils/withMessage.js";
2
- import { parseSchema } from "./parseSchema.js";
3
- /**
4
- * Parses string schemas, supporting format-specific helpers, regex constraints, and content media transformations.
5
- *
6
- * @module platform/mcp
7
- * @since 8.17.0
8
- */
9
- export const parseString = (schema) => {
10
- let r = "z.string()";
11
- r += withMessage(schema, "format", ({ value }) => {
12
- switch (value) {
13
- case "email":
14
- return [".email(", ")"];
15
- case "ip":
16
- return [".ip(", ")"];
17
- case "ipv4":
18
- return ['.ip({ version: "v4"', ", message: ", " })"];
19
- case "ipv6":
20
- return ['.ip({ version: "v6"', ", message: ", " })"];
21
- case "uri":
22
- return [".url(", ")"];
23
- case "uuid":
24
- return [".uuid(", ")"];
25
- case "date-time":
26
- return [".datetime({ offset: true", ", message: ", " })"];
27
- case "time":
28
- return [".time(", ")"];
29
- case "date":
30
- return [".date(", ")"];
31
- case "binary":
32
- return [".base64(", ")"];
33
- case "duration":
34
- return [".duration(", ")"];
35
- }
36
- });
37
- r += withMessage(schema, "pattern", ({ json }) => [`.regex(new RegExp(${json})`, ", ", ")"]);
38
- r += withMessage(schema, "minLength", ({ json }) => [`.min(${json}`, ", ", ")"]);
39
- r += withMessage(schema, "maxLength", ({ json }) => [`.max(${json}`, ", ", ")"]);
40
- r += withMessage(schema, "contentEncoding", ({ value }) => {
41
- if (value === "base64") {
42
- return [".base64(", ")"];
43
- }
44
- });
45
- const contentMediaType = withMessage(schema, "contentMediaType", ({ value }) => {
46
- if (value === "application/json") {
47
- return [
48
- '.transform((str, ctx) => { try { return JSON.parse(str); } catch (err) { ctx.addIssue({ code: "custom", message: "Invalid JSON" }); }}',
49
- ", ",
50
- ")"
51
- ];
52
- }
53
- });
54
- if (contentMediaType != "") {
55
- r += contentMediaType;
56
- r += withMessage(schema, "contentSchema", ({ value }) => {
57
- if (value && value instanceof Object) {
58
- return [`.pipe(${parseSchema(value)}`, ", ", ")"];
59
- }
60
- });
61
- }
62
- return r;
63
- };
@@ -1,126 +0,0 @@
1
- import { readFileSync, statSync } from "fs";
2
- /**
3
- * Lightweight CLI arg parser honoring shorthands, type coercion, and required flags.
4
- *
5
- * @param params Parameter metadata map.
6
- * @param args Argument vector (usually `process.argv`).
7
- * @param help Optional help flag description; when provided, `-h/--help` prints usage.
8
- * @module platform/mcp
9
- * @since 8.17.0
10
- */
11
- export function parseArgs(params, args, help) {
12
- const result = {};
13
- if (help) {
14
- let index = args.indexOf("--help");
15
- if (index === -1) {
16
- index = args.indexOf("-h");
17
- }
18
- if (index !== -1) {
19
- printParams({
20
- ...params,
21
- help: {
22
- shorthand: "h",
23
- description: typeof help === "string" ? help : "Display this message :)"
24
- }
25
- });
26
- process.exit(0);
27
- }
28
- }
29
- for (const name in params) {
30
- const { shorthand, required, value } = params[name];
31
- let index = args.indexOf("--" + name);
32
- if (index === -1 && shorthand) {
33
- index = args.indexOf("-" + shorthand);
34
- }
35
- if (index === -1) {
36
- if (required || required === "") {
37
- throw new Error(typeof required === "string" && required !== "" ? required : `Missing required argument ${name}`);
38
- }
39
- result[name] = false;
40
- continue;
41
- }
42
- if (value) {
43
- const val = args[index + 1];
44
- if (val === undefined) {
45
- throw new Error(`Expected a value for argument ${name}`);
46
- }
47
- if (value === "number") {
48
- const asNumber = Number(val);
49
- if (isNaN(asNumber)) {
50
- throw new Error(`Value of argument ${name} must be a valid number`);
51
- }
52
- result[name] = asNumber;
53
- continue;
54
- }
55
- if (Array.isArray(value) && !value.includes(val)) {
56
- throw new Error(`Value of argument ${name} must be one of ${value}`);
57
- }
58
- result[name] = val;
59
- }
60
- else {
61
- result[name] = true;
62
- }
63
- }
64
- return result;
65
- }
66
- /**
67
- * Parses inline JSON or reads JSON from a file path (auto-detected by stat).
68
- *
69
- * @module platform/mcp
70
- * @since 8.17.0
71
- */
72
- export function parseOrReadJSON(jsonOrPath) {
73
- jsonOrPath = jsonOrPath.trim();
74
- if (jsonOrPath.length < 255 && statSync(jsonOrPath, { throwIfNoEntry: false })?.isFile()) {
75
- jsonOrPath = readFileSync(jsonOrPath, "utf-8");
76
- }
77
- return JSON.parse(jsonOrPath);
78
- }
79
- /**
80
- * Reads piped stdin into a UTF-8 string.
81
- *
82
- * @module platform/mcp
83
- * @since 8.17.0
84
- */
85
- export function readPipe() {
86
- return new Promise((resolve, reject) => {
87
- let buf = "";
88
- process.stdin
89
- .setEncoding("utf-8")
90
- .on("end", () => resolve(buf))
91
- .on("error", reject)
92
- .on("readable", () => {
93
- let chunk;
94
- while ((chunk = process.stdin.read()) != null) {
95
- buf += chunk;
96
- }
97
- });
98
- });
99
- }
100
- /**
101
- * Prints a simple help table describing available CLI parameters.
102
- *
103
- * @module platform/mcp
104
- * @since 8.17.0
105
- */
106
- export function printParams(params) {
107
- const longest = Object.keys(params).reduce((l, c) => (c.length > l ? c.length : l), 5);
108
- const header = "Name " + " ".repeat(longest - 2) + "Short Description";
109
- console.log(header);
110
- for (const name in params) {
111
- let { shorthand, description } = params[name];
112
- if (shorthand) {
113
- shorthand = " -" + shorthand;
114
- }
115
- else {
116
- shorthand = " ";
117
- }
118
- if (description) {
119
- description = " " + description;
120
- }
121
- else {
122
- description = "";
123
- }
124
- console.log("--" + name + " ".repeat(longest - name.length) + shorthand + description);
125
- }
126
- }
@@ -1,9 +0,0 @@
1
- /**
2
- * Splits an array in half, returning the left and right segments.
3
- *
4
- * @module platform/mcp
5
- * @since 8.17.0
6
- */
7
- export const half = (arr) => {
8
- return [arr.slice(0, arr.length / 2), arr.slice(arr.length / 2)];
9
- };
@@ -1,24 +0,0 @@
1
- /**
2
- * Expands a description string into a formatted JSDoc block suitable for emitted code.
3
- *
4
- * @module platform/mcp
5
- * @since 8.17.0
6
- */
7
- export const expandJsdocs = (jsdocs) => {
8
- const lines = jsdocs.split("\n");
9
- const result = lines.length === 1 ? lines[0] : `\n${lines.map((x) => `* ${x}`).join("\n")}\n`;
10
- return `/**${result}*/\n`;
11
- };
12
- /**
13
- * Adds inline JSDoc to a parsed snippet when the source schema exposes a description.
14
- *
15
- * @module platform/mcp
16
- * @since 8.17.0
17
- */
18
- export const addJsdocs = (schema, parsed) => {
19
- const description = schema.description;
20
- if (!description) {
21
- return parsed;
22
- }
23
- return `\n${expandJsdocs(description)}${parsed}`;
24
- };
@@ -1,12 +0,0 @@
1
- /**
2
- * Returns a shallow copy of an object without the provided keys.
3
- *
4
- * @module platform/mcp
5
- * @since 8.17.0
6
- */
7
- export const omit = (obj, ...keys) => Object.keys(obj).reduce((acc, key) => {
8
- if (!keys.includes(key)) {
9
- acc[key] = obj[key];
10
- }
11
- return acc;
12
- }, {});
@@ -1,28 +0,0 @@
1
- /**
2
- * Utility that appends chained Zod calls while preserving custom error messages defined on the JSON Schema node.
3
- *
4
- * @param schema Schema containing potential validation keywords.
5
- * @param key Keyword to inspect (e.g., `minLength`).
6
- * @param get Builder that returns the string fragments to append.
7
- * @module platform/mcp
8
- * @since 8.17.0
9
- */
10
- export function withMessage(schema, key, get) {
11
- const value = schema[key];
12
- let r = "";
13
- if (value !== undefined) {
14
- const got = get({ value, json: JSON.stringify(value) });
15
- if (got) {
16
- const opener = got[0];
17
- const prefix = got.length === 3 ? got[1] : "";
18
- const closer = got.length === 3 ? got[2] : got[1];
19
- r += opener;
20
- if (schema.errorMessage?.[key] !== undefined) {
21
- r += prefix + JSON.stringify(schema.errorMessage[key]);
22
- }
23
- r;
24
- r += closer;
25
- }
26
- }
27
- return r;
28
- }