Class: DocloopCore

docloop DocloopCore

The Docloop core system. An instance of this class is used to setup the application and will also be passed to all adapters as core.

All events emitted by the adapters will be enhanced and reemmited on the core. See DocloopCore#relayEvent.


new DocloopCore(config)

Parameters:
Name Type Description
config Object
Properties
Name Type Argument Default Description
name String <optional>
Docloop

Readable name for frontend output or to distinguish different instances of docloop.

port Number

The port the app will respond to.

home String <optional>

Project website

clientUrl String <optional>
/

The url of the client. Some adapters will need this to redirect the user back to the client after some extenal authentication.

sessionSecret: String

Your session secret, used in express session config.

db Object

Database configuration

Properties
Name Type Argument Description
address String

mongo-db address

name String

mongo-db name

port String

mongo-db port

user String <optional>

mongo-db username

pass String <optional>

mongo-db password

Properties:
Name Type Description
app ExpressApp

The express app

adapters Object

Hash map of all used adapters. Adapters' ids are used as keys.

sourceAdapters Array.<Adapter>

Array of all used source adapters

targetAdapters Array.<Adapter>

Array of all used target adapters

ready Promise

Resolves when this instance is fully set up

preventRelayEventNames Array.<String>

Events that should not be relayed

Fires:

Members


Route:
MethodPath
GET /links/:id

Calls DocloopCore#handleGetLinkRequest.

Route Parameters:
Name Type Description
id String Link id

Methods


Get a strored link.

Parameters:
Name Type Description
mongo-db string | bson

id

Throws:
  • If id cannot be converted to ObjectId.

    Type
    TypeError
  • If no link was found matching the id.

    Type
    DocloopError | 404
  • If the stored link's source skeleton is missing or incomplete.

    Type
    DocloopError
  • If the stored link's target skeleton is missing or incomplete.

    Type
    DocloopError
  • If there is no registered adapter to match the source adapter.

    Type
    DocloopError
  • If there is no registered adapter to match the target adapter.

    Type
    DocloopError
  • If the source or target cannot be read from the respective collections.

    Type
    DocloopError
Returns:
Type
DocloopLink

<async, route> handleDeleteLinkRequest(req, res)

Route:
MethodPath
DELETE /link/:id

Express request handler. Removes a link.

Parameters:
Name Type Description
req Object

Express request object

Properties
Name Type Description
params Object

Request paramteres

Properties
Name Type Description
id Object

Link id

res Object

Express result object

Returns:

undefined


<async, route> handleDropSessionRequest(req, res)

Route:
MethodPath
GET /dropsession

Express request handler. Destroys the current session.

Parameters:
Name Type Description
req Object

Express request object

res Object

Express result object

Returns:

undefined


<async, route> handleGetAdaptersRequest(req, res)

Route:
MethodPath
GET /adapters

Express request handler. Get data for all adapters.

Parameters:
Name Type Description
req Object

Express request object

res Object

Express result object

Returns:

undefined


<async, route> handleGetLinkRequest(req, res)

Route:
MethodPath
GET /links/:id

Express request handler. Get data of a single link.

Parameters:
Name Type Description
req Object

Express request object

Properties
Name Type Description
param Object

Request paramters

Properties
Name Type Description
id Object

Link id

res Object

Express result object

Returns:

undefined


<async, route> handleGetLinksRequest(req, res)

Route:
MethodPath
GET /links

Express request handler. Gets data of all link accessible by the current session.

Parameters:
Name Type Description
req Object

Express request object

res Object

Express result object

Returns:

undefined


<async, route> handleGetRootRequest(req, res)

Route:
MethodPath
GET /

Express request handler. Returns basic app information.

Parameters:
Name Type Description
req Object

Express request object

res Object

Express result object

Returns:

App information

Type
AppData

<async, route> handlePostLinkRequest(req, res)

Route:
MethodPath
POST /links

Express request handler. Creates a new link out of posted source and target, validates and stores the link.

Parameters:
Name Type Description
req Object

Express request object

Properties
Name Type Description
body Object

Request body

Properties
Name Type Description
source EndpointData

Source Data

target EndpointData

Target Data

res Object

Express result object

Fires:
Throws:
  • If source or target is missing

    Type
    DocloopError | 400
  • If either source or target wont validate. See DocloopLink._validate.

    Type
    *
  • If there's already another link between the same source and target. See DocloopLink.preventDuplicate

    Type
    *
  • If link cannot be stored

    Type
    DocloopError | 500
Returns:

undefined


<async, route> handlePutLinkRequest(req, res)

Route:
MethodPath
PUT /links/:id

Express request handler. Updates an existing link. (Todo: should only update config)

Parameters:
Name Type Description
req Object

Express request object

Properties
Name Type Description
params Object

Request paramters

Properties
Name Type Description
id Object
body Object

Request body

Properties
Name Type Description
source EndpointData

Sourcet data

target EndpointData

Target data

res Object

Express result object

Fires:
Throws:

If id, source or target is missing

Type
DocloopError | 400
Returns:

undefined


Create new instance of DocLoopLink with this as core using the provided data.

Parameters:
Name Type Description
data LinkData

Configuration data for the new DocloopLink instance.

Returns:
Type
DocloopLink

<async> relayEvent(event_name, data)

Relays an event if it has a source property. For every Link with that source reemits the events on core replacing the source property with the link's target. This way one adapter can emit an event and everyother (linked) adapter can listen to it on the core.

Parameters:
Name Type Description
event_name String

The event name

data data

Event data

Throws:

If either source.id or source.adapter is missing.

Type
ReferenceError
Returns:

undefined


<async> run()

Start the App and listen to the configured port.

Returns:
Type
Promise

<async> use(AdapterClass, config)

Will instantiate AdapterClass once with this as core and the provided configuration object. The new instance will be added to the list of adapters.

Parameters:
Name Type Description
AdapterClass AdapterClass
config Object

The configuration object for the custom adapter class.

Throws:

If another adapter with the same id is already in use.

Type
DocloopError | 409
Returns:

this for chaining

Events


Type: LinkSkeleton

Type: LinkSkeleton

Type: LinkSkeleton