@twin.org/modules 0.0.1-next.64 → 0.0.1-next.66
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 +37 -33
- package/dist/esm/index.mjs +37 -33
- package/docs/changelog.md +28 -0
- package/package.json +2 -2
package/dist/cjs/index.cjs
CHANGED
|
@@ -91,44 +91,48 @@ class ModuleHelper {
|
|
|
91
91
|
*/
|
|
92
92
|
static async execModuleMethodThread(module, method, args) {
|
|
93
93
|
return new Promise((resolve, reject) => {
|
|
94
|
-
const worker = new node_worker_threads.Worker(`
|
|
95
|
-
|
|
96
|
-
|
|
94
|
+
const worker = new node_worker_threads.Worker(`(async () => {
|
|
95
|
+
try {
|
|
96
|
+
const { workerData, parentPort } = await import('node:worker_threads');
|
|
97
97
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
98
|
+
function rejectError(type, innerError) {
|
|
99
|
+
parentPort.postMessage({ errorType: type, innerError });
|
|
100
|
+
}
|
|
101
101
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
102
|
+
async function executeMethod(method) {
|
|
103
|
+
try {
|
|
104
|
+
const result = await method(...(args ?? []));
|
|
105
105
|
|
|
106
|
-
|
|
106
|
+
parentPort.postMessage({ result });
|
|
107
|
+
} catch (err) {
|
|
108
|
+
rejectError('resultError', err);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
107
111
|
|
|
108
|
-
|
|
109
|
-
.then(moduleInstance => {
|
|
110
|
-
const methodParts = method.split(".");
|
|
111
|
-
const moduleEntry = moduleInstance[methodParts[0]];
|
|
112
|
+
const { module, method, args } = workerData;
|
|
112
113
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
114
|
+
const moduleInstance = await import(module);
|
|
115
|
+
const methodParts = method.split('.');
|
|
116
|
+
const moduleEntry = moduleInstance[methodParts[0]];
|
|
117
|
+
|
|
118
|
+
if (moduleEntry === undefined) {
|
|
119
|
+
rejectError('entryNotFound');
|
|
120
|
+
} else if (methodParts.length === 2) {
|
|
121
|
+
const moduleMethod = moduleEntry[methodParts[1]];
|
|
122
|
+
if (typeof moduleMethod === 'function') {
|
|
123
|
+
await executeMethod(moduleMethod, args);
|
|
124
|
+
} else {
|
|
125
|
+
rejectError('notFunction');
|
|
126
|
+
}
|
|
127
|
+
} else if (typeof moduleEntry === 'function') {
|
|
128
|
+
await executeMethod(moduleEntry, args);
|
|
129
|
+
} else {
|
|
130
|
+
rejectError('notFunction');
|
|
131
|
+
}
|
|
132
|
+
} catch (err) {
|
|
133
|
+
rejectError('moduleNotFound', err);
|
|
134
|
+
}
|
|
135
|
+
})();
|
|
132
136
|
`, { eval: true, workerData: { module, method, args: args ?? [] } });
|
|
133
137
|
worker.on("message", msg => {
|
|
134
138
|
if (core.Is.stringValue(msg.errorType)) {
|
package/dist/esm/index.mjs
CHANGED
|
@@ -89,44 +89,48 @@ class ModuleHelper {
|
|
|
89
89
|
*/
|
|
90
90
|
static async execModuleMethodThread(module, method, args) {
|
|
91
91
|
return new Promise((resolve, reject) => {
|
|
92
|
-
const worker = new Worker(`
|
|
93
|
-
|
|
94
|
-
|
|
92
|
+
const worker = new Worker(`(async () => {
|
|
93
|
+
try {
|
|
94
|
+
const { workerData, parentPort } = await import('node:worker_threads');
|
|
95
95
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
96
|
+
function rejectError(type, innerError) {
|
|
97
|
+
parentPort.postMessage({ errorType: type, innerError });
|
|
98
|
+
}
|
|
99
99
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
100
|
+
async function executeMethod(method) {
|
|
101
|
+
try {
|
|
102
|
+
const result = await method(...(args ?? []));
|
|
103
103
|
|
|
104
|
-
|
|
104
|
+
parentPort.postMessage({ result });
|
|
105
|
+
} catch (err) {
|
|
106
|
+
rejectError('resultError', err);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
105
109
|
|
|
106
|
-
|
|
107
|
-
.then(moduleInstance => {
|
|
108
|
-
const methodParts = method.split(".");
|
|
109
|
-
const moduleEntry = moduleInstance[methodParts[0]];
|
|
110
|
+
const { module, method, args } = workerData;
|
|
110
111
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
112
|
+
const moduleInstance = await import(module);
|
|
113
|
+
const methodParts = method.split('.');
|
|
114
|
+
const moduleEntry = moduleInstance[methodParts[0]];
|
|
115
|
+
|
|
116
|
+
if (moduleEntry === undefined) {
|
|
117
|
+
rejectError('entryNotFound');
|
|
118
|
+
} else if (methodParts.length === 2) {
|
|
119
|
+
const moduleMethod = moduleEntry[methodParts[1]];
|
|
120
|
+
if (typeof moduleMethod === 'function') {
|
|
121
|
+
await executeMethod(moduleMethod, args);
|
|
122
|
+
} else {
|
|
123
|
+
rejectError('notFunction');
|
|
124
|
+
}
|
|
125
|
+
} else if (typeof moduleEntry === 'function') {
|
|
126
|
+
await executeMethod(moduleEntry, args);
|
|
127
|
+
} else {
|
|
128
|
+
rejectError('notFunction');
|
|
129
|
+
}
|
|
130
|
+
} catch (err) {
|
|
131
|
+
rejectError('moduleNotFound', err);
|
|
132
|
+
}
|
|
133
|
+
})();
|
|
130
134
|
`, { eval: true, workerData: { module, method, args: args ?? [] } });
|
|
131
135
|
worker.on("message", msg => {
|
|
132
136
|
if (Is.stringValue(msg.errorType)) {
|
package/docs/changelog.md
CHANGED
|
@@ -1,5 +1,33 @@
|
|
|
1
1
|
# @twin.org/modules - Changelog
|
|
2
2
|
|
|
3
|
+
## [0.0.1-next.66](https://github.com/twinfoundation/framework/compare/modules-v0.0.1-next.65...modules-v0.0.1-next.66) (2025-06-26)
|
|
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.65 to 0.0.1-next.66
|
|
16
|
+
|
|
17
|
+
## [0.0.1-next.65](https://github.com/twinfoundation/framework/compare/modules-v0.0.1-next.64...modules-v0.0.1-next.65) (2025-06-19)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### Features
|
|
21
|
+
|
|
22
|
+
* improve async pattern and error handling ([aaa1f68](https://github.com/twinfoundation/framework/commit/aaa1f6879d60adf04b78b0c1bbbec50f2873f020))
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
### Dependencies
|
|
26
|
+
|
|
27
|
+
* The following workspace dependencies were updated
|
|
28
|
+
* dependencies
|
|
29
|
+
* @twin.org/core bumped from 0.0.1-next.64 to 0.0.1-next.65
|
|
30
|
+
|
|
3
31
|
## [0.0.1-next.64](https://github.com/twinfoundation/framework/compare/modules-v0.0.1-next.63...modules-v0.0.1-next.64) (2025-06-19)
|
|
4
32
|
|
|
5
33
|
|
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.66",
|
|
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.66",
|
|
18
18
|
"@twin.org/nameof": "next"
|
|
19
19
|
},
|
|
20
20
|
"main": "./dist/cjs/index.cjs",
|