@zlink-systems/framework 0.30.0 → 0.30.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (245) hide show
  1. package/LICENSE +150 -68
  2. package/dist/.tsbuildinfo +1 -1
  3. package/dist/contracts/Actors/ZLinkActorClient.d.ts +2 -1
  4. package/dist/contracts/Channels/Calls.d.ts +2 -1
  5. package/dist/contracts/Common/ZLinkMessageMetadata.js +11 -5
  6. package/dist/contracts/Handlers/Attributes.d.ts +5 -13
  7. package/dist/contracts/Handlers/Attributes.js +7 -11
  8. package/dist/contracts/Handlers/JsonContract.d.ts +2 -46
  9. package/dist/contracts/Handlers/JsonContract.js +4 -153
  10. package/dist/contracts/Spots/Contracts.d.ts +2 -1
  11. package/dist/nest-integration.d.ts +1 -1
  12. package/dist/nest-integration.js +2 -1
  13. package/dist/runtime/actors/actor-client.d.ts +1 -1
  14. package/dist/runtime/actors/actor-client.js +14 -12
  15. package/dist/runtime/actors/actor-handoff.d.ts +1 -1
  16. package/dist/runtime/actors/actor-handoff.js +7 -4
  17. package/dist/runtime/actors/actor-join-relocation.d.ts +1 -0
  18. package/dist/runtime/actors/actor-local-native-join.js +9 -12
  19. package/dist/runtime/actors/actor-remote-wire.js +15 -0
  20. package/dist/runtime/actors/actor-routed-join-transport.d.ts +6 -2
  21. package/dist/runtime/actors/actor-routed-json-request.d.ts +2 -0
  22. package/dist/runtime/actors/index.d.ts +2 -1
  23. package/dist/runtime/actors/index.js +18 -6
  24. package/dist/runtime/actors/spot-actor-dispatch.js +2 -2
  25. package/dist/runtime/admission.d.ts +1 -1
  26. package/dist/runtime/admission.js +15 -5
  27. package/dist/runtime/application-jobs/application-ingress-record-owner.d.ts +6 -8
  28. package/dist/runtime/application-jobs/application-ingress-record-owner.js +39 -22
  29. package/dist/runtime/application-jobs/application-job-queue-scope.d.ts +2 -1
  30. package/dist/runtime/application-jobs/application-job-queue-scope.js +37 -22
  31. package/dist/runtime/application-jobs/contracts.d.ts +10 -1
  32. package/dist/runtime/backend/contracts/index.d.ts +18 -9
  33. package/dist/runtime/backend/mesh-completion-table.d.ts +9 -1
  34. package/dist/runtime/backend/mesh-completion-table.js +149 -49
  35. package/dist/runtime/backend/mesh-dispatch-pump.d.ts +3 -0
  36. package/dist/runtime/backend/mesh-dispatch-pump.js +32 -11
  37. package/dist/runtime/backend/node/node-backend-adapter-support.d.ts +2 -2
  38. package/dist/runtime/backend/node/node-backend-adapter-support.js +16 -9
  39. package/dist/runtime/backend/node/node-dealer-channel-client-transport.d.ts +1 -1
  40. package/dist/runtime/backend/node/node-dealer-channel-client-transport.js +5 -2
  41. package/dist/runtime/backend/node/node-raw-binding-port.js +42 -22
  42. package/dist/runtime/backend/node/node-raw-mesh-backend.d.ts +13 -5
  43. package/dist/runtime/backend/node/node-raw-mesh-backend.js +69 -51
  44. package/dist/runtime/backend/node/node-socket-backend-adapter.js +6 -6
  45. package/dist/runtime/backend/raw-binding-port.d.ts +2 -2
  46. package/dist/runtime/backend/runtime-message.d.ts +1 -0
  47. package/dist/runtime/backend/runtime-message.js +5 -0
  48. package/dist/runtime/backend/runtime-values.d.ts +1 -0
  49. package/dist/runtime/backend/runtime-values.js +2 -1
  50. package/dist/runtime/channels/channel-clients.d.ts +1 -0
  51. package/dist/runtime/channels/channel-clients.js +58 -21
  52. package/dist/runtime/channels/channel-dispatch-pipeline.d.ts +3 -2
  53. package/dist/runtime/channels/channel-dispatch-pipeline.js +20 -11
  54. package/dist/runtime/channels/channel-dispatch-services.d.ts +1 -0
  55. package/dist/runtime/channels/channel-dispatch-services.js +45 -0
  56. package/dist/runtime/channels/channel-dispatchers.d.ts +1 -1
  57. package/dist/runtime/channels/channel-dispatchers.js +27 -26
  58. package/dist/runtime/channels/channel-envelope-inspection.d.ts +1 -2
  59. package/dist/runtime/channels/channel-envelope-inspection.js +1 -16
  60. package/dist/runtime/channels/channel-envelope.d.ts +1 -0
  61. package/dist/runtime/channels/channel-envelope.js +83 -8
  62. package/dist/runtime/channels/channel-outbound-operations.d.ts +2 -2
  63. package/dist/runtime/channels/channel-outbound-operations.js +8 -8
  64. package/dist/runtime/channels/channel-runtime-manager.d.ts +6 -6
  65. package/dist/runtime/channels/channel-runtime-manager.js +12 -12
  66. package/dist/runtime/channels/channel-transports.d.ts +18 -15
  67. package/dist/runtime/channels/channel-transports.js +48 -31
  68. package/dist/runtime/channels/local-spot-route-transport.d.ts +1 -1
  69. package/dist/runtime/channels/local-spot-route-transport.js +2 -1
  70. package/dist/runtime/channels/router-socket-spot-route-transport.d.ts +2 -2
  71. package/dist/runtime/channels/router-socket-spot-route-transport.js +4 -4
  72. package/dist/runtime/channels/source-spot-router.d.ts +2 -2
  73. package/dist/runtime/channels/source-spot-router.js +4 -4
  74. package/dist/runtime/channels/spot-node-route-transport.d.ts +2 -2
  75. package/dist/runtime/channels/spot-node-route-transport.js +4 -4
  76. package/dist/runtime/channels/spot-route-bridge-transport.d.ts +2 -2
  77. package/dist/runtime/channels/spot-route-bridge-transport.js +4 -4
  78. package/dist/runtime/channels/spot-route-dispatch-strategy.d.ts +5 -4
  79. package/dist/runtime/channels/spot-route-dispatch-strategy.js +18 -18
  80. package/dist/runtime/execution/serial-execution-queue.d.ts +1 -0
  81. package/dist/runtime/execution/serial-execution-queue.js +1 -0
  82. package/dist/runtime/foundation/actor-join-recovery-codec.js +2 -2
  83. package/dist/runtime/foundation/durable-service-request.d.ts +14 -0
  84. package/dist/runtime/foundation/durable-service-request.js +98 -0
  85. package/dist/runtime/foundation/operation-identity.d.ts +1 -0
  86. package/dist/runtime/foundation/operation-identity.js +5 -1
  87. package/dist/runtime/foundation/raw-service-mesh-runtime.d.ts +22 -5
  88. package/dist/runtime/foundation/raw-service-mesh-runtime.js +356 -232
  89. package/dist/runtime/foundation/service-relocation-object-owner.d.ts +1 -0
  90. package/dist/runtime/foundation/service-relocation-object-owner.js +1 -0
  91. package/dist/runtime/foundation/service-relocation-runtime.d.ts +2 -0
  92. package/dist/runtime/foundation/service-relocation-runtime.js +13 -1
  93. package/dist/runtime/foundation/service-runtime-contracts.d.ts +2 -0
  94. package/dist/runtime/foundation/service-stateful-runtime.d.ts +4 -4
  95. package/dist/runtime/foundation/service-stateful-runtime.js +44 -103
  96. package/dist/runtime/foundation/service-stateful-wire-codec.d.ts +0 -5
  97. package/dist/runtime/foundation/service-topology-registry.d.ts +12 -2
  98. package/dist/runtime/foundation/service-topology-registry.js +61 -27
  99. package/dist/runtime/foundation/service-wire-m6a-codec.d.ts +3 -3
  100. package/dist/runtime/foundation/service-wire-m6a-codec.js +36 -38
  101. package/dist/runtime/handlers/handler-instance-scope.d.ts +8 -0
  102. package/dist/runtime/handlers/handler-instance-scope.js +54 -11
  103. package/dist/runtime/host/actor-runtime-options-factory.js +2 -2
  104. package/dist/runtime/host/application-job-queue.d.ts +19 -7
  105. package/dist/runtime/host/application-job-queue.js +150 -42
  106. package/dist/runtime/host/entry-actor-runtime.d.ts +1 -0
  107. package/dist/runtime/host/entry-actor-runtime.js +3 -0
  108. package/dist/runtime/host/index.d.ts +7 -1
  109. package/dist/runtime/host/index.js +142 -118
  110. package/dist/runtime/host/remote-bound-session-relay.js +2 -18
  111. package/dist/runtime/host/route-mesh-runtime.js +1 -1
  112. package/dist/runtime/host/service-relocation-control.d.ts +1 -0
  113. package/dist/runtime/host/service-relocation-control.js +10 -4
  114. package/dist/runtime/host/service-relocation-host-runtime.d.ts +6 -8
  115. package/dist/runtime/host/service-relocation-host-runtime.js +213 -241
  116. package/dist/runtime/host/spot-address-transport.js +3 -2
  117. package/dist/runtime/host/spot-runtime-options-factory.js +1 -0
  118. package/dist/runtime/locations/actor-location-claims.d.ts +2 -2
  119. package/dist/runtime/locations/actor-location-claims.js +34 -19
  120. package/dist/runtime/locations/lifecycle.d.ts +1 -2
  121. package/dist/runtime/locations/lifecycle.js +2 -5
  122. package/dist/runtime/locations/runtime.d.ts +1 -1
  123. package/dist/runtime/locations/runtime.js +24 -23
  124. package/dist/runtime/messaging/framework-json-v1.d.ts +4 -6
  125. package/dist/runtime/messaging/framework-json-v1.js +38 -294
  126. package/dist/runtime/messaging/packet-name.d.ts +1 -1
  127. package/dist/runtime/messaging/packet-name.js +8 -24
  128. package/dist/runtime/messaging/request-result.d.ts +2 -0
  129. package/dist/runtime/messaging/request-result.js +54 -0
  130. package/dist/runtime/messaging/submission-result.d.ts +1 -0
  131. package/dist/runtime/messaging/submission-result.js +5 -2
  132. package/dist/runtime/protocol/service_wire_codec.generated.d.ts +15 -0
  133. package/dist/runtime/protocol/service_wire_codec.generated.js +144 -0
  134. package/dist/runtime/protocol/service_wire_pilot_codec.generated.d.ts +9 -0
  135. package/dist/runtime/protocol/service_wire_pilot_codec.generated.js +14 -1
  136. package/dist/runtime/spots/formal-remote-actor-admission-registry.d.ts +7 -2
  137. package/dist/runtime/spots/formal-remote-actor-admission-registry.js +33 -19
  138. package/dist/runtime/spots/index.d.ts +3 -0
  139. package/dist/runtime/spots/index.js +9 -2
  140. package/dist/runtime/spots/spot-activation.d.ts +1 -0
  141. package/dist/runtime/spots/spot-activation.js +17 -8
  142. package/dist/runtime/spots/spot-entry-activation.js +6 -2
  143. package/dist/runtime/spots/spot-handler-registry.d.ts +3 -1
  144. package/dist/runtime/spots/spot-handler-registry.js +18 -8
  145. package/dist/runtime/spots/spot-node-autoconnect.js +4 -3
  146. package/dist/runtime/spots/spot-outbound.d.ts +3 -0
  147. package/dist/runtime/spots/spot-outbound.js +24 -15
  148. package/dist/runtime/spots/spot-routed-spot-packet-dispatch.d.ts +1 -0
  149. package/dist/runtime/spots/spot-routed-spot-packet-dispatch.js +1 -1
  150. package/dist/runtime/spots/spot-runtime-ports.d.ts +1 -0
  151. package/dist/runtime/spots/spot-subscription-dispatch.js +0 -3
  152. package/dist/runtime/spots/spot-timer.js +1 -0
  153. package/dist/runtime/streams/stream-session-runtime.d.ts +1 -1
  154. package/dist/runtime/streams/stream-session-runtime.js +13 -27
  155. package/package.json +2 -2
  156. package/src/contracts/Actors/ZLinkActorClient.ts +2 -1
  157. package/src/contracts/Channels/Calls.ts +2 -1
  158. package/src/contracts/Common/ZLinkMessageMetadata.ts +13 -8
  159. package/src/contracts/Handlers/Attributes.ts +14 -21
  160. package/src/contracts/Handlers/JsonContract.ts +8 -216
  161. package/src/contracts/Spots/Contracts.ts +2 -1
  162. package/src/nest-integration.ts +1 -0
  163. package/src/runtime/actors/actor-client.ts +40 -16
  164. package/src/runtime/actors/actor-handoff.ts +9 -4
  165. package/src/runtime/actors/actor-join-relocation.ts +1 -0
  166. package/src/runtime/actors/actor-local-native-join.ts +17 -26
  167. package/src/runtime/actors/actor-remote-wire.ts +17 -0
  168. package/src/runtime/actors/actor-routed-join-transport.ts +14 -4
  169. package/src/runtime/actors/actor-routed-json-request.ts +10 -2
  170. package/src/runtime/actors/index.ts +19 -5
  171. package/src/runtime/actors/spot-actor-dispatch.ts +4 -2
  172. package/src/runtime/admission.ts +18 -5
  173. package/src/runtime/application-jobs/application-ingress-record-owner.ts +41 -25
  174. package/src/runtime/application-jobs/application-job-queue-scope.ts +51 -22
  175. package/src/runtime/application-jobs/contracts.ts +14 -1
  176. package/src/runtime/backend/contracts/index.ts +53 -14
  177. package/src/runtime/backend/mesh-completion-table.ts +156 -57
  178. package/src/runtime/backend/mesh-dispatch-pump.ts +40 -10
  179. package/src/runtime/backend/node/node-backend-adapter-support.ts +17 -8
  180. package/src/runtime/backend/node/node-dealer-channel-client-transport.ts +12 -2
  181. package/src/runtime/backend/node/node-raw-binding-port.ts +57 -30
  182. package/src/runtime/backend/node/node-raw-mesh-backend.ts +128 -65
  183. package/src/runtime/backend/node/node-socket-backend-adapter.ts +21 -6
  184. package/src/runtime/backend/raw-binding-port.ts +7 -2
  185. package/src/runtime/backend/runtime-message.ts +6 -0
  186. package/src/runtime/backend/runtime-values.ts +1 -0
  187. package/src/runtime/channels/channel-clients.ts +90 -41
  188. package/src/runtime/channels/channel-dispatch-pipeline.ts +69 -34
  189. package/src/runtime/channels/channel-dispatch-services.ts +69 -1
  190. package/src/runtime/channels/channel-dispatchers.ts +29 -27
  191. package/src/runtime/channels/channel-envelope-inspection.ts +2 -16
  192. package/src/runtime/channels/channel-envelope.ts +133 -8
  193. package/src/runtime/channels/channel-outbound-operations.ts +22 -8
  194. package/src/runtime/channels/channel-runtime-manager.ts +29 -12
  195. package/src/runtime/channels/channel-transports.ts +128 -60
  196. package/src/runtime/channels/local-spot-route-transport.ts +3 -1
  197. package/src/runtime/channels/router-socket-spot-route-transport.ts +13 -4
  198. package/src/runtime/channels/source-spot-router.ts +8 -4
  199. package/src/runtime/channels/spot-node-route-transport.ts +8 -4
  200. package/src/runtime/channels/spot-route-bridge-transport.ts +6 -4
  201. package/src/runtime/channels/spot-route-dispatch-strategy.ts +47 -18
  202. package/src/runtime/execution/serial-execution-queue.ts +2 -0
  203. package/src/runtime/foundation/actor-join-recovery-codec.ts +2 -2
  204. package/src/runtime/foundation/durable-service-request.ts +137 -0
  205. package/src/runtime/foundation/operation-identity.ts +5 -1
  206. package/src/runtime/foundation/raw-service-mesh-runtime.ts +484 -293
  207. package/src/runtime/foundation/service-relocation-object-owner.ts +2 -0
  208. package/src/runtime/foundation/service-relocation-runtime.ts +18 -1
  209. package/src/runtime/foundation/service-runtime-contracts.ts +7 -1
  210. package/src/runtime/foundation/service-stateful-runtime.ts +67 -125
  211. package/src/runtime/foundation/service-stateful-wire-codec.ts +0 -5
  212. package/src/runtime/foundation/service-topology-registry.ts +91 -36
  213. package/src/runtime/foundation/service-wire-m6a-codec.ts +57 -38
  214. package/src/runtime/handlers/handler-instance-scope.ts +67 -16
  215. package/src/runtime/host/actor-runtime-options-factory.ts +13 -2
  216. package/src/runtime/host/application-job-queue.ts +175 -41
  217. package/src/runtime/host/entry-actor-runtime.ts +4 -0
  218. package/src/runtime/host/index.ts +201 -156
  219. package/src/runtime/host/remote-bound-session-relay.ts +2 -23
  220. package/src/runtime/host/route-mesh-runtime.ts +1 -1
  221. package/src/runtime/host/service-relocation-control.ts +11 -5
  222. package/src/runtime/host/service-relocation-host-runtime.ts +315 -291
  223. package/src/runtime/host/spot-address-transport.ts +4 -2
  224. package/src/runtime/host/spot-runtime-options-factory.ts +2 -0
  225. package/src/runtime/locations/actor-location-claims.ts +52 -30
  226. package/src/runtime/locations/lifecycle.ts +8 -26
  227. package/src/runtime/locations/runtime.ts +28 -24
  228. package/src/runtime/messaging/framework-json-v1.ts +5 -325
  229. package/src/runtime/messaging/packet-name.ts +5 -25
  230. package/src/runtime/messaging/request-result.ts +58 -0
  231. package/src/runtime/messaging/submission-result.ts +5 -1
  232. package/src/runtime/protocol/service_wire_codec.generated.ts +131 -1
  233. package/src/runtime/protocol/service_wire_pilot_codec.generated.ts +4 -4
  234. package/src/runtime/spots/formal-remote-actor-admission-registry.ts +43 -23
  235. package/src/runtime/spots/index.ts +14 -2
  236. package/src/runtime/spots/spot-activation.ts +28 -10
  237. package/src/runtime/spots/spot-entry-activation.ts +9 -2
  238. package/src/runtime/spots/spot-handler-registry.ts +41 -8
  239. package/src/runtime/spots/spot-node-autoconnect.ts +6 -2
  240. package/src/runtime/spots/spot-outbound.ts +36 -16
  241. package/src/runtime/spots/spot-routed-spot-packet-dispatch.ts +2 -1
  242. package/src/runtime/spots/spot-runtime-ports.ts +1 -0
  243. package/src/runtime/spots/spot-subscription-dispatch.ts +0 -3
  244. package/src/runtime/spots/spot-timer.ts +5 -1
  245. package/src/runtime/streams/stream-session-runtime.ts +12 -29
