import { C as MiddlewareInput, f as ContextFromMiddlewareInput } from "../../router-Cwb7ak0J.mjs"; import { n as RoutekitResponse } from "../../core-CzUCxvGk.mjs"; import { d as ProblemResponse, i as ValidationProblemInit, l as ProblemIssue } from "../../responses-B379Ep9Y.mjs"; import { i as ValibotRouteBuilder, l as ValibotValidationError, o as ValibotRouteHelperDefaults } from "../../valibot-2MepBTEi.mjs"; import * as v from "valibot"; //#region src/router/response/formats/problem/valibot.d.ts type AnySchema = v.BaseSchema; type StringSchema = v.BaseSchema; type ProblemSchemaResult = v.BaseSchema, ProblemResponse & string>, v.InferIssue>; declare function createSuccessSchema(dataSchema: DataSchema): v.ObjectSchema<{ readonly success: v.LiteralSchema; readonly data: DataSchema; }, undefined>; declare function createSuccessSchemaWithMeta(dataSchema: DataSchema, metaSchema: MetaSchema): v.ObjectSchema<{ readonly success: v.LiteralSchema; readonly data: DataSchema; readonly meta: v.OptionalSchema; }, undefined>; type SuccessSchemaResult = MetaSchema extends AnySchema ? ReturnType> : ReturnType>; /** * Create a Valibot schema for standard response issues. * * @example * ```ts * const schema = problemIssueSchema(v.picklist(['required', 'invalid_type'])) * ``` * * @param codeSchema - Optional issue code schema. Defaults to `v.string()`. * @returns Valibot object schema for [`ProblemIssue`]{@link ProblemIssue}. * @typeParam CodeSchema - Valibot schema used for issue codes. */ declare function problemIssueSchema(codeSchema?: CodeSchema): v.ObjectSchema<{ readonly code: CodeSchema; readonly message: v.StringSchema; readonly path: v.OptionalSchema, v.NumberSchema], undefined>, undefined>, v.ReadonlyAction<(string | number)[]>]>, undefined>; readonly expected: v.OptionalSchema, undefined>; readonly received: v.OptionalSchema, undefined>; }, undefined>; /** * Create a Valibot schema for standard primary error metadata. * * @example * ```ts * const schema = problemErrorSchema(v.picklist(['not_found', 'validation_failed'])) * ``` * * @param codeSchema - Optional primary error code schema. Defaults to `v.string()`. * @returns Valibot object schema for problem error metadata. * @typeParam CodeSchema - Valibot schema used for primary error codes. */ declare function problemErrorSchema(codeSchema?: CodeSchema): v.ObjectSchema<{ readonly code: CodeSchema; readonly message: v.StringSchema; readonly title: v.OptionalSchema, undefined>; }, undefined>; /** * Create a Valibot schema for successful standard response envelopes. * * @example * ```ts * const schema = okSchema(v.object({ id: v.string() })) * ``` * * @param dataSchema - Valibot schema for the response payload. * @param metaSchema - Optional Valibot schema for response metadata. * @returns Valibot object schema for a successful standard response. * @typeParam DataSchema - Valibot schema used for the response payload. * @typeParam MetaSchema - Optional Valibot schema used for response metadata. */ declare function okSchema(dataSchema: DataSchema, metaSchema?: MetaSchema): SuccessSchemaResult; /** * Create a Valibot schema for standard problem response envelopes. * * @example * ```ts * const schema = problemSchema({ * code: v.picklist(['not_found', 'validation_failed']), * }) * ``` * * @param options - Optional primary error and issue schemas. * @returns Valibot object schema for a standard problem response. * @typeParam CodeSchema - Valibot schema used for primary error codes. * @typeParam IssueSchema - Valibot schema used for response issues. */ declare function problemSchema>(options?: { code?: CodeSchema; issue?: IssueSchema; }): ProblemSchemaResult; readonly error: v.ObjectSchema<{ readonly code: CodeSchema; readonly message: v.StringSchema; readonly title: v.OptionalSchema, undefined>; }, undefined>; readonly issues: v.OptionalSchema, v.ReadonlyAction[]>]>, undefined>; }, undefined>>; /** * Create a Valibot schema for the full standard response union. * * @example * ```ts * const schema = standardResponseSchema(v.object({ id: v.string() }), { * code: v.picklist(['not_found']), * }) * ``` * * @param dataSchema - Valibot schema for the successful response payload. * @param options - Optional metadata, primary error, and issue schemas. * @returns Valibot union schema for successful and problem responses. * @typeParam DataSchema - Valibot schema used for the response payload. * @typeParam MetaSchema - Optional Valibot schema used for response metadata. * @typeParam CodeSchema - Valibot schema used for primary error codes. * @typeParam IssueSchema - Valibot schema used for response issues. */ declare function standardResponseSchema>(dataSchema: DataSchema, options?: { meta?: MetaSchema; code?: CodeSchema; issue?: IssueSchema; }): v.UnionSchema<[v.ObjectSchema<{ readonly success: v.LiteralSchema; readonly data: DataSchema; }, undefined> | SuccessSchemaResult, ProblemSchemaResult; readonly error: v.ObjectSchema<{ readonly code: CodeSchema; readonly message: v.StringSchema; readonly title: v.OptionalSchema, undefined>; }, undefined>; readonly issues: v.OptionalSchema, v.ReadonlyAction[]>]>, undefined>; }, undefined>>], undefined>; /** * Convert a Valibot issue into a standard response issue. * * @example * ```ts * const parsed = v.safeParse(v.object({ id: v.string() }), { id: 123 }) * if (!parsed.success) { * const issue = issueFromValibotIssue(parsed.issues[0]) * } * ``` * * @param issue - Valibot issue to convert. * @returns Standard response issue. */ declare function issueFromValibotIssue(issue: v.BaseIssue): ProblemIssue; /** * Convert Valibot issues into standard response issues. * * @example * ```ts * const parsed = v.safeParse(v.object({ id: v.string() }), { id: 123 }) * if (!parsed.success) { * const issues = issuesFromValibotIssues(parsed.issues) * } * ``` * * @param issues - Valibot issues to convert. * @returns Standard response issues. */ declare function issuesFromValibotIssues(issues: readonly v.BaseIssue[]): ProblemIssue[]; /** * Create a validation problem response from Valibot issues. * * @example * ```ts * const route = createValibotRouteBuilder() * route({ * onRequestValidationError: (_component, issues) => validationProblemFromValibotIssues(issues), * handler: () => ok({ saved: true }), * }) * ``` * * @param issues - Valibot issues to convert and include in the response. * @param init - Optional problem response overrides and headers. * @returns Routekit logical response with a validation [`ProblemResponse`]{@link ProblemResponse}. * @typeParam Code - Machine-readable primary error code. */ declare function validationProblemFromValibotIssues(issues: readonly v.BaseIssue[], init?: ValidationProblemInit): RoutekitResponse>; /** * A Valibot validation error handler that maps request validation errors to problem-compliant responses. * * This handler returns `422 Unprocessable Content` with error code `validation_failed:body` for request body * validation failures, and `400 Bad Request` with `validation_failed:query` or `validation_failed:path` for * query and path parameter validation failures respectively. * * @example * ```ts * const route = createValibotRouteBuilder({ * onRequestValidationError: problemValidationErrorHandler, * }) * ``` * * @param component - The request component that failed validation. * @param issues - A non-empty tuple of Valibot validation issues. * @returns A Routekit handler result containing the formatted problem response. */ declare function problemValidationErrorHandler(component: ValibotValidationError, issues: [v.BaseIssue, ...v.BaseIssue[]]): RoutekitResponse>; /** * Create a Valibot route builder pre-configured with problem-spec-compliant request validation errors. * * This route builder automatically configures standard error schemas for `400 Bad Request` and * `422 Unprocessable Content` statuses. It also uses [`problemValidationErrorHandler`]{@link problemValidationErrorHandler} * as its default validation error handler to output structured JSON responses when validation fails. * * @example * ```ts * const route = createValibotRouteBuilder() * * router.post('/todos', route({ * schema: { * request: { * body: v.object({ title: v.string() }) * } * }, * handler: ({ body }) => ok({ title: body.title }) * })) * ``` * * @param defaults - Additional defaults to apply to built routes. * @returns A problem-spec-compliant Valibot route builder. * @typeParam BuilderCtx - Custom context registered by middlewares (e.g. Services, Auth). */ declare function createValibotRouteBuilder, BuilderCtx extends object = ContextFromMiddlewareInput>(defaults: ValibotRouteHelperDefaults & { middleware: BuilderMiddleware; }): ValibotRouteBuilder; declare function createValibotRouteBuilder = undefined>(defaults?: ValibotRouteHelperDefaults): ValibotRouteBuilder; //#endregion export { createValibotRouteBuilder, issueFromValibotIssue, issuesFromValibotIssues, okSchema, problemErrorSchema, problemIssueSchema, problemSchema, problemValidationErrorHandler, standardResponseSchema, validationProblemFromValibotIssues };