@hydranium/protocol 1.0.0-next.12 → 1.0.0-next.123

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 (142) hide show
  1. package/README.md +35 -1
  2. package/lib/client/data-connection.d.ts +114 -0
  3. package/lib/client/data-connection.d.ts.map +1 -0
  4. package/lib/client/data-connection.js +143 -0
  5. package/lib/client/data-connection.js.map +1 -0
  6. package/lib/client/data-events.d.ts +9 -1
  7. package/lib/client/data-events.d.ts.map +1 -1
  8. package/lib/client/data-events.js +14 -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 +235 -82
  13. package/lib/client/data-session.d.ts.map +1 -1
  14. package/lib/client/data-session.js +337 -108
  15. package/lib/client/data-session.js.map +1 -1
  16. package/lib/client/index.d.ts +10 -7
  17. package/lib/client/index.d.ts.map +1 -1
  18. package/lib/client/index.js +10 -7
  19. package/lib/client/index.js.map +1 -1
  20. package/lib/client/message-relay.d.ts +8 -2
  21. package/lib/client/message-relay.d.ts.map +1 -1
  22. package/lib/client/message-relay.js +10 -4
  23. package/lib/client/message-relay.js.map +1 -1
  24. package/lib/client/rpc-connection.d.ts +143 -0
  25. package/lib/client/rpc-connection.d.ts.map +1 -0
  26. package/lib/client/rpc-connection.js +171 -0
  27. package/lib/client/rpc-connection.js.map +1 -0
  28. package/lib/client-ids.d.ts +41 -0
  29. package/lib/client-ids.d.ts.map +1 -0
  30. package/lib/client-ids.js +44 -0
  31. package/lib/client-ids.js.map +1 -0
  32. package/lib/data/data-protocol-methods.d.ts +4 -4
  33. package/lib/data/data-protocol-methods.d.ts.map +1 -1
  34. package/lib/data/data-protocol-methods.js +10 -1
  35. package/lib/data/data-protocol-methods.js.map +1 -1
  36. package/lib/data/data-server-protocol.d.ts +100 -31
  37. package/lib/data/data-server-protocol.d.ts.map +1 -1
  38. package/lib/data/events.d.ts +70 -3
  39. package/lib/data/events.d.ts.map +1 -1
  40. package/lib/data/requests.d.ts +67 -11
  41. package/lib/data/requests.d.ts.map +1 -1
  42. package/lib/errors.d.ts +91 -12
  43. package/lib/errors.d.ts.map +1 -1
  44. package/lib/errors.js +127 -18
  45. package/lib/errors.js.map +1 -1
  46. package/lib/index.d.ts +2 -0
  47. package/lib/index.d.ts.map +1 -1
  48. package/lib/index.js +5 -0
  49. package/lib/index.js.map +1 -1
  50. package/lib/latency-collector.d.ts +8 -4
  51. package/lib/latency-collector.d.ts.map +1 -1
  52. package/lib/latency-collector.js.map +1 -1
  53. package/lib/messages/index.d.ts +29 -0
  54. package/lib/messages/index.d.ts.map +1 -0
  55. package/lib/messages/index.js +55 -0
  56. package/lib/messages/index.js.map +1 -0
  57. package/lib/messages/primitives.d.ts +188 -0
  58. package/lib/messages/primitives.d.ts.map +1 -0
  59. package/lib/messages/primitives.js +161 -0
  60. package/lib/messages/primitives.js.map +1 -0
  61. package/lib/model-server.d.ts +44 -13
  62. package/lib/model-server.d.ts.map +1 -1
  63. package/lib/model-server.js +4 -2
  64. package/lib/model-server.js.map +1 -1
  65. package/lib/model-service/based-on.d.ts +57 -0
  66. package/lib/model-service/based-on.d.ts.map +1 -0
  67. package/lib/model-service/based-on.js +37 -0
  68. package/lib/model-service/based-on.js.map +1 -0
  69. package/lib/model-service/index.d.ts +1 -1
  70. package/lib/model-service/index.d.ts.map +1 -1
  71. package/lib/model-service/index.js +4 -5
  72. package/lib/model-service/index.js.map +1 -1
  73. package/lib/patch-merge.d.ts +28 -27
  74. package/lib/patch-merge.d.ts.map +1 -1
  75. package/lib/patch-merge.js +66 -22
  76. package/lib/patch-merge.js.map +1 -1
  77. package/lib/profile-session.d.ts +8 -4
  78. package/lib/profile-session.d.ts.map +1 -1
  79. package/lib/profile-session.js.map +1 -1
  80. package/lib/rpc/bind-rpc-methods.d.ts +29 -3
  81. package/lib/rpc/bind-rpc-methods.d.ts.map +1 -1
  82. package/lib/rpc/bind-rpc-methods.js +22 -3
  83. package/lib/rpc/bind-rpc-methods.js.map +1 -1
  84. package/lib/rpc/create-rpc-proxy.d.ts +7 -0
  85. package/lib/rpc/create-rpc-proxy.d.ts.map +1 -1
  86. package/lib/rpc/create-rpc-proxy.js +6 -1
  87. package/lib/rpc/create-rpc-proxy.js.map +1 -1
  88. package/lib/testing/catalogue-audit.d.ts +80 -0
  89. package/lib/testing/catalogue-audit.d.ts.map +1 -0
  90. package/lib/testing/catalogue-audit.js +94 -0
  91. package/lib/testing/catalogue-audit.js.map +1 -0
  92. package/lib/testing/data-doubles.d.ts +11 -12
  93. package/lib/testing/data-doubles.d.ts.map +1 -1
  94. package/lib/testing/data-doubles.js +14 -5
  95. package/lib/testing/data-doubles.js.map +1 -1
  96. package/lib/testing/index.d.ts +1 -0
  97. package/lib/testing/index.d.ts.map +1 -1
  98. package/lib/testing/index.js +4 -1
  99. package/lib/testing/index.js.map +1 -1
  100. package/lib/transfer-diagnostic.d.ts +33 -0
  101. package/lib/transfer-diagnostic.d.ts.map +1 -1
  102. package/lib/transfer-diagnostic.js +23 -0
  103. package/lib/transfer-diagnostic.js.map +1 -1
  104. package/lib/transfer-document.d.ts +14 -5
  105. package/lib/transfer-document.d.ts.map +1 -1
  106. package/lib/transfer-document.js +14 -1
  107. package/lib/transfer-document.js.map +1 -1
  108. package/package.json +11 -2
  109. package/src/client/data-connection.ts +216 -0
  110. package/src/client/data-events.ts +24 -1
  111. package/src/client/data-port.ts +17 -23
  112. package/src/client/data-session.ts +447 -128
  113. package/src/client/index.ts +10 -7
  114. package/src/client/message-relay.ts +28 -6
  115. package/src/client/rpc-connection.ts +235 -0
  116. package/src/client-ids.ts +45 -0
  117. package/src/data/data-protocol-methods.ts +10 -3
  118. package/src/data/data-server-protocol.ts +119 -31
  119. package/src/data/events.ts +74 -3
  120. package/src/data/requests.ts +71 -11
  121. package/src/errors.ts +139 -20
  122. package/src/index.ts +5 -0
  123. package/src/latency-collector.ts +8 -3
  124. package/src/messages/index.ts +36 -0
  125. package/src/messages/primitives.ts +271 -0
  126. package/src/model-server.ts +47 -18
  127. package/src/model-service/based-on.ts +63 -0
  128. package/src/model-service/index.ts +4 -5
  129. package/src/patch-merge.ts +90 -37
  130. package/src/profile-session.ts +9 -4
  131. package/src/rpc/bind-rpc-methods.ts +49 -4
  132. package/src/rpc/create-rpc-proxy.ts +14 -1
  133. package/src/testing/catalogue-audit.ts +111 -0
  134. package/src/testing/data-doubles.ts +33 -17
  135. package/src/testing/index.ts +4 -1
  136. package/src/transfer-diagnostic.ts +40 -0
  137. package/src/transfer-document.ts +21 -6
  138. package/lib/model-service/args.d.ts +0 -64
  139. package/lib/model-service/args.d.ts.map +0 -1
  140. package/lib/model-service/args.js +0 -11
  141. package/lib/model-service/args.js.map +0 -1
  142. package/src/model-service/args.ts +0 -67
