@orpc/openapi-client
Version:
<div align="center"> <image align="center" src="https://orpc.dev/logo.webp" width=280 alt="oRPC logo" /> </div>
40 lines (37 loc) • 1.3 kB
JavaScript
import { isSchemaIssue } from '@orpc/contract';
import { isTypescriptObject } from '@orpc/shared';
import { S as StandardBracketNotationSerializer } from './openapi-client.t9fCAe3x.mjs';
function parseFormData(form) {
const serializer = new StandardBracketNotationSerializer();
return serializer.deserialize(Array.from(form.entries()));
}
function getIssueMessage(error, path) {
if (!isTypescriptObject(error) || !isTypescriptObject(error.data) || !Array.isArray(error.data.issues)) {
return void 0;
}
const serializer = new StandardBracketNotationSerializer();
for (const issue of error.data.issues) {
if (!isSchemaIssue(issue)) {
continue;
}
if (issue.path === void 0) {
if (path === "") {
return issue.message;
}
continue;
}
const issuePath = serializer.stringifyPath(
issue.path.map((segment) => typeof segment === "object" ? segment.key.toString() : segment.toString())
);
if (issuePath === path) {
return issue.message;
}
if (path.endsWith("[]") && issuePath.replace(/\[(?:0|[1-9]\d*)\]$/, "[]") === path) {
return issue.message;
}
if (path === "" && issuePath.match(/(?:0|[1-9]\d*)$/)) {
return issue.message;
}
}
}
export { getIssueMessage as g, parseFormData as p };