import { z } from 'zod'; /// ================================ INPUT CONFIG SCHEMAS ================================ \\\ // Different regular expressions used to validate formats like // general string interpolation, step names, contract artifacts and packages const stepRegex = RegExp(/^[\w-]+\.[\w-]+$/, 'i'); export const runSchema = z .object({ /** The javascript (or typescript) file to load */ exec: z.string().describe('The javascript (or typescript) file to load'), /** The function to call in this file */ func: z.string().describe('The function to call in this file'), /** * An array of files and directories that this script depends on. * The cache of the cannonfile's build is recreated when these files change. */ modified: z .array(z.string()) .nonempty() .describe( "An array of files and directories that this script depends on. The cache of the cannonfile's build is recreated when these files change." ), /** * The artifacts that are generated by this script. Should be in the format (example): `contracts.FooBar` */ outputs: z .array(z.string()) .describe('The artifacts that are generated by this script. Should be in the format (example): `contracts.FooBar`'), }) .merge( z .object({ /** Arguments passed to the function (after the ChainBuilder object) */ args: z.array(z.string()).describe('Arguments passed to the function (after the ChainBuilder object)'), /** Environment variables to be set on the script */ env: z.array(z.string()).describe('Environment variables to be set on the script'), /** List of operations that this action depends on */ depends: z .array( z.string().refine( (val) => Boolean(val.match(stepRegex)), (val) => ({ message: `Bad format for "${val}". Must reference a previous operation, example: 'contract.Storage'`, }) ) ) .describe( 'List of operations that this operation depends on, which Cannon will execute first. If unspecified, Cannon automatically detects dependencies.' ), }) .partial() );