Comparing version 1.0.1 to 1.0.2
{ | ||
"name": "aul", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "Elegant database queries executor", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -22,3 +22,3 @@ "use strict"; | ||
this._source = source; | ||
this._filters = {}; | ||
this._filters = Object.create(null); | ||
this._mappers = []; | ||
@@ -30,4 +30,13 @@ } | ||
* @param {{}} opts | ||
* @param {boolean} append | ||
*/ | ||
addFilter(name, opts) { | ||
addFilter(name, opts, append = false) { | ||
if (name in this._filters && append) { | ||
this._filters[name] = [].concat.call( | ||
[], | ||
this._filters[name], | ||
[opts] | ||
); | ||
return; | ||
} | ||
this._filters[name] = opts; | ||
@@ -34,0 +43,0 @@ } |
@@ -61,3 +61,3 @@ "use strict"; | ||
resolveFilters(filtersMap) { | ||
return Object.keys(filtersMap) | ||
const results = Object.keys(filtersMap) | ||
.map(name => { | ||
@@ -67,5 +67,9 @@ if (typeof name === "function") { | ||
} | ||
let filterPath = this.resolveFilterPath(name); | ||
return require(filterPath)(filtersMap[name]); | ||
const filterPath = this.resolveFilterPath(name); | ||
const filterModule = require(filterPath); | ||
const filterOpts = filtersMap[name]; | ||
return Array.isArray(filterOpts) ? filterOpts.map(opts => filterModule(opts)) : filterModule(filtersMap[name]); | ||
}); | ||
return [].concat.apply([], results); | ||
} | ||
@@ -72,0 +76,0 @@ |
@@ -67,3 +67,3 @@ "use strict"; | ||
t.throws(function () { | ||
ex.resolveFilterPath("test2"); | ||
ex.resolveFilterPath("unknownFilter"); | ||
}); | ||
@@ -85,2 +85,18 @@ }); | ||
test("resolveFilters return array of function even if filters were appended", t => { | ||
t.plan(2); | ||
const path = require("path"); | ||
const ex = new Executor({path: path.join(process.cwd(), "test/fixtures")}); | ||
const res = ex.resolveFilters({ | ||
test: {}, | ||
test2: [ | ||
{opt1: 1}, | ||
{opt1: 2} | ||
] | ||
}); | ||
t.true(Array.isArray(res)); | ||
t.is(res.length, 3); | ||
}); | ||
test("mapValues", t => { | ||
@@ -87,0 +103,0 @@ const path = require("path"); |
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
20175
17
364