@twin.org/modules 0.0.2-next.9 → 0.0.3-next.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.
@@ -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 (!Is.empty(overrideImport)) {
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":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,EAAE,EAAE,WAAW,EA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BACb,QAAQ,EAAE,IAAI;qBACd,CAAC,CACF,CAAC;gBACH,CAAC;YACF,CAAC,CAAC,CAAC;QACJ,CAAC,CAAC,CAAC;IACJ,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,aAAa,CAAC,IAAY;QACvC,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;IACrD,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,gBAAgB,CAAC,IAAY;QAC1C,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;IAC7B,CAAC","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"]}
@@ -0,0 +1,4 @@
1
+ // Copyright 2024 IOTA Stiftung.
2
+ // SPDX-License-Identifier: Apache-2.0.
3
+ export * from "./helpers/moduleHelper.js";
4
+ //# sourceMappingURL=index.js.map
@@ -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<(...args: unknown[]) => T>;
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.
@@ -1 +1 @@
1
- export * from "./helpers/moduleHelper";
1
+ export * from "./helpers/moduleHelper.js";
package/docs/changelog.md CHANGED
@@ -1,5 +1,290 @@
1
1
  # @twin.org/modules - Changelog
2
2
 
3
+ ## [0.0.3-next.2](https://github.com/twinfoundation/framework/compare/modules-v0.0.3-next.1...modules-v0.0.3-next.2) (2025-11-12)
4
+
5
+
6
+ ### Miscellaneous Chores
7
+
8
+ * **modules:** Synchronize repo versions
9
+
10
+
11
+ ### Dependencies
12
+
13
+ * The following workspace dependencies were updated
14
+ * dependencies
15
+ * @twin.org/core bumped from 0.0.3-next.1 to 0.0.3-next.2
16
+ * @twin.org/nameof bumped from 0.0.3-next.1 to 0.0.3-next.2
17
+ * devDependencies
18
+ * @twin.org/nameof-transformer bumped from 0.0.3-next.1 to 0.0.3-next.2
19
+ * @twin.org/nameof-vitest-plugin bumped from 0.0.3-next.1 to 0.0.3-next.2
20
+ * @twin.org/validate-locales bumped from 0.0.3-next.1 to 0.0.3-next.2
21
+
22
+ ## [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)
23
+
24
+
25
+ ### Features
26
+
27
+ * add context id features ([#206](https://github.com/twinfoundation/framework/issues/206)) ([ef0d4ee](https://github.com/twinfoundation/framework/commit/ef0d4ee11a4f5fc6cc6f52a4958ce905c04ee13b))
28
+ * add guards arrayEndsWith and arrayStartsWith ([95d875e](https://github.com/twinfoundation/framework/commit/95d875ec8ccb4713c145fdde941d4cfedcec2ed3))
29
+ * eslint migration to flat config ([74427d7](https://github.com/twinfoundation/framework/commit/74427d78d342167f7850e49ab87269326355befe))
30
+ * improve async pattern and error handling ([aaa1f68](https://github.com/twinfoundation/framework/commit/aaa1f6879d60adf04b78b0c1bbbec50f2873f020))
31
+ * improve Is.function and ModuleHelper.getModuleMethod signatures ([ecf968b](https://github.com/twinfoundation/framework/commit/ecf968b02934b3676be4bf7cd2d1e7f8e7af6ce2))
32
+ * locales validation ([#197](https://github.com/twinfoundation/framework/issues/197)) ([55fdadb](https://github.com/twinfoundation/framework/commit/55fdadb13595ce0047f787bd1d4135d429a99f12))
33
+ * nodeIdentity optional in IComponent methods ([c78dc17](https://github.com/twinfoundation/framework/commit/c78dc17f4357d3e1ae40e415f468d3eae13e81f4))
34
+ * provide module helper override ([e998a64](https://github.com/twinfoundation/framework/commit/e998a64842cfd18693a14444be33b084fef2bb90))
35
+ * relocate core packages from tools ([bcab8f3](https://github.com/twinfoundation/framework/commit/bcab8f3160442ea4fcaf442947462504f3d6a17d))
36
+ * update dependencies ([f3bd015](https://github.com/twinfoundation/framework/commit/f3bd015efd169196b7e0335f5cab876ba6ca1d75))
37
+ * use cause instead of inner for errors ([1f4acc4](https://github.com/twinfoundation/framework/commit/1f4acc4d7a6b71a134d9547da9bf40de1e1e49da))
38
+ * use new shared store mechanism ([#131](https://github.com/twinfoundation/framework/issues/131)) ([934385b](https://github.com/twinfoundation/framework/commit/934385b2fbaf9f5c00a505ebf9d093bd5a425f55))
39
+
40
+
41
+ ### Dependencies
42
+
43
+ * The following workspace dependencies were updated
44
+ * dependencies
45
+ * @twin.org/core bumped from 0.0.3-next.0 to 0.0.3-next.1
46
+ * @twin.org/nameof bumped from 0.0.3-next.0 to 0.0.3-next.1
47
+ * devDependencies
48
+ * @twin.org/nameof-transformer bumped from 0.0.3-next.0 to 0.0.3-next.1
49
+ * @twin.org/nameof-vitest-plugin bumped from 0.0.3-next.0 to 0.0.3-next.1
50
+ * @twin.org/validate-locales bumped from 0.0.3-next.0 to 0.0.3-next.1
51
+
52
+ ## [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)
53
+
54
+
55
+ ### Miscellaneous Chores
56
+
57
+ * **modules:** Synchronize repo versions
58
+
59
+
60
+ ### Dependencies
61
+
62
+ * The following workspace dependencies were updated
63
+ * dependencies
64
+ * @twin.org/core bumped from 0.0.2-next.21 to 0.0.2-next.22
65
+ * @twin.org/nameof bumped from 0.0.2-next.21 to 0.0.2-next.22
66
+ * devDependencies
67
+ * @twin.org/nameof-transformer bumped from 0.0.2-next.21 to 0.0.2-next.22
68
+ * @twin.org/nameof-vitest-plugin bumped from 0.0.2-next.21 to 0.0.2-next.22
69
+ * @twin.org/validate-locales bumped from 0.0.2-next.21 to 0.0.2-next.22
70
+
71
+ ## [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)
72
+
73
+
74
+ ### Features
75
+
76
+ * locales validation ([#197](https://github.com/twinfoundation/framework/issues/197)) ([55fdadb](https://github.com/twinfoundation/framework/commit/55fdadb13595ce0047f787bd1d4135d429a99f12))
77
+
78
+
79
+ ### Dependencies
80
+
81
+ * The following workspace dependencies were updated
82
+ * dependencies
83
+ * @twin.org/core bumped from 0.0.2-next.20 to 0.0.2-next.21
84
+ * @twin.org/nameof bumped from 0.0.2-next.20 to 0.0.2-next.21
85
+ * devDependencies
86
+ * @twin.org/nameof-transformer bumped from 0.0.2-next.20 to 0.0.2-next.21
87
+ * @twin.org/nameof-vitest-plugin bumped from 0.0.2-next.20 to 0.0.2-next.21
88
+ * @twin.org/validate-locales bumped from 0.0.2-next.20 to 0.0.2-next.21
89
+
90
+ ## [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)
91
+
92
+
93
+ ### Features
94
+
95
+ * improve Is.function and ModuleHelper.getModuleMethod signatures ([ecf968b](https://github.com/twinfoundation/framework/commit/ecf968b02934b3676be4bf7cd2d1e7f8e7af6ce2))
96
+
97
+
98
+ ### Dependencies
99
+
100
+ * The following workspace dependencies were updated
101
+ * dependencies
102
+ * @twin.org/core bumped from 0.0.2-next.19 to 0.0.2-next.20
103
+ * @twin.org/nameof bumped from 0.0.2-next.19 to 0.0.2-next.20
104
+ * devDependencies
105
+ * @twin.org/nameof-transformer bumped from 0.0.2-next.19 to 0.0.2-next.20
106
+ * @twin.org/nameof-vitest-plugin bumped from 0.0.2-next.19 to 0.0.2-next.20
107
+
108
+ ## [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)
109
+
110
+
111
+ ### Miscellaneous Chores
112
+
113
+ * **modules:** Synchronize repo versions
114
+
115
+
116
+ ### Dependencies
117
+
118
+ * The following workspace dependencies were updated
119
+ * dependencies
120
+ * @twin.org/core bumped from 0.0.2-next.18 to 0.0.2-next.19
121
+ * @twin.org/nameof bumped from 0.0.2-next.18 to 0.0.2-next.19
122
+ * devDependencies
123
+ * @twin.org/nameof-transformer bumped from 0.0.2-next.18 to 0.0.2-next.19
124
+ * @twin.org/nameof-vitest-plugin bumped from 0.0.2-next.18 to 0.0.2-next.19
125
+
126
+ ## [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)
127
+
128
+
129
+ ### Miscellaneous Chores
130
+
131
+ * **modules:** Synchronize repo versions
132
+
133
+
134
+ ### Dependencies
135
+
136
+ * The following workspace dependencies were updated
137
+ * dependencies
138
+ * @twin.org/core bumped from 0.0.2-next.17 to 0.0.2-next.18
139
+ * @twin.org/nameof bumped from 0.0.2-next.17 to 0.0.2-next.18
140
+ * devDependencies
141
+ * @twin.org/nameof-transformer bumped from 0.0.2-next.17 to 0.0.2-next.18
142
+ * @twin.org/nameof-vitest-plugin bumped from 0.0.2-next.17 to 0.0.2-next.18
143
+
144
+ ## [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)
145
+
146
+
147
+ ### Miscellaneous Chores
148
+
149
+ * **modules:** Synchronize repo versions
150
+
151
+
152
+ ### Dependencies
153
+
154
+ * The following workspace dependencies were updated
155
+ * dependencies
156
+ * @twin.org/core bumped from 0.0.2-next.16 to 0.0.2-next.17
157
+ * @twin.org/nameof bumped from 0.0.2-next.16 to 0.0.2-next.17
158
+ * devDependencies
159
+ * @twin.org/nameof-transformer bumped from 0.0.2-next.16 to 0.0.2-next.17
160
+ * @twin.org/nameof-vitest-plugin bumped from 0.0.2-next.16 to 0.0.2-next.17
161
+
162
+ ## [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)
163
+
164
+
165
+ ### Features
166
+
167
+ * nodeIdentity optional in IComponent methods ([c78dc17](https://github.com/twinfoundation/framework/commit/c78dc17f4357d3e1ae40e415f468d3eae13e81f4))
168
+
169
+
170
+ ### Dependencies
171
+
172
+ * The following workspace dependencies were updated
173
+ * dependencies
174
+ * @twin.org/core bumped from 0.0.2-next.15 to 0.0.2-next.16
175
+ * @twin.org/nameof bumped from 0.0.2-next.15 to 0.0.2-next.16
176
+ * devDependencies
177
+ * @twin.org/nameof-transformer bumped from 0.0.2-next.15 to 0.0.2-next.16
178
+ * @twin.org/nameof-vitest-plugin bumped from 0.0.2-next.15 to 0.0.2-next.16
179
+
180
+ ## [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)
181
+
182
+
183
+ ### Miscellaneous Chores
184
+
185
+ * **modules:** Synchronize repo versions
186
+
187
+
188
+ ### Dependencies
189
+
190
+ * The following workspace dependencies were updated
191
+ * dependencies
192
+ * @twin.org/core bumped from 0.0.2-next.14 to 0.0.2-next.15
193
+ * @twin.org/nameof bumped from 0.0.2-next.14 to 0.0.2-next.15
194
+ * devDependencies
195
+ * @twin.org/nameof-transformer bumped from 0.0.2-next.14 to 0.0.2-next.15
196
+ * @twin.org/nameof-vitest-plugin bumped from 0.0.2-next.14 to 0.0.2-next.15
197
+
198
+ ## [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)
199
+
200
+
201
+ ### Miscellaneous Chores
202
+
203
+ * **modules:** Synchronize repo versions
204
+
205
+
206
+ ### Dependencies
207
+
208
+ * The following workspace dependencies were updated
209
+ * dependencies
210
+ * @twin.org/core bumped from 0.0.2-next.13 to 0.0.2-next.14
211
+ * @twin.org/nameof bumped from 0.0.2-next.13 to 0.0.2-next.14
212
+ * devDependencies
213
+ * @twin.org/nameof-transformer bumped from 0.0.2-next.13 to 0.0.2-next.14
214
+ * @twin.org/nameof-vitest-plugin bumped from 0.0.2-next.13 to 0.0.2-next.14
215
+
216
+ ## [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)
217
+
218
+
219
+ ### Miscellaneous Chores
220
+
221
+ * **modules:** Synchronize repo versions
222
+
223
+
224
+ ### Dependencies
225
+
226
+ * The following workspace dependencies were updated
227
+ * dependencies
228
+ * @twin.org/core bumped from 0.0.2-next.12 to 0.0.2-next.13
229
+ * @twin.org/nameof bumped from 0.0.2-next.12 to 0.0.2-next.13
230
+ * devDependencies
231
+ * @twin.org/nameof-transformer bumped from 0.0.2-next.12 to 0.0.2-next.13
232
+ * @twin.org/nameof-vitest-plugin bumped from 0.0.2-next.12 to 0.0.2-next.13
233
+
234
+ ## [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)
235
+
236
+
237
+ ### Miscellaneous Chores
238
+
239
+ * **modules:** Synchronize repo versions
240
+
241
+
242
+ ### Dependencies
243
+
244
+ * The following workspace dependencies were updated
245
+ * dependencies
246
+ * @twin.org/core bumped from 0.0.2-next.11 to 0.0.2-next.12
247
+ * @twin.org/nameof bumped from 0.0.2-next.11 to 0.0.2-next.12
248
+ * devDependencies
249
+ * @twin.org/nameof-transformer bumped from 0.0.2-next.11 to 0.0.2-next.12
250
+ * @twin.org/nameof-vitest-plugin bumped from 0.0.2-next.11 to 0.0.2-next.12
251
+
252
+ ## [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)
253
+
254
+
255
+ ### Miscellaneous Chores
256
+
257
+ * **modules:** Synchronize repo versions
258
+
259
+
260
+ ### Dependencies
261
+
262
+ * The following workspace dependencies were updated
263
+ * dependencies
264
+ * @twin.org/core bumped from 0.0.2-next.10 to 0.0.2-next.11
265
+ * @twin.org/nameof bumped from 0.0.2-next.10 to 0.0.2-next.11
266
+ * devDependencies
267
+ * @twin.org/nameof-transformer bumped from 0.0.2-next.10 to 0.0.2-next.11
268
+ * @twin.org/nameof-vitest-plugin bumped from 0.0.2-next.10 to 0.0.2-next.11
269
+
270
+ ## [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)
271
+
272
+
273
+ ### Miscellaneous Chores
274
+
275
+ * **modules:** Synchronize repo versions
276
+
277
+
278
+ ### Dependencies
279
+
280
+ * The following workspace dependencies were updated
281
+ * dependencies
282
+ * @twin.org/core bumped from 0.0.2-next.9 to 0.0.2-next.10
283
+ * @twin.org/nameof bumped from 0.0.2-next.9 to 0.0.2-next.10
284
+ * devDependencies
285
+ * @twin.org/nameof-transformer bumped from 0.0.2-next.9 to 0.0.2-next.10
286
+ * @twin.org/nameof-vitest-plugin bumped from 0.0.2-next.9 to 0.0.2-next.10
287
+
3
288
  ## [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)
4
289
 
5
290
 
@@ -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`\<(...`args`) => `T`\>
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`\<(...`args`) => `T`\>
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.2-next.9",
3
+ "version": "0.0.3-next.2",
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.2-next.9",
18
- "@twin.org/nameof": "0.0.2-next.9"
17
+ "@twin.org/core": "0.0.3-next.2",
18
+ "@twin.org/nameof": "0.0.3-next.2"
19
19
  },
20
- "main": "./dist/cjs/index.cjs",
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
- "require": "./dist/cjs/index.cjs",
27
- "import": "./dist/esm/index.mjs"
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/cjs",
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
  }
@@ -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;