/** * PluginSystem — Phase 19: Plugin architecture * ───────────────────────────────────────────── * Allows third-party code to extend the engine without forking: * * • Custom simple-type validators (new xs:* types or domain types) * • Custom entity resolvers (expand &myentity;) * • Custom schema validators (extra constraints beyond XSD) * • Custom serializer transforms (pre/post-processing hooks) * • Custom error formatters (already exposed via createFormatter) * * All plugins are registered on a PluginRegistry and injected at the * appropriate engine call site. Plugins compose cleanly — multiple * plugins for the same extension point run in registration order. * * Usage * ───── * const registry = new PluginRegistry(); * * // Register a custom type validator * registry.registerTypeValidator('myns:EmailType', (value) => { * return /^[^@]+@[^@]+$/.test(value) * ? { valid: true } * : { valid: false, message: `"${value}" is not a valid email` }; * }); * * // Register a custom entity resolver * registry.registerEntityResolver((name) => * name === 'company' ? 'ACME Corp' : null * ); * * // Register a custom schema validator * registry.registerSchemaValidator((doc, schema, result) => { * // add custom issues to result * }); * * // Use in parse + validate * const entityMap = registry.buildEntityMap(); * const doc = parseXml(xml, { entityMap }); * const result = validate(doc, schema); * registry.runSchemaValidators(doc, schema, result); */ import { XmlDocument } from '../parser/XmlNodes'; import { SchemaModel } from '../schema/SchemaModel'; import { ValidationResult } from '../validator/ValidationResult'; import { TypeValidationResult } from '../validator/TypeValidator'; /** A custom simple-type validator function. */ export type CustomTypeValidator = (value: string) => TypeValidationResult; /** A custom entity resolver: given an entity name, returns its expansion or null. */ export type EntityResolver = (name: string) => string | null; /** * A custom schema validator: runs after XSD validation and can add extra * issues to the ValidationResult. */ export type SchemaValidatorHook = (doc: XmlDocument, schema: SchemaModel, result: ValidationResult) => void; /** A serializer transform: called before serialization with the document. */ export type SerializerTransform = (doc: XmlDocument) => void; export declare class PluginRegistry { private typeValidators; private entityResolvers; private schemaValidators; private serializerTransforms; /** * Register a validator function for a custom type name. * The name is the key used in XSD typeName references (e.g. "myns:Email"). * If a type with this name is already registered, the new validator replaces it. */ registerTypeValidator(typeName: string, validator: CustomTypeValidator): this; /** Returns the custom validator for `typeName`, or null. */ getTypeValidator(typeName: string): CustomTypeValidator | null; /** Returns all registered custom type names. */ customTypeNames(): string[]; /** * Register an entity resolver. * Resolvers are called in registration order; the first non-null result wins. */ registerEntityResolver(resolver: EntityResolver): this; /** * Build an entity map from all registered resolvers. * Pass this to `parseXml({ entityMap })` to activate custom entities. * * The map is built lazily — unknown entities are resolved at parse time * by calling each resolver in turn. */ buildEntityMap(): Record; /** * Register a custom schema validator hook. * Hooks run after the built-in XSD validation, in registration order. * Each hook can add errors/warnings to the ValidationResult. */ registerSchemaValidator(hook: SchemaValidatorHook): this; /** * Run all registered schema validator hooks. * Call this after `validate(doc, schema)` to apply custom rules. */ runSchemaValidators(doc: XmlDocument, schema: SchemaModel, result: ValidationResult): void; /** * Register a serializer pre-transform. * Transforms are called in registration order before serialization. * They may mutate the document in-place (e.g. add/remove attributes). */ registerSerializerTransform(transform: SerializerTransform): this; /** * Apply all registered serializer transforms to a document. * Call this before `serializeXml(doc)`. */ applySerializerTransforms(doc: XmlDocument): void; /** * Merge another registry into this one (plugins compose). * Type validators from `other` override same-name validators in this. */ merge(other: PluginRegistry): this; /** Returns a summary of what's registered. */ summary(): { typeValidators: number; entityResolvers: number; schemaValidators: number; serializerTransforms: number; }; } /** Default global registry — import and extend for simple use cases. */ export declare const defaultRegistry: PluginRegistry; //# sourceMappingURL=PluginRegistry.d.ts.map