@deconz-community/ddf-validator 0.2.0 → 0.2.1
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-validator.cjs +1 -0
- package/dist/ddf-validator.mjs +349 -0
- package/package.json +4 -4
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("zod"),m=["$TYPE_AIR_PURIFIER","$TYPE_AIR_QUALITY_SENSOR","$TYPE_ALARM_SENSOR","$TYPE_BATTERY_SENSOR","$TYPE_COLOR_DIMMABLE_LIGHT","$TYPE_COLOR_LIGHT","$TYPE_COLOR_TEMPERATURE_LIGHT","$TYPE_CONSUMPTION_SENSOR","$TYPE_DIMMABLE_LIGHT","$TYPE_DIMMABLE_PLUGIN_UNIT","$TYPE_DIMMER_SWITCH","$TYPE_DOOR_LOCK_CONTROLLER","$TYPE_DOOR_LOCK","$TYPE_EXTENDED_COLOR_LIGHT","$TYPE_FIRE_SENSOR","$TYPE_HUMIDITY_SENSOR","$TYPE_LIGHT_LEVEL_SENSOR","$TYPE_ON_OFF_LIGHT","$TYPE_ON_OFF_OUTPUT","$TYPE_ON_OFF_PLUGIN_UNIT","$TYPE_OPEN_CLOSE_SENSOR","$TYPE_POWER_SENSOR","$TYPE_PRESENCE_SENSOR","$TYPE_PRESSURE_SENSOR","$TYPE_RANGE_EXTENDER","$TYPE_RELATIVE_ROTARY","$TYPE_SMART_PLUG","$TYPE_SPECTRAL_SENSOR","$TYPE_SWITCH","$TYPE_TEMPERATURE_SENSOR","$TYPE_THERMOSTAT","$TYPE_VIBRATION_SENSOR","$TYPE_WARNING_DEVICE","$TYPE_WATER_LEAK_SENSOR","$TYPE_WINDOW_COVERING_DEVICE","$TYPE_ZGP_SWITCH","ZHAAirPurifier","ZHAAirQuality","ZHAAlarm","ZHABattery","Color dimmable light","Color light","Color temperature light","ZHAConsumption","Dimmable light","Dimmable plug-in unit","Dimmer switch","Door lock controller","Door Lock","Extended color light","ZHAFire","ZHAHumidity","ZHALightLevel","On/Off light","On/Off output","On/Off plug-in unit","ZHAOpenClose","ZHAPower","ZHAPresence","ZHAPressure","Range extender","ZHARelativeRotary","Smart plug","ZHASpectral","ZHASwitch","ZHATemperature","ZHAThermostat","ZHAVibration","Warning device","ZHAWater","Window covering device","ZGPSwitch","ZHAAncillaryControl","ZHATime","ZHACarbonMonoxide","ZHADoorLock"];function e(n=void 0){return n===void 0?t.z.string():t.z.string().length(2+n)}function o(){return t.z.string()}function d(){return t.z.string()}function i(){return t.z.union([e(2),t.z.number().min(0).max(255)])}function r(){return t.z.string()}function E(){return t.z.custom(n=>{if(!Array.isArray(n)||n.length%2!==0)return!1;for(let a=0;a<n.length;a+=2){const c=n[a],u=n[a+1];if(typeof c!="number"||typeof u!="string")return!1}return!0},"The value must be an array with an even number of values and alternating between number and string.")}function b(n){return l().parse(n)}function T(){return t.z.discriminatedUnion("schema",[l().innerType()])}function l(){return t.z.strictObject({schema:t.z.literal("devcap1.schema.json"),"doc:path":t.z.optional(t.z.string()),"doc:hdr":t.z.optional(t.z.string()),"md:known_issues":t.z.optional(t.z.array(t.z.string())),manufacturername:t.z.string().or(t.z.array(t.z.string())),modelid:t.z.string().or(t.z.array(t.z.string())),vendor:t.z.optional(t.z.string()),comment:t.z.optional(t.z.string()),matchexpr:t.z.optional(o()),path:t.z.optional(r()),product:t.z.optional(t.z.string()),sleeper:t.z.optional(t.z.boolean()),supportsMgmtBind:t.z.optional(t.z.boolean()),status:t.z.enum(["Draft","Bronze","Silver","Gold"]),subdevices:t.z.array(z()),bindings:t.z.optional(t.z.array(p()))}).refine(n=>typeof n.manufacturername=="string"&&typeof n.modelid=="string"||Array.isArray(n.manufacturername)&&Array.isArray(n.modelid)&&n.manufacturername.length===n.modelid.length,{message:"manufacturername and modelid should be both strings or arrays with the same length.",path:["manufacturername","modelid"]})}function z(){return t.z.strictObject({type:t.z.enum(m),restapi:t.z.enum(["/lights","/sensors"]),uuid:t.z.union([t.z.tuple([t.z.literal("$address.ext"),e(2)]),t.z.tuple([t.z.literal("$address.ext"),e(2),e(4)])]),fingerprint:t.z.optional(t.z.strictObject({profile:e(4),device:e(4),endpoint:i(),in:t.z.optional(t.z.array(e(4))),out:t.z.optional(t.z.array(e(4)))})),meta:t.z.optional(t.z.strictObject({values:t.z.any(),"group.endpoints":t.z.optional(t.z.array(t.z.number()))})),buttons:t.z.optional(t.z.any()),buttonevents:t.z.optional(t.z.any()),items:t.z.array(s()),example:t.z.optional(t.z.unknown())})}function s(){return t.z.strictObject({name:t.z.string(),description:t.z.optional(t.z.string()),comment:t.z.optional(t.z.string()),public:t.z.optional(t.z.boolean()),static:t.z.optional(t.z.union([t.z.string(),t.z.number(),t.z.boolean()])),range:t.z.optional(t.z.tuple([t.z.number(),t.z.number()])),deprecated:t.z.optional(d()),access:t.z.optional(t.z.literal("R")),read:t.z.optional(t.z.discriminatedUnion("fn",[t.z.strictObject({fn:t.z.literal("none")}),t.z.strictObject({fn:t.z.undefined(),at:t.z.optional(e(4).or(t.z.array(e(4)))),cl:e(4),ep:t.z.optional(i()),mf:t.z.optional(e(4)),eval:t.z.optional(o())}),t.z.strictObject({fn:t.z.literal("zcl"),at:t.z.optional(e(4).or(t.z.array(e(4)))),cl:e(4),ep:t.z.optional(i()),mf:t.z.optional(e(4)),eval:t.z.optional(o())}),t.z.strictObject({fn:t.z.literal("tuya")})])),parse:t.z.optional(t.z.discriminatedUnion("fn",[t.z.strictObject({fn:t.z.undefined(),at:t.z.optional(e(4)),cl:e(4),ep:t.z.optional(i()),cmd:t.z.optional(e(2)),mf:t.z.optional(e(4)),eval:t.z.optional(o()),script:t.z.optional(r())}).refine(n=>!("eval"in n&&"script"in n),{message:"eval and script should not both be present"}).innerType(),t.z.strictObject({fn:t.z.literal("zcl"),at:t.z.optional(e(4)),cl:e(4),ep:t.z.optional(i()),cmd:t.z.optional(e(2)),mf:t.z.optional(e(4)),eval:t.z.optional(o()),script:t.z.optional(r())}).refine(n=>!("eval"in n&&"script"in n),{message:"eval and script should not both be present"}).innerType(),t.z.strictObject({fn:t.z.literal("ias:zonestatus"),mask:t.z.enum(["alarm1","alarm2"])}),t.z.strictObject({fn:t.z.literal("numtostr"),srcitem:t.z.enum(["state/airqualityppb","state/pm2_5"]),op:t.z.literal("le"),to:E()}),t.z.strictObject({fn:t.z.literal("xiaomi:special"),ep:t.z.optional(i()),at:t.z.optional(e(4)),idx:e(2),eval:t.z.optional(o()),script:t.z.optional(r())}).refine(n=>!("eval"in n&&"script"in n),{message:"eval and script should not both be present"}).innerType(),t.z.strictObject({fn:t.z.literal("tuya"),dpid:t.z.number(),eval:t.z.optional(o()),script:t.z.optional(r())}).refine(n=>!("eval"in n&&"script"in n),{message:"eval and script should not both be present"}).innerType()])),write:t.z.optional(t.z.discriminatedUnion("fn",[t.z.strictObject({fn:t.z.literal("none")}),t.z.strictObject({fn:t.z.undefined(),at:t.z.optional(e(4).or(t.z.array(e(4)))),"state.timeout":t.z.optional(t.z.number()),"change.timeout":t.z.optional(t.z.number()),cl:e(4),dt:e(2),ep:t.z.optional(i()),mf:t.z.optional(e(4)),eval:t.z.optional(o()),script:t.z.optional(r())}).refine(n=>!("eval"in n&&"script"in n),{message:"eval and script should not both be present"}).innerType(),t.z.strictObject({fn:t.z.literal("zcl"),at:t.z.optional(e(4).or(t.z.array(e(4)))),"state.timeout":t.z.optional(t.z.number()),"change.timeout":t.z.optional(t.z.number()),cl:e(4),dt:e(2),ep:t.z.optional(i()),mf:t.z.optional(e(4)),eval:t.z.optional(o()),script:t.z.optional(r())}).refine(n=>!("eval"in n&&"script"in n),{message:"eval and script should not both be present"}).innerType(),t.z.strictObject({fn:t.z.literal("tuya"),dpid:t.z.number(),dt:e(2),eval:t.z.optional(o()),script:t.z.optional(r())}).refine(n=>!("eval"in n&&"script"in n),{message:"eval and script should not both be present"}).innerType()])),awake:t.z.optional(t.z.boolean()),default:t.z.optional(t.z.unknown()),values:t.z.optional(t.z.unknown()),"refresh.interval":t.z.optional(t.z.number())})}function p(){return t.z.discriminatedUnion("bind",[t.z.strictObject({bind:t.z.literal("unicast"),"src.ep":i(),"dst.ep":t.z.optional(i()),cl:e(4),report:t.z.optional(t.z.array(t.z.strictObject({at:e(4),dt:e(2),mf:t.z.optional(e(4)),min:t.z.number(),max:t.z.number(),change:t.z.optional(e().or(t.z.number()))})))}),t.z.strictObject({bind:t.z.literal("groupcast"),"src.ep":i(),cl:e(4),"config.group":t.z.number()})])}exports.ddfSchema=l;exports.mainSchema=T;exports.subBindingSchema=p;exports.subDeviceItemSchema=s;exports.subDeviceSchema=z;exports.validate=b;
|
|
@@ -0,0 +1,349 @@
|
|
|
1
|
+
import { z as t } from "zod";
|
|
2
|
+
const c = [
|
|
3
|
+
"$TYPE_AIR_PURIFIER",
|
|
4
|
+
"$TYPE_AIR_QUALITY_SENSOR",
|
|
5
|
+
"$TYPE_ALARM_SENSOR",
|
|
6
|
+
"$TYPE_BATTERY_SENSOR",
|
|
7
|
+
"$TYPE_COLOR_DIMMABLE_LIGHT",
|
|
8
|
+
"$TYPE_COLOR_LIGHT",
|
|
9
|
+
"$TYPE_COLOR_TEMPERATURE_LIGHT",
|
|
10
|
+
"$TYPE_CONSUMPTION_SENSOR",
|
|
11
|
+
"$TYPE_DIMMABLE_LIGHT",
|
|
12
|
+
"$TYPE_DIMMABLE_PLUGIN_UNIT",
|
|
13
|
+
"$TYPE_DIMMER_SWITCH",
|
|
14
|
+
"$TYPE_DOOR_LOCK_CONTROLLER",
|
|
15
|
+
"$TYPE_DOOR_LOCK",
|
|
16
|
+
"$TYPE_EXTENDED_COLOR_LIGHT",
|
|
17
|
+
"$TYPE_FIRE_SENSOR",
|
|
18
|
+
"$TYPE_HUMIDITY_SENSOR",
|
|
19
|
+
"$TYPE_LIGHT_LEVEL_SENSOR",
|
|
20
|
+
"$TYPE_ON_OFF_LIGHT",
|
|
21
|
+
"$TYPE_ON_OFF_OUTPUT",
|
|
22
|
+
"$TYPE_ON_OFF_PLUGIN_UNIT",
|
|
23
|
+
"$TYPE_OPEN_CLOSE_SENSOR",
|
|
24
|
+
"$TYPE_POWER_SENSOR",
|
|
25
|
+
"$TYPE_PRESENCE_SENSOR",
|
|
26
|
+
"$TYPE_PRESSURE_SENSOR",
|
|
27
|
+
"$TYPE_RANGE_EXTENDER",
|
|
28
|
+
"$TYPE_RELATIVE_ROTARY",
|
|
29
|
+
"$TYPE_SMART_PLUG",
|
|
30
|
+
"$TYPE_SPECTRAL_SENSOR",
|
|
31
|
+
"$TYPE_SWITCH",
|
|
32
|
+
"$TYPE_TEMPERATURE_SENSOR",
|
|
33
|
+
"$TYPE_THERMOSTAT",
|
|
34
|
+
"$TYPE_VIBRATION_SENSOR",
|
|
35
|
+
"$TYPE_WARNING_DEVICE",
|
|
36
|
+
"$TYPE_WATER_LEAK_SENSOR",
|
|
37
|
+
"$TYPE_WINDOW_COVERING_DEVICE",
|
|
38
|
+
"$TYPE_ZGP_SWITCH",
|
|
39
|
+
"ZHAAirPurifier",
|
|
40
|
+
"ZHAAirQuality",
|
|
41
|
+
"ZHAAlarm",
|
|
42
|
+
"ZHABattery",
|
|
43
|
+
"Color dimmable light",
|
|
44
|
+
"Color light",
|
|
45
|
+
"Color temperature light",
|
|
46
|
+
"ZHAConsumption",
|
|
47
|
+
"Dimmable light",
|
|
48
|
+
"Dimmable plug-in unit",
|
|
49
|
+
"Dimmer switch",
|
|
50
|
+
"Door lock controller",
|
|
51
|
+
"Door Lock",
|
|
52
|
+
"Extended color light",
|
|
53
|
+
"ZHAFire",
|
|
54
|
+
"ZHAHumidity",
|
|
55
|
+
"ZHALightLevel",
|
|
56
|
+
"On/Off light",
|
|
57
|
+
"On/Off output",
|
|
58
|
+
"On/Off plug-in unit",
|
|
59
|
+
"ZHAOpenClose",
|
|
60
|
+
"ZHAPower",
|
|
61
|
+
"ZHAPresence",
|
|
62
|
+
"ZHAPressure",
|
|
63
|
+
"Range extender",
|
|
64
|
+
"ZHARelativeRotary",
|
|
65
|
+
"Smart plug",
|
|
66
|
+
"ZHASpectral",
|
|
67
|
+
"ZHASwitch",
|
|
68
|
+
"ZHATemperature",
|
|
69
|
+
"ZHAThermostat",
|
|
70
|
+
"ZHAVibration",
|
|
71
|
+
"Warning device",
|
|
72
|
+
"ZHAWater",
|
|
73
|
+
"Window covering device",
|
|
74
|
+
"ZGPSwitch",
|
|
75
|
+
"ZHAAncillaryControl",
|
|
76
|
+
"ZHATime",
|
|
77
|
+
"ZHACarbonMonoxide",
|
|
78
|
+
"ZHADoorLock"
|
|
79
|
+
];
|
|
80
|
+
function n(e = void 0) {
|
|
81
|
+
return e === void 0 ? t.string() : t.string().length(2 + e);
|
|
82
|
+
}
|
|
83
|
+
function o() {
|
|
84
|
+
return t.string();
|
|
85
|
+
}
|
|
86
|
+
function u() {
|
|
87
|
+
return t.string();
|
|
88
|
+
}
|
|
89
|
+
function i() {
|
|
90
|
+
return t.union([
|
|
91
|
+
n(2),
|
|
92
|
+
t.number().min(0).max(255)
|
|
93
|
+
]);
|
|
94
|
+
}
|
|
95
|
+
function r() {
|
|
96
|
+
return t.string();
|
|
97
|
+
}
|
|
98
|
+
function m() {
|
|
99
|
+
return t.custom((e) => {
|
|
100
|
+
if (!Array.isArray(e) || e.length % 2 !== 0)
|
|
101
|
+
return !1;
|
|
102
|
+
for (let a = 0; a < e.length; a += 2) {
|
|
103
|
+
const s = e[a], p = e[a + 1];
|
|
104
|
+
if (typeof s != "number" || typeof p != "string")
|
|
105
|
+
return !1;
|
|
106
|
+
}
|
|
107
|
+
return !0;
|
|
108
|
+
}, "The value must be an array with an even number of values and alternating between number and string.");
|
|
109
|
+
}
|
|
110
|
+
function b(e) {
|
|
111
|
+
return l().parse(e);
|
|
112
|
+
}
|
|
113
|
+
function f() {
|
|
114
|
+
return t.discriminatedUnion("schema", [
|
|
115
|
+
l().innerType()
|
|
116
|
+
]);
|
|
117
|
+
}
|
|
118
|
+
function l() {
|
|
119
|
+
return t.strictObject({
|
|
120
|
+
schema: t.literal("devcap1.schema.json"),
|
|
121
|
+
"doc:path": t.optional(t.string()),
|
|
122
|
+
"doc:hdr": t.optional(t.string()),
|
|
123
|
+
"md:known_issues": t.optional(t.array(t.string())),
|
|
124
|
+
manufacturername: t.string().or(t.array(t.string())),
|
|
125
|
+
modelid: t.string().or(t.array(t.string())),
|
|
126
|
+
vendor: t.optional(t.string()),
|
|
127
|
+
comment: t.optional(t.string()),
|
|
128
|
+
matchexpr: t.optional(o()),
|
|
129
|
+
path: t.optional(r()),
|
|
130
|
+
product: t.optional(t.string()),
|
|
131
|
+
sleeper: t.optional(t.boolean()),
|
|
132
|
+
supportsMgmtBind: t.optional(t.boolean()),
|
|
133
|
+
status: t.enum(["Draft", "Bronze", "Silver", "Gold"]),
|
|
134
|
+
subdevices: t.array(E()),
|
|
135
|
+
bindings: t.optional(t.array(_()))
|
|
136
|
+
}).refine((e) => typeof e.manufacturername == "string" && typeof e.modelid == "string" || Array.isArray(e.manufacturername) && Array.isArray(e.modelid) && e.manufacturername.length === e.modelid.length, {
|
|
137
|
+
message: "manufacturername and modelid should be both strings or arrays with the same length.",
|
|
138
|
+
path: ["manufacturername", "modelid"]
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
function E() {
|
|
142
|
+
return t.strictObject({
|
|
143
|
+
type: t.enum(c),
|
|
144
|
+
restapi: t.enum(["/lights", "/sensors"]),
|
|
145
|
+
uuid: t.union([
|
|
146
|
+
t.tuple([
|
|
147
|
+
t.literal("$address.ext"),
|
|
148
|
+
n(2)
|
|
149
|
+
]),
|
|
150
|
+
t.tuple([
|
|
151
|
+
t.literal("$address.ext"),
|
|
152
|
+
n(2),
|
|
153
|
+
n(4)
|
|
154
|
+
])
|
|
155
|
+
]),
|
|
156
|
+
fingerprint: t.optional(t.strictObject({
|
|
157
|
+
profile: n(4),
|
|
158
|
+
device: n(4),
|
|
159
|
+
endpoint: i(),
|
|
160
|
+
in: t.optional(t.array(n(4))),
|
|
161
|
+
out: t.optional(t.array(n(4)))
|
|
162
|
+
})),
|
|
163
|
+
meta: t.optional(t.strictObject({
|
|
164
|
+
// TODO validate this
|
|
165
|
+
values: t.any(),
|
|
166
|
+
"group.endpoints": t.optional(t.array(t.number()))
|
|
167
|
+
})),
|
|
168
|
+
// TODO validate this
|
|
169
|
+
buttons: t.optional(t.any()),
|
|
170
|
+
// TODO validate this
|
|
171
|
+
buttonevents: t.optional(t.any()),
|
|
172
|
+
items: t.array(d()),
|
|
173
|
+
example: t.optional(t.unknown())
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
function d() {
|
|
177
|
+
return t.strictObject({
|
|
178
|
+
name: t.string(),
|
|
179
|
+
description: t.optional(t.string()),
|
|
180
|
+
comment: t.optional(t.string()),
|
|
181
|
+
public: t.optional(t.boolean()),
|
|
182
|
+
static: t.optional(t.union([t.string(), t.number(), t.boolean()])),
|
|
183
|
+
range: t.optional(t.tuple([t.number(), t.number()])),
|
|
184
|
+
deprecated: t.optional(u()),
|
|
185
|
+
access: t.optional(t.literal("R")),
|
|
186
|
+
read: t.optional(
|
|
187
|
+
t.discriminatedUnion("fn", [
|
|
188
|
+
t.strictObject({
|
|
189
|
+
fn: t.literal("none")
|
|
190
|
+
}),
|
|
191
|
+
t.strictObject({
|
|
192
|
+
fn: t.undefined(),
|
|
193
|
+
at: t.optional(n(4).or(t.array(n(4)))),
|
|
194
|
+
cl: n(4),
|
|
195
|
+
ep: t.optional(i()),
|
|
196
|
+
mf: t.optional(n(4)),
|
|
197
|
+
eval: t.optional(o())
|
|
198
|
+
}),
|
|
199
|
+
t.strictObject({
|
|
200
|
+
fn: t.literal("zcl"),
|
|
201
|
+
at: t.optional(n(4).or(t.array(n(4)))),
|
|
202
|
+
cl: n(4),
|
|
203
|
+
ep: t.optional(i()),
|
|
204
|
+
mf: t.optional(n(4)),
|
|
205
|
+
eval: t.optional(o())
|
|
206
|
+
}),
|
|
207
|
+
t.strictObject({
|
|
208
|
+
fn: t.literal("tuya")
|
|
209
|
+
})
|
|
210
|
+
])
|
|
211
|
+
),
|
|
212
|
+
parse: t.optional(
|
|
213
|
+
t.discriminatedUnion("fn", [
|
|
214
|
+
t.strictObject({
|
|
215
|
+
fn: t.undefined(),
|
|
216
|
+
at: t.optional(n(4)),
|
|
217
|
+
cl: n(4),
|
|
218
|
+
ep: t.optional(i()),
|
|
219
|
+
cmd: t.optional(n(2)),
|
|
220
|
+
mf: t.optional(n(4)),
|
|
221
|
+
eval: t.optional(o()),
|
|
222
|
+
script: t.optional(r())
|
|
223
|
+
}).refine((e) => !("eval" in e && "script" in e), {
|
|
224
|
+
message: "eval and script should not both be present"
|
|
225
|
+
}).innerType(),
|
|
226
|
+
t.strictObject({
|
|
227
|
+
fn: t.literal("zcl"),
|
|
228
|
+
at: t.optional(n(4)),
|
|
229
|
+
cl: n(4),
|
|
230
|
+
ep: t.optional(i()),
|
|
231
|
+
cmd: t.optional(n(2)),
|
|
232
|
+
mf: t.optional(n(4)),
|
|
233
|
+
eval: t.optional(o()),
|
|
234
|
+
script: t.optional(r())
|
|
235
|
+
}).refine((e) => !("eval" in e && "script" in e), {
|
|
236
|
+
message: "eval and script should not both be present"
|
|
237
|
+
}).innerType(),
|
|
238
|
+
t.strictObject({
|
|
239
|
+
fn: t.literal("ias:zonestatus"),
|
|
240
|
+
mask: t.enum(["alarm1", "alarm2"])
|
|
241
|
+
}),
|
|
242
|
+
t.strictObject({
|
|
243
|
+
fn: t.literal("numtostr"),
|
|
244
|
+
srcitem: t.enum(["state/airqualityppb", "state/pm2_5"]),
|
|
245
|
+
op: t.literal("le"),
|
|
246
|
+
to: m()
|
|
247
|
+
}),
|
|
248
|
+
t.strictObject({
|
|
249
|
+
fn: t.literal("xiaomi:special"),
|
|
250
|
+
ep: t.optional(i()),
|
|
251
|
+
at: t.optional(n(4)),
|
|
252
|
+
idx: n(2),
|
|
253
|
+
eval: t.optional(o()),
|
|
254
|
+
script: t.optional(r())
|
|
255
|
+
}).refine((e) => !("eval" in e && "script" in e), {
|
|
256
|
+
message: "eval and script should not both be present"
|
|
257
|
+
}).innerType(),
|
|
258
|
+
t.strictObject({
|
|
259
|
+
fn: t.literal("tuya"),
|
|
260
|
+
dpid: t.number(),
|
|
261
|
+
eval: t.optional(o()),
|
|
262
|
+
script: t.optional(r())
|
|
263
|
+
}).refine((e) => !("eval" in e && "script" in e), {
|
|
264
|
+
message: "eval and script should not both be present"
|
|
265
|
+
}).innerType()
|
|
266
|
+
])
|
|
267
|
+
),
|
|
268
|
+
write: t.optional(
|
|
269
|
+
t.discriminatedUnion("fn", [
|
|
270
|
+
t.strictObject({
|
|
271
|
+
fn: t.literal("none")
|
|
272
|
+
}),
|
|
273
|
+
t.strictObject({
|
|
274
|
+
fn: t.undefined(),
|
|
275
|
+
at: t.optional(n(4).or(t.array(n(4)))),
|
|
276
|
+
"state.timeout": t.optional(t.number()),
|
|
277
|
+
"change.timeout": t.optional(t.number()),
|
|
278
|
+
cl: n(4),
|
|
279
|
+
dt: n(2),
|
|
280
|
+
ep: t.optional(i()),
|
|
281
|
+
mf: t.optional(n(4)),
|
|
282
|
+
eval: t.optional(o()),
|
|
283
|
+
script: t.optional(r())
|
|
284
|
+
}).refine((e) => !("eval" in e && "script" in e), {
|
|
285
|
+
message: "eval and script should not both be present"
|
|
286
|
+
}).innerType(),
|
|
287
|
+
t.strictObject({
|
|
288
|
+
fn: t.literal("zcl"),
|
|
289
|
+
at: t.optional(n(4).or(t.array(n(4)))),
|
|
290
|
+
"state.timeout": t.optional(t.number()),
|
|
291
|
+
"change.timeout": t.optional(t.number()),
|
|
292
|
+
cl: n(4),
|
|
293
|
+
dt: n(2),
|
|
294
|
+
ep: t.optional(i()),
|
|
295
|
+
mf: t.optional(n(4)),
|
|
296
|
+
eval: t.optional(o()),
|
|
297
|
+
script: t.optional(r())
|
|
298
|
+
}).refine((e) => !("eval" in e && "script" in e), {
|
|
299
|
+
message: "eval and script should not both be present"
|
|
300
|
+
}).innerType(),
|
|
301
|
+
t.strictObject({
|
|
302
|
+
fn: t.literal("tuya"),
|
|
303
|
+
dpid: t.number(),
|
|
304
|
+
dt: n(2),
|
|
305
|
+
eval: t.optional(o()),
|
|
306
|
+
script: t.optional(r())
|
|
307
|
+
}).refine((e) => !("eval" in e && "script" in e), {
|
|
308
|
+
message: "eval and script should not both be present"
|
|
309
|
+
}).innerType()
|
|
310
|
+
])
|
|
311
|
+
),
|
|
312
|
+
awake: t.optional(t.boolean()),
|
|
313
|
+
default: t.optional(t.unknown()),
|
|
314
|
+
values: t.optional(t.unknown()),
|
|
315
|
+
"refresh.interval": t.optional(t.number())
|
|
316
|
+
});
|
|
317
|
+
}
|
|
318
|
+
function _() {
|
|
319
|
+
return t.discriminatedUnion("bind", [
|
|
320
|
+
t.strictObject({
|
|
321
|
+
bind: t.literal("unicast"),
|
|
322
|
+
"src.ep": i(),
|
|
323
|
+
"dst.ep": t.optional(i()),
|
|
324
|
+
cl: n(4),
|
|
325
|
+
report: t.optional(t.array(t.strictObject({
|
|
326
|
+
at: n(4),
|
|
327
|
+
dt: n(2),
|
|
328
|
+
mf: t.optional(n(4)),
|
|
329
|
+
min: t.number(),
|
|
330
|
+
max: t.number(),
|
|
331
|
+
change: t.optional(n().or(t.number()))
|
|
332
|
+
})))
|
|
333
|
+
}),
|
|
334
|
+
t.strictObject({
|
|
335
|
+
bind: t.literal("groupcast"),
|
|
336
|
+
"src.ep": i(),
|
|
337
|
+
cl: n(4),
|
|
338
|
+
"config.group": t.number()
|
|
339
|
+
})
|
|
340
|
+
]);
|
|
341
|
+
}
|
|
342
|
+
export {
|
|
343
|
+
l as ddfSchema,
|
|
344
|
+
f as mainSchema,
|
|
345
|
+
_ as subBindingSchema,
|
|
346
|
+
d as subDeviceItemSchema,
|
|
347
|
+
E as subDeviceSchema,
|
|
348
|
+
b as validate
|
|
349
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@deconz-community/ddf-validator",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "Validating DDF files for deconz",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"deconz",
|
|
@@ -35,7 +35,8 @@
|
|
|
35
35
|
"url": "https://github.com/sponsors/Zehir"
|
|
36
36
|
},
|
|
37
37
|
"files": [
|
|
38
|
-
"./dist/"
|
|
38
|
+
"./dist/ddf-validator.cjs",
|
|
39
|
+
"./dist/ddf-validator.mjs"
|
|
39
40
|
],
|
|
40
41
|
"main": "./dist/ddf-validator.cjs",
|
|
41
42
|
"module": "./dist/ddf-validator.mjs",
|
|
@@ -76,11 +77,10 @@
|
|
|
76
77
|
"build": "vite build",
|
|
77
78
|
"build:cleanup": "rimraf ./dist",
|
|
78
79
|
"build:vite": "vite build",
|
|
79
|
-
"build:dts": "dts-bundle-generator --config ./dts-bundle-generator.config.ts",
|
|
80
80
|
"lint": "eslint",
|
|
81
81
|
"test": "vitest run",
|
|
82
82
|
"test:watch": "vitest",
|
|
83
|
-
"test:download-sample": "rimraf ./test-data && degit dresden-elektronik/deconz-rest-plugin ./test-data",
|
|
83
|
+
"test:download-sample": "rimraf ./test-data && degit dresden-elektronik/deconz-rest-plugin /tmp/test-data && mv /tmp/test-data/devices ./test-data && rimraf /tmp/test-data",
|
|
84
84
|
"up": "taze major -I"
|
|
85
85
|
}
|
|
86
86
|
}
|