@bonsae/nrg 0.5.3 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +56 -7
- package/build/server/index.cjs +120 -39
- package/build/server/resources/nrg-client.js +1653 -1590
- package/build/vite/index.js +3 -1
- package/package.json +7 -1
- package/src/core/client/app.vue +16 -26
- package/src/core/client/components/node-red-json-schema-form.vue +23 -3
- package/src/core/client/components/node-red-toggle.vue +115 -0
- package/src/core/client/components/node-red-typed-input.vue +6 -0
- package/src/core/client/index.ts +19 -25
- package/src/core/server/api/index.ts +1 -0
- package/src/core/server/api/serve-nrg-resources.ts +54 -0
- package/src/core/server/index.ts +21 -57
- package/src/core/server/nodes/factories.ts +133 -0
- package/src/core/server/nodes/index.ts +1 -0
- package/src/core/server/nodes/io-node.ts +2 -1
- package/src/core/server/nodes/types/factories.ts +115 -0
- package/src/core/server/nodes/types/index.ts +1 -0
- package/src/core/server/nodes/types/io-node.ts +3 -0
- package/src/core/server/schemas/types/index.ts +1 -0
- package/src/vite/client/build.ts +3 -1
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { type TSchema } from "@sinclair/typebox";
|
|
2
|
+
import type { Schema } from "../schemas/types";
|
|
3
|
+
import type { RED } from "../types";
|
|
4
|
+
import type {
|
|
5
|
+
InferOr,
|
|
6
|
+
InferOutputs,
|
|
7
|
+
IONodeDefinition,
|
|
8
|
+
ConfigNodeDefinition,
|
|
9
|
+
HexColor,
|
|
10
|
+
} from "./types";
|
|
11
|
+
import { IONode } from "./io-node";
|
|
12
|
+
import { ConfigNode } from "./config-node";
|
|
13
|
+
|
|
14
|
+
function defineIONode<
|
|
15
|
+
TConfigSchema extends TSchema | undefined = undefined,
|
|
16
|
+
TCredsSchema extends TSchema | undefined = undefined,
|
|
17
|
+
TSettingsSchema extends TSchema | undefined = undefined,
|
|
18
|
+
TInputSchema extends TSchema | undefined = undefined,
|
|
19
|
+
TOutputsSchema extends TSchema | readonly TSchema[] | undefined = undefined,
|
|
20
|
+
>(
|
|
21
|
+
def: IONodeDefinition<
|
|
22
|
+
TConfigSchema,
|
|
23
|
+
TCredsSchema,
|
|
24
|
+
TSettingsSchema,
|
|
25
|
+
TInputSchema,
|
|
26
|
+
TOutputsSchema
|
|
27
|
+
>,
|
|
28
|
+
) {
|
|
29
|
+
const NodeClass = class extends IONode<
|
|
30
|
+
InferOr<TConfigSchema, any>,
|
|
31
|
+
InferOr<TCredsSchema, any>,
|
|
32
|
+
InferOr<TInputSchema, any>,
|
|
33
|
+
InferOutputs<TOutputsSchema>,
|
|
34
|
+
InferOr<TSettingsSchema, any>
|
|
35
|
+
> {
|
|
36
|
+
static override readonly type: string = def.type;
|
|
37
|
+
static override readonly category: string = def.category ?? "function";
|
|
38
|
+
static override readonly color: HexColor = def.color ?? "#a6bbcf";
|
|
39
|
+
static override readonly inputs: number = def.inputs ?? 1;
|
|
40
|
+
static override readonly outputs: number = def.outputs ?? 1;
|
|
41
|
+
static override readonly paletteLabel = def.paletteLabel;
|
|
42
|
+
static override readonly inputLabels = def.inputLabels;
|
|
43
|
+
static override readonly outputLabels = def.outputLabels;
|
|
44
|
+
static override readonly align = def.align;
|
|
45
|
+
static override readonly labelStyle = def.labelStyle;
|
|
46
|
+
|
|
47
|
+
static override readonly configSchema: Schema | undefined =
|
|
48
|
+
def.configSchema as Schema | undefined;
|
|
49
|
+
static override readonly credentialsSchema: Schema | undefined =
|
|
50
|
+
def.credentialsSchema as Schema | undefined;
|
|
51
|
+
static override readonly settingsSchema: Schema | undefined =
|
|
52
|
+
def.settingsSchema as Schema | undefined;
|
|
53
|
+
static override readonly inputSchema: Schema | undefined =
|
|
54
|
+
def.inputSchema as Schema | undefined;
|
|
55
|
+
static override readonly outputsSchema: Schema | Schema[] | undefined =
|
|
56
|
+
def.outputsSchema as Schema | Schema[] | undefined;
|
|
57
|
+
static override readonly validateInput: boolean =
|
|
58
|
+
def.validateInput ?? false;
|
|
59
|
+
static override readonly validateOutput: boolean =
|
|
60
|
+
def.validateOutput ?? false;
|
|
61
|
+
|
|
62
|
+
static override _registered(RED: RED) {
|
|
63
|
+
this.validateSettings(RED);
|
|
64
|
+
return def.registered?.(RED);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
async input(msg: InferOr<TInputSchema, any>) {
|
|
68
|
+
return def.input.call(this as any, msg);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
override async created() {
|
|
72
|
+
if (def.created) return def.created.call(this as any);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
override async closed(removed?: boolean) {
|
|
76
|
+
if (def.closed) return def.closed.call(this as any, removed);
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
Object.defineProperty(NodeClass, "name", {
|
|
81
|
+
value: def.type.replace(/(^|-)(\w)/g, (_, __, c: string) =>
|
|
82
|
+
c.toUpperCase(),
|
|
83
|
+
),
|
|
84
|
+
configurable: true,
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
return NodeClass;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function defineConfigNode<
|
|
91
|
+
TConfigSchema extends TSchema | undefined = undefined,
|
|
92
|
+
TCredsSchema extends TSchema | undefined = undefined,
|
|
93
|
+
TSettingsSchema extends TSchema | undefined = undefined,
|
|
94
|
+
>(def: ConfigNodeDefinition<TConfigSchema, TCredsSchema, TSettingsSchema>) {
|
|
95
|
+
const NodeClass = class extends ConfigNode<
|
|
96
|
+
InferOr<TConfigSchema, any>,
|
|
97
|
+
InferOr<TCredsSchema, any>,
|
|
98
|
+
InferOr<TSettingsSchema, any>
|
|
99
|
+
> {
|
|
100
|
+
static override readonly type: string = def.type;
|
|
101
|
+
|
|
102
|
+
static override readonly configSchema: Schema | undefined =
|
|
103
|
+
def.configSchema as Schema | undefined;
|
|
104
|
+
static override readonly credentialsSchema: Schema | undefined =
|
|
105
|
+
def.credentialsSchema as Schema | undefined;
|
|
106
|
+
static override readonly settingsSchema: Schema | undefined =
|
|
107
|
+
def.settingsSchema as Schema | undefined;
|
|
108
|
+
|
|
109
|
+
static override _registered(RED: RED) {
|
|
110
|
+
this.validateSettings(RED);
|
|
111
|
+
return def.registered?.(RED);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
override async created() {
|
|
115
|
+
if (def.created) return def.created.call(this as any);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
override async closed(removed?: boolean) {
|
|
119
|
+
if (def.closed) return def.closed.call(this as any, removed);
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
Object.defineProperty(NodeClass, "name", {
|
|
124
|
+
value: def.type.replace(/(^|-)(\w)/g, (_, __, c: string) =>
|
|
125
|
+
c.toUpperCase(),
|
|
126
|
+
),
|
|
127
|
+
configurable: true,
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
return NodeClass;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export { defineIONode, defineConfigNode };
|
|
@@ -3,6 +3,7 @@ import type { RED } from "../../server/types";
|
|
|
3
3
|
import { validator } from "../validator";
|
|
4
4
|
import { Node } from "./node";
|
|
5
5
|
import type {
|
|
6
|
+
HexColor,
|
|
6
7
|
IONodeContext,
|
|
7
8
|
IONodeContextScope,
|
|
8
9
|
IONodeStatus,
|
|
@@ -19,7 +20,7 @@ abstract class IONode<
|
|
|
19
20
|
TSettings = any,
|
|
20
21
|
> extends Node<TConfig, TCredentials, TSettings> {
|
|
21
22
|
public static readonly align?: "left" | "right";
|
|
22
|
-
public static readonly color:
|
|
23
|
+
public static readonly color: HexColor;
|
|
23
24
|
public static readonly labelStyle?:
|
|
24
25
|
| "node_label"
|
|
25
26
|
| "node_label_italic"
|
|
@@ -0,0 +1,115 @@
|
|
|
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 };
|
package/src/vite/client/build.ts
CHANGED