@twin.org/engine-core 0.0.2-next.6 → 0.0.2-next.7
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/dist/cjs/index.cjs +6 -29
- package/dist/esm/index.mjs +7 -30
- package/docs/changelog.md +14 -0
- package/package.json +2 -2
package/dist/cjs/index.cjs
CHANGED
|
@@ -146,7 +146,7 @@ class EngineCore {
|
|
|
146
146
|
config: options.config,
|
|
147
147
|
registeredInstances: {},
|
|
148
148
|
componentInstances: [],
|
|
149
|
-
state: {
|
|
149
|
+
state: {},
|
|
150
150
|
stateDirty: false
|
|
151
151
|
};
|
|
152
152
|
this._stateStorage = options.stateStorage;
|
|
@@ -196,17 +196,10 @@ class EngineCore {
|
|
|
196
196
|
this.logInfo(core.I18n.formatMessage(`${EngineCore._CLASS_NAME_CAMEL_CASE}.componentsStarting`));
|
|
197
197
|
for (const instance of this._context.componentInstances) {
|
|
198
198
|
if (core.Is.function(instance.component.start)) {
|
|
199
|
-
const instanceName = this.getInstanceName(instance);
|
|
200
199
|
this.logInfo(core.I18n.formatMessage(`${EngineCore._CLASS_NAME_CAMEL_CASE}.componentStarting`, {
|
|
201
200
|
element: instance.instanceType
|
|
202
201
|
}));
|
|
203
|
-
|
|
204
|
-
const lastState = core.ObjectHelper.clone(componentState);
|
|
205
|
-
await instance.component.start(this._context.state.nodeIdentity, this._loggerTypeName, componentState);
|
|
206
|
-
if (!core.ObjectHelper.equal(lastState, componentState)) {
|
|
207
|
-
this._context.state.componentStates[instanceName] = componentState;
|
|
208
|
-
this._context.stateDirty = true;
|
|
209
|
-
}
|
|
202
|
+
await instance.component.start(this._context.state.nodeIdentity, this._loggerTypeName);
|
|
210
203
|
}
|
|
211
204
|
}
|
|
212
205
|
this.logInfo(core.I18n.formatMessage(`${EngineCore._CLASS_NAME_CAMEL_CASE}.componentsComplete`));
|
|
@@ -234,18 +227,11 @@ class EngineCore {
|
|
|
234
227
|
this.logInfo(core.I18n.formatMessage(`${EngineCore._CLASS_NAME_CAMEL_CASE}.componentsStopping`));
|
|
235
228
|
for (const instance of this._context.componentInstances) {
|
|
236
229
|
if (core.Is.function(instance.component.stop)) {
|
|
237
|
-
const instanceName = this.getInstanceName(instance);
|
|
238
|
-
const componentState = this._context.state.componentStates[instanceName] ?? {};
|
|
239
|
-
const lastState = core.ObjectHelper.clone(componentState);
|
|
240
230
|
this.logInfo(core.I18n.formatMessage(`${EngineCore._CLASS_NAME_CAMEL_CASE}.componentStopping`, {
|
|
241
231
|
element: instance.instanceType
|
|
242
232
|
}));
|
|
243
233
|
try {
|
|
244
|
-
await instance.component.stop(this._context.state.nodeIdentity, this._loggerTypeName
|
|
245
|
-
if (!core.ObjectHelper.equal(lastState, componentState)) {
|
|
246
|
-
this._context.state.componentStates[instanceName] = componentState;
|
|
247
|
-
this._context.stateDirty = true;
|
|
248
|
-
}
|
|
234
|
+
await instance.component.stop(this._context.state.nodeIdentity, this._loggerTypeName);
|
|
249
235
|
}
|
|
250
236
|
catch (err) {
|
|
251
237
|
this.logError(new core.GeneralError(EngineCore._CLASS_NAME, "componentStopFailed", {
|
|
@@ -385,7 +371,7 @@ class EngineCore {
|
|
|
385
371
|
config: cloneData.config,
|
|
386
372
|
registeredInstances: {},
|
|
387
373
|
componentInstances: [],
|
|
388
|
-
state: {
|
|
374
|
+
state: {},
|
|
389
375
|
stateDirty: false
|
|
390
376
|
};
|
|
391
377
|
this._typeInitialisers = cloneData.typeInitialisers;
|
|
@@ -467,10 +453,7 @@ class EngineCore {
|
|
|
467
453
|
async stateLoad() {
|
|
468
454
|
if (this._stateStorage) {
|
|
469
455
|
try {
|
|
470
|
-
this._context.state = ((await this._stateStorage.load(this)) ?? {
|
|
471
|
-
componentStates: {}
|
|
472
|
-
});
|
|
473
|
-
this._context.state.componentStates ??= {};
|
|
456
|
+
this._context.state = ((await this._stateStorage.load(this)) ?? {});
|
|
474
457
|
this._context.stateDirty = false;
|
|
475
458
|
return true;
|
|
476
459
|
}
|
|
@@ -514,19 +497,13 @@ class EngineCore {
|
|
|
514
497
|
this.logInfo(core.I18n.formatMessage(`${EngineCore._CLASS_NAME_CAMEL_CASE}.bootstrapping`, {
|
|
515
498
|
element: instanceName
|
|
516
499
|
}));
|
|
517
|
-
const
|
|
518
|
-
const lastState = core.ObjectHelper.clone(componentState);
|
|
519
|
-
const bootstrapSuccess = await instance.component.bootstrap(this._loggerTypeName, componentState);
|
|
500
|
+
const bootstrapSuccess = await instance.component.bootstrap(this._loggerTypeName);
|
|
520
501
|
// If the bootstrap method failed then throw an error
|
|
521
502
|
if (!bootstrapSuccess) {
|
|
522
503
|
throw new core.GeneralError(EngineCore._CLASS_NAME, "bootstrapFailed", {
|
|
523
504
|
component: `${instance.component.CLASS_NAME}:${instance.instanceType}`
|
|
524
505
|
});
|
|
525
506
|
}
|
|
526
|
-
if (!core.ObjectHelper.equal(lastState, componentState)) {
|
|
527
|
-
this._context.state.componentStates[instanceName] = componentState;
|
|
528
|
-
this._context.stateDirty = true;
|
|
529
|
-
}
|
|
530
507
|
}
|
|
531
508
|
}
|
|
532
509
|
// Now perform any custom bootstrap operations
|
package/dist/esm/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { I18n, StringHelper, Is,
|
|
1
|
+
import { I18n, StringHelper, Is, BaseError, GeneralError, ErrorHelper, Guards, ComponentFactory } from '@twin.org/core';
|
|
2
2
|
import { EntitySchemaFactory } from '@twin.org/entity';
|
|
3
3
|
import { ConsoleLoggingConnector } from '@twin.org/logging-connector-console';
|
|
4
4
|
import { SilentLoggingConnector, LoggingConnectorFactory } from '@twin.org/logging-models';
|
|
@@ -144,7 +144,7 @@ class EngineCore {
|
|
|
144
144
|
config: options.config,
|
|
145
145
|
registeredInstances: {},
|
|
146
146
|
componentInstances: [],
|
|
147
|
-
state: {
|
|
147
|
+
state: {},
|
|
148
148
|
stateDirty: false
|
|
149
149
|
};
|
|
150
150
|
this._stateStorage = options.stateStorage;
|
|
@@ -194,17 +194,10 @@ class EngineCore {
|
|
|
194
194
|
this.logInfo(I18n.formatMessage(`${EngineCore._CLASS_NAME_CAMEL_CASE}.componentsStarting`));
|
|
195
195
|
for (const instance of this._context.componentInstances) {
|
|
196
196
|
if (Is.function(instance.component.start)) {
|
|
197
|
-
const instanceName = this.getInstanceName(instance);
|
|
198
197
|
this.logInfo(I18n.formatMessage(`${EngineCore._CLASS_NAME_CAMEL_CASE}.componentStarting`, {
|
|
199
198
|
element: instance.instanceType
|
|
200
199
|
}));
|
|
201
|
-
|
|
202
|
-
const lastState = ObjectHelper.clone(componentState);
|
|
203
|
-
await instance.component.start(this._context.state.nodeIdentity, this._loggerTypeName, componentState);
|
|
204
|
-
if (!ObjectHelper.equal(lastState, componentState)) {
|
|
205
|
-
this._context.state.componentStates[instanceName] = componentState;
|
|
206
|
-
this._context.stateDirty = true;
|
|
207
|
-
}
|
|
200
|
+
await instance.component.start(this._context.state.nodeIdentity, this._loggerTypeName);
|
|
208
201
|
}
|
|
209
202
|
}
|
|
210
203
|
this.logInfo(I18n.formatMessage(`${EngineCore._CLASS_NAME_CAMEL_CASE}.componentsComplete`));
|
|
@@ -232,18 +225,11 @@ class EngineCore {
|
|
|
232
225
|
this.logInfo(I18n.formatMessage(`${EngineCore._CLASS_NAME_CAMEL_CASE}.componentsStopping`));
|
|
233
226
|
for (const instance of this._context.componentInstances) {
|
|
234
227
|
if (Is.function(instance.component.stop)) {
|
|
235
|
-
const instanceName = this.getInstanceName(instance);
|
|
236
|
-
const componentState = this._context.state.componentStates[instanceName] ?? {};
|
|
237
|
-
const lastState = ObjectHelper.clone(componentState);
|
|
238
228
|
this.logInfo(I18n.formatMessage(`${EngineCore._CLASS_NAME_CAMEL_CASE}.componentStopping`, {
|
|
239
229
|
element: instance.instanceType
|
|
240
230
|
}));
|
|
241
231
|
try {
|
|
242
|
-
await instance.component.stop(this._context.state.nodeIdentity, this._loggerTypeName
|
|
243
|
-
if (!ObjectHelper.equal(lastState, componentState)) {
|
|
244
|
-
this._context.state.componentStates[instanceName] = componentState;
|
|
245
|
-
this._context.stateDirty = true;
|
|
246
|
-
}
|
|
232
|
+
await instance.component.stop(this._context.state.nodeIdentity, this._loggerTypeName);
|
|
247
233
|
}
|
|
248
234
|
catch (err) {
|
|
249
235
|
this.logError(new GeneralError(EngineCore._CLASS_NAME, "componentStopFailed", {
|
|
@@ -383,7 +369,7 @@ class EngineCore {
|
|
|
383
369
|
config: cloneData.config,
|
|
384
370
|
registeredInstances: {},
|
|
385
371
|
componentInstances: [],
|
|
386
|
-
state: {
|
|
372
|
+
state: {},
|
|
387
373
|
stateDirty: false
|
|
388
374
|
};
|
|
389
375
|
this._typeInitialisers = cloneData.typeInitialisers;
|
|
@@ -465,10 +451,7 @@ class EngineCore {
|
|
|
465
451
|
async stateLoad() {
|
|
466
452
|
if (this._stateStorage) {
|
|
467
453
|
try {
|
|
468
|
-
this._context.state = ((await this._stateStorage.load(this)) ?? {
|
|
469
|
-
componentStates: {}
|
|
470
|
-
});
|
|
471
|
-
this._context.state.componentStates ??= {};
|
|
454
|
+
this._context.state = ((await this._stateStorage.load(this)) ?? {});
|
|
472
455
|
this._context.stateDirty = false;
|
|
473
456
|
return true;
|
|
474
457
|
}
|
|
@@ -512,19 +495,13 @@ class EngineCore {
|
|
|
512
495
|
this.logInfo(I18n.formatMessage(`${EngineCore._CLASS_NAME_CAMEL_CASE}.bootstrapping`, {
|
|
513
496
|
element: instanceName
|
|
514
497
|
}));
|
|
515
|
-
const
|
|
516
|
-
const lastState = ObjectHelper.clone(componentState);
|
|
517
|
-
const bootstrapSuccess = await instance.component.bootstrap(this._loggerTypeName, componentState);
|
|
498
|
+
const bootstrapSuccess = await instance.component.bootstrap(this._loggerTypeName);
|
|
518
499
|
// If the bootstrap method failed then throw an error
|
|
519
500
|
if (!bootstrapSuccess) {
|
|
520
501
|
throw new GeneralError(EngineCore._CLASS_NAME, "bootstrapFailed", {
|
|
521
502
|
component: `${instance.component.CLASS_NAME}:${instance.instanceType}`
|
|
522
503
|
});
|
|
523
504
|
}
|
|
524
|
-
if (!ObjectHelper.equal(lastState, componentState)) {
|
|
525
|
-
this._context.state.componentStates[instanceName] = componentState;
|
|
526
|
-
this._context.stateDirty = true;
|
|
527
|
-
}
|
|
528
505
|
}
|
|
529
506
|
}
|
|
530
507
|
// Now perform any custom bootstrap operations
|
package/docs/changelog.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# @twin.org/engine-core - Changelog
|
|
2
2
|
|
|
3
|
+
## [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
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* remove unused component states ([d56d648](https://github.com/twinfoundation/engine/commit/d56d6486119ea8b8501a33f9e3a3101a08b826ed))
|
|
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.6 to 0.0.2-next.7
|
|
16
|
+
|
|
3
17
|
## [0.0.2-next.6](https://github.com/twinfoundation/engine/compare/engine-core-v0.0.2-next.5...engine-core-v0.0.2-next.6) (2025-08-21)
|
|
4
18
|
|
|
5
19
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@twin.org/engine-core",
|
|
3
|
-
"version": "0.0.2-next.
|
|
3
|
+
"version": "0.0.2-next.7",
|
|
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.
|
|
20
|
+
"@twin.org/engine-models": "0.0.2-next.7",
|
|
21
21
|
"@twin.org/entity": "next",
|
|
22
22
|
"@twin.org/logging-connector-console": "next",
|
|
23
23
|
"@twin.org/logging-models": "next",
|