@hydranium/protocol 1.0.0-next.39 → 1.0.0-next.391

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 (311) hide show
  1. package/README.md +46 -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 +11 -2
  11. package/lib/client/data-events.d.ts.map +1 -1
  12. package/lib/client/data-events.js +13 -1
  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 +762 -89
  17. package/lib/client/data-session.d.ts.map +1 -1
  18. package/lib/client/data-session.js +1253 -115
  19. package/lib/client/data-session.js.map +1 -1
  20. package/lib/client/index.d.ts +16 -9
  21. package/lib/client/index.d.ts.map +1 -1
  22. package/lib/client/index.js +16 -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/working-copy.d.ts +420 -0
  41. package/lib/client/working-copy.d.ts.map +1 -0
  42. package/lib/client/working-copy.js +958 -0
  43. package/lib/client/working-copy.js.map +1 -0
  44. package/lib/client-ids.d.ts +45 -0
  45. package/lib/client-ids.d.ts.map +1 -0
  46. package/lib/client-ids.js +48 -0
  47. package/lib/client-ids.js.map +1 -0
  48. package/lib/clock.d.ts +50 -10
  49. package/lib/clock.d.ts.map +1 -1
  50. package/lib/clock.js +36 -1
  51. package/lib/clock.js.map +1 -1
  52. package/lib/console-logger.d.ts +23 -0
  53. package/lib/console-logger.d.ts.map +1 -0
  54. package/lib/console-logger.js +39 -0
  55. package/lib/console-logger.js.map +1 -0
  56. package/lib/data/data-protocol-methods.d.ts +4 -4
  57. package/lib/data/data-protocol-methods.d.ts.map +1 -1
  58. package/lib/data/data-protocol-methods.js +7 -0
  59. package/lib/data/data-protocol-methods.js.map +1 -1
  60. package/lib/data/data-server-protocol.d.ts +160 -50
  61. package/lib/data/data-server-protocol.d.ts.map +1 -1
  62. package/lib/data/events.d.ts +75 -31
  63. package/lib/data/events.d.ts.map +1 -1
  64. package/lib/data/requests.d.ts +84 -11
  65. package/lib/data/requests.d.ts.map +1 -1
  66. package/lib/debouncer.d.ts +7 -4
  67. package/lib/debouncer.d.ts.map +1 -1
  68. package/lib/debouncer.js +10 -10
  69. package/lib/debouncer.js.map +1 -1
  70. package/lib/errors.d.ts +241 -48
  71. package/lib/errors.d.ts.map +1 -1
  72. package/lib/errors.js +395 -60
  73. package/lib/errors.js.map +1 -1
  74. package/lib/format-log-arg.d.ts +33 -0
  75. package/lib/format-log-arg.d.ts.map +1 -0
  76. package/lib/format-log-arg.js +158 -0
  77. package/lib/format-log-arg.js.map +1 -0
  78. package/lib/glsp-edits-settled-actions.d.ts +54 -0
  79. package/lib/glsp-edits-settled-actions.d.ts.map +1 -0
  80. package/lib/glsp-edits-settled-actions.js +28 -0
  81. package/lib/glsp-edits-settled-actions.js.map +1 -0
  82. package/lib/glsp-request-model-args.d.ts +16 -0
  83. package/lib/glsp-request-model-args.d.ts.map +1 -0
  84. package/lib/glsp-request-model-args.js +19 -0
  85. package/lib/glsp-request-model-args.js.map +1 -0
  86. package/lib/glsp-save-model-actions.d.ts +55 -0
  87. package/lib/glsp-save-model-actions.d.ts.map +1 -0
  88. package/lib/glsp-save-model-actions.js +28 -0
  89. package/lib/glsp-save-model-actions.js.map +1 -0
  90. package/lib/index.d.ts +11 -0
  91. package/lib/index.d.ts.map +1 -1
  92. package/lib/index.js +11 -0
  93. package/lib/index.js.map +1 -1
  94. package/lib/latency-collector.d.ts +10 -4
  95. package/lib/latency-collector.d.ts.map +1 -1
  96. package/lib/latency-collector.js +2 -0
  97. package/lib/latency-collector.js.map +1 -1
  98. package/lib/logger.d.ts +38 -7
  99. package/lib/logger.d.ts.map +1 -1
  100. package/lib/logger.js +42 -4
  101. package/lib/logger.js.map +1 -1
  102. package/lib/messages/index.d.ts +4 -2
  103. package/lib/messages/index.d.ts.map +1 -1
  104. package/lib/messages/index.js +17 -4
  105. package/lib/messages/index.js.map +1 -1
  106. package/lib/messages/primitives.d.ts +59 -4
  107. package/lib/messages/primitives.d.ts.map +1 -1
  108. package/lib/messages/primitives.js +97 -4
  109. package/lib/messages/primitives.js.map +1 -1
  110. package/lib/model-server.d.ts +58 -11
  111. package/lib/model-server.d.ts.map +1 -1
  112. package/lib/model-server.js +4 -2
  113. package/lib/model-server.js.map +1 -1
  114. package/lib/model-service/base-version.d.ts +67 -0
  115. package/lib/model-service/base-version.d.ts.map +1 -0
  116. package/lib/model-service/base-version.js +44 -0
  117. package/lib/model-service/base-version.js.map +1 -0
  118. package/lib/model-service/index.d.ts +1 -1
  119. package/lib/model-service/index.d.ts.map +1 -1
  120. package/lib/model-service/index.js +4 -5
  121. package/lib/model-service/index.js.map +1 -1
  122. package/lib/model-service/reference-candidate.d.ts +5 -3
  123. package/lib/model-service/reference-candidate.d.ts.map +1 -1
  124. package/lib/node/index.d.ts +10 -0
  125. package/lib/node/index.d.ts.map +1 -0
  126. package/lib/node/index.js +29 -0
  127. package/lib/node/index.js.map +1 -0
  128. package/lib/node/process-memory.d.ts +66 -0
  129. package/lib/node/process-memory.d.ts.map +1 -0
  130. package/lib/node/process-memory.js +291 -0
  131. package/lib/node/process-memory.js.map +1 -0
  132. package/lib/noop-logger.d.ts.map +1 -1
  133. package/lib/noop-logger.js.map +1 -1
  134. package/lib/observable-value.js.map +1 -1
  135. package/lib/patch-merge.d.ts +63 -35
  136. package/lib/patch-merge.d.ts.map +1 -1
  137. package/lib/patch-merge.js +171 -25
  138. package/lib/patch-merge.js.map +1 -1
  139. package/lib/pending-work-tracker.d.ts +33 -0
  140. package/lib/pending-work-tracker.d.ts.map +1 -0
  141. package/lib/pending-work-tracker.js +48 -0
  142. package/lib/pending-work-tracker.js.map +1 -0
  143. package/lib/profile-session.d.ts +24 -8
  144. package/lib/profile-session.d.ts.map +1 -1
  145. package/lib/profile-session.js +13 -4
  146. package/lib/profile-session.js.map +1 -1
  147. package/lib/profiling.d.ts +15 -2
  148. package/lib/profiling.d.ts.map +1 -1
  149. package/lib/profiling.js.map +1 -1
  150. package/lib/project.d.ts +6 -2
  151. package/lib/project.d.ts.map +1 -1
  152. package/lib/project.js.map +1 -1
  153. package/lib/random-uuid.d.ts +14 -0
  154. package/lib/random-uuid.d.ts.map +1 -0
  155. package/lib/random-uuid.js +24 -0
  156. package/lib/random-uuid.js.map +1 -0
  157. package/lib/reconcile-write.d.ts +70 -0
  158. package/lib/reconcile-write.d.ts.map +1 -0
  159. package/lib/reconcile-write.js +69 -0
  160. package/lib/reconcile-write.js.map +1 -0
  161. package/lib/rpc/bind-rpc-methods.d.ts +6 -2
  162. package/lib/rpc/bind-rpc-methods.d.ts.map +1 -1
  163. package/lib/rpc/bind-rpc-methods.js +17 -7
  164. package/lib/rpc/bind-rpc-methods.js.map +1 -1
  165. package/lib/rpc/create-rpc-proxy.d.ts +3 -0
  166. package/lib/rpc/create-rpc-proxy.d.ts.map +1 -1
  167. package/lib/rpc/create-rpc-proxy.js +6 -1
  168. package/lib/rpc/create-rpc-proxy.js.map +1 -1
  169. package/lib/rpc/index.d.ts +1 -0
  170. package/lib/rpc/index.d.ts.map +1 -1
  171. package/lib/rpc/index.js +1 -0
  172. package/lib/rpc/index.js.map +1 -1
  173. package/lib/rpc/send-by-method-name.d.ts +76 -0
  174. package/lib/rpc/send-by-method-name.d.ts.map +1 -0
  175. package/lib/rpc/send-by-method-name.js +120 -0
  176. package/lib/rpc/send-by-method-name.js.map +1 -0
  177. package/lib/rpc/wire-prefix.js.map +1 -1
  178. package/lib/save-text-document.d.ts +40 -0
  179. package/lib/save-text-document.d.ts.map +1 -0
  180. package/lib/save-text-document.js +34 -0
  181. package/lib/save-text-document.js.map +1 -0
  182. package/lib/testing/catalogue-audit.js.map +1 -1
  183. package/lib/testing/data-doubles.d.ts +36 -11
  184. package/lib/testing/data-doubles.d.ts.map +1 -1
  185. package/lib/testing/data-doubles.js +47 -9
  186. package/lib/testing/data-doubles.js.map +1 -1
  187. package/lib/testing/fake-clock.d.ts +17 -2
  188. package/lib/testing/fake-clock.d.ts.map +1 -1
  189. package/lib/testing/fake-clock.js +61 -46
  190. package/lib/testing/fake-clock.js.map +1 -1
  191. package/lib/testing/harness.d.ts +9 -0
  192. package/lib/testing/harness.d.ts.map +1 -1
  193. package/lib/testing/index.d.ts +1 -0
  194. package/lib/testing/index.d.ts.map +1 -1
  195. package/lib/testing/index.js +4 -3
  196. package/lib/testing/index.js.map +1 -1
  197. package/lib/testing/node/duplex-connection.d.ts.map +1 -1
  198. package/lib/testing/node/duplex-connection.js +3 -2
  199. package/lib/testing/node/duplex-connection.js.map +1 -1
  200. package/lib/testing/node/duplex-stream.js.map +1 -1
  201. package/lib/testing/node/index.d.ts +2 -0
  202. package/lib/testing/node/index.d.ts.map +1 -1
  203. package/lib/testing/node/index.js +3 -2
  204. package/lib/testing/node/index.js.map +1 -1
  205. package/lib/testing/node/message-port-pair.d.ts +25 -0
  206. package/lib/testing/node/message-port-pair.d.ts.map +1 -0
  207. package/lib/testing/node/message-port-pair.js +26 -0
  208. package/lib/testing/node/message-port-pair.js.map +1 -0
  209. package/lib/testing/node/unhandled-rejections.d.ts +20 -0
  210. package/lib/testing/node/unhandled-rejections.d.ts.map +1 -0
  211. package/lib/testing/node/unhandled-rejections.js +35 -0
  212. package/lib/testing/node/unhandled-rejections.js.map +1 -0
  213. package/lib/testing/transfer-node-builder.d.ts +81 -0
  214. package/lib/testing/transfer-node-builder.d.ts.map +1 -0
  215. package/lib/testing/transfer-node-builder.js +47 -0
  216. package/lib/testing/transfer-node-builder.js.map +1 -0
  217. package/lib/testing/wait-for.d.ts +9 -3
  218. package/lib/testing/wait-for.d.ts.map +1 -1
  219. package/lib/testing/wait-for.js +57 -11
  220. package/lib/testing/wait-for.js.map +1 -1
  221. package/lib/tracer.d.ts.map +1 -1
  222. package/lib/tracer.js +5 -9
  223. package/lib/tracer.js.map +1 -1
  224. package/lib/transfer-diagnostic.d.ts +11 -0
  225. package/lib/transfer-diagnostic.d.ts.map +1 -1
  226. package/lib/transfer-diagnostic.js +17 -0
  227. package/lib/transfer-diagnostic.js.map +1 -1
  228. package/lib/transfer-document.d.ts +108 -32
  229. package/lib/transfer-document.d.ts.map +1 -1
  230. package/lib/transfer-document.js +17 -9
  231. package/lib/transfer-document.js.map +1 -1
  232. package/lib/transfer-element.d.ts +4 -4
  233. package/lib/types.d.ts +32 -0
  234. package/lib/types.d.ts.map +1 -0
  235. package/lib/{model-service/args.js → types.js} +2 -2
  236. package/lib/types.js.map +1 -0
  237. package/lib/uri.d.ts.map +1 -1
  238. package/lib/uri.js.map +1 -1
  239. package/lib/util.d.ts +8 -2
  240. package/lib/util.d.ts.map +1 -1
  241. package/lib/util.js +32 -4
  242. package/lib/util.js.map +1 -1
  243. package/package.json +24 -40
  244. package/src/abstract-logger.ts +18 -0
  245. package/src/client/data-connection.ts +654 -0
  246. package/src/client/data-events.ts +15 -1
  247. package/src/client/data-port.ts +36 -25
  248. package/src/client/data-session.ts +1606 -137
  249. package/src/client/index.ts +16 -9
  250. package/src/client/message-relay.ts +6 -4
  251. package/src/client/post-message-transport.ts +224 -4
  252. package/src/client/rpc-connection.ts +302 -0
  253. package/src/client/worker-handshake.ts +121 -0
  254. package/src/client/working-copy.ts +1116 -0
  255. package/src/client-ids.ts +49 -0
  256. package/src/clock.ts +68 -10
  257. package/src/console-logger.ts +39 -0
  258. package/src/data/data-protocol-methods.ts +8 -1
  259. package/src/data/data-server-protocol.ts +184 -49
  260. package/src/data/events.ts +77 -31
  261. package/src/data/requests.ts +90 -11
  262. package/src/debouncer.ts +11 -11
  263. package/src/errors.ts +496 -71
  264. package/src/format-log-arg.ts +176 -0
  265. package/src/glsp-edits-settled-actions.ts +62 -0
  266. package/src/glsp-request-model-args.ts +16 -0
  267. package/src/glsp-save-model-actions.ts +64 -0
  268. package/src/index.ts +11 -0
  269. package/src/latency-collector.ts +10 -3
  270. package/src/logger.ts +44 -8
  271. package/src/messages/index.ts +12 -2
  272. package/src/messages/primitives.ts +129 -5
  273. package/src/model-server.ts +62 -17
  274. package/src/model-service/base-version.ts +75 -0
  275. package/src/model-service/index.ts +4 -5
  276. package/src/model-service/reference-candidate.ts +5 -3
  277. package/src/node/index.ts +14 -0
  278. package/src/node/process-memory.ts +299 -0
  279. package/src/patch-merge.ts +230 -45
  280. package/src/pending-work-tracker.ts +48 -0
  281. package/src/profile-session.ts +31 -11
  282. package/src/profiling.ts +15 -2
  283. package/src/project.ts +6 -2
  284. package/src/random-uuid.ts +21 -0
  285. package/src/reconcile-write.ts +131 -0
  286. package/src/rpc/README.md +6 -6
  287. package/src/rpc/bind-rpc-methods.ts +18 -8
  288. package/src/rpc/create-rpc-proxy.ts +6 -1
  289. package/src/rpc/index.ts +1 -0
  290. package/src/rpc/send-by-method-name.ts +140 -0
  291. package/src/save-text-document.ts +39 -0
  292. package/src/testing/data-doubles.ts +119 -19
  293. package/src/testing/fake-clock.ts +76 -48
  294. package/src/testing/harness.ts +10 -0
  295. package/src/testing/index.ts +4 -3
  296. package/src/testing/node/duplex-connection.ts +3 -2
  297. package/src/testing/node/index.ts +3 -2
  298. package/src/testing/node/message-port-pair.ts +40 -0
  299. package/src/testing/node/unhandled-rejections.ts +31 -0
  300. package/src/testing/transfer-node-builder.ts +107 -0
  301. package/src/testing/wait-for.ts +61 -13
  302. package/src/tracer.ts +5 -9
  303. package/src/transfer-diagnostic.ts +17 -0
  304. package/src/transfer-document.ts +130 -34
  305. package/src/transfer-element.ts +4 -4
  306. package/src/types.ts +30 -0
  307. package/src/util.ts +33 -6
  308. package/lib/model-service/args.d.ts +0 -64
  309. package/lib/model-service/args.d.ts.map +0 -1
  310. package/lib/model-service/args.js.map +0 -1
  311. package/src/model-service/args.ts +0 -67
