@zlink-systems/framework 0.30.3 → 0.32.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 (398) hide show
  1. package/dist/.tsbuildinfo +1 -1
  2. package/dist/contracts/Actors/ZLinkActor.d.ts +2 -0
  3. package/dist/contracts/Actors/ZLinkSessionBindingIdentity.d.ts +6 -0
  4. package/dist/contracts/Actors/ZLinkSessionBindingIdentity.js +2 -0
  5. package/dist/contracts/Actors/index.d.ts +1 -0
  6. package/dist/contracts/Actors/index.js +1 -0
  7. package/dist/contracts/Common/CoreTypes.d.ts +1 -0
  8. package/dist/contracts/Common/HandlerMessageType.d.ts +8 -0
  9. package/dist/contracts/Common/HandlerMessageType.js +41 -0
  10. package/dist/contracts/Common/ZLinkEncodedPayload.d.ts +1 -1
  11. package/dist/contracts/Common/ZLinkEncodedPayload.js +12 -20
  12. package/dist/contracts/Common/ZLinkMessage.js +11 -7
  13. package/dist/contracts/Common/encoded-payload-storage.d.ts +0 -2
  14. package/dist/contracts/Common/encoded-payload-storage.js +4 -16
  15. package/dist/contracts/Common/index.d.ts +1 -1
  16. package/dist/contracts/Common/payload-slab.d.ts +4 -0
  17. package/dist/contracts/Common/payload-slab.js +30 -0
  18. package/dist/contracts/Configuration/RegistrationBuilders.js +15 -9
  19. package/dist/contracts/Configuration/RegistrationTypes.d.ts +19 -0
  20. package/dist/contracts/Handlers/Contexts.d.ts +1 -0
  21. package/dist/contracts/Locations/Authority.d.ts +2 -0
  22. package/dist/internal.d.ts +9 -0
  23. package/dist/internal.js +23 -1
  24. package/dist/nest-integration.d.ts +1 -0
  25. package/dist/nest-integration.js +3 -1
  26. package/dist/runtime/actors/actor-client.d.ts +6 -2
  27. package/dist/runtime/actors/actor-client.js +120 -82
  28. package/dist/runtime/actors/actor-context.js +16 -5
  29. package/dist/runtime/actors/actor-execution-context.js +2 -2
  30. package/dist/runtime/actors/actor-handoff.d.ts +12 -1
  31. package/dist/runtime/actors/actor-handoff.js +79 -34
  32. package/dist/runtime/actors/actor-join-deferred-scope.js +6 -6
  33. package/dist/runtime/actors/actor-local-native-join.d.ts +2 -2
  34. package/dist/runtime/actors/actor-local-native-join.js +19 -17
  35. package/dist/runtime/actors/actor-mailbox.d.ts +1 -1
  36. package/dist/runtime/actors/actor-remote-joiner.d.ts +2 -2
  37. package/dist/runtime/actors/actor-remote-joiner.js +4 -4
  38. package/dist/runtime/actors/actor-routed-join-transport.d.ts +9 -3
  39. package/dist/runtime/actors/actor-routed-json-request.d.ts +3 -0
  40. package/dist/runtime/actors/actor-runtime-contracts.d.ts +2 -2
  41. package/dist/runtime/actors/actor-runtime-state.d.ts +1 -1
  42. package/dist/runtime/actors/spot-actor-dispatch.d.ts +9 -5
  43. package/dist/runtime/actors/spot-actor-dispatch.js +60 -38
  44. package/dist/runtime/admission.d.ts +6 -4
  45. package/dist/runtime/admission.js +21 -10
  46. package/dist/runtime/application-jobs/application-ingress-record-owner.d.ts +1 -0
  47. package/dist/runtime/application-jobs/application-ingress-record-owner.js +3 -0
  48. package/dist/runtime/backend/contracts/index.d.ts +26 -10
  49. package/dist/runtime/backend/mesh-completion-table.d.ts +7 -1
  50. package/dist/runtime/backend/mesh-completion-table.js +84 -20
  51. package/dist/runtime/backend/mesh-dispatch-pump.d.ts +19 -6
  52. package/dist/runtime/backend/mesh-dispatch-pump.js +246 -147
  53. package/dist/runtime/backend/node/node-backend-adapter-support.d.ts +3 -2
  54. package/dist/runtime/backend/node/node-backend-adapter-support.js +27 -19
  55. package/dist/runtime/backend/node/node-dealer-channel-client-transport.d.ts +5 -2
  56. package/dist/runtime/backend/node/node-dealer-channel-client-transport.js +70 -13
  57. package/dist/runtime/backend/node/node-event-loop-poller.d.ts +2 -2
  58. package/dist/runtime/backend/node/node-event-loop-poller.js +4 -3
  59. package/dist/runtime/backend/node/node-mesh-backend-adapter.js +5 -1
  60. package/dist/runtime/backend/node/node-raw-binding-port.d.ts +7 -2
  61. package/dist/runtime/backend/node/node-raw-binding-port.js +99 -63
  62. package/dist/runtime/backend/node/node-raw-mesh-backend.d.ts +34 -16
  63. package/dist/runtime/backend/node/node-raw-mesh-backend.js +210 -106
  64. package/dist/runtime/backend/node/node-socket-backend-adapter.js +20 -6
  65. package/dist/runtime/backend/raw-binding-port.d.ts +6 -3
  66. package/dist/runtime/channels/channel-clients.js +3 -3
  67. package/dist/runtime/channels/channel-dispatch-pipeline.d.ts +11 -7
  68. package/dist/runtime/channels/channel-dispatch-pipeline.js +40 -22
  69. package/dist/runtime/channels/channel-dispatch-services.d.ts +3 -1
  70. package/dist/runtime/channels/channel-dispatch-services.js +7 -6
  71. package/dist/runtime/channels/channel-dispatchers.d.ts +13 -6
  72. package/dist/runtime/channels/channel-dispatchers.js +57 -36
  73. package/dist/runtime/channels/channel-envelope.d.ts +2 -2
  74. package/dist/runtime/channels/channel-envelope.js +609 -83
  75. package/dist/runtime/channels/channel-multipart.d.ts +1 -0
  76. package/dist/runtime/channels/channel-multipart.js +10 -6
  77. package/dist/runtime/channels/channel-outbound-operations.d.ts +6 -9
  78. package/dist/runtime/channels/channel-outbound-operations.js +107 -105
  79. package/dist/runtime/channels/channel-receive-loops.d.ts +9 -7
  80. package/dist/runtime/channels/channel-receive-loops.js +126 -90
  81. package/dist/runtime/channels/channel-runtime-lifecycle.d.ts +23 -6
  82. package/dist/runtime/channels/channel-runtime-lifecycle.js +47 -38
  83. package/dist/runtime/channels/channel-runtime-manager.d.ts +13 -6
  84. package/dist/runtime/channels/channel-runtime-manager.js +32 -14
  85. package/dist/runtime/channels/channel-socket-registry.d.ts +28 -4
  86. package/dist/runtime/channels/channel-socket-registry.js +9 -1
  87. package/dist/runtime/channels/channel-transports.d.ts +23 -16
  88. package/dist/runtime/channels/channel-transports.js +139 -119
  89. package/dist/runtime/channels/dispatch-error-reporter.d.ts +4 -4
  90. package/dist/runtime/channels/dispatch-error-reporter.js +5 -5
  91. package/dist/runtime/channels/fanout-location-runtime.d.ts +1 -1
  92. package/dist/runtime/channels/local-spot-route-transport.d.ts +5 -2
  93. package/dist/runtime/channels/local-spot-route-transport.js +15 -18
  94. package/dist/runtime/channels/router-socket-spot-route-transport.d.ts +6 -3
  95. package/dist/runtime/channels/router-socket-spot-route-transport.js +33 -19
  96. package/dist/runtime/channels/source-spot-router.d.ts +6 -3
  97. package/dist/runtime/channels/source-spot-router.js +34 -23
  98. package/dist/runtime/channels/spot-node-route-transport.d.ts +6 -3
  99. package/dist/runtime/channels/spot-node-route-transport.js +23 -17
  100. package/dist/runtime/channels/spot-route-bridge-transport.d.ts +6 -3
  101. package/dist/runtime/channels/spot-route-bridge-transport.js +38 -24
  102. package/dist/runtime/channels/spot-route-dispatch-strategy.d.ts +8 -4
  103. package/dist/runtime/channels/spot-route-dispatch-strategy.js +36 -23
  104. package/dist/runtime/diagnostics/dispatch-error-details.js +9 -3
  105. package/dist/runtime/diagnostics/message-flow-bootstrap.d.ts +1 -0
  106. package/dist/runtime/diagnostics/message-flow-bootstrap.js +8 -0
  107. package/dist/runtime/diagnostics/message-flow-delivery.d.ts +47 -0
  108. package/dist/runtime/diagnostics/message-flow-delivery.js +149 -0
  109. package/dist/runtime/diagnostics/message-flow-record.d.ts +50 -0
  110. package/dist/runtime/diagnostics/message-flow-record.js +228 -0
  111. package/dist/runtime/diagnostics/message-flow-worker.d.ts +1 -0
  112. package/dist/runtime/diagnostics/message-flow-worker.js +118 -0
  113. package/dist/runtime/diagnostics/message-flow.d.ts +7 -19
  114. package/dist/runtime/diagnostics/message-flow.js +42 -290
  115. package/dist/runtime/diagnostics/runtime-metrics.d.ts +4 -3
  116. package/dist/runtime/diagnostics/runtime-metrics.js +8 -4
  117. package/dist/runtime/execution/index.d.ts +1 -0
  118. package/dist/runtime/execution/index.js +6 -3
  119. package/dist/runtime/execution/serial-execution-queue.d.ts +26 -13
  120. package/dist/runtime/execution/serial-execution-queue.js +75 -71
  121. package/dist/runtime/foundation/durable-service-request.d.ts +12 -3
  122. package/dist/runtime/foundation/durable-service-request.js +158 -73
  123. package/dist/runtime/foundation/operation-registry.d.ts +33 -3
  124. package/dist/runtime/foundation/operation-registry.js +272 -33
  125. package/dist/runtime/foundation/raw-service-mesh-runtime.d.ts +62 -23
  126. package/dist/runtime/foundation/raw-service-mesh-runtime.js +373 -194
  127. package/dist/runtime/foundation/request-runtime.d.ts +17 -0
  128. package/dist/runtime/foundation/request-runtime.js +163 -0
  129. package/dist/runtime/foundation/service-discovery-registry.d.ts +4 -0
  130. package/dist/runtime/foundation/service-discovery-registry.js +6 -0
  131. package/dist/runtime/foundation/service-liveness-registry.d.ts +1 -1
  132. package/dist/runtime/foundation/service-mailbox.d.ts +4 -2
  133. package/dist/runtime/foundation/service-mailbox.js +4 -1
  134. package/dist/runtime/foundation/service-relocation-object-owner.d.ts +2 -2
  135. package/dist/runtime/foundation/service-relocation-object-owner.js +12 -5
  136. package/dist/runtime/foundation/service-runtime-contracts.d.ts +7 -2
  137. package/dist/runtime/foundation/service-stateful-registry.d.ts +6 -2
  138. package/dist/runtime/foundation/service-stateful-registry.js +38 -17
  139. package/dist/runtime/foundation/service-stateful-runtime.d.ts +91 -26
  140. package/dist/runtime/foundation/service-stateful-runtime.js +245 -120
  141. package/dist/runtime/foundation/service-stateful-wire-codec.d.ts +3 -0
  142. package/dist/runtime/foundation/service-stateful-wire-codec.js +15 -0
  143. package/dist/runtime/foundation/service-topology-registry.d.ts +2 -0
  144. package/dist/runtime/foundation/service-topology-registry.js +13 -3
  145. package/dist/runtime/foundation/service-wire-constants.generated.d.ts +1 -0
  146. package/dist/runtime/foundation/service-wire-constants.generated.js +12 -0
  147. package/dist/runtime/foundation/service-wire-m6a-codec.d.ts +5 -1
  148. package/dist/runtime/foundation/service-wire-m6a-codec.js +50 -15
  149. package/dist/runtime/host/actor-packet-relay.d.ts +5 -6
  150. package/dist/runtime/host/actor-packet-relay.js +58 -57
  151. package/dist/runtime/host/actor-placement-coordinator.d.ts +1 -1
  152. package/dist/runtime/host/actor-runtime-options-factory.d.ts +2 -0
  153. package/dist/runtime/host/actor-runtime-options-factory.js +3 -2
  154. package/dist/runtime/host/actor-transfer-runtime.d.ts +3 -3
  155. package/dist/runtime/host/application-job-queue.d.ts +7 -5
  156. package/dist/runtime/host/application-job-queue.js +33 -21
  157. package/dist/runtime/host/bound-session-relay.js +0 -1
  158. package/dist/runtime/host/channel-runtime-options-factory.d.ts +2 -0
  159. package/dist/runtime/host/channel-runtime-options-factory.js +1 -0
  160. package/dist/runtime/host/entry-actor-runtime.d.ts +5 -2
  161. package/dist/runtime/host/entry-actor-runtime.js +2 -2
  162. package/dist/runtime/host/index.d.ts +106 -37
  163. package/dist/runtime/host/index.js +303 -151
  164. package/dist/runtime/host/location-runtime-owner.d.ts +2 -2
  165. package/dist/runtime/host/location-runtime-owner.js +1 -1
  166. package/dist/runtime/host/service-relocation-host-runtime.d.ts +195 -45
  167. package/dist/runtime/host/service-relocation-host-runtime.js +257 -144
  168. package/dist/runtime/host/spot-address-transport.d.ts +3 -0
  169. package/dist/runtime/host/spot-address-transport.js +73 -76
  170. package/dist/runtime/host/spot-runtime-options-factory.js +2 -0
  171. package/dist/runtime/host/user-spot-creation-coordinator.d.ts +3 -1
  172. package/dist/runtime/host/user-spot-creation-coordinator.js +49 -21
  173. package/dist/runtime/internal-observation.d.ts +1 -0
  174. package/dist/runtime/internal-observation.js +5 -0
  175. package/dist/runtime/locations/actor-location-claims.d.ts +1 -1
  176. package/dist/runtime/locations/actor-location-claims.js +15 -6
  177. package/dist/runtime/locations/auto-connect-loop.d.ts +0 -1
  178. package/dist/runtime/locations/auto-connect-loop.js +25 -19
  179. package/dist/runtime/locations/auto-connect-planner.js +2 -5
  180. package/dist/runtime/locations/auto-connect-reconciler.d.ts +1 -0
  181. package/dist/runtime/locations/auto-connect-reconciler.js +35 -23
  182. package/dist/runtime/locations/in-memory-authority-store.d.ts +1 -0
  183. package/dist/runtime/locations/in-memory-authority-store.js +15 -5
  184. package/dist/runtime/locations/in-memory-location-store.d.ts +0 -2
  185. package/dist/runtime/locations/in-memory-location-store.js +1 -38
  186. package/dist/runtime/locations/lifecycle.d.ts +1 -1
  187. package/dist/runtime/locations/lifecycle.js +2 -2
  188. package/dist/runtime/locations/location-store-repository.d.ts +0 -1
  189. package/dist/runtime/locations/location-store-repository.js +163 -246
  190. package/dist/runtime/locations/resolvers.d.ts +8 -1
  191. package/dist/runtime/locations/resolvers.js +16 -2
  192. package/dist/runtime/locations/runtime.d.ts +3 -3
  193. package/dist/runtime/locations/runtime.js +12 -16
  194. package/dist/runtime/messaging/creation-payload-codec.js +8 -7
  195. package/dist/runtime/messaging/framework-json-v1.d.ts +1 -1
  196. package/dist/runtime/messaging/framework-json-v1.js +6 -2
  197. package/dist/runtime/messaging/payload-codec.js +21 -35
  198. package/dist/runtime/messaging/request-deadline.d.ts +4 -2
  199. package/dist/runtime/messaging/request-deadline.js +40 -25
  200. package/dist/runtime/messaging/request-result.d.ts +14 -1
  201. package/dist/runtime/messaging/request-result.js +74 -13
  202. package/dist/runtime/protocol/service_wire_codec.generated.d.ts +4 -0
  203. package/dist/runtime/protocol/service_wire_codec.generated.js +17 -7
  204. package/dist/runtime/spots/index.d.ts +28 -7
  205. package/dist/runtime/spots/index.js +31 -6
  206. package/dist/runtime/spots/spot-activation-registry.d.ts +3 -2
  207. package/dist/runtime/spots/spot-activation-registry.js +13 -8
  208. package/dist/runtime/spots/spot-activation-state.d.ts +2 -0
  209. package/dist/runtime/spots/spot-activation-state.js +1 -0
  210. package/dist/runtime/spots/spot-actor-admission-coordinator.d.ts +9 -4
  211. package/dist/runtime/spots/spot-actor-admission-coordinator.js +33 -12
  212. package/dist/runtime/spots/spot-actor-ingress-admission.d.ts +40 -0
  213. package/dist/runtime/spots/spot-actor-ingress-admission.js +78 -0
  214. package/dist/runtime/spots/spot-actor-membership.js +3 -3
  215. package/dist/runtime/spots/spot-actor-packet-dispatch.d.ts +16 -43
  216. package/dist/runtime/spots/spot-actor-packet-dispatch.js +56 -113
  217. package/dist/runtime/spots/spot-actor-packet-drain.d.ts +1 -0
  218. package/dist/runtime/spots/spot-actor-packet-drain.js +12 -5
  219. package/dist/runtime/spots/spot-entry-activation.d.ts +4 -3
  220. package/dist/runtime/spots/spot-entry-activation.js +7 -12
  221. package/dist/runtime/spots/spot-handler-registry.d.ts +5 -1
  222. package/dist/runtime/spots/spot-handler-registry.js +31 -15
  223. package/dist/runtime/spots/spot-manager-public.js +3 -2
  224. package/dist/runtime/spots/spot-node-runtime-manager.d.ts +11 -6
  225. package/dist/runtime/spots/spot-node-runtime-manager.js +6 -1
  226. package/dist/runtime/spots/spot-outbound.d.ts +8 -2
  227. package/dist/runtime/spots/spot-outbound.js +5 -5
  228. package/dist/runtime/spots/spot-route-packet-dispatch.js +13 -8
  229. package/dist/runtime/spots/spot-routed-spot-packet-dispatch.d.ts +3 -3
  230. package/dist/runtime/spots/spot-routed-spot-packet-dispatch.js +9 -5
  231. package/dist/runtime/spots/spot-runtime-ports.d.ts +2 -2
  232. package/dist/runtime/spots/spot-serial-executor.d.ts +2 -1
  233. package/dist/runtime/spots/spot-serial-turn-executor.js +20 -26
  234. package/dist/runtime/spots/spot-subscription-dispatch.js +5 -2
  235. package/dist/runtime/spots/spot-timer.d.ts +1 -1
  236. package/dist/runtime/streams/actor-session-binding-registry.d.ts +11 -3
  237. package/dist/runtime/streams/actor-session-binding-registry.js +28 -0
  238. package/dist/runtime/streams/bound-actor-relay-sender.d.ts +2 -2
  239. package/dist/runtime/streams/bound-actor-relay-sender.js +3 -4
  240. package/dist/runtime/streams/bound-session-service.js +6 -7
  241. package/dist/runtime/streams/index.d.ts +3 -3
  242. package/dist/runtime/streams/index.js +22 -2
  243. package/dist/runtime/streams/managed-stream.js +2 -1
  244. package/dist/runtime/streams/session-calls.d.ts +1 -1
  245. package/dist/runtime/streams/session-calls.js +3 -9
  246. package/dist/runtime/streams/session-context.d.ts +2 -2
  247. package/dist/runtime/streams/session-context.js +2 -2
  248. package/dist/runtime/streams/stream-session-runtime.d.ts +1 -0
  249. package/dist/runtime/streams/stream-session-runtime.js +64 -33
  250. package/package.json +3 -3
  251. package/src/contracts/Actors/ZLinkActor.ts +6 -0
  252. package/src/contracts/Actors/ZLinkSessionBindingIdentity.ts +7 -0
  253. package/src/contracts/Actors/index.ts +1 -0
  254. package/src/contracts/Common/CoreTypes.ts +1 -0
  255. package/src/contracts/Common/HandlerMessageType.ts +50 -0
  256. package/src/contracts/Common/ZLinkEncodedPayload.ts +13 -25
  257. package/src/contracts/Common/ZLinkMessage.ts +11 -7
  258. package/src/contracts/Common/encoded-payload-storage.ts +4 -16
  259. package/src/contracts/Common/index.ts +1 -1
  260. package/src/contracts/Common/payload-slab.ts +29 -0
  261. package/src/contracts/Configuration/RegistrationBuilders.ts +29 -15
  262. package/src/contracts/Configuration/RegistrationTypes.ts +19 -0
  263. package/src/contracts/Handlers/Contexts.ts +1 -0
  264. package/src/contracts/Locations/Authority.ts +7 -1
  265. package/src/internal.ts +17 -0
  266. package/src/nest-integration.ts +1 -0
  267. package/src/runtime/actors/actor-client.ts +257 -163
  268. package/src/runtime/actors/actor-context.ts +26 -14
  269. package/src/runtime/actors/actor-execution-context.ts +2 -2
  270. package/src/runtime/actors/actor-handoff.ts +86 -51
  271. package/src/runtime/actors/actor-join-deferred-scope.ts +6 -6
  272. package/src/runtime/actors/actor-local-native-join.ts +38 -17
  273. package/src/runtime/actors/actor-mailbox.ts +1 -1
  274. package/src/runtime/actors/actor-remote-joiner.ts +8 -4
  275. package/src/runtime/actors/actor-routed-join-transport.ts +13 -5
  276. package/src/runtime/actors/actor-routed-json-request.ts +3 -0
  277. package/src/runtime/actors/actor-runtime-contracts.ts +4 -2
  278. package/src/runtime/actors/actor-runtime-state.ts +1 -1
  279. package/src/runtime/actors/spot-actor-dispatch.ts +70 -68
  280. package/src/runtime/admission.ts +42 -15
  281. package/src/runtime/application-jobs/application-ingress-record-owner.ts +4 -0
  282. package/src/runtime/backend/contracts/index.ts +77 -10
  283. package/src/runtime/backend/mesh-completion-table.ts +106 -15
  284. package/src/runtime/backend/mesh-dispatch-pump.ts +294 -146
  285. package/src/runtime/backend/node/node-backend-adapter-support.ts +42 -32
  286. package/src/runtime/backend/node/node-dealer-channel-client-transport.ts +91 -34
  287. package/src/runtime/backend/node/node-event-loop-poller.ts +14 -5
  288. package/src/runtime/backend/node/node-mesh-backend-adapter.ts +5 -1
  289. package/src/runtime/backend/node/node-raw-binding-port.ts +180 -69
  290. package/src/runtime/backend/node/node-raw-mesh-backend.ts +386 -157
  291. package/src/runtime/backend/node/node-socket-backend-adapter.ts +56 -11
  292. package/src/runtime/backend/raw-binding-port.ts +13 -5
  293. package/src/runtime/channels/channel-clients.ts +26 -11
  294. package/src/runtime/channels/channel-dispatch-pipeline.ts +77 -65
  295. package/src/runtime/channels/channel-dispatch-services.ts +7 -12
  296. package/src/runtime/channels/channel-dispatchers.ts +93 -39
  297. package/src/runtime/channels/channel-envelope.ts +680 -144
  298. package/src/runtime/channels/channel-multipart.ts +17 -13
  299. package/src/runtime/channels/channel-outbound-operations.ts +204 -178
  300. package/src/runtime/channels/channel-receive-loops.ts +160 -107
  301. package/src/runtime/channels/channel-runtime-lifecycle.ts +64 -59
  302. package/src/runtime/channels/channel-runtime-manager.ts +74 -27
  303. package/src/runtime/channels/channel-socket-registry.ts +20 -5
  304. package/src/runtime/channels/channel-transports.ts +414 -287
  305. package/src/runtime/channels/dispatch-error-reporter.ts +4 -9
  306. package/src/runtime/channels/local-spot-route-transport.ts +27 -29
  307. package/src/runtime/channels/router-socket-spot-route-transport.ts +63 -32
  308. package/src/runtime/channels/source-spot-router.ts +75 -38
  309. package/src/runtime/channels/spot-node-route-transport.ts +67 -37
  310. package/src/runtime/channels/spot-route-bridge-transport.ts +62 -30
  311. package/src/runtime/channels/spot-route-dispatch-strategy.ts +105 -34
  312. package/src/runtime/diagnostics/dispatch-error-details.ts +10 -2
  313. package/src/runtime/diagnostics/message-flow-bootstrap.ts +6 -0
  314. package/src/runtime/diagnostics/message-flow-delivery.ts +171 -0
  315. package/src/runtime/diagnostics/message-flow-record.ts +295 -0
  316. package/src/runtime/diagnostics/message-flow-worker.ts +146 -0
  317. package/src/runtime/diagnostics/message-flow.ts +49 -362
  318. package/src/runtime/diagnostics/runtime-metrics.ts +10 -4
  319. package/src/runtime/execution/index.ts +6 -0
  320. package/src/runtime/execution/serial-execution-queue.ts +94 -96
  321. package/src/runtime/foundation/durable-service-request.ts +212 -89
  322. package/src/runtime/foundation/operation-registry.ts +287 -38
  323. package/src/runtime/foundation/raw-service-mesh-runtime.ts +617 -292
  324. package/src/runtime/foundation/request-runtime.ts +227 -0
  325. package/src/runtime/foundation/service-discovery-registry.ts +7 -0
  326. package/src/runtime/foundation/service-liveness-registry.ts +1 -1
  327. package/src/runtime/foundation/service-mailbox.ts +7 -2
  328. package/src/runtime/foundation/service-relocation-object-owner.ts +21 -6
  329. package/src/runtime/foundation/service-runtime-contracts.ts +12 -2
  330. package/src/runtime/foundation/service-stateful-registry.ts +52 -19
  331. package/src/runtime/foundation/service-stateful-runtime.ts +365 -198
  332. package/src/runtime/foundation/service-stateful-wire-codec.ts +18 -0
  333. package/src/runtime/foundation/service-topology-registry.ts +21 -3
  334. package/src/runtime/foundation/service-wire-constants.generated.ts +10 -0
  335. package/src/runtime/foundation/service-wire-m6a-codec.ts +69 -17
  336. package/src/runtime/host/actor-packet-relay.ts +160 -156
  337. package/src/runtime/host/actor-placement-coordinator.ts +1 -1
  338. package/src/runtime/host/actor-runtime-options-factory.ts +7 -2
  339. package/src/runtime/host/actor-transfer-runtime.ts +3 -3
  340. package/src/runtime/host/application-job-queue.ts +56 -27
  341. package/src/runtime/host/bound-session-relay.ts +0 -1
  342. package/src/runtime/host/channel-runtime-options-factory.ts +3 -0
  343. package/src/runtime/host/entry-actor-runtime.ts +14 -6
  344. package/src/runtime/host/index.ts +388 -113
  345. package/src/runtime/host/location-runtime-owner.ts +3 -3
  346. package/src/runtime/host/service-relocation-host-runtime.ts +380 -252
  347. package/src/runtime/host/spot-address-transport.ts +110 -95
  348. package/src/runtime/host/spot-runtime-options-factory.ts +3 -0
  349. package/src/runtime/host/user-spot-creation-coordinator.ts +69 -22
  350. package/src/runtime/internal-observation.ts +2 -0
  351. package/src/runtime/locations/actor-location-claims.ts +42 -16
  352. package/src/runtime/locations/auto-connect-loop.ts +24 -16
  353. package/src/runtime/locations/auto-connect-planner.ts +2 -5
  354. package/src/runtime/locations/auto-connect-reconciler.ts +37 -24
  355. package/src/runtime/locations/in-memory-authority-store.ts +27 -7
  356. package/src/runtime/locations/in-memory-location-store.ts +1 -74
  357. package/src/runtime/locations/lifecycle.ts +4 -2
  358. package/src/runtime/locations/location-store-repository.ts +228 -308
  359. package/src/runtime/locations/resolvers.ts +20 -8
  360. package/src/runtime/locations/runtime.ts +16 -28
  361. package/src/runtime/messaging/creation-payload-codec.ts +12 -10
  362. package/src/runtime/messaging/framework-json-v1.ts +10 -1
  363. package/src/runtime/messaging/payload-codec.ts +50 -75
  364. package/src/runtime/messaging/request-deadline.ts +47 -39
  365. package/src/runtime/messaging/request-result.ts +88 -17
  366. package/src/runtime/protocol/service_wire_codec.generated.ts +18 -8
  367. package/src/runtime/protocol/service_wire_pilot_codec.generated.ts +1 -1
  368. package/src/runtime/spots/index.ts +57 -10
  369. package/src/runtime/spots/spot-activation-registry.ts +12 -8
  370. package/src/runtime/spots/spot-activation-state.ts +2 -0
  371. package/src/runtime/spots/spot-actor-admission-coordinator.ts +62 -37
  372. package/src/runtime/spots/spot-actor-ingress-admission.ts +157 -0
  373. package/src/runtime/spots/spot-actor-membership.ts +8 -5
  374. package/src/runtime/spots/spot-actor-packet-dispatch.ts +122 -206
  375. package/src/runtime/spots/spot-actor-packet-drain.ts +21 -6
  376. package/src/runtime/spots/spot-entry-activation.ts +25 -35
  377. package/src/runtime/spots/spot-handler-registry.ts +72 -15
  378. package/src/runtime/spots/spot-manager-public.ts +4 -2
  379. package/src/runtime/spots/spot-node-runtime-manager.ts +16 -7
  380. package/src/runtime/spots/spot-outbound.ts +26 -10
  381. package/src/runtime/spots/spot-route-packet-dispatch.ts +18 -8
  382. package/src/runtime/spots/spot-routed-spot-packet-dispatch.ts +14 -8
  383. package/src/runtime/spots/spot-runtime-ports.ts +5 -2
  384. package/src/runtime/spots/spot-serial-executor.ts +1 -1
  385. package/src/runtime/spots/spot-serial-turn-executor.ts +25 -40
  386. package/src/runtime/spots/spot-subscription-dispatch.ts +9 -2
  387. package/src/runtime/spots/spot-timer.ts +1 -1
  388. package/src/runtime/streams/actor-session-binding-registry.ts +46 -3
  389. package/src/runtime/streams/bound-actor-relay-sender.ts +16 -5
  390. package/src/runtime/streams/bound-session-service.ts +10 -7
  391. package/src/runtime/streams/index.ts +30 -4
  392. package/src/runtime/streams/managed-stream.ts +2 -1
  393. package/src/runtime/streams/session-calls.ts +9 -14
  394. package/src/runtime/streams/session-context.ts +6 -11
  395. package/src/runtime/streams/stream-session-runtime.ts +79 -40
  396. package/dist/runtime/spots/spot-lifecycle-metrics.d.ts +0 -8
  397. package/dist/runtime/spots/spot-lifecycle-metrics.js +0 -17
  398. package/src/runtime/spots/spot-lifecycle-metrics.ts +0 -16
