@modern-js/create-request 1.2.6 → 1.2.9

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.
@@ -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
- keys.forEach((key, index) => {
40
- payload.params[key.name] = args[index];
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 || {};
@@ -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
- keys.forEach((key, index) => {
41
- payload.params[key.name] = args[index];
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 || {};
@@ -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
- keys.forEach((key, index) => {
55
- payload.params[key.name] = args[index];
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 || {};
@@ -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
- keys.forEach((key, index) => {
58
- payload.params[key.name] = args[index];
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,11 +1,6 @@
1
+ import _typeof from "@babel/runtime/helpers/esm/typeof";
2
+ import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
1
3
  import _regeneratorRuntime from "@babel/runtime/regenerator";
2
-
3
- function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
4
-
5
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
6
-
7
- function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
8
-
9
4
  import { compile, pathToRegexp } from 'path-to-regexp';
10
5
  import qs from 'query-string';
11
6
  import { handleRes } from "./handleRes";
@@ -46,6 +41,8 @@ export var createRequest = function createRequest(path, method, port) {
46
41
  _key,
47
42
  fetcher,
48
43
  payload,
44
+ requestParams,
45
+ params,
49
46
  finalPath,
50
47
  finalURL,
51
48
  headers,
@@ -63,9 +60,19 @@ export var createRequest = function createRequest(path, method, port) {
63
60
  fetcher = realRequest || originFetch;
64
61
  payload = _typeof(args[args.length - 1]) === 'object' ? args[args.length - 1] : {};
65
62
  payload.params = payload.params || {};
66
- keys.forEach(function (key, index) {
67
- payload.params[key.name] = args[index];
68
- });
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
+
69
76
  finalPath = getFinalPath(payload.params);
70
77
  finalURL = payload.query ? "".concat(finalPath, "?").concat(qs.stringify(payload.query)) : finalPath;
71
78
  headers = payload.headers || {};
@@ -101,7 +108,7 @@ export var createRequest = function createRequest(path, method, port) {
101
108
  headers: headers
102
109
  }));
103
110
 
104
- case 11:
111
+ case 12:
105
112
  case "end":
106
113
  return _context.stop();
107
114
  }
@@ -1,11 +1,5 @@
1
- function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
2
-
3
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
4
-
5
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
6
-
7
- function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
8
-
1
+ import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
2
+ import _typeof from "@babel/runtime/helpers/esm/typeof";
9
3
  import nodeFetch from 'node-fetch';
10
4
  import { compile, pathToRegexp } from 'path-to-regexp';
11
5
  import { useHeaders } from '@modern-js/utils/ssr';
@@ -48,9 +42,19 @@ export var createRequest = function createRequest(path, method, port) {
48
42
  var webRequestHeaders = useHeaders();
49
43
  var payload = _typeof(args[args.length - 1]) === 'object' ? args[args.length - 1] : {};
50
44
  payload.params = payload.params || {};
51
- keys.forEach(function (key, index) {
52
- payload.params[key.name] = args[index];
53
- });
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
+
54
58
  var plainPath = getFinalPath(payload.params);
55
59
  var finalPath = payload.query ? "".concat(plainPath, "?").concat(qs.stringify(payload.query)) : plainPath;
56
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.6",
14
+ "version": "1.2.9",
15
15
  "jsnext:source": "./src/index.ts",
16
16
  "types": "./dist/types/index.d.ts",
17
17
  "main": "./dist/js/node/index.js",
@@ -63,8 +63,8 @@
63
63
  },
64
64
  "dependencies": {
65
65
  "@babel/runtime": "^7",
66
- "@modern-js/plugin-ssr": "^1.3.0",
67
- "@modern-js/utils": "^1.7.0",
66
+ "@modern-js/plugin-ssr": "^1.3.2",
67
+ "@modern-js/utils": "^1.7.3",
68
68
  "node-fetch": "^2.6.1",
69
69
  "path-to-regexp": "^6.2.0",
70
70
  "query-string": "^7.1.1"
@@ -72,7 +72,7 @@
72
72
  "devDependencies": {
73
73
  "@scripts/build": "0.0.0",
74
74
  "@scripts/jest-config": "0.0.0",
75
- "@types/jest": "^27.0.3",
75
+ "@types/jest": "^27",
76
76
  "@types/node": "^14",
77
77
  "@types/node-fetch": "^2.6.1",
78
78
  "@types/react": "^17",
@@ -85,12 +85,36 @@
85
85
  "sideEffects": false,
86
86
  "publishConfig": {
87
87
  "registry": "https://registry.npmjs.org/",
88
- "access": "public"
88
+ "access": "public",
89
+ "types": "./dist/types/index.d.ts"
90
+ },
91
+ "wireit": {
92
+ "build": {
93
+ "command": "modern build",
94
+ "files": [
95
+ "src/**/*",
96
+ "tsconfig.json",
97
+ "package.json"
98
+ ],
99
+ "output": [
100
+ "dist/**/*"
101
+ ]
102
+ },
103
+ "test": {
104
+ "command": "jest --passWithNoTests",
105
+ "files": [
106
+ "src/**/*",
107
+ "tsconfig.json",
108
+ "package.json",
109
+ "tests/**/*"
110
+ ],
111
+ "output": []
112
+ }
89
113
  },
90
114
  "scripts": {
91
115
  "new": "modern new",
92
- "build": "modern build",
93
- "test": "jest --passWithNoTests"
116
+ "build": "wireit",
117
+ "test": "wireit"
94
118
  },
95
119
  "readme": "\n<p align=\"center\">\n <a href=\"https://modernjs.dev\" target=\"blank\"><img src=\"https://lf3-static.bytednsdoc.com/obj/eden-cn/ylaelkeh7nuhfnuhf/modernjs-cover.png\" width=\"300\" alt=\"Modern.js Logo\" /></a>\n</p>\n<p align=\"center\">\n现代 Web 工程体系\n <br/>\n <a href=\"https://modernjs.dev\" target=\"blank\">\n modernjs.dev\n </a>\n</p>\n<p align=\"center\">\n The meta-framework suite designed from scratch for frontend-focused modern web development\n</p>\n\n# Introduction\n\n> The doc site ([modernjs.dev](https://modernjs.dev)) and articles are only available in Chinese for now, we are planning to add English versions soon.\n\n- [Modern.js: Hello, World!](https://zhuanlan.zhihu.com/p/426707646)\n\n## Getting Started\n\n- [Quick Start](https://modernjs.dev/docs/start)\n- [Guides](https://modernjs.dev/docs/guides)\n- [API References](https://modernjs.dev/docs/apis)\n\n## Contributing\n\n- [Contributing Guide](https://github.com/modern-js-dev/modern.js/blob/main/CONTRIBUTING.md)\n"
96
120
  }