pivotql-compiler-mapboxgl
Advanced tools
+109
| 'use strict'; | ||
| Object.defineProperty(exports, "__esModule", { | ||
| value: true | ||
| }); | ||
| exports["default"] = void 0; | ||
| function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); } | ||
| function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } | ||
| function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } | ||
| function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); } | ||
| function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); } | ||
| function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } | ||
| var _firstChild = function _firstChild(node) { | ||
| return node.children[0]; | ||
| }; | ||
| var _identity = function _identity(node) { | ||
| return node.value; | ||
| }; | ||
| var generators = { | ||
| NUMBER: _identity, | ||
| BOOLEAN: _identity, | ||
| PRIMITIVE: _identity, | ||
| STRING: _identity, | ||
| SYMBOL: function SYMBOL(node) { | ||
| if (node.alone) { | ||
| return ['has', _identity(node)]; | ||
| } | ||
| return ['get', _identity(node)]; | ||
| }, | ||
| '-': function _(node) { | ||
| return -_firstChild(node).value; | ||
| }, | ||
| '&&': function _(node) { | ||
| return ['all'].concat(_toConsumableArray(node.children.map(_processNode))); | ||
| }, | ||
| '||': function _(node) { | ||
| return ['any'].concat(_toConsumableArray(node.children.map(_processNode))); | ||
| }, | ||
| ARRAY: function ARRAY(node) { | ||
| return node.children.map(_processNode); | ||
| }, | ||
| IN: function IN(node) { | ||
| var field = _processNode(node.children[0]); | ||
| var valueList = _processNode(node.children[1]); //return ['any', ...valueList.map((value) => ['==', field, value])]; | ||
| return ['in', field, ['literal', valueList]]; | ||
| }, | ||
| '!': function _(node) { | ||
| return ['!', _processNode(node.children[0])]; | ||
| }, | ||
| '==': function _(node) { | ||
| return ['=='].concat(_toConsumableArray(node.children.map(_processNode))); | ||
| }, | ||
| '!=': function _(node) { | ||
| return ['!='].concat(_toConsumableArray(node.children.map(_processNode))); | ||
| }, | ||
| MATCH: function MATCH(node) { | ||
| var _match = ['in']; | ||
| _match.push(_processNode(node.children[1]), _processNode(node.children[0])); | ||
| return _match; | ||
| }, | ||
| '<': function _(node) { | ||
| return ['<'].concat(_toConsumableArray(node.children.map(_processNode))); | ||
| }, | ||
| '<=': function _(node) { | ||
| return ['<='].concat(_toConsumableArray(node.children.map(_processNode))); | ||
| }, | ||
| '>': function _(node) { | ||
| return ['>'].concat(_toConsumableArray(node.children.map(_processNode))); | ||
| }, | ||
| '>=': function _(node) { | ||
| return ['>='].concat(_toConsumableArray(node.children.map(_processNode))); | ||
| }, | ||
| EXPRESSION: function EXPRESSION(node) { | ||
| return node.children.map(_processNode).flat(); | ||
| } | ||
| }; | ||
| var _processNode = function _processNode(node) { | ||
| if (!(node.type in generators)) { | ||
| throw new Error("Invalid node type ".concat(node.type)); | ||
| } | ||
| return generators[node.type](node); | ||
| }; | ||
| var compile = function compile(tree) { | ||
| var query = {}; | ||
| query.filter = _processNode(tree); | ||
| return query; | ||
| }; | ||
| var _default = compile; | ||
| exports["default"] = _default; | ||
| //# sourceMappingURL=index.js.map |
| {"version":3,"sources":["../../src/index.js"],"names":["_firstChild","node","children","_identity","value","generators","NUMBER","BOOLEAN","PRIMITIVE","STRING","SYMBOL","alone","map","_processNode","ARRAY","IN","field","valueList","MATCH","_match","push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GAnDgB;AAoDjB,KApDiB,aAoDbZ,IApDa,EAoDP;AACR,YAAQ,GAAR,4BAAgBA,IAAI,CAACC,QAAL,CAAcU,GAAd,CAAkBC,YAAlB,CAAhB;AACD,GAtDgB;AAuDjB,MAvDiB,aAuDZZ,IAvDY,EAuDN;AACT,YAAQ,IAAR,4BAAiBA,IAAI,CAACC,QAAL,CAAcU,GAAd,CAAkBC,YAAlB,CAAjB;AACD,GAzDgB;AA0DjBQ,EAAAA,UA1DiB,sBA0DNpB,IA1DM,EA0DA;AACf,WAAOA,IAAI,CAACC,QAAL,CAAcU,GAAd,CAAkBC,YAAlB,EAAgCS,IAAhC,EAAP;AACD;AA5DgB,CAAnB;;AA+DA,IAAMT,YAAY,GAAG,SAAfA,YAAe,CAACZ,IAAD,EAAU;AAC7B,MAAI,EAAEA,IAAI,CAACsB,IAAL,IAAalB,UAAf,CAAJ,EAAgC;AAC9B,UAAM,IAAImB,KAAJ,6BAA+BvB,IAAI,CAACsB,IAApC,EAAN;AACD;;AAED,SAAOlB,UAAU,CAACJ,IAAI,CAACsB,IAAN,CAAV,CAAsBtB,IAAtB,CAAP;AACD,CAND;;AAQA,IAAMwB,OAAO,GAAG,SAAVA,OAAU,CAACC,IAAD,EAAU;AACxB,MAAMC,KAAK,GAAG,EAAd;AACAA,EAAAA,KAAK,CAACC,MAAN,GAAef,YAAY,CAACa,IAAD,CAA3B;AACA,SAAOC,KAAP;AACD,CAJD;;eAMeF,O","sourcesContent":["'use strict';\n\nconst _firstChild = (node) => {\n return node.children[0];\n};\n\nconst _identity = (node) => {\n return node.value;\n};\n\nconst generators = {\n NUMBER: _identity,\n BOOLEAN: _identity,\n PRIMITIVE: _identity,\n STRING: _identity,\n SYMBOL: (node) => {\n if (node.alone) {\n return ['has', _identity(node)];\n }\n return ['get', _identity(node)];\n },\n\n '-'(node) {\n return -_firstChild(node).value;\n },\n '&&'(node) {\n return ['all', ...node.children.map(_processNode)];\n },\n '||'(node) {\n return ['any', ...node.children.map(_processNode)];\n },\n ARRAY(node) {\n return node.children.map(_processNode);\n },\n IN(node) {\n const field = _processNode(node.children[0]);\n const valueList = _processNode(node.children[1]);\n\n //return ['any', ...valueList.map((value) => ['==', field, value])];\n\n return ['in', field, ['literal', valueList]];\n },\n '!'(node) {\n return ['!', _processNode(node.children[0])];\n },\n '=='(node) {\n return ['==', ...node.children.map(_processNode)];\n },\n '!='(node) {\n return ['!=', ...node.children.map(_processNode)];\n },\n MATCH(node) {\n const _match = ['in'];\n _match.push(_processNode(node.children[1]), _processNode(node.children[0]));\n return _match;\n },\n '<'(node) {\n return ['<', ...node.children.map(_processNode)];\n },\n '<='(node) {\n return ['<=', ...node.children.map(_processNode)];\n },\n '>'(node) {\n return ['>', ...node.children.map(_processNode)];\n },\n '>='(node) {\n return ['>=', ...node.children.map(_processNode)];\n },\n EXPRESSION(node) {\n return node.children.map(_processNode).flat();\n },\n};\n\nconst _processNode = (node) => {\n if (!(node.type in generators)) {\n throw new Error(`Invalid node type ${node.type}`);\n }\n\n return generators[node.type](node);\n};\n\nconst compile = (tree) => {\n const query = {};\n query.filter = _processNode(tree);\n return query;\n};\n\nexport default compile;\n"],"file":"index.js"} |
+106
| 'use strict'; | ||
| const _firstChild = node => { | ||
| return node.children[0]; | ||
| }; | ||
| const _identity = node => { | ||
| return node.value; | ||
| }; | ||
| const generators = { | ||
| NUMBER: _identity, | ||
| BOOLEAN: _identity, | ||
| PRIMITIVE: _identity, | ||
| STRING: _identity, | ||
| SYMBOL: node => { | ||
| if (node.alone) { | ||
| return ['has', _identity(node)]; | ||
| } | ||
| return ['get', _identity(node)]; | ||
| }, | ||
| '-'(node) { | ||
| return -_firstChild(node).value; | ||
| }, | ||
| '&&'(node) { | ||
| return ['all', ...node.children.map(_processNode)]; | ||
| }, | ||
| '||'(node) { | ||
| return ['any', ...node.children.map(_processNode)]; | ||
| }, | ||
| ARRAY(node) { | ||
| return node.children.map(_processNode); | ||
| }, | ||
| IN(node) { | ||
| const field = _processNode(node.children[0]); | ||
| const valueList = _processNode(node.children[1]); //return ['any', ...valueList.map((value) => ['==', field, value])]; | ||
| return ['in', field, ['literal', valueList]]; | ||
| }, | ||
| '!'(node) { | ||
| return ['!', _processNode(node.children[0])]; | ||
| }, | ||
| '=='(node) { | ||
| return ['==', ...node.children.map(_processNode)]; | ||
| }, | ||
| '!='(node) { | ||
| return ['!=', ...node.children.map(_processNode)]; | ||
| }, | ||
| MATCH(node) { | ||
| const _match = ['in']; | ||
| _match.push(_processNode(node.children[1]), _processNode(node.children[0])); | ||
| return _match; | ||
| }, | ||
| '<'(node) { | ||
| return ['<', ...node.children.map(_processNode)]; | ||
| }, | ||
| '<='(node) { | ||
| return ['<=', ...node.children.map(_processNode)]; | ||
| }, | ||
| '>'(node) { | ||
| return ['>', ...node.children.map(_processNode)]; | ||
| }, | ||
| '>='(node) { | ||
| return ['>=', ...node.children.map(_processNode)]; | ||
| }, | ||
| EXPRESSION(node) { | ||
| return node.children.map(_processNode).flat(); | ||
| } | ||
| }; | ||
| const _processNode = node => { | ||
| if (!(node.type in generators)) { | ||
| throw new Error(`Invalid node type ${node.type}`); | ||
| } | ||
| return generators[node.type](node); | ||
| }; | ||
| const compile = tree => { | ||
| const query = {}; | ||
| query.filter = _processNode(tree); | ||
| return query; | ||
| }; | ||
| export default compile; | ||
| //# sourceMappingURL=index.js.map |
| {"version":3,"sources":["../../src/index.js"],"names":["_firstChild","node","children","_identity","value","generators","NUMBER","BOOLEAN","PRIMITIVE","STRING","SYMBOL","alone","map","_processNode","ARRAY","IN","field","valueList","MATCH","_match","push","EXPRESSION","flat","type","Error","compile","tree","query","filter"],"mappings":"AAAA;;AAEA,MAAMA,WAAW,GAAIC,IAAD,IAAU;AAC5B,SAAOA,IAAI,CAACC,QAAL,CAAc,CAAd,CAAP;AACD,CAFD;;AAIA,MAAMC,SAAS,GAAIF,IAAD,IAAU;AAC1B,SAAOA,IAAI,CAACG,KAAZ;AACD,CAFD;;AAIA,MAAMC,UAAU,GAAG;A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f,WAAOA,IAAI,CAACC,QAAL,CAAcU,GAAd,CAAkBC,YAAlB,EAAgCS,IAAhC,EAAP;AACD;;AA5DgB,CAAnB;;AA+DA,MAAMT,YAAY,GAAIZ,IAAD,IAAU;AAC7B,MAAI,EAAEA,IAAI,CAACsB,IAAL,IAAalB,UAAf,CAAJ,EAAgC;AAC9B,UAAM,IAAImB,KAAJ,CAAW,qBAAoBvB,IAAI,CAACsB,IAAK,EAAzC,CAAN;AACD;;AAED,SAAOlB,UAAU,CAACJ,IAAI,CAACsB,IAAN,CAAV,CAAsBtB,IAAtB,CAAP;AACD,CAND;;AAQA,MAAMwB,OAAO,GAAIC,IAAD,IAAU;AACxB,QAAMC,KAAK,GAAG,EAAd;AACAA,EAAAA,KAAK,CAACC,MAAN,GAAef,YAAY,CAACa,IAAD,CAA3B;AACA,SAAOC,KAAP;AACD,CAJD;;AAMA,eAAeF,OAAf","sourcesContent":["'use strict';\n\nconst _firstChild = (node) => {\n return node.children[0];\n};\n\nconst _identity = (node) => {\n return node.value;\n};\n\nconst generators = {\n NUMBER: _identity,\n BOOLEAN: _identity,\n PRIMITIVE: _identity,\n STRING: _identity,\n SYMBOL: (node) => {\n if (node.alone) {\n return ['has', _identity(node)];\n }\n return ['get', _identity(node)];\n },\n\n '-'(node) {\n return -_firstChild(node).value;\n },\n '&&'(node) {\n return ['all', ...node.children.map(_processNode)];\n },\n '||'(node) {\n return ['any', ...node.children.map(_processNode)];\n },\n ARRAY(node) {\n return node.children.map(_processNode);\n },\n IN(node) {\n const field = _processNode(node.children[0]);\n const valueList = _processNode(node.children[1]);\n\n //return ['any', ...valueList.map((value) => ['==', field, value])];\n\n return ['in', field, ['literal', valueList]];\n },\n '!'(node) {\n return ['!', _processNode(node.children[0])];\n },\n '=='(node) {\n return ['==', ...node.children.map(_processNode)];\n },\n '!='(node) {\n return ['!=', ...node.children.map(_processNode)];\n },\n MATCH(node) {\n const _match = ['in'];\n _match.push(_processNode(node.children[1]), _processNode(node.children[0]));\n return _match;\n },\n '<'(node) {\n return ['<', ...node.children.map(_processNode)];\n },\n '<='(node) {\n return ['<=', ...node.children.map(_processNode)];\n },\n '>'(node) {\n return ['>', ...node.children.map(_processNode)];\n },\n '>='(node) {\n return ['>=', ...node.children.map(_processNode)];\n },\n EXPRESSION(node) {\n return node.children.map(_processNode).flat();\n },\n};\n\nconst _processNode = (node) => {\n if (!(node.type in generators)) {\n throw new Error(`Invalid node type ${node.type}`);\n }\n\n return generators[node.type](node);\n};\n\nconst compile = (tree) => {\n const query = {};\n query.filter = _processNode(tree);\n return query;\n};\n\nexport default compile;\n"],"file":"index.js"} |
+88
| 'use strict'; | ||
| const _firstChild = (node) => { | ||
| return node.children[0]; | ||
| }; | ||
| const _identity = (node) => { | ||
| return node.value; | ||
| }; | ||
| const generators = { | ||
| NUMBER: _identity, | ||
| BOOLEAN: _identity, | ||
| PRIMITIVE: _identity, | ||
| STRING: _identity, | ||
| SYMBOL: (node) => { | ||
| if (node.alone) { | ||
| return ['has', _identity(node)]; | ||
| } | ||
| return ['get', _identity(node)]; | ||
| }, | ||
| '-'(node) { | ||
| return -_firstChild(node).value; | ||
| }, | ||
| '&&'(node) { | ||
| return ['all', ...node.children.map(_processNode)]; | ||
| }, | ||
| '||'(node) { | ||
| return ['any', ...node.children.map(_processNode)]; | ||
| }, | ||
| ARRAY(node) { | ||
| return node.children.map(_processNode); | ||
| }, | ||
| IN(node) { | ||
| const field = _processNode(node.children[0]); | ||
| const valueList = _processNode(node.children[1]); | ||
| //return ['any', ...valueList.map((value) => ['==', field, value])]; | ||
| return ['in', field, ['literal', valueList]]; | ||
| }, | ||
| '!'(node) { | ||
| return ['!', _processNode(node.children[0])]; | ||
| }, | ||
| '=='(node) { | ||
| return ['==', ...node.children.map(_processNode)]; | ||
| }, | ||
| '!='(node) { | ||
| return ['!=', ...node.children.map(_processNode)]; | ||
| }, | ||
| MATCH(node) { | ||
| const _match = ['in']; | ||
| _match.push(_processNode(node.children[1]), _processNode(node.children[0])); | ||
| return _match; | ||
| }, | ||
| '<'(node) { | ||
| return ['<', ...node.children.map(_processNode)]; | ||
| }, | ||
| '<='(node) { | ||
| return ['<=', ...node.children.map(_processNode)]; | ||
| }, | ||
| '>'(node) { | ||
| return ['>', ...node.children.map(_processNode)]; | ||
| }, | ||
| '>='(node) { | ||
| return ['>=', ...node.children.map(_processNode)]; | ||
| }, | ||
| EXPRESSION(node) { | ||
| return node.children.map(_processNode).flat(); | ||
| }, | ||
| }; | ||
| const _processNode = (node) => { | ||
| if (!(node.type in generators)) { | ||
| throw new Error(`Invalid node type ${node.type}`); | ||
| } | ||
| return generators[node.type](node); | ||
| }; | ||
| const compile = (tree) => { | ||
| const query = {}; | ||
| query.filter = _processNode(tree); | ||
| return query; | ||
| }; | ||
| export default compile; |
| 'use strict'; | ||
| import compiler from './index.js'; | ||
| import parser from 'pivotql-parser-expression'; | ||
| describe('Basic types', () => { | ||
| test('NUMBER', () => { | ||
| expect(compiler(parser('17'))).toEqual({ filter: 17 }); | ||
| }); | ||
| }); | ||
| describe('Basic queries', () => { | ||
| test('foo == "bar"', () => { | ||
| expect(compiler(parser('foo == "bar"'))).toEqual({ | ||
| filter: ['==', ['get', 'foo'], 'bar'], | ||
| }); | ||
| }); | ||
| test('foo != "bar"', () => { | ||
| expect(compiler(parser('foo != "bar"'))).toEqual({ | ||
| filter: ['!=', ['get', 'foo'], 'bar'], | ||
| }); | ||
| }); | ||
| test('foo', () => { | ||
| expect(compiler(parser('foo'))).toEqual({ filter: ['has', 'foo'] }); | ||
| }); | ||
| }); | ||
| describe('Compound queries', () => { | ||
| test('foo == "bar" and foo != "baz"', () => { | ||
| expect(compiler(parser('foo == "bar" and foo != "baz"'))).toEqual({ | ||
| filter: [ | ||
| 'all', | ||
| ['==', ['get', 'foo'], 'bar'], | ||
| ['!=', ['get', 'foo'], 'baz'], | ||
| ], | ||
| }); | ||
| }); | ||
| test('foo == "bar" or bar != 10', () => { | ||
| expect(compiler(parser('foo == "bar" or bar != 10'))).toEqual({ | ||
| filter: [ | ||
| 'any', | ||
| ['==', ['get', 'foo'], 'bar'], | ||
| ['!=', ['get', 'bar'], 10], | ||
| ], | ||
| }); | ||
| }); | ||
| test('foo == "bar" or foo != "baz" and bam == 10', () => { | ||
| expect( | ||
| compiler(parser('foo == "bar" or foo != "baz" and bam == 10')) | ||
| ).toEqual({ | ||
| filter: [ | ||
| 'any', | ||
| ['==', ['get', 'foo'], 'bar'], | ||
| ['all', ['!=', ['get', 'foo'], 'baz'], ['==', ['get', 'bam'], 10]], | ||
| ], | ||
| }); | ||
| }); | ||
| test('foo in ["bar", "baz"]', () => { | ||
| expect(compiler(parser('foo in ["bar", "baz"]'))).toEqual({ | ||
| filter: ['in', ['get', 'foo'], ['literal', ['bar', 'baz']]], | ||
| }); | ||
| }); | ||
| test('foo in [10, 20]', () => { | ||
| expect(compiler(parser('foo in [10, 20]'))).toEqual({ | ||
| filter: ['in', ['get', 'foo'], ['literal', [10, 20]]], | ||
| }); | ||
| }); | ||
| test('foo and (bar or baz)', () => { | ||
| expect(compiler(parser('foo and (bar or baz)'))).toEqual({ | ||
| filter: ['all', ['has', 'foo'], ['any', ['has', 'bar'], ['has', 'baz']]], | ||
| }); | ||
| }); | ||
| }); |
+30
-10
| { | ||
| "name": "pivotql-compiler-mapboxgl", | ||
| "version": "0.1.0", | ||
| "version": "0.2.0", | ||
| "description": "Compile PivotQL ASTs to mapbox filter queries.", | ||
| "main": "./index.js", | ||
| "main": "./lib/cjs/index.js", | ||
| "module": "lib/esm/index.js", | ||
| "exports": { | ||
| ".": "./index.js", | ||
| "./package.json": "./package.json" | ||
| "require": "./lib/cjs/index.js", | ||
| "import": "./lib/esm/index.js" | ||
| }, | ||
| "type": "module", | ||
| "files": [ | ||
| "src", | ||
| "lib" | ||
| ], | ||
| "scripts": { | ||
| "test": "jest", | ||
| "build": "echo \"nothing to do\"" | ||
| "test": "BABEL_ENV=test jest", | ||
| "clean": "rimraf lib", | ||
| "build:esm": "BABEL_ENV=esmUnbundled babel --config-file ../../babel.config.js src --out-dir lib/esm --source-maps", | ||
| "build:cjs": "BABEL_ENV=cjs babel --config-file ../../babel.config.js src --out-dir lib/cjs --source-maps", | ||
| "build": "npm run clean && npm run build:esm && npm run build:cjs" | ||
| }, | ||
@@ -32,2 +39,7 @@ "repository": { | ||
| "devDependencies": { | ||
| "@babel/cli": "^7.16.0", | ||
| "@babel/core": "^7.16.0", | ||
| "@babel/node": "^7.16.0", | ||
| "@babel/preset-env": "^7.16.0", | ||
| "babel-jest": "^27.3.1", | ||
| "eslint": "^7.32.0", | ||
@@ -37,9 +49,17 @@ "eslint-config-prettier": "^8.3.0", | ||
| "jest": "^27.2.2", | ||
| "jest-esm-transformer": "^1.0.0", | ||
| "pivotql-parser-expression": "^0.1.0" | ||
| "pivotql-parser-expression": "^0.2.0", | ||
| "rimraf": "^3.0.2" | ||
| }, | ||
| "jest": { | ||
| "transform": { | ||
| ".js": "jest-esm-transformer" | ||
| "\\.js$": [ | ||
| "babel-jest", | ||
| { | ||
| "configFile": "../../babel.config.js" | ||
| } | ||
| ] | ||
| }, | ||
| "transformIgnorePatterns": [ | ||
| "node_modules/(?!(pivotql-parser-expression)/)" | ||
| ], | ||
| "testMatch": [ | ||
@@ -46,0 +66,0 @@ "**/tests/**/*.[jt]s?(x)", |
+23
-0
@@ -5,2 +5,25 @@ # PivotQL compiler for mapbox | ||
| ## Install | ||
| ```sh | ||
| npm install pivotql-compiler-mapboxgl | ||
| ``` | ||
| ## Example | ||
| ```js | ||
| import parse from 'pivotql-parser-expression'; | ||
| import compile from 'pivotql-compiler-mapboxgl'; | ||
| const query = '( height <= 20 or favorites.color == "green" ) and firstname in ["john", "doug"]'; | ||
| const queryMB = compile(parse(query)) | ||
| // Use query filter in layer style | ||
| ``` | ||
| ## More information | ||
| See [main repository](https://github.com/jrmi/pivotql/) for more information. |
-88
| 'use strict'; | ||
| const _firstChild = (node) => { | ||
| return node.children[0]; | ||
| }; | ||
| const _identity = (node) => { | ||
| return node.value; | ||
| }; | ||
| const generators = { | ||
| NUMBER: _identity, | ||
| BOOLEAN: _identity, | ||
| PRIMITIVE: _identity, | ||
| STRING: _identity, | ||
| SYMBOL: (node) => { | ||
| if (node.alone) { | ||
| return ['has', _identity(node)]; | ||
| } | ||
| return ['get', _identity(node)]; | ||
| }, | ||
| '-'(node) { | ||
| return -_firstChild(node).value; | ||
| }, | ||
| '&&'(node) { | ||
| return ['all', ...node.children.map(_processNode)]; | ||
| }, | ||
| '||'(node) { | ||
| return ['any', ...node.children.map(_processNode)]; | ||
| }, | ||
| ARRAY(node) { | ||
| return node.children.map(_processNode); | ||
| }, | ||
| IN(node) { | ||
| const field = _processNode(node.children[0]); | ||
| const valueList = _processNode(node.children[1]); | ||
| //return ['any', ...valueList.map((value) => ['==', field, value])]; | ||
| return ['in', field, ['literal', valueList]]; | ||
| }, | ||
| '!'(node) { | ||
| return ['!', _processNode(node.children[0])]; | ||
| }, | ||
| '=='(node) { | ||
| return ['==', ...node.children.map(_processNode)]; | ||
| }, | ||
| '!='(node) { | ||
| return ['!=', ...node.children.map(_processNode)]; | ||
| }, | ||
| MATCH(node) { | ||
| const _match = ['in']; | ||
| _match.push(_processNode(node.children[1]), _processNode(node.children[0])); | ||
| return _match; | ||
| }, | ||
| '<'(node) { | ||
| return ['<', ...node.children.map(_processNode)]; | ||
| }, | ||
| '<='(node) { | ||
| return ['<=', ...node.children.map(_processNode)]; | ||
| }, | ||
| '>'(node) { | ||
| return ['>', ...node.children.map(_processNode)]; | ||
| }, | ||
| '>='(node) { | ||
| return ['>=', ...node.children.map(_processNode)]; | ||
| }, | ||
| EXPRESSION(node) { | ||
| return node.children.map(_processNode).flat(); | ||
| }, | ||
| }; | ||
| const _processNode = (node) => { | ||
| if (!(node.type in generators)) { | ||
| throw new Error(`Invalid node type ${node.type}`); | ||
| } | ||
| return generators[node.type](node); | ||
| }; | ||
| const compile = (tree) => { | ||
| const query = {}; | ||
| query.filter = _processNode(tree); | ||
| return query; | ||
| }; | ||
| export default compile; |
| 'use strict'; | ||
| import compiler from './index.js'; | ||
| import parser from 'pivotql-parser-expression'; | ||
| describe('Basic types', () => { | ||
| test('NUMBER', () => { | ||
| expect(compiler(parser('17'))).toEqual({ filter: 17 }); | ||
| }); | ||
| }); | ||
| describe('Basic queries', () => { | ||
| test('foo == "bar"', () => { | ||
| expect(compiler(parser('foo == "bar"'))).toEqual({ | ||
| filter: ['==', ['get', 'foo'], 'bar'], | ||
| }); | ||
| }); | ||
| test('foo != "bar"', () => { | ||
| expect(compiler(parser('foo != "bar"'))).toEqual({ | ||
| filter: ['!=', ['get', 'foo'], 'bar'], | ||
| }); | ||
| }); | ||
| test('foo', () => { | ||
| expect(compiler(parser('foo'))).toEqual({ filter: ['has', 'foo'] }); | ||
| }); | ||
| }); | ||
| describe('Compound queries', () => { | ||
| test('foo == "bar" and foo != "baz"', () => { | ||
| expect(compiler(parser('foo == "bar" and foo != "baz"'))).toEqual({ | ||
| filter: [ | ||
| 'all', | ||
| ['==', ['get', 'foo'], 'bar'], | ||
| ['!=', ['get', 'foo'], 'baz'], | ||
| ], | ||
| }); | ||
| }); | ||
| test('foo == "bar" or bar != 10', () => { | ||
| expect(compiler(parser('foo == "bar" or bar != 10'))).toEqual({ | ||
| filter: [ | ||
| 'any', | ||
| ['==', ['get', 'foo'], 'bar'], | ||
| ['!=', ['get', 'bar'], 10], | ||
| ], | ||
| }); | ||
| }); | ||
| test('foo == "bar" or foo != "baz" and bam == 10', () => { | ||
| expect( | ||
| compiler(parser('foo == "bar" or foo != "baz" and bam == 10')) | ||
| ).toEqual({ | ||
| filter: [ | ||
| 'any', | ||
| ['==', ['get', 'foo'], 'bar'], | ||
| ['all', ['!=', ['get', 'foo'], 'baz'], ['==', ['get', 'bam'], 10]], | ||
| ], | ||
| }); | ||
| }); | ||
| test('foo in ["bar", "baz"]', () => { | ||
| expect(compiler(parser('foo in ["bar", "baz"]'))).toEqual({ | ||
| filter: ['in', ['get', 'foo'], ['literal', ['bar', 'baz']]], | ||
| }); | ||
| }); | ||
| test('foo in [10, 20]', () => { | ||
| expect(compiler(parser('foo in [10, 20]'))).toEqual({ | ||
| filter: ['in', ['get', 'foo'], ['literal', [10, 20]]], | ||
| }); | ||
| }); | ||
| test('foo and (bar or baz)', () => { | ||
| expect(compiler(parser('foo and (bar or baz)'))).toEqual({ | ||
| filter: ['all', ['has', 'foo'], ['any', ['has', 'bar'], ['has', 'baz']]], | ||
| }); | ||
| }); | ||
| }); |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
22388
330.37%8
100%313
112.93%29
383.33%11
83.33%1
Infinity%No
NaN