@theotherwillembotha/node-red-plugincore 0.0.50
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/LICENSE +15 -0
- package/README.md +190 -0
- package/build/GenerateNodes.d.ts +2 -0
- package/build/GenerateNodes.d.ts.map +1 -0
- package/build/GenerateNodes.js +36 -0
- package/build/Nodes.html +1729 -0
- package/build/Nodes.js +32 -0
- package/build/Plugins.js +74 -0
- package/build/core/NodeConstructor.d.ts +188 -0
- package/build/core/NodeConstructor.d.ts.map +1 -0
- package/build/core/NodeConstructor.js +679 -0
- package/build/core/NodeGenerator.d.ts +37 -0
- package/build/core/NodeGenerator.d.ts.map +1 -0
- package/build/core/NodeGenerator.js +300 -0
- package/build/core/Utils.d.ts +7 -0
- package/build/core/Utils.d.ts.map +1 -0
- package/build/core/Utils.js +19 -0
- package/build/core/logger/LoggerDecorator.d.ts +2 -0
- package/build/core/logger/LoggerDecorator.d.ts.map +1 -0
- package/build/core/logger/LoggerDecorator.js +93 -0
- package/build/core/logger/node/ConsoleLoggerConfigNode.d.ts +16 -0
- package/build/core/logger/node/ConsoleLoggerConfigNode.d.ts.map +1 -0
- package/build/core/logger/node/ConsoleLoggerConfigNode.html +131 -0
- package/build/core/logger/node/ConsoleLoggerConfigNode.js +47 -0
- package/build/core/logger/node/LoggerConfigNode.d.ts +30 -0
- package/build/core/logger/node/LoggerConfigNode.d.ts.map +1 -0
- package/build/core/logger/node/LoggerConfigNode.html +307 -0
- package/build/core/logger/node/LoggerConfigNode.js +60 -0
- package/build/core/logger/node/LokiLoggerConfigNode.d.ts +20 -0
- package/build/core/logger/node/LokiLoggerConfigNode.d.ts.map +1 -0
- package/build/core/logger/node/LokiLoggerConfigNode.html +153 -0
- package/build/core/logger/node/LokiLoggerConfigNode.js +52 -0
- package/build/core/logger/node/RestLoggerConfigNode.d.ts +24 -0
- package/build/core/logger/node/RestLoggerConfigNode.d.ts.map +1 -0
- package/build/core/logger/node/RestLoggerConfigNode.html +209 -0
- package/build/core/logger/node/RestLoggerConfigNode.js +57 -0
- package/build/core/logger/service/LoggerService.d.ts +88 -0
- package/build/core/logger/service/LoggerService.d.ts.map +1 -0
- package/build/core/logger/service/LoggerService.js +204 -0
- package/build/core/logger/service/LoggerServiceTypes.d.ts +24 -0
- package/build/core/logger/service/LoggerServiceTypes.d.ts.map +1 -0
- package/build/core/logger/service/LoggerServiceTypes.js +30 -0
- package/build/core/logger/template/LoggerTemplate.d.ts +11 -0
- package/build/core/logger/template/LoggerTemplate.d.ts.map +1 -0
- package/build/core/logger/template/LoggerTemplate.html +328 -0
- package/build/core/logger/template/LoggerTemplate.js +12 -0
- package/build/core/metrics/MetricsDecorator.d.ts +40 -0
- package/build/core/metrics/MetricsDecorator.d.ts.map +1 -0
- package/build/core/metrics/MetricsDecorator.js +166 -0
- package/build/core/metrics/node/CounterMetricConfigNode.d.ts +16 -0
- package/build/core/metrics/node/CounterMetricConfigNode.d.ts.map +1 -0
- package/build/core/metrics/node/CounterMetricConfigNode.html +48 -0
- package/build/core/metrics/node/CounterMetricConfigNode.js +61 -0
- package/build/core/metrics/node/GaugeMetricConfigNode.d.ts +17 -0
- package/build/core/metrics/node/GaugeMetricConfigNode.d.ts.map +1 -0
- package/build/core/metrics/node/GaugeMetricConfigNode.html +48 -0
- package/build/core/metrics/node/GaugeMetricConfigNode.js +61 -0
- package/build/core/metrics/node/MetricsConfigNode.d.ts +14 -0
- package/build/core/metrics/node/MetricsConfigNode.d.ts.map +1 -0
- package/build/core/metrics/node/MetricsConfigNode.html +21 -0
- package/build/core/metrics/node/MetricsConfigNode.js +56 -0
- package/build/core/metrics/node/TimerMetricConfigNode.d.ts +28 -0
- package/build/core/metrics/node/TimerMetricConfigNode.d.ts.map +1 -0
- package/build/core/metrics/node/TimerMetricConfigNode.html +190 -0
- package/build/core/metrics/node/TimerMetricConfigNode.js +101 -0
- package/build/core/metrics/service/MetricsService.d.ts +187 -0
- package/build/core/metrics/service/MetricsService.d.ts.map +1 -0
- package/build/core/metrics/service/MetricsService.js +385 -0
- package/build/core/metrics/template/CounterMetricTemplate.d.ts +5 -0
- package/build/core/metrics/template/CounterMetricTemplate.d.ts.map +1 -0
- package/build/core/metrics/template/CounterMetricTemplate.html +40 -0
- package/build/core/metrics/template/CounterMetricTemplate.js +12 -0
- package/build/core/metrics/template/GaugeMetricTemplate.d.ts +5 -0
- package/build/core/metrics/template/GaugeMetricTemplate.d.ts.map +1 -0
- package/build/core/metrics/template/GaugeMetricTemplate.html +39 -0
- package/build/core/metrics/template/GaugeMetricTemplate.js +12 -0
- package/build/core/metrics/template/MetricsTemplate.d.ts +8 -0
- package/build/core/metrics/template/MetricsTemplate.d.ts.map +1 -0
- package/build/core/metrics/template/MetricsTemplate.html +54 -0
- package/build/core/metrics/template/MetricsTemplate.js +12 -0
- package/build/core/metrics/template/TimerMetricTemplate.d.ts +5 -0
- package/build/core/metrics/template/TimerMetricTemplate.d.ts.map +1 -0
- package/build/core/metrics/template/TimerMetricTemplate.html +39 -0
- package/build/core/metrics/template/TimerMetricTemplate.js +12 -0
- package/build/core/other/InputDecorator.d.ts +3 -0
- package/build/core/other/InputDecorator.d.ts.map +1 -0
- package/build/core/other/InputDecorator.js +43 -0
- package/build/core/other/service/InputService.d.ts +16 -0
- package/build/core/other/service/InputService.d.ts.map +1 -0
- package/build/core/other/service/InputService.js +31 -0
- package/build/core/other/service/SettingsService.d.ts +25 -0
- package/build/core/other/service/SettingsService.d.ts.map +1 -0
- package/build/core/other/service/SettingsService.js +74 -0
- package/build/core/other/template/BasicTemplate.d.ts +5 -0
- package/build/core/other/template/BasicTemplate.d.ts.map +1 -0
- package/build/core/other/template/BasicTemplate.html +76 -0
- package/build/core/other/template/BasicTemplate.js +11 -0
- package/build/core/other/template/SettingsTemplate.d.ts +5 -0
- package/build/core/other/template/SettingsTemplate.d.ts.map +1 -0
- package/build/core/other/template/SettingsTemplate.html +128 -0
- package/build/core/other/template/SettingsTemplate.js +11 -0
- package/build/core/tagging/NodeDescriptionDecorator.d.ts +17 -0
- package/build/core/tagging/NodeDescriptionDecorator.d.ts.map +1 -0
- package/build/core/tagging/NodeDescriptionDecorator.js +25 -0
- package/build/core/tagging/service/NodeTypeService.d.ts +15 -0
- package/build/core/tagging/service/NodeTypeService.d.ts.map +1 -0
- package/build/core/tagging/service/NodeTypeService.js +47 -0
- package/build/core/webhook/WebhookDecorator.d.ts +3 -0
- package/build/core/webhook/WebhookDecorator.d.ts.map +1 -0
- package/build/core/webhook/WebhookDecorator.js +45 -0
- package/build/core/webhook/node/WebhookServerConfigNode.d.ts +16 -0
- package/build/core/webhook/node/WebhookServerConfigNode.d.ts.map +1 -0
- package/build/core/webhook/node/WebhookServerConfigNode.html +61 -0
- package/build/core/webhook/node/WebhookServerConfigNode.js +40 -0
- package/build/core/webhook/service/ReverseProxyTypeService.d.ts +29 -0
- package/build/core/webhook/service/ReverseProxyTypeService.d.ts.map +1 -0
- package/build/core/webhook/service/ReverseProxyTypeService.js +24 -0
- package/build/core/webhook/service/WebhookServerService.d.ts +52 -0
- package/build/core/webhook/service/WebhookServerService.d.ts.map +1 -0
- package/build/core/webhook/service/WebhookServerService.js +146 -0
- package/build/core/webhook/template/WebhookTemplate.d.ts +22 -0
- package/build/core/webhook/template/WebhookTemplate.d.ts.map +1 -0
- package/build/core/webhook/template/WebhookTemplate.html +434 -0
- package/build/core/webhook/template/WebhookTemplate.js +12 -0
- package/build/index.d.ts +33 -0
- package/build/index.d.ts.map +1 -0
- package/build/index.js +55 -0
- package/package.json +67 -0
- package/src/GenerateNodes.ts +42 -0
- package/src/core/NodeConstructor.ts +889 -0
- package/src/core/NodeGenerator.ts +331 -0
- package/src/core/Utils.ts +19 -0
- package/src/core/logger/LoggerDecorator.ts +105 -0
- package/src/core/logger/node/ConsoleLoggerConfigNode.html +131 -0
- package/src/core/logger/node/ConsoleLoggerConfigNode.ts +46 -0
- package/src/core/logger/node/LoggerConfigNode.html +307 -0
- package/src/core/logger/node/LoggerConfigNode.ts +95 -0
- package/src/core/logger/node/LokiLoggerConfigNode.html +153 -0
- package/src/core/logger/node/LokiLoggerConfigNode.ts +58 -0
- package/src/core/logger/node/RestLoggerConfigNode.html +209 -0
- package/src/core/logger/node/RestLoggerConfigNode.ts +67 -0
- package/src/core/logger/service/LoggerService.ts +317 -0
- package/src/core/logger/service/LoggerServiceTypes.ts +26 -0
- package/src/core/logger/template/LoggerTemplate.html +328 -0
- package/src/core/logger/template/LoggerTemplate.ts +23 -0
- package/src/core/metrics/MetricsDecorator.ts +227 -0
- package/src/core/metrics/node/CounterMetricConfigNode.html +48 -0
- package/src/core/metrics/node/CounterMetricConfigNode.ts +62 -0
- package/src/core/metrics/node/GaugeMetricConfigNode.html +48 -0
- package/src/core/metrics/node/GaugeMetricConfigNode.ts +62 -0
- package/src/core/metrics/node/MetricsConfigNode.html +21 -0
- package/src/core/metrics/node/MetricsConfigNode.ts +55 -0
- package/src/core/metrics/node/TimerMetricConfigNode.html +190 -0
- package/src/core/metrics/node/TimerMetricConfigNode.ts +118 -0
- package/src/core/metrics/service/MetricsService.ts +560 -0
- package/src/core/metrics/template/CounterMetricTemplate.html +40 -0
- package/src/core/metrics/template/CounterMetricTemplate.ts +15 -0
- package/src/core/metrics/template/GaugeMetricTemplate.html +39 -0
- package/src/core/metrics/template/GaugeMetricTemplate.ts +15 -0
- package/src/core/metrics/template/MetricsTemplate.html +54 -0
- package/src/core/metrics/template/MetricsTemplate.ts +18 -0
- package/src/core/metrics/template/TimerMetricTemplate.html +39 -0
- package/src/core/metrics/template/TimerMetricTemplate.ts +14 -0
- package/src/core/other/InputDecorator.ts +57 -0
- package/src/core/other/service/InputService.ts +36 -0
- package/src/core/other/service/SettingsService.ts +103 -0
- package/src/core/other/template/BasicTemplate.html +76 -0
- package/src/core/other/template/BasicTemplate.ts +15 -0
- package/src/core/other/template/SettingsTemplate.html +128 -0
- package/src/core/other/template/SettingsTemplate.ts +17 -0
- package/src/core/tagging/NodeDescriptionDecorator.ts +39 -0
- package/src/core/tagging/service/NodeTypeService.ts +67 -0
- package/src/core/webhook/WebhookDecorator.ts +70 -0
- package/src/core/webhook/node/WebhookServerConfigNode.html +61 -0
- package/src/core/webhook/node/WebhookServerConfigNode.ts +38 -0
- package/src/core/webhook/service/ReverseProxyTypeService.ts +46 -0
- package/src/core/webhook/service/WebhookServerService.ts +211 -0
- package/src/core/webhook/template/WebhookTemplate.html +434 -0
- package/src/core/webhook/template/WebhookTemplate.ts +36 -0
- package/src/index.ts +47 -0
|
@@ -0,0 +1,679 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.buildNode = exports.NodeBuilder = exports.BaseService = exports.NodeManager = exports.Template = exports.ServiceDescriptor = exports.TemplateDescriptor = exports.NodeDescriptor = exports.ConfigNode = exports.BaseNode = void 0;
|
|
7
|
+
exports.createPostConstructDecorator = createPostConstructDecorator;
|
|
8
|
+
require("reflect-metadata");
|
|
9
|
+
const jsdom_1 = __importDefault(require("jsdom"));
|
|
10
|
+
const fs_1 = __importDefault(require("fs"));
|
|
11
|
+
const js_beautify_1 = __importDefault(require("js-beautify"));
|
|
12
|
+
const markdown_it_1 = __importDefault(require("markdown-it"));
|
|
13
|
+
const handlebars_1 = __importDefault(require("handlebars"));
|
|
14
|
+
class BaseNode {
|
|
15
|
+
node() { return this._node; }
|
|
16
|
+
config() { return this._config; }
|
|
17
|
+
flow() { return this._flow; }
|
|
18
|
+
// THIS value is imported from NodeRed Node itself.
|
|
19
|
+
id() { return this.config().id; }
|
|
20
|
+
;
|
|
21
|
+
type() { return this.config().type; }
|
|
22
|
+
;
|
|
23
|
+
name() { return this.config().name; }
|
|
24
|
+
;
|
|
25
|
+
constructor(node, config) {
|
|
26
|
+
this._node = node;
|
|
27
|
+
this._config = config;
|
|
28
|
+
this._flow = (this._node._flow?.flow).label;
|
|
29
|
+
// inject a reverse lookup so the NodeRedNode can refer back to the waos node:
|
|
30
|
+
this._node.node = () => { return this; };
|
|
31
|
+
}
|
|
32
|
+
// this function can be overwritten to be triggered after the constructor and
|
|
33
|
+
// decorators have been called.
|
|
34
|
+
onInit() { }
|
|
35
|
+
// note: this function should be implemented by every concrete implementation of the BaseNode class.
|
|
36
|
+
static getNodeDescriptor() {
|
|
37
|
+
throw new Error("getNodeDescriptor not implemented.");
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
exports.BaseNode = BaseNode;
|
|
41
|
+
class ConfigNode extends BaseNode {
|
|
42
|
+
constructor(node, config) {
|
|
43
|
+
super(node, config);
|
|
44
|
+
}
|
|
45
|
+
static getNodeDescriptor() {
|
|
46
|
+
throw new Error("getNodeDescriptor not implemented.");
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
exports.ConfigNode = ConfigNode;
|
|
50
|
+
class NodeDescriptor {
|
|
51
|
+
constructor(group, name, sourceFile, pkg) {
|
|
52
|
+
this._dependencies = [];
|
|
53
|
+
this._templates = [];
|
|
54
|
+
this._tags = [];
|
|
55
|
+
this._group = group;
|
|
56
|
+
this._name = name;
|
|
57
|
+
this._sourceFile = sourceFile;
|
|
58
|
+
this._package = pkg;
|
|
59
|
+
}
|
|
60
|
+
// DEPRECATED
|
|
61
|
+
addDependency(dependency) {
|
|
62
|
+
this._dependencies.push(dependency);
|
|
63
|
+
return this;
|
|
64
|
+
}
|
|
65
|
+
// DEPRECATED
|
|
66
|
+
addTag(tag) {
|
|
67
|
+
this._tags.push(tag);
|
|
68
|
+
return this;
|
|
69
|
+
}
|
|
70
|
+
// DEPRECATED
|
|
71
|
+
addTemplate(template, config) {
|
|
72
|
+
// TODO: we can only add every template once.
|
|
73
|
+
this._dependencies.push(template);
|
|
74
|
+
this._templates.push({ template: template, config: config });
|
|
75
|
+
return this;
|
|
76
|
+
}
|
|
77
|
+
group() { return this._group; }
|
|
78
|
+
name() { return this._name; }
|
|
79
|
+
sourceFile() { return this._sourceFile; }
|
|
80
|
+
package() { return this._package; }
|
|
81
|
+
dependencies() { return this._dependencies; }
|
|
82
|
+
templates() { return this._templates; }
|
|
83
|
+
tags() { return this._tags; }
|
|
84
|
+
}
|
|
85
|
+
exports.NodeDescriptor = NodeDescriptor;
|
|
86
|
+
class TemplateDescriptor {
|
|
87
|
+
constructor(name, clazz, templateFile, dependencies) {
|
|
88
|
+
this._name = name;
|
|
89
|
+
this._clazz = clazz;
|
|
90
|
+
this._templateFile = templateFile;
|
|
91
|
+
this._dependencies = dependencies;
|
|
92
|
+
}
|
|
93
|
+
name() {
|
|
94
|
+
return this._name;
|
|
95
|
+
}
|
|
96
|
+
clazz() {
|
|
97
|
+
return this._clazz;
|
|
98
|
+
}
|
|
99
|
+
dependencies() {
|
|
100
|
+
return this._dependencies;
|
|
101
|
+
}
|
|
102
|
+
templateFile() {
|
|
103
|
+
return this._templateFile;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
exports.TemplateDescriptor = TemplateDescriptor;
|
|
107
|
+
class ServiceDescriptor {
|
|
108
|
+
constructor(id, name, type, sourceFile, clazz, dependencies) {
|
|
109
|
+
this._id = id;
|
|
110
|
+
this._name = name;
|
|
111
|
+
this._type = type;
|
|
112
|
+
this._sourceFile = sourceFile;
|
|
113
|
+
this._clazz = clazz;
|
|
114
|
+
this._dependencies = dependencies ? dependencies : [];
|
|
115
|
+
}
|
|
116
|
+
id() { return this._id; }
|
|
117
|
+
;
|
|
118
|
+
name() { return this._name; }
|
|
119
|
+
;
|
|
120
|
+
type() { return this._type; }
|
|
121
|
+
;
|
|
122
|
+
sourceFile() { return this._sourceFile; }
|
|
123
|
+
;
|
|
124
|
+
clazz() { return this._clazz; }
|
|
125
|
+
;
|
|
126
|
+
dependencies() { return this._dependencies; }
|
|
127
|
+
;
|
|
128
|
+
}
|
|
129
|
+
exports.ServiceDescriptor = ServiceDescriptor;
|
|
130
|
+
class Template {
|
|
131
|
+
static getTemplateDescriptor() {
|
|
132
|
+
throw new Error("getTemplateDescriptor not implemented for " + this.name);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
exports.Template = Template;
|
|
136
|
+
const POST_CONSTRUCT_KEY = Symbol('postConstructInitializers');
|
|
137
|
+
// Builder class for post-construct decorators
|
|
138
|
+
class PostConstructDecoratorBuilder {
|
|
139
|
+
constructor(decoratorName) {
|
|
140
|
+
this.decoratorName = decoratorName;
|
|
141
|
+
}
|
|
142
|
+
// Set default config for when brackets are omitted
|
|
143
|
+
withDefaultConfig(config) {
|
|
144
|
+
this.defaultConfig = config;
|
|
145
|
+
return this;
|
|
146
|
+
}
|
|
147
|
+
// Method to set initialization logic
|
|
148
|
+
withInitLogic(initLogic) {
|
|
149
|
+
this.initLogic = initLogic;
|
|
150
|
+
return this;
|
|
151
|
+
}
|
|
152
|
+
// Method to set custom validation logic
|
|
153
|
+
withValidator(validator) {
|
|
154
|
+
this.validator = validator;
|
|
155
|
+
return this;
|
|
156
|
+
}
|
|
157
|
+
// Build the actual decorator factory (returns a function that takes metadata and returns a decorator)
|
|
158
|
+
build() {
|
|
159
|
+
const decoratorName = this.decoratorName;
|
|
160
|
+
const initLogic = this.initLogic;
|
|
161
|
+
const validator = this.validator;
|
|
162
|
+
const defaultConfig = this.defaultConfig;
|
|
163
|
+
// The actual decorator implementation
|
|
164
|
+
const decoratorImpl = (config) => {
|
|
165
|
+
return (target, propertyKey, descriptor) => {
|
|
166
|
+
try {
|
|
167
|
+
const className = target.constructor.name;
|
|
168
|
+
const originalMethod = descriptor.value;
|
|
169
|
+
if (typeof originalMethod !== 'function') {
|
|
170
|
+
throw new Error(`@${decoratorName} decorator error:\n` +
|
|
171
|
+
` Class: ${className}\n` +
|
|
172
|
+
` Property: ${propertyKey}\n` +
|
|
173
|
+
` Issue: Decorator can only be applied to methods.`);
|
|
174
|
+
}
|
|
175
|
+
const returnType = Reflect.getMetadata?.('design:returntype', target, propertyKey);
|
|
176
|
+
if (returnType && returnType !== Promise && returnType !== void 0 && returnType !== undefined) {
|
|
177
|
+
console.warn(`@${decoratorName} decorator warning:\n` +
|
|
178
|
+
` Class: ${className}\n` +
|
|
179
|
+
` Method: ${propertyKey}\n` +
|
|
180
|
+
` Issue: Method should return void or Promise<void>, but appears to return ${returnType.name}.`);
|
|
181
|
+
}
|
|
182
|
+
if (validator) {
|
|
183
|
+
try {
|
|
184
|
+
validator(target, propertyKey, descriptor);
|
|
185
|
+
}
|
|
186
|
+
catch (error) {
|
|
187
|
+
throw new Error(`@${decoratorName} decorator validation error:\n` +
|
|
188
|
+
` Class: ${className}\n` +
|
|
189
|
+
` Method: ${propertyKey}\n` +
|
|
190
|
+
` Issue: ${error instanceof Error ? error.message : String(error)}`);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
const wrappedMethod = async function (...args) {
|
|
194
|
+
const result = await originalMethod.apply(this, args);
|
|
195
|
+
if (result !== undefined && result !== null) {
|
|
196
|
+
console.warn(`@${decoratorName} runtime warning:\n` +
|
|
197
|
+
` Class: ${className}\n` +
|
|
198
|
+
` Method: ${propertyKey}\n` +
|
|
199
|
+
` Issue: Method returned a value (${typeof result}) but should return void or Promise<void>.`);
|
|
200
|
+
}
|
|
201
|
+
};
|
|
202
|
+
if (!target[POST_CONSTRUCT_KEY]) {
|
|
203
|
+
target[POST_CONSTRUCT_KEY] = [];
|
|
204
|
+
}
|
|
205
|
+
target[POST_CONSTRUCT_KEY].push((instance) => {
|
|
206
|
+
if (initLogic) {
|
|
207
|
+
try {
|
|
208
|
+
initLogic(instance, propertyKey, config);
|
|
209
|
+
}
|
|
210
|
+
catch (error) {
|
|
211
|
+
throw new Error(`@${decoratorName} initialization error:\n` +
|
|
212
|
+
` Class: ${className}\n` +
|
|
213
|
+
` Method: ${propertyKey}\n` +
|
|
214
|
+
` Issue: ${error instanceof Error ? error.message : String(error)}`);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
});
|
|
218
|
+
descriptor.value = wrappedMethod;
|
|
219
|
+
return descriptor;
|
|
220
|
+
}
|
|
221
|
+
catch (e) {
|
|
222
|
+
console.error("failed creating DecoratorImplementation:", "target:", target, "propertyKey:", propertyKey, "descriptor:", descriptor, "error:", e);
|
|
223
|
+
throw e;
|
|
224
|
+
}
|
|
225
|
+
};
|
|
226
|
+
};
|
|
227
|
+
// Return overloaded decorator that works with or without ()
|
|
228
|
+
const overloadedDecorator = function (targetOrConfig, propertyKey, descriptor) {
|
|
229
|
+
// Check if called without brackets (directly on method)
|
|
230
|
+
if (propertyKey !== undefined && descriptor !== undefined) {
|
|
231
|
+
// Called as @decorator (without brackets)
|
|
232
|
+
return decoratorImpl(defaultConfig)(targetOrConfig, propertyKey, descriptor);
|
|
233
|
+
}
|
|
234
|
+
else {
|
|
235
|
+
// Called as @decorator() or @decorator({...})
|
|
236
|
+
return decoratorImpl(targetOrConfig);
|
|
237
|
+
}
|
|
238
|
+
};
|
|
239
|
+
return overloadedDecorator;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
// Factory function to create decorator builders
|
|
243
|
+
function createPostConstructDecorator(decoratorName) {
|
|
244
|
+
return new PostConstructDecoratorBuilder(decoratorName);
|
|
245
|
+
}
|
|
246
|
+
// Single function to run all post-construct initializers
|
|
247
|
+
let runPostConstructInitializers = function (instance) {
|
|
248
|
+
const initializers = instance[POST_CONSTRUCT_KEY];
|
|
249
|
+
if (initializers && initializers.length > 0) {
|
|
250
|
+
const className = instance.constructor.name;
|
|
251
|
+
//console.log(`Running ${initializers.length} post-construct initializers for ${className}`);
|
|
252
|
+
initializers.forEach((init, index) => {
|
|
253
|
+
try {
|
|
254
|
+
init(instance);
|
|
255
|
+
}
|
|
256
|
+
catch (error) {
|
|
257
|
+
console.error(`Post-construct initialization failed:\n` +
|
|
258
|
+
` Class: ${className}\n` +
|
|
259
|
+
` Initializer: ${index + 1}/${initializers.length}\n` +
|
|
260
|
+
` Error: ${error instanceof Error ? error.message : String(error)}`);
|
|
261
|
+
throw error;
|
|
262
|
+
}
|
|
263
|
+
});
|
|
264
|
+
// Clear the initializers after running
|
|
265
|
+
delete instance[POST_CONSTRUCT_KEY];
|
|
266
|
+
}
|
|
267
|
+
};
|
|
268
|
+
// ************************************************
|
|
269
|
+
class NodeManager {
|
|
270
|
+
constructor(RED) {
|
|
271
|
+
this.typeBacklog = [];
|
|
272
|
+
NodeManager._RED = RED;
|
|
273
|
+
let nodeTypeServiceListener = async (pluginID) => {
|
|
274
|
+
if (pluginID === "@theotherwillembotha/nodetypeservice") {
|
|
275
|
+
// disable the listener- the plugin has been installed.
|
|
276
|
+
RED.events.off('plugin.instantiated', nodeTypeServiceListener);
|
|
277
|
+
// get a handle on the NodeTypeService
|
|
278
|
+
let plugin = RED.plugins.get("@theotherwillembotha/nodetypeservice");
|
|
279
|
+
this.nodeTypeService = RED.plugins.get("@theotherwillembotha/nodetypeservice").instance;
|
|
280
|
+
// process the backlog.
|
|
281
|
+
for (let nodeType of this.typeBacklog) {
|
|
282
|
+
for (let tag of nodeType.getNodeDescriptor().tags()) {
|
|
283
|
+
this.nodeTypeService.registerNodeType(tag, nodeType);
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
};
|
|
288
|
+
// check if the reverserproxyttypesewrvice is installed yet.
|
|
289
|
+
this.nodeTypeService = RED.plugins.get("@theotherwillembotha/nodetypeservice").instance;
|
|
290
|
+
if (this.nodeTypeService) {
|
|
291
|
+
console.log("NodeTypeService installed!");
|
|
292
|
+
}
|
|
293
|
+
else {
|
|
294
|
+
// Register a listener to trigger when the RegerseProxyTypService gets installed.
|
|
295
|
+
console.log("nodetypeservice not installed yet. waiting for it to be installed");
|
|
296
|
+
RED.events.on('plugin.instantiated', nodeTypeServiceListener);
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
static get RED() {
|
|
300
|
+
return NodeManager._RED;
|
|
301
|
+
}
|
|
302
|
+
registerService(type) {
|
|
303
|
+
let servicePlugin = NodeManager.RED.plugins.get(NodeManager.PLUGINID);
|
|
304
|
+
if (servicePlugin) {
|
|
305
|
+
servicePlugin.instance.install(NodeManager.RED, type);
|
|
306
|
+
}
|
|
307
|
+
else {
|
|
308
|
+
let serviceName = `${type.getServiceDescriptor().sourceFile()}.${type.getServiceDescriptor().name()}`;
|
|
309
|
+
console.log(`ERROR: plugin ${NodeManager.PLUGINID} does not seem to be loaded. Cannot start service: ${serviceName}`);
|
|
310
|
+
}
|
|
311
|
+
return this;
|
|
312
|
+
}
|
|
313
|
+
registerNodeType(typeName, type) {
|
|
314
|
+
if (!type) {
|
|
315
|
+
console.error(`Type "${typeName}" has no associated type. Make sure that it was exported and included in the index.js file!`);
|
|
316
|
+
}
|
|
317
|
+
let nodeConstructor = function (config) {
|
|
318
|
+
console.log("constructing node", typeName);
|
|
319
|
+
try {
|
|
320
|
+
// instantiate the node.
|
|
321
|
+
NodeManager.RED.nodes.createNode(this, config);
|
|
322
|
+
// assign an instance of it to the config.
|
|
323
|
+
//(config as any).__node = this;
|
|
324
|
+
// instatiate the actual node.
|
|
325
|
+
let node = new type(this, config);
|
|
326
|
+
//this.__node = node;
|
|
327
|
+
// run the constructor initializers.
|
|
328
|
+
runPostConstructInitializers(node);
|
|
329
|
+
// after the node has been instantiated, attempt to invole the onInit method.
|
|
330
|
+
if (node.onInit) {
|
|
331
|
+
node.onInit();
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
catch (error) {
|
|
335
|
+
console.log(error);
|
|
336
|
+
console.log("typeName:", typeName);
|
|
337
|
+
console.log("type:", type);
|
|
338
|
+
console.log("config:", config);
|
|
339
|
+
}
|
|
340
|
+
};
|
|
341
|
+
try {
|
|
342
|
+
console.log("registering node " + typeName);
|
|
343
|
+
NodeManager.RED.nodes.registerType(typeName, nodeConstructor, { settings: {} });
|
|
344
|
+
let nodeDescription = type.getNodeDescriptor();
|
|
345
|
+
// registger the node tags.
|
|
346
|
+
if (this.nodeTypeService) {
|
|
347
|
+
for (let tag of nodeDescription.tags()) {
|
|
348
|
+
this.nodeTypeService.registerNodeType(tag, type);
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
else {
|
|
352
|
+
this.typeBacklog.push(type);
|
|
353
|
+
}
|
|
354
|
+
console.log("registered node " + typeName);
|
|
355
|
+
}
|
|
356
|
+
catch (error) {
|
|
357
|
+
console.error("registering node: " + typeName + " failed", error);
|
|
358
|
+
}
|
|
359
|
+
return this;
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
exports.NodeManager = NodeManager;
|
|
363
|
+
NodeManager.PLUGINID = "node-red-contrib-theotherwillembotha/services-plugin";
|
|
364
|
+
class BaseService {
|
|
365
|
+
constructor(name) {
|
|
366
|
+
this._name = name;
|
|
367
|
+
}
|
|
368
|
+
name() {
|
|
369
|
+
return this._name;
|
|
370
|
+
}
|
|
371
|
+
onDeploy(flowDeployment) {
|
|
372
|
+
return Promise.resolve();
|
|
373
|
+
}
|
|
374
|
+
static getServiceDescriptor() {
|
|
375
|
+
throw new Error("getServiceDescriptor not implemented.");
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
exports.BaseService = BaseService;
|
|
379
|
+
const { JSDOM } = jsdom_1.default;
|
|
380
|
+
const md = (0, markdown_it_1.default)({
|
|
381
|
+
html: true,
|
|
382
|
+
linkify: true,
|
|
383
|
+
typographer: true
|
|
384
|
+
});
|
|
385
|
+
// Custom renderer for headings
|
|
386
|
+
md.renderer.rules.heading_open = function (tokens, idx, options, env, self) {
|
|
387
|
+
const token = tokens[idx];
|
|
388
|
+
const level = token.tag.substring(1); // 'h1', 'h2', etc. -> '1', '2'
|
|
389
|
+
return `<h${level} class="custom-heading">`;
|
|
390
|
+
};
|
|
391
|
+
md.renderer.rules.heading_close = function (tokens, idx, options, env, self) {
|
|
392
|
+
const token = tokens[idx];
|
|
393
|
+
const level = token.tag.substring(1);
|
|
394
|
+
return `</h${level}>`;
|
|
395
|
+
};
|
|
396
|
+
let beautifyOptions = {
|
|
397
|
+
"indent_size": 4,
|
|
398
|
+
"preserve-newlines": false,
|
|
399
|
+
"html": {
|
|
400
|
+
"end_with_newline": true,
|
|
401
|
+
"js": {
|
|
402
|
+
"indent_size": 2,
|
|
403
|
+
"preserve-newlines": false
|
|
404
|
+
},
|
|
405
|
+
"css": {
|
|
406
|
+
"indent_size": 2,
|
|
407
|
+
}
|
|
408
|
+
},
|
|
409
|
+
"css": {
|
|
410
|
+
"indent_size": 1
|
|
411
|
+
},
|
|
412
|
+
"js": {
|
|
413
|
+
"preserve-newlines": false
|
|
414
|
+
},
|
|
415
|
+
};
|
|
416
|
+
class NodeBuilder {
|
|
417
|
+
constructor(name, category) {
|
|
418
|
+
this._defaults = {};
|
|
419
|
+
this._outputs = [];
|
|
420
|
+
this._onIncludeOnce = [];
|
|
421
|
+
this._onIncludeEditPrepare = [];
|
|
422
|
+
this._onIncludeEditSave = [];
|
|
423
|
+
this._onIncludeEditCancel = [];
|
|
424
|
+
this._onIncludeEditDelete = [];
|
|
425
|
+
this._onIncludeEditForm = [];
|
|
426
|
+
this._onIncludeDocumentation = [];
|
|
427
|
+
this._name = name;
|
|
428
|
+
this._category = category;
|
|
429
|
+
}
|
|
430
|
+
addDefault(name, template) {
|
|
431
|
+
// if the template type ends with squeare brackets, its an array type.
|
|
432
|
+
if (template.type && template.type.endsWith("[]")) {
|
|
433
|
+
template.maxInstances = template.maxInstances ? template.maxInstances : 10;
|
|
434
|
+
this._defaults[name] = { type: template.type, value: "", required: true, maxInstances: template.maxInstances };
|
|
435
|
+
for (let i = 0; i < template.maxInstances; i++) {
|
|
436
|
+
this._defaults["_" + name + "_" + i] = { value: "", required: false };
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
else {
|
|
440
|
+
this._defaults[name] = template;
|
|
441
|
+
}
|
|
442
|
+
return this;
|
|
443
|
+
}
|
|
444
|
+
setIcon(icon) {
|
|
445
|
+
this._icon = icon;
|
|
446
|
+
return this;
|
|
447
|
+
}
|
|
448
|
+
setColor(color) {
|
|
449
|
+
this._color = color;
|
|
450
|
+
return this;
|
|
451
|
+
}
|
|
452
|
+
setLabel(label) {
|
|
453
|
+
this._label = label.toString();
|
|
454
|
+
return this;
|
|
455
|
+
}
|
|
456
|
+
setPaletteLabel(paletteLabel) {
|
|
457
|
+
this._paletteLabel = paletteLabel;
|
|
458
|
+
return this;
|
|
459
|
+
}
|
|
460
|
+
setLabelStyle(labelStyle) {
|
|
461
|
+
this._labelStyle = labelStyle;
|
|
462
|
+
return this;
|
|
463
|
+
}
|
|
464
|
+
setInput(input) {
|
|
465
|
+
this._inputs = input;
|
|
466
|
+
return this;
|
|
467
|
+
}
|
|
468
|
+
addOutputs(...outputs) {
|
|
469
|
+
outputs.forEach(output => this._outputs.push(output));
|
|
470
|
+
return this;
|
|
471
|
+
}
|
|
472
|
+
addTemplate(template) {
|
|
473
|
+
let templateDescriptor = template.template.getTemplateDescriptor();
|
|
474
|
+
// load the html source file
|
|
475
|
+
let uiDom = new JSDOM(fs_1.default.readFileSync(templateDescriptor.templateFile()));
|
|
476
|
+
// apply the onCompose section if available.
|
|
477
|
+
let onCompose = uiDom.window.document.querySelector("script[template-section='onCompose']")?.innerHTML;
|
|
478
|
+
if (onCompose) {
|
|
479
|
+
evalInContext({ node: this }, onCompose.toString());
|
|
480
|
+
}
|
|
481
|
+
// load the other sections and add them as needed.
|
|
482
|
+
let sections = ['IncludeOnce', 'IncludeEditPrepare', 'IncludeEditSave', 'IncludeEditCancel', 'IncludeEditDelete', 'IncludeEditForm', 'IncludeDocumentation'];
|
|
483
|
+
Object.values(sections).forEach(section => {
|
|
484
|
+
let sectionData = uiDom.window.document.querySelector(`[template-section='on${section}']`)?.innerHTML;
|
|
485
|
+
if (sectionData) {
|
|
486
|
+
this[`add${section}`](templateDescriptor.name(), sectionData);
|
|
487
|
+
}
|
|
488
|
+
});
|
|
489
|
+
return this;
|
|
490
|
+
}
|
|
491
|
+
addIncludeOnce(source, script) {
|
|
492
|
+
this._onIncludeOnce.push({ source: source, script: script });
|
|
493
|
+
return this;
|
|
494
|
+
}
|
|
495
|
+
addIncludeEditPrepare(source, script) {
|
|
496
|
+
this._onIncludeEditPrepare.push({ source: source, script: script });
|
|
497
|
+
return this;
|
|
498
|
+
}
|
|
499
|
+
addIncludeEditSave(source, script) {
|
|
500
|
+
this._onIncludeEditSave.push({ source: source, script: script });
|
|
501
|
+
return this;
|
|
502
|
+
}
|
|
503
|
+
addIncludeEditCancel(source, script) {
|
|
504
|
+
this._onIncludeEditCancel.push({ source: source, script: script });
|
|
505
|
+
return this;
|
|
506
|
+
}
|
|
507
|
+
addIncludeEditDelete(source, script) {
|
|
508
|
+
this._onIncludeEditDelete.push({ source: source, script: script });
|
|
509
|
+
return this;
|
|
510
|
+
}
|
|
511
|
+
addIncludeEditForm(source, script) {
|
|
512
|
+
this._onIncludeEditForm.push({ source: source, script: script });
|
|
513
|
+
return this;
|
|
514
|
+
}
|
|
515
|
+
addIncludeDocumentation(source, script) {
|
|
516
|
+
this._onIncludeDocumentation.push({ source: source, script: script });
|
|
517
|
+
return this;
|
|
518
|
+
}
|
|
519
|
+
serializeProperty(value) {
|
|
520
|
+
switch (typeof value) {
|
|
521
|
+
case "boolean": {
|
|
522
|
+
return "" + value;
|
|
523
|
+
}
|
|
524
|
+
case "number": {
|
|
525
|
+
return "" + value;
|
|
526
|
+
}
|
|
527
|
+
case "string": {
|
|
528
|
+
return `'${value}'`;
|
|
529
|
+
}
|
|
530
|
+
case "object": {
|
|
531
|
+
if (Array.isArray(value)) {
|
|
532
|
+
return `[${value.map(t => this.serializeProperty(t)).join(", ")}]`;
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
throw new Error(`no serializeProperty handler for ${typeof value}, ${value}`);
|
|
537
|
+
}
|
|
538
|
+
serializeHTML(source, script) {
|
|
539
|
+
let context = {
|
|
540
|
+
defaults: (this._category === "config")
|
|
541
|
+
? Object.fromEntries(Object.keys(this._defaults).map(k => [k, `node-config-input-${k}`]))
|
|
542
|
+
: Object.fromEntries(Object.keys(this._defaults).map(k => [k, `node-input-${k}`]))
|
|
543
|
+
};
|
|
544
|
+
return `<!-- ${source} -->
|
|
545
|
+
${handlebars_1.default.compile(script)(context)}
|
|
546
|
+
`;
|
|
547
|
+
}
|
|
548
|
+
serializeJavaScript(source, script) {
|
|
549
|
+
let context = {
|
|
550
|
+
defaults: (this._category === "config")
|
|
551
|
+
? Object.fromEntries(Object.keys(this._defaults).map(k => [k, `node-config-input-${k}`]))
|
|
552
|
+
: Object.fromEntries(Object.keys(this._defaults).map(k => [k, `node-input-${k}`]))
|
|
553
|
+
};
|
|
554
|
+
let serialized = handlebars_1.default.compile(script)(context).trim();
|
|
555
|
+
if (!serialized.startsWith("{") && !serialized.endsWith("}")) {
|
|
556
|
+
serialized = "{\n" + serialized + "\n}";
|
|
557
|
+
}
|
|
558
|
+
return `// **** ${source} **** //
|
|
559
|
+
${serialized}
|
|
560
|
+
`;
|
|
561
|
+
}
|
|
562
|
+
serializeFormEntry(source, script) {
|
|
563
|
+
let context = {
|
|
564
|
+
defaults: (this._category === "config")
|
|
565
|
+
? Object.fromEntries(Object.keys(this._defaults).map(k => [k, `node-config-input-${k}`]))
|
|
566
|
+
: Object.fromEntries(Object.keys(this._defaults).map(k => [k, `node-input-${k}`]))
|
|
567
|
+
};
|
|
568
|
+
return `
|
|
569
|
+
<div id='section_${source}'>${handlebars_1.default.compile(script)(context)}
|
|
570
|
+
</div>
|
|
571
|
+
`;
|
|
572
|
+
}
|
|
573
|
+
serializeDefault(name, value) {
|
|
574
|
+
return `${name}: { ${Object.entries(value).map(([k, v]) => `${k}:${this.serializeProperty(v)}`).join(", ")} },`;
|
|
575
|
+
}
|
|
576
|
+
serializeDocumentationEntry(source, script) {
|
|
577
|
+
return script;
|
|
578
|
+
}
|
|
579
|
+
buildType() {
|
|
580
|
+
// compose the shaddow defaults if need be.
|
|
581
|
+
let shaddowDefaults = Object.entries(this._defaults).filter(([name, template]) => template.type && template.type.endsWith("[]"));
|
|
582
|
+
if (shaddowDefaults.length > 0) {
|
|
583
|
+
this.addIncludeEditSave(this._name + "_shaddowDefaults", `{ let node = this; ` +
|
|
584
|
+
shaddowDefaults
|
|
585
|
+
.map(([name, template]) => `
|
|
586
|
+
for(let i = 0; i < ${template.maxInstances}; i++){
|
|
587
|
+
node["_${name}_" + i] = (node.${name}[i] || {}).proxy || "";
|
|
588
|
+
}`)
|
|
589
|
+
.join("\n\n") +
|
|
590
|
+
`}`);
|
|
591
|
+
}
|
|
592
|
+
return js_beautify_1.default.html_beautify(`
|
|
593
|
+
${this._onIncludeOnce.map(entry => this.serializeHTML(entry.source, entry.script)).join("")}
|
|
594
|
+
<script type="text/javascript">
|
|
595
|
+
RED.nodes.registerType('${this._name}',{
|
|
596
|
+
category: '${this._category}',
|
|
597
|
+
${(this._category !== "config" && this._icon) ? `icon: '${this._icon}',` : ""}
|
|
598
|
+
${(this._category !== "config" && this._color) ? `color: '${this._color}',` : ""}
|
|
599
|
+
${(this._category !== "config" && this._labelStyle) ? `labelStyle: '${this._labelStyle}',` : ""}
|
|
600
|
+
${(this._label) ? `label: ${this._label},` : ""}
|
|
601
|
+
${this._paletteLabel ? `paletteLabel: '${this._paletteLabel}',` : ""}
|
|
602
|
+
${(this._category !== "config") ? `inputs:${this._inputs ? "1" : "0"},` : ""}
|
|
603
|
+
${(this._category !== "config") ? `inputLabels:(i) => '${this._inputs}',` : ""}
|
|
604
|
+
${(this._category !== "config") ? `outputs:${this._outputs.length},` : ""}
|
|
605
|
+
${(this._category !== "config") ? `outputLabels:(i) => ${this.serializeProperty(this._outputs)}[i],` : ""}
|
|
606
|
+
defaults: {
|
|
607
|
+
${Object.entries(this._defaults).map(([key, value]) => this.serializeDefault(key, value)).join("\n")}
|
|
608
|
+
},
|
|
609
|
+
oneditprepare: function() {
|
|
610
|
+
${this._onIncludeEditPrepare.map(entry => this.serializeJavaScript(entry.source, entry.script)).join("")}
|
|
611
|
+
},
|
|
612
|
+
oneditsave: function() {
|
|
613
|
+
${this._onIncludeEditSave.map(entry => this.serializeJavaScript(entry.source, entry.script)).join("")}
|
|
614
|
+
},
|
|
615
|
+
oneditcancel: function() {
|
|
616
|
+
${this._onIncludeEditCancel.map(entry => this.serializeJavaScript(entry.source, entry.script)).join("")}
|
|
617
|
+
},
|
|
618
|
+
oneditdelete: function() {
|
|
619
|
+
${this._onIncludeEditDelete.map(entry => this.serializeJavaScript(entry.source, entry.script)).join("")}
|
|
620
|
+
},
|
|
621
|
+
});
|
|
622
|
+
</script>`, beautifyOptions);
|
|
623
|
+
}
|
|
624
|
+
;
|
|
625
|
+
buildHtml() {
|
|
626
|
+
return js_beautify_1.default.html_beautify(`
|
|
627
|
+
<script type="text/html" data-template-name='${this._name}'>
|
|
628
|
+
${this._onIncludeEditForm.map(entry => this.serializeFormEntry(entry.source, entry.script)).join("")}
|
|
629
|
+
</script>
|
|
630
|
+
`);
|
|
631
|
+
}
|
|
632
|
+
buildDocumentation() {
|
|
633
|
+
return [
|
|
634
|
+
`<script type="text/markdown" data-help-name='${this._name}'>`,
|
|
635
|
+
this._onIncludeDocumentation.map(entry => this.serializeDocumentationEntry(entry.source, entry.script)).join("").trim(),
|
|
636
|
+
`</script>`
|
|
637
|
+
].join("\n");
|
|
638
|
+
}
|
|
639
|
+
;
|
|
640
|
+
}
|
|
641
|
+
exports.NodeBuilder = NodeBuilder;
|
|
642
|
+
;
|
|
643
|
+
let evalInContext = (context, js) => {
|
|
644
|
+
const contextKeys = Object.keys(context);
|
|
645
|
+
const contextValues = Object.values(context);
|
|
646
|
+
// For scripts, we don't wrap in return() - just execute the code directly
|
|
647
|
+
try {
|
|
648
|
+
const func = new Function(...contextKeys, js);
|
|
649
|
+
return func(...contextValues);
|
|
650
|
+
}
|
|
651
|
+
catch (error) {
|
|
652
|
+
console.log("Error while evaluating onCompose Script for ", context, error);
|
|
653
|
+
throw error;
|
|
654
|
+
}
|
|
655
|
+
};
|
|
656
|
+
let buildNode = function (node) {
|
|
657
|
+
// get the node descriptor and create the builder.
|
|
658
|
+
let nodeDescriptor = node.getNodeDescriptor();
|
|
659
|
+
let nodeBuilder = new NodeBuilder(nodeDescriptor.name(), nodeDescriptor.group());
|
|
660
|
+
// load the html source file
|
|
661
|
+
let uiDom = new JSDOM(fs_1.default.readFileSync(nodeDescriptor.sourceFile()));
|
|
662
|
+
// apply the onCompose section if available.
|
|
663
|
+
let onCompose = uiDom.window.document.querySelector("script[template-section='onCompose']")?.innerHTML;
|
|
664
|
+
if (onCompose) {
|
|
665
|
+
evalInContext({ node: nodeBuilder }, onCompose.toString());
|
|
666
|
+
}
|
|
667
|
+
// load the other sections and add them as needed.
|
|
668
|
+
let sections = ['IncludeOnce', 'IncludeEditPrepare', 'IncludeEditSave', 'IncludeEditCancel', 'IncludeEditDelete', 'IncludeEditForm', 'IncludeDocumentation'];
|
|
669
|
+
Object.values(sections).forEach(section => {
|
|
670
|
+
let sectionData = uiDom.window.document.querySelector(`[template-section='on${section}']`)?.innerHTML;
|
|
671
|
+
if (sectionData) {
|
|
672
|
+
nodeBuilder[`add${section}`](nodeDescriptor.name(), sectionData);
|
|
673
|
+
}
|
|
674
|
+
});
|
|
675
|
+
// add some of the dependencies here.
|
|
676
|
+
nodeDescriptor.templates().forEach(template => nodeBuilder.addTemplate(template));
|
|
677
|
+
return [nodeBuilder.buildType(), nodeBuilder.buildHtml(), nodeBuilder.buildDocumentation()].join("\n\n");
|
|
678
|
+
};
|
|
679
|
+
exports.buildNode = buildNode;
|