Rocky_Mountain_Vending/.pnpm-store/v10/files/0d/583bf35408a9823180f027bbab1400bbc0ca4eff623d09366118abcc3eaf2b225c4433f36f55dc41d978c095ab2467b4c9a017f873fa5fd9e6ddcad11e90a1
DMleadgen 46d973904b
Initial commit: Rocky Mountain Vending website
Next.js website for Rocky Mountain Vending company featuring:
- Product catalog with Stripe integration
- Service areas and parts pages
- Admin dashboard with Clerk authentication
- SEO optimized pages with JSON-LD structured data

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-12 16:22:15 -07:00

69 lines
1.8 KiB
Text

import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';
import { TypeCheck } from '@sinclair/typebox/compiler';
import { Value, type ValueError } from '@sinclair/typebox/value';
import { FieldError, FieldErrors, appendErrors } from 'react-hook-form';
import type { Resolver } from './types';
const parseErrorSchema = (
_errors: ValueError[],
validateAllFieldCriteria: boolean,
) => {
const errors: Record<string, FieldError> = {};
for (; _errors.length; ) {
const error = _errors[0];
const { type, message, path } = error;
const _path = path.substring(1).replace(/\//g, '.');
if (!errors[_path]) {
errors[_path] = { message, type: '' + type };
}
if (validateAllFieldCriteria) {
const types = errors[_path].types;
const messages = types && types['' + type];
errors[_path] = appendErrors(
_path,
validateAllFieldCriteria,
errors,
'' + type,
messages
? ([] as string[]).concat(messages as string[], error.message)
: error.message,
) as FieldError;
}
_errors.shift();
}
return errors;
};
export const typeboxResolver: Resolver =
(schema) => async (values, _, options) => {
const errors = Array.from(
schema instanceof TypeCheck
? schema.Errors(values)
: Value.Errors(schema, values),
);
options.shouldUseNativeValidation && validateFieldsNatively({}, options);
if (!errors.length) {
return {
errors: {} as FieldErrors,
values,
};
}
return {
values: {},
errors: toNestErrors(
parseErrorSchema(
errors,
!options.shouldUseNativeValidation && options.criteriaMode === 'all',
),
options,
),
};
};