0.5.5 added yaml file load of options
parent
da75d1a468
commit
599b3242ea
36
.eslintrc.js
36
.eslintrc.js
|
@ -1,36 +0,0 @@
|
||||||
module.exports = {
|
|
||||||
"ecmaFeatures": {
|
|
||||||
"modules": true,
|
|
||||||
"spread" : true,
|
|
||||||
"restParams" : true
|
|
||||||
},
|
|
||||||
"env": {
|
|
||||||
"es6": true,
|
|
||||||
"node": true,
|
|
||||||
"mocha": true
|
|
||||||
},
|
|
||||||
"parserOptions": {
|
|
||||||
"ecmaVersion": 2017,
|
|
||||||
"sourceType": "module",
|
|
||||||
"ecmaFeatures": {
|
|
||||||
"experimentalObjectRestSpread": true
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"extends": "eslint:recommended",
|
|
||||||
"rules": {
|
|
||||||
"indent": [
|
|
||||||
"error",
|
|
||||||
2
|
|
||||||
],
|
|
||||||
"no-console": 0,
|
|
||||||
"semi": ["error", "never"],
|
|
||||||
"linebreak-style": [
|
|
||||||
"error",
|
|
||||||
"unix"
|
|
||||||
],
|
|
||||||
"quotes": [
|
|
||||||
"error",
|
|
||||||
"single"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -7,3 +7,5 @@ examples/
|
||||||
.eslintrc.js
|
.eslintrc.js
|
||||||
.travis.yml
|
.travis.yml
|
||||||
.yalc
|
.yalc
|
||||||
|
doc/
|
||||||
|
docs/
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "@uci/base",
|
"name": "@uci/base",
|
||||||
"version": "0.5.4",
|
"version": "0.5.5",
|
||||||
"description": "Multi type and transport JSON packet communication base class. Used in UCI extended classes",
|
"description": "Multi type and transport JSON packet communication base class. Used in UCI extended classes",
|
||||||
"main": "src/base",
|
"main": "src/base",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
@ -51,6 +51,7 @@
|
||||||
"@uci/websocket": "^0.4.1",
|
"@uci/websocket": "^0.4.1",
|
||||||
"await-to-js": "^2.1.1",
|
"await-to-js": "^2.1.1",
|
||||||
"is-plain-object": "^4.1.1",
|
"is-plain-object": "^4.1.1",
|
||||||
|
"load-yaml-file": "^0.2.0",
|
||||||
"merge-anything": "^3.0.5"
|
"merge-anything": "^3.0.5"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
25
src/base.js
25
src/base.js
|
@ -1,3 +1,9 @@
|
||||||
|
/**
|
||||||
|
* UCI Base Module
|
||||||
|
* @module UCI-Base
|
||||||
|
* @description This is the primary module to use in the UCI ecosystem
|
||||||
|
*/
|
||||||
|
|
||||||
// TODO add automated duplex (for consumer will create corresponding socket and send connection info to remote socket)
|
// TODO add automated duplex (for consumer will create corresponding socket and send connection info to remote socket)
|
||||||
|
|
||||||
// --------------- UCI dependencies -------------------
|
// --------------- UCI dependencies -------------------
|
||||||
|
@ -18,6 +24,7 @@ let log = {} // declare module wide log to be set during construction
|
||||||
// Community dependencies
|
// Community dependencies
|
||||||
import to from 'await-to-js'
|
import to from 'await-to-js'
|
||||||
import isPlainObject from 'is-plain-object'
|
import isPlainObject from 'is-plain-object'
|
||||||
|
import loadYaml from 'load-yaml-file'
|
||||||
import { merge } from 'merge-anything'
|
import { merge } from 'merge-anything'
|
||||||
// Nodejs dependencies
|
// Nodejs dependencies
|
||||||
import EventEmitter from 'events'
|
import EventEmitter from 'events'
|
||||||
|
@ -44,12 +51,12 @@ const TRANSLATE = {
|
||||||
* The class itself is extended from the {@link https://nodejs.org/api/events.html#events_class_eventemitter nodejs EventEmitter } to support in process communication as well
|
* The class itself is extended from the {@link https://nodejs.org/api/events.html#events_class_eventemitter nodejs EventEmitter } to support in process communication as well
|
||||||
*
|
*
|
||||||
* @extends EventEmitter
|
* @extends EventEmitter
|
||||||
* @param {Object} opts hash of options
|
* @param options {object} - object hash of options
|
||||||
* @param {String} [opts.id='ucit-base'+timestamp] and id for this process/instance used for logging, default: uci-base + timestamp
|
* @param [options.id=ucit-base+<timestamp>] {string} and id for this process/instance used for logging
|
||||||
* @param {String} [opts.desc] additional description for humans, can be logged.
|
* @param {String} [options.desc] additional description for humans, can be logged.
|
||||||
* @param {String | Boolean} [opts.path=either full path to where socket should be created or 'true' (which uses default path]
|
* @param {String | Boolean} [opts.path=either full path to where socket should be created or 'true' (which uses default path]
|
||||||
* @param {string} [opts.sockets] comma delimited strong of sockets to be created each socket of the form [name]#[c or s]>[n,t,m or w]
|
* @param {string} [opts.sockets] comma delimited strong of sockets to be created each socket of the form [name]#[c or s]>[n,t,m or w]
|
||||||
* @param {Boolean} [opts.useRootNS=false] include the "root" of the created base instance as part of the namespace for which packet cmd's try to call corresponding function
|
* @param [opts.useRootNS=false] {boolean} - include the "root" of the created base instance as part of the namespace for a packet cmd - use not recommended
|
||||||
* @param {Object} [opts.(name of socket)] options for a particular socket created by opts.socket. see UCI guide {@link ?content=guide#sockets|creating sockets}
|
* @param {Object} [opts.(name of socket)] options for a particular socket created by opts.socket. see UCI guide {@link ?content=guide#sockets|creating sockets}
|
||||||
* @property {array} socket collection of all sockets created and used by base instance as per opts.sockets or addSocket method
|
* @property {array} socket collection of all sockets created and used by base instance as per opts.sockets or addSocket method
|
||||||
*
|
*
|
||||||
|
@ -61,7 +68,8 @@ const TRANSLATE = {
|
||||||
* let mybaseprocess = new Base(opts)
|
* let mybaseprocess = new Base(opts)
|
||||||
*/
|
*/
|
||||||
class Base extends EventEmitter {
|
class Base extends EventEmitter {
|
||||||
constructor(opts = {}) {
|
constructor(opts={}) {
|
||||||
|
if (typeof opts === 'string') opts=loadYaml.sync(opts)
|
||||||
super()
|
super()
|
||||||
this.name = opts.name || opts.appName || 'a base class instance'
|
this.name = opts.name || opts.appName || 'a base class instance'
|
||||||
this.id = opts.id || 'uci-base:' + new Date().getTime()
|
this.id = opts.id || 'uci-base:' + new Date().getTime()
|
||||||
|
@ -69,6 +77,7 @@ class Base extends EventEmitter {
|
||||||
this.desc = opts.desc // additional details for humans
|
this.desc = opts.desc // additional details for humans
|
||||||
this._socket = {} // holds all the various communication sockets
|
this._socket = {} // holds all the various communication sockets
|
||||||
// these two if passed will get applied to all consumer sockets, otherwise socket defaults will be used
|
// these two if passed will get applied to all consumer sockets, otherwise socket defaults will be used
|
||||||
|
/** @type {string} - timeout for connecting to a consumer socket */
|
||||||
this.initTimeout = opts.initTimeout
|
this.initTimeout = opts.initTimeout
|
||||||
this.retryWait = opts.retryWait
|
this.retryWait = opts.retryWait
|
||||||
this.defaultReturnCmd = opts.defaultReturnCmd
|
this.defaultReturnCmd = opts.defaultReturnCmd
|
||||||
|
@ -111,14 +120,14 @@ class Base extends EventEmitter {
|
||||||
// PUBLIC METHODS
|
// PUBLIC METHODS
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* initialize the instance with the set options. This must be called to initialize all sockets and connections
|
* initialize the instance with the set options.
|
||||||
|
* This must be called to initialize all sockets and connections
|
||||||
* @async
|
* @async
|
||||||
* @public
|
* @public
|
||||||
* @required
|
* @required
|
||||||
* @param {array} sockets string of one or array array names to initialize, if none, then all current added sockets will be initialized
|
* @param {array} sockets string of one or array array names to initialize, if none, then all current added sockets will be initialized
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
async init(sockets) {
|
async init(sockets) {
|
||||||
// TODO ready needs to allow multiple all subscribers that get rebuilt on add/remove
|
// TODO ready needs to allow multiple all subscribers that get rebuilt on add/remove
|
||||||
const res = await this.socketsInit(sockets)
|
const res = await this.socketsInit(sockets)
|
||||||
|
@ -723,4 +732,4 @@ class Base extends EventEmitter {
|
||||||
} // end Base Class
|
} // end Base Class
|
||||||
|
|
||||||
export default Base
|
export default Base
|
||||||
export { Base, map, changed, isPlainObject, to, merge } // todo share rxjs
|
export { Base, map, changed, isPlainObject, to, merge, loadYaml } // todo share rxjs
|
||||||
|
|
Loading…
Reference in New Issue