@ti-engine/core 1.6.1 → 1.7.2

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.
Files changed (33) hide show
  1. package/CHANGELOG.md +383 -364
  2. package/LICENSE.md +321 -321
  3. package/README.md +597 -548
  4. package/bin/localization/labels.json +122 -122
  5. package/bin/settings.json +41 -41
  6. package/bin/start-instance.js +164 -156
  7. package/components/auditing.js +191 -191
  8. package/components/connection-observer.js +72 -72
  9. package/components/definitions.types.js +248 -248
  10. package/components/exchange/default/default-message-exchange.js +136 -136
  11. package/components/exchange/default/default-message-receiver.js +101 -101
  12. package/components/exchange/default/default-message-sender.js +100 -100
  13. package/components/exchange/message-dispatcher.js +168 -168
  14. package/components/exchange/message-exchange.js +449 -449
  15. package/components/exchange/message-handler.js +235 -234
  16. package/components/exchange/message-memory-cache.js +190 -190
  17. package/components/exchange/message-observer.js +126 -126
  18. package/components/exchange/message-receiver.js +181 -181
  19. package/components/exchange/message-sender.js +143 -143
  20. package/components/exchange/message-tracer.js +212 -212
  21. package/components/service-caller.js +370 -370
  22. package/components/service-consumer.js +131 -131
  23. package/components/service-executor.js +278 -278
  24. package/components/service-instance.js +316 -316
  25. package/components/service-provider.js +251 -251
  26. package/integrations/redis-integration.js +591 -591
  27. package/package.json +89 -90
  28. package/utils/cache.js +772 -772
  29. package/utils/config.js +103 -103
  30. package/utils/exceptions.js +368 -368
  31. package/utils/localization.js +298 -298
  32. package/utils/logger.js +82 -82
  33. package/utils/tools.js +632 -632
