@zlink-systems/framework 0.29.1 → 0.30.1

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 (322) hide show
  1. package/LICENSE +150 -68
  2. package/dist/.tsbuildinfo +1 -1
  3. package/dist/contracts/Actors/ZLinkActorClient.d.ts +2 -1
  4. package/dist/contracts/Channels/Calls.d.ts +2 -1
  5. package/dist/contracts/Common/ZLinkMessageMetadata.js +11 -5
  6. package/dist/contracts/Configuration/Builders.d.ts +1 -2
  7. package/dist/contracts/Configuration/Configs.d.ts +0 -5
  8. package/dist/contracts/Configuration/RegistrationBuilders.js +6 -4
  9. package/dist/contracts/Configuration/RegistrationTypes.d.ts +1 -6
  10. package/dist/contracts/Configuration/RegistrationValidators.js +4 -4
  11. package/dist/contracts/Configuration/index.d.ts +1 -1
  12. package/dist/contracts/Handlers/Attributes.d.ts +5 -13
  13. package/dist/contracts/Handlers/Attributes.js +7 -11
  14. package/dist/contracts/Handlers/JsonContract.d.ts +2 -46
  15. package/dist/contracts/Handlers/JsonContract.js +4 -153
  16. package/dist/contracts/Spots/Contracts.d.ts +2 -1
  17. package/dist/internal.d.ts +1 -0
  18. package/dist/internal.js +3 -1
  19. package/dist/nest-integration.d.ts +1 -1
  20. package/dist/nest-integration.js +2 -1
  21. package/dist/runtime/actors/actor-client.d.ts +1 -1
  22. package/dist/runtime/actors/actor-client.js +14 -12
  23. package/dist/runtime/actors/actor-handoff.d.ts +3 -2
  24. package/dist/runtime/actors/actor-handoff.js +15 -7
  25. package/dist/runtime/actors/actor-join-relocation.d.ts +1 -0
  26. package/dist/runtime/actors/actor-local-native-join.js +9 -12
  27. package/dist/runtime/actors/actor-remote-wire.js +15 -0
  28. package/dist/runtime/actors/actor-routed-join-transport.d.ts +6 -2
  29. package/dist/runtime/actors/actor-routed-json-request.d.ts +2 -0
  30. package/dist/runtime/actors/index.d.ts +2 -1
  31. package/dist/runtime/actors/index.js +18 -6
  32. package/dist/runtime/actors/spot-actor-dispatch.js +2 -2
  33. package/dist/runtime/admission.d.ts +1 -1
  34. package/dist/runtime/admission.js +15 -5
  35. package/dist/runtime/application-jobs/application-ingress-record-owner.d.ts +9 -9
  36. package/dist/runtime/application-jobs/application-ingress-record-owner.js +45 -23
  37. package/dist/runtime/application-jobs/application-job-queue-scope.d.ts +5 -2
  38. package/dist/runtime/application-jobs/application-job-queue-scope.js +41 -21
  39. package/dist/runtime/application-jobs/contracts.d.ts +15 -2
  40. package/dist/runtime/backend/contracts/index.d.ts +27 -27
  41. package/dist/runtime/backend/mesh-completion-table.d.ts +15 -5
  42. package/dist/runtime/backend/mesh-completion-table.js +160 -50
  43. package/dist/runtime/backend/mesh-dispatch-pump.d.ts +3 -0
  44. package/dist/runtime/backend/mesh-dispatch-pump.js +53 -36
  45. package/dist/runtime/backend/node/node-backend-adapter-factory.js +6 -1
  46. package/dist/runtime/backend/node/node-backend-adapter-support.d.ts +3 -3
  47. package/dist/runtime/backend/node/node-backend-adapter-support.js +33 -31
  48. package/dist/runtime/backend/node/node-dealer-channel-client-transport.d.ts +1 -1
  49. package/dist/runtime/backend/node/node-dealer-channel-client-transport.js +5 -2
  50. package/dist/runtime/backend/node/node-mesh-backend-adapter.d.ts +1 -9
  51. package/dist/runtime/backend/node/node-mesh-backend-adapter.js +1 -1
  52. package/dist/runtime/backend/node/node-raw-binding-port.js +50 -25
  53. package/dist/runtime/backend/node/node-raw-mesh-backend.d.ts +22 -16
  54. package/dist/runtime/backend/node/node-raw-mesh-backend.js +133 -149
  55. package/dist/runtime/backend/node/node-socket-backend-adapter.js +15 -10
  56. package/dist/runtime/backend/raw-binding-port.d.ts +10 -3
  57. package/dist/runtime/backend/runtime-message.d.ts +1 -0
  58. package/dist/runtime/backend/runtime-message.js +5 -0
  59. package/dist/runtime/backend/runtime-values.d.ts +1 -0
  60. package/dist/runtime/backend/runtime-values.js +2 -1
  61. package/dist/runtime/channels/channel-clients.d.ts +1 -0
  62. package/dist/runtime/channels/channel-clients.js +58 -21
  63. package/dist/runtime/channels/channel-dispatch-pipeline.d.ts +3 -2
  64. package/dist/runtime/channels/channel-dispatch-pipeline.js +20 -11
  65. package/dist/runtime/channels/channel-dispatch-services.d.ts +1 -0
  66. package/dist/runtime/channels/channel-dispatch-services.js +45 -0
  67. package/dist/runtime/channels/channel-dispatchers.d.ts +1 -1
  68. package/dist/runtime/channels/channel-dispatchers.js +27 -26
  69. package/dist/runtime/channels/channel-envelope-inspection.d.ts +1 -2
  70. package/dist/runtime/channels/channel-envelope-inspection.js +1 -16
  71. package/dist/runtime/channels/channel-envelope.d.ts +1 -0
  72. package/dist/runtime/channels/channel-envelope.js +83 -8
  73. package/dist/runtime/channels/channel-outbound-operations.d.ts +2 -2
  74. package/dist/runtime/channels/channel-outbound-operations.js +8 -8
  75. package/dist/runtime/channels/channel-receive-loops.js +3 -3
  76. package/dist/runtime/channels/channel-runtime-lifecycle.js +2 -1
  77. package/dist/runtime/channels/channel-runtime-manager.d.ts +6 -6
  78. package/dist/runtime/channels/channel-runtime-manager.js +12 -12
  79. package/dist/runtime/channels/channel-socket-registry.d.ts +10 -3
  80. package/dist/runtime/channels/channel-socket-registry.js +59 -82
  81. package/dist/runtime/channels/channel-transports.d.ts +18 -15
  82. package/dist/runtime/channels/channel-transports.js +48 -31
  83. package/dist/runtime/channels/local-spot-route-transport.d.ts +1 -1
  84. package/dist/runtime/channels/local-spot-route-transport.js +2 -1
  85. package/dist/runtime/channels/router-socket-spot-route-transport.d.ts +2 -2
  86. package/dist/runtime/channels/router-socket-spot-route-transport.js +4 -4
  87. package/dist/runtime/channels/source-spot-router.d.ts +2 -2
  88. package/dist/runtime/channels/source-spot-router.js +4 -4
  89. package/dist/runtime/channels/spot-node-route-transport.d.ts +2 -2
  90. package/dist/runtime/channels/spot-node-route-transport.js +4 -4
  91. package/dist/runtime/channels/spot-route-bridge-transport.d.ts +2 -2
  92. package/dist/runtime/channels/spot-route-bridge-transport.js +4 -4
  93. package/dist/runtime/channels/spot-route-dispatch-strategy.d.ts +5 -4
  94. package/dist/runtime/channels/spot-route-dispatch-strategy.js +18 -18
  95. package/dist/runtime/diagnostics/message-flow.d.ts +1 -0
  96. package/dist/runtime/diagnostics/message-flow.js +3 -3
  97. package/dist/runtime/execution/serial-execution-queue.d.ts +1 -0
  98. package/dist/runtime/execution/serial-execution-queue.js +1 -0
  99. package/dist/runtime/foundation/actor-join-recovery-codec.js +2 -2
  100. package/dist/runtime/foundation/durable-service-request.d.ts +14 -0
  101. package/dist/runtime/foundation/durable-service-request.js +98 -0
  102. package/dist/runtime/foundation/operation-identity.d.ts +1 -0
  103. package/dist/runtime/foundation/operation-identity.js +5 -1
  104. package/dist/runtime/foundation/raw-service-mesh-runtime.d.ts +37 -6
  105. package/dist/runtime/foundation/raw-service-mesh-runtime.js +473 -220
  106. package/dist/runtime/foundation/service-liveness-registry.d.ts +20 -8
  107. package/dist/runtime/foundation/service-liveness-registry.js +57 -44
  108. package/dist/runtime/foundation/service-mailbox.d.ts +3 -0
  109. package/dist/runtime/foundation/service-mailbox.js +2 -1
  110. package/dist/runtime/foundation/service-relocation-object-owner.d.ts +1 -0
  111. package/dist/runtime/foundation/service-relocation-object-owner.js +1 -0
  112. package/dist/runtime/foundation/service-relocation-runtime.d.ts +2 -0
  113. package/dist/runtime/foundation/service-relocation-runtime.js +13 -1
  114. package/dist/runtime/foundation/service-runtime-contracts.d.ts +2 -0
  115. package/dist/runtime/foundation/service-stateful-runtime.d.ts +10 -9
  116. package/dist/runtime/foundation/service-stateful-runtime.js +78 -126
  117. package/dist/runtime/foundation/service-stateful-wire-codec.d.ts +5 -7
  118. package/dist/runtime/foundation/service-stateful-wire-codec.js +43 -61
  119. package/dist/runtime/foundation/service-topology-registry.d.ts +16 -4
  120. package/dist/runtime/foundation/service-topology-registry.js +69 -30
  121. package/dist/runtime/foundation/service-wire-m6a-codec.d.ts +3 -3
  122. package/dist/runtime/foundation/service-wire-m6a-codec.js +36 -38
  123. package/dist/runtime/handlers/handler-instance-scope.d.ts +8 -0
  124. package/dist/runtime/handlers/handler-instance-scope.js +54 -11
  125. package/dist/runtime/host/actor-packet-relay.js +7 -7
  126. package/dist/runtime/host/actor-runtime-options-factory.js +2 -2
  127. package/dist/runtime/host/application-job-queue.d.ts +28 -9
  128. package/dist/runtime/host/application-job-queue.js +214 -50
  129. package/dist/runtime/host/entry-actor-runtime.d.ts +1 -0
  130. package/dist/runtime/host/entry-actor-runtime.js +4 -1
  131. package/dist/runtime/host/index.d.ts +7 -1
  132. package/dist/runtime/host/index.js +154 -126
  133. package/dist/runtime/host/instance-activation-authority.d.ts +2 -1
  134. package/dist/runtime/host/instance-activation-authority.js +89 -25
  135. package/dist/runtime/host/remote-bound-session-relay.js +2 -18
  136. package/dist/runtime/host/route-mesh-runtime.js +1 -1
  137. package/dist/runtime/host/service-relocation-control.d.ts +1 -0
  138. package/dist/runtime/host/service-relocation-control.js +10 -4
  139. package/dist/runtime/host/service-relocation-host-runtime.d.ts +6 -8
  140. package/dist/runtime/host/service-relocation-host-runtime.js +215 -243
  141. package/dist/runtime/host/spot-address-transport.d.ts +1 -0
  142. package/dist/runtime/host/spot-address-transport.js +28 -14
  143. package/dist/runtime/host/spot-runtime-options-factory.js +3 -2
  144. package/dist/runtime/host/user-spot-creation-coordinator.d.ts +1 -0
  145. package/dist/runtime/host/user-spot-creation-coordinator.js +1 -0
  146. package/dist/runtime/locations/actor-location-claims.d.ts +2 -2
  147. package/dist/runtime/locations/actor-location-claims.js +34 -19
  148. package/dist/runtime/locations/domain-store-contract.d.ts +2 -2
  149. package/dist/runtime/locations/in-memory-authority-store.d.ts +4 -2
  150. package/dist/runtime/locations/in-memory-authority-store.js +80 -8
  151. package/dist/runtime/locations/in-memory-location-store.d.ts +2 -2
  152. package/dist/runtime/locations/in-memory-location-store.js +19 -3
  153. package/dist/runtime/locations/internal-location-contracts.d.ts +3 -0
  154. package/dist/runtime/locations/lifecycle.d.ts +1 -2
  155. package/dist/runtime/locations/lifecycle.js +2 -5
  156. package/dist/runtime/locations/location-store-repository.d.ts +3 -2
  157. package/dist/runtime/locations/location-store-repository.js +165 -22
  158. package/dist/runtime/locations/resolvers.d.ts +2 -1
  159. package/dist/runtime/locations/resolvers.js +10 -1
  160. package/dist/runtime/locations/runtime.d.ts +1 -1
  161. package/dist/runtime/locations/runtime.js +24 -23
  162. package/dist/runtime/messaging/framework-json-v1.d.ts +4 -6
  163. package/dist/runtime/messaging/framework-json-v1.js +38 -294
  164. package/dist/runtime/messaging/packet-name.d.ts +1 -1
  165. package/dist/runtime/messaging/packet-name.js +8 -24
  166. package/dist/runtime/messaging/request-result.d.ts +2 -0
  167. package/dist/runtime/messaging/request-result.js +54 -0
  168. package/dist/runtime/messaging/submission-result.d.ts +2 -1
  169. package/dist/runtime/messaging/submission-result.js +7 -4
  170. package/dist/runtime/protocol/service_wire_codec.generated.d.ts +15 -0
  171. package/dist/runtime/protocol/service_wire_codec.generated.js +144 -0
  172. package/dist/runtime/protocol/service_wire_pilot_codec.generated.d.ts +9 -0
  173. package/dist/runtime/protocol/service_wire_pilot_codec.generated.js +14 -1
  174. package/dist/runtime/spots/formal-remote-actor-admission-registry.d.ts +9 -2
  175. package/dist/runtime/spots/formal-remote-actor-admission-registry.js +33 -19
  176. package/dist/runtime/spots/index.d.ts +7 -3
  177. package/dist/runtime/spots/index.js +23 -16
  178. package/dist/runtime/spots/spot-activation.d.ts +3 -1
  179. package/dist/runtime/spots/spot-activation.js +21 -12
  180. package/dist/runtime/spots/spot-actor-admission-coordinator.d.ts +2 -1
  181. package/dist/runtime/spots/spot-actor-admission-coordinator.js +11 -10
  182. package/dist/runtime/spots/spot-actor-packet-dispatch.d.ts +4 -1
  183. package/dist/runtime/spots/spot-actor-packet-dispatch.js +7 -5
  184. package/dist/runtime/spots/spot-actor-packet-drain.js +2 -0
  185. package/dist/runtime/spots/spot-actor-packet-relay-dispatch.js +1 -0
  186. package/dist/runtime/spots/spot-entry-activation.js +9 -3
  187. package/dist/runtime/spots/spot-handler-registry.d.ts +3 -1
  188. package/dist/runtime/spots/spot-handler-registry.js +18 -8
  189. package/dist/runtime/spots/spot-node-autoconnect.js +4 -3
  190. package/dist/runtime/spots/spot-node-runtime-manager.d.ts +2 -1
  191. package/dist/runtime/spots/spot-node-runtime-manager.js +4 -11
  192. package/dist/runtime/spots/spot-outbound.d.ts +3 -0
  193. package/dist/runtime/spots/spot-outbound.js +24 -15
  194. package/dist/runtime/spots/spot-routed-spot-packet-dispatch.d.ts +1 -0
  195. package/dist/runtime/spots/spot-routed-spot-packet-dispatch.js +1 -1
  196. package/dist/runtime/spots/spot-routing-internal.d.ts +6 -0
  197. package/dist/runtime/spots/spot-runtime-ports.d.ts +3 -1
  198. package/dist/runtime/spots/spot-subscription-dispatch.js +0 -3
  199. package/dist/runtime/spots/spot-timer.js +1 -0
  200. package/dist/runtime/streams/stream-session-runtime.d.ts +1 -1
  201. package/dist/runtime/streams/stream-session-runtime.js +14 -28
  202. package/package.json +3 -3
  203. package/src/contracts/Actors/ZLinkActorClient.ts +2 -1
  204. package/src/contracts/Channels/Calls.ts +2 -1
  205. package/src/contracts/Common/ZLinkMessageMetadata.ts +13 -8
  206. package/src/contracts/Configuration/Builders.ts +1 -2
  207. package/src/contracts/Configuration/Configs.ts +0 -6
  208. package/src/contracts/Configuration/RegistrationBuilders.ts +8 -12
  209. package/src/contracts/Configuration/RegistrationTypes.ts +1 -6
  210. package/src/contracts/Configuration/RegistrationValidators.ts +9 -10
  211. package/src/contracts/Configuration/index.ts +1 -6
  212. package/src/contracts/Handlers/Attributes.ts +14 -21
  213. package/src/contracts/Handlers/JsonContract.ts +8 -216
  214. package/src/contracts/Spots/Contracts.ts +2 -1
  215. package/src/internal.ts +1 -0
  216. package/src/nest-integration.ts +1 -0
  217. package/src/runtime/actors/actor-client.ts +40 -16
  218. package/src/runtime/actors/actor-handoff.ts +22 -8
  219. package/src/runtime/actors/actor-join-relocation.ts +1 -0
  220. package/src/runtime/actors/actor-local-native-join.ts +17 -26
  221. package/src/runtime/actors/actor-remote-wire.ts +17 -0
  222. package/src/runtime/actors/actor-routed-join-transport.ts +14 -4
  223. package/src/runtime/actors/actor-routed-json-request.ts +10 -2
  224. package/src/runtime/actors/index.ts +19 -5
  225. package/src/runtime/actors/spot-actor-dispatch.ts +4 -2
  226. package/src/runtime/admission.ts +18 -5
  227. package/src/runtime/application-jobs/application-ingress-record-owner.ts +53 -27
  228. package/src/runtime/application-jobs/application-job-queue-scope.ts +56 -22
  229. package/src/runtime/application-jobs/contracts.ts +28 -2
  230. package/src/runtime/backend/contracts/index.ts +63 -32
  231. package/src/runtime/backend/mesh-completion-table.ts +175 -59
  232. package/src/runtime/backend/mesh-dispatch-pump.ts +59 -32
  233. package/src/runtime/backend/node/node-backend-adapter-factory.ts +12 -5
  234. package/src/runtime/backend/node/node-backend-adapter-support.ts +42 -31
  235. package/src/runtime/backend/node/node-dealer-channel-client-transport.ts +12 -2
  236. package/src/runtime/backend/node/node-mesh-backend-adapter.ts +3 -10
  237. package/src/runtime/backend/node/node-raw-binding-port.ts +73 -37
  238. package/src/runtime/backend/node/node-raw-mesh-backend.ts +209 -176
  239. package/src/runtime/backend/node/node-socket-backend-adapter.ts +32 -13
  240. package/src/runtime/backend/raw-binding-port.ts +18 -3
  241. package/src/runtime/backend/runtime-message.ts +6 -0
  242. package/src/runtime/backend/runtime-values.ts +1 -0
  243. package/src/runtime/channels/channel-clients.ts +90 -41
  244. package/src/runtime/channels/channel-dispatch-pipeline.ts +69 -34
  245. package/src/runtime/channels/channel-dispatch-services.ts +69 -1
  246. package/src/runtime/channels/channel-dispatchers.ts +29 -27
  247. package/src/runtime/channels/channel-envelope-inspection.ts +2 -16
  248. package/src/runtime/channels/channel-envelope.ts +133 -8
  249. package/src/runtime/channels/channel-outbound-operations.ts +22 -8
  250. package/src/runtime/channels/channel-receive-loops.ts +3 -3
  251. package/src/runtime/channels/channel-runtime-lifecycle.ts +7 -1
  252. package/src/runtime/channels/channel-runtime-manager.ts +29 -12
  253. package/src/runtime/channels/channel-socket-registry.ts +84 -130
  254. package/src/runtime/channels/channel-transports.ts +128 -60
  255. package/src/runtime/channels/local-spot-route-transport.ts +3 -1
  256. package/src/runtime/channels/router-socket-spot-route-transport.ts +13 -4
  257. package/src/runtime/channels/source-spot-router.ts +8 -4
  258. package/src/runtime/channels/spot-node-route-transport.ts +8 -4
  259. package/src/runtime/channels/spot-route-bridge-transport.ts +6 -4
  260. package/src/runtime/channels/spot-route-dispatch-strategy.ts +47 -18
  261. package/src/runtime/diagnostics/message-flow.ts +1 -1
  262. package/src/runtime/execution/serial-execution-queue.ts +2 -0
  263. package/src/runtime/foundation/actor-join-recovery-codec.ts +2 -2
  264. package/src/runtime/foundation/durable-service-request.ts +137 -0
  265. package/src/runtime/foundation/operation-identity.ts +5 -1
  266. package/src/runtime/foundation/raw-service-mesh-runtime.ts +642 -253
  267. package/src/runtime/foundation/service-liveness-registry.ts +68 -59
  268. package/src/runtime/foundation/service-mailbox.ts +7 -1
  269. package/src/runtime/foundation/service-relocation-object-owner.ts +2 -0
  270. package/src/runtime/foundation/service-relocation-runtime.ts +18 -1
  271. package/src/runtime/foundation/service-runtime-contracts.ts +7 -1
  272. package/src/runtime/foundation/service-stateful-runtime.ts +128 -160
  273. package/src/runtime/foundation/service-stateful-wire-codec.ts +55 -84
  274. package/src/runtime/foundation/service-topology-registry.ts +103 -42
  275. package/src/runtime/foundation/service-wire-m6a-codec.ts +57 -38
  276. package/src/runtime/handlers/handler-instance-scope.ts +67 -16
  277. package/src/runtime/host/actor-packet-relay.ts +7 -0
  278. package/src/runtime/host/actor-runtime-options-factory.ts +14 -2
  279. package/src/runtime/host/application-job-queue.ts +249 -48
  280. package/src/runtime/host/entry-actor-runtime.ts +5 -0
  281. package/src/runtime/host/index.ts +224 -160
  282. package/src/runtime/host/instance-activation-authority.ts +132 -27
  283. package/src/runtime/host/remote-bound-session-relay.ts +2 -23
  284. package/src/runtime/host/route-mesh-runtime.ts +1 -1
  285. package/src/runtime/host/service-relocation-control.ts +11 -5
  286. package/src/runtime/host/service-relocation-host-runtime.ts +317 -291
  287. package/src/runtime/host/spot-address-transport.ts +49 -24
  288. package/src/runtime/host/spot-runtime-options-factory.ts +4 -0
  289. package/src/runtime/host/user-spot-creation-coordinator.ts +8 -0
  290. package/src/runtime/locations/actor-location-claims.ts +52 -30
  291. package/src/runtime/locations/domain-store-contract.ts +6 -2
  292. package/src/runtime/locations/in-memory-authority-store.ts +113 -9
  293. package/src/runtime/locations/in-memory-location-store.ts +25 -3
  294. package/src/runtime/locations/internal-location-contracts.ts +4 -0
  295. package/src/runtime/locations/lifecycle.ts +8 -26
  296. package/src/runtime/locations/location-store-repository.ts +220 -15
  297. package/src/runtime/locations/resolvers.ts +25 -2
  298. package/src/runtime/locations/runtime.ts +28 -24
  299. package/src/runtime/messaging/framework-json-v1.ts +5 -325
  300. package/src/runtime/messaging/packet-name.ts +5 -25
  301. package/src/runtime/messaging/request-result.ts +58 -0
  302. package/src/runtime/messaging/submission-result.ts +7 -3
  303. package/src/runtime/protocol/service_wire_codec.generated.ts +131 -1
  304. package/src/runtime/protocol/service_wire_pilot_codec.generated.ts +4 -4
  305. package/src/runtime/spots/formal-remote-actor-admission-registry.ts +45 -23
  306. package/src/runtime/spots/index.ts +30 -2
  307. package/src/runtime/spots/spot-activation.ts +33 -10
  308. package/src/runtime/spots/spot-actor-admission-coordinator.ts +13 -0
  309. package/src/runtime/spots/spot-actor-packet-dispatch.ts +10 -0
  310. package/src/runtime/spots/spot-actor-packet-drain.ts +2 -0
  311. package/src/runtime/spots/spot-actor-packet-relay-dispatch.ts +1 -0
  312. package/src/runtime/spots/spot-entry-activation.ts +12 -2
  313. package/src/runtime/spots/spot-handler-registry.ts +41 -8
  314. package/src/runtime/spots/spot-node-autoconnect.ts +6 -2
  315. package/src/runtime/spots/spot-node-runtime-manager.ts +7 -12
  316. package/src/runtime/spots/spot-outbound.ts +36 -16
  317. package/src/runtime/spots/spot-routed-spot-packet-dispatch.ts +2 -1
  318. package/src/runtime/spots/spot-routing-internal.ts +14 -0
  319. package/src/runtime/spots/spot-runtime-ports.ts +3 -0
  320. package/src/runtime/spots/spot-subscription-dispatch.ts +0 -3
  321. package/src/runtime/spots/spot-timer.ts +5 -1
  322. package/src/runtime/streams/stream-session-runtime.ts +13 -30
