mqtt2matter 0.0.0-stage → 0.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.
Files changed (279) hide show
  1. package/CHANGELOG.md +76 -0
  2. package/LICENSE +202 -0
  3. package/NOTICE +23 -0
  4. package/README.md +172 -2
  5. package/dist/app.d.ts +34 -0
  6. package/dist/app.js +157 -0
  7. package/dist/app.js.map +1 -0
  8. package/dist/commands/import-z2m.d.ts +20 -0
  9. package/dist/commands/import-z2m.js +173 -0
  10. package/dist/commands/import-z2m.js.map +1 -0
  11. package/dist/commands/install.d.ts +41 -0
  12. package/dist/commands/install.js +250 -0
  13. package/dist/commands/install.js.map +1 -0
  14. package/dist/commands/update.d.ts +14 -0
  15. package/dist/commands/update.js +109 -0
  16. package/dist/commands/update.js.map +1 -0
  17. package/dist/config/index.d.ts +2 -0
  18. package/dist/config/index.js +3 -0
  19. package/dist/config/index.js.map +1 -0
  20. package/dist/config/load.d.ts +57 -0
  21. package/dist/config/load.js +137 -0
  22. package/dist/config/load.js.map +1 -0
  23. package/dist/config/schema.d.ts +496 -0
  24. package/dist/config/schema.js +115 -0
  25. package/dist/config/schema.js.map +1 -0
  26. package/dist/engine/payload.d.ts +94 -0
  27. package/dist/engine/payload.js +515 -0
  28. package/dist/engine/payload.js.map +1 -0
  29. package/dist/engine/runtime.d.ts +79 -0
  30. package/dist/engine/runtime.js +438 -0
  31. package/dist/engine/runtime.js.map +1 -0
  32. package/dist/engine/template.d.ts +20 -0
  33. package/dist/engine/template.js +264 -0
  34. package/dist/engine/template.js.map +1 -0
  35. package/dist/engine/units.d.ts +9 -0
  36. package/dist/engine/units.js +42 -0
  37. package/dist/engine/units.js.map +1 -0
  38. package/dist/families/climate.d.ts +11 -0
  39. package/dist/families/climate.js +68 -0
  40. package/dist/families/climate.js.map +1 -0
  41. package/dist/families/color.d.ts +30 -0
  42. package/dist/families/color.js +152 -0
  43. package/dist/families/color.js.map +1 -0
  44. package/dist/families/cover.d.ts +17 -0
  45. package/dist/families/cover.js +308 -0
  46. package/dist/families/cover.js.map +1 -0
  47. package/dist/families/fan.d.ts +16 -0
  48. package/dist/families/fan.js +154 -0
  49. package/dist/families/fan.js.map +1 -0
  50. package/dist/families/index.d.ts +32 -0
  51. package/dist/families/index.js +162 -0
  52. package/dist/families/index.js.map +1 -0
  53. package/dist/families/light.d.ts +36 -0
  54. package/dist/families/light.js +258 -0
  55. package/dist/families/light.js.map +1 -0
  56. package/dist/families/lock.d.ts +10 -0
  57. package/dist/families/lock.js +31 -0
  58. package/dist/families/lock.js.map +1 -0
  59. package/dist/families/on-off.d.ts +7 -0
  60. package/dist/families/on-off.js +56 -0
  61. package/dist/families/on-off.js.map +1 -0
  62. package/dist/families/power-source.d.ts +12 -0
  63. package/dist/families/power-source.js +60 -0
  64. package/dist/families/power-source.js.map +1 -0
  65. package/dist/families/registry.d.ts +40 -0
  66. package/dist/families/registry.js +72 -0
  67. package/dist/families/registry.js.map +1 -0
  68. package/dist/families/rvc.d.ts +40 -0
  69. package/dist/families/rvc.js +83 -0
  70. package/dist/families/rvc.js.map +1 -0
  71. package/dist/families/switch.d.ts +19 -0
  72. package/dist/families/switch.js +94 -0
  73. package/dist/families/switch.js.map +1 -0
  74. package/dist/importers/actions.d.ts +19 -0
  75. package/dist/importers/actions.js +98 -0
  76. package/dist/importers/actions.js.map +1 -0
  77. package/dist/importers/ha/areas.d.ts +6 -0
  78. package/dist/importers/ha/areas.js +279 -0
  79. package/dist/importers/ha/areas.js.map +1 -0
  80. package/dist/importers/ha/generate.d.ts +51 -0
  81. package/dist/importers/ha/generate.js +1376 -0
  82. package/dist/importers/ha/generate.js.map +1 -0
  83. package/dist/importers/ha/index.d.ts +6 -0
  84. package/dist/importers/ha/index.js +7 -0
  85. package/dist/importers/ha/index.js.map +1 -0
  86. package/dist/importers/ha/source.d.ts +36 -0
  87. package/dist/importers/ha/source.js +95 -0
  88. package/dist/importers/ha/source.js.map +1 -0
  89. package/dist/importers/ha/sync.d.ts +29 -0
  90. package/dist/importers/ha/sync.js +132 -0
  91. package/dist/importers/ha/sync.js.map +1 -0
  92. package/dist/importers/ha/templates.d.ts +18 -0
  93. package/dist/importers/ha/templates.js +285 -0
  94. package/dist/importers/ha/templates.js.map +1 -0
  95. package/dist/importers/ha/types.d.ts +78 -0
  96. package/dist/importers/ha/types.js +479 -0
  97. package/dist/importers/ha/types.js.map +1 -0
  98. package/dist/importers/index.d.ts +5 -0
  99. package/dist/importers/index.js +8 -0
  100. package/dist/importers/index.js.map +1 -0
  101. package/dist/importers/patch.d.ts +50 -0
  102. package/dist/importers/patch.js +224 -0
  103. package/dist/importers/patch.js.map +1 -0
  104. package/dist/importers/sync.d.ts +112 -0
  105. package/dist/importers/sync.js +220 -0
  106. package/dist/importers/sync.js.map +1 -0
  107. package/dist/importers/twins.d.ts +10 -0
  108. package/dist/importers/twins.js +34 -0
  109. package/dist/importers/twins.js.map +1 -0
  110. package/dist/importers/z2m/generate.d.ts +81 -0
  111. package/dist/importers/z2m/generate.js +1171 -0
  112. package/dist/importers/z2m/generate.js.map +1 -0
  113. package/dist/importers/z2m/index.d.ts +5 -0
  114. package/dist/importers/z2m/index.js +6 -0
  115. package/dist/importers/z2m/index.js.map +1 -0
  116. package/dist/importers/z2m/source.d.ts +18 -0
  117. package/dist/importers/z2m/source.js +46 -0
  118. package/dist/importers/z2m/source.js.map +1 -0
  119. package/dist/importers/z2m/sync.d.ts +29 -0
  120. package/dist/importers/z2m/sync.js +92 -0
  121. package/dist/importers/z2m/sync.js.map +1 -0
  122. package/dist/importers/z2m/types.d.ts +72 -0
  123. package/dist/importers/z2m/types.js +46 -0
  124. package/dist/importers/z2m/types.js.map +1 -0
  125. package/dist/index.d.ts +5 -0
  126. package/dist/index.js +7 -0
  127. package/dist/index.js.map +1 -0
  128. package/dist/log.d.ts +17 -0
  129. package/dist/log.js +54 -0
  130. package/dist/log.js.map +1 -0
  131. package/dist/main.d.ts +2 -0
  132. package/dist/main.js +202 -0
  133. package/dist/main.js.map +1 -0
  134. package/dist/matter/bridge.d.ts +113 -0
  135. package/dist/matter/bridge.js +467 -0
  136. package/dist/matter/bridge.js.map +1 -0
  137. package/dist/matter/check.d.ts +11 -0
  138. package/dist/matter/check.js +116 -0
  139. package/dist/matter/check.js.map +1 -0
  140. package/dist/matter/cluster-defaults.d.ts +6 -0
  141. package/dist/matter/cluster-defaults.js +63 -0
  142. package/dist/matter/cluster-defaults.js.map +1 -0
  143. package/dist/matter/commissioning.d.ts +21 -0
  144. package/dist/matter/commissioning.js +88 -0
  145. package/dist/matter/commissioning.js.map +1 -0
  146. package/dist/matter/device-types.d.ts +44 -0
  147. package/dist/matter/device-types.js +230 -0
  148. package/dist/matter/device-types.js.map +1 -0
  149. package/dist/matter/ids.d.ts +31 -0
  150. package/dist/matter/ids.js +83 -0
  151. package/dist/matter/ids.js.map +1 -0
  152. package/dist/matter/index.d.ts +7 -0
  153. package/dist/matter/index.js +8 -0
  154. package/dist/matter/index.js.map +1 -0
  155. package/dist/matter/node-manager.d.ts +39 -0
  156. package/dist/matter/node-manager.js +161 -0
  157. package/dist/matter/node-manager.js.map +1 -0
  158. package/dist/matter/shards.d.ts +26 -0
  159. package/dist/matter/shards.js +93 -0
  160. package/dist/matter/shards.js.map +1 -0
  161. package/dist/model/attribute.d.ts +18 -0
  162. package/dist/model/attribute.js +28 -0
  163. package/dist/model/attribute.js.map +1 -0
  164. package/dist/model/catalog.d.ts +79 -0
  165. package/dist/model/catalog.js +223 -0
  166. package/dist/model/catalog.js.map +1 -0
  167. package/dist/model/index.d.ts +7 -0
  168. package/dist/model/index.js +8 -0
  169. package/dist/model/index.js.map +1 -0
  170. package/dist/model/migrate.d.ts +4 -0
  171. package/dist/model/migrate.js +39 -0
  172. package/dist/model/migrate.js.map +1 -0
  173. package/dist/model/options.d.ts +102 -0
  174. package/dist/model/options.js +88 -0
  175. package/dist/model/options.js.map +1 -0
  176. package/dist/model/presets.d.ts +37 -0
  177. package/dist/model/presets.js +105 -0
  178. package/dist/model/presets.js.map +1 -0
  179. package/dist/model/schema.d.ts +1747 -0
  180. package/dist/model/schema.js +243 -0
  181. package/dist/model/schema.js.map +1 -0
  182. package/dist/model/validate.d.ts +21 -0
  183. package/dist/model/validate.js +484 -0
  184. package/dist/model/validate.js.map +1 -0
  185. package/dist/mqtt/client.d.ts +38 -0
  186. package/dist/mqtt/client.js +94 -0
  187. package/dist/mqtt/client.js.map +1 -0
  188. package/dist/mqtt/index.d.ts +2 -0
  189. package/dist/mqtt/index.js +3 -0
  190. package/dist/mqtt/index.js.map +1 -0
  191. package/dist/mqtt/topic-cache.d.ts +20 -0
  192. package/dist/mqtt/topic-cache.js +58 -0
  193. package/dist/mqtt/topic-cache.js.map +1 -0
  194. package/dist/server/auth.d.ts +59 -0
  195. package/dist/server/auth.js +185 -0
  196. package/dist/server/auth.js.map +1 -0
  197. package/dist/server/catalog.d.ts +52 -0
  198. package/dist/server/catalog.js +96 -0
  199. package/dist/server/catalog.js.map +1 -0
  200. package/dist/server/compact.d.ts +3 -0
  201. package/dist/server/compact.js +105 -0
  202. package/dist/server/compact.js.map +1 -0
  203. package/dist/server/config-store.d.ts +36 -0
  204. package/dist/server/config-store.js +155 -0
  205. package/dist/server/config-store.js.map +1 -0
  206. package/dist/server/events.d.ts +50 -0
  207. package/dist/server/events.js +71 -0
  208. package/dist/server/events.js.map +1 -0
  209. package/dist/server/http.d.ts +27 -0
  210. package/dist/server/http.js +168 -0
  211. package/dist/server/http.js.map +1 -0
  212. package/dist/server/importers.d.ts +40 -0
  213. package/dist/server/importers.js +75 -0
  214. package/dist/server/importers.js.map +1 -0
  215. package/dist/server/index.d.ts +6 -0
  216. package/dist/server/index.js +8 -0
  217. package/dist/server/index.js.map +1 -0
  218. package/dist/server/log-buffer.d.ts +22 -0
  219. package/dist/server/log-buffer.js +55 -0
  220. package/dist/server/log-buffer.js.map +1 -0
  221. package/dist/server/presets.d.ts +17 -0
  222. package/dist/server/presets.js +55 -0
  223. package/dist/server/presets.js.map +1 -0
  224. package/dist/server/preview.d.ts +19 -0
  225. package/dist/server/preview.js +121 -0
  226. package/dist/server/preview.js.map +1 -0
  227. package/dist/server/server.d.ts +107 -0
  228. package/dist/server/server.js +810 -0
  229. package/dist/server/server.js.map +1 -0
  230. package/dist/server/update.d.ts +60 -0
  231. package/dist/server/update.js +191 -0
  232. package/dist/server/update.js.map +1 -0
  233. package/docs/api.md +128 -0
  234. package/docs/architecture.md +121 -0
  235. package/docs/config.md +538 -0
  236. package/docs/importers.md +241 -0
  237. package/example/mqtt2matter.json +276 -0
  238. package/package.json +90 -4
  239. package/presets/mqtt-smarthome/button.json +47 -0
  240. package/presets/mqtt-smarthome/contact.json +37 -0
  241. package/presets/mqtt-smarthome/cover.json +50 -0
  242. package/presets/mqtt-smarthome/dimmer.json +57 -0
  243. package/presets/mqtt-smarthome/humidity.json +38 -0
  244. package/presets/mqtt-smarthome/light.json +47 -0
  245. package/presets/mqtt-smarthome/occupancy.json +46 -0
  246. package/presets/mqtt-smarthome/switch.json +47 -0
  247. package/presets/mqtt-smarthome/temperature.json +38 -0
  248. package/presets/openbeken/color-light.json +64 -0
  249. package/presets/openbeken/ct-light.json +51 -0
  250. package/presets/openbeken/dimmer.json +47 -0
  251. package/presets/openbeken/humidity.json +37 -0
  252. package/presets/openbeken/relay.json +40 -0
  253. package/presets/openbeken/temperature.json +41 -0
  254. package/presets/shelly-gen1/dimmer.json +48 -0
  255. package/presets/shelly-gen1/door-window.json +43 -0
  256. package/presets/shelly-gen1/ht.json +43 -0
  257. package/presets/shelly-gen1/relay-pm.json +60 -0
  258. package/presets/shelly-gen1/relay.json +36 -0
  259. package/presets/shelly-gen1/roller.json +52 -0
  260. package/presets/shelly-gen2/cover.json +68 -0
  261. package/presets/shelly-gen2/dimmer.json +61 -0
  262. package/presets/shelly-gen2/ht.json +47 -0
  263. package/presets/shelly-gen2/i4.json +82 -0
  264. package/presets/shelly-gen2/switch-pm.json +101 -0
  265. package/presets/shelly-gen2/switch.json +47 -0
  266. package/presets/tasmota/climate.json +52 -0
  267. package/presets/tasmota/color-light.json +63 -0
  268. package/presets/tasmota/ct-light.json +50 -0
  269. package/presets/tasmota/dimmer.json +45 -0
  270. package/presets/tasmota/relay.json +39 -0
  271. package/presets/tasmota/shutter.json +46 -0
  272. package/presets/tasmota/temperature-humidity.json +42 -0
  273. package/presets/tasmota/temperature.json +32 -0
  274. package/presets/valetudo/vacuum.json +103 -0
  275. package/presets/wled/dimmer.json +46 -0
  276. package/presets/wled/light.json +59 -0
  277. package/ui/dist/assets/index-BDtT6bdH.js +10 -0
  278. package/ui/dist/assets/index-CHiG-aoU.css +1 -0
  279. package/ui/dist/index.html +18 -0
