@d1g1tal/transportr 0.0.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.
@@ -0,0 +1,887 @@
1
+ var Transportr = (() => {
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
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
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ 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
+
47
+ // src/transportr.js
48
+ var transportr_exports = {};
49
+ __export(transportr_exports, {
50
+ default: () => Transportr
51
+ });
52
+
53
+ // node_modules/@d1g1tal/collections/src/list.js
54
+ var List = class {
55
+ #array;
56
+ constructor(iterable = []) {
57
+ this.#array = Array.of(...iterable);
58
+ }
59
+ static from(iterable, mapper, context) {
60
+ return new List(Array.from(iterable, mapper, context));
61
+ }
62
+ static withSize(size) {
63
+ return new List(new Array(size));
64
+ }
65
+ add(element) {
66
+ this.#array.push(element);
67
+ return this;
68
+ }
69
+ addAll(iterable) {
70
+ this.#array.push(...iterable);
71
+ return this;
72
+ }
73
+ clear() {
74
+ this.#array.length = 0;
75
+ }
76
+ concat(elements) {
77
+ return this(this.#array.concat(...elements));
78
+ }
79
+ every(predicate) {
80
+ return this.#array.every((element, index) => predicate(element, index, this));
81
+ }
82
+ some(predicate) {
83
+ return this.#array.some((element, index) => predicate(element, index, this));
84
+ }
85
+ filter(predicate) {
86
+ return new List(this.#array.filter((element, index) => predicate(element, index, this)));
87
+ }
88
+ find(predicate, context) {
89
+ return this.#array.find((element, index) => predicate(element, index, this), context);
90
+ }
91
+ findIndex(predicate, context) {
92
+ return this.#array.findIndex((element, index) => predicate(element, index, this), context);
93
+ }
94
+ map(mapper) {
95
+ return new List(this.#array.map((element, index) => mapper(element, index, this)));
96
+ }
97
+ reduce(reducer, initialValue) {
98
+ return this.#array.reduce(reducer, initialValue);
99
+ }
100
+ sort(comparator) {
101
+ this.#array.sort(comparator);
102
+ return this;
103
+ }
104
+ forEach(consumer) {
105
+ this.#array.forEach((element, index) => consumer(element, index, this));
106
+ }
107
+ get(element, fromIndex = 0) {
108
+ return this.#array.at(this.#array.indexOf(element, fromIndex));
109
+ }
110
+ has(element) {
111
+ return this.#array.includes(element);
112
+ }
113
+ insert(index, element) {
114
+ this.#array.splice(index, 0, element);
115
+ }
116
+ delete(element) {
117
+ return this.#array.splice(this.#array.indexOf(element), 1).length == 1;
118
+ }
119
+ deleteAt(index) {
120
+ return this.#array.splice(index, 1).length == 1;
121
+ }
122
+ keys() {
123
+ return this.#array.keys();
124
+ }
125
+ values() {
126
+ return this[Symbol.iterator]();
127
+ }
128
+ entries() {
129
+ return this.#array.entries();
130
+ }
131
+ isEmpty() {
132
+ return this.#array.length === 0;
133
+ }
134
+ toArray() {
135
+ return [...this.#array];
136
+ }
137
+ toString() {
138
+ return this.#array.toString();
139
+ }
140
+ valueOf() {
141
+ return this.#array.valueOf();
142
+ }
143
+ get size() {
144
+ return this.#array.length;
145
+ }
146
+ [Symbol.iterator]() {
147
+ return this.#array[Symbol.iterator]();
148
+ }
149
+ get [Symbol.toStringTag]() {
150
+ return "List";
151
+ }
152
+ };
153
+
154
+ // node_modules/@d1g1tal/collections/src/multi-map.js
155
+ var MultiMap = class extends Map {
156
+ set(key, value) {
157
+ super.set(key, (this.get(key) ?? new List()).add(value));
158
+ return this;
159
+ }
160
+ [Symbol.toStringTag]() {
161
+ return "MultiMap";
162
+ }
163
+ };
164
+
165
+ // node_modules/@d1g1tal/collections/src/set-multi-map.js
166
+ var SetMultiMap = class extends Map {
167
+ set(key, value) {
168
+ super.set(key, (super.get(key) ?? /* @__PURE__ */ new Set()).add(value));
169
+ return this;
170
+ }
171
+ [Symbol.toStringTag]() {
172
+ return "SetMultiMap";
173
+ }
174
+ };
175
+
176
+ // node_modules/@d1g1tal/collections/src/node.js
177
+ var Node = class {
178
+ #value;
179
+ #next;
180
+ constructor(value) {
181
+ this.#value = value;
182
+ this.#next = null;
183
+ }
184
+ get value() {
185
+ return this.#value;
186
+ }
187
+ get next() {
188
+ return this.#next;
189
+ }
190
+ get [Symbol.toStringTag]() {
191
+ return "Node";
192
+ }
193
+ };
194
+
195
+ // node_modules/@d1g1tal/collections/src/weak-set-multi-map.js
196
+ var WeakSetMultiMap = class extends Map {
197
+ set(key, value) {
198
+ super.set(key, (super.get(key) ?? /* @__PURE__ */ new WeakSet()).add(value));
199
+ return this;
200
+ }
201
+ [Symbol.toStringTag]() {
202
+ return "WeakSetMultiMap";
203
+ }
204
+ };
205
+
206
+ // node_modules/@d1g1tal/chrysalis/src/esm/object-type.js
207
+ var _type = (object) => object?.constructor ?? object?.prototype?.constructor ?? globalThis[Object.prototype.toString.call(object).slice(8, -1)] ?? object;
208
+ var object_type_default = _type;
209
+
210
+ // node_modules/@d1g1tal/chrysalis/src/esm/object-is-type.js
211
+ var _isType = (object, type) => object_type_default(object) === type;
212
+ var object_is_type_default = _isType;
213
+
214
+ // node_modules/@d1g1tal/chrysalis/src/esm/object-merge.js
215
+ var _objectMerge = (...objects) => {
216
+ return objects.reduce((prev, obj) => {
217
+ Object.keys(obj).forEach((key) => {
218
+ const pVal = prev[key];
219
+ const oVal = obj[key];
220
+ if (Array.isArray(pVal) && Array.isArray(oVal)) {
221
+ prev[key] = [.../* @__PURE__ */ new Set([...oVal, ...pVal])];
222
+ } else if (object_is_type_default(pVal, Object) && object_is_type_default(oVal, Object)) {
223
+ prev[key] = _objectMerge(pVal, oVal);
224
+ } else {
225
+ prev[key] = oVal;
226
+ }
227
+ });
228
+ return prev;
229
+ }, {});
230
+ };
231
+ var object_merge_default = _objectMerge;
232
+
233
+ // node_modules/@d1g1tal/media-type/src/utils.js
234
+ var removeLeadingAndTrailingHTTPWhitespace = (string) => string.replace(/^[ \t\n\r]+/u, "").replace(/[ \t\n\r]+$/u, "");
235
+ var removeTrailingHTTPWhitespace = (string) => string.replace(/[ \t\n\r]+$/u, "");
236
+ var isHTTPWhitespaceChar = (char) => char === " " || char === " " || char === "\n" || char === "\r";
237
+ var solelyContainsHTTPTokenCodePoints = (string) => /^[-!#$%&'*+.^_`|~A-Za-z0-9]*$/u.test(string);
238
+ var solelyContainsHTTPQuotedStringTokenCodePoints = (string) => /^[\t\u0020-\u007E\u0080-\u00FF]*$/u.test(string);
239
+ var asciiLowercase = (string) => string.replace(/[A-Z]/ug, (l) => l.toLowerCase());
240
+ var collectAnHTTPQuotedString = (input, position) => {
241
+ let value = "";
242
+ position++;
243
+ while (true) {
244
+ while (position < input.length && input[position] !== '"' && input[position] !== "\\") {
245
+ value += input[position];
246
+ ++position;
247
+ }
248
+ if (position >= input.length) {
249
+ break;
250
+ }
251
+ const quoteOrBackslash = input[position];
252
+ ++position;
253
+ if (quoteOrBackslash === "\\") {
254
+ if (position >= input.length) {
255
+ value += "\\";
256
+ break;
257
+ }
258
+ value += input[position];
259
+ ++position;
260
+ } else {
261
+ break;
262
+ }
263
+ }
264
+ return [value, position];
265
+ };
266
+
267
+ // node_modules/@d1g1tal/media-type/src/media-type-parameters.js
268
+ var MediaTypeParameters = class {
269
+ constructor(map) {
270
+ this._map = map;
271
+ }
272
+ get size() {
273
+ return this._map.size;
274
+ }
275
+ get(name) {
276
+ return this._map.get(asciiLowercase(String(name)));
277
+ }
278
+ has(name) {
279
+ return this._map.has(asciiLowercase(String(name)));
280
+ }
281
+ set(name, value) {
282
+ name = asciiLowercase(String(name));
283
+ value = String(value);
284
+ if (!solelyContainsHTTPTokenCodePoints(name)) {
285
+ throw new Error(`Invalid media type parameter name "${name}": only HTTP token code points are valid.`);
286
+ }
287
+ if (!solelyContainsHTTPQuotedStringTokenCodePoints(value)) {
288
+ throw new Error(`Invalid media type parameter value "${value}": only HTTP quoted-string token code points are valid.`);
289
+ }
290
+ this._map.set(name, value);
291
+ return this;
292
+ }
293
+ clear() {
294
+ this._map.clear();
295
+ }
296
+ delete(name) {
297
+ name = asciiLowercase(String(name));
298
+ return this._map.delete(name);
299
+ }
300
+ forEach(callback, thisArg) {
301
+ this._map.forEach(callback, thisArg);
302
+ }
303
+ keys() {
304
+ return this._map.keys();
305
+ }
306
+ values() {
307
+ return this._map.values();
308
+ }
309
+ entries() {
310
+ return this._map.entries();
311
+ }
312
+ [Symbol.iterator]() {
313
+ return this._map[Symbol.iterator]();
314
+ }
315
+ };
316
+
317
+ // node_modules/@d1g1tal/media-type/src/parser.js
318
+ var parse = (input) => {
319
+ input = removeLeadingAndTrailingHTTPWhitespace(input);
320
+ let position = 0;
321
+ let type = "";
322
+ while (position < input.length && input[position] !== "/") {
323
+ type += input[position];
324
+ ++position;
325
+ }
326
+ if (type.length === 0 || !solelyContainsHTTPTokenCodePoints(type)) {
327
+ return null;
328
+ }
329
+ if (position >= input.length) {
330
+ return null;
331
+ }
332
+ ++position;
333
+ let subtype = "";
334
+ while (position < input.length && input[position] !== ";") {
335
+ subtype += input[position];
336
+ ++position;
337
+ }
338
+ subtype = removeTrailingHTTPWhitespace(subtype);
339
+ if (subtype.length === 0 || !solelyContainsHTTPTokenCodePoints(subtype)) {
340
+ return null;
341
+ }
342
+ const mediaType = {
343
+ type: asciiLowercase(type),
344
+ subtype: asciiLowercase(subtype),
345
+ parameters: /* @__PURE__ */ new Map()
346
+ };
347
+ while (position < input.length) {
348
+ ++position;
349
+ while (isHTTPWhitespaceChar(input[position])) {
350
+ ++position;
351
+ }
352
+ let parameterName = "";
353
+ while (position < input.length && input[position] !== ";" && input[position] !== "=") {
354
+ parameterName += input[position];
355
+ ++position;
356
+ }
357
+ parameterName = asciiLowercase(parameterName);
358
+ if (position < input.length) {
359
+ if (input[position] === ";") {
360
+ continue;
361
+ }
362
+ ++position;
363
+ }
364
+ let parameterValue = null;
365
+ if (input[position] === '"') {
366
+ [parameterValue, position] = collectAnHTTPQuotedString(input, position);
367
+ while (position < input.length && input[position] !== ";") {
368
+ ++position;
369
+ }
370
+ } else {
371
+ parameterValue = "";
372
+ while (position < input.length && input[position] !== ";") {
373
+ parameterValue += input[position];
374
+ ++position;
375
+ }
376
+ parameterValue = removeTrailingHTTPWhitespace(parameterValue);
377
+ if (parameterValue === "") {
378
+ continue;
379
+ }
380
+ }
381
+ if (parameterName.length > 0 && solelyContainsHTTPTokenCodePoints(parameterName) && solelyContainsHTTPQuotedStringTokenCodePoints(parameterValue) && !mediaType.parameters.has(parameterName)) {
382
+ mediaType.parameters.set(parameterName, parameterValue);
383
+ }
384
+ }
385
+ return mediaType;
386
+ };
387
+ var parser_default = parse;
388
+
389
+ // node_modules/@d1g1tal/media-type/src/serializer.js
390
+ var serialize = (mediaType) => {
391
+ let serialization = `${mediaType.type}/${mediaType.subtype}`;
392
+ if (mediaType.parameters.size === 0) {
393
+ return serialization;
394
+ }
395
+ for (let [name, value] of mediaType.parameters) {
396
+ serialization += ";";
397
+ serialization += name;
398
+ serialization += "=";
399
+ if (!solelyContainsHTTPTokenCodePoints(value) || value.length === 0) {
400
+ value = value.replace(/(["\\])/ug, "\\$1");
401
+ value = `"${value}"`;
402
+ }
403
+ serialization += value;
404
+ }
405
+ return serialization;
406
+ };
407
+ var serializer_default = serialize;
408
+
409
+ // node_modules/@d1g1tal/media-type/src/media-type.js
410
+ var MediaType = class {
411
+ constructor(string) {
412
+ string = String(string);
413
+ const result = parser_default(string);
414
+ if (result === null) {
415
+ throw new Error(`Could not parse media type string '${string}'`);
416
+ }
417
+ this._type = result.type;
418
+ this._subtype = result.subtype;
419
+ this._parameters = new MediaTypeParameters(result.parameters);
420
+ }
421
+ static parse(string) {
422
+ try {
423
+ return new this(string);
424
+ } catch (e) {
425
+ return null;
426
+ }
427
+ }
428
+ get essence() {
429
+ return `${this.type}/${this.subtype}`;
430
+ }
431
+ get type() {
432
+ return this._type;
433
+ }
434
+ set type(value) {
435
+ value = asciiLowercase(String(value));
436
+ if (value.length === 0) {
437
+ throw new Error("Invalid type: must be a non-empty string");
438
+ }
439
+ if (!solelyContainsHTTPTokenCodePoints(value)) {
440
+ throw new Error(`Invalid type ${value}: must contain only HTTP token code points`);
441
+ }
442
+ this._type = value;
443
+ }
444
+ get subtype() {
445
+ return this._subtype;
446
+ }
447
+ set subtype(value) {
448
+ value = asciiLowercase(String(value));
449
+ if (value.length === 0) {
450
+ throw new Error("Invalid subtype: must be a non-empty string");
451
+ }
452
+ if (!solelyContainsHTTPTokenCodePoints(value)) {
453
+ throw new Error(`Invalid subtype ${value}: must contain only HTTP token code points`);
454
+ }
455
+ this._subtype = value;
456
+ }
457
+ get parameters() {
458
+ return this._parameters;
459
+ }
460
+ toString() {
461
+ return serializer_default(this);
462
+ }
463
+ isJavaScript({ prohibitParameters = false } = {}) {
464
+ switch (this._type) {
465
+ case "text": {
466
+ switch (this._subtype) {
467
+ case "ecmascript":
468
+ case "javascript":
469
+ case "javascript1.0":
470
+ case "javascript1.1":
471
+ case "javascript1.2":
472
+ case "javascript1.3":
473
+ case "javascript1.4":
474
+ case "javascript1.5":
475
+ case "jscript":
476
+ case "livescript":
477
+ case "x-ecmascript":
478
+ case "x-javascript":
479
+ return !prohibitParameters || this._parameters.size === 0;
480
+ default:
481
+ return false;
482
+ }
483
+ }
484
+ case "application": {
485
+ switch (this._subtype) {
486
+ case "ecmascript":
487
+ case "javascript":
488
+ case "x-ecmascript":
489
+ case "x-javascript":
490
+ return !prohibitParameters || this._parameters.size === 0;
491
+ default:
492
+ return false;
493
+ }
494
+ }
495
+ default:
496
+ return false;
497
+ }
498
+ }
499
+ isXML() {
500
+ return this._subtype === "xml" && (this._type === "text" || this._type === "application") || this._subtype.endsWith("+xml");
501
+ }
502
+ isHTML() {
503
+ return this._subtype === "html" && this._type === "text";
504
+ }
505
+ get [Symbol.toStringTag]() {
506
+ return "MediaType";
507
+ }
508
+ };
509
+
510
+ // src/http-media-type.js
511
+ var HttpMediaType = {
512
+ AAC: "audio/aac",
513
+ ABW: "application/x-abiword",
514
+ ARC: "application/x-freearc",
515
+ AVIF: "image/avif",
516
+ AVI: "video/x-msvideo",
517
+ AZW: "application/vnd.amazon.ebook",
518
+ BIN: "application/octet-stream",
519
+ BMP: "image/bmp",
520
+ BZIP: "application/x-bzip",
521
+ BZIP2: "application/x-bzip2",
522
+ CDA: "application/x-cdf",
523
+ CSH: "application/x-csh",
524
+ CSS: "text/css",
525
+ CSV: "text/csv",
526
+ DOC: "application/msword",
527
+ DOCX: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
528
+ EOT: "application/vnd.ms-fontobject",
529
+ EPUB: "application/epub+zip",
530
+ GZIP: "application/gzip",
531
+ GIF: "image/gif",
532
+ HTML: "text/html",
533
+ ICO: "image/vnd.microsoft.icon",
534
+ ICS: "text/calendar",
535
+ JAR: "application/java-archive",
536
+ JPEG: "image/jpeg",
537
+ JAVA_SCRIPT: "text/javascript",
538
+ JSON: "application/json",
539
+ JSON_LD: "application/ld+json",
540
+ MID: "audio/midi",
541
+ X_MID: "audio/x-midi",
542
+ MP3: "audio/mpeg",
543
+ MP4A: "audio/mp4",
544
+ MP4: "video/mp4",
545
+ MPEG: "video/mpeg",
546
+ MPKG: "application/vnd.apple.installer+xml",
547
+ ODP: "application/vnd.oasis.opendocument.presentation",
548
+ ODS: "application/vnd.oasis.opendocument.spreadsheet",
549
+ ODT: "application/vnd.oasis.opendocument.text",
550
+ OGA: "audio/ogg",
551
+ OGV: "video/ogg",
552
+ OGX: "application/ogg",
553
+ OPUS: "audio/opus",
554
+ OTF: "font/otf",
555
+ PNG: "image/png",
556
+ PDF: "application/pdf",
557
+ PHP: "application/x-httpd-php",
558
+ PPT: "application/vnd.ms-powerpoint",
559
+ PPTX: "application/vnd.openxmlformats-officedocument.presentationml.presentation",
560
+ RAR: "application/vnd.rar",
561
+ RTF: "application/rtf",
562
+ SH: "application/x-sh",
563
+ SVG: "image/svg+xml",
564
+ TAR: "application/x-tar",
565
+ TIFF: "image/tiff",
566
+ TRANSPORT_STREAM: "video/mp2t",
567
+ TTF: "font/ttf",
568
+ TEXT: "text/plain",
569
+ VSD: "application/vnd.visio",
570
+ WAV: "audio/wav",
571
+ WEBA: "audio/webm",
572
+ WEBM: "video/webm",
573
+ WEBP: "image/webp",
574
+ WOFF: "font/woff",
575
+ WOFF2: "font/woff2",
576
+ XHTML: "application/xhtml+xml",
577
+ XLS: "application/vnd.ms-excel",
578
+ XLSX: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
579
+ XML: "application/xml",
580
+ XUL: "application/vnd.mozilla.xul+xml",
581
+ ZIP: "application/zip",
582
+ "3GP": "video/3gpp",
583
+ "3G2": "video/3gpp2",
584
+ "7Z": "application/x-7z-compressed"
585
+ };
586
+ var http_media_type_default = HttpMediaType;
587
+
588
+ // src/http-request-headers.js
589
+ var HttpRequestHeader = {
590
+ ACCEPT: "accept",
591
+ ACCEPT_CHARSET: "accept-charset",
592
+ ACCEPT_ENCODING: "accept-encoding",
593
+ ACCEPT_LANGUAGE: "accept-language",
594
+ AUTHORIZATION: "authorization",
595
+ CACHE_CONTROL: "cache-control",
596
+ CONNECTION: "connection",
597
+ COOKIE: "cookie",
598
+ CONTENT_LENGTH: "content-length",
599
+ CONTENT_MD5: "content-md5",
600
+ CONTENT_TYPE: "content-type",
601
+ DATE: "date",
602
+ EXPECT: "expect",
603
+ FROM: "from",
604
+ HOST: "host",
605
+ IF_MATCH: "if-match",
606
+ IF_MODIFIED_SINCE: "if-modified-since",
607
+ IF_NONE_MATCH: "if-none-match",
608
+ IF_RANGE: "if-range",
609
+ IF_UNMODIFIED_SINCE: "if-unmodified-since",
610
+ MAX_FORWARDS: "max-forwards",
611
+ ORIGIN: "origin",
612
+ PRAGMA: "pragma",
613
+ PROXY_AUTHORIZATION: "proxy-authorization",
614
+ RANGE: "range",
615
+ REFERER: "referer",
616
+ TE: "te",
617
+ USER_AGENT: "user-agent",
618
+ UPGRADE: "upgrade",
619
+ VIA: "via",
620
+ WARNING: "warning",
621
+ X_REQUESTED_WITH: "x-requested-with",
622
+ DNT: "dnt",
623
+ X_FORWARDED_FOR: "x-forwarded-for",
624
+ X_FORWARDED_HOST: "x-forwarded-host",
625
+ X_FORWARDED_PROTO: "x-forwarded-proto",
626
+ FRONT_END_HTTPS: "front-end-https",
627
+ X_HTTP_METHOD_OVERRIDE: "x-http-method-override",
628
+ X_ATT_DEVICE_ID: "x-att-deviceid",
629
+ X_WAP_PROFILE: "x-wap-profile"
630
+ };
631
+ var http_request_headers_default = HttpRequestHeader;
632
+
633
+ // src/http-request-methods.js
634
+ var HttpRequestMethod = {
635
+ OPTIONS: "OPTIONS",
636
+ GET: "GET",
637
+ HEAD: "HEAD",
638
+ POST: "POST",
639
+ PUT: "PUT",
640
+ DELETE: "DELETE",
641
+ TRACE: "TRACE",
642
+ CONNECT: "CONNECT",
643
+ PATCH: "PATCH"
644
+ };
645
+ var http_request_methods_default = HttpRequestMethod;
646
+
647
+ // src/http-response-headers.js
648
+ var HttpResponseHeader = {
649
+ PROXY_CONNECTION: "proxy-connection",
650
+ X_UIDH: "x-uidh",
651
+ X_CSRF_TOKEN: "x-csrf-token",
652
+ ACCESS_CONTROL_ALLOW_ORIGIN: "access-control-allow-origin",
653
+ ACCEPT_PATCH: "accept-patch",
654
+ ACCEPT_RANGES: "accept-ranges",
655
+ AGE: "age",
656
+ ALLOW: "allow",
657
+ CACHE_CONTROL: "cache-control",
658
+ CONNECTION: "connection",
659
+ CONTENT_DISPOSITION: "content-disposition",
660
+ CONTENT_ENCODING: "content-encoding",
661
+ CONTENT_LANGUAGE: "content-language",
662
+ CONTENT_LENGTH: "content-length",
663
+ CONTENT_LOCATION: "content-location",
664
+ CONTENT_RANGE: "content-range",
665
+ CONTENT_TYPE: "content-type",
666
+ DATE: "date",
667
+ ETAG: "etag",
668
+ EXPIRES: "expires",
669
+ LAST_MODIFIED: "last-modified",
670
+ LINK: "link",
671
+ LOCATION: "location",
672
+ P3P: "p3p",
673
+ PRAGMA: "pragma",
674
+ PROXY_AUTHENTICATION: "proxy-authenticate",
675
+ PUBLIC_KEY_PINS: "public-key-pins",
676
+ RETRY_AFTER: "retry-after",
677
+ SERVER: "server",
678
+ SET_COOKIE: "set-cookie",
679
+ STATUS: "status",
680
+ STRICT_TRANSPORT_SECURITY: "strict-transport-security",
681
+ TRAILER: "trailer",
682
+ TRANSFER_ENCODING: "transfer-encoding",
683
+ UPGRADE: "upgrade",
684
+ VARY: "vary",
685
+ VIA: "via",
686
+ WARNING: "warning",
687
+ WWW_AUTHENTICATE: "www-authenticate",
688
+ X_XSS_PROTECTION: "x-xss-protection",
689
+ CONTENT_SECURITY_POLICY: "content-security-policy",
690
+ X_CONTENT_TYPE_OPTIONS: "x-content-type-options",
691
+ X_POWERED_BY: "x-powered-by"
692
+ };
693
+ var http_response_headers_default = HttpResponseHeader;
694
+
695
+ // src/transportr.js
696
+ var HttpError = class extends Error {
697
+ };
698
+ var endsWithSlashRegEx = /\/$/;
699
+ var _handleText = async (response) => await response.text();
700
+ var _handleJson = async (response) => await response.json();
701
+ var _handleBlob = async (response) => await response.blob();
702
+ var _handleBuffer = async (response) => await response.arrayBuffer();
703
+ var _handleReadableStream = async (response) => response.body;
704
+ var _handleXml = async (response) => new DOMParser().parseFromString(await response.text(), Transportr.MediaType.XML.essence);
705
+ var _baseUrl, _MediaType, _contentTypeHandlers, _defaultRequestOptions, _get, get_fn, _request, request_fn, _createUrl, createUrl_fn, _processResponse, processResponse_fn;
706
+ var _Transportr = class {
707
+ constructor(url = location.origin) {
708
+ __privateAdd(this, _get);
709
+ __privateAdd(this, _request);
710
+ __privateAdd(this, _baseUrl, void 0);
711
+ __privateAdd(this, _defaultRequestOptions, {
712
+ body: null,
713
+ cache: _Transportr.CachingPolicy.NO_STORE,
714
+ credentials: "same-origin",
715
+ headers: {},
716
+ integrity: void 0,
717
+ keepalive: void 0,
718
+ method: void 0,
719
+ mode: "cors",
720
+ redirect: "follow",
721
+ referrer: "about:client",
722
+ referrerPolicy: "strict-origin-when-cross-origin",
723
+ signal: null,
724
+ window: null
725
+ });
726
+ __privateSet(this, _baseUrl, url instanceof URL ? url : url.startsWith("/") ? new URL(url, location.origin) : new URL(url));
727
+ }
728
+ get baseUrl() {
729
+ return __privateGet(this, _baseUrl);
730
+ }
731
+ async get(path, options = {}) {
732
+ return __privateMethod(this, _request, request_fn).call(this, path, object_merge_default(options, { method: http_request_methods_default.GET }));
733
+ }
734
+ async post(path, body, options = {}) {
735
+ return __privateMethod(this, _request, request_fn).call(this, path, object_merge_default(options, { body, method: http_request_methods_default.POST }));
736
+ }
737
+ async put(path, options = {}) {
738
+ return __privateMethod(this, _request, request_fn).call(this, path, object_merge_default(options, { method: http_request_methods_default.PUT }));
739
+ }
740
+ async patch(path, options = {}) {
741
+ return __privateMethod(this, _request, request_fn).call(this, path, object_merge_default(options, { method: http_request_methods_default.PATCH }));
742
+ }
743
+ async delete(path, options = {}) {
744
+ return __privateMethod(this, _request, request_fn).call(this, path, object_merge_default(options, { method: http_request_methods_default.DELETE }));
745
+ }
746
+ async head(path, options = {}) {
747
+ return __privateMethod(this, _request, request_fn).call(this, path, object_merge_default(options, { method: http_request_methods_default.HEAD }));
748
+ }
749
+ async options(path, options = {}) {
750
+ return __privateMethod(this, _request, request_fn).call(this, path, object_merge_default(options, { method: http_request_methods_default.OPTIONS }));
751
+ }
752
+ async request(path, options = {}) {
753
+ return __privateMethod(this, _request, request_fn).call(this, path, options);
754
+ }
755
+ async getJson(path, options = {}) {
756
+ return __privateMethod(this, _get, get_fn).call(this, path, object_merge_default(options, { headers: { [http_request_headers_default.ACCEPT]: _Transportr.MediaType.JSON } }), _handleJson);
757
+ }
758
+ async getXml(path, options = {}) {
759
+ return new DOMParser().parseFromString(await __privateMethod(this, _get, get_fn).call(this, path, object_merge_default(options, { headers: { [http_request_headers_default.ACCEPT]: _Transportr.MediaType.XML } }), _handleBlob), http_media_type_default.XML);
760
+ }
761
+ async getHtml(path, options = {}) {
762
+ return __privateMethod(this, _get, get_fn).call(this, path, object_merge_default(options, { headers: { [http_request_headers_default.ACCEPT]: http_media_type_default.HTML } }), _handleText);
763
+ }
764
+ async getScript(path, options = {}) {
765
+ return __privateMethod(this, _get, get_fn).call(this, path, object_merge_default(options, { headers: { [http_request_headers_default.ACCEPT]: http_media_type_default.JAVA_SCRIPT } }), _handleText);
766
+ }
767
+ async getBlob(path, options = {}) {
768
+ return await __privateMethod(this, _get, get_fn).call(this, path, object_merge_default(options, { headers: { [http_request_headers_default.ACCEPT]: http_media_type_default.BIN } }), _handleBlob);
769
+ }
770
+ async getImage(path, options = {}) {
771
+ return URL.createObjectURL(await __privateMethod(this, _get, get_fn).call(this, path, object_merge_default(options, { headers: { [http_request_headers_default.ACCEPT]: "image/*" } }), _handleBlob));
772
+ }
773
+ async getBuffer(path, options = {}) {
774
+ return await __privateMethod(this, _get, get_fn).call(this, path, object_merge_default(options, { headers: { [http_request_headers_default.ACCEPT]: http_media_type_default.BIN } }), _handleBuffer);
775
+ }
776
+ async getStream(path, options = {}) {
777
+ return await __privateMethod(this, _get, get_fn).call(this, path, object_merge_default(options, { headers: { [http_request_headers_default.ACCEPT]: http_media_type_default.BIN } }), _handleReadableStream);
778
+ }
779
+ };
780
+ var Transportr = _Transportr;
781
+ _baseUrl = new WeakMap();
782
+ _MediaType = new WeakMap();
783
+ _contentTypeHandlers = new WeakMap();
784
+ _defaultRequestOptions = new WeakMap();
785
+ _get = new WeakSet();
786
+ get_fn = async function(path, options, responseHandler) {
787
+ return __privateMethod(this, _request, request_fn).call(this, path, object_merge_default(options, { method: _Transportr.Method.GET }), responseHandler);
788
+ };
789
+ _request = new WeakSet();
790
+ request_fn = async function(path, options, responseHandler) {
791
+ var _a, _b;
792
+ console.debug(`Calling '${path}'`);
793
+ const requestOptions = object_merge_default(__privateGet(this, _defaultRequestOptions), options);
794
+ const headers = new Headers(requestOptions.headers);
795
+ if (headers.get(_Transportr.RequestHeader.CONTENT_TYPE) == _Transportr.MediaType.JSON) {
796
+ requestOptions.body = JSON.stringify(requestOptions.body);
797
+ }
798
+ let response;
799
+ try {
800
+ response = await fetch(__privateMethod(_a = _Transportr, _createUrl, createUrl_fn).call(_a, __privateGet(this, _baseUrl), path, requestOptions.searchParams), requestOptions);
801
+ } catch (error) {
802
+ console.error(error);
803
+ process.exit(1);
804
+ }
805
+ if (!response.ok) {
806
+ throw new HttpError(`An error has occurred with your request: ${response.status} - ${await response.text()}`);
807
+ }
808
+ try {
809
+ return await (responseHandler ? responseHandler(response) : __privateMethod(_b = _Transportr, _processResponse, processResponse_fn).call(_b, response));
810
+ } catch (error) {
811
+ console.error(error);
812
+ process.exit(1);
813
+ }
814
+ };
815
+ _createUrl = new WeakSet();
816
+ createUrl_fn = function(url, path, searchParams = {}) {
817
+ url = new URL(`${url.pathname.replace(endsWithSlashRegEx, "")}${path}`, url.origin);
818
+ for (const [name, value] of Object.entries(searchParams)) {
819
+ if (url.searchParams.has(name)) {
820
+ url.searchParams.set(name, value);
821
+ } else {
822
+ url.searchParams.append(name, value);
823
+ }
824
+ }
825
+ return url;
826
+ };
827
+ _processResponse = new WeakSet();
828
+ processResponse_fn = async function(response) {
829
+ const mediaType = new MediaType(response.headers.get(http_response_headers_default.CONTENT_TYPE));
830
+ for (const [responseHandler, contentTypes] of __privateGet(_Transportr, _contentTypeHandlers).entries()) {
831
+ if (contentTypes.has(mediaType.subtype)) {
832
+ return await responseHandler(response);
833
+ }
834
+ }
835
+ console.warn("Unable to process response. Unknown content-type or no response handler defined.");
836
+ return response;
837
+ };
838
+ __privateAdd(Transportr, _createUrl);
839
+ __privateAdd(Transportr, _processResponse);
840
+ __privateAdd(Transportr, _MediaType, {
841
+ JSON: new MediaType(http_media_type_default.JSON),
842
+ XML: new MediaType(http_media_type_default.XML),
843
+ HTML: new MediaType(http_media_type_default.HTML),
844
+ SCRIPT: new MediaType(http_media_type_default.JAVA_SCRIPT),
845
+ TEXT: new MediaType(http_media_type_default.TEXT),
846
+ CSS: new MediaType(http_media_type_default.CSS),
847
+ WEBP: new MediaType(http_media_type_default.WEBP),
848
+ PNG: new MediaType(http_media_type_default.PNG),
849
+ GIF: new MediaType(http_media_type_default.GIF),
850
+ JPG: new MediaType(http_media_type_default.JPEG),
851
+ OTF: new MediaType(http_media_type_default.OTF),
852
+ WOFF: new MediaType(http_media_type_default.WOFF),
853
+ WOFF2: new MediaType(http_media_type_default.WOFF2),
854
+ TTF: new MediaType(http_media_type_default.TTF),
855
+ PDF: new MediaType(http_media_type_default.PDF)
856
+ });
857
+ __privateAdd(Transportr, _contentTypeHandlers, new SetMultiMap([
858
+ [_handleJson, __privateGet(_Transportr, _MediaType).JSON.subtype],
859
+ [_handleText, __privateGet(_Transportr, _MediaType).HTML.subtype],
860
+ [_handleText, __privateGet(_Transportr, _MediaType).SCRIPT.subtype],
861
+ [_handleText, __privateGet(_Transportr, _MediaType).CSS.subtype],
862
+ [_handleText, __privateGet(_Transportr, _MediaType).TEXT.subtype],
863
+ [_handleXml, __privateGet(_Transportr, _MediaType).XML.subtype],
864
+ [_handleBlob, __privateGet(_Transportr, _MediaType).GIF.subtype],
865
+ [_handleBlob, __privateGet(_Transportr, _MediaType).JPG.subtype],
866
+ [_handleBlob, __privateGet(_Transportr, _MediaType).PNG.subtype]
867
+ ]));
868
+ __publicField(Transportr, "Method", Object.freeze(http_request_methods_default));
869
+ __publicField(Transportr, "MediaType", http_media_type_default);
870
+ __publicField(Transportr, "RequestHeader", http_request_headers_default);
871
+ __publicField(Transportr, "ResponseHeader", Object.freeze(http_response_headers_default));
872
+ __publicField(Transportr, "CachingPolicy", {
873
+ DEFAULT: "default",
874
+ FORCE_CACHE: "force-cache",
875
+ NO_CACHE: "no-cache",
876
+ NO_STORE: "no-store",
877
+ ONLY_IF_CACHED: "only-if-cached",
878
+ RELOAD: "reload"
879
+ });
880
+ __publicField(Transportr, "CredentialsPolicy", {
881
+ INCLUDE: "include",
882
+ OMIT: "omit",
883
+ SAME_ORIGIN: "same-origin"
884
+ });
885
+ return __toCommonJS(transportr_exports);
886
+ })();
887
+ window.Transportr = Transportr.default;