import { __exports as U } from "../../../../../../_virtual/core.js";
import { __require as ye } from "./compile/validate/index.js";
import { __require as W } from "./compile/codegen/index.js";
import { __require as _e } from "./runtime/validation_error.js";
import { __require as ve } from "./compile/ref_error.js";
import { __require as we } from "./compile/rules.js";
import { __require as ge } from "./compile/index.js";
import { __require as Se } from "./compile/resolve.js";
import { __require as Ee } from "./compile/validate/dataType.js";
import { __require as be } from "./compile/util.js";
import je from "./refs/data.json.js";
import { __require as $e } from "./runtime/uri.js";
var G;
function ze() {
  return G ? U : (G = 1, function(h) {
    Object.defineProperty(h, "__esModule", { value: !0 }), h.CodeGen = h.Name = h.nil = h.stringify = h.str = h._ = h.KeywordCxt = void 0;
    var X = ye();
    Object.defineProperty(h, "KeywordCxt", { enumerable: !0, get: function() {
      return X.KeywordCxt;
    } });
    var m = W();
    Object.defineProperty(h, "_", { enumerable: !0, get: function() {
      return m._;
    } }), Object.defineProperty(h, "str", { enumerable: !0, get: function() {
      return m.str;
    } }), Object.defineProperty(h, "stringify", { enumerable: !0, get: function() {
      return m.stringify;
    } }), Object.defineProperty(h, "nil", { enumerable: !0, get: function() {
      return m.nil;
    } }), Object.defineProperty(h, "Name", { enumerable: !0, get: function() {
      return m.Name;
    } }), Object.defineProperty(h, "CodeGen", { enumerable: !0, get: function() {
      return m.CodeGen;
    } });
    const B = _e(), C = ve(), Y = we(), p = ge(), H = W(), y = Se(), v = Ee(), w = be(), z = je, Q = $e(), D = (i, e) => new RegExp(i, e);
    D.code = "new RegExp";
    const Z = ["removeAdditional", "useDefaults", "coerceTypes"], ee = /* @__PURE__ */ new Set([
      "validate",
      "serialize",
      "parse",
      "wrapper",
      "root",
      "schema",
      "keyword",
      "pattern",
      "formats",
      "validate$data",
      "func",
      "obj",
      "Error"
    ]), te = {
      errorDataPath: "",
      format: "`validateFormats: false` can be used instead.",
      nullable: '"nullable" keyword is supported by default.',
      jsonPointers: "Deprecated jsPropertySyntax can be used instead.",
      extendRefs: "Deprecated ignoreKeywordsWithRef can be used instead.",
      missingRefs: "Pass empty schema with $id that should be ignored to ajv.addSchema.",
      processCode: "Use option `code: {process: (code, schemaEnv: object) => string}`",
      sourceCode: "Use option `code: {source: true}`",
      strictDefaults: "It is default now, see option `strict`.",
      strictKeywords: "It is default now, see option `strict`.",
      uniqueItems: '"uniqueItems" keyword is always validated.',
      unknownFormats: "Disable strict mode or pass `true` to `ajv.addFormat` (or `formats` option).",
      cache: "Map is used as cache, schema object as key.",
      serialize: "Map is used as cache, schema object as key.",
      ajvErrors: "It is default now."
    }, re = {
      ignoreKeywordsWithRef: "",
      jsPropertySyntax: "",
      unicode: '"minLength"/"maxLength" account for unicode characters by default.'
    }, F = 200;
    function ie(i) {
      var e, t, r, s, a, n, l, c, u, o, d, f, E, b, j, $, q, O, R, M, A, I, P, T, N;
      const _ = i.strict, k = (e = i.code) === null || e === void 0 ? void 0 : e.optimize, V = k === !0 || k === void 0 ? 1 : k || 0, J = (r = (t = i.code) === null || t === void 0 ? void 0 : t.regExp) !== null && r !== void 0 ? r : D, pe = (s = i.uriResolver) !== null && s !== void 0 ? s : Q.default;
      return {
        strictSchema: (n = (a = i.strictSchema) !== null && a !== void 0 ? a : _) !== null && n !== void 0 ? n : !0,
        strictNumbers: (c = (l = i.strictNumbers) !== null && l !== void 0 ? l : _) !== null && c !== void 0 ? c : !0,
        strictTypes: (o = (u = i.strictTypes) !== null && u !== void 0 ? u : _) !== null && o !== void 0 ? o : "log",
        strictTuples: (f = (d = i.strictTuples) !== null && d !== void 0 ? d : _) !== null && f !== void 0 ? f : "log",
        strictRequired: (b = (E = i.strictRequired) !== null && E !== void 0 ? E : _) !== null && b !== void 0 ? b : !1,
        code: i.code ? { ...i.code, optimize: V, regExp: J } : { optimize: V, regExp: J },
        loopRequired: (j = i.loopRequired) !== null && j !== void 0 ? j : F,
        loopEnum: ($ = i.loopEnum) !== null && $ !== void 0 ? $ : F,
        meta: (q = i.meta) !== null && q !== void 0 ? q : !0,
        messages: (O = i.messages) !== null && O !== void 0 ? O : !0,
        inlineRefs: (R = i.inlineRefs) !== null && R !== void 0 ? R : !0,
        schemaId: (M = i.schemaId) !== null && M !== void 0 ? M : "$id",
        addUsedSchema: (A = i.addUsedSchema) !== null && A !== void 0 ? A : !0,
        validateSchema: (I = i.validateSchema) !== null && I !== void 0 ? I : !0,
        validateFormats: (P = i.validateFormats) !== null && P !== void 0 ? P : !0,
        unicodeRegExp: (T = i.unicodeRegExp) !== null && T !== void 0 ? T : !0,
        int32range: (N = i.int32range) !== null && N !== void 0 ? N : !0,
        uriResolver: pe
      };
    }
    class g {
      constructor(e = {}) {
        this.schemas = {}, this.refs = {}, this.formats = {}, this._compilations = /* @__PURE__ */ new Set(), this._loading = {}, this._cache = /* @__PURE__ */ new Map(), e = this.opts = { ...e, ...ie(e) };
        const { es5: t, lines: r } = this.opts.code;
        this.scope = new H.ValueScope({ scope: {}, prefixes: ee, es5: t, lines: r }), this.logger = le(e.logger);
        const s = e.validateFormats;
        e.validateFormats = !1, this.RULES = (0, Y.getRules)(), K.call(this, te, e, "NOT SUPPORTED"), K.call(this, re, e, "DEPRECATED", "warn"), this._metaOpts = ne.call(this), e.formats && ae.call(this), this._addVocabularies(), this._addDefaultMetaSchema(), e.keywords && oe.call(this, e.keywords), typeof e.meta == "object" && this.addMetaSchema(e.meta), se.call(this), e.validateFormats = s;
      }
      _addVocabularies() {
        this.addKeyword("$async");
      }
      _addDefaultMetaSchema() {
        const { $data: e, meta: t, schemaId: r } = this.opts;
        let s = z;
        r === "id" && (s = { ...z }, s.id = s.$id, delete s.$id), t && e && this.addMetaSchema(s, s[r], !1);
      }
      defaultMeta() {
        const { meta: e, schemaId: t } = this.opts;
        return this.opts.defaultMeta = typeof e == "object" ? e[t] || e : void 0;
      }
      validate(e, t) {
        let r;
        if (typeof e == "string") {
          if (r = this.getSchema(e), !r)
            throw new Error(`no schema with key or ref "${e}"`);
        } else
          r = this.compile(e);
        const s = r(t);
        return "$async" in r || (this.errors = r.errors), s;
      }
      compile(e, t) {
        const r = this._addSchema(e, t);
        return r.validate || this._compileSchemaEnv(r);
      }
      compileAsync(e, t) {
        if (typeof this.opts.loadSchema != "function")
          throw new Error("options.loadSchema should be a function");
        const { loadSchema: r } = this.opts;
        return s.call(this, e, t);
        async function s(o, d) {
          await a.call(this, o.$schema);
          const f = this._addSchema(o, d);
          return f.validate || n.call(this, f);
        }
        async function a(o) {
          o && !this.getSchema(o) && await s.call(this, { $ref: o }, !0);
        }
        async function n(o) {
          try {
            return this._compileSchemaEnv(o);
          } catch (d) {
            if (!(d instanceof C.default))
              throw d;
            return l.call(this, d), await c.call(this, d.missingSchema), n.call(this, o);
          }
        }
        function l({ missingSchema: o, missingRef: d }) {
          if (this.refs[o])
            throw new Error(`AnySchema ${o} is loaded but ${d} cannot be resolved`);
        }
        async function c(o) {
          const d = await u.call(this, o);
          this.refs[o] || await a.call(this, d.$schema), this.refs[o] || this.addSchema(d, o, t);
        }
        async function u(o) {
          const d = this._loading[o];
          if (d)
            return d;
          try {
            return await (this._loading[o] = r(o));
          } finally {
            delete this._loading[o];
          }
        }
      }
      // Adds schema to the instance
      addSchema(e, t, r, s = this.opts.validateSchema) {
        if (Array.isArray(e)) {
          for (const n of e)
            this.addSchema(n, void 0, r, s);
          return this;
        }
        let a;
        if (typeof e == "object") {
          const { schemaId: n } = this.opts;
          if (a = e[n], a !== void 0 && typeof a != "string")
            throw new Error(`schema ${n} must be string`);
        }
        return t = (0, y.normalizeId)(t || a), this._checkUnique(t), this.schemas[t] = this._addSchema(e, r, t, s, !0), this;
      }
      // Add schema that will be used to validate other schemas
      // options in META_IGNORE_OPTIONS are alway set to false
      addMetaSchema(e, t, r = this.opts.validateSchema) {
        return this.addSchema(e, t, !0, r), this;
      }
      //  Validate schema against its meta-schema
      validateSchema(e, t) {
        if (typeof e == "boolean")
          return !0;
        let r;
        if (r = e.$schema, r !== void 0 && typeof r != "string")
          throw new Error("$schema must be a string");
        if (r = r || this.opts.defaultMeta || this.defaultMeta(), !r)
          return this.logger.warn("meta-schema not available"), this.errors = null, !0;
        const s = this.validate(r, e);
        if (!s && t) {
          const a = "schema is invalid: " + this.errorsText();
          if (this.opts.validateSchema === "log")
            this.logger.error(a);
          else
            throw new Error(a);
        }
        return s;
      }
      // Get compiled schema by `key` or `ref`.
      // (`key` that was passed to `addSchema` or full schema reference - `schema.$id` or resolved id)
      getSchema(e) {
        let t;
        for (; typeof (t = L.call(this, e)) == "string"; )
          e = t;
        if (t === void 0) {
          const { schemaId: r } = this.opts, s = new p.SchemaEnv({ schema: {}, schemaId: r });
          if (t = p.resolveSchema.call(this, s, e), !t)
            return;
          this.refs[e] = t;
        }
        return t.validate || this._compileSchemaEnv(t);
      }
      // Remove cached schema(s).
      // If no parameter is passed all schemas but meta-schemas are removed.
      // If RegExp is passed all schemas with key/id matching pattern but meta-schemas are removed.
      // Even if schema is referenced by other schemas it still can be removed as other schemas have local references.
      removeSchema(e) {
        if (e instanceof RegExp)
          return this._removeAllSchemas(this.schemas, e), this._removeAllSchemas(this.refs, e), this;
        switch (typeof e) {
          case "undefined":
            return this._removeAllSchemas(this.schemas), this._removeAllSchemas(this.refs), this._cache.clear(), this;
          case "string": {
            const t = L.call(this, e);
            return typeof t == "object" && this._cache.delete(t.schema), delete this.schemas[e], delete this.refs[e], this;
          }
          case "object": {
            const t = e;
            this._cache.delete(t);
            let r = e[this.opts.schemaId];
            return r && (r = (0, y.normalizeId)(r), delete this.schemas[r], delete this.refs[r]), this;
          }
          default:
            throw new Error("ajv.removeSchema: invalid parameter");
        }
      }
      // add "vocabulary" - a collection of keywords
      addVocabulary(e) {
        for (const t of e)
          this.addKeyword(t);
        return this;
      }
      addKeyword(e, t) {
        let r;
        if (typeof e == "string")
          r = e, typeof t == "object" && (this.logger.warn("these parameters are deprecated, see docs for addKeyword"), t.keyword = r);
        else if (typeof e == "object" && t === void 0) {
          if (t = e, r = t.keyword, Array.isArray(r) && !r.length)
            throw new Error("addKeywords: keyword must be string or non-empty array");
        } else
          throw new Error("invalid addKeywords parameters");
        if (he.call(this, r, t), !t)
          return (0, w.eachItem)(r, (a) => S.call(this, a)), this;
        me.call(this, t);
        const s = {
          ...t,
          type: (0, v.getJSONTypes)(t.type),
          schemaType: (0, v.getJSONTypes)(t.schemaType)
        };
        return (0, w.eachItem)(r, s.type.length === 0 ? (a) => S.call(this, a, s) : (a) => s.type.forEach((n) => S.call(this, a, s, n))), this;
      }
      getKeyword(e) {
        const t = this.RULES.all[e];
        return typeof t == "object" ? t.definition : !!t;
      }
      // Remove keyword
      removeKeyword(e) {
        const { RULES: t } = this;
        delete t.keywords[e], delete t.all[e];
        for (const r of t.rules) {
          const s = r.rules.findIndex((a) => a.keyword === e);
          s >= 0 && r.rules.splice(s, 1);
        }
        return this;
      }
      // Add format
      addFormat(e, t) {
        return typeof t == "string" && (t = new RegExp(t)), this.formats[e] = t, this;
      }
      errorsText(e = this.errors, { separator: t = ", ", dataVar: r = "data" } = {}) {
        return !e || e.length === 0 ? "No errors" : e.map((s) => `${r}${s.instancePath} ${s.message}`).reduce((s, a) => s + t + a);
      }
      $dataMetaSchema(e, t) {
        const r = this.RULES.all;
        e = JSON.parse(JSON.stringify(e));
        for (const s of t) {
          const a = s.split("/").slice(1);
          let n = e;
          for (const l of a)
            n = n[l];
          for (const l in r) {
            const c = r[l];
            if (typeof c != "object")
              continue;
            const { $data: u } = c.definition, o = n[l];
            u && o && (n[l] = x(o));
          }
        }
        return e;
      }
      _removeAllSchemas(e, t) {
        for (const r in e) {
          const s = e[r];
          (!t || t.test(r)) && (typeof s == "string" ? delete e[r] : s && !s.meta && (this._cache.delete(s.schema), delete e[r]));
        }
      }
      _addSchema(e, t, r, s = this.opts.validateSchema, a = this.opts.addUsedSchema) {
        let n;
        const { schemaId: l } = this.opts;
        if (typeof e == "object")
          n = e[l];
        else {
          if (this.opts.jtd)
            throw new Error("schema must be object");
          if (typeof e != "boolean")
            throw new Error("schema must be object or boolean");
        }
        let c = this._cache.get(e);
        if (c !== void 0)
          return c;
        r = (0, y.normalizeId)(n || r);
        const u = y.getSchemaRefs.call(this, e, r);
        return c = new p.SchemaEnv({ schema: e, schemaId: l, meta: t, baseId: r, localRefs: u }), this._cache.set(c.schema, c), a && !r.startsWith("#") && (r && this._checkUnique(r), this.refs[r] = c), s && this.validateSchema(e, !0), c;
      }
      _checkUnique(e) {
        if (this.schemas[e] || this.refs[e])
          throw new Error(`schema with key or id "${e}" already exists`);
      }
      _compileSchemaEnv(e) {
        if (e.meta ? this._compileMetaSchema(e) : p.compileSchema.call(this, e), !e.validate)
          throw new Error("ajv implementation error");
        return e.validate;
      }
      _compileMetaSchema(e) {
        const t = this.opts;
        this.opts = this._metaOpts;
        try {
          p.compileSchema.call(this, e);
        } finally {
          this.opts = t;
        }
      }
    }
    g.ValidationError = B.default, g.MissingRefError = C.default, h.default = g;
    function K(i, e, t, r = "error") {
      for (const s in i) {
        const a = s;
        a in e && this.logger[r](`${t}: option ${s}. ${i[a]}`);
      }
    }
    function L(i) {
      return i = (0, y.normalizeId)(i), this.schemas[i] || this.refs[i];
    }
    function se() {
      const i = this.opts.schemas;
      if (i)
        if (Array.isArray(i))
          this.addSchema(i);
        else
          for (const e in i)
            this.addSchema(i[e], e);
    }
    function ae() {
      for (const i in this.opts.formats) {
        const e = this.opts.formats[i];
        e && this.addFormat(i, e);
      }
    }
    function oe(i) {
      if (Array.isArray(i)) {
        this.addVocabulary(i);
        return;
      }
      this.logger.warn("keywords option as map is deprecated, pass array");
      for (const e in i) {
        const t = i[e];
        t.keyword || (t.keyword = e), this.addKeyword(t);
      }
    }
    function ne() {
      const i = { ...this.opts };
      for (const e of Z)
        delete i[e];
      return i;
    }
    const ce = { log() {
    }, warn() {
    }, error() {
    } };
    function le(i) {
      if (i === !1)
        return ce;
      if (i === void 0)
        return console;
      if (i.log && i.warn && i.error)
        return i;
      throw new Error("logger must implement log, warn and error methods");
    }
    const de = /^[a-z_$][a-z0-9_$:-]*$/i;
    function he(i, e) {
      const { RULES: t } = this;
      if ((0, w.eachItem)(i, (r) => {
        if (t.keywords[r])
          throw new Error(`Keyword ${r} is already defined`);
        if (!de.test(r))
          throw new Error(`Keyword ${r} has invalid name`);
      }), !!e && e.$data && !("code" in e || "validate" in e))
        throw new Error('$data keyword must have "code" or "validate" function');
    }
    function S(i, e, t) {
      var r;
      const s = e?.post;
      if (t && s)
        throw new Error('keyword with "post" flag cannot have "type"');
      const { RULES: a } = this;
      let n = s ? a.post : a.rules.find(({ type: c }) => c === t);
      if (n || (n = { type: t, rules: [] }, a.rules.push(n)), a.keywords[i] = !0, !e)
        return;
      const l = {
        keyword: i,
        definition: {
          ...e,
          type: (0, v.getJSONTypes)(e.type),
          schemaType: (0, v.getJSONTypes)(e.schemaType)
        }
      };
      e.before ? ue.call(this, n, l, e.before) : n.rules.push(l), a.all[i] = l, (r = e.implements) === null || r === void 0 || r.forEach((c) => this.addKeyword(c));
    }
    function ue(i, e, t) {
      const r = i.rules.findIndex((s) => s.keyword === t);
      r >= 0 ? i.rules.splice(r, 0, e) : (i.rules.push(e), this.logger.warn(`rule ${t} is not defined`));
    }
    function me(i) {
      let { metaSchema: e } = i;
      e !== void 0 && (i.$data && this.opts.$data && (e = x(e)), i.validateSchema = this.compile(e, !0));
    }
    const fe = {
      $ref: "https://raw.githubusercontent.com/ajv-validator/ajv/master/lib/refs/data.json#"
    };
    function x(i) {
      return { anyOf: [i, fe] };
    }
  }(U), U);
}
export {
  ze as __require
};
//# sourceMappingURL=core.js.map
