Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"hokify",
"italog",
"memjs",
"Millis",
"msisdn",
"mvno",
"OLLEH",
Expand Down
147 changes: 2 additions & 145 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,151 +5,8 @@ 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).

## [2.4.0] - 2025-05-08
## [0.0.0] - 0000-00-00

### Added

- Add the `CacheRequestAdapter` wrapper of cache functionalities inside request adapter structure and interfaces.

### Changed

- Update dependencies.
- Update Node.js version in Dockerfile.
- Add type corrections to the RabbitMQ server.

### Fixed

- Correct logic to enable offline logger.

## [2.3.0] - 2025-05-06

### Added

- New `normalize` and `normalizeOptions` utilities for payload normalization in the reprocessing module.
- APM decorators for handlers, enabling instrumentation.
- Functionality to extract RabbitMQ options from the `RABBIT_OPTIONS` environment variable.

### Changed

- Renamed non-standard folder from `utils` to `util`.
- Improved application startup and shutdown process.
- Enhanced MemCached connection process and added connection timeout.
- Updated the `.env.example` file.
- Adjusted when Elastic is started.
- Added protocol adaptation for new RabbitMQ implementations.
- Improved handler processing logic to prevent subsequent handlers from executing prematurely.
- Optimized APM decorators.

### Fixed

- Added normalization before message validation in the reprocessing module.
- Optimized `searchLabels` to prevent maximum call stack overflow.

### Deprecated

- _No deprecations._

### Removed

- _No removals._

### Security

- _No security fixes.

## [2.2.0] - 2025-03-19

### Added

- Adds the `apm-transaction-id` header to the response when APM is active.
- Adds the `CONSUMER_LIST` and `WORKER_LIST` environment variables to override the hard coded worker and consumer settings
- Introduces the `AtLeastOne` global type to enhance type utility.

### Fixed

- Prevents the context from being concatenated as undefined.
- Returns an empty array if no callbacks are provided in promises.
- Establishes a connection to memcached.

### Changed

- Improves the build process by simplifying the Dockerfile.

## [2.1.3] - 2024-12-06

## Added

- Add AtLeastOne global type.

## [2.1.2] - 2024-11-26

### Fixed

- Fixing the route loading management, add a mechanism to track loading state of WebServer class.

## [2.1.1] - 2024-11-19

### Fixed

- The display URL of Agendash was being shown incorrectly in the terminal, and this version fixes that URL.

## [2.1.0] - 2024-11-05

### Added

- Add CLI support.
- Add graceful shutdown for workers.

## [2.0.0] - 2024-11-04

### Added

- Add websocket support.
- Add graceful shutdown as default.
- Change internal http/https engine.

## Changed

- Remove support for server, worker and consumer commands and their derivatives.
- Remove the application file in /src/main, now import the server from web-server.ts.

## [1.1.0] - 2024-06-03

### Added

- Add virtual host connection on RabbitMq.
- Add reject message on RabbitMq server.

## [1.0.0] - 2024-04-17

### Added

- Directory structure matching Clean Architecture layers.
- Example snippets based on SOLID principles and project patterns, as Factory and Adapter.
- HTTP Server adapter equipped with uncoupling; input and output standardization; state sharing and utils resources.
- RabbitMq Server adapter equipped with uncoupling; input and output standardization; state sharing and utils resources.
- Scheduled tasks adapter equipped with uncoupling; management through database; input and output standardization; state sharing and utils resources.
- HTTP Requests calls adapter.
- Cryptography adapter.
- Cache server integration adapter.
- Input validator adapter (available to endpoints, queues and scheduled tasks)
- Extension of Knex functionalities: noLock hint, adjustment to time zone conversions and custom select.
- Support for unit and integration tests.
- Support for running HTTP Server, message broker and scheduled tasks simultaneously.
- Native integration with APM and ElasticSearch database.
- Utils for database mapping with Knex schemas.
- Utils for ElasticSearch integration.
- Utils for date handling.
- Utils for object handling (conversion to snake_case, camelCase...).
- Utils for promise handling.
- Utils for numbers and strings handling and formatting.
- Utils for text standardization (applicable to Http responses messages, for example).
- Utils for aggregate and organize consts.
- Utils for responses standardization.
- Utils for queued messages reprocessing.
- Utils for managing shared state dependencies.
- Utils for logging (file, MongoDb and Elastic).
- Utils for dynamic injection of data on Middlewares (ExtractValues).
- Utils for dynamic management of application flow (FlowManager).
- Utils for coordinating middlewares flow, with middleware chain pattern (Flow).
- Utils for run N middlewares in concurrency (parallelizer).
- Add example.
7 changes: 7 additions & 0 deletions TEMPLATE-CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ 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).

