Skip to content

Commit

Permalink
linter changes
Browse files Browse the repository at this point in the history
  • Loading branch information
axbuglak committed Dec 6, 2023
1 parent 85a6939 commit b07c96c
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 14 deletions.
4 changes: 2 additions & 2 deletions JavaScript/c-commonjs/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ const pg = require('pg');

let pool = null;

const init = options => {
const init = (options) => {
pool = new pg.Pool(options);
};

const crud = table => ({
const crud = (table) => ({
async query(sql, args) {
const result = await pool.query(sql, args);
return result.rows;
Expand Down
2 changes: 1 addition & 1 deletion JavaScript/c-commonjs/static.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ module.exports = (root, port, console) => {
}).listen(port);

console.log(`Static on port ${port}`);
};
};
16 changes: 8 additions & 8 deletions JavaScript/c-commonjs/static/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const transport = {};

transport.http = url => structure => {
transport.http = (url) => (structure) => {
const api = {};
const services = Object.keys(structure);
for (const name of services) {
Expand All @@ -15,7 +15,7 @@ transport.http = url => structure => {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ args }),
}).then(res => {
}).then((res) => {
if (res.status === 200) resolve(res.json());
else reject(new Error(`Status Code: ${res.status}`));
});
Expand All @@ -25,7 +25,7 @@ transport.http = url => structure => {
return Promise.resolve(api);
};

transport.ws = url => structure => {
transport.ws = (url) => (structure) => {
const socket = new WebSocket(url);
const api = {};
const services = Object.keys(structure);
Expand All @@ -34,22 +34,22 @@ transport.ws = url => structure => {
const service = structure[name];
const methods = Object.keys(service);
for (const method of methods) {
api[name][method] = (...args) => new Promise(resolve => {
api[name][method] = (...args) => new Promise((resolve) => {
const packet = { name, method, args };
socket.send(JSON.stringify(packet));
socket.onmessage = event => {
socket.onmessage = (event) => {
const data = JSON.parse(event.data);
resolve(data);
};
});
}
}
return new Promise(resolve => {
return new Promise((resolve) => {
socket.addEventListener('open', () => resolve(api));
});
};

const scaffold = url => {
const scaffold = (url) => {
const protocol = url.startsWith('ws:') ? 'ws' : 'http';
return transport[protocol](url);
};
Expand All @@ -73,5 +73,5 @@ const scaffold = url => {
}
});
const data = await api.talks.say('hello');
console.dir({ data });
console.log({ data });
})();
2 changes: 1 addition & 1 deletion JavaScript/c-commonjs/transport/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const HEADERS = {
'Content-Type': 'application/json; charset=UTF-8',
};

const receiveArgs = async req => {
const receiveArgs = async (req) => {
const buffers = [];
for await (const chunk of req) buffers.push(chunk);
const data = Buffer.concat(buffers).toString();
Expand Down
6 changes: 4 additions & 2 deletions JavaScript/c-commonjs/transport/ws.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module.exports = (routing, port, console) => {

ws.on('connection', (connection, req) => {
const ip = req.socket.remoteAddress;
connection.on('message', async message => {
connection.on('message', async (message) => {
const obj = JSON.parse(message);
const { name, method, args = [] } = obj;
const entity = routing[name];
Expand All @@ -25,7 +25,9 @@ module.exports = (routing, port, console) => {
console.log(`${ip} ${name}.${method}(${parameters})`);
try {
const result = await handler(...args);
connection.send(JSON.stringify(result.rows ? result.rows : result), { binary: false });
connection.send(
JSON.stringify(result.rows ? result.rows : result), { binary: false }
);
} catch (err) {
console.error(err);
connection.send('"Server error"', { binary: false });
Expand Down

0 comments on commit b07c96c

Please sign in to comment.