@hyper-fetch/core 10.1.1 → 10.3.0
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 +1 -0
- package/__tests__/features/adapter/adapter.bindings.spec.ts +27 -27
- package/__tests__/features/cache/cache.base.spec.ts +4 -4
- package/__tests__/features/cache/cache.events.spec.ts +4 -4
- package/__tests__/features/cache/cache.garbage-collector.spec.ts +2 -2
- package/__tests__/features/cache/cache.lazy-storage.spec.ts +2 -2
- package/__tests__/features/cache/cache.modes.spec.ts +2 -2
- package/__tests__/features/cache/cache.scoped-events.spec.ts +2 -2
- package/__tests__/features/cache/cache.scoping.spec.ts +2 -2
- package/__tests__/features/cache/cache.semantics.spec.ts +6 -1
- package/__tests__/features/cache/cache.typescript.spec.ts +2 -2
- package/__tests__/features/cache/cache.utils.spec.ts +9 -9
- package/__tests__/features/client/client.hydration.round-trip.spec.ts +2 -2
- package/__tests__/features/client/client.hydration.spec.ts +3 -3
- package/__tests__/features/client/client.interceptor.spec.ts +7 -7
- package/__tests__/features/client/client.interceptors.pipeline.spec.ts +3 -3
- package/__tests__/features/client/client.set-url.spec.ts +2 -2
- package/__tests__/features/dispatcher/dispatcher.events.spec.ts +2 -2
- package/__tests__/features/http-adapter/http-adapter.extra.spec.ts +21 -0
- package/__tests__/features/request/request.sending.spec.ts +7 -7
- package/__tests__/utils/callbacks.utils.ts +2 -2
- package/__tests__/utils/fixtures.utils.ts +4 -4
- package/dist/http-adapter/http-adapter.constants.d.ts +8 -0
- package/dist/http-adapter/http-adapter.constants.d.ts.map +1 -1
- package/dist/index.mjs +11 -3
- package/dist/index.mjs.map +1 -1
- package/dist/request/request.types.d.ts +2 -1
- package/dist/request/request.types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/http-adapter/http-adapter.constants.ts +10 -1
- package/src/http-adapter/http-adapter.fetch.ts +2 -2
- package/src/request/request.types.ts +2 -1
|
@@ -3,7 +3,7 @@ import type { ResponseSuccessType } from "adapter";
|
|
|
3
3
|
import { getErrorMessage } from "adapter";
|
|
4
4
|
import { Client } from "client";
|
|
5
5
|
import type { HttpAdapterType } from "http-adapter";
|
|
6
|
-
import {
|
|
6
|
+
import { httpExtra } from "http-adapter";
|
|
7
7
|
import type { ResponseDetailsType } from "managers";
|
|
8
8
|
import { http, HttpResponse } from "msw";
|
|
9
9
|
|
|
@@ -15,7 +15,7 @@ describe("Client [ setUrl ]", () => {
|
|
|
15
15
|
error: null,
|
|
16
16
|
status: 200,
|
|
17
17
|
success: true,
|
|
18
|
-
extra:
|
|
18
|
+
extra: httpExtra,
|
|
19
19
|
requestTimestamp: Date.now(),
|
|
20
20
|
responseTimestamp: Date.now(),
|
|
21
21
|
};
|
|
@@ -3,7 +3,7 @@ import { waitFor } from "@testing-library/dom";
|
|
|
3
3
|
import type { AdapterInstance, ResponseType } from "adapter";
|
|
4
4
|
import { getErrorMessage } from "adapter";
|
|
5
5
|
import { Client } from "client";
|
|
6
|
-
import {
|
|
6
|
+
import { httpExtra } from "http-adapter";
|
|
7
7
|
import type { ResponseDetailsType } from "managers";
|
|
8
8
|
|
|
9
9
|
import { createDispatcher, createAdapter } from "../../utils";
|
|
@@ -223,7 +223,7 @@ describe("Dispatcher [ Events ]", () => {
|
|
|
223
223
|
error: getErrorMessage("abort"),
|
|
224
224
|
status: 0,
|
|
225
225
|
success: false,
|
|
226
|
-
extra:
|
|
226
|
+
extra: httpExtra,
|
|
227
227
|
requestTimestamp: expect.toBeNumber(),
|
|
228
228
|
responseTimestamp: expect.toBeNumber(),
|
|
229
229
|
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { HttpAdapterExtraType } from "http-adapter";
|
|
2
|
+
import { HttpAdapter, httpExtra, xhrExtra } from "http-adapter";
|
|
3
|
+
|
|
4
|
+
describe("HttpAdapter [ Extra ]", () => {
|
|
5
|
+
it("should start with empty response headers", () => {
|
|
6
|
+
expect(httpExtra).toStrictEqual({ headers: {} });
|
|
7
|
+
expectTypeOf(httpExtra).toEqualTypeOf<HttpAdapterExtraType>();
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
it("should use httpExtra as the default and system error extra", () => {
|
|
11
|
+
const adapter = HttpAdapter();
|
|
12
|
+
|
|
13
|
+
expect(adapter.defaultExtra).toBe(httpExtra);
|
|
14
|
+
expect(adapter.systemErrorExtra).toBe(httpExtra);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it("should keep xhrExtra as an alias of httpExtra", () => {
|
|
18
|
+
expect(xhrExtra).toBe(httpExtra);
|
|
19
|
+
expectTypeOf(xhrExtra).toEqualTypeOf<HttpAdapterExtraType>();
|
|
20
|
+
});
|
|
21
|
+
});
|
|
@@ -2,7 +2,7 @@ import { createHttpMockingServer, sleep } from "@hyper-fetch/testing";
|
|
|
2
2
|
import { waitFor } from "@testing-library/dom";
|
|
3
3
|
import { getErrorMessage } from "adapter";
|
|
4
4
|
import { Client } from "client";
|
|
5
|
-
import {
|
|
5
|
+
import { httpExtra } from "http-adapter";
|
|
6
6
|
|
|
7
7
|
const { resetMocks, startServer, stopServer, mockRequest } = createHttpMockingServer();
|
|
8
8
|
|
|
@@ -187,7 +187,7 @@ describe("Request [ Sending ]", () => {
|
|
|
187
187
|
error: getErrorMessage("deleted"),
|
|
188
188
|
status: null,
|
|
189
189
|
success: false,
|
|
190
|
-
extra:
|
|
190
|
+
extra: httpExtra,
|
|
191
191
|
});
|
|
192
192
|
});
|
|
193
193
|
it("should call remove error", async () => {
|
|
@@ -221,14 +221,14 @@ describe("Request [ Sending ]", () => {
|
|
|
221
221
|
error: getErrorMessage("abort"),
|
|
222
222
|
status: 0,
|
|
223
223
|
success: false,
|
|
224
|
-
extra:
|
|
224
|
+
extra: httpExtra,
|
|
225
225
|
});
|
|
226
226
|
expect(res2).toStrictEqual({
|
|
227
227
|
data: null,
|
|
228
228
|
error: getErrorMessage("abort"),
|
|
229
229
|
status: 0,
|
|
230
230
|
success: false,
|
|
231
|
-
extra:
|
|
231
|
+
extra: httpExtra,
|
|
232
232
|
});
|
|
233
233
|
expect(res3).toStrictEqual({
|
|
234
234
|
data: mock,
|
|
@@ -261,14 +261,14 @@ describe("Request [ Sending ]", () => {
|
|
|
261
261
|
error: getErrorMessage("abort"),
|
|
262
262
|
status: 0,
|
|
263
263
|
success: false,
|
|
264
|
-
extra:
|
|
264
|
+
extra: httpExtra,
|
|
265
265
|
});
|
|
266
266
|
expect(res2).toStrictEqual({
|
|
267
267
|
data: null,
|
|
268
268
|
error: getErrorMessage("abort"),
|
|
269
269
|
status: 0,
|
|
270
270
|
success: false,
|
|
271
|
-
extra:
|
|
271
|
+
extra: httpExtra,
|
|
272
272
|
});
|
|
273
273
|
expect(res3).toStrictEqual({
|
|
274
274
|
data: mock,
|
|
@@ -322,7 +322,7 @@ describe("Request [ Sending ]", () => {
|
|
|
322
322
|
error: null,
|
|
323
323
|
status: 200,
|
|
324
324
|
success: true,
|
|
325
|
-
extra:
|
|
325
|
+
extra: httpExtra,
|
|
326
326
|
});
|
|
327
327
|
expect(fetchSpy).not.toHaveBeenCalled();
|
|
328
328
|
});
|
|
@@ -2,7 +2,7 @@ import { sleep } from "@hyper-fetch/testing";
|
|
|
2
2
|
import type { ResponseType } from "adapter";
|
|
3
3
|
import type { ClientInstance, ResponseInterceptorType } from "client";
|
|
4
4
|
import type { HttpAdapterType } from "http-adapter";
|
|
5
|
-
import {
|
|
5
|
+
import { httpExtra } from "http-adapter";
|
|
6
6
|
import type { RequestInstance } from "request";
|
|
7
7
|
|
|
8
8
|
export const interceptorCallback = (props?: {
|
|
@@ -25,7 +25,7 @@ export const interceptorCallback = (props?: {
|
|
|
25
25
|
error: null,
|
|
26
26
|
success: true,
|
|
27
27
|
status: 200,
|
|
28
|
-
extra:
|
|
28
|
+
extra: httpExtra,
|
|
29
29
|
requestTimestamp: 0,
|
|
30
30
|
responseTimestamp: 0,
|
|
31
31
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { CacheAsyncStorageType, CacheStorageType, CacheValueType } from "cache";
|
|
2
2
|
import type { HttpAdapterType } from "http-adapter";
|
|
3
|
-
import {
|
|
3
|
+
import { httpExtra } from "http-adapter";
|
|
4
4
|
import type { ResponseDetailsType } from "managers";
|
|
5
5
|
|
|
6
6
|
/**
|
|
@@ -109,7 +109,7 @@ export const createCacheResponse = <Data>(
|
|
|
109
109
|
error: null,
|
|
110
110
|
status: 200,
|
|
111
111
|
success: true,
|
|
112
|
-
extra:
|
|
112
|
+
extra: httpExtra,
|
|
113
113
|
...createResponseDetails(),
|
|
114
114
|
...overrides,
|
|
115
115
|
});
|
|
@@ -125,7 +125,7 @@ export const createCacheErrorResponse = <Error>(
|
|
|
125
125
|
error,
|
|
126
126
|
status: 400,
|
|
127
127
|
success: false,
|
|
128
|
-
extra:
|
|
128
|
+
extra: httpExtra,
|
|
129
129
|
...createResponseDetails(),
|
|
130
130
|
...overrides,
|
|
131
131
|
});
|
|
@@ -140,7 +140,7 @@ export const createCacheValue = <Data = unknown>(
|
|
|
140
140
|
error: null,
|
|
141
141
|
status: 200,
|
|
142
142
|
success: true,
|
|
143
|
-
extra:
|
|
143
|
+
extra: httpExtra,
|
|
144
144
|
...createResponseDetails(),
|
|
145
145
|
cacheKey: "cache-key",
|
|
146
146
|
scope: null,
|
|
@@ -1,4 +1,12 @@
|
|
|
1
1
|
import { HttpAdapterExtraType } from './http-adapter.types';
|
|
2
2
|
export declare const defaultTimeout: number;
|
|
3
|
+
/**
|
|
4
|
+
* Default `extra` of the `HttpAdapter`. It holds the response headers, so it starts empty and is used until a response
|
|
5
|
+
* arrives, and for requests that fail before the server answers.
|
|
6
|
+
*/
|
|
7
|
+
export declare const httpExtra: HttpAdapterExtraType;
|
|
8
|
+
/**
|
|
9
|
+
* @deprecated Use `httpExtra`. The `HttpAdapter` sends requests with `fetch`, not `XMLHttpRequest`.
|
|
10
|
+
*/
|
|
3
11
|
export declare const xhrExtra: HttpAdapterExtraType;
|
|
4
12
|
//# sourceMappingURL=http-adapter.constants.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http-adapter.constants.d.ts","sourceRoot":"","sources":["../../src/http-adapter/http-adapter.constants.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAEjE,eAAO,MAAM,cAAc,QAAe,CAAC;AAE3C,eAAO,MAAM,QAAQ,EAAE,
|
|
1
|
+
{"version":3,"file":"http-adapter.constants.d.ts","sourceRoot":"","sources":["../../src/http-adapter/http-adapter.constants.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAEjE,eAAO,MAAM,cAAc,QAAe,CAAC;AAE3C;;;GAGG;AACH,eAAO,MAAM,SAAS,EAAE,oBAEvB,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,QAAQ,EAAE,oBAAgC,CAAC"}
|
package/dist/index.mjs
CHANGED
|
@@ -4204,7 +4204,15 @@ var getRequestType = (request, latestRequest) => {
|
|
|
4204
4204
|
//#endregion
|
|
4205
4205
|
//#region src/http-adapter/http-adapter.constants.ts
|
|
4206
4206
|
var defaultTimeout = Time.SEC * 5;
|
|
4207
|
-
|
|
4207
|
+
/**
|
|
4208
|
+
* Default `extra` of the `HttpAdapter`. It holds the response headers, so it starts empty and is used until a response
|
|
4209
|
+
* arrives, and for requests that fail before the server answers.
|
|
4210
|
+
*/
|
|
4211
|
+
var httpExtra = { headers: {} };
|
|
4212
|
+
/**
|
|
4213
|
+
* @deprecated Use `httpExtra`. The `HttpAdapter` sends requests with `fetch`, not `XMLHttpRequest`.
|
|
4214
|
+
*/
|
|
4215
|
+
var xhrExtra = httpExtra;
|
|
4208
4216
|
//#endregion
|
|
4209
4217
|
//#region src/http-adapter/http-adapter.utils.ts
|
|
4210
4218
|
var getResponseHeaders = (headersString) => {
|
|
@@ -4306,7 +4314,7 @@ var stringifyQueryParams = (queryParams, options) => {
|
|
|
4306
4314
|
};
|
|
4307
4315
|
//#endregion
|
|
4308
4316
|
//#region src/http-adapter/http-adapter.fetch.ts
|
|
4309
|
-
var defaultExtra =
|
|
4317
|
+
var defaultExtra = httpExtra;
|
|
4310
4318
|
/**
|
|
4311
4319
|
* Size in bytes of a body that fetch sends as it is. Form data and streams get their size from the browser while they
|
|
4312
4320
|
* are sent, so it is unknown up front.
|
|
@@ -5912,6 +5920,6 @@ var fetchInfinite = async (request, options) => {
|
|
|
5912
5920
|
return result;
|
|
5913
5921
|
};
|
|
5914
5922
|
//#endregion
|
|
5915
|
-
export { AbortError, Adapter, AppEvents, AppManager, Cache, Client, DeletedError, Dispatcher, DispatcherMode, EventEmitter, HttpAdapter, HttpMethods, LoggerManager, OptimisticOperation, Plugin, Request, RequestManager, RequestProcessingError, SAFE_HTTP_METHODS, Time, TimeoutError, UnexpectedError, appManagerInitialOptions, applyOptimistic, canRetryRequest, createClient, createConfiguration, createRequestHooks, createSdk, defaultMapper, defaultTimeout, exponentialBackoff, fetchInfinite, getAbortByAbortKey, getAbortByIdKey, getAbortKey, getAdapter, getAdapterBindings, getAdapterHeaders, getAdapterOnError, getAdapterPayload, getAppManagerEvents, getCacheByKey, getCacheData, getCacheEvents, getCacheKey, getCachedPages, getDeleteByKey, getDeleteKey, getDispatcherChangeByKey, getDispatcherChangeKey, getDispatcherDrainedByKey, getDispatcherDrainedKey, getDispatcherEvents, getDispatcherRunningByKey, getDispatcherRunningKey, getDispatcherStatusByKey, getDispatcherStatusKey, getDownloadProgressByIdKey, getDownloadProgressByQueryKey, getDownloadProgressKey, getErrorMessage, getHasNextPage, getHasPreviousPage, getInitialPageParam, getInvalidateByKey, getInvalidateKey, getIsEqualTimestamp, getLoadingByCacheKey, getLoadingByIdKey, getLoadingByQueryKey, getLoadingKey, getNextPageParam, getOptimisticResult, getPageItems, getPageRequest, getPageTotal, getPaginationMode, getPreviousPageParam, getProgressData, getProgressValue, getRemoveByIdKey, getRemoveByQueryKey, getRemoveKey, getRequestDeduplicatedByCacheKey, getRequestDeduplicatedByIdKey, getRequestDeduplicatedByQueryKey, getRequestDeduplicatedKey, getRequestDispatcher, getRequestEta, getRequestKey, getRequestManagerEvents, getRequestStarByQueryKey, getRequestStartByIdKey, getRequestStartKey, getRequestType, getResponseByCacheKey, getResponseByIdKey, getResponseHeaders, getResponseKey, getResponseStartByIdKey, getResponseStartByQueryKey, getResponseStartKey, getSimpleKey, getTime, getUniqueRequestId, getUploadProgressByIdKey, getUploadProgressByQueryKey, getUploadProgressKey, handleResponse, hasDocument, hasWindow, incrementField, incrementItems, insertItem, interceptRequest, interceptResponse, isNavigatorOnline, isOptimisticMatch, isPlainObject, isStaleOptimisticResponse, logLevelOrder, logger, loggerColors, loggerStyles, mapResponseForSend, mocker, onDocumentEvent, onWindowEvent, optimistic, parseErrorResponse, parseResponse, patchItems, removeItems, replaceEqualDeep, resetOptimisticState, resolveClientMode, resolveQueryParams, runResponseMapper, runUserCode, scopeKey, sendRequest, settleOptimistic, stringifyDefaultOptions, stringifyKey, stringifyQueryParams, stringifyValue, throwOutsideLifecycle, updateListField, xhrExtra };
|
|
5923
|
+
export { AbortError, Adapter, AppEvents, AppManager, Cache, Client, DeletedError, Dispatcher, DispatcherMode, EventEmitter, HttpAdapter, HttpMethods, LoggerManager, OptimisticOperation, Plugin, Request, RequestManager, RequestProcessingError, SAFE_HTTP_METHODS, Time, TimeoutError, UnexpectedError, appManagerInitialOptions, applyOptimistic, canRetryRequest, createClient, createConfiguration, createRequestHooks, createSdk, defaultMapper, defaultTimeout, exponentialBackoff, fetchInfinite, getAbortByAbortKey, getAbortByIdKey, getAbortKey, getAdapter, getAdapterBindings, getAdapterHeaders, getAdapterOnError, getAdapterPayload, getAppManagerEvents, getCacheByKey, getCacheData, getCacheEvents, getCacheKey, getCachedPages, getDeleteByKey, getDeleteKey, getDispatcherChangeByKey, getDispatcherChangeKey, getDispatcherDrainedByKey, getDispatcherDrainedKey, getDispatcherEvents, getDispatcherRunningByKey, getDispatcherRunningKey, getDispatcherStatusByKey, getDispatcherStatusKey, getDownloadProgressByIdKey, getDownloadProgressByQueryKey, getDownloadProgressKey, getErrorMessage, getHasNextPage, getHasPreviousPage, getInitialPageParam, getInvalidateByKey, getInvalidateKey, getIsEqualTimestamp, getLoadingByCacheKey, getLoadingByIdKey, getLoadingByQueryKey, getLoadingKey, getNextPageParam, getOptimisticResult, getPageItems, getPageRequest, getPageTotal, getPaginationMode, getPreviousPageParam, getProgressData, getProgressValue, getRemoveByIdKey, getRemoveByQueryKey, getRemoveKey, getRequestDeduplicatedByCacheKey, getRequestDeduplicatedByIdKey, getRequestDeduplicatedByQueryKey, getRequestDeduplicatedKey, getRequestDispatcher, getRequestEta, getRequestKey, getRequestManagerEvents, getRequestStarByQueryKey, getRequestStartByIdKey, getRequestStartKey, getRequestType, getResponseByCacheKey, getResponseByIdKey, getResponseHeaders, getResponseKey, getResponseStartByIdKey, getResponseStartByQueryKey, getResponseStartKey, getSimpleKey, getTime, getUniqueRequestId, getUploadProgressByIdKey, getUploadProgressByQueryKey, getUploadProgressKey, handleResponse, hasDocument, hasWindow, httpExtra, incrementField, incrementItems, insertItem, interceptRequest, interceptResponse, isNavigatorOnline, isOptimisticMatch, isPlainObject, isStaleOptimisticResponse, logLevelOrder, logger, loggerColors, loggerStyles, mapResponseForSend, mocker, onDocumentEvent, onWindowEvent, optimistic, parseErrorResponse, parseResponse, patchItems, removeItems, replaceEqualDeep, resetOptimisticState, resolveClientMode, resolveQueryParams, runResponseMapper, runUserCode, scopeKey, sendRequest, settleOptimistic, stringifyDefaultOptions, stringifyKey, stringifyQueryParams, stringifyValue, throwOutsideLifecycle, updateListField, xhrExtra };
|
|
5916
5924
|
|
|
5917
5925
|
//# sourceMappingURL=index.mjs.map
|