@modern-js/create-request 2.5.1-alpha.6 → 2.5.1-alpha.8
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 +10 -10
- package/dist/cjs/node.js +8 -8
- package/dist/esm/browser.js +11 -11
- package/dist/esm/node.js +9 -9
- package/dist/esm-node/browser.js +10 -10
- package/dist/esm-node/node.js +8 -8
- package/dist/types/types.d.ts +1 -1
- package/package.json +1 -1
package/dist/cjs/browser.js
CHANGED
|
@@ -43,7 +43,7 @@ const configure = (options) => {
|
|
|
43
43
|
realAllowedHeaders = allowedHeaders;
|
|
44
44
|
}
|
|
45
45
|
};
|
|
46
|
-
const createRequest = (path, method, httpMethodDecider = "functionName",
|
|
46
|
+
const createRequest = (path, method, port, httpMethodDecider = "functionName", fetch2 = originFetch) => {
|
|
47
47
|
const getFinalPath = (0, import_path_to_regexp.compile)(path, { encode: encodeURIComponent });
|
|
48
48
|
const keys = [];
|
|
49
49
|
(0, import_path_to_regexp.pathToRegexp)(path, keys);
|
|
@@ -52,7 +52,15 @@ const createRequest = (path, method, httpMethodDecider = "functionName", port, f
|
|
|
52
52
|
let body;
|
|
53
53
|
let finalURL;
|
|
54
54
|
let headers;
|
|
55
|
-
if (httpMethodDecider === "
|
|
55
|
+
if (httpMethodDecider === "inputParams") {
|
|
56
|
+
finalURL = path;
|
|
57
|
+
body = JSON.stringify({
|
|
58
|
+
args
|
|
59
|
+
});
|
|
60
|
+
headers = {
|
|
61
|
+
"Content-Type": "application/json"
|
|
62
|
+
};
|
|
63
|
+
} else {
|
|
56
64
|
const payload = typeof args[args.length - 1] === "object" ? args[args.length - 1] : {};
|
|
57
65
|
payload.params = payload.params || {};
|
|
58
66
|
const requestParams = args[0];
|
|
@@ -86,14 +94,6 @@ const createRequest = (path, method, httpMethodDecider = "functionName", port, f
|
|
|
86
94
|
body = payload.formUrlencoded;
|
|
87
95
|
}
|
|
88
96
|
}
|
|
89
|
-
} else {
|
|
90
|
-
finalURL = path;
|
|
91
|
-
body = JSON.stringify({
|
|
92
|
-
args
|
|
93
|
-
});
|
|
94
|
-
headers = {
|
|
95
|
-
"Content-Type": "application/json"
|
|
96
|
-
};
|
|
97
97
|
}
|
|
98
98
|
return fetcher(finalURL, {
|
|
99
99
|
method,
|
package/dist/cjs/node.js
CHANGED
|
@@ -45,7 +45,7 @@ const configure = (options) => {
|
|
|
45
45
|
realAllowedHeaders = allowedHeaders;
|
|
46
46
|
}
|
|
47
47
|
};
|
|
48
|
-
const createRequest = (path, method, httpMethodDecider = "functionName",
|
|
48
|
+
const createRequest = (path, method, port, httpMethodDecider = "functionName", fetch = import_node_fetch.default) => {
|
|
49
49
|
const getFinalPath = (0, import_path_to_regexp.compile)(path, { encode: encodeURIComponent });
|
|
50
50
|
const keys = [];
|
|
51
51
|
(0, import_path_to_regexp.pathToRegexp)(path, keys);
|
|
@@ -54,7 +54,13 @@ const createRequest = (path, method, httpMethodDecider = "functionName", port, f
|
|
|
54
54
|
let body;
|
|
55
55
|
let headers;
|
|
56
56
|
let url;
|
|
57
|
-
if (httpMethodDecider === "
|
|
57
|
+
if (httpMethodDecider === "inputParams") {
|
|
58
|
+
url = path;
|
|
59
|
+
body = args;
|
|
60
|
+
headers = {
|
|
61
|
+
"Content-Type": "application/json"
|
|
62
|
+
};
|
|
63
|
+
} else {
|
|
58
64
|
const payload = typeof args[args.length - 1] === "object" ? args[args.length - 1] : {};
|
|
59
65
|
payload.params = payload.params || {};
|
|
60
66
|
const requestParams = args[0];
|
|
@@ -93,12 +99,6 @@ const createRequest = (path, method, httpMethodDecider = "functionName", port, f
|
|
|
93
99
|
}
|
|
94
100
|
}
|
|
95
101
|
url = `http://localhost:${port}${finalPath}`;
|
|
96
|
-
} else {
|
|
97
|
-
url = path;
|
|
98
|
-
body = args;
|
|
99
|
-
headers = {
|
|
100
|
-
"Content-Type": "application/json"
|
|
101
|
-
};
|
|
102
102
|
}
|
|
103
103
|
const fetcher = realRequest || originFetch;
|
|
104
104
|
return fetcher(url, { method, body, headers });
|
package/dist/esm/browser.js
CHANGED
|
@@ -175,8 +175,8 @@ var configure = function(options) {
|
|
|
175
175
|
realAllowedHeaders = allowedHeaders;
|
|
176
176
|
}
|
|
177
177
|
};
|
|
178
|
-
var createRequest = function(path, method) {
|
|
179
|
-
var httpMethodDecider = arguments.length >
|
|
178
|
+
var createRequest = function(path, method, port) {
|
|
179
|
+
var httpMethodDecider = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : "functionName", fetch2 = arguments.length > 4 && arguments[4] !== void 0 ? arguments[4] : originFetch;
|
|
180
180
|
var getFinalPath = compile(path, {
|
|
181
181
|
encode: encodeURIComponent
|
|
182
182
|
});
|
|
@@ -191,7 +191,15 @@ var createRequest = function(path, method) {
|
|
|
191
191
|
args[_key] = _arguments[_key];
|
|
192
192
|
}
|
|
193
193
|
fetcher = realRequest || originFetch;
|
|
194
|
-
if (httpMethodDecider === "
|
|
194
|
+
if (httpMethodDecider === "inputParams") {
|
|
195
|
+
finalURL = path;
|
|
196
|
+
body = JSON.stringify({
|
|
197
|
+
args: args
|
|
198
|
+
});
|
|
199
|
+
headers = {
|
|
200
|
+
"Content-Type": "application/json"
|
|
201
|
+
};
|
|
202
|
+
} else {
|
|
195
203
|
payload = typeof args[args.length - 1] === "object" ? args[args.length - 1] : {};
|
|
196
204
|
payload.params = payload.params || {};
|
|
197
205
|
requestParams = args[0];
|
|
@@ -225,14 +233,6 @@ var createRequest = function(path, method) {
|
|
|
225
233
|
body = payload.formUrlencoded;
|
|
226
234
|
}
|
|
227
235
|
}
|
|
228
|
-
} else {
|
|
229
|
-
finalURL = path;
|
|
230
|
-
body = JSON.stringify({
|
|
231
|
-
args: args
|
|
232
|
-
});
|
|
233
|
-
headers = {
|
|
234
|
-
"Content-Type": "application/json"
|
|
235
|
-
};
|
|
236
236
|
}
|
|
237
237
|
return [
|
|
238
238
|
2,
|
package/dist/esm/node.js
CHANGED
|
@@ -46,8 +46,8 @@ var configure = function(options) {
|
|
|
46
46
|
realAllowedHeaders = allowedHeaders;
|
|
47
47
|
}
|
|
48
48
|
};
|
|
49
|
-
var createRequest = function(path, method) {
|
|
50
|
-
var httpMethodDecider = arguments.length >
|
|
49
|
+
var createRequest = function(path, method, port) {
|
|
50
|
+
var httpMethodDecider = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : "functionName", fetch = arguments.length > 4 && arguments[4] !== void 0 ? arguments[4] : nodeFetch;
|
|
51
51
|
var getFinalPath = compile(path, {
|
|
52
52
|
encode: encodeURIComponent
|
|
53
53
|
});
|
|
@@ -61,7 +61,13 @@ var createRequest = function(path, method) {
|
|
|
61
61
|
var body;
|
|
62
62
|
var headers;
|
|
63
63
|
var url;
|
|
64
|
-
if (httpMethodDecider === "
|
|
64
|
+
if (httpMethodDecider === "inputParams") {
|
|
65
|
+
url = path;
|
|
66
|
+
body = args;
|
|
67
|
+
headers = {
|
|
68
|
+
"Content-Type": "application/json"
|
|
69
|
+
};
|
|
70
|
+
} else {
|
|
65
71
|
var payload = typeof args[args.length - 1] === "object" ? args[args.length - 1] : {};
|
|
66
72
|
payload.params = payload.params || {};
|
|
67
73
|
var requestParams = args[0];
|
|
@@ -117,12 +123,6 @@ var createRequest = function(path, method) {
|
|
|
117
123
|
}
|
|
118
124
|
}
|
|
119
125
|
url = "http://localhost:".concat(port).concat(finalPath);
|
|
120
|
-
} else {
|
|
121
|
-
url = path;
|
|
122
|
-
body = args;
|
|
123
|
-
headers = {
|
|
124
|
-
"Content-Type": "application/json"
|
|
125
|
-
};
|
|
126
126
|
}
|
|
127
127
|
var fetcher = realRequest || originFetch;
|
|
128
128
|
return fetcher(url, {
|
package/dist/esm-node/browser.js
CHANGED
|
@@ -14,7 +14,7 @@ const configure = (options) => {
|
|
|
14
14
|
realAllowedHeaders = allowedHeaders;
|
|
15
15
|
}
|
|
16
16
|
};
|
|
17
|
-
const createRequest = (path, method, httpMethodDecider = "functionName",
|
|
17
|
+
const createRequest = (path, method, port, httpMethodDecider = "functionName", fetch2 = originFetch) => {
|
|
18
18
|
const getFinalPath = compile(path, { encode: encodeURIComponent });
|
|
19
19
|
const keys = [];
|
|
20
20
|
pathToRegexp(path, keys);
|
|
@@ -23,7 +23,15 @@ const createRequest = (path, method, httpMethodDecider = "functionName", port, f
|
|
|
23
23
|
let body;
|
|
24
24
|
let finalURL;
|
|
25
25
|
let headers;
|
|
26
|
-
if (httpMethodDecider === "
|
|
26
|
+
if (httpMethodDecider === "inputParams") {
|
|
27
|
+
finalURL = path;
|
|
28
|
+
body = JSON.stringify({
|
|
29
|
+
args
|
|
30
|
+
});
|
|
31
|
+
headers = {
|
|
32
|
+
"Content-Type": "application/json"
|
|
33
|
+
};
|
|
34
|
+
} else {
|
|
27
35
|
const payload = typeof args[args.length - 1] === "object" ? args[args.length - 1] : {};
|
|
28
36
|
payload.params = payload.params || {};
|
|
29
37
|
const requestParams = args[0];
|
|
@@ -57,14 +65,6 @@ const createRequest = (path, method, httpMethodDecider = "functionName", port, f
|
|
|
57
65
|
body = payload.formUrlencoded;
|
|
58
66
|
}
|
|
59
67
|
}
|
|
60
|
-
} else {
|
|
61
|
-
finalURL = path;
|
|
62
|
-
body = JSON.stringify({
|
|
63
|
-
args
|
|
64
|
-
});
|
|
65
|
-
headers = {
|
|
66
|
-
"Content-Type": "application/json"
|
|
67
|
-
};
|
|
68
68
|
}
|
|
69
69
|
return fetcher(finalURL, {
|
|
70
70
|
method,
|
package/dist/esm-node/node.js
CHANGED
|
@@ -16,7 +16,7 @@ const configure = (options) => {
|
|
|
16
16
|
realAllowedHeaders = allowedHeaders;
|
|
17
17
|
}
|
|
18
18
|
};
|
|
19
|
-
const createRequest = (path, method, httpMethodDecider = "functionName",
|
|
19
|
+
const createRequest = (path, method, port, httpMethodDecider = "functionName", fetch = nodeFetch) => {
|
|
20
20
|
const getFinalPath = compile(path, { encode: encodeURIComponent });
|
|
21
21
|
const keys = [];
|
|
22
22
|
pathToRegexp(path, keys);
|
|
@@ -25,7 +25,13 @@ const createRequest = (path, method, httpMethodDecider = "functionName", port, f
|
|
|
25
25
|
let body;
|
|
26
26
|
let headers;
|
|
27
27
|
let url;
|
|
28
|
-
if (httpMethodDecider === "
|
|
28
|
+
if (httpMethodDecider === "inputParams") {
|
|
29
|
+
url = path;
|
|
30
|
+
body = args;
|
|
31
|
+
headers = {
|
|
32
|
+
"Content-Type": "application/json"
|
|
33
|
+
};
|
|
34
|
+
} else {
|
|
29
35
|
const payload = typeof args[args.length - 1] === "object" ? args[args.length - 1] : {};
|
|
30
36
|
payload.params = payload.params || {};
|
|
31
37
|
const requestParams = args[0];
|
|
@@ -64,12 +70,6 @@ const createRequest = (path, method, httpMethodDecider = "functionName", port, f
|
|
|
64
70
|
}
|
|
65
71
|
}
|
|
66
72
|
url = `http://localhost:${port}${finalPath}`;
|
|
67
|
-
} else {
|
|
68
|
-
url = path;
|
|
69
|
-
body = args;
|
|
70
|
-
headers = {
|
|
71
|
-
"Content-Type": "application/json"
|
|
72
|
-
};
|
|
73
73
|
}
|
|
74
74
|
const fetcher = realRequest || originFetch;
|
|
75
75
|
return fetcher(url, { method, body, headers });
|
package/dist/types/types.d.ts
CHANGED
|
@@ -14,7 +14,7 @@ export type Fetch = typeof fetch | typeof nodeFetch;
|
|
|
14
14
|
export type Sender = ((...args: any[]) => Promise<any>) & {
|
|
15
15
|
fetch?: Fetch;
|
|
16
16
|
};
|
|
17
|
-
export type RequestCreator = (path: string, method: string,
|
|
17
|
+
export type RequestCreator = (path: string, method: string, port: number, httpMethodDecider: HttpMethodDecider, fetch?: Fetch) => Sender;
|
|
18
18
|
export type IOptions<F = Fetch> = {
|
|
19
19
|
request?: F;
|
|
20
20
|
interceptor?: (request: F) => F;
|