Rocky_Mountain_Vending/.pnpm-store/v10/files/d8/7be02b87a8cd9ddb84d85e7342ad4a477c12724f0588ee66eb3de827cecac3575a07fd2268ef5c6d21be6308fc8af0b385f654aa3bb89b35823322314fc857
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

35 lines
981 B
Text

import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';
import { FieldError } from 'react-hook-form';
import { StructError, validate } from 'superstruct';
import { Resolver } from './types';
const parseErrorSchema = (error: StructError) =>
error.failures().reduce<Record<string, FieldError>>(
(previous, error) =>
(previous[error.path.join('.')] = {
message: error.message,
type: error.type,
}) && previous,
{},
);
export const superstructResolver: Resolver =
(schema, schemaOptions, resolverOptions = {}) =>
(values, _, options) => {
const result = validate(values, schema, schemaOptions);
if (result[0]) {
return {
values: {},
errors: toNestErrors(parseErrorSchema(result[0]), options),
};
}
options.shouldUseNativeValidation && validateFieldsNatively({}, options);
return {
values: resolverOptions.raw ? values : result[1],
errors: {},
};
};