- spawnpoint
Agnostic JS framework that empowers devs to focus on quickly building apps, rather than focusing on application config, health-checks, application structure, or architecture to build a 12 factor app in Docker.
Spawnpoint can be configured to manage the entire application life-cycle or standalone as a utility library.
- callback ⇒
this
Initializes framework to read the
configFile
, init config, Spawnpoint plugins, errorCodes and autoload folders. This also starts the application life-cycle so the app can stop gracefully.
Agnostic JS framework that empowers devs to focus on quickly building apps, rather than focusing on application config, health-checks, application structure, or architecture to build a 12 factor app in Docker.
Spawnpoint can be configured to manage the entire application life-cycle or standalone as a utility library.
Kind: global class
- spawnpoint
- new spawnpoint([configFile])
- .recursiveList(dir, [exts]) ⇒
Array
- .random([length], [hashMethod]) ⇒
String
- .sample(items) ⇒
*
- .roundRobin(items) ⇒
roundRobin
- .getAndLock(items) ⇒
roundRobin
- .omit(items, keysToOmit) ⇒
Object
- .isRoot() ⇒
Boolean
- .isSecure([uid], [gid]) ⇒
Boolean
- .require(filePath)
- .code(code, [data]) ⇒
Object
- .errorCode(code, [data]) ⇒
Object
- .failCode(code, [data]) ⇒
Object
- .registerLimit(code, threshold, options, callback) ⇒
this
- .debug() ⇒
this
- .info() ⇒
this
- .log() ⇒
this
- .warn() ⇒
this
- .error() ⇒
this
- .registerError(code, error) ⇒
this
- .registerErrors(errors) ⇒
this
- .maskErrorToCode(error) ⇒
errorCode
|false
Creates new instance of spawnpoint
Param | Type | Default | Description |
---|---|---|---|
[configFile] | string |
"/config/app.json" |
Sets the JSON file spawnpoint uses to setup the framework. |
Recursively list files in a directory by an optional file extension. NOTE: This is an event blocking sync method.
Kind: instance method of spawnpoint
Returns: Array
- Absolute/full path of filenames found.
Param | Type | Description |
---|---|---|
dir | String |
Directory to list files from. |
[exts] | Array | string |
Optional list of file extensions to return. Defaults to .js files. Set to a falsy value to disable this filter. |
Utility: Create random string.
Kind: instance method of spawnpoint
Returns: String
- Random string of characters.
Param | Type | Default | Description |
---|---|---|---|
[length] | Number |
16 |
How long of a random string to create. |
[hashMethod] | String |
Which crypto hash method to use. |
Utility: get random element from collection
.
This is a copy of the lodash _.sample method.
Kind: instance method of spawnpoint
Returns: *
- Returns the random element.
Param | Type | Description |
---|---|---|
items | Array | Object |
The collection to sample. |
Utility: Creates new roundRobin
class with collection.
Kind: instance method of spawnpoint
Returns: roundRobin
- Returns new instance of roundRobin
class.
Param | Type | Description |
---|---|---|
items | Array | Object |
The collection to sample. |
Utility: get random element from collection
in an async lock.
Kind: instance method of spawnpoint
Returns: roundRobin
- Returns new instance of roundRobin
class.
Param | Type | Description |
---|---|---|
items | Array | Object |
The collection to sample. |
Utility: omit keys from an object. Similar to Lodash omit, but much faster.
Kind: instance method of spawnpoint
Returns: Object
- Returns object with requested keys removed.
Param | Type | Description |
---|---|---|
items | Object |
The source object. |
keysToOmit | Array |
Keys to omit from the object. |
Checks if the current application runtime is running as a root user/group.
Kind: instance method of spawnpoint
Returns: Boolean
- When true: the application is running as a root user/group.
Checks if the current application runtime is running as a specific uid
and/or gid
.
Kind: instance method of spawnpoint
Returns: Boolean
- When true: the application is running as the user/group.
Param | Type | Description |
---|---|---|
[uid] | Number |
Unix uid to check against. |
[gid] | Number |
Unix gid to check against. When not set will match uid . |
Helper method that requires a file and hoists the current spawnpoint application reference.
Kind: instance method of spawnpoint
Param | Type | Description |
---|---|---|
filePath | String |
File path to require. |
Builds a Spawnpoint code object. Codes are used to create a link between a human readable message
and a computer readable string. Example: file.not_found
-> "The requested file was not found."
Kind: instance method of spawnpoint
Returns: Object
- Code Object with a message
with the computer readable message and the code
matching the input code.
Param | Type | Description |
---|---|---|
code | String |
computer readable string code. |
[data] | Object |
Object to extend the code Object with |
Spawnpoint code that wraps a Javascript Error
as a hard application error.
Kind: instance method of spawnpoint
Returns: Object
- Error Code Object with a message
with the computer readable message and the code
matching the input code.
Param | Type | Description |
---|---|---|
code | String |
computer readable string code. |
[data] | Object |
Object to extend the code Object with |
Spawnpoint code that wraps a Javascript Error
, as a soft error.
Kind: instance method of spawnpoint
Returns: Object
- Error Code Object with a message
with the computer readable message and the code
matching the input code.
Param | Type | Description |
---|---|---|
code | String |
computer readable string code. |
[data] | Object |
Object to extend the code Object with |
Error Monitoring, when enabled. This allows you to track how often an error occurs and issue a callback once that threadhold is met.
Kind: instance method of spawnpoint
Param | Type | Description |
---|---|---|
code | String |
Spawnpoint code to match against |
threshold | Number |
Number of occurrences required to trigger callback. |
options | Object |
Extra limit options |
[options.time] | Object |
When set, number of milliseconds that the threshold cools down. On each tick this will reduce bv one until it reaches zero. |
callback | Callback |
Triggered when threshold is met. |
Console.log wrapper that only triggers with when config.debug
is enabled.
Kind: instance method of spawnpoint
Params: *
[args..] Arguments to be passed to logging.
Console.log wrapper that adds an INFO tag and timestamp to the log.
Kind: instance method of spawnpoint
Params: String|Object|Array|Number
[args..] Arguments to be passed to logging.
Console.log wrapper that adds an LOG tag and timestamp to the log.
Kind: instance method of spawnpoint
Params: String|Object|Array|Number
[args..] Arguments to be passed to logging.
Console.error` wrapper that adds an WARN tag and timestamp to the log. This prints to STDERR.
Kind: instance method of spawnpoint
Params: String|Object|Array|Number
[args..] Arguments to be passed to logging.
Console.error` wrapper that adds an ERROR tag and timestamp to the log. This prints to STDERR.
Kind: instance method of spawnpoint
Params: String|Object|Array|Number
[args..] Arguments to be passed to logging.
Registers multiple custom Errors to a specific errorCode. This helps wrap errors into a singular errorCode system.
Kind: instance method of spawnpoint
Param | Type | Description |
---|---|---|
code | String |
The errorCode human readable Spawnpoint code. |
error | Error |
Instance of the error to map to.. |
Registers multiple custom Errors to a specific errorCode, using the registerError
method.
Kind: instance method of spawnpoint
Param | Type | Description |
---|---|---|
errors | Object |
Errors being registered. Each index/key is the errorCode string that the custom Error represents. The Value must be an uninitialized instance of the error. |
Checks for Spawnpoint wrapped code, errorCode, or failCode when a potential error map is found (and previously registered). This method is useful as middleware to your application error handling so that you don't have to have the server reply with a generic error.
Kind: instance method of spawnpoint
Returns: errorCode
| false
- Returns Spawnpoint mapped code, errorCode, or failCode or false when no mapped error was found.
Param | Type | Description |
---|---|---|
error | Error |
Error to check for mapped error. |
Initializes framework to read the configFile
, init config, Spawnpoint plugins, errorCodes and autoload
folders. This also starts the application life-cycle so the app can stop gracefully.
Kind: global typedef