@hydranium/protocol 1.0.0-next.14 → 1.0.0-next.140

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 (172) hide show
  1. package/README.md +35 -1
  2. package/lib/client/data-connection.d.ts +150 -0
  3. package/lib/client/data-connection.d.ts.map +1 -0
  4. package/lib/client/data-connection.js +211 -0
  5. package/lib/client/data-connection.js.map +1 -0
  6. package/lib/client/data-events.d.ts +13 -1
  7. package/lib/client/data-events.d.ts.map +1 -1
  8. package/lib/client/data-events.js +21 -0
  9. package/lib/client/data-events.js.map +1 -1
  10. package/lib/client/data-port.d.ts +17 -22
  11. package/lib/client/data-port.d.ts.map +1 -1
  12. package/lib/client/data-session.d.ts +301 -80
  13. package/lib/client/data-session.d.ts.map +1 -1
  14. package/lib/client/data-session.js +425 -107
  15. package/lib/client/data-session.js.map +1 -1
  16. package/lib/client/index.d.ts +13 -8
  17. package/lib/client/index.d.ts.map +1 -1
  18. package/lib/client/index.js +13 -8
  19. package/lib/client/index.js.map +1 -1
  20. package/lib/client/message-relay.d.ts +9 -3
  21. package/lib/client/message-relay.d.ts.map +1 -1
  22. package/lib/client/message-relay.js +11 -5
  23. package/lib/client/message-relay.js.map +1 -1
  24. package/lib/client/post-message-transport.d.ts +64 -3
  25. package/lib/client/post-message-transport.d.ts.map +1 -1
  26. package/lib/client/post-message-transport.js +175 -1
  27. package/lib/client/post-message-transport.js.map +1 -1
  28. package/lib/client/rpc-connection.d.ts +149 -0
  29. package/lib/client/rpc-connection.d.ts.map +1 -0
  30. package/lib/client/rpc-connection.js +179 -0
  31. package/lib/client/rpc-connection.js.map +1 -0
  32. package/lib/client-ids.d.ts +45 -0
  33. package/lib/client-ids.d.ts.map +1 -0
  34. package/lib/client-ids.js +48 -0
  35. package/lib/client-ids.js.map +1 -0
  36. package/lib/clock.d.ts +38 -0
  37. package/lib/clock.d.ts.map +1 -1
  38. package/lib/clock.js +36 -1
  39. package/lib/clock.js.map +1 -1
  40. package/lib/data/data-protocol-methods.d.ts +4 -4
  41. package/lib/data/data-protocol-methods.d.ts.map +1 -1
  42. package/lib/data/data-protocol-methods.js +11 -1
  43. package/lib/data/data-protocol-methods.js.map +1 -1
  44. package/lib/data/data-server-protocol.d.ts +111 -31
  45. package/lib/data/data-server-protocol.d.ts.map +1 -1
  46. package/lib/data/events.d.ts +103 -14
  47. package/lib/data/events.d.ts.map +1 -1
  48. package/lib/data/requests.d.ts +67 -11
  49. package/lib/data/requests.d.ts.map +1 -1
  50. package/lib/errors.d.ts +163 -17
  51. package/lib/errors.d.ts.map +1 -1
  52. package/lib/errors.js +219 -22
  53. package/lib/errors.js.map +1 -1
  54. package/lib/glsp-save-model-actions.d.ts +50 -0
  55. package/lib/glsp-save-model-actions.d.ts.map +1 -0
  56. package/lib/glsp-save-model-actions.js +28 -0
  57. package/lib/glsp-save-model-actions.js.map +1 -0
  58. package/lib/index.d.ts +3 -0
  59. package/lib/index.d.ts.map +1 -1
  60. package/lib/index.js +6 -0
  61. package/lib/index.js.map +1 -1
  62. package/lib/latency-collector.d.ts +8 -4
  63. package/lib/latency-collector.d.ts.map +1 -1
  64. package/lib/latency-collector.js.map +1 -1
  65. package/lib/messages/index.d.ts +29 -0
  66. package/lib/messages/index.d.ts.map +1 -0
  67. package/lib/messages/index.js +58 -0
  68. package/lib/messages/index.js.map +1 -0
  69. package/lib/messages/primitives.d.ts +188 -0
  70. package/lib/messages/primitives.d.ts.map +1 -0
  71. package/lib/messages/primitives.js +161 -0
  72. package/lib/messages/primitives.js.map +1 -0
  73. package/lib/model-server.d.ts +60 -13
  74. package/lib/model-server.d.ts.map +1 -1
  75. package/lib/model-server.js +4 -2
  76. package/lib/model-server.js.map +1 -1
  77. package/lib/model-service/based-on.d.ts +57 -0
  78. package/lib/model-service/based-on.d.ts.map +1 -0
  79. package/lib/model-service/based-on.js +37 -0
  80. package/lib/model-service/based-on.js.map +1 -0
  81. package/lib/model-service/index.d.ts +1 -1
  82. package/lib/model-service/index.d.ts.map +1 -1
  83. package/lib/model-service/index.js +4 -5
  84. package/lib/model-service/index.js.map +1 -1
  85. package/lib/patch-merge.d.ts +28 -27
  86. package/lib/patch-merge.d.ts.map +1 -1
  87. package/lib/patch-merge.js +66 -22
  88. package/lib/patch-merge.js.map +1 -1
  89. package/lib/profile-session.d.ts +8 -4
  90. package/lib/profile-session.d.ts.map +1 -1
  91. package/lib/profile-session.js.map +1 -1
  92. package/lib/rpc/bind-rpc-methods.d.ts +29 -3
  93. package/lib/rpc/bind-rpc-methods.d.ts.map +1 -1
  94. package/lib/rpc/bind-rpc-methods.js +22 -3
  95. package/lib/rpc/bind-rpc-methods.js.map +1 -1
  96. package/lib/rpc/create-rpc-proxy.d.ts +7 -0
  97. package/lib/rpc/create-rpc-proxy.d.ts.map +1 -1
  98. package/lib/rpc/create-rpc-proxy.js +6 -1
  99. package/lib/rpc/create-rpc-proxy.js.map +1 -1
  100. package/lib/testing/catalogue-audit.d.ts +80 -0
  101. package/lib/testing/catalogue-audit.d.ts.map +1 -0
  102. package/lib/testing/catalogue-audit.js +94 -0
  103. package/lib/testing/catalogue-audit.js.map +1 -0
  104. package/lib/testing/data-doubles.d.ts +13 -12
  105. package/lib/testing/data-doubles.d.ts.map +1 -1
  106. package/lib/testing/data-doubles.js +19 -5
  107. package/lib/testing/data-doubles.js.map +1 -1
  108. package/lib/testing/fake-clock.d.ts +9 -1
  109. package/lib/testing/fake-clock.d.ts.map +1 -1
  110. package/lib/testing/fake-clock.js +54 -45
  111. package/lib/testing/fake-clock.js.map +1 -1
  112. package/lib/testing/index.d.ts +1 -0
  113. package/lib/testing/index.d.ts.map +1 -1
  114. package/lib/testing/index.js +4 -1
  115. package/lib/testing/index.js.map +1 -1
  116. package/lib/testing/node/index.d.ts +1 -0
  117. package/lib/testing/node/index.d.ts.map +1 -1
  118. package/lib/testing/node/index.js +2 -2
  119. package/lib/testing/node/index.js.map +1 -1
  120. package/lib/testing/node/message-port-pair.d.ts +25 -0
  121. package/lib/testing/node/message-port-pair.d.ts.map +1 -0
  122. package/lib/testing/node/message-port-pair.js +26 -0
  123. package/lib/testing/node/message-port-pair.js.map +1 -0
  124. package/lib/transfer-diagnostic.d.ts +33 -0
  125. package/lib/transfer-diagnostic.d.ts.map +1 -1
  126. package/lib/transfer-diagnostic.js +23 -0
  127. package/lib/transfer-diagnostic.js.map +1 -1
  128. package/lib/transfer-document.d.ts +22 -5
  129. package/lib/transfer-document.d.ts.map +1 -1
  130. package/lib/transfer-document.js +14 -1
  131. package/lib/transfer-document.js.map +1 -1
  132. package/package.json +11 -2
  133. package/src/client/data-connection.ts +288 -0
  134. package/src/client/data-events.ts +33 -1
  135. package/src/client/data-port.ts +17 -23
  136. package/src/client/data-session.ts +549 -126
  137. package/src/client/index.ts +13 -8
  138. package/src/client/message-relay.ts +29 -7
  139. package/src/client/post-message-transport.ts +219 -4
  140. package/src/client/rpc-connection.ts +244 -0
  141. package/src/client-ids.ts +49 -0
  142. package/src/clock.ts +56 -0
  143. package/src/data/data-protocol-methods.ts +11 -3
  144. package/src/data/data-server-protocol.ts +132 -31
  145. package/src/data/events.ts +109 -14
  146. package/src/data/requests.ts +71 -11
  147. package/src/errors.ts +259 -24
  148. package/src/glsp-save-model-actions.ts +59 -0
  149. package/src/index.ts +6 -0
  150. package/src/latency-collector.ts +8 -3
  151. package/src/messages/index.ts +36 -0
  152. package/src/messages/primitives.ts +271 -0
  153. package/src/model-server.ts +63 -18
  154. package/src/model-service/based-on.ts +63 -0
  155. package/src/model-service/index.ts +4 -5
  156. package/src/patch-merge.ts +90 -37
  157. package/src/profile-session.ts +9 -4
  158. package/src/rpc/bind-rpc-methods.ts +49 -4
  159. package/src/rpc/create-rpc-proxy.ts +14 -1
  160. package/src/testing/catalogue-audit.ts +111 -0
  161. package/src/testing/data-doubles.ts +42 -17
  162. package/src/testing/fake-clock.ts +62 -47
  163. package/src/testing/index.ts +4 -1
  164. package/src/testing/node/index.ts +2 -2
  165. package/src/testing/node/message-port-pair.ts +40 -0
  166. package/src/transfer-diagnostic.ts +40 -0
  167. package/src/transfer-document.ts +29 -6
  168. package/lib/model-service/args.d.ts +0 -64
  169. package/lib/model-service/args.d.ts.map +0 -1
  170. package/lib/model-service/args.js +0 -11
  171. package/lib/model-service/args.js.map +0 -1
  172. package/src/model-service/args.ts +0 -67
