Code style: camelCase

Signed-off-by: Fabio José <fabiojose@gmail.com>
This commit is contained in:
Fabio José 2019-07-23 13:51:33 -03:00
parent 5ec82401ec
commit 162e78f507
1 changed files with 14 additions and 14 deletions

View File

@ -7,18 +7,18 @@ const Commons = require("./commons.js");
const structured = "structured"; const structured = "structured";
const binary = "binary"; const binary = "binary";
const receiver_by_binding = { const receiverByBinding = {
structured : new StructuredReceiver(), structured : new StructuredReceiver(),
binary : new BinaryReceiver(), binary : new BinaryReceiver(),
}; };
const allowed_binary_content_types = []; const allowedBinaryContentTypes = [];
allowed_binary_content_types.push(Constants.MIME_JSON); allowedBinaryContentTypes.push(Constants.MIME_JSON);
const allowed_structured_content_types = []; const allowedStructuredContentTypes = [];
allowed_structured_content_types.push(Constants.MIME_CE_JSON); allowedStructuredContentTypes.push(Constants.MIME_CE_JSON);
function validate_args(payload, headers) { function validateArgs(payload, headers) {
if(!payload){ if(!payload){
throw {message: "payload is null or undefined"}; throw {message: "payload is null or undefined"};
} }
@ -29,19 +29,19 @@ function validate_args(payload, headers) {
} }
// Is it binary or structured? // Is it binary or structured?
function resolve_binding_name(payload, headers) { function resolveBindingName(payload, headers) {
var contentType = headers[Constants.HEADER_CONTENT_TYPE]; var contentType = headers[Constants.HEADER_CONTENT_TYPE];
if(contentType.startsWith(Constants.MIME_CE)){ if(contentType.startsWith(Constants.MIME_CE)){
// Structured // Structured
if(allowed_structured_content_types.includes(contentType)){ if(allowedStructuredContentTypes.includes(contentType)){
return structured; return structured;
} else { } else {
throw {message: "structured+type not allowed", errors: [contentType]}; throw {message: "structured+type not allowed", errors: [contentType]};
} }
} else { } else {
// Binary // Binary
if(allowed_binary_content_types.includes(contentType)){ if(allowedBinaryContentTypes.includes(contentType)){
return binary; return binary;
} else { } else {
throw {message: "content type not allowed", errors : [contentType]}; throw {message: "content type not allowed", errors : [contentType]};
@ -56,20 +56,20 @@ var Unmarshaller = function() {
Unmarshaller.prototype.unmarshall = function(payload, headers) { Unmarshaller.prototype.unmarshall = function(payload, headers) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
try { try {
validate_args(payload, headers); validateArgs(payload, headers);
var sanity_headers = Commons.sanity_and_clone(headers); var sanityHeaders = Commons.sanity_and_clone(headers);
// Validation level 1 // Validation level 1
if(!sanity_headers[Constants.HEADER_CONTENT_TYPE]){ if(!sanityHeaders[Constants.HEADER_CONTENT_TYPE]){
throw {message: "content-type header not found"}; throw {message: "content-type header not found"};
} }
// Resolve the binding // Resolve the binding
var binding_name = resolve_binding_name(payload, sanity_headers); var bindingName = resolveBindingName(payload, sanityHeaders);
var cloudevent = var cloudevent =
receiver_by_binding[binding_name].parse(payload, sanity_headers); receiverByBinding[bindingName].parse(payload, sanityHeaders);
resolve(cloudevent); resolve(cloudevent);
}catch(e){ }catch(e){