@matter/protocol 0.13.1-alpha.0-20250520-d699cd56d → 0.14.0-alpha.0-20250524-51a7e1721

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 (264) hide show
  1. package/dist/cjs/action/Interactable.d.ts +1 -1
  2. package/dist/cjs/action/Interactable.d.ts.map +1 -1
  3. package/dist/cjs/action/client/ClientInteraction.d.ts +1 -1
  4. package/dist/cjs/action/client/ClientInteraction.d.ts.map +1 -1
  5. package/dist/cjs/action/client/ClientInteraction.js +50 -8
  6. package/dist/cjs/action/client/ClientInteraction.js.map +1 -1
  7. package/dist/cjs/action/protocols.d.ts +49 -15
  8. package/dist/cjs/action/protocols.d.ts.map +1 -1
  9. package/dist/cjs/action/request/Invoke.d.ts +10 -1
  10. package/dist/cjs/action/request/Invoke.d.ts.map +1 -1
  11. package/dist/cjs/action/request/Invoke.js +17 -5
  12. package/dist/cjs/action/request/Invoke.js.map +1 -1
  13. package/dist/cjs/action/request/Read.d.ts.map +1 -1
  14. package/dist/cjs/action/request/Read.js +1 -1
  15. package/dist/cjs/action/request/Read.js.map +1 -1
  16. package/dist/cjs/action/request/Write.d.ts +2 -0
  17. package/dist/cjs/action/request/Write.d.ts.map +1 -1
  18. package/dist/cjs/action/request/Write.js.map +1 -1
  19. package/dist/cjs/action/response/InvokeResult.d.ts +22 -6
  20. package/dist/cjs/action/response/InvokeResult.d.ts.map +1 -1
  21. package/dist/cjs/action/server/AttributeReadResponse.d.ts.map +1 -1
  22. package/dist/cjs/action/server/AttributeReadResponse.js +1 -2
  23. package/dist/cjs/action/server/AttributeReadResponse.js.map +2 -2
  24. package/dist/cjs/action/server/AttributeWriteResponse.d.ts.map +1 -1
  25. package/dist/cjs/action/server/AttributeWriteResponse.js +1 -14
  26. package/dist/cjs/action/server/AttributeWriteResponse.js.map +1 -1
  27. package/dist/cjs/action/server/CommandInvokeResponse.d.ts +25 -0
  28. package/dist/cjs/action/server/CommandInvokeResponse.d.ts.map +1 -0
  29. package/dist/cjs/action/server/CommandInvokeResponse.js +331 -0
  30. package/dist/cjs/action/server/CommandInvokeResponse.js.map +6 -0
  31. package/dist/cjs/action/server/EventReadResponse.js +1 -1
  32. package/dist/cjs/action/server/ServerInteraction.d.ts +1 -3
  33. package/dist/cjs/action/server/ServerInteraction.d.ts.map +1 -1
  34. package/dist/cjs/action/server/ServerInteraction.js +4 -2
  35. package/dist/cjs/action/server/ServerInteraction.js.map +1 -1
  36. package/dist/cjs/action/server/index.d.ts +1 -0
  37. package/dist/cjs/action/server/index.d.ts.map +1 -1
  38. package/dist/cjs/action/server/index.js +1 -0
  39. package/dist/cjs/action/server/index.js.map +1 -1
  40. package/dist/cjs/cluster/client/AttributeClient.d.ts +2 -0
  41. package/dist/cjs/cluster/client/AttributeClient.d.ts.map +1 -1
  42. package/dist/cjs/cluster/client/AttributeClient.js +10 -0
  43. package/dist/cjs/cluster/client/AttributeClient.js.map +1 -1
  44. package/dist/cjs/cluster/client/ClusterClientTypes.d.ts +0 -4
  45. package/dist/cjs/cluster/client/ClusterClientTypes.d.ts.map +1 -1
  46. package/dist/cjs/cluster/index.d.ts +0 -1
  47. package/dist/cjs/cluster/index.d.ts.map +1 -1
  48. package/dist/cjs/cluster/index.js +0 -1
  49. package/dist/cjs/cluster/index.js.map +1 -1
  50. package/dist/cjs/events/OccurrenceManager.d.ts +10 -2
  51. package/dist/cjs/events/OccurrenceManager.d.ts.map +1 -1
  52. package/dist/cjs/events/OccurrenceManager.js +57 -11
  53. package/dist/cjs/events/OccurrenceManager.js.map +1 -1
  54. package/dist/cjs/fabric/Fabric.d.ts +2 -11
  55. package/dist/cjs/fabric/Fabric.d.ts.map +1 -1
  56. package/dist/cjs/fabric/Fabric.js +1 -38
  57. package/dist/cjs/fabric/Fabric.js.map +1 -1
  58. package/dist/cjs/index.d.ts +0 -1
  59. package/dist/cjs/index.d.ts.map +1 -1
  60. package/dist/cjs/index.js +0 -1
  61. package/dist/cjs/index.js.map +1 -1
  62. package/dist/cjs/interaction/AttributeDataEncoder.d.ts +1 -1
  63. package/dist/cjs/interaction/InteractionClient.d.ts +13 -0
  64. package/dist/cjs/interaction/InteractionClient.d.ts.map +1 -1
  65. package/dist/cjs/interaction/InteractionClient.js +14 -0
  66. package/dist/cjs/interaction/InteractionClient.js.map +1 -1
  67. package/dist/cjs/interaction/InteractionMessenger.d.ts +8 -8
  68. package/dist/cjs/interaction/index.d.ts +0 -1
  69. package/dist/cjs/interaction/index.d.ts.map +1 -1
  70. package/dist/cjs/interaction/index.js +0 -1
  71. package/dist/cjs/interaction/index.js.map +1 -1
  72. package/dist/cjs/mdns/MdnsScanner.d.ts +23 -1
  73. package/dist/cjs/mdns/MdnsScanner.d.ts.map +1 -1
  74. package/dist/cjs/mdns/MdnsScanner.js +124 -11
  75. package/dist/cjs/mdns/MdnsScanner.js.map +2 -2
  76. package/dist/esm/action/Interactable.d.ts +1 -1
  77. package/dist/esm/action/Interactable.d.ts.map +1 -1
  78. package/dist/esm/action/client/ClientInteraction.d.ts +1 -1
  79. package/dist/esm/action/client/ClientInteraction.d.ts.map +1 -1
  80. package/dist/esm/action/client/ClientInteraction.js +50 -8
  81. package/dist/esm/action/client/ClientInteraction.js.map +1 -1
  82. package/dist/esm/action/protocols.d.ts +49 -15
  83. package/dist/esm/action/protocols.d.ts.map +1 -1
  84. package/dist/esm/action/request/Invoke.d.ts +10 -1
  85. package/dist/esm/action/request/Invoke.d.ts.map +1 -1
  86. package/dist/esm/action/request/Invoke.js +17 -5
  87. package/dist/esm/action/request/Invoke.js.map +1 -1
  88. package/dist/esm/action/request/Read.d.ts.map +1 -1
  89. package/dist/esm/action/request/Read.js +1 -1
  90. package/dist/esm/action/request/Read.js.map +1 -1
  91. package/dist/esm/action/request/Write.d.ts +2 -0
  92. package/dist/esm/action/request/Write.d.ts.map +1 -1
  93. package/dist/esm/action/request/Write.js.map +1 -1
  94. package/dist/esm/action/response/InvokeResult.d.ts +22 -6
  95. package/dist/esm/action/response/InvokeResult.d.ts.map +1 -1
  96. package/dist/esm/action/server/AttributeReadResponse.d.ts.map +1 -1
  97. package/dist/esm/action/server/AttributeReadResponse.js +1 -1
  98. package/dist/esm/action/server/AttributeReadResponse.js.map +1 -1
  99. package/dist/esm/action/server/AttributeWriteResponse.d.ts.map +1 -1
  100. package/dist/esm/action/server/AttributeWriteResponse.js +2 -15
  101. package/dist/esm/action/server/AttributeWriteResponse.js.map +1 -1
  102. package/dist/esm/action/server/CommandInvokeResponse.d.ts +25 -0
  103. package/dist/esm/action/server/CommandInvokeResponse.d.ts.map +1 -0
  104. package/dist/esm/action/server/CommandInvokeResponse.js +317 -0
  105. package/dist/esm/action/server/CommandInvokeResponse.js.map +6 -0
  106. package/dist/esm/action/server/EventReadResponse.js +1 -1
  107. package/dist/esm/action/server/ServerInteraction.d.ts +1 -3
  108. package/dist/esm/action/server/ServerInteraction.d.ts.map +1 -1
  109. package/dist/esm/action/server/ServerInteraction.js +4 -2
  110. package/dist/esm/action/server/ServerInteraction.js.map +1 -1
  111. package/dist/esm/action/server/index.d.ts +1 -0
  112. package/dist/esm/action/server/index.d.ts.map +1 -1
  113. package/dist/esm/action/server/index.js +1 -0
  114. package/dist/esm/action/server/index.js.map +1 -1
  115. package/dist/esm/cluster/client/AttributeClient.d.ts +2 -0
  116. package/dist/esm/cluster/client/AttributeClient.d.ts.map +1 -1
  117. package/dist/esm/cluster/client/AttributeClient.js +10 -0
  118. package/dist/esm/cluster/client/AttributeClient.js.map +1 -1
  119. package/dist/esm/cluster/client/ClusterClientTypes.d.ts +0 -4
  120. package/dist/esm/cluster/client/ClusterClientTypes.d.ts.map +1 -1
  121. package/dist/esm/cluster/index.d.ts +0 -1
  122. package/dist/esm/cluster/index.d.ts.map +1 -1
  123. package/dist/esm/cluster/index.js +0 -1
  124. package/dist/esm/cluster/index.js.map +1 -1
  125. package/dist/esm/events/OccurrenceManager.d.ts +10 -2
  126. package/dist/esm/events/OccurrenceManager.d.ts.map +1 -1
  127. package/dist/esm/events/OccurrenceManager.js +62 -12
  128. package/dist/esm/events/OccurrenceManager.js.map +1 -1
  129. package/dist/esm/fabric/Fabric.d.ts +2 -11
  130. package/dist/esm/fabric/Fabric.d.ts.map +1 -1
  131. package/dist/esm/fabric/Fabric.js +1 -38
  132. package/dist/esm/fabric/Fabric.js.map +1 -1
  133. package/dist/esm/index.d.ts +0 -1
  134. package/dist/esm/index.d.ts.map +1 -1
  135. package/dist/esm/index.js +0 -1
  136. package/dist/esm/index.js.map +1 -1
  137. package/dist/esm/interaction/AttributeDataEncoder.d.ts +1 -1
  138. package/dist/esm/interaction/InteractionClient.d.ts +13 -0
  139. package/dist/esm/interaction/InteractionClient.d.ts.map +1 -1
  140. package/dist/esm/interaction/InteractionClient.js +14 -0
  141. package/dist/esm/interaction/InteractionClient.js.map +1 -1
  142. package/dist/esm/interaction/InteractionMessenger.d.ts +8 -8
  143. package/dist/esm/interaction/index.d.ts +0 -1
  144. package/dist/esm/interaction/index.d.ts.map +1 -1
  145. package/dist/esm/interaction/index.js +0 -1
  146. package/dist/esm/interaction/index.js.map +1 -1
  147. package/dist/esm/mdns/MdnsScanner.d.ts +23 -1
  148. package/dist/esm/mdns/MdnsScanner.d.ts.map +1 -1
  149. package/dist/esm/mdns/MdnsScanner.js +127 -11
  150. package/dist/esm/mdns/MdnsScanner.js.map +2 -2
  151. package/package.json +6 -6
  152. package/src/action/Interactable.ts +1 -1
  153. package/src/action/client/ClientInteraction.ts +53 -16
  154. package/src/action/protocols.ts +70 -16
  155. package/src/action/request/Invoke.ts +32 -5
  156. package/src/action/request/Read.ts +1 -1
  157. package/src/action/request/Write.ts +4 -1
  158. package/src/action/response/InvokeResult.ts +26 -6
  159. package/src/action/response/ReadResult.ts +1 -1
  160. package/src/action/server/AttributeReadResponse.ts +1 -1
  161. package/src/action/server/AttributeWriteResponse.ts +2 -20
  162. package/src/action/server/CommandInvokeResponse.ts +427 -0
  163. package/src/action/server/EventReadResponse.ts +1 -1
  164. package/src/action/server/ServerInteraction.ts +6 -5
  165. package/src/action/server/index.ts +1 -0
  166. package/src/cluster/client/AttributeClient.ts +12 -0
  167. package/src/cluster/client/ClusterClientTypes.ts +0 -6
  168. package/src/cluster/index.ts +0 -1
  169. package/src/events/OccurrenceManager.ts +91 -11
  170. package/src/fabric/Fabric.ts +1 -49
  171. package/src/index.ts +0 -1
  172. package/src/interaction/InteractionClient.ts +24 -0
  173. package/src/interaction/index.ts +0 -1
  174. package/src/mdns/MdnsScanner.ts +187 -12
  175. package/dist/cjs/cluster/server/AttributeServer.d.ts +0 -307
  176. package/dist/cjs/cluster/server/AttributeServer.d.ts.map +0 -1
  177. package/dist/cjs/cluster/server/AttributeServer.js +0 -736
  178. package/dist/cjs/cluster/server/AttributeServer.js.map +0 -6
  179. package/dist/cjs/cluster/server/ClusterDatasource.d.ts +0 -16
  180. package/dist/cjs/cluster/server/ClusterDatasource.d.ts.map +0 -1
  181. package/dist/cjs/cluster/server/ClusterDatasource.js +0 -22
  182. package/dist/cjs/cluster/server/ClusterDatasource.js.map +0 -6
  183. package/dist/cjs/cluster/server/ClusterServer.d.ts +0 -40
  184. package/dist/cjs/cluster/server/ClusterServer.d.ts.map +0 -1
  185. package/dist/cjs/cluster/server/ClusterServer.js +0 -22
  186. package/dist/cjs/cluster/server/ClusterServer.js.map +0 -6
  187. package/dist/cjs/cluster/server/CommandServer.d.ts +0 -34
  188. package/dist/cjs/cluster/server/CommandServer.d.ts.map +0 -1
  189. package/dist/cjs/cluster/server/CommandServer.js +0 -76
  190. package/dist/cjs/cluster/server/CommandServer.js.map +0 -6
  191. package/dist/cjs/cluster/server/EventServer.d.ts +0 -42
  192. package/dist/cjs/cluster/server/EventServer.d.ts.map +0 -1
  193. package/dist/cjs/cluster/server/EventServer.js +0 -152
  194. package/dist/cjs/cluster/server/EventServer.js.map +0 -6
  195. package/dist/cjs/cluster/server/index.d.ts +0 -11
  196. package/dist/cjs/cluster/server/index.d.ts.map +0 -1
  197. package/dist/cjs/cluster/server/index.js +0 -28
  198. package/dist/cjs/cluster/server/index.js.map +0 -6
  199. package/dist/cjs/endpoint/EndpointInterface.d.ts +0 -37
  200. package/dist/cjs/endpoint/EndpointInterface.d.ts.map +0 -1
  201. package/dist/cjs/endpoint/EndpointInterface.js +0 -22
  202. package/dist/cjs/endpoint/EndpointInterface.js.map +0 -6
  203. package/dist/cjs/endpoint/EndpointStructureLogger.d.ts +0 -31
  204. package/dist/cjs/endpoint/EndpointStructureLogger.d.ts.map +0 -1
  205. package/dist/cjs/endpoint/EndpointStructureLogger.js +0 -230
  206. package/dist/cjs/endpoint/EndpointStructureLogger.js.map +0 -6
  207. package/dist/cjs/endpoint/index.d.ts +0 -8
  208. package/dist/cjs/endpoint/index.d.ts.map +0 -1
  209. package/dist/cjs/endpoint/index.js +0 -25
  210. package/dist/cjs/endpoint/index.js.map +0 -6
  211. package/dist/cjs/interaction/InteractionEndpointStructure.d.ts +0 -95
  212. package/dist/cjs/interaction/InteractionEndpointStructure.d.ts.map +0 -1
  213. package/dist/cjs/interaction/InteractionEndpointStructure.js +0 -359
  214. package/dist/cjs/interaction/InteractionEndpointStructure.js.map +0 -6
  215. package/dist/esm/cluster/server/AttributeServer.d.ts +0 -307
  216. package/dist/esm/cluster/server/AttributeServer.d.ts.map +0 -1
  217. package/dist/esm/cluster/server/AttributeServer.js +0 -729
  218. package/dist/esm/cluster/server/AttributeServer.js.map +0 -6
  219. package/dist/esm/cluster/server/ClusterDatasource.d.ts +0 -16
  220. package/dist/esm/cluster/server/ClusterDatasource.d.ts.map +0 -1
  221. package/dist/esm/cluster/server/ClusterDatasource.js +0 -6
  222. package/dist/esm/cluster/server/ClusterDatasource.js.map +0 -6
  223. package/dist/esm/cluster/server/ClusterServer.d.ts +0 -40
  224. package/dist/esm/cluster/server/ClusterServer.d.ts.map +0 -1
  225. package/dist/esm/cluster/server/ClusterServer.js +0 -6
  226. package/dist/esm/cluster/server/ClusterServer.js.map +0 -6
  227. package/dist/esm/cluster/server/CommandServer.d.ts +0 -34
  228. package/dist/esm/cluster/server/CommandServer.d.ts.map +0 -1
  229. package/dist/esm/cluster/server/CommandServer.js +0 -56
  230. package/dist/esm/cluster/server/CommandServer.js.map +0 -6
  231. package/dist/esm/cluster/server/EventServer.d.ts +0 -42
  232. package/dist/esm/cluster/server/EventServer.d.ts.map +0 -1
  233. package/dist/esm/cluster/server/EventServer.js +0 -141
  234. package/dist/esm/cluster/server/EventServer.js.map +0 -6
  235. package/dist/esm/cluster/server/index.d.ts +0 -11
  236. package/dist/esm/cluster/server/index.d.ts.map +0 -1
  237. package/dist/esm/cluster/server/index.js +0 -11
  238. package/dist/esm/cluster/server/index.js.map +0 -6
  239. package/dist/esm/endpoint/EndpointInterface.d.ts +0 -37
  240. package/dist/esm/endpoint/EndpointInterface.d.ts.map +0 -1
  241. package/dist/esm/endpoint/EndpointInterface.js +0 -6
  242. package/dist/esm/endpoint/EndpointInterface.js.map +0 -6
  243. package/dist/esm/endpoint/EndpointStructureLogger.d.ts +0 -31
  244. package/dist/esm/endpoint/EndpointStructureLogger.d.ts.map +0 -1
  245. package/dist/esm/endpoint/EndpointStructureLogger.js +0 -210
  246. package/dist/esm/endpoint/EndpointStructureLogger.js.map +0 -6
  247. package/dist/esm/endpoint/index.d.ts +0 -8
  248. package/dist/esm/endpoint/index.d.ts.map +0 -1
  249. package/dist/esm/endpoint/index.js +0 -8
  250. package/dist/esm/endpoint/index.js.map +0 -6
  251. package/dist/esm/interaction/InteractionEndpointStructure.d.ts +0 -95
  252. package/dist/esm/interaction/InteractionEndpointStructure.d.ts.map +0 -1
  253. package/dist/esm/interaction/InteractionEndpointStructure.js +0 -355
  254. package/dist/esm/interaction/InteractionEndpointStructure.js.map +0 -6
  255. package/src/cluster/server/AttributeServer.ts +0 -997
  256. package/src/cluster/server/ClusterDatasource.ts +0 -17
  257. package/src/cluster/server/ClusterServer.ts +0 -46
  258. package/src/cluster/server/CommandServer.ts +0 -89
  259. package/src/cluster/server/EventServer.ts +0 -202
  260. package/src/cluster/server/index.ts +0 -11
  261. package/src/endpoint/EndpointInterface.ts +0 -41
  262. package/src/endpoint/EndpointStructureLogger.ts +0 -270
  263. package/src/endpoint/index.ts +0 -8
  264. package/src/interaction/InteractionEndpointStructure.ts +0 -510
