import IOObject from './internet-object.cjs'; /** * IOCollection is an ordered, index-accessible collection of items. * * Features: * - Array-like operations (push, pop, insert, deleteAt) * - Functional methods (map, filter, reduce, forEach, find, some, every) * - Iterable support for for..of loops * - JSON serialization with error handling options * - Proxy-based index access (collection[0]) * * @template T The type of items stored in the collection (defaults to IOObject) * * @example * ```typescript * const collection = new IOCollection(); * collection.push({ name: 'Alice', age: 30 }); * collection.push({ name: 'Bob', age: 25 }); * * // Iteration * for (const person of collection) { * console.log(person.name); * } * * // Functional operations * const names = collection.map(p => p.name); * ``` */ declare class IOCollection { private _items; errors: Error[]; /** * Constructs a new IOCollection instance. * @param items - An optional array of items to initialize the collection with. */ constructor(items?: T[]); /** * Pushes one or more items to the IOCollection * @param items - The items to push. * @returns The updated IOCollection. */ push(...items: T[]): IOCollection; /** * Gets the item at the specified index. * @param index - The index of the item to retrieve. * @throws {Error} If the index is out of range. * @returns The item at the specified index. */ getAt(index: number): T; /** * Sets the item at the specified index. * @param index - The index at which to set the item. * @param item - The item to set. * @throws {Error} If the index is negative. * @returns The updated IOCollection. */ setAt(index: number, item: T): IOCollection; /** * Deletes an item from the IOCollection at the specified index. * @param index - The index of the item to delete. * @throws {Error} If the index is out of range. * @returns The updated IOCollection. */ deleteAt(index: number): IOCollection; /** * Gets the length of the IOCollection. * @returns The number of items in the IOCollection. */ get length(): number; /** * Checks if the IOCollection is empty. * @returns True if the IOCollection is empty, otherwise false. */ get isEmpty(): boolean; /** * Creates a new IOCollection with the results of calling a provided function on every element. * @param callback - Function that produces an element of the new IOCollection. * @returns A new IOCollection with each element being the result of the callback function. */ map(callback: (item: T, index: number, array: T[]) => U): IOCollection; /** * Creates a new IOCollection with all elements that pass the test implemented by the provided function. * @param callback - Function to test each element of the IOCollection. * @returns A new IOCollection with the elements that pass the test. */ filter(callback: (item: T, index: number, array: T[]) => boolean): IOCollection; /** * Applies a function against an accumulator and each element in the IOCollection to reduce it to a single value. * @param callback - Function to execute on each element in the IOCollection. * @param initialValue - Initial value to start the reduction. * @returns The single value that results from the reduction. */ reduce(callback: (accumulator: U, item: T, index: number, array: T[]) => U, initialValue: U): U; /** * Executes a provided function once for each IOCollection element. * @param callback - Function to execute on each element. */ forEach(callback: (item: T, index: number, array: T[]) => void): void; /** * Tests whether at least one element in the IOCollection passes the test implemented by the provided function. * @param callback - Function to test each element. * @returns True if the callback function returns a truthy value for at least one element, otherwise false. */ some(callback: (item: T, index: number, array: T[]) => boolean): boolean; /** * Tests whether all elements in the IOCollection pass the test implemented by the provided function. * @param callback - Function to test each element. * @returns True if the callback returns a truthy value for all elements, otherwise false. */ every(callback: (item: T, index: number, array: T[]) => boolean): boolean; /** * Returns the value of the first element in the IOCollection that satisfies the provided testing function. * @param callback - Function to execute on each element. * @returns The first element that satisfies the testing function, or undefined if no elements satisfy it. */ find(callback: (item: T, index: number, array: T[]) => boolean): T | undefined; /** * Returns the index of the first element in the IOCollection that satisfies the provided testing function. * @param callback - Function to execute on each element. * @returns The index of the first element that satisfies the testing function, or -1 if no elements satisfy it. */ findIndex(callback: (item: T, index: number, array: T[]) => boolean): number; /** * Inserts one or more items into the IOCollection at the specified index. * @param index - The index at which to insert the items. * @param items - The items to insert. * @returns The new length of the IOCollection. */ insert(index: number, ...items: T[]): number; /** * Removes the last item from the IOCollection. * @returns The removed item, or undefined if the IOCollection is empty. */ pop(): T | undefined; /** * Converts the collection to a plain JavaScript array. * Recursively calls `toObject()` on items that support it. * * @param options Optional configuration for conversion * @param options.skipErrors If true, excludes error objects from output (default: false) * @returns An array of plain JavaScript values. */ toObject(options?: { skipErrors?: boolean; }): any; /** * Alias for `toObject()`. * Provides compatibility with `JSON.stringify()`. */ toJSON(options?: { skipErrors?: boolean; }): any; /** * Returns all Error objects contained within this collection's ErrorNodes. * * Note: This method is primarily useful when working with collections directly. * When using Document.getErrors(), all errors (parser + validation) are already * aggregated at the document level. * * @returns Array of Error objects from ErrorNode items in this collection */ getErrors(): Error[]; /** * Allows iteration over the IOCollection using for..of syntax. * @returns An iterator for the IOCollection. */ [Symbol.iterator](): IterableIterator; /** * Returns an iterator of [index, item] pairs. * @returns An iterator of index-item pairs. */ entries(): IterableIterator<[number, T]>; /** * Returns an iterator of item indices. * @returns An iterator of item indices. */ keys(): IterableIterator; /** * Returns an iterator of IOCollection items. * @returns An iterator of IOCollection items. */ values(): IterableIterator; } export { IOCollection as default };