@ti-engine/core 1.1.10 → 1.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,133 +1,155 @@
1
- # ti-engine changelog
2
-
3
- This document will contain the list of changes made to the framework. The format is based on the [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) specification.
4
-
5
- ## Version 1.1.10
6
- * fix(cache): fix redis client creation sequence. It is now created inside the constructor as intended. It still needs to be initialized explicitly using the `initialize` method.
7
-
8
- ## Version 1.1.9
9
- * feat(redis integration)!: change the way the `redis` client is initialized. Instead of happening automatically on class instantiation, it is now initialized on demand using the `initialize` method.
10
- * feat(cache): change the way the main cache instance is initialized in compliance with the new redis integration
11
- * feat(message memory cache)!: change the way the message memory cache is initialized in compliance with the new redis integration. The `initialize` method needs to be called explicitly to initialize the cache instance before it can be used.
12
- * fix(message dispatcher): fix the way the `messageExchange` is initialized in the `MessageDispatcher` class (was not returning a promise)
13
-
14
- ## Version 1.1.8
15
- * feat(auditing): change export of the singleton class in an `instance` variable for consistency and clarity
16
- * feat(message dispatcher): change export of the singleton class in an `instance` variable for consistency and clarity
17
- * feat(cache): change export of the singleton class in an `instance` variable for consistency and clarity
18
- * feat(service executor): implement service registration retry policy
19
-
20
- ## Version 1.1.7
21
- * feat(start instance): add support for the detection of `SIGBREAK` events and graceful shutdown on Windows
22
- * feat(service instance)!: prevent the initialization of multiple `ServiceInstance` within the same process
23
- * feat(message tracer)!: covert to singleton instance and add initialization method
24
- * feat(message dispatcher): initialize the message tracer on start before message exchange is enabled
25
- * fix(message tracer): optimize `recordTraceEntry` to not call set JSON command on every request
26
- * fix(gcloud integration): fix the bool conversion of the `TI_GCLOUD_ENABLED` ENV variable
27
- * fix(redis integration): update links to official commands documentation
28
-
29
- ## Version 1.1.6
30
- * feat(start instance): add fail-fast mode as default behavior on promise unhandled rejections
31
- * feat(start instance): implement functionality to derive safe default service domain name when none is provided in the configuration
32
- * feat(config): add support for new ENV variable `TI_FAIL_FAST_ON_UNHANDLED_OFF` that controls the fail-fast mode
33
- * feat(service instance): ensure instance ID naming standard is followed when creating new instances and no ID is provided in the configuration
34
- * feat(redis integration): marked command `hmset` as deprecated (according to official documentation)
35
- * feat(redis integration)!: change redis client default behavior: set to automatically resend all pending commands on connection recovery with no limit on the retry attempts. This behavior cannot be changed. Arguments `autoRetryUnfulfilled` and `maxRetries` have been removed from the constructor
36
- * feat(redis integration)!: add options to configure redis connection retry policy. This can be controlled with two new arguments in the constructor `retryMaxIntervalMs` and `retryMaxAttempts`.
37
- * feat(redis integration)!: improve and extend the behavior of pub/sub implementation functionality. The `subscribeCommand` method can now only subscribe once to the same channel. The client instance will keep a map of all channels it has subscribed to. To unsubscribe, use the `unsubscribeCommand` method
38
- * feat(redis integration): add a `shutDown` method to gracefully close a redis connection. This is now used on instance shut down sequence as well as in the default message sender and receiver implementations
39
- * fix(start instance): fix the logging of reason for unhandled rejections and multiple resolves
40
- * fix(service instance): use the static service domain name to initialize the health check instead of the ENV variable
41
- * fix(redis integration): add detection of ReJSON2 in the verification of JSON support in the redis server
42
- * build(npm): update npm dependencies to their latest versions
43
- * docs: add section about ENV variables to the `README.md` file
44
-
45
- ## Version 1.1.5
46
-
47
- * fix(service instance): add overrides of the `reportHealthy` method in `ServiceConsumer` and `ServiceProvider` classes
48
- * fix(tester): implement `reportHealthy` method
49
- * docs(license): add a `LICENSE` file
50
- * docs(license): change all licensing information in source files to GNU 3.0
51
- * docs: improve the information in `README.md` file
52
-
53
- ## Version 1.1.4
54
-
55
- * feat(service instance): expose method `reportHealthy` and mark it as virtual to allow for overrides with custom health status reporting logic
56
-
57
- ## Version 1.1.3
58
-
59
- * feat(config)!: removed ENV variable `TI_OPERATION_MODE` as it was duplicating the practical purpose of `NODE_ENV`
60
- * feat(config)!: setting `OPERATION_MODE` is now initialized by the `NODE_ENV` ENV variable (if provided)
61
- * feat(service instance): show application operation mode in log at successful startup
62
- * docs: add more sections and information in `README.md`
63
-
64
- ## Version 1.1.2
65
-
66
- * feat(localization): add new functionality for localization based on labels and system language. It is currently utilized by the `exceptions` module for localizing the exception descriptions. The new `localization` module can also be accessed externally in the implementing application's files via standard import
67
- * feat(config): add new setting `localization.labelsPath` that specifies the file path for the localization labels
68
- * feat(config): add new setting `localization.language` that specifies the language to be used for the labels
69
- * feat(config): add new ENV variable `TI_LOCALIZATION_LABELS_PATH` that controls the `localization.labelsPath` setting
70
- * feat(config): add new ENV variable `TI_LOCALIZATION_LANGUAGE` that controls the `localization.language` setting
71
- * feat(logger): log exception label instead of system-level description
72
- * fix(start instance): fix the order of ENV loading in the `start-instance.js` script. It will now properly load the `.env` file first and then proceed with any configuration overrides in `config` module
73
- * fix(service provider): normalize service file paths on dynamic service handler loading
74
- * build(npm): update npm dependencies to their latest versions
75
-
76
- ## Version 1.1.1
77
-
78
- * feat(config): add new ENV variable `TI_AUDITING_LOG_DETAILS` that controls the `auditing.logDetails` setting
79
- * feat(service provider): add a method that returns a list of the currently registered services
80
- * feat(tester service): improved the structure, configuration, and inline docs of tester service
81
- * fix(logger): fix the way Exception is logged when it's a part of the main logging data object
82
- * docs(readme): expanded the general documentation in `README.md` with a new section and improved many of the older sections
83
- * docs: improved some of the JSDoc definitions across the framework
84
-
85
- ## Version 1.1.0
86
-
87
- * feat(redis integration): implement better process for fetching and storing the remote Redis server settings and enabled features
88
- * feat(redis integration): add getter method `serverVersion` that returns the Redis server version
89
- * feat(redis integration): add support for RedisJSON functionality
90
- * feat(redis integration): add getter method `isJSONSupported` to verify if this module is enabled/supported in Redis server
91
- * feat(redis integration): add separate enum for override modes `TiRedisOverrideMode`
92
- * feat(redis integration): add support for executing any single command in Redis that is otherwise unsupported by the underlying framework. Use method `callCommand` for that in case you need to access something more exotic or currently unimplemented
93
- * feat(cache): add support for working with JSON values. Currently supporting operations `set`, `get`, and `append array` with more coming in future versions
94
- * feat(cache): add support for setting manual expiration of values
95
- * feat(message tracer): change log level of trace entries from `DEBUG` to `NOTICE` for all events
96
- * feat(message tracer): add functionality for storing the trace entries in the `cache` in JSON format. This is the default behavior and will always work. Traces can later be retrieved from the `cache` for further processing by specialized application
97
- * feat(message tracer): add new property `traceTimestamp` to the trace entries as it may differ from the actual message timestamp
98
- * feat(config): add new setting `messageExchange.traceExpirationTime` that controls the preservation time for all trace entries. Default is one hour and will be refreshed every time a new trace is generated. Setting this to `0` will disable
99
- expiration altogether
100
- * feat(config): add new setting `messageExchange.traceRepository` that specifies the name of the key in `cache` that will store the trace entries. The default one should be sufficient for most cases
101
- * feat(config): change default of setting `messageExchange.traceLogEnabled` to `false`. With this change trace entries will not be written to the standard log output
102
- * feat(exceptions): add new exception code `1006` as `E_GEN_FEATURE_UNSUPPORTED` to indicate functionality that is unsupported by the system or integrated application
103
- * refactor(config)!: correct the name of the ENV variable controlling `memoryCache.user` to `TI_MEMORY_CACHE_USER` from previous `MEMORY_CACHE_USER`
104
- * build(npm): update npm development dependencies to their latest versions
105
- * docs: update some JSDoc types and other entries to reflect the current state of the code
106
-
107
- ## Version 1.0.14
108
-
109
- * feat(message exchange): improve the behavior of `onConnectionRecovered` and `onConnectionDisrupted` events in modules `cache`, `message-handler` and `service-executor` to prevent cross-activation or deactivation
110
- * feat(redis integration): improve Redis integration for greater stability, support of Redis Cloud, and support for Redis 7
111
- * feat(config): enable setting `auditing.logDetails` by default for all logs
112
- * docs: update general documentation
113
-
114
- ## Version 1.0.13
115
-
116
- * build(npm): update npm dependencies to their latest versions
117
-
118
- ## Version 1.0.12
119
-
120
- * build(npm): update npm dependencies to their latest versions
121
-
122
- ## Version 1.0.11
123
-
124
- * feat(message exchange): implement message tampering and insertion protection
125
- * feat(config): provide option to turn on/off the message tampering and insertion protection
126
- * feat(config): provide option to turn on/off message tracing
127
- * build(npm): update npm dependencies to their latest versions
128
- * refactor(config)!: rename all environment variables that set configuration settings to match their related setting
129
- * docs: add a change log
130
-
131
- ## Version 1.0.0
132
-
1
+ # ti-engine changelog
2
+
3
+ This document will contain the list of changes made to the framework. The format is based on the [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) specification.
4
+
5
+ ## Version 1.2.3
6
+ * feat(start instance): add support for providing a custom path to the `.env` file to be used at service startup as process argument. Accepted arguments are `--env`, `--env-file`, `--dotenv`, `--dotenv-path`, and `-e`. The path itself should be relative to the working directory and should include the file name
7
+
8
+ ## Version 1.2.2
9
+ * feat(start instance): change package `dotenv` to `@dotenvx/dotenvx` for loading of ENV variables. The new package supports encrypting the ENV variables. For more information see https://dotenvx.com/docs/
10
+
11
+ ## Version 1.2.1
12
+ * feat(localization): add support for adding custom labels to the localization system. These have to follow the same format as the system labels
13
+ * docs: add section about localization to the `README.md` file
14
+
15
+ ## Version 1.2.0
16
+ * feat(config)!: change the setting `localization.labelsPath` to be an array of strings. It can now be used to supply any additional custom labels in one or more files to the framework
17
+ * feat(message memory cache): implement graceful exception handling during shut down procedure in `receiveMessage` and `sendMessage` methods
18
+ * fix(default message sender): add missing initialization of the memory cache on enable
19
+ * fix(default message receiver): add missing initialization of the memory cache on enable
20
+ * fix(message receiver): ensure `receive` method is no longer called recursively when the receiver has been disabled
21
+ * fix(redis integration)!: change the way the Redis client is initialized as the previous sequence was leaving unresolved promises and in some cases failed to fetch the Redis server settings. Also, it will now notify the listeners only once when the server settings are fetched and the connection is ready to be used
22
+ * fix(localization)!: change the way system labels are loaded as the previous implementation could cause a critical startup error if the working dir was different from expected
23
+ * fix(package): add the missing main export to the `start-instance.js` script. Without it was impossible to start the framework in specific cases like in a workspaces repository
24
+ * fix(message tracer): exclude `E_GEN_FEATURE_UNSUPPORTED` exception from the initialization of the message tracer exception handler
25
+ * fix(service executor)!: change the individual service registration process to ensure service registration does actually happen before the service provider finishes its initialization
26
+
27
+ ## Version 1.1.10
28
+ * fix(cache): fix redis client creation sequence. It is now created inside the constructor as intended. It still needs to be initialized explicitly using the `initialize` method.
29
+
30
+ ## Version 1.1.9
31
+ * feat(redis integration)!: change the way the `redis` client is initialized. Instead of happening automatically on class instantiation, it is now initialized on demand using the `initialize` method.
32
+ * feat(cache): change the way the main cache instance is initialized in compliance with the new redis integration
33
+ * feat(message memory cache)!: change the way the message memory cache is initialized in compliance with the new redis integration. The `initialize` method needs to be called explicitly to initialize the cache instance before it can be used.
34
+ * fix(message dispatcher): fix the way the `messageExchange` is initialized in the `MessageDispatcher` class (was not returning a promise)
35
+
36
+ ## Version 1.1.8
37
+ * feat(auditing): change export of the singleton class in an `instance` variable for consistency and clarity
38
+ * feat(message dispatcher): change export of the singleton class in an `instance` variable for consistency and clarity
39
+ * feat(cache): change export of the singleton class in an `instance` variable for consistency and clarity
40
+ * feat(service executor): implement service registration retry policy
41
+
42
+ ## Version 1.1.7
43
+ * feat(start instance): add support for the detection of `SIGBREAK` events and graceful shutdown on Windows
44
+ * feat(service instance)!: prevent the initialization of multiple `ServiceInstance` within the same process
45
+ * feat(message tracer)!: covert to singleton instance and add initialization method
46
+ * feat(message dispatcher): initialize the message tracer on start before message exchange is enabled
47
+ * fix(message tracer): optimize `recordTraceEntry` to not call set JSON command on every request
48
+ * fix(gcloud integration): fix the bool conversion of the `TI_GCLOUD_ENABLED` ENV variable
49
+ * fix(redis integration): update links to official commands documentation
50
+
51
+ ## Version 1.1.6
52
+ * feat(start instance): add fail-fast mode as default behavior on promise unhandled rejections
53
+ * feat(start instance): implement functionality to derive safe default service domain name when none is provided in the configuration
54
+ * feat(config): add support for new ENV variable `TI_FAIL_FAST_ON_UNHANDLED_OFF` that controls the fail-fast mode
55
+ * feat(service instance): ensure instance ID naming standard is followed when creating new instances and no ID is provided in the configuration
56
+ * feat(redis integration): marked command `hmset` as deprecated (according to official documentation)
57
+ * feat(redis integration)!: change redis client default behavior: set to automatically resend all pending commands on connection recovery with no limit on the retry attempts. This behavior cannot be changed. Arguments `autoRetryUnfulfilled` and `maxRetries` have been removed from the constructor
58
+ * feat(redis integration)!: add options to configure redis connection retry policy. This can be controlled with two new arguments in the constructor `retryMaxIntervalMs` and `retryMaxAttempts`.
59
+ * feat(redis integration)!: improve and extend the behavior of pub/sub implementation functionality. The `subscribeCommand` method can now only subscribe once to the same channel. The client instance will keep a map of all channels it has subscribed to. To unsubscribe, use the `unsubscribeCommand` method
60
+ * feat(redis integration): add a `shutDown` method to gracefully close a redis connection. This is now used on instance shut down sequence as well as in the default message sender and receiver implementations
61
+ * fix(start instance): fix the logging of reason for unhandled rejections and multiple resolves
62
+ * fix(service instance): use the static service domain name to initialize the health check instead of the ENV variable
63
+ * fix(redis integration): add detection of ReJSON2 in the verification of JSON support in the redis server
64
+ * build(npm): update npm dependencies to their latest versions
65
+ * docs: add section about ENV variables to the `README.md` file
66
+
67
+ ## Version 1.1.5
68
+
69
+ * fix(service instance): add overrides of the `reportHealthy` method in `ServiceConsumer` and `ServiceProvider` classes
70
+ * fix(tester): implement `reportHealthy` method
71
+ * docs(license): add a `LICENSE` file
72
+ * docs(license): change all licensing information in source files to GNU 3.0
73
+ * docs: improve the information in `README.md` file
74
+
75
+ ## Version 1.1.4
76
+
77
+ * feat(service instance): expose method `reportHealthy` and mark it as virtual to allow for overrides with custom health status reporting logic
78
+
79
+ ## Version 1.1.3
80
+
81
+ * feat(config)!: removed ENV variable `TI_OPERATION_MODE` as it was duplicating the practical purpose of `NODE_ENV`
82
+ * feat(config)!: setting `OPERATION_MODE` is now initialized by the `NODE_ENV` ENV variable (if provided)
83
+ * feat(service instance): show application operation mode in log at successful startup
84
+ * docs: add more sections and information in `README.md`
85
+
86
+ ## Version 1.1.2
87
+
88
+ * feat(localization): add new functionality for localization based on labels and system language. It is currently utilized by the `exceptions` module for localizing the exception descriptions. The new `localization` module can also be accessed externally in the implementing application's files via standard import
89
+ * feat(config): add new setting `localization.labelsPath` that specifies the file path for the localization labels
90
+ * feat(config): add new setting `localization.language` that specifies the language to be used for the labels
91
+ * feat(config): add new ENV variable `TI_LOCALIZATION_LABELS_PATH` that controls the `localization.labelsPath` setting
92
+ * feat(config): add new ENV variable `TI_LOCALIZATION_LANGUAGE` that controls the `localization.language` setting
93
+ * feat(logger): log exception label instead of system-level description
94
+ * fix(start instance): fix the order of ENV loading in the `start-instance.js` script. It will now properly load the `.env` file first and then proceed with any configuration overrides in `config` module
95
+ * fix(service provider): normalize service file paths on dynamic service handler loading
96
+ * build(npm): update npm dependencies to their latest versions
97
+
98
+ ## Version 1.1.1
99
+
100
+ * feat(config): add new ENV variable `TI_AUDITING_LOG_DETAILS` that controls the `auditing.logDetails` setting
101
+ * feat(service provider): add a method that returns a list of the currently registered services
102
+ * feat(tester service): improved the structure, configuration, and inline docs of tester service
103
+ * fix(logger): fix the way Exception is logged when it's a part of the main logging data object
104
+ * docs(readme): expanded the general documentation in `README.md` with a new section and improved many of the older sections
105
+ * docs: improved some of the JSDoc definitions across the framework
106
+
107
+ ## Version 1.1.0
108
+
109
+ * feat(redis integration): implement better process for fetching and storing the remote Redis server settings and enabled features
110
+ * feat(redis integration): add getter method `serverVersion` that returns the Redis server version
111
+ * feat(redis integration): add support for RedisJSON functionality
112
+ * feat(redis integration): add getter method `isJSONSupported` to verify if this module is enabled/supported in Redis server
113
+ * feat(redis integration): add separate enum for override modes `TiRedisOverrideMode`
114
+ * feat(redis integration): add support for executing any single command in Redis that is otherwise unsupported by the underlying framework. Use method `callCommand` for that in case you need to access something more exotic or currently unimplemented
115
+ * feat(cache): add support for working with JSON values. Currently supporting operations `set`, `get`, and `append array` with more coming in future versions
116
+ * feat(cache): add support for setting manual expiration of values
117
+ * feat(message tracer): change log level of trace entries from `DEBUG` to `NOTICE` for all events
118
+ * feat(message tracer): add functionality for storing the trace entries in the `cache` in JSON format. This is the default behavior and will always work. Traces can later be retrieved from the `cache` for further processing by specialized application
119
+ * feat(message tracer): add new property `traceTimestamp` to the trace entries as it may differ from the actual message timestamp
120
+ * feat(config): add new setting `messageExchange.traceExpirationTime` that controls the preservation time for all trace entries. Default is one hour and will be refreshed every time a new trace is generated. Setting this to `0` will disable
121
+ expiration altogether
122
+ * feat(config): add new setting `messageExchange.traceRepository` that specifies the name of the key in `cache` that will store the trace entries. The default one should be sufficient for most cases
123
+ * feat(config): change default of setting `messageExchange.traceLogEnabled` to `false`. With this change trace entries will not be written to the standard log output
124
+ * feat(exceptions): add new exception code `1006` as `E_GEN_FEATURE_UNSUPPORTED` to indicate functionality that is unsupported by the system or integrated application
125
+ * refactor(config)!: correct the name of the ENV variable controlling `memoryCache.user` to `TI_MEMORY_CACHE_USER` from previous `MEMORY_CACHE_USER`
126
+ * build(npm): update npm development dependencies to their latest versions
127
+ * docs: update some JSDoc types and other entries to reflect the current state of the code
128
+
129
+ ## Version 1.0.14
130
+
131
+ * feat(message exchange): improve the behavior of `onConnectionRecovered` and `onConnectionDisrupted` events in modules `cache`, `message-handler` and `service-executor` to prevent cross-activation or deactivation
132
+ * feat(redis integration): improve Redis integration for greater stability, support of Redis Cloud, and support for Redis 7
133
+ * feat(config): enable setting `auditing.logDetails` by default for all logs
134
+ * docs: update general documentation
135
+
136
+ ## Version 1.0.13
137
+
138
+ * build(npm): update npm dependencies to their latest versions
139
+
140
+ ## Version 1.0.12
141
+
142
+ * build(npm): update npm dependencies to their latest versions
143
+
144
+ ## Version 1.0.11
145
+
146
+ * feat(message exchange): implement message tampering and insertion protection
147
+ * feat(config): provide option to turn on/off the message tampering and insertion protection
148
+ * feat(config): provide option to turn on/off message tracing
149
+ * build(npm): update npm dependencies to their latest versions
150
+ * refactor(config)!: rename all environment variables that set configuration settings to match their related setting
151
+ * docs: add a change log
152
+
153
+ ## Version 1.0.0
154
+
133
155
  * feat: create initial version of the framework
