Constructor
new ResourceFilter()
Defines a storage filter.
A filter is a uniform way of filtering results common to all storages. A filter can contain only one "or" operation, one "nor" operation and one "and" operation.
- Source:
Example
var filter = new ResourceFilter()
.equal('field1', 42)
.exists('field1', true)
.notEqual('field2', 42)
.greaterThan('field3', 42)
.greaterThanEqual('field4', 42)
.in('field5', [42])
.lesserThan('field6', 42)
.lesserThanEqual('field7', 42)
.regex('field8', /^Something/i)
.search('query')
.or([
new ResourceFilter().equal('field8', 42),
new ResourceFilter().notIn('field9', [42])
])
.nor([
new ResourceFilter().equal('field10', 42),
new ResourceFilter().notIn('field11', [42])
)],
.and([
new ResourceFilter().equal('field12', 42),
new ResourceFilter().notIn('field13', [42])
)];
Members
(static, constant) OPERATORS :Object
The available operators.
Type:
- Object
- Default Value:
{"OR":"or","NOR":"nor","AND":"and","EQUAL":"equal","EXISTS":"exists","NOT_EQUAL":"notEqual","IN":"in","NOT_IN":"notIn","GREATER_THAN":"greaterThan","GREATER_THAN_EQUAL":"greaterThanEqual","LESSER_THAN":"lesserThan","LESSER_THAN_EQUAL":"lesserThanEqual","REGEX":"regex","SEARCH":"search"}
- Source:
(readonly) operations :Array
The list of operations.
Type:
- Array
- Source:
Methods
(private, static) addComparisonOperation(field, value, Resource, The) → {module:storages/ResourceFilter~ResourceFilter}
Adds a comparison operation to the filter.
This:
Parameters:
Name | Type | Description |
---|---|---|
field |
String | The name of the field |
value |
String | Number | Boolean | Date | The value to compare the field to |
Resource |
String | filter operator |
The |
Array | list of authorized types as strings |
- Source:
Throws:
-
An error if field and / or value is not valid
- Type
- TypeError
Returns:
The actual filter
(private, static) addLogicalOperation(filters) → {module:storages/ResourceFilter~ResourceFilter}
Adds a logical operation to the filter.
Only one logical operation can be added in a filter.
This:
Parameters:
Name | Type | Description |
---|---|---|
filters |
Array | The list of filters |
- Source:
Throws:
-
An error if field and / or value is not valid
- Type
- TypeError
Returns:
The actual filter
(private, static) isValidType(value, The) → {Boolean}
Validates the type of a value.
This:
Parameters:
Name | Type | Description |
---|---|---|
value |
String | The value to test |
The |
Array | list of authorized types as strings |
- Source:
Returns:
true if valid, false otherwise
- Type
- Boolean
and(filters) → {module:storages:ResourceFilter~ResourceFilter}
Adds an "and" operation to the filter.
Parameters:
Name | Type | Description |
---|---|---|
filters |
Array | The list of filters |
- Source:
Throws:
-
An error if filters are not valid
- Type
- TypeError
Returns:
The actual filter
- Type
- module:storages:ResourceFilter~ResourceFilter
equal(field, value) → {module:storages/ResourceFilter~ResourceFilter}
Adds an equal operation to the filter.
Parameters:
Name | Type | Description |
---|---|---|
field |
String | The name of the field |
value |
String | Number | Boolean | Date | The value to compare the field to |
- Source:
Throws:
-
An error if field and / or value is not valid
- Type
- TypeError
Returns:
The actual filter
exists(field, value) → {module:storages/ResourceFilter~ResourceFilter}
Adds an exists operation to the filter.
Parameters:
Name | Type | Description |
---|---|---|
field |
String | The name of the field |
value |
Boolean | true if the field should exist, false otherwise |
- Source:
Throws:
-
An error if field and / or value is not valid
- Type
- TypeError
Returns:
The actual filter
getComparisonOperation(operator, field) → {Object|Null}
Gets an operation from filter or sub filters.
Parameters:
Name | Type | Description |
---|---|---|
operator |
String | Operation operator |
field |
String | Operation field |
- Source:
Returns:
The operation with: -String type The operation type -String field The operation field -String|Number|Boolean|Date|Array value The operation value
- Type
- Object | Null
getLogicalOperation(operator) → {Object|Null}
Gets a logical operation from filter.
Parameters:
Name | Type | Description |
---|---|---|
operator |
String | Logical operator to look for |
- Source:
Returns:
The operation with: -String type The operation type -Array filters The list of filters inside the logical operation
- Type
- Object | Null
greaterThan(field, value) → {module:storages/ResourceFilter~ResourceFilter}
Adds a "greater than" operation to the filter.
Parameters:
Name | Type | Description |
---|---|---|
field |
String | The name of the field |
value |
String | Number | Boolean | Date | The value to compare the field to |
- Source:
Throws:
-
An error if field and / or value is not valid
- Type
- TypeError
Returns:
The actual filter
greaterThanEqual(field, value) → {module:storages/ResourceFilter~ResourceFilter}
Adds a "greater than or equal" operation to the filter.
Parameters:
Name | Type | Description |
---|---|---|
field |
String | The name of the field |
value |
String | Number | Boolean | Date | The value to compare the field to |
- Source:
Throws:
-
An error if field and / or value is not valid
- Type
- TypeError
Returns:
The actual filter
hasOperation(operator) → {Boolean}
Tests if an operation has already been specified.
Parameters:
Name | Type | Description |
---|---|---|
operator |
String | Operation operator |
- Source:
Returns:
true if the operation has already been added to this filter, false otherwise
- Type
- Boolean
in(field, value) → {module:storages/ResourceFilter~ResourceFilter}
Adds an "in" operation to the filter.
Parameters:
Name | Type | Description |
---|---|---|
field |
String | The name of the field |
value |
Array | The value to compare the field to |
- Source:
Throws:
-
An error if field and / or value is not valid
- Type
- TypeError
Returns:
The actual filter
lesserThan(field, value) → {module:storages/ResourceFilter~ResourceFilter}
Adds a "lesser than" operation to the filter.
Parameters:
Name | Type | Description |
---|---|---|
field |
String | The name of the field |
value |
String | Number | Boolean | Date | The value to compare the field to |
- Source:
Throws:
-
An error if field and / or value is not valid
- Type
- TypeError
Returns:
The actual filter
lesserThanEqual(field, value) → {module:storages/ResourceFilter~ResourceFilter}
Adds a "lesser than equal" operation to the filter.
Parameters:
Name | Type | Description |
---|---|---|
field |
String | The name of the field |
value |
String | Number | Boolean | Date | The value to compare the field to |
- Source:
Throws:
-
An error if field and / or value is not valid
- Type
- TypeError
Returns:
The actual filter
nor(filters) → {module:storages/ResourceFilter~ResourceFilter}
Adds a "nor" operation to the filter.
Parameters:
Name | Type | Description |
---|---|---|
filters |
Array | The list of filters |
- Source:
Throws:
-
An error if filters are not valid
- Type
- TypeError
Returns:
The actual filter
notEqual(field, value) → {module:storages/ResourceFilter~ResourceFilter}
Adds a "not equal" operation to the filter.
Parameters:
Name | Type | Description |
---|---|---|
field |
String | The name of the field |
value |
String | Number | Boolean | Date | The value to compare the field to |
- Source:
Throws:
-
An error if field and / or value is not valid
- Type
- TypeError
Returns:
The actual filter
notIn(field, value) → {module:storages/ResourceFilter~ResourceFilter}
Adds a "not in" operation to the filter.
Parameters:
Name | Type | Description |
---|---|---|
field |
String | The name of the field |
value |
Array | The value to compare the field to |
- Source:
Throws:
-
An error if field and / or value is not valid
- Type
- TypeError
Returns:
The actual filter
or(filters) → {module:storages/ResourceFilter~ResourceFilter}
Adds a "or" operation to the filter.
Parameters:
Name | Type | Description |
---|---|---|
filters |
Array | The list of filters |
- Source:
Throws:
-
An error if filters are not valid
- Type
- TypeError
Returns:
The actual filter
regex(field, value) → {module:storages/ResourceFilter~ResourceFilter}
Adds a "regular expression" operation to the filter.
Parameters:
Name | Type | Description |
---|---|---|
field |
String | The name of the field |
value |
RegExp | The regular expression to compare the field to |
- Source:
Throws:
-
An error if field and / or value is not valid
- Type
- TypeError
Returns:
The actual filter
search(value) → {module:storages/ResourceFilter~ResourceFilter}
Adds a "search" operation to the filter.
Parameters:
Name | Type | Description |
---|---|---|
value |
String | The search query |
- Source:
Throws:
-
An error if value is not a String
- Type
- TypeError
Returns:
The actual filter