@@ -0,0 +1,223 @@
1
+ /* Lookups into @matter/model: device types, clusters, their features, attributes, commands and events,
2
+ with what the editor and the validator need (metatype, nullability, writability, enum members, bitmap
3
+ fields, ranges, conformance under a feature set). Nothing here is hand-maintained; the model is the
4
+ catalogue. The few names the families add on top of the model — composite attributes such
5
+ as `ColorControl.colorHs` — are listed at the end so the validator knows them. */
6
+ import { Conformance, FeatureSet, Matter, } from '@matter/main/model';
7
+ export function lowerCamel(name) {
8
+ return name.charAt(0).toLowerCase() + name.slice(1);
9
+ }
10
+ export function upperCamel(name) {
11
+ return name.charAt(0).toUpperCase() + name.slice(1);
12
+ }
13
+ const clusterCache = new Map();
14
+ const deviceTypeCache = new Map();
15
+ function featureContext(cluster, enabled) {
16
+ const byTitle = new Map();
17
+ for (const f of cluster.features) {
18
+ byTitle.set(f.title ?? f.name, f.name);
19
+ byTitle.set(f.name, f.name);
20
+ }
21
+ const codes = [];
22
+ for (const name of enabled) {
23
+ const code = byTitle.get(name);
24
+ if (code !== undefined) {
25
+ codes.push(code);
26
+ }
27
+ }
28
+ return {
29
+ definedFeatures: new FeatureSet(cluster.features.map((f) => f.name)),
30
+ supportedFeatures: new FeatureSet(codes),
31
+ };
32
+ }
33
+ function constraintBound(value) {
34
+ return typeof value === 'number' ? value : undefined;
35
+ }
36
+ function attributeInfo(cluster, attribute) {
37
+ const metatype = (attribute.effectiveMetatype ?? 'any');
38
+ let enumMembers;
39
+ let bitFields;
40
+ if (metatype === 'enum') {
41
+ enumMembers = new Map();
42
+ // a derived cluster extends the base's enum in a datatype of its own (RvcOperationalState adds Docked …)
43
+ const local = cluster.datatypes.find((d) => d.name === attribute.type);
44
+ for (const member of local?.children ?? attribute.members) {
45
+ if (typeof member.id === 'number') {
46
+ enumMembers.set(member.name, member.id);
47
+ }
48
+ }
49
+ }
50
+ else if (metatype === 'bitmap') {
51
+ bitFields = [];
52
+ for (const member of attribute.members) {
53
+ const bit = constraintBound(member.constraint.value) ?? constraintBound(member.constraint.min);
54
+ if (bit !== undefined) {
55
+ bitFields.push({ name: lowerCamel(member.name), bit });
56
+ }
57
+ }
58
+ }
59
+ const constraint = attribute.effectiveConstraint;
60
+ return {
61
+ name: lowerCamel(attribute.name),
62
+ id: attribute.id,
63
+ metatype,
64
+ nullable: attribute.effectiveQuality.nullable === true,
65
+ writable: attribute.access.writable,
66
+ enumMembers,
67
+ bitFields,
68
+ min: constraintBound(constraint.min),
69
+ max: constraintBound(constraint.max),
70
+ applicability: (features) => attribute.conformance.applicabilityFor(featureContext(cluster, features)),
71
+ };
72
+ }
73
+ function commandInfo(cluster, command) {
74
+ return {
75
+ name: lowerCamel(command.name),
76
+ id: command.id,
77
+ fields: command.children.map((f) => lowerCamel(f.name)),
78
+ // a derived cluster's command that only narrows the base's has its conformance and direction there
79
+ applicability: (features) => command.effectiveConformance.applicabilityFor(featureContext(cluster, features)),
80
+ };
81
+ }
82
+ /** the cluster by its PascalCase name (`OnOff`, `LevelControl`), or undefined */
83
+ export function cluster(name) {
84
+ const cached = clusterCache.get(name);
85
+ if (cached !== undefined) {
86
+ return cached ?? undefined;
87
+ }
88
+ const model = Matter.clusters(name);
89
+ if (model?.id === undefined) {
90
+ clusterCache.set(name, null);
91
+ return undefined;
92
+ }
93
+ const features = model.features.map((f) => ({ code: f.name, title: f.title ?? f.name }));
94
+ const attributes = new Map();
95
+ for (const attribute of model.attributes) {
96
+ if (attribute.isGlobal) {
97
+ continue;
98
+ }
99
+ const info = attributeInfo(model, attribute);
100
+ attributes.set(info.name, info);
101
+ }
102
+ const commands = new Map();
103
+ for (const command of model.commands) {
104
+ if (String(command.effectiveDirection) !== 'request') {
105
+ continue;
106
+ }
107
+ const info = commandInfo(model, command);
108
+ commands.set(info.name, info);
109
+ }
110
+ const info = {
111
+ name: model.name,
112
+ id: model.id,
113
+ behaviorId: lowerCamel(model.name),
114
+ features,
115
+ attributes,
116
+ commands,
117
+ events: model.events.map((e) => lowerCamel(e.name)),
118
+ feature: (nameOrCode) => features.find((f) => f.title === nameOrCode) ?? features.find((f) => f.code === nameOrCode),
119
+ };
120
+ clusterCache.set(name, info);
121
+ return info;
122
+ }
123
+ function requirementFeatures(clusterModel, requirement) {
124
+ if (clusterModel === undefined) {
125
+ return [];
126
+ }
127
+ const titles = [];
128
+ for (const child of requirement.children) {
129
+ const feature = clusterModel.features.find((f) => f.name === child.name);
130
+ if (feature === undefined) {
131
+ continue;
132
+ }
133
+ const conformance = child.conformance;
134
+ if (conformance?.isMandatory) {
135
+ titles.push(feature.title ?? feature.name);
136
+ }
137
+ }
138
+ return titles;
139
+ }
140
+ /** the device type by its name (`OnOffLight`, `PowerSource`), or undefined */
141
+ export function deviceType(name) {
142
+ const cached = deviceTypeCache.get(name);
143
+ if (cached !== undefined) {
144
+ return cached ?? undefined;
145
+ }
146
+ const model = Matter.deviceTypes(name);
147
+ if (model === undefined) {
148
+ deviceTypeCache.set(name, null);
149
+ return undefined;
150
+ }
151
+ const clusters = [];
152
+ for (const requirement of model.requirements) {
153
+ if (requirement.element !== 'serverCluster' || requirement.name === 'Descriptor') {
154
+ continue;
155
+ }
156
+ const conformance = String(requirement.conformance);
157
+ if (conformance === 'X' || conformance.startsWith('D')) {
158
+ continue;
159
+ }
160
+ clusters.push({
161
+ cluster: requirement.name,
162
+ mandatory: requirement.conformance.isMandatory,
163
+ features: requirementFeatures(Matter.clusters(requirement.name), requirement),
164
+ });
165
+ }
166
+ const info = {
167
+ name: model.name,
168
+ id: model.id,
169
+ revision: model.revision,
170
+ classification: String(model.classification),
171
+ clusters,
172
+ };
173
+ deviceTypeCache.set(name, info);
174
+ return info;
175
+ }
176
+ /** every device type name the model knows, for the editor's picker */
177
+ export function deviceTypeNames() {
178
+ return Matter.deviceTypes.map((d) => d.name).sort();
179
+ }
180
+ export { Conformance };
181
+ /** command keys whose confirmation arrives on another attribute's status: decides the default of `optimistic` */
182
+ export const RELATED_STATUS = {
183
+ 'WindowCovering.targetPositionLiftPercent100ths': [
184
+ 'WindowCovering.currentPositionLiftPercent100ths',
185
+ 'WindowCovering.motion',
186
+ ],
187
+ 'WindowCovering.targetPositionTiltPercent100ths': ['WindowCovering.currentPositionTiltPercent100ths'],
188
+ 'WindowCovering.upOrOpen': ['WindowCovering.currentPositionLiftPercent100ths', 'WindowCovering.motion'],
189
+ 'WindowCovering.downOrClose': ['WindowCovering.currentPositionLiftPercent100ths', 'WindowCovering.motion'],
190
+ 'WindowCovering.stopMotion': ['WindowCovering.currentPositionLiftPercent100ths', 'WindowCovering.motion'],
191
+ 'FanControl.fanMode': ['FanControl.percentCurrent', 'FanControl.percentSetting'],
192
+ 'FanControl.percentSetting': ['FanControl.percentCurrent'],
193
+ 'FanControl.speedSetting': ['FanControl.speedCurrent', 'FanControl.percentCurrent'],
194
+ 'DoorLock.lockState': [],
195
+ };
196
+ /** composite attributes the families own on top of the model; the value is an object of these fields */
197
+ export const COMPOSITE_ATTRIBUTES = {
198
+ 'ColorControl.colorHs': {
199
+ cluster: 'ColorControl',
200
+ fields: ['hue', 'saturation'],
201
+ features: ['HueSaturation'],
202
+ description: 'hue 0–360° and saturation 0–100 %',
203
+ },
204
+ 'ColorControl.colorXy': {
205
+ cluster: 'ColorControl',
206
+ fields: ['x', 'y'],
207
+ features: ['Xy'],
208
+ description: 'CIE x and y, 0–1',
209
+ },
210
+ 'ColorControl.colorRgb': {
211
+ cluster: 'ColorControl',
212
+ fields: ['r', 'g', 'b'],
213
+ features: [],
214
+ description: 'red, green, blue 0–255 (converted to the colour features the endpoint has)',
215
+ },
216
+ 'WindowCovering.motion': {
217
+ cluster: 'WindowCovering',
218
+ fields: [],
219
+ features: [],
220
+ description: 'opening, closing, stopped, open or closed',
221
+ },
222
+ };
223
+ //# sourceMappingURL=catalog.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"catalog.js","sourceRoot":"","sources":["../../src/model/catalog.ts"],"names":[],"mappings":"AAAA;;;;oFAIoF;AAEpF,OAAO,EAIH,WAAW,EAEX,UAAU,EACV,MAAM,GAET,MAAM,oBAAoB,CAAC;AA8E5B,MAAM,UAAU,UAAU,CAAC,IAAY;IACnC,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AACxD,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,IAAY;IACnC,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AACxD,CAAC;AAED,MAAM,YAAY,GAAG,IAAI,GAAG,EAA8B,CAAC;AAC3D,MAAM,eAAe,GAAG,IAAI,GAAG,EAAiC,CAAC;AAEjE,SAAS,cAAc,CAAC,OAAqB,EAAE,OAAyB;IACpE,MAAM,OAAO,GAAG,IAAI,GAAG,EAAkB,CAAC;IAC1C,KAAK,MAAM,CAAC,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC;QAC/B,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC;QACvC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC;IA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2B,CAAC;IAC1D,yBAAyB,EAAE,CAAC,yBAAyB,EAAE,2BAA2B,CAAC;IACnF,oBAAoB,EAAE,EAAE;CAC3B,CAAC;AAEF,wGAAwG;AACxG,MAAM,CAAC,MAAM,oBAAoB,GAE7B;IACA,sBAAsB,EAAE;QACpB,OAAO,EAAE,cAAc;QACvB,MAAM,EAAE,CAAC,KAAK,EAAE,YAAY,CAAC;QAC7B,QAAQ,EAAE,CAAC,eAAe,CAAC;QAC3B,WAAW,EAAE,mCAAmC;KACnD;IACD,sBAAsB,EAAE;QACpB,OAAO,EAAE,cAAc;QACvB,MAAM,EAAE,CAAC,GAAG,EAAE,GAAG,CAAC;QAClB,QAAQ,EAAE,CAAC,IAAI,CAAC;QAChB,WAAW,EAAE,kBAAkB;KAClC;IACD,uBAAuB,EAAE;QACrB,OAAO,EAAE,cAAc;QACvB,MAAM,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC;QACvB,QAAQ,EAAE,EAAE;QACZ,WAAW,EAAE,4EAA4E;KAC5F;IACD,uBAAuB,EAAE;QACrB,OAAO,EAAE,gBAAgB;QACzB,MAAM,EAAE,EAAE;QACV,QAAQ,EAAE,EAAE;QACZ,WAAW,EAAE,2CAA2C;KAC3D;CACJ,CAAC"}
@@ -0,0 +1,7 @@
1
+ export * from './schema.ts';
2
+ export * from './options.ts';
3
+ export * from './attribute.ts';
4
+ export * from './catalog.ts';
5
+ export * from './validate.ts';
6
+ export * from './presets.ts';
7
+ export * from './migrate.ts';
@@ -0,0 +1,8 @@
1
+ export * from "./schema.js";
2
+ export * from "./options.js";
3
+ export * from "./attribute.js";
4
+ export * from "./catalog.js";
5
+ export * from "./validate.js";
6
+ export * from "./presets.js";
7
+ export * from "./migrate.js";
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/model/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC"}
@@ -0,0 +1,4 @@
1
+ /** migrate one raw device entry in place; true when something changed */
2
+ export declare function migrateDevice(device: unknown): boolean;
3
+ /** migrate a raw `devices` object in place; the keys of the devices that changed */
4
+ export declare function migrateDevices(devices: unknown): string[];
@@ -0,0 +1,39 @@
1
+ /* Migrations of the device format. A file written by an earlier version is brought to the current
2
+ schema on load, so it keeps working; the next save writes the current form. Each step is idempotent
3
+ and changes only what it recognises. */
4
+ function isRecord(value) {
5
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
6
+ }
7
+ /** migrate one raw device entry in place; true when something changed */
8
+ export function migrateDevice(device) {
9
+ if (!isRecord(device) || !Array.isArray(device.endpoints)) {
10
+ return false;
11
+ }
12
+ let changed = false;
13
+ for (const endpoint of device.endpoints) {
14
+ // the joins of a Matter element with MQTT were called bindings before they were called mappings
15
+ if (!isRecord(endpoint) || !('bindings' in endpoint)) {
16
+ continue;
17
+ }
18
+ const old = endpoint.bindings;
19
+ delete endpoint.bindings;
20
+ if (endpoint.mappings === undefined) {
21
+ endpoint.mappings = old;
22
+ }
23
+ else if (Array.isArray(endpoint.mappings) && Array.isArray(old)) {
24
+ endpoint.mappings = [...endpoint.mappings, ...old];
25
+ }
26
+ changed = true;
27
+ }
28
+ return changed;
29
+ }
30
+ /** migrate a raw `devices` object in place; the keys of the devices that changed */
31
+ export function migrateDevices(devices) {
32
+ if (!isRecord(devices)) {
33
+ return [];
34
+ }
35
+ return Object.entries(devices)
36
+ .filter(([, device]) => migrateDevice(device))
37
+ .map(([key]) => key);
38
+ }
39
+ //# sourceMappingURL=migrate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"migrate.js","sourceRoot":"","sources":["../../src/model/migrate.ts"],"names":[],"mappings":"AAAA;;0CAE0C;AAE1C,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C;IACD,OAAO,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC;SACzB,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,EAAE,EAAE,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;SAC7C,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC;AAC7B,CAAC"}
@@ -0,0 +1,102 @@
1
+ import { z } from 'zod';
2
+ export declare const OnOffOptionsSchema: z.ZodObject<{
3
+ momentary: z.ZodDefault<z.ZodNumber>;
4
+ }, z.core.$strict>;
5
+ export type OnOffOptions = z.infer<typeof OnOffOptionsSchema>;
6
+ export declare const LightOptionsSchema: z.ZodObject<{
7
+ onCommandType: z.ZodDefault<z.ZodEnum<{
8
+ first: "first";
9
+ last: "last";
10
+ brightness: "brightness";
11
+ }>>;
12
+ transition: z.ZodDefault<z.ZodBoolean>;
13
+ minMireds: z.ZodDefault<z.ZodNumber>;
14
+ maxMireds: z.ZodDefault<z.ZodNumber>;
15
+ }, z.core.$strict>;
16
+ export type LightOptions = z.infer<typeof LightOptionsSchema>;
17
+ export declare const CoverOptionsSchema: z.ZodObject<{
18
+ echoFilter: z.ZodDefault<z.ZodBoolean>;
19
+ reportTimeout: z.ZodDefault<z.ZodNumber>;
20
+ tolerance: z.ZodDefault<z.ZodNumber>;
21
+ }, z.core.$strict>;
22
+ export type CoverOptions = z.infer<typeof CoverOptionsSchema>;
23
+ export declare const ClimateOptionsSchema: z.ZodObject<{
24
+ minHeat: z.ZodDefault<z.ZodNumber>;
25
+ maxHeat: z.ZodDefault<z.ZodNumber>;
26
+ minCool: z.ZodDefault<z.ZodNumber>;
27
+ maxCool: z.ZodDefault<z.ZodNumber>;
28
+ deadband: z.ZodDefault<z.ZodNumber>;
29
+ }, z.core.$strict>;
30
+ export type ClimateOptions = z.infer<typeof ClimateOptionsSchema>;
31
+ export declare const FanOptionsSchema: z.ZodObject<{
32
+ low: z.ZodDefault<z.ZodNumber>;
33
+ medium: z.ZodDefault<z.ZodNumber>;
34
+ speedMax: z.ZodDefault<z.ZodNumber>;
35
+ }, z.core.$strict>;
36
+ export type FanOptions = z.infer<typeof FanOptionsSchema>;
37
+ export declare const SwitchOptionsSchema: z.ZodObject<{
38
+ kind: z.ZodDefault<z.ZodEnum<{
39
+ momentary: "momentary";
40
+ latching: "latching";
41
+ }>>;
42
+ numberOfPositions: z.ZodDefault<z.ZodNumber>;
43
+ multiPressMax: z.ZodDefault<z.ZodNumber>;
44
+ multiPressDelay: z.ZodDefault<z.ZodNumber>;
45
+ longPressDelay: z.ZodDefault<z.ZodNumber>;
46
+ pressDuration: z.ZodDefault<z.ZodNumber>;
47
+ }, z.core.$strict>;
48
+ export type SwitchOptions = z.infer<typeof SwitchOptionsSchema>;
49
+ export declare const PowerSourceOptionsSchema: z.ZodObject<{
50
+ warning: z.ZodDefault<z.ZodNumber>;
51
+ critical: z.ZodDefault<z.ZodNumber>;
52
+ }, z.core.$strict>;
53
+ export type PowerSourceOptions = z.infer<typeof PowerSourceOptionsSchema>;
54
+ export declare const OptionsSchema: z.ZodObject<{
55
+ onOff: z.ZodPrefault<z.ZodObject<{
56
+ momentary: z.ZodDefault<z.ZodNumber>;
57
+ }, z.core.$strict>>;
58
+ light: z.ZodPrefault<z.ZodObject<{
59
+ onCommandType: z.ZodDefault<z.ZodEnum<{
60
+ first: "first";
61
+ last: "last";
62
+ brightness: "brightness";
63
+ }>>;
64
+ transition: z.ZodDefault<z.ZodBoolean>;
65
+ minMireds: z.ZodDefault<z.ZodNumber>;
66
+ maxMireds: z.ZodDefault<z.ZodNumber>;
67
+ }, z.core.$strict>>;
68
+ cover: z.ZodPrefault<z.ZodObject<{
69
+ echoFilter: z.ZodDefault<z.ZodBoolean>;
70
+ reportTimeout: z.ZodDefault<z.ZodNumber>;
71
+ tolerance: z.ZodDefault<z.ZodNumber>;
72
+ }, z.core.$strict>>;
73
+ climate: z.ZodPrefault<z.ZodObject<{
74
+ minHeat: z.ZodDefault<z.ZodNumber>;
75
+ maxHeat: z.ZodDefault<z.ZodNumber>;
76
+ minCool: z.ZodDefault<z.ZodNumber>;
77
+ maxCool: z.ZodDefault<z.ZodNumber>;
78
+ deadband: z.ZodDefault<z.ZodNumber>;
79
+ }, z.core.$strict>>;
80
+ fan: z.ZodPrefault<z.ZodObject<{
81
+ low: z.ZodDefault<z.ZodNumber>;
82
+ medium: z.ZodDefault<z.ZodNumber>;
83
+ speedMax: z.ZodDefault<z.ZodNumber>;
84
+ }, z.core.$strict>>;
85
+ switch: z.ZodPrefault<z.ZodObject<{
86
+ kind: z.ZodDefault<z.ZodEnum<{
87
+ momentary: "momentary";
88
+ latching: "latching";
89
+ }>>;
90
+ numberOfPositions: z.ZodDefault<z.ZodNumber>;
91
+ multiPressMax: z.ZodDefault<z.ZodNumber>;
92
+ multiPressDelay: z.ZodDefault<z.ZodNumber>;
93
+ longPressDelay: z.ZodDefault<z.ZodNumber>;
94
+ pressDuration: z.ZodDefault<z.ZodNumber>;
95
+ }, z.core.$strict>>;
96
+ powerSource: z.ZodPrefault<z.ZodObject<{
97
+ warning: z.ZodDefault<z.ZodNumber>;
98
+ critical: z.ZodDefault<z.ZodNumber>;
99
+ }, z.core.$strict>>;
100
+ }, z.core.$strict>;
101
+ export type Options = z.infer<typeof OptionsSchema>;
102
+ export type OptionsInput = z.input<typeof OptionsSchema>;
@@ -0,0 +1,88 @@
1
+ /* Family options: the knobs of the state machines in src/families, one object per family under an
2
+ endpoint's `options`. They are part of the model (pure zod, no matter.js) so the config validates
3
+ without the families and the UI can render a form from them. Every field has a default. */
4
+ import { z } from 'zod';
5
+ export const OnOffOptionsSchema = z
6
+ .object({
7
+ /** ms: a stateless trigger (a scene, a Home Assistant button): `on` publishes the command and the endpoint
8
+ * falls back to off after this long; `off` publishes nothing. 0 = an ordinary on/off */
9
+ momentary: z.number().int().min(0).max(60_000).default(0),
10
+ })
11
+ .strict();
12
+ export const LightOptionsSchema = z
13
+ .object({
14
+ /** HA's `on_command_type`: `first` publishes on, then the level; `last` the level, then on; `brightness`
15
+ * only the level (the device turns on by itself) */
16
+ onCommandType: z.enum(['first', 'last', 'brightness']).default('last'),
17
+ /** pass a controller's transition time to the command templates as `transition` (seconds) */
18
+ transition: z.boolean().default(true),
19
+ /** the device's colour temperature range in mireds (the attribute's physical min/max) */
20
+ minMireds: z.number().int().min(1).max(65279).default(153),
21
+ maxMireds: z.number().int().min(1).max(65279).default(500),
22
+ })
23
+ .strict();
24
+ export const CoverOptionsSchema = z
25
+ .object({
26
+ /** hold back a position report that merely echoes the previous position right after a command until a
27
+ * second report corroborates it or `reportTimeout` passes (the FYRTUR target echo) */
28
+ echoFilter: z.boolean().default(false),
29
+ /** seconds after the last position report before a movement counts as stopped */
30
+ reportTimeout: z.number().positive().default(30),
31
+ /** percent100ths within which current and target count as equal */
32
+ tolerance: z.number().int().min(0).max(10000).default(100),
33
+ })
34
+ .strict();
35
+ export const ClimateOptionsSchema = z
36
+ .object({
37
+ /** setpoint limits in °C */
38
+ minHeat: z.number().default(7),
39
+ maxHeat: z.number().default(30),
40
+ minCool: z.number().default(16),
41
+ maxCool: z.number().default(32),
42
+ /** °C between heating and cooling setpoint in auto mode */
43
+ deadband: z.number().min(0).max(12.7).default(2),
44
+ })
45
+ .strict();
46
+ export const FanOptionsSchema = z
47
+ .object({
48
+ /** percent thresholds that turn a percent into low / medium / high when only a percent is bound */
49
+ low: z.number().int().min(1).max(100).default(33),
50
+ medium: z.number().int().min(1).max(100).default(66),
51
+ /** the device's discrete speeds (the MultiSpeed feature); 0 = none */
52
+ speedMax: z.number().int().min(0).max(100).default(0),
53
+ })
54
+ .strict();
55
+ export const SwitchOptionsSchema = z
56
+ .object({
57
+ /** `momentary` (buttons: press kinds → events) or `latching` (a toggle: the value is the position) */
58
+ kind: z.enum(['momentary', 'latching']).default('momentary'),
59
+ numberOfPositions: z.number().int().min(2).max(255).default(2),
60
+ /** presses in one sequence the controller is told about (MultiPress); 1 = single presses only */
61
+ multiPressMax: z.number().int().min(1).max(255).default(3),
62
+ /** ms the family waits for a further press before it completes a sequence (multiPressDelay) */
63
+ multiPressDelay: z.number().int().min(50).max(5000).default(300),
64
+ /** ms a press lasts before it is a long press (longPressDelay) */
65
+ longPressDelay: z.number().int().min(50).max(10000).default(500),
66
+ /** ms between the press and the release the family emits for a complete press kind */
67
+ pressDuration: z.number().int().min(10).max(2000).default(50),
68
+ })
69
+ .strict();
70
+ export const PowerSourceOptionsSchema = z
71
+ .object({
72
+ /** percent at or below which `batChargeLevel` is Warning / Critical when it is not bound itself */
73
+ warning: z.number().int().min(0).max(100).default(20),
74
+ critical: z.number().int().min(0).max(100).default(10),
75
+ })
76
+ .strict();
77
+ export const OptionsSchema = z
78
+ .object({
79
+ onOff: OnOffOptionsSchema.prefault({}),
80
+ light: LightOptionsSchema.prefault({}),
81
+ cover: CoverOptionsSchema.prefault({}),
82
+ climate: ClimateOptionsSchema.prefault({}),
83
+ fan: FanOptionsSchema.prefault({}),
84
+ switch: SwitchOptionsSchema.prefault({}),
85
+ powerSource: PowerSourceOptionsSchema.prefault({}),
86
+ })
87
+ .strict();
88
+ //# sourceMappingURL=options.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"options.js","sourceRoot":"","sources":["../../src/model/options.ts"],"names":[],"mappings":"AAAA;;6FAE6F;AAE7F,OAAO,EAAC,CAAC,EAAC,MAAM,KAAK,CAAC;AAEtB,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC;KAC9B,MAAM,CAAC;IACJ;6FACyF;IACzF,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC;CAC5D,CAAC;KACD,MAAM,EAAE,CAAC;AAGd,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC;KAC9B,MAAM,CAAC;IACJ;yDACqD;IACrD,aAAa,EAAE,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E,CAAC;IACtC,KAAK,EAAE,kBAAkB,CAAC,QAAQ,CAAC,EAAE,CAAC;IACtC,KAAK,EAAE,kBAAkB,CAAC,QAAQ,CAAC,EAAE,CAAC;IACtC,OAAO,EAAE,oBAAoB,CAAC,QAAQ,CAAC,EAAE,CAAC;IAC1C,GAAG,EAAE,gBAAgB,CAAC,QAAQ,CAAC,EAAE,CAAC;IAClC,MAAM,EAAE,mBAAmB,CAAC,QAAQ,CAAC,EAAE,CAAC;IACxC,WAAW,EAAE,wBAAwB,CAAC,QAAQ,CAAC,EAAE,CAAC;CACrD,CAAC;KACD,MAAM,EAAE,CAAC"}
@@ -0,0 +1,37 @@
1
+ import { z } from 'zod';
2
+ import { type DeviceConfig } from './schema.ts';
3
+ export declare const PLACEHOLDER_PATTERN: RegExp;
4
+ export declare const PresetVariableSchema: z.ZodObject<{
5
+ label: z.ZodString;
6
+ description: z.ZodOptional<z.ZodString>;
7
+ default: z.ZodOptional<z.ZodString>;
8
+ optional: z.ZodDefault<z.ZodBoolean>;
9
+ }, z.core.$strict>;
10
+ export type PresetVariable = z.infer<typeof PresetVariableSchema>;
11
+ export declare const PresetSchema: z.ZodObject<{
12
+ id: z.ZodString;
13
+ name: z.ZodString;
14
+ description: z.ZodOptional<z.ZodString>;
15
+ vendor: z.ZodOptional<z.ZodString>;
16
+ format: z.ZodDefault<z.ZodLiteral<1>>;
17
+ variables: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodObject<{
18
+ label: z.ZodString;
19
+ description: z.ZodOptional<z.ZodString>;
20
+ default: z.ZodOptional<z.ZodString>;
21
+ optional: z.ZodDefault<z.ZodBoolean>;
22
+ }, z.core.$strict>>>;
23
+ device: z.ZodUnknown;
24
+ }, z.core.$strict>;
25
+ export type Preset = z.infer<typeof PresetSchema>;
26
+ export declare class PresetError extends Error {
27
+ constructor(message: string);
28
+ }
29
+ /** the placeholders a preset's device template uses */
30
+ export declare function placeholdersOf(preset: Preset): string[];
31
+ /** parse a preset file's JSON; every placeholder must be declared in `variables` */
32
+ export declare function parsePreset(raw: unknown): Preset;
33
+ /**
34
+ * The device entry a preset yields for the user's values. Values are substituted into the JSON text, so
35
+ * they are escaped as JSON strings; a placeholder that forms a whole JSON string stays a string.
36
+ */
37
+ export declare function applyPreset(preset: Preset, values: Record<string, string>): DeviceConfig;
@@ -0,0 +1,105 @@
1
+ /* Presets: a device template — the endpoints and mappings of a kind of device (a Tasmota relay, a Shelly
2
+ cover, an ESPHome sensor) with placeholders — that becomes a device entry by substituting the user's
3
+ values. The format is fixed here; the shipped presets for Tasmota, Shelly and ESPHome come later and
4
+ users add their own as JSON files. A placeholder is `%name%`; `variables` declares each with a label
5
+ and a default, so an editor can ask for them. Substitution is textual over the JSON of the template,
6
+ so a placeholder can stand in a topic, a payload or a template string alike. */
7
+ import { z } from 'zod';
8
+ import { DeviceSchema } from "./schema.js";
9
+ export const PLACEHOLDER_PATTERN = /%([A-Za-z_][A-Za-z0-9_]*)%/g;
10
+ export const PresetVariableSchema = z
11
+ .object({
12
+ /** what the editor asks for */
13
+ label: z.string().min(1),
14
+ description: z.string().optional(),
15
+ default: z.string().optional(),
16
+ /** no default and not optional: the user must fill it */
17
+ optional: z.boolean().default(false),
18
+ })
19
+ .strict();
20
+ export const PresetSchema = z
21
+ .object({
22
+ /** a unique id, e.g. `tasmota/relay` */
23
+ id: z.string().regex(/^[a-z0-9][a-z0-9/_-]*$/, 'a preset id is lower case: tasmota/relay'),
24
+ name: z.string().min(1),
25
+ description: z.string().optional(),
26
+ /** the ecosystem it belongs to, for grouping */
27
+ vendor: z.string().optional(),
28
+ /** the format version; 1 */
29
+ format: z.literal(1).default(1),
30
+ variables: z.record(z.string().regex(/^[A-Za-z_][A-Za-z0-9_]*$/), PresetVariableSchema).default({}),
31
+ /** the device entry with placeholders; validated after substitution */
32
+ device: z.unknown(),
33
+ })
34
+ .strict();
35
+ export class PresetError extends Error {
36
+ constructor(message) {
37
+ super(message);
38
+ this.name = 'PresetError';
39
+ }
40
+ }
41
+ /** the placeholders a preset's device template uses */
42
+ export function placeholdersOf(preset) {
43
+ const names = new Set();
44
+ for (const match of JSON.stringify(preset.device).matchAll(PLACEHOLDER_PATTERN)) {
45
+ const name = match[1];
46
+ if (name !== undefined) {
47
+ names.add(name);
48
+ }
49
+ }
50
+ return [...names].sort();
51
+ }
52
+ /** parse a preset file's JSON; every placeholder must be declared in `variables` */
53
+ export function parsePreset(raw) {
54
+ const result = PresetSchema.safeParse(raw);
55
+ if (!result.success) {
56
+ throw new PresetError(`invalid preset:\n${z.prettifyError(result.error)}`);
57
+ }
58
+ const preset = result.data;
59
+ const undeclared = placeholdersOf(preset).filter((name) => !(name in preset.variables));
60
+ if (undeclared.length > 0) {
61
+ throw new PresetError(`preset ${preset.id}: placeholders without a variable: ${undeclared.join(', ')}`);
62
+ }
63
+ return preset;
64
+ }
65
+ function escapeForJson(value) {
66
+ return JSON.stringify(value).slice(1, -1);
67
+ }
68
+ /**
69
+ * The device entry a preset yields for the user's values. Values are substituted into the JSON text, so
70
+ * they are escaped as JSON strings; a placeholder that forms a whole JSON string stays a string.
71
+ */
72
+ export function applyPreset(preset, values) {
73
+ const missing = [];
74
+ const filled = {};
75
+ for (const [name, variable] of Object.entries(preset.variables)) {
76
+ const value = values[name] ?? variable.default;
77
+ if (value === undefined) {
78
+ if (!variable.optional) {
79
+ missing.push(name);
80
+ }
81
+ filled[name] = '';
82
+ }
83
+ else {
84
+ filled[name] = value;
85
+ }
86
+ }
87
+ if (missing.length > 0) {
88
+ throw new PresetError(`preset ${preset.id}: missing values for ${missing.join(', ')}`);
89
+ }
90
+ const text = JSON.stringify(preset.device).replace(PLACEHOLDER_PATTERN, (_m, name) => escapeForJson(filled[name] ?? ''));
91
+ let raw;
92
+ try {
93
+ raw = JSON.parse(text);
94
+ }
95
+ catch (error) {
96
+ throw new PresetError(`preset ${preset.id}: the substituted device is not valid JSON: ${error.message}`);
97
+ }
98
+ const parsed = DeviceSchema.safeParse(raw);
99
+ if (!parsed.success) {
100
+ throw new PresetError(`preset ${preset.id}: the device is invalid:\n${z.prettifyError(parsed.error)}`);
101
+ }
102
+ const device = parsed.data;
103
+ return { ...device, source: { kind: 'preset', key: preset.id, version: String(preset.format) } };
104
+ }
105
+ //# sourceMappingURL=presets.js.map