@bonsae/nrg 0.17.0 → 0.18.1

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.
@@ -1,5 +1,8 @@
1
1
  // Generated by dts-bundle-generator v9.5.1
2
2
 
3
+ import { SchemaOptions, Static, TSchema } from '@sinclair/typebox';
4
+ import { App } from 'vue';
5
+
3
6
  export interface MockEditor {
4
7
  getValue(): string;
5
8
  setValue(val: string): void;
@@ -43,16 +46,92 @@ export interface MockRED {
43
46
  }
44
47
  export declare function createRED(): MockRED;
45
48
  export declare function createJQuery(): (selector: any, attrs?: Record<string, any>) => any;
46
- export declare const defaultConfig: {
47
- testTimeout: number;
48
- setupFiles: string[];
49
- browser: {
50
- enabled: boolean;
51
- instances: {
52
- browser: string;
53
- }[];
49
+ interface NodeRefResolved<T = any> {
50
+ readonly __nrg_node_ref: true;
51
+ readonly __instance: T;
52
+ }
53
+ interface NodeRedNodeButtonDefinition {
54
+ toggle: string;
55
+ onclick: () => void;
56
+ enabled?: () => boolean;
57
+ visible?: () => boolean;
58
+ }
59
+ interface NodeRedNode {
60
+ id: string;
61
+ type: string;
62
+ name: string;
63
+ category: string;
64
+ x: string;
65
+ y: string;
66
+ g: string;
67
+ z: string;
68
+ credentials: Record<string, any>;
69
+ _def: {
70
+ defaults: Record<string, {
71
+ value: string;
72
+ type?: string;
73
+ label?: string;
74
+ required?: boolean;
75
+ }>;
76
+ credentials: Record<string, {
77
+ value: string;
78
+ type?: "password" | "text";
79
+ label?: string;
80
+ required?: boolean;
81
+ }>;
82
+ category: string;
83
+ color?: string;
84
+ icon?: string;
85
+ label?: ((this: NodeRedNode) => string) | string;
86
+ inputs?: number;
87
+ outputs?: number;
88
+ paletteLabel?: ((this: NodeRedNode) => string) | string;
89
+ labelStyle?: ((this: NodeRedNode) => string) | string;
90
+ inputLabels?: ((this: NodeRedNode, index: number) => string) | string;
91
+ outputLabels?: ((this: NodeRedNode, index: number) => string) | string;
92
+ align?: "left" | "right";
93
+ button?: NodeRedNodeButtonDefinition;
54
94
  };
55
- };
95
+ _newState?: NodeRedNode;
96
+ _app?: App | null;
97
+ _: (str: string) => string;
98
+ [key: string]: any;
99
+ }
100
+ interface TypedInputValue {
101
+ value: string;
102
+ type: string;
103
+ }
104
+ type _ToClient<T> = T extends NodeRefResolved<any> ? string : T extends {
105
+ resolve(...args: any[]): any;
106
+ value: unknown;
107
+ type: string;
108
+ } ? TypedInputValue : T extends (...args: any[]) => any ? T : T extends Array<infer I> ? _ToClient<I>[] : T extends object ? {
109
+ [K in keyof T]: _ToClient<T[K]>;
110
+ } : T;
111
+ interface FormNode<TConfig extends TSchema = TSchema, TCredentials extends TSchema = TSchema> {
112
+ node: NodeRedNode & _ToClient<Static<TConfig>> & {
113
+ credentials: _ToClient<Static<TCredentials>> & Record<string, any>;
114
+ };
115
+ schema: Record<string, any>;
116
+ errors: Record<string, string>;
117
+ }
118
+ /**
119
+ * Composable that provides typed access to the form node, schema, and errors.
120
+ * Replaces `defineProps` in custom form components — no props declaration needed.
121
+ *
122
+ * @example
123
+ * ```vue
124
+ * <script setup lang="ts">
125
+ * import { useFormNode } from "@bonsae/nrg/client";
126
+ * import type { ConfigsSchema, CredentialsSchema } from "../../server/schemas/my-node";
127
+ *
128
+ * const { node, errors } = useFormNode<typeof ConfigsSchema, typeof CredentialsSchema>();
129
+ * node.name // string — typed from ConfigsSchema
130
+ * node.credentials.apiKey // string — typed from CredentialsSchema
131
+ * </script>
132
+ * ```
133
+ */
134
+ export declare function useFormNode<TConfig extends TSchema = TSchema, TCredentials extends TSchema = TSchema>(): FormNode<TConfig, TCredentials>;
56
135
  export interface TestNode {
57
136
  id: string;
58
137
  type: string;
@@ -61,9 +140,15 @@ export interface TestNode {
61
140
  _: (key: string) => string;
62
141
  [key: string]: any;
63
142
  }
143
+ interface FormProvide {
144
+ __nrg_form_node: TestNode;
145
+ __nrg_form_schema: Record<string, any>;
146
+ __nrg_form_errors: Record<string, string>;
147
+ }
64
148
  interface CreateNodeResult {
65
149
  node: TestNode;
66
150
  RED: MockRED;
151
+ provide: FormProvide;
67
152
  }
68
153
  export declare function createNode(overrides?: Record<string, any>): CreateNodeResult;
69
154
 
@@ -1,5 +1,8 @@
1
1
  // Generated by dts-bundle-generator v9.5.1
2
2
 
3
+ import { SchemaOptions, Static, TSchema } from '@sinclair/typebox';
4
+ import { App } from 'vue';
5
+
3
6
  export interface MockEditor {
4
7
  getValue(): string;
5
8
  setValue(val: string): void;
@@ -43,10 +46,91 @@ export interface MockRED {
43
46
  }
44
47
  export declare function createRED(): MockRED;
45
48
  export declare function createJQuery(): (selector: any, attrs?: Record<string, any>) => any;
46
- export declare const defaultConfig: {
47
- testTimeout: number;
48
- environment: "happy-dom";
49
- setupFiles: string[];
50
- };
49
+ interface NodeRefResolved<T = any> {
50
+ readonly __nrg_node_ref: true;
51
+ readonly __instance: T;
52
+ }
53
+ interface NodeRedNodeButtonDefinition {
54
+ toggle: string;
55
+ onclick: () => void;
56
+ enabled?: () => boolean;
57
+ visible?: () => boolean;
58
+ }
59
+ interface NodeRedNode {
60
+ id: string;
61
+ type: string;
62
+ name: string;
63
+ category: string;
64
+ x: string;
65
+ y: string;
66
+ g: string;
67
+ z: string;
68
+ credentials: Record<string, any>;
69
+ _def: {
70
+ defaults: Record<string, {
71
+ value: string;
72
+ type?: string;
73
+ label?: string;
74
+ required?: boolean;
75
+ }>;
76
+ credentials: Record<string, {
77
+ value: string;
78
+ type?: "password" | "text";
79
+ label?: string;
80
+ required?: boolean;
81
+ }>;
82
+ category: string;
83
+ color?: string;
84
+ icon?: string;
85
+ label?: ((this: NodeRedNode) => string) | string;
86
+ inputs?: number;
87
+ outputs?: number;
88
+ paletteLabel?: ((this: NodeRedNode) => string) | string;
89
+ labelStyle?: ((this: NodeRedNode) => string) | string;
90
+ inputLabels?: ((this: NodeRedNode, index: number) => string) | string;
91
+ outputLabels?: ((this: NodeRedNode, index: number) => string) | string;
92
+ align?: "left" | "right";
93
+ button?: NodeRedNodeButtonDefinition;
94
+ };
95
+ _newState?: NodeRedNode;
96
+ _app?: App | null;
97
+ _: (str: string) => string;
98
+ [key: string]: any;
99
+ }
100
+ interface TypedInputValue {
101
+ value: string;
102
+ type: string;
103
+ }
104
+ type _ToClient<T> = T extends NodeRefResolved<any> ? string : T extends {
105
+ resolve(...args: any[]): any;
106
+ value: unknown;
107
+ type: string;
108
+ } ? TypedInputValue : T extends (...args: any[]) => any ? T : T extends Array<infer I> ? _ToClient<I>[] : T extends object ? {
109
+ [K in keyof T]: _ToClient<T[K]>;
110
+ } : T;
111
+ interface FormNode<TConfig extends TSchema = TSchema, TCredentials extends TSchema = TSchema> {
112
+ node: NodeRedNode & _ToClient<Static<TConfig>> & {
113
+ credentials: _ToClient<Static<TCredentials>> & Record<string, any>;
114
+ };
115
+ schema: Record<string, any>;
116
+ errors: Record<string, string>;
117
+ }
118
+ /**
119
+ * Composable that provides typed access to the form node, schema, and errors.
120
+ * Replaces `defineProps` in custom form components — no props declaration needed.
121
+ *
122
+ * @example
123
+ * ```vue
124
+ * <script setup lang="ts">
125
+ * import { useFormNode } from "@bonsae/nrg/client";
126
+ * import type { ConfigsSchema, CredentialsSchema } from "../../server/schemas/my-node";
127
+ *
128
+ * const { node, errors } = useFormNode<typeof ConfigsSchema, typeof CredentialsSchema>();
129
+ * node.name // string — typed from ConfigsSchema
130
+ * node.credentials.apiKey // string — typed from CredentialsSchema
131
+ * </script>
132
+ * ```
133
+ */
134
+ export declare function useFormNode<TConfig extends TSchema = TSchema, TCredentials extends TSchema = TSchema>(): FormNode<TConfig, TCredentials>;
51
135
 
52
136
  export {};
@@ -390,11 +390,18 @@ type ExtractInput<T> = T extends {
390
390
  type ExtractOutput<T> = T extends {
391
391
  send(msg: infer O): any;
392
392
  } ? O : any;
393
+ type PortNames<T> = [
394
+ T
395
+ ] extends [
396
+ Record<string, Record<string, any>>
397
+ ] ? string extends keyof T ? never : keyof T & string : never;
398
+ type PortMessage<T, P extends string> = T extends Record<string, any> ? (P extends keyof T ? T[P] : never) : never;
393
399
  interface TestNodeHelpers<TInput = any, TOutput = any> {
394
400
  receive(msg: TInput): Promise<void>;
395
401
  close(removed?: boolean): Promise<void>;
396
402
  reset(): void;
397
403
  sent(): TOutput[];
404
+ sent<P extends PortNames<TOutput>>(port: P): PortMessage<TOutput, P>[];
398
405
  sent(port: number): any[];
399
406
  statuses(): any[];
400
407
  logged(level?: "info" | "warn" | "error" | "debug"): string[];
package/vite/index.js CHANGED
@@ -77,8 +77,12 @@ function copyFiles(targets, outDir) {
77
77
  function getPackageName() {
78
78
  const pkgPath = path.resolve("./package.json");
79
79
  if (fs.existsSync(pkgPath)) {
80
- const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf-8"));
81
- return pkg.name;
80
+ try {
81
+ const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf-8"));
82
+ return pkg.name;
83
+ } catch {
84
+ return "node-red-nodes";
85
+ }
82
86
  }
83
87
  return "node-red-nodes";
84
88
  }
@@ -2375,7 +2379,7 @@ async function build2(clientBuildOptions, buildContext) {
2375
2379
  const config = {
2376
2380
  configFile: false,
2377
2381
  logLevel: "warn",
2378
- base: `/${path11.join("resources", buildContext.packageName)}`,
2382
+ base: `/resources/${buildContext.packageName}`,
2379
2383
  publicDir: path11.resolve(srcDir, "public"),
2380
2384
  resolve: {
2381
2385
  alias: {
@@ -2405,9 +2409,9 @@ async function build2(clientBuildOptions, buildContext) {
2405
2409
  external,
2406
2410
  treeshake: false,
2407
2411
  output: {
2408
- entryFileNames: path11.join("resources", "index.[hash].js"),
2409
- chunkFileNames: path11.join("resources", "vendor.[hash].js"),
2410
- assetFileNames: path11.join("resources", "[name].[hash].[ext]"),
2412
+ entryFileNames: "resources/index.[hash].js",
2413
+ chunkFileNames: "resources/vendor.[hash].js",
2414
+ assetFileNames: "resources/[name].[hash].[ext]",
2411
2415
  globals,
2412
2416
  paths: {
2413
2417
  vue: "/nrg/assets/vue.esm-browser.prod.js",