Comparing version 1.1.10 to 1.1.11
@@ -17,9 +17,13 @@ //Translate JSON action objects to SQL and execute them in the backend DB | ||
module.exports = class Handler { | ||
constructor({db, control, actions, dispatch, expApp, log}) { | ||
constructor({db, control, actions, dispatch, dConfig, log}) { | ||
this.db = db | ||
this.control = control | ||
this.actions = actions | ||
this.dispatch = dispatch | ||
this.expApp = expApp | ||
this.dConfig = dConfig | ||
this.log = log || require('./log') | ||
LangCache.request((language, view, cb) => { //If a report needs language data | ||
this.log.debug('Lang cache view request:', language, view) | ||
this.handle({id:'internal', action: 'lang', language, view}, cb) | ||
}) | ||
} | ||
@@ -49,3 +53,3 @@ | ||
, lc = LangCache.view(language, view) | ||
if (lc) { //If we have this language data in our cache already | ||
if (lc) { //Return cached language data if we have it | ||
msg.data = lc //;this.log.debug('LH:', view, msg.language, lc) | ||
@@ -86,4 +90,4 @@ sender(msg) | ||
default: | ||
if (!this.control && this.dispatch) //If some other action was specified | ||
this.control = new this.dispatch(this.expApp, this.db, this.actions, this.log) //Start a controller just in time | ||
if (!this.control && this.dispatch) //If some other action was specified | ||
this.control = new this.dispatch(this.dConfig) //Start a controller just in time | ||
if (this.control && this.control.handle && this.control.handle(msg, sender)) return //And try to handle this packet | ||
@@ -90,0 +94,0 @@ result.error = this.error('Unhandled: ' + action, 'badAction') //Requested action not recognized |
@@ -10,5 +10,10 @@ //Maintain a cache of language data on various views to avoid duplicate queries | ||
var log = require('./log') //Fixme: not using passed-in logging | ||
var requestCB | ||
//Singleton instance watches language queries for all connections | ||
module.exports = { | ||
request: function(cb) { //Register a routine that can refresh view data | ||
requestCB = cb | ||
}, | ||
checkLanguage: function(language) { //Make sure there is at least an empty object for this language | ||
@@ -20,25 +25,39 @@ if (langCache[language] === undefined) | ||
refresh: function(language, view, data) { //Store this language data | ||
view: function(language, view) { //Return data for this view or undefined if not cached | ||
//log.debug("LC view:", language, view) | ||
let lc = this.checkLanguage(language) | ||
return lc[view] | ||
}, | ||
refresh: function(language, view, data) { //Store this view's language data | ||
let lc = this.checkLanguage(language) | ||
lc[view] = data | ||
//log.debug("LC Refresh:", view, data) | ||
//log.debug("LC Refresh:", language, view, data) | ||
}, | ||
view: function(language, view) { //Return all language data for this view | ||
viewData: function(language, view, cb) { //Return language data for a view | ||
//log.debug("LC checkView:", language, view) | ||
let lc = this.checkLanguage(language) | ||
//log.debug("LC view:", language, view) | ||
return lc[view] | ||
, finder = code => { //Routine for returning a message object from its code | ||
let lv = lc[view] | ||
, message = lv?.messages?.find(el => (el.code == code)) | ||
return message ?? {} | ||
} | ||
if (lc[view] === undefined && requestCB) { | ||
requestCB(language, view, () => cb(lc[view], finder)) //Call back with data when available | ||
} | ||
cb (lc[view], finder) | ||
}, | ||
messages: function(language, view) { //Return just messages for this view | ||
let lc = this.checkLanguage(language) | ||
return lc[view]?.messages ?? [] | ||
}, | ||
// messages: function(language, view) { //Return just messages for this view | ||
// let lv = this.checkView(language, view) | ||
// return lv?.messages ?? [] | ||
// }, | ||
message: function(language, view, code) { //Return a single message object for this view | ||
// message: function(language, view, code) { //Return a single message object for this view | ||
//log.debug("LC message:", language, view, code) | ||
let lc = this.checkLanguage(language) | ||
, m = lc[view]?.messages?.find(el => (el.code == code)) | ||
return m ?? {} | ||
} | ||
// let lv = this.checkView(language, view) | ||
// , m = lv?.messages?.find(el => (el.code == code)) | ||
// return m ?? {} | ||
// } | ||
} |
@@ -22,8 +22,9 @@ //Manage the connection between a User Interface and the backend database | ||
let { websock, sock, actions, dispatch, expApp } = sockConf | ||
, { credentials, delta } = websock | ||
, wsport = websock.port | ||
, { credentials } = websock | ||
, wsport = parseInt(websock.port) | ||
this.server = credentials ? Https.createServer(credentials) : Http.createServer() //websocket rides on this server | ||
this.log = dbConf.log || sockConf.log || adminConf.log || require('./log') //Try to find a logger | ||
this.log = dbConf.log ?? sockConf.log ?? adminConf.log ?? require('./log') //Try to find a logger | ||
this.adminDB = new DbClient(adminConf) //Open Admin connection to the DB | ||
this.maxDelta = delta || 60000 | ||
this.maxDelta = websock.delta ?? 60000 | ||
this.uiPort = websock.uiPort ?? (wsport - 1) | ||
if (!Subtle) { | ||
@@ -54,4 +55,5 @@ this.log.error("Can't find webcrypt.subtle library") | ||
let payload = req.WysemanPayload | ||
, config = Object.assign({}, dbConf, payload) //user,listen was passed to us from verifyClient | ||
this.log.verbose("WS Connected; User:", config.user, config) | ||
, { user, listen, origin } = payload | ||
, config = Object.assign({}, dbConf, {user, listen}) //user,listen was passed to us from verifyClient | ||
this.log.verbose("WS Connected; User:", config.user, config, ws) | ||
if (!config.user) return //Shouldn't be able to get here without a username | ||
@@ -65,3 +67,6 @@ let db = new DbClient(config, (channel, message, mine) => { | ||
}) | ||
, handler = new Handler({db, control:null, actions, dispatch, expApp, log:this.log}) | ||
, handler = new Handler({ | ||
db, control: null, log:this.log, | ||
dispatch, dConfig: {db, expApp, actions, origin, log: this.log} | ||
}) | ||
this.log.trace("Wyseman connection conf:", "Client WS port:", wsport) | ||
@@ -146,3 +151,6 @@ | ||
, listen = db ? JSON.parse(Buffer.from(db,'base64').toString()) : null | ||
, payload = req.WysemanPayload = {} //Custom Wyseman data to pass back to connection | ||
, orgUrl = Url.parse(origin ?? req.headers.host) | ||
, payload = req.WysemanPayload = { //Custom Wyseman data to pass back to connection | ||
origin: `${orgUrl.protocol}//${orgUrl.hostname}:${this.uiPort}` | ||
} | ||
@@ -149,0 +157,0 @@ this.log.trace("Checking client:", origin, "cb:", !!cb, "q:", query, "s:", secure, "IP:", req.connection.remoteAddress, "pub:", pub) |
{ | ||
"name": "wyseman", | ||
"version": "1.1.10", | ||
"version": "1.1.11", | ||
"description": "PostgreSQL Schema Manager with Javascript, Ruby, TCL API", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
529389
2882