@hyper-fetch/core 8.2.0 → 8.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -4
- package/__tests__/e2e/e2e.advanced.spec.ts +7 -7
- package/__tests__/features/adapter/adapter.base.spec.ts +2 -1
- package/__tests__/features/adapter/adapter.bindings.spec.ts +4 -4
- package/__tests__/features/adapter/adapter.browser.spec.ts +0 -1
- package/__tests__/features/adapter/adapter.server.spec.ts +4 -5
- package/__tests__/features/adapter/adapter.utils.spec.ts +6 -7
- package/__tests__/features/cache/cache.base.spec.ts +7 -7
- package/__tests__/features/cache/cache.events.spec.ts +15 -15
- package/__tests__/features/cache/cache.garbage-collector.spec.ts +18 -18
- package/__tests__/features/cache/cache.lazy-storage.spec.ts +8 -8
- package/__tests__/features/cache/cache.modes.spec.ts +7 -6
- package/__tests__/features/cache/cache.scoping.spec.ts +12 -8
- package/__tests__/features/cache/cache.typescript.spec.ts +2 -2
- package/__tests__/features/cache/cache.utils.spec.ts +14 -14
- package/__tests__/features/client/client.auth.spec.ts +0 -1
- package/__tests__/features/client/client.base.spec.ts +2 -3
- package/__tests__/features/client/client.from-json.spec.ts +0 -1
- package/__tests__/features/client/client.hydration.spec.ts +5 -5
- package/__tests__/features/client/client.interceptor.spec.ts +3 -3
- package/__tests__/features/client/client.methods.spec.ts +5 -5
- package/__tests__/features/client/client.middleware.spec.ts +2 -2
- package/__tests__/features/client/client.utils.spec.ts +16 -15
- package/__tests__/features/dispatcher/dispatcher.base.spec.ts +3 -3
- package/__tests__/features/dispatcher/dispatcher.custom-storage.spec.ts +4 -5
- package/__tests__/features/dispatcher/dispatcher.events.spec.ts +4 -4
- package/__tests__/features/dispatcher/dispatcher.queue.spec.ts +13 -13
- package/__tests__/features/dispatcher/dispatcher.requests.spec.ts +10 -10
- package/__tests__/features/dispatcher/dispatcher.utils.spec.ts +35 -8
- package/__tests__/features/managers/app/app.manager.base.spec.ts +2 -3
- package/__tests__/features/managers/logger/logger.base.spec.ts +1 -2
- package/__tests__/features/managers/request/request.manager.base.spec.ts +8 -9
- package/__tests__/features/managers/request/request.manager.events.spec.ts +1 -2
- package/__tests__/features/mocker/mocker.base.spec.ts +6 -6
- package/__tests__/features/plugin/plugin.base.spec.ts +1 -2
- package/__tests__/features/request/request.cloning.spec.ts +0 -1
- package/__tests__/features/request/request.deduplicate-defaults.spec.ts +79 -0
- package/__tests__/features/request/request.retry-on-error.spec.ts +1 -2
- package/__tests__/features/request/request.sending.spec.ts +73 -24
- package/__tests__/features/request/request.setters.spec.ts +4 -3
- package/__tests__/features/request/request.typescript.spec.ts +0 -1
- package/__tests__/features/request/request.utils.spec.ts +1 -0
- package/__tests__/features/sdk/sdk.base.spec.ts +0 -1
- package/__tests__/features/sdk/sdk.request-fields.spec.ts +80 -0
- package/__tests__/features/sdk/sdk.types.spec.ts +3 -4
- package/__tests__/shared/callbacks.shared.ts +1 -1
- package/__tests__/tsconfig.json +4 -17
- package/__tests__/utils/adapter.utils.ts +1 -2
- package/__tests__/utils/callbacks.utils.ts +1 -2
- package/__tests__/utils/dispatcher.utils.ts +1 -1
- package/__tests__/vitest.setup.ts +1 -1
- package/dist/adapter/adapter.d.ts +4 -4
- package/dist/adapter/adapter.d.ts.map +1 -1
- package/dist/adapter/adapter.types.d.ts +1 -1
- package/dist/adapter/adapter.types.d.ts.map +1 -1
- package/dist/adapter/adapter.utils.d.ts.map +1 -1
- package/dist/cache/cache.d.ts +3 -3
- package/dist/cache/cache.d.ts.map +1 -1
- package/dist/cache/cache.events.d.ts +2 -2
- package/dist/cache/cache.events.d.ts.map +1 -1
- package/dist/client/client.create.d.ts +1 -1
- package/dist/client/client.create.d.ts.map +1 -1
- package/dist/client/client.d.ts +3 -3
- package/dist/client/client.d.ts.map +1 -1
- package/dist/client/client.types.d.ts +1 -1
- package/dist/client/client.types.d.ts.map +1 -1
- package/dist/client/client.utils.d.ts.map +1 -1
- package/dist/constants/http.constants.d.ts +5 -1
- package/dist/constants/http.constants.d.ts.map +1 -1
- package/dist/constants/time.constants.d.ts.map +1 -1
- package/dist/dispatcher/dispatcher.d.ts +3 -3
- package/dist/dispatcher/dispatcher.d.ts.map +1 -1
- package/dist/dispatcher/dispatcher.events.d.ts +1 -1
- package/dist/dispatcher/dispatcher.events.d.ts.map +1 -1
- package/dist/dispatcher/dispatcher.utils.d.ts +1 -1
- package/dist/dispatcher/dispatcher.utils.d.ts.map +1 -1
- package/dist/http-adapter/http-adapter.constants.d.ts.map +1 -1
- package/dist/http-adapter/http-adapter.d.ts.map +1 -1
- package/dist/http-adapter/http-adapter.fetch.d.ts +2 -2
- package/dist/http-adapter/http-adapter.fetch.d.ts.map +1 -1
- package/dist/http-adapter/http-adapter.types.d.ts +2 -2
- package/dist/http-adapter/http-adapter.types.d.ts.map +1 -1
- package/dist/http-adapter/http-adapter.utils.d.ts.map +1 -1
- package/dist/index.mjs +2363 -2347
- package/dist/index.mjs.map +1 -1
- package/dist/managers/app/app.manager.constants.d.ts +1 -1
- package/dist/managers/app/app.manager.constants.d.ts.map +1 -1
- package/dist/managers/app/app.manager.d.ts +1 -1
- package/dist/managers/app/app.manager.d.ts.map +1 -1
- package/dist/managers/app/app.manager.events.d.ts.map +1 -1
- package/dist/managers/logger/logger.manager.d.ts +1 -1
- package/dist/managers/logger/logger.manager.d.ts.map +1 -1
- package/dist/managers/request/request.manager.d.ts.map +1 -1
- package/dist/managers/request/request.manager.events.d.ts +2 -2
- package/dist/managers/request/request.manager.events.d.ts.map +1 -1
- package/dist/plugin/plugin.d.ts +1 -1
- package/dist/plugin/plugin.d.ts.map +1 -1
- package/dist/plugin/plugin.types.d.ts +4 -4
- package/dist/plugin/plugin.types.d.ts.map +1 -1
- package/dist/request/request.d.ts +5 -4
- package/dist/request/request.d.ts.map +1 -1
- package/dist/request/request.hooks.d.ts +2 -2
- package/dist/request/request.hooks.d.ts.map +1 -1
- package/dist/request/request.types.d.ts +3 -3
- package/dist/request/request.types.d.ts.map +1 -1
- package/dist/request/request.utils.d.ts.map +1 -1
- package/dist/sdk/sdk.d.ts +1 -1
- package/dist/sdk/sdk.d.ts.map +1 -1
- package/dist/types/http.types.d.ts +1 -1
- package/dist/types/http.types.d.ts.map +1 -1
- package/dist/types/request.types.d.ts +2 -2
- package/dist/types/request.types.d.ts.map +1 -1
- package/dist/utils/emitter.utils.d.ts +1 -1
- package/dist/utils/emitter.utils.d.ts.map +1 -1
- package/package.json +8 -8
- package/src/adapter/adapter.bindings.ts +14 -14
- package/src/adapter/adapter.ts +10 -9
- package/src/adapter/adapter.types.ts +2 -1
- package/src/adapter/adapter.utils.ts +5 -5
- package/src/cache/cache.events.ts +2 -3
- package/src/cache/cache.ts +11 -11
- package/src/client/client.create.ts +1 -1
- package/src/client/client.ts +9 -8
- package/src/client/client.types.ts +2 -2
- package/src/client/client.utils.ts +3 -2
- package/src/constants/http.constants.ts +5 -0
- package/src/constants/time.constants.ts +1 -1
- package/src/dispatcher/dispatcher.events.ts +1 -2
- package/src/dispatcher/dispatcher.ts +12 -12
- package/src/dispatcher/dispatcher.utils.ts +10 -4
- package/src/http-adapter/http-adapter.constants.ts +1 -0
- package/src/http-adapter/http-adapter.fetch.ts +19 -9
- package/src/http-adapter/http-adapter.ts +2 -1
- package/src/http-adapter/http-adapter.types.ts +3 -2
- package/src/http-adapter/http-adapter.utils.ts +15 -11
- package/src/managers/app/app.manager.constants.ts +2 -1
- package/src/managers/app/app.manager.events.ts +0 -1
- package/src/managers/app/app.manager.ts +1 -1
- package/src/managers/app/app.manager.utils.ts +2 -2
- package/src/managers/logger/logger.manager.ts +1 -2
- package/src/managers/request/request.manager.events.ts +2 -3
- package/src/managers/request/request.manager.ts +4 -4
- package/src/mocker/mocker.ts +2 -2
- package/src/plugin/plugin.ts +1 -1
- package/src/plugin/plugin.types.ts +4 -4
- package/src/request/request.hooks.ts +6 -5
- package/src/request/request.ts +49 -34
- package/src/request/request.types.ts +4 -3
- package/src/request/request.utils.ts +17 -16
- package/src/sdk/sdk.ts +26 -19
- package/src/types/http.types.ts +1 -1
- package/src/types/request.types.ts +3 -2
- package/src/utils/emitter.utils.ts +1 -1
- package/src/utils/uuid.utils.ts +1 -1
- package/tsconfig.json +30 -2
- package/vite.config.ts +14 -20
- package/.eslintrc.cjs +0 -12
- package/tsconfig.base.json +0 -7
package/src/adapter/adapter.ts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
|
+
import type { Client, ClientInstance } from "client";
|
|
2
|
+
import type { LoggerMethods } from "managers";
|
|
3
|
+
import { mocker } from "mocker";
|
|
4
|
+
import type { RequestInstance, RequestOptionsType } from "request";
|
|
1
5
|
/* eslint-disable class-methods-use-this */
|
|
2
6
|
import type { EmptyTypes, ExtendRequest } from "types";
|
|
7
|
+
|
|
3
8
|
import { getAdapterOnError, getAdapterBindings } from "./adapter.bindings";
|
|
4
9
|
import type {
|
|
5
10
|
EndpointMapper,
|
|
@@ -11,14 +16,10 @@ import type {
|
|
|
11
16
|
RequestResponseType,
|
|
12
17
|
ResponseType,
|
|
13
18
|
} from "./adapter.types";
|
|
14
|
-
import type { RequestInstance, RequestOptionsType } from "request";
|
|
15
|
-
import type { Client, ClientInstance } from "client";
|
|
16
|
-
import { mocker } from "mocker";
|
|
17
|
-
import type { LoggerMethods } from "managers";
|
|
18
19
|
import type { getErrorMessage } from "./adapter.utils";
|
|
19
20
|
import { getAdapterHeaders, getAdapterPayload, RequestProcessingError } from "./adapter.utils";
|
|
20
21
|
|
|
21
|
-
export type DefaultMapperType = <V, C>(value: V, config
|
|
22
|
+
export type DefaultMapperType = <V, C = undefined>(value: V, config?: C) => V;
|
|
22
23
|
export const defaultMapper: DefaultMapperType = (value) => value;
|
|
23
24
|
|
|
24
25
|
/**
|
|
@@ -67,12 +68,12 @@ export class Adapter<
|
|
|
67
68
|
public defaultExtra: Extra;
|
|
68
69
|
public systemErrorStatus: StatusType;
|
|
69
70
|
public systemErrorExtra: Extra;
|
|
70
|
-
public defaultRequestOptions?: RequestOptionsType<EndpointType, AdapterOptions, MethodType
|
|
71
|
+
public defaultRequestOptions?: RequestOptionsType<EndpointType, AdapterOptions, MethodType> = undefined;
|
|
71
72
|
public logger: LoggerMethods;
|
|
72
73
|
public initialized = false;
|
|
73
74
|
public client: ClientInstance;
|
|
74
75
|
|
|
75
|
-
public unstable_onInitializeCallback?: (options: { client: ClientInstance }) => void;
|
|
76
|
+
public unstable_onInitializeCallback?: (options: { client: ClientInstance }) => void = undefined;
|
|
76
77
|
|
|
77
78
|
public unstable_queryParamsMapperConfig: Parameters<QueryParamsMapperType>[1];
|
|
78
79
|
public unstable_headerMapperConfig: Parameters<HeaderMapperType>[1];
|
|
@@ -151,11 +152,11 @@ export class Adapter<
|
|
|
151
152
|
>;
|
|
152
153
|
}
|
|
153
154
|
>,
|
|
154
|
-
) => AdapterOptions;
|
|
155
|
+
) => AdapterOptions = undefined;
|
|
155
156
|
/** Get default request options for the request. */
|
|
156
157
|
public unstable_getRequestDefaults?: (
|
|
157
158
|
options: RequestOptionsType<EndpointType, AdapterOptions, MethodType>,
|
|
158
|
-
) => Partial<RequestOptionsType<EndpointType, AdapterOptions, MethodType
|
|
159
|
+
) => Partial<RequestOptionsType<EndpointType, AdapterOptions, MethodType>> = undefined;
|
|
159
160
|
/**
|
|
160
161
|
* Get formatted endpoint name of the request.
|
|
161
162
|
* Helpful in displaying long endpoints like in case of graphql schemas etc.
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-shadow */
|
|
2
2
|
import type { RequestInstance } from "request";
|
|
3
|
+
|
|
3
4
|
import type {
|
|
4
5
|
EmptyTypes,
|
|
5
6
|
ExtractAdapterEndpointMapperType,
|
|
@@ -99,7 +100,7 @@ export type DefaultPayloadMapper = (options: { request: RequestInstance; payload
|
|
|
99
100
|
// QueryParams
|
|
100
101
|
|
|
101
102
|
export type QueryParamValuesType = number | string | boolean | null | undefined | Record<any, any>;
|
|
102
|
-
export type QueryParamType = QueryParamValuesType |
|
|
103
|
+
export type QueryParamType = QueryParamValuesType | QueryParamValuesType[] | Record<string, QueryParamValuesType>;
|
|
103
104
|
export type QueryParamsType = Record<string, QueryParamType>;
|
|
104
105
|
|
|
105
106
|
// Responses
|
|
@@ -25,7 +25,7 @@ export class DeletedError extends Error {
|
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
export class RequestProcessingError extends Error {
|
|
28
|
-
description?: string;
|
|
28
|
+
description?: string = undefined;
|
|
29
29
|
|
|
30
30
|
constructor(description?: string) {
|
|
31
31
|
super("Request processing error");
|
|
@@ -35,7 +35,7 @@ export class RequestProcessingError extends Error {
|
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
export class UnexpectedError extends Error {
|
|
38
|
-
description?: string;
|
|
38
|
+
description?: string = undefined;
|
|
39
39
|
|
|
40
40
|
constructor(description?: string) {
|
|
41
41
|
super("Unexpected error");
|
|
@@ -65,7 +65,7 @@ export const getErrorMessage = (errorCase?: "timeout" | "abort" | "deleted" | "p
|
|
|
65
65
|
export const stringifyValue = (response: string | unknown): string => {
|
|
66
66
|
try {
|
|
67
67
|
return JSON.stringify(response as string);
|
|
68
|
-
} catch
|
|
68
|
+
} catch {
|
|
69
69
|
return "";
|
|
70
70
|
}
|
|
71
71
|
};
|
|
@@ -75,7 +75,7 @@ export const getAdapterHeaders = (request: RequestInstance) => {
|
|
|
75
75
|
const isObject = typeof request.payload === "object" && request.payload !== null;
|
|
76
76
|
const headers: HeadersInit = {};
|
|
77
77
|
|
|
78
|
-
if (!isFormData && isObject) headers["Content-Type"] = "application/json";
|
|
78
|
+
if (!isFormData && isObject) {headers["Content-Type"] = "application/json";}
|
|
79
79
|
|
|
80
80
|
Object.assign(headers, request.headers);
|
|
81
81
|
return headers as HeadersInit;
|
|
@@ -83,7 +83,7 @@ export const getAdapterHeaders = (request: RequestInstance) => {
|
|
|
83
83
|
|
|
84
84
|
export const getAdapterPayload = (data: unknown): string | FormData => {
|
|
85
85
|
const isFormData = hasWindow() && data instanceof FormData;
|
|
86
|
-
if (isFormData) return data;
|
|
86
|
+
if (isFormData) {return data;}
|
|
87
87
|
|
|
88
88
|
return stringifyValue(data);
|
|
89
89
|
};
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import type
|
|
2
|
-
|
|
1
|
+
import type { AdapterInstance } from "adapter";
|
|
3
2
|
import type { CacheValueType } from "cache";
|
|
4
3
|
import { getInvalidateByKey, getInvalidateKey, getCacheByKey, getCacheKey, getDeleteKey, getDeleteByKey } from "cache";
|
|
5
|
-
import type
|
|
4
|
+
import type EventEmitter from "events";
|
|
6
5
|
|
|
7
6
|
/** Create the cache event emitters and listeners for data changes, invalidation, and deletion. */
|
|
8
7
|
export const getCacheEvents = (emitter: EventEmitter) => ({
|
package/src/cache/cache.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import type { AdapterInstance, ResponseType } from "adapter";
|
|
2
|
-
import type { ResponseDetailsType, LoggerMethods } from "managers";
|
|
3
|
-
import type { ClientInstance } from "client";
|
|
4
2
|
import type {
|
|
5
3
|
CacheOptionsType,
|
|
6
4
|
CacheAsyncStorageType,
|
|
@@ -10,6 +8,8 @@ import type {
|
|
|
10
8
|
RequestCacheType,
|
|
11
9
|
} from "cache";
|
|
12
10
|
import { getCacheData, getCacheEvents } from "cache";
|
|
11
|
+
import type { ClientInstance } from "client";
|
|
12
|
+
import type { ResponseDetailsType, LoggerMethods } from "managers";
|
|
13
13
|
import type { RequestInstance } from "request";
|
|
14
14
|
import { Request, scopeKey } from "request";
|
|
15
15
|
import type { ExtractAdapterType, ExtractErrorType, ExtractResponseType } from "types";
|
|
@@ -27,7 +27,7 @@ export class Cache<Adapter extends AdapterInstance> {
|
|
|
27
27
|
public events: ReturnType<typeof getCacheEvents>;
|
|
28
28
|
|
|
29
29
|
public storage: CacheStorageType;
|
|
30
|
-
public lazyStorage?: CacheAsyncStorageType;
|
|
30
|
+
public lazyStorage?: CacheAsyncStorageType = undefined;
|
|
31
31
|
public version: string;
|
|
32
32
|
public garbageCollectors = new Map<string, ReturnType<typeof setTimeout>>();
|
|
33
33
|
private logger: LoggerMethods;
|
|
@@ -172,7 +172,7 @@ export class Cache<Adapter extends AdapterInstance> {
|
|
|
172
172
|
keys = (): string[] => {
|
|
173
173
|
const values = this.storage.keys();
|
|
174
174
|
|
|
175
|
-
return
|
|
175
|
+
return [...values];
|
|
176
176
|
};
|
|
177
177
|
|
|
178
178
|
/**
|
|
@@ -197,11 +197,11 @@ export class Cache<Adapter extends AdapterInstance> {
|
|
|
197
197
|
* It emits invalidation event for each matching cacheKey and sets staleTime to 0 to indicate out of time cache
|
|
198
198
|
* @param key - cacheKey or Request instance or RegExp for partial matching
|
|
199
199
|
*/
|
|
200
|
-
invalidate = (cacheKeys: string | RegExp | RequestInstance |
|
|
200
|
+
invalidate = (cacheKeys: string | RegExp | RequestInstance | (string | RegExp | RequestInstance)[]) => {
|
|
201
201
|
this.logger.debug({ title: "Revalidating cache element", type: "system", extra: { cacheKeys } });
|
|
202
202
|
|
|
203
203
|
const onInvalidate = (key: string | RegExp | RequestInstance) => {
|
|
204
|
-
const keys =
|
|
204
|
+
const keys = [...this.storage.keys()];
|
|
205
205
|
const handleInvalidation = (invalidateStorageKey: string, notifyCacheKey: string = invalidateStorageKey) => {
|
|
206
206
|
const value = this.storage.get(invalidateStorageKey);
|
|
207
207
|
if (value) {
|
|
@@ -220,7 +220,7 @@ export class Cache<Adapter extends AdapterInstance> {
|
|
|
220
220
|
handleInvalidation(scopeKey(key.cacheKey, key.scope), key.cacheKey);
|
|
221
221
|
} else if (typeof key === "string") {
|
|
222
222
|
handleInvalidation(key);
|
|
223
|
-
} else if (keys.length) {
|
|
223
|
+
} else if (keys.length > 0) {
|
|
224
224
|
keys.forEach((entityKey) => {
|
|
225
225
|
if (key.test(entityKey)) {
|
|
226
226
|
handleInvalidation(entityKey);
|
|
@@ -249,7 +249,7 @@ export class Cache<Adapter extends AdapterInstance> {
|
|
|
249
249
|
// No data in lazy storage
|
|
250
250
|
const hasLazyData = this.lazyStorage && data;
|
|
251
251
|
if (hasLazyData) {
|
|
252
|
-
const now =
|
|
252
|
+
const now = Date.now();
|
|
253
253
|
const isNewestData = syncData ? syncData.responseTimestamp < data.responseTimestamp : true;
|
|
254
254
|
const isStaleData = data.staleTime <= now - data.responseTimestamp;
|
|
255
255
|
const isValidLazyData = data.version === this.version;
|
|
@@ -285,8 +285,8 @@ export class Cache<Adapter extends AdapterInstance> {
|
|
|
285
285
|
*/
|
|
286
286
|
getAllKeys = async () => {
|
|
287
287
|
const keys = await this.lazyStorage?.keys();
|
|
288
|
-
const asyncKeys =
|
|
289
|
-
const syncKeys =
|
|
288
|
+
const asyncKeys = [...keys || []];
|
|
289
|
+
const syncKeys = [...this.storage.keys()];
|
|
290
290
|
|
|
291
291
|
return [...new Set([...asyncKeys, ...syncKeys])];
|
|
292
292
|
};
|
|
@@ -305,7 +305,7 @@ export class Cache<Adapter extends AdapterInstance> {
|
|
|
305
305
|
|
|
306
306
|
// Garbage collect
|
|
307
307
|
if (cacheData) {
|
|
308
|
-
const timeLeft = cacheData.cacheTime + cacheData.responseTimestamp -
|
|
308
|
+
const timeLeft = cacheData.cacheTime + cacheData.responseTimestamp - Date.now();
|
|
309
309
|
// null
|
|
310
310
|
if (cacheData.cacheTime === null) {
|
|
311
311
|
this.logger.debug({ title: "Cache time is null", type: "system", extra: { cacheKey } });
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { TypeWithDefaults } from "types";
|
|
2
1
|
import type { ClientErrorType, ClientOptionsType } from "client";
|
|
3
2
|
import { Client } from "client";
|
|
4
3
|
import type { HttpAdapterType } from "http-adapter";
|
|
4
|
+
import type { TypeWithDefaults } from "types";
|
|
5
5
|
|
|
6
6
|
export type ClientGenericType = {
|
|
7
7
|
error?: ClientErrorType;
|
package/src/client/client.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { AdapterInstance, ResponseType } from "adapter";
|
|
2
|
-
import
|
|
3
|
-
import { parseResponse, HttpAdapter } from "http-adapter";
|
|
2
|
+
import { Cache } from "cache";
|
|
4
3
|
import type {
|
|
5
4
|
ClientErrorType,
|
|
6
5
|
ClientInstance,
|
|
@@ -10,14 +9,14 @@ import type {
|
|
|
10
9
|
RequestInterceptorType,
|
|
11
10
|
ResponseInterceptorType,
|
|
12
11
|
} from "client";
|
|
13
|
-
import { Cache } from "cache";
|
|
14
12
|
import { Dispatcher } from "dispatcher";
|
|
13
|
+
import type { HttpAdapterType } from "http-adapter";
|
|
14
|
+
import { parseResponse, HttpAdapter } from "http-adapter";
|
|
15
|
+
import type { LogLevel } from "managers";
|
|
16
|
+
import { AppManager, LoggerManager, RequestManager } from "managers";
|
|
15
17
|
import type { PluginInstance, PluginMethodParameters, PluginMethods } from "plugin";
|
|
16
18
|
import type { RequestInstance, RequestJSON, RequestOptionsType } from "request";
|
|
17
19
|
import { getRequestKey, getSimpleKey, Request, scopeKey } from "request";
|
|
18
|
-
import type { LogLevel } from "managers";
|
|
19
|
-
import { AppManager, LoggerManager, RequestManager } from "managers";
|
|
20
|
-
import { interceptRequest, interceptResponse, resolveClientMode } from "./client.utils";
|
|
21
20
|
import type {
|
|
22
21
|
EmptyTypes,
|
|
23
22
|
TypeWithDefaults,
|
|
@@ -32,6 +31,8 @@ import type {
|
|
|
32
31
|
} from "types";
|
|
33
32
|
import { getUniqueRequestId } from "utils";
|
|
34
33
|
|
|
34
|
+
import { interceptRequest, interceptResponse, resolveClientMode } from "./client.utils";
|
|
35
|
+
|
|
35
36
|
/**
|
|
36
37
|
* **Client** is a class that allows you to configure the connection with the server and then use it to create
|
|
37
38
|
* requests. It allows you to set global defaults for the requests configuration, query params configuration.
|
|
@@ -270,7 +271,7 @@ export class Client<
|
|
|
270
271
|
};
|
|
271
272
|
|
|
272
273
|
triggerPlugins = <Key extends keyof PluginMethods<Client>>(key: Key, data: PluginMethodParameters<Key, Client>) => {
|
|
273
|
-
if (
|
|
274
|
+
if (this.plugins.length === 0) {
|
|
274
275
|
return this;
|
|
275
276
|
}
|
|
276
277
|
|
|
@@ -408,7 +409,7 @@ export class Client<
|
|
|
408
409
|
options?: Partial<HydrationOptions> | ((item: HydrateDataType) => Partial<HydrationOptions>),
|
|
409
410
|
) => {
|
|
410
411
|
hydrationData?.forEach((item) => {
|
|
411
|
-
if (!item) return;
|
|
412
|
+
if (!item) {return;}
|
|
412
413
|
|
|
413
414
|
const { cacheKey, scope, response, ...fallbackOptions } = item;
|
|
414
415
|
const defaults = {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-shadow */
|
|
2
|
-
import type { RequestInstance } from "request";
|
|
3
1
|
import type { AdapterInstance, ResponseType } from "adapter";
|
|
4
2
|
import type { Client } from "client";
|
|
3
|
+
/* eslint-disable @typescript-eslint/no-shadow */
|
|
4
|
+
import type { RequestInstance } from "request";
|
|
5
5
|
import type { ExtendRequest, ExtractClientAdapterType, TypeWithDefaults } from "types";
|
|
6
6
|
|
|
7
7
|
export type ClientErrorType = Record<string, any> | string;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { ResponseType } from "adapter";
|
|
2
2
|
import type { RequestInstance } from "request";
|
|
3
3
|
import type { ExtendRequest, ExtractClientAdapterType } from "types";
|
|
4
|
+
|
|
4
5
|
import type {
|
|
5
6
|
ClientInstance,
|
|
6
7
|
ClientMode,
|
|
@@ -30,7 +31,7 @@ export const interceptRequest = async (interceptors: RequestInterceptorType[], r
|
|
|
30
31
|
for (const interceptor of interceptors) {
|
|
31
32
|
// eslint-disable-next-line no-await-in-loop
|
|
32
33
|
newRequest = (await interceptor(request)) as RequestInstance;
|
|
33
|
-
if (!newRequest) throw new Error("Request modifier must return request");
|
|
34
|
+
if (!newRequest) {throw new Error("Request modifier must return request");}
|
|
34
35
|
}
|
|
35
36
|
}
|
|
36
37
|
return newRequest;
|
|
@@ -47,7 +48,7 @@ export const interceptResponse = async <GlobalErrorType, Client extends ClientIn
|
|
|
47
48
|
for (const interceptor of interceptors) {
|
|
48
49
|
// eslint-disable-next-line no-await-in-loop
|
|
49
50
|
newResponse = await interceptor(response, request);
|
|
50
|
-
if (!newResponse) throw new Error("Response modifier must return data");
|
|
51
|
+
if (!newResponse) {throw new Error("Response modifier must return data");}
|
|
51
52
|
}
|
|
52
53
|
}
|
|
53
54
|
return newResponse;
|
|
@@ -4,4 +4,9 @@ export enum HttpMethods {
|
|
|
4
4
|
PUT = "PUT",
|
|
5
5
|
PATCH = "PATCH",
|
|
6
6
|
DELETE = "DELETE",
|
|
7
|
+
/** Safe, idempotent read with a request body (IETF draft-ietf-httpbis-safe-method-w-body). */
|
|
8
|
+
QUERY = "QUERY",
|
|
7
9
|
}
|
|
10
|
+
|
|
11
|
+
/** Methods that are safe reads: routed to the fetch dispatcher and deduplicated by default. */
|
|
12
|
+
export const SAFE_HTTP_METHODS: string[] = [HttpMethods.GET, HttpMethods.QUERY];
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import type EventEmitter from "events";
|
|
2
|
-
|
|
3
1
|
import type { QueueDataType } from "dispatcher";
|
|
4
2
|
import {
|
|
5
3
|
getDispatcherChangeKey,
|
|
@@ -9,6 +7,7 @@ import {
|
|
|
9
7
|
getDispatcherDrainedKey,
|
|
10
8
|
getDispatcherDrainedByKey,
|
|
11
9
|
} from "dispatcher";
|
|
10
|
+
import type EventEmitter from "events";
|
|
12
11
|
import type { RequestInstance } from "request";
|
|
13
12
|
|
|
14
13
|
export const getDispatcherEvents = (emitter: EventEmitter) => ({
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import type { AdapterInstance, RequestResponseType } from "adapter";
|
|
2
|
+
import { getErrorMessage } from "adapter";
|
|
3
|
+
import type { ClientInstance } from "client";
|
|
1
4
|
import type {
|
|
2
5
|
QueueDataType,
|
|
3
6
|
DispatcherOptionsType,
|
|
@@ -7,13 +10,10 @@ import type {
|
|
|
7
10
|
RunningRequestValueType,
|
|
8
11
|
} from "dispatcher";
|
|
9
12
|
import { getRequestType, canRetryRequest, getDispatcherEvents, DispatcherMode } from "dispatcher";
|
|
10
|
-
import type { ClientInstance } from "client";
|
|
11
|
-
import { EventEmitter } from "utils";
|
|
12
13
|
import type { ResponseDetailsType, LoggerMethods } from "managers";
|
|
13
14
|
import type { RequestInstance, RequestJSON } from "request";
|
|
14
15
|
import { Request, scopeKey } from "request";
|
|
15
|
-
import
|
|
16
|
-
import { getErrorMessage } from "adapter";
|
|
16
|
+
import { EventEmitter } from "utils";
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
19
|
* Dispatcher controls and manages the requests that are going to be executed with adapter. It manages them based on the options provided with request.
|
|
@@ -112,7 +112,7 @@ export class Dispatcher<Adapter extends AdapterInstance> {
|
|
|
112
112
|
* Return all queue keys currently tracked by the dispatcher storage
|
|
113
113
|
*/
|
|
114
114
|
getQueuesKeys = () => {
|
|
115
|
-
return
|
|
115
|
+
return [...this.storage.keys()];
|
|
116
116
|
};
|
|
117
117
|
|
|
118
118
|
/**
|
|
@@ -217,7 +217,7 @@ export class Dispatcher<Adapter extends AdapterInstance> {
|
|
|
217
217
|
const isStopped = queue && queue.stopped;
|
|
218
218
|
const isOffline = !this.client.appManager.isOnline;
|
|
219
219
|
const isConcurrent = !queueItem?.request.queued;
|
|
220
|
-
const isInactive =
|
|
220
|
+
const isInactive = runningRequests.length === 0;
|
|
221
221
|
const isEmpty = !queueItem;
|
|
222
222
|
|
|
223
223
|
// When there are no requests to flush, when its stopped, there is running request
|
|
@@ -309,7 +309,7 @@ export class Dispatcher<Adapter extends AdapterInstance> {
|
|
|
309
309
|
* Get currently running requests from all queryKeys
|
|
310
310
|
*/
|
|
311
311
|
getAllRunningRequests = () => {
|
|
312
|
-
return
|
|
312
|
+
return [...this.runningRequests.values()].flat();
|
|
313
313
|
};
|
|
314
314
|
|
|
315
315
|
/**
|
|
@@ -342,7 +342,7 @@ export class Dispatcher<Adapter extends AdapterInstance> {
|
|
|
342
342
|
* Get the value based on the currently running requests
|
|
343
343
|
*/
|
|
344
344
|
hasRunningRequests = (queryKey: string) => {
|
|
345
|
-
return
|
|
345
|
+
return this.getRunningRequests(queryKey).length > 0;
|
|
346
346
|
};
|
|
347
347
|
|
|
348
348
|
/**
|
|
@@ -350,7 +350,7 @@ export class Dispatcher<Adapter extends AdapterInstance> {
|
|
|
350
350
|
*/
|
|
351
351
|
hasRunningRequest = (queryKey: string, requestId: string) => {
|
|
352
352
|
const runningRequests = this.getRunningRequests(queryKey);
|
|
353
|
-
return !!runningRequests.
|
|
353
|
+
return !!runningRequests.some((req) => req.requestId === requestId);
|
|
354
354
|
};
|
|
355
355
|
|
|
356
356
|
/**
|
|
@@ -420,7 +420,7 @@ export class Dispatcher<Adapter extends AdapterInstance> {
|
|
|
420
420
|
const requestId = this.client.unstable_requestIdMapper(request);
|
|
421
421
|
return {
|
|
422
422
|
requestId,
|
|
423
|
-
timestamp:
|
|
423
|
+
timestamp: Date.now(),
|
|
424
424
|
request,
|
|
425
425
|
retries: 0,
|
|
426
426
|
stopped: false,
|
|
@@ -491,7 +491,7 @@ export class Dispatcher<Adapter extends AdapterInstance> {
|
|
|
491
491
|
const queue = this.getQueue(queryKey);
|
|
492
492
|
const queueItem = queue.requests.find((req) => req.requestId === requestId);
|
|
493
493
|
|
|
494
|
-
if (!queueItem) return;
|
|
494
|
+
if (!queueItem) {return;}
|
|
495
495
|
|
|
496
496
|
queue.requests = queue.requests.filter((req) => req.requestId !== requestId);
|
|
497
497
|
this.storage.set(queryKey, queue);
|
|
@@ -512,7 +512,7 @@ export class Dispatcher<Adapter extends AdapterInstance> {
|
|
|
512
512
|
resolved: queueItem.resolved,
|
|
513
513
|
});
|
|
514
514
|
|
|
515
|
-
if (
|
|
515
|
+
if (queue.requests.length === 0) {
|
|
516
516
|
this.client.triggerPlugins("onDispatcherQueueDrained", { queue, dispatcher: this });
|
|
517
517
|
this.events.emitDrained(queue);
|
|
518
518
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { RequestInstance } from "request";
|
|
2
1
|
import type { ResolvedQueueItemType } from "dispatcher";
|
|
3
2
|
import { DispatcherMode } from "dispatcher";
|
|
3
|
+
import type { RequestInstance } from "request";
|
|
4
4
|
|
|
5
5
|
// Events
|
|
6
6
|
|
|
@@ -41,14 +41,17 @@ export const canRetryRequest = (currentRetries: number, retry: number | undefine
|
|
|
41
41
|
|
|
42
42
|
const isInDeduplicateRange = (request: RequestInstance, latestRequest: ResolvedQueueItemType) => {
|
|
43
43
|
if (request.deduplicateTime) {
|
|
44
|
-
return
|
|
44
|
+
return Date.now() - latestRequest.timestamp <= request.deduplicateTime;
|
|
45
45
|
}
|
|
46
46
|
return true;
|
|
47
47
|
};
|
|
48
48
|
|
|
49
49
|
export const getRequestType = (request: RequestInstance, latestRequest: ResolvedQueueItemType | undefined) => {
|
|
50
|
-
const { queued, cancelable, deduplicate } = request;
|
|
50
|
+
const { queued, cancelable, deduplicate, used } = request;
|
|
51
51
|
const canDeduplicate = latestRequest ? isInDeduplicateRange(request, latestRequest) : false;
|
|
52
|
+
// Only join requests that are genuinely still ongoing. A resolved item already emitted its
|
|
53
|
+
// response (a late joiner would wait forever), and a stopped item may never fire at all.
|
|
54
|
+
const isOngoing = latestRequest ? !latestRequest.resolved && !latestRequest.stopped : false;
|
|
52
55
|
|
|
53
56
|
if (queued) {
|
|
54
57
|
return DispatcherMode.ONE_BY_ONE;
|
|
@@ -56,7 +59,10 @@ export const getRequestType = (request: RequestInstance, latestRequest: Resolved
|
|
|
56
59
|
if (cancelable) {
|
|
57
60
|
return DispatcherMode.PREVIOUS_CANCELED;
|
|
58
61
|
}
|
|
59
|
-
|
|
62
|
+
// A request marked with setUsed(true) is an intentional resend, like the auth interceptor
|
|
63
|
+
// retrying after a token refresh. Deduplicating it against the original in-flight request
|
|
64
|
+
// would deadlock: the retry would wait for a response that is blocked on the interceptor.
|
|
65
|
+
if (canDeduplicate && isOngoing && deduplicate && !used) {
|
|
60
66
|
return DispatcherMode.DEDUPLICATED;
|
|
61
67
|
}
|
|
62
68
|
return DispatcherMode.ALL_AT_ONCE;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { Adapter } from "../adapter/adapter";
|
|
2
|
-
import { HttpMethods } from "constants/http.constants";
|
|
3
|
-
import type { HttpMethodsType, HttpStatusType } from "types";
|
|
4
1
|
import type { QueryParamsType } from "adapter";
|
|
2
|
+
import { HttpMethods, SAFE_HTTP_METHODS } from "constants/http.constants";
|
|
3
|
+
import type { HttpMethodsType, HttpStatusType } from "types";
|
|
4
|
+
|
|
5
|
+
import { Adapter } from "../adapter/adapter";
|
|
6
|
+
import { defaultTimeout, xhrExtra } from "./http-adapter.constants";
|
|
5
7
|
import type { HttpAdapterExtraType, FetchAdapterOptionsType } from "./http-adapter.types";
|
|
6
8
|
import { parseErrorResponse, parseResponse, stringifyQueryParams } from "./http-adapter.utils";
|
|
7
|
-
import { defaultTimeout, xhrExtra } from "./http-adapter.constants";
|
|
8
9
|
|
|
9
10
|
const defaultExtra = xhrExtra;
|
|
10
11
|
|
|
@@ -25,6 +26,15 @@ export const getAdapter = () =>
|
|
|
25
26
|
systemErrorExtra: defaultExtra,
|
|
26
27
|
})
|
|
27
28
|
.setQueryParamsMapper(stringifyQueryParams)
|
|
29
|
+
// Safe reads (GET, QUERY) deduplicate by default: concurrent identical requests collapse
|
|
30
|
+
// into one network call. Explicit `deduplicate` in request options still wins.
|
|
31
|
+
.setRequestDefaults((options) => {
|
|
32
|
+
const method = options.method ?? HttpMethods.GET;
|
|
33
|
+
if (SAFE_HTTP_METHODS.includes(method)) {
|
|
34
|
+
return { deduplicate: true };
|
|
35
|
+
}
|
|
36
|
+
return {};
|
|
37
|
+
})
|
|
28
38
|
.setFetcher(
|
|
29
39
|
async ({
|
|
30
40
|
request,
|
|
@@ -93,7 +103,7 @@ export const getAdapter = () =>
|
|
|
93
103
|
|
|
94
104
|
const response = await fetch(fullUrl, init);
|
|
95
105
|
|
|
96
|
-
if (timeoutId) clearTimeout(timeoutId);
|
|
106
|
+
if (timeoutId) {clearTimeout(timeoutId);}
|
|
97
107
|
|
|
98
108
|
onResponseStart();
|
|
99
109
|
|
|
@@ -128,7 +138,7 @@ export const getAdapter = () =>
|
|
|
128
138
|
while (true) {
|
|
129
139
|
// eslint-disable-next-line no-await-in-loop
|
|
130
140
|
const { done, value } = await reader.read();
|
|
131
|
-
if (done) break;
|
|
141
|
+
if (done) {break;}
|
|
132
142
|
chunks.push(value);
|
|
133
143
|
receivedLength += value.length;
|
|
134
144
|
onResponseProgress({ total: contentLength || receivedLength, loaded: receivedLength } as ProgressEvent);
|
|
@@ -157,8 +167,8 @@ export const getAdapter = () =>
|
|
|
157
167
|
onError({ error, status, extra });
|
|
158
168
|
}
|
|
159
169
|
}
|
|
160
|
-
} catch (
|
|
161
|
-
if (timeoutId) clearTimeout(timeoutId);
|
|
170
|
+
} catch (error: any) {
|
|
171
|
+
if (timeoutId) {clearTimeout(timeoutId);}
|
|
162
172
|
unmountListener();
|
|
163
173
|
|
|
164
174
|
if (controller?.signal?.aborted) {
|
|
@@ -168,7 +178,7 @@ export const getAdapter = () =>
|
|
|
168
178
|
return;
|
|
169
179
|
}
|
|
170
180
|
|
|
171
|
-
onError({ error
|
|
181
|
+
onError({ error, status: 0, extra: defaultExtra });
|
|
172
182
|
}
|
|
173
183
|
},
|
|
174
184
|
);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import type { HttpMethodsType, HttpStatusType } from "../types";
|
|
2
1
|
import type { DeclareAdapterType, QueryParamsType, QueryParamType } from "adapter";
|
|
2
|
+
|
|
3
|
+
import type { HttpMethodsType, HttpStatusType } from "../types";
|
|
3
4
|
import type { stringifyQueryParams } from "./http-adapter.utils";
|
|
4
5
|
/**
|
|
5
6
|
* Base Adapter
|
|
@@ -83,7 +84,7 @@ export type QueryStringifyOptionsType = {
|
|
|
83
84
|
export type BufferEncoding =
|
|
84
85
|
| "ascii"
|
|
85
86
|
| "utf8"
|
|
86
|
-
| "
|
|
87
|
+
| "utf8"
|
|
87
88
|
| "utf16le"
|
|
88
89
|
| "ucs2"
|
|
89
90
|
| "ucs-2"
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import type { QueryParamsType, QueryParamType, QueryParamValuesType } from "adapter";
|
|
2
2
|
import { getErrorMessage } from "adapter";
|
|
3
|
+
import { stringifyDefaultOptions } from "client";
|
|
3
4
|
import type { RequestInstance } from "request";
|
|
4
5
|
import type { ExtractErrorType, EmptyTypes } from "types";
|
|
6
|
+
|
|
5
7
|
import type { BufferEncoding, QueryStringifyOptionsType } from "./http-adapter.types";
|
|
6
|
-
import { stringifyDefaultOptions } from "client";
|
|
7
8
|
|
|
8
9
|
// Utils
|
|
9
10
|
|
|
@@ -28,7 +29,7 @@ export const getResponseHeaders = (headersString: string): Record<string, string
|
|
|
28
29
|
export const parseResponse = (response: string | unknown) => {
|
|
29
30
|
try {
|
|
30
31
|
return JSON.parse(response as string);
|
|
31
|
-
} catch
|
|
32
|
+
} catch {
|
|
32
33
|
return response;
|
|
33
34
|
}
|
|
34
35
|
};
|
|
@@ -36,12 +37,15 @@ export const parseResponse = (response: string | unknown) => {
|
|
|
36
37
|
export const handleResponse = (responseChunks: any[], responseType: string, responseEncoding: BufferEncoding) => {
|
|
37
38
|
const bufferedResponse = Buffer.concat(responseChunks);
|
|
38
39
|
switch (responseType) {
|
|
39
|
-
case "arraybuffer":
|
|
40
|
+
case "arraybuffer": {
|
|
40
41
|
return bufferedResponse;
|
|
41
|
-
|
|
42
|
+
}
|
|
43
|
+
case "json": {
|
|
42
44
|
return parseResponse(bufferedResponse.toString(responseEncoding));
|
|
43
|
-
|
|
45
|
+
}
|
|
46
|
+
default: {
|
|
44
47
|
return bufferedResponse.toString(responseEncoding);
|
|
48
|
+
}
|
|
45
49
|
}
|
|
46
50
|
};
|
|
47
51
|
|
|
@@ -73,7 +77,7 @@ const encodeValue = (
|
|
|
73
77
|
{ encode, strict }: Pick<QueryStringifyOptionsType, "encode" | "strict">,
|
|
74
78
|
): string => {
|
|
75
79
|
if (encode && strict) {
|
|
76
|
-
return encodeURIComponent(value).
|
|
80
|
+
return encodeURIComponent(value).replaceAll(/[!'()*]/g, (s) => `%${s.codePointAt(0)!.toString(16).toUpperCase()}`);
|
|
77
81
|
}
|
|
78
82
|
if (encode) {
|
|
79
83
|
return encodeURIComponent(value);
|
|
@@ -103,7 +107,7 @@ const encodeParams = (key: string, value: QueryParamType, options: QueryStringif
|
|
|
103
107
|
return `${encodeValue(key, options)}=${encodeValue(parsedValue(), options)}`;
|
|
104
108
|
};
|
|
105
109
|
|
|
106
|
-
const encodeArray = (key: string, array:
|
|
110
|
+
const encodeArray = (key: string, array: QueryParamValuesType[], options: QueryStringifyOptionsType): string => {
|
|
107
111
|
const { arrayFormat, arraySeparator } = options;
|
|
108
112
|
|
|
109
113
|
return array
|
|
@@ -121,15 +125,15 @@ const encodeArray = (key: string, array: Array<QueryParamValuesType>, options: Q
|
|
|
121
125
|
break;
|
|
122
126
|
}
|
|
123
127
|
case "comma": {
|
|
124
|
-
const keyValue = (
|
|
128
|
+
const keyValue = (acc.length === 0 && `${encodeValue(key, options)}=`) || "";
|
|
125
129
|
return [[...acc, `${keyValue}${encodeValue(String(value), options)}`].join(",")];
|
|
126
130
|
}
|
|
127
131
|
case "separator": {
|
|
128
|
-
const keyValue = (
|
|
132
|
+
const keyValue = (acc.length === 0 && `${encodeValue(key, options)}=`) || "";
|
|
129
133
|
return [[...acc, `${keyValue}${encodeValue(String(value), options)}`].join(arraySeparator || "|")];
|
|
130
134
|
}
|
|
131
135
|
case "bracket-separator": {
|
|
132
|
-
const keyValue = (
|
|
136
|
+
const keyValue = (acc.length === 0 && `${encodeValue(key, options)}[]=`) || "";
|
|
133
137
|
return [[...acc, `${keyValue}${encodeValue(String(value), options)}`].join(arraySeparator || "|")];
|
|
134
138
|
}
|
|
135
139
|
default: {
|
|
@@ -147,7 +151,7 @@ export const stringifyQueryParams = (
|
|
|
147
151
|
queryParams: QueryParamsType | string | EmptyTypes,
|
|
148
152
|
options: QueryStringifyOptionsType = stringifyDefaultOptions,
|
|
149
153
|
): string => {
|
|
150
|
-
if (!queryParams ||
|
|
154
|
+
if (!queryParams || Object.keys(queryParams).length === 0) {
|
|
151
155
|
return "";
|
|
152
156
|
}
|
|
153
157
|
|