new DocloopCore(config)
Parameters:
Name | Type | Description | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
config |
Object |
Properties
|
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> getSingleLink
-
Route:
Method Path GET /links/:id Calls DocloopCore#handleGetLinkRequest.
Route Parameters:
Name Type Description id String Link id
Methods
-
<async> getStoredLink(mongo-db)
-
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:
Method Path 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:
Method Path 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:
Method Path 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:
Method Path 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:
Method Path 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:
Method Path 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:
Method Path 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:
Method Path 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
-
-
newLink(data)
-
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
-
link-established
-
Type: LinkSkeleton
-
link-removed
-
Type: LinkSkeleton
-
link-updated
-
Type: LinkSkeleton