@@ -15,7 +15,6 @@ exports.decodeChannelPayload = decodeChannelPayload;
15
15
  exports.closeMessages = closeMessages;
16
16
  exports.decodeChannelHeader = decodeChannelHeader;
17
17
  exports.isValidChannelCorrelationId = isValidChannelCorrelationId;
18
- const runtime_message_1 = require("../backend/runtime-message");
19
18
  const node_crypto_1 = require("node:crypto");
20
19
  const node_buffer_1 = require("node:buffer");
21
20
  const contracts_1 = require("../../contracts");
@@ -47,7 +46,7 @@ const CHANNEL_CORRELATION_TEXT = /^[0-9a-f]{32}$/;
47
46
  const CHANNEL_FLOW_FIELD = ',"flowId":';
48
47
  // A flow id is a lowercase UUIDv7 (spec 27 §3): fixed 36 JSON-safe ASCII bytes.
49
48
  const PREPARED_CHANNEL_FLOW = '00000000-0000-7000-8000-000000000000';
50
- const CHANNEL_FLOW_TEXT = /^[0-9a-f-]{36}$/;
49
+ const CHANNEL_FLOW_TEXT = /^[0-9a-f]{8}-[0-9a-f]{4}-7[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/;
51
50
  // A per-process random 64-bit prefix followed by a per-process counter, both
52
51
  // as lowercase hex: unique among the runtime's pending requests (spec 06-obs/04
53
52
  // §3) without drawing random bytes for every request — the shape Java
@@ -56,8 +55,10 @@ const CHANNEL_CORRELATION_PREFIX = (0, node_crypto_1.randomBytes)(CHANNEL_CORREL
56
55
  let channelCorrelationCounter = 0;
57
56
  function newChannelCorrelationId() {
58
57
  channelCorrelationCounter += 1;
58
+ const suffix = channelCorrelationCounter.toString(16);
59
59
  return (CHANNEL_CORRELATION_PREFIX +
60
- channelCorrelationCounter.toString(16).padStart(CHANNEL_CORRELATION_TEXT_LENGTH / 2, '0'));
60
+ PREPARED_CHANNEL_CORRELATION.slice(suffix.length, CHANNEL_CORRELATION_TEXT_LENGTH / 2) +
61
+ suffix);
61
62
  }
62
63
  function encodeChannelEnvelopeParts(kind, channelName, packetName, payload, timeoutMs, topic, codecs, correlationId, createFlow = true, metadata = EMPTY_OUTBOUND_METADATA) {
63
64
  return encodeChannelEnvelopePartsAtDeadline(kind, channelName, packetName, payload, timeoutMs === undefined ? undefined : Date.now() + timeoutMs, topic, codecs, correlationId, createFlow, metadata);
@@ -74,29 +75,14 @@ function encodeChannelEnvelopePartsAtDeadline(kind, channelName, packetName, pay
74
75
  throw new RangeError('deadlineUnixMs must be a positive safe integer.');
75
76
  }
76
77
  const messageName = (0, packet_name_1.resolveFrameworkPacketName)(payload, packetName, 'Channel');
77
- const encoded = encodePayload(payload, (0, channel_framework_packets_1.codecsForFrameworkPacket)(messageName, codecs), messageName, 'payload');
78
- const flow = createFlow ? (0, flow_context_1.currentOrCreateFlow)('Application') : undefined;
79
- const envelopeCorrelationId = correlationIdForOutboundKind(kind, correlationId);
80
- return [
81
- encodeChannelHeader(kind, channelName, messageName, encoded.contentType, envelopeCorrelationId, deadlineUnixMs === undefined ? null : new Date(deadlineUnixMs).toISOString(), topic ?? null, null, null, undefined, applicationMetadataRecord(metadata), flow?.flowId, flow?.flowOrigin, codecs),
82
- encoded.message
83
- ];
78
+ return encodePayload(payload, (0, channel_framework_packets_1.codecsForFrameworkPacket)(messageName, codecs), messageName, 'payload', kind, channelName, correlationId, deadlineUnixMs, topic, createFlow, metadata, undefined, codecs);
84
79
  }
85
80
  function encodeChannelPublishEnvelopeParts(channelName, topic, packetName, payload, codecs, createFlow = true, metadata = EMPTY_OUTBOUND_METADATA) {
86
81
  const messageName = (0, packet_name_1.resolveFrameworkPacketName)(payload, packetName, 'Channel');
87
- const encoded = encodePayload(payload, (0, channel_framework_packets_1.codecsForFrameworkPacket)(messageName, codecs), messageName, 'payload');
88
- const flow = createFlow ? (0, flow_context_1.currentOrCreateFlow)('Application') : undefined;
89
- return [
90
- encodeChannelHeader(4 /* ZLinkChannelMessageKind.Publish */, channelName, messageName, encoded.contentType, null, null, topic, null, null, undefined, applicationMetadataRecord(metadata), flow?.flowId, flow?.flowOrigin),
91
- encoded.message
92
- ];
82
+ return encodePayload(payload, (0, channel_framework_packets_1.codecsForFrameworkPacket)(messageName, codecs), messageName, 'payload', 4 /* ZLinkChannelMessageKind.Publish */, channelName, undefined, undefined, topic, createFlow, metadata);
93
83
  }
94
84
  function encodeChannelReplyParts(request, payload, codecs) {
95
- const encoded = encodePayload(payload ?? Buffer.alloc(0), (0, channel_framework_packets_1.codecsForFrameworkPacket)(request.messageName, codecs), request.messageName, 'reply');
96
- return [
97
- encodeChannelHeader(2 /* ZLinkChannelMessageKind.Response */, request.channelName, request.messageName, encoded.contentType, request.correlationId, null, null, undefined, undefined, undefined, EMPTY_APPLICATION_METADATA, request.flowId, request.flowOrigin, codecs),
98
- encoded.message
99
- ];
85
+ return encodePayload(payload ?? Buffer.alloc(0), (0, channel_framework_packets_1.codecsForFrameworkPacket)(request.messageName, codecs), request.messageName, 'reply', 2 /* ZLinkChannelMessageKind.Response */, request.channelName, request.correlationId ?? undefined, undefined, undefined, false, EMPTY_OUTBOUND_METADATA, request, codecs);
100
86
  }
101
87
  /**
102
88
  * Reply metadata marker for errors the framework generated itself (never for
@@ -138,7 +124,7 @@ function encodeChannelErrorReplyParts(request, error, metadata = {}) {
138
124
  const errorMessage = error instanceof Error ? error.message : String(error);
139
125
  return [
140
126
  encodeChannelHeader(5 /* ZLinkChannelMessageKind.Error */, request.channelName, request.messageName, exports.JSON_CONTENT_TYPE, request.correlationId, null, null, errorCode, errorMessage, undefined, metadata, request.flowId, request.flowOrigin),
