@floegence/flowersec-core 5.11.0 → 6.1.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.
Files changed (716) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +170 -58
  3. package/THIRD_PARTY_NOTICES.md +3072 -7
  4. package/dist/application/rpcJSON.d.ts +15 -0
  5. package/dist/{rpc/validate.js → application/rpcJSON.js} +1 -1
  6. package/dist/browser/clientV4.d.ts +61 -0
  7. package/dist/browser/clientV4.js +179 -0
  8. package/dist/browser/index.d.ts +15 -8
  9. package/dist/browser/index.js +5 -3
  10. package/dist/browser/indexedDBPoolV4.d.ts +101 -0
  11. package/dist/browser/indexedDBPoolV4.js +634 -0
  12. package/dist/browser/liveHTTPSV4.d.ts +35 -0
  13. package/dist/browser/liveHTTPSV4.js +162 -0
  14. package/dist/browser/localBrowserBridge.d.ts +20 -0
  15. package/dist/browser/localBrowserBridge.js +82 -0
  16. package/dist/browser/poolServerAllow.d.ts +21 -0
  17. package/dist/browser/poolServerAllow.js +151 -0
  18. package/dist/browser/webTransportPositionsV4.d.ts +16 -0
  19. package/dist/browser/webTransportPositionsV4.js +75 -0
  20. package/dist/browser/webTransportStreamV4.d.ts +36 -0
  21. package/dist/browser/webTransportStreamV4.js +370 -0
  22. package/dist/browser/webTransportV4.d.ts +126 -0
  23. package/dist/browser/webTransportV4.js +627 -0
  24. package/dist/browser/wssV4.d.ts +69 -0
  25. package/dist/browser/wssV4.js +339 -0
  26. package/dist/cli.d.ts +24 -1
  27. package/dist/cli.js +91 -119
  28. package/dist/defaults.d.ts +1 -23
  29. package/dist/defaults.js +1 -23
  30. package/dist/facade.d.ts +104 -21
  31. package/dist/facade.js +45 -8
  32. package/dist/generated/brotliWorker.d.ts +1 -0
  33. package/dist/generated/brotliWorker.js +3 -0
  34. package/dist/generated/idna151.d.ts +2 -0
  35. package/dist/generated/idna151.js +38 -0
  36. package/dist/generated/normalization151.d.ts +5 -0
  37. package/dist/generated/normalization151.js +878 -0
  38. package/dist/generated/sqliteWorkers.d.ts +2 -0
  39. package/dist/generated/sqliteWorkers.js +3 -0
  40. package/dist/generated/transportV4APIResults.d.ts +21 -1
  41. package/dist/generated/transportV4APIResults.js +42 -1
  42. package/dist/generated/transportV4Registry.d.ts +276 -2
  43. package/dist/generated/transportV4Registry.js +10 -4
  44. package/dist/interop/browserRunner.d.ts +72 -0
  45. package/dist/interop/browserRunner.js +354 -0
  46. package/dist/interop/currentClock.d.ts +3 -0
  47. package/dist/interop/currentClock.js +39 -0
  48. package/dist/interop/currentContracts.d.ts +6 -0
  49. package/dist/interop/currentContracts.js +14 -0
  50. package/dist/interop/currentNativeTunnel.d.ts +31 -0
  51. package/dist/interop/currentNativeTunnel.js +185 -0
  52. package/dist/interop/currentParity.d.ts +68 -0
  53. package/dist/interop/currentParity.js +392 -0
  54. package/dist/interop/currentPeer.d.ts +252 -0
  55. package/dist/interop/currentPeer.js +677 -0
  56. package/dist/interop/currentRegisteredTunnelPeer.d.ts +37 -0
  57. package/dist/interop/currentRegisteredTunnelPeer.js +93 -0
  58. package/dist/interop/currentRelayPeer.d.ts +131 -0
  59. package/dist/interop/currentRelayPeer.js +263 -0
  60. package/dist/interop/currentServer.d.ts +44 -0
  61. package/dist/interop/currentServer.js +299 -0
  62. package/dist/interop/currentTLSPin.d.ts +9 -0
  63. package/dist/interop/currentTLSPin.js +44 -0
  64. package/dist/interop/currentTunnelMaterial.d.ts +34 -0
  65. package/dist/interop/currentTunnelMaterial.js +100 -0
  66. package/dist/interop/httpApplicationPeer.d.ts +15 -0
  67. package/dist/interop/httpApplicationPeer.js +167 -0
  68. package/dist/interop/invalidProofPeer.d.ts +8 -0
  69. package/dist/interop/invalidProofPeer.js +106 -0
  70. package/dist/interop/proxyServerPeer.js +8 -56
  71. package/dist/interop/serverParityPeer.d.ts +101 -1
  72. package/dist/interop/serverParityPeer.js +550 -578
  73. package/dist/node/acceptorCurrent.d.ts +55 -0
  74. package/dist/node/acceptorCurrent.js +286 -0
  75. package/dist/node/admissionRecord.d.ts +23 -0
  76. package/dist/node/admissionRecord.js +178 -0
  77. package/dist/node/clientV4.d.ts +59 -0
  78. package/dist/node/clientV4.js +197 -0
  79. package/dist/node/connectionPath.d.ts +2 -0
  80. package/dist/node/connectionPath.js +18 -0
  81. package/dist/node/endpointDialer.d.ts +70 -0
  82. package/dist/node/endpointDialer.js +231 -0
  83. package/dist/node/endpointListener.d.ts +48 -0
  84. package/dist/node/endpointListener.js +403 -0
  85. package/dist/node/endpointTransport.d.ts +7 -0
  86. package/dist/node/endpointTransport.js +18 -0
  87. package/dist/node/grantIssuerCurrent.d.ts +64 -0
  88. package/dist/node/grantIssuerCurrent.js +355 -0
  89. package/dist/node/index.d.ts +52 -16
  90. package/dist/node/index.js +24 -6
  91. package/dist/node/liveHTTPSV4.d.ts +28 -0
  92. package/dist/node/liveHTTPSV4.js +298 -0
  93. package/dist/node/liveTunnelAuthorityCurrent.d.ts +153 -0
  94. package/dist/node/liveTunnelAuthorityCurrent.js +590 -0
  95. package/dist/node/nativeDuplexBridgeV4.d.ts +41 -0
  96. package/dist/node/nativeDuplexBridgeV4.js +494 -0
  97. package/dist/node/nativeTransportCurrent.d.ts +196 -0
  98. package/dist/node/nativeTransportCurrent.js +37 -0
  99. package/dist/node/poolServerAllow.d.ts +33 -0
  100. package/dist/node/poolServerAllow.js +277 -0
  101. package/dist/node/proxyCredentials.d.ts +67 -0
  102. package/dist/node/proxyCredentials.js +364 -0
  103. package/dist/node/proxyNetwork.d.ts +18 -0
  104. package/dist/node/proxyNetwork.js +213 -0
  105. package/dist/node/proxyServer.d.ts +30 -4
  106. package/dist/node/proxyServer.js +599 -154
  107. package/dist/node/rawQUICCurrent.d.ts +139 -0
  108. package/dist/node/rawQUICCurrent.js +1177 -0
  109. package/dist/node/registeredLiveTunnelControl.d.ts +74 -0
  110. package/dist/node/registeredLiveTunnelControl.js +865 -0
  111. package/dist/node/registeredPoolTunnelAuthority.d.ts +50 -0
  112. package/dist/node/registeredPoolTunnelAuthority.js +305 -0
  113. package/dist/node/registeredTunnelControl.d.ts +189 -0
  114. package/dist/node/registeredTunnelControl.js +1007 -0
  115. package/dist/node/registeredWinnerContinuation.d.ts +26 -0
  116. package/dist/node/registeredWinnerContinuation.js +83 -0
  117. package/dist/node/relayNativePair.d.ts +62 -0
  118. package/dist/node/relayNativePair.js +737 -0
  119. package/dist/node/relayRecord.d.ts +57 -0
  120. package/dist/node/relayRecord.js +275 -0
  121. package/dist/node/serveRawQUIC.d.ts +58 -0
  122. package/dist/node/serveRawQUIC.js +331 -0
  123. package/dist/node/serveWSS.d.ts +58 -0
  124. package/dist/node/serveWSS.js +309 -0
  125. package/dist/node/sqliteAdmission.d.ts +100 -0
  126. package/dist/node/sqliteAdmission.js +1185 -0
  127. package/dist/node/sqliteExecutionContentV4.d.ts +63 -0
  128. package/dist/node/sqliteExecutionContentV4.js +251 -0
  129. package/dist/node/sqliteExecutionV4.d.ts +114 -0
  130. package/dist/node/sqliteExecutionV4.js +1052 -0
  131. package/dist/node/sqliteFormat.d.ts +20 -0
  132. package/dist/node/sqliteFormat.js +72 -0
  133. package/dist/node/sqliteInspectionV4.d.ts +7 -0
  134. package/dist/node/sqliteInspectionV4.js +47 -0
  135. package/dist/node/sqliteNativeV4.d.ts +3 -0
  136. package/dist/node/sqliteNativeV4.js +16 -0
  137. package/dist/node/sqlitePoolV4.d.ts +41 -0
  138. package/dist/node/sqlitePoolV4.js +282 -0
  139. package/dist/node/sqlitePoolWorkerProgramV4.js +411 -0
  140. package/dist/node/sqlitePoolWorkerV4.d.ts +67 -0
  141. package/dist/node/sqlitePoolWorkerV4.js +206 -0
  142. package/dist/node/sqliteV4.d.ts +82 -0
  143. package/dist/node/sqliteV4.js +166 -0
  144. package/dist/node/sqliteWorkerProgramV4.js +175 -0
  145. package/dist/node/sqliteWorkerV4.d.ts +47 -0
  146. package/dist/node/sqliteWorkerV4.js +142 -0
  147. package/dist/node/streamDuplexV4.d.ts +33 -0
  148. package/dist/node/streamDuplexV4.js +359 -0
  149. package/dist/node/tunnelListenerPreparation.d.ts +37 -0
  150. package/dist/node/tunnelListenerPreparation.js +162 -0
  151. package/dist/node/tunnelRuntime.d.ts +124 -0
  152. package/dist/node/tunnelRuntime.js +1205 -0
  153. package/dist/node/webTransportCurrent.d.ts +24 -0
  154. package/dist/node/webTransportCurrent.js +12 -0
  155. package/dist/node/wssV4.d.ts +99 -0
  156. package/dist/node/wssV4.js +846 -0
  157. package/dist/proxy/admission.d.ts +21 -0
  158. package/dist/proxy/admission.js +126 -0
  159. package/dist/proxy/brotliBody.d.ts +10 -0
  160. package/dist/proxy/brotliBody.js +85 -0
  161. package/dist/proxy/credentialControl.d.ts +30 -0
  162. package/dist/proxy/credentialControl.js +86 -0
  163. package/dist/proxy/currentStream.d.ts +24 -0
  164. package/dist/proxy/currentStream.js +158 -0
  165. package/dist/proxy/fetch.d.ts +3 -2
  166. package/dist/proxy/fetch.js +96 -29
  167. package/dist/proxy/headers.d.ts +8 -0
  168. package/dist/proxy/headers.js +63 -0
  169. package/dist/proxy/index.d.ts +4 -0
  170. package/dist/proxy/index.js +2 -0
  171. package/dist/proxy/integration.d.ts +12 -8
  172. package/dist/proxy/integration.js +23 -16
  173. package/dist/proxy/policy.d.ts +5 -0
  174. package/dist/proxy/policy.js +60 -22
  175. package/dist/proxy/publicationOwner.d.ts +10 -0
  176. package/dist/proxy/publicationOwner.js +130 -0
  177. package/dist/proxy/requestAssociation.d.ts +11 -0
  178. package/dist/proxy/requestAssociation.js +8 -0
  179. package/dist/proxy/runtime.d.ts +3 -1
  180. package/dist/proxy/runtime.js +403 -170
  181. package/dist/proxy/scope.js +2 -2
  182. package/dist/proxy/serviceWorker.d.ts +3 -0
  183. package/dist/proxy/serviceWorker.js +634 -176
  184. package/dist/proxy/serviceWorkerRuntime.js +26 -1
  185. package/dist/proxy/stream.d.ts +16 -3
  186. package/dist/proxy/stream.js +6 -0
  187. package/dist/proxy/surface.d.ts +45 -0
  188. package/dist/proxy/surface.js +384 -0
  189. package/dist/proxy/types.d.ts +49 -6
  190. package/dist/proxy/windowBridge.d.ts +11 -3
  191. package/dist/proxy/windowBridge.js +62 -19
  192. package/dist/proxy/wire.d.ts +11 -0
  193. package/dist/proxy/wire.js +214 -0
  194. package/dist/proxy/wsPatch.js +13 -6
  195. package/dist/public/contract.d.ts +0 -71
  196. package/dist/public/contract.js +0 -8
  197. package/dist/public/streamKind.d.ts +3 -0
  198. package/dist/public/streamKind.js +19 -0
  199. package/dist/public/streamMetadata.d.ts +34 -2
  200. package/dist/public/streamMetadata.js +206 -13
  201. package/dist/v4/admissionOffer.d.ts +8 -0
  202. package/dist/v4/checkpoint.d.ts +23 -0
  203. package/dist/v4/checkpoint.js +16 -0
  204. package/dist/v4/clientServices.d.ts +35 -0
  205. package/dist/v4/clientServices.js +11 -0
  206. package/dist/v4/connectionDiagnostic.d.ts +42 -0
  207. package/dist/v4/connectionDiagnostic.js +45 -0
  208. package/dist/v4/connectionRequirements.d.ts +5 -0
  209. package/dist/v4/connectionRequirements.js +34 -0
  210. package/dist/v4/controller.d.ts +122 -0
  211. package/dist/v4/controller.js +1161 -0
  212. package/dist/v4/controllerNotifications.d.ts +81 -0
  213. package/dist/v4/controllerNotifications.js +610 -0
  214. package/dist/v4/diagnostics.d.ts +44 -0
  215. package/dist/v4/diagnostics.js +9 -0
  216. package/dist/v4/drain.d.ts +39 -0
  217. package/dist/v4/drain.js +80 -0
  218. package/dist/v4/duplexBridge.d.ts +53 -0
  219. package/dist/v4/duplexBridge.js +446 -0
  220. package/dist/v4/entrypoints.d.ts +20 -0
  221. package/dist/v4/entrypoints.js +50 -0
  222. package/dist/v4/eventSource.d.ts +34 -0
  223. package/dist/v4/eventSource.js +28 -0
  224. package/dist/v4/handlerPlan.d.ts +53 -0
  225. package/dist/v4/handlerPlan.js +129 -0
  226. package/dist/v4/liveness.d.ts +20 -0
  227. package/dist/v4/liveness.js +10 -0
  228. package/dist/v4/localReport.d.ts +17 -0
  229. package/dist/v4/localReport.js +10 -0
  230. package/dist/v4/messageDefinition.d.ts +66 -0
  231. package/dist/v4/messageDefinition.js +109 -0
  232. package/dist/v4/messageStream.d.ts +89 -0
  233. package/dist/v4/messageStream.js +1375 -0
  234. package/dist/v4/notificationOperation.d.ts +30 -0
  235. package/dist/v4/notificationOperation.js +31 -0
  236. package/dist/v4/notificationSubscription.d.ts +47 -0
  237. package/dist/v4/notificationSubscription.js +24 -0
  238. package/dist/v4/operationReference.d.ts +28 -0
  239. package/dist/v4/operationReference.js +61 -0
  240. package/dist/v4/operationReferenceCodec.d.ts +20 -0
  241. package/dist/v4/operationReferenceCodec.js +129 -0
  242. package/dist/v4/operationReferenceStore.d.ts +90 -0
  243. package/dist/v4/operationReferenceStore.js +272 -0
  244. package/dist/v4/operationResultRead.d.ts +26 -0
  245. package/dist/v4/operationResultRead.js +24 -0
  246. package/dist/v4/poolControl.d.ts +11 -0
  247. package/dist/v4/poolControl.js +50 -0
  248. package/dist/v4/poolSource.d.ts +93 -0
  249. package/dist/v4/poolSource.js +900 -0
  250. package/dist/v4/public.d.ts +232 -0
  251. package/dist/v4/public.js +632 -0
  252. package/dist/v4/responsePublication.d.ts +48 -0
  253. package/dist/v4/responsePublication.js +227 -0
  254. package/dist/v4/resume.d.ts +17 -0
  255. package/dist/v4/resume.js +15 -0
  256. package/dist/v4/runtime/applicationExecutor.d.ts +190 -0
  257. package/dist/v4/runtime/applicationExecutor.js +759 -0
  258. package/dist/v4/runtime/applicationHeader.d.ts +61 -0
  259. package/dist/v4/runtime/applicationHeader.js +222 -0
  260. package/dist/v4/runtime/canonicalText.d.ts +8 -0
  261. package/dist/v4/runtime/canonicalText.js +142 -0
  262. package/dist/v4/runtime/cbor.d.ts +92 -0
  263. package/dist/v4/runtime/cbor.js +728 -0
  264. package/dist/v4/runtime/cborWriter.d.ts +18 -0
  265. package/dist/v4/runtime/cborWriter.js +59 -0
  266. package/dist/v4/runtime/checkpointToken.d.ts +41 -0
  267. package/dist/v4/runtime/checkpointToken.js +61 -0
  268. package/dist/v4/runtime/clientAdmission.d.ts +40 -0
  269. package/dist/v4/runtime/clientAdmission.js +378 -0
  270. package/dist/v4/runtime/clientSessionSpec.d.ts +45 -0
  271. package/dist/v4/runtime/clientSessionSpec.js +91 -0
  272. package/dist/v4/runtime/clock.d.ts +80 -0
  273. package/dist/v4/runtime/clock.js +284 -0
  274. package/dist/v4/runtime/connectionFacts.d.ts +23 -0
  275. package/dist/v4/runtime/connectionFacts.js +106 -0
  276. package/dist/v4/runtime/contractAcceptance.d.ts +20 -0
  277. package/dist/v4/runtime/contractAcceptance.js +91 -0
  278. package/dist/v4/runtime/contractQuery.d.ts +57 -0
  279. package/dist/v4/runtime/contractQuery.js +265 -0
  280. package/dist/v4/runtime/contractQueryAccess.d.ts +25 -0
  281. package/dist/v4/runtime/contractQueryAccess.js +117 -0
  282. package/dist/v4/runtime/contractQueryAcquisition.d.ts +83 -0
  283. package/dist/v4/runtime/contractQueryAcquisition.js +572 -0
  284. package/dist/v4/runtime/contractQueryClient.d.ts +70 -0
  285. package/dist/v4/runtime/contractQueryClient.js +411 -0
  286. package/dist/v4/runtime/contractQueryCodecs.d.ts +20 -0
  287. package/dist/v4/runtime/contractQueryCodecs.js +71 -0
  288. package/dist/v4/runtime/contractQueryExchange.d.ts +36 -0
  289. package/dist/v4/runtime/contractQueryExchange.js +160 -0
  290. package/dist/v4/runtime/contractQueryService.d.ts +42 -0
  291. package/dist/v4/runtime/contractQueryService.js +572 -0
  292. package/dist/v4/runtime/contractQuerySession.d.ts +38 -0
  293. package/dist/v4/runtime/contractQuerySession.js +158 -0
  294. package/dist/v4/runtime/contractRoutes.d.ts +87 -0
  295. package/dist/v4/runtime/contractRoutes.js +396 -0
  296. package/dist/v4/runtime/contractSnapshotReader.d.ts +59 -0
  297. package/dist/v4/runtime/contractSnapshotReader.js +418 -0
  298. package/dist/v4/runtime/contractSnapshotWriter.d.ts +32 -0
  299. package/dist/v4/runtime/contractSnapshotWriter.js +208 -0
  300. package/dist/v4/runtime/controllerServiceSource.d.ts +23 -0
  301. package/dist/v4/runtime/controllerServiceSource.js +109 -0
  302. package/dist/v4/runtime/controllerUnaryRoute.d.ts +28 -0
  303. package/dist/v4/runtime/credentialNamespace.d.ts +143 -0
  304. package/dist/v4/runtime/credentialNamespace.js +1286 -0
  305. package/dist/v4/runtime/credentialSupport.d.ts +60 -0
  306. package/dist/v4/runtime/credentialSupport.js +294 -0
  307. package/dist/v4/runtime/credentialVerifier.d.ts +404 -0
  308. package/dist/v4/runtime/credentialVerifier.js +1443 -0
  309. package/dist/v4/runtime/cryptoUsage.d.ts +135 -0
  310. package/dist/v4/runtime/cryptoUsage.js +552 -0
  311. package/dist/v4/runtime/deadline.d.ts +31 -0
  312. package/dist/v4/runtime/deadline.js +188 -0
  313. package/dist/v4/runtime/diagnosticCounters.d.ts +15 -0
  314. package/dist/v4/runtime/diagnosticCounters.js +78 -0
  315. package/dist/v4/runtime/diagnosticObservation.d.ts +25 -0
  316. package/dist/v4/runtime/diagnosticObservation.js +67 -0
  317. package/dist/v4/runtime/diagnosticSink.d.ts +16 -0
  318. package/dist/v4/runtime/diagnosticSink.js +320 -0
  319. package/dist/v4/runtime/ed25519.d.ts +1 -0
  320. package/dist/v4/runtime/ed25519.js +34 -0
  321. package/dist/v4/runtime/endpointHop.d.ts +12 -0
  322. package/dist/v4/runtime/endpointHop.js +26 -0
  323. package/dist/v4/runtime/envelope.d.ts +66 -0
  324. package/dist/v4/runtime/envelope.js +275 -0
  325. package/dist/v4/runtime/environment.d.ts +277 -0
  326. package/dist/v4/runtime/environment.js +1913 -0
  327. package/dist/v4/runtime/executionManagementChannel.d.ts +27 -0
  328. package/dist/v4/runtime/executionManagementChannel.js +733 -0
  329. package/dist/v4/runtime/executionManagementCodec.d.ts +84 -0
  330. package/dist/v4/runtime/executionManagementCodec.js +127 -0
  331. package/dist/v4/runtime/executionStorage.d.ts +71 -0
  332. package/dist/v4/runtime/executionStorage.js +10 -0
  333. package/dist/v4/runtime/fixedDiagnosticExecutor.d.ts +34 -0
  334. package/dist/v4/runtime/fixedDiagnosticExecutor.js +149 -0
  335. package/dist/v4/runtime/fixedManagementExecutor.d.ts +21 -0
  336. package/dist/v4/runtime/fixedManagementExecutor.js +153 -0
  337. package/dist/v4/runtime/fixedQueryExecutor.d.ts +46 -0
  338. package/dist/v4/runtime/fixedQueryExecutor.js +311 -0
  339. package/dist/v4/runtime/grantDigest.d.ts +9 -0
  340. package/dist/v4/runtime/grantDigest.js +31 -0
  341. package/dist/v4/runtime/hopAuthentication.d.ts +51 -0
  342. package/dist/v4/runtime/hopAuthentication.js +392 -0
  343. package/dist/v4/runtime/host.d.ts +15 -0
  344. package/dist/v4/runtime/host.js +332 -0
  345. package/dist/v4/runtime/initializerWorkload.d.ts +38 -0
  346. package/dist/v4/runtime/initializerWorkload.js +164 -0
  347. package/dist/v4/runtime/lifecycle.d.ts +5 -0
  348. package/dist/v4/runtime/lifecycle.js +17 -0
  349. package/dist/v4/runtime/liveAuthorization.d.ts +42 -0
  350. package/dist/v4/runtime/liveAuthorization.js +133 -0
  351. package/dist/v4/runtime/liveAuthorizationWire.d.ts +8 -0
  352. package/dist/v4/runtime/liveAuthorizationWire.js +31 -0
  353. package/dist/v4/runtime/liveCarrierPreparation.d.ts +9 -0
  354. package/dist/v4/runtime/liveCarrierPreparation.js +27 -0
  355. package/dist/v4/runtime/liveness.d.ts +37 -0
  356. package/dist/v4/runtime/liveness.js +319 -0
  357. package/dist/v4/runtime/maintenancePositions.d.ts +29 -0
  358. package/dist/v4/runtime/maintenancePositions.js +152 -0
  359. package/dist/v4/runtime/messageCodec.d.ts +20 -0
  360. package/dist/v4/runtime/messageCodec.js +192 -0
  361. package/dist/v4/runtime/namespaceContinuity.d.ts +20 -0
  362. package/dist/v4/runtime/namespaceContinuity.js +176 -0
  363. package/dist/v4/runtime/nativeCandidates.d.ts +18 -0
  364. package/dist/v4/runtime/nativeCandidates.js +109 -0
  365. package/dist/v4/runtime/nativeFailure.d.ts +10 -0
  366. package/dist/v4/runtime/nativeFailure.js +32 -0
  367. package/dist/v4/runtime/nativeFrame.d.ts +47 -0
  368. package/dist/v4/runtime/nativeFrame.js +318 -0
  369. package/dist/v4/runtime/nativeIngress.d.ts +30 -0
  370. package/dist/v4/runtime/nativeIngress.js +177 -0
  371. package/dist/v4/runtime/nativePositions.d.ts +24 -0
  372. package/dist/v4/runtime/nativePositions.js +131 -0
  373. package/dist/v4/runtime/nativeProviderPositions.d.ts +16 -0
  374. package/dist/v4/runtime/nativeProviderPositions.js +75 -0
  375. package/dist/v4/runtime/nativeSend.d.ts +15 -0
  376. package/dist/v4/runtime/nativeSend.js +57 -0
  377. package/dist/v4/runtime/noiseHandshake.d.ts +70 -0
  378. package/dist/v4/runtime/noiseHandshake.js +373 -0
  379. package/dist/v4/runtime/noiseWasmBinary.d.ts +2 -0
  380. package/dist/v4/runtime/noiseWasmBinary.js +3 -0
  381. package/dist/v4/runtime/notifyChannel.d.ts +37 -0
  382. package/dist/v4/runtime/notifyChannel.js +277 -0
  383. package/dist/v4/runtime/notifyDispatch.d.ts +108 -0
  384. package/dist/v4/runtime/notifyDispatch.js +717 -0
  385. package/dist/v4/runtime/notifyExecution.d.ts +18 -0
  386. package/dist/v4/runtime/notifyExecution.js +59 -0
  387. package/dist/v4/runtime/notifyPreparation.d.ts +70 -0
  388. package/dist/v4/runtime/notifyPreparation.js +465 -0
  389. package/dist/v4/runtime/openAdmission.d.ts +125 -0
  390. package/dist/v4/runtime/openAdmission.js +810 -0
  391. package/dist/v4/runtime/peerOpenPreparation.d.ts +18 -0
  392. package/dist/v4/runtime/peerOpenPreparation.js +61 -0
  393. package/dist/v4/runtime/poolJournal.d.ts +18 -0
  394. package/dist/v4/runtime/poolJournal.js +14 -0
  395. package/dist/v4/runtime/poolJournalStorage.d.ts +4 -0
  396. package/dist/v4/runtime/poolJournalStorage.js +172 -0
  397. package/dist/v4/runtime/poolRecord.d.ts +9 -0
  398. package/dist/v4/runtime/poolRecord.js +23 -0
  399. package/dist/v4/runtime/poolRecordStorage.d.ts +10 -0
  400. package/dist/v4/runtime/poolRecordStorage.js +216 -0
  401. package/dist/v4/runtime/poolServerAllow.d.ts +49 -0
  402. package/dist/v4/runtime/poolServerAllow.js +38 -0
  403. package/dist/v4/runtime/poolSpend.d.ts +20 -0
  404. package/dist/v4/runtime/poolSpend.js +4 -0
  405. package/dist/v4/runtime/queryRenewalPosition.d.ts +59 -0
  406. package/dist/v4/runtime/queryRenewalPosition.js +220 -0
  407. package/dist/v4/runtime/random.d.ts +15 -0
  408. package/dist/v4/runtime/random.js +71 -0
  409. package/dist/v4/runtime/rawStreamPreparation.d.ts +40 -0
  410. package/dist/v4/runtime/rawStreamPreparation.js +125 -0
  411. package/dist/v4/runtime/receiveDirection.d.ts +135 -0
  412. package/dist/v4/runtime/receiveDirection.js +957 -0
  413. package/dist/v4/runtime/receiveWorkspace.d.ts +19 -0
  414. package/dist/v4/runtime/receiveWorkspace.js +82 -0
  415. package/dist/v4/runtime/record.d.ts +7 -0
  416. package/dist/v4/runtime/record.js +173 -0
  417. package/dist/v4/runtime/recordCrypto.d.ts +121 -0
  418. package/dist/v4/runtime/recordCrypto.js +633 -0
  419. package/dist/v4/runtime/recordWorkspace.d.ts +17 -0
  420. package/dist/v4/runtime/recordWorkspace.js +69 -0
  421. package/dist/v4/runtime/registeredCarrierPreparation.d.ts +17 -0
  422. package/dist/v4/runtime/registeredCarrierPreparation.js +191 -0
  423. package/dist/v4/runtime/rekey.d.ts +40 -0
  424. package/dist/v4/runtime/rekey.js +362 -0
  425. package/dist/v4/runtime/relayCredentials.d.ts +126 -0
  426. package/dist/v4/runtime/relayCredentials.js +349 -0
  427. package/dist/v4/runtime/replayWindow.d.ts +6 -0
  428. package/dist/v4/runtime/replayWindow.js +59 -0
  429. package/dist/v4/runtime/resources.d.ts +200 -0
  430. package/dist/v4/runtime/resources.js +1236 -0
  431. package/dist/v4/runtime/resumeCodec.d.ts +44 -0
  432. package/dist/v4/runtime/resumeCodec.js +192 -0
  433. package/dist/v4/runtime/resumeStream.d.ts +23 -0
  434. package/dist/v4/runtime/resumeStream.js +23 -0
  435. package/dist/v4/runtime/rpcApplication.d.ts +234 -0
  436. package/dist/v4/runtime/rpcApplication.js +2170 -0
  437. package/dist/v4/runtime/rpcApplicationServices.d.ts +18 -0
  438. package/dist/v4/runtime/rpcApplicationServices.js +62 -0
  439. package/dist/v4/runtime/rpcCallCapacity.d.ts +62 -0
  440. package/dist/v4/runtime/rpcCallCapacity.js +289 -0
  441. package/dist/v4/runtime/rpcChannel.d.ts +58 -0
  442. package/dist/v4/runtime/rpcChannel.js +334 -0
  443. package/dist/v4/runtime/rpcCompletion.d.ts +42 -0
  444. package/dist/v4/runtime/rpcCompletion.js +152 -0
  445. package/dist/v4/runtime/rpcEventSource.d.ts +27 -0
  446. package/dist/v4/runtime/rpcEventSource.js +201 -0
  447. package/dist/v4/runtime/rpcFragment.d.ts +42 -0
  448. package/dist/v4/runtime/rpcFragment.js +227 -0
  449. package/dist/v4/runtime/rpcInput.d.ts +41 -0
  450. package/dist/v4/runtime/rpcInput.js +137 -0
  451. package/dist/v4/runtime/rpcNetwork.d.ts +143 -0
  452. package/dist/v4/runtime/rpcNetwork.js +652 -0
  453. package/dist/v4/runtime/rpcOutputInterest.d.ts +20 -0
  454. package/dist/v4/runtime/rpcOutputInterest.js +106 -0
  455. package/dist/v4/runtime/rpcPayload.d.ts +24 -0
  456. package/dist/v4/runtime/rpcPayload.js +82 -0
  457. package/dist/v4/runtime/rpcPreacceptedStreams.d.ts +46 -0
  458. package/dist/v4/runtime/rpcPreacceptedStreams.js +406 -0
  459. package/dist/v4/runtime/rpcPublisher.d.ts +49 -0
  460. package/dist/v4/runtime/rpcPublisher.js +406 -0
  461. package/dist/v4/runtime/rpcReceiver.d.ts +40 -0
  462. package/dist/v4/runtime/rpcReceiver.js +255 -0
  463. package/dist/v4/runtime/rpcResumeDispatch.d.ts +46 -0
  464. package/dist/v4/runtime/rpcResumeDispatch.js +266 -0
  465. package/dist/v4/runtime/rpcStream.d.ts +14 -0
  466. package/dist/v4/runtime/rpcStream.js +12 -0
  467. package/dist/v4/runtime/rpcStreamMessages.d.ts +53 -0
  468. package/dist/v4/runtime/rpcStreamMessages.js +428 -0
  469. package/dist/v4/runtime/rpcStreamPreparation.d.ts +21 -0
  470. package/dist/v4/runtime/rpcStreamPreparation.js +110 -0
  471. package/dist/v4/runtime/rpcStreamingDispatch.d.ts +26 -0
  472. package/dist/v4/runtime/rpcStreamingDispatch.js +607 -0
  473. package/dist/v4/runtime/rpcStreamingExchange.d.ts +91 -0
  474. package/dist/v4/runtime/rpcStreamingExchange.js +812 -0
  475. package/dist/v4/runtime/rpcUnaryCall.d.ts +16 -0
  476. package/dist/v4/runtime/rpcUnaryCall.js +152 -0
  477. package/dist/v4/runtime/rpcUnaryDispatch.d.ts +34 -0
  478. package/dist/v4/runtime/rpcUnaryDispatch.js +569 -0
  479. package/dist/v4/runtime/rpcUnaryExchange.d.ts +127 -0
  480. package/dist/v4/runtime/rpcUnaryExchange.js +1042 -0
  481. package/dist/v4/runtime/rpcUnaryPreparation.d.ts +102 -0
  482. package/dist/v4/runtime/rpcUnaryPreparation.js +736 -0
  483. package/dist/v4/runtime/rpcUnaryRegistration.d.ts +33 -0
  484. package/dist/v4/runtime/rpcUnaryRegistration.js +113 -0
  485. package/dist/v4/runtime/rpcUnaryResultRecipient.d.ts +21 -0
  486. package/dist/v4/runtime/rpcUnaryResultRecipient.js +57 -0
  487. package/dist/v4/runtime/schema.d.ts +26 -0
  488. package/dist/v4/runtime/schema.js +668 -0
  489. package/dist/v4/runtime/schemaRegistry.d.ts +128 -0
  490. package/dist/v4/runtime/schemaRegistry.js +74 -0
  491. package/dist/v4/runtime/sendBudget.d.ts +10 -0
  492. package/dist/v4/runtime/sendBudget.js +46 -0
  493. package/dist/v4/runtime/serveGroup.d.ts +73 -0
  494. package/dist/v4/runtime/serveGroup.js +589 -0
  495. package/dist/v4/runtime/serverAdmission.d.ts +33 -0
  496. package/dist/v4/runtime/serverAdmission.js +342 -0
  497. package/dist/v4/runtime/serverAdmissionAuthority.d.ts +23 -0
  498. package/dist/v4/runtime/serverAdmissionAuthority.js +5 -0
  499. package/dist/v4/runtime/serverSessionSpec.d.ts +9 -0
  500. package/dist/v4/runtime/serverSessionSpec.js +12 -0
  501. package/dist/v4/runtime/serviceBinding.d.ts +128 -0
  502. package/dist/v4/runtime/serviceBinding.js +1435 -0
  503. package/dist/v4/runtime/serviceBindingConfig.d.ts +72 -0
  504. package/dist/v4/runtime/serviceBindingConfig.js +85 -0
  505. package/dist/v4/runtime/serviceBindingPool.d.ts +58 -0
  506. package/dist/v4/runtime/serviceBindingPool.js +327 -0
  507. package/dist/v4/runtime/serviceContract.d.ts +111 -0
  508. package/dist/v4/runtime/serviceContract.js +588 -0
  509. package/dist/v4/runtime/serviceInputs.d.ts +30 -0
  510. package/dist/v4/runtime/serviceInputs.js +201 -0
  511. package/dist/v4/runtime/serviceOfferPlan.d.ts +81 -0
  512. package/dist/v4/runtime/serviceOfferPlan.js +335 -0
  513. package/dist/v4/runtime/serviceOfferScheduler.d.ts +12 -0
  514. package/dist/v4/runtime/serviceOfferScheduler.js +201 -0
  515. package/dist/v4/runtime/serviceOfferWork.d.ts +25 -0
  516. package/dist/v4/runtime/serviceOfferWork.js +1 -0
  517. package/dist/v4/runtime/session.d.ts +411 -0
  518. package/dist/v4/runtime/session.js +6369 -0
  519. package/dist/v4/runtime/sessionActivity.d.ts +19 -0
  520. package/dist/v4/runtime/sessionActivity.js +97 -0
  521. package/dist/v4/runtime/sessionAdmission.d.ts +93 -0
  522. package/dist/v4/runtime/sessionAdmission.js +498 -0
  523. package/dist/v4/runtime/sessionCleanup.d.ts +47 -0
  524. package/dist/v4/runtime/sessionCleanup.js +268 -0
  525. package/dist/v4/runtime/sessionKeyPreparation.d.ts +19 -0
  526. package/dist/v4/runtime/sessionKeyPreparation.js +50 -0
  527. package/dist/v4/runtime/signedMap.d.ts +68 -0
  528. package/dist/v4/runtime/signedMap.js +425 -0
  529. package/dist/v4/runtime/streamAdapter.d.ts +113 -0
  530. package/dist/v4/runtime/streamAdapter.js +62 -0
  531. package/dist/v4/runtime/streamData.d.ts +11 -0
  532. package/dist/v4/runtime/streamData.js +50 -0
  533. package/dist/v4/runtime/streamOpenPreparation.d.ts +23 -0
  534. package/dist/v4/runtime/streamOpenPreparation.js +77 -0
  535. package/dist/v4/runtime/streamRegistration.d.ts +87 -0
  536. package/dist/v4/runtime/streamRegistration.js +296 -0
  537. package/dist/v4/runtime/taskObservation.d.ts +1 -0
  538. package/dist/v4/runtime/taskObservation.js +48 -0
  539. package/dist/v4/runtime/timeArithmetic.d.ts +29 -0
  540. package/dist/v4/runtime/timeArithmetic.js +107 -0
  541. package/dist/v4/runtime/unreliable.d.ts +76 -0
  542. package/dist/v4/runtime/unreliable.js +473 -0
  543. package/dist/v4/runtime/volatileExecutions.d.ts +128 -0
  544. package/dist/v4/runtime/volatileExecutions.js +792 -0
  545. package/dist/v4/runtime/wireRegistry.d.ts +52 -0
  546. package/dist/v4/runtime/wireRegistry.js +29 -0
  547. package/dist/v4/runtime/writeRequest.d.ts +42 -0
  548. package/dist/v4/runtime/writeRequest.js +237 -0
  549. package/dist/v4/serve.d.ts +107 -0
  550. package/dist/v4/serve.js +80 -0
  551. package/dist/v4/serviceClient.d.ts +92 -0
  552. package/dist/v4/serviceClient.js +323 -0
  553. package/dist/v4/serviceDefinition.d.ts +138 -0
  554. package/dist/v4/serviceDefinition.js +150 -0
  555. package/dist/v4/serviceDependencies.d.ts +66 -0
  556. package/dist/v4/serviceDependencies.js +250 -0
  557. package/dist/v4/serviceFactory.d.ts +31 -0
  558. package/dist/v4/serviceFactory.js +157 -0
  559. package/dist/v4/serviceHandlers.d.ts +55 -0
  560. package/dist/v4/serviceHandlers.js +15 -0
  561. package/dist/v4/serviceMembers.d.ts +4 -0
  562. package/dist/v4/serviceMembers.js +12 -0
  563. package/dist/v4/staticServiceContracts.d.ts +43 -0
  564. package/dist/v4/staticServiceContracts.js +161 -0
  565. package/dist/v4/storageFormat.d.ts +16 -0
  566. package/dist/v4/storageFormat.js +5 -0
  567. package/dist/v4/streamContent.d.ts +30 -0
  568. package/dist/v4/streamContent.js +29 -0
  569. package/dist/v4/streamHandlers.d.ts +61 -0
  570. package/dist/v4/streamHandlers.js +16 -0
  571. package/dist/v4/streamingOperation.d.ts +64 -0
  572. package/dist/v4/streamingOperation.js +141 -0
  573. package/dist/v4/testSupport/cbor.d.ts +124 -0
  574. package/dist/v4/testSupport/cbor.js +230 -0
  575. package/dist/v4/testSupport/credentials.d.ts +55 -0
  576. package/dist/v4/testSupport/credentials.js +111 -0
  577. package/dist/v4/testSupport/unicode.d.ts +19 -0
  578. package/dist/v4/testSupport/unicode.js +112 -0
  579. package/dist/v4/unaryOperation.d.ts +59 -0
  580. package/dist/v4/unaryOperation.js +80 -0
  581. package/dist/v4/unreliable.d.ts +26 -0
  582. package/dist/v4/unreliable.js +10 -0
  583. package/dist/v4/webStreams.d.ts +30 -0
  584. package/dist/v4/webStreams.js +377 -0
  585. package/package.json +19 -16
  586. package/sbom/cyclonedx.json +761 -43
  587. package/sbom/spdx.json +566 -49
  588. package/dist/browser/connectSessionV3.d.ts +0 -31
  589. package/dist/browser/connectSessionV3.js +0 -241
  590. package/dist/browser/directWebSocketProfileV1.d.ts +0 -14
  591. package/dist/browser/directWebSocketProfileV1.js +0 -71
  592. package/dist/browser/httpDirectV1.d.ts +0 -30
  593. package/dist/browser/httpDirectV1.js +0 -52
  594. package/dist/browser/privateLoopbackV1.d.ts +0 -30
  595. package/dist/browser/privateLoopbackV1.js +0 -70
  596. package/dist/framing/index.d.ts +0 -1
  597. package/dist/framing/index.js +0 -1
  598. package/dist/framing/jsonframe.d.ts +0 -14
  599. package/dist/framing/jsonframe.js +0 -42
  600. package/dist/node/acceptor.d.ts +0 -36
  601. package/dist/node/acceptor.js +0 -155
  602. package/dist/node/acceptorV3.d.ts +0 -57
  603. package/dist/node/acceptorV3.js +0 -227
  604. package/dist/node/byteStreamDuplex.d.ts +0 -4
  605. package/dist/node/byteStreamDuplex.js +0 -69
  606. package/dist/node/connectSessionV3.d.ts +0 -24
  607. package/dist/node/connectSessionV3.js +0 -79
  608. package/dist/node/nativeTransportAddon.d.ts +0 -104
  609. package/dist/node/nativeTransportAddon.js +0 -212
  610. package/dist/node/rawQuicAdapterV3.d.ts +0 -10
  611. package/dist/node/rawQuicAdapterV3.js +0 -76
  612. package/dist/node/rawQuicServerV3.d.ts +0 -24
  613. package/dist/node/rawQuicServerV3.js +0 -34
  614. package/dist/node/runtimeAuthorizationV3.d.ts +0 -29
  615. package/dist/node/runtimeAuthorizationV3.js +0 -126
  616. package/dist/node/tunnelRuntimeV3.d.ts +0 -57
  617. package/dist/node/tunnelRuntimeV3.js +0 -857
  618. package/dist/node/webSocketServerV3.d.ts +0 -27
  619. package/dist/node/webSocketServerV3.js +0 -219
  620. package/dist/node/wsFactory.d.ts +0 -8
  621. package/dist/node/wsFactory.js +0 -84
  622. package/dist/public/streamHandlers.d.ts +0 -20
  623. package/dist/public/streamHandlers.js +0 -127
  624. package/dist/rpc/callError.d.ts +0 -5
  625. package/dist/rpc/callError.js +0 -11
  626. package/dist/rpc/caller.d.ts +0 -8
  627. package/dist/rpc/client.d.ts +0 -23
  628. package/dist/rpc/client.js +0 -171
  629. package/dist/rpc/index.d.ts +0 -6
  630. package/dist/rpc/index.js +0 -6
  631. package/dist/rpc/rpcProxy.d.ts +0 -16
  632. package/dist/rpc/rpcProxy.js +0 -58
  633. package/dist/rpc/server.d.ts +0 -51
  634. package/dist/rpc/server.js +0 -283
  635. package/dist/rpc/typed.d.ts +0 -5
  636. package/dist/rpc/typed.js +0 -9
  637. package/dist/rpc/validate.d.ts +0 -4
  638. package/dist/rpc/wire.d.ts +0 -15
  639. package/dist/v3/admissionError.d.ts +0 -4
  640. package/dist/v3/admissionError.js +0 -8
  641. package/dist/v3/artifact.d.ts +0 -145
  642. package/dist/v3/artifact.js +0 -1176
  643. package/dist/v3/artifactLease.d.ts +0 -17
  644. package/dist/v3/artifactLease.js +0 -109
  645. package/dist/v3/browserRuntime.d.ts +0 -37
  646. package/dist/v3/browserRuntime.js +0 -197
  647. package/dist/v3/browserSessionRuntime.d.ts +0 -2
  648. package/dist/v3/browserSessionRuntime.js +0 -21
  649. package/dist/v3/capability.d.ts +0 -32
  650. package/dist/v3/capability.js +0 -345
  651. package/dist/v3/carrier.d.ts +0 -84
  652. package/dist/v3/carrier.js +0 -411
  653. package/dist/v3/connectionController.d.ts +0 -100
  654. package/dist/v3/connectionController.js +0 -861
  655. package/dist/v3/contract.d.ts +0 -65
  656. package/dist/v3/contract.js +0 -3
  657. package/dist/v3/controller.d.ts +0 -45
  658. package/dist/v3/controller.js +0 -316
  659. package/dist/v3/handshake.d.ts +0 -81
  660. package/dist/v3/handshake.js +0 -471
  661. package/dist/v3/jcs.d.ts +0 -6
  662. package/dist/v3/jcs.js +0 -69
  663. package/dist/v3/jsonPreflight.d.ts +0 -1
  664. package/dist/v3/jsonPreflight.js +0 -251
  665. package/dist/v3/nodeRuntime.d.ts +0 -43
  666. package/dist/v3/nodeRuntime.js +0 -373
  667. package/dist/v3/nodeSessionRuntime.d.ts +0 -2
  668. package/dist/v3/nodeSessionRuntime.js +0 -13
  669. package/dist/v3/protocol.d.ts +0 -99
  670. package/dist/v3/protocol.js +0 -674
  671. package/dist/v3/publicApi.d.ts +0 -12
  672. package/dist/v3/publicApi.js +0 -46
  673. package/dist/v3/publicSession.js +0 -281
  674. package/dist/v3/retryDisposition.d.ts +0 -16
  675. package/dist/v3/retryDisposition.js +0 -23
  676. package/dist/v3/runtimeAdapters.d.ts +0 -9
  677. package/dist/v3/runtimeAdapters.js +0 -109
  678. package/dist/v3/security.d.ts +0 -36
  679. package/dist/v3/security.js +0 -113
  680. package/dist/v3/serverAdmission.d.ts +0 -38
  681. package/dist/v3/serverAdmission.js +0 -223
  682. package/dist/v3/session.d.ts +0 -322
  683. package/dist/v3/session.js +0 -2302
  684. package/dist/v3/sessionConnector.d.ts +0 -42
  685. package/dist/v3/sessionConnector.js +0 -513
  686. package/dist/v3/streamLifetimeLedger.d.ts +0 -31
  687. package/dist/v3/streamLifetimeLedger.js +0 -131
  688. package/dist/v3/streamMetadata.js +0 -7
  689. package/dist/v3/transportConstants.d.ts +0 -56
  690. package/dist/v3/transportConstants.js +0 -59
  691. package/dist/v3/unreliableMessage.d.ts +0 -44
  692. package/dist/v3/unreliableMessage.js +0 -287
  693. package/dist/v3/webSocketCarrier.d.ts +0 -31
  694. package/dist/v3/webSocketCarrier.js +0 -370
  695. package/dist/v3/webTransportCarrier.d.ts +0 -27
  696. package/dist/v3/webTransportCarrier.js +0 -552
  697. package/dist/ws-client/binaryTransport.d.ts +0 -64
  698. package/dist/ws-client/binaryTransport.js +0 -393
  699. package/dist/yamux/byteReader.d.ts +0 -13
  700. package/dist/yamux/byteReader.js +0 -81
  701. package/dist/yamux/constants.d.ts +0 -10
  702. package/dist/yamux/constants.js +0 -14
  703. package/dist/yamux/errors.d.ts +0 -15
  704. package/dist/yamux/errors.js +0 -34
  705. package/dist/yamux/header.d.ts +0 -17
  706. package/dist/yamux/header.js +0 -26
  707. package/dist/yamux/index.d.ts +0 -6
  708. package/dist/yamux/index.js +0 -6
  709. package/dist/yamux/session.d.ts +0 -81
  710. package/dist/yamux/session.js +0 -401
  711. package/dist/yamux/stream.d.ts +0 -42
  712. package/dist/yamux/stream.js +0 -296
  713. /package/dist/{rpc/caller.js → node/sqlitePoolWorkerProgramV4.d.ts} +0 -0
  714. /package/dist/{rpc/wire.js → node/sqliteWorkerProgramV4.d.ts} +0 -0
  715. /package/dist/{v3/publicSession.d.ts → v4/admissionOffer.js} +0 -0
  716. /package/dist/{v3/streamMetadata.d.ts → v4/runtime/controllerUnaryRoute.js} +0 -0
