Global

Methods

_generateSuccessDetails(req, data) → {Object}

Appends a standard set of request data to a success response

Parameters:
Name Type Description
req Object

An express request object

data Object

Data to be included in response

Source:
Returns:

The original data with request information added

Type
Object

_IMPLEMENT(options) → {Object}

Generates a set of controller functions indexed by a standard set of properties

Parameters:
Name Type Description
options Object

Configurable options for the creation of model specific middleware

Properties
Name Type Attributes Description
override Object <optional>

A set of middleware functions that will be used in place of defaults

Properties
Name Type Attributes Description
new function <optional>

Override function for standard "new" view rendering function

show function <optional>

Override function for standard "show" view rendering function

edit function <optional>

Override function for standard "edit" view rendering function

index function <optional>

Override function for standard "index" view rendering function

remove function <optional>

Override function for standard "remove" middleware

search function <optional>

Override function for standard "search" view rendering function

create function <optional>

Override function for standard "create" middleware

update function <optional>

Override function for standard "update" middleware

load function <optional>

Override function for standard "load" middleware

paginate function <optional>

Override function for standard "paginate" middleware

router Object <optional>

An express router that routes will be appended on. If no router is provided routes will not be registered and only controller functions are returned

Source:
Returns:

A set of controller functions a express router if options.router was provided

Type
Object

CLI(options) → {function}

Generates a function that handles CLI inputs for queries

Parameters:
Name Type Description
options Object

Configurable options for CLI handler

Properties
Name Type Description
protocol Object

A protocol adapter with a defined db property containing database adapters indexed by model name

Source:
Returns:

Returns a function that handles CLI inputs for queries and writes result to process stdout

Type
function

composeMiddleware(options) → {function}

A convenience method for creating view rendering middleware for a given model

Parameters:
Name Type Description
options Object

Configurable options

Properties
Name Type Attributes Description
fileext string <optional>

Defines the file extension of the view file being rendered

viewname string <optional>

Defines the basename, partial path or full path of a view file

themename string <optional>

Specifies a periodicjs theme folder that will be searched for a the view file

basename string <optional>

If viewname is not provided basename is used to define a best guess viewname by combining options.model_name and options.basename

model_name string <optional>

The name of the model that the middleware is being generated for

protocol Object <optional>

A parent protocol adapter that must have a defined responder property

transform_data function

A function for pulling data out of a request object and assigning it to an eventual response body

strict Boolean <optional>

When falsy defined protocol responder will always be used instead of default HTML adapter. Default HTML adapter will also be ignored if protocol responder is an HTML adapter

Source:
Returns:

Returns an express middleware function that will render a view dependent on options

Type
function

CREATE(options) → {function}

Generates middleware that handles creating items in a database

Parameters:
Name Type Description
options Object

Configurable options for create middleware

Properties
Name Type Description
model_name string

Name of the model that the view middleware is being generated for

protocol Object

A protocol adapter with a defined db property containing database adapters indexed by model name

Source:
Returns:

Returns middleware that handles creating items

Type
function

EDIT(options) → {function}

Generates middleware that will render the "edit" view

Parameters:
Name Type Description
options Object

Configurable options for "edit" view rendering

Properties
Name Type Attributes Description
use_plural_view_name Boolean <optional>

If true the plural value of the model name will be used in the view

template_ext string

Used in specifying a custom file extension for view files

model_name string

Name of the model that the view middleware is being generated for

Source:
Returns:

Returns a middleware function that will render "edit" view

Type
function

generateErrorDetails(req, data) → {Object}

Appends a standard set of request data to an error response

Parameters:
Name Type Description
req Object

An express request object

data Object

Error data that should be included in response

Source:
Returns:

The original error data with request information added

Type
Object

INDEX(options) → {function}

Generates middleware that will render the "index" view

Parameters:
Name Type Description
options Object

Configurable options for "index" view rendering

Properties
Name Type Attributes Description
use_plural_view_name Boolean <optional>

If true the plural value of the model name will be used in the view

template_ext string

Used in specifying a custom file extension for view files

model_name string

Name of the model that the view middleware is being generated for

Source:
Returns:

