{"version":3,"file":"config-validator.mjs","sources":["../../../src/lib/config/config-validator.ts"],"sourcesContent":["/**\n * @fileoverview Configuration validation with schema support.\n *\n * Provides comprehensive validation:\n * - Type checking\n * - Required field validation\n * - Pattern matching\n * - Range validation\n * - Custom validators\n *\n * @module config/config-validator\n *\n * @example\n * ```typescript\n * const validator = new ConfigValidator(schema);\n * const result = validator.validate(config);\n *\n * if (!result.valid) {\n *   console.error('Validation errors:', result.errors);\n * }\n * ```\n */\n\nimport type {\n  ConfigSchema,\n  ConfigFieldSchema,\n  ConfigRecord,\n  ValidationResult,\n  ValidationError,\n  ValidationRule,\n  ValidationRuleType,\n} from './types';\n\n// ============================================================================\n// Types\n// ============================================================================\n\n/**\n * Custom validator function.\n */\nexport type CustomValidator = (\n  value: unknown,\n  path: string,\n  config: ConfigRecord\n) => string | null;\n\n/**\n * Validator options.\n */\nexport interface ValidatorOptions {\n  /** Custom validators */\n  readonly customValidators?: Record<string, CustomValidator>;\n  /** Whether to stop on first error */\n  readonly stopOnFirstError?: boolean;\n  /** Whether to coerce types */\n  readonly coerceTypes?: boolean;\n}\n\n// ============================================================================\n// Config Validator\n// ============================================================================\n\n/**\n * Configuration validator with schema support.\n */\nexport class ConfigValidator {\n  private readonly schema: ConfigSchema;\n  private readonly customValidators: Record<string, CustomValidator>;\n  private options: ValidatorOptions;\n\n  constructor(schema: ConfigSchema, options: ValidatorOptions = {}) {\n    this.schema = schema;\n    this.customValidators = options.customValidators ?? {};\n    this.options = options;\n  }\n\n  /**\n   * Validate configuration against schema.\n   */\n  validate(config: ConfigRecord): ValidationResult {\n    const errors: ValidationError[] = [];\n    const warnings: string[] = [];\n\n    this.validateObject(config, this.schema, '', errors, warnings);\n\n    return {\n      valid: errors.length === 0,\n      errors,\n      warnings,\n    };\n  }\n\n  /**\n   * Validate a single value against a field schema.\n   */\n  validateField(\n    value: unknown,\n    schema: ConfigFieldSchema,\n    path: string\n  ): ValidationError[] {\n    const errors: ValidationError[] = [];\n\n    if (schema.rules) {\n      for (const rule of schema.rules) {\n        const error = this.validateRule(value, rule, path);\n        if (error) {\n          errors.push(error);\n          if (this.options.stopOnFirstError === true) {\n            break;\n          }\n        }\n      }\n    }\n\n    return errors;\n  }\n\n  /**\n   * Register a custom validator.\n   */\n  registerValidator(name: string, validator: CustomValidator): void {\n    this.customValidators[name] = validator;\n  }\n\n  private validateObject(\n    obj: ConfigRecord,\n    schema: ConfigSchema,\n    basePath: string,\n    errors: ValidationError[],\n    warnings: string[]\n  ): void {\n    // Check each field in schema\n    for (const [key, fieldSchema] of Object.entries(schema)) {\n      const path = basePath ? `${basePath}.${key}` : key;\n      const value = obj[key];\n\n      // Check for deprecated fields\n      if (fieldSchema.deprecated === true && value !== undefined) {\n        warnings.push(\n          fieldSchema.deprecationMessage ??\n            `Field '${path}' is deprecated`\n        );\n      }\n\n      // Validate rules\n      if (fieldSchema.rules) {\n        for (const rule of fieldSchema.rules) {\n          const error = this.validateRule(value, rule, path);\n          if (error != null) {\n            errors.push(error);\n            if (this.options.stopOnFirstError === true) {\n              return;\n            }\n          }\n        }\n      }\n\n      // Validate nested object\n      if (\n        fieldSchema.properties &&\n        value !== undefined &&\n        value !== null &&\n        typeof value === 'object' &&\n        !Array.isArray(value)\n      ) {\n        this.validateObject(\n          value as ConfigRecord,\n          fieldSchema.properties,\n          path,\n          errors,\n          warnings\n        );\n      }\n\n      // Validate array items\n      if (fieldSchema.items && Array.isArray(value)) {\n        for (let i = 0; i < value.length; i++) {\n          const itemPath = `${path}[${i}]`;\n          const itemErrors = this.validateField(\n            value[i],\n            fieldSchema.items,\n            itemPath\n          );\n          errors.push(...itemErrors);\n        }\n      }\n    }\n  }\n\n  private validateRule(\n    value: unknown,\n    rule: ValidationRule,\n    path: string\n  ): ValidationError | null {\n    const { type, params, message } = rule;\n\n    switch (type) {\n      case 'required':\n        if (value === undefined || value === null || value === '') {\n          return this.createError(path, message ?? `${path} is required`, type, value);\n        }\n        break;\n\n      case 'string':\n        if (value !== undefined && value !== null && typeof value !== 'string') {\n          return this.createError(\n            path,\n            message ?? `${path} must be a string`,\n            type,\n            value\n          );\n        }\n        break;\n\n      case 'number':\n        if (value !== undefined && value !== null && typeof value !== 'number') {\n          return this.createError(\n            path,\n            message ?? `${path} must be a number`,\n            type,\n            value\n          );\n        }\n        break;\n\n      case 'boolean':\n        if (value !== undefined && value !== null && typeof value !== 'boolean') {\n          return this.createError(\n            path,\n            message ?? `${path} must be a boolean`,\n            type,\n            value\n          );\n        }\n        break;\n\n      case 'array':\n        if (value !== undefined && value !== null && !Array.isArray(value)) {\n          return this.createError(\n            path,\n            message ?? `${path} must be an array`,\n            type,\n            value\n          );\n        }\n        break;\n\n      case 'object':\n        if (\n          value !== undefined &&\n          value !== null &&\n          (typeof value !== 'object' || Array.isArray(value))\n        ) {\n          return this.createError(\n            path,\n            message ?? `${path} must be an object`,\n            type,\n            value\n          );\n        }\n        break;\n\n      case 'enum':\n        if (\n          value !== undefined &&\n          value !== null &&\n          Array.isArray(params) &&\n          !params.includes(value)\n        ) {\n          return this.createError(\n            path,\n            message ?? `${path} must be one of: ${params.join(', ')}`,\n            type,\n            value\n          );\n        }\n        break;\n\n      case 'pattern':\n        if (\n          typeof value === 'string' &&\n          typeof params === 'string' &&\n          !new RegExp(params).test(value)\n        ) {\n          return this.createError(\n            path,\n            message ?? `${path} does not match pattern`,\n            type,\n            value\n          );\n        }\n        break;\n\n      case 'min':\n        if (typeof value === 'number' && typeof params === 'number' && value < params) {\n          return this.createError(\n            path,\n            message ?? `${path} must be at least ${params}`,\n            type,\n            value\n          );\n        }\n        break;\n\n      case 'max':\n        if (typeof value === 'number' && typeof params === 'number' && value > params) {\n          return this.createError(\n            path,\n            message ?? `${path} must be at most ${params}`,\n            type,\n            value\n          );\n        }\n        break;\n\n      case 'minLength':\n        if (\n          typeof value === 'string' &&\n          typeof params === 'number' &&\n          value.length < params\n        ) {\n          return this.createError(\n            path,\n            message ?? `${path} must be at least ${params} characters`,\n            type,\n            value\n          );\n        }\n        if (\n          Array.isArray(value) &&\n          typeof params === 'number' &&\n          value.length < params\n        ) {\n          return this.createError(\n            path,\n            message ?? `${path} must have at least ${params} items`,\n            type,\n            value\n          );\n        }\n        break;\n\n      case 'maxLength':\n        if (\n          typeof value === 'string' &&\n          typeof params === 'number' &&\n          value.length > params\n        ) {\n          return this.createError(\n            path,\n            message ?? `${path} must be at most ${params} characters`,\n            type,\n            value\n          );\n        }\n        if (\n          Array.isArray(value) &&\n          typeof params === 'number' &&\n          value.length > params\n        ) {\n          return this.createError(\n            path,\n            message ?? `${path} must have at most ${params} items`,\n            type,\n            value\n          );\n        }\n        break;\n\n      case 'email':\n        if (\n          typeof value === 'string' &&\n          !/^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/.test(value)\n        ) {\n          return this.createError(\n            path,\n            message ?? `${path} must be a valid email address`,\n            type,\n            value\n          );\n        }\n        break;\n\n      case 'url':\n        if (typeof value === 'string') {\n          try {\n            new URL(value);\n          } catch {\n            return this.createError(\n              path,\n              message ?? `${path} must be a valid URL`,\n              type,\n              value\n            );\n          }\n        }\n        break;\n\n      case 'custom':\n        if (typeof params === 'string' && this.customValidators[params] != null) {\n          const customMessage = this.customValidators[params](value, path, {});\n          if (customMessage != null && customMessage !== '') {\n            return this.createError(path, customMessage, type, value);\n          }\n        }\n        break;\n    }\n\n    return null;\n  }\n\n  private createError(\n    path: string,\n    message: string,\n    rule: ValidationRuleType,\n    value: unknown\n  ): ValidationError {\n    return { path, message, rule, value };\n  }\n}\n\n// ============================================================================\n// Schema Builder\n// ============================================================================\n\n/**\n * Fluent builder for configuration schemas.\n */\nexport class SchemaBuilder {\n  private schema: ConfigSchema = {};\n\n  /**\n   * Add a string field.\n   */\n  string(\n    name: string,\n    options?: {\n      required?: boolean;\n      default?: string;\n      pattern?: string;\n      minLength?: number;\n      maxLength?: number;\n      enum?: string[];\n      description?: string;\n      secret?: boolean;\n      envVar?: string;\n    }\n  ): this {\n    const rules: ValidationRule[] = [{ type: 'string' }];\n\n    if (options?.required === true) {\n      rules.unshift({ type: 'required' });\n    }\n    if (options?.pattern != null && options.pattern !== '') {\n      rules.push({ type: 'pattern', params: options.pattern });\n    }\n    if (options?.minLength !== undefined) {\n      rules.push({ type: 'minLength', params: options.minLength });\n    }\n    if (options?.maxLength !== undefined) {\n      rules.push({ type: 'maxLength', params: options.maxLength });\n    }\n    if (options?.enum) {\n      rules.push({ type: 'enum', params: options.enum });\n    }\n\n    this.schema[name] = {\n      description: options?.description,\n      default: options?.default,\n      rules,\n      secret: options?.secret,\n      envVar: options?.envVar,\n    };\n\n    return this;\n  }\n\n  /**\n   * Add a number field.\n   */\n  number(\n    name: string,\n    options?: {\n      required?: boolean;\n      default?: number;\n      min?: number;\n      max?: number;\n      description?: string;\n      envVar?: string;\n    }\n  ): this {\n    const rules: ValidationRule[] = [{ type: 'number' }];\n\n    if (options?.required === true) {\n      rules.unshift({ type: 'required' });\n    }\n    if (options?.min !== undefined) {\n      rules.push({ type: 'min', params: options.min });\n    }\n    if (options?.max !== undefined) {\n      rules.push({ type: 'max', params: options.max });\n    }\n\n    this.schema[name] = {\n      description: options?.description,\n      default: options?.default,\n      rules,\n      envVar: options?.envVar,\n    };\n\n    return this;\n  }\n\n  /**\n   * Add a boolean field.\n   */\n  boolean(\n    name: string,\n    options?: {\n      required?: boolean;\n      default?: boolean;\n      description?: string;\n      envVar?: string;\n    }\n  ): this {\n    const rules: ValidationRule[] = [{ type: 'boolean' }];\n\n    if (options?.required === true) {\n      rules.unshift({ type: 'required' });\n    }\n\n    this.schema[name] = {\n      description: options?.description,\n      default: options?.default,\n      rules,\n      envVar: options?.envVar,\n    };\n\n    return this;\n  }\n\n  /**\n   * Add an object field.\n   */\n  object(\n    name: string,\n    properties: ConfigSchema,\n    options?: {\n      required?: boolean;\n      description?: string;\n    }\n  ): this {\n    const rules: ValidationRule[] = [{ type: 'object' }];\n\n    if (options?.required === true) {\n      rules.unshift({ type: 'required' });\n    }\n\n    this.schema[name] = {\n      description: options?.description,\n      rules,\n      properties,\n    };\n\n    return this;\n  }\n\n  /**\n   * Add an array field.\n   */\n  array(\n    name: string,\n    items: ConfigFieldSchema,\n    options?: {\n      required?: boolean;\n      minLength?: number;\n      maxLength?: number;\n      description?: string;\n    }\n  ): this {\n    const rules: ValidationRule[] = [{ type: 'array' }];\n\n    if (options?.required === true) {\n      rules.unshift({ type: 'required' });\n    }\n    if (options?.minLength !== undefined) {\n      rules.push({ type: 'minLength', params: options.minLength });\n    }\n    if (options?.maxLength !== undefined) {\n      rules.push({ type: 'maxLength', params: options.maxLength });\n    }\n\n    this.schema[name] = {\n      description: options?.description,\n      rules,\n      items,\n    };\n\n    return this;\n  }\n\n  /**\n   * Build the schema.\n   */\n  build(): ConfigSchema {\n    return { ...this.schema };\n  }\n}\n\n/**\n * Create a new schema builder.\n */\nexport function createSchema(): SchemaBuilder {\n  return new SchemaBuilder();\n}\n\n// ============================================================================\n// Utility Functions\n// ============================================================================\n\n/**\n * Validate configuration with a quick schema.\n */\nexport function validateConfig(\n  config: ConfigRecord,\n  schema: ConfigSchema,\n  options?: ValidatorOptions\n): ValidationResult {\n  const validator = new ConfigValidator(schema, options);\n  return validator.validate(config);\n}\n\n/**\n * Common validation schemas.\n */\nexport const CommonSchemas = {\n  /**\n   * URL field schema.\n   */\n  url: (required = false): ConfigFieldSchema => ({\n    rules: [\n      ...(required ? [{ type: 'required' as const }] : []),\n      { type: 'string' as const },\n      { type: 'url' as const },\n    ],\n  }),\n\n  /**\n   * Email field schema.\n   */\n  email: (required = false): ConfigFieldSchema => ({\n    rules: [\n      ...(required ? [{ type: 'required' as const }] : []),\n      { type: 'string' as const },\n      { type: 'email' as const },\n    ],\n  }),\n\n  /**\n   * Port number schema.\n   */\n  port: (required = false): ConfigFieldSchema => ({\n    rules: [\n      ...(required ? [{ type: 'required' as const }] : []),\n      { type: 'number' as const },\n      { type: 'min' as const, params: 1 },\n      { type: 'max' as const, params: 65535 },\n    ],\n  }),\n\n  /**\n   * Positive number schema.\n   */\n  positiveNumber: (required = false): ConfigFieldSchema => ({\n    rules: [\n      ...(required ? [{ type: 'required' as const }] : []),\n      { type: 'number' as const },\n      { type: 'min' as const, params: 0 },\n    ],\n  }),\n\n  /**\n   * Percentage schema (0-100).\n   */\n  percentage: (required = false): ConfigFieldSchema => ({\n    rules: [\n      ...(required ? [{ type: 'required' as const }] : []),\n      { type: 'number' as const },\n      { type: 'min' as const, params: 0 },\n      { type: 'max' as const, params: 100 },\n    ],\n  }),\n};\n"],"names":["ConfigValidator","schema","options","config","errors","warnings","value","path","rule","error","name","validator","obj","basePath","key","fieldSchema","i","itemPath","itemErrors","type","params","message","customMessage","SchemaBuilder","rules","properties","items","createSchema","validateConfig","CommonSchemas","required"],"mappings":"AAiEO,MAAMA,EAAgB;AAAA,EACV;AAAA,EACA;AAAA,EACT;AAAA,EAER,YAAYC,GAAsBC,IAA4B,IAAI;AAChE,SAAK,SAASD,GACd,KAAK,mBAAmBC,EAAQ,oBAAoB,CAAA,GACpD,KAAK,UAAUA;AAAA,EACjB;AAAA;AAAA;AAAA;AAAA,EAKA,SAASC,GAAwC;AAC/C,UAAMC,IAA4B,CAAA,GAC5BC,IAAqB,CAAA;AAE3B,gBAAK,eAAeF,GAAQ,KAAK,QAAQ,IAAIC,GAAQC,CAAQ,GAEtD;AAAA,MACL,OAAOD,EAAO,WAAW;AAAA,MACzB,QAAAA;AAAA,MACA,UAAAC;AAAA,IAAA;AAAA,EAEJ;AAAA;AAAA;AAAA;AAAA,EAKA,cACEC,GACAL,GACAM,GACmB;AACnB,UAAMH,IAA4B,CAAA;AAElC,QAAIH,EAAO;AACT,iBAAWO,KAAQP,EAAO,OAAO;AAC/B,cAAMQ,IAAQ,KAAK,aAAaH,GAAOE,GAAMD,CAAI;AACjD,YAAIE,MACFL,EAAO,KAAKK,CAAK,GACb,KAAK,QAAQ,qBAAqB;AACpC;AAAA,MAGN;AAGF,WAAOL;AAAA,EACT;AAAA;AAAA;AAAA;AAAA,EAKA,kB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