@bonsae/nrg-runtime 0.25.0 → 0.26.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/package.json +3 -23
- package/server/index.cjs +52 -42
- package/server/resources/nrg-client.js +6 -6
- package/internal/README.md +0 -30
- package/internal/client/components.mjs +0 -1287
- package/internal/client/index.mjs +0 -229
- package/internal/server/index.cjs +0 -298
- package/types/client.d.ts +0 -266
- package/types/internal/client/components.d.ts +0 -9
- package/types/internal/client/index.d.ts +0 -9
- package/types/internal/server/index.d.ts +0 -422
- package/types/server.d.ts +0 -941
- package/types/shims/brands.d.ts +0 -32
- package/types/shims/client/form/components/node-red-config-input.vue.d.ts +0 -125
- package/types/shims/client/form/components/node-red-editor-input.vue.d.ts +0 -124
- package/types/shims/client/form/components/node-red-input-label.vue.d.ts +0 -34
- package/types/shims/client/form/components/node-red-input.vue.d.ts +0 -123
- package/types/shims/client/form/components/node-red-json-schema-form.vue.d.ts +0 -772
- package/types/shims/client/form/components/node-red-select-input.vue.d.ts +0 -132
- package/types/shims/client/form/components/node-red-toggle.vue.d.ts +0 -36
- package/types/shims/client/form/components/node-red-typed-input.vue.d.ts +0 -151
- package/types/shims/client/globals.d.ts +0 -320
- package/types/shims/client/types.d.ts +0 -227
- package/types/shims/components.d.ts +0 -23
- package/types/shims/constants.d.ts +0 -4
- package/types/shims/schema-options.d.ts +0 -24
- package/types/shims/shims-vue.d.ts +0 -5
- package/types/shims/typebox.d.ts +0 -10
|
@@ -1,229 +0,0 @@
|
|
|
1
|
-
// src/client/use-form-node.ts
|
|
2
|
-
import { inject } from "vue";
|
|
3
|
-
function useFormNode() {
|
|
4
|
-
const node = inject("__nrg_form_node");
|
|
5
|
-
const schema = inject("__nrg_form_schema");
|
|
6
|
-
const errors = inject("__nrg_form_errors");
|
|
7
|
-
if (!node) {
|
|
8
|
-
throw new Error(
|
|
9
|
-
"useFormNode() must be called inside a form component mounted by NRG."
|
|
10
|
-
);
|
|
11
|
-
}
|
|
12
|
-
return {
|
|
13
|
-
node,
|
|
14
|
-
schema,
|
|
15
|
-
errors
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
// src/client/validation.ts
|
|
20
|
-
import jsonpointer from "jsonpointer";
|
|
21
|
-
|
|
22
|
-
// src/validator.ts
|
|
23
|
-
import Ajv from "ajv";
|
|
24
|
-
import addFormats from "ajv-formats";
|
|
25
|
-
import addErrors from "ajv-errors";
|
|
26
|
-
var Validator = class {
|
|
27
|
-
ajv;
|
|
28
|
-
constructor(options) {
|
|
29
|
-
const { customKeywords, customFormats, ...ajvOptions } = options || {};
|
|
30
|
-
this.ajv = new Ajv({
|
|
31
|
-
allErrors: true,
|
|
32
|
-
code: {
|
|
33
|
-
source: false
|
|
34
|
-
},
|
|
35
|
-
coerceTypes: true,
|
|
36
|
-
removeAdditional: false,
|
|
37
|
-
strict: false,
|
|
38
|
-
strictSchema: false,
|
|
39
|
-
useDefaults: true,
|
|
40
|
-
validateFormats: true,
|
|
41
|
-
// NOTE: typebox handles validation via typescript
|
|
42
|
-
// NOTE: if true, types that are not serializable JSON, like Function, would not work
|
|
43
|
-
validateSchema: false,
|
|
44
|
-
verbose: true,
|
|
45
|
-
...ajvOptions
|
|
46
|
-
});
|
|
47
|
-
addFormats(this.ajv);
|
|
48
|
-
addErrors(this.ajv);
|
|
49
|
-
this.addCustomKeywords(customKeywords || []);
|
|
50
|
-
this.addCustomFormats(customFormats || {});
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Add custom keywords to the validator
|
|
54
|
-
*/
|
|
55
|
-
addCustomKeywords(keywords) {
|
|
56
|
-
if (!keywords) return;
|
|
57
|
-
keywords.forEach((keyword) => {
|
|
58
|
-
this.ajv.addKeyword(keyword);
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Add custom formats to the validator
|
|
63
|
-
*/
|
|
64
|
-
addCustomFormats(formats) {
|
|
65
|
-
if (!formats) return;
|
|
66
|
-
Object.entries(formats).forEach(([name, validator2]) => {
|
|
67
|
-
if (validator2 instanceof RegExp) {
|
|
68
|
-
this.ajv.addFormat(name, validator2);
|
|
69
|
-
} else {
|
|
70
|
-
this.ajv.addFormat(name, { validate: validator2 });
|
|
71
|
-
}
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* Create a validator function with caching
|
|
76
|
-
* @param schema - JSON Schema to validate against
|
|
77
|
-
* @param cacheKey - Optional cache key for reusing validators
|
|
78
|
-
*/
|
|
79
|
-
createValidator(schema, cacheKey) {
|
|
80
|
-
if (cacheKey && !schema.$id) {
|
|
81
|
-
schema.$id = cacheKey;
|
|
82
|
-
}
|
|
83
|
-
if (schema.$id) {
|
|
84
|
-
const cached = this.ajv.getSchema(schema.$id);
|
|
85
|
-
if (cached) return cached;
|
|
86
|
-
}
|
|
87
|
-
const validator2 = this.ajv.compile(schema);
|
|
88
|
-
return validator2;
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* Validate data against a schema and return a structured result
|
|
92
|
-
*/
|
|
93
|
-
validate(data, schema, options) {
|
|
94
|
-
const validator2 = this.createValidator(schema, options?.cacheKey);
|
|
95
|
-
const valid = validator2(data);
|
|
96
|
-
if (!valid) {
|
|
97
|
-
const errorMessage = this.formatErrors(validator2.errors);
|
|
98
|
-
if (options?.throwOnError) {
|
|
99
|
-
throw new ValidationError(errorMessage, validator2.errors || []);
|
|
100
|
-
}
|
|
101
|
-
return {
|
|
102
|
-
valid: false,
|
|
103
|
-
errors: validator2.errors || void 0,
|
|
104
|
-
errorMessage
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
return {
|
|
108
|
-
valid: true,
|
|
109
|
-
data
|
|
110
|
-
};
|
|
111
|
-
}
|
|
112
|
-
/**
|
|
113
|
-
* Format errors into a human-readable string
|
|
114
|
-
*/
|
|
115
|
-
formatErrors(errors, options) {
|
|
116
|
-
if (!errors || errors.length === 0) {
|
|
117
|
-
return "No errors";
|
|
118
|
-
}
|
|
119
|
-
return this.ajv.errorsText(errors, {
|
|
120
|
-
separator: "; ",
|
|
121
|
-
dataVar: "data",
|
|
122
|
-
...options
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
/**
|
|
126
|
-
* Get detailed error information
|
|
127
|
-
*/
|
|
128
|
-
getDetailedErrors(errors) {
|
|
129
|
-
if (!errors || errors.length === 0) return [];
|
|
130
|
-
return errors.map((error) => ({
|
|
131
|
-
field: error.instancePath || "/",
|
|
132
|
-
message: error.message || "Validation failed",
|
|
133
|
-
keyword: error.keyword,
|
|
134
|
-
params: error.params,
|
|
135
|
-
schemaPath: error.schemaPath
|
|
136
|
-
}));
|
|
137
|
-
}
|
|
138
|
-
/**
|
|
139
|
-
* Add a schema to the validator for reference
|
|
140
|
-
*/
|
|
141
|
-
addSchema(schema, key) {
|
|
142
|
-
this.ajv.addSchema(schema, key);
|
|
143
|
-
return this;
|
|
144
|
-
}
|
|
145
|
-
/**
|
|
146
|
-
* Remove a schema from the validator
|
|
147
|
-
*/
|
|
148
|
-
removeSchema(key) {
|
|
149
|
-
this.ajv.removeSchema(key);
|
|
150
|
-
return this;
|
|
151
|
-
}
|
|
152
|
-
};
|
|
153
|
-
var ValidationError = class _ValidationError extends Error {
|
|
154
|
-
constructor(message, errors) {
|
|
155
|
-
super(message);
|
|
156
|
-
this.errors = errors;
|
|
157
|
-
this.name = "ValidationError";
|
|
158
|
-
Object.setPrototypeOf(this, _ValidationError.prototype);
|
|
159
|
-
}
|
|
160
|
-
};
|
|
161
|
-
|
|
162
|
-
// src/client/validation.ts
|
|
163
|
-
var validator = new Validator({
|
|
164
|
-
customKeywords: [
|
|
165
|
-
{
|
|
166
|
-
keyword: "x-nrg-skip-validation",
|
|
167
|
-
schemaType: "boolean",
|
|
168
|
-
valid: true
|
|
169
|
-
},
|
|
170
|
-
{
|
|
171
|
-
keyword: "x-nrg-node-type",
|
|
172
|
-
type: "string",
|
|
173
|
-
validate: (schemaValue, dataValue) => {
|
|
174
|
-
if (!dataValue) return true;
|
|
175
|
-
const node = RED.nodes.node(dataValue);
|
|
176
|
-
return !!node && node.type === schemaValue;
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
],
|
|
180
|
-
customFormats: {
|
|
181
|
-
"node-id": /^[a-zA-Z0-9-_]+$/,
|
|
182
|
-
"flow-id": /^[a-f0-9]{16}$/,
|
|
183
|
-
"topic-path": (data) => /^[a-zA-Z0-9/_-]+$/.test(data)
|
|
184
|
-
}
|
|
185
|
-
});
|
|
186
|
-
function composeValidationSchema(configSchema, credentialsSchema) {
|
|
187
|
-
if (configSchema && credentialsSchema?.properties) {
|
|
188
|
-
return {
|
|
189
|
-
...configSchema,
|
|
190
|
-
properties: {
|
|
191
|
-
...configSchema.properties,
|
|
192
|
-
credentials: {
|
|
193
|
-
type: "object",
|
|
194
|
-
properties: credentialsSchema.properties
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
};
|
|
198
|
-
}
|
|
199
|
-
return configSchema;
|
|
200
|
-
}
|
|
201
|
-
function runValidation(subject, schema) {
|
|
202
|
-
const result = validator.validate(subject, schema, {
|
|
203
|
-
cacheKey: `node-schema-${subject.type}`
|
|
204
|
-
});
|
|
205
|
-
return result.valid ? [] : result.errors ?? [];
|
|
206
|
-
}
|
|
207
|
-
function validateForm(subject, schema) {
|
|
208
|
-
return runValidation(subject, schema).filter((e) => {
|
|
209
|
-
if (e.parentSchema?.format !== "password") return true;
|
|
210
|
-
const v = jsonpointer.get(subject, e.instancePath);
|
|
211
|
-
return v !== "__PWD__";
|
|
212
|
-
}).reduce(
|
|
213
|
-
(acc, error) => {
|
|
214
|
-
let path = error.instancePath;
|
|
215
|
-
if (error.keyword === "required" && error.params?.missingProperty) {
|
|
216
|
-
path = `${path}/${error.params.missingProperty}`;
|
|
217
|
-
}
|
|
218
|
-
const key = `node${path.replaceAll("/", ".")}`;
|
|
219
|
-
acc[key] = error.message ?? "Invalid";
|
|
220
|
-
return acc;
|
|
221
|
-
},
|
|
222
|
-
{}
|
|
223
|
-
);
|
|
224
|
-
}
|
|
225
|
-
export {
|
|
226
|
-
composeValidationSchema,
|
|
227
|
-
useFormNode,
|
|
228
|
-
validateForm
|
|
229
|
-
};
|
|
@@ -1,298 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
|
|
30
|
-
// src/internal/server/index.ts
|
|
31
|
-
var index_exports = {};
|
|
32
|
-
__export(index_exports, {
|
|
33
|
-
WIRE_HANDLERS: () => WIRE_HANDLERS,
|
|
34
|
-
initValidator: () => initValidator,
|
|
35
|
-
setupContext: () => setupContext
|
|
36
|
-
});
|
|
37
|
-
module.exports = __toCommonJS(index_exports);
|
|
38
|
-
|
|
39
|
-
// src/server/nodes/symbols.ts
|
|
40
|
-
var WIRE_HANDLERS = Symbol.for("nrg.wireHandlers");
|
|
41
|
-
|
|
42
|
-
// src/server/nodes/context.ts
|
|
43
|
-
var updateLocks = /* @__PURE__ */ new WeakMap();
|
|
44
|
-
function setupContext(context, store) {
|
|
45
|
-
const get = (key) => new Promise(
|
|
46
|
-
(resolve, reject) => context.get(
|
|
47
|
-
key,
|
|
48
|
-
store,
|
|
49
|
-
(error, value) => error ? reject(error) : resolve(value)
|
|
50
|
-
)
|
|
51
|
-
);
|
|
52
|
-
const set = (key, value) => new Promise(
|
|
53
|
-
(resolve, reject) => context.set(
|
|
54
|
-
key,
|
|
55
|
-
value,
|
|
56
|
-
store,
|
|
57
|
-
(error) => error ? reject(error) : resolve()
|
|
58
|
-
)
|
|
59
|
-
);
|
|
60
|
-
const keys = () => new Promise(
|
|
61
|
-
(resolve, reject) => context.keys(store, (error, k) => error ? reject(error) : resolve(k))
|
|
62
|
-
);
|
|
63
|
-
const nativeUpdate = context.update;
|
|
64
|
-
const nativeIncrement = context.increment;
|
|
65
|
-
const update = (key, fn) => {
|
|
66
|
-
if (nativeUpdate) {
|
|
67
|
-
return new Promise(
|
|
68
|
-
(resolve, reject) => nativeUpdate(
|
|
69
|
-
key,
|
|
70
|
-
fn,
|
|
71
|
-
store,
|
|
72
|
-
(error, value) => error ? reject(error) : resolve(value)
|
|
73
|
-
)
|
|
74
|
-
);
|
|
75
|
-
}
|
|
76
|
-
let chains = updateLocks.get(context);
|
|
77
|
-
if (!chains) updateLocks.set(context, chains = /* @__PURE__ */ new Map());
|
|
78
|
-
const lockKey = JSON.stringify([store ?? null, key]);
|
|
79
|
-
const task = async () => {
|
|
80
|
-
const next = await fn(await get(key));
|
|
81
|
-
await set(key, next);
|
|
82
|
-
return next;
|
|
83
|
-
};
|
|
84
|
-
const run = (chains.get(lockKey) ?? Promise.resolve()).then(task, task);
|
|
85
|
-
chains.set(
|
|
86
|
-
lockKey,
|
|
87
|
-
run.then(
|
|
88
|
-
() => void 0,
|
|
89
|
-
() => void 0
|
|
90
|
-
)
|
|
91
|
-
);
|
|
92
|
-
return run;
|
|
93
|
-
};
|
|
94
|
-
const increment = (key, by = 1) => {
|
|
95
|
-
if (nativeIncrement) {
|
|
96
|
-
return new Promise(
|
|
97
|
-
(resolve, reject) => nativeIncrement(
|
|
98
|
-
key,
|
|
99
|
-
by,
|
|
100
|
-
store,
|
|
101
|
-
(error, value) => error ? reject(error) : resolve(value)
|
|
102
|
-
)
|
|
103
|
-
);
|
|
104
|
-
}
|
|
105
|
-
return update(
|
|
106
|
-
key,
|
|
107
|
-
(current) => typeof current === "number" ? current + by : by
|
|
108
|
-
);
|
|
109
|
-
};
|
|
110
|
-
return { get, set, keys, update, increment };
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
// src/validator.ts
|
|
114
|
-
var import_ajv = __toESM(require("ajv"));
|
|
115
|
-
var import_ajv_formats = __toESM(require("ajv-formats"));
|
|
116
|
-
var import_ajv_errors = __toESM(require("ajv-errors"));
|
|
117
|
-
var Validator = class {
|
|
118
|
-
ajv;
|
|
119
|
-
constructor(options) {
|
|
120
|
-
const { customKeywords, customFormats, ...ajvOptions } = options || {};
|
|
121
|
-
this.ajv = new import_ajv.default({
|
|
122
|
-
allErrors: true,
|
|
123
|
-
code: {
|
|
124
|
-
source: false
|
|
125
|
-
},
|
|
126
|
-
coerceTypes: true,
|
|
127
|
-
removeAdditional: false,
|
|
128
|
-
strict: false,
|
|
129
|
-
strictSchema: false,
|
|
130
|
-
useDefaults: true,
|
|
131
|
-
validateFormats: true,
|
|
132
|
-
// NOTE: typebox handles validation via typescript
|
|
133
|
-
// NOTE: if true, types that are not serializable JSON, like Function, would not work
|
|
134
|
-
validateSchema: false,
|
|
135
|
-
verbose: true,
|
|
136
|
-
...ajvOptions
|
|
137
|
-
});
|
|
138
|
-
(0, import_ajv_formats.default)(this.ajv);
|
|
139
|
-
(0, import_ajv_errors.default)(this.ajv);
|
|
140
|
-
this.addCustomKeywords(customKeywords || []);
|
|
141
|
-
this.addCustomFormats(customFormats || {});
|
|
142
|
-
}
|
|
143
|
-
/**
|
|
144
|
-
* Add custom keywords to the validator
|
|
145
|
-
*/
|
|
146
|
-
addCustomKeywords(keywords) {
|
|
147
|
-
if (!keywords) return;
|
|
148
|
-
keywords.forEach((keyword) => {
|
|
149
|
-
this.ajv.addKeyword(keyword);
|
|
150
|
-
});
|
|
151
|
-
}
|
|
152
|
-
/**
|
|
153
|
-
* Add custom formats to the validator
|
|
154
|
-
*/
|
|
155
|
-
addCustomFormats(formats) {
|
|
156
|
-
if (!formats) return;
|
|
157
|
-
Object.entries(formats).forEach(([name, validator]) => {
|
|
158
|
-
if (validator instanceof RegExp) {
|
|
159
|
-
this.ajv.addFormat(name, validator);
|
|
160
|
-
} else {
|
|
161
|
-
this.ajv.addFormat(name, { validate: validator });
|
|
162
|
-
}
|
|
163
|
-
});
|
|
164
|
-
}
|
|
165
|
-
/**
|
|
166
|
-
* Create a validator function with caching
|
|
167
|
-
* @param schema - JSON Schema to validate against
|
|
168
|
-
* @param cacheKey - Optional cache key for reusing validators
|
|
169
|
-
*/
|
|
170
|
-
createValidator(schema, cacheKey) {
|
|
171
|
-
if (cacheKey && !schema.$id) {
|
|
172
|
-
schema.$id = cacheKey;
|
|
173
|
-
}
|
|
174
|
-
if (schema.$id) {
|
|
175
|
-
const cached = this.ajv.getSchema(schema.$id);
|
|
176
|
-
if (cached) return cached;
|
|
177
|
-
}
|
|
178
|
-
const validator = this.ajv.compile(schema);
|
|
179
|
-
return validator;
|
|
180
|
-
}
|
|
181
|
-
/**
|
|
182
|
-
* Validate data against a schema and return a structured result
|
|
183
|
-
*/
|
|
184
|
-
validate(data, schema, options) {
|
|
185
|
-
const validator = this.createValidator(schema, options?.cacheKey);
|
|
186
|
-
const valid = validator(data);
|
|
187
|
-
if (!valid) {
|
|
188
|
-
const errorMessage = this.formatErrors(validator.errors);
|
|
189
|
-
if (options?.throwOnError) {
|
|
190
|
-
throw new ValidationError(errorMessage, validator.errors || []);
|
|
191
|
-
}
|
|
192
|
-
return {
|
|
193
|
-
valid: false,
|
|
194
|
-
errors: validator.errors || void 0,
|
|
195
|
-
errorMessage
|
|
196
|
-
};
|
|
197
|
-
}
|
|
198
|
-
return {
|
|
199
|
-
valid: true,
|
|
200
|
-
data
|
|
201
|
-
};
|
|
202
|
-
}
|
|
203
|
-
/**
|
|
204
|
-
* Format errors into a human-readable string
|
|
205
|
-
*/
|
|
206
|
-
formatErrors(errors, options) {
|
|
207
|
-
if (!errors || errors.length === 0) {
|
|
208
|
-
return "No errors";
|
|
209
|
-
}
|
|
210
|
-
return this.ajv.errorsText(errors, {
|
|
211
|
-
separator: "; ",
|
|
212
|
-
dataVar: "data",
|
|
213
|
-
...options
|
|
214
|
-
});
|
|
215
|
-
}
|
|
216
|
-
/**
|
|
217
|
-
* Get detailed error information
|
|
218
|
-
*/
|
|
219
|
-
getDetailedErrors(errors) {
|
|
220
|
-
if (!errors || errors.length === 0) return [];
|
|
221
|
-
return errors.map((error) => ({
|
|
222
|
-
field: error.instancePath || "/",
|
|
223
|
-
message: error.message || "Validation failed",
|
|
224
|
-
keyword: error.keyword,
|
|
225
|
-
params: error.params,
|
|
226
|
-
schemaPath: error.schemaPath
|
|
227
|
-
}));
|
|
228
|
-
}
|
|
229
|
-
/**
|
|
230
|
-
* Add a schema to the validator for reference
|
|
231
|
-
*/
|
|
232
|
-
addSchema(schema, key) {
|
|
233
|
-
this.ajv.addSchema(schema, key);
|
|
234
|
-
return this;
|
|
235
|
-
}
|
|
236
|
-
/**
|
|
237
|
-
* Remove a schema from the validator
|
|
238
|
-
*/
|
|
239
|
-
removeSchema(key) {
|
|
240
|
-
this.ajv.removeSchema(key);
|
|
241
|
-
return this;
|
|
242
|
-
}
|
|
243
|
-
};
|
|
244
|
-
var ValidationError = class _ValidationError extends Error {
|
|
245
|
-
constructor(message, errors) {
|
|
246
|
-
super(message);
|
|
247
|
-
this.errors = errors;
|
|
248
|
-
this.name = "ValidationError";
|
|
249
|
-
Object.setPrototypeOf(this, _ValidationError.prototype);
|
|
250
|
-
}
|
|
251
|
-
};
|
|
252
|
-
|
|
253
|
-
// src/server/validation.ts
|
|
254
|
-
function initValidator(RED) {
|
|
255
|
-
if (RED.validator) return;
|
|
256
|
-
const nrg = {
|
|
257
|
-
validator: new Validator({
|
|
258
|
-
customKeywords: [
|
|
259
|
-
{
|
|
260
|
-
keyword: "x-nrg-skip-validation",
|
|
261
|
-
schemaType: "boolean",
|
|
262
|
-
valid: true
|
|
263
|
-
},
|
|
264
|
-
{
|
|
265
|
-
keyword: "x-nrg-node-type",
|
|
266
|
-
type: "string",
|
|
267
|
-
validate: (schemaValue, dataValue) => {
|
|
268
|
-
if (!dataValue) return true;
|
|
269
|
-
const node = RED.nodes.getNode(dataValue);
|
|
270
|
-
return node?.type === schemaValue;
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
],
|
|
274
|
-
customFormats: {
|
|
275
|
-
"node-id": /^[a-zA-Z0-9-_]+$/,
|
|
276
|
-
"flow-id": /^[a-f0-9]{16}$/,
|
|
277
|
-
"topic-path": (data) => /^[a-zA-Z0-9/_-]+$/.test(data)
|
|
278
|
-
}
|
|
279
|
-
})
|
|
280
|
-
};
|
|
281
|
-
Object.defineProperty(RED, "_nrg", {
|
|
282
|
-
value: nrg,
|
|
283
|
-
writable: false,
|
|
284
|
-
enumerable: false,
|
|
285
|
-
configurable: false
|
|
286
|
-
});
|
|
287
|
-
Object.defineProperty(RED, "validator", {
|
|
288
|
-
get: () => nrg.validator,
|
|
289
|
-
enumerable: false,
|
|
290
|
-
configurable: false
|
|
291
|
-
});
|
|
292
|
-
}
|
|
293
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
294
|
-
0 && (module.exports = {
|
|
295
|
-
WIRE_HANDLERS,
|
|
296
|
-
initValidator,
|
|
297
|
-
setupContext
|
|
298
|
-
});
|