fromZodSchema
Call Signature
Section titled “Call Signature”fromZodSchema<
T>(schema,options?):Validator<T[]>
Defined in: core/src/utils/zod.ts:108
Create a validator from a Zod schema. This is a utility function to easily integrate Zod schemas as validators.
The schema checks the method’s first argument. A schema with an async
refinement or transform needs { async: true }, and gives an async
validator: see FromZodSchemaOptions.async.
Type Parameters
Section titled “Type Parameters”T
Parameters
Section titled “Parameters”schema
Section titled “schema”ZodSyncSchema
A Zod schema to validate against: anything with zod’s
safeParse, or with its safeParseAsync for { async: true }
options?
Section titled “options?”FromZodSchemaOptions & object
Pass { async: true } to parse with safeParseAsync
Returns
Section titled “Returns”Validator<T[]>
A Validator function compatible with DisplayReactor
Examples
Section titled “Examples”import { z } from "zod"import { fromZodSchema } from "@ic-reactor/core"
const transferSchema = z.object({ to: z.string().min(1, "Recipient is required"), amount: z.string().regex(/^\d+$/, "Must be a valid number"),})
reactor.registerValidator("transfer", fromZodSchema(transferSchema))An async refinement
const recipientSchema = z.object({ to: z.string().refine(async (to) => !(await isBlocked(to)), "Address is blocked"),})
reactor.registerValidator( "transfer", fromZodSchema(recipientSchema, { async: true }))await reactor.callMethodWithValidation({ functionName: "transfer", args })Call Signature
Section titled “Call Signature”fromZodSchema<
T>(schema,options):Validator<T[]>
Defined in: core/src/utils/zod.ts:112
Create a validator from a Zod schema. This is a utility function to easily integrate Zod schemas as validators.
The schema checks the method’s first argument. A schema with an async
refinement or transform needs { async: true }, and gives an async
validator: see FromZodSchemaOptions.async.
Type Parameters
Section titled “Type Parameters”T
Parameters
Section titled “Parameters”schema
Section titled “schema”ZodAsyncSchema
A Zod schema to validate against: anything with zod’s
safeParse, or with its safeParseAsync for { async: true }
options
Section titled “options”FromZodSchemaOptions & object
Pass { async: true } to parse with safeParseAsync
Returns
Section titled “Returns”Validator<T[]>
A Validator function compatible with DisplayReactor
Examples
Section titled “Examples”import { z } from "zod"import { fromZodSchema } from "@ic-reactor/core"
const transferSchema = z.object({ to: z.string().min(1, "Recipient is required"), amount: z.string().regex(/^\d+$/, "Must be a valid number"),})
reactor.registerValidator("transfer", fromZodSchema(transferSchema))An async refinement
const recipientSchema = z.object({ to: z.string().refine(async (to) => !(await isBlocked(to)), "Address is blocked"),})
reactor.registerValidator( "transfer", fromZodSchema(recipientSchema, { async: true }))await reactor.callMethodWithValidation({ functionName: "transfer", args })Call Signature
Section titled “Call Signature”fromZodSchema<
T>(schema,options?):Validator<T[]>
Defined in: core/src/utils/zod.ts:116
Create a validator from a Zod schema. This is a utility function to easily integrate Zod schemas as validators.
The schema checks the method’s first argument. A schema with an async
refinement or transform needs { async: true }, and gives an async
validator: see FromZodSchemaOptions.async.
Type Parameters
Section titled “Type Parameters”T
Parameters
Section titled “Parameters”schema
Section titled “schema”ZodSyncSchema & ZodAsyncSchema
A Zod schema to validate against: anything with zod’s
safeParse, or with its safeParseAsync for { async: true }
options?
Section titled “options?”Pass { async: true } to parse with safeParseAsync
Returns
Section titled “Returns”Validator<T[]>
A Validator function compatible with DisplayReactor
Examples
Section titled “Examples”import { z } from "zod"import { fromZodSchema } from "@ic-reactor/core"
const transferSchema = z.object({ to: z.string().min(1, "Recipient is required"), amount: z.string().regex(/^\d+$/, "Must be a valid number"),})
reactor.registerValidator("transfer", fromZodSchema(transferSchema))An async refinement
const recipientSchema = z.object({ to: z.string().refine(async (to) => !(await isBlocked(to)), "Address is blocked"),})
reactor.registerValidator( "transfer", fromZodSchema(recipientSchema, { async: true }))await reactor.callMethodWithValidation({ functionName: "transfer", args })