@floegence/flowersec-core 5.11.0 → 6.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 +170 -58
- package/THIRD_PARTY_NOTICES.md +3070 -5
- package/dist/application/rpcJSON.d.ts +15 -0
- package/dist/{rpc/validate.js → application/rpcJSON.js} +1 -1
- package/dist/browser/clientV4.d.ts +61 -0
- package/dist/browser/clientV4.js +179 -0
- package/dist/browser/index.d.ts +15 -8
- package/dist/browser/index.js +5 -3
- package/dist/browser/indexedDBPoolV4.d.ts +101 -0
- package/dist/browser/indexedDBPoolV4.js +634 -0
- package/dist/browser/liveHTTPSV4.d.ts +35 -0
- package/dist/browser/liveHTTPSV4.js +162 -0
- package/dist/browser/localBrowserBridge.d.ts +20 -0
- package/dist/browser/localBrowserBridge.js +82 -0
- package/dist/browser/poolServerAllow.d.ts +21 -0
- package/dist/browser/poolServerAllow.js +151 -0
- package/dist/browser/webTransportPositionsV4.d.ts +16 -0
- package/dist/browser/webTransportPositionsV4.js +75 -0
- package/dist/browser/webTransportStreamV4.d.ts +36 -0
- package/dist/browser/webTransportStreamV4.js +370 -0
- package/dist/browser/webTransportV4.d.ts +126 -0
- package/dist/browser/webTransportV4.js +627 -0
- package/dist/browser/wssV4.d.ts +69 -0
- package/dist/browser/wssV4.js +339 -0
- package/dist/cli.d.ts +24 -1
- package/dist/cli.js +91 -119
- package/dist/defaults.d.ts +1 -23
- package/dist/defaults.js +1 -23
- package/dist/facade.d.ts +104 -21
- package/dist/facade.js +45 -8
- package/dist/generated/brotliWorker.d.ts +1 -0
- package/dist/generated/brotliWorker.js +3 -0
- package/dist/generated/idna151.d.ts +2 -0
- package/dist/generated/idna151.js +38 -0
- package/dist/generated/normalization151.d.ts +5 -0
- package/dist/generated/normalization151.js +878 -0
- package/dist/generated/sqliteWorkers.d.ts +2 -0
- package/dist/generated/sqliteWorkers.js +3 -0
- package/dist/generated/transportV4APIResults.d.ts +21 -1
- package/dist/generated/transportV4APIResults.js +42 -1
- package/dist/generated/transportV4Registry.d.ts +276 -2
- package/dist/generated/transportV4Registry.js +10 -4
- package/dist/interop/browserRunner.d.ts +72 -0
- package/dist/interop/browserRunner.js +354 -0
- package/dist/interop/currentContracts.d.ts +6 -0
- package/dist/interop/currentContracts.js +14 -0
- package/dist/interop/currentNativeTunnel.d.ts +30 -0
- package/dist/interop/currentNativeTunnel.js +149 -0
- package/dist/interop/currentParity.d.ts +68 -0
- package/dist/interop/currentParity.js +392 -0
- package/dist/interop/currentPeer.d.ts +241 -0
- package/dist/interop/currentPeer.js +630 -0
- package/dist/interop/currentRegisteredTunnelPeer.d.ts +37 -0
- package/dist/interop/currentRegisteredTunnelPeer.js +93 -0
- package/dist/interop/currentRelayPeer.d.ts +118 -0
- package/dist/interop/currentRelayPeer.js +251 -0
- package/dist/interop/currentServer.d.ts +44 -0
- package/dist/interop/currentServer.js +293 -0
- package/dist/interop/currentTLSPin.d.ts +9 -0
- package/dist/interop/currentTLSPin.js +44 -0
- package/dist/interop/currentTunnelMaterial.d.ts +34 -0
- package/dist/interop/currentTunnelMaterial.js +100 -0
- package/dist/interop/httpApplicationPeer.d.ts +15 -0
- package/dist/interop/httpApplicationPeer.js +167 -0
- package/dist/interop/invalidProofPeer.d.ts +8 -0
- package/dist/interop/invalidProofPeer.js +106 -0
- package/dist/interop/proxyServerPeer.js +8 -56
- package/dist/interop/serverParityPeer.d.ts +101 -1
- package/dist/interop/serverParityPeer.js +550 -578
- package/dist/node/acceptorCurrent.d.ts +55 -0
- package/dist/node/acceptorCurrent.js +286 -0
- package/dist/node/admissionRecord.d.ts +23 -0
- package/dist/node/admissionRecord.js +178 -0
- package/dist/node/clientV4.d.ts +59 -0
- package/dist/node/clientV4.js +197 -0
- package/dist/node/endpointDialer.d.ts +70 -0
- package/dist/node/endpointDialer.js +231 -0
- package/dist/node/endpointListener.d.ts +48 -0
- package/dist/node/endpointListener.js +403 -0
- package/dist/node/endpointTransport.d.ts +7 -0
- package/dist/node/endpointTransport.js +18 -0
- package/dist/node/grantIssuerCurrent.d.ts +64 -0
- package/dist/node/grantIssuerCurrent.js +355 -0
- package/dist/node/index.d.ts +52 -18
- package/dist/node/index.js +24 -7
- package/dist/node/liveHTTPSV4.d.ts +26 -0
- package/dist/node/liveHTTPSV4.js +283 -0
- package/dist/node/liveTunnelAuthorityCurrent.d.ts +153 -0
- package/dist/node/liveTunnelAuthorityCurrent.js +590 -0
- package/dist/node/nativeDuplexBridgeV4.d.ts +41 -0
- package/dist/node/nativeDuplexBridgeV4.js +494 -0
- package/dist/node/nativeTransportCurrent.d.ts +196 -0
- package/dist/node/nativeTransportCurrent.js +37 -0
- package/dist/node/poolServerAllow.d.ts +33 -0
- package/dist/node/poolServerAllow.js +277 -0
- package/dist/node/proxyCredentials.d.ts +67 -0
- package/dist/node/proxyCredentials.js +364 -0
- package/dist/node/proxyNetwork.d.ts +18 -0
- package/dist/node/proxyNetwork.js +213 -0
- package/dist/node/proxyServer.d.ts +30 -4
- package/dist/node/proxyServer.js +599 -154
- package/dist/node/rawQUICCurrent.d.ts +139 -0
- package/dist/node/rawQUICCurrent.js +1177 -0
- package/dist/node/registeredLiveTunnelControl.d.ts +74 -0
- package/dist/node/registeredLiveTunnelControl.js +865 -0
- package/dist/node/registeredPoolTunnelAuthority.d.ts +41 -0
- package/dist/node/registeredPoolTunnelAuthority.js +297 -0
- package/dist/node/registeredTunnelControl.d.ts +189 -0
- package/dist/node/registeredTunnelControl.js +1007 -0
- package/dist/node/registeredWinnerContinuation.d.ts +26 -0
- package/dist/node/registeredWinnerContinuation.js +83 -0
- package/dist/node/relayNativePair.d.ts +62 -0
- package/dist/node/relayNativePair.js +737 -0
- package/dist/node/relayRecord.d.ts +57 -0
- package/dist/node/relayRecord.js +275 -0
- package/dist/node/serveRawQUIC.d.ts +58 -0
- package/dist/node/serveRawQUIC.js +331 -0
- package/dist/node/serveWSS.d.ts +58 -0
- package/dist/node/serveWSS.js +309 -0
- package/dist/node/sqliteAdmission.d.ts +100 -0
- package/dist/node/sqliteAdmission.js +1185 -0
- package/dist/node/sqliteExecutionContentV4.d.ts +63 -0
- package/dist/node/sqliteExecutionContentV4.js +251 -0
- package/dist/node/sqliteExecutionV4.d.ts +114 -0
- package/dist/node/sqliteExecutionV4.js +1052 -0
- package/dist/node/sqliteFormat.d.ts +20 -0
- package/dist/node/sqliteFormat.js +72 -0
- package/dist/node/sqliteInspectionV4.d.ts +7 -0
- package/dist/node/sqliteInspectionV4.js +47 -0
- package/dist/node/sqliteNativeV4.d.ts +3 -0
- package/dist/node/sqliteNativeV4.js +16 -0
- package/dist/node/sqlitePoolV4.d.ts +41 -0
- package/dist/node/sqlitePoolV4.js +282 -0
- package/dist/node/sqlitePoolWorkerProgramV4.js +411 -0
- package/dist/node/sqlitePoolWorkerV4.d.ts +67 -0
- package/dist/node/sqlitePoolWorkerV4.js +206 -0
- package/dist/node/sqliteV4.d.ts +82 -0
- package/dist/node/sqliteV4.js +166 -0
- package/dist/node/sqliteWorkerProgramV4.js +175 -0
- package/dist/node/sqliteWorkerV4.d.ts +47 -0
- package/dist/node/sqliteWorkerV4.js +142 -0
- package/dist/node/streamDuplexV4.d.ts +33 -0
- package/dist/node/streamDuplexV4.js +359 -0
- package/dist/node/tunnelListenerPreparation.d.ts +37 -0
- package/dist/node/tunnelListenerPreparation.js +162 -0
- package/dist/node/tunnelRuntime.d.ts +124 -0
- package/dist/node/tunnelRuntime.js +1205 -0
- package/dist/node/webTransportCurrent.d.ts +24 -0
- package/dist/node/webTransportCurrent.js +12 -0
- package/dist/node/wssV4.d.ts +96 -0
- package/dist/node/wssV4.js +822 -0
- package/dist/proxy/admission.d.ts +21 -0
- package/dist/proxy/admission.js +126 -0
- package/dist/proxy/brotliBody.d.ts +10 -0
- package/dist/proxy/brotliBody.js +85 -0
- package/dist/proxy/credentialControl.d.ts +30 -0
- package/dist/proxy/credentialControl.js +86 -0
- package/dist/proxy/currentStream.d.ts +24 -0
- package/dist/proxy/currentStream.js +158 -0
- package/dist/proxy/fetch.d.ts +3 -2
- package/dist/proxy/fetch.js +96 -29
- package/dist/proxy/headers.d.ts +8 -0
- package/dist/proxy/headers.js +63 -0
- package/dist/proxy/index.d.ts +4 -0
- package/dist/proxy/index.js +2 -0
- package/dist/proxy/integration.d.ts +12 -8
- package/dist/proxy/integration.js +23 -16
- package/dist/proxy/policy.d.ts +5 -0
- package/dist/proxy/policy.js +60 -22
- package/dist/proxy/publicationOwner.d.ts +10 -0
- package/dist/proxy/publicationOwner.js +130 -0
- package/dist/proxy/requestAssociation.d.ts +11 -0
- package/dist/proxy/requestAssociation.js +8 -0
- package/dist/proxy/runtime.d.ts +3 -1
- package/dist/proxy/runtime.js +403 -170
- package/dist/proxy/scope.js +2 -2
- package/dist/proxy/serviceWorker.d.ts +3 -0
- package/dist/proxy/serviceWorker.js +634 -176
- package/dist/proxy/serviceWorkerRuntime.js +26 -1
- package/dist/proxy/stream.d.ts +16 -3
- package/dist/proxy/stream.js +6 -0
- package/dist/proxy/surface.d.ts +45 -0
- package/dist/proxy/surface.js +384 -0
- package/dist/proxy/types.d.ts +49 -6
- package/dist/proxy/windowBridge.d.ts +11 -3
- package/dist/proxy/windowBridge.js +68 -25
- package/dist/proxy/wire.d.ts +11 -0
- package/dist/proxy/wire.js +214 -0
- package/dist/proxy/wsPatch.js +13 -6
- package/dist/public/contract.d.ts +0 -71
- package/dist/public/contract.js +0 -8
- package/dist/public/streamKind.d.ts +3 -0
- package/dist/public/streamKind.js +19 -0
- package/dist/public/streamMetadata.d.ts +34 -2
- package/dist/public/streamMetadata.js +206 -13
- package/dist/v4/admissionOffer.d.ts +8 -0
- package/dist/v4/checkpoint.d.ts +23 -0
- package/dist/v4/checkpoint.js +16 -0
- package/dist/v4/clientServices.d.ts +35 -0
- package/dist/v4/clientServices.js +11 -0
- package/dist/v4/connectionDiagnostic.d.ts +42 -0
- package/dist/v4/connectionDiagnostic.js +45 -0
- package/dist/v4/connectionRequirements.d.ts +5 -0
- package/dist/v4/connectionRequirements.js +34 -0
- package/dist/v4/controller.d.ts +122 -0
- package/dist/v4/controller.js +1161 -0
- package/dist/v4/controllerNotifications.d.ts +81 -0
- package/dist/v4/controllerNotifications.js +610 -0
- package/dist/v4/diagnostics.d.ts +44 -0
- package/dist/v4/diagnostics.js +9 -0
- package/dist/v4/drain.d.ts +39 -0
- package/dist/v4/drain.js +80 -0
- package/dist/v4/duplexBridge.d.ts +53 -0
- package/dist/v4/duplexBridge.js +446 -0
- package/dist/v4/entrypoints.d.ts +20 -0
- package/dist/v4/entrypoints.js +50 -0
- package/dist/v4/eventSource.d.ts +34 -0
- package/dist/v4/eventSource.js +28 -0
- package/dist/v4/handlerPlan.d.ts +53 -0
- package/dist/v4/handlerPlan.js +129 -0
- package/dist/v4/liveness.d.ts +20 -0
- package/dist/v4/liveness.js +10 -0
- package/dist/v4/localReport.d.ts +17 -0
- package/dist/v4/localReport.js +10 -0
- package/dist/v4/messageDefinition.d.ts +66 -0
- package/dist/v4/messageDefinition.js +109 -0
- package/dist/v4/messageStream.d.ts +89 -0
- package/dist/v4/messageStream.js +1375 -0
- package/dist/v4/notificationOperation.d.ts +30 -0
- package/dist/v4/notificationOperation.js +31 -0
- package/dist/v4/notificationSubscription.d.ts +47 -0
- package/dist/v4/notificationSubscription.js +24 -0
- package/dist/v4/operationReference.d.ts +28 -0
- package/dist/v4/operationReference.js +61 -0
- package/dist/v4/operationReferenceCodec.d.ts +20 -0
- package/dist/v4/operationReferenceCodec.js +129 -0
- package/dist/v4/operationReferenceStore.d.ts +90 -0
- package/dist/v4/operationReferenceStore.js +272 -0
- package/dist/v4/operationResultRead.d.ts +26 -0
- package/dist/v4/operationResultRead.js +24 -0
- package/dist/v4/poolControl.d.ts +11 -0
- package/dist/v4/poolControl.js +50 -0
- package/dist/v4/poolSource.d.ts +93 -0
- package/dist/v4/poolSource.js +900 -0
- package/dist/v4/public.d.ts +232 -0
- package/dist/v4/public.js +632 -0
- package/dist/v4/responsePublication.d.ts +48 -0
- package/dist/v4/responsePublication.js +227 -0
- package/dist/v4/resume.d.ts +17 -0
- package/dist/v4/resume.js +15 -0
- package/dist/v4/runtime/applicationExecutor.d.ts +190 -0
- package/dist/v4/runtime/applicationExecutor.js +759 -0
- package/dist/v4/runtime/applicationHeader.d.ts +61 -0
- package/dist/v4/runtime/applicationHeader.js +222 -0
- package/dist/v4/runtime/canonicalText.d.ts +8 -0
- package/dist/v4/runtime/canonicalText.js +142 -0
- package/dist/v4/runtime/cbor.d.ts +92 -0
- package/dist/v4/runtime/cbor.js +728 -0
- package/dist/v4/runtime/cborWriter.d.ts +18 -0
- package/dist/v4/runtime/cborWriter.js +59 -0
- package/dist/v4/runtime/checkpointToken.d.ts +41 -0
- package/dist/v4/runtime/checkpointToken.js +61 -0
- package/dist/v4/runtime/clientAdmission.d.ts +40 -0
- package/dist/v4/runtime/clientAdmission.js +378 -0
- package/dist/v4/runtime/clientSessionSpec.d.ts +45 -0
- package/dist/v4/runtime/clientSessionSpec.js +91 -0
- package/dist/v4/runtime/clock.d.ts +80 -0
- package/dist/v4/runtime/clock.js +284 -0
- package/dist/v4/runtime/connectionFacts.d.ts +23 -0
- package/dist/v4/runtime/connectionFacts.js +106 -0
- package/dist/v4/runtime/contractAcceptance.d.ts +20 -0
- package/dist/v4/runtime/contractAcceptance.js +91 -0
- package/dist/v4/runtime/contractQuery.d.ts +57 -0
- package/dist/v4/runtime/contractQuery.js +265 -0
- package/dist/v4/runtime/contractQueryAccess.d.ts +25 -0
- package/dist/v4/runtime/contractQueryAccess.js +117 -0
- package/dist/v4/runtime/contractQueryAcquisition.d.ts +83 -0
- package/dist/v4/runtime/contractQueryAcquisition.js +572 -0
- package/dist/v4/runtime/contractQueryClient.d.ts +70 -0
- package/dist/v4/runtime/contractQueryClient.js +411 -0
- package/dist/v4/runtime/contractQueryCodecs.d.ts +20 -0
- package/dist/v4/runtime/contractQueryCodecs.js +71 -0
- package/dist/v4/runtime/contractQueryExchange.d.ts +36 -0
- package/dist/v4/runtime/contractQueryExchange.js +160 -0
- package/dist/v4/runtime/contractQueryService.d.ts +42 -0
- package/dist/v4/runtime/contractQueryService.js +572 -0
- package/dist/v4/runtime/contractQuerySession.d.ts +38 -0
- package/dist/v4/runtime/contractQuerySession.js +158 -0
- package/dist/v4/runtime/contractRoutes.d.ts +87 -0
- package/dist/v4/runtime/contractRoutes.js +396 -0
- package/dist/v4/runtime/contractSnapshotReader.d.ts +59 -0
- package/dist/v4/runtime/contractSnapshotReader.js +418 -0
- package/dist/v4/runtime/contractSnapshotWriter.d.ts +32 -0
- package/dist/v4/runtime/contractSnapshotWriter.js +208 -0
- package/dist/v4/runtime/controllerServiceSource.d.ts +23 -0
- package/dist/v4/runtime/controllerServiceSource.js +109 -0
- package/dist/v4/runtime/controllerUnaryRoute.d.ts +28 -0
- package/dist/v4/runtime/credentialNamespace.d.ts +143 -0
- package/dist/v4/runtime/credentialNamespace.js +1286 -0
- package/dist/v4/runtime/credentialSupport.d.ts +60 -0
- package/dist/v4/runtime/credentialSupport.js +294 -0
- package/dist/v4/runtime/credentialVerifier.d.ts +404 -0
- package/dist/v4/runtime/credentialVerifier.js +1443 -0
- package/dist/v4/runtime/cryptoUsage.d.ts +135 -0
- package/dist/v4/runtime/cryptoUsage.js +552 -0
- package/dist/v4/runtime/deadline.d.ts +31 -0
- package/dist/v4/runtime/deadline.js +188 -0
- package/dist/v4/runtime/diagnosticCounters.d.ts +15 -0
- package/dist/v4/runtime/diagnosticCounters.js +78 -0
- package/dist/v4/runtime/diagnosticObservation.d.ts +25 -0
- package/dist/v4/runtime/diagnosticObservation.js +67 -0
- package/dist/v4/runtime/diagnosticSink.d.ts +16 -0
- package/dist/v4/runtime/diagnosticSink.js +320 -0
- package/dist/v4/runtime/ed25519.d.ts +1 -0
- package/dist/v4/runtime/ed25519.js +34 -0
- package/dist/v4/runtime/endpointHop.d.ts +12 -0
- package/dist/v4/runtime/endpointHop.js +26 -0
- package/dist/v4/runtime/envelope.d.ts +66 -0
- package/dist/v4/runtime/envelope.js +275 -0
- package/dist/v4/runtime/environment.d.ts +277 -0
- package/dist/v4/runtime/environment.js +1911 -0
- package/dist/v4/runtime/executionManagementChannel.d.ts +27 -0
- package/dist/v4/runtime/executionManagementChannel.js +733 -0
- package/dist/v4/runtime/executionManagementCodec.d.ts +84 -0
- package/dist/v4/runtime/executionManagementCodec.js +127 -0
- package/dist/v4/runtime/executionStorage.d.ts +71 -0
- package/dist/v4/runtime/executionStorage.js +10 -0
- package/dist/v4/runtime/fixedDiagnosticExecutor.d.ts +34 -0
- package/dist/v4/runtime/fixedDiagnosticExecutor.js +149 -0
- package/dist/v4/runtime/fixedManagementExecutor.d.ts +21 -0
- package/dist/v4/runtime/fixedManagementExecutor.js +153 -0
- package/dist/v4/runtime/fixedQueryExecutor.d.ts +46 -0
- package/dist/v4/runtime/fixedQueryExecutor.js +311 -0
- package/dist/v4/runtime/grantDigest.d.ts +9 -0
- package/dist/v4/runtime/grantDigest.js +31 -0
- package/dist/v4/runtime/hopAuthentication.d.ts +51 -0
- package/dist/v4/runtime/hopAuthentication.js +392 -0
- package/dist/v4/runtime/host.d.ts +15 -0
- package/dist/v4/runtime/host.js +332 -0
- package/dist/v4/runtime/initializerWorkload.d.ts +38 -0
- package/dist/v4/runtime/initializerWorkload.js +164 -0
- package/dist/v4/runtime/lifecycle.d.ts +5 -0
- package/dist/v4/runtime/lifecycle.js +17 -0
- package/dist/v4/runtime/liveAuthorization.d.ts +42 -0
- package/dist/v4/runtime/liveAuthorization.js +133 -0
- package/dist/v4/runtime/liveAuthorizationWire.d.ts +8 -0
- package/dist/v4/runtime/liveAuthorizationWire.js +31 -0
- package/dist/v4/runtime/liveCarrierPreparation.d.ts +9 -0
- package/dist/v4/runtime/liveCarrierPreparation.js +27 -0
- package/dist/v4/runtime/liveness.d.ts +37 -0
- package/dist/v4/runtime/liveness.js +319 -0
- package/dist/v4/runtime/maintenancePositions.d.ts +29 -0
- package/dist/v4/runtime/maintenancePositions.js +152 -0
- package/dist/v4/runtime/messageCodec.d.ts +20 -0
- package/dist/v4/runtime/messageCodec.js +192 -0
- package/dist/v4/runtime/namespaceContinuity.d.ts +20 -0
- package/dist/v4/runtime/namespaceContinuity.js +176 -0
- package/dist/v4/runtime/nativeCandidates.d.ts +18 -0
- package/dist/v4/runtime/nativeCandidates.js +109 -0
- package/dist/v4/runtime/nativeFailure.d.ts +10 -0
- package/dist/v4/runtime/nativeFailure.js +32 -0
- package/dist/v4/runtime/nativeFrame.d.ts +47 -0
- package/dist/v4/runtime/nativeFrame.js +318 -0
- package/dist/v4/runtime/nativeIngress.d.ts +30 -0
- package/dist/v4/runtime/nativeIngress.js +177 -0
- package/dist/v4/runtime/nativePositions.d.ts +24 -0
- package/dist/v4/runtime/nativePositions.js +131 -0
- package/dist/v4/runtime/nativeProviderPositions.d.ts +16 -0
- package/dist/v4/runtime/nativeProviderPositions.js +75 -0
- package/dist/v4/runtime/nativeSend.d.ts +15 -0
- package/dist/v4/runtime/nativeSend.js +57 -0
- package/dist/v4/runtime/noiseHandshake.d.ts +70 -0
- package/dist/v4/runtime/noiseHandshake.js +373 -0
- package/dist/v4/runtime/noiseWasmBinary.d.ts +2 -0
- package/dist/v4/runtime/noiseWasmBinary.js +3 -0
- package/dist/v4/runtime/notifyChannel.d.ts +37 -0
- package/dist/v4/runtime/notifyChannel.js +277 -0
- package/dist/v4/runtime/notifyDispatch.d.ts +108 -0
- package/dist/v4/runtime/notifyDispatch.js +717 -0
- package/dist/v4/runtime/notifyExecution.d.ts +18 -0
- package/dist/v4/runtime/notifyExecution.js +59 -0
- package/dist/v4/runtime/notifyPreparation.d.ts +70 -0
- package/dist/v4/runtime/notifyPreparation.js +465 -0
- package/dist/v4/runtime/openAdmission.d.ts +125 -0
- package/dist/v4/runtime/openAdmission.js +810 -0
- package/dist/v4/runtime/peerOpenPreparation.d.ts +18 -0
- package/dist/v4/runtime/peerOpenPreparation.js +61 -0
- package/dist/v4/runtime/poolJournal.d.ts +18 -0
- package/dist/v4/runtime/poolJournal.js +14 -0
- package/dist/v4/runtime/poolJournalStorage.d.ts +4 -0
- package/dist/v4/runtime/poolJournalStorage.js +172 -0
- package/dist/v4/runtime/poolRecord.d.ts +9 -0
- package/dist/v4/runtime/poolRecord.js +23 -0
- package/dist/v4/runtime/poolRecordStorage.d.ts +10 -0
- package/dist/v4/runtime/poolRecordStorage.js +216 -0
- package/dist/v4/runtime/poolServerAllow.d.ts +49 -0
- package/dist/v4/runtime/poolServerAllow.js +38 -0
- package/dist/v4/runtime/poolSpend.d.ts +20 -0
- package/dist/v4/runtime/poolSpend.js +4 -0
- package/dist/v4/runtime/queryRenewalPosition.d.ts +59 -0
- package/dist/v4/runtime/queryRenewalPosition.js +220 -0
- package/dist/v4/runtime/random.d.ts +15 -0
- package/dist/v4/runtime/random.js +71 -0
- package/dist/v4/runtime/rawStreamPreparation.d.ts +40 -0
- package/dist/v4/runtime/rawStreamPreparation.js +125 -0
- package/dist/v4/runtime/receiveDirection.d.ts +135 -0
- package/dist/v4/runtime/receiveDirection.js +957 -0
- package/dist/v4/runtime/receiveWorkspace.d.ts +19 -0
- package/dist/v4/runtime/receiveWorkspace.js +82 -0
- package/dist/v4/runtime/record.d.ts +7 -0
- package/dist/v4/runtime/record.js +173 -0
- package/dist/v4/runtime/recordCrypto.d.ts +121 -0
- package/dist/v4/runtime/recordCrypto.js +633 -0
- package/dist/v4/runtime/recordWorkspace.d.ts +17 -0
- package/dist/v4/runtime/recordWorkspace.js +69 -0
- package/dist/v4/runtime/registeredCarrierPreparation.d.ts +17 -0
- package/dist/v4/runtime/registeredCarrierPreparation.js +191 -0
- package/dist/v4/runtime/rekey.d.ts +40 -0
- package/dist/v4/runtime/rekey.js +362 -0
- package/dist/v4/runtime/relayCredentials.d.ts +126 -0
- package/dist/v4/runtime/relayCredentials.js +349 -0
- package/dist/v4/runtime/replayWindow.d.ts +6 -0
- package/dist/v4/runtime/replayWindow.js +59 -0
- package/dist/v4/runtime/resources.d.ts +200 -0
- package/dist/v4/runtime/resources.js +1236 -0
- package/dist/v4/runtime/resumeCodec.d.ts +44 -0
- package/dist/v4/runtime/resumeCodec.js +192 -0
- package/dist/v4/runtime/resumeStream.d.ts +23 -0
- package/dist/v4/runtime/resumeStream.js +23 -0
- package/dist/v4/runtime/rpcApplication.d.ts +234 -0
- package/dist/v4/runtime/rpcApplication.js +2170 -0
- package/dist/v4/runtime/rpcApplicationServices.d.ts +18 -0
- package/dist/v4/runtime/rpcApplicationServices.js +62 -0
- package/dist/v4/runtime/rpcCallCapacity.d.ts +62 -0
- package/dist/v4/runtime/rpcCallCapacity.js +289 -0
- package/dist/v4/runtime/rpcChannel.d.ts +58 -0
- package/dist/v4/runtime/rpcChannel.js +334 -0
- package/dist/v4/runtime/rpcCompletion.d.ts +42 -0
- package/dist/v4/runtime/rpcCompletion.js +152 -0
- package/dist/v4/runtime/rpcEventSource.d.ts +27 -0
- package/dist/v4/runtime/rpcEventSource.js +201 -0
- package/dist/v4/runtime/rpcFragment.d.ts +42 -0
- package/dist/v4/runtime/rpcFragment.js +227 -0
- package/dist/v4/runtime/rpcInput.d.ts +41 -0
- package/dist/v4/runtime/rpcInput.js +137 -0
- package/dist/v4/runtime/rpcNetwork.d.ts +143 -0
- package/dist/v4/runtime/rpcNetwork.js +652 -0
- package/dist/v4/runtime/rpcOutputInterest.d.ts +20 -0
- package/dist/v4/runtime/rpcOutputInterest.js +106 -0
- package/dist/v4/runtime/rpcPayload.d.ts +24 -0
- package/dist/v4/runtime/rpcPayload.js +82 -0
- package/dist/v4/runtime/rpcPreacceptedStreams.d.ts +46 -0
- package/dist/v4/runtime/rpcPreacceptedStreams.js +406 -0
- package/dist/v4/runtime/rpcPublisher.d.ts +49 -0
- package/dist/v4/runtime/rpcPublisher.js +406 -0
- package/dist/v4/runtime/rpcReceiver.d.ts +40 -0
- package/dist/v4/runtime/rpcReceiver.js +255 -0
- package/dist/v4/runtime/rpcResumeDispatch.d.ts +46 -0
- package/dist/v4/runtime/rpcResumeDispatch.js +266 -0
- package/dist/v4/runtime/rpcStream.d.ts +14 -0
- package/dist/v4/runtime/rpcStream.js +12 -0
- package/dist/v4/runtime/rpcStreamMessages.d.ts +53 -0
- package/dist/v4/runtime/rpcStreamMessages.js +428 -0
- package/dist/v4/runtime/rpcStreamPreparation.d.ts +21 -0
- package/dist/v4/runtime/rpcStreamPreparation.js +110 -0
- package/dist/v4/runtime/rpcStreamingDispatch.d.ts +26 -0
- package/dist/v4/runtime/rpcStreamingDispatch.js +607 -0
- package/dist/v4/runtime/rpcStreamingExchange.d.ts +91 -0
- package/dist/v4/runtime/rpcStreamingExchange.js +812 -0
- package/dist/v4/runtime/rpcUnaryCall.d.ts +16 -0
- package/dist/v4/runtime/rpcUnaryCall.js +152 -0
- package/dist/v4/runtime/rpcUnaryDispatch.d.ts +34 -0
- package/dist/v4/runtime/rpcUnaryDispatch.js +569 -0
- package/dist/v4/runtime/rpcUnaryExchange.d.ts +127 -0
- package/dist/v4/runtime/rpcUnaryExchange.js +1042 -0
- package/dist/v4/runtime/rpcUnaryPreparation.d.ts +102 -0
- package/dist/v4/runtime/rpcUnaryPreparation.js +736 -0
- package/dist/v4/runtime/rpcUnaryRegistration.d.ts +33 -0
- package/dist/v4/runtime/rpcUnaryRegistration.js +113 -0
- package/dist/v4/runtime/rpcUnaryResultRecipient.d.ts +21 -0
- package/dist/v4/runtime/rpcUnaryResultRecipient.js +57 -0
- package/dist/v4/runtime/schema.d.ts +26 -0
- package/dist/v4/runtime/schema.js +668 -0
- package/dist/v4/runtime/schemaRegistry.d.ts +128 -0
- package/dist/v4/runtime/schemaRegistry.js +74 -0
- package/dist/v4/runtime/sendBudget.d.ts +10 -0
- package/dist/v4/runtime/sendBudget.js +46 -0
- package/dist/v4/runtime/serveGroup.d.ts +73 -0
- package/dist/v4/runtime/serveGroup.js +589 -0
- package/dist/v4/runtime/serverAdmission.d.ts +33 -0
- package/dist/v4/runtime/serverAdmission.js +342 -0
- package/dist/v4/runtime/serverAdmissionAuthority.d.ts +23 -0
- package/dist/v4/runtime/serverAdmissionAuthority.js +5 -0
- package/dist/v4/runtime/serverSessionSpec.d.ts +9 -0
- package/dist/v4/runtime/serverSessionSpec.js +12 -0
- package/dist/v4/runtime/serviceBinding.d.ts +128 -0
- package/dist/v4/runtime/serviceBinding.js +1435 -0
- package/dist/v4/runtime/serviceBindingConfig.d.ts +72 -0
- package/dist/v4/runtime/serviceBindingConfig.js +85 -0
- package/dist/v4/runtime/serviceBindingPool.d.ts +58 -0
- package/dist/v4/runtime/serviceBindingPool.js +327 -0
- package/dist/v4/runtime/serviceContract.d.ts +111 -0
- package/dist/v4/runtime/serviceContract.js +588 -0
- package/dist/v4/runtime/serviceInputs.d.ts +30 -0
- package/dist/v4/runtime/serviceInputs.js +201 -0
- package/dist/v4/runtime/serviceOfferPlan.d.ts +81 -0
- package/dist/v4/runtime/serviceOfferPlan.js +335 -0
- package/dist/v4/runtime/serviceOfferScheduler.d.ts +12 -0
- package/dist/v4/runtime/serviceOfferScheduler.js +201 -0
- package/dist/v4/runtime/serviceOfferWork.d.ts +25 -0
- package/dist/v4/runtime/serviceOfferWork.js +1 -0
- package/dist/v4/runtime/session.d.ts +411 -0
- package/dist/v4/runtime/session.js +6369 -0
- package/dist/v4/runtime/sessionActivity.d.ts +19 -0
- package/dist/v4/runtime/sessionActivity.js +97 -0
- package/dist/v4/runtime/sessionAdmission.d.ts +93 -0
- package/dist/v4/runtime/sessionAdmission.js +498 -0
- package/dist/v4/runtime/sessionCleanup.d.ts +47 -0
- package/dist/v4/runtime/sessionCleanup.js +268 -0
- package/dist/v4/runtime/sessionKeyPreparation.d.ts +19 -0
- package/dist/v4/runtime/sessionKeyPreparation.js +50 -0
- package/dist/v4/runtime/signedMap.d.ts +68 -0
- package/dist/v4/runtime/signedMap.js +425 -0
- package/dist/v4/runtime/streamAdapter.d.ts +113 -0
- package/dist/v4/runtime/streamAdapter.js +62 -0
- package/dist/v4/runtime/streamData.d.ts +11 -0
- package/dist/v4/runtime/streamData.js +50 -0
- package/dist/v4/runtime/streamOpenPreparation.d.ts +23 -0
- package/dist/v4/runtime/streamOpenPreparation.js +77 -0
- package/dist/v4/runtime/streamRegistration.d.ts +87 -0
- package/dist/v4/runtime/streamRegistration.js +296 -0
- package/dist/v4/runtime/taskObservation.d.ts +1 -0
- package/dist/v4/runtime/taskObservation.js +48 -0
- package/dist/v4/runtime/timeArithmetic.d.ts +29 -0
- package/dist/v4/runtime/timeArithmetic.js +107 -0
- package/dist/v4/runtime/unreliable.d.ts +76 -0
- package/dist/v4/runtime/unreliable.js +473 -0
- package/dist/v4/runtime/volatileExecutions.d.ts +128 -0
- package/dist/v4/runtime/volatileExecutions.js +792 -0
- package/dist/v4/runtime/wireRegistry.d.ts +52 -0
- package/dist/v4/runtime/wireRegistry.js +29 -0
- package/dist/v4/runtime/writeRequest.d.ts +42 -0
- package/dist/v4/runtime/writeRequest.js +237 -0
- package/dist/v4/serve.d.ts +107 -0
- package/dist/v4/serve.js +80 -0
- package/dist/v4/serviceClient.d.ts +92 -0
- package/dist/v4/serviceClient.js +323 -0
- package/dist/v4/serviceDefinition.d.ts +138 -0
- package/dist/v4/serviceDefinition.js +150 -0
- package/dist/v4/serviceDependencies.d.ts +66 -0
- package/dist/v4/serviceDependencies.js +250 -0
- package/dist/v4/serviceFactory.d.ts +31 -0
- package/dist/v4/serviceFactory.js +157 -0
- package/dist/v4/serviceHandlers.d.ts +55 -0
- package/dist/v4/serviceHandlers.js +15 -0
- package/dist/v4/serviceMembers.d.ts +4 -0
- package/dist/v4/serviceMembers.js +12 -0
- package/dist/v4/staticServiceContracts.d.ts +43 -0
- package/dist/v4/staticServiceContracts.js +161 -0
- package/dist/v4/storageFormat.d.ts +16 -0
- package/dist/v4/storageFormat.js +5 -0
- package/dist/v4/streamContent.d.ts +30 -0
- package/dist/v4/streamContent.js +29 -0
- package/dist/v4/streamHandlers.d.ts +61 -0
- package/dist/v4/streamHandlers.js +16 -0
- package/dist/v4/streamingOperation.d.ts +64 -0
- package/dist/v4/streamingOperation.js +141 -0
- package/dist/v4/testSupport/cbor.d.ts +124 -0
- package/dist/v4/testSupport/cbor.js +230 -0
- package/dist/v4/testSupport/credentials.d.ts +55 -0
- package/dist/v4/testSupport/credentials.js +111 -0
- package/dist/v4/testSupport/unicode.d.ts +19 -0
- package/dist/v4/testSupport/unicode.js +112 -0
- package/dist/v4/unaryOperation.d.ts +59 -0
- package/dist/v4/unaryOperation.js +80 -0
- package/dist/v4/unreliable.d.ts +26 -0
- package/dist/v4/unreliable.js +10 -0
- package/dist/v4/webStreams.d.ts +30 -0
- package/dist/v4/webStreams.js +377 -0
- package/package.json +15 -12
- package/sbom/cyclonedx.json +756 -38
- package/sbom/spdx.json +555 -38
- package/dist/browser/connectSessionV3.d.ts +0 -31
- package/dist/browser/connectSessionV3.js +0 -241
- package/dist/browser/directWebSocketProfileV1.d.ts +0 -14
- package/dist/browser/directWebSocketProfileV1.js +0 -71
- package/dist/browser/httpDirectV1.d.ts +0 -30
- package/dist/browser/httpDirectV1.js +0 -52
- package/dist/browser/privateLoopbackV1.d.ts +0 -30
- package/dist/browser/privateLoopbackV1.js +0 -70
- package/dist/framing/index.d.ts +0 -1
- package/dist/framing/index.js +0 -1
- package/dist/framing/jsonframe.d.ts +0 -14
- package/dist/framing/jsonframe.js +0 -42
- package/dist/node/acceptor.d.ts +0 -36
- package/dist/node/acceptor.js +0 -155
- package/dist/node/acceptorV3.d.ts +0 -57
- package/dist/node/acceptorV3.js +0 -227
- package/dist/node/byteStreamDuplex.d.ts +0 -4
- package/dist/node/byteStreamDuplex.js +0 -69
- package/dist/node/connectSessionV3.d.ts +0 -24
- package/dist/node/connectSessionV3.js +0 -79
- package/dist/node/connectionPath.d.ts +0 -28
- package/dist/node/connectionPath.js +0 -169
- package/dist/node/nativeTransportAddon.d.ts +0 -104
- package/dist/node/nativeTransportAddon.js +0 -212
- package/dist/node/rawQuicAdapterV3.d.ts +0 -10
- package/dist/node/rawQuicAdapterV3.js +0 -76
- package/dist/node/rawQuicServerV3.d.ts +0 -24
- package/dist/node/rawQuicServerV3.js +0 -34
- package/dist/node/runtimeAuthorizationV3.d.ts +0 -29
- package/dist/node/runtimeAuthorizationV3.js +0 -126
- package/dist/node/tunnelRuntimeV3.d.ts +0 -57
- package/dist/node/tunnelRuntimeV3.js +0 -857
- package/dist/node/webSocketServerV3.d.ts +0 -27
- package/dist/node/webSocketServerV3.js +0 -219
- package/dist/node/wsFactory.d.ts +0 -8
- package/dist/node/wsFactory.js +0 -84
- package/dist/public/streamHandlers.d.ts +0 -20
- package/dist/public/streamHandlers.js +0 -127
- package/dist/rpc/callError.d.ts +0 -5
- package/dist/rpc/callError.js +0 -11
- package/dist/rpc/caller.d.ts +0 -8
- package/dist/rpc/client.d.ts +0 -23
- package/dist/rpc/client.js +0 -171
- package/dist/rpc/index.d.ts +0 -6
- package/dist/rpc/index.js +0 -6
- package/dist/rpc/rpcProxy.d.ts +0 -16
- package/dist/rpc/rpcProxy.js +0 -58
- package/dist/rpc/server.d.ts +0 -51
- package/dist/rpc/server.js +0 -283
- package/dist/rpc/typed.d.ts +0 -5
- package/dist/rpc/typed.js +0 -9
- package/dist/rpc/validate.d.ts +0 -4
- package/dist/rpc/wire.d.ts +0 -15
- package/dist/v3/admissionError.d.ts +0 -4
- package/dist/v3/admissionError.js +0 -8
- package/dist/v3/artifact.d.ts +0 -145
- package/dist/v3/artifact.js +0 -1176
- package/dist/v3/artifactLease.d.ts +0 -17
- package/dist/v3/artifactLease.js +0 -109
- package/dist/v3/browserRuntime.d.ts +0 -37
- package/dist/v3/browserRuntime.js +0 -197
- package/dist/v3/browserSessionRuntime.d.ts +0 -2
- package/dist/v3/browserSessionRuntime.js +0 -21
- package/dist/v3/capability.d.ts +0 -32
- package/dist/v3/capability.js +0 -345
- package/dist/v3/carrier.d.ts +0 -84
- package/dist/v3/carrier.js +0 -411
- package/dist/v3/connectionController.d.ts +0 -100
- package/dist/v3/connectionController.js +0 -861
- package/dist/v3/contract.d.ts +0 -65
- package/dist/v3/contract.js +0 -3
- package/dist/v3/controller.d.ts +0 -45
- package/dist/v3/controller.js +0 -316
- package/dist/v3/handshake.d.ts +0 -81
- package/dist/v3/handshake.js +0 -471
- package/dist/v3/jcs.d.ts +0 -6
- package/dist/v3/jcs.js +0 -69
- package/dist/v3/jsonPreflight.d.ts +0 -1
- package/dist/v3/jsonPreflight.js +0 -251
- package/dist/v3/nodeRuntime.d.ts +0 -43
- package/dist/v3/nodeRuntime.js +0 -373
- package/dist/v3/nodeSessionRuntime.d.ts +0 -2
- package/dist/v3/nodeSessionRuntime.js +0 -13
- package/dist/v3/protocol.d.ts +0 -99
- package/dist/v3/protocol.js +0 -674
- package/dist/v3/publicApi.d.ts +0 -12
- package/dist/v3/publicApi.js +0 -46
- package/dist/v3/publicSession.js +0 -281
- package/dist/v3/retryDisposition.d.ts +0 -16
- package/dist/v3/retryDisposition.js +0 -23
- package/dist/v3/runtimeAdapters.d.ts +0 -9
- package/dist/v3/runtimeAdapters.js +0 -109
- package/dist/v3/security.d.ts +0 -36
- package/dist/v3/security.js +0 -113
- package/dist/v3/serverAdmission.d.ts +0 -38
- package/dist/v3/serverAdmission.js +0 -223
- package/dist/v3/session.d.ts +0 -322
- package/dist/v3/session.js +0 -2302
- package/dist/v3/sessionConnector.d.ts +0 -42
- package/dist/v3/sessionConnector.js +0 -513
- package/dist/v3/streamLifetimeLedger.d.ts +0 -31
- package/dist/v3/streamLifetimeLedger.js +0 -131
- package/dist/v3/streamMetadata.js +0 -7
- package/dist/v3/transportConstants.d.ts +0 -56
- package/dist/v3/transportConstants.js +0 -59
- package/dist/v3/unreliableMessage.d.ts +0 -44
- package/dist/v3/unreliableMessage.js +0 -287
- package/dist/v3/webSocketCarrier.d.ts +0 -31
- package/dist/v3/webSocketCarrier.js +0 -370
- package/dist/v3/webTransportCarrier.d.ts +0 -27
- package/dist/v3/webTransportCarrier.js +0 -552
- package/dist/ws-client/binaryTransport.d.ts +0 -64
- package/dist/ws-client/binaryTransport.js +0 -393
- package/dist/yamux/byteReader.d.ts +0 -13
- package/dist/yamux/byteReader.js +0 -81
- package/dist/yamux/constants.d.ts +0 -10
- package/dist/yamux/constants.js +0 -14
- package/dist/yamux/errors.d.ts +0 -15
- package/dist/yamux/errors.js +0 -34
- package/dist/yamux/header.d.ts +0 -17
- package/dist/yamux/header.js +0 -26
- package/dist/yamux/index.d.ts +0 -6
- package/dist/yamux/index.js +0 -6
- package/dist/yamux/session.d.ts +0 -81
- package/dist/yamux/session.js +0 -401
- package/dist/yamux/stream.d.ts +0 -42
- package/dist/yamux/stream.js +0 -296
- /package/dist/{rpc/caller.js → node/sqlitePoolWorkerProgramV4.d.ts} +0 -0
- /package/dist/{rpc/wire.js → node/sqliteWorkerProgramV4.d.ts} +0 -0
- /package/dist/{v3/publicSession.d.ts → v4/admissionOffer.js} +0 -0
- /package/dist/{v3/streamMetadata.d.ts → v4/runtime/controllerUnaryRoute.js} +0 -0
|
@@ -0,0 +1,957 @@
|
|
|
1
|
+
import { V4ReadMethodError } from "../public.js";
|
|
2
|
+
import { CBORDecoder, CBORWireError, cborDecoderCharge, byteSlice } from "./cbor.js";
|
|
3
|
+
import { timerChunk } from "./deadline.js";
|
|
4
|
+
import { ResourceError, ResourceVector } from "./resources.js";
|
|
5
|
+
import { SchemaValidationError } from "./schema.js";
|
|
6
|
+
import { TimeError } from "./timeArithmetic.js";
|
|
7
|
+
import { wire } from "./wireRegistry.js";
|
|
8
|
+
import { ReceiveWorkspace } from "./receiveWorkspace.js";
|
|
9
|
+
const token = Symbol("receive direction owner");
|
|
10
|
+
const empty = new Uint8Array();
|
|
11
|
+
const copy = Uint8Array.prototype.set;
|
|
12
|
+
const reverse = Uint8Array.prototype.reverse;
|
|
13
|
+
const NativeBytes = Uint8Array;
|
|
14
|
+
const NativePromise = Promise;
|
|
15
|
+
const enqueueReadJob = queueMicrotask;
|
|
16
|
+
const uint64Max = (1n << 64n) - 1n;
|
|
17
|
+
const complete = Object.freeze({ status: "complete", core_cleanup: "complete", pending_callbacks: 0n });
|
|
18
|
+
const pending = Object.freeze({ status: "pending", core_cleanup: "pending", pending_callbacks: 0n });
|
|
19
|
+
export class ReceiveError extends Error {
|
|
20
|
+
code;
|
|
21
|
+
constructor(code) {
|
|
22
|
+
super(code);
|
|
23
|
+
this.code = code;
|
|
24
|
+
this.name = "ReceiveError";
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
function fail(code) { throw new ReceiveError(code); }
|
|
28
|
+
function quantity(n) {
|
|
29
|
+
if (typeof n !== "bigint" || n < 0n || n > uint64Max)
|
|
30
|
+
fail("configuration_capacity");
|
|
31
|
+
return n;
|
|
32
|
+
}
|
|
33
|
+
function size(n) {
|
|
34
|
+
if (!Number.isSafeInteger(n) || n < 1 || n > 0x7fffffff)
|
|
35
|
+
fail("configuration_capacity");
|
|
36
|
+
return n;
|
|
37
|
+
}
|
|
38
|
+
function vector(bytes, items = 1n, work = 1n, tasks = 0n) {
|
|
39
|
+
return new ResourceVector([bytes, 0n, 0n, items, work, tasks, 0n, 0n, 0n, 0n, 0n]);
|
|
40
|
+
}
|
|
41
|
+
export function receiveDeliveryCharge(runtimeBytes) {
|
|
42
|
+
if (quantity(runtimeBytes) === 0n)
|
|
43
|
+
fail("configuration_capacity");
|
|
44
|
+
return new ResourceVector([runtimeBytes, 0n, 0n, 1n, 1n, 1n, 1n, 0n, 0n, 0n, 0n]);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Original result authorization, separate from normal Session I/O shutdown.
|
|
48
|
+
* The admission/security owner supplies the captured trusted deadline and closes
|
|
49
|
+
* this gate on revocation, authorization termination or Environment.Close.
|
|
50
|
+
* Its reservation must belong to that safety lifetime, not a short I/O scope.
|
|
51
|
+
*/
|
|
52
|
+
export class ReceiveDeliveryGate {
|
|
53
|
+
#deadline;
|
|
54
|
+
#reservation;
|
|
55
|
+
#reason;
|
|
56
|
+
#authorization;
|
|
57
|
+
#authorizationRelease;
|
|
58
|
+
#authorizationRemaining;
|
|
59
|
+
#authorizationObserver;
|
|
60
|
+
#timer;
|
|
61
|
+
#retiring = false;
|
|
62
|
+
#closing = false;
|
|
63
|
+
#cleaned;
|
|
64
|
+
#leases = new Set();
|
|
65
|
+
constructor(deadline, runtimeBytes, reservation) {
|
|
66
|
+
deadline.check();
|
|
67
|
+
this.#deadline = deadline;
|
|
68
|
+
this.#reservation = reservation.take(receiveDeliveryCharge(runtimeBytes));
|
|
69
|
+
Object.freeze(this);
|
|
70
|
+
}
|
|
71
|
+
constrainAuthorization(check, original, release, remainingMS, observe) {
|
|
72
|
+
this.check(token);
|
|
73
|
+
if (this.#authorization !== undefined || !this.#reservation.sameEnvironment(original))
|
|
74
|
+
fail("receive_owner");
|
|
75
|
+
check();
|
|
76
|
+
this.#authorization = check;
|
|
77
|
+
this.#authorizationRelease = release;
|
|
78
|
+
this.#authorizationRemaining = remainingMS;
|
|
79
|
+
this.#authorizationObserver = observe?.(() => {
|
|
80
|
+
if (!this.#retiring || this.#reason !== undefined)
|
|
81
|
+
return;
|
|
82
|
+
if (this.#timer !== undefined)
|
|
83
|
+
clearTimeout(this.#timer);
|
|
84
|
+
this.#timer = undefined;
|
|
85
|
+
this.#armAuthorization();
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
retain(directionReservation, closed) {
|
|
89
|
+
this.check(token);
|
|
90
|
+
if (this.#retiring)
|
|
91
|
+
throw new V4ReadMethodError("closed");
|
|
92
|
+
if (!this.#reservation.sameEnvironment(directionReservation))
|
|
93
|
+
fail("receive_owner");
|
|
94
|
+
const reservation = this.#reservation.borrow();
|
|
95
|
+
const lease = new ReceiveDeliveryLease(token, this, reservation, closed);
|
|
96
|
+
this.#leases.add(lease);
|
|
97
|
+
return lease;
|
|
98
|
+
}
|
|
99
|
+
check(capability) {
|
|
100
|
+
if (capability !== token)
|
|
101
|
+
fail("receive_owner");
|
|
102
|
+
if (this.#reason !== undefined)
|
|
103
|
+
throw new V4ReadMethodError(this.#reason);
|
|
104
|
+
try {
|
|
105
|
+
this.#reservation.check();
|
|
106
|
+
}
|
|
107
|
+
catch {
|
|
108
|
+
this.close();
|
|
109
|
+
throw new V4ReadMethodError("closed");
|
|
110
|
+
}
|
|
111
|
+
try {
|
|
112
|
+
this.#deadline.check();
|
|
113
|
+
this.#authorization?.();
|
|
114
|
+
}
|
|
115
|
+
catch (error) {
|
|
116
|
+
if (error instanceof TimeError && ["time_unavailable", "time_pending", "time_continuity"].includes(error.code)) {
|
|
117
|
+
throw new V4ReadMethodError(error.code === "time_pending" ? "time_pending" : "time_unavailable");
|
|
118
|
+
}
|
|
119
|
+
this.close("authorization_denied");
|
|
120
|
+
throw new V4ReadMethodError("authorization_denied");
|
|
121
|
+
}
|
|
122
|
+
if (this.#reason !== undefined)
|
|
123
|
+
throw new V4ReadMethodError(this.#reason);
|
|
124
|
+
}
|
|
125
|
+
release(capability, lease) {
|
|
126
|
+
if (capability !== token || !this.#leases.delete(lease))
|
|
127
|
+
fail("receive_owner");
|
|
128
|
+
if (this.#retiring && this.#leases.size === 0)
|
|
129
|
+
this.close();
|
|
130
|
+
this.#notifyCleanup();
|
|
131
|
+
}
|
|
132
|
+
onCleanup(callback) { if (this.#cleaned !== undefined)
|
|
133
|
+
fail("receive_owner"); this.#cleaned = callback; this.#notifyCleanup(); }
|
|
134
|
+
#notifyCleanup() {
|
|
135
|
+
if (this.#closing || this.#reason === undefined || this.#leases.size !== 0)
|
|
136
|
+
return;
|
|
137
|
+
const callback = this.#cleaned;
|
|
138
|
+
this.#cleaned = undefined;
|
|
139
|
+
callback?.();
|
|
140
|
+
}
|
|
141
|
+
/** Normal I/O shutdown leaves existing complete candidates authorized. */
|
|
142
|
+
retire() {
|
|
143
|
+
if (this.#retiring || this.#reason !== undefined)
|
|
144
|
+
return;
|
|
145
|
+
this.#retiring = true;
|
|
146
|
+
if (this.#leases.size === 0)
|
|
147
|
+
this.close();
|
|
148
|
+
else
|
|
149
|
+
this.#armAuthorization();
|
|
150
|
+
}
|
|
151
|
+
#armAuthorization() {
|
|
152
|
+
if (this.#reason !== undefined)
|
|
153
|
+
return;
|
|
154
|
+
let remaining;
|
|
155
|
+
try {
|
|
156
|
+
this.check(token);
|
|
157
|
+
const session = this.#deadline.remainingMS(), authorization = this.#authorizationRemaining?.() ?? session;
|
|
158
|
+
remaining = authorization < session ? authorization : session;
|
|
159
|
+
}
|
|
160
|
+
catch (error) {
|
|
161
|
+
if (this.#reason !== undefined)
|
|
162
|
+
return;
|
|
163
|
+
// Loss of a usable clock suspends delivery. A wake retries the original
|
|
164
|
+
// deadlines; it neither expires a result speculatively nor renews it.
|
|
165
|
+
if (error instanceof V4ReadMethodError && ["time_pending", "time_unavailable"].includes(error.reason) ||
|
|
166
|
+
error instanceof TimeError && ["time_pending", "time_unavailable", "time_continuity"].includes(error.code))
|
|
167
|
+
remaining = 1000n;
|
|
168
|
+
else {
|
|
169
|
+
this.close("authorization_denied");
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
if (this.#reason === undefined)
|
|
174
|
+
this.#timer = setTimeout(() => { this.#timer = undefined; this.#armAuthorization(); }, timerChunk(remaining));
|
|
175
|
+
}
|
|
176
|
+
close(reason = "closed") {
|
|
177
|
+
if (this.#reason !== undefined)
|
|
178
|
+
return;
|
|
179
|
+
this.#reason = reason;
|
|
180
|
+
this.#closing = true;
|
|
181
|
+
if (this.#timer !== undefined)
|
|
182
|
+
clearTimeout(this.#timer);
|
|
183
|
+
this.#timer = undefined;
|
|
184
|
+
this.#reservation?.seal();
|
|
185
|
+
for (const lease of this.#leases)
|
|
186
|
+
lease.notifyClosed();
|
|
187
|
+
this.#reservation?.release();
|
|
188
|
+
this.#reservation = undefined;
|
|
189
|
+
this.#deadline = undefined;
|
|
190
|
+
this.#authorization = undefined;
|
|
191
|
+
this.#authorizationRemaining = undefined;
|
|
192
|
+
this.#authorizationObserver?.();
|
|
193
|
+
this.#authorizationObserver = undefined;
|
|
194
|
+
const release = this.#authorizationRelease;
|
|
195
|
+
this.#authorizationRelease = undefined;
|
|
196
|
+
release?.();
|
|
197
|
+
this.#closing = false;
|
|
198
|
+
this.#notifyCleanup();
|
|
199
|
+
}
|
|
200
|
+
cleanupStatus() { return !this.#closing && this.#reason !== undefined && this.#leases.size === 0 ? complete : pending; }
|
|
201
|
+
}
|
|
202
|
+
class ReceiveDeliveryLease {
|
|
203
|
+
#gate;
|
|
204
|
+
#reservation;
|
|
205
|
+
#closed;
|
|
206
|
+
constructor(capability, gate, reservation, closed) {
|
|
207
|
+
if (capability !== token)
|
|
208
|
+
fail("receive_owner");
|
|
209
|
+
this.#gate = gate;
|
|
210
|
+
this.#reservation = reservation;
|
|
211
|
+
this.#closed = closed;
|
|
212
|
+
}
|
|
213
|
+
check() {
|
|
214
|
+
if (this.#gate === undefined)
|
|
215
|
+
throw new V4ReadMethodError("closed");
|
|
216
|
+
this.#reservation.checkRetained();
|
|
217
|
+
this.#gate.check(token);
|
|
218
|
+
}
|
|
219
|
+
notifyClosed() { this.#closed?.(); }
|
|
220
|
+
release() {
|
|
221
|
+
if (this.#gate === undefined)
|
|
222
|
+
return;
|
|
223
|
+
this.#reservation.release();
|
|
224
|
+
this.#gate.release(token, this);
|
|
225
|
+
this.#gate = undefined;
|
|
226
|
+
this.#reservation = undefined;
|
|
227
|
+
this.#closed = undefined;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
function capture(c) {
|
|
231
|
+
const maxDataBytes = size(c.maxDataBytes), queueBytes = size(c.queueBytes), maxCursorBytes = size(c.maxCursorBytes);
|
|
232
|
+
const receiveLimit = quantity(c.receiveLimit), runtimeBytes = quantity(c.runtimeBytes);
|
|
233
|
+
const cursorRuntimeBytes = quantity(c.cursorRuntimeBytes), decoderRuntimeBytes = quantity(c.decoderRuntimeBytes);
|
|
234
|
+
if (maxDataBytes > wire.resource_caps.max_payload_length - 100 || receiveLimit > BigInt(queueBytes) ||
|
|
235
|
+
runtimeBytes === 0n || cursorRuntimeBytes === 0n || decoderRuntimeBytes === 0n)
|
|
236
|
+
fail("configuration_capacity");
|
|
237
|
+
const workspace = c.workspace;
|
|
238
|
+
if (workspace !== undefined && !(workspace instanceof ReceiveWorkspace))
|
|
239
|
+
fail("configuration_capacity");
|
|
240
|
+
return Object.freeze({ maxDataBytes, queueBytes, maxCursorBytes, receiveLimit, runtimeBytes,
|
|
241
|
+
cursorRuntimeBytes, decoderRuntimeBytes, plaintextBytes: workspace?.maxPlainBytes ?? maxDataBytes + 64,
|
|
242
|
+
...(workspace === undefined ? {} : { workspace }) });
|
|
243
|
+
}
|
|
244
|
+
function decoderConfig(c) {
|
|
245
|
+
return { bytes: c.plaintextBytes, nodes: 15, textBytes: 0, arrayItems: 1, runtimeBytes: c.decoderRuntimeBytes };
|
|
246
|
+
}
|
|
247
|
+
export function receiveDirectionCharge(config) {
|
|
248
|
+
const c = capture(config);
|
|
249
|
+
return vector(BigInt(c.queueBytes + (c.workspace === undefined ? c.plaintextBytes : 0)) + c.runtimeBytes, 1n, 1n, 1n);
|
|
250
|
+
}
|
|
251
|
+
export function receiveCursorCharge(config) {
|
|
252
|
+
const c = capture(config);
|
|
253
|
+
return vector(BigInt(c.maxCursorBytes) + c.cursorRuntimeBytes, 1n, 1n, 1n);
|
|
254
|
+
}
|
|
255
|
+
export function receiveDecoderCharge(config) {
|
|
256
|
+
const c = capture(config);
|
|
257
|
+
return c.workspace === undefined ? cborDecoderCharge(decoderConfig(c)) : vector(64n + c.decoderRuntimeBytes, 1n, 0n);
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* One real authenticated receive queue. Ordinary reads and public ReaderCursor
|
|
261
|
+
* share its direction claim, bytes, resource root and result authorization.
|
|
262
|
+
* This component does not establish OPEN/READY or publish maintenance credit.
|
|
263
|
+
* The configured limit is fixed until that Session machinery supplies a real
|
|
264
|
+
* authenticated credit publication path; consumed bytes are never self-granted.
|
|
265
|
+
*/
|
|
266
|
+
export class ReliableReceiveDirection {
|
|
267
|
+
released;
|
|
268
|
+
settled;
|
|
269
|
+
#config;
|
|
270
|
+
#cipher;
|
|
271
|
+
#binding;
|
|
272
|
+
#reservation;
|
|
273
|
+
#cursorReservation;
|
|
274
|
+
#borrowedCursor = false;
|
|
275
|
+
#decoder;
|
|
276
|
+
#workspaceReference;
|
|
277
|
+
#workspaceRelease;
|
|
278
|
+
#delivery;
|
|
279
|
+
#ring = empty;
|
|
280
|
+
#queueReference;
|
|
281
|
+
#bodyQueue;
|
|
282
|
+
#scratch = empty;
|
|
283
|
+
#head = 0;
|
|
284
|
+
#queued = 0;
|
|
285
|
+
#ack = 0n;
|
|
286
|
+
#receiveLimit = 0n;
|
|
287
|
+
#released = 0n;
|
|
288
|
+
#creditPaused = false;
|
|
289
|
+
#fin;
|
|
290
|
+
#terminal;
|
|
291
|
+
#active;
|
|
292
|
+
#wait;
|
|
293
|
+
#working = false;
|
|
294
|
+
#pumpQueued = false;
|
|
295
|
+
#abandoned = false;
|
|
296
|
+
#closed = false;
|
|
297
|
+
#nativeClaims = [];
|
|
298
|
+
constructor(config, cipher, delivery, reservations, released, settled) {
|
|
299
|
+
this.released = released;
|
|
300
|
+
this.settled = settled;
|
|
301
|
+
const c = capture(config);
|
|
302
|
+
const { root, direction, decoder, cursor } = reservations;
|
|
303
|
+
if (!direction.sameEnvironment(decoder) || !direction.sameEnvironment(cursor))
|
|
304
|
+
fail("receive_owner");
|
|
305
|
+
this.#binding = cipher.receiveBinding(direction);
|
|
306
|
+
this.#config = c;
|
|
307
|
+
this.#receiveLimit = c.receiveLimit;
|
|
308
|
+
this.#cipher = cipher;
|
|
309
|
+
this.#reservation = direction.take(receiveDirectionCharge(c));
|
|
310
|
+
try {
|
|
311
|
+
this.#delivery = delivery.retain(this.#reservation, () => this.close());
|
|
312
|
+
if (reservations.cursorPosition === undefined)
|
|
313
|
+
this.#cursorReservation = root.protect(cursor, receiveCursorCharge(c));
|
|
314
|
+
else {
|
|
315
|
+
if (!reservations.cursorPosition.sameEnvironment(cursor))
|
|
316
|
+
fail("receive_owner");
|
|
317
|
+
this.#cursorReservation = reservations.cursorPosition;
|
|
318
|
+
this.#borrowedCursor = true;
|
|
319
|
+
cursor.release();
|
|
320
|
+
}
|
|
321
|
+
if (c.workspace === undefined) {
|
|
322
|
+
this.#decoder = new CBORDecoder(decoderConfig(c), decoder);
|
|
323
|
+
this.#scratch = new Uint8Array(c.plaintextBytes);
|
|
324
|
+
}
|
|
325
|
+
else {
|
|
326
|
+
this.#workspaceReference = decoder.take(receiveDecoderCharge(c));
|
|
327
|
+
this.#workspaceRelease = c.workspace.retain(this.#workspaceReference);
|
|
328
|
+
}
|
|
329
|
+
this.#ring = new Uint8Array(c.queueBytes);
|
|
330
|
+
}
|
|
331
|
+
catch (error) {
|
|
332
|
+
this.close();
|
|
333
|
+
throw error;
|
|
334
|
+
}
|
|
335
|
+
Object.freeze(this);
|
|
336
|
+
}
|
|
337
|
+
progress() {
|
|
338
|
+
return Object.freeze({ ack_offset: this.#ack, released_offset: this.#released,
|
|
339
|
+
receive_limit: this.#receiveLimit, queued_bytes: BigInt(this.#queued),
|
|
340
|
+
...(this.#fin === undefined ? {} : { fin_offset: this.#fin }) });
|
|
341
|
+
}
|
|
342
|
+
claimNative(bytes, payloadClaim, prefetch = false) {
|
|
343
|
+
this.#checkIngress();
|
|
344
|
+
if (this.#nativeClaims.length >= 2 || !prefetch && this.#nativeClaims.some(value => !value.validated) ||
|
|
345
|
+
this.#fin !== undefined || !Number.isSafeInteger(bytes) || bytes < 0 || payloadClaim < BigInt(bytes))
|
|
346
|
+
fail("receive_credit");
|
|
347
|
+
let start = this.#ack;
|
|
348
|
+
for (const state of this.#nativeClaims)
|
|
349
|
+
if (!state.validated && state.end > start)
|
|
350
|
+
start = state.end;
|
|
351
|
+
// Conservative gaps left by a preceding claim stay in the original paid
|
|
352
|
+
// ring. Lack of space disables overlap; it never rejects a legal next frame.
|
|
353
|
+
if (start > this.#receiveLimit || payloadClaim > this.#receiveLimit - start) {
|
|
354
|
+
if (prefetch)
|
|
355
|
+
return undefined;
|
|
356
|
+
fail("receive_credit");
|
|
357
|
+
}
|
|
358
|
+
const body = this.#bodyQueue;
|
|
359
|
+
let segments;
|
|
360
|
+
if (body !== undefined) {
|
|
361
|
+
const offset = start - body.start;
|
|
362
|
+
if (offset < 0n || BigInt(bytes) > body.end - start)
|
|
363
|
+
fail("receive_credit");
|
|
364
|
+
segments = [byteSlice(body.bytes, Number(offset), Number(offset) + bytes)];
|
|
365
|
+
}
|
|
366
|
+
else {
|
|
367
|
+
if (start < this.#released || start - this.#released + BigInt(bytes) > BigInt(this.#ring.length))
|
|
368
|
+
fail("receive_credit");
|
|
369
|
+
const at = this.#ring.length === 0 ? 0 : (this.#head + Number(start - this.#released)) % this.#ring.length;
|
|
370
|
+
const first = Math.min(bytes, this.#ring.length - at);
|
|
371
|
+
segments = [byteSlice(this.#ring, at, at + first), byteSlice(this.#ring, 0, bytes - first)];
|
|
372
|
+
}
|
|
373
|
+
// The direction already owns this exact backing reference before granting
|
|
374
|
+
// credit, including the retained alias of a transferred message body. Lend
|
|
375
|
+
// that owner to its bounded native claims; do not allocate a fresh
|
|
376
|
+
// root alias under memory pressure after the promise has been published.
|
|
377
|
+
const reference = body?.reference ?? this.#queueReference ?? this.#reservation;
|
|
378
|
+
reference.checkRetained();
|
|
379
|
+
let released = false;
|
|
380
|
+
const claim = {
|
|
381
|
+
get segments() { if (released)
|
|
382
|
+
fail("receive_owner"); return segments; },
|
|
383
|
+
check: () => { if (released || !this.#nativeClaims.includes(state))
|
|
384
|
+
fail("receive_owner"); reference.checkRetained(); this.#checkIngress(); },
|
|
385
|
+
release: () => {
|
|
386
|
+
if (released)
|
|
387
|
+
return;
|
|
388
|
+
released = true;
|
|
389
|
+
if (!state.validated)
|
|
390
|
+
state.clear();
|
|
391
|
+
segments = [];
|
|
392
|
+
const at = this.#nativeClaims.indexOf(state);
|
|
393
|
+
if (at < 0)
|
|
394
|
+
fail("receive_owner");
|
|
395
|
+
this.#nativeClaims.splice(at, 1);
|
|
396
|
+
if (state.detached && !this.#nativeClaims.some(value => value.reference === reference))
|
|
397
|
+
reference.release();
|
|
398
|
+
this.#cleanup();
|
|
399
|
+
},
|
|
400
|
+
};
|
|
401
|
+
const state = { claim, reference, end: start + payloadClaim, logicalBytes: payloadClaim,
|
|
402
|
+
detached: false, validated: false, clear: () => { for (const part of segments)
|
|
403
|
+
part.fill(0); } };
|
|
404
|
+
this.#nativeClaims.push(state);
|
|
405
|
+
return claim;
|
|
406
|
+
}
|
|
407
|
+
nativePrefetchFits(claim, remaining) {
|
|
408
|
+
this.#checkIngress();
|
|
409
|
+
if (!this.#nativeClaims.some(state => state.claim === claim))
|
|
410
|
+
fail("receive_owner");
|
|
411
|
+
return this.#nativeClaims.reduce((total, state) => total + (state.validated ? 0n : state.logicalBytes), 0n) <= remaining;
|
|
412
|
+
}
|
|
413
|
+
#validateNative(length) {
|
|
414
|
+
const state = this.#nativeClaims.find(value => !value.validated);
|
|
415
|
+
if (state === undefined)
|
|
416
|
+
return;
|
|
417
|
+
if (BigInt(length) > state.logicalBytes)
|
|
418
|
+
fail("receive_credit");
|
|
419
|
+
// Coalescing and schema validation have ended their ciphertext borrow.
|
|
420
|
+
// Keep the original claim/reference until its actual candidate exits, but
|
|
421
|
+
// allow this exact storage to receive the authenticated plaintext below.
|
|
422
|
+
state.clear();
|
|
423
|
+
state.validated = true;
|
|
424
|
+
}
|
|
425
|
+
#releaseBacking(reference) {
|
|
426
|
+
let retained = false;
|
|
427
|
+
for (const state of this.#nativeClaims)
|
|
428
|
+
if (state.reference === reference) {
|
|
429
|
+
state.detached = true;
|
|
430
|
+
retained = true;
|
|
431
|
+
}
|
|
432
|
+
if (!retained)
|
|
433
|
+
reference.release();
|
|
434
|
+
}
|
|
435
|
+
/** Original fixed queue capacity backs the new absolute promise. Publication
|
|
436
|
+
* calls commitCredit in the same record ticket gate, never after completion. */
|
|
437
|
+
nextCredit() {
|
|
438
|
+
if (this.#abandoned || this.#fin !== undefined || this.#creditPaused)
|
|
439
|
+
return this.#receiveLimit;
|
|
440
|
+
if (this.#bodyQueue !== undefined) {
|
|
441
|
+
const end = this.#bodyQueue.end, window = this.#released + BigInt(this.#config.queueBytes);
|
|
442
|
+
return window < end ? window : end;
|
|
443
|
+
}
|
|
444
|
+
if (this.#ring.length === 0)
|
|
445
|
+
return this.#receiveLimit;
|
|
446
|
+
const remaining = uint64Max - this.#released;
|
|
447
|
+
return this.#released + (remaining < BigInt(this.#config.queueBytes) ? remaining : BigInt(this.#config.queueBytes));
|
|
448
|
+
}
|
|
449
|
+
commitCredit(limit) {
|
|
450
|
+
this.#checkIngress();
|
|
451
|
+
if (limit < this.#receiveLimit || limit > this.nextCredit())
|
|
452
|
+
fail("receive_credit");
|
|
453
|
+
this.#receiveLimit = limit;
|
|
454
|
+
}
|
|
455
|
+
state() {
|
|
456
|
+
return this.#terminal ?? Object.freeze({ stream_status: this.#fin !== undefined && this.#queued === 0 ? "eof" : "open" });
|
|
457
|
+
}
|
|
458
|
+
checkAdapterClaim() {
|
|
459
|
+
if (this.#active !== undefined || this.#closed)
|
|
460
|
+
throw new V4ReadMethodError("read_in_progress");
|
|
461
|
+
this.#delivery.check();
|
|
462
|
+
}
|
|
463
|
+
setAdapterCreditPaused(paused) {
|
|
464
|
+
this.#creditPaused = paused;
|
|
465
|
+
if (!paused && !this.#closed)
|
|
466
|
+
this.released?.();
|
|
467
|
+
}
|
|
468
|
+
/** A single authenticated message interval can take the queue's real
|
|
469
|
+
* backing. Cross-boundary promises keep their ring and full overlap charge. */
|
|
470
|
+
admitMessageBody(length, structure, reserve) {
|
|
471
|
+
if (!Number.isSafeInteger(length) || length < 0 || BigInt(length) > uint64Max - this.#released ||
|
|
472
|
+
this.#closed || this.#working || this.#wait !== undefined || this.#bodyQueue !== undefined)
|
|
473
|
+
fail("receive_owner");
|
|
474
|
+
this.#delivery.check();
|
|
475
|
+
const direct = this.#nativeClaims.length === 0 && length > 0 && this.#ring.length > 0 && this.#receiveLimit - this.#released <= BigInt(length) && this.#queued <= length;
|
|
476
|
+
const reuse = direct && length <= this.#ring.length;
|
|
477
|
+
const charge = structure.add(vector(reuse ? 0n : BigInt(length), 0n, 0n));
|
|
478
|
+
const reference = reserve("v4_message_body", charge);
|
|
479
|
+
let retained;
|
|
480
|
+
try {
|
|
481
|
+
// Take the actual I/O alias before changing any backing or accounting.
|
|
482
|
+
// A canceled message cannot refund storage still held by this direction.
|
|
483
|
+
if (direct)
|
|
484
|
+
retained = reference.borrow();
|
|
485
|
+
const bytes = reuse ? byteSlice(this.#ring, 0, length) : new NativeBytes(length);
|
|
486
|
+
if (!direct)
|
|
487
|
+
return { bytes, reference };
|
|
488
|
+
const capacity = this.#ring.length, original = this.#queueReference ?? this.#reservation;
|
|
489
|
+
// New allocation overlaps the old ring until its bytes are copied and
|
|
490
|
+
// all aliases below have exited. Reuse performs an in-place rotation.
|
|
491
|
+
if (!reuse) {
|
|
492
|
+
const first = Math.min(this.#queued, capacity - this.#head);
|
|
493
|
+
copy.call(bytes, byteSlice(this.#ring, this.#head, this.#head + first));
|
|
494
|
+
if (first < this.#queued)
|
|
495
|
+
copy.call(bytes, byteSlice(this.#ring, 0, this.#queued - first), first);
|
|
496
|
+
}
|
|
497
|
+
original.moveBytesTo(reference, BigInt(capacity));
|
|
498
|
+
if (reuse && this.#head !== 0) {
|
|
499
|
+
reverse.call(byteSlice(this.#ring, 0, this.#head));
|
|
500
|
+
reverse.call(byteSlice(this.#ring, this.#head, capacity));
|
|
501
|
+
reverse.call(this.#ring);
|
|
502
|
+
}
|
|
503
|
+
if (!reuse)
|
|
504
|
+
this.#ring.fill(0);
|
|
505
|
+
this.#bodyQueue = { start: this.#released, end: this.#released + BigInt(length), bytes, reference: retained };
|
|
506
|
+
this.#ring = empty;
|
|
507
|
+
this.#head = 0;
|
|
508
|
+
this.#queueReference?.release();
|
|
509
|
+
this.#queueReference = undefined;
|
|
510
|
+
if (!reuse)
|
|
511
|
+
reference.shrink(charge, [retained]);
|
|
512
|
+
return { bytes, reference };
|
|
513
|
+
}
|
|
514
|
+
catch (error) {
|
|
515
|
+
retained?.release();
|
|
516
|
+
reference.release();
|
|
517
|
+
throw error;
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
/** A consumed message still owns its backing. New credit needs a different
|
|
521
|
+
* paid queue; restoring it cannot reuse the private result's memory. */
|
|
522
|
+
ensureMessageQueue(reserve) {
|
|
523
|
+
if (this.#closed || this.#working || this.#wait !== undefined)
|
|
524
|
+
fail("receive_owner");
|
|
525
|
+
if (this.#ring.length !== 0 || this.#fin !== undefined && this.#queued === 0)
|
|
526
|
+
return;
|
|
527
|
+
if (this.#bodyQueue !== undefined && this.#released !== this.#bodyQueue.end)
|
|
528
|
+
fail("receive_owner");
|
|
529
|
+
const reference = reserve("v4_message_queue", vector(BigInt(this.#config.queueBytes), 0n, 0n));
|
|
530
|
+
try {
|
|
531
|
+
const bytes = new NativeBytes(this.#config.queueBytes);
|
|
532
|
+
this.#delivery.check();
|
|
533
|
+
const previous = this.#bodyQueue;
|
|
534
|
+
this.#bodyQueue = undefined;
|
|
535
|
+
if (previous !== undefined)
|
|
536
|
+
this.#releaseBacking(previous.reference);
|
|
537
|
+
this.#ring = bytes;
|
|
538
|
+
this.#head = 0;
|
|
539
|
+
this.#queueReference = reference;
|
|
540
|
+
}
|
|
541
|
+
catch (error) {
|
|
542
|
+
reference.release();
|
|
543
|
+
throw error;
|
|
544
|
+
}
|
|
545
|
+
this.released?.();
|
|
546
|
+
}
|
|
547
|
+
/** Consumes this exact key's packet on success or authenticated input failure. */
|
|
548
|
+
accept(packet, finalOffset) {
|
|
549
|
+
this.#checkIngress();
|
|
550
|
+
// A packet from another queue is an integration error, not a peer input
|
|
551
|
+
// violation. Do not consume it or damage either direction on that path.
|
|
552
|
+
const info = this.#cipher.inspectIncoming(packet);
|
|
553
|
+
if (info.frameType !== wire.frame_types.STREAM_DATA)
|
|
554
|
+
fail("receive_owner");
|
|
555
|
+
this.#working = true;
|
|
556
|
+
let document;
|
|
557
|
+
let scratch = this.#scratch, decoder = this.#decoder, shared = false, scratchUsed = 0;
|
|
558
|
+
try {
|
|
559
|
+
if (this.#config.workspace !== undefined) {
|
|
560
|
+
const position = this.#config.workspace.acquire(this);
|
|
561
|
+
scratch = position.scratch;
|
|
562
|
+
decoder = position.decoder;
|
|
563
|
+
shared = true;
|
|
564
|
+
}
|
|
565
|
+
if (info.plaintextBytes > scratch.length)
|
|
566
|
+
fail("receive_data");
|
|
567
|
+
scratchUsed = info.plaintextBytes;
|
|
568
|
+
const count = packet.copyBytes(scratch);
|
|
569
|
+
document = decoder.decodeMap(byteSlice(scratch, 0, count), "STREAM_DATA", { limits: {
|
|
570
|
+
max_data_payload_bytes: shared ? Math.min(this.#config.queueBytes, this.#config.plaintextBytes) : this.#config.maxDataBytes,
|
|
571
|
+
} });
|
|
572
|
+
if (document.uint(document.field(0, 0)) !== info.scope || document.uint(document.field(0, 1)) !== BigInt(info.direction) ||
|
|
573
|
+
document.uint(document.field(0, 2)) !== BigInt(info.epoch) || document.uint(document.field(0, 3)) !== info.sequence)
|
|
574
|
+
fail("receive_data");
|
|
575
|
+
const offset = document.uint(document.field(0, 4)), fin = document.boolean(document.field(0, 5));
|
|
576
|
+
const node = document.field(0, 6), length = document.size(node);
|
|
577
|
+
if (offset !== this.#ack || this.#fin !== undefined || BigInt(length) > uint64Max - offset)
|
|
578
|
+
fail("receive_sequence");
|
|
579
|
+
if (finalOffset !== undefined && (finalOffset < this.#ack || finalOffset > this.#receiveLimit || offset + BigInt(length) > finalOffset))
|
|
580
|
+
fail("receive_credit");
|
|
581
|
+
const body = this.#bodyQueue;
|
|
582
|
+
if (offset + BigInt(length) > this.#receiveLimit ||
|
|
583
|
+
(body === undefined ? length > this.#ring.length - this.#queued : offset < body.start || offset + BigInt(length) > body.end))
|
|
584
|
+
fail("receive_credit");
|
|
585
|
+
this.#delivery.check();
|
|
586
|
+
if (this.#closed)
|
|
587
|
+
fail("receive_closed");
|
|
588
|
+
this.#validateNative(length);
|
|
589
|
+
// All storage is prepaid. The hidden tail is not visible to readers until
|
|
590
|
+
// both full schema/association validation and crypto commit succeed.
|
|
591
|
+
if (!this.#abandoned && body !== undefined) {
|
|
592
|
+
document.copyRange(node, 0, byteSlice(body.bytes, Number(offset - body.start), Number(offset - body.start) + length), true);
|
|
593
|
+
}
|
|
594
|
+
else if (!this.#abandoned && length > 0) {
|
|
595
|
+
const tail = (this.#head + this.#queued) % this.#ring.length;
|
|
596
|
+
const first = Math.min(length, this.#ring.length - tail);
|
|
597
|
+
document.copyRange(node, 0, byteSlice(this.#ring, tail, tail + first), true);
|
|
598
|
+
if (first < length)
|
|
599
|
+
document.copyRange(node, first, byteSlice(this.#ring, 0, length - first), true);
|
|
600
|
+
}
|
|
601
|
+
packet.commitValidated();
|
|
602
|
+
if (!this.#abandoned)
|
|
603
|
+
this.#queued += length;
|
|
604
|
+
this.#ack += BigInt(length);
|
|
605
|
+
if (fin)
|
|
606
|
+
this.#fin = this.#ack;
|
|
607
|
+
}
|
|
608
|
+
catch (error) {
|
|
609
|
+
if (!this.#closed) {
|
|
610
|
+
if (error instanceof SchemaValidationError || error instanceof CBORWireError || error instanceof ReceiveError &&
|
|
611
|
+
["receive_data", "receive_sequence", "receive_credit"].includes(error.code)) {
|
|
612
|
+
this.#terminate({ stream_status: "error", error: { code: "stream_data_invalid", scope: "stream", retry_disposition: "preserve_facts" } });
|
|
613
|
+
}
|
|
614
|
+
else if (error instanceof ResourceError && error.code === "resource_exhausted") {
|
|
615
|
+
this.#terminate({ stream_status: "error", error: { code: "resource_exhausted", scope: "stream", retry_disposition: "preserve_facts" } });
|
|
616
|
+
}
|
|
617
|
+
else
|
|
618
|
+
this.close();
|
|
619
|
+
}
|
|
620
|
+
throw error;
|
|
621
|
+
}
|
|
622
|
+
finally {
|
|
623
|
+
document?.release();
|
|
624
|
+
packet.release();
|
|
625
|
+
if (shared)
|
|
626
|
+
this.#config.workspace.release(this, scratchUsed);
|
|
627
|
+
else
|
|
628
|
+
scratch.fill(0, 0, scratchUsed);
|
|
629
|
+
this.#working = false;
|
|
630
|
+
this.#pump();
|
|
631
|
+
this.#cleanup();
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
/** Called by the original rekey owner before retiring its old receive key. */
|
|
635
|
+
replaceCipher(next) {
|
|
636
|
+
this.#checkIngress();
|
|
637
|
+
const binding = next.receiveBinding(this.#reservation);
|
|
638
|
+
if (!next.sharesReceiveDirection(this.#cipher) || binding.epoch !== this.#binding.epoch + 1)
|
|
639
|
+
fail("receive_owner");
|
|
640
|
+
this.#cipher = next;
|
|
641
|
+
this.#binding = binding;
|
|
642
|
+
}
|
|
643
|
+
/** Seal application delivery at the original direction, while retaining the
|
|
644
|
+
* decoder and credit promise needed to authenticate/discard in-flight DATA.
|
|
645
|
+
* Discarded bytes advance only the authenticated frontier, never consumption. */
|
|
646
|
+
abandonDelivery() {
|
|
647
|
+
if (this.#closed || this.#abandoned)
|
|
648
|
+
return;
|
|
649
|
+
this.#abandoned = true;
|
|
650
|
+
this.#terminate({ stream_status: "aborted" });
|
|
651
|
+
this.#pump();
|
|
652
|
+
}
|
|
653
|
+
acquireCursor(target) { return this.#acquire(target); }
|
|
654
|
+
#acquire(target) {
|
|
655
|
+
if (typeof target !== "bigint" || target < 0n || target > BigInt(this.#config.maxCursorBytes) || target > uint64Max - this.#released) {
|
|
656
|
+
throw new V4ReadMethodError("invalid_argument");
|
|
657
|
+
}
|
|
658
|
+
if (this.#closed)
|
|
659
|
+
throw new V4ReadMethodError("closed");
|
|
660
|
+
if (this.#active !== undefined)
|
|
661
|
+
throw new V4ReadMethodError("read_in_progress");
|
|
662
|
+
this.#reservation.check();
|
|
663
|
+
this.#delivery.check();
|
|
664
|
+
if (this.#closed)
|
|
665
|
+
throw new V4ReadMethodError("closed");
|
|
666
|
+
const reservation = this.#cursorReservation.checkout();
|
|
667
|
+
try {
|
|
668
|
+
const owner = new ReceiveCursorOwner(token, this, this.#released, Number(target), reservation);
|
|
669
|
+
this.#active = owner;
|
|
670
|
+
return owner;
|
|
671
|
+
}
|
|
672
|
+
catch (error) {
|
|
673
|
+
reservation.release();
|
|
674
|
+
throw error;
|
|
675
|
+
}
|
|
676
|
+
}
|
|
677
|
+
read(maxBytes, options) {
|
|
678
|
+
let resolve, reject;
|
|
679
|
+
const promise = new NativePromise((yes, no) => { resolve = yes; reject = no; });
|
|
680
|
+
if (typeof maxBytes !== "bigint" || maxBytes <= 0n || maxBytes > BigInt(this.#config.maxCursorBytes)) {
|
|
681
|
+
reject(new V4ReadMethodError("invalid_argument"));
|
|
682
|
+
return promise;
|
|
683
|
+
}
|
|
684
|
+
if (this.#closed && this.state().stream_status === "eof") {
|
|
685
|
+
resolve(readResult(new Uint8Array(), this.#released, "ready", this.state()));
|
|
686
|
+
return promise;
|
|
687
|
+
}
|
|
688
|
+
const signal = options?.signal;
|
|
689
|
+
let owner;
|
|
690
|
+
try {
|
|
691
|
+
owner = this.#acquire(maxBytes);
|
|
692
|
+
}
|
|
693
|
+
catch (error) {
|
|
694
|
+
reject(error);
|
|
695
|
+
return promise;
|
|
696
|
+
}
|
|
697
|
+
const canceled = () => this.#pump();
|
|
698
|
+
const wait = { kind: "raw", owner, maximum: Number(maxBytes), resolve, reject, signal, canceled, armed: false };
|
|
699
|
+
this.#wait = wait;
|
|
700
|
+
signal?.addEventListener("abort", canceled, { once: true });
|
|
701
|
+
this.#pump();
|
|
702
|
+
wait.armed = true;
|
|
703
|
+
return promise;
|
|
704
|
+
}
|
|
705
|
+
cursorRead(capability, owner, maximum, transfer, signal) {
|
|
706
|
+
return new Promise((resolve, reject) => {
|
|
707
|
+
if (capability !== token || this.#active !== owner) {
|
|
708
|
+
reject(new V4ReadMethodError("owner_unavailable"));
|
|
709
|
+
return;
|
|
710
|
+
}
|
|
711
|
+
if (this.#wait !== undefined) {
|
|
712
|
+
reject(new V4ReadMethodError("read_in_progress"));
|
|
713
|
+
return;
|
|
714
|
+
}
|
|
715
|
+
if (!Number.isSafeInteger(maximum) || maximum <= 0 || maximum > owner.storage.length) {
|
|
716
|
+
reject(new V4ReadMethodError("invalid_argument"));
|
|
717
|
+
return;
|
|
718
|
+
}
|
|
719
|
+
const canceled = () => {
|
|
720
|
+
const wait = this.#wait;
|
|
721
|
+
if (wait?.owner !== owner)
|
|
722
|
+
return;
|
|
723
|
+
this.#detach(wait);
|
|
724
|
+
reject(new V4ReadMethodError("prefix_frozen"));
|
|
725
|
+
};
|
|
726
|
+
this.#wait = { kind: "cursor", owner, maximum, transfer, resolve, reject, signal, canceled };
|
|
727
|
+
signal.addEventListener("abort", canceled, { once: true });
|
|
728
|
+
if (signal.aborted)
|
|
729
|
+
canceled();
|
|
730
|
+
this.#pump();
|
|
731
|
+
});
|
|
732
|
+
}
|
|
733
|
+
claimDelivery(capability, owner) {
|
|
734
|
+
if (capability !== token || this.#active !== owner)
|
|
735
|
+
throw new V4ReadMethodError("owner_unavailable");
|
|
736
|
+
// Normal I/O close does not close the independently captured safety gate.
|
|
737
|
+
this.#delivery.check();
|
|
738
|
+
}
|
|
739
|
+
releaseCursor(capability, owner) {
|
|
740
|
+
if (capability !== token || this.#active !== owner || this.#wait?.owner === owner)
|
|
741
|
+
fail("receive_owner");
|
|
742
|
+
this.#active = undefined;
|
|
743
|
+
if (this.#bodyQueue !== undefined && this.#released === this.#bodyQueue.end) {
|
|
744
|
+
const body = this.#bodyQueue;
|
|
745
|
+
this.#bodyQueue = undefined;
|
|
746
|
+
this.#releaseBacking(body.reference);
|
|
747
|
+
}
|
|
748
|
+
this.#cleanup();
|
|
749
|
+
this.settled?.();
|
|
750
|
+
}
|
|
751
|
+
#checkIngress() {
|
|
752
|
+
if (this.#closed || this.#terminal !== undefined && !this.#abandoned)
|
|
753
|
+
fail("receive_closed");
|
|
754
|
+
if (this.#working)
|
|
755
|
+
fail("receive_busy");
|
|
756
|
+
this.#reservation.check();
|
|
757
|
+
this.#delivery.check();
|
|
758
|
+
if (this.#closed)
|
|
759
|
+
fail("receive_closed");
|
|
760
|
+
}
|
|
761
|
+
#detach(wait) {
|
|
762
|
+
if (this.#wait === wait)
|
|
763
|
+
this.#wait = undefined;
|
|
764
|
+
wait.signal?.removeEventListener("abort", wait.canceled);
|
|
765
|
+
}
|
|
766
|
+
#pump() {
|
|
767
|
+
if (this.#pumpQueued || this.#wait === undefined || this.#working)
|
|
768
|
+
return;
|
|
769
|
+
this.#pumpQueued = true;
|
|
770
|
+
enqueueReadJob(() => { this.#pumpQueued = false; this.#runPump(); });
|
|
771
|
+
}
|
|
772
|
+
#runPump() {
|
|
773
|
+
const wait = this.#wait;
|
|
774
|
+
if (wait === undefined || this.#working || wait.kind === "raw" && !wait.armed)
|
|
775
|
+
return;
|
|
776
|
+
if (this.#queued === 0 && this.state().stream_status === "open" && !(wait.kind === "raw" && wait.signal?.aborted))
|
|
777
|
+
return;
|
|
778
|
+
this.#detach(wait);
|
|
779
|
+
let handoff = false;
|
|
780
|
+
try {
|
|
781
|
+
if (wait.kind === "raw") {
|
|
782
|
+
if (wait.signal?.aborted && this.state().stream_status === "open") {
|
|
783
|
+
const result = readResult(new Uint8Array(), this.#released, "wait_canceled", this.state());
|
|
784
|
+
wait.resolve(result);
|
|
785
|
+
wait.owner.release();
|
|
786
|
+
return;
|
|
787
|
+
}
|
|
788
|
+
}
|
|
789
|
+
else if (this.#queued > 0) {
|
|
790
|
+
this.#delivery.check();
|
|
791
|
+
}
|
|
792
|
+
const body = this.#bodyQueue;
|
|
793
|
+
const maximum = Math.min(wait.maximum, this.#queued, body === undefined ? this.#ring.length - this.#head : Number(body.end - this.#released), this.#config.maxDataBytes);
|
|
794
|
+
let count = 0;
|
|
795
|
+
if (maximum > 0) {
|
|
796
|
+
const bytes = body === undefined ? byteSlice(this.#ring, this.#head, this.#head + maximum) :
|
|
797
|
+
byteSlice(body.bytes, Number(this.#released - body.start), Number(this.#released - body.start) + maximum);
|
|
798
|
+
if (wait.kind === "raw") {
|
|
799
|
+
copy.call(wait.owner.storage, bytes);
|
|
800
|
+
count = maximum;
|
|
801
|
+
}
|
|
802
|
+
else
|
|
803
|
+
count = wait.transfer(bytes);
|
|
804
|
+
if (!Number.isSafeInteger(count) || count < 0 || count > maximum)
|
|
805
|
+
fail("receive_owner");
|
|
806
|
+
}
|
|
807
|
+
let result;
|
|
808
|
+
if (wait.kind === "raw") {
|
|
809
|
+
const state = this.#terminal ?? { stream_status: this.#fin !== undefined && this.#queued === count ? "eof" : "open" };
|
|
810
|
+
result = readResult(byteSlice(wait.owner.storage, 0, count), this.#released + BigInt(count), "ready", state);
|
|
811
|
+
// All backing, result shape and the final capability exist before the
|
|
812
|
+
// irreversible claim. Retain the reservation through resolver exit.
|
|
813
|
+
wait.owner.claimDelivery();
|
|
814
|
+
handoff = true;
|
|
815
|
+
}
|
|
816
|
+
if (count > 0) {
|
|
817
|
+
if (body === undefined) {
|
|
818
|
+
this.#ring.fill(0, this.#head, this.#head + count);
|
|
819
|
+
this.#head = (this.#head + count) % this.#ring.length;
|
|
820
|
+
}
|
|
821
|
+
this.#queued -= count;
|
|
822
|
+
this.#released += BigInt(count);
|
|
823
|
+
}
|
|
824
|
+
if (wait.kind === "cursor")
|
|
825
|
+
wait.resolve();
|
|
826
|
+
else {
|
|
827
|
+
wait.resolve(result);
|
|
828
|
+
wait.owner.release();
|
|
829
|
+
}
|
|
830
|
+
// The original final resolver remains the caller's capability. Credit
|
|
831
|
+
// publication observes the committed transfer without chaining payload
|
|
832
|
+
// through a private intermediate promise or invoking host code in it.
|
|
833
|
+
if (count > 0)
|
|
834
|
+
this.released?.();
|
|
835
|
+
}
|
|
836
|
+
catch (error) {
|
|
837
|
+
if (handoff)
|
|
838
|
+
return;
|
|
839
|
+
if (wait.kind === "raw")
|
|
840
|
+
wait.owner.release();
|
|
841
|
+
wait.reject(error);
|
|
842
|
+
}
|
|
843
|
+
}
|
|
844
|
+
#terminate(state) {
|
|
845
|
+
this.#terminal ??= Object.freeze({ ...state, ...(state.error === undefined ? {} : { error: Object.freeze({ ...state.error }) }) });
|
|
846
|
+
if (this.#nativeClaims.length === 0)
|
|
847
|
+
this.#ring.fill(0);
|
|
848
|
+
else {
|
|
849
|
+
// An intentional delivery stop cannot corrupt an in-flight ciphertext
|
|
850
|
+
// which still belongs to the original authentication/termination path.
|
|
851
|
+
const first = Math.min(this.#queued, this.#ring.length - this.#head);
|
|
852
|
+
this.#ring.fill(0, this.#head, this.#head + first);
|
|
853
|
+
this.#ring.fill(0, 0, this.#queued - first);
|
|
854
|
+
}
|
|
855
|
+
this.#queued = 0;
|
|
856
|
+
}
|
|
857
|
+
close() {
|
|
858
|
+
if (this.#closed)
|
|
859
|
+
return;
|
|
860
|
+
this.#closed = true;
|
|
861
|
+
if (this.state().stream_status === "open")
|
|
862
|
+
this.#terminate({ stream_status: "aborted" });
|
|
863
|
+
if (!this.#borrowedCursor)
|
|
864
|
+
this.#cursorReservation?.closeAfterUse();
|
|
865
|
+
this.#pump();
|
|
866
|
+
this.#cleanup();
|
|
867
|
+
}
|
|
868
|
+
#cleanup() {
|
|
869
|
+
if (this.#closed && !this.#working) {
|
|
870
|
+
// Retained cursors/claims need their real bytes and safety gate, but no
|
|
871
|
+
// future parser access. They do not retain the shared full workspace.
|
|
872
|
+
this.#workspaceRelease?.();
|
|
873
|
+
this.#workspaceRelease = undefined;
|
|
874
|
+
this.#workspaceReference?.release();
|
|
875
|
+
this.#workspaceReference = undefined;
|
|
876
|
+
}
|
|
877
|
+
if (!this.#closed || this.#working || this.#nativeClaims.length !== 0 || this.#active !== undefined || this.#wait !== undefined)
|
|
878
|
+
return;
|
|
879
|
+
this.#ring.fill(0);
|
|
880
|
+
this.#scratch.fill(0);
|
|
881
|
+
this.#ring = empty;
|
|
882
|
+
this.#scratch = empty;
|
|
883
|
+
// The independent message owner clears or delivers its body. This I/O
|
|
884
|
+
// alias neither zeros a completed result nor refunds its transferred charge.
|
|
885
|
+
const body = this.#bodyQueue;
|
|
886
|
+
this.#bodyQueue = undefined;
|
|
887
|
+
body?.reference.release();
|
|
888
|
+
this.#queueReference?.release();
|
|
889
|
+
this.#queueReference = undefined;
|
|
890
|
+
this.#decoder?.close();
|
|
891
|
+
this.#decoder = undefined;
|
|
892
|
+
this.#cipher = undefined;
|
|
893
|
+
this.#delivery?.release();
|
|
894
|
+
this.#delivery = undefined;
|
|
895
|
+
this.#reservation?.release();
|
|
896
|
+
this.#reservation = undefined;
|
|
897
|
+
}
|
|
898
|
+
cleanupStatus() {
|
|
899
|
+
return this.#closed && this.#reservation === undefined && (this.#borrowedCursor || this.#cursorReservation?.cleanupComplete() !== false) ? complete : pending;
|
|
900
|
+
}
|
|
901
|
+
}
|
|
902
|
+
class ReceiveCursorOwner {
|
|
903
|
+
#direction;
|
|
904
|
+
#reservation;
|
|
905
|
+
#storage;
|
|
906
|
+
#claimed = false;
|
|
907
|
+
#state = { stream_status: "open" };
|
|
908
|
+
startOffset;
|
|
909
|
+
constructor(capability, direction, offset, size, reservation) {
|
|
910
|
+
if (capability !== token)
|
|
911
|
+
fail("receive_owner");
|
|
912
|
+
this.#direction = direction;
|
|
913
|
+
this.#reservation = reservation;
|
|
914
|
+
this.startOffset = offset;
|
|
915
|
+
this.#storage = new Uint8Array(size);
|
|
916
|
+
}
|
|
917
|
+
get storage() { return this.#storage; }
|
|
918
|
+
state() { return this.#direction?.state() ?? this.#state; }
|
|
919
|
+
read(maximum, transfer, signal) {
|
|
920
|
+
if (this.#direction === undefined)
|
|
921
|
+
return Promise.reject(new V4ReadMethodError("closed"));
|
|
922
|
+
return this.#direction.cursorRead(token, this, maximum, transfer, signal);
|
|
923
|
+
}
|
|
924
|
+
claimDelivery() {
|
|
925
|
+
if (this.#claimed)
|
|
926
|
+
throw new V4ReadMethodError("already_delivered");
|
|
927
|
+
if (this.#direction === undefined)
|
|
928
|
+
throw new V4ReadMethodError("closed");
|
|
929
|
+
this.#reservation.checkRetained();
|
|
930
|
+
this.#direction.claimDelivery(token, this);
|
|
931
|
+
this.#claimed = true;
|
|
932
|
+
}
|
|
933
|
+
release() {
|
|
934
|
+
if (this.#direction === undefined)
|
|
935
|
+
return;
|
|
936
|
+
const direction = this.#direction;
|
|
937
|
+
this.#state = direction.state();
|
|
938
|
+
this.#direction = undefined;
|
|
939
|
+
if (!this.#claimed)
|
|
940
|
+
this.#storage.fill(0);
|
|
941
|
+
this.#storage = empty;
|
|
942
|
+
this.#reservation.release();
|
|
943
|
+
this.#reservation = undefined;
|
|
944
|
+
direction.releaseCursor(token, this);
|
|
945
|
+
}
|
|
946
|
+
}
|
|
947
|
+
function readResult(data, offset, waitStatus, state) {
|
|
948
|
+
const error = state.error;
|
|
949
|
+
const result = { data, progress: Object.freeze({ offset, filled: BigInt(data.length) }), wait_status: waitStatus,
|
|
950
|
+
stream_status: state.stream_status, ...(error === undefined ? {} : { error }) };
|
|
951
|
+
Object.defineProperty(result, "then", { value: undefined });
|
|
952
|
+
return Object.freeze(result);
|
|
953
|
+
}
|
|
954
|
+
for (const owner of [ReceiveDeliveryGate, ReliableReceiveDirection, ReceiveCursorOwner]) {
|
|
955
|
+
Object.freeze(owner.prototype);
|
|
956
|
+
Object.freeze(owner);
|
|
957
|
+
}
|