@@ -8,78 +8,159 @@
8
8
  * SPDX-License-Identifier: MIT
9
9
  ********************************************************************************/
10
10
  Object.defineProperty(exports, "__esModule", { value: true });
11
- exports.DataSession = void 0;
12
- const data_1 = require("../data");
13
- const rpc_1 = require("../rpc");
11
+ exports.DataSession = exports.DATA_SESSION_UNSAVED_LOST = exports.DATA_SESSION_RESTORE_FAILED = void 0;
12
+ const vscode_jsonrpc_1 = require("vscode-jsonrpc");
13
+ const clock_1 = require("../clock");
14
+ const errors_1 = require("../errors");
15
+ const primitives_1 = require("../messages/primitives");
14
16
  /**
15
- * The host-invariant half of talking to the data head: everything above
16
- * {@link DataPort} that would otherwise be re-derived by every host
17
- * adapter.
17
+ * A session could not re-open a document it had open after its connection
18
+ * dropped.
19
+ */
20
+ exports.DATA_SESSION_RESTORE_FAILED = (0, primitives_1.defineMessage)('hydranium/protocol/data-session-restore-failed', 'Could not restore {uri} after reconnecting to the data server: {detail}');
21
+ /**
22
+ * A session re-opened documents after its connection dropped whose version had
23
+ * moved on since the session's last unsaved write to them: another client
24
+ * edited them, even while the session was still connected, the server reverted
25
+ * them to what is on disk, or the server restarted. The session's unsaved edits
26
+ * may be gone.
27
+ */
28
+ exports.DATA_SESSION_UNSAVED_LOST = (0, primitives_1.defineMessage)('hydranium/protocol/data-session-unsaved-lost', 'Unsaved changes to {uris} may have been lost when the connection to the data server dropped.');
29
+ /**
30
+ * One participant on a data connection: a properties panel, a tree, a form
31
+ * editor. The client side of a server client session, registered over the
32
+ * wire under {@link clientId}.
18
33
  *
19
- * Three jobs, and deliberately no fourth:
34
+ * The session writes only what it has open: the server refuses its update or
35
+ * save of a document it has not opened with a `DocumentNotOpenError` code.
36
+ * Every call waits for the registration, so the first can be issued at once.
20
37
  *
21
- * 1. **Build the typed proxy** over the port's connection, with the framework's
22
- * wire prefix and its drift-proof client-method allowlist.
23
- * 2. **Own the readiness gate** — `waitForReady` once per connection, shared
24
- * across concurrent callers. A socket client can connect before the
25
- * workspace walk finishes, and an early request is then answered correctly
26
- * from an empty registry, which reads as a broken project tier rather than
27
- * as a race.
28
- * 3. **Own the reconnect policy**, by dropping its connection generation when
29
- * the port disposes and building a fresh one on the next request.
38
+ * Every document operation stamps {@link clientId} itself. A caller that
39
+ * passed its own could pass another participant's, and the server would
40
+ * attribute the write and close the document accordingly.
30
41
  *
31
- * It does **not** wrap the protocol methods; callers reach them through
32
- * {@link connected}. The one exception is {@link openDocument}, which exists
33
- * because the open/watch *order* is silently wrong the other way round — see
34
- * its own doc.
42
+ * {@link closeDocument} and {@link dispose} first wait, up to
43
+ * {@link settleBeforeCloseMs}, for this session's calls still in flight on the
44
+ * URI, or on any URI for `dispose`: a save sent just before its close would
45
+ * otherwise reach the server after it, and fail as not open.
35
46
  *
36
- * Generic over the transfer root so this file names no grammar. An adopter
37
- * binds the concrete root (or the union of them, for a multi-grammar head) at
38
- * its own edge.
47
+ * After the connection drops, the session registers again under the same id,
48
+ * re-opens and re-watches what it had open, tells the client of their dirty
49
+ * state where it changed, and reports the documents whose unsaved edits did
50
+ * not survive; see {@link restore}. The connection does this at
51
+ * once for a session with documents open, and any session's next call does it
52
+ * too.
53
+ *
54
+ * Generic over the transfer root so this file names no grammar.
55
+ *
56
+ * `TServer` is bound to a server answering with ITS OWN diagnostic shape, read
57
+ * back off the parameter being bound. Simplifying that to
58
+ * `DataServerProtocol<TTransfer>` compiles and costs the wrappers their
59
+ * return type: every call through `TServer` would resolve against that looser
60
+ * bound, so an adopter's diagnostics would come back as the framework's and
61
+ * the document would have to be cast on the way out.
39
62
  */