@@ -0,0 +1,2170 @@
1
+ import { DiagnosticActivity } from "./diagnosticObservation.js";
2
+ import { initializerCallBacking } from "./initializerWorkload.js";
3
+ import { checkMaintenanceOwner } from "../responsePublication.js";
4
+ import { rpcOutputInterestCharge } from "./rpcOutputInterest.js";
5
+ import { RPCResumeDispatch, rpcResumeDispatchCharge } from "./rpcResumeDispatch.js";
6
+ import { ResumeCodec, resumeCodecCharges } from "./resumeCodec.js";
7
+ import { executionStorage, executionMode } from "./executionStorage.js";
8
+ import { byteEventSource } from "../eventSource.js";
9
+ import { eventSourceCharge } from "./rpcEventSource.js";
10
+ import { RPCStreamingExchange, rpcStreamingErrorCharge } from "./rpcStreamingExchange.js";
11
+ import { RPCStreamingDispatch, rpcStreamingDispatchCharges } from "./rpcStreamingDispatch.js";
12
+ import { RPCStreamMessages, rpcStreamMessagesCharges } from "./rpcStreamMessages.js";
13
+ import { RPCPreacceptedStreams, rpcPreacceptedStreamsCharge } from "./rpcPreacceptedStreams.js";
14
+ import { checkStreamingTarget } from "./serviceBindingConfig.js";
15
+ import { rpcCompletionCharge } from "./rpcCompletion.js";
16
+ import { NotificationExecution } from "./notifyExecution.js";
17
+ import { notificationSubscription } from "../notificationSubscription.js";
18
+ import { NotifyChannel, notifyChannelCharges } from "./notifyChannel.js";
19
+ import { NotifyPreparation, captureNotifyOptions, notifyPreparationCharges } from "./notifyPreparation.js";
20
+ import { NotificationInput, NotificationMessage, NotificationRegistration, NotificationSubscribers, NotificationAccess, captureNotificationHandler, notificationMessageCharges, notificationRegistrationCharge, notificationWorkCharge, notificationSubscribersCharge } from "./notifyDispatch.js";
21
+ import { rpcPayloadCharge } from "./rpcPayload.js";
22
+ import { timeAdd } from "./timeArithmetic.js";
23
+ import { operationTarget, operationResultLimit } from "../operationReference.js";
24
+ import { checkServiceBindingTarget, captureServiceBindingTarget } from "./serviceBindingConfig.js";
25
+ import { ExecutionManagementChannel, executionManagementCharges } from "./executionManagementChannel.js";
26
+ import { ExecutionManagementCodec, executionManagementDecoderCharge } from "./executionManagementCodec.js";
27
+ import { captureExecutionIdentity, captureVolatileExecution, executionResultReadCharge } from "./volatileExecutions.js";
28
+ import { methodDefinition, serviceDefinition } from "../serviceDefinition.js";
29
+ import { applicationGroup, applicationGroupCharge, applicationWorkClass, completionPositionCharge } from "./applicationExecutor.js";
30
+ import { byteLength } from "./cbor.js";
31
+ import { ContractQueryAccess } from "./contractQueryAccess.js";
32
+ import { contractQueryAccessCharge } from "./contractQueryAccess.js";
33
+ import { ContractQuerySession, contractQuerySessionCharges } from "./contractQuerySession.js";
34
+ import { ContractRoutes, contractRoutesCharge } from "./contractRoutes.js";
35
+ import { RPCChannelRuntime, rpcChannelCharge } from "./rpcChannel.js";
36
+ import { RPCCallCapacity, rpcCallCapacityCharge } from "./rpcCallCapacity.js";
37
+ import { RPCProtocolError } from "./rpcFragment.js";
38
+ import { RPCNetwork, rpcNetworkCharge } from "./rpcNetwork.js";
39
+ import { rpcPublisherCharge } from "./rpcPublisher.js";
40
+ import { rpcReceiverCharges } from "./rpcReceiver.js";
41
+ import { RPCUnaryDispatch, rpcUnaryDispatchCharges } from "./rpcUnaryDispatch.js";
42
+ import { RPCUnaryRegistration, captureUnaryHandler, rpcUnaryRegistrationCharge } from "./rpcUnaryRegistration.js";
43
+ import { TimeError } from "./timeArithmetic.js";
44
+ import { ServiceBinding } from "./serviceBinding.js";
45
+ import { captureServiceBinding } from "./serviceBindingConfig.js";
46
+ import { RPCUnaryExchange, rpcUnaryExchangeCharges } from "./rpcUnaryExchange.js";
47
+ import { RPCPayload } from "./rpcPayload.js";
48
+ import { RPCUnaryPreparation, captureUnaryOptions, rpcUnaryPreparationCharges, unaryResponseLimit } from "./rpcUnaryPreparation.js";
49
+ import { messageInputBytes } from "./messageCodec.js";
50
+ import { ServiceContractSnapshot, serviceContractCharge, serviceContractDecoderCharge } from "./serviceContract.js";
51
+ import { ServiceInputs, serviceInputsCharges } from "./serviceInputs.js";
52
+ import { ResourceError, ResourceVector } from "./resources.js";
53
+ import { writeRequestCharge } from "./writeRequest.js";
54
+ const managementAddListener = EventTarget.prototype.addEventListener, managementRemoveListener = EventTarget.prototype.removeEventListener;
55
+ const managementAborted = Object.getOwnPropertyDescriptor(AbortSignal.prototype, "aborted").get;
56
+ function captureExecutionDelegations(input) {
57
+ if (!Array.isArray(input) || input.length > 64)
58
+ throw new RPCProtocolError("configuration_capacity");
59
+ const keys = new Set();
60
+ return Object.freeze(input.map(entry => {
61
+ const { direction, namespace, principalAuthority, principalSubject, targetAuthority, targetSubject, query, cancel, notAfterMS } = entry;
62
+ if (direction !== "outgoing" && direction !== "incoming" || ![namespace, principalSubject, targetSubject].every(value => typeof value === "string" && /^[a-z0-9][a-z0-9._:/@-]{0,127}$/u.test(value)) ||
63
+ ![principalAuthority, targetAuthority].every(value => typeof value === "string" && /^[0-9a-f]{64}$/u.test(value) && !/^0+$/u.test(value)) ||
64
+ typeof query !== "boolean" || typeof cancel !== "boolean" || !query && !cancel || typeof notAfterMS !== "bigint" || notAfterMS < 1n || notAfterMS >= 1n << 64n)
65
+ throw new RPCProtocolError("configuration_capacity");
66
+ const key = [direction, namespace, principalAuthority, principalSubject, targetAuthority, targetSubject].join("\0");
67
+ if (keys.has(key))
68
+ throw new RPCProtocolError("configuration_capacity");
69
+ keys.add(key);
70
+ return Object.freeze({ direction, namespace, principalAuthority, principalSubject, targetAuthority, targetSubject, query, cancel, notAfterMS });
71
+ }));
72
+ }
73
+ export function captureRPCApplication(input) {
74
+ const query = input.query, typeID = query.typeID, digest = query.contractDigest;
75
+ const definitions = input.definitions, maxMethods = input.maxMethods, maxCaptureBytes = input.maxCaptureBytes, queryAcquisitions = input.queryAcquisitions ?? 4;
76
+ if (queryAcquisitions !== 2 && queryAcquisitions !== 4 || !Number.isSafeInteger(typeID) || typeID < 1 || typeID > 0xffffffff || byteLength(digest) !== 32 ||
77
+ !Array.isArray(definitions) || !Number.isSafeInteger(maxMethods) || maxMethods < 1 || maxMethods > 4096 || definitions.length > maxMethods ||
78
+ !Number.isSafeInteger(maxCaptureBytes) || maxCaptureBytes < 0 || maxCaptureBytes > 1048576)
79
+ throw new RPCProtocolError("configuration_capacity");
80
+ const executionIdentity = captureExecutionIdentity(input.executionIdentity);
81
+ const executionDelegations = captureExecutionDelegations(input.executionDelegations ?? []);
82
+ const readInput = input.resultRead;
83
+ const readType = readInput?.typeID, readDigest = readInput?.contractDigest;
84
+ if (readInput !== undefined && (!Number.isSafeInteger(readType) || readType < 1 || readType > 0xffffffff || readDigest === undefined || byteLength(readDigest) !== 32))
85
+ throw new RPCProtocolError("configuration_capacity");
86
+ const resultRead = readInput === undefined ? undefined : Object.freeze({ typeID: readType, contractDigest: new Uint8Array(readDigest) });
87
+ const localExecutionAuthority = input.localExecutionAuthority;
88
+ if (localExecutionAuthority !== undefined && (!/^[0-9a-f]{64}$/u.test(localExecutionAuthority) || /^0+$/u.test(localExecutionAuthority)))
89
+ throw new RPCProtocolError("configuration_capacity");
90
+ const targetInput = input.referenceTargets ?? [];
91
+ if (!Array.isArray(targetInput) || targetInput.length > 64)
92
+ throw new RPCProtocolError("configuration_capacity");
93
+ const referenceTargets = Object.freeze(targetInput.map(captureServiceBindingTarget));
94
+ if (new Set(referenceTargets.map(target => target.authority)).size !== referenceTargets.length)
95
+ throw new RPCProtocolError("configuration_capacity");
96
+ const serviceInput = input.executionServices ?? [], permissionInputExecution = input.executionPermissions ?? [];
97
+ if (!Array.isArray(serviceInput) || serviceInput.length > 64 || !Array.isArray(permissionInputExecution) || permissionInputExecution.length > 64)
98
+ throw new RPCProtocolError("configuration_capacity");
99
+ const executionServices = Object.freeze(serviceInput.map(captureVolatileExecution));
100
+ const executionPermissions = Object.freeze(permissionInputExecution.map(({ namespace, query, cancel }) => {
101
+ if (!/^[a-z0-9][a-z0-9._:/@-]{0,127}$/u.test(namespace) || typeof query !== "boolean" || typeof cancel !== "boolean")
102
+ throw new RPCProtocolError("configuration_capacity");
103
+ return Object.freeze({ namespace, query, cancel });
104
+ }));
105
+ if (executionServices.length > 64 || executionPermissions.length > 64 || new Set(executionPermissions.map(entry => entry.namespace)).size !== executionPermissions.length)
106
+ throw new RPCProtocolError("configuration_capacity");
107
+ const handlerInput = input.unaryHandlers ?? [];
108
+ if (!Array.isArray(handlerInput) || handlerInput.length > maxMethods)
109
+ throw new RPCProtocolError("configuration_capacity");
110
+ const declared = definitions.flatMap(definition => { const service = serviceDefinition(definition); return service.entries.map(entry => ({ namespace: service.namespace, method: entry.method })); });
111
+ const keys = new Set();
112
+ const unaryHandlers = Object.freeze(handlerInput.map(entry => {
113
+ const { namespace, method, contract, handler, options, offer, maximumOfferWindowMS } = entry, facts = methodDefinition(method);
114
+ const key = `${namespace}\0${facts.typeID}`;
115
+ if (keys.has(key) || typeof handler !== "function" || !declared.some(value => value.namespace === namespace && value.method === method) ||
116
+ facts.shape !== "unary")
117
+ throw new RPCProtocolError("configuration_capacity");
118
+ keys.add(key);
119
+ contract.checkMethod(namespace, facts);
120
+ if (facts.restartFlush)
121
+ checkMaintenanceOwner(input.maintenanceOwner);
122
+ const execution = entry.execution === undefined ? undefined : captureVolatileExecution(entry.execution);
123
+ if (facts.semantics === "execution") {
124
+ if (execution === undefined || executionIdentity === undefined || offer === undefined || maximumOfferWindowMS === undefined ||
125
+ execution.namespace !== namespace || !execution.callerAuthorities.includes(executionIdentity.authority) || contract.optionalUint(13) !== executionMode(execution) ||
126
+ (contract.optionalUint(19) !== 0n && contract.optionalUint(19) !== 1n) || facts.checkpointFormat !== undefined && executionMode(execution) !== 1n)
127
+ throw new RPCProtocolError("configuration_capacity");
128
+ offer.copyEncoded(contract, maximumOfferWindowMS, new Uint8Array(256));
129
+ executionStorage(execution)?.checkContract(contract, offer, maximumOfferWindowMS);
130
+ }
131
+ else if (execution !== undefined || offer !== undefined || maximumOfferWindowMS !== undefined)
132
+ throw new RPCProtocolError("configuration_capacity");
133
+ return Object.freeze({ namespace, method, contract, handler, options: captureUnaryHandler(options),
134
+ ...(execution === undefined ? {} : { execution, offer: offer, maximumOfferWindowMS: maximumOfferWindowMS }) });
135
+ }));
136
+ const streamInput = input.streamingHandlers ?? [], streamKinds = new Set();
137
+ if (!Array.isArray(streamInput) || streamInput.length > maxMethods)
138
+ throw new RPCProtocolError("configuration_capacity");
139
+ const streamingHandlers = Object.freeze(streamInput.map(({ namespace, method, kind, metadata = new Uint8Array(), contract, handler, options, execution: executionInput, offer, maximumOfferWindowMS }) => {
140
+ const facts = methodDefinition(method), key = `${namespace}\0${facts.typeID}`;
141
+ checkStreamingTarget(kind, metadata);
142
+ if (keys.has(key) || streamKinds.has(kind) || facts.shape !== "server_streaming" || facts.restartFlush ||
143
+ typeof handler !== "function" && byteEventSource(handler) === undefined || !declared.some(entry => entry.namespace === namespace && entry.method === method))
144
+ throw new RPCProtocolError("configuration_capacity");
145
+ contract.checkMethod(namespace, facts);
146
+ keys.add(key);
147
+ streamKinds.add(kind);
148
+ const execution = executionInput === undefined ? undefined : captureVolatileExecution(executionInput);
149
+ if (facts.semantics === "execution") {
150
+ if (execution === undefined || executionIdentity === undefined || offer === undefined || maximumOfferWindowMS === undefined ||
151
+ execution.namespace !== namespace || !execution.callerAuthorities.includes(executionIdentity.authority) || contract.optionalUint(13) !== executionMode(execution) ||
152
+ (contract.optionalUint(19) !== 0n && contract.optionalUint(19) !== 1n) || facts.checkpointFormat !== undefined && executionMode(execution) !== 1n ||
153
+ contract.streamContentMode() !== "none" && (facts.streamContent === undefined || executionMode(execution) !== 1n))
154
+ throw new RPCProtocolError("configuration_capacity");
155
+ offer.copyEncoded(contract, maximumOfferWindowMS, new Uint8Array(256));
156
+ executionStorage(execution)?.checkContract(contract, offer, maximumOfferWindowMS);
157
+ }
158
+ else if (execution !== undefined || offer !== undefined || maximumOfferWindowMS !== undefined)
159
+ throw new RPCProtocolError("configuration_capacity");
160
+ return Object.freeze({ namespace, method, kind, metadata: new Uint8Array(metadata), contract, handler, options: captureUnaryHandler(options),
161
+ ...(execution === undefined ? {} : { execution, offer: offer, maximumOfferWindowMS: maximumOfferWindowMS }) });
162
+ }));
163
+ for (const source of streamingHandlers) {
164
+ const definition = methodDefinition(source.method).streamContent;
165
+ if (definition !== undefined && !unaryHandlers.some(reader => reader.namespace === source.namespace &&
166
+ methodDefinition(reader.method).typeID === definition.readTypeID && reader.execution === source.execution))
167
+ throw new RPCProtocolError("configuration_capacity");
168
+ }
169
+ const notifyInput = input.notificationHandlers ?? [];
170
+ // A local subscription selects an exact MethodDefinition. Reusing that
171
+ // selector in another incoming namespace would make its dispatch ambiguous.
172
+ const notificationSelectors = new Set();
173
+ if (!Array.isArray(notifyInput) || notifyInput.length > Math.min(maxMethods, 128))
174
+ throw new RPCProtocolError("configuration_capacity");
175
+ const notificationHandlers = Object.freeze(notifyInput.map(({ namespace, method, contract, handler, options, execution: executionInput, offer, maximumOfferWindowMS }) => {
176
+ const facts = methodDefinition(method), key = `${namespace}\0${facts.typeID}`;
177
+ if (keys.has(key) || notificationSelectors.has(method) || typeof handler !== "function" || facts.shape !== "notify" ||
178
+ !declared.some(value => value.namespace === namespace && value.method === method))
179
+ throw new RPCProtocolError("configuration_capacity");
180
+ keys.add(key);
181
+ notificationSelectors.add(method);
182
+ contract.checkMethod(namespace, facts);
183
+ const execution = executionInput === undefined ? undefined : captureVolatileExecution(executionInput);
184
+ if (facts.semantics === "execution") {
185
+ if (execution === undefined || executionIdentity === undefined || offer === undefined || maximumOfferWindowMS === undefined ||
186
+ execution.namespace !== namespace || !execution.callerAuthorities.includes(executionIdentity.authority) || contract.optionalUint(13) !== executionMode(execution) ||
187
+ (contract.optionalUint(19) !== 0n && contract.optionalUint(19) !== 1n))
188
+ throw new RPCProtocolError("configuration_capacity");
189
+ offer.copyEncoded(contract, maximumOfferWindowMS, new Uint8Array(256));
190
+ executionStorage(execution)?.checkContract(contract, offer, maximumOfferWindowMS);
191
+ }
192
+ else if (execution !== undefined || offer !== undefined || maximumOfferWindowMS !== undefined)
193
+ throw new RPCProtocolError("configuration_capacity");
194
+ return Object.freeze({ namespace, method, contract, handler, options: captureNotificationHandler(options),
195
+ ...(execution === undefined ? {} : { execution, offer: offer, maximumOfferWindowMS: maximumOfferWindowMS }) });
196
+ }));
197
+ const notificationMethodInput = input.notificationMethods ?? [];
198
+ if (!Array.isArray(notificationMethodInput) || notificationMethodInput.length > maxMethods)
199
+ throw new RPCProtocolError("configuration_capacity");
200
+ const notificationMethods = Object.freeze(notificationMethodInput.map(({ namespace, method, contract, permission }) => {
201
+ const facts = methodDefinition(method), key = `${namespace}\0${facts.typeID}`;
202
+ if (keys.has(key) || notificationSelectors.has(method) || facts.shape !== "notify" || facts.semantics !== "observation" || !["allowed", "denied", "unavailable"].includes(permission) ||
203
+ !declared.some(value => value.namespace === namespace && value.method === method))
204
+ throw new RPCProtocolError("configuration_capacity");
205
+ keys.add(key);
206
+ notificationSelectors.add(method);
207
+ if (contract instanceof Uint8Array) {
208
+ if (byteLength(contract) < 1 || byteLength(contract) > 8192)
209
+ throw new RPCProtocolError("configuration_capacity");
210
+ return Object.freeze({ namespace, method, contract: new Uint8Array(contract), permission });
211
+ }
212
+ contract.checkMethod(namespace, facts);
213
+ return Object.freeze({ namespace, method, contract, permission });
214
+ }));
215
+ const permissionInput = input.queryPermissions ?? [];
216
+ if (!Array.isArray(permissionInput) || permissionInput.length > maxMethods)
217
+ throw new RPCProtocolError("configuration_capacity");
218
+ const permissionKeys = new Set();
219
+ const queryPermissions = Object.freeze(permissionInput.map(entry => {
220
+ const { namespace, method, permission } = entry, facts = methodDefinition(method), key = `${namespace}\0${facts.typeID}`;
221
+ if (permissionKeys.has(key) || !declared.some(value => value.namespace === namespace && value.method === method) ||
222
+ !["unavailable", "denied", "allowed"].includes(permission))
223
+ throw new RPCProtocolError("configuration_capacity");
224
+ permissionKeys.add(key);
225
+ return Object.freeze({ namespace, method, permission });
226
+ }));
227
+ const histories = new Map();
228
+ for (const entry of [...executionServices, ...notificationHandlers.flatMap(entry => entry.execution === undefined ? [] : [entry.execution]), ...unaryHandlers.flatMap(entry => entry.execution === undefined ? [] : [entry.execution]), ...streamingHandlers.flatMap(entry => entry.execution === undefined ? [] : [entry.execution])]) {
229
+ const encoded = JSON.stringify(entry, (_key, value) => typeof value === "bigint" ? value.toString() : value);
230
+ const previous = histories.get(entry.namespace);
231
+ if (previous !== undefined && previous !== encoded)
232
+ throw new RPCProtocolError("configuration_capacity");
233
+ histories.set(entry.namespace, encoded);
234
+ }
235
+ const captured = Object.freeze({ ...(input.maintenanceOwner === undefined ? {} : { maintenanceOwner: input.maintenanceOwner }), query: Object.freeze({ typeID, contractDigest: new Uint8Array(digest) }),
236
+ ...(resultRead === undefined ? {} : { resultRead: Object.freeze(resultRead) }),
237
+ executionDelegations, referenceTargets, definitions: Object.freeze([...definitions]), maxMethods, maxCaptureBytes, queryAcquisitions, unaryHandlers, streamingHandlers, notificationHandlers, notificationMethods, queryPermissions, executionServices, executionPermissions, ...(localExecutionAuthority === undefined ? {} : { localExecutionAuthority }), ...(executionIdentity === undefined ? {} : { executionIdentity }) });
238
+ // This also verifies unique trusted namespace/type identities without
239
+ // executing any application encoder or authorization callback.
240
+ contractRoutesCharge(captured.definitions, captured.maxMethods, 1n);
241
+ return captured;
242
+ }
243
+ export function rpcApplicationPlan(config, profile, maxGeneral, runtimeBytes) {
244
+ const referenceBytes = (config.referenceTargets ?? []).reduce((sum, target) => sum + 2048n + BigInt(target.peers.length) * 1024n, 0n);
245
+ const charges = [new ResourceVector([8192n + referenceBytes + BigInt(config.executionDelegations?.length ?? 0) * 1536n + 65n * runtimeBytes, 0n, 0n, 84n, 0n, 0n, 0n, 0n, 0n, 0n, 0n]),
246
+ applicationGroupCharge(runtimeBytes), rpcNetworkCharge({ profile, maxGeneral, query: config.query, runtimeBytes, ...(config.resultRead === undefined ? {} : { resultRead: config.resultRead }) }),
247
+ contractRoutesCharge(config.definitions, config.maxMethods, runtimeBytes), contractQueryAccessCharge(config.definitions, config.maxMethods, runtimeBytes),
248
+ rpcCallCapacityCharge(maxGeneral, runtimeBytes), completionPositionCharge(runtimeBytes)];
249
+ const handlers = charges.length;
250
+ for (const entry of config.unaryHandlers ?? []) {
251
+ if (entry.options.maxConcurrentCalls > maxGeneral)
252
+ throw new RPCProtocolError("configuration_capacity");
253
+ charges.push(rpcUnaryRegistrationCharge(entry.options, runtimeBytes));
254
+ }
255
+ const streamingHandlers = charges.length;
256
+ for (const entry of config.streamingHandlers ?? []) {
257
+ const source = byteEventSource(entry.handler);
258
+ if (source !== undefined)
259
+ eventSourceCharge(source, runtimeBytes);
260
+ if (entry.options.maxConcurrentCalls > maxGeneral)
261
+ throw new RPCProtocolError("configuration_capacity");
262
+ charges.push(rpcUnaryRegistrationCharge(entry.options, runtimeBytes).add(new ResourceVector([8192n, 0n, 0n, 0n, 0n, 0n, 0n, 0n, 0n, 0n, 0n])));
263
+ }
264
+ const notificationHandlers = charges.length;
265
+ for (const entry of config.notificationHandlers ?? [])
266
+ charges.push(notificationRegistrationCharge(entry.options, runtimeBytes));
267
+ const notificationMethods = charges.length;
268
+ for (const entry of config.notificationMethods ?? [])
269
+ if (entry.contract instanceof Uint8Array)
270
+ charges.push(serviceContractCharge(runtimeBytes), serviceContractDecoderCharge(runtimeBytes));
271
+ const notificationSubscribers = charges.length;
272
+ charges.push(notificationSubscribersCharge(runtimeBytes));
273
+ const inputs = charges.length;
274
+ charges.push(...serviceInputsCharges(maxGeneral, runtimeBytes));
275
+ const queries = charges.length;
276
+ charges.push(...contractQuerySessionCharges(runtimeBytes));
277
+ const channel = charges.length;
278
+ const channelCosts = [rpcChannelCharge(runtimeBytes),
279
+ new ResourceVector([50304n + runtimeBytes, 0n, 0n, 5n, 6n, 6n, 4n, 0n, 0n, 1n, 0n]), applicationGroupCharge(runtimeBytes),
280
+ ...rpcReceiverCharges(runtimeBytes), rpcPublisherCharge(runtimeBytes), writeRequestCharge(16384, runtimeBytes)];
281
+ const channelWidth = channelCosts.length;
282
+ for (let position = 0; position < 8; position++)
283
+ charges.push(...channelCosts);
284
+ const publication = channel + channelWidth - 1, management = charges.length;
285
+ if (profile === "execution")
286
+ charges.push(...executionManagementCharges(runtimeBytes));
287
+ const resultRead = charges.length;
288
+ if (config.resultRead !== undefined)
289
+ charges.push(executionManagementDecoderCharge(runtimeBytes), new ResourceVector([4096n + runtimeBytes, 0n, 0n, 4n, 0n, 0n, 0n, 0n, 0n, 0n, 0n]));
290
+ const notify = charges.length;
291
+ charges.push(...notifyChannelCharges(runtimeBytes), ...notifyChannelCharges(runtimeBytes));
292
+ return Object.freeze({ charges: Object.freeze(charges), handlers, streamingHandlers, notificationHandlers, notificationMethods, notificationSubscribers, notify, inputs, queries, channel, channelWidth, publication, management, resultRead });
293
+ }
294
+ /** Original pre-spend Session RPC admission. All fixed query/network/input and
295
+ * eight-channel positions and execution-service attachments are acquired before
296
+ * irreversible authorization consumption. Authentication and physical Stream
297
+ * binding remain gates in the original Session; this owner cannot assert READY. */
298
+ export class RPCApplicationAdmission {
299
+ #profile;
300
+ #general;
301
+ #deadline;
302
+ #runtimeBytes;
303
+ #reference;
304
+ #group;
305
+ #channelGroups = [];
306
+ #network;
307
+ #calls;
308
+ #completion;
309
+ #routes;
310
+ #access;
311
+ #inputs;
312
+ #queries;
313
+ #acquisitions;
314
+ #host;
315
+ #cleanup;
316
+ #authentication;
317
+ #executionIdentity;
318
+ #managementLease;
319
+ #localExecutionAuthority;
320
+ #referenceTargets = [];
321
+ #executionDelegations = [];
322
+ #executionPermissions;
323
+ #histories = new Map();
324
+ #management;
325
+ #managementGroup;
326
+ #managementPosition;
327
+ #managementRefs = [];
328
+ #managementPositions = [];
329
+ #managementChanged;
330
+ #managementWaiters = new Set();
331
+ #managementUnavailable = false;
332
+ #managementBusinessAvailable;
333
+ #resultReadCodec;
334
+ #resultReadReference;
335
+ #resultReadBuffer = new Uint8Array();
336
+ #resultReadBusy = false;
337
+ #subscribers;
338
+ #notificationAccess = new Map();
339
+ #notificationBusinesses = new Map();
340
+ #notifyPreparations = new Set();
341
+ #notifyChannels = [undefined, undefined];
342
+ #notifyRefs = [[], []];
343
+ #notifyPositions = [];
344
+ #notifyGroups = [];
345
+ #maxCaptureBytes;
346
+ #unary = new Set();
347
+ #inbound = new Set();
348
+ #serviceClients = new Set();
349
+ #serviceGroup = Object.freeze(Object.create(null));
350
+ #inboundAbort = new AbortController();
351
+ #nextInbound = 0n;
352
+ #nextRegistration = 0n;
353
+ #preparations = new Set();
354
+ #streamOpener;
355
+ #session;
356
+ #resumeDispatches = new Set();
357
+ #preaccepted;
358
+ #initialStreams;
359
+ #streamHandlers = new Map();
360
+ #streaming = new Set();
361
+ #streamDispatches = new Set();
362
+ #nextPreparation = 0n;
363
+ #random;
364
+ #bindings;
365
+ #channels = Array.from({ length: 8 });
366
+ #channelPositions = [];
367
+ #channelsChanged;
368
+ #checkpointPolicy;
369
+ #claimed = false;
370
+ #bound = false;
371
+ #closed = false;
372
+ #closing = false;
373
+ #draining = false;
374
+ #peerDraining = false;
375
+ #dispatching = new Set();
376
+ #collecting = false;
377
+ #observer;
378
+ #cleaned;
379
+ #turns = new Map();
380
+ #maintenanceOwner;
381
+ constructor(config, profile, maxGeneral, root, accounts, sendAccounts, owner, clock, deadline, delivery, runtimeBytes, references, acquisitions, random, bindings, executionOwner, notificationAccounts, channelSendAccounts, prepaidCalls, prepaidServices, initialStreams, diagnostics) {
382
+ const plan = rpcApplicationPlan(config, profile, maxGeneral, runtimeBytes);
383
+ this.#maxCaptureBytes = config.maxCaptureBytes;
384
+ this.#maintenanceOwner = config.maintenanceOwner;
385
+ if (config.maintenanceOwner !== undefined)
386
+ checkMaintenanceOwner(config.maintenanceOwner, references[0]);
387
+ this.#executionIdentity = config.executionIdentity;
388
+ this.#localExecutionAuthority = config.localExecutionAuthority;
389
+ this.#referenceTargets = config.referenceTargets ?? [];
390
+ this.#executionDelegations = config.executionDelegations ?? [];
391
+ this.#executionPermissions = config.executionPermissions ?? [];
392
+ if (profile !== "execution" && ((config.executionServices?.length ?? 0) !== 0 || this.#executionPermissions.length !== 0 || this.#executionDelegations.length !== 0 || config.localExecutionAuthority !== undefined || config.executionIdentity !== undefined))
393
+ throw new RPCProtocolError("configuration_capacity");
394
+ if (references.length !== plan.charges.length || channelSendAccounts.length !== 8 || !deadline.belongsTo(clock) || !references.every(reference => references[0].sameEnvironment(reference)) ||
395
+ !acquisitions.sameEnvironment(references[0], clock))
396
+ throw new RPCProtocolError("rpc_owner");
397
+ this.#profile = profile;
398
+ this.#general = maxGeneral;
399
+ this.#deadline = deadline;
400
+ this.#runtimeBytes = runtimeBytes;
401
+ this.#acquisitions = acquisitions;
402
+ this.#random = random;
403
+ this.#bindings = bindings;
404
+ this.#host = { root, diagnostics, accounts: Object.freeze([...accounts]), sendAccounts: Object.freeze([...sendAccounts]), owner: Object.freeze({ ...owner }), clock, delivery, notificationAccounts,
405
+ channelSendAccounts: Object.freeze(channelSendAccounts.map(scopes => Object.freeze([...scopes]))) };
406
+ this.#reference = references[0].take(plan.charges[0]);
407
+ this.#initialStreams = initialStreams;
408
+ try {
409
+ if (prepaidServices !== undefined && (!prepaidServices.group.sameEnvironment(this.#reference) ||
410
+ prepaidServices.completion.group !== prepaidServices.group || prepaidServices.queries.group !== prepaidServices.group ||
411
+ prepaidServices.queries.direction !== 0 || prepaidServices.notificationGroups.length !== 2 ||
412
+ prepaidServices.channelGroups.length !== 8 || !prepaidServices.channelGroups.every(group => group.sameEnvironment(this.#reference)) ||
413
+ !prepaidServices.notificationGroups.every(group => group.sameEnvironment(this.#reference))))
414
+ throw new RPCProtocolError("rpc_owner");
415
+ this.#group = prepaidServices?.group ?? applicationGroup(root, accounts, { ...owner, kind: "rpc_application" }, runtimeBytes, true, references[1]);
416
+ if (profile === "execution")
417
+ this.#group.enableManagement();
418
+ this.#completion = prepaidServices?.completion ?? this.#group.protectCompletion(runtimeBytes, references[6]);
419
+ if (prepaidCalls !== undefined && (prepaidCalls.limit !== maxGeneral || !prepaidCalls.sameEnvironment(this.#reference)))
420
+ throw new RPCProtocolError("rpc_call_owner");
421
+ this.#calls = prepaidCalls ?? new RPCCallCapacity(maxGeneral, runtimeBytes, references[5]);
422
+ this.#network = new RPCNetwork({ profile, maxGeneral, query: config.query, runtimeBytes, ...(config.resultRead === undefined ? {} : { resultRead: config.resultRead }) }, references[2], this.#calls);
423
+ this.#routes = new ContractRoutes(config.definitions, config.maxMethods, runtimeBytes, references[3], clock);
424
+ for (const configEntry of config.executionServices ?? [])
425
+ this.#histories.set(configEntry.namespace, executionOwner(configEntry));
426
+ for (const [index, entry] of (config.unaryHandlers ?? []).entries()) {
427
+ if (entry.execution !== undefined && profile !== "execution")
428
+ throw new RPCProtocolError("configuration_capacity");
429
+ const history = entry.execution === undefined ? undefined : executionOwner(entry.execution);
430
+ if (history !== undefined)
431
+ this.#histories.set(entry.namespace, history);
432
+ const registration = new RPCUnaryRegistration(entry.method, entry.handler, entry.options, runtimeBytes, references[plan.handlers + index], history);
433
+ try {
434
+ this.#routes.install(entry.namespace, entry.method, [entry.contract]);
435
+ this.#routes.installHandler(entry.namespace, entry.method, registration);
436
+ const digest = new Uint8Array(32);
437
+ entry.contract.copyDigest(digest);
438
+ try {
439
+ this.#routes.advertise(entry.namespace, entry.method, digest, entry.offer, entry.maximumOfferWindowMS);
440
+ }
441
+ finally {
442
+ digest.fill(0);
443
+ }
444
+ }
445
+ catch (error) {
446
+ registration.close();
447
+ throw error;
448
+ }
449
+ }
450
+ for (const [index, entry] of (config.streamingHandlers ?? []).entries()) {
451
+ if (entry.execution !== undefined && profile !== "execution")
452
+ throw new RPCProtocolError("configuration_capacity");
453
+ const history = entry.execution === undefined ? undefined : executionOwner(entry.execution);
454
+ if (history !== undefined)
455
+ this.#histories.set(entry.namespace, history);
456
+ const registration = new RPCUnaryRegistration(entry.method, entry.handler, entry.options, runtimeBytes, references[plan.streamingHandlers + index], history, "server_streaming");
457
+ try {
458
+ this.#routes.install(entry.namespace, entry.method, [entry.contract]);
459
+ this.#routes.installStreamingHandler(entry.namespace, entry.method, registration);
460
+ const digest = new Uint8Array(32);
461
+ entry.contract.copyDigest(digest);
462
+ try {
463
+ this.#routes.advertise(entry.namespace, entry.method, digest, entry.offer, entry.maximumOfferWindowMS);
464
+ }
465
+ finally {
466
+ digest.fill(0);
467
+ }
468
+ this.#streamHandlers.set(entry.kind, entry);
469
+ }
470
+ catch (error) {
471
+ registration.close();
472
+ throw error;
473
+ }
474
+ }
475
+ this.#subscribers = new NotificationSubscribers(root, accounts, owner, clock, runtimeBytes, references[plan.notificationSubscribers]);
476
+ let notificationContractIndex = plan.notificationMethods;
477
+ for (const entry of config.notificationMethods ?? []) {
478
+ const snapshot = entry.contract instanceof Uint8Array
479
+ ? new ServiceContractSnapshot(entry.contract, runtimeBytes, references[notificationContractIndex++], references[notificationContractIndex++]) : entry.contract;
480
+ try {
481
+ this.#routes.install(entry.namespace, entry.method, [snapshot]);
482
+ const digest = new Uint8Array(32);
483
+ snapshot.copyDigest(digest);
484
+ try {
485
+ this.#routes.advertise(entry.namespace, entry.method, digest);
486
+ }
487
+ finally {
488
+ digest.fill(0);
489
+ }
490
+ this.#notificationAccess.set(entry.method, new NotificationAccess(entry.permission));
491
+ }
492
+ finally {
493
+ if (entry.contract instanceof Uint8Array)
494
+ snapshot.release();
495
+ }
496
+ }
497
+ for (const [index, entry] of (config.notificationHandlers ?? []).entries()) {
498
+ const access = new NotificationAccess("allowed");
499
+ this.#notificationAccess.set(entry.method, access);
500
+ const history = entry.execution === undefined ? undefined : executionOwner(entry.execution);
501
+ if (history !== undefined) {
502
+ if (profile !== "execution")
503
+ throw new RPCProtocolError("configuration_capacity");
504
+ this.#histories.set(entry.namespace, history);
505
+ }
506
+ const registration = new NotificationRegistration(entry.handler, { ...captureNotificationHandler(entry.options), pendingPolicy: "drop_newest" }, access, runtimeBytes, references[plan.notificationHandlers + index], {
507
+ clock, reserve: charge => root.reserve({ accounts, owner: { ...owner, kind: "notification_business_wait" }, charge }), released: () => undefined,
508
+ });
509
+ try {
510
+ this.#notificationBusinesses.set(entry.method, registration);
511
+ this.#routes.install(entry.namespace, entry.method, [entry.contract]);
512
+ if (history !== undefined)
513
+ this.#routes.installNotificationHandler(entry.namespace, entry.method, registration);
514
+ const digest = new Uint8Array(32);
515
+ entry.contract.copyDigest(digest);
516
+ try {
517
+ this.#routes.advertise(entry.namespace, entry.method, digest, entry.offer, entry.maximumOfferWindowMS);
518
+ }
519
+ finally {
520
+ digest.fill(0);
521
+ }
522
+ }
523
+ catch (error) {
524
+ registration.close();
525
+ throw error;
526
+ }
527
+ }
528
+ const notifyCosts = notifyChannelCharges(runtimeBytes);
529
+ for (let position = 0; position < 2; position++) {
530
+ const refs = references.slice(plan.notify + position * notifyCosts.length, plan.notify + (position + 1) * notifyCosts.length);
531
+ this.#notifyGroups.push(prepaidServices?.notificationGroups[position] ?? applicationGroup(root, accounts, { ...owner, kind: `notify_channel_${position}` }, runtimeBytes, false, refs[2]));
532
+ this.#notifyPositions.push(root.protect(refs[5], notifyCosts[5]));
533
+ for (const index of [0, 1, 3, 4])
534
+ this.#notifyRefs[position][index] = refs[index].take(notifyCosts[index]);
535
+ }
536
+ this.#access = new ContractQueryAccess(config.definitions, config.maxMethods, delivery, runtimeBytes, references[4]);
537
+ for (const entry of config.queryPermissions ?? [])
538
+ this.#access.set(entry.namespace, methodDefinition(entry.method).typeID, entry.permission);
539
+ this.#inputs = new ServiceInputs(this.#network, this.#routes, { root, accounts, owner, deadline, maxCaptureBytes: config.maxCaptureBytes, runtimeBytes }, references.slice(plan.inputs, plan.queries));
540
+ this.#queries = new ContractQuerySession(this.#network, this.#inputs, this.#routes, this.#access, this.#group, root, delivery, deadline, runtimeBytes, references.slice(plan.queries, plan.channel), prepaidServices?.queries, prepaidServices?.outgoing, prepaidServices?.queryResponses, diagnostics);
541
+ for (let position = 0; position < 8; position++) {
542
+ const start = plan.channel + position * plan.channelWidth, positions = [];
543
+ this.#channelPositions.push(positions);
544
+ this.#channelGroups.push(prepaidServices?.channelGroups[position] ?? applicationGroup(root, accounts, { ...owner, kind: `rpc_channel_${position}` }, runtimeBytes, true, references[start + 2]));
545
+ for (let part = 0; part < plan.channelWidth; part++)
546
+ if (part !== 2)
547
+ positions[part] = root.protect(references[start + part], plan.charges[start + part]);
548
+ }
549
+ if (profile === "execution") {
550
+ const costs = executionManagementCharges(runtimeBytes), refs = references.slice(plan.management, plan.resultRead);
551
+ this.#managementPosition = root.protect(refs[6], costs[6]);
552
+ for (let i = 0; i < 6; i++)
553
+ this.#managementPositions.push(root.protect(refs[i], costs[i]));
554
+ }
555
+ if (config.resultRead !== undefined) {
556
+ this.#resultReadReference = references[plan.resultRead + 1].take(plan.charges[plan.resultRead + 1]);
557
+ this.#resultReadCodec = new ExecutionManagementCodec(runtimeBytes, references[plan.resultRead]);
558
+ this.#resultReadBuffer = new Uint8Array(1024);
559
+ }
560
+ this.#observer = root.observeAvailability(this.#reference, () => { this.#collect(); if (!this.#closed)
561
+ this.#managementChanged?.(); });
562
+ Object.freeze(this);
563
+ }
564
+ catch (error) {
565
+ this.close();
566
+ throw error;
567
+ }
568
+ }
569
+ #check() { if (this.#closed)
570
+ throw new RPCProtocolError("rpc_closed"); this.#reference.check(); }
571
+ #applicationDraining() { return this.#draining || this.#peerDraining; }
572
+ /** Once-only transfer to the actual authenticated Session assembly. */
573
+ claim(reference, profile, maxGeneral, deadline, cleanup, authentication, checkpointPolicy, session, managementBusinessAvailable) {
574
+ this.#check();
575
+ if (this.#claimed || profile !== this.#profile || maxGeneral !== this.#general || deadline !== this.#deadline ||
576
+ !this.#reference.sameEnvironment(reference))
577
+ throw new RPCProtocolError("rpc_owner");
578
+ if (this.#executionIdentity !== undefined && (authentication?.peerSubject !== this.#executionIdentity.subject ||
579
+ authentication.peerIdentityDigest !== this.#executionIdentity.identityDigest))
580
+ throw new RPCProtocolError("permission_denied");
581
+ this.#claimed = true;
582
+ this.#cleanup = cleanup;
583
+ this.#checkpointPolicy = checkpointPolicy;
584
+ this.#session = session;
585
+ this.#managementBusinessAvailable = managementBusinessAvailable;
586
+ this.#authentication = authentication === undefined ? undefined : Object.freeze({ ...authentication });
587
+ if (profile === "execution")
588
+ this.#managementLease = this.#host.delivery.retain(this.#reference, () => this.close());
589
+ }
590
+ /** Called only after the real fixed-scope prefix is bound. This never sends
591
+ * another OPEN and never creates a channel for each service or method. */
592
+ bindBootstrap(stream) {
593
+ this.#check();
594
+ if (!this.#claimed || this.#bound)
595
+ throw new RPCProtocolError("rpc_owner");
596
+ this.#bound = true;
597
+ try {
598
+ this.bindChannel(stream, 0);
599
+ }
600
+ catch (error) {
601
+ this.#bound = false;
602
+ throw error;
603
+ }
604
+ }
605
+ onChannelsChange(changed) {
606
+ this.#check();
607
+ if (this.#channelsChanged !== undefined)
608
+ throw new RPCProtocolError("rpc_owner");
609
+ this.#channelsChanged = changed;
610
+ }
611
+ channelReady(position) { return !this.#closed && this.#channels[position]?.ready() === true; }
612
+ channelGracefullyEnded(position) { return this.#channels[position]?.gracefullyEnded() === true; }
613
+ channelsReady() { return !this.#closed && this.#channels.some(channel => channel?.ready()); }
614
+ channelReusable(position) {
615
+ return !this.#closed && !this.#draining && Number.isSafeInteger(position) && position >= 0 && position < 8 &&
616
+ this.#channels[position]?.cleanupComplete() !== false && this.#channelPositions[position].every(slot => slot.available());
617
+ }
618
+ bindChannel(stream, position) {
619
+ this.#check();
620
+ if (!this.#claimed || !this.channelReusable(position))
621
+ throw new RPCProtocolError("rpc_channel_owner");
622
+ const slots = this.#channelPositions[position], refs = [];
623
+ try {
624
+ for (let part = 0; part < slots.length - 1; part++)
625
+ if (part !== 2)
626
+ refs[part] = slots[part].checkout();
627
+ const channel = new RPCChannelRuntime(stream, this.#network, this.#inputs, this.#runtimeBytes, { channel: refs[0], adapter: refs[1], application: this.#channelGroups[position], receiver: refs.slice(3, 8),
628
+ publisher: refs[8], publication: slots[9], reusable: true });
629
+ this.#channels[position] = channel;
630
+ channel.onChange(() => { this.#channelsChanged?.(); this.#collect(); });
631
+ try {
632
+ channel.start();
633
+ if (this.#peerDraining)
634
+ channel.drain();
635
+ this.#dispatching.add(channel);
636
+ void this.#dispatch(channel);
637
+ this.#channelsChanged?.();
638
+ }
639
+ catch (error) {
640
+ this.#dispatching.delete(channel);
641
+ channel.close();
642
+ throw error;
643
+ }
644
+ }
645
+ finally {
646
+ for (const reference of refs)
647
+ reference?.release();
648
+ }
649
+ }
650
+ #selectChannel(workClass = "short") {
651
+ this.#check();
652
+ let selected, preferred = false, load = Number.POSITIVE_INFINITY;
653
+ for (const [position, channel] of this.#channels.entries()) {
654
+ if (channel?.requestReady() !== true)
655
+ continue;
656
+ const matching = (position % 4 >= 2) === (workClass === "resident"), current = channel.requestLoad();
657
+ if (selected === undefined || matching && !preferred || matching === preferred && current < load) {
658
+ selected = channel;
659
+ preferred = matching;
660
+ load = current;
661
+ }
662
+ }
663
+ if (selected === undefined)
664
+ throw new RPCProtocolError("not_ready");
665
+ return selected;
666
+ }
667
+ #sendAccounts(channel) {
668
+ const position = this.#channels.indexOf(channel);
669
+ if (position < 0)
670
+ throw new RPCProtocolError("rpc_channel_owner");
671
+ return this.#host.channelSendAccounts[position];
672
+ }
673
+ bindNotify(stream, position) {
674
+ this.#check();
675
+ if (this.#notifyChannels[position] !== undefined || this.#draining)
676
+ throw new RPCProtocolError("notify_unavailable");
677
+ const refs = this.#notifyRefs[position];
678
+ try {
679
+ const channel = new NotifyChannel(stream, this.#runtimeBytes, refs, this.#notifyGroups[position], this.#notifyPositions[position], header => this.#acceptNotification(header), () => this.#collect());
680
+ this.#notifyChannels[position] = channel;
681
+ channel.start();
682
+ if (this.#peerDraining)
683
+ channel.drain();
684
+ }
685
+ finally {
686
+ for (const ref of refs)
687
+ ref?.release();
688
+ refs.length = 0;
689
+ }
690
+ }
691
+ notifyReady() { return !this.#closed && this.#notifyChannels.some(channel => channel?.ready()); }
692
+ subscribeNotification(method, handler, options) {
693
+ return notificationSubscription(this.subscribeNotificationOwner(method, handler, options));
694
+ }
695
+ subscribeNotificationOwner(method, handler, options, scheduler) {
696
+ this.#check();
697
+ if (this.#applicationDraining() || this.#authentication === undefined)
698
+ throw new RPCProtocolError("source_unavailable");
699
+ const access = this.#notificationAccess.get(method), definition = methodDefinition(method);
700
+ if (access === undefined || definition.shape !== "notify")
701
+ throw new RPCProtocolError("method_unavailable");
702
+ const registration = this.#subscribers.subscribe(method, definition, handler, options, access, undefined, scheduler);
703
+ try {
704
+ this.#check();
705
+ if (this.#applicationDraining())
706
+ throw new RPCProtocolError("source_unavailable");
707
+ return registration;
708
+ }
709
+ catch (error) {
710
+ registration.close();
711
+ throw error;
712
+ }
713
+ }
714
+ #acceptNotification(header) {
715
+ let route, references = [];
716
+ try {
717
+ this.#check();
718
+ if (this.#applicationDraining() || (header.kind !== "observation_notify" && header.kind !== "execution_notify") || header.payloadBytes > this.#maxCaptureBytes || this.#authentication === undefined || this.#cleanup === undefined)
719
+ return;
720
+ route = this.#routes.capture(header);
721
+ if (route === undefined || !route.registered)
722
+ return;
723
+ const access = this.#notificationAccess.get(route.method);
724
+ if (access === undefined)
725
+ return;
726
+ access.check();
727
+ route.contract.checkRequest(header);
728
+ const host = this.#host, sample = host.clock.sample(), now = sample.requireInterval(), cutoff = header.uint(5);
729
+ this.#deadline.checkAt(sample);
730
+ this.#check();
731
+ access.check();
732
+ if (cutoff <= now.upperMS || cutoff > timeAdd(now.lowerMS, route.contract.uint(header.kind === "execution_notify" ? 17 : 11)))
733
+ return;
734
+ const deadline = this.#deadline.fork(cutoff < this.#deadline.cap ? cutoff : this.#deadline.cap);
735
+ if (this.#nextInbound === (1n << 64n) - 1n)
736
+ return;
737
+ const id = ++this.#nextInbound;
738
+ references = host.root.reserveBatch(notificationMessageCharges(header.payloadBytes, this.#runtimeBytes).map((charge, index) => ({ accounts: host.accounts, owner: { ...host.owner, kind: `notify_message_${id}_${index}` }, charge })));
739
+ const input = new NotificationMessage(header, route, deadline, this.#runtimeBytes, references, (original, request, payload, limit) => {
740
+ if (header.kind === "execution_notify")
741
+ return this.#dispatchNotification(original, request, payload, limit);
742
+ this.#fanoutNotification(original, payload, limit);
743
+ return false;
744
+ });
745
+ route = undefined;
746
+ return input;
747
+ }
748
+ catch {
749
+ return undefined;
750
+ }
751
+ finally {
752
+ route?.close();
753
+ for (const reference of references)
754
+ reference.release();
755
+ }
756
+ }
757
+ #dispatchNotification(route, request, bytes, deadline) {
758
+ this.#check();
759
+ deadline.check();
760
+ if (this.#applicationDraining())
761
+ return false;
762
+ const registration = this.#notificationBusinesses.get(route.method), history = this.#histories.get(route.namespace), access = this.#notificationAccess.get(route.method);
763
+ if (registration === undefined || history === undefined || access === undefined || this.#executionIdentity === undefined || !registration.available() || request.header.uint(7) === 1n && !registration.idle)
764
+ return false;
765
+ registration.check();
766
+ access.check();
767
+ const boundary = this.#subscribers.boundary, host = this.#host;
768
+ if (this.#nextInbound === (1n << 64n) - 1n)
769
+ return false;
770
+ const id = ++this.#nextInbound;
771
+ const refs = host.root.reserveBatch([rpcPayloadCharge(bytes.length, this.#runtimeBytes), notificationWorkCharge(route.definition, registration.options, this.#runtimeBytes)]
772
+ .map((charge, index) => ({ accounts: host.accounts, owner: { ...host.owner, kind: `notify_execution_${id}_${index}` }, charge })));
773
+ let execution, input;
774
+ try {
775
+ execution = new NotificationExecution(request, route, deadline, history, this.#routes, this.#authentication, this.#executionIdentity, { check: () => registration.check(), current: () => registration.current() }, () => {
776
+ const original = request.borrow();
777
+ try {
778
+ this.#fanoutNotification(route, original.bytes, deadline, this.#subscribers.snapshot(route.method, boundary));
779
+ }
780
+ finally {
781
+ original.release();
782
+ }
783
+ });
784
+ input = new NotificationInput(bytes, route.definition, registration, deadline.fork(deadline.cap), this.#group, this.#authentication, host.delivery, this.#cleanup, this.#runtimeBytes, refs, execution, host.diagnostics);
785
+ input.ready();
786
+ return true;
787
+ }
788
+ catch {
789
+ input?.close();
790
+ execution?.close();
791
+ return false;
792
+ }
793
+ finally {
794
+ for (const ref of refs)
795
+ ref.release();
796
+ }
797
+ }
798
+ #fanoutNotification(route, bytes, deadline, captured) {
799
+ this.#check();
800
+ deadline.check();
801
+ if (this.#applicationDraining() && captured === undefined || this.#cleanup === undefined || this.#authentication === undefined)
802
+ return;
803
+ const access = this.#notificationAccess.get(route.method);
804
+ access?.check();
805
+ if (access === undefined)
806
+ return;
807
+ // Capture once at complete-message admission; no late registration replay.
808
+ const registrations = captured ?? [...(this.#notificationBusinesses.has(route.method) ? [this.#notificationBusinesses.get(route.method)] : []), ...this.#subscribers.snapshot(route.method)], host = this.#host;
809
+ for (const registration of registrations) {
810
+ if (registration.closed)
811
+ continue;
812
+ if (!registration.available()) {
813
+ host.diagnostics?.counters.observe("slow_consumer", { phase: "application", code: "slow_consumer" });
814
+ registration.gap("dropped_budget");
815
+ continue;
816
+ }
817
+ let refs = [], input;
818
+ try {
819
+ this.#check();
820
+ deadline.check();
821
+ access.check();
822
+ registration.check();
823
+ if (this.#nextInbound === (1n << 64n) - 1n)
824
+ throw new RPCProtocolError("resource_exhausted");
825
+ const id = ++this.#nextInbound;
826
+ refs = host.root.reserveBatch([rpcPayloadCharge(bytes.length, this.#runtimeBytes), notificationWorkCharge(route.definition, registration.options, this.#runtimeBytes)]
827
+ .map((charge, index) => ({ accounts: host.accounts, owner: { ...host.owner, kind: `notify_observer_${id}_${index}` }, charge })));
828
+ input = new NotificationInput(bytes, route.definition, registration, deadline.fork(deadline.cap), this.#group, this.#authentication, host.delivery, this.#cleanup, this.#runtimeBytes, refs, undefined, host.diagnostics);
829
+ input.ready();
830
+ }
831
+ catch {
832
+ if (input === undefined)
833
+ registration.gap("dropped_budget");
834
+ else
835
+ input.close("dropped_budget");
836
+ }
837
+ finally {
838
+ for (const ref of refs)
839
+ ref.release();
840
+ }
841
+ }
842
+ }
843
+ prepareNotify(method, namespace, contract, offer, value, options, source, workClass, context, signal, destination) {
844
+ this.#check();
845
+ const definition = methodDefinition(method), captured = captureNotifyOptions(options, context), host = this.#host;
846
+ if (this.#applicationDraining() || this.#cleanup === undefined || this.#authentication === undefined || definition.shape !== "notify" || definition.semantics === "execution" && this.#profile !== "execution")
847
+ throw new RPCProtocolError("notify_unavailable");
848
+ contract.checkMethod(namespace, definition);
849
+ source.check();
850
+ this.#check();
851
+ if (!source.current() || signal?.aborted || context?.signal.aborted)
852
+ throw new RPCProtocolError("canceled");
853
+ const localClass = applicationWorkClass(workClass, context), inputBytes = messageInputBytes(value, definition.request.implementation, definition.request.maximum);
854
+ if (this.#nextPreparation === (1n << 64n) - 1n)
855
+ throw new RPCProtocolError("resource_exhausted");
856
+ const id = ++this.#nextPreparation;
857
+ // Fix the original channel's send budget before retaining immutable bytes.
858
+ // Start cannot silently move a preparation to a different channel/account.
859
+ let position = this.#notifyChannels.findIndex(channel => channel?.ready());
860
+ if (position < 0)
861
+ position = this.#notifyChannels.findIndex(channel => channel !== undefined);
862
+ if (position < 0)
863
+ position = this.#authentication.localRole === "client" ? 0 : 1;
864
+ const costs = notifyPreparationCharges(definition, contract, inputBytes, this.#runtimeBytes);
865
+ const prepaid = initializerCallBacking(context, this, method, namespace, destination, costs, host.accounts, host.notificationAccounts[position]);
866
+ const refs = prepaid?.references ?? host.root.reserveBatch(costs.map((charge, index) => ({
867
+ accounts: index === 1 ? host.notificationAccounts[position] : host.accounts, owner: { ...host.owner, kind: `notify_preparation_${id}_${index}` }, charge
868
+ })));
869
+ let operation;
870
+ try {
871
+ operation = new NotifyPreparation(definition, namespace, contract, captured, this.#operationPublication(source), { start: original => {
872
+ this.#check();
873
+ if (this.#applicationDraining())
874
+ throw new RPCProtocolError("source_unavailable");
875
+ const channel = this.#notifyChannels[position];
876
+ return channel?.submit(original) ?? Object.freeze({ status: "not_admitted", submission: "not_submitted", reason: "not_ready" });
877
+ } }, host.clock, this.#deadline, this.#group, this.#authentication, host.delivery, this.#cleanup, localClass, inputBytes, this.#runtimeBytes, refs, offer, this.#random, this.#localExecutionAuthority, destination, host.diagnostics);
878
+ const original = operation;
879
+ this.#notifyPreparations.add(original);
880
+ original.onDetach(() => { this.#notifyPreparations.delete(original); this.#collect(); });
881
+ return original.encode(value, context, signal).then(() => { original.checkPublication(); return original; });
882
+ }
883
+ catch (error) {
884
+ operation?.close();
885
+ throw error;
886
+ }
887
+ finally {
888
+ for (const ref of refs)
889
+ ref.release();
890
+ }
891
+ }
892
+ bindManagement(stream) {
893
+ this.#check();
894
+ if (this.#profile !== "execution" || this.#management !== undefined || this.#managementUnavailable || this.#draining)
895
+ throw new RPCProtocolError("management_unavailable");
896
+ const refs = this.#managementRefs;
897
+ try {
898
+ this.#management = new ExecutionManagementChannel(stream, this.#host.clock, this.#deadline, this.#managementPosition, this.#runtimeBytes, refs, this.#managementGroup, (target, cancel, access) => {
899
+ const history = this.#histories.get(target.namespace);
900
+ if (history === undefined)
901
+ return { status: "unavailable" };
902
+ return history.manage(target, cancel, access);
903
+ }, (target, cancel, outgoing) => this.#authorizeManagement(target, cancel, outgoing), () => { this.#collect(); this.#managementChanged?.(); }, this.#host.diagnostics);
904
+ this.#management.start();
905
+ for (const wake of this.#managementWaiters)
906
+ wake();
907
+ }
908
+ catch (error) {
909
+ this.managementFailed();
910
+ throw error;
911
+ }
912
+ finally {
913
+ for (const reference of refs)
914
+ reference.release();
915
+ refs.length = 0;
916
+ }
917
+ }
918
+ managementFailed() {
919
+ this.#managementUnavailable = true;
920
+ this.#management?.close();
921
+ this.#managementGroup?.close();
922
+ for (const reference of this.#managementRefs)
923
+ reference.release();
924
+ this.#managementRefs.length = 0;
925
+ for (const wake of this.#managementWaiters)
926
+ wake();
927
+ this.#managementChanged?.();
928
+ }
929
+ onManagementChange(callback) {
930
+ this.#check();
931
+ if (this.#managementChanged !== undefined)
932
+ throw new RPCProtocolError("management_owner");
933
+ this.#managementChanged = callback;
934
+ }
935
+ managementReady() { return this.#management !== undefined && !this.#management.closed; }
936
+ managementReusable() {
937
+ return !this.#closed && !this.managementReady() && this.#management?.cleanupComplete() !== false && this.#managementGroup?.cleanupComplete() !== false &&
938
+ this.#managementRefs.length === 0 && this.#managementPositions.every(position => position.available()) && this.#managementPosition?.available() === true;
939
+ }
940
+ prepareManagement() {
941
+ this.#check();
942
+ if (this.#draining || !this.managementReusable())
943
+ throw new RPCProtocolError("management_unavailable");
944
+ this.#management = undefined;
945
+ this.#managementGroup = undefined;
946
+ const host = this.#host, refs = [];
947
+ try {
948
+ for (const position of this.#managementPositions)
949
+ refs.push(position.checkout());
950
+ this.#managementGroup = applicationGroup(host.root, host.accounts, { ...host.owner, kind: "execution_management" }, this.#runtimeBytes, true, refs[2]);
951
+ const costs = executionManagementCharges(this.#runtimeBytes);
952
+ for (const i of [0, 1, 3, 4, 5])
953
+ this.#managementRefs.push(refs[i].take(costs[i]));
954
+ this.#managementUnavailable = false;
955
+ }
956
+ catch (error) {
957
+ this.managementFailed();
958
+ throw error;
959
+ }
960
+ finally {
961
+ for (const reference of refs)
962
+ reference.release();
963
+ }
964
+ }
965
+ #authorizeManagement(target, cancel, outgoing) {
966
+ this.#check();
967
+ this.#deadline.check();
968
+ this.#managementLease?.check();
969
+ const identity = this.#executionIdentity, authentication = this.#authentication;
970
+ if (this.#managementBusinessAvailable?.() === false)
971
+ throw new RPCProtocolError("management_unavailable");
972
+ if (this.#profile !== "execution" || authentication === undefined || target.tenant !== authentication.tenant || target.audience !== authentication.audience)
973
+ throw new RPCProtocolError("permission_denied");
974
+ let authority, subject;
975
+ if (outgoing) {
976
+ authority = this.#localExecutionAuthority;
977
+ subject = authentication.localSubject;
978
+ }
979
+ else {
980
+ const permission = this.#executionPermissions.find(entry => entry.namespace === target.namespace);
981
+ if (identity === undefined || identity.subject !== authentication.peerSubject || identity.identityDigest !== authentication.peerIdentityDigest ||
982
+ !(cancel ? permission?.cancel : permission?.query))
983
+ throw new RPCProtocolError("permission_denied");
984
+ authority = identity.authority;
985
+ subject = identity.subject;
986
+ }
987
+ if (authority === undefined)
988
+ throw new RPCProtocolError("permission_denied");
989
+ if (authority !== target.authority || subject !== target.subject) {
990
+ const grant = this.#executionDelegations.find(entry => entry.direction === (outgoing ? "outgoing" : "incoming") && entry.namespace === target.namespace &&
991
+ entry.principalAuthority === authority && entry.principalSubject === subject && entry.targetAuthority === target.authority && entry.targetSubject === target.subject);
992
+ if (grant === undefined || !(cancel ? grant.cancel : grant.query))
993
+ throw new RPCProtocolError("permission_denied");
994
+ // Current trusted time and the original grant cutoff are checked again
995
+ // at every management publication and retained-result fragment.
996
+ const now = this.#host.clock.sample().requireInterval();
997
+ this.#check();
998
+ if (now.upperMS >= grant.notAfterMS)
999
+ throw new RPCProtocolError("permission_denied");
1000
+ }
1001
+ this.#check();
1002
+ }
1003
+ async manageExecution(reference, cancel, deadline, signal) {
1004
+ const diagnostic = new DiagnosticActivity(this.#host?.diagnostics, "application");
1005
+ let transferred = false;
1006
+ try {
1007
+ return await this.#manageExecution(reference, cancel, deadline, signal, diagnostic, () => { transferred = true; });
1008
+ }
1009
+ catch (error) {
1010
+ if (!transferred)
1011
+ diagnostic.failure(error);
1012
+ throw error;
1013
+ }
1014
+ }
1015
+ async #manageExecution(reference, cancel, deadline, signal, diagnostic, transfer) {
1016
+ this.#check();
1017
+ if (this.#authentication === undefined)
1018
+ throw new RPCProtocolError("permission_denied");
1019
+ const target = operationTarget(reference, this.#authentication, this.#referenceTargets);
1020
+ this.#authorizeManagement(target, cancel, true);
1021
+ if (!this.managementReady()) {
1022
+ if (this.#managementWaiters.size >= 2 || this.#managementUnavailable || this.#draining)
1023
+ throw new RPCProtocolError("management_unavailable");
1024
+ await new Promise((resolve, reject) => {
1025
+ let timer;
1026
+ const finish = () => {
1027
+ if (timer !== undefined)
1028
+ clearTimeout(timer);
1029
+ timer = undefined;
1030
+ this.#managementWaiters.delete(wake);
1031
+ if (signal !== undefined)
1032
+ managementRemoveListener.call(signal, "abort", wake);
1033
+ };
1034
+ const wake = () => {
1035
+ try {
1036
+ this.#check();
1037
+ deadline.check();
1038
+ if (signal !== undefined && managementAborted.call(signal))
1039
+ throw new RPCProtocolError("canceled");
1040
+ if (this.#managementUnavailable || this.#draining)
1041
+ throw new RPCProtocolError("management_unavailable");
1042
+ if (this.managementReady()) {
1043
+ finish();
1044
+ resolve();
1045
+ }
1046
+ }
1047
+ catch (error) {
1048
+ finish();
1049
+ reject(error);
1050
+ }
1051
+ };
1052
+ try {
1053
+ const remaining = deadline.remainingMS();
1054
+ this.#managementWaiters.add(wake);
1055
+ if (signal !== undefined)
1056
+ managementAddListener.call(signal, "abort", wake, { once: true });
1057
+ timer = setTimeout(wake, Number(remaining > 2147483647n ? 2147483647n : remaining));
1058
+ wake();
1059
+ }
1060
+ catch (error) {
1061
+ finish();
1062
+ reject(error);
1063
+ }
1064
+ });
1065
+ }
1066
+ const channel = this.#management;
1067
+ if (channel === undefined)
1068
+ throw new RPCProtocolError("management_unavailable");
1069
+ transfer();
1070
+ return channel.request(target, cancel, deadline, signal, diagnostic);
1071
+ }
1072
+ get bound() { return this.#bound; }
1073
+ /** Fixed ordinary read, admitted as general K + complete result ownership.
1074
+ * No management request, Offer refresh or execution registration is hidden. */
1075
+ readExecutionResult(reference, deadline, context, signal) {
1076
+ this.#check();
1077
+ if (this.#applicationDraining() || this.#authentication === undefined || this.#resultReadCodec === undefined || this.#resultReadBusy)
1078
+ throw new RPCProtocolError("service_unavailable");
1079
+ if (signal !== undefined && managementAborted.call(signal))
1080
+ throw new RPCProtocolError("canceled");
1081
+ const target = operationTarget(reference, this.#authentication, this.#referenceTargets), limit = operationResultLimit(reference), host = this.#host, cleanup = this.#cleanup;
1082
+ if (!deadline.belongsTo(host.clock) || deadline.cap > this.#deadline.cap)
1083
+ throw new RPCProtocolError("rpc_request_binding");
1084
+ this.#authorizeManagement(target, false, true);
1085
+ deadline.check();
1086
+ const workClass = applicationWorkClass("resident", context);
1087
+ const channel = this.#selectChannel(workClass);
1088
+ this.#resultReadBusy = true;
1089
+ let references = [], reserved;
1090
+ let request, exchange, job = false;
1091
+ const diagnostic = new DiagnosticActivity(host.diagnostics, "application");
1092
+ try {
1093
+ if (this.#nextPreparation === (1n << 64n) - 1n)
1094
+ throw new RPCProtocolError("resource_exhausted");
1095
+ const id = ++this.#nextPreparation, encoded = this.#resultReadCodec.encodeTarget(target, this.#resultReadBuffer);
1096
+ const costs = rpcUnaryExchangeCharges(encoded.length, limit, this.#runtimeBytes);
1097
+ references = host.root.reserveBatch(costs.map((charge, index) => ({ accounts: index === 1 ? this.#sendAccounts(channel) : host.accounts,
1098
+ owner: { ...host.owner, kind: `rpc_result_read_${id}_${index}` }, charge })));
1099
+ reserved = this.reserveCall(workClass);
1100
+ request = new RPCPayload(encoded.length, this.#runtimeBytes, references[1]);
1101
+ request.write(0, encoded);
1102
+ const header = channel.resultReadHeader(encoded.length, deadline.cap);
1103
+ const guard = Object.freeze({ check: () => this.#authorizeManagement(target, false, true), current: () => !this.#closed });
1104
+ cleanup.startJob();
1105
+ job = true;
1106
+ exchange = new RPCUnaryExchange(header, undefined, request, deadline, guard, host.delivery, host.root, this.#runtimeBytes, [references[0], references[2]], reserved.call, reserved.completion, undefined, this.#authentication, undefined, limit, undefined, diagnostic);
1107
+ const original = exchange;
1108
+ this.#unary.add(original);
1109
+ original.onNetworkCleanup(() => { this.#unary.delete(original); cleanup.finishJob(); this.#collect(); });
1110
+ job = false;
1111
+ this.#check();
1112
+ if (this.#applicationDraining())
1113
+ throw new RPCProtocolError("service_unavailable");
1114
+ original.cancelWith(signal);
1115
+ original.submit(channel);
1116
+ return original;
1117
+ }
1118
+ catch (error) {
1119
+ diagnostic.failure(error);
1120
+ exchange?.close();
1121
+ request?.close();
1122
+ reserved?.call.close();
1123
+ reserved?.completion.close();
1124
+ if (job)
1125
+ cleanup.finishJob();
1126
+ throw error;
1127
+ }
1128
+ finally {
1129
+ this.#resultReadBuffer.fill(0);
1130
+ for (const ref of references)
1131
+ ref.release();
1132
+ this.#resultReadBusy = false;
1133
+ this.#collect();
1134
+ }
1135
+ }
1136
+ get routes() { this.#check(); return this.#routes; }
1137
+ get permissions() { this.#check(); return this.#access; }
1138
+ /** Bind borrows this exact authenticated Session and its existing query
1139
+ * owner. It never acquires material, connects or opens a per-service Stream. */
1140
+ bindService(definition, options, deadline, context, signal, dependency, prepaid, preparation) {
1141
+ this.#check();
1142
+ const contracts = options.contractSource, captured = dependency ?? captureServiceBinding(definition, options);
1143
+ if (captured.definition !== definition)
1144
+ throw new RPCProtocolError("service_binding_owner");
1145
+ this.#check();
1146
+ if (this.#applicationDraining() || this.#authentication === undefined || !deadline.belongsTo(this.#host.clock))
1147
+ throw new RPCProtocolError("source_unavailable");
1148
+ const source = this.bindingSource(captured, () => preparation);
1149
+ const reservation = prepaid ?? this.#bindings.reserve(captured);
1150
+ reservation.claim(captured, this.#bindings);
1151
+ let binding;
1152
+ try {
1153
+ binding = new ServiceBinding(captured, reservation, source);
1154
+ const original = binding;
1155
+ this.#serviceClients.add(original);
1156
+ original.onClose(() => { this.#serviceClients.delete(original); this.#collect(); });
1157
+ this.#check();
1158
+ return original.initialize(deadline, context, signal, contracts).finally(() => { preparation = undefined; });
1159
+ }
1160
+ catch (error) {
1161
+ binding?.close();
1162
+ reservation.close();
1163
+ throw error;
1164
+ }
1165
+ }
1166
+ /** Expose the original fixed Session capabilities without creating another
1167
+ * binding or taking ownership of a Controller's method snapshots. */
1168
+ bindingSource(captured, preparation) {
1169
+ this.#check();
1170
+ const check = () => {
1171
+ this.#check();
1172
+ this.#deadline.check();
1173
+ if (this.#applicationDraining() || this.#authentication === undefined)
1174
+ throw new RPCProtocolError("source_unavailable");
1175
+ };
1176
+ const current = () => !this.#closed && !this.#applicationDraining() && this.#authentication !== undefined;
1177
+ return Object.freeze({ clock: this.#host.clock, group: this.#serviceGroup, check, current,
1178
+ authentication: () => { check(); return this.#authentication; },
1179
+ checkDependency: (method, contract) => {
1180
+ check();
1181
+ if (method.facts.shape === "notify") {
1182
+ if (!this.notifyReady())
1183
+ throw new RPCProtocolError("not_ready");
1184
+ }
1185
+ else if (method.facts.shape === "unary")
1186
+ this.#selectChannel().checkDependency();
1187
+ else {
1188
+ if (this.#preaccepted === undefined || method.streamKind === undefined)
1189
+ throw new RPCProtocolError("not_ready");
1190
+ this.#preaccepted.checkReady({ namespace: captured.namespace, authority: captured.target.authority, kind: method.streamKind, metadata: method.streamMetadata, contract });
1191
+ }
1192
+ },
1193
+ deadline: duration => { check(); return this.#deadline.forkAgeAt(this.#host.clock.sample(), duration); },
1194
+ protectRenewal: reference => {
1195
+ check();
1196
+ return this.#queries.protectRenewal(this.#acquisitions, this.#selectChannel(), reference);
1197
+ },
1198
+ observeAvailability: (reference, wake) => this.#host.root.observeAvailability(reference, wake),
1199
+ retain: (reference, closed) => this.#host.delivery.retain(reference, closed),
1200
+ query: (targets, limit, windows, invocation, delivery, renewal) => this.query(targets, limit, windows, invocation, delivery, renewal, renewal === undefined ? preparation?.() : undefined),
1201
+ prepareStream: (method, namespace, contract, offer, value, settings, invocation, cancellation) => this.prepareStream(method, namespace, contract, offer, value, settings, { check, current }, invocation, cancellation, captured.target),
1202
+ preacceptStreams: (namespace, targets) => this.#preacceptStreams(namespace, targets, captured.target.authority),
1203
+ prepareNotify: (method, namespace, contract, offer, value, settings, invocation, cancellation) => this.prepareNotify(method.method, namespace, contract, offer, value, settings, { check, current }, method.workClass, invocation, cancellation, captured.target),
1204
+ prepareResume: (method, namespace, contract, offer, stream, token, settings, invocation, cancellation) => this.prepareResume(method, namespace, contract, offer, stream, token, settings, { check, current }, invocation, cancellation, captured.target),
1205
+ prepare: (method, namespace, contract, offer, value, settings, invocation, cancellation) => this.prepareUnary(method.method, namespace, contract, offer, value, settings, { check, current }, method.workClass, invocation, cancellation, captured.target), });
1206
+ }
1207
+ /** Only a method declared by the original plan can receive a new handler
1208
+ * generation. This does not install or silently update its wire contract. */
1209
+ registerUnary(namespace, method, handler, options) {
1210
+ this.#check();
1211
+ const captured = captureUnaryHandler(options), definition = methodDefinition(method), host = this.#host;
1212
+ if (definition.restartFlush)
1213
+ checkMaintenanceOwner(this.#maintenanceOwner, this.#reference);
1214
+ if (definition.shape !== "unary" || definition.semantics !== "transient" ||
1215
+ captured.maxConcurrentCalls > this.#general || this.#nextRegistration === (1n << 64n) - 1n)
1216
+ throw new RPCProtocolError("configuration_capacity");
1217
+ const reference = host.root.reserve({ accounts: host.accounts,
1218
+ owner: { ...host.owner, kind: `rpc_unary_registration_${++this.#nextRegistration}` }, charge: rpcUnaryRegistrationCharge(captured, this.#runtimeBytes) });
1219
+ let registration;
1220
+ try {
1221
+ registration = new RPCUnaryRegistration(method, handler, captured, this.#runtimeBytes, reference);
1222
+ this.#routes.installHandler(namespace, method, registration);
1223
+ return registration;
1224
+ }
1225
+ catch (error) {
1226
+ registration?.close();
1227
+ throw error;
1228
+ }
1229
+ finally {
1230
+ reference.release();
1231
+ }
1232
+ }
1233
+ /** The method binding supplies its captured local class before encoding. */
1234
+ reserveCall(workClass, prepaid, prepaidCall) {
1235
+ let call;
1236
+ try {
1237
+ this.#check();
1238
+ if (this.#applicationDraining())
1239
+ throw new RPCProtocolError("service_unavailable");
1240
+ if (prepaidCall !== undefined) {
1241
+ this.#calls.checkUnsubmitted(prepaidCall);
1242
+ prepaidCall.inheritClass(workClass);
1243
+ }
1244
+ call = prepaidCall ?? this.#network.reserveCall(workClass);
1245
+ }
1246
+ catch (error) {
1247
+ prepaidCall?.close();
1248
+ prepaid?.close();
1249
+ throw error;
1250
+ }
1251
+ try {
1252
+ const completion = prepaid ?? (workClass === "short" && this.#completion.available() ? this.#completion.checkout() : this.#group.reserveCompletion());
1253
+ return Object.freeze({ call, completion });
1254
+ }
1255
+ catch (error) {
1256
+ call.close();
1257
+ throw error;
1258
+ }
1259
+ }
1260
+ /** The exact trusted binding enters before any application encoder. All
1261
+ * request/result/codec bytes, K and Completion ownership are captured here. */
1262
+ setStreamOpener(opener) {
1263
+ this.#check();
1264
+ if (this.#streamOpener !== undefined)
1265
+ throw new RPCProtocolError("rpc_stream_owner");
1266
+ this.#streamOpener = opener;
1267
+ }
1268
+ #preacceptStreams(namespace, targets, authority) {
1269
+ this.#check();
1270
+ const host = this.#host;
1271
+ if (this.#applicationDraining() || this.#streamOpener === undefined || targets.some(({ method }) => method.streamKind === undefined || method.facts.shape !== "server_streaming"))
1272
+ throw new RPCProtocolError("not_ready");
1273
+ if (this.#preaccepted === undefined) {
1274
+ const reference = this.#initialStreams?.takePool() ?? host.root.reserve({ owner: { ...host.owner, kind: "rpc_preaccepted_streams" }, accounts: host.accounts, charge: rpcPreacceptedStreamsCharge(this.#runtimeBytes) });
1275
+ try {
1276
+ this.#preaccepted = new RPCPreacceptedStreams(this.#runtimeBytes, reference, host.clock, this.#deadline.fork(this.#deadline.cap), target => this.#newMessages(target), async (target, fixed, signal) => {
1277
+ this.#check();
1278
+ if (this.#applicationDraining())
1279
+ throw new RPCProtocolError("source_unavailable");
1280
+ await this.#streamOpener(target.kind, target.metadata, this.#deadline.forkAgeAt(host.clock.sample(), 30000n), signal, stream => fixed.messages.attach(stream, fixed.adapter), fixed.open);
1281
+ }, () => this.#collect());
1282
+ }
1283
+ finally {
1284
+ reference.release();
1285
+ }
1286
+ }
1287
+ return this.#preaccepted.demand(targets.map(({ method, contract }) => ({ namespace, authority, kind: method.streamKind, metadata: method.streamMetadata, contract })));
1288
+ }
1289
+ hasStreamingKind(kind) { return !this.#closed && this.#streamHandlers.has(kind); }
1290
+ hasStreamingHandlers() { return !this.#closed && this.#streamHandlers.size !== 0; }
1291
+ #newMessages(target) {
1292
+ this.#check();
1293
+ const host = this.#host, costs = [...rpcStreamMessagesCharges(this.#runtimeBytes), rpcStreamingErrorCharge(this.#runtimeBytes)];
1294
+ if (this.#nextPreparation === (1n << 64n) - 1n)
1295
+ throw new RPCProtocolError("resource_exhausted");
1296
+ const serial = ++this.#nextPreparation;
1297
+ const prepaid = target === undefined ? undefined : this.#initialStreams?.take(target.namespace, target.authority, target.kind, target.metadata);
1298
+ const references = prepaid === undefined ? host.root.reserveBatch(costs.map((charge, part) => ({ owner: { ...host.owner, kind: `rpc_stream_io_${serial}_${part}` },
1299
+ accounts: part === 4 ? host.sendAccounts : host.accounts, charge }))) : [...prepaid.references];
1300
+ let messages, group = prepaid?.group, position;
1301
+ try {
1302
+ if (prepaid !== undefined) {
1303
+ const output = references[4];
1304
+ references[4] = output.transfer({ ...host.owner, kind: `rpc_stream_io_${serial}_4` }, host.owner.backing, host.sendAccounts);
1305
+ output.release();
1306
+ }
1307
+ group ??= applicationGroup(host.root, host.accounts, { ...host.owner, kind: `rpc_stream_group_${serial}` }, this.#runtimeBytes, false, references[5]);
1308
+ position = host.root.protect(references[4], costs[4]);
1309
+ messages = new RPCStreamMessages(this.#runtimeBytes, references, position, group);
1310
+ return { messages, adapter: references[1].take(costs[1]), error: references[6].take(costs[6]), ...(prepaid === undefined ? {} : { open: prepaid.open }) };
1311
+ }
1312
+ catch (error) {
1313
+ prepaid?.open.close();
1314
+ messages?.close();
1315
+ group?.close();
1316
+ position?.closeAfterUse();
1317
+ throw error;
1318
+ }
1319
+ finally {
1320
+ for (const reference of references)
1321
+ reference.release();
1322
+ }
1323
+ }
1324
+ prepareIncomingResume(kind, namespace, method) {
1325
+ this.#check();
1326
+ const host = this.#host, definition = methodDefinition(method);
1327
+ if (this.#applicationDraining() || this.#checkpointPolicy === undefined || this.#executionIdentity === undefined || this.#authentication === undefined ||
1328
+ this.#cleanup === undefined || definition.shape !== "unary" || definition.semantics !== "execution")
1329
+ throw new RPCProtocolError("resume_binding");
1330
+ const fixed = this.#newMessages();
1331
+ let codec, output, interest, work, dispatch;
1332
+ try {
1333
+ codec = this.#newResumeCodec();
1334
+ output = host.root.reserve({ owner: { ...host.owner, kind: `rpc_resume_output_${this.#nextPreparation}` }, accounts: host.sendAccounts, charge: rpcPayloadCharge(4248, this.#runtimeBytes) });
1335
+ interest = host.root.reserve({ owner: { ...host.owner, kind: `rpc_resume_interest_${this.#nextPreparation}` }, accounts: host.accounts, charge: rpcOutputInterestCharge(this.#runtimeBytes) });
1336
+ const serial = this.#nextPreparation;
1337
+ work = host.root.reserve({ owner: { ...host.owner, kind: `rpc_resume_dispatch_${serial}` }, accounts: host.accounts, charge: rpcResumeDispatchCharge(this.#runtimeBytes) });
1338
+ const ticket = this.#network.reserveIncomingStream(fixed.messages);
1339
+ fixed.messages.bind(this.#network, ticket);
1340
+ dispatch = new RPCResumeDispatch(fixed.messages, fixed.adapter, codec, this.#network, ticket, this.#inputs, this.#routes, namespace, method, kind, this.#group, this.#authentication, this.#executionIdentity, this.#checkpointPolicy, host.clock, this.#cleanup, this.#runtimeBytes, output, interest, work, bytes => host.root.reserve({
1341
+ owner: { ...host.owner, kind: `rpc_resume_authorization_${serial}` }, accounts: host.accounts,
1342
+ charge: new ResourceVector([bytes, 0n, 0n, 0n, 0n, 0n, 0n, 0n, 0n, 0n, 0n])
1343
+ }), host.diagnostics);
1344
+ const original = dispatch;
1345
+ this.#resumeDispatches.add(original);
1346
+ original.onCleanup(() => { this.#resumeDispatches.delete(original); this.#collect(); });
1347
+ return original;
1348
+ }
1349
+ catch (error) {
1350
+ dispatch?.close();
1351
+ fixed.messages.close();
1352
+ fixed.adapter.release();
1353
+ codec?.close();
1354
+ throw error;
1355
+ }
1356
+ finally {
1357
+ output?.release();
1358
+ interest?.release();
1359
+ work?.release();
1360
+ fixed.error.release();
1361
+ }
1362
+ }
1363
+ prepareIncomingStream(kind, metadata) {
1364
+ this.#check();
1365
+ const entry = this.#streamHandlers.get(kind), host = this.#host;
1366
+ if (entry === undefined || this.#applicationDraining() || this.#authentication === undefined || this.#cleanup === undefined ||
1367
+ metadata.length !== (entry.metadata?.length ?? 0) || metadata.some((byte, index) => byte !== entry.metadata[index]))
1368
+ throw new RPCProtocolError("service_unavailable");
1369
+ const fixed = this.#newMessages();
1370
+ let dispatch;
1371
+ const source = byteEventSource(entry.handler);
1372
+ const costs = rpcStreamingDispatchCharges(methodDefinition(entry.method), entry.options.applicationBytes, this.#runtimeBytes, source);
1373
+ let references = [];
1374
+ try {
1375
+ const ticket = this.#network.reserveIncomingStream(fixed.messages);
1376
+ fixed.messages.bind(this.#network, ticket);
1377
+ references = host.root.reserveBatch(costs.map((charge, part) => ({ owner: { ...host.owner, kind: `rpc_stream_dispatch_${this.#nextPreparation}_${part}` },
1378
+ accounts: part === 1 ? host.sendAccounts : host.accounts, charge })));
1379
+ dispatch = new RPCStreamingDispatch(fixed.messages, this.#network, ticket, this.#inputs, entry.contract, methodDefinition(entry.method), entry.options.applicationBytes, this.#group, this.#authentication, host.clock, this.#deadline.fork(this.#deadline.cap), host.delivery, this.#cleanup, this.#runtimeBytes, references, this.#routes, this.#executionIdentity, source, charge => {
1380
+ if (this.#nextPreparation === (1n << 64n) - 1n)
1381
+ throw new RPCProtocolError("resource_exhausted");
1382
+ return host.root.reserve({ owner: { ...host.owner, kind: `rpc_source_input_${++this.#nextPreparation}` }, accounts: host.accounts, charge });
1383
+ }, host.diagnostics);
1384
+ const original = dispatch;
1385
+ this.#streamDispatches.add(original);
1386
+ original.onCleanup(() => { this.#streamDispatches.delete(original); if (this.#closed && this.#streamDispatches.size === 0)
1387
+ this.#group?.retireResults(); this.#collect(); });
1388
+ return Object.freeze({ attach: (stream) => { try {
1389
+ fixed.messages.attach(stream, fixed.adapter);
1390
+ }
1391
+ finally {
1392
+ fixed.adapter.release();
1393
+ } },
1394
+ start: () => original.start(), close: () => { fixed.adapter.release(); original.close(); } });
1395
+ }
1396
+ catch (error) {
1397
+ fixed.adapter.release();
1398
+ dispatch?.close();
1399
+ fixed.messages.close();
1400
+ throw error;
1401
+ }
1402
+ finally {
1403
+ fixed.error.release();
1404
+ for (const reference of references)
1405
+ reference.release();
1406
+ }
1407
+ }
1408
+ prepareStream(method, namespace, contract, offer, value, options, source, context, signal, destination) {
1409
+ this.#check();
1410
+ const host = this.#host, captured = captureUnaryOptions(options, context), definition = method.facts;
1411
+ if (definition.shape !== "server_streaming" || definition.semantics === "execution" && this.#profile !== "execution" || method.streamKind === undefined || this.#streamOpener === undefined ||
1412
+ this.#applicationDraining() || this.#authentication === undefined || this.#cleanup === undefined || destination === undefined)
1413
+ throw new RPCProtocolError("rpc_request_binding");
1414
+ const kind = method.streamKind, metadata = new Uint8Array(method.streamMetadata);
1415
+ contract.checkMethod(namespace, definition);
1416
+ const localClass = applicationWorkClass(method.workClass, context), inputBytes = messageInputBytes(value, definition.request.implementation, definition.request.maximum);
1417
+ const costs = rpcUnaryPreparationCharges(contract, definition, unaryResponseLimit(contract, captured), inputBytes, this.#runtimeBytes);
1418
+ if (this.#nextPreparation === (1n << 64n) - 1n)
1419
+ throw new RPCProtocolError("resource_exhausted");
1420
+ const serial = ++this.#nextPreparation;
1421
+ const prepaid = initializerCallBacking(context, this, method.method, namespace, destination, costs, host.accounts, host.sendAccounts);
1422
+ const references = prepaid?.references ?? host.root.reserveBatch(costs.map((charge, part) => ({ owner: { ...host.owner, kind: `rpc_stream_prepare_${serial}_${part}` }, accounts: part === 1 ? host.sendAccounts : host.accounts, charge })));
1423
+ let reserved, preparation;
1424
+ try {
1425
+ reserved = this.reserveCall(localClass, prepaid?.completion, prepaid?.call);
1426
+ preparation = new RPCUnaryPreparation(definition, namespace, contract, offer, captured, this.#operationPublication(source), {
1427
+ check: (header, call) => { this.#check(); if (this.#applicationDraining() || this.#streamOpener === undefined)
1428
+ throw new RPCProtocolError("not_ready"); this.#network.checkOutgoingStream(header, call); },
1429
+ current: () => !this.#closed && !this.#applicationDraining() && this.#streamOpener !== undefined,
1430
+ reserve: (header, call) => header.uint(7) === 1n ? this.#reserveStreamStart(header, call, { namespace, authority: destination.authority, kind, metadata, contract }) : undefined,
1431
+ start: (transfer, claim) => this.#startStream(transfer, claim, kind, metadata),
1432
+ }, host.clock, this.#deadline, this.#random, host.delivery, this.#group, this.#authentication, this.#cleanup, reserved.call, reserved.completion, localClass, inputBytes, this.#runtimeBytes, references, this.#localExecutionAuthority, destination, false, host.diagnostics);
1433
+ const original = preparation;
1434
+ this.#preparations.add(original);
1435
+ original.onDetach(() => { this.#preparations.delete(original); this.#collect(); });
1436
+ return original.encode(value, context, signal).then(() => { original.checkReady(); return original; });
1437
+ }
1438
+ catch (error) {
1439
+ preparation?.close();
1440
+ reserved?.completion.close();
1441
+ reserved?.call.close();
1442
+ throw error;
1443
+ }
1444
+ finally {
1445
+ for (const reference of references)
1446
+ reference.release();
1447
+ }
1448
+ }
1449
+ #reserveStreamStart(header, call, target) {
1450
+ this.#check();
1451
+ if (this.#preaccepted === undefined)
1452
+ throw new RPCProtocolError("not_ready");
1453
+ const checkout = this.#preaccepted.claim(target), host = this.#host, network = this.#network;
1454
+ let admission;
1455
+ let lease;
1456
+ let exchange, transferred = false, authorized = true;
1457
+ try {
1458
+ admission = network.prepareOutgoingStream(checkout.fixed.messages, header, call);
1459
+ lease = host.delivery.retain(checkout.fixed.error, () => { authorized = false; exchange?.authorizationClosed(); });
1460
+ return {
1461
+ current: () => authorized && !this.#closed && !this.#applicationDraining() && checkout.current() && admission.current(),
1462
+ start: (transfer, claim) => {
1463
+ const fixed = checkout.take();
1464
+ transferred = true;
1465
+ try {
1466
+ exchange = this.#startStream(transfer, claim, target.kind, target.metadata, { fixed, admission: admission, lease: lease });
1467
+ lease = undefined;
1468
+ return exchange;
1469
+ }
1470
+ catch (error) {
1471
+ fixed.messages.close();
1472
+ fixed.error.release();
1473
+ fixed.adapter.release();
1474
+ throw error;
1475
+ }
1476
+ },
1477
+ release: () => { checkout.release(); admission.release(); if (!transferred || lease !== undefined)
1478
+ lease?.release(); },
1479
+ };
1480
+ }
1481
+ catch (error) {
1482
+ lease?.release();
1483
+ admission?.release();
1484
+ checkout.release();
1485
+ throw error;
1486
+ }
1487
+ }
1488
+ #startStream(transfer, claim, kind, metadata, prepared) {
1489
+ this.#check();
1490
+ const host = this.#host, cleanup = this.#cleanup, opener = this.#streamOpener;
1491
+ const fixed = prepared?.fixed ?? this.#newMessages();
1492
+ let exchange, job = false;
1493
+ try {
1494
+ const ticket = prepared?.admission.commit() ?? this.#network.reserveOutgoingStream(fixed.messages, transfer.header, transfer.call);
1495
+ fixed.messages.bind(this.#network, ticket);
1496
+ cleanup.startJob();
1497
+ job = true;
1498
+ exchange = new RPCStreamingExchange(transfer, fixed.messages, this.#runtimeBytes, fixed.error, host.delivery, this.#authentication, () => host.root.reserve({ owner: { ...host.owner, kind: "rpc_stream_item" }, accounts: host.accounts,
1499
+ charge: rpcCompletionCharge(Number(transfer.header.uint(8)), this.#runtimeBytes) }), claim, host.clock, prepared?.lease);
1500
+ const original = exchange;
1501
+ this.#streaming.add(original);
1502
+ original.onNetworkCleanup(() => { this.#streaming.delete(original); cleanup.finishJob(); this.#collect(); });
1503
+ job = false;
1504
+ original.start(this.#network, ticket, async (signal) => {
1505
+ if (prepared !== undefined) {
1506
+ if (signal.aborted)
1507
+ throw new RPCProtocolError("canceled");
1508
+ return;
1509
+ }
1510
+ try {
1511
+ await opener(kind, metadata, transfer.deadline, signal, stream => fixed.messages.attach(stream, fixed.adapter), fixed.open);
1512
+ }
1513
+ finally {
1514
+ fixed.adapter.release();
1515
+ }
1516
+ });
1517
+ return original;
1518
+ }
1519
+ catch (error) {
1520
+ fixed.adapter.release();
1521
+ exchange?.close();
1522
+ fixed.messages.close();
1523
+ if (job)
1524
+ cleanup.finishJob();
1525
+ throw error;
1526
+ }
1527
+ finally {
1528
+ fixed.error.release();
1529
+ }
1530
+ }
1531
+ #newResumeCodec() {
1532
+ const host = this.#host;
1533
+ if (this.#nextPreparation === (1n << 64n) - 1n)
1534
+ throw new RPCProtocolError("resource_exhausted");
1535
+ const id = ++this.#nextPreparation;
1536
+ const refs = host.root.reserveBatch(resumeCodecCharges(this.#runtimeBytes).map((charge, index) => ({
1537
+ owner: { ...host.owner, kind: `rpc_resume_codec_${id}_${index}` }, accounts: host.accounts, charge
1538
+ })));
1539
+ try {
1540
+ return new ResumeCodec(this.#runtimeBytes, refs);
1541
+ }
1542
+ finally {
1543
+ refs.forEach(ref => ref.release());
1544
+ }
1545
+ }
1546
+ async prepareResume(method, namespace, contract, offer, stream, token, options, source, context, signal, destination) {
1547
+ this.#check();
1548
+ if (this.#session === undefined || this.#checkpointPolicy === undefined || method.resumeKind === undefined ||
1549
+ contract.optionalUint(13) !== 1n || contract.requestMaxBytes < 9345 || contract.maxResponseBytes < 4248 ||
1550
+ byteLength(token) > this.#checkpointPolicy.maxTokenBytes)
1551
+ throw new RPCProtocolError("resume_binding");
1552
+ const fixed = this.#newMessages();
1553
+ let codec, preparation, moved = false;
1554
+ const release = () => {
1555
+ if (moved)
1556
+ return;
1557
+ moved = true;
1558
+ try {
1559
+ fixed.messages.releaseUnusedResume();
1560
+ }
1561
+ catch {
1562
+ fixed.messages.close();
1563
+ }
1564
+ codec?.close();
1565
+ fixed.adapter.release();
1566
+ fixed.error.release();
1567
+ };
1568
+ try {
1569
+ // Exclusive target qualification precedes every operation ID or saved ref.
1570
+ const target = fixed.messages.attachResume(stream, this.#session, method.resumeKind, fixed.adapter);
1571
+ fixed.adapter.release();
1572
+ codec = this.#newResumeCodec();
1573
+ const bytes = new Uint8Array(9345);
1574
+ try {
1575
+ const size = codec.encodeRequest(token, target, bytes);
1576
+ const guard = { check: () => { source.check(); fixed.messages.check(); }, current: () => source.current() && !fixed.messages.closed };
1577
+ preparation = await this.prepareUnary(method.method, namespace, contract, offer, bytes.subarray(0, size), options, guard, method.workClass, context, signal, destination, {
1578
+ check: (header, call) => { guard.check(); this.#network.checkOutgoingStream(header, call); },
1579
+ current: () => guard.current() && !this.#applicationDraining() && !this.#closed,
1580
+ releaseUnused: release,
1581
+ reserve: (header, call) => {
1582
+ if (header.uint(7) !== 1n)
1583
+ return;
1584
+ const admission = this.#network.prepareOutgoingStream(fixed.messages, header, call);
1585
+ return {
1586
+ current: () => guard.current() && !this.#applicationDraining() && !this.#closed && admission.current(),
1587
+ start: (transfer, claim) => {
1588
+ moved = true;
1589
+ fixed.error.release();
1590
+ return this.#startResume(transfer, claim, fixed.messages, codec, admission);
1591
+ },
1592
+ release: () => admission.release(),
1593
+ };
1594
+ },
1595
+ start: (transfer, claim) => {
1596
+ moved = true;
1597
+ fixed.error.release();
1598
+ return this.#startResume(transfer, claim, fixed.messages, codec);
1599
+ },
1600
+ });
1601
+ }
1602
+ finally {
1603
+ bytes.fill(0);
1604
+ }
1605
+ return preparation;
1606
+ }
1607
+ catch (error) {
1608
+ preparation?.close();
1609
+ release();
1610
+ throw error;
1611
+ }
1612
+ }
1613
+ #startResume(transfer, claim, messages, codec, prepared) {
1614
+ const host = this.#host, cleanup = this.#cleanup, network = this.#network;
1615
+ let exchange, job = false;
1616
+ try {
1617
+ this.#check();
1618
+ const ticket = prepared?.commit() ?? network.reserveOutgoingStream(messages, transfer.header, transfer.call);
1619
+ messages.bind(network, ticket);
1620
+ cleanup.startJob();
1621
+ job = true;
1622
+ exchange = new RPCUnaryExchange(transfer.header, transfer.contract, transfer.request, transfer.deadline, transfer.guard, host.delivery, host.root, this.#runtimeBytes, transfer.references, transfer.call, transfer.completion, transfer.method, this.#authentication, claim, undefined, undefined, transfer.diagnostic);
1623
+ const original = exchange;
1624
+ this.#unary.add(original);
1625
+ original.onNetworkCleanup(() => { this.#unary.delete(original); cleanup.finishJob(); this.#collect(); });
1626
+ job = false;
1627
+ original.submitResume(messages, network, ticket, codec);
1628
+ return original;
1629
+ }
1630
+ catch (error) {
1631
+ exchange?.close();
1632
+ messages.close();
1633
+ codec.close();
1634
+ if (job)
1635
+ cleanup.finishJob();
1636
+ throw error;
1637
+ }
1638
+ }
1639
+ prepareUnary(method, namespace, contract, offer, value, options, source, workClass, context, signal, destination, resume, route) {
1640
+ this.#check();
1641
+ const captured = captureUnaryOptions(options, context), definition = methodDefinition(method);
1642
+ const host = this.#host, cleanup = this.#cleanup, authentication = this.#authentication;
1643
+ if (this.#applicationDraining() || cleanup === undefined || authentication === undefined)
1644
+ throw new RPCProtocolError("service_unavailable");
1645
+ if (signal?.aborted)
1646
+ throw new RPCProtocolError("canceled");
1647
+ if (definition.shape !== "unary" || definition.semantics === "execution" && this.#profile !== "execution" ||
1648
+ !contract.sameEnvironment(this.#reference))
1649
+ throw new RPCProtocolError("rpc_request_binding");
1650
+ contract.checkMethod(namespace, definition);
1651
+ source.check();
1652
+ this.#check();
1653
+ if (!source.current() || this.#applicationDraining())
1654
+ throw new RPCProtocolError("source_unavailable");
1655
+ const localClass = applicationWorkClass(workClass, context);
1656
+ const inputBytes = messageInputBytes(value, definition.request.implementation, definition.request.maximum);
1657
+ const costs = rpcUnaryPreparationCharges(contract, definition, unaryResponseLimit(contract, captured), inputBytes, this.#runtimeBytes);
1658
+ if (this.#nextPreparation === (1n << 64n) - 1n)
1659
+ throw new RPCProtocolError("resource_exhausted");
1660
+ const index = ++this.#nextPreparation;
1661
+ const prepaid = initializerCallBacking(context, this, method, namespace, destination, costs, host.accounts, host.sendAccounts);
1662
+ const references = prepaid?.references ?? host.root.reserveBatch(costs.map((charge, part) => ({ accounts: part === 1 ? host.sendAccounts : host.accounts,
1663
+ owner: { ...host.owner, kind: `rpc_unary_${index}_${part}` }, charge })));
1664
+ let reserved, preparation;
1665
+ try {
1666
+ reserved = this.reserveCall(localClass, prepaid?.completion, prepaid?.call);
1667
+ preparation = new RPCUnaryPreparation(definition, namespace, contract, offer, captured, this.#operationPublication(source), resume ?? {
1668
+ check: (header, call) => {
1669
+ this.#check();
1670
+ if (this.#applicationDraining())
1671
+ throw new RPCProtocolError("service_unavailable");
1672
+ this.#selectChannel(call.workClass()).checkRequestAdmission(header, call);
1673
+ },
1674
+ current: (header, call) => !this.#closed && !this.#applicationDraining() && this.#channels.some(channel => channel?.ready() && channel.requestAdmissionCurrent(header, call)),
1675
+ start: (transfer, claim) => this.#startUnary(transfer, claim, route),
1676
+ }, host.clock, this.#deadline, this.#random, host.delivery, this.#group, authentication, cleanup, reserved.call, reserved.completion, localClass, inputBytes, this.#runtimeBytes, references, this.#localExecutionAuthority, destination, resume !== undefined, host.diagnostics);
1677
+ const original = preparation;
1678
+ this.#preparations.add(original);
1679
+ original.onDetach(() => { this.#preparations.delete(original); this.#collect(); });
1680
+ this.#check();
1681
+ return original.encode(value, context, signal).then(() => { original.checkReady(); return original; });
1682
+ }
1683
+ catch (error) {
1684
+ preparation?.close();
1685
+ reserved?.completion.close();
1686
+ reserved?.call.close();
1687
+ throw error;
1688
+ }
1689
+ finally {
1690
+ for (const reference of references)
1691
+ reference.release();
1692
+ }
1693
+ }
1694
+ #operationPublication(source) {
1695
+ let admitted = false;
1696
+ return Object.freeze({
1697
+ check: () => {
1698
+ if (!admitted) {
1699
+ source.check();
1700
+ return;
1701
+ }
1702
+ // Drain seals new admission but does not revoke the original accepted
1703
+ // operation. Its deadline, result safety and channel still govern tails.
1704
+ this.#check();
1705
+ this.#deadline.check();
1706
+ if (this.#authentication === undefined)
1707
+ throw new RPCProtocolError("source_unavailable");
1708
+ },
1709
+ current: () => admitted ? !this.#closed && this.#authentication !== undefined : source.current(),
1710
+ admitted: () => { admitted = true; source.admitted?.(); },
1711
+ });
1712
+ }
1713
+ /** SDK-local route identity. A captured execution authority cannot be
1714
+ * inferred from a later peer advertisement or changed during reselection. */
1715
+ unaryRouteAuthority() { this.#check(); return this.#localExecutionAuthority; }
1716
+ /** Adopt the original encoded queued operation into this published Session.
1717
+ * This path allocates a complete new K/Completion/result vector and never
1718
+ * invokes an encoder, generates an ID or extends the original deadline. */
1719
+ adoptControllerUnary(request, method, target, workClass, route, originalAuthority) {
1720
+ this.#check();
1721
+ const host = this.#host, channel = this.#selectChannel(workClass), authentication = this.#authentication;
1722
+ if (this.#applicationDraining() || channel === undefined || this.#cleanup === undefined || request.publication.reroute === undefined ||
1723
+ request.header.uint(7) !== 0n || request.header.kind !== "transient_unary_request" && request.header.kind !== "execution_unary_request")
1724
+ throw new RPCProtocolError("source_unavailable");
1725
+ checkServiceBindingTarget(target, authentication);
1726
+ const original = request.authentication;
1727
+ checkServiceBindingTarget(target, original);
1728
+ if (original.tenant !== authentication.tenant || original.audience !== authentication.audience || original.localRole !== authentication.localRole ||
1729
+ original.localSubject !== authentication.localSubject ||
1730
+ request.header.has(1) && (this.#profile !== "execution" || originalAuthority === undefined || this.#localExecutionAuthority !== originalAuthority))
1731
+ throw new RPCProtocolError("rpc_request_binding");
1732
+ request.contract.checkMethod(request.contract.namespace, method.facts);
1733
+ request.contract.checkRequest(request.header);
1734
+ if (!request.deadline.belongsTo(host.clock) || request.bytes.length !== request.header.payloadBytes)
1735
+ throw new RPCProtocolError("rpc_request_binding");
1736
+ request.deadline.check();
1737
+ this.#deadline.check();
1738
+ route.check();
1739
+ this.#check();
1740
+ const guard = request.publication.reroute(this.#operationPublication({
1741
+ check: () => { this.#check(); this.#deadline.check(); if (this.#applicationDraining())
1742
+ throw new RPCProtocolError("source_unavailable"); },
1743
+ current: () => !this.#closed && !this.#applicationDraining(),
1744
+ }));
1745
+ const costs = rpcUnaryExchangeCharges(request.bytes.length, Number(request.header.uint(8)), this.#runtimeBytes, request.method);
1746
+ if (this.#nextPreparation === (1n << 64n) - 1n)
1747
+ throw new RPCProtocolError("resource_exhausted");
1748
+ const index = ++this.#nextPreparation;
1749
+ const references = host.root.reserveBatch(costs.map((charge, part) => ({ accounts: part === 1 ? this.#sendAccounts(channel) : host.accounts,
1750
+ owner: { ...host.owner, kind: `rpc_unary_route_${index}_${part}` }, charge })));
1751
+ let requestPayload, reserved, exchange;
1752
+ try {
1753
+ reserved = this.reserveCall(workClass);
1754
+ requestPayload = new RPCPayload(request.bytes.length, this.#runtimeBytes, references[1]);
1755
+ requestPayload.write(0, request.bytes);
1756
+ channel.checkRequestAdmission(request.header, reserved.call);
1757
+ route.check();
1758
+ this.#check();
1759
+ if (!route.current() || !channel.requestAdmissionCurrent(request.header, reserved.call))
1760
+ throw new RPCProtocolError("source_unavailable");
1761
+ exchange = this.#startUnary({ header: request.header, contract: request.contract, request: requestPayload, deadline: request.deadline,
1762
+ guard, references: [references[0], references[2]], call: reserved.call, completion: reserved.completion, method: request.method }, undefined, route);
1763
+ return exchange;
1764
+ }
1765
+ catch (error) {
1766
+ exchange?.close();
1767
+ requestPayload?.close();
1768
+ reserved?.call.close();
1769
+ reserved?.completion.close();
1770
+ throw error;
1771
+ }
1772
+ finally {
1773
+ for (const reference of references)
1774
+ reference.release();
1775
+ }
1776
+ }
1777
+ #startUnary(transfer, claim, route) {
1778
+ this.#check();
1779
+ const host = this.#host, channel = this.#selectChannel(transfer.call.workClass()), cleanup = this.#cleanup;
1780
+ if (this.#applicationDraining() || channel === undefined)
1781
+ throw new RPCProtocolError("service_unavailable");
1782
+ let exchange, job = false;
1783
+ try {
1784
+ cleanup.startJob();
1785
+ job = true;
1786
+ exchange = new RPCUnaryExchange(transfer.header, transfer.contract, transfer.request, transfer.deadline, transfer.guard, host.delivery, host.root, this.#runtimeBytes, transfer.references, transfer.call, transfer.completion, transfer.method, this.#authentication, claim, undefined, route, transfer.diagnostic);
1787
+ const original = exchange;
1788
+ this.#unary.add(original);
1789
+ // Install original cleanup before any later safety check can fail.
1790
+ original.onNetworkCleanup(() => { this.#unary.delete(original); cleanup.finishJob(); this.#collect(); });
1791
+ job = false;
1792
+ this.#check();
1793
+ original.submit(channel);
1794
+ return original;
1795
+ }
1796
+ catch (error) {
1797
+ exchange?.close();
1798
+ if (job)
1799
+ cleanup.finishJob();
1800
+ throw error;
1801
+ }
1802
+ }
1803
+ query(targets, deadline, windows, context, delivery, renewal, preparation) {
1804
+ this.#check();
1805
+ return this.#queries.acquire(this.#acquisitions, this.#selectChannel(), targets, deadline, windows, context, delivery, renewal, preparation);
1806
+ }
1807
+ #acceptUnary(channel, request) {
1808
+ if (request.refusal !== undefined || request.input === undefined) {
1809
+ request.input?.close();
1810
+ channel.replySDK(request.ticket, request.refusal ?? "service_unavailable");
1811
+ return;
1812
+ }
1813
+ const input = request.input, host = this.#host;
1814
+ let route, permit, job;
1815
+ let references = [];
1816
+ try {
1817
+ this.#check();
1818
+ channel.checkIncoming(request.ticket);
1819
+ if (this.#applicationDraining() || this.#cleanup === undefined || this.#authentication === undefined)
1820
+ throw new RPCProtocolError("service_unavailable");
1821
+ route = input.takeRoute();
1822
+ const handler = route.handler;
1823
+ if (handler === undefined)
1824
+ throw new RPCProtocolError("method_unavailable");
1825
+ if (route.contract.semantics === "execution" && (handler.execution === undefined || this.#executionIdentity === undefined || this.#profile !== "execution"))
1826
+ throw new RPCProtocolError("service_unavailable");
1827
+ handler.check();
1828
+ input.checkDeadline();
1829
+ const costs = rpcUnaryDispatchCharges(input.header.payloadBytes, Number(input.header.uint(8)), route.definition, handler, this.#runtimeBytes);
1830
+ if (this.#nextInbound === (1n << 64n) - 1n)
1831
+ throw new RPCProtocolError("resource_exhausted");
1832
+ const id = ++this.#nextInbound;
1833
+ references = host.root.reserveBatch(costs.map((charge, index) => ({ accounts: index === 1 ? this.#sendAccounts(channel) : host.accounts,
1834
+ owner: { ...host.owner, kind: `rpc_dispatch_${id}_${index}` }, charge })));
1835
+ if (input.header.uint(7) === 1n)
1836
+ permit = this.#group.tryOrdinary(handler.options.workClass);
1837
+ handler.admit();
1838
+ job = new RPCUnaryDispatch(input, route, channel, request.ticket, this.#group, this.#authentication, host.clock, host.delivery, this.#cleanup, this.#inboundAbort.signal, this.#runtimeBytes, references, permit, this.#routes, this.#executionIdentity, this.#checkpointPolicy, this.#maintenanceOwner, host.diagnostics);
1839
+ route = undefined;
1840
+ permit = undefined;
1841
+ const original = job;
1842
+ this.#inbound.add(original);
1843
+ original.onDetach(() => { this.#inbound.delete(original); this.#collect(); });
1844
+ original.start();
1845
+ }
1846
+ catch (error) {
1847
+ job?.close();
1848
+ route?.close();
1849
+ permit?.release();
1850
+ input.close();
1851
+ const code = error instanceof ResourceError || error instanceof Error && error.message === "would_block" ? "resource_exhausted"
1852
+ : error instanceof TimeError ? "deadline_exceeded"
1853
+ : error instanceof RPCProtocolError && ["permission_denied", "resource_exhausted", "method_unavailable", "service_unavailable"].includes(error.code) ? error.code : "service_failed";
1854
+ channel.replySDK(request.ticket, code);
1855
+ }
1856
+ finally {
1857
+ for (const reference of references)
1858
+ reference.release();
1859
+ }
1860
+ }
1861
+ #acceptResultRead(channel, request) {
1862
+ const input = request.input;
1863
+ let reference, payload, entered = false;
1864
+ try {
1865
+ this.#check();
1866
+ channel.checkIncoming(request.ticket);
1867
+ if (this.#applicationDraining() || this.#resultReadCodec === undefined || this.#resultReadBusy)
1868
+ throw new RPCProtocolError("service_unavailable");
1869
+ this.#resultReadBusy = entered = true;
1870
+ const borrow = input.borrow();
1871
+ let target;
1872
+ try {
1873
+ target = this.#resultReadCodec.target(borrow.bytes);
1874
+ }
1875
+ finally {
1876
+ borrow.release();
1877
+ }
1878
+ const deadline = input.forkDeadline();
1879
+ const access = Object.freeze({ check: () => { deadline.check(); this.#authorizeManagement(target, false, false); }, current: () => !this.#closed });
1880
+ access.check();
1881
+ const history = this.#histories.get(target.namespace);
1882
+ if (history === undefined)
1883
+ throw new RPCProtocolError("service_unavailable");
1884
+ if (this.#nextInbound === (1n << 64n) - 1n)
1885
+ throw new RPCProtocolError("resource_exhausted");
1886
+ const host = this.#host;
1887
+ reference = host.root.reserve({ accounts: host.accounts, owner: { ...host.owner, kind: `rpc_result_pin_${++this.#nextInbound}` }, charge: executionResultReadCharge(this.#runtimeBytes) });
1888
+ const read = history.captureResult(target, access, reference, this.#runtimeBytes);
1889
+ payload = read.payload;
1890
+ read.guard.check();
1891
+ channel.queueResultRead(request.ticket, payload, read.guard);
1892
+ payload = undefined;
1893
+ }
1894
+ catch (error) {
1895
+ const code = error instanceof ResourceError ? "resource_exhausted" : error instanceof TimeError ? "deadline_exceeded" :
1896
+ error instanceof RPCProtocolError && ["permission_denied", "resource_exhausted", "operation_conflict", "result_expired", "deadline_exceeded"].includes(error.code) ? error.code : "service_unavailable";
1897
+ channel.replySDK(request.ticket, code);
1898
+ }
1899
+ finally {
1900
+ payload?.release();
1901
+ reference?.release();
1902
+ input.close();
1903
+ if (entered)
1904
+ this.#resultReadBusy = false;
1905
+ this.#collect();
1906
+ }
1907
+ }
1908
+ async #dispatch(channel) {
1909
+ try {
1910
+ while (!this.#closed) {
1911
+ let count = 0;
1912
+ for (; count < 8; count++) {
1913
+ const request = channel.nextRequest();
1914
+ if (request === undefined)
1915
+ break;
1916
+ if (this.#queries.accept(channel, request))
1917
+ continue;
1918
+ if (request.refusal === undefined && request.input?.header.kind === "read_result_request") {
1919
+ this.#acceptResultRead(channel, request);
1920
+ continue;
1921
+ }
1922
+ this.#acceptUnary(channel, request);
1923
+ }
1924
+ if (count < 8)
1925
+ await channel.waitRequests();
1926
+ else
1927
+ await new Promise(resolve => {
1928
+ const timer = setTimeout(() => { this.#turns.delete(channel); resolve(); }, 0);
1929
+ this.#turns.set(channel, { timer, resolve });
1930
+ });
1931
+ }
1932
+ }
1933
+ catch {
1934
+ channel.close();
1935
+ }
1936
+ finally {
1937
+ this.#dispatching.delete(channel);
1938
+ this.#channelsChanged?.();
1939
+ this.#collect();
1940
+ }
1941
+ }
1942
+ /** Peer GOAWAY seals new application work while retaining the original
1943
+ * management owner. Accepted RPC/Notify channels still finish their input
1944
+ * and output tails on the same owners; no new deadline or channel is made. */
1945
+ peerGoaway() {
1946
+ this.#check();
1947
+ if (this.#peerDraining)
1948
+ return;
1949
+ this.#peerDraining = true;
1950
+ this.#preaccepted?.close();
1951
+ for (const preparation of [...this.#preparations])
1952
+ preparation.close();
1953
+ for (const preparation of [...this.#notifyPreparations])
1954
+ preparation.close();
1955
+ this.#queries.drain();
1956
+ this.#drainApplicationChannels();
1957
+ }
1958
+ drain(deadline) {
1959
+ this.#check();
1960
+ if (this.#draining)
1961
+ return;
1962
+ this.#draining = true;
1963
+ this.#preaccepted?.close();
1964
+ // A prepared operation has not crossed the local OPEN/NOTIFY admission
1965
+ // gate. Drain seals that gate and releases such dormant owners; already
1966
+ // submitted exchanges remain attached to their original channel and are
1967
+ // allowed to finish under the Session drain proof.
1968
+ for (const preparation of [...this.#preparations])
1969
+ preparation.close();
1970
+ for (const preparation of [...this.#notifyPreparations])
1971
+ preparation.close();
1972
+ this.#queries.drain();
1973
+ if (deadline !== undefined)
1974
+ this.#management?.drain(deadline);
1975
+ for (const wake of this.#managementWaiters)
1976
+ wake();
1977
+ this.drainChannels();
1978
+ }
1979
+ #drainApplicationChannels() {
1980
+ if (this.#closed)
1981
+ return;
1982
+ for (const channel of this.#channels)
1983
+ channel?.drain();
1984
+ for (const channel of this.#notifyChannels)
1985
+ channel?.drain();
1986
+ }
1987
+ drainChannels() {
1988
+ if (!this.#draining || this.#closed)
1989
+ return;
1990
+ this.#drainApplicationChannels();
1991
+ }
1992
+ businessPending() {
1993
+ return this.#group?.businessPending() === true || this.#channelGroups.some(group => group.businessPending()) ||
1994
+ this.#notifyGroups.some(group => group.businessPending()) || this.#subscribers?.businessPending() === true ||
1995
+ this.#channels.some(channel => channel?.businessPending()) || this.#notifyChannels.some(channel => channel?.businessPending()) ||
1996
+ [...this.#notificationBusinesses.values()].some(registration => !registration.idle);
1997
+ }
1998
+ finishBusinessDrain() {
1999
+ if (!this.#draining || this.#closed || this.#managementUnavailable)
2000
+ return;
2001
+ this.managementFailed();
2002
+ }
2003
+ onCleanup(callback) {
2004
+ if (this.#cleaned !== undefined)
2005
+ throw new RPCProtocolError("rpc_owner");
2006
+ if (this.#reference === undefined)
2007
+ callback();
2008
+ else
2009
+ this.#cleaned = callback;
2010
+ }
2011
+ close() {
2012
+ if (this.#closed)
2013
+ return;
2014
+ this.#closed = true;
2015
+ this.#closing = true;
2016
+ try {
2017
+ for (const turn of this.#turns.values()) {
2018
+ clearTimeout(turn.timer);
2019
+ turn.resolve();
2020
+ }
2021
+ this.#turns.clear();
2022
+ this.#channelsChanged = undefined;
2023
+ this.#managementBusinessAvailable = undefined;
2024
+ this.#inboundAbort.abort();
2025
+ this.#managementLease?.release();
2026
+ this.#managementLease = undefined;
2027
+ this.managementFailed();
2028
+ this.#management?.close();
2029
+ this.#managementGroup?.close();
2030
+ this.#managementPosition?.closeAfterUse();
2031
+ this.#managementChanged = undefined;
2032
+ for (const position of this.#managementPositions)
2033
+ position.closeAfterUse();
2034
+ for (const reference of this.#managementRefs)
2035
+ reference.release();
2036
+ this.#managementRefs.length = 0;
2037
+ for (const binding of this.#serviceClients)
2038
+ binding.close();
2039
+ this.#serviceClients.clear();
2040
+ for (const job of this.#inbound)
2041
+ job.close();
2042
+ this.#inbound.clear();
2043
+ for (const preparation of this.#preparations)
2044
+ preparation.close();
2045
+ for (const stream of this.#streaming)
2046
+ stream.networkClosed();
2047
+ for (const dispatch of this.#streamDispatches)
2048
+ dispatch.close();
2049
+ for (const dispatch of this.#resumeDispatches)
2050
+ dispatch.close();
2051
+ this.#preaccepted?.close();
2052
+ this.#initialStreams?.close();
2053
+ this.#initialStreams = undefined;
2054
+ this.#streamOpener = undefined;
2055
+ this.#session = undefined;
2056
+ this.#streamHandlers.clear();
2057
+ for (const preparation of this.#notifyPreparations)
2058
+ preparation.close();
2059
+ for (const access of this.#notificationAccess.values())
2060
+ access.close();
2061
+ this.#notificationAccess.clear();
2062
+ for (const registration of this.#notificationBusinesses.values())
2063
+ registration.close("source_closed");
2064
+ this.#notificationBusinesses.clear();
2065
+ this.#subscribers?.close();
2066
+ this.#subscribers = undefined;
2067
+ for (const channel of this.#notifyChannels)
2068
+ channel?.close();
2069
+ for (const refs of this.#notifyRefs) {
2070
+ for (const ref of refs)
2071
+ ref?.release();
2072
+ refs.length = 0;
2073
+ }
2074
+ for (const position of this.#notifyPositions)
2075
+ position.closeAfterUse();
2076
+ for (const group of this.#notifyGroups)
2077
+ group.close();
2078
+ for (const exchange of this.#unary)
2079
+ exchange.endSession();
2080
+ this.#queries?.close();
2081
+ for (const channel of this.#channels)
2082
+ channel?.close();
2083
+ this.#inputs?.close();
2084
+ this.#access?.close();
2085
+ this.#routes?.close();
2086
+ for (const positions of this.#channelPositions)
2087
+ for (const position of positions)
2088
+ position?.closeAfterUse();
2089
+ this.#network?.close();
2090
+ this.#network?.flushOutputEvents();
2091
+ this.#calls?.close();
2092
+ this.#completion?.close();
2093
+ // Accepted event subscriptions still own ordinary cleanup duties. Keep the
2094
+ // original executor service alive until their real disposer exits.
2095
+ if (this.#streamDispatches.size === 0)
2096
+ this.#group?.retireResults();
2097
+ for (const group of this.#channelGroups)
2098
+ group.close();
2099
+ }
2100
+ finally {
2101
+ this.#closing = false;
2102
+ this.#collect();
2103
+ }
2104
+ }
2105
+ #collect() {
2106
+ if (!this.#closed || this.#closing || this.#collecting || this.#dispatching.size !== 0 || this.#resultReadBusy)
2107
+ return;
2108
+ this.#collecting = true;
2109
+ try {
2110
+ if (this.#management?.cleanupComplete() === false || this.#managementPosition?.cleanupComplete() === false || this.#managementGroup?.cleanupComplete() === false ||
2111
+ this.#managementPositions.some(position => !position.cleanupComplete()))
2112
+ return;
2113
+ if (this.#notifyPreparations.size !== 0 || this.#notifyChannels.some(channel => channel?.cleanupComplete() === false) ||
2114
+ this.#notifyPositions.some(position => !position.cleanupComplete()))
2115
+ return;
2116
+ if (this.#preaccepted?.cleanupComplete() === false || this.#preparations.size !== 0 || this.#streaming.size !== 0 || this.#streamDispatches.size !== 0 || this.#resumeDispatches.size !== 0 || this.#unary.size !== 0 || this.#channels.some(channel => channel?.cleanupComplete() === false) || this.#queries?.cleanupComplete() === false || this.#inputs?.cleanupComplete() === false ||
2117
+ this.#network?.cleanupComplete() === false || this.#channelGroups.some(group => !group.cleanupComplete()) ||
2118
+ this.#channelPositions.some(positions => positions.some(position => !position.cleanupComplete())))
2119
+ return;
2120
+ this.#notifyChannels.length = this.#notifyPositions.length = this.#notifyGroups.length = 0;
2121
+ this.#management = undefined;
2122
+ this.#managementPosition = undefined;
2123
+ this.#managementGroup = undefined;
2124
+ this.#histories.clear();
2125
+ this.#localExecutionAuthority = undefined;
2126
+ this.#referenceTargets = [];
2127
+ this.#executionDelegations = [];
2128
+ this.#managementPositions.length = 0;
2129
+ this.#resultReadCodec?.close();
2130
+ this.#resultReadCodec = undefined;
2131
+ this.#resultReadReference?.release();
2132
+ this.#resultReadReference = undefined;
2133
+ this.#resultReadBuffer.fill(0);
2134
+ this.#resultReadBuffer = new Uint8Array();
2135
+ this.#channels.length = this.#channelGroups.length = this.#channelPositions.length = 0;
2136
+ this.#preaccepted = undefined;
2137
+ this.#queries = undefined;
2138
+ this.#inputs = undefined;
2139
+ this.#access = undefined;
2140
+ this.#routes = undefined;
2141
+ this.#network = undefined;
2142
+ this.#calls = undefined;
2143
+ this.#completion = undefined;
2144
+ this.#group = undefined;
2145
+ this.#acquisitions = undefined;
2146
+ // Complete unary results retain only their original compact K and
2147
+ // Completion owners. Their eventual release does not hold Session core.
2148
+ this.#deadline = undefined;
2149
+ this.#host = undefined;
2150
+ this.#cleanup = undefined;
2151
+ this.#authentication = undefined;
2152
+ this.#executionIdentity = undefined;
2153
+ this.#random = undefined;
2154
+ this.#bindings = undefined;
2155
+ this.#observer?.();
2156
+ this.#observer = undefined;
2157
+ this.#reference?.release();
2158
+ this.#reference = undefined;
2159
+ const cleaned = this.#cleaned;
2160
+ this.#cleaned = undefined;
2161
+ cleaned?.();
2162
+ }
2163
+ finally {
2164
+ this.#collecting = false;
2165
+ }
2166
+ }
2167
+ cleanupComplete() { this.#collect(); return this.#reference === undefined; }
2168
+ }
2169
+ Object.freeze(RPCApplicationAdmission.prototype);
2170
+ Object.freeze(RPCApplicationAdmission);