@jwn-js/common 2.0.34 → 2.0.35

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/jsonBody.js CHANGED
@@ -4,10 +4,8 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var ApiError = require('./ApiError-b517f53a.js');
6
6
 
7
- const jsonBody = (res, req) => new Promise((resolve, reject) => {
8
- readJson(res, (obj) => {
9
- resolve(obj);
10
- }, (e) => {
7
+ const jsonBody = (res) => new Promise((resolve, reject) => {
8
+ readJson(res, (obj) => resolve(obj), () => {
11
9
  reject(new ApiError.ApiError({ message: "Can`t parse request", code: 1, statusCode: 404 }));
12
10
  });
13
11
  });
@@ -20,7 +18,6 @@ function readJson(res, cb, err) {
20
18
  cb(JSON.parse(buffer.toString()));
21
19
  } catch (e) {
22
20
  cb({});
23
- return;
24
21
  }
25
22
  }
26
23
  });
package/multipartBody.js CHANGED
@@ -18,11 +18,9 @@ const multipartBody = (res, req, options = { multiples: true }) => new Promise(a
18
18
  stream$1.headers = {};
19
19
  req.forEach((key, val) => stream$1.headers[key] = val);
20
20
  res.onData((chunk, isLast) => {
21
- stream$1.write(Buffer.from(Buffer.from(chunk)));
21
+ stream$1.write(Buffer.from(chunk));
22
22
  stream$1.resume();
23
- if (isLast) {
24
- stream$1.end();
25
- }
23
+ isLast && stream$1.end();
26
24
  });
27
25
  const form = formidable__default["default"](options);
28
26
  const adapter = (row) => ({
@@ -34,9 +32,7 @@ const multipartBody = (res, req, options = { multiples: true }) => new Promise(a
34
32
  newFilename: row.newFilename
35
33
  });
36
34
  form.parse(stream$1, (err2, fields, files) => {
37
- if (err2) {
38
- reject(err2);
39
- }
35
+ err2 && reject(err2);
40
36
  const output = {};
41
37
  Object.keys(files).map((key) => {
42
38
  output[key] = Array.isArray(files[key]) ? files[key].map((row) => adapter(row)) : adapter(files[key]);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@jwn-js/common",
3
3
  "private": false,
4
- "version": "2.0.34",
4
+ "version": "2.0.35",
5
5
  "description": "@jwn-js/common package",
6
6
  "main": "./index.js",
7
7
  "types": "./index.d.ts",
@@ -43,7 +43,7 @@
43
43
  "zlib": "^1.0.5"
44
44
  },
45
45
  "dependencies": {
46
- "buildmsql": "^1.3.16",
46
+ "buildmsql": "^1.3.17",
47
47
  "easy-ash": "^1.1.7",
48
48
  "formidable": "2",
49
49
  "memjs": "^1.3.0",
package/staticBody.d.ts CHANGED
@@ -7,15 +7,10 @@ declare const exts: Record<string, string>;
7
7
  declare const extensions: Array<string>;
8
8
  /**
9
9
  * Get extension from path
10
- * @param path
11
- * @return {string}
12
10
  */
13
11
  declare const getExt: (path: string) => string;
14
12
  /**
15
13
  * Reed static files
16
- * @param req
17
- * @param res
18
- * @param base
19
14
  */
20
15
  declare function staticBody(res: HttpResponse, req: HttpRequest, base: string): Promise<void>;
21
16
 
@@ -1,10 +1,9 @@
1
- import { HttpResponse, HttpRequest } from 'uWebSockets.js';
1
+ import { HttpResponse } from 'uWebSockets.js';
2
2
 
3
3
  /**
4
4
  * @description
5
5
  * Parser of form urlencoded requests body
6
- * @throws {ApiError}
7
6
  */
8
- declare const urlencodedBody: (res: HttpResponse, req?: HttpRequest) => Promise<any>;
7
+ declare const urlencodedBody: (res: HttpResponse) => Promise<any>;
9
8
 
10
9
  export { urlencodedBody };
package/urlencodedBody.js CHANGED
@@ -9,10 +9,8 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
9
9
 
10
10
  var querystring__default = /*#__PURE__*/_interopDefaultLegacy(querystring);
11
11
 
12
- const urlencodedBody = (res, req) => new Promise((resolve, reject) => {
13
- readBody(res, (obj) => {
14
- resolve(obj);
15
- }, (e) => {
12
+ const urlencodedBody = (res) => new Promise((resolve, reject) => {
13
+ readBody(res, (obj) => resolve(obj), () => {
16
14
  reject(new ApiError.ApiError({ message: "Can`t parse body", code: 1, statusCode: 404 }));
17
15
  });
18
16
  });
@@ -24,8 +22,7 @@ function readBody(res, cb, err) {
24
22
  try {
25
23
  cb(querystring__default["default"].parse(buffer.toString()));
26
24
  } catch (e) {
27
- cb(null);
28
- return;
25
+ cb({});
29
26
  }
30
27
  }
31
28
  });