@bonsae/nrg-runtime 0.24.0 → 0.25.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/package.json +1 -1
- package/server/index.cjs +13 -17
package/package.json
CHANGED
package/server/index.cjs
CHANGED
|
@@ -483,6 +483,8 @@ function setupContext(context, store) {
|
|
|
483
483
|
}
|
|
484
484
|
|
|
485
485
|
// src/server/nodes/io-node.ts
|
|
486
|
+
var import_node_async_hooks = require("node:async_hooks");
|
|
487
|
+
var inputInvocation = new import_node_async_hooks.AsyncLocalStorage();
|
|
486
488
|
function isSchemaLike(obj) {
|
|
487
489
|
return obj != null && typeof obj === "object" && import_typebox.Kind in obj;
|
|
488
490
|
}
|
|
@@ -532,13 +534,6 @@ var IONode = class extends Node {
|
|
|
532
534
|
if (!s || Array.isArray(s) || isSchemaLike(s)) return void 0;
|
|
533
535
|
return Object.keys(s);
|
|
534
536
|
}
|
|
535
|
-
#send;
|
|
536
|
-
/**
|
|
537
|
-
* Most recent input message — the spread base for output wrapping. Not
|
|
538
|
-
* cleared after input() so late async sends merge with the last received
|
|
539
|
-
* message.
|
|
540
|
-
*/
|
|
541
|
-
#currentInputMsg;
|
|
542
537
|
context;
|
|
543
538
|
constructor(RED, node, config, credentials) {
|
|
544
539
|
super(RED, node, config, credentials);
|
|
@@ -577,7 +572,6 @@ var IONode = class extends Node {
|
|
|
577
572
|
}
|
|
578
573
|
try {
|
|
579
574
|
nodeRedNode.log("Calling input");
|
|
580
|
-
this.#currentInputMsg = msg;
|
|
581
575
|
const result = await this.#input(msg, send);
|
|
582
576
|
this.#sendToPort("complete", {
|
|
583
577
|
...msg,
|
|
@@ -591,9 +585,12 @@ var IONode = class extends Node {
|
|
|
591
585
|
nodeRedNode.log("Input processed");
|
|
592
586
|
} catch (error) {
|
|
593
587
|
const errorMsg = error instanceof Error ? error.message : "Unknown error during input handling";
|
|
588
|
+
const errorData = error && typeof error === "object" ? { ...error } : {};
|
|
594
589
|
this.#sendToPort("error", {
|
|
595
590
|
...msg,
|
|
596
591
|
error: {
|
|
592
|
+
...errorData,
|
|
593
|
+
name: error?.name ?? "Error",
|
|
597
594
|
message: errorMsg,
|
|
598
595
|
source: this.#nodeSource()
|
|
599
596
|
},
|
|
@@ -630,12 +627,10 @@ var IONode = class extends Node {
|
|
|
630
627
|
});
|
|
631
628
|
this.log("Input is valid");
|
|
632
629
|
}
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
this.#send = void 0;
|
|
638
|
-
}
|
|
630
|
+
return await inputInvocation.run(
|
|
631
|
+
{ inputMsg: msg, send },
|
|
632
|
+
() => Promise.resolve(this.input(msg))
|
|
633
|
+
);
|
|
639
634
|
}
|
|
640
635
|
send(msg) {
|
|
641
636
|
const multi = this.baseOutputs > 1 && Array.isArray(msg);
|
|
@@ -648,8 +643,9 @@ var IONode = class extends Node {
|
|
|
648
643
|
this.#deliver(out);
|
|
649
644
|
}
|
|
650
645
|
#deliver(out) {
|
|
651
|
-
|
|
652
|
-
|
|
646
|
+
const send = inputInvocation.getStore()?.send;
|
|
647
|
+
if (send) {
|
|
648
|
+
send(out);
|
|
653
649
|
} else {
|
|
654
650
|
this.node.send(out);
|
|
655
651
|
}
|
|
@@ -710,7 +706,7 @@ var IONode = class extends Node {
|
|
|
710
706
|
*/
|
|
711
707
|
#wrapOutgoing(value, mode, port) {
|
|
712
708
|
const key = this.#returnPropertyKey(port);
|
|
713
|
-
const input =
|
|
709
|
+
const input = inputInvocation.getStore()?.inputMsg ?? {};
|
|
714
710
|
if (mode === "reset") {
|
|
715
711
|
return { [key]: value };
|
|
716
712
|
}
|