@hydranium/protocol 1.0.0-next.32 → 1.0.0-next.320

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