UNPKG

salve-annos

Version:

A fork with support for documentation of Salve, a Javascript library which implements a validator able to validate an XML document on the basis of a subset of RelaxNG.

59 lines 2.67 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.convertRNGToPattern = convertRNGToPattern; const convert_simplified_1 = require("./convert-simplified"); const resource_loader_1 = require("./resource-loader"); const internal_1 = require("./schema-simplifiers/internal"); const DEFAULT_OPTIONS = { createManifest: false, manifestHashAlgorithm: "SHA-1", resourceLoader: undefined, idCheck: true, }; /** * Validate, simplify and convert a schema to a pattern, which can then be used * to validate an XML document. This function uses the internal simplification * and validation code. * * @param schemaPath The schema's location. The schema must be in the XML Relax * NG format. (Not the compact notation.) * * @param options The options driving the conversion. * * @returns The converted pattern. */ function convertRNGToPattern(schemaPath_1) { return __awaiter(this, arguments, void 0, function* (schemaPath, options = DEFAULT_OPTIONS) { const resourceLoader = options.resourceLoader !== undefined ? options.resourceLoader : (0, resource_loader_1.makeResourceLoader)(); const simplifier = new internal_1.InternalSimplifier({ verbose: false, timing: false, keepTemp: false, simplifyTo: Infinity, resourceLoader, validate: true, createManifest: options.createManifest, manifestHashAlgorithm: options.manifestHashAlgorithm, }); // Read the RNG source at this point so that it can be returned as part of the retuened object const { simplified, warnings, manifest, schemaText } = yield simplifier.simplify(schemaPath); return { pattern: (0, convert_simplified_1.makePatternFromSimplifiedSchema)(simplified), simplified, warnings, manifest, schemaText, }; }); } //# sourceMappingURL=convert.js.map