@deconz-community/ddf-validator 2.15.0 → 2.17.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/dist/ddf-schema.json +1 -1
- package/dist/ddf-validator.cjs +1 -1
- package/dist/ddf-validator.d.ts +6 -6
- package/dist/ddf-validator.mjs +107 -102
- package/package.json +6 -6
package/dist/ddf-validator.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { z as e } from "zod";
|
|
2
|
-
const E = "2.
|
|
2
|
+
const E = "2.17.0", y = {
|
|
3
3
|
"devcap1.schema.json": [
|
|
4
4
|
O,
|
|
5
5
|
_,
|
|
@@ -11,12 +11,12 @@ const E = "2.15.0", y = {
|
|
|
11
11
|
T
|
|
12
12
|
]
|
|
13
13
|
};
|
|
14
|
-
function O(t, a,
|
|
14
|
+
function O(t, a, u) {
|
|
15
15
|
const o = typeof t.manufacturername == "string" && typeof t.modelid == "string";
|
|
16
16
|
if (o)
|
|
17
17
|
return;
|
|
18
|
-
const
|
|
19
|
-
if (
|
|
18
|
+
const d = Array.isArray(t.manufacturername) && Array.isArray(t.modelid);
|
|
19
|
+
if (d && t.manufacturername.length !== t.modelid.length) {
|
|
20
20
|
a.addIssue({
|
|
21
21
|
code: e.ZodIssueCode.invalid_intersection_types,
|
|
22
22
|
message: "When 'manufacturername' and 'modelid' are both arrays they should be the same length",
|
|
@@ -24,38 +24,38 @@ function O(t, a, d) {
|
|
|
24
24
|
});
|
|
25
25
|
return;
|
|
26
26
|
}
|
|
27
|
-
(o ||
|
|
27
|
+
(o || d) === !1 && a.addIssue({
|
|
28
28
|
code: e.ZodIssueCode.invalid_intersection_types,
|
|
29
29
|
message: "Invalid properties 'manufacturername' and 'modelid' should have the same type",
|
|
30
30
|
path: ["manufacturername", "modelid"]
|
|
31
31
|
});
|
|
32
32
|
}
|
|
33
|
-
function _(t, a,
|
|
33
|
+
function _(t, a, u) {
|
|
34
34
|
if (!t.bindings)
|
|
35
35
|
return;
|
|
36
|
-
const o = (
|
|
37
|
-
t.bindings.forEach((
|
|
38
|
-
|
|
39
|
-
|
|
36
|
+
const o = (i) => `0x${(typeof i == "number" ? i : Number.parseInt(i, 16)).toString(16)}`, d = {};
|
|
37
|
+
t.bindings.forEach((i) => {
|
|
38
|
+
i.bind === "unicast" && i.report && i.report.forEach((l) => {
|
|
39
|
+
l.max !== 65535 && (d[`${o(i["src.ep"])}.${o(i.cl)}.${o(l.at)}`] = l.max);
|
|
40
40
|
});
|
|
41
|
-
}), t.subdevices.forEach((
|
|
42
|
-
|
|
43
|
-
var
|
|
44
|
-
if (
|
|
45
|
-
const
|
|
46
|
-
for (let v = 0; v <
|
|
47
|
-
const g = `${
|
|
48
|
-
|
|
41
|
+
}), t.subdevices.forEach((i, l) => {
|
|
42
|
+
i.items.forEach((s, n) => {
|
|
43
|
+
var c;
|
|
44
|
+
if (s["refresh.interval"] && s.read && s.read.fn === "zcl") {
|
|
45
|
+
const b = o(s.read.ep ?? ((c = i.fingerprint) == null ? void 0 : c.endpoint) ?? i.uuid[1]), h = Array.isArray(s.read.at) ? s.read.at : [s.read.at];
|
|
46
|
+
for (let v = 0; v < h.length; v++) {
|
|
47
|
+
const g = `${b}.${o(s.read.cl)}.${o(h[v])}`;
|
|
48
|
+
d[g] !== void 0 && s["refresh.interval"] - 60 < d[g] && a.addIssue({
|
|
49
49
|
code: e.ZodIssueCode.custom,
|
|
50
|
-
message: `The refresh interval (${
|
|
51
|
-
path: ["subdevices",
|
|
50
|
+
message: `The refresh interval (${s["refresh.interval"]} - 60 = ${s["refresh.interval"] - 60}) should be greater than the binding max refresh value (${d[g]}) with a margin of 60 seconds`,
|
|
51
|
+
path: ["subdevices", l, "items", n, "refresh.interval"]
|
|
52
52
|
});
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
55
|
});
|
|
56
56
|
});
|
|
57
57
|
}
|
|
58
|
-
function $(t, a,
|
|
58
|
+
function $(t, a, u) {
|
|
59
59
|
const o = [
|
|
60
60
|
/*
|
|
61
61
|
{
|
|
@@ -146,83 +146,83 @@ function $(t, a, d) {
|
|
|
146
146
|
}
|
|
147
147
|
}
|
|
148
148
|
}
|
|
149
|
-
],
|
|
150
|
-
t.subdevices.forEach((
|
|
151
|
-
const
|
|
152
|
-
o.forEach((
|
|
153
|
-
(Object.keys(
|
|
154
|
-
switch (
|
|
149
|
+
], d = (i, l) => typeof i == "string" ? l(i) : Array.isArray(i) ? i.every((s) => d(s, l)) : "and" in i ? i.and.every((s) => d(s, l)) : "or" in i ? i.or.some((s) => d(s, l)) : !1;
|
|
150
|
+
t.subdevices.forEach((i, l) => {
|
|
151
|
+
const s = i.items.map((n) => n.name);
|
|
152
|
+
o.forEach((n) => {
|
|
153
|
+
(Object.keys(n.if).length === 0 || Object.entries(n.if).some(([c, b]) => {
|
|
154
|
+
switch (c) {
|
|
155
155
|
case "type":
|
|
156
|
-
return
|
|
156
|
+
return d(b, (h) => h === i.type);
|
|
157
157
|
case "item":
|
|
158
|
-
return
|
|
158
|
+
return d(b, (h) => s.includes(h));
|
|
159
159
|
default:
|
|
160
160
|
return !1;
|
|
161
161
|
}
|
|
162
|
-
})) && (
|
|
162
|
+
})) && (d(n.need.item, (c) => s.includes(c)) || a.addIssue({
|
|
163
163
|
code: e.ZodIssueCode.custom,
|
|
164
|
-
message: `The device is missing some items because ${
|
|
165
|
-
path: ["subdevices",
|
|
164
|
+
message: `The device is missing some items because ${n.description}`,
|
|
165
|
+
path: ["subdevices", l, "items"]
|
|
166
166
|
}));
|
|
167
167
|
});
|
|
168
168
|
});
|
|
169
169
|
}
|
|
170
|
-
function w(t, a,
|
|
170
|
+
function w(t, a, u) {
|
|
171
171
|
const o = ["parse", "write"];
|
|
172
|
-
t.subdevices.forEach((
|
|
173
|
-
|
|
174
|
-
o.forEach((
|
|
175
|
-
const
|
|
176
|
-
|
|
172
|
+
t.subdevices.forEach((d, i) => {
|
|
173
|
+
d.items.forEach((l, s) => {
|
|
174
|
+
o.forEach((n) => {
|
|
175
|
+
const c = l[n];
|
|
176
|
+
c !== void 0 && (c.fn === void 0 || c.fn === "zcl" || c.fn === "zcl:attr" || c.fn === "zcl:cmd") && (c.eval === void 0 && c.script === void 0 && a.addIssue({
|
|
177
177
|
code: e.ZodIssueCode.custom,
|
|
178
|
-
message: `The '${
|
|
179
|
-
path: ["subdevices",
|
|
180
|
-
}),
|
|
178
|
+
message: `The '${n}' function is missing 'eval' or 'script' option.`,
|
|
179
|
+
path: ["subdevices", i, "items", s, n]
|
|
180
|
+
}), c.eval !== void 0 && c.script !== void 0 && a.addIssue({
|
|
181
181
|
code: e.ZodIssueCode.custom,
|
|
182
|
-
message: `The '${
|
|
183
|
-
path: ["subdevices",
|
|
182
|
+
message: `The '${n}' function is having both 'eval' and 'script' option.`,
|
|
183
|
+
path: ["subdevices", i, "items", s, n]
|
|
184
184
|
}));
|
|
185
185
|
});
|
|
186
186
|
});
|
|
187
187
|
});
|
|
188
188
|
}
|
|
189
|
-
function T(t, a,
|
|
189
|
+
function T(t, a, u) {
|
|
190
190
|
const o = I();
|
|
191
|
-
Object.keys(t).forEach((
|
|
192
|
-
if (!Object.keys(o.shape).includes(
|
|
193
|
-
if (!["$MF_", "$TYPE_"].some((
|
|
191
|
+
Object.keys(t).forEach((d) => {
|
|
192
|
+
if (!Object.keys(o.shape).includes(d)) {
|
|
193
|
+
if (!["$MF_", "$TYPE_"].some((i) => d.startsWith(i))) {
|
|
194
194
|
a.addIssue({
|
|
195
195
|
code: e.ZodIssueCode.custom,
|
|
196
196
|
message: "The constant key should start with '$MF_' or '$TYPE_'",
|
|
197
|
-
path: [
|
|
197
|
+
path: [d]
|
|
198
198
|
});
|
|
199
199
|
return;
|
|
200
200
|
}
|
|
201
|
-
typeof t[
|
|
201
|
+
typeof t[d] != "string" && a.addIssue({
|
|
202
202
|
code: e.ZodIssueCode.custom,
|
|
203
203
|
message: "The constant value should be a string",
|
|
204
|
-
path: [
|
|
204
|
+
path: [d]
|
|
205
205
|
});
|
|
206
206
|
}
|
|
207
207
|
});
|
|
208
208
|
}
|
|
209
|
-
function C(t, a,
|
|
210
|
-
t.subdevices.forEach((o,
|
|
211
|
-
const
|
|
212
|
-
if (!
|
|
209
|
+
function C(t, a, u) {
|
|
210
|
+
t.subdevices.forEach((o, d) => {
|
|
211
|
+
const i = u.subDevices[o.type];
|
|
212
|
+
if (!i) {
|
|
213
213
|
a.addIssue({
|
|
214
214
|
code: e.ZodIssueCode.custom,
|
|
215
215
|
message: `The device is missing the device definition for the type "${o.type}"`,
|
|
216
|
-
path: ["subdevices",
|
|
216
|
+
path: ["subdevices", d, "items"]
|
|
217
217
|
});
|
|
218
218
|
return;
|
|
219
219
|
}
|
|
220
|
-
let
|
|
221
|
-
|
|
222
|
-
o.items.find((
|
|
220
|
+
let l = i.items;
|
|
221
|
+
i.items_optional && (l = l.filter((s) => !i.items_optional.includes(s))), l.forEach((s) => {
|
|
222
|
+
o.items.find((n) => n.name === s) || a.addIssue({
|
|
223
223
|
code: e.ZodIssueCode.custom,
|
|
224
|
-
message: `The device should have the item "${
|
|
225
|
-
path: ["subdevices",
|
|
224
|
+
message: `The device should have the item "${s}" because it is mandatory for devices of type "${o.type}"`,
|
|
225
|
+
path: ["subdevices", d, "items"]
|
|
226
226
|
});
|
|
227
227
|
});
|
|
228
228
|
});
|
|
@@ -252,7 +252,7 @@ function r(t = void 0) {
|
|
|
252
252
|
const a = "Invalid hexadecimal value";
|
|
253
253
|
return t === void 0 ? e.string().regex(/^0x[0-9a-fA-F]+$/, a) : e.string().regex(new RegExp(`^0x[0-9a-fA-F]{${t}}$`), a);
|
|
254
254
|
}
|
|
255
|
-
function
|
|
255
|
+
function m() {
|
|
256
256
|
return e.union([
|
|
257
257
|
r(2),
|
|
258
258
|
e.number().min(0).max(255)
|
|
@@ -263,8 +263,8 @@ function S() {
|
|
|
263
263
|
if (!Array.isArray(t) || t.length % 2 !== 0)
|
|
264
264
|
return !1;
|
|
265
265
|
for (let a = 0; a < t.length; a += 2) {
|
|
266
|
-
const
|
|
267
|
-
if (typeof
|
|
266
|
+
const u = t[a], o = t[a + 1];
|
|
267
|
+
if (typeof u != "number" || typeof o != "string")
|
|
268
268
|
return !1;
|
|
269
269
|
}
|
|
270
270
|
return !0;
|
|
@@ -298,7 +298,7 @@ function J() {
|
|
|
298
298
|
fn: e.undefined().describe("Generic function to read ZCL attributes."),
|
|
299
299
|
at: r(4).or(e.array(r(4))).describe("Attribute ID."),
|
|
300
300
|
cl: r(4).describe("Cluster ID."),
|
|
301
|
-
ep: e.optional(
|
|
301
|
+
ep: e.optional(m()).describe("Endpoint, 255 means any endpoint, 0 means auto selected from subdevice."),
|
|
302
302
|
mf: e.optional(r(4)).describe("Manufacturer code, must be set to 0x0000 for non manufacturer specific commands."),
|
|
303
303
|
eval: e.optional(p()).describe("Javascript expression to transform the raw value.")
|
|
304
304
|
}),
|
|
@@ -306,7 +306,7 @@ function J() {
|
|
|
306
306
|
fn: e.literal("zcl").describe("Generic function to read ZCL attributes."),
|
|
307
307
|
at: r(4).or(e.array(r(4))).describe("Attribute ID."),
|
|
308
308
|
cl: r(4).describe("Cluster ID."),
|
|
309
|
-
ep: e.optional(
|
|
309
|
+
ep: e.optional(m()).describe("Endpoint, 255 means any endpoint, 0 means auto selected from subdevice."),
|
|
310
310
|
mf: e.optional(r(4)).describe("Manufacturer code, must be set to 0x0000 for non manufacturer specific commands."),
|
|
311
311
|
eval: e.optional(p()).describe("Javascript expression to transform the raw value."),
|
|
312
312
|
script: e.optional(f()).describe("Relative path of a Javascript .js file.")
|
|
@@ -315,7 +315,7 @@ function J() {
|
|
|
315
315
|
fn: e.literal("zcl:attr").describe("Generic function to parse ZCL values from read/report commands."),
|
|
316
316
|
at: r(4).or(e.array(r(4))).describe("String hex value or array of string hex values."),
|
|
317
317
|
cl: r(4).describe("Cluster ID."),
|
|
318
|
-
ep: e.optional(
|
|
318
|
+
ep: e.optional(m()).describe("Endpoint, 255 means any endpoint, 0 means auto selected from subdevice."),
|
|
319
319
|
mf: e.optional(r(4)).describe("Manufacturer code, must be set to 0x0000 for non manufacturer specific commands."),
|
|
320
320
|
eval: e.optional(p()).describe("Javascript expression to transform the attribute value to the Item value."),
|
|
321
321
|
script: e.optional(f()).describe("Relative path of a Javascript .js file.")
|
|
@@ -323,7 +323,7 @@ function J() {
|
|
|
323
323
|
e.strictObject({
|
|
324
324
|
fn: e.literal("zcl:cmd").describe("Generic function to parse ZCL values from read/report commands."),
|
|
325
325
|
cl: r(4).describe("Cluster ID."),
|
|
326
|
-
ep: e.optional(
|
|
326
|
+
ep: e.optional(m()).describe("Endpoint, 255 means any endpoint, 0 means auto selected from subdevice."),
|
|
327
327
|
mf: e.optional(r(4)).describe("Manufacturer code, must be set to 0x0000 for non manufacturer specific commands."),
|
|
328
328
|
cmd: e.optional(r(2)).describe("Zigbee command."),
|
|
329
329
|
eval: e.optional(p()).describe("Javascript expression to transform the attribute value to the Item value."),
|
|
@@ -344,7 +344,7 @@ function Z() {
|
|
|
344
344
|
at: e.optional(r(4).or(e.array(r(4)))).describe("Attribute ID."),
|
|
345
345
|
cl: r(4).describe("Cluster ID."),
|
|
346
346
|
cppsrc: e.optional(e.string()),
|
|
347
|
-
ep: e.optional(
|
|
347
|
+
ep: e.optional(m()).describe("Endpoint, 255 means any endpoint, 0 means auto selected from subdevice."),
|
|
348
348
|
cmd: e.optional(r(2)).describe("Zigbee command."),
|
|
349
349
|
mf: e.optional(r(4)).describe("Manufacturer code, must be set to 0x0000 for non manufacturer specific commands."),
|
|
350
350
|
eval: e.optional(p()).describe("Javascript expression to transform the raw value."),
|
|
@@ -355,7 +355,7 @@ function Z() {
|
|
|
355
355
|
at: e.optional(r(4).or(e.array(r(4)))).describe("Attribute ID."),
|
|
356
356
|
cl: r(4).describe("Cluster ID."),
|
|
357
357
|
cppsrc: e.optional(e.string()),
|
|
358
|
-
ep: e.optional(
|
|
358
|
+
ep: e.optional(m()).describe("Endpoint, 255 means any endpoint, 0 means auto selected from subdevice."),
|
|
359
359
|
cmd: e.optional(r(2)).describe("Zigbee command."),
|
|
360
360
|
mf: e.optional(r(4)).describe("Manufacturer code, must be set to 0x0000 for non manufacturer specific commands."),
|
|
361
361
|
eval: e.optional(p()).describe("Javascript expression to transform the raw value."),
|
|
@@ -365,7 +365,7 @@ function Z() {
|
|
|
365
365
|
fn: e.literal("zcl:attr").describe("Generic function to parse ZCL values from read/report commands."),
|
|
366
366
|
at: r(4).or(e.array(r(4))).describe("String hex value or array of string hex values."),
|
|
367
367
|
cl: r(4).describe("Cluster ID."),
|
|
368
|
-
ep: e.optional(
|
|
368
|
+
ep: e.optional(m()).describe("Endpoint, 255 means any endpoint, 0 means auto selected from subdevice."),
|
|
369
369
|
mf: e.optional(r(4)).describe("Manufacturer code, must be set to 0x0000 for non manufacturer specific commands."),
|
|
370
370
|
eval: e.optional(p()).describe("Javascript expression to transform the attribute value to the Item value."),
|
|
371
371
|
script: e.optional(f()).describe("Relative path of a Javascript .js file.")
|
|
@@ -373,7 +373,7 @@ function Z() {
|
|
|
373
373
|
e.strictObject({
|
|
374
374
|
fn: e.literal("zcl:cmd").describe("Generic function to parse ZCL values from read/report commands."),
|
|
375
375
|
cl: r(4).describe("Cluster ID."),
|
|
376
|
-
ep: e.optional(
|
|
376
|
+
ep: e.optional(m()).describe("Endpoint, 255 means any endpoint, 0 means auto selected from subdevice."),
|
|
377
377
|
mf: e.optional(r(4)).describe("Manufacturer code, must be set to 0x0000 for non manufacturer specific commands."),
|
|
378
378
|
cmd: e.optional(r(2)).describe("Zigbee command."),
|
|
379
379
|
eval: e.optional(p()).describe("Javascript expression to transform the attribute value to the Item value."),
|
|
@@ -395,7 +395,7 @@ function Z() {
|
|
|
395
395
|
}),
|
|
396
396
|
e.strictObject({
|
|
397
397
|
fn: e.literal("xiaomi:special").describe("Generic function to parse custom Xiaomi attributes and commands."),
|
|
398
|
-
ep: e.optional(
|
|
398
|
+
ep: e.optional(m()).describe("Endpoint, 255 means any endpoint, 0 means auto selected from subdevice."),
|
|
399
399
|
mf: e.optional(r(4)).describe("Manufacturer code, must be set to 0x0000 for non manufacturer specific commands."),
|
|
400
400
|
at: e.optional(r(4)).describe("Attribute ID. The attribute to parse, shall be 0xff01, 0xff02 or 0x00f7"),
|
|
401
401
|
idx: r(2).describe("A 8-bit string hex value."),
|
|
@@ -412,7 +412,7 @@ function Z() {
|
|
|
412
412
|
message: "eval and script should not both be present"
|
|
413
413
|
});
|
|
414
414
|
}
|
|
415
|
-
function
|
|
415
|
+
function G() {
|
|
416
416
|
return e.discriminatedUnion("fn", [
|
|
417
417
|
e.strictObject({
|
|
418
418
|
fn: e.literal("none")
|
|
@@ -424,7 +424,7 @@ function R() {
|
|
|
424
424
|
"change.timeout": e.optional(e.number()),
|
|
425
425
|
cl: r(4).describe("Cluster ID."),
|
|
426
426
|
dt: r(2).describe("Data type."),
|
|
427
|
-
ep: e.optional(
|
|
427
|
+
ep: e.optional(m()).describe("Endpoint, 255 means any endpoint, 0 means auto selected from subdevice."),
|
|
428
428
|
mf: e.optional(r(4)).describe("Manufacturer code, must be set to 0x0000 for non manufacturer specific commands."),
|
|
429
429
|
eval: e.optional(p()).describe("Javascript expression to transform the raw value."),
|
|
430
430
|
script: e.optional(f()).describe("Relative path of a Javascript .js file.")
|
|
@@ -436,7 +436,7 @@ function R() {
|
|
|
436
436
|
"change.timeout": e.optional(e.number()),
|
|
437
437
|
cl: r(4).describe("Cluster ID."),
|
|
438
438
|
dt: r(2).describe("Data type."),
|
|
439
|
-
ep: e.optional(
|
|
439
|
+
ep: e.optional(m()).describe("Endpoint, 255 means any endpoint, 0 means auto selected from subdevice."),
|
|
440
440
|
mf: e.optional(r(4)).describe("Manufacturer code, must be set to 0x0000 for non manufacturer specific commands."),
|
|
441
441
|
eval: e.optional(p()).describe("Javascript expression to transform the raw value."),
|
|
442
442
|
script: e.optional(f()).describe("Relative path of a Javascript .js file.")
|
|
@@ -448,7 +448,7 @@ function R() {
|
|
|
448
448
|
"change.timeout": e.optional(e.number()),
|
|
449
449
|
cl: r(4).describe("Cluster ID."),
|
|
450
450
|
dt: r(2).describe("Data type."),
|
|
451
|
-
ep: e.optional(
|
|
451
|
+
ep: e.optional(m()).describe("Endpoint, 255 means any endpoint, 0 means auto selected from subdevice."),
|
|
452
452
|
mf: e.optional(r(4)).describe("Manufacturer code, must be set to 0x0000 for non manufacturer specific commands."),
|
|
453
453
|
eval: e.optional(p()).describe("Javascript expression to transform the attribute value to the Item value."),
|
|
454
454
|
script: e.optional(f()).describe("Relative path of a Javascript .js file.")
|
|
@@ -456,7 +456,7 @@ function R() {
|
|
|
456
456
|
e.strictObject({
|
|
457
457
|
fn: e.literal("zcl:cmd").describe("Generic function to parse ZCL values from read/report commands."),
|
|
458
458
|
cl: r(4).describe("Cluster ID."),
|
|
459
|
-
ep: e.optional(
|
|
459
|
+
ep: e.optional(m()).describe("Endpoint, 255 means any endpoint, 0 means auto selected from subdevice."),
|
|
460
460
|
mf: e.optional(r(4)).describe("Manufacturer code, must be set to 0x0000 for non manufacturer specific commands."),
|
|
461
461
|
cmd: e.optional(r(2)).describe("Zigbee command."),
|
|
462
462
|
eval: e.optional(p()).describe("Javascript expression to transform the attribute value to the Item value."),
|
|
@@ -507,7 +507,7 @@ function D(t) {
|
|
|
507
507
|
virtual: e.optional(e.boolean()).describe("TODO: What is this ?"),
|
|
508
508
|
read: e.optional(J()).describe("Fonction used to read value."),
|
|
509
509
|
parse: e.optional(Z()).describe("Fonction used to parse incoming values."),
|
|
510
|
-
write: e.optional(
|
|
510
|
+
write: e.optional(G()).describe("Fonction used to write value."),
|
|
511
511
|
"refresh.interval": e.optional(e.number()).describe("Refresh interval used for read fonction, NEED to be superior at value used in binding part."),
|
|
512
512
|
// TODO Validate this
|
|
513
513
|
values: e.optional(e.unknown()).describe("TODO: What is this ?"),
|
|
@@ -515,7 +515,7 @@ function D(t) {
|
|
|
515
515
|
default: e.optional(e.unknown()).describe("Defaut value.")
|
|
516
516
|
});
|
|
517
517
|
}
|
|
518
|
-
function
|
|
518
|
+
function R(t) {
|
|
519
519
|
return e.strictObject({
|
|
520
520
|
$schema: e.optional(e.string()),
|
|
521
521
|
schema: e.literal("devcap1.schema.json"),
|
|
@@ -552,7 +552,7 @@ function F(t) {
|
|
|
552
552
|
return e.strictObject({
|
|
553
553
|
type: e.union([
|
|
554
554
|
e.enum(Object.keys(t.deviceTypes), {
|
|
555
|
-
errorMap: (a,
|
|
555
|
+
errorMap: (a, u) => a.code === "invalid_enum_value" ? { message: `Invalid enum value. Expected type from generic attributes definition, received '${a.received}'` } : { message: u.defaultError }
|
|
556
556
|
}),
|
|
557
557
|
e.string().regex(/^(?!\$TYPE_).*/g, "The type start with $TYPE_ but is not present in constants.json")
|
|
558
558
|
]),
|
|
@@ -561,7 +561,7 @@ function F(t) {
|
|
|
561
561
|
fingerprint: e.optional(e.strictObject({
|
|
562
562
|
profile: r(4),
|
|
563
563
|
device: r(4),
|
|
564
|
-
endpoint:
|
|
564
|
+
endpoint: m(),
|
|
565
565
|
in: e.optional(e.array(r(4))),
|
|
566
566
|
out: e.optional(e.array(r(4)))
|
|
567
567
|
})),
|
|
@@ -585,7 +585,7 @@ function z(t) {
|
|
|
585
585
|
id: !0
|
|
586
586
|
}).extend({
|
|
587
587
|
name: e.enum(t.attributes, {
|
|
588
|
-
errorMap: (a,
|
|
588
|
+
errorMap: (a, u) => a.code === "invalid_enum_value" ? { message: `Invalid enum value. Expected item from generic attributes definition, received '${a.received}'` } : { message: u.defaultError }
|
|
589
589
|
}).describe("Item name.")
|
|
590
590
|
});
|
|
591
591
|
}
|
|
@@ -593,8 +593,8 @@ function k(t) {
|
|
|
593
593
|
return e.discriminatedUnion("bind", [
|
|
594
594
|
e.strictObject({
|
|
595
595
|
bind: e.literal("unicast"),
|
|
596
|
-
"src.ep":
|
|
597
|
-
"dst.ep": e.optional(
|
|
596
|
+
"src.ep": m().describe("Source endpoint."),
|
|
597
|
+
"dst.ep": e.optional(m()).describe("Destination endpoint, generaly 0x01."),
|
|
598
598
|
cl: r(4).describe("Cluster."),
|
|
599
599
|
report: e.optional(e.array(
|
|
600
600
|
e.strictObject({
|
|
@@ -609,7 +609,7 @@ function k(t) {
|
|
|
609
609
|
}),
|
|
610
610
|
e.strictObject({
|
|
611
611
|
bind: e.literal("groupcast"),
|
|
612
|
-
"src.ep":
|
|
612
|
+
"src.ep": m().describe("Source endpoint."),
|
|
613
613
|
cl: r(4).describe("Cluster."),
|
|
614
614
|
"config.group": e.number().min(0).max(255)
|
|
615
615
|
})
|
|
@@ -618,7 +618,7 @@ function k(t) {
|
|
|
618
618
|
function L(t) {
|
|
619
619
|
const a = e.array(
|
|
620
620
|
e.enum(t.attributes, {
|
|
621
|
-
errorMap: (
|
|
621
|
+
errorMap: (u, o) => u.code === "invalid_enum_value" ? { message: `Invalid enum value. Expected item from generic attributes definition, received '${u.received}'` } : { message: o.defaultError }
|
|
622
622
|
})
|
|
623
623
|
);
|
|
624
624
|
return e.strictObject({
|
|
@@ -626,7 +626,7 @@ function L(t) {
|
|
|
626
626
|
schema: e.literal("subdevice1.schema.json"),
|
|
627
627
|
type: e.union([
|
|
628
628
|
e.enum(Object.keys(t.deviceTypes), {
|
|
629
|
-
errorMap: (
|
|
629
|
+
errorMap: (u, o) => u.code === "invalid_enum_value" ? { message: `Invalid enum value. Expected type from generic attributes definition, received '${u.received}'` } : { message: o.defaultError }
|
|
630
630
|
}),
|
|
631
631
|
e.string().regex(/^(?!\$TYPE_).*/g, "The type start with $TYPE_ but is not present in constants.json")
|
|
632
632
|
]),
|
|
@@ -640,18 +640,18 @@ function L(t) {
|
|
|
640
640
|
}
|
|
641
641
|
function x(t) {
|
|
642
642
|
return e.discriminatedUnion("schema", [
|
|
643
|
-
|
|
643
|
+
R(t),
|
|
644
644
|
A(),
|
|
645
645
|
I(),
|
|
646
646
|
D(),
|
|
647
647
|
L(t)
|
|
648
|
-
]).superRefine((a,
|
|
648
|
+
]).superRefine((a, u) => {
|
|
649
649
|
switch (a.schema) {
|
|
650
650
|
case "devcap1.schema.json":
|
|
651
|
-
y[a.schema].map((o) => o(a,
|
|
651
|
+
y[a.schema].map((o) => o(a, u, t));
|
|
652
652
|
break;
|
|
653
653
|
case "constants2.schema.json":
|
|
654
|
-
y[a.schema].map((o) => o(a,
|
|
654
|
+
y[a.schema].map((o) => o(a, u, t));
|
|
655
655
|
break;
|
|
656
656
|
}
|
|
657
657
|
});
|
|
@@ -664,7 +664,7 @@ function P(t = {
|
|
|
664
664
|
subDevices: {}
|
|
665
665
|
}) {
|
|
666
666
|
let a = x(t);
|
|
667
|
-
const
|
|
667
|
+
const u = () => {
|
|
668
668
|
a = x(t);
|
|
669
669
|
};
|
|
670
670
|
return { generics: t, loadGeneric: (s) => {
|
|
@@ -680,28 +680,33 @@ function P(t = {
|
|
|
680
680
|
};
|
|
681
681
|
break;
|
|
682
682
|
case "constants2.schema.json": {
|
|
683
|
-
Object.keys(n).filter((
|
|
684
|
-
t.manufacturers[
|
|
685
|
-
}), Object.keys(n).filter((
|
|
686
|
-
t.deviceTypes[
|
|
683
|
+
Object.keys(n).filter((c) => c.startsWith("$MF_")).forEach((c) => {
|
|
684
|
+
t.manufacturers[c] = n[c];
|
|
685
|
+
}), Object.keys(n).filter((c) => c.startsWith("$TYPE_")).forEach((c) => {
|
|
686
|
+
t.deviceTypes[c] = n[c];
|
|
687
687
|
});
|
|
688
688
|
break;
|
|
689
689
|
}
|
|
690
690
|
case "resourceitem1.schema.json": {
|
|
691
691
|
if (t.attributes.includes(n.id))
|
|
692
692
|
throw new Error(`Got duplicate resource item with attribute id '${n.id}'.`);
|
|
693
|
-
const
|
|
694
|
-
delete
|
|
693
|
+
const c = n, b = n.id;
|
|
694
|
+
delete c.$schema, delete c.schema, delete c.id, t.resources[b] = c, t.attributes.push(b);
|
|
695
695
|
break;
|
|
696
696
|
}
|
|
697
697
|
case "subdevice1.schema.json":
|
|
698
698
|
t.subDevices[n.type] = n, t.subDevices[n.name] = n;
|
|
699
699
|
break;
|
|
700
|
-
|
|
701
|
-
throw new Error(
|
|
700
|
+
default:
|
|
701
|
+
throw new Error(`Got invalid generic file, got data with schema '${n.schema}'.`);
|
|
702
702
|
}
|
|
703
|
-
return
|
|
704
|
-
}, validate: (s) => a.parse(s), getSchema: () => a, version: E
|
|
703
|
+
return u(), !0;
|
|
704
|
+
}, validate: (s) => a.parse(s), getSchema: () => a, version: E, isGeneric: (s) => [
|
|
705
|
+
"constants1.schema.json",
|
|
706
|
+
"constants2.schema.json",
|
|
707
|
+
"resourceitem1.schema.json",
|
|
708
|
+
"subdevice1.schema.json"
|
|
709
|
+
].includes(s), isDDF: (s) => s === "devcap1.schema.json" };
|
|
705
710
|
}
|
|
706
711
|
export {
|
|
707
712
|
P as createValidator
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@deconz-community/ddf-validator",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.17.0",
|
|
4
4
|
"description": "Validating DDF files for deconz",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"deconz",
|
|
@@ -53,13 +53,13 @@
|
|
|
53
53
|
"pnpm": ">=8.6.8",
|
|
54
54
|
"node": ">=16.0.0"
|
|
55
55
|
},
|
|
56
|
-
"packageManager": "pnpm@8.7.
|
|
56
|
+
"packageManager": "pnpm@8.7.5",
|
|
57
57
|
"devDependencies": {
|
|
58
|
-
"@types/jsdom": "^21.1.
|
|
59
|
-
"@types/node": "^20.6.
|
|
58
|
+
"@types/jsdom": "^21.1.3",
|
|
59
|
+
"@types/node": "^20.6.2",
|
|
60
60
|
"@types/pako": "^2.0.0",
|
|
61
|
-
"@typescript-eslint/eslint-plugin": "^6.
|
|
62
|
-
"@typescript-eslint/parser": "^6.
|
|
61
|
+
"@typescript-eslint/eslint-plugin": "^6.7.0",
|
|
62
|
+
"@typescript-eslint/parser": "^6.7.0",
|
|
63
63
|
"degit": "^2.8.4",
|
|
64
64
|
"eslint": "^8.49.0",
|
|
65
65
|
"glob": "^10.3.4",
|