@@ -1,729 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright 2022-2025 Matter.js Authors
4
- * SPDX-License-Identifier: Apache-2.0
5
- */
6
- import {
7
- Diagnostic,
8
- ImplementationError,
9
- InternalError,
10
- Logger,
11
- MatterError,
12
- MaybePromise,
13
- camelize,
14
- isDeepEqual
15
- } from "#general";
16
- import { AccessLevel, AttributeModel, ClusterModel, DatatypeModel, FabricIndex, MatterModel } from "#model";
17
- import {
18
- StatusCode,
19
- StatusResponseError,
20
- ValidationError
21
- } from "#types";
22
- import { NoAssociatedFabricError, assertSecureSession } from "../../session/SecureSession.js";
23
- const logger = Logger.get("AttributeServer");
24
- const FabricIndexName = camelize(FabricIndex.name);
25
- class FabricScopeError extends MatterError {
26
- }
27
- function createAttributeServer(clusterDef, attributeDef, attributeName, initValue, datasource, getter, setter, validator) {
28
- const {
29
- id,
30
- schema,
31
- writable,
32
- fabricScoped,
33
- fixed,
34
- omitChanges,
35
- timed,
36
- default: defaultValue,
37
- readAcl,
38
- writeAcl
39
- } = attributeDef;
40
- if (fixed) {
41
- return new FixedAttributeServer(
42
- id,
43
- attributeName,
44
- readAcl,
45
- writeAcl,
46
- schema,
47
- writable,
48
- false,
49
- timed,
50
- initValue,
51
- defaultValue,
52
- datasource,
53
- getter
54
- );
55
- }
56
- if (fabricScoped) {
57
- return new FabricScopedAttributeServer(
58
- id,
59
- attributeName,
60
- readAcl,
61
- writeAcl,
62
- schema,
63
- writable,
64
- !omitChanges,
65
- timed,
66
- initValue,
67
- defaultValue,
68
- clusterDef,
69
- datasource,
70
- getter,
71
- setter,
72
- validator
73
- );
74
- }
75
- return new AttributeServer(
76
- id,
77
- attributeName,
78
- readAcl,
79
- writeAcl,
80
- schema,
81
- writable,
82
- !omitChanges,
83
- timed,
84
- initValue,
85
- defaultValue,
86
- datasource,
87
- getter,
88
- setter,
89
- validator
90
- );
91
- }
92
- class BaseAttributeServer {
93
- constructor(id, name, readAcl, writeAcl, schema, isWritable, isSubscribable, requiresTimedInteraction, initValue, defaultValue) {
94
- this.id = id;
95
- this.name = name;
96
- this.schema = schema;
97
- this.isWritable = isWritable;
98
- this.isSubscribable = isSubscribable;
99
- this.requiresTimedInteraction = requiresTimedInteraction;
100
- this.#readAcl = readAcl;
101
- this.#writeAcl = writeAcl;
102
- try {
103
- this.validateWithSchema(initValue);
104
- this.value = initValue;
105
- } catch (error) {
106
- logger.warn(
107
- `Attribute value to initialize for ${name} has an invalid value ${Diagnostic.json(
108
- initValue
109
- )}. Restore to default ${Diagnostic.json(defaultValue)}`
110
- );
111
- if (defaultValue === void 0) {
112
- throw new ImplementationError(`Attribute value to initialize for ${name} cannot be undefined.`);
113
- }
114
- this.validateWithSchema(defaultValue);
115
- this.value = defaultValue;
116
- }
117
- this.defaultValue = this.value;
118
- }
119
- /**
120
- * The value is undefined when getter/setter are used. But we still handle the version number here.
121
- */
122
- value = void 0;
123
- endpoint;
124
- defaultValue;
125
- #readAcl;
126
- #writeAcl;
127
- get hasFabricSensitiveData() {
128
- return false;
129
- }
130
- validateWithSchema(value) {
131
- try {
132
- this.schema.validate(value);
133
- } catch (e) {
134
- ValidationError.accept(e);
135
- e.message = `Validation error for attribute "${this.name}"${e.fieldName !== void 0 ? ` in field ${e.fieldName}` : ""}: ${e.message}`;
136
- throw e;
137
- }
138
- }
139
- assignToEndpoint(endpoint) {
140
- this.endpoint = endpoint;
141
- }
142
- get writeAcl() {
143
- return this.#writeAcl ?? AccessLevel.Operate;
144
- }
145
- get readAcl() {
146
- return this.#readAcl ?? AccessLevel.View;
147
- }
148
- }
149
- class FixedAttributeServer extends BaseAttributeServer {
150
- constructor(id, name, readAcl, writeAcl, schema, isWritable, isSubscribable, requiresTimedInteraction, initValue, defaultValue, datasource, getter) {
151
- super(
152
- id,
153
- name,
154
- readAcl,
155
- writeAcl,
156
- schema,
157
- isWritable,
158
- isSubscribable,
159
- requiresTimedInteraction,
160
- initValue,
161
- defaultValue
162
- );
163
- this.datasource = datasource;
164
- if (getter === void 0) {
165
- this.getter = () => {
166
- if (this.value === void 0) {
167
- throw new InternalError(`Attribute value for attribute "${name}" is not initialized.`);
168
- }
169
- return this.value;
170
- };
171
- } else {
172
- this.getter = getter;
173
- }
174
- }
175
- isFixed = true;
176
- getter;
177
- /**
178
- * Get the value of the attribute. This method is used by the Interaction model to read the value of the attribute
179
- * and includes the ACL check. It should not be used locally in the code!
180
- *
181
- * If a getter is defined the value is determined by that getter method.
182
- */
183
- get(session, isFabricFiltered, message) {
184
- return this.getter(session, this.endpoint, isFabricFiltered, message);
185
- }
186
- /**
187
- * Get the value of the attribute including the version number. This method is used by the Interaction model to read
188
- * the value of the attribute and includes the ACL check. It should not be used locally in the code!
189
- *
190
- * If a getter is defined the value is determined by that getter method. The version number is always 0 for fixed
191
- * attributes.
192
- */
193
- getWithVersion(session, isFabricFiltered, message) {
194
- return { version: this.datasource.version, value: this.get(session, isFabricFiltered, message) };
195
- }
196
- /**
197
- * Get the value of the attribute locally. This method should be used locally in the code and does not include the
198
- * ACL check.
199
- * If a getter is defined the value is determined by that getter method.
200
- */
201
- getLocal() {
202
- return this.getter(void 0, this.endpoint);
203
- }
204
- /**
205
- * Initialize the value of the attribute, used when a persisted value is set initially or when values needs to be
206
- * adjusted before the Device gets announced. Do not use this method to change values when the device is in use!
207
- * If a getter or setter is defined the value must be undefined The version number must also be undefined.
208
- */
209
- init(value) {
210
- if (value === void 0) {
211
- throw new InternalError(`Cannot initialize fixed attribute "${this.name}" with undefined value.`);
212
- }
213
- this.validateWithSchema(value);
214
- this.value = value;
215
- }
216
- /**
217
- * Add an internal listener that is called when the value of the attribute changes. The listener is called with the
218
- * new value and the version number.
219
- */
220
- addValueChangeListener(_listener) {
221
- }
222
- /**
223
- * Remove an internal listener.
224
- */
225
- removeValueChangeListener(_listener) {
226
- }
227
- /**
228
- * Add an external listener that is called when the value of the attribute changes. The listener is called with the
229
- * new value and the old value.
230
- */
231
- addValueSetListener(_listener) {
232
- }
233
- /**
234
- * Add an external listener that is called when the value of the attribute changes. The listener is called with the
235
- * new value and the old value. This method is a convenient alias for addValueSetListener.
236
- */
237
- subscribe(_listener) {
238
- }
239
- /**
240
- * Remove an external listener.
241
- */
242
- removeValueSetListener(_listener) {
243
- }
244
- }
245
- class AttributeServer extends FixedAttributeServer {
246
- isFixed = false;
247
- valueChangeListeners = new Array();
248
- valueSetListeners = new Array();
249
- setter;
250
- validator;
251
- delayedChangeData = void 0;
252
- constructor(id, name, readAcl, writeAcl, schema, isWritable, isSubscribable, requiresTimedInteraction, initValue, defaultValue, datasource, getter, setter, validator) {
253
- if (isWritable && (getter === void 0 || setter === void 0) && !(getter === void 0 && setter === void 0)) {
254
- throw new ImplementationError(
255
- `Getter and setter must be implemented together for writeable attribute "${name}".`
256
- );
257
- }
258
- super(
259
- id,
260
- name,
261
- readAcl,
262
- writeAcl,
263
- schema,
264
- isWritable,
265
- isSubscribable,
266
- requiresTimedInteraction,
267
- initValue,
268
- defaultValue,
269
- datasource,
270
- getter
271
- );
272
- if (setter === void 0) {
273
- this.setter = (value) => {
274
- const oldValue = this.value;
275
- this.value = value;
276
- return !isDeepEqual(value, oldValue);
277
- };
278
- } else {
279
- this.setter = setter;
280
- }
281
- this.validator = (value, session, endpoint) => {
282
- this.validateWithSchema(value);
283
- if (validator !== void 0) {
284
- validator(value, session, endpoint);
285
- }
286
- };
287
- }
288
- /**
289
- * Initialize the value of the attribute, used when a persisted value is set initially or when values needs to be
290
- * adjusted before the Device gets announced. Do not use this method to change values when the device is in use!
291
- */
292
- init(value) {
293
- if (value === void 0) {
294
- value = this.getter(void 0, this.endpoint);
295
- }
296
- if (value === void 0) {
297
- throw new InternalError(`Cannot initialize attribute "${this.name}" with undefined value.`);
298
- }
299
- this.validator(value, void 0, this.endpoint);
300
- this.value = value;
301
- }
302
- /**
303
- * Set the value of the attribute. This method is used by the Interaction model to write the value of the attribute
304
- * and includes the ACL check. It should not be used locally in the code!
305
- *
306
- * If a setter is defined this setter method is called to store the value.
307
- *
308
- * Listeners are called when the value changes (internal listeners) or in any case (external listeners).
309
- */
310
- set(value, session, message, delayChangeEvents = false) {
311
- if (!this.isWritable) {
312
- throw new StatusResponseError(`Attribute "${this.name}" is not writable.`, StatusCode.UnsupportedWrite);
313
- }
314
- this.setRemote(value, session, message, delayChangeEvents);
315
- }
316
- /**
317
- * Method that contains the logic to set a value "from remote" (e.g. from a client).
318
- */
319
- setRemote(value, session, message, delayChangeEvents = false) {
320
- this.processSet(value, session, message, delayChangeEvents);
321
- this.value = value;
322
- }
323
- /**
324
- * Set the value of the attribute locally. This method should be used locally in the code and does not include the
325
- * ACL check.
326
- *
327
- * If a setter is defined this setter method is called to validate and store the value.
328
- *
329
- * Else if a validator is defined the value is validated before it is stored.
330
- *
331
- * Listeners are called when the value changes (internal listeners) or in any case (external listeners).
332
- */
333
- setLocal(value) {
334
- this.processSet(value, void 0);
335
- this.value = value;
336
- }
337
- /**
338
- * Helper Method to process the set of a value in a generic way. This method is used internally.
339
- */
340
- processSet(value, session, message, delayChangeEvents = false) {
341
- this.validator(value, session, this.endpoint);
342
- const oldValue = this.getter(session, this.endpoint, void 0, message);
343
- const valueChanged = this.setter(value, session, this.endpoint, message);
344
- if (delayChangeEvents) {
345
- this.delayedChangeData = {
346
- oldValue: this.delayedChangeData?.oldValue ?? oldValue,
347
- // We keep the oldest value
348
- newValue: value,
349
- changed: !!this.delayedChangeData?.changed || valueChanged
350
- // We combine the changed flag
351
- };
352
- logger.info(`Delay change for attribute "${this.name}" with value ${Diagnostic.json(value)}`);
353
- } else {
354
- this.handleVersionAndTriggerListeners(value, oldValue, valueChanged);
355
- }
356
- }
357
- triggerDelayedChangeEvents() {
358
- if (this.delayedChangeData !== void 0) {
359
- const { oldValue, newValue, changed } = this.delayedChangeData;
360
- this.delayedChangeData = void 0;
361
- logger.info(`Trigger delayed change for attribute "${this.name}" with value ${Diagnostic.json(newValue)}`);
362
- this.handleVersionAndTriggerListeners(newValue, oldValue, changed);
363
- }
364
- }
365
- /**
366
- * Helper Method to handle needed version increases and trigger the relevant listeners. This method is used
367
- * internally.
368
- */
369
- handleVersionAndTriggerListeners(value, oldValue, considerVersionChanged) {
370
- if (considerVersionChanged) {
371
- const version = this.datasource.increaseVersion();
372
- this.valueChangeListeners.forEach((listener) => listener(value, version));
373
- }
374
- if (oldValue !== void 0) {
375
- this.valueSetListeners.forEach((listener) => listener(value, oldValue));
376
- }
377
- }
378
- /**
379
- * When the value is handled by getter or setter methods and is changed by other processes this method can be used
380
- * to notify the attribute server that the value has changed. This will increase the version number and trigger the
381
- * listeners.
382
- *
383
- * ACL checks needs to be performed before calling this method.
384
- */
385
- updated(session) {
386
- const oldValue = this.value ?? this.defaultValue;
387
- try {
388
- this.value = this.get(session, false);
389
- } catch (e) {
390
- NoAssociatedFabricError.accept(e);
391
- if (this.value === void 0) {
392
- this.value = this.defaultValue;
393
- }
394
- }
395
- this.handleVersionAndTriggerListeners(this.value, oldValue, true);
396
- }
397
- /**
398
- * When the value is handled by getter or setter methods and is changed by other processes and no session from the
399
- * originating process is known this method can be used to notify the attribute server that the value has changed.
400
- * This will increase the version number and trigger the listeners.
401
- *
402
- * ACL checks needs to be performed before calling this method.
403
- */
404
- updatedLocal() {
405
- const oldValue = this.value ?? this.defaultValue;
406
- this.value = this.getLocal();
407
- this.handleVersionAndTriggerListeners(this.value, oldValue, true);
408
- }
409
- /**
410
- * Add an internal listener that is called when the value of the attribute changes. The listener is called with the
411
- * new value and the version number.
412
- */
413
- addValueChangeListener(listener) {
414
- this.valueChangeListeners.push(listener);
415
- }
416
- /**
417
- * Remove an internal listener.
418
- */
419
- removeValueChangeListener(listener) {
420
- const entryIndex = this.valueChangeListeners.indexOf(listener);
421
- if (entryIndex !== -1) {
422
- this.valueChangeListeners.splice(entryIndex, 1);
423
- }
424
- }
425
- /**
426
- * Add an external listener that is called when the value of the attribute changes. The listener is called with the
427
- * new value and the old value.
428
- */
429
- addValueSetListener(listener) {
430
- this.valueSetListeners.push(listener);
431
- }
432
- /**
433
- * Add an external listener that is called when the value of the attribute changes. The listener is called with the
434
- * new value and the old value. This method is a convenient alias for addValueSetListener.
435
- */
436
- subscribe(listener) {
437
- this.addValueSetListener(listener);
438
- }
439
- /**
440
- * Remove an external listener.
441
- */
442
- removeValueSetListener(listener) {
443
- const entryIndex = this.valueSetListeners.indexOf(listener);
444
- if (entryIndex !== -1) {
445
- this.valueSetListeners.splice(entryIndex, 1);
446
- }
447
- }
448
- }
449
- function genericFabricScopedAttributeGetterFromFabric(fabric, cluster, attributeName, defaultValue) {
450
- const data = fabric.getScopedClusterDataValue(cluster, attributeName);
451
- return data?.value ?? defaultValue;
452
- }
453
- function genericFabricScopedAttributeGetter(session, isFabricFiltered, cluster, attributeName, defaultValue, fabrics) {
454
- if (session === void 0) {
455
- throw new FabricScopeError(`Session is required for fabric scoped attribute ${attributeName}`);
456
- }
457
- if (isFabricFiltered) {
458
- assertSecureSession(session);
459
- return genericFabricScopedAttributeGetterFromFabric(
460
- session.associatedFabric,
461
- cluster,
462
- attributeName,
463
- defaultValue
464
- );
465
- } else {
466
- const values = new Array();
467
- for (const fabric of fabrics) {
468
- const value = genericFabricScopedAttributeGetterFromFabric(fabric, cluster, attributeName, defaultValue);
469
- if (!Array.isArray(value)) {
470
- throw new FabricScopeError(
471
- `Fabric scoped attribute "${attributeName}" can only be read for all fabrics if they are arrays.`
472
- );
473
- }
474
- values.push(...value);
475
- }
476
- return values;
477
- }
478
- }
479
- function genericFabricScopedAttributeSetterForFabric(fabric, cluster, attributeName, value, defaultValue) {
480
- const oldValue = genericFabricScopedAttributeGetterFromFabric(fabric, cluster, attributeName, defaultValue);
481
- if (!isDeepEqual(value, oldValue)) {
482
- const setResult = fabric.setScopedClusterDataValue(cluster, attributeName, { value });
483
- if (MaybePromise.is(setResult)) {
484
- throw new ImplementationError(
485
- "Seems like an Asynchronous Storage is used with Legacy code paths which is forbidden!"
486
- );
487
- }
488
- return true;
489
- }
490
- return false;
491
- }
492
- function genericFabricScopedAttributeSetter(value, session, cluster, attributeName, defaultValue) {
493
- if (session === void 0) {
494
- throw new FabricScopeError(`Session is required for fabric scoped attribute "${attributeName}".`);
495
- }
496
- assertSecureSession(session);
497
- const fabric = session.associatedFabric;
498
- return genericFabricScopedAttributeSetterForFabric(fabric, cluster, attributeName, value, defaultValue);
499
- }
500
- class FabricScopedAttributeServer extends AttributeServer {
501
- constructor(id, name, readAcl, writeAcl, schema, isWritable, isSubscribable, requiresTimedInteraction, initValue, defaultValue, cluster, datasource, getter, setter, validator) {
502
- if (isWritable && (getter === void 0 || setter === void 0) && !(getter === void 0 && setter === void 0)) {
503
- throw new ImplementationError(
504
- `Getter and setter must be implemented together for writeable fabric scoped attribute "${name}".`
505
- );
506
- }
507
- let isCustomGetter = false;
508
- if (getter === void 0) {
509
- getter = (session, _endpoint, isFabricFiltered) => {
510
- if (session === void 0)
511
- throw new FabricScopeError(`Session is required for fabric scoped attribute ${name}`);
512
- if (isFabricFiltered === true) {
513
- assertSecureSession(session);
514
- return this.getLocalForFabric(session.associatedFabric);
515
- } else {
516
- const values = new Array();
517
- for (const fabric of datasource.fabrics) {
518
- const value = this.getLocalForFabric(fabric);
519
- if (!Array.isArray(value)) {
520
- throw new FabricScopeError(
521
- `Fabric scoped attribute "${name}" can only be read for all fabrics if they are arrays.`
522
- );
523
- }
524
- values.push(...value);
525
- }
526
- return values;
527
- }
528
- };
529
- } else {
530
- isCustomGetter = true;
531
- }
532
- let isCustomSetter = false;
533
- if (setter === void 0) {
534
- setter = (value, session) => genericFabricScopedAttributeSetter(value, session, this.cluster, this.name, this.defaultValue);
535
- } else {
536
- isCustomSetter = true;
537
- }
538
- super(
539
- id,
540
- name,
541
- readAcl,
542
- writeAcl,
543
- schema,
544
- isWritable,
545
- isSubscribable,
546
- requiresTimedInteraction,
547
- initValue,
548
- defaultValue,
549
- datasource,
550
- getter,
551
- setter,
552
- validator
553
- );
554
- this.cluster = cluster;
555
- this.isCustomGetter = isCustomGetter;
556
- this.isCustomSetter = isCustomSetter;
557
- this.#determineSensitiveFieldsToRemove();
558
- }
559
- isCustomGetter;
560
- isCustomSetter;
561
- fabricSensitiveElementsToRemove = new Array();
562
- #determineSensitiveFieldsToRemove() {
563
- const clusterFromModel = MatterModel.standard.get(ClusterModel, this.cluster.id);
564
- if (clusterFromModel === void 0) {
565
- logger.debug(`${this.cluster.name}: Cluster for Fabric scoped element not found in Model, ignore`);
566
- return;
567
- }
568
- const attributeFromModel = clusterFromModel.get(AttributeModel, this.id);
569
- if (attributeFromModel === void 0) {
570
- logger.debug(
571
- `${this.cluster.name}.${this.id}: Attribute for Fabric scoped element not found in Model, ignore`
572
- );
573
- return;
574
- }
575
- if (!attributeFromModel.fabricScoped) {
576
- logger.debug(`${this.cluster.name}.${this.id}: Attribute is not Fabric scoped in model, ignore`);
577
- return;
578
- }
579
- if (attributeFromModel.children.length !== 1) {
580
- logger.debug(`${this.cluster.name}.${this.id}: Attribute has not exactly one child, ignore`);
581
- return;
582
- }
583
- const type = attributeFromModel.children[0].type;
584
- if (type === void 0) {
585
- logger.debug(`${this.cluster.name}.${this.id}: Attribute field has no type, ignore`);
586
- return;
587
- }
588
- const dataType = clusterFromModel.get(DatatypeModel, type);
589
- if (dataType === void 0) {
590
- logger.debug(`${this.cluster.name}.${this.id}: DataType ${type} not found in model, ignore`);
591
- return;
592
- }
593
- dataType.children.filter((field) => field.fabricSensitive).forEach((field) => this.fabricSensitiveElementsToRemove.push(camelize(field.name)));
594
- }
595
- get hasFabricSensitiveData() {
596
- return this.fabricSensitiveElementsToRemove.length > 0;
597
- }
598
- /**
599
- * Sanitize the value of the attribute by removing fabric sensitive fields that do not belong to the
600
- * associated fabric
601
- */
602
- sanitizeFabricSensitiveFields(value, associatedFabric) {
603
- if (this.fabricSensitiveElementsToRemove.length && Array.isArray(value)) {
604
- const associatedFabricIndex = associatedFabric?.fabricIndex ?? -1;
605
- return value.map((data) => {
606
- if (data[FabricIndexName] !== associatedFabricIndex) {
607
- const result = { ...data };
608
- this.fabricSensitiveElementsToRemove.forEach((fieldName) => delete result[fieldName]);
609
- return result;
610
- }
611
- return data;
612
- });
613
- }
614
- return value;
615
- }
616
- /**
617
- * Initialize the attribute with a value. Because the value is stored on fabric level this method only initializes
618
- * the version number.
619
- */
620
- init(value) {
621
- if (value !== void 0) {
622
- throw new InternalError(`Cannot initialize fabric scoped attribute "${this.name}" with a value.`);
623
- }
624
- }
625
- /**
626
- * Fabric scoped enhancement of set to allow setting special fabricindex locally.
627
- */
628
- set(value, session, message, delayChangeEvents = false, preserveFabricIndex = false) {
629
- if (!this.isWritable) {
630
- throw new StatusResponseError(`Attribute "${this.name}" is not writable.`, StatusCode.UnsupportedWrite);
631
- }
632
- this.setRemote(value, session, message, delayChangeEvents, preserveFabricIndex);
633
- }
634
- /**
635
- * Method that contains the logic to set a value "from remote" (e.g. from a client). For Fabric scoped attributes
636
- * we need to inject the fabric index into the value.
637
- */
638
- setRemote(value, session, message, delayChangeEvents = false, preserveFabricIndex = false) {
639
- value = this.schema.injectField(
640
- value,
641
- FabricIndex.id,
642
- session.associatedFabric.fabricIndex,
643
- () => !preserveFabricIndex
644
- // No one should send any index and if we simply SHALL ignore it, but internally we might need it
645
- );
646
- logger.info(
647
- `Set remote value for fabric scoped attribute "${this.name}" to ${Diagnostic.json(value)} (delayed=${delayChangeEvents})`
648
- );
649
- super.setRemote(value, session, message, delayChangeEvents);
650
- }
651
- /**
652
- * Set Local is not allowed for fabric scoped attributes. Use setLocalForFabric instead.
653
- */
654
- setLocal(_value) {
655
- throw new FabricScopeError(
656
- `Fabric scoped attribute "${this.name}" can only be set locally by providing a Fabric. Use setLocalForFabric instead.`
657
- );
658
- }
659
- /**
660
- * Set the value of the attribute locally for a fabric. This method should be used locally in the code and does not
661
- * include the ACL check.
662
- * If a setter is defined this method cannot be used!
663
- * If a validator is defined the value is validated before it is stored.
664
- * Listeners are called when the value changes (internal listeners) or in any case (external listeners).
665
- */
666
- setLocalForFabric(value, fabric) {
667
- if (this.isCustomSetter) {
668
- throw new FabricScopeError(
669
- `Fabric scoped attribute "${this.name}" cannot be set locally when a custom setter is defined.`
670
- );
671
- }
672
- this.validator(value, void 0, this.endpoint);
673
- const oldValue = this.getLocalForFabric(fabric);
674
- const valueChanged = !isDeepEqual(value, oldValue);
675
- if (valueChanged) {
676
- const setResult = fabric.setScopedClusterDataValue(this.cluster, this.name, { value });
677
- if (MaybePromise.is(setResult)) {
678
- throw new ImplementationError(
679
- "Seems like an Asynchronous Storage is used with Legacy code paths which is forbidden!"
680
- );
681
- }
682
- }
683
- this.handleVersionAndTriggerListeners(value, oldValue, valueChanged);
684
- }
685
- /**
686
- * When the value is handled by getter or setter methods and is changed by other processes and no session from the
687
- * originating process is known this method can be used to notify the attribute server that the value has changed.
688
- * This will increase the version number and trigger the listeners.
689
- * ACL checks needs to be performed before calling this method.
690
- */
691
- updatedLocalForFabric(fabric) {
692
- const oldValue = this.value ?? this.defaultValue;
693
- try {
694
- this.value = this.getLocalForFabric(fabric);
695
- } catch (e) {
696
- FabricScopeError.accept(e);
697
- if (this.value === void 0) {
698
- this.value = this.defaultValue;
699
- }
700
- }
701
- this.handleVersionAndTriggerListeners(this.value, oldValue, true);
702
- }
703
- /**
704
- * Get the value of the attribute locally for a special Fabric. This method should be used locally in the code and
705
- * does not include the ACL check.
706
- * If a getter is defined this method returns an error and the value should be retrieved directly internally.
707
- */
708
- getLocalForFabric(fabric) {
709
- if (this.isCustomGetter) {
710
- throw new FabricScopeError(
711
- `Fabric scoped attribute "${this.name}" cannot be read locally when a custom getter is defined.`
712
- );
713
- }
714
- return genericFabricScopedAttributeGetterFromFabric(fabric, this.cluster, this.name, this.defaultValue);
715
- }
716
- }
717
- export {
718
- AttributeServer,
719
- BaseAttributeServer,
720
- FabricScopeError,
721
- FabricScopedAttributeServer,
722
- FixedAttributeServer,
723
- createAttributeServer,
724
- genericFabricScopedAttributeGetter,
725
- genericFabricScopedAttributeGetterFromFabric,
726
- genericFabricScopedAttributeSetter,
727
- genericFabricScopedAttributeSetterForFabric
728
- };
729
- //# sourceMappingURL=AttributeServer.js.map