{ "version": 3, "sources": ["src/app/shared/rxjs/custom-operators.ts"], "sourcesContent": ["import {\n HttpErrorResponse,\n HttpEvent,\n HttpEventType,\n HttpResponse\n} from '@angular/common/http';\nimport {\n EMPTY,\n MonoTypeOperatorFunction,\n Observable,\n UnaryFunction,\n of,\n pipe,\n throwError,\n timer\n} from 'rxjs';\nimport { RetryConfig, catchError, filter, map, tap } from 'rxjs/operators';\nimport { LivErrorResponse } from 'src/app/core/models/liv-response-protocol.model';\n\ninterface LivCatchErrorOptions {\n throw?: boolean;\n}\n\nexport function filterResponse(): UnaryFunction<\n Observable>,\n Observable\n> {\n return pipe(\n filter((event: HttpEvent) => event.type === HttpEventType.Response),\n map((response: HttpResponse) => response.body)\n );\n}\n\nexport function uploadProgress(\n cb: (progress: number) => void\n): MonoTypeOperatorFunction> {\n return tap((event: HttpEvent) => {\n if (event.type === HttpEventType.UploadProgress) {\n cb(Math.round((event.loaded * 100) / event.total));\n }\n });\n}\n\nexport function customCatchError(\n cb: (error: LivErrorResponse['error']) => void,\n options: LivCatchErrorOptions & { fallbackValue?: T } = {\n throw: false\n }\n): MonoTypeOperatorFunction {\n return pipe(\n catchError((error: LivErrorResponse) => {\n cb(error?.error);\n\n if (options.throw) {\n return throwError(() => error);\n }\n\n // Retorna o valor de fallback ou EMPTY como padrĂ£o\n return options.fallbackValue !== undefined\n ? of(options.fallbackValue)\n : EMPTY;\n })\n );\n}\n\nexport function shouldRetry({\n maxRetryAttempts = 3,\n scalingDuration = 1000,\n excludedStatusCodes = []\n}: GenericRetryStrategy = {}): RetryConfig {\n return {\n count: maxRetryAttempts,\n delay(error, retryAttempt) {\n const err = error as HttpErrorResponse;\n if (\n retryAttempt > maxRetryAttempts ||\n excludedStatusCodes.some((statusCode) => statusCode === err.status)\n ) {\n return throwError(() => err);\n }\n return timer(retryAttempt * scalingDuration);\n }\n } as RetryConfig;\n}\n\ntype GenericRetryStrategy = {\n maxRetryAttempts?: number;\n scalingDuration?: number;\n excludedStatusCodes?: number[];\n};\n"], "mappings": ";;;;;;;;;;;;;;AAuBM,SAAU,iBAAc;AAI5B,SAAO,KACL,OAAO,CAAC,UAAwB,MAAM,SAAS,cAAc,QAAQ,GACrE,IAAI,CAAC,aAA8B,SAAS,IAAI,CAAC;AAErD;AAEM,SAAU,eACd,IAA8B;AAE9B,SAAO,IAAI,CAAC,UAAuB;AACjC,QAAI,MAAM,SAAS,cAAc,gBAAgB;AAC/C,SAAG,KAAK,MAAO,MAAM,SAAS,MAAO,MAAM,KAAK,CAAC;IACnD;EACF,CAAC;AACH;AAEM,SAAU,iBACd,IACA,UAAwD;EACtD,OAAO;GACR;AAED,SAAO,KACL,WAAW,CAAC,UAA2B;AACrC,OAAG,OAAO,KAAK;AAEf,QAAI,QAAQ,OAAO;AACjB,aAAO,WAAW,MAAM,KAAK;IAC/B;AAGA,WAAO,QAAQ,kBAAkB,SAC7B,GAAG,QAAQ,aAAa,IACxB;EACN,CAAC,CAAC;AAEN;AAEM,SAAU,YAAY,EAC1B,mBAAmB,GACnB,kBAAkB,KAClB,sBAAsB,CAAA,EAAE,IACA,CAAA,GAAE;AAC1B,SAAO;IACL,OAAO;IACP,MAAM,OAAO,cAAY;AACvB,YAAM,MAAM;AACZ,UACE,eAAe,oBACf,oBAAoB,KAAK,CAAC,eAAe,eAAe,IAAI,MAAM,GAClE;AACA,eAAO,WAAW,MAAM,GAAG;MAC7B;AACA,aAAO,MAAM,eAAe,eAAe;IAC7C;;AAEJ;", "names": [] }