0.5.5 added yaml file load of options

master
Kebler Network System Administrator 2021-03-11 16:24:56 -08:00
parent da75d1a468
commit 599b3242ea
4 changed files with 21 additions and 45 deletions

View File

@ -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"
]
}
}

View File

@ -7,3 +7,5 @@ examples/
.eslintrc.js
.travis.yml
.yalc
doc/
docs/

View File

@ -1,6 +1,6 @@
{
"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",
"main": "src/base",
"scripts": {
@ -51,6 +51,7 @@
"@uci/websocket": "^0.4.1",
"await-to-js": "^2.1.1",
"is-plain-object": "^4.1.1",
"load-yaml-file": "^0.2.0",
"merge-anything": "^3.0.5"
}
}

View File

@ -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)
// --------------- UCI dependencies -------------------
@ -18,6 +24,7 @@ let log = {} // declare module wide log to be set during construction
// Community dependencies
import to from 'await-to-js'
import isPlainObject from 'is-plain-object'
import loadYaml from 'load-yaml-file'
import { merge } from 'merge-anything'
// Nodejs dependencies
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
*
* @extends EventEmitter
* @param {Object} opts hash of options
* @param {String} [opts.id='ucit-base'+timestamp] and id for this process/instance used for logging, default: uci-base + timestamp
* @param {String} [opts.desc] additional description for humans, can be logged.
* @param options {object} - object hash of options
* @param [options.id=ucit-base+<timestamp>] {string} and id for this process/instance used for logging
* @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} [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}
* @property {array} socket collection of all sockets created and used by base instance as per opts.sockets or addSocket method
*
@ -62,6 +69,7 @@ const TRANSLATE = {
*/
class Base extends EventEmitter {
constructor(opts={}) {
if (typeof opts === 'string') opts=loadYaml.sync(opts)
super()
this.name = opts.name || opts.appName || 'a base class instance'
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._socket = {} // holds all the various communication sockets
// 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.retryWait = opts.retryWait
this.defaultReturnCmd = opts.defaultReturnCmd
@ -111,14 +120,14 @@ class Base extends EventEmitter {
// 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
* @public
* @required
* @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) {
// TODO ready needs to allow multiple all subscribers that get rebuilt on add/remove
const res = await this.socketsInit(sockets)
@ -723,4 +732,4 @@ class Base extends EventEmitter {
} // end Base Class
export default Base
export { Base, map, changed, isPlainObject, to, merge } // todo share rxjs
export { Base, map, changed, isPlainObject, to, merge, loadYaml } // todo share rxjs