UNPKG

@actyx/sdk

Version:
21 lines 996 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.validateOrThrow = void 0; const Either_1 = require("fp-ts/lib/Either"); /* eslint-disable @typescript-eslint/no-explicit-any */ const validationErrorsMsgs = (input, decoder, errors) => { const validationErrors = errors.map((error) => `[${error.context.map(({ key }) => key).join('.')}] = ${JSON.stringify(error.value)}`); return `Validation of [${JSON.stringify(input)}] to ${decoder} failed:\n${validationErrors.join('.')}`; }; const isTestEnv = typeof process !== 'undefined' && process.env && process.env.NODE_ENV !== 'production'; function validateOrThrow(decoder) { return (value) => { const validated = decoder.decode(value); if ((0, Either_1.isLeft)(validated)) { throw new Error(validationErrorsMsgs(value, decoder.name, validated.left)); } return validated.right; }; } exports.validateOrThrow = validateOrThrow; //# sourceMappingURL=io.js.map