{"version":3,"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 enum 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}\n\nexport interface ErrorInfo {\n  '@type': DetailType.ERROR_INFO;\n  reason: ResolvedErrorReason;\n  domain?: string;\n  metadata?: Record<string, string>;\n}\n\nexport interface RetryInfo {\n  '@type': DetailType.RETRY_INFO;\n  retryDelay: number;\n}\n\nexport interface DebugInfo {\n  '@type': DetailType.DEBUG_INFO;\n  stackEntries: string[];\n  detail: string;\n}\n\nexport interface QuotaFailure {\n  '@type': 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': DetailType.PRECONDITION_FAILURE;\n  violations: { type: string; subject: string; description: string }[];\n}\n\nexport interface BadRequest {\n  '@type': 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': DetailType.REQUEST_INFO;\n  requestId: string;\n  servingData: string;\n}\n\nexport interface ResourceInfo {\n  '@type': DetailType.RESOURCE_INFO;\n  resourceType: string;\n  resourceName: string;\n  owner: string;\n  description: string;\n}\n\nexport interface Help {\n  '@type': DetailType.HELP;\n  links: { url: string; description: string }[];\n}\n\nexport interface LocalizedMessage {\n  '@type': 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":";AAGO,IAAK,aAAL,kBAAKA,gBAAL;AACL,EAAAA,YAAA,gBAAa;AACb,EAAAA,YAAA,gBAAa;AACb,EAAAA,YAAA,gBAAa;AACb,EAAAA,YAAA,mBAAgB;AAChB,EAAAA,YAAA,0BAAuB;AACvB,EAAAA,YAAA,iBAAc;AACd,EAAAA,YAAA,kBAAe;AACf,EAAAA,YAAA,mBAAgB;AAChB,EAAAA,YAAA,UAAO;AACP,EAAAA,YAAA,uBAAoB;AAVV,SAAAA;AAAA,GAAA;AAuGL,IAAM,UAAN,MAAM,SAAQ;AAAA,EACV,OAAiB,CAAC;AAAA,EACnB,cAAc;AAAA,EAAC;AAAA,EAEvB,OAAO,MAAM;AACX,WAAO,IAAI,SAAQ;AAAA,EACrB;AAAA,EAEA,UAAU,QAAkC;AAC1C,SAAK,KAAK,KAAK,EAAE,SAAS,6DAAuB,GAAG,OAAO,CAAC;AAC5D,WAAO;AAAA,EACT;AAAA,EAEA,UAAU,QAAkC;AAC1C,SAAK,KAAK,KAAK,EAAE,SAAS,6DAAuB,GAAG,OAAO,CAAC;AAC5D,WAAO;AAAA,EACT;AAAA,EAEA,UAAU,QAAkC;AAC1C,SAAK,KAAK,KAAK,EAAE,SAAS,6DAAuB,GAAG,OAAO,CAAC;AAC5D,WAAO;AAAA,EACT;AAAA,EAEA,aAAa,QAAqC;AAChD,SAAK,KAAK,KAAK,EAAE,SAAS,mEAA0B,GAAG,OAAO,CAAC;AAC/D,WAAO;AAAA,EACT;AAAA,EAEA,oBAAoB,QAA4C;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