Skip to content
IC Reactor

fromZodSchema

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.

T

ZodSyncSchema

A Zod schema to validate against: anything with zod’s safeParse, or with its safeParseAsync for { async: true }

FromZodSchemaOptions & object

Pass { async: true } to parse with safeParseAsync

Validator<T[]>

A Validator function compatible with DisplayReactor

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 })

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.

T

ZodAsyncSchema

A Zod schema to validate against: anything with zod’s safeParse, or with its safeParseAsync for { async: true }

FromZodSchemaOptions & object

Pass { async: true } to parse with safeParseAsync

Validator<T[]>

A Validator function compatible with DisplayReactor

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 })

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.

T

ZodSyncSchema & ZodAsyncSchema

A Zod schema to validate against: anything with zod’s safeParse, or with its safeParseAsync for { async: true }

FromZodSchemaOptions

Pass { async: true } to parse with safeParseAsync

Validator<T[]>

A Validator function compatible with DisplayReactor

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 })