import IODocument from '../core/document.js'; import IODefinitions from '../core/definitions.js'; import IOSchema from '../schema/schema.js'; import '../core/header.js'; import '../core/section-collection.js'; import '../core/section.js'; import '../core/collection.js'; import '../core/internet-object.js'; import '../schema/types/memberdef.js'; import '../schema/schema-types.js'; /** * Options for loading documents */ interface LoadDocumentOptions { /** * Schema to use for all sections (if not specified per section) */ defaultSchema?: string | IOSchema; /** * Schema mapping for named sections * Example: { users: userSchema, products: productSchema } */ sectionSchemas?: { [sectionName: string]: string | IOSchema; }; /** * External definitions to merge with document definitions */ definitions?: IODefinitions; /** * Collect validation errors instead of throwing */ errorCollector?: Error[]; /** * Strict mode - throw on first error * Default: false (collect all errors) */ strict?: boolean; } /** * Document data structure for loading */ interface DocumentData { /** * Header definitions (variables, schemas, etc.) */ header?: { definitions?: { [key: string]: any; }; schema?: string | IOSchema; }; /** * Data sections - can be: * - Single unnamed section (data directly) * - Named sections ({ sectionName: data }) */ data?: any; /** * Alternative: explicitly named sections */ sections?: { [name: string]: any; }; } /** * Load and validate a complete IODocument from plain JavaScript data. * * This function creates a full IODocument structure with header (definitions, schema) * and data sections, validating all data according to the provided schemas. * * @param data - Document data with header and sections * @param options - Loading options (schemas, definitions, error handling) * @returns Validated IODocument * @throws ValidationError if data doesn't conform to schemas (in strict mode) * * @example * ```typescript * // Load document with single section * const docData = { * header: { * definitions: { appName: 'MyApp', version: '1.0' } * }, * data: [ * { name: 'Alice', age: 28 }, * { name: 'Bob', age: 35 } * ] * }; * const doc = loadDocument(docData, { * defaultSchema: '{ name: string, age: number }' * }); * * // Load document with multiple named sections * const docData = { * header: { * schema: userSchema * }, * sections: { * users: [{ name: 'Alice' }, { name: 'Bob' }], * admins: [{ name: 'Admin' }] * } * }; * const doc = loadDocument(docData, { * sectionSchemas: { * users: userSchema, * admins: adminSchema * } * }); * * // Load with error collection * const errors: Error[] = []; * const doc = loadDocument(docData, { * defaultSchema: schema, * errorCollector: errors, * strict: false * }); * console.log(`Loaded with ${errors.length} errors`); * ``` */ declare function loadDocument(data: DocumentData, options?: LoadDocumentOptions): IODocument; export { type DocumentData, type LoadDocumentOptions, loadDocument };