diff --git a/docs/package-lock.json b/docs/package-lock.json index 897b8a7..80da8fd 100644 --- a/docs/package-lock.json +++ b/docs/package-lock.json @@ -88,6 +88,14 @@ "@types/react": "*" } }, + "@types/react-syntax-highlighter": { + "version": "0.0.7", + "resolved": "https://registry.npmjs.org/@types/react-syntax-highlighter/-/react-syntax-highlighter-0.0.7.tgz", + "integrity": "sha512-z2DJUpaEcLEAE/94PwwRCVRCyUjLOhGcHlkesurEHK8qm0iF1RIy/2kVDo08z1XtIWmoqWMWcaS9c5wilHPsGg==", + "requires": { + "@types/react": "*" + } + }, "@uifabric/icons": { "version": "6.1.2", "resolved": "https://registry.npmjs.org/@uifabric/icons/-/icons-6.1.2.tgz", @@ -1825,6 +1833,21 @@ } } }, + "character-entities": { + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/character-entities/-/character-entities-1.2.2.tgz", + "integrity": "sha512-sMoHX6/nBiy3KKfC78dnEalnpn0Az0oSNvqUWYTtYrhRI5iUIYsROU48G+E+kMFQzqXaJ8kHJZ85n7y6/PHgwQ==" + }, + "character-entities-legacy": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/character-entities-legacy/-/character-entities-legacy-1.1.2.tgz", + "integrity": "sha512-9NB2VbXtXYWdXzqrvAHykE/f0QJxzaKIpZ5QzNZrrgQ7Iyxr2vnfS8fCBNVW9nUEZE0lo57nxKRqnzY/dKrwlA==" + }, + "character-reference-invalid": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/character-reference-invalid/-/character-reference-invalid-1.1.2.tgz", + "integrity": "sha512-7I/xceXfKyUJmSAn/jw8ve/9DyOP7XxufNYLI9Px7CmsKgEUaZLUTax6nZxGQtaoiZCjpu6cHPj20xC/vqRReQ==" + }, "chardet": { "version": "0.4.2", "resolved": "https://registry.npmjs.org/chardet/-/chardet-0.4.2.tgz", @@ -1925,6 +1948,17 @@ "resolved": "https://registry.npmjs.org/cli-width/-/cli-width-2.2.0.tgz", "integrity": "sha1-/xnt6Kml5XkyQUewwR8PvLq+1jk=" }, + "clipboard": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/clipboard/-/clipboard-2.0.1.tgz", + "integrity": "sha512-7yhQBmtN+uYZmfRjjVjKa0dZdWuabzpSKGtyQZN+9C8xlC788SSJjOHWh7tzurfwTqTD5UDYAhIv5fRJg3sHjQ==", + "optional": true, + "requires": { + "good-listener": "^1.2.2", + "select": "^1.1.2", + "tiny-emitter": "^2.0.0" + } + }, "cliui": { "version": "3.2.0", "resolved": "https://registry.npmjs.org/cliui/-/cliui-3.2.0.tgz", @@ -2021,6 +2055,14 @@ "delayed-stream": "~1.0.0" } }, + "comma-separated-tokens": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/comma-separated-tokens/-/comma-separated-tokens-1.0.5.tgz", + "integrity": "sha512-Cg90/fcK93n0ecgYTAz1jaA3zvnQ0ExlmKY1rdbyHqAx6BHxwoJc+J7HDu0iuQ7ixEs1qaa+WyQ6oeuBpYP1iA==", + "requires": { + "trim": "0.0.1" + } + }, "commander": { "version": "2.17.1", "resolved": "https://registry.npmjs.org/commander/-/commander-2.17.1.tgz", @@ -2713,6 +2755,12 @@ "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", "integrity": "sha1-3zrhmayt+31ECqrgsp4icrJOxhk=" }, + "delegate": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/delegate/-/delegate-3.2.0.tgz", + "integrity": "sha512-IofjkYBZaZivn0V8nnsMJGBr4jVLxHDheKSW88PyxS5QC4Vo9ZbZVvhzlSxY87fVq3STR6r+4cGepyHkcWOQSw==", + "optional": true + }, "depd": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/depd/-/depd-1.1.2.tgz", @@ -3431,6 +3479,14 @@ "resolved": "https://registry.npmjs.org/fastparse/-/fastparse-1.1.1.tgz", "integrity": "sha1-0eJkOzipTXWDtHkGDmxK/8lAcfg=" }, + "fault": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/fault/-/fault-1.0.2.tgz", + "integrity": "sha512-o2eo/X2syzzERAtN5LcGbiVQ0WwZSlN3qLtadwAz3X8Bu+XWD16dja/KMsjZLiQr+BLGPDnHGkc4yUJf1Xpkpw==", + "requires": { + "format": "^0.2.2" + } + }, "faye-websocket": { "version": "0.11.1", "resolved": "https://registry.npmjs.org/faye-websocket/-/faye-websocket-0.11.1.tgz", @@ -3641,6 +3697,11 @@ } } }, + "format": { + "version": "0.2.2", + "resolved": "https://registry.npmjs.org/format/-/format-0.2.2.tgz", + "integrity": "sha1-1hcBB+nv3E7TDJ3DkBbflCtctYs=" + }, "forwarded": { "version": "0.1.2", "resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.1.2.tgz", @@ -4327,6 +4388,15 @@ "pinkie-promise": "^2.0.0" } }, + "good-listener": { + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/good-listener/-/good-listener-1.2.2.tgz", + "integrity": "sha1-1TswzfkxPf+33JoNR3CWqm0UXFA=", + "optional": true, + "requires": { + "delegate": "^3.1.2" + } + }, "got": { "version": "6.7.1", "resolved": "http://registry.npmjs.org/got/-/got-6.7.1.tgz", @@ -4491,11 +4561,32 @@ "minimalistic-assert": "^1.0.1" } }, + "hast-util-parse-selector": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/hast-util-parse-selector/-/hast-util-parse-selector-2.2.0.tgz", + "integrity": "sha512-trw0pqZN7+sH9k7hPWCJNZUbWW2KroSIM/XpIy3G5ZMtx9LSabCyoSp4skJZ4q/eZ5UOBPtvWh4W9c+RE3HRoQ==" + }, + "hastscript": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/hastscript/-/hastscript-4.1.0.tgz", + "integrity": "sha512-bOTn9hEfzewvHyXdbYGKqOr/LOz+2zYhKbC17U2YAjd16mnjqB1BQ0nooM/RdMy/htVyli0NAznXiBtwDi1cmQ==", + "requires": { + "comma-separated-tokens": "^1.0.0", + "hast-util-parse-selector": "^2.2.0", + "property-information": "^4.0.0", + "space-separated-tokens": "^1.0.0" + } + }, "he": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/he/-/he-1.1.1.tgz", "integrity": "sha1-k0EP0hsAlzUVH4howvJx80J+I/0=" }, + "highlight.js": { + "version": "9.12.0", + "resolved": "https://registry.npmjs.org/highlight.js/-/highlight.js-9.12.0.tgz", + "integrity": "sha1-5tnb5Xy+/mB1HwKvM2GVhwyQwB4=" + }, "hmac-drbg": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/hmac-drbg/-/hmac-drbg-1.0.1.tgz", @@ -4921,6 +5012,20 @@ "kind-of": "^3.0.2" } }, + "is-alphabetical": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/is-alphabetical/-/is-alphabetical-1.0.2.tgz", + "integrity": "sha512-V0xN4BYezDHcBSKb1QHUFMlR4as/XEuCZBzMJUU4n7+Cbt33SmUnSol+pnXFvLxSHNq2CemUXNdaXV6Flg7+xg==" + }, + "is-alphanumerical": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/is-alphanumerical/-/is-alphanumerical-1.0.2.tgz", + "integrity": "sha512-pyfU/0kHdISIgslFfZN9nfY1Gk3MquQgUm1mJTjdkEPpkAKNWuBTSqFwewOpR7N351VkErCiyV71zX7mlQQqsg==", + "requires": { + "is-alphabetical": "^1.0.0", + "is-decimal": "^1.0.0" + } + }, "is-arrayish": { "version": "0.2.1", "resolved": "https://registry.npmjs.org/is-arrayish/-/is-arrayish-0.2.1.tgz", @@ -4973,6 +5078,11 @@ "resolved": "https://registry.npmjs.org/is-date-object/-/is-date-object-1.0.1.tgz", "integrity": "sha1-mqIOtq7rv/d/vTPnTKAbM1gdOhY=" }, + "is-decimal": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/is-decimal/-/is-decimal-1.0.2.tgz", + "integrity": "sha512-TRzl7mOCchnhchN+f3ICUCzYvL9ul7R+TYOsZ8xia++knyZAJfv/uA1FvQXsAnYIl1T3B2X5E/J7Wb1QXiIBXg==" + }, "is-descriptor": { "version": "0.1.6", "resolved": "https://registry.npmjs.org/is-descriptor/-/is-descriptor-0.1.6.tgz", @@ -5047,6 +5157,11 @@ "is-extglob": "^1.0.0" } }, + "is-hexadecimal": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/is-hexadecimal/-/is-hexadecimal-1.0.2.tgz", + "integrity": "sha512-but/G3sapV3MNyqiDBLrOi4x8uCIw0RY3o/Vb5GT0sMFHrVV7731wFSVy41T5FO1og7G0gXLJh0MkgPRouko/A==" + }, "is-installed-globally": { "version": "0.1.0", "resolved": "https://registry.npmjs.org/is-installed-globally/-/is-installed-globally-0.1.0.tgz", @@ -5919,6 +6034,15 @@ "resolved": "https://registry.npmjs.org/lowercase-keys/-/lowercase-keys-1.0.1.tgz", "integrity": "sha512-G2Lj61tXDnVFFOi8VZds+SoQjtQC3dgokKdDG2mTm1tx4m50NUHBOZSBwQQHyy0V12A0JTG4icfZQH+xPyh8VA==" }, + "lowlight": { + "version": "1.9.2", + "resolved": "https://registry.npmjs.org/lowlight/-/lowlight-1.9.2.tgz", + "integrity": "sha512-Ek18ElVCf/wF/jEm1b92gTnigh94CtBNWiZ2ad+vTgW7cTmQxUY3I98BjHK68gZAJEWmybGBZgx9qv3QxLQB/Q==", + "requires": { + "fault": "^1.0.2", + "highlight.js": "~9.12.0" + } + }, "lru-cache": { "version": "4.1.3", "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-4.1.3.tgz", @@ -6665,6 +6789,19 @@ "pbkdf2": "^3.0.3" } }, + "parse-entities": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/parse-entities/-/parse-entities-1.2.0.tgz", + "integrity": "sha512-XXtDdOPLSB0sHecbEapQi6/58U/ODj/KWfIXmmMCJF/eRn8laX6LZbOyioMoETOOJoWRW8/qTSl5VQkUIfKM5g==", + "requires": { + "character-entities": "^1.0.0", + "character-entities-legacy": "^1.0.0", + "character-reference-invalid": "^1.0.0", + "is-alphanumerical": "^1.0.0", + "is-decimal": "^1.0.0", + "is-hexadecimal": "^1.0.0" + } + }, "parse-glob": { "version": "3.0.4", "resolved": "https://registry.npmjs.org/parse-glob/-/parse-glob-3.0.4.tgz", @@ -8016,6 +8153,14 @@ "ansi-styles": "^3.0.0" } }, + "prismjs": { + "version": "1.15.0", + "resolved": "https://registry.npmjs.org/prismjs/-/prismjs-1.15.0.tgz", + "integrity": "sha512-Lf2JrFYx8FanHrjoV5oL8YHCclLQgbJcVZR+gikGGMqz6ub5QVWDTM6YIwm3BuPxM/LOV+rKns3LssXNLIf+DA==", + "requires": { + "clipboard": "^2.0.0" + } + }, "private": { "version": "0.1.8", "resolved": "https://registry.npmjs.org/private/-/private-0.1.8.tgz", @@ -8053,6 +8198,14 @@ "object-assign": "^4.1.1" } }, + "property-information": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/property-information/-/property-information-4.2.0.tgz", + "integrity": "sha512-TlgDPagHh+eBKOnH2VYvk8qbwsCG/TAJdmTL7f1PROUcSO8qt/KSmShEQ/OKvock8X9tFjtqjCScyOkkkvIKVQ==", + "requires": { + "xtend": "^4.0.1" + } + }, "proxy-addr": { "version": "2.0.4", "resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.4.tgz", @@ -8345,6 +8498,18 @@ "whatwg-fetch": "2.0.3" } }, + "react-syntax-highlighter": { + "version": "9.0.0", + "resolved": "https://registry.npmjs.org/react-syntax-highlighter/-/react-syntax-highlighter-9.0.0.tgz", + "integrity": "sha512-kdaBn+2FE3Yh4+rgYQYaNyNHK1km+OY6EzcDVSFyFRICY3KCTM8FgRJZ2+hVG6WxCWp10ylMZ3lNcYvuPqYOCQ==", + "requires": { + "babel-runtime": "^6.18.0", + "highlight.js": "~9.12.0", + "lowlight": "~1.9.1", + "prismjs": "^1.8.4", + "refractor": "^2.4.1" + } + }, "read-pkg": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/read-pkg/-/read-pkg-1.1.0.tgz", @@ -8716,6 +8881,16 @@ } } }, + "refractor": { + "version": "2.6.0", + "resolved": "https://registry.npmjs.org/refractor/-/refractor-2.6.0.tgz", + "integrity": "sha512-ZkziLxSnkGmcFd9gVtMPqWyuA9nLzQCJqIjma03UvS2kw3gU+JQhCz8bWpbXtQX0e5XurZb/1wglrxpkYTJalQ==", + "requires": { + "hastscript": "^4.0.0", + "parse-entities": "^1.1.2", + "prismjs": "~1.15.0" + } + }, "regenerate": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/regenerate/-/regenerate-1.4.0.tgz", @@ -9084,6 +9259,12 @@ "ajv": "^5.0.0" } }, + "select": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/select/-/select-1.1.2.tgz", + "integrity": "sha1-DnNQrN7ICxEIUoeG7B1EGNEbOW0=", + "optional": true + }, "select-hose": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/select-hose/-/select-hose-2.0.0.tgz", @@ -9391,9 +9572,9 @@ } }, "soql-parser-js": { - "version": "0.3.2", - "resolved": "https://registry.npmjs.org/soql-parser-js/-/soql-parser-js-0.3.2.tgz", - "integrity": "sha512-xEQ/wZs6XAOBYzETHQhf3W2GRsr9kaiDAI+FjtKXx8XZBrTVTjlKFb8vQN4kKbPhcjjGGNd7thslxjN3aLjZTg==", + "version": "0.3.3", + "resolved": "https://registry.npmjs.org/soql-parser-js/-/soql-parser-js-0.3.3.tgz", + "integrity": "sha512-yeC3xP/evGx/8np8tNPWBDVTQqikaOw6pBIx7nsqC7enNGCHx8hvaHYl7ajdFdU7bXmqo2YUYPM9/oOIvYH75g==", "requires": { "antlr4ts": "0.4.1-alpha.0", "minimist": "^1.2.0" @@ -9465,6 +9646,14 @@ "resolved": "https://registry.npmjs.org/source-map-url/-/source-map-url-0.4.0.tgz", "integrity": "sha1-PpNdfd1zYxuXZZlW1VEo6HtQhKM=" }, + "space-separated-tokens": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/space-separated-tokens/-/space-separated-tokens-1.1.2.tgz", + "integrity": "sha512-G3jprCEw+xFEs0ORweLmblJ3XLymGGr6hxZYTYZjIlvDti9vOBUjRQa1Rzjt012aRrocKstHwdNi+F7HguPsEA==", + "requires": { + "trim": "0.0.1" + } + }, "spdx-correct": { "version": "3.0.2", "resolved": "https://registry.npmjs.org/spdx-correct/-/spdx-correct-3.0.2.tgz", @@ -9863,6 +10052,12 @@ "setimmediate": "^1.0.4" } }, + "tiny-emitter": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/tiny-emitter/-/tiny-emitter-2.0.2.tgz", + "integrity": "sha512-2NM0auVBGft5tee/OxP4PI3d8WItkDM+fPnaRAVo6xTDI2knbz9eC5ArWGqtGlYqiH3RU5yMpdyTTO7MguC4ow==", + "optional": true + }, "tmp": { "version": "0.0.33", "resolved": "https://registry.npmjs.org/tmp/-/tmp-0.0.33.tgz", @@ -9948,6 +10143,11 @@ "resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz", "integrity": "sha1-gYT9NH2snNwYWZLzpmIuFLnZq2o=" }, + "trim": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/trim/-/trim-0.0.1.tgz", + "integrity": "sha1-WFhUf2spB1fulczMZm+1AITEYN0=" + }, "trim-newlines": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/trim-newlines/-/trim-newlines-1.0.0.tgz", diff --git a/docs/package.json b/docs/package.json index 12b8b30..1d51711 100644 --- a/docs/package.json +++ b/docs/package.json @@ -5,13 +5,15 @@ "homepage": "http://paustint.github.io/soql-parser-js", "dependencies": { "@types/react-copy-to-clipboard": "^4.2.6", + "@types/react-syntax-highlighter": "0.0.7", "gh-pages": "^2.0.1", "office-ui-fabric-react": "^6.84.0", "react": "^16.5.2", "react-copy-to-clipboard": "^5.0.1", "react-dom": "^16.5.2", "react-scripts-ts": "3.1.0", - "soql-parser-js": "^0.3.2" + "react-syntax-highlighter": "^9.0.0", + "soql-parser-js": "^0.3.3" }, "scripts": { "start": "react-scripts-ts start", diff --git a/docs/src/components/parse-soql.css b/docs/src/components/parse-soql.css index 8bf1c76..40b3fa0 100644 --- a/docs/src/components/parse-soql.css +++ b/docs/src/components/parse-soql.css @@ -1,3 +1,7 @@ .parse-row { margin-top: 10px; +} + +.ms-Grid-row { + margin-top: 10px; } \ No newline at end of file diff --git a/docs/src/components/parse-soql.tsx b/docs/src/components/parse-soql.tsx index 5829243..cab1667 100644 --- a/docs/src/components/parse-soql.tsx +++ b/docs/src/components/parse-soql.tsx @@ -2,7 +2,10 @@ import { Button, DefaultButton } from 'office-ui-fabric-react/lib/Button'; import { TextField } from 'office-ui-fabric-react/lib/TextField'; import * as React from 'react'; import * as CopyToClipboard from 'react-copy-to-clipboard'; -import { parseQuery } from 'soql-parser-js'; +import { parseQuery, Query, composeQuery } from 'soql-parser-js'; +import SyntaxHighlighter from 'react-syntax-highlighter/prism'; +import { xonokai } from 'react-syntax-highlighter/styles/prism'; + import './parse-soql.css'; interface IParseSoqlProps { @@ -12,6 +15,7 @@ interface IParseSoqlProps { interface IParseSoqlState { isValid: boolean; parsedSoql: string; + composedQuery?: string; soql: string; } @@ -19,9 +23,13 @@ export class ParseSoql extends React.Component constructor(props: IParseSoqlProps) { super(props); + const parsedSoql = props.soql ? parseQuery(props.soql) : undefined; + const composedQuery = parsedSoql ? composeQuery(parsedSoql) : ''; + this.state = { isValid: true, - parsedSoql: props.soql ? JSON.stringify(parseQuery(props.soql), null, 4) : '', + parsedSoql: JSON.stringify(parsedSoql || '', null, 4), + composedQuery, soql: props.soql || '', }; } @@ -57,9 +65,11 @@ export class ParseSoql extends React.Component public parseQuery = (query?: string) => { try { - const parsedSoql = parseQuery(query || this.state.soql); + const parsedSoql: Query = parseQuery(query || this.state.soql); + const composedQuery: string = composeQuery(parsedSoql); this.setState({ parsedSoql: JSON.stringify(parsedSoql, null, 4), + composedQuery, }); } catch (ex) { this.setState({ @@ -84,7 +94,7 @@ export class ParseSoql extends React.Component
- -
+
Parsed Query
+ + {this.state.parsedSoql} + +
{this.state.parsedSoql && ( -
- -
+ +
+ {this.state.composedQuery && ( +
+
+
+ Composed Query (Parsed query converted back to SOQL) +
+ + {this.state.composedQuery} + + +
+
+ )}
); diff --git a/lib/SoqlComposer.ts b/lib/SoqlComposer.ts index 3b38beb..c669931 100644 --- a/lib/SoqlComposer.ts +++ b/lib/SoqlComposer.ts @@ -1,14 +1,13 @@ import { - Query, Field, FunctionExp, - WhereClause, GroupByClause, HavingClause, OrderByClause, + Query, TypeOfField, + WhereClause, WithDataCategoryClause, - ForClause, } from './models/SoqlQuery.model'; import * as utils from './utils'; diff --git a/lib/index.ts b/lib/index.ts index 44e8f23..1b0eaf0 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -3,5 +3,6 @@ * The software in this package is published under the terms of the MIT license, * a copy of which has been included with this distribution in the LICENSE.txt file. */ -export { parseQuery } from './SoqlParser'; -export { composeQuery } from './SoqlComposer'; +export * from './SoqlParser'; +export * from './SoqlComposer'; +export * from './models/SoqlQuery.model'; diff --git a/package.json b/package.json index b3790b0..654e778 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "soql-parser-js", - "version": "0.3.2", + "version": "0.3.3", "description": "Salesforce.com SOQL parser.", "main": "dist/index.js", "module": "dist/index.es.js",