@twin.org/modules 0.0.2-next.8 → 0.0.3-next.1
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/{esm/index.mjs → es/helpers/moduleHelper.js} +6 -7
- package/dist/es/helpers/moduleHelper.js.map +1 -0
- package/dist/es/index.js +4 -0
- package/dist/es/index.js.map +1 -0
- package/dist/types/helpers/moduleHelper.d.ts +1 -1
- package/dist/types/index.d.ts +1 -1
- package/docs/changelog.md +284 -0
- package/docs/reference/classes/ModuleHelper.md +3 -3
- package/package.json +22 -10
- package/dist/cjs/index.cjs +0 -195
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import { Worker } from 'node:worker_threads';
|
|
2
|
-
import { SharedStore, Is, GeneralError, BaseError } from '@twin.org/core';
|
|
3
|
-
|
|
4
1
|
// Copyright 2024 IOTA Stiftung.
|
|
5
2
|
// SPDX-License-Identifier: Apache-2.0.
|
|
3
|
+
import { Worker } from "node:worker_threads";
|
|
4
|
+
import { BaseError, GeneralError, Is, SharedStore } from "@twin.org/core";
|
|
6
5
|
/**
|
|
7
6
|
* Helper functions for modules.
|
|
8
7
|
*/
|
|
9
|
-
class ModuleHelper {
|
|
8
|
+
export class ModuleHelper {
|
|
10
9
|
/**
|
|
11
10
|
* Runtime name for the class.
|
|
12
11
|
*/
|
|
@@ -30,7 +29,7 @@ class ModuleHelper {
|
|
|
30
29
|
try {
|
|
31
30
|
let useDefault = true;
|
|
32
31
|
const overrideImport = SharedStore.get("overrideImport");
|
|
33
|
-
if (
|
|
32
|
+
if (Is.function(overrideImport)) {
|
|
34
33
|
const overrideResult = await overrideImport(module);
|
|
35
34
|
moduleInstance = overrideResult.module;
|
|
36
35
|
useDefault = overrideResult.useDefault;
|
|
@@ -61,6 +60,7 @@ class ModuleHelper {
|
|
|
61
60
|
* @returns The result of the method execution.
|
|
62
61
|
* @throws GeneralError if executing the module entry failed.
|
|
63
62
|
*/
|
|
63
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
64
64
|
static async getModuleMethod(module, method) {
|
|
65
65
|
const methodParts = method.split(".");
|
|
66
66
|
if (methodParts.length === 2) {
|
|
@@ -189,5 +189,4 @@ class ModuleHelper {
|
|
|
189
189
|
return name.startsWith(".");
|
|
190
190
|
}
|
|
191
191
|
}
|
|
192
|
-
|
|
193
|
-
export { ModuleHelper };
|
|
192
|
+
//# sourceMappingURL=moduleHelper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"moduleHelper.js","sourceRoot":"","sources":["../../../src/helpers/moduleHelper.ts"],"names":[],"mappings":"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","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { Worker } from \"node:worker_threads\";\nimport { BaseError, GeneralError, Is, SharedStore } from \"@twin.org/core\";\nimport { nameof } from \"@twin.org/nameof\";\n\n/**\n * Helper functions for modules.\n */\nexport class ModuleHelper {\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<ModuleHelper>();\n\n\t/**\n\t * Override the import function for modules.\n\t * @param overrideImport The override import function.\n\t */\n\tpublic static overrideImport(\n\t\toverrideImport: (moduleName: string) => Promise<{ module?: unknown; useDefault: boolean }>\n\t): void {\n\t\tSharedStore.set(\"overrideImport\", overrideImport);\n\t}\n\n\t/**\n\t * Get the module entry.\n\t * @param module The module.\n\t * @param entry The entry to get from the module.\n\t * @returns The entry from the module.\n\t * @throws GeneralError if getting the module entry failed.\n\t */\n\tpublic static async getModuleEntry<T>(module: string, entry: string): Promise<T> {\n\t\tlet moduleInstance;\n\n\t\ttry {\n\t\t\tlet useDefault = true;\n\n\t\t\tconst overrideImport =\n\t\t\t\tSharedStore.get<(moduleName: string) => Promise<{ module?: unknown; useDefault: boolean }>>(\n\t\t\t\t\t\"overrideImport\"\n\t\t\t\t);\n\n\t\t\tif (Is.function(overrideImport)) {\n\t\t\t\tconst overrideResult = await overrideImport(module);\n\n\t\t\t\tmoduleInstance = overrideResult.module;\n\t\t\t\tuseDefault = overrideResult.useDefault;\n\t\t\t}\n\n\t\t\tif (useDefault) {\n\t\t\t\tmoduleInstance = await import(module);\n\t\t\t}\n\t\t} catch (err) {\n\t\t\tthrow new GeneralError(\n\t\t\t\tModuleHelper.CLASS_NAME,\n\t\t\t\t\"moduleNotFound\",\n\t\t\t\t{\n\t\t\t\t\tmodule,\n\t\t\t\t\tentry\n\t\t\t\t},\n\t\t\t\tBaseError.fromError(err)\n\t\t\t);\n\t\t}\n\n\t\tconst moduleEntry = moduleInstance?.[entry];\n\n\t\tif (Is.empty(moduleEntry)) {\n\t\t\tthrow new GeneralError(ModuleHelper.CLASS_NAME, \"entryNotFound\", {\n\t\t\t\tmodule,\n\t\t\t\tentry\n\t\t\t});\n\t\t}\n\n\t\treturn moduleEntry as T;\n\t}\n\n\t/**\n\t * Get the method from a module.\n\t * @param module The module.\n\t * @param method The method to execute from the module, use dot notation to get a static class method.\n\t * @returns The result of the method execution.\n\t * @throws GeneralError if executing the module entry failed.\n\t */\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tpublic static async getModuleMethod<T extends (...args: any[]) => any = (...args: any[]) => any>(\n\t\tmodule: string,\n\t\tmethod: string\n\t): Promise<T> {\n\t\tconst methodParts = method.split(\".\");\n\n\t\tif (methodParts.length === 2) {\n\t\t\tconst moduleEntry = await ModuleHelper.getModuleEntry<{\n\t\t\t\t[id: string]: T;\n\t\t\t}>(module, methodParts[0]);\n\n\t\t\tif (Is.function<T>(moduleEntry[methodParts[1]])) {\n\t\t\t\treturn moduleEntry[methodParts[1]];\n\t\t\t}\n\t\t\tthrow new GeneralError(ModuleHelper.CLASS_NAME, \"notFunction\", {\n\t\t\t\tmodule,\n\t\t\t\tentry: method\n\t\t\t});\n\t\t}\n\n\t\tconst moduleEntry = await ModuleHelper.getModuleEntry<T>(module, methodParts[0]);\n\n\t\tif (Is.function<T>(moduleEntry)) {\n\t\t\treturn moduleEntry;\n\t\t}\n\n\t\tthrow new GeneralError(ModuleHelper.CLASS_NAME, \"notFunction\", {\n\t\t\tmodule,\n\t\t\tentry: method\n\t\t});\n\t}\n\n\t/**\n\t * Execute the method in the module.\n\t * @param module The module.\n\t * @param method The method to execute from the module.\n\t * @param args The arguments to pass to the method.\n\t * @returns The result of the method execution.\n\t * @throws GeneralError if executing the module entry failed.\n\t */\n\tpublic static async execModuleMethod<T>(\n\t\tmodule: string,\n\t\tmethod: string,\n\t\targs?: unknown[]\n\t): Promise<T> {\n\t\tconst moduleMethod = await ModuleHelper.getModuleMethod<(...args: unknown[]) => T>(\n\t\t\tmodule,\n\t\t\tmethod\n\t\t);\n\n\t\treturn moduleMethod(...(args ?? []));\n\t}\n\n\t/**\n\t * Execute the method in the module in a thread.\n\t * @param module The module.\n\t * @param method The method to execute from the module.\n\t * @param args The arguments to pass to the method.\n\t * @returns The result of the method execution.\n\t * @throws GeneralError if executing the module entry failed.\n\t */\n\tpublic static async execModuleMethodThread<T>(\n\t\tmodule: string,\n\t\tmethod: string,\n\t\targs?: unknown[]\n\t): Promise<T> {\n\t\treturn new Promise((resolve, reject) => {\n\t\t\tconst worker = new Worker(\n\t\t\t\t`(async () => {\n\ttry {\n\t\tconst { workerData, parentPort } = await import('node:worker_threads');\n\n\t\tfunction rejectError(errorType, cause) {\n\t\t\tparentPort.postMessage({ errorType, cause });\n\t\t}\n\n\t\tasync function executeMethod(method) {\n\t\t\ttry {\n\t\t\t\tconst result = await method(...(args ?? []));\n\n\t\t\t\tparentPort.postMessage({ result });\n\t\t\t} catch (err) {\n\t\t\t\trejectError('resultError', err);\n\t\t\t}\n\t\t}\n\n\t\tconst { module, method, args } = workerData;\n\n\t\tconst moduleInstance = await import(module);\n\t\tconst methodParts = method.split('.');\n\t\tconst moduleEntry = moduleInstance[methodParts[0]];\n\n\t\tif (moduleEntry === undefined) {\n\t\t\trejectError('entryNotFound');\n\t\t} else if (methodParts.length === 2) {\n\t\t\tconst moduleMethod = moduleEntry[methodParts[1]];\n\t\t\tif (typeof moduleMethod === 'function') {\n\t\t\t\tawait executeMethod(moduleMethod, args);\n\t\t\t} else {\n\t\t\t\trejectError('notFunction');\n\t\t\t}\n\t\t} else if (typeof moduleEntry === 'function') {\n\t\t\tawait executeMethod(moduleEntry, args);\n\t\t} else {\n\t\t\trejectError('notFunction');\n\t\t}\n\t} catch (err) {\n\t\trejectError('moduleNotFound', err);\n\t}\n})();\n\t\t\t`,\n\t\t\t\t{ eval: true, workerData: { module, method, args: args ?? [] } }\n\t\t\t);\n\n\t\t\tworker.on(\"message\", msg => {\n\t\t\t\tif (Is.stringValue(msg.errorType)) {\n\t\t\t\t\treject(\n\t\t\t\t\t\tnew GeneralError(\n\t\t\t\t\t\t\tModuleHelper.CLASS_NAME,\n\t\t\t\t\t\t\tmsg.errorType,\n\t\t\t\t\t\t\t{ module, entry: method },\n\t\t\t\t\t\t\tmsg.cause\n\t\t\t\t\t\t)\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\tresolve(msg.result);\n\t\t\t\t}\n\t\t\t});\n\n\t\t\tworker.on(\"error\", err => {\n\t\t\t\treject(\n\t\t\t\t\tnew GeneralError(\n\t\t\t\t\t\tModuleHelper.CLASS_NAME,\n\t\t\t\t\t\t\"workerException\",\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tmodule,\n\t\t\t\t\t\t\tentry: method\n\t\t\t\t\t\t},\n\t\t\t\t\t\terr\n\t\t\t\t\t)\n\t\t\t\t);\n\t\t\t});\n\n\t\t\tworker.on(\"exit\", code => {\n\t\t\t\tif (code === 1) {\n\t\t\t\t\treject(\n\t\t\t\t\t\tnew GeneralError(ModuleHelper.CLASS_NAME, \"workerFailed\", {\n\t\t\t\t\t\t\tmodule,\n\t\t\t\t\t\t\tentry: method,\n\t\t\t\t\t\t\texitCode: code\n\t\t\t\t\t\t})\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t});\n\t\t});\n\t}\n\n\t/**\n\t * Check if a module is a local module.\n\t * @param name The name of the module.\n\t * @returns True if the module is local, false otherwise.\n\t */\n\tpublic static isLocalModule(name: string): boolean {\n\t\treturn name.startsWith(\".\") || name.startsWith(\"/\");\n\t}\n\n\t/**\n\t * Check if a module is a relative module.\n\t * @param name The name of the module.\n\t * @returns True if the module is relative, false otherwise.\n\t */\n\tpublic static isRelativeModule(name: string): boolean {\n\t\treturn name.startsWith(\".\");\n\t}\n}\n"]}
|
package/dist/es/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,cAAc,2BAA2B,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nexport * from \"./helpers/moduleHelper.js\";\n"]}
|
|
@@ -29,7 +29,7 @@ export declare class ModuleHelper {
|
|
|
29
29
|
* @returns The result of the method execution.
|
|
30
30
|
* @throws GeneralError if executing the module entry failed.
|
|
31
31
|
*/
|
|
32
|
-
static getModuleMethod<T>(module: string, method: string): Promise<
|
|
32
|
+
static getModuleMethod<T extends (...args: any[]) => any = (...args: any[]) => any>(module: string, method: string): Promise<T>;
|
|
33
33
|
/**
|
|
34
34
|
* Execute the method in the module.
|
|
35
35
|
* @param module The module.
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from "./helpers/moduleHelper";
|
|
1
|
+
export * from "./helpers/moduleHelper.js";
|
package/docs/changelog.md
CHANGED
|
@@ -1,5 +1,289 @@
|
|
|
1
1
|
# @twin.org/modules - Changelog
|
|
2
2
|
|
|
3
|
+
## [0.0.3-next.1](https://github.com/twinfoundation/framework/compare/modules-v0.0.3-next.0...modules-v0.0.3-next.1) (2025-11-10)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* add context id features ([#206](https://github.com/twinfoundation/framework/issues/206)) ([ef0d4ee](https://github.com/twinfoundation/framework/commit/ef0d4ee11a4f5fc6cc6f52a4958ce905c04ee13b))
|
|
9
|
+
* add guards arrayEndsWith and arrayStartsWith ([95d875e](https://github.com/twinfoundation/framework/commit/95d875ec8ccb4713c145fdde941d4cfedcec2ed3))
|
|
10
|
+
* eslint migration to flat config ([74427d7](https://github.com/twinfoundation/framework/commit/74427d78d342167f7850e49ab87269326355befe))
|
|
11
|
+
* improve async pattern and error handling ([aaa1f68](https://github.com/twinfoundation/framework/commit/aaa1f6879d60adf04b78b0c1bbbec50f2873f020))
|
|
12
|
+
* improve Is.function and ModuleHelper.getModuleMethod signatures ([ecf968b](https://github.com/twinfoundation/framework/commit/ecf968b02934b3676be4bf7cd2d1e7f8e7af6ce2))
|
|
13
|
+
* locales validation ([#197](https://github.com/twinfoundation/framework/issues/197)) ([55fdadb](https://github.com/twinfoundation/framework/commit/55fdadb13595ce0047f787bd1d4135d429a99f12))
|
|
14
|
+
* nodeIdentity optional in IComponent methods ([c78dc17](https://github.com/twinfoundation/framework/commit/c78dc17f4357d3e1ae40e415f468d3eae13e81f4))
|
|
15
|
+
* provide module helper override ([e998a64](https://github.com/twinfoundation/framework/commit/e998a64842cfd18693a14444be33b084fef2bb90))
|
|
16
|
+
* relocate core packages from tools ([bcab8f3](https://github.com/twinfoundation/framework/commit/bcab8f3160442ea4fcaf442947462504f3d6a17d))
|
|
17
|
+
* update dependencies ([f3bd015](https://github.com/twinfoundation/framework/commit/f3bd015efd169196b7e0335f5cab876ba6ca1d75))
|
|
18
|
+
* use cause instead of inner for errors ([1f4acc4](https://github.com/twinfoundation/framework/commit/1f4acc4d7a6b71a134d9547da9bf40de1e1e49da))
|
|
19
|
+
* use new shared store mechanism ([#131](https://github.com/twinfoundation/framework/issues/131)) ([934385b](https://github.com/twinfoundation/framework/commit/934385b2fbaf9f5c00a505ebf9d093bd5a425f55))
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
### Dependencies
|
|
23
|
+
|
|
24
|
+
* The following workspace dependencies were updated
|
|
25
|
+
* dependencies
|
|
26
|
+
* @twin.org/core bumped from 0.0.3-next.0 to 0.0.3-next.1
|
|
27
|
+
* @twin.org/nameof bumped from 0.0.3-next.0 to 0.0.3-next.1
|
|
28
|
+
* devDependencies
|
|
29
|
+
* @twin.org/nameof-transformer bumped from 0.0.3-next.0 to 0.0.3-next.1
|
|
30
|
+
* @twin.org/nameof-vitest-plugin bumped from 0.0.3-next.0 to 0.0.3-next.1
|
|
31
|
+
* @twin.org/validate-locales bumped from 0.0.3-next.0 to 0.0.3-next.1
|
|
32
|
+
|
|
33
|
+
## [0.0.2-next.22](https://github.com/twinfoundation/framework/compare/modules-v0.0.2-next.21...modules-v0.0.2-next.22) (2025-10-10)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
### Miscellaneous Chores
|
|
37
|
+
|
|
38
|
+
* **modules:** Synchronize repo versions
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
### Dependencies
|
|
42
|
+
|
|
43
|
+
* The following workspace dependencies were updated
|
|
44
|
+
* dependencies
|
|
45
|
+
* @twin.org/core bumped from 0.0.2-next.21 to 0.0.2-next.22
|
|
46
|
+
* @twin.org/nameof bumped from 0.0.2-next.21 to 0.0.2-next.22
|
|
47
|
+
* devDependencies
|
|
48
|
+
* @twin.org/nameof-transformer bumped from 0.0.2-next.21 to 0.0.2-next.22
|
|
49
|
+
* @twin.org/nameof-vitest-plugin bumped from 0.0.2-next.21 to 0.0.2-next.22
|
|
50
|
+
* @twin.org/validate-locales bumped from 0.0.2-next.21 to 0.0.2-next.22
|
|
51
|
+
|
|
52
|
+
## [0.0.2-next.21](https://github.com/twinfoundation/framework/compare/modules-v0.0.2-next.20...modules-v0.0.2-next.21) (2025-10-09)
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
### Features
|
|
56
|
+
|
|
57
|
+
* locales validation ([#197](https://github.com/twinfoundation/framework/issues/197)) ([55fdadb](https://github.com/twinfoundation/framework/commit/55fdadb13595ce0047f787bd1d4135d429a99f12))
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
### Dependencies
|
|
61
|
+
|
|
62
|
+
* The following workspace dependencies were updated
|
|
63
|
+
* dependencies
|
|
64
|
+
* @twin.org/core bumped from 0.0.2-next.20 to 0.0.2-next.21
|
|
65
|
+
* @twin.org/nameof bumped from 0.0.2-next.20 to 0.0.2-next.21
|
|
66
|
+
* devDependencies
|
|
67
|
+
* @twin.org/nameof-transformer bumped from 0.0.2-next.20 to 0.0.2-next.21
|
|
68
|
+
* @twin.org/nameof-vitest-plugin bumped from 0.0.2-next.20 to 0.0.2-next.21
|
|
69
|
+
* @twin.org/validate-locales bumped from 0.0.2-next.20 to 0.0.2-next.21
|
|
70
|
+
|
|
71
|
+
## [0.0.2-next.20](https://github.com/twinfoundation/framework/compare/modules-v0.0.2-next.19...modules-v0.0.2-next.20) (2025-10-02)
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
### Features
|
|
75
|
+
|
|
76
|
+
* improve Is.function and ModuleHelper.getModuleMethod signatures ([ecf968b](https://github.com/twinfoundation/framework/commit/ecf968b02934b3676be4bf7cd2d1e7f8e7af6ce2))
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
### Dependencies
|
|
80
|
+
|
|
81
|
+
* The following workspace dependencies were updated
|
|
82
|
+
* dependencies
|
|
83
|
+
* @twin.org/core bumped from 0.0.2-next.19 to 0.0.2-next.20
|
|
84
|
+
* @twin.org/nameof bumped from 0.0.2-next.19 to 0.0.2-next.20
|
|
85
|
+
* devDependencies
|
|
86
|
+
* @twin.org/nameof-transformer bumped from 0.0.2-next.19 to 0.0.2-next.20
|
|
87
|
+
* @twin.org/nameof-vitest-plugin bumped from 0.0.2-next.19 to 0.0.2-next.20
|
|
88
|
+
|
|
89
|
+
## [0.0.2-next.19](https://github.com/twinfoundation/framework/compare/modules-v0.0.2-next.18...modules-v0.0.2-next.19) (2025-09-30)
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
### Miscellaneous Chores
|
|
93
|
+
|
|
94
|
+
* **modules:** Synchronize repo versions
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
### Dependencies
|
|
98
|
+
|
|
99
|
+
* The following workspace dependencies were updated
|
|
100
|
+
* dependencies
|
|
101
|
+
* @twin.org/core bumped from 0.0.2-next.18 to 0.0.2-next.19
|
|
102
|
+
* @twin.org/nameof bumped from 0.0.2-next.18 to 0.0.2-next.19
|
|
103
|
+
* devDependencies
|
|
104
|
+
* @twin.org/nameof-transformer bumped from 0.0.2-next.18 to 0.0.2-next.19
|
|
105
|
+
* @twin.org/nameof-vitest-plugin bumped from 0.0.2-next.18 to 0.0.2-next.19
|
|
106
|
+
|
|
107
|
+
## [0.0.2-next.18](https://github.com/twinfoundation/framework/compare/modules-v0.0.2-next.17...modules-v0.0.2-next.18) (2025-09-29)
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
### Miscellaneous Chores
|
|
111
|
+
|
|
112
|
+
* **modules:** Synchronize repo versions
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
### Dependencies
|
|
116
|
+
|
|
117
|
+
* The following workspace dependencies were updated
|
|
118
|
+
* dependencies
|
|
119
|
+
* @twin.org/core bumped from 0.0.2-next.17 to 0.0.2-next.18
|
|
120
|
+
* @twin.org/nameof bumped from 0.0.2-next.17 to 0.0.2-next.18
|
|
121
|
+
* devDependencies
|
|
122
|
+
* @twin.org/nameof-transformer bumped from 0.0.2-next.17 to 0.0.2-next.18
|
|
123
|
+
* @twin.org/nameof-vitest-plugin bumped from 0.0.2-next.17 to 0.0.2-next.18
|
|
124
|
+
|
|
125
|
+
## [0.0.2-next.17](https://github.com/twinfoundation/framework/compare/modules-v0.0.2-next.16...modules-v0.0.2-next.17) (2025-09-29)
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
### Miscellaneous Chores
|
|
129
|
+
|
|
130
|
+
* **modules:** Synchronize repo versions
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
### Dependencies
|
|
134
|
+
|
|
135
|
+
* The following workspace dependencies were updated
|
|
136
|
+
* dependencies
|
|
137
|
+
* @twin.org/core bumped from 0.0.2-next.16 to 0.0.2-next.17
|
|
138
|
+
* @twin.org/nameof bumped from 0.0.2-next.16 to 0.0.2-next.17
|
|
139
|
+
* devDependencies
|
|
140
|
+
* @twin.org/nameof-transformer bumped from 0.0.2-next.16 to 0.0.2-next.17
|
|
141
|
+
* @twin.org/nameof-vitest-plugin bumped from 0.0.2-next.16 to 0.0.2-next.17
|
|
142
|
+
|
|
143
|
+
## [0.0.2-next.16](https://github.com/twinfoundation/framework/compare/modules-v0.0.2-next.15...modules-v0.0.2-next.16) (2025-09-28)
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
### Features
|
|
147
|
+
|
|
148
|
+
* nodeIdentity optional in IComponent methods ([c78dc17](https://github.com/twinfoundation/framework/commit/c78dc17f4357d3e1ae40e415f468d3eae13e81f4))
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
### Dependencies
|
|
152
|
+
|
|
153
|
+
* The following workspace dependencies were updated
|
|
154
|
+
* dependencies
|
|
155
|
+
* @twin.org/core bumped from 0.0.2-next.15 to 0.0.2-next.16
|
|
156
|
+
* @twin.org/nameof bumped from 0.0.2-next.15 to 0.0.2-next.16
|
|
157
|
+
* devDependencies
|
|
158
|
+
* @twin.org/nameof-transformer bumped from 0.0.2-next.15 to 0.0.2-next.16
|
|
159
|
+
* @twin.org/nameof-vitest-plugin bumped from 0.0.2-next.15 to 0.0.2-next.16
|
|
160
|
+
|
|
161
|
+
## [0.0.2-next.15](https://github.com/twinfoundation/framework/compare/modules-v0.0.2-next.14...modules-v0.0.2-next.15) (2025-09-22)
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
### Miscellaneous Chores
|
|
165
|
+
|
|
166
|
+
* **modules:** Synchronize repo versions
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
### Dependencies
|
|
170
|
+
|
|
171
|
+
* The following workspace dependencies were updated
|
|
172
|
+
* dependencies
|
|
173
|
+
* @twin.org/core bumped from 0.0.2-next.14 to 0.0.2-next.15
|
|
174
|
+
* @twin.org/nameof bumped from 0.0.2-next.14 to 0.0.2-next.15
|
|
175
|
+
* devDependencies
|
|
176
|
+
* @twin.org/nameof-transformer bumped from 0.0.2-next.14 to 0.0.2-next.15
|
|
177
|
+
* @twin.org/nameof-vitest-plugin bumped from 0.0.2-next.14 to 0.0.2-next.15
|
|
178
|
+
|
|
179
|
+
## [0.0.2-next.14](https://github.com/twinfoundation/framework/compare/modules-v0.0.2-next.13...modules-v0.0.2-next.14) (2025-09-22)
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
### Miscellaneous Chores
|
|
183
|
+
|
|
184
|
+
* **modules:** Synchronize repo versions
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
### Dependencies
|
|
188
|
+
|
|
189
|
+
* The following workspace dependencies were updated
|
|
190
|
+
* dependencies
|
|
191
|
+
* @twin.org/core bumped from 0.0.2-next.13 to 0.0.2-next.14
|
|
192
|
+
* @twin.org/nameof bumped from 0.0.2-next.13 to 0.0.2-next.14
|
|
193
|
+
* devDependencies
|
|
194
|
+
* @twin.org/nameof-transformer bumped from 0.0.2-next.13 to 0.0.2-next.14
|
|
195
|
+
* @twin.org/nameof-vitest-plugin bumped from 0.0.2-next.13 to 0.0.2-next.14
|
|
196
|
+
|
|
197
|
+
## [0.0.2-next.13](https://github.com/twinfoundation/framework/compare/modules-v0.0.2-next.12...modules-v0.0.2-next.13) (2025-09-22)
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
### Miscellaneous Chores
|
|
201
|
+
|
|
202
|
+
* **modules:** Synchronize repo versions
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
### Dependencies
|
|
206
|
+
|
|
207
|
+
* The following workspace dependencies were updated
|
|
208
|
+
* dependencies
|
|
209
|
+
* @twin.org/core bumped from 0.0.2-next.12 to 0.0.2-next.13
|
|
210
|
+
* @twin.org/nameof bumped from 0.0.2-next.12 to 0.0.2-next.13
|
|
211
|
+
* devDependencies
|
|
212
|
+
* @twin.org/nameof-transformer bumped from 0.0.2-next.12 to 0.0.2-next.13
|
|
213
|
+
* @twin.org/nameof-vitest-plugin bumped from 0.0.2-next.12 to 0.0.2-next.13
|
|
214
|
+
|
|
215
|
+
## [0.0.2-next.12](https://github.com/twinfoundation/framework/compare/modules-v0.0.2-next.11...modules-v0.0.2-next.12) (2025-09-15)
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
### Miscellaneous Chores
|
|
219
|
+
|
|
220
|
+
* **modules:** Synchronize repo versions
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
### Dependencies
|
|
224
|
+
|
|
225
|
+
* The following workspace dependencies were updated
|
|
226
|
+
* dependencies
|
|
227
|
+
* @twin.org/core bumped from 0.0.2-next.11 to 0.0.2-next.12
|
|
228
|
+
* @twin.org/nameof bumped from 0.0.2-next.11 to 0.0.2-next.12
|
|
229
|
+
* devDependencies
|
|
230
|
+
* @twin.org/nameof-transformer bumped from 0.0.2-next.11 to 0.0.2-next.12
|
|
231
|
+
* @twin.org/nameof-vitest-plugin bumped from 0.0.2-next.11 to 0.0.2-next.12
|
|
232
|
+
|
|
233
|
+
## [0.0.2-next.11](https://github.com/twinfoundation/framework/compare/modules-v0.0.2-next.10...modules-v0.0.2-next.11) (2025-09-15)
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
### Miscellaneous Chores
|
|
237
|
+
|
|
238
|
+
* **modules:** Synchronize repo versions
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
### Dependencies
|
|
242
|
+
|
|
243
|
+
* The following workspace dependencies were updated
|
|
244
|
+
* dependencies
|
|
245
|
+
* @twin.org/core bumped from 0.0.2-next.10 to 0.0.2-next.11
|
|
246
|
+
* @twin.org/nameof bumped from 0.0.2-next.10 to 0.0.2-next.11
|
|
247
|
+
* devDependencies
|
|
248
|
+
* @twin.org/nameof-transformer bumped from 0.0.2-next.10 to 0.0.2-next.11
|
|
249
|
+
* @twin.org/nameof-vitest-plugin bumped from 0.0.2-next.10 to 0.0.2-next.11
|
|
250
|
+
|
|
251
|
+
## [0.0.2-next.10](https://github.com/twinfoundation/framework/compare/modules-v0.0.2-next.9...modules-v0.0.2-next.10) (2025-09-11)
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
### Miscellaneous Chores
|
|
255
|
+
|
|
256
|
+
* **modules:** Synchronize repo versions
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
### Dependencies
|
|
260
|
+
|
|
261
|
+
* The following workspace dependencies were updated
|
|
262
|
+
* dependencies
|
|
263
|
+
* @twin.org/core bumped from 0.0.2-next.9 to 0.0.2-next.10
|
|
264
|
+
* @twin.org/nameof bumped from 0.0.2-next.9 to 0.0.2-next.10
|
|
265
|
+
* devDependencies
|
|
266
|
+
* @twin.org/nameof-transformer bumped from 0.0.2-next.9 to 0.0.2-next.10
|
|
267
|
+
* @twin.org/nameof-vitest-plugin bumped from 0.0.2-next.9 to 0.0.2-next.10
|
|
268
|
+
|
|
269
|
+
## [0.0.2-next.9](https://github.com/twinfoundation/framework/compare/modules-v0.0.2-next.8...modules-v0.0.2-next.9) (2025-09-08)
|
|
270
|
+
|
|
271
|
+
|
|
272
|
+
### Miscellaneous Chores
|
|
273
|
+
|
|
274
|
+
* **modules:** Synchronize repo versions
|
|
275
|
+
|
|
276
|
+
|
|
277
|
+
### Dependencies
|
|
278
|
+
|
|
279
|
+
* The following workspace dependencies were updated
|
|
280
|
+
* dependencies
|
|
281
|
+
* @twin.org/core bumped from 0.0.2-next.8 to 0.0.2-next.9
|
|
282
|
+
* @twin.org/nameof bumped from 0.0.2-next.8 to 0.0.2-next.9
|
|
283
|
+
* devDependencies
|
|
284
|
+
* @twin.org/nameof-transformer bumped from 0.0.2-next.8 to 0.0.2-next.9
|
|
285
|
+
* @twin.org/nameof-vitest-plugin bumped from 0.0.2-next.8 to 0.0.2-next.9
|
|
286
|
+
|
|
3
287
|
## [0.0.2-next.8](https://github.com/twinfoundation/framework/compare/modules-v0.0.2-next.7...modules-v0.0.2-next.8) (2025-09-05)
|
|
4
288
|
|
|
5
289
|
|
|
@@ -82,7 +82,7 @@ GeneralError if getting the module entry failed.
|
|
|
82
82
|
|
|
83
83
|
### getModuleMethod()
|
|
84
84
|
|
|
85
|
-
> `static` **getModuleMethod**\<`T`\>(`module`, `method`): `Promise
|
|
85
|
+
> `static` **getModuleMethod**\<`T`\>(`module`, `method`): `Promise`\<`T`\>
|
|
86
86
|
|
|
87
87
|
Get the method from a module.
|
|
88
88
|
|
|
@@ -90,7 +90,7 @@ Get the method from a module.
|
|
|
90
90
|
|
|
91
91
|
##### T
|
|
92
92
|
|
|
93
|
-
`T`
|
|
93
|
+
`T` *extends* (...`args`) => `any` = (...`args`) => `any`
|
|
94
94
|
|
|
95
95
|
#### Parameters
|
|
96
96
|
|
|
@@ -108,7 +108,7 @@ The method to execute from the module, use dot notation to get a static class me
|
|
|
108
108
|
|
|
109
109
|
#### Returns
|
|
110
110
|
|
|
111
|
-
`Promise
|
|
111
|
+
`Promise`\<`T`\>
|
|
112
112
|
|
|
113
113
|
The result of the method execution.
|
|
114
114
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@twin.org/modules",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3-next.1",
|
|
4
4
|
"description": "Helper classes for loading and executing from modules",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -14,25 +14,37 @@
|
|
|
14
14
|
"node": ">=20.0.0"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@twin.org/core": "0.0.
|
|
18
|
-
"@twin.org/nameof": "0.0.
|
|
17
|
+
"@twin.org/core": "0.0.3-next.1",
|
|
18
|
+
"@twin.org/nameof": "0.0.3-next.1"
|
|
19
19
|
},
|
|
20
|
-
"main": "./dist/
|
|
21
|
-
"module": "./dist/esm/index.mjs",
|
|
20
|
+
"main": "./dist/es/index.js",
|
|
22
21
|
"types": "./dist/types/index.d.ts",
|
|
23
22
|
"exports": {
|
|
24
23
|
".": {
|
|
25
24
|
"types": "./dist/types/index.d.ts",
|
|
26
|
-
"
|
|
27
|
-
"
|
|
25
|
+
"import": "./dist/es/index.js",
|
|
26
|
+
"default": "./dist/es/index.js"
|
|
28
27
|
},
|
|
29
28
|
"./locales/*.json": "./locales/*.json"
|
|
30
29
|
},
|
|
31
30
|
"files": [
|
|
32
|
-
"dist/
|
|
33
|
-
"dist/esm",
|
|
31
|
+
"dist/es",
|
|
34
32
|
"dist/types",
|
|
35
33
|
"locales",
|
|
36
34
|
"docs"
|
|
37
|
-
]
|
|
35
|
+
],
|
|
36
|
+
"keywords": [
|
|
37
|
+
"twin",
|
|
38
|
+
"trade",
|
|
39
|
+
"iota",
|
|
40
|
+
"framework",
|
|
41
|
+
"blockchain",
|
|
42
|
+
"core",
|
|
43
|
+
"foundation",
|
|
44
|
+
"utilities"
|
|
45
|
+
],
|
|
46
|
+
"bugs": {
|
|
47
|
+
"url": "git+https://github.com/twinfoundation/framework/issues"
|
|
48
|
+
},
|
|
49
|
+
"homepage": "https://twindev.org"
|
|
38
50
|
}
|
package/dist/cjs/index.cjs
DELETED
|
@@ -1,195 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var node_worker_threads = require('node:worker_threads');
|
|
4
|
-
var core = require('@twin.org/core');
|
|
5
|
-
|
|
6
|
-
// Copyright 2024 IOTA Stiftung.
|
|
7
|
-
// SPDX-License-Identifier: Apache-2.0.
|
|
8
|
-
/**
|
|
9
|
-
* Helper functions for modules.
|
|
10
|
-
*/
|
|
11
|
-
class ModuleHelper {
|
|
12
|
-
/**
|
|
13
|
-
* Runtime name for the class.
|
|
14
|
-
*/
|
|
15
|
-
static CLASS_NAME = "ModuleHelper";
|
|
16
|
-
/**
|
|
17
|
-
* Override the import function for modules.
|
|
18
|
-
* @param overrideImport The override import function.
|
|
19
|
-
*/
|
|
20
|
-
static overrideImport(overrideImport) {
|
|
21
|
-
core.SharedStore.set("overrideImport", overrideImport);
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Get the module entry.
|
|
25
|
-
* @param module The module.
|
|
26
|
-
* @param entry The entry to get from the module.
|
|
27
|
-
* @returns The entry from the module.
|
|
28
|
-
* @throws GeneralError if getting the module entry failed.
|
|
29
|
-
*/
|
|
30
|
-
static async getModuleEntry(module, entry) {
|
|
31
|
-
let moduleInstance;
|
|
32
|
-
try {
|
|
33
|
-
let useDefault = true;
|
|
34
|
-
const overrideImport = core.SharedStore.get("overrideImport");
|
|
35
|
-
if (!core.Is.empty(overrideImport)) {
|
|
36
|
-
const overrideResult = await overrideImport(module);
|
|
37
|
-
moduleInstance = overrideResult.module;
|
|
38
|
-
useDefault = overrideResult.useDefault;
|
|
39
|
-
}
|
|
40
|
-
if (useDefault) {
|
|
41
|
-
moduleInstance = await import(module);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
catch (err) {
|
|
45
|
-
throw new core.GeneralError(ModuleHelper.CLASS_NAME, "moduleNotFound", {
|
|
46
|
-
module,
|
|
47
|
-
entry
|
|
48
|
-
}, core.BaseError.fromError(err));
|
|
49
|
-
}
|
|
50
|
-
const moduleEntry = moduleInstance?.[entry];
|
|
51
|
-
if (core.Is.empty(moduleEntry)) {
|
|
52
|
-
throw new core.GeneralError(ModuleHelper.CLASS_NAME, "entryNotFound", {
|
|
53
|
-
module,
|
|
54
|
-
entry
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
return moduleEntry;
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* Get the method from a module.
|
|
61
|
-
* @param module The module.
|
|
62
|
-
* @param method The method to execute from the module, use dot notation to get a static class method.
|
|
63
|
-
* @returns The result of the method execution.
|
|
64
|
-
* @throws GeneralError if executing the module entry failed.
|
|
65
|
-
*/
|
|
66
|
-
static async getModuleMethod(module, method) {
|
|
67
|
-
const methodParts = method.split(".");
|
|
68
|
-
if (methodParts.length === 2) {
|
|
69
|
-
const moduleEntry = await ModuleHelper.getModuleEntry(module, methodParts[0]);
|
|
70
|
-
if (core.Is.function(moduleEntry[methodParts[1]])) {
|
|
71
|
-
return moduleEntry[methodParts[1]];
|
|
72
|
-
}
|
|
73
|
-
throw new core.GeneralError(ModuleHelper.CLASS_NAME, "notFunction", {
|
|
74
|
-
module,
|
|
75
|
-
entry: method
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
const moduleEntry = await ModuleHelper.getModuleEntry(module, methodParts[0]);
|
|
79
|
-
if (core.Is.function(moduleEntry)) {
|
|
80
|
-
return moduleEntry;
|
|
81
|
-
}
|
|
82
|
-
throw new core.GeneralError(ModuleHelper.CLASS_NAME, "notFunction", {
|
|
83
|
-
module,
|
|
84
|
-
entry: method
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* Execute the method in the module.
|
|
89
|
-
* @param module The module.
|
|
90
|
-
* @param method The method to execute from the module.
|
|
91
|
-
* @param args The arguments to pass to the method.
|
|
92
|
-
* @returns The result of the method execution.
|
|
93
|
-
* @throws GeneralError if executing the module entry failed.
|
|
94
|
-
*/
|
|
95
|
-
static async execModuleMethod(module, method, args) {
|
|
96
|
-
const moduleMethod = await ModuleHelper.getModuleMethod(module, method);
|
|
97
|
-
return moduleMethod(...(args ?? []));
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* Execute the method in the module in a thread.
|
|
101
|
-
* @param module The module.
|
|
102
|
-
* @param method The method to execute from the module.
|
|
103
|
-
* @param args The arguments to pass to the method.
|
|
104
|
-
* @returns The result of the method execution.
|
|
105
|
-
* @throws GeneralError if executing the module entry failed.
|
|
106
|
-
*/
|
|
107
|
-
static async execModuleMethodThread(module, method, args) {
|
|
108
|
-
return new Promise((resolve, reject) => {
|
|
109
|
-
const worker = new node_worker_threads.Worker(`(async () => {
|
|
110
|
-
try {
|
|
111
|
-
const { workerData, parentPort } = await import('node:worker_threads');
|
|
112
|
-
|
|
113
|
-
function rejectError(errorType, cause) {
|
|
114
|
-
parentPort.postMessage({ errorType, cause });
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
async function executeMethod(method) {
|
|
118
|
-
try {
|
|
119
|
-
const result = await method(...(args ?? []));
|
|
120
|
-
|
|
121
|
-
parentPort.postMessage({ result });
|
|
122
|
-
} catch (err) {
|
|
123
|
-
rejectError('resultError', err);
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
const { module, method, args } = workerData;
|
|
128
|
-
|
|
129
|
-
const moduleInstance = await import(module);
|
|
130
|
-
const methodParts = method.split('.');
|
|
131
|
-
const moduleEntry = moduleInstance[methodParts[0]];
|
|
132
|
-
|
|
133
|
-
if (moduleEntry === undefined) {
|
|
134
|
-
rejectError('entryNotFound');
|
|
135
|
-
} else if (methodParts.length === 2) {
|
|
136
|
-
const moduleMethod = moduleEntry[methodParts[1]];
|
|
137
|
-
if (typeof moduleMethod === 'function') {
|
|
138
|
-
await executeMethod(moduleMethod, args);
|
|
139
|
-
} else {
|
|
140
|
-
rejectError('notFunction');
|
|
141
|
-
}
|
|
142
|
-
} else if (typeof moduleEntry === 'function') {
|
|
143
|
-
await executeMethod(moduleEntry, args);
|
|
144
|
-
} else {
|
|
145
|
-
rejectError('notFunction');
|
|
146
|
-
}
|
|
147
|
-
} catch (err) {
|
|
148
|
-
rejectError('moduleNotFound', err);
|
|
149
|
-
}
|
|
150
|
-
})();
|
|
151
|
-
`, { eval: true, workerData: { module, method, args: args ?? [] } });
|
|
152
|
-
worker.on("message", msg => {
|
|
153
|
-
if (core.Is.stringValue(msg.errorType)) {
|
|
154
|
-
reject(new core.GeneralError(ModuleHelper.CLASS_NAME, msg.errorType, { module, entry: method }, msg.cause));
|
|
155
|
-
}
|
|
156
|
-
else {
|
|
157
|
-
resolve(msg.result);
|
|
158
|
-
}
|
|
159
|
-
});
|
|
160
|
-
worker.on("error", err => {
|
|
161
|
-
reject(new core.GeneralError(ModuleHelper.CLASS_NAME, "workerException", {
|
|
162
|
-
module,
|
|
163
|
-
entry: method
|
|
164
|
-
}, err));
|
|
165
|
-
});
|
|
166
|
-
worker.on("exit", code => {
|
|
167
|
-
if (code === 1) {
|
|
168
|
-
reject(new core.GeneralError(ModuleHelper.CLASS_NAME, "workerFailed", {
|
|
169
|
-
module,
|
|
170
|
-
entry: method,
|
|
171
|
-
exitCode: code
|
|
172
|
-
}));
|
|
173
|
-
}
|
|
174
|
-
});
|
|
175
|
-
});
|
|
176
|
-
}
|
|
177
|
-
/**
|
|
178
|
-
* Check if a module is a local module.
|
|
179
|
-
* @param name The name of the module.
|
|
180
|
-
* @returns True if the module is local, false otherwise.
|
|
181
|
-
*/
|
|
182
|
-
static isLocalModule(name) {
|
|
183
|
-
return name.startsWith(".") || name.startsWith("/");
|
|
184
|
-
}
|
|
185
|
-
/**
|
|
186
|
-
* Check if a module is a relative module.
|
|
187
|
-
* @param name The name of the module.
|
|
188
|
-
* @returns True if the module is relative, false otherwise.
|
|
189
|
-
*/
|
|
190
|
-
static isRelativeModule(name) {
|
|
191
|
-
return name.startsWith(".");
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
exports.ModuleHelper = ModuleHelper;
|