@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,95 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
TSchema,
|
|
3
|
-
TProperties,
|
|
4
|
-
SchemaOptions,
|
|
5
|
-
ObjectOptions,
|
|
6
|
-
} from "@sinclair/typebox";
|
|
7
|
-
import type { Schema } from "./types";
|
|
8
|
-
import { Type as BaseType, Kind } from "@sinclair/typebox";
|
|
9
|
-
import { TypedInputSchema } from "./base";
|
|
10
|
-
import type { TNodeRef, TTypedInput } from "./types";
|
|
11
|
-
import { isJSONType } from "ajv/dist/compile/rules";
|
|
12
|
-
|
|
13
|
-
function NodeRef<T extends new (...args: any[]) => any>(
|
|
14
|
-
nodeClass: T,
|
|
15
|
-
options?: SchemaOptions,
|
|
16
|
-
): TNodeRef<InstanceType<T>> {
|
|
17
|
-
return {
|
|
18
|
-
...BaseType.String({
|
|
19
|
-
description:
|
|
20
|
-
options?.description || `Reference to ${(nodeClass as any).type}`,
|
|
21
|
-
format: "node-id",
|
|
22
|
-
}),
|
|
23
|
-
"x-nrg-node-type": (nodeClass as any).type,
|
|
24
|
-
...options,
|
|
25
|
-
[Kind]: "NodeRef",
|
|
26
|
-
} as unknown as TNodeRef<InstanceType<T>>;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function TypedInput(options?: SchemaOptions): TTypedInput {
|
|
30
|
-
return {
|
|
31
|
-
...TypedInputSchema,
|
|
32
|
-
...options,
|
|
33
|
-
[Kind]: "TypedInput",
|
|
34
|
-
} as unknown as TTypedInput;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
const SchemaType = Object.assign({}, BaseType, {
|
|
38
|
-
NodeRef,
|
|
39
|
-
TypedInput,
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
function markNonValidatable<T extends TSchema>(schema: T): T {
|
|
43
|
-
const type = (schema as any).type;
|
|
44
|
-
|
|
45
|
-
const hasInvalidType =
|
|
46
|
-
type !== undefined &&
|
|
47
|
-
(Array.isArray(type) ? !type.every(isJSONType) : !isJSONType(type));
|
|
48
|
-
|
|
49
|
-
// NOTE: if the type is non serializable, like Functions or Constructor, we must skip validation and avoid applying defaults
|
|
50
|
-
if (hasInvalidType) {
|
|
51
|
-
(schema as any)["x-nrg-skip-validation"] = true;
|
|
52
|
-
|
|
53
|
-
if ((schema as any).default !== undefined) {
|
|
54
|
-
(schema as any)._default = (schema as any).default;
|
|
55
|
-
delete (schema as any).default;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
// NOTE: delete type to avoid the following error during validation => Error registering node types: Error: type must be JSONType or JSONType[]: Function
|
|
59
|
-
delete (schema as any).type;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
if (schema.properties) {
|
|
63
|
-
for (const prop of Object.values(schema.properties)) {
|
|
64
|
-
markNonValidatable(prop as TSchema);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
if (schema.items) {
|
|
69
|
-
markNonValidatable(schema.items as TSchema);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
if (schema.anyOf) {
|
|
73
|
-
schema.anyOf.forEach((s) => markNonValidatable(s as TSchema));
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
if (schema.allOf) {
|
|
77
|
-
schema.allOf.forEach((s) => markNonValidatable(s as TSchema));
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
if (schema.oneOf) {
|
|
81
|
-
schema.oneOf.forEach((s) => markNonValidatable(s as TSchema));
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
return schema;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
function defineSchema<T extends TProperties>(
|
|
88
|
-
properties: T,
|
|
89
|
-
options: ObjectOptions & { $id: string },
|
|
90
|
-
): Schema<T> {
|
|
91
|
-
const schema = SchemaType.Object(properties, options);
|
|
92
|
-
return markNonValidatable(schema) as Schema<T>;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
export { SchemaType, defineSchema };
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
Kind,
|
|
3
|
-
TSchema,
|
|
4
|
-
TObject,
|
|
5
|
-
TProperties,
|
|
6
|
-
Static,
|
|
7
|
-
} from "@sinclair/typebox";
|
|
8
|
-
import type { TYPED_INPUT_TYPES } from "../../../constants";
|
|
9
|
-
|
|
10
|
-
interface TNodeRef<T = any> extends TSchema {
|
|
11
|
-
[Kind]: "NodeRef";
|
|
12
|
-
static: T;
|
|
13
|
-
type: "string";
|
|
14
|
-
"x-nrg-node-type"?: string;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
type ResolveNodeRefs<T> =
|
|
18
|
-
T extends TNodeRef<infer N>
|
|
19
|
-
? N
|
|
20
|
-
: T extends (...args: any[]) => any
|
|
21
|
-
? T
|
|
22
|
-
: T extends Array<infer Item>
|
|
23
|
-
? ResolveNodeRefs<Item>[]
|
|
24
|
-
: T extends object
|
|
25
|
-
? { [K in keyof T]: ResolveNodeRefs<T[K]> }
|
|
26
|
-
: T;
|
|
27
|
-
|
|
28
|
-
type Infer<T extends TSchema> = ResolveNodeRefs<Static<T>>;
|
|
29
|
-
|
|
30
|
-
type TypedInputType = (typeof TYPED_INPUT_TYPES)[number];
|
|
31
|
-
|
|
32
|
-
interface TTypedInput extends TSchema {
|
|
33
|
-
[Kind]: "TypedInput";
|
|
34
|
-
static: {
|
|
35
|
-
value: string | number | boolean | null;
|
|
36
|
-
type: TypedInputType;
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
interface NrgFormOptions {
|
|
41
|
-
icon?: string;
|
|
42
|
-
typedInputTypes?: string[];
|
|
43
|
-
editorLanguage?: string;
|
|
44
|
-
toggle?: boolean;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
declare module "@sinclair/typebox" {
|
|
48
|
-
interface SchemaOptions {
|
|
49
|
-
exportable?: boolean;
|
|
50
|
-
"x-nrg-node-type"?: string;
|
|
51
|
-
"x-nrg-form"?: NrgFormOptions;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
interface Schema<T extends TProperties = TProperties> extends TObject<T> {
|
|
56
|
-
$id: string;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export { Infer, ResolveNodeRefs, TNodeRef, TTypedInput };
|
|
60
|
-
export type { Schema };
|
|
61
|
-
export type {
|
|
62
|
-
TSchema,
|
|
63
|
-
TObject,
|
|
64
|
-
TProperties,
|
|
65
|
-
TString,
|
|
66
|
-
TNumber,
|
|
67
|
-
TBoolean,
|
|
68
|
-
TArray,
|
|
69
|
-
TUnion,
|
|
70
|
-
TIntersect,
|
|
71
|
-
TLiteral,
|
|
72
|
-
TEnum,
|
|
73
|
-
TRecord,
|
|
74
|
-
TTuple,
|
|
75
|
-
TOptional,
|
|
76
|
-
TNull,
|
|
77
|
-
TInteger,
|
|
78
|
-
TRef,
|
|
79
|
-
TConst,
|
|
80
|
-
TFunction,
|
|
81
|
-
SchemaOptions,
|
|
82
|
-
} from "@sinclair/typebox";
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "ES2022",
|
|
4
|
-
"module": "ESNext",
|
|
5
|
-
"moduleResolution": "bundler",
|
|
6
|
-
"lib": ["ES2022"],
|
|
7
|
-
"strict": true,
|
|
8
|
-
"esModuleInterop": true,
|
|
9
|
-
"skipLibCheck": true,
|
|
10
|
-
"noEmit": true,
|
|
11
|
-
"noImplicitAny": false,
|
|
12
|
-
"noImplicitOverride": true,
|
|
13
|
-
"resolveJsonModule": true
|
|
14
|
-
},
|
|
15
|
-
"include": ["**/*.ts", "../constants.ts", "../validator.ts"],
|
|
16
|
-
"exclude": ["node_modules"]
|
|
17
|
-
}
|
|
@@ -1,220 +0,0 @@
|
|
|
1
|
-
import type { EventEmitter } from "events";
|
|
2
|
-
import type { NodeRedRuntimeSettings } from "../../../types";
|
|
3
|
-
|
|
4
|
-
// ---------------------------------------------------------------------------
|
|
5
|
-
// RED.log
|
|
6
|
-
// ---------------------------------------------------------------------------
|
|
7
|
-
|
|
8
|
-
interface NodeRedLog {
|
|
9
|
-
info(msg: any): void;
|
|
10
|
-
warn(msg: any): void;
|
|
11
|
-
error(msg: any, error?: any): void;
|
|
12
|
-
debug(msg: any): void;
|
|
13
|
-
trace(msg: any): void;
|
|
14
|
-
log(msg: { level: number; msg: string }): void;
|
|
15
|
-
metric(): boolean;
|
|
16
|
-
audit(msg: Record<string, any>, req?: any): void;
|
|
17
|
-
addHandler(handler: (msg: any) => void): void;
|
|
18
|
-
removeHandler(handler: (msg: any) => void): void;
|
|
19
|
-
FATAL: 10;
|
|
20
|
-
ERROR: 20;
|
|
21
|
-
WARN: 30;
|
|
22
|
-
INFO: 40;
|
|
23
|
-
DEBUG: 50;
|
|
24
|
-
TRACE: 60;
|
|
25
|
-
AUDIT: 98;
|
|
26
|
-
METRIC: 99;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
// ---------------------------------------------------------------------------
|
|
30
|
-
// Node-RED runtime node (the raw node object from RED.nodes.createNode)
|
|
31
|
-
// ---------------------------------------------------------------------------
|
|
32
|
-
|
|
33
|
-
interface NodeRedNode {
|
|
34
|
-
id: string;
|
|
35
|
-
type: string;
|
|
36
|
-
name?: string;
|
|
37
|
-
z?: string;
|
|
38
|
-
x: number;
|
|
39
|
-
y: number;
|
|
40
|
-
g?: string;
|
|
41
|
-
wires: string[][];
|
|
42
|
-
credentials: any;
|
|
43
|
-
_node?: any;
|
|
44
|
-
send(msg: any): void;
|
|
45
|
-
receive(msg: any): void;
|
|
46
|
-
status(
|
|
47
|
-
status: string | { fill?: string; shape?: string; text?: string },
|
|
48
|
-
): void;
|
|
49
|
-
updateWires(wires: string[][]): void;
|
|
50
|
-
on(event: string, callback: (...args: any[]) => void): void;
|
|
51
|
-
log(msg: any): void;
|
|
52
|
-
warn(msg: any): void;
|
|
53
|
-
error(msg: any, errorMsg?: any): void;
|
|
54
|
-
context(): NodeRedNodeContext;
|
|
55
|
-
[key: string]: any;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
interface NodeRedNodeContext extends NodeRedContextStore {
|
|
59
|
-
flow: NodeRedContextStore;
|
|
60
|
-
global: NodeRedContextStore;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
// ---------------------------------------------------------------------------
|
|
64
|
-
// RED.nodes
|
|
65
|
-
// ---------------------------------------------------------------------------
|
|
66
|
-
|
|
67
|
-
interface NodeRedNodes {
|
|
68
|
-
registerType(type: string, constructor: any, opts?: any): void;
|
|
69
|
-
getNode(id: string): (NodeRedNode & { _node?: any }) | undefined;
|
|
70
|
-
createNode(node: NodeRedNode, config: Record<string, any>): void;
|
|
71
|
-
getCredentials(id: string): Record<string, any> | undefined;
|
|
72
|
-
eachNode(callback: (node: any) => void): void;
|
|
73
|
-
getType(type: string): any;
|
|
74
|
-
getNodeInfo(type: string): any;
|
|
75
|
-
getNodeList(filter?: any): any[];
|
|
76
|
-
getModuleInfo(module: string): any;
|
|
77
|
-
installModule(module: string, version?: string): Promise<any>;
|
|
78
|
-
uninstallModule(module: string): Promise<any>;
|
|
79
|
-
enableNode(id: string): Promise<any>;
|
|
80
|
-
disableNode(id: string): Promise<any>;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
// ---------------------------------------------------------------------------
|
|
84
|
-
// RED.util
|
|
85
|
-
// ---------------------------------------------------------------------------
|
|
86
|
-
|
|
87
|
-
interface NodeRedUtil {
|
|
88
|
-
evaluateNodeProperty(
|
|
89
|
-
value: any,
|
|
90
|
-
type: string,
|
|
91
|
-
node: any,
|
|
92
|
-
msg: Record<string, any> | undefined,
|
|
93
|
-
callback: (err: Error | null, result: any) => void,
|
|
94
|
-
): void;
|
|
95
|
-
generateId(): string;
|
|
96
|
-
cloneMessage<T = any>(msg: T): T;
|
|
97
|
-
ensureString(o: any): string;
|
|
98
|
-
ensureBuffer(o: any): Buffer;
|
|
99
|
-
compareObjects(obj1: any, obj2: any): boolean;
|
|
100
|
-
getMessageProperty(msg: any, expr: string): any;
|
|
101
|
-
setMessageProperty(
|
|
102
|
-
msg: any,
|
|
103
|
-
prop: string,
|
|
104
|
-
value: any,
|
|
105
|
-
createMissing?: boolean,
|
|
106
|
-
): void;
|
|
107
|
-
getObjectProperty(obj: any, expr: string): any;
|
|
108
|
-
setObjectProperty(
|
|
109
|
-
obj: any,
|
|
110
|
-
prop: string,
|
|
111
|
-
value: any,
|
|
112
|
-
createMissing?: boolean,
|
|
113
|
-
): void;
|
|
114
|
-
normalisePropertyExpression(
|
|
115
|
-
str: string,
|
|
116
|
-
msg?: any,
|
|
117
|
-
toString?: boolean,
|
|
118
|
-
): string[];
|
|
119
|
-
normaliseNodeTypeName(name: string): string;
|
|
120
|
-
prepareJSONataExpression(value: string, node: any): any;
|
|
121
|
-
evaluateJSONataExpression(
|
|
122
|
-
expr: any,
|
|
123
|
-
msg: any,
|
|
124
|
-
callback: (err: Error | null, result: any) => void,
|
|
125
|
-
): void;
|
|
126
|
-
parseContextStore(key: string): {
|
|
127
|
-
store: string | undefined;
|
|
128
|
-
key: string;
|
|
129
|
-
};
|
|
130
|
-
getSetting(node: any, name: string, flow?: any): any;
|
|
131
|
-
encodeObject(obj: any): any;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
// ---------------------------------------------------------------------------
|
|
135
|
-
// RED.hooks
|
|
136
|
-
// ---------------------------------------------------------------------------
|
|
137
|
-
|
|
138
|
-
interface NodeRedHooks {
|
|
139
|
-
add(hookId: string, callback: (event: any) => void | Promise<void>): void;
|
|
140
|
-
remove(hookId: string): void;
|
|
141
|
-
trigger(
|
|
142
|
-
hookId: string,
|
|
143
|
-
event: any,
|
|
144
|
-
callback?: (err?: Error) => void,
|
|
145
|
-
): void | Promise<void>;
|
|
146
|
-
has(hookId: string): boolean;
|
|
147
|
-
clear(): void;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
// ---------------------------------------------------------------------------
|
|
151
|
-
// Express-like HTTP app (httpAdmin / httpNode)
|
|
152
|
-
// ---------------------------------------------------------------------------
|
|
153
|
-
|
|
154
|
-
type NodeRedRequestHandler = (req: any, res: any, next?: () => void) => void;
|
|
155
|
-
|
|
156
|
-
interface NodeRedExpressApp {
|
|
157
|
-
get(path: string, ...handlers: NodeRedRequestHandler[]): void;
|
|
158
|
-
post(path: string, ...handlers: NodeRedRequestHandler[]): void;
|
|
159
|
-
put(path: string, ...handlers: NodeRedRequestHandler[]): void;
|
|
160
|
-
delete(path: string, ...handlers: NodeRedRequestHandler[]): void;
|
|
161
|
-
patch(path: string, ...handlers: NodeRedRequestHandler[]): void;
|
|
162
|
-
options(path: string, ...handlers: NodeRedRequestHandler[]): void;
|
|
163
|
-
head(path: string, ...handlers: NodeRedRequestHandler[]): void;
|
|
164
|
-
use(
|
|
165
|
-
path: string | NodeRedRequestHandler,
|
|
166
|
-
...handlers: NodeRedRequestHandler[]
|
|
167
|
-
): void;
|
|
168
|
-
all(path: string, ...handlers: NodeRedRequestHandler[]): void;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
// ---------------------------------------------------------------------------
|
|
172
|
-
// RED (main interface)
|
|
173
|
-
// ---------------------------------------------------------------------------
|
|
174
|
-
|
|
175
|
-
interface RED {
|
|
176
|
-
/** Internationalization function */
|
|
177
|
-
_(key: string, substitutions?: Record<string, string>): string;
|
|
178
|
-
/** Logging API */
|
|
179
|
-
log: NodeRedLog;
|
|
180
|
-
/** Node registry and management */
|
|
181
|
-
nodes: NodeRedNodes;
|
|
182
|
-
/** Utility functions */
|
|
183
|
-
util: NodeRedUtil;
|
|
184
|
-
/** Hook system for message lifecycle and module events */
|
|
185
|
-
hooks: NodeRedHooks;
|
|
186
|
-
/** Runtime event emitter */
|
|
187
|
-
events: EventEmitter;
|
|
188
|
-
/** Express app for admin HTTP endpoints */
|
|
189
|
-
httpAdmin: NodeRedExpressApp;
|
|
190
|
-
/** Express app for node HTTP endpoints */
|
|
191
|
-
httpNode: NodeRedExpressApp;
|
|
192
|
-
/** Runtime settings (user-provided settings plus node-registered settings) */
|
|
193
|
-
settings: NodeRedRuntimeSettings & Record<string, any>;
|
|
194
|
-
/** Node-RED version string */
|
|
195
|
-
version(): string;
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
// ---------------------------------------------------------------------------
|
|
199
|
-
// Context store (internal)
|
|
200
|
-
// ---------------------------------------------------------------------------
|
|
201
|
-
|
|
202
|
-
interface NodeRedContextStore {
|
|
203
|
-
get(
|
|
204
|
-
key: string,
|
|
205
|
-
store: string | undefined,
|
|
206
|
-
callback: (err: Error | null, value: any) => void,
|
|
207
|
-
): void;
|
|
208
|
-
set(
|
|
209
|
-
key: string,
|
|
210
|
-
value: any,
|
|
211
|
-
store: string | undefined,
|
|
212
|
-
callback: (err: Error | null) => void,
|
|
213
|
-
): void;
|
|
214
|
-
keys(
|
|
215
|
-
store: string | undefined,
|
|
216
|
-
callback: (err: Error | null, keys: string[]) => void,
|
|
217
|
-
): void;
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
export { RED, NodeRedNode, NodeRedNodeContext, NodeRedContextStore };
|
package/src/core/server/utils.ts
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import type { TObject, SchemaOptions } from "@sinclair/typebox";
|
|
2
|
-
|
|
3
|
-
interface NodeSchemaOptions extends SchemaOptions {
|
|
4
|
-
"x-nrg-node-type"?: string;
|
|
5
|
-
default?: any;
|
|
6
|
-
format?: string;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
function getDefaultsFromSchema(
|
|
10
|
-
schema: TObject,
|
|
11
|
-
): Record<string, { type?: string; required: boolean; value: any }> {
|
|
12
|
-
const result: Record<
|
|
13
|
-
string,
|
|
14
|
-
{ type?: string; required: boolean; value: any }
|
|
15
|
-
> = {};
|
|
16
|
-
|
|
17
|
-
for (const [key, value] of Object.entries(schema.properties)) {
|
|
18
|
-
// NOTE: these are excluded from defaults because they must be set by the editor
|
|
19
|
-
if (["x", "y", "z", "g", "wires", "type", "id"].includes(key)) continue;
|
|
20
|
-
|
|
21
|
-
const property = value as NodeSchemaOptions;
|
|
22
|
-
|
|
23
|
-
result[key] = {
|
|
24
|
-
// NOTE: required is always false because it is controlled by the JSON Schema and AJV validation instead of using node-red client core
|
|
25
|
-
required: false,
|
|
26
|
-
value: property.default ?? undefined,
|
|
27
|
-
// NOTE: I'm using a custom json schema keyword to determine the node type
|
|
28
|
-
type: property["x-nrg-node-type"],
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
return result;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
function getCredentialsFromSchema(
|
|
36
|
-
schema: TObject,
|
|
37
|
-
): Record<string, { type: string; required: boolean; value: any }> {
|
|
38
|
-
const result: Record<
|
|
39
|
-
string,
|
|
40
|
-
{ type: string; required: boolean; value: any }
|
|
41
|
-
> = {};
|
|
42
|
-
|
|
43
|
-
for (const [key, value] of Object.entries(schema.properties)) {
|
|
44
|
-
const property = value as NodeSchemaOptions;
|
|
45
|
-
result[key] = {
|
|
46
|
-
// NOTE: required is always false because it is controlled by the JSON Schema and AJV validation instead of using node-red client core
|
|
47
|
-
required: false,
|
|
48
|
-
type: property.format === "password" ? "password" : "text",
|
|
49
|
-
value: property.default ?? undefined,
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
return result;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export { getDefaultsFromSchema, getCredentialsFromSchema };
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { Validator } from "../validator";
|
|
2
|
-
import type { RED } from "./types";
|
|
3
|
-
|
|
4
|
-
class NodeRedValidator extends Validator {
|
|
5
|
-
constructor(RED: RED) {
|
|
6
|
-
super({
|
|
7
|
-
customKeywords: [
|
|
8
|
-
{
|
|
9
|
-
keyword: "x-nrg-skip-validation",
|
|
10
|
-
schemaType: "boolean",
|
|
11
|
-
valid: true,
|
|
12
|
-
},
|
|
13
|
-
{
|
|
14
|
-
keyword: "x-nrg-node-type",
|
|
15
|
-
type: "string",
|
|
16
|
-
validate: (schemaValue: string, dataValue: string) => {
|
|
17
|
-
if (!dataValue) return true;
|
|
18
|
-
const node = RED.nodes.getNode(dataValue);
|
|
19
|
-
return node?.type === schemaValue;
|
|
20
|
-
},
|
|
21
|
-
},
|
|
22
|
-
],
|
|
23
|
-
customFormats: {
|
|
24
|
-
"node-id": /^[a-zA-Z0-9-_]+$/,
|
|
25
|
-
"flow-id": /^[a-f0-9]{16}$/,
|
|
26
|
-
"topic-path": (data: string) => /^[a-zA-Z0-9/_-]+$/.test(data),
|
|
27
|
-
},
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export let validator: NodeRedValidator = undefined!;
|
|
33
|
-
|
|
34
|
-
export function initValidator(RED: RED): void {
|
|
35
|
-
validator = new NodeRedValidator(RED);
|
|
36
|
-
}
|