@@ -8,78 +8,128 @@
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 primitives_1 = require("../messages/primitives");
14
13
  /**
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.
14
+ * A session could not re-open a document it had open after its connection
15
+ * dropped.
16
+ */
17
+ 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}');
18
+ /**
19
+ * A session re-opened documents after its connection dropped whose version had
20
+ * moved on since the session's last unsaved write to them: another client
21
+ * edited them, even while the session was still connected, the server reverted
22
+ * them to what is on disk, or the server restarted. The session's unsaved edits
23
+ * may be gone.
24
+ */
25
+ 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.');
26
+ /**
27
+ * One participant on a data connection: a properties panel, a tree, a form
28
+ * editor. The client side of a server client session, registered over the
29
+ * wire under {@link clientId}.
30
+ *
31
+ * The session writes only what it has open: the server refuses its update or
32
+ * save of a document it has not opened with a `DocumentNotOpenError` code.
33
+ * Every call waits for the registration, so the first can be issued at once.
34
+ *
35
+ * Every document operation stamps {@link clientId} itself. A caller that
36
+ * passed its own could pass another participant's, and the server would
37
+ * attribute the write and close the document accordingly.
18
38
  *
19
- * Three jobs, and deliberately no fourth:
39
+ * {@link closeDocument} and {@link dispose} first wait, up to
40
+ * {@link settleBeforeCloseMs}, for this session's calls still in flight on the
41
+ * URI, or on any URI for `dispose`: a save sent just before its close would
42
+ * otherwise reach the server after it, and fail as not open.
20
43
  *
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.
44
+ * After the connection drops, the session registers again under the same id,
45
+ * re-opens and re-watches what it had open, and reports the documents whose
46
+ * unsaved edits did not survive; see {@link restore}. The connection does this at
47
+ * once for a session with documents open, and any session's next call does it
48
+ * too.
30
49
  *
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.
50
+ * Generic over the transfer root so this file names no grammar.
35
51
  *
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.
52
+ * `TServer` is bound to a server answering with ITS OWN diagnostic shape, read
53
+ * back off the parameter being bound. Simplifying that to
54
+ * `DataServerProtocol<TTransfer>` compiles and costs the wrappers their
55
+ * return type: every call through `TServer` would resolve against that looser
56
+ * bound, so an adopter's diagnostics would come back as the framework's and
57
+ * the document would have to be cast on the way out.
39
58
  */
