UNPKG

dilswer

Version:

Blazingly fast data validation library with TypeScript integration.

39 lines (37 loc) 1.5 kB
var __defProp = Object.defineProperty; var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value); // src/validation-algorithms/validation-error/validation-error.ts import { concatPath } from "../../utilities/concat-object-path.mjs"; var ValidationErrorSymbol = Symbol("ValidationError"); var _a, _b; var ValidationError = class extends (_b = TypeError, _a = ValidationErrorSymbol, _b) { constructor(path, expected, value, customMessage) { super( customMessage != null ? customMessage : "value does not conform the data type structure definition" ); __publicField(this, _a, true); __publicField(this, "path"); __publicField(this, "expectedValueType"); __publicField(this, "receivedValue"); __publicField(this, "fieldPathCache", null); this.expectedValueType = expected; this.path = path; this.receivedValue = value; } static isValidationError(e) { return typeof e === "object" && e !== null && e instanceof Error && ValidationErrorSymbol in e; } get fieldPath() { if (this.fieldPathCache == null) { this.fieldPathCache = concatPath(this.path.flatten()); } return this.fieldPathCache; } get pathSegments() { return this.path.flatten().map((p) => ({ key: p })); } }; export { ValidationError };