input.parse
Read JSON from stdin and validate it against a Zod schema. Returns the validated and typed object.
Performs three steps internally:
- Reads all of stdin via
input.read() - Parses the raw string as JSON
- Validates the parsed object against the provided Zod schema
Throws StdinParseError if any step fails.
Parameters
| Parameter | Type | Description |
|---|---|---|
schema | ZodType<T> | A Zod schema to validate the parsed JSON against |
Returns
Promise<T>
Example
import { z } from "zod";
import { input } from "@hmcs/sdk/commands";
const data = await input.parse(
z.object({
entity: z.number(),
text: z.union([z.string(), z.array(z.string())]),
speaker: z.number().default(0),
}),
);