{"version":3,"file":"error-Cp5qYZcv.mjs","names":[],"sources":["../src/error.ts"],"sourcesContent":["import type { ParseError } from \"./types.js\";\n\nconst BRAND = Symbol.for(\"@smonn/ids/IdsError\");\n\n/**\n * The stable machine-readable failure reason carried by `IdsError`.\n * Use `code` — not `message` — for programmatic branching; `message` is non-contractual.\n * Adding a new member is minor-additive; renaming or removing one is breaking.\n */\nexport type IdsErrorCode =\n  | \"invalid_brand\"\n  | \"invalid_key_format\"\n  | \"invalid_key_encoding\"\n  | \"invalid_key_length\"\n  | \"invalid_kind\"\n  | \"empty_keyring\"\n  | \"duplicate_keyring_entry\"\n  | \"invalid_lookup_key\"\n  | \"verification_failed\"\n  | \"invalid_id\"\n  | \"invalid_namespace\"\n  | \"invalid_timestamp\";\n\n/**\n * The single error class thrown by caller-reachable public failures.\n * Carries a stable `readonly code: IdsErrorCode` for programmatic discrimination.\n * Recognized via `isIdsError()` — a branded guard that survives realm/dual-package duplication\n * where bare `instanceof` would silently fail.\n *\n * @example\n * ```ts\n * try {\n *   usr.parse(rawInput);\n * } catch (err) {\n *   if (isIdsError(err) && err.code === \"invalid_id\") return; // handle parse failure\n * }\n * ```\n */\nexport class IdsError extends Error {\n  readonly code: IdsErrorCode;\n  /**\n   * Populated when `code === \"invalid_id\"` (carrying the originating `ParseError` string)\n   * or when `code === \"invalid_key_encoding\"` (carrying the original decode `Error`).\n   * All other codes leave `cause` undefined.\n   */\n  declare readonly cause?: ParseError | Error;\n\n  constructor(code: IdsErrorCode, message: string, options?: { cause?: ParseError | Error }) {\n    super(message, options);\n    this.name = \"IdsError\";\n    this.code = code;\n    Object.defineProperty(this, BRAND, {\n      value: true,\n      enumerable: false,\n      configurable: false,\n      writable: false,\n    });\n  }\n}\n\n/**\n * Type guard for `IdsError`. Checks a non-enumerable brand rather than bare `instanceof`\n * so it survives realm/dual-package duplication (ESM + CJS dual package hazard).\n *\n * @example\n * ```ts\n * if (isIdsError(err)) {\n *   switch (err.code) {\n *     case \"verification_failed\": // ...\n *     case \"invalid_id\": // ...\n *   }\n * }\n * ```\n */\nexport function isIdsError(value: unknown): value is IdsError {\n  return (\n    typeof value === \"object\" &&\n    value !== null &&\n    (value as Record<symbol, unknown>)[BRAND] === true\n  );\n}\n"],"mappings":";AAEA,MAAM,QAAQ,OAAO,IAAI,qBAAqB;;;;;;;;;;;;;;;;AAoC9C,IAAa,WAAb,cAA8B,MAAM;CAClC;CAQA,YAAY,MAAoB,SAAiB,SAA0C;EACzF,MAAM,SAAS,OAAO;EACtB,KAAK,OAAO;EACZ,KAAK,OAAO;EACZ,OAAO,eAAe,MAAM,OAAO;GACjC,OAAO;GACP,YAAY;GACZ,cAAc;GACd,UAAU;EACZ,CAAC;CACH;AACF;;;;;;;;;;;;;;;AAgBA,SAAgB,WAAW,OAAmC;CAC5D,OACE,OAAO,UAAU,YACjB,UAAU,QACT,MAAkC,WAAW;AAElD"}