Add xml2json and json2xml functions (#2022)
This commit is contained in:
parent
1cafbca767
commit
df902440f5
64
app/client/cypress/fixtures/xmlParser.json
Normal file
64
app/client/cypress/fixtures/xmlParser.json
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
{
|
||||
"dsl": {
|
||||
"widgetName": "MainContainer",
|
||||
"backgroundColor": "none",
|
||||
"rightColumn": 1224,
|
||||
"snapColumns": 16,
|
||||
"detachFromLayout": true,
|
||||
"widgetId": "0",
|
||||
"topRow": 0,
|
||||
"bottomRow": 1280,
|
||||
"containerStyle": "none",
|
||||
"snapRows": 33,
|
||||
"parentRowSpace": 1,
|
||||
"type": "CANVAS_WIDGET",
|
||||
"canExtend": true,
|
||||
"version": 7,
|
||||
"minHeight": 1292,
|
||||
"parentColumnSpace": 1,
|
||||
"leftColumn": 0,
|
||||
"dynamicBindingPathList": [],
|
||||
"children": [
|
||||
{
|
||||
"isVisible": true,
|
||||
"text": "{{xmlParser.parse(Input1.text) }}",
|
||||
"textStyle": "LABEL",
|
||||
"textAlign": "LEFT",
|
||||
"widgetName": "Text1",
|
||||
"type": "TEXT_WIDGET",
|
||||
"isLoading": false,
|
||||
"parentColumnSpace": 74,
|
||||
"parentRowSpace": 40,
|
||||
"leftColumn": 3,
|
||||
"rightColumn": 8,
|
||||
"topRow": 3,
|
||||
"bottomRow": 10,
|
||||
"parentId": "0",
|
||||
"widgetId": "axlcnmjk4t",
|
||||
"dynamicBindingPathList": [
|
||||
{
|
||||
"key": "text"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"isVisible": true,
|
||||
"inputType": "TEXT",
|
||||
"label": "",
|
||||
"widgetName": "Input1",
|
||||
"type": "INPUT_WIDGET",
|
||||
"isLoading": false,
|
||||
"parentColumnSpace": 74,
|
||||
"parentRowSpace": 40,
|
||||
"leftColumn": 3,
|
||||
"rightColumn": 8,
|
||||
"topRow": 2,
|
||||
"bottomRow": 3,
|
||||
"parentId": "0",
|
||||
"widgetId": "8n5urob9mz",
|
||||
"dynamicBindingPathList": [],
|
||||
"defaultText": "<note> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend!</body> </note>"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
const dsl = require("../../../fixtures/xmlParser.json");
|
||||
const publish = require("../../../locators/publishWidgetspage.json");
|
||||
|
||||
describe("xml2json text", function() {
|
||||
before(() => {
|
||||
cy.addDsl(dsl);
|
||||
});
|
||||
it("publish widget and validate the data displayed in text widget from xmlParser function", function() {
|
||||
cy.PublishtheApp();
|
||||
cy.get(publish.textWidget)
|
||||
.first()
|
||||
.should(
|
||||
"have.text",
|
||||
`{ "note": { "to": "Tove", "from": "Jani", "heading": "Reminder", "body": "Don't forget me this weekend!" }}`,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
@ -52,6 +52,7 @@
|
|||
"downloadjs": "^1.4.7",
|
||||
"eslint": "^7.11.0",
|
||||
"fast-deep-equal": "^3.1.1",
|
||||
"fast-xml-parser": "^3.17.5",
|
||||
"flow-bin": "^0.91.0",
|
||||
"fuse.js": "^3.4.5",
|
||||
"fusioncharts": "^3.15.0-sr.1",
|
||||
|
|
|
|||
13
app/client/src/constants/defs/xmlParser.json
Normal file
13
app/client/src/constants/defs/xmlParser.json
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
{
|
||||
"!name": "xmlParser",
|
||||
"xmlParser": {
|
||||
"parse": {
|
||||
"!doc": "converts xml string to json object",
|
||||
"!type": "fn(xml: string, options?: object) -> object"
|
||||
},
|
||||
"validate": {
|
||||
"!doc": "validate xml data",
|
||||
"!type": "fn(xml: string) -> bool"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -6,6 +6,7 @@ import {
|
|||
import { Action } from "entities/Action";
|
||||
import moment from "moment-timezone";
|
||||
import { WidgetProps } from "../widgets/BaseWidget";
|
||||
import parser from "fast-xml-parser";
|
||||
|
||||
export const removeBindingsFromActionObject = (obj: Action) => {
|
||||
const string = JSON.stringify(obj);
|
||||
|
|
@ -127,6 +128,13 @@ export const extraLibraries: ExtraLibrary[] = [
|
|||
docsURL: `https://momentjs.com/docs/`,
|
||||
displayName: "moment",
|
||||
},
|
||||
{
|
||||
accessor: "xmlParser",
|
||||
lib: parser,
|
||||
version: "3.17.5",
|
||||
docsURL: "https://github.com/NaturalIntelligence/fast-xml-parser",
|
||||
displayName: "xmlParser",
|
||||
},
|
||||
];
|
||||
|
||||
export interface DynamicPath {
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import ecma from "tern/defs/ecmascript.json";
|
|||
import lodash from "constants/defs/lodash.json";
|
||||
import base64 from "constants/defs/base64-js.json";
|
||||
import moment from "constants/defs/moment.json";
|
||||
import xmlJs from "constants/defs/xmlParser.json";
|
||||
import { dataTreeTypeDefCreator } from "utils/autocomplete/dataTreeTypeDefCreator";
|
||||
import CodeMirror, { Hint, Pos, cmpPos } from "codemirror";
|
||||
import {
|
||||
|
|
@ -13,7 +14,7 @@ import {
|
|||
isDynamicValue,
|
||||
} from "utils/DynamicBindingUtils";
|
||||
|
||||
const DEFS = [ecma, lodash, base64, moment];
|
||||
const DEFS = [ecma, lodash, base64, moment, xmlJs];
|
||||
const bigDoc = 250;
|
||||
const cls = "CodeMirror-Tern-";
|
||||
const hintDelay = 1700;
|
||||
|
|
|
|||
|
|
@ -9047,6 +9047,11 @@ fast-levenshtein@^2.0.6, fast-levenshtein@~2.0.6:
|
|||
resolved "https://registry.yarnpkg.com/fast-levenshtein/-/fast-levenshtein-2.0.6.tgz#3d8a5c66883a16a30ca8643e851f19baa7797917"
|
||||
integrity sha1-PYpcZog6FqMMqGQ+hR8Zuqd5eRc=
|
||||
|
||||
fast-xml-parser@^3.17.5:
|
||||
version "3.17.5"
|
||||
resolved "https://registry.yarnpkg.com/fast-xml-parser/-/fast-xml-parser-3.17.5.tgz#760bc7755681d2e1d70329c9ac6a1a7cb38b135e"
|
||||
integrity sha512-lEvThd1Xq+CCylf1n+05bUZCDZjTufaaaqpxM3JZ+4iDqtlG+d/oKgtMmg9GEMOuzBgUoalIzFOaClht9YiGJQ==
|
||||
|
||||
fastq@^1.6.0:
|
||||
version "1.8.0"
|
||||
resolved "https://registry.yarnpkg.com/fastq/-/fastq-1.8.0.tgz#550e1f9f59bbc65fe185cb6a9b4d95357107f481"
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user