{"version":3,"sources":["../../src/core/section.ts"],"sourcesContent":["import IOCollection from \"./collection\";\r\nimport IOObject from \"./internet-object\";\r\n\r\n/**\r\n * IOSection represents a single data section within an Internet Object document.\r\n *\r\n * Each section can:\r\n * - Have an optional name for multi-section documents\r\n * - Reference a schema definition by name\r\n * - Contain either a single IOObject or an IOCollection of items\r\n * - Track parsing/validation errors specific to the section's data\r\n *\r\n * @template T The type of data items stored in the section\r\n *\r\n * @example\r\n * ```typescript\r\n * // Named section with schema reference\r\n * // --- users: $person\r\n * const section = new IOSection(userCollection, 'users', '$person');\r\n *\r\n * console.log(section.name);       // 'users'\r\n * console.log(section.schemaName); // '$person'\r\n * console.log(section.data);       // IOCollection of user objects\r\n * ```\r\n */\r\nclass IOSection<T = any> {\r\n  private _data: IOCollection<T> | IOObject<T> | null;\r\n  private _name?: string;\r\n  private _schemaName?: string;\r\n\r\n  constructor(data: any, name?: string, _schemaName?: string) {\r\n    this._data = data;\r\n    this._name = name;\r\n    this._schemaName = _schemaName;\r\n  }\r\n\r\n  public get name(): string | undefined {\r\n    return this._name;\r\n  }\r\n\r\n  public get schemaName(): string | undefined {\r\n    return this._schemaName;\r\n  }\r\n\r\n  public get data(): IOCollection<T> | IOObject<T> | null {\r\n    return this._data;\r\n  }\r\n\r\n  public get errors(): Error[] {\r\n    const errors: Error[] = [];\r\n\r\n    if (this._data instanceof IOCollection) {\r\n      // Add collection's own errors\r\n      errors.push(...this._data.errors);\r\n      // Also aggregate errors from child IOObjects within the collection\r\n      for (const item of this._data) {\r\n        if (item instanceof IOObject && item.errors.length > 0) {\r\n          errors.push(...item.errors);\r\n        }\r\n      }\r\n    } else if (this._data instanceof IOObject) {\r\n      errors.push(...this._data.errors);\r\n    }\r\n\r\n    return errors;\r\n  }\r\n\r\n  /**\r\n   * Return a clean object for nodejs console logging.\r\n   */\r\n  [Symbol.for('nodejs.util.inspect.custom')]() {\r\n    return {\r\n      name: this._name,\r\n      schema: this._schemaName,\r\n      data: this._data\r\n    }\r\n  }\r\n\r\n  /**\r\n   * Converts the section data to a plain JavaScript object.\r\n   * Delegates to the underlying data's `toObject` method if available.\r\n   *\r\n   * @param options - Conversion options.\r\n   * @param options.skipErrors - If true, excludes error objects from collection output.\r\n   * @returns The plain object representation of the section data.\r\n   */\r\n  public toObject(options?: { skipErrors?: boolean }): any {\r\n    // IOObject\r\n    if (this._data instanceof IOObject) {\r\n      return this._data.toObject();\r\n    }\r\n    // IOCollection\r\n    else if (this._data instanceof IOCollection) {\r\n      return this._data.toObject(options);\r\n    }\r\n    // Plain object\r\n    else if (this._data && typeof this._data === 'object') {\r\n      return this._data;\r\n    }\r\n    return null;\r\n  }\r\n\r\n  /**\r\n   * Alias for `toObject()`.\r\n   * Provides compatibility with `JSON.stringify()`.\r\n   */\r\n  public toJSON(options?: { skipErrors?: boolean }): any {\r\n    return this.toObject(options);\r\n  }\r\n}\r\n\r\nexport default IOSection;"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBAAyB;AACzB,6BAAqB;AAwBrB,MAAM,UAAmB;AAAA,EACf;AAAA,EACA;AAAA,EACA;AAAA,EAER,YAAY,MAAW,MAAe,aAAsB;AAC1D,SAAK,QAAQ;AACb,SAAK,QAAQ;AACb,SAAK,cAAc;AAAA,EACrB;AAAA,EAEA,IAAW,OAA2B;AACpC,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,IAAW,aAAiC;AAC1C,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,IAAW,OAA6C;AACtD,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,IAAW,SAAkB;AAC3B,UAAM,SAAkB,CAAC;AAEzB,QAAI,KAAK,iBAAiB,kBAAAA,SAAc;AAEtC,aAAO,KAAK,GAAG,KAAK,MAAM,MAAM;AAEhC,iBAAW,QAAQ,KAAK,OAAO;AAC7B,YAAI,gBAAgB,uBAAAC,WAAY,KAAK,OAAO,SAAS,GAAG;AACtD,iBAAO,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