@modern-js/create-request 1.2.8 → 1.2.11
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/js/modern/browser.js +15 -3
- package/dist/js/modern/node.js +15 -3
- package/dist/js/node/browser.js +15 -3
- package/dist/js/node/node.js +15 -3
- package/dist/js/treeshaking/browser.js +19 -7
- package/dist/js/treeshaking/node.js +13 -3
- package/package.json +6 -5
|
@@ -36,9 +36,21 @@ fetch = originFetch) => {
|
|
|
36
36
|
const fetcher = realRequest || originFetch;
|
|
37
37
|
const payload = typeof args[args.length - 1] === 'object' ? args[args.length - 1] : {};
|
|
38
38
|
payload.params = payload.params || {};
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
39
|
+
const requestParams = args[0]; // 这种场景下是使用 schema,所以 params 要从 args[0] 中获取
|
|
40
|
+
|
|
41
|
+
if (typeof requestParams === 'object' && requestParams.params) {
|
|
42
|
+
const {
|
|
43
|
+
params
|
|
44
|
+
} = requestParams;
|
|
45
|
+
keys.forEach(key => {
|
|
46
|
+
payload.params[key.name] = params[key.name];
|
|
47
|
+
});
|
|
48
|
+
} else {
|
|
49
|
+
keys.forEach((key, index) => {
|
|
50
|
+
payload.params[key.name] = args[index];
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
|
|
42
54
|
const finalPath = getFinalPath(payload.params);
|
|
43
55
|
const finalURL = payload.query ? `${finalPath}?${qs.stringify(payload.query)}` : finalPath;
|
|
44
56
|
const headers = payload.headers || {};
|
package/dist/js/modern/node.js
CHANGED
|
@@ -37,9 +37,21 @@ fetch = nodeFetch) => {
|
|
|
37
37
|
const webRequestHeaders = useHeaders();
|
|
38
38
|
const payload = typeof args[args.length - 1] === 'object' ? args[args.length - 1] : {};
|
|
39
39
|
payload.params = payload.params || {};
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
40
|
+
const requestParams = args[0]; // 这种场景下是使用 schema,所以 params 要从 args[0] 中获取
|
|
41
|
+
|
|
42
|
+
if (typeof requestParams === 'object' && requestParams.params) {
|
|
43
|
+
const {
|
|
44
|
+
params
|
|
45
|
+
} = requestParams;
|
|
46
|
+
keys.forEach(key => {
|
|
47
|
+
payload.params[key.name] = params[key.name];
|
|
48
|
+
});
|
|
49
|
+
} else {
|
|
50
|
+
keys.forEach((key, index) => {
|
|
51
|
+
payload.params[key.name] = args[index];
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
|
|
43
55
|
const plainPath = getFinalPath(payload.params);
|
|
44
56
|
const finalPath = payload.query ? `${plainPath}?${qs.stringify(payload.query)}` : plainPath;
|
|
45
57
|
const headers = payload.headers || {};
|
package/dist/js/node/browser.js
CHANGED
|
@@ -51,9 +51,21 @@ fetch = originFetch) => {
|
|
|
51
51
|
const fetcher = realRequest || originFetch;
|
|
52
52
|
const payload = typeof args[args.length - 1] === 'object' ? args[args.length - 1] : {};
|
|
53
53
|
payload.params = payload.params || {};
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
54
|
+
const requestParams = args[0]; // 这种场景下是使用 schema,所以 params 要从 args[0] 中获取
|
|
55
|
+
|
|
56
|
+
if (typeof requestParams === 'object' && requestParams.params) {
|
|
57
|
+
const {
|
|
58
|
+
params
|
|
59
|
+
} = requestParams;
|
|
60
|
+
keys.forEach(key => {
|
|
61
|
+
payload.params[key.name] = params[key.name];
|
|
62
|
+
});
|
|
63
|
+
} else {
|
|
64
|
+
keys.forEach((key, index) => {
|
|
65
|
+
payload.params[key.name] = args[index];
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
|
|
57
69
|
const finalPath = getFinalPath(payload.params);
|
|
58
70
|
const finalURL = payload.query ? `${finalPath}?${_queryString.default.stringify(payload.query)}` : finalPath;
|
|
59
71
|
const headers = payload.headers || {};
|
package/dist/js/node/node.js
CHANGED
|
@@ -54,9 +54,21 @@ fetch = _nodeFetch.default) => {
|
|
|
54
54
|
const webRequestHeaders = (0, _ssr.useHeaders)();
|
|
55
55
|
const payload = typeof args[args.length - 1] === 'object' ? args[args.length - 1] : {};
|
|
56
56
|
payload.params = payload.params || {};
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
57
|
+
const requestParams = args[0]; // 这种场景下是使用 schema,所以 params 要从 args[0] 中获取
|
|
58
|
+
|
|
59
|
+
if (typeof requestParams === 'object' && requestParams.params) {
|
|
60
|
+
const {
|
|
61
|
+
params
|
|
62
|
+
} = requestParams;
|
|
63
|
+
keys.forEach(key => {
|
|
64
|
+
payload.params[key.name] = params[key.name];
|
|
65
|
+
});
|
|
66
|
+
} else {
|
|
67
|
+
keys.forEach((key, index) => {
|
|
68
|
+
payload.params[key.name] = args[index];
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
|
|
60
72
|
const plainPath = getFinalPath(payload.params);
|
|
61
73
|
const finalPath = payload.query ? `${plainPath}?${_queryString.default.stringify(payload.query)}` : plainPath;
|
|
62
74
|
const headers = payload.headers || {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime";
|
|
1
2
|
import _typeof from "@babel/runtime/helpers/esm/typeof";
|
|
2
3
|
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
|
3
|
-
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
4
4
|
import { compile, pathToRegexp } from 'path-to-regexp';
|
|
5
5
|
import qs from 'query-string';
|
|
6
6
|
import { handleRes } from "./handleRes";
|
|
@@ -35,19 +35,21 @@ export var createRequest = function createRequest(path, method, port) {
|
|
|
35
35
|
pathToRegexp(path, keys);
|
|
36
36
|
|
|
37
37
|
var sender = /*#__PURE__*/function () {
|
|
38
|
-
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
38
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
39
39
|
var _len,
|
|
40
40
|
args,
|
|
41
41
|
_key,
|
|
42
42
|
fetcher,
|
|
43
43
|
payload,
|
|
44
|
+
requestParams,
|
|
45
|
+
params,
|
|
44
46
|
finalPath,
|
|
45
47
|
finalURL,
|
|
46
48
|
headers,
|
|
47
49
|
body,
|
|
48
50
|
_args = arguments;
|
|
49
51
|
|
|
50
|
-
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
52
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
51
53
|
while (1) {
|
|
52
54
|
switch (_context.prev = _context.next) {
|
|
53
55
|
case 0:
|
|
@@ -58,9 +60,19 @@ export var createRequest = function createRequest(path, method, port) {
|
|
|
58
60
|
fetcher = realRequest || originFetch;
|
|
59
61
|
payload = _typeof(args[args.length - 1]) === 'object' ? args[args.length - 1] : {};
|
|
60
62
|
payload.params = payload.params || {};
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
63
|
+
requestParams = args[0]; // 这种场景下是使用 schema,所以 params 要从 args[0] 中获取
|
|
64
|
+
|
|
65
|
+
if (_typeof(requestParams) === 'object' && requestParams.params) {
|
|
66
|
+
params = requestParams.params;
|
|
67
|
+
keys.forEach(function (key) {
|
|
68
|
+
payload.params[key.name] = params[key.name];
|
|
69
|
+
});
|
|
70
|
+
} else {
|
|
71
|
+
keys.forEach(function (key, index) {
|
|
72
|
+
payload.params[key.name] = args[index];
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
|
|
64
76
|
finalPath = getFinalPath(payload.params);
|
|
65
77
|
finalURL = payload.query ? "".concat(finalPath, "?").concat(qs.stringify(payload.query)) : finalPath;
|
|
66
78
|
headers = payload.headers || {};
|
|
@@ -96,7 +108,7 @@ export var createRequest = function createRequest(path, method, port) {
|
|
|
96
108
|
headers: headers
|
|
97
109
|
}));
|
|
98
110
|
|
|
99
|
-
case
|
|
111
|
+
case 12:
|
|
100
112
|
case "end":
|
|
101
113
|
return _context.stop();
|
|
102
114
|
}
|
|
@@ -42,9 +42,19 @@ export var createRequest = function createRequest(path, method, port) {
|
|
|
42
42
|
var webRequestHeaders = useHeaders();
|
|
43
43
|
var payload = _typeof(args[args.length - 1]) === 'object' ? args[args.length - 1] : {};
|
|
44
44
|
payload.params = payload.params || {};
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
45
|
+
var requestParams = args[0]; // 这种场景下是使用 schema,所以 params 要从 args[0] 中获取
|
|
46
|
+
|
|
47
|
+
if (_typeof(requestParams) === 'object' && requestParams.params) {
|
|
48
|
+
var params = requestParams.params;
|
|
49
|
+
keys.forEach(function (key) {
|
|
50
|
+
payload.params[key.name] = params[key.name];
|
|
51
|
+
});
|
|
52
|
+
} else {
|
|
53
|
+
keys.forEach(function (key, index) {
|
|
54
|
+
payload.params[key.name] = args[index];
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
48
58
|
var plainPath = getFinalPath(payload.params);
|
|
49
59
|
var finalPath = payload.query ? "".concat(plainPath, "?").concat(qs.stringify(payload.query)) : plainPath;
|
|
50
60
|
var headers = payload.headers || {};
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"modern",
|
|
12
12
|
"modern.js"
|
|
13
13
|
],
|
|
14
|
-
"version": "1.2.
|
|
14
|
+
"version": "1.2.11",
|
|
15
15
|
"jsnext:source": "./src/index.ts",
|
|
16
16
|
"types": "./dist/types/index.d.ts",
|
|
17
17
|
"main": "./dist/js/node/index.js",
|
|
@@ -62,9 +62,9 @@
|
|
|
62
62
|
}
|
|
63
63
|
},
|
|
64
64
|
"dependencies": {
|
|
65
|
-
"@babel/runtime": "^7",
|
|
66
|
-
"@modern-js/plugin-ssr": "^1.
|
|
67
|
-
"@modern-js/utils": "^1.7.
|
|
65
|
+
"@babel/runtime": "^7.18.0",
|
|
66
|
+
"@modern-js/plugin-ssr": "^1.4.5",
|
|
67
|
+
"@modern-js/utils": "^1.7.6",
|
|
68
68
|
"node-fetch": "^2.6.1",
|
|
69
69
|
"path-to-regexp": "^6.2.0",
|
|
70
70
|
"query-string": "^7.1.1"
|
|
@@ -104,7 +104,8 @@
|
|
|
104
104
|
"files": [
|
|
105
105
|
"src/**/*",
|
|
106
106
|
"tsconfig.json",
|
|
107
|
-
"package.json"
|
|
107
|
+
"package.json",
|
|
108
|
+
"tests/**/*"
|
|
108
109
|
],
|
|
109
110
|
"output": []
|
|
110
111
|
}
|