From bfd7f251764b38e720a07070420be87eac80250e Mon Sep 17 00:00:00 2001 From: Grant Timmerman Date: Fri, 1 May 2020 10:24:53 -0700 Subject: [PATCH 1/2] chore: es6 unmarshaller Signed-off-by: Grant Timmerman chore: fix lint multiline if Signed-off-by: Grant Timmerman Update lib/bindings/http/unmarshaller.js Co-authored-by: Lance Ball fix: fix pr suggestion errors Signed-off-by: Grant Timmerman refactor: fix DCO in PR Signed-off-by: Grant Timmerman fix: fix pr suggestion errors Signed-off-by: Grant Timmerman --- lib/bindings/http/unmarshaller.js | 54 +++++++++++++++---------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/lib/bindings/http/unmarshaller.js b/lib/bindings/http/unmarshaller.js index a45c21cb..cfe41662 100644 --- a/lib/bindings/http/unmarshaller.js +++ b/lib/bindings/http/unmarshaller.js @@ -4,22 +4,14 @@ const Commons = require("./commons.js"); const STRUCTURED = "structured"; const BINARY = "binary"; -const allowedBinaryContentTypes = []; -allowedBinaryContentTypes.push(Constants.MIME_JSON); -allowedBinaryContentTypes.push(Constants.MIME_OCTET_STREAM); +const allowedBinaryContentTypes = [ + Constants.MIME_JSON, + Constants.MIME_OCTET_STREAM +]; -const allowedStructuredContentTypes = []; -allowedStructuredContentTypes.push(Constants.MIME_CE_JSON); - -function validateArgs(payload, headers) { - if (!payload) { - throw new TypeError("payload is null or undefined"); - } - - if (!headers) { - throw new TypeError("headers is null or undefined"); - } -} +const allowedStructuredContentTypes = [ + Constants.MIME_CE_JSON +]; // Is it binary or structured? function resolveBindingName(payload, headers) { @@ -47,18 +39,28 @@ function resolveBindingName(payload, headers) { } } -const Unmarshaller = function(receiverByBinding) { - this.receiverByBinding = receiverByBinding; -}; +class Unmarshaller { + constructor(receiverByBinding) { + this.receiverByBinding = receiverByBinding; + } -Unmarshaller.prototype.unmarshall = function(payload, headers) { - return new Promise((resolve, reject) => { - try { - validateArgs(payload, headers); + unmarshall(payload, headers) { + return new Promise((resolve, reject) => { + if (!payload) { + return reject(new TypeError("payload is null or undefined")); + } + if (!headers) { + return reject(new TypeError("headers is null or undefined")); + } +<<<<<<< HEAD + // Validation level 1 + const sanityHeaders = Commons.sanityAndClone(headers); +======= const sanityHeaders = Commons.sanityAndClone(headers); // Validation level 1 +>>>>>>> c722b03... fix: fix pr suggestion errors if (!sanityHeaders[Constants.HEADER_CONTENT_TYPE]) { throw new TypeError("content-type header not found"); } @@ -69,10 +71,8 @@ Unmarshaller.prototype.unmarshall = function(payload, headers) { .parse(payload, sanityHeaders); resolve(cloudevent); - } catch (e) { - reject(e); - } - }); -}; + }); + } +} module.exports = Unmarshaller; From 5ab8b1d24c49966cbcd56f42d261edef2b94d98f Mon Sep 17 00:00:00 2001 From: Grant Timmerman Date: Tue, 5 May 2020 12:57:58 -0700 Subject: [PATCH 2/2] refactor: merge conflict Signed-off-by: Grant Timmerman --- lib/bindings/http/unmarshaller.js | 6 ------ 1 file changed, 6 deletions(-) diff --git a/lib/bindings/http/unmarshaller.js b/lib/bindings/http/unmarshaller.js index cfe41662..4476f25a 100644 --- a/lib/bindings/http/unmarshaller.js +++ b/lib/bindings/http/unmarshaller.js @@ -53,14 +53,8 @@ class Unmarshaller { return reject(new TypeError("headers is null or undefined")); } -<<<<<<< HEAD // Validation level 1 const sanityHeaders = Commons.sanityAndClone(headers); -======= - const sanityHeaders = Commons.sanityAndClone(headers); - - // Validation level 1 ->>>>>>> c722b03... fix: fix pr suggestion errors if (!sanityHeaders[Constants.HEADER_CONTENT_TYPE]) { throw new TypeError("content-type header not found"); }