1.0.2 • Published 8 years ago
space-engine-node
Licence
Apache-2.0
Version
1.0.2
Deps
2
Size
5 kB
Vulns
0
Weekly
0
Client API for Space Cloud
Installation
$ npm install space-engine-node --save
Quick Start
Create Engine Instance
const Engine = require('space-engine-node');
const engine = new Engine('my-engine');
Note: All instances with same engine name are automatically load balanced.
Register the function
engine.registerFunc('my-func', (params, auth, cb) => {
console.log('Params:', params, 'Auth', auth)
// Do something
const res = { ack: true, message: 'Function as a Service is Awesome!' }
cb('response', res)
})
Note: Enable Functions module in Space Cloud, run space-exec and nats server to be able to use it.
Classes
EngineClass representing the Engine Interface.
Functions
Callback(type, res)Callback to be called before returning from function.
EngineFunction(params, auth, cb)Callback for realtime updates to the subscribed data
Engine
Class representing the Engine Interface.
Kind: global class
new Engine(engineName, opts)
Create an instance of the Engine API.
| Param | Type | Description |
|---|---|---|
| engineName | string |
Name of the engine. |
| opts | string | Object |
Connection options for Nats. |
Example
const Engine = require('space-engine-node');
const engine = new Engine('my-engine');
// Register function with engine
engine.registerFunc('my-func', (params, auth, cb) => {
console.log('Params:', params, 'Auth', auth)
// Do something
const res = { ack: true, message: 'Function as a Service is Awesome!' }
cb('response', res)
})
engine.registerFunc(name, func)
Register the function to FaaS Engine
Kind: instance method of Engine
| Param | Type | Description |
|---|---|---|
| name | string |
Name of the function. |
| func | EngineFunction |
Function to be registered |
Callback(type, res)
Callback to be called before returning from function.
Kind: global function
| Param | Type | Description |
|---|---|---|
| type | string |
Type of callback action to be performed. |
| res | Object |
Data to be sent to client. |
EngineFunction(params, auth, cb)
Callback for realtime updates to the subscribed data
Kind: global function
| Param | Type | Description |
|---|---|---|
| params | Object |
Params received by function. |
| auth | Object |
Auth object of client. Will be undefined if request is unauthenticated. |
| cb | Callback |
The callback function to be called by the function. |