@twin.org/engine-core 0.0.2-next.7 → 0.0.2-next.9

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.
@@ -1,5 +1,6 @@
1
1
  'use strict';
2
2
 
3
+ var node_worker_threads = require('node:worker_threads');
3
4
  var core = require('@twin.org/core');
4
5
  var entity = require('@twin.org/entity');
5
6
  var loggingConnectorConsole = require('@twin.org/logging-connector-console');
@@ -117,6 +118,11 @@ class EngineCore {
117
118
  * @internal
118
119
  */
119
120
  _isStarted;
121
+ /**
122
+ * Is the engine a clone.
123
+ * @internal
124
+ */
125
+ _isClone;
120
126
  /**
121
127
  * Add type initialisers to the engine.
122
128
  * @internal
@@ -151,6 +157,7 @@ class EngineCore {
151
157
  };
152
158
  this._stateStorage = options.stateStorage;
153
159
  this._isStarted = false;
160
+ this._isClone = false;
154
161
  if (core.Is.function(this._populateTypeInitialisers)) {
155
162
  this._populateTypeInitialisers(this, this._context);
156
163
  }
@@ -244,6 +251,27 @@ class EngineCore {
244
251
  this.logInfo(core.I18n.formatMessage(`${EngineCore._CLASS_NAME_CAMEL_CASE}.componentsStopped`));
245
252
  this.logInfo(core.I18n.formatMessage(`${EngineCore._CLASS_NAME_CAMEL_CASE}.stopped`));
246
253
  }
254
+ /**
255
+ * Is the engine started.
256
+ * @returns True if the engine is started.
257
+ */
258
+ isStarted() {
259
+ return this._isStarted;
260
+ }
261
+ /**
262
+ * Is this the primary engine instance.
263
+ * @returns True if the engine is the primary instance.
264
+ */
265
+ isPrimary() {
266
+ return node_worker_threads.isMainThread && !this._isClone;
267
+ }
268
+ /**
269
+ * Is this engine instance a clone.
270
+ * @returns True if the engine instance is a clone.
271
+ */
272
+ isClone() {
273
+ return this._isClone;
274
+ }
247
275
  /**
248
276
  * Log info.
249
277
  * @param message The message to log.
@@ -364,6 +392,7 @@ class EngineCore {
364
392
  core.Guards.array(EngineCore._CLASS_NAME, "cloneData.typeInitialisers", cloneData.typeInitialisers);
365
393
  this._loggerTypeName = cloneData.loggerTypeName;
366
394
  this._skipBootstrap = true;
395
+ this._isClone = true;
367
396
  if (silent ?? false) {
368
397
  cloneData.config.silent = true;
369
398
  }
@@ -1,3 +1,4 @@
1
+ import { isMainThread } from 'node:worker_threads';
1
2
  import { I18n, StringHelper, Is, BaseError, GeneralError, ErrorHelper, Guards, ComponentFactory } from '@twin.org/core';
2
3
  import { EntitySchemaFactory } from '@twin.org/entity';
3
4
  import { ConsoleLoggingConnector } from '@twin.org/logging-connector-console';
@@ -115,6 +116,11 @@ class EngineCore {
115
116
  * @internal
116
117
  */
117
118
  _isStarted;
119
+ /**
120
+ * Is the engine a clone.
121
+ * @internal
122
+ */
123
+ _isClone;
118
124
  /**
119
125
  * Add type initialisers to the engine.
120
126
  * @internal
@@ -149,6 +155,7 @@ class EngineCore {
149
155
  };
150
156
  this._stateStorage = options.stateStorage;
151
157
  this._isStarted = false;
158
+ this._isClone = false;
152
159
  if (Is.function(this._populateTypeInitialisers)) {
153
160
  this._populateTypeInitialisers(this, this._context);
154
161
  }
@@ -242,6 +249,27 @@ class EngineCore {
242
249
  this.logInfo(I18n.formatMessage(`${EngineCore._CLASS_NAME_CAMEL_CASE}.componentsStopped`));
243
250
  this.logInfo(I18n.formatMessage(`${EngineCore._CLASS_NAME_CAMEL_CASE}.stopped`));
244
251
  }
252
+ /**
253
+ * Is the engine started.
254
+ * @returns True if the engine is started.
255
+ */
256
+ isStarted() {
257
+ return this._isStarted;
258
+ }
259
+ /**
260
+ * Is this the primary engine instance.
261
+ * @returns True if the engine is the primary instance.
262
+ */
263
+ isPrimary() {
264
+ return isMainThread && !this._isClone;
265
+ }
266
+ /**
267
+ * Is this engine instance a clone.
268
+ * @returns True if the engine instance is a clone.
269
+ */
270
+ isClone() {
271
+ return this._isClone;
272
+ }
245
273
  /**
246
274
  * Log info.
247
275
  * @param message The message to log.
@@ -362,6 +390,7 @@ class EngineCore {
362
390
  Guards.array(EngineCore._CLASS_NAME, "cloneData.typeInitialisers", cloneData.typeInitialisers);
363
391
  this._loggerTypeName = cloneData.loggerTypeName;
364
392
  this._skipBootstrap = true;
393
+ this._isClone = true;
365
394
  if (silent ?? false) {
366
395
  cloneData.config.silent = true;
367
396
  }
@@ -36,6 +36,21 @@ export declare class EngineCore<C extends IEngineCoreConfig = IEngineCoreConfig,
36
36
  * @returns Nothing.
37
37
  */
38
38
  stop(): Promise<void>;
39
+ /**
40
+ * Is the engine started.
41
+ * @returns True if the engine is started.
42
+ */
43
+ isStarted(): boolean;
44
+ /**
45
+ * Is this the primary engine instance.
46
+ * @returns True if the engine is the primary instance.
47
+ */
48
+ isPrimary(): boolean;
49
+ /**
50
+ * Is this engine instance a clone.
51
+ * @returns True if the engine instance is a clone.
52
+ */
53
+ isClone(): boolean;
39
54
  /**
40
55
  * Log info.
41
56
  * @param message The message to log.
package/docs/changelog.md CHANGED
@@ -1,5 +1,33 @@
1
1
  # @twin.org/engine-core - Changelog
2
2
 
3
+ ## [0.0.2-next.9](https://github.com/twinfoundation/engine/compare/engine-core-v0.0.2-next.8...engine-core-v0.0.2-next.9) (2025-08-25)
4
+
5
+
6
+ ### Features
7
+
8
+ * add isPrimary and isClone methods ([a7c63e9](https://github.com/twinfoundation/engine/commit/a7c63e97f54c95b104cc81e66d3fa42c6607bdc1))
9
+
10
+
11
+ ### Dependencies
12
+
13
+ * The following workspace dependencies were updated
14
+ * dependencies
15
+ * @twin.org/engine-models bumped from 0.0.2-next.8 to 0.0.2-next.9
16
+
17
+ ## [0.0.2-next.8](https://github.com/twinfoundation/engine/compare/engine-core-v0.0.2-next.7...engine-core-v0.0.2-next.8) (2025-08-22)
18
+
19
+
20
+ ### Miscellaneous Chores
21
+
22
+ * **engine-core:** Synchronize repo versions
23
+
24
+
25
+ ### Dependencies
26
+
27
+ * The following workspace dependencies were updated
28
+ * dependencies
29
+ * @twin.org/engine-models bumped from 0.0.2-next.7 to 0.0.2-next.8
30
+
3
31
  ## [0.0.2-next.7](https://github.com/twinfoundation/engine/compare/engine-core-v0.0.2-next.6...engine-core-v0.0.2-next.7) (2025-08-22)
4
32
 
5
33
 
@@ -132,6 +132,60 @@ Nothing.
132
132
 
133
133
  ***
134
134
 
135
+ ### isStarted()
136
+
137
+ > **isStarted**(): `boolean`
138
+
139
+ Is the engine started.
140
+
141
+ #### Returns
142
+
143
+ `boolean`
144
+
145
+ True if the engine is started.
146
+
147
+ #### Implementation of
148
+
149
+ `IEngineCore.isStarted`
150
+
151
+ ***
152
+
153
+ ### isPrimary()
154
+
155
+ > **isPrimary**(): `boolean`
156
+
157
+ Is this the primary engine instance.
158
+
159
+ #### Returns
160
+
161
+ `boolean`
162
+
163
+ True if the engine is the primary instance.
164
+
165
+ #### Implementation of
166
+
167
+ `IEngineCore.isPrimary`
168
+
169
+ ***
170
+
171
+ ### isClone()
172
+
173
+ > **isClone**(): `boolean`
174
+
175
+ Is this engine instance a clone.
176
+
177
+ #### Returns
178
+
179
+ `boolean`
180
+
181
+ True if the engine instance is a clone.
182
+
183
+ #### Implementation of
184
+
185
+ `IEngineCore.isClone`
186
+
187
+ ***
188
+
135
189
  ### logInfo()
136
190
 
137
191
  > **logInfo**(`message`): `void`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@twin.org/engine-core",
3
- "version": "0.0.2-next.7",
3
+ "version": "0.0.2-next.9",
4
4
  "description": "Engine core.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -17,7 +17,7 @@
17
17
  "@twin.org/core": "next",
18
18
  "@twin.org/crypto": "next",
19
19
  "@twin.org/data-core": "next",
20
- "@twin.org/engine-models": "0.0.2-next.7",
20
+ "@twin.org/engine-models": "0.0.2-next.9",
21
21
  "@twin.org/entity": "next",
22
22
  "@twin.org/logging-connector-console": "next",
23
23
  "@twin.org/logging-models": "next",