-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
34 lines (29 loc) · 781 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
const proto2protoj = require('protocol-buffers-schema');
const protoj2jsonSchema = require('./protoj2jsonSchema');
module.exports = {
parse,
getMimeTypes
};
async function parse({ message, defaultSchemaFormat }) {
try {
const payload = message.payload;
const jsonModel = protoj2jsonSchema(
proto2protoj(payload),
{
getOne: true,
}
);
message['x-parser-original-schema-format'] = message.schemaFormat || defaultSchemaFormat;
message['x-parser-original-payload'] = payload;
message.payload = jsonModel;
delete message.schemaFormat;
} catch (e) {
console.error(e);
}
}
function getMimeTypes() {
return [
'application/vnd.google.protobuf;version=2',
'application/vnd.google.protobuf;version=3',
];
}