40
59
  class DataSession {
41
- port;
42
- client;
43
- methodNamespace;
44
- /** The current generation, or `undefined` before the first request / after a teardown. */
45
- generation;
60
+ clientId;
61
+ host;
62
+ label;
63
+ /**
64
+ * How long {@link closeDocument} and {@link dispose} wait for this session's
65
+ * calls in flight before closing anyway. Long, because the wait only runs
66
+ * out when a call hangs, and a close sent while a save is still running
67
+ * fails that save.
68
+ */
69
+ settleBeforeCloseMs = 10_000;
70
+ /** URIs this session has open, re-opened after a reconnect. */
71
+ openUris = new Set();
72
+ /**
73
+ * Per URI, how many opens of it this session has under way. Such a URI
74
+ * counts as open for {@link withOpenDocument}, which would otherwise close
75
+ * it under the open that is still being made.
76
+ */
77
+ openingUris = new Map();
78
+ /**
79
+ * Per URI written since its last save, the version the server answered this
80
+ * session's last write with; see {@link restore}.
81
+ */
82
+ unsavedWrites = new Map();
83
+ /** Per URI, this session's calls still in flight on it, which a close waits for. */
84
+ inFlight = new Map();
85
+ /**
86
+ * Sent with every registration, so the server lets this session register
87
+ * its id again while the dropped connection's session is still live there:
88
+ * a server that has not yet noticed the drop would otherwise refuse the id
89
+ * as a duplicate until it does.
90
+ */
91
+ resumeToken = globalThis.crypto.randomUUID();
92
+ /** The proxy the session is registered on; another one means the connection was replaced. */
93
+ registeredOn;
94
+ registration;
46
95
  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;
96
+ /**
97
+ * Disposed through {@link detach} rather than {@link dispose}, so nothing may
98
+ * be sent. Folding it into {@link disposed} would send the session's close
99
+ * over a connection that is going away.
100
+ */
101
+ detached = false;
102
+ constructor(clientId, host, label) {
103
+ this.clientId = clientId;
104
+ this.host = host;
105
+ this.label = label;
57
106
  }
58
107
  /**
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.
108
+ * The connected, READY server proxy once this session is registered on it,
109
+ * for protocol methods this session does not wrap. The proxy stamps
110
+ * nothing: pass this session's {@link clientId} to any method that carries
111
+ * one.
68
112
  */
69
113
  async connected() {
70
- if (this.disposed) {
71
- throw new Error('DataSession is disposed');
114
+ // `async` so a disposed session REJECTS rather than throwing
115
+ // synchronously: the connection's own `connected` rejects, and a caller
116
+ // reaching for `.catch` on one of them would not catch the other.
117
+ this.assertLive();
118
+ const server = await this.host.connected();
119
+ // Again after the wait: a session disposed meanwhile must not register,
120
+ // since its dispose found nothing registered to end.
121
+ this.assertLive();
122
+ if (this.registeredOn !== server) {
123
+ const reconnected = this.registeredOn !== undefined;
124
+ this.registeredOn = server;
125
+ this.registration = this.register(server, reconnected);
72
126
  }
73
- const generation = this.currentGeneration();
74
- if (!generation.ready) {
75
- generation.ready = this.awaitReady(generation);
76
- }
77
- await generation.ready;
78
- return generation.server;
127
+ await this.registration;
128
+ return server;
79
129
  }
80
130
  /**
81
- * Open `uri` for editing and start watching it, in that order, returning
82
- * the opened snapshot.
131
+ * Open `args.uri` for editing and start watching it, in that order,
132
+ * returning the opened snapshot.
83
133
  *
84
134
  * **The order is the whole reason this method exists.**
85
135
  * `watchModelDocument` baselines its dedup fingerprint from the *current*
@@ -87,30 +137,113 @@ class DataSession {
87
137
  * baseline, and the first phase event after the open arrives as a spurious
88
138
  * `'changed'` — which a widget that resets its in-memory root to the server
89
139
  * 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.
140
+ * had typed.
92
141
  *
93
142
  * Note that the returned snapshot's empty `diagnostics` does not mean
94
143
  * valid: `open` settles at the integrity landmark, not at validation.
95
144
  * Validity arrives asynchronously on `onDocumentUpdated`, or synchronously
96
145
  * from `getModelDocument({ includeDiagnostics: true })`.
97
146
  */
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 });
147
+ openDocument(args) {
148
+ return this.trackOpen(args.uri, async () => {
149
+ const server = await this.connected();
150
+ return this.watchOpened(server, args.uri, await server.openModelDocument({ ...args, clientId: this.clientId }));
151
+ });
152
+ }
153
+ /**
154
+ * Create a document that exists nowhere yet, open and watched for this
155
+ * session; it reaches disk with the first {@link saveDocument}. The server
156
+ * refuses a URI that exists on disk or that any client has open.
157
+ */
158
+ createDocument(args) {
159
+ return this.trackOpen(args.uri, async () => {
160
+ const server = await this.connected();
161
+ return this.watchOpened(server, args.uri, await server.createModelDocument({ ...args, clientId: this.clientId }));
162
+ });
163
+ }
164
+ /**
165
+ * Watch a document this session just opened, and record it as open. A
166
+ * failed watch closes it again: the caller sees a failed open and so would
167
+ * never close it.
168
+ */
169
+ async watchOpened(server, uri, document) {
170
+ try {
171
+ await server.watchModelDocument({ uri, clientId: this.clientId });
172
+ }
173
+ catch (error) {
174
+ await server.closeModelDocument({ uri, clientId: this.clientId }).catch(() => undefined);
175
+ throw error;
176
+ }
177
+ this.openUris.add(uri);
102
178
  return document;
103
179
  }
