{"version":3,"sources":["../../src/types/error.ts"],"names":[],"mappings":";AAuFO,SAAS,gBAAgB,KAAA,EAAwC;AACtE,EAAA,OACE,OAAO,UAAU,QAAA,IACjB,KAAA,KAAU,QACV,MAAA,IAAU,KAAA,IACV,OAAQ,KAAA,CAAwB,IAAA,KAAS,QAAA;AAE7C;AA+CO,SAAS,oBACd,OAAA,EACe;AACf,EAAA,MAAM,KAAA,GAAQ,IAAI,KAAA,CAAM,OAAA,CAAQ,OAAO,CAAA;AACvC,EAAA,KAAA,CAAM,IAAA,GAAO,eAAA;AACb,EAAA,KAAA,CAAM,OAAO,OAAA,CAAQ,IAAA;AAErB,EAAA,IAAI,OAAA,CAAQ,IAAA,KAAS,MAAA,EAAW,KAAA,CAAM,OAAO,OAAA,CAAQ,IAAA;AACrD,EAAA,IAAI,OAAA,CAAQ,UAAA,KAAe,MAAA,EAAW,KAAA,CAAM,aAAa,OAAA,CAAQ,UAAA;AACjE,EAAA,IAAI,OAAA,CAAQ,KAAA,KAAU,MAAA,EAAW,KAAA,CAAM,QAAQ,OAAA,CAAQ,KAAA;AACvD,EAAA,IAAI,OAAA,CAAQ,MAAA,KAAW,MAAA,EAAW,KAAA,CAAM,SAAS,OAAA,CAAQ,MAAA;AACzD,EAAA,IAAI,OAAA,CAAQ,MAAA,KAAW,MAAA,EAAW,KAAA,CAAM,SAAS,OAAA,CAAQ,MAAA;AACzD,EAAA,IAAI,OAAA,CAAQ,IAAA,KAAS,MAAA,EAAW,KAAA,CAAM,OAAO,OAAA,CAAQ,IAAA;AACrD,EAAA,IAAI,OAAA,CAAQ,KAAA,KAAU,MAAA,EAAW,KAAA,CAAM,QAAQ,OAAA,CAAQ,KAAA;AAEvD,EAAA,OAAO,KAAA;AACT","file":"index.mjs","sourcesContent":["/**\n * Database error type definitions.\n *\n * @packageDocumentation\n */\n\n/**\n * Database error classification.\n *\n * @remarks\n * Categorizes database errors for consistent error handling across adapters.\n * Each adapter translates database-specific error codes to these kinds.\n *\n * @public\n */\nexport type DatabaseErrorKind =\n  | \"connection\" // Connection/network errors\n  | \"query\" // Syntax or execution errors\n  | \"constraint\" // Generic constraint violation\n  | \"unique_violation\" // Unique constraint violation\n  | \"foreign_key_violation\" // Foreign key constraint violation\n  | \"check_violation\" // Check constraint violation\n  | \"not_null_violation\" // NOT NULL constraint violation\n  | \"deadlock\" // Transaction deadlock\n  | \"timeout\" // Query or connection timeout\n  | \"serialization_failure\" // Serializable transaction conflict\n  | \"unsupported_version\" // F17: DB version below minimum or unparseable at connect\n  | \"unknown\"; // Unclassified error\n\n/**\n * Enhanced database error interface.\n *\n * @remarks\n * Extends the standard Error interface with database-specific context.\n * Adapters should throw errors implementing this interface for consistent\n * error handling.\n *\n * @example\n * ```typescript\n * try {\n *   await adapter.insert('users', { email: 'duplicate@example.com' });\n * } catch (error) {\n *   if (isDatabaseError(error) && error.kind === 'unique_violation') {\n *     console.log(`Duplicate ${error.column} in ${error.table}`);\n *   }\n * }\n * ```\n *\n * @public\n */\nexport interface DatabaseError extends Error {\n  /** Error classification */\n  kind: DatabaseErrorKind;\n\n  /** Database-specific error code (e.g., \"23505\" for PostgreSQL unique violation) */\n  code?: string;\n\n  /** Constraint name that was violated (if applicable) */\n  constraint?: string;\n\n  /** Table name involved in the error */\n  table?: string;\n\n  /** Column name involved in the error */\n  column?: string;\n\n  /** Detailed error description from the database */\n  detail?: string;\n\n  /** Hint for resolving the error */\n  hint?: string;\n\n  /** Original error from the database driver */\n  cause?: Error;\n}\n\n/**\n * Type guard for DatabaseError.\n *\n * @remarks\n * Checks if an error is a DatabaseError with proper typing.\n *\n * @param error - Error to check\n * @returns True if error is a DatabaseError\n *\n * @public\n */\nexport function isDatabaseError(error: unknown): error is DatabaseError {\n  return (\n    typeof error === \"object\" &&\n    error !== null &&\n    \"kind\" in error &&\n    typeof (error as DatabaseError).kind === \"string\"\n  );\n}\n\n/**\n * Database error constructor options.\n *\n * @public\n */\nexport interface DatabaseErrorOptions {\n  /** Error classification */\n  kind: DatabaseErrorKind;\n\n  /** Error message */\n  message: string;\n\n  /** Database-specific error code */\n  code?: string;\n\n  /** Constraint name */\n  constraint?: string;\n\n  /** Table name */\n  table?: string;\n\n  /** Column name */\n  column?: string;\n\n  /** Detailed description */\n  detail?: string;\n\n  /** Resolution hint */\n  hint?: string;\n\n  /** Original error */\n  cause?: Error;\n}\n\n/**\n * Create a DatabaseError instance.\n *\n * @remarks\n * Helper function to create properly structured DatabaseError objects.\n *\n * @param options - Error options\n * @returns DatabaseError instance\n *\n * @public\n */\nexport function createDatabaseError(\n  options: DatabaseErrorOptions\n): DatabaseError {\n  const error = new Error(options.message) as DatabaseError;\n  error.name = \"DatabaseError\";\n  error.kind = options.kind;\n\n  if (options.code !== undefined) error.code = options.code;\n  if (options.constraint !== undefined) error.constraint = options.constraint;\n  if (options.table !== undefined) error.table = options.table;\n  if (options.column !== undefined) error.column = options.column;\n  if (options.detail !== undefined) error.detail = options.detail;\n  if (options.hint !== undefined) error.hint = options.hint;\n  if (options.cause !== undefined) error.cause = options.cause;\n\n  return error;\n}\n"]}