@chubbyts/chubbyts-api
Version:
[](https://github.com/chubbyts/chubbyts-api/actions?query=workflow%3ACI) [ • 1.04 kB
JavaScript
import { isArray, isBoolean, isNull, isNumber, isObject, isString } from '@chubbyts/chubbyts-decode-encode/dist/data';
const resolveName = (path) => {
return path
.map((pathPart, i) => {
return i > 0 ? `[${pathPart.toString()}]` : pathPart;
})
.join('');
};
const filterContext = (rest) => {
if (isObject(rest)) {
return Object.fromEntries(Object.entries(rest).map(([key, value]) => [key, filterContext(value)]));
}
if (isArray(rest)) {
return rest.map(filterContext);
}
if (isNull(rest) || isBoolean(rest) || isNumber(rest) || isString(rest)) {
return rest;
}
if (rest instanceof Date) {
return rest.toJSON();
}
return '**filtered**';
};
export const zodToInvalidParameters = (zodError) => {
return zodError.issues.map((issue) => {
const { path, message, ...context } = issue;
return {
name: resolveName(path),
reason: message,
context: filterContext(context),
};
});
};