@deconz-community/ddf-validator 2.32.0 → 2.34.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 +57 -8
- package/dist/ddf-validator.mjs +163 -165
- package/package.json +20 -20
package/dist/ddf-validator.mjs
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
import { z as e } from "zod";
|
|
2
|
-
const
|
|
2
|
+
const A = "2.34.0", _ = {
|
|
3
3
|
"devcap1.schema.json": [
|
|
4
|
-
|
|
4
|
+
F,
|
|
5
|
+
k,
|
|
6
|
+
Z,
|
|
7
|
+
G,
|
|
5
8
|
P,
|
|
6
|
-
|
|
7
|
-
L,
|
|
8
|
-
R,
|
|
9
|
-
Y
|
|
9
|
+
M
|
|
10
10
|
],
|
|
11
11
|
"constants2.schema.json": [
|
|
12
|
-
|
|
12
|
+
z
|
|
13
13
|
]
|
|
14
14
|
};
|
|
15
|
-
function
|
|
16
|
-
const
|
|
17
|
-
if (
|
|
15
|
+
function F(t, r, m) {
|
|
16
|
+
const s = typeof t.manufacturername == "string" && typeof t.modelid == "string";
|
|
17
|
+
if (s)
|
|
18
18
|
return;
|
|
19
|
-
const
|
|
20
|
-
if (
|
|
19
|
+
const o = Array.isArray(t.manufacturername) && Array.isArray(t.modelid);
|
|
20
|
+
if (o && t.manufacturername.length !== t.modelid.length) {
|
|
21
21
|
r.addIssue({
|
|
22
22
|
code: e.ZodIssueCode.invalid_intersection_types,
|
|
23
23
|
message: "When 'manufacturername' and 'modelid' are both arrays they should be the same length",
|
|
@@ -25,39 +25,38 @@ function z(t, r, u) {
|
|
|
25
25
|
});
|
|
26
26
|
return;
|
|
27
27
|
}
|
|
28
|
-
(
|
|
28
|
+
(s || o) === !1 && r.addIssue({
|
|
29
29
|
code: e.ZodIssueCode.invalid_intersection_types,
|
|
30
30
|
message: "Invalid properties 'manufacturername' and 'modelid' should have the same type",
|
|
31
31
|
path: ["manufacturername", "modelid"]
|
|
32
32
|
});
|
|
33
33
|
}
|
|
34
|
-
function
|
|
34
|
+
function k(t, r, m) {
|
|
35
35
|
if (!t.bindings)
|
|
36
36
|
return;
|
|
37
|
-
const
|
|
37
|
+
const s = (n) => `0x${(typeof n == "number" ? n : Number.parseInt(n, 16)).toString(16)}`, o = {};
|
|
38
38
|
t.bindings.forEach((n) => {
|
|
39
|
-
n.bind === "unicast" && n.report && n.report.forEach((
|
|
40
|
-
|
|
39
|
+
n.bind === "unicast" && n.report && n.report.forEach((c) => {
|
|
40
|
+
c.max !== 65535 && (o[`${s(n["src.ep"])}.${s(n.cl)}.${s(c.at)}`] = c.max);
|
|
41
41
|
});
|
|
42
|
-
}), t.subdevices.forEach((n,
|
|
43
|
-
n.items.forEach((a,
|
|
44
|
-
var s;
|
|
42
|
+
}), t.subdevices.forEach((n, c) => {
|
|
43
|
+
n.items.forEach((a, d) => {
|
|
45
44
|
if (a["refresh.interval"] && a.read && a.read.fn === "zcl:attr" && a.read.at) {
|
|
46
|
-
const
|
|
47
|
-
for (let
|
|
48
|
-
const h = `${
|
|
49
|
-
|
|
45
|
+
const i = s(a.read.ep ?? n.fingerprint?.endpoint ?? n.uuid[1]), u = Array.isArray(a.read.at) ? a.read.at : [a.read.at];
|
|
46
|
+
for (let p = 0; p < u.length; p++) {
|
|
47
|
+
const h = `${i}.${s(a.read.cl)}.${s(u[p])}`;
|
|
48
|
+
o[h] !== void 0 && a["refresh.interval"] - 60 < o[h] && r.addIssue({
|
|
50
49
|
code: e.ZodIssueCode.custom,
|
|
51
|
-
message: `The refresh interval (${a["refresh.interval"]} - 60 = ${a["refresh.interval"] - 60}) should be greater than the binding max refresh value (${
|
|
52
|
-
path: ["subdevices",
|
|
50
|
+
message: `The refresh interval (${a["refresh.interval"]} - 60 = ${a["refresh.interval"] - 60}) should be greater than the binding max refresh value (${o[h]}) with a margin of 60 seconds`,
|
|
51
|
+
path: ["subdevices", c, "items", d, "refresh.interval"]
|
|
53
52
|
});
|
|
54
53
|
}
|
|
55
54
|
}
|
|
56
55
|
});
|
|
57
56
|
});
|
|
58
57
|
}
|
|
59
|
-
function
|
|
60
|
-
const
|
|
58
|
+
function Z(t, r, m) {
|
|
59
|
+
const s = [
|
|
61
60
|
/*
|
|
62
61
|
{
|
|
63
62
|
description: 'a device should always have basic attributes.',
|
|
@@ -147,100 +146,100 @@ function W(t, r, u) {
|
|
|
147
146
|
}
|
|
148
147
|
}
|
|
149
148
|
}
|
|
150
|
-
],
|
|
151
|
-
t.subdevices.forEach((n,
|
|
152
|
-
const a = n.items.map((
|
|
153
|
-
|
|
154
|
-
(Object.keys(
|
|
155
|
-
switch (
|
|
149
|
+
], o = (n, c) => typeof n == "string" ? c(n) : Array.isArray(n) ? n.every((a) => o(a, c)) : "and" in n ? n.and.every((a) => o(a, c)) : "or" in n ? n.or.some((a) => o(a, c)) : !1;
|
|
150
|
+
t.subdevices.forEach((n, c) => {
|
|
151
|
+
const a = n.items.map((d) => d.name);
|
|
152
|
+
s.forEach((d) => {
|
|
153
|
+
(Object.keys(d.if).length === 0 || Object.entries(d.if).some(([i, u]) => {
|
|
154
|
+
switch (i) {
|
|
156
155
|
case "type":
|
|
157
|
-
return
|
|
156
|
+
return o(u, (p) => p === n.type);
|
|
158
157
|
case "item":
|
|
159
|
-
return
|
|
158
|
+
return o(u, (p) => a.includes(p));
|
|
160
159
|
default:
|
|
161
160
|
return !1;
|
|
162
161
|
}
|
|
163
|
-
})) && (
|
|
162
|
+
})) && (o(d.need.item, (i) => a.includes(i)) || r.addIssue({
|
|
164
163
|
code: e.ZodIssueCode.custom,
|
|
165
|
-
message: `The device is missing some items because ${
|
|
166
|
-
path: ["subdevices",
|
|
164
|
+
message: `The device is missing some items because ${d.description}`,
|
|
165
|
+
path: ["subdevices", c, "items"]
|
|
167
166
|
}));
|
|
168
167
|
});
|
|
169
168
|
});
|
|
170
169
|
}
|
|
171
|
-
function
|
|
172
|
-
const
|
|
173
|
-
t.subdevices.forEach((
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
const
|
|
177
|
-
|
|
170
|
+
function G(t, r, m) {
|
|
171
|
+
const s = ["parse", "write"];
|
|
172
|
+
t.subdevices.forEach((o, n) => {
|
|
173
|
+
o.items.forEach((c, a) => {
|
|
174
|
+
s.forEach((d) => {
|
|
175
|
+
const i = c[d];
|
|
176
|
+
i !== void 0 && (i.fn === void 0 || i.fn === "zcl:attr" || i.fn === "zcl:cmd") && (i.eval === void 0 && i.script === void 0 && r.addIssue({
|
|
178
177
|
code: e.ZodIssueCode.custom,
|
|
179
|
-
message: `The '${
|
|
180
|
-
path: ["subdevices", n, "items", a,
|
|
181
|
-
}),
|
|
178
|
+
message: `The '${d}' function is missing 'eval' or 'script' option.`,
|
|
179
|
+
path: ["subdevices", n, "items", a, d]
|
|
180
|
+
}), i.eval !== void 0 && i.script !== void 0 && r.addIssue({
|
|
182
181
|
code: e.ZodIssueCode.custom,
|
|
183
|
-
message: `The '${
|
|
184
|
-
path: ["subdevices", n, "items", a,
|
|
182
|
+
message: `The '${d}' function is having both 'eval' and 'script' option.`,
|
|
183
|
+
path: ["subdevices", n, "items", a, d]
|
|
185
184
|
}));
|
|
186
185
|
});
|
|
187
186
|
});
|
|
188
187
|
});
|
|
189
188
|
}
|
|
190
|
-
function
|
|
191
|
-
const
|
|
192
|
-
Object.keys(t).forEach((
|
|
193
|
-
if (!Object.keys(
|
|
194
|
-
if (!["$MF_", "$TYPE_"].some((n) =>
|
|
189
|
+
function z(t, r, m) {
|
|
190
|
+
const s = w();
|
|
191
|
+
Object.keys(t).forEach((o) => {
|
|
192
|
+
if (!Object.keys(s.shape).includes(o)) {
|
|
193
|
+
if (!["$MF_", "$TYPE_"].some((n) => o.startsWith(n))) {
|
|
195
194
|
r.addIssue({
|
|
196
195
|
code: e.ZodIssueCode.custom,
|
|
197
196
|
message: "The constant key should start with '$MF_' or '$TYPE_'",
|
|
198
|
-
path: [
|
|
197
|
+
path: [o]
|
|
199
198
|
});
|
|
200
199
|
return;
|
|
201
200
|
}
|
|
202
|
-
typeof t[
|
|
201
|
+
typeof t[o] != "string" && r.addIssue({
|
|
203
202
|
code: e.ZodIssueCode.custom,
|
|
204
203
|
message: "The constant value should be a string",
|
|
205
|
-
path: [
|
|
204
|
+
path: [o]
|
|
206
205
|
});
|
|
207
206
|
}
|
|
208
207
|
});
|
|
209
208
|
}
|
|
210
|
-
function
|
|
211
|
-
t.subdevices.forEach((
|
|
212
|
-
const n =
|
|
209
|
+
function P(t, r, m) {
|
|
210
|
+
t.subdevices.forEach((s, o) => {
|
|
211
|
+
const n = m.subDevices[s.type];
|
|
213
212
|
if (!n) {
|
|
214
213
|
r.addIssue({
|
|
215
214
|
code: e.ZodIssueCode.custom,
|
|
216
|
-
message: `The device is missing the device definition (subdevice1.schema.json) for the type "${
|
|
217
|
-
path: ["subdevices",
|
|
215
|
+
message: `The device is missing the device definition (subdevice1.schema.json) for the type "${s.type}"`,
|
|
216
|
+
path: ["subdevices", o, "items"]
|
|
218
217
|
});
|
|
219
218
|
return;
|
|
220
219
|
}
|
|
221
|
-
let
|
|
222
|
-
n.items_optional && (
|
|
223
|
-
|
|
220
|
+
let c = n.items;
|
|
221
|
+
n.items_optional && (c = c.filter((a) => !n.items_optional.includes(a))), c.forEach((a) => {
|
|
222
|
+
s.items.find((d) => d.name === a) || r.addIssue({
|
|
224
223
|
code: e.ZodIssueCode.custom,
|
|
225
|
-
message: `The device should have the item "${a}" because it is mandatory for devices of type "${
|
|
226
|
-
path: ["subdevices",
|
|
224
|
+
message: `The device should have the item "${a}" because it is mandatory for devices of type "${s.type}"`,
|
|
225
|
+
path: ["subdevices", o, "items"]
|
|
227
226
|
});
|
|
228
227
|
});
|
|
229
228
|
});
|
|
230
229
|
}
|
|
231
|
-
function
|
|
232
|
-
t.subdevices.forEach((
|
|
233
|
-
const n =
|
|
234
|
-
|
|
235
|
-
|
|
230
|
+
function M(t, r, m) {
|
|
231
|
+
t.subdevices.forEach((s, o) => {
|
|
232
|
+
const n = s.items.map((c) => c.name);
|
|
233
|
+
s.items.forEach((c, a) => {
|
|
234
|
+
c.parse && c.parse.fn === "numtostr" && (n.includes(c.parse.srcitem) || r.addIssue({
|
|
236
235
|
code: e.ZodIssueCode.custom,
|
|
237
|
-
message: `The device should have the item "${
|
|
238
|
-
path: ["subdevices",
|
|
236
|
+
message: `The device should have the item "${c.parse.srcitem}" because it is used in the 'numtostr' function`,
|
|
237
|
+
path: ["subdevices", o, "items", a, "parse", "srcitem"]
|
|
239
238
|
}));
|
|
240
239
|
});
|
|
241
240
|
});
|
|
242
241
|
}
|
|
243
|
-
function
|
|
242
|
+
function W(t) {
|
|
244
243
|
return e.strictObject({
|
|
245
244
|
$schema: e.optional(e.string()),
|
|
246
245
|
schema: e.literal("constants1.schema.json"),
|
|
@@ -249,17 +248,17 @@ function B(t) {
|
|
|
249
248
|
"device-types": e.record(e.string().startsWith("$TYPE_"), e.string())
|
|
250
249
|
});
|
|
251
250
|
}
|
|
252
|
-
function
|
|
251
|
+
function w(t) {
|
|
253
252
|
return e.object({
|
|
254
253
|
$schema: e.optional(e.string()),
|
|
255
254
|
schema: e.literal("constants2.schema.json"),
|
|
256
255
|
ddfvalidate: e.optional(e.boolean())
|
|
257
|
-
}).
|
|
256
|
+
}).loose();
|
|
258
257
|
}
|
|
259
|
-
function
|
|
258
|
+
function L() {
|
|
260
259
|
return e.string().regex(
|
|
261
260
|
// Regex for AAAA-MM-JJ
|
|
262
|
-
/^(\d{4})-(?:
|
|
261
|
+
/^(\d{4})-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\d|3[01])$/,
|
|
263
262
|
"Invalid date value"
|
|
264
263
|
);
|
|
265
264
|
}
|
|
@@ -273,19 +272,19 @@ function g() {
|
|
|
273
272
|
e.number().min(0).max(255)
|
|
274
273
|
]);
|
|
275
274
|
}
|
|
276
|
-
function
|
|
275
|
+
function N() {
|
|
277
276
|
return e.custom((t) => {
|
|
278
277
|
if (!Array.isArray(t) || t.length % 2 !== 0)
|
|
279
278
|
return !1;
|
|
280
279
|
for (let r = 0; r < t.length; r += 2) {
|
|
281
|
-
const
|
|
282
|
-
if (typeof
|
|
280
|
+
const m = t[r], s = t[r + 1];
|
|
281
|
+
if (typeof m != "number" || typeof s != "string")
|
|
283
282
|
return !1;
|
|
284
283
|
}
|
|
285
284
|
return !0;
|
|
286
285
|
}, "The value must be an array with an even number of values and alternating between number and string.");
|
|
287
286
|
}
|
|
288
|
-
function
|
|
287
|
+
function E() {
|
|
289
288
|
return e.union([
|
|
290
289
|
e.tuple([
|
|
291
290
|
e.literal("$address.ext"),
|
|
@@ -298,10 +297,10 @@ function S() {
|
|
|
298
297
|
])
|
|
299
298
|
]);
|
|
300
299
|
}
|
|
301
|
-
function
|
|
300
|
+
function O() {
|
|
302
301
|
return e.string();
|
|
303
302
|
}
|
|
304
|
-
function
|
|
303
|
+
function D() {
|
|
305
304
|
return e.string();
|
|
306
305
|
}
|
|
307
306
|
const x = e.strictObject({
|
|
@@ -311,8 +310,8 @@ const x = e.strictObject({
|
|
|
311
310
|
mf: e.optional(l(4)).describe("Manufacturer code, must be set to 0x0000 for non manufacturer specific commands."),
|
|
312
311
|
cmd: e.optional(e.union([e.literal("any"), l(2)])).describe("Zigbee command."),
|
|
313
312
|
fc: e.optional(l(2).or(e.number())).describe("Zigbee command frame control."),
|
|
314
|
-
eval: e.optional(
|
|
315
|
-
script: e.optional(
|
|
313
|
+
eval: e.optional(D()).describe("Javascript expression to transform the attribute value to the Item value."),
|
|
314
|
+
script: e.optional(O()).describe("Relative path of a Javascript .js file.")
|
|
316
315
|
}), f = {
|
|
317
316
|
read: x.extend({}),
|
|
318
317
|
parse: x.extend({}),
|
|
@@ -322,7 +321,7 @@ const x = e.strictObject({
|
|
|
322
321
|
dt: e.optional(l(2)).describe("Data type.")
|
|
323
322
|
})
|
|
324
323
|
};
|
|
325
|
-
function
|
|
324
|
+
function R() {
|
|
326
325
|
return e.discriminatedUnion("fn", [
|
|
327
326
|
e.strictObject({
|
|
328
327
|
fn: e.literal("none")
|
|
@@ -343,7 +342,7 @@ function V() {
|
|
|
343
342
|
message: "eval and script should not both be present"
|
|
344
343
|
});
|
|
345
344
|
}
|
|
346
|
-
function
|
|
345
|
+
function Y(t) {
|
|
347
346
|
return e.discriminatedUnion("fn", [
|
|
348
347
|
f.parse.extend({
|
|
349
348
|
fn: e.undefined().describe("Generic function to read ZCL attributes."),
|
|
@@ -362,10 +361,10 @@ function q(t) {
|
|
|
362
361
|
e.strictObject({
|
|
363
362
|
fn: e.literal("numtostr").describe("Generic function to to convert number to string."),
|
|
364
363
|
srcitem: e.enum(t.attributes, {
|
|
365
|
-
|
|
364
|
+
error: (r) => r.code === "invalid_value" ? `Invalid enum value. Expected item from generic attributes definition, received '${r.input}'` : r.message
|
|
366
365
|
}).describe("The source item holding the number."),
|
|
367
366
|
op: e.enum(["lt", "le", "eq", "gt", "ge"]).describe("Comparison operator (lt | le | eq | gt | ge)"),
|
|
368
|
-
to:
|
|
367
|
+
to: N().describe("Array of (num, string) mappings")
|
|
369
368
|
}),
|
|
370
369
|
e.strictObject({
|
|
371
370
|
fn: e.literal("time").describe("Specialized function to parse time, local and last set time from read/report commands of the time cluster and auto-sync time if needed.")
|
|
@@ -388,7 +387,7 @@ function q(t) {
|
|
|
388
387
|
message: "eval and script should not both be present"
|
|
389
388
|
});
|
|
390
389
|
}
|
|
391
|
-
function
|
|
390
|
+
function B() {
|
|
392
391
|
return e.discriminatedUnion("fn", [
|
|
393
392
|
e.strictObject({
|
|
394
393
|
fn: e.literal("none")
|
|
@@ -412,7 +411,7 @@ function H() {
|
|
|
412
411
|
message: "eval and script should not both be present"
|
|
413
412
|
});
|
|
414
413
|
}
|
|
415
|
-
function
|
|
414
|
+
function C(t) {
|
|
416
415
|
return e.strictObject({
|
|
417
416
|
$schema: e.optional(e.string()),
|
|
418
417
|
schema: e.literal("resourceitem1.schema.json"),
|
|
@@ -420,7 +419,7 @@ function Z(t) {
|
|
|
420
419
|
ddfvalidate: e.optional(e.boolean()),
|
|
421
420
|
description: e.optional(e.string()).describe("Item description, better to do not use it."),
|
|
422
421
|
comment: e.optional(e.string()).describe("TODO: What is this ? What the difference with description ?"),
|
|
423
|
-
deprecated: e.optional(
|
|
422
|
+
deprecated: e.optional(L()).describe("Date of deprecation, if the item is deprecated, it's better to use the new one."),
|
|
424
423
|
datatype: e.optional(e.enum([
|
|
425
424
|
"String",
|
|
426
425
|
"Bool",
|
|
@@ -445,9 +444,9 @@ function Z(t) {
|
|
|
445
444
|
static: e.optional(e.union([e.string(), e.number(), e.boolean()])).describe("A static default value is fixed and can be not changed."),
|
|
446
445
|
range: e.optional(e.tuple([e.number(), e.number()])).describe("Values range limit."),
|
|
447
446
|
virtual: e.optional(e.boolean()).describe("TODO: What is this ?"),
|
|
448
|
-
read: e.optional(
|
|
449
|
-
parse: e.optional(
|
|
450
|
-
write: e.optional(
|
|
447
|
+
read: e.optional(R()).describe("Fonction used to read value."),
|
|
448
|
+
parse: e.optional(Y(t)).describe("Fonction used to parse incoming values."),
|
|
449
|
+
write: e.optional(B()).describe("Fonction used to write value."),
|
|
451
450
|
"refresh.interval": e.optional(e.number()).describe("Refresh interval used for read fonction, NEED to be superior at value used in binding part."),
|
|
452
451
|
// TODO Validate this
|
|
453
452
|
values: e.optional(e.unknown()).describe("TODO: What is this ?"),
|
|
@@ -455,7 +454,7 @@ function Z(t) {
|
|
|
455
454
|
default: e.optional(e.unknown()).describe("Defaut value.")
|
|
456
455
|
});
|
|
457
456
|
}
|
|
458
|
-
function
|
|
457
|
+
function U(t) {
|
|
459
458
|
return e.strictObject({
|
|
460
459
|
$schema: e.optional(e.string()),
|
|
461
460
|
schema: e.literal("devcap1.schema.json"),
|
|
@@ -483,25 +482,25 @@ function J(t) {
|
|
|
483
482
|
vendor: e.optional(e.string()).describe("Friendly name of the manufacturer."),
|
|
484
483
|
product: e.optional(e.string()).describe("Friendly name of the product."),
|
|
485
484
|
comment: e.optional(e.string()),
|
|
486
|
-
matchexpr: e.optional(
|
|
487
|
-
path: e.optional(
|
|
485
|
+
matchexpr: e.optional(D()).describe("Need to return true for the DDF be used."),
|
|
486
|
+
path: e.optional(O()).describe("DDF path, useless, can be removed."),
|
|
488
487
|
sleeper: e.optional(e.boolean()).describe("Sleeping devices can only receive when awake."),
|
|
489
488
|
supportsMgmtBind: e.optional(e.boolean()),
|
|
490
489
|
status: e.enum(["Draft", "Bronze", "Silver", "Gold"]).describe("The code quality of the DDF file."),
|
|
491
|
-
subdevices: e.array(
|
|
492
|
-
bindings: e.optional(e.array(
|
|
490
|
+
subdevices: e.array(V(t)).describe("Devices section."),
|
|
491
|
+
bindings: e.optional(e.array(H())).describe("Bindings section.")
|
|
493
492
|
});
|
|
494
493
|
}
|
|
495
|
-
function
|
|
494
|
+
function V(t) {
|
|
496
495
|
return e.strictObject({
|
|
497
496
|
type: e.union([
|
|
498
497
|
e.enum(Object.keys(t.deviceTypes), {
|
|
499
|
-
|
|
498
|
+
error: (r) => r.code === "invalid_value" ? `Invalid enum value. Expected type from generic attributes definition, received '${r.received}'` : r.message
|
|
500
499
|
}),
|
|
501
500
|
e.string().regex(/^(?!\$TYPE_).*/g, "The type start with $TYPE_ but is not present in constants.json")
|
|
502
501
|
]),
|
|
503
502
|
restapi: e.enum(["/lights", "/sensors"]),
|
|
504
|
-
uuid:
|
|
503
|
+
uuid: E(),
|
|
505
504
|
fingerprint: e.optional(e.strictObject({
|
|
506
505
|
profile: l(4),
|
|
507
506
|
device: l(4),
|
|
@@ -518,22 +517,22 @@ function X(t) {
|
|
|
518
517
|
buttons: e.optional(e.any()),
|
|
519
518
|
// TODO validate this
|
|
520
519
|
buttonevents: e.optional(e.any()),
|
|
521
|
-
items: e.array(
|
|
520
|
+
items: e.array(q(t)),
|
|
522
521
|
example: e.optional(e.unknown())
|
|
523
522
|
});
|
|
524
523
|
}
|
|
525
|
-
function
|
|
526
|
-
return
|
|
524
|
+
function q(t) {
|
|
525
|
+
return C(t).omit({
|
|
527
526
|
$schema: !0,
|
|
528
527
|
schema: !0,
|
|
529
528
|
id: !0
|
|
530
529
|
}).extend({
|
|
531
530
|
name: e.enum(t.attributes, {
|
|
532
|
-
|
|
531
|
+
error: (r) => r.code === "invalid_value" ? `Invalid enum value. Expected item from generic attributes definition, received '${r.received}'` : r.message
|
|
533
532
|
}).describe("Item name.")
|
|
534
533
|
});
|
|
535
534
|
}
|
|
536
|
-
function
|
|
535
|
+
function H(t) {
|
|
537
536
|
return e.discriminatedUnion("bind", [
|
|
538
537
|
e.strictObject({
|
|
539
538
|
bind: e.literal("unicast"),
|
|
@@ -559,10 +558,10 @@ function Q(t) {
|
|
|
559
558
|
})
|
|
560
559
|
]);
|
|
561
560
|
}
|
|
562
|
-
function
|
|
561
|
+
function J(t) {
|
|
563
562
|
const r = e.array(
|
|
564
563
|
e.enum(t.attributes, {
|
|
565
|
-
|
|
564
|
+
error: (m) => m.code === "invalid_value" ? `Invalid enum value. Expected item from generic attributes definition, received '${m.input}'` : m.message
|
|
566
565
|
})
|
|
567
566
|
);
|
|
568
567
|
return e.strictObject({
|
|
@@ -571,111 +570,110 @@ function ee(t) {
|
|
|
571
570
|
ddfvalidate: e.optional(e.boolean()),
|
|
572
571
|
type: e.union([
|
|
573
572
|
e.enum(Object.keys(t.deviceTypes), {
|
|
574
|
-
|
|
573
|
+
error: (m) => m.code === "invalid_value" ? `Invalid enum value. Expected type from generic attributes definition, received '${m.input}'` : m.message
|
|
575
574
|
}),
|
|
576
575
|
e.string().regex(/^(?!\$TYPE_).*/g, "The type start with $TYPE_ but is not present in constants.json")
|
|
577
576
|
]),
|
|
578
577
|
name: e.string(),
|
|
578
|
+
ui_name: e.string().max(64),
|
|
579
579
|
restapi: e.enum(["/lights", "/sensors"]),
|
|
580
580
|
order: e.number(),
|
|
581
|
-
uuid:
|
|
581
|
+
uuid: E(),
|
|
582
582
|
items: r,
|
|
583
583
|
items_optional: e.optional(r)
|
|
584
584
|
});
|
|
585
585
|
}
|
|
586
|
-
function
|
|
586
|
+
function T(t) {
|
|
587
587
|
return e.discriminatedUnion("schema", [
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
]).superRefine((r,
|
|
588
|
+
U(t),
|
|
589
|
+
W(),
|
|
590
|
+
w(),
|
|
591
|
+
C(t),
|
|
592
|
+
J(t)
|
|
593
|
+
]).superRefine((r, m) => {
|
|
594
594
|
switch (r.schema) {
|
|
595
595
|
case "devcap1.schema.json":
|
|
596
|
-
|
|
596
|
+
_[r.schema].map((s) => s(r, m, t));
|
|
597
597
|
break;
|
|
598
598
|
case "constants2.schema.json":
|
|
599
|
-
|
|
599
|
+
_[r.schema].map((s) => s(r, m, t));
|
|
600
600
|
break;
|
|
601
601
|
}
|
|
602
602
|
});
|
|
603
603
|
}
|
|
604
|
-
function
|
|
604
|
+
function K(t = {
|
|
605
605
|
attributes: [],
|
|
606
606
|
manufacturers: {},
|
|
607
607
|
deviceTypes: {},
|
|
608
608
|
resources: {},
|
|
609
609
|
subDevices: {}
|
|
610
610
|
}) {
|
|
611
|
-
let r =
|
|
612
|
-
const
|
|
613
|
-
r =
|
|
614
|
-
},
|
|
611
|
+
let r = T(t);
|
|
612
|
+
const m = () => {
|
|
613
|
+
r = T(t);
|
|
614
|
+
}, s = (d) => [
|
|
615
615
|
"constants1.schema.json",
|
|
616
616
|
"constants2.schema.json",
|
|
617
617
|
"resourceitem1.schema.json",
|
|
618
618
|
"subdevice1.schema.json"
|
|
619
|
-
].includes(
|
|
620
|
-
const
|
|
621
|
-
switch (
|
|
619
|
+
].includes(d), o = (d) => d === "devcap1.schema.json", n = (d) => {
|
|
620
|
+
const i = r.parse(d);
|
|
621
|
+
switch (i.schema) {
|
|
622
622
|
case "constants1.schema.json":
|
|
623
623
|
t.manufacturers = {
|
|
624
624
|
...t.manufacturers,
|
|
625
|
-
...
|
|
625
|
+
...i.manufacturers
|
|
626
626
|
}, t.deviceTypes = {
|
|
627
627
|
...t.deviceTypes,
|
|
628
|
-
...
|
|
628
|
+
...i["device-types"]
|
|
629
629
|
};
|
|
630
630
|
break;
|
|
631
631
|
case "constants2.schema.json": {
|
|
632
|
-
Object.keys(
|
|
633
|
-
t.manufacturers[
|
|
634
|
-
}), Object.keys(
|
|
635
|
-
t.deviceTypes[
|
|
632
|
+
Object.keys(i).filter((u) => u.startsWith("$MF_")).forEach((u) => {
|
|
633
|
+
t.manufacturers[u] = i[u];
|
|
634
|
+
}), Object.keys(i).filter((u) => u.startsWith("$TYPE_")).forEach((u) => {
|
|
635
|
+
t.deviceTypes[u] = i[u];
|
|
636
636
|
});
|
|
637
637
|
break;
|
|
638
638
|
}
|
|
639
639
|
case "resourceitem1.schema.json": {
|
|
640
|
-
if (t.attributes.includes(
|
|
641
|
-
throw new Error(`Got duplicate resource item with attribute id '${
|
|
642
|
-
const
|
|
643
|
-
delete
|
|
640
|
+
if (t.attributes.includes(i.id))
|
|
641
|
+
throw new Error(`Got duplicate resource item with attribute id '${i.id}'.`);
|
|
642
|
+
const u = i, p = i.id;
|
|
643
|
+
delete u.$schema, delete u.schema, delete u.id, t.resources[p] = u, t.attributes.push(p);
|
|
644
644
|
break;
|
|
645
645
|
}
|
|
646
646
|
case "subdevice1.schema.json":
|
|
647
|
-
t.subDevices[
|
|
647
|
+
t.subDevices[i.type] = i, t.subDevices[i.name] = i;
|
|
648
648
|
break;
|
|
649
649
|
default:
|
|
650
|
-
throw new Error(`Got invalid generic file, got data with schema '${
|
|
650
|
+
throw new Error(`Got invalid generic file, got data with schema '${i.schema}'.`);
|
|
651
651
|
}
|
|
652
|
-
return
|
|
653
|
-
},
|
|
654
|
-
return { generics: t, loadGeneric: n, validate:
|
|
655
|
-
const p = (
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
var w;
|
|
660
|
-
(w = o.onSectionProgress) == null || w.call(o, h, I++, b.length);
|
|
652
|
+
return m(), !0;
|
|
653
|
+
}, c = (d) => r.parse(d);
|
|
654
|
+
return { generics: t, loadGeneric: n, validate: c, bulkValidate: (d, i, u = {}) => {
|
|
655
|
+
const p = (h, v) => {
|
|
656
|
+
let I = 0, $ = Number.POSITIVE_INFINITY, j = h, b = [];
|
|
657
|
+
for (u.onSectionStart?.(v, h.length); b = [], u.onSectionProgress?.(v, 1, h.length), j.forEach((y) => {
|
|
658
|
+
u.onSectionProgress?.(v, I++, h.length);
|
|
661
659
|
try {
|
|
662
|
-
|
|
663
|
-
} catch (
|
|
664
|
-
|
|
660
|
+
v === "generic" ? n(y.data) : v === "ddf" && c(y.data);
|
|
661
|
+
} catch (S) {
|
|
662
|
+
b.push({
|
|
665
663
|
...y,
|
|
666
|
-
error:
|
|
664
|
+
error: S
|
|
667
665
|
});
|
|
668
666
|
}
|
|
669
|
-
}), !(
|
|
670
|
-
I -=
|
|
671
|
-
return
|
|
667
|
+
}), !(b.length === 0 || b.length >= $); )
|
|
668
|
+
I -= b.length, j = b, $ = b.length;
|
|
669
|
+
return u.onSectionEnd?.(v, h.length, b), b;
|
|
672
670
|
};
|
|
673
671
|
return [
|
|
674
|
-
...p(
|
|
675
|
-
...p(
|
|
672
|
+
...p(d, "generic"),
|
|
673
|
+
...p(i, "ddf")
|
|
676
674
|
];
|
|
677
|
-
}, getSchema: () => r, version:
|
|
675
|
+
}, getSchema: () => r, version: A, isGeneric: s, isDDF: o };
|
|
678
676
|
}
|
|
679
677
|
export {
|
|
680
|
-
|
|
678
|
+
K as createValidator
|
|
681
679
|
};
|