import { __exports as i } from "../../../../../../../../_virtual/utils.js";
import { __require as B } from "../validators/is.js";
import { __require as J } from "../validators/validate.js";
var K;
function H() {
  if (K)
    return i;
  K = 1, Object.defineProperty(i, "__esModule", {
    value: !0
  }), i.VISITOR_KEYS = i.NODE_PARENT_VALIDATIONS = i.NODE_FIELDS = i.FLIPPED_ALIAS_KEYS = i.DEPRECATED_KEYS = i.BUILDER_KEYS = i.ALIAS_KEYS = void 0, i.arrayOf = D, i.arrayOfType = $, i.assertEach = P, i.assertNodeOrValueType = k, i.assertNodeType = h, i.assertOneOf = V, i.assertOptionalChainStart = j, i.assertShape = C, i.assertValueType = v, i.chain = g, i.default = L, i.defineAliasedType = U, i.typeIs = E, i.validate = O, i.validateArrayOfType = m, i.validateOptional = x, i.validateOptionalType = R, i.validateType = Y;
  var T = B(), c = J();
  const S = {};
  i.VISITOR_KEYS = S;
  const _ = {};
  i.ALIAS_KEYS = _;
  const y = {};
  i.FLIPPED_ALIAS_KEYS = y;
  const I = {};
  i.NODE_FIELDS = I;
  const w = {};
  i.BUILDER_KEYS = w;
  const b = {};
  i.DEPRECATED_KEYS = b;
  const N = {};
  i.NODE_PARENT_VALIDATIONS = N;
  function p(e) {
    return Array.isArray(e) ? "array" : e === null ? "null" : typeof e;
  }
  function O(e) {
    return {
      validate: e
    };
  }
  function E(e) {
    return typeof e == "string" ? h(e) : h(...e);
  }
  function Y(e) {
    return O(E(e));
  }
  function x(e) {
    return {
      validate: e,
      optional: !0
    };
  }
  function R(e) {
    return {
      validate: E(e),
      optional: !0
    };
  }
  function D(e) {
    return g(v("array"), P(e));
  }
  function $(e) {
    return D(E(e));
  }
  function m(e) {
    return O($(e));
  }
  function P(e) {
    function r(n, t, a) {
      if (!!Array.isArray(a))
        for (let f = 0; f < a.length; f++) {
          const l = `${t}[${f}]`, o = a[f];
          e(n, l, o), process.env.BABEL_TYPES_8_BREAKING && (0, c.validateChild)(n, l, o);
        }
    }
    return r.each = e, r;
  }
  function V(...e) {
    function r(n, t, a) {
      if (e.indexOf(a) < 0)
        throw new TypeError(`Property ${t} expected value to be one of ${JSON.stringify(e)} but got ${JSON.stringify(a)}`);
    }
    return r.oneOf = e, r;
  }
  function h(...e) {
    function r(n, t, a) {
      for (const f of e)
        if ((0, T.default)(f, a)) {
          (0, c.validateChild)(n, t, a);
          return;
        }
      throw new TypeError(`Property ${t} of ${n.type} expected node to be of a type ${JSON.stringify(e)} but instead got ${JSON.stringify(a == null ? void 0 : a.type)}`);
    }
    return r.oneOfNodeTypes = e, r;
  }
  function k(...e) {
    function r(n, t, a) {
      for (const f of e)
        if (p(a) === f || (0, T.default)(f, a)) {
          (0, c.validateChild)(n, t, a);
          return;
        }
      throw new TypeError(`Property ${t} of ${n.type} expected node to be of a type ${JSON.stringify(e)} but instead got ${JSON.stringify(a == null ? void 0 : a.type)}`);
    }
    return r.oneOfNodeOrValueTypes = e, r;
  }
  function v(e) {
    function r(n, t, a) {
      if (!(p(a) === e))
        throw new TypeError(`Property ${t} expected type of ${e} but got ${p(a)}`);
    }
    return r.type = e, r;
  }
  function C(e) {
    function r(n, t, a) {
      const f = [];
      for (const l of Object.keys(e))
        try {
          (0, c.validateField)(n, l, a[l], e[l]);
        } catch (o) {
          if (o instanceof TypeError) {
            f.push(o.message);
            continue;
          }
          throw o;
        }
      if (f.length)
        throw new TypeError(`Property ${t} of ${n.type} expected to have the following:
${f.join(`
`)}`);
    }
    return r.shapeOf = e, r;
  }
  function j() {
    function e(r) {
      var n;
      let t = r;
      for (; r; ) {
        const {
          type: a
        } = t;
        if (a === "OptionalCallExpression") {
          if (t.optional)
            return;
          t = t.callee;
          continue;
        }
        if (a === "OptionalMemberExpression") {
          if (t.optional)
            return;
          t = t.object;
          continue;
        }
        break;
      }
      throw new TypeError(`Non-optional ${r.type} must chain from an optional OptionalMemberExpression or OptionalCallExpression. Found chain from ${(n = t) == null ? void 0 : n.type}`);
    }
    return e;
  }
  function g(...e) {
    function r(...n) {
      for (const t of e)
        t(...n);
    }
    if (r.chainOf = e, e.length >= 2 && "type" in e[0] && e[0].type === "array" && !("each" in e[1]))
      throw new Error('An assertValueType("array") validator can only be followed by an assertEach(...) validator.');
    return r;
  }
  const F = ["aliases", "builder", "deprecatedAlias", "fields", "inherits", "visitor", "validate"], q = ["default", "optional", "validate"];
  function U(...e) {
    return (r, n = {}) => {
      let t = n.aliases;
      if (!t) {
        var a, f;
        n.inherits && (t = (a = A[n.inherits].aliases) == null ? void 0 : a.slice()), (f = t) != null || (t = []), n.aliases = t;
      }
      const l = e.filter((o) => !t.includes(o));
      return t.unshift(...l), L(r, n);
    };
  }
  function L(e, r = {}) {
    const n = r.inherits && A[r.inherits] || {};
    let t = r.fields;
    if (!t && (t = {}, n.fields)) {
      const o = Object.getOwnPropertyNames(n.fields);
      for (const s of o) {
        const u = n.fields[s], d = u.default;
        if (Array.isArray(d) ? d.length > 0 : d && typeof d == "object")
          throw new Error("field defaults can only be primitives or empty arrays currently");
        t[s] = {
          default: Array.isArray(d) ? [] : d,
          optional: u.optional,
          validate: u.validate
        };
      }
    }
    const a = r.visitor || n.visitor || [], f = r.aliases || n.aliases || [], l = r.builder || n.builder || r.visitor || [];
    for (const o of Object.keys(r))
      if (F.indexOf(o) === -1)
        throw new Error(`Unknown type option "${o}" on ${e}`);
    r.deprecatedAlias && (b[r.deprecatedAlias] = e);
    for (const o of a.concat(l))
      t[o] = t[o] || {};
    for (const o of Object.keys(t)) {
      const s = t[o];
      s.default !== void 0 && l.indexOf(o) === -1 && (s.optional = !0), s.default === void 0 ? s.default = null : !s.validate && s.default != null && (s.validate = v(p(s.default)));
      for (const u of Object.keys(s))
        if (q.indexOf(u) === -1)
          throw new Error(`Unknown field key "${u}" on ${e}.${o}`);
    }
    S[e] = r.visitor = a, w[e] = r.builder = l, I[e] = r.fields = t, _[e] = r.aliases = f, f.forEach((o) => {
      y[o] = y[o] || [], y[o].push(e);
    }), r.validate && (N[e] = r.validate), A[e] = r;
  }
  const A = {};
  return i;
}
export {
  H as __require
};
//# sourceMappingURL=utils.js.map