package/README.md CHANGED
@@ -395,9 +395,9 @@ GCLOUD_PROJECT_ID (Alpha)
395
395
  : This setting holds the project ID for the GCloud integration module.
396
396
 
397
397
  LOCALIZATION_LABELS_PATH
398
- : JSON path `localization.labelsPath`, type `string`, default `../core/bin/localization/labels.json`
398
+ : JSON path `localization.labelsPath`, type `Array<string>`, default `[]`
399
399
  : ENV variable `TI_LOCALIZATION_LABELS_PATH`
400
- : This setting holds the file system path to the `.json` file containing the localization information. By default, the framework provides such a file with english texts that can be customized further. Alternatively, you can provide your own file from a different location, but it still has to follow the rules of the `localization` module.
400
+ : This setting holds a list of paths to custom `.json` files containing additional localization information. By default, the framework also provides such a file with english texts that can be customized further. All additional JSONs in these files have to follow the rules and structure of the `localization` module.
401
401
 
402
402
  LOCALIZATION_LANGUAGE
403
403
  : JSON path `localization.language`, type `string`, default `en`
@@ -497,4 +497,24 @@ OPERATION_MODE
497
497
 
498
498
  ## Advanced topics
499
499
 
500
- Under development...
500
+ ### Localization
501
+
502
+ The **ti-engine** framework provides a localization mechanism that allows you to translate labels into localized text. The framework comes with a default set of labels that can be found in the `localization` module. You can add your own custom labels to this set by providing one or more JSON files with the same structure as the default one (see below). The path to these files should be specified in the `LOCALIZATION_LABELS_PATH` setting. On startup, the framework will load all the JSON files and merge them into a single repository.
503
+
504
+ The following is an example of a custom localization file (the names in brackets can be replaced with your own values):
505
+
506
+ ```json
507
+ {
508
+ "labels": {
509
+ "[category]": {
510
+ "[sub-category]": {
511
+ "[label]": {
512
+ "en": "[localized label text]"
513
+ }
514
+ }
515
+ }
516
+ }
517
+ }
518
+ ```
519
+
520
+ The individual languages are specified with a two-letter code. The default language is `en` (English). If you want to use a different language, you can set the `LOCALIZATION_LANGUAGE` setting to the desired language code.
package/bin/settings.json CHANGED
@@ -12,7 +12,7 @@
12
12
  "projectID": ""
