@d1g1tal/transportr 1.2.0 → 1.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 +88 -0
- package/dist/transportr.js +474 -478
- package/dist/transportr.min.js +2 -2
- package/dist/transportr.min.js.map +4 -4
- package/package.json +7 -7
- package/src/transportr.js +70 -59
package/dist/transportr.js
CHANGED
|
@@ -3,7 +3,6 @@ var Transportr = (() => {
|
|
|
3
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
7
6
|
var __export = (target, all) => {
|
|
8
7
|
for (var name in all)
|
|
9
8
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -17,32 +16,6 @@ var Transportr = (() => {
|
|
|
17
16
|
return to;
|
|
18
17
|
};
|
|
19
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
-
var __publicField = (obj, key, value) => {
|
|
21
|
-
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
22
|
-
return value;
|
|
23
|
-
};
|
|
24
|
-
var __accessCheck = (obj, member, msg) => {
|
|
25
|
-
if (!member.has(obj))
|
|
26
|
-
throw TypeError("Cannot " + msg);
|
|
27
|
-
};
|
|
28
|
-
var __privateGet = (obj, member, getter) => {
|
|
29
|
-
__accessCheck(obj, member, "read from private field");
|
|
30
|
-
return getter ? getter.call(obj) : member.get(obj);
|
|
31
|
-
};
|
|
32
|
-
var __privateAdd = (obj, member, value) => {
|
|
33
|
-
if (member.has(obj))
|
|
34
|
-
throw TypeError("Cannot add the same private member more than once");
|
|
35
|
-
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
36
|
-
};
|
|
37
|
-
var __privateSet = (obj, member, value, setter) => {
|
|
38
|
-
__accessCheck(obj, member, "write to private field");
|
|
39
|
-
setter ? setter.call(obj, value) : member.set(obj, value);
|
|
40
|
-
return value;
|
|
41
|
-
};
|
|
42
|
-
var __privateMethod = (obj, member, method) => {
|
|
43
|
-
__accessCheck(obj, member, "access private method");
|
|
44
|
-
return method;
|
|
45
|
-
};
|
|
46
19
|
|
|
47
20
|
// src/transportr.js
|
|
48
21
|
var transportr_exports = {};
|
|
@@ -85,20 +58,48 @@ var Transportr = (() => {
|
|
|
85
58
|
// node_modules/@d1g1tal/collections/src/set-multi-map.js
|
|
86
59
|
var SetMultiMap = class extends Map {
|
|
87
60
|
/**
|
|
88
|
-
* Adds a new element with a specified key and value to the SetMultiMap.
|
|
61
|
+
* Adds a new element with a specified key and value to the SetMultiMap.
|
|
62
|
+
* If an element with the same key already exists, the value will be added to the underlying {@link Set}.
|
|
63
|
+
* If the value already exists in the {@link Set}, it will not be added again.
|
|
89
64
|
*
|
|
90
65
|
* @param {K} key The key to set.
|
|
91
66
|
* @param {V} value The value to add to the SetMultiMap
|
|
92
|
-
* @returns {SetMultiMap} The SetMultiMap with the updated key and value.
|
|
67
|
+
* @returns {SetMultiMap<K, V>} The SetMultiMap with the updated key and value.
|
|
93
68
|
*/
|
|
94
69
|
set(key, value) {
|
|
95
70
|
super.set(key, (super.get(key) ?? /* @__PURE__ */ new Set()).add(value));
|
|
96
71
|
return this;
|
|
97
72
|
}
|
|
98
|
-
|
|
73
|
+
/**
|
|
74
|
+
* Checks if a specific key has a specific value.
|
|
75
|
+
*
|
|
76
|
+
* @param {K} key The key to check.
|
|
77
|
+
* @param {V} value The value to check.
|
|
78
|
+
* @returns {boolean} True if the key has the value, false otherwise.
|
|
79
|
+
*/
|
|
80
|
+
hasValue(key, value) {
|
|
81
|
+
const values = super.get(key);
|
|
82
|
+
return values ? values.has(value) : false;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Removes a specific value from a specific key.
|
|
86
|
+
*
|
|
87
|
+
* @param {K} key The key to remove the value from.
|
|
88
|
+
* @param {V} value The value to remove.
|
|
89
|
+
* @returns {boolean} True if the value was removed, false otherwise.
|
|
90
|
+
*/
|
|
91
|
+
deleteValue(key, value) {
|
|
92
|
+
const values = super.get(key);
|
|
93
|
+
if (values) {
|
|
94
|
+
return values.delete(value);
|
|
95
|
+
}
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
98
|
+
get [Symbol.toStringTag]() {
|
|
99
99
|
return "SetMultiMap";
|
|
100
100
|
}
|
|
101
101
|
};
|
|
102
|
+
var set_multi_map_default = SetMultiMap;
|
|
102
103
|
|
|
103
104
|
// node_modules/@d1g1tal/media-type/src/utils.js
|
|
104
105
|
var whitespaceCharacters = [" ", " ", "\n", "\r"];
|
|
@@ -359,7 +360,7 @@ var Transportr = (() => {
|
|
|
359
360
|
var serializer_default = serialize;
|
|
360
361
|
|
|
361
362
|
// node_modules/@d1g1tal/media-type/src/media-type.js
|
|
362
|
-
var MediaType = class {
|
|
363
|
+
var MediaType = class _MediaType {
|
|
363
364
|
/** @type {string} */
|
|
364
365
|
#type;
|
|
365
366
|
/** @type {string} */
|
|
@@ -386,7 +387,7 @@ var Transportr = (() => {
|
|
|
386
387
|
*/
|
|
387
388
|
static parse(string) {
|
|
388
389
|
try {
|
|
389
|
-
return new
|
|
390
|
+
return new _MediaType(string);
|
|
390
391
|
} catch (e) {
|
|
391
392
|
throw new Error(`Could not parse media type string '${string}'`);
|
|
392
393
|
}
|
|
@@ -526,6 +527,24 @@ var Transportr = (() => {
|
|
|
526
527
|
}
|
|
527
528
|
};
|
|
528
529
|
|
|
530
|
+
// node_modules/@d1g1tal/subscribr/node_modules/@d1g1tal/collections/src/set-multi-map.js
|
|
531
|
+
var SetMultiMap2 = class extends Map {
|
|
532
|
+
/**
|
|
533
|
+
* Adds a new element with a specified key and value to the SetMultiMap. If an element with the same key already exists, the value will be added to the underlying {@link Set}.
|
|
534
|
+
*
|
|
535
|
+
* @param {*} key The key to set.
|
|
536
|
+
* @param {*} value The value to add to the SetMultiMap
|
|
537
|
+
* @returns {SetMultiMap} The SetMultiMap with the updated key and value.
|
|
538
|
+
*/
|
|
539
|
+
set(key, value) {
|
|
540
|
+
super.set(key, (super.get(key) ?? /* @__PURE__ */ new Set()).add(value));
|
|
541
|
+
return this;
|
|
542
|
+
}
|
|
543
|
+
[Symbol.toStringTag]() {
|
|
544
|
+
return "SetMultiMap";
|
|
545
|
+
}
|
|
546
|
+
};
|
|
547
|
+
|
|
529
548
|
// node_modules/@d1g1tal/subscribr/src/context-event-handler.js
|
|
530
549
|
var ContextEventHandler = class {
|
|
531
550
|
#context;
|
|
@@ -590,7 +609,7 @@ var Transportr = (() => {
|
|
|
590
609
|
/** @type {SetMultiMap<string, ContextEventHandler>} */
|
|
591
610
|
#subscribers;
|
|
592
611
|
constructor() {
|
|
593
|
-
this.#subscribers = new
|
|
612
|
+
this.#subscribers = new SetMultiMap2();
|
|
594
613
|
}
|
|
595
614
|
/**
|
|
596
615
|
* Subscribe to an event
|
|
@@ -1914,8 +1933,42 @@ var Transportr = (() => {
|
|
|
1914
1933
|
var _handleHtml = async (response) => new DOMParser().parseFromString(await response.text(), http_media_type_default.HTML);
|
|
1915
1934
|
var _handleHtmlFragment = async (response) => document.createRange().createContextualFragment(await response.text());
|
|
1916
1935
|
var _typeConverter = (data) => Object.fromEntries(Array.from(data.keys()).map((key, index, keys, value = data.getAll(key)) => [key, value.length > 1 ? value : value[0]]));
|
|
1917
|
-
var
|
|
1918
|
-
|
|
1936
|
+
var Transportr = class _Transportr {
|
|
1937
|
+
/** @type {URL} */
|
|
1938
|
+
#baseUrl;
|
|
1939
|
+
/** @type {RequestOptions} */
|
|
1940
|
+
#options;
|
|
1941
|
+
/** @type {Subscribr} */
|
|
1942
|
+
#subscribr;
|
|
1943
|
+
/** @type {Subscribr} */
|
|
1944
|
+
static #globalSubscribr = new Subscribr();
|
|
1945
|
+
/** @type {Array<SignalController>} */
|
|
1946
|
+
static #activeRequests = [];
|
|
1947
|
+
/**
|
|
1948
|
+
* @private
|
|
1949
|
+
* @static
|
|
1950
|
+
* @type {SetMultiMap<ResponseHandler<ResponseBody>, string>}
|
|
1951
|
+
*/
|
|
1952
|
+
static #contentTypeHandlers = new set_multi_map_default([
|
|
1953
|
+
[_handleImage, _mediaTypes.get(http_media_type_default.PNG).type],
|
|
1954
|
+
[_handleText, _mediaTypes.get(http_media_type_default.TEXT).type],
|
|
1955
|
+
[_handleJson, _mediaTypes.get(http_media_type_default.JSON).subtype],
|
|
1956
|
+
[_handleHtml, _mediaTypes.get(http_media_type_default.HTML).subtype],
|
|
1957
|
+
[_handleScript, _mediaTypes.get(http_media_type_default.JAVA_SCRIPT).subtype],
|
|
1958
|
+
[_handleCss, _mediaTypes.get(http_media_type_default.CSS).subtype],
|
|
1959
|
+
[_handleXml, _mediaTypes.get(http_media_type_default.XML).subtype],
|
|
1960
|
+
[_handleReadableStream, _mediaTypes.get(http_media_type_default.BIN).subtype]
|
|
1961
|
+
]);
|
|
1962
|
+
/**
|
|
1963
|
+
* @private
|
|
1964
|
+
* @static
|
|
1965
|
+
* @type {Set<PropertyTypeConverter>}
|
|
1966
|
+
*/
|
|
1967
|
+
static #propertyTypeConverters = /* @__PURE__ */ new Set([
|
|
1968
|
+
[{ property: "body", type: FormData, converter: _typeConverter }],
|
|
1969
|
+
[{ property: "searchParams", type: URLSearchParams, converter: _typeConverter }],
|
|
1970
|
+
[{ property: "headers", type: Headers, converter: Object.fromEntries }]
|
|
1971
|
+
]);
|
|
1919
1972
|
/**
|
|
1920
1973
|
* Create a new Transportr instance with the provided location or origin and context path.
|
|
1921
1974
|
*
|
|
@@ -1923,73 +1976,6 @@ var Transportr = (() => {
|
|
|
1923
1976
|
* @param {RequestOptions} [options={}] The default {@link RequestOptions} for this instance.
|
|
1924
1977
|
*/
|
|
1925
1978
|
constructor(url = location.origin, options = {}) {
|
|
1926
|
-
/**
|
|
1927
|
-
* Makes a GET request to the given path, using the given options, and then calls the
|
|
1928
|
-
* given response handler with the response.
|
|
1929
|
-
*
|
|
1930
|
-
* @private
|
|
1931
|
-
* @async
|
|
1932
|
-
* @param {string} path - The path to the endpoint you want to call.
|
|
1933
|
-
* @param {RequestOptions} [userOptions] - The options passed to the public function to use for the request.
|
|
1934
|
-
* @param {RequestOptions} [options] - The options for the request.
|
|
1935
|
-
* @param {ResponseHandler<ResponseBody>} [responseHandler] - A function that will be called with the response object.
|
|
1936
|
-
* @returns {Promise<ResponseBody>} The result of the #request method.
|
|
1937
|
-
*/
|
|
1938
|
-
__privateAdd(this, _get);
|
|
1939
|
-
/**
|
|
1940
|
-
* It takes a path, options, and a response handler, and returns a promise that resolves to the
|
|
1941
|
-
* response entity.
|
|
1942
|
-
*
|
|
1943
|
-
* @private
|
|
1944
|
-
* @async
|
|
1945
|
-
* @param {string} path - The path to the resource you want to access.
|
|
1946
|
-
* @param {RequestOptions} [userOptions={}] - The options passed to the public function to use for the request.
|
|
1947
|
-
* @param {RequestOptions} [options={}] - The options to use for the request.
|
|
1948
|
-
* @param {ResponseHandler<ResponseBody>} [responseHandler] - A function that will be called with the response body as a parameter. This
|
|
1949
|
-
* is useful if you want to do something with the response body before returning it.
|
|
1950
|
-
* @returns {Promise<ResponseBody>} The response from the API call.
|
|
1951
|
-
*/
|
|
1952
|
-
__privateAdd(this, _request);
|
|
1953
|
-
/**
|
|
1954
|
-
* Handles an error by logging it and throwing it.
|
|
1955
|
-
*
|
|
1956
|
-
* @private
|
|
1957
|
-
* @param {URL} url The path to the resource you want to access.
|
|
1958
|
-
* @param {import('./http-error.js').HttpErrorOptions} options The options for the HttpError.
|
|
1959
|
-
* @returns {HttpError} The HttpError.
|
|
1960
|
-
*/
|
|
1961
|
-
__privateAdd(this, _handleError);
|
|
1962
|
-
/**
|
|
1963
|
-
* Publishes an event to the global and instance subscribers.
|
|
1964
|
-
*
|
|
1965
|
-
* @private
|
|
1966
|
-
* @param {string} eventName The name of the event.
|
|
1967
|
-
* @param {boolean} global Whether or not to publish the event to the global subscribers.
|
|
1968
|
-
* @param {Event} [event] The event object.
|
|
1969
|
-
* @param {*} [data] The data to pass to the subscribers.
|
|
1970
|
-
* @returns {void}
|
|
1971
|
-
*/
|
|
1972
|
-
__privateAdd(this, _publish);
|
|
1973
|
-
/**
|
|
1974
|
-
* It takes a response and a handler, and if the handler is not defined, it tries to find a handler
|
|
1975
|
-
* based on the response's content type
|
|
1976
|
-
*
|
|
1977
|
-
* @private
|
|
1978
|
-
* @static
|
|
1979
|
-
* @async
|
|
1980
|
-
* @param {Response} response - The response object returned by the fetch API.
|
|
1981
|
-
* @param {URL} url - The path to the resource you want to access. Used for error handling.
|
|
1982
|
-
* @param {ResponseHandler<ResponseBody>} [handler] - The handler to use for processing the response.
|
|
1983
|
-
* @returns {Promise<ResponseBody>} The response is being returned.
|
|
1984
|
-
*/
|
|
1985
|
-
__privateAdd(this, _processResponse);
|
|
1986
|
-
/** @type {URL} */
|
|
1987
|
-
__privateAdd(this, _baseUrl, void 0);
|
|
1988
|
-
/** @type {RequestOptions} */
|
|
1989
|
-
__privateAdd(this, _options, void 0);
|
|
1990
|
-
/** @type {Subscribr} */
|
|
1991
|
-
__privateAdd(this, _subscribr, void 0);
|
|
1992
|
-
var _a;
|
|
1993
1979
|
const type = object_type_default(url);
|
|
1994
1980
|
if (type == Object) {
|
|
1995
1981
|
options = url;
|
|
@@ -1997,9 +1983,9 @@ var Transportr = (() => {
|
|
|
1997
1983
|
} else if (type != URL) {
|
|
1998
1984
|
url = url.startsWith("/") ? new URL(url, location.origin) : new URL(url);
|
|
1999
1985
|
}
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
1986
|
+
this.#baseUrl = url;
|
|
1987
|
+
this.#options = object_merge_default(_Transportr.#defaultRequestOptions, _Transportr.#convertRequestOptions(options));
|
|
1988
|
+
this.#subscribr = new Subscribr();
|
|
2003
1989
|
}
|
|
2004
1990
|
/**
|
|
2005
1991
|
* Returns a {@link SignalController} used for aborting requests.
|
|
@@ -2021,7 +2007,7 @@ var Transportr = (() => {
|
|
|
2021
2007
|
* @returns {EventRegistration} A new {@link EventRegistration} instance.
|
|
2022
2008
|
*/
|
|
2023
2009
|
static register(event, handler, context) {
|
|
2024
|
-
return
|
|
2010
|
+
return _Transportr.#globalSubscribr.subscribe(event, handler, context);
|
|
2025
2011
|
}
|
|
2026
2012
|
/**
|
|
2027
2013
|
* Removes a {@link EventRegistration} from the global event handler.
|
|
@@ -2031,7 +2017,7 @@ var Transportr = (() => {
|
|
|
2031
2017
|
* @returns {boolean} True if the {@link EventRegistration} was removed, false otherwise.
|
|
2032
2018
|
*/
|
|
2033
2019
|
static unregister(eventRegistration) {
|
|
2034
|
-
return
|
|
2020
|
+
return _Transportr.#globalSubscribr.unsubscribe(eventRegistration);
|
|
2035
2021
|
}
|
|
2036
2022
|
/**
|
|
2037
2023
|
* Aborts all active requests.
|
|
@@ -2043,18 +2029,138 @@ var Transportr = (() => {
|
|
|
2043
2029
|
* @returns {void}
|
|
2044
2030
|
*/
|
|
2045
2031
|
static abortAll() {
|
|
2046
|
-
for (const signalController of
|
|
2032
|
+
for (const signalController of this.#activeRequests) {
|
|
2047
2033
|
signalController.abort();
|
|
2048
2034
|
}
|
|
2049
|
-
|
|
2035
|
+
this.#activeRequests = [];
|
|
2050
2036
|
}
|
|
2037
|
+
/**
|
|
2038
|
+
* @static
|
|
2039
|
+
* @constant {Object<string, HttpRequestMethod>}
|
|
2040
|
+
*/
|
|
2041
|
+
static Method = Object.freeze(http_request_methods_default);
|
|
2042
|
+
/**
|
|
2043
|
+
* @static
|
|
2044
|
+
* @constant {Object<string, HttpMediaType>}
|
|
2045
|
+
*/
|
|
2046
|
+
static MediaType = Object.freeze(http_media_type_default);
|
|
2047
|
+
/**
|
|
2048
|
+
* @static
|
|
2049
|
+
* @see {@link HttpRequestHeader}
|
|
2050
|
+
* @constant {Object<string, HttpRequestHeader>}
|
|
2051
|
+
*/
|
|
2052
|
+
static RequestHeader = Object.freeze(http_request_headers_default);
|
|
2053
|
+
/**
|
|
2054
|
+
* @static
|
|
2055
|
+
* @constant {Object<string, HttpResponseHeader>}
|
|
2056
|
+
*/
|
|
2057
|
+
static ResponseHeader = Object.freeze(http_response_headers_default);
|
|
2058
|
+
/**
|
|
2059
|
+
* @static
|
|
2060
|
+
* @constant {Object<string, RequestCache>}
|
|
2061
|
+
*/
|
|
2062
|
+
static CachingPolicy = Object.freeze({
|
|
2063
|
+
DEFAULT: "default",
|
|
2064
|
+
FORCE_CACHE: "force-cache",
|
|
2065
|
+
NO_CACHE: "no-cache",
|
|
2066
|
+
NO_STORE: "no-store",
|
|
2067
|
+
ONLY_IF_CACHED: "only-if-cached",
|
|
2068
|
+
RELOAD: "reload"
|
|
2069
|
+
});
|
|
2070
|
+
/**
|
|
2071
|
+
* @static
|
|
2072
|
+
* @constant {Object<string, RequestCredentials>}
|
|
2073
|
+
*/
|
|
2074
|
+
static CredentialsPolicy = Object.freeze({
|
|
2075
|
+
INCLUDE: "include",
|
|
2076
|
+
OMIT: "omit",
|
|
2077
|
+
SAME_ORIGIN: "same-origin"
|
|
2078
|
+
});
|
|
2079
|
+
/**
|
|
2080
|
+
* @static
|
|
2081
|
+
* @constant {Object<string, RequestMode>}
|
|
2082
|
+
*/
|
|
2083
|
+
static RequestMode = Object.freeze({
|
|
2084
|
+
CORS: "cors",
|
|
2085
|
+
NAVIGATE: "navigate",
|
|
2086
|
+
NO_CORS: "no-cors",
|
|
2087
|
+
SAME_ORIGIN: "same-origin"
|
|
2088
|
+
});
|
|
2089
|
+
/**
|
|
2090
|
+
* @static
|
|
2091
|
+
* @constant {Object<string, RequestRedirect>}
|
|
2092
|
+
*/
|
|
2093
|
+
static RedirectPolicy = Object.freeze({
|
|
2094
|
+
ERROR: "error",
|
|
2095
|
+
FOLLOW: "follow",
|
|
2096
|
+
MANUAL: "manual"
|
|
2097
|
+
});
|
|
2098
|
+
/**
|
|
2099
|
+
* @static
|
|
2100
|
+
* @constant {Object<string, ReferrerPolicy>}
|
|
2101
|
+
*/
|
|
2102
|
+
static ReferrerPolicy = Object.freeze({
|
|
2103
|
+
NO_REFERRER: "no-referrer",
|
|
2104
|
+
NO_REFERRER_WHEN_DOWNGRADE: "no-referrer-when-downgrade",
|
|
2105
|
+
ORIGIN: "origin",
|
|
2106
|
+
ORIGIN_WHEN_CROSS_ORIGIN: "origin-when-cross-origin",
|
|
2107
|
+
SAME_ORIGIN: "same-origin",
|
|
2108
|
+
STRICT_ORIGIN: "strict-origin",
|
|
2109
|
+
STRICT_ORIGIN_WHEN_CROSS_ORIGIN: "strict-origin-when-cross-origin",
|
|
2110
|
+
UNSAFE_URL: "unsafe-url"
|
|
2111
|
+
});
|
|
2112
|
+
/**
|
|
2113
|
+
* @static
|
|
2114
|
+
* @constant {Object<string, TransportrEvent>}
|
|
2115
|
+
*/
|
|
2116
|
+
static Events = Object.freeze({
|
|
2117
|
+
CONFIGURED: "configured",
|
|
2118
|
+
SUCCESS: "success",
|
|
2119
|
+
ERROR: "error",
|
|
2120
|
+
ABORTED: "aborted",
|
|
2121
|
+
TIMEOUT: "timeout",
|
|
2122
|
+
COMPLETE: "complete",
|
|
2123
|
+
ALL_COMPLETE: "all-complete"
|
|
2124
|
+
});
|
|
2125
|
+
/**
|
|
2126
|
+
* @private
|
|
2127
|
+
* @static
|
|
2128
|
+
* @type {RequestOptions}
|
|
2129
|
+
*/
|
|
2130
|
+
static #defaultRequestOptions = Object.freeze({
|
|
2131
|
+
body: null,
|
|
2132
|
+
cache: _Transportr.CachingPolicy.NO_STORE,
|
|
2133
|
+
credentials: _Transportr.CredentialsPolicy.SAME_ORIGIN,
|
|
2134
|
+
headers: { [http_request_headers_default.CONTENT_TYPE]: _mediaTypes.get(http_media_type_default.JSON).toString(), [http_request_headers_default.ACCEPT]: _mediaTypes.get(http_media_type_default.JSON).toString() },
|
|
2135
|
+
searchParams: {},
|
|
2136
|
+
integrity: void 0,
|
|
2137
|
+
keepalive: void 0,
|
|
2138
|
+
method: http_request_methods_default.GET,
|
|
2139
|
+
mode: _Transportr.RequestMode.CORS,
|
|
2140
|
+
redirect: _Transportr.RedirectPolicy.FOLLOW,
|
|
2141
|
+
referrer: "about:client",
|
|
2142
|
+
referrerPolicy: _Transportr.ReferrerPolicy.STRICT_ORIGIN_WHEN_CROSS_ORIGIN,
|
|
2143
|
+
signal: void 0,
|
|
2144
|
+
timeout: 3e4,
|
|
2145
|
+
global: true,
|
|
2146
|
+
window: null
|
|
2147
|
+
});
|
|
2148
|
+
/**
|
|
2149
|
+
* @private
|
|
2150
|
+
* @static
|
|
2151
|
+
* @type {Map<TransportrEvent, ResponseStatus>}
|
|
2152
|
+
*/
|
|
2153
|
+
static #eventResponseStatuses = /* @__PURE__ */ new Map([
|
|
2154
|
+
[_Transportr.Events.ABORTED, new ResponseStatus(499, "Aborted")],
|
|
2155
|
+
[_Transportr.Events.TIMEOUT, new ResponseStatus(504, "Gateway Timeout")]
|
|
2156
|
+
]);
|
|
2051
2157
|
/**
|
|
2052
2158
|
* It returns the base {@link URL} for the API.
|
|
2053
2159
|
*
|
|
2054
2160
|
* @returns {URL} The baseUrl property.
|
|
2055
2161
|
*/
|
|
2056
2162
|
get baseUrl() {
|
|
2057
|
-
return
|
|
2163
|
+
return this.#baseUrl;
|
|
2058
2164
|
}
|
|
2059
2165
|
/**
|
|
2060
2166
|
* Registers an event handler with a {@link Transportr} instance.
|
|
@@ -2065,7 +2171,7 @@ var Transportr = (() => {
|
|
|
2065
2171
|
* @returns {EventRegistration} An object that can be used to remove the event handler.
|
|
2066
2172
|
*/
|
|
2067
2173
|
register(event, handler, context) {
|
|
2068
|
-
return
|
|
2174
|
+
return this.#subscribr.subscribe(event, handler, context);
|
|
2069
2175
|
}
|
|
2070
2176
|
/**
|
|
2071
2177
|
* Unregisters an event handler from a {@link Transportr} instance.
|
|
@@ -2074,545 +2180,435 @@ var Transportr = (() => {
|
|
|
2074
2180
|
* @returns {void}
|
|
2075
2181
|
*/
|
|
2076
2182
|
unregister(eventRegistration) {
|
|
2077
|
-
|
|
2183
|
+
this.#subscribr.unsubscribe(eventRegistration);
|
|
2078
2184
|
}
|
|
2079
2185
|
/**
|
|
2080
2186
|
* This function returns a promise that resolves to the result of a request to the specified path with
|
|
2081
2187
|
* the specified options, where the method is GET.
|
|
2082
2188
|
*
|
|
2083
2189
|
* @async
|
|
2084
|
-
* @param {string} path
|
|
2085
|
-
* @param {RequestOptions} [options]
|
|
2190
|
+
* @param {string} [path] The path to the resource you want to get.
|
|
2191
|
+
* @param {RequestOptions} [options] The options for the request.
|
|
2086
2192
|
* @returns {Promise<ResponseBody>} A promise that resolves to the response of the request.
|
|
2087
2193
|
*/
|
|
2088
2194
|
async get(path, options) {
|
|
2089
|
-
return
|
|
2195
|
+
return this.#get(path, options);
|
|
2090
2196
|
}
|
|
2091
2197
|
/**
|
|
2092
2198
|
* This function makes a POST request to the given path with the given body and options.
|
|
2093
2199
|
*
|
|
2094
2200
|
* @async
|
|
2095
|
-
* @param {string} path
|
|
2096
|
-
* @param {RequestBody} body
|
|
2097
|
-
* @param {RequestOptions} [options]
|
|
2201
|
+
* @param {string} [path] The path to the endpoint you want to call.
|
|
2202
|
+
* @param {RequestBody} body The body of the request.
|
|
2203
|
+
* @param {RequestOptions} [options] The options for the request.
|
|
2098
2204
|
* @returns {Promise<ResponseBody>} A promise that resolves to the response body.
|
|
2099
2205
|
*/
|
|
2100
2206
|
async post(path, body, options) {
|
|
2101
|
-
return
|
|
2207
|
+
return this.#request(path, { ...options, body }, { method: http_request_methods_default.POST });
|
|
2102
2208
|
}
|
|
2103
2209
|
/**
|
|
2104
2210
|
* This function returns a promise that resolves to the result of a request to the specified path with
|
|
2105
2211
|
* the specified options, where the method is PUT.
|
|
2106
2212
|
*
|
|
2107
2213
|
* @async
|
|
2108
|
-
* @param {string} path
|
|
2109
|
-
* @param {RequestOptions} [options]
|
|
2214
|
+
* @param {string} [path] The path to the endpoint you want to call.
|
|
2215
|
+
* @param {RequestOptions} [options] The options for the request.
|
|
2110
2216
|
* @returns {Promise<ResponseBody>} The return value of the #request method.
|
|
2111
2217
|
*/
|
|
2112
2218
|
async put(path, options) {
|
|
2113
|
-
return
|
|
2219
|
+
return this.#request(path, options, { method: http_request_methods_default.PUT });
|
|
2114
2220
|
}
|
|
2115
2221
|
/**
|
|
2116
2222
|
* It takes a path and options, and returns a request with the method set to PATCH.
|
|
2117
2223
|
*
|
|
2118
2224
|
* @async
|
|
2119
|
-
* @param {string} path
|
|
2120
|
-
* @param {RequestOptions} [options]
|
|
2225
|
+
* @param {string} [path] The path to the endpoint you want to hit.
|
|
2226
|
+
* @param {RequestOptions} [options] The options for the request.
|
|
2121
2227
|
* @returns {Promise<ResponseBody>} A promise that resolves to the response of the request.
|
|
2122
2228
|
*/
|
|
2123
2229
|
async patch(path, options) {
|
|
2124
|
-
return
|
|
2230
|
+
return this.#request(path, options, { method: http_request_methods_default.PATCH });
|
|
2125
2231
|
}
|
|
2126
2232
|
/**
|
|
2127
2233
|
* It takes a path and options, and returns a request with the method set to DELETE.
|
|
2128
2234
|
*
|
|
2129
2235
|
* @async
|
|
2130
|
-
* @param {string} path
|
|
2131
|
-
* @param {RequestOptions} [options]
|
|
2236
|
+
* @param {string} [path] The path to the resource you want to access.
|
|
2237
|
+
* @param {RequestOptions} [options] The options for the request.
|
|
2132
2238
|
* @returns {Promise<ResponseBody>} The result of the request.
|
|
2133
2239
|
*/
|
|
2134
2240
|
async delete(path, options) {
|
|
2135
|
-
return
|
|
2241
|
+
return this.#request(path, options, { method: http_request_methods_default.DELETE });
|
|
2136
2242
|
}
|
|
2137
2243
|
/**
|
|
2138
2244
|
* Returns the response headers of a request to the given path.
|
|
2139
2245
|
*
|
|
2140
2246
|
* @async
|
|
2141
|
-
* @param {string} path
|
|
2142
|
-
* @param {RequestOptions} [options]
|
|
2247
|
+
* @param {string} [path] The path to the resource you want to access.
|
|
2248
|
+
* @param {RequestOptions} [options] The options for the request.
|
|
2143
2249
|
* @returns {Promise<ResponseBody>} A promise that resolves to the response object.
|
|
2144
2250
|
*/
|
|
2145
2251
|
async head(path, options) {
|
|
2146
|
-
return
|
|
2252
|
+
return this.#request(path, options, { method: http_request_methods_default.HEAD });
|
|
2147
2253
|
}
|
|
2148
2254
|
/**
|
|
2149
2255
|
* It takes a path and options, and returns a request with the method set to OPTIONS.
|
|
2150
2256
|
*
|
|
2151
2257
|
* @async
|
|
2152
|
-
* @param {string} path
|
|
2153
|
-
* @param {RequestOptions} [options]
|
|
2258
|
+
* @param {string} [path] The path to the resource.
|
|
2259
|
+
* @param {RequestOptions} [options] The options for the request.
|
|
2154
2260
|
* @returns {Promise<ResponseBody>} The return value of the #request method.
|
|
2155
2261
|
*/
|
|
2156
2262
|
async options(path, options) {
|
|
2157
|
-
return
|
|
2263
|
+
return this.#request(path, options, { method: http_request_methods_default.OPTIONS });
|
|
2158
2264
|
}
|
|
2159
2265
|
/**
|
|
2160
2266
|
* It takes a path and options, and makes a request to the server.
|
|
2161
2267
|
*
|
|
2162
2268
|
* @async
|
|
2163
|
-
* @param {string} path
|
|
2164
|
-
* @param {RequestOptions} [options]
|
|
2269
|
+
* @param {string} [path] The path to the endpoint you want to hit.
|
|
2270
|
+
* @param {RequestOptions} [options] The options for the request.
|
|
2165
2271
|
* @returns {Promise<ResponseBody>} The return value of the function is the return value of the function that is passed to the `then` method of the promise returned by the `fetch` method.
|
|
2166
2272
|
*/
|
|
2167
2273
|
async request(path, options) {
|
|
2168
|
-
return
|
|
2274
|
+
return this.#request(path, options);
|
|
2169
2275
|
}
|
|
2170
2276
|
/**
|
|
2171
2277
|
* It gets a JSON resource from the server.
|
|
2172
2278
|
*
|
|
2173
2279
|
* @async
|
|
2174
|
-
* @param {string} path
|
|
2175
|
-
* @param {RequestOptions} [options]
|
|
2280
|
+
* @param {string} [path] The path to the resource.
|
|
2281
|
+
* @param {RequestOptions} [options] The options object to pass to the request.
|
|
2176
2282
|
* @returns {Promise<JsonObject>} A promise that resolves to the response body as a JSON object.
|
|
2177
2283
|
*/
|
|
2178
2284
|
async getJson(path, options) {
|
|
2179
|
-
return
|
|
2285
|
+
return this.#get(path, options, { headers: { [http_request_headers_default.ACCEPT]: _mediaTypes.get(http_media_type_default.JSON).toString() } }, _handleJson);
|
|
2180
2286
|
}
|
|
2181
2287
|
/**
|
|
2182
2288
|
* It gets the XML representation of the resource at the given path.
|
|
2183
2289
|
*
|
|
2184
2290
|
* @async
|
|
2185
|
-
* @param {string} path
|
|
2186
|
-
* @param {RequestOptions} [options]
|
|
2291
|
+
* @param {string} [path] The path to the resource you want to get.
|
|
2292
|
+
* @param {RequestOptions} [options] The options for the request.
|
|
2187
2293
|
* @returns {Promise<Document>} The result of the function call to #get.
|
|
2188
2294
|
*/
|
|
2189
2295
|
async getXml(path, options) {
|
|
2190
|
-
return
|
|
2296
|
+
return this.#get(path, options, { headers: { [http_request_headers_default.ACCEPT]: _mediaTypes.get(http_media_type_default.XML).toString() } }, _handleXml);
|
|
2191
2297
|
}
|
|
2192
2298
|
/**
|
|
2193
2299
|
* Get the HTML content of the specified path.
|
|
2194
2300
|
*
|
|
2195
2301
|
* @todo Add way to return portion of the retrieved HTML using a selector. Like jQuery.
|
|
2196
2302
|
* @async
|
|
2197
|
-
* @param {string} path
|
|
2198
|
-
* @param {RequestOptions} [options]
|
|
2303
|
+
* @param {string} [path] The path to the resource.
|
|
2304
|
+
* @param {RequestOptions} [options] The options for the request.
|
|
2199
2305
|
* @returns {Promise<Document>} The return value of the function is the return value of the function passed to the `then`
|
|
2200
2306
|
* method of the promise returned by the `#get` method.
|
|
2201
2307
|
*/
|
|
2202
2308
|
async getHtml(path, options) {
|
|
2203
|
-
return
|
|
2309
|
+
return this.#get(path, options, { headers: { [http_request_headers_default.ACCEPT]: _mediaTypes.get(http_media_type_default.HTML).toString() } }, _handleHtml);
|
|
2204
2310
|
}
|
|
2205
2311
|
/**
|
|
2206
2312
|
* It returns a promise that resolves to the HTML fragment at the given path.
|
|
2207
2313
|
*
|
|
2208
|
-
* @todo
|
|
2314
|
+
* @todo Add way to return portion of the retrieved HTML using a selector. Like jQuery.
|
|
2209
2315
|
* @async
|
|
2210
|
-
* @param {string} path
|
|
2211
|
-
* @param {RequestOptions} [options]
|
|
2316
|
+
* @param {string} [path] The path to the resource.
|
|
2317
|
+
* @param {RequestOptions} [options] The options for the request.
|
|
2212
2318
|
* @returns {Promise<DocumentFragment>} A promise that resolves to an HTML fragment.
|
|
2213
2319
|
*/
|
|
2214
2320
|
async getHtmlFragment(path, options) {
|
|
2215
|
-
return
|
|
2321
|
+
return this.#get(path, options, { headers: { [http_request_headers_default.ACCEPT]: _mediaTypes.get(http_media_type_default.HTML).toString() } }, _handleHtmlFragment);
|
|
2216
2322
|
}
|
|
2217
2323
|
/**
|
|
2218
2324
|
* It gets a script from the server, and appends the script to the {@link Document} {@link HTMLHeadElement}
|
|
2219
2325
|
* CORS is enabled by default.
|
|
2220
2326
|
*
|
|
2221
2327
|
* @async
|
|
2222
|
-
* @param {string} path
|
|
2223
|
-
* @param {RequestOptions} [options]
|
|
2328
|
+
* @param {string} [path] The path to the script.
|
|
2329
|
+
* @param {RequestOptions} [options] The options for the request.
|
|
2224
2330
|
* @returns {Promise<void>} A promise that has been resolved.
|
|
2225
2331
|
*/
|
|
2226
2332
|
async getScript(path, options) {
|
|
2227
|
-
return
|
|
2333
|
+
return this.#get(path, options, { headers: { [http_request_headers_default.ACCEPT]: _mediaTypes.get(http_media_type_default.JAVA_SCRIPT).toString() } }, _handleScript);
|
|
2228
2334
|
}
|
|
2229
2335
|
/**
|
|
2230
2336
|
* Gets a stylesheet from the server, and adds it as a {@link Blob} {@link URL}.
|
|
2231
2337
|
*
|
|
2232
2338
|
* @async
|
|
2233
|
-
* @param {string} path
|
|
2234
|
-
* @param {RequestOptions} [options]
|
|
2339
|
+
* @param {string} [path] The path to the stylesheet.
|
|
2340
|
+
* @param {RequestOptions} [options] The options for the request.
|
|
2235
2341
|
* @returns {Promise<void>} A promise that has been resolved.
|
|
2236
2342
|
*/
|
|
2237
2343
|
async getStylesheet(path, options) {
|
|
2238
|
-
return
|
|
2344
|
+
return this.#get(path, options, { headers: { [http_request_headers_default.ACCEPT]: _mediaTypes.get(http_media_type_default.CSS).toString() } }, _handleCss);
|
|
2239
2345
|
}
|
|
2240
2346
|
/**
|
|
2241
2347
|
* It returns a blob from the specified path.
|
|
2242
2348
|
*
|
|
2243
2349
|
* @async
|
|
2244
|
-
* @param {string} path
|
|
2245
|
-
* @param {RequestOptions} [options]
|
|
2350
|
+
* @param {string} [path] The path to the resource.
|
|
2351
|
+
* @param {RequestOptions} [options] The options for the request.
|
|
2246
2352
|
* @returns {Promise<Blob>} A promise that resolves to a blob.
|
|
2247
2353
|
*/
|
|
2248
2354
|
async getBlob(path, options) {
|
|
2249
|
-
return
|
|
2355
|
+
return this.#get(path, options, { headers: { [http_request_headers_default.ACCEPT]: http_media_type_default.BIN } }, _handleBlob);
|
|
2250
2356
|
}
|
|
2251
2357
|
/**
|
|
2252
2358
|
* It returns a promise that resolves to an object URL.
|
|
2253
2359
|
*
|
|
2254
2360
|
* @async
|
|
2255
|
-
* @param {string} path
|
|
2256
|
-
* @param {RequestOptions} [options]
|
|
2361
|
+
* @param {string|RequestOptions} [path] The path to the resource.
|
|
2362
|
+
* @param {RequestOptions} [options] The options for the request.
|
|
2257
2363
|
* @returns {Promise<string>} A promise that resolves to an object URL.
|
|
2258
2364
|
*/
|
|
2259
2365
|
async getImage(path, options) {
|
|
2260
|
-
return
|
|
2366
|
+
return this.#get(path, options, { headers: { [http_request_headers_default.ACCEPT]: "image/*" } }, _handleImage);
|
|
2261
2367
|
}
|
|
2262
2368
|
/**
|
|
2263
2369
|
* It gets a buffer from the specified path
|
|
2264
2370
|
*
|
|
2265
2371
|
* @async
|
|
2266
|
-
* @param {string} path
|
|
2267
|
-
* @param {RequestOptions} [options]
|
|
2372
|
+
* @param {string} [path] The path to the resource.
|
|
2373
|
+
* @param {RequestOptions} [options] The options for the request.
|
|
2268
2374
|
* @returns {Promise<ArrayBuffer>} A promise that resolves to a buffer.
|
|
2269
2375
|
*/
|
|
2270
2376
|
async getBuffer(path, options) {
|
|
2271
|
-
return
|
|
2377
|
+
return this.#get(path, options, { headers: { [http_request_headers_default.ACCEPT]: http_media_type_default.BIN } }, _handleBuffer);
|
|
2272
2378
|
}
|
|
2273
2379
|
/**
|
|
2274
2380
|
* It returns a readable stream of the response body from the specified path.
|
|
2275
2381
|
*
|
|
2276
2382
|
* @async
|
|
2277
|
-
* @param {string} path
|
|
2278
|
-
* @param {RequestOptions} [options]
|
|
2383
|
+
* @param {string} [path] The path to the resource.
|
|
2384
|
+
* @param {RequestOptions} [options] The options for the request.
|
|
2279
2385
|
* @returns {Promise<ReadableStream<Uint8Array>>} A readable stream.
|
|
2280
2386
|
*/
|
|
2281
2387
|
async getStream(path, options) {
|
|
2282
|
-
return
|
|
2388
|
+
return this.#get(path, options, { headers: { [http_request_headers_default.ACCEPT]: http_media_type_default.BIN } }, _handleReadableStream);
|
|
2283
2389
|
}
|
|
2284
2390
|
/**
|
|
2285
|
-
*
|
|
2286
|
-
*
|
|
2391
|
+
* Makes a GET request to the given path, using the given options, and then calls the
|
|
2392
|
+
* given response handler with the response.
|
|
2287
2393
|
*
|
|
2288
|
-
* @
|
|
2394
|
+
* @private
|
|
2395
|
+
* @async
|
|
2396
|
+
* @param {string} [path] The path to the endpoint you want to call.
|
|
2397
|
+
* @param {RequestOptions} [userOptions] The options passed to the public function to use for the request.
|
|
2398
|
+
* @param {RequestOptions} [options] The options for the request.
|
|
2399
|
+
* @param {ResponseHandler<ResponseBody>} [responseHandler] A function that will be called with the response object.
|
|
2400
|
+
* @returns {Promise<ResponseBody>} The result of the #request method.
|
|
2289
2401
|
*/
|
|
2290
|
-
get
|
|
2291
|
-
|
|
2402
|
+
async #get(path, userOptions, options, responseHandler) {
|
|
2403
|
+
delete userOptions?.method;
|
|
2404
|
+
return this.#request(path, userOptions, options, responseHandler);
|
|
2292
2405
|
}
|
|
2293
|
-
|
|
2294
|
-
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
|
|
2300
|
-
|
|
2301
|
-
|
|
2302
|
-
|
|
2303
|
-
|
|
2304
|
-
|
|
2305
|
-
|
|
2306
|
-
|
|
2307
|
-
|
|
2308
|
-
|
|
2309
|
-
|
|
2310
|
-
var _a, _b, _c, _d, _e;
|
|
2311
|
-
const requestOptions = object_merge_default(__privateGet(this, _options), __privateMethod(_a = _Transportr, _convertRequestOptions, convertRequestOptions_fn).call(_a, userOptions), options);
|
|
2312
|
-
const url = __privateMethod(_b = _Transportr, _createUrl, createUrl_fn).call(_b, __privateGet(this, _baseUrl), path, requestOptions.searchParams);
|
|
2313
|
-
const signalController = new SignalController(requestOptions.signal);
|
|
2314
|
-
__privateGet(_Transportr, _activeRequests).push(signalController);
|
|
2315
|
-
requestOptions.signal = signalController.signal;
|
|
2316
|
-
if (__privateMethod(_c = _Transportr, _needsSerialization, needsSerialization_fn).call(_c, requestOptions.method, requestOptions.headers[http_request_headers_default.CONTENT_TYPE])) {
|
|
2317
|
-
try {
|
|
2318
|
-
requestOptions.body = JSON.stringify(requestOptions.body);
|
|
2319
|
-
} catch (error) {
|
|
2320
|
-
return Promise.reject(new HttpError(url, { cause: error }));
|
|
2406
|
+
/**
|
|
2407
|
+
* It takes a path, options, and a response handler, and returns a promise that resolves to the
|
|
2408
|
+
* response entity.
|
|
2409
|
+
*
|
|
2410
|
+
* @private
|
|
2411
|
+
* @async
|
|
2412
|
+
* @param {string} [path] The path to the resource you want to access.
|
|
2413
|
+
* @param {RequestOptions} [userOptions={}] The options passed to the public function to use for the request.
|
|
2414
|
+
* @param {RequestOptions} [options={}] The options to use for the request.
|
|
2415
|
+
* @param {ResponseHandler<ResponseBody>} [responseHandler] A function that will be called with the response body as a parameter. This
|
|
2416
|
+
* is useful if you want to do something with the response body before returning it.
|
|
2417
|
+
* @returns {Promise<ResponseBody>} The response from the API call.
|
|
2418
|
+
*/
|
|
2419
|
+
async #request(path, userOptions = {}, options = {}, responseHandler) {
|
|
2420
|
+
if (object_type_default(path) == Object) {
|
|
2421
|
+
userOptions = path;
|
|
2422
|
+
path = void 0;
|
|
2321
2423
|
}
|
|
2322
|
-
|
|
2323
|
-
|
|
2324
|
-
|
|
2325
|
-
|
|
2326
|
-
|
|
2327
|
-
|
|
2328
|
-
|
|
2329
|
-
|
|
2330
|
-
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
|
|
2334
|
-
requestOptions.
|
|
2335
|
-
|
|
2336
|
-
response = await fetch(url, requestOptions);
|
|
2337
|
-
if (!response.ok) {
|
|
2338
|
-
return Promise.reject(__privateMethod(this, _handleError, handleError_fn).call(this, url, { status: __privateMethod(_d = _Transportr, _generateResponseStatusFromError, generateResponseStatusFromError_fn).call(_d, "ResponseError", response), entity: await __privateMethod(this, _processResponse, processResponse_fn).call(this, response, url) }));
|
|
2424
|
+
const requestOptions = object_merge_default(this.#options, _Transportr.#convertRequestOptions(userOptions), options);
|
|
2425
|
+
const url = _Transportr.#createUrl(this.#baseUrl, path, requestOptions.searchParams);
|
|
2426
|
+
const signalController = new SignalController(requestOptions.signal);
|
|
2427
|
+
_Transportr.#activeRequests.push(signalController);
|
|
2428
|
+
requestOptions.signal = signalController.signal;
|
|
2429
|
+
if (_Transportr.#needsSerialization(requestOptions.method, requestOptions.headers[http_request_headers_default.CONTENT_TYPE])) {
|
|
2430
|
+
try {
|
|
2431
|
+
requestOptions.body = JSON.stringify(requestOptions.body);
|
|
2432
|
+
} catch (error) {
|
|
2433
|
+
return Promise.reject(new HttpError(url, { cause: error }));
|
|
2434
|
+
}
|
|
2435
|
+
} else if (requestOptions.method == http_request_methods_default.GET && requestOptions.headers[http_request_headers_default.CONTENT_TYPE] != "") {
|
|
2436
|
+
delete requestOptions.headers[http_request_headers_default.CONTENT_TYPE];
|
|
2437
|
+
delete requestOptions.body;
|
|
2339
2438
|
}
|
|
2340
|
-
|
|
2341
|
-
|
|
2342
|
-
|
|
2343
|
-
|
|
2344
|
-
|
|
2345
|
-
|
|
2346
|
-
|
|
2347
|
-
|
|
2348
|
-
|
|
2349
|
-
|
|
2350
|
-
|
|
2439
|
+
requestOptions.signal.addEventListener("abort", (event) => this.#publish(_Transportr.Events.ABORTED, requestOptions.global, event));
|
|
2440
|
+
requestOptions.signal.addEventListener("timeout", (event) => this.#publish(_Transportr.Events.TIMEOUT, requestOptions.global, event));
|
|
2441
|
+
this.#publish(_Transportr.Events.CONFIGURED, requestOptions.global, requestOptions);
|
|
2442
|
+
let result, timeoutId, response;
|
|
2443
|
+
try {
|
|
2444
|
+
timeoutId = setTimeout(() => {
|
|
2445
|
+
const cause = new DOMException(`The call to '${url}' timed-out after ${requestOptions.timeout / 1e3} seconds`, "TimeoutError");
|
|
2446
|
+
signalController.abort(cause);
|
|
2447
|
+
requestOptions.signal.dispatchEvent(new CustomEvent(_Transportr.Events.TIMEOUT, { detail: { url, options: requestOptions, cause } }));
|
|
2448
|
+
}, requestOptions.timeout);
|
|
2449
|
+
response = await fetch(url, requestOptions);
|
|
2450
|
+
if (!response.ok) {
|
|
2451
|
+
return Promise.reject(this.#handleError(url, { status: _Transportr.#generateResponseStatusFromError("ResponseError", response), entity: await this.#processResponse(response, url) }));
|
|
2351
2452
|
}
|
|
2352
|
-
|
|
2353
|
-
|
|
2453
|
+
result = await this.#processResponse(response, url, responseHandler);
|
|
2454
|
+
this.#publish(_Transportr.Events.SUCCESS, requestOptions.global, result);
|
|
2455
|
+
} catch (error) {
|
|
2456
|
+
return Promise.reject(this.#handleError(url, { cause: error, status: _Transportr.#generateResponseStatusFromError(error.name, response) }));
|
|
2457
|
+
} finally {
|
|
2458
|
+
clearTimeout(timeoutId);
|
|
2459
|
+
if (!requestOptions.signal.aborted) {
|
|
2460
|
+
this.#publish(_Transportr.Events.COMPLETE, requestOptions.global, response);
|
|
2461
|
+
const index = _Transportr.#activeRequests.indexOf(signalController);
|
|
2462
|
+
if (index > -1) {
|
|
2463
|
+
_Transportr.#activeRequests.splice(index, 1);
|
|
2464
|
+
}
|
|
2465
|
+
if (_Transportr.#activeRequests.length === 0) {
|
|
2466
|
+
this.#publish(_Transportr.Events.ALL_COMPLETE, requestOptions.global, response);
|
|
2467
|
+
}
|
|
2354
2468
|
}
|
|
2355
2469
|
}
|
|
2470
|
+
return result;
|
|
2356
2471
|
}
|
|
2357
|
-
|
|
2358
|
-
|
|
2359
|
-
|
|
2360
|
-
|
|
2361
|
-
|
|
2362
|
-
|
|
2363
|
-
|
|
2364
|
-
|
|
2365
|
-
|
|
2366
|
-
|
|
2367
|
-
|
|
2368
|
-
|
|
2472
|
+
/**
|
|
2473
|
+
* Handles an error by logging it and throwing it.
|
|
2474
|
+
*
|
|
2475
|
+
* @private
|
|
2476
|
+
* @param {URL} url The path to the resource you want to access.
|
|
2477
|
+
* @param {import('./http-error.js').HttpErrorOptions} options The options for the HttpError.
|
|
2478
|
+
* @returns {HttpError} The HttpError.
|
|
2479
|
+
*/
|
|
2480
|
+
#handleError(url, options) {
|
|
2481
|
+
const error = new HttpError(`An error has occurred with your request to: '${url}'`, options);
|
|
2482
|
+
this.#publish(_Transportr.Events.ERROR, true, error);
|
|
2483
|
+
return error;
|
|
2369
2484
|
}
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
-
|
|
2373
|
-
|
|
2374
|
-
|
|
2375
|
-
|
|
2376
|
-
|
|
2377
|
-
|
|
2378
|
-
|
|
2379
|
-
|
|
2380
|
-
|
|
2485
|
+
/**
|
|
2486
|
+
* Publishes an event to the global and instance subscribers.
|
|
2487
|
+
*
|
|
2488
|
+
* @private
|
|
2489
|
+
* @param {string} eventName The name of the event.
|
|
2490
|
+
* @param {boolean} global Whether or not to publish the event to the global subscribers.
|
|
2491
|
+
* @param {Event} [event] The event object.
|
|
2492
|
+
* @param {*} [data] The data to pass to the subscribers.
|
|
2493
|
+
* @returns {void}
|
|
2494
|
+
*/
|
|
2495
|
+
#publish(eventName, global, event, data) {
|
|
2496
|
+
if (global) {
|
|
2497
|
+
_Transportr.#globalSubscribr.publish(eventName, event, data);
|
|
2498
|
+
}
|
|
2499
|
+
this.#subscribr.publish(eventName, event, data);
|
|
2381
2500
|
}
|
|
2382
|
-
|
|
2383
|
-
|
|
2384
|
-
|
|
2385
|
-
|
|
2386
|
-
|
|
2387
|
-
|
|
2388
|
-
|
|
2389
|
-
|
|
2390
|
-
|
|
2391
|
-
|
|
2392
|
-
|
|
2393
|
-
|
|
2501
|
+
/**
|
|
2502
|
+
* Generates a ResponseStatus object based on the error name and the response.
|
|
2503
|
+
*
|
|
2504
|
+
* @private
|
|
2505
|
+
* @static
|
|
2506
|
+
* @param {string} errorName The name of the error.
|
|
2507
|
+
* @param {Response} response The response object returned by the fetch API.
|
|
2508
|
+
* @returns {ResponseStatus} The response status object.
|
|
2509
|
+
*/
|
|
2510
|
+
static #generateResponseStatusFromError(errorName, response) {
|
|
2511
|
+
switch (errorName) {
|
|
2512
|
+
case "AbortError":
|
|
2513
|
+
return _Transportr.#eventResponseStatuses.get(_Transportr.Events.ABORTED);
|
|
2514
|
+
case "TimeoutError":
|
|
2515
|
+
return _Transportr.#eventResponseStatuses.get(_Transportr.Events.TIMEOUT);
|
|
2516
|
+
default:
|
|
2517
|
+
return response ? new ResponseStatus(response.status, response.statusText) : new ResponseStatus(500, "Internal Server Error");
|
|
2518
|
+
}
|
|
2519
|
+
}
|
|
2520
|
+
/**
|
|
2521
|
+
* It takes a response and a handler, and if the handler is not defined, it tries to find a handler
|
|
2522
|
+
* based on the response's content type
|
|
2523
|
+
*
|
|
2524
|
+
* @private
|
|
2525
|
+
* @static
|
|
2526
|
+
* @async
|
|
2527
|
+
* @param {Response} response The response object returned by the fetch API.
|
|
2528
|
+
* @param {URL} url The path to the resource you want to access. Used for error handling.
|
|
2529
|
+
* @param {ResponseHandler<ResponseBody>} [handler] The handler to use for processing the response.
|
|
2530
|
+
* @returns {Promise<ResponseBody>} The response is being returned.
|
|
2531
|
+
*/
|
|
2532
|
+
async #processResponse(response, url, handler) {
|
|
2533
|
+
try {
|
|
2534
|
+
let mediaType;
|
|
2535
|
+
if (!handler) {
|
|
2536
|
+
mediaType = MediaType.parse(response.headers.get(http_response_headers_default.CONTENT_TYPE));
|
|
2537
|
+
if (mediaType) {
|
|
2538
|
+
for (const [responseHandler, contentTypes] of _Transportr.#contentTypeHandlers) {
|
|
2539
|
+
if (contentTypes.has(mediaType.type) || contentTypes.has(mediaType.subtype)) {
|
|
2540
|
+
handler = responseHandler;
|
|
2541
|
+
break;
|
|
2542
|
+
}
|
|
2394
2543
|
}
|
|
2395
2544
|
}
|
|
2396
2545
|
}
|
|
2546
|
+
return (handler ?? _handleText)(response);
|
|
2547
|
+
} catch (error) {
|
|
2548
|
+
console.error("Unable to process response.", error, response);
|
|
2549
|
+
return Promise.reject(this.#handleError(url, { cause: error }));
|
|
2397
2550
|
}
|
|
2398
|
-
return (handler ?? _handleText)(response);
|
|
2399
|
-
} catch (error) {
|
|
2400
|
-
console.error("Unable to process response.", error, response);
|
|
2401
|
-
return Promise.reject(__privateMethod(this, _handleError, handleError_fn).call(this, url, { cause: error }));
|
|
2402
2551
|
}
|
|
2403
|
-
|
|
2404
|
-
|
|
2405
|
-
|
|
2406
|
-
|
|
2407
|
-
|
|
2552
|
+
/**
|
|
2553
|
+
* It takes a URL, a path, and a set of search parameters, and returns a new URL with the path and
|
|
2554
|
+
* search parameters applied.
|
|
2555
|
+
*
|
|
2556
|
+
* @private
|
|
2557
|
+
* @static
|
|
2558
|
+
* @param {URL} url The URL to use as a base.
|
|
2559
|
+
* @param {string} [path] The path to the resource. This can be a relative path or a full URL.
|
|
2560
|
+
* @param {Object<string, string>} [searchParams={}] An object containing the query parameters to be added to the URL.
|
|
2561
|
+
* @returns {URL} A new URL object with the pathname and origin of the url parameter, and the path parameter
|
|
2562
|
+
* appended to the end of the pathname.
|
|
2563
|
+
*/
|
|
2564
|
+
static #createUrl(url, path, searchParams = {}) {
|
|
2565
|
+
let _url;
|
|
2566
|
+
if (path) {
|
|
2567
|
+
_url = path.startsWith("/") ? new URL(`${url.pathname.replace(endsWithSlashRegEx, "")}${path}`, url.origin) : new URL(path);
|
|
2568
|
+
} else {
|
|
2569
|
+
_url = new URL(url);
|
|
2570
|
+
}
|
|
2571
|
+
Object.entries(searchParams).forEach(([key, value]) => _url.searchParams.append(key, value));
|
|
2572
|
+
return _url;
|
|
2408
2573
|
}
|
|
2409
|
-
|
|
2410
|
-
|
|
2411
|
-
|
|
2412
|
-
|
|
2413
|
-
|
|
2414
|
-
|
|
2415
|
-
|
|
2416
|
-
|
|
2417
|
-
|
|
2418
|
-
|
|
2419
|
-
|
|
2420
|
-
|
|
2421
|
-
|
|
2574
|
+
/**
|
|
2575
|
+
* If the request method is POST, PUT, or PATCH, and the content type is JSON, then the request body
|
|
2576
|
+
* needs to be serialized.
|
|
2577
|
+
*
|
|
2578
|
+
* @private
|
|
2579
|
+
* @static
|
|
2580
|
+
* @param {RequestMethod} method The HTTP request method.
|
|
2581
|
+
* @param {HttpMediaType} contentType The headers of the request.
|
|
2582
|
+
* @returns {boolean} `true` if the request body needs to be serialized, `false` otherwise.
|
|
2583
|
+
*/
|
|
2584
|
+
static #needsSerialization(method, contentType) {
|
|
2585
|
+
return (_mediaTypes.get(contentType) ?? new MediaType(contentType)).essence == http_media_type_default.JSON && [http_request_methods_default.POST, http_request_methods_default.PUT, http_request_methods_default.PATCH].includes(method);
|
|
2586
|
+
}
|
|
2587
|
+
/**
|
|
2588
|
+
*
|
|
2589
|
+
* @param {RequestOptions} options The options passed to the public function to use for the request.
|
|
2590
|
+
* @returns {RequestOptions} The options to use for the request.
|
|
2591
|
+
*/
|
|
2592
|
+
static #convertRequestOptions(options) {
|
|
2593
|
+
if (!object_is_empty_default(options)) {
|
|
2594
|
+
for (const [{ property, type, converter }, option = options[property]] of _Transportr.#propertyTypeConverters) {
|
|
2595
|
+
if (option instanceof type) {
|
|
2596
|
+
options[property] = converter(option);
|
|
2597
|
+
}
|
|
2422
2598
|
}
|
|
2423
2599
|
}
|
|
2600
|
+
return options;
|
|
2601
|
+
}
|
|
2602
|
+
/**
|
|
2603
|
+
* A String value that is used in the creation of the default string
|
|
2604
|
+
* description of an object. Called by the built-in method {@link Object.prototype.toString}.
|
|
2605
|
+
*
|
|
2606
|
+
* @returns {string} The default string description of this object.
|
|
2607
|
+
*/
|
|
2608
|
+
get [Symbol.toStringTag]() {
|
|
2609
|
+
return "Transportr";
|
|
2424
2610
|
}
|
|
2425
|
-
return options;
|
|
2426
2611
|
};
|
|
2427
|
-
/**
|
|
2428
|
-
* Generates a ResponseStatus object based on the error name and the response.
|
|
2429
|
-
*
|
|
2430
|
-
* @private
|
|
2431
|
-
* @static
|
|
2432
|
-
* @param {string} errorName The name of the error.
|
|
2433
|
-
* @param {Response} response The response object returned by the fetch API.
|
|
2434
|
-
* @returns {ResponseStatus} The response status object.
|
|
2435
|
-
*/
|
|
2436
|
-
__privateAdd(Transportr, _generateResponseStatusFromError);
|
|
2437
|
-
/**
|
|
2438
|
-
* It takes a URL, a path, and a set of search parameters, and returns a new URL with the path and
|
|
2439
|
-
* search parameters applied.
|
|
2440
|
-
*
|
|
2441
|
-
* @private
|
|
2442
|
-
* @static
|
|
2443
|
-
* @param {URL} url - The URL to use as a base.
|
|
2444
|
-
* @param {string} path - The path to the resource. This can be a relative path or a full URL.
|
|
2445
|
-
* @param {Object<string, string>} [searchParams={}] - An object containing the query parameters to be added to the URL.
|
|
2446
|
-
* @returns {URL} A new URL object with the pathname and origin of the url parameter, and the path parameter
|
|
2447
|
-
* appended to the end of the pathname.
|
|
2448
|
-
*/
|
|
2449
|
-
__privateAdd(Transportr, _createUrl);
|
|
2450
|
-
/**
|
|
2451
|
-
* If the request method is POST, PUT, or PATCH, and the content type is JSON, then the request body
|
|
2452
|
-
* needs to be serialized.
|
|
2453
|
-
*
|
|
2454
|
-
* @private
|
|
2455
|
-
* @static
|
|
2456
|
-
* @param {RequestMethod} method - The HTTP request method.
|
|
2457
|
-
* @param {HttpMediaType} contentType - The headers of the request.
|
|
2458
|
-
* @returns {boolean} `true` if the request body needs to be serialized, `false` otherwise.
|
|
2459
|
-
*/
|
|
2460
|
-
__privateAdd(Transportr, _needsSerialization);
|
|
2461
|
-
/**
|
|
2462
|
-
*
|
|
2463
|
-
* @param {RequestOptions} options - The options passed to the public function to use for the request.
|
|
2464
|
-
* @returns {RequestOptions} The options to use for the request.
|
|
2465
|
-
*/
|
|
2466
|
-
__privateAdd(Transportr, _convertRequestOptions);
|
|
2467
|
-
/** @type {Subscribr} */
|
|
2468
|
-
__privateAdd(Transportr, _globalSubscribr, new Subscribr());
|
|
2469
|
-
/** @type {Array<SignalController>} */
|
|
2470
|
-
__privateAdd(Transportr, _activeRequests, []);
|
|
2471
|
-
/**
|
|
2472
|
-
* @private
|
|
2473
|
-
* @static
|
|
2474
|
-
* @type {SetMultiMap<ResponseHandler<ResponseBody>, string>}
|
|
2475
|
-
*/
|
|
2476
|
-
__privateAdd(Transportr, _contentTypeHandlers, new SetMultiMap([
|
|
2477
|
-
[_handleImage, _mediaTypes.get(http_media_type_default.PNG).type],
|
|
2478
|
-
[_handleText, _mediaTypes.get(http_media_type_default.TEXT).type],
|
|
2479
|
-
[_handleJson, _mediaTypes.get(http_media_type_default.JSON).subtype],
|
|
2480
|
-
[_handleHtml, _mediaTypes.get(http_media_type_default.HTML).subtype],
|
|
2481
|
-
[_handleScript, _mediaTypes.get(http_media_type_default.JAVA_SCRIPT).subtype],
|
|
2482
|
-
[_handleCss, _mediaTypes.get(http_media_type_default.CSS).subtype],
|
|
2483
|
-
[_handleXml, _mediaTypes.get(http_media_type_default.XML).subtype],
|
|
2484
|
-
[_handleReadableStream, _mediaTypes.get(http_media_type_default.BIN).subtype]
|
|
2485
|
-
]));
|
|
2486
|
-
/**
|
|
2487
|
-
* @private
|
|
2488
|
-
* @static
|
|
2489
|
-
* @type {Set<PropertyTypeConverter>}
|
|
2490
|
-
*/
|
|
2491
|
-
__privateAdd(Transportr, _propertyTypeConverters, /* @__PURE__ */ new Set([
|
|
2492
|
-
[{ property: "body", type: FormData, converter: _typeConverter }],
|
|
2493
|
-
[{ property: "searchParams", type: URLSearchParams, converter: _typeConverter }],
|
|
2494
|
-
[{ property: "headers", type: Headers, converter: Object.fromEntries }]
|
|
2495
|
-
]));
|
|
2496
|
-
/**
|
|
2497
|
-
* @static
|
|
2498
|
-
* @constant {Object<string, HttpRequestMethod>}
|
|
2499
|
-
*/
|
|
2500
|
-
__publicField(Transportr, "Method", Object.freeze(http_request_methods_default));
|
|
2501
|
-
/**
|
|
2502
|
-
* @static
|
|
2503
|
-
* @constant {Object<string, HttpMediaType>}
|
|
2504
|
-
*/
|
|
2505
|
-
__publicField(Transportr, "MediaType", Object.freeze(http_media_type_default));
|
|
2506
|
-
/**
|
|
2507
|
-
* @static
|
|
2508
|
-
* @see {@link HttpRequestHeader}
|
|
2509
|
-
* @constant {Object<string, HttpRequestHeader>}
|
|
2510
|
-
*/
|
|
2511
|
-
__publicField(Transportr, "RequestHeader", Object.freeze(http_request_headers_default));
|
|
2512
|
-
/**
|
|
2513
|
-
* @static
|
|
2514
|
-
* @constant {Object<string, HttpResponseHeader>}
|
|
2515
|
-
*/
|
|
2516
|
-
__publicField(Transportr, "ResponseHeader", Object.freeze(http_response_headers_default));
|
|
2517
|
-
/**
|
|
2518
|
-
* @static
|
|
2519
|
-
* @constant {Object<string, RequestCache>}
|
|
2520
|
-
*/
|
|
2521
|
-
__publicField(Transportr, "CachingPolicy", Object.freeze({
|
|
2522
|
-
DEFAULT: "default",
|
|
2523
|
-
FORCE_CACHE: "force-cache",
|
|
2524
|
-
NO_CACHE: "no-cache",
|
|
2525
|
-
NO_STORE: "no-store",
|
|
2526
|
-
ONLY_IF_CACHED: "only-if-cached",
|
|
2527
|
-
RELOAD: "reload"
|
|
2528
|
-
}));
|
|
2529
|
-
/**
|
|
2530
|
-
* @static
|
|
2531
|
-
* @constant {Object<string, RequestCredentials>}
|
|
2532
|
-
*/
|
|
2533
|
-
__publicField(Transportr, "CredentialsPolicy", Object.freeze({
|
|
2534
|
-
INCLUDE: "include",
|
|
2535
|
-
OMIT: "omit",
|
|
2536
|
-
SAME_ORIGIN: "same-origin"
|
|
2537
|
-
}));
|
|
2538
|
-
/**
|
|
2539
|
-
* @static
|
|
2540
|
-
* @constant {Object<string, RequestMode>}
|
|
2541
|
-
*/
|
|
2542
|
-
__publicField(Transportr, "RequestMode", Object.freeze({
|
|
2543
|
-
CORS: "cors",
|
|
2544
|
-
NAVIGATE: "navigate",
|
|
2545
|
-
NO_CORS: "no-cors",
|
|
2546
|
-
SAME_ORIGIN: "same-origin"
|
|
2547
|
-
}));
|
|
2548
|
-
/**
|
|
2549
|
-
* @static
|
|
2550
|
-
* @constant {Object<string, RequestRedirect>}
|
|
2551
|
-
*/
|
|
2552
|
-
__publicField(Transportr, "RedirectPolicy", Object.freeze({
|
|
2553
|
-
ERROR: "error",
|
|
2554
|
-
FOLLOW: "follow",
|
|
2555
|
-
MANUAL: "manual"
|
|
2556
|
-
}));
|
|
2557
|
-
/**
|
|
2558
|
-
* @static
|
|
2559
|
-
* @constant {Object<string, ReferrerPolicy>}
|
|
2560
|
-
*/
|
|
2561
|
-
__publicField(Transportr, "ReferrerPolicy", Object.freeze({
|
|
2562
|
-
NO_REFERRER: "no-referrer",
|
|
2563
|
-
NO_REFERRER_WHEN_DOWNGRADE: "no-referrer-when-downgrade",
|
|
2564
|
-
ORIGIN: "origin",
|
|
2565
|
-
ORIGIN_WHEN_CROSS_ORIGIN: "origin-when-cross-origin",
|
|
2566
|
-
SAME_ORIGIN: "same-origin",
|
|
2567
|
-
STRICT_ORIGIN: "strict-origin",
|
|
2568
|
-
STRICT_ORIGIN_WHEN_CROSS_ORIGIN: "strict-origin-when-cross-origin",
|
|
2569
|
-
UNSAFE_URL: "unsafe-url"
|
|
2570
|
-
}));
|
|
2571
|
-
/**
|
|
2572
|
-
* @static
|
|
2573
|
-
* @constant {Object<string, TransportrEvent>}
|
|
2574
|
-
*/
|
|
2575
|
-
__publicField(Transportr, "Events", Object.freeze({
|
|
2576
|
-
CONFIGURED: "configured",
|
|
2577
|
-
SUCCESS: "success",
|
|
2578
|
-
ERROR: "error",
|
|
2579
|
-
ABORTED: "aborted",
|
|
2580
|
-
TIMEOUT: "timeout",
|
|
2581
|
-
COMPLETE: "complete",
|
|
2582
|
-
ALL_COMPLETE: "all-complete"
|
|
2583
|
-
}));
|
|
2584
|
-
/**
|
|
2585
|
-
* @private
|
|
2586
|
-
* @static
|
|
2587
|
-
* @type {RequestOptions}
|
|
2588
|
-
*/
|
|
2589
|
-
__privateAdd(Transportr, _defaultRequestOptions, Object.freeze({
|
|
2590
|
-
body: null,
|
|
2591
|
-
cache: _Transportr.CachingPolicy.NO_STORE,
|
|
2592
|
-
credentials: _Transportr.CredentialsPolicy.SAME_ORIGIN,
|
|
2593
|
-
headers: { [http_request_headers_default.CONTENT_TYPE]: _mediaTypes.get(http_media_type_default.JSON).toString(), [http_request_headers_default.ACCEPT]: _mediaTypes.get(http_media_type_default.JSON).toString() },
|
|
2594
|
-
searchParams: {},
|
|
2595
|
-
integrity: void 0,
|
|
2596
|
-
keepalive: void 0,
|
|
2597
|
-
method: http_request_methods_default.GET,
|
|
2598
|
-
mode: _Transportr.RequestMode.CORS,
|
|
2599
|
-
redirect: _Transportr.RedirectPolicy.FOLLOW,
|
|
2600
|
-
referrer: "about:client",
|
|
2601
|
-
referrerPolicy: _Transportr.ReferrerPolicy.STRICT_ORIGIN_WHEN_CROSS_ORIGIN,
|
|
2602
|
-
signal: void 0,
|
|
2603
|
-
timeout: 1e4,
|
|
2604
|
-
global: true,
|
|
2605
|
-
window: null
|
|
2606
|
-
}));
|
|
2607
|
-
/**
|
|
2608
|
-
* @private
|
|
2609
|
-
* @static
|
|
2610
|
-
* @type {Map<TransportrEvent, ResponseStatus>}
|
|
2611
|
-
*/
|
|
2612
|
-
__privateAdd(Transportr, _eventResponseStatuses, /* @__PURE__ */ new Map([
|
|
2613
|
-
[_Transportr.Events.ABORTED, new ResponseStatus(499, "Aborted")],
|
|
2614
|
-
[_Transportr.Events.TIMEOUT, new ResponseStatus(504, "Gateway Timeout")]
|
|
2615
|
-
]));
|
|
2616
2612
|
return __toCommonJS(transportr_exports);
|
|
2617
2613
|
})();
|
|
2618
2614
|
window.Transportr = Transportr.default;
|