@hydranium/protocol 1.0.0-next.8 → 1.0.0-next.86
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.
- package/README.md +35 -1
- package/lib/client/data-connection.d.ts +114 -0
- package/lib/client/data-connection.d.ts.map +1 -0
- package/lib/client/data-connection.js +128 -0
- package/lib/client/data-connection.js.map +1 -0
- package/lib/client/data-events.d.ts +9 -1
- package/lib/client/data-events.d.ts.map +1 -1
- package/lib/client/data-events.js +14 -0
- package/lib/client/data-events.js.map +1 -1
- package/lib/client/data-port.d.ts +17 -22
- package/lib/client/data-port.d.ts.map +1 -1
- package/lib/client/data-session.d.ts +95 -78
- package/lib/client/data-session.d.ts.map +1 -1
- package/lib/client/data-session.js +115 -108
- package/lib/client/data-session.js.map +1 -1
- package/lib/client/index.d.ts +10 -7
- package/lib/client/index.d.ts.map +1 -1
- package/lib/client/index.js +10 -7
- package/lib/client/index.js.map +1 -1
- package/lib/client/message-relay.d.ts +8 -2
- package/lib/client/message-relay.d.ts.map +1 -1
- package/lib/client/message-relay.js +10 -4
- package/lib/client/message-relay.js.map +1 -1
- package/lib/client/rpc-connection.d.ts +139 -0
- package/lib/client/rpc-connection.d.ts.map +1 -0
- package/lib/client/rpc-connection.js +171 -0
- package/lib/client/rpc-connection.js.map +1 -0
- package/lib/client-ids.d.ts +41 -0
- package/lib/client-ids.d.ts.map +1 -0
- package/lib/client-ids.js +44 -0
- package/lib/client-ids.js.map +1 -0
- package/lib/data/data-protocol-methods.d.ts +2 -2
- package/lib/data/data-protocol-methods.d.ts.map +1 -1
- package/lib/data/data-protocol-methods.js +6 -1
- package/lib/data/data-protocol-methods.js.map +1 -1
- package/lib/data/data-server-protocol.d.ts +35 -2
- package/lib/data/data-server-protocol.d.ts.map +1 -1
- package/lib/data/events.d.ts +70 -3
- package/lib/data/events.d.ts.map +1 -1
- package/lib/errors.d.ts +28 -11
- package/lib/errors.d.ts.map +1 -1
- package/lib/errors.js +35 -17
- package/lib/errors.js.map +1 -1
- package/lib/index.d.ts +2 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +5 -0
- package/lib/index.js.map +1 -1
- package/lib/messages/index.d.ts +28 -0
- package/lib/messages/index.d.ts.map +1 -0
- package/lib/messages/index.js +52 -0
- package/lib/messages/index.js.map +1 -0
- package/lib/messages/primitives.d.ts +141 -0
- package/lib/messages/primitives.d.ts.map +1 -0
- package/lib/messages/primitives.js +138 -0
- package/lib/messages/primitives.js.map +1 -0
- package/lib/model-server.d.ts +27 -10
- package/lib/model-server.d.ts.map +1 -1
- package/lib/model-server.js +4 -2
- package/lib/model-server.js.map +1 -1
- package/lib/model-service/args.d.ts +14 -13
- package/lib/model-service/args.d.ts.map +1 -1
- package/lib/model-service/based-on.d.ts +55 -0
- package/lib/model-service/based-on.d.ts.map +1 -0
- package/lib/model-service/based-on.js +34 -0
- package/lib/model-service/based-on.js.map +1 -0
- package/lib/model-service/index.d.ts +1 -0
- package/lib/model-service/index.d.ts.map +1 -1
- package/lib/model-service/index.js +1 -0
- package/lib/model-service/index.js.map +1 -1
- package/lib/rpc/bind-rpc-methods.d.ts +29 -3
- package/lib/rpc/bind-rpc-methods.d.ts.map +1 -1
- package/lib/rpc/bind-rpc-methods.js +22 -3
- package/lib/rpc/bind-rpc-methods.js.map +1 -1
- package/lib/rpc/create-rpc-proxy.d.ts +7 -0
- package/lib/rpc/create-rpc-proxy.d.ts.map +1 -1
- package/lib/rpc/create-rpc-proxy.js +6 -1
- package/lib/rpc/create-rpc-proxy.js.map +1 -1
- package/lib/testing/catalogue-audit.d.ts +80 -0
- package/lib/testing/catalogue-audit.d.ts.map +1 -0
- package/lib/testing/catalogue-audit.js +94 -0
- package/lib/testing/catalogue-audit.js.map +1 -0
- package/lib/testing/data-doubles.d.ts +11 -12
- package/lib/testing/data-doubles.d.ts.map +1 -1
- package/lib/testing/data-doubles.js +14 -5
- package/lib/testing/data-doubles.js.map +1 -1
- package/lib/testing/index.d.ts +1 -0
- package/lib/testing/index.d.ts.map +1 -1
- package/lib/testing/index.js +4 -1
- package/lib/testing/index.js.map +1 -1
- package/lib/transfer-diagnostic.d.ts +33 -0
- package/lib/transfer-diagnostic.d.ts.map +1 -1
- package/lib/transfer-diagnostic.js +23 -0
- package/lib/transfer-diagnostic.js.map +1 -1
- package/lib/transfer-document.d.ts +15 -5
- package/lib/transfer-document.d.ts.map +1 -1
- package/lib/transfer-document.js +14 -1
- package/lib/transfer-document.js.map +1 -1
- package/package.json +11 -2
- package/src/client/data-connection.ts +181 -0
- package/src/client/data-events.ts +24 -1
- package/src/client/data-port.ts +17 -23
- package/src/client/data-session.ts +172 -131
- package/src/client/index.ts +10 -7
- package/src/client/message-relay.ts +28 -6
- package/src/client/rpc-connection.ts +230 -0
- package/src/client-ids.ts +45 -0
- package/src/data/data-protocol-methods.ts +6 -3
- package/src/data/data-server-protocol.ts +46 -2
- package/src/data/events.ts +74 -3
- package/src/errors.ts +41 -19
- package/src/index.ts +5 -0
- package/src/messages/index.ts +35 -0
- package/src/messages/primitives.ts +215 -0
- package/src/model-server.ts +30 -11
- package/src/model-service/args.ts +15 -13
- package/src/model-service/based-on.ts +60 -0
- package/src/model-service/index.ts +1 -0
- package/src/rpc/bind-rpc-methods.ts +49 -4
- package/src/rpc/create-rpc-proxy.ts +14 -1
- package/src/testing/catalogue-audit.ts +111 -0
- package/src/testing/data-doubles.ts +33 -17
- package/src/testing/index.ts +4 -1
- package/src/transfer-diagnostic.ts +40 -0
- package/src/transfer-document.ts +22 -6
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
/********************************************************************************
|
|
2
|
+
* Copyright (c) 2026 CrossBreeze, EclipseSource and others.
|
|
3
|
+
*
|
|
4
|
+
* This program and the accompanying materials are made available under the
|
|
5
|
+
* terms of the MIT License which is available in the project root.
|
|
6
|
+
*
|
|
7
|
+
* SPDX-License-Identifier: MIT
|
|
8
|
+
********************************************************************************/
|
|
9
|
+
|
|
10
|
+
import type { MessageConnection } from 'vscode-jsonrpc';
|
|
11
|
+
import { type ResolvedMessage, defineMessage, describeError, resolve } from '../messages/primitives';
|
|
12
|
+
import { type RpcProxy, createRpcProxy } from '../rpc';
|
|
13
|
+
import type { DataPort } from './data-port';
|
|
14
|
+
|
|
15
|
+
/**
|
|
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.
|
|
20
|
+
*/
|
|
21
|
+
export const DATA_SERVER_CONNECT_FAILED = defineMessage(
|
|
22
|
+
'hydranium/protocol/data-server-connect-failed',
|
|
23
|
+
'Could not connect to the data server: {detail}'
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
export const DATA_SERVER_NOT_READY = defineMessage(
|
|
27
|
+
'hydranium/protocol/data-server-not-ready',
|
|
28
|
+
'The data server did not become ready: {detail}'
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
/** The one method a connection needs of any server: its startup gate. */
|
|
32
|
+
export interface ReadyServer {
|
|
33
|
+
waitForReady(): Promise<void>;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Lifecycle reporting, for a host that raises warm-up UI around the two waits.
|
|
38
|
+
*
|
|
39
|
+
* Nothing fires until something asks for the connection — the generation is
|
|
40
|
+
* built on the first {@link RpcConnection.connected}. A host that wants the
|
|
41
|
+
* sequence at startup drives that call itself, or a workspace where nobody
|
|
42
|
+
* opens a document reports neither the connect nor the readiness its UI waits
|
|
43
|
+
* on.
|
|
44
|
+
*/
|
|
45
|
+
export interface RpcConnectionLifecycle {
|
|
46
|
+
/** A generation is opening its transport, including on each reconnect. */
|
|
47
|
+
readonly onConnecting?: () => void;
|
|
48
|
+
/** The server's readiness gate has settled for a generation. */
|
|
49
|
+
readonly onReady?: () => void;
|
|
50
|
+
/**
|
|
51
|
+
* A generation failed to connect or to become ready. The failure is still
|
|
52
|
+
* reported through {@link DataPort.reportError} and still rejects the
|
|
53
|
+
* awaiting caller; this is for a host that also drives its own UI.
|
|
54
|
+
*/
|
|
55
|
+
readonly onFailed?: (error: unknown) => void;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** Everything {@link RpcConnection} needs once a subclass has resolved its defaults. */
|
|
59
|
+
export interface ResolvedRpcConnectionOptions<TClient extends object> {
|
|
60
|
+
readonly methodNamespace: string;
|
|
61
|
+
readonly clientMethods: readonly (keyof TClient & string)[];
|
|
62
|
+
readonly lifecycle: RpcConnectionLifecycle;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** One connection generation: its connection, its proxy, and its readiness. */
|
|
66
|
+
interface Generation<TServer extends object> {
|
|
67
|
+
readonly connection: Promise<MessageConnection>;
|
|
68
|
+
readonly server: RpcProxy<TServer>;
|
|
69
|
+
/** Set on first use; the shared readiness gate for this generation. */
|
|
70
|
+
ready?: Promise<void>;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* One JSON-RPC connection to a head, with the three jobs every host adapter
|
|
75
|
+
* would otherwise re-derive above {@link DataPort}:
|
|
76
|
+
*
|
|
77
|
+
* 1. **Build the typed proxy** over the port's connection, with the caller's
|
|
78
|
+
* wire prefix and client-method allowlist.
|
|
79
|
+
* 2. **Own the readiness gate** — `waitForReady` once per connection, shared
|
|
80
|
+
* across concurrent callers. A client can connect before the workspace walk
|
|
81
|
+
* finishes, and an early request is then answered correctly from an empty
|
|
82
|
+
* registry, which reads as a broken project tier rather than as a race.
|
|
83
|
+
* 3. **Own the reconnect policy**, by dropping its generation when the port
|
|
84
|
+
* disposes and building a fresh one on the next request.
|
|
85
|
+
*
|
|
86
|
+
* Bounded only by {@link ReadyServer}, so a head serving a slice of the data
|
|
87
|
+
* protocol — diagnostics alone, or one with methods excluded — is still a
|
|
88
|
+
* legal server here. `DataConnection` narrows the bound because its sessions
|
|
89
|
+
* call the document methods; nothing at this layer does.
|
|
90
|
+
*/
|
|
91
|
+
export class RpcConnection<TServer extends ReadyServer, TClient extends object> {
|
|
92
|
+
protected readonly methodNamespace: string;
|
|
93
|
+
protected readonly clientMethods: readonly (keyof TClient & string)[];
|
|
94
|
+
protected readonly lifecycle: RpcConnectionLifecycle;
|
|
95
|
+
/** The current generation, or `undefined` before the first request / after a teardown. */
|
|
96
|
+
protected generation?: Generation<TServer>;
|
|
97
|
+
protected disposed = false;
|
|
98
|
+
protected readonly portDisposeListener: { dispose(): void };
|
|
99
|
+
|
|
100
|
+
constructor(
|
|
101
|
+
protected readonly port: DataPort,
|
|
102
|
+
protected readonly client: TClient,
|
|
103
|
+
options: ResolvedRpcConnectionOptions<TClient>
|
|
104
|
+
) {
|
|
105
|
+
this.methodNamespace = options.methodNamespace;
|
|
106
|
+
this.clientMethods = options.clientMethods;
|
|
107
|
+
this.lifecycle = options.lifecycle;
|
|
108
|
+
this.portDisposeListener = this.port.onDispose(() => this.dropGeneration());
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* The connected, READY server proxy.
|
|
113
|
+
*
|
|
114
|
+
* Returns the proxy rather than `void` on purpose. A reconnect replaces the
|
|
115
|
+
* proxy, so a caller that cached one from an earlier call would go on
|
|
116
|
+
* addressing a dead connection with no error — handing it back per call
|
|
117
|
+
* makes the stale reference unrepresentable.
|
|
118
|
+
*
|
|
119
|
+
* Concurrent callers share one readiness promise, so `waitForReady` is
|
|
120
|
+
* awaited once per generation and not once per caller.
|
|
121
|
+
*/
|
|
122
|
+
async connected(): Promise<RpcProxy<TServer>> {
|
|
123
|
+
this.assertLive();
|
|
124
|
+
const generation = this.currentGeneration();
|
|
125
|
+
if (!generation.ready) {
|
|
126
|
+
generation.ready = this.awaitReady(generation);
|
|
127
|
+
}
|
|
128
|
+
await generation.ready;
|
|
129
|
+
return generation.server;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* The current generation's proxy WITHOUT awaiting readiness — calls queue
|
|
134
|
+
* against the connection promise.
|
|
135
|
+
*
|
|
136
|
+
* **Protected, and that is the point.** An early request is answered
|
|
137
|
+
* correctly from a registry the workspace walk has not filled yet, which
|
|
138
|
+
* reads as a broken project tier rather than as a race — so every caller has
|
|
139
|
+
* to interpose the gate, and every caller forgetting to is a silent bug.
|
|
140
|
+
* {@link connected} is the public route and returns this same proxy once the
|
|
141
|
+
* gate has settled, which leaves nothing to forget. The one caller that
|
|
142
|
+
* cannot use it is {@link awaitReady}, whose whole job is running the gate.
|
|
143
|
+
*
|
|
144
|
+
* Read per access, never cached: a reconnect replaces the generation, and a
|
|
145
|
+
* held reference would address the dead one.
|
|
146
|
+
*/
|
|
147
|
+
protected get server(): RpcProxy<TServer> {
|
|
148
|
+
this.assertLive();
|
|
149
|
+
return this.currentGeneration().server;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Surface a failure the way this host does, through the port's sink.
|
|
154
|
+
*
|
|
155
|
+
* Here rather than only on the port so every participant sharing the
|
|
156
|
+
* connection reports through one route without being handed the transport.
|
|
157
|
+
*/
|
|
158
|
+
reportError(error: unknown, reported: ResolvedMessage): void {
|
|
159
|
+
this.port.reportError(error, reported);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/** Tear down the current connection and stop tracking the port. Idempotent. */
|
|
163
|
+
dispose(): void {
|
|
164
|
+
if (this.disposed) {
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
this.disposed = true;
|
|
168
|
+
this.portDisposeListener.dispose();
|
|
169
|
+
this.dropGeneration();
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/** The live generation, building one if there is none. */
|
|
173
|
+
protected currentGeneration(): Generation<TServer> {
|
|
174
|
+
if (this.generation) {
|
|
175
|
+
return this.generation;
|
|
176
|
+
}
|
|
177
|
+
this.lifecycle.onConnecting?.();
|
|
178
|
+
const connection = this.port.connect();
|
|
179
|
+
// Rejection is reported here rather than left to float: an unhandled
|
|
180
|
+
// rejection on a connection promise is the failure mode that reads as
|
|
181
|
+
// "the model is empty" instead of "the transport never opened".
|
|
182
|
+
connection.catch((error: unknown) =>
|
|
183
|
+
this.port.reportError(error, resolve(DATA_SERVER_CONNECT_FAILED, { detail: describeError(error) }))
|
|
184
|
+
);
|
|
185
|
+
const server = createRpcProxy<TServer, TClient>(connection, {
|
|
186
|
+
methodNamespace: this.methodNamespace,
|
|
187
|
+
localTarget: this.client,
|
|
188
|
+
localMethods: this.clientMethods
|
|
189
|
+
});
|
|
190
|
+
this.generation = { connection, server };
|
|
191
|
+
return this.generation;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/** Await the connection and the server's startup gate for one generation. */
|
|
195
|
+
protected async awaitReady(generation: Generation<TServer>): Promise<void> {
|
|
196
|
+
try {
|
|
197
|
+
await generation.connection;
|
|
198
|
+
await generation.server.waitForReady();
|
|
199
|
+
this.lifecycle.onReady?.();
|
|
200
|
+
} catch (error: unknown) {
|
|
201
|
+
this.lifecycle.onFailed?.(error);
|
|
202
|
+
// Drop the generation so the next request retries rather than
|
|
203
|
+
// re-awaiting a settled rejection forever.
|
|
204
|
+
if (this.generation === generation) {
|
|
205
|
+
this.generation = undefined;
|
|
206
|
+
}
|
|
207
|
+
this.port.reportError(error, resolve(DATA_SERVER_NOT_READY, { detail: describeError(error) }));
|
|
208
|
+
throw error;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Discard the current generation, disposing its connection if it opened.
|
|
214
|
+
* The next {@link connected} builds a fresh one.
|
|
215
|
+
*/
|
|
216
|
+
protected dropGeneration(): void {
|
|
217
|
+
const generation = this.generation;
|
|
218
|
+
this.generation = undefined;
|
|
219
|
+
if (!generation) {
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
generation.connection.then(connection => connection.dispose()).catch(() => undefined);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
protected assertLive(): void {
|
|
226
|
+
if (this.disposed) {
|
|
227
|
+
throw new Error(`${this.constructor.name} is disposed`);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/********************************************************************************
|
|
2
|
+
* Copyright (c) 2026 CrossBreeze, EclipseSource and others.
|
|
3
|
+
*
|
|
4
|
+
* This program and the accompanying materials are made available under the
|
|
5
|
+
* terms of the MIT License which is available in the project root.
|
|
6
|
+
*
|
|
7
|
+
* SPDX-License-Identifier: MIT
|
|
8
|
+
********************************************************************************/
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Well-known values of the wire's `clientId` / `sourceClientId` field.
|
|
12
|
+
*
|
|
13
|
+
* The framework tracks each document as belonging to one or more "clients" —
|
|
14
|
+
* typically an LSP-text client (Monaco, VS Code, …), a GLSP diagram client,
|
|
15
|
+
* and/or a structured-form client — and keys its holds and watches per
|
|
16
|
+
* `(uri, clientId)`. These three values are not real participants, so a client
|
|
17
|
+
* minting its own id must avoid them.
|
|
18
|
+
*
|
|
19
|
+
* **Here rather than in the server package, because the side that has to
|
|
20
|
+
* RECOGNISE them is the client.** An inbound `onDocumentUpdated` carries
|
|
21
|
+
* `sourceClientId`, and a consumer deciding what to do with it is asking which
|
|
22
|
+
* of these it is — so a frontend would otherwise have to depend on the server
|
|
23
|
+
* tier to name three strings, and in practice retypes the literal instead.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
/** Identifier for an LSP-text client (Monaco, VS Code, …). */
|
|
27
|
+
export const LANGUAGE_CLIENT_ID = 'language-client';
|
|
28
|
+
|
|
29
|
+
/** Fallback identifier when a document's author is unknown (e.g. cold workspace-init load). */
|
|
30
|
+
export const UNKNOWN_CLIENT_ID = 'unknown';
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Synthetic author id on the `onDocumentUpdated` broadcast a data-server
|
|
34
|
+
* emits after the LAST client closed a document and the framework rebuilt it
|
|
35
|
+
* from its disk content (discarding unsaved in-session edits). Not a real
|
|
36
|
+
* client: it lets consumers distinguish the revert broadcast from
|
|
37
|
+
* client-authored updates.
|
|
38
|
+
*/
|
|
39
|
+
export const REVERT_ON_CLOSE_CLIENT_ID = 'revert-on-close';
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Every id the framework reserves, for a client checking that the identity it
|
|
43
|
+
* is about to mint collides with none of them.
|
|
44
|
+
*/
|
|
45
|
+
export const FRAMEWORK_CLIENT_IDS: readonly string[] = [LANGUAGE_CLIENT_ID, UNKNOWN_CLIENT_ID, REVERT_ON_CLOSE_CLIENT_ID];
|
|
@@ -59,9 +59,12 @@ export const REFERENCE_SERVER_PROTOCOL_METHODS = [
|
|
|
59
59
|
] as const satisfies ReadonlyArray<keyof ReferenceServerProtocol<TransferElement> & string>;
|
|
60
60
|
|
|
61
61
|
/** Notification-method names on {@link DocumentClientProtocol}. */
|
|
62
|
-
export const DOCUMENT_CLIENT_PROTOCOL_METHODS = [
|
|
63
|
-
|
|
64
|
-
|
|
62
|
+
export const DOCUMENT_CLIENT_PROTOCOL_METHODS = [
|
|
63
|
+
'onDocumentUpdated',
|
|
64
|
+
'onDocumentSaved',
|
|
65
|
+
'onDocumentDeleted',
|
|
66
|
+
'onDocumentsBuilt'
|
|
67
|
+
] as const satisfies ReadonlyArray<keyof DocumentClientProtocol<TransferElement> & string>;
|
|
65
68
|
|
|
66
69
|
/** Notification-method names on {@link ProjectClientProtocol}. */
|
|
67
70
|
export const PROJECT_CLIENT_PROTOCOL_METHODS = ['onProjectsChanged'] as const satisfies ReadonlyArray<keyof ProjectClientProtocol & string>;
|
|
@@ -13,7 +13,13 @@ import type { Project } from '../project';
|
|
|
13
13
|
import type { TransferDocument } from '../transfer-document';
|
|
14
14
|
import type { CloseModelArgs, FindNextNameArgs, OpenModelArgs, ReferenceContext, ReferenceRequest } from '../model-server';
|
|
15
15
|
import type { ReferenceCandidate, ReferenceTarget } from '../model-service/reference-candidate';
|
|
16
|
-
import type {
|
|
16
|
+
import type {
|
|
17
|
+
ProjectsChangedEvent,
|
|
18
|
+
TransferDocumentDeletedEvent,
|
|
19
|
+
TransferDocumentSavedEvent,
|
|
20
|
+
TransferDocumentsBuiltEvent,
|
|
21
|
+
TransferDocumentUpdatedEvent
|
|
22
|
+
} from './events';
|
|
17
23
|
import type {
|
|
18
24
|
GetModelDocumentArgs,
|
|
19
25
|
GetProjectForUriArgs,
|
|
@@ -45,7 +51,7 @@ export interface DocumentServerProtocol<TTransfer extends TransferElement, TDiag
|
|
|
45
51
|
* (so concurrent editors share one built document) and returns the
|
|
46
52
|
* document at the server's configured target phase — the same shape
|
|
47
53
|
* {@link getModelDocument} returns, except that `version` is taken from
|
|
48
|
-
* the text-document store so the caller's first `
|
|
54
|
+
* the text-document store so the caller's first `basedOn` write
|
|
49
55
|
* cannot self-conflict. Idempotent in registration terms: opening an
|
|
50
56
|
* already-open document refreshes the client registration. Note it does
|
|
51
57
|
* NOT avoid a rebuild — a second client attaching triggers
|
|
@@ -194,6 +200,22 @@ export interface DataServerProtocol<
|
|
|
194
200
|
>
|
|
195
201
|
extends DocumentServerProtocol<TTransfer, TDiagnostic>, ProjectServerProtocol<TProject> {}
|
|
196
202
|
|
|
203
|
+
/**
|
|
204
|
+
* The diagnostic shape a server answers with, read back off its own
|
|
205
|
+
* declaration.
|
|
206
|
+
*
|
|
207
|
+
* This is what lets a client tier stay generic over the server alone and still
|
|
208
|
+
* describe what it hands back. Both parameters must be inferred: naming
|
|
209
|
+
* {@link TransferElement} for the transfer instead fails to match while that
|
|
210
|
+
* parameter is still generic, and a default declared against the constraint
|
|
211
|
+
* then stops satisfying it.
|
|
212
|
+
*/
|
|
213
|
+
export type DiagnosticOf<TServer> =
|
|
214
|
+
TServer extends DocumentServerProtocol<infer _TTransfer, infer TDiagnostic> ? TDiagnostic : TransferDiagnostic;
|
|
215
|
+
|
|
216
|
+
/** The project shape a server answers with, read back off its own declaration. */
|
|
217
|
+
export type ProjectOf<TServer> = TServer extends ProjectServerProtocol<infer TProject> ? TProject : Project;
|
|
218
|
+
|
|
197
219
|
/**
|
|
198
220
|
* Cross-reference / naming slice of the server surface — scope-aware
|
|
199
221
|
* queries that resolve against the language's reference services. NOT part
|
|
@@ -262,6 +284,28 @@ export interface DocumentClientProtocol<TTransfer extends TransferElement, TDiag
|
|
|
262
284
|
* codepath, not a subscription codepath).
|
|
263
285
|
*/
|
|
264
286
|
onDocumentSaved(event: TransferDocumentSavedEvent<TTransfer, TDiagnostic>): void;
|
|
287
|
+
|
|
288
|
+
/**
|
|
289
|
+
* Delivered when a document's backing file was removed. Separate from
|
|
290
|
+
* {@link onDocumentUpdated} for the same reason as {@link onDocumentSaved},
|
|
291
|
+
* and more strongly: there is no built state to deliver, and the build-phase
|
|
292
|
+
* path cannot report a deletion at all.
|
|
293
|
+
*
|
|
294
|
+
* Ungated, because on a browser host — where the workspace lives behind the
|
|
295
|
+
* head — no other source can observe a file disappearing. Recipients that
|
|
296
|
+
* only care about their own documents filter by URI.
|
|
297
|
+
*/
|
|
298
|
+
onDocumentDeleted(event: TransferDocumentDeletedEvent): void;
|
|
299
|
+
|
|
300
|
+
/**
|
|
301
|
+
* Delivered once per build, naming the documents that reached the
|
|
302
|
+
* subscription phase and that
|
|
303
|
+
* nobody on this connection watches — chiefly the ones rebuilt as a cascade
|
|
304
|
+
* from a dependency's change, which no filesystem watcher can see because
|
|
305
|
+
* their own files did not change. The complement of
|
|
306
|
+
* {@link onDocumentUpdated}; carries URIs and no documents.
|
|
307
|
+
*/
|
|
308
|
+
onDocumentsBuilt(event: TransferDocumentsBuiltEvent): void;
|
|
265
309
|
}
|
|
266
310
|
|
|
267
311
|
/**
|
package/src/data/events.ts
CHANGED
|
@@ -30,10 +30,14 @@ import type { TransferDocument } from '../transfer-document';
|
|
|
30
30
|
* from both `onDocumentUpdated` and `onDocumentSaved`. The framework's own
|
|
31
31
|
* `dispatchPhaseEvent` does NOT emit `'saved'` — saves take the dedicated
|
|
32
32
|
* `DataClientProtocol.onDocumentSaved` channel.
|
|
33
|
-
*
|
|
34
|
-
*
|
|
33
|
+
*
|
|
34
|
+
* Deletion is deliberately NOT a member. An update event carries a built
|
|
35
|
+
* document, which a deleted one has none of, and the phase-driven path that
|
|
36
|
+
* produces these events never runs for a deleted URI — the builder drops the
|
|
37
|
+
* document before deriving the rebuild set. It travels as
|
|
38
|
+
* {@link TransferDocumentDeletedEvent} on its own channel instead.
|
|
35
39
|
*/
|
|
36
|
-
export type TransferDocumentUpdateReason = 'changed' | 'rebuilt' | 'saved'
|
|
40
|
+
export type TransferDocumentUpdateReason = 'changed' | 'rebuilt' | 'saved';
|
|
37
41
|
|
|
38
42
|
/**
|
|
39
43
|
* Delivered on the data-server when a document's content (or existence)
|
|
@@ -91,6 +95,73 @@ export type TransferDocumentSavedListener<
|
|
|
91
95
|
TDiagnostic extends TransferDiagnostic = TransferDiagnostic
|
|
92
96
|
> = (event: TransferDocumentSavedEvent<TTransfer, TDiagnostic>) => void;
|
|
93
97
|
|
|
98
|
+
/**
|
|
99
|
+
* Delivered on the data-server when a document's backing file was removed.
|
|
100
|
+
* Carries no document, and cannot: the state a
|
|
101
|
+
* {@link TransferDocumentUpdatedEvent} would have to carry no longer exists by
|
|
102
|
+
* the time anyone can be told. That is also why deletion is not a `reason` on
|
|
103
|
+
* the update stream — `DocumentBuilder.update` drops the document before
|
|
104
|
+
* deriving the rebuild set, so the phase-driven path that produces update
|
|
105
|
+
* events never runs for it.
|
|
106
|
+
*
|
|
107
|
+
* **Delivered for EVERY document, not only watched ones**, unlike
|
|
108
|
+
* `onDocumentUpdated` and `onDocumentSaved`. The test that decides which
|
|
109
|
+
* channels are gated is whether any OTHER source can observe the fact on the
|
|
110
|
+
* least capable host: a browser-hosted client's workspace lives behind the
|
|
111
|
+
* head, so nothing there can see a file disappear, and gating the notification
|
|
112
|
+
* would leave it blind. (A Theia frontend's filesystem watcher would cover it,
|
|
113
|
+
* which is why this is a host argument and not a structure-versus-content one.)
|
|
114
|
+
* A watcher is told about its own document's deletion here too, the update
|
|
115
|
+
* channel being silent for deletions by construction. Filter on {@link uri} if
|
|
116
|
+
* the receiver only cares about documents it opened.
|
|
117
|
+
*
|
|
118
|
+
* A watch survives the deletion, so a file that comes back resumes delivering
|
|
119
|
+
* `onDocumentUpdated` to the same subscribers with no re-subscription. A
|
|
120
|
+
* client that responds by closing its editor releases the watch through
|
|
121
|
+
* `closeModelDocument` as usual.
|
|
122
|
+
*/
|
|
123
|
+
export interface TransferDocumentDeletedEvent {
|
|
124
|
+
/** Canonical URI of the removed document, keyed as the subscription is. */
|
|
125
|
+
readonly uri: string;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** Callback shape for `DataClientProtocol.onDocumentDeleted`. */
|
|
129
|
+
export type TransferDocumentDeletedListener = (event: TransferDocumentDeletedEvent) => void;
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Delivered on the data-server once per build, naming the documents that reached
|
|
133
|
+
* the configured subscription phase (`DataServerOptions.subscriptionPhase`,
|
|
134
|
+
* `Validated` by default) and that NO client on the connection is watching. Not
|
|
135
|
+
* the integrity-settled landmark, which is a different point and a different
|
|
136
|
+
* word in this framework.
|
|
137
|
+
*
|
|
138
|
+
* The complement of {@link TransferDocumentUpdatedEvent}, which is gated per
|
|
139
|
+
* URI: together the two cover every document a build touched. This one exists
|
|
140
|
+
* for the case no source outside the server can observe — a document rebuilt
|
|
141
|
+
* because something it DEPENDS ON changed. Its own file never changed, so a
|
|
142
|
+
* filesystem watcher cannot see it, and it has no subscriber, so the update
|
|
143
|
+
* channel does not report it. A consumer showing data derived from such a
|
|
144
|
+
* document (a tree label, a decorator) would otherwise hold a stale value with
|
|
145
|
+
* nothing to invalidate it.
|
|
146
|
+
*
|
|
147
|
+
* Carries URIs and no documents: a recipient re-reads what it displays, through
|
|
148
|
+
* `getModelDocument` or its own request. That keeps the bandwidth property the
|
|
149
|
+
* per-URI subscription exists for, without gating the message.
|
|
150
|
+
*
|
|
151
|
+
* Not sent when the set is empty, which is the normal case while editing — the
|
|
152
|
+
* document being edited is watched by its own editor and therefore excluded.
|
|
153
|
+
* Workspace initialisation sends nothing either: it does not build to the
|
|
154
|
+
* subscription phase. The largest message a workspace can produce is therefore
|
|
155
|
+
* a whole-workspace rebuild at that phase, which is one message of URIs.
|
|
156
|
+
*/
|
|
157
|
+
export interface TransferDocumentsBuiltEvent {
|
|
158
|
+
/** Canonical URIs, keyed as subscriptions are. Never empty. */
|
|
159
|
+
readonly uris: readonly string[];
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/** Callback shape for `DataClientProtocol.onDocumentsBuilt`. */
|
|
163
|
+
export type TransferDocumentsBuiltListener = (event: TransferDocumentsBuiltEvent) => void;
|
|
164
|
+
|
|
94
165
|
/**
|
|
95
166
|
* Why a project-change event fired. `added` — the project was newly
|
|
96
167
|
* registered (descriptor discovered); `updated` — the project's
|
package/src/errors.ts
CHANGED
|
@@ -8,6 +8,20 @@
|
|
|
8
8
|
********************************************************************************/
|
|
9
9
|
|
|
10
10
|
import { ResponseError } from 'vscode-jsonrpc';
|
|
11
|
+
import { defineMessage, type HydraniumMessageData, messageData } from './messages/primitives';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* The catalogue declaration behind {@link ConflictError}'s sentence.
|
|
15
|
+
*
|
|
16
|
+
* Its English must keep containing {@link CONFLICT_ERROR_MESSAGE_MARKER}: the
|
|
17
|
+
* marker is tier 3 of {@link isConflictError}'s ladder, and it matches on text.
|
|
18
|
+
* That tier only ever works untranslated, which is why it is the last resort
|
|
19
|
+
* behind the numeric code rather than the primary check.
|
|
20
|
+
*/
|
|
21
|
+
export const STALE_BASED_UPDATE = defineMessage(
|
|
22
|
+
'hydranium/protocol/stale-based-update',
|
|
23
|
+
'Stale-based update for {uri}: expected v{expectedVersion}, server is at v{actualVersion}'
|
|
24
|
+
);
|
|
11
25
|
|
|
12
26
|
/**
|
|
13
27
|
* Application-specific JSON-RPC error code for {@link ConflictError}.
|
|
@@ -24,12 +38,12 @@ export const CONFLICT_ERROR_CODE = 1001;
|
|
|
24
38
|
* Structured payload carried in {@link ConflictError.data}, and the only place
|
|
25
39
|
* a post-RPC caller can read the version mismatch from.
|
|
26
40
|
*/
|
|
27
|
-
export interface ConflictErrorData {
|
|
41
|
+
export interface ConflictErrorData extends HydraniumMessageData {
|
|
28
42
|
readonly uri: string;
|
|
29
43
|
/** The based-on version the caller authored against. */
|
|
30
|
-
readonly
|
|
44
|
+
readonly expectedVersion: number;
|
|
31
45
|
/** The server's current text-document version at the time of the throw. */
|
|
32
|
-
readonly
|
|
46
|
+
readonly actualVersion: number;
|
|
33
47
|
}
|
|
34
48
|
|
|
35
49
|
/**
|
|
@@ -46,11 +60,9 @@ export interface ConflictErrorData {
|
|
|
46
60
|
* `err.data` (the instance is reconstructed as a generic
|
|
47
61
|
* `ResponseError`, so subclass getters / fields do not survive).
|
|
48
62
|
*
|
|
49
|
-
* Detection is
|
|
50
|
-
* `TransferUpdateArgs` / `TransferSaveArgs`;
|
|
51
|
-
*
|
|
52
|
-
* posture, so headless / CLI / batch tooling with no meaningful based-on
|
|
53
|
-
* version can opt out explicitly.
|
|
63
|
+
* Detection is driven by the required `basedOn` field on
|
|
64
|
+
* `TransferUpdateArgs` / `TransferSaveArgs`; a caller with no meaningful
|
|
65
|
+
* based-on version passes `'anything'` and gets no gating.
|
|
54
66
|
*
|
|
55
67
|
* Three reasonable adopter recovery strategies:
|
|
56
68
|
*
|
|
@@ -64,18 +76,19 @@ export interface ConflictErrorData {
|
|
|
64
76
|
* No auto-retry or auto-merge ships by default.
|
|
65
77
|
*/
|
|
66
78
|
export class ConflictError extends ResponseError<ConflictErrorData> {
|
|
67
|
-
constructor(uri: string,
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
});
|
|
79
|
+
constructor(uri: string, expectedVersion: number, actualVersion: number) {
|
|
80
|
+
const params = { uri, expectedVersion, actualVersion };
|
|
81
|
+
// The identity rides alongside the typed payload rather than replacing
|
|
82
|
+
// it: `isConflictError`'s name check is surface an adopter may bind, so
|
|
83
|
+
// adding the identity widens the payload rather than reshaping it.
|
|
84
|
+
super(CONFLICT_ERROR_CODE, STALE_BASED_UPDATE.format(params), { ...params, ...messageData(STALE_BASED_UPDATE, params) });
|
|
73
85
|
this.name = 'ConflictError';
|
|
74
86
|
// ResponseError's constructor calls `Object.setPrototypeOf(this,
|
|
75
87
|
// ResponseError.prototype)` to keep its own prototype chain intact across
|
|
76
88
|
// transpilation targets; that resets us to ResponseError, hiding the
|
|
77
89
|
// ConflictError-specific getters. Restore the prototype here so
|
|
78
|
-
// `err.uri` / `.
|
|
90
|
+
// `err.uri` / `.expectedVersion` / `.actualVersion` resolve through this
|
|
91
|
+
// class.
|
|
79
92
|
Object.setPrototypeOf(this, ConflictError.prototype);
|
|
80
93
|
}
|
|
81
94
|
|
|
@@ -83,12 +96,21 @@ export class ConflictError extends ResponseError<ConflictErrorData> {
|
|
|
83
96
|
return this.data!.uri;
|
|
84
97
|
}
|
|
85
98
|
|
|
86
|
-
|
|
87
|
-
|
|
99
|
+
/**
|
|
100
|
+
* The based-on version the caller authored against.
|
|
101
|
+
*
|
|
102
|
+
* Must not be renamed to `expected`, nor its sibling to `actual`: a test
|
|
103
|
+
* reporter reads an error carrying both as an assertion failure, and
|
|
104
|
+
* vitest's formatter then ASSIGNS to them, which throws on an accessor and
|
|
105
|
+
* replaces the real failure with a `TypeError`.
|
|
106
|
+
*/
|
|
107
|
+
get expectedVersion(): number {
|
|
108
|
+
return this.data!.expectedVersion;
|
|
88
109
|
}
|
|
89
110
|
|
|
90
|
-
|
|
91
|
-
|
|
111
|
+
/** The server's version at the time of the throw. Not `actual` — see {@link expectedVersion}. */
|
|
112
|
+
get actualVersion(): number {
|
|
113
|
+
return this.data!.actualVersion;
|
|
92
114
|
}
|
|
93
115
|
}
|
|
94
116
|
|
package/src/index.ts
CHANGED
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
|
|
17
17
|
export * from './abstract-logger';
|
|
18
18
|
export * from './client';
|
|
19
|
+
export * from './client-ids';
|
|
19
20
|
export * from './clock';
|
|
20
21
|
export * from './data';
|
|
21
22
|
export * from './browser-runtime';
|
|
@@ -24,6 +25,10 @@ export * from './errors';
|
|
|
24
25
|
export * from './host-diagnostics';
|
|
25
26
|
export * from './logger';
|
|
26
27
|
export * from './latency-collector';
|
|
28
|
+
// The primitives only. The `./messages` subpath additionally enumerates this
|
|
29
|
+
// package's own declarations, which the root barrel already re-exports through
|
|
30
|
+
// the modules that raise them.
|
|
31
|
+
export * from './messages/primitives';
|
|
27
32
|
export * from './patch-merge';
|
|
28
33
|
export * from './noop-logger';
|
|
29
34
|
export * from './observable-value';
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/********************************************************************************
|
|
2
|
+
* Copyright (c) 2026 CrossBreeze, EclipseSource and others.
|
|
3
|
+
*
|
|
4
|
+
* This program and the accompanying materials are made available under the
|
|
5
|
+
* terms of the MIT License which is available in the project root.
|
|
6
|
+
*
|
|
7
|
+
* SPDX-License-Identifier: MIT
|
|
8
|
+
********************************************************************************/
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* The message-externalization mechanism, plus every user-facing message
|
|
12
|
+
* `@hydranium/protocol` itself raises.
|
|
13
|
+
*
|
|
14
|
+
* Declarations stay beside their call sites and are re-exported here, so this is
|
|
15
|
+
* enumeration rather than centralization: a code's package segment has to name
|
|
16
|
+
* the package that raises it, and a shared module would make that segment a lie
|
|
17
|
+
* for every message in it. Adding a message therefore touches the file that
|
|
18
|
+
* raises it and this list, and nothing else.
|
|
19
|
+
*
|
|
20
|
+
* A barrel makes every code and English default public API, so renaming a code
|
|
21
|
+
* is a breaking change. That was already true — an adopter's catalogue keys on
|
|
22
|
+
* these codes either way — but it is now in the type system rather than implicit.
|
|
23
|
+
* The English is a fallback, not a contract; the code is the contract.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
export * from './primitives';
|
|
27
|
+
|
|
28
|
+
export { STALE_BASED_UPDATE } from '../errors';
|
|
29
|
+
export { DATA_SERVER_CONNECT_FAILED, DATA_SERVER_NOT_READY } from '../client/rpc-connection';
|
|
30
|
+
export {
|
|
31
|
+
RELAY_REPLAY_FAILED,
|
|
32
|
+
RELAY_TRANSPORT_OPEN_FAILED,
|
|
33
|
+
RELAY_TRANSPORT_READ_FAILED,
|
|
34
|
+
RELAY_TRANSPORT_WRITE_FAILED
|
|
35
|
+
} from '../client/message-relay';
|