@middy/http-content-encoding 3.0.0-alpha.1 → 3.0.0-alpha.5

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.
Files changed (2) hide show
  1. package/index.js +13 -4
  2. package/package.json +6 -5
package/index.js CHANGED
@@ -1,8 +1,7 @@
1
- import { Readable, Writable, pipeline as pipelineCallback } from 'stream';
1
+ import stream, { Readable, Writable } from 'stream';
2
2
  import { promisify } from 'util';
3
3
  import { createBrotliCompress, createGzip, createDeflate } from 'zlib';
4
4
  import { normalizeHttpResponse } from '@middy/util';
5
- const pipeline = promisify(pipelineCallback);
6
5
  const contentEncodingStreams = {
7
6
  br: (opts = {}) => createBrotliCompress(opts),
8
7
  gzip: (opts = {}) => createGzip(opts),
@@ -19,6 +18,7 @@ const httpContentEncodingMiddleware = opts => {
19
18
  const options = { ...defaults,
20
19
  ...opts
21
20
  };
21
+ const supportedContentEncodings = Object.keys(contentEncodingStreams);
22
22
 
23
23
  const httpContentEncodingMiddlewareAfter = async request => {
24
24
  normalizeHttpResponse(request);
@@ -30,7 +30,7 @@ const httpContentEncodingMiddleware = opts => {
30
30
  response
31
31
  } = request;
32
32
 
33
- if (!preferredEncoding || response.isBase64Encoded) {
33
+ if (response.isBase64Encoded || !preferredEncoding || !supportedContentEncodings.includes(preferredEncoding)) {
34
34
  return;
35
35
  }
36
36
 
@@ -85,6 +85,15 @@ const httpContentEncodingMiddleware = opts => {
85
85
  };
86
86
  };
87
87
 
88
- const isReadableStream = stream => typeof stream.pipe === 'function' && stream.readable !== false && typeof stream._read === 'function' && typeof stream._readableState === 'object';
88
+ const isReadableStream = stream => typeof (stream === null || stream === void 0 ? void 0 : stream.pipe) === 'function' && (stream === null || stream === void 0 ? void 0 : stream.readable) !== false && typeof (stream === null || stream === void 0 ? void 0 : stream._read) === 'function' && typeof (stream === null || stream === void 0 ? void 0 : stream._readableState) === 'object';
89
89
 
90
+ const polyfillPipelinePromise = () => {
91
+ if (process.version < 'v15.0.0') {
92
+ return promisify(stream.pipeline);
93
+ } else {
94
+ return stream.promises.pipeline;
95
+ }
96
+ };
97
+
98
+ const pipeline = polyfillPipelinePromise();
90
99
  export default httpContentEncodingMiddleware;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@middy/http-content-encoding",
3
- "version": "3.0.0-alpha.1",
3
+ "version": "3.0.0-alpha.5",
4
4
  "description": "Http content encoding middleware for the middy framework",
5
5
  "type": "module",
6
6
  "engines": {
@@ -18,7 +18,8 @@
18
18
  ],
19
19
  "scripts": {
20
20
  "test": "npm run test:unit",
21
- "test:unit": "ava"
21
+ "test:unit": "ava",
22
+ "test:benchmark": "node __benchmarks__/index.js"
22
23
  },
23
24
  "license": "MIT",
24
25
  "keywords": [
@@ -50,10 +51,10 @@
50
51
  },
51
52
  "homepage": "https://github.com/middyjs/middy#readme",
52
53
  "dependencies": {
53
- "@middy/util": "^3.0.0-alpha.1"
54
+ "@middy/util": "^3.0.0-alpha.5"
54
55
  },
55
56
  "devDependencies": {
56
- "@middy/core": "^3.0.0-alpha.1"
57
+ "@middy/core": "^3.0.0-alpha.5"
57
58
  },
58
- "gitHead": "a14125c6b2e21b181824f9985a919a47f1e4711f"
59
+ "gitHead": "cf6a1b02a2e163bea353b10146d67e0d95ef8072"
59
60
  }