@wooksjs/http-body 0.4.10 → 0.4.12

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/index.cjs CHANGED
@@ -2,55 +2,21 @@
2
2
 
3
3
  var eventHttp = require('@wooksjs/event-http');
4
4
 
5
- /******************************************************************************
6
- Copyright (c) Microsoft Corporation.
7
-
8
- Permission to use, copy, modify, and/or distribute this software for any
9
- purpose with or without fee is hereby granted.
10
-
11
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
12
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
13
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
14
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
16
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17
- PERFORMANCE OF THIS SOFTWARE.
18
- ***************************************************************************** */
19
- /* global Reflect, Promise, SuppressedError, Symbol */
20
-
21
-
22
- function __awaiter(thisArg, _arguments, P, generator) {
23
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
24
- return new (P || (P = Promise))(function (resolve, reject) {
25
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
26
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
27
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
28
- step((generator = generator.apply(thisArg, _arguments || [])).next());
29
- });
30
- }
31
-
32
- typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
33
- var e = new Error(message);
34
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
35
- };
36
-
37
5
  const compressors = {
38
6
  identity: {
39
7
  compress: (v) => v,
40
8
  uncompress: (v) => v,
41
9
  },
42
10
  };
43
- function uncompressBody(encodings, body) {
44
- return __awaiter(this, void 0, void 0, function* () {
45
- let newBody = body;
46
- for (const e of encodings.reverse()) {
47
- if (!compressors[e]) {
48
- throw new Error(`Usupported compression type "${e}".`);
49
- }
50
- newBody = yield compressors[e].uncompress(body);
11
+ async function uncompressBody(encodings, body) {
12
+ let newBody = body;
13
+ for (const e of encodings.reverse()) {
14
+ if (!compressors[e]) {
15
+ throw new Error(`Usupported compression type "${e}".`);
51
16
  }
52
- return newBody;
53
- });
17
+ newBody = await compressors[e].uncompress(body);
18
+ }
19
+ return newBody;
54
20
  }
55
21
 
56
22
  function useBody() {
@@ -80,8 +46,8 @@ function useBody() {
80
46
  .split(',')
81
47
  .map((p) => p.trim())
82
48
  .filter((p) => !!p));
83
- const parseBody = () => init('parsed', () => __awaiter(this, void 0, void 0, function* () {
84
- const body = yield uncompressBody(contentEncodings(), (yield rawBody()).toString());
49
+ const parseBody = () => init('parsed', async () => {
50
+ const body = await uncompressBody(contentEncodings(), (await rawBody()).toString());
85
51
  if (isJson())
86
52
  return jsonParser(body);
87
53
  else if (isFormData())
@@ -92,7 +58,7 @@ function useBody() {
92
58
  return textParser(body);
93
59
  else
94
60
  return textParser(body);
95
- }));
61
+ });
96
62
  function jsonParser(v) {
97
63
  try {
98
64
  return JSON.parse(v);
package/dist/index.d.ts CHANGED
@@ -1,24 +1,21 @@
1
- /// <reference types="node" />
2
-
3
- export declare function registerBodyCompressor(name: string, compressor: TBodyCompressor): void;
4
-
5
- declare type TBodyCompressor = {
6
- compress: (data: string) => string | Promise<string>;
7
- uncompress: (data: string) => string | Promise<string>;
8
- };
9
-
10
- export declare function useBody(): {
11
- isJson: () => boolean;
12
- isHtml: () => boolean;
13
- isXml: () => boolean;
14
- isText: () => boolean;
15
- isBinary: () => boolean;
16
- isFormData: () => boolean;
17
- isUrlencoded: () => boolean;
18
- isCompressed: () => boolean;
19
- contentEncodings: () => string[];
20
- parseBody: () => Promise<unknown> | undefined;
21
- rawBody: () => Promise<Buffer>;
22
- };
23
-
24
- export { }
1
+ type TBodyCompressor = {
2
+ compress: (data: string) => string | Promise<string>;
3
+ uncompress: (data: string) => string | Promise<string>;
4
+ };
5
+
6
+ declare function useBody(): {
7
+ isJson: () => boolean;
8
+ isHtml: () => boolean;
9
+ isXml: () => boolean;
10
+ isText: () => boolean;
11
+ isBinary: () => boolean;
12
+ isFormData: () => boolean;
13
+ isUrlencoded: () => boolean;
14
+ isCompressed: () => boolean;
15
+ contentEncodings: () => string[];
16
+ parseBody: () => Promise<unknown> | undefined;
17
+ rawBody: () => Promise<Buffer>;
18
+ };
19
+ declare function registerBodyCompressor(name: string, compressor: TBodyCompressor): void;
20
+
21
+ export { registerBodyCompressor, useBody };
package/dist/index.mjs CHANGED
@@ -1,54 +1,20 @@
1
1
  import { useHttpContext, useRequest, useHeaders, HttpError, EHttpStatusCode, WooksURLSearchParams } from '@wooksjs/event-http';
2
2
 
3
- /******************************************************************************
4
- Copyright (c) Microsoft Corporation.
5
-
6
- Permission to use, copy, modify, and/or distribute this software for any
7
- purpose with or without fee is hereby granted.
8
-
9
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
10
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
12
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
14
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15
- PERFORMANCE OF THIS SOFTWARE.
16
- ***************************************************************************** */
17
- /* global Reflect, Promise, SuppressedError, Symbol */
18
-
19
-
20
- function __awaiter(thisArg, _arguments, P, generator) {
21
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
22
- return new (P || (P = Promise))(function (resolve, reject) {
23
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
24
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
25
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
26
- step((generator = generator.apply(thisArg, _arguments || [])).next());
27
- });
28
- }
29
-
30
- typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
31
- var e = new Error(message);
32
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
33
- };
34
-
35
3
  const compressors = {
36
4
  identity: {
37
5
  compress: (v) => v,
38
6
  uncompress: (v) => v,
39
7
  },
40
8
  };
41
- function uncompressBody(encodings, body) {
42
- return __awaiter(this, void 0, void 0, function* () {
43
- let newBody = body;
44
- for (const e of encodings.reverse()) {
45
- if (!compressors[e]) {
46
- throw new Error(`Usupported compression type "${e}".`);
47
- }
48
- newBody = yield compressors[e].uncompress(body);
9
+ async function uncompressBody(encodings, body) {
10
+ let newBody = body;
11
+ for (const e of encodings.reverse()) {
12
+ if (!compressors[e]) {
13
+ throw new Error(`Usupported compression type "${e}".`);
49
14
  }
50
- return newBody;
51
- });
15
+ newBody = await compressors[e].uncompress(body);
16
+ }
17
+ return newBody;
52
18
  }
53
19
 
54
20
  function useBody() {
@@ -78,8 +44,8 @@ function useBody() {
78
44
  .split(',')
79
45
  .map((p) => p.trim())
80
46
  .filter((p) => !!p));
81
- const parseBody = () => init('parsed', () => __awaiter(this, void 0, void 0, function* () {
82
- const body = yield uncompressBody(contentEncodings(), (yield rawBody()).toString());
47
+ const parseBody = () => init('parsed', async () => {
48
+ const body = await uncompressBody(contentEncodings(), (await rawBody()).toString());
83
49
  if (isJson())
84
50
  return jsonParser(body);
85
51
  else if (isFormData())
@@ -90,7 +56,7 @@ function useBody() {
90
56
  return textParser(body);
91
57
  else
92
58
  return textParser(body);
93
- }));
59
+ });
94
60
  function jsonParser(v) {
95
61
  try {
96
62
  return JSON.parse(v);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wooksjs/http-body",
3
- "version": "0.4.10",
3
+ "version": "0.4.12",
4
4
  "description": "@wooksjs/http-body",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.mjs",
@@ -8,6 +8,14 @@
8
8
  "files": [
9
9
  "dist"
10
10
  ],
11
+ "exports": {
12
+ "./package.json": "./package.json",
13
+ ".": {
14
+ "require": "./dist/index.cjs",
15
+ "import": "./dist/index.mjs",
16
+ "types": "./dist/index.d.ts"
17
+ }
18
+ },
11
19
  "repository": {
12
20
  "type": "git",
13
21
  "url": "git+https://github.com/wooksjs/wooksjs.git",
@@ -31,7 +39,7 @@
31
39
  "url": "https://github.com/wooksjs/wooksjs/issues"
32
40
  },
33
41
  "peerDependencies": {
34
- "@wooksjs/event-http": "0.4.10"
42
+ "@wooksjs/event-http": "0.4.12"
35
43
  },
36
44
  "homepage": "https://github.com/wooksjs/wooksjs/tree/main/packages/http-body#readme"
37
45
  }