@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
@@ -4,26 +4,18 @@
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
6
 
7
- import { isObject, serialize } from "@matter/general";
7
+ import { InternalError, isObject, serialize } from "@matter/general";
8
8
  import type { Schema } from "@matter/model";
9
9
  import { Access, AttributeModel, DataModelPath, ValueModel } from "@matter/model";
10
- import {
11
- AccessControl,
12
- ExpiredReferenceError,
13
- hasLocalActor,
14
- hasRemoteActor,
15
- ReadError,
16
- SchemaImplementationError,
17
- Val,
18
- WriteError,
19
- } from "@matter/protocol";
10
+ import { AccessControl, hasRemoteActor, ReadError, SchemaImplementationError, Val, WriteError } from "@matter/protocol";
20
11
  import { Status } from "@matter/types";
21
12
  import type { RootSupervisor } from "../../../supervision/RootSupervisor.js";
22
13
  import type { ValueSupervisor } from "../../../supervision/ValueSupervisor.js";
23
14
  import type { ValidationLocation } from "../../validation/location.js";
24
15
  import { Internal } from "../Internal.js";
25
16
  import { ManagedReference } from "../ManagedReference.js";
26
- import type { ValReference } from "../ValReference.js";
17
+ import { ReadOnlyReference } from "../ReadOnlyReference.js";
18
+ import { ValReference } from "../ValReference.js";
27
19
  import { PrimitiveManager } from "./PrimitiveManager.js";
28
20
 
