@bonsae/nrg 0.5.4 → 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.
@@ -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 };
@@ -1,3 +1,4 @@
1
1
  export * from "./node";
2
2
  export * from "./io-node";
3
3
  export * from "./config-node";
4
+ export type * from "./factories";
@@ -28,7 +28,10 @@ type IONodeContext = {
28
28
  global: NodeContextStore;
29
29
  };
30
30
 
31
+ type HexColor = `#${string}`;
32
+
31
33
  export {
34
+ HexColor,
32
35
  IONodeConfig,
33
36
  IONodeContext,
34
37
  IONodeContextScope,
@@ -41,6 +41,7 @@ interface NrgFormOptions {
41
41
  icon?: string;
42
42
  typedInputTypes?: string[];
43
43
  editorLanguage?: string;
44
+ toggle?: boolean;
44
45
  }
45
46
 
46
47
  declare module "@sinclair/typebox" {