13
13
  },
14
14
  "localization": {
15
- "labelsPath": "../core/bin/localization/labels.json",
15
+ "labelsPath": [],
16
16
  "language": "en"
17
17
  },
18
18
  "memoryCache": {
@@ -11,7 +11,28 @@
11
11
  const path = require( "path" );
12
12
 
13
13
  // Load any ENV variables defined in a .env file - before including any framework files:
14
- require( "dotenv" ).config( { path: path.join( process.cwd(), ".env" ) } );
14
+ // - If an env file path is provided via process arguments, use it; otherwise, default to CWD/.env
15
+ const envFilePath = ( () => {
16
+ let envPath = path.join( process.cwd(), ".env" );
17
+ try {
18
+ const argv = Array.isArray( process.argv ) ? process.argv.slice( 2 ) : [];
19
+ const aliases = [ "--env", "--env-file", "--dotenv", "--dotenv-path", "-e" ];
20
+ for ( const key of aliases ) {
21
+ const idx = argv.indexOf( key );
22
+ if ( idx !== -1 && idx + 1 < argv.length ) {
23
+ const value = argv[ idx + 1 ];
24
+ if ( typeof value === "string" && !value.startsWith( "-" ) ) {
25
+ envPath = path.join( process.cwd(), value.trim() );
26
+ break;
27
+ }
28
+ }
29
+ }
30
+ } catch {
31
+ }
32
+ return envPath;
33
+ } )();
34
+
35
+ require( "@dotenvx/dotenvx" ).config( { path: envFilePath } );
15
36
 
16
37
  const tools = require( "#tools" );
17
38
  const logger = require( "#logger" );
@@ -36,7 +57,7 @@ const defaultNameFromClass = ( () => {
36
57
 
37
58
  process.env.TI_INSTANCE_NAME = process.env.TI_INSTANCE_NAME || defaultNameFromClass;
38
59
 
39
- // Configure the process error handlers:
60
+ // Configure the process termination handlers to ensure a graceful shutdown:
40
61
 
41
62
  /**
42
63
  * Will be used to gracefully shut down the instance.
@@ -75,6 +96,8 @@ process.on( "SIGBREAK", () => {
75
96
  shutDownInstance( 0 );
76
97
  } );
77
98
 
99
+ // Configure the process general error handlers:
100
+
78
101
  process.on( "unhandledRejection", ( reason ) => {
79
102
  // Check if the fail-fast behavior has been forcefully disabled:
80
103
  const failFastDisabled = tools.toBool( process.env.TI_FAIL_FAST_ON_UNHANDLED_OFF || "" );
@@ -1,6 +1,6 @@
1
1
  /*
2
2
  * The ti-engine is an open source, free to use—both for personal and commercial projects—framework for the creation of microservice-based solutions using node.js.
3
- * Copyright © 2021-2023 Boris Kostadinov <kostadinov.boris@gmail.com>
3
+ * Copyright © 2021-2025 Boris Kostadinov <kostadinov.boris@gmail.com>
4
4
  * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
5
5
  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
6
6
  * You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
@@ -43,8 +43,13 @@ class DefaultMessageReceiver extends MessageReceiver {
43
43
  return new Promise( ( resolve, reject ) => {
44
44
  this.#memoryCache = memoryCache.create( this.connectionIdentifier );
45
45
  this.#memoryCache.addConnectionObserver( this );
46
- this.receive();
47
- resolve();
46
+ this.#memoryCache.initialize().then( () => {
47
+ this.isReceiving = true;
48
+ this.receive();
49
+ resolve();
50
+ } ).catch( ( error ) => {
51
+ reject( exceptions.raise( error ) );
52
+ } );
48
53
  } );
49
54
  }
50
55
 
@@ -60,6 +65,7 @@ class DefaultMessageReceiver extends MessageReceiver {
60
65
  return new Promise( ( resolve, reject ) => {
61
66
  this.isAvailable = false;
62
67
  this.#memoryCache.shutDown().then( () => {
68
+ this.isReceiving = false;
63
69
  this.#memoryCache = null;
64
70
  resolve();
65
71
  } ).catch( ( error ) => {
@@ -80,6 +86,7 @@ class DefaultMessageReceiver extends MessageReceiver {
80
86
  */
81
87
  onReceive() {
82
88
  return new Promise( ( resolve, reject ) => {
89
+ // NOTE: The method execution will block on this call until a message is received:
83
90
  this.#memoryCache.receiveMessage( this.receiveQueue ).then( ( lightweightMessage ) => {
84
91
  return this.#memoryCache.retrieveMessagePayload( lightweightMessage, config.getSetting( config.setting.MESSAGE_EXCHANGE_MESSAGE_STORE ) );
85
92
  } ).then( ( message ) => {
@@ -92,4 +99,4 @@ class DefaultMessageReceiver extends MessageReceiver {
92
99
 
93
100
  }
94
101
 
95
- module.exports = DefaultMessageReceiver;
102
+ module.exports = DefaultMessageReceiver;
@@ -1,6 +1,6 @@
1
1
  /*
2
2
  * The ti-engine is an open source, free to use—both for personal and commercial projects—framework for the creation of microservice-based solutions using node.js.
3
- * Copyright © 2021-2023 Boris Kostadinov <kostadinov.boris@gmail.com>
3
+ * Copyright © 2021-2025 Boris Kostadinov <kostadinov.boris@gmail.com>
4
4
  * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
5
5
  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
6
6
  * You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
@@ -34,7 +34,7 @@ class DefaultMessageSender extends MessageSender {
34
34
  /**
35
35
  * Used to perform the actual sending of a message.
36
36
  * <br/>
37
- * NOTE: The default message exchange works with lightweight messages (i.e. will keep the payloads stored in Redis while exchanging).
37
+ * NOTE: The default message exchange works with lightweight messages (i.e., will keep the payloads stored in Redis while exchanging).
38
38
  *
39
39
  * @method
40
40
  * @param {Message} message The message to send.
@@ -69,7 +69,11 @@ class DefaultMessageSender extends MessageSender {
69
69
  return new Promise( ( resolve, reject ) => {
70
70
  this.#memoryCache = memoryCache.create( this.connectionIdentifier );
71
71
  this.#memoryCache.addConnectionObserver( this );
72
- resolve();
72
+ this.#memoryCache.initialize().then( () => {
73
+ resolve();
74
+ } ).catch( ( error ) => {
75
+ reject( exceptions.raise( error ) );
76
+ } );
73
77
  } );
74
78
  }
75
79
 
@@ -94,4 +98,4 @@ class DefaultMessageSender extends MessageSender {
94
98
  }
95
99
  }
96
100
 
97
- module.exports = DefaultMessageSender;
101
+ module.exports = DefaultMessageSender;
@@ -1,6 +1,6 @@
1
1
  /*
2
2
  * The ti-engine is an open source, free to use—both for personal and commercial projects—framework for the creation of microservice-based solutions using node.js.
3
- * Copyright © 2021-2023 Boris Kostadinov <kostadinov.boris@gmail.com>
3
+ * Copyright © 2021-2025 Boris Kostadinov <kostadinov.boris@gmail.com>
4
4
  * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
5
5
  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
6
6
  * You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
@@ -170,7 +170,7 @@ class MessageHandler extends ConnectionObserver {
170
170
  }
171
171
 
172
172
  /**
173
- * An event-triggered method that will notify any observers about primary connection disrupted state.
173
+ * An event-triggered method that will notify any observers about the primary connection disrupted state.
174
174
  * <br/>
175
175
  * NOTE: You can override this to add custom functionality but make sure to also call the base method
176
176
  * using: super.onConnectionDisrupted( identifier )
@@ -191,4 +191,4 @@ class MessageHandler extends ConnectionObserver {
191
191
 
192
192
  }
193
193
 
194
- module.exports = MessageHandler;
194
+ module.exports = MessageHandler;
@@ -20,6 +20,7 @@ const redis = require( "#redis-integration" );
20
20
  class MessageMemoryCache {
21
21
 
22
22
  #redisClient = null;
23
+ #isShuttingDown = false;
23
24
 
24
25
  /**
25
26
  * @constructor
@@ -60,6 +61,7 @@ class MessageMemoryCache {
60
61
  * @public
61
62
  */
62
63
  shutDown( timeoutMs ) {
64
+ this.#isShuttingDown = true;
63
65
  return this.#redisClient.shutDown( timeoutMs );
64
66
  }
65
67
 
@@ -85,13 +87,17 @@ class MessageMemoryCache {
85
87
  */
86
88
  sendMessage( message, queue ) {
87
89
  return new Promise( ( resolve, reject ) => {
88
- let command = [ redis.cacheCommands.LIST_PUSH, queue, tools.stringifyJSON( message ) ];
89
- this.#redisClient.executeCommands( [ command ] ).then( ( results ) => {
90
- results = results[ 0 ];
91
- resolve( ( results && results.length > 1 ) ? results[ 1 ] : undefined );
92
- } ).catch( ( error ) => {
93
- reject( exceptions.raise( error ) );
94
- } );
90
+ if ( this.#isShuttingDown === true ) {
91
+ reject( exceptions.raise( exceptions.exceptionCode.E_COM_MESSAGE_SENDER_UNAVAILABLE ) );
92
+ } else {
93
+ let command = [ redis.cacheCommands.LIST_PUSH, queue, tools.stringifyJSON( message ) ];
94
+ this.#redisClient.executeCommands( [ command ] ).then( ( results ) => {
95
+ results = results[ 0 ];
96
+ resolve( ( results && results.length > 1 ) ? results[ 1 ] : undefined );
97
+ } ).catch( ( error ) => {
98
+ reject( exceptions.raise( error ) );
99
+ } );
100
+ }
95
101
  } );
96
102
  }
97
103
 
@@ -134,7 +140,11 @@ class MessageMemoryCache {
134
140
  results = ( results && results.length > 1 ) ? results[ 1 ] : undefined;
135
141
  resolve( tools.parseJSON( results ) );
136
142
  } ).catch( ( error ) => {
137
- reject( exceptions.raise( error ) );
143
+ if ( this.#isShuttingDown === true ) {
144
+ reject( exceptions.raise( exceptions.exceptionCode.E_COM_MESSAGE_RECEIVER_UNAVAILABLE ) );
145
+ } else {
146
+ reject( exceptions.raise( error ) );
147
+ }
138
148
  } );
139
149
  } );
140
150
  }