import IODefinitions from '../core/definitions.js'; import IOObject from '../core/internet-object.js'; import IOCollection from '../core/collection.js'; import IODocument from '../core/document.js'; import IOSchema from '../schema/schema.js'; import '../core/header.js'; import '../core/section-collection.js'; import '../core/section.js'; import '../schema/types/memberdef.js'; import '../schema/schema-types.js'; /** * Stringify options for controlling output format */ interface StringifyOptions { /** * 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 io = stringify(user, defs, { schemaName: '$User' }); * ``` */ schemaName?: string; /** * Indentation for pretty printing (number of spaces or string) * If omitted, output is compact (single line) */ indent?: number | string; /** * Skip error objects in collections * Default: false (includes errors in output) */ skipErrors?: boolean; /** * Include type annotations in output * Default: false (values only) */ includeTypes?: boolean; /** * Include header section with definitions (for Document only) * Default: false (data only) */ includeHeader?: boolean; } /** * Serialize an InternetObject, Collection, or Document to Internet Object text format. * * This is the high-level API for converting validated data back to IO format. * Uses TypeDef.stringify() methods to serialize each field according to type rules. * * ## Overload Patterns * * 1. `stringify(value)` - Schema-less serialization (no validation) * 2. `stringify(value, defs)` - Uses `defs.defaultSchema` ($schema) for type info * 3. `stringify(value, options)` - Schema-less with formatting options * 4. `stringify(value, defs, options)` - Full control with schema from defs * * ## Schema Resolution * * When `defs` is provided, the schema is resolved in this order: * 1. `options.schemaName` → `defs.get(schemaName)` (pick specific schema) * 2. `defs.defaultSchema` → Uses `$schema` from definitions * 3. No schema → Schema-less mode (values only, no validation) * * @param value - InternetObject, Collection, or Document to serialize * @param defs - Optional definitions for schema and variable resolution * @param options - Optional formatting options (includes `schemaName` to pick specific schema) * @returns Internet Object text representation * * @example * ```typescript * // Schema-less stringify * const obj = new InternetObject(); * obj.set('name', 'Alice'); * obj.set('age', 28); * const text = stringify(obj); * // Output: "Alice, 28" * * // Stringify with definitions (uses $schema) * const defs = new Definitions(); * defs.set('$schema', userSchema); * const text = stringify(obj, defs); * * // Stringify with specific schema from defs * const text = stringify(obj, defs, { schemaName: '$Address' }); * * // Stringify a document * const doc = parse(ioText, null); * const text = stringify(doc); * * // Stringify with pretty printing * const text = stringify(obj, defs, { indent: 2 }); * * // Stringify a collection * const collection = new Collection([obj1, obj2, obj3]); * const text = stringify(collection, defs); * ``` */ declare function stringify(value: IOObject | IOCollection | IODocument | any): string; declare function stringify(value: IOObject | IOCollection | IODocument | any, defs: IODefinitions): string; declare function stringify(value: IOObject | IOCollection | IODocument | any, options: StringifyOptions): string; declare function stringify(value: IOObject | IOCollection | IODocument | any, defs: IODefinitions, options: StringifyOptions): string; /** * Stringify an InternetObject to IO text format. * @internal Used by stringifyDocument for section serialization. */ declare function stringifyObject(obj: IOObject, schema?: IOSchema, defs?: IODefinitions, options?: StringifyOptions): string; /** * Stringify a Collection to IO text format. * @internal Used by stringifyDocument for section serialization. */ declare function stringifyCollection(collection: IOCollection, schema?: IOSchema, defs?: IODefinitions, options?: StringifyOptions): string; export { type StringifyOptions, stringify, stringifyCollection, stringifyObject };