@tsed/cli-mcp 7.5.0 → 7.5.1
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/utils/toZod.js +1 -1
- package/lib/tsconfig.esm.tsbuildinfo +1 -1
- package/lib/types/fn/defineTool.d.ts +2 -2
- package/package.json +4 -3
- package/lib/esm/utils/json-schema-to-zod/Types.js +0 -1
- package/lib/esm/utils/json-schema-to-zod/cli.js +0 -74
- package/lib/esm/utils/json-schema-to-zod/index.js +0 -25
- package/lib/esm/utils/json-schema-to-zod/jsonSchemaToZod.js +0 -43
- package/lib/esm/utils/json-schema-to-zod/parsers/parseAllOf.js +0 -37
- package/lib/esm/utils/json-schema-to-zod/parsers/parseAnyOf.js +0 -11
- package/lib/esm/utils/json-schema-to-zod/parsers/parseArray.js +0 -16
- package/lib/esm/utils/json-schema-to-zod/parsers/parseBoolean.js +0 -3
- package/lib/esm/utils/json-schema-to-zod/parsers/parseConst.js +0 -3
- package/lib/esm/utils/json-schema-to-zod/parsers/parseDefault.js +0 -3
- package/lib/esm/utils/json-schema-to-zod/parsers/parseEnum.js +0 -15
- package/lib/esm/utils/json-schema-to-zod/parsers/parseIfThenElse.js +0 -20
- package/lib/esm/utils/json-schema-to-zod/parsers/parseMultipleType.js +0 -4
- package/lib/esm/utils/json-schema-to-zod/parsers/parseNot.js +0 -7
- package/lib/esm/utils/json-schema-to-zod/parsers/parseNull.js +0 -3
- package/lib/esm/utils/json-schema-to-zod/parsers/parseNullable.js +0 -8
- package/lib/esm/utils/json-schema-to-zod/parsers/parseNumber.js +0 -46
- package/lib/esm/utils/json-schema-to-zod/parsers/parseObject.js +0 -171
- package/lib/esm/utils/json-schema-to-zod/parsers/parseOneOf.js +0 -34
- package/lib/esm/utils/json-schema-to-zod/parsers/parseSchema.js +0 -138
- package/lib/esm/utils/json-schema-to-zod/parsers/parseString.js +0 -57
- package/lib/esm/utils/json-schema-to-zod/utils/cliTools.js +0 -99
- package/lib/esm/utils/json-schema-to-zod/utils/half.js +0 -3
- package/lib/esm/utils/json-schema-to-zod/utils/jsdocs.js +0 -12
- package/lib/esm/utils/json-schema-to-zod/utils/omit.js +0 -6
- package/lib/esm/utils/json-schema-to-zod/utils/withMessage.js +0 -19
- package/lib/types/utils/json-schema-to-zod/Types.d.ts +0 -68
- package/lib/types/utils/json-schema-to-zod/cli.d.ts +0 -2
- package/lib/types/utils/json-schema-to-zod/index.d.ts +0 -25
- package/lib/types/utils/json-schema-to-zod/jsonSchemaToZod.d.ts +0 -2
- package/lib/types/utils/json-schema-to-zod/parsers/parseAllOf.d.ts +0 -4
- package/lib/types/utils/json-schema-to-zod/parsers/parseAnyOf.d.ts +0 -4
- package/lib/types/utils/json-schema-to-zod/parsers/parseArray.d.ts +0 -4
- package/lib/types/utils/json-schema-to-zod/parsers/parseBoolean.d.ts +0 -4
- package/lib/types/utils/json-schema-to-zod/parsers/parseConst.d.ts +0 -4
- package/lib/types/utils/json-schema-to-zod/parsers/parseDefault.d.ts +0 -2
- package/lib/types/utils/json-schema-to-zod/parsers/parseEnum.d.ts +0 -4
- package/lib/types/utils/json-schema-to-zod/parsers/parseIfThenElse.d.ts +0 -6
- package/lib/types/utils/json-schema-to-zod/parsers/parseMultipleType.d.ts +0 -4
- package/lib/types/utils/json-schema-to-zod/parsers/parseNot.d.ts +0 -4
- package/lib/types/utils/json-schema-to-zod/parsers/parseNull.d.ts +0 -4
- package/lib/types/utils/json-schema-to-zod/parsers/parseNullable.d.ts +0 -7
- package/lib/types/utils/json-schema-to-zod/parsers/parseNumber.d.ts +0 -4
- package/lib/types/utils/json-schema-to-zod/parsers/parseObject.d.ts +0 -4
- package/lib/types/utils/json-schema-to-zod/parsers/parseOneOf.d.ts +0 -4
- package/lib/types/utils/json-schema-to-zod/parsers/parseSchema.d.ts +0 -46
- package/lib/types/utils/json-schema-to-zod/parsers/parseString.d.ts +0 -4
- package/lib/types/utils/json-schema-to-zod/utils/cliTools.d.ts +0 -28
- package/lib/types/utils/json-schema-to-zod/utils/half.d.ts +0 -1
- package/lib/types/utils/json-schema-to-zod/utils/jsdocs.d.ts +0 -3
- package/lib/types/utils/json-schema-to-zod/utils/omit.d.ts +0 -1
- package/lib/types/utils/json-schema-to-zod/utils/withMessage.d.ts +0 -10
|
@@ -1,138 +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
|
-
export const parseSchema = (schema, refs = { seen: new Map(), path: [] }, blockMeta) => {
|
|
18
|
-
if (typeof schema !== "object")
|
|
19
|
-
return schema ? "z.any()" : "z.never()";
|
|
20
|
-
if (refs.parserOverride) {
|
|
21
|
-
const custom = refs.parserOverride(schema, refs);
|
|
22
|
-
if (typeof custom === "string") {
|
|
23
|
-
return custom;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
let seen = refs.seen.get(schema);
|
|
27
|
-
if (seen) {
|
|
28
|
-
if (seen.r !== undefined) {
|
|
29
|
-
return seen.r;
|
|
30
|
-
}
|
|
31
|
-
if (refs.depth === undefined || seen.n >= refs.depth) {
|
|
32
|
-
return "z.any()";
|
|
33
|
-
}
|
|
34
|
-
seen.n += 1;
|
|
35
|
-
}
|
|
36
|
-
else {
|
|
37
|
-
seen = { r: undefined, n: 0 };
|
|
38
|
-
refs.seen.set(schema, seen);
|
|
39
|
-
}
|
|
40
|
-
let parsed = selectParser(schema, refs);
|
|
41
|
-
if (!blockMeta) {
|
|
42
|
-
if (!refs.withoutDescribes) {
|
|
43
|
-
parsed = addDescribes(schema, parsed);
|
|
44
|
-
}
|
|
45
|
-
if (!refs.withoutDefaults) {
|
|
46
|
-
parsed = addDefaults(schema, parsed);
|
|
47
|
-
}
|
|
48
|
-
parsed = addAnnotations(schema, parsed);
|
|
49
|
-
}
|
|
50
|
-
seen.r = parsed;
|
|
51
|
-
return parsed;
|
|
52
|
-
};
|
|
53
|
-
const addDescribes = (schema, parsed) => {
|
|
54
|
-
if (schema.description) {
|
|
55
|
-
parsed += `.describe(${JSON.stringify(schema.description)})`;
|
|
56
|
-
}
|
|
57
|
-
return parsed;
|
|
58
|
-
};
|
|
59
|
-
const addDefaults = (schema, parsed) => {
|
|
60
|
-
if (schema.default !== undefined) {
|
|
61
|
-
parsed += `.default(${JSON.stringify(schema.default)})`;
|
|
62
|
-
}
|
|
63
|
-
return parsed;
|
|
64
|
-
};
|
|
65
|
-
const addAnnotations = (schema, parsed) => {
|
|
66
|
-
if (schema.readOnly) {
|
|
67
|
-
parsed += ".readonly()";
|
|
68
|
-
}
|
|
69
|
-
return parsed;
|
|
70
|
-
};
|
|
71
|
-
const selectParser = (schema, refs) => {
|
|
72
|
-
if (its.a.nullable(schema)) {
|
|
73
|
-
return parseNullable(schema, refs);
|
|
74
|
-
}
|
|
75
|
-
else if (its.an.object(schema)) {
|
|
76
|
-
return parseObject(schema, refs);
|
|
77
|
-
}
|
|
78
|
-
else if (its.an.array(schema)) {
|
|
79
|
-
return parseArray(schema, refs);
|
|
80
|
-
}
|
|
81
|
-
else if (its.an.anyOf(schema)) {
|
|
82
|
-
return parseAnyOf(schema, refs);
|
|
83
|
-
}
|
|
84
|
-
else if (its.an.allOf(schema)) {
|
|
85
|
-
return parseAllOf(schema, refs);
|
|
86
|
-
}
|
|
87
|
-
else if (its.a.oneOf(schema)) {
|
|
88
|
-
return parseOneOf(schema, refs);
|
|
89
|
-
}
|
|
90
|
-
else if (its.a.not(schema)) {
|
|
91
|
-
return parseNot(schema, refs);
|
|
92
|
-
}
|
|
93
|
-
else if (its.an.enum(schema)) {
|
|
94
|
-
return parseEnum(schema); //<-- needs to come before primitives
|
|
95
|
-
}
|
|
96
|
-
else if (its.a.const(schema)) {
|
|
97
|
-
return parseConst(schema);
|
|
98
|
-
}
|
|
99
|
-
else if (its.a.multipleType(schema)) {
|
|
100
|
-
return parseMultipleType(schema, refs);
|
|
101
|
-
}
|
|
102
|
-
else if (its.a.primitive(schema, "string")) {
|
|
103
|
-
return parseString(schema);
|
|
104
|
-
}
|
|
105
|
-
else if (its.a.primitive(schema, "number") || its.a.primitive(schema, "integer")) {
|
|
106
|
-
return parseNumber(schema);
|
|
107
|
-
}
|
|
108
|
-
else if (its.a.primitive(schema, "boolean")) {
|
|
109
|
-
return parseBoolean(schema);
|
|
110
|
-
}
|
|
111
|
-
else if (its.a.primitive(schema, "null")) {
|
|
112
|
-
return parseNull(schema);
|
|
113
|
-
}
|
|
114
|
-
else if (its.a.conditional(schema)) {
|
|
115
|
-
return parseIfThenElse(schema, refs);
|
|
116
|
-
}
|
|
117
|
-
else {
|
|
118
|
-
return parseDefault(schema);
|
|
119
|
-
}
|
|
120
|
-
};
|
|
121
|
-
export const its = {
|
|
122
|
-
an: {
|
|
123
|
-
object: (x) => x.type === "object",
|
|
124
|
-
array: (x) => x.type === "array",
|
|
125
|
-
anyOf: (x) => x.anyOf !== undefined,
|
|
126
|
-
allOf: (x) => x.allOf !== undefined,
|
|
127
|
-
enum: (x) => x.enum !== undefined
|
|
128
|
-
},
|
|
129
|
-
a: {
|
|
130
|
-
nullable: (x) => x.nullable === true,
|
|
131
|
-
multipleType: (x) => Array.isArray(x.type),
|
|
132
|
-
not: (x) => x.not !== undefined,
|
|
133
|
-
const: (x) => x.const !== undefined,
|
|
134
|
-
primitive: (x, p) => x.type === p,
|
|
135
|
-
conditional: (x) => Boolean("if" in x && x.if && "then" in x && "else" in x && x.then && x.else),
|
|
136
|
-
oneOf: (x) => x.oneOf !== undefined
|
|
137
|
-
}
|
|
138
|
-
};
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { withMessage } from "../utils/withMessage.js";
|
|
2
|
-
import { parseSchema } from "./parseSchema.js";
|
|
3
|
-
export const parseString = (schema) => {
|
|
4
|
-
let r = "z.string()";
|
|
5
|
-
r += withMessage(schema, "format", ({ value }) => {
|
|
6
|
-
switch (value) {
|
|
7
|
-
case "email":
|
|
8
|
-
return [".email(", ")"];
|
|
9
|
-
case "ip":
|
|
10
|
-
return [".ip(", ")"];
|
|
11
|
-
case "ipv4":
|
|
12
|
-
return ['.ip({ version: "v4"', ", message: ", " })"];
|
|
13
|
-
case "ipv6":
|
|
14
|
-
return ['.ip({ version: "v6"', ", message: ", " })"];
|
|
15
|
-
case "uri":
|
|
16
|
-
return [".url(", ")"];
|
|
17
|
-
case "uuid":
|
|
18
|
-
return [".uuid(", ")"];
|
|
19
|
-
case "date-time":
|
|
20
|
-
return [".datetime({ offset: true", ", message: ", " })"];
|
|
21
|
-
case "time":
|
|
22
|
-
return [".time(", ")"];
|
|
23
|
-
case "date":
|
|
24
|
-
return [".date(", ")"];
|
|
25
|
-
case "binary":
|
|
26
|
-
return [".base64(", ")"];
|
|
27
|
-
case "duration":
|
|
28
|
-
return [".duration(", ")"];
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
r += withMessage(schema, "pattern", ({ json }) => [`.regex(new RegExp(${json})`, ", ", ")"]);
|
|
32
|
-
r += withMessage(schema, "minLength", ({ json }) => [`.min(${json}`, ", ", ")"]);
|
|
33
|
-
r += withMessage(schema, "maxLength", ({ json }) => [`.max(${json}`, ", ", ")"]);
|
|
34
|
-
r += withMessage(schema, "contentEncoding", ({ value }) => {
|
|
35
|
-
if (value === "base64") {
|
|
36
|
-
return [".base64(", ")"];
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
const contentMediaType = withMessage(schema, "contentMediaType", ({ value }) => {
|
|
40
|
-
if (value === "application/json") {
|
|
41
|
-
return [
|
|
42
|
-
'.transform((str, ctx) => { try { return JSON.parse(str); } catch (err) { ctx.addIssue({ code: "custom", message: "Invalid JSON" }); }}',
|
|
43
|
-
", ",
|
|
44
|
-
")"
|
|
45
|
-
];
|
|
46
|
-
}
|
|
47
|
-
});
|
|
48
|
-
if (contentMediaType != "") {
|
|
49
|
-
r += contentMediaType;
|
|
50
|
-
r += withMessage(schema, "contentSchema", ({ value }) => {
|
|
51
|
-
if (value && value instanceof Object) {
|
|
52
|
-
return [`.pipe(${parseSchema(value)}`, ", ", ")"];
|
|
53
|
-
}
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
return r;
|
|
57
|
-
};
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
import { readFileSync, statSync } from "fs";
|
|
2
|
-
export function parseArgs(params, args, help) {
|
|
3
|
-
const result = {};
|
|
4
|
-
if (help) {
|
|
5
|
-
let index = args.indexOf("--help");
|
|
6
|
-
if (index === -1) {
|
|
7
|
-
index = args.indexOf("-h");
|
|
8
|
-
}
|
|
9
|
-
if (index !== -1) {
|
|
10
|
-
printParams({
|
|
11
|
-
...params,
|
|
12
|
-
help: {
|
|
13
|
-
shorthand: "h",
|
|
14
|
-
description: typeof help === "string" ? help : "Display this message :)"
|
|
15
|
-
}
|
|
16
|
-
});
|
|
17
|
-
process.exit(0);
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
for (const name in params) {
|
|
21
|
-
const { shorthand, required, value } = params[name];
|
|
22
|
-
let index = args.indexOf("--" + name);
|
|
23
|
-
if (index === -1 && shorthand) {
|
|
24
|
-
index = args.indexOf("-" + shorthand);
|
|
25
|
-
}
|
|
26
|
-
if (index === -1) {
|
|
27
|
-
if (required || required === "") {
|
|
28
|
-
throw new Error(typeof required === "string" && required !== "" ? required : `Missing required argument ${name}`);
|
|
29
|
-
}
|
|
30
|
-
result[name] = false;
|
|
31
|
-
continue;
|
|
32
|
-
}
|
|
33
|
-
if (value) {
|
|
34
|
-
const val = args[index + 1];
|
|
35
|
-
if (val === undefined) {
|
|
36
|
-
throw new Error(`Expected a value for argument ${name}`);
|
|
37
|
-
}
|
|
38
|
-
if (value === "number") {
|
|
39
|
-
const asNumber = Number(val);
|
|
40
|
-
if (isNaN(asNumber)) {
|
|
41
|
-
throw new Error(`Value of argument ${name} must be a valid number`);
|
|
42
|
-
}
|
|
43
|
-
result[name] = asNumber;
|
|
44
|
-
continue;
|
|
45
|
-
}
|
|
46
|
-
if (Array.isArray(value) && !value.includes(val)) {
|
|
47
|
-
throw new Error(`Value of argument ${name} must be one of ${value}`);
|
|
48
|
-
}
|
|
49
|
-
result[name] = val;
|
|
50
|
-
}
|
|
51
|
-
else {
|
|
52
|
-
result[name] = true;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
return result;
|
|
56
|
-
}
|
|
57
|
-
export function parseOrReadJSON(jsonOrPath) {
|
|
58
|
-
jsonOrPath = jsonOrPath.trim();
|
|
59
|
-
if (jsonOrPath.length < 255 && statSync(jsonOrPath, { throwIfNoEntry: false })?.isFile()) {
|
|
60
|
-
jsonOrPath = readFileSync(jsonOrPath, "utf-8");
|
|
61
|
-
}
|
|
62
|
-
return JSON.parse(jsonOrPath);
|
|
63
|
-
}
|
|
64
|
-
export function readPipe() {
|
|
65
|
-
return new Promise((resolve, reject) => {
|
|
66
|
-
let buf = "";
|
|
67
|
-
process.stdin
|
|
68
|
-
.setEncoding("utf-8")
|
|
69
|
-
.on("end", () => resolve(buf))
|
|
70
|
-
.on("error", reject)
|
|
71
|
-
.on("readable", () => {
|
|
72
|
-
let chunk;
|
|
73
|
-
while ((chunk = process.stdin.read()) != null) {
|
|
74
|
-
buf += chunk;
|
|
75
|
-
}
|
|
76
|
-
});
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
export function printParams(params) {
|
|
80
|
-
const longest = Object.keys(params).reduce((l, c) => (c.length > l ? c.length : l), 5);
|
|
81
|
-
const header = "Name " + " ".repeat(longest - 2) + "Short Description";
|
|
82
|
-
console.log(header);
|
|
83
|
-
for (const name in params) {
|
|
84
|
-
let { shorthand, description } = params[name];
|
|
85
|
-
if (shorthand) {
|
|
86
|
-
shorthand = " -" + shorthand;
|
|
87
|
-
}
|
|
88
|
-
else {
|
|
89
|
-
shorthand = " ";
|
|
90
|
-
}
|
|
91
|
-
if (description) {
|
|
92
|
-
description = " " + description;
|
|
93
|
-
}
|
|
94
|
-
else {
|
|
95
|
-
description = "";
|
|
96
|
-
}
|
|
97
|
-
console.log("--" + name + " ".repeat(longest - name.length) + shorthand + description);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export const expandJsdocs = (jsdocs) => {
|
|
2
|
-
const lines = jsdocs.split("\n");
|
|
3
|
-
const result = lines.length === 1 ? lines[0] : `\n${lines.map((x) => `* ${x}`).join("\n")}\n`;
|
|
4
|
-
return `/**${result}*/\n`;
|
|
5
|
-
};
|
|
6
|
-
export const addJsdocs = (schema, parsed) => {
|
|
7
|
-
const description = schema.description;
|
|
8
|
-
if (!description) {
|
|
9
|
-
return parsed;
|
|
10
|
-
}
|
|
11
|
-
return `\n${expandJsdocs(description)}${parsed}`;
|
|
12
|
-
};
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
export function withMessage(schema, key, get) {
|
|
2
|
-
const value = schema[key];
|
|
3
|
-
let r = "";
|
|
4
|
-
if (value !== undefined) {
|
|
5
|
-
const got = get({ value, json: JSON.stringify(value) });
|
|
6
|
-
if (got) {
|
|
7
|
-
const opener = got[0];
|
|
8
|
-
const prefix = got.length === 3 ? got[1] : "";
|
|
9
|
-
const closer = got.length === 3 ? got[2] : got[1];
|
|
10
|
-
r += opener;
|
|
11
|
-
if (schema.errorMessage?.[key] !== undefined) {
|
|
12
|
-
r += prefix + JSON.stringify(schema.errorMessage[key]);
|
|
13
|
-
}
|
|
14
|
-
r;
|
|
15
|
-
r += closer;
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
return r;
|
|
19
|
-
}
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
export type Serializable = {
|
|
2
|
-
[key: string]: Serializable;
|
|
3
|
-
} | Serializable[] | string | number | boolean | null;
|
|
4
|
-
export type JsonSchema = JsonSchemaObject | boolean;
|
|
5
|
-
export type JsonSchemaObject = {
|
|
6
|
-
type?: string | string[];
|
|
7
|
-
properties?: {
|
|
8
|
-
[key: string]: JsonSchema;
|
|
9
|
-
};
|
|
10
|
-
additionalProperties?: JsonSchema;
|
|
11
|
-
unevaluatedProperties?: JsonSchema;
|
|
12
|
-
patternProperties?: {
|
|
13
|
-
[key: string]: JsonSchema;
|
|
14
|
-
};
|
|
15
|
-
minProperties?: number;
|
|
16
|
-
maxProperties?: number;
|
|
17
|
-
required?: string[] | boolean;
|
|
18
|
-
propertyNames?: JsonSchema;
|
|
19
|
-
items?: JsonSchema | JsonSchema[];
|
|
20
|
-
additionalItems?: JsonSchema;
|
|
21
|
-
minItems?: number;
|
|
22
|
-
maxItems?: number;
|
|
23
|
-
uniqueItems?: boolean;
|
|
24
|
-
minLength?: number;
|
|
25
|
-
maxLength?: number;
|
|
26
|
-
pattern?: string;
|
|
27
|
-
format?: string;
|
|
28
|
-
minimum?: number;
|
|
29
|
-
maximum?: number;
|
|
30
|
-
exclusiveMinimum?: number | boolean;
|
|
31
|
-
exclusiveMaximum?: number | boolean;
|
|
32
|
-
multipleOf?: number;
|
|
33
|
-
anyOf?: JsonSchema[];
|
|
34
|
-
allOf?: JsonSchema[];
|
|
35
|
-
oneOf?: JsonSchema[];
|
|
36
|
-
if?: JsonSchema;
|
|
37
|
-
then?: JsonSchema;
|
|
38
|
-
else?: JsonSchema;
|
|
39
|
-
const?: Serializable;
|
|
40
|
-
enum?: Serializable[];
|
|
41
|
-
errorMessage?: {
|
|
42
|
-
[key: string]: string | undefined;
|
|
43
|
-
};
|
|
44
|
-
} & {
|
|
45
|
-
[key: string]: any;
|
|
46
|
-
};
|
|
47
|
-
export type ParserSelector = (schema: JsonSchemaObject, refs: Refs) => string;
|
|
48
|
-
export type ParserOverride = (schema: JsonSchemaObject, refs: Refs) => string | void;
|
|
49
|
-
export type ZodVersion = 3 | 4;
|
|
50
|
-
export type Options = {
|
|
51
|
-
name?: string;
|
|
52
|
-
module?: "cjs" | "esm" | "none";
|
|
53
|
-
withoutDefaults?: boolean;
|
|
54
|
-
withoutDescribes?: boolean;
|
|
55
|
-
withJsdocs?: boolean;
|
|
56
|
-
parserOverride?: ParserOverride;
|
|
57
|
-
depth?: number;
|
|
58
|
-
type?: boolean | string;
|
|
59
|
-
noImport?: boolean;
|
|
60
|
-
zodVersion?: ZodVersion;
|
|
61
|
-
};
|
|
62
|
-
export type Refs = Options & {
|
|
63
|
-
path: (string | number)[];
|
|
64
|
-
seen: Map<object | boolean, {
|
|
65
|
-
n: number;
|
|
66
|
-
r: string | undefined;
|
|
67
|
-
}>;
|
|
68
|
-
};
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
export * from "./jsonSchemaToZod.js";
|
|
2
|
-
export * from "./parsers/parseAllOf.js";
|
|
3
|
-
export * from "./parsers/parseAnyOf.js";
|
|
4
|
-
export * from "./parsers/parseArray.js";
|
|
5
|
-
export * from "./parsers/parseBoolean.js";
|
|
6
|
-
export * from "./parsers/parseConst.js";
|
|
7
|
-
export * from "./parsers/parseDefault.js";
|
|
8
|
-
export * from "./parsers/parseEnum.js";
|
|
9
|
-
export * from "./parsers/parseIfThenElse.js";
|
|
10
|
-
export * from "./parsers/parseMultipleType.js";
|
|
11
|
-
export * from "./parsers/parseNot.js";
|
|
12
|
-
export * from "./parsers/parseNull.js";
|
|
13
|
-
export * from "./parsers/parseNullable.js";
|
|
14
|
-
export * from "./parsers/parseNumber.js";
|
|
15
|
-
export * from "./parsers/parseObject.js";
|
|
16
|
-
export * from "./parsers/parseOneOf.js";
|
|
17
|
-
export * from "./parsers/parseSchema.js";
|
|
18
|
-
export * from "./parsers/parseString.js";
|
|
19
|
-
export * from "./Types.js";
|
|
20
|
-
export * from "./utils/half.js";
|
|
21
|
-
export * from "./utils/jsdocs.js";
|
|
22
|
-
export * from "./utils/omit.js";
|
|
23
|
-
export * from "./utils/withMessage.js";
|
|
24
|
-
import { jsonSchemaToZod } from "./jsonSchemaToZod.js";
|
|
25
|
-
export default jsonSchemaToZod;
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import type { JsonSchema, JsonSchemaObject, Refs, Serializable } from "../Types.js";
|
|
2
|
-
export declare const parseSchema: (schema: JsonSchema, refs?: Refs, blockMeta?: boolean) => string;
|
|
3
|
-
export declare const its: {
|
|
4
|
-
an: {
|
|
5
|
-
object: (x: JsonSchemaObject) => x is JsonSchemaObject & {
|
|
6
|
-
type: "object";
|
|
7
|
-
};
|
|
8
|
-
array: (x: JsonSchemaObject) => x is JsonSchemaObject & {
|
|
9
|
-
type: "array";
|
|
10
|
-
};
|
|
11
|
-
anyOf: (x: JsonSchemaObject) => x is JsonSchemaObject & {
|
|
12
|
-
anyOf: JsonSchema[];
|
|
13
|
-
};
|
|
14
|
-
allOf: (x: JsonSchemaObject) => x is JsonSchemaObject & {
|
|
15
|
-
allOf: JsonSchema[];
|
|
16
|
-
};
|
|
17
|
-
enum: (x: JsonSchemaObject) => x is JsonSchemaObject & {
|
|
18
|
-
enum: Serializable | Serializable[];
|
|
19
|
-
};
|
|
20
|
-
};
|
|
21
|
-
a: {
|
|
22
|
-
nullable: (x: JsonSchemaObject) => x is JsonSchemaObject & {
|
|
23
|
-
nullable: true;
|
|
24
|
-
};
|
|
25
|
-
multipleType: (x: JsonSchemaObject) => x is JsonSchemaObject & {
|
|
26
|
-
type: string[];
|
|
27
|
-
};
|
|
28
|
-
not: (x: JsonSchemaObject) => x is JsonSchemaObject & {
|
|
29
|
-
not: JsonSchema;
|
|
30
|
-
};
|
|
31
|
-
const: (x: JsonSchemaObject) => x is JsonSchemaObject & {
|
|
32
|
-
const: Serializable;
|
|
33
|
-
};
|
|
34
|
-
primitive: <T extends "string" | "number" | "integer" | "boolean" | "null">(x: JsonSchemaObject, p: T) => x is JsonSchemaObject & {
|
|
35
|
-
type: T;
|
|
36
|
-
};
|
|
37
|
-
conditional: (x: JsonSchemaObject) => x is JsonSchemaObject & {
|
|
38
|
-
if: JsonSchema;
|
|
39
|
-
then: JsonSchema;
|
|
40
|
-
else: JsonSchema;
|
|
41
|
-
};
|
|
42
|
-
oneOf: (x: JsonSchemaObject) => x is JsonSchemaObject & {
|
|
43
|
-
oneOf: JsonSchema[];
|
|
44
|
-
};
|
|
45
|
-
};
|
|
46
|
-
};
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
export type Param = {
|
|
2
|
-
shorthand?: string;
|
|
3
|
-
description?: string;
|
|
4
|
-
required?: boolean | string | undefined;
|
|
5
|
-
} & ({
|
|
6
|
-
value?: "boolean";
|
|
7
|
-
} | {
|
|
8
|
-
value: "number";
|
|
9
|
-
} | {
|
|
10
|
-
value: "string";
|
|
11
|
-
} | {
|
|
12
|
-
value: {
|
|
13
|
-
[key: number]: string;
|
|
14
|
-
};
|
|
15
|
-
});
|
|
16
|
-
export type Params = {
|
|
17
|
-
[name: string]: Param;
|
|
18
|
-
};
|
|
19
|
-
type InferReturnType<T extends Params> = {
|
|
20
|
-
[name in keyof T]: (T[name]["value"] extends "number" ? number : T[name]["value"] extends "string" ? string : T[name]["value"] extends {
|
|
21
|
-
[key: number]: string;
|
|
22
|
-
} ? T[name]["value"][number] : T[name]["value"] extends never ? boolean : boolean) | (T[name]["required"] extends string | true ? never : undefined);
|
|
23
|
-
};
|
|
24
|
-
export declare function parseArgs<T extends Params>(params: T, args: string[], help?: boolean | string): InferReturnType<T>;
|
|
25
|
-
export declare function parseOrReadJSON(jsonOrPath: string): unknown;
|
|
26
|
-
export declare function readPipe(): Promise<string>;
|
|
27
|
-
export declare function printParams(params: Record<string, Param>): void;
|
|
28
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const half: <T>(arr: T[]) => [T[], T[]];
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const omit: <T extends object, K extends keyof T>(obj: T, ...keys: K[]) => Omit<T, K>;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { JsonSchemaObject } from "../Types.js";
|
|
2
|
-
type Opener = string;
|
|
3
|
-
type MessagePrefix = string;
|
|
4
|
-
type Closer = string;
|
|
5
|
-
type Builder = [Opener, Closer] | [Opener, MessagePrefix, Closer];
|
|
6
|
-
export declare function withMessage(schema: JsonSchemaObject, key: string, get: (props: {
|
|
7
|
-
value: unknown;
|
|
8
|
-
json: string;
|
|
9
|
-
}) => Builder | void): string;
|
|
10
|
-
export {};
|