@bonsae/nrg 0.11.1 → 0.12.0

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/README.md CHANGED
@@ -5,7 +5,7 @@
5
5
  <p align="center">
6
6
  <a href="https://www.npmjs.com/package/@bonsae/nrg"><img src="https://img.shields.io/npm/v/@bonsae/nrg.svg" alt="npm package"></a>
7
7
  <a href="https://github.com/bonsaedev/nrg/actions/workflows/ci.yaml"><img src="https://github.com/bonsaedev/nrg/actions/workflows/ci.yaml/badge.svg?branch=main" alt="build status"></a>
8
- <a href="https://socket.dev/npm/package/@bonsae/nrg"><img src="https://badge.socket.dev/npm/package/@bonsae/nrg" alt="Socket Badge"></a>
8
+ <a href="https://socket.dev/npm/package/@bonsae/nrg"><img src="https://badge.socket.dev/npm/package/@bonsae/nrg?v=1" alt="Socket Badge"></a>
9
9
  </p>
10
10
 
11
11
  # nrg
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bonsae/nrg",
3
- "version": "0.11.1",
3
+ "version": "0.12.0",
4
4
  "description": "NRG framework — build Node-RED nodes with Vue 3, TypeScript, and JSON Schema",
5
5
  "author": "Allan Oricil <allanoricil@duck.com>",
6
6
  "license": "MIT",
package/server/index.cjs CHANGED
@@ -614,8 +614,74 @@ var IONode = class extends Node {
614
614
  this.node.send(msg);
615
615
  }
616
616
  }
617
+ // --- Emit port management ---
618
+ /** @internal */
619
+ get _baseOutputs() {
620
+ return this.constructor.outputs ?? 0;
621
+ }
622
+ /** @internal */
623
+ get _totalOutputs() {
624
+ let count = this._baseOutputs;
625
+ if (this.config.emitError) count++;
626
+ if (this.config.emitComplete) count++;
627
+ if (this.config.emitStatus) count++;
628
+ return count;
629
+ }
630
+ /** @internal */
631
+ _sendToPort(portIndex, msg) {
632
+ const out = Array(this._totalOutputs).fill(null);
633
+ out[portIndex] = msg;
634
+ this.node.send(out);
635
+ }
636
+ /** @internal */
637
+ _getErrorPortIndex() {
638
+ if (!this.config.emitError) return null;
639
+ return this._baseOutputs;
640
+ }
641
+ /** @internal */
642
+ _getCompletePortIndex() {
643
+ if (!this.config.emitComplete) return null;
644
+ let idx = this._baseOutputs;
645
+ if (this.config.emitError) idx++;
646
+ return idx;
647
+ }
648
+ /** @internal */
649
+ _getStatusPortIndex() {
650
+ if (!this.config.emitStatus) return null;
651
+ let idx = this._baseOutputs;
652
+ if (this.config.emitError) idx++;
653
+ if (this.config.emitComplete) idx++;
654
+ return idx;
655
+ }
656
+ _nodeSource() {
657
+ return {
658
+ id: this.id,
659
+ type: this.constructor.type,
660
+ name: this.name
661
+ };
662
+ }
617
663
  status(status) {
618
664
  this.node.status(status);
665
+ const portIdx = this._getStatusPortIndex();
666
+ if (portIdx !== null) {
667
+ this._sendToPort(portIdx, {
668
+ status,
669
+ source: this._nodeSource()
670
+ });
671
+ }
672
+ }
673
+ error(message, msg) {
674
+ super.error(message, msg);
675
+ const portIdx = this._getErrorPortIndex();
676
+ if (portIdx !== null && msg) {
677
+ this._sendToPort(portIdx, {
678
+ ...msg,
679
+ error: {
680
+ message,
681
+ source: this._nodeSource()
682
+ }
683
+ });
684
+ }
619
685
  }
620
686
  updateWires(wires) {
621
687
  this.node.updateWires(wires);
@@ -963,15 +1029,35 @@ async function registerType(RED, NodeClass) {
963
1029
  try {
964
1030
  this.log("Calling input");
965
1031
  await Promise.resolve(node._input(msg, send));
1032
+ const completeIdx = node._getCompletePortIndex();
1033
+ if (completeIdx !== null) {
1034
+ node._sendToPort(completeIdx, {
1035
+ ...msg,
1036
+ complete: {
1037
+ source: { id: node.id, type: NC.type, name: node.name }
1038
+ }
1039
+ });
1040
+ }
966
1041
  done();
967
1042
  this.log("Input processed");
968
1043
  } catch (error) {
1044
+ const errorMsg = error instanceof Error ? error.message : "Unknown error during input handling";
1045
+ const errorIdx = node._getErrorPortIndex();
1046
+ if (errorIdx !== null) {
1047
+ node._sendToPort(errorIdx, {
1048
+ ...msg,
1049
+ error: {
1050
+ message: errorMsg,
1051
+ source: { id: node.id, type: NC.type, name: node.name }
1052
+ }
1053
+ });
1054
+ }
969
1055
  if (error instanceof Error) {
970
1056
  this.error("Error while processing input: " + error.message, msg);
971
1057
  done(error);
972
1058
  } else {
973
1059
  this.error("Unknown error occurred during input handling", msg);
974
- done(new Error("Unknown error during input handling"));
1060
+ done(new Error(errorMsg));
975
1061
  }
976
1062
  }
977
1063
  }