@hydranium/protocol 1.0.0-next.38 → 1.0.0-next.381

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 (298) hide show
  1. package/README.md +44 -83
  2. package/lib/abstract-logger.d.ts +11 -0
  3. package/lib/abstract-logger.d.ts.map +1 -1
  4. package/lib/abstract-logger.js +16 -0
  5. package/lib/abstract-logger.js.map +1 -1
  6. package/lib/client/data-connection.d.ts +303 -0
  7. package/lib/client/data-connection.d.ts.map +1 -0
  8. package/lib/client/data-connection.js +534 -0
  9. package/lib/client/data-connection.js.map +1 -0
  10. package/lib/client/data-events.d.ts +18 -1
  11. package/lib/client/data-events.d.ts.map +1 -1
  12. package/lib/client/data-events.js +26 -0
  13. package/lib/client/data-events.js.map +1 -1
  14. package/lib/client/data-port.d.ts +34 -24
  15. package/lib/client/data-port.d.ts.map +1 -1
  16. package/lib/client/data-session.d.ts +694 -89
  17. package/lib/client/data-session.d.ts.map +1 -1
  18. package/lib/client/data-session.js +1158 -115
  19. package/lib/client/data-session.js.map +1 -1
  20. package/lib/client/index.d.ts +15 -9
  21. package/lib/client/index.d.ts.map +1 -1
  22. package/lib/client/index.js +15 -9
  23. package/lib/client/index.js.map +1 -1
  24. package/lib/client/message-relay.d.ts +6 -4
  25. package/lib/client/message-relay.d.ts.map +1 -1
  26. package/lib/client/message-relay.js +4 -4
  27. package/lib/client/message-relay.js.map +1 -1
  28. package/lib/client/post-message-transport.d.ts +69 -3
  29. package/lib/client/post-message-transport.d.ts.map +1 -1
  30. package/lib/client/post-message-transport.js +175 -1
  31. package/lib/client/post-message-transport.js.map +1 -1
  32. package/lib/client/rpc-connection.d.ts +173 -0
  33. package/lib/client/rpc-connection.d.ts.map +1 -0
  34. package/lib/client/rpc-connection.js +225 -0
  35. package/lib/client/rpc-connection.js.map +1 -0
  36. package/lib/client/worker-handshake.d.ts +94 -0
  37. package/lib/client/worker-handshake.d.ts.map +1 -0
  38. package/lib/client/worker-handshake.js +51 -0
  39. package/lib/client/worker-handshake.js.map +1 -0
  40. package/lib/client-ids.d.ts +45 -0
  41. package/lib/client-ids.d.ts.map +1 -0
  42. package/lib/client-ids.js +48 -0
  43. package/lib/client-ids.js.map +1 -0
  44. package/lib/clock.d.ts +50 -10
  45. package/lib/clock.d.ts.map +1 -1
  46. package/lib/clock.js +36 -1
  47. package/lib/clock.js.map +1 -1
  48. package/lib/console-logger.d.ts +23 -0
  49. package/lib/console-logger.d.ts.map +1 -0
  50. package/lib/console-logger.js +39 -0
  51. package/lib/console-logger.js.map +1 -0
  52. package/lib/data/data-protocol-methods.d.ts +4 -4
  53. package/lib/data/data-protocol-methods.d.ts.map +1 -1
  54. package/lib/data/data-protocol-methods.js +13 -1
  55. package/lib/data/data-protocol-methods.js.map +1 -1
  56. package/lib/data/data-server-protocol.d.ts +176 -49
  57. package/lib/data/data-server-protocol.d.ts.map +1 -1
  58. package/lib/data/events.d.ts +144 -33
  59. package/lib/data/events.d.ts.map +1 -1
  60. package/lib/data/requests.d.ts +84 -11
  61. package/lib/data/requests.d.ts.map +1 -1
  62. package/lib/debouncer.d.ts +7 -4
  63. package/lib/debouncer.d.ts.map +1 -1
  64. package/lib/debouncer.js +10 -10
  65. package/lib/debouncer.js.map +1 -1
  66. package/lib/errors.d.ts +243 -41
  67. package/lib/errors.d.ts.map +1 -1
  68. package/lib/errors.js +400 -55
  69. package/lib/errors.js.map +1 -1
  70. package/lib/format-log-arg.d.ts +33 -0
  71. package/lib/format-log-arg.d.ts.map +1 -0
  72. package/lib/format-log-arg.js +158 -0
  73. package/lib/format-log-arg.js.map +1 -0
  74. package/lib/glsp-edits-settled-actions.d.ts +54 -0
  75. package/lib/glsp-edits-settled-actions.d.ts.map +1 -0
  76. package/lib/glsp-edits-settled-actions.js +28 -0
  77. package/lib/glsp-edits-settled-actions.js.map +1 -0
  78. package/lib/glsp-request-model-args.d.ts +16 -0
  79. package/lib/glsp-request-model-args.d.ts.map +1 -0
  80. package/lib/glsp-request-model-args.js +19 -0
  81. package/lib/glsp-request-model-args.js.map +1 -0
  82. package/lib/glsp-save-model-actions.d.ts +55 -0
  83. package/lib/glsp-save-model-actions.d.ts.map +1 -0
  84. package/lib/glsp-save-model-actions.js +28 -0
  85. package/lib/glsp-save-model-actions.js.map +1 -0
  86. package/lib/index.d.ts +11 -0
  87. package/lib/index.d.ts.map +1 -1
  88. package/lib/index.js +11 -0
  89. package/lib/index.js.map +1 -1
  90. package/lib/latency-collector.d.ts +10 -4
  91. package/lib/latency-collector.d.ts.map +1 -1
  92. package/lib/latency-collector.js +2 -0
  93. package/lib/latency-collector.js.map +1 -1
  94. package/lib/logger.d.ts +38 -7
  95. package/lib/logger.d.ts.map +1 -1
  96. package/lib/logger.js +42 -4
  97. package/lib/logger.js.map +1 -1
  98. package/lib/messages/index.d.ts +4 -2
  99. package/lib/messages/index.d.ts.map +1 -1
  100. package/lib/messages/index.js +17 -4
  101. package/lib/messages/index.js.map +1 -1
  102. package/lib/messages/primitives.d.ts +59 -4
  103. package/lib/messages/primitives.d.ts.map +1 -1
  104. package/lib/messages/primitives.js +97 -4
  105. package/lib/messages/primitives.js.map +1 -1
  106. package/lib/model-server.d.ts +60 -13
  107. package/lib/model-server.d.ts.map +1 -1
  108. package/lib/model-server.js +4 -2
  109. package/lib/model-server.js.map +1 -1
  110. package/lib/model-service/base-version.d.ts +67 -0
  111. package/lib/model-service/base-version.d.ts.map +1 -0
  112. package/lib/model-service/base-version.js +44 -0
  113. package/lib/model-service/base-version.js.map +1 -0
  114. package/lib/model-service/index.d.ts +1 -1
  115. package/lib/model-service/index.d.ts.map +1 -1
  116. package/lib/model-service/index.js +4 -5
  117. package/lib/model-service/index.js.map +1 -1
  118. package/lib/model-service/reference-candidate.d.ts +5 -3
  119. package/lib/model-service/reference-candidate.d.ts.map +1 -1
  120. package/lib/node/index.d.ts +10 -0
  121. package/lib/node/index.d.ts.map +1 -0
  122. package/lib/node/index.js +29 -0
  123. package/lib/node/index.js.map +1 -0
  124. package/lib/node/process-memory.d.ts +66 -0
  125. package/lib/node/process-memory.d.ts.map +1 -0
  126. package/lib/node/process-memory.js +291 -0
  127. package/lib/node/process-memory.js.map +1 -0
  128. package/lib/noop-logger.d.ts.map +1 -1
  129. package/lib/noop-logger.js.map +1 -1
  130. package/lib/observable-value.js.map +1 -1
  131. package/lib/patch-merge.d.ts +63 -35
  132. package/lib/patch-merge.d.ts.map +1 -1
  133. package/lib/patch-merge.js +171 -25
  134. package/lib/patch-merge.js.map +1 -1
  135. package/lib/pending-work-tracker.d.ts +30 -0
  136. package/lib/pending-work-tracker.d.ts.map +1 -0
  137. package/lib/pending-work-tracker.js +47 -0
  138. package/lib/pending-work-tracker.js.map +1 -0
  139. package/lib/profile-session.d.ts +24 -8
  140. package/lib/profile-session.d.ts.map +1 -1
  141. package/lib/profile-session.js +13 -4
  142. package/lib/profile-session.js.map +1 -1
  143. package/lib/profiling.d.ts +15 -2
  144. package/lib/profiling.d.ts.map +1 -1
  145. package/lib/profiling.js.map +1 -1
  146. package/lib/project.d.ts +6 -2
  147. package/lib/project.d.ts.map +1 -1
  148. package/lib/project.js.map +1 -1
  149. package/lib/random-uuid.d.ts +14 -0
  150. package/lib/random-uuid.d.ts.map +1 -0
  151. package/lib/random-uuid.js +24 -0
  152. package/lib/random-uuid.js.map +1 -0
  153. package/lib/reconcile-write.d.ts +70 -0
  154. package/lib/reconcile-write.d.ts.map +1 -0
  155. package/lib/reconcile-write.js +69 -0
  156. package/lib/reconcile-write.js.map +1 -0
  157. package/lib/rpc/bind-rpc-methods.d.ts +6 -2
  158. package/lib/rpc/bind-rpc-methods.d.ts.map +1 -1
  159. package/lib/rpc/bind-rpc-methods.js +17 -7
  160. package/lib/rpc/bind-rpc-methods.js.map +1 -1
  161. package/lib/rpc/create-rpc-proxy.d.ts +3 -0
  162. package/lib/rpc/create-rpc-proxy.d.ts.map +1 -1
  163. package/lib/rpc/create-rpc-proxy.js +6 -1
  164. package/lib/rpc/create-rpc-proxy.js.map +1 -1
  165. package/lib/rpc/index.d.ts +1 -0
  166. package/lib/rpc/index.d.ts.map +1 -1
  167. package/lib/rpc/index.js +1 -0
  168. package/lib/rpc/index.js.map +1 -1
  169. package/lib/rpc/send-by-method-name.d.ts +76 -0
  170. package/lib/rpc/send-by-method-name.d.ts.map +1 -0
  171. package/lib/rpc/send-by-method-name.js +120 -0
  172. package/lib/rpc/send-by-method-name.js.map +1 -0
  173. package/lib/rpc/wire-prefix.js.map +1 -1
  174. package/lib/save-text-document.d.ts +40 -0
  175. package/lib/save-text-document.d.ts.map +1 -0
  176. package/lib/save-text-document.js +34 -0
  177. package/lib/save-text-document.js.map +1 -0
  178. package/lib/testing/catalogue-audit.js.map +1 -1
  179. package/lib/testing/data-doubles.d.ts +41 -12
  180. package/lib/testing/data-doubles.d.ts.map +1 -1
  181. package/lib/testing/data-doubles.js +56 -8
  182. package/lib/testing/data-doubles.js.map +1 -1
  183. package/lib/testing/fake-clock.d.ts +17 -2
  184. package/lib/testing/fake-clock.d.ts.map +1 -1
  185. package/lib/testing/fake-clock.js +61 -46
  186. package/lib/testing/fake-clock.js.map +1 -1
  187. package/lib/testing/index.d.ts +1 -0
  188. package/lib/testing/index.d.ts.map +1 -1
  189. package/lib/testing/index.js +4 -3
  190. package/lib/testing/index.js.map +1 -1
  191. package/lib/testing/node/duplex-connection.d.ts.map +1 -1
  192. package/lib/testing/node/duplex-connection.js +3 -2
  193. package/lib/testing/node/duplex-connection.js.map +1 -1
  194. package/lib/testing/node/duplex-stream.js.map +1 -1
  195. package/lib/testing/node/index.d.ts +1 -0
  196. package/lib/testing/node/index.d.ts.map +1 -1
  197. package/lib/testing/node/index.js +2 -2
  198. package/lib/testing/node/index.js.map +1 -1
  199. package/lib/testing/node/message-port-pair.d.ts +25 -0
  200. package/lib/testing/node/message-port-pair.d.ts.map +1 -0
  201. package/lib/testing/node/message-port-pair.js +26 -0
  202. package/lib/testing/node/message-port-pair.js.map +1 -0
  203. package/lib/testing/transfer-node-builder.d.ts +81 -0
  204. package/lib/testing/transfer-node-builder.d.ts.map +1 -0
  205. package/lib/testing/transfer-node-builder.js +47 -0
  206. package/lib/testing/transfer-node-builder.js.map +1 -0
  207. package/lib/testing/wait-for.d.ts +9 -3
  208. package/lib/testing/wait-for.d.ts.map +1 -1
  209. package/lib/testing/wait-for.js +57 -11
  210. package/lib/testing/wait-for.js.map +1 -1
  211. package/lib/tracer.d.ts.map +1 -1
  212. package/lib/tracer.js +5 -9
  213. package/lib/tracer.js.map +1 -1
  214. package/lib/transfer-diagnostic.d.ts +11 -0
  215. package/lib/transfer-diagnostic.d.ts.map +1 -1
  216. package/lib/transfer-diagnostic.js +17 -0
  217. package/lib/transfer-diagnostic.js.map +1 -1
  218. package/lib/transfer-document.d.ts +96 -32
  219. package/lib/transfer-document.d.ts.map +1 -1
  220. package/lib/transfer-document.js +17 -9
  221. package/lib/transfer-document.js.map +1 -1
  222. package/lib/transfer-element.d.ts +4 -4
  223. package/lib/types.d.ts +32 -0
  224. package/lib/types.d.ts.map +1 -0
  225. package/lib/{model-service/args.js → types.js} +2 -2
  226. package/lib/types.js.map +1 -0
  227. package/lib/uri.d.ts.map +1 -1
  228. package/lib/uri.js.map +1 -1
  229. package/lib/util.d.ts +8 -2
  230. package/lib/util.d.ts.map +1 -1
  231. package/lib/util.js +32 -4
  232. package/lib/util.js.map +1 -1
  233. package/package.json +24 -40
  234. package/src/abstract-logger.ts +18 -0
  235. package/src/client/data-connection.ts +654 -0
  236. package/src/client/data-events.ts +38 -1
  237. package/src/client/data-port.ts +36 -25
  238. package/src/client/data-session.ts +1479 -137
  239. package/src/client/index.ts +15 -9
  240. package/src/client/message-relay.ts +6 -4
  241. package/src/client/post-message-transport.ts +224 -4
  242. package/src/client/rpc-connection.ts +302 -0
  243. package/src/client/worker-handshake.ts +121 -0
  244. package/src/client-ids.ts +49 -0
  245. package/src/clock.ts +68 -10
  246. package/src/console-logger.ts +39 -0
  247. package/src/data/data-protocol-methods.ts +14 -4
  248. package/src/data/data-server-protocol.ts +203 -49
  249. package/src/data/events.ts +150 -33
  250. package/src/data/requests.ts +90 -11
  251. package/src/debouncer.ts +11 -11
  252. package/src/errors.ts +500 -65
  253. package/src/format-log-arg.ts +176 -0
  254. package/src/glsp-edits-settled-actions.ts +62 -0
  255. package/src/glsp-request-model-args.ts +16 -0
  256. package/src/glsp-save-model-actions.ts +64 -0
  257. package/src/index.ts +11 -0
  258. package/src/latency-collector.ts +10 -3
  259. package/src/logger.ts +44 -8
  260. package/src/messages/index.ts +12 -2
  261. package/src/messages/primitives.ts +129 -5
  262. package/src/model-server.ts +64 -19
  263. package/src/model-service/base-version.ts +75 -0
  264. package/src/model-service/index.ts +4 -5
  265. package/src/model-service/reference-candidate.ts +5 -3
  266. package/src/node/index.ts +14 -0
  267. package/src/node/process-memory.ts +299 -0
  268. package/src/patch-merge.ts +230 -45
  269. package/src/pending-work-tracker.ts +47 -0
  270. package/src/profile-session.ts +31 -11
  271. package/src/profiling.ts +15 -2
  272. package/src/project.ts +6 -2
  273. package/src/random-uuid.ts +21 -0
  274. package/src/reconcile-write.ts +131 -0
  275. package/src/rpc/README.md +6 -6
  276. package/src/rpc/bind-rpc-methods.ts +18 -8
  277. package/src/rpc/create-rpc-proxy.ts +6 -1
  278. package/src/rpc/index.ts +1 -0
  279. package/src/rpc/send-by-method-name.ts +140 -0
  280. package/src/save-text-document.ts +39 -0
  281. package/src/testing/data-doubles.ts +141 -19
  282. package/src/testing/fake-clock.ts +76 -48
  283. package/src/testing/index.ts +4 -3
  284. package/src/testing/node/duplex-connection.ts +3 -2
  285. package/src/testing/node/index.ts +2 -2
  286. package/src/testing/node/message-port-pair.ts +40 -0
  287. package/src/testing/transfer-node-builder.ts +107 -0
  288. package/src/testing/wait-for.ts +61 -13
  289. package/src/tracer.ts +5 -9
  290. package/src/transfer-diagnostic.ts +17 -0
  291. package/src/transfer-document.ts +116 -34
  292. package/src/transfer-element.ts +4 -4
  293. package/src/types.ts +30 -0
  294. package/src/util.ts +33 -6
  295. package/lib/model-service/args.d.ts +0 -64
  296. package/lib/model-service/args.d.ts.map +0 -1
  297. package/lib/model-service/args.js.map +0 -1
  298. package/src/model-service/args.ts +0 -67
