@matter/node 0.18.0 → 0.18.1-alpha.0-20261111-b89790712

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 (353) hide show
  1. package/dist/cjs/behavior/Behavior.d.ts.map +1 -1
  2. package/dist/cjs/behavior/Behavior.js +2 -0
  3. package/dist/cjs/behavior/Behavior.js.map +1 -1
  4. package/dist/cjs/behavior/Events.d.ts.map +1 -1
  5. package/dist/cjs/behavior/Events.js +4 -2
  6. package/dist/cjs/behavior/Events.js.map +1 -1
  7. package/dist/cjs/behavior/cluster/ClusterBehavior.d.ts +17 -3
  8. package/dist/cjs/behavior/cluster/ClusterBehavior.d.ts.map +1 -1
  9. package/dist/cjs/behavior/cluster/ClusterBehavior.js +2 -20
  10. package/dist/cjs/behavior/cluster/ClusterBehavior.js.map +1 -1
  11. package/dist/cjs/behavior/cluster/ClusterBehaviorType.d.ts.map +1 -1
  12. package/dist/cjs/behavior/cluster/ClusterBehaviorType.js +8 -150
  13. package/dist/cjs/behavior/cluster/ClusterBehaviorType.js.map +1 -1
  14. package/dist/cjs/behavior/internal/BehaviorBacking.d.ts.map +1 -1
  15. package/dist/cjs/behavior/internal/BehaviorBacking.js +2 -0
  16. package/dist/cjs/behavior/internal/BehaviorBacking.js.map +1 -1
  17. package/dist/cjs/behavior/internal/ClusterDerivation.d.ts +45 -0
  18. package/dist/cjs/behavior/internal/ClusterDerivation.d.ts.map +1 -0
  19. package/dist/cjs/behavior/internal/ClusterDerivation.js +192 -0
  20. package/dist/cjs/behavior/internal/ClusterDerivation.js.map +6 -0
  21. package/dist/cjs/behavior/internal/ClusterStatics.d.ts +16 -0
  22. package/dist/cjs/behavior/internal/ClusterStatics.d.ts.map +1 -0
  23. package/dist/cjs/behavior/internal/ClusterStatics.js +138 -0
  24. package/dist/cjs/behavior/internal/ClusterStatics.js.map +6 -0
  25. package/dist/cjs/behavior/internal/ModeledState.d.ts +18 -0
  26. package/dist/cjs/behavior/internal/ModeledState.d.ts.map +1 -0
  27. package/dist/cjs/behavior/internal/ModeledState.js +54 -0
  28. package/dist/cjs/behavior/internal/ModeledState.js.map +6 -0
  29. package/dist/cjs/behavior/internal/ServerBehaviorBacking.d.ts.map +1 -1
  30. package/dist/cjs/behavior/internal/ServerBehaviorBacking.js +3 -12
  31. package/dist/cjs/behavior/internal/ServerBehaviorBacking.js.map +1 -1
  32. package/dist/cjs/behavior/state/managed/Datasource.js +28 -17
  33. package/dist/cjs/behavior/state/managed/Datasource.js.map +1 -1
  34. package/dist/cjs/behavior/state/managed/Internal.d.ts +16 -5
  35. package/dist/cjs/behavior/state/managed/Internal.d.ts.map +1 -1
  36. package/dist/cjs/behavior/state/managed/Internal.js +23 -25
  37. package/dist/cjs/behavior/state/managed/Internal.js.map +1 -1
  38. package/dist/cjs/behavior/state/managed/ManagedReference.d.ts +45 -12
  39. package/dist/cjs/behavior/state/managed/ManagedReference.d.ts.map +1 -1
  40. package/dist/cjs/behavior/state/managed/ManagedReference.js +74 -44
  41. package/dist/cjs/behavior/state/managed/ManagedReference.js.map +1 -1
  42. package/dist/cjs/behavior/state/managed/ReadOnlyReference.d.ts +31 -0
  43. package/dist/cjs/behavior/state/managed/ReadOnlyReference.d.ts.map +1 -0
  44. package/dist/cjs/behavior/state/managed/ReadOnlyReference.js +60 -0
  45. package/dist/cjs/behavior/state/managed/ReadOnlyReference.js.map +6 -0
  46. package/dist/cjs/behavior/state/managed/ValReference.d.ts +47 -10
  47. package/dist/cjs/behavior/state/managed/ValReference.d.ts.map +1 -1
  48. package/dist/cjs/behavior/state/managed/ValReference.js +29 -0
  49. package/dist/cjs/behavior/state/managed/ValReference.js.map +2 -2
  50. package/dist/cjs/behavior/state/managed/values/BitmapManager.js +5 -20
  51. package/dist/cjs/behavior/state/managed/values/BitmapManager.js.map +1 -1
  52. package/dist/cjs/behavior/state/managed/values/ListManager.d.ts.map +1 -1
  53. package/dist/cjs/behavior/state/managed/values/ListManager.js +262 -119
  54. package/dist/cjs/behavior/state/managed/values/ListManager.js.map +2 -2
  55. package/dist/cjs/behavior/state/managed/values/StructManager.js +14 -23
  56. package/dist/cjs/behavior/state/managed/values/StructManager.js.map +2 -2
  57. package/dist/cjs/behavior/system/commissioning/CommissioningClient.d.ts +13 -3
  58. package/dist/cjs/behavior/system/commissioning/CommissioningClient.d.ts.map +1 -1
  59. package/dist/cjs/behavior/system/commissioning/CommissioningClient.js +12 -0
  60. package/dist/cjs/behavior/system/commissioning/CommissioningClient.js.map +1 -1
  61. package/dist/cjs/behavior/system/commissioning/RemoteDescriptor.d.ts +9 -1
  62. package/dist/cjs/behavior/system/commissioning/RemoteDescriptor.d.ts.map +1 -1
  63. package/dist/cjs/behavior/system/commissioning/RemoteDescriptor.js +9 -0
  64. package/dist/cjs/behavior/system/commissioning/RemoteDescriptor.js.map +1 -1
  65. package/dist/cjs/behavior/system/controller/ControllerBehavior.d.ts +2 -1
  66. package/dist/cjs/behavior/system/controller/ControllerBehavior.d.ts.map +1 -1
  67. package/dist/cjs/behavior/system/controller/ControllerBehavior.js +2 -1
  68. package/dist/cjs/behavior/system/controller/ControllerBehavior.js.map +1 -1
  69. package/dist/cjs/behavior/system/dcl/DclBehavior.d.ts +3 -3
  70. package/dist/cjs/behavior/system/network/ServerGroupNetworking.d.ts +2 -1
  71. package/dist/cjs/behavior/system/network/ServerGroupNetworking.d.ts.map +1 -1
  72. package/dist/cjs/behavior/system/network/ServerGroupNetworking.js.map +1 -1
  73. package/dist/cjs/behavior/system/sessions/SessionsBehavior.d.ts +4 -0
  74. package/dist/cjs/behavior/system/sessions/SessionsBehavior.d.ts.map +1 -1
  75. package/dist/cjs/behavior/system/sessions/SessionsBehavior.js +6 -1
  76. package/dist/cjs/behavior/system/sessions/SessionsBehavior.js.map +1 -1
  77. package/dist/cjs/behavior/system/subscriptions/SubscriptionStore.d.ts +28 -0
  78. package/dist/cjs/behavior/system/subscriptions/SubscriptionStore.d.ts.map +1 -0
  79. package/dist/cjs/behavior/system/subscriptions/SubscriptionStore.js +74 -0
  80. package/dist/cjs/behavior/system/subscriptions/SubscriptionStore.js.map +6 -0
  81. package/dist/cjs/behavior/system/subscriptions/SubscriptionsServer.d.ts +8 -3
  82. package/dist/cjs/behavior/system/subscriptions/SubscriptionsServer.d.ts.map +1 -1
  83. package/dist/cjs/behavior/system/subscriptions/SubscriptionsServer.js +61 -30
  84. package/dist/cjs/behavior/system/subscriptions/SubscriptionsServer.js.map +1 -1
  85. package/dist/cjs/behaviors/access-control/AccessControlServer.d.ts +2 -2
  86. package/dist/cjs/behaviors/access-control/AccessControlServer.d.ts.map +1 -1
  87. package/dist/cjs/behaviors/administrator-commissioning/AdministratorCommissioningServer.d.ts.map +1 -1
  88. package/dist/cjs/behaviors/administrator-commissioning/AdministratorCommissioningServer.js +43 -21
  89. package/dist/cjs/behaviors/administrator-commissioning/AdministratorCommissioningServer.js.map +1 -1
  90. package/dist/cjs/behaviors/general-diagnostics/GeneralDiagnosticsServer.d.ts +29 -23
  91. package/dist/cjs/behaviors/general-diagnostics/GeneralDiagnosticsServer.d.ts.map +1 -1
  92. package/dist/cjs/behaviors/general-diagnostics/GeneralDiagnosticsServer.js +104 -60
  93. package/dist/cjs/behaviors/general-diagnostics/GeneralDiagnosticsServer.js.map +1 -1
  94. package/dist/cjs/behaviors/group-key-management/GroupKeyManagementServer.d.ts +9 -1
  95. package/dist/cjs/behaviors/group-key-management/GroupKeyManagementServer.d.ts.map +1 -1
  96. package/dist/cjs/behaviors/group-key-management/GroupKeyManagementServer.js +11 -7
  97. package/dist/cjs/behaviors/group-key-management/GroupKeyManagementServer.js.map +1 -1
  98. package/dist/cjs/behaviors/groupcast/GroupcastServer.d.ts.map +1 -1
  99. package/dist/cjs/behaviors/groupcast/GroupcastServer.js +41 -25
  100. package/dist/cjs/behaviors/groupcast/GroupcastServer.js.map +2 -2
  101. package/dist/cjs/behaviors/localization-configuration/LocalizationConfigurationServer.d.ts +1 -1
  102. package/dist/cjs/behaviors/localization-configuration/LocalizationConfigurationServer.d.ts.map +1 -1
  103. package/dist/cjs/behaviors/operational-credentials/VendorIdVerification.d.ts +2 -0
  104. package/dist/cjs/behaviors/operational-credentials/VendorIdVerification.d.ts.map +1 -1
  105. package/dist/cjs/behaviors/operational-credentials/VendorIdVerification.js +27 -23
  106. package/dist/cjs/behaviors/operational-credentials/VendorIdVerification.js.map +1 -1
  107. package/dist/cjs/behaviors/thermostat/ThermostatServer.d.ts +15 -4
  108. package/dist/cjs/behaviors/thermostat/ThermostatServer.d.ts.map +1 -1
  109. package/dist/cjs/behaviors/thermostat/ThermostatServer.js +66 -49
  110. package/dist/cjs/behaviors/thermostat/ThermostatServer.js.map +1 -1
  111. package/dist/cjs/behaviors/time-format-localization/TimeFormatLocalizationServer.d.ts +4 -4
  112. package/dist/cjs/behaviors/time-format-localization/TimeFormatLocalizationServer.d.ts.map +1 -1
  113. package/dist/cjs/behaviors/time-format-localization/TimeFormatLocalizationServer.js.map +1 -1
  114. package/dist/cjs/endpoint/properties/Behaviors.d.ts.map +1 -1
  115. package/dist/cjs/endpoint/properties/Behaviors.js +5 -1
  116. package/dist/cjs/endpoint/properties/Behaviors.js.map +1 -1
  117. package/dist/cjs/node/ClientNode.d.ts +6 -0
  118. package/dist/cjs/node/ClientNode.d.ts.map +1 -1
  119. package/dist/cjs/node/ClientNode.js +6 -0
  120. package/dist/cjs/node/ClientNode.js.map +1 -1
  121. package/dist/cjs/node/ServerNode.d.ts.map +1 -1
  122. package/dist/cjs/node/ServerNode.js +2 -0
  123. package/dist/cjs/node/ServerNode.js.map +1 -1
  124. package/dist/cjs/node/client/ClientEventEmitter.d.ts.map +1 -1
  125. package/dist/cjs/node/client/ClientEventEmitter.js +6 -2
  126. package/dist/cjs/node/client/ClientEventEmitter.js.map +1 -1
  127. package/dist/cjs/node/client/ClientStructure.d.ts.map +1 -1
  128. package/dist/cjs/node/client/ClientStructure.js +181 -108
  129. package/dist/cjs/node/client/ClientStructure.js.map +2 -2
  130. package/dist/cjs/node/client/Peers.d.ts +3 -2
  131. package/dist/cjs/node/client/Peers.d.ts.map +1 -1
  132. package/dist/cjs/node/client/Peers.js +8 -9
  133. package/dist/cjs/node/client/Peers.js.map +1 -1
  134. package/dist/cjs/node/integration/ChangeNotificationService.d.ts +14 -3
  135. package/dist/cjs/node/integration/ChangeNotificationService.d.ts.map +1 -1
  136. package/dist/cjs/node/integration/ProtocolService.d.ts.map +1 -1
  137. package/dist/cjs/node/integration/ProtocolService.js +38 -56
  138. package/dist/cjs/node/integration/ProtocolService.js.map +1 -1
  139. package/dist/cjs/node/server/InteractionServer.d.ts.map +1 -1
  140. package/dist/cjs/node/server/InteractionServer.js +28 -24
  141. package/dist/cjs/node/server/InteractionServer.js.map +2 -2
  142. package/dist/cjs/node/server/ServerSubscription.d.ts +7 -2
  143. package/dist/cjs/node/server/ServerSubscription.d.ts.map +1 -1
  144. package/dist/cjs/node/server/ServerSubscription.js +83 -47
  145. package/dist/cjs/node/server/ServerSubscription.js.map +1 -1
  146. package/dist/cjs/testing/mock-server-node.d.ts +2 -1
  147. package/dist/cjs/testing/mock-server-node.d.ts.map +1 -1
  148. package/dist/cjs/testing/mock-server-node.js +8 -5
  149. package/dist/cjs/testing/mock-server-node.js.map +2 -2
  150. package/dist/cjs/testing/node-helpers.d.ts +5 -0
  151. package/dist/cjs/testing/node-helpers.d.ts.map +1 -1
  152. package/dist/cjs/testing/node-helpers.js +4 -4
  153. package/dist/cjs/testing/node-helpers.js.map +1 -1
  154. package/dist/esm/behavior/Behavior.d.ts.map +1 -1
  155. package/dist/esm/behavior/Behavior.js +2 -0
  156. package/dist/esm/behavior/Behavior.js.map +1 -1
  157. package/dist/esm/behavior/Events.d.ts.map +1 -1
  158. package/dist/esm/behavior/Events.js +4 -2
  159. package/dist/esm/behavior/Events.js.map +1 -1
  160. package/dist/esm/behavior/cluster/ClusterBehavior.d.ts +17 -3
  161. package/dist/esm/behavior/cluster/ClusterBehavior.d.ts.map +1 -1
  162. package/dist/esm/behavior/cluster/ClusterBehavior.js +2 -20
  163. package/dist/esm/behavior/cluster/ClusterBehavior.js.map +1 -1
  164. package/dist/esm/behavior/cluster/ClusterBehaviorType.d.ts.map +1 -1
  165. package/dist/esm/behavior/cluster/ClusterBehaviorType.js +10 -159
  166. package/dist/esm/behavior/cluster/ClusterBehaviorType.js.map +1 -1
  167. package/dist/esm/behavior/internal/BehaviorBacking.d.ts.map +1 -1
  168. package/dist/esm/behavior/internal/BehaviorBacking.js +2 -0
  169. package/dist/esm/behavior/internal/BehaviorBacking.js.map +1 -1
  170. package/dist/esm/behavior/internal/ClusterDerivation.d.ts +45 -0
  171. package/dist/esm/behavior/internal/ClusterDerivation.d.ts.map +1 -0
  172. package/dist/esm/behavior/internal/ClusterDerivation.js +172 -0
  173. package/dist/esm/behavior/internal/ClusterDerivation.js.map +6 -0
  174. package/dist/esm/behavior/internal/ClusterStatics.d.ts +16 -0
  175. package/dist/esm/behavior/internal/ClusterStatics.d.ts.map +1 -0
  176. package/dist/esm/behavior/internal/ClusterStatics.js +118 -0
  177. package/dist/esm/behavior/internal/ClusterStatics.js.map +6 -0
  178. package/dist/esm/behavior/internal/ModeledState.d.ts +18 -0
  179. package/dist/esm/behavior/internal/ModeledState.d.ts.map +1 -0
  180. package/dist/esm/behavior/internal/ModeledState.js +34 -0
  181. package/dist/esm/behavior/internal/ModeledState.js.map +6 -0
  182. package/dist/esm/behavior/internal/ServerBehaviorBacking.d.ts.map +1 -1
  183. package/dist/esm/behavior/internal/ServerBehaviorBacking.js +3 -12
  184. package/dist/esm/behavior/internal/ServerBehaviorBacking.js.map +1 -1
  185. package/dist/esm/behavior/state/managed/Datasource.js +28 -17
  186. package/dist/esm/behavior/state/managed/Datasource.js.map +1 -1
  187. package/dist/esm/behavior/state/managed/Internal.d.ts +16 -5
  188. package/dist/esm/behavior/state/managed/Internal.d.ts.map +1 -1
  189. package/dist/esm/behavior/state/managed/Internal.js +23 -25
  190. package/dist/esm/behavior/state/managed/Internal.js.map +1 -1
  191. package/dist/esm/behavior/state/managed/ManagedReference.d.ts +45 -12
  192. package/dist/esm/behavior/state/managed/ManagedReference.d.ts.map +1 -1
  193. package/dist/esm/behavior/state/managed/ManagedReference.js +75 -45
  194. package/dist/esm/behavior/state/managed/ManagedReference.js.map +1 -1
  195. package/dist/esm/behavior/state/managed/ReadOnlyReference.d.ts +31 -0
  196. package/dist/esm/behavior/state/managed/ReadOnlyReference.d.ts.map +1 -0
  197. package/dist/esm/behavior/state/managed/ReadOnlyReference.js +40 -0
  198. package/dist/esm/behavior/state/managed/ReadOnlyReference.js.map +6 -0
  199. package/dist/esm/behavior/state/managed/ValReference.d.ts +47 -10
  200. package/dist/esm/behavior/state/managed/ValReference.d.ts.map +1 -1
  201. package/dist/esm/behavior/state/managed/ValReference.js +25 -0
  202. package/dist/esm/behavior/state/managed/ValReference.js.map +2 -2
  203. package/dist/esm/behavior/state/managed/values/BitmapManager.js +6 -21
  204. package/dist/esm/behavior/state/managed/values/BitmapManager.js.map +1 -1
  205. package/dist/esm/behavior/state/managed/values/ListManager.d.ts.map +1 -1
  206. package/dist/esm/behavior/state/managed/values/ListManager.js +264 -129
  207. package/dist/esm/behavior/state/managed/values/ListManager.js.map +2 -2
  208. package/dist/esm/behavior/state/managed/values/StructManager.js +15 -24
  209. package/dist/esm/behavior/state/managed/values/StructManager.js.map +2 -2
  210. package/dist/esm/behavior/system/commissioning/CommissioningClient.d.ts +13 -3
  211. package/dist/esm/behavior/system/commissioning/CommissioningClient.d.ts.map +1 -1
  212. package/dist/esm/behavior/system/commissioning/CommissioningClient.js +12 -0
  213. package/dist/esm/behavior/system/commissioning/CommissioningClient.js.map +1 -1
  214. package/dist/esm/behavior/system/commissioning/RemoteDescriptor.d.ts +9 -1
  215. package/dist/esm/behavior/system/commissioning/RemoteDescriptor.d.ts.map +1 -1
  216. package/dist/esm/behavior/system/commissioning/RemoteDescriptor.js +10 -1
  217. package/dist/esm/behavior/system/commissioning/RemoteDescriptor.js.map +1 -1
  218. package/dist/esm/behavior/system/controller/ControllerBehavior.d.ts +2 -1
  219. package/dist/esm/behavior/system/controller/ControllerBehavior.d.ts.map +1 -1
  220. package/dist/esm/behavior/system/controller/ControllerBehavior.js +2 -1
  221. package/dist/esm/behavior/system/controller/ControllerBehavior.js.map +1 -1
  222. package/dist/esm/behavior/system/dcl/DclBehavior.d.ts +3 -3
  223. package/dist/esm/behavior/system/network/ServerGroupNetworking.d.ts +2 -1
  224. package/dist/esm/behavior/system/network/ServerGroupNetworking.d.ts.map +1 -1
  225. package/dist/esm/behavior/system/network/ServerGroupNetworking.js.map +1 -1
  226. package/dist/esm/behavior/system/sessions/SessionsBehavior.d.ts +4 -0
  227. package/dist/esm/behavior/system/sessions/SessionsBehavior.d.ts.map +1 -1
  228. package/dist/esm/behavior/system/sessions/SessionsBehavior.js +6 -1
  229. package/dist/esm/behavior/system/sessions/SessionsBehavior.js.map +1 -1
  230. package/dist/esm/behavior/system/subscriptions/SubscriptionStore.d.ts +28 -0
  231. package/dist/esm/behavior/system/subscriptions/SubscriptionStore.d.ts.map +1 -0
  232. package/dist/esm/behavior/system/subscriptions/SubscriptionStore.js +54 -0
  233. package/dist/esm/behavior/system/subscriptions/SubscriptionStore.js.map +6 -0
  234. package/dist/esm/behavior/system/subscriptions/SubscriptionsServer.d.ts +8 -3
  235. package/dist/esm/behavior/system/subscriptions/SubscriptionsServer.d.ts.map +1 -1
  236. package/dist/esm/behavior/system/subscriptions/SubscriptionsServer.js +61 -30
  237. package/dist/esm/behavior/system/subscriptions/SubscriptionsServer.js.map +1 -1
  238. package/dist/esm/behaviors/access-control/AccessControlServer.d.ts +2 -2
  239. package/dist/esm/behaviors/access-control/AccessControlServer.d.ts.map +1 -1
  240. package/dist/esm/behaviors/administrator-commissioning/AdministratorCommissioningServer.d.ts.map +1 -1
  241. package/dist/esm/behaviors/administrator-commissioning/AdministratorCommissioningServer.js +43 -21
  242. package/dist/esm/behaviors/administrator-commissioning/AdministratorCommissioningServer.js.map +1 -1
  243. package/dist/esm/behaviors/general-diagnostics/GeneralDiagnosticsServer.d.ts +29 -23
  244. package/dist/esm/behaviors/general-diagnostics/GeneralDiagnosticsServer.d.ts.map +1 -1
  245. package/dist/esm/behaviors/general-diagnostics/GeneralDiagnosticsServer.js +105 -60
  246. package/dist/esm/behaviors/general-diagnostics/GeneralDiagnosticsServer.js.map +1 -1
  247. package/dist/esm/behaviors/group-key-management/GroupKeyManagementServer.d.ts +9 -1
  248. package/dist/esm/behaviors/group-key-management/GroupKeyManagementServer.d.ts.map +1 -1
  249. package/dist/esm/behaviors/group-key-management/GroupKeyManagementServer.js +11 -7
  250. package/dist/esm/behaviors/group-key-management/GroupKeyManagementServer.js.map +1 -1
  251. package/dist/esm/behaviors/groupcast/GroupcastServer.d.ts.map +1 -1
  252. package/dist/esm/behaviors/groupcast/GroupcastServer.js +42 -25
  253. package/dist/esm/behaviors/groupcast/GroupcastServer.js.map +2 -2
  254. package/dist/esm/behaviors/localization-configuration/LocalizationConfigurationServer.d.ts +1 -1
  255. package/dist/esm/behaviors/localization-configuration/LocalizationConfigurationServer.d.ts.map +1 -1
  256. package/dist/esm/behaviors/operational-credentials/VendorIdVerification.d.ts +2 -0
  257. package/dist/esm/behaviors/operational-credentials/VendorIdVerification.d.ts.map +1 -1
  258. package/dist/esm/behaviors/operational-credentials/VendorIdVerification.js +32 -24
  259. package/dist/esm/behaviors/operational-credentials/VendorIdVerification.js.map +1 -1
  260. package/dist/esm/behaviors/thermostat/ThermostatServer.d.ts +15 -4
  261. package/dist/esm/behaviors/thermostat/ThermostatServer.d.ts.map +1 -1
  262. package/dist/esm/behaviors/thermostat/ThermostatServer.js +66 -49
  263. package/dist/esm/behaviors/thermostat/ThermostatServer.js.map +1 -1
  264. package/dist/esm/behaviors/time-format-localization/TimeFormatLocalizationServer.d.ts +4 -4
  265. package/dist/esm/behaviors/time-format-localization/TimeFormatLocalizationServer.d.ts.map +1 -1
  266. package/dist/esm/behaviors/time-format-localization/TimeFormatLocalizationServer.js.map +1 -1
  267. package/dist/esm/endpoint/properties/Behaviors.d.ts.map +1 -1
  268. package/dist/esm/endpoint/properties/Behaviors.js +6 -2
  269. package/dist/esm/endpoint/properties/Behaviors.js.map +1 -1
  270. package/dist/esm/node/ClientNode.d.ts +6 -0
  271. package/dist/esm/node/ClientNode.d.ts.map +1 -1
  272. package/dist/esm/node/ClientNode.js +6 -0
  273. package/dist/esm/node/ClientNode.js.map +1 -1
  274. package/dist/esm/node/ServerNode.d.ts.map +1 -1
  275. package/dist/esm/node/ServerNode.js +2 -0
  276. package/dist/esm/node/ServerNode.js.map +1 -1
  277. package/dist/esm/node/client/ClientEventEmitter.d.ts.map +1 -1
  278. package/dist/esm/node/client/ClientEventEmitter.js +6 -2
  279. package/dist/esm/node/client/ClientEventEmitter.js.map +1 -1
  280. package/dist/esm/node/client/ClientStructure.d.ts.map +1 -1
  281. package/dist/esm/node/client/ClientStructure.js +181 -108
  282. package/dist/esm/node/client/ClientStructure.js.map +2 -2
  283. package/dist/esm/node/client/Peers.d.ts +3 -2
  284. package/dist/esm/node/client/Peers.d.ts.map +1 -1
  285. package/dist/esm/node/client/Peers.js +8 -10
  286. package/dist/esm/node/client/Peers.js.map +1 -1
  287. package/dist/esm/node/integration/ChangeNotificationService.d.ts +14 -3
  288. package/dist/esm/node/integration/ChangeNotificationService.d.ts.map +1 -1
  289. package/dist/esm/node/integration/ProtocolService.d.ts.map +1 -1
  290. package/dist/esm/node/integration/ProtocolService.js +40 -57
  291. package/dist/esm/node/integration/ProtocolService.js.map +1 -1
  292. package/dist/esm/node/server/InteractionServer.d.ts.map +1 -1
  293. package/dist/esm/node/server/InteractionServer.js +28 -25
  294. package/dist/esm/node/server/InteractionServer.js.map +2 -2
  295. package/dist/esm/node/server/ServerSubscription.d.ts +7 -2
  296. package/dist/esm/node/server/ServerSubscription.d.ts.map +1 -1
  297. package/dist/esm/node/server/ServerSubscription.js +83 -47
  298. package/dist/esm/node/server/ServerSubscription.js.map +1 -1
  299. package/dist/esm/testing/mock-server-node.d.ts +2 -1
  300. package/dist/esm/testing/mock-server-node.d.ts.map +1 -1
  301. package/dist/esm/testing/mock-server-node.js +16 -7
  302. package/dist/esm/testing/mock-server-node.js.map +2 -2
  303. package/dist/esm/testing/node-helpers.d.ts +5 -0
  304. package/dist/esm/testing/node-helpers.d.ts.map +1 -1
  305. package/dist/esm/testing/node-helpers.js +4 -4
  306. package/dist/esm/testing/node-helpers.js.map +1 -1
  307. package/package.json +6 -6
  308. package/src/behavior/Behavior.ts +2 -0
  309. package/src/behavior/Events.ts +6 -3
  310. package/src/behavior/cluster/ClusterBehavior.ts +22 -13
  311. package/src/behavior/cluster/ClusterBehaviorType.ts +9 -270
  312. package/src/behavior/internal/BehaviorBacking.ts +3 -0
  313. package/src/behavior/internal/ClusterDerivation.ts +295 -0
  314. package/src/behavior/internal/ClusterStatics.ts +180 -0
  315. package/src/behavior/internal/ModeledState.ts +58 -0
  316. package/src/behavior/internal/ServerBehaviorBacking.ts +3 -15
  317. package/src/behavior/state/managed/Datasource.ts +36 -21
  318. package/src/behavior/state/managed/Internal.ts +36 -33
  319. package/src/behavior/state/managed/ManagedReference.ts +120 -68
  320. package/src/behavior/state/managed/ReadOnlyReference.ts +54 -0
  321. package/src/behavior/state/managed/ValReference.ts +67 -11
  322. package/src/behavior/state/managed/values/BitmapManager.ts +6 -22
  323. package/src/behavior/state/managed/values/ListManager.ts +301 -146
  324. package/src/behavior/state/managed/values/StructManager.ts +20 -29
  325. package/src/behavior/system/commissioning/CommissioningClient.ts +22 -3
  326. package/src/behavior/system/commissioning/RemoteDescriptor.ts +17 -1
  327. package/src/behavior/system/controller/ControllerBehavior.ts +2 -1
  328. package/src/behavior/system/dcl/DclBehavior.ts +3 -3
  329. package/src/behavior/system/network/ServerGroupNetworking.ts +3 -2
  330. package/src/behavior/system/sessions/SessionsBehavior.ts +8 -2
  331. package/src/behavior/system/subscriptions/SubscriptionStore.ts +66 -0
  332. package/src/behavior/system/subscriptions/SubscriptionsServer.ts +73 -33
  333. package/src/behaviors/access-control/AccessControlServer.ts +3 -3
  334. package/src/behaviors/administrator-commissioning/AdministratorCommissioningServer.ts +47 -24
  335. package/src/behaviors/general-diagnostics/GeneralDiagnosticsServer.ts +138 -84
  336. package/src/behaviors/group-key-management/GroupKeyManagementServer.ts +12 -8
  337. package/src/behaviors/groupcast/GroupcastServer.ts +50 -34
  338. package/src/behaviors/localization-configuration/LocalizationConfigurationServer.ts +1 -1
  339. package/src/behaviors/operational-credentials/VendorIdVerification.ts +50 -35
  340. package/src/behaviors/thermostat/ThermostatServer.ts +93 -70
  341. package/src/behaviors/time-format-localization/TimeFormatLocalizationServer.ts +4 -4
  342. package/src/endpoint/properties/Behaviors.ts +6 -2
  343. package/src/node/ClientNode.ts +6 -0
  344. package/src/node/ServerNode.ts +2 -0
  345. package/src/node/client/ClientEventEmitter.ts +7 -3
  346. package/src/node/client/ClientStructure.ts +208 -135
  347. package/src/node/client/Peers.ts +10 -14
  348. package/src/node/integration/ChangeNotificationService.ts +18 -3
  349. package/src/node/integration/ProtocolService.ts +45 -57
  350. package/src/node/server/InteractionServer.ts +33 -35
  351. package/src/node/server/ServerSubscription.ts +88 -50
  352. package/src/testing/mock-server-node.ts +22 -9
  353. package/src/testing/node-helpers.ts +5 -1