29
21
  /**
@@ -100,7 +92,6 @@ interface ListConfig {
100
92
  authorizeWrite: AccessControl["authorizeWrite"];
101
93
  }
102
94
 
103
- const assertWriteOkAlways = () => true;
104
95
  const cloneEntry = (val: Val) => (Array.isArray(val) ? [...(val as Val.List)] : isObject(val) ? { ...val } : val);
105
96
  const inspectCustom = Symbol.for("nodejs.util.inspect.custom");
106
97
 
@@ -112,6 +103,35 @@ function inspectList(this: Val.List) {
112
103
  return [...this];
113
104
  }
114
105
 
106
+ /**
107
+ * Maximum number of entries in a list: list indices are 16 bits wide.
108
+ */
109
+ const MAX_LIST_LENGTH = 65536;
110
+
111
+ /**
112
+ * Array methods that add, remove, overwrite, move or insert entries. The proxy runs them on a plain array of the
113
+ * visible entries; see {@link ListProxyHandler.editEntries}.
114
+ */
115
+ const entryEdits = new Map<PropertyKey, (...args: never[]) => unknown>([
116
+ ["copyWithin", Array.prototype.copyWithin],
117
+ ["fill", Array.prototype.fill],
118
+ ["pop", Array.prototype.pop],
119
+ ["push", Array.prototype.push],
120
+ ["reverse", Array.prototype.reverse],
121
+ ["shift", Array.prototype.shift],
122
+ ["sort", Array.prototype.sort],
123
+ ["splice", Array.prototype.splice],
124
+ ["unshift", Array.prototype.unshift],
125
+ ]);
126
+
127
+ /**
128
+ * The list index a property key names, or `undefined` for any other key. Like an array, the list treats only the
129
+ * canonical decimal form as an index, so `"1.5"` and `"01"` are not indices.
130
+ */
131
+ function entryIndexFor(property: PropertyKey) {
132
+ return typeof property === "string" && /^(0|[1-9]\d*)$/.test(property) ? Number.parseInt(property) : undefined;
133
+ }
134
+
115
135
  class ListProxyHandler implements ProxyHandler<Val.List> {
116
136
  protected reference: ValReference<Val.List>;
117
137
  protected session: ValueSupervisor.Session;
@@ -130,14 +150,11 @@ class ListProxyHandler implements ProxyHandler<Val.List> {
130
150
  }
131
151
 
132
152
  protected readVal() {
133
- return this.reference.value ?? [];
153
+ return ValReference.containerOf(this.reference);
134
154
  }
135
155
 
136
156
  protected writeVal() {
137
- if (this.reference.expired) {
138
- throw new ExpiredReferenceError(this.reference.location);
139
- }
140
- return this.reference.value;
157
+ return ValReference.writableContainerOf(this.reference);
141
158
  }
142
159
 
143
160
  protected getListLength() {
@@ -145,10 +162,14 @@ class ListProxyHandler implements ProxyHandler<Val.List> {
145
162
  }
146
163
 
147
164
  protected setListLength(length: number) {
148
- if (length > 65535) {
149
- throw new WriteError(this.reference.location, `Index ${length} is greater than allowed maximum of 65535`);
165
+ this.config.authorizeWrite(this.session, this.reference.location);
166
+ if (!Number.isInteger(length) || length < 0) {
167
+ throw new WriteError(this.reference.location, `Length ${length} is not a valid list length`);
168
+ }
169
+ if (length > this.getListLength()) {
170
+ throw new WriteError(this.reference.location, `Length ${length} would leave a gap after the last entry`);
150
171
  }
151
- this.reference.change(() => (this.writeVal().length = length), "length");
172
+ this.storeEntries(this.visibleEntries().slice(0, length));
152
173
  }
153
174
 
154
175
  protected hasEntry(index: number) {
@@ -163,8 +184,11 @@ class ListProxyHandler implements ProxyHandler<Val.List> {
163
184
  throw new ReadError(this.reference.location, `Index ${index} is out of bounds`);
164
185
  }
165
186
 
166
- if (index > 65535) {
167
- throw new ReadError(this.reference.location, `Index ${index} is greater than allowed maximum of 65535`);
187
+ if (index >= MAX_LIST_LENGTH) {
188
+ throw new ReadError(
189
+ this.reference.location,
190
+ `Index ${index} is greater than allowed maximum of ${MAX_LIST_LENGTH - 1}`,
191
+ );
168
192
  }
169
193
 
170
194
  const value = this.readVal()[index];
@@ -175,14 +199,7 @@ class ListProxyHandler implements ProxyHandler<Val.List> {
175
199
  let subref = this.reference.subrefs?.[index];
176
200
 
177
201
  if (subref === undefined) {
178
- subref = new ManagedReference(
179
- this.reference,
180
- index,
181
- undefined,
182
- assertWriteOkAlways,
183
- cloneEntry,
184
- this.session,
185
- );
202
+ subref = new ManagedReference(this.reference, index, undefined, cloneEntry, this.session, "entry");
186
203
 
187
204
  this.config.manageEntry(subref, this.session);
188
205
  }
@@ -202,35 +219,181 @@ class ListProxyHandler implements ProxyHandler<Val.List> {
202
219
  *
203
220
  * Invoked before the entry is validated, because validation judges the entry as a whole.
204
221
  */
205
- protected prepareEntry(value: Val): Val {
222
+ protected prepareEntry(value: Val, _location: AccessControl.Location): Val {
206
223
  return value;
207
224
  }
208
225
 
226
+ /**
227
+ * Store a prepared, validated entry after the caller authorized the write. The caller passes a value the list may
228
+ * own; see {@link Internal.copy}.
229
+ */
209
230
  protected writeEntry(index: number, value: Val, location: AccessControl.Location) {
210
- this.config.authorizeWrite(this.session, location);
211
-
212
- if (index < 0 || index > this.readVal().length + 1) {
231
+ if (index < 0 || index > this.readVal().length) {
213
232
  throw new WriteError(location, `Index ${index} is out of bounds`);
214
233
  }
215
234
 
216
- if (index > 65535) {
217
- throw new ReadError(location, `Index ${index} is greater than allowed maximum of 65535`);
235
+ if (index >= MAX_LIST_LENGTH) {
236
+ throw new WriteError(location, `Index ${index} is greater than allowed maximum of ${MAX_LIST_LENGTH - 1}`);
218
237
  }
219
238
 
220
- // Unwrap incoming managed values (including nested)
221
- value = Internal.unmanage(value);
222
-
223
239
  this.reference.change(() => (this.writeVal()[index] = value), index);
224
240
  }
225
241
 
242
+ /**
243
+ * Remove an entry. Only the last entry may go, so the list never has a gap. An index beyond the end is ignored.
244
+ */
245
+ protected deleteEntry(index: number, location: AccessControl.Location) {
246
+ const length = this.getListLength();
247
+ if (index >= length) {
248
+ return;
249
+ }
250
+ if (index !== length - 1) {
251
+ throw new WriteError(location, `Deleting entry ${index} would leave a gap; use splice to remove it`);
252
+ }
253
+ this.setListLength(index);
254
+ }
255
+
256
+ /**
257
+ * The stored entries this session sees, in the order of the indices {@link readEntry} and {@link writeEntry} use.
258
+ */
259
+ protected visibleEntries(): Val[] {
260
+ return [...this.readVal()];
261
+ }
262
+
263
+ /**
264
+ * Replace the entries {@link visibleEntries} returns with `entries` in a single change. Throws {@link WriteError}
265
+ * when the list would exceed {@link MAX_LIST_LENGTH}.
266
+ *
267
+ * An entry that `entries` holds more than once is stored once and copied into its other slots, because the
268
+ * transaction may own the entry and a nested write changes an owned entry in place (see {@link ValReference.owns}).
269
+ * The original stays at the slot that already holds it, so the reference held for that slot stays live.
270
+ */
271
+ protected storeEntries(entries: Val[]) {
272
+ if (entries.length > MAX_LIST_LENGTH) {
273
+ throw new WriteError(
274
+ this.reference.location,
275
+ `Length ${entries.length} exceeds the maximum of ${MAX_LIST_LENGTH}`,
276
+ );
277
+ }
278
+
279
+ const current = this.readVal();
280
+ const originalSlot = new Map<Val, number>();
281
+ entries.forEach((entry, index) => {
282
+ if (typeof entry !== "object" || entry === null) {
283
+ return;
284
+ }
285
+ const slot = originalSlot.get(entry);
286
+ if (slot === undefined || current[index] === entry) {
287
+ originalSlot.set(entry, index);
288
+ }
289
+ });
290
+ const placed = entries.map((entry, index) =>
291
+ typeof entry === "object" && entry !== null && originalSlot.get(entry) !== index
292
+ ? Internal.copy(entry)
293
+ : entry,
294
+ );
295
+
296
+ this.reference.change(() => {
297
+ const list = this.writeVal();
298
+ placed.forEach((entry, index) => (list[index] = entry));
299
+ list.length = placed.length;
300
+ }, "length");
301
+ }
302
+
303
+ /**
304
+ * Apply an array method that changes entries, and return its result.
305
+ *
306
+ * The method runs on a plain array of the visible entries, so it moves entry objects rather than entry proxies. A
307
+ * stored entry keeps its value. Every other value is new: it is copied, prepared and validated before anything is
308
+ * stored. The result is stored in a single change, so a rejected entry leaves the list unchanged.
309
+ *
310
+ * A stored entry leaves this method only as a read-only view (see {@link ReadOnlyReference}): the entries `pop`,
311
+ * `shift` and `splice` remove, and the entries a `sort` comparator receives. A method that returns its array
312
+ * returns the list itself.
313
+ */
314
+ protected editEntries(method: (...args: never[]) => unknown, args: unknown[], receiver: Val.List): unknown {
315
+ this.config.authorizeWrite(this.session, this.reference.location);
316
+
317
+ const stored = this.visibleEntries();
318
+ const viewOf = this.#viewsOf(stored);
319
+ const [compare] = args;
320
+ const edited = [...stored];
321
+ const result = Reflect.apply(
322
+ method,
323
+ edited,
324
+ method === Array.prototype.sort && typeof compare === "function"
325
+ ? [(a: Val, b: Val): unknown => Reflect.apply(compare, undefined, [viewOf(a), viewOf(b)])]
326
+ : args,
327
+ );
328
+
329
+ const isStored = new Set(stored);
330
+ const entries = edited.map((entry, index) => (isStored.has(entry) ? entry : this.#acceptEntry(entry, index)));
331
+
332
+ this.storeEntries(entries);
333
+
334
+ if (result === edited) {
335
+ return receiver;
336
+ }
337
+ if (method === Array.prototype.splice && Array.isArray(result)) {
338
+ return result.map(viewOf);
339
+ }
340
+ return viewOf(result);
341
+ }
342
+
343
+ /**
344
+ * Create a function that returns a read-only managed view of an entry of `stored`, one view per entry. Any other
345
+ * value, and every entry of a list of primitives, is returned unchanged.
346
+ */
347
+ #viewsOf(stored: Val[]) {
348
+ const views = new Map<Val, Val>();
349
+ let indices: Map<Val, number> | undefined;
350
+
351
+ return (entry: Val) => {
352
+ if (!this.config.manageEntries || typeof entry !== "object" || entry === null) {
353
+ return entry;
354
+ }
355
+
356
+ let view = views.get(entry);
357
+ if (view === undefined) {
358
+ indices ??= new Map(stored.map((entry, index) => [entry, index]));
359
+ const index = indices.get(entry);
360
+ if (index === undefined) {
361
+ throw new InternalError(`Entry to view at ${this.reference.location.path} is not a stored entry`);
362
+ }
363
+
364
+ const location = { ...this.reference.location, path: this.reference.location.path.at(index) };
365
+ const reference = new ReadOnlyReference(entry, location, this.reference.rootOwner);
366
+ this.config.manageEntry(reference, this.session);
367
+ view = reference.owner;
368
+ views.set(entry, view);
369
+ }
370
+ return view;
371
+ };
372
+ }
373
+
374
+ /**
375
+ * Turn a caller's value into an entry the list may store: a copy of the value, prepared and validated. The
376
+ * caller's value stays unchanged.
377
+ */
378
+ #acceptEntry(value: Val, index: number) {
379
+ this.#sublocation.path.id = index;
380
+ if (value === undefined) {
381
+ throw new WriteError(this.#sublocation, `Entry ${index} has no value`);
382
+ }
383
+ const entry = this.prepareEntry(Internal.copy(value), this.#sublocation);
384
+ this.config.validateEntry?.(entry, this.session, this.#sublocation);
385
+ return entry;
386
+ }
387
+
226
388
  protected getIteratorFn(): Val.List[typeof Symbol.iterator] {
227
389
  return this.readVal()[Symbol.iterator];
228
390
  }
229
391
 
230
392
  get(_target: Val.List, property: PropertyKey, receiver: Val.List) {
231
- if (typeof property === "string" && property.match(/^\d+/)) {
232
- this.#sublocation.path.id = property;
233
- return this.readEntry(Number.parseInt(property), this.#sublocation);
393
+ const index = entryIndexFor(property);
394
+ if (index !== undefined) {
395
+ this.#sublocation.path.id = index;
396
+ return this.readEntry(index, this.#sublocation);
234
397
  }
235
398
 
236
399
  switch (property) {
@@ -253,15 +416,19 @@ class ListProxyHandler implements ProxyHandler<Val.List> {
253
416
  return undefined;
254
417
  }
255
418
 
419
+ const method = entryEdits.get(property);
420
+ if (method) {
421
+ return (...args: unknown[]) => this.editEntries(method, args, receiver);
422
+ }
423
+
256
424
  return Reflect.get(this.readVal(), property, receiver);
257
425
  }
258
426
 
259
427
  set(_target: Val.List, property: PropertyKey, newValue: Val, receiver: Val.List) {
260
- if (typeof property === "string" && property.match(/^\d+/)) {
261
- this.#sublocation.path.id = property;
262
- newValue = this.prepareEntry(newValue);
263
- this.config.validateEntry?.(newValue, this.session, this.#sublocation);
264
- this.writeEntry(Number.parseInt(property), newValue, this.#sublocation);
428
+ const index = entryIndexFor(property);
429
+ if (index !== undefined) {
430
+ this.config.authorizeWrite(this.session, this.reference.location);
431
+ this.writeEntry(index, this.#acceptEntry(newValue, index), this.#sublocation);
265
432
  return true;
266
433
  } else if (property === "length") {
267
434
  this.setListLength(newValue as number);
@@ -272,17 +439,19 @@ class ListProxyHandler implements ProxyHandler<Val.List> {
272
439
  }
273
440
 
274
441
  has(_target: Val.List, property: PropertyKey) {
275
- if (typeof property === "string" && property.match(/^\d+/)) {
276
- return this.hasEntry(Number.parseInt(property));
442
+ const index = entryIndexFor(property);
443
+ if (index !== undefined) {
444
+ return this.hasEntry(index);
277
445
  }
278
446
 
279
447
  return Reflect.has(this.readVal(), property);
280
448
  }
281
449
 
282
450
  deleteProperty(_target: Val.List, property: PropertyKey) {
283
- if (typeof property === "string" && property.match(/^\d+/)) {
284
- this.#sublocation.path.id = property;
285
- this.writeEntry(Number.parseInt(property), undefined, this.#sublocation);
451
+ const index = entryIndexFor(property);
452
+ if (index !== undefined) {
453
+ this.#sublocation.path.id = index;
454
+ this.deleteEntry(index, this.#sublocation);
286
455
  return true;
287
456
  }
288
457
 
@@ -293,8 +462,30 @@ class ListProxyHandler implements ProxyHandler<Val.List> {
293
462
  return Reflect.ownKeys(this.readVal());
294
463
  }
295
464
 
465
+ /**
466
+ * The descriptors of the entries and of `length` carry what {@link get} returns: the managed entry and the length
467
+ * this session sees.
468
+ */
296
469
  getOwnPropertyDescriptor(_target: Val.List, key: PropertyKey) {
297
- return Reflect.getOwnPropertyDescriptor(this.readVal(), key);
470
+ const index = entryIndexFor(key);
471
+ if (index === undefined) {
472
+ const descriptor = Reflect.getOwnPropertyDescriptor(this.readVal(), key);
473
+ if (key === "length" && descriptor !== undefined) {
474
+ descriptor.value = this.getListLength();
475
+ }
476
+ return descriptor;
477
+ }
478
+ if (index >= this.getListLength()) {
479
+ return undefined;
480
+ }
481
+
482
+ this.#sublocation.path.id = index;
483
+ return {
484
+ value: this.readEntry(index, this.#sublocation),
485
+ writable: true,
486
+ enumerable: true,
487
+ configurable: true,
488
+ };
298
489
  }
299
490
  }
300
491
 
@@ -303,6 +494,14 @@ class ListProxyHandler implements ProxyHandler<Val.List> {
303
494
  * list with fabric filtering enabled, logical indices are mapped to physical indices that match the actor's fabric.
304
495
  */
305
496
  class FabricFilteredListProxyHandler extends ListProxyHandler {
497
+ #isVisible(entry: Val) {
498
+ if (!isObject(entry)) {
499
+ return false;
500
+ }
501
+ const { fabricIndex } = entry as { fabricIndex?: number };
502
+ return !fabricIndex || fabricIndex === this.session.fabric;
503
+ }
504
+
306
505
  #mapScopedToActual(index: number, reading: boolean) {
307
506
  if (index < 0) {
308
507
  throw new (reading ? ReadError : WriteError)(
@@ -311,14 +510,10 @@ class FabricFilteredListProxyHandler extends ListProxyHandler {
311
510
  );
312
511
  }
313
512
 
513
+ const list = reading ? this.readVal() : this.writeVal();
314
514
  let nextPos = 0;
315
- for (let i = 0; i < this.readVal().length; i++) {
316
- const entry = this.readVal()[i] as undefined | { fabricIndex?: number };
317
- if (!isObject(entry)) {
318
- continue;
319
- }
320
-
321
- if (hasLocalActor(this.session) || !entry.fabricIndex || entry.fabricIndex === this.session.fabric) {
515
+ for (let i = 0; i < list.length; i++) {
516
+ if (this.#isVisible(list[i])) {
322
517
  if (nextPos === index) {
323
518
  return i;
324
519
  }
@@ -331,7 +526,7 @@ class FabricFilteredListProxyHandler extends ListProxyHandler {
331
526
  }
332
527
 
333
528
  if (nextPos === index) {
334
- return this.readVal().length;
529
+ return list.length;
335
530
  }
336
531
 
337
532
  throw new WriteError(this.reference.location, `Index ${index} would leave gaps in fabric-filtered list`);
@@ -341,7 +536,10 @@ class FabricFilteredListProxyHandler extends ListProxyHandler {
341
536
  try {
342
537
  return super.readEntry(this.#mapScopedToActual(index, true), this.reference.location) !== undefined;
343
538
  } catch (e) {
344
- return false;
539
+ if (e instanceof ReadError) {
540
+ return false;
541
+ }
542
+ throw e;
345
543
  }
346
544
  }
347
545
 
@@ -349,85 +547,58 @@ class FabricFilteredListProxyHandler extends ListProxyHandler {
349
547
  return super.readEntry(this.#mapScopedToActual(index, true), location);
350
548
  }
351
549
 
352
- protected override prepareEntry(value: Val) {
353
- if (isObject(value)) {
354
- (value as { fabricIndex?: number }).fabricIndex ??= this.session.fabric;
550
+ protected override prepareEntry(value: Val, location: AccessControl.Location) {
551
+ if (!isObject(value)) {
552
+ throw new WriteError(location, `Fabric scoped list value is not an object`, Status.Failure);
355
553
  }
554
+ (value as { fabricIndex?: number }).fabricIndex ??= this.session.fabric;
356
555
  return value;
357
556
  }
358
557
 
359
558
  protected override writeEntry(index: number, value: Val, location: AccessControl.Location) {
360
- if (value === undefined) {
361
- const valueIndex = this.#mapScopedToActual(index, false);
362
- this.writeVal().splice(valueIndex, 1);
363
- } else {
364
- if (!isObject(value)) {
365
- throw new WriteError(location, `Fabric scoped list value is not an object`, Status.Failure);
366
- }
367
- super.writeEntry(this.#mapScopedToActual(index, false), value, location);
368
- }
559
+ super.writeEntry(this.#mapScopedToActual(index, false), value, location);
369
560
  }
370
561
 
371
- protected override getListLength() {
372
- let length = 0;
373
- for (let i = 0; i < this.readVal().length; i++) {
374
- const entry = this.readVal()[i] as undefined | { fabricIndex?: number };
375
- if (isObject(entry) && (!entry.fabricIndex || entry.fabricIndex === this.session.fabric)) {
376
- length++;
377
- }
562
+ /**
563
+ * Remove an entry. Any entry may go, because the later entries of this fabric move up to fill the gap. An index
564
+ * beyond the end is ignored.
565
+ */
566
+ protected override deleteEntry(index: number, location: AccessControl.Location) {
567
+ if (index >= this.getListLength()) {
568
+ return;
378
569
  }
379
- return length;
570
+ this.config.authorizeWrite(this.session, location);
571
+ const entries = this.visibleEntries();
572
+ entries.splice(index, 1);
573
+ this.storeEntries(entries);
380
574
  }
381
575
 
382
- protected override setListLength(length: number) {
383
- const formerLength = this.getListLength();
384
-
385
- this.reference.change(() => {
386
- for (let i = formerLength - 1; i >= length; i--) {
387
- const entry = this.writeVal()[this.#mapScopedToActual(i, true)] as undefined | { fabricIndex?: number };
388
- if (isObject(entry) && (!entry.fabricIndex || entry.fabricIndex === this.session.fabric)) {
389
- this.writeVal().splice(this.#mapScopedToActual(i, false), 1);
390
- } else if (entry !== undefined) {
391
- throw new WriteError(
392
- this.reference.location,
393
- `Fabric scoped list value is not an object`,
394
- Status.Failure,
395
- );
396
- }
397
- }
398
- }, "length");
576
+ protected override visibleEntries() {
577
+ return this.readVal().filter(entry => this.#isVisible(entry));
399
578
  }
400
579
 
401
- protected override getIteratorFn(): Val.List[typeof Symbol.iterator] {
402
- const fabric = this.session.fabric;
403
- const readVal = () => this.readVal();
404
-
405
- return (() => {
406
- const iterator = readVal()[Symbol.iterator]();
407
-
408
- return {
409
- ...iterator,
410
- next() {
411
- while (true) {
412
- const next = iterator.next();
413
-
414
- if (
415
- !next.done &&
416
- isObject(next.value) &&
417
- (next.value as { fabricIndex?: number }).fabricIndex !== fabric
418
- ) {
419
- continue;
420
- }
580
+ /**
581
+ * Put `entries` into the positions of this fabric's entries, in order, and keep other fabrics' entries in their
582
+ * order. Entries beyond those positions go to the end; positions beyond the entries are removed.
583
+ */
584
+ protected override storeEntries(entries: Val[]) {
585
+ const stored = this.readVal();
586
+ const result = new Array<Val>();
587
+ let next = 0;
588
+ for (const entry of stored) {
589
+ if (!this.#isVisible(entry)) {
590
+ result.push(entry);
591
+ } else if (next < entries.length) {
592
+ result.push(entries[next++]);
593
+ }
594
+ }
595
+ result.push(...entries.slice(next));
421
596
 
422
- return next;
423
- }
424
- },
597
+ super.storeEntries(result);
598
+ }
425
599
 
426
- [Symbol.iterator]() {
427
- return this;
428
- },
429
- };
430
- }) as Val.List[typeof Symbol.iterator];
600
+ protected override getListLength() {
601
+ return this.visibleEntries().length;
431
602
  }
432
603
 
433
604
  override ownKeys() {
@@ -437,26 +608,10 @@ class FabricFilteredListProxyHandler extends ListProxyHandler {
437
608
  if (typeof k !== "string") {
438
609
  return true;
439
610
  }
440
- if (!k.match(/^\d+$/)) {
441
- return true;
442
- }
443
- if (Number.parseInt(k) < length) {
444
- return true;
445
- }
446
- return false;
611
+ const index = entryIndexFor(k);
612
+ return index === undefined || index < length;
447
613
  });
448
614
  }
449
-
450
- override getOwnPropertyDescriptor(_target: Val.List, key: PropertyKey) {
451
- if (typeof key === "string" && key.match(/^\d+$/)) {
452
- key = Number.parseInt(key);
453
- }
454
- if (typeof key !== "number") {
455
- return Reflect.getOwnPropertyDescriptor(this.readVal(), key);
456
- }
457
-
458
- return Reflect.getOwnPropertyDescriptor(this.readVal(), this.#mapScopedToActual(key, true));
459
- }
460
615
  }
461
616
 
462
617
  function createProxy(config: ListConfig, reference: ValReference<Val.List>, session: ValueSupervisor.Session) {