Skip to content

Latest commit

 

History

History
816 lines (481 loc) · 14.2 KB

api.md

File metadata and controls

816 lines (481 loc) · 14.2 KB

Table of Contents

create

create a new restify json client. a new one is created for each outbound API request (i.e., one per model). TODO: this is potentially expensive, need to investigate creating a single client per incoming request (i.e., per user, per remote host) crux of the problem is allowing customization on a per request basis (headers), which currently requires creating a new client per model.

Parameters

  • model Object a restify model

Returns Object a restify JsonClient

Conductor

Class definition

Parameters

  • config Object user configuration object.
    • config.name String a name for your conductor
    • config.deps Array? an array of dependencies to be mixed in
    • config.props Object? props to create for this conductor.
    • config.handlers Object? an object or array of handlers

name

name of the conductor

Type: String

getHandlers

retrieves a handler block for a given key.

Parameters

  • key String the key of the handler block

Returns Array an array of function handlers

getHandlerKeys

retrieves the sorted handler keys for the conductor.

Returns Array an array of strings

getProps

retrieves an immutable property. if no name passed in, return all props.

Parameters

  • name String? optional name of the prop to retrieve.

Returns Object the copy of the prop

getProps

retrieve an immutable prop off the conductor object

Parameters

  • req Object the request object
  • propName String the name of the prop to retrieve

Returns Object a prop value

createModels

iterates through a specific model bucket, invoking each function in the array to create a new instance of a model. does not change any state.

Parameters

  • req Object the request object
  • res Object the response object
  • bucketName String the name of the model bucket to create.

Returns Array an array of models

getDebugHandlerStack

returns a flattened list of handler stacks. for debug use only.

Returns Array an array of function names and the index of their blocks

buildModelsWrapper

a handler to build any models defined on the conductor.

Parameters

  • modelBucket Array a key we can use to look up a bucket of models defined on the conductor
  • modelFetcher Function function to run for fetching / creating models. The function should accept req as the first parameter, req as the second, a models array as the third, and a callback as the fourth.

Returns undefined

initWrapper

a handler to initialize the restify conductor namespaces on the request and response objects.

Parameters

  • conductor Object an instance of restify conductor

Returns void

runHandlersWrapper

a handler to run the wrapped conductor handlers. no options at the moment.

Returns undefined

createConductor

wrapper function for creating conductors

Parameters

  • options Object an options object

Returns Conductor a Conductor instance

createConductor

wrapper function for creating models. we MUST return a closure, this is necessary to provide req res to the lifecycle methods, and allow us to return a new model for each new incoming request.

Parameters

  • options Object an options object

Returns Function

createConductorHandlers

Create a middleware chain that executes a specific conductor

Parameters

  • conductor Object a Conductor instance

Returns Array<Function>

methodInstaller

programatically create wrapperis for Restify's server[method]

Parameters

  • opts (String | Object) the url of REST resource or opts to pass to Restify
  • conductor Conductor a conductor instance
  • server Object a restify server

Returns undefined

getDefault

retrieves default restify-conductor logger

Returns Object bunyan logger

child

creates a child logger from default restify-conductor logger

Parameters

  • name String name of child logger

Returns Object bunyan logger

addSerializers

add the restify-conductor specific serializers

Parameters

Returns void

Model

Model class. abstraction for restify-conductor models.

Parameters

  • config Object model configuration object

props

arbitrary model props

Type: Object

data

the model data

Type: Object

errors

collected errors that may have occurred through the lifecycle methods.

Type: Array

log

a bunyan instance for loggin

Type: Object

client

a remote client that implements a get() method for fetching remote data

Type: Object

type

model type for debugging purposes

Type: String

name

model name

Type: String

async

flag used to help debug. true if the model is async.

Type: Boolean

before

default noop for all models. gives users a hook to modify the model before requesting it.

Parameters

  • req Object the request object
  • res Object the response object

Returns undefined

after

default noop for all models. gives users a hook to modify the model after getting a return value.

Parameters

  • req Object the request object
  • res Object the response object

Returns undefined

isValid

lifecycle method for validating returned data.

Parameters

  • data Object the data to validate

Returns Boolean

fallback

default noop for all models. gives users a hook to handle validation errors.

Returns Object

get

public method to invoke the get of the model data.

Parameters

Returns undefined

get

retrieves the remote resource.

Parameters

  • callback Function a callback function to invoke when complete

Returns Object the parsed JSON response

preConfigure

public method to invoke the before chain of lifecycle events.

Parameters

  • req Object the request object
  • res Object the response object
  • options Object an options object

Returns undefined

postConfigure

public method to invoke the after chain of lifecycle events.

Parameters

  • req Object the request object
  • res Object the response object

Returns undefined

RestModel

RestModel class. abstraction for restify-conductor models.

Parameters

  • config Object model configuration object

type

model type for debugging purposes

Type: String

async

flag used to help debug. true if the model is async.

Type: Boolean

method

the type of http request. defaults to GET.

Type: String

secure

whether or not the request should be made over https.

Type: Boolean

host

the hostname for the request

Type: String

port

port number for remote host

Type: Number

baseUrl

the base url of the request: http://{hostname}/{baseurl}

Type: String

url

the specific url of the request: http://{hostname}/{baseurl}/{url}

Type: String

qs

a query string object

Type: Object

postBody

a post body object

Type: Object

postType

if a post request, the post type. defafult is json, can also be 'form'.

Type: String

headers

specific headers set for this model

Type: Object

resourceType

the format of the returned payload. defaults to JSON, but can be XML or other.

Type: String

rawResponseData

some cherry picked debug about the external resource call.

Type: Object

fallbackMode

whether or not model is operating in fallback mode.

Type: Boolean

getConductor

returns the conductor for a given request.

Parameters

  • req Object the request object

Returns undefined

getClient

returns a restify JSON client if one exists for this host for this incoming request. otherwise, creates one.

Parameters

  • req Object the request object
  • model Object a restify model

Returns Object a restify JSON client

getModels

gets all the saved models off the request

Parameters

  • req Object the request object
  • modelName String? name of the model to retrieve. returns all models if not specified.

Returns (Object | Array) returns an array of models, or just one model.

getReqTimerPrefix

gets the current request timer prefix name. useful for using it to prefix other request timers.

Parameters

  • req Object the request object

Returns String

setReqTimerPrefix

sets the current timer name prefix.

Parameters

  • req Object the request object
  • prefix String the timer name prefix

Returns undefined

setModel

saves a model onto the request

Parameters

  • req Object the request object
  • model Object an instance of a Model or RestModel.

Returns undefined

shardConductor

replace an conductor midstream with a .createAction

Parameters

  • req Object the request object
  • newConductor Object a Conductor

Returns undefined