Skip to content

Releases: harshanacz/xerces-wasm-validator

2.0.2

Choose a tag to compare

@harshanacz harshanacz released this 21 Sep 05:37

Documentation: rewritten README with an API reference, restructured sections, and a corrected memory comparison in the benchmark table.

Full changelog: https://github.com/harshanacz/xerces-wasm-validator/blob/main/CHANGELOG.md

v2.0.0 — Full rewrite: cached grammar pools

Choose a tag to compare

@harshanacz harshanacz released this 24 Jun 18:13

⚠️ Breaking release. v2 is a complete rewrite with a new architecture and API. v1.x code will not work unchanged — see Migration below.

Highlights

  • In-memory grammar pool caching — each project's XSDs compile once into a locked XMLGrammarPool held in WASM memory; every validation reuses it, no re-parsing.
  • New project-based API — createProjectValidator() returns a reusable validator with validate(), reload(), and destroy().
  • Per-project isolation — each project keeps its own compiled pool, so the same XML can be valid in one project and invalid in another.
  • Fast re-validation — in the bundled benchmark: ~22 ms one-time compile, ~0.04 ms per subsequent validate().
  • Node.js + browser — the same WASM module runs in both.

New API

import { createProjectValidator } from "xerces-wasm";

const v = await createProjectValidator({
  entry: "main.xsd",
  files: { "main.xsd": xsdText /*, "types.xsd": ... */ },
});

const { valid, parseErrors, schemaErrors } = await v.validate(xml);
await v.reload(updatedFiles); // recompile when schemas change
v.destroy();                  // free the pool from WASM memory

Every validate() runs two passes: syntax (well-formedness → parseErrors) and schema (XSD rules → schemaErrors). Diagnostics are { message, line, column, severity }.

Breaking changes

  • Validation now goes through a createProjectValidator() instance, not a one-shot top-level call.
  • Results are { valid, parseErrors, schemaErrors } (separate syntax vs. schema error lists).
  • You must call destroy() when done — WASM memory is not reclaimed by the JS garbage collector.

Migration from v1.x

  1. Create one validator per project with createProjectValidator({ entry, files }).
  2. Pass every dependent XSD in files (keyed by filename) so xs:import / xs:include resolve from memory.
  3. Read results from parseErrors / schemaErrors instead of the old result shape.
  4. Call destroy() when a project closes.

Install

npm install xerces-wasm@2.0.0

License

MIT. Bundles Apache Xerces-C++ (Apache-2.0) — see LICENSE-APACHE and NOTICE.