@floegence/flowersec-core 6.1.0 → 7.0.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/README.md +101 -170
- package/THIRD_PARTY_NOTICES.md +7 -3072
- package/dist/browser/connectSessionV3.d.ts +44 -0
- package/dist/browser/connectSessionV3.js +261 -0
- package/dist/browser/directWebSocketProfileV1.d.ts +14 -0
- package/dist/browser/directWebSocketProfileV1.js +71 -0
- package/dist/browser/httpDirectV1.d.ts +30 -0
- package/dist/browser/httpDirectV1.js +52 -0
- package/dist/browser/index.d.ts +10 -15
- package/dist/browser/index.js +4 -5
- package/dist/browser/privateLoopbackV1.d.ts +30 -0
- package/dist/browser/privateLoopbackV1.js +70 -0
- package/dist/cli.d.ts +1 -24
- package/dist/cli.js +129 -91
- package/dist/cliSpendMarker.js +8 -0
- package/dist/defaults.d.ts +23 -1
- package/dist/defaults.js +23 -1
- package/dist/facade.d.ts +21 -104
- package/dist/facade.js +8 -45
- package/dist/framing/jsonframe.d.ts +21 -0
- package/dist/framing/jsonframe.js +107 -0
- package/dist/node/acceptor.d.ts +1 -0
- package/dist/node/acceptor.js +1 -0
- package/dist/node/acceptorV3.d.ts +70 -0
- package/dist/node/acceptorV3.js +295 -0
- package/dist/node/byteStreamDuplex.d.ts +4 -0
- package/dist/node/byteStreamDuplex.js +69 -0
- package/dist/node/connectSessionV3.d.ts +33 -0
- package/dist/node/connectSessionV3.js +93 -0
- package/dist/node/connectionPath.d.ts +0 -2
- package/dist/node/connectionPath.js +0 -18
- package/dist/node/index.d.ts +16 -52
- package/dist/node/index.js +6 -24
- package/dist/node/listenerIngress.d.ts +5 -0
- package/dist/node/listenerIngress.js +12 -0
- package/dist/node/nativeTransportAddon.d.ts +142 -0
- package/dist/node/nativeTransportAddon.js +235 -0
- package/dist/node/proxyServer.d.ts +4 -30
- package/dist/node/proxyServer.js +169 -600
- package/dist/node/rawQuicAdapterV3.d.ts +11 -0
- package/dist/node/rawQuicAdapterV3.js +83 -0
- package/dist/node/rawQuicServerV3.d.ts +34 -0
- package/dist/node/rawQuicServerV3.js +60 -0
- package/dist/node/runtimeAuthorizationV3.d.ts +41 -0
- package/dist/node/runtimeAuthorizationV3.js +156 -0
- package/dist/node/tunnelRuntimeV3.d.ts +60 -0
- package/dist/node/tunnelRuntimeV3.js +837 -0
- package/dist/node/webSocketServerV3.d.ts +28 -0
- package/dist/node/webSocketServerV3.js +220 -0
- package/dist/proxy/fetch.d.ts +2 -3
- package/dist/proxy/fetch.js +29 -96
- package/dist/proxy/index.d.ts +1 -5
- package/dist/proxy/index.js +0 -2
- package/dist/proxy/integration.d.ts +8 -12
- package/dist/proxy/integration.js +16 -23
- package/dist/proxy/policy.d.ts +0 -5
- package/dist/proxy/policy.js +22 -60
- package/dist/proxy/runtime.d.ts +1 -3
- package/dist/proxy/runtime.js +186 -404
- package/dist/proxy/scope.js +2 -2
- package/dist/proxy/serviceWorker.d.ts +0 -3
- package/dist/proxy/serviceWorker.js +176 -634
- package/dist/proxy/serviceWorkerRuntime.js +1 -26
- package/dist/proxy/stream.d.ts +6 -17
- package/dist/proxy/stream.js +40 -9
- package/dist/proxy/types.d.ts +11 -50
- package/dist/proxy/windowBridge.d.ts +3 -11
- package/dist/proxy/windowBridge.js +31 -70
- package/dist/proxy/wsPatch.js +26 -34
- package/dist/public/contract.d.ts +74 -1
- package/dist/public/contract.js +8 -0
- package/dist/public/sessionHandlers.d.ts +47 -0
- package/dist/public/sessionHandlers.js +151 -0
- package/dist/public/streamHandlers.d.ts +20 -0
- package/dist/public/streamHandlers.js +127 -0
- package/dist/public/streamMetadata.d.ts +2 -34
- package/dist/public/streamMetadata.js +13 -206
- package/dist/rpc/client.d.ts +34 -0
- package/dist/rpc/client.js +244 -0
- package/dist/rpc/server.d.ts +59 -0
- package/dist/rpc/server.js +255 -0
- package/dist/rpc/validate.d.ts +4 -0
- package/dist/{application/rpcJSON.js → rpc/validate.js} +1 -1
- package/dist/rpc/wire.d.ts +15 -0
- package/dist/v3/admissionError.d.ts +4 -0
- package/dist/v3/admissionError.js +8 -0
- package/dist/v3/artifact.d.ts +145 -0
- package/dist/v3/artifact.js +1180 -0
- package/dist/v3/artifactLease.d.ts +19 -0
- package/dist/v3/artifactLease.js +128 -0
- package/dist/v3/browserRuntime.d.ts +37 -0
- package/dist/v3/browserRuntime.js +197 -0
- package/dist/v3/browserSessionRuntime.d.ts +2 -0
- package/dist/v3/browserSessionRuntime.js +21 -0
- package/dist/v3/capability.d.ts +32 -0
- package/dist/v3/capability.js +345 -0
- package/dist/v3/carrier.d.ts +86 -0
- package/dist/v3/carrier.js +414 -0
- package/dist/v3/connectionController.d.ts +101 -0
- package/dist/v3/connectionController.js +888 -0
- package/dist/v3/contract.d.ts +70 -0
- package/dist/v3/contract.js +3 -0
- package/dist/v3/controller.d.ts +45 -0
- package/dist/v3/controller.js +316 -0
- package/dist/v3/handshake.d.ts +81 -0
- package/dist/v3/handshake.js +471 -0
- package/dist/v3/jcs.d.ts +6 -0
- package/dist/v3/jcs.js +69 -0
- package/dist/v3/jsonPreflight.d.ts +1 -0
- package/dist/v3/jsonPreflight.js +251 -0
- package/dist/v3/nodeRuntime.d.ts +43 -0
- package/dist/v3/nodeRuntime.js +437 -0
- package/dist/v3/nodeSessionRuntime.d.ts +2 -0
- package/dist/v3/nodeSessionRuntime.js +13 -0
- package/dist/v3/protocol.d.ts +100 -0
- package/dist/v3/protocol.js +715 -0
- package/dist/v3/publicApi.d.ts +12 -0
- package/dist/v3/publicApi.js +46 -0
- package/dist/v3/publicSession.js +316 -0
- package/dist/v3/runtimeAdapters.d.ts +9 -0
- package/dist/v3/runtimeAdapters.js +109 -0
- package/dist/v3/security.d.ts +36 -0
- package/dist/v3/security.js +113 -0
- package/dist/v3/serverAdmission.d.ts +42 -0
- package/dist/v3/serverAdmission.js +242 -0
- package/dist/v3/session.d.ts +339 -0
- package/dist/v3/session.js +2399 -0
- package/dist/v3/sessionConnector.d.ts +46 -0
- package/dist/v3/sessionConnector.js +534 -0
- package/dist/v3/streamLifetimeLedger.d.ts +32 -0
- package/dist/v3/streamLifetimeLedger.js +146 -0
- package/dist/v3/streamMetadata.js +7 -0
- package/dist/v3/transportConstants.d.ts +56 -0
- package/dist/v3/transportConstants.js +59 -0
- package/dist/v3/tunnelIngress.d.ts +8 -0
- package/dist/v3/tunnelIngress.js +21 -0
- package/dist/v3/unreliableMessage.d.ts +44 -0
- package/dist/v3/unreliableMessage.js +287 -0
- package/dist/v3/webSocketCarrier.d.ts +33 -0
- package/dist/v3/webSocketCarrier.js +380 -0
- package/dist/v3/webTransportCarrier.d.ts +27 -0
- package/dist/v3/webTransportCarrier.js +580 -0
- package/dist/ws-client/binaryTransport.d.ts +65 -0
- package/dist/ws-client/binaryTransport.js +348 -0
- package/dist/yamux/byteReader.d.ts +13 -0
- package/dist/yamux/byteReader.js +81 -0
- package/dist/yamux/constants.d.ts +10 -0
- package/dist/yamux/constants.js +14 -0
- package/dist/yamux/errors.d.ts +15 -0
- package/dist/yamux/errors.js +34 -0
- package/dist/yamux/header.d.ts +20 -0
- package/dist/yamux/header.js +30 -0
- package/dist/yamux/session.d.ts +81 -0
- package/dist/yamux/session.js +401 -0
- package/dist/yamux/stream.d.ts +42 -0
- package/dist/yamux/stream.js +307 -0
- package/package.json +20 -19
- package/sbom/cyclonedx.json +43 -761
- package/sbom/spdx.json +49 -566
- package/dist/application/rpcJSON.d.ts +0 -15
- package/dist/browser/clientV4.d.ts +0 -61
- package/dist/browser/clientV4.js +0 -179
- package/dist/browser/indexedDBPoolV4.d.ts +0 -101
- package/dist/browser/indexedDBPoolV4.js +0 -634
- package/dist/browser/liveHTTPSV4.d.ts +0 -35
- package/dist/browser/liveHTTPSV4.js +0 -162
- package/dist/browser/localBrowserBridge.d.ts +0 -20
- package/dist/browser/localBrowserBridge.js +0 -82
- package/dist/browser/poolServerAllow.d.ts +0 -21
- package/dist/browser/poolServerAllow.js +0 -151
- package/dist/browser/webTransportPositionsV4.d.ts +0 -16
- package/dist/browser/webTransportPositionsV4.js +0 -75
- package/dist/browser/webTransportStreamV4.d.ts +0 -36
- package/dist/browser/webTransportStreamV4.js +0 -370
- package/dist/browser/webTransportV4.d.ts +0 -126
- package/dist/browser/webTransportV4.js +0 -627
- package/dist/browser/wssV4.d.ts +0 -69
- package/dist/browser/wssV4.js +0 -339
- package/dist/generated/brotliWorker.d.ts +0 -1
- package/dist/generated/brotliWorker.js +0 -3
- package/dist/generated/idna151.d.ts +0 -2
- package/dist/generated/idna151.js +0 -38
- package/dist/generated/normalization151.d.ts +0 -5
- package/dist/generated/normalization151.js +0 -878
- package/dist/generated/sqliteWorkers.d.ts +0 -2
- package/dist/generated/sqliteWorkers.js +0 -3
- package/dist/generated/transportV4APIResults.d.ts +0 -145
- package/dist/generated/transportV4APIResults.js +0 -52
- package/dist/generated/transportV4Registry.d.ts +0 -3758
- package/dist/generated/transportV4Registry.js +0 -29
- package/dist/interop/browserRunner.d.ts +0 -72
- package/dist/interop/browserRunner.js +0 -354
- package/dist/interop/currentClock.d.ts +0 -3
- package/dist/interop/currentClock.js +0 -39
- package/dist/interop/currentContracts.d.ts +0 -6
- package/dist/interop/currentContracts.js +0 -14
- package/dist/interop/currentNativeTunnel.d.ts +0 -31
- package/dist/interop/currentNativeTunnel.js +0 -185
- package/dist/interop/currentParity.d.ts +0 -68
- package/dist/interop/currentParity.js +0 -392
- package/dist/interop/currentPeer.d.ts +0 -252
- package/dist/interop/currentPeer.js +0 -677
- package/dist/interop/currentRegisteredTunnelPeer.d.ts +0 -37
- package/dist/interop/currentRegisteredTunnelPeer.js +0 -93
- package/dist/interop/currentRelayPeer.d.ts +0 -131
- package/dist/interop/currentRelayPeer.js +0 -263
- package/dist/interop/currentServer.d.ts +0 -44
- package/dist/interop/currentServer.js +0 -299
- package/dist/interop/currentTLSPin.d.ts +0 -9
- package/dist/interop/currentTLSPin.js +0 -44
- package/dist/interop/currentTunnelMaterial.d.ts +0 -34
- package/dist/interop/currentTunnelMaterial.js +0 -100
- package/dist/interop/httpApplicationPeer.d.ts +0 -15
- package/dist/interop/httpApplicationPeer.js +0 -167
- package/dist/interop/invalidProofPeer.d.ts +0 -8
- package/dist/interop/invalidProofPeer.js +0 -106
- package/dist/interop/proxyServerPeer.js +0 -49
- package/dist/interop/serverParityPeer.d.ts +0 -101
- package/dist/interop/serverParityPeer.js +0 -609
- package/dist/node/acceptorCurrent.d.ts +0 -55
- package/dist/node/acceptorCurrent.js +0 -286
- package/dist/node/admissionRecord.d.ts +0 -23
- package/dist/node/admissionRecord.js +0 -178
- package/dist/node/clientV4.d.ts +0 -59
- package/dist/node/clientV4.js +0 -197
- package/dist/node/endpointDialer.d.ts +0 -70
- package/dist/node/endpointDialer.js +0 -231
- package/dist/node/endpointListener.d.ts +0 -48
- package/dist/node/endpointListener.js +0 -403
- package/dist/node/endpointTransport.d.ts +0 -7
- package/dist/node/endpointTransport.js +0 -18
- package/dist/node/grantIssuerCurrent.d.ts +0 -64
- package/dist/node/grantIssuerCurrent.js +0 -355
- package/dist/node/liveHTTPSV4.d.ts +0 -28
- package/dist/node/liveHTTPSV4.js +0 -298
- package/dist/node/liveTunnelAuthorityCurrent.d.ts +0 -153
- package/dist/node/liveTunnelAuthorityCurrent.js +0 -590
- package/dist/node/nativeDuplexBridgeV4.d.ts +0 -41
- package/dist/node/nativeDuplexBridgeV4.js +0 -494
- package/dist/node/nativeTransportCurrent.d.ts +0 -196
- package/dist/node/nativeTransportCurrent.js +0 -37
- package/dist/node/poolServerAllow.d.ts +0 -33
- package/dist/node/poolServerAllow.js +0 -277
- package/dist/node/proxyCredentials.d.ts +0 -67
- package/dist/node/proxyCredentials.js +0 -364
- package/dist/node/proxyNetwork.d.ts +0 -18
- package/dist/node/proxyNetwork.js +0 -213
- package/dist/node/rawQUICCurrent.d.ts +0 -139
- package/dist/node/rawQUICCurrent.js +0 -1177
- package/dist/node/registeredLiveTunnelControl.d.ts +0 -74
- package/dist/node/registeredLiveTunnelControl.js +0 -865
- package/dist/node/registeredPoolTunnelAuthority.d.ts +0 -50
- package/dist/node/registeredPoolTunnelAuthority.js +0 -305
- package/dist/node/registeredTunnelControl.d.ts +0 -189
- package/dist/node/registeredTunnelControl.js +0 -1007
- package/dist/node/registeredWinnerContinuation.d.ts +0 -26
- package/dist/node/registeredWinnerContinuation.js +0 -83
- package/dist/node/relayNativePair.d.ts +0 -62
- package/dist/node/relayNativePair.js +0 -737
- package/dist/node/relayRecord.d.ts +0 -57
- package/dist/node/relayRecord.js +0 -275
- package/dist/node/serveRawQUIC.d.ts +0 -58
- package/dist/node/serveRawQUIC.js +0 -331
- package/dist/node/serveWSS.d.ts +0 -58
- package/dist/node/serveWSS.js +0 -309
- package/dist/node/sqliteAdmission.d.ts +0 -100
- package/dist/node/sqliteAdmission.js +0 -1185
- package/dist/node/sqliteExecutionContentV4.d.ts +0 -63
- package/dist/node/sqliteExecutionContentV4.js +0 -251
- package/dist/node/sqliteExecutionV4.d.ts +0 -114
- package/dist/node/sqliteExecutionV4.js +0 -1052
- package/dist/node/sqliteFormat.d.ts +0 -20
- package/dist/node/sqliteFormat.js +0 -72
- package/dist/node/sqliteInspectionV4.d.ts +0 -7
- package/dist/node/sqliteInspectionV4.js +0 -47
- package/dist/node/sqliteNativeV4.d.ts +0 -3
- package/dist/node/sqliteNativeV4.js +0 -16
- package/dist/node/sqlitePoolV4.d.ts +0 -41
- package/dist/node/sqlitePoolV4.js +0 -282
- package/dist/node/sqlitePoolWorkerProgramV4.js +0 -411
- package/dist/node/sqlitePoolWorkerV4.d.ts +0 -67
- package/dist/node/sqlitePoolWorkerV4.js +0 -206
- package/dist/node/sqliteV4.d.ts +0 -82
- package/dist/node/sqliteV4.js +0 -166
- package/dist/node/sqliteWorkerProgramV4.js +0 -175
- package/dist/node/sqliteWorkerV4.d.ts +0 -47
- package/dist/node/sqliteWorkerV4.js +0 -142
- package/dist/node/streamDuplexV4.d.ts +0 -33
- package/dist/node/streamDuplexV4.js +0 -359
- package/dist/node/tunnelListenerPreparation.d.ts +0 -37
- package/dist/node/tunnelListenerPreparation.js +0 -162
- package/dist/node/tunnelRuntime.d.ts +0 -124
- package/dist/node/tunnelRuntime.js +0 -1205
- package/dist/node/webTransportCurrent.d.ts +0 -24
- package/dist/node/webTransportCurrent.js +0 -12
- package/dist/node/wssV4.d.ts +0 -99
- package/dist/node/wssV4.js +0 -846
- package/dist/proxy/admission.d.ts +0 -21
- package/dist/proxy/admission.js +0 -126
- package/dist/proxy/brotliBody.d.ts +0 -10
- package/dist/proxy/brotliBody.js +0 -85
- package/dist/proxy/credentialControl.d.ts +0 -30
- package/dist/proxy/credentialControl.js +0 -86
- package/dist/proxy/currentStream.d.ts +0 -24
- package/dist/proxy/currentStream.js +0 -158
- package/dist/proxy/headers.d.ts +0 -8
- package/dist/proxy/headers.js +0 -63
- package/dist/proxy/publicationOwner.d.ts +0 -10
- package/dist/proxy/publicationOwner.js +0 -130
- package/dist/proxy/requestAssociation.d.ts +0 -11
- package/dist/proxy/requestAssociation.js +0 -8
- package/dist/proxy/surface.d.ts +0 -45
- package/dist/proxy/surface.js +0 -384
- package/dist/proxy/wire.d.ts +0 -11
- package/dist/proxy/wire.js +0 -214
- package/dist/public/streamKind.d.ts +0 -3
- package/dist/public/streamKind.js +0 -19
- package/dist/testSupport/tlsFixture.d.ts +0 -2
- package/dist/testSupport/tlsFixture.js +0 -8
- package/dist/v4/admissionOffer.d.ts +0 -8
- package/dist/v4/admissionOffer.js +0 -1
- package/dist/v4/checkpoint.d.ts +0 -23
- package/dist/v4/checkpoint.js +0 -16
- package/dist/v4/clientServices.d.ts +0 -35
- package/dist/v4/clientServices.js +0 -11
- package/dist/v4/connectionDiagnostic.d.ts +0 -42
- package/dist/v4/connectionDiagnostic.js +0 -45
- package/dist/v4/connectionRequirements.d.ts +0 -5
- package/dist/v4/connectionRequirements.js +0 -34
- package/dist/v4/controller.d.ts +0 -122
- package/dist/v4/controller.js +0 -1161
- package/dist/v4/controllerNotifications.d.ts +0 -81
- package/dist/v4/controllerNotifications.js +0 -610
- package/dist/v4/diagnostics.d.ts +0 -44
- package/dist/v4/diagnostics.js +0 -9
- package/dist/v4/drain.d.ts +0 -39
- package/dist/v4/drain.js +0 -80
- package/dist/v4/duplexBridge.d.ts +0 -53
- package/dist/v4/duplexBridge.js +0 -446
- package/dist/v4/entrypoints.d.ts +0 -20
- package/dist/v4/entrypoints.js +0 -50
- package/dist/v4/eventSource.d.ts +0 -34
- package/dist/v4/eventSource.js +0 -28
- package/dist/v4/handlerPlan.d.ts +0 -53
- package/dist/v4/handlerPlan.js +0 -129
- package/dist/v4/liveness.d.ts +0 -20
- package/dist/v4/liveness.js +0 -10
- package/dist/v4/localReport.d.ts +0 -17
- package/dist/v4/localReport.js +0 -10
- package/dist/v4/messageDefinition.d.ts +0 -66
- package/dist/v4/messageDefinition.js +0 -109
- package/dist/v4/messageStream.d.ts +0 -89
- package/dist/v4/messageStream.js +0 -1375
- package/dist/v4/notificationOperation.d.ts +0 -30
- package/dist/v4/notificationOperation.js +0 -31
- package/dist/v4/notificationSubscription.d.ts +0 -47
- package/dist/v4/notificationSubscription.js +0 -24
- package/dist/v4/operationReference.d.ts +0 -28
- package/dist/v4/operationReference.js +0 -61
- package/dist/v4/operationReferenceCodec.d.ts +0 -20
- package/dist/v4/operationReferenceCodec.js +0 -129
- package/dist/v4/operationReferenceStore.d.ts +0 -90
- package/dist/v4/operationReferenceStore.js +0 -272
- package/dist/v4/operationResultRead.d.ts +0 -26
- package/dist/v4/operationResultRead.js +0 -24
- package/dist/v4/poolControl.d.ts +0 -11
- package/dist/v4/poolControl.js +0 -50
- package/dist/v4/poolSource.d.ts +0 -93
- package/dist/v4/poolSource.js +0 -900
- package/dist/v4/profileDHReference.d.ts +0 -2
- package/dist/v4/profileDHReference.js +0 -42
- package/dist/v4/public.d.ts +0 -232
- package/dist/v4/public.js +0 -632
- package/dist/v4/responsePublication.d.ts +0 -48
- package/dist/v4/responsePublication.js +0 -227
- package/dist/v4/resume.d.ts +0 -17
- package/dist/v4/resume.js +0 -15
- package/dist/v4/runtime/applicationExecutor.d.ts +0 -190
- package/dist/v4/runtime/applicationExecutor.js +0 -759
- package/dist/v4/runtime/applicationHeader.d.ts +0 -61
- package/dist/v4/runtime/applicationHeader.js +0 -222
- package/dist/v4/runtime/canonicalText.d.ts +0 -8
- package/dist/v4/runtime/canonicalText.js +0 -142
- package/dist/v4/runtime/cbor.d.ts +0 -92
- package/dist/v4/runtime/cbor.js +0 -728
- package/dist/v4/runtime/cborWriter.d.ts +0 -18
- package/dist/v4/runtime/cborWriter.js +0 -59
- package/dist/v4/runtime/checkpointToken.d.ts +0 -41
- package/dist/v4/runtime/checkpointToken.js +0 -61
- package/dist/v4/runtime/clientAdmission.d.ts +0 -40
- package/dist/v4/runtime/clientAdmission.js +0 -378
- package/dist/v4/runtime/clientSessionSpec.d.ts +0 -45
- package/dist/v4/runtime/clientSessionSpec.js +0 -91
- package/dist/v4/runtime/clock.d.ts +0 -80
- package/dist/v4/runtime/clock.js +0 -284
- package/dist/v4/runtime/connectionFacts.d.ts +0 -23
- package/dist/v4/runtime/connectionFacts.js +0 -106
- package/dist/v4/runtime/contractAcceptance.d.ts +0 -20
- package/dist/v4/runtime/contractAcceptance.js +0 -91
- package/dist/v4/runtime/contractQuery.d.ts +0 -57
- package/dist/v4/runtime/contractQuery.js +0 -265
- package/dist/v4/runtime/contractQueryAccess.d.ts +0 -25
- package/dist/v4/runtime/contractQueryAccess.js +0 -117
- package/dist/v4/runtime/contractQueryAcquisition.d.ts +0 -83
- package/dist/v4/runtime/contractQueryAcquisition.js +0 -572
- package/dist/v4/runtime/contractQueryClient.d.ts +0 -70
- package/dist/v4/runtime/contractQueryClient.js +0 -411
- package/dist/v4/runtime/contractQueryCodecs.d.ts +0 -20
- package/dist/v4/runtime/contractQueryCodecs.js +0 -71
- package/dist/v4/runtime/contractQueryExchange.d.ts +0 -36
- package/dist/v4/runtime/contractQueryExchange.js +0 -160
- package/dist/v4/runtime/contractQueryService.d.ts +0 -42
- package/dist/v4/runtime/contractQueryService.js +0 -572
- package/dist/v4/runtime/contractQuerySession.d.ts +0 -38
- package/dist/v4/runtime/contractQuerySession.js +0 -158
- package/dist/v4/runtime/contractRoutes.d.ts +0 -87
- package/dist/v4/runtime/contractRoutes.js +0 -396
- package/dist/v4/runtime/contractSnapshotReader.d.ts +0 -59
- package/dist/v4/runtime/contractSnapshotReader.js +0 -418
- package/dist/v4/runtime/contractSnapshotWriter.d.ts +0 -32
- package/dist/v4/runtime/contractSnapshotWriter.js +0 -208
- package/dist/v4/runtime/controllerServiceSource.d.ts +0 -23
- package/dist/v4/runtime/controllerServiceSource.js +0 -109
- package/dist/v4/runtime/controllerUnaryRoute.d.ts +0 -28
- package/dist/v4/runtime/controllerUnaryRoute.js +0 -1
- package/dist/v4/runtime/credentialNamespace.d.ts +0 -143
- package/dist/v4/runtime/credentialNamespace.js +0 -1286
- package/dist/v4/runtime/credentialSupport.d.ts +0 -60
- package/dist/v4/runtime/credentialSupport.js +0 -294
- package/dist/v4/runtime/credentialVerifier.d.ts +0 -404
- package/dist/v4/runtime/credentialVerifier.js +0 -1443
- package/dist/v4/runtime/cryptoUsage.d.ts +0 -135
- package/dist/v4/runtime/cryptoUsage.js +0 -552
- package/dist/v4/runtime/deadline.d.ts +0 -31
- package/dist/v4/runtime/deadline.js +0 -188
- package/dist/v4/runtime/diagnosticCounters.d.ts +0 -15
- package/dist/v4/runtime/diagnosticCounters.js +0 -78
- package/dist/v4/runtime/diagnosticObservation.d.ts +0 -25
- package/dist/v4/runtime/diagnosticObservation.js +0 -67
- package/dist/v4/runtime/diagnosticSink.d.ts +0 -16
- package/dist/v4/runtime/diagnosticSink.js +0 -320
- package/dist/v4/runtime/ed25519.d.ts +0 -1
- package/dist/v4/runtime/ed25519.js +0 -34
- package/dist/v4/runtime/endpointHop.d.ts +0 -12
- package/dist/v4/runtime/endpointHop.js +0 -26
- package/dist/v4/runtime/envelope.d.ts +0 -66
- package/dist/v4/runtime/envelope.js +0 -275
- package/dist/v4/runtime/environment.d.ts +0 -277
- package/dist/v4/runtime/environment.js +0 -1913
- package/dist/v4/runtime/executionManagementChannel.d.ts +0 -27
- package/dist/v4/runtime/executionManagementChannel.js +0 -733
- package/dist/v4/runtime/executionManagementCodec.d.ts +0 -84
- package/dist/v4/runtime/executionManagementCodec.js +0 -127
- package/dist/v4/runtime/executionStorage.d.ts +0 -71
- package/dist/v4/runtime/executionStorage.js +0 -10
- package/dist/v4/runtime/fixedDiagnosticExecutor.d.ts +0 -34
- package/dist/v4/runtime/fixedDiagnosticExecutor.js +0 -149
- package/dist/v4/runtime/fixedManagementExecutor.d.ts +0 -21
- package/dist/v4/runtime/fixedManagementExecutor.js +0 -153
- package/dist/v4/runtime/fixedQueryExecutor.d.ts +0 -46
- package/dist/v4/runtime/fixedQueryExecutor.js +0 -311
- package/dist/v4/runtime/grantDigest.d.ts +0 -9
- package/dist/v4/runtime/grantDigest.js +0 -31
- package/dist/v4/runtime/hopAuthentication.d.ts +0 -51
- package/dist/v4/runtime/hopAuthentication.js +0 -392
- package/dist/v4/runtime/host.d.ts +0 -15
- package/dist/v4/runtime/host.js +0 -332
- package/dist/v4/runtime/initializerWorkload.d.ts +0 -38
- package/dist/v4/runtime/initializerWorkload.js +0 -164
- package/dist/v4/runtime/lifecycle.d.ts +0 -5
- package/dist/v4/runtime/lifecycle.js +0 -17
- package/dist/v4/runtime/liveAuthorization.d.ts +0 -42
- package/dist/v4/runtime/liveAuthorization.js +0 -133
- package/dist/v4/runtime/liveAuthorizationWire.d.ts +0 -8
- package/dist/v4/runtime/liveAuthorizationWire.js +0 -31
- package/dist/v4/runtime/liveCarrierPreparation.d.ts +0 -9
- package/dist/v4/runtime/liveCarrierPreparation.js +0 -27
- package/dist/v4/runtime/liveness.d.ts +0 -37
- package/dist/v4/runtime/liveness.js +0 -319
- package/dist/v4/runtime/maintenancePositions.d.ts +0 -29
- package/dist/v4/runtime/maintenancePositions.js +0 -152
- package/dist/v4/runtime/messageCodec.d.ts +0 -20
- package/dist/v4/runtime/messageCodec.js +0 -192
- package/dist/v4/runtime/namespaceContinuity.d.ts +0 -20
- package/dist/v4/runtime/namespaceContinuity.js +0 -176
- package/dist/v4/runtime/nativeCandidates.d.ts +0 -18
- package/dist/v4/runtime/nativeCandidates.js +0 -109
- package/dist/v4/runtime/nativeFailure.d.ts +0 -10
- package/dist/v4/runtime/nativeFailure.js +0 -32
- package/dist/v4/runtime/nativeFrame.d.ts +0 -47
- package/dist/v4/runtime/nativeFrame.js +0 -318
- package/dist/v4/runtime/nativeIngress.d.ts +0 -30
- package/dist/v4/runtime/nativeIngress.js +0 -177
- package/dist/v4/runtime/nativePositions.d.ts +0 -24
- package/dist/v4/runtime/nativePositions.js +0 -131
- package/dist/v4/runtime/nativeProviderPositions.d.ts +0 -16
- package/dist/v4/runtime/nativeProviderPositions.js +0 -75
- package/dist/v4/runtime/nativeSend.d.ts +0 -15
- package/dist/v4/runtime/nativeSend.js +0 -57
- package/dist/v4/runtime/noiseHandshake.d.ts +0 -70
- package/dist/v4/runtime/noiseHandshake.js +0 -373
- package/dist/v4/runtime/noiseWasmBinary.d.ts +0 -2
- package/dist/v4/runtime/noiseWasmBinary.js +0 -3
- package/dist/v4/runtime/notifyChannel.d.ts +0 -37
- package/dist/v4/runtime/notifyChannel.js +0 -277
- package/dist/v4/runtime/notifyDispatch.d.ts +0 -108
- package/dist/v4/runtime/notifyDispatch.js +0 -717
- package/dist/v4/runtime/notifyExecution.d.ts +0 -18
- package/dist/v4/runtime/notifyExecution.js +0 -59
- package/dist/v4/runtime/notifyPreparation.d.ts +0 -70
- package/dist/v4/runtime/notifyPreparation.js +0 -465
- package/dist/v4/runtime/openAdmission.d.ts +0 -125
- package/dist/v4/runtime/openAdmission.js +0 -810
- package/dist/v4/runtime/peerOpenPreparation.d.ts +0 -18
- package/dist/v4/runtime/peerOpenPreparation.js +0 -61
- package/dist/v4/runtime/poolJournal.d.ts +0 -18
- package/dist/v4/runtime/poolJournal.js +0 -14
- package/dist/v4/runtime/poolJournalStorage.d.ts +0 -4
- package/dist/v4/runtime/poolJournalStorage.js +0 -172
- package/dist/v4/runtime/poolRecord.d.ts +0 -9
- package/dist/v4/runtime/poolRecord.js +0 -23
- package/dist/v4/runtime/poolRecordStorage.d.ts +0 -10
- package/dist/v4/runtime/poolRecordStorage.js +0 -216
- package/dist/v4/runtime/poolServerAllow.d.ts +0 -49
- package/dist/v4/runtime/poolServerAllow.js +0 -38
- package/dist/v4/runtime/poolSpend.d.ts +0 -20
- package/dist/v4/runtime/poolSpend.js +0 -4
- package/dist/v4/runtime/queryRenewalPosition.d.ts +0 -59
- package/dist/v4/runtime/queryRenewalPosition.js +0 -220
- package/dist/v4/runtime/random.d.ts +0 -15
- package/dist/v4/runtime/random.js +0 -71
- package/dist/v4/runtime/rawStreamPreparation.d.ts +0 -40
- package/dist/v4/runtime/rawStreamPreparation.js +0 -125
- package/dist/v4/runtime/receiveDirection.d.ts +0 -135
- package/dist/v4/runtime/receiveDirection.js +0 -957
- package/dist/v4/runtime/receiveWorkspace.d.ts +0 -19
- package/dist/v4/runtime/receiveWorkspace.js +0 -82
- package/dist/v4/runtime/record.d.ts +0 -7
- package/dist/v4/runtime/record.js +0 -173
- package/dist/v4/runtime/recordCrypto.d.ts +0 -121
- package/dist/v4/runtime/recordCrypto.js +0 -633
- package/dist/v4/runtime/recordWorkspace.d.ts +0 -17
- package/dist/v4/runtime/recordWorkspace.js +0 -69
- package/dist/v4/runtime/registeredCarrierPreparation.d.ts +0 -17
- package/dist/v4/runtime/registeredCarrierPreparation.js +0 -191
- package/dist/v4/runtime/rekey.d.ts +0 -40
- package/dist/v4/runtime/rekey.js +0 -362
- package/dist/v4/runtime/relayCredentials.d.ts +0 -126
- package/dist/v4/runtime/relayCredentials.js +0 -349
- package/dist/v4/runtime/replayWindow.d.ts +0 -6
- package/dist/v4/runtime/replayWindow.js +0 -59
- package/dist/v4/runtime/resources.d.ts +0 -200
- package/dist/v4/runtime/resources.js +0 -1236
- package/dist/v4/runtime/resumeCodec.d.ts +0 -44
- package/dist/v4/runtime/resumeCodec.js +0 -192
- package/dist/v4/runtime/resumeStream.d.ts +0 -23
- package/dist/v4/runtime/resumeStream.js +0 -23
- package/dist/v4/runtime/rpcApplication.d.ts +0 -234
- package/dist/v4/runtime/rpcApplication.js +0 -2170
- package/dist/v4/runtime/rpcApplicationServices.d.ts +0 -18
- package/dist/v4/runtime/rpcApplicationServices.js +0 -62
- package/dist/v4/runtime/rpcCallCapacity.d.ts +0 -62
- package/dist/v4/runtime/rpcCallCapacity.js +0 -289
- package/dist/v4/runtime/rpcChannel.d.ts +0 -58
- package/dist/v4/runtime/rpcChannel.js +0 -334
- package/dist/v4/runtime/rpcCompletion.d.ts +0 -42
- package/dist/v4/runtime/rpcCompletion.js +0 -152
- package/dist/v4/runtime/rpcEventSource.d.ts +0 -27
- package/dist/v4/runtime/rpcEventSource.js +0 -201
- package/dist/v4/runtime/rpcFragment.d.ts +0 -42
- package/dist/v4/runtime/rpcFragment.js +0 -227
- package/dist/v4/runtime/rpcInput.d.ts +0 -41
- package/dist/v4/runtime/rpcInput.js +0 -137
- package/dist/v4/runtime/rpcNetwork.d.ts +0 -143
- package/dist/v4/runtime/rpcNetwork.js +0 -652
- package/dist/v4/runtime/rpcOutputInterest.d.ts +0 -20
- package/dist/v4/runtime/rpcOutputInterest.js +0 -106
- package/dist/v4/runtime/rpcPayload.d.ts +0 -24
- package/dist/v4/runtime/rpcPayload.js +0 -82
- package/dist/v4/runtime/rpcPreacceptedStreams.d.ts +0 -46
- package/dist/v4/runtime/rpcPreacceptedStreams.js +0 -406
- package/dist/v4/runtime/rpcPublisher.d.ts +0 -49
- package/dist/v4/runtime/rpcPublisher.js +0 -406
- package/dist/v4/runtime/rpcReceiver.d.ts +0 -40
- package/dist/v4/runtime/rpcReceiver.js +0 -255
- package/dist/v4/runtime/rpcResumeDispatch.d.ts +0 -46
- package/dist/v4/runtime/rpcResumeDispatch.js +0 -266
- package/dist/v4/runtime/rpcStream.d.ts +0 -14
- package/dist/v4/runtime/rpcStream.js +0 -12
- package/dist/v4/runtime/rpcStreamMessages.d.ts +0 -53
- package/dist/v4/runtime/rpcStreamMessages.js +0 -428
- package/dist/v4/runtime/rpcStreamPreparation.d.ts +0 -21
- package/dist/v4/runtime/rpcStreamPreparation.js +0 -110
- package/dist/v4/runtime/rpcStreamingDispatch.d.ts +0 -26
- package/dist/v4/runtime/rpcStreamingDispatch.js +0 -607
- package/dist/v4/runtime/rpcStreamingExchange.d.ts +0 -91
- package/dist/v4/runtime/rpcStreamingExchange.js +0 -812
- package/dist/v4/runtime/rpcUnaryCall.d.ts +0 -16
- package/dist/v4/runtime/rpcUnaryCall.js +0 -152
- package/dist/v4/runtime/rpcUnaryDispatch.d.ts +0 -34
- package/dist/v4/runtime/rpcUnaryDispatch.js +0 -569
- package/dist/v4/runtime/rpcUnaryExchange.d.ts +0 -127
- package/dist/v4/runtime/rpcUnaryExchange.js +0 -1042
- package/dist/v4/runtime/rpcUnaryPreparation.d.ts +0 -102
- package/dist/v4/runtime/rpcUnaryPreparation.js +0 -736
- package/dist/v4/runtime/rpcUnaryRegistration.d.ts +0 -33
- package/dist/v4/runtime/rpcUnaryRegistration.js +0 -113
- package/dist/v4/runtime/rpcUnaryResultRecipient.d.ts +0 -21
- package/dist/v4/runtime/rpcUnaryResultRecipient.js +0 -57
- package/dist/v4/runtime/schema.d.ts +0 -26
- package/dist/v4/runtime/schema.js +0 -668
- package/dist/v4/runtime/schemaRegistry.d.ts +0 -128
- package/dist/v4/runtime/schemaRegistry.js +0 -74
- package/dist/v4/runtime/sendBudget.d.ts +0 -10
- package/dist/v4/runtime/sendBudget.js +0 -46
- package/dist/v4/runtime/serveGroup.d.ts +0 -73
- package/dist/v4/runtime/serveGroup.js +0 -589
- package/dist/v4/runtime/serverAdmission.d.ts +0 -33
- package/dist/v4/runtime/serverAdmission.js +0 -342
- package/dist/v4/runtime/serverAdmissionAuthority.d.ts +0 -23
- package/dist/v4/runtime/serverAdmissionAuthority.js +0 -5
- package/dist/v4/runtime/serverSessionSpec.d.ts +0 -9
- package/dist/v4/runtime/serverSessionSpec.js +0 -12
- package/dist/v4/runtime/serviceBinding.d.ts +0 -128
- package/dist/v4/runtime/serviceBinding.js +0 -1435
- package/dist/v4/runtime/serviceBindingConfig.d.ts +0 -72
- package/dist/v4/runtime/serviceBindingConfig.js +0 -85
- package/dist/v4/runtime/serviceBindingPool.d.ts +0 -58
- package/dist/v4/runtime/serviceBindingPool.js +0 -327
- package/dist/v4/runtime/serviceContract.d.ts +0 -111
- package/dist/v4/runtime/serviceContract.js +0 -588
- package/dist/v4/runtime/serviceInputs.d.ts +0 -30
- package/dist/v4/runtime/serviceInputs.js +0 -201
- package/dist/v4/runtime/serviceOfferPlan.d.ts +0 -81
- package/dist/v4/runtime/serviceOfferPlan.js +0 -335
- package/dist/v4/runtime/serviceOfferScheduler.d.ts +0 -12
- package/dist/v4/runtime/serviceOfferScheduler.js +0 -201
- package/dist/v4/runtime/serviceOfferWork.d.ts +0 -25
- package/dist/v4/runtime/serviceOfferWork.js +0 -1
- package/dist/v4/runtime/session.d.ts +0 -411
- package/dist/v4/runtime/session.js +0 -6369
- package/dist/v4/runtime/sessionActivity.d.ts +0 -19
- package/dist/v4/runtime/sessionActivity.js +0 -97
- package/dist/v4/runtime/sessionAdmission.d.ts +0 -93
- package/dist/v4/runtime/sessionAdmission.js +0 -498
- package/dist/v4/runtime/sessionCleanup.d.ts +0 -47
- package/dist/v4/runtime/sessionCleanup.js +0 -268
- package/dist/v4/runtime/sessionKeyPreparation.d.ts +0 -19
- package/dist/v4/runtime/sessionKeyPreparation.js +0 -50
- package/dist/v4/runtime/signedMap.d.ts +0 -68
- package/dist/v4/runtime/signedMap.js +0 -425
- package/dist/v4/runtime/streamAdapter.d.ts +0 -113
- package/dist/v4/runtime/streamAdapter.js +0 -62
- package/dist/v4/runtime/streamData.d.ts +0 -11
- package/dist/v4/runtime/streamData.js +0 -50
- package/dist/v4/runtime/streamOpenPreparation.d.ts +0 -23
- package/dist/v4/runtime/streamOpenPreparation.js +0 -77
- package/dist/v4/runtime/streamRegistration.d.ts +0 -87
- package/dist/v4/runtime/streamRegistration.js +0 -296
- package/dist/v4/runtime/taskObservation.d.ts +0 -1
- package/dist/v4/runtime/taskObservation.js +0 -48
- package/dist/v4/runtime/timeArithmetic.d.ts +0 -29
- package/dist/v4/runtime/timeArithmetic.js +0 -107
- package/dist/v4/runtime/unreliable.d.ts +0 -76
- package/dist/v4/runtime/unreliable.js +0 -473
- package/dist/v4/runtime/volatileExecutions.d.ts +0 -128
- package/dist/v4/runtime/volatileExecutions.js +0 -792
- package/dist/v4/runtime/wireRegistry.d.ts +0 -52
- package/dist/v4/runtime/wireRegistry.js +0 -29
- package/dist/v4/runtime/writeRequest.d.ts +0 -42
- package/dist/v4/runtime/writeRequest.js +0 -237
- package/dist/v4/serve.d.ts +0 -107
- package/dist/v4/serve.js +0 -80
- package/dist/v4/serviceClient.d.ts +0 -92
- package/dist/v4/serviceClient.js +0 -323
- package/dist/v4/serviceDefinition.d.ts +0 -138
- package/dist/v4/serviceDefinition.js +0 -150
- package/dist/v4/serviceDependencies.d.ts +0 -66
- package/dist/v4/serviceDependencies.js +0 -250
- package/dist/v4/serviceFactory.d.ts +0 -31
- package/dist/v4/serviceFactory.js +0 -157
- package/dist/v4/serviceHandlers.d.ts +0 -55
- package/dist/v4/serviceHandlers.js +0 -15
- package/dist/v4/serviceMembers.d.ts +0 -4
- package/dist/v4/serviceMembers.js +0 -12
- package/dist/v4/staticServiceContracts.d.ts +0 -43
- package/dist/v4/staticServiceContracts.js +0 -161
- package/dist/v4/storageFormat.d.ts +0 -16
- package/dist/v4/storageFormat.js +0 -5
- package/dist/v4/streamContent.d.ts +0 -30
- package/dist/v4/streamContent.js +0 -29
- package/dist/v4/streamHandlers.d.ts +0 -61
- package/dist/v4/streamHandlers.js +0 -16
- package/dist/v4/streamingOperation.d.ts +0 -64
- package/dist/v4/streamingOperation.js +0 -141
- package/dist/v4/strictEd25519Reference.d.ts +0 -2
- package/dist/v4/strictEd25519Reference.js +0 -37
- package/dist/v4/testSupport/cbor.d.ts +0 -124
- package/dist/v4/testSupport/cbor.js +0 -230
- package/dist/v4/testSupport/credentials.d.ts +0 -55
- package/dist/v4/testSupport/credentials.js +0 -111
- package/dist/v4/testSupport/unicode.d.ts +0 -19
- package/dist/v4/testSupport/unicode.js +0 -112
- package/dist/v4/unaryOperation.d.ts +0 -59
- package/dist/v4/unaryOperation.js +0 -80
- package/dist/v4/unreliable.d.ts +0 -26
- package/dist/v4/unreliable.js +0 -10
- package/dist/v4/webStreams.d.ts +0 -30
- package/dist/v4/webStreams.js +0 -377
- /package/dist/{interop/proxyServerPeer.d.ts → rpc/wire.js} +0 -0
- /package/dist/{node/sqlitePoolWorkerProgramV4.d.ts → v3/publicSession.d.ts} +0 -0
- /package/dist/{node/sqliteWorkerProgramV4.d.ts → v3/streamMetadata.d.ts} +0 -0
package/dist/v4/messageStream.js
DELETED
|
@@ -1,1375 +0,0 @@
|
|
|
1
|
-
import { streamMetadataFromDocument } from "../public/streamMetadata.js";
|
|
2
|
-
import { CBORDecoder, cborDecoderCharge, byteLength, byteSlice } from "./runtime/cbor.js";
|
|
3
|
-
import { ResourceError, ResourceVector } from "./runtime/resources.js";
|
|
4
|
-
import { timerChunk } from "./runtime/deadline.js";
|
|
5
|
-
import { acquireMessageStreamAdapter } from "./runtime/streamAdapter.js";
|
|
6
|
-
import { MessageSegments, messageInputBytes, checkApplicationMessageOutput } from "./runtime/messageCodec.js";
|
|
7
|
-
import { messageDefinition, sameMessageDigest, emptyMessageMetadata } from "./messageDefinition.js";
|
|
8
|
-
import { applicationHasPermit } from "./streamHandlers.js";
|
|
9
|
-
import { applicationHasCompletionAncestor, applicationDependsOn } from "./runtime/applicationExecutor.js";
|
|
10
|
-
import { DiagnosticActivity } from "./runtime/diagnosticObservation.js";
|
|
11
|
-
export class V4MessageStreamError extends Error {
|
|
12
|
-
code;
|
|
13
|
-
progress;
|
|
14
|
-
application_input_delivered;
|
|
15
|
-
codec;
|
|
16
|
-
cause;
|
|
17
|
-
constructor(code, progress, application_input_delivered = false, codec) {
|
|
18
|
-
super(code);
|
|
19
|
-
this.code = code;
|
|
20
|
-
this.progress = progress;
|
|
21
|
-
this.application_input_delivered = application_input_delivered;
|
|
22
|
-
this.codec = codec;
|
|
23
|
-
this.name = "V4MessageStreamError";
|
|
24
|
-
this.cause = code === "result_mode_conflict" ? "decoder_started" : undefined;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
const complete = Object.freeze({ status: "complete", core_cleanup: "complete", pending_callbacks: 0n });
|
|
28
|
-
const pending = Object.freeze({ status: "pending", core_cleanup: "pending", pending_callbacks: 0n });
|
|
29
|
-
const empty = new Uint8Array(), token = Symbol("original typed message owner"), copy = Uint8Array.prototype.set;
|
|
30
|
-
const NativePromise = Promise, enqueue = queueMicrotask, defineProperty = Object.defineProperty, freeze = Object.freeze;
|
|
31
|
-
const nativeDecode = TextDecoder.prototype.decode, utf8 = new TextDecoder("utf-8", { fatal: true, ignoreBOM: true });
|
|
32
|
-
const sendCap = 2 * 1024 * 1024 + 32;
|
|
33
|
-
function result(value) { defineProperty(value, "then", { value: undefined }); return freeze(value); }
|
|
34
|
-
function duration(value, fallback, max = 90000n) {
|
|
35
|
-
const n = value ?? fallback;
|
|
36
|
-
if (typeof n !== "bigint" || n < 1n || n > max)
|
|
37
|
-
throw new Error("configuration_capacity");
|
|
38
|
-
return n;
|
|
39
|
-
}
|
|
40
|
-
export function captureMessageOptions(options = {}) {
|
|
41
|
-
return Object.freeze({ assemblyTimeoutMS: duration(options.assemblyTimeoutMS, 30000n), sendTimeoutMS: duration(options.sendTimeoutMS, 30000n), cleanupTimeoutMS: duration(options.cleanupTimeoutMS, 5000n, 30000n) });
|
|
42
|
-
}
|
|
43
|
-
export function messageAdapterProfile(options, prepaid) {
|
|
44
|
-
return Object.freeze({ kind: "message", readBytes: 4096, inputBackingBytes: 1, inputEntries: 1,
|
|
45
|
-
gracefulFinishMS: Number(options.sendTimeoutMS), cleanupMS: Number(options.cleanupTimeoutMS), ...(prepaid === undefined ? {} : { prepaid }) });
|
|
46
|
-
}
|
|
47
|
-
export function messageAdapterCharge(runtimeBytes) {
|
|
48
|
-
return new ResourceVector([25728n + runtimeBytes, 0n, 0n, 5n, 6n, 6n, 4n, 0n, 0n, 1n, 0n]);
|
|
49
|
-
}
|
|
50
|
-
/** One duplex owner, bounded FIFO and persistent message cursor. Complete
|
|
51
|
-
* payloads are allocated only after validating the original four-byte prefix. */
|
|
52
|
-
export class V4TypedMessageStream {
|
|
53
|
-
#owner;
|
|
54
|
-
#inbound;
|
|
55
|
-
#outbound;
|
|
56
|
-
#metadata = emptyMessageMetadata();
|
|
57
|
-
#definition;
|
|
58
|
-
#prepared;
|
|
59
|
-
#options;
|
|
60
|
-
#sends = [];
|
|
61
|
-
#actualSends = new Set();
|
|
62
|
-
#sendBytes = 0;
|
|
63
|
-
#publishing = false;
|
|
64
|
-
#publisher;
|
|
65
|
-
#sealed = false;
|
|
66
|
-
#closed = false;
|
|
67
|
-
#ioEnded = false;
|
|
68
|
-
#ioDetached = false;
|
|
69
|
-
#cleaning = false;
|
|
70
|
-
#failure;
|
|
71
|
-
#closeResult;
|
|
72
|
-
#direction = "c2s";
|
|
73
|
-
#closeTail;
|
|
74
|
-
#closeRunning = false;
|
|
75
|
-
#fin;
|
|
76
|
-
#finResolve;
|
|
77
|
-
#finReject;
|
|
78
|
-
#finDeadline;
|
|
79
|
-
#finTimer;
|
|
80
|
-
#finStarted = false;
|
|
81
|
-
#finResult;
|
|
82
|
-
#finish;
|
|
83
|
-
#readWait;
|
|
84
|
-
#readOwner;
|
|
85
|
-
#readRunning = false;
|
|
86
|
-
#handoff = false;
|
|
87
|
-
#readAdmissionBlocked = false;
|
|
88
|
-
#readScheduled = false;
|
|
89
|
-
#readAbort;
|
|
90
|
-
#prefix = new Uint8Array(4);
|
|
91
|
-
#prefixBytes = 0;
|
|
92
|
-
#length;
|
|
93
|
-
#body = empty;
|
|
94
|
-
#filled = 0;
|
|
95
|
-
#bodyReference;
|
|
96
|
-
#typedReference;
|
|
97
|
-
#typedPrepaid = false;
|
|
98
|
-
#completion;
|
|
99
|
-
#value;
|
|
100
|
-
#decoded = false;
|
|
101
|
-
#decoding = false;
|
|
102
|
-
#applicationInputDelivered = false;
|
|
103
|
-
#decodeContext;
|
|
104
|
-
#decodeAbort;
|
|
105
|
-
#decodeFailed = false;
|
|
106
|
-
#eof = false;
|
|
107
|
-
#assembly;
|
|
108
|
-
#assemblyTimer;
|
|
109
|
-
#resourceObserver;
|
|
110
|
-
#dependencyDeadline;
|
|
111
|
-
#dependencyTimer;
|
|
112
|
-
#cleanupDeadline;
|
|
113
|
-
#cleanupTimer;
|
|
114
|
-
#cleanupIncomplete = false;
|
|
115
|
-
#waits = 0;
|
|
116
|
-
#cleanupWaits = 0;
|
|
117
|
-
#observers = new Set();
|
|
118
|
-
constructor(capability, definition, options) {
|
|
119
|
-
if (capability !== token)
|
|
120
|
-
throw new Error("owner_unavailable");
|
|
121
|
-
messageDefinition(definition);
|
|
122
|
-
this.#definition = definition;
|
|
123
|
-
this.#options = captureMessageOptions(options);
|
|
124
|
-
Object.defineProperty(this, "then", { value: undefined });
|
|
125
|
-
}
|
|
126
|
-
get metadata() { return this.#metadata; }
|
|
127
|
-
/** Internal pre-acceptance preparation has no byte I/O or delivery rights. */
|
|
128
|
-
prepare(capability, context) {
|
|
129
|
-
if (capability !== token || this.#prepared !== undefined || this.#closed)
|
|
130
|
-
throw new Error("owner_unavailable");
|
|
131
|
-
const def = messageDefinition(this.#definition);
|
|
132
|
-
if (context.kind !== this.#definition.kind)
|
|
133
|
-
throw new V4MessageStreamError("definition_mismatch");
|
|
134
|
-
const config = { bytes: 4096, nodes: 272, textBytes: 128, arrayItems: 1, runtimeBytes: context.runtimeBytes };
|
|
135
|
-
const reference = context.reserve("v4_message_metadata", cborDecoderCharge(config));
|
|
136
|
-
let decoder;
|
|
137
|
-
try {
|
|
138
|
-
decoder = new CBORDecoder(config, reference);
|
|
139
|
-
const document = decoder.decodeMap(context.metadata, "TypedMessageMetadata");
|
|
140
|
-
let application;
|
|
141
|
-
try {
|
|
142
|
-
let digest = empty;
|
|
143
|
-
application = empty;
|
|
144
|
-
for (let k = document.firstChild(document.field(0, 2)); k >= 0;) {
|
|
145
|
-
const v = document.nextSibling(k), bytes = new Uint8Array(document.size(v));
|
|
146
|
-
document.copyPayload(v, bytes);
|
|
147
|
-
if (document.text(k) === "definition")
|
|
148
|
-
digest = bytes;
|
|
149
|
-
else
|
|
150
|
-
application = bytes;
|
|
151
|
-
k = document.nextSibling(v);
|
|
152
|
-
}
|
|
153
|
-
if (!sameMessageDigest(digest, def.digest))
|
|
154
|
-
throw new V4MessageStreamError("definition_mismatch");
|
|
155
|
-
}
|
|
156
|
-
finally {
|
|
157
|
-
document.release();
|
|
158
|
-
}
|
|
159
|
-
if (application.length !== 0) {
|
|
160
|
-
const doc = decoder.decodeMap(application, "StreamMetadata");
|
|
161
|
-
try {
|
|
162
|
-
this.#metadata = streamMetadataFromDocument(doc);
|
|
163
|
-
}
|
|
164
|
-
finally {
|
|
165
|
-
doc.release();
|
|
166
|
-
application.fill(0);
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
this.#inbound = def.directions[context.localOpener ? 1 : 0];
|
|
170
|
-
this.#outbound = def.directions[context.localOpener ? 0 : 1];
|
|
171
|
-
this.#prepared = Object.freeze({ localOpener: context.localOpener, kind: context.kind });
|
|
172
|
-
}
|
|
173
|
-
finally {
|
|
174
|
-
decoder?.close();
|
|
175
|
-
reference.release();
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
/** Internal one-time transfer after the same OPEN reaches accepted. */
|
|
179
|
-
bind(capability, owner) {
|
|
180
|
-
if (capability !== token || this.#owner !== undefined || this.#closed)
|
|
181
|
-
throw new Error("owner_unavailable");
|
|
182
|
-
if (this.#prepared === undefined)
|
|
183
|
-
this.prepare(token, owner);
|
|
184
|
-
if (this.#prepared.localOpener !== owner.localOpener || this.#prepared.kind !== owner.kind)
|
|
185
|
-
throw new V4MessageStreamError("definition_mismatch");
|
|
186
|
-
owner.check();
|
|
187
|
-
this.#owner = owner;
|
|
188
|
-
this.#direction = owner.direction;
|
|
189
|
-
owner.cleanupWith(() => this.#cleanup());
|
|
190
|
-
owner.invalidateWith(() => { if (this.#applicationInputDelivered)
|
|
191
|
-
this.#endIO();
|
|
192
|
-
else
|
|
193
|
-
this.#fail("closed"); });
|
|
194
|
-
owner.ioEndedWith(() => this.#endIO());
|
|
195
|
-
}
|
|
196
|
-
#check() {
|
|
197
|
-
if (this.#closed || this.#owner === undefined)
|
|
198
|
-
throw new V4MessageStreamError(this.#failure ?? "closed");
|
|
199
|
-
this.#owner.check();
|
|
200
|
-
return this.#owner;
|
|
201
|
-
}
|
|
202
|
-
#checkRead() {
|
|
203
|
-
if (!this.#applicationInputDelivered)
|
|
204
|
-
return this.#check();
|
|
205
|
-
if (this.#closed || this.#owner === undefined)
|
|
206
|
-
throw new V4MessageStreamError(this.#failure ?? "closed", undefined, true);
|
|
207
|
-
// The same application completion owns already-disclosed input. Revocation
|
|
208
|
-
// still prevents all future I/O, but cannot recall that original input.
|
|
209
|
-
return this.#owner;
|
|
210
|
-
}
|
|
211
|
-
#endIO() {
|
|
212
|
-
if (this.#closed || this.#ioEnded)
|
|
213
|
-
return;
|
|
214
|
-
// A complete empty frame has no body read to provide another wake.
|
|
215
|
-
if (this.#length === undefined && this.#prefixBytes === 4 && this.#prefix.every(byte => byte === 0)) {
|
|
216
|
-
const owner = this.#owner;
|
|
217
|
-
try {
|
|
218
|
-
this.#bodyReference = owner.reserve("v4_message_body", new ResourceVector([owner.runtimeBytes + 256n, 0n, 0n, 1n, 0n, 0n, 0n, 0n, 0n, 0n, 0n]));
|
|
219
|
-
this.#length = 0;
|
|
220
|
-
}
|
|
221
|
-
catch {
|
|
222
|
-
this.#fail("resource_exhausted");
|
|
223
|
-
return;
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
// Only a completely authenticated/assembled body can outlive transport.
|
|
227
|
-
if (this.#length === undefined || this.#filled !== this.#length || this.#bodyReference === undefined) {
|
|
228
|
-
this.#fail("closed");
|
|
229
|
-
return;
|
|
230
|
-
}
|
|
231
|
-
this.#ioEnded = true;
|
|
232
|
-
this.#sealed = true;
|
|
233
|
-
this.#stopAssembly();
|
|
234
|
-
this.#resourceObserver?.();
|
|
235
|
-
this.#resourceObserver = undefined;
|
|
236
|
-
for (const entry of this.#actualSends) {
|
|
237
|
-
entry.revoked = true;
|
|
238
|
-
entry.reason = "closed";
|
|
239
|
-
entry.abort.abort();
|
|
240
|
-
entry.request?.cancel();
|
|
241
|
-
this.#settleSend(entry, "closed");
|
|
242
|
-
if (!entry.running)
|
|
243
|
-
this.#releaseSend(entry);
|
|
244
|
-
}
|
|
245
|
-
this.#sends.length = 0;
|
|
246
|
-
if (this.#finTimer !== undefined)
|
|
247
|
-
clearTimeout(this.#finTimer);
|
|
248
|
-
this.#finTimer = undefined;
|
|
249
|
-
this.#finReject?.(new V4MessageStreamError("closed"));
|
|
250
|
-
this.#finReject = this.#finResolve = undefined;
|
|
251
|
-
if (!this.#readRunning)
|
|
252
|
-
this.#owner?.releaseReader();
|
|
253
|
-
this.#cleanup();
|
|
254
|
-
}
|
|
255
|
-
#snapshot(entry) {
|
|
256
|
-
const accepted = entry.accepted + (entry.request?.progress().accepted_bytes ?? 0n);
|
|
257
|
-
return result({ submission: accepted === 0n ? "not_submitted" : "submitted", stream_bytes_accepted_at_return: accepted,
|
|
258
|
-
publication_pending: accepted > 0n && !entry.done, cleanup_status: entry.done ? complete : pending });
|
|
259
|
-
}
|
|
260
|
-
#settleSend(entry, failure) {
|
|
261
|
-
if (entry.delivered)
|
|
262
|
-
return;
|
|
263
|
-
entry.delivered = true;
|
|
264
|
-
entry.signal?.removeEventListener("abort", entry.canceled);
|
|
265
|
-
if (failure === undefined) {
|
|
266
|
-
entry.resolve(this.#snapshot(entry));
|
|
267
|
-
}
|
|
268
|
-
else {
|
|
269
|
-
entry.diagnosticFailure = failure;
|
|
270
|
-
const error = new V4MessageStreamError(failure, this.#snapshot(entry));
|
|
271
|
-
entry.reject(error);
|
|
272
|
-
}
|
|
273
|
-
this.#finishSendDiagnostic(entry);
|
|
274
|
-
}
|
|
275
|
-
#finishSendDiagnostic(entry) {
|
|
276
|
-
if (!entry.done || !entry.delivered || entry.diagnosticFinished)
|
|
277
|
-
return;
|
|
278
|
-
entry.diagnosticFinished = true;
|
|
279
|
-
if (entry.diagnosticFailure !== undefined)
|
|
280
|
-
entry.diagnostic.failure(new V4MessageStreamError(entry.diagnosticFailure));
|
|
281
|
-
else {
|
|
282
|
-
entry.diagnostic.event({ state: "ready", code: "ok" });
|
|
283
|
-
entry.diagnostic.close();
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
send(value, options = {}) {
|
|
287
|
-
const diagnostic = new DiagnosticActivity(this.#owner?.diagnostics, "application");
|
|
288
|
-
let resolve, reject;
|
|
289
|
-
const promise = new NativePromise((yes, no) => { resolve = yes; reject = no; });
|
|
290
|
-
let reference, admitted;
|
|
291
|
-
try {
|
|
292
|
-
const owner = this.#check();
|
|
293
|
-
if (this.#sealed)
|
|
294
|
-
throw new V4MessageStreamError("closed");
|
|
295
|
-
if (options.signal?.aborted)
|
|
296
|
-
throw new V4MessageStreamError("canceled");
|
|
297
|
-
if (options.admission !== undefined && options.admission !== "queued" && options.admission !== "try_now")
|
|
298
|
-
throw new V4MessageStreamError("encode_failed");
|
|
299
|
-
if ((options.admission === "try_now" || applicationHasPermit(options.context)) && (this.#publishing || this.#sends.length !== 0))
|
|
300
|
-
throw new V4MessageStreamError("would_block");
|
|
301
|
-
if (this.#actualSends.size === 8 || this.#sendBytes + 4 > sendCap)
|
|
302
|
-
throw new V4MessageStreamError("resource_exhausted");
|
|
303
|
-
const maximum = this.#outbound.maximum, codec = this.#outbound.application;
|
|
304
|
-
const bytes = messageInputBytes(value, this.#outbound.implementation, maximum), outputBytes = codec === undefined ? 0 : 2 * maximum;
|
|
305
|
-
if (outputBytes + 4 > sendCap - this.#sendBytes)
|
|
306
|
-
throw new V4MessageStreamError("resource_exhausted");
|
|
307
|
-
const timeout = duration(options.timeoutMS, this.#options.sendTimeoutMS, this.#options.sendTimeoutMS), deadline = owner.deadline(timeout);
|
|
308
|
-
reference = owner.reserveSend("v4_message_send", new ResourceVector([BigInt(bytes + outputBytes) + (codec?.applicationBytes ?? 0n) + owner.runtimeBytes + 512n, 0n, 0n, 1n, 1n, 1n, 1n, 0n, 0n, 0n, 0n]));
|
|
309
|
-
const entry = { diagnostic, diagnosticFailure: undefined, diagnosticFinished: false, value, reference, deadline, signal: options.signal, canceled: () => this.#cancelSend(entry), resolve, reject, timer: undefined,
|
|
310
|
-
segments: undefined, request: undefined, capacity: outputBytes + 4, accepted: 0n, prefix: new Uint8Array(4), running: false, done: false, delivered: false, revoked: false, reason: undefined,
|
|
311
|
-
abort: new AbortController(), context: options.context, permit: undefined, payload: undefined, preparing: false, applicationContext: undefined };
|
|
312
|
-
this.#sendBytes += entry.capacity;
|
|
313
|
-
this.#actualSends.add(entry);
|
|
314
|
-
this.#sends.push(entry);
|
|
315
|
-
reference = undefined;
|
|
316
|
-
admitted = entry;
|
|
317
|
-
const guard = () => { this.#check(); entry.deadline.check(); if (entry.signal?.aborted || entry.revoked)
|
|
318
|
-
throw new V4MessageStreamError("canceled"); };
|
|
319
|
-
if (applicationHasPermit(options.context)) {
|
|
320
|
-
let used = false;
|
|
321
|
-
if (codec?.execution !== "async") {
|
|
322
|
-
entry.running = entry.preparing = true;
|
|
323
|
-
try {
|
|
324
|
-
const synchronous = owner.application.synchronous(options.context, guard, () => this.#encodeSend(entry, owner, guard, options.context));
|
|
325
|
-
used = synchronous.used;
|
|
326
|
-
}
|
|
327
|
-
finally {
|
|
328
|
-
entry.running = entry.preparing = false;
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
if (!used)
|
|
332
|
-
entry.permit = owner.application.tryOrdinary("short", options.context);
|
|
333
|
-
}
|
|
334
|
-
else if (options.admission === "try_now")
|
|
335
|
-
entry.permit = owner.application.tryOrdinary("short");
|
|
336
|
-
const expire = () => {
|
|
337
|
-
try {
|
|
338
|
-
entry.deadline.check();
|
|
339
|
-
entry.timer = setTimeout(expire, timerChunk(entry.deadline.remainingMS()));
|
|
340
|
-
}
|
|
341
|
-
catch {
|
|
342
|
-
entry.timer = undefined;
|
|
343
|
-
this.#cancelSend(entry, "deadline_exceeded");
|
|
344
|
-
}
|
|
345
|
-
};
|
|
346
|
-
entry.signal?.addEventListener("abort", entry.canceled, { once: true });
|
|
347
|
-
expire();
|
|
348
|
-
enqueue(() => { if (entry.signal?.aborted)
|
|
349
|
-
this.#cancelSend(entry); this.#publish(); });
|
|
350
|
-
}
|
|
351
|
-
catch (error) {
|
|
352
|
-
reference?.release();
|
|
353
|
-
const code = error instanceof V4MessageStreamError ? error.code : error instanceof ResourceError ? "resource_exhausted" :
|
|
354
|
-
error instanceof Error && (error.message === "dependency_unavailable" || error.message === "would_block") ? error.message : "encode_failed";
|
|
355
|
-
if (admitted !== undefined) {
|
|
356
|
-
this.#cancelSend(admitted, code);
|
|
357
|
-
return promise;
|
|
358
|
-
}
|
|
359
|
-
diagnostic.failure(new V4MessageStreamError(code));
|
|
360
|
-
reject(new V4MessageStreamError(code, result({ submission: "not_submitted", stream_bytes_accepted_at_return: 0n, publication_pending: false, cleanup_status: complete })));
|
|
361
|
-
}
|
|
362
|
-
return promise;
|
|
363
|
-
}
|
|
364
|
-
#cancelSend(entry, reason = "canceled") {
|
|
365
|
-
if (entry.done)
|
|
366
|
-
return;
|
|
367
|
-
const submitted = entry.accepted + (entry.request?.progress().accepted_bytes ?? 0n) > 0n;
|
|
368
|
-
if (!submitted) {
|
|
369
|
-
entry.revoked = true;
|
|
370
|
-
entry.reason = reason;
|
|
371
|
-
entry.abort.abort();
|
|
372
|
-
entry.request?.cancel();
|
|
373
|
-
const i = this.#sends.indexOf(entry);
|
|
374
|
-
if (i >= 0)
|
|
375
|
-
this.#sends.splice(i, 1);
|
|
376
|
-
if (entry.preparing && this.#publisher === entry) {
|
|
377
|
-
this.#publisher = undefined;
|
|
378
|
-
this.#publishing = false;
|
|
379
|
-
}
|
|
380
|
-
}
|
|
381
|
-
else if (reason !== "canceled") {
|
|
382
|
-
entry.reason = reason;
|
|
383
|
-
entry.request?.cancel();
|
|
384
|
-
this.#fail(reason);
|
|
385
|
-
}
|
|
386
|
-
this.#settleSend(entry, reason);
|
|
387
|
-
if (!entry.running)
|
|
388
|
-
this.#releaseSend(entry);
|
|
389
|
-
this.#publish();
|
|
390
|
-
}
|
|
391
|
-
#publish() {
|
|
392
|
-
if (this.#publishing || this.#closed || this.#ioEnded)
|
|
393
|
-
return;
|
|
394
|
-
const entry = this.#sends[0];
|
|
395
|
-
if (entry === undefined) {
|
|
396
|
-
this.#startFIN();
|
|
397
|
-
return;
|
|
398
|
-
}
|
|
399
|
-
this.#publishing = true;
|
|
400
|
-
this.#publisher = entry;
|
|
401
|
-
void this.#runSend(entry).finally(() => {
|
|
402
|
-
if (this.#publisher === entry) {
|
|
403
|
-
this.#publisher = undefined;
|
|
404
|
-
this.#publishing = false;
|
|
405
|
-
}
|
|
406
|
-
this.#publish();
|
|
407
|
-
this.#cleanup();
|
|
408
|
-
});
|
|
409
|
-
}
|
|
410
|
-
#encodeSend(entry, owner, guard, context) {
|
|
411
|
-
guard();
|
|
412
|
-
const codec = this.#outbound.application;
|
|
413
|
-
if (codec !== undefined) {
|
|
414
|
-
if (codec.execution !== "sync" || context === undefined)
|
|
415
|
-
throw new V4MessageStreamError("encode_failed");
|
|
416
|
-
entry.applicationContext = context;
|
|
417
|
-
try {
|
|
418
|
-
let output;
|
|
419
|
-
try {
|
|
420
|
-
output = codec.encode(context, entry.value);
|
|
421
|
-
}
|
|
422
|
-
catch {
|
|
423
|
-
throw new V4MessageStreamError("encode_failed");
|
|
424
|
-
}
|
|
425
|
-
this.#sealApplicationOutput(entry, guard, output);
|
|
426
|
-
output = undefined;
|
|
427
|
-
this.#finishApplicationEncoding(entry, owner);
|
|
428
|
-
}
|
|
429
|
-
finally {
|
|
430
|
-
entry.applicationContext = undefined;
|
|
431
|
-
}
|
|
432
|
-
return;
|
|
433
|
-
}
|
|
434
|
-
const segments = entry.segments = new MessageSegments(this.#outbound.maximum, owner.runtimeBytes, (charge, capacity) => {
|
|
435
|
-
guard();
|
|
436
|
-
if (capacity > sendCap - this.#sendBytes)
|
|
437
|
-
throw new ResourceError("resource_exhausted");
|
|
438
|
-
const ref = owner.reserveSend("v4_message_segment", charge);
|
|
439
|
-
this.#sendBytes += capacity;
|
|
440
|
-
entry.capacity += capacity;
|
|
441
|
-
return ref;
|
|
442
|
-
}, guard);
|
|
443
|
-
if (this.#outbound.implementation === "bytes")
|
|
444
|
-
segments.append(entry.value);
|
|
445
|
-
else
|
|
446
|
-
segments.utf8(entry.value);
|
|
447
|
-
entry.payload = segments.finalize();
|
|
448
|
-
entry.value = undefined;
|
|
449
|
-
new DataView(entry.prefix.buffer).setUint32(0, segments.length);
|
|
450
|
-
entry.reference.shrink(new ResourceVector([owner.runtimeBytes + 512n, 0n, 0n, 1n, 1n, 1n, 1n, 0n, 0n, 0n, 0n]));
|
|
451
|
-
}
|
|
452
|
-
#sealApplicationOutput(entry, guard, value) {
|
|
453
|
-
guard();
|
|
454
|
-
let source = checkApplicationMessageOutput(value, this.#outbound.maximum);
|
|
455
|
-
const length = byteLength(source), owned = new Uint8Array(length);
|
|
456
|
-
copy.call(owned, source);
|
|
457
|
-
source = undefined;
|
|
458
|
-
value = undefined;
|
|
459
|
-
entry.value = undefined;
|
|
460
|
-
entry.payload = [owned];
|
|
461
|
-
new DataView(entry.prefix.buffer).setUint32(0, length);
|
|
462
|
-
}
|
|
463
|
-
#finishApplicationEncoding(entry, owner) {
|
|
464
|
-
const length = byteLength(entry.payload[0]);
|
|
465
|
-
this.#sendBytes -= entry.capacity - length - 4;
|
|
466
|
-
entry.capacity = length + 4;
|
|
467
|
-
entry.reference.shrink(new ResourceVector([BigInt(length) + owner.runtimeBytes + 512n, 0n, 0n, 1n, 1n, 1n, 1n, 0n, 0n, 0n, 0n]));
|
|
468
|
-
}
|
|
469
|
-
async #runSend(entry) {
|
|
470
|
-
entry.running = true;
|
|
471
|
-
let failure;
|
|
472
|
-
let applicationTail;
|
|
473
|
-
try {
|
|
474
|
-
const owner = this.#check();
|
|
475
|
-
const guard = () => { this.#check(); entry.deadline.check(); if (entry.revoked)
|
|
476
|
-
throw new V4MessageStreamError(entry.reason ?? "canceled"); };
|
|
477
|
-
guard();
|
|
478
|
-
if (entry.payload === undefined) {
|
|
479
|
-
entry.preparing = true;
|
|
480
|
-
let invocation;
|
|
481
|
-
try {
|
|
482
|
-
entry.permit ??= await owner.application.acquire("short", entry.abort.signal, guard, entry.context);
|
|
483
|
-
guard();
|
|
484
|
-
const codec = this.#outbound.application;
|
|
485
|
-
if (codec !== undefined) {
|
|
486
|
-
if (owner.authentication === undefined)
|
|
487
|
-
throw new V4MessageStreamError("encode_failed");
|
|
488
|
-
invocation = owner.application.context(entry.permit, owner.authentication, entry.abort.signal);
|
|
489
|
-
entry.applicationContext = invocation.context;
|
|
490
|
-
applicationTail = owner.sessionCleanup.startApplicationCallback();
|
|
491
|
-
if (codec.execution === "async") {
|
|
492
|
-
let output;
|
|
493
|
-
try {
|
|
494
|
-
output = await codec.encode(invocation.context, entry.value);
|
|
495
|
-
}
|
|
496
|
-
catch {
|
|
497
|
-
throw new V4MessageStreamError("encode_failed");
|
|
498
|
-
}
|
|
499
|
-
this.#sealApplicationOutput(entry, guard, output);
|
|
500
|
-
output = undefined;
|
|
501
|
-
this.#finishApplicationEncoding(entry, owner);
|
|
502
|
-
}
|
|
503
|
-
else
|
|
504
|
-
this.#encodeSend(entry, owner, guard, invocation.context);
|
|
505
|
-
}
|
|
506
|
-
else
|
|
507
|
-
this.#encodeSend(entry, owner, guard);
|
|
508
|
-
}
|
|
509
|
-
finally {
|
|
510
|
-
invocation?.release();
|
|
511
|
-
entry.applicationContext = undefined;
|
|
512
|
-
entry.permit?.release();
|
|
513
|
-
entry.permit = undefined;
|
|
514
|
-
entry.preparing = false;
|
|
515
|
-
applicationTail?.callbackExited();
|
|
516
|
-
}
|
|
517
|
-
}
|
|
518
|
-
const payload = entry.payload;
|
|
519
|
-
for (const bytes of [entry.prefix, ...payload]) {
|
|
520
|
-
for (let at = 0; at < bytes.length;) {
|
|
521
|
-
guard();
|
|
522
|
-
const count = Math.min(owner.maxWriteBytes, bytes.length - at);
|
|
523
|
-
if (count > sendCap - this.#sendBytes)
|
|
524
|
-
throw new ResourceError("resource_exhausted");
|
|
525
|
-
const remaining = entry.deadline.remainingMS(), request = owner.prepareWrite(byteSlice(bytes, at, at + count), remaining < owner.maxWriteMilliseconds ? remaining : owner.maxWriteMilliseconds);
|
|
526
|
-
entry.request = request;
|
|
527
|
-
this.#sendBytes += count;
|
|
528
|
-
try {
|
|
529
|
-
if (entry.revoked)
|
|
530
|
-
request.cancel();
|
|
531
|
-
request.start();
|
|
532
|
-
const progress = await request.wait();
|
|
533
|
-
await request.waitCleanup();
|
|
534
|
-
entry.accepted += progress.accepted_bytes;
|
|
535
|
-
entry.request = undefined;
|
|
536
|
-
if (progress.accepted_bytes !== BigInt(count) || progress.terminal_reason !== "complete")
|
|
537
|
-
throw new V4MessageStreamError(entry.reason ?? "write_failed");
|
|
538
|
-
at += count;
|
|
539
|
-
}
|
|
540
|
-
finally {
|
|
541
|
-
this.#sendBytes -= count;
|
|
542
|
-
}
|
|
543
|
-
}
|
|
544
|
-
}
|
|
545
|
-
}
|
|
546
|
-
catch (error) {
|
|
547
|
-
failure = entry.reason ?? (error instanceof V4MessageStreamError ? error.code : error instanceof ResourceError ? "resource_exhausted" : "encode_failed");
|
|
548
|
-
if (!this.#ioEnded && entry.accepted + (entry.request?.progress().accepted_bytes ?? 0n) > 0n)
|
|
549
|
-
this.#fail(failure);
|
|
550
|
-
}
|
|
551
|
-
finally {
|
|
552
|
-
if (entry.request !== undefined) {
|
|
553
|
-
entry.request.cancel();
|
|
554
|
-
await entry.request.waitCleanup();
|
|
555
|
-
entry.accepted += entry.request.progress().accepted_bytes;
|
|
556
|
-
entry.request = undefined;
|
|
557
|
-
}
|
|
558
|
-
const i = this.#sends.indexOf(entry);
|
|
559
|
-
if (i >= 0)
|
|
560
|
-
this.#sends.splice(i, 1);
|
|
561
|
-
applicationTail?.finish();
|
|
562
|
-
entry.running = false;
|
|
563
|
-
this.#releaseSend(entry);
|
|
564
|
-
this.#settleSend(entry, failure);
|
|
565
|
-
}
|
|
566
|
-
}
|
|
567
|
-
#releaseSend(entry) {
|
|
568
|
-
if (entry.done)
|
|
569
|
-
return;
|
|
570
|
-
entry.done = true;
|
|
571
|
-
if (entry.timer !== undefined)
|
|
572
|
-
clearTimeout(entry.timer);
|
|
573
|
-
entry.timer = undefined;
|
|
574
|
-
entry.signal?.removeEventListener("abort", entry.canceled);
|
|
575
|
-
entry.value = undefined;
|
|
576
|
-
entry.permit?.release();
|
|
577
|
-
entry.permit = undefined;
|
|
578
|
-
if (entry.segments === undefined)
|
|
579
|
-
for (const bytes of entry.payload ?? [])
|
|
580
|
-
bytes.fill(0);
|
|
581
|
-
entry.segments?.close();
|
|
582
|
-
entry.segments = undefined;
|
|
583
|
-
entry.payload = undefined;
|
|
584
|
-
entry.prefix.fill(0);
|
|
585
|
-
entry.prefix = empty;
|
|
586
|
-
this.#sendBytes -= entry.capacity;
|
|
587
|
-
entry.capacity = 0;
|
|
588
|
-
entry.reference.release();
|
|
589
|
-
this.#actualSends.delete(entry);
|
|
590
|
-
this.#finishSendDiagnostic(entry);
|
|
591
|
-
}
|
|
592
|
-
receive(options) { return this.#receive(false, options); }
|
|
593
|
-
receiveEncoded(options) { return this.#receive(true, options); }
|
|
594
|
-
#receive(encoded, options) {
|
|
595
|
-
const diagnostic = new DiagnosticActivity(this.#owner?.diagnostics, "application");
|
|
596
|
-
let resolve, reject;
|
|
597
|
-
const promise = new NativePromise((yes, no) => { resolve = yes; reject = no; });
|
|
598
|
-
try {
|
|
599
|
-
this.#checkRead();
|
|
600
|
-
if (applicationDependsOn(options?.context, this.#decodeContext))
|
|
601
|
-
throw new V4MessageStreamError("dependency_unavailable", undefined, this.#applicationInputDelivered);
|
|
602
|
-
if (this.#readWait !== undefined)
|
|
603
|
-
throw new V4MessageStreamError("read_in_progress");
|
|
604
|
-
if (this.#ioEnded && this.#length === undefined)
|
|
605
|
-
throw new V4MessageStreamError("closed");
|
|
606
|
-
if (options?.signal?.aborted)
|
|
607
|
-
throw new V4MessageStreamError("canceled");
|
|
608
|
-
applicationHasPermit(options?.context);
|
|
609
|
-
if (encoded && this.#applicationInputDelivered)
|
|
610
|
-
throw new V4MessageStreamError("result_mode_conflict", undefined, true, this.#codecIdentity());
|
|
611
|
-
const wait = { diagnostic, diagnosticOutcome: undefined, diagnosticFinished: false, encoded, signal: options?.signal, context: options?.context, claim: undefined, resolve, reject, canceled: () => {
|
|
612
|
-
if (this.#readWait !== wait || this.#handoff)
|
|
613
|
-
return;
|
|
614
|
-
this.#readWait = undefined;
|
|
615
|
-
wait.signal?.removeEventListener("abort", wait.canceled);
|
|
616
|
-
if (!this.#decoded && !this.#applicationInputDelivered && this.#typedPrepaid && this.#bodyReference !== undefined && this.#length !== undefined) {
|
|
617
|
-
try {
|
|
618
|
-
this.#bodyReference.shrink(new ResourceVector([BigInt(this.#body.buffer.byteLength) + this.#owner.runtimeBytes + 256n, 0n, 0n, 1n, 0n, 0n, 0n, 0n, 0n, 0n, 0n]));
|
|
619
|
-
this.#typedPrepaid = false;
|
|
620
|
-
}
|
|
621
|
-
catch { /* Closed roots retain the original charge until cleanup. */ }
|
|
622
|
-
}
|
|
623
|
-
if (!this.#decoded && !this.#applicationInputDelivered) {
|
|
624
|
-
this.#typedReference?.release();
|
|
625
|
-
this.#typedReference = undefined;
|
|
626
|
-
this.#completion?.close();
|
|
627
|
-
this.#completion = undefined;
|
|
628
|
-
}
|
|
629
|
-
wait.claim?.release();
|
|
630
|
-
wait.claim = undefined;
|
|
631
|
-
if (this.#dependencyTimer !== undefined)
|
|
632
|
-
clearTimeout(this.#dependencyTimer);
|
|
633
|
-
this.#dependencyTimer = undefined;
|
|
634
|
-
const error = new V4MessageStreamError("canceled", undefined, this.#applicationInputDelivered);
|
|
635
|
-
this.#readAbort?.abort();
|
|
636
|
-
wait.diagnosticOutcome = error;
|
|
637
|
-
this.#finishReadDiagnostic(wait);
|
|
638
|
-
wait.reject(error);
|
|
639
|
-
} };
|
|
640
|
-
this.#readWait = wait;
|
|
641
|
-
wait.signal?.addEventListener("abort", wait.canceled, { once: true });
|
|
642
|
-
this.#scheduleRead();
|
|
643
|
-
}
|
|
644
|
-
catch (error) {
|
|
645
|
-
const failure = error instanceof V4MessageStreamError ? error : new V4MessageStreamError(error instanceof Error && error.message === "dependency_unavailable" ? "dependency_unavailable" : "closed");
|
|
646
|
-
diagnostic.failure(failure);
|
|
647
|
-
reject(failure);
|
|
648
|
-
}
|
|
649
|
-
return promise;
|
|
650
|
-
}
|
|
651
|
-
#finishReadDiagnostic(wait) {
|
|
652
|
-
if (wait === this.#readOwner || wait.diagnosticOutcome === undefined || wait.diagnosticFinished)
|
|
653
|
-
return;
|
|
654
|
-
wait.diagnosticFinished = true;
|
|
655
|
-
if (wait.diagnosticOutcome === "ready") {
|
|
656
|
-
wait.diagnostic.event({ state: "ready", code: "ok" });
|
|
657
|
-
wait.diagnostic.close();
|
|
658
|
-
}
|
|
659
|
-
else
|
|
660
|
-
wait.diagnostic.failure(wait.diagnosticOutcome);
|
|
661
|
-
}
|
|
662
|
-
#releaseReadOwner() {
|
|
663
|
-
const original = this.#readOwner;
|
|
664
|
-
this.#readOwner = undefined;
|
|
665
|
-
if (original !== undefined)
|
|
666
|
-
this.#finishReadDiagnostic(original);
|
|
667
|
-
}
|
|
668
|
-
#scheduleRead() {
|
|
669
|
-
if (this.#readScheduled || this.#readRunning || this.#closed || this.#readWait === undefined)
|
|
670
|
-
return;
|
|
671
|
-
this.#readScheduled = true;
|
|
672
|
-
enqueue(() => { this.#readScheduled = false; if (!this.#closed && this.#readWait !== undefined)
|
|
673
|
-
void this.#runRead(); });
|
|
674
|
-
}
|
|
675
|
-
#startAssembly() {
|
|
676
|
-
if (this.#assembly !== undefined)
|
|
677
|
-
return;
|
|
678
|
-
this.#assembly = this.#owner.deadline(this.#options.assemblyTimeoutMS);
|
|
679
|
-
const tick = () => {
|
|
680
|
-
try {
|
|
681
|
-
this.#assembly.check();
|
|
682
|
-
this.#assemblyTimer = setTimeout(tick, timerChunk(this.#assembly.remainingMS()));
|
|
683
|
-
}
|
|
684
|
-
catch {
|
|
685
|
-
this.#assemblyTimer = undefined;
|
|
686
|
-
this.#fail("deadline_exceeded");
|
|
687
|
-
}
|
|
688
|
-
};
|
|
689
|
-
tick();
|
|
690
|
-
}
|
|
691
|
-
#stopAssembly() { if (this.#assemblyTimer !== undefined)
|
|
692
|
-
clearTimeout(this.#assemblyTimer); this.#assemblyTimer = undefined; this.#assembly = undefined; }
|
|
693
|
-
#bodyAdmission(wait) {
|
|
694
|
-
const owner = this.#owner, n = this.#length, typed = !wait.encoded;
|
|
695
|
-
const dependent = applicationHasCompletionAncestor(wait.context);
|
|
696
|
-
let completion;
|
|
697
|
-
try {
|
|
698
|
-
if (dependent) {
|
|
699
|
-
this.#dependencyDeadline ??= owner.deadline(30000n);
|
|
700
|
-
this.#dependencyDeadline.check();
|
|
701
|
-
if (typed && wait.claim?.active !== true)
|
|
702
|
-
wait.claim = owner.application.claimCompletion(wait.context);
|
|
703
|
-
if (this.#dependencyTimer === undefined) {
|
|
704
|
-
const tick = () => {
|
|
705
|
-
try {
|
|
706
|
-
this.#dependencyDeadline.check();
|
|
707
|
-
this.#dependencyTimer = setTimeout(tick, timerChunk(this.#dependencyDeadline.remainingMS()));
|
|
708
|
-
}
|
|
709
|
-
catch {
|
|
710
|
-
this.#dependencyTimer = undefined;
|
|
711
|
-
const current = this.#readWait;
|
|
712
|
-
if (current !== undefined && current.context !== undefined)
|
|
713
|
-
this.#rejectRead(current, "completion_dependency_unavailable");
|
|
714
|
-
}
|
|
715
|
-
};
|
|
716
|
-
tick();
|
|
717
|
-
}
|
|
718
|
-
}
|
|
719
|
-
if (typed && this.#completion === undefined)
|
|
720
|
-
completion = owner.application.reserveCompletion();
|
|
721
|
-
if (this.#bodyReference === undefined) {
|
|
722
|
-
const extra = typed ? (this.#inbound.implementation === "utf8" ? BigInt(n) * 2n : 0n) + (this.#inbound.application?.applicationBytes ?? 0n) + owner.runtimeBytes + 256n : 0n;
|
|
723
|
-
const body = owner.admitBody(n, new ResourceVector([owner.runtimeBytes + 256n + extra, 0n, 0n, typed ? 2n : 1n, typed ? 1n : 0n, typed ? 1n : 0n, 0n, 0n, 0n, 0n, 0n]));
|
|
724
|
-
this.#bodyReference = body.reference;
|
|
725
|
-
this.#typedPrepaid = typed;
|
|
726
|
-
this.#body = body.bytes;
|
|
727
|
-
}
|
|
728
|
-
if (typed && !this.#typedPrepaid && this.#typedReference === undefined)
|
|
729
|
-
this.#typedReference = owner.reserve("v4_message_decode", new ResourceVector([
|
|
730
|
-
(this.#inbound.implementation === "utf8" ? BigInt(n) * 2n : 0n) + (this.#inbound.application?.applicationBytes ?? 0n) + owner.runtimeBytes + 256n, 0n, 0n, 1n, 1n, 1n, 0n, 0n, 0n, 0n, 0n,
|
|
731
|
-
]));
|
|
732
|
-
if (completion !== undefined) {
|
|
733
|
-
this.#completion = completion;
|
|
734
|
-
completion = undefined;
|
|
735
|
-
}
|
|
736
|
-
const observe = this.#resourceObserver;
|
|
737
|
-
this.#resourceObserver = undefined;
|
|
738
|
-
observe?.();
|
|
739
|
-
this.#readAdmissionBlocked = false;
|
|
740
|
-
owner.pauseCredit(false);
|
|
741
|
-
return true;
|
|
742
|
-
}
|
|
743
|
-
catch (error) {
|
|
744
|
-
completion?.close();
|
|
745
|
-
wait.claim?.release();
|
|
746
|
-
wait.claim = undefined;
|
|
747
|
-
if (dependent) {
|
|
748
|
-
this.#rejectRead(wait, "completion_dependency_unavailable");
|
|
749
|
-
return false;
|
|
750
|
-
}
|
|
751
|
-
if (!(error instanceof ResourceError) || error.code !== "resource_exhausted")
|
|
752
|
-
throw error;
|
|
753
|
-
owner.pauseCredit(true);
|
|
754
|
-
// No short cursor/borrow is held while waiting for a complete vector.
|
|
755
|
-
owner.releaseReader();
|
|
756
|
-
this.#readAdmissionBlocked = true;
|
|
757
|
-
this.#resourceObserver ??= owner.observeResources(() => {
|
|
758
|
-
if (this.#readRunning) {
|
|
759
|
-
this.#readAdmissionBlocked = false;
|
|
760
|
-
return;
|
|
761
|
-
}
|
|
762
|
-
this.#scheduleRead();
|
|
763
|
-
});
|
|
764
|
-
return false;
|
|
765
|
-
}
|
|
766
|
-
}
|
|
767
|
-
async #runRead() {
|
|
768
|
-
if (this.#readRunning)
|
|
769
|
-
return;
|
|
770
|
-
this.#readRunning = true;
|
|
771
|
-
// A failed attempt's own temporary refunds are not new capacity. Subscribe
|
|
772
|
-
// only after the attempt exits; subsequent owner transitions wake it once.
|
|
773
|
-
const observe = this.#resourceObserver;
|
|
774
|
-
this.#resourceObserver = undefined;
|
|
775
|
-
observe?.();
|
|
776
|
-
try {
|
|
777
|
-
while (this.#readWait !== undefined && !this.#closed) {
|
|
778
|
-
this.#releaseReadOwner();
|
|
779
|
-
this.#readOwner = this.#readWait;
|
|
780
|
-
const owner = this.#checkRead();
|
|
781
|
-
if (this.#readWait === undefined || this.#closed)
|
|
782
|
-
break;
|
|
783
|
-
if (this.#eof) {
|
|
784
|
-
this.#deliverRead();
|
|
785
|
-
break;
|
|
786
|
-
}
|
|
787
|
-
if (this.#prefixBytes === 0 && this.#length === undefined) {
|
|
788
|
-
try {
|
|
789
|
-
owner.ensureReadQueue();
|
|
790
|
-
}
|
|
791
|
-
catch (error) {
|
|
792
|
-
if (!(error instanceof ResourceError) || error.code !== "resource_exhausted")
|
|
793
|
-
throw error;
|
|
794
|
-
owner.pauseCredit(true);
|
|
795
|
-
owner.releaseReader();
|
|
796
|
-
this.#readAdmissionBlocked = true;
|
|
797
|
-
this.#resourceObserver ??= owner.observeResources(() => {
|
|
798
|
-
if (this.#readRunning) {
|
|
799
|
-
this.#readAdmissionBlocked = false;
|
|
800
|
-
return;
|
|
801
|
-
}
|
|
802
|
-
this.#scheduleRead();
|
|
803
|
-
});
|
|
804
|
-
break;
|
|
805
|
-
}
|
|
806
|
-
this.#readAdmissionBlocked = false;
|
|
807
|
-
owner.pauseCredit(false);
|
|
808
|
-
}
|
|
809
|
-
if (this.#prefixBytes === 4 && this.#length === undefined) {
|
|
810
|
-
this.#length = new DataView(this.#prefix.buffer).getUint32(0);
|
|
811
|
-
if (this.#length > this.#inbound.maximum) {
|
|
812
|
-
this.#fail("framing_error");
|
|
813
|
-
break;
|
|
814
|
-
}
|
|
815
|
-
}
|
|
816
|
-
if (this.#length !== undefined && !this.#bodyAdmission(this.#readWait))
|
|
817
|
-
break;
|
|
818
|
-
if (this.#length !== undefined && this.#filled === this.#length) {
|
|
819
|
-
this.#stopAssembly();
|
|
820
|
-
owner.releaseReader();
|
|
821
|
-
if (!this.#readWait.encoded && !this.#decoded) {
|
|
822
|
-
const wait = this.#readWait, abort = this.#readAbort = new AbortController();
|
|
823
|
-
let permit;
|
|
824
|
-
const check = () => {
|
|
825
|
-
this.#check();
|
|
826
|
-
if (this.#readWait !== wait || abort.signal.aborted)
|
|
827
|
-
throw new Error("canceled");
|
|
828
|
-
if (wait.context !== undefined) {
|
|
829
|
-
applicationHasPermit(wait.context);
|
|
830
|
-
if (applicationHasCompletionAncestor(wait.context))
|
|
831
|
-
this.#dependencyDeadline?.check();
|
|
832
|
-
}
|
|
833
|
-
};
|
|
834
|
-
try {
|
|
835
|
-
permit = await this.#completion.acquire(abort.signal, check, wait.context, wait.claim);
|
|
836
|
-
wait.claim = undefined;
|
|
837
|
-
check();
|
|
838
|
-
const codec = this.#inbound.application;
|
|
839
|
-
if (codec === undefined) {
|
|
840
|
-
try {
|
|
841
|
-
this.#value = this.#inbound.implementation === "bytes" ? this.#body : nativeDecode.call(utf8, this.#body);
|
|
842
|
-
}
|
|
843
|
-
catch {
|
|
844
|
-
this.#fail("framing_error");
|
|
845
|
-
break;
|
|
846
|
-
}
|
|
847
|
-
}
|
|
848
|
-
else {
|
|
849
|
-
if (owner.authentication === undefined)
|
|
850
|
-
throw new V4MessageStreamError("decode_failed");
|
|
851
|
-
const decodeAbort = this.#decodeAbort = new AbortController();
|
|
852
|
-
const invocation = owner.application.context(permit, owner.authentication, decodeAbort.signal);
|
|
853
|
-
try {
|
|
854
|
-
check();
|
|
855
|
-
this.#decodeContext = invocation.context;
|
|
856
|
-
this.#decoding = true;
|
|
857
|
-
this.#applicationInputDelivered = true;
|
|
858
|
-
this.#readAbort = undefined;
|
|
859
|
-
try {
|
|
860
|
-
if (codec.execution === "sync")
|
|
861
|
-
this.#value = codec.decode(invocation.context, this.#body);
|
|
862
|
-
else {
|
|
863
|
-
const output = codec.decode(invocation.context, this.#body);
|
|
864
|
-
this.#cleanup();
|
|
865
|
-
this.#value = await output;
|
|
866
|
-
}
|
|
867
|
-
}
|
|
868
|
-
catch {
|
|
869
|
-
this.#decodeFailed = true;
|
|
870
|
-
}
|
|
871
|
-
}
|
|
872
|
-
finally {
|
|
873
|
-
invocation.release();
|
|
874
|
-
this.#decodeContext = undefined;
|
|
875
|
-
this.#decodeAbort = undefined;
|
|
876
|
-
this.#decoding = false;
|
|
877
|
-
}
|
|
878
|
-
}
|
|
879
|
-
this.#decoded = true;
|
|
880
|
-
}
|
|
881
|
-
catch {
|
|
882
|
-
if (this.#readWait === wait)
|
|
883
|
-
this.#rejectRead(wait, "completion_dependency_unavailable");
|
|
884
|
-
break;
|
|
885
|
-
}
|
|
886
|
-
finally {
|
|
887
|
-
permit?.release();
|
|
888
|
-
if (this.#readAbort === abort)
|
|
889
|
-
this.#readAbort = undefined;
|
|
890
|
-
}
|
|
891
|
-
}
|
|
892
|
-
this.#deliverRead();
|
|
893
|
-
break;
|
|
894
|
-
}
|
|
895
|
-
const before = owner.readState();
|
|
896
|
-
if (before.stream_status !== "open") {
|
|
897
|
-
if (before.stream_status === "eof" && this.#prefixBytes === 0) {
|
|
898
|
-
this.#eof = true;
|
|
899
|
-
owner.releaseReader();
|
|
900
|
-
continue;
|
|
901
|
-
}
|
|
902
|
-
this.#fail("framing_error");
|
|
903
|
-
break;
|
|
904
|
-
}
|
|
905
|
-
const abort = this.#readAbort = new AbortController();
|
|
906
|
-
await owner.readInto(this.#length === undefined ? 4 - this.#prefixBytes : this.#length - this.#filled, bytes => {
|
|
907
|
-
if (this.#closed || abort.signal.aborted)
|
|
908
|
-
return 0;
|
|
909
|
-
if (this.#prefixBytes === 0)
|
|
910
|
-
this.#startAssembly();
|
|
911
|
-
else
|
|
912
|
-
this.#assembly?.check();
|
|
913
|
-
const n = byteLength(bytes);
|
|
914
|
-
if (this.#length === undefined) {
|
|
915
|
-
copy.call(this.#prefix, bytes, this.#prefixBytes);
|
|
916
|
-
this.#prefixBytes += n;
|
|
917
|
-
if (this.#prefixBytes === 4)
|
|
918
|
-
owner.pauseCredit(true);
|
|
919
|
-
}
|
|
920
|
-
else {
|
|
921
|
-
copy.call(this.#body, bytes, this.#filled);
|
|
922
|
-
this.#filled += n;
|
|
923
|
-
if (this.#filled === this.#length)
|
|
924
|
-
this.#stopAssembly();
|
|
925
|
-
}
|
|
926
|
-
return n;
|
|
927
|
-
}, abort.signal);
|
|
928
|
-
this.#readAbort = undefined;
|
|
929
|
-
const state = owner.readState();
|
|
930
|
-
if (state.stream_status !== "open") {
|
|
931
|
-
if (state.stream_status === "eof" && this.#prefixBytes === 0) {
|
|
932
|
-
this.#eof = true;
|
|
933
|
-
owner.releaseReader();
|
|
934
|
-
}
|
|
935
|
-
else if (!(this.#ioEnded && this.#length !== undefined && this.#filled === this.#length) &&
|
|
936
|
-
(state.stream_status !== "eof" || this.#prefixBytes < 4 || this.#length !== undefined && this.#filled < this.#length)) {
|
|
937
|
-
this.#fail("framing_error");
|
|
938
|
-
break;
|
|
939
|
-
}
|
|
940
|
-
else if (this.#length === undefined && new DataView(this.#prefix.buffer).getUint32(0) !== 0) {
|
|
941
|
-
this.#fail("framing_error");
|
|
942
|
-
break;
|
|
943
|
-
}
|
|
944
|
-
}
|
|
945
|
-
}
|
|
946
|
-
}
|
|
947
|
-
catch {
|
|
948
|
-
if (!this.#readAbort?.signal.aborted && !this.#closed)
|
|
949
|
-
this.#fail("framing_error");
|
|
950
|
-
}
|
|
951
|
-
finally {
|
|
952
|
-
this.#readAbort = undefined;
|
|
953
|
-
this.#readRunning = false;
|
|
954
|
-
if (this.#closed) {
|
|
955
|
-
this.#owner?.releaseReader();
|
|
956
|
-
this.#clearBody();
|
|
957
|
-
}
|
|
958
|
-
else if (this.#ioEnded)
|
|
959
|
-
this.#owner?.releaseReader();
|
|
960
|
-
this.#cleanup();
|
|
961
|
-
this.#releaseReadOwner();
|
|
962
|
-
// A replacement waiter may have arrived while the old native read exited.
|
|
963
|
-
if (!this.#closed && this.#readWait !== undefined && !this.#readAdmissionBlocked)
|
|
964
|
-
this.#scheduleRead();
|
|
965
|
-
}
|
|
966
|
-
}
|
|
967
|
-
#codecIdentity() {
|
|
968
|
-
const inbound = this.#inbound;
|
|
969
|
-
return inbound === undefined ? undefined : result({
|
|
970
|
-
codec_schema_digest: new Uint8Array(inbound.schema), codec_revision: inbound.revision,
|
|
971
|
-
});
|
|
972
|
-
}
|
|
973
|
-
#deliverRead() {
|
|
974
|
-
const wait = this.#readWait;
|
|
975
|
-
if (wait === undefined || wait.signal?.aborted)
|
|
976
|
-
return;
|
|
977
|
-
this.#checkRead();
|
|
978
|
-
if (this.#readWait !== wait || wait.signal?.aborted || this.#closed)
|
|
979
|
-
return;
|
|
980
|
-
const identity = this.#codecIdentity();
|
|
981
|
-
if (!this.#eof && identity === undefined) {
|
|
982
|
-
this.#fail("definition_mismatch");
|
|
983
|
-
return;
|
|
984
|
-
}
|
|
985
|
-
const value = this.#eof ? result({ done: true }) : result({
|
|
986
|
-
done: false, value: wait.encoded ? this.#body : this.#value,
|
|
987
|
-
application_input_delivered: this.#applicationInputDelivered,
|
|
988
|
-
codec_schema_digest: identity.codec_schema_digest, codec_revision: identity.codec_revision,
|
|
989
|
-
});
|
|
990
|
-
wait.signal?.removeEventListener("abort", wait.canceled);
|
|
991
|
-
wait.claim?.release();
|
|
992
|
-
wait.claim = undefined;
|
|
993
|
-
const failed = this.#decodeFailed && !wait.encoded;
|
|
994
|
-
this.#checkRead();
|
|
995
|
-
if (this.#readWait !== wait || wait.signal?.aborted || this.#closed)
|
|
996
|
-
return;
|
|
997
|
-
this.#handoff = true;
|
|
998
|
-
try {
|
|
999
|
-
if (failed) {
|
|
1000
|
-
const error = new V4MessageStreamError("decode_failed", undefined, this.#applicationInputDelivered, identity);
|
|
1001
|
-
wait.diagnosticOutcome = error;
|
|
1002
|
-
wait.reject(error);
|
|
1003
|
-
}
|
|
1004
|
-
else {
|
|
1005
|
-
wait.diagnosticOutcome = "ready";
|
|
1006
|
-
wait.resolve(value);
|
|
1007
|
-
}
|
|
1008
|
-
}
|
|
1009
|
-
finally {
|
|
1010
|
-
// Reentrant host hooks cannot reclaim, zero, or deliver this same body.
|
|
1011
|
-
if (!this.#eof)
|
|
1012
|
-
this.#clearBody(!failed && (wait.encoded || this.#inbound.implementation === "bytes"));
|
|
1013
|
-
this.#readWait = undefined;
|
|
1014
|
-
this.#handoff = false;
|
|
1015
|
-
this.#finishReadDiagnostic(wait);
|
|
1016
|
-
}
|
|
1017
|
-
}
|
|
1018
|
-
#rejectRead(wait, reason) {
|
|
1019
|
-
if (this.#readWait !== wait)
|
|
1020
|
-
return;
|
|
1021
|
-
this.#readWait = undefined;
|
|
1022
|
-
wait.signal?.removeEventListener("abort", wait.canceled);
|
|
1023
|
-
wait.claim?.release();
|
|
1024
|
-
wait.claim = undefined;
|
|
1025
|
-
this.#readAbort?.abort();
|
|
1026
|
-
this.#owner?.releaseReader();
|
|
1027
|
-
if (this.#dependencyTimer !== undefined)
|
|
1028
|
-
clearTimeout(this.#dependencyTimer);
|
|
1029
|
-
this.#dependencyTimer = undefined;
|
|
1030
|
-
const error = new V4MessageStreamError(reason, undefined, this.#applicationInputDelivered, this.#codecIdentity());
|
|
1031
|
-
wait.diagnosticOutcome = error;
|
|
1032
|
-
this.#finishReadDiagnostic(wait);
|
|
1033
|
-
wait.reject(error);
|
|
1034
|
-
}
|
|
1035
|
-
#clearBody(delivered = false) {
|
|
1036
|
-
this.#stopAssembly();
|
|
1037
|
-
if (this.#dependencyTimer !== undefined)
|
|
1038
|
-
clearTimeout(this.#dependencyTimer);
|
|
1039
|
-
this.#dependencyTimer = undefined;
|
|
1040
|
-
this.#dependencyDeadline = undefined;
|
|
1041
|
-
if (!delivered && !this.#applicationInputDelivered)
|
|
1042
|
-
this.#body.fill(0);
|
|
1043
|
-
this.#body = empty;
|
|
1044
|
-
this.#value = undefined;
|
|
1045
|
-
this.#bodyReference?.release();
|
|
1046
|
-
this.#bodyReference = undefined;
|
|
1047
|
-
this.#typedReference?.release();
|
|
1048
|
-
this.#typedReference = undefined;
|
|
1049
|
-
this.#completion?.close();
|
|
1050
|
-
this.#completion = undefined;
|
|
1051
|
-
this.#length = undefined;
|
|
1052
|
-
this.#filled = 0;
|
|
1053
|
-
this.#prefixBytes = 0;
|
|
1054
|
-
this.#prefix.fill(0);
|
|
1055
|
-
this.#decoded = this.#decodeFailed = this.#typedPrepaid = this.#applicationInputDelivered = false;
|
|
1056
|
-
}
|
|
1057
|
-
closeWrite(options) {
|
|
1058
|
-
if (this.#fin === undefined) {
|
|
1059
|
-
try {
|
|
1060
|
-
const owner = this.#check();
|
|
1061
|
-
this.#sealed = true;
|
|
1062
|
-
this.#finDeadline = owner.deadline(this.#options.sendTimeoutMS);
|
|
1063
|
-
this.#fin = new NativePromise((resolve, reject) => { this.#finResolve = resolve; this.#finReject = reject; });
|
|
1064
|
-
void this.#fin.catch(() => undefined);
|
|
1065
|
-
const expire = () => {
|
|
1066
|
-
try {
|
|
1067
|
-
this.#finDeadline.check();
|
|
1068
|
-
this.#finTimer = setTimeout(expire, timerChunk(this.#finDeadline.remainingMS()));
|
|
1069
|
-
}
|
|
1070
|
-
catch {
|
|
1071
|
-
this.#finTimer = undefined;
|
|
1072
|
-
this.#fail("deadline_exceeded");
|
|
1073
|
-
}
|
|
1074
|
-
};
|
|
1075
|
-
expire();
|
|
1076
|
-
this.#publish();
|
|
1077
|
-
}
|
|
1078
|
-
catch {
|
|
1079
|
-
return Promise.reject(new V4MessageStreamError(this.#failure ?? "closed"));
|
|
1080
|
-
}
|
|
1081
|
-
}
|
|
1082
|
-
return this.#wait(this.#fin, options);
|
|
1083
|
-
}
|
|
1084
|
-
#startFIN() {
|
|
1085
|
-
if (this.#fin === undefined || this.#finStarted || this.#closed)
|
|
1086
|
-
return;
|
|
1087
|
-
this.#finStarted = true;
|
|
1088
|
-
void this.#owner.closeWrite().then(value => {
|
|
1089
|
-
if (this.#finTimer !== undefined)
|
|
1090
|
-
clearTimeout(this.#finTimer);
|
|
1091
|
-
this.#finTimer = undefined;
|
|
1092
|
-
this.#finResult = value;
|
|
1093
|
-
this.#finResolve?.(value);
|
|
1094
|
-
this.#finResolve = this.#finReject = undefined;
|
|
1095
|
-
this.#cleanup();
|
|
1096
|
-
}, () => this.#fail("write_failed"));
|
|
1097
|
-
}
|
|
1098
|
-
finish(options) {
|
|
1099
|
-
if (this.#finish === undefined) {
|
|
1100
|
-
this.#finish = this.closeWrite().then(async () => {
|
|
1101
|
-
if (this.#owner === undefined && this.#failure === undefined && this.#finResult !== undefined)
|
|
1102
|
-
return result({ ...this.#finResult, send_drained: true, read_terminal: "eof", cleanup_status: complete });
|
|
1103
|
-
this.#check();
|
|
1104
|
-
const value = await this.#owner.finish();
|
|
1105
|
-
this.#finResult = value;
|
|
1106
|
-
return value;
|
|
1107
|
-
});
|
|
1108
|
-
void this.#finish.catch(() => undefined);
|
|
1109
|
-
}
|
|
1110
|
-
return this.#wait(this.#finish, options);
|
|
1111
|
-
}
|
|
1112
|
-
close(options) {
|
|
1113
|
-
this.#fail("closed");
|
|
1114
|
-
return this.waitCleanup(options).then(cleanup => result({ ...(this.#closeResult ?? { direction: this.#direction, send_drained: false, read_terminal: "abandoned" }), cleanup_status: cleanup }));
|
|
1115
|
-
}
|
|
1116
|
-
#fail(reason) {
|
|
1117
|
-
if (this.#closed)
|
|
1118
|
-
return;
|
|
1119
|
-
this.#closed = true;
|
|
1120
|
-
this.#sealed = true;
|
|
1121
|
-
this.#failure = reason;
|
|
1122
|
-
this.#stopAssembly();
|
|
1123
|
-
this.#resourceObserver?.();
|
|
1124
|
-
this.#resourceObserver = undefined;
|
|
1125
|
-
this.#readAbort?.abort();
|
|
1126
|
-
this.#decodeAbort?.abort();
|
|
1127
|
-
const wait = this.#readWait;
|
|
1128
|
-
if (!this.#handoff) {
|
|
1129
|
-
this.#readWait = undefined;
|
|
1130
|
-
if (wait !== undefined) {
|
|
1131
|
-
wait.signal?.removeEventListener("abort", wait.canceled);
|
|
1132
|
-
wait.claim?.release();
|
|
1133
|
-
wait.claim = undefined;
|
|
1134
|
-
const error = new V4MessageStreamError(reason, undefined, this.#applicationInputDelivered, this.#codecIdentity());
|
|
1135
|
-
wait.diagnosticOutcome = error;
|
|
1136
|
-
this.#finishReadDiagnostic(wait);
|
|
1137
|
-
wait.reject(error);
|
|
1138
|
-
}
|
|
1139
|
-
}
|
|
1140
|
-
for (const entry of this.#actualSends) {
|
|
1141
|
-
entry.revoked = true;
|
|
1142
|
-
entry.reason = reason;
|
|
1143
|
-
entry.abort.abort();
|
|
1144
|
-
entry.request?.cancel();
|
|
1145
|
-
this.#settleSend(entry, reason);
|
|
1146
|
-
if (!entry.running)
|
|
1147
|
-
this.#releaseSend(entry);
|
|
1148
|
-
}
|
|
1149
|
-
this.#sends.length = 0;
|
|
1150
|
-
if (this.#finTimer !== undefined)
|
|
1151
|
-
clearTimeout(this.#finTimer);
|
|
1152
|
-
this.#finTimer = undefined;
|
|
1153
|
-
this.#finReject?.(new V4MessageStreamError(reason));
|
|
1154
|
-
this.#finReject = this.#finResolve = undefined;
|
|
1155
|
-
if (!this.#readRunning) {
|
|
1156
|
-
this.#owner?.releaseReader();
|
|
1157
|
-
this.#clearBody();
|
|
1158
|
-
}
|
|
1159
|
-
if (this.#owner !== undefined) {
|
|
1160
|
-
try {
|
|
1161
|
-
this.#cleanupDeadline = this.#owner.deadline(this.#options.cleanupTimeoutMS);
|
|
1162
|
-
}
|
|
1163
|
-
catch {
|
|
1164
|
-
this.#cleanupIncomplete = true;
|
|
1165
|
-
}
|
|
1166
|
-
this.#closeRunning = true;
|
|
1167
|
-
this.#closeTail = this.#owner.reset().then(value => { this.#closeResult = value; }, () => undefined).finally(() => { this.#closeRunning = false; this.#cleanup(); });
|
|
1168
|
-
const expire = () => {
|
|
1169
|
-
try {
|
|
1170
|
-
this.#cleanupDeadline.check();
|
|
1171
|
-
this.#cleanupTimer = setTimeout(expire, timerChunk(this.#cleanupDeadline.remainingMS()));
|
|
1172
|
-
}
|
|
1173
|
-
catch {
|
|
1174
|
-
this.#cleanupTimer = undefined;
|
|
1175
|
-
this.#cleanupIncomplete = true;
|
|
1176
|
-
this.#notify();
|
|
1177
|
-
}
|
|
1178
|
-
};
|
|
1179
|
-
if (this.#cleanupDeadline !== undefined)
|
|
1180
|
-
expire();
|
|
1181
|
-
}
|
|
1182
|
-
this.#cleanup();
|
|
1183
|
-
}
|
|
1184
|
-
#cleanup() {
|
|
1185
|
-
if (this.#owner === undefined || this.#cleaning)
|
|
1186
|
-
return;
|
|
1187
|
-
this.#cleaning = true;
|
|
1188
|
-
try {
|
|
1189
|
-
this.#collect();
|
|
1190
|
-
}
|
|
1191
|
-
finally {
|
|
1192
|
-
this.#cleaning = false;
|
|
1193
|
-
}
|
|
1194
|
-
}
|
|
1195
|
-
#collect() {
|
|
1196
|
-
if (this.#owner === undefined)
|
|
1197
|
-
return;
|
|
1198
|
-
if (this.#ioEnded && !this.#ioDetached && (!this.#readRunning || this.#decoding) && !this.#closeRunning &&
|
|
1199
|
-
[...this.#actualSends].every(entry => entry.preparing) && this.#owner.cleanupStatus().status === "complete") {
|
|
1200
|
-
this.#ioDetached = true;
|
|
1201
|
-
this.#owner.detachIO();
|
|
1202
|
-
}
|
|
1203
|
-
if (this.#ioDetached && this.#applicationInputDelivered)
|
|
1204
|
-
this.#owner.releaseDelivery();
|
|
1205
|
-
if (this.#ioEnded && this.#length === undefined && !this.#handoff)
|
|
1206
|
-
this.#closed = true;
|
|
1207
|
-
const natural = this.#eof && this.#finResult !== undefined && this.#sends.length === 0;
|
|
1208
|
-
if ((!this.#closed && !natural) || this.#handoff || this.#readRunning || this.#publishing || this.#closeRunning || this.#actualSends.size !== 0 || this.#waits !== 0 || this.#owner.cleanupStatus().status !== "complete") {
|
|
1209
|
-
this.#notify();
|
|
1210
|
-
return;
|
|
1211
|
-
}
|
|
1212
|
-
this.#closed = true;
|
|
1213
|
-
this.#sealed = true;
|
|
1214
|
-
this.#resourceObserver?.();
|
|
1215
|
-
this.#resourceObserver = undefined;
|
|
1216
|
-
if (this.#cleanupTimer !== undefined)
|
|
1217
|
-
clearTimeout(this.#cleanupTimer);
|
|
1218
|
-
this.#cleanupTimer = undefined;
|
|
1219
|
-
const owner = this.#owner;
|
|
1220
|
-
this.#owner = undefined;
|
|
1221
|
-
owner.release();
|
|
1222
|
-
this.#definition = undefined;
|
|
1223
|
-
this.#prepared = undefined;
|
|
1224
|
-
this.#inbound = this.#outbound = undefined;
|
|
1225
|
-
this.#cleanupDeadline = this.#finDeadline = undefined;
|
|
1226
|
-
this.#notify();
|
|
1227
|
-
}
|
|
1228
|
-
#notify() { for (const wake of this.#observers)
|
|
1229
|
-
wake(); }
|
|
1230
|
-
cleanupStatus() {
|
|
1231
|
-
if (this.#owner === undefined)
|
|
1232
|
-
return complete;
|
|
1233
|
-
return result({ status: this.#cleanupIncomplete ? "cleanup_incomplete" : "pending", core_cleanup: this.#owner.cleanupStatus().core_cleanup,
|
|
1234
|
-
pending_callbacks: BigInt(this.#actualSends.size + Number(this.#readRunning) + Number(this.#publishing) + Number(this.#closeRunning)) });
|
|
1235
|
-
}
|
|
1236
|
-
#wait(operation, options) {
|
|
1237
|
-
if (options?.signal?.aborted)
|
|
1238
|
-
return Promise.reject(new V4MessageStreamError("canceled"));
|
|
1239
|
-
if (this.#owner === undefined)
|
|
1240
|
-
return operation;
|
|
1241
|
-
if (this.#waits >= 32)
|
|
1242
|
-
return Promise.reject(new V4MessageStreamError("resource_exhausted"));
|
|
1243
|
-
let reference;
|
|
1244
|
-
try {
|
|
1245
|
-
reference = this.#owner.reserve("v4_message_wait", new ResourceVector([this.#owner.runtimeBytes + 128n, 0n, 0n, 1n, 0n, 1n, 0n, 0n, 0n, 0n, 0n]));
|
|
1246
|
-
}
|
|
1247
|
-
catch {
|
|
1248
|
-
return Promise.reject(new V4MessageStreamError("resource_exhausted"));
|
|
1249
|
-
}
|
|
1250
|
-
this.#waits++;
|
|
1251
|
-
return new NativePromise((resolve, reject) => {
|
|
1252
|
-
let done = false;
|
|
1253
|
-
const finish = () => { if (done)
|
|
1254
|
-
return false; done = true; options?.signal?.removeEventListener("abort", cancel); return true; };
|
|
1255
|
-
const release = () => { this.#waits--; reference.release(); this.#cleanup(); };
|
|
1256
|
-
const cancel = () => { if (finish())
|
|
1257
|
-
reject(new V4MessageStreamError("canceled")); };
|
|
1258
|
-
options?.signal?.addEventListener("abort", cancel, { once: true });
|
|
1259
|
-
// An uncancelable native Promise reaction remains a real retained tail.
|
|
1260
|
-
// Cancel detaches only the public wait; its slot is refunded on reaction exit.
|
|
1261
|
-
void operation.then(value => { try {
|
|
1262
|
-
if (finish())
|
|
1263
|
-
resolve(value);
|
|
1264
|
-
}
|
|
1265
|
-
finally {
|
|
1266
|
-
release();
|
|
1267
|
-
} }, () => {
|
|
1268
|
-
try {
|
|
1269
|
-
if (finish())
|
|
1270
|
-
reject(new V4MessageStreamError(this.#failure ?? "write_failed"));
|
|
1271
|
-
}
|
|
1272
|
-
finally {
|
|
1273
|
-
release();
|
|
1274
|
-
}
|
|
1275
|
-
});
|
|
1276
|
-
});
|
|
1277
|
-
}
|
|
1278
|
-
waitCleanup(options) {
|
|
1279
|
-
try {
|
|
1280
|
-
if (applicationDependsOn(options?.context, this.#decodeContext) || [...this.#actualSends].some(entry => applicationDependsOn(options?.context, entry.applicationContext))) {
|
|
1281
|
-
return Promise.reject(new V4MessageStreamError("dependency_unavailable", undefined, this.#applicationInputDelivered));
|
|
1282
|
-
}
|
|
1283
|
-
}
|
|
1284
|
-
catch {
|
|
1285
|
-
return Promise.reject(new V4MessageStreamError("dependency_unavailable", undefined, this.#applicationInputDelivered));
|
|
1286
|
-
}
|
|
1287
|
-
const initial = this.cleanupStatus();
|
|
1288
|
-
if (initial.status !== "pending")
|
|
1289
|
-
return Promise.resolve(initial);
|
|
1290
|
-
if (options?.signal?.aborted)
|
|
1291
|
-
return Promise.reject(new V4MessageStreamError("canceled"));
|
|
1292
|
-
if (this.#cleanupWaits >= 32)
|
|
1293
|
-
return Promise.reject(new V4MessageStreamError("resource_exhausted"));
|
|
1294
|
-
const owner = this.#owner;
|
|
1295
|
-
let deadline, reference;
|
|
1296
|
-
try {
|
|
1297
|
-
deadline = owner.deadline(this.#options.cleanupTimeoutMS);
|
|
1298
|
-
reference = owner.reserve("v4_message_cleanup_wait", new ResourceVector([owner.runtimeBytes + 256n, 0n, 0n, 1n, 0n, 1n, 1n, 0n, 0n, 0n, 0n]));
|
|
1299
|
-
}
|
|
1300
|
-
catch {
|
|
1301
|
-
return Promise.reject(new V4MessageStreamError("resource_exhausted"));
|
|
1302
|
-
}
|
|
1303
|
-
this.#cleanupWaits++;
|
|
1304
|
-
return new NativePromise((resolve, reject) => {
|
|
1305
|
-
let timer;
|
|
1306
|
-
let done = false;
|
|
1307
|
-
const finish = (canceled = false) => {
|
|
1308
|
-
if (done)
|
|
1309
|
-
return;
|
|
1310
|
-
done = true;
|
|
1311
|
-
if (timer !== undefined)
|
|
1312
|
-
clearTimeout(timer);
|
|
1313
|
-
this.#observers.delete(wake);
|
|
1314
|
-
options?.signal?.removeEventListener("abort", cancel);
|
|
1315
|
-
this.#cleanupWaits--;
|
|
1316
|
-
reference.release();
|
|
1317
|
-
if (canceled)
|
|
1318
|
-
reject(new V4MessageStreamError("canceled"));
|
|
1319
|
-
else
|
|
1320
|
-
resolve(this.cleanupStatus());
|
|
1321
|
-
};
|
|
1322
|
-
const cancel = () => finish(true);
|
|
1323
|
-
const wake = () => { if (this.cleanupStatus().status !== "pending")
|
|
1324
|
-
finish(); };
|
|
1325
|
-
const tick = () => { try {
|
|
1326
|
-
deadline.check();
|
|
1327
|
-
timer = setTimeout(tick, timerChunk(deadline.remainingMS()));
|
|
1328
|
-
}
|
|
1329
|
-
catch {
|
|
1330
|
-
finish();
|
|
1331
|
-
} };
|
|
1332
|
-
this.#observers.add(wake);
|
|
1333
|
-
options?.signal?.addEventListener("abort", cancel, { once: true });
|
|
1334
|
-
if (options?.signal?.aborted)
|
|
1335
|
-
cancel();
|
|
1336
|
-
else {
|
|
1337
|
-
wake();
|
|
1338
|
-
if (!done)
|
|
1339
|
-
tick();
|
|
1340
|
-
}
|
|
1341
|
-
});
|
|
1342
|
-
}
|
|
1343
|
-
}
|
|
1344
|
-
/** Low-level conversion requires an untouched accepted Stream whose OPEN
|
|
1345
|
-
* already contains the exact definition binding. */
|
|
1346
|
-
export function asTypedMessages(stream, definition, options = {}) {
|
|
1347
|
-
messageDefinition(definition);
|
|
1348
|
-
const fixed = captureMessageOptions(options), owner = acquireMessageStreamAdapter(stream, messageAdapterProfile(fixed));
|
|
1349
|
-
try {
|
|
1350
|
-
const candidate = prepareTypedMessages(definition, fixed);
|
|
1351
|
-
candidate.bind(token, owner);
|
|
1352
|
-
return candidate;
|
|
1353
|
-
}
|
|
1354
|
-
catch (error) {
|
|
1355
|
-
owner.rollback();
|
|
1356
|
-
throw error;
|
|
1357
|
-
}
|
|
1358
|
-
}
|
|
1359
|
-
/** Internal candidate construction occurs before OPEN and application delivery. */
|
|
1360
|
-
export function prepareTypedMessages(definition, options) {
|
|
1361
|
-
return new V4TypedMessageStream(token, definition, options);
|
|
1362
|
-
}
|
|
1363
|
-
export function prepareMessageBinding(candidate, context) {
|
|
1364
|
-
candidate.prepare(token, context);
|
|
1365
|
-
}
|
|
1366
|
-
export function bindTypedMessages(candidate, stream, options, prepaid, preaccepted = false) {
|
|
1367
|
-
const owner = acquireMessageStreamAdapter(stream, { ...messageAdapterProfile(captureMessageOptions(options), prepaid), preaccepted });
|
|
1368
|
-
try {
|
|
1369
|
-
candidate.bind(token, owner);
|
|
1370
|
-
}
|
|
1371
|
-
catch (error) {
|
|
1372
|
-
owner.rollback();
|
|
1373
|
-
throw error;
|
|
1374
|
-
}
|
|
1375
|
-
}
|