{"version":3,"file":"detail.cjs","names":[],"sources":["../../src/error/detail.ts"],"sourcesContent":["/** reference: https://github.com/googleapis/googleapis/blob/master/google/rpc/error_details.proto */\nimport type { ResolvedErrorReason } from './reason';\n\nexport const DetailType = {\n  ERROR_INFO: 'type.googleapis.com/google.rpc.ErrorInfo',\n  RETRY_INFO: 'type.googleapis.com/google.rpc.RetryInfo',\n  DEBUG_INFO: 'type.googleapis.com/google.rpc.DebugInfo',\n  QUOTA_FAILURE: 'type.googleapis.com/google.rpc.QuotaFailure',\n  PRECONDITION_FAILURE: 'type.googleapis.com/google.rpc.PreconditionFailure',\n  BAD_REQUEST: 'type.googleapis.com/google.rpc.BadRequest',\n  REQUEST_INFO: 'type.googleapis.com/google.rpc.RequestInfo',\n  RESOURCE_INFO: 'type.googleapis.com/google.rpc.ResourceInfo',\n  HELP: 'type.googleapis.com/google.rpc.Help',\n  LOCALIZED_MESSAGE: 'type.googleapis.com/google.rpc.LocalizedMessage',\n} as const;\n\nexport type DetailType = (typeof DetailType)[keyof typeof DetailType];\n\nexport interface ErrorInfo {\n  '@type': typeof DetailType.ERROR_INFO;\n  reason: ResolvedErrorReason;\n  domain?: string;\n  metadata?: Record<string, string>;\n}\n\nexport interface RetryInfo {\n  '@type': typeof DetailType.RETRY_INFO;\n  retryDelay: number;\n}\n\nexport interface DebugInfo {\n  '@type': typeof DetailType.DEBUG_INFO;\n  stackEntries: string[];\n  detail: string;\n}\n\nexport interface QuotaFailure {\n  '@type': typeof DetailType.QUOTA_FAILURE;\n  violations: {\n    subject: string;\n    description: string;\n    apiService: string;\n    quoteId: string;\n    quoteValue: number;\n    quotaMetric: string;\n    quotaDimensions: Record<string, string>;\n    futureQuotaValue: number;\n  }[];\n}\n\nexport interface PreconditionFailure {\n  '@type': typeof DetailType.PRECONDITION_FAILURE;\n  violations: { type: string; subject: string; description: string }[];\n}\n\nexport interface BadRequest {\n  '@type': typeof DetailType.BAD_REQUEST;\n  fieldViolations: {\n    field: string;\n    description: string;\n    reason: string;\n    localizedMessage: Omit<LocalizedMessage, '@type'>;\n  }[];\n}\n\nexport interface RequestInfo {\n  '@type': typeof DetailType.REQUEST_INFO;\n  requestId: string;\n  servingData: string;\n}\n\nexport interface ResourceInfo {\n  '@type': typeof DetailType.RESOURCE_INFO;\n  resourceType: string;\n  resourceName: string;\n  owner: string;\n  description: string;\n}\n\nexport interface Help {\n  '@type': typeof DetailType.HELP;\n  links: { url: string; description: string }[];\n}\n\nexport interface LocalizedMessage {\n  '@type': typeof DetailType.LOCALIZED_MESSAGE;\n  locale: string;\n  message: string;\n}\n\nexport type Detail =\n  | RetryInfo\n  | DebugInfo\n  | QuotaFailure\n  | ErrorInfo\n  | PreconditionFailure\n  | BadRequest\n  | RequestInfo\n  | ResourceInfo\n  | Help\n  | LocalizedMessage;\n\n/**\n * Example usage:\n * const details = Details.new()\n *   .requestInfo({ requestId: '1234567890', servingData: '/v1/tests' })\n *   .errorInfo({ reason: 'ACCOUNT_LOCKED' });\n * */\nexport class Details {\n  readonly list: Detail[] = [];\n  private constructor() {}\n\n  static new() {\n    return new Details();\n  }\n\n  errorInfo(detail: Omit<ErrorInfo, '@type'>) {\n    this.list.push({ '@type': DetailType.ERROR_INFO, ...detail });\n    return this;\n  }\n\n  retryInfo(detail: Omit<RetryInfo, '@type'>) {\n    this.list.push({ '@type': DetailType.RETRY_INFO, ...detail });\n    return this;\n  }\n\n  debugInfo(detail: Omit<DebugInfo, '@type'>) {\n    this.list.push({ '@type': DetailType.DEBUG_INFO, ...detail });\n    return this;\n  }\n\n  quotaFailure(detail: Omit<QuotaFailure, '@type'>) {\n    this.list.push({ '@type': DetailType.QUOTA_FAILURE, ...detail });\n    return this;\n  }\n\n  preconditionFailure(detail: Omit<PreconditionFailure, '@type'>) {\n    this.list.push({ '@type': DetailType.PRECONDITION_FAILURE, ...detail });\n    return this;\n  }\n\n  badRequest(detail: Omit<BadRequest, '@type'>) {\n    this.list.push({ '@type': DetailType.BAD_REQUEST, ...detail });\n    return this;\n  }\n\n  requestInfo(detail: Omit<RequestInfo, '@type'>) {\n    this.list.push({ '@type': DetailType.REQUEST_INFO, ...detail });\n    return this;\n  }\n\n  resourceInfo(detail: Omit<ResourceInfo, '@type'>) {\n    this.list.push({ '@type': DetailType.RESOURCE_INFO, ...detail });\n    return this;\n  }\n\n  help(detail: Omit<Help, '@type'>) {\n    this.list.push({ '@type': DetailType.HELP, ...detail });\n    return this;\n  }\n\n  localizedMessage(detail: Omit<LocalizedMessage, '@type'>) {\n    this.list.push({ '@type': DetailType.LOCALIZED_MESSAGE, ...detail });\n    return this;\n  }\n}\n"],"mappings":";;AAGA,MAAa,aAAa;CACxB,YAAY;CACZ,YAAY;CACZ,YAAY;CACZ,eAAe;CACf,sBAAsB;CACtB,aAAa;CACb,cAAc;CACd,eAAe;CACf,MAAM;CACN,mBAAmB;AACrB;;;;;;;AA8FA,IAAa,UAAb,MAAa,QAAQ;CACnB,OAA0B,CAAC;CAC3B,cAAsB,CAAC;CAEvB,OAAO,MAAM;EACX,OAAO,IAAI,QAAQ;CACrB;CAEA,UAAU,QAAkC;EAC1C,KAAK,KAAK,KAAK;GAAE,SAAS,WAAW;GAAY,GAAG;EAAO,CAAC;EAC5D,OAAO;CACT;CAEA,UAAU,QAAkC;EAC1C,KAAK,KAAK,KAAK;GAAE,SAAS,WAAW;GAAY,GAAG;EAAO,CAAC;EAC5D,OAAO;CACT;CAEA,UAAU,QAAkC;EAC1C,KAAK,KAAK,KAAK;GAAE,SAAS,WAAW;GAAY,GAAG;EAAO,CAAC;EAC5D,OAAO;CACT;CAEA,aAAa,QAAqC;EAChD,KAAK,KAAK,KAAK;GAAE,SAAS,WAAW;GAAe,GAAG;EAAO,CAAC;EAC/D,OAAO;CACT;CAEA,oBAAoB,QAA4C;EAC9D,KAAK,KAAK,KAAK;GAAE,SAAS,WAAW;GAAsB,GAAG;EAAO,CAAC;EACtE,OAAO;CACT;CAEA,WAAW,QAAmC;EAC5C,KAAK,KAAK,KAAK;GAAE,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