@zlink-systems/framework 0.10.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.
- package/LICENSE +105 -0
- package/dist/.tsbuildinfo +1 -0
- package/dist/contracts/Actors/ZLinkActor.d.ts +7 -0
- package/dist/contracts/Actors/ZLinkActor.js +2 -0
- package/dist/contracts/Actors/ZLinkActorClient.d.ts +15 -0
- package/dist/contracts/Actors/ZLinkActorClient.js +2 -0
- package/dist/contracts/Actors/ZLinkActorContext.d.ts +14 -0
- package/dist/contracts/Actors/ZLinkActorContext.js +2 -0
- package/dist/contracts/Actors/ZLinkActorFactory.d.ts +34 -0
- package/dist/contracts/Actors/ZLinkActorFactory.js +2 -0
- package/dist/contracts/Actors/ZLinkActorManager.d.ts +34 -0
- package/dist/contracts/Actors/ZLinkActorManager.js +2 -0
- package/dist/contracts/Actors/index.d.ts +5 -0
- package/dist/contracts/Actors/index.js +21 -0
- package/dist/contracts/Channels/Calls.d.ts +28 -0
- package/dist/contracts/Channels/Calls.js +2 -0
- package/dist/contracts/Channels/IZLinkChannelClient.d.ts +5 -0
- package/dist/contracts/Channels/IZLinkChannelClient.js +2 -0
- package/dist/contracts/Channels/IZLinkFanoutClient.d.ts +11 -0
- package/dist/contracts/Channels/IZLinkFanoutClient.js +2 -0
- package/dist/contracts/Channels/RouteCalls.d.ts +11 -0
- package/dist/contracts/Channels/RouteCalls.js +2 -0
- package/dist/contracts/Channels/index.d.ts +4 -0
- package/dist/contracts/Channels/index.js +20 -0
- package/dist/contracts/Codecs/IZLinkCodecRegistryBuilder.d.ts +14 -0
- package/dist/contracts/Codecs/IZLinkCodecRegistryBuilder.js +2 -0
- package/dist/contracts/Codecs/ZLinkMessageSerializer.d.ts +5 -0
- package/dist/contracts/Codecs/ZLinkMessageSerializer.js +2 -0
- package/dist/contracts/Codecs/index.d.ts +2 -0
- package/dist/contracts/Codecs/index.js +18 -0
- package/dist/contracts/Common/ActorRef.d.ts +7 -0
- package/dist/contracts/Common/ActorRef.js +2 -0
- package/dist/contracts/Common/CoreTypes.d.ts +6 -0
- package/dist/contracts/Common/CoreTypes.js +2 -0
- package/dist/contracts/Common/Message.d.ts +9 -0
- package/dist/contracts/Common/Message.js +2 -0
- package/dist/contracts/Common/ZLinkEncodedPayload.d.ts +12 -0
- package/dist/contracts/Common/ZLinkEncodedPayload.js +41 -0
- package/dist/contracts/Common/ZLinkMessage.d.ts +25 -0
- package/dist/contracts/Common/ZLinkMessage.js +127 -0
- package/dist/contracts/Common/ZLinkMessageMetadata.d.ts +10 -0
- package/dist/contracts/Common/ZLinkMessageMetadata.js +49 -0
- package/dist/contracts/Common/ZLinkProviderResolver.d.ts +5 -0
- package/dist/contracts/Common/ZLinkProviderResolver.js +2 -0
- package/dist/contracts/Common/encoded-payload-storage.d.ts +3 -0
- package/dist/contracts/Common/encoded-payload-storage.js +18 -0
- package/dist/contracts/Common/index.d.ts +5 -0
- package/dist/contracts/Common/index.js +24 -0
- package/dist/contracts/Configuration/Builders.d.ts +153 -0
- package/dist/contracts/Configuration/Builders.js +2 -0
- package/dist/contracts/Configuration/CodecContentType.d.ts +2 -0
- package/dist/contracts/Configuration/CodecContentType.js +68 -0
- package/dist/contracts/Configuration/CodecSerializerSelection.d.ts +9 -0
- package/dist/contracts/Configuration/CodecSerializerSelection.js +15 -0
- package/dist/contracts/Configuration/Configs.d.ts +23 -0
- package/dist/contracts/Configuration/Configs.js +2 -0
- package/dist/contracts/Configuration/ConfigurationException.d.ts +3 -0
- package/dist/contracts/Configuration/ConfigurationException.js +10 -0
- package/dist/contracts/Configuration/Connections.d.ts +5 -0
- package/dist/contracts/Configuration/Connections.js +2 -0
- package/dist/contracts/Configuration/DiagnosticsValidation.d.ts +3 -0
- package/dist/contracts/Configuration/DiagnosticsValidation.js +23 -0
- package/dist/contracts/Configuration/EndpointNotation.d.ts +77 -0
- package/dist/contracts/Configuration/EndpointNotation.js +218 -0
- package/dist/contracts/Configuration/InternalDefaults.d.ts +7 -0
- package/dist/contracts/Configuration/InternalDefaults.js +47 -0
- package/dist/contracts/Configuration/ObjectRoles.d.ts +38 -0
- package/dist/contracts/Configuration/ObjectRoles.js +13 -0
- package/dist/contracts/Configuration/Registration.d.ts +11 -0
- package/dist/contracts/Configuration/Registration.js +162 -0
- package/dist/contracts/Configuration/RegistrationBuilderPolicy.d.ts +14 -0
- package/dist/contracts/Configuration/RegistrationBuilderPolicy.js +61 -0
- package/dist/contracts/Configuration/RegistrationBuilders.d.ts +61 -0
- package/dist/contracts/Configuration/RegistrationBuilders.js +1181 -0
- package/dist/contracts/Configuration/RegistrationCodecRegistry.d.ts +19 -0
- package/dist/contracts/Configuration/RegistrationCodecRegistry.js +79 -0
- package/dist/contracts/Configuration/RegistrationNormalizers.d.ts +23 -0
- package/dist/contracts/Configuration/RegistrationNormalizers.js +319 -0
- package/dist/contracts/Configuration/RegistrationTypes.d.ts +414 -0
- package/dist/contracts/Configuration/RegistrationTypes.js +2 -0
- package/dist/contracts/Configuration/RegistrationValidators.d.ts +2 -0
- package/dist/contracts/Configuration/RegistrationValidators.js +461 -0
- package/dist/contracts/Configuration/RouteChannelInternalState.d.ts +10 -0
- package/dist/contracts/Configuration/RouteChannelInternalState.js +39 -0
- package/dist/contracts/Configuration/RuntimeEndpointConnections.d.ts +9 -0
- package/dist/contracts/Configuration/RuntimeEndpointConnections.js +80 -0
- package/dist/contracts/Configuration/SendTimeoutValidation.d.ts +2 -0
- package/dist/contracts/Configuration/SendTimeoutValidation.js +16 -0
- package/dist/contracts/Configuration/TimerRegistrationValidator.d.ts +2 -0
- package/dist/contracts/Configuration/TimerRegistrationValidator.js +24 -0
- package/dist/contracts/Configuration/index.d.ts +5 -0
- package/dist/contracts/Configuration/index.js +18 -0
- package/dist/contracts/Dispatch/ZLinkDispatchOptions.d.ts +181 -0
- package/dist/contracts/Dispatch/ZLinkDispatchOptions.js +89 -0
- package/dist/contracts/Dispatch/ZLinkFlowOrigin.d.ts +1 -0
- package/dist/contracts/Dispatch/ZLinkFlowOrigin.js +2 -0
- package/dist/contracts/Dispatch/index.d.ts +2 -0
- package/dist/contracts/Dispatch/index.js +18 -0
- package/dist/contracts/Errors/ZLinkFrameworkException.d.ts +20 -0
- package/dist/contracts/Errors/ZLinkFrameworkException.js +29 -0
- package/dist/contracts/Errors/index.d.ts +1 -0
- package/dist/contracts/Errors/index.js +6 -0
- package/dist/contracts/Eventing/Metrics.d.ts +29 -0
- package/dist/contracts/Eventing/Metrics.js +4 -0
- package/dist/contracts/Eventing/index.d.ts +1 -0
- package/dist/contracts/Eventing/index.js +17 -0
- package/dist/contracts/Handlers/Attributes.d.ts +24 -0
- package/dist/contracts/Handlers/Attributes.js +84 -0
- package/dist/contracts/Handlers/Contexts.d.ts +18 -0
- package/dist/contracts/Handlers/Contexts.js +2 -0
- package/dist/contracts/Handlers/IZLinkChannelHandlers.d.ts +43 -0
- package/dist/contracts/Handlers/IZLinkChannelHandlers.js +2 -0
- package/dist/contracts/Handlers/IZLinkHandlerFilter.d.ts +15 -0
- package/dist/contracts/Handlers/IZLinkHandlerFilter.js +11 -0
- package/dist/contracts/Handlers/JsonContract.d.ts +46 -0
- package/dist/contracts/Handlers/JsonContract.js +137 -0
- package/dist/contracts/Handlers/ZLinkHandlerFilterNext.d.ts +1 -0
- package/dist/contracts/Handlers/ZLinkHandlerFilterNext.js +2 -0
- package/dist/contracts/Handlers/index.d.ts +5 -0
- package/dist/contracts/Handlers/index.js +33 -0
- package/dist/contracts/Locations/ActorTransfer.d.ts +41 -0
- package/dist/contracts/Locations/ActorTransfer.js +2 -0
- package/dist/contracts/Locations/Authority.d.ts +296 -0
- package/dist/contracts/Locations/Authority.js +17 -0
- package/dist/contracts/Locations/Diagnostics.d.ts +42 -0
- package/dist/contracts/Locations/Diagnostics.js +12 -0
- package/dist/contracts/Locations/Keys.d.ts +86 -0
- package/dist/contracts/Locations/Keys.js +2 -0
- package/dist/contracts/Locations/Models.d.ts +7 -0
- package/dist/contracts/Locations/Models.js +23 -0
- package/dist/contracts/Locations/Options.d.ts +23 -0
- package/dist/contracts/Locations/Options.js +20 -0
- package/dist/contracts/Locations/Readiness.d.ts +5 -0
- package/dist/contracts/Locations/Readiness.js +2 -0
- package/dist/contracts/Locations/RelocationStore.d.ts +38 -0
- package/dist/contracts/Locations/RelocationStore.js +2 -0
- package/dist/contracts/Locations/Resolvers.d.ts +4 -0
- package/dist/contracts/Locations/Resolvers.js +2 -0
- package/dist/contracts/Locations/Rows.d.ts +152 -0
- package/dist/contracts/Locations/Rows.js +19 -0
- package/dist/contracts/Locations/RuntimeQuery.d.ts +25 -0
- package/dist/contracts/Locations/RuntimeQuery.js +2 -0
- package/dist/contracts/Locations/Stores.d.ts +88 -0
- package/dist/contracts/Locations/Stores.js +2 -0
- package/dist/contracts/Locations/Values.d.ts +27 -0
- package/dist/contracts/Locations/Values.js +36 -0
- package/dist/contracts/Locations/Watch.d.ts +14 -0
- package/dist/contracts/Locations/Watch.js +12 -0
- package/dist/contracts/Locations/Writes.d.ts +48 -0
- package/dist/contracts/Locations/Writes.js +15 -0
- package/dist/contracts/Locations/index.d.ts +12 -0
- package/dist/contracts/Locations/index.js +30 -0
- package/dist/contracts/RouteMesh/Contracts.d.ts +102 -0
- package/dist/contracts/RouteMesh/Contracts.js +39 -0
- package/dist/contracts/RouteMesh/RuntimeTopology.d.ts +165 -0
- package/dist/contracts/RouteMesh/RuntimeTopology.js +38 -0
- package/dist/contracts/RouteMesh/index.d.ts +2 -0
- package/dist/contracts/RouteMesh/index.js +18 -0
- package/dist/contracts/Spots/Builders.d.ts +10 -0
- package/dist/contracts/Spots/Builders.js +2 -0
- package/dist/contracts/Spots/Contracts.d.ts +110 -0
- package/dist/contracts/Spots/Contracts.js +9 -0
- package/dist/contracts/Spots/SpotKind.d.ts +8 -0
- package/dist/contracts/Spots/SpotKind.js +28 -0
- package/dist/contracts/Spots/ZLinkSpot.d.ts +62 -0
- package/dist/contracts/Spots/ZLinkSpot.js +15 -0
- package/dist/contracts/Spots/index.d.ts +3 -0
- package/dist/contracts/Spots/index.js +19 -0
- package/dist/contracts/Streams/BoundSessionContracts.d.ts +8 -0
- package/dist/contracts/Streams/BoundSessionContracts.js +2 -0
- package/dist/contracts/Streams/IZLinkSession.d.ts +44 -0
- package/dist/contracts/Streams/IZLinkSession.js +2 -0
- package/dist/contracts/Streams/IZLinkSessionActor.d.ts +15 -0
- package/dist/contracts/Streams/IZLinkSessionActor.js +2 -0
- package/dist/contracts/Streams/IZLinkSessionPacketHandler.d.ts +9 -0
- package/dist/contracts/Streams/IZLinkSessionPacketHandler.js +2 -0
- package/dist/contracts/Streams/IZLinkStream.d.ts +9 -0
- package/dist/contracts/Streams/IZLinkStream.js +2 -0
- package/dist/contracts/Streams/ZLinkMessageMetadata.d.ts +1 -0
- package/dist/contracts/Streams/ZLinkMessageMetadata.js +2 -0
- package/dist/contracts/Streams/ZLinkStreamCompression.d.ts +8 -0
- package/dist/contracts/Streams/ZLinkStreamCompression.js +2 -0
- package/dist/contracts/Streams/ZLinkStreamError.d.ts +8 -0
- package/dist/contracts/Streams/ZLinkStreamError.js +8 -0
- package/dist/contracts/Streams/index.d.ts +8 -0
- package/dist/contracts/Streams/index.js +24 -0
- package/dist/contracts/Timers/IZLinkTimer.d.ts +5 -0
- package/dist/contracts/Timers/IZLinkTimer.js +2 -0
- package/dist/contracts/Timers/ZLinkTimerOptions.d.ts +10 -0
- package/dist/contracts/Timers/ZLinkTimerOptions.js +9 -0
- package/dist/contracts/Timers/ZLinkTimerTick.d.ts +12 -0
- package/dist/contracts/Timers/ZLinkTimerTick.js +2 -0
- package/dist/contracts/Timers/index.d.ts +3 -0
- package/dist/contracts/Timers/index.js +19 -0
- package/dist/contracts/index.d.ts +25 -0
- package/dist/contracts/index.js +45 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +17 -0
- package/dist/internal.d.ts +26 -0
- package/dist/internal.js +48 -0
- package/dist/location-store-integration.d.ts +5 -0
- package/dist/location-store-integration.js +31 -0
- package/dist/nest-integration.d.ts +49 -0
- package/dist/nest-integration.js +143 -0
- package/dist/runtime/abort.d.ts +13 -0
- package/dist/runtime/abort.js +71 -0
- package/dist/runtime/actors/actor-authority-payload-codec.d.ts +33 -0
- package/dist/runtime/actors/actor-authority-payload-codec.js +366 -0
- package/dist/runtime/actors/actor-authority-publication.d.ts +28 -0
- package/dist/runtime/actors/actor-authority-publication.js +207 -0
- package/dist/runtime/actors/actor-client.d.ts +36 -0
- package/dist/runtime/actors/actor-client.js +612 -0
- package/dist/runtime/actors/actor-context.d.ts +26 -0
- package/dist/runtime/actors/actor-context.js +433 -0
- package/dist/runtime/actors/actor-creation.d.ts +19 -0
- package/dist/runtime/actors/actor-creation.js +158 -0
- package/dist/runtime/actors/actor-execution-context.d.ts +6 -0
- package/dist/runtime/actors/actor-execution-context.js +27 -0
- package/dist/runtime/actors/actor-handoff.d.ts +191 -0
- package/dist/runtime/actors/actor-handoff.js +1252 -0
- package/dist/runtime/actors/actor-join-deferred-scope.d.ts +11 -0
- package/dist/runtime/actors/actor-join-deferred-scope.js +144 -0
- package/dist/runtime/actors/actor-join-relocation.d.ts +38 -0
- package/dist/runtime/actors/actor-join-relocation.js +2 -0
- package/dist/runtime/actors/actor-lifecycle-snapshot.d.ts +21 -0
- package/dist/runtime/actors/actor-lifecycle-snapshot.js +58 -0
- package/dist/runtime/actors/actor-local-native-join.d.ts +27 -0
- package/dist/runtime/actors/actor-local-native-join.js +409 -0
- package/dist/runtime/actors/actor-mailbox.d.ts +10 -0
- package/dist/runtime/actors/actor-mailbox.js +53 -0
- package/dist/runtime/actors/actor-message-follow-context.d.ts +46 -0
- package/dist/runtime/actors/actor-message-follow-context.js +257 -0
- package/dist/runtime/actors/actor-native-lookup.d.ts +4 -0
- package/dist/runtime/actors/actor-native-lookup.js +30 -0
- package/dist/runtime/actors/actor-packet-relay-wire.d.ts +73 -0
- package/dist/runtime/actors/actor-packet-relay-wire.js +144 -0
- package/dist/runtime/actors/actor-remote-joiner.d.ts +37 -0
- package/dist/runtime/actors/actor-remote-joiner.js +122 -0
- package/dist/runtime/actors/actor-remote-wire.d.ts +73 -0
- package/dist/runtime/actors/actor-remote-wire.js +84 -0
- package/dist/runtime/actors/actor-retry-delay.d.ts +5 -0
- package/dist/runtime/actors/actor-retry-delay.js +40 -0
- package/dist/runtime/actors/actor-routed-join-transport.d.ts +33 -0
- package/dist/runtime/actors/actor-routed-join-transport.js +2 -0
- package/dist/runtime/actors/actor-routed-json-request.d.ts +11 -0
- package/dist/runtime/actors/actor-routed-json-request.js +39 -0
- package/dist/runtime/actors/actor-runtime-contracts.d.ts +63 -0
- package/dist/runtime/actors/actor-runtime-contracts.js +2 -0
- package/dist/runtime/actors/actor-runtime-state.d.ts +152 -0
- package/dist/runtime/actors/actor-runtime-state.js +545 -0
- package/dist/runtime/actors/actor-source-transfer.d.ts +27 -0
- package/dist/runtime/actors/actor-source-transfer.js +2 -0
- package/dist/runtime/actors/actor-transfer-registry.d.ts +18 -0
- package/dist/runtime/actors/actor-transfer-registry.js +71 -0
- package/dist/runtime/actors/actor-transport-delivery-gate.d.ts +6 -0
- package/dist/runtime/actors/actor-transport-delivery-gate.js +4 -0
- package/dist/runtime/actors/bound-session-wire.d.ts +81 -0
- package/dist/runtime/actors/bound-session-wire.js +184 -0
- package/dist/runtime/actors/deferred-join-accepted-journal.d.ts +47 -0
- package/dist/runtime/actors/deferred-join-accepted-journal.js +962 -0
- package/dist/runtime/actors/index.d.ts +79 -0
- package/dist/runtime/actors/index.js +639 -0
- package/dist/runtime/actors/post-commit-actor-binder.d.ts +18 -0
- package/dist/runtime/actors/post-commit-actor-binder.js +68 -0
- package/dist/runtime/actors/post-commit-actor-location.d.ts +19 -0
- package/dist/runtime/actors/post-commit-actor-location.js +72 -0
- package/dist/runtime/actors/spot-actor-dispatch.d.ts +59 -0
- package/dist/runtime/actors/spot-actor-dispatch.js +179 -0
- package/dist/runtime/actors/transferred-actor-rollback.d.ts +16 -0
- package/dist/runtime/actors/transferred-actor-rollback.js +91 -0
- package/dist/runtime/admission.d.ts +20 -0
- package/dist/runtime/admission.js +166 -0
- package/dist/runtime/application-jobs/application-ingress-record-owner.d.ts +57 -0
- package/dist/runtime/application-jobs/application-ingress-record-owner.js +185 -0
- package/dist/runtime/application-jobs/application-job-queue-handler-start-gate.d.ts +8 -0
- package/dist/runtime/application-jobs/application-job-queue-handler-start-gate.js +8 -0
- package/dist/runtime/application-jobs/application-job-queue-scope.d.ts +17 -0
- package/dist/runtime/application-jobs/application-job-queue-scope.js +57 -0
- package/dist/runtime/application-jobs/contracts.d.ts +19 -0
- package/dist/runtime/application-jobs/contracts.js +2 -0
- package/dist/runtime/application-jobs/receive-flow-controller.d.ts +32 -0
- package/dist/runtime/application-jobs/receive-flow-controller.js +165 -0
- package/dist/runtime/backend/contracts/index.d.ts +487 -0
- package/dist/runtime/backend/contracts/index.js +29 -0
- package/dist/runtime/backend/index.d.ts +9 -0
- package/dist/runtime/backend/index.js +25 -0
- package/dist/runtime/backend/mesh-actor-session-node-adapter.d.ts +3 -0
- package/dist/runtime/backend/mesh-actor-session-node-adapter.js +51 -0
- package/dist/runtime/backend/mesh-completion-table.d.ts +34 -0
- package/dist/runtime/backend/mesh-completion-table.js +124 -0
- package/dist/runtime/backend/mesh-dispatch-pump.d.ts +48 -0
- package/dist/runtime/backend/mesh-dispatch-pump.js +322 -0
- package/dist/runtime/backend/mesh-record-dispatcher.d.ts +19 -0
- package/dist/runtime/backend/mesh-record-dispatcher.js +53 -0
- package/dist/runtime/backend/node/index.d.ts +4 -0
- package/dist/runtime/backend/node/index.js +22 -0
- package/dist/runtime/backend/node/node-backend-adapter-factory.d.ts +12 -0
- package/dist/runtime/backend/node/node-backend-adapter-factory.js +161 -0
- package/dist/runtime/backend/node/node-backend-adapter-support.d.ts +52 -0
- package/dist/runtime/backend/node/node-backend-adapter-support.js +203 -0
- package/dist/runtime/backend/node/node-dealer-channel-client-transport.d.ts +13 -0
- package/dist/runtime/backend/node/node-dealer-channel-client-transport.js +52 -0
- package/dist/runtime/backend/node/node-mesh-backend-adapter.d.ts +11 -0
- package/dist/runtime/backend/node/node-mesh-backend-adapter.js +23 -0
- package/dist/runtime/backend/node/node-monitor-backend-adapter.d.ts +6 -0
- package/dist/runtime/backend/node/node-monitor-backend-adapter.js +38 -0
- package/dist/runtime/backend/node/node-raw-binding-port.d.ts +8 -0
- package/dist/runtime/backend/node/node-raw-binding-port.js +411 -0
- package/dist/runtime/backend/node/node-raw-mesh-backend.d.ts +266 -0
- package/dist/runtime/backend/node/node-raw-mesh-backend.js +1707 -0
- package/dist/runtime/backend/node/node-socket-backend-adapter.d.ts +9 -0
- package/dist/runtime/backend/node/node-socket-backend-adapter.js +286 -0
- package/dist/runtime/backend/node-backend-adapter.d.ts +9 -0
- package/dist/runtime/backend/node-backend-adapter.js +12 -0
- package/dist/runtime/backend/raw-binding-port.d.ts +58 -0
- package/dist/runtime/backend/raw-binding-port.js +2 -0
- package/dist/runtime/backend/runtime-message.d.ts +14 -0
- package/dist/runtime/backend/runtime-message.js +44 -0
- package/dist/runtime/backend/runtime-values.d.ts +78 -0
- package/dist/runtime/backend/runtime-values.js +66 -0
- package/dist/runtime/channels/channel-autoconnect.d.ts +14 -0
- package/dist/runtime/channels/channel-autoconnect.js +23 -0
- package/dist/runtime/channels/channel-clients.d.ts +50 -0
- package/dist/runtime/channels/channel-clients.js +329 -0
- package/dist/runtime/channels/channel-dispatch-pipeline.d.ts +76 -0
- package/dist/runtime/channels/channel-dispatch-pipeline.js +237 -0
- package/dist/runtime/channels/channel-dispatch-services.d.ts +52 -0
- package/dist/runtime/channels/channel-dispatch-services.js +132 -0
- package/dist/runtime/channels/channel-dispatchers.d.ts +125 -0
- package/dist/runtime/channels/channel-dispatchers.js +575 -0
- package/dist/runtime/channels/channel-envelope-inspection.d.ts +25 -0
- package/dist/runtime/channels/channel-envelope-inspection.js +96 -0
- package/dist/runtime/channels/channel-envelope.d.ts +73 -0
- package/dist/runtime/channels/channel-envelope.js +546 -0
- package/dist/runtime/channels/channel-framework-packets.d.ts +2 -0
- package/dist/runtime/channels/channel-framework-packets.js +6 -0
- package/dist/runtime/channels/channel-multipart.d.ts +16 -0
- package/dist/runtime/channels/channel-multipart.js +31 -0
- package/dist/runtime/channels/channel-outbound-operations.d.ts +33 -0
- package/dist/runtime/channels/channel-outbound-operations.js +343 -0
- package/dist/runtime/channels/channel-receive-loops.d.ts +151 -0
- package/dist/runtime/channels/channel-receive-loops.js +728 -0
- package/dist/runtime/channels/channel-receive-task-tracker.d.ts +14 -0
- package/dist/runtime/channels/channel-receive-task-tracker.js +37 -0
- package/dist/runtime/channels/channel-runtime-lifecycle.d.ts +77 -0
- package/dist/runtime/channels/channel-runtime-lifecycle.js +630 -0
- package/dist/runtime/channels/channel-runtime-manager.d.ts +84 -0
- package/dist/runtime/channels/channel-runtime-manager.js +193 -0
- package/dist/runtime/channels/channel-socket-options.d.ts +18 -0
- package/dist/runtime/channels/channel-socket-options.js +119 -0
- package/dist/runtime/channels/channel-socket-registry.d.ts +157 -0
- package/dist/runtime/channels/channel-socket-registry.js +1428 -0
- package/dist/runtime/channels/channel-transports.d.ts +126 -0
- package/dist/runtime/channels/channel-transports.js +448 -0
- package/dist/runtime/channels/client-server-location-runtime.d.ts +41 -0
- package/dist/runtime/channels/client-server-location-runtime.js +465 -0
- package/dist/runtime/channels/client-server-service-wire.d.ts +48 -0
- package/dist/runtime/channels/client-server-service-wire.js +306 -0
- package/dist/runtime/channels/dispatch-error-reporter.d.ts +22 -0
- package/dist/runtime/channels/dispatch-error-reporter.js +133 -0
- package/dist/runtime/channels/fanout-location-runtime.d.ts +38 -0
- package/dist/runtime/channels/fanout-location-runtime.js +356 -0
- package/dist/runtime/channels/fanout-service-wire.d.ts +12 -0
- package/dist/runtime/channels/fanout-service-wire.js +29 -0
- package/dist/runtime/channels/handler-filter-scope.d.ts +8 -0
- package/dist/runtime/channels/handler-filter-scope.js +11 -0
- package/dist/runtime/channels/index.d.ts +9 -0
- package/dist/runtime/channels/index.js +30 -0
- package/dist/runtime/channels/local-spot-route-transport.d.ts +9 -0
- package/dist/runtime/channels/local-spot-route-transport.js +40 -0
- package/dist/runtime/channels/route-disconnected-error.d.ts +3 -0
- package/dist/runtime/channels/route-disconnected-error.js +10 -0
- package/dist/runtime/channels/route-member-snapshot.d.ts +10 -0
- package/dist/runtime/channels/route-member-snapshot.js +55 -0
- package/dist/runtime/channels/router-socket-spot-route-transport.d.ts +12 -0
- package/dist/runtime/channels/router-socket-spot-route-transport.js +43 -0
- package/dist/runtime/channels/source-spot-router.d.ts +10 -0
- package/dist/runtime/channels/source-spot-router.js +46 -0
- package/dist/runtime/channels/spot-direct-envelope.d.ts +5 -0
- package/dist/runtime/channels/spot-direct-envelope.js +29 -0
- package/dist/runtime/channels/spot-node-route-transport.d.ts +13 -0
- package/dist/runtime/channels/spot-node-route-transport.js +60 -0
- package/dist/runtime/channels/spot-route-bridge-transport.d.ts +14 -0
- package/dist/runtime/channels/spot-route-bridge-transport.js +58 -0
- package/dist/runtime/channels/spot-route-dispatch-strategy.d.ts +50 -0
- package/dist/runtime/channels/spot-route-dispatch-strategy.js +128 -0
- package/dist/runtime/channels/spot-route-target-resolver.d.ts +16 -0
- package/dist/runtime/channels/spot-route-target-resolver.js +92 -0
- package/dist/runtime/codecs/index.d.ts +14 -0
- package/dist/runtime/codecs/index.js +44 -0
- package/dist/runtime/configuration/index.d.ts +1 -0
- package/dist/runtime/configuration/index.js +17 -0
- package/dist/runtime/diagnostics/dispatch-error-port.d.ts +8 -0
- package/dist/runtime/diagnostics/dispatch-error-port.js +2 -0
- package/dist/runtime/diagnostics/flow-context.d.ts +21 -0
- package/dist/runtime/diagnostics/flow-context.js +68 -0
- package/dist/runtime/diagnostics/index.d.ts +82 -0
- package/dist/runtime/diagnostics/index.js +335 -0
- package/dist/runtime/diagnostics/internal-event-contracts.d.ts +139 -0
- package/dist/runtime/diagnostics/internal-event-contracts.js +68 -0
- package/dist/runtime/diagnostics/message-flow.d.ts +55 -0
- package/dist/runtime/diagnostics/message-flow.js +420 -0
- package/dist/runtime/diagnostics/runtime-metrics.d.ts +123 -0
- package/dist/runtime/diagnostics/runtime-metrics.js +454 -0
- package/dist/runtime/diagnostics/runtime-observation-queue.d.ts +58 -0
- package/dist/runtime/diagnostics/runtime-observation-queue.js +324 -0
- package/dist/runtime/diagnostics/topology-runtime-projections.d.ts +33 -0
- package/dist/runtime/diagnostics/topology-runtime-projections.js +255 -0
- package/dist/runtime/execution/index.d.ts +114 -0
- package/dist/runtime/execution/index.js +363 -0
- package/dist/runtime/execution/serial-execution-queue.d.ts +94 -0
- package/dist/runtime/execution/serial-execution-queue.js +411 -0
- package/dist/runtime/execution/serial-work-size.d.ts +4 -0
- package/dist/runtime/execution/serial-work-size.js +28 -0
- package/dist/runtime/execution/state-lane.d.ts +28 -0
- package/dist/runtime/execution/state-lane.js +105 -0
- package/dist/runtime/foundation/actor-join-recovery-codec.d.ts +72 -0
- package/dist/runtime/foundation/actor-join-recovery-codec.js +333 -0
- package/dist/runtime/foundation/event-loop-resources.d.ts +37 -0
- package/dist/runtime/foundation/event-loop-resources.js +163 -0
- package/dist/runtime/foundation/index.d.ts +18 -0
- package/dist/runtime/foundation/index.js +34 -0
- package/dist/runtime/foundation/message-follow-suppression-registry.d.ts +38 -0
- package/dist/runtime/foundation/message-follow-suppression-registry.js +89 -0
- package/dist/runtime/foundation/operation-identity.d.ts +12 -0
- package/dist/runtime/foundation/operation-identity.js +33 -0
- package/dist/runtime/foundation/operation-registry.d.ts +42 -0
- package/dist/runtime/foundation/operation-registry.js +146 -0
- package/dist/runtime/foundation/raw-service-mesh-runtime.d.ts +143 -0
- package/dist/runtime/foundation/raw-service-mesh-runtime.js +1349 -0
- package/dist/runtime/foundation/route-mesh-connection-policy.d.ts +3 -0
- package/dist/runtime/foundation/route-mesh-connection-policy.js +13 -0
- package/dist/runtime/foundation/runtime-state-projections.d.ts +13 -0
- package/dist/runtime/foundation/runtime-state-projections.js +44 -0
- package/dist/runtime/foundation/service-authority-payload-codec.d.ts +56 -0
- package/dist/runtime/foundation/service-authority-payload-codec.js +411 -0
- package/dist/runtime/foundation/service-discovery-registry.d.ts +42 -0
- package/dist/runtime/foundation/service-discovery-registry.js +175 -0
- package/dist/runtime/foundation/service-instance-activation-recovery-codec.d.ts +19 -0
- package/dist/runtime/foundation/service-instance-activation-recovery-codec.js +287 -0
- package/dist/runtime/foundation/service-liveness-registry.d.ts +28 -0
- package/dist/runtime/foundation/service-liveness-registry.js +109 -0
- package/dist/runtime/foundation/service-mailbox.d.ts +60 -0
- package/dist/runtime/foundation/service-mailbox.js +283 -0
- package/dist/runtime/foundation/service-maintenance-runtime.d.ts +45 -0
- package/dist/runtime/foundation/service-maintenance-runtime.js +198 -0
- package/dist/runtime/foundation/service-metadata-codec.d.ts +2 -0
- package/dist/runtime/foundation/service-metadata-codec.js +69 -0
- package/dist/runtime/foundation/service-relocation-aggregate-committer.d.ts +35 -0
- package/dist/runtime/foundation/service-relocation-aggregate-committer.js +139 -0
- package/dist/runtime/foundation/service-relocation-coordinator.d.ts +19 -0
- package/dist/runtime/foundation/service-relocation-coordinator.js +16 -0
- package/dist/runtime/foundation/service-relocation-object-owner.d.ts +71 -0
- package/dist/runtime/foundation/service-relocation-object-owner.js +242 -0
- package/dist/runtime/foundation/service-relocation-runtime.d.ts +143 -0
- package/dist/runtime/foundation/service-relocation-runtime.js +1080 -0
- package/dist/runtime/foundation/service-runtime-contracts.d.ts +332 -0
- package/dist/runtime/foundation/service-runtime-contracts.js +66 -0
- package/dist/runtime/foundation/service-session-binding-ingress-port.d.ts +23 -0
- package/dist/runtime/foundation/service-session-binding-ingress-port.js +11 -0
- package/dist/runtime/foundation/service-stateful-registry.d.ts +142 -0
- package/dist/runtime/foundation/service-stateful-registry.js +465 -0
- package/dist/runtime/foundation/service-stateful-runtime.d.ts +393 -0
- package/dist/runtime/foundation/service-stateful-runtime.js +3898 -0
- package/dist/runtime/foundation/service-stateful-wire-codec.d.ts +597 -0
- package/dist/runtime/foundation/service-stateful-wire-codec.js +2006 -0
- package/dist/runtime/foundation/service-topology-registry.d.ts +68 -0
- package/dist/runtime/foundation/service-topology-registry.js +393 -0
- package/dist/runtime/foundation/service-weighted-selection.d.ts +14 -0
- package/dist/runtime/foundation/service-weighted-selection.js +128 -0
- package/dist/runtime/foundation/service-wire-binary-primitives.d.ts +10 -0
- package/dist/runtime/foundation/service-wire-binary-primitives.js +53 -0
- package/dist/runtime/foundation/service-wire-codec.d.ts +22 -0
- package/dist/runtime/foundation/service-wire-codec.js +67 -0
- package/dist/runtime/foundation/service-wire-constants.generated.d.ts +110 -0
- package/dist/runtime/foundation/service-wire-constants.generated.js +132 -0
- package/dist/runtime/foundation/service-wire-m6a-codec.d.ts +102 -0
- package/dist/runtime/foundation/service-wire-m6a-codec.js +568 -0
- package/dist/runtime/framework-errors-internal.d.ts +95 -0
- package/dist/runtime/framework-errors-internal.js +301 -0
- package/dist/runtime/handlers/handler-instance-scope.d.ts +11 -0
- package/dist/runtime/handlers/handler-instance-scope.js +284 -0
- package/dist/runtime/handlers/index.d.ts +13 -0
- package/dist/runtime/handlers/index.js +57 -0
- package/dist/runtime/host/actor-packet-relay.d.ts +60 -0
- package/dist/runtime/host/actor-packet-relay.js +664 -0
- package/dist/runtime/host/actor-placement-coordinator.d.ts +32 -0
- package/dist/runtime/host/actor-placement-coordinator.js +386 -0
- package/dist/runtime/host/actor-runtime-options-factory.d.ts +65 -0
- package/dist/runtime/host/actor-runtime-options-factory.js +160 -0
- package/dist/runtime/host/actor-transfer-authority-runtime.d.ts +26 -0
- package/dist/runtime/host/actor-transfer-authority-runtime.js +138 -0
- package/dist/runtime/host/actor-transfer-runtime.d.ts +149 -0
- package/dist/runtime/host/actor-transfer-runtime.js +1245 -0
- package/dist/runtime/host/application-job-queue.d.ts +99 -0
- package/dist/runtime/host/application-job-queue.js +409 -0
- package/dist/runtime/host/bound-session-relay.d.ts +41 -0
- package/dist/runtime/host/bound-session-relay.js +52 -0
- package/dist/runtime/host/bounded-replay-map.d.ts +12 -0
- package/dist/runtime/host/bounded-replay-map.js +42 -0
- package/dist/runtime/host/channel-runtime-options-factory.d.ts +22 -0
- package/dist/runtime/host/channel-runtime-options-factory.js +76 -0
- package/dist/runtime/host/entry-actor-runtime.d.ts +30 -0
- package/dist/runtime/host/entry-actor-runtime.js +80 -0
- package/dist/runtime/host/host-capacity-status.d.ts +11 -0
- package/dist/runtime/host/host-capacity-status.js +85 -0
- package/dist/runtime/host/index.d.ts +188 -0
- package/dist/runtime/host/index.js +2552 -0
- package/dist/runtime/host/instance-activation-authority.d.ts +33 -0
- package/dist/runtime/host/instance-activation-authority.js +496 -0
- package/dist/runtime/host/location-runtime-owner.d.ts +48 -0
- package/dist/runtime/host/location-runtime-owner.js +227 -0
- package/dist/runtime/host/mesh-router-resolver.d.ts +16 -0
- package/dist/runtime/host/mesh-router-resolver.js +108 -0
- package/dist/runtime/host/relocation-direct-transfer.d.ts +81 -0
- package/dist/runtime/host/relocation-direct-transfer.js +240 -0
- package/dist/runtime/host/relocation-integrity-fault-gate.d.ts +6 -0
- package/dist/runtime/host/relocation-integrity-fault-gate.js +5 -0
- package/dist/runtime/host/relocation-state-adapter.d.ts +8 -0
- package/dist/runtime/host/relocation-state-adapter.js +13 -0
- package/dist/runtime/host/remote-actor-join-receiver.d.ts +47 -0
- package/dist/runtime/host/remote-actor-join-receiver.js +161 -0
- package/dist/runtime/host/remote-actor-packet-target-store.d.ts +29 -0
- package/dist/runtime/host/remote-actor-packet-target-store.js +185 -0
- package/dist/runtime/host/remote-bound-session-relay.d.ts +58 -0
- package/dist/runtime/host/remote-bound-session-relay.js +540 -0
- package/dist/runtime/host/route-mesh-runtime-options.d.ts +9 -0
- package/dist/runtime/host/route-mesh-runtime-options.js +41 -0
- package/dist/runtime/host/route-mesh-runtime.d.ts +76 -0
- package/dist/runtime/host/route-mesh-runtime.js +746 -0
- package/dist/runtime/host/runtime-shutdown.d.ts +33 -0
- package/dist/runtime/host/runtime-shutdown.js +68 -0
- package/dist/runtime/host/service-relocation-control.d.ts +7 -0
- package/dist/runtime/host/service-relocation-control.js +24 -0
- package/dist/runtime/host/service-relocation-host-runtime.d.ts +241 -0
- package/dist/runtime/host/service-relocation-host-runtime.js +4113 -0
- package/dist/runtime/host/spot-address-transport.d.ts +47 -0
- package/dist/runtime/host/spot-address-transport.js +601 -0
- package/dist/runtime/host/spot-node-runtime-options-factory.d.ts +38 -0
- package/dist/runtime/host/spot-node-runtime-options-factory.js +36 -0
- package/dist/runtime/host/spot-runtime-options-factory.d.ts +48 -0
- package/dist/runtime/host/spot-runtime-options-factory.js +169 -0
- package/dist/runtime/host/stateful-authority-route-runtime.d.ts +34 -0
- package/dist/runtime/host/stateful-authority-route-runtime.js +440 -0
- package/dist/runtime/host/user-spot-creation-coordinator.d.ts +69 -0
- package/dist/runtime/host/user-spot-creation-coordinator.js +759 -0
- package/dist/runtime/locations/actor-location-claims.d.ts +43 -0
- package/dist/runtime/locations/actor-location-claims.js +319 -0
- package/dist/runtime/locations/actor-session-route-claims.d.ts +10 -0
- package/dist/runtime/locations/actor-session-route-claims.js +51 -0
- package/dist/runtime/locations/aggregate-inventory-store.d.ts +18 -0
- package/dist/runtime/locations/aggregate-inventory-store.js +399 -0
- package/dist/runtime/locations/authority-key-codec.d.ts +6 -0
- package/dist/runtime/locations/authority-key-codec.js +78 -0
- package/dist/runtime/locations/auto-connect-loop.d.ts +37 -0
- package/dist/runtime/locations/auto-connect-loop.js +112 -0
- package/dist/runtime/locations/auto-connect-planner.d.ts +9 -0
- package/dist/runtime/locations/auto-connect-planner.js +137 -0
- package/dist/runtime/locations/auto-connect-reconciler.d.ts +57 -0
- package/dist/runtime/locations/auto-connect-reconciler.js +358 -0
- package/dist/runtime/locations/auto-connect-types.d.ts +42 -0
- package/dist/runtime/locations/auto-connect-types.js +2 -0
- package/dist/runtime/locations/auto-connect.d.ts +4 -0
- package/dist/runtime/locations/auto-connect.js +20 -0
- package/dist/runtime/locations/canonical-codec.d.ts +7 -0
- package/dist/runtime/locations/canonical-codec.js +48 -0
- package/dist/runtime/locations/domain-store-contract.d.ts +34 -0
- package/dist/runtime/locations/domain-store-contract.js +2 -0
- package/dist/runtime/locations/in-memory-authority-store.d.ts +51 -0
- package/dist/runtime/locations/in-memory-authority-store.js +895 -0
- package/dist/runtime/locations/in-memory-location-store.d.ts +78 -0
- package/dist/runtime/locations/in-memory-location-store.js +1008 -0
- package/dist/runtime/locations/in-memory-provider-location-store.d.ts +19 -0
- package/dist/runtime/locations/in-memory-provider-location-store.js +183 -0
- package/dist/runtime/locations/index.d.ts +11 -0
- package/dist/runtime/locations/index.js +27 -0
- package/dist/runtime/locations/internal-location-contracts.d.ts +7 -0
- package/dist/runtime/locations/internal-location-contracts.js +21 -0
- package/dist/runtime/locations/internal-store-contracts.d.ts +35 -0
- package/dist/runtime/locations/internal-store-contracts.js +2 -0
- package/dist/runtime/locations/key-codec.d.ts +13 -0
- package/dist/runtime/locations/key-codec.js +41 -0
- package/dist/runtime/locations/lease-tracker.d.ts +36 -0
- package/dist/runtime/locations/lease-tracker.js +155 -0
- package/dist/runtime/locations/lifecycle-runtime.d.ts +19 -0
- package/dist/runtime/locations/lifecycle-runtime.js +2 -0
- package/dist/runtime/locations/lifecycle.d.ts +40 -0
- package/dist/runtime/locations/lifecycle.js +120 -0
- package/dist/runtime/locations/location-store-repository.d.ts +72 -0
- package/dist/runtime/locations/location-store-repository.js +3198 -0
- package/dist/runtime/locations/relocation-blob.d.ts +7 -0
- package/dist/runtime/locations/relocation-blob.js +24 -0
- package/dist/runtime/locations/resolvers.d.ts +145 -0
- package/dist/runtime/locations/resolvers.js +693 -0
- package/dist/runtime/locations/runtime.d.ts +144 -0
- package/dist/runtime/locations/runtime.js +792 -0
- package/dist/runtime/locations/spot-location-claims.d.ts +36 -0
- package/dist/runtime/locations/spot-location-claims.js +305 -0
- package/dist/runtime/messaging/creation-payload-codec.d.ts +4 -0
- package/dist/runtime/messaging/creation-payload-codec.js +40 -0
- package/dist/runtime/messaging/framework-json-v1.d.ts +7 -0
- package/dist/runtime/messaging/framework-json-v1.js +296 -0
- package/dist/runtime/messaging/index.d.ts +1 -0
- package/dist/runtime/messaging/index.js +2 -0
- package/dist/runtime/messaging/packet-name.d.ts +4 -0
- package/dist/runtime/messaging/packet-name.js +79 -0
- package/dist/runtime/messaging/payload-codec.d.ts +25 -0
- package/dist/runtime/messaging/payload-codec.js +255 -0
- package/dist/runtime/messaging/submission-result.d.ts +15 -0
- package/dist/runtime/messaging/submission-result.js +37 -0
- package/dist/runtime/protocol/service_wire_pilot_codec.generated.d.ts +395 -0
- package/dist/runtime/protocol/service_wire_pilot_codec.generated.js +645 -0
- package/dist/runtime/routing-id.d.ts +8 -0
- package/dist/runtime/routing-id.js +112 -0
- package/dist/runtime/spots/formal-remote-actor-admission-registry.d.ts +124 -0
- package/dist/runtime/spots/formal-remote-actor-admission-registry.js +269 -0
- package/dist/runtime/spots/formal-remote-actor-transfer-registry.d.ts +33 -0
- package/dist/runtime/spots/formal-remote-actor-transfer-registry.js +94 -0
- package/dist/runtime/spots/index.d.ts +247 -0
- package/dist/runtime/spots/index.js +2090 -0
- package/dist/runtime/spots/spot-activation-registry.d.ts +47 -0
- package/dist/runtime/spots/spot-activation-registry.js +272 -0
- package/dist/runtime/spots/spot-activation-state.d.ts +104 -0
- package/dist/runtime/spots/spot-activation-state.js +288 -0
- package/dist/runtime/spots/spot-activation.d.ts +89 -0
- package/dist/runtime/spots/spot-activation.js +601 -0
- package/dist/runtime/spots/spot-actor-admission-coordinator.d.ts +20 -0
- package/dist/runtime/spots/spot-actor-admission-coordinator.js +194 -0
- package/dist/runtime/spots/spot-actor-join-dispatch.d.ts +83 -0
- package/dist/runtime/spots/spot-actor-join-dispatch.js +185 -0
- package/dist/runtime/spots/spot-actor-lifecycle-drain.d.ts +22 -0
- package/dist/runtime/spots/spot-actor-lifecycle-drain.js +51 -0
- package/dist/runtime/spots/spot-actor-membership.d.ts +39 -0
- package/dist/runtime/spots/spot-actor-membership.js +179 -0
- package/dist/runtime/spots/spot-actor-packet-dispatch.d.ts +91 -0
- package/dist/runtime/spots/spot-actor-packet-dispatch.js +315 -0
- package/dist/runtime/spots/spot-actor-packet-drain.d.ts +40 -0
- package/dist/runtime/spots/spot-actor-packet-drain.js +235 -0
- package/dist/runtime/spots/spot-actor-packet-relay-dispatch.d.ts +18 -0
- package/dist/runtime/spots/spot-actor-packet-relay-dispatch.js +110 -0
- package/dist/runtime/spots/spot-closing.d.ts +2 -0
- package/dist/runtime/spots/spot-closing.js +30 -0
- package/dist/runtime/spots/spot-context.d.ts +46 -0
- package/dist/runtime/spots/spot-context.js +113 -0
- package/dist/runtime/spots/spot-entry-activation.d.ts +107 -0
- package/dist/runtime/spots/spot-entry-activation.js +342 -0
- package/dist/runtime/spots/spot-handle.d.ts +28 -0
- package/dist/runtime/spots/spot-handle.js +38 -0
- package/dist/runtime/spots/spot-handler-registry.d.ts +52 -0
- package/dist/runtime/spots/spot-handler-registry.js +155 -0
- package/dist/runtime/spots/spot-lifecycle-metrics.d.ts +8 -0
- package/dist/runtime/spots/spot-lifecycle-metrics.js +16 -0
- package/dist/runtime/spots/spot-location-claim.d.ts +25 -0
- package/dist/runtime/spots/spot-location-claim.js +55 -0
- package/dist/runtime/spots/spot-manager-internal-contracts.d.ts +10 -0
- package/dist/runtime/spots/spot-manager-internal-contracts.js +2 -0
- package/dist/runtime/spots/spot-manager-public.d.ts +32 -0
- package/dist/runtime/spots/spot-manager-public.js +219 -0
- package/dist/runtime/spots/spot-native-actor-join-admission.d.ts +26 -0
- package/dist/runtime/spots/spot-native-actor-join-admission.js +105 -0
- package/dist/runtime/spots/spot-native-flags.d.ts +2 -0
- package/dist/runtime/spots/spot-native-flags.js +5 -0
- package/dist/runtime/spots/spot-node-autoconnect.d.ts +23 -0
- package/dist/runtime/spots/spot-node-autoconnect.js +246 -0
- package/dist/runtime/spots/spot-node-runtime-manager.d.ts +137 -0
- package/dist/runtime/spots/spot-node-runtime-manager.js +1111 -0
- package/dist/runtime/spots/spot-outbound.d.ts +78 -0
- package/dist/runtime/spots/spot-outbound.js +460 -0
- package/dist/runtime/spots/spot-provider.d.ts +4 -0
- package/dist/runtime/spots/spot-provider.js +28 -0
- package/dist/runtime/spots/spot-publisher-transport.d.ts +14 -0
- package/dist/runtime/spots/spot-publisher-transport.js +28 -0
- package/dist/runtime/spots/spot-remote-codec.d.ts +50 -0
- package/dist/runtime/spots/spot-remote-codec.js +190 -0
- package/dist/runtime/spots/spot-remote-route-codec.d.ts +47 -0
- package/dist/runtime/spots/spot-remote-route-codec.js +168 -0
- package/dist/runtime/spots/spot-route-packet-dispatch.d.ts +25 -0
- package/dist/runtime/spots/spot-route-packet-dispatch.js +238 -0
- package/dist/runtime/spots/spot-route-replies.d.ts +17 -0
- package/dist/runtime/spots/spot-route-replies.js +76 -0
- package/dist/runtime/spots/spot-route-reply-wire.d.ts +10 -0
- package/dist/runtime/spots/spot-route-reply-wire.js +6 -0
- package/dist/runtime/spots/spot-routed-actor-admission.d.ts +36 -0
- package/dist/runtime/spots/spot-routed-actor-admission.js +240 -0
- package/dist/runtime/spots/spot-routed-bound-session-dispatch.d.ts +19 -0
- package/dist/runtime/spots/spot-routed-bound-session-dispatch.js +46 -0
- package/dist/runtime/spots/spot-routed-frame-dispatch.d.ts +54 -0
- package/dist/runtime/spots/spot-routed-frame-dispatch.js +162 -0
- package/dist/runtime/spots/spot-routed-spot-packet-dispatch.d.ts +43 -0
- package/dist/runtime/spots/spot-routed-spot-packet-dispatch.js +152 -0
- package/dist/runtime/spots/spot-routing-internal.d.ts +28 -0
- package/dist/runtime/spots/spot-routing-internal.js +2 -0
- package/dist/runtime/spots/spot-runtime-ports.d.ts +64 -0
- package/dist/runtime/spots/spot-runtime-ports.js +2 -0
- package/dist/runtime/spots/spot-serial-executor.d.ts +38 -0
- package/dist/runtime/spots/spot-serial-executor.js +133 -0
- package/dist/runtime/spots/spot-serial-turn-executor.d.ts +54 -0
- package/dist/runtime/spots/spot-serial-turn-executor.js +219 -0
- package/dist/runtime/spots/spot-subscription-dispatch.d.ts +32 -0
- package/dist/runtime/spots/spot-subscription-dispatch.js +194 -0
- package/dist/runtime/spots/spot-timer.d.ts +110 -0
- package/dist/runtime/spots/spot-timer.js +419 -0
- package/dist/runtime/streams/actor-session-binding-registry.d.ts +193 -0
- package/dist/runtime/streams/actor-session-binding-registry.js +1127 -0
- package/dist/runtime/streams/actor-session-binding-runtime-owner.d.ts +20 -0
- package/dist/runtime/streams/actor-session-binding-runtime-owner.js +19 -0
- package/dist/runtime/streams/actor-session-lifecycle-coordinator.d.ts +4 -0
- package/dist/runtime/streams/actor-session-lifecycle-coordinator.js +24 -0
- package/dist/runtime/streams/bound-actor-relay-sender.d.ts +29 -0
- package/dist/runtime/streams/bound-actor-relay-sender.js +181 -0
- package/dist/runtime/streams/bound-session-response-target.d.ts +25 -0
- package/dist/runtime/streams/bound-session-response-target.js +54 -0
- package/dist/runtime/streams/bound-session-service.d.ts +48 -0
- package/dist/runtime/streams/bound-session-service.js +201 -0
- package/dist/runtime/streams/index.d.ts +152 -0
- package/dist/runtime/streams/index.js +338 -0
- package/dist/runtime/streams/managed-stream.d.ts +53 -0
- package/dist/runtime/streams/managed-stream.js +329 -0
- package/dist/runtime/streams/native-fallback-bound-session.d.ts +24 -0
- package/dist/runtime/streams/native-fallback-bound-session.js +201 -0
- package/dist/runtime/streams/protocol.d.ts +67 -0
- package/dist/runtime/streams/protocol.js +244 -0
- package/dist/runtime/streams/session-actor-coordinator.d.ts +56 -0
- package/dist/runtime/streams/session-actor-coordinator.js +371 -0
- package/dist/runtime/streams/session-calls.d.ts +59 -0
- package/dist/runtime/streams/session-calls.js +123 -0
- package/dist/runtime/streams/session-context.d.ts +108 -0
- package/dist/runtime/streams/session-context.js +377 -0
- package/dist/runtime/streams/session-local-actors.d.ts +10 -0
- package/dist/runtime/streams/session-local-actors.js +26 -0
- package/dist/runtime/streams/session-provider.d.ts +4 -0
- package/dist/runtime/streams/session-provider.js +30 -0
- package/dist/runtime/streams/session-requests.d.ts +25 -0
- package/dist/runtime/streams/session-requests.js +100 -0
- package/dist/runtime/streams/session-serial-executor.d.ts +12 -0
- package/dist/runtime/streams/session-serial-executor.js +58 -0
- package/dist/runtime/streams/stream-binding-runtime-ports.d.ts +62 -0
- package/dist/runtime/streams/stream-binding-runtime-ports.js +2 -0
- package/dist/runtime/streams/stream-frame-factory.d.ts +44 -0
- package/dist/runtime/streams/stream-frame-factory.js +149 -0
- package/dist/runtime/streams/stream-message-utils.d.ts +5 -0
- package/dist/runtime/streams/stream-message-utils.js +74 -0
- package/dist/runtime/streams/stream-session-runtime.d.ts +166 -0
- package/dist/runtime/streams/stream-session-runtime.js +1144 -0
- package/dist/runtime/workers/index.d.ts +38 -0
- package/dist/runtime/workers/index.js +474 -0
- package/package.json +19 -0
- package/src/contracts/Actors/ZLinkActor.ts +8 -0
- package/src/contracts/Actors/ZLinkActorClient.ts +18 -0
- package/src/contracts/Actors/ZLinkActorContext.ts +15 -0
- package/src/contracts/Actors/ZLinkActorFactory.ts +41 -0
- package/src/contracts/Actors/ZLinkActorManager.ts +31 -0
- package/src/contracts/Actors/index.ts +5 -0
- package/src/contracts/Channels/Calls.ts +33 -0
- package/src/contracts/Channels/IZLinkChannelClient.ts +6 -0
- package/src/contracts/Channels/IZLinkFanoutClient.ts +13 -0
- package/src/contracts/Channels/RouteCalls.ts +13 -0
- package/src/contracts/Channels/index.ts +4 -0
- package/src/contracts/Codecs/IZLinkCodecRegistryBuilder.ts +22 -0
- package/src/contracts/Codecs/ZLinkMessageSerializer.ts +6 -0
- package/src/contracts/Codecs/index.ts +2 -0
- package/src/contracts/Common/ActorRef.ts +8 -0
- package/src/contracts/Common/CoreTypes.ts +6 -0
- package/src/contracts/Common/Message.ts +9 -0
- package/src/contracts/Common/ZLinkEncodedPayload.ts +47 -0
- package/src/contracts/Common/ZLinkMessage.ts +135 -0
- package/src/contracts/Common/ZLinkMessageMetadata.ts +77 -0
- package/src/contracts/Common/ZLinkProviderResolver.ts +6 -0
- package/src/contracts/Common/encoded-payload-storage.ts +16 -0
- package/src/contracts/Common/index.ts +5 -0
- package/src/contracts/Configuration/Builders.ts +200 -0
- package/src/contracts/Configuration/CodecContentType.ts +68 -0
- package/src/contracts/Configuration/CodecSerializerSelection.ts +28 -0
- package/src/contracts/Configuration/Configs.ts +27 -0
- package/src/contracts/Configuration/ConfigurationException.ts +6 -0
- package/src/contracts/Configuration/Connections.ts +5 -0
- package/src/contracts/Configuration/DiagnosticsValidation.ts +25 -0
- package/src/contracts/Configuration/EndpointNotation.ts +232 -0
- package/src/contracts/Configuration/InternalDefaults.ts +13 -0
- package/src/contracts/Configuration/ObjectRoles.ts +47 -0
- package/src/contracts/Configuration/Registration.ts +191 -0
- package/src/contracts/Configuration/RegistrationBuilderPolicy.ts +76 -0
- package/src/contracts/Configuration/RegistrationBuilders.ts +1705 -0
- package/src/contracts/Configuration/RegistrationCodecRegistry.ts +118 -0
- package/src/contracts/Configuration/RegistrationNormalizers.ts +404 -0
- package/src/contracts/Configuration/RegistrationTypes.ts +499 -0
- package/src/contracts/Configuration/RegistrationValidators.ts +698 -0
- package/src/contracts/Configuration/RouteChannelInternalState.ts +50 -0
- package/src/contracts/Configuration/RuntimeEndpointConnections.ts +91 -0
- package/src/contracts/Configuration/SendTimeoutValidation.ts +15 -0
- package/src/contracts/Configuration/TimerRegistrationValidator.ts +37 -0
- package/src/contracts/Configuration/index.ts +35 -0
- package/src/contracts/Dispatch/ZLinkDispatchOptions.ts +222 -0
- package/src/contracts/Dispatch/ZLinkFlowOrigin.ts +1 -0
- package/src/contracts/Dispatch/index.ts +2 -0
- package/src/contracts/Errors/ZLinkFrameworkException.ts +27 -0
- package/src/contracts/Errors/index.ts +4 -0
- package/src/contracts/Eventing/Metrics.ts +27 -0
- package/src/contracts/Eventing/index.ts +1 -0
- package/src/contracts/Handlers/Attributes.ts +111 -0
- package/src/contracts/Handlers/Contexts.ts +21 -0
- package/src/contracts/Handlers/IZLinkChannelHandlers.ts +69 -0
- package/src/contracts/Handlers/IZLinkHandlerFilter.ts +22 -0
- package/src/contracts/Handlers/JsonContract.ts +172 -0
- package/src/contracts/Handlers/ZLinkHandlerFilterNext.ts +1 -0
- package/src/contracts/Handlers/index.ts +17 -0
- package/src/contracts/Locations/ActorTransfer.ts +84 -0
- package/src/contracts/Locations/Authority.ts +308 -0
- package/src/contracts/Locations/Diagnostics.ts +48 -0
- package/src/contracts/Locations/Keys.ts +93 -0
- package/src/contracts/Locations/Models.ts +7 -0
- package/src/contracts/Locations/Options.ts +42 -0
- package/src/contracts/Locations/Readiness.ts +11 -0
- package/src/contracts/Locations/RelocationStore.ts +51 -0
- package/src/contracts/Locations/Resolvers.ts +8 -0
- package/src/contracts/Locations/Rows.ts +164 -0
- package/src/contracts/Locations/RuntimeQuery.ts +56 -0
- package/src/contracts/Locations/Stores.ts +92 -0
- package/src/contracts/Locations/Values.ts +32 -0
- package/src/contracts/Locations/Watch.ts +16 -0
- package/src/contracts/Locations/Writes.ts +56 -0
- package/src/contracts/Locations/index.ts +48 -0
- package/src/contracts/RouteMesh/Contracts.ts +145 -0
- package/src/contracts/RouteMesh/RuntimeTopology.ts +201 -0
- package/src/contracts/RouteMesh/index.ts +2 -0
- package/src/contracts/Spots/Builders.ts +11 -0
- package/src/contracts/Spots/Contracts.ts +150 -0
- package/src/contracts/Spots/SpotKind.ts +24 -0
- package/src/contracts/Spots/ZLinkSpot.ts +88 -0
- package/src/contracts/Spots/index.ts +3 -0
- package/src/contracts/Streams/BoundSessionContracts.ts +9 -0
- package/src/contracts/Streams/IZLinkSession.ts +52 -0
- package/src/contracts/Streams/IZLinkSessionActor.ts +17 -0
- package/src/contracts/Streams/IZLinkSessionPacketHandler.ts +11 -0
- package/src/contracts/Streams/IZLinkStream.ts +10 -0
- package/src/contracts/Streams/ZLinkMessageMetadata.ts +1 -0
- package/src/contracts/Streams/ZLinkStreamCompression.ts +9 -0
- package/src/contracts/Streams/ZLinkStreamError.ts +9 -0
- package/src/contracts/Streams/index.ts +8 -0
- package/src/contracts/Timers/IZLinkTimer.ts +5 -0
- package/src/contracts/Timers/ZLinkTimerOptions.ts +11 -0
- package/src/contracts/Timers/ZLinkTimerTick.ts +12 -0
- package/src/contracts/Timers/index.ts +3 -0
- package/src/contracts/index.ts +71 -0
- package/src/index.ts +1 -0
- package/src/internal.ts +29 -0
- package/src/location-store-integration.ts +51 -0
- package/src/nest-integration.ts +251 -0
- package/src/runtime/abort.ts +70 -0
- package/src/runtime/actors/actor-authority-payload-codec.ts +454 -0
- package/src/runtime/actors/actor-authority-publication.ts +277 -0
- package/src/runtime/actors/actor-client.ts +1018 -0
- package/src/runtime/actors/actor-context.ts +583 -0
- package/src/runtime/actors/actor-creation.ts +254 -0
- package/src/runtime/actors/actor-execution-context.ts +38 -0
- package/src/runtime/actors/actor-handoff.ts +1911 -0
- package/src/runtime/actors/actor-join-deferred-scope.ts +183 -0
- package/src/runtime/actors/actor-join-relocation.ts +39 -0
- package/src/runtime/actors/actor-lifecycle-snapshot.ts +90 -0
- package/src/runtime/actors/actor-local-native-join.ts +725 -0
- package/src/runtime/actors/actor-mailbox.ts +92 -0
- package/src/runtime/actors/actor-message-follow-context.ts +347 -0
- package/src/runtime/actors/actor-native-lookup.ts +38 -0
- package/src/runtime/actors/actor-packet-relay-wire.ts +223 -0
- package/src/runtime/actors/actor-remote-joiner.ts +238 -0
- package/src/runtime/actors/actor-remote-wire.ts +169 -0
- package/src/runtime/actors/actor-retry-delay.ts +37 -0
- package/src/runtime/actors/actor-routed-join-transport.ts +58 -0
- package/src/runtime/actors/actor-routed-json-request.ts +44 -0
- package/src/runtime/actors/actor-runtime-contracts.ts +126 -0
- package/src/runtime/actors/actor-runtime-state.ts +805 -0
- package/src/runtime/actors/actor-source-transfer.ts +62 -0
- package/src/runtime/actors/actor-transfer-registry.ts +112 -0
- package/src/runtime/actors/actor-transport-delivery-gate.ts +17 -0
- package/src/runtime/actors/bound-session-wire.ts +257 -0
- package/src/runtime/actors/deferred-join-accepted-journal.ts +1319 -0
- package/src/runtime/actors/index.ts +972 -0
- package/src/runtime/actors/post-commit-actor-binder.ts +70 -0
- package/src/runtime/actors/post-commit-actor-location.ts +114 -0
- package/src/runtime/actors/spot-actor-dispatch.ts +362 -0
- package/src/runtime/actors/transferred-actor-rollback.ts +123 -0
- package/src/runtime/admission.ts +192 -0
- package/src/runtime/application-jobs/application-ingress-record-owner.ts +216 -0
- package/src/runtime/application-jobs/application-job-queue-handler-start-gate.ts +10 -0
- package/src/runtime/application-jobs/application-job-queue-scope.ts +64 -0
- package/src/runtime/application-jobs/contracts.ts +26 -0
- package/src/runtime/application-jobs/receive-flow-controller.ts +188 -0
- package/src/runtime/backend/contracts/index.ts +765 -0
- package/src/runtime/backend/index.ts +9 -0
- package/src/runtime/backend/mesh-actor-session-node-adapter.ts +73 -0
- package/src/runtime/backend/mesh-completion-table.ts +165 -0
- package/src/runtime/backend/mesh-dispatch-pump.ts +363 -0
- package/src/runtime/backend/mesh-record-dispatcher.ts +65 -0
- package/src/runtime/backend/node/index.ts +4 -0
- package/src/runtime/backend/node/node-backend-adapter-factory.ts +204 -0
- package/src/runtime/backend/node/node-backend-adapter-support.ts +257 -0
- package/src/runtime/backend/node/node-dealer-channel-client-transport.ts +133 -0
- package/src/runtime/backend/node/node-mesh-backend-adapter.ts +44 -0
- package/src/runtime/backend/node/node-monitor-backend-adapter.ts +39 -0
- package/src/runtime/backend/node/node-raw-binding-port.contract.ts +21 -0
- package/src/runtime/backend/node/node-raw-binding-port.ts +518 -0
- package/src/runtime/backend/node/node-raw-mesh-backend.ts +2669 -0
- package/src/runtime/backend/node/node-socket-backend-adapter.ts +372 -0
- package/src/runtime/backend/node-backend-adapter.ts +19 -0
- package/src/runtime/backend/raw-binding-port.ts +69 -0
- package/src/runtime/backend/runtime-message.ts +51 -0
- package/src/runtime/backend/runtime-values.ts +107 -0
- package/src/runtime/channels/channel-autoconnect.ts +46 -0
- package/src/runtime/channels/channel-clients.ts +527 -0
- package/src/runtime/channels/channel-dispatch-pipeline.ts +408 -0
- package/src/runtime/channels/channel-dispatch-services.ts +234 -0
- package/src/runtime/channels/channel-dispatchers.ts +790 -0
- package/src/runtime/channels/channel-envelope-inspection.ts +125 -0
- package/src/runtime/channels/channel-envelope.ts +743 -0
- package/src/runtime/channels/channel-framework-packets.ts +8 -0
- package/src/runtime/channels/channel-multipart.ts +61 -0
- package/src/runtime/channels/channel-outbound-operations.ts +584 -0
- package/src/runtime/channels/channel-receive-loops.ts +901 -0
- package/src/runtime/channels/channel-receive-task-tracker.ts +39 -0
- package/src/runtime/channels/channel-runtime-lifecycle.ts +969 -0
- package/src/runtime/channels/channel-runtime-manager.ts +444 -0
- package/src/runtime/channels/channel-socket-options.ts +153 -0
- package/src/runtime/channels/channel-socket-registry.ts +1837 -0
- package/src/runtime/channels/channel-transports.ts +1154 -0
- package/src/runtime/channels/client-server-location-runtime.ts +576 -0
- package/src/runtime/channels/client-server-service-wire.ts +390 -0
- package/src/runtime/channels/dispatch-error-reporter.ts +165 -0
- package/src/runtime/channels/fanout-location-runtime.ts +459 -0
- package/src/runtime/channels/fanout-service-wire.ts +43 -0
- package/src/runtime/channels/handler-filter-scope.ts +29 -0
- package/src/runtime/channels/index.ts +45 -0
- package/src/runtime/channels/local-spot-route-transport.ts +59 -0
- package/src/runtime/channels/route-disconnected-error.ts +6 -0
- package/src/runtime/channels/route-member-snapshot.ts +55 -0
- package/src/runtime/channels/router-socket-spot-route-transport.ts +77 -0
- package/src/runtime/channels/source-spot-router.ts +89 -0
- package/src/runtime/channels/spot-direct-envelope.ts +44 -0
- package/src/runtime/channels/spot-node-route-transport.ts +92 -0
- package/src/runtime/channels/spot-route-bridge-transport.ts +75 -0
- package/src/runtime/channels/spot-route-dispatch-strategy.ts +329 -0
- package/src/runtime/channels/spot-route-target-resolver.ts +101 -0
- package/src/runtime/codecs/index.ts +69 -0
- package/src/runtime/configuration/index.ts +1 -0
- package/src/runtime/diagnostics/dispatch-error-port.ts +8 -0
- package/src/runtime/diagnostics/flow-context.ts +84 -0
- package/src/runtime/diagnostics/index.ts +441 -0
- package/src/runtime/diagnostics/internal-event-contracts.ts +135 -0
- package/src/runtime/diagnostics/message-flow.ts +560 -0
- package/src/runtime/diagnostics/runtime-metrics.ts +601 -0
- package/src/runtime/diagnostics/runtime-observation-queue.ts +362 -0
- package/src/runtime/diagnostics/topology-runtime-projections.ts +298 -0
- package/src/runtime/execution/index.ts +466 -0
- package/src/runtime/execution/serial-execution-queue.ts +534 -0
- package/src/runtime/execution/serial-work-size.ts +31 -0
- package/src/runtime/execution/state-lane.ts +116 -0
- package/src/runtime/foundation/actor-join-recovery-codec.ts +465 -0
- package/src/runtime/foundation/event-loop-resources.ts +162 -0
- package/src/runtime/foundation/index.ts +18 -0
- package/src/runtime/foundation/message-follow-suppression-registry.ts +130 -0
- package/src/runtime/foundation/operation-identity.ts +49 -0
- package/src/runtime/foundation/operation-registry.ts +162 -0
- package/src/runtime/foundation/raw-service-mesh-runtime.ts +1771 -0
- package/src/runtime/foundation/route-mesh-connection-policy.ts +28 -0
- package/src/runtime/foundation/runtime-state-projections.ts +68 -0
- package/src/runtime/foundation/service-authority-payload-codec.ts +566 -0
- package/src/runtime/foundation/service-discovery-registry.ts +263 -0
- package/src/runtime/foundation/service-instance-activation-recovery-codec.ts +329 -0
- package/src/runtime/foundation/service-liveness-registry.ts +144 -0
- package/src/runtime/foundation/service-mailbox.ts +369 -0
- package/src/runtime/foundation/service-maintenance-runtime.ts +242 -0
- package/src/runtime/foundation/service-metadata-codec.ts +75 -0
- package/src/runtime/foundation/service-relocation-aggregate-committer.ts +218 -0
- package/src/runtime/foundation/service-relocation-coordinator.ts +37 -0
- package/src/runtime/foundation/service-relocation-object-owner.ts +428 -0
- package/src/runtime/foundation/service-relocation-runtime.ts +1407 -0
- package/src/runtime/foundation/service-runtime-contracts.ts +423 -0
- package/src/runtime/foundation/service-session-binding-ingress-port.ts +45 -0
- package/src/runtime/foundation/service-stateful-registry.ts +664 -0
- package/src/runtime/foundation/service-stateful-runtime.ts +5753 -0
- package/src/runtime/foundation/service-stateful-wire-codec.ts +3008 -0
- package/src/runtime/foundation/service-topology-registry.ts +599 -0
- package/src/runtime/foundation/service-weighted-selection.ts +166 -0
- package/src/runtime/foundation/service-wire-binary-primitives.ts +80 -0
- package/src/runtime/foundation/service-wire-codec.ts +91 -0
- package/src/runtime/foundation/service-wire-constants.generated.ts +131 -0
- package/src/runtime/foundation/service-wire-m6a-codec.ts +647 -0
- package/src/runtime/framework-errors-internal.ts +338 -0
- package/src/runtime/handlers/handler-instance-scope.ts +372 -0
- package/src/runtime/handlers/index.ts +93 -0
- package/src/runtime/host/actor-packet-relay.ts +1070 -0
- package/src/runtime/host/actor-placement-coordinator.ts +573 -0
- package/src/runtime/host/actor-runtime-options-factory.ts +282 -0
- package/src/runtime/host/actor-transfer-authority-runtime.ts +225 -0
- package/src/runtime/host/actor-transfer-runtime.ts +1958 -0
- package/src/runtime/host/application-job-queue.ts +518 -0
- package/src/runtime/host/bound-session-relay.ts +94 -0
- package/src/runtime/host/bounded-replay-map.ts +42 -0
- package/src/runtime/host/channel-runtime-options-factory.ts +104 -0
- package/src/runtime/host/entry-actor-runtime.ts +115 -0
- package/src/runtime/host/host-capacity-status.ts +103 -0
- package/src/runtime/host/index.ts +3492 -0
- package/src/runtime/host/instance-activation-authority.ts +658 -0
- package/src/runtime/host/location-runtime-owner.ts +313 -0
- package/src/runtime/host/mesh-router-resolver.ts +114 -0
- package/src/runtime/host/relocation-direct-transfer.ts +273 -0
- package/src/runtime/host/relocation-integrity-fault-gate.ts +8 -0
- package/src/runtime/host/relocation-state-adapter.ts +24 -0
- package/src/runtime/host/remote-actor-join-receiver.ts +264 -0
- package/src/runtime/host/remote-actor-packet-target-store.ts +244 -0
- package/src/runtime/host/remote-bound-session-relay.ts +900 -0
- package/src/runtime/host/route-mesh-runtime-options.ts +46 -0
- package/src/runtime/host/route-mesh-runtime.ts +891 -0
- package/src/runtime/host/runtime-shutdown.ts +101 -0
- package/src/runtime/host/service-relocation-control.ts +28 -0
- package/src/runtime/host/service-relocation-host-runtime.ts +5817 -0
- package/src/runtime/host/spot-address-transport.ts +997 -0
- package/src/runtime/host/spot-node-runtime-options-factory.ts +82 -0
- package/src/runtime/host/spot-runtime-options-factory.ts +286 -0
- package/src/runtime/host/stateful-authority-route-runtime.ts +662 -0
- package/src/runtime/host/user-spot-creation-coordinator.ts +1176 -0
- package/src/runtime/locations/actor-location-claims.ts +426 -0
- package/src/runtime/locations/actor-session-route-claims.ts +64 -0
- package/src/runtime/locations/aggregate-inventory-store.ts +581 -0
- package/src/runtime/locations/authority-key-codec.ts +80 -0
- package/src/runtime/locations/auto-connect-loop.ts +131 -0
- package/src/runtime/locations/auto-connect-planner.ts +178 -0
- package/src/runtime/locations/auto-connect-reconciler.ts +425 -0
- package/src/runtime/locations/auto-connect-types.ts +62 -0
- package/src/runtime/locations/auto-connect.ts +4 -0
- package/src/runtime/locations/canonical-codec.ts +54 -0
- package/src/runtime/locations/domain-store-contract.ts +149 -0
- package/src/runtime/locations/in-memory-authority-store.ts +1172 -0
- package/src/runtime/locations/in-memory-location-store.ts +1467 -0
- package/src/runtime/locations/in-memory-provider-location-store.ts +213 -0
- package/src/runtime/locations/index.ts +11 -0
- package/src/runtime/locations/internal-location-contracts.ts +22 -0
- package/src/runtime/locations/internal-store-contracts.ts +90 -0
- package/src/runtime/locations/key-codec.ts +61 -0
- package/src/runtime/locations/lease-tracker.ts +221 -0
- package/src/runtime/locations/lifecycle-runtime.ts +44 -0
- package/src/runtime/locations/lifecycle.ts +272 -0
- package/src/runtime/locations/location-store-repository.ts +4211 -0
- package/src/runtime/locations/relocation-blob.ts +36 -0
- package/src/runtime/locations/resolvers.ts +1054 -0
- package/src/runtime/locations/runtime.ts +1126 -0
- package/src/runtime/locations/spot-location-claims.ts +435 -0
- package/src/runtime/messaging/creation-payload-codec.ts +59 -0
- package/src/runtime/messaging/framework-json-v1.ts +307 -0
- package/src/runtime/messaging/index.ts +1 -0
- package/src/runtime/messaging/packet-name.ts +94 -0
- package/src/runtime/messaging/payload-codec.ts +418 -0
- package/src/runtime/messaging/submission-result.ts +61 -0
- package/src/runtime/protocol/service_wire_pilot_codec.generated.ts +189 -0
- package/src/runtime/routing-id.ts +125 -0
- package/src/runtime/spots/formal-remote-actor-admission-registry.ts +418 -0
- package/src/runtime/spots/formal-remote-actor-transfer-registry.ts +147 -0
- package/src/runtime/spots/index.ts +3303 -0
- package/src/runtime/spots/spot-activation-registry.ts +335 -0
- package/src/runtime/spots/spot-activation-state.ts +414 -0
- package/src/runtime/spots/spot-activation.ts +1027 -0
- package/src/runtime/spots/spot-actor-admission-coordinator.ts +354 -0
- package/src/runtime/spots/spot-actor-join-dispatch.ts +303 -0
- package/src/runtime/spots/spot-actor-lifecycle-drain.ts +79 -0
- package/src/runtime/spots/spot-actor-membership.ts +266 -0
- package/src/runtime/spots/spot-actor-packet-dispatch.ts +593 -0
- package/src/runtime/spots/spot-actor-packet-drain.ts +328 -0
- package/src/runtime/spots/spot-actor-packet-relay-dispatch.ts +162 -0
- package/src/runtime/spots/spot-closing.ts +34 -0
- package/src/runtime/spots/spot-context.ts +259 -0
- package/src/runtime/spots/spot-entry-activation.ts +551 -0
- package/src/runtime/spots/spot-handle.ts +101 -0
- package/src/runtime/spots/spot-handler-registry.ts +273 -0
- package/src/runtime/spots/spot-lifecycle-metrics.ts +15 -0
- package/src/runtime/spots/spot-location-claim.ts +86 -0
- package/src/runtime/spots/spot-manager-internal-contracts.ts +11 -0
- package/src/runtime/spots/spot-manager-public.ts +361 -0
- package/src/runtime/spots/spot-native-actor-join-admission.ts +151 -0
- package/src/runtime/spots/spot-native-flags.ts +4 -0
- package/src/runtime/spots/spot-node-autoconnect.ts +325 -0
- package/src/runtime/spots/spot-node-runtime-manager.ts +1573 -0
- package/src/runtime/spots/spot-outbound.ts +761 -0
- package/src/runtime/spots/spot-provider.ts +36 -0
- package/src/runtime/spots/spot-publisher-transport.ts +69 -0
- package/src/runtime/spots/spot-remote-codec.ts +308 -0
- package/src/runtime/spots/spot-remote-route-codec.ts +284 -0
- package/src/runtime/spots/spot-route-packet-dispatch.ts +359 -0
- package/src/runtime/spots/spot-route-replies.ts +126 -0
- package/src/runtime/spots/spot-route-reply-wire.ts +15 -0
- package/src/runtime/spots/spot-routed-actor-admission.ts +351 -0
- package/src/runtime/spots/spot-routed-bound-session-dispatch.ts +132 -0
- package/src/runtime/spots/spot-routed-frame-dispatch.ts +250 -0
- package/src/runtime/spots/spot-routed-spot-packet-dispatch.ts +254 -0
- package/src/runtime/spots/spot-routing-internal.ts +33 -0
- package/src/runtime/spots/spot-runtime-ports.ts +196 -0
- package/src/runtime/spots/spot-serial-executor.ts +170 -0
- package/src/runtime/spots/spot-serial-turn-executor.ts +319 -0
- package/src/runtime/spots/spot-subscription-dispatch.ts +252 -0
- package/src/runtime/spots/spot-timer.ts +609 -0
- package/src/runtime/streams/actor-session-binding-registry.ts +1691 -0
- package/src/runtime/streams/actor-session-binding-runtime-owner.ts +78 -0
- package/src/runtime/streams/actor-session-lifecycle-coordinator.ts +20 -0
- package/src/runtime/streams/bound-actor-relay-sender.ts +275 -0
- package/src/runtime/streams/bound-session-response-target.ts +91 -0
- package/src/runtime/streams/bound-session-service.ts +500 -0
- package/src/runtime/streams/index.ts +706 -0
- package/src/runtime/streams/managed-stream.ts +509 -0
- package/src/runtime/streams/native-fallback-bound-session.ts +321 -0
- package/src/runtime/streams/protocol.ts +291 -0
- package/src/runtime/streams/session-actor-coordinator.ts +605 -0
- package/src/runtime/streams/session-calls.ts +221 -0
- package/src/runtime/streams/session-context.ts +609 -0
- package/src/runtime/streams/session-local-actors.ts +30 -0
- package/src/runtime/streams/session-provider.ts +50 -0
- package/src/runtime/streams/session-requests.ts +109 -0
- package/src/runtime/streams/session-serial-executor.ts +97 -0
- package/src/runtime/streams/stream-binding-runtime-ports.ts +106 -0
- package/src/runtime/streams/stream-frame-factory.ts +255 -0
- package/src/runtime/streams/stream-message-utils.ts +89 -0
- package/src/runtime/streams/stream-session-runtime.ts +1420 -0
- package/src/runtime/workers/index.ts +580 -0
- package/tsconfig.json +17 -0
|
@@ -0,0 +1,2669 @@
|
|
|
1
|
+
import { randomBytes } from 'node:crypto';
|
|
2
|
+
import { disconnectStreamPeer } from './node-socket-backend-adapter';
|
|
3
|
+
import { ZLinkFrameworkException } from '../../../contracts';
|
|
4
|
+
import { internalFrameworkWireReply } from '../../framework-errors-internal';
|
|
5
|
+
import {
|
|
6
|
+
Message,
|
|
7
|
+
RoutingId as BindingRoutingId,
|
|
8
|
+
RequestResult,
|
|
9
|
+
SubmitError,
|
|
10
|
+
SubmitResult,
|
|
11
|
+
type RequestResult as RequestResultValue,
|
|
12
|
+
type StreamSocket,
|
|
13
|
+
type SubmitResult as SubmitResultValue
|
|
14
|
+
} from '@zlink-systems/zlink';
|
|
15
|
+
import {
|
|
16
|
+
isZLinkBackendResultError,
|
|
17
|
+
ZLinkBackendResultError,
|
|
18
|
+
type ZLinkBackendMessageLike as MessageLike
|
|
19
|
+
} from '../runtime-values';
|
|
20
|
+
import type {
|
|
21
|
+
MeshOperationId,
|
|
22
|
+
MeshPeerEntry,
|
|
23
|
+
MeshPublisher,
|
|
24
|
+
ReadyBatch,
|
|
25
|
+
ReadyRecord,
|
|
26
|
+
ReceiveBatch,
|
|
27
|
+
ReceiveRecord,
|
|
28
|
+
ServiceSpot,
|
|
29
|
+
StreamSessionActorAuthorityFence,
|
|
30
|
+
StreamSessionService
|
|
31
|
+
} from '../../foundation/service-runtime-contracts';
|
|
32
|
+
import {
|
|
33
|
+
OperationKind,
|
|
34
|
+
ReadyDomain,
|
|
35
|
+
ReadyOwnerKind,
|
|
36
|
+
ReceiveKind
|
|
37
|
+
} from '../../foundation/service-runtime-contracts';
|
|
38
|
+
import {
|
|
39
|
+
OperationCancelledError,
|
|
40
|
+
OperationTimeoutError
|
|
41
|
+
} from '../../foundation/operation-registry';
|
|
42
|
+
import {
|
|
43
|
+
RawServiceMeshRuntime,
|
|
44
|
+
type RawServiceRequestResult
|
|
45
|
+
} from '../../foundation/raw-service-mesh-runtime';
|
|
46
|
+
import {
|
|
47
|
+
decodeApplicationPayloadView,
|
|
48
|
+
encodeMultipartApplicationPayload,
|
|
49
|
+
type ServiceApplicationPayload,
|
|
50
|
+
ServiceWireProtocolError
|
|
51
|
+
} from '../../foundation/service-wire-m6a-codec';
|
|
52
|
+
import {
|
|
53
|
+
SERVICE_FRAMEWORK_MULTIPART_CONTENT_TYPE,
|
|
54
|
+
SERVICE_FRAMEWORK_MULTIPART_PACKET_NAME,
|
|
55
|
+
SERVICE_WIRE_REQUIRED_CAPABILITY
|
|
56
|
+
} from '../../foundation/service-wire-constants.generated';
|
|
57
|
+
import {
|
|
58
|
+
ServiceStatefulRuntime,
|
|
59
|
+
statefulMailboxData,
|
|
60
|
+
type ServiceAsyncInstanceActivationAuthority,
|
|
61
|
+
type ServiceInstanceApplicationLifecycle,
|
|
62
|
+
type ServicePendingInstanceActivation,
|
|
63
|
+
type ServiceSpotMessageFollowSeal,
|
|
64
|
+
type ServiceUserSpotOperationHandler,
|
|
65
|
+
type ServiceUserSpotOperationResult,
|
|
66
|
+
type ServiceStatefulMailboxData,
|
|
67
|
+
type ServiceStatefulPendingOperation,
|
|
68
|
+
type ServiceStatefulResult
|
|
69
|
+
} from '../../foundation/service-stateful-runtime';
|
|
70
|
+
import type {
|
|
71
|
+
ServiceActorRef,
|
|
72
|
+
ServiceSpotState
|
|
73
|
+
} from '../../foundation/service-stateful-registry';
|
|
74
|
+
import { serviceSessionBindingIngressPortIfRegistered } from
|
|
75
|
+
'../../foundation/service-session-binding-ingress-port';
|
|
76
|
+
import type {
|
|
77
|
+
ServiceActorCreateRecord,
|
|
78
|
+
ServiceDirectSpotRouteFence,
|
|
79
|
+
ServiceInstanceActivationTarget,
|
|
80
|
+
ServiceInstanceRouteFence,
|
|
81
|
+
ServiceRetiredBoundSessionRouteFence,
|
|
82
|
+
ServiceSpotRouteFence,
|
|
83
|
+
ServiceUserSpotCloseRecord,
|
|
84
|
+
ServiceUserSpotCreateRecord
|
|
85
|
+
} from '../../foundation/service-stateful-wire-codec';
|
|
86
|
+
import { encodeServiceMetadataFrame } from '../../foundation/service-metadata-codec';
|
|
87
|
+
import type {
|
|
88
|
+
ServiceInstanceActivationRecoveryEnvelope
|
|
89
|
+
} from '../../foundation/service-instance-activation-recovery-codec';
|
|
90
|
+
import type {
|
|
91
|
+
ServiceMailboxClaim,
|
|
92
|
+
ServiceMailboxDomain,
|
|
93
|
+
ServiceMailboxRecord
|
|
94
|
+
} from '../../foundation/service-mailbox';
|
|
95
|
+
import type {
|
|
96
|
+
ServiceChannelDescriptor,
|
|
97
|
+
ServiceNodeDescriptor
|
|
98
|
+
} from '../../foundation/service-topology-registry';
|
|
99
|
+
import type { RoutingId } from '../../../contracts';
|
|
100
|
+
import { buildAdvertisedEndpoint } from '../../../contracts/Configuration/EndpointNotation';
|
|
101
|
+
import { ZLinkConfigurationException } from
|
|
102
|
+
'../../../contracts/Configuration/ConfigurationException';
|
|
103
|
+
import type {
|
|
104
|
+
ZLinkBackendActorRef,
|
|
105
|
+
ZLinkBackendActorSessionSendFence,
|
|
106
|
+
ZLinkBackendObjectPlacement,
|
|
107
|
+
ZLinkBackendMeshNode
|
|
108
|
+
} from '../contracts';
|
|
109
|
+
import type { ZLinkRawBindingPort } from '../raw-binding-port';
|
|
110
|
+
import type { ApplicationJobQueuePort } from '../../application-jobs/contracts';
|
|
111
|
+
|
|
112
|
+
const MULTIPART_PACKET_NAME = SERVICE_FRAMEWORK_MULTIPART_PACKET_NAME;
|
|
113
|
+
const MULTIPART_CONTENT_TYPE = SERVICE_FRAMEWORK_MULTIPART_CONTENT_TYPE;
|
|
114
|
+
const FATAL_UTF8 = new TextDecoder('utf-8', { fatal: true });
|
|
115
|
+
const MAX_DRAIN_RECORDS = 64;
|
|
116
|
+
// A timer is only a no-data backoff. Once the binding has reported readable
|
|
117
|
+
// work, continue from the next event-loop turn so a full socket does not wait
|
|
118
|
+
// for an arbitrary timer cadence between batches.
|
|
119
|
+
const MESH_BACKEND_IDLE_POLL_INTERVAL_MS = 1;
|
|
120
|
+
const MESH_RECEIVE_BATCH_BYTE_LIMIT = 4 * 1024 * 1024;
|
|
121
|
+
const MESH_RECEIVE_BATCH_TIME_LIMIT_MS = 2;
|
|
122
|
+
/**
|
|
123
|
+
* Conservative Actor Join admission cap for relocation state chunks (spec 15
|
|
124
|
+
* §4.2): a stable lower bound safe on any deployment, never lowered on
|
|
125
|
+
* recompute. Matches the source's own conservative chunk floor.
|
|
126
|
+
*/
|
|
127
|
+
const ACTOR_JOIN_ADVERTISED_RECEIVE_CHUNK_LIMIT_BYTES = 32 * 1024;
|
|
128
|
+
|
|
129
|
+
class ZLinkMeshReceiveBatchBudget {
|
|
130
|
+
private readonly peerMessages = new Map<string, number>();
|
|
131
|
+
private readonly peerBytes = new Map<string, number>();
|
|
132
|
+
private startedAtMs = 0;
|
|
133
|
+
|
|
134
|
+
reset(nowMs: number): void {
|
|
135
|
+
this.peerMessages.clear();
|
|
136
|
+
this.peerBytes.clear();
|
|
137
|
+
this.startedAtMs = nowMs;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
record(peer: string, byteCount: number, nowMs: number): boolean {
|
|
141
|
+
const messages = (this.peerMessages.get(peer) ?? 0) + 1;
|
|
142
|
+
const bytes = (this.peerBytes.get(peer) ?? 0) + byteCount;
|
|
143
|
+
this.peerMessages.set(peer, messages);
|
|
144
|
+
this.peerBytes.set(peer, bytes);
|
|
145
|
+
return messages >= MAX_DRAIN_RECORDS
|
|
146
|
+
|| bytes >= MESH_RECEIVE_BATCH_BYTE_LIMIT
|
|
147
|
+
|| nowMs - this.startedAtMs >= MESH_RECEIVE_BATCH_TIME_LIMIT_MS;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* M6A MeshNode backend. Stateful Spot/Actor entry points stay explicit until
|
|
153
|
+
* their owning M6B runtime is connected; topology and node/channel dispatch do
|
|
154
|
+
* not depend on those entry points.
|
|
155
|
+
*/
|
|
156
|
+
export class ZLinkNodeRawMeshBackend implements ZLinkBackendMeshNode {
|
|
157
|
+
readonly nativeInstance = this;
|
|
158
|
+
|
|
159
|
+
private readonly channels = new Map<string, number>();
|
|
160
|
+
private readonly peerIntents = new Map<bigint, {
|
|
161
|
+
readonly endpoint: string;
|
|
162
|
+
readonly nodeRoutingId?: string;
|
|
163
|
+
readonly lifecycleGeneration?: bigint;
|
|
164
|
+
}>();
|
|
165
|
+
private readonly completions: Array<PendingCompletion | undefined> = [];
|
|
166
|
+
private completionHead = 0;
|
|
167
|
+
private completionCount = 0;
|
|
168
|
+
private readonly routingId: string;
|
|
169
|
+
private readonly lifecycleGeneration: bigint;
|
|
170
|
+
private bindEndpoint?: string;
|
|
171
|
+
private advertiseHost?: string;
|
|
172
|
+
private runtime?: RawServiceMeshRuntime;
|
|
173
|
+
private stateful?: ServiceStatefulRuntime;
|
|
174
|
+
private readyHandler?: (domains: number) => number;
|
|
175
|
+
private pollTimer?: NodeJS.Timeout;
|
|
176
|
+
private nextPeerIntent = 1n;
|
|
177
|
+
private closed = false;
|
|
178
|
+
private objectRole: ServiceNodeDescriptor['objectRole'] = 'none';
|
|
179
|
+
private placementWeight = 100;
|
|
180
|
+
private activeCapacityLimit = 10_000;
|
|
181
|
+
private pendingCapacityLimit = 128;
|
|
182
|
+
private objectCapabilities: readonly string[] = [];
|
|
183
|
+
private maintenanceWave?: string;
|
|
184
|
+
private mailboxRecordDropped?: (record: {
|
|
185
|
+
readonly kind: 'spot_multicast' | 'actor_control' | 'actor_binding';
|
|
186
|
+
readonly owner: string;
|
|
187
|
+
}) => void;
|
|
188
|
+
private protocolError?: (record: {
|
|
189
|
+
readonly sourceNodeRid: string;
|
|
190
|
+
readonly request: boolean;
|
|
191
|
+
readonly replied: boolean;
|
|
192
|
+
readonly command?: number;
|
|
193
|
+
}) => void;
|
|
194
|
+
private messageFollowHandler?: (
|
|
195
|
+
record: import('../../foundation/service-stateful-wire-codec').ServiceMessageFollowRecord
|
|
196
|
+
) => void;
|
|
197
|
+
private readonly peerDisconnectedHandlers = new Set<(endpoint: string) => void>();
|
|
198
|
+
private readonly receiveBatchBudget = new ZLinkMeshReceiveBatchBudget();
|
|
199
|
+
private observedPumpSourceRoutingId?: string;
|
|
200
|
+
private observedPumpByteCount = 0;
|
|
201
|
+
private readonly observePump = (sourceRoutingId: string, byteCount: number): void => {
|
|
202
|
+
this.observedPumpSourceRoutingId = sourceRoutingId;
|
|
203
|
+
this.observedPumpByteCount = byteCount;
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
private takePumpObservation(): { readonly sourceRoutingId: string; readonly byteCount: number } | undefined {
|
|
207
|
+
const sourceRoutingId = this.observedPumpSourceRoutingId;
|
|
208
|
+
if (sourceRoutingId === undefined) return undefined;
|
|
209
|
+
return { sourceRoutingId, byteCount: this.observedPumpByteCount };
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
constructor(
|
|
213
|
+
private readonly meshName: string,
|
|
214
|
+
routingId: string | undefined,
|
|
215
|
+
private readonly bindingPort: ZLinkRawBindingPort,
|
|
216
|
+
private readonly applicationJobQueue?: ApplicationJobQueuePort,
|
|
217
|
+
private readonly applicationJobReceiveFlowFailureSink?: (error: unknown) => void,
|
|
218
|
+
private readonly peerAdmissionSealed?: () => boolean
|
|
219
|
+
) {
|
|
220
|
+
if (meshName.length === 0) throw new TypeError('MeshName must be non-empty.');
|
|
221
|
+
if (routingId === undefined || routingId.length === 0) {
|
|
222
|
+
throw new TypeError('M6A raw MeshNode requires a routing id.');
|
|
223
|
+
}
|
|
224
|
+
this.routingId = routingId;
|
|
225
|
+
this.lifecycleGeneration = createLifecycleGeneration();
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
configureObjectPlacement(options: {
|
|
229
|
+
readonly role: ServiceNodeDescriptor['objectRole'];
|
|
230
|
+
readonly placementWeight: number;
|
|
231
|
+
readonly activeCapacityLimit: number;
|
|
232
|
+
readonly pendingCapacityLimit: number;
|
|
233
|
+
readonly objectCapabilities: readonly string[];
|
|
234
|
+
readonly maintenanceWave?: string;
|
|
235
|
+
}): void {
|
|
236
|
+
this.requireNotStarted();
|
|
237
|
+
this.objectRole = options.role;
|
|
238
|
+
this.placementWeight = requirePublicWeight(
|
|
239
|
+
options.placementWeight,
|
|
240
|
+
'placementWeight'
|
|
241
|
+
);
|
|
242
|
+
this.activeCapacityLimit = requirePositivePlacementValue(
|
|
243
|
+
options.activeCapacityLimit,
|
|
244
|
+
'activeCapacityLimit'
|
|
245
|
+
);
|
|
246
|
+
this.pendingCapacityLimit = requirePositivePlacementValue(
|
|
247
|
+
options.pendingCapacityLimit,
|
|
248
|
+
'pendingCapacityLimit'
|
|
249
|
+
);
|
|
250
|
+
this.objectCapabilities = [...new Set(options.objectCapabilities)].sort();
|
|
251
|
+
this.maintenanceWave = options.maintenanceWave;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
setMailboxRecordDroppedHandler(handler: (record: {
|
|
255
|
+
readonly kind: 'spot_multicast' | 'actor_control' | 'actor_binding';
|
|
256
|
+
readonly owner: string;
|
|
257
|
+
}) => void): void {
|
|
258
|
+
this.mailboxRecordDropped = handler;
|
|
259
|
+
this.stateful?.setMailboxDropHandler(handler);
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
setProtocolErrorHandler(handler: (record: {
|
|
263
|
+
readonly sourceNodeRid: string;
|
|
264
|
+
readonly request: boolean;
|
|
265
|
+
readonly replied: boolean;
|
|
266
|
+
readonly command?: number;
|
|
267
|
+
}) => void): void {
|
|
268
|
+
this.protocolError = handler;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
onPeerDisconnected(handler: (endpoint: string) => void): void {
|
|
272
|
+
this.peerDisconnectedHandlers.add(handler);
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
selectObjectPlacement(stableType: string): ZLinkBackendObjectPlacement {
|
|
276
|
+
const runtime = this.requireRuntime();
|
|
277
|
+
const localNodeRid = runtime.topology.localDescriptor().nodeRoutingId;
|
|
278
|
+
const status = runtime.topology.objectPlacementStatus(
|
|
279
|
+
stableType,
|
|
280
|
+
candidate => candidate.nodeRoutingId === localNodeRid
|
|
281
|
+
|| runtime.isPeerRouteReady(candidate.nodeRoutingId)
|
|
282
|
+
);
|
|
283
|
+
if (status !== 'available') return { kind: status };
|
|
284
|
+
const descriptor = runtime.topology.selectObjectPlacement(
|
|
285
|
+
stableType,
|
|
286
|
+
candidate => candidate.nodeRoutingId === localNodeRid
|
|
287
|
+
|| runtime.isPeerRouteReady(candidate.nodeRoutingId)
|
|
288
|
+
);
|
|
289
|
+
return descriptor === undefined
|
|
290
|
+
? { kind: 'unavailable' }
|
|
291
|
+
: {
|
|
292
|
+
kind: 'selected',
|
|
293
|
+
target: {
|
|
294
|
+
targetNodeRid: descriptor.nodeRoutingId,
|
|
295
|
+
targetNodeGeneration: descriptor.lifecycleGeneration,
|
|
296
|
+
descriptorVersion: descriptor.descriptorRevision.toString()
|
|
297
|
+
}
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
instanceSpotPlacementTypes(): readonly string[] {
|
|
302
|
+
return this.requireRuntime().topology.instanceSpotPlacementTypes();
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
async sendToMissingInstanceSpot(
|
|
306
|
+
target: ServiceInstanceActivationTarget,
|
|
307
|
+
parts: MessageLike | readonly MessageLike[],
|
|
308
|
+
deadlineUnixMs: bigint,
|
|
309
|
+
sourceSpotId?: string,
|
|
310
|
+
metadata?: ReadonlyMap<string, string>
|
|
311
|
+
): Promise<SubmitResult> {
|
|
312
|
+
const result = await this.requireStateful().sendToMissingInstanceSpotFrame(
|
|
313
|
+
target,
|
|
314
|
+
encodeMultipartApplicationFrame(parts),
|
|
315
|
+
deadlineUnixMs,
|
|
316
|
+
sourceSpotId,
|
|
317
|
+
metadata === undefined ? undefined : encodeServiceMetadataFrame(metadata)
|
|
318
|
+
);
|
|
319
|
+
return result as SubmitResult;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
requestToMissingInstanceSpot(
|
|
323
|
+
target: ServiceInstanceActivationTarget,
|
|
324
|
+
parts: MessageLike | readonly MessageLike[],
|
|
325
|
+
deadlineUnixMs: bigint,
|
|
326
|
+
sourceSpotId?: string,
|
|
327
|
+
metadata?: ReadonlyMap<string, string>
|
|
328
|
+
): MeshOperationId {
|
|
329
|
+
return this.observeStateful(
|
|
330
|
+
OperationKind.InstanceSpotRequest,
|
|
331
|
+
this.requireStateful().requestToMissingInstanceSpotFrame(
|
|
332
|
+
target,
|
|
333
|
+
encodeMultipartApplicationFrame(parts),
|
|
334
|
+
deadlineUnixMs,
|
|
335
|
+
sourceSpotId,
|
|
336
|
+
metadata === undefined ? undefined : encodeServiceMetadataFrame(metadata)
|
|
337
|
+
)
|
|
338
|
+
);
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
setRoutingId(routingId: unknown): void {
|
|
342
|
+
if (String(routingId) !== this.routingId) {
|
|
343
|
+
throw new Error('MeshNode routing id is immutable after construction.');
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
setBind(endpoint: string): void {
|
|
348
|
+
this.requireNotStarted();
|
|
349
|
+
if (endpoint.length === 0) throw new TypeError('MeshNode bind endpoint must be non-empty.');
|
|
350
|
+
this.bindEndpoint = endpoint;
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
setAdvertiseHost(host: string): void {
|
|
354
|
+
this.requireNotStarted();
|
|
355
|
+
if (host.length === 0) throw new TypeError('MeshNode advertise host must be non-empty.');
|
|
356
|
+
this.advertiseHost = host;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
start(): void {
|
|
360
|
+
if (this.runtime !== undefined) return;
|
|
361
|
+
if (this.closed) throw new Error('MeshNode is closed.');
|
|
362
|
+
if (this.bindEndpoint === undefined) throw new Error('MeshNode bind endpoint is not configured.');
|
|
363
|
+
const descriptor = this.createDescriptor();
|
|
364
|
+
const runtime = new RawServiceMeshRuntime({
|
|
365
|
+
descriptor,
|
|
366
|
+
resolveAdvertisedEndpoint: boundEndpoint =>
|
|
367
|
+
this.resolveAdvertisedEndpoint(boundEndpoint),
|
|
368
|
+
bindingPort: this.bindingPort,
|
|
369
|
+
applicationJobQueue: this.requireApplicationJobQueue(),
|
|
370
|
+
peerAdmissionSealed: this.peerAdmissionSealed,
|
|
371
|
+
onReceiveFlowConfigFailure: this.applicationJobReceiveFlowFailureSink,
|
|
372
|
+
onMailboxReady: (domain) => this.readyHandler?.(
|
|
373
|
+
domain === 'application' ? ReadyDomain.Application : ReadyDomain.Infrastructure
|
|
374
|
+
),
|
|
375
|
+
onProtocolError: (record) => this.protocolError?.({
|
|
376
|
+
sourceNodeRid: record.sourceRoutingId,
|
|
377
|
+
request: record.request,
|
|
378
|
+
replied: record.replied,
|
|
379
|
+
...(record.command === undefined ? {} : { command: record.command })
|
|
380
|
+
}),
|
|
381
|
+
onPeerNotRequired: (nodeRoutingId, endpoint) => {
|
|
382
|
+
for (const [intent, peer] of this.peerIntents) {
|
|
383
|
+
if (
|
|
384
|
+
(
|
|
385
|
+
peer.nodeRoutingId === undefined
|
|
386
|
+
|| peer.nodeRoutingId === nodeRoutingId
|
|
387
|
+
)
|
|
388
|
+
&& peer.endpoint === endpoint
|
|
389
|
+
) {
|
|
390
|
+
this.peerIntents.delete(intent);
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
},
|
|
394
|
+
onPeerDisconnected: (nodeRoutingId, endpoint) => {
|
|
395
|
+
for (const [intentId, peer] of this.peerIntents) {
|
|
396
|
+
if (
|
|
397
|
+
peer.endpoint === endpoint
|
|
398
|
+
&& (peer.nodeRoutingId === undefined || peer.nodeRoutingId === nodeRoutingId)
|
|
399
|
+
) {
|
|
400
|
+
this.peerIntents.delete(intentId);
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
for (const handler of this.peerDisconnectedHandlers) handler(endpoint);
|
|
404
|
+
}
|
|
405
|
+
});
|
|
406
|
+
runtime.start();
|
|
407
|
+
this.stateful = new ServiceStatefulRuntime(
|
|
408
|
+
runtime,
|
|
409
|
+
descriptor.nodeRoutingId,
|
|
410
|
+
descriptor.lifecycleGeneration
|
|
411
|
+
);
|
|
412
|
+
if (this.mailboxRecordDropped !== undefined) {
|
|
413
|
+
this.stateful.setMailboxDropHandler(this.mailboxRecordDropped);
|
|
414
|
+
}
|
|
415
|
+
this.stateful.setMessageFollowHandler((record) => this.messageFollowHandler?.(record));
|
|
416
|
+
this.runtime = runtime;
|
|
417
|
+
this.schedulePoll();
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
setMessageFollowHandler(handler: (
|
|
421
|
+
record: import('../../foundation/service-stateful-wire-codec').ServiceMessageFollowRecord
|
|
422
|
+
) => void): void {
|
|
423
|
+
this.messageFollowHandler = handler;
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
async sendMessageFollowNotification(
|
|
427
|
+
targetNodeRid: string,
|
|
428
|
+
record: Omit<
|
|
429
|
+
import('../../foundation/service-stateful-wire-codec').ServiceMessageFollowRecord,
|
|
430
|
+
'kind'
|
|
431
|
+
>
|
|
432
|
+
): Promise<boolean> {
|
|
433
|
+
return await this.requireStateful().sendMessageFollowNotification(targetNodeRid, record);
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
shutdown(_timeoutMs: number): RequestResultValue {
|
|
437
|
+
this.close();
|
|
438
|
+
return RequestResult.Ok;
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
async publishDraining(): Promise<void> {
|
|
442
|
+
for (const name of this.channels.keys()) this.channels.set(name, 0);
|
|
443
|
+
await this.requireRuntime().updateLocalDescriptor({ state: 'draining' });
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
close(): void {
|
|
447
|
+
if (this.closed) return;
|
|
448
|
+
this.closed = true;
|
|
449
|
+
if (this.pollTimer !== undefined) clearTimeout(this.pollTimer);
|
|
450
|
+
this.pollTimer = undefined;
|
|
451
|
+
this.stateful?.close();
|
|
452
|
+
this.stateful = undefined;
|
|
453
|
+
this.runtime?.close();
|
|
454
|
+
this.runtime = undefined;
|
|
455
|
+
this.clearCompletions();
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
addChannelName(name: string): void {
|
|
459
|
+
this.requireNotStarted();
|
|
460
|
+
if (name.length === 0) throw new TypeError('ChannelName must be non-empty.');
|
|
461
|
+
this.channels.set(name, this.channels.get(name) ?? 100);
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
async setChannelWeight(name: string, weight: number): Promise<void> {
|
|
465
|
+
if (!this.channels.has(name)) throw new Error(`Channel '${name}' is not registered.`);
|
|
466
|
+
const validated = requirePublicWeight(weight, 'Channel weight');
|
|
467
|
+
if (this.channels.get(name) === validated) return;
|
|
468
|
+
this.channels.set(name, validated);
|
|
469
|
+
if (this.runtime !== undefined) {
|
|
470
|
+
await this.runtime.updateLocalDescriptor({
|
|
471
|
+
channelName: name,
|
|
472
|
+
channelWeight: validated
|
|
473
|
+
});
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
async setPlacementWeight(weight: number): Promise<void> {
|
|
478
|
+
const validated = requirePublicWeight(weight, 'Placement weight');
|
|
479
|
+
if (this.placementWeight === validated) return;
|
|
480
|
+
this.placementWeight = validated;
|
|
481
|
+
if (this.runtime !== undefined) {
|
|
482
|
+
await this.runtime.updateLocalDescriptor({ placementWeight: validated });
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
async connectPeer(options: {
|
|
487
|
+
readonly endpoint: string;
|
|
488
|
+
readonly expectedRid?: unknown;
|
|
489
|
+
readonly expectedSecurityIdentity?: string;
|
|
490
|
+
readonly expectedLifecycleGeneration?: bigint;
|
|
491
|
+
}): Promise<bigint> {
|
|
492
|
+
const runtime = this.requireRuntime();
|
|
493
|
+
const nodeRoutingId = options.expectedRid === undefined
|
|
494
|
+
? undefined
|
|
495
|
+
: String(options.expectedRid);
|
|
496
|
+
if (nodeRoutingId === undefined) {
|
|
497
|
+
runtime.connectPeerEndpoint(options.endpoint);
|
|
498
|
+
} else {
|
|
499
|
+
runtime.connectPeerByRoutingId(
|
|
500
|
+
options.endpoint,
|
|
501
|
+
nodeRoutingId,
|
|
502
|
+
options.expectedSecurityIdentity
|
|
503
|
+
?? runtime.topology.localDescriptor().securityIdentity,
|
|
504
|
+
options.expectedLifecycleGeneration
|
|
505
|
+
);
|
|
506
|
+
}
|
|
507
|
+
const intent = this.nextPeerIntent++;
|
|
508
|
+
this.peerIntents.set(intent, {
|
|
509
|
+
endpoint: options.endpoint,
|
|
510
|
+
...(nodeRoutingId === undefined ? {} : {
|
|
511
|
+
nodeRoutingId,
|
|
512
|
+
lifecycleGeneration: options.expectedLifecycleGeneration
|
|
513
|
+
})
|
|
514
|
+
});
|
|
515
|
+
if (nodeRoutingId !== undefined) await runtime.announcePeer(nodeRoutingId);
|
|
516
|
+
return intent;
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
expectPeer(peer: {
|
|
520
|
+
readonly nodeRoutingId: string;
|
|
521
|
+
readonly endpoint: string;
|
|
522
|
+
readonly securityIdentity?: string;
|
|
523
|
+
readonly lifecycleGeneration: bigint;
|
|
524
|
+
}): void {
|
|
525
|
+
this.requireRuntime().expectPeerByRoutingId(
|
|
526
|
+
peer.endpoint,
|
|
527
|
+
peer.nodeRoutingId,
|
|
528
|
+
peer.securityIdentity,
|
|
529
|
+
peer.lifecycleGeneration
|
|
530
|
+
);
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
removePeerConnection(intentId: bigint): void {
|
|
534
|
+
const intent = this.peerIntents.get(intentId);
|
|
535
|
+
if (intent === undefined) return;
|
|
536
|
+
this.peerIntents.delete(intentId);
|
|
537
|
+
if (intent.nodeRoutingId === undefined) {
|
|
538
|
+
this.runtime?.disconnectPeerEndpoint(intent.endpoint);
|
|
539
|
+
} else {
|
|
540
|
+
this.runtime?.disconnectPeer(
|
|
541
|
+
intent.endpoint,
|
|
542
|
+
intent.nodeRoutingId,
|
|
543
|
+
intent.lifecycleGeneration
|
|
544
|
+
);
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
disconnectPeer(peerRid: unknown, lifecycleGeneration: bigint): void {
|
|
549
|
+
const nodeRoutingId = String(peerRid);
|
|
550
|
+
const admitted = this.runtime?.topology.peer(nodeRoutingId);
|
|
551
|
+
if (
|
|
552
|
+
admitted !== undefined
|
|
553
|
+
&& admitted.descriptor.lifecycleGeneration !== lifecycleGeneration
|
|
554
|
+
) {
|
|
555
|
+
return;
|
|
556
|
+
}
|
|
557
|
+
const admittedEndpoint = admitted?.descriptor.advertisedEndpoint;
|
|
558
|
+
const found = [...this.peerIntents.entries()]
|
|
559
|
+
.find(([, intent]) =>
|
|
560
|
+
(
|
|
561
|
+
intent.nodeRoutingId === nodeRoutingId
|
|
562
|
+
&& (
|
|
563
|
+
intent.lifecycleGeneration === undefined
|
|
564
|
+
|| intent.lifecycleGeneration === lifecycleGeneration
|
|
565
|
+
)
|
|
566
|
+
)
|
|
567
|
+
|| (
|
|
568
|
+
intent.nodeRoutingId === undefined
|
|
569
|
+
&& admittedEndpoint !== undefined
|
|
570
|
+
&& intent.endpoint === admittedEndpoint
|
|
571
|
+
));
|
|
572
|
+
if (found === undefined) {
|
|
573
|
+
if (admitted !== undefined) {
|
|
574
|
+
this.runtime?.disconnectPeer(
|
|
575
|
+
admitted.descriptor.advertisedEndpoint,
|
|
576
|
+
nodeRoutingId,
|
|
577
|
+
lifecycleGeneration
|
|
578
|
+
);
|
|
579
|
+
}
|
|
580
|
+
return;
|
|
581
|
+
}
|
|
582
|
+
this.removePeerConnection(found[0]);
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
replaceDiscoveredNotRequiredPeers(peers: readonly {
|
|
586
|
+
readonly nodeRoutingId: string;
|
|
587
|
+
readonly lifecycleGeneration: bigint;
|
|
588
|
+
readonly descriptorRevision: bigint;
|
|
589
|
+
readonly endpoint: string;
|
|
590
|
+
}[]): void {
|
|
591
|
+
const local = this.requireRuntime().topology.localDescriptor();
|
|
592
|
+
this.requireRuntime().replaceDiscoveredNotRequired(peers.map(peer => ({
|
|
593
|
+
...local,
|
|
594
|
+
nodeRoutingId: peer.nodeRoutingId,
|
|
595
|
+
lifecycleGeneration: peer.lifecycleGeneration,
|
|
596
|
+
descriptorRevision: peer.descriptorRevision,
|
|
597
|
+
advertisedEndpoint: peer.endpoint,
|
|
598
|
+
channels: [],
|
|
599
|
+
objectRole: 'client'
|
|
600
|
+
})));
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
isObjectClientNodeDirectTarget(targetRid: unknown): boolean {
|
|
604
|
+
return this.requireRuntime().isObjectClientNodeDirectTarget(String(targetRid));
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
isPeerRouteReady(targetRid: unknown, lifecycleGeneration?: bigint): boolean {
|
|
608
|
+
return this.requireRuntime().isPeerRouteReady(String(targetRid), lifecycleGeneration);
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
async sendToNode(
|
|
612
|
+
targetRid: unknown,
|
|
613
|
+
parts: MessageLike | readonly MessageLike[]
|
|
614
|
+
): Promise<SubmitResultValue> {
|
|
615
|
+
return await this.requireRuntime().sendToNode(
|
|
616
|
+
String(targetRid),
|
|
617
|
+
encodeMultipart(parts)
|
|
618
|
+
) ? SubmitResult.Ok : SubmitResult.NotConnected;
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
async sendInfrastructureControl(
|
|
622
|
+
targetRid: unknown,
|
|
623
|
+
record: Uint8Array | readonly Uint8Array[]
|
|
624
|
+
): Promise<SubmitResultValue> {
|
|
625
|
+
return await this.requireRuntime().sendService(
|
|
626
|
+
String(targetRid),
|
|
627
|
+
(Array.isArray(record) ? record : [record]).map(value => Buffer.from(value))
|
|
628
|
+
) ? SubmitResult.Ok : SubmitResult.NotConnected;
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
async sendInfrastructureControlFrames(
|
|
632
|
+
targetRid: unknown,
|
|
633
|
+
frames: readonly Uint8Array[]
|
|
634
|
+
): Promise<SubmitResultValue> {
|
|
635
|
+
return await this.requireRuntime().sendService(
|
|
636
|
+
String(targetRid),
|
|
637
|
+
frames.map(frame => Buffer.from(frame))
|
|
638
|
+
) ? SubmitResult.Ok : SubmitResult.NotConnected;
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
async requestInfrastructureControlFrames(
|
|
642
|
+
targetRid: unknown,
|
|
643
|
+
frames: readonly Uint8Array[],
|
|
644
|
+
options?: { readonly timeoutMs?: number }
|
|
645
|
+
): Promise<readonly Uint8Array[]> {
|
|
646
|
+
return await this.requireRuntime().requestService(
|
|
647
|
+
String(targetRid),
|
|
648
|
+
frames.map(frame => Buffer.from(frame)),
|
|
649
|
+
options?.timeoutMs ?? 30_000
|
|
650
|
+
);
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
requestToNode(
|
|
654
|
+
targetRid: unknown,
|
|
655
|
+
parts: MessageLike | readonly MessageLike[],
|
|
656
|
+
options?: { readonly timeoutMs?: number }
|
|
657
|
+
): MeshOperationId {
|
|
658
|
+
const pending = this.requireRuntime().requestToNode(
|
|
659
|
+
String(targetRid),
|
|
660
|
+
encodeMultipart(parts),
|
|
661
|
+
options?.timeoutMs ?? 30_000
|
|
662
|
+
);
|
|
663
|
+
return this.observeCompletion(pending.id, OperationKind.NodeRequest, pending.promise);
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
async sendToChannel(
|
|
667
|
+
channelName: string,
|
|
668
|
+
parts: MessageLike | readonly MessageLike[]
|
|
669
|
+
): Promise<SubmitResultValue> {
|
|
670
|
+
return await this.requireRuntime().sendToChannel(
|
|
671
|
+
channelName,
|
|
672
|
+
encodeMultipart(parts)
|
|
673
|
+
) ? SubmitResult.Ok : SubmitResult.NotConnected;
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
requestToChannel(
|
|
677
|
+
channelName: string,
|
|
678
|
+
parts: MessageLike | readonly MessageLike[],
|
|
679
|
+
options?: { readonly timeoutMs?: number }
|
|
680
|
+
): MeshOperationId {
|
|
681
|
+
const pending = this.requireRuntime().requestToChannel(
|
|
682
|
+
channelName,
|
|
683
|
+
encodeMultipart(parts),
|
|
684
|
+
options?.timeoutMs ?? 30_000
|
|
685
|
+
);
|
|
686
|
+
if (pending === undefined) {
|
|
687
|
+
return this.enqueueImmediateFailure(OperationKind.ChannelRequest, RequestResult.NotFound);
|
|
688
|
+
}
|
|
689
|
+
return this.observeCompletion(pending.id, OperationKind.ChannelRequest, pending.promise);
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
status() {
|
|
693
|
+
const descriptor = this.runtime?.topology.localDescriptor() ?? this.createDescriptor();
|
|
694
|
+
const peers = this.runtime?.topology.peers() ?? [];
|
|
695
|
+
return {
|
|
696
|
+
state: stateCode(descriptor.state),
|
|
697
|
+
routingId: descriptor.nodeRoutingId as RoutingId,
|
|
698
|
+
meshName: descriptor.meshName,
|
|
699
|
+
localEndpoint: descriptor.advertisedEndpoint,
|
|
700
|
+
lifecycleGeneration: descriptor.lifecycleGeneration,
|
|
701
|
+
descriptorRevision: descriptor.descriptorRevision,
|
|
702
|
+
channelCount: descriptor.channels.length,
|
|
703
|
+
configuredPeerCount: this.peerIntents.size,
|
|
704
|
+
admittedPeerCount: peers.length,
|
|
705
|
+
drainingPeerCount: peers.filter(peer => peer.descriptor.state === 'draining').length,
|
|
706
|
+
pendingApplicationMessages: BigInt(this.runtime?.mailbox.pendingMessages('application') ?? 0),
|
|
707
|
+
pendingInfrastructureMessages: BigInt(
|
|
708
|
+
(this.runtime?.mailbox.pendingMessages('infrastructure') ?? 0) + this.completionCount
|
|
709
|
+
),
|
|
710
|
+
pendingBytes: BigInt(
|
|
711
|
+
(this.runtime?.mailbox.pendingBytes('application') ?? 0)
|
|
712
|
+
+ (this.runtime?.mailbox.pendingBytes('infrastructure') ?? 0)
|
|
713
|
+
),
|
|
714
|
+
lastError: 0,
|
|
715
|
+
lastChangedMs: BigInt(Math.trunc(performance.now()))
|
|
716
|
+
};
|
|
717
|
+
}
|
|
718
|
+
|
|
719
|
+
peers(): MeshPeerEntry[] {
|
|
720
|
+
const intents = [...this.peerIntents.entries()].map(([id, intent]) => ({
|
|
721
|
+
id,
|
|
722
|
+
...intent
|
|
723
|
+
}));
|
|
724
|
+
const findIntent = (nodeRoutingId: string, endpoint: string) =>
|
|
725
|
+
intents.find(intent =>
|
|
726
|
+
intent.nodeRoutingId === nodeRoutingId
|
|
727
|
+
|| (
|
|
728
|
+
intent.nodeRoutingId === undefined
|
|
729
|
+
&& intent.endpoint === endpoint
|
|
730
|
+
));
|
|
731
|
+
const admitted = (this.runtime?.topology.peers() ?? []).map(peer => ({
|
|
732
|
+
connectionIntentId: findIntent(
|
|
733
|
+
peer.descriptor.nodeRoutingId,
|
|
734
|
+
peer.descriptor.advertisedEndpoint
|
|
735
|
+
)?.id ?? 0n,
|
|
736
|
+
source: 1,
|
|
737
|
+
state: this.runtime?.isPeerRouteReady(peer.descriptor.nodeRoutingId) === false
|
|
738
|
+
? 1
|
|
739
|
+
: peerStateCode(peer.descriptor.state),
|
|
740
|
+
routingId: peer.descriptor.nodeRoutingId as RoutingId,
|
|
741
|
+
lifecycleGeneration: peer.descriptor.lifecycleGeneration,
|
|
742
|
+
descriptorRevision: peer.descriptor.descriptorRevision,
|
|
743
|
+
endpoint: peer.descriptor.advertisedEndpoint,
|
|
744
|
+
channelCount: peer.descriptor.channels.length,
|
|
745
|
+
lastError: 0,
|
|
746
|
+
lastChangedMs: BigInt(Math.trunc(performance.now()))
|
|
747
|
+
}));
|
|
748
|
+
const notRequired = (this.runtime?.topology.notRequiredPeers() ?? []).map(descriptor => ({
|
|
749
|
+
connectionIntentId: findIntent(
|
|
750
|
+
descriptor.nodeRoutingId,
|
|
751
|
+
descriptor.advertisedEndpoint
|
|
752
|
+
)?.id ?? 0n,
|
|
753
|
+
source: 1,
|
|
754
|
+
state: 6,
|
|
755
|
+
routingId: descriptor.nodeRoutingId as RoutingId,
|
|
756
|
+
lifecycleGeneration: descriptor.lifecycleGeneration,
|
|
757
|
+
descriptorRevision: descriptor.descriptorRevision,
|
|
758
|
+
endpoint: descriptor.advertisedEndpoint,
|
|
759
|
+
channelCount: 0,
|
|
760
|
+
lastError: 0,
|
|
761
|
+
lastChangedMs: BigInt(Math.trunc(performance.now()))
|
|
762
|
+
}));
|
|
763
|
+
const projected = new Set([
|
|
764
|
+
...admitted.map(peer => peer.connectionIntentId),
|
|
765
|
+
...notRequired.map(peer => peer.connectionIntentId)
|
|
766
|
+
]);
|
|
767
|
+
const disconnected = intents
|
|
768
|
+
.filter(intent =>
|
|
769
|
+
intent.nodeRoutingId !== undefined
|
|
770
|
+
&& !projected.has(intent.id))
|
|
771
|
+
.map(intent => {
|
|
772
|
+
const descriptor = this.runtime?.topology.knownDescriptor(intent.nodeRoutingId!);
|
|
773
|
+
return {
|
|
774
|
+
connectionIntentId: intent.id,
|
|
775
|
+
source: 1,
|
|
776
|
+
// A new manual intent is Connecting until its first descriptor is
|
|
777
|
+
// observed. A previously admitted required peer is NotConnected.
|
|
778
|
+
state: descriptor === undefined ? 1 : 0,
|
|
779
|
+
routingId: intent.nodeRoutingId! as RoutingId,
|
|
780
|
+
lifecycleGeneration: descriptor?.lifecycleGeneration ?? 0n,
|
|
781
|
+
descriptorRevision: descriptor?.descriptorRevision ?? 0n,
|
|
782
|
+
endpoint: descriptor?.advertisedEndpoint ?? intent.endpoint,
|
|
783
|
+
channelCount: descriptor?.channels.length ?? 0,
|
|
784
|
+
lastError: 0,
|
|
785
|
+
lastChangedMs: BigInt(Math.trunc(performance.now()))
|
|
786
|
+
};
|
|
787
|
+
});
|
|
788
|
+
return [...admitted, ...notRequired, ...disconnected]
|
|
789
|
+
.sort((left, right) => String(left.routingId).localeCompare(String(right.routingId)));
|
|
790
|
+
}
|
|
791
|
+
|
|
792
|
+
peerChannels(peerRid: unknown, lifecycleGeneration: bigint) {
|
|
793
|
+
const descriptor = this.runtime?.topology.knownDescriptor(String(peerRid));
|
|
794
|
+
if (descriptor === undefined || descriptor.lifecycleGeneration !== lifecycleGeneration) {
|
|
795
|
+
return { names: [], weights: [] };
|
|
796
|
+
}
|
|
797
|
+
return {
|
|
798
|
+
names: descriptor.channels.map(channel => channel.name),
|
|
799
|
+
weights: descriptor.channels.map(channel => channel.weight)
|
|
800
|
+
};
|
|
801
|
+
}
|
|
802
|
+
|
|
803
|
+
createPublisher(): MeshPublisher {
|
|
804
|
+
let publisherClosed = false;
|
|
805
|
+
const publish = async (
|
|
806
|
+
channelName: string,
|
|
807
|
+
topic: string,
|
|
808
|
+
parts: MessageLike | readonly MessageLike[]
|
|
809
|
+
): Promise<void> => {
|
|
810
|
+
if (publisherClosed) throw new Error('Mesh publisher is closed.');
|
|
811
|
+
await this.requireStateful().publishLogicalMulticast(
|
|
812
|
+
channelName,
|
|
813
|
+
topic,
|
|
814
|
+
encodeMultipart(parts)
|
|
815
|
+
);
|
|
816
|
+
};
|
|
817
|
+
return {
|
|
818
|
+
publish,
|
|
819
|
+
publishAsync: async (channelName, topic, parts, _options, signal) => {
|
|
820
|
+
signal?.throwIfAborted();
|
|
821
|
+
await publish(channelName, topic, parts);
|
|
822
|
+
},
|
|
823
|
+
close: () => {
|
|
824
|
+
publisherClosed = true;
|
|
825
|
+
}
|
|
826
|
+
};
|
|
827
|
+
}
|
|
828
|
+
|
|
829
|
+
setReadyHandler(handler: (readyDomains: number) => number): void {
|
|
830
|
+
this.readyHandler = handler;
|
|
831
|
+
this.notifyReady();
|
|
832
|
+
}
|
|
833
|
+
|
|
834
|
+
createReadyBatch(capacity: number): ReadyBatch {
|
|
835
|
+
return new RawReadyBatch(capacity);
|
|
836
|
+
}
|
|
837
|
+
|
|
838
|
+
createReceiveBatch(
|
|
839
|
+
messageCapacity: number,
|
|
840
|
+
partCapacity: number
|
|
841
|
+
): ReceiveBatch {
|
|
842
|
+
return new RawReceiveBatch(messageCapacity, partCapacity);
|
|
843
|
+
}
|
|
844
|
+
|
|
845
|
+
drainReady(
|
|
846
|
+
domains: number,
|
|
847
|
+
batch: ReadyBatch
|
|
848
|
+
): { readonly ok: boolean; readonly hasResidue: boolean; readonly records: readonly ReadyRecord[] } {
|
|
849
|
+
const target = requireRawReadyBatch(batch);
|
|
850
|
+
if ((domains & ReadyDomain.Infrastructure) !== 0) {
|
|
851
|
+
this.drainCompletions(target);
|
|
852
|
+
this.drainMailbox('infrastructure', target);
|
|
853
|
+
}
|
|
854
|
+
if ((domains & ReadyDomain.Application) !== 0) {
|
|
855
|
+
this.drainMailbox('application', target);
|
|
856
|
+
}
|
|
857
|
+
const runtime = this.runtime;
|
|
858
|
+
const infrastructureResidue = (domains & ReadyDomain.Infrastructure) !== 0
|
|
859
|
+
&& (
|
|
860
|
+
this.completionCount > 0
|
|
861
|
+
|| (runtime?.mailbox.pendingMessages('infrastructure') ?? 0) > 0
|
|
862
|
+
);
|
|
863
|
+
const applicationResidue = (domains & ReadyDomain.Application) !== 0
|
|
864
|
+
&& (runtime?.mailbox.pendingMessages('application') ?? 0) > 0;
|
|
865
|
+
return {
|
|
866
|
+
ok: true,
|
|
867
|
+
// Residue is scoped to the requested lane. The pump drains lanes in
|
|
868
|
+
// separate turns and must not wait on another lane before returning.
|
|
869
|
+
hasResidue: infrastructureResidue || applicationResidue,
|
|
870
|
+
records: target.records
|
|
871
|
+
};
|
|
872
|
+
}
|
|
873
|
+
|
|
874
|
+
createSpot(): ServiceSpot {
|
|
875
|
+
return new RawServiceSpot(this, this.requireStateful().createSpot());
|
|
876
|
+
}
|
|
877
|
+
|
|
878
|
+
entrySpot(): ServiceSpot {
|
|
879
|
+
return new RawServiceSpot(this, this.requireStateful().entrySpot());
|
|
880
|
+
}
|
|
881
|
+
|
|
882
|
+
getOrCreateSpot(routingId: unknown): { readonly spot: ServiceSpot; readonly created: boolean } {
|
|
883
|
+
const stateful = this.requireStateful();
|
|
884
|
+
const rid = String(routingId);
|
|
885
|
+
const existing = stateful.registry.spot(rid);
|
|
886
|
+
const state = existing ?? stateful.createSpot(rid);
|
|
887
|
+
return { spot: new RawServiceSpot(this, state), created: existing === undefined };
|
|
888
|
+
}
|
|
889
|
+
|
|
890
|
+
instanceSpotApplicationTarget(
|
|
891
|
+
spotId: string
|
|
892
|
+
): { readonly stableType: string; readonly objectGeneration: bigint } | undefined {
|
|
893
|
+
return this.requireStateful().instanceSpotApplicationTarget(spotId);
|
|
894
|
+
}
|
|
895
|
+
|
|
896
|
+
waitForInstanceApplicationQuiescence(
|
|
897
|
+
spotId: string,
|
|
898
|
+
signal?: AbortSignal
|
|
899
|
+
): Promise<void> {
|
|
900
|
+
return this.requireStateful().waitForInstanceApplicationQuiescence(spotId, signal);
|
|
901
|
+
}
|
|
902
|
+
|
|
903
|
+
restoreUserSpotAuthority(
|
|
904
|
+
spotId: string,
|
|
905
|
+
stableType: string,
|
|
906
|
+
generation: bigint,
|
|
907
|
+
authorityOwnerGeneration: bigint
|
|
908
|
+
): ServiceSpot {
|
|
909
|
+
return new RawServiceSpot(
|
|
910
|
+
this,
|
|
911
|
+
this.requireStateful().restoreUserSpotAuthority(
|
|
912
|
+
spotId,
|
|
913
|
+
stableType,
|
|
914
|
+
generation,
|
|
915
|
+
authorityOwnerGeneration
|
|
916
|
+
)
|
|
917
|
+
);
|
|
918
|
+
}
|
|
919
|
+
|
|
920
|
+
restoreSpotAuthority(
|
|
921
|
+
spotId: string,
|
|
922
|
+
objectKind: 'user_spot' | 'instance_spot',
|
|
923
|
+
stableType: string,
|
|
924
|
+
generation: bigint,
|
|
925
|
+
authorityOwnerGeneration: bigint
|
|
926
|
+
): ServiceSpot {
|
|
927
|
+
return new RawServiceSpot(
|
|
928
|
+
this,
|
|
929
|
+
this.requireStateful().restoreSpotAuthority(
|
|
930
|
+
spotId,
|
|
931
|
+
objectKind,
|
|
932
|
+
stableType,
|
|
933
|
+
generation,
|
|
934
|
+
authorityOwnerGeneration
|
|
935
|
+
)
|
|
936
|
+
);
|
|
937
|
+
}
|
|
938
|
+
|
|
939
|
+
createActor(actorId: string): ZLinkBackendActorRef {
|
|
940
|
+
return this.requireStateful().createActor(actorId).ref;
|
|
941
|
+
}
|
|
942
|
+
|
|
943
|
+
restoreActorAuthority(
|
|
944
|
+
actorId: string,
|
|
945
|
+
stableType: string,
|
|
946
|
+
generation: bigint,
|
|
947
|
+
authorityOwnerGeneration: bigint,
|
|
948
|
+
spotId: string,
|
|
949
|
+
spotGeneration: bigint,
|
|
950
|
+
membershipEpoch: bigint
|
|
951
|
+
): ZLinkBackendActorRef {
|
|
952
|
+
return this.requireStateful().restoreActorAuthority(
|
|
953
|
+
actorId,
|
|
954
|
+
stableType,
|
|
955
|
+
generation,
|
|
956
|
+
authorityOwnerGeneration,
|
|
957
|
+
spotId,
|
|
958
|
+
spotGeneration,
|
|
959
|
+
membershipEpoch
|
|
960
|
+
).ref;
|
|
961
|
+
}
|
|
962
|
+
|
|
963
|
+
discardRelocatedActor(actor: ZLinkBackendActorRef): void {
|
|
964
|
+
this.requireStateful().discardRelocatedActor({
|
|
965
|
+
nodeRid: String(actor.nodeRid),
|
|
966
|
+
actorId: actor.actorId,
|
|
967
|
+
generation: actor.generation
|
|
968
|
+
});
|
|
969
|
+
}
|
|
970
|
+
|
|
971
|
+
restoreActorSessionBinding(
|
|
972
|
+
actor: ZLinkBackendActorRef,
|
|
973
|
+
sessionNodeRid: unknown,
|
|
974
|
+
sessionRid: unknown,
|
|
975
|
+
bindingGeneration: bigint
|
|
976
|
+
): void {
|
|
977
|
+
this.requireStateful().restoreActorSessionBinding(
|
|
978
|
+
{
|
|
979
|
+
nodeRid: String(actor.nodeRid),
|
|
980
|
+
actorId: actor.actorId,
|
|
981
|
+
generation: actor.generation
|
|
982
|
+
},
|
|
983
|
+
String(sessionNodeRid),
|
|
984
|
+
String(sessionRid),
|
|
985
|
+
bindingGeneration
|
|
986
|
+
);
|
|
987
|
+
}
|
|
988
|
+
|
|
989
|
+
registerInstanceIntent(
|
|
990
|
+
instanceType: string,
|
|
991
|
+
route: ServiceInstanceRouteFence,
|
|
992
|
+
expectedCurrentRoute?: ServiceInstanceRouteFence | null
|
|
993
|
+
): void {
|
|
994
|
+
this.requireStateful().registerInstanceIntent(instanceType, route, expectedCurrentRoute);
|
|
995
|
+
}
|
|
996
|
+
|
|
997
|
+
registerAsyncInstanceActivationAuthority(
|
|
998
|
+
authority: ServiceAsyncInstanceActivationAuthority
|
|
999
|
+
): void {
|
|
1000
|
+
this.requireStateful().registerAsyncInstanceActivationAuthority(authority);
|
|
1001
|
+
}
|
|
1002
|
+
|
|
1003
|
+
registerInstanceApplicationLifecycle(
|
|
1004
|
+
lifecycle: ServiceInstanceApplicationLifecycle
|
|
1005
|
+
): void {
|
|
1006
|
+
this.requireStateful().registerInstanceApplicationLifecycle(lifecycle);
|
|
1007
|
+
}
|
|
1008
|
+
|
|
1009
|
+
registerUserSpotOperationHandler(handler: ServiceUserSpotOperationHandler): void {
|
|
1010
|
+
this.requireStateful().registerUserSpotOperationHandler(handler);
|
|
1011
|
+
}
|
|
1012
|
+
|
|
1013
|
+
requestUserSpotCreate(
|
|
1014
|
+
targetNodeRid: string,
|
|
1015
|
+
request: Omit<ServiceUserSpotCreateRecord, 'kind' | 'correlation' | 'operation'>,
|
|
1016
|
+
timeoutMs: number
|
|
1017
|
+
): Promise<ServiceUserSpotOperationResult> {
|
|
1018
|
+
return this.requireStateful().requestUserSpotCreate(targetNodeRid, request, timeoutMs);
|
|
1019
|
+
}
|
|
1020
|
+
|
|
1021
|
+
requestUserSpotClose(
|
|
1022
|
+
targetNodeRid: string,
|
|
1023
|
+
request: Omit<ServiceUserSpotCloseRecord, 'kind' | 'correlation' | 'operation'>,
|
|
1024
|
+
timeoutMs: number
|
|
1025
|
+
): Promise<ServiceUserSpotOperationResult> {
|
|
1026
|
+
return this.requireStateful().requestUserSpotClose(targetNodeRid, request, timeoutMs);
|
|
1027
|
+
}
|
|
1028
|
+
|
|
1029
|
+
requestActorCreate(
|
|
1030
|
+
targetNodeRid: string,
|
|
1031
|
+
request: Omit<ServiceActorCreateRecord, 'kind' | 'correlation' | 'operation'>,
|
|
1032
|
+
timeoutMs: number
|
|
1033
|
+
): Promise<ServiceUserSpotOperationResult> {
|
|
1034
|
+
return this.requireStateful().requestActorCreate(targetNodeRid, request, timeoutMs);
|
|
1035
|
+
}
|
|
1036
|
+
|
|
1037
|
+
recoverInstanceActivation(
|
|
1038
|
+
envelope: ServiceInstanceActivationRecoveryEnvelope,
|
|
1039
|
+
route: ServiceInstanceRouteFence,
|
|
1040
|
+
expectedCurrentRoute?: ServiceInstanceRouteFence | null
|
|
1041
|
+
): Promise<boolean> {
|
|
1042
|
+
return this.requireStateful().recoverInstanceActivation(envelope, route, expectedCurrentRoute);
|
|
1043
|
+
}
|
|
1044
|
+
|
|
1045
|
+
recoverPendingInstanceActivation(
|
|
1046
|
+
envelope: ServiceInstanceActivationRecoveryEnvelope,
|
|
1047
|
+
pending: ServicePendingInstanceActivation,
|
|
1048
|
+
expectedCurrentRoute?: ServiceInstanceRouteFence | null
|
|
1049
|
+
): Promise<boolean> {
|
|
1050
|
+
return this.requireStateful().recoverPendingInstanceActivation(envelope, pending, expectedCurrentRoute);
|
|
1051
|
+
}
|
|
1052
|
+
|
|
1053
|
+
completeRecoveredInstanceActivation(
|
|
1054
|
+
target: ServiceInstanceActivationTarget,
|
|
1055
|
+
route: ServiceInstanceRouteFence,
|
|
1056
|
+
expectedCurrentRoute?: ServiceInstanceRouteFence | null
|
|
1057
|
+
): Promise<ServiceInstanceRouteFence | undefined> {
|
|
1058
|
+
return this.requireStateful().completeRecoveredInstanceActivation(target, route, expectedCurrentRoute);
|
|
1059
|
+
}
|
|
1060
|
+
|
|
1061
|
+
forgetInstanceIntent(
|
|
1062
|
+
spotId: string,
|
|
1063
|
+
objectGeneration: bigint,
|
|
1064
|
+
authorityOwnerGeneration: bigint,
|
|
1065
|
+
storeVersion?: string
|
|
1066
|
+
): void {
|
|
1067
|
+
this.requireStateful().forgetInstanceIntent(
|
|
1068
|
+
spotId,
|
|
1069
|
+
objectGeneration,
|
|
1070
|
+
authorityOwnerGeneration,
|
|
1071
|
+
storeVersion
|
|
1072
|
+
);
|
|
1073
|
+
}
|
|
1074
|
+
|
|
1075
|
+
rememberSpotRoute(
|
|
1076
|
+
route: ServiceDirectSpotRouteFence,
|
|
1077
|
+
expectedCurrentRoute?: ServiceDirectSpotRouteFence | null
|
|
1078
|
+
): void {
|
|
1079
|
+
this.requireStateful().rememberSpotRoute(route, expectedCurrentRoute);
|
|
1080
|
+
}
|
|
1081
|
+
|
|
1082
|
+
entrySpotRouteFence(
|
|
1083
|
+
targetNodeRid: string,
|
|
1084
|
+
targetSpotId: string
|
|
1085
|
+
): ServiceDirectSpotRouteFence {
|
|
1086
|
+
const generation = this.peerGeneration(targetNodeRid);
|
|
1087
|
+
return {
|
|
1088
|
+
spot: { spotId: targetSpotId, generation },
|
|
1089
|
+
targetNodeRid,
|
|
1090
|
+
targetNodeGeneration: generation,
|
|
1091
|
+
authorityOwnerGeneration: generation,
|
|
1092
|
+
ownerLeaseGeneration: generation,
|
|
1093
|
+
storeVersion: entrySpotFenceVersion(generation)
|
|
1094
|
+
};
|
|
1095
|
+
}
|
|
1096
|
+
|
|
1097
|
+
sealSpotMessageFollowIngress(
|
|
1098
|
+
source: ServiceDirectSpotRouteFence
|
|
1099
|
+
): ServiceSpotMessageFollowSeal | undefined {
|
|
1100
|
+
return this.requireStateful().sealSpotMessageFollowIngress(source);
|
|
1101
|
+
}
|
|
1102
|
+
|
|
1103
|
+
abortSpotMessageFollowIngress(seal: ServiceSpotMessageFollowSeal): boolean {
|
|
1104
|
+
return this.requireStateful().abortSpotMessageFollowIngress(seal);
|
|
1105
|
+
}
|
|
1106
|
+
|
|
1107
|
+
commitSpotMessageFollowIngress(
|
|
1108
|
+
seal: ServiceSpotMessageFollowSeal,
|
|
1109
|
+
target: ServiceDirectSpotRouteFence,
|
|
1110
|
+
durationMs: number
|
|
1111
|
+
): Promise<boolean> {
|
|
1112
|
+
return this.requireStateful().commitSpotMessageFollowIngress(
|
|
1113
|
+
seal,
|
|
1114
|
+
target,
|
|
1115
|
+
durationMs
|
|
1116
|
+
);
|
|
1117
|
+
}
|
|
1118
|
+
|
|
1119
|
+
forgetSpotRoute(
|
|
1120
|
+
spot: ServiceSpotRouteFence['spot'],
|
|
1121
|
+
authorityOwnerGeneration: bigint,
|
|
1122
|
+
storeVersion?: string
|
|
1123
|
+
): void {
|
|
1124
|
+
this.requireStateful().forgetSpotRoute(spot, authorityOwnerGeneration, storeVersion);
|
|
1125
|
+
}
|
|
1126
|
+
|
|
1127
|
+
async sendToInstanceSpot(
|
|
1128
|
+
route: ServiceInstanceRouteFence,
|
|
1129
|
+
parts: MessageLike | readonly MessageLike[],
|
|
1130
|
+
sourceSpotId?: string,
|
|
1131
|
+
metadata?: ReadonlyMap<string, string>
|
|
1132
|
+
): Promise<SubmitResult> {
|
|
1133
|
+
const result = await this.requireStateful().sendToInstanceSpot(
|
|
1134
|
+
route,
|
|
1135
|
+
encodeMultipart(parts),
|
|
1136
|
+
sourceSpotId,
|
|
1137
|
+
metadata === undefined ? undefined : encodeServiceMetadataFrame(metadata)
|
|
1138
|
+
);
|
|
1139
|
+
return result as SubmitResult;
|
|
1140
|
+
}
|
|
1141
|
+
|
|
1142
|
+
requestInstanceSpot(
|
|
1143
|
+
route: ServiceInstanceRouteFence,
|
|
1144
|
+
parts: MessageLike | readonly MessageLike[],
|
|
1145
|
+
timeoutMs = 30_000,
|
|
1146
|
+
sourceSpotId?: string,
|
|
1147
|
+
metadata?: ReadonlyMap<string, string>
|
|
1148
|
+
): MeshOperationId {
|
|
1149
|
+
return this.observeStateful(
|
|
1150
|
+
OperationKind.InstanceSpotRequest,
|
|
1151
|
+
this.requireStateful().requestToInstanceSpot(
|
|
1152
|
+
route,
|
|
1153
|
+
encodeMultipart(parts),
|
|
1154
|
+
timeoutMs,
|
|
1155
|
+
sourceSpotId,
|
|
1156
|
+
metadata === undefined ? undefined : encodeServiceMetadataFrame(metadata)
|
|
1157
|
+
)
|
|
1158
|
+
);
|
|
1159
|
+
}
|
|
1160
|
+
|
|
1161
|
+
actorLookup(actorId: string) {
|
|
1162
|
+
const actor = this.requireStateful().actor(actorId);
|
|
1163
|
+
if (actor === undefined) {
|
|
1164
|
+
throw Object.assign(new Error(`Actor '${actorId}' was not found.`), { nativeErrno: 2 });
|
|
1165
|
+
}
|
|
1166
|
+
return {
|
|
1167
|
+
actor: actor.ref,
|
|
1168
|
+
spotId: actor.spot.spotId,
|
|
1169
|
+
spotGeneration: actor.spot.generation,
|
|
1170
|
+
membershipEpoch: actor.membershipEpoch
|
|
1171
|
+
};
|
|
1172
|
+
}
|
|
1173
|
+
|
|
1174
|
+
lookupRemoteActor(targetNodeRid: unknown, actorId: string, timeoutMs = 30_000): MeshOperationId {
|
|
1175
|
+
return this.observeStateful(
|
|
1176
|
+
OperationKind.ActorLookup,
|
|
1177
|
+
this.requireStateful().lookupRemoteActor(String(targetNodeRid), actorId, timeoutMs)
|
|
1178
|
+
);
|
|
1179
|
+
}
|
|
1180
|
+
|
|
1181
|
+
destroyActor(actor: ZLinkBackendActorRef, timeoutMs = 30_000): MeshOperationId {
|
|
1182
|
+
return this.observeStateful(
|
|
1183
|
+
OperationKind.ActorDestroy,
|
|
1184
|
+
this.requireStateful().destroyActor(actor, timeoutMs)
|
|
1185
|
+
);
|
|
1186
|
+
}
|
|
1187
|
+
|
|
1188
|
+
joinActorSpot(
|
|
1189
|
+
actor: ZLinkBackendActorRef,
|
|
1190
|
+
targetNodeRid: unknown,
|
|
1191
|
+
targetSpotId: unknown,
|
|
1192
|
+
targetSpotGeneration: bigint,
|
|
1193
|
+
request: ServiceApplicationPayload,
|
|
1194
|
+
timeoutMs = 30_000
|
|
1195
|
+
): MeshOperationId {
|
|
1196
|
+
return this.observeStateful(
|
|
1197
|
+
OperationKind.ActorJoin,
|
|
1198
|
+
this.requireStateful().joinActor(
|
|
1199
|
+
actor,
|
|
1200
|
+
String(targetNodeRid),
|
|
1201
|
+
{ spotId: String(targetSpotId), generation: targetSpotGeneration },
|
|
1202
|
+
targetSpotGeneration,
|
|
1203
|
+
request,
|
|
1204
|
+
timeoutMs
|
|
1205
|
+
)
|
|
1206
|
+
);
|
|
1207
|
+
}
|
|
1208
|
+
|
|
1209
|
+
joinActorSpotCanonical(
|
|
1210
|
+
actor: ZLinkBackendActorRef,
|
|
1211
|
+
targetNodeRid: unknown,
|
|
1212
|
+
targetSpotId: unknown,
|
|
1213
|
+
targetSpotGeneration: bigint,
|
|
1214
|
+
request: ServiceApplicationPayload,
|
|
1215
|
+
actorFence: {
|
|
1216
|
+
readonly targetNodeGeneration: bigint;
|
|
1217
|
+
readonly authorityOwnerGeneration: bigint;
|
|
1218
|
+
readonly ownerLeaseGeneration: bigint;
|
|
1219
|
+
},
|
|
1220
|
+
local: { readonly phase: 'admission'; readonly transferId: string },
|
|
1221
|
+
timeoutMs = 30_000
|
|
1222
|
+
): MeshOperationId {
|
|
1223
|
+
return this.observeStateful(
|
|
1224
|
+
OperationKind.ActorJoin,
|
|
1225
|
+
this.requireStateful().joinActorCanonical(
|
|
1226
|
+
actor,
|
|
1227
|
+
String(targetNodeRid),
|
|
1228
|
+
{ spotId: String(targetSpotId), generation: targetSpotGeneration },
|
|
1229
|
+
targetSpotGeneration,
|
|
1230
|
+
request,
|
|
1231
|
+
actorFence,
|
|
1232
|
+
local,
|
|
1233
|
+
timeoutMs
|
|
1234
|
+
)
|
|
1235
|
+
);
|
|
1236
|
+
}
|
|
1237
|
+
|
|
1238
|
+
joinActorEntrySpot(
|
|
1239
|
+
actor: ZLinkBackendActorRef,
|
|
1240
|
+
targetNodeRid: unknown,
|
|
1241
|
+
request: ServiceApplicationPayload,
|
|
1242
|
+
timeoutMs = 30_000
|
|
1243
|
+
): MeshOperationId {
|
|
1244
|
+
const target = String(targetNodeRid);
|
|
1245
|
+
return this.observeStateful(
|
|
1246
|
+
OperationKind.ActorJoin,
|
|
1247
|
+
this.requireStateful().joinActorEntrySpot(
|
|
1248
|
+
actor,
|
|
1249
|
+
target,
|
|
1250
|
+
request,
|
|
1251
|
+
timeoutMs
|
|
1252
|
+
)
|
|
1253
|
+
);
|
|
1254
|
+
}
|
|
1255
|
+
|
|
1256
|
+
joinActorEntrySpotCanonical(
|
|
1257
|
+
actor: ZLinkBackendActorRef,
|
|
1258
|
+
targetNodeRid: unknown,
|
|
1259
|
+
request: ServiceApplicationPayload,
|
|
1260
|
+
actorFence: {
|
|
1261
|
+
readonly targetNodeGeneration: bigint;
|
|
1262
|
+
readonly authorityOwnerGeneration: bigint;
|
|
1263
|
+
readonly ownerLeaseGeneration: bigint;
|
|
1264
|
+
},
|
|
1265
|
+
local: { readonly phase: 'admission'; readonly transferId: string },
|
|
1266
|
+
timeoutMs = 30_000
|
|
1267
|
+
): MeshOperationId {
|
|
1268
|
+
const target = String(targetNodeRid);
|
|
1269
|
+
return this.observeStateful(
|
|
1270
|
+
OperationKind.ActorJoin,
|
|
1271
|
+
this.requireStateful().joinActorEntrySpotCanonical(
|
|
1272
|
+
actor,
|
|
1273
|
+
target,
|
|
1274
|
+
request,
|
|
1275
|
+
actorFence,
|
|
1276
|
+
local,
|
|
1277
|
+
timeoutMs
|
|
1278
|
+
)
|
|
1279
|
+
);
|
|
1280
|
+
}
|
|
1281
|
+
|
|
1282
|
+
async sendToActor(
|
|
1283
|
+
actor: ZLinkBackendActorRef,
|
|
1284
|
+
parts: MessageLike | readonly MessageLike[]
|
|
1285
|
+
): Promise<SubmitResultValue> {
|
|
1286
|
+
return this.requireStateful().sendToActor(
|
|
1287
|
+
actor,
|
|
1288
|
+
this.peerGeneration(String(actor.nodeRid)),
|
|
1289
|
+
actor.generation,
|
|
1290
|
+
encodeMultipart(parts)
|
|
1291
|
+
) as Promise<SubmitResultValue>;
|
|
1292
|
+
}
|
|
1293
|
+
|
|
1294
|
+
requestToActor(
|
|
1295
|
+
actor: ZLinkBackendActorRef,
|
|
1296
|
+
parts: MessageLike | readonly MessageLike[],
|
|
1297
|
+
options?: { readonly timeoutMs?: number }
|
|
1298
|
+
): MeshOperationId {
|
|
1299
|
+
return this.observeStateful(
|
|
1300
|
+
OperationKind.ActorRequest,
|
|
1301
|
+
this.requireStateful().requestToActor(
|
|
1302
|
+
actor,
|
|
1303
|
+
this.peerGeneration(String(actor.nodeRid)),
|
|
1304
|
+
actor.generation,
|
|
1305
|
+
encodeMultipart(parts),
|
|
1306
|
+
options?.timeoutMs ?? 30_000
|
|
1307
|
+
)
|
|
1308
|
+
);
|
|
1309
|
+
}
|
|
1310
|
+
|
|
1311
|
+
async actorSendToActor(
|
|
1312
|
+
source: ZLinkBackendActorRef,
|
|
1313
|
+
target: ZLinkBackendActorRef,
|
|
1314
|
+
parts: MessageLike | readonly MessageLike[]
|
|
1315
|
+
): Promise<SubmitResultValue> {
|
|
1316
|
+
return await this.requireStateful().sendToActor(
|
|
1317
|
+
target,
|
|
1318
|
+
this.peerGeneration(String(target.nodeRid)),
|
|
1319
|
+
target.generation,
|
|
1320
|
+
encodeMultipart(parts),
|
|
1321
|
+
source
|
|
1322
|
+
) as SubmitResultValue;
|
|
1323
|
+
}
|
|
1324
|
+
|
|
1325
|
+
actorRequestToActor(
|
|
1326
|
+
source: ZLinkBackendActorRef,
|
|
1327
|
+
target: ZLinkBackendActorRef,
|
|
1328
|
+
parts: MessageLike | readonly MessageLike[],
|
|
1329
|
+
options?: { readonly timeoutMs?: number }
|
|
1330
|
+
): MeshOperationId {
|
|
1331
|
+
return this.observeStateful(
|
|
1332
|
+
OperationKind.ActorRequest,
|
|
1333
|
+
this.requireStateful().requestToActor(
|
|
1334
|
+
target,
|
|
1335
|
+
this.peerGeneration(String(target.nodeRid)),
|
|
1336
|
+
target.generation,
|
|
1337
|
+
encodeMultipart(parts),
|
|
1338
|
+
options?.timeoutMs ?? 30_000,
|
|
1339
|
+
source
|
|
1340
|
+
)
|
|
1341
|
+
);
|
|
1342
|
+
}
|
|
1343
|
+
|
|
1344
|
+
async sendActorBoundSession(
|
|
1345
|
+
actor: ZLinkBackendActorRef,
|
|
1346
|
+
expectedBindingGeneration: bigint,
|
|
1347
|
+
parts: MessageLike | readonly MessageLike[],
|
|
1348
|
+
_flags?: number,
|
|
1349
|
+
actorFence?: ZLinkBackendActorSessionSendFence
|
|
1350
|
+
): Promise<SubmitResultValue> {
|
|
1351
|
+
return await this.requireStateful().sendBoundSession(
|
|
1352
|
+
actor,
|
|
1353
|
+
expectedBindingGeneration,
|
|
1354
|
+
encodeMultipart(parts),
|
|
1355
|
+
actorFence
|
|
1356
|
+
) as SubmitResultValue;
|
|
1357
|
+
}
|
|
1358
|
+
|
|
1359
|
+
closeActorBoundSession(
|
|
1360
|
+
actor: ZLinkBackendActorRef,
|
|
1361
|
+
expectedBindingGeneration: bigint,
|
|
1362
|
+
timeoutMs = 30_000
|
|
1363
|
+
): MeshOperationId {
|
|
1364
|
+
const binding = this.requireStateful().registry.binding(actor);
|
|
1365
|
+
if (binding === undefined) {
|
|
1366
|
+
return this.enqueueImmediateFailure(OperationKind.StreamUnbind, RequestResult.NotFound);
|
|
1367
|
+
}
|
|
1368
|
+
return this.observeStateful(
|
|
1369
|
+
OperationKind.StreamUnbind,
|
|
1370
|
+
this.requireStateful().unbindSession(
|
|
1371
|
+
binding.sessionRid,
|
|
1372
|
+
actor,
|
|
1373
|
+
expectedBindingGeneration,
|
|
1374
|
+
timeoutMs
|
|
1375
|
+
)
|
|
1376
|
+
);
|
|
1377
|
+
}
|
|
1378
|
+
|
|
1379
|
+
leaveActor(
|
|
1380
|
+
actor: ZLinkBackendActorRef,
|
|
1381
|
+
expectedMembershipEpoch: bigint,
|
|
1382
|
+
timeoutMs = 30_000
|
|
1383
|
+
): MeshOperationId {
|
|
1384
|
+
return this.observeStateful(
|
|
1385
|
+
OperationKind.ActorLeave,
|
|
1386
|
+
this.requireStateful().leaveActor(actor, expectedMembershipEpoch, timeoutMs)
|
|
1387
|
+
);
|
|
1388
|
+
}
|
|
1389
|
+
|
|
1390
|
+
createStreamSessionService(stream: unknown): StreamSessionService {
|
|
1391
|
+
return new RawStreamSessionService(
|
|
1392
|
+
this.requireStateful(),
|
|
1393
|
+
stream as StreamSocket,
|
|
1394
|
+
(kind, pending) => this.observeStateful(kind, pending)
|
|
1395
|
+
);
|
|
1396
|
+
}
|
|
1397
|
+
|
|
1398
|
+
async sendFromSpot(
|
|
1399
|
+
source: ServiceSpotState,
|
|
1400
|
+
target: ServiceDirectSpotRouteFence,
|
|
1401
|
+
parts: MessageLike | readonly MessageLike[]
|
|
1402
|
+
): Promise<SubmitResultValue> {
|
|
1403
|
+
return await this.requireStateful().sendToSpot(
|
|
1404
|
+
source.ref.spotId,
|
|
1405
|
+
target,
|
|
1406
|
+
encodeMultipart(parts)
|
|
1407
|
+
) as SubmitResultValue;
|
|
1408
|
+
}
|
|
1409
|
+
|
|
1410
|
+
requestFromSpot(
|
|
1411
|
+
source: ServiceSpotState,
|
|
1412
|
+
target: ServiceDirectSpotRouteFence,
|
|
1413
|
+
parts: MessageLike | readonly MessageLike[],
|
|
1414
|
+
timeoutMs: number
|
|
1415
|
+
): MeshOperationId {
|
|
1416
|
+
return this.observeStateful(
|
|
1417
|
+
OperationKind.SpotRequest,
|
|
1418
|
+
this.requireStateful().requestToSpot(
|
|
1419
|
+
source.ref.spotId,
|
|
1420
|
+
target,
|
|
1421
|
+
encodeMultipart(parts),
|
|
1422
|
+
timeoutMs
|
|
1423
|
+
)
|
|
1424
|
+
);
|
|
1425
|
+
}
|
|
1426
|
+
|
|
1427
|
+
closeSpot(state: ServiceSpotState): boolean {
|
|
1428
|
+
return this.requireStateful().registry.closeSpot(state.ref);
|
|
1429
|
+
}
|
|
1430
|
+
|
|
1431
|
+
async publishFromSpot(
|
|
1432
|
+
state: ServiceSpotState,
|
|
1433
|
+
channelName: string,
|
|
1434
|
+
topic: string,
|
|
1435
|
+
parts: MessageLike | readonly MessageLike[]
|
|
1436
|
+
): Promise<void> {
|
|
1437
|
+
await this.requireStateful().publishLogicalMulticast(
|
|
1438
|
+
channelName,
|
|
1439
|
+
topic,
|
|
1440
|
+
encodeMultipart(parts),
|
|
1441
|
+
state.ref.spotId
|
|
1442
|
+
);
|
|
1443
|
+
}
|
|
1444
|
+
|
|
1445
|
+
setSpotSubscription(
|
|
1446
|
+
state: ServiceSpotState,
|
|
1447
|
+
channelName: string,
|
|
1448
|
+
topicFilter: string
|
|
1449
|
+
): void {
|
|
1450
|
+
this.requireStateful().setSubscription(state, channelName, topicFilter);
|
|
1451
|
+
}
|
|
1452
|
+
|
|
1453
|
+
unsetSpotSubscription(
|
|
1454
|
+
state: ServiceSpotState,
|
|
1455
|
+
channelName: string,
|
|
1456
|
+
topicFilter: string
|
|
1457
|
+
): void {
|
|
1458
|
+
this.requireStateful().unsetSubscription(state, channelName, topicFilter);
|
|
1459
|
+
}
|
|
1460
|
+
|
|
1461
|
+
clearSpotSubscriptions(state: ServiceSpotState): void {
|
|
1462
|
+
this.requireStateful().clearSubscriptions(state.ref.spotId);
|
|
1463
|
+
}
|
|
1464
|
+
|
|
1465
|
+
private createDescriptor(): ServiceNodeDescriptor {
|
|
1466
|
+
const channels: ServiceChannelDescriptor[] = [...this.channels]
|
|
1467
|
+
.map(([name, weight]) => ({ name, weight }))
|
|
1468
|
+
.sort((left, right) => left.name.localeCompare(right.name));
|
|
1469
|
+
return {
|
|
1470
|
+
meshName: this.meshName,
|
|
1471
|
+
nodeRoutingId: this.routingId,
|
|
1472
|
+
lifecycleGeneration: this.lifecycleGeneration,
|
|
1473
|
+
descriptorRevision: 1n,
|
|
1474
|
+
advertisedEndpoint: this.bindEndpoint ?? 'inproc://not-started',
|
|
1475
|
+
channels,
|
|
1476
|
+
state: 'preparing',
|
|
1477
|
+
// Plaintext RouteMesh peers use the shared default admission identity.
|
|
1478
|
+
securityIdentity: 'default',
|
|
1479
|
+
applicationVersion: 0n,
|
|
1480
|
+
...(this.maintenanceWave === undefined ? {} : { maintenanceWave: this.maintenanceWave }),
|
|
1481
|
+
protocolCapabilities: [
|
|
1482
|
+
SERVICE_WIRE_REQUIRED_CAPABILITY,
|
|
1483
|
+
...this.objectCapabilities
|
|
1484
|
+
].sort(),
|
|
1485
|
+
objectRole: this.objectRole,
|
|
1486
|
+
placementWeight: this.placementWeight,
|
|
1487
|
+
activeCapacityLimit: this.activeCapacityLimit,
|
|
1488
|
+
pendingCapacityLimit: this.pendingCapacityLimit,
|
|
1489
|
+
activeCapacityUsed: 0,
|
|
1490
|
+
pendingCapacityUsed: 0
|
|
1491
|
+
};
|
|
1492
|
+
}
|
|
1493
|
+
|
|
1494
|
+
private resolveAdvertisedEndpoint(boundEndpoint: string): string {
|
|
1495
|
+
const result = buildAdvertisedEndpoint(boundEndpoint, this.advertiseHost, 'tcp');
|
|
1496
|
+
if (result === undefined) {
|
|
1497
|
+
throw new ZLinkConfigurationException(
|
|
1498
|
+
`RouteMesh advertise host requires a TCP endpoint, received '${boundEndpoint}'.`
|
|
1499
|
+
);
|
|
1500
|
+
}
|
|
1501
|
+
return result;
|
|
1502
|
+
}
|
|
1503
|
+
|
|
1504
|
+
private schedulePoll(delayMs = MESH_BACKEND_IDLE_POLL_INTERVAL_MS): void {
|
|
1505
|
+
if (this.closed || this.pollTimer !== undefined) return;
|
|
1506
|
+
this.pollTimer = setTimeout(async () => {
|
|
1507
|
+
this.pollTimer = undefined;
|
|
1508
|
+
try {
|
|
1509
|
+
const received = await this.poll();
|
|
1510
|
+
// A zero-delay timer yields to I/O and other ready work first without
|
|
1511
|
+
// inserting the idle polling interval between readable batches.
|
|
1512
|
+
delayMs = received ? 0 : MESH_BACKEND_IDLE_POLL_INTERVAL_MS;
|
|
1513
|
+
} finally {
|
|
1514
|
+
if (!this.closed) this.schedulePoll(delayMs);
|
|
1515
|
+
}
|
|
1516
|
+
}, delayMs);
|
|
1517
|
+
}
|
|
1518
|
+
|
|
1519
|
+
private async poll(): Promise<boolean> {
|
|
1520
|
+
const runtime = this.runtime;
|
|
1521
|
+
if (runtime === undefined) return false;
|
|
1522
|
+
let received = false;
|
|
1523
|
+
await runtime.drainMonitorEvents();
|
|
1524
|
+
this.receiveBatchBudget.reset(performance.now());
|
|
1525
|
+
for (;;) {
|
|
1526
|
+
this.observedPumpSourceRoutingId = undefined;
|
|
1527
|
+
const result = await runtime.pumpOne(performance.now(), this.observePump);
|
|
1528
|
+
if (result === 'noData') break;
|
|
1529
|
+
received = true;
|
|
1530
|
+
if (result === 'application') this.readyHandler?.(ReadyDomain.Application);
|
|
1531
|
+
const observation = this.takePumpObservation();
|
|
1532
|
+
// Core ROUTER advances its fair-queue cursor after each complete
|
|
1533
|
+
// multipart message, so the next poll resumes from the following pipe.
|
|
1534
|
+
if (
|
|
1535
|
+
observation !== undefined
|
|
1536
|
+
&& this.receiveBatchBudget.record(
|
|
1537
|
+
observation.sourceRoutingId,
|
|
1538
|
+
observation.byteCount,
|
|
1539
|
+
performance.now()
|
|
1540
|
+
)
|
|
1541
|
+
) break;
|
|
1542
|
+
}
|
|
1543
|
+
await runtime.announceExpectedPeers();
|
|
1544
|
+
await runtime.tickLiveness();
|
|
1545
|
+
this.notifyReady();
|
|
1546
|
+
return received;
|
|
1547
|
+
}
|
|
1548
|
+
|
|
1549
|
+
private notifyReady(): void {
|
|
1550
|
+
const runtime = this.runtime;
|
|
1551
|
+
let domains = ReadyDomain.None;
|
|
1552
|
+
if (this.completionCount > 0 || (runtime?.mailbox.pendingMessages('infrastructure') ?? 0) > 0) {
|
|
1553
|
+
domains |= ReadyDomain.Infrastructure;
|
|
1554
|
+
}
|
|
1555
|
+
if ((runtime?.mailbox.pendingMessages('application') ?? 0) > 0) {
|
|
1556
|
+
domains |= ReadyDomain.Application;
|
|
1557
|
+
}
|
|
1558
|
+
if (domains !== ReadyDomain.None) this.readyHandler?.(domains);
|
|
1559
|
+
}
|
|
1560
|
+
|
|
1561
|
+
private observeCompletion(
|
|
1562
|
+
low: bigint,
|
|
1563
|
+
operationKind: number,
|
|
1564
|
+
promise: Promise<RawServiceRequestResult>
|
|
1565
|
+
): MeshOperationId {
|
|
1566
|
+
const id = { high: 1n, low };
|
|
1567
|
+
void promise.then(
|
|
1568
|
+
result => this.enqueueCompletion(id, operationKind, result),
|
|
1569
|
+
error => this.enqueueCompletion(
|
|
1570
|
+
id, operationKind, genericOperationFailure(error))
|
|
1571
|
+
);
|
|
1572
|
+
return id;
|
|
1573
|
+
}
|
|
1574
|
+
|
|
1575
|
+
private observeStateful(
|
|
1576
|
+
operationKind: number,
|
|
1577
|
+
pending: ServiceStatefulPendingOperation
|
|
1578
|
+
): MeshOperationId {
|
|
1579
|
+
const id = { high: 2n, low: pending.id };
|
|
1580
|
+
void pending.promise.then(
|
|
1581
|
+
result => this.enqueueCompletion(id, operationKind, result),
|
|
1582
|
+
error => this.enqueueCompletion(id, operationKind, statefulOperationFailure(error))
|
|
1583
|
+
);
|
|
1584
|
+
return id;
|
|
1585
|
+
}
|
|
1586
|
+
|
|
1587
|
+
private enqueueImmediateFailure(operationKind: number, terminalResult: number): MeshOperationId {
|
|
1588
|
+
const low = this.nextPeerIntent++;
|
|
1589
|
+
const id = { high: 1n, low };
|
|
1590
|
+
this.enqueueCompletion(id, operationKind, { terminalResult, failureCode: 0 });
|
|
1591
|
+
return id;
|
|
1592
|
+
}
|
|
1593
|
+
|
|
1594
|
+
private enqueueCompletion(
|
|
1595
|
+
operationId: MeshOperationId,
|
|
1596
|
+
operationKind: number,
|
|
1597
|
+
result: RawServiceRequestResult | ServiceStatefulResult
|
|
1598
|
+
): void {
|
|
1599
|
+
if (this.closed) return;
|
|
1600
|
+
this.completions.push({ operationId, operationKind, result });
|
|
1601
|
+
this.completionCount += 1;
|
|
1602
|
+
this.readyHandler?.(ReadyDomain.Infrastructure);
|
|
1603
|
+
}
|
|
1604
|
+
|
|
1605
|
+
private drainCompletions(batch: RawReadyBatch): void {
|
|
1606
|
+
while (!batch.full && this.completionCount > 0) {
|
|
1607
|
+
const completion = this.takeCompletion();
|
|
1608
|
+
if (completion === undefined) continue;
|
|
1609
|
+
batch.push(
|
|
1610
|
+
{
|
|
1611
|
+
ownerKind: ReadyOwnerKind.Node,
|
|
1612
|
+
domain: ReadyDomain.Infrastructure,
|
|
1613
|
+
spotId: null,
|
|
1614
|
+
actor: null,
|
|
1615
|
+
terminalCompletion: true
|
|
1616
|
+
},
|
|
1617
|
+
new CompletionClaim(completion)
|
|
1618
|
+
);
|
|
1619
|
+
}
|
|
1620
|
+
}
|
|
1621
|
+
|
|
1622
|
+
private takeCompletion(): PendingCompletion | undefined {
|
|
1623
|
+
const completion = this.completions[this.completionHead];
|
|
1624
|
+
if (completion === undefined) return undefined;
|
|
1625
|
+
this.completions[this.completionHead] = undefined;
|
|
1626
|
+
this.completionHead += 1;
|
|
1627
|
+
this.completionCount -= 1;
|
|
1628
|
+
if (this.completionCount === 0) {
|
|
1629
|
+
this.clearCompletions();
|
|
1630
|
+
} else if (this.completionHead >= 1024
|
|
1631
|
+
&& this.completionHead * 2 >= this.completions.length) {
|
|
1632
|
+
this.completions.splice(0, this.completionHead);
|
|
1633
|
+
this.completionHead = 0;
|
|
1634
|
+
}
|
|
1635
|
+
return completion;
|
|
1636
|
+
}
|
|
1637
|
+
|
|
1638
|
+
private clearCompletions(): void {
|
|
1639
|
+
this.completions.length = 0;
|
|
1640
|
+
this.completionHead = 0;
|
|
1641
|
+
this.completionCount = 0;
|
|
1642
|
+
}
|
|
1643
|
+
|
|
1644
|
+
private drainMailbox(domain: ServiceMailboxDomain, batch: RawReadyBatch): void {
|
|
1645
|
+
const runtime = this.runtime;
|
|
1646
|
+
if (runtime === undefined) return;
|
|
1647
|
+
while (!batch.full) {
|
|
1648
|
+
const claim = runtime.mailbox.tryClaim(
|
|
1649
|
+
domain,
|
|
1650
|
+
MAX_DRAIN_RECORDS,
|
|
1651
|
+
Number.MAX_SAFE_INTEGER
|
|
1652
|
+
);
|
|
1653
|
+
if (claim === undefined) break;
|
|
1654
|
+
const owner = readyOwner(claim.owner, this.routingId, this.stateful, domain);
|
|
1655
|
+
batch.push(
|
|
1656
|
+
owner,
|
|
1657
|
+
new MailboxClaim(runtime, claim, () => {
|
|
1658
|
+
// A receive batch may intentionally consume fewer records than the
|
|
1659
|
+
// mailbox claim. Releasing the claim re-queues the remainder, so
|
|
1660
|
+
// expose that newly ready work to the dispatch pump.
|
|
1661
|
+
if (runtime.mailbox.pendingMessages(domain) > 0) {
|
|
1662
|
+
this.readyHandler?.(
|
|
1663
|
+
domain === 'infrastructure' ? ReadyDomain.Infrastructure : ReadyDomain.Application
|
|
1664
|
+
);
|
|
1665
|
+
}
|
|
1666
|
+
})
|
|
1667
|
+
);
|
|
1668
|
+
}
|
|
1669
|
+
}
|
|
1670
|
+
|
|
1671
|
+
private requireRuntime(): RawServiceMeshRuntime {
|
|
1672
|
+
if (this.runtime === undefined) throw new Error('MeshNode is not started.');
|
|
1673
|
+
return this.runtime;
|
|
1674
|
+
}
|
|
1675
|
+
|
|
1676
|
+
private requireApplicationJobQueue(): ApplicationJobQueuePort {
|
|
1677
|
+
if (this.applicationJobQueue === undefined) {
|
|
1678
|
+
throw new Error('Raw MeshNode requires the host Application Job Queue.');
|
|
1679
|
+
}
|
|
1680
|
+
return this.applicationJobQueue;
|
|
1681
|
+
}
|
|
1682
|
+
|
|
1683
|
+
private requireStateful(): ServiceStatefulRuntime {
|
|
1684
|
+
if (this.stateful === undefined) throw new Error('Stateful MeshNode is not started.');
|
|
1685
|
+
return this.stateful;
|
|
1686
|
+
}
|
|
1687
|
+
|
|
1688
|
+
private peerGeneration(nodeRid: string): bigint {
|
|
1689
|
+
if (nodeRid === this.routingId) {
|
|
1690
|
+
return this.requireRuntime().topology.localDescriptor().lifecycleGeneration;
|
|
1691
|
+
}
|
|
1692
|
+
return this.requireRuntime().topology.peer(nodeRid)?.descriptor.lifecycleGeneration ?? 1n;
|
|
1693
|
+
}
|
|
1694
|
+
|
|
1695
|
+
private requireNotStarted(): void {
|
|
1696
|
+
if (this.runtime !== undefined) throw new Error('MeshNode is already started.');
|
|
1697
|
+
if (this.closed) throw new Error('MeshNode is closed.');
|
|
1698
|
+
}
|
|
1699
|
+
}
|
|
1700
|
+
|
|
1701
|
+
interface PendingCompletion {
|
|
1702
|
+
readonly operationId: MeshOperationId;
|
|
1703
|
+
readonly operationKind: number;
|
|
1704
|
+
readonly result: RawServiceRequestResult | ServiceStatefulResult;
|
|
1705
|
+
}
|
|
1706
|
+
|
|
1707
|
+
interface RawClaim {
|
|
1708
|
+
recvBatch(batch: ReceiveBatch): {
|
|
1709
|
+
readonly ok: boolean;
|
|
1710
|
+
readonly records: ReceiveRecord[];
|
|
1711
|
+
};
|
|
1712
|
+
release(): void;
|
|
1713
|
+
}
|
|
1714
|
+
|
|
1715
|
+
class RawServiceSpot implements ServiceSpot {
|
|
1716
|
+
readonly routingId: RoutingId;
|
|
1717
|
+
readonly lifecycleGeneration: bigint;
|
|
1718
|
+
private readonly subscriptions = new Set<string>();
|
|
1719
|
+
private closed = false;
|
|
1720
|
+
|
|
1721
|
+
constructor(
|
|
1722
|
+
private readonly backend: ZLinkNodeRawMeshBackend,
|
|
1723
|
+
private readonly state: ServiceSpotState
|
|
1724
|
+
) {
|
|
1725
|
+
this.routingId = state.ref.spotId;
|
|
1726
|
+
this.lifecycleGeneration = state.ref.generation;
|
|
1727
|
+
}
|
|
1728
|
+
|
|
1729
|
+
status() {
|
|
1730
|
+
return {
|
|
1731
|
+
routingId: this.routingId,
|
|
1732
|
+
lifecycleGeneration: this.lifecycleGeneration
|
|
1733
|
+
};
|
|
1734
|
+
}
|
|
1735
|
+
|
|
1736
|
+
async sendToChannel(
|
|
1737
|
+
channelName: string,
|
|
1738
|
+
parts: MessageLike | readonly MessageLike[],
|
|
1739
|
+
options?: { readonly flags?: number }
|
|
1740
|
+
): Promise<SubmitResultValue> {
|
|
1741
|
+
this.requireOpen();
|
|
1742
|
+
void options;
|
|
1743
|
+
return this.backend.sendToChannel(channelName, parts);
|
|
1744
|
+
}
|
|
1745
|
+
|
|
1746
|
+
requestToChannel(
|
|
1747
|
+
channelName: string,
|
|
1748
|
+
parts: MessageLike | readonly MessageLike[],
|
|
1749
|
+
options?: { readonly flags?: number; readonly timeoutMs?: number }
|
|
1750
|
+
): MeshOperationId {
|
|
1751
|
+
this.requireOpen();
|
|
1752
|
+
return this.backend.requestToChannel(channelName, parts, options);
|
|
1753
|
+
}
|
|
1754
|
+
|
|
1755
|
+
async sendToSpot(
|
|
1756
|
+
targetNodeRid: unknown,
|
|
1757
|
+
targetSpotId: unknown,
|
|
1758
|
+
targetSpotGeneration: bigint,
|
|
1759
|
+
parts: MessageLike | readonly MessageLike[],
|
|
1760
|
+
options?: {
|
|
1761
|
+
readonly routeFence?: ServiceDirectSpotRouteFence;
|
|
1762
|
+
readonly entrySpot?: boolean;
|
|
1763
|
+
}
|
|
1764
|
+
): Promise<SubmitResultValue> {
|
|
1765
|
+
this.requireOpen();
|
|
1766
|
+
const routeFence = requireDirectSpotRouteFence(
|
|
1767
|
+
options?.routeFence,
|
|
1768
|
+
String(targetNodeRid),
|
|
1769
|
+
String(targetSpotId),
|
|
1770
|
+
targetSpotGeneration,
|
|
1771
|
+
options?.entrySpot === true
|
|
1772
|
+
? this.backend.entrySpotRouteFence(
|
|
1773
|
+
String(targetNodeRid),
|
|
1774
|
+
String(targetSpotId)
|
|
1775
|
+
)
|
|
1776
|
+
: undefined
|
|
1777
|
+
);
|
|
1778
|
+
return this.backend.sendFromSpot(
|
|
1779
|
+
this.state,
|
|
1780
|
+
routeFence,
|
|
1781
|
+
parts
|
|
1782
|
+
);
|
|
1783
|
+
}
|
|
1784
|
+
|
|
1785
|
+
requestToSpot(
|
|
1786
|
+
targetNodeRid: unknown,
|
|
1787
|
+
targetSpotId: unknown,
|
|
1788
|
+
targetSpotGeneration: bigint,
|
|
1789
|
+
parts: MessageLike | readonly MessageLike[],
|
|
1790
|
+
options?: {
|
|
1791
|
+
readonly timeoutMs?: number;
|
|
1792
|
+
readonly routeFence?: ServiceDirectSpotRouteFence;
|
|
1793
|
+
readonly entrySpot?: boolean;
|
|
1794
|
+
}
|
|
1795
|
+
): MeshOperationId {
|
|
1796
|
+
this.requireOpen();
|
|
1797
|
+
const routeFence = requireDirectSpotRouteFence(
|
|
1798
|
+
options?.routeFence,
|
|
1799
|
+
String(targetNodeRid),
|
|
1800
|
+
String(targetSpotId),
|
|
1801
|
+
targetSpotGeneration,
|
|
1802
|
+
options?.entrySpot === true
|
|
1803
|
+
? this.backend.entrySpotRouteFence(
|
|
1804
|
+
String(targetNodeRid),
|
|
1805
|
+
String(targetSpotId)
|
|
1806
|
+
)
|
|
1807
|
+
: undefined
|
|
1808
|
+
);
|
|
1809
|
+
return this.backend.requestFromSpot(
|
|
1810
|
+
this.state,
|
|
1811
|
+
routeFence,
|
|
1812
|
+
parts,
|
|
1813
|
+
options?.timeoutMs ?? 30_000
|
|
1814
|
+
);
|
|
1815
|
+
}
|
|
1816
|
+
|
|
1817
|
+
async publish(
|
|
1818
|
+
channelName: string,
|
|
1819
|
+
topic: string,
|
|
1820
|
+
parts: MessageLike | readonly MessageLike[],
|
|
1821
|
+
options?: { readonly flags?: number }
|
|
1822
|
+
): Promise<void> {
|
|
1823
|
+
this.requireOpen();
|
|
1824
|
+
void options;
|
|
1825
|
+
await this.backend.publishFromSpot(this.state, channelName, topic, parts);
|
|
1826
|
+
}
|
|
1827
|
+
|
|
1828
|
+
setSubscription(channelName: string, topicFilter: string, kind = 0): void {
|
|
1829
|
+
this.requireOpen();
|
|
1830
|
+
if (kind !== 0) throw new RangeError('Only the default logical multicast subscription kind is supported.');
|
|
1831
|
+
this.backend.setSpotSubscription(this.state, channelName, topicFilter);
|
|
1832
|
+
this.subscriptions.add(`${channelName}\0${topicFilter}\0${kind}`);
|
|
1833
|
+
}
|
|
1834
|
+
|
|
1835
|
+
unsetSubscription(channelName: string, topicFilter: string, kind = 0): void {
|
|
1836
|
+
this.requireOpen();
|
|
1837
|
+
if (kind !== 0) throw new RangeError('Only the default logical multicast subscription kind is supported.');
|
|
1838
|
+
this.backend.unsetSpotSubscription(this.state, channelName, topicFilter);
|
|
1839
|
+
this.subscriptions.delete(`${channelName}\0${topicFilter}\0${kind}`);
|
|
1840
|
+
}
|
|
1841
|
+
|
|
1842
|
+
close(): void {
|
|
1843
|
+
if (this.closed) return;
|
|
1844
|
+
if (this.state.kind !== 'entry' && !this.backend.closeSpot(this.state)) {
|
|
1845
|
+
throw new Error(`Spot '${this.routingId}' still has Actor members.`);
|
|
1846
|
+
}
|
|
1847
|
+
this.backend.clearSpotSubscriptions(this.state);
|
|
1848
|
+
this.closed = true;
|
|
1849
|
+
this.subscriptions.clear();
|
|
1850
|
+
}
|
|
1851
|
+
|
|
1852
|
+
async dispose(): Promise<void> {
|
|
1853
|
+
this.close();
|
|
1854
|
+
}
|
|
1855
|
+
|
|
1856
|
+
private requireOpen(): void {
|
|
1857
|
+
if (this.closed) throw new Error(`Spot '${this.routingId}' is closed.`);
|
|
1858
|
+
}
|
|
1859
|
+
}
|
|
1860
|
+
|
|
1861
|
+
function requireDirectSpotRouteFence(
|
|
1862
|
+
route: ServiceDirectSpotRouteFence | undefined,
|
|
1863
|
+
targetNodeRid: string,
|
|
1864
|
+
targetSpotId: string,
|
|
1865
|
+
targetSpotGeneration: bigint,
|
|
1866
|
+
entryRoute: ServiceDirectSpotRouteFence | undefined
|
|
1867
|
+
): ServiceDirectSpotRouteFence {
|
|
1868
|
+
if (route === undefined && entryRoute !== undefined) {
|
|
1869
|
+
return entryRoute;
|
|
1870
|
+
}
|
|
1871
|
+
if (
|
|
1872
|
+
route === undefined
|
|
1873
|
+
|| route.targetNodeRid !== targetNodeRid
|
|
1874
|
+
|| route.spot.spotId !== targetSpotId
|
|
1875
|
+
|| route.spot.generation !== targetSpotGeneration
|
|
1876
|
+
) {
|
|
1877
|
+
throw new TypeError('Direct Spot submission requires the exact resolved authority fence.');
|
|
1878
|
+
}
|
|
1879
|
+
return route;
|
|
1880
|
+
}
|
|
1881
|
+
|
|
1882
|
+
function entrySpotFenceVersion(generation: bigint): string {
|
|
1883
|
+
return `entry:${generation}`;
|
|
1884
|
+
}
|
|
1885
|
+
|
|
1886
|
+
class RawStreamSessionService implements StreamSessionService {
|
|
1887
|
+
private state = 1;
|
|
1888
|
+
private closed = false;
|
|
1889
|
+
private readonly sessionTargets = new Map<string, RoutingId>();
|
|
1890
|
+
|
|
1891
|
+
constructor(
|
|
1892
|
+
private readonly stateful: ServiceStatefulRuntime,
|
|
1893
|
+
private readonly stream: StreamSocket,
|
|
1894
|
+
private readonly observe: (
|
|
1895
|
+
operationKind: number,
|
|
1896
|
+
pending: ServiceStatefulPendingOperation
|
|
1897
|
+
) => MeshOperationId
|
|
1898
|
+
) {}
|
|
1899
|
+
|
|
1900
|
+
start(): void {
|
|
1901
|
+
if (this.closed) throw new Error('STREAM session service is closed.');
|
|
1902
|
+
this.state = 2;
|
|
1903
|
+
}
|
|
1904
|
+
|
|
1905
|
+
shutdown(_timeoutMs: number): RequestResultValue {
|
|
1906
|
+
this.close();
|
|
1907
|
+
return RequestResult.Ok;
|
|
1908
|
+
}
|
|
1909
|
+
|
|
1910
|
+
close(): void {
|
|
1911
|
+
if (this.closed) return;
|
|
1912
|
+
this.closed = true;
|
|
1913
|
+
this.state = 5;
|
|
1914
|
+
this.sessionTargets.clear();
|
|
1915
|
+
}
|
|
1916
|
+
|
|
1917
|
+
status() {
|
|
1918
|
+
const bindings = this.stateful.allSessionBindings();
|
|
1919
|
+
return {
|
|
1920
|
+
state: this.state,
|
|
1921
|
+
lifecycleGeneration: 1n,
|
|
1922
|
+
sessionCount: BigInt(new Set(bindings.map(value => value.sessionRid)).size),
|
|
1923
|
+
bindingCount: BigInt(bindings.length),
|
|
1924
|
+
pendingMessageCount: 0n,
|
|
1925
|
+
pendingByteCount: 0n,
|
|
1926
|
+
lastError: 0
|
|
1927
|
+
};
|
|
1928
|
+
}
|
|
1929
|
+
|
|
1930
|
+
lookupActor(
|
|
1931
|
+
targetNodeRid: RoutingId,
|
|
1932
|
+
actorId: string,
|
|
1933
|
+
timeoutMs = 30_000
|
|
1934
|
+
): MeshOperationId {
|
|
1935
|
+
this.requireStarted();
|
|
1936
|
+
return this.observe(
|
|
1937
|
+
OperationKind.ActorLookup,
|
|
1938
|
+
this.stateful.lookupRemoteActor(String(targetNodeRid), actorId, timeoutMs)
|
|
1939
|
+
);
|
|
1940
|
+
}
|
|
1941
|
+
|
|
1942
|
+
bindActor(
|
|
1943
|
+
sessionRid: RoutingId,
|
|
1944
|
+
actor: ServiceActorRef,
|
|
1945
|
+
timeoutMs = 30_000,
|
|
1946
|
+
onBindingReplaced?: (
|
|
1947
|
+
actorId: string,
|
|
1948
|
+
retiredSession: ServiceRetiredBoundSessionRouteFence,
|
|
1949
|
+
actor: ServiceActorRef
|
|
1950
|
+
) => void,
|
|
1951
|
+
actorAuthority?: StreamSessionActorAuthorityFence
|
|
1952
|
+
): MeshOperationId {
|
|
1953
|
+
this.requireStarted();
|
|
1954
|
+
const sessionKey = String(sessionRid);
|
|
1955
|
+
this.sessionTargets.set(sessionKey, sessionRid);
|
|
1956
|
+
return this.observe(
|
|
1957
|
+
OperationKind.StreamBind,
|
|
1958
|
+
this.stateful.bindSession(
|
|
1959
|
+
sessionKey,
|
|
1960
|
+
actor,
|
|
1961
|
+
timeoutMs,
|
|
1962
|
+
(targetSessionRid, payloadFrame) => this.deliver(targetSessionRid, payloadFrame),
|
|
1963
|
+
onBindingReplaced,
|
|
1964
|
+
serviceSessionBindingIngressPortIfRegistered(this),
|
|
1965
|
+
actorAuthority
|
|
1966
|
+
)
|
|
1967
|
+
);
|
|
1968
|
+
}
|
|
1969
|
+
|
|
1970
|
+
unbindActor(
|
|
1971
|
+
sessionRid: RoutingId,
|
|
1972
|
+
actor: ServiceActorRef,
|
|
1973
|
+
expectedBindingGeneration: bigint,
|
|
1974
|
+
timeoutMs = 30_000
|
|
1975
|
+
): MeshOperationId {
|
|
1976
|
+
this.requireStarted();
|
|
1977
|
+
return this.observe(
|
|
1978
|
+
OperationKind.StreamUnbind,
|
|
1979
|
+
this.stateful.unbindSession(
|
|
1980
|
+
String(sessionRid),
|
|
1981
|
+
actor,
|
|
1982
|
+
expectedBindingGeneration,
|
|
1983
|
+
timeoutMs
|
|
1984
|
+
)
|
|
1985
|
+
);
|
|
1986
|
+
}
|
|
1987
|
+
|
|
1988
|
+
bindings(sessionRid: RoutingId) {
|
|
1989
|
+
return this.stateful.sessionBindings(String(sessionRid));
|
|
1990
|
+
}
|
|
1991
|
+
|
|
1992
|
+
async sendToActor(
|
|
1993
|
+
sessionRid: RoutingId,
|
|
1994
|
+
actor: ServiceActorRef,
|
|
1995
|
+
parts: MessageLike | readonly MessageLike[]
|
|
1996
|
+
): Promise<SubmitResultValue> {
|
|
1997
|
+
this.requireStarted();
|
|
1998
|
+
return await this.stateful.sendSessionToActor(
|
|
1999
|
+
String(sessionRid),
|
|
2000
|
+
actor,
|
|
2001
|
+
encodeMultipart(parts)
|
|
2002
|
+
) as SubmitResultValue;
|
|
2003
|
+
}
|
|
2004
|
+
|
|
2005
|
+
private async deliver(sessionRid: string, payload: Uint8Array): Promise<boolean> {
|
|
2006
|
+
const target = this.sessionTargets.get(sessionRid);
|
|
2007
|
+
if (target === undefined) return false;
|
|
2008
|
+
const operation = this.stream.send(target as unknown as BindingRoutingId);
|
|
2009
|
+
const parts = decodeMultipartBuffers(decodeApplicationPayloadView(payload).payload);
|
|
2010
|
+
if (parts.length === 0) return false;
|
|
2011
|
+
let submit = operation.message(parts[0]!);
|
|
2012
|
+
for (let index = 1; index < parts.length; index++) {
|
|
2013
|
+
submit = submit.message(parts[index]!);
|
|
2014
|
+
}
|
|
2015
|
+
try {
|
|
2016
|
+
await submit.submit();
|
|
2017
|
+
return true;
|
|
2018
|
+
} catch (error) {
|
|
2019
|
+
if (!(error instanceof SubmitError)) throw error;
|
|
2020
|
+
switch (error.result) {
|
|
2021
|
+
case SubmitResult.NotConnected:
|
|
2022
|
+
case SubmitResult.NotFound:
|
|
2023
|
+
case SubmitResult.Terminated:
|
|
2024
|
+
// Let the socket monitor drive the existing STREAM close/unbind
|
|
2025
|
+
// lifecycle instead of maintaining a second session-close state.
|
|
2026
|
+
disconnectStreamPeer(this.stream, target);
|
|
2027
|
+
throw new ZLinkBackendResultError(
|
|
2028
|
+
'submit',
|
|
2029
|
+
error.result,
|
|
2030
|
+
error.nativeErrno,
|
|
2031
|
+
{ cause: error }
|
|
2032
|
+
);
|
|
2033
|
+
case SubmitResult.Backpressured:
|
|
2034
|
+
case SubmitResult.NotAdmitted:
|
|
2035
|
+
throw new ZLinkBackendResultError(
|
|
2036
|
+
'submit',
|
|
2037
|
+
error.result,
|
|
2038
|
+
error.nativeErrno,
|
|
2039
|
+
{ cause: error }
|
|
2040
|
+
);
|
|
2041
|
+
default:
|
|
2042
|
+
throw error;
|
|
2043
|
+
}
|
|
2044
|
+
}
|
|
2045
|
+
}
|
|
2046
|
+
|
|
2047
|
+
private requireStarted(): void {
|
|
2048
|
+
if (this.state !== 2 || this.closed) {
|
|
2049
|
+
throw new Error('STREAM session service is not started.');
|
|
2050
|
+
}
|
|
2051
|
+
}
|
|
2052
|
+
}
|
|
2053
|
+
|
|
2054
|
+
class RawReadyBatch implements ReadyBatch {
|
|
2055
|
+
readonly records: ReadyRecord[] = [];
|
|
2056
|
+
private readonly claims: RawClaim[] = [];
|
|
2057
|
+
|
|
2058
|
+
constructor(private readonly capacity: number) {
|
|
2059
|
+
if (!Number.isInteger(capacity) || capacity < 1) throw new RangeError('Ready capacity must be positive.');
|
|
2060
|
+
}
|
|
2061
|
+
|
|
2062
|
+
get full(): boolean {
|
|
2063
|
+
return this.records.length >= this.capacity;
|
|
2064
|
+
}
|
|
2065
|
+
|
|
2066
|
+
push(record: ReadyRecord, claim: RawClaim): void {
|
|
2067
|
+
if (this.full) throw new Error('Ready batch is full.');
|
|
2068
|
+
this.records.push(record);
|
|
2069
|
+
this.claims.push(claim);
|
|
2070
|
+
}
|
|
2071
|
+
|
|
2072
|
+
takeClaim(index: number) {
|
|
2073
|
+
if (index < 0 || index >= this.claims.length) {
|
|
2074
|
+
throw new RangeError('Ready claim index is invalid.');
|
|
2075
|
+
}
|
|
2076
|
+
return this.claims[index]!;
|
|
2077
|
+
}
|
|
2078
|
+
|
|
2079
|
+
reset(): void {
|
|
2080
|
+
this.records.length = 0;
|
|
2081
|
+
this.claims.length = 0;
|
|
2082
|
+
}
|
|
2083
|
+
|
|
2084
|
+
close(): void {
|
|
2085
|
+
this.reset();
|
|
2086
|
+
}
|
|
2087
|
+
}
|
|
2088
|
+
|
|
2089
|
+
class RawReceiveBatch implements ReceiveBatch {
|
|
2090
|
+
constructor(
|
|
2091
|
+
readonly messageCapacity: number,
|
|
2092
|
+
readonly partCapacity: number
|
|
2093
|
+
) {
|
|
2094
|
+
if ([messageCapacity, partCapacity].some(value => !Number.isInteger(value) || value < 1)) {
|
|
2095
|
+
throw new RangeError('Receive batch capacities must be positive.');
|
|
2096
|
+
}
|
|
2097
|
+
}
|
|
2098
|
+
|
|
2099
|
+
reset(): void {}
|
|
2100
|
+
close(): void {}
|
|
2101
|
+
}
|
|
2102
|
+
|
|
2103
|
+
class MailboxClaim implements RawClaim {
|
|
2104
|
+
private consumed = false;
|
|
2105
|
+
private released = false;
|
|
2106
|
+
private remaining: ServiceMailboxRecord[] = [];
|
|
2107
|
+
|
|
2108
|
+
constructor(
|
|
2109
|
+
private readonly runtime: RawServiceMeshRuntime,
|
|
2110
|
+
private readonly claim: ServiceMailboxClaim,
|
|
2111
|
+
private readonly onRelease?: () => void
|
|
2112
|
+
) {}
|
|
2113
|
+
|
|
2114
|
+
recvBatch(batch: ReceiveBatch) {
|
|
2115
|
+
if (this.consumed) return { ok: false, records: [] };
|
|
2116
|
+
this.consumed = true;
|
|
2117
|
+
const capacity = batch as RawReceiveBatch;
|
|
2118
|
+
const records: ReceiveRecord[] = [];
|
|
2119
|
+
let parts = 0;
|
|
2120
|
+
for (let index = 0; index < this.claim.records.length; index += 1) {
|
|
2121
|
+
const record = this.claim.records[index]!;
|
|
2122
|
+
let decoded: ReceiveRecord;
|
|
2123
|
+
try {
|
|
2124
|
+
decoded = decodeMultipartRecord(this.runtime, record);
|
|
2125
|
+
} catch (error) {
|
|
2126
|
+
record.applicationJob?.close();
|
|
2127
|
+
if (error instanceof ServiceWireProtocolError) {
|
|
2128
|
+
this.runtime.mailbox.releaseClaimedPayload(record);
|
|
2129
|
+
continue;
|
|
2130
|
+
}
|
|
2131
|
+
this.runtime.mailbox.releaseClaimedPayload(record);
|
|
2132
|
+
this.remaining = this.claim.records.slice(index + 1);
|
|
2133
|
+
throw error;
|
|
2134
|
+
}
|
|
2135
|
+
const nextParts = decoded.parts.length;
|
|
2136
|
+
if (
|
|
2137
|
+
records.length >= capacity.messageCapacity
|
|
2138
|
+
|| parts + nextParts > capacity.partCapacity
|
|
2139
|
+
) {
|
|
2140
|
+
for (const part of decoded.parts) part.close();
|
|
2141
|
+
this.remaining = this.claim.records.slice(index);
|
|
2142
|
+
break;
|
|
2143
|
+
}
|
|
2144
|
+
parts += nextParts;
|
|
2145
|
+
records.push(decoded);
|
|
2146
|
+
this.runtime.mailbox.releaseClaimedPayload(record);
|
|
2147
|
+
}
|
|
2148
|
+
return { ok: records.length > 0, records };
|
|
2149
|
+
}
|
|
2150
|
+
|
|
2151
|
+
release(): void {
|
|
2152
|
+
if (this.released) return;
|
|
2153
|
+
this.released = true;
|
|
2154
|
+
this.runtime.mailbox.release(this.claim, this.remaining);
|
|
2155
|
+
this.onRelease?.();
|
|
2156
|
+
}
|
|
2157
|
+
}
|
|
2158
|
+
|
|
2159
|
+
class CompletionClaim implements RawClaim {
|
|
2160
|
+
private consumed = false;
|
|
2161
|
+
|
|
2162
|
+
constructor(private readonly completion: PendingCompletion) {}
|
|
2163
|
+
|
|
2164
|
+
recvBatch(): { readonly ok: boolean; readonly records: ReceiveRecord[] } {
|
|
2165
|
+
if (this.consumed) return { ok: false, records: [] };
|
|
2166
|
+
this.consumed = true;
|
|
2167
|
+
const payload = this.completion.result.payload;
|
|
2168
|
+
return {
|
|
2169
|
+
ok: true,
|
|
2170
|
+
records: [{
|
|
2171
|
+
kind: ReceiveKind.Completion,
|
|
2172
|
+
domain: ReadyDomain.Infrastructure,
|
|
2173
|
+
sourceNodeRid: null,
|
|
2174
|
+
sourceSpotId: null,
|
|
2175
|
+
sourceBindingGeneration: 0n,
|
|
2176
|
+
sourceActor: null,
|
|
2177
|
+
operationId: this.completion.operationId,
|
|
2178
|
+
operationKind: this.completion.operationKind,
|
|
2179
|
+
channelName: null,
|
|
2180
|
+
topic: null,
|
|
2181
|
+
applicationMetadata: null,
|
|
2182
|
+
kindData: 'kindData' in this.completion.result
|
|
2183
|
+
? this.completion.result.kindData ?? null
|
|
2184
|
+
: null,
|
|
2185
|
+
terminalResult: this.completion.result.terminalResult,
|
|
2186
|
+
failureErrno: this.completion.result.failureCode,
|
|
2187
|
+
parts: payload === undefined
|
|
2188
|
+
? []
|
|
2189
|
+
: payload.contentType === MULTIPART_CONTENT_TYPE
|
|
2190
|
+
? decodeMultipart(payload.payload)
|
|
2191
|
+
: [Message.from(payload.payload)],
|
|
2192
|
+
reply: () => SubmitResult.InvalidState,
|
|
2193
|
+
replyActorJoin: () => SubmitResult.NotSupported
|
|
2194
|
+
}]
|
|
2195
|
+
};
|
|
2196
|
+
}
|
|
2197
|
+
|
|
2198
|
+
release(): void {}
|
|
2199
|
+
}
|
|
2200
|
+
|
|
2201
|
+
function decodeMultipartRecord(
|
|
2202
|
+
runtime: RawServiceMeshRuntime,
|
|
2203
|
+
record: ServiceMailboxRecord
|
|
2204
|
+
): ReceiveRecord {
|
|
2205
|
+
const stateful = statefulMailboxData(record);
|
|
2206
|
+
if (stateful !== undefined) {
|
|
2207
|
+
return decodeStatefulRecord(record, stateful);
|
|
2208
|
+
}
|
|
2209
|
+
// RawServiceMeshRuntime admits the frozen relocation/session controls as
|
|
2210
|
+
// bare service-wire frames on the infrastructure mailbox. They are
|
|
2211
|
+
// node-owned infrastructure work, not an M6A application envelope, so do
|
|
2212
|
+
// not try to read `parts[1]` as an application payload frame here. The
|
|
2213
|
+
// host's relocation dispatcher decodes the canonical frame directly from
|
|
2214
|
+
// `parts[0]` and any trailing frames (e.g. a Prepare's bound-session
|
|
2215
|
+
// journal sideband, spec 28 §4.4) as its own node-internal ZLNI frames.
|
|
2216
|
+
// Application dispatch (Channel*/NodeSend/NodeRequest 16-19 envelopes)
|
|
2217
|
+
// always arrives on the application mailbox domain, so gating on
|
|
2218
|
+
// `record.domain` here — rather than solely on part count — keeps a
|
|
2219
|
+
// multi-frame infrastructure control (Prepare + sideband) from being
|
|
2220
|
+
// misread as a 2-frame application envelope and dropped as invalid_frame.
|
|
2221
|
+
if (record.parts.length === 1 || record.domain === 'infrastructure') {
|
|
2222
|
+
const request = record.requestSequence !== undefined
|
|
2223
|
+
&& record.sourceRoutingId !== undefined;
|
|
2224
|
+
return {
|
|
2225
|
+
kind: request ? ReceiveKind.NodeRequest : ReceiveKind.NodeSend,
|
|
2226
|
+
domain: readyDomain(record.domain),
|
|
2227
|
+
sourceNodeRid: record.sourceRoutingId as RoutingId | undefined ?? null,
|
|
2228
|
+
sourceSpotId: null,
|
|
2229
|
+
sourceBindingGeneration: 0n,
|
|
2230
|
+
sourceActor: null,
|
|
2231
|
+
operationId: { high: 0n, low: record.requestSequence ?? 0n },
|
|
2232
|
+
operationKind: request ? OperationKind.NodeRequest : 0,
|
|
2233
|
+
channelName: null,
|
|
2234
|
+
topic: null,
|
|
2235
|
+
applicationMetadata: null,
|
|
2236
|
+
packetName: undefined,
|
|
2237
|
+
contentType: undefined,
|
|
2238
|
+
kindData: null,
|
|
2239
|
+
terminalResult: 0,
|
|
2240
|
+
failureErrno: 0,
|
|
2241
|
+
...receiveIngressLifecycle(record),
|
|
2242
|
+
parts: record.parts.map(part => Message.from(part)),
|
|
2243
|
+
reply(parts) {
|
|
2244
|
+
if (!request) return SubmitResult.InvalidState;
|
|
2245
|
+
const values = Array.isArray(parts) ? parts : [parts];
|
|
2246
|
+
if (values.length === 0) return SubmitResult.InvalidState;
|
|
2247
|
+
runtime.replyService({
|
|
2248
|
+
sourceRoutingId: record.sourceRoutingId!,
|
|
2249
|
+
...(record.sourceRoute === undefined ? {} : { sourceRoute: record.sourceRoute }),
|
|
2250
|
+
requestSequence: record.requestSequence!,
|
|
2251
|
+
...(record.reply === undefined ? {} : { reply: record.reply })
|
|
2252
|
+
}, values.map(value => Buffer.from(messageBytesView(value))));
|
|
2253
|
+
return SubmitResult.Ok;
|
|
2254
|
+
},
|
|
2255
|
+
replyActorJoin: () => SubmitResult.NotSupported
|
|
2256
|
+
};
|
|
2257
|
+
}
|
|
2258
|
+
const header = record.parts[0]!;
|
|
2259
|
+
const command = header[3]!;
|
|
2260
|
+
const payloadFrame = record.parts[1]!;
|
|
2261
|
+
const application = decodeApplicationEnvelope(payloadFrame);
|
|
2262
|
+
const channelName = record.owner.startsWith('channel:') ? record.owner.slice('channel:'.length) : null;
|
|
2263
|
+
const operationId = record.correlation === undefined
|
|
2264
|
+
? { high: 0n, low: 0n }
|
|
2265
|
+
: { high: 1n, low: record.correlation };
|
|
2266
|
+
const kind = command === 16
|
|
2267
|
+
? ReceiveKind.NodeSend
|
|
2268
|
+
: command === 17
|
|
2269
|
+
? ReceiveKind.NodeRequest
|
|
2270
|
+
: command === 18
|
|
2271
|
+
? ReceiveKind.ChannelSend
|
|
2272
|
+
: ReceiveKind.ChannelRequest;
|
|
2273
|
+
const operationKind = kind === ReceiveKind.NodeRequest
|
|
2274
|
+
? OperationKind.NodeRequest
|
|
2275
|
+
: kind === ReceiveKind.ChannelRequest
|
|
2276
|
+
? OperationKind.ChannelRequest
|
|
2277
|
+
: 0;
|
|
2278
|
+
const ingressLifecycle = receiveIngressLifecycle(record);
|
|
2279
|
+
return {
|
|
2280
|
+
kind,
|
|
2281
|
+
domain: readyDomain(record.domain),
|
|
2282
|
+
sourceNodeRid: record.sourceRoutingId as RoutingId | undefined ?? null,
|
|
2283
|
+
sourceSpotId: null,
|
|
2284
|
+
sourceBindingGeneration: 0n,
|
|
2285
|
+
sourceActor: null,
|
|
2286
|
+
operationId,
|
|
2287
|
+
operationKind,
|
|
2288
|
+
channelName,
|
|
2289
|
+
topic: null,
|
|
2290
|
+
applicationMetadata: null,
|
|
2291
|
+
packetName: application.packetName,
|
|
2292
|
+
contentType: application.contentType,
|
|
2293
|
+
kindData: null,
|
|
2294
|
+
terminalResult: 0,
|
|
2295
|
+
failureErrno: 0,
|
|
2296
|
+
...ingressLifecycle,
|
|
2297
|
+
parts: decodeMultipart(application.payload),
|
|
2298
|
+
reply(parts) {
|
|
2299
|
+
if (record.correlation === undefined) return SubmitResult.InvalidState;
|
|
2300
|
+
runtime.reply(record, encodeMultipart(parts));
|
|
2301
|
+
return SubmitResult.Ok;
|
|
2302
|
+
},
|
|
2303
|
+
replyActorJoin: () => SubmitResult.NotSupported
|
|
2304
|
+
};
|
|
2305
|
+
}
|
|
2306
|
+
|
|
2307
|
+
function decodeStatefulRecord(
|
|
2308
|
+
record: ServiceMailboxRecord,
|
|
2309
|
+
stateful: ServiceStatefulMailboxData
|
|
2310
|
+
): ReceiveRecord {
|
|
2311
|
+
const payloadFrame = record.parts.length < 2 ? undefined : record.parts[1];
|
|
2312
|
+
const canonicalActorJoin = stateful.kindData?.kind === 'actorControl'
|
|
2313
|
+
&& stateful.kindData.canonicalActorJoin !== undefined;
|
|
2314
|
+
const canonicalActorJoinPayload = stateful.operationKind === OperationKind.ActorJoin
|
|
2315
|
+
&& stateful.canonicalApplicationPayload !== undefined;
|
|
2316
|
+
const application = canonicalActorJoinPayload
|
|
2317
|
+
? stateful.canonicalApplicationPayload
|
|
2318
|
+
: (payloadFrame === undefined ? undefined : decodeApplicationEnvelope(payloadFrame));
|
|
2319
|
+
const operationId = record.correlation === undefined
|
|
2320
|
+
? { high: 0n, low: 0n }
|
|
2321
|
+
: { high: 2n, low: record.correlation };
|
|
2322
|
+
const ingressLifecycle = receiveIngressLifecycle(record);
|
|
2323
|
+
return {
|
|
2324
|
+
kind: stateful.receiveKind,
|
|
2325
|
+
domain: readyDomain(record.domain),
|
|
2326
|
+
sourceNodeRid: record.sourceRoutingId as RoutingId | undefined ?? null,
|
|
2327
|
+
sourceSpotId: stateful.sourceSpotId as RoutingId | undefined ?? null,
|
|
2328
|
+
sourceBindingGeneration: stateful.sourceBindingGeneration ?? 0n,
|
|
2329
|
+
sourceActor: stateful.sourceActor ?? null,
|
|
2330
|
+
operationId,
|
|
2331
|
+
operationKind: stateful.operationKind,
|
|
2332
|
+
channelName: stateful.channelName ?? null,
|
|
2333
|
+
topic: stateful.topic ?? null,
|
|
2334
|
+
applicationMetadata: stateful.applicationMetadata ?? null,
|
|
2335
|
+
...(application === undefined
|
|
2336
|
+
? {}
|
|
2337
|
+
: {
|
|
2338
|
+
packetName: application.packetName,
|
|
2339
|
+
contentType: application.contentType
|
|
2340
|
+
}),
|
|
2341
|
+
kindData: stateful.kindData ?? null,
|
|
2342
|
+
terminalResult: 0,
|
|
2343
|
+
failureErrno: 0,
|
|
2344
|
+
...ingressLifecycle,
|
|
2345
|
+
parts: application === undefined
|
|
2346
|
+
? []
|
|
2347
|
+
: canonicalActorJoinPayload
|
|
2348
|
+
? [Message.from(application.payload)]
|
|
2349
|
+
: decodeMultipart(application.payload),
|
|
2350
|
+
...(stateful.isPending === undefined ? {} : { isPending: stateful.isPending }),
|
|
2351
|
+
...(stateful.deadlineUnixMs === undefined ? {} : { deadlineUnixMs: stateful.deadlineUnixMs }),
|
|
2352
|
+
...(stateful.messageFollowOrigin === undefined
|
|
2353
|
+
? {}
|
|
2354
|
+
: { messageFollowOrigin: stateful.messageFollowOrigin }),
|
|
2355
|
+
...(stateful.onTerminalCompletion === undefined
|
|
2356
|
+
? {}
|
|
2357
|
+
: { onTerminalCompletion: stateful.onTerminalCompletion }),
|
|
2358
|
+
reply(parts) {
|
|
2359
|
+
if (stateful.reply === undefined) return SubmitResult.InvalidState;
|
|
2360
|
+
return stateful.reply(
|
|
2361
|
+
RequestResult.Ok,
|
|
2362
|
+
0,
|
|
2363
|
+
encodeMultipart(parts)
|
|
2364
|
+
) ? SubmitResult.Ok : SubmitResult.InvalidState;
|
|
2365
|
+
},
|
|
2366
|
+
replyActorJoin(joinResult, parts, _flags, _replyContentType) {
|
|
2367
|
+
if (stateful.reply === undefined || stateful.targetSpot === undefined) {
|
|
2368
|
+
return SubmitResult.InvalidState;
|
|
2369
|
+
}
|
|
2370
|
+
const membershipEpoch = stateful.kindData?.kind === 'actorControl'
|
|
2371
|
+
? stateful.kindData.currentMembershipEpoch
|
|
2372
|
+
: undefined;
|
|
2373
|
+
if (joinResult === 0 && membershipEpoch === undefined) {
|
|
2374
|
+
return SubmitResult.InvalidState;
|
|
2375
|
+
}
|
|
2376
|
+
const replyParts = Array.isArray(parts) ? parts : [parts];
|
|
2377
|
+
if (canonicalActorJoin && replyParts.length > 1) {
|
|
2378
|
+
return SubmitResult.InvalidState;
|
|
2379
|
+
}
|
|
2380
|
+
const replyPayload = replyParts.length === 0
|
|
2381
|
+
? undefined
|
|
2382
|
+
: encodeMultipart(replyParts);
|
|
2383
|
+
const accepted = stateful.reply(
|
|
2384
|
+
RequestResult.Ok,
|
|
2385
|
+
0,
|
|
2386
|
+
replyPayload,
|
|
2387
|
+
{
|
|
2388
|
+
kind: 'actorJoin',
|
|
2389
|
+
joinResult: joinResult === 0 ? 0 : 1,
|
|
2390
|
+
spot: stateful.targetSpot,
|
|
2391
|
+
...(membershipEpoch === undefined ? {} : { membershipEpoch }),
|
|
2392
|
+
// Spec 15 §4.2: the accepted admission reply carries the target's
|
|
2393
|
+
// valid receive chunk cap for this join's relocation state chunks —
|
|
2394
|
+
// a conservative, recompute-stable bound (never lowered).
|
|
2395
|
+
...(joinResult === 0
|
|
2396
|
+
? { receiveChunkLimitBytes: ACTOR_JOIN_ADVERTISED_RECEIVE_CHUNK_LIMIT_BYTES }
|
|
2397
|
+
: {})
|
|
2398
|
+
}
|
|
2399
|
+
);
|
|
2400
|
+
return accepted ? SubmitResult.Ok : SubmitResult.InvalidState;
|
|
2401
|
+
},
|
|
2402
|
+
replyFailure(terminalResult, failureCode) {
|
|
2403
|
+
if (stateful.reply === undefined) return SubmitResult.InvalidState;
|
|
2404
|
+
return stateful.reply(terminalResult, failureCode)
|
|
2405
|
+
? SubmitResult.Ok
|
|
2406
|
+
: SubmitResult.InvalidState;
|
|
2407
|
+
}
|
|
2408
|
+
};
|
|
2409
|
+
}
|
|
2410
|
+
|
|
2411
|
+
function receiveIngressLifecycle(record: ServiceMailboxRecord): {
|
|
2412
|
+
readonly applicationJobPermit?: import('../../application-jobs/contracts').ApplicationJobPermitPort;
|
|
2413
|
+
readonly releaseRetainedIngress?: () => void;
|
|
2414
|
+
} {
|
|
2415
|
+
const applicationJob = record.applicationJob;
|
|
2416
|
+
return applicationJob === undefined
|
|
2417
|
+
? {}
|
|
2418
|
+
: {
|
|
2419
|
+
applicationJobPermit: applicationJob,
|
|
2420
|
+
releaseRetainedIngress: () => applicationJob.close()
|
|
2421
|
+
};
|
|
2422
|
+
}
|
|
2423
|
+
|
|
2424
|
+
function readyOwner(
|
|
2425
|
+
owner: string,
|
|
2426
|
+
nodeRid: string,
|
|
2427
|
+
stateful: ServiceStatefulRuntime | undefined,
|
|
2428
|
+
domain: ServiceMailboxDomain
|
|
2429
|
+
): ReadyRecord {
|
|
2430
|
+
if (owner.startsWith('spot:')) {
|
|
2431
|
+
return {
|
|
2432
|
+
ownerKind: ReadyOwnerKind.Spot,
|
|
2433
|
+
domain: readyDomain(domain),
|
|
2434
|
+
ordinaryIngressPreAdmitted: domain === 'application',
|
|
2435
|
+
spotId: owner.slice('spot:'.length),
|
|
2436
|
+
actor: null
|
|
2437
|
+
};
|
|
2438
|
+
}
|
|
2439
|
+
if (owner.startsWith('actor:')) {
|
|
2440
|
+
const separator = owner.indexOf('\0', 'actor:'.length);
|
|
2441
|
+
const actorId = separator < 0
|
|
2442
|
+
? owner.slice('actor:'.length)
|
|
2443
|
+
: owner.slice('actor:'.length, separator);
|
|
2444
|
+
const generation = separator < 0 ? 0n : BigInt(owner.slice(separator + 1));
|
|
2445
|
+
const current = stateful?.actor(actorId);
|
|
2446
|
+
return {
|
|
2447
|
+
ownerKind: ReadyOwnerKind.Actor,
|
|
2448
|
+
domain: readyDomain(domain),
|
|
2449
|
+
ordinaryIngressPreAdmitted: domain === 'application',
|
|
2450
|
+
spotId: current?.spot.spotId ?? null,
|
|
2451
|
+
actor: current?.ref ?? {
|
|
2452
|
+
nodeRid,
|
|
2453
|
+
actorId,
|
|
2454
|
+
generation
|
|
2455
|
+
}
|
|
2456
|
+
};
|
|
2457
|
+
}
|
|
2458
|
+
return {
|
|
2459
|
+
ownerKind: ReadyOwnerKind.Node,
|
|
2460
|
+
domain: readyDomain(domain),
|
|
2461
|
+
ordinaryIngressPreAdmitted: domain === 'application',
|
|
2462
|
+
spotId: null,
|
|
2463
|
+
actor: null
|
|
2464
|
+
};
|
|
2465
|
+
}
|
|
2466
|
+
|
|
2467
|
+
function readyDomain(domain: ServiceMailboxDomain): number {
|
|
2468
|
+
return domain === 'infrastructure'
|
|
2469
|
+
? ReadyDomain.Infrastructure
|
|
2470
|
+
: ReadyDomain.Application;
|
|
2471
|
+
}
|
|
2472
|
+
|
|
2473
|
+
/**
|
|
2474
|
+
* Classifies a generic node/channel request rejection into a completion
|
|
2475
|
+
* terminal. Spec 32-framework-error-model:91-92 — a reply that could not be
|
|
2476
|
+
* decoded (ServiceWireProtocolError from the reply parser) is a protocol
|
|
2477
|
+
* failure, not connection loss; only genuine transport rejections collapse to
|
|
2478
|
+
* NotConnected.
|
|
2479
|
+
*/
|
|
2480
|
+
export function genericOperationFailure(error: unknown): RawServiceRequestResult {
|
|
2481
|
+
// requestProtocolError(16): the schema terminal-failure-integrity rule
|
|
2482
|
+
// forbids a typed terminal (104) with failure none, so the synthesized
|
|
2483
|
+
// decode-failure pair is 104+16; genuine transport loss stays 109+0.
|
|
2484
|
+
return error instanceof ServiceWireProtocolError
|
|
2485
|
+
? { terminalResult: RequestResult.ProtocolError, failureCode: 16 }
|
|
2486
|
+
: { terminalResult: RequestResult.NotConnected, failureCode: 0 };
|
|
2487
|
+
}
|
|
2488
|
+
|
|
2489
|
+
function statefulOperationFailure(error: unknown): RawServiceRequestResult {
|
|
2490
|
+
if (error instanceof ZLinkFrameworkException) {
|
|
2491
|
+
return internalFrameworkWireReply(error);
|
|
2492
|
+
}
|
|
2493
|
+
if (error instanceof OperationTimeoutError) {
|
|
2494
|
+
return { terminalResult: RequestResult.TimedOut, failureCode: 0 };
|
|
2495
|
+
}
|
|
2496
|
+
if (isZLinkBackendResultError(error)) {
|
|
2497
|
+
return {
|
|
2498
|
+
terminalResult: error.result,
|
|
2499
|
+
failureCode: error.nativeErrno ?? 0
|
|
2500
|
+
};
|
|
2501
|
+
}
|
|
2502
|
+
if (error instanceof OperationCancelledError) {
|
|
2503
|
+
return { terminalResult: RequestResult.NotConnected, failureCode: 0 };
|
|
2504
|
+
}
|
|
2505
|
+
return { terminalResult: RequestResult.InternalError, failureCode: 17 };
|
|
2506
|
+
}
|
|
2507
|
+
|
|
2508
|
+
function encodeMultipart(parts: MessageLike | readonly MessageLike[]) {
|
|
2509
|
+
const values = Array.isArray(parts) ? parts : [parts];
|
|
2510
|
+
if (values.length === 0) throw new TypeError('Multipart payload must contain at least one part.');
|
|
2511
|
+
// messageBytesView aliases the caller's buffer; the parts are consumed
|
|
2512
|
+
// synchronously by the copy loop below and never retained.
|
|
2513
|
+
const bytes = values.map(messageBytesView);
|
|
2514
|
+
let size = 4;
|
|
2515
|
+
for (const part of bytes) size += 4 + part.byteLength;
|
|
2516
|
+
const payload = Buffer.alloc(size);
|
|
2517
|
+
payload.writeUInt32BE(bytes.length, 0);
|
|
2518
|
+
let offset = 4;
|
|
2519
|
+
for (const part of bytes) {
|
|
2520
|
+
payload.writeUInt32BE(part.byteLength, offset);
|
|
2521
|
+
offset += 4;
|
|
2522
|
+
payload.set(part, offset);
|
|
2523
|
+
offset += part.byteLength;
|
|
2524
|
+
}
|
|
2525
|
+
return {
|
|
2526
|
+
packetName: MULTIPART_PACKET_NAME,
|
|
2527
|
+
contentType: MULTIPART_CONTENT_TYPE,
|
|
2528
|
+
payload
|
|
2529
|
+
};
|
|
2530
|
+
}
|
|
2531
|
+
|
|
2532
|
+
function encodeMultipartApplicationFrame(
|
|
2533
|
+
parts: MessageLike | readonly MessageLike[]
|
|
2534
|
+
): Buffer {
|
|
2535
|
+
const values = Array.isArray(parts) ? parts : [parts];
|
|
2536
|
+
if (values.length === 0) throw new TypeError('Multipart payload must contain at least one part.');
|
|
2537
|
+
return encodeMultipartApplicationPayload(
|
|
2538
|
+
values.map(messageBytesView),
|
|
2539
|
+
MULTIPART_PACKET_NAME,
|
|
2540
|
+
MULTIPART_CONTENT_TYPE
|
|
2541
|
+
);
|
|
2542
|
+
}
|
|
2543
|
+
|
|
2544
|
+
function decodeApplicationEnvelope(frame: Uint8Array) {
|
|
2545
|
+
const bytes = Buffer.from(frame.buffer, frame.byteOffset, frame.byteLength);
|
|
2546
|
+
if (bytes.length < 11 || bytes[0] !== 1) {
|
|
2547
|
+
throw new ServiceWireProtocolError('Invalid application envelope.');
|
|
2548
|
+
}
|
|
2549
|
+
const bodyLength = bytes.readUInt32BE(1);
|
|
2550
|
+
if (bodyLength !== bytes.length - 5) {
|
|
2551
|
+
throw new ServiceWireProtocolError('Invalid application envelope length.');
|
|
2552
|
+
}
|
|
2553
|
+
let offset = 5;
|
|
2554
|
+
const packetLength = bytes[offset++]!;
|
|
2555
|
+
if (packetLength === 0 || bytes.length - offset < packetLength + 1) {
|
|
2556
|
+
throw new ServiceWireProtocolError('Invalid application envelope packet name.');
|
|
2557
|
+
}
|
|
2558
|
+
let packetName: string;
|
|
2559
|
+
try {
|
|
2560
|
+
packetName = FATAL_UTF8.decode(bytes.subarray(offset, offset + packetLength));
|
|
2561
|
+
} catch {
|
|
2562
|
+
throw new ServiceWireProtocolError('Invalid application envelope packet name.');
|
|
2563
|
+
}
|
|
2564
|
+
offset += packetLength;
|
|
2565
|
+
const contentLength = bytes[offset++]!;
|
|
2566
|
+
if (contentLength === 0 || bytes.length - offset < contentLength + 4) {
|
|
2567
|
+
throw new ServiceWireProtocolError('Invalid application envelope content type.');
|
|
2568
|
+
}
|
|
2569
|
+
let contentType: string;
|
|
2570
|
+
try {
|
|
2571
|
+
contentType = FATAL_UTF8.decode(bytes.subarray(offset, offset + contentLength));
|
|
2572
|
+
} catch {
|
|
2573
|
+
throw new ServiceWireProtocolError('Invalid application envelope content type.');
|
|
2574
|
+
}
|
|
2575
|
+
offset += contentLength;
|
|
2576
|
+
const payloadLength = bytes.readUInt32BE(offset);
|
|
2577
|
+
offset += 4;
|
|
2578
|
+
if (
|
|
2579
|
+
packetName !== MULTIPART_PACKET_NAME
|
|
2580
|
+
|| contentType !== MULTIPART_CONTENT_TYPE
|
|
2581
|
+
|| payloadLength !== bytes.length - offset
|
|
2582
|
+
) {
|
|
2583
|
+
throw new ServiceWireProtocolError('Unexpected M6A application payload.');
|
|
2584
|
+
}
|
|
2585
|
+
return { packetName, contentType, payload: bytes.subarray(offset) };
|
|
2586
|
+
}
|
|
2587
|
+
|
|
2588
|
+
function decodeMultipart(payload: Uint8Array): Message[] {
|
|
2589
|
+
const buffers = decodeMultipartBuffers(payload);
|
|
2590
|
+
return buffers.map(part => Message.from(part));
|
|
2591
|
+
}
|
|
2592
|
+
|
|
2593
|
+
function decodeMultipartBuffers(payload: Uint8Array): Buffer[] {
|
|
2594
|
+
const bytes = Buffer.from(payload.buffer, payload.byteOffset, payload.byteLength);
|
|
2595
|
+
if (bytes.length < 4) throw new ServiceWireProtocolError('Truncated multipart payload.');
|
|
2596
|
+
const count = bytes.readUInt32BE(0);
|
|
2597
|
+
if (count === 0 || count > Math.floor((bytes.length - 4) / 4)) {
|
|
2598
|
+
throw new ServiceWireProtocolError('Invalid multipart part count.');
|
|
2599
|
+
}
|
|
2600
|
+
const result = new Array<Buffer>(count);
|
|
2601
|
+
let offset = 4;
|
|
2602
|
+
for (let index = 0; index < count; index++) {
|
|
2603
|
+
if (bytes.length - offset < 4) {
|
|
2604
|
+
throw new ServiceWireProtocolError('Truncated multipart part length.');
|
|
2605
|
+
}
|
|
2606
|
+
const length = bytes.readUInt32BE(offset);
|
|
2607
|
+
offset += 4;
|
|
2608
|
+
if (bytes.length - offset < length) {
|
|
2609
|
+
throw new ServiceWireProtocolError('Truncated multipart part.');
|
|
2610
|
+
}
|
|
2611
|
+
result[index] = bytes.subarray(offset, offset + length);
|
|
2612
|
+
offset += length;
|
|
2613
|
+
}
|
|
2614
|
+
if (offset !== bytes.length) {
|
|
2615
|
+
throw new ServiceWireProtocolError('Multipart payload has trailing bytes.');
|
|
2616
|
+
}
|
|
2617
|
+
return result;
|
|
2618
|
+
}
|
|
2619
|
+
|
|
2620
|
+
function messageBytesView(value: MessageLike): Uint8Array {
|
|
2621
|
+
if (typeof value === 'object' && 'data' in value) {
|
|
2622
|
+
return value.data();
|
|
2623
|
+
}
|
|
2624
|
+
if (typeof value === 'string') return Buffer.from(value);
|
|
2625
|
+
return value;
|
|
2626
|
+
}
|
|
2627
|
+
|
|
2628
|
+
function requireRawReadyBatch(batch: ReadyBatch): RawReadyBatch {
|
|
2629
|
+
if (!(batch instanceof RawReadyBatch)) throw new TypeError('Ready batch belongs to another backend.');
|
|
2630
|
+
return batch;
|
|
2631
|
+
}
|
|
2632
|
+
|
|
2633
|
+
function stateCode(state: ServiceNodeDescriptor['state']): number {
|
|
2634
|
+
return ['preparing', 'serving', 'retiring', 'draining', 'stopped', 'error'].indexOf(state) + 1;
|
|
2635
|
+
}
|
|
2636
|
+
|
|
2637
|
+
function peerStateCode(state: ServiceNodeDescriptor['state']): number {
|
|
2638
|
+
switch (state) {
|
|
2639
|
+
case 'preparing': return 2;
|
|
2640
|
+
case 'serving':
|
|
2641
|
+
case 'retiring': return 3;
|
|
2642
|
+
case 'draining': return 4;
|
|
2643
|
+
case 'stopped':
|
|
2644
|
+
case 'error': return 5;
|
|
2645
|
+
}
|
|
2646
|
+
}
|
|
2647
|
+
|
|
2648
|
+
function createLifecycleGeneration(): bigint {
|
|
2649
|
+
// Node's public Spot context exposes this lifecycle token as a number. Keep
|
|
2650
|
+
// the opaque equality token within the exact range that surface can carry;
|
|
2651
|
+
// lifecycle ordering is never inferred from its numeric value.
|
|
2652
|
+
const generation = randomBytes(8).readBigUInt64BE()
|
|
2653
|
+
& BigInt(Number.MAX_SAFE_INTEGER);
|
|
2654
|
+
return generation === 0n ? 1n : generation;
|
|
2655
|
+
}
|
|
2656
|
+
|
|
2657
|
+
function requirePositivePlacementValue(value: number, name: string): number {
|
|
2658
|
+
if (!Number.isSafeInteger(value) || value <= 0 || value > 0x7fff_ffff) {
|
|
2659
|
+
throw new RangeError(`${name} must be an integer in 1..2147483647.`);
|
|
2660
|
+
}
|
|
2661
|
+
return value;
|
|
2662
|
+
}
|
|
2663
|
+
|
|
2664
|
+
function requirePublicWeight(value: number, name: string): number {
|
|
2665
|
+
if (!Number.isInteger(value) || value < 0 || value > 10_000) {
|
|
2666
|
+
throw new RangeError(`${name} must be an integer in 0..10000.`);
|
|
2667
|
+
}
|
|
2668
|
+
return value;
|
|
2669
|
+
}
|