@zlink-systems/framework 0.26.0 → 0.27.0

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 (521) hide show
  1. package/dist/.tsbuildinfo +1 -1
  2. package/dist/contracts/Common/CoreTypes.d.ts +6 -0
  3. package/dist/contracts/Common/CoreTypes.js +7 -0
  4. package/dist/contracts/Common/index.d.ts +1 -1
  5. package/dist/contracts/Common/index.js +0 -1
  6. package/dist/contracts/Configuration/InternalDefaults.d.ts +8 -0
  7. package/dist/contracts/Configuration/InternalDefaults.js +9 -1
  8. package/dist/contracts/Configuration/Registration.d.ts +13 -2
  9. package/dist/contracts/Configuration/Registration.js +58 -36
  10. package/dist/contracts/Configuration/RegistrationBuilderPolicy.d.ts +13 -1
  11. package/dist/contracts/Configuration/RegistrationBuilderPolicy.js +38 -1
  12. package/dist/contracts/Configuration/RegistrationBuilders.d.ts +2 -3
  13. package/dist/contracts/Configuration/RegistrationBuilders.js +27 -32
  14. package/dist/contracts/Configuration/RegistrationTypes.d.ts +1 -0
  15. package/dist/contracts/Configuration/RegistrationValidators.js +15 -12
  16. package/dist/contracts/Configuration/TimerRegistrationValidator.js +3 -2
  17. package/dist/contracts/Dispatch/ZLinkDispatchOptions.d.ts +1 -1
  18. package/dist/contracts/Handlers/JsonContract.js +10 -4
  19. package/dist/contracts/Locations/Authority.d.ts +1 -1
  20. package/dist/contracts/Locations/Authority.js +3 -2
  21. package/dist/contracts/Locations/Options.js +1 -1
  22. package/dist/contracts/Locations/Stores.d.ts +12 -0
  23. package/dist/contracts/Locations/Stores.js +9 -0
  24. package/dist/contracts/Spots/Contracts.d.ts +1 -1
  25. package/dist/internal.d.ts +4 -0
  26. package/dist/internal.js +15 -1
  27. package/dist/nest-integration.d.ts +4 -2
  28. package/dist/nest-integration.js +14 -4
  29. package/dist/runtime/abort.d.ts +1 -0
  30. package/dist/runtime/abort.js +8 -5
  31. package/dist/runtime/activation-admission.d.ts +1 -2
  32. package/dist/runtime/activation-admission.js +2 -6
  33. package/dist/runtime/actors/actor-authority-payload-codec.d.ts +1 -2
  34. package/dist/runtime/actors/actor-authority-payload-codec.js +34 -18
  35. package/dist/runtime/actors/actor-client.d.ts +2 -2
  36. package/dist/runtime/actors/actor-client.js +42 -143
  37. package/dist/runtime/actors/actor-context.d.ts +3 -5
  38. package/dist/runtime/actors/actor-context.js +13 -11
  39. package/dist/runtime/actors/actor-handoff.d.ts +4 -4
  40. package/dist/runtime/actors/actor-handoff.js +8 -8
  41. package/dist/runtime/actors/actor-lifecycle-snapshot.js +2 -1
  42. package/dist/runtime/actors/actor-local-native-join.d.ts +11 -6
  43. package/dist/runtime/actors/actor-local-native-join.js +83 -105
  44. package/dist/runtime/actors/actor-native-lookup.js +2 -8
  45. package/dist/runtime/actors/actor-packet-relay-wire.d.ts +3 -3
  46. package/dist/runtime/actors/actor-packet-relay-wire.js +5 -3
  47. package/dist/runtime/actors/actor-remote-joiner.d.ts +1 -1
  48. package/dist/runtime/actors/actor-remote-joiner.js +5 -9
  49. package/dist/runtime/actors/actor-remote-wire.js +5 -3
  50. package/dist/runtime/actors/actor-request-deadline.d.ts +3 -0
  51. package/dist/runtime/actors/actor-request-deadline.js +31 -0
  52. package/dist/runtime/actors/actor-retry-delay.js +2 -1
  53. package/dist/runtime/actors/actor-runtime-state.d.ts +9 -21
  54. package/dist/runtime/actors/actor-runtime-state.js +70 -187
  55. package/dist/runtime/actors/bound-session-wire.js +2 -7
  56. package/dist/runtime/actors/deferred-join-completion.d.ts +11 -6
  57. package/dist/runtime/actors/deferred-join-completion.js +1 -0
  58. package/dist/runtime/actors/index.d.ts +9 -7
  59. package/dist/runtime/actors/index.js +87 -69
  60. package/dist/runtime/actors/spot-actor-dispatch.d.ts +3 -3
  61. package/dist/runtime/actors/spot-actor-dispatch.js +25 -10
  62. package/dist/runtime/actors/transferred-actor-rollback.d.ts +3 -5
  63. package/dist/runtime/actors/transferred-actor-rollback.js +9 -42
  64. package/dist/runtime/admission.d.ts +2 -0
  65. package/dist/runtime/admission.js +7 -1
  66. package/dist/runtime/application-jobs/application-job-queue-scope.d.ts +1 -1
  67. package/dist/runtime/application-jobs/application-job-queue-scope.js +1 -1
  68. package/dist/runtime/backend/contracts/index.d.ts +6 -23
  69. package/dist/runtime/backend/mesh-actor-session-node-adapter.js +1 -17
  70. package/dist/runtime/backend/mesh-dispatch-pump.d.ts +1 -2
  71. package/dist/runtime/backend/mesh-dispatch-pump.js +95 -107
  72. package/dist/runtime/backend/node/node-backend-adapter-support.d.ts +1 -1
  73. package/dist/runtime/backend/node/node-backend-adapter-support.js +16 -6
  74. package/dist/runtime/backend/node/node-event-loop-poller.d.ts +2 -2
  75. package/dist/runtime/backend/node/node-event-loop-poller.js +6 -7
  76. package/dist/runtime/backend/node/node-monitor-backend-adapter.js +1 -0
  77. package/dist/runtime/backend/node/node-raw-binding-port.js +40 -16
  78. package/dist/runtime/backend/node/node-raw-mesh-backend.d.ts +14 -15
  79. package/dist/runtime/backend/node/node-raw-mesh-backend.js +146 -118
  80. package/dist/runtime/backend/node/node-socket-backend-adapter.js +3 -2
  81. package/dist/runtime/backend/raw-binding-port.d.ts +1 -1
  82. package/dist/runtime/backend/runtime-values.d.ts +4 -1
  83. package/dist/runtime/backend/runtime-values.js +2 -0
  84. package/dist/runtime/channels/channel-clients.d.ts +20 -8
  85. package/dist/runtime/channels/channel-clients.js +68 -52
  86. package/dist/runtime/channels/channel-envelope-inspection.js +2 -1
  87. package/dist/runtime/channels/channel-envelope.js +47 -29
  88. package/dist/runtime/channels/channel-outbound-operations.d.ts +3 -0
  89. package/dist/runtime/channels/channel-outbound-operations.js +9 -10
  90. package/dist/runtime/channels/channel-receive-loops.d.ts +8 -3
  91. package/dist/runtime/channels/channel-receive-loops.js +27 -6
  92. package/dist/runtime/channels/channel-runtime-lifecycle.d.ts +12 -1
  93. package/dist/runtime/channels/channel-runtime-lifecycle.js +48 -28
  94. package/dist/runtime/channels/channel-runtime-manager.js +5 -2
  95. package/dist/runtime/channels/channel-socket-options.js +3 -2
  96. package/dist/runtime/channels/channel-socket-registry.d.ts +14 -29
  97. package/dist/runtime/channels/channel-socket-registry.js +248 -174
  98. package/dist/runtime/channels/channel-transports.d.ts +11 -17
  99. package/dist/runtime/channels/channel-transports.js +68 -47
  100. package/dist/runtime/channels/client-server-location-runtime.d.ts +1 -1
  101. package/dist/runtime/channels/client-server-location-runtime.js +10 -11
  102. package/dist/runtime/channels/client-server-service-wire.d.ts +7 -2
  103. package/dist/runtime/channels/client-server-service-wire.js +32 -11
  104. package/dist/runtime/channels/dispatch-error-reporter.d.ts +1 -2
  105. package/dist/runtime/channels/dispatch-error-reporter.js +2 -1
  106. package/dist/runtime/channels/fanout-location-runtime.d.ts +16 -3
  107. package/dist/runtime/channels/fanout-location-runtime.js +130 -72
  108. package/dist/runtime/channels/spot-direct-envelope.d.ts +1 -0
  109. package/dist/runtime/channels/spot-direct-envelope.js +4 -3
  110. package/dist/runtime/channels/spot-node-route-transport.js +3 -2
  111. package/dist/runtime/diagnostics/diagnostic-text.d.ts +2 -0
  112. package/dist/runtime/diagnostics/diagnostic-text.js +7 -0
  113. package/dist/runtime/diagnostics/dispatch-error-details.d.ts +3 -0
  114. package/dist/runtime/diagnostics/dispatch-error-details.js +30 -2
  115. package/dist/runtime/diagnostics/flow-context.d.ts +6 -0
  116. package/dist/runtime/diagnostics/flow-context.js +16 -2
  117. package/dist/runtime/diagnostics/index.d.ts +4 -2
  118. package/dist/runtime/diagnostics/index.js +14 -4
  119. package/dist/runtime/diagnostics/message-flow.d.ts +1 -1
  120. package/dist/runtime/diagnostics/message-flow.js +10 -19
  121. package/dist/runtime/diagnostics/runtime-metrics.d.ts +94 -31
  122. package/dist/runtime/diagnostics/runtime-metrics.js +168 -105
  123. package/dist/runtime/diagnostics/runtime-observation-queue.js +3 -2
  124. package/dist/runtime/diagnostics/topology-runtime-projections.d.ts +2 -4
  125. package/dist/runtime/diagnostics/topology-runtime-projections.js +135 -154
  126. package/dist/runtime/disposal.d.ts +5 -0
  127. package/dist/runtime/disposal.js +22 -0
  128. package/dist/runtime/execution/index.d.ts +12 -9
  129. package/dist/runtime/execution/index.js +58 -14
  130. package/dist/runtime/execution/serial-execution-queue.d.ts +8 -2
  131. package/dist/runtime/execution/serial-execution-queue.js +54 -15
  132. package/dist/runtime/execution/state-lane.d.ts +8 -1
  133. package/dist/runtime/execution/state-lane.js +118 -3
  134. package/dist/runtime/foundation/actor-join-recovery-codec.d.ts +3 -0
  135. package/dist/runtime/foundation/actor-join-recovery-codec.js +15 -11
  136. package/dist/runtime/foundation/event-loop-resources.d.ts +2 -24
  137. package/dist/runtime/foundation/event-loop-resources.js +6 -119
  138. package/dist/runtime/foundation/operation-identity.d.ts +2 -0
  139. package/dist/runtime/foundation/operation-identity.js +9 -5
  140. package/dist/runtime/foundation/operation-registry.d.ts +5 -7
  141. package/dist/runtime/foundation/operation-registry.js +34 -44
  142. package/dist/runtime/foundation/raw-service-mesh-runtime.d.ts +8 -5
  143. package/dist/runtime/foundation/raw-service-mesh-runtime.js +62 -83
  144. package/dist/runtime/foundation/runtime-state-projections.d.ts +3 -1
  145. package/dist/runtime/foundation/runtime-state-projections.js +8 -0
  146. package/dist/runtime/foundation/service-authority-payload-codec.js +22 -12
  147. package/dist/runtime/foundation/service-discovery-registry.d.ts +4 -0
  148. package/dist/runtime/foundation/service-discovery-registry.js +22 -3
  149. package/dist/runtime/foundation/service-instance-activation-recovery-codec.js +8 -4
  150. package/dist/runtime/foundation/service-liveness-registry.js +2 -1
  151. package/dist/runtime/foundation/service-maintenance-runtime.d.ts +0 -1
  152. package/dist/runtime/foundation/service-maintenance-runtime.js +0 -6
  153. package/dist/runtime/foundation/service-metadata-codec.js +3 -3
  154. package/dist/runtime/foundation/service-relocation-aggregate-committer.d.ts +2 -5
  155. package/dist/runtime/foundation/service-relocation-aggregate-committer.js +1 -48
  156. package/dist/runtime/foundation/service-relocation-object-owner.js +3 -2
  157. package/dist/runtime/foundation/service-relocation-runtime.js +43 -32
  158. package/dist/runtime/foundation/service-runtime-contracts.d.ts +40 -8
  159. package/dist/runtime/foundation/service-runtime-contracts.js +25 -1
  160. package/dist/runtime/foundation/service-session-binding-ingress-port.d.ts +0 -12
  161. package/dist/runtime/foundation/service-stateful-registry.d.ts +2 -0
  162. package/dist/runtime/foundation/service-stateful-registry.js +10 -2
  163. package/dist/runtime/foundation/service-stateful-runtime.d.ts +26 -25
  164. package/dist/runtime/foundation/service-stateful-runtime.js +217 -204
  165. package/dist/runtime/foundation/service-stateful-wire-codec.d.ts +3 -3
  166. package/dist/runtime/foundation/service-stateful-wire-codec.js +89 -55
  167. package/dist/runtime/foundation/service-topology-registry.d.ts +0 -1
  168. package/dist/runtime/foundation/service-topology-registry.js +17 -32
  169. package/dist/runtime/foundation/service-wire-binary-primitives.d.ts +5 -0
  170. package/dist/runtime/foundation/service-wire-binary-primitives.js +6 -0
  171. package/dist/runtime/foundation/service-wire-codec.js +10 -8
  172. package/dist/runtime/foundation/service-wire-constants.generated.d.ts +1 -0
  173. package/dist/runtime/foundation/service-wire-constants.generated.js +2 -1
  174. package/dist/runtime/foundation/service-wire-m6a-codec.d.ts +2 -0
  175. package/dist/runtime/foundation/service-wire-m6a-codec.js +23 -13
  176. package/dist/runtime/framework-errors-internal.d.ts +2 -1
  177. package/dist/runtime/framework-errors-internal.js +343 -122
  178. package/dist/runtime/handlers/handler-instance-scope.d.ts +3 -1
  179. package/dist/runtime/handlers/handler-instance-scope.js +61 -74
  180. package/dist/runtime/host/actor-packet-relay.d.ts +9 -6
  181. package/dist/runtime/host/actor-packet-relay.js +48 -91
  182. package/dist/runtime/host/actor-placement-coordinator.js +7 -5
  183. package/dist/runtime/host/actor-runtime-options-factory.d.ts +2 -0
  184. package/dist/runtime/host/actor-runtime-options-factory.js +17 -4
  185. package/dist/runtime/host/actor-transfer-runtime.d.ts +16 -18
  186. package/dist/runtime/host/actor-transfer-runtime.js +143 -176
  187. package/dist/runtime/host/application-job-queue.js +16 -33
  188. package/dist/runtime/host/bound-session-relay.js +1 -1
  189. package/dist/runtime/host/channel-runtime-options-factory.js +1 -1
  190. package/dist/runtime/host/index.d.ts +14 -13
  191. package/dist/runtime/host/index.js +190 -157
  192. package/dist/runtime/host/instance-activation-authority.d.ts +2 -3
  193. package/dist/runtime/host/instance-activation-authority.js +17 -45
  194. package/dist/runtime/host/location-runtime-owner.d.ts +1 -1
  195. package/dist/runtime/host/location-runtime-owner.js +2 -2
  196. package/dist/runtime/host/remote-actor-join-receiver.d.ts +2 -2
  197. package/dist/runtime/host/remote-actor-join-receiver.js +1 -14
  198. package/dist/runtime/host/remote-actor-packet-target-store.d.ts +3 -2
  199. package/dist/runtime/host/remote-actor-packet-target-store.js +8 -47
  200. package/dist/runtime/host/remote-bound-session-relay.d.ts +2 -3
  201. package/dist/runtime/host/remote-bound-session-relay.js +7 -20
  202. package/dist/runtime/host/route-mesh-runtime.d.ts +13 -11
  203. package/dist/runtime/host/route-mesh-runtime.js +171 -252
  204. package/dist/runtime/host/runtime-shutdown.d.ts +2 -0
  205. package/dist/runtime/host/runtime-shutdown.js +18 -21
  206. package/dist/runtime/host/service-relocation-control.js +6 -1
  207. package/dist/runtime/host/service-relocation-host-runtime.d.ts +21 -30
  208. package/dist/runtime/host/service-relocation-host-runtime.js +508 -416
  209. package/dist/runtime/host/spot-address-transport.d.ts +2 -3
  210. package/dist/runtime/host/spot-address-transport.js +34 -136
  211. package/dist/runtime/host/spot-node-runtime-options-factory.d.ts +1 -1
  212. package/dist/runtime/host/spot-node-runtime-options-factory.js +3 -2
  213. package/dist/runtime/host/spot-runtime-options-factory.d.ts +4 -10
  214. package/dist/runtime/host/spot-runtime-options-factory.js +50 -14
  215. package/dist/runtime/host/user-spot-creation-coordinator.d.ts +3 -3
  216. package/dist/runtime/host/user-spot-creation-coordinator.js +11 -8
  217. package/dist/runtime/locations/aggregate-inventory-store.js +13 -10
  218. package/dist/runtime/locations/authority-key-codec.js +4 -3
  219. package/dist/runtime/locations/auto-connect-reconciler.d.ts +4 -0
  220. package/dist/runtime/locations/auto-connect-reconciler.js +37 -25
  221. package/dist/runtime/locations/creation-operation-id.js +6 -4
  222. package/dist/runtime/locations/domain-store-contract.d.ts +3 -3
  223. package/dist/runtime/locations/in-memory-authority-store.js +31 -15
  224. package/dist/runtime/locations/in-memory-location-store.d.ts +2 -2
  225. package/dist/runtime/locations/in-memory-location-store.js +17 -14
  226. package/dist/runtime/locations/in-memory-provider-location-store.d.ts +1 -0
  227. package/dist/runtime/locations/in-memory-provider-location-store.js +72 -22
  228. package/dist/runtime/locations/key-codec.js +3 -2
  229. package/dist/runtime/locations/lease-tracker.d.ts +3 -5
  230. package/dist/runtime/locations/lease-tracker.js +7 -11
  231. package/dist/runtime/locations/lifecycle.d.ts +4 -9
  232. package/dist/runtime/locations/lifecycle.js +2 -31
  233. package/dist/runtime/locations/location-store-failure.d.ts +2 -0
  234. package/dist/runtime/locations/location-store-failure.js +7 -0
  235. package/dist/runtime/locations/location-store-pages.d.ts +3 -0
  236. package/dist/runtime/locations/location-store-pages.js +13 -0
  237. package/dist/runtime/locations/location-store-repository.d.ts +5 -7
  238. package/dist/runtime/locations/location-store-repository.js +303 -332
  239. package/dist/runtime/locations/relocation-blob.js +18 -5
  240. package/dist/runtime/locations/resolvers.d.ts +5 -5
  241. package/dist/runtime/locations/resolvers.js +37 -28
  242. package/dist/runtime/locations/runtime.d.ts +5 -4
  243. package/dist/runtime/locations/runtime.js +123 -92
  244. package/dist/runtime/locations/spot-location-claims.d.ts +6 -0
  245. package/dist/runtime/locations/spot-location-claims.js +42 -1
  246. package/dist/runtime/messaging/payload-codec.js +26 -20
  247. package/dist/runtime/messaging/submission-result.d.ts +3 -0
  248. package/dist/runtime/messaging/submission-result.js +48 -0
  249. package/dist/runtime/protocol/service_wire_codec.generated.d.ts +1 -0
  250. package/dist/runtime/protocol/service_wire_codec.generated.js +12 -7
  251. package/dist/runtime/spots/formal-remote-actor-transfer-registry.d.ts +4 -1
  252. package/dist/runtime/spots/index.d.ts +14 -20
  253. package/dist/runtime/spots/index.js +302 -176
  254. package/dist/runtime/spots/spot-activation-registry.d.ts +3 -5
  255. package/dist/runtime/spots/spot-activation-registry.js +14 -50
  256. package/dist/runtime/spots/spot-activation-state.d.ts +1 -1
  257. package/dist/runtime/spots/spot-activation-state.js +2 -2
  258. package/dist/runtime/spots/spot-activation.d.ts +3 -4
  259. package/dist/runtime/spots/spot-activation.js +49 -32
  260. package/dist/runtime/spots/spot-actor-admission-coordinator.d.ts +1 -2
  261. package/dist/runtime/spots/spot-actor-admission-coordinator.js +3 -40
  262. package/dist/runtime/spots/spot-actor-join-dispatch.d.ts +10 -18
  263. package/dist/runtime/spots/spot-actor-join-dispatch.js +4 -52
  264. package/dist/runtime/spots/spot-actor-membership.d.ts +4 -6
  265. package/dist/runtime/spots/spot-actor-membership.js +22 -45
  266. package/dist/runtime/spots/spot-actor-packet-dispatch.d.ts +0 -1
  267. package/dist/runtime/spots/spot-actor-packet-dispatch.js +0 -9
  268. package/dist/runtime/spots/spot-actor-packet-relay-dispatch.d.ts +2 -2
  269. package/dist/runtime/spots/spot-actor-packet-relay-dispatch.js +1 -7
  270. package/dist/runtime/spots/spot-context.d.ts +2 -2
  271. package/dist/runtime/spots/spot-entry-activation.d.ts +2 -2
  272. package/dist/runtime/spots/spot-entry-activation.js +9 -20
  273. package/dist/runtime/spots/spot-lifecycle-metrics.js +3 -2
  274. package/dist/runtime/spots/spot-manager-public.d.ts +5 -6
  275. package/dist/runtime/spots/spot-manager-public.js +5 -4
  276. package/dist/runtime/spots/spot-node-autoconnect.js +22 -31
  277. package/dist/runtime/spots/spot-node-runtime-manager.d.ts +19 -18
  278. package/dist/runtime/spots/spot-node-runtime-manager.js +67 -72
  279. package/dist/runtime/spots/spot-outbound.d.ts +4 -3
  280. package/dist/runtime/spots/spot-outbound.js +9 -8
  281. package/dist/runtime/spots/spot-remote-codec.js +5 -3
  282. package/dist/runtime/spots/spot-route-packet-dispatch.d.ts +2 -2
  283. package/dist/runtime/spots/spot-route-packet-dispatch.js +8 -8
  284. package/dist/runtime/spots/spot-route-replies.d.ts +2 -2
  285. package/dist/runtime/spots/spot-route-replies.js +3 -1
  286. package/dist/runtime/spots/spot-routed-actor-admission.d.ts +3 -3
  287. package/dist/runtime/spots/spot-routed-actor-admission.js +3 -12
  288. package/dist/runtime/spots/spot-routed-frame-dispatch.d.ts +1 -2
  289. package/dist/runtime/spots/spot-routed-frame-dispatch.js +0 -1
  290. package/dist/runtime/spots/spot-routed-spot-packet-dispatch.d.ts +4 -0
  291. package/dist/runtime/spots/spot-routed-spot-packet-dispatch.js +65 -15
  292. package/dist/runtime/spots/spot-runtime-ports.d.ts +2 -16
  293. package/dist/runtime/spots/spot-serial-executor.js +2 -2
  294. package/dist/runtime/spots/spot-serial-turn-executor.d.ts +27 -7
  295. package/dist/runtime/spots/spot-serial-turn-executor.js +83 -11
  296. package/dist/runtime/spots/spot-timer.d.ts +3 -2
  297. package/dist/runtime/streams/actor-session-binding-registry.d.ts +16 -29
  298. package/dist/runtime/streams/actor-session-binding-registry.js +142 -212
  299. package/dist/runtime/streams/actor-session-binding-runtime-owner.d.ts +1 -4
  300. package/dist/runtime/streams/bound-actor-relay-sender.d.ts +6 -2
  301. package/dist/runtime/streams/bound-actor-relay-sender.js +57 -33
  302. package/dist/runtime/streams/bound-session-service.d.ts +7 -0
  303. package/dist/runtime/streams/bound-session-service.js +11 -1
  304. package/dist/runtime/streams/index.d.ts +14 -15
  305. package/dist/runtime/streams/index.js +20 -21
  306. package/dist/runtime/streams/managed-stream.d.ts +3 -0
  307. package/dist/runtime/streams/managed-stream.js +17 -8
  308. package/dist/runtime/streams/native-fallback-bound-session.js +1 -3
  309. package/dist/runtime/streams/protocol.d.ts +6 -33
  310. package/dist/runtime/streams/protocol.js +38 -110
  311. package/dist/runtime/streams/session-actor-coordinator.d.ts +2 -3
  312. package/dist/runtime/streams/session-actor-coordinator.js +12 -4
  313. package/dist/runtime/streams/session-calls.d.ts +1 -1
  314. package/dist/runtime/streams/session-calls.js +5 -4
  315. package/dist/runtime/streams/session-context.d.ts +6 -6
  316. package/dist/runtime/streams/session-context.js +22 -4
  317. package/dist/runtime/streams/session-requests.js +2 -1
  318. package/dist/runtime/streams/stream-binding-runtime-ports.d.ts +16 -1
  319. package/dist/runtime/streams/stream-frame-factory.js +2 -2
  320. package/dist/runtime/streams/stream-session-runtime.d.ts +10 -11
  321. package/dist/runtime/streams/stream-session-runtime.js +25 -33
  322. package/dist/runtime/workers/index.d.ts +2 -2
  323. package/dist/runtime/workers/index.js +5 -4
  324. package/package.json +3 -3
  325. package/src/contracts/Common/CoreTypes.ts +7 -0
  326. package/src/contracts/Common/index.ts +1 -1
  327. package/src/contracts/Configuration/InternalDefaults.ts +12 -0
  328. package/src/contracts/Configuration/Registration.ts +92 -48
  329. package/src/contracts/Configuration/RegistrationBuilderPolicy.ts +44 -2
  330. package/src/contracts/Configuration/RegistrationBuilders.ts +77 -68
  331. package/src/contracts/Configuration/RegistrationTypes.ts +1 -0
  332. package/src/contracts/Configuration/RegistrationValidators.ts +19 -13
  333. package/src/contracts/Configuration/TimerRegistrationValidator.ts +4 -2
  334. package/src/contracts/Dispatch/ZLinkDispatchOptions.ts +1 -0
  335. package/src/contracts/Handlers/JsonContract.ts +14 -4
  336. package/src/contracts/Locations/Authority.ts +7 -3
  337. package/src/contracts/Locations/Options.ts +1 -1
  338. package/src/contracts/Locations/Stores.ts +14 -0
  339. package/src/contracts/Spots/Contracts.ts +1 -1
  340. package/src/internal.ts +14 -0
  341. package/src/nest-integration.ts +28 -10
  342. package/src/runtime/abort.ts +6 -5
  343. package/src/runtime/activation-admission.ts +2 -8
  344. package/src/runtime/actors/actor-authority-payload-codec.ts +58 -20
  345. package/src/runtime/actors/actor-client.ts +77 -204
  346. package/src/runtime/actors/actor-context.ts +39 -33
  347. package/src/runtime/actors/actor-handoff.ts +24 -22
  348. package/src/runtime/actors/actor-lifecycle-snapshot.ts +2 -1
  349. package/src/runtime/actors/actor-local-native-join.ts +172 -174
  350. package/src/runtime/actors/actor-native-lookup.ts +2 -9
  351. package/src/runtime/actors/actor-packet-relay-wire.ts +18 -12
  352. package/src/runtime/actors/actor-remote-joiner.ts +9 -11
  353. package/src/runtime/actors/actor-remote-wire.ts +5 -3
  354. package/src/runtime/actors/actor-request-deadline.ts +49 -0
  355. package/src/runtime/actors/actor-retry-delay.ts +2 -1
  356. package/src/runtime/actors/actor-runtime-state.ts +85 -247
  357. package/src/runtime/actors/bound-session-wire.ts +2 -8
  358. package/src/runtime/actors/deferred-join-completion.ts +10 -6
  359. package/src/runtime/actors/index.ts +100 -79
  360. package/src/runtime/actors/spot-actor-dispatch.ts +60 -29
  361. package/src/runtime/actors/transferred-actor-rollback.ts +11 -62
  362. package/src/runtime/admission.ts +8 -1
  363. package/src/runtime/application-jobs/application-job-queue-scope.ts +4 -4
  364. package/src/runtime/backend/contracts/index.ts +13 -29
  365. package/src/runtime/backend/mesh-actor-session-node-adapter.ts +2 -18
  366. package/src/runtime/backend/mesh-dispatch-pump.ts +111 -117
  367. package/src/runtime/backend/node/node-backend-adapter-support.ts +23 -6
  368. package/src/runtime/backend/node/node-event-loop-poller.ts +8 -12
  369. package/src/runtime/backend/node/node-monitor-backend-adapter.ts +1 -0
  370. package/src/runtime/backend/node/node-raw-binding-port.ts +41 -20
  371. package/src/runtime/backend/node/node-raw-mesh-backend.ts +227 -170
  372. package/src/runtime/backend/node/node-socket-backend-adapter.ts +3 -2
  373. package/src/runtime/backend/raw-binding-port.ts +1 -1
  374. package/src/runtime/backend/runtime-values.ts +4 -1
  375. package/src/runtime/channels/channel-clients.ts +132 -85
  376. package/src/runtime/channels/channel-envelope-inspection.ts +2 -1
  377. package/src/runtime/channels/channel-envelope.ts +58 -29
  378. package/src/runtime/channels/channel-outbound-operations.ts +10 -23
  379. package/src/runtime/channels/channel-receive-loops.ts +39 -7
  380. package/src/runtime/channels/channel-runtime-lifecycle.ts +60 -27
  381. package/src/runtime/channels/channel-runtime-manager.ts +6 -2
  382. package/src/runtime/channels/channel-socket-options.ts +8 -2
  383. package/src/runtime/channels/channel-socket-registry.ts +301 -192
  384. package/src/runtime/channels/channel-transports.ts +161 -112
  385. package/src/runtime/channels/client-server-location-runtime.ts +17 -17
  386. package/src/runtime/channels/client-server-service-wire.ts +40 -12
  387. package/src/runtime/channels/dispatch-error-reporter.ts +7 -5
  388. package/src/runtime/channels/fanout-location-runtime.ts +172 -91
  389. package/src/runtime/channels/spot-direct-envelope.ts +1 -1
  390. package/src/runtime/channels/spot-node-route-transport.ts +5 -2
  391. package/src/runtime/diagnostics/diagnostic-text.ts +4 -0
  392. package/src/runtime/diagnostics/dispatch-error-details.ts +36 -1
  393. package/src/runtime/diagnostics/flow-context.ts +16 -2
  394. package/src/runtime/diagnostics/index.ts +27 -17
  395. package/src/runtime/diagnostics/message-flow.ts +15 -25
  396. package/src/runtime/diagnostics/runtime-metrics.ts +181 -113
  397. package/src/runtime/diagnostics/runtime-observation-queue.ts +3 -2
  398. package/src/runtime/diagnostics/topology-runtime-projections.ts +194 -162
  399. package/src/runtime/disposal.ts +19 -0
  400. package/src/runtime/execution/index.ts +60 -20
  401. package/src/runtime/execution/serial-execution-queue.ts +131 -18
  402. package/src/runtime/execution/state-lane.ts +142 -4
  403. package/src/runtime/foundation/actor-join-recovery-codec.ts +13 -8
  404. package/src/runtime/foundation/event-loop-resources.ts +5 -122
  405. package/src/runtime/foundation/operation-identity.ts +11 -5
  406. package/src/runtime/foundation/operation-registry.ts +33 -50
  407. package/src/runtime/foundation/raw-service-mesh-runtime.ts +110 -111
  408. package/src/runtime/foundation/runtime-state-projections.ts +9 -1
  409. package/src/runtime/foundation/service-authority-payload-codec.ts +31 -13
  410. package/src/runtime/foundation/service-discovery-registry.ts +32 -3
  411. package/src/runtime/foundation/service-instance-activation-recovery-codec.ts +12 -4
  412. package/src/runtime/foundation/service-liveness-registry.ts +2 -1
  413. package/src/runtime/foundation/service-maintenance-runtime.ts +0 -10
  414. package/src/runtime/foundation/service-metadata-codec.ts +2 -2
  415. package/src/runtime/foundation/service-relocation-aggregate-committer.ts +3 -66
  416. package/src/runtime/foundation/service-relocation-object-owner.ts +5 -2
  417. package/src/runtime/foundation/service-relocation-runtime.ts +57 -35
  418. package/src/runtime/foundation/service-runtime-contracts.ts +46 -10
  419. package/src/runtime/foundation/service-session-binding-ingress-port.ts +0 -17
  420. package/src/runtime/foundation/service-stateful-registry.ts +14 -2
  421. package/src/runtime/foundation/service-stateful-runtime.ts +322 -276
  422. package/src/runtime/foundation/service-stateful-wire-codec.ts +128 -80
  423. package/src/runtime/foundation/service-topology-registry.ts +23 -32
  424. package/src/runtime/foundation/service-wire-binary-primitives.ts +6 -0
  425. package/src/runtime/foundation/service-wire-codec.ts +15 -8
  426. package/src/runtime/foundation/service-wire-constants.generated.ts +1 -0
  427. package/src/runtime/foundation/service-wire-m6a-codec.ts +29 -15
  428. package/src/runtime/framework-errors-internal.ts +380 -134
  429. package/src/runtime/handlers/handler-instance-scope.ts +68 -95
  430. package/src/runtime/host/actor-packet-relay.ts +57 -147
  431. package/src/runtime/host/actor-placement-coordinator.ts +8 -5
  432. package/src/runtime/host/actor-runtime-options-factory.ts +27 -8
  433. package/src/runtime/host/actor-transfer-runtime.ts +180 -260
  434. package/src/runtime/host/application-job-queue.ts +28 -34
  435. package/src/runtime/host/bound-session-relay.ts +1 -2
  436. package/src/runtime/host/channel-runtime-options-factory.ts +1 -2
  437. package/src/runtime/host/index.ts +327 -296
  438. package/src/runtime/host/instance-activation-authority.ts +89 -109
  439. package/src/runtime/host/location-runtime-owner.ts +4 -2
  440. package/src/runtime/host/remote-actor-join-receiver.ts +3 -31
  441. package/src/runtime/host/remote-actor-packet-target-store.ts +17 -58
  442. package/src/runtime/host/remote-bound-session-relay.ts +8 -41
  443. package/src/runtime/host/route-mesh-runtime.ts +228 -271
  444. package/src/runtime/host/runtime-shutdown.ts +17 -21
  445. package/src/runtime/host/service-relocation-control.ts +14 -1
  446. package/src/runtime/host/service-relocation-host-runtime.ts +699 -561
  447. package/src/runtime/host/spot-address-transport.ts +73 -195
  448. package/src/runtime/host/spot-node-runtime-options-factory.ts +6 -3
  449. package/src/runtime/host/spot-runtime-options-factory.ts +73 -22
  450. package/src/runtime/host/user-spot-creation-coordinator.ts +36 -22
  451. package/src/runtime/locations/aggregate-inventory-store.ts +16 -13
  452. package/src/runtime/locations/authority-key-codec.ts +7 -3
  453. package/src/runtime/locations/auto-connect-reconciler.ts +39 -26
  454. package/src/runtime/locations/creation-operation-id.ts +6 -3
  455. package/src/runtime/locations/domain-store-contract.ts +12 -3
  456. package/src/runtime/locations/in-memory-authority-store.ts +44 -15
  457. package/src/runtime/locations/in-memory-location-store.ts +50 -39
  458. package/src/runtime/locations/in-memory-provider-location-store.ts +100 -25
  459. package/src/runtime/locations/key-codec.ts +3 -2
  460. package/src/runtime/locations/lease-tracker.ts +8 -14
  461. package/src/runtime/locations/lifecycle.ts +13 -43
  462. package/src/runtime/locations/location-store-failure.ts +4 -0
  463. package/src/runtime/locations/location-store-pages.ts +18 -0
  464. package/src/runtime/locations/location-store-repository.ts +450 -478
  465. package/src/runtime/locations/relocation-blob.ts +17 -6
  466. package/src/runtime/locations/resolvers.ts +75 -49
  467. package/src/runtime/locations/runtime.ts +220 -110
  468. package/src/runtime/locations/spot-location-claims.ts +58 -1
  469. package/src/runtime/messaging/payload-codec.ts +35 -24
  470. package/src/runtime/messaging/submission-result.ts +57 -1
  471. package/src/runtime/protocol/service_wire_codec.generated.ts +18 -8
  472. package/src/runtime/protocol/service_wire_pilot_codec.generated.ts +1 -1
  473. package/src/runtime/spots/formal-remote-actor-transfer-registry.ts +4 -1
  474. package/src/runtime/spots/index.ts +433 -229
  475. package/src/runtime/spots/spot-activation-registry.ts +30 -69
  476. package/src/runtime/spots/spot-activation-state.ts +2 -2
  477. package/src/runtime/spots/spot-activation.ts +67 -37
  478. package/src/runtime/spots/spot-actor-admission-coordinator.ts +5 -57
  479. package/src/runtime/spots/spot-actor-join-dispatch.ts +24 -77
  480. package/src/runtime/spots/spot-actor-membership.ts +40 -72
  481. package/src/runtime/spots/spot-actor-packet-dispatch.ts +0 -16
  482. package/src/runtime/spots/spot-actor-packet-relay-dispatch.ts +3 -15
  483. package/src/runtime/spots/spot-context.ts +3 -3
  484. package/src/runtime/spots/spot-entry-activation.ts +13 -30
  485. package/src/runtime/spots/spot-lifecycle-metrics.ts +3 -2
  486. package/src/runtime/spots/spot-manager-public.ts +21 -17
  487. package/src/runtime/spots/spot-node-autoconnect.ts +20 -26
  488. package/src/runtime/spots/spot-node-runtime-manager.ts +136 -125
  489. package/src/runtime/spots/spot-outbound.ts +45 -23
  490. package/src/runtime/spots/spot-remote-codec.ts +7 -3
  491. package/src/runtime/spots/spot-route-packet-dispatch.ts +25 -24
  492. package/src/runtime/spots/spot-route-replies.ts +6 -4
  493. package/src/runtime/spots/spot-routed-actor-admission.ts +13 -26
  494. package/src/runtime/spots/spot-routed-frame-dispatch.ts +2 -3
  495. package/src/runtime/spots/spot-routed-spot-packet-dispatch.ts +95 -22
  496. package/src/runtime/spots/spot-runtime-ports.ts +5 -27
  497. package/src/runtime/spots/spot-serial-executor.ts +2 -2
  498. package/src/runtime/spots/spot-serial-turn-executor.ts +112 -11
  499. package/src/runtime/spots/spot-timer.ts +3 -2
  500. package/src/runtime/streams/actor-session-binding-registry.ts +179 -269
  501. package/src/runtime/streams/actor-session-binding-runtime-owner.ts +0 -8
  502. package/src/runtime/streams/bound-actor-relay-sender.ts +89 -43
  503. package/src/runtime/streams/bound-session-service.ts +21 -1
  504. package/src/runtime/streams/index.ts +76 -64
  505. package/src/runtime/streams/managed-stream.ts +29 -10
  506. package/src/runtime/streams/native-fallback-bound-session.ts +1 -3
  507. package/src/runtime/streams/protocol.ts +34 -88
  508. package/src/runtime/streams/session-actor-coordinator.ts +17 -5
  509. package/src/runtime/streams/session-calls.ts +6 -5
  510. package/src/runtime/streams/session-context.ts +54 -10
  511. package/src/runtime/streams/session-requests.ts +2 -1
  512. package/src/runtime/streams/stream-binding-runtime-ports.ts +22 -1
  513. package/src/runtime/streams/stream-frame-factory.ts +2 -3
  514. package/src/runtime/streams/stream-session-runtime.ts +57 -59
  515. package/src/runtime/workers/index.ts +13 -12
  516. package/dist/runtime/actors/post-commit-actor-location.d.ts +0 -19
  517. package/dist/runtime/actors/post-commit-actor-location.js +0 -72
  518. package/dist/runtime/spots/spot-native-actor-join-admission.d.ts +0 -26
  519. package/dist/runtime/spots/spot-native-actor-join-admission.js +0 -106
  520. package/src/runtime/actors/post-commit-actor-location.ts +0 -121
  521. package/src/runtime/spots/spot-native-actor-join-admission.ts +0 -155
