UNPKG

@jay-js/system

Version:

A powerful and flexible TypeScript library for UI, state management, lazy loading, routing and managing draggable elements in modern web applications.

34 lines 1.75 kB
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; export function standardSchemaResolver(schema) { return (values, fieldName) => __awaiter(this, void 0, void 0, function* () { const standard = schema["~standard"]; if (!standard || standard.version !== 1) { throw new Error("Invalid Standard Schema: missing or incompatible version"); } const result = standard.validate(values); if (result.issues) { const errors = result.issues .filter((issue) => { if (!fieldName) return true; const path = Array.isArray(issue.path) ? issue.path.join(".") : String(issue.path || ""); return path === fieldName || path.startsWith(`${fieldName}.`); }) .map((issue) => ({ path: Array.isArray(issue.path) ? issue.path.join(".") : String(issue.path || ""), message: issue.message, })); return { errors }; } return { errors: [] }; }); } //# sourceMappingURL=standard-schema-resolver.js.map