@hydranium/protocol 1.0.0-next.27 → 1.0.0-next.270

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