@@ -1,6 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ZLinkLocationRuntime = exports.ZLinkOwnerLeaseClaimError = exports.ZLinkOwnerCleanupError = void 0;
4
+ const location_store_pages_1 = require("./location-store-pages");
5
+ const runtime_metrics_1 = require("../diagnostics/runtime-metrics");
6
+ const Stores_1 = require("../../contracts/Locations/Stores");
4
7
  const Options_1 = require("../../contracts/Locations/Options");
5
8
  const EndpointNotation_1 = require("../../contracts/Configuration/EndpointNotation");
6
9
  const node_crypto_1 = require("node:crypto");
@@ -10,6 +13,7 @@ const authority_key_codec_1 = require("./authority-key-codec");
10
13
  const canonical_codec_1 = require("./canonical-codec");
11
14
  const key_codec_1 = require("./key-codec");
12
15
  const lease_tracker_1 = require("./lease-tracker");
16
+ const abort_1 = require("../abort");
13
17
  class ZLinkOwnerCleanupError extends Error {
14
18
  constructor(cause) {
15
19
  super(`Owner cleanup failed: ${errorMessage(cause)}`, { cause });
@@ -35,6 +39,7 @@ class ZLinkLocationRuntime {
35
39
  clearTimer;
36
40
  monotonicNowMs;
37
41
  liveRows;
42
+ leaseTracker;
38
43
  ownershipLostHandlers = new Set();
39
44
  ownerLeaseRenewedHandlers = new Set();
40
45
  ownerLeaseRenewalFailedHandlers = new Set();
@@ -74,13 +79,14 @@ class ZLinkLocationRuntime {
74
79
  runtimeOptions.setTimer ?? ((callback, delayMs) => setTimeout(callback, delayMs));
75
80
  this.clearTimer =
76
81
  runtimeOptions.clearTimer ?? ((handle) => clearTimeout(handle));
77
- const leaseTracker = runtimeOptions.leaseTracker ??
78
- new lease_tracker_1.ZLinkOwnerLeaseTracker({
79
- store: this.stores.ownerLeaseStore,
80
- options: this.options,
81
- monotonicNowMs: this.monotonicNowMs
82
- });
83
- this.liveRows = new lease_tracker_1.ZLinkLiveRowFilter(leaseTracker);
82
+ this.leaseTracker =
83
+ runtimeOptions.leaseTracker ??
84
+ new lease_tracker_1.ZLinkOwnerLeaseTracker({
85
+ store: this.stores.ownerLeaseStore,
86
+ options: this.options,
87
+ monotonicNowMs: this.monotonicNowMs
88
+ });
89
+ this.liveRows = new lease_tracker_1.ZLinkLiveRowFilter();
84
90
  }
85
91
  get isStarted() {
86
92
  return this.started;
@@ -145,7 +151,7 @@ class ZLinkLocationRuntime {
145
151
  let cursor;
146
152
  let expired = false;
147
153
  do {
148
- const page = await this.stores.authorityStore.listAuthorities('', cursor, 1000, signal);
154
+ const page = await this.stores.authorityStore.listAuthorities('', cursor, Stores_1.ZLINK_PROVIDER_MAX_PAGE_SIZE, signal);
149
155
  if (page.kind === 'scanExpired') {
150
156
  expired = true;
151
157
  break;
@@ -175,15 +181,17 @@ class ZLinkLocationRuntime {
175
181
  removeOwnerLeaseRenewalFailedHandler(handler) {
176
182
  this.ownerLeaseRenewalFailedHandlers.delete(handler);
177
183
  }
178
- async start(nodeRid, signal) {
184
+ async start(nodeRid, signal, shutdownSignal) {
179
185
  if (this.started) {
180
186
  return;
181
187
  }
182
188
  this.started = true;
183
189
  this.ownerCleanupComplete = false;
184
190
  this.nodeRidValue = nodeRid;
191
+ const claim = this.renewOwnerLeaseOnce(signal, shutdownSignal);
192
+ this.heartbeatRenewal = claim;
185
193
  try {
186
- const claimed = await this.renewOwnerLeaseOnce(signal);
194
+ const claimed = await claim;
187
195
  if (claimed) {
188
196
  this.scheduleHeartbeat();
189
197
  return;
@@ -194,13 +202,10 @@ class ZLinkLocationRuntime {
194
202
  catch (error) {
195
203
  this.started = false;
196
204
  this.ownerCleanupComplete = true;
197
- throw error;
205
+ throw signal?.aborted === true ? signal.reason : error;
198
206
  }
199
207
  }
200
208
  async stop(signal) {
201
- if (!this.started && this.ownerCleanupComplete) {
202
- return;
203
- }
204
209
  this.started = false;
205
210
  if (this.heartbeatTimer !== undefined) {
206
211
  this.clearTimer(this.heartbeatTimer);
@@ -208,10 +213,21 @@ class ZLinkLocationRuntime {
208
213
  }
209
214
  this.nextLeaseRenewAtMs = undefined;
210
215
  this.ownerLeaseDeadlineMs = undefined;
211
- await this.heartbeatRenewal;
212
216
  await this.cleanupOwner(signal);
213
217
  }
214
218
  async cleanupOwner(signal) {
219
+ const pending = this.heartbeatRenewal;
220
+ try {
221
+ await withTimeout(() => pending ?? Promise.resolve(), undefined, signal);
222
+ }
223
+ catch (error) {
224
+ if (!(0, abort_1.isAbortError)(error))
225
+ throw error;
226
+ }
227
+ finally {
228
+ if (this.heartbeatRenewal === pending)
229
+ this.heartbeatRenewal = undefined;
230
+ }
215
231
  if (this.ownerCleanupComplete) {
216
232
  return;
217
233
  }
@@ -221,11 +237,13 @@ class ZLinkLocationRuntime {
221
237
  ownerId: this.ownerId,
222
238
  leaseGeneration: 0n
223
239
  };
224
- await this.stores.locationStore.removeAllByOwner(owner, signal);
225
- const currentLease = await this.stores.ownerLeaseStore.readOwnerLease(this.ownerId, signal);
226
- if (currentLease.kind === 'found') {
227
- await this.stores.ownerLeaseStore.releaseOwnerLease(currentLease.token, signal);
228
- }
240
+ await withTimeout(async (cleanupSignal) => {
241
+ await this.stores.locationStore.removeAllByOwner(owner, cleanupSignal);
242
+ const currentLease = await this.stores.ownerLeaseStore.readOwnerLease(this.ownerId, cleanupSignal);
243
+ if (currentLease.kind === 'found') {
244
+ await this.stores.ownerLeaseStore.releaseOwnerLease(currentLease.token, cleanupSignal);
245
+ }
246
+ }, undefined, signal);
229
247
  this.ownerToken = undefined;
230
248
  this.lastOwnerToken = undefined;
231
249
  this.ownerCleanupComplete = true;
@@ -235,12 +253,12 @@ class ZLinkLocationRuntime {
235
253
  throw new ZLinkOwnerCleanupError(error);
236
254
  }
237
255
  }
238
- async renewOwnerLeaseOnce(signal) {
256
+ async renewOwnerLeaseOnce(signal, shutdownSignal) {
239
257
  if (!this.started) {
240
258
  return false;
241
259
  }
242
260
  if (this.ownerToken === undefined) {
243
- return await this.claimFreshOwnerLease(signal);
261
+ return await this.claimFreshOwnerLease(signal, shutdownSignal);
244
262
  }
245
263
  const wasOwnerLeaseUsable = this.ownerLeaseUsable;
246
264
  try {
@@ -261,7 +279,7 @@ class ZLinkLocationRuntime {
261
279
  // The store has already told us that this owner token cannot be
262
280
  // renewed. Claim immediately so descriptor recovery does not wait for
263
281
  // another heartbeat interval.
264
- return await this.claimFreshOwnerLease(signal);
282
+ return await this.claimFreshOwnerLease(signal, shutdownSignal);
265
283
  }
266
284
  this.ownerLeaseHealthy = true;
267
285
  this.ownerLeaseRenewedAt = result.storeNow;
@@ -283,12 +301,12 @@ class ZLinkLocationRuntime {
283
301
  return false;
284
302
  }
285
303
  }
286
- async claimFreshOwnerLease(signal) {
304
+ async claimFreshOwnerLease(signal, shutdownSignal) {
287
305
  const claimStartedAtMs = this.monotonicNowMs();
288
306
  const timeoutDeadline = performance.now() + this.options.ownerLeaseRenewTimeoutMs;
289
307
  let claim;
290
308
  try {
291
- claim = await this.claimOwnerLeaseWithConfirmation(timeoutDeadline, signal);
309
+ claim = await this.claimOwnerLeaseWithConfirmation(timeoutDeadline, signal, shutdownSignal);
292
310
  }
293
311
  catch (error) {
294
312
  if (signal?.aborted === true)
@@ -307,14 +325,7 @@ class ZLinkLocationRuntime {
307
325
  }
308
326
  try {
309
327
  if (!this.started) {
310
- // stop() may have completed while the Store claim was in flight. Do
311
- // not install a token into a stopped runtime or leave an orphan lease.
312
- try {
313
- await withTimeout((releaseSignal) => this.stores.ownerLeaseStore.releaseOwnerLease(claim.token, releaseSignal), remainingTimeoutMs(timeoutDeadline));
314
- }
315
- catch (error) {
316
- this.recordFailure(errorMessage(error), 'owner_lease_release');
317
- }
328
+ // stop owns confirmation and release under the host shutdown signal.
318
329
  return false;
319
330
  }
320
331
  this.lastOwnerToken = this.ownerToken;
@@ -340,16 +351,32 @@ class ZLinkLocationRuntime {
340
351
  return false;
341
352
  }
342
353
  }
343
- async claimOwnerLeaseWithConfirmation(timeoutDeadline, signal) {
354
+ async claimOwnerLeaseWithConfirmation(timeoutDeadline, signal, shutdownSignal) {
344
355
  signal?.throwIfAborted();
345
356
  let claim;
357
+ let request;
346
358
  try {
347
- claim = await withTimeout((claimSignal) => this.stores.ownerLeaseStore.claimOwnerLease(this.ownerId, this.options.ownerLeaseTtlMs, claimSignal), remainingTimeoutMs(timeoutDeadline), signal);
359
+ claim = await withTimeout((claimSignal) => (request = this.stores.ownerLeaseStore.claimOwnerLease(this.ownerId, this.options.ownerLeaseTtlMs, claimSignal)), remainingTimeoutMs(timeoutDeadline), signal);
348
360
  }
349
361
  catch (error) {
350
362
  if (error instanceof OwnerLeaseRenewTimeoutError)
351
363
  throw error;
352
- const confirmed = await this.confirmOwnerLease(error, timeoutDeadline, signal);
364
+ if (signal?.aborted === true && request !== undefined) {
365
+ const cleanupSignal = shutdownSignal?.();
366
+ try {
367
+ await withTimeout(() => request, cleanupSignal === undefined ? remainingTimeoutMs(timeoutDeadline) : undefined, cleanupSignal);
368
+ }
369
+ catch (completionError) {
370
+ if (cleanupSignal?.aborted === true ||
371
+ completionError instanceof OwnerLeaseRenewTimeoutError) {
372
+ throw new ZLinkOwnerCleanupError(completionError);
373
+ }
374
+ if (!(0, abort_1.isAbortError)(completionError)) {
375
+ this.recordFailure(errorMessage(completionError), 'owner_lease_claim');
376
+ }
377
+ }
378
+ }
379
+ const confirmed = await this.confirmOwnerLease(error, timeoutDeadline, signal, shutdownSignal);
353
380
  if (confirmed !== undefined)
354
381
  return confirmed;
355
382
  throw error;
@@ -357,29 +384,34 @@ class ZLinkLocationRuntime {
357
384
  if (claim.kind !== 'conflict')
358
385
  return claim;
359
386
  const conflict = new ZLinkOwnerLeaseClaimError(claim.kind);
360
- return (await this.confirmOwnerLease(conflict, timeoutDeadline, signal)) ?? claim;
387
+ return ((await this.confirmOwnerLease(conflict, timeoutDeadline, signal, shutdownSignal)) ?? claim);
361
388
  }
362
- async confirmOwnerLease(originalError, timeoutDeadline, signal) {
363
- const confirmationTimeoutMs = remainingTimeoutMs(timeoutDeadline);
364
- if (confirmationTimeoutMs <= 0)
389
+ async confirmOwnerLease(originalError, timeoutDeadline, signal, shutdownSignal) {
390
+ const cancelled = signal?.aborted === true;
391
+ const cleanupSignal = cancelled ? shutdownSignal?.() : undefined;
392
+ const confirmationTimeoutMs = cleanupSignal === undefined ? remainingTimeoutMs(timeoutDeadline) : undefined;
393
+ if (confirmationTimeoutMs !== undefined && confirmationTimeoutMs <= 0)
365
394
  throw originalError;
366
395
  let confirmed;
367
396
  try {
368
- confirmed = await withTimeout((readSignal) => this.stores.ownerLeaseStore.readOwnerLease(this.ownerId, readSignal), confirmationTimeoutMs);
397
+ confirmed = await withTimeout((readSignal) => this.stores.ownerLeaseStore.readOwnerLease(this.ownerId, readSignal), confirmationTimeoutMs, cleanupSignal);
369
398
  }
370
399
  catch (confirmationError) {
371
400
  this.recordFailure(errorMessage(confirmationError), 'owner_lease_claim_confirmation');
372
- throw originalError;
401
+ if (cancelled)
402
+ throw new ZLinkOwnerCleanupError(confirmationError);
403
+ throw confirmationError;
373
404
  }
374
405
  if (confirmed.kind !== 'found' || confirmed.token.ownerId !== this.ownerId) {
375
406
  throw originalError;
376
407
  }
377
408
  if (signal?.aborted === true) {
378
409
  try {
379
- await withTimeout((releaseSignal) => this.stores.ownerLeaseStore.releaseOwnerLease(confirmed.token, releaseSignal), remainingTimeoutMs(timeoutDeadline));
410
+ await withTimeout((releaseSignal) => this.stores.ownerLeaseStore.releaseOwnerLease(confirmed.token, releaseSignal), cleanupSignal === undefined ? remainingTimeoutMs(timeoutDeadline) : undefined, cleanupSignal);
380
411
  }
381
412
  catch (releaseError) {
382
413
  this.recordFailure(errorMessage(releaseError), 'owner_lease_release');
414
+ throw new ZLinkOwnerCleanupError(releaseError);
383
415
  }
384
416
  throw originalError;
385
417
  }
@@ -562,7 +594,7 @@ class ZLinkLocationRuntime {
562
594
  }
563
595
  async listPeerLocations(filter, signal) {
564
596
  const rows = await this.stores.peerStore.listPeers(filter, signal);
565
- const live = await this.filterLive(rows, (row) => row.ownerId, signal);
597
+ const live = await this.liveRows.filter(rows, (row, signal) => this.leaseTracker.isOwnerLive(row.ownerId, signal), signal);
566
598
  // Location Store rows may have been written before this process adopted
567
599
  // the endpoint-notation policy, or by another language/version's writer.
568
600
  // Normalize on read so every comparison downstream sees the canonical
@@ -570,13 +602,13 @@ class ZLinkLocationRuntime {
570
602
  return live.map((row) => ({ ...row, endpoint: (0, EndpointNotation_1.normalizeEndpoint)(row.endpoint) }));
571
603
  }
572
604
  async listLiveMeshNodes(meshName, signal) {
573
- const rows = (await this.stores.locationStore.listMeshNodes(meshName, undefined, signal)).items;
574
- const live = await this.filterLive(rows, (row) => row.ownerId, signal);
605
+ const rows = await (0, location_store_pages_1.listAllMeshNodeDescriptors)(this.stores.locationStore, meshName, signal);
606
+ const live = await this.liveRows.filter(rows, (row, signal) => this.leaseTracker.isOwnerTokenLive(row, signal), signal);
575
607
  return live.map((row) => ({ ...row, endpoint: (0, EndpointNotation_1.normalizeEndpoint)(row.endpoint) }));
576
608
  }
577
609
  async listMeshNodeDescriptors(meshName, page, signal) {
578
610
  const rows = await this.stores.locationStore.listMeshNodes(meshName, this.pageRequest(page), signal);
579
- const live = await this.filterLive(rows.items, (row) => row.ownerId, signal);
611
+ const live = await this.liveRows.filter(rows.items, (row, signal) => this.leaseTracker.isOwnerTokenLive(row, signal), signal);
580
612
  return {
581
613
  items: live.map((row) => ({ ...row, endpoint: (0, EndpointNotation_1.normalizeEndpoint)(row.endpoint) })),
582
614
  continuationToken: rows.continuationToken
@@ -589,7 +621,7 @@ class ZLinkLocationRuntime {
589
621
  }
590
622
  const rows = await queryStore.listSpots(filter, this.pageRequest(page), signal);
591
623
  return {
592
- items: await this.filterLive(rows.items, (row) => row.ownerId, signal),
624
+ items: await this.liveRows.filter(rows.items, (row, signal) => this.leaseTracker.isOwnerTokenLive(row, signal), signal),
593
625
  continuationToken: rows.continuationToken
594
626
  };
595
627
  }
@@ -600,13 +632,13 @@ class ZLinkLocationRuntime {
600
632
  }
601
633
  const rows = await queryStore.listActors(filter, this.pageRequest(page), signal);
602
634
  return {
603
- items: await this.filterLive(rows.items, (row) => row.ownerId, signal),
635
+ items: await this.liveRows.filter(rows.items, (row, signal) => this.leaseTracker.isOwnerTokenLive(row, signal), signal),
604
636
  continuationToken: rows.continuationToken
605
637
  };
606
638
  }
607
639
  async listObjectLocations(filter, page = {}, signal) {
608
640
  const normalizedPage = this.pageRequest(page);
609
- const pageSize = normalizedPage.pageSize ?? this.options.listPageSize;
641
+ const pageSize = normalizedPage.pageSize;
610
642
  const requestedCursor = normalizedPage.continuationToken;
611
643
  let cursor = requestedCursor === undefined ? undefined : Authority_1.ZLinkAuthorityScanCursor.from(requestedCursor);
612
644
  const items = [];
@@ -624,7 +656,10 @@ class ZLinkLocationRuntime {
624
656
  (filter.stableType !== undefined && allocation.stableType !== filter.stableType) ||
625
657
  (filter.meshName !== undefined && allocation.descriptor.meshName !== filter.meshName))
626
658
  continue;
627
- const live = (await this.liveRows.resolve(entry, (candidate) => candidate.snapshot.ownerId, signal)) !== undefined;
659
+ const live = (await this.liveRows.resolve(entry, (candidate, signal) => this.leaseTracker.isOwnerTokenLive({
660
+ ownerId: candidate.snapshot.ownerId,
661
+ leaseGeneration: candidate.snapshot.ownerLeaseGeneration
662
+ }, signal), signal)) !== undefined;
628
663
  items.push(this.objectLocationEntry(identity.globalId, entry.snapshot, live));
629
664
  if (items.length >= pageSize)
630
665
  break;
@@ -646,14 +681,14 @@ class ZLinkLocationRuntime {
646
681
  const found = await this.stores.authorityStore.readAuthority((0, authority_key_codec_1.encodeAuthorityKey)('user_spot', String(spotId)), signal);
647
682
  if (found.kind === 'missing' || found.allocation.objectKind === 'actor')
648
683
  return undefined;
649
- const live = (await this.liveRows.resolve(found, (snapshot) => snapshot.ownerId, signal)) !== undefined;
684
+ const live = (await this.liveRows.resolve(found, (snapshot, signal) => this.leaseTracker.isOwnerTokenLive({ ownerId: snapshot.ownerId, leaseGeneration: snapshot.ownerLeaseGeneration }, signal), signal)) !== undefined;
650
685
  return this.objectLocationEntry(String(spotId), found, live);
651
686
  }
652
687
  async findObjectLocation(kind, globalId, signal) {
653
688
  const found = await this.stores.authorityStore.readAuthority((0, authority_key_codec_1.encodeAuthorityKey)(kind, globalId), signal);
654
689
  if (found.kind === 'missing' || found.allocation.objectKind !== kind)
655
690
  return undefined;
656
- const live = (await this.liveRows.resolve(found, (snapshot) => snapshot.ownerId, signal)) !== undefined;
691
+ const live = (await this.liveRows.resolve(found, (snapshot, signal) => this.leaseTracker.isOwnerTokenLive({ ownerId: snapshot.ownerId, leaseGeneration: snapshot.ownerLeaseGeneration }, signal), signal)) !== undefined;
657
692
  return this.objectLocationEntry(globalId, found, live);
658
693
  }
659
694
  objectLocationEntry(globalId, snapshot, ownerLive) {
@@ -670,15 +705,15 @@ class ZLinkLocationRuntime {
670
705
  async listRouteLocations(filter, page, signal) {
671
706
  const rows = await this.stores.routeStore.listRoutes(filter, this.pageRequest(page), signal);
672
707
  return {
673
- items: await this.filterLive(rows.items, (row) => row.ownerId, signal),
708
+ items: await this.liveRows.filter(rows.items, (row, signal) => this.leaseTracker.isOwnerLive(row.ownerId, signal), signal),
674
709
  continuationToken: rows.continuationToken
675
710
  };
676
711
  }
677
712
  async listTopology(filter, page, signal) {
678
713
  const entries = [];
679
714
  for (const meshName of this.meshNamesOf(filter.meshName)) {
680
- for (const descriptor of await this.listAllMeshNodeDescriptors(meshName, signal)) {
681
- const live = (await this.filterLive([descriptor], (row) => row.ownerId, signal)).length > 0;
715
+ for (const descriptor of await (0, location_store_pages_1.listAllMeshNodeDescriptors)(this.stores.locationStore, meshName, signal, this.options.listPageSize)) {
716
+ const live = await this.leaseTracker.isOwnerTokenLive(descriptor, signal);
682
717
  const entry = {
683
718
  meshName: descriptor.meshName,
684
719
  nodeRid: descriptor.rid,
@@ -702,22 +737,23 @@ class ZLinkLocationRuntime {
702
737
  return this.pageInMemory(entries, page);
703
738
  }
704
739
  pageRequest(page) {
705
- return page?.pageSize === undefined ? { ...page, pageSize: this.options.listPageSize } : page;
740
+ return page?.pageSize === undefined
741
+ ? { ...page, pageSize: this.options.listPageSize }
742
+ : page;
706
743
  }
707
744
  async listServiceSummaries(filter, page, signal) {
708
745
  const summaries = [];
709
746
  for (const meshName of this.meshNamesOf(filter.meshName)) {
710
- const descriptors = await this.listAllMeshNodeDescriptors(meshName, signal);
747
+ const descriptors = await (0, location_store_pages_1.listAllMeshNodeDescriptors)(this.stores.locationStore, meshName, signal, this.options.listPageSize);
711
748
  if (descriptors.length === 0)
712
749
  continue;
713
- const live = await this.filterLive(descriptors, (row) => row.ownerId, signal);
714
- const liveOwners = new Set(live.map((row) => row.ownerId));
750
+ const live = await this.liveRows.filter(descriptors, (row, signal) => this.leaseTracker.isOwnerTokenLive(row, signal), signal);
715
751
  summaries.push({
716
752
  meshName,
717
753
  totalCount: descriptors.length,
718
- readyCount: descriptors.filter((row) => liveOwners.has(row.ownerId)).length,
754
+ readyCount: live.length,
719
755
  errorCount: 0,
720
- stoppedCount: descriptors.filter((row) => !liveOwners.has(row.ownerId)).length,
756
+ stoppedCount: descriptors.length - live.length,
721
757
  lastUpdatedAt: descriptors.reduce((latest, row) => (row.updatedAt > latest ? row.updatedAt : latest), descriptors[0].updatedAt)
722
758
  });
723
759
  }
@@ -726,21 +762,11 @@ class ZLinkLocationRuntime {
726
762
  meshNamesOf(meshName) {
727
763
  return meshName === undefined ? this.meshNames : [meshName];
728
764
  }
729
- async listAllMeshNodeDescriptors(meshName, signal) {
730
- const rows = [];
731
- let continuationToken;
732
- do {
733
- const result = await this.stores.locationStore.listMeshNodes(meshName, { pageSize: this.options.listPageSize, continuationToken }, signal);
734
- rows.push(...result.items);
735
- continuationToken = result.continuationToken;
736
- } while (continuationToken !== undefined);
737
- return rows;
738
- }
739
765
  pageInMemory(entries, page) {
740
766
  const normalized = this.pageRequest(page);
741
767
  const parsedOffset = Number.parseInt(normalized.continuationToken ?? '0', 10);
742
768
  const offset = Number.isFinite(parsedOffset) && parsedOffset >= 0 ? parsedOffset : 0;
743
- const pageSize = normalized.pageSize ?? this.options.listPageSize;
769
+ const pageSize = normalized.pageSize;
744
770
  const items = entries.slice(offset, offset + pageSize);
745
771
  const nextOffset = offset + items.length;
746
772
  return {
@@ -748,9 +774,6 @@ class ZLinkLocationRuntime {
748
774
  continuationToken: nextOffset < entries.length ? String(nextOffset) : undefined
749
775
  };
750
776
  }
751
- async filterLive(rows, ownerIdOf, signal) {
752
- return await this.liveRows.filter(rows, ownerIdOf, signal);
753
- }
754
777
  scheduleHeartbeat() {
755
778
  if (!this.started) {
756
779
  return;
@@ -759,11 +782,11 @@ class ZLinkLocationRuntime {
759
782
  const delayMs = Math.max(0, scheduledAt - this.monotonicNowMs());
760
783
  this.heartbeatTimer = this.setTimer(() => {
761
784
  this.heartbeatTimer = undefined;
762
- const lateness = Math.max(0, this.monotonicNowMs() - scheduledAt) / 1000;
785
+ const lateness = Math.max(0, this.monotonicNowMs() - scheduledAt) / runtime_metrics_1.MILLISECONDS_PER_SECOND;
763
786
  for (const scope of this.leaseScopes) {
764
787
  this.metrics?.recordOwnerLeaseRenewLateness(lateness, scope.kind, scope.name);
765
788
  }
766
- this.nextLeaseRenewAtMs = scheduledAt + this.options.ownerLeaseRenewIntervalMs;
789
+ this.nextLeaseRenewAtMs = this.monotonicNowMs() + this.options.ownerLeaseRenewIntervalMs;
767
790
  if (this.ownerLeaseDeadlineMs !== undefined &&
768
791
  this.monotonicNowMs() >= this.ownerLeaseDeadlineMs) {
769
792
  this.ownerLeaseHealthy = false;
@@ -838,20 +861,24 @@ class ZLinkLocationRuntime {
838
861
  }
839
862
  exports.ZLinkLocationRuntime = ZLinkLocationRuntime;
840
863
  async function withTimeout(action, timeoutMs, signal) {
841
- const timeoutController = new AbortController();
864
+ const timeoutController = timeoutMs === undefined ? undefined : new AbortController();
842
865
  const operationSignal = signal === undefined
843
- ? timeoutController.signal
844
- : AbortSignal.any([signal, timeoutController.signal]);
866
+ ? timeoutController?.signal
867
+ : timeoutController === undefined
868
+ ? signal
869
+ : AbortSignal.any([signal, timeoutController.signal]);
845
870
  let timeout;
846
871
  let abort;
847
- const deadline = new Promise((_resolve, reject) => {
848
- timeout = setTimeout(() => {
849
- const error = new OwnerLeaseRenewTimeoutError(timeoutMs);
850
- timeoutController.abort(error);
851
- reject(error);
852
- }, timeoutMs);
853
- timeout.unref();
854
- });
872
+ const deadline = timeoutMs === undefined
873
+ ? undefined
874
+ : new Promise((_resolve, reject) => {
875
+ timeout = setTimeout(() => {
876
+ const error = new OwnerLeaseRenewTimeoutError(timeoutMs);
877
+ timeoutController.abort(error);
878
+ reject(error);
879
+ }, timeoutMs);
880
+ timeout.unref();
881
+ });
855
882
  const cancellation = signal === undefined
856
883
  ? undefined
857
884
  : new Promise((_resolve, reject) => {
@@ -860,9 +887,13 @@ async function withTimeout(action, timeoutMs, signal) {
860
887
  });
861
888
  try {
862
889
  signal?.throwIfAborted();
863
- return await Promise.race(cancellation === undefined
864
- ? [action(operationSignal), deadline]
865
- : [action(operationSignal), deadline, cancellation]);
890
+ const operation = action(operationSignal);
891
+ if (deadline === undefined) {
892
+ return cancellation === undefined
893
+ ? await operation
894
+ : await Promise.race([operation, cancellation]);
895
+ }
896
+ return await Promise.race(cancellation === undefined ? [operation, deadline] : [operation, deadline, cancellation]);
866
897
  }
867
898
  finally {
868
899
  if (timeout !== undefined)
@@ -1,4 +1,5 @@
1
1
  import type { RoutingId } from '../../contracts/Common';
2
+ import type { ZLinkAuthoritySnapshot } from './internal-location-contracts';
2
3
  import { ZLinkLocationWriteStatus } from './internal-location-contracts';
3
4
  import { ZLinkSpotKind } from '../../contracts/Spots';
4
5
  import type { IZLinkLocationLifecycleRuntime, ZLinkOwnershipLostEvent } from './lifecycle-runtime';
@@ -33,4 +34,9 @@ export interface ZLinkTrackedInstanceAuthority {
33
34
  }
34
35
  export interface ZLinkInstanceClosingAuthority {
35
36
  release(): Promise<void>;
37
+ reincarnate?(initialize: (authority: ZLinkAuthoritySnapshot & {
38
+ readonly stableType: string;
39
+ }) => Promise<void>): Promise<ZLinkAuthoritySnapshot & {
40
+ readonly stableType: string;
41
+ }>;
36
42
  }
@@ -118,7 +118,48 @@ class ZLinkSpotLocationClaims {
118
118
  tracked.storeVersion = result.storeVersion.value;
119
119
  onCommitted();
120
120
  return {
121
- release: async () => undefined
121
+ release: () => this.release(meshName, spotId),
122
+ reincarnate: async (initialize) => {
123
+ const reincarnated = await store.compareExchangeAuthority(key, result.storeVersion, {
124
+ kind: 'put',
125
+ generationTransition: 'reincarnate',
126
+ payload: (0, service_relocation_runtime_1.replaceServiceRelocationAuthorityApplicationPayload)(result.payload, (0, service_authority_payload_codec_1.encodeServiceInstanceAuthorityPayload)({ ...decoded, state: 'coldActivating' }))
127
+ });
128
+ if (reincarnated.kind !== 'stored') {
129
+ throw (0, framework_errors_internal_1.createInternalFrameworkException)(reincarnated.kind === 'generationExhausted'
130
+ ? framework_errors_internal_1.ZLinkFrameworkInternalErrorKind.InvalidOperation
131
+ : framework_errors_internal_1.ZLinkFrameworkInternalErrorKind.SpotMoving, `Instance Spot '${String(spotId)}' Closing authority changed before reincarnation.`);
132
+ }
133
+ this.trackInstanceAuthority({
134
+ ...tracked,
135
+ objectGeneration: reincarnated.objectGeneration,
136
+ authorityOwnerGeneration: reincarnated.authorityOwnerGeneration,
137
+ storeVersion: reincarnated.storeVersion.value
138
+ });
139
+ this.invalidateSpotRoute?.(spotId);
140
+ try {
141
+ await initialize({ ...reincarnated, kind: 'snapshot', stableType: tracked.stableType });
142
+ const ready = await store.compareExchangeAuthority(key, reincarnated.storeVersion, {
143
+ kind: 'put',
144
+ generationTransition: 'preserve',
145
+ payload: (0, service_relocation_runtime_1.replaceServiceRelocationAuthorityApplicationPayload)(reincarnated.payload, (0, service_authority_payload_codec_1.encodeServiceInstanceAuthorityPayload)({ ...decoded, state: 'ready' }))
146
+ });
147
+ if (ready.kind !== 'stored') {
148
+ throw (0, framework_errors_internal_1.createInternalFrameworkException)(ready.kind === 'generationExhausted'
149
+ ? framework_errors_internal_1.ZLinkFrameworkInternalErrorKind.InvalidOperation
150
+ : framework_errors_internal_1.ZLinkFrameworkInternalErrorKind.SpotMoving, `Instance Spot '${String(spotId)}' reincarnation authority changed before initialization completed.`);
151
+ }
152
+ const latest = this.spots.get(canonical);
153
+ if (latest?.kind === 'authority' && latest.objectGeneration === ready.objectGeneration) {
154
+ latest.storeVersion = ready.storeVersion.value;
155
+ }
156
+ return { ...ready, kind: 'snapshot', stableType: tracked.stableType };
157
+ }
158
+ catch (error) {
159
+ await this.release(meshName, spotId, reincarnated.objectGeneration);
160
+ throw error;
161
+ }
162
+ }
122
163
  };
123
164
  }
124
165
  onOwnershipLost(event) {
@@ -9,6 +9,7 @@ exports.wrapFrameworkPayloadMessage = wrapFrameworkPayloadMessage;
9
9
  exports.selectDefaultSerializer = selectDefaultSerializer;
10
10
  exports.selectSerializer = selectSerializer;
11
11
  exports.selectSerializerWithContentType = selectSerializerWithContentType;
12
+ const stream_wire_1 = require("@zlink-systems/stream-wire");
12
13
  const framework_errors_internal_1 = require("../framework-errors-internal");
13
14
  const runtime_message_1 = require("../backend/runtime-message");
14
15
  const contracts_1 = require("../../contracts");
@@ -20,8 +21,11 @@ const Attributes_1 = require("../../contracts/Handlers/Attributes");
20
21
  const packet_name_1 = require("./packet-name");
21
22
  const CodecContentType_1 = require("../../contracts/Configuration/CodecContentType");
22
23
  const CodecSerializerSelection_1 = require("../../contracts/Configuration/CodecSerializerSelection");
24
+ const MAX_DECLARED_TYPE_SELECTIONS = 1024;
23
25
  const noSerializer = Symbol('noSerializer');
24
- const JSON_CONTENT_TYPE = 'application/json';
26
+ const JSON_CONTENT_TYPE = stream_wire_1.ZlinkStreamContentType.Json;
27
+ const frameworkJsonReceiveCodec = Symbol('frameworkJsonReceiveCodec');
28
+ const defaultReceiveCodecs = new Map([[JSON_CONTENT_TYPE, frameworkJsonReceiveCodec]]);
25
29
  // Registration maps are created during host configuration and are immutable
26
30
  // for the runtime lifetime. Compile the candidate list and reverse content
27
31
  // type lookup once per map so the message path does not allocate arrays or
@@ -36,8 +40,8 @@ function encodeFrameworkPayload(payload, registry, packetName, contractPart = 'p
36
40
  if ((0, contracts_1.isZLinkMessage)(payload)) {
37
41
  if (payload.isEncoded()) {
38
42
  return {
39
- message: rememberContentType(toRuntimeMessage(payload.toEncodedPayload()), 'application/octet-stream'),
40
- contentType: 'application/octet-stream'
43
+ message: rememberContentType(toRuntimeMessage(payload.toEncodedPayload()), stream_wire_1.ZlinkStreamContentType.Raw),
44
+ contentType: stream_wire_1.ZlinkStreamContentType.Raw
41
45
  };
42
46
  }
43
47
  declaredType = (0, ZLinkMessage_1.readZLinkMessageDeclaredType)(payload);
@@ -72,16 +76,11 @@ function decodeFrameworkTypedPayloadMessage(message, registry, type, contentType
72
76
  return decodeFrameworkPayload(message, registry, type, contentType, packetName, contractPart);
73
77
  }
74
78
  function decodeFrameworkPayload(message, registry, type, contentType, packetName, contractPart) {
75
- if (!(0, CodecContentType_1.isCanonicalCodecContentType)(contentType)) {
76
- throw unsupportedContentType(contentType);
77
- }
78
- if (contentType !== JSON_CONTENT_TYPE) {
79
- const serializer = serializerMapOf(registry)?.get(contentType);
80
- if (serializer === undefined)
81
- throw unsupportedContentType(contentType);
79
+ const codec = receiveCodecFor(contentType, registry);
80
+ if (codec !== frameworkJsonReceiveCodec) {
82
81
  if (message.isEmpty())
83
82
  return undefined;
84
- return serializer.deserialize(encodedPayloadFromOwned(message.data()), (type ?? Object));
83
+ return codec.deserialize(encodedPayloadFromOwned(message.data()), (type ?? Object));
85
84
  }
86
85
  if (message.isEmpty())
87
86
  return undefined;
@@ -96,16 +95,11 @@ function wrapFrameworkPayloadMessage(message, registry, contentType = JSON_CONTE
96
95
  return (0, ZLinkMessage_1.createZLinkMessageFromEncoded)(payload, (type) => decodeFrameworkEncodedPayload(payload, registry, type, contentType, packetName, contractPart));
97
96
  }
98
97
  function decodeFrameworkEncodedPayload(payload, registry, type, contentType, packetName, contractPart) {
99
- if (!(0, CodecContentType_1.isCanonicalCodecContentType)(contentType)) {
100
- throw unsupportedContentType(contentType);
101
- }
102
- if (contentType !== JSON_CONTENT_TYPE) {
103
- const serializer = serializerMapOf(registry)?.get(contentType);
104
- if (serializer === undefined)
105
- throw unsupportedContentType(contentType);
98
+ const codec = receiveCodecFor(contentType, registry);
99
+ if (codec !== frameworkJsonReceiveCodec) {
106
100
  if (payload.isEmpty())
107
101
  return undefined;
108
- return serializer.deserialize(payload, (type ?? Object));
102
+ return codec.deserialize(payload, (type ?? Object));
109
103
  }
110
104
  if (payload.isEmpty())
111
105
  return undefined;
@@ -117,6 +111,18 @@ function decodeFrameworkEncodedPayload(payload, registry, type, contentType, pac
117
111
  throw (0, framework_errors_internal_1.createInternalFrameworkException)(framework_errors_internal_1.ZLinkFrameworkInternalErrorKind.PayloadDecodeFailed, 'PayloadDecodeFailed: framework payload is not valid JSON.', false, error);
118
112
  }
119
113
  }
114
+ function receiveCodecFor(contentType, registry) {
115
+ if (!(0, CodecContentType_1.isCanonicalCodecContentType)(contentType)) {
116
+ throw unsupportedContentType(contentType);
117
+ }
118
+ const registeredCodec = serializerMapOf(registry)?.get(contentType);
119
+ if (registeredCodec !== undefined)
120
+ return registeredCodec;
121
+ const defaultCodec = defaultReceiveCodecs.get(contentType);
122
+ if (defaultCodec !== undefined)
123
+ return defaultCodec;
124
+ throw unsupportedContentType(contentType);
125
+ }
120
126
  function schemaForDecode(type, packetName, contractPart) {
121
127
  const contract = type === undefined ? undefined : (0, packet_name_1.readFrameworkPacketJsonContract)(type, packetName);
122
128
  return (contract ??
@@ -167,7 +173,7 @@ function serializerSelectionPlanOf(registry) {
167
173
  return cached === noSerializer ? undefined : cached;
168
174
  }
169
175
  const selected = selectSerializerFromEntries(frozenEntries, declaredType);
170
- if (cachedBusinessTypeCount < 1024) {
176
+ if (cachedBusinessTypeCount < MAX_DECLARED_TYPE_SELECTIONS) {
171
177
  outboundByBusinessType.set(declaredType, selected ?? noSerializer);
172
178
  cachedBusinessTypeCount += 1;
173
179
  }