@ambassify/aql-condition
Advanced tools
Comparing version 0.5.0 to 0.6.1
@@ -6,12 +6,5 @@ { | ||
], | ||
"parserOptions": { | ||
"sourceType": "script", | ||
"ecmaVersion": 2015 | ||
}, | ||
"rules": { | ||
"strict": [ | ||
2, | ||
"global" | ||
] | ||
"strict": [ "error", "global" ] | ||
} | ||
} |
'use strict'; | ||
var normalize = require('./normalize'); | ||
var OPERATORS = require('./operators'); | ||
function createMultiConditionBuilder(operator) { | ||
@@ -12,3 +10,2 @@ return function buildMultiCondition() { | ||
} | ||
conditions = conditions.map(normalize).filter(Boolean); | ||
@@ -23,3 +20,2 @@ if (!conditions.length) return null; | ||
} | ||
function createValuelessBuilder(operator) { | ||
@@ -33,3 +29,2 @@ return function (key) { | ||
} | ||
function createBuilder(operator) { | ||
@@ -44,6 +39,4 @@ return function (key, value) { | ||
} | ||
module.exports.and = createMultiConditionBuilder(OPERATORS.AND); | ||
module.exports.or = createMultiConditionBuilder(OPERATORS.OR); | ||
module.exports.not = function (c) { | ||
@@ -55,3 +48,2 @@ return normalize({ | ||
}; | ||
module.exports.known = createValuelessBuilder(OPERATORS.KNOWN); | ||
@@ -58,0 +50,0 @@ module.exports.unknown = createValuelessBuilder(OPERATORS.UNKNOWN); |
'use strict'; | ||
var aqlParser = require('@ambassify/aql-parser'); | ||
var normalize = require('./normalize'); | ||
function parse(str) { | ||
@@ -11,3 +9,2 @@ var condition = aqlParser.condition(str) || (aqlParser.url(str) || {}).condition; | ||
} | ||
module.exports = Object.assign({ | ||
@@ -14,0 +11,0 @@ OPERATORS: require('./operators'), |
'use strict'; | ||
var normalize = require('./normalize'); | ||
var OPERATORS = require('./operators'); | ||
var KEYLESS = OPERATORS.KEYLESS, | ||
NOT = OPERATORS.NOT; | ||
NOT = OPERATORS.NOT; | ||
function map(condition, predicate) { | ||
if (condition && KEYLESS.includes(condition.operator)) { | ||
var _condition = condition, | ||
value = _condition.value; | ||
value = _condition.value; | ||
value = condition.operator === NOT ? map(value, predicate) : value.map(function (c) { | ||
@@ -21,6 +18,4 @@ return map(c, predicate); | ||
} | ||
return predicate(condition); | ||
} | ||
function pMap(condition, predicate) { | ||
@@ -36,10 +31,7 @@ return map(condition, function (c) { | ||
} | ||
return predicate(c); | ||
}); | ||
} | ||
function filter(condition, predicate) { | ||
if (!condition || !condition.operator) return null; | ||
if (KEYLESS.includes(condition.operator)) { | ||
@@ -54,7 +46,5 @@ var value = condition.value; | ||
} | ||
if (!predicate(condition)) return null; | ||
return condition; | ||
} | ||
module.exports = { | ||
@@ -61,0 +51,0 @@ filter: filter, |
'use strict'; | ||
var OPERATORS = require('./operators'); | ||
var KEYLESS = OPERATORS.KEYLESS, | ||
AND = OPERATORS.AND, | ||
OR = OPERATORS.OR, | ||
NOT = OPERATORS.NOT; | ||
AND = OPERATORS.AND, | ||
OR = OPERATORS.OR, | ||
NOT = OPERATORS.NOT; | ||
function normalize(condition) { | ||
var _ref = condition || {}, | ||
operator = _ref.operator; | ||
operator = _ref.operator; | ||
var _ref2 = condition || {}, | ||
value = _ref2.value; | ||
value = _ref2.value; | ||
if (!operator) return null; | ||
if (!KEYLESS.includes(operator)) return condition; | ||
if (operator == AND || operator == OR) { | ||
@@ -32,3 +27,2 @@ value = value.map(normalize).filter(Boolean); | ||
} | ||
return { | ||
@@ -39,3 +33,2 @@ operator: operator, | ||
} | ||
module.exports = normalize; |
'use strict'; | ||
var _VALIDATORS; | ||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } | ||
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); } | ||
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } | ||
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } | ||
var OPERATORS = require('./operators'); | ||
function isString(v) { | ||
return typeof v === 'string'; | ||
} | ||
function isCondition(c) { | ||
if (!c || _typeof(c) !== 'object') return false; // eslint-disable-next-line no-use-before-define | ||
if (!c || _typeof(c) !== 'object') return false; | ||
// eslint-disable-next-line no-use-before-define | ||
if (!c.operator || !VALIDATORS[c.operator]) return false; | ||
return OPERATORS.KEYLESS.includes(c.operator) ? true : !!c.key; | ||
} | ||
function isValid(condition) { | ||
if (!isCondition(condition)) return false; // eslint-disable-next-line no-use-before-define | ||
if (!isCondition(condition)) return false; | ||
// eslint-disable-next-line no-use-before-define | ||
return VALIDATORS[condition.operator](condition); | ||
} | ||
var VALIDATORS = (_VALIDATORS = {}, _defineProperty(_VALIDATORS, OPERATORS.AND, function (condition) { | ||
@@ -29,0 +26,0 @@ return isCondition(condition) && Array.isArray(condition.value) && condition.value.every(isValid); |
{ | ||
"name": "@ambassify/aql-condition", | ||
"version": "0.5.0", | ||
"version": "0.6.1", | ||
"description": "AQL condition tool", | ||
@@ -8,3 +8,3 @@ "main": "src/index.js", | ||
"engines": { | ||
"node": "8" | ||
"node": ">=16" | ||
}, | ||
@@ -14,3 +14,3 @@ "scripts": { | ||
"prepublishOnly": "npm run test && npm run build", | ||
"build": "n-clean lib && babel -d lib src", | ||
"build": "babel --delete-dir-on-start -d lib src", | ||
"test": "npm run test:lint && npm run test:unit", | ||
@@ -31,3 +31,3 @@ "test:lint": "eslint --fix \"@(src|test)/**\"", | ||
"dependencies": { | ||
"@ambassify/aql-parser": "^0.5.0" | ||
"@ambassify/aql-parser": "^0.6.1" | ||
}, | ||
@@ -39,7 +39,6 @@ "devDependencies": { | ||
"eslint": "^5.16.0", | ||
"eslint-config-ambassify": "^1.2.0", | ||
"eslint-config-ambassify": "^3.0.1", | ||
"lodash": "^4.17.21", | ||
"mocha": "^6.1.2", | ||
"npm-build-tools": "^2.2.5", | ||
"nyc": "^13.3.0" | ||
"mocha": "^10.2.0", | ||
"nyc": "^15.1.0" | ||
}, | ||
@@ -49,3 +48,3 @@ "publishConfig": { | ||
}, | ||
"gitHead": "820d155d7d7c0b959d7d239cd10c0f42912cb97d" | ||
"gitHead": "5240ba4b26c6fb088026a28a576ddaaf26ce1db5" | ||
} |
@@ -29,3 +29,3 @@ 'use strict'; | ||
return function(key, value) { | ||
return { key, operator, value}; | ||
return { key, operator, value }; | ||
}; | ||
@@ -32,0 +32,0 @@ } |
'use strict'; | ||
module.exports = Object.freeze({ | ||
KEYLESS: ['and', 'or', 'not'], | ||
KEYLESS: [ 'and', 'or', 'not' ], | ||
AND: 'and', | ||
@@ -6,0 +6,0 @@ OR: 'or', |
{ | ||
"parserOptions": { | ||
"ecmaFeatures": { | ||
"experimentalObjectRestSpread": true | ||
} | ||
}, | ||
"extends": [ | ||
@@ -11,4 +6,4 @@ "eslint-config-ambassify/mocha" | ||
"rules": { | ||
"node/no-unpublished-require": [ 0 ] | ||
"n/no-unpublished-require": [ 0 ] | ||
} | ||
} |
@@ -8,3 +8,3 @@ 'use strict'; | ||
describe('# builder', function () { | ||
describe('# builder', function() { | ||
@@ -11,0 +11,0 @@ it('should expose a method for every operator', () => { |
@@ -6,3 +6,3 @@ 'use strict'; | ||
describe('# filter', function () { | ||
describe('# filter', function() { | ||
@@ -9,0 +9,0 @@ it('should recursively filter a condition based on a predicate', () => { |
@@ -7,3 +7,3 @@ 'use strict'; | ||
describe('# map', function () { | ||
describe('# map', function() { | ||
@@ -28,3 +28,3 @@ it('should recursively map a condition based on a predicate', () => { | ||
describe('# pMap', function () { | ||
describe('# pMap', function() { | ||
@@ -31,0 +31,0 @@ it('should recursively map a condition based on a predicate that returns a promise', async () => { |
@@ -6,3 +6,3 @@ 'use strict'; | ||
describe('# normalize', function () { | ||
describe('# normalize', function() { | ||
@@ -9,0 +9,0 @@ it('should filter out conditions that are always true (~= empty conditions)', () => { |
@@ -6,3 +6,3 @@ 'use strict'; | ||
describe('# parse', function () { | ||
describe('# parse', function() { | ||
@@ -9,0 +9,0 @@ it('should expose the AQL condition parser', () => { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
67401
8
25
843
+ Added@ambassify/aql-parser@0.6.1(transitive)
- Removed@ambassify/aql-parser@0.5.0(transitive)
Updated@ambassify/aql-parser@^0.6.1