@twin.org/modules 0.0.1-next.57 → 0.0.1-next.58
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 +30 -28
- package/dist/esm/index.mjs +30 -28
- package/docs/changelog.md +14 -0
- package/package.json +2 -2
package/dist/cjs/index.cjs
CHANGED
|
@@ -92,42 +92,44 @@ class ModuleHelper {
|
|
|
92
92
|
static async execModuleMethodThread(module, method, args) {
|
|
93
93
|
return new Promise((resolve, reject) => {
|
|
94
94
|
const worker = new node_worker_threads.Worker(`
|
|
95
|
-
|
|
95
|
+
(async () => {
|
|
96
|
+
const { workerData, parentPort } = await import('worker_threads');
|
|
96
97
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
98
|
+
function rejectError(type, innerError) {
|
|
99
|
+
parentPort.postMessage({ errorType: type, innerError });
|
|
100
|
+
}
|
|
100
101
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
102
|
+
function resolveResult(result) {
|
|
103
|
+
Promise.resolve(result).then(res => parentPort.postMessage({ result: res }));
|
|
104
|
+
}
|
|
104
105
|
|
|
105
|
-
|
|
106
|
+
const { module, method, args } = workerData;
|
|
106
107
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
108
|
+
import(module)
|
|
109
|
+
.then(moduleInstance => {
|
|
110
|
+
const methodParts = method.split(".");
|
|
111
|
+
const moduleEntry = moduleInstance[methodParts[0]];
|
|
111
112
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
113
|
+
if (moduleEntry === undefined) {
|
|
114
|
+
rejectError("entryNotFound");
|
|
115
|
+
} else if (methodParts.length === 2) {
|
|
116
|
+
const moduleMethod = moduleEntry[methodParts[1]];
|
|
117
|
+
if (typeof moduleMethod === "function") {
|
|
118
|
+
resolveResult(moduleMethod(...(args ?? [])));
|
|
119
|
+
} else {
|
|
120
|
+
rejectError("notFunction");
|
|
121
|
+
}
|
|
122
|
+
} else if (typeof moduleEntry === "function") {
|
|
123
|
+
resolveResult(moduleEntry(...(args ?? [])));
|
|
118
124
|
} else {
|
|
119
125
|
rejectError("notFunction");
|
|
120
126
|
}
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
.catch(err => {
|
|
128
|
-
rejectError("moduleNotFound", err);
|
|
129
|
-
});
|
|
130
|
-
`, { eval: true, workerData: { module, method, args: args ?? [] } });
|
|
127
|
+
})
|
|
128
|
+
.catch(err => {
|
|
129
|
+
rejectError("moduleNotFound", err);
|
|
130
|
+
});
|
|
131
|
+
})();
|
|
132
|
+
`, { eval: true, workerData: { module, method, args: args ?? [] } });
|
|
131
133
|
worker.on("message", msg => {
|
|
132
134
|
if (core.Is.stringValue(msg.errorType)) {
|
|
133
135
|
reject(new core.GeneralError(ModuleHelper.CLASS_NAME, msg.errorType, { module, entry: method }, msg.innerError));
|
package/dist/esm/index.mjs
CHANGED
|
@@ -90,42 +90,44 @@ class ModuleHelper {
|
|
|
90
90
|
static async execModuleMethodThread(module, method, args) {
|
|
91
91
|
return new Promise((resolve, reject) => {
|
|
92
92
|
const worker = new Worker(`
|
|
93
|
-
|
|
93
|
+
(async () => {
|
|
94
|
+
const { workerData, parentPort } = await import('worker_threads');
|
|
94
95
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
96
|
+
function rejectError(type, innerError) {
|
|
97
|
+
parentPort.postMessage({ errorType: type, innerError });
|
|
98
|
+
}
|
|
98
99
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
100
|
+
function resolveResult(result) {
|
|
101
|
+
Promise.resolve(result).then(res => parentPort.postMessage({ result: res }));
|
|
102
|
+
}
|
|
102
103
|
|
|
103
|
-
|
|
104
|
+
const { module, method, args } = workerData;
|
|
104
105
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
106
|
+
import(module)
|
|
107
|
+
.then(moduleInstance => {
|
|
108
|
+
const methodParts = method.split(".");
|
|
109
|
+
const moduleEntry = moduleInstance[methodParts[0]];
|
|
109
110
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
111
|
+
if (moduleEntry === undefined) {
|
|
112
|
+
rejectError("entryNotFound");
|
|
113
|
+
} else if (methodParts.length === 2) {
|
|
114
|
+
const moduleMethod = moduleEntry[methodParts[1]];
|
|
115
|
+
if (typeof moduleMethod === "function") {
|
|
116
|
+
resolveResult(moduleMethod(...(args ?? [])));
|
|
117
|
+
} else {
|
|
118
|
+
rejectError("notFunction");
|
|
119
|
+
}
|
|
120
|
+
} else if (typeof moduleEntry === "function") {
|
|
121
|
+
resolveResult(moduleEntry(...(args ?? [])));
|
|
116
122
|
} else {
|
|
117
123
|
rejectError("notFunction");
|
|
118
124
|
}
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
.catch(err => {
|
|
126
|
-
rejectError("moduleNotFound", err);
|
|
127
|
-
});
|
|
128
|
-
`, { eval: true, workerData: { module, method, args: args ?? [] } });
|
|
125
|
+
})
|
|
126
|
+
.catch(err => {
|
|
127
|
+
rejectError("moduleNotFound", err);
|
|
128
|
+
});
|
|
129
|
+
})();
|
|
130
|
+
`, { eval: true, workerData: { module, method, args: args ?? [] } });
|
|
129
131
|
worker.on("message", msg => {
|
|
130
132
|
if (Is.stringValue(msg.errorType)) {
|
|
131
133
|
reject(new GeneralError(ModuleHelper.CLASS_NAME, msg.errorType, { module, entry: method }, msg.innerError));
|
package/docs/changelog.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# @twin.org/modules - Changelog
|
|
2
2
|
|
|
3
|
+
## [0.0.1-next.58](https://github.com/twinfoundation/framework/compare/modules-v0.0.1-next.57...modules-v0.0.1-next.58) (2025-06-13)
|
|
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.1-next.57 to 0.0.1-next.58
|
|
16
|
+
|
|
3
17
|
## [0.0.1-next.57](https://github.com/twinfoundation/framework/compare/modules-v0.0.1-next.56...modules-v0.0.1-next.57) (2025-06-10)
|
|
4
18
|
|
|
5
19
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@twin.org/modules",
|
|
3
|
-
"version": "0.0.1-next.
|
|
3
|
+
"version": "0.0.1-next.58",
|
|
4
4
|
"description": "Helper classes for loading and executing from modules",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"node": ">=20.0.0"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@twin.org/core": "0.0.1-next.
|
|
17
|
+
"@twin.org/core": "0.0.1-next.58",
|
|
18
18
|
"@twin.org/nameof": "next"
|
|
19
19
|
},
|
|
20
20
|
"main": "./dist/cjs/index.cjs",
|