loopback/node_modules/asteroid-module
Ritchie Martori 621b845978 Allow asteroid modules to define and validate options 2013-04-15 12:36:37 -07:00
..
lib Allow asteroid modules to define and validate options 2013-04-15 12:36:37 -07:00
test Update gitignore to allow node_modules 2013-04-09 11:33:29 -07:00
.gitignore Update gitignore to allow node_modules 2013-04-09 11:33:29 -07:00
README.md Allow asteroid modules to define and validate options 2013-04-15 12:36:37 -07:00
index.js Update gitignore to allow node_modules 2013-04-09 11:33:29 -07:00
package.json Update gitignore to allow node_modules 2013-04-09 11:33:29 -07:00

README.md

asteroid-module

v0.0.1

About

An AsteroidModule is an abstract class that provides a base for all asteroid modules. Its constructor takes an options argument provided by a config.json. It is also supplied with dependencies it lists on its constructor based on information in the config.json file.

Example

See resource for an example asteroid module.

AsteroidModule.dependencies

An asteroid module may define dependencies on other modules that can be configured in config.json. Eg. the collection module defines a model dependency.

Collection.dependencies = {
  model: 'model'
}

A configuration then must define:

{
  "dependencies": {
    "model": "some-model-module"
  }
}

Where some-model-module is an existing model instance.

AsteroidModule.options

Asteroid Modules may also describe the options they accept. This will validate the configuration and make sure users have supplied required information and in a way that the module can use to construct a working instance.

Here is an example options description for the oracle database connection module.

// must come after `inherits()`
OracleConnection.defineOption('hostname', 'string', {required: true});
OracleConnection.defineOption('port', 'number', {min: 10, max: 99999});
OracleConnection.defineOption('username', 'string');
OracleConnection.defineOption('password', 'string');

AsteroidModule.defineOption(key, type, [options])

key the option name given in config.json.

type must be one of:

  • string
  • boolean
  • number
  • array

options depend on the type

{
  required: true, // options are optional by default
  min: 10, // minimum length or value
  max: 100, // max length or value
}