Skip to content

Commit

Permalink
Version 2.0.0
Browse files Browse the repository at this point in the history
### Added

- Server 'start' method.
- Default config to server module.
- HttpConnection and WsConnection factory classes.
- 'use strict' directive.
- Documentation in russian.
- Secure HTTP protocol is now supported.
- CHANGELOG.md.
- Introspection getErrors method.
- Function registerError for adding new error types for api.

### Changed

- Function getIntrospectionModule return object with 'introspection' property.
- Class ConsoleTransport not a singlton.
- HTTPConnection fix bug when global HEADERS object was modifing.
  • Loading branch information
DonVietnam authored Aug 21, 2022
2 parents 7a77180 + 5e46b93 commit 1d2cd6e
Show file tree
Hide file tree
Showing 16 changed files with 6,163 additions and 572 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.vscode
node_modules
pgdata
certs
66 changes: 66 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

<!-- ## [Unreleased] -->

## [2.0.0] - 2022-08-20

### Added

- Server 'start' method.
- Default config to server module.
- HttpConnection and WsConnection factory classes.
- 'use strict' directive.
- Documentation in russian.
- Secure HTTP protocol is now supported.
- CHANGELOG.md.
- Introspection getErrors method.
- Function registerError for adding new error types for api.

### Changed

- Function getIntrospectionModule return object with 'introspection' property.
- Class ConsoleTransport not a singlton.
- HTTPConnection fix bug when global HEADERS object was modifing.

## [1.0.2] - 2022-03-14

### Added

- Unit tests.

### Changed

- Fix bug when reading property of undefined in client.checkConnection.

## [1.0.1] - 2022-03-11

### Changed

- Descriptions for Auth module schema.

## [1.0.0] - 2022-03-11

### Added

- Initial project structure.
- User module.
- Session module.
- Security utils.
- Auth module.
- Database module.
- Server module.
- Validator service.
- HTTP and WebSocket transport.
- Logger service.
- Introspection module.

[unreleased]: https://github.com/web-soft-llc/web-soft-server/compare/v2.0.0...master
[2.0.0]: https://github.com/web-soft-llc/web-soft-server/compare/v.1.0.2...v2.0.0
[1.0.2]: https://github.com/web-soft-llc/web-soft-server/compare/v.1.0.1...v.1.0.2
[1.0.1]: https://github.com/web-soft-llc/web-soft-server/compare/v.1.0.0...v.1.0.1
[1.0.0]: https://github.com/web-soft-llc/web-soft-server/releases/tag/v.1.0.0
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# web-soft-server
# Server for web-soft projects.

Server for web-soft-projects.
[Документация на русском языке.](lang/README-RU.md)
5 changes: 4 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ services:
PGDATA: '/var/lib/postgresql/data/pgdata'
volumes:
- ./db:/docker-entrypoint-initdb.d
- .:/var/lib/postgresql/data
- pgdata:/var/lib/postgresql/data
ports:
- '5432:5432'
volumes:
pgdata:
external: true
143 changes: 143 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
import { IncomingMessage, ServerResponse } from 'http';

export function registerError(label: string, code: number, message?: string): { code: number; message: string };

export interface ServerConfig {
port?: number;
host?: string;
cors?: boolean;
serverCloseTimeout?: number;
}

export interface MethodDataSchema {
type: string;
description?: string;
required?: Array<string>;
properties?: { [property: string]: MethodDataSchema };
items?: MethodDataSchema;
additionalProperties?: boolean;
}

export interface MethodSchema {
public?: boolean;
description?: string;
params?: MethodDataSchema;
result?: MethodDataSchema;
emit?: MethodDataSchema;
roles?: Array<string>;
transport?: 'http' | 'ws';
}

export interface ServerModule {
schema: { [method: string]: MethodSchema };
Module: Class<T>;
}

export interface User {
username: string;
password: string;
role: string;
createdTime: string;
}

export interface UserRole {
role: string;
createdTime: string;
}

export interface Session {
username: string;
token: string;
createdTime: string;
}

export interface LoggerSettings {
info: boolean;
debug: boolean;
warn: boolean;
error: boolean;
fatal: boolean;
sql: boolean;
}

export interface LoggerMessage {
type: string;
message: string;
stack?: string;
}

export interface LoggerTransport {
log: (data: LoggerMessage) => void;
}

export interface ErrorMetaData {
code: number;
message: string;
internal: string;
}

export interface DatabaseData {
[key: string]: number | string | boolean;
}

export class Server {
constructor(config?: ServerConfig);
start(modules: { [name: string]: ServerModule }): void;
close(): void;
}

export class ConnectionError extends Error {
constructor(meta: ErrorMetaData, data: any);
code?: number;
data?: any;
internal?: string;
pass: boolean;
}

export declare namespace validator {
function compile(schema: MethodDataSchema): (data: any) => boolean;
}

export declare namespace userService {
function save(username: string, hashPassword: string): Promise<UserRole>;
function getByUsername(username: string): Promise<User>;
function updatePassword(username: string, password: string): Promise<UserRole>;
}

export declare namespace sessionService {
function restoreSession(request: IncomingMessage): Promise<Session>;
function startSession(request: IncomingMessage, response: ServerResponse, username: string): Promise<Session>;
function endSession(request: IncomingMessage, response: ServerResponse): Promise<Session>;
}

export declare namespace logger {
function setSettings(settings: LoggerSettings): void;
function setTransport(transport: LoggerTransport): void;
function info(...data: any[]): void;
function debug(...data: any[]): void;
function warn(...data: any[]): void;
function sql(...data: any[]): void;
function error(error: Error): void;
function fatal(error: Error): void;
}

export declare namespace database {
function query(text: string, params: Array<any>): Promise<any[]>;
function insert(table: string, data: DatabaseData, returning: Array<string>): Promise<any>;
function select(
table: string,
fields: Array<string>,
conditions: DatabaseData,
orderFields: Array<string>,
itemsOnPage: number,
page: number
): Promise<any[]>;
function update(
table: string,
delta: DatabaseData,
conditions: DatabaseData,
returning: Array<string>
): Promise<any[]>;
function _delete(table: string, conditions: DatabaseData, returning: Array<string>): Promise<any[]>;
export { _delete as delete, query, insert, select, update };
}
5 changes: 2 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
const { Server } = require('./lib/server');
const AuthModule = require('./lib/auth-module');
const { consoleTransport } = require('./lib/console-transport');
const { database } = require('./lib/db');
const { ERRORS, ConnectionError } = require('./lib/error');
const { ERRORS, ConnectionError, registerError } = require('./lib/error');
const { logger } = require('./lib/logger');
const { sessionService } = require('./lib/session');
const { userService } = require('./lib/user');
const { validator } = require('./lib/validator');

module.exports.AuthModule = AuthModule;
module.exports.consoleTransport = consoleTransport;
module.exports.database = database;
module.exports.ERRORS = ERRORS;
module.exports.ConnectionError = ConnectionError;
module.exports.registerError = registerError;
module.exports.logger = logger;
module.exports.sessionService = sessionService;
module.exports.userService = userService;
Expand Down
Loading

0 comments on commit 1d2cd6e

Please sign in to comment.