Manual Reference Source
public class | source

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):

    1. Check if entity exists, if not, fails
    2. Merge JSON body with existing entity
    3. Apply default fields
    4. Complete fields
    5. Format fieds
    6. Validate fields
    7. UPDATE or FAIL
  • For POST requests (CREATE):

    1. Start at 2. from the above list
    2. 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
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

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

_filter(input: Object, filters: Array<String>): Object

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

async _reset(input: Object, resetters: Object): Object

Static Public Methods

public static check(type: *): * source

Invoke the dispatcher to check if the entity exists

Params:

NameTypeAttributeDescription
type *

Entity type;

Return:

*

Koa middleware

public static complete(type: *): * source

Invoke the dispatcher to complete the input

Params:

NameTypeAttributeDescription
type *

Entity type;

Return:

*

Koa middleware

public static defaults(type: *): * source

Invoke the dispatcher to include default values in the input

Params:

NameTypeAttributeDescription
type *

Entity type;

Return:

*

Koa middleware

public static filter(type: *): * source

Invoke the dispatcher to filter the input

Params:

NameTypeAttributeDescription
type *

Entity type;

Return:

*

Koa middleware

public static format(type: *): * source

Invoke the dispatcher to format the input

Params:

NameTypeAttributeDescription
type *

Entity type;

Return:

*

Koa middleware

public static memoize_model(type: string): Function source

Params:

NameTypeAttributeDescription
type string

Return:

Function

public static merge(type: *): * source

Invoke the dispatcher to merge previous entity with new input

Params:

NameTypeAttributeDescription
type *

Entity type;

Return:

*

Koa middleware

public static reset(type: *): * source

Invoke the dispatcher to reset the input

Params:

NameTypeAttributeDescription
type *

Entity type;

Return:

*

Koa middleware

public static transform(type: *): * source

Invoke the dispatcher to transform the input

Params:

NameTypeAttributeDescription
type *

Entity type;

Return:

*

Koa middleware

public static validate(type: *): * source

Invoke the dispatcher to validate the input

Params:

NameTypeAttributeDescription
type *

Entity type;

Return:

*

Koa middleware

Static Private Methods

private static _action(type: *, m: *): * source

Dispatcher to apply each part of the pipeline

Params:

NameTypeAttributeDescription
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, ...).

Params:

NameTypeAttributeDescription
body Object

JSON body

type string

entity type

Return:

Promise<boolean>

a promise containing a boolean

private static async _evaluate_pipeline(item: Object, extra_info: Object, pipeline: Object, type: string, action: string, method: string): {"item": *, "errors": *} source

Params:

NameTypeAttributeDescription
item Object
extra_info Object
pipeline Object
type string
action string
method string

Return:

{"item": *, "errors": *}

private static _filter(input: Object, filters: Array<String>): Object source

Params:

NameTypeAttributeDescription
input Object
filters Array<String>

Return:

Object

private static _format_range(potential_range: *, total: *): undefined[] source

Params:

NameTypeAttributeDescription
potential_range *
total *

Return:

undefined[]

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).

Params:

NameTypeAttributeDescription
input Object

input object

defaults Object

default object

Return:

Object

merged object

private static _merge_put(input: Object, defaults: Object): Object source

Params:

NameTypeAttributeDescription
input Object
defaults Object

Return:

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> source

Params:

NameTypeAttributeDescription
item Object
extra_info Object
type string
pipelines Array<Object>
action string
method string
range Array<any>
bulk_mode boolean

Return:

Promise<Object>

private static async _reset(input: Object, resetters: Object): Object source

Params:

NameTypeAttributeDescription
input Object
resetters Object

Return:

Object