import IODefinitions from '../core/definitions.js'; import IODocument from '../core/document.js'; import IOObject from '../core/internet-object.js'; import IOCollection from '../core/collection.js'; import '../schema/schema.js'; import '../schema/types/memberdef.js'; import '../schema/schema-types.js'; import '../core/header.js'; import '../core/section-collection.js'; import '../core/section.js'; interface LoadObjectOptions { /** * The name of the schema to use from definitions. * If provided, the schema will be looked up by this name in the definitions. * If not provided, uses `defs.defaultSchema` (`$schema`). * * @example * ```typescript * const defs = parseDefinitions('~ $User: { name, age }'); * const obj = loadObject(data, defs, { schemaName: '$User' }); * ``` */ schemaName?: string; /** * When true, throws on first validation error. * When false (default), continues processing and collects errors. * @default false */ strict?: boolean; /** * Array to collect validation errors instead of throwing. * Useful for processing collections where some items may be invalid. */ errorCollector?: Error[]; } /** * Load and validate plain JavaScript data according to an Internet Object schema. * * This is the high-level API for validating external data (from APIs, databases, etc.) * using Internet Object schemas. Unlike parse(), which processes IO text, * loadObject() validates plain JavaScript objects. * * @param data - Plain JavaScript object or array to validate * @param defs - Definitions object containing schemas * @param options - LoadObjectOptions (schemaName, strict, errorCollector) * @returns Validated InternetObject or Collection * @throws ValidationError if data doesn't conform to schema * * @example * ```typescript * // Schema-less (no validation, just wrap in InternetObject) * const obj = loadObject({ name: 'Alice', age: 28 }); * * // Load with definitions (uses $schema as default) * const defs = parseDefinitions('~ $schema: { name: string, age: int }'); * const obj = loadObject(data, defs); * * // Load with specific schema name from definitions * const defs = parseDefinitions('~ $User: { name, age }'); * const obj = loadObject(data, defs, { schemaName: '$User' }); * ``` */ declare function loadObject(data: object): IOObject; declare function loadObject(data: object, defs: IODefinitions): IOObject; declare function loadObject(data: object, options: LoadObjectOptions): IOObject; declare function loadObject(data: object, defs: IODefinitions, options: LoadObjectOptions): IOObject; /** * Options for loadCollection function (same as LoadOptions) */ type LoadCollectionOptions = LoadOptions; /** * Load JS array (no Document wrapper). * * @param data - Array of plain JavaScript objects to validate * @param defs - Definitions object containing schemas * @param options - LoadCollectionOptions (schemaName, strict, errorCollector) * @returns Collection of validated InternetObjects * * @example * ```typescript * // Schema-less (no validation) * const col = loadCollection([{ name: 'Alice' }, { name: 'Bob' }]); * * // With definitions (validates each item against $schema) * const col = loadCollection(data, defs); * * // With specific schema from definitions * const col = loadCollection(users, defs, { schemaName: '$User' }); * ``` */ declare function loadCollection(data: any[]): IOCollection; declare function loadCollection(data: any[], defs: IODefinitions): IOCollection; declare function loadCollection(data: any[], options: LoadCollectionOptions): IOCollection; declare function loadCollection(data: any[], defs: IODefinitions, options: LoadCollectionOptions): IOCollection; /** * Options for load function */ interface LoadOptions { /** * The name of the schema to use from definitions. * If provided, the schema will be looked up by this name in the definitions. * If not provided, uses `defs.defaultSchema` (`$schema`). * * @example * ```typescript * const defs = parseDefinitions('~ $User: { name, age }'); * const doc = load(data, defs, { schemaName: '$User' }); * ``` */ schemaName?: string; /** * When true, throws on first validation error. * When false (default), continues processing and collects errors. * @default false */ strict?: boolean; /** * Array to collect validation errors instead of throwing. * Useful for processing collections where some items may be invalid. */ errorCollector?: Error[]; } /** * Load plain JavaScript data into a complete IODocument with header and sections. * * This function creates a full document structure that can be stringified with * schema definitions in the header. Use this when you need the complete IO format * with definitions output. * * @param data - Plain JavaScript object or array to load * @param defs - Definitions object containing schemas * @param options - LoadOptions (schemaName, strict, errorCollector) * @returns Complete IODocument with header containing definitions * * @example * ```typescript * // Schema-less (no validation) * const doc = load(data); * * // Load with definitions (uses $schema as default) * const defs = parseDefinitions('~ $schema: { name, age, address: $address }'); * const doc = load(data, defs); * * // Load with specific schema name * const defs = parseDefinitions('~ $User: { name, age }'); * const doc = load(data, defs, { schemaName: '$User' }); * ``` */ declare function load(data: any): IODocument; declare function load(data: any, defs: IODefinitions): IODocument; declare function load(data: any, options: LoadOptions): IODocument; declare function load(data: any, defs: IODefinitions, options: LoadOptions): IODocument; export { type LoadCollectionOptions, type LoadObjectOptions, type LoadOptions, load, loadCollection, loadObject };