@@ -6,92 +6,404 @@
6
6
  *
7
7
  * SPDX-License-Identifier: MIT
8
8
  ********************************************************************************/
9
- import type { MessageConnection } from 'vscode-jsonrpc';
10
- import { type DataClientProtocol, type DataServerProtocol } from '../data';
11
- import { type RpcProxy } from '../rpc';
12
- import type { TransferDocument } from '../transfer-document';
9
+ import { type Disposable, Emitter, type Event } from 'vscode-jsonrpc';
10
+ import { type Clock } from '../clock';
11
+ import type { DataServerProtocol, DiagnosticOf, TransferDocumentDeletedEvent, TransferDocumentDirtyChangedEvent, TransferDocumentUpdatedEvent } from '../data';
12
+ import { STALE_BASE_VERSION_SAVE, STALE_BASE_VERSION_UPDATE } from '../errors';
13
+ import type { Logger } from '../logger';
14
+ import { type BaseVersion, type ModelVersion } from '../model-service/base-version';
15
+ import { type ResolvedMessage } from '../messages/primitives';
16
+ import { PendingWorkTracker } from '../pending-work-tracker';
17
+ import type { MaybePromise } from '../util';
18
+ import type { RpcProxy } from '../rpc';
19
+ import type { TextState, TransferCreatedDocument, TransferDocument, TransferSavedDocument, TransferWrittenDocument } from '../transfer-document';
13
20
  import type { TransferElement } from '../transfer-element';
