@deconz-community/ddf-validator 0.2.0 → 1.0.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/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2023 Zehir
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Zehir
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,80 @@
1
- # DDF bundler
1
+ # DDF validator
2
2
 
3
- Work in progress
3
+ The complete solution for validating DDF File.
4
+
5
+ - [Installation](#installation)
6
+ - [Quick Start](#quick-start)
7
+
8
+ ## Installation
9
+
10
+ ```sh
11
+ npm install @deconz-community/ddf-validator
12
+ ```
13
+
14
+ ## Quick Start
15
+
16
+ You can validate all DDF in a specefic directory using the example below. The validate method will return the validated data or will throw a [Zod Error](https://github.com/colinhacks/zod/blob/master/ERROR_HANDLING.md). You can use the package `zod-validation-error` to format the error for the user.
17
+
18
+ Example :
19
+
20
+ ```js
21
+ import { readFile } from 'fs/promises'
22
+ import glob from 'glob'
23
+ import { fromZodError } from 'zod-validation-error'
24
+ import { validate } from '@deconz-community/ddf-validator'
25
+
26
+ (async () => {
27
+ const jsonfiles = await glob('devices/**/*.json', { ignore: '**/generic/**' })
28
+ jsonfiles.forEach((filePath) => {
29
+ const data = await readFile(filePath, 'utf-8')
30
+ const decoded = JSON.parse(data)
31
+ try {
32
+ const result = validate(decoded)
33
+ console.log(result)
34
+ }
35
+ catch (error) {
36
+ throw new Error(fromZodError(error).message)
37
+ }
38
+ })
39
+ })()
40
+ ```
41
+
42
+ ## API
43
+
44
+ ### validate
45
+
46
+ Main function to validate the DDF data object.
47
+
48
+ #### Arguments
49
+ - `data` - object; The DDF data parsed from JSON (required)
50
+
51
+ #### Example
52
+
53
+ ```typescript
54
+ import { validate } from '@deconz-community/ddf-validator'
55
+ import { fromZodError } from 'zod-validation-error'
56
+
57
+ const decoded = JSON.parse("{...}")
58
+
59
+ try {
60
+ const result = validate(decoded)
61
+ console.log(result) // DDF type
62
+ }
63
+ catch (error) {
64
+ throw new Error(fromZodError(error).message)
65
+ }
66
+ ```
67
+
68
+ ### Type definition
69
+
70
+ ### DDF
71
+
72
+ The type definition of a valid DDF file.
73
+
74
+ #### Example
75
+
76
+ ```typescript
77
+ import type { DDF } from '@deconz-community/ddf-validator'
78
+
79
+ const data = {} as DDF
80
+ ```
@@ -0,0 +1 @@
1
+ {"$ref":"#/definitions/DDF","definitions":{"DDF":{"anyOf":[{"type":"object","properties":{"$schema":{"type":"string"},"schema":{"type":"string","const":"devcap1.schema.json"},"doc:path":{"type":"string"},"doc:hdr":{"type":"string"},"md:known_issues":{"type":"array","items":{"type":"string"}},"manufacturername":{"anyOf":[{"type":"string"},{"type":"array","items":{"type":"string"}}]},"modelid":{"anyOf":[{"type":"string"},{"type":"array","items":{"type":"string"}}]},"vendor":{"type":"string"},"comment":{"type":"string"},"matchexpr":{"type":"string"},"path":{"type":"string"},"product":{"type":"string"},"sleeper":{"type":"boolean"},"supportsMgmtBind":{"type":"boolean"},"status":{"type":"string","enum":["Draft","Bronze","Silver","Gold"],"description":"The code quality of the DDF file."},"subdevices":{"type":"array","items":{"type":"object","properties":{"type":{"type":"string","enum":["$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"]},"restapi":{"type":"string","enum":["/lights","/sensors"]},"uuid":{"anyOf":[{"type":"array","minItems":2,"maxItems":2,"items":[{"type":"string","const":"$address.ext"},{"type":"string","minLength":4,"maxLength":4}]},{"type":"array","minItems":3,"maxItems":3,"items":[{"type":"string","const":"$address.ext"},{"type":"string","minLength":4,"maxLength":4},{"type":"string","minLength":6,"maxLength":6}]}]},"fingerprint":{"type":"object","properties":{"profile":{"type":"string","minLength":6,"maxLength":6},"device":{"type":"string","minLength":6,"maxLength":6},"endpoint":{"anyOf":[{"type":"string","minLength":4,"maxLength":4},{"type":"number","minimum":0,"maximum":255}]},"in":{"type":"array","items":{"type":"string","minLength":6,"maxLength":6}},"out":{"type":"array","items":{"type":"string","minLength":6,"maxLength":6}}},"required":["profile","device","endpoint"],"additionalProperties":false},"meta":{"type":"object","properties":{"values":{},"group.endpoints":{"type":"array","items":{"type":"number"}}},"additionalProperties":false},"buttons":{},"buttonevents":{},"items":{"type":"array","items":{"type":"object","properties":{"name":{"type":"string"},"description":{"type":"string"},"comment":{"type":"string"},"public":{"type":"boolean"},"static":{"type":["string","number","boolean"]},"range":{"type":"array","minItems":2,"maxItems":2,"items":[{"type":"number"},{"type":"number"}]},"deprecated":{"type":"string"},"access":{"type":"string","const":"R"},"read":{"anyOf":[{"type":"object","properties":{"fn":{"type":"string","const":"none"}},"required":["fn"],"additionalProperties":false},{"type":"object","properties":{"fn":{"not":{}},"at":{"anyOf":[{"type":"string","minLength":6,"maxLength":6},{"type":"array","items":{"type":"string","minLength":6,"maxLength":6}}]},"cl":{"type":"string","minLength":6,"maxLength":6},"ep":{"anyOf":[{"type":"string","minLength":4,"maxLength":4},{"type":"number","minimum":0,"maximum":255}]},"mf":{"type":"string","minLength":6,"maxLength":6},"eval":{"type":"string"}},"required":["cl"],"additionalProperties":false},{"type":"object","properties":{"fn":{"type":"string","const":"zcl"},"at":{"anyOf":[{"type":"string","minLength":6,"maxLength":6},{"type":"array","items":{"type":"string","minLength":6,"maxLength":6}}]},"cl":{"type":"string","minLength":6,"maxLength":6},"ep":{"anyOf":[{"type":"string","minLength":4,"maxLength":4},{"type":"number","minimum":0,"maximum":255}]},"mf":{"type":"string","minLength":6,"maxLength":6},"eval":{"type":"string"}},"required":["fn","cl"],"additionalProperties":false},{"type":"object","properties":{"fn":{"type":"string","const":"tuya"}},"required":["fn"],"additionalProperties":false}]},"parse":{"anyOf":[{"type":"object","properties":{"fn":{"not":{}},"at":{"type":"string","minLength":6,"maxLength":6},"cl":{"type":"string","minLength":6,"maxLength":6},"ep":{"anyOf":[{"type":"string","minLength":4,"maxLength":4},{"type":"number","minimum":0,"maximum":255}]},"cmd":{"type":"string","minLength":4,"maxLength":4},"mf":{"type":"string","minLength":6,"maxLength":6},"eval":{"type":"string"},"script":{"type":"string"}},"required":["cl"],"additionalProperties":false},{"type":"object","properties":{"fn":{"type":"string","const":"zcl"},"at":{"type":"string","minLength":6,"maxLength":6},"cl":{"type":"string","minLength":6,"maxLength":6},"ep":{"anyOf":[{"type":"string","minLength":4,"maxLength":4},{"type":"number","minimum":0,"maximum":255}]},"cmd":{"type":"string","minLength":4,"maxLength":4},"mf":{"type":"string","minLength":6,"maxLength":6},"eval":{"type":"string"},"script":{"type":"string"}},"required":["fn","cl"],"additionalProperties":false},{"type":"object","properties":{"fn":{"type":"string","const":"ias:zonestatus"},"mask":{"type":"string","enum":["alarm1","alarm2"]}},"required":["fn","mask"],"additionalProperties":false},{"type":"object","properties":{"fn":{"type":"string","const":"numtostr"},"srcitem":{"type":"string","enum":["state/airqualityppb","state/pm2_5"]},"op":{"type":"string","const":"le"},"to":{}},"required":["fn","srcitem","op","to"],"additionalProperties":false},{"type":"object","properties":{"fn":{"type":"string","const":"xiaomi:special"},"ep":{"anyOf":[{"type":"string","minLength":4,"maxLength":4},{"type":"number","minimum":0,"maximum":255}]},"at":{"type":"string","minLength":6,"maxLength":6},"idx":{"type":"string","minLength":4,"maxLength":4},"eval":{"type":"string"},"script":{"type":"string"}},"required":["fn","idx"],"additionalProperties":false},{"type":"object","properties":{"fn":{"type":"string","const":"tuya"},"dpid":{"type":"number"},"eval":{"type":"string"},"script":{"type":"string"}},"required":["fn","dpid"],"additionalProperties":false}]},"write":{"anyOf":[{"type":"object","properties":{"fn":{"type":"string","const":"none"}},"required":["fn"],"additionalProperties":false},{"type":"object","properties":{"fn":{"not":{}},"at":{"anyOf":[{"type":"string","minLength":6,"maxLength":6},{"type":"array","items":{"type":"string","minLength":6,"maxLength":6}}]},"state.timeout":{"type":"number"},"change.timeout":{"type":"number"},"cl":{"type":"string","minLength":6,"maxLength":6},"dt":{"type":"string","minLength":4,"maxLength":4},"ep":{"anyOf":[{"type":"string","minLength":4,"maxLength":4},{"type":"number","minimum":0,"maximum":255}]},"mf":{"type":"string","minLength":6,"maxLength":6},"eval":{"type":"string"},"script":{"type":"string"}},"required":["cl","dt"],"additionalProperties":false},{"type":"object","properties":{"fn":{"type":"string","const":"zcl"},"at":{"anyOf":[{"type":"string","minLength":6,"maxLength":6},{"type":"array","items":{"type":"string","minLength":6,"maxLength":6}}]},"state.timeout":{"type":"number"},"change.timeout":{"type":"number"},"cl":{"type":"string","minLength":6,"maxLength":6},"dt":{"type":"string","minLength":4,"maxLength":4},"ep":{"anyOf":[{"type":"string","minLength":4,"maxLength":4},{"type":"number","minimum":0,"maximum":255}]},"mf":{"type":"string","minLength":6,"maxLength":6},"eval":{"type":"string"},"script":{"type":"string"}},"required":["fn","cl","dt"],"additionalProperties":false},{"type":"object","properties":{"fn":{"type":"string","const":"tuya"},"dpid":{"type":"number"},"dt":{"type":"string","minLength":4,"maxLength":4},"eval":{"type":"string"},"script":{"type":"string"}},"required":["fn","dpid","dt"],"additionalProperties":false}]},"awake":{"type":"boolean"},"default":{},"values":{},"refresh.interval":{"type":"number"}},"required":["name"],"additionalProperties":false}},"example":{}},"required":["type","restapi","uuid","items"],"additionalProperties":false}},"bindings":{"type":"array","items":{"anyOf":[{"type":"object","properties":{"bind":{"type":"string","const":"unicast"},"src.ep":{"anyOf":[{"type":"string","minLength":4,"maxLength":4},{"type":"number","minimum":0,"maximum":255}]},"dst.ep":{"anyOf":[{"type":"string","minLength":4,"maxLength":4},{"type":"number","minimum":0,"maximum":255}]},"cl":{"type":"string","minLength":6,"maxLength":6},"report":{"type":"array","items":{"type":"object","properties":{"at":{"type":"string","minLength":6,"maxLength":6},"dt":{"type":"string","minLength":4,"maxLength":4},"mf":{"type":"string","minLength":6,"maxLength":6},"min":{"type":"number"},"max":{"type":"number"},"change":{"type":["string","number"]}},"required":["at","dt","min","max"],"additionalProperties":false}}},"required":["bind","src.ep","cl"],"additionalProperties":false},{"type":"object","properties":{"bind":{"type":"string","const":"groupcast"},"src.ep":{"anyOf":[{"type":"string","minLength":4,"maxLength":4},{"type":"number","minimum":0,"maximum":255}]},"cl":{"type":"string","minLength":6,"maxLength":6},"config.group":{"type":"number"}},"required":["bind","src.ep","cl","config.group"],"additionalProperties":false}]}}},"required":["schema","manufacturername","modelid","status","subdevices"],"additionalProperties":false}]}},"$schema":"http://json-schema.org/draft-07/schema#"}
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("zod"),s=["$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 p(){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 c(){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 l=n[a],z=n[a+1];if(typeof l!="number"||typeof z!="string")return!1}return!0},"The value must be an array with an even number of values and alternating between number and string.")}function u(n){return m().parse(n)}function m(){return t.z.discriminatedUnion("schema",[d().innerType()])}function d(){return t.z.strictObject({$schema:t.z.optional(t.z.string()),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"]).describe("The code quality of the DDF file."),subdevices:t.z.array(E()),bindings:t.z.optional(t.z.array(b()))}).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 E(){return t.z.strictObject({type:t.z.enum(s),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(T()),example:t.z.optional(t.z.unknown())})}function T(){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(p()),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:c()}),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 b(){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.validate=u;
@@ -0,0 +1,174 @@
1
+
2
+ export type DDF = {
3
+ $schema?: string | undefined;
4
+ schema: "devcap1.schema.json";
5
+ "doc:path"?: string | undefined;
6
+ "doc:hdr"?: string | undefined;
7
+ "md:known_issues"?: string[] | undefined;
8
+ manufacturername: string | string[];
9
+ modelid: string | string[];
10
+ vendor?: string | undefined;
11
+ comment?: string | undefined;
12
+ matchexpr?: string | undefined;
13
+ path?: string | undefined;
14
+ product?: string | undefined;
15
+ sleeper?: boolean | undefined;
16
+ supportsMgmtBind?: boolean | undefined;
17
+ /** The code quality of the DDF file. */
18
+ status: "Draft" | "Bronze" | "Silver" | "Gold";
19
+ subdevices: {
20
+ type: "$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";
21
+ restapi: "/lights" | "/sensors";
22
+ uuid: [
23
+ "$address.ext",
24
+ string
25
+ ] | [
26
+ "$address.ext",
27
+ string,
28
+ string
29
+ ];
30
+ fingerprint?: {
31
+ profile: string;
32
+ device: string;
33
+ endpoint: string | number;
34
+ in?: string[] | undefined;
35
+ out?: string[] | undefined;
36
+ } | undefined;
37
+ meta?: {
38
+ values?: any;
39
+ "group.endpoints"?: number[] | undefined;
40
+ } | undefined;
41
+ buttons?: any | undefined;
42
+ buttonevents?: any | undefined;
43
+ items: {
44
+ name: string;
45
+ description?: string | undefined;
46
+ comment?: string | undefined;
47
+ public?: boolean | undefined;
48
+ static?: (string | number | boolean) | undefined;
49
+ range?: [
50
+ number,
51
+ number
52
+ ] | undefined;
53
+ deprecated?: string | undefined;
54
+ access?: "R" | undefined;
55
+ read?: ({
56
+ fn: "none";
57
+ } | {
58
+ fn?: undefined;
59
+ at?: (string | string[]) | undefined;
60
+ cl: string;
61
+ ep?: (string | number) | undefined;
62
+ mf?: string | undefined;
63
+ eval?: string | undefined;
64
+ } | {
65
+ fn: "zcl";
66
+ at?: (string | string[]) | undefined;
67
+ cl: string;
68
+ ep?: (string | number) | undefined;
69
+ mf?: string | undefined;
70
+ eval?: string | undefined;
71
+ } | {
72
+ fn: "tuya";
73
+ }) | undefined;
74
+ parse?: ({
75
+ fn?: undefined;
76
+ at?: string | undefined;
77
+ cl: string;
78
+ ep?: (string | number) | undefined;
79
+ cmd?: string | undefined;
80
+ mf?: string | undefined;
81
+ eval?: string | undefined;
82
+ script?: string | undefined;
83
+ } | {
84
+ fn: "zcl";
85
+ at?: string | undefined;
86
+ cl: string;
87
+ ep?: (string | number) | undefined;
88
+ cmd?: string | undefined;
89
+ mf?: string | undefined;
90
+ eval?: string | undefined;
91
+ script?: string | undefined;
92
+ } | {
93
+ fn: "ias:zonestatus";
94
+ mask: "alarm1" | "alarm2";
95
+ } | {
96
+ fn: "numtostr";
97
+ srcitem: "state/airqualityppb" | "state/pm2_5";
98
+ op: "le";
99
+ to: any;
100
+ } | {
101
+ fn: "xiaomi:special";
102
+ ep?: (string | number) | undefined;
103
+ at?: string | undefined;
104
+ idx: string;
105
+ eval?: string | undefined;
106
+ script?: string | undefined;
107
+ } | {
108
+ fn: "tuya";
109
+ dpid: number;
110
+ eval?: string | undefined;
111
+ script?: string | undefined;
112
+ }) | undefined;
113
+ write?: ({
114
+ fn: "none";
115
+ } | {
116
+ fn?: undefined;
117
+ at?: (string | string[]) | undefined;
118
+ "state.timeout"?: number | undefined;
119
+ "change.timeout"?: number | undefined;
120
+ cl: string;
121
+ dt: string;
122
+ ep?: (string | number) | undefined;
123
+ mf?: string | undefined;
124
+ eval?: string | undefined;
125
+ script?: string | undefined;
126
+ } | {
127
+ fn: "zcl";
128
+ at?: (string | string[]) | undefined;
129
+ "state.timeout"?: number | undefined;
130
+ "change.timeout"?: number | undefined;
131
+ cl: string;
132
+ dt: string;
133
+ ep?: (string | number) | undefined;
134
+ mf?: string | undefined;
135
+ eval?: string | undefined;
136
+ script?: string | undefined;
137
+ } | {
138
+ fn: "tuya";
139
+ dpid: number;
140
+ dt: string;
141
+ eval?: string | undefined;
142
+ script?: string | undefined;
143
+ }) | undefined;
144
+ awake?: boolean | undefined;
145
+ default?: unknown | undefined;
146
+ values?: unknown | undefined;
147
+ "refresh.interval"?: number | undefined;
148
+ }[];
149
+ example?: unknown | undefined;
150
+ }[];
151
+ bindings?: ({
152
+ bind: "unicast";
153
+ "src.ep": string | number;
154
+ "dst.ep"?: (string | number) | undefined;
155
+ cl: string;
156
+ report?: {
157
+ at: string;
158
+ dt: string;
159
+ mf?: string | undefined;
160
+ min: number;
161
+ max: number;
162
+ change?: (string | number) | undefined;
163
+ }[] | undefined;
164
+ } | {
165
+ bind: "groupcast";
166
+ "src.ep": string | number;
167
+ cl: string;
168
+ "config.group": number;
169
+ })[] | undefined;
170
+ };
171
+
172
+ export declare function validate(data: unknown): DDF
173
+
174
+ export {};
@@ -0,0 +1,345 @@
1
+ import { z as t } from "zod";
2
+ const p = [
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 c() {
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 u() {
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 l = e[a], s = e[a + 1];
104
+ if (typeof l != "number" || typeof s != "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 m().parse(e);
112
+ }
113
+ function m() {
114
+ return t.discriminatedUnion("schema", [
115
+ E().innerType()
116
+ ]);
117
+ }
118
+ function E() {
119
+ return t.strictObject({
120
+ $schema: t.optional(t.string()),
121
+ schema: t.literal("devcap1.schema.json"),
122
+ "doc:path": t.optional(t.string()),
123
+ "doc:hdr": t.optional(t.string()),
124
+ "md:known_issues": t.optional(t.array(t.string())),
125
+ manufacturername: t.string().or(t.array(t.string())),
126
+ modelid: t.string().or(t.array(t.string())),
127
+ vendor: t.optional(t.string()),
128
+ comment: t.optional(t.string()),
129
+ matchexpr: t.optional(o()),
130
+ path: t.optional(r()),
131
+ product: t.optional(t.string()),
132
+ sleeper: t.optional(t.boolean()),
133
+ supportsMgmtBind: t.optional(t.boolean()),
134
+ status: t.enum(["Draft", "Bronze", "Silver", "Gold"]).describe("The code quality of the DDF file."),
135
+ subdevices: t.array(d()),
136
+ bindings: t.optional(t.array(_()))
137
+ }).refine((e) => typeof e.manufacturername == "string" && typeof e.modelid == "string" || Array.isArray(e.manufacturername) && Array.isArray(e.modelid) && e.manufacturername.length === e.modelid.length, {
138
+ message: "manufacturername and modelid should be both strings or arrays with the same length.",
139
+ path: ["manufacturername", "modelid"]
140
+ });
141
+ }
142
+ function d() {
143
+ return t.strictObject({
144
+ type: t.enum(p),
145
+ restapi: t.enum(["/lights", "/sensors"]),
146
+ uuid: t.union([
147
+ t.tuple([
148
+ t.literal("$address.ext"),
149
+ n(2)
150
+ ]),
151
+ t.tuple([
152
+ t.literal("$address.ext"),
153
+ n(2),
154
+ n(4)
155
+ ])
156
+ ]),
157
+ fingerprint: t.optional(t.strictObject({
158
+ profile: n(4),
159
+ device: n(4),
160
+ endpoint: i(),
161
+ in: t.optional(t.array(n(4))),
162
+ out: t.optional(t.array(n(4)))
163
+ })),
164
+ meta: t.optional(t.strictObject({
165
+ // TODO validate this
166
+ values: t.any(),
167
+ "group.endpoints": t.optional(t.array(t.number()))
168
+ })),
169
+ // TODO validate this
170
+ buttons: t.optional(t.any()),
171
+ // TODO validate this
172
+ buttonevents: t.optional(t.any()),
173
+ items: t.array(T()),
174
+ example: t.optional(t.unknown())
175
+ });
176
+ }
177
+ function T() {
178
+ return t.strictObject({
179
+ name: t.string(),
180
+ description: t.optional(t.string()),
181
+ comment: t.optional(t.string()),
182
+ public: t.optional(t.boolean()),
183
+ static: t.optional(t.union([t.string(), t.number(), t.boolean()])),
184
+ range: t.optional(t.tuple([t.number(), t.number()])),
185
+ deprecated: t.optional(c()),
186
+ access: t.optional(t.literal("R")),
187
+ read: t.optional(
188
+ t.discriminatedUnion("fn", [
189
+ t.strictObject({
190
+ fn: t.literal("none")
191
+ }),
192
+ t.strictObject({
193
+ fn: t.undefined(),
194
+ at: t.optional(n(4).or(t.array(n(4)))),
195
+ cl: n(4),
196
+ ep: t.optional(i()),
197
+ mf: t.optional(n(4)),
198
+ eval: t.optional(o())
199
+ }),
200
+ t.strictObject({
201
+ fn: t.literal("zcl"),
202
+ at: t.optional(n(4).or(t.array(n(4)))),
203
+ cl: n(4),
204
+ ep: t.optional(i()),
205
+ mf: t.optional(n(4)),
206
+ eval: t.optional(o())
207
+ }),
208
+ t.strictObject({
209
+ fn: t.literal("tuya")
210
+ })
211
+ ])
212
+ ),
213
+ parse: t.optional(
214
+ t.discriminatedUnion("fn", [
215
+ t.strictObject({
216
+ fn: t.undefined(),
217
+ at: t.optional(n(4)),
218
+ cl: n(4),
219
+ ep: t.optional(i()),
220
+ cmd: t.optional(n(2)),
221
+ mf: t.optional(n(4)),
222
+ eval: t.optional(o()),
223
+ script: t.optional(r())
224
+ }).refine((e) => !("eval" in e && "script" in e), {
225
+ message: "eval and script should not both be present"
226
+ }).innerType(),
227
+ t.strictObject({
228
+ fn: t.literal("zcl"),
229
+ at: t.optional(n(4)),
230
+ cl: n(4),
231
+ ep: t.optional(i()),
232
+ cmd: t.optional(n(2)),
233
+ mf: t.optional(n(4)),
234
+ eval: t.optional(o()),
235
+ script: t.optional(r())
236
+ }).refine((e) => !("eval" in e && "script" in e), {
237
+ message: "eval and script should not both be present"
238
+ }).innerType(),
239
+ t.strictObject({
240
+ fn: t.literal("ias:zonestatus"),
241
+ mask: t.enum(["alarm1", "alarm2"])
242
+ }),
243
+ t.strictObject({
244
+ fn: t.literal("numtostr"),
245
+ srcitem: t.enum(["state/airqualityppb", "state/pm2_5"]),
246
+ op: t.literal("le"),
247
+ to: u()
248
+ }),
249
+ t.strictObject({
250
+ fn: t.literal("xiaomi:special"),
251
+ ep: t.optional(i()),
252
+ at: t.optional(n(4)),
253
+ idx: n(2),
254
+ eval: t.optional(o()),
255
+ script: t.optional(r())
256
+ }).refine((e) => !("eval" in e && "script" in e), {
257
+ message: "eval and script should not both be present"
258
+ }).innerType(),
259
+ t.strictObject({
260
+ fn: t.literal("tuya"),
261
+ dpid: t.number(),
262
+ eval: t.optional(o()),
263
+ script: t.optional(r())
264
+ }).refine((e) => !("eval" in e && "script" in e), {
265
+ message: "eval and script should not both be present"
266
+ }).innerType()
267
+ ])
268
+ ),
269
+ write: t.optional(
270
+ t.discriminatedUnion("fn", [
271
+ t.strictObject({
272
+ fn: t.literal("none")
273
+ }),
274
+ t.strictObject({
275
+ fn: t.undefined(),
276
+ at: t.optional(n(4).or(t.array(n(4)))),
277
+ "state.timeout": t.optional(t.number()),
278
+ "change.timeout": t.optional(t.number()),
279
+ cl: n(4),
280
+ dt: n(2),
281
+ ep: t.optional(i()),
282
+ mf: t.optional(n(4)),
283
+ eval: t.optional(o()),
284
+ script: t.optional(r())
285
+ }).refine((e) => !("eval" in e && "script" in e), {
286
+ message: "eval and script should not both be present"
287
+ }).innerType(),
288
+ t.strictObject({
289
+ fn: t.literal("zcl"),
290
+ at: t.optional(n(4).or(t.array(n(4)))),
291
+ "state.timeout": t.optional(t.number()),
292
+ "change.timeout": t.optional(t.number()),
293
+ cl: n(4),
294
+ dt: n(2),
295
+ ep: t.optional(i()),
296
+ mf: t.optional(n(4)),
297
+ eval: t.optional(o()),
298
+ script: t.optional(r())
299
+ }).refine((e) => !("eval" in e && "script" in e), {
300
+ message: "eval and script should not both be present"
301
+ }).innerType(),
302
+ t.strictObject({
303
+ fn: t.literal("tuya"),
304
+ dpid: t.number(),
305
+ dt: n(2),
306
+ eval: t.optional(o()),
307
+ script: t.optional(r())
308
+ }).refine((e) => !("eval" in e && "script" in e), {
309
+ message: "eval and script should not both be present"
310
+ }).innerType()
311
+ ])
312
+ ),
313
+ awake: t.optional(t.boolean()),
314
+ default: t.optional(t.unknown()),
315
+ values: t.optional(t.unknown()),
316
+ "refresh.interval": t.optional(t.number())
317
+ });
318
+ }
319
+ function _() {
320
+ return t.discriminatedUnion("bind", [
321
+ t.strictObject({
322
+ bind: t.literal("unicast"),
323
+ "src.ep": i(),
324
+ "dst.ep": t.optional(i()),
325
+ cl: n(4),
326
+ report: t.optional(t.array(t.strictObject({
327
+ at: n(4),
328
+ dt: n(2),
329
+ mf: t.optional(n(4)),
330
+ min: t.number(),
331
+ max: t.number(),
332
+ change: t.optional(n().or(t.number()))
333
+ })))
334
+ }),
335
+ t.strictObject({
336
+ bind: t.literal("groupcast"),
337
+ "src.ep": i(),
338
+ cl: n(4),
339
+ "config.group": t.number()
340
+ })
341
+ ]);
342
+ }
343
+ export {
344
+ b as validate
345
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deconz-community/ddf-validator",
3
- "version": "0.2.0",
3
+ "version": "1.0.0",
4
4
  "description": "Validating DDF files for deconz",
5
5
  "keywords": [
6
6
  "deconz",
@@ -35,10 +35,14 @@
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",
40
+ "./dist/ddf-validator.d.ts",
41
+ "./dist/ddf-schema.json"
39
42
  ],
40
43
  "main": "./dist/ddf-validator.cjs",
41
44
  "module": "./dist/ddf-validator.mjs",
45
+ "types": "./dist/ddf-validator.d.ts",
42
46
  "exports": {
43
47
  ".": {
44
48
  "require": "./dist/ddf-validator.cjs",
@@ -52,6 +56,7 @@
52
56
  "@typescript-eslint/eslint-plugin": "^5.51.0",
53
57
  "@typescript-eslint/parser": "^5.51.0",
54
58
  "degit": "^2.8.4",
59
+ "dts-bundle-generator": "^7.2.0",
55
60
  "eslint": "^8.33.0",
56
61
  "eslint-config-prettier": "^8.6.0",
57
62
  "eslint-plugin-prettier": "^4.2.1",
@@ -67,20 +72,22 @@
67
72
  "typescript": "^4.9.5",
68
73
  "vite": "^4.1.1",
69
74
  "vitest": "^0.28.4",
75
+ "zod-to-json-schema": "^3.20.4",
76
+ "zod-to-ts": "^1.1.2",
70
77
  "zod-validation-error": "^1.0.1"
71
78
  },
72
79
  "dependencies": {
73
80
  "zod": "^3.21.4"
74
81
  },
75
82
  "scripts": {
76
- "build": "vite build",
83
+ "build": "pnpm run build:vite && pnpm run build:dts",
77
84
  "build:cleanup": "rimraf ./dist",
78
85
  "build:vite": "vite build",
79
- "build:dts": "dts-bundle-generator --config ./dts-bundle-generator.config.ts",
86
+ "build:dts": "ts-node ./build-dts.ts",
80
87
  "lint": "eslint",
81
88
  "test": "vitest run",
82
89
  "test:watch": "vitest",
83
- "test:download-sample": "rimraf ./test-data && degit dresden-elektronik/deconz-rest-plugin ./test-data",
90
+ "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
91
  "up": "taze major -I"
85
92
  }
86
93
  }