Umarchaller impl start

Signed-off-by: Fabio José <fabiojose@gmail.com>
This commit is contained in:
Fabio José 2019-06-09 21:04:41 -03:00
parent 25c4ad27f7
commit a3884160be
1 changed files with 40 additions and 0 deletions

View File

@ -0,0 +1,40 @@
const content_type_header = "content-type";
const ce_structured_content_type = "application/cloudevents";
/**
* Level 0 of validation: is that string? is that JSON?
*/
function validate_and_parse_as_json(payload) {
var json = payload;
if( (typeof payload) === "string"){
try {
json = JSON.parse(payload);
}catch(e) {
throw {message: "Invalid payload", errors: e};
}
} else if( (typeof payload) !== "object"){
// anything else
throw {message: "Invalid payload type, allowed are: string or object"};
}
return json;
}
var Unmarshaller = function() {
}
Unmarshaller.prototype.unmarshall = function(payload, headers) {
var valid0 = validate_and_parse_as_json(payload);
//TODO binary or structured ?
//"Content-Type"
}
module.exports = Unmarshaller;