queryfilters
Advanced tools
Comparing version 0.1.5 to 0.1.6
{ | ||
"name": "queryfilters", | ||
"version": "v0.1.5", | ||
"version": "v0.1.6", | ||
"scripts": { | ||
@@ -5,0 +5,0 @@ "test": "jest" |
108
queryql.js
@@ -1,38 +0,54 @@ | ||
function QueryQl() { | ||
const relation = 1; | ||
function Combinators () { | ||
const COMBINATORS_AND = 'and'; | ||
const COMBINATORS_DEFAULT = 'filtering'; | ||
const COMBINATORS_OR = 'or'; | ||
this.getCombinators = function () { | ||
return [ | ||
COMBINATORS_AND, | ||
COMBINATORS_DEFAULT, | ||
COMBINATORS_OR | ||
]; | ||
} | ||
this.getDefaultCombinator = function () { | ||
return COMBINATORS_DEFAULT; | ||
}; | ||
} | ||
function QueryStringBuilder () { | ||
this.filters = []; | ||
this.combine = 'filtering'; | ||
var combinators = new Combinators(); | ||
this.rel = []; | ||
this.combinators = combinators.getCombinators(); | ||
this.combinators = ['filtering', 'or', 'and']; | ||
this.combine = combinators.getDefaultCombinator(); | ||
this.applyFilter = function (filter) { | ||
this.filters.push(filter); | ||
}; | ||
this.getRels = function () { | ||
this.rel = []; | ||
for (f in this.filters) { | ||
var filter = this.filters[f]; | ||
if (this.containsRelations(filter)) { | ||
filterRelation = filter.field.split('.')[relation]; | ||
this.rel.push(filterRelation); | ||
} | ||
this.ensureHaveValidCombinator = function () | ||
{ | ||
if (!this.combinators.includes(this.getCombinator())) { | ||
throw new Error('combinator ' + this.getCombinator() + ' is not available'); | ||
} | ||
return this.rel; | ||
}; | ||
return this; | ||
} | ||
this.setCombinator = function (combinator) { | ||
this.combine = combinator; | ||
return this; | ||
}; | ||
this.getQueryString = function () { | ||
if (!this.combinators.includes(this.combine)) { | ||
throw new Error('combinator ' + this.combine + ' is not available'); | ||
} | ||
this.getCombinator = function () { | ||
return this.combine; | ||
}; | ||
this.setFilters = function (filters) { | ||
this.filters = filters; | ||
return this; | ||
}; | ||
this.build = function () { | ||
var qs = ''; | ||
@@ -73,2 +89,44 @@ var rel = ''; | ||
this.containsRelations = function (filter) { | ||
return filter.field.indexOf('_embedded') !== -1; | ||
}; | ||
} | ||
function QueryQl() { | ||
const relation = 1; | ||
this.setCombinator = function (combinator) { | ||
this.builder.setCombinator(combinator); | ||
return this; | ||
}; | ||
this.builder = new QueryStringBuilder(); | ||
this.filters = []; | ||
this.rel = []; | ||
this.applyFilter = function (filter) { | ||
this.filters.push(filter); | ||
}; | ||
this.getRels = function () { | ||
this.rel = []; | ||
for (f in this.filters) { | ||
var filter = this.filters[f]; | ||
if (this.builder.containsRelations(filter)) { | ||
filterRelation = filter.field.split('.')[relation]; | ||
this.rel.push(filterRelation); | ||
} | ||
} | ||
return this.rel; | ||
}; | ||
this.getQueryString = function () { | ||
return this.builder | ||
.ensureHaveValidCombinator() | ||
.setFilters(this.filters) | ||
.build(); | ||
}; | ||
this.getFilters = function () { | ||
@@ -81,6 +139,2 @@ var filters = []; | ||
}; | ||
this.containsRelations = function (filter) { | ||
return filter.field.indexOf('_embedded') !== -1; | ||
}; | ||
} | ||
@@ -87,0 +141,0 @@ |
@@ -11,4 +11,4 @@ const QueryQl = require('./queryql'); | ||
var queryQl = new QueryQl() | ||
expect(queryQl.containsRelations({ field: 'id', value: 42 })).toBe(false); | ||
expect(queryQl.containsRelations({ field: '_embedded.foo.bar', value: 42 })).toBe(true); | ||
expect(queryQl.builder.containsRelations({ field: 'id', value: 42 })).toBe(false); | ||
expect(queryQl.builder.containsRelations({ field: '_embedded.foo.bar', value: 42 })).toBe(true); | ||
}); | ||
@@ -15,0 +15,0 @@ |
# queryfilters | ||
npm install queryfilters | ||
⇓ npm install queryfilters | ||
@@ -5,0 +5,0 @@ ## Examples |
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
8724
173