-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add: exports main components from package.
- Loading branch information
DanilSord
committed
Mar 11, 2022
1 parent
70d9ead
commit ccdb9c2
Showing
1 changed file
with
18 additions
and
172 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |