11import express from "express" ;
2- import z from "zod" ;
3- import { guildPlugins } from "../plugins/availablePlugins.js" ;
4- import { guildPluginInfo } from "../plugins/pluginInfo .js" ;
2+ import z from "zod/v4 " ;
3+ import { availableGuildPlugins } from "../plugins/availablePlugins.js" ;
4+ import { ZeppelinGuildPluginInfo } from "../types .js" ;
55import { indentLines } from "../utils.js" ;
66import { notFound } from "./responses.js" ;
7+ import { $ZodPipeDef } from "zod/v4/core" ;
78
8- function isZodObject ( schema : z . ZodTypeAny ) : schema is z . ZodObject < any > {
9- return schema . _def . typeName === "ZodObject " ;
9+ function isZodObject ( schema : z . ZodType ) : schema is z . ZodObject < any > {
10+ return schema . def . type === "object " ;
1011}
1112
12- function isZodRecord ( schema : z . ZodTypeAny ) : schema is z . ZodRecord < any > {
13- return schema . _def . typeName === "ZodRecord " ;
13+ function isZodRecord ( schema : z . ZodType ) : schema is z . ZodRecord < any > {
14+ return schema . def . type === "record " ;
1415}
1516
16- function isZodEffects ( schema : z . ZodTypeAny ) : schema is z . ZodEffects < any , any > {
17- return schema . _def . typeName === "ZodEffects " ;
17+ function isZodOptional ( schema : z . ZodType ) : schema is z . ZodOptional < any > {
18+ return schema . def . type === "optional " ;
1819}
1920
20- function isZodOptional ( schema : z . ZodTypeAny ) : schema is z . ZodOptional < any > {
21- return schema . _def . typeName === "ZodOptional " ;
21+ function isZodArray ( schema : z . ZodType ) : schema is z . ZodArray < any > {
22+ return schema . def . type === "array " ;
2223}
2324
24- function isZodArray ( schema : z . ZodTypeAny ) : schema is z . ZodArray < any > {
25- return schema . _def . typeName === "ZodArray " ;
25+ function isZodUnion ( schema : z . ZodType ) : schema is z . ZodUnion < any > {
26+ return schema . def . type === "union " ;
2627}
2728
28- function isZodUnion ( schema : z . ZodTypeAny ) : schema is z . ZodUnion < any > {
29- return schema . _def . typeName === "ZodUnion " ;
29+ function isZodNullable ( schema : z . ZodType ) : schema is z . ZodNullable < any > {
30+ return schema . def . type === "nullable " ;
3031}
3132
32- function isZodNullable ( schema : z . ZodTypeAny ) : schema is z . ZodNullable < any > {
33- return schema . _def . typeName === "ZodNullable " ;
33+ function isZodDefault ( schema : z . ZodType ) : schema is z . ZodDefault < any > {
34+ return schema . def . type === "default " ;
3435}
3536
36- function isZodDefault ( schema : z . ZodTypeAny ) : schema is z . ZodDefault < any > {
37- return schema . _def . typeName === "ZodDefault " ;
37+ function isZodLiteral ( schema : z . ZodType ) : schema is z . ZodLiteral < any > {
38+ return schema . def . type === "literal " ;
3839}
3940
40- function isZodLiteral ( schema : z . ZodTypeAny ) : schema is z . ZodLiteral < any > {
41- return schema . _def . typeName === "ZodLiteral " ;
41+ function isZodIntersection ( schema : z . ZodType ) : schema is z . ZodIntersection < any , any > {
42+ return schema . def . type === "intersection " ;
4243}
4344
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 ) {
45+ function formatZodConfigSchema ( schema : z . ZodType ) {
4946 if ( isZodObject ( schema ) ) {
5047 return (
5148 `{\n` +
52- Object . entries ( schema . _def . shape ( ) )
53- . map ( ( [ k , value ] ) => indentLines ( `${ k } : ${ formatZodConfigSchema ( value as z . ZodTypeAny ) } ` , 2 ) )
49+ Object . entries ( schema . def . shape )
50+ . map ( ( [ k , value ] ) => indentLines ( `${ k } : ${ formatZodConfigSchema ( value as z . ZodType ) } ` , 2 ) )
5451 . join ( "\n" ) +
5552 "\n}"
5653 ) ;
5754 }
5855 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 ) ;
56+ return "{\n" + indentLines ( `[string]: ${ formatZodConfigSchema ( schema . valueType as z . ZodType ) } ` , 2 ) + "\n}" ;
6357 }
6458 if ( isZodOptional ( schema ) ) {
65- return `Optional<${ formatZodConfigSchema ( schema . _def . innerType ) } >` ;
59+ return `Optional<${ formatZodConfigSchema ( schema . def . innerType ) } >` ;
6660 }
6761 if ( isZodArray ( schema ) ) {
68- return `Array<${ formatZodConfigSchema ( schema . _def . type ) } >` ;
62+ return `Array<${ formatZodConfigSchema ( schema . def . element ) } >` ;
6963 }
7064 if ( isZodUnion ( schema ) ) {
71- return schema . _def . options . map ( ( t ) => formatZodConfigSchema ( t ) ) . join ( " | " ) ;
65+ return schema . def . options . map ( ( t ) => formatZodConfigSchema ( t ) ) . join ( " | " ) ;
7266 }
7367 if ( isZodNullable ( schema ) ) {
74- return `Nullable<${ formatZodConfigSchema ( schema . _def . innerType ) } >` ;
68+ return `Nullable<${ formatZodConfigSchema ( schema . def . innerType ) } >` ;
7569 }
7670 if ( isZodDefault ( schema ) ) {
77- return formatZodConfigSchema ( schema . _def . innerType ) ;
71+ return formatZodConfigSchema ( schema . def . innerType ) ;
7872 }
7973 if ( isZodLiteral ( schema ) ) {
80- return schema . _def . value ;
74+ return schema . def . values ;
8175 }
8276 if ( isZodIntersection ( schema ) ) {
83- return [ formatZodConfigSchema ( schema . _def . left ) , formatZodConfigSchema ( schema . _def . right ) ] . join ( " & " ) ;
77+ return [
78+ formatZodConfigSchema ( schema . def . left as z . ZodType ) ,
79+ formatZodConfigSchema ( schema . def . right as z . ZodType ) ,
80+ ] . join ( " & " ) ;
8481 }
85- if ( schema . _def . typeName === "ZodString " ) {
82+ if ( schema . def . type === "string " ) {
8683 return "string" ;
8784 }
88- if ( schema . _def . typeName === "ZodNumber " ) {
85+ if ( schema . def . type === "number " ) {
8986 return "number" ;
9087 }
91- if ( schema . _def . typeName === "ZodBoolean " ) {
88+ if ( schema . def . type === "boolean " ) {
9289 return "boolean" ;
9390 }
94- if ( schema . _def . typeName === "ZodNever " ) {
91+ if ( schema . def . type === "never " ) {
9592 return "never" ;
9693 }
94+ if ( schema . def . type === "pipe" ) {
95+ return formatZodConfigSchema ( ( schema . def as $ZodPipeDef ) . in as z . ZodType ) ;
96+ }
9797 return "unknown" ;
9898}
9999
100+ const availableGuildPluginsByName = availableGuildPlugins . reduce < Record < string , ZeppelinGuildPluginInfo > > (
101+ ( map , obj ) => {
102+ map [ obj . plugin . name ] = obj ;
103+ return map ;
104+ } ,
105+ { } ,
106+ ) ;
107+
100108export function initDocs ( router : express . Router ) {
101- const docsPluginNames = Object . keys ( guildPluginInfo ) . filter ( ( k ) => guildPluginInfo [ k ] . showInDocs ) ;
109+ const docsPlugins = availableGuildPlugins . filter ( ( obj ) => obj . docs . type !== "internal" ) ;
102110
103111 router . get ( "/docs/plugins" , ( req : express . Request , res : express . Response ) => {
104112 res . json (
105- docsPluginNames . map ( ( pluginName ) => {
106- const info = guildPluginInfo [ pluginName ] ;
107- const thinInfo = info ? { prettyName : info . prettyName , legacy : info . legacy ?? false } : { } ;
108- return {
109- name : pluginName ,
110- info : thinInfo ,
111- } ;
112- } ) ,
113+ docsPlugins . map ( ( obj ) => ( {
114+ name : obj . plugin . name ,
115+ info : {
116+ prettyName : obj . docs . prettyName ,
117+ type : obj . docs . type ,
118+ } ,
119+ } ) ) ,
113120 ) ;
114121 } ) ;
115122
116123 router . get ( "/docs/plugins/:pluginName" , ( req : express . Request , res : express . Response ) => {
117- const name = req . params . pluginName ;
118- const baseInfo = guildPluginInfo [ name ] ;
119- if ( ! baseInfo ) {
124+ const pluginInfo = availableGuildPluginsByName [ req . params . pluginName ] ;
125+ if ( ! pluginInfo ) {
120126 return notFound ( res ) ;
121127 }
122128
123- const plugin = guildPlugins . find ( ( p ) => p . name === name ) ! ;
124- const { configSchema, ...info } = baseInfo ;
129+ const { configSchema, ...info } = pluginInfo . docs ;
125130 const formattedConfigSchema = formatZodConfigSchema ( configSchema ) ;
126131
127- const messageCommands = ( plugin . messageCommands || [ ] ) . map ( ( cmd ) => ( {
132+ const messageCommands = ( pluginInfo . plugin . messageCommands || [ ] ) . map ( ( cmd ) => ( {
128133 trigger : cmd . trigger ,
129134 permission : cmd . permission ,
130135 signature : cmd . signature ,
@@ -133,10 +138,10 @@ export function initDocs(router: express.Router) {
133138 config : cmd . config ,
134139 } ) ) ;
135140
136- const defaultOptions = plugin . defaultOptions || { } ;
141+ const defaultOptions = pluginInfo . docs . configSchema . safeParse ( { } ) . data ?? { } ;
137142
138143 res . json ( {
139- name,
144+ name : pluginInfo . plugin . name ,
140145 info,
141146 configSchema : formattedConfigSchema ,
142147 defaultOptions,
0 commit comments