104
180
  /**
105
- * Close `uri`. The server unwatches implicitly, so this is the dual of
106
- * {@link openDocument} and needs no separate unwatch.
181
+ * Close `args.uri`, once this session's calls on it have settled or
182
+ * {@link settleBeforeCloseMs} has passed. The server unwatches implicitly,
183
+ * so this is the dual of {@link openDocument} and needs no separate unwatch.
107
184
  */
108
- async closeDocument(uri) {
185
+ async closeDocument(args) {
186
+ this.assertLive();
187
+ await this.settle(this.inFlight.get(args.uri));
188
+ // Forgotten before the close is sent, so a reconnect in between does not
189
+ // re-open a document the caller has closed; after the wait, so an open
190
+ // of it that was still in flight does not record it again.
191
+ this.openUris.delete(args.uri);
192
+ this.unsavedWrites.delete(args.uri);
109
193
  const server = await this.connected();
110
- await server.closeModelDocument({ uri, clientId: this.clientId });
194
+ await server.closeModelDocument({ ...args, clientId: this.clientId });
195
+ }
196
+ /**
197
+ * Open `args.uri`, run `fn` with the opened snapshot, and close it once
198
+ * `fn` settles, whether it returned or threw. A URI this session already
199
+ * had open, or is still opening through another call, stays open: the close
200
+ * undoes only the open this call made.
201
+ */
202
+ async withOpenDocument(args, fn) {
203
+ const alreadyOpen = this.openUris.has(args.uri) || this.openingUris.has(args.uri);
204
+ const document = await this.openDocument(args);
205
+ try {
206
+ return await fn(document);
207
+ }
208
+ finally {
209
+ if (!alreadyOpen && !this.disposed) {
210
+ await this.closeDocument({ uri: args.uri });
211
+ }
212
+ }
213
+ }
214
+ /** Write `args.model` back as this session. The session must have `args.uri` open. */
215
+ updateDocument(args) {
216
+ return this.track([args.uri], async () => {
217
+ const server = await this.connected();
218
+ const document = await server.updateModelDocument({ ...args, clientId: this.clientId });
219
+ this.unsavedWrites.set(args.uri, document.version);
220
+ return document;
221
+ });
111
222
  }
112
223
  /**
113
- * Whether `event.sourceClientId` identifies this session's own write.
224
+ * Write several documents this session has open, all or none: the server
225
+ * refuses the whole set, before any text applies, when one is stale or not
226
+ * open. Resolves to the documents in the order given.
227
+ */
228
+ updateDocuments(args) {
229
+ return this.track(args.updates.map(update => update.uri), async () => {
230
+ const server = await this.connected();
231
+ const documents = await server.updateModelDocuments({ ...args, clientId: this.clientId });
232
+ args.updates.forEach((update, i) => this.unsavedWrites.set(update.uri, documents[i].version));
233
+ return documents;
234
+ });
235
+ }
236
+ /** Persist `args.model` to disk as this session. The session must have `args.uri` open. */
237
+ saveDocument(args) {
238
+ return this.track([args.uri], async () => {
239
+ const server = await this.connected();
240
+ const document = await server.saveModelDocument({ ...args, clientId: this.clientId });
241
+ this.unsavedWrites.delete(args.uri);
242
+ return document;
243
+ });
244
+ }
245
+ /**
246
+ * Whether `sourceClientId` identifies this session's own write.
114
247
  *
115
248
  * Every watcher needs this and the check is one comparison, so getting it
116
249
  * wrong is cheap to do and expensive to find: an unfiltered echo looks
@@ -119,60 +252,156 @@ class DataSession {
119
252
  isOwnEcho(sourceClientId) {
120
253
  return sourceClientId === this.clientId;
121
254
  }
122
- /** Tear down the current connection and stop tracking the port. Idempotent. */
255
+ /**
256
+ * End the session: detach it from the connection at once, and once its
257
+ * calls in flight have settled or {@link settleBeforeCloseMs} has passed,
258
+ * end it on the server, which closes everything it has open. Idempotent,
259
+ * and leaves the connection usable by its other sessions.
260
+ *
261
+ * Every later call rejects. The server close is not awaited, because a
262
+ * `Disposable` cannot be; a close that fails leaves the session to the
263
+ * server's connection-close cleanup.
264
+ */
123
265
  dispose() {
124
266
  if (this.disposed) {
125
267
  return;
126
268
  }
127
269
  this.disposed = true;
128
- this.portDisposeListener.dispose();
129
- this.dropGeneration();
270
+ this.host.releaseSession(this);
271
+ const pending = [...this.inFlight.values()].flatMap(calls => [...calls]);
272
+ void (async () => {
273
+ await this.settle(pending);
274
+ await this.registration;
275
+ // The proxy the session registered on, never a fresh connection: a
276
+ // connection that dropped already ended the session on the server.
277
+ if (!this.detached && this.registeredOn) {
278
+ await this.registeredOn.closeSession({ clientId: this.clientId });
279
+ }
280
+ })().catch(() => undefined);
130
281
  }
131
- /** The live generation, building one if there is none. */
132
- currentGeneration() {
133
- if (this.generation) {
134
- return this.generation;
135
- }
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;
282
+ /**
283
+ * Come off the connection because it is going away.
284
+ *
285
+ * Sends nothing, unlike {@link dispose}: the server ends every session on a
286
+ * connection it sees close, and the close would travel over the very
287
+ * connection being disposed.
288
+ */
289
+ detach() {
290
+ this.disposed = true;
291
+ this.detached = true;
292
+ this.openUris.clear();
293
+ this.unsavedWrites.clear();
148
294
  }
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();
295
+ /**
296
+ * Register again and restore now, after the connection dropped, instead of
297
+ * on the next call. A no-op for a session with nothing open, which the next
298
+ * call restores anyway. A failure is left to that next call, which meets it
299
+ * again.
300
+ */
301
+ reconnect() {
302
+ if (!this.disposed && this.openUris.size > 0) {
303
+ this.connected().catch(() => undefined);
154
304
  }
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;
305
+ }
306
+ /**
307
+ * Register on `server`, and after a reconnect restore what the ended session
308
+ * had. Calls issued meanwhile wait for this.
309
+ */
310
+ async register(server, reconnected) {
311
+ await server.createSession({ clientId: this.clientId, label: this.label, resumeToken: this.resumeToken });
312
+ if (reconnected) {
313
+ await this.restore(server);
163
314
  }
164
315
  }
165
316
  /**
166
- * Discard the current generation, disposing its connection if it opened.
167
- * The next {@link connected} builds a fresh one.
317
+ * Re-open and re-watch every document the session had open, and tell the
318
+ * host which of them lost what the session wrote since their last save.
319
+ *
320
+ * The unsaved text is not sent again. A document whose re-opened version is
321
+ * the one the session's last write was answered with still holds that
322
+ * write. Any other version means the text changed after that write:
323
+ * another client edited it, even while the session was still connected;
324
+ * the server reverted it to disk when the session's open closed as the
325
+ * document's last; or the server restarted and numbers versions afresh.
326
+ * Re-sending based on the write's own version then always conflicts, and
327
+ * based on the re-opened version it would overwrite whatever changed, so
328
+ * neither is done.
329
+ *
330
+ * No caller is waiting, so both outcomes go through the host: one report
331
+ * naming every document whose unsaved text is gone, whose record is then
332
+ * dropped, and one per document that could not be re-opened, which is
333
+ * forgotten.
168
334
  */
169
- dropGeneration() {
170
- const generation = this.generation;
171
- this.generation = undefined;
172
- if (!generation) {
335
+ async restore(server) {
336
+ const lost = [];
337
+ for (const uri of [...this.openUris]) {
338
+ try {
339
+ const document = await server.openModelDocument({ uri, clientId: this.clientId });
340
+ await server.watchModelDocument({ uri, clientId: this.clientId });
341
+ const written = this.unsavedWrites.get(uri);
342
+ if (written !== undefined && written !== document.version) {
343
+ lost.push(uri);
344
+ this.unsavedWrites.delete(uri);
345
+ }
346
+ }
347
+ catch (error) {
348
+ this.openUris.delete(uri);
349
+ this.unsavedWrites.delete(uri);
350
+ this.host.reportError?.(error, (0, primitives_1.resolve)(exports.DATA_SESSION_RESTORE_FAILED, { uri, detail: (0, primitives_1.describeError)(error) }));
351
+ }
352
+ }
353
+ if (lost.length > 0) {
354
+ const reported = (0, primitives_1.resolve)(exports.DATA_SESSION_UNSAVED_LOST, { uris: lost.join(', ') });
355
+ this.host.reportError?.(new Error(reported.text), reported);
356
+ }
357
+ }
358
+ /** Run `call`, counted as in flight on each of `uris` until it settles. */
359
+ track(uris, call) {
360
+ const running = call();
361
+ for (const uri of uris) {
362
+ this.inFlight.set(uri, (this.inFlight.get(uri) ?? new Set()).add(running));
363
+ }
364
+ const done = () => uris.forEach(uri => this.inFlight.get(uri)?.delete(running));
365
+ running.then(done, done);
366
+ return running;
367
+ }
368
+ /** {@link track} an open of `uri`, counted in {@link openingUris} until it settles. */
369
+ trackOpen(uri, call) {
370
+ this.openingUris.set(uri, (this.openingUris.get(uri) ?? 0) + 1);
371
+ const done = () => {
372
+ const remaining = (this.openingUris.get(uri) ?? 1) - 1;
373
+ if (remaining > 0) {
374
+ this.openingUris.set(uri, remaining);
375
+ }
376
+ else {
377
+ this.openingUris.delete(uri);
378
+ }
379
+ };
380
+ const running = this.track([uri], call);
381
+ running.then(done, done);
382
+ return running;
383
+ }
384
+ /** Wait until `calls` have settled, or {@link settleBeforeCloseMs} has passed. */
385
+ async settle(calls) {
386
+ const pending = [...(calls ?? [])];
387
+ if (pending.length === 0) {
173
388
  return;
174
389
  }
175
- generation.connection.then(connection => connection.dispose()).catch(() => undefined);
390
+ let timer;
391
+ const bound = new Promise(resolveBound => {
392
+ timer = setTimeout(resolveBound, this.settleBeforeCloseMs);
393
+ });
394
+ try {
395
+ await Promise.race([Promise.allSettled(pending), bound]);
396
+ }
397
+ finally {
398
+ clearTimeout(timer);
399
+ }
400
+ }
401
+ assertLive() {
402
+ if (this.disposed) {
403
+ throw new Error('DataSession is disposed');
404
+ }
176
405
  }
177
406
  }
178
407
  exports.DataSession = DataSession;
@@ -1 +1 @@
1
- {"version":3,"file":"data-session.js","sourceRoot":"","sources":["../../src/client/data-session.ts"],"names":[],"mappings":";AAAA;;;;;;;kFAOkF;;;AAGlF,kCAAkI;AAClI,gCAAuD;AAyBvD;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAa,WAAW;IAQC;IACA;IARH,eAAe,CAAS;IAC3C,0FAA0F;IAChF,UAAU,CAAyB;IACnC,QAAQ,GAAG,KAAK,CAAC;IACR,mBAAmB,CAAsB;IAE5D,YACsB,IAAc,EACd,MAAqC,EACxD,UAA8B,EAAE;QAFb,SAAI,GAAJ,IAAI,CAAU;QACd,WAAM,GAAN,MAAM,CAA+B;QAGxD,IAAI,CAAC,eAAe,GAAG,OAAO,CAAC,eAAe,IAAI,8BAAuB,CAAC;QAC1E,IAAI,CAAC,mBAAmB,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,cAAc,EAAE,CAAC,CAAC;IAC/E,CAAC;IAED,+EAA+E;IAC/E,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F,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC;QAC5D,CAAC;gBAAS,CAAC;YACR,YAAY,CAAC,KAAK,CAAC,CAAC;QACvB,CAAC;IACJ,CAAC;IAES,UAAU;QACjB,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;YACjB,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;QAC9C,CAAC;IACJ,CAAC;CACH;AApXD,kCAoXC"}
@@ -12,8 +12,9 @@
12
12
  *
13
13
  * Where `./data` is the wire *contract* and `./rpc` is the machinery that lowers
14
14
  * it onto a connection, this is what a client wraps around both: the seam a host
15
- * fills in (`DataPort`), the lifecycle above it (`DataSession` —
16
- * readiness gate, open/watch ordering, echo recognition, reconnect), the inbound
15
+ * fills in (`DataPort`), the connection above it (`DataConnection` — readiness
16
+ * gate and reconnect), the participants on that connection (`DataSession` —
17
+ * identity, open/watch ordering, echo recognition), the inbound
17
18
  * fan-out (`DataEvents`), and the two halves of the hop for hosts whose
18
19
  * client cannot hold a socket — `createPostMessageTransport` on the client
19
20
  * side and `relayToPostMessageChannel` on the side that does hold it.
@@ -25,15 +26,17 @@
25
26
  * carries the entries.
26
27
  *
27
28
  * The Theia-specific mounting of the same contract lives in
28
- * `@hydranium/data-client-theia`: its `AbstractDataServiceFrontend` solves the
29
- * same problem against Theia's channel transport, and its `EmitterDataClient`
30
- * is the Theia-bound counterpart of `DataEvents`. Prefer this tier for
31
- * anything new, and reach for the Theia package only for what genuinely needs
32
- * Theia DI.
29
+ * `@hydranium/data-client-theia`, and is now only the TRANSPORT: its
30
+ * `ChannelDataPort` fills the `DataPort` seam over a Theia channel, and its
31
+ * `EmitterDataClient` is the Theia-bound counterpart of `DataEvents`.
32
+ * Everything above the port is here, so a Theia frontend and a browser page
33
+ * differ by which port they construct and nothing else.
33
34
  */
35
+ export * from './data-connection';
34
36
  export * from './data-events';
35
37
  export * from './data-port';
36
38
  export * from './data-session';
37
39
  export * from './message-relay';
38
40
  export * from './post-message-transport';
41
+ export * from './rpc-connection';
39
42
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA;;;;;;;kFAOkF;AAElF;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,0BAA0B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA;;;;;;;kFAOkF;AAElF;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,cAAc,mBAAmB,CAAC;AAClC,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,0BAA0B,CAAC;AACzC,cAAc,kBAAkB,CAAC"}
@@ -28,8 +28,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
28
28
  *
29
29
  * Where `./data` is the wire *contract* and `./rpc` is the machinery that lowers
30
30
  * it onto a connection, this is what a client wraps around both: the seam a host
31
- * fills in (`DataPort`), the lifecycle above it (`DataSession` —
32
- * readiness gate, open/watch ordering, echo recognition, reconnect), the inbound
31
+ * fills in (`DataPort`), the connection above it (`DataConnection` — readiness
32
+ * gate and reconnect), the participants on that connection (`DataSession` —
33
+ * identity, open/watch ordering, echo recognition), the inbound
33
34
  * fan-out (`DataEvents`), and the two halves of the hop for hosts whose
34
35
  * client cannot hold a socket — `createPostMessageTransport` on the client
35
36
  * side and `relayToPostMessageChannel` on the side that does hold it.
@@ -41,15 +42,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
41
42
  * carries the entries.
42
43
  *
43
44
  * The Theia-specific mounting of the same contract lives in
44
- * `@hydranium/data-client-theia`: its `AbstractDataServiceFrontend` solves the
45
- * same problem against Theia's channel transport, and its `EmitterDataClient`
46
- * is the Theia-bound counterpart of `DataEvents`. Prefer this tier for
47
- * anything new, and reach for the Theia package only for what genuinely needs
48
- * Theia DI.
45
+ * `@hydranium/data-client-theia`, and is now only the TRANSPORT: its
46
+ * `ChannelDataPort` fills the `DataPort` seam over a Theia channel, and its
47
+ * `EmitterDataClient` is the Theia-bound counterpart of `DataEvents`.
48
+ * Everything above the port is here, so a Theia frontend and a browser page
49
+ * differ by which port they construct and nothing else.
49
50
  */
51
+ __exportStar(require("./data-connection"), exports);
50
52
  __exportStar(require("./data-events"), exports);
51
53
  __exportStar(require("./data-port"), exports);
52
54
  __exportStar(require("./data-session"), exports);
53
55
  __exportStar(require("./message-relay"), exports);
54
56
  __exportStar(require("./post-message-transport"), exports);
57
+ __exportStar(require("./rpc-connection"), exports);
55
58
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":";AAAA;;;;;;;kFAOkF;;;;;;;;;;;;;;;;AAElF;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,gDAA8B;AAC9B,8CAA4B;AAC5B,iDAA+B;AAC/B,kDAAgC;AAChC,2DAAyC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":";AAAA;;;;;;;kFAOkF;;;;;;;;;;;;;;;;AAElF;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,oDAAkC;AAClC,gDAA8B;AAC9B,8CAA4B;AAC5B,iDAA+B;AAC/B,kDAAgC;AAChC,2DAAyC;AACzC,mDAAiC"}