From daad633195fc7f9494f8dacb665f8b7a5dbcecf1 Mon Sep 17 00:00:00 2001 From: n1474335 Date: Thu, 31 Oct 2019 14:17:07 +0000 Subject: [PATCH] Tidied up Avro to JSON operation --- src/core/operations/AvroToJSON.mjs | 27 +++++++++++-------------- src/core/operations/BSONDeserialise.mjs | 2 +- src/core/operations/BSONSerialise.mjs | 2 +- tests/operations/index.mjs | 2 +- tests/operations/tests/AvroToJSON.mjs | 1 - 5 files changed, 15 insertions(+), 19 deletions(-) diff --git a/src/core/operations/AvroToJSON.mjs b/src/core/operations/AvroToJSON.mjs index ee2b81a91..497a3872b 100644 --- a/src/core/operations/AvroToJSON.mjs +++ b/src/core/operations/AvroToJSON.mjs @@ -20,25 +20,26 @@ class AvroToJSON extends Operation { super(); this.name = "Avro to JSON"; - this.module = "Avro"; + this.module = "Serialise"; this.description = "Converts Avro encoded data into JSON."; - this.infoURL = "https://avro.apache.org/docs/current/spec.html"; + this.infoURL = "https://wikipedia.org/wiki/Apache_Avro"; this.inputType = "ArrayBuffer"; - this.outputType = "JSON"; - this.args = [{ - name: "Force Valid JSON", - type: "boolean", - value: true - }]; + this.outputType = "string"; + this.args = [ + { + name: "Force Valid JSON", + type: "boolean", + value: true + } + ]; } /** * @param {ArrayBuffer} input * @param {Object[]} args - * @returns {JSON} + * @returns {string} */ run(input, args) { - const self = this; if (input.byteLength <= 0) { throw new OperationError("Please provide an input."); } @@ -59,12 +60,8 @@ class AvroToJSON extends Operation { }) .on("end", function () { if (forceJSON) { - self.presentType = "JSON"; - self.outputType = "JSON"; - resolve(result.length === 1 ? result[0] : result); + resolve(result.length === 1 ? JSON.stringify(result[0], null, 4) : JSON.stringify(result, null, 4)); } else { - self.presentType = "string"; - self.outputType = "string"; const data = result.reduce((result, current) => result + JSON.stringify(current) + "\n", ""); resolve(data); } diff --git a/src/core/operations/BSONDeserialise.mjs b/src/core/operations/BSONDeserialise.mjs index a21eaadd3..cb46b357e 100644 --- a/src/core/operations/BSONDeserialise.mjs +++ b/src/core/operations/BSONDeserialise.mjs @@ -20,7 +20,7 @@ class BSONDeserialise extends Operation { super(); this.name = "BSON deserialise"; - this.module = "BSON"; + this.module = "Serialise"; this.description = "BSON is a computer data interchange format used mainly as a data storage and network transfer format in the MongoDB database. It is a binary form for representing simple data structures, associative arrays (called objects or documents in MongoDB), and various data types of specific interest to MongoDB. The name 'BSON' is based on the term JSON and stands for 'Binary JSON'.

Input data should be in a raw bytes format."; this.infoURL = "https://wikipedia.org/wiki/BSON"; this.inputType = "ArrayBuffer"; diff --git a/src/core/operations/BSONSerialise.mjs b/src/core/operations/BSONSerialise.mjs index 6d33c6be6..25eed876d 100644 --- a/src/core/operations/BSONSerialise.mjs +++ b/src/core/operations/BSONSerialise.mjs @@ -20,7 +20,7 @@ class BSONSerialise extends Operation { super(); this.name = "BSON serialise"; - this.module = "BSON"; + this.module = "Serialise"; this.description = "BSON is a computer data interchange format used mainly as a data storage and network transfer format in the MongoDB database. It is a binary form for representing simple data structures, associative arrays (called objects or documents in MongoDB), and various data types of specific interest to MongoDB. The name 'BSON' is based on the term JSON and stands for 'Binary JSON'.

Input data should be valid JSON."; this.infoURL = "https://wikipedia.org/wiki/BSON"; this.inputType = "string"; diff --git a/tests/operations/index.mjs b/tests/operations/index.mjs index a15038142..71c4432cc 100644 --- a/tests/operations/index.mjs +++ b/tests/operations/index.mjs @@ -91,7 +91,7 @@ import "./tests/Protobuf.mjs"; import "./tests/ParseSSHHostKey.mjs"; import "./tests/DefangIP.mjs"; import "./tests/ParseUDP.mjs"; -import "./tests/AvroToJSON"; +import "./tests/AvroToJSON.mjs"; // Cannot test operations that use the File type yet // import "./tests/SplitColourChannels.mjs"; diff --git a/tests/operations/tests/AvroToJSON.mjs b/tests/operations/tests/AvroToJSON.mjs index b6e763adf..045abddbc 100644 --- a/tests/operations/tests/AvroToJSON.mjs +++ b/tests/operations/tests/AvroToJSON.mjs @@ -1,5 +1,4 @@ /** - * * Avro to JSON tests. * * @author jarrodconnolly [jarrod@nestedquotes.ca]