IrisJS

Namespace: iris

iris

Utility functions and Iris system calls

Source:

Methods

(static) deleteConfig(directory, filename, callback)

Deletes a saved JSON config file

Additionally, the saved configStore for the file will be deleted

Parameters:
Name Type Description
directory string

The directory, under "/configurations", in which the file is stored

filename string

The name of the file

callback string

The callback to run once completed

Source:
Returns:

Runs callback with 'err' boolean (false if operation successful)

(static) error()

Error helper function

Converts parameters code, message and notes into a keyed object.

Source:

(static) hook(hookname, authPass, staticVariables, variables)

Invokes a hook.

All implementations of this hook, across all modules, will be run in order.

The 'variables' object is passed between each hook and is mutable - it can be assigned different values by each hook. The other parameters are kept static. 'Variables' are what is returned once the hook is complete.

Parameters:
Name Type Description
hookname string

The unique name of the hook to run

authPass object

The authPass object, which includes permissions information about the current user. Use string "root" to run with all permissions.

staticVariables object

Variables provided to the hook implementations which should not be mutable

variables object

Variables provided to the hook implementations which are mutable

Source:
Returns:

a promise which, if successful, contains the final hook variables as its first argument

(static) include(defaultLocation, customLocation)

Attempt to load a file from a given location or fall back to a default location.

Parameters:
Name Type Description
defaultLocation string

Fallback location of file

customLocation string

Preferred custom location of file

Source:
Returns:

the file as a module, as the output of require()

(static) log()

Logs an event.

Call server message logging function and hook log.

Source:

(static) promise()

Run given callback as a promise.

Pretty prints any errors that occur inside the callback.

Source:
Returns:

a promise that runs the specified callback

(static) promiseChain(tasks, parameters, success, fail)

Run a series of promises in sequence.

If any promise fails, the chain is stopped and the failure callback is run.

Parameters:
Name Type Description
tasks Array.<promise>

array of promises to be resolved

parameters

arguments to pass to each promise

success

success callback to run if all promises are successful

fail

failure callback to run if any promise is unsuccessful

Source:

(static) readConfig(directory, filename)

Reads a stored JSON configuration file

Will attempt to read from the configStore cache.

Parameters:
Name Type Description
directory string

The directory, under "/configurations", in which the file is stored

filename string

The name of the file

Source:
Returns:

A promise which, if successful, has the config file as a JavaScript object as its first argument

(static) registerModule(name, directoryopt)

Register a module to make its hooks and handlers active.

Parameters:
Name Type Attributes Description
name string

The name of the module; this should match the filename

directory boolean <optional>

Flag for whether a config directory should be created for this module.

Source:
Returns:

the internal module object that was created, if succesful.

(static) registerTranslation()

Register a translation to be used by the translate function

Source:

(static) sanitizeName(name)

Sanitize file name

Replaces all non alphanumeric characters with '-'. This is a problem with non-Latin scripts.

Parameters:
Name Type Description
name string

string to convert into a sanitized filename

Source:
Returns:

a sanitized string ready for use as a filename

(static) saveConfig(contents, directory, filename, callback)

Saves a JavaScript object as a JSON configuration file.

Additionally, adds the config to the configStore in memory.

Parameters:
Name Type Description
contents object

The object (of key-value pairs) to be saved

directory string

The directory, under "/configurations", in which to store the file

filename string

The name of the file

callback function

The callback to run once the file has been saved

Source:
Returns:

Runs callback with 'err' boolean (false if operation successful)

(static) sendSocketMessage(userids, message, data)

Sends a socket message to any specified users

Parameters:
Name Type Description
userids Array.<string>

Array of userids. If it contains '*', the message is sent to all users.

message string

Socket event name on which the message will be sent.

data

Any variable to be sent as a message.

Source:

(static) socketLogin(userid, token, socket)

Authentication of a user via sockets

Parameters:
Name Type Description
userid string

The userid of the authenticating user.

token string

The session token that the authenticating user should possess.

socket object

The socket object being used for the request.

Source:

(static) translate(translationString, args)

Translate a string

If a translation for the given string has been registered, the input string will be replaced with that one.

Parameters:
Name Type Description
translationString string

string that should be translated

args

util.format arguments to replace inside string

Source:
Returns:

Translated string with arguments processed by util.format

(static) typeCheck(allowed, entity, data#)

Field data type check

Parameters:
Name Type Description
allowed object

object containing key-value pairs of the field name and its allowed type

entity object

the entity to check

data# object
Source:
Returns:

an object with parameter 'valid' as a boolean; if invalid, an array of invalidFields is also provided