@modern-js/create-request 2.15.0 → 2.16.0

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.
@@ -4,7 +4,7 @@ import { handleRes } from "./handleRes";
4
4
  let realRequest;
5
5
  let realAllowedHeaders;
6
6
  const originFetch = (...params) => fetch(...params).then(handleRes);
7
- const configure = (options) => {
7
+ export const configure = (options) => {
8
8
  const { request, interceptor, allowedHeaders } = options;
9
9
  realRequest = request || originFetch;
10
10
  if (interceptor && !request) {
@@ -14,8 +14,10 @@ const configure = (options) => {
14
14
  realAllowedHeaders = allowedHeaders;
15
15
  }
16
16
  };
17
- const createRequest = (path, method, port, httpMethodDecider = "functionName", fetch2 = originFetch) => {
18
- const getFinalPath = compile(path, { encode: encodeURIComponent });
17
+ export const createRequest = (path, method, port, httpMethodDecider = "functionName", fetch1 = originFetch) => {
18
+ const getFinalPath = compile(path, {
19
+ encode: encodeURIComponent
20
+ });
19
21
  const keys = [];
20
22
  pathToRegexp(path, keys);
21
23
  const sender = async (...args) => {
@@ -81,7 +83,3 @@ const createRequest = (path, method, port, httpMethodDecider = "functionName", f
81
83
  };
82
84
  return sender;
83
85
  };
84
- export {
85
- configure,
86
- createRequest
87
- };
@@ -5,20 +5,18 @@ const handleRes = async (res) => {
5
5
  res.data = data;
6
6
  throw res;
7
7
  }
8
- if ((contentType == null ? void 0 : contentType.includes("application/json")) || (contentType == null ? void 0 : contentType.includes("text/json"))) {
8
+ if ((contentType === null || contentType === void 0 ? void 0 : contentType.includes("application/json")) || (contentType === null || contentType === void 0 ? void 0 : contentType.includes("text/json"))) {
9
9
  return res.json();
10
10
  }
11
- if ((contentType == null ? void 0 : contentType.includes("text/html")) || (contentType == null ? void 0 : contentType.includes("text/plain"))) {
11
+ if ((contentType === null || contentType === void 0 ? void 0 : contentType.includes("text/html")) || (contentType === null || contentType === void 0 ? void 0 : contentType.includes("text/plain"))) {
12
12
  return res.text();
13
13
  }
14
- if (((contentType == null ? void 0 : contentType.includes("application/x-www-form-urlencoded")) || (contentType == null ? void 0 : contentType.includes("multipart/form-data"))) && res instanceof Response) {
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) {
15
15
  return res.formData();
16
16
  }
17
- if (contentType == null ? void 0 : contentType.includes("application/octet-stream")) {
17
+ if (contentType === null || contentType === void 0 ? void 0 : contentType.includes("application/octet-stream")) {
18
18
  return res.arrayBuffer();
19
19
  }
20
20
  return res.text();
21
21
  };
22
- export {
23
- handleRes
24
- };
22
+ export { handleRes };
@@ -6,7 +6,7 @@ import { handleRes } from "./handleRes";
6
6
  let realRequest;
7
7
  let realAllowedHeaders = [];
8
8
  const originFetch = (...params) => nodeFetch(...params).then(handleRes);
9
- const configure = (options) => {
9
+ export const configure = (options) => {
10
10
  const { request, interceptor, allowedHeaders } = options;
11
11
  realRequest = request || originFetch;
12
12
  if (interceptor && !request) {
@@ -16,8 +16,10 @@ const configure = (options) => {
16
16
  realAllowedHeaders = allowedHeaders;
17
17
  }
18
18
  };
19
- const createRequest = (path, method, port, httpMethodDecider = "functionName", fetch = nodeFetch) => {
20
- const getFinalPath = compile(path, { encode: encodeURIComponent });
19
+ export const createRequest = (path, method, port, httpMethodDecider = "functionName", fetch = nodeFetch) => {
20
+ const getFinalPath = compile(path, {
21
+ encode: encodeURIComponent
22
+ });
21
23
  const keys = [];
22
24
  pathToRegexp(path, keys);
23
25
  const sender = (...args) => {
@@ -79,11 +81,11 @@ const createRequest = (path, method, port, httpMethodDecider = "functionName", f
79
81
  body = void 0;
80
82
  }
81
83
  headers.accept = `application/json,*/*;q=0.8`;
82
- return fetcher(url, { method, body, headers });
84
+ return fetcher(url, {
85
+ method,
86
+ body,
87
+ headers
88
+ });
83
89
  };
84
90
  return sender;
85
91
  };
86
- export {
87
- configure,
88
- createRequest
89
- };
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -3,7 +3,11 @@
3
3
  "description": "A Progressive React Framework for modern web development.",
4
4
  "homepage": "https://modernjs.dev",
5
5
  "bugs": "https://github.com/web-infra-dev/modern.js/issues",
6
- "repository": "web-infra-dev/modern.js",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/web-infra-dev/modern.js",
9
+ "directory": "packages/server/create-request"
10
+ },
7
11
  "license": "MIT",
8
12
  "keywords": [
9
13
  "react",
@@ -11,7 +15,7 @@
11
15
  "modern",
12
16
  "modern.js"
13
17
  ],
14
- "version": "2.15.0",
18
+ "version": "2.16.0",
15
19
  "jsnext:source": "./src/index.ts",
16
20
  "types": "./dist/types/index.d.ts",
17
21
  "main": "./dist/cjs/index.js",
@@ -60,7 +64,7 @@
60
64
  "node-fetch": "^2.6.1",
61
65
  "path-to-regexp": "^6.2.0",
62
66
  "query-string": "^7.1.1",
63
- "@modern-js/utils": "2.15.0"
67
+ "@modern-js/utils": "2.16.0"
64
68
  },
65
69
  "devDependencies": {
66
70
  "@types/jest": "^29",
@@ -70,9 +74,9 @@
70
74
  "jest": "^29",
71
75
  "nock": "^13.2.1",
72
76
  "typescript": "^4",
73
- "@modern-js/types": "2.15.0",
74
- "@scripts/build": "2.15.0",
75
- "@scripts/jest-config": "2.15.0"
77
+ "@modern-js/types": "2.16.0",
78
+ "@scripts/jest-config": "2.16.0",
79
+ "@scripts/build": "2.16.0"
76
80
  },
77
81
  "sideEffects": false,
78
82
  "publishConfig": {