@@ -30,7 +30,7 @@ export declare class ZLinkNodeRawMeshBackend implements ZLinkBackendMeshNode {
30
30
  private readonly channels;
31
31
  private readonly peerIntents;
32
32
  private completionHandler?;
33
- private readonly routingId;
33
+ readonly routingId: string;
34
34
  private readonly lifecycleGeneration;
35
35
  private bindEndpoint?;
36
36
  private advertiseHost?;
@@ -80,7 +80,7 @@ export declare class ZLinkNodeRawMeshBackend implements ZLinkBackendMeshNode {
80
80
  selectObjectPlacement(stableType: string): ZLinkBackendObjectPlacement;
81
81
  instanceSpotPlacementTypes(): readonly string[];
82
82
  sendToMissingInstanceSpot(target: ServiceInstanceColdActivationTarget, parts: MessageLike | readonly MessageLike[], deadlineUnixMs: bigint, sourceSpotId?: string, metadata?: ReadonlyMap<string, string>): Promise<SubmitResult>;
83
- requestToMissingInstanceSpot(target: ServiceInstanceColdActivationTarget, parts: MessageLike | readonly MessageLike[], deadlineUnixMs: bigint, sourceSpotId?: string, metadata?: ReadonlyMap<string, string>): MeshOperationId;
83
+ requestToMissingInstanceSpot(target: ServiceInstanceColdActivationTarget, parts: MessageLike | readonly MessageLike[], deadlineUnixMs: bigint, sourceSpotId?: string, metadata?: ReadonlyMap<string, string>, onAdmitted?: () => void): MeshOperationId;
84
84
  setRoutingId(routingId: unknown): void;
85
85
  setBind(endpoint: string): void;
86
86
  setAdvertiseHost(host: string): void;
@@ -114,19 +114,25 @@ export declare class ZLinkNodeRawMeshBackend implements ZLinkBackendMeshNode {
114
114
  readonly endpoint: string;
115
115
  }[]): void;
116
116
  isObjectClientNodeDirectTarget(targetRid: unknown): boolean;
117
+ observePeerRoute(targetRid: unknown): import("../../foundation/durable-service-request").PeerRouteObservation;
118
+ hasPeerRouteOrConnectionIntent(targetRid: unknown, endpoint: string): boolean;
117
119
  isPeerRouteReady(targetRid: unknown, lifecycleGeneration?: bigint): boolean;
118
- sendToNode(targetRid: unknown, parts: MessageLike | readonly MessageLike[]): Promise<SubmitResultValue>;
120
+ sendToNode(targetRid: unknown, parts: MessageLike | readonly MessageLike[]): SubmitResultValue | Promise<SubmitResultValue>;
119
121
  sendInfrastructureControl(targetRid: unknown, record: Uint8Array | readonly Uint8Array[]): Promise<SubmitResultValue>;
120
122
  sendInfrastructureControlFrames(targetRid: unknown, frames: readonly Uint8Array[]): Promise<SubmitResultValue>;
121
123
  requestInfrastructureControlFrames(targetRid: unknown, frames: readonly Uint8Array[], options?: {
122
124
  readonly timeoutMs?: number;
125
+ readonly signal?: AbortSignal;
126
+ readonly onSubmitted?: (signal: AbortSignal) => Promise<void>;
123
127
  }): Promise<readonly Uint8Array[]>;
124
128
  requestToNode(targetRid: unknown, parts: MessageLike | readonly MessageLike[], options?: {
125
129
  readonly timeoutMs?: number;
130
+ readonly onAdmitted?: () => void;
126
131
  }): MeshOperationId;
127
132
  sendToChannel(channelName: string, parts: MessageLike | readonly MessageLike[]): Promise<SubmitResultValue>;
128
133
  requestToChannel(channelName: string, parts: MessageLike | readonly MessageLike[], options?: {
129
134
  readonly timeoutMs?: number;
135
+ readonly onAdmitted?: () => void;
130
136
  }): MeshOperationId;
131
137
  status(): {
132
138
  state: MeshNodeRuntimeState;
@@ -196,7 +202,7 @@ export declare class ZLinkNodeRawMeshBackend implements ZLinkBackendMeshNode {
196
202
  commitSpotMessageFollowIngress(seal: ServiceSpotMessageFollowSeal, target: ServiceDirectSpotRouteFence, durationMs: number): Promise<boolean>;
197
203
  forgetSpotRoute(spot: ServiceSpotRouteFence['spot'], authorityOwnerGeneration: bigint, storeVersion?: string): void;
198
204
  sendToInstanceSpot(route: ServiceInstanceRouteFence, parts: MessageLike | readonly MessageLike[], sourceSpotId?: string, metadata?: ReadonlyMap<string, string>, instanceIntent?: boolean): Promise<SubmitResult>;
199
- requestInstanceSpot(route: ServiceInstanceRouteFence, parts: MessageLike | readonly MessageLike[], timeoutMs?: number, sourceSpotId?: string, metadata?: ReadonlyMap<string, string>, instanceIntent?: boolean): MeshOperationId;
205
+ requestInstanceSpot(route: ServiceInstanceRouteFence, parts: MessageLike | readonly MessageLike[], timeoutMs?: number, sourceSpotId?: string, metadata?: ReadonlyMap<string, string>, instanceIntent?: boolean, onAdmitted?: () => void): MeshOperationId;
200
206
  actorLookup(actorId: string): {
201
207
  actor: ServiceActorRef;
202
208
  spotId: string;
@@ -226,17 +232,19 @@ export declare class ZLinkNodeRawMeshBackend implements ZLinkBackendMeshNode {
226
232
  sendToActor(actor: ZLinkBackendActorRef, parts: MessageLike | readonly MessageLike[]): Promise<SubmitResultValue>;
227
233
  requestToActor(actor: ZLinkBackendActorRef, parts: MessageLike | readonly MessageLike[], options?: {
228
234
  readonly timeoutMs?: number;
235
+ readonly onAdmitted?: () => void;
229
236
  }): MeshOperationId;
230
237
  actorSendToActor(source: ZLinkBackendActorRef, target: ZLinkBackendActorRef, parts: MessageLike | readonly MessageLike[]): Promise<SubmitResultValue>;
231
238
  actorRequestToActor(source: ZLinkBackendActorRef, target: ZLinkBackendActorRef, parts: MessageLike | readonly MessageLike[], options?: {
232
239
  readonly timeoutMs?: number;
240
+ readonly onAdmitted?: () => void;
233
241
  }): MeshOperationId;
234
242
  sendActorBoundSession(actor: ZLinkBackendActorRef, expectedBindingGeneration: bigint, parts: MessageLike | readonly MessageLike[], _flags?: number): Promise<SubmitResultValue>;
235
243
  closeActorBoundSession(actor: ZLinkBackendActorRef, expectedBindingGeneration: bigint, timeoutMs?: number): MeshOperationId;
236
244
  leaveActor(actor: ZLinkBackendActorRef, expectedMembershipEpoch: bigint, timeoutMs?: number): MeshOperationId;
237
245
  createStreamSessionService(stream: unknown): StreamSessionService;
238
246
  sendFromSpot(source: ServiceSpotState, target: ServiceDirectSpotRouteFence, parts: MessageLike | readonly MessageLike[]): Promise<SubmitResultValue>;
239
- requestFromSpot(source: ServiceSpotState, target: ServiceDirectSpotRouteFence, parts: MessageLike | readonly MessageLike[], timeoutMs: number): MeshOperationId;
247
+ requestFromSpot(source: ServiceSpotState, target: ServiceDirectSpotRouteFence, parts: MessageLike | readonly MessageLike[], timeoutMs: number, onAdmitted?: () => void): MeshOperationId;
240
248
  closeSpot(state: ServiceSpotState): boolean;
241
249
  publishFromSpot(state: ServiceSpotState, channelName: string, topic: string, parts: MessageLike | readonly MessageLike[]): Promise<void>;
242
250
  setSpotSubscription(state: ServiceSpotState, channelName: string, topicFilter: string): void;
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ZLinkNodeRawMeshBackend = void 0;
4
4
  exports.requestFailureResult = requestFailureResult;
5
+ const durable_service_request_1 = require("../../foundation/durable-service-request");
5
6
  const stream_wire_1 = require("@zlink-systems/stream-wire");
6
7
  const zlink_1 = require("@zlink-systems/zlink");
7
8
  const node_crypto_1 = require("node:crypto");
@@ -168,8 +169,8 @@ class ZLinkNodeRawMeshBackend {
168
169
  const result = await this.requireStateful().sendToMissingInstanceSpotFrame(target, encodeMultipartApplicationFrame(parts), deadlineUnixMs, sourceSpotId, metadata === undefined ? undefined : (0, service_metadata_codec_1.encodeServiceMetadataFrame)(metadata));
169
170
  return result;
170
171
  }
171
- requestToMissingInstanceSpot(target, parts, deadlineUnixMs, sourceSpotId, metadata) {
172
- return this.observeStateful(service_runtime_contracts_1.OperationKind.InstanceSpotRequest, this.requireStateful().requestToMissingInstanceSpotFrame(target, encodeMultipartApplicationFrame(parts), deadlineUnixMs, sourceSpotId, metadata === undefined ? undefined : (0, service_metadata_codec_1.encodeServiceMetadataFrame)(metadata)));
172
+ requestToMissingInstanceSpot(target, parts, deadlineUnixMs, sourceSpotId, metadata, onAdmitted) {
173
+ return this.observeStateful(service_runtime_contracts_1.OperationKind.InstanceSpotRequest, this.requireStateful().requestToMissingInstanceSpotFrame(target, encodeMultipartApplicationFrame(parts), deadlineUnixMs, sourceSpotId, metadata === undefined ? undefined : (0, service_metadata_codec_1.encodeServiceMetadataFrame)(metadata), onAdmitted));
173
174
  }
174
175
  setRoutingId(routingId) {
175
176
  if (String(routingId) !== this.routingId) {
@@ -221,13 +222,7 @@ class ZLinkNodeRawMeshBackend {
221
222
  }
222
223
  }
223
224
  },
224
- onPeerDisconnected: (nodeRoutingId, endpoint) => {
225
- for (const [intentId, peer] of this.peerIntents) {
226
- if (peer.endpoint === endpoint &&
227
- (peer.nodeRoutingId === undefined || peer.nodeRoutingId === nodeRoutingId)) {
228
- this.peerIntents.delete(intentId);
229
- }
230
- }
225
+ onPeerDisconnected: (_nodeRoutingId, endpoint) => {
231
226
  for (const handler of this.peerDisconnectedHandlers)
232
227
  handler(endpoint);
233
228
  }
@@ -379,13 +374,28 @@ class ZLinkNodeRawMeshBackend {
379
374
  isObjectClientNodeDirectTarget(targetRid) {
380
375
  return this.requireRuntime().isObjectClientNodeDirectTarget(String(targetRid));
381
376
  }
377
+ observePeerRoute(targetRid) {
378
+ return this.requireRuntime().observePeerRoute(String(targetRid));
379
+ }
380
+ hasPeerRouteOrConnectionIntent(targetRid, endpoint) {
381
+ const rid = String(targetRid);
382
+ if (this.requireRuntime().hasSelectedPeerRoute(rid))
383
+ return true;
384
+ for (const intent of this.peerIntents.values()) {
385
+ if (intent.nodeRoutingId === rid ||
386
+ (intent.nodeRoutingId === undefined && intent.endpoint === endpoint))
387
+ return true;
388
+ }
389
+ return false;
390
+ }
382
391
  isPeerRouteReady(targetRid, lifecycleGeneration) {
383
392
  return this.requireRuntime().isPeerRouteReady(String(targetRid), lifecycleGeneration);
384
393
  }
385
- async sendToNode(targetRid, parts) {
386
- return (await this.requireRuntime().sendToNode(String(targetRid), encodeMultipartApplicationFrame(parts)))
387
- ? zlink_1.SubmitResult.Ok
388
- : zlink_1.SubmitResult.NotConnected;
394
+ sendToNode(targetRid, parts) {
395
+ const submitted = this.requireRuntime().sendToNode(String(targetRid), encodeMultipartApplicationFrame(parts));
396
+ return submitted instanceof Promise
397
+ ? submitted.then(nodeSendResult)
398
+ : nodeSendResult(submitted);
389
399
  }
390
400
  async sendInfrastructureControl(targetRid, record) {
391
401
  return (await this.requireRuntime().sendService(String(targetRid), (Array.isArray(record) ? record : [record]).map((value) => Buffer.from(value))))
@@ -398,17 +408,17 @@ class ZLinkNodeRawMeshBackend {
398
408
  : zlink_1.SubmitResult.NotConnected;
399
409
  }
400
410
  async requestInfrastructureControlFrames(targetRid, frames, options) {
401
- return await this.requireRuntime().requestService(String(targetRid), frames.map((frame) => Buffer.from(frame)), options?.timeoutMs ?? Registration_1.DEFAULT_REQUEST_TIMEOUT_MS);
411
+ return (0, durable_service_request_1.requestDurableService)(this.requireRuntime(), String(targetRid), frames, performance.now() + (options?.timeoutMs ?? Registration_1.DEFAULT_REQUEST_TIMEOUT_MS), 'relocation control', options?.signal, options?.onSubmitted);
402
412
  }
403
413
  requestToNode(targetRid, parts, options) {
404
- const pending = this.requireRuntime().requestToNode(String(targetRid), encodeMultipartApplicationFrame(parts), options?.timeoutMs ?? Registration_1.DEFAULT_REQUEST_TIMEOUT_MS);
414
+ const pending = this.requireRuntime().requestToNode(String(targetRid), encodeMultipartApplicationFrame(parts), options?.timeoutMs ?? Registration_1.DEFAULT_REQUEST_TIMEOUT_MS, options?.onAdmitted);
405
415
  return this.observeCompletion(pending.id, service_runtime_contracts_1.OperationKind.NodeRequest, pending.promise);
406
416
  }
407
417
  async sendToChannel(channelName, parts) {
408
418
  return this.requireRuntime().sendToChannel(channelName, encodeMultipartApplicationFrame(parts));
409
419
  }
410
420
  requestToChannel(channelName, parts, options) {
411
- const pending = this.requireRuntime().requestToChannel(channelName, encodeMultipartApplicationFrame(parts), options?.timeoutMs ?? Registration_1.DEFAULT_REQUEST_TIMEOUT_MS);
421
+ const pending = this.requireRuntime().requestToChannel(channelName, encodeMultipartApplicationFrame(parts), options?.timeoutMs ?? Registration_1.DEFAULT_REQUEST_TIMEOUT_MS, options?.onAdmitted);
412
422
  return this.observeCompletion(pending.id, service_runtime_contracts_1.OperationKind.ChannelRequest, pending.promise);
413
423
  }
414
424
  status() {
@@ -666,8 +676,8 @@ class ZLinkNodeRawMeshBackend {
666
676
  const result = await this.requireStateful().sendToInstanceSpot(route, encodeMultipart(parts), sourceSpotId, metadata === undefined ? undefined : (0, service_metadata_codec_1.encodeServiceMetadataFrame)(metadata), instanceIntent);
667
677
  return result;
668
678
  }
669
- requestInstanceSpot(route, parts, timeoutMs = Registration_1.DEFAULT_REQUEST_TIMEOUT_MS, sourceSpotId, metadata, instanceIntent = false) {
670
- return this.observeStateful(service_runtime_contracts_1.OperationKind.InstanceSpotRequest, this.requireStateful().requestToInstanceSpot(route, encodeMultipart(parts), timeoutMs, sourceSpotId, metadata === undefined ? undefined : (0, service_metadata_codec_1.encodeServiceMetadataFrame)(metadata), instanceIntent));
679
+ requestInstanceSpot(route, parts, timeoutMs = Registration_1.DEFAULT_REQUEST_TIMEOUT_MS, sourceSpotId, metadata, instanceIntent = false, onAdmitted) {
680
+ return this.observeStateful(service_runtime_contracts_1.OperationKind.InstanceSpotRequest, this.requireStateful().requestToInstanceSpot(route, encodeMultipart(parts), timeoutMs, sourceSpotId, metadata === undefined ? undefined : (0, service_metadata_codec_1.encodeServiceMetadataFrame)(metadata), instanceIntent, onAdmitted));
671
681
  }
672
682
  actorLookup(actorId) {
673
683
  const actor = this.requireStateful().actor(actorId);
@@ -707,13 +717,13 @@ class ZLinkNodeRawMeshBackend {
707
717
  return this.requireStateful().sendToActor(actor, this.peerGeneration(String(actor.nodeRid)), actor.generation, encodeMultipart(parts));
708
718
  }
709
719
  requestToActor(actor, parts, options) {
710
- return this.observeStateful(service_runtime_contracts_1.OperationKind.ActorRequest, this.requireStateful().requestToActor(actor, this.peerGeneration(String(actor.nodeRid)), actor.generation, encodeMultipart(parts), options?.timeoutMs ?? Registration_1.DEFAULT_REQUEST_TIMEOUT_MS));
720
+ return this.observeStateful(service_runtime_contracts_1.OperationKind.ActorRequest, this.requireStateful().requestToActor(actor, this.peerGeneration(String(actor.nodeRid)), actor.generation, encodeMultipart(parts), options?.timeoutMs ?? Registration_1.DEFAULT_REQUEST_TIMEOUT_MS, undefined, undefined, options?.onAdmitted));
711
721
  }
712
722
  async actorSendToActor(source, target, parts) {
713
723
  return (await this.requireStateful().sendToActor(target, this.peerGeneration(String(target.nodeRid)), target.generation, encodeMultipart(parts), source));
714
724
  }
715
725
  actorRequestToActor(source, target, parts, options) {
716
- return this.observeStateful(service_runtime_contracts_1.OperationKind.ActorRequest, this.requireStateful().requestToActor(target, this.peerGeneration(String(target.nodeRid)), target.generation, encodeMultipart(parts), options?.timeoutMs ?? Registration_1.DEFAULT_REQUEST_TIMEOUT_MS, source));
726
+ return this.observeStateful(service_runtime_contracts_1.OperationKind.ActorRequest, this.requireStateful().requestToActor(target, this.peerGeneration(String(target.nodeRid)), target.generation, encodeMultipart(parts), options?.timeoutMs ?? Registration_1.DEFAULT_REQUEST_TIMEOUT_MS, source, undefined, options?.onAdmitted));
717
727
  }
718
728
  async sendActorBoundSession(actor, expectedBindingGeneration, parts, _flags) {
719
729
  return (await this.requireStateful().sendBoundSession(actor, expectedBindingGeneration, encodeMultipart(parts)));
@@ -734,8 +744,8 @@ class ZLinkNodeRawMeshBackend {
734
744
  async sendFromSpot(source, target, parts) {
735
745
  return (await this.requireStateful().sendToSpot(source.ref.spotId, target, encodeMultipart(parts)));
736
746
  }
737
- requestFromSpot(source, target, parts, timeoutMs) {
738
- return this.observeStateful(service_runtime_contracts_1.OperationKind.SpotRequest, this.requireStateful().requestToSpot(source.ref.spotId, target, encodeMultipart(parts), timeoutMs));
747
+ requestFromSpot(source, target, parts, timeoutMs, onAdmitted) {
748
+ return this.observeStateful(service_runtime_contracts_1.OperationKind.SpotRequest, this.requireStateful().requestToSpot(source.ref.spotId, target, encodeMultipart(parts), timeoutMs, onAdmitted));
739
749
  }
740
750
  closeSpot(state) {
741
751
  return this.requireStateful().registry.closeSpot(state.ref);
@@ -744,6 +754,8 @@ class ZLinkNodeRawMeshBackend {
744
754
  await this.requireStateful().publishLogicalMulticast(channelName, topic, encodeMultipart(parts), state.ref.spotId);
745
755
  }
746
756
  setSpotSubscription(state, channelName, topicFilter) {
757
+ if (!this.channels.has(channelName))
758
+ throw new contracts_1.ZLinkFrameworkException(contracts_1.ZLinkFrameworkErrorKind.InvalidOperation, `Spot does not participate in subscription channel '${channelName}'.`);
747
759
  this.requireStateful().setSubscription(state, channelName, topicFilter);
748
760
  }
749
761
  unsetSpotSubscription(state, channelName, topicFilter) {
@@ -953,7 +965,7 @@ class RawServiceSpot {
953
965
  const routeFence = requireDirectSpotRouteFence(options?.routeFence, String(targetNodeRid), String(targetSpotId), targetSpotGeneration, options?.entrySpot === true
954
966
  ? this.backend.entrySpotRouteFence(String(targetNodeRid), String(targetSpotId))
955
967
  : undefined);
956
- return this.backend.requestFromSpot(this.state, routeFence, parts, options?.timeoutMs ?? Registration_1.DEFAULT_REQUEST_TIMEOUT_MS);
968
+ return this.backend.requestFromSpot(this.state, routeFence, parts, options?.timeoutMs ?? Registration_1.DEFAULT_REQUEST_TIMEOUT_MS, options?.onAdmitted);
957
969
  }
958
970
  async publish(channelName, topic, parts, options) {
959
971
  this.requireOpen();
@@ -992,6 +1004,9 @@ class RawServiceSpot {
992
1004
  throw new Error(`Spot '${this.routingId}' is closed.`);
993
1005
  }
994
1006
  }
1007
+ function nodeSendResult(submitted) {
1008
+ return submitted ? zlink_1.SubmitResult.Ok : zlink_1.SubmitResult.NotConnected;
1009
+ }
995
1010
  function requireDirectSpotRouteFence(route, targetNodeRid, targetSpotId, targetSpotGeneration, entryRoute) {
996
1011
  if (route === undefined && entryRoute !== undefined) {
997
1012
  return entryRoute;
@@ -1073,7 +1088,7 @@ class RawStreamSessionService {
1073
1088
  if (target === undefined)
1074
1089
  return false;
1075
1090
  const operation = this.stream.send(target);
1076
- const parts = decodeMultipartBuffers((0, service_wire_m6a_codec_1.decodeApplicationPayloadView)(payload).payload);
1091
+ const parts = decodeMultipartParts((0, service_wire_m6a_codec_1.decodeApplicationPayloadView)(payload).payload, borrowMultipartPart);
1077
1092
  if (parts.length === 0)
1078
1093
  return false;
1079
1094
  const actorSlot = await (0, service_session_binding_ingress_port_1.serviceSessionBindingIngressPortIfRegistered)(this)?.actorSlot(actorId, sessionRid);
@@ -1637,22 +1652,15 @@ function decodeApplicationEnvelope(frame) {
1637
1652
  return { packetName, contentType, payload: bytes.subarray(offset) };
1638
1653
  }
1639
1654
  function decodeMultipart(payload) {
1640
- const buffers = decodeMultipartBuffers(payload);
1641
- const parts = new Array(buffers.length);
1642
- let materialized = 0;
1643
- try {
1644
- for (; materialized < buffers.length; materialized += 1) {
1645
- parts[materialized] = runtime_message_1.ZLinkBufferMessage.fromOwned(buffers[materialized]);
1646
- }
1647
- return parts;
1648
- }
1649
- catch (error) {
1650
- for (let index = 0; index < materialized; index += 1)
1651
- parts[index].close();
1652
- throw error;
1653
- }
1655
+ return decodeMultipartParts(payload, runtime_message_1.ZLinkBufferMessage.fromOwned, closeMultipartMessage);
1656
+ }
1657
+ function closeMultipartMessage(part) {
1658
+ part.close();
1654
1659
  }
1655
- function decodeMultipartBuffers(payload) {
1660
+ function borrowMultipartPart(part) {
1661
+ return part;
1662
+ }
1663
+ function decodeMultipartParts(payload, materialize, release) {
1656
1664
  const bytes = Buffer.from(payload.buffer, payload.byteOffset, payload.byteLength);
1657
1665
  if (bytes.length < 4)
1658
1666
  throw new service_wire_m6a_codec_1.ServiceWireProtocolError('Truncated multipart payload.');
@@ -1662,22 +1670,32 @@ function decodeMultipartBuffers(payload) {
1662
1670
  }
1663
1671
  const result = new Array(count);
1664
1672
  let offset = 4;
1665
- for (let index = 0; index < count; index++) {
1666
- if (bytes.length - offset < 4) {
1667
- throw new service_wire_m6a_codec_1.ServiceWireProtocolError('Truncated multipart part length.');
1673
+ let index = 0;
1674
+ try {
1675
+ for (; index < count; index++) {
1676
+ if (bytes.length - offset < 4) {
1677
+ throw new service_wire_m6a_codec_1.ServiceWireProtocolError('Truncated multipart part length.');
1678
+ }
1679
+ const length = bytes.readUInt32BE(offset);
1680
+ offset += 4;
1681
+ if (bytes.length - offset < length) {
1682
+ throw new service_wire_m6a_codec_1.ServiceWireProtocolError('Truncated multipart part.');
1683
+ }
1684
+ result[index] = materialize(bytes.subarray(offset, offset + length));
1685
+ offset += length;
1668
1686
  }
1669
- const length = bytes.readUInt32BE(offset);
1670
- offset += 4;
1671
- if (bytes.length - offset < length) {
1672
- throw new service_wire_m6a_codec_1.ServiceWireProtocolError('Truncated multipart part.');
1687
+ if (offset !== bytes.length) {
1688
+ throw new service_wire_m6a_codec_1.ServiceWireProtocolError('Multipart payload has trailing bytes.');
1673
1689
  }
1674
- result[index] = bytes.subarray(offset, offset + length);
1675
- offset += length;
1690
+ return result;
1676
1691
  }
1677
- if (offset !== bytes.length) {
1678
- throw new service_wire_m6a_codec_1.ServiceWireProtocolError('Multipart payload has trailing bytes.');
1692
+ catch (error) {
1693
+ if (release !== undefined) {
1694
+ for (let retained = 0; retained < index; retained++)
1695
+ release(result[retained]);
1696
+ }
1697
+ throw error;
1679
1698
  }
1680
- return result;
1681
1699
  }
1682
1700
  function messageBytesView(value) {
1683
1701
  if (typeof value === 'object' && 'data' in value) {
@@ -144,12 +144,12 @@ function wrapSocket(nativeInstance, pollCompletion) {
144
144
  },
145
145
  request(...args) {
146
146
  if (hasRoutedPeer) {
147
- const [routingId, payload, timeoutMs] = args;
148
- return (0, node_backend_adapter_support_1.submitBindingRequest)(nativeInstance.request((0, node_backend_adapter_support_1.toNativeRoutingId)(routingId)), payload, timeoutMs);
147
+ const [routingId, payload, timeoutMs, onAdmitted] = args;
148
+ return (0, node_backend_adapter_support_1.submitBindingRequest)(nativeInstance.request((0, node_backend_adapter_support_1.toNativeRoutingId)(routingId)), payload, timeoutMs, undefined, onAdmitted);
149
149
  }
150
150
  if (hasRequest) {
151
- const [payload, timeoutMs] = args;
152
- return (0, node_backend_adapter_support_1.submitBindingRequest)(nativeInstance.request(), payload, timeoutMs, adapter.receiveAdmission?.recordReceived);
151
+ const [payload, timeoutMs, onAdmitted] = args;
152
+ return (0, node_backend_adapter_support_1.submitBindingRequest)(nativeInstance.request(), payload, timeoutMs, adapter.receiveAdmission?.recordReceived, onAdmitted);
153
153
  }
154
154
  throw new TypeError('Backend request requires a DEALER or ROUTER socket.');
155
155
  },
@@ -201,8 +201,8 @@ function wrapSocket(nativeInstance, pollCompletion) {
201
201
  const operation = nativeInstance.sendToSpot((0, node_backend_adapter_support_1.toNativeRoutingId)(targetRid), (0, node_backend_adapter_support_1.toNativeRoutingId)(targetSpot));
202
202
  await (0, node_backend_adapter_support_1.submitBindingAsyncSend)(operation, payload);
203
203
  },
204
- requestToSpot(targetRid, targetSpot, payload, timeoutMs) {
205
- return (0, node_backend_adapter_support_1.submitBindingRequest)(nativeInstance.requestToSpot((0, node_backend_adapter_support_1.toNativeRoutingId)(targetRid), (0, node_backend_adapter_support_1.toNativeRoutingId)(targetSpot)), payload, timeoutMs);
204
+ requestToSpot(targetRid, targetSpot, payload, timeoutMs, onAdmitted) {
205
+ return (0, node_backend_adapter_support_1.submitBindingRequest)(nativeInstance.requestToSpot((0, node_backend_adapter_support_1.toNativeRoutingId)(targetRid), (0, node_backend_adapter_support_1.toNativeRoutingId)(targetSpot)), payload, timeoutMs, undefined, onAdmitted);
206
206
  },
207
207
  disconnectPeer(routingId) {
208
208
  disconnectStreamPeer(nativeInstance, routingId);
@@ -56,7 +56,7 @@ export interface ZLinkRawRouterPort extends ZLinkRawSocketPort {
56
56
  setRoutingId(routingId: string): void;
57
57
  connectToRoutingId(routingId: string, endpoint: string): void;
58
58
  send(targetRid: string, parts: readonly Uint8Array[]): Promise<void>;
59
- request(targetRid: string, parts: readonly Uint8Array[], timeoutMs: number, recordReceived?: () => void): Promise<readonly Buffer[]>;
59
+ request(targetRid: string, parts: readonly Uint8Array[], timeoutMs: number, recordReceived?: () => void, onAdmitted?: () => void): Promise<readonly Buffer[]>;
60
60
  receive(dontWait?: boolean): ZLinkRawReceivedRecord | undefined;
61
61
  /** The selected route of every RID. The socket's one route observer calls it. */
62
62
  routesSnapshot(): readonly ZLinkRawRouterRoute[];
@@ -64,7 +64,7 @@ export interface ZLinkRawRouterPort extends ZLinkRawSocketPort {
64
64
  export interface ZLinkRawDealerPort extends ZLinkRawSocketPort {
65
65
  setRoutingId(routingId: string): void;
66
66
  send(parts: readonly Uint8Array[]): Promise<void>;
67
- request(parts: readonly Uint8Array[], timeoutMs: number): Promise<readonly Buffer[]>;
67
+ request(parts: readonly Uint8Array[], timeoutMs: number, onAdmitted?: () => void): Promise<readonly Buffer[]>;
68
68
  receive(dontWait?: boolean): ZLinkRawReceivedRecord | undefined;
69
69
  }
70
70
  export interface ZLinkRawHostPort {
@@ -4,6 +4,7 @@ export declare class ZLinkBufferMessage implements Message {
4
4
  private constructor();
5
5
  static from(value: Message | Buffer | Uint8Array | string): ZLinkBufferMessage;
6
6
  static fromOwned(bytes: Buffer): ZLinkBufferMessage;
7
+ static retainPayload(message: Message): Buffer;
7
8
  data(): Buffer;
8
9
  toBytes(): Uint8Array;
9
10
  copy(): Message;
@@ -16,6 +16,11 @@ class ZLinkBufferMessage {
16
16
  static fromOwned(bytes) {
17
17
  return new ZLinkBufferMessage(bytes);
18
18
  }
19
+ static retainPayload(message) {
20
+ // Binding data() Buffers retain their storage after the message handle closes.
21
+ // Preserve that ownership at runtime boundaries without copying the payload.
22
+ return message.data();
23
+ }
19
24
  data() {
20
25
  return this.bytes;
21
26
  }
@@ -36,6 +36,7 @@ export type SubmitResult = (typeof SubmitResult)[keyof typeof SubmitResult];
36
36
  export type ZLinkBackendSendFlags = number;
37
37
  export type ZLinkBackendRecvFlags = number;
38
38
  export declare const ZLINK_BACKEND_SEND_NONE: ZLinkBackendSendFlags;
39
+ export declare const ZLINK_BACKEND_SEND_DONT_WAIT: ZLinkBackendSendFlags;
39
40
  export declare const ZLINK_BACKEND_RECV_DONT_WAIT: ZLinkBackendRecvFlags;
40
41
  export declare class ZLinkBackendResultError extends Error {
41
42
  readonly operation: 'request' | 'submit';
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ZLinkBackendResultError = exports.ZLINK_BACKEND_RECV_DONT_WAIT = exports.ZLINK_BACKEND_SEND_NONE = exports.SubmitResult = exports.RequestResult = void 0;
3
+ exports.ZLinkBackendResultError = exports.ZLINK_BACKEND_RECV_DONT_WAIT = exports.ZLINK_BACKEND_SEND_DONT_WAIT = exports.ZLINK_BACKEND_SEND_NONE = exports.SubmitResult = exports.RequestResult = void 0;
4
4
  exports.isZLinkBackendResultError = isZLinkBackendResultError;
5
5
  exports.isBackendNotConnectedError = isBackendNotConnectedError;
6
6
  exports.isBackendRequestTimeoutError = isBackendRequestTimeoutError;
@@ -37,6 +37,7 @@ exports.SubmitResult = Object.freeze({
37
37
  NotAdmitted: 13
38
38
  });
39
39
  exports.ZLINK_BACKEND_SEND_NONE = 0;
40
+ exports.ZLINK_BACKEND_SEND_DONT_WAIT = 1;
40
41
  exports.ZLINK_BACKEND_RECV_DONT_WAIT = 1;
41
42
  class ZLinkBackendResultError extends Error {
42
43
  operation;
@@ -35,6 +35,7 @@ export declare class DefaultZLinkRouteClient implements ZLinkRouteClient {
35
35
  private readonly transport?;
36
36
  private readonly spotRouterChannelIdForMesh;
37
37
  private readonly channelTransport?;
38
+ private readonly nodeSends;
38
39
  constructor(registration: ZLinkFrameworkRegistration, transport?: ZLinkRouteClientTransport | undefined, spotRouterChannelIdForMesh?: (meshName: string) => string, channelTransport?: ZLinkChannelClientTransportSource | undefined);
39
40
  sendToNode(meshName: string, targetNodeRid: string, message: unknown): ZLinkSendCall;
40
41
  requestToNode(meshName: string, targetNodeRid: string, request: unknown): ZLinkRequestCall;
@@ -4,6 +4,7 @@ exports.DefaultZLinkSpotPublisherClient = exports.DefaultZLinkRouteClient = expo
4
4
  exports.resolveChannelRoute = resolveChannelRoute;
5
5
  exports.requireUniqueRouteMeshChannel = requireUniqueRouteMeshChannel;
6
6
  const Registration_1 = require("../../contracts/Configuration/Registration");
7
+ const request_result_1 = require("../messaging/request-result");
7
8
  const configuration_1 = require("../configuration");
8
9
  const framework_errors_internal_1 = require("../framework-errors-internal");
9
10
  const submission_result_1 = require("../messaging/submission-result");
@@ -79,6 +80,7 @@ class DefaultZLinkRouteClient {
79
80
  transport;
80
81
  spotRouterChannelIdForMesh;
81
82
  channelTransport;
83
+ nodeSends = new Map();
82
84
  constructor(registration, transport, spotRouterChannelIdForMesh = (meshName) => meshName, channelTransport) {
83
85
  this.registration = registration;
84
86
  this.transport = transport;
@@ -86,10 +88,23 @@ class DefaultZLinkRouteClient {
86
88
  this.channelTransport = channelTransport;
87
89
  }
88
90
  sendToNode(meshName, targetNodeRid, message) {
89
- return new DefaultZLinkSendCall(() => this.requireMesh(meshName), async (packetName, metadata) => normalizeSubmitResult(await this.requireTransport().submit(meshName, targetNodeRid, packetName, message, metadata)));
91
+ let targets = this.nodeSends.get(meshName);
92
+ if (targets === undefined)
93
+ this.nodeSends.set(meshName, (targets = new Map()));
94
+ let prepared = targets.get(targetNodeRid);
95
+ if (prepared === undefined) {
96
+ prepared = {
97
+ validate: () => {
98
+ this.requireMesh(meshName);
99
+ },
100
+ submit: (packetName, metadata, payload) => normalizeSubmitResult(this.requireTransport().submit(meshName, targetNodeRid, packetName, payload, metadata))
101
+ };
102
+ targets.set(targetNodeRid, prepared);
103
+ }
104
+ return new DefaultZLinkSendCall(prepared.validate, prepared.submit, message);
90
105
  }
91
106
  requestToNode(meshName, targetNodeRid, request) {
92
- return new DefaultZLinkRequestCall(() => this.requireMesh(meshName), (packetName, timeoutMs, metadata, signal) => this.requireTransport().request(meshName, targetNodeRid, packetName, request, timeoutMs, signal, metadata), this.defaultRequestTimeout(meshName));
107
+ return new DefaultZLinkRequestCall(() => this.requireMesh(meshName), (packetName, timeoutMs, metadata, signal, onAdmitted) => this.requireTransport().request(meshName, targetNodeRid, packetName, request, timeoutMs, signal, metadata, onAdmitted), this.defaultRequestTimeout(meshName));
93
108
  }
94
109
  sendToChannel(channelName, message) {
95
110
  return new DefaultZLinkSendCall(() => this.requireChannelRoute(channelName), async (packetName, metadata) => {
@@ -101,12 +116,12 @@ class DefaultZLinkRouteClient {
101
116
  });
102
117
  }
103
118
  requestToChannel(channelName, request) {
104
- return new DefaultZLinkRequestCall(() => this.requireChannelRoute(channelName), (packetName, timeoutMs, metadata, signal) => {
119
+ return new DefaultZLinkRequestCall(() => this.requireChannelRoute(channelName), (packetName, timeoutMs, metadata, signal, onAdmitted) => {
105
120
  const route = this.requireChannelRoute(channelName);
106
121
  if (route.kind === 'route-mesh') {
107
- return this.requireTransport().requestToChannel(route.meshName, channelName, packetName, request, timeoutMs, signal, metadata);
122
+ return this.requireTransport().requestToChannel(route.meshName, channelName, packetName, request, timeoutMs, signal, metadata, onAdmitted);
108
123
  }
109
- return this.requireChannelTransport().request(channelName, packetName, request, timeoutMs, signal, metadata);
124
+ return this.requireChannelTransport().request(channelName, packetName, request, timeoutMs, signal, metadata, onAdmitted);
110
125
  }, this.defaultRequestTimeoutForChannel(channelName));
111
126
  }
112
127
  sendToSpot(spot, message) {
@@ -123,10 +138,11 @@ class DefaultZLinkRouteClient {
123
138
  requestToSpot(spot, request) {
124
139
  return new DefaultZLinkRequestCall(() => {
125
140
  this.requireSpotTransport();
126
- }, (_packetName, timeoutMs, metadata, signal) => (0, spot_outbound_1.requestToSpotHandle)(this.requireSpotTransport(), spot, request, {
141
+ }, (_packetName, timeoutMs, metadata, signal, onAdmitted) => (0, spot_outbound_1.requestToSpotHandle)(this.requireSpotTransport(), spot, request, {
127
142
  timeoutMs,
128
143
  signal,
129
144
  metadata,
145
+ onAdmitted,
130
146
  spotRouterChannelIdForMesh: this.spotRouterChannelIdForMesh
131
147
  }), this.registration.requestTimeoutMs ?? Registration_1.DEFAULT_REQUEST_TIMEOUT_MS);
132
148
  }
@@ -217,14 +233,17 @@ exports.DefaultZLinkSpotPublisherClient = DefaultZLinkSpotPublisherClient;
217
233
  class DefaultZLinkSendCall {
218
234
  validate;
219
235
  submitter;
220
- selectedMetadata = new Map();
236
+ message;
237
+ selectedMetadata;
221
238
  executed = false;
222
- constructor(validate, submitter) {
239
+ constructor(validate, submitter, message) {
223
240
  this.validate = validate;
224
241
  this.submitter = submitter;
242
+ this.message = message;
225
243
  }
226
244
  metadata(keyOrMetadata, value) {
227
245
  ensureNotExecuted(this.executed);
246
+ this.selectedMetadata ??= new Map();
228
247
  if (typeof keyOrMetadata === 'string') {
229
248
  this.selectedMetadata.set(keyOrMetadata, value);
230
249
  }
@@ -235,12 +254,20 @@ class DefaultZLinkSendCall {
235
254
  }
236
255
  return this;
237
256
  }
238
- async submit() {
239
- ensureNotExecuted(this.executed);
240
- this.validate();
241
- this.executed = true;
242
- const result = await this.submitter(undefined, new Map(this.selectedMetadata));
243
- (0, submission_result_1.requireOneWayCompletion)(result, 'One-way send');
257
+ submit() {
258
+ try {
259
+ ensureNotExecuted(this.executed);
260
+ this.validate();
261
+ this.executed = true;
262
+ const result = this.submitter(undefined, this.selectedMetadata ?? EMPTY_CALL_METADATA, this.message);
263
+ if (result instanceof Promise)
264
+ return result.then(completeOneWaySend);
265
+ completeOneWaySend(result);
266
+ return completedOneWaySend;
267
+ }
268
+ catch (error) {
269
+ return Promise.reject(error);
270
+ }
244
271
  }
245
272
  }
246
273
  function ensureNotExecuted(executed) {
@@ -248,15 +275,22 @@ function ensureNotExecuted(executed) {
248
275
  (0, submission_result_1.throwAlreadySubmitted)('ZLink call');
249
276
  }
250
277
  }
278
+ const EMPTY_CALL_METADATA = new Map();
279
+ const completedOneWaySend = Promise.resolve();
280
+ function completeOneWaySend(result) {
281
+ (0, submission_result_1.requireOneWayCompletion)(result, 'One-way send');
282
+ }
251
283
  function normalizeSubmitResult(result) {
252
- return result ?? { status: submission_result_1.ZLinkSubmitStatus.Submitted };
284
+ return result instanceof Promise
285
+ ? result.then((value) => value ?? submission_result_1.submittedResult)
286
+ : (result ?? submission_result_1.submittedResult);
253
287
  }
254
288
  class DefaultZLinkRequestCall {
255
289
  validate;
256
290
  submitter;
257
291
  defaultRequestTimeoutMs;
258
292
  timeoutMs;
259
- selectedMetadata = new Map();
293
+ selectedMetadata;
260
294
  turn = (0, execution_1.captureZLinkSpotSerialTurn)();
261
295
  constructor(validate, submitter, defaultRequestTimeoutMs) {
262
296
  this.validate = validate;
@@ -264,6 +298,7 @@ class DefaultZLinkRequestCall {
264
298
  this.defaultRequestTimeoutMs = defaultRequestTimeoutMs;
265
299
  }
266
300
  metadata(keyOrMetadata, value) {
301
+ this.selectedMetadata ??= new Map();
267
302
  if (typeof keyOrMetadata === 'string') {
268
303
  this.selectedMetadata.set(keyOrMetadata, value);
269
304
  }
@@ -278,16 +313,18 @@ class DefaultZLinkRequestCall {
278
313
  this.timeoutMs = timeoutMs;
279
314
  return this;
280
315
  }
281
- async submit(signal) {
282
- (0, abort_1.throwIfAborted)(signal);
283
- this.validate();
284
- return this.submitter(undefined, this.timeoutMs ?? this.defaultRequestTimeoutMs, new Map(this.selectedMetadata), signal);
316
+ submit(signal) {
317
+ return (0, request_result_1.createZLinkRequest)((onAdmitted) => {
318
+ (0, abort_1.throwIfAborted)(signal);
319
+ this.validate();
320
+ return this.submitter(undefined, this.timeoutMs ?? this.defaultRequestTimeoutMs, this.selectedMetadata === undefined ? EMPTY_CALL_METADATA : new Map(this.selectedMetadata), signal, onAdmitted);
321
+ });
285
322
  }
286
323
  async yield(signal) {
287
324
  const turn = (0, execution_1.requireZLinkYieldTurn)(this.turn);
288
325
  (0, abort_1.throwIfAborted)(signal);
289
326
  this.validate();
290
- const pending = this.submitter(undefined, this.timeoutMs ?? this.defaultRequestTimeoutMs, new Map(this.selectedMetadata), signal);
327
+ const pending = this.submitter(undefined, this.timeoutMs ?? this.defaultRequestTimeoutMs, this.selectedMetadata === undefined ? EMPTY_CALL_METADATA : new Map(this.selectedMetadata), signal);
291
328
  return turn.yieldPromise(pending);
292
329
  }
293
330
  }
@@ -39,8 +39,8 @@ interface ZLinkRequestDispatch<TContext extends ZLinkMessageContext> {
39
39
  readonly context: TContext;
40
40
  readonly signal?: AbortSignal;
41
41
  readonly missingHandlerMessage: string;
42
- readonly writeReply: (reply: unknown) => Promise<void>;
43
- readonly writeError: (error: unknown) => Promise<void>;
42
+ readonly writeReply: (reply: unknown) => void | Promise<void>;
43
+ readonly writeError: (error: unknown) => void | Promise<void>;
44
44
  }
45
45
  export declare class ZLinkChannelDispatchPipeline {
46
46
  private readonly options;
@@ -66,6 +66,7 @@ export declare class ZLinkChannelDispatchPipeline {
66
66
  readonly writeProtocolError?: (error: ZLinkFrameworkException) => Promise<void>;
67
67
  }): Promise<void>;
68
68
  private invoke;
69
+ private invokeFiltered;
69
70
  private createFilterContext;
70
71
  private dispatchKind;
71
72
  private report;