{"version":3,"file":"ngx-forkable-http-client.mjs","sources":["../../../lib/src/http-interceptor-handler.ts","../../../lib/src/forkable-http-client.ts","../../../lib/src/forkable-http-client-factory-builder.ts","../../../lib/ngx-forkable-http-client.ts"],"sourcesContent":["import { HttpEvent, HttpHandler, HttpInterceptor, HttpRequest } from '@angular/common/http';\nimport { Observable } from 'rxjs';\n\nexport function createInterceptorHandler(baseHandler: HttpHandler, interceptors: HttpInterceptor[]): HttpHandler {\n    return interceptors.reduceRight((next, interceptor) => new HttpInterceptorHandler(next, interceptor), baseHandler);\n}\n\nexport class HttpInterceptorHandler implements HttpHandler {\n    constructor(\n        private readonly next: HttpHandler,\n        private readonly interceptor: HttpInterceptor,\n    ) {}\n\n    public handle(request: HttpRequest<unknown>): Observable<HttpEvent<unknown>> {\n        return this.interceptor.intercept(request, this.next);\n    }\n}\n","import { Injectable, Inject, Optional } from '@angular/core';\nimport { HTTP_INTERCEPTORS, HttpBackend, HttpClient, HttpHandler, HttpInterceptor } from '@angular/common/http';\n\nimport { createInterceptorHandler } from './http-interceptor-handler';\n\n@Injectable({ providedIn: 'root' })\nexport class ForkableHttpClient extends HttpClient {\n    private readonly interceptors: HttpInterceptor[];\n\n    constructor(\n        @Inject(HttpBackend) private readonly baseHandler: HttpHandler,\n        @Optional() @Inject(HTTP_INTERCEPTORS) interceptors: HttpInterceptor[] | null,\n    ) {\n        super(createInterceptorHandler(baseHandler, interceptors || []));\n        this.interceptors = interceptors || [];\n    }\n\n    public fork(...interceptors: HttpInterceptor[]): ForkableHttpClient {\n        return new ForkableHttpClient(this.baseHandler, [...this.interceptors, ...interceptors]);\n    }\n}\n\nexport function forkHttpClient(parent: ForkableHttpClient, ...interceptors: HttpInterceptor[]): ForkableHttpClient {\n    return parent.fork(...interceptors);\n}\n","import { InjectionToken, Type, inject } from '@angular/core';\nimport { HttpInterceptor } from '@angular/common/http';\n\nimport { ForkableHttpClient } from './forkable-http-client';\n\n/** Token that can be used for injecting values that conform to the `HttpInterceptor` interface. */\nexport type HttpInterceptorInjectionToken = Type<HttpInterceptor> | InjectionToken<HttpInterceptor>;\n\n/** Factory function that creates a new `ForkableHttpClient` instance. */\nexport type ForkableHttpClientFactory = (() => ForkableHttpClient) & {\n    /**\n     * Adds extra interceptors to the HTTP client that will be created when the factory function is called.\n     *\n     * @param   interceptors HTTP interceptors that should be added.\n     * @returns              Factory function itself.\n     */\n    with(...interceptors: HttpInterceptorInjectionToken[]): ForkableHttpClientFactory;\n};\n\n/**\n * Creates a factory function that can be used for the factory of a self-providing `InjectionToken` for `ForkableHttpClient`.\n *\n * @param   parent Optional parent `ForkableHttpClient` which should be forked to create the new `ForkableHttpClient` instance. If no\n *                 argument is provided for this parameter, then the default 'root' ForkableHttpClient will be used.\n * @returns        A factory function that creates and returns a new `ForkableHttpClient` instance. The factory function also has a `with`\n *                 function that can be called to add extra interceptors to the new HTTP client.\n */\nexport function httpClient(parent?: InjectionToken<ForkableHttpClient>): ForkableHttpClientFactory {\n    const interceptors: HttpInterceptorInjectionToken[] = [];\n\n    const factory = (() => {\n\n        return inject(parent || ForkableHttpClient).fork(...interceptors.map((interceptor) => inject(interceptor)));\n\n    }) as ForkableHttpClientFactory;\n\n    factory.with = (...interceptorsToAdd: HttpInterceptorInjectionToken[]) => {\n        interceptors.push(...interceptorsToAdd);\n\n        return factory;\n    };\n\n    return factory;\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;;SAGgB,wBAAwB,CAAC,WAAwB,EAAE,YAA+B;IAC9F,OAAO,YAAY,CAAC,WAAW,CAAC,CAAC,IAAI,EAAE,WAAW,KAAK,IAAI,sBAAsB,CAAC,IAAI,EAAE,WAAW,CAAC,EAAE,WAAW,CAAC,CAAC;AACvH,CAAC;MAEY,sBAAsB;IAC/B,YACqB,IAAiB,EACjB,WAA4B;QAD5B,SAAI,GAAJ,IAAI,CAAa;QACjB,gBAAW,GAAX,WAAW,CAAiB;KAC7C;IAEG,MAAM,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