@@ -0,0 +1,654 @@
1
+ /********************************************************************************
2
+ * Copyright (c) 2026 CrossBreeze, EclipseSource and others.
3
+ *
4
+ * This program and the accompanying materials are made available under the
5
+ * terms of the MIT License which is available in the project root.
6
+ *
7
+ * SPDX-License-Identifier: MIT
8
+ ********************************************************************************/
9
+
10
+ import { Disposable, Emitter, type Event } from 'vscode-jsonrpc';
11
+ import { FRAMEWORK_CLIENT_IDS, UNKNOWN_CLIENT_ID } from '../client-ids';
12
+ import {
13
+ DATA_CLIENT_PROTOCOL_METHODS,
14
+ DATA_SERVER_WIRE_PREFIX,
15
+ type DataClientProtocol,
16
+ type DataServerProtocol,
17
+ type DiagnosticOf,
18
+ type ProjectOf,
19
+ type TransferDocumentDeletedEvent,
20
+ type TransferDocumentDirtyChangedEvent,
21
+ type TransferDocumentUpdatedEvent
22
+ } from '../data';
23
+ import type { TransferWatchedDocument } from '../transfer-document';
24
+ import { DuplicateClientIdError, ReservedClientIdError } from '../errors';
25
+ import type { Logger } from '../logger';
26
+ import { defineMessage, describeError, describeErrorWithStack, resolve } from '../messages/primitives';
27
+ import { NoopLogger } from '../noop-logger';
28
+ import { randomUuid } from '../random-uuid';
29
+ import type { TransferElement } from '../transfer-element';
30
+ import { DataEvents } from './data-events';
31
+ import type { DataPort } from './data-port';
32
+ import { DataSession, type DataSessionFactory } from './data-session';
33
+ import { RpcConnection, type RpcConnectionGeneration, type RpcConnectionLifecycle } from './rpc-connection';
34
+
35
+ /**
36
+ * A watch {@link DataConnection.watchDocument} keeps could not be sent again to
37
+ * a connection that became ready after a drop; the next one sends it again.
38
+ */
39
+ export const DATA_CONNECTION_WATCH_RESTORE_FAILED = defineMessage(
40
+ 'hydranium/protocol/data-connection-watch-restore-failed',
41
+ 'Could not watch {uri} again after reconnecting to the data server: {detail}'
42
+ );
43
+
44
+ /**
45
+ * A session's restore threw when its connection came back; the connection
46
+ * went on restoring the others.
47
+ */
48
+ export const DATA_CONNECTION_SESSION_RESTORE_FAILED = defineMessage(
49
+ 'hydranium/protocol/data-connection-session-restore-failed',
50
+ 'Could not restore a session after reconnecting to the data server: {detail}'
51
+ );
52
+
53
+ /**
54
+ * A watch {@link DataConnection.watchDocument} keeps, with what the client last
55
+ * heard of its document: a reconnect whose watch answers that no document
56
+ * exists tells the client of a deletion only where it had heard one did.
57
+ */
58
+ export interface DataConnectionWatch {
59
+ /** The URI as the caller named it, which the watch is sent under. */
60
+ readonly uri: string;
61
+ /** The key a watch of it last answered with, which events name; absent until one answered. */
62
+ readonly serverUri?: string;
63
+ /** Whether the client last heard that the document exists. */
64
+ readonly exists: boolean;
65
+ }
66
+
67
+ /** What an event heard while a watch was in flight said of its document, and the event's position. */
68
+ export interface DataConnectionHeardEvent {
69
+ readonly exists: boolean;
70
+ readonly sequence: number;
71
+ }
72
+
73
+ /** Whether the document exists, by the newer of a watch's answer and an event heard while the watch was in flight. */
74
+ function existsAfter(heard: DataConnectionHeardEvent | undefined, answer: TransferWatchedDocument): boolean {
75
+ return heard !== undefined && heard.sequence > answer.sequence ? heard.exists : answer.exists;
76
+ }
77
+
78
+ /** Options for {@link DataConnection}. */
79
+ export interface DataConnectionOptions<
80
+ TTransfer extends TransferElement = TransferElement,
81
+ TServer extends DataServerProtocol<TTransfer, DiagnosticOf<TServer>> = DataServerProtocol<TTransfer>
82
+ > extends RpcConnectionLifecycle {
83
+ /**
84
+ * Wire namespace the server is addressed under. Defaults to the
85
+ * framework's {@link DATA_SERVER_WIRE_PREFIX}, which is what an unmodified
86
+ * `DataServer` binds. Override only alongside the server's own
87
+ * `methodNamespace` option — a mismatch turns every request into
88
+ * "Unhandled method" rather than failing at wire-up.
89
+ */
90
+ readonly methodNamespace?: string;
91
+ /** Builds the sessions `createSession` hands out. Defaults to a plain {@link DataSession}. */
92
+ readonly sessionFactory?: DataSessionFactory<TTransfer, TServer>;
93
+ }
94
+
95
+ /** {@link DataConnectionOptions} for a client that does not speak {@link DataClientProtocol}. */
96
+ export interface DataConnectionOptionsWithMethods<
97
+ TClient extends object,
98
+ TTransfer extends TransferElement = TransferElement,
99
+ TServer extends DataServerProtocol<TTransfer, DiagnosticOf<TServer>> = DataServerProtocol<TTransfer>
100
+ > extends DataConnectionOptions<TTransfer, TServer> {
101
+ /**
102
+ * Method names of the client to bind as inbound handlers. Declare it
103
+ * `as const satisfies ReadonlyArray<keyof YourClient & string>` so the list
104
+ * cannot drift from the interface.
105
+ */
106
+ readonly clientMethods: readonly (keyof TClient & string)[];
107
+ }
108
+
109
+ /**
110
+ * Trailing constructor arguments, required only when the client cannot take
111
+ * the framework's default method list.
112
+ *
113
+ * `bindRpcMethods` throws for a name the target does not implement, so a
114
+ * request/response-only client binding the default list fails at wire-up. The
115
+ * conditional turns that into a compile error.
116
+ */
117
+ export type DataConnectionArgs<
118
+ TTransfer extends TransferElement,
119
+ TClient extends object,
120
+ TServer extends DataServerProtocol<TTransfer, DiagnosticOf<TServer>> = DataServerProtocol<TTransfer>
121
+ > =
122
+ TClient extends DataClientProtocol<TTransfer>
123
+ ? [options?: DataConnectionOptions<TTransfer, TServer> & Partial<DataConnectionOptionsWithMethods<TClient, TTransfer, TServer>>]
124
+ : [options: DataConnectionOptionsWithMethods<TClient, TTransfer, TServer>];
125
+
126
+ /**
127
+ * A {@link RpcConnection} to the data head, carrying as many participants as
128
+ * the host has interested parties.
129
+ *
130
+ * Document operations live on the participants rather than here: they carry a
131
+ * `clientId`, which identifies a participant rather than a wire, and the server
132
+ * keys its opens and watches per `(uri, clientId)`. Two parties sharing one
133
+ * identity cannot tell each other's writes from their own echoes.
134
+ * {@link DataConnection.watchDocument} is the exception: it acts as no
135
+ * participant, under an id no session holds, and opens or writes nothing.
136
+ *
137
+ * Generic over the transfer root so this file names no grammar. An adopter
138
+ * binds the concrete root (or the union of them, for a multi-grammar head) at
139
+ * its own edge.
140
+ */
141
+ export class DataConnection<
142
+ TTransfer extends TransferElement,
143
+ TServer extends DataServerProtocol<TTransfer, DiagnosticOf<TServer>> = DataServerProtocol<TTransfer>,
144
+ TClient extends object = DataClientProtocol<TTransfer>
145
+ > extends RpcConnection<TServer, TClient> {
146
+ /** Backs {@link liveSessions}, and is what {@link createSession} checks a new id against. */
147
+ protected readonly sessions = new Set<DataSession<TTransfer, TServer>>();
148
+ protected readonly sessionFactory: DataSessionFactory<TTransfer, TServer>;
149
+ protected readonly createSessionEmitter = new Emitter<DataSession<TTransfer, TServer>>();
150
+ /**
151
+ * Fires with each session {@link createSession} starts, before it returns,
152
+ * so a listener sees every session a caller can. A session started before
153
+ * the listener subscribed is in {@link liveSessions}.
154
+ */
155
+ readonly onDidCreateSession: Event<DataSession<TTransfer, TServer>> = this.createSessionEmitter.event;
156
+ /**
157
+ * Per URI, the `dirty` the client was last told, whether a session of this
158
+ * connection has it open or a watch follows it. A session's open or close
159
+ * of the URI forgets it; disposing a watch does not, since a watch knows
160
+ * only the caller's spelling of the URI, not the server's key. A
161
+ * session's restore and a watch sent again after a reconnect tell the
162
+ * client their answer where it differs, a forgotten URI included; see
163
+ * {@link restoreDirty}.
164
+ */
165
+ protected readonly dirtyStates = new Map<string, boolean>();
166
+ /** Backs each session's {@link DataSessionHost.onDidChangeDirty}. */
167
+ protected readonly dirtyChangedEmitter = new Emitter<TransferDocumentDirtyChangedEvent>();
168
+ /** Backs each session's {@link DataSessionHost.onDidUpdateDocument}. */
169
+ protected readonly documentUpdatedEmitter = new Emitter<TransferDocumentUpdatedEvent<TTransfer, DiagnosticOf<TServer>>>();
170
+ /** Backs each session's {@link DataSessionHost.onDidDeleteDocument}. */
171
+ protected readonly documentDeletedEmitter = new Emitter<TransferDocumentDeletedEvent>();
172
+ /**
173
+ * Per id {@link watchDocument} watches under, the watch, which
174
+ * {@link generationReady} sends again to every later generation until the
175
+ * watch's handle is disposed.
176
+ */
177
+ protected readonly watches = new Map<string, DataConnectionWatch>();
178
+ /**
179
+ * Per id, the URI of a watch whose handle was disposed with no ready
180
+ * generation to unwatch on. {@link generationReady} sends the unwatch to the
181
+ * next ready one: a generation that failed its readiness check after its
182
+ * watches were sent leaves them on a connection the port may hand back.
183
+ */
184
+ protected readonly pendingUnwatches = new Map<string, string>();
185
+ /**
186
+ * The keys of the deletions the current generation's reconnect told the
187
+ * client of, so a URI several sessions and watches follow is told once.
188
+ */
189
+ protected readonly toldDeletions = new Set<string>();
190
+ /**
191
+ * One map per watch in flight, keyed by document, of what the last event
192
+ * heard since the watch was sent said of its existence, and the event's
193
+ * position. The server may take the answer before an event goes out, so
194
+ * an event heard in flight wins over the answer where its position is
195
+ * past the one the answer carries.
196
+ */
197
+ protected readonly heardInFlight = new Set<Map<string, DataConnectionHeardEvent>>();
198
+ /** The port's logger, or one that logs nothing. */
199
+ protected readonly logger: Logger;
200
+ /** Backs {@link onDidReconnect}. */
201
+ protected readonly reconnectEmitter = new Emitter<void>();
202
+ /**
203
+ * Fires on every reconnect: once a connection becomes ready after an
204
+ * earlier one was, and its watches have been sent. The server sends no
205
+ * event for a change made while the connection was down, so a watcher reads
206
+ * its document again on this; a read it sends now reaches the server after
207
+ * its watch.
208
+ */
209
+ readonly onDidReconnect: Event<void> = this.reconnectEmitter.event;
210
+ /** Whether a generation was ready before, which makes the next one a reconnect. */
211
+ protected readyBefore = false;
212
+
213
+ constructor(port: DataPort, client: TClient, ...rest: DataConnectionArgs<TTransfer, TClient, TServer>) {
214
+ const [options = {}] = rest as [
215
+ (DataConnectionOptions<TTransfer, TServer> & Partial<DataConnectionOptionsWithMethods<TClient, TTransfer, TServer>>)?
216
+ ];
217
+ super(port, client, {
218
+ methodNamespace: options.methodNamespace ?? DATA_SERVER_WIRE_PREFIX,
219
+ // The default is reachable only where `TClient` satisfies
220
+ // `DataClientProtocol`, which the constructor's conditional enforces;
221
+ // the compiler cannot carry that through to the generic parameter.
222
+ clientMethods: options.clientMethods ?? (DATA_CLIENT_PROTOCOL_METHODS as unknown as readonly (keyof TClient & string)[]),
223
+ lifecycle: options
224
+ });
225
+ this.sessionFactory =
226
+ options.sessionFactory ?? ((clientId, host, label) => new DataSession<TTransfer, TServer>(clientId, host, label));
227
+ this.logger = (port.logger ?? new NoopLogger()).for('DataConnection');
228
+ }
229
+
230
+ /**
231
+ * The sessions of this connection that have not ended, in the order they
232
+ * started. A session is listed until its `onDidDispose` fires, or until
233
+ * {@link dispose} clears the list.
234
+ */
235
+ get liveSessions(): readonly DataSession<TTransfer, TServer>[] {
236
+ return [...this.sessions];
237
+ }
238
+
239
+ /**
240
+ * Start a participant on this connection, registered with the server under a
241
+ * fresh id, `label` plus `#` plus a random UUID, or under `clientId` when
242
+ * given. Pass a `label` naming the participant; without one it is
243
+ * `session`. Synchronous: the registration is sent at once, and the
244
+ * session's calls wait for it. The server refuses an id live anywhere in
245
+ * its process, and every call of that session then rejects with an error
246
+ * `isDuplicateClientIdError` recognises; an id the server reserves beyond
247
+ * {@link FRAMEWORK_CLIENT_IDS}, such as the integrity author, with one
248
+ * `isReservedClientIdError` recognises. Test with those guards rather than
249
+ * `instanceof`, which misses an error from another copy of this package.
250
+ *
251
+ * Throws a {@link ReservedClientIdError} for an id in
252
+ * {@link FRAMEWORK_CLIENT_IDS} — those are authors the SERVER emits rather
253
+ * than participants, so a session holding one would read the framework's
254
+ * own broadcasts as its own echoes and drop them — and a
255
+ * {@link DuplicateClientIdError} for an id a live session on this
256
+ * connection already holds.
257
+ */
258
+ createSession(label = 'session', clientId?: string): DataSession<TTransfer, TServer> {
259
+ this.assertLive();
260
+ const id = clientId ?? `${label}#${randomUuid()}`;
261
+ if (FRAMEWORK_CLIENT_IDS.includes(id)) {
262
+ throw new ReservedClientIdError(id);
263
+ }
264
+ if ([...this.sessions].some(session => session.clientId === id)) {
265
+ throw new DuplicateClientIdError(id);
266
+ }
267
+ const session = this.sessionFactory(
268
+ id,
269
+ {
270
+ connected: () => this.connected(),
271
+ reportError: (error, reported) => this.reportError(error, reported),
272
+ restoreDirty: event => this.restoreDirty(event),
273
+ // Without it the session reports the unsaved text it loses.
274
+ restoreDeletion: this.hearsDeletions ? event => this.restoreDeletion(event) : undefined,
275
+ forgetDirty: uri => this.dirtyStates.delete(uri),
276
+ onDidChangeDirty: this.dirtyChangedEmitter.event,
277
+ onDidUpdateDocument: this.documentUpdatedEmitter.event,
278
+ onDidDeleteDocument: this.documentDeletedEmitter.event,
279
+ logger: this.logger.for('DataSession').with(id)
280
+ },
281
+ label
282
+ );
283
+ this.sessions.add(session);
284
+ // Subscribed before the session is handed out, so the id is free again
285
+ // on this connection by the time any caller's listener runs.
286
+ session.onDidDispose(() => this.sessions.delete(session));
287
+ // A failure reaches the session's own calls, which wait for the same
288
+ // registration; caught here only so it is not also reported unhandled.
289
+ session.connected().catch(() => undefined);
290
+ this.createSessionEmitter.fire(session);
291
+ return session;
292
+ }
293
+
294
+ /**
295
+ * Follow `uri` without opening it: its update events reach this
296
+ * connection's client once this resolves. An open would hold the document
297
+ * for as long as the caller follows it. The watch runs under an id of its
298
+ * own, `label` plus `#` plus a random UUID, and needs no session: a session
299
+ * closing the document would also end its own watch of it. Every later
300
+ * connection that becomes ready gets the watch again, and tells the client
301
+ * of a deletion while it was down. Disposing the handle unwatches.
302
+ */
303
+ async watchDocument(uri: string, label = 'watch'): Promise<Disposable> {
304
+ const clientId = `${label}#${randomUuid()}`;
305
+ const server = await this.connected();
306
+ // Kept only from here: kept during the wait, a generation that became
307
+ // ready meanwhile would send the watch a second time.
308
+ this.watches.set(clientId, { uri, exists: false });
309
+ const heard = new Map<string, DataConnectionHeardEvent>();
310
+ this.heardInFlight.add(heard);
311
+ let answer: TransferWatchedDocument;
312
+ try {
313
+ answer = await server.watchModelDocument({ uri, clientId });
314
+ } catch (error: unknown) {
315
+ this.watches.delete(clientId);
316
+ throw error;
317
+ } finally {
318
+ this.heardInFlight.delete(heard);
319
+ }
320
+ this.logger.debug(`Watch ${uri} as ${clientId}`);
321
+ this.watches.set(clientId, { uri, serverUri: answer.uri, exists: existsAfter(heard.get(answer.uri), answer) });
322
+ return Disposable.create(() => {
323
+ if (!this.watches.delete(clientId)) {
324
+ return;
325
+ }
326
+ // Without a ready generation the unwatch waits for the next one,
327
+ // rather than opening a connection only for it.
328
+ const unwatchLater = (): void => {
329
+ this.pendingUnwatches.set(clientId, uri);
330
+ };
331
+ const generation = this.generation;
332
+ if (!generation) {
333
+ unwatchLater();
334
+ return;
335
+ }
336
+ (generation.ready ??= this.awaitReady(generation)).then(() => {
337
+ if (this.generation === generation) {
338
+ this.unwatch(generation, clientId, uri);
339
+ } else {
340
+ unwatchLater();
341
+ }
342
+ }, unwatchLater);
343
+ });
344
+ }
345
+
346
+ /**
347
+ * The client, with its `onDocumentDirtyChanged` passing through
348
+ * {@link deliverDirty} first, so {@link dirtyStates} holds what the server
349
+ * told it, and every session hears it through {@link dirtyChangedEmitter};
350
+ * and with its `onDocumentUpdated` and `onDocumentDeleted` heard by every
351
+ * session through {@link documentUpdatedEmitter} and
352
+ * {@link documentDeletedEmitter} first. Every other bound method forwards
353
+ * to the client unchanged, and one the client lacks stays absent, so the
354
+ * binding still refuses it.
355
+ */
356
+ protected override localTarget(): TClient {
357
+ const client = this.client as unknown as Record<string, unknown>;
358
+ const hearsDirty = this.bindsClientMethod('onDocumentDirtyChanged');
359
+ const hearsUpdates = this.bindsClientMethod('onDocumentUpdated');
360
+ const hearsDeletions = this.hearsDeletions;
361
+ if (!hearsDirty && !hearsUpdates && !hearsDeletions) {
362
+ return this.client;
363
+ }
364
+ const target: Record<string, unknown> = {};
365
+ for (const name of this.clientMethods) {
366
+ const method: unknown = client[name];
367
+ if (typeof method === 'function') {
368
+ target[name] = (params: unknown): unknown => (method as (params: unknown) => unknown).call(client, params);
369
+ }
370
+ }
371
+ if (hearsDirty) {
372
+ target.onDocumentDirtyChanged = (event: TransferDocumentDirtyChangedEvent): void => {
373
+ this.dirtyChangedEmitter.fire(event);
374
+ this.deliverDirty(event);
375
+ };
376
+ }
377
+ if (hearsUpdates) {
378
+ const forward = target.onDocumentUpdated as (event: TransferDocumentUpdatedEvent<TTransfer, DiagnosticOf<TServer>>) => void;
379
+ target.onDocumentUpdated = (event: TransferDocumentUpdatedEvent<TTransfer, DiagnosticOf<TServer>>): void => {
380
+ if (event.document.model) {
381
+ this.markWatches(event.document.uri, true, event.sequence);
382
+ }
383
+ this.documentUpdatedEmitter.fire(event);
384
+ forward(event);
385
+ };
386
+ }
387
+ if (hearsDeletions) {
388
+ const forward = target.onDocumentDeleted as (event: TransferDocumentDeletedEvent) => void;
389
+ target.onDocumentDeleted = (event: TransferDocumentDeletedEvent): void => {
390
+ // Held gone, so a reconnect tells the client of it no second time.
391
+ // A server sending no position has its deletion count as sent
392
+ // before any answer.
393
+ this.markWatches(event.uri, false, event.sequence ?? 0);
394
+ this.documentDeletedEmitter.fire(event);
395
+ forward(event);
396
+ };
397
+ }
398
+ return target as unknown as TClient;
399
+ }
400
+
401
+ /**
402
+ * Whether the client binds `onDocumentDeleted`. Without it no deletion
403
+ * reaches the client or the sessions, the server's or one a reconnect
404
+ * found, and a session's restore reports what a gone document took.
405
+ */
406
+ protected get hearsDeletions(): boolean {
407
+ return this.bindsClientMethod('onDocumentDeleted');
408
+ }
409
+
410
+ /** Whether `name` is among the methods bound for the client, and the client implements it. */
411
+ protected bindsClientMethod(name: string): boolean {
412
+ const client = this.client as unknown as Record<string, unknown>;
413
+ return (this.clientMethods as readonly string[]).includes(name) && typeof client[name] === 'function';
414
+ }
415
+
416
+ /**
417
+ * Hand the client a deletion a session's restore or a watch sent again
418
+ * found, which no event brought while the connection was down, unless
419
+ * {@link toldDeletions} says this generation told it already. The sessions
420
+ * do not hear it: each finds what it lost in its own restore.
421
+ */
422
+ protected restoreDeletion(event: TransferDocumentDeletedEvent): void {
423
+ if (this.toldDeletions.has(event.uri)) {
424
+ return;
425
+ }
426
+ this.toldDeletions.add(event.uri);
427
+ const client = this.client as unknown as Pick<DataClientProtocol<TTransfer>, 'onDocumentDeleted'>;
428
+ client.onDocumentDeleted(event);
429
+ }
430
+
431
+ /**
432
+ * Record in every watch whose answer named `uri` whether the document
433
+ * exists, and in {@link heardInFlight} for the watches not answered yet,
434
+ * with the event's position.
435
+ */
436
+ protected markWatches(uri: string, exists: boolean, sequence: number): void {
437
+ this.watches.forEach((watch, clientId) => {
438
+ if (watch.serverUri === uri) {
439
+ this.watches.set(clientId, { ...watch, exists });
440
+ }
441
+ });
442
+ this.heardInFlight.forEach(heard => heard.set(uri, { exists, sequence }));
443
+ }
444
+
445
+ /**
446
+ * Hand a dirty state a restore read to the client, unless it is what
447
+ * {@link dirtyStates} says the client was last told; a URI it holds
448
+ * nothing for counts as different.
449
+ */
450
+ protected restoreDirty(event: TransferDocumentDirtyChangedEvent): void {
451
+ if (this.dirtyStates.get(event.uri) !== (event.text?.dirty ?? false)) {
452
+ this.deliverDirty(event);
453
+ }
454
+ }
455
+
456
+ /** Record `event` in {@link dirtyStates} and hand it to the client. */
457
+ protected deliverDirty(event: TransferDocumentDirtyChangedEvent): void {
458
+ this.dirtyStates.set(event.uri, event.text?.dirty ?? false);
459
+ if (this.bindsClientMethod('onDocumentDirtyChanged')) {
460
+ const client = this.client as unknown as Pick<DataClientProtocol<TTransfer>, 'onDocumentDirtyChanged'>;
461
+ client.onDocumentDirtyChanged(event);
462
+ }
463
+ }
464
+
465
+ /**
466
+ * After the transport dropped, reconnect on the next macrotask for the
467
+ * sessions with documents open, so they re-watch and follow their documents
468
+ * again without waiting for a call of their own, and connect for what
469
+ * {@link watchDocument} watches, which {@link generationReady} places
470
+ * again; a session with nothing open restores on its next call. Nothing is
471
+ * scheduled once this connection is disposed, which drops its generation
472
+ * too.
473
+ */
474
+ protected override dropGeneration(): void {
475
+ const dropped = this.generation !== undefined;
476
+ super.dropGeneration();
477
+ if (dropped && !this.disposed) {
478
+ setTimeout(() => {
479
+ if (!this.disposed) {
480
+ this.reconnectSessions();
481
+ if (this.watches.size > 0) {
482
+ // One generation, not `connected`, which follows a drop to
483
+ // the next: that drop's own timer asks again whether
484
+ // anything is still kept. A failure is reported by the gate.
485
+ const generation = this.currentGeneration();
486
+ (generation.ready ??= this.awaitReady(generation)).catch(() => undefined);
487
+ }
488
+ }
489
+ }, 0);
490
+ }
491
+ }
492
+
493
+ /**
494
+ * Call `reconnect()` on every session, reporting a throw instead of letting
495
+ * one session's restore stop the others and the watches after them, and,
496
+ * inside the readiness gate, fail the whole generation.
497
+ */
498
+ protected reconnectSessions(): void {
499
+ for (const session of this.sessions) {
500
+ try {
501
+ session.reconnect();
502
+ } catch (error: unknown) {
503
+ // Reported, so it reaches the user on a port without a logger;
504
+ // logged too, since only the log names the session.
505
+ this.reportError(error, resolve(DATA_CONNECTION_SESSION_RESTORE_FAILED, { detail: describeError(error) }));
506
+ this.logger.error(`Could not restore session ${session.clientId}: ${describeErrorWithStack(error)}`);
507
+ }
508
+ }
509
+ }
510
+
511
+ /**
512
+ * Restore what the server lost with an earlier generation, whichever
513
+ * request brought this one up: the documents of sessions that have some
514
+ * open, and every watch {@link watchDocument} keeps.
515
+ */
516
+ protected override generationReady(generation: RpcConnectionGeneration<TServer>): void {
517
+ super.generationReady(generation);
518
+ this.toldDeletions.clear();
519
+ this.reconnectSessions();
520
+ this.watches.forEach((watch, clientId) => this.watchAgain(generation, clientId, watch.uri));
521
+ this.pendingUnwatches.forEach((uri, clientId) => this.unwatch(generation, clientId, uri));
522
+ this.pendingUnwatches.clear();
523
+ if (this.readyBefore) {
524
+ this.reconnectEmitter.fire(undefined);
525
+ }
526
+ this.readyBefore = true;
527
+ }
528
+
529
+ /** Take back the watch of `uri` under `clientId` on `generation`; the server ignores one it does not hold. */
530
+ protected unwatch(generation: RpcConnectionGeneration<TServer>, clientId: string, uri: string): void {
531
+ this.logger.debug(`Unwatch ${uri} as ${clientId}`);
532
+ generation.server.unwatchModelDocument({ uri, clientId }).catch(() => undefined);
533
+ }
534
+
535
+ /**
536
+ * Send the watch of `uri` under `clientId` to `generation`, which has just
537
+ * passed its readiness gate. Sent at once rather than after a wait, so no
538
+ * drop can come between choosing the generation and sending. A failure is
539
+ * reported, since no caller waits on it, only while the watch is kept and
540
+ * `generation` is still current: otherwise the next generation sends it
541
+ * again.
542
+ *
543
+ * A document the client last heard exists that the watch's answer says
544
+ * is gone goes to the client as a deletion; once the watch is in place,
545
+ * the document's dirty state is read and goes through
546
+ * {@link restoreDirty}, as a session's restore does. Neither reached
547
+ * anyone while the connection was down.
548
+ */
549
+ protected watchAgain(generation: RpcConnectionGeneration<TServer>, clientId: string, uri: string): void {
550
+ const heard = new Map<string, DataConnectionHeardEvent>();
551
+ this.heardInFlight.add(heard);
552
+ generation.server
553
+ .watchModelDocument({ uri, clientId })
554
+ .finally(() => this.heardInFlight.delete(heard))
555
+ .then(
556
+ answer => {
557
+ const known = this.watches.get(clientId);
558
+ if (!known) {
559
+ return;
560
+ }
561
+ this.logger.debug(`Watch ${uri} again as ${clientId}`);
562
+ const exists = existsAfter(heard.get(answer.uri), answer);
563
+ this.watches.set(clientId, { uri, serverUri: answer.uri, exists });
564
+ if (known.exists && !exists && this.hearsDeletions) {
565
+ try {
566
+ this.restoreDeletion({ uri: answer.uri, sourceClientId: UNKNOWN_CLIENT_ID });
567
+ } catch {
568
+ // The client's listener failed, not the watch, which stays kept.
569
+ }
570
+ }
571
+ generation.server.getModelDocument({ uri }).then(
572
+ current => {
573
+ if (current.text && this.watches.has(clientId)) {
574
+ try {
575
+ this.restoreDirty({ uri: current.uri, text: current.text });
576
+ } catch {
577
+ // The client's listener failed, not the watch, which stays kept.
578
+ }
579
+ }
580
+ },
581
+ () => undefined
582
+ );
583
+ },
584
+ (error: unknown) => {
585
+ if (!this.watches.has(clientId)) {
586
+ return;
587
+ }
588
+ if (this.generation !== generation) {
589
+ this.logger.debug(`Watch of ${uri} as ${clientId} cut short by a lost connection; the next one sends it again`);
590
+ return;
591
+ }
592
+ this.reportError(error, resolve(DATA_CONNECTION_WATCH_RESTORE_FAILED, { uri, detail: describeError(error) }));
593
+ }
594
+ );
595
+ }
596
+
597
+ /**
598
+ * Sessions are detached rather than disposed: the server ends every session
599
+ * on a connection it sees close, so ending each one first sends requests
600
+ * over a connection this call is about to dispose.
601
+ */
602
+ override dispose(): void {
603
+ for (const session of [...this.sessions]) {
604
+ session.detach();
605
+ }
606
+ // For a factory's session whose `detach` does not fire.
607
+ this.sessions.clear();
608
+ this.watches.clear();
609
+ this.pendingUnwatches.clear();
610
+ this.createSessionEmitter.dispose();
611
+ this.reconnectEmitter.dispose();
612
+ this.dirtyChangedEmitter.dispose();
613
+ this.documentUpdatedEmitter.dispose();
614
+ this.documentDeletedEmitter.dispose();
615
+ super.dispose();
616
+ }
617
+ }
618
+
619
+ /**
620
+ * A {@link DataConnection} that brings its own {@link DataEvents}, so a host
621
+ * with several interested parties does not have to supply one.
622
+ *
623
+ * **The client slot holds exactly one object, and that is why this exists.**
624
+ * `createRpcProxy` binds a single `localTarget`, and underneath a method name
625
+ * maps to one handler — a second registration replaces the first silently. So a
626
+ * properties panel and a tree cannot both be the client; one fan-out sits in the
627
+ * slot and both subscribe to it.
628
+ *
629
+ * Use {@link DataConnection} directly instead when the client is yours: an
630
+ * adopter service that implements the protocol plus its own methods, a single
631
+ * consumer that IS the client, or a request/response-only client that binds
632
+ * nothing.
633
+ */
634
+ export class DataConnectionWithEvents<
635
+ TTransfer extends TransferElement,
636
+ TServer extends DataServerProtocol<TTransfer, DiagnosticOf<TServer>> = DataServerProtocol<TTransfer>
637
+ > extends DataConnection<TTransfer, TServer, DataEvents<TTransfer, DiagnosticOf<TServer>, ProjectOf<TServer>>> {
638
+ /** Server pushes, fanned out to as many local listeners as the host has. */
639
+ readonly events: DataEvents<TTransfer, DiagnosticOf<TServer>, ProjectOf<TServer>>;
640
+
641
+ constructor(port: DataPort, options?: DataConnectionOptions<TTransfer, TServer>) {
642
+ // Built as a local because `this` is unavailable before `super`, then
643
+ // read back onto the field.
644
+ const events = new DataEvents<TTransfer, DiagnosticOf<TServer>, ProjectOf<TServer>>();
645
+ super(port, events, options);
646
+ this.events = events;
647
+ }
648
+
649
+ /** Disposes the fan-out it created, which no caller else holds. */
650
+ override dispose(): void {
651
+ super.dispose();
652
+ this.events.dispose();
653
+ }
654
+ }