UNPKG

dilswer

Version:

Blazingly fast data validation library with TypeScript integration.

49 lines (47 loc) 1.56 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/data-types/types/intersection.ts import { BaseType } from "../base-type.mjs"; import { getStandardSchemaProps } from "../generate-standard-schema.mjs"; var IntersectionType = class extends BaseType { constructor(allOf) { super(); __publicField(this, "allOf", allOf); __publicField(this, "kind", "intersection"); Object.freeze(this.allOf); Object.freeze(this); } /** @internal */ _acceptVisitor(visitor, depth = 1) { const children = []; for (let i = 0; i < this.allOf.length; i++) { children.push(this.allOf[i]._acceptVisitor(visitor, depth + 1)); } return visitor.visit(this, children, depth); } get ["~standard"]() { return getStandardSchemaProps(this); } ["~validate"](path, value) { for (let i = 0; i < this.allOf.length; i++) { const dataType = this.allOf[i]; dataType["~validate"](path, value); } } ["~matches"](value) { for (let i = 0; i < this.allOf.length; i++) { const dataType = this.allOf[i]; if (!dataType["~matches"](value)) { return false; } } return true; } toString() { return `IntersectionSchema[ ${this.allOf.map((t) => t.toString()).join(" & ")} ]`; } }; export { IntersectionType };