From 10d20edbaa8619d84d0527cdab5a6bf7c492cc50 Mon Sep 17 00:00:00 2001 From: "Eric J. Smith" Date: Thu, 9 May 2024 00:19:55 -0500 Subject: [PATCH] Fix linting errors --- src/FetchClient.test.ts | 1 - src/FetchClient.ts | 10 ++++++++++ src/FetchClientProvider.ts | 9 ++++++--- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/FetchClient.test.ts b/src/FetchClient.test.ts index 66e5532..954adfa 100644 --- a/src/FetchClient.test.ts +++ b/src/FetchClient.test.ts @@ -1,6 +1,5 @@ import { assert, assertEquals, assertFalse } from "@std/assert"; import { - defaultProvider, defaultProvider as provider, FetchClient, ProblemDetails, diff --git a/src/FetchClient.ts b/src/FetchClient.ts index fa45e3b..9058bda 100644 --- a/src/FetchClient.ts +++ b/src/FetchClient.ts @@ -120,6 +120,16 @@ export class FetchClient { return this.requestCount > 0; } + /** + * Adds one or more middleware functions to the FetchClient's middleware pipeline. + * Middleware functions are executed in the order they are added. + * + * @param mw - The middleware functions to add. + */ + public use(...mw: FetchClientMiddleware[]): void { + this.#middleware.push(...mw); + } + /** * Sends a GET request to the specified URL. * diff --git a/src/FetchClientProvider.ts b/src/FetchClientProvider.ts index 82b7b74..24f74e3 100644 --- a/src/FetchClientProvider.ts +++ b/src/FetchClientProvider.ts @@ -80,10 +80,11 @@ export class FetchClientProvider { /** * Creates a new instance of FetchClient using the current provider. + * @param options - The options to use for the new FetchClient instance. Options provided here will override the default options set on the provider. * @returns A new instance of FetchClient. */ - public getFetchClient(): FetchClient { - return new FetchClient({ + public getFetchClient(options?: FetchClientOptions): FetchClient { + const o = { defaultRequestOptions: this.#options.defaultRequestOptions, baseUrl: this.#options.baseUrl, cache: this.#cache, @@ -92,7 +93,9 @@ export class FetchClientProvider { modelValidator: this.#options.modelValidator, accessTokenFunc: this.#options.accessTokenFunc, providerCounter: this.#counter, - }); + }; + options = { ...o, ...options }; + return new FetchClient(options); } /**