@zlink-systems/framework 0.30.1 → 0.30.2

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 (340) hide show
  1. package/dist/.tsbuildinfo +1 -1
  2. package/dist/contracts/Common/ZLinkEncodedPayload.d.ts +6 -0
  3. package/dist/contracts/Common/ZLinkEncodedPayload.js +18 -3
  4. package/dist/contracts/Common/encoded-payload-storage.d.ts +1 -1
  5. package/dist/contracts/Common/encoded-payload-storage.js +5 -2
  6. package/dist/contracts/Configuration/Builders.d.ts +1 -1
  7. package/dist/contracts/Configuration/RegistrationBuilderPolicy.d.ts +2 -1
  8. package/dist/contracts/Configuration/RegistrationBuilderPolicy.js +5 -1
  9. package/dist/contracts/Configuration/RegistrationBuilders.js +2 -2
  10. package/dist/contracts/Configuration/RegistrationTypes.d.ts +1 -0
  11. package/dist/contracts/Dispatch/ZLinkDispatchOptions.d.ts +2 -2
  12. package/dist/contracts/Locations/Rows.d.ts +2 -0
  13. package/dist/contracts/Spots/Contracts.d.ts +4 -0
  14. package/dist/contracts/Spots/ZLinkSpot.d.ts +3 -3
  15. package/dist/runtime/abort.d.ts +5 -0
  16. package/dist/runtime/abort.js +10 -0
  17. package/dist/runtime/actors/actor-authority-publication.js +3 -2
  18. package/dist/runtime/actors/actor-client.d.ts +0 -1
  19. package/dist/runtime/actors/actor-client.js +38 -45
  20. package/dist/runtime/actors/actor-context.d.ts +2 -0
  21. package/dist/runtime/actors/actor-context.js +46 -9
  22. package/dist/runtime/actors/actor-handoff.d.ts +7 -3
  23. package/dist/runtime/actors/actor-handoff.js +212 -88
  24. package/dist/runtime/actors/actor-join-relocation.d.ts +2 -0
  25. package/dist/runtime/actors/actor-local-native-join.js +4 -0
  26. package/dist/runtime/actors/actor-mailbox.js +27 -1
  27. package/dist/runtime/actors/actor-remote-joiner.js +3 -1
  28. package/dist/runtime/actors/actor-reply.d.ts +4 -0
  29. package/dist/runtime/actors/actor-reply.js +29 -0
  30. package/dist/runtime/actors/actor-runtime-contracts.d.ts +2 -0
  31. package/dist/runtime/actors/actor-runtime-state.js +2 -20
  32. package/dist/runtime/actors/actor-source-transfer.d.ts +1 -17
  33. package/dist/runtime/actors/index.d.ts +6 -2
  34. package/dist/runtime/actors/index.js +37 -21
  35. package/dist/runtime/actors/session-disconnected-wire.d.ts +8 -0
  36. package/dist/runtime/actors/session-disconnected-wire.js +48 -0
  37. package/dist/runtime/admission.d.ts +9 -1
  38. package/dist/runtime/admission.js +55 -32
  39. package/dist/runtime/application-jobs/application-job-queue-scope.d.ts +13 -0
  40. package/dist/runtime/application-jobs/application-job-queue-scope.js +27 -1
  41. package/dist/runtime/application-jobs/contracts.d.ts +2 -0
  42. package/dist/runtime/backend/contracts/index.d.ts +19 -3
  43. package/dist/runtime/backend/mesh-actor-session-node-adapter.js +2 -2
  44. package/dist/runtime/backend/mesh-completion-table.js +5 -0
  45. package/dist/runtime/backend/mesh-dispatch-pump.d.ts +26 -2
  46. package/dist/runtime/backend/mesh-dispatch-pump.js +193 -107
  47. package/dist/runtime/backend/node/node-raw-binding-port.js +90 -58
  48. package/dist/runtime/backend/node/node-raw-mesh-backend.d.ts +33 -8
  49. package/dist/runtime/backend/node/node-raw-mesh-backend.js +142 -143
  50. package/dist/runtime/backend/node/node-socket-backend-adapter.d.ts +1 -1
  51. package/dist/runtime/backend/node/node-socket-backend-adapter.js +5 -5
  52. package/dist/runtime/channels/channel-clients.d.ts +1 -0
  53. package/dist/runtime/channels/channel-clients.js +20 -5
  54. package/dist/runtime/channels/channel-dispatch-pipeline.d.ts +22 -3
  55. package/dist/runtime/channels/channel-dispatch-pipeline.js +103 -57
  56. package/dist/runtime/channels/channel-dispatchers.d.ts +3 -2
  57. package/dist/runtime/channels/channel-dispatchers.js +44 -37
  58. package/dist/runtime/channels/channel-envelope.d.ts +1 -0
  59. package/dist/runtime/channels/channel-envelope.js +74 -31
  60. package/dist/runtime/channels/channel-runtime-lifecycle.d.ts +4 -3
  61. package/dist/runtime/channels/channel-runtime-lifecycle.js +19 -24
  62. package/dist/runtime/channels/channel-runtime-manager.d.ts +3 -2
  63. package/dist/runtime/channels/channel-runtime-manager.js +4 -4
  64. package/dist/runtime/channels/channel-transports.d.ts +0 -1
  65. package/dist/runtime/channels/channel-transports.js +35 -33
  66. package/dist/runtime/channels/client-server-location-runtime.js +5 -4
  67. package/dist/runtime/channels/dispatch-error-reporter.d.ts +2 -1
  68. package/dist/runtime/channels/dispatch-error-reporter.js +2 -1
  69. package/dist/runtime/channels/fanout-location-runtime.d.ts +1 -1
  70. package/dist/runtime/channels/fanout-location-runtime.js +3 -3
  71. package/dist/runtime/diagnostics/flow-context.js +19 -7
  72. package/dist/runtime/diagnostics/index.js +4 -9
  73. package/dist/runtime/diagnostics/message-flow.d.ts +8 -0
  74. package/dist/runtime/diagnostics/message-flow.js +35 -5
  75. package/dist/runtime/diagnostics/runtime-metrics.d.ts +2 -2
  76. package/dist/runtime/diagnostics/runtime-metrics.js +10 -8
  77. package/dist/runtime/execution/index.d.ts +4 -2
  78. package/dist/runtime/execution/index.js +33 -10
  79. package/dist/runtime/execution/serial-execution-queue.d.ts +4 -0
  80. package/dist/runtime/execution/serial-execution-queue.js +21 -2
  81. package/dist/runtime/execution/state-lane.d.ts +2 -0
  82. package/dist/runtime/execution/state-lane.js +5 -0
  83. package/dist/runtime/foundation/operation-registry.d.ts +25 -1
  84. package/dist/runtime/foundation/operation-registry.js +86 -18
  85. package/dist/runtime/foundation/raw-service-mesh-runtime.d.ts +39 -3
  86. package/dist/runtime/foundation/raw-service-mesh-runtime.js +151 -55
  87. package/dist/runtime/foundation/service-liveness-registry.d.ts +12 -1
  88. package/dist/runtime/foundation/service-liveness-registry.js +38 -0
  89. package/dist/runtime/foundation/service-mailbox.d.ts +7 -0
  90. package/dist/runtime/foundation/service-maintenance-runtime.js +1 -6
  91. package/dist/runtime/foundation/service-relocation-object-owner.d.ts +2 -3
  92. package/dist/runtime/foundation/service-relocation-object-owner.js +48 -35
  93. package/dist/runtime/foundation/service-relocation-runtime.js +7 -3
  94. package/dist/runtime/foundation/service-runtime-contracts.d.ts +8 -1
  95. package/dist/runtime/foundation/service-session-binding-ingress-port.d.ts +2 -1
  96. package/dist/runtime/foundation/service-stateful-registry.d.ts +5 -4
  97. package/dist/runtime/foundation/service-stateful-registry.js +24 -26
  98. package/dist/runtime/foundation/service-stateful-runtime.d.ts +72 -6
  99. package/dist/runtime/foundation/service-stateful-runtime.js +444 -117
  100. package/dist/runtime/foundation/service-stateful-wire-codec.d.ts +14 -1
  101. package/dist/runtime/foundation/service-stateful-wire-codec.js +48 -27
  102. package/dist/runtime/foundation/service-wire-binary-primitives.d.ts +6 -1
  103. package/dist/runtime/foundation/service-wire-binary-primitives.js +27 -11
  104. package/dist/runtime/foundation/service-wire-constants.generated.d.ts +1 -0
  105. package/dist/runtime/foundation/service-wire-constants.generated.js +1 -0
  106. package/dist/runtime/foundation/service-wire-m6a-codec.d.ts +10 -0
  107. package/dist/runtime/foundation/service-wire-m6a-codec.js +166 -53
  108. package/dist/runtime/host/actor-packet-relay.d.ts +6 -4
  109. package/dist/runtime/host/actor-packet-relay.js +59 -72
  110. package/dist/runtime/host/actor-placement-coordinator.js +25 -8
  111. package/dist/runtime/host/actor-transfer-runtime.d.ts +7 -31
  112. package/dist/runtime/host/actor-transfer-runtime.js +85 -331
  113. package/dist/runtime/host/application-job-queue.d.ts +24 -3
  114. package/dist/runtime/host/application-job-queue.js +28 -41
  115. package/dist/runtime/host/index.d.ts +5 -1
  116. package/dist/runtime/host/index.js +171 -97
  117. package/dist/runtime/host/location-runtime-owner.js +2 -6
  118. package/dist/runtime/host/mesh-router-resolver.d.ts +4 -0
  119. package/dist/runtime/host/mesh-router-resolver.js +14 -6
  120. package/dist/runtime/host/remote-bound-session-relay.d.ts +2 -4
  121. package/dist/runtime/host/remote-bound-session-relay.js +71 -190
  122. package/dist/runtime/host/route-mesh-runtime.d.ts +2 -2
  123. package/dist/runtime/host/route-mesh-runtime.js +5 -3
  124. package/dist/runtime/host/runtime-shutdown.d.ts +1 -0
  125. package/dist/runtime/host/runtime-shutdown.js +3 -2
  126. package/dist/runtime/host/service-relocation-host-runtime.d.ts +17 -7
  127. package/dist/runtime/host/service-relocation-host-runtime.js +550 -367
  128. package/dist/runtime/host/spot-runtime-options-factory.js +15 -7
  129. package/dist/runtime/host/user-spot-creation-coordinator.js +33 -84
  130. package/dist/runtime/locations/auto-connect-loop.d.ts +2 -0
  131. package/dist/runtime/locations/auto-connect-loop.js +22 -14
  132. package/dist/runtime/locations/auto-connect-reconciler.js +0 -6
  133. package/dist/runtime/locations/auto-connect-types.d.ts +0 -1
  134. package/dist/runtime/locations/descriptor-publication.d.ts +4 -0
  135. package/dist/runtime/locations/descriptor-publication.js +11 -0
  136. package/dist/runtime/locations/domain-store-contract.d.ts +1 -0
  137. package/dist/runtime/locations/in-memory-authority-store.d.ts +7 -1
  138. package/dist/runtime/locations/in-memory-authority-store.js +56 -19
  139. package/dist/runtime/locations/in-memory-location-store.js +1 -10
  140. package/dist/runtime/locations/index.d.ts +1 -0
  141. package/dist/runtime/locations/index.js +1 -0
  142. package/dist/runtime/locations/lease-tracker.js +1 -6
  143. package/dist/runtime/locations/location-store-repository.d.ts +51 -1
  144. package/dist/runtime/locations/location-store-repository.js +363 -139
  145. package/dist/runtime/locations/relocation-blob.d.ts +18 -1
  146. package/dist/runtime/locations/relocation-blob.js +52 -1
  147. package/dist/runtime/locations/request-source-resolver.d.ts +37 -0
  148. package/dist/runtime/locations/request-source-resolver.js +80 -0
  149. package/dist/runtime/locations/resolvers.js +1 -1
  150. package/dist/runtime/locations/runtime.d.ts +6 -2
  151. package/dist/runtime/locations/runtime.js +37 -30
  152. package/dist/runtime/messaging/payload-codec.d.ts +7 -1
  153. package/dist/runtime/messaging/payload-codec.js +7 -6
  154. package/dist/runtime/messaging/request-result.js +29 -26
  155. package/dist/runtime/protocol/service_wire_codec.generated.d.ts +19 -1
  156. package/dist/runtime/protocol/service_wire_codec.generated.js +85 -0
  157. package/dist/runtime/protocol/service_wire_pilot_codec.generated.d.ts +7 -1
  158. package/dist/runtime/protocol/service_wire_pilot_codec.generated.js +23 -7
  159. package/dist/runtime/spots/formal-remote-actor-admission-registry.js +3 -2
  160. package/dist/runtime/spots/index.d.ts +18 -11
  161. package/dist/runtime/spots/index.js +234 -176
  162. package/dist/runtime/spots/spot-activation-registry.d.ts +4 -2
  163. package/dist/runtime/spots/spot-activation-registry.js +21 -11
  164. package/dist/runtime/spots/spot-activation-state.d.ts +1 -1
  165. package/dist/runtime/spots/spot-activation-state.js +7 -7
  166. package/dist/runtime/spots/spot-activation.d.ts +6 -3
  167. package/dist/runtime/spots/spot-activation.js +123 -44
  168. package/dist/runtime/spots/spot-actor-admission-coordinator.d.ts +1 -0
  169. package/dist/runtime/spots/spot-actor-admission-coordinator.js +13 -22
  170. package/dist/runtime/spots/spot-actor-membership.d.ts +0 -1
  171. package/dist/runtime/spots/spot-actor-membership.js +0 -8
  172. package/dist/runtime/spots/spot-actor-packet-dispatch.js +33 -8
  173. package/dist/runtime/spots/spot-actor-packet-drain.js +5 -33
  174. package/dist/runtime/spots/spot-entry-activation.d.ts +2 -0
  175. package/dist/runtime/spots/spot-entry-activation.js +14 -9
  176. package/dist/runtime/spots/spot-handler-registry.d.ts +4 -3
  177. package/dist/runtime/spots/spot-handler-registry.js +6 -2
  178. package/dist/runtime/spots/spot-manager-internal-contracts.d.ts +2 -2
  179. package/dist/runtime/spots/spot-manager-public.js +2 -2
  180. package/dist/runtime/spots/spot-node-autoconnect.d.ts +2 -1
  181. package/dist/runtime/spots/spot-node-autoconnect.js +18 -39
  182. package/dist/runtime/spots/spot-node-runtime-manager.d.ts +19 -2
  183. package/dist/runtime/spots/spot-node-runtime-manager.js +115 -50
  184. package/dist/runtime/spots/spot-outbound.js +3 -3
  185. package/dist/runtime/spots/spot-remote-codec.js +5 -1
  186. package/dist/runtime/spots/spot-runtime-ports.d.ts +0 -1
  187. package/dist/runtime/spots/spot-serial-executor.d.ts +10 -0
  188. package/dist/runtime/spots/spot-serial-executor.js +61 -8
  189. package/dist/runtime/spots/spot-serial-turn-executor.js +19 -2
  190. package/dist/runtime/spots/spot-subscription-dispatch.js +1 -1
  191. package/dist/runtime/spots/spot-timer.d.ts +57 -5
  192. package/dist/runtime/spots/spot-timer.js +287 -103
  193. package/dist/runtime/streams/actor-session-binding-registry.d.ts +42 -11
  194. package/dist/runtime/streams/actor-session-binding-registry.js +165 -48
  195. package/dist/runtime/streams/actor-session-binding-runtime-owner.d.ts +8 -4
  196. package/dist/runtime/streams/bound-actor-relay-sender.d.ts +2 -1
  197. package/dist/runtime/streams/bound-actor-relay-sender.js +15 -8
  198. package/dist/runtime/streams/bound-session-service.d.ts +1 -1
  199. package/dist/runtime/streams/bound-session-service.js +6 -11
  200. package/dist/runtime/streams/index.d.ts +3 -2
  201. package/dist/runtime/streams/index.js +6 -4
  202. package/dist/runtime/streams/managed-stream.js +3 -2
  203. package/dist/runtime/streams/native-fallback-bound-session.js +8 -73
  204. package/dist/runtime/streams/session-actor-coordinator.d.ts +2 -8
  205. package/dist/runtime/streams/session-actor-coordinator.js +15 -32
  206. package/dist/runtime/streams/stream-binding-runtime-ports.d.ts +3 -10
  207. package/dist/runtime/streams/stream-session-runtime.js +1 -4
  208. package/dist/runtime/workers/index.js +1 -1
  209. package/package.json +3 -3
  210. package/src/contracts/Common/ZLinkEncodedPayload.ts +24 -4
  211. package/src/contracts/Common/encoded-payload-storage.ts +6 -3
  212. package/src/contracts/Configuration/Builders.ts +4 -1
  213. package/src/contracts/Configuration/RegistrationBuilderPolicy.ts +7 -2
  214. package/src/contracts/Configuration/RegistrationBuilders.ts +6 -2
  215. package/src/contracts/Configuration/RegistrationTypes.ts +1 -0
  216. package/src/contracts/Dispatch/ZLinkDispatchOptions.ts +2 -1
  217. package/src/contracts/Locations/Rows.ts +2 -0
  218. package/src/contracts/Spots/Contracts.ts +8 -0
  219. package/src/contracts/Spots/ZLinkSpot.ts +3 -3
  220. package/src/runtime/abort.ts +12 -0
  221. package/src/runtime/actors/actor-authority-publication.ts +3 -2
  222. package/src/runtime/actors/actor-client.ts +61 -70
  223. package/src/runtime/actors/actor-context.ts +49 -9
  224. package/src/runtime/actors/actor-handoff.ts +282 -106
  225. package/src/runtime/actors/actor-join-relocation.ts +2 -0
  226. package/src/runtime/actors/actor-local-native-join.ts +4 -0
  227. package/src/runtime/actors/actor-mailbox.ts +40 -2
  228. package/src/runtime/actors/actor-remote-joiner.ts +6 -1
  229. package/src/runtime/actors/actor-reply.ts +42 -0
  230. package/src/runtime/actors/actor-runtime-contracts.ts +2 -0
  231. package/src/runtime/actors/actor-runtime-state.ts +2 -20
  232. package/src/runtime/actors/actor-source-transfer.ts +1 -34
  233. package/src/runtime/actors/index.ts +41 -27
  234. package/src/runtime/actors/session-disconnected-wire.ts +66 -0
  235. package/src/runtime/admission.ts +69 -34
  236. package/src/runtime/application-jobs/application-job-queue-scope.ts +33 -1
  237. package/src/runtime/application-jobs/contracts.ts +2 -0
  238. package/src/runtime/backend/contracts/index.ts +39 -4
  239. package/src/runtime/backend/mesh-actor-session-node-adapter.ts +5 -3
  240. package/src/runtime/backend/mesh-completion-table.ts +4 -0
  241. package/src/runtime/backend/mesh-dispatch-pump.ts +223 -124
  242. package/src/runtime/backend/node/node-raw-binding-port.ts +106 -70
  243. package/src/runtime/backend/node/node-raw-mesh-backend.ts +221 -170
  244. package/src/runtime/backend/node/node-socket-backend-adapter.ts +5 -5
  245. package/src/runtime/channels/channel-clients.ts +49 -24
  246. package/src/runtime/channels/channel-dispatch-pipeline.ts +173 -124
  247. package/src/runtime/channels/channel-dispatchers.ts +116 -72
  248. package/src/runtime/channels/channel-envelope.ts +105 -36
  249. package/src/runtime/channels/channel-runtime-lifecycle.ts +13 -13
  250. package/src/runtime/channels/channel-runtime-manager.ts +12 -5
  251. package/src/runtime/channels/channel-transports.ts +49 -58
  252. package/src/runtime/channels/client-server-location-runtime.ts +11 -10
  253. package/src/runtime/channels/dispatch-error-reporter.ts +4 -2
  254. package/src/runtime/channels/fanout-location-runtime.ts +17 -9
  255. package/src/runtime/diagnostics/flow-context.ts +20 -7
  256. package/src/runtime/diagnostics/index.ts +1 -7
  257. package/src/runtime/diagnostics/message-flow.ts +47 -9
  258. package/src/runtime/diagnostics/runtime-metrics.ts +12 -10
  259. package/src/runtime/execution/index.ts +40 -14
  260. package/src/runtime/execution/serial-execution-queue.ts +31 -4
  261. package/src/runtime/execution/state-lane.ts +7 -0
  262. package/src/runtime/foundation/operation-registry.ts +98 -20
  263. package/src/runtime/foundation/raw-service-mesh-runtime.ts +244 -67
  264. package/src/runtime/foundation/service-liveness-registry.ts +39 -0
  265. package/src/runtime/foundation/service-mailbox.ts +8 -0
  266. package/src/runtime/foundation/service-maintenance-runtime.ts +1 -8
  267. package/src/runtime/foundation/service-relocation-object-owner.ts +54 -37
  268. package/src/runtime/foundation/service-relocation-runtime.ts +7 -3
  269. package/src/runtime/foundation/service-runtime-contracts.ts +12 -1
  270. package/src/runtime/foundation/service-session-binding-ingress-port.ts +2 -1
  271. package/src/runtime/foundation/service-stateful-registry.ts +38 -35
  272. package/src/runtime/foundation/service-stateful-runtime.ts +667 -152
  273. package/src/runtime/foundation/service-stateful-wire-codec.ts +49 -11
  274. package/src/runtime/foundation/service-wire-binary-primitives.ts +35 -12
  275. package/src/runtime/foundation/service-wire-constants.generated.ts +1 -0
  276. package/src/runtime/foundation/service-wire-m6a-codec.ts +187 -51
  277. package/src/runtime/host/actor-packet-relay.ts +113 -94
  278. package/src/runtime/host/actor-placement-coordinator.ts +31 -8
  279. package/src/runtime/host/actor-transfer-runtime.ts +104 -430
  280. package/src/runtime/host/application-job-queue.ts +29 -44
  281. package/src/runtime/host/index.ts +286 -129
  282. package/src/runtime/host/location-runtime-owner.ts +2 -6
  283. package/src/runtime/host/mesh-router-resolver.ts +13 -5
  284. package/src/runtime/host/remote-bound-session-relay.ts +86 -248
  285. package/src/runtime/host/route-mesh-runtime.ts +11 -5
  286. package/src/runtime/host/runtime-shutdown.ts +15 -4
  287. package/src/runtime/host/service-relocation-host-runtime.ts +784 -475
  288. package/src/runtime/host/spot-runtime-options-factory.ts +18 -7
  289. package/src/runtime/host/user-spot-creation-coordinator.ts +41 -100
  290. package/src/runtime/locations/auto-connect-loop.ts +22 -14
  291. package/src/runtime/locations/auto-connect-reconciler.ts +0 -6
  292. package/src/runtime/locations/auto-connect-types.ts +0 -1
  293. package/src/runtime/locations/descriptor-publication.ts +7 -0
  294. package/src/runtime/locations/domain-store-contract.ts +5 -0
  295. package/src/runtime/locations/in-memory-authority-store.ts +85 -23
  296. package/src/runtime/locations/in-memory-location-store.ts +1 -12
  297. package/src/runtime/locations/index.ts +1 -0
  298. package/src/runtime/locations/lease-tracker.ts +2 -9
  299. package/src/runtime/locations/location-store-repository.ts +628 -152
  300. package/src/runtime/locations/relocation-blob.ts +75 -1
  301. package/src/runtime/locations/request-source-resolver.ts +138 -0
  302. package/src/runtime/locations/resolvers.ts +2 -2
  303. package/src/runtime/locations/runtime.ts +70 -40
  304. package/src/runtime/messaging/payload-codec.ts +8 -11
  305. package/src/runtime/messaging/request-result.ts +33 -29
  306. package/src/runtime/protocol/service_wire_codec.generated.ts +87 -4
  307. package/src/runtime/protocol/service_wire_pilot_codec.generated.ts +13 -10
  308. package/src/runtime/spots/formal-remote-actor-admission-registry.ts +3 -2
  309. package/src/runtime/spots/index.ts +375 -281
  310. package/src/runtime/spots/spot-activation-registry.ts +25 -13
  311. package/src/runtime/spots/spot-activation-state.ts +12 -19
  312. package/src/runtime/spots/spot-activation.ts +170 -86
  313. package/src/runtime/spots/spot-actor-admission-coordinator.ts +25 -55
  314. package/src/runtime/spots/spot-actor-membership.ts +0 -15
  315. package/src/runtime/spots/spot-actor-packet-dispatch.ts +56 -11
  316. package/src/runtime/spots/spot-actor-packet-drain.ts +9 -52
  317. package/src/runtime/spots/spot-entry-activation.ts +24 -19
  318. package/src/runtime/spots/spot-handler-registry.ts +15 -4
  319. package/src/runtime/spots/spot-manager-internal-contracts.ts +2 -2
  320. package/src/runtime/spots/spot-manager-public.ts +2 -2
  321. package/src/runtime/spots/spot-node-autoconnect.ts +22 -45
  322. package/src/runtime/spots/spot-node-runtime-manager.ts +197 -67
  323. package/src/runtime/spots/spot-outbound.ts +3 -3
  324. package/src/runtime/spots/spot-remote-codec.ts +9 -2
  325. package/src/runtime/spots/spot-runtime-ports.ts +0 -1
  326. package/src/runtime/spots/spot-serial-executor.ts +97 -25
  327. package/src/runtime/spots/spot-serial-turn-executor.ts +22 -3
  328. package/src/runtime/spots/spot-subscription-dispatch.ts +1 -1
  329. package/src/runtime/spots/spot-timer.ts +413 -157
  330. package/src/runtime/streams/actor-session-binding-registry.ts +236 -64
  331. package/src/runtime/streams/actor-session-binding-runtime-owner.ts +16 -8
  332. package/src/runtime/streams/bound-actor-relay-sender.ts +23 -9
  333. package/src/runtime/streams/bound-session-service.ts +7 -10
  334. package/src/runtime/streams/index.ts +12 -6
  335. package/src/runtime/streams/managed-stream.ts +4 -2
  336. package/src/runtime/streams/native-fallback-bound-session.ts +14 -103
  337. package/src/runtime/streams/session-actor-coordinator.ts +39 -88
  338. package/src/runtime/streams/stream-binding-runtime-ports.ts +3 -9
  339. package/src/runtime/streams/stream-session-runtime.ts +1 -5
  340. package/src/runtime/workers/index.ts +1 -1
