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AO,IAAkB,EAAO,cAAgB,MAAM,EACxD,IAEA,EAAU,OAAO,GAAG,OAAQ,GAC5B,EAAU,OAAO,GAAG,OAAQ,GAG5B,MAAM,EAAQ,EAAU,MAExB,GAAI,EAAM,OAKR,OAJA,EAAM,OAAO,GAAG,OAAO,WACrB,EAAM,OAAO,OAAO,EACtB,IAEO,EAAM,OAAO,KAAK,GAGvB,EAAM,KACR,EAAM,MAAM,EAAM,KAGhB,EAAM,QACR,EAAM,MAAM,EAAM,OAAO,YAI3B,EAAM,KAAK,GAEf,CAcO,CAAc,EACvB,EAEA,OAAO,QAAQ,UAAY,UAK3B,OAAO,QAAQ,MAAQ,WAGrB,OAAO,cAFO,uBAAuB,KAAK,QAAQ,IAAI,WAAa,IAGrE,EASA,OAAO,QAAQ,YAAc,SAAS,EAAK,EAAQ,GAKjD,OAAO,IAAI,UAAU,CACnB,IAJU,QAAQ,MAKlB,MAJY,uBAAuB,KAAK,QAAQ,IAAI,WAAa,MAKhE,YAAY,EAAK,EAAQ,EAC9B","file":"/npm/xsd-schema-validator@0.11.0/lib/validator.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.37.0.\n * Original file: /npm/xsd-schema-validator@0.11.0/lib/validator.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","const fs = require('fs');\nconst os = require('os');\nconst path = require('path');\n\nconst which = require('which');\n\nconst spawn = require('child_process').spawn;\n\n/**\n * @typedef { import('node:stream').Readable } ReadableStream\n */\n\nconst CLASSPATH_SEPARATOR = os.platform() === 'win32' ? ';' : ':';\n\nconst BASE_DIR = path.resolve(__dirname, '..');\n\nconst VALIDATOR = path.resolve(BASE_DIR, 'support/XMLValidator');\n\nasync function withJava(executable, debug) {\n\n  if (debug) {\n    console.log('Locating %s, JAVA_HOME=%s', executable, process.env.JAVA_HOME);\n  }\n\n  const options = process.env.JAVA_HOME\n    ? { path: process.env.JAVA_HOME + '/bin' }\n    : {};\n\n  return which(executable, options);\n}\n\nasync function withValidator(debug) {\n\n  if (fs.existsSync(VALIDATOR + '.class')) {\n    if (debug) {\n      console.log('Using existing helper');\n    }\n\n    return;\n  }\n\n  if (debug) {\n    console.log('Compiling helper');\n  }\n\n  const javac = await withJava('javac').catch(err => {\n    throw new Error('Java SDK required at JAVA_HOME or in path to compile validation helper');\n  });\n\n  if (debug) {\n    console.log('Found javac: %s', javac);\n  }\n\n  return new Promise((resolve, reject) => {\n\n    spawn(javac, [ 'support/XMLValidator.java' ], { cwd: BASE_DIR })\n      .on('error', reject)\n      .on('exit', function(exitCode) {\n        if (exitCode !== 0) {\n          return reject(\n            new Error('Failed to compile helper (exitCode=' + exitCode + ')')\n          );\n        }\n\n        if (debug) {\n          console.log('Helper compiled');\n        }\n\n        return resolve();\n      });\n\n  });\n}\n\nfunction stripLineEnding(str) {\n  return str.replace(/[\\r\\n]+/g, '');\n}\n\n/**\n * Pass the current working directory as an argument\n *\n * @param {Object} [options] directory to search for schema resources and includes.\n */\nfunction Validator(options) {\n  options = options || {};\n\n  this.cwd = options.cwd;\n  this.debug = !!options.debug;\n}\n\n/**\n * Validate a xml file against the given schema\n *\n * @param { string|Buffer|ReadableStream|Object } xml\n * @param { string } schema path to schema\n * @param { { insecure?: boolean } } [options]\n *\n * @return Promise<any>\n */\nValidator.prototype.validateXML = async function(xml, schema, { insecure } = { }) {\n\n  const cwd = this.cwd;\n  const debug = this.debug;\n\n  // validate input and set validator mode\n  let input;\n\n  if (typeof xml === 'string') {\n\n    // plain string\n    input = {\n      str: xml\n    };\n  } else if (typeof xml.pipe === 'function') {\n\n    // readable stream\n    input = {\n      stream: xml\n    };\n  } else if (xml instanceof Buffer) {\n    input = {\n      buffer: xml\n    };\n  } else if (xml.file) {\n\n    // file\n    input = xml;\n  }\n\n  if (!input) {\n    throw new Error(\n      'unsupported <xml> parameter: ' +\n      'expected String|Buffer|ReadableStream|Object={ file: path }'\n    );\n  }\n\n  function runValidation(java) {\n\n    return new Promise((resolve, reject) => {\n\n      const args = [\n        '-Dfile.encoding=UTF-8',\n        '-classpath',\n        [ BASE_DIR, cwd ].join(CLASSPATH_SEPARATOR),\n        'support.XMLValidator',\n        insecure ? '-insecure' : null,\n        input.file ? '-file=' + input.file : '-stdin',\n        '-schema=' + schema\n      ].filter(arg => arg);\n\n      const validator = spawn(java, args, { cwd: cwd });\n\n      let result,\n          code,\n          messages = [];\n\n      function finish(result, code) {\n        const success = !code;\n        const err = success ? null : buildError(result, messages);\n\n        const data = {\n          valid: success,\n          result: result,\n          messages: messages\n        };\n\n        if (err) {\n          reject(Object.assign(err, data));\n        } else {\n          resolve(data);\n        }\n      }\n\n      function handleText(data) {\n        const msg = data.toString('utf-8');\n\n        if (msg.indexOf('[') === 0) {\n          messages.push(stripLineEnding(msg));\n        } else\n          if (msg.indexOf('result=') === 0) {\n            result = stripLineEnding(msg.slice('result='.length));\n\n            if (code !== undefined) {\n              finish(result, code);\n            }\n          } else {\n            if (debug) {\n              console.log(msg);\n            }\n          }\n      }\n\n      function buildError(result, messages) {\n        let msg = 'invalid xml (status=' + result + ')';\n        messages.forEach(function(m) {\n          msg += '\\n\\t' + m;\n        });\n\n        return new Error(msg);\n      }\n\n      validator.on('error', function(err) {\n        reject(err);\n      });\n\n      validator.on('exit', function(exitCode) {\n        code = exitCode;\n\n        finish(result ? result : code ? 'WITH_ERRORS' : 'OK', code);\n      });\n\n      validator.stderr.on('data', handleText);\n      validator.stdout.on('data', handleText);\n\n\n      const stdin = validator.stdin;\n\n      if (input.stream) {\n        input.stream.on('end', function() {\n          input.stream.unpipe(stdin);\n        });\n\n        return input.stream.pipe(stdin);\n      }\n\n      if (input.str) {\n        stdin.write(input.str);\n      }\n\n      if (input.buffer) {\n        stdin.write(input.buffer.toString());\n      }\n\n      // end input\n      stdin.end();\n    });\n  }\n\n  await withValidator(debug);\n\n  const java = await withJava('java', debug).catch(err => {\n    throw new Error(\n      'Java JRE required at JAVA_HOME or in path to perform validation'\n    );\n  });\n\n  if (debug) {\n    console.log('Found java: %s', java);\n  }\n\n  return runValidation(java);\n};\n\nmodule.exports.Validator = Validator;\n\n/**\n * Ensures that the validator is setup to perform actual validation.\n */\nmodule.exports.setup = function() {\n  const debug = /xsd-schema-validator/.test(process.env.LOG_DEBUG || '');\n\n  return withValidator(debug);\n};\n\n/**\n * Validate xml based on the given schema.\n *\n * @param { string|ReadableStream|Buffer|{ file: string } } xml\n * @param { string } schema\n * @param { { insecure?: boolean } } [options]\n */\nmodule.exports.validateXML = function(xml, schema, options) {\n\n  const cwd = process.cwd();\n  const debug = /xsd-schema-validator/.test(process.env.LOG_DEBUG || '');\n\n  return new Validator({\n    cwd,\n    debug\n  }).validateXML(xml, schema, options);\n};\n"]}