/** * XsdParser (full rewrite) * ───────────────────────── * Parses an XSD 1.0 document into a SchemaModel. * * Fixed / added vs. prior version * ──────────────────────────────── * • xs:import / xs:include – schema composition (with optional loader hook) * • xs:element ref="" – element reference resolution * • xs:attribute ref="" – attribute ref: copies type/use/fixed from * the referenced top-level attribute declaration * • xs:attributeGroup nested refs resolved transitively * • identity constraints – xs:key, xs:keyref, xs:unique stored on SchemaModel * • substitutionGroup index built after all elements are registered * • final / block on xs:element and xs:complexType * • Consistent key strategy: bare names when tns='', {tns}name otherwise */ import { SchemaModel } from '../schema/SchemaModel'; /** * Synchronous hook to resolve xs:import / xs:include schemaLocation values. * If not provided, import/include directives are silently skipped. */ export type SchemaLoader = (location: string, namespace: string) => string | null; /** * Asynchronous hook to resolve xs:import / xs:include schemaLocation values. * Use this when you need to fetch schemas from remote URLs or async file I/O. * * @example * ```ts * const asyncLoader: AsyncSchemaLoader = async (location, ns) => { * const res = await fetch(location); * return res.ok ? res.text() : null; * }; * const schema = await parseXsdAsync(xsdSource, asyncLoader); * ``` */ export type AsyncSchemaLoader = (location: string, namespace: string) => Promise; export declare class XsdParser { private loader?; private schema; private xsPrefix; private tns; private namedGroups; private namedAttrGroups; private importedNs; /** * NP1-14 fix: prefix → namespace URI map built from schema root xmlns declarations. * Used by _resolveRef to resolve prefixes that are not the xs-prefix or tns-prefix * (e.g. imported namespaces declared with xmlns:pfx="..."). */ private _prefixNsMap; /** * v1.7.0: source-level parse cache shared across sub-parsers created by * xs:import, xs:include, and xs:redefine. Prevents re-parsing the same XSD * source string more than once per top-level `parse()` call. * Key: sha256-short(src), Value: parsed SchemaModel. */ private _parseCache; /** * NP0-08 fix: deterministic counter for anonymous type keys. * Using Math.random() produces non-deterministic keys across reloads, breaking * content-hash caches and multi-import resolution. A per-parse counter is stable. */ private _anonCounter; constructor(loader?: SchemaLoader | undefined); parse(xsdSource: string): SchemaModel; private _parseSchemaRoot; private _handleImport; /** * xs:redefine: load the referenced schema file (like xs:include) then apply * overriding type/group definitions from the redefine block on top. * * sub-schemas loaded via redefine now go through _parseSubSource() * which uses _parseCache to prevent cascading re-compilation on nested * redefine/include chains. */ private _handleRedefine; /** * v1.7.0: parse a sub-schema from `src`, re-using a cached SchemaModel if * the same source was already parsed within this parse() call. */ private _parseSubSource; private _detectXsPrefix; private _ln; private _qkey; /** Resolve a ref/type attribute value into a SchemaModel map key. */ private _resolveRef; private _parseTopElement; private _parseElementDecl; private _parseIdentityConstraint; private _parseSimpleType; private _parseSimpleRestriction; private _parseSimpleList; private _parseSimpleUnion; private _parseComplexType; private _parseSimpleContent; private _collectSimpleContentAttrs; private _parseComplexContent; private _parseCompositor; private _parseAttributeDecl; private _parseAnyAttribute; private _parseNamedGroup; private _parseNamedAttrGroup; private _collectAttrGroupAttrs; private _resolveAttrGroup; } /** * Convenience – parse an XSD string into a SchemaModel. * Provide a `loader` to support xs:import / xs:include. */ export declare function parseXsd(xsdSource: string, loader?: SchemaLoader): SchemaModel; /** * Asynchronous XSD parser — supports `AsyncSchemaLoader` for xs:import / xs:include. * * This is identical to `parseXsd` but accepts an async loader function, enabling * use cases like fetching remote schemas via `fetch()` or using async file I/O. * * @example * ```ts * import { parseXsdAsync, AsyncSchemaLoader } from 'xml-xsd-engine'; * import { readFile } from 'fs/promises'; * import { join, dirname } from 'path'; * * const loader: AsyncSchemaLoader = async (location) => * readFile(join('/schemas', location), 'utf8').catch(() => null); * * const schema = await parseXsdAsync(mainXsdSource, loader); * ``` */ export declare function parseXsdAsync(xsdSource: string, loader?: AsyncSchemaLoader | SchemaLoader): Promise; //# sourceMappingURL=XsdParser.d.ts.map