{"version":3,"sources":["../../../src/internals/helpers/counter.ts"],"names":["RetryCounter","Serializable","remaining","maxRetries","lastError","finalError","constructor","ErrorClass","use","error","undefined","isFatal","isRetryable","createSnapshot","loadSnapshot","snapshot","Object","assign"],"mappings":";;;;;;AAmBO,MAAMA,qBAAqBC,6BAAAA,CAAAA;EAnBlC;;;;AAoBSC,EAAAA,SAAAA;AACYC,EAAAA,UAAAA;AACTC,EAAAA,SAAAA;AACAC,EAAAA,UAAAA;EAEVC,WACEH,CAAAA,UAAAA,GAAa,GACHI,UACV,EAAA;AACA,IAAK,KAAA,EAAA,EAAA,KAFKA,UAAAA,GAAAA,UAAAA;AAGV,IAAA,IAAA,CAAKJ,UAAaA,GAAAA,UAAAA;AAClB,IAAA,IAAA,CAAKD,SAAYC,GAAAA,UAAAA;AACnB;AAEAK,EAAAA,GAAAA,CAAIC,KAAe,EAAA;AACjB,IAAA,IAAI,KAAKJ,UAAY,EAAA;AACnB,MAAA,MAAM,IAAKA,CAAAA,UAAAA;AACb;AAEA,IAAKD,IAAAA,CAAAA,SAAAA,GAAYK,SAAS,IAAKL,CAAAA,SAAAA;AAC/B,IAAKF,IAAAA,CAAAA,SAAAA,EAAAA;AACL,IAAI,IAAA,IAAA,CAAKA,YAAY,CAAG,EAAA;AACtB,MAAKG,IAAAA,CAAAA,UAAAA,GAAa,IAAI,IAAKE,CAAAA,UAAAA,CACzB,qCAAqC,IAAKJ,CAAAA,UAAU,CACpD,mBAAA,CAAA,EAAA,IAAA,CAAKC,SAAY,GAAA;QAAC,IAAKA,CAAAA;UAAaM,MACpC,EAAA;QAAEC,OAAS,EAAA,IAAA;QAAMC,WAAa,EAAA;OAAM,CAAA;AAEtC,MAAA,MAAM,IAAKP,CAAAA,UAAAA;AACb;AACF;EAEAQ,cAAiB,GAAA;AACf,IAAO,OAAA;AACLX,MAAAA,SAAAA,EAAW,IAAKA,CAAAA,SAAAA;AAChBC,MAAAA,UAAAA,EAAY,IAAKA,CAAAA,UAAAA;AACjBC,MAAAA,SAAAA,EAAW,IAAKA,CAAAA,SAAAA;AAChBC,MAAAA,UAAAA,EAAY,IAAKA,CAAAA,UAAAA;AACjBE,MAAAA,UAAAA,EAAY,IAAKA,CAAAA;AACnB,KAAA;AACF;AAEAO,EAAAA,YAAAA,CAAaC,QAAkD,EAAA;AAC7DC,IAAOC,MAAAA,CAAAA,MAAAA,CAAO,MAAMF,QAAAA,CAAAA;AACtB;AACF","file":"counter.cjs","sourcesContent":["/**\n * Copyright 2025 IBM Corp.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { FrameworkError } from \"@/errors.js\";\nimport { Serializable } from \"@/internals/serializable.js\";\n\nexport class RetryCounter extends Serializable {\n  public remaining: number;\n  protected readonly maxRetries: number;\n  protected lastError?: Error;\n  protected finalError?: Error;\n\n  constructor(\n    maxRetries = 0,\n    protected ErrorClass: typeof FrameworkError,\n  ) {\n    super();\n    this.maxRetries = maxRetries;\n    this.remaining = maxRetries;\n  }\n\n  use(error?: Error) {\n    if (this.finalError) {\n      throw this.finalError;\n    }\n\n    this.lastError = error ?? this.lastError;\n    this.remaining--;\n    if (this.remaining < 0) {\n      this.finalError = new this.ErrorClass(\n        `Maximal amount of global retries (${this.maxRetries}) has been reached.`,\n        this.lastError ? [this.lastError] : undefined,\n        { isFatal: true, isRetryable: false },\n      );\n      throw this.finalError;\n    }\n  }\n\n  createSnapshot() {\n    return {\n      remaining: this.remaining,\n      maxRetries: this.maxRetries,\n      lastError: this.lastError,\n      finalError: this.finalError,\n      ErrorClass: this.ErrorClass,\n    };\n  }\n\n  loadSnapshot(snapshot: ReturnType<typeof this.createSnapshot>) {\n    Object.assign(this, snapshot);\n  }\n}\n"]}