@bonsae/nrg 0.4.0 → 0.5.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/build/server/index.cjs +10 -17
- package/build/server/resources/nrg-client.js +3387 -3211
- package/build/vite/index.js +8 -6
- package/package.json +1 -1
- package/src/core/client/app.vue +2 -8
- package/src/core/client/components/node-red-config-input.vue +22 -0
- package/src/core/client/components/node-red-editor-input.vue +22 -0
- package/src/core/client/components/node-red-input-label.vue +53 -0
- package/src/core/client/components/node-red-input.vue +22 -0
- package/src/core/client/components/node-red-json-schema-form.vue +89 -44
- package/src/core/client/components/node-red-select-input.vue +22 -0
- package/src/core/client/components/node-red-typed-input.vue +22 -0
- package/src/core/client/index.ts +2 -0
- package/src/core/server/schemas/type.ts +5 -19
- package/src/core/server/schemas/types/index.ts +9 -1
- package/src/core/server/utils.ts +2 -2
- package/src/core/server/validator.ts +6 -2
- package/src/vite/client/build.ts +9 -7
- package/src/vite/client/plugins/node-definitions-inliner.ts +1 -1
|
@@ -15,40 +15,26 @@ function NodeRef<T extends new (...args: any[]) => any>(
|
|
|
15
15
|
options?: SchemaOptions,
|
|
16
16
|
): TNodeRef<InstanceType<T>> {
|
|
17
17
|
return {
|
|
18
|
-
...
|
|
18
|
+
...BaseType.String({
|
|
19
19
|
description:
|
|
20
20
|
options?.description || `Reference to ${(nodeClass as any).type}`,
|
|
21
21
|
format: "node-id",
|
|
22
22
|
}),
|
|
23
|
-
"node-type": (nodeClass as any).type,
|
|
23
|
+
"x-nrg-node-type": (nodeClass as any).type,
|
|
24
24
|
...options,
|
|
25
25
|
[Kind]: "NodeRef",
|
|
26
26
|
} as unknown as TNodeRef<InstanceType<T>>;
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
function TypedInput(
|
|
30
|
-
options?: SchemaOptions & { types?: string[] },
|
|
31
|
-
): TTypedInput {
|
|
32
|
-
const { types, ...rest } = options ?? {};
|
|
29
|
+
function TypedInput(options?: SchemaOptions): TTypedInput {
|
|
33
30
|
return {
|
|
34
31
|
...TypedInputSchema,
|
|
35
|
-
...
|
|
36
|
-
...(types ? { "x-typed-types": types } : {}),
|
|
32
|
+
...options,
|
|
37
33
|
[Kind]: "TypedInput",
|
|
38
34
|
} as unknown as TTypedInput;
|
|
39
35
|
}
|
|
40
36
|
|
|
41
|
-
const _OriginalString = BaseType.String.bind(BaseType);
|
|
42
|
-
function StringWithLang(options?: SchemaOptions & { lang?: string }) {
|
|
43
|
-
const { lang, ...rest } = options ?? {};
|
|
44
|
-
return _OriginalString({
|
|
45
|
-
...rest,
|
|
46
|
-
...(lang ? { "x-editor-language": lang } : {}),
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
|
|
50
37
|
const SchemaType = Object.assign({}, BaseType, {
|
|
51
|
-
String: StringWithLang,
|
|
52
38
|
NodeRef,
|
|
53
39
|
TypedInput,
|
|
54
40
|
});
|
|
@@ -62,7 +48,7 @@ function markNonValidatable<T extends TSchema>(schema: T): T {
|
|
|
62
48
|
|
|
63
49
|
// NOTE: if the type is non serializable, like Functions or Constructor, we must skip validation and avoid applying defaults
|
|
64
50
|
if (hasInvalidType) {
|
|
65
|
-
(schema as any)["skip-validation"] = true;
|
|
51
|
+
(schema as any)["x-nrg-skip-validation"] = true;
|
|
66
52
|
|
|
67
53
|
if ((schema as any).default !== undefined) {
|
|
68
54
|
(schema as any)._default = (schema as any).default;
|
|
@@ -11,7 +11,7 @@ interface TNodeRef<T = any> extends TSchema {
|
|
|
11
11
|
[Kind]: "NodeRef";
|
|
12
12
|
static: T;
|
|
13
13
|
type: "string";
|
|
14
|
-
"node-type"?: string;
|
|
14
|
+
"x-nrg-node-type"?: string;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
type ResolveNodeRefs<T> =
|
|
@@ -37,9 +37,17 @@ interface TTypedInput extends TSchema {
|
|
|
37
37
|
};
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
+
interface NrgFormOptions {
|
|
41
|
+
icon?: string;
|
|
42
|
+
typedInputTypes?: string[];
|
|
43
|
+
editorLanguage?: string;
|
|
44
|
+
}
|
|
45
|
+
|
|
40
46
|
declare module "@sinclair/typebox" {
|
|
41
47
|
interface SchemaOptions {
|
|
42
48
|
exportable?: boolean;
|
|
49
|
+
"x-nrg-node-type"?: string;
|
|
50
|
+
"x-nrg-form"?: NrgFormOptions;
|
|
43
51
|
}
|
|
44
52
|
}
|
|
45
53
|
|
package/src/core/server/utils.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { TObject, SchemaOptions } from "@sinclair/typebox";
|
|
2
2
|
|
|
3
3
|
interface NodeSchemaOptions extends SchemaOptions {
|
|
4
|
-
"node-type"?: string;
|
|
4
|
+
"x-nrg-node-type"?: string;
|
|
5
5
|
default?: any;
|
|
6
6
|
format?: string;
|
|
7
7
|
}
|
|
@@ -25,7 +25,7 @@ function getDefaultsFromSchema(
|
|
|
25
25
|
required: false,
|
|
26
26
|
value: property.default ?? undefined,
|
|
27
27
|
// NOTE: I'm using a custom json schema keyword to determine the node type
|
|
28
|
-
type: property["node-type"],
|
|
28
|
+
type: property["x-nrg-node-type"],
|
|
29
29
|
};
|
|
30
30
|
}
|
|
31
31
|
|
|
@@ -5,9 +5,13 @@ class NodeRedValidator extends Validator {
|
|
|
5
5
|
constructor(RED: RED) {
|
|
6
6
|
super({
|
|
7
7
|
customKeywords: [
|
|
8
|
-
{ keyword: "skip-validation", schemaType: "boolean", valid: true },
|
|
9
8
|
{
|
|
10
|
-
keyword: "
|
|
9
|
+
keyword: "x-nrg-skip-validation",
|
|
10
|
+
schemaType: "boolean",
|
|
11
|
+
valid: true,
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
keyword: "x-nrg-node-type",
|
|
11
15
|
type: "string",
|
|
12
16
|
validate: (schemaValue: string, dataValue: string) => {
|
|
13
17
|
if (!dataValue) return true;
|
package/src/vite/client/build.ts
CHANGED
|
@@ -39,13 +39,15 @@ async function build(
|
|
|
39
39
|
if (fs.existsSync(physicalEntryPath)) {
|
|
40
40
|
entryPath = physicalEntryPath;
|
|
41
41
|
} else {
|
|
42
|
-
// No physical entry — create a minimal empty file
|
|
43
|
-
//
|
|
44
|
-
|
|
45
|
-
|
|
42
|
+
// No physical entry — create a minimal empty file in the cache directory
|
|
43
|
+
// so the file watcher on srcDir is not triggered by the create/delete cycle.
|
|
44
|
+
const cacheDir = path.resolve("node_modules", ".nrg", "client");
|
|
45
|
+
const cachedEntryPath = path.resolve(cacheDir, entry);
|
|
46
|
+
if (!fs.existsSync(cacheDir)) {
|
|
47
|
+
fs.mkdirSync(cacheDir, { recursive: true });
|
|
46
48
|
}
|
|
47
|
-
fs.writeFileSync(
|
|
48
|
-
entryPath =
|
|
49
|
+
fs.writeFileSync(cachedEntryPath, "// auto-generated entry\n");
|
|
50
|
+
entryPath = cachedEntryPath;
|
|
49
51
|
generatedEntry = true;
|
|
50
52
|
}
|
|
51
53
|
|
|
@@ -215,7 +217,7 @@ async function build(
|
|
|
215
217
|
throw new BuildError("client", error as Error);
|
|
216
218
|
} finally {
|
|
217
219
|
if (generatedEntry) {
|
|
218
|
-
fs.unlinkSync(
|
|
220
|
+
fs.unlinkSync(entryPath);
|
|
219
221
|
}
|
|
220
222
|
}
|
|
221
223
|
}
|