@bonsae/nrg 0.6.2 → 0.7.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/README.md CHANGED
@@ -14,10 +14,12 @@ Build Node-RED nodes with Vue 3, TypeScript, and JSON Schema validation.
14
14
  ## Install
15
15
 
16
16
  ```bash
17
- pnpm add @bonsae/nrg vue
18
- pnpm add -D vite
17
+ pnpm add @bonsae/nrg
18
+ pnpm add -D vite vue
19
19
  ```
20
20
 
21
+ > `vite` and `vue` are dev dependencies because they are only needed at build time. The Vue runtime is bundled by nrg and served automatically — your published package does not need them at runtime.
22
+
21
23
  ## Package Exports
22
24
 
23
25
  | Export | Description |
@@ -32,8 +34,8 @@ pnpm add -D vite
32
34
 
33
35
  ```bash
34
36
  # In your Node-RED package project
35
- pnpm add @bonsae/nrg vue
36
- pnpm add -D vite
37
+ pnpm add @bonsae/nrg
38
+ pnpm add -D vite vue
37
39
  ```
38
40
 
39
41
  **vite.config.ts**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bonsae/nrg",
3
- "version": "0.6.2",
3
+ "version": "0.7.0",
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",
package/server/index.cjs CHANGED
@@ -103,11 +103,11 @@ var Validator = class {
103
103
  */
104
104
  addCustomFormats(formats) {
105
105
  if (!formats) return;
106
- Object.entries(formats).forEach(([name, validator3]) => {
107
- if (validator3 instanceof RegExp) {
108
- this.ajv.addFormat(name, validator3);
106
+ Object.entries(formats).forEach(([name, validator2]) => {
107
+ if (validator2 instanceof RegExp) {
108
+ this.ajv.addFormat(name, validator2);
109
109
  } else {
110
- this.ajv.addFormat(name, { validate: validator3 });
110
+ this.ajv.addFormat(name, { validate: validator2 });
111
111
  }
112
112
  });
113
113
  }
@@ -124,23 +124,23 @@ var Validator = class {
124
124
  const cached = this.ajv.getSchema(schema.$id);
125
125
  if (cached) return cached;
126
126
  }
127
- const validator3 = this.ajv.compile(schema);
128
- return validator3;
127
+ const validator2 = this.ajv.compile(schema);
128
+ return validator2;
129
129
  }
130
130
  /**
131
131
  * Validate data against a schema and return a structured result
132
132
  */
133
133
  validate(data, schema, options) {
134
- const validator3 = this.createValidator(schema, options?.cacheKey);
135
- const valid = validator3(data);
134
+ const validator2 = this.createValidator(schema, options?.cacheKey);
135
+ const valid = validator2(data);
136
136
  if (!valid) {
137
- const errorMessage = this.formatErrors(validator3.errors);
137
+ const errorMessage = this.formatErrors(validator2.errors);
138
138
  if (options?.throwOnError) {
139
- throw new ValidationError(errorMessage, validator3.errors || []);
139
+ throw new ValidationError(errorMessage, validator2.errors || []);
140
140
  }
141
141
  return {
142
142
  valid: false,
143
- errors: validator3.errors || void 0,
143
+ errors: validator2.errors || void 0,
144
144
  errorMessage
145
145
  };
146
146
  }
@@ -198,39 +198,33 @@ var ValidationError = class _ValidationError extends Error {
198
198
  Object.setPrototypeOf(this, _ValidationError.prototype);
199
199
  }
200
200
  };
201
- var validator = new Validator();
202
201
 
203
- // src/core/server/validator.ts
204
- var NodeRedValidator = class extends Validator {
205
- constructor(RED) {
206
- super({
207
- customKeywords: [
208
- {
209
- keyword: "x-nrg-skip-validation",
210
- schemaType: "boolean",
211
- valid: true
212
- },
213
- {
214
- keyword: "x-nrg-node-type",
215
- type: "string",
216
- validate: (schemaValue, dataValue) => {
217
- if (!dataValue) return true;
218
- const node = RED.nodes.getNode(dataValue);
219
- return node?.type === schemaValue;
220
- }
202
+ // src/core/server/validation.ts
203
+ var validator = void 0;
204
+ function initValidator(RED) {
205
+ validator = new Validator({
206
+ customKeywords: [
207
+ {
208
+ keyword: "x-nrg-skip-validation",
209
+ schemaType: "boolean",
210
+ valid: true
211
+ },
212
+ {
213
+ keyword: "x-nrg-node-type",
214
+ type: "string",
215
+ validate: (schemaValue, dataValue) => {
216
+ if (!dataValue) return true;
217
+ const node = RED.nodes.getNode(dataValue);
218
+ return node?.type === schemaValue;
221
219
  }
222
- ],
223
- customFormats: {
224
- "node-id": /^[a-zA-Z0-9-_]+$/,
225
- "flow-id": /^[a-f0-9]{16}$/,
226
- "topic-path": (data) => /^[a-zA-Z0-9/_-]+$/.test(data)
227
220
  }
228
- });
229
- }
230
- };
231
- var validator2 = void 0;
232
- function initValidator(RED) {
233
- validator2 = new NodeRedValidator(RED);
221
+ ],
222
+ customFormats: {
223
+ "node-id": /^[a-zA-Z0-9-_]+$/,
224
+ "flow-id": /^[a-f0-9]{16}$/,
225
+ "topic-path": (data) => /^[a-zA-Z0-9/_-]+$/.test(data)
226
+ }
227
+ });
234
228
  }
235
229
 
236
230
  // src/core/errors.ts
@@ -358,7 +352,7 @@ var Node = class {
358
352
  }
359
353
  }
360
354
  }
361
- validator2.validate(settings, this.settingsSchema, {
355
+ validator.validate(settings, this.settingsSchema, {
362
356
  cacheKey: this.settingsSchema.$id || `${this.type}:settings`,
363
357
  throwOnError: true
364
358
  });
@@ -377,7 +371,7 @@ var Node = class {
377
371
  const constructor = this.constructor;
378
372
  if (constructor.configSchema) {
379
373
  this.log("Validating configs");
380
- const configResult = validator2.validate(
374
+ const configResult = validator.validate(
381
375
  config,
382
376
  constructor.configSchema,
383
377
  {
@@ -398,7 +392,7 @@ var Node = class {
398
392
  );
399
393
  if (constructor.credentialsSchema && credentials) {
400
394
  this.log("Validating credentials");
401
- const credResult = validator2.validate(
395
+ const credResult = validator.validate(
402
396
  credentials,
403
397
  constructor.credentialsSchema,
404
398
  {
@@ -545,7 +539,7 @@ var IONode = class extends Node {
545
539
  const shouldValidateInput = this.config.validateInput ?? NodeClass.validateInput;
546
540
  if (shouldValidateInput && NodeClass.inputSchema) {
547
541
  this.log("Validating input");
548
- validator2.validate(msg, NodeClass.inputSchema, {
542
+ validator.validate(msg, NodeClass.inputSchema, {
549
543
  cacheKey: NodeClass.inputSchema.$id || `${NodeClass.type}:input-schema`,
550
544
  throwOnError: true
551
545
  });
@@ -568,7 +562,7 @@ var IONode = class extends Node {
568
562
  const msgs = msg;
569
563
  for (let i = 0; i < schemas.length; i++) {
570
564
  if (msgs[i] == null) continue;
571
- validator2.validate(msgs[i], schemas[i], {
565
+ validator.validate(msgs[i], schemas[i], {
572
566
  cacheKey: schemas[i].$id || `${NodeClass.type}:output-schema:${i}`,
573
567
  throwOnError: true
574
568
  });
@@ -576,13 +570,13 @@ var IONode = class extends Node {
576
570
  } else if (Array.isArray(msg)) {
577
571
  for (let i = 0; i < msg.length; i++) {
578
572
  if (msg[i] == null) continue;
579
- validator2.validate(msg[i], schemas, {
573
+ validator.validate(msg[i], schemas, {
580
574
  cacheKey: schemas.$id || `${NodeClass.type}:output-schema`,
581
575
  throwOnError: true
582
576
  });
583
577
  }
584
578
  } else {
585
- validator2.validate(msg, schemas, {
579
+ validator.validate(msg, schemas, {
586
580
  cacheKey: schemas.$id || `${NodeClass.type}:output-schema`,
587
581
  throwOnError: true
588
582
  });