@d1g1tal/transportr 3.3.4 → 4.0.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/CHANGELOG.md +46 -0
- package/README.md +2 -2
- package/dist/FPFIT6Y7.js +9 -0
- package/dist/FPFIT6Y7.js.map +7 -0
- package/dist/iife/content-type.js +1 -3
- package/dist/iife/content-type.js.map +1 -1
- package/dist/iife/request-header.js +1 -3
- package/dist/iife/request-header.js.map +1 -1
- package/dist/iife/request-method.js +1 -3
- package/dist/iife/request-method.js.map +1 -1
- package/dist/iife/response-header.js +1 -3
- package/dist/iife/response-header.js.map +1 -1
- package/dist/iife/transportr.js +10 -1283
- package/dist/iife/transportr.js.map +4 -4
- package/dist/transportr.d.ts +61 -155
- package/dist/transportr.js +6 -6
- package/dist/transportr.js.map +4 -4
- package/package.json +23 -22
- package/dist/VSS64DLN.js +0 -8
- package/dist/VSS64DLN.js.map +0 -7
package/dist/transportr.d.ts
CHANGED
|
@@ -7,8 +7,7 @@ import { MediaType } from "@d1g1tal/media-type";
|
|
|
7
7
|
* @author D1g1talEntr0py <jason.dimeo@gmail.com>
|
|
8
8
|
*/
|
|
9
9
|
declare class ResponseStatus {
|
|
10
|
-
private
|
|
11
|
-
private readonly _text;
|
|
10
|
+
#private;
|
|
12
11
|
/**
|
|
13
12
|
*
|
|
14
13
|
* @param code The status code from the {@link Response}
|
|
@@ -122,11 +121,7 @@ type HttpErrorOptions = {
|
|
|
122
121
|
* @author D1g1talEntr0py <jason.dimeo@gmail.com>
|
|
123
122
|
*/
|
|
124
123
|
declare class HttpError extends Error {
|
|
125
|
-
private
|
|
126
|
-
private readonly responseStatus;
|
|
127
|
-
private readonly _url;
|
|
128
|
-
private readonly _method;
|
|
129
|
-
private readonly _timing;
|
|
124
|
+
#private;
|
|
130
125
|
/**
|
|
131
126
|
* Creates an instance of HttpError.
|
|
132
127
|
* @param status The status code and status text of the {@link Response}.
|
|
@@ -655,7 +650,7 @@ type RequestOptions = Prettify<{
|
|
|
655
650
|
unwrap?: boolean;
|
|
656
651
|
/** When true, script tags in HTML fragment responses are preserved by DOMPurify instead of stripped. Defaults to false. Only applies to getHtmlFragment(). */
|
|
657
652
|
allowScripts?: boolean;
|
|
658
|
-
} & Omit<RequestInit, 'headers'> & MethodBody>;
|
|
653
|
+
} & Omit<RequestInit, 'headers' | 'body' | 'method'> & MethodBody>;
|
|
659
654
|
/** Configuration for retry behavior on failed requests. */
|
|
660
655
|
type RetryOptions = {
|
|
661
656
|
/** Maximum number of retry attempts. Defaults to 0 (no retries). */
|
|
@@ -718,11 +713,19 @@ declare const endsWithSlashRegEx: RegExp;
|
|
|
718
713
|
declare const XSRF_COOKIE_NAME = "XSRF-TOKEN";
|
|
719
714
|
/** Default XSRF header name */
|
|
720
715
|
declare const XSRF_HEADER_NAME = "X-XSRF-TOKEN";
|
|
721
|
-
type MediaTypeKey = 'PNG' | 'TEXT' | 'JSON' | 'HTML' | 'JAVA_SCRIPT' | 'CSS' | 'XML' | 'BIN' | 'EVENT_STREAM' | 'NDJSON';
|
|
722
716
|
declare const mediaTypes: {
|
|
723
|
-
|
|
717
|
+
readonly PNG: "image/png";
|
|
718
|
+
readonly TEXT: "text/plain";
|
|
719
|
+
readonly JSON: "application/json";
|
|
720
|
+
readonly HTML: "text/html";
|
|
721
|
+
readonly JAVA_SCRIPT: "text/javascript";
|
|
722
|
+
readonly CSS: "text/css";
|
|
723
|
+
readonly XML: "application/xml";
|
|
724
|
+
readonly BIN: "application/octet-stream";
|
|
725
|
+
readonly EVENT_STREAM: "text/event-stream";
|
|
726
|
+
readonly NDJSON: "application/x-ndjson";
|
|
724
727
|
};
|
|
725
|
-
declare const defaultMediaType:
|
|
728
|
+
declare const defaultMediaType: MediaType;
|
|
726
729
|
declare const defaultOrigin: string;
|
|
727
730
|
/** Constant object for caching policies */
|
|
728
731
|
declare const RequestCachingPolicy: {
|
|
@@ -789,20 +792,7 @@ type RequestEvent = (typeof RequestEvent)[keyof typeof RequestEvent];
|
|
|
789
792
|
* @author D1g1talEntr0py <jason.dimeo@gmail.com>
|
|
790
793
|
*/
|
|
791
794
|
declare class Transportr {
|
|
792
|
-
private
|
|
793
|
-
private readonly _options;
|
|
794
|
-
private readonly subscribr;
|
|
795
|
-
private readonly hooks;
|
|
796
|
-
private static globalSubscribr;
|
|
797
|
-
private static globalHooks;
|
|
798
|
-
private static signalControllers;
|
|
799
|
-
/** Map of in-flight deduplicated requests keyed by URL + method */
|
|
800
|
-
private static inflightRequests;
|
|
801
|
-
/** Cached config for the common "no retry" case (retry === undefined) */
|
|
802
|
-
private static readonly noRetryConfig;
|
|
803
|
-
/** Cache for parsed MediaType instances to avoid re-parsing the same content-type strings */
|
|
804
|
-
private static mediaTypeCache;
|
|
805
|
-
private static contentTypeHandlers;
|
|
795
|
+
#private;
|
|
806
796
|
/**
|
|
807
797
|
* Create a new Transportr instance with the provided location or origin and context path.
|
|
808
798
|
*
|
|
@@ -848,8 +838,6 @@ declare class Transportr {
|
|
|
848
838
|
};
|
|
849
839
|
/** Request Event */
|
|
850
840
|
static readonly RequestEvent: typeof RequestEvent;
|
|
851
|
-
/** Default Request Options */
|
|
852
|
-
private static readonly defaultRequestOptions;
|
|
853
841
|
/**
|
|
854
842
|
* Returns a {@link EventRegistration} used for subscribing to global events with typed data.
|
|
855
843
|
*
|
|
@@ -985,6 +973,8 @@ declare class Transportr {
|
|
|
985
973
|
get<T extends ResponseBody = ResponseBody>(path: RequestOptions & {
|
|
986
974
|
unwrap: false;
|
|
987
975
|
}): Promise<Result<T | undefined>>;
|
|
976
|
+
/** Throws on failure and resolves to the response body (default behavior). */
|
|
977
|
+
get<T extends ResponseBody = ResponseBody>(path?: string | RequestOptions, options?: RequestOptions): Promise<T | undefined>;
|
|
988
978
|
/** Returns a Result tuple instead of throwing. */
|
|
989
979
|
post<T extends ResponseBody = ResponseBody>(path: string | undefined, body: RequestBody, options: RequestOptions & {
|
|
990
980
|
unwrap: false;
|
|
@@ -993,6 +983,10 @@ declare class Transportr {
|
|
|
993
983
|
post<T extends ResponseBody = ResponseBody>(body: RequestBody, options: RequestOptions & {
|
|
994
984
|
unwrap: false;
|
|
995
985
|
}): Promise<Result<T | undefined>>;
|
|
986
|
+
/** Throws on failure and resolves to the response body (default behavior). */
|
|
987
|
+
post<T extends ResponseBody = ResponseBody>(path: string | undefined, body?: RequestBody, options?: RequestOptions): Promise<T | undefined>;
|
|
988
|
+
/** Throws on failure and resolves to the response body (default behavior). */
|
|
989
|
+
post<T extends ResponseBody = ResponseBody>(body: RequestBody, options?: RequestOptions): Promise<T | undefined>;
|
|
996
990
|
/** Returns a Result tuple instead of throwing. */
|
|
997
991
|
put<T extends ResponseBody = ResponseBody>(path: string | undefined, body: RequestBody, options: RequestOptions & {
|
|
998
992
|
unwrap: false;
|
|
@@ -1001,6 +995,10 @@ declare class Transportr {
|
|
|
1001
995
|
put<T extends ResponseBody = ResponseBody>(body: RequestBody, options: RequestOptions & {
|
|
1002
996
|
unwrap: false;
|
|
1003
997
|
}): Promise<Result<T | undefined>>;
|
|
998
|
+
/** Throws on failure and resolves to the response body (default behavior). */
|
|
999
|
+
put<T extends ResponseBody = ResponseBody>(path: string | undefined, body?: RequestBody, options?: RequestOptions): Promise<T | undefined>;
|
|
1000
|
+
/** Throws on failure and resolves to the response body (default behavior). */
|
|
1001
|
+
put<T extends ResponseBody = ResponseBody>(body: RequestBody, options?: RequestOptions): Promise<T | undefined>;
|
|
1004
1002
|
/** Returns a Result tuple instead of throwing. */
|
|
1005
1003
|
patch<T extends ResponseBody = ResponseBody>(path: string | undefined, body: RequestBody, options: RequestOptions & {
|
|
1006
1004
|
unwrap: false;
|
|
@@ -1009,6 +1007,10 @@ declare class Transportr {
|
|
|
1009
1007
|
patch<T extends ResponseBody = ResponseBody>(body: RequestBody, options: RequestOptions & {
|
|
1010
1008
|
unwrap: false;
|
|
1011
1009
|
}): Promise<Result<T | undefined>>;
|
|
1010
|
+
/** Throws on failure and resolves to the response body (default behavior). */
|
|
1011
|
+
patch<T extends ResponseBody = ResponseBody>(path: string | undefined, body?: RequestBody, options?: RequestOptions): Promise<T | undefined>;
|
|
1012
|
+
/** Throws on failure and resolves to the response body (default behavior). */
|
|
1013
|
+
patch<T extends ResponseBody = ResponseBody>(body: RequestBody, options?: RequestOptions): Promise<T | undefined>;
|
|
1012
1014
|
/** Returns a Result tuple instead of throwing. */
|
|
1013
1015
|
delete<T extends ResponseBody = ResponseBody>(path: string | undefined, body: RequestBody, options: RequestOptions & {
|
|
1014
1016
|
unwrap: false;
|
|
@@ -1017,6 +1019,8 @@ declare class Transportr {
|
|
|
1017
1019
|
delete<T extends ResponseBody = ResponseBody>(body: RequestBody, options: RequestOptions & {
|
|
1018
1020
|
unwrap: false;
|
|
1019
1021
|
}): Promise<Result<T | undefined>>;
|
|
1022
|
+
/** Throws on failure and resolves to the response body (default behavior). */
|
|
1023
|
+
delete<T extends ResponseBody = ResponseBody>(path?: string | RequestBody, body?: RequestBody | RequestOptions, options?: RequestOptions): Promise<T | undefined>;
|
|
1020
1024
|
/** Returns a Result tuple instead of throwing. */
|
|
1021
1025
|
head<T extends ResponseBody = ResponseBody>(path: string | undefined, options: RequestOptions & {
|
|
1022
1026
|
unwrap: false;
|
|
@@ -1025,6 +1029,8 @@ declare class Transportr {
|
|
|
1025
1029
|
head<T extends ResponseBody = ResponseBody>(path: RequestOptions & {
|
|
1026
1030
|
unwrap: false;
|
|
1027
1031
|
}): Promise<Result<T | undefined>>;
|
|
1032
|
+
/** Throws on failure and resolves to the response body (default behavior). */
|
|
1033
|
+
head<T extends ResponseBody = ResponseBody>(path?: string | RequestOptions, options?: RequestOptions): Promise<T | undefined>;
|
|
1028
1034
|
/** Returns a Result tuple instead of throwing. */
|
|
1029
1035
|
options(path: string | undefined, options: RequestOptions & {
|
|
1030
1036
|
unwrap: false;
|
|
@@ -1033,6 +1039,8 @@ declare class Transportr {
|
|
|
1033
1039
|
options(path: RequestOptions & {
|
|
1034
1040
|
unwrap: false;
|
|
1035
1041
|
}): Promise<Result<string[] | undefined>>;
|
|
1042
|
+
/** Throws on failure and resolves to allowed methods (default behavior). */
|
|
1043
|
+
options(path?: string | RequestOptions, options?: RequestOptions): Promise<string[] | undefined>;
|
|
1036
1044
|
/** Returns a Result tuple instead of throwing. */
|
|
1037
1045
|
request<T = unknown>(path: string | undefined, options: RequestOptions & {
|
|
1038
1046
|
unwrap: false;
|
|
@@ -1041,6 +1049,8 @@ declare class Transportr {
|
|
|
1041
1049
|
request<T = unknown>(path: RequestOptions & {
|
|
1042
1050
|
unwrap: false;
|
|
1043
1051
|
}): Promise<Result<TypedResponse<T>>>;
|
|
1052
|
+
/** Throws on failure and resolves to the typed response (default behavior). */
|
|
1053
|
+
request<T = unknown>(path?: string | RequestOptions, options?: RequestOptions): Promise<TypedResponse<T>>;
|
|
1044
1054
|
/** Returns a Result tuple instead of throwing. */
|
|
1045
1055
|
getJson(path: string | undefined, options: RequestOptions & {
|
|
1046
1056
|
unwrap: false;
|
|
@@ -1049,6 +1059,8 @@ declare class Transportr {
|
|
|
1049
1059
|
getJson(path: RequestOptions & {
|
|
1050
1060
|
unwrap: false;
|
|
1051
1061
|
}): Promise<Result<Json | undefined>>;
|
|
1062
|
+
/** Throws on failure and resolves to JSON content (default behavior). */
|
|
1063
|
+
getJson(path?: string | RequestOptions, options?: RequestOptions): Promise<Json | undefined>;
|
|
1052
1064
|
/** Returns a Result tuple instead of throwing. */
|
|
1053
1065
|
getXml(path: string | undefined, options: RequestOptions & {
|
|
1054
1066
|
unwrap: false;
|
|
@@ -1057,6 +1069,8 @@ declare class Transportr {
|
|
|
1057
1069
|
getXml(path: RequestOptions & {
|
|
1058
1070
|
unwrap: false;
|
|
1059
1071
|
}): Promise<Result<Document | undefined>>;
|
|
1072
|
+
/** Throws on failure and resolves to XML content (default behavior). */
|
|
1073
|
+
getXml(path?: string | RequestOptions, options?: RequestOptions): Promise<Document | undefined>;
|
|
1060
1074
|
/** Returns a Result tuple instead of throwing. */
|
|
1061
1075
|
getHtml(path: string | undefined, options: RequestOptions & {
|
|
1062
1076
|
unwrap: false;
|
|
@@ -1065,6 +1079,8 @@ declare class Transportr {
|
|
|
1065
1079
|
getHtml(path: RequestOptions & {
|
|
1066
1080
|
unwrap: false;
|
|
1067
1081
|
}): Promise<Result<Document | Element | null | undefined>>;
|
|
1082
|
+
/** Throws on failure and resolves to parsed HTML (default behavior). */
|
|
1083
|
+
getHtml(path?: string | RequestOptions, options?: RequestOptions, selector?: string): Promise<Document | Element | null | undefined>;
|
|
1068
1084
|
/** Returns a Result tuple instead of throwing. */
|
|
1069
1085
|
getHtmlFragment(path: string | undefined, options: RequestOptions & {
|
|
1070
1086
|
unwrap: false;
|
|
@@ -1073,6 +1089,8 @@ declare class Transportr {
|
|
|
1073
1089
|
getHtmlFragment(path: RequestOptions & {
|
|
1074
1090
|
unwrap: false;
|
|
1075
1091
|
}): Promise<Result<DocumentFragment | Element | null | undefined>>;
|
|
1092
|
+
/** Throws on failure and resolves to parsed HTML fragment (default behavior). */
|
|
1093
|
+
getHtmlFragment(path?: string | RequestOptions, options?: RequestOptions, selector?: string): Promise<DocumentFragment | Element | null | undefined>;
|
|
1076
1094
|
/** Returns a Result tuple instead of throwing. */
|
|
1077
1095
|
getScript(path: string | undefined, options: RequestOptions & {
|
|
1078
1096
|
unwrap: false;
|
|
@@ -1081,6 +1099,8 @@ declare class Transportr {
|
|
|
1081
1099
|
getScript(path: RequestOptions & {
|
|
1082
1100
|
unwrap: false;
|
|
1083
1101
|
}): Promise<Result<void>>;
|
|
1102
|
+
/** Throws on failure and resolves when the script is loaded (default behavior). */
|
|
1103
|
+
getScript(path?: string | RequestOptions, options?: RequestOptions): Promise<void>;
|
|
1084
1104
|
/** Returns a Result tuple instead of throwing. */
|
|
1085
1105
|
getStylesheet(path: string | undefined, options: RequestOptions & {
|
|
1086
1106
|
unwrap: false;
|
|
@@ -1089,6 +1109,8 @@ declare class Transportr {
|
|
|
1089
1109
|
getStylesheet(path: RequestOptions & {
|
|
1090
1110
|
unwrap: false;
|
|
1091
1111
|
}): Promise<Result<void>>;
|
|
1112
|
+
/** Throws on failure and resolves when the stylesheet is loaded (default behavior). */
|
|
1113
|
+
getStylesheet(path?: string | RequestOptions, options?: RequestOptions): Promise<void>;
|
|
1092
1114
|
/** Returns a Result tuple instead of throwing. */
|
|
1093
1115
|
getBlob(path: string | undefined, options: RequestOptions & {
|
|
1094
1116
|
unwrap: false;
|
|
@@ -1097,10 +1119,14 @@ declare class Transportr {
|
|
|
1097
1119
|
getBlob(path: RequestOptions & {
|
|
1098
1120
|
unwrap: false;
|
|
1099
1121
|
}): Promise<Result<Blob | undefined>>;
|
|
1122
|
+
/** Throws on failure and resolves to Blob data (default behavior). */
|
|
1123
|
+
getBlob(path?: string | RequestOptions, options?: RequestOptions): Promise<Blob | undefined>;
|
|
1100
1124
|
/** Returns a Result tuple instead of throwing. */
|
|
1101
1125
|
getImage(path: string | undefined, options: RequestOptions & {
|
|
1102
1126
|
unwrap: false;
|
|
1103
1127
|
}): Promise<Result<HTMLImageElement | undefined>>;
|
|
1128
|
+
/** Throws on failure and resolves to an image element (default behavior). */
|
|
1129
|
+
getImage(path?: string | RequestOptions, options?: RequestOptions): Promise<HTMLImageElement | undefined>;
|
|
1104
1130
|
/** Returns a Result tuple instead of throwing. */
|
|
1105
1131
|
getBuffer(path: string | undefined, options: RequestOptions & {
|
|
1106
1132
|
unwrap: false;
|
|
@@ -1109,6 +1135,8 @@ declare class Transportr {
|
|
|
1109
1135
|
getBuffer(path: RequestOptions & {
|
|
1110
1136
|
unwrap: false;
|
|
1111
1137
|
}): Promise<Result<ArrayBuffer | undefined>>;
|
|
1138
|
+
/** Throws on failure and resolves to ArrayBuffer data (default behavior). */
|
|
1139
|
+
getBuffer(path?: string | RequestOptions, options?: RequestOptions): Promise<ArrayBuffer | undefined>;
|
|
1112
1140
|
/** Returns a Result tuple instead of throwing. */
|
|
1113
1141
|
getStream(path: string | undefined, options: RequestOptions & {
|
|
1114
1142
|
unwrap: false;
|
|
@@ -1117,6 +1145,8 @@ declare class Transportr {
|
|
|
1117
1145
|
getStream(path: RequestOptions & {
|
|
1118
1146
|
unwrap: false;
|
|
1119
1147
|
}): Promise<Result<ReadableStream<Uint8Array> | null | undefined>>;
|
|
1148
|
+
/** Throws on failure and resolves to a readable stream (default behavior). */
|
|
1149
|
+
getStream(path?: string | RequestOptions, options?: RequestOptions): Promise<ReadableStream<Uint8Array> | null | undefined>;
|
|
1120
1150
|
/** Returns a Result tuple instead of throwing. */
|
|
1121
1151
|
getEventStream(path: string | undefined, options: RequestOptions & {
|
|
1122
1152
|
unwrap: false;
|
|
@@ -1125,6 +1155,8 @@ declare class Transportr {
|
|
|
1125
1155
|
getEventStream(path: RequestOptions & {
|
|
1126
1156
|
unwrap: false;
|
|
1127
1157
|
}): Promise<Result<AsyncIterable<ServerSentEvent>>>;
|
|
1158
|
+
/** Throws on failure and resolves to an SSE async iterable (default behavior). */
|
|
1159
|
+
getEventStream(path?: string | RequestOptions, options?: RequestOptions): Promise<AsyncIterable<ServerSentEvent>>;
|
|
1128
1160
|
/** Returns a Result tuple instead of throwing. */
|
|
1129
1161
|
getJsonStream<T = Json>(path: string | undefined, options: RequestOptions & {
|
|
1130
1162
|
unwrap: false;
|
|
@@ -1133,134 +1165,8 @@ declare class Transportr {
|
|
|
1133
1165
|
getJsonStream<T = Json>(path: RequestOptions & {
|
|
1134
1166
|
unwrap: false;
|
|
1135
1167
|
}): Promise<Result<AsyncIterable<T>>>;
|
|
1136
|
-
/**
|
|
1137
|
-
|
|
1138
|
-
* @async
|
|
1139
|
-
* @param path The path to the resource.
|
|
1140
|
-
* @param userOptions The user options for the request.
|
|
1141
|
-
* @param options The options for the request.
|
|
1142
|
-
* @param responseHandler The response handler for the request.
|
|
1143
|
-
* @returns A promise that resolves to the response body or void.
|
|
1144
|
-
*/
|
|
1145
|
-
private _get;
|
|
1146
|
-
/**
|
|
1147
|
-
* It processes the request options and returns a new object with the processed options.
|
|
1148
|
-
* @param path The path to the resource.
|
|
1149
|
-
* @param processedRequestOptions The user options for the request.
|
|
1150
|
-
* @returns A new object with the processed options.
|
|
1151
|
-
*/
|
|
1152
|
-
private _request;
|
|
1153
|
-
/**
|
|
1154
|
-
* Normalizes a retry option into a full RetryOptions object.
|
|
1155
|
-
* @param retry The retry option from request options.
|
|
1156
|
-
* @returns Normalized retry configuration.
|
|
1157
|
-
*/
|
|
1158
|
-
private static normalizeRetryOptions;
|
|
1159
|
-
/**
|
|
1160
|
-
* Waits for the appropriate delay before a retry attempt.
|
|
1161
|
-
* @param config The retry configuration.
|
|
1162
|
-
* @param attempt The current attempt number (1-based).
|
|
1163
|
-
* @returns A promise that resolves after the delay.
|
|
1164
|
-
*/
|
|
1165
|
-
private static retryDelay;
|
|
1166
|
-
/**
|
|
1167
|
-
* Shared implementation for body-accepting HTTP methods (POST, PUT, PATCH, DELETE).
|
|
1168
|
-
* @param method The HTTP method to use.
|
|
1169
|
-
* @param path The request path, or the request body when called without a path.
|
|
1170
|
-
* @param body The request body, or options when called without a path.
|
|
1171
|
-
* @param options Additional request options.
|
|
1172
|
-
* @param responseHandler Optional response handler override.
|
|
1173
|
-
* @returns A promise that resolves to the response body.
|
|
1174
|
-
*/
|
|
1175
|
-
private executeBodyMethod;
|
|
1176
|
-
/**
|
|
1177
|
-
* It returns a response handler based on the content type of the response.
|
|
1178
|
-
* @param path The path to the resource.
|
|
1179
|
-
* @param userOptions The user options for the request.
|
|
1180
|
-
* @param options The options for the request.
|
|
1181
|
-
* @param responseHandler The response handler for the request.
|
|
1182
|
-
* @returns A response handler function.
|
|
1183
|
-
*/
|
|
1184
|
-
private execute;
|
|
1185
|
-
/**
|
|
1186
|
-
* Creates a new set of options for a request.
|
|
1187
|
-
* @param options The user options for the request.
|
|
1188
|
-
* @param userOptions The default options for the request.
|
|
1189
|
-
* @returns A new set of options for the request.
|
|
1190
|
-
*/
|
|
1191
|
-
private static createOptions;
|
|
1192
|
-
/**
|
|
1193
|
-
* Merges user and request headers into the target Headers object.
|
|
1194
|
-
* @param target The target Headers object.
|
|
1195
|
-
* @param headerSources Variable number of header sources to merge.
|
|
1196
|
-
* @returns The merged Headers object.
|
|
1197
|
-
*/
|
|
1198
|
-
private static mergeHeaders;
|
|
1199
|
-
/**
|
|
1200
|
-
* Merges user and request search parameters into the target URLSearchParams object.
|
|
1201
|
-
* @param target The target URLSearchParams object.
|
|
1202
|
-
* @param sources The search parameters to merge.
|
|
1203
|
-
* @returns The merged URLSearchParams object.
|
|
1204
|
-
*/
|
|
1205
|
-
private static mergeSearchParams;
|
|
1206
|
-
/**
|
|
1207
|
-
* Processes request options by merging user, instance, and method-specific options.
|
|
1208
|
-
* This method optimizes performance by using cached instance options and performing
|
|
1209
|
-
* shallow merges where possible instead of deep object cloning.
|
|
1210
|
-
* @param userOptions The user-provided options for the request.
|
|
1211
|
-
* @param options Additional method-specific options.
|
|
1212
|
-
* @returns Processed request options with signal controller and global flag.
|
|
1213
|
-
*/
|
|
1214
|
-
private processRequestOptions;
|
|
1215
|
-
/**
|
|
1216
|
-
* Gets the base URL from a URL or string.
|
|
1217
|
-
* @param url The URL or string to parse.
|
|
1218
|
-
* @returns The base URL.
|
|
1219
|
-
*/
|
|
1220
|
-
private static getBaseUrl;
|
|
1221
|
-
/**
|
|
1222
|
-
* Parses a content-type string into a MediaType instance with caching.
|
|
1223
|
-
* This method caches parsed MediaType instances to avoid re-parsing the same content-type strings,
|
|
1224
|
-
* which significantly improves performance for repeated requests with the same content types.
|
|
1225
|
-
* @param contentType The content-type string to parse.
|
|
1226
|
-
* @returns The parsed MediaType instance, or undefined if parsing fails.
|
|
1227
|
-
*/
|
|
1228
|
-
private static getOrParseMediaType;
|
|
1229
|
-
/**
|
|
1230
|
-
* Creates a new URL with the given path and search parameters.
|
|
1231
|
-
* @param url The base URL.
|
|
1232
|
-
* @param path The path to append to the base URL.
|
|
1233
|
-
* @param searchParams The search parameters to append to the URL.
|
|
1234
|
-
* @returns A new URL with the given path and search parameters.
|
|
1235
|
-
*/
|
|
1236
|
-
private static createUrl;
|
|
1237
|
-
/**
|
|
1238
|
-
* It generates a ResponseStatus object from an error name and a Response object.
|
|
1239
|
-
* @param errorName The name of the error.
|
|
1240
|
-
* @param response The Response object.
|
|
1241
|
-
* @returns A ResponseStatus object.
|
|
1242
|
-
*/
|
|
1243
|
-
private static generateResponseStatusFromError;
|
|
1244
|
-
/**
|
|
1245
|
-
* Handles an error that occurs during a request.
|
|
1246
|
-
* @param path The path of the request.
|
|
1247
|
-
* @param response The Response object.
|
|
1248
|
-
* @param options Additional error context including cause, entity, url, method, and timing.
|
|
1249
|
-
* @param requestOptions The original request options that led to the error, used for hooks context.
|
|
1250
|
-
* @returns An HttpError object.
|
|
1251
|
-
*/
|
|
1252
|
-
private handleError;
|
|
1253
|
-
/**
|
|
1254
|
-
* Publishes an event to the global and instance event handlers.
|
|
1255
|
-
* @param eventObject The event object to publish.
|
|
1256
|
-
*/
|
|
1257
|
-
private publish;
|
|
1258
|
-
/**
|
|
1259
|
-
* It returns a response handler based on the content type of the response.
|
|
1260
|
-
* @param contentType The content type of the response.
|
|
1261
|
-
* @returns A response handler function.
|
|
1262
|
-
*/
|
|
1263
|
-
private getResponseHandler;
|
|
1168
|
+
/** Throws on failure and resolves to an NDJSON async iterable (default behavior). */
|
|
1169
|
+
getJsonStream<T = Json>(path?: string | RequestOptions, options?: RequestOptions): Promise<AsyncIterable<T>>;
|
|
1264
1170
|
/**
|
|
1265
1171
|
* A string representation of the Transportr instance.
|
|
1266
1172
|
* @returns The string 'Transportr'.
|
package/dist/transportr.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
var
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
`),id:t,retry:
|
|
1
|
+
var I=/^[-!#$%&'*+.^_`|~A-Za-z0-9]*$/u,xe=/(["\\])/ug,ke=/^[\t\u0020-\u007E\u0080-\u00FF]*$/u,L=n=>{for(let e=0,t=n.length;e<t;e++){let s=n.charCodeAt(e);if(s>=65&&s<=90)return n.toLowerCase()}return n},oe=class ie extends Map{constructor(e=[]){super(e)}static isValid(e,t){return I.test(e)&&ke.test(t)}get(e){return super.get(L(e))}has(e){return super.has(L(e))}set(e,t){if(!ie.isValid(e,t))throw new Error(`Invalid media type parameter name/value: ${e}/${t}`);return super.set(L(e),t),this}delete(e){return super.delete(L(e))}toString(){let e="";for(let[t,s]of this)e+=";",e+=t,e+="=",s.length===0||!I.test(s)?(e+='"',e+=s.replace(xe,"\\$1"),e+='"'):e+=s;return e}get[Symbol.toStringTag](){return"MediaTypeParameters"}},v=n=>n===32||n===9||n===10||n===13,Le=Map.prototype.set,Ie=Map.prototype.has,Me=class b{constructor(){}static parse(e){let t=0,s=e.length;for(;t<s&&v(e.charCodeAt(t));)t++;for(;s>t&&v(e.charCodeAt(s-1));)s--;(t!==0||s!==e.length)&&(e=e.slice(t,s));let r=e.length,o=0;for(;o<r&&e.charCodeAt(o)!==47;)o++;if(o===0||o>=r)throw new TypeError(b.#s("type",e.slice(0,o)));let i=e.slice(0,o);if(!I.test(i))throw new TypeError(b.#s("type",i));i=i.toLowerCase(),o++;let a=o;for(;o<r&&e.charCodeAt(o)!==59;)o++;let d=o;for(;d>a&&v(e.charCodeAt(d-1));)d--;if(d===a)throw new TypeError(b.#s("subtype",""));let u=e.slice(a,d);if(!I.test(u))throw new TypeError(b.#s("subtype",u));u=u.toLowerCase();let l=new oe;for(;o<r;){for(o++;o<r&&v(e.charCodeAt(o));)o++;let c=o;for(;o<r;){let p=e.charCodeAt(o);if(p===59||p===61)break;o++}let f=c===o?"":e.slice(c,o);if(o>=r||e.charCodeAt(o)===59)continue;o++;let R;if(o<r&&e.charCodeAt(o)===34){o=b.#t(e,o,r),R=b.#e;let p=e.indexOf(";",o);o=p===-1?r:p}else{let p=o;for(;o<r&&e.charCodeAt(o)!==59;)o++;let y=o;for(;y>p&&v(e.charCodeAt(y-1));)y--;if(y===p)continue;R=e.slice(p,y)}if(f.length!==0&&oe.isValid(f,R)){let p=f.toLowerCase();Ie.call(l,p)||Le.call(l,p,R)}}return{type:i,subtype:u,parameters:l}}static#e="";static#t(e,t,s){t++;let r=t;for(;t<s;){let i=e.charCodeAt(t);if(i===34||i===92)break;t++}if(t>=s)return b.#e=e.slice(r,t),t;if(e.charCodeAt(t)===34)return b.#e=e.slice(r,t),t+1;let o=e.slice(r,t);for(;t<s;){let i=e.charCodeAt(t);if(i===34){t++;break}i===92&&t+1<s&&t++,o+=e[t],t++}return b.#e=o,t}static#s(e,t){return`Invalid ${e} "${t}": only HTTP token code points are valid.`}},M=class ae{#e;#t;#s;#n;constructor(e,t){if({type:this.#e,subtype:this.#t,parameters:this.#n}=Me.parse(e),this.#s=this.#e+"/"+this.#t,t!==void 0){if(t===null||typeof t!="object"||Array.isArray(t))throw new TypeError("The parameters argument must be an object");for(let s in t)Object.prototype.hasOwnProperty.call(t,s)&&this.#n.set(s,t[s])}}static parse(e){try{return new ae(e)}catch{}return null}get type(){return this.#e}get subtype(){return this.#t}get essence(){return this.#s}get parameters(){return this.#n}matches(e){return typeof e=="string"?this.#s===e:this.#e===e.#e&&this.#t===e.#t}toString(){return this.#s+this.#n.toString()}get[Symbol.toStringTag](){return"MediaType"}};var Ue=class extends Map{set(n,e){return super.set(n,e instanceof Set?e:(super.get(n)??new Set).add(e)),this}getOrInsert(n,e){return this.has(n)?super.get(n):(super.set(n,e instanceof Set?e:(super.get(n)??new Set).add(e)),e)}getOrInsertComputed(n,e){if(this.has(n))return super.get(n);let t=e(n);return super.set(n,t instanceof Set?t:(super.get(n)??new Set).add(t)),t}find(n,e){let t=this.get(n);if(t!==void 0)return Array.from(t).find(e)}hasValue(n,e){let t=super.get(n);return t?t.has(e):!1}deleteValue(n,e){if(e===void 0)return this.delete(n);let t=super.get(n);if(t){let s=t.delete(e);return t.size===0&&super.delete(n),s}return!1}get[Symbol.toStringTag](){return"SetMultiMap"}},Ne=class{#e;#t;constructor(n,e){this.#e=n,this.#t=e}handle(n,e){this.#t.call(this.#e,n,e)}get[Symbol.toStringTag](){return"ContextEventHandler"}},De=class{#e;#t;constructor(n,e){this.#e=n,this.#t=e}get eventName(){return this.#e}get contextEventHandler(){return this.#t}get[Symbol.toStringTag](){return"Subscription"}},U=class{#e=new Ue;#t;setErrorHandler(n){this.#t=n}subscribe(n,e,t=e,s){if(this.#s(n),s?.once){let i=e;e=(a,d)=>{i.call(t,a,d),this.unsubscribe(o)}}let r=new Ne(t,e);this.#e.set(n,r);let o=new De(n,r);return o}unsubscribe({eventName:n,contextEventHandler:e}){let t=this.#e.get(n);if(!t)return!1;let s=t.delete(e);return s&&t.size===0&&this.#e.delete(n),s}publish(n,e=new CustomEvent(n),t){this.#s(n),this.#e.get(n)?.forEach(s=>{try{s.handle(e,t)}catch(r){this.#t?this.#t(r,n,e,t):console.error(`Error in event handler for '${n}':`,r)}})}isSubscribed({eventName:n,contextEventHandler:e}){return this.#e.get(n)?.has(e)??!1}#s(n){if(!n||typeof n!="string")throw new TypeError("Event name must be a non-empty string");if(n.trim()!==n)throw new Error("Event name cannot have leading or trailing whitespace")}destroy(){this.#e.clear()}get[Symbol.toStringTag](){return"Subscribr"}};var O=class extends Error{#e;#t;#s;#n;#o;constructor(e,{message:t,cause:s,entity:r,url:o,method:i,timing:a}={}){super(t,{cause:s}),this.#e=r,this.#t=e,this.#s=o,this.#n=i,this.#o=a}get entity(){return this.#e}get statusCode(){return this.#t.code}get statusText(){return this.#t?.text}get url(){return this.#s}get method(){return this.#n}get timing(){return this.#o}get name(){return"HttpError"}get[Symbol.toStringTag](){return this.name}};var E=class{#e;#t;constructor(e,t){this.#e=e,this.#t=t}get code(){return this.#e}get text(){return this.#t}get[Symbol.toStringTag](){return"ResponseStatus"}toString(){return`${this.#e} ${this.#t}`}};var ue="XSRF-TOKEN",de="X-XSRF-TOKEN",h={PNG:"image/png",TEXT:"text/plain",JSON:"application/json",HTML:"text/html",JAVA_SCRIPT:"text/javascript",CSS:"text/css",XML:"application/xml",BIN:"application/octet-stream",EVENT_STREAM:"text/event-stream",NDJSON:"application/x-ndjson"},Fe={charset:"utf-8"},A=new M(h.JSON,Fe),W=globalThis.location?.origin??"http://localhost",le={DEFAULT:"default",FORCE_CACHE:"force-cache",NO_CACHE:"no-cache",NO_STORE:"no-store",ONLY_IF_CACHED:"only-if-cached",RELOAD:"reload"},m={CONFIGURED:"configured",SUCCESS:"success",ERROR:"error",ABORTED:"aborted",TIMEOUT:"timeout",RETRY:"retry",COMPLETE:"complete",ALL_COMPLETE:"all-complete"},q={ABORT:"abort",TIMEOUT:"timeout"},w={ABORT:"AbortError",TIMEOUT:"TimeoutError"},B={once:!0,passive:!0},N=()=>new CustomEvent(q.ABORT,{detail:{cause:w.ABORT}}),ce=()=>new CustomEvent(q.TIMEOUT,{detail:{cause:w.TIMEOUT}}),pe=["POST","PUT","PATCH","DELETE"],fe=new E(500,"Internal Server Error"),Re=new E(499,"Aborted"),he=new E(504,"Request Timeout"),K=[408,413,429,500,502,503,504],Y=["GET","PUT","HEAD","DELETE","OPTIONS"],D=300,F=2;var j=class{#e;#t=new AbortController;#s;#n;constructor({signal:e,timeout:t=1/0}={}){if(t<0)throw new RangeError("The timeout cannot be negative");let s=e!=null,r=t!==1/0;if(!s&&!r){this.#e=this.#t.signal,this.#n=!1;return}let o=[this.#t.signal];s&&o.push(e),r&&o.push(AbortSignal.timeout(t)),this.#e=AbortSignal.any(o),this.#n=!0,r&&this.#e.addEventListener(q.ABORT,this,B)}handleEvent({target:{reason:e}}){this.#t.signal.aborted||e instanceof DOMException&&e.name===w.TIMEOUT&&this.#e.dispatchEvent(ce())}get signal(){return this.#e}onAbort(e){return this.#o(q.ABORT,e)}onTimeout(e){return this.#o(q.TIMEOUT,e)}abort(e=N()){this.#t.abort(e.detail?.cause)}destroy(){this.#n&&this.#e.removeEventListener(q.ABORT,this,B);let e=this.#s;if(e!==void 0){for(let[t,s]of e)this.#e.removeEventListener(s,t,B);e.clear()}return this}#o(e,t){return this.#e.addEventListener(e,t,B),(this.#s??=new Map).set(t,e),this}get[Symbol.toStringTag](){return"SignalController"}};var J,$,G=()=>J||(J=(typeof document>"u"||typeof DOMParser>"u"||typeof DocumentFragment>"u"?import("jsdom").then(({JSDOM:e})=>{let{window:t}=new e("<!DOCTYPE html><html><head></head><body></body></html>",{url:"http://localhost"});globalThis.window=t,Object.assign(globalThis,{document:t.document,DOMParser:t.DOMParser,DocumentFragment:t.DocumentFragment})}).catch(()=>{throw J=void 0,new Error("jsdom is required for HTML/XML/DOM features in Node.js environments. Install it with: npm install jsdom")}):Promise.resolve()).then(()=>import("./FPFIT6Y7.js")).then(({default:e})=>{$=e})),ge=async(n,e)=>(await G(),new DOMParser().parseFromString($.sanitize(await n.text()),e)),Z=async(n,e)=>{await G();let t=URL.createObjectURL(await n.blob());try{return new Promise((s,r)=>e(t,s,r))}finally{URL.revokeObjectURL(t)}},me=n=>n.text(),Q=n=>Z(n,(e,t,s)=>{let r=Object.assign(document.createElement("script"),{src:e,type:"text/javascript",async:!0});r.onload=()=>{document.head.removeChild(r),t()},r.onerror=()=>{document.head.removeChild(r),s(new Error("Script failed to load"))},document.head.appendChild(r)}),_=n=>Z(n,(e,t,s)=>{let r=Object.assign(document.createElement("link"),{href:e,type:"text/css",rel:"stylesheet"});r.onload=()=>t(),r.onerror=()=>{document.head.removeChild(r),s(new Error("Stylesheet load failed"))},document.head.appendChild(r)}),H=n=>n.json(),ye=n=>n.blob(),ee=n=>Z(n,(e,t,s)=>{let r=new Image;r.onload=()=>t(r),r.onerror=()=>s(new Error("Image failed to load")),r.src=e}),be=n=>n.arrayBuffer(),te=n=>Promise.resolve(n.body),C=async n=>ge(n,"application/xml"),ne=async n=>ge(n,"text/html"),Te=async n=>(await G(),document.createRange().createContextualFragment($.sanitize(await n.text()))),Oe=async n=>(await G(),document.createRange().createContextualFragment($.sanitize(await n.text(),{ADD_TAGS:["script"]})));async function*Ee(n,e,t){let s=n.getReader(),r=new TextDecoder,o=e.length,i="",a=0;try{for(;;){let d;for(;(d=i.indexOf(e,a))!==-1;)yield i.slice(a,d),a=d+o;a>0&&a>=i.length-a&&(i=a<i.length?i.slice(a):"",a=0);let{done:u,value:l}=await s.read();if(u)break;i+=r.decode(l,{stream:!0})}if(t){let u=((a<i.length?i.slice(a):"")+r.decode()).trim();u&&(yield u)}}finally{await s.cancel()}}var je=n=>{let e="message",t="",s,r,o,i=n.split(`
|
|
2
|
+
`);for(let d=0,u,l=i.length;d<l;d++){if(u=i[d],u.charCodeAt(0)===58)continue;let c=u.indexOf(":"),f,R;switch(c===-1?(f=u,R=""):(f=u.slice(0,c),R=u.charCodeAt(c+1)===32?u.slice(c+2):u.slice(c+1)),f){case"event":{e=R;break}case"data":{r===void 0?r=R:(o??=[]).push(R);break}case"id":{t=R;break}case"retry":{let p=parseInt(R,10);isNaN(p)||(s=p);break}}}if(r===void 0&&e==="message")return;let a=o===void 0?r??"":`${r}
|
|
3
|
+
${o.join(`
|
|
4
|
+
`)}`;return{event:e,data:a,id:t,retry:s}},qe=n=>({async*[Symbol.asyncIterator](){for await(let e of Ee(n.body,`
|
|
5
5
|
|
|
6
|
-
`,!1)){if(!e)continue;let t
|
|
7
|
-
`,!0)){let t=e.trim();t&&(yield JSON.parse(t))}}});var He=s=>s!==void 0&&he.includes(s),Ae=s=>s instanceof FormData||s instanceof Blob||s instanceof ArrayBuffer||s instanceof ReadableStream||s instanceof URLSearchParams||ArrayBuffer.isView(s),Be=s=>{if(typeof document>"u"||!document.cookie)return;let e=`${s}=`,t=document.cookie.split(";");for(let n=0,r=t.length;n<r;n++){let o=t[n].trim();if(o.startsWith(e))return decodeURIComponent(o.slice(e.length))}},Ce=s=>JSON.stringify(s),J=s=>s!==null&&typeof s=="string",ke=s=>s instanceof ArrayBuffer||Object.prototype.toString.call(s)==="[object ArrayBuffer]",y=s=>s!==null&&typeof s=="object"&&!Array.isArray(s)&&Object.getPrototypeOf(s)===Object.prototype,$=(...s)=>{let e=s.length;if(e===0)return;if(e===1){let[n]=s;return y(n)?re(n):n}let t={};for(let n of s){if(!y(n))return;for(let[r,o]of Object.entries(n)){let i=t[r];Array.isArray(o)?t[r]=[...o,...Array.isArray(i)?i.filter(a=>!o.includes(a)):[]]:y(o)?t[r]=y(i)?$(i,o):re(o):t[r]=o}}return t};function re(s){if(y(s)){let e={},t=Object.keys(s);for(let n=0,r=t.length,o;n<r;n++)o=t[n],e[o]=re(s[o]);return e}return s}var xe=class s{_baseUrl;_options;subscribr;hooks={beforeRequest:[],afterResponse:[],beforeError:[]};static globalSubscribr=new I;static globalHooks={beforeRequest:[],afterResponse:[],beforeError:[]};static signalControllers=new Set;static inflightRequests=new Map;static noRetryConfig={limit:0,statusCodes:[],methods:[],delay:N,backoffFactor:D};static mediaTypeCache=new Map(Object.values(m).map(e=>[e.toString(),e]));static contentTypeHandlers=[[m.TEXT.type,Te],[m.JSON.subtype,Z],[m.BIN.subtype,te],[m.HTML.subtype,ne],[m.XML.subtype,se],[m.PNG.type,ee],[m.JAVA_SCRIPT.subtype,Y],[m.CSS.subtype,Q]];constructor(e=X,t={}){y(e)&&([e,t]=[X,e]),this._baseUrl=s.getBaseUrl(e),this._options=s.createOptions(t,s.defaultRequestOptions),this.subscribr=new I}static CredentialsPolicy={INCLUDE:"include",OMIT:"omit",SAME_ORIGIN:"same-origin"};static RequestMode={CORS:"cors",NAVIGATE:"navigate",NO_CORS:"no-cors",SAME_ORIGIN:"same-origin"};static RequestPriority={HIGH:"high",LOW:"low",AUTO:"auto"};static RedirectPolicy={ERROR:"error",FOLLOW:"follow",MANUAL:"manual"};static ReferrerPolicy={NO_REFERRER:"no-referrer",NO_REFERRER_WHEN_DOWNGRADE:"no-referrer-when-downgrade",ORIGIN:"origin",ORIGIN_WHEN_CROSS_ORIGIN:"origin-when-cross-origin",SAME_ORIGIN:"same-origin",STRICT_ORIGIN:"strict-origin",STRICT_ORIGIN_WHEN_CROSS_ORIGIN:"strict-origin-when-cross-origin",UNSAFE_URL:"unsafe-url"};static RequestEvent=b;static defaultRequestOptions={body:void 0,cache:fe.NO_STORE,credentials:s.CredentialsPolicy.SAME_ORIGIN,headers:new Headers({"content-type":G,accept:G}),searchParams:void 0,integrity:void 0,keepalive:void 0,method:"GET",mode:s.RequestMode.CORS,priority:s.RequestPriority.AUTO,redirect:s.RedirectPolicy.FOLLOW,referrer:"about:client",referrerPolicy:s.ReferrerPolicy.STRICT_ORIGIN_WHEN_CROSS_ORIGIN,signal:void 0,timeout:3e4,global:!0};static register(e,t,n){return s.globalSubscribr.subscribe(e,t,n)}static unregister(e){return s.globalSubscribr.unsubscribe(e)}static abortAll(){for(let e of this.signalControllers)e.abort(L());this.signalControllers.clear()}static all(e){return Promise.all(e)}static async race(e){let t=[],n=new Array(e.length);for(let r=0;r<e.length;r++){let o=new AbortController;t.push(o),n[r]=e[r](o.signal)}try{return await Promise.race(n)}finally{for(let r of t)r.abort()}}static registerContentTypeHandler(e,t){s.contentTypeHandlers.unshift([e,t])}static unregisterContentTypeHandler(e){let t=s.contentTypeHandlers.findIndex(([n])=>n===e);return t===-1?!1:(s.contentTypeHandlers.splice(t,1),!0)}static addHooks(e){e.beforeRequest&&s.globalHooks.beforeRequest.push(...e.beforeRequest),e.afterResponse&&s.globalHooks.afterResponse.push(...e.afterResponse),e.beforeError&&s.globalHooks.beforeError.push(...e.beforeError)}static clearHooks(){s.globalHooks={beforeRequest:[],afterResponse:[],beforeError:[]}}static unregisterAll(){s.abortAll(),s.globalSubscribr=new I,s.clearHooks(),s.inflightRequests.clear()}get baseUrl(){return this._baseUrl}register(e,t,n){return this.subscribr.subscribe(e,t,n)}unregister(e){return this.subscribr.unsubscribe(e)}addHooks(e){return e.beforeRequest&&this.hooks.beforeRequest.push(...e.beforeRequest),e.afterResponse&&this.hooks.afterResponse.push(...e.afterResponse),e.beforeError&&this.hooks.beforeError.push(...e.beforeError),this}clearHooks(){return this.hooks.beforeRequest.length=0,this.hooks.afterResponse.length=0,this.hooks.beforeError.length=0,this}configure({headers:e,searchParams:t,hooks:n,...r}){return e&&s.mergeHeaders(this._options.headers,e),t&&s.mergeSearchParams(this._options.searchParams,t),Object.keys(r).length>0&&Object.assign(this._options,r),n&&this.addHooks(n),this}destroy(){this.clearHooks(),this.subscribr.destroy()}async get(e,t){return this._get(e,t)}async post(e,t,n){return this.executeBodyMethod("POST",e,t,n)}async put(e,t,n){return this.executeBodyMethod("PUT",e,t,n)}async patch(e,t,n){return this.executeBodyMethod("PATCH",e,t,n)}async delete(e,t,n){return this.executeBodyMethod("DELETE",e,t,n)}async head(e,t){return this.execute(e,t,{method:"HEAD"})}async options(e,t={}){y(e)&&([e,t]=[void 0,e]);let n=this.processRequestOptions(t,{method:"OPTIONS"}),{requestOptions:r}=n,o=r.unwrap!==!1,i=r.hooks;try{let a=s.createUrl(this._baseUrl,e,r.searchParams),u=[s.globalHooks.beforeRequest,this.hooks.beforeRequest,i?.beforeRequest];for(let c of u)if(c)for(let l of c){let g=await l(r,a);g&&(Object.assign(r,g),g.searchParams!==void 0&&(a=s.createUrl(this._baseUrl,e,r.searchParams)))}let p=await this._request(e,n),R=[s.globalHooks.afterResponse,this.hooks.afterResponse,i?.afterResponse];for(let c of R)if(c)for(let l of c){let g=await l(p,r);g&&(p=g)}let d=p.headers.get("allow"),h;if(d){let c=d.split(",");h=new Array(c.length);for(let l=0,g=c.length;l<g;l++)h[l]=c[l].trim()}return this.publish({name:b.SUCCESS,data:h,global:t.global}),o?h:[!0,h]}catch(a){if(!o)return[!1,a];throw a}}async request(e,t={}){y(e)&&([e,t]=[void 0,e]);let n=this.processRequestOptions(t,{}),r=n.requestOptions.unwrap!==!1;try{let o=await this._request(e,n);return this.publish({name:b.SUCCESS,data:o,global:t.global}),r?o:[!0,o]}catch(o){if(!r)return[!1,o];throw o}}async getJson(e,t){return this._get(e,t,{headers:{accept:`${m.JSON}`}},Z)}async getXml(e,t){return this._get(e,t,{headers:{accept:`${m.XML}`}},se)}async getHtml(e,t,n){let r=await this._get(e,t,{headers:{accept:`${m.HTML}`}},ne);return Array.isArray(r)?r:n&&r?r.querySelector(n):r}async getHtmlFragment(e,t,n){let r=(y(e)?e:t)?.allowScripts===!0,o=await this._get(e,t,{headers:{accept:`${m.HTML}`}},r?we:Oe);return Array.isArray(o)?o:n&&o?o.querySelector(n):o}async getScript(e,t){return this._get(e,t,{headers:{accept:`${m.JAVA_SCRIPT}`}},Y)}async getStylesheet(e,t){return this._get(e,t,{headers:{accept:`${m.CSS}`}},Q)}async getBlob(e,t){return this._get(e,t,{headers:{accept:"application/octet-stream"}},Ee)}async getImage(e,t){return this._get(e,t,{headers:{accept:"image/*"}},ee)}async getBuffer(e,t){return this._get(e,t,{headers:{accept:"application/octet-stream"}},Se)}async getStream(e,t){return this._get(e,t,{headers:{accept:"application/octet-stream"}},te)}async getEventStream(e,t){y(e)&&([e,t]=[void 0,e]);let n=this.processRequestOptions(t??{},{method:t?.body?"POST":"GET",headers:{accept:`${m.EVENT_STREAM}`}}),{requestOptions:r}=n,o=r.unwrap!==!1,i=r.hooks;try{let a=s.createUrl(this._baseUrl,e,r.searchParams),u=[s.globalHooks.beforeRequest,this.hooks.beforeRequest,i?.beforeRequest];for(let c of u)if(c)for(let l of c){let g=await l(r,a);g&&(Object.assign(r,g),g.searchParams!==void 0&&(a=s.createUrl(this._baseUrl,e,r.searchParams)))}let R=await this._request(e,n),d=[s.globalHooks.afterResponse,this.hooks.afterResponse,i?.afterResponse];for(let c of d)if(c)for(let l of c){let g=await l(R,r);g&&(R=g)}this.publish({name:b.SUCCESS,data:R,global:n.global});let h=qe(R);return o?h:[!0,h]}catch(a){if(!o)return[!1,a];throw a}}async getJsonStream(e,t){y(e)&&([e,t]=[void 0,e]);let n=this.processRequestOptions(t??{},{method:"GET",headers:{accept:`${m.NDJSON}`}}),{requestOptions:r}=n,o=r.unwrap!==!1,i=r.hooks;try{let a=s.createUrl(this._baseUrl,e,r.searchParams),u=[s.globalHooks.beforeRequest,this.hooks.beforeRequest,i?.beforeRequest];for(let c of u)if(c)for(let l of c){let g=await l(r,a);g&&(Object.assign(r,g),g.searchParams!==void 0&&(a=s.createUrl(this._baseUrl,e,r.searchParams)))}let R=await this._request(e,n),d=[s.globalHooks.afterResponse,this.hooks.afterResponse,i?.afterResponse];for(let c of d)if(c)for(let l of c){let g=await l(R,r);g&&(R=g)}this.publish({name:b.SUCCESS,data:R,global:n.global});let h=Pe(R);return o?h:[!0,h]}catch(a){if(!o)return[!1,a];throw a}}async _get(e,t,n={},r){return n.method="GET",n.body=void 0,this.execute(e,t,n,r)}async _request(e,{signalController:t,requestOptions:n,global:r}){s.signalControllers.add(t);let o=s.normalizeRetryOptions(n.retry),i=n.method??"GET",a=o.limit>0&&o.methods.includes(i),u=n.dedupe===!0&&(i==="GET"||i==="HEAD"),p=0,R=performance.now(),d=()=>{let h=performance.now();return{start:R,end:h,duration:h-R}};try{let h=s.createUrl(this._baseUrl,e,n.searchParams),c;if(u){c=`${i}:${h.href}`;let f=s.inflightRequests.get(c);if(f)return(await f).clone()}let l=n.body,g=n.onUploadProgress,A=async()=>{if(!g||l==null)return;let f=null;if(typeof l=="string")f=new TextEncoder().encode(l);else if(l instanceof Blob)f=new Uint8Array(await l.arrayBuffer());else if(ke(l))f=new Uint8Array(l);else if(ArrayBuffer.isView(l))f=new Uint8Array(l.buffer,l.byteOffset,l.byteLength);else if(!(l instanceof ReadableStream))return;let E=f?f.byteLength:null,x=f?new ReadableStream({start(q){q.enqueue(f),q.close()}}):l,S=0,C=new TransformStream({transform(q,U){S+=q.byteLength,g({loaded:S,total:E,percentage:E!==null&&E>0?Math.round(S/E*100):null}),U.enqueue(q)}});n.body=x.pipeThrough(C),Object.assign(n,{duplex:"half"})},oe=async()=>{for(;;)try{await A();let f=await fetch(h,n);if(!f.ok){if(a&&p<o.limit&&o.statusCodes.includes(f.status)){p++,this.publish({name:b.RETRY,data:{attempt:p,status:f.status,method:i,path:e,timing:d()},global:r}),await s.retryDelay(o,p);continue}let E;try{E=await f.text()}catch{}throw await this.handleError(e,f,{entity:E,url:h,method:i,timing:d()},n)}return f}catch(f){if(f instanceof B)throw f;if(a&&p<o.limit){p++,this.publish({name:b.RETRY,data:{attempt:p,error:f.message,method:i,path:e,timing:d()},global:r}),await s.retryDelay(o,p);continue}throw await this.handleError(e,void 0,{cause:f,url:h,method:i,timing:d()},n)}},ie=f=>{let E=n.onDownloadProgress;if(!E||!f.body)return f;let x=f.headers.get("content-length"),S=x?parseInt(x,10):null,C=0,q=new TransformStream({transform(U,Ue){C+=U.byteLength,E({loaded:C,total:S,percentage:S!==null&&S>0?Math.round(C/S*100):null}),Ue.enqueue(U)}});return new Response(f.body.pipeThrough(q),{status:f.status,statusText:f.statusText,headers:f.headers})};if(u){let f=oe();s.inflightRequests.set(c,f);try{return ie(await f)}finally{s.inflightRequests.delete(c)}}return ie(await oe())}finally{s.signalControllers.delete(t.destroy()),n.signal?.aborted||(this.publish({name:b.COMPLETE,data:{timing:d()},global:r}),s.signalControllers.size===0&&this.publish({name:b.ALL_COMPLETE,global:r}))}}static normalizeRetryOptions(e){return e===void 0?s.noRetryConfig:typeof e=="number"?{limit:e,statusCodes:V,methods:z,delay:N,backoffFactor:D}:{limit:e.limit??0,statusCodes:e.statusCodes??V,methods:e.methods??z,delay:e.delay??N,backoffFactor:e.backoffFactor??D}}static retryDelay(e,t){let n=typeof e.delay=="function"?e.delay(t):e.delay*e.backoffFactor**(t-1);return new Promise(r=>setTimeout(r,n))}executeBodyMethod(e,t,n,r,o){let[i,a,u]=J(t)?[t,n,r]:[void 0,t,n];return this.execute(i,Object.assign(u??{},{body:a,method:e}),{},o)}async execute(e,t={},n={},r){y(e)&&([e,t]=[void 0,e]);let o=this.processRequestOptions(t,n),{requestOptions:i}=o,a=i.unwrap!==!1,u=i.hooks;try{let p=s.createUrl(this._baseUrl,e,i.searchParams);for(let d of[s.globalHooks.beforeRequest,this.hooks.beforeRequest,u?.beforeRequest])if(d)for(let h of d){let c=await h(i,p);c&&(Object.assign(i,c),c.searchParams!==void 0&&(p=s.createUrl(this._baseUrl,e,i.searchParams)))}let R=await this._request(e,o);for(let d of[s.globalHooks.afterResponse,this.hooks.afterResponse,u?.afterResponse])if(d)for(let h of d){let c=await h(R,i);c&&(R=c)}try{!r&&R.status!==204&&(r=this.getResponseHandler(R.headers.get("content-type")));let d=await r?.(R);return this.publish({name:b.SUCCESS,data:d,global:o.global}),a?d:[!0,d]}catch(d){throw await this.handleError(e,R,{cause:d},i)}}catch(p){if(!a)return[!1,p];throw p}}static createOptions({headers:e,searchParams:t,...n},{headers:r,searchParams:o,...i}){return r=s.mergeHeaders(new Headers,e,r),o=s.mergeSearchParams(new URLSearchParams,t,o),{...$(i,n),headers:r,searchParams:o}}static mergeHeaders(e,...t){for(let n of t)if(n!==void 0)if(n instanceof Headers)n.forEach((r,o)=>e.set(o,r));else if(Array.isArray(n))for(let[r,o]of n)e.set(r,o);else{let r=Object.keys(n);for(let o=0,i=r.length;o<i;o++){let a=r[o],u=n[a];u!==void 0&&e.set(a,u)}}return e}static mergeSearchParams(e,...t){for(let n of t)if(n!==void 0)if(n instanceof URLSearchParams)n.forEach((r,o)=>e.set(o,r));else if(J(n)||Array.isArray(n))for(let[r,o]of new URLSearchParams(n))e.set(r,o);else{let r=Object.keys(n);for(let o=0;o<r.length;o++){let i=r[o],a=n[i];a!==void 0&&e.set(i,typeof a=="string"?a:String(a))}}return e}processRequestOptions({body:e,headers:t,searchParams:n,...r},{headers:o,searchParams:i,...a}){let u={...this._options,...r,...a,headers:s.mergeHeaders(new Headers(this._options.headers),t,o),searchParams:s.mergeSearchParams(new URLSearchParams(this._options.searchParams),n,i)};if(He(u.method))if(Ae(e))Object.assign(u,{body:e}),u.headers.delete("content-type");else{let l=this._options.body,g=y(l)&&y(e)?$(l,e):e!==void 0?e:l,A=u.headers.get("content-type")?.includes("json")??!1;Object.assign(u,{body:A&&y(g)?Ce(g):g})}else u.headers.delete("content-type"),u.body instanceof URLSearchParams&&s.mergeSearchParams(u.searchParams,u.body),u.body=void 0;let{signal:p,timeout:R,global:d=!1,xsrf:h}=u;if(h){let{cookieName:l,headerName:g}=typeof h=="object"?h:{},A=Be(l??ce);A&&u.headers.set(g??pe,A)}let c=new _({signal:p,timeout:R}).onAbort(l=>this.publish({name:b.ABORTED,event:l,global:d})).onTimeout(l=>this.publish({name:b.TIMEOUT,event:l,global:d}));return u.signal=c.signal,this.publish({name:b.CONFIGURED,data:u,global:d}),{signalController:c,requestOptions:u,global:d}}static getBaseUrl(e){if(e instanceof URL)return e;if(!J(e))throw new TypeError("Invalid URL");return new URL(e,e.startsWith("/")?globalThis.location.origin:void 0)}static getOrParseMediaType(e){if(e===null)return;let t=s.mediaTypeCache.get(e);return t!==void 0||(t=T.parse(e)??void 0,t!==void 0&&(s.mediaTypeCache.size>=100&&s.mediaTypeCache.delete(s.mediaTypeCache.keys().next().value),s.mediaTypeCache.set(e,t))),t}static createUrl(e,t,n){let r=t?new URL(`${e.pathname.replace(de,"")}${t}`,e.origin):new URL(e);return n&&s.mergeSearchParams(r.searchParams,n),r}static generateResponseStatusFromError(e,{status:t,statusText:n}=new Response){switch(e){case H.ABORT:return me;case H.TIMEOUT:return ye;default:return t>=400?new w(t,n):ge}}async handleError(e,t,{cause:n,entity:r,url:o,method:i,timing:a}={},u){let p=i&&o?`${i} ${o.href} failed${t?` with status ${t.status}`:""}`:`An error has occurred with your request to: '${e}'`,R=new B(s.generateResponseStatusFromError(n?.name,t),{message:p,cause:n,entity:r,url:o,method:i,timing:a});for(let d of[s.globalHooks.beforeError,this.hooks.beforeError,u?.hooks?.beforeError])if(d)for(let h of d){let c=await h(R);c instanceof B&&(R=c)}return this.publish({name:b.ERROR,data:R}),R}publish({name:e,event:t=new CustomEvent(e),data:n,global:r=!0}){r&&s.globalSubscribr.publish(e,t,n),this.subscribr.publish(e,t,n)}getResponseHandler(e){if(!e)return;let t=s.getOrParseMediaType(e);if(t){for(let[n,r]of s.contentTypeHandlers)if(t.matches(n))return r}}get[Symbol.toStringTag](){return"Transportr"}};export{xe as Transportr};
|
|
6
|
+
`,!1)){if(!e)continue;let t=je(e);t&&(yield t)}}}),we=n=>({async*[Symbol.asyncIterator](){for await(let e of Ee(n.body,`
|
|
7
|
+
`,!0)){let t=e.trim();t&&(yield JSON.parse(t))}}});var Se=n=>n!==void 0&&pe.includes(n),Pe=n=>n instanceof FormData||n instanceof Blob||n instanceof ArrayBuffer||n instanceof ReadableStream||n instanceof URLSearchParams||ArrayBuffer.isView(n),ve=n=>{if(typeof document>"u")return;let e=document.cookie;if(!e)return;let t=`${n}=`,s=t.length,r=e.length,o=0;for(;o<r;){for(;o<r&&e.charCodeAt(o)===32;)o++;let i=e.indexOf(";",o);if(i===-1&&(i=r),i-o>=s&&e.startsWith(t,o))return decodeURIComponent(e.slice(o+s,i));o=i+1}},Ae=n=>JSON.stringify(n),z=n=>n!==null&&typeof n=="string",Be=n=>n instanceof ArrayBuffer||Object.prototype.toString.call(n)==="[object ArrayBuffer]",g=n=>n!==null&&typeof n=="object"&&!Array.isArray(n)&&Object.getPrototypeOf(n)===Object.prototype,X=(...n)=>{let e=n.length;if(e===0)return;if(e===1){let[s]=n;return g(s)?se(s):s}let t={};for(let s=0,r=n.length;s<r;s++){let o=n[s];if(!g(o))return;let i=Object.keys(o);for(let a=0,d=i.length;a<d;a++){let u=i[a],l=o[u],c=t[u];if(Array.isArray(l))if(Array.isArray(c)){let f=l.slice();for(let R=0,p=c.length;R<p;R++){let y=c[R];l.includes(y)||f.push(y)}t[u]=f}else t[u]=l.slice();else g(l)?t[u]=g(c)?X(c,l):se(l):t[u]=l}}return t};function se(n){if(g(n)){let e={},t=Object.keys(n);for(let s=0,r=t.length,o;s<r;s++)o=t[s],e[o]=se(n[o]);return e}return n}var He=class n{#e;#t;#s;#n;#o;#h;#a={beforeRequest:[],afterResponse:[],beforeError:[]};#f={beforeRequest:0,afterResponse:0,beforeError:0};#u=Object.create(null);static#O=new U;static#c={beforeRequest:[],afterResponse:[],beforeError:[]};static#R={beforeRequest:0,afterResponse:0,beforeError:0};static#p=Object.create(null);static#g=new Set;static#E=new Map;static#L={limit:0,statusCodes:[],methods:[],delay:D,backoffFactor:F};static#C=new WeakMap;static#m=new Map([[A.toString(),A]]);static#d=new Map;static#q=[[h.TEXT,me],[h.JSON,H],[h.BIN,te],[h.HTML,ne],[h.XML,C],[h.PNG,ee],[h.JAVA_SCRIPT,Q],[h.CSS,_]];constructor(e=W,t={}){g(e)&&([e,t]=[W,e]),this.#e=n.#j(e),this.#t=this.#e.origin;let s=this.#e.pathname;this.#s=s.length>0&&s.charCodeAt(s.length-1)===47?s.slice(0,-1):s,this.#n=n.#F(t,n.#I),this.#o=new Headers(this.#n.headers),this.#o.delete("content-type"),this.#h=new U}static CredentialsPolicy={INCLUDE:"include",OMIT:"omit",SAME_ORIGIN:"same-origin"};static RequestMode={CORS:"cors",NAVIGATE:"navigate",NO_CORS:"no-cors",SAME_ORIGIN:"same-origin"};static RequestPriority={HIGH:"high",LOW:"low",AUTO:"auto"};static RedirectPolicy={ERROR:"error",FOLLOW:"follow",MANUAL:"manual"};static ReferrerPolicy={NO_REFERRER:"no-referrer",NO_REFERRER_WHEN_DOWNGRADE:"no-referrer-when-downgrade",ORIGIN:"origin",ORIGIN_WHEN_CROSS_ORIGIN:"origin-when-cross-origin",SAME_ORIGIN:"same-origin",STRICT_ORIGIN:"strict-origin",STRICT_ORIGIN_WHEN_CROSS_ORIGIN:"strict-origin-when-cross-origin",UNSAFE_URL:"unsafe-url"};static RequestEvent=m;static#I={body:void 0,cache:le.NO_STORE,credentials:n.CredentialsPolicy.SAME_ORIGIN,headers:new Headers({"content-type":A.toString(),accept:A.toString()}),searchParams:void 0,integrity:void 0,keepalive:void 0,method:"GET",mode:n.RequestMode.CORS,priority:n.RequestPriority.AUTO,redirect:n.RedirectPolicy.FOLLOW,referrer:"about:client",referrerPolicy:n.ReferrerPolicy.STRICT_ORIGIN_WHEN_CROSS_ORIGIN,signal:void 0,timeout:3e4,global:!0};static register(e,t,s){let r=n.#O.subscribe(e,t,s);return n.#p[e]=(n.#p[e]??0)+1,r}static unregister(e){let t=n.#O.unsubscribe(e);if(t){let s=e.eventName,r=(n.#p[s]??1)-1;r<=0?delete n.#p[s]:n.#p[s]=r}return t}static abortAll(){for(let e of this.#g)e.abort(N());this.#g.clear()}static all(e){return Promise.all(e)}static async race(e){let t=[],s=new Array(e.length);for(let r=0;r<e.length;r++){let o=new AbortController;t.push(o),s[r]=e[r](o.signal)}try{return await Promise.race(s)}finally{for(let r of t)r.abort()}}static registerContentTypeHandler(e,t){n.#q.unshift([e,t]),n.#d.clear()}static unregisterContentTypeHandler(e){let t=n.#q.findIndex(([s])=>s===e);return t===-1?!1:(n.#q.splice(t,1),n.#d.clear(),!0)}static addHooks(e){let{beforeRequest:t,afterResponse:s,beforeError:r}=e;t&&(n.#c.beforeRequest.push(...t),n.#R.beforeRequest+=t.length),s&&(n.#c.afterResponse.push(...s),n.#R.afterResponse+=s.length),r&&(n.#c.beforeError.push(...r),n.#R.beforeError+=r.length)}static clearHooks(){n.#c={beforeRequest:[],afterResponse:[],beforeError:[]},n.#R.beforeRequest=0,n.#R.afterResponse=0,n.#R.beforeError=0}static unregisterAll(){n.abortAll(),n.#O=new U,n.#p=Object.create(null),n.clearHooks(),n.#E.clear()}get baseUrl(){return this.#e}register(e,t,s){let r=this.#h.subscribe(e,t,s);return this.#u[e]=(this.#u[e]??0)+1,r}unregister(e){let t=this.#h.unsubscribe(e);if(t){let s=e.eventName,r=(this.#u[s]??1)-1;r<=0?delete this.#u[s]:this.#u[s]=r}return t}addHooks(e){let{beforeRequest:t,afterResponse:s,beforeError:r}=e;return t&&(this.#a.beforeRequest.push(...t),this.#f.beforeRequest+=t.length),s&&(this.#a.afterResponse.push(...s),this.#f.afterResponse+=s.length),r&&(this.#a.beforeError.push(...r),this.#f.beforeError+=r.length),this}clearHooks(){return this.#a.beforeRequest.length=0,this.#a.afterResponse.length=0,this.#a.beforeError.length=0,this.#f.beforeRequest=0,this.#f.afterResponse=0,this.#f.beforeError=0,this}configure({headers:e,searchParams:t,hooks:s,...r}){return e&&(n.#B(this.#n.headers,e),this.#o=new Headers(this.#n.headers),this.#o.delete("content-type")),t&&n.#b(this.#n.searchParams,t),Object.assign(this.#n,r),s&&this.addHooks(s),this}destroy(){this.clearHooks(),this.#h.destroy();for(let e in this.#u)delete this.#u[e]}async get(e,t){return this.#i(e,t)}async post(e,t,s){return this.#S("POST",e,t,s)}async put(e,t,s){return this.#S("PUT",e,t,s)}async patch(e,t,s){return this.#S("PATCH",e,t,s)}async delete(e,t,s){return this.#S("DELETE",e,t,s)}async head(e,t){return this.#A(e,t,{method:"HEAD"})}async options(e,t={}){g(e)&&([e,t]=[void 0,e]);let s=this.#T(t,{method:"OPTIONS"}),{requestOptions:r}=s,o=r.unwrap!==!1,i=r.hooks;try{let a=n.#l(this,e,r.searchParams);await this.#P(r,a,e,i?.beforeRequest);let d=await this.#y(e,s);d=await this.#v(d,r,i?.afterResponse);let u=d.headers.get("allow"),l;if(u){let c=u.split(",");l=new Array(c.length);for(let f=0,R=c.length;f<R;f++)l[f]=c[f].trim()}return this.#r({name:m.SUCCESS,data:l,global:t.global}),o?l:[!0,l]}catch(a){if(!o)return[!1,a];throw a}}async request(e,t={}){g(e)&&([e,t]=[void 0,e]);let s=this.#T(t,{}),r=s.requestOptions.unwrap!==!1;try{let o=await this.#y(e,s);return this.#r({name:m.SUCCESS,data:o,global:t.global}),r?o:[!0,o]}catch(o){if(!r)return[!1,o];throw o}}async getJson(e,t){return this.#i(e,t,{headers:{accept:`${h.JSON}`}},H)}async getXml(e,t){return this.#i(e,t,{headers:{accept:`${h.XML}`}},C)}async getHtml(e,t,s){let r=await this.#i(e,t,{headers:{accept:`${h.HTML}`}},ne);return Array.isArray(r)?r:s&&r?r.querySelector(s):r}async getHtmlFragment(e,t,s){let r=(g(e)?e:t)?.allowScripts===!0,o=await this.#i(e,t,{headers:{accept:`${h.HTML}`}},r?Oe:Te);return Array.isArray(o)?o:s&&o?o.querySelector(s):o}async getScript(e,t){return this.#i(e,t,{headers:{accept:`${h.JAVA_SCRIPT}`}},Q)}async getStylesheet(e,t){return this.#i(e,t,{headers:{accept:`${h.CSS}`}},_)}async getBlob(e,t){return this.#i(e,t,{headers:{accept:"application/octet-stream"}},ye)}async getImage(e,t){return this.#i(e,t,{headers:{accept:"image/*"}},ee)}async getBuffer(e,t){return this.#i(e,t,{headers:{accept:"application/octet-stream"}},be)}async getStream(e,t){return this.#i(e,t,{headers:{accept:"application/octet-stream"}},te)}async getEventStream(e,t){g(e)&&([e,t]=[void 0,e]);let s=this.#T(t??{},{method:t?.body?"POST":"GET",headers:{accept:`${h.EVENT_STREAM}`}}),{requestOptions:r}=s,o=r.unwrap!==!1,i=r.hooks;try{let a=n.#l(this,e,r.searchParams);await this.#P(r,a,e,i?.beforeRequest);let d=await this.#y(e,s),u=await this.#v(d,r,i?.afterResponse);this.#r({name:m.SUCCESS,data:u,global:s.global});let l=qe(u);return o?l:[!0,l]}catch(a){if(!o)return[!1,a];throw a}}async getJsonStream(e,t){g(e)&&([e,t]=[void 0,e]);let s=this.#T(t??{},{method:"GET",headers:{accept:`${h.NDJSON}`}}),{requestOptions:r}=s,o=r.unwrap!==!1,i=r.hooks;try{let a=n.#l(this,e,r.searchParams);await this.#P(r,a,e,i?.beforeRequest);let d=await this.#y(e,s),u=await this.#v(d,r,i?.afterResponse);this.#r({name:m.SUCCESS,data:u,global:s.global});let l=we(u);return o?l:[!0,l]}catch(a){if(!o)return[!1,a];throw a}}async#i(e,t,s={},r){return s.method="GET",s.body=void 0,this.#A(e,t,s,r)}async#y(e,t){let{signalController:s,requestOptions:r,global:o}=t;n.#g.add(s);let i=n.#N(r.retry),a=r.method??"GET",d=i.limit>0&&i.methods.includes(a),u=r.dedupe===!0&&(a==="GET"||a==="HEAD"),l=performance.now();try{let c=n.#l(this,e,r.searchParams),f;if(u){f=`${a}:${c.href}`;let x=n.#E.get(f);if(x)return(await x).clone()}let R=r.onUploadProgress,p=r.body;R&&p!=null&&(r.duplex="half");let y=this.#M(c,r,e,a,d,i,p,R,l,o);if(u){n.#E.set(f,y);try{return n.#x(await y,r)}finally{n.#E.delete(f)}}return n.#x(await y,r)}finally{if(n.#g.delete(s.destroy()),!r.signal?.aborted){let c=performance.now();this.#r({name:m.COMPLETE,data:{timing:{start:l,end:c,duration:c-l}},global:o}),n.#g.size===0&&this.#r({name:m.ALL_COMPLETE,global:o})}}}async#M(e,t,s,r,o,i,a,d,u,l){let c=0;for(;;)try{d&&await n.#U(t,a,d);let f=await fetch(e,t);if(!f.ok){if(o&&c<i.limit&&i.statusCodes.includes(f.status)){c++,this.#r({name:m.RETRY,data:{attempt:c,status:f.status,method:r,path:s,timing:n.#w(u)},global:l}),await n.#k(i,c);continue}let R;if(t.captureErrorBody!==!1)try{R=await f.text()}catch{}throw await this.#H(s,f,{entity:R,url:e,method:r,timing:n.#w(u)},t)}return f}catch(f){if(f instanceof O)throw f;if(o&&c<i.limit){c++,this.#r({name:m.RETRY,data:{attempt:c,error:f.message,method:r,path:s,timing:n.#w(u)},global:l}),await n.#k(i,c);continue}throw await this.#H(s,void 0,{cause:f,url:e,method:r,timing:n.#w(u)},t)}}static async#U(e,t,s){if(t==null)return;let r=null;if(typeof t=="string")r=new TextEncoder().encode(t);else if(t instanceof Blob)r=new Uint8Array(await t.arrayBuffer());else if(Be(t))r=new Uint8Array(t);else if(ArrayBuffer.isView(t))r=new Uint8Array(t.buffer,t.byteOffset,t.byteLength);else if(!(t instanceof ReadableStream))return;let o=r?r.byteLength:null,i=r?new ReadableStream({start(u){u.enqueue(r),u.close()}}):t,a=0,d=new TransformStream({transform(u,l){a+=u.byteLength,s({loaded:a,total:o,percentage:o!==null&&o>0?Math.round(a/o*100):null}),l.enqueue(u)}});e.body=i.pipeThrough(d)}static#x(e,t){let s=t.onDownloadProgress;if(!s||!e.body)return e;let r=e.headers.get("content-length"),o=r?parseInt(r,10):null,i=0,a=new TransformStream({transform(d,u){i+=d.byteLength,s({loaded:i,total:o,percentage:o!==null&&o>0?Math.round(i/o*100):null}),u.enqueue(d)}});return new Response(e.body.pipeThrough(a),{status:e.status,statusText:e.statusText,headers:e.headers})}static#w(e){let t=performance.now();return{start:e,end:t,duration:t-e}}static#N(e){if(e===void 0)return n.#L;if(typeof e=="number")return{limit:e,statusCodes:K,methods:Y,delay:D,backoffFactor:F};let t=n.#C.get(e);if(t!==void 0)return t;let s={limit:e.limit??0,statusCodes:e.statusCodes??K,methods:e.methods??Y,delay:e.delay??D,backoffFactor:e.backoffFactor??F};return n.#C.set(e,s),s}static#k(e,t){let s=typeof e.delay=="function"?e.delay(t):e.delay*e.backoffFactor**(t-1);return new Promise(r=>setTimeout(r,s))}#S(e,t,s,r,o){let[i,a,d]=z(t)?[t,s,r]:[void 0,t,s],u=d!==void 0?Object.assign({},d,{body:a,method:e}):{body:a,method:e};return this.#A(i,u,{},o)}async#P(e,t,s,r){let o=n.#c.beforeRequest,i=this.#a.beforeRequest,a=r===void 0?0:r.length;if(o.length===0&&i.length===0&&a===0)return t;for(let d=0,u=o.length;d<u;d++){let l=await o[d](e,t);l&&(Object.assign(e,l),l.searchParams!==void 0&&(t=n.#l(this,s,e.searchParams)))}for(let d=0,u=i.length;d<u;d++){let l=await i[d](e,t);l&&(Object.assign(e,l),l.searchParams!==void 0&&(t=n.#l(this,s,e.searchParams)))}for(let d=0;d<a;d++){let u=await r[d](e,t);u&&(Object.assign(e,u),u.searchParams!==void 0&&(t=n.#l(this,s,e.searchParams)))}return t}async#v(e,t,s){let r=n.#c.afterResponse,o=this.#a.afterResponse,i=s===void 0?0:s.length;if(r.length===0&&o.length===0&&i===0)return e;for(let a=0,d=r.length;a<d;a++){let u=await r[a](e,t);u&&(e=u)}for(let a=0,d=o.length;a<d;a++){let u=await o[a](e,t);u&&(e=u)}for(let a=0;a<i;a++){let d=await s[a](e,t);d&&(e=d)}return e}async#D(e,t){let s=n.#c.beforeError,r=this.#a.beforeError,o=t===void 0?0:t.length;if(s.length===0&&r.length===0&&o===0)return e;for(let i=0,a=s.length;i<a;i++){let d=await s[i](e);d instanceof O&&(e=d)}for(let i=0,a=r.length;i<a;i++){let d=await r[i](e);d instanceof O&&(e=d)}for(let i=0;i<o;i++){let a=await t[i](e);a instanceof O&&(e=a)}return e}async#A(e,t={},s={},r){g(e)&&([e,t]=[void 0,e]);let o=this.#T(t,s),{requestOptions:i}=o,a=i.unwrap!==!1,d=i.hooks;try{let u=n.#l(this,e,i.searchParams);await this.#P(i,u,e,d?.beforeRequest);let l=await this.#y(e,o);l=await this.#v(l,i,d?.afterResponse);try{!r&&l.status!==204&&(r=this.#G(l.headers.get("content-type")));let c=await r?.(l);return this.#r({name:m.SUCCESS,data:c,global:o.global}),a?c:[!0,c]}catch(c){throw await this.#H(e,l,{cause:c},i)}}catch(u){if(!a)return[!1,u];throw u}}static#F({headers:e,searchParams:t,...s},{headers:r,searchParams:o,...i}){return r=n.#B(new Headers,e,r),o=n.#b(new URLSearchParams,t,o),{...X(i,s),headers:r,searchParams:o}}static#B(e,...t){for(let s of t)if(s!==void 0)if(s instanceof Headers)s.forEach((r,o)=>e.set(o,r));else if(Array.isArray(s))for(let[r,o]of s)e.set(r,o);else{let r=Object.keys(s);for(let o=0,i=r.length;o<i;o++){let a=r[o],d=s[a];d!==void 0&&e.set(a,d)}}return e}static#b(e,...t){for(let s of t)if(s!==void 0)if(s instanceof URLSearchParams)s.forEach((r,o)=>e.set(o,r));else if(z(s)||Array.isArray(s))for(let[r,o]of new URLSearchParams(s))e.set(r,o);else{let r=Object.keys(s);for(let o=0;o<r.length;o++){let i=r[o],a=s[i];a!==void 0&&e.set(i,typeof a=="string"?a:String(a))}}return e}#T(e,t){let s=e.headers,r=e.searchParams,o=e.body,i=t.headers,a=t.searchParams,d=t.method??e.method??this.#n.method??"GET",u=Se(d),l;!u&&s===void 0&&i===void 0?l=new Headers(this.#o):(l=new Headers(this.#n.headers),(s!==void 0||i!==void 0)&&n.#B(l,s,i));let c=this.#n.searchParams,f=c!==void 0&&c.size>0,R;!f&&r===void 0&&a===void 0?R=new URLSearchParams:(R=new URLSearchParams(c),(r!==void 0||a!==void 0)&&n.#b(R,r,a));let p=Object.assign({},this.#n,e,t);if(p.headers=l,p.searchParams=R,u)if(Pe(o))p.body=o,l.delete("content-type");else{let T=this.#n.body,S=g(T)&&g(o)?X(T,o):o!==void 0?o:T,P=l.get("content-type"),Ce=P!==null&&P.includes("json");p.body=Ce&&g(S)?Ae(S):S}else p.body instanceof URLSearchParams&&n.#b(R,p.body),p.body=void 0,(s!==void 0||i!==void 0)&&l.delete("content-type");let y=p.signal,x=p.timeout,k=p.global??!1,V=p.xsrf;if(V){let{cookieName:T,headerName:S}=typeof V=="object"?V:{},P=ve(T??ue);P&&l.set(S??de,P)}let re=new j({signal:y,timeout:x}).onAbort(T=>this.#r({name:m.ABORTED,event:T,global:k})).onTimeout(T=>this.#r({name:m.TIMEOUT,event:T,global:k}));return p.signal=re.signal,this.#r({name:m.CONFIGURED,data:p,global:k}),{signalController:re,requestOptions:p,global:k}}static#j(e){if(e instanceof URL)return e;if(!z(e))throw new TypeError("Invalid URL");return new URL(e,e.startsWith("/")?globalThis.location.origin:void 0)}static#J(e){if(e===null)return;let t=n.#m.get(e);return t!==void 0||(t=M.parse(e)??void 0,t!==void 0&&(n.#m.size>=100&&n.#m.delete(n.#m.keys().next().value),n.#m.set(e,t))),t}static#l(e,t,s){let r;if(e instanceof URL){let o=e.pathname,i=o.charCodeAt(o.length-1)===47?o.slice(0,-1):o;r=t?new URL(`${i}${t}`,e.origin):new URL(e)}else r=t?new URL(`${e.#s}${t}`,e.#t):new URL(e.#e);return s&&n.#b(r.searchParams,s),r}static#$(e,{status:t,statusText:s}=new Response){switch(e){case w.ABORT:return Re;case w.TIMEOUT:return he;default:return t>=400?new E(t,s):fe}}async#H(e,t,{cause:s,entity:r,url:o,method:i,timing:a}={},d){let u=i&&o?`${i} ${o.href} failed${t?` with status ${t.status}`:""}`:`An error has occurred with your request to: '${e}'`,l=new O(n.#$(s?.name,t),{message:u,cause:s,entity:r,url:o,method:i,timing:a});return l=await this.#D(l,d?.hooks?.beforeError),this.#r({name:m.ERROR,data:l}),l}#r({name:e,event:t,data:s,global:r=!0}){let o=r&&(n.#p[e]??0)>0,i=(this.#u[e]??0)>0;if(!o&&!i)return;let a=t??new CustomEvent(e);o&&n.#O.publish(e,a,s),i&&this.#h.publish(e,a,s)}#G(e){if(!e)return;let t=n.#d.get(e);if(t!==void 0)return t===null?void 0:t;let s=n.#J(e);if(!s){n.#d.set(e,null);return}let r=n.#q;for(let i=0,a=r.length;i<a;i++){let d=r[i];if(s.matches(d[0])){let u=d[1];return n.#d.set(e,u),u}}let o=s.subtype;if(o.endsWith("+json"))return n.#d.set(e,H),H;if(o.endsWith("+xml"))return n.#d.set(e,C),C;n.#d.set(e,null)}get[Symbol.toStringTag](){return"Transportr"}};export{He as Transportr};
|
|
8
8
|
//# sourceMappingURL=transportr.js.map
|