Skip to content

Decorators Pipeline

Maxwell Bates edited this page Aug 6, 2014 · 3 revisions

Proposing options.decorators as an array of function IDs, through which the result of an API request will be sequentially passed before returned to the requester.

Relevant functions are get() and query()

It is expected the function(s) will return a slightly modified version of the object. Data which should not be stored in the database should be stored on a dollar-prefixed property of the object. These properties will be stripped when saving the object back to Clotho.

Each function will retrieve an object of the same signature. The first function will be passed the result of the API request, and each subsequent function will be passed the result of the previous call.

  • If the initial request returns null or an object of length 0, the pipeline is skipped
  • If a function errors, it will be skipped and the result of the previous function will be used
  • It is expect the user will handle namespace collisions

Example Request

{
  "channel" : "get",
  "data" : "anObjectID",
  "options" : {
    "decorators" : ['aFunctionID']
  }
}

Here, aFunctionID may determine further information about the sharable's schema, and could attach it on the $schema property of the object:

retreived

{
  id : "mySharableId",
  name : "my Sharable",
  schema : "my.schema.id",
  ...
}

after pipeline

{
  id : "mySharableId",
  name : "my Sharable",
  schema : "my.schema.id",
  ...
  $schema : {
    parent : "Function"
  }
}

saved to database

{
  id : "mySharableId",
  name : "my Sharable",
  schema : "my.schema.id",
  ...
}
Clone this wiki locally