@hyper-fetch/core 9.3.0 → 9.4.1
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/__tests__/features/adapter/adapter.request-options.spec.ts +116 -0
- package/__tests__/features/client/client.base.spec.ts +14 -0
- package/__tests__/features/managers/app/app.manager.base.spec.ts +173 -1
- package/dist/adapter/adapter.d.ts +17 -12
- package/dist/adapter/adapter.d.ts.map +1 -1
- package/dist/adapter/adapter.types.d.ts +5 -3
- package/dist/adapter/adapter.types.d.ts.map +1 -1
- package/dist/client/client.d.ts +2 -2
- package/dist/client/client.d.ts.map +1 -1
- package/dist/http-adapter/http-adapter.fetch.d.ts +1 -1
- package/dist/http-adapter/http-adapter.fetch.d.ts.map +1 -1
- package/dist/index.mjs +69 -15
- package/dist/index.mjs.map +1 -1
- package/dist/managers/app/app.manager.constants.d.ts.map +1 -1
- package/dist/managers/app/app.manager.d.ts +9 -0
- package/dist/managers/app/app.manager.d.ts.map +1 -1
- package/dist/managers/app/app.manager.types.d.ts +8 -2
- package/dist/managers/app/app.manager.types.d.ts.map +1 -1
- package/dist/managers/app/app.manager.utils.d.ts +5 -0
- package/dist/managers/app/app.manager.utils.d.ts.map +1 -1
- package/dist/types/adapter.types.d.ts +13 -11
- package/dist/types/adapter.types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/adapter/adapter.ts +33 -13
- package/src/adapter/adapter.types.ts +7 -3
- package/src/client/client.ts +3 -1
- package/src/managers/app/app.manager.constants.ts +18 -7
- package/src/managers/app/app.manager.ts +44 -10
- package/src/managers/app/app.manager.types.ts +8 -2
- package/src/managers/app/app.manager.utils.ts +13 -0
- package/src/types/adapter.types.ts +18 -11
package/dist/index.mjs
CHANGED
|
@@ -982,6 +982,7 @@ var AppManager = class {
|
|
|
982
982
|
isBrowser;
|
|
983
983
|
isOnline;
|
|
984
984
|
isFocused;
|
|
985
|
+
unmountCallbacks = [];
|
|
985
986
|
constructor(options) {
|
|
986
987
|
this.options = options;
|
|
987
988
|
this.emitter?.setMaxListeners(1e3);
|
|
@@ -990,22 +991,48 @@ var AppManager = class {
|
|
|
990
991
|
this.setInitialOnline(initiallyOnline);
|
|
991
992
|
this.isBrowser = hasDocument();
|
|
992
993
|
}
|
|
994
|
+
/**
|
|
995
|
+
* Subscribes to the environment focus and network changes. Calling it again replaces the previous subscriptions,
|
|
996
|
+
* so the listeners are never registered twice.
|
|
997
|
+
*/
|
|
993
998
|
initialize = () => {
|
|
994
999
|
const { focusEvent = appManagerInitialOptions.focusEvent, onlineEvent = appManagerInitialOptions.onlineEvent } = this.options || appManagerInitialOptions;
|
|
995
|
-
|
|
996
|
-
onlineEvent(this.setOnline)
|
|
1000
|
+
this.unmount();
|
|
1001
|
+
[focusEvent(this.setFocused), onlineEvent(this.setOnline)].forEach((unmount) => {
|
|
1002
|
+
if (typeof unmount === "function") this.unmountCallbacks.push(unmount);
|
|
1003
|
+
});
|
|
1004
|
+
};
|
|
1005
|
+
/**
|
|
1006
|
+
* Removes the environment listeners registered by `initialize()`. Listeners added with `events` are kept.
|
|
1007
|
+
*/
|
|
1008
|
+
unmount = () => {
|
|
1009
|
+
const callbacks = this.unmountCallbacks;
|
|
1010
|
+
this.unmountCallbacks = [];
|
|
1011
|
+
callbacks.forEach((unmount) => unmount());
|
|
997
1012
|
};
|
|
998
1013
|
setInitialFocus = async (initValue) => {
|
|
999
|
-
if (typeof initValue
|
|
1014
|
+
if (typeof initValue !== "function") {
|
|
1015
|
+
this.isFocused = initValue;
|
|
1016
|
+
return;
|
|
1017
|
+
}
|
|
1018
|
+
const value = initValue();
|
|
1019
|
+
if (typeof value === "boolean") this.isFocused = value;
|
|
1020
|
+
else {
|
|
1000
1021
|
this.isFocused = false;
|
|
1001
|
-
this.isFocused = await
|
|
1002
|
-
}
|
|
1022
|
+
this.isFocused = await value;
|
|
1023
|
+
}
|
|
1003
1024
|
};
|
|
1004
1025
|
setInitialOnline = async (initValue) => {
|
|
1005
|
-
if (typeof initValue
|
|
1026
|
+
if (typeof initValue !== "function") {
|
|
1027
|
+
this.isOnline = initValue;
|
|
1028
|
+
return;
|
|
1029
|
+
}
|
|
1030
|
+
const value = initValue();
|
|
1031
|
+
if (typeof value === "boolean") this.isOnline = value;
|
|
1032
|
+
else {
|
|
1006
1033
|
this.isOnline = false;
|
|
1007
|
-
this.isOnline = await
|
|
1008
|
-
}
|
|
1034
|
+
this.isOnline = await value;
|
|
1035
|
+
}
|
|
1009
1036
|
};
|
|
1010
1037
|
setFocused = (isFocused) => {
|
|
1011
1038
|
this.isFocused = isFocused;
|
|
@@ -1036,6 +1063,18 @@ var hasDocument = () => {
|
|
|
1036
1063
|
return false;
|
|
1037
1064
|
}
|
|
1038
1065
|
};
|
|
1066
|
+
/**
|
|
1067
|
+
* Reads the current network state from the browser. Falls back to `true` when it is unknown - e.g. in Node.js or
|
|
1068
|
+
* React Native, where `navigator.onLine` is not available.
|
|
1069
|
+
*/
|
|
1070
|
+
var isNavigatorOnline = () => {
|
|
1071
|
+
try {
|
|
1072
|
+
return typeof navigator.onLine === "boolean" ? navigator.onLine : true;
|
|
1073
|
+
} catch {
|
|
1074
|
+
/* istanbul ignore next */
|
|
1075
|
+
return true;
|
|
1076
|
+
}
|
|
1077
|
+
};
|
|
1039
1078
|
var onWindowEvent = (key, listener, options) => {
|
|
1040
1079
|
/* istanbul ignore next */
|
|
1041
1080
|
if (hasWindow()) {
|
|
@@ -1098,15 +1137,24 @@ var AppEvents = /* @__PURE__ */ function(AppEvents) {
|
|
|
1098
1137
|
}({});
|
|
1099
1138
|
var appManagerInitialOptions = {
|
|
1100
1139
|
initiallyFocused: true,
|
|
1101
|
-
initiallyOnline:
|
|
1140
|
+
initiallyOnline: isNavigatorOnline,
|
|
1102
1141
|
focusEvent: (setFocused) => {
|
|
1103
|
-
onDocumentEvent("visibilitychange", () => setFocused(true));
|
|
1104
|
-
onWindowEvent("focus", () => setFocused(true));
|
|
1105
|
-
onWindowEvent("blur", () => setFocused(false));
|
|
1142
|
+
const unmountVisibility = onDocumentEvent("visibilitychange", () => setFocused(true));
|
|
1143
|
+
const unmountFocus = onWindowEvent("focus", () => setFocused(true));
|
|
1144
|
+
const unmountBlur = onWindowEvent("blur", () => setFocused(false));
|
|
1145
|
+
return () => {
|
|
1146
|
+
unmountVisibility();
|
|
1147
|
+
unmountFocus();
|
|
1148
|
+
unmountBlur();
|
|
1149
|
+
};
|
|
1106
1150
|
},
|
|
1107
1151
|
onlineEvent: (setOnline) => {
|
|
1108
|
-
onWindowEvent("online", () => setOnline(true));
|
|
1109
|
-
onWindowEvent("offline", () => setOnline(false));
|
|
1152
|
+
const unmountOnline = onWindowEvent("online", () => setOnline(true));
|
|
1153
|
+
const unmountOffline = onWindowEvent("offline", () => setOnline(false));
|
|
1154
|
+
return () => {
|
|
1155
|
+
unmountOnline();
|
|
1156
|
+
unmountOffline();
|
|
1157
|
+
};
|
|
1110
1158
|
}
|
|
1111
1159
|
};
|
|
1112
1160
|
//#endregion
|
|
@@ -1550,6 +1598,11 @@ var Adapter = class {
|
|
|
1550
1598
|
unstable_headerMapperConfig;
|
|
1551
1599
|
unstable_payloadMapperConfig;
|
|
1552
1600
|
unstable_endpointMapperConfig;
|
|
1601
|
+
/**
|
|
1602
|
+
* Type-only carrier of the additional `createRequest` fields declared by this adapter.
|
|
1603
|
+
* It has no runtime value - adapters read those fields from `request.requestOptions`.
|
|
1604
|
+
*/
|
|
1605
|
+
unstable_requestOptionsType = void 0;
|
|
1553
1606
|
constructor(options) {
|
|
1554
1607
|
this.options = options;
|
|
1555
1608
|
this.name = options.name;
|
|
@@ -4084,6 +4137,7 @@ var Client = class {
|
|
|
4084
4137
|
this.fetchDispatcher.emitter.removeAllListeners();
|
|
4085
4138
|
this.submitDispatcher.emitter.removeAllListeners();
|
|
4086
4139
|
this.cache.emitter.removeAllListeners();
|
|
4140
|
+
this.appManager.unmount();
|
|
4087
4141
|
this.cache = cache?.() || new Cache();
|
|
4088
4142
|
this.appManager = appManager?.() || new AppManager();
|
|
4089
4143
|
this.fetchDispatcher = fetchDispatcher?.() || new Dispatcher();
|
|
@@ -4299,6 +4353,6 @@ var createConfiguration = () => {
|
|
|
4299
4353
|
return (defaults) => defaults;
|
|
4300
4354
|
};
|
|
4301
4355
|
//#endregion
|
|
4302
|
-
export { AbortError, Adapter, AppEvents, AppManager, Cache, Client, DeletedError, Dispatcher, DispatcherMode, EventEmitter, HttpAdapter, HttpMethods, LoggerManager, Plugin, Request, RequestManager, RequestProcessingError, SAFE_HTTP_METHODS, Time, TimeoutError, UnexpectedError, appManagerInitialOptions, canRetryRequest, createClient, createConfiguration, createRequestHooks, createSdk, defaultMapper, defaultTimeout, getAbortByAbortKey, getAbortByIdKey, getAbortKey, getAdapter, getAdapterBindings, getAdapterHeaders, getAdapterOnError, getAdapterPayload, getAppManagerEvents, getCacheByKey, getCacheData, getCacheEvents, getCacheKey, getDeleteByKey, getDeleteKey, getDispatcherChangeByKey, getDispatcherChangeKey, getDispatcherDrainedByKey, getDispatcherDrainedKey, getDispatcherEvents, getDispatcherRunningByKey, getDispatcherRunningKey, getDispatcherStatusByKey, getDispatcherStatusKey, getDownloadProgressByIdKey, getDownloadProgressByQueryKey, getDownloadProgressKey, getErrorMessage, getInvalidateByKey, getInvalidateKey, getIsEqualTimestamp, getLoadingByCacheKey, getLoadingByIdKey, getLoadingByQueryKey, getLoadingKey, 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, interceptRequest, interceptResponse, isPlainObject, logLevelOrder, logger, loggerColors, loggerStyles, mapResponseForSend, mocker, onDocumentEvent, onWindowEvent, parseErrorResponse, parseResponse, replaceEqualDeep, resolveClientMode, scopeKey, sendRequest, stringifyDefaultOptions, stringifyKey, stringifyQueryParams, stringifyValue, xhrExtra };
|
|
4356
|
+
export { AbortError, Adapter, AppEvents, AppManager, Cache, Client, DeletedError, Dispatcher, DispatcherMode, EventEmitter, HttpAdapter, HttpMethods, LoggerManager, Plugin, Request, RequestManager, RequestProcessingError, SAFE_HTTP_METHODS, Time, TimeoutError, UnexpectedError, appManagerInitialOptions, canRetryRequest, createClient, createConfiguration, createRequestHooks, createSdk, defaultMapper, defaultTimeout, getAbortByAbortKey, getAbortByIdKey, getAbortKey, getAdapter, getAdapterBindings, getAdapterHeaders, getAdapterOnError, getAdapterPayload, getAppManagerEvents, getCacheByKey, getCacheData, getCacheEvents, getCacheKey, getDeleteByKey, getDeleteKey, getDispatcherChangeByKey, getDispatcherChangeKey, getDispatcherDrainedByKey, getDispatcherDrainedKey, getDispatcherEvents, getDispatcherRunningByKey, getDispatcherRunningKey, getDispatcherStatusByKey, getDispatcherStatusKey, getDownloadProgressByIdKey, getDownloadProgressByQueryKey, getDownloadProgressKey, getErrorMessage, getInvalidateByKey, getInvalidateKey, getIsEqualTimestamp, getLoadingByCacheKey, getLoadingByIdKey, getLoadingByQueryKey, getLoadingKey, 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, interceptRequest, interceptResponse, isNavigatorOnline, isPlainObject, logLevelOrder, logger, loggerColors, loggerStyles, mapResponseForSend, mocker, onDocumentEvent, onWindowEvent, parseErrorResponse, parseResponse, replaceEqualDeep, resolveClientMode, scopeKey, sendRequest, stringifyDefaultOptions, stringifyKey, stringifyQueryParams, stringifyValue, xhrExtra };
|
|
4303
4357
|
|
|
4304
4358
|
//# sourceMappingURL=index.mjs.map
|