@theotherwillembotha/node-red-plugincore 0.0.55 → 0.2.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 +616 -217
- package/build/GenerateNodes.js +3 -6
- package/build/Nodes.html +3 -1502
- package/build/Nodes.js +5 -15
- package/build/Plugins.html +227 -0
- package/build/Plugins.js +18 -9
- package/build/core/NodeConstructor.d.ts +10 -16
- package/build/core/NodeConstructor.d.ts.map +1 -1
- package/build/core/NodeConstructor.js +112 -156
- package/build/core/NodeGenerator.d.ts.map +1 -1
- package/build/core/NodeGenerator.js +79 -29
- package/build/core/NodeManagerRuntime.d.ts +44 -0
- package/build/core/NodeManagerRuntime.d.ts.map +1 -0
- package/build/core/NodeManagerRuntime.js +140 -0
- package/build/core/Utils.d.ts.map +1 -1
- package/build/core/logger/service/LoggerService.d.ts +6 -5
- package/build/core/logger/service/LoggerService.d.ts.map +1 -1
- package/build/core/logger/service/LoggerService.js +51 -20
- package/build/core/logger/template/LoggerTemplate.d.ts.map +1 -1
- package/build/core/metrics/MetricsDecorator.d.ts +1 -2
- package/build/core/metrics/MetricsDecorator.d.ts.map +1 -1
- package/build/core/metrics/MetricsDecorator.js +89 -116
- package/build/core/metrics/node/CounterMetricConfigNode.d.ts.map +1 -1
- package/build/core/metrics/node/CounterMetricConfigNode.js +4 -5
- package/build/core/metrics/node/GaugeMetricConfigNode.d.ts.map +1 -1
- package/build/core/metrics/node/GaugeMetricConfigNode.js +5 -6
- package/build/core/metrics/node/MetricsConfigNode.d.ts +19 -9
- package/build/core/metrics/node/MetricsConfigNode.d.ts.map +1 -1
- package/build/core/metrics/node/MetricsConfigNode.js +14 -45
- package/build/core/metrics/node/TimerMetricConfigNode.d.ts.map +1 -1
- package/build/core/metrics/node/TimerMetricConfigNode.js +11 -17
- package/build/core/metrics/service/MetricsService.d.ts +110 -114
- package/build/core/metrics/service/MetricsService.d.ts.map +1 -1
- package/build/core/metrics/service/MetricsService.js +122 -339
- package/build/core/metrics/template/CounterMetricTemplate.d.ts.map +1 -1
- package/build/core/metrics/template/GaugeMetricTemplate.d.ts.map +1 -1
- package/build/core/metrics/template/MetricsTemplate.d.ts.map +1 -1
- package/build/core/metrics/template/MetricsTemplate.js +1 -2
- package/build/core/metrics/template/TimerMetricTemplate.d.ts.map +1 -1
- package/build/core/other/node/DelegatedConfigReferenceNode.d.ts +1 -1
- package/build/core/other/node/DelegatedConfigReferenceNode.d.ts.map +1 -1
- package/build/core/other/node/DelegatedConfigReferenceNode.js +1 -1
- package/build/core/other/service/InputService.d.ts.map +1 -1
- package/build/core/other/service/SettingsService.d.ts +1 -2
- package/build/core/other/service/SettingsService.d.ts.map +1 -1
- package/build/core/other/service/SettingsService.js +19 -5
- package/build/core/other/template/BasicTemplate.d.ts.map +1 -1
- package/build/core/other/template/SettingsTemplate.d.ts.map +1 -1
- package/build/core/state/node/InternalStateConfigNode.d.ts +16 -0
- package/build/core/state/node/InternalStateConfigNode.d.ts.map +1 -0
- package/build/core/state/node/InternalStateConfigNode.js +89 -0
- package/build/core/state/node/StateConfigNode.d.ts +24 -0
- package/build/core/state/node/StateConfigNode.d.ts.map +1 -0
- package/build/core/state/node/StateConfigNode.js +22 -0
- package/build/core/state/service/StateService.d.ts +34 -0
- package/build/core/state/service/StateService.d.ts.map +1 -0
- package/build/core/state/service/StateService.js +201 -0
- package/build/core/state/template/StateTemplate.d.ts +8 -0
- package/build/core/state/template/StateTemplate.d.ts.map +1 -0
- package/build/core/state/template/StateTemplate.js +11 -0
- package/build/core/tagging/ServiceDescriptionDecorator.d.ts +10 -0
- package/build/core/tagging/ServiceDescriptionDecorator.d.ts.map +1 -0
- package/build/core/tagging/ServiceDescriptionDecorator.js +10 -0
- package/build/core/tagging/service/NodeTypeService.d.ts +1 -2
- package/build/core/tagging/service/NodeTypeService.d.ts.map +1 -1
- package/build/core/tagging/service/NodeTypeService.js +19 -5
- package/build/core/ui/template/ScriptEditorTemplate.d.ts.map +1 -1
- package/build/core/ui/template/UIHelperTemplate.d.ts.map +1 -1
- package/build/core/webhook/WebhookDecorator.d.ts.map +1 -1
- package/build/core/webhook/WebhookDecorator.js +43 -6
- package/build/core/webhook/node/WebhookServerConfigNode.d.ts.map +1 -1
- package/build/core/webhook/service/ReverseProxyTypeService.d.ts +1 -0
- package/build/core/webhook/service/ReverseProxyTypeService.d.ts.map +1 -1
- package/build/core/webhook/service/WebhookServerService.d.ts +3 -4
- package/build/core/webhook/service/WebhookServerService.d.ts.map +1 -1
- package/build/core/webhook/service/WebhookServerService.js +48 -23
- package/build/core/webhook/template/WebhookTemplate.d.ts.map +1 -1
- package/build/index.d.ts +5 -2
- package/build/index.d.ts.map +1 -1
- package/build/index.js +6 -2
- package/build/runtime/NodeManagerRuntime.js +140 -0
- package/documentation/CounterMetricConfigNode.png +0 -0
- package/documentation/GaugeMetricConfigNode.png +0 -0
- package/documentation/LoggerTemplate.png +0 -0
- package/documentation/MetricsTemplate.png +0 -0
- package/documentation/StateTemplate.png +0 -0
- package/documentation/TimerMetricConfigNode_histogram.png +0 -0
- package/documentation/TimerMetricConfigNode_summary.png +0 -0
- package/documentation/WebhookServerConfigNode.png +0 -0
- package/documentation/WebhookTemplate.png +0 -0
- package/package.json +5 -12
- package/src/GenerateNodes.ts +7 -11
- package/src/core/NodeConstructor.ts +134 -197
- package/src/core/NodeGenerator.ts +88 -34
- package/src/core/NodeManagerRuntime.ts +179 -0
- package/src/core/logger/service/LoggerService.ts +39 -26
- package/src/core/logger/template/LoggerTemplate.html +13 -8
- package/src/core/metrics/MetricsDecorator.ts +140 -168
- package/src/core/metrics/node/CounterMetricConfigNode.ts +20 -20
- package/src/core/metrics/node/GaugeMetricConfigNode.ts +24 -25
- package/src/core/metrics/node/MetricsConfigNode.ts +29 -48
- package/src/core/metrics/node/TimerMetricConfigNode.html +2 -2
- package/src/core/metrics/node/TimerMetricConfigNode.ts +50 -59
- package/src/core/metrics/service/MetricsService.ts +214 -489
- package/src/core/metrics/template/CounterMetricTemplate.html +0 -1
- package/src/core/metrics/template/GaugeMetricTemplate.html +1 -1
- package/src/core/metrics/template/MetricsTemplate.html +132 -13
- package/src/core/metrics/template/MetricsTemplate.ts +3 -4
- package/src/core/other/node/DelegatedConfigReferenceNode.ts +1 -1
- package/src/core/other/service/SettingsService.ts +6 -10
- package/src/core/other/template/BasicTemplate.html +5 -2
- package/src/core/state/node/InternalStateConfigNode.html +77 -0
- package/src/core/state/node/InternalStateConfigNode.ts +102 -0
- package/src/core/state/node/StateConfigNode.ts +29 -0
- package/src/core/state/service/StateService.ts +180 -0
- package/src/core/state/template/StateTemplate.html +244 -0
- package/src/core/state/template/StateTemplate.ts +17 -0
- package/src/core/tagging/ServiceDescriptionDecorator.ts +23 -0
- package/src/core/tagging/service/NodeTypeService.ts +6 -11
- package/src/core/ui/template/UIHelperTemplate.html +41 -26
- package/src/core/webhook/WebhookDecorator.ts +53 -10
- package/src/core/webhook/service/ReverseProxyTypeService.ts +1 -0
- package/src/core/webhook/service/WebhookServerService.ts +39 -28
- package/src/core/webhook/template/WebhookTemplate.html +29 -36
- package/src/index.ts +7 -2
- package/build/core/logger/node/ConsoleLoggerConfigNode.d.ts +0 -20
- package/build/core/logger/node/ConsoleLoggerConfigNode.d.ts.map +0 -1
- package/build/core/logger/node/ConsoleLoggerConfigNode.html +0 -90
- package/build/core/logger/node/ConsoleLoggerConfigNode.js +0 -62
- package/build/core/logger/node/RestLoggerConfigNode.d.ts +0 -40
- package/build/core/logger/node/RestLoggerConfigNode.d.ts.map +0 -1
- package/build/core/logger/node/RestLoggerConfigNode.html +0 -183
- package/build/core/logger/node/RestLoggerConfigNode.js +0 -128
- package/build/core/logger/template/LoggerTemplate.html +0 -331
- package/build/core/metrics/node/CounterMetricConfigNode.html +0 -48
- package/build/core/metrics/node/GaugeMetricConfigNode.html +0 -48
- package/build/core/metrics/node/MetricsConfigNode.html +0 -21
- package/build/core/metrics/node/TimerMetricConfigNode.html +0 -190
- package/build/core/metrics/template/CounterMetricTemplate.html +0 -40
- package/build/core/metrics/template/GaugeMetricTemplate.html +0 -39
- package/build/core/metrics/template/MetricsTemplate.html +0 -54
- package/build/core/metrics/template/TimerMetricTemplate.html +0 -39
- package/build/core/other/node/DelegatedConfigReferenceNode.html +0 -1
- package/build/core/other/template/BasicTemplate.html +0 -76
- package/build/core/other/template/SettingsTemplate.html +0 -128
- package/build/core/ui/template/ScriptEditorTemplate.html +0 -50
- package/build/core/ui/template/UIHelperTemplate.html +0 -229
- package/build/core/webhook/node/WebhookServerConfigNode.html +0 -61
- package/build/core/webhook/template/WebhookTemplate.html +0 -442
- package/documentation/ConsoleLoggerConfigNode.png +0 -0
- package/documentation/MetricsConfigNode.png +0 -0
- package/documentation/RestLoggerConfigNode.png +0 -0
- package/documentation/TimerMetricConfigNode.png +0 -0
- package/documentation/WebhookNode.png +0 -0
- package/src/core/logger/node/ConsoleLoggerConfigNode.html +0 -90
- package/src/core/logger/node/ConsoleLoggerConfigNode.ts +0 -71
- package/src/core/logger/node/RestLoggerConfigNode.html +0 -183
- package/src/core/logger/node/RestLoggerConfigNode.ts +0 -170
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Node } from "node-red";
|
|
2
|
+
import { ConfigNodeConfig } from "../../NodeConstructor";
|
|
3
|
+
import { StateHandle } from "../service/StateService";
|
|
4
|
+
import { StateConfigNode } from "./StateConfigNode";
|
|
5
|
+
interface InternalStateConfigNodeConfig extends ConfigNodeConfig {
|
|
6
|
+
survivesRedeploy: boolean;
|
|
7
|
+
survivesRestart: boolean;
|
|
8
|
+
}
|
|
9
|
+
export declare class InternalStateConfigNode extends StateConfigNode {
|
|
10
|
+
private _survivesRedeploy;
|
|
11
|
+
private _survivesRestart;
|
|
12
|
+
constructor(node: Node, config: InternalStateConfigNodeConfig);
|
|
13
|
+
createHandle(): StateHandle;
|
|
14
|
+
}
|
|
15
|
+
export {};
|
|
16
|
+
//# sourceMappingURL=InternalStateConfigNode.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"InternalStateConfigNode.d.ts","sourceRoot":"","sources":["../../../../src/core/state/node/InternalStateConfigNode.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAChC,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAGzD,OAAO,EAAgB,WAAW,EAAE,MAAM,yBAAyB,CAAC;AACpE,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD,UAAU,6BAA8B,SAAQ,gBAAgB;IAC5D,gBAAgB,EAAE,OAAO,CAAC;IAC1B,eAAe,EAAE,OAAO,CAAC;CAC5B;AA4DD,qBASa,uBAAwB,SAAQ,eAAe;IACxD,OAAO,CAAC,iBAAiB,CAAU;IACnC,OAAO,CAAC,gBAAgB,CAAU;IAElC,YAAY,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,6BAA6B,EAS5D;IAEM,YAAY,IAAI,WAAW,CAMjC;CACJ"}
|
|
@@ -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.InternalStateConfigNode = void 0;
|
|
13
|
+
const NodeDescriptionDecorator_1 = require("../../tagging/NodeDescriptionDecorator");
|
|
14
|
+
const NodeGenerator_1 = require("../../NodeGenerator");
|
|
15
|
+
const StateService_1 = require("../service/StateService");
|
|
16
|
+
const StateConfigNode_1 = require("./StateConfigNode");
|
|
17
|
+
class InternalStateHandle {
|
|
18
|
+
constructor(nodeId, survivesRedeploy, survivesRestart) {
|
|
19
|
+
this._callback = null;
|
|
20
|
+
this._nodeId = nodeId;
|
|
21
|
+
this._survivesRedeploy = survivesRedeploy;
|
|
22
|
+
this._survivesRestart = survivesRestart;
|
|
23
|
+
this._init();
|
|
24
|
+
}
|
|
25
|
+
_init() {
|
|
26
|
+
// On process restart, memory is empty. If this node survives restarts, load from file.
|
|
27
|
+
if (this._survivesRestart && StateService_1.StateService.getMemory(this._nodeId) === null) {
|
|
28
|
+
const fileValue = StateService_1.StateService.readFile(this._nodeId);
|
|
29
|
+
if (fileValue !== null) {
|
|
30
|
+
StateService_1.StateService.setMemory(this._nodeId, fileValue);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
// Default state seeding is the consumer node's responsibility - call set() after get() returns null.
|
|
34
|
+
}
|
|
35
|
+
_read() {
|
|
36
|
+
return StateService_1.StateService.getMemory(this._nodeId);
|
|
37
|
+
}
|
|
38
|
+
_write(value) {
|
|
39
|
+
StateService_1.StateService.setMemory(this._nodeId, value);
|
|
40
|
+
if (this._survivesRestart) {
|
|
41
|
+
StateService_1.StateService.writeFile(this._nodeId, value);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
get() {
|
|
45
|
+
return Promise.resolve(this._read());
|
|
46
|
+
}
|
|
47
|
+
set(stateName) {
|
|
48
|
+
this._write(stateName);
|
|
49
|
+
StateService_1.StateService.notifySubscribers(this._nodeId, stateName);
|
|
50
|
+
return Promise.resolve();
|
|
51
|
+
}
|
|
52
|
+
subscribe(callback) {
|
|
53
|
+
this._callback = callback;
|
|
54
|
+
StateService_1.StateService.addSubscriber(this._nodeId, callback);
|
|
55
|
+
}
|
|
56
|
+
unsubscribe() {
|
|
57
|
+
if (this._callback) {
|
|
58
|
+
StateService_1.StateService.removeSubscriber(this._nodeId, this._callback);
|
|
59
|
+
this._callback = null;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
let InternalStateConfigNode = class InternalStateConfigNode extends StateConfigNode_1.StateConfigNode {
|
|
64
|
+
constructor(node, config) {
|
|
65
|
+
super(node, config);
|
|
66
|
+
this._survivesRedeploy = config.survivesRedeploy ?? false;
|
|
67
|
+
this._survivesRestart = config.survivesRestart ?? false;
|
|
68
|
+
StateService_1.StateService.registerConfig(config.id, {
|
|
69
|
+
survivesRedeploy: this._survivesRedeploy,
|
|
70
|
+
survivesRestart: this._survivesRestart,
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
createHandle() {
|
|
74
|
+
return new InternalStateHandle(this.id(), this._survivesRedeploy, this._survivesRestart);
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
exports.InternalStateConfigNode = InternalStateConfigNode;
|
|
78
|
+
exports.InternalStateConfigNode = InternalStateConfigNode = __decorate([
|
|
79
|
+
(0, NodeDescriptionDecorator_1.NodeDescription)({
|
|
80
|
+
id: "InternalStateConfigNode",
|
|
81
|
+
name: "Internal State Config Node",
|
|
82
|
+
group: "config",
|
|
83
|
+
sourceFile: NodeGenerator_1.SourceUtility.getSourcePath("/build/", "/src/") + "InternalStateConfigNode.html",
|
|
84
|
+
package: "@theotherwillembotha/node-red-plugincore",
|
|
85
|
+
dependencies: [StateService_1.StateService],
|
|
86
|
+
tags: ["StateProvider"]
|
|
87
|
+
}),
|
|
88
|
+
__metadata("design:paramtypes", [Object, Object])
|
|
89
|
+
], InternalStateConfigNode);
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Node } from "node-red";
|
|
2
|
+
import { ConfigNode, ConfigNodeConfig } from "../../NodeConstructor";
|
|
3
|
+
import { StateHandle } from "../service/StateService";
|
|
4
|
+
/**
|
|
5
|
+
* Abstract base for all state provider config nodes.
|
|
6
|
+
*
|
|
7
|
+
* Concrete implementations (e.g. InternalStateConfigNode, ZookeeperStateConfigNode) extend this
|
|
8
|
+
* class, decorate with @NodeDescription + tags: ["StateProvider"], and implement createHandle()
|
|
9
|
+
* to return their backend-specific StateHandle.
|
|
10
|
+
*
|
|
11
|
+
* This class is intentionally NOT decorated with @NodeDescription - it is never registered as a
|
|
12
|
+
* Node-RED node type directly. Only concrete subclasses are registered.
|
|
13
|
+
*/
|
|
14
|
+
export declare abstract class StateConfigNode extends ConfigNode<ConfigNodeConfig> {
|
|
15
|
+
constructor(node: Node, config: ConfigNodeConfig);
|
|
16
|
+
/**
|
|
17
|
+
* Creates a new StateHandle for a consumer node.
|
|
18
|
+
* Called once per consumer that references this config node.
|
|
19
|
+
* Each handle maintains its own subscriber slot, so multiple consumers
|
|
20
|
+
* can independently subscribe and unsubscribe without interfering.
|
|
21
|
+
*/
|
|
22
|
+
abstract createHandle(): StateHandle;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=StateConfigNode.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StateConfigNode.d.ts","sourceRoot":"","sources":["../../../../src/core/state/node/StateConfigNode.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAChC,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACrE,OAAO,EAAE,WAAW,EAAgB,MAAM,yBAAyB,CAAC;AAEpE;;;;;;;;;GASG;AACH,8BAAsB,eAAgB,SAAQ,UAAU,CAAC,gBAAgB,CAAC;IAEtE,YAAY,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,gBAAgB,EAG/C;IAED;;;;;OAKG;IACH,SAAgB,YAAY,IAAI,WAAW,CAAC;CAC/C"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.StateConfigNode = void 0;
|
|
4
|
+
const NodeConstructor_1 = require("../../NodeConstructor");
|
|
5
|
+
const StateService_1 = require("../service/StateService");
|
|
6
|
+
/**
|
|
7
|
+
* Abstract base for all state provider config nodes.
|
|
8
|
+
*
|
|
9
|
+
* Concrete implementations (e.g. InternalStateConfigNode, ZookeeperStateConfigNode) extend this
|
|
10
|
+
* class, decorate with @NodeDescription + tags: ["StateProvider"], and implement createHandle()
|
|
11
|
+
* to return their backend-specific StateHandle.
|
|
12
|
+
*
|
|
13
|
+
* This class is intentionally NOT decorated with @NodeDescription - it is never registered as a
|
|
14
|
+
* Node-RED node type directly. Only concrete subclasses are registered.
|
|
15
|
+
*/
|
|
16
|
+
class StateConfigNode extends NodeConstructor_1.ConfigNode {
|
|
17
|
+
constructor(node, config) {
|
|
18
|
+
super(node, config);
|
|
19
|
+
StateService_1.StateService.registerFactory(config.id, () => this.createHandle());
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.StateConfigNode = StateConfigNode;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { BaseService, FlowDeployment } from "../../NodeConstructor";
|
|
2
|
+
import { NodeAPI, NodeAPISettingsWithData } from "node-red";
|
|
3
|
+
export interface StateHandle {
|
|
4
|
+
get(): Promise<string | null>;
|
|
5
|
+
set(stateName: string): Promise<void>;
|
|
6
|
+
subscribe(callback: (stateName: string) => void): void;
|
|
7
|
+
unsubscribe(): void;
|
|
8
|
+
}
|
|
9
|
+
export declare class DoNothingStateHandle implements StateHandle {
|
|
10
|
+
get(): Promise<string | null>;
|
|
11
|
+
set(_stateName: string): Promise<void>;
|
|
12
|
+
subscribe(_callback: (stateName: string) => void): void;
|
|
13
|
+
unsubscribe(): void;
|
|
14
|
+
}
|
|
15
|
+
export declare class StateService extends BaseService {
|
|
16
|
+
constructor();
|
|
17
|
+
init(red: NodeAPI<NodeAPISettingsWithData>): void;
|
|
18
|
+
deinit(_red: NodeAPI<NodeAPISettingsWithData>): void;
|
|
19
|
+
onDeploy(deployment: FlowDeployment): Promise<void>;
|
|
20
|
+
static registerFactory(nodeId: string, factory: () => StateHandle): void;
|
|
21
|
+
static registerConfig(nodeId: string, config: {
|
|
22
|
+
survivesRedeploy: boolean;
|
|
23
|
+
survivesRestart: boolean;
|
|
24
|
+
}): void;
|
|
25
|
+
static createHandle(stateReference: string): StateHandle;
|
|
26
|
+
static getMemory(nodeId: string): string | null;
|
|
27
|
+
static setMemory(nodeId: string, value: string): void;
|
|
28
|
+
static readFile(nodeId: string): string | null;
|
|
29
|
+
static writeFile(nodeId: string, value: string): void;
|
|
30
|
+
static addSubscriber(nodeId: string, callback: (s: string) => void): void;
|
|
31
|
+
static removeSubscriber(nodeId: string, callback: (s: string) => void): void;
|
|
32
|
+
static notifySubscribers(nodeId: string, value: string): void;
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=StateService.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StateService.d.ts","sourceRoot":"","sources":["../../../../src/core/state/service/StateService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAEpE,OAAO,EAAE,OAAO,EAAE,uBAAuB,EAAE,MAAM,UAAU,CAAC;AAQ5D,MAAM,WAAW,WAAW;IACxB,GAAG,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IAC9B,GAAG,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACtC,SAAS,CAAC,QAAQ,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,IAAI,GAAG,IAAI,CAAC;IACvD,WAAW,IAAI,IAAI,CAAC;CACvB;AAED,qBAAa,oBAAqB,YAAW,WAAW;IAC7C,GAAG,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAkC;IAC/D,GAAG,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAA8B;IACpE,SAAS,CAAC,SAAS,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,IAAI,GAAG,IAAI,CAAG;IAC1D,WAAW,IAAI,IAAI,CAAG;CAChC;AAgDD,qBAMa,YAAa,SAAQ,WAAW;IAEzC,cAEC;IAEM,IAAI,CAAC,GAAG,EAAE,OAAO,CAAC,uBAAuB,CAAC,GAAG,IAAI,CAEvD;IAEM,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,uBAAuB,CAAC,GAAG,IAAI,CAAG;IAEjD,QAAQ,CAAC,UAAU,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC,CAsB/D;IAID,OAAc,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,WAAW,GAAG,IAAI,CAE9E;IAED,OAAc,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE;QAAE,gBAAgB,EAAE,OAAO,CAAC;QAAC,eAAe,EAAE,OAAO,CAAA;KAAE,GAAG,IAAI,CAElH;IAID,OAAc,YAAY,CAAC,cAAc,EAAE,MAAM,GAAG,WAAW,CAI9D;IAID,OAAc,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAErD;IAED,OAAc,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAE3D;IAID,OAAc,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAUpD;IAED,OAAc,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAM3D;IAID,OAAc,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,IAAI,GAAG,IAAI,CAI/E;IAED,OAAc,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,IAAI,GAAG,IAAI,CAElF;IAED,OAAc,iBAAiB,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAInE;CACJ"}
|
|
@@ -0,0 +1,201 @@
|
|
|
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
19
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
20
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
21
|
+
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;
|
|
22
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
23
|
+
};
|
|
24
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
25
|
+
var ownKeys = function(o) {
|
|
26
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
27
|
+
var ar = [];
|
|
28
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
29
|
+
return ar;
|
|
30
|
+
};
|
|
31
|
+
return ownKeys(o);
|
|
32
|
+
};
|
|
33
|
+
return function (mod) {
|
|
34
|
+
if (mod && mod.__esModule) return mod;
|
|
35
|
+
var result = {};
|
|
36
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
37
|
+
__setModuleDefault(result, mod);
|
|
38
|
+
return result;
|
|
39
|
+
};
|
|
40
|
+
})();
|
|
41
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
42
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
43
|
+
};
|
|
44
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
45
|
+
exports.StateService = exports.DoNothingStateHandle = void 0;
|
|
46
|
+
const NodeConstructor_1 = require("../../NodeConstructor");
|
|
47
|
+
const ServiceDescriptionDecorator_1 = require("../../tagging/ServiceDescriptionDecorator");
|
|
48
|
+
const fs = __importStar(require("fs"));
|
|
49
|
+
const path = __importStar(require("path"));
|
|
50
|
+
class DoNothingStateHandle {
|
|
51
|
+
get() { return Promise.resolve(null); }
|
|
52
|
+
set(_stateName) { return Promise.resolve(); }
|
|
53
|
+
subscribe(_callback) { }
|
|
54
|
+
unsubscribe() { }
|
|
55
|
+
}
|
|
56
|
+
exports.DoNothingStateHandle = DoNothingStateHandle;
|
|
57
|
+
// (StateReference removed - stateEnabled is no longer optional; consumers pass the ID directly)
|
|
58
|
+
// ******************************************************* //
|
|
59
|
+
// Global Store Keys //
|
|
60
|
+
// ******************************************************* //
|
|
61
|
+
const _GLOBAL_STATE_MEMORY_KEY = '__plugincore_internalstate_memory__';
|
|
62
|
+
const _GLOBAL_STATE_SUBS_KEY = '__plugincore_internalstate_subscribers__';
|
|
63
|
+
const _GLOBAL_STATE_FACTORIES_KEY = '__plugincore_state_factories__';
|
|
64
|
+
const _GLOBAL_STATE_CONFIG_KEY = '__plugincore_state_config__';
|
|
65
|
+
const _GLOBAL_STATE_USERDIR_KEY = '__plugincore_state_userDir__';
|
|
66
|
+
function getMemoryStore() {
|
|
67
|
+
if (!global[_GLOBAL_STATE_MEMORY_KEY])
|
|
68
|
+
global[_GLOBAL_STATE_MEMORY_KEY] = new Map();
|
|
69
|
+
return global[_GLOBAL_STATE_MEMORY_KEY];
|
|
70
|
+
}
|
|
71
|
+
function getSubscriberStore() {
|
|
72
|
+
if (!global[_GLOBAL_STATE_SUBS_KEY])
|
|
73
|
+
global[_GLOBAL_STATE_SUBS_KEY] = new Map();
|
|
74
|
+
return global[_GLOBAL_STATE_SUBS_KEY];
|
|
75
|
+
}
|
|
76
|
+
function getFactoryStore() {
|
|
77
|
+
if (!global[_GLOBAL_STATE_FACTORIES_KEY])
|
|
78
|
+
global[_GLOBAL_STATE_FACTORIES_KEY] = new Map();
|
|
79
|
+
return global[_GLOBAL_STATE_FACTORIES_KEY];
|
|
80
|
+
}
|
|
81
|
+
function getConfigStore() {
|
|
82
|
+
if (!global[_GLOBAL_STATE_CONFIG_KEY])
|
|
83
|
+
global[_GLOBAL_STATE_CONFIG_KEY] = new Map();
|
|
84
|
+
return global[_GLOBAL_STATE_CONFIG_KEY];
|
|
85
|
+
}
|
|
86
|
+
function getUserDir() {
|
|
87
|
+
return global[_GLOBAL_STATE_USERDIR_KEY];
|
|
88
|
+
}
|
|
89
|
+
function stateFilePath(nodeId) {
|
|
90
|
+
const userDir = getUserDir();
|
|
91
|
+
if (!userDir)
|
|
92
|
+
return null;
|
|
93
|
+
return path.join(userDir, 'internalstate', nodeId + '.json');
|
|
94
|
+
}
|
|
95
|
+
// ******************************************************* //
|
|
96
|
+
// StateService //
|
|
97
|
+
// ******************************************************* //
|
|
98
|
+
let StateService = class StateService extends NodeConstructor_1.BaseService {
|
|
99
|
+
constructor() {
|
|
100
|
+
super("StateService");
|
|
101
|
+
}
|
|
102
|
+
init(red) {
|
|
103
|
+
global[_GLOBAL_STATE_USERDIR_KEY] = red.settings.userDir;
|
|
104
|
+
}
|
|
105
|
+
deinit(_red) { }
|
|
106
|
+
async onDeploy(deployment) {
|
|
107
|
+
const flowIds = new Set(deployment.flows.map(e => e.id));
|
|
108
|
+
const factories = getFactoryStore();
|
|
109
|
+
const configs = getConfigStore();
|
|
110
|
+
const memory = getMemoryStore();
|
|
111
|
+
// Remove factories for config nodes no longer in the flow.
|
|
112
|
+
factories.forEach((_, nodeId) => {
|
|
113
|
+
if (!flowIds.has(nodeId))
|
|
114
|
+
factories.delete(nodeId);
|
|
115
|
+
});
|
|
116
|
+
// Clear memory for state config nodes that are gone or do not survive redeploy.
|
|
117
|
+
configs.forEach((cfg, nodeId) => {
|
|
118
|
+
if (!flowIds.has(nodeId)) {
|
|
119
|
+
memory.delete(nodeId);
|
|
120
|
+
configs.delete(nodeId);
|
|
121
|
+
}
|
|
122
|
+
else if (!cfg.survivesRedeploy && !cfg.survivesRestart) {
|
|
123
|
+
memory.delete(nodeId);
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
return Promise.resolve();
|
|
127
|
+
}
|
|
128
|
+
// ---- Factory registration (called by StateConfigNode subclasses) ----
|
|
129
|
+
static registerFactory(nodeId, factory) {
|
|
130
|
+
getFactoryStore().set(nodeId, factory);
|
|
131
|
+
}
|
|
132
|
+
static registerConfig(nodeId, config) {
|
|
133
|
+
getConfigStore().set(nodeId, config);
|
|
134
|
+
}
|
|
135
|
+
// ---- Handle creation (called by consumer nodes) ----
|
|
136
|
+
static createHandle(stateReference) {
|
|
137
|
+
if (!stateReference)
|
|
138
|
+
return new DoNothingStateHandle();
|
|
139
|
+
const factory = getFactoryStore().get(stateReference);
|
|
140
|
+
return factory ? factory() : new DoNothingStateHandle();
|
|
141
|
+
}
|
|
142
|
+
// ---- Memory store (used by InternalStateHandle) ----
|
|
143
|
+
static getMemory(nodeId) {
|
|
144
|
+
return getMemoryStore().get(nodeId) ?? null;
|
|
145
|
+
}
|
|
146
|
+
static setMemory(nodeId, value) {
|
|
147
|
+
getMemoryStore().set(nodeId, value);
|
|
148
|
+
}
|
|
149
|
+
// ---- File store (used by InternalStateHandle) ----
|
|
150
|
+
static readFile(nodeId) {
|
|
151
|
+
const filePath = stateFilePath(nodeId);
|
|
152
|
+
if (!filePath)
|
|
153
|
+
return null;
|
|
154
|
+
try {
|
|
155
|
+
if (!fs.existsSync(filePath))
|
|
156
|
+
return null;
|
|
157
|
+
const content = fs.readFileSync(filePath, 'utf8');
|
|
158
|
+
return JSON.parse(content).value ?? null;
|
|
159
|
+
}
|
|
160
|
+
catch {
|
|
161
|
+
return null;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
static writeFile(nodeId, value) {
|
|
165
|
+
const filePath = stateFilePath(nodeId);
|
|
166
|
+
if (!filePath)
|
|
167
|
+
return;
|
|
168
|
+
const dir = path.dirname(filePath);
|
|
169
|
+
if (!fs.existsSync(dir))
|
|
170
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
171
|
+
fs.writeFileSync(filePath, JSON.stringify({ value }), 'utf8');
|
|
172
|
+
}
|
|
173
|
+
// ---- Subscriber management (used by InternalStateHandle) ----
|
|
174
|
+
static addSubscriber(nodeId, callback) {
|
|
175
|
+
const store = getSubscriberStore();
|
|
176
|
+
if (!store.has(nodeId))
|
|
177
|
+
store.set(nodeId, new Set());
|
|
178
|
+
store.get(nodeId).add(callback);
|
|
179
|
+
}
|
|
180
|
+
static removeSubscriber(nodeId, callback) {
|
|
181
|
+
getSubscriberStore().get(nodeId)?.delete(callback);
|
|
182
|
+
}
|
|
183
|
+
static notifySubscribers(nodeId, value) {
|
|
184
|
+
getSubscriberStore().get(nodeId)?.forEach(cb => {
|
|
185
|
+
try {
|
|
186
|
+
cb(value);
|
|
187
|
+
}
|
|
188
|
+
catch { }
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
exports.StateService = StateService;
|
|
193
|
+
exports.StateService = StateService = __decorate([
|
|
194
|
+
(0, ServiceDescriptionDecorator_1.ServiceDescription)({
|
|
195
|
+
id: "@theotherwillembotha/stateservice",
|
|
196
|
+
name: "StateService",
|
|
197
|
+
type: "integration-plugin",
|
|
198
|
+
sourceFile: "@theotherwillembotha/node-red-plugincore",
|
|
199
|
+
}),
|
|
200
|
+
__metadata("design:paramtypes", [])
|
|
201
|
+
], StateService);
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { BaseNodeConfig, Template, TemplateDescriptor } from "../../NodeConstructor";
|
|
2
|
+
export interface StateTemplateConfig extends BaseNodeConfig {
|
|
3
|
+
stateReference: string;
|
|
4
|
+
}
|
|
5
|
+
export declare class StateTemplate extends Template {
|
|
6
|
+
static getTemplateDescriptor(): TemplateDescriptor;
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=StateTemplate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StateTemplate.d.ts","sourceRoot":"","sources":["../../../../src/core/state/template/StateTemplate.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAErF,MAAM,WAAW,mBAAoB,SAAQ,cAAc;IACvD,cAAc,EAAE,MAAM,CAAC;CAC1B;AAED,qBAAa,aAAc,SAAQ,QAAQ;IAEvC,OAAc,qBAAqB,IAAI,kBAAkB,CAMxD;CACJ"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.StateTemplate = void 0;
|
|
4
|
+
const NodeGenerator_1 = require("../../NodeGenerator");
|
|
5
|
+
const NodeConstructor_1 = require("../../NodeConstructor");
|
|
6
|
+
class StateTemplate extends NodeConstructor_1.Template {
|
|
7
|
+
static getTemplateDescriptor() {
|
|
8
|
+
return new NodeConstructor_1.TemplateDescriptor("state", StateTemplate, NodeGenerator_1.SourceUtility.getSourcePath("/build/", "/src/") + "StateTemplate.html", []);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
exports.StateTemplate = StateTemplate;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { DependencyType } from "../NodeConstructor";
|
|
2
|
+
export type ServiceDescriptionConfig = {
|
|
3
|
+
id: string;
|
|
4
|
+
sourceFile: string;
|
|
5
|
+
type?: string;
|
|
6
|
+
name?: string;
|
|
7
|
+
dependencies?: DependencyType[];
|
|
8
|
+
};
|
|
9
|
+
export declare function ServiceDescription(config: ServiceDescriptionConfig): (target: any) => void;
|
|
10
|
+
//# sourceMappingURL=ServiceDescriptionDecorator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ServiceDescriptionDecorator.d.ts","sourceRoot":"","sources":["../../../src/core/tagging/ServiceDescriptionDecorator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAqB,MAAM,oBAAoB,CAAC;AAEvE,MAAM,MAAM,wBAAwB,GAAG;IACnC,EAAE,EAAE,MAAM,CAAC;IACX,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,YAAY,CAAC,EAAE,cAAc,EAAE,CAAC;CACnC,CAAA;AAED,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,wBAAwB,YACvC,GAAG,UAW9B"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ServiceDescription = ServiceDescription;
|
|
4
|
+
const NodeConstructor_1 = require("../NodeConstructor");
|
|
5
|
+
function ServiceDescription(config) {
|
|
6
|
+
return function (target) {
|
|
7
|
+
const descriptor = new NodeConstructor_1.ServiceDescriptor(config.id, config.name ?? target.name, config.type ?? "services-plugin", config.sourceFile, target, config.dependencies);
|
|
8
|
+
target.getServiceDescriptor = () => descriptor;
|
|
9
|
+
};
|
|
10
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { INodeClass } from "../../NodeGenerator";
|
|
2
|
-
import { BaseService, FlowDeployment
|
|
2
|
+
import { BaseService, FlowDeployment } from "../../NodeConstructor";
|
|
3
3
|
import { NodeAPI, NodeAPISettingsWithData } from "node-red";
|
|
4
4
|
export declare class NodeTypeService extends BaseService {
|
|
5
5
|
private red;
|
|
@@ -10,6 +10,5 @@ export declare class NodeTypeService extends BaseService {
|
|
|
10
10
|
onDeploy(flowDeployment: FlowDeployment): void | Promise<void>;
|
|
11
11
|
registerNodeType(tag: string, resource: INodeClass): Promise<void>;
|
|
12
12
|
getNodeTypesForTag(tag: string): INodeClass[];
|
|
13
|
-
static getServiceDescriptor(): ServiceDescriptor;
|
|
14
13
|
}
|
|
15
14
|
//# sourceMappingURL=NodeTypeService.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NodeTypeService.d.ts","sourceRoot":"","sources":["../../../../src/core/tagging/service/NodeTypeService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,WAAW,EAAc,cAAc,EAAE,
|
|
1
|
+
{"version":3,"file":"NodeTypeService.d.ts","sourceRoot":"","sources":["../../../../src/core/tagging/service/NodeTypeService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,WAAW,EAAc,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAEhF,OAAO,EAAE,OAAO,EAAE,uBAAuB,EAAE,MAAM,UAAU,CAAC;AAG5D,qBAIa,eAAgB,SAAQ,WAAW;IAC5C,OAAO,CAAC,GAAG,CAAoC;IAC/C,OAAO,CAAC,SAAS,CAAkC;IAEnD,cAEC;IAEM,IAAI,CAAC,GAAG,EAAE,OAAO,CAAC,uBAAuB,CAAC,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAoBvE;IAEM,MAAM,CAAC,GAAG,EAAE,OAAO,CAAC,uBAAuB,CAAC,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAEzE;IAEM,QAAQ,CAAC,cAAc,EAAE,cAAc,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAEpE;IAEM,gBAAgB,CAAC,GAAG,EAAC,MAAM,EAAE,QAAQ,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,CAOvE;IAEM,kBAAkB,CAAC,GAAG,EAAC,MAAM,GAAE,UAAU,EAAE,CAEjD;CAEJ"}
|
|
@@ -1,8 +1,18 @@
|
|
|
1
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
|
+
};
|
|
2
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
12
|
exports.NodeTypeService = void 0;
|
|
4
13
|
const NodeConstructor_1 = require("../../NodeConstructor");
|
|
5
|
-
|
|
14
|
+
const ServiceDescriptionDecorator_1 = require("../ServiceDescriptionDecorator");
|
|
15
|
+
let NodeTypeService = class NodeTypeService extends NodeConstructor_1.BaseService {
|
|
6
16
|
constructor() {
|
|
7
17
|
super("nodetypes");
|
|
8
18
|
this.nodeTypes = {};
|
|
@@ -40,8 +50,12 @@ class NodeTypeService extends NodeConstructor_1.BaseService {
|
|
|
40
50
|
getNodeTypesForTag(tag) {
|
|
41
51
|
return this.nodeTypes[tag] ? this.nodeTypes[tag] : [];
|
|
42
52
|
}
|
|
43
|
-
|
|
44
|
-
return new NodeConstructor_1.ServiceDescriptor("@theotherwillembotha/nodetypeservice", "NodeTypeService", "services-plugin", "@theotherwillembotha/node-red-plugincore", NodeTypeService, []);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
53
|
+
};
|
|
47
54
|
exports.NodeTypeService = NodeTypeService;
|
|
55
|
+
exports.NodeTypeService = NodeTypeService = __decorate([
|
|
56
|
+
(0, ServiceDescriptionDecorator_1.ServiceDescription)({
|
|
57
|
+
id: "@theotherwillembotha/nodetypeservice",
|
|
58
|
+
sourceFile: "@theotherwillembotha/node-red-plugincore"
|
|
59
|
+
}),
|
|
60
|
+
__metadata("design:paramtypes", [])
|
|
61
|
+
], NodeTypeService);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ScriptEditorTemplate.d.ts","sourceRoot":"","sources":["../../../../src/core/ui/template/ScriptEditorTemplate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAA;AAGpE,qBAAa,oBAAqB,SAAQ,QAAQ;
|
|
1
|
+
{"version":3,"file":"ScriptEditorTemplate.d.ts","sourceRoot":"","sources":["../../../../src/core/ui/template/ScriptEditorTemplate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAA;AAGpE,qBAAa,oBAAqB,SAAQ,QAAQ;IAE9C,OAAc,qBAAqB,IAAI,kBAAkB,CAOxD;CACJ"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UIHelperTemplate.d.ts","sourceRoot":"","sources":["../../../../src/core/ui/template/UIHelperTemplate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAA;AAGpE,qBAAa,gBAAiB,SAAQ,QAAQ;
|
|
1
|
+
{"version":3,"file":"UIHelperTemplate.d.ts","sourceRoot":"","sources":["../../../../src/core/ui/template/UIHelperTemplate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAA;AAGpE,qBAAa,gBAAiB,SAAQ,QAAQ;IAE1C,OAAc,qBAAqB,IAAI,kBAAkB,CAOxD;CACJ"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WebhookDecorator.d.ts","sourceRoot":"","sources":["../../../src/core/webhook/WebhookDecorator.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"WebhookDecorator.d.ts","sourceRoot":"","sources":["../../../src/core/webhook/WebhookDecorator.ts"],"names":[],"mappings":"AAqBA,QAAA,MAAM,OAAO,KAoFD,CAAC;AAGb,OAAO,EACH,OAAO,EACV,CAAA"}
|
|
@@ -1,8 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.Webhook = void 0;
|
|
7
|
+
const os_1 = __importDefault(require("os"));
|
|
4
8
|
const LoggerService_1 = require("../logger/service/LoggerService");
|
|
5
9
|
const NodeConstructor_1 = require("../NodeConstructor");
|
|
10
|
+
const ReverseProxyTypeService_1 = require("./service/ReverseProxyTypeService");
|
|
11
|
+
// In-memory registry: nodeId → managed proxy host entries from the last deploy.
|
|
12
|
+
const managedProxyHosts = new Map();
|
|
6
13
|
const Webhook = (0, NodeConstructor_1.createPostConstructDecorator)('Webhook')
|
|
7
14
|
.withInitLogic(async (instance, propertyKey, webhookconfig) => {
|
|
8
15
|
//console.log(`Registering webhook callback`, "PROPERTYKEY", propertyKey, "WEBHOOK CONFIG", webhookconfig, "THIS", this);
|
|
@@ -21,20 +28,50 @@ const Webhook = (0, NodeConstructor_1.createPostConstructDecorator)('Webhook')
|
|
|
21
28
|
let webhookServer = NodeConstructor_1.NodeManager.RED.nodes.getNode(nodeConfig.webhook).node().server();
|
|
22
29
|
webhookServer.attach(endpointConfig, (request, respponse) => instance[propertyKey](request, respponse));
|
|
23
30
|
if (nodeConfig.reverseProxies_enabled) {
|
|
31
|
+
let targetPort = webhookServer.config().port;
|
|
32
|
+
let targetHost = os_1.default.hostname();
|
|
33
|
+
let nodeId = nodeConfig.id;
|
|
34
|
+
let newlyManaged = [];
|
|
24
35
|
await Promise.all(nodeConfig.reverseProxies_connections.map(async (proxy) => {
|
|
25
36
|
try {
|
|
26
|
-
// get a n instance of reverseProxNode.
|
|
27
|
-
let reverseProxyNode = NodeConstructor_1.NodeManager.RED.nodes.getNode(proxy.proxy).node();
|
|
28
37
|
// TODO: ReverseProxyConfigNodes need to become their own subtype of config nodes so we can enforce the ".client()" method.
|
|
38
|
+
let reverseProxyNode = NodeConstructor_1.NodeManager.RED.nodes.getNode(proxy.proxy).node();
|
|
39
|
+
let proxyClient = reverseProxyNode.client();
|
|
40
|
+
let hosts = await proxyClient.getHosts();
|
|
41
|
+
let matchingHost = hosts.find(h => h.domainNames?.includes(proxy.domainname));
|
|
42
|
+
if (!matchingHost) {
|
|
43
|
+
await proxyClient.updateHost({ domainNames: [proxy.domainname], forwardHost: targetHost, forwardPort: targetPort, scheme: ReverseProxyTypeService_1.HTTPScheme.HTTP });
|
|
44
|
+
// Fetch again to get the assigned ID of the newly created entry.
|
|
45
|
+
let updatedHosts = await proxyClient.getHosts();
|
|
46
|
+
matchingHost = updatedHosts.find(h => h.domainNames?.includes(proxy.domainname));
|
|
47
|
+
}
|
|
48
|
+
else if (matchingHost.forwardHost !== targetHost || matchingHost.forwardPort !== targetPort) {
|
|
49
|
+
await proxyClient.updateHost({ id: matchingHost.id, forwardHost: targetHost, forwardPort: targetPort, scheme: ReverseProxyTypeService_1.HTTPScheme.HTTP });
|
|
50
|
+
}
|
|
51
|
+
if (matchingHost?.id !== undefined) {
|
|
52
|
+
newlyManaged.push({ proxyNodeId: proxy.proxy, hostId: matchingHost.id });
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
catch (e) {
|
|
56
|
+
console.error(e);
|
|
57
|
+
}
|
|
58
|
+
}));
|
|
59
|
+
// Remove any stale proxy host entries that were managed last deploy but are no longer in the current config.
|
|
60
|
+
let previouslyManaged = managedProxyHosts.get(nodeId) ?? [];
|
|
61
|
+
let newHostIds = new Set(newlyManaged.map(m => m.hostId));
|
|
62
|
+
await Promise.all(previouslyManaged
|
|
63
|
+
.filter(m => !newHostIds.has(m.hostId))
|
|
64
|
+
.map(async (stale) => {
|
|
65
|
+
try {
|
|
66
|
+
let reverseProxyNode = NodeConstructor_1.NodeManager.RED.nodes.getNode(stale.proxyNodeId).node();
|
|
29
67
|
let proxyClient = reverseProxyNode.client();
|
|
30
|
-
|
|
31
|
-
//console.log("ADD REVERSE PROXY:" + proxy.proxy + " to " + node.id(), proxyClient);
|
|
68
|
+
await proxyClient.deleteHost(stale.hostId);
|
|
32
69
|
}
|
|
33
70
|
catch (e) {
|
|
34
|
-
console.
|
|
71
|
+
console.error(e);
|
|
35
72
|
}
|
|
36
|
-
return Promise.resolve();
|
|
37
73
|
}));
|
|
74
|
+
managedProxyHosts.set(nodeId, newlyManaged);
|
|
38
75
|
}
|
|
39
76
|
// register a close listener to the node.
|
|
40
77
|
node.node().on("close", () => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WebhookServerConfigNode.d.ts","sourceRoot":"","sources":["../../../../src/core/webhook/node/WebhookServerConfigNode.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAChC,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAA;AAEpE,OAAO,EAAE,aAAa,EAAwB,MAAM,iCAAiC,CAAC;AAGtF,UAAU,6BAA8B,SAAQ,gBAAgB;IAC5D,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,EAAC,MAAM,CAAC;IACpB,YAAY,EAAC,MAAM,CAAC;CACvB;AAED,qBASa,uBAAwB,SAAQ,UAAU,CAAC,6BAA6B,CAAC;IAClF,OAAO,CAAC,OAAO,CAAgB;
|
|
1
|
+
{"version":3,"file":"WebhookServerConfigNode.d.ts","sourceRoot":"","sources":["../../../../src/core/webhook/node/WebhookServerConfigNode.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAChC,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAA;AAEpE,OAAO,EAAE,aAAa,EAAwB,MAAM,iCAAiC,CAAC;AAGtF,UAAU,6BAA8B,SAAQ,gBAAgB;IAC5D,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,EAAC,MAAM,CAAC;IACpB,YAAY,EAAC,MAAM,CAAC;CACvB;AAED,qBASa,uBAAwB,SAAQ,UAAU,CAAC,6BAA6B,CAAC;IAClF,OAAO,CAAC,OAAO,CAAgB;IAE/B,YAAY,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,6BAA6B,EAM5D;IAEM,MAAM,IAAG,aAAa,CAE5B;CACJ"}
|
|
@@ -8,6 +8,7 @@ export declare abstract class ReverseProxyType {
|
|
|
8
8
|
export interface ProxyManagerClient {
|
|
9
9
|
updateHost(data: Partial<HostEntry>): Promise<void>;
|
|
10
10
|
getHosts(): Promise<Partial<HostEntry>[]>;
|
|
11
|
+
deleteHost(id: number): Promise<void>;
|
|
11
12
|
}
|
|
12
13
|
export type HostEntry = {
|
|
13
14
|
id: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ReverseProxyTypeService.d.ts","sourceRoot":"","sources":["../../../../src/core/webhook/service/ReverseProxyTypeService.ts"],"names":[],"mappings":"AAGA,8BAAsB,gBAAgB;IAElC,OAAO,CAAC,GAAG,CAAS;IACpB,OAAO,CAAC,KAAK,CAAS;
|
|
1
|
+
{"version":3,"file":"ReverseProxyTypeService.d.ts","sourceRoot":"","sources":["../../../../src/core/webhook/service/ReverseProxyTypeService.ts"],"names":[],"mappings":"AAGA,8BAAsB,gBAAgB;IAElC,OAAO,CAAC,GAAG,CAAS;IACpB,OAAO,CAAC,KAAK,CAAS;IAEtB,YAAY,EAAE,EAAC,MAAM,EAAE,IAAI,EAAC,MAAM,EAGjC;IAEM,EAAE,IAAG,MAAM,CAEjB;IACM,IAAI,IAAG,MAAM,CAEnB;CACJ;AAED,MAAM,WAAW,kBAAkB;IAC/B,UAAU,CAAC,IAAI,EAAE,OAAO,CAAC,SAAS,CAAC,GAAE,OAAO,CAAC,IAAI,CAAC,CAAC;IACnD,QAAQ,IAAG,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC;IACzC,UAAU,CAAC,EAAE,EAAE,MAAM,GAAE,OAAO,CAAC,IAAI,CAAC,CAAC;CACxC;AAED,MAAM,MAAM,SAAS,GAAG;IACpB,EAAE,EAAC,MAAM,CAAC;IACV,WAAW,EAAC,MAAM,EAAE,CAAC;IACrB,MAAM,EAAC,UAAU,CAAC;IAClB,WAAW,EAAC,MAAM,CAAC;IACnB,WAAW,EAAC,MAAM,CAAC;IACnB,UAAU,EAAC,MAAM,CAAC;IAClB,WAAW,EAAC,OAAO,CAAC;IACpB,mBAAmB,EAAC,OAAO,CAAC;IAC5B,gBAAgB,EAAC,OAAO,CAAC;CAC5B,CAAA;AAED,oBAAY,UAAU;IAClB,IAAI,SAAS;IACb,KAAK,UAAU;CAClB"}
|