40
63
  class DataSession {
41
- port;
42
- client;
43
- methodNamespace;
44
- /** The current generation, or `undefined` before the first request / after a teardown. */
45
- generation;
64
+ clientId;
65
+ host;
66
+ label;
67
+ /**
68
+ * How long {@link closeDocument} and {@link dispose} wait for this session's
69
+ * calls in flight before closing anyway. Long, because the wait only runs
70
+ * out when a call hangs, and a close sent while a save is still running
71
+ * fails that save.
72
+ */
73
+ settleBeforeCloseMs = 10_000;
74
+ /**
75
+ * The clock {@link settleBeforeCloseMs} runs on. {@link DataSessionHost}
76
+ * carries no {@link Clock}, so a subclass replaces this field as it
77
+ * replaces the bound.
78
+ */
79
+ clock = new clock_1.SystemClock();
80
+ /** URIs this session has open, re-opened after a reconnect. */
81
+ openUris = new Set();
82
+ /**
83
+ * Per URI in {@link openUris}, the URI the server's last answer to its open
84
+ * or re-open named. The server keys its notifications by it, and so does
85
+ * the host's record of what its client was told.
86
+ */
87
+ serverUris = new Map();
88
+ /**
89
+ * Per URI, how many opens of it this session has under way. Such a URI
90
+ * counts as open for {@link withOpenDocument}, which would otherwise close
91
+ * it under the open that is still being made.
92
+ */
93
+ openingUris = new Map();
94
+ /**
95
+ * Per URI written since its last save, the version the server answered this
96
+ * session's last write with; see {@link restore}.
97
+ */
98
+ unsavedWrites = new Map();
99
+ /** Per URI, this session's calls still in flight on it, which a close waits for. */
100
+ inFlight = new Map();
101
+ /** This session's saves still in flight, which a host's exit waits for; see {@link hasSavesInFlight}. */
102
+ savesInFlight = new Set();
103
+ disposeEmitter = new vscode_jsonrpc_1.Emitter();
104
+ /**
105
+ * Fires once when the session ends, by {@link dispose} or {@link detach}, as
106
+ * soon as it rejects further calls and before any close is sent. For a
107
+ * session its connection created, the connection's listener runs first, so
108
+ * the id is free again on that connection by the time any other listener
109
+ * runs; the server still holds it until the close arrives, and refuses a new
110
+ * session under it until then.
111
+ *
112
+ * A listener subscribed once the session has ended is never called, so a
113
+ * late subscriber checks {@link isDisposed} first.
114
+ */
115
+ onDidDispose = this.disposeEmitter.event;
116
+ /**
117
+ * Sent with every registration, so the server lets this session register
118
+ * its id again while the dropped connection's session is still live there:
119
+ * a server that has not yet noticed the drop would otherwise refuse the id
120
+ * as a duplicate until it does.
121
+ */
122
+ resumeToken = globalThis.crypto.randomUUID();
123
+ /** The proxy the session is registered on; another one means the connection was replaced. */
124
+ registeredOn;
125
+ registration;
46
126
  disposed = false;
47
- portDisposeListener;
48
- constructor(port, client, options = {}) {
49
- this.port = port;
50
- this.client = client;
51
- this.methodNamespace = options.methodNamespace ?? data_1.DATA_SERVER_WIRE_PREFIX;
52
- this.portDisposeListener = this.port.onDispose(() => this.dropGeneration());
53
- }
54
- /** The identity every request is made under — the port's, not a second one. */
55
- get clientId() {
56
- return this.port.clientId;
127
+ /**
128
+ * Disposed through {@link detach} rather than {@link dispose}, so nothing may
129
+ * be sent. Folding it into {@link disposed} would send the session's close
130
+ * over a connection that is going away.
131
+ */
132
+ detached = false;
133
+ constructor(clientId, host, label) {
134
+ this.clientId = clientId;
135
+ this.host = host;
136
+ this.label = label;
57
137
  }
58
138
  /**
59
- * The connected, READY server proxy.
60
- *
61
- * Returns the proxy rather than `void` on purpose. A reconnect replaces the
62
- * proxy, so a caller that cached one from an earlier call would go on
63
- * addressing a dead connection with no error — handing it back per call
64
- * makes the stale reference unrepresentable.
65
- *
66
- * Concurrent callers share one readiness promise, so `waitForReady` is
67
- * awaited once per generation and not once per caller.
139
+ * The connected, READY server proxy once this session is registered on it,
140
+ * for protocol methods this session does not wrap. The proxy stamps
141
+ * nothing: pass this session's {@link clientId} to any method that carries
142
+ * one.
68
143
  */
69
144
  async connected() {
70
- if (this.disposed) {
71
- throw new Error('DataSession is disposed');
145
+ // `async` so a disposed session REJECTS rather than throwing
146
+ // synchronously: the connection's own `connected` rejects, and a caller
147
+ // reaching for `.catch` on one of them would not catch the other.
148
+ this.assertLive();
149
+ const server = await this.host.connected();
150
+ // Again after the wait: a session disposed meanwhile must not register,
151
+ // since its dispose found nothing registered to end.
152
+ this.assertLive();
153
+ if (this.registeredOn !== server) {
154
+ const reconnected = this.registeredOn !== undefined;
155
+ this.registeredOn = server;
156
+ this.registration = this.register(server, reconnected);
72
157
  }
73
- const generation = this.currentGeneration();
74
- if (!generation.ready) {
75
- generation.ready = this.awaitReady(generation);
76
- }
77
- await generation.ready;
78
- return generation.server;
158
+ await this.registration;
159
+ return server;
79
160
  }
80
161
  /**
81
- * Open `uri` for editing and start watching it, in that order, returning
82
- * the opened snapshot.
162
+ * Open `args.uri` for editing and start watching it, in that order,
163
+ * returning the opened snapshot.
83
164
  *
84
165
  * **The order is the whole reason this method exists.**
85
166
  * `watchModelDocument` baselines its dedup fingerprint from the *current*
@@ -87,30 +168,144 @@ class DataSession {
87
168
  * baseline, and the first phase event after the open arrives as a spurious
88
169
  * `'changed'` — which a widget that resets its in-memory root to the server
89
170
  * view misreads as a concurrent third-party write, losing whatever the user
90
- * had typed. Nothing about the wrong order fails loudly, so it is encoded
91
- * here rather than documented and re-derived.
171
+ * had typed.
92
172
  *
93
173
  * Note that the returned snapshot's empty `diagnostics` does not mean
94
174
  * valid: `open` settles at the integrity landmark, not at validation.
95
175
  * Validity arrives asynchronously on `onDocumentUpdated`, or synchronously
96
176
  * from `getModelDocument({ includeDiagnostics: true })`.
97
177
  */
98
- async openDocument(uri) {
99
- const server = await this.connected();
100
- const document = await server.openModelDocument({ uri, clientId: this.clientId });
101
- await server.watchModelDocument({ uri, clientId: this.clientId });
178
+ openDocument(args) {
179
+ return this.trackOpen(args.uri, async () => {
180
+ const server = await this.connected();
181
+ return this.watchOpened(server, args.uri, await server.openModelDocument({ ...args, clientId: this.clientId }));
182
+ });
183
+ }
184
+ /**
185
+ * Create a document that exists nowhere yet, open and watched for this
186
+ * session; it reaches disk with the first {@link saveDocument}. The server
187
+ * refuses a URI that exists on disk or that any client has open.
188
+ */
189
+ createDocument(args) {
190
+ return this.trackOpen(args.uri, async () => {
191
+ const server = await this.connected();
192
+ return this.watchOpened(server, args.uri, await server.createModelDocument({ ...args, clientId: this.clientId }));
193
+ });
194
+ }
195
+ /**
196
+ * Watch a document this session just opened, and record it as open. A
197
+ * failed watch closes it again: the caller sees a failed open and so would
198
+ * never close it.
199
+ */
200
+ async watchOpened(server, uri, document) {
201
+ try {
202
+ await server.watchModelDocument({ uri, clientId: this.clientId });
203
+ }
204
+ catch (error) {
205
+ await server.closeModelDocument({ uri, clientId: this.clientId }).catch(() => undefined);
206
+ throw error;
207
+ }
208
+ this.openUris.add(uri);
209
+ this.serverUris.set(uri, document.uri);
210
+ // Keyed as the server keys its notifications, which may not be how the
211
+ // caller spelled the URI.
212
+ this.host.forgetDirty?.(document.uri);
102
213
  return document;
103
214
  }
104
215
  /**
105
- * Close `uri`. The server unwatches implicitly, so this is the dual of
106
- * {@link openDocument} and needs no separate unwatch.
216
+ * Close `args.uri`, once this session's calls on it have settled or
217
+ * {@link settleBeforeCloseMs} has passed. The server unwatches implicitly,
218
+ * so this is the dual of {@link openDocument} and needs no separate unwatch.
107
219
  */
108
- async closeDocument(uri) {
220
+ async closeDocument(args) {
221
+ this.assertLive();
222
+ await this.settle(this.inFlight.get(args.uri));
223
+ // Forgotten before the close is sent, so a reconnect in between does not
224
+ // re-open a document the caller has closed; after the wait, so an open
225
+ // of it that was still in flight does not record it again.
226
+ const serverUri = this.serverUris.get(args.uri) ?? args.uri;
227
+ this.openUris.delete(args.uri);
228
+ this.serverUris.delete(args.uri);
229
+ this.unsavedWrites.delete(args.uri);
230
+ this.host.forgetDirty?.(serverUri);
109
231
  const server = await this.connected();
110
- await server.closeModelDocument({ uri, clientId: this.clientId });
232
+ await server.closeModelDocument({ ...args, clientId: this.clientId });
111
233
  }
112
234
  /**
113
- * Whether `event.sourceClientId` identifies this session's own write.
235
+ * Open `args.uri`, run `fn` with the opened snapshot, and close it once
236
+ * `fn` settles, whether it returned or threw. A URI this session already
237
+ * had open, or is still opening through another call, stays open: the close
238
+ * undoes only the open this call made.
239
+ */
240
+ async withOpenDocument(args, fn) {
241
+ const alreadyOpen = this.openUris.has(args.uri) || this.openingUris.has(args.uri);
242
+ const document = await this.openDocument(args);
243
+ try {
244
+ return await fn(document);
245
+ }
246
+ finally {
247
+ if (!alreadyOpen && !this.disposed) {
248
+ await this.closeDocument({ uri: args.uri });
249
+ }
250
+ }
251
+ }
252
+ /** Write `args.model` back as this session. The session must have `args.uri` open. */
253
+ updateDocument(args) {
254
+ return this.track([args.uri], async () => {
255
+ const server = await this.connected();
256
+ const document = await server.updateModelDocument({ ...args, clientId: this.clientId });
257
+ this.unsavedWrites.set(args.uri, document.version);
258
+ return document;
259
+ });
260
+ }
261
+ /**
262
+ * Write several documents this session has open, all or none: the server
263
+ * refuses the whole set, before any text applies, when one is stale or not
264
+ * open. Resolves to the documents in the order given.
265
+ */
266
+ updateDocuments(args) {
267
+ return this.track(args.updates.map(update => update.uri), async () => {
268
+ const server = await this.connected();
269
+ const documents = await server.updateModelDocuments({ ...args, clientId: this.clientId });
270
+ args.updates.forEach((update, i) => this.unsavedWrites.set(update.uri, documents[i].version));
271
+ return documents;
272
+ });
273
+ }
274
+ /** Persist `args.model` to disk as this session. The session must have `args.uri` open. */
275
+ saveDocument(args) {
276
+ const saving = this.track([args.uri], async () => {
277
+ const server = await this.connected();
278
+ const document = await server.saveModelDocument({ ...args, clientId: this.clientId });
279
+ this.unsavedWrites.delete(args.uri);
280
+ return document;
281
+ });
282
+ this.savesInFlight.add(saving);
283
+ const done = () => this.savesInFlight.delete(saving);
284
+ saving.then(done, done);
285
+ return saving;
286
+ }
287
+ /** Whether the session has ended, by {@link dispose} or {@link detach}. */
288
+ get isDisposed() {
289
+ return this.disposed;
290
+ }
291
+ /**
292
+ * Whether a save of this session has not answered yet. Synchronous, for a
293
+ * host whose exit veto must decide within the tick, such as Theia's
294
+ * `onWillStop`.
295
+ */
296
+ get hasSavesInFlight() {
297
+ return this.savesInFlight.size > 0;
298
+ }
299
+ /**
300
+ * Resolves once the saves in flight now have answered, or
301
+ * {@link settleBeforeCloseMs} has passed. Never rejects: a failed save has
302
+ * answered too.
303
+ */
304
+ whenSavesSettled() {
305
+ return this.settle(this.savesInFlight);
306
+ }
307
+ /**
308
+ * Whether `sourceClientId` identifies this session's own write.
114
309
  *
115
310
  * Every watcher needs this and the check is one comparison, so getting it
116
311
  * wrong is cheap to do and expensive to find: an unfiltered echo looks
@@ -119,60 +314,183 @@ class DataSession {
119
314
  isOwnEcho(sourceClientId) {
120
315
  return sourceClientId === this.clientId;
121
316
  }
122
- /** Tear down the current connection and stop tracking the port. Idempotent. */
317
+ /**
318
+ * End the session: detach it from the connection at once, and once its
319
+ * calls in flight have settled or {@link settleBeforeCloseMs} has passed,
320
+ * end it on the server, which closes everything it has open. Idempotent,
321
+ * and leaves the connection usable by its other sessions.
322
+ *
323
+ * Every later call rejects, and so does a call made earlier in the same
324
+ * tick, which has not reached the wire yet and is never sent. The server
325
+ * close is not awaited, because a `Disposable` cannot be; a close that fails
326
+ * leaves the session to the server's connection-close cleanup.
327
+ */
123
328
  dispose() {
124
329
  if (this.disposed) {
125
330
  return;
126
331
  }
127
332
  this.disposed = true;
128
- this.portDisposeListener.dispose();
129
- this.dropGeneration();
333
+ this.fireDispose();
334
+ const pending = [...this.inFlight.values()].flatMap(calls => [...calls]);
335
+ void (async () => {
336
+ await this.settle(pending);
337
+ await this.registration;
338
+ // The proxy the session registered on, never a fresh connection: a
339
+ // connection that dropped already ended the session on the server.
340
+ if (!this.detached && this.registeredOn) {
341
+ await this.registeredOn.closeSession({ clientId: this.clientId });
342
+ }
343
+ })().catch(() => undefined);
130
344
  }
131
- /** The live generation, building one if there is none. */
132
- currentGeneration() {
133
- if (this.generation) {
134
- return this.generation;
345
+ /**
346
+ * Come off the connection because it is going away.
347
+ *
348
+ * Sends nothing, unlike {@link dispose}: the server ends every session on a
349
+ * connection it sees close, and the close would travel over the very
350
+ * connection being disposed.
351
+ *
352
+ * Public because the connection calls it; anyone else ends a session with
353
+ * {@link dispose}. It fires {@link onDidDispose} only if the session has not
354
+ * already ended, and after {@link dispose} it still cancels the close that
355
+ * dispose has not sent yet.
356
+ */
357
+ detach() {
358
+ this.detached = true;
359
+ this.openUris.clear();
360
+ this.serverUris.clear();
361
+ this.unsavedWrites.clear();
362
+ if (!this.disposed) {
363
+ this.disposed = true;
364
+ this.fireDispose();
135
365
  }
136
- const connection = this.port.connect();
137
- // Rejection is reported here rather than left to float: an unhandled
138
- // rejection on a connection promise is the failure mode that reads as
139
- // "the model is empty" instead of "the transport never opened".
140
- connection.catch((error) => this.port.reportError(error, 'connecting to the data server'));
141
- const server = (0, rpc_1.createRpcProxy)(connection, {
142
- methodNamespace: this.methodNamespace,
143
- localTarget: this.client,
144
- localMethods: data_1.DATA_CLIENT_PROTOCOL_METHODS
145
- });
146
- this.generation = { connection, server };
147
- return this.generation;
148
366
  }
149
- /** Await the connection and the server's startup gate for one generation. */
150
- async awaitReady(generation) {
151
- try {
152
- await generation.connection;
153
- await generation.server.waitForReady();
367
+ /** Fire {@link onDidDispose} and dispose its emitter, so a second call fires nothing. */
368
+ fireDispose() {
369
+ this.disposeEmitter.fire(undefined);
370
+ this.disposeEmitter.dispose();
371
+ }
372
+ /**
373
+ * Register again and restore now, after the connection dropped, instead of
374
+ * on the next call. A no-op for a session with nothing open, which the next
375
+ * call restores anyway. A failure is left to that next call, which meets it
376
+ * again.
377
+ */
378
+ reconnect() {
379
+ if (!this.disposed && this.openUris.size > 0) {
380
+ this.connected().catch(() => undefined);
154
381
  }
155
- catch (error) {
156
- // Drop the generation so the next request retries rather than
157
- // re-awaiting a settled rejection forever.
158
- if (this.generation === generation) {
159
- this.generation = undefined;
160
- }
161
- this.port.reportError(error, 'waiting for the data server to become ready');
162
- throw error;
382
+ }
383
+ /**
384
+ * Register on `server`, and after a reconnect restore what the ended session
385
+ * had. Calls issued meanwhile wait for this.
386
+ */
387
+ async register(server, reconnected) {
388
+ await server.createSession({ clientId: this.clientId, label: this.label, resumeToken: this.resumeToken });
389
+ if (reconnected) {
390
+ await this.restore(server);
163
391
  }
164
392
  }
165
393
  /**
166
- * Discard the current generation, disposing its connection if it opened.
167
- * The next {@link connected} builds a fresh one.
394
+ * Re-open and re-watch every document the session had open, and tell the
395
+ * host which of them lost what the session wrote since their last save.
396
+ *
397
+ * The unsaved text is not sent again. A document whose re-opened version is
398
+ * the one the session's last write was answered with still holds that
399
+ * write. Any other version means the text changed after that write:
400
+ * another client edited it, even while the session was still connected;
401
+ * the server reverted it to disk when the session's open closed as the
402
+ * document's last; or the server restarted and numbers versions afresh.
403
+ * Re-sending based on the write's own version then always conflicts, and
404
+ * based on the re-opened version it would overwrite whatever changed, so
405
+ * neither is done.
406
+ *
407
+ * No caller is waiting, so both outcomes go through the host: one report
408
+ * naming every document whose unsaved text is gone, whose record is then
409
+ * dropped, and one per document that could not be re-opened, which is
410
+ * forgotten.
411
+ *
412
+ * Each document's dirty state goes to the host too, read once the watch is
413
+ * in place: a flip while the connection was down, or between the re-open
414
+ * and the watch, reached no one, and the re-open's own answer misses the
415
+ * second.
168
416
  */
169
- dropGeneration() {
170
- const generation = this.generation;
171
- this.generation = undefined;
172
- if (!generation) {
417
+ async restore(server) {
418
+ const lost = [];
419
+ for (const uri of [...this.openUris]) {
420
+ try {
421
+ const document = await server.openModelDocument({ uri, clientId: this.clientId });
422
+ await server.watchModelDocument({ uri, clientId: this.clientId });
423
+ if (this.openUris.has(uri)) {
424
+ this.serverUris.set(uri, document.uri);
425
+ }
426
+ // A failed read leaves the client's dirty state as it was; the
427
+ // document is restored all the same.
428
+ const current = await server.getModelDocument({ uri }).catch(() => undefined);
429
+ if (current?.dirty !== undefined) {
430
+ try {
431
+ this.host.restoreDirty?.({ uri: current.uri, dirty: current.dirty });
432
+ }
433
+ catch {
434
+ // The client's listener failed, not the restore: the server
435
+ // has the document open and watched, so it stays restored.
436
+ }
437
+ }
438
+ const written = this.unsavedWrites.get(uri);
439
+ if (written !== undefined && written !== document.version) {
440
+ lost.push(uri);
441
+ this.unsavedWrites.delete(uri);
442
+ }
443
+ }
444
+ catch (error) {
445
+ this.openUris.delete(uri);
446
+ this.serverUris.delete(uri);
447
+ this.unsavedWrites.delete(uri);
448
+ this.host.reportError?.(error, (0, primitives_1.resolve)(exports.DATA_SESSION_RESTORE_FAILED, { uri, detail: (0, primitives_1.describeError)(error) }));
449
+ }
450
+ }
451
+ if (lost.length > 0) {
452
+ const reported = (0, primitives_1.resolve)(exports.DATA_SESSION_UNSAVED_LOST, { uris: lost.join(', ') });
453
+ this.host.reportError?.(new Error(reported.text), reported);
454
+ }
455
+ }
456
+ /** Run `call`, counted as in flight on each of `uris` until it settles. */
457
+ track(uris, call) {
458
+ const running = call();
459
+ for (const uri of uris) {
460
+ this.inFlight.set(uri, (this.inFlight.get(uri) ?? new Set()).add(running));
461
+ }
462
+ const done = () => uris.forEach(uri => this.inFlight.get(uri)?.delete(running));
463
+ running.then(done, done);
464
+ return running;
465
+ }
466
+ /** {@link track} an open of `uri`, counted in {@link openingUris} until it settles. */
467
+ trackOpen(uri, call) {
468
+ this.openingUris.set(uri, (this.openingUris.get(uri) ?? 0) + 1);
469
+ const done = () => {
470
+ const remaining = (this.openingUris.get(uri) ?? 1) - 1;
471
+ if (remaining > 0) {
472
+ this.openingUris.set(uri, remaining);
473
+ }
474
+ else {
475
+ this.openingUris.delete(uri);
476
+ }
477
+ };
478
+ const running = this.track([uri], call);
479
+ running.then(done, done);
480
+ return running;
481
+ }
482
+ /** Wait until `calls` have settled, or {@link settleBeforeCloseMs} has passed. */
483
+ async settle(calls) {
484
+ const pending = [...(calls ?? [])];
485
+ if (pending.length === 0) {
173
486
  return;
174
487
  }
175
- generation.connection.then(connection => connection.dispose()).catch(() => undefined);
488
+ await this.clock.raceTimer(Promise.allSettled(pending), this.settleBeforeCloseMs);
489
+ }
490
+ assertLive() {
491
+ if (this.disposed) {
492
+ throw new errors_1.SessionClosedError(this.clientId);
493
+ }
176
494
  }
177
495
  }
178
496
  exports.DataSession = DataSession;
@@ -1 +1 @@
1
- {"version":3,"file":"data-session.js","sourceRoot":"","sources":["../../src/client/data-session.ts"],"names":[],"mappings":";AAAA;;;;;;;kFAOkF;;;AA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