@matter/protocol 0.13.1-alpha.0-20250517-99a1e848a → 0.14.0-alpha.0-20250521-979eda05d

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