## [2.4.0] - 2025-12-03

### Added

- Add timeouts and pool settings to the Mongoose connection.
- Add timeouts and pool settings to the Knex connection.

## [2.4.0] - 2025-05-08

### Added
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { CreateInputAndOutputLogRepositoryRepository } from '@/data/protocols/db';
import { convertCamelCaseKeysToSnakeCase } from '@/util/object';
import { logger } from '@/util';

import { InputAndOutputLogModel } from './input-and-output-log-model';

Expand All @@ -9,8 +10,14 @@ export class InputAndOutputLogRepository
public async create(
params: CreateInputAndOutputLogRepositoryRepository.Params
): CreateInputAndOutputLogRepositoryRepository.Result {
const formattedParams = convertCamelCaseKeysToSnakeCase(params);
try {
const formattedParams = convertCamelCaseKeysToSnakeCase(params);

await InputAndOutputLogModel.create(formattedParams);
await InputAndOutputLogModel.create(formattedParams, {
writeConcern: { w: 0 }
});
} catch (error) {
logger.log(error);
}
}
}
10 changes: 7 additions & 3 deletions src/infra/db/mongodb/log/log-repository.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import { CreateLogRepository } from '@/data/protocols/db';
import { convertCamelCaseKeysToSnakeCase } from '@/util';
import { convertCamelCaseKeysToSnakeCase, logger } from '@/util';

import { LogModel } from './log-model';

export class LogRepository implements CreateLogRepository {
public async create(
params: CreateLogRepository.Params
): CreateLogRepository.Result {
const formattedParams = convertCamelCaseKeysToSnakeCase(params);
await LogModel.create(formattedParams);
try {
const formattedParams = convertCamelCaseKeysToSnakeCase(params);
await LogModel.create(formattedParams, { writeConcern: { w: 0 } });
} catch (error) {
logger.log(error);
}
}
}
11 changes: 11 additions & 0 deletions src/infra/db/mssql/util/connection/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,22 @@ const configs = {
port: +DB.PORT,
user: DB.USERNAME,
password: DB.PASSWORD,
requestTimeout: DB.CONNECTION_TIMEOUT_MS,
options: {
encrypt: false,
enableArithAbort: false,
appName: pkg.name
}
},
pool: {
max: DB.MAX_POOL,
min: DB.MIN_POOL,
acquireTimeoutMillis: DB.CONNECTION_TIMEOUT_MS,
createTimeoutMillis: DB.CONNECTION_TIMEOUT_MS,
destroyTimeoutMillis: DB.CONNECTION_TIMEOUT_MS,
idleTimeoutMillis: DB.IDLE_TIMEOUT_IN_MILLISECONDS,
reapIntervalMillis: DB.REPEAT_INTERVAL_IN_MS,
createRetryIntervalMillis: DB.CREATE_RETRY_INTERVAL_IN_MS
}
},

Expand Down
18 changes: 13 additions & 5 deletions src/main/util/get-mongoose-connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,17 @@ import mongoose from 'mongoose';
import { MONGO } from '@/util';

