From ccafb6a5f61e1ddc94a98ae015c3aba02cde9f79 Mon Sep 17 00:00:00 2001 From: Elin Angelow Date: Fri, 5 Apr 2024 15:17:36 +0300 Subject: [PATCH] fix: rm unnedded calls, wss tidy --- lib/loader.js | 7 +++---- lib/logger.js | 6 ++---- lib/sql.js | 6 ++---- lib/wss.js | 18 ++++++++---------- 4 files changed, 15 insertions(+), 22 deletions(-) diff --git a/lib/loader.js b/lib/loader.js index 5ae382c..36d470f 100644 --- a/lib/loader.js +++ b/lib/loader.js @@ -46,21 +46,20 @@ module.exports = () => { .reduce((prev, curr) => { const ln = layerProps(curr, createConfig, Config); console.log(`Add Layer: ${ln.layerName} for namespace ${ln.namespace}`); - const comp = curr({ + return curr({ prev, config: ln.config, wires, list: methodsList, allMethods }); - return () => comp; }, - () => Methods({ + Methods({ wires, list: methodsList, config: layerProps(Methods, createConfig, Config).config })); - const comp = new (Component()); + const comp = new Component(); components.push(comp); return api; }, diff --git a/lib/logger.js b/lib/logger.js index 35ebd5e..c703e9c 100644 --- a/lib/logger.js +++ b/lib/logger.js @@ -14,11 +14,9 @@ log4js.configure({ const loggers = new Map(); const Logger = ({ prev, - config, - wires, - list + config }) => { - class logger extends prev({wires, list, config}) { + class logger extends prev { log(level, ...rest) { let l = loggers.get(this.namespace); if (!l) { diff --git a/lib/sql.js b/lib/sql.js index ae34231..580160c 100644 --- a/lib/sql.js +++ b/lib/sql.js @@ -4,11 +4,9 @@ const exposeMethods = require('expose-sql-methods/lib/postgres'); const Sql = ({ prev, - config, - wires, - list + config }) => { - class sql extends prev({wires, list}) { + class sql extends prev { async init() { this.log('info', 'Sql', 'Init'); await migration({ diff --git a/lib/wss.js b/lib/wss.js index efd2974..c922a86 100644 --- a/lib/wss.js +++ b/lib/wss.js @@ -33,11 +33,9 @@ const dumpingComm = (fn) => { }; const Wss = ({ prev, - config, - wires, - list + config }) => { - class wss extends prev({wires, list}) { + class wss extends prev { constructor() { super(); this.server = undefined; @@ -65,7 +63,7 @@ const Wss = ({ } async init() { this.log('info', 'Wss', 'Init'); - await this.connect(); + await this.initWssServer(); this.add({name: this.namespace + '.write', fn: async(message) => { try { if (!message.id) { @@ -266,11 +264,15 @@ const Wss = ({ this.refreshConnection(id); return this.connections.get(id)?.connection; } - async connect() { + async initWssServer() { return await (new Promise((resolve, reject) => { this.server = new WebSocketServer({ port: config.port }); + this.server.on('error', (error) => { + this.log('error', 'Wss', error); + reject(error); + }); this.server.on('connection', async(wsClient, req) => { const connectionId = uuidv4(); try { @@ -296,10 +298,6 @@ const Wss = ({ wsClient.close(); } }); - this.server.on('error', (error) => { - this.log('error', 'Wss', error); - reject(error); - }); this.server.on('listening', () => { this.log('info', 'Wss', 'Listening', this.server.address()); resolve();