Pipeline
Completion and validation pipeline
The pipeline works by applying a sequence of actions (represented as Koa's middlewares). When an action fails, the middleware returns an error that needs to be handled by the client who emitted that request.
The pipeline works the following way:
For PUT requests (UPDATE):
- Check if entity exists, if not, fails
- Merge JSON body with existing entity
- Apply default fields
- Complete fields
- Format fieds
- Validate fields
- UPDATE or FAIL
For POST requests (CREATE):
- Start at 2. from the above list
- CREATE or FAIL.
Static Method Summary
Static Public Methods | ||
public static |
check(type: *): * Invoke the dispatcher to check if the entity exists |
|
public static |
complete(type: *): * Invoke the dispatcher to complete the input |
|
public static |
defaults(type: *): * Invoke the dispatcher to include default values in the input |
|
public static |
filter(type: *): * Invoke the dispatcher to filter the input |
|
public static |
format(type: *): * Invoke the dispatcher to format the input |
|
public static |
memoize_model(type: string): Function |
|
public static |
merge(type: *): * Invoke the dispatcher to merge previous entity with new input |
|
public static |
reset(type: *): * Invoke the dispatcher to reset the input |
|
public static |
transform(type: *): * Invoke the dispatcher to transform the input |
|
public static |
validate(type: *): * Invoke the dispatcher to validate the input |
Static Private Methods | ||
private static |
_action(type: *, m: *): * Dispatcher to apply each part of the pipeline |
|
private static |
async _check_if_entity_exists(body: Object, type: string): Promise<boolean> Check if an entity exists in the DB by using its type (publication, user, journal, ...). |
|
private static |
async _evaluate_pipeline(item: Object, extra_info: Object, pipeline: Object, type: string, action: string, method: string): {"item": *, "errors": *} |
|
private static |
|
|
private static |
_format_range(potential_range: *, total: *): undefined[] |
|
private static |
_merge_defaults(input: Object, defaults: Object): Object Merge two objects, considering the second one as default values (if key exists in the first object, the first object keeps its own values). |
|
private static |
_merge_put(input: Object, defaults: Object): Object |
|
private static |
async _papply(item: Object, extra_info: Object, type: string, pipelines: Array<Object>, action: string, method: string, range: Array<any>, bulk_mode: boolean): Promise<Object> |
|
private static |
|
Static Public Methods
public static check(type: *): * source
Invoke the dispatcher to check if the entity exists
Params:
Name | Type | Attribute | Description |
type | * | Entity type; |
Return:
* | Koa middleware |
public static complete(type: *): * source
Invoke the dispatcher to complete the input
Params:
Name | Type | Attribute | Description |
type | * | Entity type; |
Return:
* | Koa middleware |
public static defaults(type: *): * source
Invoke the dispatcher to include default values in the input
Params:
Name | Type | Attribute | Description |
type | * | Entity type; |
Return:
* | Koa middleware |
public static filter(type: *): * source
Invoke the dispatcher to filter the input
Params:
Name | Type | Attribute | Description |
type | * | Entity type; |
Return:
* | Koa middleware |
public static format(type: *): * source
Invoke the dispatcher to format the input
Params:
Name | Type | Attribute | Description |
type | * | Entity type; |
Return:
* | Koa middleware |
public static memoize_model(type: string): Function source
Params:
Name | Type | Attribute | Description |
type | string |
public static merge(type: *): * source
Invoke the dispatcher to merge previous entity with new input
Params:
Name | Type | Attribute | Description |
type | * | Entity type; |
Return:
* | Koa middleware |
public static reset(type: *): * source
Invoke the dispatcher to reset the input
Params:
Name | Type | Attribute | Description |
type | * | Entity type; |
Return:
* | Koa middleware |
public static transform(type: *): * source
Invoke the dispatcher to transform the input
Params:
Name | Type | Attribute | Description |
type | * | Entity type; |
Return:
* | Koa middleware |
public static validate(type: *): * source
Invoke the dispatcher to validate the input
Params:
Name | Type | Attribute | Description |
type | * | Entity type; |
Return:
* | Koa middleware |
Static Private Methods
private static _action(type: *, m: *): * source
Dispatcher to apply each part of the pipeline
Params:
Name | Type | Attribute | Description |
type | * | Entity type |
|
m | * | Part of the pipeline to apply |
Return:
* | Koa middleware |
private static async _check_if_entity_exists(body: Object, type: string): Promise<boolean> source
Check if an entity exists in the DB by using its type (publication, user, journal, ...).
private static async _evaluate_pipeline(item: Object, extra_info: Object, pipeline: Object, type: string, action: string, method: string): {"item": *, "errors": *} source
Return:
{"item": *, "errors": *} |
private static _format_range(potential_range: *, total: *): undefined[] source
Params:
Name | Type | Attribute | Description |
potential_range | * | ||
total | * |
private static _merge_defaults(input: Object, defaults: Object): Object source
Merge two objects, considering the second one as default values (if key exists in the first object, the first object keeps its own values).