UNPKG

unstructured-client

Version:

<h3 align="center"> <img src="https://raw.githubusercontent.com/Unstructured-IO/unstructured/main/img/unstructured_logo.png" height="200" > </h3>

57 lines 1.78 kB
/* * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. */ import { ZodError, } from "zod"; import { SDKValidationError } from "../sdk/models/errors/sdkvalidationerror.js"; import { ERR, OK } from "../sdk/types/fp.js"; /** * Utility function that executes some code which may throw a ZodError. It * intercepts this error and converts it to an SDKValidationError so as to not * leak Zod implementation details to user code. */ export function parse(rawValue, fn, errorMessage) { try { return fn(rawValue); } catch (err) { if (err instanceof ZodError) { throw new SDKValidationError(errorMessage, err, rawValue); } throw err; } } /** * Utility function that executes some code which may result in a ZodError. It * intercepts this error and converts it to an SDKValidationError so as to not * leak Zod implementation details to user code. */ export function safeParse(rawValue, fn, errorMessage) { try { return OK(fn(rawValue)); } catch (err) { return ERR(new SDKValidationError(errorMessage, err, rawValue)); } } export function collectExtraKeys(obj, extrasKey, optional) { return obj.transform((val) => { const extras = {}; const { shape } = obj; for (const [key] of Object.entries(val)) { if (key in shape) { continue; } const v = val[key]; if (typeof v === "undefined") { continue; } extras[key] = v; delete val[key]; } if (optional && Object.keys(extras).length === 0) { return val; } return { ...val, [extrasKey]: extras }; }); } //# sourceMappingURL=schemas.js.map