@theotherwillembotha/node-red-circuitbreaker 0.0.53

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/build/Nodes.js ADDED
@@ -0,0 +1,26 @@
1
+
2
+ /*
3
+
4
+ This file was automatically generated using the NODERED Core utility.
5
+ Any modifications to his file will be overwritten the next time the code is regenerated.
6
+
7
+ You have been warned.
8
+
9
+ */
10
+ "use strict";
11
+ const NodeManager = require("@theotherwillembotha/node-red-plugincore").NodeManager;
12
+ const CircuitBreakerConfigNode = require("@theotherwillembotha/node-red-circuitbreaker").CircuitBreakerConfigNode;
13
+ const CircuitBreakerNode = require("@theotherwillembotha/node-red-circuitbreaker").CircuitBreakerNode;
14
+ const CircuitBreakerFaultDetectorNode = require("@theotherwillembotha/node-red-circuitbreaker").CircuitBreakerFaultDetectorNode;
15
+ const CircuitBreakerEventNode = require("@theotherwillembotha/node-red-circuitbreaker").CircuitBreakerEventNode;
16
+ const CircuitBreakerStateNode = require("@theotherwillembotha/node-red-circuitbreaker").CircuitBreakerStateNode;
17
+ module.exports = (RED) => {
18
+ let manager = new NodeManager(RED);
19
+ manager.registerNodeType("CircuitBreakerConfigNode", CircuitBreakerConfigNode);
20
+ manager.registerNodeType("CircuitBreakerNode", CircuitBreakerNode);
21
+ manager.registerNodeType("CircuitBreakerFaultDetectorNode", CircuitBreakerFaultDetectorNode);
22
+ manager.registerNodeType("CircuitBreakerEventNode", CircuitBreakerEventNode);
23
+ manager.registerNodeType("CircuitBreakerStateNode", CircuitBreakerStateNode);
24
+ }
25
+
26
+
@@ -0,0 +1,70 @@
1
+
2
+ /*
3
+
4
+ This file was automatically generated using the NODERED Core utility.
5
+ Any modifications to his file will be overwritten the next time the code is regenerated.
6
+
7
+ You have been warned.
8
+
9
+ */
10
+ "use strict";
11
+ const runtime = require("node-red").runtime;
12
+
13
+
14
+ module.exports = function (RED) {
15
+
16
+ // 1. make a list of all the plugins that need to be installed.
17
+ let pluginList = []
18
+ .map(service => service.getServiceDescriptor())
19
+ .filter(plugin => !RED.plugins.get(plugin.id()));
20
+
21
+ // 2. register a listener if there are any plugins in the pluginList.
22
+ if(pluginList.length > 0){
23
+ RED.events.on('registry:plugin-added', async pluginID => {
24
+
25
+ let addedPlugin = pluginList.find(plugin => plugin.id() === pluginID);
26
+ let plugin = RED.plugins.get(pluginID);
27
+
28
+ if(addedPlugin && plugin.instantiate && !plugin.instance){
29
+ console.log("Deploying instance of: " + plugin.id);
30
+ plugin.instance = new plugin.class();
31
+
32
+ // instantiate the plugin.
33
+ await plugin.instance.init(RED);
34
+
35
+ // publish an event that it has ben deployed.
36
+ RED.events.emit("plugin.instantiated", pluginID);
37
+
38
+ pluginList.splice(pluginList.findIndex(current => current.id() === addedPlugin.id()), 1);
39
+
40
+ // register a flow deployment listener.
41
+ let startupDeployment = true;
42
+ RED.events.on('runtime-event', async (event) => {
43
+ // startup deployment.
44
+ if ("runtime-deploy" === event?.id && startupDeployment) {
45
+ console.log("STARTUP DEPLOYMENT");
46
+ startupDeployment = false;
47
+ const flows = await runtime.flows.getFlows({});
48
+ await plugin.instance.onDeploy(flows);
49
+ }
50
+
51
+ // stopping flows on redeployment.
52
+ if ("runtime-state" === event?.id && event?.payload?.state === "stop" && event?.payload?.deploy) {
53
+ console.log("REDEPLOY!");
54
+ const flows = await runtime.flows.getFlows({});
55
+ await plugin.instance.onDeploy(flows);
56
+ }
57
+ });
58
+ }
59
+ });
60
+ }
61
+
62
+ // 3. register the plugins.
63
+ [...pluginList].forEach(plugin => {
64
+ RED.plugins.registerPlugin(plugin.id(), {
65
+ type: plugin.type(),
66
+ instantiate:true,
67
+ class: plugin.clazz()
68
+ });
69
+ })
70
+ };
@@ -0,0 +1,89 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.CircuitBreakerEventType = exports.BreakerContext = exports.CircuitBreakerConfigNode = exports.CircuitBreakerDefaultState = void 0;
13
+ const node_red_plugincore_1 = require("@theotherwillembotha/node-red-plugincore");
14
+ var CircuitBreakerDefaultState;
15
+ (function (CircuitBreakerDefaultState) {
16
+ CircuitBreakerDefaultState["Closed"] = "Closed";
17
+ CircuitBreakerDefaultState["Open"] = "Open";
18
+ })(CircuitBreakerDefaultState || (exports.CircuitBreakerDefaultState = CircuitBreakerDefaultState = {}));
19
+ let CircuitBreakerConfigNode = class CircuitBreakerConfigNode extends node_red_plugincore_1.ConfigNode {
20
+ constructor(node, config) {
21
+ super(node, config);
22
+ this._eventListeners = [];
23
+ this._context = new BreakerContext();
24
+ this._open = config.defaultState === CircuitBreakerDefaultState.Open;
25
+ }
26
+ isOpen() {
27
+ return this._open;
28
+ }
29
+ trip() {
30
+ this._open = true;
31
+ let event = {
32
+ state: CircuitBreakerEventType.Trip
33
+ };
34
+ this._eventListeners.forEach(listener => listener(event));
35
+ }
36
+ reset() {
37
+ this._open = false;
38
+ let event = {
39
+ state: CircuitBreakerEventType.Reset
40
+ };
41
+ this._eventListeners.forEach(listener => listener(event));
42
+ }
43
+ addEventListener(listener) {
44
+ this._eventListeners.push(listener);
45
+ return listener;
46
+ }
47
+ removeEventListener(listener) {
48
+ let index = this._eventListeners.indexOf(listener);
49
+ if (index >= 0) {
50
+ this._eventListeners = this._eventListeners.splice(index, 1);
51
+ }
52
+ }
53
+ context() {
54
+ return this._context;
55
+ }
56
+ };
57
+ exports.CircuitBreakerConfigNode = CircuitBreakerConfigNode;
58
+ exports.CircuitBreakerConfigNode = CircuitBreakerConfigNode = __decorate([
59
+ (0, node_red_plugincore_1.NodeDescription)({
60
+ id: "CircuitBreakerConfigNode",
61
+ name: "Circuit Breaker Config Node",
62
+ group: "config",
63
+ sourceFile: node_red_plugincore_1.SourceUtility.getSourcePath("/build/", "/src/") + "CircuitBreakerConfigNode.html",
64
+ package: "@theotherwillembotha/node-red-circuitbreaker",
65
+ tags: ["CircuitBreaker"]
66
+ }),
67
+ __metadata("design:paramtypes", [Object, Object])
68
+ ], CircuitBreakerConfigNode);
69
+ class BreakerContext {
70
+ constructor() {
71
+ this.values = {};
72
+ }
73
+ get(id, defaultValue) {
74
+ let value = this.values[id];
75
+ if (value === undefined) {
76
+ value = this.set(id, defaultValue);
77
+ }
78
+ return value;
79
+ }
80
+ set(id, value) {
81
+ return this.values[id] = value;
82
+ }
83
+ }
84
+ exports.BreakerContext = BreakerContext;
85
+ var CircuitBreakerEventType;
86
+ (function (CircuitBreakerEventType) {
87
+ CircuitBreakerEventType["Trip"] = "Trip";
88
+ CircuitBreakerEventType["Reset"] = "Reset";
89
+ })(CircuitBreakerEventType || (exports.CircuitBreakerEventType = CircuitBreakerEventType = {}));
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.CircuitBreakerEventNode = void 0;
13
+ const node_red_plugincore_1 = require("@theotherwillembotha/node-red-plugincore");
14
+ const node_red_plugincore_2 = require("@theotherwillembotha/node-red-plugincore");
15
+ const node_red_plugincore_3 = require("@theotherwillembotha/node-red-plugincore");
16
+ const CircuitBreakerConfigNode_1 = require("./CircuitBreakerConfigNode");
17
+ let CircuitBreakerEventNode = class CircuitBreakerEventNode extends node_red_plugincore_1.BaseNode {
18
+ constructor(node, config) {
19
+ super(node, config);
20
+ this._circuitBreakerConfigNode = node_red_plugincore_1.NodeManager.RED.nodes.getNode(config.circuitbreakerconfig).node();
21
+ this._eventListener = this._circuitBreakerConfigNode.addEventListener(event => {
22
+ if (event.state === CircuitBreakerConfigNode_1.CircuitBreakerEventType.Trip) {
23
+ this.tripCounter.inc();
24
+ this.log.log(event);
25
+ this.node().send([event, null]);
26
+ }
27
+ if (event.state === CircuitBreakerConfigNode_1.CircuitBreakerEventType.Reset) {
28
+ this.resetCounter.inc();
29
+ this.log.log(event);
30
+ this.node().send([null, event]);
31
+ }
32
+ });
33
+ this.node().on("close", () => {
34
+ this._circuitBreakerConfigNode.removeEventListener(this._eventListener);
35
+ });
36
+ }
37
+ };
38
+ exports.CircuitBreakerEventNode = CircuitBreakerEventNode;
39
+ __decorate([
40
+ (0, node_red_plugincore_3.Logger)(),
41
+ __metadata("design:type", Object)
42
+ ], CircuitBreakerEventNode.prototype, "log", void 0);
43
+ __decorate([
44
+ (0, node_red_plugincore_2.Metrics)({ name: "tripCounter", type: node_red_plugincore_2.MetricType.Counter, description: "number of times the circuit breaker tripped" }),
45
+ __metadata("design:type", node_red_plugincore_2.CounterMetric)
46
+ ], CircuitBreakerEventNode.prototype, "tripCounter", void 0);
47
+ __decorate([
48
+ (0, node_red_plugincore_2.Metrics)({ name: "resetCounter", type: node_red_plugincore_2.MetricType.Counter, description: "number of times the circuit breaker was reset" }),
49
+ __metadata("design:type", node_red_plugincore_2.CounterMetric)
50
+ ], CircuitBreakerEventNode.prototype, "resetCounter", void 0);
51
+ exports.CircuitBreakerEventNode = CircuitBreakerEventNode = __decorate([
52
+ (0, node_red_plugincore_1.NodeDescription)({
53
+ id: "CircuitBreakerEventNode",
54
+ name: "Circuit Breaker Event Node",
55
+ group: "circuitbreaker",
56
+ sourceFile: node_red_plugincore_1.SourceUtility.getSourcePath("/build/", "/src/") + "CircuitBreakerEventNode.html",
57
+ package: "@theotherwillembotha/node-red-circuitbreaker",
58
+ dependencies: [CircuitBreakerConfigNode_1.CircuitBreakerConfigNode],
59
+ templates: [
60
+ { template: node_red_plugincore_3.LoggerTemplate, config: {} },
61
+ { template: node_red_plugincore_2.MetricsTemplate, config: {} },
62
+ ],
63
+ tags: ["CircuitBreaker"]
64
+ }),
65
+ __metadata("design:paramtypes", [Object, Object])
66
+ ], CircuitBreakerEventNode);
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.CircuitBreakerFaultDetectorNode = void 0;
13
+ const node_red_plugincore_1 = require("@theotherwillembotha/node-red-plugincore");
14
+ const node_red_plugincore_2 = require("@theotherwillembotha/node-red-plugincore");
15
+ const node_red_plugincore_3 = require("@theotherwillembotha/node-red-plugincore");
16
+ const node_red_plugincore_4 = require("@theotherwillembotha/node-red-plugincore");
17
+ const CircuitBreakerConfigNode_1 = require("./CircuitBreakerConfigNode");
18
+ let CircuitBreakerFaultDetectorNode = class CircuitBreakerFaultDetectorNode extends node_red_plugincore_1.BaseNode {
19
+ constructor(node, config) {
20
+ super(node, config);
21
+ let _this = this;
22
+ // get a reference to the reolink clients.
23
+ this._configNode = node_red_plugincore_1.NodeManager.RED.nodes.getNode(config.circuitbreakerconfig).node();
24
+ this._breakerFaultFunction = new Function('msg', config.faultFunction);
25
+ this._breakerTripFunction = new Function('breaker', config.tripFunction);
26
+ }
27
+ async messageReceived(message) {
28
+ this.log.log(message);
29
+ this.counter.inc();
30
+ // perform the fault check
31
+ if (this._breakerFaultFunction(message)) {
32
+ // perform the trip function. if it passes, notify the circuitbreakerconfig.
33
+ if (this._breakerTripFunction(this._configNode)) {
34
+ this._configNode.trip();
35
+ }
36
+ this.node().send([null, message]);
37
+ }
38
+ else {
39
+ // perform the resetFunction. if it passes, notify the circuritbreakerconfig.
40
+ this.node().send([message, null]);
41
+ }
42
+ }
43
+ };
44
+ exports.CircuitBreakerFaultDetectorNode = CircuitBreakerFaultDetectorNode;
45
+ __decorate([
46
+ (0, node_red_plugincore_3.Logger)(),
47
+ __metadata("design:type", Object)
48
+ ], CircuitBreakerFaultDetectorNode.prototype, "log", void 0);
49
+ __decorate([
50
+ (0, node_red_plugincore_2.Metrics)({ name: "counter", type: node_red_plugincore_2.MetricType.Counter, description: "number of requests received" }),
51
+ __metadata("design:type", node_red_plugincore_2.CounterMetric)
52
+ ], CircuitBreakerFaultDetectorNode.prototype, "counter", void 0);
53
+ __decorate([
54
+ (0, node_red_plugincore_1.onInput)(),
55
+ __metadata("design:type", Function),
56
+ __metadata("design:paramtypes", [Object]),
57
+ __metadata("design:returntype", Promise)
58
+ ], CircuitBreakerFaultDetectorNode.prototype, "messageReceived", null);
59
+ exports.CircuitBreakerFaultDetectorNode = CircuitBreakerFaultDetectorNode = __decorate([
60
+ (0, node_red_plugincore_1.NodeDescription)({
61
+ id: "CircuitBreakerFaultDetectorNode",
62
+ name: "Circuit Breaker Fault Detector Node",
63
+ group: "circuitbreaker",
64
+ sourceFile: node_red_plugincore_1.SourceUtility.getSourcePath("/build/", "/src/") + "CircuitBreakerFaultDetectorNode.html",
65
+ package: "@theotherwillembotha/node-red-circuitbreaker",
66
+ dependencies: [CircuitBreakerConfigNode_1.CircuitBreakerConfigNode],
67
+ templates: [
68
+ { template: node_red_plugincore_3.LoggerTemplate, config: {} },
69
+ { template: node_red_plugincore_2.MetricsTemplate, config: {} },
70
+ { template: node_red_plugincore_4.ScriptEditorTemplate, config: {} },
71
+ ],
72
+ tags: ["CircuitBreaker"]
73
+ }),
74
+ __metadata("design:paramtypes", [Object, Object])
75
+ ], CircuitBreakerFaultDetectorNode);
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.CircuitBreakerNode = void 0;
13
+ const node_red_plugincore_1 = require("@theotherwillembotha/node-red-plugincore");
14
+ const node_red_plugincore_2 = require("@theotherwillembotha/node-red-plugincore");
15
+ const node_red_plugincore_3 = require("@theotherwillembotha/node-red-plugincore");
16
+ const CircuitBreakerConfigNode_1 = require("./CircuitBreakerConfigNode");
17
+ const openStatus = { fill: "red", shape: "dot", text: "open" };
18
+ const closedStatus = { fill: "green", shape: "dot", text: "closed" };
19
+ let CircuitBreakerNode = class CircuitBreakerNode extends node_red_plugincore_1.BaseNode {
20
+ constructor(node, config) {
21
+ super(node, config);
22
+ this._configNode = node_red_plugincore_1.NodeManager.RED.nodes.getNode(config.circuitbreakerconfig).node();
23
+ // register a status listener
24
+ this._configNode.addEventListener(event => {
25
+ this.node().status(event.state === CircuitBreakerConfigNode_1.CircuitBreakerEventType.Trip ? openStatus : closedStatus);
26
+ });
27
+ // set the initial status
28
+ this.node().status(this._configNode.isOpen() ? openStatus : closedStatus);
29
+ }
30
+ async messageReceived(message) {
31
+ // check the current state of the node.
32
+ if (this._configNode.isOpen()) {
33
+ this.openCounter.inc();
34
+ this.log.log({ state: "open", data: message });
35
+ this.node().send([null, message]);
36
+ }
37
+ else {
38
+ this.closedCounter.inc();
39
+ this.log.log({ state: "closed", data: message });
40
+ this.node().send([message, null]);
41
+ }
42
+ }
43
+ };
44
+ exports.CircuitBreakerNode = CircuitBreakerNode;
45
+ __decorate([
46
+ (0, node_red_plugincore_3.Logger)(),
47
+ __metadata("design:type", Object)
48
+ ], CircuitBreakerNode.prototype, "log", void 0);
49
+ __decorate([
50
+ (0, node_red_plugincore_2.Metrics)({ name: "closeCounter", type: node_red_plugincore_2.MetricType.Counter, description: "number of requests processed while circuit breaker closed" }),
51
+ __metadata("design:type", node_red_plugincore_2.CounterMetric)
52
+ ], CircuitBreakerNode.prototype, "closedCounter", void 0);
53
+ __decorate([
54
+ (0, node_red_plugincore_2.Metrics)({ name: "openCounter", type: node_red_plugincore_2.MetricType.Counter, description: "number of requests processed while circuit breaker open" }),
55
+ __metadata("design:type", node_red_plugincore_2.CounterMetric)
56
+ ], CircuitBreakerNode.prototype, "openCounter", void 0);
57
+ __decorate([
58
+ (0, node_red_plugincore_1.onInput)(),
59
+ __metadata("design:type", Function),
60
+ __metadata("design:paramtypes", [Object]),
61
+ __metadata("design:returntype", Promise)
62
+ ], CircuitBreakerNode.prototype, "messageReceived", null);
63
+ exports.CircuitBreakerNode = CircuitBreakerNode = __decorate([
64
+ (0, node_red_plugincore_1.NodeDescription)({
65
+ id: "CircuitBreakerNode",
66
+ name: "Circuit Breaker Node",
67
+ group: "circuitbreaker",
68
+ sourceFile: node_red_plugincore_1.SourceUtility.getSourcePath("/build/", "/src/") + "CircuitBreakerNode.html",
69
+ package: "@theotherwillembotha/node-red-circuitbreaker",
70
+ dependencies: [CircuitBreakerConfigNode_1.CircuitBreakerConfigNode],
71
+ templates: [
72
+ { template: node_red_plugincore_3.LoggerTemplate, config: {} },
73
+ { template: node_red_plugincore_2.MetricsTemplate, config: {} },
74
+ ],
75
+ tags: ["CircuitBreaker"]
76
+ }),
77
+ __metadata("design:paramtypes", [Object, Object])
78
+ ], CircuitBreakerNode);
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.CircuitBreakerStateNode = void 0;
13
+ const node_red_plugincore_1 = require("@theotherwillembotha/node-red-plugincore");
14
+ const node_red_plugincore_2 = require("@theotherwillembotha/node-red-plugincore");
15
+ const node_red_plugincore_3 = require("@theotherwillembotha/node-red-plugincore");
16
+ const node_red_plugincore_4 = require("@theotherwillembotha/node-red-plugincore");
17
+ const CircuitBreakerConfigNode_1 = require("./CircuitBreakerConfigNode");
18
+ let CircuitBreakerStateNode = class CircuitBreakerStateNode extends node_red_plugincore_1.BaseNode {
19
+ constructor(node, config) {
20
+ super(node, config);
21
+ this._circuitBreakerConfigNode = node_red_plugincore_1.NodeManager.RED.nodes.getNode(config.circuitbreakerconfig).node();
22
+ if (config.action === CircuitBreakerStateAction.Script) {
23
+ this._breakerScript = new Function('breaker', 'message', config.script);
24
+ }
25
+ }
26
+ onMessageReceived(message) {
27
+ this.log.log(message);
28
+ this.counter.inc();
29
+ // handle the message and change the state based on the mesage.
30
+ if (this.config().action === CircuitBreakerStateAction.Reset) {
31
+ this._circuitBreakerConfigNode.reset();
32
+ }
33
+ if (this.config().action === CircuitBreakerStateAction.Trip) {
34
+ this._circuitBreakerConfigNode.trip();
35
+ }
36
+ if (this.config().action === CircuitBreakerStateAction.Script) {
37
+ this._breakerScript(this._circuitBreakerConfigNode, message);
38
+ }
39
+ this.node().send(message);
40
+ }
41
+ };
42
+ exports.CircuitBreakerStateNode = CircuitBreakerStateNode;
43
+ __decorate([
44
+ (0, node_red_plugincore_3.Logger)(),
45
+ __metadata("design:type", Object)
46
+ ], CircuitBreakerStateNode.prototype, "log", void 0);
47
+ __decorate([
48
+ (0, node_red_plugincore_2.Metrics)({ name: "counter", type: node_red_plugincore_2.MetricType.Counter, description: "number of messages received" }),
49
+ __metadata("design:type", node_red_plugincore_2.CounterMetric)
50
+ ], CircuitBreakerStateNode.prototype, "counter", void 0);
51
+ __decorate([
52
+ (0, node_red_plugincore_1.onInput)(),
53
+ __metadata("design:type", Function),
54
+ __metadata("design:paramtypes", [Object]),
55
+ __metadata("design:returntype", void 0)
56
+ ], CircuitBreakerStateNode.prototype, "onMessageReceived", null);
57
+ exports.CircuitBreakerStateNode = CircuitBreakerStateNode = __decorate([
58
+ (0, node_red_plugincore_1.NodeDescription)({
59
+ id: "CircuitBreakerStateNode",
60
+ name: "Circuit Breaker State Node",
61
+ group: "circuitbreaker",
62
+ sourceFile: node_red_plugincore_1.SourceUtility.getSourcePath("/build/", "/src/") + "CircuitBreakerStateNode.html",
63
+ package: "@theotherwillembotha/node-red-circuitbreaker",
64
+ dependencies: [CircuitBreakerConfigNode_1.CircuitBreakerConfigNode],
65
+ templates: [
66
+ { template: node_red_plugincore_3.LoggerTemplate, config: {} },
67
+ { template: node_red_plugincore_2.MetricsTemplate, config: {} },
68
+ { template: node_red_plugincore_4.ScriptEditorTemplate, config: {} },
69
+ ],
70
+ tags: ["CircuitBreaker"]
71
+ }),
72
+ __metadata("design:paramtypes", [Object, Object])
73
+ ], CircuitBreakerStateNode);
74
+ var CircuitBreakerStateAction;
75
+ (function (CircuitBreakerStateAction) {
76
+ CircuitBreakerStateAction["Reset"] = "Reset";
77
+ CircuitBreakerStateAction["Trip"] = "Trip";
78
+ CircuitBreakerStateAction["Script"] = "Script";
79
+ })(CircuitBreakerStateAction || (CircuitBreakerStateAction = {}));
Binary file
package/build/index.js ADDED
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./circuitbreaker/node/CircuitBreakerConfigNode"), exports);
18
+ __exportStar(require("./circuitbreaker/node/CircuitBreakerNode"), exports);
19
+ __exportStar(require("./circuitbreaker/node/CircuitBreakerFaultDetectorNode"), exports);
20
+ __exportStar(require("./circuitbreaker/node/CircuitBreakerEventNode"), exports);
21
+ __exportStar(require("./circuitbreaker/node/CircuitBreakerStateNode"), exports);
Binary file
package/package.json ADDED
@@ -0,0 +1,59 @@
1
+ {
2
+ "name": "@theotherwillembotha/node-red-circuitbreaker",
3
+ "version": "0.0.53",
4
+ "description": "Circuit Breaker nodes for Node-RED with configurable fault detection, trip conditions, and state management.",
5
+ "main": "./build/index.js",
6
+ "exports": "./build/index.js",
7
+ "author": "Willem Botha (@theotherwillembotha)",
8
+ "license": "ISC",
9
+ "keywords": [
10
+ "node-red",
11
+ "circuit-breaker",
12
+ "fault-tolerance",
13
+ "resilience",
14
+ "reliability"
15
+ ],
16
+ "scripts": {
17
+ "test": "echo \"Error: no test specified\" && exit 1",
18
+ "build": "npm run clean && tsc && npm run generate-nodes && npm run copy-files",
19
+ "clean": "rm -rf ./build",
20
+ "generate-nodes": "node build/GenerateNodes.js",
21
+ "copy-files": "cp -r ./icons ./build/"
22
+ },
23
+ "files": [
24
+ "build/",
25
+ "icons/",
26
+ "documentation/",
27
+ "LICENSE",
28
+ "README.md"
29
+ ],
30
+ "repository": {
31
+ "type": "git",
32
+ "url": "git+https://github.com/theotherwillembotha/nodered_circuitbreaker.git"
33
+ },
34
+ "bugs": {
35
+ "url": "https://github.com/theotherwillembotha/nodered_circuitbreaker/issues"
36
+ },
37
+ "homepage": "https://github.com/theotherwillembotha/nodered_circuitbreaker#readme",
38
+ "engines": {
39
+ "node": ">=18",
40
+ "nodered": ">=4.0.0"
41
+ },
42
+ "dependencies": {
43
+ "@theotherwillembotha/node-red-plugincore": "^0.0.53"
44
+ },
45
+ "devDependencies": {
46
+ "@theotherwillembotha/node-red-plugincore": "../nodered_plugincore",
47
+ "@types/node": "^22.15.16",
48
+ "@types/node-red": "~1.3.5"
49
+ },
50
+ "node-red": {
51
+ "version": ">=4.0.0",
52
+ "nodes": {
53
+ "circuitbreaker": "./build/Nodes.js"
54
+ },
55
+ "plugins": {
56
+ "circuitbreaker": "./build/Plugins.js"
57
+ }
58
+ }
59
+ }