@@ -1,132 +1,132 @@
1
- /*
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-2025 Boris Kostadinov <kostadinov.boris@gmail.com>
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
- * 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
- * You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
7
- */
8
-
9
- const ServiceInstance = require( "#service-instance" );
10
- const exceptions = require( "#exceptions" );
11
- const messageDispatcher = require( "#message-dispatcher" );
12
-
13
- /**
14
- * Abstract class used to define a Service Consumer behavior.
15
- * <br/>
16
- * NOTE: Inherit this to create a module that can be started as a microservice consumer instance.
17
- * <br/>
18
- * NOTE: A service consumer is a microservice that can invoke named business services in the APIs of other
19
- * microservices using {@link ServiceCall} objects. The consumer does not need to know the specifics of
20
- * the business logic in these services but only the service address and the inbound parameters (if any).
21
- * The result of the execution will be returned to the consumer in a {@link ServiceCallResult} object.
22
- *
23
- * @class ServiceConsumer
24
- * @extends ServiceInstance
25
- * @abstract
26
- * @public
27
- */
28
- class ServiceConsumer extends ServiceInstance {
29
-
30
- #serviceCaller;
31
-
32
- /**
33
- * @constructor
34
- * @param {string} serviceDomainName The service domain name for this service instance.
35
- * @param {ServiceConfiguration} [serviceConfig] The JSON configuration for this service.
36
- * @throws {TiException.E_GEN_ABSTRACT_CLASS_INIT} If this class is instantiated directly.
37
- */
38
- constructor( serviceDomainName, serviceConfig ) {
39
- super( serviceDomainName, serviceConfig );
40
-
41
- // make sure this abstract class cannot be instantiated:
42
- if ( new.target === ServiceConsumer ) {
43
- throw exceptions.raise( exceptions.exceptionCode.E_GEN_ABSTRACT_CLASS_INIT, { name: this.constructor.name } );
44
- }
45
- }
46
-
47
- /* Public interface */
48
-
49
- /**
50
- * Perform initialization tasks when the service consumer starts.
51
- * <br/>
52
- * NOTE: This method will be invoked automatically.
53
- * <br/>
54
- * NOTE: If you need to add more onStart logic you can override this method but make sure to call it in the
55
- * overriding method using: super.onStart()
56
- *
57
- * @method
58
- * @returns {Promise}
59
- * @override
60
- * @public
61
- */
62
- onStart() {
63
- return new Promise( ( resolve, reject ) => {
64
- const ServiceCaller = require( "#service-caller" );
65
-
66
- this.#serviceCaller = new ServiceCaller();
67
-
68
- super.onStart().then( () => {
69
- messageDispatcher.instance.addMessageObserverResponsesIn( this.#serviceCaller );
70
- resolve();
71
- } ).catch( ( error ) => {
72
- reject( exceptions.raise( error ) );
73
- } );
74
- } );
75
- }
76
-
77
- /**
78
- * Perform shut down and cleanup tasks when the service consumer stops.
79
- * <br/>
80
- * NOTE: This method will be invoked automatically.
81
- * <br/>
82
- * NOTE: If you need to add more onStop logic you can override this method but make sure to call it in the
83
- * overriding method using: super.onStop()
84
- *
85
- * @method
86
- * @returns {Promise}
87
- * @override
88
- * @public
89
- */
90
- onStop() {
91
- return new Promise( ( resolve, reject ) => {
92
- super.onStop().then( () => {
93
- resolve();
94
- } ).catch( ( error ) => {
95
- reject( exceptions.raise( error ) );
96
- } );
97
- } );
98
- }
99
-
100
- /**
101
- * Used to report health status of the service instance for external monitoring.
102
- * This is a scheduled job that will be executed at SERVICE_HEALTH_CHECK_INTERVAL time.
103
- * <br/>
104
- * NOTE: By default this method will update a Redis key with an expiration timer. You can override this
105
- * functionality with something custom like calling an HTTP endpoint.
106
- *
107
- * @method
108
- * @override
109
- * @virtual
110
- * @public
111
- */
112
- reportHealthy() {
113
- super.reportHealthy();
114
- }
115
-
116
- /**
117
- * Used to invoke a business service in any {@link ServiceInstance}.
118
- *
119
- * @method
120
- * @param {ServiceAddress} serviceAddress
121
- * @param {Object} serviceParams
122
- * @param {ServiceExecContext} serviceExecContext
123
- * @returns {Promise<ServiceCallResult>}
124
- * @public
125
- */
126
- callService( serviceAddress, serviceParams, serviceExecContext ) {
127
- return this.#serviceCaller.executeServiceCall( serviceAddress, serviceParams, serviceExecContext );
128
- }
129
-
130
- }
131
-
1
+ /*
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-2025 Boris Kostadinov <kostadinov.boris@gmail.com>
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
+ * 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
+ * You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
7
+ */
8
+
9
+ const ServiceInstance = require( "#service-instance" );
10
+ const exceptions = require( "#exceptions" );
11
+ const messageDispatcher = require( "#message-dispatcher" );
12
+
13
+ /**
14
+ * Abstract class used to define a Service Consumer behavior.
15
+ * <br/>
16
+ * NOTE: Inherit this to create a module that can be started as a microservice consumer instance.
17
+ * <br/>
18
+ * NOTE: A service consumer is a microservice that can invoke named business services in the APIs of other
19
+ * microservices using {@link ServiceCall} objects. The consumer does not need to know the specifics of
20
+ * the business logic in these services but only the service address and the inbound parameters (if any).
21
+ * The result of the execution will be returned to the consumer in a {@link ServiceCallResult} object.
22
+ *
23
+ * @class ServiceConsumer
24
+ * @extends ServiceInstance
25
+ * @abstract
26
+ * @public
27
+ */
28
+ class ServiceConsumer extends ServiceInstance {
29
+
30
+ #serviceCaller;
31
+
32
+ /**
33
+ * @constructor
34
+ * @param {string} serviceDomainName The service domain name for this service instance.
35
+ * @param {ServiceConfiguration} [serviceConfig] The JSON configuration for this service.
36
+ * @throws {TiException.E_GEN_ABSTRACT_CLASS_INIT} If this class is instantiated directly.
37
+ */
38
+ constructor( serviceDomainName, serviceConfig ) {
39
+ super( serviceDomainName, serviceConfig );
40
+
41
+ // make sure this abstract class cannot be instantiated:
42
+ if ( new.target === ServiceConsumer ) {
43
+ throw exceptions.raise( exceptions.exceptionCode.E_GEN_ABSTRACT_CLASS_INIT, { name: this.constructor.name } );
44
+ }
45
+ }
46
+
47
+ /* Public interface */
48
+
49
+ /**
50
+ * Perform initialization tasks when the service consumer starts.
51
+ * <br/>
52
+ * NOTE: This method will be invoked automatically.
53
+ * <br/>
54
+ * NOTE: If you need to add more onStart logic you can override this method but make sure to call it in the
55
+ * overriding method using: super.onStart()
56
+ *
57
+ * @method
58
+ * @returns {Promise}
59
+ * @override
60
+ * @public
61
+ */
62
+ onStart() {
63
+ return new Promise( ( resolve, reject ) => {
64
+ const ServiceCaller = require( "#service-caller" );
65
+
66
+ this.#serviceCaller = new ServiceCaller();
67
+
68
+ super.onStart().then( () => {
69
+ messageDispatcher.instance.addMessageObserverResponsesIn( this.#serviceCaller );
70
+ resolve();
71
+ } ).catch( ( error ) => {
72
+ reject( exceptions.raise( error ) );
73
+ } );
74
+ } );
75
+ }
76
+
77
+ /**
78
+ * Perform shut down and cleanup tasks when the service consumer stops.
79
+ * <br/>
80
+ * NOTE: This method will be invoked automatically.
81
+ * <br/>
82
+ * NOTE: If you need to add more onStop logic you can override this method but make sure to call it in the
83
+ * overriding method using: super.onStop()
84
+ *
85
+ * @method
86
+ * @returns {Promise}
87
+ * @override
88
+ * @public
89
+ */
90
+ onStop() {
91
+ return new Promise( ( resolve, reject ) => {
92
+ super.onStop().then( () => {
93
+ resolve();
94
+ } ).catch( ( error ) => {
95
+ reject( exceptions.raise( error ) );
96
+ } );
97
+ } );
98
+ }
99
+
100
+ /**
101
+ * Used to report health status of the service instance for external monitoring.
102
+ * This is a scheduled job that will be executed at SERVICE_HEALTH_CHECK_INTERVAL time.
103
+ * <br/>
104
+ * NOTE: By default this method will update a Redis key with an expiration timer. You can override this
105
+ * functionality with something custom like calling an HTTP endpoint.
106
+ *
107
+ * @method
108
+ * @override
109
+ * @virtual
110
+ * @public
111
+ */
112
+ reportHealthy() {
113
+ super.reportHealthy();
114
+ }
115
+
116
+ /**
117
+ * Used to invoke a business service in any {@link ServiceInstance}.
118
+ *
119
+ * @method
120
+ * @param {ServiceAddress} serviceAddress
121
+ * @param {Object} serviceParams
122
+ * @param {ServiceExecContext} serviceExecContext
123
+ * @returns {Promise<ServiceCallResult>}
124
+ * @public
125
+ */
126
+ callService( serviceAddress, serviceParams, serviceExecContext ) {
127
+ return this.#serviceCaller.executeServiceCall( serviceAddress, serviceParams, serviceExecContext );
128
+ }
129
+
130
+ }
131
+
132
132
  module.exports = ServiceConsumer;