Skip to content

Commit

Permalink
add: exports main components from package.
Browse files Browse the repository at this point in the history
  • Loading branch information
DanilSord committed Mar 11, 2022
1 parent 70d9ead commit ccdb9c2
Showing 1 changed file with 18 additions and 172 deletions.
190 changes: 18 additions & 172 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,174 +1,20 @@
const { Server } = require('./lib/server');
const { Auth } = require('./lib/auth');
const AuthModule = require('./lib/auth-module');
const { consoleTransport } = require('./lib/console-transport');
const { database } = require('./lib/db');
const { ERRORS, ConnectionError } = require('./lib/error');
const { logger } = require('./lib/logger');
const { sessionService } = require('./lib/session');
const { userService } = require('./lib/user');
const { validator } = require('./lib/validator');

const clients = new Set();
let counter = 0;

setInterval(async () => {
counter++;
for (const client of clients) {
try {
await client.emit('counter/getCounts', { counter });
} catch (error) {
clients.delete(client);
}
}
}, 2000);

class Counter {
getCounts(data, client) {
clients.add(client);
}
}

const modules = {
counter: {
schema: {
getCounts: {
description: 'Получение обновляемого счётчика.',
public: true,
emit: {
description: 'Объект события',
required: ['counter', 'proper'],
properties: {
counter: {
type: 'Number',
description: 'Счётчик'
},
proper: {
type: 'object',
description: 'Ещё одно свойство',
required: ['prop1'],
properties: {
prop1: {
type: 'number',
description: 'Ещё одно свойство внутри!'
}
}
}
}
}
}
},
Module: Counter
},
auth: {
schema: {
register: {
public: true,
description: 'Регистрация',
params: {
required: ['username', 'password'],
properties: {
username: {
type: 'string',
description: 'Имя пользователя'
},
password: {
type: 'string'
}
}
},
result: {
required: ['username', 'role', 'createdTime'],
properties: {
username: {
type: 'string'
},
role: {
type: 'string'
},
createdTime: {
type: 'string'
}
}
},
transport: 'http'
},
login: {
public: true,
params: {
required: ['username', 'password'],
properties: {
username: {
type: 'string'
},
password: {
type: 'string'
}
}
},
result: {
required: ['username', 'role', 'createdTime'],
properties: {
username: {
type: 'string'
},
role: {
type: 'string'
},
createdTime: {
type: 'string'
}
}
},
transport: 'http'
},
logout: {
public: false,
transport: 'http'
},
me: {
public: false,
result: {
required: ['username', 'role', 'createdTime'],
properties: {
username: {
type: 'string'
},
role: {
type: 'string'
},
createdTime: {
type: 'string'
}
}
}
},
changePassword: {
public: false,
params: {
required: ['username', 'oldPassword', 'newPassword'],
properties: {
username: {
type: 'string'
},
oldPassword: {
type: 'string'
},
newPassword: {
type: 'string'
}
}
},
result: {
required: ['username', 'role', 'createdTime'],
properties: {
username: {
type: 'string'
},
role: {
type: 'string'
},
createdTime: {
type: 'string'
}
}
}
}
},
Module: Auth
}
};

const server = new Server(modules, { port: 80, host: 'localhost', cors: false });
module.exports.AuthModule = AuthModule;
module.exports.consoleTransport = consoleTransport;
module.exports.database = database;
module.exports.ERRORS = ERRORS;
module.exports.ConnectionError = ConnectionError;
module.exports.logger = logger;
module.exports.sessionService = sessionService;
module.exports.userService = userService;
module.exports.validator = validator;
module.exports.Server = Server;

0 comments on commit ccdb9c2

Please sign in to comment.