@zlink-systems/framework 0.29.1 → 0.30.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +150 -68
- package/dist/.tsbuildinfo +1 -1
- package/dist/contracts/Actors/ZLinkActorClient.d.ts +2 -1
- package/dist/contracts/Channels/Calls.d.ts +2 -1
- package/dist/contracts/Common/ZLinkMessageMetadata.js +11 -5
- package/dist/contracts/Configuration/Builders.d.ts +1 -2
- package/dist/contracts/Configuration/Configs.d.ts +0 -5
- package/dist/contracts/Configuration/RegistrationBuilders.js +6 -4
- package/dist/contracts/Configuration/RegistrationTypes.d.ts +1 -6
- package/dist/contracts/Configuration/RegistrationValidators.js +4 -4
- package/dist/contracts/Configuration/index.d.ts +1 -1
- package/dist/contracts/Handlers/Attributes.d.ts +5 -13
- package/dist/contracts/Handlers/Attributes.js +7 -11
- package/dist/contracts/Handlers/JsonContract.d.ts +2 -46
- package/dist/contracts/Handlers/JsonContract.js +4 -153
- package/dist/contracts/Spots/Contracts.d.ts +2 -1
- package/dist/internal.d.ts +1 -0
- package/dist/internal.js +3 -1
- package/dist/nest-integration.d.ts +1 -1
- package/dist/nest-integration.js +2 -1
- package/dist/runtime/actors/actor-client.d.ts +1 -1
- package/dist/runtime/actors/actor-client.js +14 -12
- package/dist/runtime/actors/actor-handoff.d.ts +3 -2
- package/dist/runtime/actors/actor-handoff.js +15 -7
- package/dist/runtime/actors/actor-join-relocation.d.ts +1 -0
- package/dist/runtime/actors/actor-local-native-join.js +9 -12
- package/dist/runtime/actors/actor-remote-wire.js +15 -0
- package/dist/runtime/actors/actor-routed-join-transport.d.ts +6 -2
- package/dist/runtime/actors/actor-routed-json-request.d.ts +2 -0
- package/dist/runtime/actors/index.d.ts +2 -1
- package/dist/runtime/actors/index.js +18 -6
- package/dist/runtime/actors/spot-actor-dispatch.js +2 -2
- package/dist/runtime/admission.d.ts +1 -1
- package/dist/runtime/admission.js +15 -5
- package/dist/runtime/application-jobs/application-ingress-record-owner.d.ts +9 -9
- package/dist/runtime/application-jobs/application-ingress-record-owner.js +45 -23
- package/dist/runtime/application-jobs/application-job-queue-scope.d.ts +5 -2
- package/dist/runtime/application-jobs/application-job-queue-scope.js +41 -21
- package/dist/runtime/application-jobs/contracts.d.ts +15 -2
- package/dist/runtime/backend/contracts/index.d.ts +27 -27
- package/dist/runtime/backend/mesh-completion-table.d.ts +15 -5
- package/dist/runtime/backend/mesh-completion-table.js +160 -50
- package/dist/runtime/backend/mesh-dispatch-pump.d.ts +3 -0
- package/dist/runtime/backend/mesh-dispatch-pump.js +53 -36
- package/dist/runtime/backend/node/node-backend-adapter-factory.js +6 -1
- package/dist/runtime/backend/node/node-backend-adapter-support.d.ts +3 -3
- package/dist/runtime/backend/node/node-backend-adapter-support.js +33 -31
- package/dist/runtime/backend/node/node-dealer-channel-client-transport.d.ts +1 -1
- package/dist/runtime/backend/node/node-dealer-channel-client-transport.js +5 -2
- package/dist/runtime/backend/node/node-mesh-backend-adapter.d.ts +1 -9
- package/dist/runtime/backend/node/node-mesh-backend-adapter.js +1 -1
- package/dist/runtime/backend/node/node-raw-binding-port.js +50 -25
- package/dist/runtime/backend/node/node-raw-mesh-backend.d.ts +22 -16
- package/dist/runtime/backend/node/node-raw-mesh-backend.js +133 -149
- package/dist/runtime/backend/node/node-socket-backend-adapter.js +15 -10
- package/dist/runtime/backend/raw-binding-port.d.ts +10 -3
- package/dist/runtime/backend/runtime-message.d.ts +1 -0
- package/dist/runtime/backend/runtime-message.js +5 -0
- package/dist/runtime/backend/runtime-values.d.ts +1 -0
- package/dist/runtime/backend/runtime-values.js +2 -1
- package/dist/runtime/channels/channel-clients.d.ts +1 -0
- package/dist/runtime/channels/channel-clients.js +58 -21
- package/dist/runtime/channels/channel-dispatch-pipeline.d.ts +3 -2
- package/dist/runtime/channels/channel-dispatch-pipeline.js +20 -11
- package/dist/runtime/channels/channel-dispatch-services.d.ts +1 -0
- package/dist/runtime/channels/channel-dispatch-services.js +45 -0
- package/dist/runtime/channels/channel-dispatchers.d.ts +1 -1
- package/dist/runtime/channels/channel-dispatchers.js +27 -26
- package/dist/runtime/channels/channel-envelope-inspection.d.ts +1 -2
- package/dist/runtime/channels/channel-envelope-inspection.js +1 -16
- package/dist/runtime/channels/channel-envelope.d.ts +1 -0
- package/dist/runtime/channels/channel-envelope.js +83 -8
- package/dist/runtime/channels/channel-outbound-operations.d.ts +2 -2
- package/dist/runtime/channels/channel-outbound-operations.js +8 -8
- package/dist/runtime/channels/channel-receive-loops.js +3 -3
- package/dist/runtime/channels/channel-runtime-lifecycle.js +2 -1
- package/dist/runtime/channels/channel-runtime-manager.d.ts +6 -6
- package/dist/runtime/channels/channel-runtime-manager.js +12 -12
- package/dist/runtime/channels/channel-socket-registry.d.ts +10 -3
- package/dist/runtime/channels/channel-socket-registry.js +59 -82
- package/dist/runtime/channels/channel-transports.d.ts +18 -15
- package/dist/runtime/channels/channel-transports.js +48 -31
- package/dist/runtime/channels/local-spot-route-transport.d.ts +1 -1
- package/dist/runtime/channels/local-spot-route-transport.js +2 -1
- package/dist/runtime/channels/router-socket-spot-route-transport.d.ts +2 -2
- package/dist/runtime/channels/router-socket-spot-route-transport.js +4 -4
- package/dist/runtime/channels/source-spot-router.d.ts +2 -2
- package/dist/runtime/channels/source-spot-router.js +4 -4
- package/dist/runtime/channels/spot-node-route-transport.d.ts +2 -2
- package/dist/runtime/channels/spot-node-route-transport.js +4 -4
- package/dist/runtime/channels/spot-route-bridge-transport.d.ts +2 -2
- package/dist/runtime/channels/spot-route-bridge-transport.js +4 -4
- package/dist/runtime/channels/spot-route-dispatch-strategy.d.ts +5 -4
- package/dist/runtime/channels/spot-route-dispatch-strategy.js +18 -18
- package/dist/runtime/diagnostics/message-flow.d.ts +1 -0
- package/dist/runtime/diagnostics/message-flow.js +3 -3
- package/dist/runtime/execution/serial-execution-queue.d.ts +1 -0
- package/dist/runtime/execution/serial-execution-queue.js +1 -0
- package/dist/runtime/foundation/actor-join-recovery-codec.js +2 -2
- package/dist/runtime/foundation/durable-service-request.d.ts +14 -0
- package/dist/runtime/foundation/durable-service-request.js +98 -0
- package/dist/runtime/foundation/operation-identity.d.ts +1 -0
- package/dist/runtime/foundation/operation-identity.js +5 -1
- package/dist/runtime/foundation/raw-service-mesh-runtime.d.ts +37 -6
- package/dist/runtime/foundation/raw-service-mesh-runtime.js +473 -220
- package/dist/runtime/foundation/service-liveness-registry.d.ts +20 -8
- package/dist/runtime/foundation/service-liveness-registry.js +57 -44
- package/dist/runtime/foundation/service-mailbox.d.ts +3 -0
- package/dist/runtime/foundation/service-mailbox.js +2 -1
- package/dist/runtime/foundation/service-relocation-object-owner.d.ts +1 -0
- package/dist/runtime/foundation/service-relocation-object-owner.js +1 -0
- package/dist/runtime/foundation/service-relocation-runtime.d.ts +2 -0
- package/dist/runtime/foundation/service-relocation-runtime.js +13 -1
- package/dist/runtime/foundation/service-runtime-contracts.d.ts +2 -0
- package/dist/runtime/foundation/service-stateful-runtime.d.ts +10 -9
- package/dist/runtime/foundation/service-stateful-runtime.js +78 -126
- package/dist/runtime/foundation/service-stateful-wire-codec.d.ts +5 -7
- package/dist/runtime/foundation/service-stateful-wire-codec.js +43 -61
- package/dist/runtime/foundation/service-topology-registry.d.ts +16 -4
- package/dist/runtime/foundation/service-topology-registry.js +69 -30
- package/dist/runtime/foundation/service-wire-m6a-codec.d.ts +3 -3
- package/dist/runtime/foundation/service-wire-m6a-codec.js +36 -38
- package/dist/runtime/handlers/handler-instance-scope.d.ts +8 -0
- package/dist/runtime/handlers/handler-instance-scope.js +54 -11
- package/dist/runtime/host/actor-packet-relay.js +7 -7
- package/dist/runtime/host/actor-runtime-options-factory.js +2 -2
- package/dist/runtime/host/application-job-queue.d.ts +28 -9
- package/dist/runtime/host/application-job-queue.js +214 -50
- package/dist/runtime/host/entry-actor-runtime.d.ts +1 -0
- package/dist/runtime/host/entry-actor-runtime.js +4 -1
- package/dist/runtime/host/index.d.ts +7 -1
- package/dist/runtime/host/index.js +154 -126
- package/dist/runtime/host/instance-activation-authority.d.ts +2 -1
- package/dist/runtime/host/instance-activation-authority.js +89 -25
- package/dist/runtime/host/remote-bound-session-relay.js +2 -18
- package/dist/runtime/host/route-mesh-runtime.js +1 -1
- package/dist/runtime/host/service-relocation-control.d.ts +1 -0
- package/dist/runtime/host/service-relocation-control.js +10 -4
- package/dist/runtime/host/service-relocation-host-runtime.d.ts +6 -8
- package/dist/runtime/host/service-relocation-host-runtime.js +215 -243
- package/dist/runtime/host/spot-address-transport.d.ts +1 -0
- package/dist/runtime/host/spot-address-transport.js +28 -14
- package/dist/runtime/host/spot-runtime-options-factory.js +3 -2
- package/dist/runtime/host/user-spot-creation-coordinator.d.ts +1 -0
- package/dist/runtime/host/user-spot-creation-coordinator.js +1 -0
- package/dist/runtime/locations/actor-location-claims.d.ts +2 -2
- package/dist/runtime/locations/actor-location-claims.js +34 -19
- package/dist/runtime/locations/domain-store-contract.d.ts +2 -2
- package/dist/runtime/locations/in-memory-authority-store.d.ts +4 -2
- package/dist/runtime/locations/in-memory-authority-store.js +80 -8
- package/dist/runtime/locations/in-memory-location-store.d.ts +2 -2
- package/dist/runtime/locations/in-memory-location-store.js +19 -3
- package/dist/runtime/locations/internal-location-contracts.d.ts +3 -0
- package/dist/runtime/locations/lifecycle.d.ts +1 -2
- package/dist/runtime/locations/lifecycle.js +2 -5
- package/dist/runtime/locations/location-store-repository.d.ts +3 -2
- package/dist/runtime/locations/location-store-repository.js +165 -22
- package/dist/runtime/locations/resolvers.d.ts +2 -1
- package/dist/runtime/locations/resolvers.js +10 -1
- package/dist/runtime/locations/runtime.d.ts +1 -1
- package/dist/runtime/locations/runtime.js +24 -23
- package/dist/runtime/messaging/framework-json-v1.d.ts +4 -6
- package/dist/runtime/messaging/framework-json-v1.js +38 -294
- package/dist/runtime/messaging/packet-name.d.ts +1 -1
- package/dist/runtime/messaging/packet-name.js +8 -24
- package/dist/runtime/messaging/request-result.d.ts +2 -0
- package/dist/runtime/messaging/request-result.js +54 -0
- package/dist/runtime/messaging/submission-result.d.ts +2 -1
- package/dist/runtime/messaging/submission-result.js +7 -4
- package/dist/runtime/protocol/service_wire_codec.generated.d.ts +15 -0
- package/dist/runtime/protocol/service_wire_codec.generated.js +144 -0
- package/dist/runtime/protocol/service_wire_pilot_codec.generated.d.ts +9 -0
- package/dist/runtime/protocol/service_wire_pilot_codec.generated.js +14 -1
- package/dist/runtime/spots/formal-remote-actor-admission-registry.d.ts +9 -2
- package/dist/runtime/spots/formal-remote-actor-admission-registry.js +33 -19
- package/dist/runtime/spots/index.d.ts +7 -3
- package/dist/runtime/spots/index.js +23 -16
- package/dist/runtime/spots/spot-activation.d.ts +3 -1
- package/dist/runtime/spots/spot-activation.js +21 -12
- package/dist/runtime/spots/spot-actor-admission-coordinator.d.ts +2 -1
- package/dist/runtime/spots/spot-actor-admission-coordinator.js +11 -10
- package/dist/runtime/spots/spot-actor-packet-dispatch.d.ts +4 -1
- package/dist/runtime/spots/spot-actor-packet-dispatch.js +7 -5
- package/dist/runtime/spots/spot-actor-packet-drain.js +2 -0
- package/dist/runtime/spots/spot-actor-packet-relay-dispatch.js +1 -0
- package/dist/runtime/spots/spot-entry-activation.js +9 -3
- package/dist/runtime/spots/spot-handler-registry.d.ts +3 -1
- package/dist/runtime/spots/spot-handler-registry.js +18 -8
- package/dist/runtime/spots/spot-node-autoconnect.js +4 -3
- package/dist/runtime/spots/spot-node-runtime-manager.d.ts +2 -1
- package/dist/runtime/spots/spot-node-runtime-manager.js +4 -11
- package/dist/runtime/spots/spot-outbound.d.ts +3 -0
- package/dist/runtime/spots/spot-outbound.js +24 -15
- package/dist/runtime/spots/spot-routed-spot-packet-dispatch.d.ts +1 -0
- package/dist/runtime/spots/spot-routed-spot-packet-dispatch.js +1 -1
- package/dist/runtime/spots/spot-routing-internal.d.ts +6 -0
- package/dist/runtime/spots/spot-runtime-ports.d.ts +3 -1
- package/dist/runtime/spots/spot-subscription-dispatch.js +0 -3
- package/dist/runtime/spots/spot-timer.js +1 -0
- package/dist/runtime/streams/stream-session-runtime.d.ts +1 -1
- package/dist/runtime/streams/stream-session-runtime.js +14 -28
- package/package.json +3 -3
- package/src/contracts/Actors/ZLinkActorClient.ts +2 -1
- package/src/contracts/Channels/Calls.ts +2 -1
- package/src/contracts/Common/ZLinkMessageMetadata.ts +13 -8
- package/src/contracts/Configuration/Builders.ts +1 -2
- package/src/contracts/Configuration/Configs.ts +0 -6
- package/src/contracts/Configuration/RegistrationBuilders.ts +8 -12
- package/src/contracts/Configuration/RegistrationTypes.ts +1 -6
- package/src/contracts/Configuration/RegistrationValidators.ts +9 -10
- package/src/contracts/Configuration/index.ts +1 -6
- package/src/contracts/Handlers/Attributes.ts +14 -21
- package/src/contracts/Handlers/JsonContract.ts +8 -216
- package/src/contracts/Spots/Contracts.ts +2 -1
- package/src/internal.ts +1 -0
- package/src/nest-integration.ts +1 -0
- package/src/runtime/actors/actor-client.ts +40 -16
- package/src/runtime/actors/actor-handoff.ts +22 -8
- package/src/runtime/actors/actor-join-relocation.ts +1 -0
- package/src/runtime/actors/actor-local-native-join.ts +17 -26
- package/src/runtime/actors/actor-remote-wire.ts +17 -0
- package/src/runtime/actors/actor-routed-join-transport.ts +14 -4
- package/src/runtime/actors/actor-routed-json-request.ts +10 -2
- package/src/runtime/actors/index.ts +19 -5
- package/src/runtime/actors/spot-actor-dispatch.ts +4 -2
- package/src/runtime/admission.ts +18 -5
- package/src/runtime/application-jobs/application-ingress-record-owner.ts +53 -27
- package/src/runtime/application-jobs/application-job-queue-scope.ts +56 -22
- package/src/runtime/application-jobs/contracts.ts +28 -2
- package/src/runtime/backend/contracts/index.ts +63 -32
- package/src/runtime/backend/mesh-completion-table.ts +175 -59
- package/src/runtime/backend/mesh-dispatch-pump.ts +59 -32
- package/src/runtime/backend/node/node-backend-adapter-factory.ts +12 -5
- package/src/runtime/backend/node/node-backend-adapter-support.ts +42 -31
- package/src/runtime/backend/node/node-dealer-channel-client-transport.ts +12 -2
- package/src/runtime/backend/node/node-mesh-backend-adapter.ts +3 -10
- package/src/runtime/backend/node/node-raw-binding-port.ts +73 -37
- package/src/runtime/backend/node/node-raw-mesh-backend.ts +209 -176
- package/src/runtime/backend/node/node-socket-backend-adapter.ts +32 -13
- package/src/runtime/backend/raw-binding-port.ts +18 -3
- package/src/runtime/backend/runtime-message.ts +6 -0
- package/src/runtime/backend/runtime-values.ts +1 -0
- package/src/runtime/channels/channel-clients.ts +90 -41
- package/src/runtime/channels/channel-dispatch-pipeline.ts +69 -34
- package/src/runtime/channels/channel-dispatch-services.ts +69 -1
- package/src/runtime/channels/channel-dispatchers.ts +29 -27
- package/src/runtime/channels/channel-envelope-inspection.ts +2 -16
- package/src/runtime/channels/channel-envelope.ts +133 -8
- package/src/runtime/channels/channel-outbound-operations.ts +22 -8
- package/src/runtime/channels/channel-receive-loops.ts +3 -3
- package/src/runtime/channels/channel-runtime-lifecycle.ts +7 -1
- package/src/runtime/channels/channel-runtime-manager.ts +29 -12
- package/src/runtime/channels/channel-socket-registry.ts +84 -130
- package/src/runtime/channels/channel-transports.ts +128 -60
- package/src/runtime/channels/local-spot-route-transport.ts +3 -1
- package/src/runtime/channels/router-socket-spot-route-transport.ts +13 -4
- package/src/runtime/channels/source-spot-router.ts +8 -4
- package/src/runtime/channels/spot-node-route-transport.ts +8 -4
- package/src/runtime/channels/spot-route-bridge-transport.ts +6 -4
- package/src/runtime/channels/spot-route-dispatch-strategy.ts +47 -18
- package/src/runtime/diagnostics/message-flow.ts +1 -1
- package/src/runtime/execution/serial-execution-queue.ts +2 -0
- package/src/runtime/foundation/actor-join-recovery-codec.ts +2 -2
- package/src/runtime/foundation/durable-service-request.ts +137 -0
- package/src/runtime/foundation/operation-identity.ts +5 -1
- package/src/runtime/foundation/raw-service-mesh-runtime.ts +642 -253
- package/src/runtime/foundation/service-liveness-registry.ts +68 -59
- package/src/runtime/foundation/service-mailbox.ts +7 -1
- package/src/runtime/foundation/service-relocation-object-owner.ts +2 -0
- package/src/runtime/foundation/service-relocation-runtime.ts +18 -1
- package/src/runtime/foundation/service-runtime-contracts.ts +7 -1
- package/src/runtime/foundation/service-stateful-runtime.ts +128 -160
- package/src/runtime/foundation/service-stateful-wire-codec.ts +55 -84
- package/src/runtime/foundation/service-topology-registry.ts +103 -42
- package/src/runtime/foundation/service-wire-m6a-codec.ts +57 -38
- package/src/runtime/handlers/handler-instance-scope.ts +67 -16
- package/src/runtime/host/actor-packet-relay.ts +7 -0
- package/src/runtime/host/actor-runtime-options-factory.ts +14 -2
- package/src/runtime/host/application-job-queue.ts +249 -48
- package/src/runtime/host/entry-actor-runtime.ts +5 -0
- package/src/runtime/host/index.ts +224 -160
- package/src/runtime/host/instance-activation-authority.ts +132 -27
- package/src/runtime/host/remote-bound-session-relay.ts +2 -23
- package/src/runtime/host/route-mesh-runtime.ts +1 -1
- package/src/runtime/host/service-relocation-control.ts +11 -5
- package/src/runtime/host/service-relocation-host-runtime.ts +317 -291
- package/src/runtime/host/spot-address-transport.ts +49 -24
- package/src/runtime/host/spot-runtime-options-factory.ts +4 -0
- package/src/runtime/host/user-spot-creation-coordinator.ts +8 -0
- package/src/runtime/locations/actor-location-claims.ts +52 -30
- package/src/runtime/locations/domain-store-contract.ts +6 -2
- package/src/runtime/locations/in-memory-authority-store.ts +113 -9
- package/src/runtime/locations/in-memory-location-store.ts +25 -3
- package/src/runtime/locations/internal-location-contracts.ts +4 -0
- package/src/runtime/locations/lifecycle.ts +8 -26
- package/src/runtime/locations/location-store-repository.ts +220 -15
- package/src/runtime/locations/resolvers.ts +25 -2
- package/src/runtime/locations/runtime.ts +28 -24
- package/src/runtime/messaging/framework-json-v1.ts +5 -325
- package/src/runtime/messaging/packet-name.ts +5 -25
- package/src/runtime/messaging/request-result.ts +58 -0
- package/src/runtime/messaging/submission-result.ts +7 -3
- package/src/runtime/protocol/service_wire_codec.generated.ts +131 -1
- package/src/runtime/protocol/service_wire_pilot_codec.generated.ts +4 -4
- package/src/runtime/spots/formal-remote-actor-admission-registry.ts +45 -23
- package/src/runtime/spots/index.ts +30 -2
- package/src/runtime/spots/spot-activation.ts +33 -10
- package/src/runtime/spots/spot-actor-admission-coordinator.ts +13 -0
- package/src/runtime/spots/spot-actor-packet-dispatch.ts +10 -0
- package/src/runtime/spots/spot-actor-packet-drain.ts +2 -0
- package/src/runtime/spots/spot-actor-packet-relay-dispatch.ts +1 -0
- package/src/runtime/spots/spot-entry-activation.ts +12 -2
- package/src/runtime/spots/spot-handler-registry.ts +41 -8
- package/src/runtime/spots/spot-node-autoconnect.ts +6 -2
- package/src/runtime/spots/spot-node-runtime-manager.ts +7 -12
- package/src/runtime/spots/spot-outbound.ts +36 -16
- package/src/runtime/spots/spot-routed-spot-packet-dispatch.ts +2 -1
- package/src/runtime/spots/spot-routing-internal.ts +14 -0
- package/src/runtime/spots/spot-runtime-ports.ts +3 -0
- package/src/runtime/spots/spot-subscription-dispatch.ts +0 -3
- package/src/runtime/spots/spot-timer.ts +5 -1
- package/src/runtime/streams/stream-session-runtime.ts +13 -30
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
} from './service-topology-registry';
|
|
9
9
|
import {
|
|
10
10
|
SERVICE_WIRE_PREFIX_SIZE,
|
|
11
|
+
SERVICE_WIRE_TEXT8_MAX_BYTES,
|
|
11
12
|
decodeCanonicalServiceWireText,
|
|
12
13
|
encodeCanonicalServiceWireText
|
|
13
14
|
} from './service-wire-binary-primitives';
|
|
@@ -70,8 +71,7 @@ export function encodeNodeRequestHeader(correlation: bigint): Buffer {
|
|
|
70
71
|
return withU64(prefix(M6aServiceWireCommand.nodeRequest), correlation, 'correlation');
|
|
71
72
|
}
|
|
72
73
|
|
|
73
|
-
export function decodeNodeRequestHeader(frame: Uint8Array): bigint {
|
|
74
|
-
const header = decodeHeader(frame);
|
|
74
|
+
export function decodeNodeRequestHeader(frame: Uint8Array, header = decodeHeader(frame)): bigint {
|
|
75
75
|
if (
|
|
76
76
|
header.command !== M6aServiceWireCommand.nodeRequest ||
|
|
77
77
|
header.flags !== 0 ||
|
|
@@ -86,8 +86,7 @@ export function encodeChannelSendHeader(channelName: string): Buffer {
|
|
|
86
86
|
return concat(prefix(M6aServiceWireCommand.channelSend), encodeText8(channelName, 'channelName'));
|
|
87
87
|
}
|
|
88
88
|
|
|
89
|
-
export function decodeChannelSendHeader(frame: Uint8Array): string {
|
|
90
|
-
const header = decodeHeader(frame);
|
|
89
|
+
export function decodeChannelSendHeader(frame: Uint8Array, header = decodeHeader(frame)): string {
|
|
91
90
|
if (header.command !== M6aServiceWireCommand.channelSend || header.flags !== 0) {
|
|
92
91
|
fail('Invalid channelSend header.');
|
|
93
92
|
}
|
|
@@ -104,11 +103,13 @@ export function encodeChannelRequestHeader(correlation: bigint, channelName: str
|
|
|
104
103
|
);
|
|
105
104
|
}
|
|
106
105
|
|
|
107
|
-
export function decodeChannelRequestHeader(
|
|
106
|
+
export function decodeChannelRequestHeader(
|
|
107
|
+
frame: Uint8Array,
|
|
108
|
+
header = decodeHeader(frame)
|
|
109
|
+
): {
|
|
108
110
|
readonly correlation: bigint;
|
|
109
111
|
readonly channelName: string;
|
|
110
112
|
} {
|
|
111
|
-
const header = decodeHeader(frame);
|
|
112
113
|
if (header.command !== M6aServiceWireCommand.channelRequest || header.flags !== 0) {
|
|
113
114
|
fail('Invalid channelRequest header.');
|
|
114
115
|
}
|
|
@@ -165,24 +166,12 @@ export function decodeReplyHeader(frame: Uint8Array): ServiceReplyHeader {
|
|
|
165
166
|
}
|
|
166
167
|
|
|
167
168
|
export function encodeApplicationPayload(payload: ServiceApplicationPayload): Buffer {
|
|
168
|
-
const
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
packetName.byteLength + contentType.byteLength + 4 + payload.payload.byteLength;
|
|
173
|
-
if (bodyLength > MAX_U32) fail('Application payload body exceeds u32.');
|
|
174
|
-
const result = Buffer.alloc(5 + bodyLength);
|
|
175
|
-
result[0] = APPLICATION_PAYLOAD_VERSION;
|
|
176
|
-
result.writeUInt32BE(bodyLength, 1);
|
|
177
|
-
let offset = 5;
|
|
178
|
-
offset += packetName.copy(result, offset);
|
|
179
|
-
offset += contentType.copy(result, offset);
|
|
180
|
-
result.writeUInt32BE(payload.payload.byteLength, offset);
|
|
181
|
-
offset += 4;
|
|
182
|
-
Buffer.from(payload.payload.buffer, payload.payload.byteOffset, payload.payload.byteLength).copy(
|
|
183
|
-
result,
|
|
184
|
-
offset
|
|
169
|
+
const result = allocateApplicationPayload(
|
|
170
|
+
payload.packetName,
|
|
171
|
+
payload.contentType,
|
|
172
|
+
payload.payload.byteLength
|
|
185
173
|
);
|
|
174
|
+
result.set(payload.payload, result.byteLength - payload.payload.byteLength);
|
|
186
175
|
return result;
|
|
187
176
|
}
|
|
188
177
|
|
|
@@ -198,35 +187,65 @@ export function encodeMultipartApplicationPayload(
|
|
|
198
187
|
): Buffer {
|
|
199
188
|
if (parts.length === 0) fail('Multipart payload must contain at least one part.');
|
|
200
189
|
if (parts.length > MAX_U32) fail('Multipart part count exceeds u32.');
|
|
201
|
-
const packetNameBytes = encodeText8(packetName, 'packetName');
|
|
202
|
-
const contentTypeBytes = encodeText8(contentType, 'contentType');
|
|
203
190
|
let multipartLength = 4;
|
|
204
191
|
for (const part of parts) {
|
|
205
192
|
if (part.byteLength > MAX_U32) fail('Multipart part exceeds u32.');
|
|
206
193
|
multipartLength += 4 + part.byteLength;
|
|
207
194
|
if (multipartLength > MAX_U32) fail('Multipart payload exceeds u32.');
|
|
208
195
|
}
|
|
209
|
-
const
|
|
210
|
-
|
|
211
|
-
const result = Buffer.alloc(5 + bodyLength);
|
|
212
|
-
result[0] = APPLICATION_PAYLOAD_VERSION;
|
|
213
|
-
result.writeUInt32BE(bodyLength, 1);
|
|
214
|
-
let offset = 5;
|
|
215
|
-
offset += packetNameBytes.copy(result, offset);
|
|
216
|
-
offset += contentTypeBytes.copy(result, offset);
|
|
217
|
-
result.writeUInt32BE(multipartLength, offset);
|
|
218
|
-
offset += 4;
|
|
196
|
+
const result = allocateApplicationPayload(packetName, contentType, multipartLength);
|
|
197
|
+
let offset = result.byteLength - multipartLength;
|
|
219
198
|
result.writeUInt32BE(parts.length, offset);
|
|
220
199
|
offset += 4;
|
|
221
200
|
for (const part of parts) {
|
|
222
201
|
result.writeUInt32BE(part.byteLength, offset);
|
|
223
202
|
offset += 4;
|
|
224
|
-
|
|
203
|
+
result.set(part, offset);
|
|
225
204
|
offset += part.byteLength;
|
|
226
205
|
}
|
|
227
206
|
return result;
|
|
228
207
|
}
|
|
229
208
|
|
|
209
|
+
function allocateApplicationPayload(
|
|
210
|
+
packetName: string,
|
|
211
|
+
contentType: string,
|
|
212
|
+
payloadLength: number
|
|
213
|
+
): Buffer {
|
|
214
|
+
const packetNameBytes = encodeCanonicalServiceWireText(
|
|
215
|
+
packetName,
|
|
216
|
+
'packetName',
|
|
217
|
+
SERVICE_WIRE_TEXT8_MAX_BYTES,
|
|
218
|
+
fail
|
|
219
|
+
);
|
|
220
|
+
const contentTypeBytes = encodeCanonicalServiceWireText(
|
|
221
|
+
contentType,
|
|
222
|
+
'contentType',
|
|
223
|
+
SERVICE_WIRE_TEXT8_MAX_BYTES,
|
|
224
|
+
fail
|
|
225
|
+
);
|
|
226
|
+
if (payloadLength > MAX_U32) fail('Application payload exceeds u32.');
|
|
227
|
+
const frameLength =
|
|
228
|
+
APPLICATION_PAYLOAD_MINIMUM_FIELD_BYTES +
|
|
229
|
+
packetNameBytes.byteLength +
|
|
230
|
+
contentTypeBytes.byteLength +
|
|
231
|
+
payloadLength;
|
|
232
|
+
const prefixLength = 1 + APPLICATION_PAYLOAD_LENGTH_FIELD_BYTES;
|
|
233
|
+
const bodyLength = frameLength - prefixLength;
|
|
234
|
+
if (bodyLength > MAX_U32) fail('Application payload body exceeds u32.');
|
|
235
|
+
const result = Buffer.alloc(frameLength);
|
|
236
|
+
result[0] = APPLICATION_PAYLOAD_VERSION;
|
|
237
|
+
result.writeUInt32BE(bodyLength, 1);
|
|
238
|
+
let offset = prefixLength;
|
|
239
|
+
result[offset++] = packetNameBytes.byteLength;
|
|
240
|
+
result.set(packetNameBytes, offset);
|
|
241
|
+
offset += packetNameBytes.byteLength;
|
|
242
|
+
result[offset++] = contentTypeBytes.byteLength;
|
|
243
|
+
result.set(contentTypeBytes, offset);
|
|
244
|
+
offset += contentTypeBytes.byteLength;
|
|
245
|
+
result.writeUInt32BE(payloadLength, offset);
|
|
246
|
+
return result;
|
|
247
|
+
}
|
|
248
|
+
|
|
230
249
|
export function decodeApplicationPayload(frame: Uint8Array): ServiceApplicationPayload {
|
|
231
250
|
const decoded = decodeApplicationPayloadView(frame);
|
|
232
251
|
return {
|
|
@@ -487,7 +506,7 @@ function encodeU64(value: bigint): Buffer {
|
|
|
487
506
|
}
|
|
488
507
|
|
|
489
508
|
function encodeText8(value: string, field: string): Buffer {
|
|
490
|
-
const bytes = encodeCanonicalServiceWireText(value, field,
|
|
509
|
+
const bytes = encodeCanonicalServiceWireText(value, field, SERVICE_WIRE_TEXT8_MAX_BYTES, fail);
|
|
491
510
|
return concat(Buffer.of(bytes.byteLength), bytes);
|
|
492
511
|
}
|
|
493
512
|
|
|
@@ -501,7 +520,7 @@ function tlv(id: number, value: Buffer): Buffer {
|
|
|
501
520
|
}
|
|
502
521
|
|
|
503
522
|
function concat(...parts: readonly Uint8Array[]): Buffer {
|
|
504
|
-
return Buffer.concat(parts
|
|
523
|
+
return Buffer.concat(parts);
|
|
505
524
|
}
|
|
506
525
|
|
|
507
526
|
function readNonZeroU64(bytes: Buffer, offset: number, field: string): bigint {
|
|
@@ -9,13 +9,10 @@ export interface ZLinkHandlerInstanceScope {
|
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
interface ZLinkHandlerInstanceScopeFactory {
|
|
12
|
+
prepare?(type: Type): void | (() => unknown);
|
|
12
13
|
create(context?: ZLinkMessageContext): ZLinkHandlerInstanceScope;
|
|
13
14
|
}
|
|
14
15
|
|
|
15
|
-
interface ActiveHandlerScope {
|
|
16
|
-
readonly scope: ZLinkHandlerInstanceScope;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
16
|
interface Deferred<T> {
|
|
20
17
|
readonly promise: Promise<T>;
|
|
21
18
|
readonly resolve: (value: T) => void;
|
|
@@ -29,12 +26,37 @@ interface LifecycleScopeDisposal {
|
|
|
29
26
|
}
|
|
30
27
|
|
|
31
28
|
const HANDLER_SCOPE_FACTORY = Symbol.for('@zlink-systems/framework.handler-instance-scope-factory');
|
|
32
|
-
const activeHandlerScope = new AsyncLocalStorage<
|
|
29
|
+
const activeHandlerScope = new AsyncLocalStorage<ZLinkHandlerInstanceScope>();
|
|
33
30
|
const activeLifecycleScope = new AsyncLocalStorage<LifecycleHandlerInstanceScope>();
|
|
34
31
|
const detachedLifecycleResource = new AsyncResource('zlink:handler-instance-scope');
|
|
35
32
|
const dispatchScopes = new WeakMap<object, ZLinkHandlerInstanceScope>();
|
|
36
33
|
const lifecycleScopes = new WeakMap<object, LifecycleHandlerInstanceScope>();
|
|
37
34
|
|
|
35
|
+
export function registerHandlerInstanceScopeFactory(
|
|
36
|
+
providerResolver: ZLinkProviderResolver,
|
|
37
|
+
factory: ZLinkHandlerInstanceScopeFactory
|
|
38
|
+
): void {
|
|
39
|
+
Object.defineProperty(providerResolver, HANDLER_SCOPE_FACTORY, {
|
|
40
|
+
value: factory,
|
|
41
|
+
enumerable: false
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function prepareHandlerInstance<T>(
|
|
46
|
+
providerResolver: ZLinkProviderResolver | undefined,
|
|
47
|
+
type: Type<T>
|
|
48
|
+
): (() => T) | undefined {
|
|
49
|
+
if (providerResolver === undefined) return () => new type();
|
|
50
|
+
const factory = (providerResolver as unknown as Record<PropertyKey, unknown>)[
|
|
51
|
+
HANDLER_SCOPE_FACTORY
|
|
52
|
+
];
|
|
53
|
+
if (isHandlerInstanceScopeFactory(factory)) {
|
|
54
|
+
const activate = factory.prepare?.(type);
|
|
55
|
+
if (activate !== undefined) return activate as () => T;
|
|
56
|
+
}
|
|
57
|
+
return undefined;
|
|
58
|
+
}
|
|
59
|
+
|
|
38
60
|
export async function runInHandlerInstanceScope<T>(
|
|
39
61
|
providerResolver: ZLinkProviderResolver | undefined,
|
|
40
62
|
context: ZLinkMessageContext | undefined,
|
|
@@ -42,7 +64,7 @@ export async function runInHandlerInstanceScope<T>(
|
|
|
42
64
|
): Promise<T> {
|
|
43
65
|
const active = activeHandlerScope.getStore();
|
|
44
66
|
if (active !== undefined) {
|
|
45
|
-
return callback(active
|
|
67
|
+
return callback(active);
|
|
46
68
|
}
|
|
47
69
|
if (context !== undefined) {
|
|
48
70
|
const existing = dispatchScopes.get(context);
|
|
@@ -56,7 +78,7 @@ export async function runInHandlerInstanceScope<T>(
|
|
|
56
78
|
dispatchScopes.set(context, scope);
|
|
57
79
|
}
|
|
58
80
|
try {
|
|
59
|
-
return await activeHandlerScope.run(
|
|
81
|
+
return await activeHandlerScope.run(scope, () => callback(scope));
|
|
60
82
|
} finally {
|
|
61
83
|
if (context !== undefined && dispatchScopes.get(context) === scope) {
|
|
62
84
|
dispatchScopes.delete(context);
|
|
@@ -144,14 +166,15 @@ class DefaultHandlerInstanceScope implements ZLinkHandlerInstanceScope {
|
|
|
144
166
|
if (existing !== undefined) return existing;
|
|
145
167
|
const activation = createDeferred<unknown>();
|
|
146
168
|
this.instances.set(type, activation.promise);
|
|
147
|
-
|
|
169
|
+
this.activate(type, activation);
|
|
148
170
|
return activation.promise as Promise<T>;
|
|
149
171
|
}
|
|
150
172
|
|
|
151
173
|
async dispose(): Promise<void> {
|
|
152
174
|
if (this.disposed) return;
|
|
153
175
|
this.disposed = true;
|
|
154
|
-
|
|
176
|
+
if (this.owned.length !== this.instances.size)
|
|
177
|
+
await Promise.allSettled(this.instances.values());
|
|
155
178
|
try {
|
|
156
179
|
await disposeOwnedInstances(this.owned);
|
|
157
180
|
} finally {
|
|
@@ -159,21 +182,43 @@ class DefaultHandlerInstanceScope implements ZLinkHandlerInstanceScope {
|
|
|
159
182
|
this.instances.clear();
|
|
160
183
|
}
|
|
161
184
|
}
|
|
162
|
-
private
|
|
163
|
-
let instance: T;
|
|
185
|
+
private activate<T>(type: Type<T>, activation: Deferred<unknown>): void {
|
|
164
186
|
try {
|
|
165
187
|
const created = this.providerResolver?.create?.(type);
|
|
166
|
-
|
|
188
|
+
if (created === undefined) {
|
|
189
|
+
this.completeActivation(new type(), activation);
|
|
190
|
+
} else {
|
|
191
|
+
void this.activatePending(created, activation);
|
|
192
|
+
}
|
|
167
193
|
} catch (error) {
|
|
168
194
|
activation.reject(error);
|
|
169
|
-
return;
|
|
170
195
|
}
|
|
196
|
+
}
|
|
171
197
|
|
|
198
|
+
private async activatePending<T>(
|
|
199
|
+
created: T | Promise<T>,
|
|
200
|
+
activation: Deferred<unknown>
|
|
201
|
+
): Promise<void> {
|
|
202
|
+
try {
|
|
203
|
+
this.completeActivation(await created, activation);
|
|
204
|
+
} catch (error) {
|
|
205
|
+
activation.reject(error);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
private completeActivation(instance: unknown, activation: Deferred<unknown>): void {
|
|
172
210
|
if (!this.disposed) {
|
|
173
211
|
this.owned.push(instance);
|
|
174
212
|
activation.resolve(instance);
|
|
175
213
|
return;
|
|
176
214
|
}
|
|
215
|
+
void this.disposeLateActivation(instance, activation);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
private async disposeLateActivation(
|
|
219
|
+
instance: unknown,
|
|
220
|
+
activation: Deferred<unknown>
|
|
221
|
+
): Promise<void> {
|
|
177
222
|
try {
|
|
178
223
|
await disposeOwnedInstance(instance);
|
|
179
224
|
activation.reject(new Error('Handler instance scope was disposed during activation.'));
|
|
@@ -306,6 +351,11 @@ function startOutsideLifecycleInvocation<T>(work: () => T): T {
|
|
|
306
351
|
}
|
|
307
352
|
|
|
308
353
|
export async function disposeOwnedInstance(instance: unknown): Promise<void> {
|
|
354
|
+
const cleanup = handlerInstanceCleanup(instance);
|
|
355
|
+
if (cleanup !== undefined) await cleanup.call(instance);
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
export function handlerInstanceCleanup(instance: unknown): (() => unknown) | undefined {
|
|
309
359
|
if (instance === null || instance === undefined) return;
|
|
310
360
|
const value = instance as {
|
|
311
361
|
dispose?: () => unknown;
|
|
@@ -313,12 +363,13 @@ export async function disposeOwnedInstance(instance: unknown): Promise<void> {
|
|
|
313
363
|
onModuleDestroy?: () => unknown;
|
|
314
364
|
};
|
|
315
365
|
if (typeof value.dispose === 'function') {
|
|
316
|
-
|
|
366
|
+
return value.dispose;
|
|
317
367
|
} else if (typeof value.close === 'function') {
|
|
318
|
-
|
|
368
|
+
return value.close;
|
|
319
369
|
} else if (typeof value.onModuleDestroy === 'function') {
|
|
320
|
-
|
|
370
|
+
return value.onModuleDestroy;
|
|
321
371
|
}
|
|
372
|
+
return undefined;
|
|
322
373
|
}
|
|
323
374
|
|
|
324
375
|
export async function disposeOwnedInstances(instances: readonly unknown[]): Promise<void> {
|
|
@@ -303,6 +303,7 @@ export class ZLinkActorPacketRelay {
|
|
|
303
303
|
const dispatch =
|
|
304
304
|
state?.spotId === undefined
|
|
305
305
|
? this.requireSpotNodeRuntime().dispatchEntryActorPacket(
|
|
306
|
+
'remote',
|
|
306
307
|
relay.actorId,
|
|
307
308
|
[header, body],
|
|
308
309
|
false,
|
|
@@ -310,6 +311,7 @@ export class ZLinkActorPacketRelay {
|
|
|
310
311
|
fallbackActorRef
|
|
311
312
|
)
|
|
312
313
|
: this.requireSpotManager().dispatchRoutedActorPacket(
|
|
314
|
+
'remote',
|
|
313
315
|
state.spotId,
|
|
314
316
|
relay.actorId,
|
|
315
317
|
[header, body],
|
|
@@ -356,6 +358,7 @@ export class ZLinkActorPacketRelay {
|
|
|
356
358
|
const dispatch =
|
|
357
359
|
state?.spotId === undefined
|
|
358
360
|
? this.requireSpotNodeRuntime().dispatchEntryActorPacket(
|
|
361
|
+
'remote',
|
|
359
362
|
relay.actorId,
|
|
360
363
|
[header, body],
|
|
361
364
|
false,
|
|
@@ -363,6 +366,7 @@ export class ZLinkActorPacketRelay {
|
|
|
363
366
|
fallbackActorRef
|
|
364
367
|
)
|
|
365
368
|
: this.requireSpotManager().dispatchRoutedActorPacket(
|
|
369
|
+
'remote',
|
|
366
370
|
state.spotId,
|
|
367
371
|
relay.actorId,
|
|
368
372
|
[header, body],
|
|
@@ -423,6 +427,7 @@ export class ZLinkActorPacketRelay {
|
|
|
423
427
|
const response =
|
|
424
428
|
state?.spotId === undefined
|
|
425
429
|
? await this.requireSpotNodeRuntime().dispatchEntryActorPacket(
|
|
430
|
+
'remote',
|
|
426
431
|
relay.actorId,
|
|
427
432
|
[header, body],
|
|
428
433
|
relay.returnResponse === true,
|
|
@@ -430,6 +435,7 @@ export class ZLinkActorPacketRelay {
|
|
|
430
435
|
fallbackActorRef
|
|
431
436
|
)
|
|
432
437
|
: await this.requireSpotManager().dispatchRoutedActorPacket(
|
|
438
|
+
'remote',
|
|
433
439
|
state.spotId,
|
|
434
440
|
relay.actorId,
|
|
435
441
|
[header, body],
|
|
@@ -892,6 +898,7 @@ export class ZLinkActorPacketRelay {
|
|
|
892
898
|
this.options.detachedTaskRunner.runDetached('local actor packet relay', async () => {
|
|
893
899
|
try {
|
|
894
900
|
const response = await this.requireSpotManager().dispatchRoutedActorPacket(
|
|
901
|
+
'local',
|
|
895
902
|
spotId,
|
|
896
903
|
actor.actorId,
|
|
897
904
|
[header, body],
|
|
@@ -276,16 +276,28 @@ export class ZLinkActorRuntimeOptionsFactory {
|
|
|
276
276
|
staleActorRefPredicate: (meshName, actor) =>
|
|
277
277
|
this.actorBelongsToMesh(meshName, actor.actorId) &&
|
|
278
278
|
this.options.actorHandoff.isKnownStale(actor),
|
|
279
|
-
handoffCapture: (
|
|
279
|
+
handoffCapture: (
|
|
280
|
+
meshName,
|
|
281
|
+
actorId,
|
|
282
|
+
parts,
|
|
283
|
+
returnResponse,
|
|
284
|
+
actor,
|
|
285
|
+
deadlineUnixMs,
|
|
286
|
+
onAdmitted
|
|
287
|
+
) =>
|
|
280
288
|
this.actorBelongsToMesh(meshName, actorId) &&
|
|
281
289
|
!this.options.actorHandoff.isProvisional(actorId)
|
|
282
290
|
? this.options.actorHandoff.capture(
|
|
291
|
+
'local',
|
|
283
292
|
actorId,
|
|
284
293
|
parts,
|
|
285
294
|
returnResponse,
|
|
286
295
|
undefined,
|
|
287
296
|
actor,
|
|
288
|
-
deadlineUnixMs
|
|
297
|
+
deadlineUnixMs,
|
|
298
|
+
undefined,
|
|
299
|
+
undefined,
|
|
300
|
+
onAdmitted
|
|
289
301
|
)
|
|
290
302
|
: undefined,
|
|
291
303
|
sendErrorReporter: this.options.reportPostCommitError
|