14
- import type { DataPort } from './data-port';
15
21
  /**
16
- * The transport never opened. A complete sentence rather than a fragment: a
17
- * fragment is nested inside a sentence the framework does not own, so no
18
- * translator controls the whole and the composition cannot be made to read
19
- * correctly in every language.
22
+ * A session could not re-open a document it had open after its connection
23
+ * dropped, and forgot it; or could not write it again for another reason than
24
+ * a conflict, and keeps its unsaved edits for the next restore.
20
25
  */
21
- export declare const DATA_SERVER_CONNECT_FAILED: import("../messages/primitives").MessageDefinition<"Could not connect to the data server: {detail}">;
22
- export declare const DATA_SERVER_NOT_READY: import("../messages/primitives").MessageDefinition<"The data server did not become ready: {detail}">;
23
- /** Options for {@link DataSession}. */
24
- export interface DataSessionOptions {
25
- /**
26
- * Wire namespace the server is addressed under. Defaults to the
27
- * framework's {@link DATA_SERVER_WIRE_PREFIX}, which is what an unmodified
28
- * `DataServer` binds. Override only alongside the server's own
29
- * `methodNamespace` option — a mismatch turns every request into
30
- * "Unhandled method" rather than failing at wire-up.
31
- */
32
- readonly methodNamespace?: string;
26
+ export declare const DATA_SESSION_RESTORE_FAILED: import("../messages/primitives").MessageDefinition<"Could not restore {uri} after reconnecting to the data server: {detail}">;
27
+ /** A write or open of `{uri}` that the data server answered without a model. */
28
+ export declare const DATA_SESSION_ANSWER_WITHOUT_MODEL: import("../messages/primitives").MessageDefinition<"The data server answered a write of {uri} without a model; the session counts that answer as older than every version.">;
29
+ /**
30
+ * A session re-opened documents after its connection dropped and cannot put
31
+ * back what it wrote to them since their last save: another client changed
32
+ * them, even while the session was still connected; the session could not
33
+ * tell the text its writes started from, or lost another document written with
34
+ * them; or the write it sent again conflicted. The session's unsaved edits may
35
+ * be gone, and it no longer holds them.
36
+ */
37
+ export declare const DATA_SESSION_UNSAVED_LOST: import("../messages/primitives").MessageDefinition<"Unsaved changes to {uris} may have been lost when the connection to the data server dropped.">;
38
+ /**
39
+ * What one of `TServer`'s document methods takes, minus the `clientId` a
40
+ * {@link DataSession} stamps itself.
41
+ *
42
+ * Read off the SERVER's signature, not off the framework's own arg type: an
43
+ * adopter server widens these, and a wrapper declared against the narrow
44
+ * shape rejects the extra field on a fresh object literal, so that call
45
+ * cannot go through a session at all.
46
+ */
47
+ export type DataSessionArgs<TMethod extends (args: never) => unknown> = Omit<Parameters<TMethod>[0], 'clientId'>;
48
+ /**
49
+ * Open a document through a session; the session supplies `clientId`. Only the
50
+ * URI and the open's options, read off the server's signature: the server
51
+ * ignores the `languageId`, `version` and `text` seeds of `OpenModelArgs`, and
52
+ * a field an adopter adds never reaches the server session's open, so
53
+ * accepting either would let a caller believe it took effect.
54
+ */
55
+ export type DataSessionOpenArgs<TTransfer extends TransferElement, TServer extends DataServerProtocol<TTransfer, DiagnosticOf<TServer>> = DataServerProtocol<TTransfer>> = Pick<Parameters<TServer['openModelDocument']>[0], 'uri' | ('options' & keyof Parameters<TServer['openModelDocument']>[0])>;
56
+ /**
57
+ * The options an open through a session passes to `TServer`, `undefined` when
58
+ * it passed none; only `undefined` for a server whose open takes none.
59
+ */
60
+ export type DataSessionOpenOptions<TTransfer extends TransferElement, TServer extends DataServerProtocol<TTransfer, DiagnosticOf<TServer>> = DataServerProtocol<TTransfer>> = DataSessionOpenArgs<TTransfer, TServer>['options' & keyof DataSessionOpenArgs<TTransfer, TServer>] | undefined;
61
+ /** Create a document through a session; the session supplies `clientId`. */
62
+ export type DataSessionCreateArgs<TTransfer extends TransferElement, TServer extends DataServerProtocol<TTransfer, DiagnosticOf<TServer>> = DataServerProtocol<TTransfer>> = DataSessionArgs<TServer['createModelDocument']>;
63
+ /** Close a document through a session; the session supplies `clientId`. */
64
+ export type DataSessionCloseArgs<TTransfer extends TransferElement, TServer extends DataServerProtocol<TTransfer, DiagnosticOf<TServer>> = DataServerProtocol<TTransfer>> = DataSessionArgs<TServer['closeModelDocument']>;
65
+ /** Update a document through a session; the session supplies `clientId`. */
66
+ export type DataSessionUpdateArgs<TTransfer extends TransferElement, TServer extends DataServerProtocol<TTransfer, DiagnosticOf<TServer>> = DataServerProtocol<TTransfer>> = DataSessionArgs<TServer['updateModelDocument']>;
67
+ /** Update several documents at once through a session; the session supplies `clientId`. */
68
+ export type DataSessionUpdatesArgs<TTransfer extends TransferElement, TServer extends DataServerProtocol<TTransfer, DiagnosticOf<TServer>> = DataServerProtocol<TTransfer>> = DataSessionArgs<TServer['updateModelDocuments']>;
69
+ /** Persist a document through a session; the session supplies `clientId`. */
70
+ export type DataSessionSaveArgs<TTransfer extends TransferElement, TServer extends DataServerProtocol<TTransfer, DiagnosticOf<TServer>> = DataServerProtocol<TTransfer>> = DataSessionArgs<TServer['saveModelDocument']>;
71
+ /** Persist the text the server holds through a session; the session supplies `clientId`. */
72
+ export type DataSessionPersistArgs<TTransfer extends TransferElement, TServer extends DataServerProtocol<TTransfer, DiagnosticOf<TServer>> = DataServerProtocol<TTransfer>> = DataSessionArgs<TServer['persistModelDocument']>;
73
+ /** Delete a document through a session; the session supplies `clientId`. */
74
+ export type DataSessionDeleteArgs<TTransfer extends TransferElement, TServer extends DataServerProtocol<TTransfer, DiagnosticOf<TServer>> = DataServerProtocol<TTransfer>> = DataSessionArgs<TServer['deleteModelDocument']>;
75
+ /** The document a session hands back, carrying its server's diagnostic shape. */
76
+ export type DataSessionDocument<TTransfer extends TransferElement, TServer extends DataServerProtocol<TTransfer, DiagnosticOf<TServer>> = DataServerProtocol<TTransfer>> = TransferDocument<TTransfer, DiagnosticOf<TServer>>;
77
+ /**
78
+ * A document a restore opened again, or could not, with the caller's URI and
79
+ * what the restore read, `undefined` when that read failed. Not reopened, the
80
+ * session no longer has the document open.
81
+ */
82
+ export interface DataSessionRestoreEvent<TTransfer extends TransferElement, TServer extends DataServerProtocol<TTransfer, DiagnosticOf<TServer>> = DataServerProtocol<TTransfer>> {
83
+ /** The document's URI as the caller spelled it. */
84
+ readonly uri: string;
85
+ /** Whether the session has the document open again. */
86
+ readonly reopened: boolean;
87
+ /** What the restore read, `undefined` when that read failed or it was not reopened. */
88
+ readonly document?: DataSessionDocument<TTransfer, TServer>;
89
+ }
90
+ /**
91
+ * What a {@link DataSession} keeps of a URI it wrote since the URI's last save,
92
+ * to write it again after a reconnect that lost it.
93
+ */
94
+ export interface DataSessionUnsavedWrite<TTransfer extends TransferElement, TServer extends DataServerProtocol<TTransfer, DiagnosticOf<TServer>> = DataServerProtocol<TTransfer>> {
95
+ /**
96
+ * The `text.hash` of the text the first of these writes was based on.
97
+ * `undefined` when the session could not tell, for a write based on
98
+ * `'any'` or on a version it could not read back, and such a write is
99
+ * never sent again: the session cannot tell another client's text from the
100
+ * text it wrote over.
101
+ */
102
+ readonly baseHash: string | undefined;
103
+ /**
104
+ * The model version the last of these writes was answered with, which
105
+ * orders its answers, and the `text.hash` of that answer.
106
+ */
107
+ readonly answer: {
108
+ readonly version: ModelVersion;
109
+ readonly hash?: string;
110
+ };
111
+ /**
112
+ * The call that made the last write, and for an `updateDocuments` call this
113
+ * URI's index in it. Records whose `updates` is the same object were
114
+ * written together and are sent again together, so a restore never applies
115
+ * part of a set.
116
+ */
117
+ readonly call: {
118
+ readonly update: DataSessionUpdateArgs<TTransfer, TServer>;
119
+ } | {
120
+ readonly updates: DataSessionUpdatesArgs<TTransfer, TServer>;
121
+ readonly index: number;
122
+ };
33
123
  }
34
- /** One connection generation: its connection, its proxy, and its readiness. */
35
- interface Generation<TTransfer extends TransferElement> {
36
- readonly connection: Promise<MessageConnection>;
37
- readonly server: RpcProxy<DataServerProtocol<TTransfer>>;
38
- /** Set on first use; the shared readiness gate for this generation. */
39
- ready?: Promise<void>;
124
+ /**
125
+ * One open of a URI by a {@link DataSession}, from the answer to its open,
126
+ * create or re-open until a close or a deletion ends it. A call records its
127
+ * answer only while the open it was sent under is still the URI's: checking
128
+ * that the URI is open accepts an answer from before a close or deletion
129
+ * once the URI is open again.
130
+ */
131
+ export interface DataSessionOpen<TTransfer extends TransferElement, TServer extends DataServerProtocol<TTransfer, DiagnosticOf<TServer>> = DataServerProtocol<TTransfer>> {
132
+ /** The URI the open's answer named, which the server keys its notifications by. */
133
+ readonly serverUri: string;
134
+ /**
135
+ * The options the server opened under, which a re-open after a reconnect
136
+ * passes again: those of the earliest open of the URI under way when the
137
+ * first answered, since the server keeps the open that arrives first.
138
+ */
139
+ readonly options: DataSessionOpenOptions<TTransfer, TServer>;
140
+ /** Whether a deletion ended the open, which an open still watching sends again; a close does not. */
141
+ deleted: boolean;
142
+ }
143
+ /**
144
+ * One open or create of a URI by a {@link DataSession}, from its call until it
145
+ * settles. A close of the URI while it is under way marks it: it then records
146
+ * nothing and is not sent again, so the close stands. Without the mark, a
147
+ * deletion during its watch has it sent again after the close.
148
+ */
149
+ export interface DataSessionOpening<TTransfer extends TransferElement, TServer extends DataServerProtocol<TTransfer, DiagnosticOf<TServer>> = DataServerProtocol<TTransfer>> {
150
+ /** Whether a close of the URI came while this open was under way. */
151
+ closed: boolean;
152
+ /** The options the open was sent with; none for a create. */
153
+ readonly options: DataSessionOpenOptions<TTransfer, TServer>;
154
+ }
155
+ /**
156
+ * What a {@link DataSession} needs from the connection that minted it.
157
+ *
158
+ * Narrower than the connection itself so the dependency points one way:
159
+ * `DataConnection` constructs sessions, and nothing here imports it back.
160
+ */
161
+ export interface DataSessionHost<TTransfer extends TransferElement, TServer extends DataServerProtocol<TTransfer, DiagnosticOf<TServer>>> {
162
+ /** The connected, READY proxy of the current connection; a new object after each reconnect. */
163
+ connected(): Promise<RpcProxy<TServer>>;
164
+ /** Surface a failure no caller is waiting on, such as restoring a document after a reconnect. */
165
+ reportError?(error: unknown, reported: ResolvedMessage): void;
166
+ /**
167
+ * Tell the connection's client the dirty state a restore read, unless it
168
+ * is what the client was last told of the URI since the URI's last open.
169
+ */
170
+ restoreDirty?(event: TransferDocumentDirtyChangedEvent): void;
171
+ /**
172
+ * Tell the connection's client of a document a restore found gone, whose
173
+ * deletion reached no one while the connection was down, as the server
174
+ * tells it of a deletion over a live connection. Without it, the restore
175
+ * reports the unsaved text such a document took with it as lost.
176
+ */
177
+ restoreDeletion?(event: TransferDocumentDeletedEvent): void;
178
+ /**
179
+ * Forget what the client was told of `uri`'s dirty state: an open just
180
+ * made answered its caller afresh, and the client heard none of it, or a
181
+ * close leaves nothing to restore. Forgetting a URI another session still
182
+ * has open costs at most one repeat of a state the client already has.
183
+ */
184
+ forgetDirty?(uri: string): void;
185
+ /**
186
+ * Fires with each flip of a document's dirty state the server sends. A
187
+ * session drops the unsaved write it keeps of a document that turns
188
+ * clean; without this event it keeps it, and a restore after another
189
+ * client's save of the document can report the write lost.
190
+ */
191
+ readonly onDidChangeDirty?: Event<TransferDocumentDirtyChangedEvent>;
192
+ /**
193
+ * Fires with each update event the server sends. A session drops the
194
+ * unsaved write it keeps of a document another client wrote over; without
195
+ * this event it keeps it, and a restore reports the write lost.
196
+ */
197
+ readonly onDidUpdateDocument?: Event<TransferDocumentUpdatedEvent<TTransfer, DiagnosticOf<TServer>>>;
198
+ /**
199
+ * Fires with each deletion the server sends. A session forgets a document
200
+ * whose file was deleted; without this event it keeps it as open until a
201
+ * restore finds it gone.
202
+ */
203
+ readonly onDidDeleteDocument?: Event<TransferDocumentDeletedEvent>;
204
+ /** Where the session logs the documents it forgets as gone. */
205
+ readonly logger?: Logger;
40
206
  }
41
207
  /**
42
- * The host-invariant half of talking to the data head: everything above
43
- * {@link DataPort} that would otherwise be re-derived by every host
44
- * adapter.
208
+ * Builds the session `DataConnection.createSession` hands out, for an adopter
209
+ * that extends {@link DataSession}. The connection has minted `clientId` and
210
+ * checked it by then.
211
+ */
212
+ export type DataSessionFactory<TTransfer extends TransferElement, TServer extends DataServerProtocol<TTransfer, DiagnosticOf<TServer>>> = (clientId: string, host: DataSessionHost<TTransfer, TServer>, label: string) => DataSession<TTransfer, TServer>;
213
+ /**
214
+ * One participant on a data connection: a properties panel, a tree, a form
215
+ * editor. The client side of a server client session, registered over the
216
+ * wire under {@link clientId}.
217
+ *
218
+ * The session writes only what it has open: the server refuses its update or
219
+ * save of a document it has not opened with a `DocumentNotOpenError` code.
220
+ * Every call waits for the registration, so the first can be issued at once.
221
+ *
222
+ * Every document operation stamps {@link clientId} itself. A caller that
223
+ * passed its own could pass another participant's, and the server would
224
+ * attribute the write and close the document accordingly.
45
225
  *
46
- * Three jobs, and deliberately no fourth:
226
+ * {@link closeDocument}, {@link deleteDocument} and {@link dispose} first wait,
227
+ * up to {@link settleBeforeCloseMs}, for this session's calls still in flight
228
+ * on the URI, or on any URI for `dispose`: a save sent just before its close
229
+ * would otherwise reach the server after it, and fail as not open. An open or
230
+ * create of a URI called while a close or delete of it is under way is sent
231
+ * once that has answered, so the server takes them in the order they were
232
+ * called.
47
233
  *
48
- * 1. **Build the typed proxy** over the port's connection, with the framework's
49
- * wire prefix and its drift-proof client-method allowlist.
50
- * 2. **Own the readiness gate** — `waitForReady` once per connection, shared
51
- * across concurrent callers. A socket client can connect before the
52
- * workspace walk finishes, and an early request is then answered correctly
53
- * from an empty registry, which reads as a broken project tier rather than
54
- * as a race.
55
- * 3. **Own the reconnect policy**, by dropping its connection generation when
56
- * the port disposes and building a fresh one on the next request.
234
+ * After the connection drops, the session registers again under the same id,
235
+ * re-opens and re-watches what it had open, tells the client of their dirty
236
+ * state where it changed, and reports the documents whose unsaved edits did
237
+ * not survive; see {@link restore}. The connection does this at
238
+ * once for a session with documents open, and again once any later connection
239
+ * is ready, so a reconnect that failed is not left to the session's own next
240
+ * call; any session's next call does it too.
57
241
  *
58
- * It does **not** wrap the protocol methods; callers reach them through
59
- * {@link connected}. The one exception is {@link openDocument}, which exists
60
- * because the open/watch *order* is silently wrong the other way round — see
61
- * its own doc.
242
+ * A restarted server numbers versions afresh, so an update, save, persist or
243
+ * delete gated on a version is refused with a `ConflictError` and not sent
244
+ * when a restore ran between the call and its send. A restore that found the
245
+ * text the session last saw, at its version, refuses nothing. A call made
246
+ * later is not checked, so it takes its version from
247
+ * {@link onDidRestoreDocument}.
62
248
  *
63
- * Generic over the transfer root so this file names no grammar. An adopter
64
- * binds the concrete root (or the union of them, for a multi-grammar head) at
65
- * its own edge.
249
+ * Generic over the transfer root so this file names no grammar.
250
+ *
251
+ * `TServer` is bound to a server answering with ITS OWN diagnostic shape, read
252
+ * back off the parameter being bound. Simplifying that to
253
+ * `DataServerProtocol<TTransfer>` compiles and costs the wrappers their
254
+ * return type: every call through `TServer` would resolve against that looser
255
+ * bound, so an adopter's diagnostics would come back as the framework's and
256
+ * the document would have to be cast on the way out.
66
257
  */
67
- export declare class DataSession<TTransfer extends TransferElement> {
68
- protected readonly port: DataPort;
69
- protected readonly client: DataClientProtocol<TTransfer>;
70
- protected readonly methodNamespace: string;
71
- /** The current generation, or `undefined` before the first request / after a teardown. */
72
- protected generation?: Generation<TTransfer>;
73
- protected disposed: boolean;
74
- protected readonly portDisposeListener: {
75
- dispose(): void;
76
- };
77
- constructor(port: DataPort, client: DataClientProtocol<TTransfer>, options?: DataSessionOptions);
78
- /** The identity every request is made under — the port's, not a second one. */
79
- get clientId(): string;
258
+ export declare class DataSession<TTransfer extends TransferElement, TServer extends DataServerProtocol<TTransfer, DiagnosticOf<TServer>> = DataServerProtocol<TTransfer>> implements Disposable {
259
+ readonly clientId: string;
260
+ protected readonly host: DataSessionHost<TTransfer, TServer>;
261
+ readonly label: string;
80
262
  /**
81
- * The connected, READY server proxy.
82
- *
83
- * Returns the proxy rather than `void` on purpose. A reconnect replaces the
84
- * proxy, so a caller that cached one from an earlier call would go on
85
- * addressing a dead connection with no error — handing it back per call
86
- * makes the stale reference unrepresentable.
263
+ * How long {@link closeDocument}, {@link deleteDocument} and {@link dispose}
264
+ * wait for this session's calls in flight before going on anyway. Long,
265
+ * because a close sent while a save is still writing fails that save. It
266
+ * need not outlast the server's language-client settle after the write,
267
+ * which a close does not fail.
268
+ */
269
+ protected readonly settleBeforeCloseMs: number;
270
+ /**
271
+ * How long {@link whenWritesSettled} waits before going on anyway: well past
272
+ * the server's bound on the language-client settle it runs before answering
273
+ * an update. The update itself has no bound, so a server slower than that is
274
+ * taken as lost.
275
+ */
276
+ protected readonly settleWritesMs: number;
277
+ /**
278
+ * The clock {@link settleBeforeCloseMs} runs on. {@link DataSessionHost}
279
+ * carries no {@link Clock}, so a subclass replaces this field as it
280
+ * replaces the bound.
281
+ */
282
+ protected readonly clock: Clock;
283
+ /** URIs this session has open, re-opened after a reconnect. */
284
+ protected readonly openUris: Set<string>;
285
+ /**
286
+ * Per URI in {@link openUris}, or whose open answered and whose watch is
287
+ * still under way, the open it is under. A repeat open keeps it, as the
288
+ * server keeps its earlier open.
289
+ */
290
+ protected readonly opens: Map<string, DataSessionOpen<TTransfer, TServer>>;
291
+ /**
292
+ * Per URI, the opens of it this session has under way. Such a URI counts
293
+ * as open for {@link withOpenDocument}, which would otherwise close it
294
+ * under the open that is still being made.
295
+ */
296
+ protected readonly openings: Map<string, Set<DataSessionOpening<TTransfer, TServer>>>;
297
+ /**
298
+ * Per URI, the closes and deletes of it this session has under way, which
299
+ * an open or create called meanwhile waits for; see {@link trackEnding}.
300
+ */
301
+ protected readonly endings: Map<string, Promise<unknown>>;
302
+ /** Per URI written since its last save, what {@link restore} needs to write it again. */
303
+ protected readonly unsavedWrites: Map<string, DataSessionUnsavedWrite<TTransfer, TServer>>;
304
+ /**
305
+ * Per URI this session has open, the text of the last document one of its
306
+ * own calls was answered with, or another client's update event named. It
307
+ * spares the read a first unsaved write otherwise makes for its base, see
308
+ * {@link baseHashOf}, and lets a restore that finds it refuse nothing.
309
+ */
310
+ protected readonly lastAnswers: Map<string, TextState>;
311
+ /**
312
+ * Per URI this session has open, the text version its last save or persist
313
+ * of it wrote, as its answer's `persisted` says; see {@link recordWrite}.
314
+ * Not the answer's model version, which can carry a write that landed
315
+ * after the text was taken. Only those set it: an open answers at the
316
+ * version of a write still in flight as well, and that write is not saved.
317
+ */
318
+ protected readonly savedVersions: Map<string, number>;
319
+ /**
320
+ * URIs this session created whose whole text is still its own and unsaved,
321
+ * even with no write recorded: no save, clean flip, other client's write or
322
+ * reported loss has come since the create, its answer included; see
323
+ * {@link forgetGoneDocument}.
324
+ */
325
+ protected readonly createdUris: Set<string>;
326
+ /** Per URI, this session's calls still in flight on it, which a close or delete waits for. */
327
+ protected readonly inFlight: Map<string, PendingWorkTracker>;
328
+ /** This session's saves, persists and deletes still in flight, which a host's exit waits for; see {@link hasSavesInFlight}. */
329
+ protected readonly savesInFlight: PendingWorkTracker;
330
+ /** This session's updates still in flight, which a page's unload guard and save account for; see {@link hasWritesInFlight}. */
331
+ protected readonly writesInFlight: PendingWorkTracker;
332
+ protected readonly disposeEmitter: Emitter<void>;
333
+ /**
334
+ * Fires once when the session ends, by {@link dispose} or {@link detach}, as
335
+ * soon as it rejects further calls and before any close is sent. For a
336
+ * session its connection created, the connection's listener runs first, so
337
+ * the id is free again on that connection by the time any other listener
338
+ * runs; the server still holds it until the close arrives, and refuses a new
339
+ * session under it until then.
87
340
  *
88
- * Concurrent callers share one readiness promise, so `waitForReady` is
89
- * awaited once per generation and not once per caller.
341
+ * A listener subscribed once the session has ended is never called, so a
342
+ * late subscriber checks {@link isDisposed} first.
90
343
  */
91
- connected(): Promise<RpcProxy<DataServerProtocol<TTransfer>>>;
344
+ readonly onDidDispose: Event<void>;
92
345
  /**
93
- * Open `uri` for editing and start watching it, in that order, returning
94
- * the opened snapshot.
346
+ * Per URI, the restores whose event has fired. A call gated on a version
347
+ * from before one is refused, see {@link refuseAcrossRestore}.
348
+ */
349
+ protected readonly restores: Map<string, number>;
350
+ /** Fires {@link onDidRestoreDocument}. */
351
+ protected readonly restoreEmitter: Emitter<DataSessionRestoreEvent<TTransfer, TServer>>;
352
+ /**
353
+ * Fires for each document a restore after a reconnect opened again, and
354
+ * for each it could not open again and did not find deleted. No update
355
+ * event tells of a change made while the connection was down, and a
356
+ * restarted server numbers versions afresh, so a client that keeps a
357
+ * document or its version takes them from here. A call gated on a version
358
+ * and made before this fires is refused, unless the restore found the text
359
+ * the session last saw, at its version.
360
+ */
361
+ readonly onDidRestoreDocument: Event<DataSessionRestoreEvent<TTransfer, TServer>>;
362
+ /**
363
+ * Sent with every registration, so the server lets this session register
364
+ * its id again while the dropped connection's session is still live there:
365
+ * a server that has not yet noticed the drop would otherwise refuse the id
366
+ * as a duplicate until it does.
367
+ */
368
+ protected readonly resumeToken: string;
369
+ /** The proxy the session is registered on; another one means the connection was replaced. */
370
+ protected registeredOn?: RpcProxy<TServer>;
371
+ /** The registration on {@link registeredOn}, which {@link connected} awaits. Replaced when the proxy changes. */
372
+ protected registration?: Promise<void>;
373
+ /** Set by {@link dispose} or {@link detach}, whichever comes first, after which {@link assertLive} throws. */
374
+ protected disposed: boolean;
375
+ /**
376
+ * Disposed through {@link detach} rather than {@link dispose}, so nothing may
377
+ * be sent. Folding it into {@link disposed} would send the session's close
378
+ * over a connection that is going away.
379
+ */
380
+ protected detached: boolean;
381
+ /**
382
+ * Write sets, keyed as a restore groups them, that lost a document to
383
+ * another client's deletion. A restore cannot write such a set again
384
+ * whole, so it writes none of it. Weak, so a set goes once no write
385
+ * record holds it.
386
+ */
387
+ protected readonly brokenSets: WeakSet<object>;
388
+ /** The subscription to the host's `onDidChangeDirty`, disposed with the session. */
389
+ protected readonly dirtySubscription?: Disposable;
390
+ /** The subscription to the host's `onDidUpdateDocument`, disposed with the session. */
391
+ protected readonly updateSubscription?: Disposable;
392
+ /** The subscription to the host's `onDidDeleteDocument`, disposed with the session. */
393
+ protected readonly deletionSubscription?: Disposable;
394
+ /** The host's logger, or one that logs nothing. */
395
+ protected readonly logger: Logger;
396
+ constructor(clientId: string, host: DataSessionHost<TTransfer, TServer>, label: string);
397
+ /**
398
+ * The connected, READY server proxy once this session is registered on it,
399
+ * for protocol methods this session does not wrap. The proxy stamps
400
+ * nothing: pass this session's {@link clientId} to any method that carries
401
+ * one.
402
+ */
403
+ connected(): Promise<RpcProxy<TServer>>;
404
+ /**
405
+ * Open `args.uri` for editing and start watching it, in that order,
406
+ * returning the opened snapshot.
95
407
  *
96
408
  * **The order is the whole reason this method exists.**
97
409
  * `watchModelDocument` baselines its dedup fingerprint from the *current*
@@ -99,39 +411,400 @@ export declare class DataSession<TTransfer extends TransferElement> {
99
411
  * baseline, and the first phase event after the open arrives as a spurious
100
412
  * `'changed'` — which a widget that resets its in-memory root to the server
101
413
  * view misreads as a concurrent third-party write, losing whatever the user
102
- * had typed. Nothing about the wrong order fails loudly, so it is encoded
103
- * here rather than documented and re-derived.
414
+ * had typed.
104
415
  *
105
- * Note that the returned snapshot's empty `diagnostics` does not mean
106
- * valid: `open` settles at the integrity landmark, not at validation.
416
+ * Note that the returned snapshot's model usually has no `diagnostics`:
417
+ * `open` settles at the integrity landmark, not at validation.
107
418
  * Validity arrives asynchronously on `onDocumentUpdated`, or synchronously
108
419
  * from `getModelDocument({ includeDiagnostics: true })`.
109
420
  */
110
- openDocument(uri: string): Promise<TransferDocument<TTransfer>>;
421
+ openDocument(args: DataSessionOpenArgs<TTransfer, TServer>): Promise<DataSessionDocument<TTransfer, TServer>>;
422
+ /**
423
+ * Create a document that exists nowhere yet, open and watched for this
424
+ * session; it reaches disk with the first {@link saveDocument}. The server
425
+ * refuses a URI that exists on disk or that any client has open. The answer
426
+ * names the version the create made in `created`, which a write of what
427
+ * this session created is based on: the answered model can already be
428
+ * another client's write or an integrity repair.
429
+ */
430
+ createDocument(args: DataSessionCreateArgs<TTransfer, TServer>): Promise<TransferCreatedDocument<TTransfer, DiagnosticOf<TServer>>>;
111
431
  /**
112
- * Close `uri`. The server unwatches implicitly, so this is the dual of
113
- * {@link openDocument} and needs no separate unwatch.
432
+ * Send `open` and watch what it answered, again for as long as a deletion
433
+ * heard while the watch is under way closes that open: sent after the
434
+ * deletion, the open fails as an open of a gone file does, or opens the
435
+ * file that is back. `created` reads the version the create made off the
436
+ * answered document, or none for an open; see {@link watchOpened} for the
437
+ * mark it puts in {@link createdUris}.
438
+ *
439
+ * An `opening` a close marked answers with the document, recording nothing
440
+ * and sending nothing again; one it marked before the open answered is
441
+ * undone, since the server may have taken the close first. A failed watch
442
+ * is undone too: the caller sees a failed open, and so would never close it.
443
+ */
444
+ protected openAndWatch<TDocument extends DataSessionDocument<TTransfer, TServer>>(uri: string, opening: DataSessionOpening<TTransfer, TServer>, created: (document: TDocument) => ModelVersion | undefined, open: (server: RpcProxy<TServer>) => Promise<TDocument>): Promise<TDocument>;
445
+ /**
446
+ * Watch a document this session just opened, and record it as open.
447
+ * Answers `undefined`, recording nothing, when a deletion heard while the
448
+ * watch is under way has ended the open already, and the document,
449
+ * recording nothing, when a close has. A failed watch rejects with the open
450
+ * still recorded, for its caller to undo, see {@link undoOpen}.
451
+ *
452
+ * A document created at `createdVersion` is marked in {@link createdUris}
453
+ * while its text is still at that version: a version past it is another's,
454
+ * a write or a repair, as a changed event would have said. Marked before the
455
+ * watch, so an event heard while it is under way clears the mark for good,
456
+ * and checked again against the text the watch answered, which an event
457
+ * sent before the watch was in place moved on unheard. The restore's
458
+ * re-open is the one other point the session learns of the text without
459
+ * hearing the events between, and checks the mark the same way. An answer
460
+ * without text leaves the mark as it is, at every one of the three.
461
+ */
462
+ protected watchOpened<TDocument extends DataSessionDocument<TTransfer, TServer>>(server: RpcProxy<TServer>, uri: string, document: TDocument, createdVersion?: ModelVersion): Promise<TDocument | undefined>;
463
+ /**
464
+ * Close `args.uri`, once this session's calls on it have settled or
465
+ * {@link settleBeforeCloseMs} has passed. The server unwatches implicitly,
466
+ * so this is the dual of {@link openDocument} and needs no separate unwatch.
467
+ */
468
+ closeDocument(args: DataSessionCloseArgs<TTransfer, TServer>): Promise<void>;
469
+ /**
470
+ * Close `uri` again after `opening` failed or was closed while under way,
471
+ * and drop what it recorded, unless the session still relies on the open,
472
+ * see {@link hasOpen}: the server holds one open per session and URI, so
473
+ * the close would end that one too.
474
+ */
475
+ protected undoOpen(server: RpcProxy<TServer>, uri: string, opening: DataSessionOpening<TTransfer, TServer>): Promise<void>;
476
+ /** Drop everything this session keeps of `uri`, which it no longer has open. */
477
+ protected forgetDocument(uri: string): void;
478
+ /**
479
+ * Whether this session has `uri` open, or has an open of it under way that
480
+ * no close has marked, other than `except`. A marked open records nothing,
481
+ * so nothing can rely on it.
482
+ */
483
+ protected hasOpen(uri: string, except?: DataSessionOpening<TTransfer, TServer>): boolean;
484
+ /**
485
+ * Open `args.uri`, run `fn` with the opened snapshot, and close it once
486
+ * `fn` settles, whether it returned or threw. A URI this session already
487
+ * had open, or is still opening through another call, stays open: the close
488
+ * undoes only the open this call made.
489
+ */
490
+ withOpenDocument<T>(args: DataSessionOpenArgs<TTransfer, TServer>, fn: (document: DataSessionDocument<TTransfer, TServer>) => MaybePromise<T>): Promise<T>;
491
+ /**
492
+ * Write `args.model` back as this session. The session must have `args.uri`
493
+ * open. Refused unsent with a `ConflictError` when a restore ran between the
494
+ * call and its send, see the class doc.
114
495
  */
115
- closeDocument(uri: string): Promise<void>;
496
+ updateDocument(args: DataSessionUpdateArgs<TTransfer, TServer>): Promise<TransferWrittenDocument<TTransfer, DiagnosticOf<TServer>>>;
116
497
  /**
117
- * Whether `event.sourceClientId` identifies this session's own write.
498
+ * Write several documents this session has open, all or none: the server
499
+ * refuses the whole set, before any text applies, when one is stale or not
500
+ * open. Resolves to the documents in the order given. Refused unsent with a
501
+ * `ConflictError` when a restore ran between the call and its send.
502
+ */
503
+ updateDocuments(args: DataSessionUpdatesArgs<TTransfer, TServer>): Promise<TransferWrittenDocument<TTransfer, DiagnosticOf<TServer>>[]>;
504
+ /**
505
+ * Persist `args.model` to disk as this session. The session must have
506
+ * `args.uri` open. Refused unsent with a `ConflictError` when a restore
507
+ * ran between the call and its send, see the class doc.
508
+ */
509
+ saveDocument(args: DataSessionSaveArgs<TTransfer, TServer>): Promise<TransferSavedDocument<TTransfer, DiagnosticOf<TServer>>>;
510
+ /**
511
+ * Persist the text the server holds for `args.uri` as this session, with no
512
+ * model of its own. The session must have `args.uri` open. Refused unsent
513
+ * with a `ConflictError` when a restore ran between the call and its send.
514
+ */
515
+ persistDocument(args: DataSessionPersistArgs<TTransfer, TServer>): Promise<TransferSavedDocument<TTransfer, DiagnosticOf<TServer>>>;
516
+ /**
517
+ * Delete `args.uri` as this session, at once: its file, then the document.
518
+ * The session must have `args.uri` open. Sent once this session's calls in
519
+ * flight on the URI have settled, as {@link closeDocument} is, and counted
520
+ * in {@link hasSavesInFlight} until it answers.
521
+ *
522
+ * The session forgets the document once the delete has succeeded: on
523
+ * hearing its own deletion, which the server sends before it answers, or
524
+ * on the answer, for a client that hears no deletions. A refused delete
525
+ * leaves the document open, as the server does. Refused unsent with a
526
+ * `ConflictError` when a restore ran between the call and its send.
527
+ */
528
+ deleteDocument(args: DataSessionDeleteArgs<TTransfer, TServer>): Promise<void>;
529
+ /** Run a save or persist of `uri` and record what it answered as saved. */
530
+ protected trackSave(uri: string, baseVersion: BaseVersion, send: (server: RpcProxy<TServer>) => Promise<TransferSavedDocument<TTransfer, DiagnosticOf<TServer>>>): Promise<TransferSavedDocument<TTransfer, DiagnosticOf<TServer>>>;
531
+ /** Whether the session has ended, by {@link dispose} or {@link detach}. */
532
+ get isDisposed(): boolean;
533
+ /**
534
+ * Whether a save, persist or delete of this session has not answered yet.
535
+ * Synchronous, for a host whose exit veto must decide within the tick, such
536
+ * as Theia's `onWillStop`.
537
+ */
538
+ get hasSavesInFlight(): boolean;
539
+ /**
540
+ * Resolves once the saves in flight now have answered, or
541
+ * {@link settleBeforeCloseMs} has passed. Never rejects: a failed save has
542
+ * answered too.
543
+ */
544
+ whenSavesSettled(): Promise<void>;
545
+ /**
546
+ * Whether an update of this session, one a restore sends again included,
547
+ * has not answered yet. The server answers once an editor on the language
548
+ * client holds the text, so a page that reads unsaved work from its editor
549
+ * guards a reload on this too. Synchronous, for an unload guard that must
550
+ * decide within the tick.
551
+ */
552
+ get hasWritesInFlight(): boolean;
553
+ /**
554
+ * Resolves to `true` once the updates in flight now have answered, so a
555
+ * save of the editor's documents started after it includes them, or to
556
+ * `false` once {@link settleWritesMs} has passed first. An update sent while
557
+ * it waits is not waited for. Never rejects.
558
+ */
559
+ whenWritesSettled(): Promise<boolean>;
560
+ /**
561
+ * Whether `sourceClientId` identifies this session's own write.
118
562
  *
119
563
  * Every watcher needs this and the check is one comparison, so getting it
120
564
  * wrong is cheap to do and expensive to find: an unfiltered echo looks
121
565
  * exactly like a concurrent third-party edit.
122
566
  */
123
567
  isOwnEcho(sourceClientId: string): boolean;
124
- /** Tear down the current connection and stop tracking the port. Idempotent. */
568
+ /**
569
+ * End the session: detach it from the connection at once, and once its
570
+ * calls in flight have settled or {@link settleBeforeCloseMs} has passed,
571
+ * end it on the server, which closes everything it has open. Idempotent,
572
+ * and leaves the connection usable by its other sessions.
573
+ *
574
+ * Every later call rejects, and so does a call made earlier in the same
575
+ * tick, which has not reached the wire yet and is never sent. The server
576
+ * close is not awaited, because a `Disposable` cannot be; a close that fails
577
+ * leaves the session to the server's connection-close cleanup.
578
+ */
125
579
  dispose(): void;
126
- /** The live generation, building one if there is none. */
127
- protected currentGeneration(): Generation<TTransfer>;
128
- /** Await the connection and the server's startup gate for one generation. */
129
- protected awaitReady(generation: Generation<TTransfer>): Promise<void>;
130
580
  /**
131
- * Discard the current generation, disposing its connection if it opened.
132
- * The next {@link connected} builds a fresh one.
581
+ * Come off the connection because it is going away.
582
+ *
583
+ * Sends nothing, unlike {@link dispose}: the server ends every session on a
584
+ * connection it sees close, and the close would travel over the very
585
+ * connection being disposed.
586
+ *
587
+ * Public because the connection calls it; anyone else ends a session with
588
+ * {@link dispose}. It fires {@link onDidDispose} only if the session has not
589
+ * already ended, and after {@link dispose} it still cancels the close that
590
+ * dispose has not sent yet.
591
+ */
592
+ detach(): void;
593
+ /**
594
+ * Dispose {@link dirtySubscription}, {@link updateSubscription} and
595
+ * {@link deletionSubscription}, fire {@link onDidDispose} and dispose its
596
+ * emitter, so a second call fires nothing.
597
+ */
598
+ protected fireDispose(): void;
599
+ /**
600
+ * Register again and restore now, after the connection dropped, instead of
601
+ * on the next call. A no-op for a session with nothing open, which the next
602
+ * call restores anyway, and for one already registered on the current
603
+ * connection. A failure is retried on the connection's next ready
604
+ * generation; a call before then meets it again.
605
+ */
606
+ reconnect(): void;
607
+ /**
608
+ * Drop the record in {@link unsavedWrites} of a document this session has
609
+ * open once the server says it turned clean, and its mark in
610
+ * {@link createdUris}: it holds no unsaved text then, and a record kept
611
+ * would have a restore report the write lost once another client's save
612
+ * changed the file.
613
+ *
614
+ * The server sends a flip only for a document someone watches, so a
615
+ * document the session writes without watching it keeps its record, and
616
+ * can still be reported lost that way.
617
+ */
618
+ protected forgetSavedWrite(event: TransferDocumentDirtyChangedEvent): void;
619
+ /**
620
+ * Drop the record in {@link unsavedWrites} of a document another client
621
+ * wrote over while the connection held: its write replaced the session's,
622
+ * so a restore has nothing of the session's to put back, and a record kept
623
+ * would have it report the write lost to the reconnect. A write superseded
624
+ * before its answer needs nothing: the answer names the other client's
625
+ * text, which the record then holds.
626
+ *
627
+ * Only a `'changed'` event from another client counts, and only where the
628
+ * document no longer holds the write: the session's own echo, and an
629
+ * integrity repair already in the write's answer, replaced nothing, and a
630
+ * `'rebuilt'` event carries no new text. Like {@link forgetSavedWrite}, it
631
+ * depends on the server sending the event, which it does only for a
632
+ * document someone watches.
633
+ *
634
+ * The mark in {@link createdUris} goes on any such event: the unsaved text
635
+ * is then the other client's, and a record still kept reports the
636
+ * session's own. Its text goes in {@link lastAnswers} unless that holds a
637
+ * later version, so a restore that finds it counts no change.
638
+ */
639
+ protected forgetSupersededWrite(event: TransferDocumentUpdatedEvent<TTransfer, DiagnosticOf<TServer>>): void;
640
+ /**
641
+ * Forget a document whose file was deleted, which closed this session's
642
+ * open. At once rather than after the calls in flight settle, which would
643
+ * let a restore re-open the file that is gone. Unwatched rather than
644
+ * closed: the server keeps the watch, and a close could end a re-open of a
645
+ * re-created file still in flight. Unsaved writes are logged, not
646
+ * reported: the client hears the deletion too. A document this session
647
+ * created and never saved, deleted by no session, is reported as well: a
648
+ * drop released it. An unsaved write breaks the set it was written with,
649
+ * see {@link brokenSets}.
650
+ *
651
+ * This session's own deletion is neither unwatched nor logged as dropping
652
+ * unsaved text: its delete released the watch, and its caller chose to
653
+ * drop the text.
654
+ */
655
+ protected forgetDeletedDocument(event: TransferDocumentDeletedEvent): void;
656
+ /**
657
+ * {@link forgetDocument} a document that is gone, logging any unsaved text
658
+ * it drops, written or created; returns whether it dropped some.
659
+ */
660
+ protected forgetGoneDocument(uri: string): boolean;
661
+ /**
662
+ * Register on `server`, and after a reconnect restore what the ended session
663
+ * had. Calls issued meanwhile wait for this.
664
+ */
665
+ protected register(server: RpcProxy<TServer>, reconnected: boolean): Promise<void>;
666
+ /** The restores of `uri` whose event has fired. */
667
+ protected restoresOf(uri: string): number;
668
+ /**
669
+ * Tell the listeners of a restore of `uri`, and count it when `counted`.
670
+ * Counted just before, so a call made with the version the event hands out
671
+ * is taken, and one made before it, which can only hold the old server's,
672
+ * is refused. A re-open that found the text the session last saw, at its
673
+ * version, is not counted, since a version from before still names it.
674
+ */
675
+ protected fireRestored(event: DataSessionRestoreEvent<TTransfer, TServer>, counted?: boolean): void;
676
+ /**
677
+ * Refuse a call gated on `baseVersion` if `uri` was restored since the
678
+ * call was made, when its count in {@link restores} was `restores`. A
679
+ * restarted server numbers versions afresh, so the version can match text
680
+ * the caller never saw, and the server would take the call over it.
681
+ */
682
+ protected refuseAcrossRestore(restores: number, uri: string, baseVersion: BaseVersion, message?: typeof STALE_BASE_VERSION_UPDATE | typeof STALE_BASE_VERSION_SAVE): void;
683
+ /**
684
+ * Re-open, each under the options its {@link DataSessionOpen} holds, and
685
+ * re-watch every document the session had open, write again what it wrote
686
+ * since their last save where the re-open lost it, and tell the host which
687
+ * of them lost it for good.
688
+ *
689
+ * Decided per document by the re-opened document's `text.hash`,
690
+ * in {@link restoreOutcome}. Versions cannot decide a write: a revert moves
691
+ * the version on and a restarted server numbers afresh, so the version the
692
+ * last write was answered with never matches where a write is needed, and
693
+ * any other version may be another client's edit, which a write would
694
+ * overwrite.
695
+ *
696
+ * Only what the drop cost is reported: a write another client wrote over
697
+ * while the connection held has no record left by then, see
698
+ * {@link forgetSupersededWrite}.
699
+ *
700
+ * A write is sent again based on the re-opened version, as an ordinary
701
+ * write, so an edit arriving in between conflicts, and a conflict is not
702
+ * retried. Documents last written by one {@link updateDocuments} are sent
703
+ * again by one, and only when every one of them may be; a document that
704
+ * could not be re-opened, or that another client deleted, blocks its set.
705
+ *
706
+ * No caller is waiting, so the outcomes go through the host: one report
707
+ * naming every document whose unsaved text is gone, whose record is then
708
+ * dropped, and one per document that could not be re-opened or written
709
+ * again for another reason than a conflict. A document that could not be
710
+ * re-opened is forgotten; a failed write keeps its record, for the next
711
+ * restore to decide again. A document closed while the restore runs, or
712
+ * whose file is deleted then, is neither restored nor reported. One gone
713
+ * while the connection was down, which the server reads back without a
714
+ * model, is forgotten, and its deletion goes to the host as the deletion
715
+ * no event brought; unsaved text it took with it is logged, as for a
716
+ * deletion heard live, and reported as well for a document the session
717
+ * created and never saved, which the drop released. A host that cannot
718
+ * tell the client has the unsaved text of either reported. Once the session
719
+ * is disposed, its caller has ended it, and the restore returns at its
720
+ * next await: nothing more goes to the server or the host.
721
+ *
722
+ * Each document's dirty state goes to the host too, read once the watch is
723
+ * in place and any write is sent: a flip while the connection was down, or
724
+ * between the re-open and the watch, reached no one, and the re-open's own
725
+ * answer misses the second. Read before the write, it would tell the client
726
+ * a document is clean that the write is about to make dirty again.
727
+ */
728
+ protected restore(server: RpcProxy<TServer>): Promise<void>;
729
+ /**
730
+ * Whether the re-opened `document` still holds the session's unsaved
731
+ * `write` (`'kept'`), holds the text the write started from, so the write
732
+ * can be sent again (`'resend'`), or holds something else (`'lost'`).
733
+ *
734
+ * A document without `text` comes from a server that sends none, and
735
+ * counts as kept only at the version the write was answered with. One
736
+ * without a model has no version to send the write again on.
737
+ */
738
+ protected restoreOutcome(write: DataSessionUnsavedWrite<TTransfer, TServer>, document: DataSessionDocument<TTransfer, TServer>): 'kept' | 'resend' | 'lost';
739
+ /**
740
+ * Write again, in one call and based on their `reopened` versions, the
741
+ * `members` of one write call that the re-open lost, all or none. Returns
742
+ * the URIs whose unsaved text is gone, and drops their records, and the
743
+ * record of a member that could not be re-opened.
744
+ *
745
+ * A member whose record is no longer the one the restore started with was
746
+ * closed, saved or disposed meanwhile, and is left out: writing it would
747
+ * put back text its caller discarded. A set in {@link brokenSets} is
748
+ * not written again.
749
+ *
750
+ * Sent as a `restore`: a model the server took was written over text that
751
+ * parsed, so it is complete even where the reopened text does not parse.
752
+ */
753
+ protected reapply(server: RpcProxy<TServer>, members: readonly [string, DataSessionUnsavedWrite<TTransfer, TServer>][], reopened: ReadonlyMap<string, DataSessionDocument<TTransfer, TServer>>): Promise<string[]>;
754
+ /**
755
+ * The text hash of the version `baseVersion` names for `uri`, for a write that
756
+ * starts the URI's record in {@link unsavedWrites}; `undefined` for any
757
+ * other write, whose record keeps the base it has.
758
+ *
759
+ * Taken from {@link lastAnswers} when that is at the version, otherwise
760
+ * read, and kept only when the read answers that version: a server's text
761
+ * changes only with its version, so the text at a version is the text the
762
+ * write, once it passes the gate, was applied to.
763
+ */
764
+ protected baseHashOf(server: RpcProxy<TServer>, uri: string, baseVersion: BaseVersion): Promise<string | undefined>;
765
+ /**
766
+ * Record `document` as the answer to a write of `uri` sent under `open`,
767
+ * keeping the base of the URI's record if it has one. An answer sent under
768
+ * no open, or under one that has ended, is ignored. So is one numbered below
769
+ * the record's: two writes of `uri` in flight at once may answer out of
770
+ * order, and the record holds the one applied last.
771
+ *
772
+ * So is one numbered at or below the URI's entry in {@link savedVersions}.
773
+ * The save came after that write was applied, so the save persisted its
774
+ * text or a later write replaced it, and its answer carries the text as it
775
+ * was when sent, which a restore would report as lost.
776
+ */
777
+ protected recordWrite(uri: string, open: DataSessionOpen<TTransfer, TServer> | undefined, document: DataSessionDocument<TTransfer, TServer>, baseHash: string | undefined, call: DataSessionUnsavedWrite<TTransfer, TServer>['call']): void;
778
+ /**
779
+ * What {@link DataSessionUnsavedWrite.answer} keeps of `document`. Every write
780
+ * and open answers with a model; one without is reported and counted older
781
+ * than every version, so it never replaces a real answer.
782
+ */
783
+ protected answerOf(uri: string, document: DataSessionDocument<TTransfer, TServer>): DataSessionUnsavedWrite<TTransfer, TServer>['answer'];
784
+ /** Keep `document`'s text in {@link lastAnswers}, or forget it for a server that sends none. */
785
+ protected recordText(uri: string, document: DataSessionDocument<TTransfer, TServer>): void;
786
+ /** Run `call`, counted as in flight on each of `uris` until it settles. */
787
+ protected track<T>(uris: readonly string[], call: () => Promise<T>): Promise<T>;
788
+ /** {@link track} an update of `uris`, counted in {@link writesInFlight} too. */
789
+ protected trackWrite<T>(uris: readonly string[], call: () => Promise<T>): Promise<T>;
790
+ /**
791
+ * {@link track} an open of `uri`, kept in {@link openings} until it settles,
792
+ * and sent once the closes and deletes of `uri` called before it have
793
+ * answered.
794
+ */
795
+ protected trackOpen<T>(uri: string, options: DataSessionOpenOptions<TTransfer, TServer>, call: (opening: DataSessionOpening<TTransfer, TServer>) => Promise<T>): Promise<T>;
796
+ /**
797
+ * Run `end`, a close or delete of `uri`, kept in {@link endings} until it
798
+ * and every earlier one of `uri` have settled.
799
+ */
800
+ protected trackEnding(uri: string, end: () => Promise<void>): Promise<void>;
801
+ /** Wait until the work `trackers` hold now has settled, or {@link settleBeforeCloseMs} has passed. */
802
+ protected settle(trackers: Iterable<PendingWorkTracker | undefined>): Promise<void>;
803
+ /**
804
+ * Throw a `SessionClosedError` once the session has ended. {@link connected}
805
+ * runs it again after each of its waits, since a session disposed during
806
+ * one would otherwise register or send after the close.
133
807
  */
134
- protected dropGeneration(): void;
808
+ protected assertLive(): void;
135
809
  }
136
- export {};
137
810
  //# sourceMappingURL=data-session.d.ts.map