@deconz-community/ddf-validator 0.2.1 → 1.2.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},"cppsrc":{"type":"string"},"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},"cppsrc":{"type":"string"},"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#"}
@@ -1 +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;
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 n(e=void 0){return e===void 0?t.z.string():t.z.string().length(2+e)}function o(){return t.z.string()}function p(){return t.z.string()}function i(){return t.z.union([n(2),t.z.number().min(0).max(255)])}function r(){return t.z.string()}function c(){return t.z.custom(e=>{if(!Array.isArray(e)||e.length%2!==0)return!1;for(let a=0;a<e.length;a+=2){const l=e[a],z=e[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(e){return m().parse(e)}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(e=>typeof e.manufacturername=="string"&&typeof e.modelid=="string"||Array.isArray(e.manufacturername)&&Array.isArray(e.modelid)&&e.manufacturername.length===e.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"),n(2)]),t.z.tuple([t.z.literal("$address.ext"),n(2),n(4)])]),fingerprint:t.z.optional(t.z.strictObject({profile:n(4),device:n(4),endpoint:i(),in:t.z.optional(t.z.array(n(4))),out:t.z.optional(t.z.array(n(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(n(4).or(t.z.array(n(4)))),cl:n(4),ep:t.z.optional(i()),mf:t.z.optional(n(4)),eval:t.z.optional(o())}),t.z.strictObject({fn:t.z.literal("zcl"),at:t.z.optional(n(4).or(t.z.array(n(4)))),cl:n(4),ep:t.z.optional(i()),mf:t.z.optional(n(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(n(4)),cl:n(4),cppsrc:t.z.optional(t.z.string()),ep:t.z.optional(i()),cmd:t.z.optional(n(2)),mf:t.z.optional(n(4)),eval:t.z.optional(o()),script:t.z.optional(r())}).refine(e=>!("eval"in e&&"script"in e),{message:"eval and script should not both be present"}).innerType(),t.z.strictObject({fn:t.z.literal("zcl"),at:t.z.optional(n(4)),cl:n(4),cppsrc:t.z.optional(t.z.string()),ep:t.z.optional(i()),cmd:t.z.optional(n(2)),mf:t.z.optional(n(4)),eval:t.z.optional(o()),script:t.z.optional(r())}).refine(e=>!("eval"in e&&"script"in e),{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(n(4)),idx:n(2),eval:t.z.optional(o()),script:t.z.optional(r())}).refine(e=>!("eval"in e&&"script"in e),{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(e=>!("eval"in e&&"script"in e),{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(n(4).or(t.z.array(n(4)))),"state.timeout":t.z.optional(t.z.number()),"change.timeout":t.z.optional(t.z.number()),cl:n(4),dt:n(2),ep:t.z.optional(i()),mf:t.z.optional(n(4)),eval:t.z.optional(o()),script:t.z.optional(r())}).refine(e=>!("eval"in e&&"script"in e),{message:"eval and script should not both be present"}).innerType(),t.z.strictObject({fn:t.z.literal("zcl"),at:t.z.optional(n(4).or(t.z.array(n(4)))),"state.timeout":t.z.optional(t.z.number()),"change.timeout":t.z.optional(t.z.number()),cl:n(4),dt:n(2),ep:t.z.optional(i()),mf:t.z.optional(n(4)),eval:t.z.optional(o()),script:t.z.optional(r())}).refine(e=>!("eval"in e&&"script"in e),{message:"eval and script should not both be present"}).innerType(),t.z.strictObject({fn:t.z.literal("tuya"),dpid:t.z.number(),dt:n(2),eval:t.z.optional(o()),script:t.z.optional(r())}).refine(e=>!("eval"in e&&"script"in e),{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:n(4),report:t.z.optional(t.z.array(t.z.strictObject({at:n(4),dt:n(2),mf:t.z.optional(n(4)),min:t.z.number(),max:t.z.number(),change:t.z.optional(n().or(t.z.number()))})))}),t.z.strictObject({bind:t.z.literal("groupcast"),"src.ep":i(),cl:n(4),"config.group":t.z.number()})])}exports.validate=u;
@@ -0,0 +1,176 @@
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
+ cppsrc?: string | undefined;
79
+ ep?: (string | number) | undefined;
80
+ cmd?: string | undefined;
81
+ mf?: string | undefined;
82
+ eval?: string | undefined;
83
+ script?: string | undefined;
84
+ } | {
85
+ fn: "zcl";
86
+ at?: string | undefined;
87
+ cl: string;
88
+ cppsrc?: string | undefined;
89
+ ep?: (string | number) | undefined;
90
+ cmd?: string | undefined;
91
+ mf?: string | undefined;
92
+ eval?: string | undefined;
93
+ script?: string | undefined;
94
+ } | {
95
+ fn: "ias:zonestatus";
96
+ mask: "alarm1" | "alarm2";
97
+ } | {
98
+ fn: "numtostr";
99
+ srcitem: "state/airqualityppb" | "state/pm2_5";
100
+ op: "le";
101
+ to: any;
102
+ } | {
103
+ fn: "xiaomi:special";
104
+ ep?: (string | number) | undefined;
105
+ at?: string | undefined;
106
+ idx: string;
107
+ eval?: string | undefined;
108
+ script?: string | undefined;
109
+ } | {
110
+ fn: "tuya";
111
+ dpid: number;
112
+ eval?: string | undefined;
113
+ script?: string | undefined;
114
+ }) | undefined;
115
+ write?: ({
116
+ fn: "none";
117
+ } | {
118
+ fn?: undefined;
119
+ at?: (string | string[]) | undefined;
120
+ "state.timeout"?: number | undefined;
121
+ "change.timeout"?: number | undefined;
122
+ cl: string;
123
+ dt: string;
124
+ ep?: (string | number) | undefined;
125
+ mf?: string | undefined;
126
+ eval?: string | undefined;
127
+ script?: string | undefined;
128
+ } | {
129
+ fn: "zcl";
130
+ at?: (string | string[]) | undefined;
131
+ "state.timeout"?: number | undefined;
132
+ "change.timeout"?: number | undefined;
133
+ cl: string;
134
+ dt: string;
135
+ ep?: (string | number) | undefined;
136
+ mf?: string | undefined;
137
+ eval?: string | undefined;
138
+ script?: string | undefined;
139
+ } | {
140
+ fn: "tuya";
141
+ dpid: number;
142
+ dt: string;
143
+ eval?: string | undefined;
144
+ script?: string | undefined;
145
+ }) | undefined;
146
+ awake?: boolean | undefined;
147
+ default?: unknown | undefined;
148
+ values?: unknown | undefined;
149
+ "refresh.interval"?: number | undefined;
150
+ }[];
151
+ example?: unknown | undefined;
152
+ }[];
153
+ bindings?: ({
154
+ bind: "unicast";
155
+ "src.ep": string | number;
156
+ "dst.ep"?: (string | number) | undefined;
157
+ cl: string;
158
+ report?: {
159
+ at: string;
160
+ dt: string;
161
+ mf?: string | undefined;
162
+ min: number;
163
+ max: number;
164
+ change?: (string | number) | undefined;
165
+ }[] | undefined;
166
+ } | {
167
+ bind: "groupcast";
168
+ "src.ep": string | number;
169
+ cl: string;
170
+ "config.group": number;
171
+ })[] | undefined;
172
+ };
173
+
174
+ export declare function validate(data: unknown): DDF
175
+
176
+ export {};
@@ -1,5 +1,5 @@
1
1
  import { z as t } from "zod";
2
- const c = [
2
+ const p = [
3
3
  "$TYPE_AIR_PURIFIER",
4
4
  "$TYPE_AIR_QUALITY_SENSOR",
5
5
  "$TYPE_ALARM_SENSOR",
@@ -83,7 +83,7 @@ function n(e = void 0) {
83
83
  function o() {
84
84
  return t.string();
85
85
  }
86
- function u() {
86
+ function c() {
87
87
  return t.string();
88
88
  }
89
89
  function i() {
@@ -95,28 +95,29 @@ function i() {
95
95
  function r() {
96
96
  return t.string();
97
97
  }
98
- function m() {
98
+ function u() {
99
99
  return t.custom((e) => {
100
100
  if (!Array.isArray(e) || e.length % 2 !== 0)
101
101
  return !1;
102
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")
103
+ const l = e[a], s = e[a + 1];
104
+ if (typeof l != "number" || typeof s != "string")
105
105
  return !1;
106
106
  }
107
107
  return !0;
108
108
  }, "The value must be an array with an even number of values and alternating between number and string.");
109
109
  }
110
110
  function b(e) {
111
- return l().parse(e);
111
+ return m().parse(e);
112
112
  }
113
- function f() {
113
+ function m() {
114
114
  return t.discriminatedUnion("schema", [
115
- l().innerType()
115
+ E().innerType()
116
116
  ]);
117
117
  }
118
- function l() {
118
+ function E() {
119
119
  return t.strictObject({
120
+ $schema: t.optional(t.string()),
120
121
  schema: t.literal("devcap1.schema.json"),
121
122
  "doc:path": t.optional(t.string()),
122
123
  "doc:hdr": t.optional(t.string()),
@@ -130,17 +131,17 @@ function l() {
130
131
  product: t.optional(t.string()),
131
132
  sleeper: t.optional(t.boolean()),
132
133
  supportsMgmtBind: t.optional(t.boolean()),
133
- status: t.enum(["Draft", "Bronze", "Silver", "Gold"]),
134
- subdevices: t.array(E()),
134
+ status: t.enum(["Draft", "Bronze", "Silver", "Gold"]).describe("The code quality of the DDF file."),
135
+ subdevices: t.array(d()),
135
136
  bindings: t.optional(t.array(_()))
136
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, {
137
138
  message: "manufacturername and modelid should be both strings or arrays with the same length.",
138
139
  path: ["manufacturername", "modelid"]
139
140
  });
140
141
  }
141
- function E() {
142
+ function d() {
142
143
  return t.strictObject({
143
- type: t.enum(c),
144
+ type: t.enum(p),
144
145
  restapi: t.enum(["/lights", "/sensors"]),
145
146
  uuid: t.union([
146
147
  t.tuple([
@@ -169,11 +170,11 @@ function E() {
169
170
  buttons: t.optional(t.any()),
170
171
  // TODO validate this
171
172
  buttonevents: t.optional(t.any()),
172
- items: t.array(d()),
173
+ items: t.array(T()),
173
174
  example: t.optional(t.unknown())
174
175
  });
175
176
  }
176
- function d() {
177
+ function T() {
177
178
  return t.strictObject({
178
179
  name: t.string(),
179
180
  description: t.optional(t.string()),
@@ -181,7 +182,7 @@ function d() {
181
182
  public: t.optional(t.boolean()),
182
183
  static: t.optional(t.union([t.string(), t.number(), t.boolean()])),
183
184
  range: t.optional(t.tuple([t.number(), t.number()])),
184
- deprecated: t.optional(u()),
185
+ deprecated: t.optional(c()),
185
186
  access: t.optional(t.literal("R")),
186
187
  read: t.optional(
187
188
  t.discriminatedUnion("fn", [
@@ -215,6 +216,7 @@ function d() {
215
216
  fn: t.undefined(),
216
217
  at: t.optional(n(4)),
217
218
  cl: n(4),
219
+ cppsrc: t.optional(t.string()),
218
220
  ep: t.optional(i()),
219
221
  cmd: t.optional(n(2)),
220
222
  mf: t.optional(n(4)),
@@ -227,6 +229,7 @@ function d() {
227
229
  fn: t.literal("zcl"),
228
230
  at: t.optional(n(4)),
229
231
  cl: n(4),
232
+ cppsrc: t.optional(t.string()),
230
233
  ep: t.optional(i()),
231
234
  cmd: t.optional(n(2)),
232
235
  mf: t.optional(n(4)),
@@ -243,7 +246,7 @@ function d() {
243
246
  fn: t.literal("numtostr"),
244
247
  srcitem: t.enum(["state/airqualityppb", "state/pm2_5"]),
245
248
  op: t.literal("le"),
246
- to: m()
249
+ to: u()
247
250
  }),
248
251
  t.strictObject({
249
252
  fn: t.literal("xiaomi:special"),
@@ -340,10 +343,5 @@ function _() {
340
343
  ]);
341
344
  }
342
345
  export {
343
- l as ddfSchema,
344
- f as mainSchema,
345
- _ as subBindingSchema,
346
- d as subDeviceItemSchema,
347
- E as subDeviceSchema,
348
346
  b as validate
349
347
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deconz-community/ddf-validator",
3
- "version": "0.2.1",
3
+ "version": "1.2.0",
4
4
  "description": "Validating DDF files for deconz",
5
5
  "keywords": [
6
6
  "deconz",
@@ -36,10 +36,13 @@
36
36
  },
37
37
  "files": [
38
38
  "./dist/ddf-validator.cjs",
39
- "./dist/ddf-validator.mjs"
39
+ "./dist/ddf-validator.mjs",
40
+ "./dist/ddf-validator.d.ts",
41
+ "./dist/ddf-schema.json"
40
42
  ],
41
43
  "main": "./dist/ddf-validator.cjs",
42
44
  "module": "./dist/ddf-validator.mjs",
45
+ "types": "./dist/ddf-validator.d.ts",
43
46
  "exports": {
44
47
  ".": {
45
48
  "require": "./dist/ddf-validator.cjs",
@@ -53,6 +56,7 @@
53
56
  "@typescript-eslint/eslint-plugin": "^5.51.0",
54
57
  "@typescript-eslint/parser": "^5.51.0",
55
58
  "degit": "^2.8.4",
59
+ "dts-bundle-generator": "^7.2.0",
56
60
  "eslint": "^8.33.0",
57
61
  "eslint-config-prettier": "^8.6.0",
58
62
  "eslint-plugin-prettier": "^4.2.1",
@@ -68,15 +72,18 @@
68
72
  "typescript": "^4.9.5",
69
73
  "vite": "^4.1.1",
70
74
  "vitest": "^0.28.4",
75
+ "zod-to-json-schema": "^3.20.4",
76
+ "zod-to-ts": "^1.1.2",
71
77
  "zod-validation-error": "^1.0.1"
72
78
  },
73
79
  "dependencies": {
74
80
  "zod": "^3.21.4"
75
81
  },
76
82
  "scripts": {
77
- "build": "vite build",
83
+ "build": "pnpm run build:vite && pnpm run build:dts",
78
84
  "build:cleanup": "rimraf ./dist",
79
85
  "build:vite": "vite build",
86
+ "build:dts": "ts-node ./build-dts.ts",
80
87
  "lint": "eslint",
81
88
  "test": "vitest run",
82
89
  "test:watch": "vitest",