141
- encodeJsonBytes(null)
127
+ encodeJsonText(null)
142
128
  ];
143
129
  }
144
130
  function decodeChannelReply(parts, codecs) {
@@ -158,16 +144,17 @@ function decodeChannelReply(parts, codecs) {
158
144
  header.contentType !== exports.JSON_CONTENT_TYPE) {
159
145
  throw unsupportedChannelContentType(header.contentType);
160
146
  }
161
- if (parts.length < 2 || parts[1].data().length === 0) {
147
+ const body = parts.length < 2 ? undefined : parts[1].data();
148
+ if (body === undefined || body.length === 0) {
162
149
  return undefined;
163
150
  }
164
151
  if (header.contentType === exports.BINARY_CONTENT_TYPE) {
165
- return runtime_message_1.ZLinkBufferMessage.retainPayload(parts[1]);
152
+ return body;
166
153
  }
167
154
  if (serializer !== undefined) {
168
- return serializer.deserialize((0, payload_codec_1.encodedPayloadFromOwned)(parts[1].data()), Object);
155
+ return serializer.deserialize((0, payload_codec_1.encodedPayloadFromOwned)(body), Object);
169
156
  }
170
- return parseWireJson(parts[1].data().toString(), (0, Attributes_1.readZLinkPacketJsonContract)(header.messageName)?.reply);
157
+ return parseWireJson(body.toString(), (0, Attributes_1.readZLinkPacketJsonContract)(header.messageName)?.reply);
171
158
  }
172
159
  function decodeChannelError(header) {
173
160
  const code = header.errorCode;
@@ -215,14 +202,14 @@ function decodeChannelEnvelope(parts, decodedHeader, flowEnabled = true) {
215
202
  // Borrow its Buffer so envelope admission does not copy the whole payload.
216
203
  return { header, packetName: header.messageName, payload: parts[1].data() };
217
204
  }
218
- function decodeChannelPayload(envelope, codecs) {
205
+ function decodeChannelPayload(envelope, codecs, messageType) {
219
206
  try {
220
207
  if (!(0, CodecContentType_1.isCanonicalCodecContentType)(envelope.header.contentType)) {
221
208
  throw unsupportedChannelContentType(envelope.header.contentType);
222
209
  }
223
210
  const serializer = codecs?.serializers.get(envelope.header.contentType);
224
211
  if (serializer !== undefined) {
225
- return serializer.deserialize((0, payload_codec_1.encodedPayloadFromOwned)(envelope.payload), Object);
212
+ return serializer.deserialize((0, payload_codec_1.encodedPayloadFromOwned)(envelope.payload), (messageType ?? Object));
226
213
  }
227
214
  if (envelope.header.contentType === exports.BINARY_CONTENT_TYPE) {
228
215
  // The receive loop owns the Message for the duration of dispatch, so
@@ -230,7 +217,7 @@ function decodeChannelPayload(envelope, codecs) {
230
217
  return envelope.payload;
231
218
  }
232
219
  if (envelope.header.contentType === exports.JSON_CONTENT_TYPE) {
233
- return parseWireJson(envelope.payload.toString(), schemaForInboundChannelEnvelope(envelope.header));
220
+ return (0, ZLinkMessage_1.materializeZLinkMessageValue)(parseWireJson(envelope.payload.toString(), schemaForInboundChannelEnvelope(envelope.header)), messageType);
234
221
  }
235
222
  throw unsupportedChannelContentType(envelope.header.contentType);
236
223
  }
@@ -251,36 +238,45 @@ function closeMessages(parts) {
251
238
  }
252
239
  }
253
240
  }
254
- function encodePayload(value, codecs, packetName, contractPart) {
241
+ function encodePayload(value, codecs, packetName, contractPart, kind, channelName, correlationId, deadlineUnixMs, topic, createFlow, metadata, request, headerCodecs) {
242
+ let declaredType;
243
+ let contentType;
244
+ let message;
255
245
  if ((0, ZLinkMessage_1.isZLinkMessage)(value) && value.isEncoded()) {
256
246
  const payload = value.toEncodedPayload();
257
- return {
258
- contentType: exports.BINARY_CONTENT_TYPE,
259
- message: (0, encoded_payload_storage_1.borrowEncodedPayload)(payload) ?? payload.data()
260
- };
247
+ contentType = exports.BINARY_CONTENT_TYPE;
248
+ message = (0, encoded_payload_storage_1.borrowEncodedPayload)(payload) ?? payload.data();
261
249
  }
262
- const declaredType = (0, ZLinkMessage_1.isZLinkMessage)(value) ? (0, ZLinkMessage_1.readZLinkMessageDeclaredType)(value) : undefined;
263
- if ((0, ZLinkMessage_1.isZLinkMessage)(value))
264
- value = value.decode();
265
- const selected = (0, payload_codec_1.selectSerializerWithContentType)(value, codecs, declaredType);
266
- if (selected !== undefined &&
267
- !(Buffer.isBuffer(value) || value instanceof Uint8Array || isMessage(value))) {
268
- const payload = selected.serializer.serialize(value);
269
- return {
270
- contentType: selected.contentType,
271
- message: (0, encoded_payload_storage_1.borrowEncodedPayload)(payload) ?? payload.data()
272
- };
250
+ else {
251
+ if ((0, ZLinkMessage_1.isZLinkMessage)(value)) {
252
+ declaredType = (0, ZLinkMessage_1.readZLinkMessageDeclaredType)(value);
253
+ value = value.decode();
254
+ }
255
+ const selected = (0, payload_codec_1.selectSerializerWithContentType)(value, codecs, declaredType);
256
+ if (selected !== undefined &&
257
+ !(Buffer.isBuffer(value) || value instanceof Uint8Array || isMessage(value))) {
258
+ const payload = selected.serializer.serialize(value);
259
+ contentType = selected.contentType;
260
+ message = (0, encoded_payload_storage_1.borrowEncodedPayload)(payload) ?? payload.data();
261
+ }
262
+ else {
263
+ contentType = contentTypeOf(value);
264
+ message = toMessageLike(value, (0, Attributes_1.readZLinkPacketJsonContract)(packetName)?.[contractPart]);
265
+ }
273
266
  }
274
- return {
275
- contentType: contentTypeOf(value),
276
- message: toMessageLike(value, (0, Attributes_1.readZLinkPacketJsonContract)(packetName)?.[contractPart])
277
- };
267
+ const flow = request ?? (createFlow ? (0, flow_context_1.currentOrCreateFlow)('Application') : undefined);
268
+ return [
269
+ encodeChannelHeader(kind, channelName, packetName, contentType, request === undefined
270
+ ? correlationIdForOutboundKind(kind, correlationId)
271
+ : request.correlationId, deadlineUnixMs === undefined ? null : new Date(deadlineUnixMs).toISOString(), topic ?? null, contractPart === 'reply' ? undefined : null, contractPart === 'reply' ? undefined : null, undefined, applicationMetadataRecord(metadata), flow?.flowId, flow?.flowOrigin, headerCodecs),
272
+ message
273
+ ];
278
274
  }
279
275
  function toMessageLike(value, schema) {
280
276
  if (Buffer.isBuffer(value) || value instanceof Uint8Array || isMessage(value)) {
281
277
  return value;
282
278
  }
283
- return encodeJsonBytes(value, schema);
279
+ return encodeJsonText(value, schema);
284
280
  }
285
281
  function contentTypeOf(value) {
286
282
  return Buffer.isBuffer(value) || value instanceof Uint8Array || isMessage(value)
@@ -292,8 +288,8 @@ function isMessage(value) {
292
288
  value !== null &&
293
289
  typeof value.data === 'function');
294
290
  }
295
- function encodeJsonBytes(value, schema) {
296
- return Buffer.from((0, framework_json_v1_1.stringifyFrameworkJsonV1)(value, schema));
291
+ function encodeJsonText(value, schema) {
292
+ return (0, framework_json_v1_1.stringifyFrameworkJsonV1)(value, schema);
297
293
  }
298
294
  function encodeChannelHeader(kind, channelName, messageName, contentType, correlationId, deadline, topic, errorCode, errorMessage, source, metadata, flowId, flowOrigin, codecs) {
299
295
  if (codecs !== undefined &&
@@ -525,34 +521,62 @@ function decodeChannelHeader(parts, flowEnabled = true) {
525
521
  if (parts.length === 0) {
526
522
  throw new configuration_1.ZLinkConfigurationException('Channel envelope header part is missing.');
527
523
  }
528
- return validateChannelHeader(parseChannelHeaderBytes(parts[0].data()), flowEnabled);
524
+ return validateChannelHeader(parseChannelHeaderBytes(parts[0].data(), flowEnabled), flowEnabled);
529
525
  }
526
+ const CHANNEL_JSON_PARSE_OPTIONS = Object.freeze({ rejectPropertyName: isPrototypeKey });
530
527
  function parseWireJson(payload, schema) {
531
- return (0, framework_json_v1_1.parseFrameworkJsonV1)(payload, {
532
- rejectPropertyName: isPrototypeKey
533
- }, schema);
534
- }
535
- function parseChannelHeaderBytes(payload) {
536
- const reader = new CanonicalChannelHeaderReader(payload);
537
- const canonical = tryParseCanonicalChannelHeader(reader);
538
- // An all-ASCII canonical header is valid UTF-8 by construction; any other
539
- // header is checked before it is decoded.
540
- if (canonical !== undefined && !reader.sawNonAscii)
541
- return canonical;
528
+ return (0, framework_json_v1_1.parseFrameworkJsonV1)(payload, CHANNEL_JSON_PARSE_OPTIONS, schema);
529
+ }
530
+ const CHANNEL_HEADER_FIELD_NAMES = [
531
+ '',
532
+ 'formatMarker',
533
+ 'kind',
534
+ 'channelName',
535
+ 'messageName',
536
+ 'contentType',
537
+ 'correlationId',
538
+ 'deadline',
539
+ 'topic',
540
+ 'errorCode',
541
+ 'errorMessage',
542
+ 'source',
543
+ 'flowId',
544
+ 'flowOrigin',
545
+ 'metadata'
546
+ ];
547
+ const CHANNEL_HEADER_FIELD_COUNT = CHANNEL_HEADER_FIELD_NAMES.length - 1;
548
+ const CHANNEL_HEADER_INVALID_VALUE = Symbol('invalid channel header value');
549
+ const CANONICAL_CHANNEL_HEADER_PREFIX = '{"formatMarker":242,"kind":';
550
+ function parseChannelHeaderBytes(payload, flowEnabled) {
551
+ if (startsWithJson(payload, CANONICAL_CHANNEL_HEADER_PREFIX)) {
552
+ const reader = new CanonicalChannelHeaderReader(payload, CANONICAL_CHANNEL_HEADER_PREFIX.length);
553
+ const canonical = tryParseCanonicalChannelHeader(reader, flowEnabled);
554
+ // Canonical ASCII headers need no UTF-8 pass; all other paths are checked
555
+ // before byte slices are decoded.
556
+ if (canonical !== undefined && !reader.sawNonAscii)
557
+ return canonical;
558
+ if (canonical !== undefined) {
559
+ if (!(0, node_buffer_1.isUtf8)(payload)) {
560
+ throw new contracts_1.ZLinkFrameworkException(contracts_1.ZLinkFrameworkErrorKind.ProtocolError, 'Channel envelope header must contain valid UTF-8.');
561
+ }
562
+ return canonical;
563
+ }
564
+ }
542
565
  if (!(0, node_buffer_1.isUtf8)(payload)) {
543
566
  throw new contracts_1.ZLinkFrameworkException(contracts_1.ZLinkFrameworkErrorKind.ProtocolError, 'Channel envelope header must contain valid UTF-8.');
544
567
  }
545
- return canonical ?? (0, framework_json_v1_1.parseFrameworkJsonV1)(payload.toString());
568
+ return new ChannelHeaderJsonReader(payload, flowEnabled).parse();
546
569
  }
547
- /**
548
- * Accept the byte layout emitted by writeChannelHeader without materializing
549
- * the enclosing JSON text. Any variation falls through to the established
550
- * framework-json-v1 parser, which remains the sole authority for JSON
551
- * failures and unknown properties. Header metadata accepts every valid string key.
552
- */
553
- function tryParseCanonicalChannelHeader(reader) {
554
- if (!reader.consume('{"formatMarker":242,"kind":'))
555
- return undefined;
570
+ function startsWithJson(bytes, value) {
571
+ if (bytes.length < value.length)
572
+ return false;
573
+ for (let index = 0; index < value.length; index += 1) {
574
+ if (bytes[index] !== value.charCodeAt(index))
575
+ return false;
576
+ }
577
+ return true;
578
+ }
579
+ function tryParseCanonicalChannelHeader(reader, flowEnabled) {
556
580
  const kind = reader.readSingleDigit();
557
581
  if (kind === undefined || !reader.consume(',"channelName":'))
558
582
  return undefined;
@@ -582,7 +606,13 @@ function tryParseCanonicalChannelHeader(reader) {
582
606
  contentType,
583
607
  correlationId: correlationId === NULL_JSON_STRING ? null : correlationId,
584
608
  deadline: deadline === NULL_JSON_STRING ? null : deadline,
585
- topic: topic === NULL_JSON_STRING ? null : topic
609
+ topic: topic === NULL_JSON_STRING ? null : topic,
610
+ errorCode: null,
611
+ errorMessage: null,
612
+ source: undefined,
613
+ metadata: undefined,
614
+ flowId: undefined,
615
+ flowOrigin: undefined
586
616
  };
587
617
  if (!reader.readOptionalNullableString(CANONICAL_ERROR_CODE, 'errorCode', header))
588
618
  return undefined;
@@ -590,10 +620,13 @@ function tryParseCanonicalChannelHeader(reader) {
590
620
  return undefined;
591
621
  if (!reader.readOptionalNullableString(CANONICAL_SOURCE, 'source', header))
592
622
  return undefined;
593
- // Empty metadata validates to the shared empty record.
594
- if (!reader.consume(',"metadata":{}'))
623
+ const metadata = reader.readMetadata();
624
+ if (metadata === undefined)
595
625
  return undefined;
596
- if (!reader.readOptionalString(CANONICAL_FLOW_ID, 'flowId', header))
626
+ // Empty metadata validates to the shared empty record.
627
+ if (metadata !== NULL_JSON_STRING)
628
+ header.metadata = metadata;
629
+ if (!reader.readOptionalString(CANONICAL_FLOW_ID, 'flowId', header, flowEnabled))
597
630
  return undefined;
598
631
  if (!reader.readOptionalSingleDigit(CANONICAL_FLOW_ORIGIN, 'flowOrigin', header))
599
632
  return undefined;
@@ -610,8 +643,9 @@ class CanonicalChannelHeaderReader {
610
643
  index = 0;
611
644
  /** A string held a byte outside ASCII, so the caller must still check UTF-8. */
612
645
  sawNonAscii = false;
613
- constructor(bytes) {
646
+ constructor(bytes, initialIndex = 0) {
614
647
  this.bytes = bytes;
648
+ this.index = initialIndex;
615
649
  }
616
650
  atEnd() {
617
651
  return this.index === this.bytes.length;
@@ -686,6 +720,41 @@ class CanonicalChannelHeaderReader {
686
720
  return NULL_JSON_STRING;
687
721
  return this.readString();
688
722
  }
723
+ readMetadata() {
724
+ if (!this.consume(',"metadata":{'))
725
+ return undefined;
726
+ if (this.consume('}'))
727
+ return NULL_JSON_STRING;
728
+ const metadata = {};
729
+ for (;;) {
730
+ const key = this.readString();
731
+ if (key === undefined)
732
+ return undefined;
733
+ if (Object.prototype.hasOwnProperty.call(metadata, key)) {
734
+ throw new contracts_1.ZLinkFrameworkException(contracts_1.ZLinkFrameworkErrorKind.ProtocolError, 'duplicate envelope metadata key');
735
+ }
736
+ if (!this.consume(':'))
737
+ return undefined;
738
+ const value = this.readString();
739
+ if (value === undefined)
740
+ return undefined;
741
+ if (key === '__proto__') {
742
+ Object.defineProperty(metadata, key, {
743
+ configurable: true,
744
+ enumerable: true,
745
+ value,
746
+ writable: true
747
+ });
748
+ }
749
+ else {
750
+ metadata[key] = value;
751
+ }
752
+ if (this.consume('}'))
753
+ return metadata;
754
+ if (!this.consume(','))
755
+ return undefined;
756
+ }
757
+ }
689
758
  readOptionalNullableString(token, name, target) {
690
759
  if (!this.consume(token))
691
760
  return true;
@@ -695,15 +764,54 @@ class CanonicalChannelHeaderReader {
695
764
  target[name] = value === NULL_JSON_STRING ? null : value;
696
765
  return true;
697
766
  }
698
- readOptionalString(token, name, target) {
767
+ readOptionalString(token, name, target, decode = true) {
699
768
  if (!this.consume(token))
700
769
  return true;
770
+ if (!decode)
771
+ return this.skipString();
701
772
  const value = this.readString();
702
773
  if (value === undefined)
703
774
  return false;
704
775
  target[name] = value;
705
776
  return true;
706
777
  }
778
+ skipString() {
779
+ if (this.bytes[this.index] !== 0x22)
780
+ return false;
781
+ this.index += 1;
782
+ while (this.index < this.bytes.length) {
783
+ const value = this.bytes[this.index++];
784
+ if (value === 0x22)
785
+ return true;
786
+ if (value < 0x20)
787
+ return false;
788
+ if (value >= 0x80)
789
+ this.sawNonAscii = true;
790
+ if (value !== 0x5c)
791
+ continue;
792
+ if (this.index === this.bytes.length)
793
+ return false;
794
+ const escaped = this.bytes[this.index++];
795
+ if (escaped === 0x75) {
796
+ for (let count = 0; count < 4; count += 1) {
797
+ if (this.index === this.bytes.length || !isHexDigit(this.bytes[this.index]))
798
+ return false;
799
+ this.index += 1;
800
+ }
801
+ }
802
+ else if (escaped !== 0x22 &&
803
+ escaped !== 0x5c &&
804
+ escaped !== 0x2f &&
805
+ escaped !== 0x62 &&
806
+ escaped !== 0x66 &&
807
+ escaped !== 0x6e &&
808
+ escaped !== 0x72 &&
809
+ escaped !== 0x74) {
810
+ return false;
811
+ }
812
+ }
813
+ return false;
814
+ }
707
815
  readOptionalSingleDigit(token, name, target) {
708
816
  if (!this.consume(token))
709
817
  return true;
@@ -719,6 +827,419 @@ function isHexDigit(value) {
719
827
  (value >= 0x41 && value <= 0x46) ||
720
828
  (value >= 0x61 && value <= 0x66));
721
829
  }
830
+ /** Reads a noncanonical channel header directly from its UTF-8 bytes. */
831
+ class ChannelHeaderJsonReader {
832
+ bytes;
833
+ flowEnabled;
834
+ index = 0;
835
+ propertyName = '';
836
+ stringStart = 0;
837
+ stringEnd = 0;
838
+ stringHasEscapes = false;
839
+ constructor(bytes, flowEnabled) {
840
+ this.bytes = bytes;
841
+ this.flowEnabled = flowEnabled;
842
+ }
843
+ parse() {
844
+ if (this.bytes.length >= 3 &&
845
+ this.bytes[0] === 0xef &&
846
+ this.bytes[1] === 0xbb &&
847
+ this.bytes[2] === 0xbf) {
848
+ throw new SyntaxError('framework-json-v1 does not allow a UTF-8 BOM.');
849
+ }
850
+ this.skipWhitespace();
851
+ if (this.bytes[this.index] !== 0x7b) {
852
+ this.skipValue();
853
+ this.skipWhitespace();
854
+ if (this.index !== this.bytes.length)
855
+ this.fail('trailing data');
856
+ return CHANNEL_HEADER_INVALID_VALUE;
857
+ }
858
+ const header = {};
859
+ let seenFields = 0;
860
+ this.index += 1;
861
+ this.skipWhitespace();
862
+ if (this.consumeByte(0x7d))
863
+ return this.finish(header);
864
+ for (;;) {
865
+ const field = this.readPropertyName(true);
866
+ const propertyName = this.propertyName;
867
+ this.skipWhitespace();
868
+ this.expectByte(0x3a, "':' after object property");
869
+ this.skipWhitespace();
870
+ if (field !== 0) {
871
+ const bit = 1 << field;
872
+ if ((seenFields & bit) !== 0) {
873
+ throw new contracts_1.ZLinkFrameworkException(contracts_1.ZLinkFrameworkErrorKind.ProtocolError, 'duplicate envelope header field');
874
+ }
875
+ seenFields |= bit;
876
+ const name = CHANNEL_HEADER_FIELD_NAMES[field];
877
+ if (!this.flowEnabled && (field === 12 || field === 13)) {
878
+ this.skipValue();
879
+ header[name] = undefined;
880
+ }
881
+ else if (field === 14) {
882
+ header[name] = this.readMetadata();
883
+ }
884
+ else {
885
+ header[name] = this.readValue(field === 1 || field === 2 || field === 13);
886
+ }
887
+ }
888
+ else {
889
+ const value = this.readValue();
890
+ if (propertyName === '__proto__') {
891
+ Object.defineProperty(header, propertyName, {
892
+ configurable: true,
893
+ enumerable: true,
894
+ value,
895
+ writable: true
896
+ });
897
+ }
898
+ else {
899
+ header[propertyName] = value;
900
+ }
901
+ }
902
+ this.skipWhitespace();
903
+ if (this.consumeByte(0x7d))
904
+ break;
905
+ this.expectByte(0x2c, "',' or '}' after object property");
906
+ this.skipWhitespace();
907
+ }
908
+ return this.finish(header);
909
+ }
910
+ finish(header) {
911
+ this.skipWhitespace();
912
+ if (this.index !== this.bytes.length)
913
+ this.fail('trailing data');
914
+ return header;
915
+ }
916
+ readMetadata() {
917
+ if (this.bytes[this.index] !== 0x7b)
918
+ return this.readValue();
919
+ this.index += 1;
920
+ this.skipWhitespace();
921
+ if (this.consumeByte(0x7d))
922
+ return undefined;
923
+ const metadata = {};
924
+ for (;;) {
925
+ const key = this.readString();
926
+ if (Object.prototype.hasOwnProperty.call(metadata, key)) {
927
+ throw new contracts_1.ZLinkFrameworkException(contracts_1.ZLinkFrameworkErrorKind.ProtocolError, 'duplicate envelope metadata key');
928
+ }
929
+ this.skipWhitespace();
930
+ this.expectByte(0x3a, "':' after object property");
931
+ this.skipWhitespace();
932
+ const value = this.readValue();
933
+ if (key === '__proto__') {
934
+ Object.defineProperty(metadata, key, {
935
+ configurable: true,
936
+ enumerable: true,
937
+ value,
938
+ writable: true
939
+ });
940
+ }
941
+ else {
942
+ metadata[key] = value;
943
+ }
944
+ this.skipWhitespace();
945
+ if (this.consumeByte(0x7d))
946
+ return metadata;
947
+ this.expectByte(0x2c, "',' or '}' after object property");
948
+ this.skipWhitespace();
949
+ }
950
+ }
951
+ readPropertyName(materializeUnknown = false) {
952
+ this.scanString();
953
+ let field = 0;
954
+ let decoded;
955
+ if (this.stringHasEscapes) {
956
+ decoded = this.decodeString();
957
+ for (let candidate = 1; candidate <= CHANNEL_HEADER_FIELD_COUNT; candidate += 1) {
958
+ if (CHANNEL_HEADER_FIELD_NAMES[candidate] === decoded) {
959
+ field = candidate;
960
+ break;
961
+ }
962
+ }
963
+ }
964
+ else {
965
+ for (let candidate = 1; candidate <= CHANNEL_HEADER_FIELD_COUNT; candidate += 1) {
966
+ if (this.matchesAscii(this.stringStart + 1, this.stringEnd - 1, CHANNEL_HEADER_FIELD_NAMES[candidate])) {
967
+ field = candidate;
968
+ break;
969
+ }
970
+ }
971
+ }
972
+ this.propertyName =
973
+ field !== 0
974
+ ? CHANNEL_HEADER_FIELD_NAMES[field]
975
+ : (decoded ??
976
+ (materializeUnknown
977
+ ? this.bytes.toString('utf8', this.stringStart + 1, this.stringEnd - 1)
978
+ : ''));
979
+ return field;
980
+ }
981
+ readValue(integerOnly = false) {
982
+ const value = this.bytes[this.index];
983
+ if (value === 0x22)
984
+ return this.readString();
985
+ if (value === 0x7b)
986
+ return this.readObject();
987
+ if (value === 0x5b)
988
+ return this.readArray();
989
+ if (value === 0x74) {
990
+ this.readLiteral('true');
991
+ return true;
992
+ }
993
+ if (value === 0x66) {
994
+ this.readLiteral('false');
995
+ return false;
996
+ }
997
+ if (value === 0x6e) {
998
+ this.readLiteral('null');
999
+ return null;
1000
+ }
1001
+ return this.readNumber(integerOnly);
1002
+ }
1003
+ readObject() {
1004
+ this.index += 1;
1005
+ this.skipWhitespace();
1006
+ const object = {};
1007
+ if (this.consumeByte(0x7d))
1008
+ return object;
1009
+ for (;;) {
1010
+ const key = this.readString();
1011
+ this.skipWhitespace();
1012
+ this.expectByte(0x3a, "':' after object property");
1013
+ this.skipWhitespace();
1014
+ const value = this.readValue();
1015
+ if (key === '__proto__') {
1016
+ Object.defineProperty(object, key, {
1017
+ configurable: true,
1018
+ enumerable: true,
1019
+ value,
1020
+ writable: true
1021
+ });
1022
+ }
1023
+ else {
1024
+ object[key] = value;
1025
+ }
1026
+ this.skipWhitespace();
1027
+ if (this.consumeByte(0x7d))
1028
+ return object;
1029
+ this.expectByte(0x2c, "',' or '}' after object property");
1030
+ this.skipWhitespace();
1031
+ }
1032
+ }
1033
+ readArray() {
1034
+ this.index += 1;
1035
+ this.skipWhitespace();
1036
+ const array = [];
1037
+ if (this.consumeByte(0x5d))
1038
+ return array;
1039
+ for (;;) {
1040
+ array.push(this.readValue());
1041
+ this.skipWhitespace();
1042
+ if (this.consumeByte(0x5d))
1043
+ return array;
1044
+ this.expectByte(0x2c, "',' or ']' after array item");
1045
+ this.skipWhitespace();
1046
+ }
1047
+ }
1048
+ skipValue() {
1049
+ const value = this.bytes[this.index];
1050
+ if (value === 0x22) {
1051
+ this.scanString();
1052
+ return;
1053
+ }
1054
+ if (value === 0x7b)
1055
+ return this.skipObject();
1056
+ if (value === 0x5b)
1057
+ return this.skipArray();
1058
+ if (value === 0x74)
1059
+ return this.readLiteral('true');
1060
+ if (value === 0x66)
1061
+ return this.readLiteral('false');
1062
+ if (value === 0x6e)
1063
+ return this.readLiteral('null');
1064
+ this.readNumber();
1065
+ }
1066
+ skipObject() {
1067
+ this.index += 1;
1068
+ this.skipWhitespace();
1069
+ if (this.consumeByte(0x7d))
1070
+ return;
1071
+ for (;;) {
1072
+ this.readPropertyName();
1073
+ this.skipWhitespace();
1074
+ this.expectByte(0x3a, "':' after object property");
1075
+ this.skipWhitespace();
1076
+ this.skipValue();
1077
+ this.skipWhitespace();
1078
+ if (this.consumeByte(0x7d))
1079
+ return;
1080
+ this.expectByte(0x2c, "',' or '}' after object property");
1081
+ this.skipWhitespace();
1082
+ }
1083
+ }
1084
+ skipArray() {
1085
+ this.index += 1;
1086
+ this.skipWhitespace();
1087
+ if (this.consumeByte(0x5d))
1088
+ return;
1089
+ for (;;) {
1090
+ this.skipValue();
1091
+ this.skipWhitespace();
1092
+ if (this.consumeByte(0x5d))
1093
+ return;
1094
+ this.expectByte(0x2c, "',' or ']' after array item");
1095
+ this.skipWhitespace();
1096
+ }
1097
+ }
1098
+ readString() {
1099
+ this.scanString();
1100
+ return this.decodeString();
1101
+ }
1102
+ scanString() {
1103
+ if (this.bytes[this.index] !== 0x22)
1104
+ this.fail('string');
1105
+ this.stringStart = this.index++;
1106
+ this.stringHasEscapes = false;
1107
+ while (this.index < this.bytes.length) {
1108
+ const value = this.bytes[this.index++];
1109
+ if (value === 0x22) {
1110
+ this.stringEnd = this.index;
1111
+ return;
1112
+ }
1113
+ if (value < 0x20)
1114
+ this.fail('valid string character');
1115
+ if (value !== 0x5c)
1116
+ continue;
1117
+ this.stringHasEscapes = true;
1118
+ if (this.index === this.bytes.length)
1119
+ this.fail('valid string escape');
1120
+ const escaped = this.bytes[this.index++];
1121
+ if (escaped === 0x75) {
1122
+ for (let count = 0; count < 4; count += 1) {
1123
+ if (this.index === this.bytes.length || !isHexDigit(this.bytes[this.index]))
1124
+ this.fail('four hexadecimal digits after \\u');
1125
+ this.index += 1;
1126
+ }
1127
+ }
1128
+ else if (escaped !== 0x22 &&
1129
+ escaped !== 0x5c &&
1130
+ escaped !== 0x2f &&
1131
+ escaped !== 0x62 &&
1132
+ escaped !== 0x66 &&
1133
+ escaped !== 0x6e &&
1134
+ escaped !== 0x72 &&
1135
+ escaped !== 0x74) {
1136
+ this.fail('valid string escape');
1137
+ }
1138
+ }
1139
+ this.fail('terminated string');
1140
+ }
1141
+ decodeString() {
1142
+ return this.stringHasEscapes
1143
+ ? JSON.parse(this.bytes.toString('utf8', this.stringStart, this.stringEnd))
1144
+ : this.bytes.toString('utf8', this.stringStart + 1, this.stringEnd - 1);
1145
+ }
1146
+ readNumber(integerOnly = false) {
1147
+ const start = this.index;
1148
+ let hasFractionOrExponent = false;
1149
+ if (this.bytes[this.index] === 0x2d)
1150
+ this.index += 1;
1151
+ if (this.bytes[this.index] === 0x30) {
1152
+ this.index += 1;
1153
+ }
1154
+ else if (this.isDigitOneToNine(this.bytes[this.index])) {
1155
+ while (this.isDigit(this.bytes[this.index]))
1156
+ this.index += 1;
1157
+ }
1158
+ else {
1159
+ this.fail('JSON value');
1160
+ }
1161
+ if (this.bytes[this.index] === 0x2e) {
1162
+ hasFractionOrExponent = true;
1163
+ this.index += 1;
1164
+ if (!this.isDigit(this.bytes[this.index]))
1165
+ this.fail('digit after decimal point');
1166
+ while (this.isDigit(this.bytes[this.index]))
1167
+ this.index += 1;
1168
+ }
1169
+ if (this.bytes[this.index] === 0x65 || this.bytes[this.index] === 0x45) {
1170
+ hasFractionOrExponent = true;
1171
+ this.index += 1;
1172
+ if (this.bytes[this.index] === 0x2b || this.bytes[this.index] === 0x2d)
1173
+ this.index += 1;
1174
+ if (!this.isDigit(this.bytes[this.index]))
1175
+ this.fail('digit in exponent');
1176
+ while (this.isDigit(this.bytes[this.index]))
1177
+ this.index += 1;
1178
+ }
1179
+ if (integerOnly && hasFractionOrExponent) {
1180
+ throw new contracts_1.ZLinkFrameworkException(contracts_1.ZLinkFrameworkErrorKind.ProtocolError, 'Channel envelope integer fields must use an integer literal.');
1181
+ }
1182
+ if (integerOnly) {
1183
+ const negative = this.bytes[start] === 0x2d;
1184
+ const digitsStart = start + (negative ? 1 : 0);
1185
+ if (this.index - digitsStart <= 3) {
1186
+ let integer = 0;
1187
+ for (let offset = digitsStart; offset < this.index; offset += 1) {
1188
+ integer = integer * 10 + this.bytes[offset] - 0x30;
1189
+ }
1190
+ return negative ? -integer : integer;
1191
+ }
1192
+ }
1193
+ const number = Number(this.bytes.toString('ascii', start, this.index));
1194
+ if (!Number.isFinite(number)) {
1195
+ throw new TypeError('framework-json-v1 only accepts finite JSON numbers.');
1196
+ }
1197
+ return number;
1198
+ }
1199
+ readLiteral(value) {
1200
+ for (let offset = 0; offset < value.length; offset += 1) {
1201
+ if (this.bytes[this.index + offset] !== value.charCodeAt(offset))
1202
+ this.fail(value);
1203
+ }
1204
+ this.index += value.length;
1205
+ }
1206
+ matchesAscii(start, end, value) {
1207
+ if (end - start !== value.length)
1208
+ return false;
1209
+ for (let offset = 0; offset < value.length; offset += 1) {
1210
+ if (this.bytes[start + offset] !== value.charCodeAt(offset))
1211
+ return false;
1212
+ }
1213
+ return true;
1214
+ }
1215
+ isDigit(value) {
1216
+ return value !== undefined && value >= 0x30 && value <= 0x39;
1217
+ }
1218
+ isDigitOneToNine(value) {
1219
+ return value !== undefined && value >= 0x31 && value <= 0x39;
1220
+ }
1221
+ skipWhitespace() {
1222
+ while (this.bytes[this.index] === 0x20 ||
1223
+ this.bytes[this.index] === 0x09 ||
1224
+ this.bytes[this.index] === 0x0a ||
1225
+ this.bytes[this.index] === 0x0d) {
1226
+ this.index += 1;
1227
+ }
1228
+ }
1229
+ consumeByte(value) {
1230
+ if (this.bytes[this.index] !== value)
1231
+ return false;
1232
+ this.index += 1;
1233
+ return true;
1234
+ }
1235
+ expectByte(value, expected) {
1236
+ if (!this.consumeByte(value))
1237
+ this.fail(expected);
1238
+ }
1239
+ fail(expected) {
1240
+ throw new SyntaxError(`framework-json-v1 expected ${expected} at offset ${this.index}.`);
1241
+ }
1242
+ }
722
1243
  function schemaForInboundChannelEnvelope(header) {
723
1244
  const contract = (0, Attributes_1.readZLinkPacketJsonContract)(header.messageName);
724
1245
  return header.kind === 2 /* ZLinkChannelMessageKind.Response */ ? contract?.reply : contract?.payload;
@@ -797,8 +1318,13 @@ function validateCorrelationForKind(kind, correlationId) {
797
1318
  }
798
1319
  const MAXIMUM_CORRELATION_ID_BYTES = 64;
799
1320
  function isValidChannelCorrelationId(value) {
800
- const byteLength = Buffer.byteLength(value, 'utf8');
801
- return (byteLength >= 1 && byteLength <= MAXIMUM_CORRELATION_ID_BYTES && /^[\x00-\x7f]*$/.test(value));
1321
+ if (value.length < 1 || value.length > MAXIMUM_CORRELATION_ID_BYTES)
1322
+ return false;
1323
+ for (let index = 0; index < value.length; index++) {
1324
+ if (value.charCodeAt(index) > 0x7f)
1325
+ return false;
1326
+ }
1327
+ return true;
802
1328
  }
803
1329
  function validateCorrelationValue(correlationId) {
804
1330
  if (!isValidChannelCorrelationId(correlationId)) {
@@ -867,7 +1393,7 @@ function optionalFlowOrigin(value) {
867
1393
  }
868
1394
  function requireFlowId(value) {
869
1395
  const flowId = requireString(value, 'flowId');
870
- if (!/^[0-9a-f]{8}-[0-9a-f]{4}-7[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/.test(flowId)) {
1396
+ if (!CHANNEL_FLOW_TEXT.test(flowId)) {
871
1397
  throw new configuration_1.ZLinkConfigurationException('Channel envelope flowId must be a lowercase UUIDv7.');
872
1398
  }
873
1399
  return flowId;