@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,189 +0,0 @@
1
- import {readFileSync, statSync} from "fs";
2
-
3
- /**
4
- * CLI parameter definition consumed by {@link parseArgs}.
5
- *
6
- * @module platform/mcp
7
- * @since 8.17.0
8
- */
9
- export type Param = {
10
- shorthand?: string;
11
- description?: string;
12
- required?: boolean | string | undefined;
13
- } & ({value?: "boolean"} | {value: "number"} | {value: "string"} | {value: {[key: number]: string}});
14
-
15
- /**
16
- * Map of CLI parameter definitions.
17
- *
18
- * @module platform/mcp
19
- * @since 8.17.0
20
- */
21
- export type Params = {[name: string]: Param};
22
-
23
- type InferReturnType<T extends Params> = {
24
- [name in keyof T]:
25
- | (T[name]["value"] extends "number"
26
- ? number
27
- : T[name]["value"] extends "string"
28
- ? string
29
- : T[name]["value"] extends {[key: number]: string}
30
- ? T[name]["value"][number]
31
- : T[name]["value"] extends never
32
- ? boolean
33
- : boolean)
34
- | (T[name]["required"] extends string | true ? never : undefined);
35
- };
36
-
37
- /**
38
- * Lightweight CLI arg parser honoring shorthands, type coercion, and required flags.
39
- *
40
- * @param params Parameter metadata map.
41
- * @param args Argument vector (usually `process.argv`).
42
- * @param help Optional help flag description; when provided, `-h/--help` prints usage.
43
- * @module platform/mcp
44
- * @since 8.17.0
45
- */
46
- export function parseArgs<T extends Params>(params: T, args: string[], help?: boolean | string): InferReturnType<T> {
47
- const result: Record<string, string | number | boolean> = {};
48
-
49
- if (help) {
50
- let index = args.indexOf("--help");
51
-
52
- if (index === -1) {
53
- index = args.indexOf("-h");
54
- }
55
-
56
- if (index !== -1) {
57
- printParams({
58
- ...params,
59
- help: {
60
- shorthand: "h",
61
- description: typeof help === "string" ? help : "Display this message :)"
62
- }
63
- });
64
-
65
- process.exit(0);
66
- }
67
- }
68
-
69
- for (const name in params) {
70
- const {shorthand, required, value} = params[name];
71
- let index = args.indexOf("--" + name);
72
-
73
- if (index === -1 && shorthand) {
74
- index = args.indexOf("-" + shorthand);
75
- }
76
-
77
- if (index === -1) {
78
- if (required || required === "") {
79
- throw new Error(typeof required === "string" && required !== "" ? required : `Missing required argument ${name}`);
80
- }
81
-
82
- result[name] = false;
83
-
84
- continue;
85
- }
86
-
87
- if (value) {
88
- const val = args[index + 1];
89
-
90
- if (val === undefined) {
91
- throw new Error(`Expected a value for argument ${name}`);
92
- }
93
-
94
- if (value === "number") {
95
- const asNumber = Number(val);
96
-
97
- if (isNaN(asNumber)) {
98
- throw new Error(`Value of argument ${name} must be a valid number`);
99
- }
100
-
101
- result[name] = asNumber;
102
-
103
- continue;
104
- }
105
-
106
- if (Array.isArray(value) && !value.includes(val)) {
107
- throw new Error(`Value of argument ${name} must be one of ${value}`);
108
- }
109
-
110
- result[name] = val;
111
- } else {
112
- result[name] = true;
113
- }
114
- }
115
-
116
- return result as any;
117
- }
118
-
119
- /**
120
- * Parses inline JSON or reads JSON from a file path (auto-detected by stat).
121
- *
122
- * @module platform/mcp
123
- * @since 8.17.0
124
- */
125
- export function parseOrReadJSON(jsonOrPath: string): unknown {
126
- jsonOrPath = jsonOrPath.trim();
127
-
128
- if (jsonOrPath.length < 255 && statSync(jsonOrPath, {throwIfNoEntry: false})?.isFile()) {
129
- jsonOrPath = readFileSync(jsonOrPath, "utf-8");
130
- }
131
-
132
- return JSON.parse(jsonOrPath);
133
- }
134
-
135
- /**
136
- * Reads piped stdin into a UTF-8 string.
137
- *
138
- * @module platform/mcp
139
- * @since 8.17.0
140
- */
141
- export function readPipe(): Promise<string> {
142
- return new Promise<string>((resolve, reject) => {
143
- let buf = "";
144
-
145
- process.stdin
146
- .setEncoding("utf-8")
147
- .on("end", () => resolve(buf))
148
- .on("error", reject)
149
- .on("readable", () => {
150
- let chunk: string | null;
151
-
152
- while ((chunk = process.stdin.read()) != null) {
153
- buf += chunk;
154
- }
155
- });
156
- });
157
- }
158
-
159
- /**
160
- * Prints a simple help table describing available CLI parameters.
161
- *
162
- * @module platform/mcp
163
- * @since 8.17.0
164
- */
165
- export function printParams(params: Record<string, Param>): void {
166
- const longest = Object.keys(params).reduce((l, c) => (c.length > l ? c.length : l), 5);
167
-
168
- const header = "Name " + " ".repeat(longest - 2) + "Short Description";
169
-
170
- console.log(header);
171
-
172
- for (const name in params) {
173
- let {shorthand, description} = params[name];
174
-
175
- if (shorthand) {
176
- shorthand = " -" + shorthand;
177
- } else {
178
- shorthand = " ";
179
- }
180
-
181
- if (description) {
182
- description = " " + description;
183
- } else {
184
- description = "";
185
- }
186
-
187
- console.log("--" + name + " ".repeat(longest - name.length) + shorthand + description);
188
- }
189
- }
@@ -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 = <T>(arr: T[]): [T[], T[]] => {
8
- return [arr.slice(0, arr.length / 2), arr.slice(arr.length / 2)];
9
- };
@@ -1,29 +0,0 @@
1
- import {JsonSchemaObject} from "../Types.js";
2
-
3
- /**
4
- * Expands a description string into a formatted JSDoc block suitable for emitted code.
5
- *
6
- * @module platform/mcp
7
- * @since 8.17.0
8
- */
9
- export const expandJsdocs = (jsdocs: string): string => {
10
- const lines = jsdocs.split("\n");
11
- const result = lines.length === 1 ? lines[0] : `\n${lines.map((x) => `* ${x}`).join("\n")}\n`;
12
-
13
- return `/**${result}*/\n`;
14
- };
15
-
16
- /**
17
- * Adds inline JSDoc to a parsed snippet when the source schema exposes a description.
18
- *
19
- * @module platform/mcp
20
- * @since 8.17.0
21
- */
22
- export const addJsdocs = (schema: JsonSchemaObject, parsed: string): string => {
23
- const description = schema.description as string;
24
- if (!description) {
25
- return parsed;
26
- }
27
-
28
- return `\n${expandJsdocs(description)}${parsed}`;
29
- };
@@ -1,14 +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 = <T extends object, K extends keyof T>(obj: T, ...keys: K[]): Omit<T, K> =>
8
- Object.keys(obj).reduce((acc: Record<string, unknown>, key) => {
9
- if (!keys.includes(key as K)) {
10
- acc[key] = obj[key as K];
11
- }
12
-
13
- return acc;
14
- }, {}) as any;
@@ -1,42 +0,0 @@
1
- import {JsonSchemaObject} from "../Types.js";
2
-
3
- type Opener = string;
4
- type MessagePrefix = string;
5
- type Closer = string;
6
-
7
- type Builder = [Opener, Closer] | [Opener, MessagePrefix, Closer];
8
-
9
- /**
10
- * Utility that appends chained Zod calls while preserving custom error messages defined on the JSON Schema node.
11
- *
12
- * @param schema Schema containing potential validation keywords.
13
- * @param key Keyword to inspect (e.g., `minLength`).
14
- * @param get Builder that returns the string fragments to append.
15
- * @module platform/mcp
16
- * @since 8.17.0
17
- */
18
- export function withMessage(schema: JsonSchemaObject, key: string, get: (props: {value: unknown; json: string}) => Builder | void) {
19
- const value = schema[key as keyof typeof schema];
20
-
21
- let r = "";
22
-
23
- if (value !== undefined) {
24
- const got = get({value, json: JSON.stringify(value)});
25
-
26
- if (got) {
27
- const opener = got[0];
28
- const prefix = got.length === 3 ? got[1] : "";
29
- const closer = got.length === 3 ? got[2] : got[1];
30
-
31
- r += opener;
32
-
33
- if (schema.errorMessage?.[key] !== undefined) {
34
- r += prefix + JSON.stringify(schema.errorMessage[key]);
35
- }
36
- r;
37
- r += closer;
38
- }
39
- }
40
-
41
- return r;
42
- }