@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
@@ -935,6 +935,11 @@ class RootReference implements ValReference<Val.Struct>, Transaction.Participant
935
935
  #precommitValues: Val.Struct | undefined;
936
936
  #changes: CommitChanges | undefined;
937
937
 
938
+ /**
939
+ * Containers this session cloned since its last commit or rollback; see {@link owns}.
940
+ */
941
+ #owned = new WeakSet<object>();
942
+
938
943
  /**
939
944
  * Keys of the members this session assigned since its last commit or rollback, whether or not the value differs.
940
945
  */
@@ -1007,7 +1012,7 @@ class RootReference implements ValReference<Val.Struct>, Transaction.Participant
1007
1012
  onChange: (oldValues: Val.Struct) => {
1008
1013
  if (this.#values === oldValues) {
1009
1014
  this.#values = this.#internals.values;
1010
- this.#refreshSubrefs();
1015
+ this.#refreshSubrefs("external");
1011
1016
  }
1012
1017
  },
1013
1018
  };
@@ -1024,7 +1029,6 @@ class RootReference implements ValReference<Val.Struct>, Transaction.Participant
1024
1029
  try {
1025
1030
  this.#internals.sessions?.delete(this.#session);
1026
1031
  this.#expired = true;
1027
- this.#refreshSubrefs();
1028
1032
  } catch (e) {
1029
1033
  logger.warn(
1030
1034
  `Error detaching reference to ${this.#internals.location.path} from closed transaction ${transaction.via}:`,
@@ -1042,10 +1046,6 @@ class RootReference implements ValReference<Val.Struct>, Transaction.Participant
1042
1046
 
1043
1047
  // -- ValReference implementation --
1044
1048
 
1045
- get original() {
1046
- return this.#internals.values;
1047
- }
1048
-
1049
1049
  get value() {
1050
1050
  if (this.#expired) {
1051
1051
  throw new ExpiredReferenceError(this.location);
@@ -1053,10 +1053,6 @@ class RootReference implements ValReference<Val.Struct>, Transaction.Participant
1053
1053
  return this.#values;
1054
1054
  }
1055
1055
 
1056
- set value(_value) {
1057
- throw new InternalError(`Cannot set root reference for ${this.#internals.supervisor.schema.name}`);
1058
- }
1059
-
1060
1056
  get expired() {
1061
1057
  return this.#expired;
1062
1058
  }
@@ -1073,6 +1069,16 @@ class RootReference implements ValReference<Val.Struct>, Transaction.Participant
1073
1069
  return this.#internals.owner;
1074
1070
  }
1075
1071
 
1072
+ owns(container: Val) {
1073
+ return typeof container === "object" && container !== null && this.#owned.has(container);
1074
+ }
1075
+
1076
+ adopt(container: Val) {
1077
+ if (typeof container === "object" && container !== null) {
1078
+ this.#owned.add(container);
1079
+ }
1080
+ }
1081
+
1076
1082
  change(mutator: () => void, member: string | number) {
1077
1083
  if (this.#expired) {
1078
1084
  throw new ExpiredReferenceError(this.location);
@@ -1116,17 +1122,19 @@ class RootReference implements ValReference<Val.Struct>, Transaction.Participant
1116
1122
  }
1117
1123
 
1118
1124
  // Point subreferences to the clone
1119
- this.#refreshSubrefs();
1125
+ this.#refreshSubrefs("session");
1120
1126
  }
1121
1127
 
1122
- if (this.#internals.mirrorsRemote) {
1123
- this.#mutateRecording(mutator, member);
1124
- } else {
1125
- mutator();
1128
+ // A mutator that throws may already have changed or restored values
1129
+ try {
1130
+ if (this.#internals.mirrorsRemote) {
1131
+ this.#mutateRecording(mutator, member);
1132
+ } else {
1133
+ mutator();
1134
+ }
1135
+ } finally {
1136
+ this.#refreshSubrefs("session");
1126
1137
  }
1127
-
1128
- // Refresh subrefs referencing any mutated values
1129
- this.#refreshSubrefs();
1130
1138
  }
1131
1139
 
1132
1140
  /**
@@ -1259,6 +1267,12 @@ class RootReference implements ValReference<Val.Struct>, Transaction.Participant
1259
1267
  commit2() {
1260
1268
  this.#assigned = undefined;
1261
1269
 
1270
+ // The clones become canonical, so the next write must clone them again
1271
+ this.#owned = new WeakSet();
1272
+
1273
+ // The next announcement diffs against the canonical value, which another transaction may change meanwhile
1274
+ this.#precommitValues = undefined;
1275
+
1262
1276
  if (!this.#changes) {
1263
1277
  return;
1264
1278
  }
@@ -1317,12 +1331,13 @@ class RootReference implements ValReference<Val.Struct>, Transaction.Participant
1317
1331
  rollback() {
1318
1332
  this.#values = this.#internals.values;
1319
1333
  this.#assigned = undefined;
1334
+ this.#owned = new WeakSet();
1320
1335
 
1321
1336
  // A rolled back value was never adopted, so it must not stand as the baseline the next announcement diffs
1322
1337
  // against
1323
1338
  this.#precommitValues = undefined;
1324
1339
 
1325
- this.#refreshSubrefs();
1340
+ this.#refreshSubrefs("session");
1326
1341
  }
1327
1342
 
1328
1343
  // -- Private helpers --
@@ -1370,11 +1385,11 @@ class RootReference implements ValReference<Val.Struct>, Transaction.Participant
1370
1385
  }
1371
1386
  }
1372
1387
 
1373
- #refreshSubrefs() {
1388
+ #refreshSubrefs(cause: ValReference.RefreshCause) {
1374
1389
  const subrefs = this.subrefs;
1375
1390
  if (subrefs) {
1376
1391
  for (const key in subrefs) {
1377
- subrefs[key].refresh();
1392
+ subrefs[key].refresh(cause);
1378
1393
  }
1379
1394
  }
1380
1395
  }
@@ -8,7 +8,8 @@ import type { Val } from "@matter/protocol";
8
8
  import type { ValReference } from "./ValReference.js";
9
9
 
10
10
  /**
11
- * API for bypassing managed collections and accessing the internal object containing raw data.
11
+ * API for bypassing managed collections: access to the internal object containing raw data, and raw copies of
12
+ * incoming values.
12
13
  */
13
14
  export namespace Internal {
14
15
  export const reference = Symbol("reference");
@@ -19,53 +20,55 @@ export namespace Internal {
19
20
  }
20
21
 
21
22
  /**
22
- * Recursively unwrap managed proxies in a value tree, returning raw data.
23
+ * The raw value behind a managed proxy, or `value` itself. Unlike {@link copy}, the result is the stored object,
24
+ * so a list entry reference bound to one of its entries stays live when the value is stored back.
25
+ */
26
+ export function rawOf(value: Val): Val {
27
+ if (value === null || value === undefined || typeof value !== "object") {
28
+ return value;
29
+ }
30
+ const ref = (value as Collection)[reference];
31
+ return ref ? ref.value : value;
32
+ }
33
+
34
+ /**
35
+ * Copy an incoming value tree into raw data for a manager to store.
23
36
  *
24
- * Primitives, Uint8Array, Date, and other non-plain objects pass through unchanged. Plain
25
- * arrays and plain objects are walked; a new container is only allocated if a child was replaced.
37
+ * A managed proxy is replaced by a copy of its raw value, including the entries of other fabrics. Every array and
38
+ * every plain object is copied, so the stored value shares no array or plain object with the committed state, with
39
+ * another reference or with the caller. A nested write changes a container in place once the transaction owns it,
40
+ * so a shared container would change in both places. A copied object keeps its symbol-keyed properties, such as
41
+ * `BitmapEncodedValue`, with the same values.
42
+ *
43
+ * Primitives, Uint8Array, Date and other class instances pass through unchanged.
26
44
  */
27
- export function unmanage(value: Val): Val {
45
+ export function copy(value: Val): Val {
28
46
  if (value === null || value === undefined || typeof value !== "object") {
29
47
  return value;
30
48
  }
31
49
 
32
- // Unwrap managed proxy to its raw value, then continue walking
33
50
  const ref = (value as Collection)[reference];
34
51
  if (ref) {
35
- return unmanage(ref.value);
52
+ return copy(ref.value);
36
53
  }
37
54
 
38
55
  if (Array.isArray(value)) {
39
- let changed = false;
40
- const result = new Array(value.length);
41
-
42
- for (let i = 0; i < value.length; i++) {
43
- const child = unmanage(value[i]);
44
- if (child !== value[i]) {
45
- changed = true;
46
- }
47
- result[i] = child;
48
- }
49
-
50
- return changed ? result : value;
56
+ return value.map(copy);
51
57
  }
52
58
 
53
59
  const proto = Object.getPrototypeOf(value);
54
- if (proto === Object.prototype || proto === null) {
55
- let changed = false;
56
- const result = {} as Record<string, Val>;
57
-
58
- for (const key in value as Record<string, Val>) {
59
- const child = unmanage((value as Record<string, Val>)[key]);
60
- if (child !== (value as Record<string, Val>)[key]) {
61
- changed = true;
62
- }
63
- result[key] = child;
64
- }
65
-
66
- return changed ? result : value;
60
+ if (proto !== Object.prototype && proto !== null) {
61
+ return value;
67
62
  }
68
63
 
69
- return value;
64
+ const source = value as Val.Struct;
65
+ const result: Val.Struct = {};
66
+ for (const key in source) {
67
+ result[key] = copy(source[key]);
68
+ }
69
+ for (const symbol of Object.getOwnPropertySymbols(source)) {
70
+ Object.defineProperty(result, symbol, Object.getOwnPropertyDescriptor(source, symbol)!);
71
+ }
72
+ return result;
70
73
  }
71
74
  }
@@ -5,7 +5,7 @@
5
5
  */
6
6
 
7
7
  import { InternalError } from "@matter/general";
8
- import { AccessControl, ExpiredReferenceError, Val } from "@matter/protocol";
8
+ import { AccessControl, Val } from "@matter/protocol";
9
9
  import type { Supervision } from "../../supervision/Supervision.js";
10
10
  import {
11
11
  memberFallbackKeyFor,
@@ -14,14 +14,14 @@ import {
14
14
  memberSlotOf,
15
15
  memberValueOf,
16
16
  } from "./MemberKeys.js";
17
- import type { ValReference } from "./ValReference.js";
17
+ import { ValReference } from "./ValReference.js";
18
18
 
19
19
  type Container = Record<string | number, Val>;
20
20
 
21
21
  /**
22
22
  * ManagedReference manages a reference to a container property of another reference.
23
23
  *
24
- * The ManagedReference detects when the value changes and clones the container if it is the original copy.
24
+ * The ManagedReference clones the container on write unless the transaction already owns it.
25
25
  *
26
26
  * This serves the following purposes:
27
27
  *
@@ -31,9 +31,20 @@ type Container = Record<string | number, Val>;
31
31
  *
32
32
  * - Preserves metadata regarding the state of the value
33
33
  *
34
- * Change detection happens automatically if the value is replaced. If a subvalue is replaced, the logic replacing the
35
- * subvalue must update "changed" manually before replacing the subvalue. For managed structures this is handled by a
36
- * separate ManagedReference.
34
+ * A member reference follows whatever container the parent holds at its key. A list entry reference is bound to one
35
+ * entry instead, because an index does not identify an entry (see {@link ManagedReference.Binding}):
36
+ *
37
+ * | State | Cause | {@link value} | Writes |
38
+ * |---------|-----------------------------------------------------|--------------------|-------------------------|
39
+ * | live | the member holds a container | that container | allowed |
40
+ * | absent | the member, or a container above it, is absent; | `undefined`/`null` | `PhantomReferenceError` |
41
+ * | | for an entry, only after another transaction's | | |
42
+ * | | commit | | |
43
+ * | expired | the owning context exited, a parent is read-only, | last container | `ExpiredReferenceError` |
44
+ * | | or a change in this session moved, removed or | | |
45
+ * | | replaced this entry | | |
46
+ *
47
+ * "absent" returns to "live" when a container is assigned again. "expired" is final.
37
48
  */
38
49
  export class ManagedReference implements ValReference {
39
50
  readonly primaryKey = "name";
@@ -46,35 +57,37 @@ export class ManagedReference implements ValReference {
46
57
  #key: string | number;
47
58
  #fallbackKey: string | number | undefined;
48
59
  #readFallbackKey: string | number | undefined;
49
- #assertWriteOk: (value: Val) => void;
50
- #clone: ((container: Val) => Val) | undefined;
60
+ #clone: (container: Val) => Val;
51
61
  #session: AccessControl.Session;
52
- #expired = false;
53
62
  #location: AccessControl.Location;
54
63
  #value: unknown;
55
64
  #dynamicContainer: Val.Struct | undefined;
56
65
  #dynamicSource: Val | undefined;
66
+ #binding: ManagedReference.Binding;
67
+ #entry: unknown;
68
+ #copies?: WeakSet<object>;
69
+ #detached = false;
57
70
 
58
71
  /**
59
72
  * @param parent a reference to the container we reference
60
73
  * @param name the name (in the case of structs) or index (in case of lists)
61
74
  * @param id the lookup ID, used when {@link parent} keys its members by ID
62
- * @param assertWriteOk enforces ACLs and read-only
63
- * @param clone clones the container prior to write; undefined if not transactional
75
+ * @param clone clones the container prior to write
64
76
  * @param session the access control session
77
+ * @param binding what the reference stays bound to when the parent changes
65
78
  */
66
79
  constructor(
67
80
  parent: ValReference<Val.Collection>,
68
81
  name: string | number,
69
82
  id: number | undefined,
70
- assertWriteOk: (value: Val) => void,
71
83
  clone: (container: Val) => Val,
72
84
  session: AccessControl.Session,
85
+ binding: ManagedReference.Binding,
73
86
  ) {
74
87
  this.parent = parent;
75
- this.#assertWriteOk = assertWriteOk;
76
88
  this.#clone = clone;
77
89
  this.#session = session;
90
+ this.#binding = binding;
78
91
 
79
92
  this.#location = {
80
93
  ...parent.location,
@@ -93,6 +106,7 @@ export class ManagedReference implements ValReference {
93
106
  this.#dynamicContainer === undefined
94
107
  ? memberValueOf(parent.value as Container, key, readFallbackKey)
95
108
  : memberValueOf(this.#dynamicContainer as Container, key, fallbackKey);
109
+ this.#entry = this.#value;
96
110
 
97
111
  // Propagate supervision config from parent
98
112
  if (parent.supervisionConfig) {
@@ -106,34 +120,16 @@ export class ManagedReference implements ValReference {
106
120
  }
107
121
 
108
122
  get rootOwner() {
109
- return this.parent!.rootOwner;
123
+ return this.parent.rootOwner;
110
124
  }
111
125
 
112
126
  get value() {
113
127
  // Authorization is unnecessary here because the reference would not exist if access is unauthorized
114
- // Note that we allow read from expired references
115
128
  return this.#value;
116
129
  }
117
130
 
118
- set value(newValue: Val) {
119
- if (this.#value === newValue) {
120
- return;
121
- }
122
-
123
- // Authorization and validation
124
- this.#assertWriteOk(newValue);
125
-
126
- // Set the value directly before change() so change() doesn't create a useless clone
127
- this.#replaceValue(newValue);
128
-
129
- // Now use change to complete the update
130
- this.change(() => {
131
- this.#writeTo(this.#dynamicContainer ?? (this.parent!.value as Container), newValue);
132
- });
133
- }
134
-
135
131
  get expired() {
136
- return this.#expired;
132
+ return this.#detached || this.parent.expired;
137
133
  }
138
134
 
139
135
  get location() {
@@ -144,52 +140,59 @@ export class ManagedReference implements ValReference {
144
140
  this.#location = loc;
145
141
  }
146
142
 
147
- get original() {
148
- if (!this.parent!.original) {
149
- return undefined;
150
- }
151
- if (this.#dynamicContainer !== undefined) {
152
- const origProperties = (this.parent!.original as Val.Dynamic)[Val.properties](
153
- this.parent!.rootOwner,
154
- this.#session,
155
- );
156
- return memberValueOf(origProperties as Container, this.#key, this.#fallbackKey);
157
- }
158
- return memberValueOf(this.parent!.original as Container, this.#key, this.#readFallbackKey);
143
+ /**
144
+ * A container a `Val.properties` provider serves, and every container below it, is never owned, even when the
145
+ * provider serves a container the transaction cloned for another member. The provider keeps the value its setter
146
+ * accepted, so a later change must clone it again instead of changing it in place.
147
+ */
148
+ owns(container: Val) {
149
+ return this.#dynamicContainer === undefined && this.parent.owns(container);
159
150
  }
160
151
 
161
- change(mutator: () => void) {
162
- if (this.#expired) {
163
- throw new ExpiredReferenceError(this.location);
164
- }
152
+ adopt(container: Val) {
153
+ this.parent.adopt(container);
154
+ }
165
155
 
166
- this.parent!.change(() => {
167
- // In transactions, clone the value if we haven't done so yet
168
- if (this.#clone && this.#value === this.original) {
169
- const newValue = this.#clone(this.#value);
170
- this.#writeTo(this.#dynamicContainer ?? (this.parent!.value as Container), newValue);
171
- this.#replaceValue(newValue);
156
+ /**
157
+ * Clones the container unless the transaction {@link owns} it, runs {@link mutator}, then stores the container in
158
+ * the parent. A dynamic provider's setter therefore receives the container after every change, with the change
159
+ * applied.
160
+ */
161
+ change(mutator: () => void) {
162
+ ValReference.writableContainerOf(this);
163
+
164
+ this.parent.change(() => {
165
+ // The parent's change may refresh this reference and expire it
166
+ ValReference.writableContainerOf(this);
167
+
168
+ if (!this.owns(this.#value)) {
169
+ const clone = this.#clone(this.#value);
170
+ this.adopt(clone);
171
+ if (this.#binding === "entry" && typeof clone === "object" && clone !== null) {
172
+ (this.#copies ??= new WeakSet()).add(clone);
173
+ }
174
+ this.#replaceValue(clone, "session");
172
175
  }
173
176
 
174
- // Apply changes
175
177
  mutator();
178
+
179
+ this.#writeTo(this.#dynamicContainer ?? (this.parent.value as Container), this.#value);
176
180
  }, this.#key);
177
181
  }
178
182
 
179
- refresh() {
180
- if (this.parent!.expired) {
181
- this.#expired = true;
183
+ refresh(cause: ValReference.RefreshCause) {
184
+ if (this.expired) {
182
185
  return;
183
186
  }
184
- if (this.parent!.value === undefined || this.parent!.value === null) {
185
- this.#expired = true;
186
- this.#replaceValue(undefined);
187
+
188
+ if (this.parent.value === undefined || this.parent.value === null) {
189
+ this.#follow(undefined, cause);
187
190
  return;
188
191
  }
189
192
 
190
193
  // A member the parent serves from a provider must stay served for the life of this reference; a reference that
191
194
  // found no provider is never asked again, so a parent may not start serving one either
192
- if (this.#dynamicContainer !== undefined && this.parent!.value !== this.#dynamicSource) {
195
+ if (this.#dynamicContainer !== undefined && this.parent.value !== this.#dynamicSource) {
193
196
  this.#bindDynamicContainer();
194
197
  if (this.#dynamicContainer === undefined) {
195
198
  throw new InternalError(`Value at ${this.location.path} no longer serves ${this.#key}`);
@@ -198,10 +201,46 @@ export class ManagedReference implements ValReference {
198
201
 
199
202
  const value =
200
203
  this.#dynamicContainer === undefined
201
- ? memberValueOf(this.parent!.value as Container, this.#key, this.#readFallbackKey)
204
+ ? memberValueOf(this.parent.value as Container, this.#key, this.#readFallbackKey)
202
205
  : memberValueOf(this.#dynamicContainer as Container, this.#key, this.#fallbackKey);
203
206
 
204
- this.#replaceValue(value);
207
+ this.#follow(value, cause);
208
+ }
209
+
210
+ /**
211
+ * Take `value` as the referenced value. An entry reference expires instead when a change in this session put
212
+ * another entry at its index. It accepts its entry and every copy it made of that entry, because only a rollback
213
+ * puts an earlier copy back. After another transaction's commit, an entry reference follows its index like a
214
+ * member reference and binds to the entry now there.
215
+ */
216
+ #follow(value: unknown, cause: ValReference.RefreshCause) {
217
+ if (this.#binding === "entry") {
218
+ if (cause === "external") {
219
+ this.#entry = value;
220
+ this.#copies = undefined;
221
+ } else if (!this.#holds(value)) {
222
+ this.#detach();
223
+ return;
224
+ }
225
+ }
226
+
227
+ this.#replaceValue(value, cause);
228
+ }
229
+
230
+ #holds(value: unknown) {
231
+ if (value === this.#entry) {
232
+ return true;
233
+ }
234
+ return typeof value === "object" && value !== null && !!this.#copies?.has(value);
235
+ }
236
+
237
+ /**
238
+ * Stop following the entry. The reference keeps its last value and is {@link expired}. It leaves the parent's
239
+ * subrefs, so the next read at its index creates a reference for the entry now there.
240
+ */
241
+ #detach() {
242
+ this.#detached = true;
243
+ delete this.parent.subrefs?.[this.#key];
205
244
  }
206
245
 
207
246
  /**
@@ -209,7 +248,7 @@ export class ManagedReference implements ValReference {
209
248
  * struct it was derived from, so this runs again whenever the parent replaces that struct.
210
249
  */
211
250
  #bindDynamicContainer() {
212
- const parent = this.parent!;
251
+ const parent = this.parent;
213
252
 
214
253
  this.#dynamicSource = parent.value;
215
254
  this.#dynamicContainer = undefined;
@@ -236,14 +275,27 @@ export class ManagedReference implements ValReference {
236
275
  }
237
276
  }
238
277
 
239
- #replaceValue(newValue: Val) {
278
+ #replaceValue(newValue: Val, cause: ValReference.RefreshCause) {
240
279
  this.#value = newValue;
241
280
 
242
281
  const subrefs = this.subrefs;
243
282
  if (subrefs) {
244
283
  for (const key in subrefs) {
245
- subrefs[key].refresh();
284
+ subrefs[key].refresh(cause);
246
285
  }
247
286
  }
248
287
  }
249
288
  }
289
+
290
+ export namespace ManagedReference {
291
+ /**
292
+ * What a reference stays bound to when its parent changes.
293
+ *
294
+ * - `member`: the key. A struct member is identified by its name, so the reference follows the container the
295
+ * parent holds there.
296
+ * - `entry`: the entry it was read for, or the entry another transaction's commit put at its index. An index does
297
+ * not identify a list entry: a list method, a length change, an assignment at the index or of the whole list puts
298
+ * another entry there.
299
+ */
300
+ export type Binding = "member" | "entry";
301
+ }
@@ -0,0 +1,54 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2022-2026 Matter.js Authors
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+
7
+ import { AccessControl, ExpiredReferenceError, Val } from "@matter/protocol";
8
+ import type { ValReference } from "./ValReference.js";
9
+
10
+ /**
11
+ * A read-only reference to a value that has no slot in managed state, such as an entry a list method removed or an
12
+ * entry a sort comparator receives.
13
+ *
14
+ * The reference serves the value it was given, not a copy. A manager over it reads through the same path as over a
15
+ * live reference, with the same authorization and name resolution. The reference counts as expired, so every write
16
+ * through it or through a reference below it throws {@link ExpiredReferenceError}.
17
+ */
18
+ export class ReadOnlyReference implements ValReference {
19
+ readonly primaryKey = "name";
20
+ readonly expired = true;
21
+
22
+ subrefs?: Record<number | string, ValReference>;
23
+ owner?: Val;
24
+ location: AccessControl.Location;
25
+
26
+ #value: Val;
27
+ #rootOwner: unknown;
28
+
29
+ constructor(value: Val, location: AccessControl.Location, rootOwner: unknown) {
30
+ this.#value = value;
31
+ this.location = location;
32
+ this.#rootOwner = rootOwner;
33
+ }
34
+
35
+ get value() {
36
+ return this.#value;
37
+ }
38
+
39
+ get rootOwner() {
40
+ return this.#rootOwner;
41
+ }
42
+
43
+ change() {
44
+ throw new ExpiredReferenceError(this.location);
45
+ }
46
+
47
+ refresh() {}
48
+
49
+ owns() {
50
+ return false;
51
+ }
52
+
53
+ adopt() {}
54
+ }