@d1g1tal/transportr 0.1.3 → 0.1.5

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.
@@ -80,6 +80,20 @@ var Transportr = (() => {
80
80
  };
81
81
  var object_merge_default = _objectMerge;
82
82
 
83
+ // node_modules/@d1g1tal/chrysalis/src/esm/is-iterable.js
84
+ var _isIterable = (input) => !!input?.[Symbol.iterator];
85
+ var is_iterable_default = _isIterable;
86
+
87
+ // node_modules/@d1g1tal/chrysalis/src/esm/object-construct.js
88
+ var _construct = (value, args = []) => {
89
+ try {
90
+ return Reflect.construct(value, args);
91
+ } catch (error) {
92
+ return value(...args);
93
+ }
94
+ };
95
+ var object_construct_default = _construct;
96
+
83
97
  // node_modules/@d1g1tal/collections/src/set-multi-map.js
84
98
  var SetMultiMap = class extends Map {
85
99
  /**
@@ -512,10 +526,10 @@ var Transportr = (() => {
512
526
  #responseStatus;
513
527
  /**
514
528
  * @param {string} [message] The error message.
515
- * @param {HttpErrorOptions} [options] The error options.
516
- * @param {Error} [options.cause] The cause of the error.
517
- * @param {ResponseStatus} [options.status] The response status.
518
- * @param {ResponseBody} [options.entity] The error entity from the server, if any.
529
+ * @param {HttpErrorOptions} [httpErrorOptions] The http error options.
530
+ * @param {any} [httpErrorOptions.cause] The cause of the error.
531
+ * @param {ResponseStatus} [httpErrorOptions.status] The response status.
532
+ * @param {ResponseBody} [httpErrorOptions.entity] The error entity from the server, if any.
519
533
  */
520
534
  constructor(message, { cause, status, entity }) {
521
535
  super(message, { cause });
@@ -546,8 +560,19 @@ var Transportr = (() => {
546
560
  get statusText() {
547
561
  return this.#responseStatus?.text;
548
562
  }
563
+ get name() {
564
+ return "HttpError";
565
+ }
566
+ /**
567
+ * A String value that is used in the creation of the default string
568
+ * description of an object. Called by the built-in method {@link Object.prototype.toString}.
569
+ *
570
+ * @returns {string} The default string description of this object.
571
+ */
572
+ get [Symbol.toStringTag]() {
573
+ return "HttpError";
574
+ }
549
575
  };
550
- var http_error_default = HttpError;
551
576
 
552
577
  // src/http-media-type.js
553
578
  var HttpMediaType = {
@@ -679,6 +704,10 @@ var Transportr = (() => {
679
704
  WOFF: "font/woff",
680
705
  /** Web Open Font Format */
681
706
  WOFF2: "font/woff2",
707
+ /** Form - Encoded */
708
+ FORM: "application/x-www-form-urlencoded",
709
+ /** Multipart FormData */
710
+ MULTIPART_FORM_DATA: "multipart/form-data",
682
711
  /** XHTML - The Extensible HyperText Markup Language */
683
712
  XHTML: "application/xhtml+xml",
684
713
  /** Microsoft Excel Document */
@@ -1655,6 +1684,26 @@ var Transportr = (() => {
1655
1684
  get text() {
1656
1685
  return this.#text;
1657
1686
  }
1687
+ /**
1688
+ * A String value that is used in the creation of the default string
1689
+ * description of an object. Called by the built-in method {@link Object.prototype.toString}.
1690
+ *
1691
+ * @override
1692
+ * @returns {string} The default string description of this object.
1693
+ */
1694
+ get [Symbol.toStringTag]() {
1695
+ return "ResponseStatus";
1696
+ }
1697
+ /**
1698
+ * tostring method for the class.
1699
+ *
1700
+ * @override
1701
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/toString|Object.prototype.toString}
1702
+ * @returns {string} The status code and status text.
1703
+ */
1704
+ toString() {
1705
+ return `${this.#code} ${this.#text}`;
1706
+ }
1658
1707
  };
1659
1708
 
1660
1709
  // src/transportr.js
@@ -1677,18 +1726,18 @@ var Transportr = (() => {
1677
1726
  var _handleImage = async (response) => URL.createObjectURL(await response.blob());
1678
1727
  var _handleBuffer = async (response) => await response.arrayBuffer();
1679
1728
  var _handleReadableStream = async (response) => response.body;
1680
- var _handleXml = async (response) => new DOMParser().parseFromString(await response.text(), Transportr.MediaType.XML.essence);
1681
- var _handleHtml = async (response) => new DOMParser().parseFromString(await response.text(), Transportr.MediaType.HTML.essence);
1729
+ var _handleXml = async (response) => new DOMParser().parseFromString(await response.text(), http_media_type_default.XML.essence);
1730
+ var _handleHtml = async (response) => new DOMParser().parseFromString(await response.text(), http_media_type_default.HTML.essence);
1682
1731
  var _handleHtmlFragment = async (response) => document.createRange().createContextualFragment(await response.text());
1683
- var _baseUrl, _options, _contentTypeHandlers, _defaultRequestOptions, _get, get_fn, _createUrl, createUrl_fn, _request, request_fn, _processResponse, processResponse_fn, _needsSerialization, needsSerialization_fn;
1732
+ var _baseUrl, _options, _contentTypeHandlers, _defaultRequestOptions, _get, get_fn, _request, request_fn, _processResponse, processResponse_fn, _createUrl, createUrl_fn, _needsSerialization, needsSerialization_fn, _convertRequestOptions, convertRequestOptions_fn;
1684
1733
  var _Transportr = class {
1685
1734
  /**
1686
1735
  * Create a new Transportr instance with the provided location or origin and context path.
1687
1736
  *
1688
- * @param {URL | string | RequestOptions} [url = location.origin] The URL for {@link fetch} requests.
1689
- * @param {RequestOptions} [options = Transportr.#defaultRequestOptions] The default {@link RequestOptions} for this instance.
1737
+ * @param {URL | string | RequestOptions} [url=location.origin] The URL for {@link fetch} requests.
1738
+ * @param {RequestOptions} [options=Transportr.#defaultRequestOptions] The default {@link RequestOptions} for this instance.
1690
1739
  */
1691
- constructor(url = location.origin, options = __privateGet(_Transportr, _defaultRequestOptions)) {
1740
+ constructor(url = location.origin, options = {}) {
1692
1741
  /**
1693
1742
  * Makes a GET request to the given path, using the given options, and then calls the
1694
1743
  * given response handler with the response.
@@ -1696,8 +1745,9 @@ var Transportr = (() => {
1696
1745
  * @private
1697
1746
  * @async
1698
1747
  * @param {string} path - The path to the endpoint you want to call.
1699
- * @param {RequestOptions} options - The options for the request.
1700
- * @param {ResponseHandler<ResponseBody>} responseHandler - A function that will be called with the response object.
1748
+ * @param {RequestOptions} [userOptions] - The options passed to the public function to use for the request.
1749
+ * @param {RequestOptions} [options] - The options for the request.
1750
+ * @param {ResponseHandler<ResponseBody>} [responseHandler] - A function that will be called with the response object.
1701
1751
  * @returns {Promise<ResponseBody>} The result of the #request method.
1702
1752
  */
1703
1753
  __privateAdd(this, _get);
@@ -1708,7 +1758,8 @@ var Transportr = (() => {
1708
1758
  * @private
1709
1759
  * @async
1710
1760
  * @param {string} path - The path to the resource you want to access.
1711
- * @param {RequestOptions} options - The options to use for the request.
1761
+ * @param {RequestOptions} [userOptions={}] - The options passed to the public function to use for the request.
1762
+ * @param {RequestOptions} [options={}] - The options to use for the request.
1712
1763
  * @param {ResponseHandler<ResponseBody>} [responseHandler] - A function that will be called with the response body as a parameter. This
1713
1764
  * is useful if you want to do something with the response body before returning it.
1714
1765
  * @returns {Promise<ResponseBody>} The response from the API call.
@@ -1718,6 +1769,7 @@ var Transportr = (() => {
1718
1769
  __privateAdd(this, _baseUrl, void 0);
1719
1770
  /** @type {RequestOptions} */
1720
1771
  __privateAdd(this, _options, void 0);
1772
+ var _a;
1721
1773
  const type = object_type_default(url);
1722
1774
  if (type == Object) {
1723
1775
  options = url;
@@ -1726,7 +1778,7 @@ var Transportr = (() => {
1726
1778
  url = url.startsWith("/") ? new URL(url, location.origin) : new URL(url);
1727
1779
  }
1728
1780
  __privateSet(this, _baseUrl, url);
1729
- __privateSet(this, _options, options);
1781
+ __privateSet(this, _options, object_merge_default(__privateGet(_Transportr, _defaultRequestOptions), __privateMethod(_a = _Transportr, _convertRequestOptions, convertRequestOptions_fn).call(_a, options, { headers: Object, searchParams: Object })));
1730
1782
  }
1731
1783
  /**
1732
1784
  * It returns the base {@link URL} for the API.
@@ -1742,23 +1794,23 @@ var Transportr = (() => {
1742
1794
  *
1743
1795
  * @async
1744
1796
  * @param {string} path - The path to the resource you want to get.
1745
- * @param {RequestOptions} [options={}] - The options for the request.
1797
+ * @param {RequestOptions} [options] - The options for the request.
1746
1798
  * @returns {Promise<ResponseBody>} A promise that resolves to the response of the request.
1747
1799
  */
1748
- async get(path, options = {}) {
1749
- return __privateMethod(this, _request, request_fn).call(this, path, object_merge_default(options, { method: http_request_methods_default.GET }));
1800
+ async get(path, options) {
1801
+ return __privateMethod(this, _get, get_fn).call(this, path, options);
1750
1802
  }
1751
1803
  /**
1752
1804
  * This function makes a POST request to the given path with the given body and options.
1753
1805
  *
1754
1806
  * @async
1755
1807
  * @param {string} path - The path to the endpoint you want to call.
1756
- * @param {Object} body - The body of the request.
1757
- * @param {RequestOptions} [options={}] - The options for the request.
1808
+ * @param {RequestBody} body - The body of the request.
1809
+ * @param {RequestOptions} [options] - The options for the request.
1758
1810
  * @returns {Promise<ResponseBody>} A promise that resolves to the response body.
1759
1811
  */
1760
- async post(path, body, options = {}) {
1761
- return __privateMethod(this, _request, request_fn).call(this, path, object_merge_default(options, { body, method: http_request_methods_default.POST }));
1812
+ async post(path, body, options) {
1813
+ return __privateMethod(this, _request, request_fn).call(this, path, options, { body, method: http_request_methods_default.POST });
1762
1814
  }
1763
1815
  /**
1764
1816
  * This function returns a promise that resolves to the result of a request to the specified path with
@@ -1766,65 +1818,65 @@ var Transportr = (() => {
1766
1818
  *
1767
1819
  * @async
1768
1820
  * @param {string} path - The path to the endpoint you want to call.
1769
- * @param {RequestOptions} [options={}] - The options for the request.
1821
+ * @param {RequestOptions} [options] - The options for the request.
1770
1822
  * @returns {Promise<ResponseBody>} The return value of the #request method.
1771
1823
  */
1772
- async put(path, options = {}) {
1773
- return __privateMethod(this, _request, request_fn).call(this, path, object_merge_default(options, { method: http_request_methods_default.PUT }));
1824
+ async put(path, options) {
1825
+ return __privateMethod(this, _request, request_fn).call(this, path, options, { method: http_request_methods_default.PUT });
1774
1826
  }
1775
1827
  /**
1776
1828
  * It takes a path and options, and returns a request with the method set to PATCH.
1777
1829
  *
1778
1830
  * @async
1779
1831
  * @param {string} path - The path to the endpoint you want to hit.
1780
- * @param {RequestOptions} [options={}] - The options for the request.
1832
+ * @param {RequestOptions} [options] - The options for the request.
1781
1833
  * @returns {Promise<ResponseBody>} A promise that resolves to the response of the request.
1782
1834
  */
1783
- async patch(path, options = {}) {
1784
- return __privateMethod(this, _request, request_fn).call(this, path, object_merge_default(options, { method: http_request_methods_default.PATCH }));
1835
+ async patch(path, options) {
1836
+ return __privateMethod(this, _request, request_fn).call(this, path, options, { method: http_request_methods_default.PATCH });
1785
1837
  }
1786
1838
  /**
1787
1839
  * It takes a path and options, and returns a request with the method set to DELETE.
1788
1840
  *
1789
1841
  * @async
1790
1842
  * @param {string} path - The path to the resource you want to access.
1791
- * @param {RequestOptions} [options={}] - The options for the request.
1843
+ * @param {RequestOptions} [options] - The options for the request.
1792
1844
  * @returns {Promise<ResponseBody>} The result of the request.
1793
1845
  */
1794
- async delete(path, options = {}) {
1795
- return __privateMethod(this, _request, request_fn).call(this, path, object_merge_default(options, { method: http_request_methods_default.DELETE }));
1846
+ async delete(path, options) {
1847
+ return __privateMethod(this, _request, request_fn).call(this, path, options, { method: http_request_methods_default.DELETE });
1796
1848
  }
1797
1849
  /**
1798
1850
  * Returns the response headers of a request to the given path.
1799
1851
  *
1800
1852
  * @async
1801
1853
  * @param {string} path - The path to the resource you want to access.
1802
- * @param {RequestOptions} [options={}] - The options for the request.
1854
+ * @param {RequestOptions} [options] - The options for the request.
1803
1855
  * @returns {Promise<ResponseBody>} A promise that resolves to the response object.
1804
1856
  */
1805
- async head(path, options = {}) {
1806
- return __privateMethod(this, _request, request_fn).call(this, path, object_merge_default(options, { method: http_request_methods_default.HEAD }));
1857
+ async head(path, options) {
1858
+ return __privateMethod(this, _request, request_fn).call(this, path, options, { method: http_request_methods_default.HEAD });
1807
1859
  }
1808
1860
  /**
1809
1861
  * It takes a path and options, and returns a request with the method set to OPTIONS.
1810
1862
  *
1811
1863
  * @async
1812
1864
  * @param {string} path - The path to the resource.
1813
- * @param {RequestOptions} [options={}] - The options for the request.
1865
+ * @param {RequestOptions} [options] - The options for the request.
1814
1866
  * @returns {Promise<ResponseBody>} The return value of the #request method.
1815
1867
  */
1816
- async options(path, options = {}) {
1817
- return __privateMethod(this, _request, request_fn).call(this, path, object_merge_default(options, { method: http_request_methods_default.OPTIONS }));
1868
+ async options(path, options) {
1869
+ return __privateMethod(this, _request, request_fn).call(this, path, options, { method: http_request_methods_default.OPTIONS });
1818
1870
  }
1819
1871
  /**
1820
1872
  * It takes a path and options, and makes a request to the server.
1821
1873
  *
1822
1874
  * @async
1823
1875
  * @param {string} path - The path to the endpoint you want to hit.
1824
- * @param {RequestOptions} [options={}] - The options for the request.
1876
+ * @param {RequestOptions} [options] - The options for the request.
1825
1877
  * @returns {Promise<ResponseBody>} The return value of the function is the return value of the function that is passed to the `then` method of the promise returned by the `fetch` method.
1826
1878
  */
1827
- async request(path, options = {}) {
1879
+ async request(path, options) {
1828
1880
  return __privateMethod(this, _request, request_fn).call(this, path, options);
1829
1881
  }
1830
1882
  /**
@@ -1832,43 +1884,35 @@ var Transportr = (() => {
1832
1884
  *
1833
1885
  * @async
1834
1886
  * @param {string} path - The path to the resource.
1835
- * @param {RequestOptions} [options={}] - The options object to pass to the request.
1887
+ * @param {RequestOptions} [options] - The options object to pass to the request.
1836
1888
  * @returns {Promise<JsonObject>} A promise that resolves to the response body as a JSON object.
1837
1889
  */
1838
- async getJson(path, options = {}) {
1839
- return __privateMethod(this, _get, get_fn).call(this, path, object_merge_default(options, { headers: { [http_request_headers_default.ACCEPT]: _Transportr.MediaType.JSON } }), _handleJson);
1890
+ async getJson(path, options) {
1891
+ return __privateMethod(this, _get, get_fn).call(this, path, options, { headers: { [http_request_headers_default.ACCEPT]: http_media_type_default.JSON } }, _handleJson);
1840
1892
  }
1841
1893
  /**
1842
1894
  * It gets the XML representation of the resource at the given path.
1843
1895
  *
1844
1896
  * @async
1845
1897
  * @param {string} path - The path to the resource you want to get.
1846
- * @param {RequestOptions} [options={}] - The options for the request.
1898
+ * @param {RequestOptions} [options] - The options for the request.
1847
1899
  * @returns {Promise<Document>} The result of the function call to #get.
1848
1900
  */
1849
- async getXml(path, options = {}) {
1850
- return await __privateMethod(this, _get, get_fn).call(this, path, object_merge_default(options, { headers: { [http_request_headers_default.ACCEPT]: _Transportr.MediaType.XML } }), _handleXml);
1901
+ async getXml(path, options) {
1902
+ return __privateMethod(this, _get, get_fn).call(this, path, options, { headers: { [http_request_headers_default.ACCEPT]: http_media_type_default.XML } }, _handleXml);
1851
1903
  }
1852
- /**
1853
- * TODO - Add way to return portion of the retrieved HTML using a selector. Like jQuery.
1854
- *
1855
- * @async
1856
- * @param {string} path
1857
- * @param {RequestOptions} [options = {}]
1858
- * @returns {Promise<Document>}
1859
- */
1860
1904
  /**
1861
1905
  * Get the HTML content of the specified path.
1862
1906
  *
1863
1907
  * @todo Add way to return portion of the retrieved HTML using a selector. Like jQuery.
1864
1908
  * @async
1865
1909
  * @param {string} path - The path to the resource.
1866
- * @param {RequestOptions} [options={}] - The options for the request.
1910
+ * @param {RequestOptions} [options] - The options for the request.
1867
1911
  * @returns {Promise<Document>} The return value of the function is the return value of the function passed to the `then`
1868
1912
  * method of the promise returned by the `#get` method.
1869
1913
  */
1870
- async getHtml(path, options = {}) {
1871
- return __privateMethod(this, _get, get_fn).call(this, path, object_merge_default(options, { headers: { [http_request_headers_default.ACCEPT]: http_media_type_default.HTML } }), _handleHtml);
1914
+ async getHtml(path, options) {
1915
+ return __privateMethod(this, _get, get_fn).call(this, path, options, { headers: { [http_request_headers_default.ACCEPT]: http_media_type_default.HTML } }, _handleHtml);
1872
1916
  }
1873
1917
  /**
1874
1918
  * It returns a promise that resolves to the HTML fragment at the given path.
@@ -1876,11 +1920,11 @@ var Transportr = (() => {
1876
1920
  * @todo - Add way to return portion of the retrieved HTML using a selector. Like jQuery.
1877
1921
  * @async
1878
1922
  * @param {string} path - The path to the resource.
1879
- * @param {RequestOptions} [options={}] - The options for the request.
1923
+ * @param {RequestOptions} [options] - The options for the request.
1880
1924
  * @returns {Promise<DocumentFragment>} A promise that resolves to an HTML fragment.
1881
1925
  */
1882
- async getHtmlFragment(path, options = {}) {
1883
- return __privateMethod(this, _get, get_fn).call(this, path, object_merge_default(options, { headers: { [http_request_headers_default.ACCEPT]: http_media_type_default.HTML } }), _handleHtmlFragment);
1926
+ async getHtmlFragment(path, options) {
1927
+ return __privateMethod(this, _get, get_fn).call(this, path, options, { headers: { [http_request_headers_default.ACCEPT]: http_media_type_default.HTML } }, _handleHtmlFragment);
1884
1928
  }
1885
1929
  /**
1886
1930
  * It gets a script from the server, and appends the script to the {@link Document} {@link HTMLHeadElement}
@@ -1888,66 +1932,75 @@ var Transportr = (() => {
1888
1932
  *
1889
1933
  * @async
1890
1934
  * @param {string} path - The path to the script.
1891
- * @param {RequestOptions} [options={}] - The options for the request.
1935
+ * @param {RequestOptions} [options] - The options for the request.
1892
1936
  * @returns {Promise<void>} A promise that has been resolved.
1893
1937
  */
1894
- async getScript(path, options = {}) {
1895
- 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 } }), _handleScript);
1938
+ async getScript(path, options) {
1939
+ return __privateMethod(this, _get, get_fn).call(this, path, options, { headers: { [http_request_headers_default.ACCEPT]: http_media_type_default.JAVA_SCRIPT } }, _handleScript);
1896
1940
  }
1897
1941
  /**
1898
1942
  * Gets a stylesheet from the server, and adds it as a {@link Blob} {@link URL}.
1899
1943
  *
1900
1944
  * @async
1901
1945
  * @param {string} path - The path to the stylesheet.
1902
- * @param {RequestOptions} [options={}] - The options for the request.
1946
+ * @param {RequestOptions} [options] - The options for the request.
1903
1947
  * @returns {Promise<void>} A promise that has been resolved.
1904
1948
  */
1905
- async getStylesheet(path, options = {}) {
1906
- return __privateMethod(this, _get, get_fn).call(this, path, object_merge_default(options, { headers: { [http_request_headers_default.ACCEPT]: http_media_type_default.CSS } }), _handleCss);
1949
+ async getStylesheet(path, options) {
1950
+ return __privateMethod(this, _get, get_fn).call(this, path, options, { headers: { [http_request_headers_default.ACCEPT]: http_media_type_default.CSS } }, _handleCss);
1907
1951
  }
1908
1952
  /**
1909
1953
  * It returns a blob from the specified path.
1910
1954
  *
1911
1955
  * @async
1912
1956
  * @param {string} path - The path to the resource.
1913
- * @param {RequestOptions} [options={}] - The options for the request.
1957
+ * @param {RequestOptions} [options] - The options for the request.
1914
1958
  * @returns {Promise<Blob>} A promise that resolves to a blob.
1915
1959
  */
1916
- async getBlob(path, options = {}) {
1917
- 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);
1960
+ async getBlob(path, options) {
1961
+ return __privateMethod(this, _get, get_fn).call(this, path, options, { headers: { [http_request_headers_default.ACCEPT]: http_media_type_default.BIN } }, _handleBlob);
1918
1962
  }
1919
1963
  /**
1920
1964
  * It returns a promise that resolves to an object URL.
1921
1965
  *
1922
1966
  * @async
1923
1967
  * @param {string} path - The path to the resource.
1924
- * @param {RequestOptions} [options={}] - The options for the request.
1968
+ * @param {RequestOptions} [options] - The options for the request.
1925
1969
  * @returns {Promise<string>} A promise that resolves to an object URL.
1926
1970
  */
1927
- async getImage(path, options = {}) {
1928
- return await __privateMethod(this, _get, get_fn).call(this, path, object_merge_default(options, { headers: { [http_request_headers_default.ACCEPT]: "image/*" } }), _handleImage);
1971
+ async getImage(path, options) {
1972
+ return __privateMethod(this, _get, get_fn).call(this, path, options, { headers: { [http_request_headers_default.ACCEPT]: "image/*" } }, _handleImage);
1929
1973
  }
1930
1974
  /**
1931
1975
  * It gets a buffer from the specified path
1932
1976
  *
1933
1977
  * @async
1934
1978
  * @param {string} path - The path to the resource.
1935
- * @param {RequestOptions} [options={}] - The options for the request.
1979
+ * @param {RequestOptions} [options] - The options for the request.
1936
1980
  * @returns {Promise<ArrayBuffer>} A promise that resolves to a buffer.
1937
1981
  */
1938
- async getBuffer(path, options = {}) {
1939
- 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);
1982
+ async getBuffer(path, options) {
1983
+ return __privateMethod(this, _get, get_fn).call(this, path, options, { headers: { [http_request_headers_default.ACCEPT]: http_media_type_default.BIN } }, _handleBuffer);
1940
1984
  }
1941
1985
  /**
1942
1986
  * It returns a readable stream of the response body from the specified path.
1943
1987
  *
1944
1988
  * @async
1945
1989
  * @param {string} path - The path to the resource.
1946
- * @param {RequestOptions} [options={}] - The options for the request.
1990
+ * @param {RequestOptions} [options] - The options for the request.
1947
1991
  * @returns {Promise<ReadableStream<Uint8Array>>} A readable stream.
1948
1992
  */
1949
- async getStream(path, options = {}) {
1950
- 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);
1993
+ async getStream(path, options) {
1994
+ return __privateMethod(this, _get, get_fn).call(this, path, options, { headers: { [http_request_headers_default.ACCEPT]: http_media_type_default.BIN } }, _handleReadableStream);
1995
+ }
1996
+ /**
1997
+ * A String value that is used in the creation of the default string
1998
+ * description of an object. Called by the built-in method {@link Object.prototype.toString}.
1999
+ *
2000
+ * @returns {string} The default string description of this object.
2001
+ */
2002
+ get [Symbol.toStringTag]() {
2003
+ return "Transportr";
1951
2004
  }
1952
2005
  };
1953
2006
  var Transportr = _Transportr;
@@ -1956,40 +2009,28 @@ var Transportr = (() => {
1956
2009
  _contentTypeHandlers = new WeakMap();
1957
2010
  _defaultRequestOptions = new WeakMap();
1958
2011
  _get = new WeakSet();
1959
- get_fn = async function(path, options, responseHandler) {
1960
- return __privateMethod(this, _request, request_fn).call(this, path, object_merge_default(options, { method: _Transportr.Method.GET }), responseHandler);
1961
- };
1962
- _createUrl = new WeakSet();
1963
- createUrl_fn = function(url, path, searchParams = new URLSearchParams()) {
1964
- url = path.startsWith("/") ? new URL(`${url.pathname.replace(endsWithSlashRegEx, "")}${path}`, url.origin) : new URL(path);
1965
- for (const [name, value] of searchParams) {
1966
- url.searchParams.append(name, value);
1967
- }
1968
- return url;
2012
+ get_fn = async function(path, userOptions, options, responseHandler) {
2013
+ return __privateMethod(this, _request, request_fn).call(this, path, userOptions, options, responseHandler);
1969
2014
  };
1970
2015
  _request = new WeakSet();
1971
- request_fn = async function(path, options, responseHandler) {
1972
- var _a, _b, _c, _d;
1973
- const requestOptions = object_merge_default(__privateGet(this, _options), options);
1974
- const headers = new Headers(requestOptions.headers);
2016
+ request_fn = async function(path, userOptions = {}, options = {}, responseHandler) {
2017
+ var _a, _b, _c, _d, _e;
2018
+ const requestOptions = __privateMethod(_a = _Transportr, _convertRequestOptions, convertRequestOptions_fn).call(_a, object_merge_default(__privateGet(this, _options), userOptions, options), { headers: Headers, searchParams: URLSearchParams });
1975
2019
  const errorMessage = `An error has occurred with your Request: ${path}`;
1976
- if (__privateMethod(_a = _Transportr, _needsSerialization, needsSerialization_fn).call(_a, options.method, headers)) {
2020
+ if (__privateMethod(_b = _Transportr, _needsSerialization, needsSerialization_fn).call(_b, requestOptions.method, requestOptions.headers.get(http_request_headers_default.CONTENT_TYPE))) {
1977
2021
  requestOptions.body = JSON.stringify(requestOptions.body);
1978
2022
  }
1979
- if (requestOptions.searchParams && !(requestOptions.searchParams instanceof URLSearchParams)) {
1980
- requestOptions.searchParams = new URLSearchParams(requestOptions.searchParams);
1981
- }
1982
2023
  let response;
1983
2024
  try {
1984
- response = await fetch(__privateMethod(_b = _Transportr, _createUrl, createUrl_fn).call(_b, __privateGet(this, _baseUrl), path, requestOptions.searchParams), requestOptions);
2025
+ response = await fetch(__privateMethod(_c = _Transportr, _createUrl, createUrl_fn).call(_c, __privateGet(this, _baseUrl), path, requestOptions.searchParams), requestOptions);
1985
2026
  } catch (error) {
1986
2027
  console.error(errorMessage, error);
1987
- throw new http_error_default(errorMessage, { cause: error, status: new ResponseStatus(response.status, response.statusText) });
2028
+ throw new HttpError(errorMessage, { cause: error, status: new ResponseStatus(response.status, response.statusText) });
1988
2029
  }
1989
2030
  if (!response.ok) {
1990
- throw new http_error_default(errorMessage, { status: new ResponseStatus(response.status, response.statusText), entity: await __privateMethod(_c = _Transportr, _processResponse, processResponse_fn).call(_c, response) });
2031
+ throw new HttpError(errorMessage, { status: new ResponseStatus(response.status, response.statusText), entity: await __privateMethod(_d = _Transportr, _processResponse, processResponse_fn).call(_d, response) });
1991
2032
  }
1992
- return await __privateMethod(_d = _Transportr, _processResponse, processResponse_fn).call(_d, response, responseHandler);
2033
+ return await __privateMethod(_e = _Transportr, _processResponse, processResponse_fn).call(_e, response, responseHandler);
1993
2034
  };
1994
2035
  _processResponse = new WeakSet();
1995
2036
  processResponse_fn = async function(response, handler) {
@@ -2009,13 +2050,42 @@ var Transportr = (() => {
2009
2050
  } catch (error) {
2010
2051
  const errorMessage = "Unable to process response.";
2011
2052
  console.error(errorMessage, error, response);
2012
- throw new http_error_default(errorMessage, { cause: error });
2053
+ throw new HttpError(errorMessage, { cause: error });
2013
2054
  }
2014
2055
  };
2056
+ _createUrl = new WeakSet();
2057
+ createUrl_fn = function(url, path, searchParams = new URLSearchParams()) {
2058
+ url = path.startsWith("/") ? new URL(`${url.pathname.replace(endsWithSlashRegEx, "")}${path}`, url.origin) : new URL(path);
2059
+ searchParams.forEach((value, key) => url.searchParams.append(key, value));
2060
+ return url;
2061
+ };
2015
2062
  _needsSerialization = new WeakSet();
2016
- needsSerialization_fn = function(method, headers) {
2017
- return [http_request_methods_default.POST, http_request_methods_default.PUT, http_request_methods_default.PATCH].includes(method) && headers.get(_Transportr.RequestHeader.CONTENT_TYPE) == _Transportr.MediaType.JSON;
2063
+ needsSerialization_fn = function(method, contentType) {
2064
+ return contentType == http_media_type_default.JSON && [http_request_methods_default.POST, http_request_methods_default.PUT, http_request_methods_default.PATCH].includes(method);
2065
+ };
2066
+ _convertRequestOptions = new WeakSet();
2067
+ convertRequestOptions_fn = function(options, typeConversionMap) {
2068
+ let object;
2069
+ for (const [property, type, option = options[property]] of Object.entries(typeConversionMap)) {
2070
+ if (option) {
2071
+ object = is_iterable_default(option) ? Object.fromEntries(option.entries()) : option;
2072
+ options[property] = type == Object ? object : object_construct_default(type, [object]);
2073
+ }
2074
+ }
2075
+ return options;
2018
2076
  };
2077
+ /**
2078
+ * It takes a response and a handler, and if the handler is not defined, it tries to find a handler
2079
+ * based on the response's content type
2080
+ *
2081
+ * @private
2082
+ * @static
2083
+ * @async
2084
+ * @param {Response} response - The response object returned by the fetch API.
2085
+ * @param {ResponseHandler<ResponseBody>} [handler] - The handler to use for processing the response.
2086
+ * @returns {Promise<ResponseBody>} The response is being returned.
2087
+ */
2088
+ __privateAdd(Transportr, _processResponse);
2019
2089
  /**
2020
2090
  * It takes a URL, a path, and a set of search parameters, and returns a new URL with the path and
2021
2091
  * search parameters applied.
@@ -2029,18 +2099,6 @@ var Transportr = (() => {
2029
2099
  * appended to the end of the pathname.
2030
2100
  */
2031
2101
  __privateAdd(Transportr, _createUrl);
2032
- /**
2033
- * It takes a response and a handler, and if the handler is not defined, it tries to find a handler
2034
- * based on the response's content type
2035
- *
2036
- * @private
2037
- * @static
2038
- * @async
2039
- * @param {Response} response - The response object returned by the fetch API.
2040
- * @param {ResponseHandler<ResponseBody>} [handler] - The handler to use for processing the response.
2041
- * @returns {Promise<ResponseBody>} The response is being returned.
2042
- */
2043
- __privateAdd(Transportr, _processResponse);
2044
2102
  /**
2045
2103
  * If the request method is POST, PUT, or PATCH, and the content type is JSON, then the request body
2046
2104
  * needs to be serialized.
@@ -2048,10 +2106,17 @@ var Transportr = (() => {
2048
2106
  * @private
2049
2107
  * @static
2050
2108
  * @param {RequestMethod} method - The HTTP request method.
2051
- * @param {RequestHeaders} headers - The headers of the request.
2109
+ * @param {HttpMediaType} contentType - The headers of the request.
2052
2110
  * @returns {boolean} `true` if the request body needs to be serialized, `false` otherwise.
2053
2111
  */
2054
2112
  __privateAdd(Transportr, _needsSerialization);
2113
+ /**
2114
+ *
2115
+ * @param {RequestOptions} options - The options passed to the public function to use for the request.
2116
+ * @param {Object<string, Type>} typeConversionMap - A map of properties to convert to the specified type.
2117
+ * @returns {RequestOptions} The options to use for the request.
2118
+ */
2119
+ __privateAdd(Transportr, _convertRequestOptions);
2055
2120
  /**
2056
2121
  * @private
2057
2122
  * @static
@@ -2069,69 +2134,70 @@ var Transportr = (() => {
2069
2134
  ]));
2070
2135
  /**
2071
2136
  * @static
2072
- * @constant {Object<string, RequestMethod>}
2137
+ * @constant {Object<string, HttpRequestMethod>}
2073
2138
  */
2074
2139
  __publicField(Transportr, "Method", Object.freeze(http_request_methods_default));
2075
2140
  /**
2076
2141
  * @static
2077
- * @constant {Object<string, string>}
2142
+ * @constant {Object<string, HttpMediaType>}
2078
2143
  */
2079
- __publicField(Transportr, "MediaType", http_media_type_default);
2144
+ __publicField(Transportr, "MediaType", Object.freeze(http_media_type_default));
2080
2145
  /**
2081
2146
  * @static
2082
- * @constant {Object<string, string>}
2147
+ * @see {@link HttpRequestHeader}
2148
+ * @constant {Object<string, HttpRequestHeader>}
2083
2149
  */
2084
- __publicField(Transportr, "RequestHeader", http_request_headers_default);
2150
+ __publicField(Transportr, "RequestHeader", Object.freeze(http_request_headers_default));
2085
2151
  /**
2086
2152
  * @static
2087
- * @constant {Object<string, string>}
2153
+ * @constant {Object<string, HttpResponseHeader>}
2088
2154
  */
2089
2155
  __publicField(Transportr, "ResponseHeader", Object.freeze(http_response_headers_default));
2090
2156
  /**
2091
2157
  * @static
2092
2158
  * @constant {Object<string, RequestCache>}
2093
2159
  */
2094
- __publicField(Transportr, "CachingPolicy", {
2160
+ __publicField(Transportr, "CachingPolicy", Object.freeze({
2095
2161
  DEFAULT: "default",
2096
2162
  FORCE_CACHE: "force-cache",
2097
2163
  NO_CACHE: "no-cache",
2098
2164
  NO_STORE: "no-store",
2099
2165
  ONLY_IF_CACHED: "only-if-cached",
2100
2166
  RELOAD: "reload"
2101
- });
2167
+ }));
2102
2168
  /**
2103
2169
  * @static
2104
2170
  * @constant {Object<string, RequestCredentials>}
2105
2171
  */
2106
- __publicField(Transportr, "CredentialsPolicy", {
2172
+ __publicField(Transportr, "CredentialsPolicy", Object.freeze({
2107
2173
  INCLUDE: "include",
2108
2174
  OMIT: "omit",
2109
2175
  SAME_ORIGIN: "same-origin"
2110
- });
2176
+ }));
2111
2177
  /**
2112
2178
  * @static
2113
2179
  * @constant {Object<string, RequestMode>}
2114
2180
  */
2115
- __publicField(Transportr, "RequestMode", {
2181
+ __publicField(Transportr, "RequestMode", Object.freeze({
2116
2182
  CORS: "cors",
2117
2183
  NAVIGATE: "navigate",
2118
2184
  NO_CORS: "no-cors",
2119
2185
  SAME_ORIGIN: "same-origin"
2120
- });
2186
+ }));
2121
2187
  /**
2122
2188
  * @static
2123
2189
  * @constant {Object<string, RequestRedirect>}
2124
2190
  */
2125
- __publicField(Transportr, "RedirectPolicy", {
2191
+ __publicField(Transportr, "RedirectPolicy", Object.freeze({
2126
2192
  ERROR: "error",
2127
2193
  FOLLOW: "follow",
2128
2194
  MANUAL: "manual"
2129
- });
2195
+ }));
2130
2196
  /**
2131
2197
  * @static
2132
2198
  * @constant {Object<string, ReferrerPolicy>}
2133
2199
  */
2134
- __publicField(Transportr, "ReferrerPolicy", {
2200
+ __publicField(Transportr, "ReferrerPolicy", Object.freeze({
2135
2201
  NO_REFERRER: "no-referrer",
2136
2202
  NO_REFERRER_WHEN_DOWNGRADE: "no-referrer-when-downgrade",
2137
2203
  ORIGIN: "origin",
@@ -2140,26 +2206,28 @@ var Transportr = (() => {
2140
2206
  STRICT_ORIGIN: "strict-origin",
2141
2207
  STRICT_ORIGIN_WHEN_CROSS_ORIGIN: "strict-origin-when-cross-origin",
2142
2208
  UNSAFE_URL: "unsafe-url"
2143
- });
2209
+ }));
2144
2210
  /**
2211
+ * @private
2145
2212
  * @static
2146
2213
  * @type {RequestOptions}
2147
2214
  */
2148
- __privateAdd(Transportr, _defaultRequestOptions, {
2215
+ __privateAdd(Transportr, _defaultRequestOptions, Object.freeze({
2149
2216
  body: null,
2150
2217
  cache: _Transportr.CachingPolicy.NO_STORE,
2151
2218
  credentials: _Transportr.CredentialsPolicy.SAME_ORIGIN,
2152
2219
  headers: {},
2220
+ searchParams: {},
2153
2221
  integrity: void 0,
2154
2222
  keepalive: void 0,
2155
- method: void 0,
2223
+ method: http_request_methods_default.GET,
2156
2224
  mode: _Transportr.RequestMode.CORS,
2157
2225
  redirect: _Transportr.RedirectPolicy.FOLLOW,
2158
2226
  referrer: "about:client",
2159
2227
  referrerPolicy: _Transportr.ReferrerPolicy.STRICT_ORIGIN_WHEN_CROSS_ORIGIN,
2160
2228
  signal: null,
2161
2229
  window: null
2162
- });
2230
+ }));
2163
2231
  return __toCommonJS(transportr_exports);
2164
2232
  })();
2165
2233
  window.Transportr = Transportr.default;