@@ -81,6 +81,7 @@ class DefaultZLinkRouteClient {
81
81
  spotRouterChannelIdForMesh;
82
82
  channelTransport;
83
83
  nodeSends = new Map();
84
+ nodeRequests = new Map();
84
85
  constructor(registration, transport, spotRouterChannelIdForMesh = (meshName) => meshName, channelTransport) {
85
86
  this.registration = registration;
86
87
  this.transport = transport;
@@ -104,7 +105,18 @@ class DefaultZLinkRouteClient {
104
105
  return new DefaultZLinkSendCall(prepared.validate, prepared.submit, message);
105
106
  }
106
107
  requestToNode(meshName, targetNodeRid, request) {
107
- return new DefaultZLinkRequestCall(() => this.requireMesh(meshName), (packetName, timeoutMs, metadata, signal, onAdmitted) => this.requireTransport().request(meshName, targetNodeRid, packetName, request, timeoutMs, signal, metadata, onAdmitted), this.defaultRequestTimeout(meshName));
108
+ let targets = this.nodeRequests.get(meshName);
109
+ if (targets === undefined)
110
+ this.nodeRequests.set(meshName, (targets = new Map()));
111
+ let prepared = targets.get(targetNodeRid);
112
+ if (prepared === undefined) {
113
+ prepared = {
114
+ validate: () => this.requireMesh(meshName),
115
+ submit: (packetName, timeoutMs, metadata, signal, onAdmitted, message) => this.requireTransport().request(meshName, targetNodeRid, packetName, message, timeoutMs, signal, metadata, onAdmitted)
116
+ };
117
+ targets.set(targetNodeRid, prepared);
118
+ }
119
+ return new DefaultZLinkRequestCall(prepared.validate, prepared.submit, this.defaultRequestTimeout(meshName), request);
108
120
  }
109
121
  sendToChannel(channelName, message) {
110
122
  return new DefaultZLinkSendCall(() => this.requireChannelRoute(channelName), async (packetName, metadata) => {
@@ -289,13 +301,16 @@ class DefaultZLinkRequestCall {
289
301
  validate;
290
302
  submitter;
291
303
  defaultRequestTimeoutMs;
304
+ message;
292
305
  timeoutMs;
293
306
  selectedMetadata;
294
307
  turn = (0, execution_1.captureZLinkSpotSerialTurn)();
295
- constructor(validate, submitter, defaultRequestTimeoutMs) {
308
+ /** `message` is the request payload a prepared submitter receives per call. */
309
+ constructor(validate, submitter, defaultRequestTimeoutMs, message) {
296
310
  this.validate = validate;
297
311
  this.submitter = submitter;
298
312
  this.defaultRequestTimeoutMs = defaultRequestTimeoutMs;
313
+ this.message = message;
299
314
  }
300
315
  metadata(keyOrMetadata, value) {
301
316
  this.selectedMetadata ??= new Map();
@@ -317,15 +332,15 @@ class DefaultZLinkRequestCall {
317
332
  return (0, request_result_1.createZLinkRequest)((onAdmitted) => {
318
333
  (0, abort_1.throwIfAborted)(signal);
319
334
  this.validate();
320
- return this.submitter(undefined, this.timeoutMs ?? this.defaultRequestTimeoutMs, this.selectedMetadata === undefined ? EMPTY_CALL_METADATA : new Map(this.selectedMetadata), signal, onAdmitted);
335
+ return this.submitter(undefined, this.timeoutMs ?? this.defaultRequestTimeoutMs, this.selectedMetadata === undefined ? EMPTY_CALL_METADATA : new Map(this.selectedMetadata), signal, onAdmitted, this.message);
321
336
  });
322
337
  }
323
338
  async yield(signal) {
324
339
  const turn = (0, execution_1.requireZLinkYieldTurn)(this.turn);
325
340
  (0, abort_1.throwIfAborted)(signal);
326
341
  this.validate();
327
- const pending = this.submitter(undefined, this.timeoutMs ?? this.defaultRequestTimeoutMs, this.selectedMetadata === undefined ? EMPTY_CALL_METADATA : new Map(this.selectedMetadata), signal);
328
- return turn.yieldPromise(pending);
342
+ const pending = this.submitter(undefined, this.timeoutMs ?? this.defaultRequestTimeoutMs, this.selectedMetadata === undefined ? EMPTY_CALL_METADATA : new Map(this.selectedMetadata), signal, undefined, this.message);
343
+ return turn.yieldFrameworkPromise(pending);
329
344
  }
330
345
  }
331
346
  class DefaultZLinkPublishCall {
@@ -1,3 +1,4 @@
1
+ import type { ZLinkMeshDispatchAdmission } from '../admission';
1
2
  import type { ZLinkMessageContext, ZLinkHandlerFilter, ZLinkUnhandledDispatchOptions, ZLinkFlowOrigin } from '../../contracts';
2
3
  import { ZLinkFrameworkException } from '../../contracts';
3
4
  import { ZLinkDispatchMessageKind, ZLinkDispatchErrorSurface } from '../../contracts/Dispatch/ZLinkDispatchOptions';
@@ -31,7 +32,7 @@ interface ZLinkOneWayDispatch<TContext extends ZLinkMessageContext> {
31
32
  readonly context: TContext;
32
33
  readonly signal?: AbortSignal;
33
34
  }
34
- interface ZLinkRequestDispatch<TContext extends ZLinkMessageContext> {
35
+ export interface ZLinkRequestDispatch<TContext extends ZLinkMessageContext> {
35
36
  readonly fields: ZLinkChannelDispatchFields;
36
37
  readonly envelope: ZLinkChannelEnvelope;
37
38
  readonly codecs?: ZLinkChannelEnvelopeCodecRegistry;
@@ -47,8 +48,26 @@ export declare class ZLinkChannelDispatchPipeline {
47
48
  private readonly filters;
48
49
  private readonly unhandled;
49
50
  constructor(options: ZLinkChannelDispatchPipelineOptions);
50
- dispatchOneWay<TContext extends ZLinkMessageContext>(dispatch: ZLinkOneWayDispatch<TContext>): Promise<void>;
51
- dispatchRequest<TContext extends ZLinkMessageContext>(dispatch: ZLinkRequestDispatch<TContext>): Promise<void>;
51
+ /**
52
+ * Runs the handler in the caller's execution turn. A synchronous handler
53
+ * completes here; an asynchronous handler adds exactly one continuation
54
+ * for its terminal trace or error record.
55
+ */
56
+ dispatchOneWay<TContext extends ZLinkMessageContext>(dispatch: ZLinkOneWayDispatch<TContext>, admit?: ZLinkMeshDispatchAdmission): void | Promise<void>;
57
+ private dispatchMissingOneWay;
58
+ private completeOneWay;
59
+ private failOneWay;
60
+ /**
61
+ * Runs the handler in the caller's execution turn and writes its reply in
62
+ * the same turn when the handler completes synchronously. An asynchronous
63
+ * handler adds exactly one continuation that writes the reply.
64
+ */
65
+ dispatchRequest<TContext extends ZLinkMessageContext>(dispatch: ZLinkRequestDispatch<TContext>, admit?: ZLinkMeshDispatchAdmission): void | Promise<void>;
66
+ private dispatchMissingRequest;
67
+ private invokeInFlow;
68
+ private completeRequest;
69
+ private replyPathMissing;
70
+ private failRequest;
52
71
  dropMissingReplyPath(fields: ZLinkChannelDispatchFields): void;
53
72
  /**
54
73
  * Terminal handling for an envelope that failed structural decoding.
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ZLinkChannelDispatchPipeline = void 0;
4
4
  const framework_errors_internal_1 = require("../framework-errors-internal");
5
+ const abort_1 = require("../abort");
5
6
  const contracts_1 = require("../../contracts");
6
7
  const ZLinkDispatchOptions_1 = require("../../contracts/Dispatch/ZLinkDispatchOptions");
7
8
  const handlers_1 = require("../handlers");
@@ -17,81 +18,126 @@ class ZLinkChannelDispatchPipeline {
17
18
  this.filters = options.filters ?? [];
18
19
  this.unhandled = options.unhandled ?? DEFAULT_UNHANDLED_DISPATCH;
19
20
  }
20
- async dispatchOneWay(dispatch) {
21
+ /**
22
+ * Runs the handler in the caller's execution turn. A synchronous handler
23
+ * completes here; an asynchronous handler adds exactly one continuation
24
+ * for its terminal trace or error record.
25
+ */
26
+ dispatchOneWay(dispatch, admit) {
27
+ if (admit !== undefined) {
28
+ const pipeline = this;
29
+ const record = dispatch;
30
+ return admit(() => pipeline.dispatchOneWay(record), (error) => pipeline.failOneWay(record.fields, error));
31
+ }
21
32
  this.trace(ZLinkDispatchOptions_1.ZLinkRuntimeMessageFlowOutcome.Received, dispatch.fields);
22
33
  this.trace(ZLinkDispatchOptions_1.ZLinkRuntimeMessageFlowOutcome.Admitted, dispatch.fields);
23
- if (dispatch.handler === undefined) {
24
- const action = dispatch.fields.messageKind === ZLinkDispatchOptions_1.ZLinkDispatchMessageKind.Publish
25
- ? this.unhandled.publish
26
- : this.unhandled.send;
27
- this.report(dispatch.fields, ZLinkDispatchOptions_1.ZLinkRuntimeDispatchErrorReason.HandlerMissing, ZLinkDispatchOptions_1.ZLinkRuntimeDispatchErrorAction.Drop);
28
- this.applyOneWayUnhandled(action, dispatch.fields);
29
- return;
30
- }
34
+ if (dispatch.handler === undefined)
35
+ return this.dispatchMissingOneWay(dispatch.fields);
36
+ let invocation;
31
37
  try {
32
- const flow = (0, flow_context_1.createInboundFlow)(dispatch.fields.flowId, dispatch.fields.flowOrigin, this.options.dispatchErrors.flow.flowCreationEnabled(), undefined);
33
- const invocation = await (flow === undefined
34
- ? this.invoke(dispatch.envelope, dispatch.codecs, dispatch.handler, dispatch.context, dispatch.fields, dispatch.signal)
35
- : (0, flow_context_1.runWithFlow)(flow, () => this.invoke(dispatch.envelope, dispatch.codecs, dispatch.handler, dispatch.context, dispatch.fields, dispatch.signal)));
36
- if (invocation !== HANDLER_FILTER_REJECTED) {
37
- this.trace(ZLinkDispatchOptions_1.ZLinkRuntimeMessageFlowOutcome.Completed, dispatch.fields);
38
- }
38
+ invocation = this.invokeInFlow(dispatch, dispatch.handler);
39
39
  }
40
40
  catch (error) {
41
- this.report(dispatch.fields, this.failureReason(error), ZLinkDispatchOptions_1.ZLinkRuntimeDispatchErrorAction.Drop, error);
41
+ this.failOneWay(dispatch.fields, error);
42
+ return;
43
+ }
44
+ if (!(0, abort_1.isPromiseLike)(invocation)) {
45
+ this.completeOneWay(dispatch.fields, invocation);
46
+ return;
47
+ }
48
+ return Promise.resolve(invocation).then((value) => this.completeOneWay(dispatch.fields, value), (error) => this.failOneWay(dispatch.fields, error));
49
+ }
50
+ async dispatchMissingOneWay(fields) {
51
+ const action = fields.messageKind === ZLinkDispatchOptions_1.ZLinkDispatchMessageKind.Publish
52
+ ? this.unhandled.publish
53
+ : this.unhandled.send;
54
+ this.report(fields, ZLinkDispatchOptions_1.ZLinkRuntimeDispatchErrorReason.HandlerMissing, ZLinkDispatchOptions_1.ZLinkRuntimeDispatchErrorAction.Drop);
55
+ this.applyOneWayUnhandled(action, fields);
56
+ }
57
+ completeOneWay(fields, invocation) {
58
+ if (invocation !== HANDLER_FILTER_REJECTED) {
59
+ this.trace(ZLinkDispatchOptions_1.ZLinkRuntimeMessageFlowOutcome.Completed, fields);
42
60
  }
43
61
  }
44
- async dispatchRequest(dispatch) {
62
+ failOneWay(fields, error) {
63
+ this.report(fields, this.failureReason(error), ZLinkDispatchOptions_1.ZLinkRuntimeDispatchErrorAction.Drop, error);
64
+ }
65
+ /**
66
+ * Runs the handler in the caller's execution turn and writes its reply in
67
+ * the same turn when the handler completes synchronously. An asynchronous
68
+ * handler adds exactly one continuation that writes the reply.
69
+ */
70
+ dispatchRequest(dispatch, admit) {
71
+ if (admit !== undefined) {
72
+ const pipeline = this;
73
+ const record = dispatch;
74
+ return admit(() => pipeline.dispatchRequest(record), (error) => pipeline.failRequest(record, error));
75
+ }
45
76
  this.trace(ZLinkDispatchOptions_1.ZLinkRuntimeMessageFlowOutcome.Received, dispatch.fields);
46
77
  this.trace(ZLinkDispatchOptions_1.ZLinkRuntimeMessageFlowOutcome.Admitted, dispatch.fields);
47
- if (dispatch.handler === undefined) {
48
- const missing = (0, framework_errors_internal_1.createInternalFrameworkException)(framework_errors_internal_1.ZLinkFrameworkInternalErrorKind.HandlerNotFound, dispatch.missingHandlerMessage);
49
- if (this.unhandled.request === contracts_1.ZLinkUnhandledDispatchAction.ReplyError) {
50
- await dispatch.writeError(missing);
51
- }
52
- this.report(dispatch.fields, ZLinkDispatchOptions_1.ZLinkRuntimeDispatchErrorReason.HandlerMissing, this.unhandled.request === contracts_1.ZLinkUnhandledDispatchAction.ReplyError
53
- ? ZLinkDispatchOptions_1.ZLinkRuntimeDispatchErrorAction.ReplyError
54
- : ZLinkDispatchOptions_1.ZLinkRuntimeDispatchErrorAction.Drop);
55
- if (this.unhandled.request === contracts_1.ZLinkUnhandledDispatchAction.Throw) {
56
- throw missing;
57
- }
58
- return;
78
+ if (dispatch.handler === undefined)
79
+ return this.dispatchMissingRequest(dispatch);
80
+ let invocation;
81
+ try {
82
+ invocation = this.invokeInFlow(dispatch, dispatch.handler);
59
83
  }
60
- let reply;
84
+ catch (error) {
85
+ return this.failRequest(dispatch, error);
86
+ }
87
+ if (!(0, abort_1.isPromiseLike)(invocation))
88
+ return this.completeRequest(dispatch, invocation);
89
+ return Promise.resolve(invocation).then((value) => this.completeRequest(dispatch, value), (error) => this.failRequest(dispatch, error));
90
+ }
91
+ async dispatchMissingRequest(dispatch) {
92
+ const missing = (0, framework_errors_internal_1.createInternalFrameworkException)(framework_errors_internal_1.ZLinkFrameworkInternalErrorKind.HandlerNotFound, dispatch.missingHandlerMessage);
93
+ if (this.unhandled.request === contracts_1.ZLinkUnhandledDispatchAction.ReplyError) {
94
+ await dispatch.writeError(missing);
95
+ }
96
+ this.report(dispatch.fields, ZLinkDispatchOptions_1.ZLinkRuntimeDispatchErrorReason.HandlerMissing, this.unhandled.request === contracts_1.ZLinkUnhandledDispatchAction.ReplyError
97
+ ? ZLinkDispatchOptions_1.ZLinkRuntimeDispatchErrorAction.ReplyError
98
+ : ZLinkDispatchOptions_1.ZLinkRuntimeDispatchErrorAction.Drop);
99
+ if (this.unhandled.request === contracts_1.ZLinkUnhandledDispatchAction.Throw) {
100
+ throw missing;
101
+ }
102
+ }
103
+ invokeInFlow(dispatch, handler) {
104
+ const flow = (0, flow_context_1.createInboundFlow)(dispatch.fields.flowId, dispatch.fields.flowOrigin, this.options.dispatchErrors.flow.flowCreationEnabled(), undefined);
105
+ return flow === undefined
106
+ ? this.invoke(dispatch.envelope, dispatch.codecs, handler, dispatch.context, dispatch.fields, dispatch.signal)
107
+ : (0, flow_context_1.runWithFlow)(flow, () => this.invoke(dispatch.envelope, dispatch.codecs, handler, dispatch.context, dispatch.fields, dispatch.signal));
108
+ }
109
+ completeRequest(dispatch, invocation) {
110
+ if (invocation === HANDLER_FILTER_REJECTED) {
111
+ return this.failRequest(dispatch, (0, framework_errors_internal_1.createInternalFrameworkException)(framework_errors_internal_1.ZLinkFrameworkInternalErrorKind.RequestRejected, `A handler filter rejected '${this.options.channelName}:${dispatch.fields.packetName}'.`));
112
+ }
113
+ let written;
61
114
  try {
62
- const flow = (0, flow_context_1.createInboundFlow)(dispatch.fields.flowId, dispatch.fields.flowOrigin, this.options.dispatchErrors.flow.flowCreationEnabled(), undefined);
63
- const invocation = await (flow === undefined
64
- ? this.invoke(dispatch.envelope, dispatch.codecs, dispatch.handler, dispatch.context, dispatch.fields, dispatch.signal)
65
- : (0, flow_context_1.runWithFlow)(flow, () => this.invoke(dispatch.envelope, dispatch.codecs, dispatch.handler, dispatch.context, dispatch.fields, dispatch.signal)));
66
- if (invocation === HANDLER_FILTER_REJECTED) {
67
- throw (0, framework_errors_internal_1.createInternalFrameworkException)(framework_errors_internal_1.ZLinkFrameworkInternalErrorKind.RequestRejected, `A handler filter rejected '${this.options.channelName}:${dispatch.fields.packetName}'.`);
68
- }
69
- reply = invocation;
115
+ written = dispatch.writeReply(invocation);
70
116
  }
71
117
  catch (error) {
72
- try {
73
- await dispatch.writeError(error);
74
- }
75
- catch (replyError) {
76
- // Spec 26 §3.1: a failed reply write means the reply delivery path is
77
- // gone; `unexpected_reply` names a surplus/late reply instead.
78
- this.report(dispatch.fields, ZLinkDispatchOptions_1.ZLinkRuntimeDispatchErrorReason.ReplyPathMissing, ZLinkDispatchOptions_1.ZLinkRuntimeDispatchErrorAction.Drop, replyError);
79
- return;
80
- }
81
- this.report(dispatch.fields, this.failureReason(error), ZLinkDispatchOptions_1.ZLinkRuntimeDispatchErrorAction.ReplyError, error);
118
+ this.replyPathMissing(dispatch.fields, error);
82
119
  return;
83
120
  }
84
- try {
85
- const written = dispatch.writeReply(reply);
86
- if (written !== undefined)
87
- await written;
121
+ if (written === undefined) {
88
122
  this.trace(ZLinkDispatchOptions_1.ZLinkRuntimeMessageFlowOutcome.Replied, dispatch.fields);
123
+ return;
89
124
  }
90
- catch (error) {
91
- // Spec 26 §3.1: a failed reply write means the reply delivery path is
92
- // gone; `unexpected_reply` names a surplus/late reply instead.
93
- this.report(dispatch.fields, ZLinkDispatchOptions_1.ZLinkRuntimeDispatchErrorReason.ReplyPathMissing, ZLinkDispatchOptions_1.ZLinkRuntimeDispatchErrorAction.Drop, error);
125
+ return written.then(() => this.trace(ZLinkDispatchOptions_1.ZLinkRuntimeMessageFlowOutcome.Replied, dispatch.fields), (error) => this.replyPathMissing(dispatch.fields, error));
126
+ }
127
+ replyPathMissing(fields, error) {
128
+ // Spec 26 §3.1: a failed reply write means the reply delivery path is
129
+ // gone; `unexpected_reply` names a surplus/late reply instead.
130
+ this.report(fields, ZLinkDispatchOptions_1.ZLinkRuntimeDispatchErrorReason.ReplyPathMissing, ZLinkDispatchOptions_1.ZLinkRuntimeDispatchErrorAction.Drop, error);
131
+ }
132
+ async failRequest(dispatch, error) {
133
+ try {
134
+ await dispatch.writeError(error);
135
+ }
136
+ catch (replyError) {
137
+ this.replyPathMissing(dispatch.fields, replyError);
138
+ return;
94
139
  }
140
+ this.report(dispatch.fields, this.failureReason(error), ZLinkDispatchOptions_1.ZLinkRuntimeDispatchErrorAction.ReplyError, error);
95
141
  }
96
142
  dropMissingReplyPath(fields) {
97
143
  this.report(fields, ZLinkDispatchOptions_1.ZLinkRuntimeDispatchErrorReason.ReplyPathMissing, ZLinkDispatchOptions_1.ZLinkRuntimeDispatchErrorAction.Drop);
@@ -1,3 +1,4 @@
1
+ import type { ZLinkMeshDispatchAdmission } from '../admission';
1
2
  import type { RoutingId, ZLinkMessageContext, ZLinkHandlerFilter, ZLinkPublishMessageContext, ZLinkRouteMessageContext, ZLinkUnhandledDispatchOptions } from '../../contracts';
2
3
  import type { Message } from '../../contracts/Common/Message';
3
4
  import { type ReceiveRecord } from '../foundation/service-runtime-contracts';
@@ -54,7 +55,7 @@ export declare class ZLinkChannelRequestDispatcher {
54
55
  }, router: {
55
56
  reply(routingId: unknown, replyToken: unknown): ZLinkMultipartReplyOperation;
56
57
  }, signal?: AbortSignal, decodedHeader?: ZLinkChannelEnvelopeHeader): Promise<boolean | void>;
57
- dispatchMesh(record: ReceiveRecord, signal?: AbortSignal): Promise<void>;
58
+ dispatchMesh(record: ReceiveRecord, signal?: AbortSignal, admit?: ZLinkMeshDispatchAdmission): void | Promise<void>;
58
59
  private submitReply;
59
60
  private createMeshContext;
60
61
  }
@@ -117,7 +118,7 @@ export declare class ZLinkRoutePacketDispatcher {
117
118
  }, router: {
118
119
  reply(routingId: unknown, replyToken: unknown): ZLinkMultipartReplyOperation;
119
120
  }, signal?: AbortSignal, decodedHeader?: ZLinkChannelEnvelopeHeader, infrastructureChecked?: boolean): Promise<boolean | void>;
120
- dispatchMesh(record: ReceiveRecord, signal?: AbortSignal): Promise<void>;
121
+ dispatchMesh(record: ReceiveRecord, signal?: AbortSignal, admit?: ZLinkMeshDispatchAdmission): void | Promise<void>;
121
122
  dispatchLocalCommand(parts: readonly Message[], sourceNodeRid: RoutingId, signal?: AbortSignal): Promise<void>;
122
123
  private dispatchMeshCommand;
123
124
  private submitReply;
@@ -126,7 +126,7 @@ class ZLinkChannelRequestDispatcher {
126
126
  writeError: (error) => this.submitReply((0, channel_multipart_1.appendParts)(router.reply(received.routingId, replyToken), (0, channel_envelope_1.encodeChannelErrorReplyParts)(envelope.header, error)), signal)
127
127
  });
128
128
  }
129
- dispatchMesh(record, signal) {
129
+ dispatchMesh(record, signal, admit) {
130
130
  if (record.parts.length === 0 || record.parts[0].data().length === 0) {
131
131
  return completedChannelReply;
132
132
  }
@@ -165,7 +165,7 @@ class ZLinkChannelRequestDispatcher {
165
165
  handler: this.options.sendHandlers?.get(packetName),
166
166
  context: this.createMeshContext(envelope, record.sourceNodeRid),
167
167
  signal
168
- });
168
+ }, admit);
169
169
  }
170
170
  if (envelope.header.kind !== 1 /* ZLinkChannelMessageKind.Request */) {
171
171
  return completedChannelReply;
@@ -177,21 +177,7 @@ class ZLinkChannelRequestDispatcher {
177
177
  flowId: envelope.header.flowId,
178
178
  flowOrigin: envelope.header.flowOrigin
179
179
  };
180
- return this.pipeline.dispatchRequest({
181
- fields,
182
- envelope,
183
- codecs: this.options.codecs,
184
- handler: this.options.handlers.get(packetName),
185
- context: this.createMeshContext(envelope, record.sourceNodeRid),
186
- signal,
187
- missingHandlerMessage: `No channel request handler is registered for '${this.options.channelName}:${packetName}'.`,
188
- writeReply: (reply) => {
189
- requireMeshReplyAccepted(record.reply((0, channel_envelope_1.encodeChannelReplyParts)(envelope.header, reply, this.options.codecs)));
190
- },
191
- writeError: (error) => {
192
- requireMeshReplyAccepted(record.reply((0, channel_envelope_1.encodeChannelErrorReplyParts)(envelope.header, error)));
193
- }
194
- });
180
+ return this.pipeline.dispatchRequest(new ZLinkMeshRequestDispatch(fields, envelope, this.options.codecs, this.options.handlers.get(packetName), this.createMeshContext(envelope, record.sourceNodeRid), signal, record, 'channel', this.options.channelName), admit);
195
181
  }
196
182
  submitReply(operation, signal) {
197
183
  void signal;
@@ -220,6 +206,42 @@ class ZLinkChannelRequestDispatcher {
220
206
  }
221
207
  }
222
208
  exports.ZLinkChannelRequestDispatcher = ZLinkChannelRequestDispatcher;
209
+ /**
210
+ * One mesh request handed to the dispatch pipeline. The reply writers are
211
+ * methods over the received record instead of per-message closures, and the
212
+ * missing-handler text is built only when no handler exists.
213
+ */
214
+ class ZLinkMeshRequestDispatch {
215
+ fields;
216
+ envelope;
217
+ codecs;
218
+ handler;
219
+ context;
220
+ signal;
221
+ record;
222
+ handlerSurface;
223
+ channelName;
224
+ constructor(fields, envelope, codecs, handler, context, signal, record, handlerSurface, channelName) {
225
+ this.fields = fields;
226
+ this.envelope = envelope;
227
+ this.codecs = codecs;
228
+ this.handler = handler;
229
+ this.context = context;
230
+ this.signal = signal;
231
+ this.record = record;
232
+ this.handlerSurface = handlerSurface;
233
+ this.channelName = channelName;
234
+ }
235
+ get missingHandlerMessage() {
236
+ return `No ${this.handlerSurface} request handler is registered for '${this.channelName}:${this.fields.packetName}'.`;
237
+ }
238
+ writeReply(reply) {
239
+ requireMeshReplyAccepted(this.record.reply((0, channel_envelope_1.encodeChannelReplyParts)(this.envelope.header, reply, this.codecs)));
240
+ }
241
+ writeError(error) {
242
+ requireMeshReplyAccepted(this.record.reply((0, channel_envelope_1.encodeChannelErrorReplyParts)(this.envelope.header, error)));
243
+ }
244
+ }
223
245
  function requireMeshReplyAccepted(result) {
224
246
  if (result !== runtime_values_1.SubmitResult.Ok) {
225
247
  throw new configuration_1.ZLinkConfigurationException(`MeshNode channel reply was not accepted (submit result ${result}).`);
@@ -452,7 +474,7 @@ class ZLinkRoutePacketDispatcher {
452
474
  writeError: (error) => this.submitReply((0, channel_multipart_1.appendParts)(router.reply(received.routingId, replyToken), (0, channel_envelope_1.encodeChannelErrorReplyParts)(envelope.header, error)))
453
475
  });
454
476
  }
455
- dispatchMesh(record, signal) {
477
+ dispatchMesh(record, signal, admit) {
456
478
  if (record.parts.length === 0 || record.parts[0].data().length === 0) {
457
479
  return completedChannelReply;
458
480
  }
@@ -479,7 +501,7 @@ class ZLinkRoutePacketDispatcher {
479
501
  const sourceNodeRid = String(record.sourceNodeRid ?? '');
480
502
  const correlationId = envelope.header.correlationId ?? undefined;
481
503
  if (envelope.header.kind === 3 /* ZLinkChannelMessageKind.Command */) {
482
- return this.dispatchMeshCommand(envelope, packetName, sourceNodeRid, record.sourceNodeRid, signal);
504
+ return this.dispatchMeshCommand(envelope, packetName, sourceNodeRid, record.sourceNodeRid, signal, admit);
483
505
  }
484
506
  if (envelope.header.kind !== 1 /* ZLinkChannelMessageKind.Request */) {
485
507
  return completedChannelReply;
@@ -492,22 +514,7 @@ class ZLinkRoutePacketDispatcher {
492
514
  flowId: envelope.header.flowId,
493
515
  flowOrigin: envelope.header.flowOrigin
494
516
  };
495
- const codecs = (0, channel_framework_packets_1.codecsForFrameworkPacket)(packetName, this.codecs);
496
- return this.pipeline.dispatchRequest({
497
- fields,
498
- envelope,
499
- codecs,
500
- handler: this.requestHandlers.get(packetName),
501
- context: this.createRouteContext(envelope, record.sourceNodeRid),
502
- signal,
503
- missingHandlerMessage: `No routed request handler is registered for '${this.routerChannelId}:${packetName}'.`,
504
- writeReply: (reply) => {
505
- requireMeshReplyAccepted(record.reply((0, channel_envelope_1.encodeChannelReplyParts)(envelope.header, reply, codecs)));
506
- },
507
- writeError: (error) => {
508
- requireMeshReplyAccepted(record.reply((0, channel_envelope_1.encodeChannelErrorReplyParts)(envelope.header, error)));
509
- }
510
- });
517
+ return this.pipeline.dispatchRequest(new ZLinkMeshRequestDispatch(fields, envelope, (0, channel_framework_packets_1.codecsForFrameworkPacket)(packetName, this.codecs), this.requestHandlers.get(packetName), this.createRouteContext(envelope, record.sourceNodeRid), signal, record, 'routed', this.routerChannelId), admit);
511
518
  }
512
519
  async dispatchLocalCommand(parts, sourceNodeRid, signal) {
513
520
  if (parts.length === 0 || parts[0].data().length === 0)
@@ -535,7 +542,7 @@ class ZLinkRoutePacketDispatcher {
535
542
  }
536
543
  await this.dispatchMeshCommand(envelope, packetName, String(sourceNodeRid), sourceNodeRid, signal);
537
544
  }
538
- dispatchMeshCommand(envelope, packetName, sourceRid, sourceNodeRid, signal) {
545
+ dispatchMeshCommand(envelope, packetName, sourceRid, sourceNodeRid, signal, admit) {
539
546
  return this.pipeline.dispatchOneWay({
540
547
  fields: {
541
548
  messageKind: ZLinkDispatchOptions_1.ZLinkDispatchMessageKind.Send,
@@ -550,7 +557,7 @@ class ZLinkRoutePacketDispatcher {
550
557
  handler: this.sendHandlers.get(packetName),
551
558
  context: this.createRouteContext(envelope, sourceNodeRid),
552
559
  signal
553
- });
560
+ }, admit);
554
561
  }
555
562
  submitReply(operation) {
556
563
  if (operation.submit() === false) {
@@ -54,6 +54,7 @@ export declare function encodeChannelReplyParts(request: ZLinkChannelEnvelopeHea
54
54
  */
55
55
  export declare const ZLINK_FRAMEWORK_ORIGIN_METADATA_KEY = "zlink.origin";
56
56
  export declare const ZLINK_FRAMEWORK_ORIGIN_METADATA_VALUE = "framework";
57
+ export declare function channelErrorKindFromCode(code: string): ZLinkFrameworkErrorKind | undefined;
57
58
  export declare function channelErrorCodeName(kind: ZLinkFrameworkErrorKind): string;
58
59
  /**
59
60
  * A channel error decoded from an Error reply envelope. `origin` carries the