@@ -7,7 +7,7 @@
7
7
  import { camelize, deepCopy, GeneratedClass, isObject } from "@matter/general";
8
8
  import type { Schema } from "@matter/model";
9
9
  import { ElementTag, FieldValue, MandatoryDefaultValue, Metatype, ValueModel } from "@matter/model";
10
- import { AccessControl, PhantomReferenceError, SchemaImplementationError, Val } from "@matter/protocol";
10
+ import { AccessControl, SchemaImplementationError, Val } from "@matter/protocol";
11
11
  import { FabricIndex } from "@matter/types";
12
12
  import { RootSupervisor } from "../../../supervision/RootSupervisor.js";
13
13
  import type { ValueSupervisor } from "../../../supervision/ValueSupervisor.js";
@@ -22,7 +22,7 @@ import {
22
22
  memberValueOf,
23
23
  } from "../MemberKeys.js";
24
24
  import { NameResolver } from "../NameResolver.js";
25
- import type { ValReference } from "../ValReference.js";
25
+ import { ValReference } from "../ValReference.js";
26
26
  import { isFabricScopedList } from "./ListManager.js";
27
27
  import { PrimitiveManager } from "./PrimitiveManager.js";
28
28
 
@@ -185,20 +185,21 @@ function configureProperty(supervisor: RootSupervisor, schema: ValueModel) {
185
185
 
186
186
  set(this: Struct, value: Val) {
187
187
  access.authorizeWrite(this[Internal.session], this[Internal.reference].location);
188
+ const container = ValReference.writableContainerOf(this[Internal.reference]);
188
189
 
189
190
  // We allow attribute/field name or id as key. If name is present id is ignored
190
191
  const pk = this[Internal.reference].primaryKey;
191
192
  let key = memberKeyFor(pk, name, id);
192
- let storedKey = memberSlotOf(this[Internal.reference].value, key, memberFallbackKeyFor(pk, name, id));
193
+ let storedKey = memberSlotOf(container, key, memberFallbackKeyFor(pk, name, id));
193
194
 
194
195
  // Rollback and the fabric-scoped-list merge check must see stored truth — never the write-migration
195
196
  // slot above and never a synthesized default
196
- const oldValue = memberValueOf(this[Internal.reference].value, key, memberReadFallbackKeyFor(pk, name, id));
197
+ const oldValue = memberValueOf(container, key, memberReadFallbackKeyFor(pk, name, id));
197
198
 
198
199
  const self = this;
199
200
 
200
201
  this[Internal.reference].change(() => {
201
- const struct = this[Internal.reference].value;
202
+ const struct = ValReference.containerOf(this[Internal.reference]);
202
203
 
203
204
  // Identify the target. Usually just "struct" except when struct supports Val.Dynamic
204
205
  let target;
@@ -214,9 +215,9 @@ function configureProperty(supervisor: RootSupervisor, schema: ValueModel) {
214
215
  if (fabricScopedList || validate) {
215
216
  // A dynamic member's previous value lives in the provider, not the container slot;
216
217
  // read it only when rollback or the fabric-scoped merge check may consume it, as the
217
- // provider's getter may be costly. Unmanage in case the provider serves a managed
218
- // value — rollback must not plant a proxy that expires with this session
219
- previousValue = Internal.unmanage(properties[name]);
218
+ // provider's getter may be costly. Unwrap in case the provider serves a managed value —
219
+ // rollback must not plant a proxy that expires with this session
220
+ previousValue = Internal.rawOf(properties[name]);
220
221
  }
221
222
  } else {
222
223
  target = struct;
@@ -225,8 +226,7 @@ function configureProperty(supervisor: RootSupervisor, schema: ValueModel) {
225
226
  target = struct;
226
227
  }
227
228
 
228
- // Unwrap if incoming value (or nested children) is managed
229
- value = Internal.unmanage(value);
229
+ value = Internal.copy(value);
230
230
 
231
231
  // Undo our change on error. Rollback will take care of this when transactional but this handles the
232
232
  // cases of 1.) no transaction, and 2.) error is caught within transaction. A previously absent member
@@ -243,11 +243,14 @@ function configureProperty(supervisor: RootSupervisor, schema: ValueModel) {
243
243
  if (fabricScopedList && Array.isArray(value)) {
244
244
  // The merge must run through the proxy even for an absent member; it is what filters by fabric
245
245
  // and supplies the accessing fabric
246
- if (previousValue === undefined) {
246
+ if (previousValue === undefined || previousValue === null) {
247
247
  target[key] = [];
248
248
  if (storedKey !== undefined && storedKey !== key) {
249
249
  delete target[storedKey];
250
250
  }
251
+
252
+ // The direct write above bypasses the cached reference; the merge below reads through it
253
+ this[Internal.reference].subrefs?.[memberKeyFor(pk, name, id)]?.refresh("session");
251
254
  }
252
255
 
253
256
  // In the case of fabric-scoped write to established list we use the managed proxy to perform update
@@ -258,6 +261,9 @@ function configureProperty(supervisor: RootSupervisor, schema: ValueModel) {
258
261
  proxy[i] = value[i];
259
262
  }
260
263
  proxy.length = value.length;
264
+
265
+ // The list prepared copies of the entries, so validate those
266
+ value = Array.from(proxy, Internal.copy);
261
267
  } catch (e) {
262
268
  undo();
263
269
  throw e;
@@ -298,10 +304,7 @@ function configureProperty(supervisor: RootSupervisor, schema: ValueModel) {
298
304
  // For primitives, we don't need a manager so just proxy reads directly
299
305
  descriptor.get = function (this: Struct) {
300
306
  if (access.mayRead(this[Internal.session], this[Internal.reference].location)) {
301
- const struct = this[Internal.reference].value as Val.Dynamic;
302
- if (struct === undefined) {
303
- throw new PhantomReferenceError(this[Internal.reference].location);
304
- }
307
+ const struct = ValReference.containerOf(this[Internal.reference]) as Val.Dynamic;
305
308
  if (struct[Val.properties]) {
306
309
  const properties = struct[Val.properties](
307
310
  this[Internal.reference].rootOwner,
@@ -350,7 +353,7 @@ function configureProperty(supervisor: RootSupervisor, schema: ValueModel) {
350
353
  let value;
351
354
 
352
355
  // Obtain the value. Normally just struct[key] except in the case of Val.Dynamic
353
- const struct = this[Internal.reference].value;
356
+ const struct = ValReference.containerOf(this[Internal.reference]);
354
357
  const primaryKey = this[Internal.reference].primaryKey;
355
358
  const key = memberKeyFor(primaryKey, name, id);
356
359
  if ((struct as Val.Dynamic)[Val.properties]) {
@@ -389,26 +392,14 @@ function configureProperty(supervisor: RootSupervisor, schema: ValueModel) {
389
392
  return managed.owner;
390
393
  }
391
394
 
392
- const assertWriteOk = (value: Val) => {
393
- // Note - this needs to mirror behavior in the setter above
394
- access.authorizeWrite(this[Internal.session], this[Internal.reference].location);
395
- if (validate) {
396
- validate(value, this[Internal.session], {
397
- path: this[Internal.reference].location.path,
398
- siblings: this[Internal.reference].value,
399
- owner: this[Internal.reference].rootOwner,
400
- });
401
- }
402
- };
403
-
404
395
  // Clone the container before write
405
396
  const ref = new ManagedReference(
406
397
  this[Internal.reference],
407
398
  name,
408
399
  id,
409
- assertWriteOk,
410
400
  cloneContainer,
411
401
  this[Internal.session],
402
+ "member",
412
403
  );
413
404
 
414
405
  ref.owner = manage(ref, this[Internal.session]);
@@ -127,10 +127,23 @@ export class CommissioningClient extends Behavior {
127
127
  * Older versions stored a peer's session parameters under `sessionParameters`: the full effective set once a
128
128
  * session existed, otherwise only the DNS-SD intervals. The first becomes the reported set, the second the
129
129
  * advertised intervals. Values already under the new keys win.
130
+ *
131
+ * Stored discovery TTLs are dropped, so the default TTL applies. Versions before 0.16.11 stored TTLs inflated by
132
+ * powers of 1000 or `null`, which fail validation or keep an address from expiring. Current discovery stores no
133
+ * TTL.
130
134
  */
131
135
  static override migrate(values: Val.Struct) {
132
136
  super.migrate(values);
133
137
 
138
+ delete values.ttl;
139
+ if (Array.isArray(values.addresses)) {
140
+ for (const address of values.addresses) {
141
+ if (isObject(address)) {
142
+ delete address.ttl;
143
+ }
144
+ }
145
+ }
146
+
134
147
  const { sessionParameters } = values;
135
148
  delete values.sessionParameters;
136
149
  if (!isObject(sessionParameters)) {
@@ -964,7 +977,10 @@ export namespace CommissioningClient {
964
977
  peerAddress?: PeerAddress;
965
978
 
966
979
  /**
967
- * Case Authenticated Tags (CATs)
980
+ * Case Authenticated Tags (CATs) intended for sessions with this node.
981
+ *
982
+ * Stored, but not applied yet. Sessions present the CATs of this node's own NOC in the fabric
983
+ * (`ControllerBehavior.caseAuthenticatedTags`). The CATs of the peer come from its NOC.
968
984
  *
969
985
  * See {@link PeerDescriptor}
970
986
  */
@@ -1025,7 +1041,7 @@ export namespace CommissioningClient {
1025
1041
  fabricIndexOnPeer?: FabricIndex;
1026
1042
 
1027
1043
  /**
1028
- * The TTL of the discovery record if applicable (in seconds).
1044
+ * The TTL of the discovery record if applicable.
1029
1045
  */
1030
1046
  @field(duration, nonvolatile)
1031
1047
  ttl?: Duration;
@@ -1225,7 +1241,10 @@ export namespace CommissioningClient {
1225
1241
  autoStateInitialize?: boolean;
1226
1242
 
1227
1243
  /**
1228
- * Case Authenticated Tags (CATs)
1244
+ * Case Authenticated Tags (CATs) intended for sessions with this node.
1245
+ *
1246
+ * Stored, but not applied yet. Sessions present the CATs of this node's own NOC in the fabric
1247
+ * (`ControllerBehavior.caseAuthenticatedTags`). The CATs of the peer come from its NOC.
1229
1248
  */
1230
1249
  caseAuthenticatedTags?: CaseAuthenticatedTag[];
1231
1250
 
@@ -4,7 +4,7 @@
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
6
 
7
- import { Immutable, ServerAddress } from "@matter/general";
7
+ import { Immutable, ServerAddress, Time } from "@matter/general";
8
8
  import {
9
9
  CommissionableDevice,
10
10
  OperationalDevice,
@@ -164,6 +164,22 @@ export namespace RemoteDescriptor {
164
164
  return result;
165
165
  }
166
166
 
167
+ /**
168
+ * Convert a peer record of the legacy controller storage (`commissionedNodes`) to the long form.
169
+ *
170
+ * Drops the discovery TTLs: versions before 0.16.11 stored them inflated by powers of 1000 or as `null`, which
171
+ * fails validation when the result is written to {@link CommissioningClient}. `discoveredAt` defaults to the
172
+ * current time.
173
+ */
174
+ export function legacyRecordToLongForm(discoveryData?: RemoteDescriptor, operationalAddress?: ServerAddress) {
175
+ return toLongForm({
176
+ discoveredAt: Time.nowMs,
177
+ ...discoveryData,
178
+ ttl: undefined,
179
+ addresses: operationalAddress ? [{ ...operationalAddress, ttl: undefined }] : [],
180
+ });
181
+ }
182
+
167
183
  export function toLongForm(descriptor: RemoteDescriptor | undefined, long: Long = {}) {
168
184
  if (!descriptor) {
169
185
  return long;
@@ -314,7 +314,8 @@ export namespace ControllerBehavior {
314
314
  adminNodeId?: NodeId = undefined;
315
315
 
316
316
  /**
317
- * Case Authenticated Tags to be used to commission and connect to devices.
317
+ * Only used when this controller creates the fabric; sessions on that fabric present them in the controller's
318
+ * NOC.
318
319
  */
319
320
  caseAuthenticatedTags?: CaseAuthenticatedTag[] = undefined;
320
321
 
@@ -172,9 +172,9 @@ export namespace DclBehavior {
172
172
  fetchTestCertificates = false;
173
173
 
174
174
  /**
175
- * Whether to trust test (non-production) certificates as valid trust anchors during device
176
- * attestation. Independent of {@link fetchTestCertificates}. When unset, defaults to the value of
177
- * `fetchTestCertificates`.
175
+ * Whether device attestation trusts test (non-production) certificates: test PAAs and the Matter test CD
176
+ * signer. When not trusted, each is reported as a `TrustedAsTestCertificate` finding. Independent of
177
+ * {@link fetchTestCertificates}. When unset, defaults to the value of `fetchTestCertificates`.
178
178
  */
179
179
  @field(bool)
180
180
  acceptTestCertificates?: boolean = undefined;
@@ -24,7 +24,8 @@ const JOIN_RETRY_INTERVAL = Seconds(30);
24
24
 
25
25
  /**
26
26
  * Joins the multicast address of every group the fabrics use on the node's UDP transport and follows group changes.
27
- * An address stays joined while any fabric still uses it.
27
+ * A fabric uses a group while the group has an entry in its {@link FabricGroups.endpoints}, and the address joined is
28
+ * {@link FabricGroups.multicastAddressFor} of that group. An address stays joined while any fabric still uses it.
28
29
  */
29
30
  export class ServerGroupNetworking {
30
31
  #construction: Construction<ServerGroupNetworking>;
@@ -202,7 +203,7 @@ export class ServerGroupNetworking {
202
203
  const fabricIndex = fabric.fabricIndex;
203
204
 
204
205
  // Multicast membership follows group existence (groups with endpoints to receive for), not key availability:
205
- // a group whose key mapping was removed still receives datagrams so Groupcast testing can report NoAvailableKey
206
+ // a group whose key mapping was removed still receives datagrams so Groupcast testing can report them
206
207
  const observers = this.#observersForFabric(fabricIndex);
207
208
  observers.on(fabric.groups.endpoints.added, groupId => {
208
209
  this.#want(groupId, fabric);
@@ -25,6 +25,7 @@ export class SessionsBehavior extends Behavior {
25
25
 
26
26
  declare readonly state: SessionsBehavior.State;
27
27
  declare readonly events: SessionsBehavior.Events;
28
+ declare internal: SessionsBehavior.Internal;
28
29
 
29
30
  override initialize() {
30
31
  const env = this.env;
@@ -77,8 +78,9 @@ export class SessionsBehavior extends Behavior {
77
78
  return;
78
79
  }
79
80
 
80
- // When subscription was added then inform SubscriptionsBehavior
81
- if (session.subscriptions.has(subscription)) {
81
+ // When subscription was added then inform SubscriptionsBehavior, but not again when it moves to another session
82
+ if (session.subscriptions.has(subscription) && !this.internal.announcedSubscriptions.has(subscription)) {
83
+ this.internal.announcedSubscriptions.add(subscription);
82
84
  this.events.subscriptionAdded.emit(subscription);
83
85
  }
84
86
 
@@ -120,6 +122,10 @@ export namespace SessionsBehavior {
120
122
  intervals?: Partial<SessionIntervals>;
121
123
  }
122
124
 
125
+ export class Internal {
126
+ announcedSubscriptions = new WeakSet<Subscription>();
127
+ }
128
+
123
129
  export class Events extends EventEmitter {
124
130
  opened = Observable<[session: Session]>();
125
131
  closed = Observable<[session: Session]>();
@@ -0,0 +1,66 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2022-2026 Matter.js Authors
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+
7
+ import type { PeerSubscription } from "#node/server/InteractionServer.js";
8
+ import { Environment, Environmental, Logger, StorageContext, StorageManager } from "@matter/general";
9
+ import { PeerAddress, PeerAddressStore } from "@matter/protocol";
10
+
11
+ const logger = Logger.get("SubscriptionStore");
12
+
13
+ /** A subscription as stored; the storage key carries the peer address. */
14
+ type StoredSubscription = Omit<PeerSubscription, "peerAddress">;
15
+
16
+ /**
17
+ * Subscriptions a server node recorded so it can re-establish them after a restart, stored with one key per peer.
18
+ * Operations keep the call order of {@link PeerAddressStore}.
19
+ */
20
+ export class SubscriptionStore {
21
+ readonly #store: PeerAddressStore<StoredSubscription[]>;
22
+
23
+ constructor(storage: StorageContext) {
24
+ this.#store = new PeerAddressStore(storage);
25
+ }
26
+
27
+ static [Environmental.create](env: Environment) {
28
+ const instance = new SubscriptionStore(env.get(StorageManager).createContext("subscriptions"));
29
+ env.set(SubscriptionStore, instance);
30
+ return instance;
31
+ }
32
+
33
+ /**
34
+ * Store {@link subscriptions} as the subscriptions of {@link address}, in creation order. An empty list deletes the
35
+ * peer's entry.
36
+ */
37
+ save(address: PeerAddress, subscriptions: readonly PeerSubscription[]) {
38
+ if (!subscriptions.length) {
39
+ return this.#store.delete(address);
40
+ }
41
+ return this.#store.set(
42
+ address,
43
+ subscriptions.map(({ peerAddress: _peerAddress, ...subscription }) => subscription),
44
+ );
45
+ }
46
+
47
+ /**
48
+ * Read all stored subscriptions, each peer's in creation order. A peer's entry that is not a list is deleted.
49
+ */
50
+ async load() {
51
+ const stored = await this.#store.load((address, subscriptions) => {
52
+ if (Array.isArray(subscriptions)) {
53
+ return true;
54
+ }
55
+ logger.warn(`Deleting stored subscriptions of ${address}: not a list`);
56
+ return false;
57
+ });
58
+ return [...stored].flatMap(([peerAddress, subscriptions]) =>
59
+ subscriptions.map((subscription): PeerSubscription => ({ ...subscription, peerAddress })),
60
+ );
61
+ }
62
+
63
+ clear() {
64
+ return this.#store.clear();
65
+ }
66
+ }
@@ -26,12 +26,12 @@ import {
26
26
  PeerAddressSet,
27
27
  PeerSet,
28
28
  Subscription,
29
- SubscriptionId,
30
29
  TransientPeerCommunicationError,
31
30
  } from "@matter/protocol";
32
31
  import { Status, StatusResponseError } from "@matter/types";
33
32
  import { Behavior } from "../../Behavior.js";
34
33
  import { SessionsBehavior } from "../sessions/SessionsBehavior.js";
34
+ import { SubscriptionStore } from "./SubscriptionStore.js";
35
35
  const logger = Logger.get("SubscriptionsBehavior");
36
36
 
37
37
  /** Timeout in seconds to wait for responses or discovery of the peer node when trying to re-establish a subscription. */
@@ -52,7 +52,7 @@ export class SubscriptionsServer extends Behavior {
52
52
 
53
53
  override initialize() {
54
54
  const sessions = this.agent.get(SessionsBehavior);
55
- this.reactTo(sessions.events.subscriptionAdded, this.#addSubscription, { lock: true });
55
+ this.reactTo(sessions.events.subscriptionAdded, this.#addSubscription);
56
56
  }
57
57
 
58
58
  static override readonly schema = new DatatypeModel(
@@ -131,7 +131,7 @@ export class SubscriptionsServer extends Behavior {
131
131
  ),
132
132
  );
133
133
 
134
- #addSubscription(subscription: Subscription) {
134
+ #addSubscription(subscription: Subscription): MaybePromise {
135
135
  if (this.state.persistenceEnabled === false || !(subscription instanceof ServerSubscription)) return;
136
136
 
137
137
  const {
@@ -144,11 +144,10 @@ export class SubscriptionsServer extends Behavior {
144
144
  minIntervalFloor,
145
145
  } = subscription;
146
146
  const { peerAddress } = session;
147
- const { fabricIndex, nodeId } = peerAddress;
148
147
 
149
148
  const peerSubscription: PeerSubscription = {
150
149
  subscriptionId: id,
151
- peerAddress: { fabricIndex, nodeId },
150
+ peerAddress,
152
151
  maxIntervalCeiling,
153
152
  minIntervalFloor,
154
153
  attributeRequests,
@@ -159,23 +158,32 @@ export class SubscriptionsServer extends Behavior {
159
158
  };
160
159
  this.reactTo(subscription.cancelled, this.#subscriptionCancelled);
161
160
 
162
- const existingIndex = this.state.subscriptions.findIndex(({ subscriptionId }) => id === subscriptionId);
163
- if (existingIndex !== -1) {
164
- // Should normally never happen
165
- this.state.subscriptions[existingIndex] = peerSubscription;
166
- return;
167
- }
168
- this.state.subscriptions.push(peerSubscription);
161
+ const recorded = this.internal.subscriptions.get(peerAddress) ?? [];
162
+ return this.#record(peerAddress, [
163
+ ...recorded.filter(({ subscriptionId }) => subscriptionId !== id),
164
+ peerSubscription,
165
+ ]);
169
166
  }
170
167
 
171
168
  #subscriptionCancelled(subscription: Subscription): MaybePromise {
172
- if (subscription.isTerminated && this.state.persistenceEnabled !== false) {
173
- return this.#removeSubscription(subscription.subscriptionId);
169
+ if (
170
+ !subscription.isTerminated ||
171
+ this.state.persistenceEnabled === false ||
172
+ !(subscription instanceof ServerSubscription)
173
+ ) {
174
+ return;
174
175
  }
175
- }
176
176
 
177
- async #removeSubscription(id: SubscriptionId) {
178
- await this.#updateStored(subscriptions => subscriptions.filter(({ subscriptionId }) => subscriptionId !== id));
177
+ const { peerAddress } = subscription.session;
178
+ const recorded = this.internal.subscriptions.get(peerAddress);
179
+ if (recorded === undefined) {
180
+ return;
181
+ }
182
+ const { subscriptionId: id } = subscription;
183
+ return this.#record(
184
+ peerAddress,
185
+ recorded.filter(({ subscriptionId }) => subscriptionId !== id),
186
+ );
179
187
  }
180
188
 
181
189
  /**
@@ -187,18 +195,21 @@ export class SubscriptionsServer extends Behavior {
187
195
  const orderOf = ({ subscriptionId }: PeerSubscription) =>
188
196
  formerIndex.get(subscriptionId) ?? formerSubscriptions.length;
189
197
 
190
- await this.#updateStored(subscriptions => [...subscriptions].sort((a, b) => orderOf(a) - orderOf(b)));
198
+ for (const [peerAddress, recorded] of this.internal.subscriptions) {
199
+ const ordered = [...recorded].sort((a, b) => orderOf(a) - orderOf(b));
200
+ if (ordered.some((subscription, index) => subscription !== recorded[index])) {
201
+ await this.#record(peerAddress, ordered);
202
+ }
203
+ }
191
204
  }
192
205
 
193
- /**
194
- * Change the stored subscriptions outside a locked reactor. The list is read only under the lock, because adds
195
- * and removals of other subscriptions commit while this waits for it.
196
- */
197
- async #updateStored(update: (subscriptions: readonly PeerSubscription[]) => PeerSubscription[]) {
198
- await this.context.transaction.addResources(this);
199
- await this.context.transaction.begin();
200
- this.state.subscriptions = update(this.state.subscriptions);
201
- await this.context.transaction.commit();
206
+ #record(peerAddress: PeerAddress, subscriptions: PeerSubscription[]) {
207
+ if (subscriptions.length) {
208
+ this.internal.subscriptions.set(peerAddress, subscriptions);
209
+ } else {
210
+ this.internal.subscriptions.delete(peerAddress);
211
+ }
212
+ return this.env.get(SubscriptionStore).save(peerAddress, subscriptions);
202
213
  }
203
214
 
204
215
  /**
@@ -209,9 +220,33 @@ export class SubscriptionsServer extends Behavior {
209
220
  *
210
221
  * @internal
211
222
  */
212
- beginRun() {
213
- this.internal.formerSubscriptions = deepCopy(this.state.subscriptions);
214
- this.state.subscriptions = [];
223
+ async beginRun() {
224
+ this.internal.subscriptions.clear();
225
+
226
+ const store = this.env.get(SubscriptionStore);
227
+ this.internal.formerSubscriptions =
228
+ this.state.persistenceEnabled === false ? [] : await this.#formerSubscriptionsOf(store);
229
+ await store.clear();
230
+
231
+ if (this.state.subscriptions.length) {
232
+ this.state.subscriptions = [];
233
+ }
234
+ }
235
+
236
+ /**
237
+ * The stored subscriptions, plus those of peers the store has none for from {@link SubscriptionsServer.State.subscriptions}, where
238
+ * versions before {@link SubscriptionStore} kept them.
239
+ */
240
+ async #formerSubscriptionsOf(store: SubscriptionStore) {
241
+ const stored = await store.load();
242
+ if (!this.state.subscriptions.length) {
243
+ return stored;
244
+ }
245
+ const storedPeers = new PeerAddressSet(stored.map(({ peerAddress }) => peerAddress));
246
+ const legacy = deepCopy(this.state.subscriptions)
247
+ .map(subscription => ({ ...subscription, peerAddress: PeerAddress(subscription.peerAddress) }))
248
+ .filter(({ peerAddress }) => !storedPeers.has(peerAddress));
249
+ return [...stored, ...legacy];
215
250
  }
216
251
 
217
252
  async reestablishFormerSubscriptions() {
@@ -239,7 +274,7 @@ export class SubscriptionsServer extends Behavior {
239
274
  // Group subscriptions by peer address for parallel processing
240
275
  const subscriptionsByPeer = new PeerAddressMap<PeerSubscription[]>();
241
276
  for (const subscription of formerSubscriptions) {
242
- const peerAddress = PeerAddress(subscription.peerAddress);
277
+ const { peerAddress } = subscription;
243
278
  const existing = subscriptionsByPeer.get(peerAddress);
244
279
  if (existing !== undefined) {
245
280
  existing.push(subscription);
@@ -347,13 +382,18 @@ export namespace SubscriptionsServer {
347
382
  persistenceEnabled = true;
348
383
 
349
384
  /**
350
- * List of subscriptions. This list is collected automatically.
351
- * The state value should not be initialized by the developer.
385
+ * Subscriptions as versions before {@link SubscriptionStore} stored them. {@link SubscriptionsServer.beginRun}
386
+ * takes them over and sets the list to empty.
387
+ *
388
+ * @deprecated Not written anymore. Will be removed in a future version.
352
389
  */
353
390
  subscriptions: PeerSubscription[] = [];
354
391
  }
355
392
 
356
393
  export class Internal {
394
+ /** Subscriptions recorded in this run of the node, in creation order per peer. */
395
+ subscriptions = new PeerAddressMap<PeerSubscription[]>();
396
+
357
397
  /**
358
398
  * Subscriptions that were established on the former device run. {@link SubscriptionsServer.beginRun} sets
359
399
  * them from the recorded subscriptions and they are then used to re-establish the subscriptions.
@@ -742,14 +742,14 @@ export namespace AccessControlServer {
742
742
  }
743
743
 
744
744
  export declare const ExtensionInterface: {
745
- extensionEntryValidator: (extension: AccessControlTypes.AccessControlExtension) => void;
746
- extensionEntryAccessCheck: (
745
+ extensionEntryValidator(extension: AccessControlTypes.AccessControlExtension): void;
746
+ extensionEntryAccessCheck(
747
747
  aclList: AclList,
748
748
  aclEntry: AclEntry,
749
749
  subjectDesc: IncomingSubjectDescriptor,
750
750
  endpoint: AclEndpointContext,
751
751
  clusterId: ClusterId,
752
- ) => boolean;
752
+ ): boolean;
753
753
  };
754
754
 
755
755
  /**