@hydranium/protocol 1.0.0-next.35 → 1.0.0-next.350

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