xsd-lookup
Version:
Multi-schema XSD lookup utility
174 lines • 8.66 kB
TypeScript
import { Schema, AttributeInfo, EnhancedAttributeInfo, AttributeValidationResult } from './Schema';
export type { AttributeInfo, EnhancedAttributeInfo, AttributeValidationResult };
/**
* Interface for attribute name validation results
*/
export interface AttributeNameValidationResult {
wrongAttributes: string[];
missingRequiredAttributes: string[];
}
export declare class XsdReference {
private schemas;
private xsdDirectory;
constructor(xsdDirectory: string);
/**
* Discover and parse XSD includes from a schema file
* @param xsdFilePath The path to the XSD file to scan for includes
* @returns Array of absolute paths to included XSD files that exist
*/
private discoverIncludes;
/**
* Load a schema dynamically based on schema name
* @param schemaName The name of the schema to load (without .xsd extension)
* @returns The loaded Schema instance, or null if loading failed
*/
private loadSchema;
/**
* Get the appropriate schema for a given XML file (legacy method)
* @deprecated Use XsdDetector.detectSchemaFromXml() and then getSchema() instead
*/
getSchemaForFile(xmlFilePath: string): Schema | null;
/**
* Get schema by type name (loads on demand)
* @param schemaType The type/name of the schema to retrieve
* @returns The Schema instance if found and loaded successfully, null otherwise
*/
getSchema(schemaType: string): Schema | null;
/**
* Get all currently loaded schema types
* @returns Array of schema type names that are currently loaded in memory
*/
getAvailableSchemas(): string[];
/**
* Get all discoverable schema files in the XSD directory
* @returns Array of schema names (without .xsd extension) found in the XSD directory
*/
getDiscoverableSchemas(): string[];
/**
* Get element definition using a specific schema by name
* @param schemaName The schema to use
* @param elementName The element name to find
* @param hierarchy The element hierarchy in bottom-up order (parent → root)
*/
getElementDefinition(schemaName: string, elementName: string, hierarchy?: string[]): Element | undefined;
/**
* Get element attributes using a specific schema by name
* @param schemaName The schema to use
* @param elementName The element name to find
* @param hierarchy The element hierarchy in bottom-up order (parent → root)
*/
getElementAttributes(schemaName: string, elementName: string, hierarchy?: string[]): AttributeInfo[];
/**
* Get element attributes with type information
* @param schemaName The schema to use
* @param elementName The element name to find
* @param hierarchy The element hierarchy in bottom-up order (parent → root)
*/
getElementAttributesWithTypes(schemaName: string, elementName: string, hierarchy?: string[]): EnhancedAttributeInfo[];
/**
* Validate an attribute value against the schema
* @param schemaName The schema to use
* @param elementName The element name
* @param attributeName The attribute name
* @param attributeValue The attribute value to validate
* @param hierarchy The element hierarchy in bottom-up order (parent → root)
*/
validateAttributeValue(schemaName: string, elementName: string, attributeName: string, attributeValue: string, hierarchy?: string[]): AttributeValidationResult;
/**
* Validate attributes against a list of provided attribute names
* @param attributeInfos The attribute info array from getElementAttributesWithTypes
* @param providedAttributes Array of attribute names that are provided
* @returns Object containing wrong attributes and missing required attributes
*/
static validateAttributeNames(attributeInfos: EnhancedAttributeInfo[], providedAttributes: string[]): AttributeNameValidationResult;
/**
* Filter attributes by type
* @param attributeInfos The attribute info array from getElementAttributesWithTypes
* @param attributeType The type to filter by (e.g., 'xs:string', 'xs:int', etc.)
* @returns Array of attributes that match the specified type
*/
static filterAttributesByType(attributeInfos: EnhancedAttributeInfo[], attributeType: string): string[];
/**
* Filter attributes by restriction type
* @param attributeInfos The attribute info array from getElementAttributesWithTypes
* @param restrictionType The restriction to filter by ('enumeration', 'pattern', 'length', 'range')
* @returns Array of attributes that have the specified restriction type
*/
static filterAttributesByRestriction(attributeInfos: EnhancedAttributeInfo[], restrictionType: 'enumeration' | 'pattern' | 'length' | 'range'): string[];
/**
* Validate an attribute value against its schema rules
* @param attributeInfos The attribute info array from getElementAttributesWithTypes
* @param attributeName The attribute name to validate
* @param attributeValue The value to validate
* @returns Validation result with details
*/
static validateAttributeValueAgainstRules(attributeInfos: EnhancedAttributeInfo[], attributeName: string, attributeValue: string): {
isValid: boolean;
errorMessage?: string;
violatedRules?: string[];
};
/**
* Get possible values for an attribute if it has enumeration restrictions
* @param attributeInfos The attribute info array from getElementAttributesWithTypes
* @param attributeName The attribute name
* @returns Map where key is the enum value and value is its annotation text, or empty map if no enumeration exists
*/
static getAttributePossibleValues(attributeInfos: EnhancedAttributeInfo[], attributeName: string): Map<string, string>;
/**
* Get all simple types that use a specific type as their base
* @param schemaName The schema name to search
* @param baseType The base type to filter by (e.g., 'lvalueexpression')
* @returns Array of simple type names that use the specified base type
*/
getSimpleTypesWithBaseType(schemaName: string, baseType: string): string[];
/**
* Get enumeration values for a named SimpleType
* @param schemaName The schema name to search in
* @param simpleTypeName The name of the SimpleType to get enumeration values from
* @returns Object containing enumeration values and their annotations, or null if not found or not an enumeration
*/
getSimpleTypeEnumerationValues(schemaName: string, simpleTypeName: string): {
values: string[];
annotations: Map<string, string>;
} | null;
/**
* Check if an attribute name is an XML infrastructure attribute that should be ignored
* @param attributeName The attribute name to check
* @returns True if it's an infrastructure attribute (xmlns, xsi, etc.)
*/
private static isXmlInfrastructureAttribute;
/**
* Filter out XML infrastructure attributes from a list
* @param attributeNames Array of attribute names to filter
* @returns Array with infrastructure attributes removed
*/
private static filterOutInfrastructureAttributes;
/**
* Get possible child elements for a given element by name and hierarchy
* @param schemaName The schema to use
* @param elementName The parent element name
* @param hierarchy The element hierarchy in bottom-up order (parent → root)
* @param previousSibling Optional previous sibling element name to filter results based on sequence constraints
* @returns Map where key is child element name and value is its annotation text
*/
getPossibleChildElements(schemaName: string, elementName: string, hierarchy?: string[], previousSibling?: string): Map<string, string>;
/**
* Extract annotation text from an XML element.
* This static method provides access to Schema's annotation extraction functionality.
* @param element The XML element to extract annotation from
* @returns The annotation text, or undefined if no annotation found
*/
static extractAnnotationText(element: Element): string | undefined;
/**
* Clear a specific schema from the cache
* @param schemaName The name of the schema to clear
*/
private clearSchema;
/**
* Clear all schemas and their caches
* This method clears all loaded schemas and their internal caches.
* It can be used to release resources when the XSD reference is no longer needed.
*/
dispose(): void;
}
//# sourceMappingURL=XsdReference.d.ts.map