Constructor
new EntityProvider(storage, location)
Defines a provider holding a single type of resources.
An entity provider manages a single type of resources. These resources are stored into the given storage / location.
Parameters:
Name | Type | Description |
---|---|---|
storage |
module:storages/Storage~Storage | The storage to use to store provider entities |
location |
String | The location of the entities in the storage |
- Source:
Throws:
-
If storage and / or location is not valid
- Type
- TypeError
Extends
Members
(readonly) location :String
The location of the entities in the storage.
Type:
- String
- Source:
Methods
add(entities, callbackopt)
Adds entities.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
entities |
Array | The list of entities to store |
|
callback |
module:providers/EntityProvider~EntityProvider~addCallback |
<optional> |
The function to call when it's done |
- Source:
executeCallback(callbackopt, erroropt, callbackopt)
Executes the given callback or log the error message if no callback specified.
It assumes that the second argument is the error. All arguments, except the callback itself, will be specified as arguments when executing the callback.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
callback |
function |
<optional> |
The function to execute |
error |
Error |
<optional> |
An eventual error to pass to the callback |
callback |
callback |
<optional> |
The function to call, if not specified the error is logged |
- Inherited From:
- Source:
get(filteropt, fieldsopt, limitopt, pageopt, sortopt, callback)
Fetches entities.
Parameters:
Name | Type | Attributes | Description | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
filter |
module:storages/ResourceFilter~ResourceFilter |
<optional> |
Rules to filter entities |
||||||||||||
fields |
Object |
<optional> |
Fields to be included or excluded from the response, by default all fields are returned. Only "exclude" or "include" can be specified, not both Properties
|
||||||||||||
limit |
Number |
<optional> |
A limit number of entities to retrieve (10 by default) |
||||||||||||
page |
Number |
<optional> |
The page number started at 0 for the first page |
||||||||||||
sort |
Object |
<optional> |
The list of fields to sort by with the field name as key and the sort order as value (e.g. {field1: 'asc', field2: 'desc', field3: 'score'}) |
||||||||||||
callback |
module:providers/EntityProvider~EntityProvider~getCallback | The function to call when it's done |
- Source:
getAll(filteropt, fieldsopt, sort, callback)
Gets all entities from storage iterating on all pages.
Parameters:
Name | Type | Attributes | Description | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
filter |
module:storages/ResourceFilter~ResourceFilter |
<optional> |
Rules to filter entities |
||||||||||||
fields |
Object |
<optional> |
Fields to be included or excluded from the response, by default all fields are returned. Only "exclude" or "include" can be specified, not both Properties
|
||||||||||||
sort |
Object | The list of fields to sort by with the field name as key and the sort order as value (e.g. {field1: 'asc', field2: 'desc', field3: 'score'}) |
|||||||||||||
callback |
module:providers/EntityProvider~EntityProvider~getAllCallback | Function to call when it's done |
- Source:
getOne(filteropt, fieldsopt, callback)
Fetches an entity.
If filter corresponds to more than one entity, the first found entity will be the returned one.
Parameters:
Name | Type | Attributes | Description | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
filter |
module:storages/ResourceFilter~ResourceFilter |
<optional> |
Rules to filter entities |
||||||||||||
fields |
Object |
<optional> |
Fields to be included or excluded from the response, by default all fields are returned. Only "exclude" or "include" can be specified, not both Properties
|
||||||||||||
callback |
module:providers/EntityProvider~EntityProvider~getOneCallback | The function to call when it's done |
- Source:
remove(filteropt, callbackopt)
Removes entities.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
filter |
module:storages/ResourceFilter~ResourceFilter |
<optional> |
Rules to filter entities to remove |
callback |
module:providers/EntityProvider~EntityProvider~removeCallback |
<optional> |
The function to call when it's done |
- Source:
removeField(field, filteropt, callbackopt)
Removes a field from entities.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
field |
String | The field to remove from entities |
|
filter |
module:storages/ResourceFilter~ResourceFilter |
<optional> |
Rules to filter entities to update |
callback |
module:providers/EntityProvider~EntityProvider~removeFieldCallback |
<optional> |
The function to call when it's done |
- Source:
updateOne(filteropt, data, callbackopt)
Updates an entity.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
filter |
module:storages/ResourceFilter~ResourceFilter |
<optional> |
Rules to filter the entity to update |
data |
Object | The modifications to perform |
|
callback |
module:providers/EntityProvider~EntityProvider~updateOneCallback |
<optional> |
The function to call when it's done |
- Source:
Type Definitions
addCallback(error, total, entities)
Parameters:
Name | Type | Description |
---|---|---|
error |
Error | null | The error if an error occurred, null otherwise |
total |
Number | undefined | The total amount of entities inserted |
entities |
Array | undefined | The list of added entities |
- Source:
getAllCallback(error, entities)
Parameters:
Name | Type | Description |
---|---|---|
error |
Error | null | The error if an error occurred, null otherwise |
entities |
Array | undefined | The list of entities |
- Source:
getCallback(error, entities, pagination)
Parameters:
Name | Type | Description | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
error |
Error | null | The error if an error occurred, null otherwise |
|||||||||||||||
entities |
Array | undefined | The list of retrieved entities |
|||||||||||||||
pagination |
Object | undefined | Pagination information Properties
|
- Source:
getOneCallback(error, entity)
Parameters:
Name | Type | Description |
---|---|---|
error |
Error | null | The error if an error occurred, null otherwise |
entity |
Object | undefined | The entity |
- Source:
removeCallback(error, total)
Parameters:
Name | Type | Description |
---|---|---|
error |
Error | null | The error if an error occurred, null otherwise |
total |
Number | undefined | The number of removed entities |
- Source:
removeFieldCallback(error, total)
Parameters:
Name | Type | Description |
---|---|---|
error |
Error | null | The error if an error occurred, null otherwise |
total |
Number | undefined | The number of updated entities |
- Source:
updateOneCallback(error, 1)
Parameters:
Name | Type | Description |
---|---|---|
error |
Error | null | The error if an error occurred, null otherwise |
1 |
Number | undefined | if everything went fine |
- Source: