import type { StandardSchemaV1 } from "@standard-schema/spec"; import { ClientError } from "../util/index.js"; import { ValidationError } from "./error.js"; import type { Extractor } from "./index.js"; export declare class MissingJsonContentTypeError extends ClientError { constructor(); } export declare class MalformedJsonError extends ClientError { constructor(reason: string); } export declare class InvalidJsonError extends ValidationError { constructor(issues: readonly StandardSchemaV1.Issue[]); } /** * Extractor that will get JSON from the body and parse it. * * The schema can be anything implementing the [Standard Schema](https://standardschema.dev/). * * If the request is lacking a JSON content type, it will reject the request * with a `415 Unsupported Media Type` response. * * If the body is malformed, it will reject the request with a `400 Bad Request` * response. * * If the JSON cannot be parsed, it will reject the request with a * `422 Unprocessable Content` response. * * @example * ```ts * import { json } from "@taxum/core/extract"; * import { m, Router } from "@taxum/core/routing"; * import { z } from "zod"; * * const bodySchema = z.object({ * foo: z.string(), * }); * * const handler = handler([json(bodySchema)], (body) => { * const foo = body.foo; * * // ... * }); * * const router = new Router() * .route("/users", m.post(handler)); * ``` * * @throws {@link MissingJsonContentTypeError} if the request is lacking a JSON content type. * @throws {@link MalformedJsonError} if the body is malformed. * @throws {@link InvalidJsonError} if the JSON cannot be parsed. */ export declare const json: (schema: T) => Extractor>;