@hydranium/protocol 1.0.0-next.28 → 1.0.0-next.280

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