@bonsae/nrg 0.26.3 → 0.27.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.
@@ -1,16 +1,16 @@
1
- var j = Object.defineProperty;
2
- var $ = (t, e, r) => e in t ? j(t, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : t[e] = r;
3
- var v = (t, e, r) => $(t, typeof e != "symbol" ? e + "" : e, r);
4
- import { inject as F, vi as y } from "vitest";
5
- import { inject as l, reactive as _, watch as S } from "vue";
6
- import b from "jsonpointer";
1
+ var w = Object.defineProperty;
2
+ var $ = (r, e, t) => e in r ? w(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t;
3
+ var v = (r, e, t) => $(r, typeof e != "symbol" ? e + "" : e, t);
4
+ import { inject as b, vi as y } from "vitest";
5
+ import { inject as l, reactive as _, watch as F } from "vue";
6
+ import P from "jsonpointer";
7
7
  import k from "ajv";
8
8
  import O from "ajv-formats";
9
- import P from "ajv-errors";
10
- class N {
9
+ import N from "ajv-errors";
10
+ class S {
11
11
  constructor(e) {
12
12
  v(this, "ajv");
13
- const { customKeywords: r, customFormats: o, ...a } = e || {};
13
+ const { customKeywords: t, customFormats: o, ...n } = e || {};
14
14
  this.ajv = new k({
15
15
  allErrors: !0,
16
16
  code: {
@@ -26,23 +26,23 @@ class N {
26
26
  // NOTE: if true, types that are not serializable JSON, like Function, would not work
27
27
  validateSchema: !1,
28
28
  verbose: !0,
29
- ...a
30
- }), O(this.ajv), P(this.ajv), this.addCustomKeywords(r || []), this.addCustomFormats(o || {});
29
+ ...n
30
+ }), O(this.ajv), N(this.ajv), this.addCustomKeywords(t || []), this.addCustomFormats(o || {});
31
31
  }
32
32
  /**
33
33
  * Add custom keywords to the validator
34
34
  */
35
35
  addCustomKeywords(e) {
36
- e && e.forEach((r) => {
37
- this.ajv.addKeyword(r);
36
+ e && e.forEach((t) => {
37
+ this.ajv.addKeyword(t);
38
38
  });
39
39
  }
40
40
  /**
41
41
  * Add custom formats to the validator
42
42
  */
43
43
  addCustomFormats(e) {
44
- e && Object.entries(e).forEach(([r, o]) => {
45
- o instanceof RegExp ? this.ajv.addFormat(r, o) : this.ajv.addFormat(r, { validate: o });
44
+ e && Object.entries(e).forEach(([t, o]) => {
45
+ o instanceof RegExp ? this.ajv.addFormat(t, o) : this.ajv.addFormat(t, { validate: o });
46
46
  });
47
47
  }
48
48
  /**
@@ -50,25 +50,25 @@ class N {
50
50
  * @param schema - JSON Schema to validate against
51
51
  * @param cacheKey - Optional cache key for reusing validators
52
52
  */
53
- createValidator(e, r) {
54
- if (r && !e.$id && (e.$id = r), e.$id) {
55
- const a = this.ajv.getSchema(e.$id);
56
- if (a) return a;
53
+ createValidator(e, t) {
54
+ if (t && !e.$id && (e.$id = t), e.$id) {
55
+ const n = this.ajv.getSchema(e.$id);
56
+ if (n) return n;
57
57
  }
58
58
  return this.ajv.compile(e);
59
59
  }
60
60
  /**
61
61
  * Validate data against a schema and return a structured result
62
62
  */
63
- validate(e, r, o) {
64
- const a = this.createValidator(r, o == null ? void 0 : o.cacheKey);
65
- if (!a(e)) {
66
- const i = this.formatErrors(a.errors);
63
+ validate(e, t, o) {
64
+ const n = this.createValidator(t, o == null ? void 0 : o.cacheKey);
65
+ if (!n(e)) {
66
+ const i = this.formatErrors(n.errors);
67
67
  if (o != null && o.throwOnError)
68
- throw new h(i, a.errors || []);
68
+ throw new p(i, n.errors || []);
69
69
  return {
70
70
  valid: !1,
71
- errors: a.errors || void 0,
71
+ errors: n.errors || void 0,
72
72
  errorMessage: i
73
73
  };
74
74
  }
@@ -80,30 +80,30 @@ class N {
80
80
  /**
81
81
  * Format errors into a human-readable string
82
82
  */
83
- formatErrors(e, r) {
83
+ formatErrors(e, t) {
84
84
  return !e || e.length === 0 ? "No errors" : this.ajv.errorsText(e, {
85
85
  separator: "; ",
86
86
  dataVar: "data",
87
- ...r
87
+ ...t
88
88
  });
89
89
  }
90
90
  /**
91
91
  * Get detailed error information
92
92
  */
93
93
  getDetailedErrors(e) {
94
- return !e || e.length === 0 ? [] : e.map((r) => ({
95
- field: r.instancePath || "/",
96
- message: r.message || "Validation failed",
97
- keyword: r.keyword,
98
- params: r.params,
99
- schemaPath: r.schemaPath
94
+ return !e || e.length === 0 ? [] : e.map((t) => ({
95
+ field: t.instancePath || "/",
96
+ message: t.message || "Validation failed",
97
+ keyword: t.keyword,
98
+ params: t.params,
99
+ schemaPath: t.schemaPath
100
100
  }));
101
101
  }
102
102
  /**
103
103
  * Add a schema to the validator for reference
104
104
  */
105
- addSchema(e, r) {
106
- return this.ajv.addSchema(e, r), this;
105
+ addSchema(e, t) {
106
+ return this.ajv.addSchema(e, t), this;
107
107
  }
108
108
  /**
109
109
  * Remove a schema from the validator
@@ -112,12 +112,12 @@ class N {
112
112
  return this.ajv.removeSchema(e), this;
113
113
  }
114
114
  }
115
- class h extends Error {
116
- constructor(e, r) {
117
- super(e), this.errors = r, this.name = "ValidationError", Object.setPrototypeOf(this, h.prototype);
115
+ class p extends Error {
116
+ constructor(e, t) {
117
+ super(e), this.errors = t, this.name = "ValidationError", Object.setPrototypeOf(this, p.prototype);
118
118
  }
119
119
  }
120
- const V = new N({
120
+ const V = new S({
121
121
  customKeywords: [
122
122
  {
123
123
  keyword: "x-nrg-skip-validation",
@@ -127,118 +127,126 @@ const V = new N({
127
127
  {
128
128
  keyword: "x-nrg-node-type",
129
129
  type: "string",
130
- validate: (t, e) => {
130
+ validate: (r, e) => {
131
131
  if (!e) return !0;
132
- const r = RED.nodes.node(e);
133
- return !!r && r.type === t;
132
+ const t = RED.nodes.node(e);
133
+ return !!t && t.type === r;
134
134
  }
135
135
  }
136
136
  ],
137
137
  customFormats: {
138
- "node-id": /^[a-zA-Z0-9-_]+$/,
139
- "flow-id": /^[a-f0-9]{16}$/,
140
- "topic-path": (t) => /^[a-zA-Z0-9/_-]+$/.test(t)
138
+ "node-id": /^[a-zA-Z0-9-_]+$/
141
139
  }
142
140
  });
143
- function x(t, e) {
144
- return t && (e != null && e.properties) ? {
145
- ...t,
141
+ function x(r, e) {
142
+ const t = e == null ? void 0 : e.properties;
143
+ if (!t) return r;
144
+ const o = {
145
+ type: "object",
146
+ properties: t,
147
+ // Propagate `required` so required credentials are actually enforced
148
+ // (previously they never were, even alongside a config schema).
149
+ ...e != null && e.required ? { required: e.required } : {}
150
+ };
151
+ return r ? {
152
+ ...r,
146
153
  properties: {
147
- ...t.properties,
148
- credentials: {
149
- type: "object",
150
- properties: e.properties
151
- }
154
+ ...r.properties,
155
+ credentials: o
152
156
  }
153
- } : t;
157
+ } : {
158
+ type: "object",
159
+ properties: { credentials: o },
160
+ additionalProperties: !0
161
+ };
154
162
  }
155
- function K(t, e) {
156
- const r = V.validate(t, e, {
157
- cacheKey: `node-schema-${t.type}`
163
+ function K(r, e) {
164
+ const t = V.validate(r, e, {
165
+ cacheKey: `node-schema-${r.type}`
158
166
  });
159
- return r.valid ? [] : r.errors ?? [];
167
+ return t.valid ? [] : t.errors ?? [];
160
168
  }
161
- function g(t, e) {
162
- return K(t, e).filter((r) => {
163
- var a;
164
- return ((a = r.parentSchema) == null ? void 0 : a.format) !== "password" ? !0 : b.get(t, r.instancePath) !== "__PWD__";
169
+ function g(r, e) {
170
+ return K(r, e).filter((t) => {
171
+ var n;
172
+ return ((n = t.parentSchema) == null ? void 0 : n.format) !== "password" ? !0 : P.get(r, t.instancePath) !== "__PWD__";
165
173
  }).reduce(
166
- (r, o) => {
174
+ (t, o) => {
167
175
  var i;
168
- let a = o.instancePath;
169
- o.keyword === "required" && ((i = o.params) != null && i.missingProperty) && (a = `${a}/${o.params.missingProperty}`);
170
- const n = `node${a.replaceAll("/", ".")}`;
171
- return r[n] = o.message ?? "Invalid", r;
176
+ let n = o.instancePath;
177
+ o.keyword === "required" && ((i = o.params) != null && i.missingProperty) && (n = `${n}/${o.params.missingProperty}`);
178
+ const a = `node${n.replaceAll("/", ".")}`;
179
+ return t[a] = o.message ?? "Invalid", t;
172
180
  },
173
181
  {}
174
182
  );
175
183
  }
176
184
  function B() {
177
- const t = l("__nrg_form_node"), e = l("__nrg_form_schema"), r = l("__nrg_form_errors");
178
- if (!t)
185
+ const r = l("__nrg_form_node"), e = l("__nrg_form_schema"), t = l("__nrg_form_errors");
186
+ if (!r)
179
187
  throw new Error(
180
188
  "useFormNode() must be called inside a form component mounted by NRG."
181
189
  );
182
190
  return {
183
- node: t,
191
+ node: r,
184
192
  schema: e,
185
- errors: r
193
+ errors: t
186
194
  };
187
195
  }
188
- let w = 0;
189
- function H(t = {}) {
190
- var p;
191
- const e = "type" in t || "configs" in t || "configSchema" in t || "credentialsSchema" in t || "nodes" in t ? t : { configs: t }, r = e.type ? (p = A()) == null ? void 0 : p[e.type] : void 0, o = e.configSchema ?? (r == null ? void 0 : r.configSchema), a = e.credentialsSchema ?? (r == null ? void 0 : r.credentialsSchema), n = _({
192
- id: `test-${w}`,
196
+ let j = 0;
197
+ function H(r = {}) {
198
+ var h;
199
+ const e = "type" in r || "configs" in r || "configSchema" in r || "credentialsSchema" in r || "nodes" in r ? r : { configs: r }, t = e.type ? (h = C()) == null ? void 0 : h[e.type] : void 0, o = e.configSchema ?? (t == null ? void 0 : t.configSchema), n = e.credentialsSchema ?? (t == null ? void 0 : t.credentialsSchema), a = _({
200
+ id: `test-${j}`,
193
201
  // Unique type per node: validateForm caches compiled schemas by
194
202
  // `node-schema-${subject.type}`, so a shared type would silently reuse
195
203
  // the first schema for every later createNode call in the same file.
196
- type: `test-node-${w++}`,
204
+ type: `test-node-${j++}`,
197
205
  changed: !1,
198
206
  _def: { outputs: 1 },
199
207
  _: (c) => c,
200
208
  ...e.configs,
201
209
  credentials: { ...e.credentials }
202
- }), i = x(o, a);
210
+ }), i = x(o, n);
203
211
  let d;
204
212
  if (i) {
205
- const { $id: c, ...u } = i;
206
- d = u;
213
+ const { $id: c, ...f } = i;
214
+ d = f;
207
215
  }
208
- const f = T();
209
- C(f), f.nodes.clear();
216
+ const m = q();
217
+ T(m), m.nodes.clear();
210
218
  for (const c of e.nodes ?? [])
211
- f.nodes.add(c);
212
- const m = _(
213
- d ? g(n, d) : {}
219
+ m.nodes.add(c);
220
+ const u = _(
221
+ d ? g(a, d) : {}
214
222
  );
215
- return d && S(
216
- n,
223
+ return d && F(
224
+ a,
217
225
  () => {
218
- const c = g(n, d);
219
- Object.keys(m).forEach((u) => delete m[u]), Object.assign(m, c);
226
+ const c = g(a, d);
227
+ Object.keys(u).forEach((f) => delete u[f]), Object.assign(u, c);
220
228
  },
221
229
  { deep: !0 }
222
- ), { node: n, errors: m, RED: f, provide: {
223
- __nrg_form_node: n,
230
+ ), { node: a, errors: u, RED: m, provide: {
231
+ __nrg_form_node: a,
224
232
  __nrg_form_schema: d ?? {},
225
- __nrg_form_errors: m
233
+ __nrg_form_errors: u
226
234
  } };
227
235
  }
228
- function A() {
236
+ function C() {
229
237
  try {
230
- return F("__nrg_schemas");
238
+ return b("__nrg_schemas");
231
239
  } catch {
232
240
  return;
233
241
  }
234
242
  }
235
- function s(t, e) {
236
- y.isMockFunction(t[e]) || y.spyOn(t, e);
243
+ function s(r, e) {
244
+ y.isMockFunction(r[e]) || y.spyOn(r, e);
237
245
  }
238
- function C(t) {
239
- s(t, "_"), s(t, "notify"), s(t.editor, "createEditor"), s(t.editor, "prepareConfigNodeSelect"), s(t.editor, "validateNode"), s(t.tray, "show"), s(t.tray, "close"), s(t.popover, "tooltip"), s(t.popover, "create"), s(t.nodes, "registerType"), s(t.nodes, "node"), s(t.nodes, "add"), s(t.nodes, "remove"), s(t.nodes, "getType"), s(t.nodes, "dirty"), s(t.events, "on"), s(t.events, "off"), s(t.events, "emit"), s(t.comms, "subscribe"), s(t.comms, "unsubscribe");
246
+ function T(r) {
247
+ s(r, "_"), s(r, "notify"), s(r.editor, "createEditor"), s(r.editor, "prepareConfigNodeSelect"), s(r.editor, "validateNode"), s(r.tray, "show"), s(r.tray, "close"), s(r.popover, "tooltip"), s(r.popover, "create"), s(r.nodes, "registerType"), s(r.nodes, "node"), s(r.nodes, "add"), s(r.nodes, "remove"), s(r.nodes, "getType"), s(r.nodes, "dirty"), s(r.events, "on"), s(r.events, "off"), s(r.events, "emit"), s(r.comms, "subscribe"), s(r.comms, "unsubscribe");
240
248
  }
241
- function T() {
249
+ function q() {
242
250
  return window.RED;
243
251
  }
244
252
  export {
@@ -1 +1 @@
1
- .nrg-label[data-v-864b02f2]{display:inline-block;width:100%;margin-bottom:4px;cursor:default}.nrg-label i[data-v-864b02f2]{margin-right:5px}.nrg-required[data-v-864b02f2]{color:var(--red-ui-text-color-error);margin-left:2px}.editor-wrapper[data-v-ea93e881]{position:relative}.expand-button[data-v-ea93e881]{position:absolute;top:-23px;right:0;z-index:10;transition:color .3s ease;cursor:pointer}.nrg-toggle-wrapper[data-v-724dcae4]{display:inline-flex;align-items:center}.nrg-toggle[data-v-724dcae4]{position:relative;display:inline-flex!important;flex-direction:column;align-items:flex-start;cursor:pointer;gap:4px;-webkit-user-select:none;user-select:none}.nrg-toggle__input[data-v-724dcae4]{position:absolute;opacity:0;width:0;height:0}.nrg-toggle__slider[data-v-724dcae4]{position:relative;display:inline-block;width:36px;min-width:36px;height:20px;background-color:var(--red-ui-secondary-border-color, #ccc);border-radius:10px;transition:background-color .2s ease}.nrg-toggle__slider[data-v-724dcae4]:after{content:"";position:absolute;top:2px;left:2px;width:16px;height:16px;background-color:#fff;border-radius:50%;transition:transform .2s ease}.nrg-toggle--checked .nrg-toggle__slider[data-v-724dcae4]{background-color:var(--red-ui-text-color-link, #0070d2)}.nrg-toggle--checked .nrg-toggle__slider[data-v-724dcae4]:after{transform:translate(16px)}.nrg-toggle__label[data-v-724dcae4]{cursor:default;white-space:nowrap}.nrg-toggle__label i[data-v-724dcae4]{margin-right:2px}
1
+ .nrg-label[data-v-864b02f2]{display:inline-block;width:100%;margin-bottom:4px;cursor:default}.nrg-label i[data-v-864b02f2]{margin-right:5px}.nrg-required[data-v-864b02f2]{color:var(--red-ui-text-color-error);margin-left:2px}.editor-wrapper[data-v-ea93e881]{position:relative}.expand-button[data-v-ea93e881]{position:absolute;top:-23px;right:0;z-index:10;transition:color .3s ease;cursor:pointer}.nrg-toggle-wrapper[data-v-4657f355]{display:inline-flex;align-items:center}.nrg-toggle[data-v-4657f355]{position:relative;display:inline-flex!important;flex-direction:column;align-items:flex-start;cursor:pointer;gap:4px;-webkit-user-select:none;user-select:none}.nrg-toggle__input[data-v-4657f355]{position:absolute;opacity:0;width:0;height:0}.nrg-toggle__slider[data-v-4657f355]{position:relative;display:inline-block;width:36px;min-width:36px;height:20px;background-color:var(--red-ui-secondary-border-color, #ccc);border-radius:10px;transition:background-color .2s ease}.nrg-toggle__slider[data-v-4657f355]:after{content:"";position:absolute;top:2px;left:2px;width:16px;height:16px;background-color:#fff;border-radius:50%;transition:transform .2s ease}.nrg-toggle--checked .nrg-toggle__slider[data-v-4657f355]{background-color:var(--red-ui-text-color-link, #0070d2)}.nrg-toggle--checked .nrg-toggle__slider[data-v-4657f355]:after{transform:translate(16px)}.nrg-toggle__label[data-v-4657f355]{cursor:default;white-space:nowrap}.nrg-toggle__label i[data-v-4657f355]{margin-right:2px}