@@ -35,16 +35,19 @@ class ServiceTopologyRegistry {
35
35
  }
36
36
  this.local = cloneDescriptor(descriptor);
37
37
  for (const [nodeRoutingId, remote] of this.notRequiredByRid) {
38
- if (!(0, route_mesh_connection_policy_1.descriptorConnectionNotRequired)(this.local, remote)) {
38
+ if (!(0, route_mesh_connection_policy_1.descriptorConnectionNotRequired)(this.local, remote.descriptor)) {
39
39
  this.notRequiredByRid.delete(nodeRoutingId);
40
40
  }
41
41
  }
42
42
  this.rebuildSelections();
43
43
  }
44
- admit(descriptor, connectionId, expected) {
44
+ admit(descriptor, connectionId, expected, admitLiveness, command = service_wire_constants_generated_1.ServiceWireCommand.hello, descriptorBytes) {
45
45
  try {
46
46
  validateDescriptor(descriptor);
47
- requireText(connectionId, 'connectionId');
47
+ if (typeof connectionId === 'string')
48
+ requireText(connectionId, 'connectionId');
49
+ else if (connectionId === 0n)
50
+ throw new TypeError('connectionId must be nonzero.');
48
51
  }
49
52
  catch (error) {
50
53
  return 'invalidDescriptor';
@@ -60,33 +63,48 @@ class ServiceTopologyRegistry {
60
63
  descriptor.lifecycleGeneration !== expected.lifecycleGeneration)) {
61
64
  return 'invalidDescriptor';
62
65
  }
66
+ const current = this.peersByRid.get(descriptor.nodeRoutingId);
67
+ const previous = current ?? this.notRequiredByRid.get(descriptor.nodeRoutingId);
68
+ const receivedAdmit = command === service_wire_constants_generated_1.ServiceWireCommand.admit ||
69
+ (previous?.connectionId === connectionId && previous.remoteAdmitReceived === true);
70
+ if (previous !== undefined &&
71
+ previous.descriptor.lifecycleGeneration === descriptor.lifecycleGeneration) {
72
+ const existing = previous.descriptor;
73
+ if (descriptor.descriptorRevision < existing.descriptorRevision ||
74
+ (descriptor.descriptorRevision === existing.descriptorRevision &&
75
+ !(previous.descriptorBytes !== undefined && descriptorBytes !== undefined
76
+ ? Buffer.compare(previous.descriptorBytes, descriptorBytes) === 0
77
+ : sameServiceNodeDescriptor(existing, descriptor))) ||
78
+ (descriptor.descriptorRevision > existing.descriptorRevision &&
79
+ command !== service_wire_constants_generated_1.ServiceWireCommand.update))
80
+ return 'staleDescriptor';
81
+ if (descriptor.descriptorRevision > existing.descriptorRevision &&
82
+ !sameImmutableDescriptor(existing, descriptor))
83
+ return 'invalidDescriptor';
84
+ }
85
+ else if (command === service_wire_constants_generated_1.ServiceWireCommand.update) {
86
+ return 'staleDescriptor';
87
+ }
88
+ const admission = {
89
+ descriptor: cloneDescriptor(descriptor),
90
+ ...(descriptorBytes === undefined ? {} : { descriptorBytes: Buffer.from(descriptorBytes) }),
91
+ connectionId,
92
+ remoteAdmitReceived: receivedAdmit
93
+ };
63
94
  if ((0, route_mesh_connection_policy_1.descriptorConnectionNotRequired)(this.local, descriptor)) {
64
95
  this.peersByRid.delete(descriptor.nodeRoutingId);
65
96
  this.remember(descriptor);
66
- this.notRequiredByRid.set(descriptor.nodeRoutingId, cloneDescriptor(descriptor));
97
+ this.notRequiredByRid.set(descriptor.nodeRoutingId, admission);
67
98
  this.rebuildSelections();
68
99
  return 'notRequired';
69
100
  }
70
101
  this.notRequiredByRid.delete(descriptor.nodeRoutingId);
71
- const current = this.peersByRid.get(descriptor.nodeRoutingId);
72
- if (current !== undefined &&
73
- current.descriptor.lifecycleGeneration === descriptor.lifecycleGeneration &&
74
- descriptor.descriptorRevision > current.descriptor.descriptorRevision &&
75
- !sameImmutableDescriptor(current.descriptor, descriptor)) {
76
- return 'invalidDescriptor';
77
- }
78
- if (current !== undefined &&
79
- current.descriptor.lifecycleGeneration === descriptor.lifecycleGeneration &&
80
- (current.descriptor.descriptorRevision > descriptor.descriptorRevision ||
81
- (current.descriptor.descriptorRevision === descriptor.descriptorRevision &&
82
- !sameServiceNodeDescriptor(current.descriptor, descriptor)))) {
83
- return 'staleDescriptor';
84
- }
85
102
  // Core selects the one route per RID (Core ROUTER §10.1); an admission on
86
103
  // that route replaces the admission of a route it replaced.
87
104
  this.peersByRid.set(descriptor.nodeRoutingId, {
88
- descriptor: cloneDescriptor(descriptor),
89
- connectionId
105
+ ...admission,
106
+ connectionId,
107
+ liveness: admitLiveness?.() ?? current?.liveness
90
108
  });
91
109
  this.remember(descriptor);
92
110
  this.rebuildSelections();
@@ -101,9 +119,15 @@ class ServiceTopologyRegistry {
101
119
  return true;
102
120
  }
103
121
  peer(nodeRoutingId) {
104
- const peer = this.peersByRid.get(nodeRoutingId);
122
+ const peer = this.admittedPeer(nodeRoutingId);
105
123
  return peer === undefined ? undefined : clonePeer(peer);
106
124
  }
125
+ routeAdmission(nodeRoutingId) {
126
+ return this.peersByRid.get(nodeRoutingId) ?? this.notRequiredByRid.get(nodeRoutingId);
127
+ }
128
+ admittedPeer(nodeRoutingId) {
129
+ return this.peersByRid.get(nodeRoutingId);
130
+ }
107
131
  peers() {
108
132
  return this.peersCore();
109
133
  }
@@ -114,8 +138,8 @@ class ServiceTopologyRegistry {
114
138
  }
115
139
  notRequiredPeers() {
116
140
  return [...this.notRequiredByRid.values()]
117
- .sort((left, right) => compareOrdinal(left.nodeRoutingId, right.nodeRoutingId))
118
- .map(cloneDescriptor);
141
+ .sort((left, right) => compareOrdinal(left.descriptor.nodeRoutingId, right.descriptor.nodeRoutingId))
142
+ .map((peer) => cloneDescriptor(peer.descriptor));
119
143
  }
120
144
  replaceDiscoveredNotRequired(descriptors) {
121
145
  const next = new Map();
@@ -124,13 +148,16 @@ class ServiceTopologyRegistry {
124
148
  if (descriptor.meshName === this.local.meshName &&
125
149
  descriptor.nodeRoutingId !== this.local.nodeRoutingId &&
126
150
  (0, route_mesh_connection_policy_1.descriptorConnectionNotRequired)(this.local, descriptor)) {
127
- next.set(descriptor.nodeRoutingId, cloneDescriptor(descriptor));
151
+ next.set(descriptor.nodeRoutingId, {
152
+ ...this.notRequiredByRid.get(descriptor.nodeRoutingId),
153
+ descriptor: cloneDescriptor(descriptor)
154
+ });
128
155
  }
129
156
  }
130
157
  this.notRequiredByRid.clear();
131
- for (const [nodeRoutingId, descriptor] of next) {
132
- this.notRequiredByRid.set(nodeRoutingId, descriptor);
133
- this.remember(descriptor);
158
+ for (const [nodeRoutingId, admission] of next) {
159
+ this.notRequiredByRid.set(nodeRoutingId, admission);
160
+ this.remember(admission.descriptor);
134
161
  }
135
162
  this.rebuildSelections();
136
163
  }
@@ -139,10 +166,21 @@ class ServiceTopologyRegistry {
139
166
  this.rebuildSelections();
140
167
  }
141
168
  knownDescriptor(nodeRoutingId) {
142
- const admitted = this.peersByRid.get(nodeRoutingId)?.descriptor;
143
- const descriptor = admitted ?? this.notRequiredByRid.get(nodeRoutingId) ?? this.knownByRid.get(nodeRoutingId);
169
+ const descriptor = this.knownPeerDescriptor(nodeRoutingId);
144
170
  return descriptor === undefined ? undefined : cloneDescriptor(descriptor);
145
171
  }
172
+ isObjectClientNodeDirectTarget(nodeRoutingId) {
173
+ const descriptor = nodeRoutingId === this.local.nodeRoutingId
174
+ ? this.local
175
+ : this.knownPeerDescriptor(nodeRoutingId);
176
+ return descriptor?.objectRole === 'client';
177
+ }
178
+ knownPeerDescriptor(nodeRoutingId) {
179
+ const admitted = this.peersByRid.get(nodeRoutingId)?.descriptor;
180
+ return (admitted ??
181
+ this.notRequiredByRid.get(nodeRoutingId)?.descriptor ??
182
+ this.knownByRid.get(nodeRoutingId));
183
+ }
146
184
  hasKnownChannelTarget(channelName) {
147
185
  requireText(channelName, 'channelName');
148
186
  return [...this.knownByRid.values()].some((descriptor) => (descriptor.state === 'serving' ||
@@ -329,7 +367,8 @@ function cloneDescriptor(descriptor) {
329
367
  function clonePeer(peer) {
330
368
  return {
331
369
  descriptor: cloneDescriptor(peer.descriptor),
332
- connectionId: peer.connectionId
370
+ connectionId: peer.connectionId,
371
+ liveness: peer.liveness
333
372
  };
334
373
  }
335
374
  function sameServiceNodeDescriptor(left, right) {
@@ -66,11 +66,11 @@ export declare class ServiceWireProtocolError extends Error {
66
66
  }
67
67
  export declare function encodeNodeSendHeader(): Buffer;
68
68
  export declare function encodeNodeRequestHeader(correlation: bigint): Buffer;
69
- export declare function decodeNodeRequestHeader(frame: Uint8Array): bigint;
69
+ export declare function decodeNodeRequestHeader(frame: Uint8Array, header?: ServiceWireHeader): bigint;
70
70
  export declare function encodeChannelSendHeader(channelName: string): Buffer;
71
- export declare function decodeChannelSendHeader(frame: Uint8Array): string;
71
+ export declare function decodeChannelSendHeader(frame: Uint8Array, header?: ServiceWireHeader): string;
72
72
  export declare function encodeChannelRequestHeader(correlation: bigint, channelName: string): Buffer;
73
- export declare function decodeChannelRequestHeader(frame: Uint8Array): {
73
+ export declare function decodeChannelRequestHeader(frame: Uint8Array, header?: ServiceWireHeader): {
74
74
  readonly correlation: bigint;
75
75
  readonly channelName: string;
76
76
  };
@@ -54,8 +54,7 @@ function encodeNodeSendHeader() {
54
54
  function encodeNodeRequestHeader(correlation) {
55
55
  return withU64(prefix(exports.M6aServiceWireCommand.nodeRequest), correlation, 'correlation');
56
56
  }
57
- function decodeNodeRequestHeader(frame) {
58
- const header = decodeHeader(frame);
57
+ function decodeNodeRequestHeader(frame, header = decodeHeader(frame)) {
59
58
  if (header.command !== exports.M6aServiceWireCommand.nodeRequest ||
60
59
  header.flags !== 0 ||
61
60
  frame.byteLength !== 13) {
@@ -66,8 +65,7 @@ function decodeNodeRequestHeader(frame) {
66
65
  function encodeChannelSendHeader(channelName) {
67
66
  return concat(prefix(exports.M6aServiceWireCommand.channelSend), encodeText8(channelName, 'channelName'));
68
67
  }
69
- function decodeChannelSendHeader(frame) {
70
- const header = decodeHeader(frame);
68
+ function decodeChannelSendHeader(frame, header = decodeHeader(frame)) {
71
69
  if (header.command !== exports.M6aServiceWireCommand.channelSend || header.flags !== 0) {
72
70
  fail('Invalid channelSend header.');
73
71
  }
@@ -79,8 +77,7 @@ function decodeChannelSendHeader(frame) {
79
77
  function encodeChannelRequestHeader(correlation, channelName) {
80
78
  return concat(withU64(prefix(exports.M6aServiceWireCommand.channelRequest), correlation, 'correlation'), encodeText8(channelName, 'channelName'));
81
79
  }
82
- function decodeChannelRequestHeader(frame) {
83
- const header = decodeHeader(frame);
80
+ function decodeChannelRequestHeader(frame, header = decodeHeader(frame)) {
84
81
  if (header.command !== exports.M6aServiceWireCommand.channelRequest || header.flags !== 0) {
85
82
  fail('Invalid channelRequest header.');
86
83
  }
@@ -127,22 +124,8 @@ function decodeReplyHeader(frame) {
127
124
  return result;
128
125
  }
129
126
  function encodeApplicationPayload(payload) {
130
- const packetName = encodeText8(payload.packetName, 'packetName');
131
- const contentType = encodeText8(payload.contentType, 'contentType');
132
- if (payload.payload.byteLength > MAX_U32)
133
- fail('Application payload exceeds u32.');
134
- const bodyLength = packetName.byteLength + contentType.byteLength + 4 + payload.payload.byteLength;
135
- if (bodyLength > MAX_U32)
136
- fail('Application payload body exceeds u32.');
137
- const result = Buffer.alloc(5 + bodyLength);
138
- result[0] = exports.APPLICATION_PAYLOAD_VERSION;
139
- result.writeUInt32BE(bodyLength, 1);
140
- let offset = 5;
141
- offset += packetName.copy(result, offset);
142
- offset += contentType.copy(result, offset);
143
- result.writeUInt32BE(payload.payload.byteLength, offset);
144
- offset += 4;
145
- Buffer.from(payload.payload.buffer, payload.payload.byteOffset, payload.payload.byteLength).copy(result, offset);
127
+ const result = allocateApplicationPayload(payload.packetName, payload.contentType, payload.payload.byteLength);
128
+ result.set(payload.payload, result.byteLength - payload.payload.byteLength);
146
129
  return result;
147
130
  }
148
131
  /**
@@ -155,8 +138,6 @@ function encodeMultipartApplicationPayload(parts, packetName, contentType) {
155
138
  fail('Multipart payload must contain at least one part.');
156
139
  if (parts.length > MAX_U32)
157
140
  fail('Multipart part count exceeds u32.');
158
- const packetNameBytes = encodeText8(packetName, 'packetName');
159
- const contentTypeBytes = encodeText8(contentType, 'contentType');
160
141
  let multipartLength = 4;
161
142
  for (const part of parts) {
162
143
  if (part.byteLength > MAX_U32)
@@ -165,27 +146,44 @@ function encodeMultipartApplicationPayload(parts, packetName, contentType) {
165
146
  if (multipartLength > MAX_U32)
166
147
  fail('Multipart payload exceeds u32.');
167
148
  }
168
- const bodyLength = packetNameBytes.byteLength + contentTypeBytes.byteLength + 4 + multipartLength;
169
- if (bodyLength > MAX_U32)
170
- fail('Application payload body exceeds u32.');
171
- const result = Buffer.alloc(5 + bodyLength);
172
- result[0] = exports.APPLICATION_PAYLOAD_VERSION;
173
- result.writeUInt32BE(bodyLength, 1);
174
- let offset = 5;
175
- offset += packetNameBytes.copy(result, offset);
176
- offset += contentTypeBytes.copy(result, offset);
177
- result.writeUInt32BE(multipartLength, offset);
178
- offset += 4;
149
+ const result = allocateApplicationPayload(packetName, contentType, multipartLength);
150
+ let offset = result.byteLength - multipartLength;
179
151
  result.writeUInt32BE(parts.length, offset);
180
152
  offset += 4;
181
153
  for (const part of parts) {
182
154
  result.writeUInt32BE(part.byteLength, offset);
183
155
  offset += 4;
184
- Buffer.from(part.buffer, part.byteOffset, part.byteLength).copy(result, offset);
156
+ result.set(part, offset);
185
157
  offset += part.byteLength;
186
158
  }
187
159
  return result;
188
160
  }
161
+ function allocateApplicationPayload(packetName, contentType, payloadLength) {
162
+ const packetNameBytes = (0, service_wire_binary_primitives_1.encodeCanonicalServiceWireText)(packetName, 'packetName', service_wire_binary_primitives_1.SERVICE_WIRE_TEXT8_MAX_BYTES, fail);
163
+ const contentTypeBytes = (0, service_wire_binary_primitives_1.encodeCanonicalServiceWireText)(contentType, 'contentType', service_wire_binary_primitives_1.SERVICE_WIRE_TEXT8_MAX_BYTES, fail);
164
+ if (payloadLength > MAX_U32)
165
+ fail('Application payload exceeds u32.');
166
+ const frameLength = exports.APPLICATION_PAYLOAD_MINIMUM_FIELD_BYTES +
167
+ packetNameBytes.byteLength +
168
+ contentTypeBytes.byteLength +
169
+ payloadLength;
170
+ const prefixLength = 1 + APPLICATION_PAYLOAD_LENGTH_FIELD_BYTES;
171
+ const bodyLength = frameLength - prefixLength;
172
+ if (bodyLength > MAX_U32)
173
+ fail('Application payload body exceeds u32.');
174
+ const result = Buffer.alloc(frameLength);
175
+ result[0] = exports.APPLICATION_PAYLOAD_VERSION;
176
+ result.writeUInt32BE(bodyLength, 1);
177
+ let offset = prefixLength;
178
+ result[offset++] = packetNameBytes.byteLength;
179
+ result.set(packetNameBytes, offset);
180
+ offset += packetNameBytes.byteLength;
181
+ result[offset++] = contentTypeBytes.byteLength;
182
+ result.set(contentTypeBytes, offset);
183
+ offset += contentTypeBytes.byteLength;
184
+ result.writeUInt32BE(payloadLength, offset);
185
+ return result;
186
+ }
189
187
  function decodeApplicationPayload(frame) {
190
188
  const decoded = decodeApplicationPayloadView(frame);
191
189
  return {
@@ -419,7 +417,7 @@ function encodeU64(value) {
419
417
  return result;
420
418
  }
421
419
  function encodeText8(value, field) {
422
- const bytes = (0, service_wire_binary_primitives_1.encodeCanonicalServiceWireText)(value, field, 0xff, fail);
420
+ const bytes = (0, service_wire_binary_primitives_1.encodeCanonicalServiceWireText)(value, field, service_wire_binary_primitives_1.SERVICE_WIRE_TEXT8_MAX_BYTES, fail);
423
421
  return concat(Buffer.of(bytes.byteLength), bytes);
424
422
  }
425
423
  function encodeText16(value, field) {
@@ -430,7 +428,7 @@ function tlv(id, value) {
430
428
  return concat(Buffer.of(id), encodeU32(value.byteLength), value);
431
429
  }
432
430
  function concat(...parts) {
433
- return Buffer.concat(parts.map((part) => Buffer.from(part)));
431
+ return Buffer.concat(parts);
434
432
  }
435
433
  function readNonZeroU64(bytes, offset, field) {
436
434
  const result = bytes.readBigUInt64BE(offset);
@@ -5,9 +5,17 @@ export interface ZLinkHandlerInstanceScope {
5
5
  resolve<T>(type: Type<T>): Promise<T>;
6
6
  dispose(): Promise<void>;
7
7
  }
8
+ interface ZLinkHandlerInstanceScopeFactory {
9
+ prepare?(type: Type): void | (() => unknown);
10
+ create(context?: ZLinkMessageContext): ZLinkHandlerInstanceScope;
11
+ }
12
+ export declare function registerHandlerInstanceScopeFactory(providerResolver: ZLinkProviderResolver, factory: ZLinkHandlerInstanceScopeFactory): void;
13
+ export declare function prepareHandlerInstance<T>(providerResolver: ZLinkProviderResolver | undefined, type: Type<T>): (() => T) | undefined;
8
14
  export declare function runInHandlerInstanceScope<T>(providerResolver: ZLinkProviderResolver | undefined, context: ZLinkMessageContext | undefined, callback: (scope: ZLinkHandlerInstanceScope) => Promise<T>): Promise<T>;
9
15
  export declare function resolveLifecycleHandler<T>(owner: object, type: Type<T>, providerResolver?: ZLinkProviderResolver): Promise<T>;
10
16
  export declare function runWithLifecycleHandler<THandler, TResult>(owner: object, type: Type<THandler>, providerResolver: ZLinkProviderResolver | undefined, callback: (handler: THandler) => Promise<TResult>): Promise<TResult>;
11
17
  export declare function disposeLifecycleHandlers(owner: object, detachedTaskRunner: ZLinkDetachedTaskRunner): Promise<void>;
12
18
  export declare function disposeOwnedInstance(instance: unknown): Promise<void>;
19
+ export declare function handlerInstanceCleanup(instance: unknown): (() => unknown) | undefined;
13
20
  export declare function disposeOwnedInstances(instances: readonly unknown[]): Promise<void>;
21
+ export {};
@@ -1,10 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.registerHandlerInstanceScopeFactory = registerHandlerInstanceScopeFactory;
4
+ exports.prepareHandlerInstance = prepareHandlerInstance;
3
5
  exports.runInHandlerInstanceScope = runInHandlerInstanceScope;
4
6
  exports.resolveLifecycleHandler = resolveLifecycleHandler;
5
7
  exports.runWithLifecycleHandler = runWithLifecycleHandler;
6
8
  exports.disposeLifecycleHandlers = disposeLifecycleHandlers;
7
9
  exports.disposeOwnedInstance = disposeOwnedInstance;
10
+ exports.handlerInstanceCleanup = handlerInstanceCleanup;
8
11
  exports.disposeOwnedInstances = disposeOwnedInstances;
9
12
  const node_async_hooks_1 = require("node:async_hooks");
10
13
  const HANDLER_SCOPE_FACTORY = Symbol.for('@zlink-systems/framework.handler-instance-scope-factory');
@@ -13,10 +16,27 @@ const activeLifecycleScope = new node_async_hooks_1.AsyncLocalStorage();
13
16
  const detachedLifecycleResource = new node_async_hooks_1.AsyncResource('zlink:handler-instance-scope');
14
17
  const dispatchScopes = new WeakMap();
15
18
  const lifecycleScopes = new WeakMap();
19
+ function registerHandlerInstanceScopeFactory(providerResolver, factory) {
20
+ Object.defineProperty(providerResolver, HANDLER_SCOPE_FACTORY, {
21
+ value: factory,
22
+ enumerable: false
23
+ });
24
+ }
25
+ function prepareHandlerInstance(providerResolver, type) {
26
+ if (providerResolver === undefined)
27
+ return () => new type();
28
+ const factory = providerResolver[HANDLER_SCOPE_FACTORY];
29
+ if (isHandlerInstanceScopeFactory(factory)) {
30
+ const activate = factory.prepare?.(type);
31
+ if (activate !== undefined)
32
+ return activate;
33
+ }
34
+ return undefined;
35
+ }
16
36
  async function runInHandlerInstanceScope(providerResolver, context, callback) {
17
37
  const active = activeHandlerScope.getStore();
18
38
  if (active !== undefined) {
19
- return callback(active.scope);
39
+ return callback(active);
20
40
  }
21
41
  if (context !== undefined) {
22
42
  const existing = dispatchScopes.get(context);
@@ -29,7 +49,7 @@ async function runInHandlerInstanceScope(providerResolver, context, callback) {
29
49
  dispatchScopes.set(context, scope);
30
50
  }
31
51
  try {
32
- return await activeHandlerScope.run({ scope }, () => callback(scope));
52
+ return await activeHandlerScope.run(scope, () => callback(scope));
33
53
  }
34
54
  finally {
35
55
  if (context !== undefined && dispatchScopes.get(context) === scope) {
@@ -94,14 +114,15 @@ class DefaultHandlerInstanceScope {
94
114
  return existing;
95
115
  const activation = createDeferred();
96
116
  this.instances.set(type, activation.promise);
97
- void this.activate(type, activation);
117
+ this.activate(type, activation);
98
118
  return activation.promise;
99
119
  }
100
120
  async dispose() {
101
121
  if (this.disposed)
102
122
  return;
103
123
  this.disposed = true;
104
- await Promise.allSettled(this.instances.values());
124
+ if (this.owned.length !== this.instances.size)
125
+ await Promise.allSettled(this.instances.values());
105
126
  try {
106
127
  await disposeOwnedInstances(this.owned);
107
128
  }
@@ -110,21 +131,37 @@ class DefaultHandlerInstanceScope {
110
131
  this.instances.clear();
111
132
  }
112
133
  }
113
- async activate(type, activation) {
114
- let instance;
134
+ activate(type, activation) {
115
135
  try {
116
136
  const created = this.providerResolver?.create?.(type);
117
- instance = created === undefined ? new type() : await created;
137
+ if (created === undefined) {
138
+ this.completeActivation(new type(), activation);
139
+ }
140
+ else {
141
+ void this.activatePending(created, activation);
142
+ }
118
143
  }
119
144
  catch (error) {
120
145
  activation.reject(error);
121
- return;
122
146
  }
147
+ }
148
+ async activatePending(created, activation) {
149
+ try {
150
+ this.completeActivation(await created, activation);
151
+ }
152
+ catch (error) {
153
+ activation.reject(error);
154
+ }
155
+ }
156
+ completeActivation(instance, activation) {
123
157
  if (!this.disposed) {
124
158
  this.owned.push(instance);
125
159
  activation.resolve(instance);
126
160
  return;
127
161
  }
162
+ void this.disposeLateActivation(instance, activation);
163
+ }
164
+ async disposeLateActivation(instance, activation) {
128
165
  try {
129
166
  await disposeOwnedInstance(instance);
130
167
  activation.reject(new Error('Handler instance scope was disposed during activation.'));
@@ -240,18 +277,24 @@ function startOutsideLifecycleInvocation(work) {
240
277
  return detachedLifecycleResource.runInAsyncScope(work);
241
278
  }
242
279
  async function disposeOwnedInstance(instance) {
280
+ const cleanup = handlerInstanceCleanup(instance);
281
+ if (cleanup !== undefined)
282
+ await cleanup.call(instance);
283
+ }
284
+ function handlerInstanceCleanup(instance) {
243
285
  if (instance === null || instance === undefined)
244
286
  return;
245
287
  const value = instance;
246
288
  if (typeof value.dispose === 'function') {
247
- await value.dispose();
289
+ return value.dispose;
248
290
  }
249
291
  else if (typeof value.close === 'function') {
250
- await value.close();
292
+ return value.close;
251
293
  }
252
294
  else if (typeof value.onModuleDestroy === 'function') {
253
- await value.onModuleDestroy();
295
+ return value.onModuleDestroy;
254
296
  }
297
+ return undefined;
255
298
  }
256
299
  async function disposeOwnedInstances(instances) {
257
300
  const failures = [];
@@ -173,8 +173,8 @@ class ZLinkActorPacketRelay {
173
173
  const state = this.options.actorManager()?.getState(relay.actorId);
174
174
  if (frameHeader.kind === protocol_1.ZLinkStreamMessageKind.Send) {
175
175
  const dispatch = state?.spotId === undefined
176
- ? this.requireSpotNodeRuntime().dispatchEntryActorPacket(relay.actorId, [header, body], false, remoteBoundSessionTarget, fallbackActorRef)
177
- : this.requireSpotManager().dispatchRoutedActorPacket(state.spotId, relay.actorId, [header, body], false, remoteBoundSessionTarget, fallbackActorRef);
176
+ ? this.requireSpotNodeRuntime().dispatchEntryActorPacket('remote', relay.actorId, [header, body], false, remoteBoundSessionTarget, fallbackActorRef)
177
+ : this.requireSpotManager().dispatchRoutedActorPacket('remote', state.spotId, relay.actorId, [header, body], false, remoteBoundSessionTarget, fallbackActorRef);
178
178
  // Spec 05 §1.3: a one-way Session Actor relay completes at relay
179
179
  // queue admission, not after the remote application turn. In
180
180
  // particular, a handler may register a deferred Join whose relocation
@@ -207,8 +207,8 @@ class ZLinkActorPacketRelay {
207
207
  frameHeader.requestSeq !== undefined &&
208
208
  relay.returnResponse !== true) {
209
209
  const dispatch = state?.spotId === undefined
210
- ? this.requireSpotNodeRuntime().dispatchEntryActorPacket(relay.actorId, [header, body], false, remoteBoundSessionTarget, fallbackActorRef)
211
- : this.requireSpotManager().dispatchRoutedActorPacket(state.spotId, relay.actorId, [header, body], false, remoteBoundSessionTarget, fallbackActorRef);
210
+ ? this.requireSpotNodeRuntime().dispatchEntryActorPacket('remote', relay.actorId, [header, body], false, remoteBoundSessionTarget, fallbackActorRef)
211
+ : this.requireSpotManager().dispatchRoutedActorPacket('remote', state.spotId, relay.actorId, [header, body], false, remoteBoundSessionTarget, fallbackActorRef);
212
212
  closeFrameMessages = false;
213
213
  const deferredPacketName = frameHeader.name;
214
214
  const deferredRequestSeq = frameHeader.requestSeq;
@@ -249,8 +249,8 @@ class ZLinkActorPacketRelay {
249
249
  };
250
250
  }
251
251
  const response = state?.spotId === undefined
252
- ? await this.requireSpotNodeRuntime().dispatchEntryActorPacket(relay.actorId, [header, body], relay.returnResponse === true, remoteBoundSessionTarget, fallbackActorRef)
253
- : await this.requireSpotManager().dispatchRoutedActorPacket(state.spotId, relay.actorId, [header, body], relay.returnResponse === true, remoteBoundSessionTarget, fallbackActorRef);
252
+ ? await this.requireSpotNodeRuntime().dispatchEntryActorPacket('remote', relay.actorId, [header, body], relay.returnResponse === true, remoteBoundSessionTarget, fallbackActorRef)
253
+ : await this.requireSpotManager().dispatchRoutedActorPacket('remote', state.spotId, relay.actorId, [header, body], relay.returnResponse === true, remoteBoundSessionTarget, fallbackActorRef);
254
254
  return {
255
255
  ok: true,
256
256
  response,
@@ -551,7 +551,7 @@ class ZLinkActorPacketRelay {
551
551
  try {
552
552
  this.options.detachedTaskRunner.runDetached('local actor packet relay', async () => {
553
553
  try {
554
- const response = await this.requireSpotManager().dispatchRoutedActorPacket(spotId, actor.actorId, [header, body], returnResponse);
554
+ const response = await this.requireSpotManager().dispatchRoutedActorPacket('local', spotId, actor.actorId, [header, body], returnResponse);
555
555
  if (!returnResponse) {
556
556
  return;
557
557
  }
@@ -149,9 +149,9 @@ class ZLinkActorRuntimeOptionsFactory {
149
149
  staleActorRefReporter: (_meshName, actorId) => this.options.actorHandoff.recordStaleFailure(actorId),
150
150
  staleActorRefPredicate: (meshName, actor) => this.actorBelongsToMesh(meshName, actor.actorId) &&
151
151
  this.options.actorHandoff.isKnownStale(actor),
152
- handoffCapture: (meshName, actorId, parts, returnResponse, actor, deadlineUnixMs) => this.actorBelongsToMesh(meshName, actorId) &&
152
+ handoffCapture: (meshName, actorId, parts, returnResponse, actor, deadlineUnixMs, onAdmitted) => this.actorBelongsToMesh(meshName, actorId) &&
153
153
  !this.options.actorHandoff.isProvisional(actorId)
154
- ? this.options.actorHandoff.capture(actorId, parts, returnResponse, undefined, actor, deadlineUnixMs)
154
+ ? this.options.actorHandoff.capture('local', actorId, parts, returnResponse, undefined, actor, deadlineUnixMs, undefined, undefined, onAdmitted)
155
155
  : undefined,
156
156
  sendErrorReporter: this.options.reportPostCommitError
157
157
  };
@@ -1,4 +1,4 @@
1
- import type { ApplicationJobPermitPort, ApplicationJobQueuePort } from '../application-jobs/contracts';
1
+ import type { ApplicationJobOrigin, ApplicationJobPermitPort, ApplicationJobReceiveRotationPort, ApplicationJobQueuePort } from '../application-jobs/contracts';
2
2
  export type ApplicationJobQueueProfileValue = 'compact' | 'low_latency' | 'balanced' | 'throughput';
3
3
  export interface ApplicationJobQueueOptions {
4
4
  readonly profile?: ApplicationJobQueueProfileValue;
@@ -39,12 +39,18 @@ export interface ApplicationJobQueueSnapshot extends ApplicationJobQueueConfigur
39
39
  export declare function resolveApplicationJobQueueConfiguration(options?: ApplicationJobQueueOptions, effectiveProcessorCount?: () => bigint): ApplicationJobQueueConfiguration;
40
40
  export declare class ApplicationJobQueuePermit implements ApplicationJobPermitPort {
41
41
  private readonly owner;
42
+ readonly origin: ApplicationJobOrigin;
43
+ private readonly reusable;
44
+ detachedForHandlerTurn: boolean;
42
45
  private state;
43
- constructor(owner: ApplicationJobQueue);
46
+ constructor(owner: ApplicationJobQueue, origin: ApplicationJobOrigin, reusable?: boolean);
47
+ reserveStorage(): boolean;
48
+ releaseStorage(): void;
49
+ detachForHandlerTurn(): void;
44
50
  markApplicationQueued(): void;
45
51
  releaseBeforeHandler(): void;
46
52
  releaseAfterInternalProcessing(): void;
47
- private release;
53
+ takeReleaseState(): 'reserved' | 'queued' | undefined;
48
54
  }
49
55
  /**
50
56
  * Host-instance owner of the ordinary-ingress queue permit lifecycle.
@@ -55,9 +61,13 @@ export declare class ApplicationJobQueue implements ApplicationJobQueuePort {
55
61
  private readonly configuration;
56
62
  private readonly nowMs;
57
63
  private readonly handlerStartGate?;
58
- private reservedSupplyPermits;
59
- private queuedApplicationJobs;
60
- private peakPermitsInUse;
64
+ private readonly loggerFailureReporter?;
65
+ private localWaiters;
66
+ private localBacklogLogged;
67
+ private readonly permitCounts;
68
+ private readonly limitCount;
69
+ private readonly pauseCount;
70
+ private readonly resumeCount;
61
71
  private capacityWaitCount;
62
72
  private capacityWaitDurationSeconds;
63
73
  private metricsEpoch;
@@ -73,11 +83,15 @@ export declare class ApplicationJobQueue implements ApplicationJobQueuePort {
73
83
  private readonly waiters;
74
84
  private readonly receiveFlowTargets;
75
85
  private readonly receiveFlowController;
76
- constructor(configuration: ApplicationJobQueueConfiguration, nowMs?: () => number, handlerStartGate?: (() => boolean) | undefined);
86
+ constructor(configuration: ApplicationJobQueueConfiguration, nowMs?: () => number, handlerStartGate?: (() => boolean) | undefined, loggerFailureReporter?: ((error: unknown) => void) | undefined);
77
87
  shouldHoldPermitBeforeHandler(): boolean;
88
+ createReceiveRotation(capacity: number, origin: ApplicationJobOrigin): ApplicationJobReceiveRotationPort;
89
+ receiveRotationCapacity(capacity: number): number;
90
+ reserveReceiveRotation(count: number): void;
78
91
  registerReceiveFlowTarget(identity: object, applyState: (state: ApplicationJobQueuePressureState) => void, failureSink?: (error: unknown) => void): boolean;
79
92
  unregisterReceiveFlowTarget(identity: object): void;
80
- acquire(signal?: AbortSignal): Promise<ApplicationJobQueuePermit>;
93
+ acquire(signal: AbortSignal | undefined, origin: ApplicationJobOrigin): Promise<ApplicationJobQueuePermit>;
94
+ acquireOrResume(resume: (permit: ApplicationJobQueuePermit) => void, reject: (reason: unknown) => void, signal: AbortSignal | undefined, origin: ApplicationJobOrigin): ApplicationJobQueuePermit | undefined;
81
95
  snapshot(): ApplicationJobQueueSnapshot;
82
96
  resetMetrics(): void;
83
97
  pressureState(): ApplicationJobQueuePressureState;
@@ -85,13 +99,18 @@ export declare class ApplicationJobQueue implements ApplicationJobQueuePort {
85
99
  onPressureStateChange(listener: (state: ApplicationJobQueuePressureState, sequence: bigint) => void): () => void;
86
100
  recordFlowStateConfigFailure(): void;
87
101
  markQueued(): void;
88
- release(state: 'reserved' | 'queued'): void;
102
+ releasePermit(permit: ApplicationJobQueuePermit): void;
103
+ releaseUnusedReceiveRotation(grants: readonly (ApplicationJobQueuePermit | undefined)[], consumed: number, granted: number): void;
104
+ release(state: 'reserved' | 'queued', count?: number): void;
89
105
  private limit;
90
106
  private permitsInUse;
107
+ private reserveSupply;
91
108
  private reserve;
92
109
  private drainWaiters;
93
110
  private cancel;
94
111
  private recordCompletedWait;
112
+ private updateLocalWaiters;
113
+ private logLocalBacklog;
95
114
  private evaluatePressure;
96
115
  private pauseDurationAt;
97
116
  private cumulativePauseDurationAt;