@bonsae/nrg 0.22.0 → 0.22.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bonsae/nrg",
3
- "version": "0.22.0",
3
+ "version": "0.22.2",
4
4
  "description": "NRG framework — build Node-RED nodes with Vue 3, TypeScript, and JSON Schema",
5
5
  "author": "Allan Oricil <allanoricil@duck.com>",
6
6
  "license": "MIT",
@@ -119,7 +119,7 @@
119
119
  }
120
120
  },
121
121
  "dependencies": {
122
- "@bonsae/nrg-runtime": "0.22.0",
122
+ "@bonsae/nrg-runtime": "0.22.2",
123
123
  "@clack/prompts": "^1.0.1",
124
124
  "@sinclair/typebox": "^0.34.33",
125
125
  "@vitejs/plugin-vue": "^5.2.3",
package/types/client.d.ts CHANGED
@@ -1 +1,266 @@
1
- export * from "@bonsae/nrg-runtime/client";
1
+ // Generated by dts-bundle-generator v9.5.1
2
+
3
+ import { Static, TSchema } from '@sinclair/typebox';
4
+ import { SchemaObject } from 'ajv';
5
+ import { App, Component } from 'vue';
6
+
7
+ interface NodeRefResolved<T = any> {
8
+ readonly __nrg_node_ref: true;
9
+ readonly __instance: T;
10
+ }
11
+ interface TypedInputResolved {
12
+ resolve(...args: any[]): any;
13
+ value: unknown;
14
+ type: string;
15
+ }
16
+ interface JsonSchemaObjectExtensions {
17
+ format?: "node-id" | "flow-id" | "topic-path" | (string & {});
18
+ /** expose this settings property to the editor via RED.settings */
19
+ exportable?: boolean;
20
+ /** set by SchemaType.NodeRef — the referenced config node type */
21
+ "x-nrg-node-type"?: string;
22
+ /** set by SchemaType.TypedInput — marks a TypedInput value/type pair */
23
+ "x-nrg-typed-input"?: boolean;
24
+ /** set by markNonValidatable — ajv skips this property */
25
+ "x-nrg-skip-validation"?: boolean;
26
+ /** form rendering hints consumed by the auto-generated editor form */
27
+ "x-nrg-form"?: {
28
+ icon?: string;
29
+ typedInputTypes?: string[];
30
+ editorLanguage?: string;
31
+ toggle?: boolean;
32
+ };
33
+ }
34
+ export interface NodeStateCredentials {
35
+ [key: string]: any;
36
+ }
37
+ export interface NodeState {
38
+ credentials: NodeStateCredentials;
39
+ [key: string]: any;
40
+ }
41
+ export interface NodeButtonDefinition {
42
+ toggle: string;
43
+ onClick: () => void;
44
+ enabled?: () => boolean;
45
+ visible?: () => boolean;
46
+ }
47
+ export interface NodeRedNodeButtonDefinition {
48
+ toggle: string;
49
+ onclick: () => void;
50
+ enabled?: () => boolean;
51
+ visible?: () => boolean;
52
+ }
53
+ export interface NodeFormDefinition {
54
+ component?: Component;
55
+ }
56
+ export interface NodeRedNode {
57
+ id: string;
58
+ type: string;
59
+ name: string;
60
+ category: string;
61
+ x: string;
62
+ y: string;
63
+ g: string;
64
+ z: string;
65
+ credentials: Record<string, any>;
66
+ _def: {
67
+ defaults: Record<string, {
68
+ value: string;
69
+ type?: string;
70
+ label?: string;
71
+ required?: boolean;
72
+ }>;
73
+ credentials: Record<string, {
74
+ value: string;
75
+ type?: "password" | "text";
76
+ label?: string;
77
+ required?: boolean;
78
+ }>;
79
+ category: string;
80
+ color?: string;
81
+ icon?: string;
82
+ label?: ((this: NodeRedNode) => string) | string;
83
+ inputs?: number;
84
+ outputs?: number;
85
+ paletteLabel?: ((this: NodeRedNode) => string) | string;
86
+ labelStyle?: ((this: NodeRedNode) => string) | string;
87
+ inputLabels?: ((this: NodeRedNode, index: number) => string) | string;
88
+ outputLabels?: ((this: NodeRedNode, index: number) => string) | string;
89
+ align?: "left" | "right";
90
+ button?: NodeRedNodeButtonDefinition;
91
+ };
92
+ _newState?: NodeRedNode;
93
+ _app?: App | null;
94
+ _: (str: string) => string;
95
+ /** dynamic port count (base outputs + enabled built-in ports) */
96
+ outputs?: number;
97
+ /** injected when the node has an inputSchema */
98
+ validateInput?: boolean;
99
+ /** built-in port toggles, present when declared in the configSchema */
100
+ errorPort?: boolean;
101
+ completePort?: boolean;
102
+ statusPort?: boolean;
103
+ /**
104
+ * Per-port output settings, indexed by base-output port. `validateOutputs` is
105
+ * injected (empty) when the node has an outputsSchema; `outputReturnProperties`
106
+ * and `outputContextModes` are author-declared (SchemaType.*) — present only
107
+ * when the node opts into per-port return keys / context modes. Read at
108
+ * runtime by IONode.
109
+ */
110
+ validateOutputs?: Record<number, boolean>;
111
+ outputContextModes?: Record<number, "carry" | "trace" | "reset">;
112
+ outputReturnProperties?: Record<number, string>;
113
+ [key: string]: any;
114
+ }
115
+ export interface NodeDefinition {
116
+ type: string;
117
+ category?: string;
118
+ color?: string;
119
+ icon?: ((this: NodeRedNode) => string) | string;
120
+ label?: ((this: NodeRedNode) => string) | string;
121
+ inputs?: number;
122
+ outputs?: number;
123
+ paletteLabel?: ((this: NodeRedNode) => string) | string;
124
+ labelStyle?: ((this: NodeRedNode) => string) | string;
125
+ inputLabels?: ((this: NodeRedNode, index: number) => string) | string;
126
+ outputLabels?: ((this: NodeRedNode, index: number) => string) | string;
127
+ align?: "left" | "right";
128
+ button?: NodeButtonDefinition;
129
+ onEditResize?: (this: NodeRedNode, size: {
130
+ width: number;
131
+ height: number;
132
+ }) => void;
133
+ onPaletteAdd?: (this: NodeRedNode) => void;
134
+ onPaletteRemove?: (this: NodeRedNode) => void;
135
+ form?: NodeFormDefinition;
136
+ }
137
+ /** Form rendering hints carried by the `x-nrg-form` schema keyword. */
138
+ export type NrgFormOptions = NonNullable<JsonSchemaObjectExtensions["x-nrg-form"]>;
139
+ /**
140
+ * A serialized property schema inside {@link JsonSchemaObject} `properties`,
141
+ * including NRG's custom keywords (shared vocabulary in core/schema-options)
142
+ * that drive form rendering and NodeRef/TypedInput identification.
143
+ */
144
+ export interface JsonPropertySchema extends JsonSchemaObjectExtensions {
145
+ type?: string | string[];
146
+ properties?: Record<string, JsonPropertySchema>;
147
+ required?: string[];
148
+ enum?: unknown[];
149
+ anyOf?: JsonPropertySchema[];
150
+ const?: unknown;
151
+ items?: JsonPropertySchema;
152
+ title?: string;
153
+ description?: string;
154
+ default?: unknown;
155
+ }
156
+ /**
157
+ * A serialized JSON Schema object as the build pipeline emits it (never a
158
+ * live TypeBox instance). Extends ajv's `SchemaObject` so it flows into
159
+ * validator APIs without casts, while keeping the `type: "object"`
160
+ * discriminant and structured `properties`/`required` that ajv's open
161
+ * `[x: string]: any` shape does not provide.
162
+ */
163
+ export interface JsonSchemaObject extends SchemaObject {
164
+ type: "object";
165
+ properties?: Record<string, JsonPropertySchema>;
166
+ required?: string[];
167
+ }
168
+ /**
169
+ * A node definition as it exists at editor runtime, after the build pipeline
170
+ * merged in the schema-derived artifacts (defaults, credentials, serialized
171
+ * schemas). Authors write {@link NodeDefinition}; the inliner provides the
172
+ * rest.
173
+ */
174
+ export interface RuntimeNodeDefinition extends NodeDefinition {
175
+ defaults?: NodeDefaults;
176
+ credentials?: NodeCredentials;
177
+ /**
178
+ * Names of the base output ports when `outputsSchema` is a record of named
179
+ * ports, in declaration order; absent for single/positional outputs. Resolved
180
+ * server-side by the inliner so the editor never guesses port names from the
181
+ * serialized schema.
182
+ */
183
+ outputPortNames?: string[];
184
+ configSchema?: JsonSchemaObject;
185
+ credentialsSchema?: JsonSchemaObject;
186
+ inputSchema?: JsonSchemaObject;
187
+ /**
188
+ * Single port, positional ports, or named ports (key = port name).
189
+ * Not constrained to object schemas: with returnProperty the raw sent
190
+ * value is validated, so results may be any schema shape.
191
+ */
192
+ outputsSchema?: JsonPropertySchema | JsonPropertySchema[] | Record<string, JsonPropertySchema>;
193
+ }
194
+ export interface NodeDefaults {
195
+ [key: string]: {
196
+ value: any;
197
+ type?: string;
198
+ label?: string;
199
+ required?: boolean;
200
+ validate?: (this: NodeRedNode, value: any, opt: any) => any;
201
+ };
202
+ }
203
+ export interface NodeCredentials {
204
+ [key: string]: {
205
+ value?: string;
206
+ type?: "password" | "text";
207
+ label?: string;
208
+ required?: boolean;
209
+ };
210
+ }
211
+ export interface NodeFeatures {
212
+ hasInputSchema: boolean;
213
+ hasOutputSchema: boolean;
214
+ /**
215
+ * Base output ports (excludes built-in error/complete/status), in port-index
216
+ * order. Drives the per-port context-mode rows in the Outputs subsection.
217
+ */
218
+ outputPorts: {
219
+ index: number;
220
+ label: string;
221
+ }[];
222
+ }
223
+ /** Client-side representation of a TypedInput field: the raw value string and its type selector. */
224
+ export interface TypedInputValue {
225
+ value: string;
226
+ type: string;
227
+ }
228
+ /**
229
+ * Maps a schema's static type to the raw values the editor form holds.
230
+ * The server counterpart (`ResolvedStatic` in server/schemas/types) maps the
231
+ * same brands — shared via core/brands — to resolved runtime values instead.
232
+ * - `NodeRef<T>` → `string` (the referenced node's id)
233
+ * - `TypedInput<T>` → `TypedInputValue` (raw value + type pair)
234
+ * - Functions pass through, arrays and objects map recursively
235
+ */
236
+ export type EditorStatic<T> = T extends NodeRefResolved<any> ? string : T extends TypedInputResolved ? TypedInputValue : T extends (...args: any[]) => any ? T : T extends Array<infer I> ? EditorStatic<I>[] : T extends object ? {
237
+ [K in keyof T]: EditorStatic<T[K]>;
238
+ } : T;
239
+ /**
240
+ * Infers the client-side TypeScript type from a TypeBox schema.
241
+ *
242
+ * Resolves schema types to their client form representations:
243
+ * - `NodeRef<T>` → `string` (node ID in the editor)
244
+ * - `TypedInput<T>` → `{ value: string; type: string }`
245
+ * - All other types resolve via TypeBox's `Static<T>`
246
+ *
247
+ * @example
248
+ * ```ts
249
+ * import type { Infer } from "@bonsae/nrg/client";
250
+ * import type { ConfigSchema } from "../schemas/my-node";
251
+ *
252
+ * type Config = Infer<typeof ConfigSchema>;
253
+ * ```
254
+ */
255
+ export type Infer<T extends TSchema> = EditorStatic<Static<T>>;
256
+
257
+ export {};
258
+
259
+ export declare function defineNode<T extends NodeDefinition>(options: T): T;
260
+ export declare function registerType(definition: NodeDefinition): Promise<void>;
261
+ export declare function registerTypes(nodes: NodeDefinition[]): Promise<void>;
262
+ export declare function useFormNode<TConfig extends TSchema = TSchema, TCredentials extends TSchema = TSchema>(): {
263
+ node: NodeRedNode & Infer<TConfig> & { credentials: Infer<TCredentials> & Record<string, any> };
264
+ schema: Record<string, any>;
265
+ errors: Record<string, string>;
266
+ };