UNPKG

@smooai/utils

Version:

A collection of shared utilities and tools used across SmooAI projects. This package provides common functionality to standardize and simplify development across all SmooAI repositories.

41 lines (40 loc) 1.37 kB
// src/validation/standardSchema.ts import { getDotPath, SchemaError } from "@standard-schema/utils"; var HumanReadableSchemaError = class extends Error { constructor(schemaError) { super(formatStandardSchemaErrorToHumanReadable(schemaError.issues)); this.schemaError = schemaError; this.name = "HumanReadableSchemaError"; } }; function formatStandardSchemaErrorToHumanReadable(issues) { if (issues.length === 0) { return "No validation errors"; } if (issues.length === 1) { const issue = issues[0]; const dotPath = getDotPath(issue); const pathString = dotPath ? ` at "${dotPath}"` : ""; return `${issue.message}${pathString}`; } return issues.map((issue, index) => { const dotPath = getDotPath(issue); const pathString = dotPath ? ` at "${dotPath}"` : ""; return `${index + 1}. ${issue.message}${pathString}`; }).join("\n"); } async function handleSchemaValidation(schema, input) { let result = schema["~standard"].validate(input); if (result instanceof Promise) result = await result; if (result.issues) { const schemaError = new SchemaError(result.issues); throw new HumanReadableSchemaError(schemaError); } return result.value; } export { HumanReadableSchemaError, formatStandardSchemaErrorToHumanReadable, handleSchemaValidation }; //# sourceMappingURL=chunk-WKR62SAR.mjs.map