bb-service-seneca
Seneca related service tools.
Installation
npm install @kapitchi/bb-service-seneca
Usage
TODO
API
Classes
- SenecaClient
-
Seneca client
- SenecaFactory
-
Seneca factory
- SenecaServer
SenecaClient
Seneca client
Kind: global class
new SenecaClient(seneca)
Param | Type |
---|---|
seneca | Seneca |
Promise
senecaClient.act(serviceName, method, params) ⇒ Calls seneca.act() with action pattern:
- bbservice - serviceName
- bbmethod - method
Args object is merged with bbservice/bbmethod seneca pattern object.
Kind: instance method of SenecaClient
Param | Type |
---|---|
serviceName | string |
method | string |
params | Object |
SenecaFactory
Seneca factory
Kind: global class
-
SenecaFactory
-
.createProxyServices(config, senecaClient) ⇒
Object
-
.createProxyService(serviceName, senecaClient, opts) ⇒
Object
|Proxy
-
.createPlugin(obj, opts) ⇒
function
-
.createProxyServices(config, senecaClient) ⇒
Object
SenecaFactory.createProxyServices(config, senecaClient) ⇒ TODO
Kind: static method of SenecaFactory
Returns: Object
- Proxy services created
Param | Type |
---|---|
config | Object |
senecaClient | SenecaClient |
Object
| Proxy
SenecaFactory.createProxyService(serviceName, senecaClient, opts) ⇒ Creates local-like service proxying to seneca client
If used in environment where Proxy class is not available define opts.methods
parameter.
This creates plain object with methods defined instead of using Proxy.
Kind: static method of SenecaFactory
Param | Type | Description |
---|---|---|
serviceName | string |
|
senecaClient | SenecaClient |
|
opts | Object |
|
[opts.methods] | Array |
Array of methods to proxy (creates plain object instead of using Proxy) |
function
SenecaFactory.createPlugin(obj, opts) ⇒ Creates seneca plugin from the service class instance
Exposes each service method with action pattern:
- bbservice - service name
- bbmethod - method name
Kind: static method of SenecaFactory
Returns: function
- Seneca plugin
Param | Type | Description |
---|---|---|
obj | Object |
Service instance |
opts | Object |
|
opts.methods | Array |
Service methods to expose |
[opts.service] | string |
Service name (default: object's constructor name) |
[opts.pluginName] | string |
Seneca plugin name (default: service name) |
[opts.initMethod] | string |
Register service method as Seneca initialization action http://senecajs.org/docs/tutorials/how-to-write-a-plugin.html#wp-init |
[opts.logger] | Object |
Logger { log: fn } |
SenecaServer
Kind: global class
-
SenecaServer
- new SenecaServer(senecaServerOpts, senecaServerExposedServices)
-
.listen() ⇒
Promise.<void>
new SenecaServer(senecaServerOpts, senecaServerExposedServices)
Param | Type | Description |
---|---|---|
senecaServerOpts | Object |
|
senecaServerOpts.port | number |
|
senecaServerOpts.params | Object |
Seneca params |
senecaServerExposedServices | Object |
Services to expose |
Example
const server = new SenecaServer({
port: 8080
}, {
myService: {
instance: myServiceImp //service object
methods: ['firstMethod', 'otherMethod']
}
})
Promise.<void>
senecaServer.listen() ⇒ Start seneca server
Kind: instance method of SenecaServer