{"version":3,"sources":["../../src/schema/schema.ts"],"sourcesContent":["import IOError from '../errors/io-error'\r\nimport ErrorCodes from '../errors/io-error-codes'\r\nimport MemberDef from \"./types/memberdef\";\r\nimport { MemberMap } from \"./schema-types\";\r\n\r\nexport default class IOSchema {\r\n  /** Name of the schema */\r\n  public name: string;\r\n\r\n  /** The names of the members (properties) in the schema */\r\n  public readonly names: string[] = [];\r\n\r\n  /** The definitions of the members (properties) in the schema */\r\n  public readonly defs: MemberMap = {};\r\n\r\n  /**\r\n   * Controls additional properties (dynamic fields) in the object.\r\n   * - false: No additional properties allowed\r\n   * - true: Any additional property allowed (no constraints)\r\n   * - MemberDef: Additional properties must match the given type/constraints\r\n   *   (e.g., string, array, object, or with constraints like {string, minLen: 10})\r\n   *\r\n   * If the schema uses *: type, *: {}, or *: [string], then open is set to the corresponding MemberDef.\r\n   * If the schema uses just *, then open is true.\r\n   * If no * is present, open is false.\r\n   */\r\n  public open: boolean | MemberDef = false;\r\n\r\n  [key: string]: any;\r\n\r\n  /**\r\n   * Creates a new instance of Internet Object IOSchema.\r\n   * Backward-compatible with legacy constructor usage that passes member objects.\r\n   * @param name The name of the schema\r\n   * @param o Optional member definition objects (legacy)\r\n   */\r\n  constructor(name: string, ...o: { [key: string]: MemberDef }[]) {\r\n    this.name = name;\r\n\r\n    // Legacy varargs support: new IOSchema('Name', { field: def }, { field2: def })\r\n    if (o && o.length > 0) {\r\n      o.forEach((item) => {\r\n        const key = Object.keys(item)[0];\r\n        const value = item[key];\r\n        if (value.path === undefined) value.path = key;\r\n        this.names.push(key);\r\n        this.defs[key] = value;\r\n      });\r\n    }\r\n  }\r\n\r\n  /** Returns the member definition of the given member name. */\r\n  get(name: string): MemberDef | undefined {\r\n    return this.defs[name];\r\n  }\r\n\r\n  /** Checks if a member exists by name. */\r\n  has(name: string): boolean {\r\n    return this.defs[name] !== undefined;\r\n  }\r\n\r\n  /** Returns the number of members in the schema. */\r\n  get memberCount(): number {\r\n    return this.names.length;\r\n  }\r\n\r\n  /** Builder entry for new, immutable-style construction while keeping runtime mutability */\r\n  static create(name: string): SchemaBuilder {\r\n    return new SchemaBuilder(name);\r\n  }\r\n\r\n  /** Legacy helper for creating from varargs member objects */\r\n  static fromLegacy(name: string, ...memberObjects: { [key: string]: MemberDef }[]): IOSchema {\r\n    return new IOSchema(name, ...memberObjects);\r\n  }\r\n}\r\n\r\nexport class SchemaBuilder {\r\n  private names: string[] = [];\r\n  private defs: MemberMap = {};\r\n  private isOpen: boolean | MemberDef = false;\r\n\r\n  constructor(private name: string) {}\r\n\r\n  addMember(name: string, def: MemberDef): this {\r\n    if (this.defs[name]) {\r\n      throw new IOError(ErrorCodes.duplicateMember, `Member '${name}' already exists in schema '${this.name}'`);\r\n    }\r\n    this.names.push(name);\r\n    this.defs[name] = { ...def, path: def.path || name };\r\n    return this;\r\n  }\r\n\r\n  setOpen(open: boolean | MemberDef): this {\r\n    this.isOpen = open;\r\n    return this;\r\n  }\r\n\r\n  build(): IOSchema {\r\n    const schema = new IOSchema(this.name);\r\n    // Populate mutable structure to keep backward compatibility\r\n    for (const n of this.names) {\r\n      schema.names.push(n);\r\n      schema.defs[n] = this.defs[n];\r\n    }\r\n    schema.open = this.isOpen;\r\n    // Freeze names and defs for immutability\r\n    Object.freeze(schema.names);\r\n    Object.freeze(schema.defs);\r\n    return schema;\r\n  }\r\n}"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAAoB;AACpB,4BAAuB;AAIvB,MAAO,SAAuB;AAAA;AAAA,EAErB;AAAA;AAAA,EAGS,QAAkB,CAAC;AAAA;AAAA,EAGnB,OAAkB,CAAC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAa5B,OAA4B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUnC,YAAY,SAAiB,GAAmC;AAC9D,SAAK,OAAO;AAGZ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