@twin.org/engine-core 0.0.2-next.10 → 0.0.2-next.12
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 +46 -1
- package/dist/esm/index.mjs +46 -2
- package/dist/types/index.d.ts +1 -0
- package/dist/types/utils/engineModuleHelper.d.ts +17 -0
- package/docs/changelog.md +28 -0
- package/docs/reference/classes/EngineModuleHelper.md +55 -0
- package/docs/reference/index.md +1 -0
- package/locales/en.json +3 -0
- package/package.json +2 -2
package/dist/cjs/index.cjs
CHANGED
|
@@ -420,7 +420,7 @@ class EngineCore {
|
|
|
420
420
|
if (core.Is.arrayValue(typeConfig)) {
|
|
421
421
|
const instanceMethod = await modules.ModuleHelper.getModuleEntry(module, method);
|
|
422
422
|
for (let i = 0; i < typeConfig.length; i++) {
|
|
423
|
-
const instanceType = instanceMethod(this, this._context, typeConfig[i], typeConfig[i].overrideInstanceType);
|
|
423
|
+
const instanceType = await instanceMethod(this, this._context, typeConfig[i], typeConfig[i].overrideInstanceType);
|
|
424
424
|
if (core.Is.stringValue(instanceType)) {
|
|
425
425
|
this._context.registeredInstances[typeKey] ??= [];
|
|
426
426
|
if (typeConfig[i].isDefault ?? false) {
|
|
@@ -644,6 +644,51 @@ class FileStateStorage {
|
|
|
644
644
|
}
|
|
645
645
|
}
|
|
646
646
|
|
|
647
|
+
// Copyright 2024 IOTA Stiftung.
|
|
648
|
+
// SPDX-License-Identifier: Apache-2.0.
|
|
649
|
+
/**
|
|
650
|
+
* Helper class for engine modules.
|
|
651
|
+
*/
|
|
652
|
+
class EngineModuleHelper {
|
|
653
|
+
/**
|
|
654
|
+
* Runtime name for the class.
|
|
655
|
+
*/
|
|
656
|
+
static CLASS_NAME = "EngineModuleHelper";
|
|
657
|
+
/**
|
|
658
|
+
* Loads an engine component and constructs it with the relevant dependencies and configuration.
|
|
659
|
+
* @param engineCore The engine core.
|
|
660
|
+
* @param engineModuleConfig The configuration for the module.
|
|
661
|
+
* @returns The instantiated component.
|
|
662
|
+
*/
|
|
663
|
+
static async loadComponent(engineCore, engineModuleConfig) {
|
|
664
|
+
const moduleClass = await modules.ModuleHelper.getModuleEntry(engineModuleConfig.moduleName, engineModuleConfig.className);
|
|
665
|
+
const isClass = core.Is.class(moduleClass);
|
|
666
|
+
if (!isClass) {
|
|
667
|
+
throw new core.GeneralError(EngineModuleHelper.CLASS_NAME, "moduleNotClass", {
|
|
668
|
+
moduleName: engineModuleConfig.moduleName,
|
|
669
|
+
className: engineModuleConfig.className
|
|
670
|
+
});
|
|
671
|
+
}
|
|
672
|
+
const constructorOptions = {};
|
|
673
|
+
if (core.Is.arrayValue(engineModuleConfig.dependencies)) {
|
|
674
|
+
for (const dependency of engineModuleConfig.dependencies) {
|
|
675
|
+
if (dependency.isOptional ?? false) {
|
|
676
|
+
constructorOptions[dependency.propertyName] = engineCore.getRegisteredInstanceType(dependency.componentName, dependency.features);
|
|
677
|
+
}
|
|
678
|
+
else {
|
|
679
|
+
constructorOptions[dependency.propertyName] =
|
|
680
|
+
engineCore.getRegisteredInstanceTypeOptional(dependency.componentName, dependency.features);
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
}
|
|
684
|
+
if (core.Is.object(engineModuleConfig.config)) {
|
|
685
|
+
constructorOptions.config = engineModuleConfig.config;
|
|
686
|
+
}
|
|
687
|
+
return new moduleClass(constructorOptions);
|
|
688
|
+
}
|
|
689
|
+
}
|
|
690
|
+
|
|
647
691
|
exports.EngineCore = EngineCore;
|
|
692
|
+
exports.EngineModuleHelper = EngineModuleHelper;
|
|
648
693
|
exports.FileStateStorage = FileStateStorage;
|
|
649
694
|
exports.MemoryStateStorage = MemoryStateStorage;
|
package/dist/esm/index.mjs
CHANGED
|
@@ -418,7 +418,7 @@ class EngineCore {
|
|
|
418
418
|
if (Is.arrayValue(typeConfig)) {
|
|
419
419
|
const instanceMethod = await ModuleHelper.getModuleEntry(module, method);
|
|
420
420
|
for (let i = 0; i < typeConfig.length; i++) {
|
|
421
|
-
const instanceType = instanceMethod(this, this._context, typeConfig[i], typeConfig[i].overrideInstanceType);
|
|
421
|
+
const instanceType = await instanceMethod(this, this._context, typeConfig[i], typeConfig[i].overrideInstanceType);
|
|
422
422
|
if (Is.stringValue(instanceType)) {
|
|
423
423
|
this._context.registeredInstances[typeKey] ??= [];
|
|
424
424
|
if (typeConfig[i].isDefault ?? false) {
|
|
@@ -642,4 +642,48 @@ class FileStateStorage {
|
|
|
642
642
|
}
|
|
643
643
|
}
|
|
644
644
|
|
|
645
|
-
|
|
645
|
+
// Copyright 2024 IOTA Stiftung.
|
|
646
|
+
// SPDX-License-Identifier: Apache-2.0.
|
|
647
|
+
/**
|
|
648
|
+
* Helper class for engine modules.
|
|
649
|
+
*/
|
|
650
|
+
class EngineModuleHelper {
|
|
651
|
+
/**
|
|
652
|
+
* Runtime name for the class.
|
|
653
|
+
*/
|
|
654
|
+
static CLASS_NAME = "EngineModuleHelper";
|
|
655
|
+
/**
|
|
656
|
+
* Loads an engine component and constructs it with the relevant dependencies and configuration.
|
|
657
|
+
* @param engineCore The engine core.
|
|
658
|
+
* @param engineModuleConfig The configuration for the module.
|
|
659
|
+
* @returns The instantiated component.
|
|
660
|
+
*/
|
|
661
|
+
static async loadComponent(engineCore, engineModuleConfig) {
|
|
662
|
+
const moduleClass = await ModuleHelper.getModuleEntry(engineModuleConfig.moduleName, engineModuleConfig.className);
|
|
663
|
+
const isClass = Is.class(moduleClass);
|
|
664
|
+
if (!isClass) {
|
|
665
|
+
throw new GeneralError(EngineModuleHelper.CLASS_NAME, "moduleNotClass", {
|
|
666
|
+
moduleName: engineModuleConfig.moduleName,
|
|
667
|
+
className: engineModuleConfig.className
|
|
668
|
+
});
|
|
669
|
+
}
|
|
670
|
+
const constructorOptions = {};
|
|
671
|
+
if (Is.arrayValue(engineModuleConfig.dependencies)) {
|
|
672
|
+
for (const dependency of engineModuleConfig.dependencies) {
|
|
673
|
+
if (dependency.isOptional ?? false) {
|
|
674
|
+
constructorOptions[dependency.propertyName] = engineCore.getRegisteredInstanceType(dependency.componentName, dependency.features);
|
|
675
|
+
}
|
|
676
|
+
else {
|
|
677
|
+
constructorOptions[dependency.propertyName] =
|
|
678
|
+
engineCore.getRegisteredInstanceTypeOptional(dependency.componentName, dependency.features);
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
if (Is.object(engineModuleConfig.config)) {
|
|
683
|
+
constructorOptions.config = engineModuleConfig.config;
|
|
684
|
+
}
|
|
685
|
+
return new moduleClass(constructorOptions);
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
export { EngineCore, EngineModuleHelper, FileStateStorage, MemoryStateStorage };
|
package/dist/types/index.d.ts
CHANGED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { IEngineCore, IEngineModuleConfig } from "@twin.org/engine-models";
|
|
2
|
+
/**
|
|
3
|
+
* Helper class for engine modules.
|
|
4
|
+
*/
|
|
5
|
+
export declare class EngineModuleHelper {
|
|
6
|
+
/**
|
|
7
|
+
* Runtime name for the class.
|
|
8
|
+
*/
|
|
9
|
+
static readonly CLASS_NAME: string;
|
|
10
|
+
/**
|
|
11
|
+
* Loads an engine component and constructs it with the relevant dependencies and configuration.
|
|
12
|
+
* @param engineCore The engine core.
|
|
13
|
+
* @param engineModuleConfig The configuration for the module.
|
|
14
|
+
* @returns The instantiated component.
|
|
15
|
+
*/
|
|
16
|
+
static loadComponent<T>(engineCore: IEngineCore, engineModuleConfig: IEngineModuleConfig): Promise<T>;
|
|
17
|
+
}
|
package/docs/changelog.md
CHANGED
|
@@ -1,5 +1,33 @@
|
|
|
1
1
|
# @twin.org/engine-core - Changelog
|
|
2
2
|
|
|
3
|
+
## [0.0.2-next.12](https://github.com/twinfoundation/engine/compare/engine-core-v0.0.2-next.11...engine-core-v0.0.2-next.12) (2025-09-05)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* add rights management negotiation ([84ef46b](https://github.com/twinfoundation/engine/commit/84ef46bff110611a19512793425c8c873ee2a590))
|
|
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.11 to 0.0.2-next.12
|
|
16
|
+
|
|
17
|
+
## [0.0.2-next.11](https://github.com/twinfoundation/engine/compare/engine-core-v0.0.2-next.10...engine-core-v0.0.2-next.11) (2025-08-29)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### Features
|
|
21
|
+
|
|
22
|
+
* eslint migration to flat config ([6b978da](https://github.com/twinfoundation/engine/commit/6b978daf777a615d7758b63c3df57d5a376f6dfb))
|
|
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.10 to 0.0.2-next.11
|
|
30
|
+
|
|
3
31
|
## [0.0.2-next.10](https://github.com/twinfoundation/engine/compare/engine-core-v0.0.2-next.9...engine-core-v0.0.2-next.10) (2025-08-26)
|
|
4
32
|
|
|
5
33
|
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# Class: EngineModuleHelper
|
|
2
|
+
|
|
3
|
+
Helper class for engine modules.
|
|
4
|
+
|
|
5
|
+
## Constructors
|
|
6
|
+
|
|
7
|
+
### Constructor
|
|
8
|
+
|
|
9
|
+
> **new EngineModuleHelper**(): `EngineModuleHelper`
|
|
10
|
+
|
|
11
|
+
#### Returns
|
|
12
|
+
|
|
13
|
+
`EngineModuleHelper`
|
|
14
|
+
|
|
15
|
+
## Properties
|
|
16
|
+
|
|
17
|
+
### CLASS\_NAME
|
|
18
|
+
|
|
19
|
+
> `readonly` `static` **CLASS\_NAME**: `string`
|
|
20
|
+
|
|
21
|
+
Runtime name for the class.
|
|
22
|
+
|
|
23
|
+
## Methods
|
|
24
|
+
|
|
25
|
+
### loadComponent()
|
|
26
|
+
|
|
27
|
+
> `static` **loadComponent**\<`T`\>(`engineCore`, `engineModuleConfig`): `Promise`\<`T`\>
|
|
28
|
+
|
|
29
|
+
Loads an engine component and constructs it with the relevant dependencies and configuration.
|
|
30
|
+
|
|
31
|
+
#### Type Parameters
|
|
32
|
+
|
|
33
|
+
##### T
|
|
34
|
+
|
|
35
|
+
`T`
|
|
36
|
+
|
|
37
|
+
#### Parameters
|
|
38
|
+
|
|
39
|
+
##### engineCore
|
|
40
|
+
|
|
41
|
+
`IEngineCore`
|
|
42
|
+
|
|
43
|
+
The engine core.
|
|
44
|
+
|
|
45
|
+
##### engineModuleConfig
|
|
46
|
+
|
|
47
|
+
`IEngineModuleConfig`
|
|
48
|
+
|
|
49
|
+
The configuration for the module.
|
|
50
|
+
|
|
51
|
+
#### Returns
|
|
52
|
+
|
|
53
|
+
`Promise`\<`T`\>
|
|
54
|
+
|
|
55
|
+
The instantiated component.
|
package/docs/reference/index.md
CHANGED
package/locales/en.json
CHANGED
|
@@ -12,6 +12,9 @@
|
|
|
12
12
|
"fileStateStorage": {
|
|
13
13
|
"failedLoading": "Failed to load file state storage from \"{filename}\"",
|
|
14
14
|
"failedSaving": "Failed to save file state storage to \"{filename}\""
|
|
15
|
+
},
|
|
16
|
+
"engineModuleHelper": {
|
|
17
|
+
"moduleNotClass": "The module \"{moduleName}\" does not export a class \"{className}\""
|
|
15
18
|
}
|
|
16
19
|
},
|
|
17
20
|
"engineCore": {
|
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.12",
|
|
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.12",
|
|
21
21
|
"@twin.org/entity": "next",
|
|
22
22
|
"@twin.org/logging-connector-console": "next",
|
|
23
23
|
"@twin.org/logging-models": "next",
|