|
1 | 1 | import express from "express"; |
2 | | -import z from "zod"; |
| 2 | +import z from "zod/v4"; |
3 | 3 | import { availableGuildPlugins } from "../plugins/availablePlugins.js"; |
4 | 4 | import { ZeppelinGuildPluginInfo } from "../types.js"; |
5 | 5 | import { indentLines } from "../utils.js"; |
6 | 6 | import { notFound } from "./responses.js"; |
7 | 7 |
|
8 | | -function isZodObject(schema: z.ZodTypeAny): schema is z.ZodObject<any> { |
9 | | - return schema._def.typeName === "ZodObject"; |
| 8 | +function isZodObject(schema: z.ZodType): schema is z.ZodObject<any> { |
| 9 | + return schema.def.type === "object"; |
10 | 10 | } |
11 | 11 |
|
12 | | -function isZodRecord(schema: z.ZodTypeAny): schema is z.ZodRecord<any> { |
13 | | - return schema._def.typeName === "ZodRecord"; |
| 12 | +function isZodRecord(schema: z.ZodType): schema is z.ZodRecord<any> { |
| 13 | + return schema.def.type === "record"; |
14 | 14 | } |
15 | 15 |
|
16 | | -function isZodEffects(schema: z.ZodTypeAny): schema is z.ZodEffects<any, any> { |
17 | | - return schema._def.typeName === "ZodEffects"; |
| 16 | +function isZodOptional(schema: z.ZodType): schema is z.ZodOptional<any> { |
| 17 | + return schema.def.type === "optional"; |
18 | 18 | } |
19 | 19 |
|
20 | | -function isZodOptional(schema: z.ZodTypeAny): schema is z.ZodOptional<any> { |
21 | | - return schema._def.typeName === "ZodOptional"; |
| 20 | +function isZodArray(schema: z.ZodType): schema is z.ZodArray<any> { |
| 21 | + return schema.def.type === "array"; |
22 | 22 | } |
23 | 23 |
|
24 | | -function isZodArray(schema: z.ZodTypeAny): schema is z.ZodArray<any> { |
25 | | - return schema._def.typeName === "ZodArray"; |
| 24 | +function isZodUnion(schema: z.ZodType): schema is z.ZodUnion<any> { |
| 25 | + return schema.def.type === "union"; |
26 | 26 | } |
27 | 27 |
|
28 | | -function isZodUnion(schema: z.ZodTypeAny): schema is z.ZodUnion<any> { |
29 | | - return schema._def.typeName === "ZodUnion"; |
| 28 | +function isZodNullable(schema: z.ZodType): schema is z.ZodNullable<any> { |
| 29 | + return schema.def.type === "nullable"; |
30 | 30 | } |
31 | 31 |
|
32 | | -function isZodNullable(schema: z.ZodTypeAny): schema is z.ZodNullable<any> { |
33 | | - return schema._def.typeName === "ZodNullable"; |
| 32 | +function isZodDefault(schema: z.ZodType): schema is z.ZodDefault<any> { |
| 33 | + return schema.def.type === "default"; |
34 | 34 | } |
35 | 35 |
|
36 | | -function isZodDefault(schema: z.ZodTypeAny): schema is z.ZodDefault<any> { |
37 | | - return schema._def.typeName === "ZodDefault"; |
| 36 | +function isZodLiteral(schema: z.ZodType): schema is z.ZodLiteral<any> { |
| 37 | + return schema.def.type === "literal"; |
38 | 38 | } |
39 | 39 |
|
40 | | -function isZodLiteral(schema: z.ZodTypeAny): schema is z.ZodLiteral<any> { |
41 | | - return schema._def.typeName === "ZodLiteral"; |
| 40 | +function isZodIntersection(schema: z.ZodType): schema is z.ZodIntersection<any, any> { |
| 41 | + return schema.def.type === "intersection"; |
42 | 42 | } |
43 | 43 |
|
44 | | -function isZodIntersection(schema: z.ZodTypeAny): schema is z.ZodIntersection<any, any> { |
45 | | - return schema._def.typeName === "ZodIntersection"; |
46 | | -} |
47 | | - |
48 | | -function formatZodConfigSchema(schema: z.ZodTypeAny) { |
| 44 | +function formatZodConfigSchema(schema: z.ZodType) { |
49 | 45 | if (isZodObject(schema)) { |
50 | 46 | return ( |
51 | 47 | `{\n` + |
52 | 48 | Object.entries(schema._def.shape()) |
53 | | - .map(([k, value]) => indentLines(`${k}: ${formatZodConfigSchema(value as z.ZodTypeAny)}`, 2)) |
| 49 | + .map(([k, value]) => indentLines(`${k}: ${formatZodConfigSchema(value as z.ZodType)}`, 2)) |
54 | 50 | .join("\n") + |
55 | 51 | "\n}" |
56 | 52 | ); |
57 | 53 | } |
58 | 54 | if (isZodRecord(schema)) { |
59 | | - return "{\n" + indentLines(`[string]: ${formatZodConfigSchema(schema._def.valueType)}`, 2) + "\n}"; |
60 | | - } |
61 | | - if (isZodEffects(schema)) { |
62 | | - return formatZodConfigSchema(schema._def.schema); |
| 55 | + return "{\n" + indentLines(`[string]: ${formatZodConfigSchema(schema.valueType as z.ZodType)}`, 2) + "\n}"; |
63 | 56 | } |
64 | 57 | if (isZodOptional(schema)) { |
65 | | - return `Optional<${formatZodConfigSchema(schema._def.innerType)}>`; |
| 58 | + return `Optional<${formatZodConfigSchema(schema.def.innerType)}>`; |
66 | 59 | } |
67 | 60 | if (isZodArray(schema)) { |
68 | | - return `Array<${formatZodConfigSchema(schema._def.type)}>`; |
| 61 | + return `Array<${formatZodConfigSchema(schema.def.element)}>`; |
69 | 62 | } |
70 | 63 | if (isZodUnion(schema)) { |
71 | 64 | return schema._def.options.map((t) => formatZodConfigSchema(t)).join(" | "); |
72 | 65 | } |
73 | 66 | if (isZodNullable(schema)) { |
74 | | - return `Nullable<${formatZodConfigSchema(schema._def.innerType)}>`; |
| 67 | + return `Nullable<${formatZodConfigSchema(schema.def.innerType)}>`; |
75 | 68 | } |
76 | 69 | if (isZodDefault(schema)) { |
77 | | - return formatZodConfigSchema(schema._def.innerType); |
| 70 | + return formatZodConfigSchema(schema.def.innerType); |
78 | 71 | } |
79 | 72 | if (isZodLiteral(schema)) { |
80 | | - return schema._def.value; |
| 73 | + return schema.def.values; |
81 | 74 | } |
82 | 75 | if (isZodIntersection(schema)) { |
83 | | - return [formatZodConfigSchema(schema._def.left), formatZodConfigSchema(schema._def.right)].join(" & "); |
| 76 | + return [formatZodConfigSchema(schema.def.left as z.ZodType), formatZodConfigSchema(schema.def.right as z.ZodType)].join(" & "); |
84 | 77 | } |
85 | | - if (schema._def.typeName === "ZodString") { |
| 78 | + if (schema.def.type === "string") { |
86 | 79 | return "string"; |
87 | 80 | } |
88 | | - if (schema._def.typeName === "ZodNumber") { |
| 81 | + if (schema.def.type === "number") { |
89 | 82 | return "number"; |
90 | 83 | } |
91 | | - if (schema._def.typeName === "ZodBoolean") { |
| 84 | + if (schema.def.type === "boolean") { |
92 | 85 | return "boolean"; |
93 | 86 | } |
94 | | - if (schema._def.typeName === "ZodNever") { |
| 87 | + if (schema.def.type === "never") { |
95 | 88 | return "never"; |
96 | 89 | } |
97 | 90 | return "unknown"; |
|
0 commit comments