export function getMongooseConnection() {
return mongoose.set('strictQuery', false).connect(MONGO.URL(), {
dbName: MONGO.NAME,
authSource: MONGO.AUTH_SOURCE,
authMechanism: 'SCRAM-SHA-1'
});
return mongoose
.set('strictQuery', false)
.set('bufferTimeoutMS', MONGO.CONNECTION_TIMEOUT_MS)
.connect(MONGO.URL(), {
dbName: MONGO.NAME,
authSource: MONGO.AUTH_SOURCE,
authMechanism: 'SCRAM-SHA-1',
serverSelectionTimeoutMS: MONGO.CONNECTION_TIMEOUT_MS,
socketTimeoutMS: MONGO.CONNECTION_TIMEOUT_MS,
connectTimeoutMS: MONGO.CONNECTION_TIMEOUT_MS,
maxPoolSize: MONGO.MAX_POOL_SIZE,
minPoolSize: MONGO.MIN_POOL_SIZE
});
}
14 changes: 14 additions & 0 deletions src/util/constants/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,16 @@ export const DB = {
? stringToBoolean(process.env.DB_ENABLED)
: true,
DB_TEST_CONNECTION_QUERY: process.env.DB_TEST_CONNECTION_QUERY || 'SELECT 1',
CONNECTION_TIMEOUT_MS: +(() =>
process.env.DB_CONNECTION_TIMEOUT_MS || 60000)(),
MAX_POOL: +(() => process.env.DB_MAX_POOL || 10)(),
MIN_POOL: +(() => process.env.DB_MIN_POOL || 2)(),
IDLE_TIMEOUT_IN_MILLISECONDS: +(() =>
process.env.DB_IDLE_TIMEOUT_IN_MILLISECONDS || 30000)(),
REPEAT_INTERVAL_IN_MS: +(() =>
process.env.DB_REPEAT_INTERVAL_IN_MS || 1000)(),
CREATE_RETRY_INTERVAL_IN_MS: +(() =>
process.env.DB_CREATE_RETRY_INTERVAL_IN_MS || 200)(),
CONFIG: process.env.DB_CONFIG || 'default',
DIALECT: process.env.DB_DIALECT || 'mssql',
HOST: process.env.DB_HOST || '',
Expand Down Expand Up @@ -85,6 +95,10 @@ export const MONGO = {
ENABLED: process.env.MONGO_ENABLED
? stringToBoolean(process.env.MONGO_ENABLED)
: true,
CONNECTION_TIMEOUT_MS: +(() =>
process.env.MONGO_CONNECTION_TIMEOUT_MS || 60000)(),
MAX_POOL_SIZE: +(() => process.env.MONGO_MAX_POOL_SIZE || 100)(),
MIN_POOL_SIZE: +(() => process.env.MONGO_MIN_POOL_SIZE || 1)(),
USER: process.env.MONGO_USER || '',
PASSWORD: process.env.MONGO_PASSWORD || '',
HOST: process.env.MONGO_HOST || '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ describe('InputAndOutputLog Repository', () => {
},
type: 'any_type'
};
expect(createSpy).toHaveBeenCalledWith(expected);

const writeConcern = {
w: 0
};

expect(createSpy).toHaveBeenCalledWith(expected, { writeConcern });
});
});
7 changes: 6 additions & 1 deletion test/unit/infra/db/mongodb/log/log-repository.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ describe('Log Repository', () => {
log_message: 'my_item',
type: 'any_type'
};
expect(createSpy).toHaveBeenCalledWith(expected);

const writeConcern = {
w: 0
};

expect(createSpy).toHaveBeenCalledWith(expected, { writeConcern });
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,15 @@ describe('KNEX connection config', () => {
const config = getConfig();

const values = Object.keys(config.connection);
const expectedValues = ['host', 'port', 'user', 'password', 'options'];
const expectedValues = [
'host',
'port',
'user',
'password',
'requestTimeout',
'options'
];

expect(values).toEqual(expectedValues);
expect(config.client).toBeTruthy();
});
Expand Down
Loading