Returns a middleware function that will render "index" view

Type
function

LOAD(options) → {function}

Generates middleware that handles querying for a single populated item

Parameters:
Name Type Description
options Object

Configurable options for load middleware

Properties
Name Type Description
protocol Object

A protocol adapter with a defined db property containing database adapters indexed by model name

Source:
Returns:

Returns a middleware function that will query the database for a single item which is populated by default

Type
function

LOAD_WITH_COUNT(options) → {function}

Generates middleware that sets a property on req.headers that specifies that query results should be paginated

Parameters:
Name Type Description
options Object

Configurable options for generating middleware

Properties
Name Type Description
model_name string

Name of the model being queried

Source:
Returns:

Returns a middleware that ensures that query results are paginated

Type
function

LOAD_WITH_LIMIT(options) → {function}

Generates middleware that sets a default limit and starting page for paginated queries

Parameters:
Name Type Description
options Object

Configurable options for generating middleware

Source:
Returns:

Returns a middleware that set default limit and starting page number params on req.query for paginated queries

Type
function

NEW(options) → {function}

Generates middleware that will render the "new" view

Parameters:
Name Type Description
options Object

Configurable options for "new" view rendering

Properties
Name Type Attributes Description
use_plural_view_name Boolean <optional>

If true the plural value of the model name will be used in the view

template_ext string

Used in specifying a custom file extension for view files

model_name string

Name of the model that the view middleware is being generated for

Source:
Returns:

Returns a middleware function that will render "new" view

Type
function

PAGINATE(options) → {function}

Generates middleware that handles querying a database and returning paginated data

Parameters:
Name Type Description
options Object

Configurable options for generating middleware for making queries that will return paginated data

Properties
Name Type Attributes Default Description
protocol Object

A protocol adapter with a defined db property containing database adapters indexed by model name

query Object <optional>
{}

Sets a default query that should be used. This value is ignored if req.controllerData.model_query is set

fields Object <optional>

A default set of fields to pull when middleware is called this value is ignored if req.controllerData.model_fields is set

population string | Object <optional>
""

Population settings for model

Source:
Returns:

Returns a middleware function that will query the database and return paginated data

Type
function

REMOVE(options) → {function}

Generates middleware that handles deleting items from a database

Parameters:
Name Type Description
options Object

Configurable options for delete middleware

Properties
Name Type Description
model_name string

Name of the model that the view middleware is being generated for

protocol Object

A protocol adapter with a defined db property containing database adapters indexed by model name

Source:
Returns:

Returns middleware that handles deleting items

Type
function

Generates middleware that handles rendering a view from paginated data

Parameters:
Name Type Description
options Object

Configurable options for querying middleware

Properties
Name Type Attributes Description
use_plural_view_name Boolean <optional>

If true the plural value of the model name will be used in the view

template_ext string

Used in specifying a custom file extension for view files

model_name string

Name of the model that the view middleware is being generated for

Source:
Returns:

Returns middleware that handles rendering a view from paginated data

Type
function

setViewModelProperties(model_name) → {Object}

Checks to see if active model label matches model name. If there is a match returns active model inflected name values otherwise generates expanded names from model name and sets value to active model

Parameters:
Name Type Description
model_name string

String value that should be inflected

Source:
Returns:

Returns an object containing inflected string values

Type
Object

SHOW(options) → {function}

Generates middleware that will render the "show" view

Parameters:
Name Type Description
options Object

Configurable options for "show" view rendering

Properties
Name Type Attributes Description
use_plural_view_name Boolean <optional>

If true the plural value of the model name will be used in the view

template_ext string

Used in specifying a custom file extension for view files

model_name string

Name of the model that the view middleware is being generated for

Source:
Returns:

Returns a middleware function that will render "show" view

Type
function

UPDATE(options) → {function}

Generates middleware that handles updating an item in a database

Parameters:
Name Type Description
options Object

Configurable options for delete middleware

Properties
Name Type Description
model_name string

Name of the model that the view middleware is being generated for

protocol Object

A protocol adapter with a defined db property containing database adapters indexed by model name

Source:
Returns:

Returns middleware that handles updating items

Type
function