@bonsae/nrg 0.6.0 → 0.6.2
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 +5 -5
- package/package.json +14 -75
- package/{build/server → server}/index.cjs +1 -1
- package/{src/core/client → shims}/components.d.ts +2 -0
- package/{src/tsconfig → tsconfig}/client.json +3 -3
- package/types/client.d.ts +37 -0
- package/types/index.d.ts +211 -0
- package/types/server.d.ts +2293 -0
- package/types/vite.d.ts +12 -0
- package/{build/vite → vite}/index.js +95 -0
- package/build/vite/utils.js +0 -56
- package/src/core/client/app.vue +0 -185
- package/src/core/client/components/node-red-config-input.vue +0 -79
- package/src/core/client/components/node-red-editor-input.vue +0 -307
- package/src/core/client/components/node-red-input-label.vue +0 -53
- package/src/core/client/components/node-red-input.vue +0 -93
- package/src/core/client/components/node-red-json-schema-form.vue +0 -444
- package/src/core/client/components/node-red-select-input.vue +0 -108
- package/src/core/client/components/node-red-toggle.vue +0 -115
- package/src/core/client/components/node-red-typed-input.vue +0 -158
- package/src/core/client/index.ts +0 -500
- package/src/core/client/tsconfig.json +0 -18
- package/src/core/constants.ts +0 -18
- package/src/core/errors.ts +0 -9
- package/src/core/server/api/index.ts +0 -1
- package/src/core/server/api/serve-nrg-resources.ts +0 -54
- package/src/core/server/index.ts +0 -190
- package/src/core/server/nodes/config-node.ts +0 -67
- package/src/core/server/nodes/factories.ts +0 -133
- package/src/core/server/nodes/index.ts +0 -5
- package/src/core/server/nodes/io-node.ts +0 -179
- package/src/core/server/nodes/node.ts +0 -259
- package/src/core/server/nodes/types/config-node.ts +0 -28
- package/src/core/server/nodes/types/factories.ts +0 -115
- package/src/core/server/nodes/types/index.ts +0 -4
- package/src/core/server/nodes/types/io-node.ts +0 -40
- package/src/core/server/nodes/types/node.ts +0 -41
- package/src/core/server/nodes/utils.ts +0 -106
- package/src/core/server/schemas/base.ts +0 -66
- package/src/core/server/schemas/index.ts +0 -3
- package/src/core/server/schemas/type.ts +0 -95
- package/src/core/server/schemas/types/index.ts +0 -82
- package/src/core/server/tsconfig.json +0 -17
- package/src/core/server/types/index.ts +0 -220
- package/src/core/server/utils.ts +0 -56
- package/src/core/server/validator.ts +0 -36
- package/src/core/validator.ts +0 -222
- package/src/index.ts +0 -2
- package/src/types.ts +0 -189
- package/src/utils.ts +0 -20
- package/src/vite/async-utils.ts +0 -61
- package/src/vite/client/build.ts +0 -227
- package/src/vite/client/index.ts +0 -1
- package/src/vite/client/plugins/html-generator.ts +0 -75
- package/src/vite/client/plugins/index.ts +0 -5
- package/src/vite/client/plugins/locales-generator.ts +0 -126
- package/src/vite/client/plugins/minifier.ts +0 -23
- package/src/vite/client/plugins/node-definitions-inliner.ts +0 -275
- package/src/vite/client/plugins/static-copy.ts +0 -43
- package/src/vite/defaults.ts +0 -77
- package/src/vite/errors.ts +0 -37
- package/src/vite/index.ts +0 -2
- package/src/vite/logger.ts +0 -94
- package/src/vite/node-red-launcher.ts +0 -344
- package/src/vite/plugin.ts +0 -61
- package/src/vite/plugins/build.ts +0 -85
- package/src/vite/plugins/index.ts +0 -2
- package/src/vite/plugins/server.ts +0 -267
- package/src/vite/server/build.ts +0 -124
- package/src/vite/server/index.ts +0 -1
- package/src/vite/server/plugins/index.ts +0 -3
- package/src/vite/server/plugins/output-wrapper.ts +0 -109
- package/src/vite/server/plugins/package-json-generator.ts +0 -203
- package/src/vite/server/plugins/type-generator.ts +0 -285
- package/src/vite/types.ts +0 -174
- package/src/vite/utils.ts +0 -72
- /package/{build/index.js → index.js} +0 -0
- /package/{build/server → server}/resources/nrg-client.js +0 -0
- /package/{build/server → server}/resources/vue.esm-browser.js +0 -0
- /package/{build/server → server}/resources/vue.esm-browser.prod.js +0 -0
- /package/{src/core/client → shims}/globals.d.ts +0 -0
- /package/{src/core/client → shims}/shims-vue.d.ts +0 -0
- /package/{src/tsconfig → tsconfig}/base.json +0 -0
- /package/{src/tsconfig → tsconfig}/server.json +0 -0
|
@@ -1,259 +0,0 @@
|
|
|
1
|
-
import type { Schema } from "../schemas/types";
|
|
2
|
-
import { type RED, type NodeRedNode } from "../../server/types";
|
|
3
|
-
import type {
|
|
4
|
-
ConfigNodeContext,
|
|
5
|
-
IONodeContext,
|
|
6
|
-
NodeConfig,
|
|
7
|
-
NodeCredentials,
|
|
8
|
-
TypedInput,
|
|
9
|
-
NodeSettings,
|
|
10
|
-
} from "./types";
|
|
11
|
-
import { validator } from "../validator";
|
|
12
|
-
import { setupConfigProxy } from "./utils";
|
|
13
|
-
|
|
14
|
-
abstract class Node<TConfig = any, TCredentials = any, TSettings = any> {
|
|
15
|
-
public static readonly type: string;
|
|
16
|
-
public static readonly category: "config" | string;
|
|
17
|
-
public static readonly configSchema?: Schema;
|
|
18
|
-
public static readonly credentialsSchema?: Schema;
|
|
19
|
-
public static readonly settingsSchema?: Schema;
|
|
20
|
-
|
|
21
|
-
private static _cachedSettings: any = null;
|
|
22
|
-
|
|
23
|
-
public static registered?(RED: RED): void | Promise<void>;
|
|
24
|
-
|
|
25
|
-
/** @internal */
|
|
26
|
-
public static _registered?(RED: RED): void | Promise<void>;
|
|
27
|
-
|
|
28
|
-
/** @internal */
|
|
29
|
-
public static _settings(): NodeSettings | undefined {
|
|
30
|
-
if (!this.settingsSchema) return;
|
|
31
|
-
|
|
32
|
-
const settings: NodeSettings = {};
|
|
33
|
-
const prefix = this.type.replace(/-./g, (x) => x[1].toUpperCase());
|
|
34
|
-
for (const [key, prop] of Object.entries(this.settingsSchema.properties)) {
|
|
35
|
-
const settingKey = prefix + key.charAt(0).toUpperCase() + key.slice(1);
|
|
36
|
-
settings[settingKey] = {
|
|
37
|
-
value: prop.default,
|
|
38
|
-
exportable: prop.exportable ?? false,
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
return settings;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
// NOTE:
|
|
45
|
-
public static validateSettings(RED: RED): void {
|
|
46
|
-
if (!this.settingsSchema) return;
|
|
47
|
-
|
|
48
|
-
RED.log.info("Validating settings");
|
|
49
|
-
const prefix = this.type.replace(/-./g, (x) => x[1].toUpperCase());
|
|
50
|
-
const properties = this.settingsSchema.properties;
|
|
51
|
-
const settings: Record<string, unknown> = {};
|
|
52
|
-
|
|
53
|
-
for (const key of Object.keys(properties)) {
|
|
54
|
-
const settingKey = prefix + key.charAt(0).toUpperCase() + key.slice(1);
|
|
55
|
-
const value = RED.settings[settingKey];
|
|
56
|
-
|
|
57
|
-
if (value !== undefined) {
|
|
58
|
-
settings[key] = value;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
// NOTE: assign defaults manually to avoid ajv errors for non json types (eg. Function, Constructor)
|
|
63
|
-
for (const [key, prop] of Object.entries(properties) as [string, any][]) {
|
|
64
|
-
if (settings[key] === undefined) {
|
|
65
|
-
// NOTE: here I need to use _default when it is a non validatable type (eg. Function, Constructor...)
|
|
66
|
-
const defaultValue = prop.default ?? prop._default;
|
|
67
|
-
if (defaultValue !== undefined) {
|
|
68
|
-
settings[key] = defaultValue;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
validator.validate(settings, this.settingsSchema, {
|
|
74
|
-
cacheKey: this.settingsSchema.$id || `${this.type}:settings`,
|
|
75
|
-
throwOnError: true,
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
this._cachedSettings = settings;
|
|
79
|
-
|
|
80
|
-
RED.log.info("Settings are valid");
|
|
81
|
-
}
|
|
82
|
-
protected readonly RED: RED;
|
|
83
|
-
protected readonly node: NodeRedNode;
|
|
84
|
-
protected readonly context!: ConfigNodeContext | IONodeContext;
|
|
85
|
-
public readonly config!: NodeConfig<TConfig>;
|
|
86
|
-
|
|
87
|
-
private readonly timers = new Set<NodeJS.Timeout>();
|
|
88
|
-
private readonly intervals = new Set<NodeJS.Timeout>();
|
|
89
|
-
|
|
90
|
-
constructor(
|
|
91
|
-
RED: RED,
|
|
92
|
-
node: NodeRedNode,
|
|
93
|
-
config: NodeConfig<TConfig>,
|
|
94
|
-
credentials: NodeCredentials<TCredentials>,
|
|
95
|
-
) {
|
|
96
|
-
this.RED = RED;
|
|
97
|
-
this.node = node;
|
|
98
|
-
|
|
99
|
-
const constructor = this.constructor as typeof Node;
|
|
100
|
-
if (constructor.configSchema) {
|
|
101
|
-
this.log("Validating configs");
|
|
102
|
-
const configResult = validator.validate(
|
|
103
|
-
config,
|
|
104
|
-
constructor.configSchema,
|
|
105
|
-
{
|
|
106
|
-
cacheKey:
|
|
107
|
-
constructor.configSchema.$id ||
|
|
108
|
-
`${constructor.type}:configs-schema`,
|
|
109
|
-
throwOnError: false,
|
|
110
|
-
},
|
|
111
|
-
);
|
|
112
|
-
if (!configResult.valid && configResult.errors?.length) {
|
|
113
|
-
this.warn(
|
|
114
|
-
`Config validation errors: ${configResult.errors.map((e) => `${e.instancePath} ${e.message}`).join("; ")}`,
|
|
115
|
-
);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
(this as any).config = setupConfigProxy(
|
|
119
|
-
RED,
|
|
120
|
-
config,
|
|
121
|
-
constructor.configSchema,
|
|
122
|
-
);
|
|
123
|
-
|
|
124
|
-
if (constructor.credentialsSchema && credentials) {
|
|
125
|
-
this.log("Validating credentials");
|
|
126
|
-
const credResult = validator.validate(
|
|
127
|
-
credentials,
|
|
128
|
-
constructor.credentialsSchema,
|
|
129
|
-
{
|
|
130
|
-
cacheKey:
|
|
131
|
-
constructor.credentialsSchema.$id ||
|
|
132
|
-
`${constructor.type}:credentials-schema`,
|
|
133
|
-
throwOnError: false,
|
|
134
|
-
},
|
|
135
|
-
);
|
|
136
|
-
if (!credResult.valid && credResult.errors?.length) {
|
|
137
|
-
this.warn(
|
|
138
|
-
`Credentials validation errors: ${credResult.errors.map((e) => `${e.instancePath} ${e.message}`).join("; ")}`,
|
|
139
|
-
);
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
public i18n(key: string, substitutions?: Record<string, string>): string {
|
|
145
|
-
const nodeType = (this.constructor as typeof Node).type;
|
|
146
|
-
return this.RED._(`${nodeType}.${key}`, substitutions);
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
public setTimeout(fn: () => void, ms: number): NodeJS.Timeout {
|
|
150
|
-
const timer = setTimeout(() => {
|
|
151
|
-
this.timers.delete(timer);
|
|
152
|
-
fn();
|
|
153
|
-
}, ms);
|
|
154
|
-
this.timers.add(timer);
|
|
155
|
-
return timer;
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
public setInterval(fn: () => void, ms: number): NodeJS.Timeout {
|
|
159
|
-
const interval = setInterval(fn, ms);
|
|
160
|
-
this.intervals.add(interval);
|
|
161
|
-
return interval;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
public clearTimeout(timer: NodeJS.Timeout): void {
|
|
165
|
-
clearTimeout(timer);
|
|
166
|
-
this.timers.delete(timer);
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
public clearInterval(interval: NodeJS.Timeout): void {
|
|
170
|
-
clearInterval(interval);
|
|
171
|
-
this.intervals.delete(interval);
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
public created?(): void | Promise<void>;
|
|
175
|
-
public closed?(removed?: boolean): void | Promise<void>;
|
|
176
|
-
|
|
177
|
-
// NOTE: typing msg isnt necessary in this case
|
|
178
|
-
public resolveTypedInput<T = any>(
|
|
179
|
-
typedInput: TypedInput,
|
|
180
|
-
msg?: Record<string, any>,
|
|
181
|
-
): Promise<T> {
|
|
182
|
-
return new Promise((resolve, reject) => {
|
|
183
|
-
this.RED.util.evaluateNodeProperty(
|
|
184
|
-
typedInput.value,
|
|
185
|
-
typedInput.type,
|
|
186
|
-
this.node,
|
|
187
|
-
msg,
|
|
188
|
-
(error: Error | null, result: any) => {
|
|
189
|
-
if (error) {
|
|
190
|
-
reject(error);
|
|
191
|
-
return;
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
// NOTE: some references might have not been written with the nrg framework
|
|
195
|
-
// TODO: type with NodeRedNode for nodes that don't have types
|
|
196
|
-
if (typedInput.type === "node" && result) {
|
|
197
|
-
resolve((result._node ?? result) as T);
|
|
198
|
-
return;
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
resolve(result as T);
|
|
202
|
-
},
|
|
203
|
-
);
|
|
204
|
-
});
|
|
205
|
-
}
|
|
206
|
-
// NOTE: used by the registered function. Had to be a different one to avoid calling the parent's closed again
|
|
207
|
-
/** @internal */
|
|
208
|
-
public async _closed(removed?: boolean) {
|
|
209
|
-
try {
|
|
210
|
-
await Promise.resolve(this.closed?.(removed));
|
|
211
|
-
} finally {
|
|
212
|
-
this.log("clearing timers and intervals");
|
|
213
|
-
this.timers.forEach((t) => clearTimeout(t));
|
|
214
|
-
this.intervals.forEach((i) => clearInterval(i));
|
|
215
|
-
this.timers.clear();
|
|
216
|
-
this.intervals.clear();
|
|
217
|
-
this.log("timers and intervals cleared");
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
public on(event: string, callback: (...args: any[]) => void) {
|
|
222
|
-
this.node.on(event, callback);
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
public log(msg: any) {
|
|
226
|
-
this.node.log(msg);
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
public warn(message: string) {
|
|
230
|
-
this.node.warn(message);
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
public error(message: string, msg?: any) {
|
|
234
|
-
this.node.error(message, msg);
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
public get id(): string {
|
|
238
|
-
return this.node.id;
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
public get name(): string | undefined {
|
|
242
|
-
return this.node.name;
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
public get z(): string | undefined {
|
|
246
|
-
return this.node.z;
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
public get credentials(): NodeCredentials<TCredentials> | undefined {
|
|
250
|
-
return this.node.credentials;
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
public get settings(): TSettings {
|
|
254
|
-
const constructor = this.constructor as typeof Node;
|
|
255
|
-
return (constructor._cachedSettings as TSettings) ?? ({} as TSettings);
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
export { Node };
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import type { Static } from "@sinclair/typebox";
|
|
2
|
-
import type {
|
|
3
|
-
NodeConfig,
|
|
4
|
-
NodeCredentials,
|
|
5
|
-
NodeContextScope,
|
|
6
|
-
NodeContextStore,
|
|
7
|
-
} from "../../../server/nodes/types";
|
|
8
|
-
import type { ConfigNodeConfigSchema } from "../../schemas";
|
|
9
|
-
|
|
10
|
-
type ConfigNodeContextScope = Exclude<NodeContextScope, "flow">;
|
|
11
|
-
|
|
12
|
-
type ConfigNodeConfig<TConfig = any> = NodeConfig<TConfig> &
|
|
13
|
-
Static<typeof ConfigNodeConfigSchema>;
|
|
14
|
-
|
|
15
|
-
type ConfigNodeCredentials<TCredentials = any> = NodeCredentials<TCredentials>;
|
|
16
|
-
|
|
17
|
-
type ConfigNodeContext = {
|
|
18
|
-
(scope: ConfigNodeContextScope, store?: string): NodeContextStore;
|
|
19
|
-
node: NodeContextStore;
|
|
20
|
-
global: NodeContextStore;
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
export {
|
|
24
|
-
ConfigNodeConfig,
|
|
25
|
-
ConfigNodeContext,
|
|
26
|
-
ConfigNodeCredentials,
|
|
27
|
-
ConfigNodeContextScope,
|
|
28
|
-
};
|
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
import { type Static, type TSchema } from "@sinclair/typebox";
|
|
2
|
-
import type { RED } from "../../types";
|
|
3
|
-
import type { IONode } from "../io-node";
|
|
4
|
-
import type { ConfigNode } from "../config-node";
|
|
5
|
-
import type { HexColor } from "./io-node";
|
|
6
|
-
|
|
7
|
-
type InferOr<T, Fallback> = T extends TSchema ? Static<T> : Fallback;
|
|
8
|
-
|
|
9
|
-
type InferOutputs<T> = T extends readonly TSchema[]
|
|
10
|
-
? { [K in keyof T]: T[K] extends TSchema ? Static<T[K]> : never }
|
|
11
|
-
: T extends TSchema
|
|
12
|
-
? Static<T>
|
|
13
|
-
: any;
|
|
14
|
-
|
|
15
|
-
type BoundIONode<
|
|
16
|
-
TC extends TSchema | undefined,
|
|
17
|
-
TCr extends TSchema | undefined,
|
|
18
|
-
TS extends TSchema | undefined,
|
|
19
|
-
TIn extends TSchema | undefined,
|
|
20
|
-
TOut extends TSchema | readonly TSchema[] | undefined,
|
|
21
|
-
> = IONode<
|
|
22
|
-
InferOr<TC, any>,
|
|
23
|
-
InferOr<TCr, any>,
|
|
24
|
-
InferOr<TIn, any>,
|
|
25
|
-
InferOutputs<TOut>,
|
|
26
|
-
InferOr<TS, any>
|
|
27
|
-
>;
|
|
28
|
-
|
|
29
|
-
type BoundConfigNode<
|
|
30
|
-
TC extends TSchema | undefined,
|
|
31
|
-
TCr extends TSchema | undefined,
|
|
32
|
-
TS extends TSchema | undefined,
|
|
33
|
-
> = ConfigNode<InferOr<TC, any>, InferOr<TCr, any>, InferOr<TS, any>>;
|
|
34
|
-
|
|
35
|
-
interface IONodeDefinition<
|
|
36
|
-
TConfigSchema extends TSchema | undefined = undefined,
|
|
37
|
-
TCredsSchema extends TSchema | undefined = undefined,
|
|
38
|
-
TSettingsSchema extends TSchema | undefined = undefined,
|
|
39
|
-
TInputSchema extends TSchema | undefined = undefined,
|
|
40
|
-
TOutputsSchema extends TSchema | readonly TSchema[] | undefined = undefined,
|
|
41
|
-
> {
|
|
42
|
-
type: string;
|
|
43
|
-
category?: string;
|
|
44
|
-
color?: HexColor;
|
|
45
|
-
inputs?: 0 | 1;
|
|
46
|
-
outputs?: number;
|
|
47
|
-
paletteLabel?: string;
|
|
48
|
-
inputLabels?: string | string[];
|
|
49
|
-
outputLabels?: string | string[];
|
|
50
|
-
align?: "left" | "right";
|
|
51
|
-
labelStyle?: string;
|
|
52
|
-
|
|
53
|
-
configSchema?: TConfigSchema;
|
|
54
|
-
credentialsSchema?: TCredsSchema;
|
|
55
|
-
settingsSchema?: TSettingsSchema;
|
|
56
|
-
inputSchema?: TInputSchema;
|
|
57
|
-
outputsSchema?: TOutputsSchema;
|
|
58
|
-
|
|
59
|
-
validateInput?: boolean;
|
|
60
|
-
validateOutput?: boolean;
|
|
61
|
-
|
|
62
|
-
registered?(RED: RED): void | Promise<void>;
|
|
63
|
-
created?(
|
|
64
|
-
this: BoundIONode<
|
|
65
|
-
TConfigSchema,
|
|
66
|
-
TCredsSchema,
|
|
67
|
-
TSettingsSchema,
|
|
68
|
-
TInputSchema,
|
|
69
|
-
TOutputsSchema
|
|
70
|
-
>,
|
|
71
|
-
): void | Promise<void>;
|
|
72
|
-
closed?(
|
|
73
|
-
this: BoundIONode<
|
|
74
|
-
TConfigSchema,
|
|
75
|
-
TCredsSchema,
|
|
76
|
-
TSettingsSchema,
|
|
77
|
-
TInputSchema,
|
|
78
|
-
TOutputsSchema
|
|
79
|
-
>,
|
|
80
|
-
removed?: boolean,
|
|
81
|
-
): void | Promise<void>;
|
|
82
|
-
input(
|
|
83
|
-
this: BoundIONode<
|
|
84
|
-
TConfigSchema,
|
|
85
|
-
TCredsSchema,
|
|
86
|
-
TSettingsSchema,
|
|
87
|
-
TInputSchema,
|
|
88
|
-
TOutputsSchema
|
|
89
|
-
>,
|
|
90
|
-
msg: InferOr<TInputSchema, any>,
|
|
91
|
-
): void | Promise<void>;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
interface ConfigNodeDefinition<
|
|
95
|
-
TConfigSchema extends TSchema | undefined = undefined,
|
|
96
|
-
TCredsSchema extends TSchema | undefined = undefined,
|
|
97
|
-
TSettingsSchema extends TSchema | undefined = undefined,
|
|
98
|
-
> {
|
|
99
|
-
type: string;
|
|
100
|
-
|
|
101
|
-
configSchema?: TConfigSchema;
|
|
102
|
-
credentialsSchema?: TCredsSchema;
|
|
103
|
-
settingsSchema?: TSettingsSchema;
|
|
104
|
-
|
|
105
|
-
registered?(RED: RED): void | Promise<void>;
|
|
106
|
-
created?(
|
|
107
|
-
this: BoundConfigNode<TConfigSchema, TCredsSchema, TSettingsSchema>,
|
|
108
|
-
): void | Promise<void>;
|
|
109
|
-
closed?(
|
|
110
|
-
this: BoundConfigNode<TConfigSchema, TCredsSchema, TSettingsSchema>,
|
|
111
|
-
removed?: boolean,
|
|
112
|
-
): void | Promise<void>;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
export type { InferOr, InferOutputs, IONodeDefinition, ConfigNodeDefinition };
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import type { Static } from "@sinclair/typebox";
|
|
2
|
-
import type { IONodeConfigSchema } from "../../schemas";
|
|
3
|
-
import type {
|
|
4
|
-
NodeConfig,
|
|
5
|
-
NodeCredentials,
|
|
6
|
-
NodeContextStore,
|
|
7
|
-
NodeContextScope,
|
|
8
|
-
} from "../../../server/nodes/types";
|
|
9
|
-
|
|
10
|
-
type IONodeContextScope = NodeContextScope;
|
|
11
|
-
|
|
12
|
-
type IONodeConfig<TConfig = any> = NodeConfig<TConfig> &
|
|
13
|
-
Static<typeof IONodeConfigSchema> & {
|
|
14
|
-
validateInput?: boolean;
|
|
15
|
-
validateOutput?: boolean;
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
type IONodeCredentials<TCredentials = any> = NodeCredentials<TCredentials>;
|
|
19
|
-
|
|
20
|
-
type IONodeStatus =
|
|
21
|
-
| { fill?: "red" | "green"; shape?: "dot" | "string"; text?: string }
|
|
22
|
-
| string;
|
|
23
|
-
|
|
24
|
-
type IONodeContext = {
|
|
25
|
-
(scope: IONodeContextScope, store?: string): NodeContextStore;
|
|
26
|
-
node: NodeContextStore;
|
|
27
|
-
flow: NodeContextStore;
|
|
28
|
-
global: NodeContextStore;
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
type HexColor = `#${string}`;
|
|
32
|
-
|
|
33
|
-
export {
|
|
34
|
-
HexColor,
|
|
35
|
-
IONodeConfig,
|
|
36
|
-
IONodeContext,
|
|
37
|
-
IONodeContextScope,
|
|
38
|
-
IONodeCredentials,
|
|
39
|
-
IONodeStatus,
|
|
40
|
-
};
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import type { Static } from "@sinclair/typebox";
|
|
2
|
-
import type { NodeConfigSchema, TTypedInput } from "../../schemas";
|
|
3
|
-
import type { RED } from "../../../server/types";
|
|
4
|
-
|
|
5
|
-
type NodeContextScope = "node" | "flow" | "global";
|
|
6
|
-
|
|
7
|
-
interface NodeContextStore {
|
|
8
|
-
get<T = any>(key: string): Promise<T>;
|
|
9
|
-
set<T = any>(key: string, value: T): Promise<void>;
|
|
10
|
-
keys(): Promise<string[]>;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
type NodeConstructor<T = any> = (new (...args: any[]) => T) & {
|
|
14
|
-
type: string;
|
|
15
|
-
registered?(RED: RED): void | Promise<void>;
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
type NodeConfig<TConfig = any> = TConfig & Static<typeof NodeConfigSchema>;
|
|
19
|
-
|
|
20
|
-
type NodeCredentials<TCredentials = any> = TCredentials;
|
|
21
|
-
|
|
22
|
-
interface NodeSetting<T = any> {
|
|
23
|
-
value: T;
|
|
24
|
-
exportable?: boolean;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
type NodeSettings = Record<string, NodeSetting>;
|
|
28
|
-
|
|
29
|
-
// TODO: move this somewhere else
|
|
30
|
-
type TypedInput = Static<TTypedInput>;
|
|
31
|
-
|
|
32
|
-
export {
|
|
33
|
-
NodeConfig,
|
|
34
|
-
NodeContextStore,
|
|
35
|
-
NodeContextScope,
|
|
36
|
-
NodeConstructor,
|
|
37
|
-
NodeCredentials,
|
|
38
|
-
NodeSetting,
|
|
39
|
-
NodeSettings,
|
|
40
|
-
TypedInput,
|
|
41
|
-
};
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
import type { ResolveNodeRefs } from "../schemas/types";
|
|
2
|
-
import type { RED, NodeRedContextStore } from "../types";
|
|
3
|
-
import type { NodeContextStore } from "./types";
|
|
4
|
-
import { NrgError } from "../../errors";
|
|
5
|
-
|
|
6
|
-
function setupContext(
|
|
7
|
-
context: NodeRedContextStore,
|
|
8
|
-
store?: string,
|
|
9
|
-
): NodeContextStore {
|
|
10
|
-
return {
|
|
11
|
-
get: (key) =>
|
|
12
|
-
new Promise((resolve, reject) =>
|
|
13
|
-
context.get(key, store, (error, value) =>
|
|
14
|
-
error ? reject(error) : resolve(value),
|
|
15
|
-
),
|
|
16
|
-
),
|
|
17
|
-
|
|
18
|
-
set: (key, value) =>
|
|
19
|
-
new Promise((resolve, reject) =>
|
|
20
|
-
context.set(key, value, store, (error) =>
|
|
21
|
-
error ? reject(error) : resolve(),
|
|
22
|
-
),
|
|
23
|
-
),
|
|
24
|
-
|
|
25
|
-
keys: () =>
|
|
26
|
-
new Promise((resolve, reject) =>
|
|
27
|
-
context.keys(store, (error, k) => (error ? reject(error) : resolve(k))),
|
|
28
|
-
),
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
function setupConfigProxy<T extends object>(
|
|
33
|
-
RED: RED,
|
|
34
|
-
config: T,
|
|
35
|
-
schema?: any,
|
|
36
|
-
): ResolveNodeRefs<T> {
|
|
37
|
-
const SKIP_PROPS = new Set(["id", "_id", "_users"]);
|
|
38
|
-
|
|
39
|
-
// Build a set of property names that are node references based on the schema.
|
|
40
|
-
// Only these properties will have their string values resolved via RED.nodes.getNode().
|
|
41
|
-
const nodeRefProps = new Set<string>();
|
|
42
|
-
if (schema?.properties) {
|
|
43
|
-
for (const [key, propSchema] of Object.entries(schema.properties)) {
|
|
44
|
-
if ((propSchema as any)?.["x-nrg-node-type"]) {
|
|
45
|
-
nodeRefProps.add(key);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
// Per-node-instance cache: original object/array -> proxy or mapped array.
|
|
51
|
-
// This preserves reference equality: config.server === config.server
|
|
52
|
-
const cache = new WeakMap<object, any>();
|
|
53
|
-
|
|
54
|
-
const createProxy = <O extends object>(obj: O): any => {
|
|
55
|
-
const cached = cache.get(obj);
|
|
56
|
-
if (cached) return cached;
|
|
57
|
-
|
|
58
|
-
if (Array.isArray(obj)) {
|
|
59
|
-
// Map once, cache the result array so identity is stable across reads
|
|
60
|
-
const mapped = obj.map((item) => {
|
|
61
|
-
if (item && typeof item === "object") {
|
|
62
|
-
return createProxy(item);
|
|
63
|
-
}
|
|
64
|
-
return item;
|
|
65
|
-
});
|
|
66
|
-
cache.set(obj, mapped);
|
|
67
|
-
return mapped;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
const proxy = new Proxy(obj, {
|
|
71
|
-
get(target: any, prop: string | symbol): any {
|
|
72
|
-
if (typeof prop === "symbol") return target[prop];
|
|
73
|
-
if (SKIP_PROPS.has(prop)) return target[prop];
|
|
74
|
-
|
|
75
|
-
const value = target[prop];
|
|
76
|
-
|
|
77
|
-
// Only resolve strings as node references if the schema marks the property
|
|
78
|
-
if (
|
|
79
|
-
typeof value === "string" &&
|
|
80
|
-
value.length > 0 &&
|
|
81
|
-
nodeRefProps.has(prop)
|
|
82
|
-
) {
|
|
83
|
-
return RED.nodes.getNode(value)?._node ?? value;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
if (value && typeof value === "object") {
|
|
87
|
-
return createProxy(value); // hits the cache on repeat access
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
return value;
|
|
91
|
-
},
|
|
92
|
-
set(_target: any, prop: string | symbol): boolean {
|
|
93
|
-
throw new NrgError(
|
|
94
|
-
`Cannot set property '${String(prop)}' on read-only node config`,
|
|
95
|
-
);
|
|
96
|
-
},
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
cache.set(obj, proxy);
|
|
100
|
-
return proxy;
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
return createProxy(config) as ResolveNodeRefs<T>;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
export { setupConfigProxy, setupContext };
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import { TYPED_INPUT_TYPES } from "../../constants";
|
|
2
|
-
import { SchemaType } from "./type";
|
|
3
|
-
|
|
4
|
-
const NodeConfigSchema = SchemaType.Object({
|
|
5
|
-
id: SchemaType.String(),
|
|
6
|
-
type: SchemaType.String(),
|
|
7
|
-
name: SchemaType.String(),
|
|
8
|
-
z: SchemaType.Optional(SchemaType.String()),
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
const ConfigNodeConfigSchema = SchemaType.Object({
|
|
12
|
-
...NodeConfigSchema.properties,
|
|
13
|
-
_users: SchemaType.Array(SchemaType.String()),
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
const IONodeConfigSchema = SchemaType.Object({
|
|
17
|
-
...NodeConfigSchema.properties,
|
|
18
|
-
wires: SchemaType.Array(
|
|
19
|
-
SchemaType.Array(SchemaType.String(), { default: [] }),
|
|
20
|
-
{
|
|
21
|
-
default: [[]],
|
|
22
|
-
},
|
|
23
|
-
),
|
|
24
|
-
x: SchemaType.Number(),
|
|
25
|
-
y: SchemaType.Number(),
|
|
26
|
-
g: SchemaType.Optional(SchemaType.String()),
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
const TypedInputSchema = SchemaType.Object(
|
|
30
|
-
{
|
|
31
|
-
value: SchemaType.Union(
|
|
32
|
-
[
|
|
33
|
-
SchemaType.String(),
|
|
34
|
-
SchemaType.Number(),
|
|
35
|
-
SchemaType.Boolean(),
|
|
36
|
-
SchemaType.Null(),
|
|
37
|
-
],
|
|
38
|
-
{
|
|
39
|
-
description: "The actual value entered or selected.",
|
|
40
|
-
default: "",
|
|
41
|
-
},
|
|
42
|
-
),
|
|
43
|
-
type: SchemaType.Union(
|
|
44
|
-
TYPED_INPUT_TYPES.map((type) => SchemaType.Literal(type)),
|
|
45
|
-
{
|
|
46
|
-
description:
|
|
47
|
-
"The type of the value (string, number, message property, etc.)",
|
|
48
|
-
default: "str",
|
|
49
|
-
},
|
|
50
|
-
),
|
|
51
|
-
},
|
|
52
|
-
{
|
|
53
|
-
description: "Represents a Node-RED TypedInput value and its type.",
|
|
54
|
-
default: {
|
|
55
|
-
type: "str",
|
|
56
|
-
value: "",
|
|
57
|
-
},
|
|
58
|
-
},
|
|
59
|
-
);
|
|
60
|
-
|
|
61
|
-
export {
|
|
62
|
-
ConfigNodeConfigSchema,
|
|
63
|
-
IONodeConfigSchema,
|
|
64
|
-
NodeConfigSchema,
|
|
65
|
-
TypedInputSchema,
|
|
66
|
-
};
|