@modern-js/create-request 2.35.0 → 2.35.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/browser.js +2 -2
- package/dist/cjs/handleRes.js +4 -5
- package/dist/cjs/node.js +4 -4
- package/dist/esm/browser.js +2 -2
- package/dist/esm/handleRes.js +5 -5
- package/dist/esm/node.js +3 -3
- package/dist/esm-node/browser.js +2 -2
- package/dist/esm-node/handleRes.js +4 -5
- package/dist/esm-node/node.js +3 -3
- package/package.json +6 -5
package/dist/cjs/browser.js
CHANGED
|
@@ -23,9 +23,9 @@ const _handleRes = require("./handleRes");
|
|
|
23
23
|
let realRequest;
|
|
24
24
|
let realAllowedHeaders;
|
|
25
25
|
const originFetch = (...params) => {
|
|
26
|
-
var _init_method
|
|
26
|
+
var _init_method;
|
|
27
27
|
const [url, init] = params;
|
|
28
|
-
if ((
|
|
28
|
+
if ((init === null || init === void 0 ? void 0 : (_init_method = init.method) === null || _init_method === void 0 ? void 0 : _init_method.toLowerCase()) === "get") {
|
|
29
29
|
init.body = void 0;
|
|
30
30
|
}
|
|
31
31
|
return fetch(url, init).then(_handleRes.handleRes);
|
package/dist/cjs/handleRes.js
CHANGED
|
@@ -9,23 +9,22 @@ Object.defineProperty(exports, "handleRes", {
|
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
11
|
const handleRes = async (res) => {
|
|
12
|
-
var _contentType, _contentType1, _contentType2, _contentType3, _contentType4, _contentType5, _contentType6;
|
|
13
12
|
const contentType = res.headers.get("content-type");
|
|
14
13
|
if (!res.ok) {
|
|
15
14
|
const data = await res.json();
|
|
16
15
|
res.data = data;
|
|
17
16
|
throw res;
|
|
18
17
|
}
|
|
19
|
-
if ((
|
|
18
|
+
if ((contentType === null || contentType === void 0 ? void 0 : contentType.includes("application/json")) || (contentType === null || contentType === void 0 ? void 0 : contentType.includes("text/json"))) {
|
|
20
19
|
return res.json();
|
|
21
20
|
}
|
|
22
|
-
if ((
|
|
21
|
+
if ((contentType === null || contentType === void 0 ? void 0 : contentType.includes("text/html")) || (contentType === null || contentType === void 0 ? void 0 : contentType.includes("text/plain"))) {
|
|
23
22
|
return res.text();
|
|
24
23
|
}
|
|
25
|
-
if (((
|
|
24
|
+
if (((contentType === null || contentType === void 0 ? void 0 : contentType.includes("application/x-www-form-urlencoded")) || (contentType === null || contentType === void 0 ? void 0 : contentType.includes("multipart/form-data"))) && res instanceof Response) {
|
|
26
25
|
return res.formData();
|
|
27
26
|
}
|
|
28
|
-
if (
|
|
27
|
+
if (contentType === null || contentType === void 0 ? void 0 : contentType.includes("application/octet-stream")) {
|
|
29
28
|
return res.arrayBuffer();
|
|
30
29
|
}
|
|
31
30
|
return res.text();
|
package/dist/cjs/node.js
CHANGED
|
@@ -20,15 +20,15 @@ _export(exports, {
|
|
|
20
20
|
const _interop_require_default = require("@swc/helpers/_/_interop_require_default");
|
|
21
21
|
const _nodefetch = /* @__PURE__ */ _interop_require_default._(require("node-fetch"));
|
|
22
22
|
const _pathtoregexp = require("path-to-regexp");
|
|
23
|
-
const
|
|
23
|
+
const _node = require("@modern-js/runtime-utils/node");
|
|
24
24
|
const _querystring = require("query-string");
|
|
25
25
|
const _handleRes = require("./handleRes");
|
|
26
26
|
let realRequest;
|
|
27
27
|
let realAllowedHeaders = [];
|
|
28
28
|
const originFetch = (...params) => {
|
|
29
|
-
var _init_method
|
|
29
|
+
var _init_method;
|
|
30
30
|
const [, init] = params;
|
|
31
|
-
if ((
|
|
31
|
+
if ((init === null || init === void 0 ? void 0 : (_init_method = init.method) === null || _init_method === void 0 ? void 0 : _init_method.toLowerCase()) === "get") {
|
|
32
32
|
init.body = void 0;
|
|
33
33
|
}
|
|
34
34
|
return (0, _nodefetch.default)(...params).then(_handleRes.handleRes);
|
|
@@ -50,7 +50,7 @@ const createRequest = (path, method, port, httpMethodDecider = "functionName", f
|
|
|
50
50
|
const keys = [];
|
|
51
51
|
(0, _pathtoregexp.pathToRegexp)(path, keys);
|
|
52
52
|
const sender = (...args) => {
|
|
53
|
-
const webRequestHeaders = (0,
|
|
53
|
+
const webRequestHeaders = (0, _node.useHeaders)();
|
|
54
54
|
let body;
|
|
55
55
|
let headers;
|
|
56
56
|
let url;
|
package/dist/esm/browser.js
CHANGED
|
@@ -11,9 +11,9 @@ var originFetch = function() {
|
|
|
11
11
|
for (var _len = arguments.length, params = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
12
12
|
params[_key] = arguments[_key];
|
|
13
13
|
}
|
|
14
|
-
var _init_method
|
|
14
|
+
var _init_method;
|
|
15
15
|
var _params = _sliced_to_array(params, 2), url = _params[0], init = _params[1];
|
|
16
|
-
if ((
|
|
16
|
+
if ((init === null || init === void 0 ? void 0 : (_init_method = init.method) === null || _init_method === void 0 ? void 0 : _init_method.toLowerCase()) === "get") {
|
|
17
17
|
init.body = void 0;
|
|
18
18
|
}
|
|
19
19
|
return fetch(url, init).then(handleRes);
|
package/dist/esm/handleRes.js
CHANGED
|
@@ -3,7 +3,7 @@ import { _ as _instanceof } from "@swc/helpers/_/_instanceof";
|
|
|
3
3
|
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
4
4
|
var handleRes = function() {
|
|
5
5
|
var _ref = _async_to_generator(function(res) {
|
|
6
|
-
var
|
|
6
|
+
var contentType, data;
|
|
7
7
|
return _ts_generator(this, function(_state) {
|
|
8
8
|
switch (_state.label) {
|
|
9
9
|
case 0:
|
|
@@ -22,25 +22,25 @@ var handleRes = function() {
|
|
|
22
22
|
res.data = data;
|
|
23
23
|
throw res;
|
|
24
24
|
case 2:
|
|
25
|
-
if ((
|
|
25
|
+
if ((contentType === null || contentType === void 0 ? void 0 : contentType.includes("application/json")) || (contentType === null || contentType === void 0 ? void 0 : contentType.includes("text/json"))) {
|
|
26
26
|
return [
|
|
27
27
|
2,
|
|
28
28
|
res.json()
|
|
29
29
|
];
|
|
30
30
|
}
|
|
31
|
-
if ((
|
|
31
|
+
if ((contentType === null || contentType === void 0 ? void 0 : contentType.includes("text/html")) || (contentType === null || contentType === void 0 ? void 0 : contentType.includes("text/plain"))) {
|
|
32
32
|
return [
|
|
33
33
|
2,
|
|
34
34
|
res.text()
|
|
35
35
|
];
|
|
36
36
|
}
|
|
37
|
-
if (((
|
|
37
|
+
if (((contentType === null || contentType === void 0 ? void 0 : contentType.includes("application/x-www-form-urlencoded")) || (contentType === null || contentType === void 0 ? void 0 : contentType.includes("multipart/form-data"))) && _instanceof(res, Response)) {
|
|
38
38
|
return [
|
|
39
39
|
2,
|
|
40
40
|
res.formData()
|
|
41
41
|
];
|
|
42
42
|
}
|
|
43
|
-
if (
|
|
43
|
+
if (contentType === null || contentType === void 0 ? void 0 : contentType.includes("application/octet-stream")) {
|
|
44
44
|
return [
|
|
45
45
|
2,
|
|
46
46
|
res.arrayBuffer()
|
package/dist/esm/node.js
CHANGED
|
@@ -2,7 +2,7 @@ import { _ as _sliced_to_array } from "@swc/helpers/_/_sliced_to_array";
|
|
|
2
2
|
import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
|
|
3
3
|
import nodeFetch from "node-fetch";
|
|
4
4
|
import { compile, pathToRegexp } from "path-to-regexp";
|
|
5
|
-
import { useHeaders } from "@modern-js/utils/
|
|
5
|
+
import { useHeaders } from "@modern-js/runtime-utils/node";
|
|
6
6
|
import { stringify } from "query-string";
|
|
7
7
|
import { handleRes } from "./handleRes";
|
|
8
8
|
var realRequest;
|
|
@@ -11,9 +11,9 @@ var originFetch = function() {
|
|
|
11
11
|
for (var _len = arguments.length, params = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
12
12
|
params[_key] = arguments[_key];
|
|
13
13
|
}
|
|
14
|
-
var _init_method
|
|
14
|
+
var _init_method;
|
|
15
15
|
var _params = _sliced_to_array(params, 2), init = _params[1];
|
|
16
|
-
if ((
|
|
16
|
+
if ((init === null || init === void 0 ? void 0 : (_init_method = init.method) === null || _init_method === void 0 ? void 0 : _init_method.toLowerCase()) === "get") {
|
|
17
17
|
init.body = void 0;
|
|
18
18
|
}
|
|
19
19
|
return nodeFetch.apply(void 0, _to_consumable_array(params)).then(handleRes);
|
package/dist/esm-node/browser.js
CHANGED
|
@@ -4,9 +4,9 @@ import { handleRes } from "./handleRes";
|
|
|
4
4
|
let realRequest;
|
|
5
5
|
let realAllowedHeaders;
|
|
6
6
|
const originFetch = (...params) => {
|
|
7
|
-
var _init_method
|
|
7
|
+
var _init_method;
|
|
8
8
|
const [url, init] = params;
|
|
9
|
-
if ((
|
|
9
|
+
if ((init === null || init === void 0 ? void 0 : (_init_method = init.method) === null || _init_method === void 0 ? void 0 : _init_method.toLowerCase()) === "get") {
|
|
10
10
|
init.body = void 0;
|
|
11
11
|
}
|
|
12
12
|
return fetch(url, init).then(handleRes);
|
|
@@ -1,21 +1,20 @@
|
|
|
1
1
|
const handleRes = async (res) => {
|
|
2
|
-
var _contentType, _contentType1, _contentType2, _contentType3, _contentType4, _contentType5, _contentType6;
|
|
3
2
|
const contentType = res.headers.get("content-type");
|
|
4
3
|
if (!res.ok) {
|
|
5
4
|
const data = await res.json();
|
|
6
5
|
res.data = data;
|
|
7
6
|
throw res;
|
|
8
7
|
}
|
|
9
|
-
if ((
|
|
8
|
+
if ((contentType === null || contentType === void 0 ? void 0 : contentType.includes("application/json")) || (contentType === null || contentType === void 0 ? void 0 : contentType.includes("text/json"))) {
|
|
10
9
|
return res.json();
|
|
11
10
|
}
|
|
12
|
-
if ((
|
|
11
|
+
if ((contentType === null || contentType === void 0 ? void 0 : contentType.includes("text/html")) || (contentType === null || contentType === void 0 ? void 0 : contentType.includes("text/plain"))) {
|
|
13
12
|
return res.text();
|
|
14
13
|
}
|
|
15
|
-
if (((
|
|
14
|
+
if (((contentType === null || contentType === void 0 ? void 0 : contentType.includes("application/x-www-form-urlencoded")) || (contentType === null || contentType === void 0 ? void 0 : contentType.includes("multipart/form-data"))) && res instanceof Response) {
|
|
16
15
|
return res.formData();
|
|
17
16
|
}
|
|
18
|
-
if (
|
|
17
|
+
if (contentType === null || contentType === void 0 ? void 0 : contentType.includes("application/octet-stream")) {
|
|
19
18
|
return res.arrayBuffer();
|
|
20
19
|
}
|
|
21
20
|
return res.text();
|
package/dist/esm-node/node.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import nodeFetch from "node-fetch";
|
|
2
2
|
import { compile, pathToRegexp } from "path-to-regexp";
|
|
3
|
-
import { useHeaders } from "@modern-js/utils/
|
|
3
|
+
import { useHeaders } from "@modern-js/runtime-utils/node";
|
|
4
4
|
import { stringify } from "query-string";
|
|
5
5
|
import { handleRes } from "./handleRes";
|
|
6
6
|
let realRequest;
|
|
7
7
|
let realAllowedHeaders = [];
|
|
8
8
|
const originFetch = (...params) => {
|
|
9
|
-
var _init_method
|
|
9
|
+
var _init_method;
|
|
10
10
|
const [, init] = params;
|
|
11
|
-
if ((
|
|
11
|
+
if ((init === null || init === void 0 ? void 0 : (_init_method = init.method) === null || _init_method === void 0 ? void 0 : _init_method.toLowerCase()) === "get") {
|
|
12
12
|
init.body = void 0;
|
|
13
13
|
}
|
|
14
14
|
return nodeFetch(...params).then(handleRes);
|
package/package.json
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"modern",
|
|
16
16
|
"modern.js"
|
|
17
17
|
],
|
|
18
|
-
"version": "2.35.
|
|
18
|
+
"version": "2.35.1",
|
|
19
19
|
"jsnext:source": "./src/node.ts",
|
|
20
20
|
"types": "./dist/types/index.d.ts",
|
|
21
21
|
"main": "./dist/cjs/node.js",
|
|
@@ -64,7 +64,8 @@
|
|
|
64
64
|
"path-to-regexp": "^6.2.0",
|
|
65
65
|
"query-string": "^7.1.1",
|
|
66
66
|
"@swc/helpers": "0.5.1",
|
|
67
|
-
"@modern-js/utils": "2.35.
|
|
67
|
+
"@modern-js/utils": "2.35.1",
|
|
68
|
+
"@modern-js/runtime-utils": "2.35.1"
|
|
68
69
|
},
|
|
69
70
|
"devDependencies": {
|
|
70
71
|
"@types/jest": "^29",
|
|
@@ -74,9 +75,9 @@
|
|
|
74
75
|
"jest": "^29",
|
|
75
76
|
"nock": "^13.2.1",
|
|
76
77
|
"typescript": "^5",
|
|
77
|
-
"@
|
|
78
|
-
"@scripts/build": "2.35.
|
|
79
|
-
"@
|
|
78
|
+
"@modern-js/types": "2.35.1",
|
|
79
|
+
"@scripts/build": "2.35.1",
|
|
80
|
+
"@scripts/jest-config": "2.35.1"
|
|
80
81
|
},
|
|
81
82
|
"sideEffects": false,
|
|
82
83
|
"publishConfig": {
|