chore: udpate based on jon changes

This commit is contained in:
Martin Patino 2024-02-09 17:22:31 -07:00
parent df6668fb7c
commit 74297b6e13
No known key found for this signature in database
GPG Key ID: 76B3D61125CD7514
4 changed files with 86 additions and 10 deletions

27
package-lock.json generated
View File

@ -50,6 +50,7 @@
"js-sha3": "^0.9.3",
"jsesc": "^3.0.2",
"json5": "^2.2.3",
"jsonata": "^2.0.3",
"jsonpath-plus": "^8.0.0",
"jsonwebtoken": "8.5.1",
"jsqr": "^1.4.0",
@ -114,7 +115,7 @@
"babel-plugin-dynamic-import-node": "^2.3.3",
"babel-plugin-transform-builtin-extend": "1.1.2",
"base64-loader": "^1.0.0",
"chromedriver": "^121.0.0",
"chromedriver": "^114.0.2",
"cli-progress": "^3.12.0",
"colors": "^1.4.0",
"copy-webpack-plugin": "^12.0.2",
@ -4896,25 +4897,25 @@
}
},
"node_modules/chromedriver": {
"version": "121.0.0",
"resolved": "https://registry.npmjs.org/chromedriver/-/chromedriver-121.0.0.tgz",
"integrity": "sha512-ZIKEdZrQAfuzT/RRofjl8/EZR99ghbdBXNTOcgJMKGP6N/UL6lHUX4n6ONWBV18pDvDFfQJ0x58h5AdOaXIOMw==",
"version": "114.0.3",
"resolved": "https://registry.npmjs.org/chromedriver/-/chromedriver-114.0.3.tgz",
"integrity": "sha512-Qy5kqsAUrCDwpovM5pIWFkb3X3IgJLoorigwFEDgC1boL094svny3N7yw06marJHAuyX4CE/hhd25RarIcKvKg==",
"dev": true,
"hasInstallScript": true,
"dependencies": {
"@testim/chrome-version": "^1.1.4",
"axios": "^1.6.5",
"compare-versions": "^6.1.0",
"@testim/chrome-version": "^1.1.3",
"axios": "^1.4.0",
"compare-versions": "^6.0.0",
"extract-zip": "^2.0.1",
"https-proxy-agent": "^5.0.1",
"proxy-from-env": "^1.1.0",
"tcp-port-used": "^1.0.2"
"tcp-port-used": "^1.0.1"
},
"bin": {
"chromedriver": "bin/chromedriver"
},
"engines": {
"node": ">=18"
"node": ">=16"
}
},
"node_modules/ci-info": {
@ -9782,6 +9783,14 @@
"node": ">=6"
}
},
"node_modules/jsonata": {
"version": "2.0.3",
"resolved": "https://registry.npmjs.org/jsonata/-/jsonata-2.0.3.tgz",
"integrity": "sha512-Up2H81MUtjqI/dWwWX7p4+bUMfMrQJVMN/jW6clFMTiYP528fBOBNtRu944QhKTs3+IsVWbgMeUTny5fw2VMUA==",
"engines": {
"node": ">= 8"
}
},
"node_modules/jsonpath-plus": {
"version": "8.0.0",
"resolved": "https://registry.npmjs.org/jsonpath-plus/-/jsonpath-plus-8.0.0.tgz",

View File

@ -56,7 +56,7 @@
"babel-plugin-dynamic-import-node": "^2.3.3",
"babel-plugin-transform-builtin-extend": "1.1.2",
"base64-loader": "^1.0.0",
"chromedriver": "^121.0.0",
"chromedriver": "^114.0.2",
"cli-progress": "^3.12.0",
"colors": "^1.4.0",
"copy-webpack-plugin": "^12.0.2",
@ -133,6 +133,7 @@
"js-sha3": "^0.9.3",
"jsesc": "^3.0.2",
"json5": "^2.2.3",
"jsonata": "^2.0.3",
"jsonpath-plus": "^8.0.0",
"jsonwebtoken": "8.5.1",
"jsqr": "^1.4.0",

View File

@ -330,6 +330,7 @@
"Regular expression",
"XPath expression",
"JPath expression",
"Jsonata Query",
"CSS selector",
"Extract EXIF",
"Extract ID3",

View File

@ -0,0 +1,65 @@
/**
* @author Jon K (jon@ajarsoftware.com)
* @copyright Crown Copyright 2016
* @license Apache-2.0
*/
import jsonata from "jsonata";
import Operation from "../Operation.mjs";
import OperationError from "../errors/OperationError.mjs";
/**
* Jsonata Query operation
*/
class JsonataQuery extends Operation {
/**
* JsonataQuery constructor
*/
constructor() {
super();
this.name = "Jsonata Query";
this.module = "Code";
this.description =
"Query and transform JSON data with a jsonata query.";
this.infoURL = "https://docs.jsonata.org/overview.html";
this.inputType = "string";
this.outputType = "string";
this.args = [
{
name: "Query",
type: "text",
value: "string",
},
];
}
/**
* @param {string} input
* @param {Object[]} args
* @returns {string}
*/
async run(input, args) {
const [query] = args;
let result, jsonObj;
try {
jsonObj = JSON.parse(input);
} catch (err) {
throw new OperationError(`Invalid input JSON: ${err.message}`);
}
try {
const expression = jsonata(query);
result = await expression.evaluate(jsonObj);
} catch (err) {
throw new OperationError(
`Invalid Jsonata Expression: ${err.message}`
);
}
return JSON.stringify(result);
}
}
export default JsonataQuery;