Skip to content

Commit 0c6454e

Browse files
authored
fix: jq-web -> jq-wasm, includes jq version 1.8.1 (gchq#2223)
Co-authored-by: GCHQDeveloper581 <63102987+GCHQDeveloper581@users.noreply.github.com> (added tests)
1 parent cd7dafd commit 0c6454e

File tree

4 files changed

+26
-18
lines changed

4 files changed

+26
-18
lines changed

package-lock.json

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@
135135
"highlight.js": "^11.11.1",
136136
"ieee754": "^1.2.1",
137137
"jimp": "^1.6.0",
138-
"jq-web": "^0.6.2",
138+
"jq-wasm": "^1.1.0-jq-1.8.1",
139139
"jquery": "3.7.1",
140140
"js-sha3": "^0.9.3",
141141
"jsesc": "^3.1.0",

src/core/operations/Jq.mjs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import Operation from "../Operation.mjs";
88
import OperationError from "../errors/OperationError.mjs";
9-
import jq from "jq-web";
9+
import * as jq from "jq-wasm";
1010

1111
/**
1212
* jq operation
@@ -40,16 +40,15 @@ class Jq extends Operation {
4040
* @returns {string}
4141
*/
4242
run(input, args) {
43-
const [query] = args;
44-
let result;
45-
46-
try {
47-
result = jq.json(input, query);
48-
} catch (err) {
49-
throw new OperationError(`Invalid jq expression: ${err.message}`);
50-
}
51-
52-
return JSON.stringify(result);
43+
return (async () => {
44+
const [query] = args;
45+
try {
46+
const result = await jq.json(input, query);
47+
return JSON.stringify(result);
48+
} catch (err) {
49+
throw new OperationError(`Invalid jq expression: ${err.message}`);
50+
}
51+
})();
5352
}
5453

5554
}

tests/browser/02_ops.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,14 @@ module.exports = {
5050
testOp(browser, "Analyse hash", "0123456789abcdef", /CRC-64/);
5151
testOp(browser, "Atbash Cipher", "test input", "gvhg rmkfg");
5252
// testOp(browser, "Avro to JSON", "test input", "test_output");
53+
testOp(browser,
54+
[
55+
"From Hex", "Avro to JSON"
56+
],
57+
"4f626a0104166176726f2e736368656d6196017b2274797065223a227265636f7264222c226e616d65223a22736d616c6c222c226669656c6473223a5b7b226e616d65223a226e616d65222c2274797065223a22737472696e67227d5d7d146176726f2e636f646563086e756c6c004e0247632e3702e5b75cdab9a62f1541020e0c6d796e616d654e0247632e3702e5b75cdab9a62f1541",
58+
'{"name":"myname"}\n',
59+
[[], [false]]
60+
);
5361
testOp(browser, "BLAKE2b", "test input", "33ebdc8f38177f3f3f334eeb117a84e11f061bbca4db6b8923e5cec85103f59f415551a5d5a933fdb6305dc7bf84671c2540b463dbfa08ee1895cfaa5bd780b5", ["512", "Hex", { "option": "UTF8", "string": "pass" }]);
5462
testOp(browser, "BLAKE2s", "test input", "defe73d61dfa6e5807e4f9643e159a09ccda6be3c26dcd65f8a9bb38bfc973a7", ["256", "Hex", { "option": "UTF8", "string": "pass" }]);
5563
testOp(browser, "BSON deserialise", "\u0011\u0000\u0000\u0000\u0002a\u0000\u0005\u0000\u0000\u0000test\u0000\u0000", '{\u000A "a": "test"\u000A}');
@@ -206,6 +214,7 @@ module.exports = {
206214
testOpHtml(browser, "Index of Coincidence", "test input", "", /Index of Coincidence: 0.08333333333333333/);
207215
testOpImage(browser, "Invert Image", "files/Hitchhikers_Guide.jpeg");
208216
// testOp(browser, "JPath expression", "test input", "test_output");
217+
testOp(browser, "Jq", '{"a":{"b":1}}', '{"b":1}', [".a"]);
209218
testOpHtml(browser, "JSON Beautify", "{a:1}", ".json-dict .json-literal", "1");
210219
// testOp(browser, "JSON Minify", "test input", "test_output");
211220
// testOp(browser, "JSON to CSV", "test input", "test_output");

0 commit comments

Comments
 (0)