MCPcopy Create free account
hub / github.com/subquery/subql / zodToFlags

Function zodToFlags

packages/cli/src/adapters/utils.ts:103–144  ·  view source on GitHub ↗
(schema: ZodObject<Shape>)

Source from the content-addressed store, hash-verified

101
102// Runtime impl
103export function zodToFlags<Shape extends Record<string, ZodTypeAny>>(schema: ZodObject<Shape>): FlagsFromSchema<Shape> {
104 const flags: Record<string, Flag<any>> = {};
105
106 for (const [key, def] of Object.entries(schema.shape)) {
107 const description = def.description ?? '';
108
109 const {array, default: defaultValue, optional, type} = unwrap(def);
110
111 if (type instanceof z.ZodString) {
112 flags[key] = Flags.string({
113 description,
114 required: !optional,
115 default: defaultValue,
116 multiple: array as any, // Gets around a type issue
117 });
118 } else if (type instanceof z.ZodNumber) {
119 flags[key] = Flags.integer({
120 description,
121 required: !optional,
122 default: defaultValue,
123 multiple: array as any, // Gets around a type issue
124 });
125 } else if (type instanceof z.ZodBoolean) {
126 flags[key] = Flags.boolean({
127 description,
128 default: defaultValue,
129 });
130 } else if (type instanceof z.ZodEnum) {
131 flags[key] = Flags.string({
132 description,
133 required: !optional,
134 default: defaultValue,
135 options: type.options,
136 multiple: array as any, // Gets around a type issue
137 });
138 } else {
139 throw new Error(`Unsupported Zod type for flag: ${key}`);
140 }
141 }
142
143 return flags as FlagsFromSchema<Shape>;
144}
145
146export function zodToArgs<Shape extends Record<string, ZodTypeAny>>(schema: ZodObject<Shape>): ArgsFromSchema<Shape> {
147 const args: Record<string, Arg<any>> = {};

Callers 15

BuildManifestClass · 0.90
InitClass · 0.90
PublishClass · 0.90
BuildClass · 0.90
MigrateSubgraphClass · 0.90
AddDeploymentBoostClass · 0.90
ConnectWalletClass · 0.90
SwapDeploymentBoostClass · 0.90
RemoveApiKeyClass · 0.90
ListAccountBoostsClass · 0.90
CreateNetworkApiKeyClass · 0.90

Calls 1

unwrapFunction · 0.85

Tested by

no test coverage detected