@hydranium/protocol 1.0.0-next.4 → 1.0.0-next.42
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-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 +10 -3
- package/lib/client/data-port.d.ts.map +1 -1
- package/lib/client/data-session.d.ts +8 -0
- package/lib/client/data-session.d.ts.map +1 -1
- package/lib/client/data-session.js +12 -3
- package/lib/client/data-session.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/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 +21 -1
- 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 +25 -6
- package/lib/errors.d.ts.map +1 -1
- package/lib/errors.js +32 -12
- package/lib/errors.js.map +1 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +4 -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 +2 -2
- package/lib/model-server.d.ts.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 -5
- package/lib/testing/data-doubles.d.ts.map +1 -1
- package/lib/testing/data-doubles.js +14 -4
- 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/package.json +11 -2
- package/src/client/data-events.ts +24 -1
- package/src/client/data-port.ts +10 -3
- package/src/client/data-session.ts +21 -2
- package/src/client/message-relay.ts +28 -6
- package/src/data/data-protocol-methods.ts +6 -3
- package/src/data/data-server-protocol.ts +29 -1
- package/src/data/events.ts +74 -3
- package/src/errors.ts +38 -14
- package/src/index.ts +4 -0
- package/src/messages/index.ts +35 -0
- package/src/messages/primitives.ts +215 -0
- package/src/model-server.ts +2 -2
- 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 -9
- package/src/testing/index.ts +4 -1
- package/src/transfer-diagnostic.ts +40 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transfer-diagnostic.js","sourceRoot":"","sources":["../src/transfer-diagnostic.ts"],"names":[],"mappings":";AAAA;;;;;;;kFAOkF;;;
|
|
1
|
+
{"version":3,"file":"transfer-diagnostic.js","sourceRoot":"","sources":["../src/transfer-diagnostic.ts"],"names":[],"mappings":";AAAA;;;;;;;kFAOkF;;;AAsElF,IAAiB,kBAAkB,CAsDlC;AAtDD,WAAiB,kBAAkB;IAChC,mEAAmE;IACtD,4CAAyB,GAAG,GAAG,CAAC;IAC7C,wDAAwD;IAC3C,0CAAuB,GAAG,GAAG,CAAC;IAC3C,sFAAsF;IACzE,6CAA0B,GAAG,GAAG,CAAC;IAE9C,SAAgB,OAAO,CAAC,UAA8B;QACnD,OAAO,UAAU,CAAC,QAAQ,KAAK,OAAO,CAAC;IAC1C,CAAC;IAFe,0BAAO,UAEtB,CAAA;IAED,SAAgB,YAAY,CAAC,UAA8B;QACxD,OAAO,UAAU,CAAC,IAAI,KAAK,eAAe,CAAC;IAC9C,CAAC;IAFe,+BAAY,eAE3B,CAAA;IAED;;;;;;;;;;;;;;;OAeG;IACH,SAAgB,QAAQ,CAAC,UAA8B;QACpD,IAAI,OAAO,UAAU,CAAC,IAAI,KAAK,QAAQ,IAAI,UAAU,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;YAC1E,OAAO,SAAS,CAAC;QACpB,CAAC;QACD,OAAO,EAAE,IAAI,EAAE,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,CAAC,MAAM,EAAE,IAAI,EAAE,UAAU,CAAC,OAAO,EAAE,CAAC;IACzF,CAAC;IALe,2BAAQ,WAKvB,CAAA;IAED,SAAgB,OAAO,CAAC,UAA8B;QACnD,OAAO,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,OAAO,GAAG,mBAAA,0BAA0B,GAAG,UAAU,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,OAAO,CAAC;IAChI,CAAC;IAFe,0BAAO,UAEtB,CAAA;IAED,SAAgB,MAAM,CAAC,WAAiC;QACrD,OAAO,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IACtC,CAAC;IAFe,yBAAM,SAErB,CAAA;IAED,SAAgB,SAAS,CAAC,WAAiC;QACxD,OAAO,WAAW,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACpC,CAAC;IAFe,4BAAS,YAExB,CAAA;IAED,SAAgB,cAAc,CAAC,WAAiC;QAC7D,OAAO,WAAW,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;IACzC,CAAC;IAFe,iCAAc,iBAE7B,CAAA;AACJ,CAAC,EAtDgB,kBAAkB,kCAAlB,kBAAkB,QAsDlC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hydranium/protocol",
|
|
3
|
-
"version": "1.0.0-next.
|
|
3
|
+
"version": "1.0.0-next.42",
|
|
4
4
|
"description": "Generic, language-agnostic types, constants, and pure utilities for the hydranium framework.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"hydranium",
|
|
@@ -41,6 +41,14 @@
|
|
|
41
41
|
"types": "./lib/data/index.d.ts",
|
|
42
42
|
"default": "./lib/data/index.js"
|
|
43
43
|
},
|
|
44
|
+
"./messages": {
|
|
45
|
+
"types": "./lib/messages/index.d.ts",
|
|
46
|
+
"default": "./lib/messages/index.js"
|
|
47
|
+
},
|
|
48
|
+
"./lib/messages": {
|
|
49
|
+
"types": "./lib/messages/index.d.ts",
|
|
50
|
+
"default": "./lib/messages/index.js"
|
|
51
|
+
},
|
|
44
52
|
"./testing": {
|
|
45
53
|
"types": "./lib/testing/index.d.ts",
|
|
46
54
|
"default": "./lib/testing/index.js"
|
|
@@ -88,7 +96,7 @@
|
|
|
88
96
|
"vscode-jsonrpc": "9.0.1"
|
|
89
97
|
},
|
|
90
98
|
"peerDependencies": {
|
|
91
|
-
"vscode-jsonrpc": "
|
|
99
|
+
"vscode-jsonrpc": "9.0.1"
|
|
92
100
|
},
|
|
93
101
|
"engines": {
|
|
94
102
|
"node": ">=22.13"
|
|
@@ -96,5 +104,6 @@
|
|
|
96
104
|
"publishConfig": {
|
|
97
105
|
"access": "public"
|
|
98
106
|
},
|
|
107
|
+
"//peerDependencies": "`vscode-jsonrpc` is EXACT rather than a range, because it is one link of an atomic chain with no independently movable link: `vscode-languageserver-protocol` depends on it at exactly 9.0.1, so any other value an adopter supplies is a SECOND physical copy rather than an upgrade. This wire stack breaks on copy identity rather than on structure — `ParameterStructures.auto` is a singleton compared by `===` in connection.js, so a request type built by one copy and sent over a connection owned by the other throws `Unknown parameter structure auto`. A caret or union range was rejected because npm then resolves a `vscode-jsonrpc@8.2.0` tree SILENTLY, with no diagnostic at all, and the failure surfaces only later at server init. Exact does not fail the install either — npm downgrades an unsatisfiable peer to a warning — but it is a NAMED ERESOLVE warning printing the required version beside the found one, and a hard error for anyone installing with `--strict-peer-deps`. It does NOT prevent a NESTED copy — `@eclipse-glsp/*` carries its own exact `vscode-jsonrpc@8.2.0` dependency and root `overrides` do not ship — so a consumer of the GLSP head must pin the chain in its own manifest.",
|
|
99
108
|
"//prepack": "The publish guard, and it deliberately is NOT a `prepare`: npm runs a workspace `prepare` BEFORE the root `postinstall` that applies patches/vscode-jsonrpc+9.0.1.patch, so building there fails on a cold clone and npm rolls the entire install back. `prepack` runs only when a tarball is made (`npm pack`, `npm publish`) and never on install, so it cannot break the install it has no business touching. It FAILS rather than rebuilds, because the rebuild is exactly the part that ordering defeats. What it defends against: `files` lists `lib`, `lib` is gitignored, and a `files` entry matching nothing is skipped SILENTLY — so `npm publish` from an unbuilt tree emits a tarball of `src` and nothing else, with no error."
|
|
100
109
|
}
|
|
@@ -8,7 +8,14 @@
|
|
|
8
8
|
********************************************************************************/
|
|
9
9
|
|
|
10
10
|
import { Emitter, type Event } from 'vscode-jsonrpc';
|
|
11
|
-
import type {
|
|
11
|
+
import type {
|
|
12
|
+
DataClientProtocol,
|
|
13
|
+
ProjectsChangedEvent,
|
|
14
|
+
TransferDocumentDeletedEvent,
|
|
15
|
+
TransferDocumentSavedEvent,
|
|
16
|
+
TransferDocumentsBuiltEvent,
|
|
17
|
+
TransferDocumentUpdatedEvent
|
|
18
|
+
} from '../data';
|
|
12
19
|
import type { Project } from '../project';
|
|
13
20
|
import type { TransferDiagnostic } from '../transfer-diagnostic';
|
|
14
21
|
import type { TransferElement } from '../transfer-element';
|
|
@@ -40,12 +47,18 @@ export class DataEvents<
|
|
|
40
47
|
> implements DataClientProtocol<TTransfer, TDiagnostic, TProject> {
|
|
41
48
|
protected readonly documentUpdatedEmitter = new Emitter<TransferDocumentUpdatedEvent<TTransfer, TDiagnostic>>();
|
|
42
49
|
protected readonly documentSavedEmitter = new Emitter<TransferDocumentSavedEvent<TTransfer, TDiagnostic>>();
|
|
50
|
+
protected readonly documentDeletedEmitter = new Emitter<TransferDocumentDeletedEvent>();
|
|
51
|
+
protected readonly documentsBuiltEmitter = new Emitter<TransferDocumentsBuiltEvent>();
|
|
43
52
|
protected readonly projectsChangedEmitter = new Emitter<ProjectsChangedEvent<TProject>>();
|
|
44
53
|
|
|
45
54
|
/** A build-phase event for a watched document. Carries the originating `sourceClientId`. */
|
|
46
55
|
readonly onDidUpdateDocument: Event<TransferDocumentUpdatedEvent<TTransfer, TDiagnostic>> = this.documentUpdatedEmitter.event;
|
|
47
56
|
/** A watched document was persisted to disk. */
|
|
48
57
|
readonly onDidSaveDocument: Event<TransferDocumentSavedEvent<TTransfer, TDiagnostic>> = this.documentSavedEmitter.event;
|
|
58
|
+
/** A document's backing file was removed, watched or not. Any watch survives. */
|
|
59
|
+
readonly onDidDeleteDocument: Event<TransferDocumentDeletedEvent> = this.documentDeletedEmitter.event;
|
|
60
|
+
/** Documents built that nobody watches — re-read anything derived from them. */
|
|
61
|
+
readonly onDidBuildDocuments: Event<TransferDocumentsBuiltEvent> = this.documentsBuiltEmitter.event;
|
|
49
62
|
/** The project set changed. */
|
|
50
63
|
readonly onDidChangeProjects: Event<ProjectsChangedEvent<TProject>> = this.projectsChangedEmitter.event;
|
|
51
64
|
|
|
@@ -59,6 +72,14 @@ export class DataEvents<
|
|
|
59
72
|
this.documentSavedEmitter.fire(event);
|
|
60
73
|
}
|
|
61
74
|
|
|
75
|
+
onDocumentDeleted(event: TransferDocumentDeletedEvent): void {
|
|
76
|
+
this.documentDeletedEmitter.fire(event);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
onDocumentsBuilt(event: TransferDocumentsBuiltEvent): void {
|
|
80
|
+
this.documentsBuiltEmitter.fire(event);
|
|
81
|
+
}
|
|
82
|
+
|
|
62
83
|
onProjectsChanged(event: ProjectsChangedEvent<TProject>): void {
|
|
63
84
|
this.projectsChangedEmitter.fire(event);
|
|
64
85
|
}
|
|
@@ -66,6 +87,8 @@ export class DataEvents<
|
|
|
66
87
|
dispose(): void {
|
|
67
88
|
this.documentUpdatedEmitter.dispose();
|
|
68
89
|
this.documentSavedEmitter.dispose();
|
|
90
|
+
this.documentDeletedEmitter.dispose();
|
|
91
|
+
this.documentsBuiltEmitter.dispose();
|
|
69
92
|
this.projectsChangedEmitter.dispose();
|
|
70
93
|
}
|
|
71
94
|
}
|
package/src/client/data-port.ts
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
********************************************************************************/
|
|
9
9
|
|
|
10
10
|
import type { Event, MessageConnection } from 'vscode-jsonrpc';
|
|
11
|
+
import type { ResolvedMessage } from '../messages/primitives';
|
|
11
12
|
|
|
12
13
|
/**
|
|
13
14
|
* The one thing a host has to supply for the data head: a live JSON-RPC
|
|
@@ -77,10 +78,16 @@ export interface DataPort {
|
|
|
77
78
|
*
|
|
78
79
|
* It exists because the alternative is worse in both directions: this tier
|
|
79
80
|
* cannot import a host's UI, and swallowing the error makes a dead
|
|
80
|
-
* connection look like an empty model.
|
|
81
|
-
*
|
|
81
|
+
* connection look like an empty model.
|
|
82
|
+
*
|
|
83
|
+
* `reported` is a complete sentence plus the identity needed to render it in
|
|
84
|
+
* another language. It carries a value rather than using a protocol field
|
|
85
|
+
* because this tier does not know whether a process hop intervenes — in a
|
|
86
|
+
* webview host the render happens across one — and a `ResolvedMessage` is
|
|
87
|
+
* structured-clone safe either way. Render it with `renderFrameworkMessage`;
|
|
88
|
+
* passing no translation map yields the English.
|
|
82
89
|
*/
|
|
83
|
-
reportError(error: unknown,
|
|
90
|
+
reportError(error: unknown, reported: ResolvedMessage): void;
|
|
84
91
|
|
|
85
92
|
/**
|
|
86
93
|
* Fires when the host tears the transport down and the current connection
|
|
@@ -9,11 +9,28 @@
|
|
|
9
9
|
|
|
10
10
|
import type { MessageConnection } from 'vscode-jsonrpc';
|
|
11
11
|
import { DATA_CLIENT_PROTOCOL_METHODS, DATA_SERVER_WIRE_PREFIX, type DataClientProtocol, type DataServerProtocol } from '../data';
|
|
12
|
+
import { defineMessage, describeError, resolve } from '../messages/primitives';
|
|
12
13
|
import { type RpcProxy, createRpcProxy } from '../rpc';
|
|
13
14
|
import type { TransferDocument } from '../transfer-document';
|
|
14
15
|
import type { TransferElement } from '../transfer-element';
|
|
15
16
|
import type { DataPort } from './data-port';
|
|
16
17
|
|
|
18
|
+
/**
|
|
19
|
+
* The transport never opened. A complete sentence rather than a fragment: a
|
|
20
|
+
* fragment is nested inside a sentence the framework does not own, so no
|
|
21
|
+
* translator controls the whole and the composition cannot be made to read
|
|
22
|
+
* correctly in every language.
|
|
23
|
+
*/
|
|
24
|
+
export const DATA_SERVER_CONNECT_FAILED = defineMessage(
|
|
25
|
+
'hydranium/protocol/data-server-connect-failed',
|
|
26
|
+
'Could not connect to the data server: {detail}'
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
export const DATA_SERVER_NOT_READY = defineMessage(
|
|
30
|
+
'hydranium/protocol/data-server-not-ready',
|
|
31
|
+
'The data server did not become ready: {detail}'
|
|
32
|
+
);
|
|
33
|
+
|
|
17
34
|
/** Options for {@link DataSession}. */
|
|
18
35
|
export interface DataSessionOptions {
|
|
19
36
|
/**
|
|
@@ -168,7 +185,9 @@ export class DataSession<TTransfer extends TransferElement> {
|
|
|
168
185
|
// Rejection is reported here rather than left to float: an unhandled
|
|
169
186
|
// rejection on a connection promise is the failure mode that reads as
|
|
170
187
|
// "the model is empty" instead of "the transport never opened".
|
|
171
|
-
connection.catch((error: unknown) =>
|
|
188
|
+
connection.catch((error: unknown) =>
|
|
189
|
+
this.port.reportError(error, resolve(DATA_SERVER_CONNECT_FAILED, { detail: describeError(error) }))
|
|
190
|
+
);
|
|
172
191
|
const server = createRpcProxy<DataServerProtocol<TTransfer>, DataClientProtocol<TTransfer>>(connection, {
|
|
173
192
|
methodNamespace: this.methodNamespace,
|
|
174
193
|
localTarget: this.client,
|
|
@@ -189,7 +208,7 @@ export class DataSession<TTransfer extends TransferElement> {
|
|
|
189
208
|
if (this.generation === generation) {
|
|
190
209
|
this.generation = undefined;
|
|
191
210
|
}
|
|
192
|
-
this.port.reportError(error,
|
|
211
|
+
this.port.reportError(error, resolve(DATA_SERVER_NOT_READY, { detail: describeError(error) }));
|
|
193
212
|
throw error;
|
|
194
213
|
}
|
|
195
214
|
}
|
|
@@ -8,8 +8,29 @@
|
|
|
8
8
|
********************************************************************************/
|
|
9
9
|
|
|
10
10
|
import { Emitter, type Disposable, type Event, type Message, type MessageReader, type MessageWriter } from 'vscode-jsonrpc';
|
|
11
|
+
import { defineMessage, describeError, resolve, type ResolvedMessage } from '../messages/primitives';
|
|
11
12
|
import type { PostMessageChannel } from './post-message-transport';
|
|
12
13
|
|
|
14
|
+
export const RELAY_TRANSPORT_OPEN_FAILED = defineMessage(
|
|
15
|
+
'hydranium/protocol/relay-transport-open-failed',
|
|
16
|
+
'Could not open the transport to relay: {detail}'
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
export const RELAY_TRANSPORT_READ_FAILED = defineMessage(
|
|
20
|
+
'hydranium/protocol/relay-transport-read-failed',
|
|
21
|
+
'Could not read from the relayed transport: {detail}'
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
export const RELAY_TRANSPORT_WRITE_FAILED = defineMessage(
|
|
25
|
+
'hydranium/protocol/relay-transport-write-failed',
|
|
26
|
+
'Could not write to the relayed transport: {detail}'
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
export const RELAY_REPLAY_FAILED = defineMessage(
|
|
30
|
+
'hydranium/protocol/relay-replay-failed',
|
|
31
|
+
'Could not replay a buffered message to the relayed transport: {detail}'
|
|
32
|
+
);
|
|
33
|
+
|
|
13
34
|
/**
|
|
14
35
|
* The framed side of a relay: the reader/writer pair over whatever transport the
|
|
15
36
|
* host actually holds — a TCP socket to the data-server, a child process' stdio,
|
|
@@ -30,13 +51,14 @@ export interface RelayTransport {
|
|
|
30
51
|
export interface MessageRelayOptions {
|
|
31
52
|
/**
|
|
32
53
|
* Surface a failure the way the host does. Same contract as
|
|
33
|
-
* `DataPort.reportError`: `
|
|
54
|
+
* `DataPort.reportError`: `reported` is a complete sentence plus the identity
|
|
55
|
+
* needed to render it in another language.
|
|
34
56
|
*
|
|
35
57
|
* A relay has no other way to report — it sits between two transports and
|
|
36
58
|
* owns neither, so a swallowed error here presents as a form that never
|
|
37
59
|
* populates.
|
|
38
60
|
*/
|
|
39
|
-
readonly reportError?: (error: unknown,
|
|
61
|
+
readonly reportError?: (error: unknown, reported: ResolvedMessage) => void;
|
|
40
62
|
}
|
|
41
63
|
|
|
42
64
|
/** A live relay. Dispose to tear both directions down. */
|
|
@@ -143,7 +165,7 @@ export function relayToPostMessageChannel(
|
|
|
143
165
|
bufferSubscription?.dispose();
|
|
144
166
|
bufferSubscription = undefined;
|
|
145
167
|
buffered.length = 0;
|
|
146
|
-
options.reportError?.(error,
|
|
168
|
+
options.reportError?.(error, resolve(RELAY_TRANSPORT_OPEN_FAILED, { detail: describeError(error) }));
|
|
147
169
|
closeFramedSide();
|
|
148
170
|
return false;
|
|
149
171
|
}
|
|
@@ -166,12 +188,12 @@ export function relayToPostMessageChannel(
|
|
|
166
188
|
opened.reader.listen(message => channel.post(message)),
|
|
167
189
|
opened.reader.onClose(() => closeFramedSide()),
|
|
168
190
|
opened.reader.onError(error => {
|
|
169
|
-
options.reportError?.(error,
|
|
191
|
+
options.reportError?.(error, resolve(RELAY_TRANSPORT_READ_FAILED, { detail: describeError(error) }));
|
|
170
192
|
closeFramedSide();
|
|
171
193
|
}),
|
|
172
194
|
channel.onMessage(message => {
|
|
173
195
|
void opened.writer.write(message).catch((error: unknown) => {
|
|
174
|
-
options.reportError?.(error,
|
|
196
|
+
options.reportError?.(error, resolve(RELAY_TRANSPORT_WRITE_FAILED, { detail: describeError(error) }));
|
|
175
197
|
});
|
|
176
198
|
})
|
|
177
199
|
);
|
|
@@ -183,7 +205,7 @@ export function relayToPostMessageChannel(
|
|
|
183
205
|
|
|
184
206
|
for (const message of buffered) {
|
|
185
207
|
void opened.writer.write(message).catch((error: unknown) => {
|
|
186
|
-
options.reportError?.(error,
|
|
208
|
+
options.reportError?.(error, resolve(RELAY_REPLAY_FAILED, { detail: describeError(error) }));
|
|
187
209
|
});
|
|
188
210
|
}
|
|
189
211
|
buffered.length = 0;
|
|
@@ -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,
|
|
@@ -262,6 +268,28 @@ export interface DocumentClientProtocol<TTransfer extends TransferElement, TDiag
|
|
|
262
268
|
* codepath, not a subscription codepath).
|
|
263
269
|
*/
|
|
264
270
|
onDocumentSaved(event: TransferDocumentSavedEvent<TTransfer, TDiagnostic>): void;
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* Delivered when a document's backing file was removed. Separate from
|
|
274
|
+
* {@link onDocumentUpdated} for the same reason as {@link onDocumentSaved},
|
|
275
|
+
* and more strongly: there is no built state to deliver, and the build-phase
|
|
276
|
+
* path cannot report a deletion at all.
|
|
277
|
+
*
|
|
278
|
+
* Ungated, because on a browser host — where the workspace lives behind the
|
|
279
|
+
* head — no other source can observe a file disappearing. Recipients that
|
|
280
|
+
* only care about their own documents filter by URI.
|
|
281
|
+
*/
|
|
282
|
+
onDocumentDeleted(event: TransferDocumentDeletedEvent): void;
|
|
283
|
+
|
|
284
|
+
/**
|
|
285
|
+
* Delivered once per build, naming the documents that reached the
|
|
286
|
+
* subscription phase and that
|
|
287
|
+
* nobody on this connection watches — chiefly the ones rebuilt as a cascade
|
|
288
|
+
* from a dependency's change, which no filesystem watcher can see because
|
|
289
|
+
* their own files did not change. The complement of
|
|
290
|
+
* {@link onDocumentUpdated}; carries URIs and no documents.
|
|
291
|
+
*/
|
|
292
|
+
onDocumentsBuilt(event: TransferDocumentsBuiltEvent): void;
|
|
265
293
|
}
|
|
266
294
|
|
|
267
295
|
/**
|
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
|
/**
|
|
@@ -64,18 +78,19 @@ export interface ConflictErrorData {
|
|
|
64
78
|
* No auto-retry or auto-merge ships by default.
|
|
65
79
|
*/
|
|
66
80
|
export class ConflictError extends ResponseError<ConflictErrorData> {
|
|
67
|
-
constructor(uri: string,
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
});
|
|
81
|
+
constructor(uri: string, expectedVersion: number, actualVersion: number) {
|
|
82
|
+
const params = { uri, expectedVersion, actualVersion };
|
|
83
|
+
// The identity rides alongside the typed payload rather than replacing
|
|
84
|
+
// it: `isConflictError`'s name check is surface an adopter may bind, so
|
|
85
|
+
// adding the identity widens the payload rather than reshaping it.
|
|
86
|
+
super(CONFLICT_ERROR_CODE, STALE_BASED_UPDATE.format(params), { ...params, ...messageData(STALE_BASED_UPDATE, params) });
|
|
73
87
|
this.name = 'ConflictError';
|
|
74
88
|
// ResponseError's constructor calls `Object.setPrototypeOf(this,
|
|
75
89
|
// ResponseError.prototype)` to keep its own prototype chain intact across
|
|
76
90
|
// transpilation targets; that resets us to ResponseError, hiding the
|
|
77
91
|
// ConflictError-specific getters. Restore the prototype here so
|
|
78
|
-
// `err.uri` / `.
|
|
92
|
+
// `err.uri` / `.expectedVersion` / `.actualVersion` resolve through this
|
|
93
|
+
// class.
|
|
79
94
|
Object.setPrototypeOf(this, ConflictError.prototype);
|
|
80
95
|
}
|
|
81
96
|
|
|
@@ -83,12 +98,21 @@ export class ConflictError extends ResponseError<ConflictErrorData> {
|
|
|
83
98
|
return this.data!.uri;
|
|
84
99
|
}
|
|
85
100
|
|
|
86
|
-
|
|
87
|
-
|
|
101
|
+
/**
|
|
102
|
+
* The based-on version the caller authored against.
|
|
103
|
+
*
|
|
104
|
+
* Must not be renamed to `expected`, nor its sibling to `actual`: a test
|
|
105
|
+
* reporter reads an error carrying both as an assertion failure, and
|
|
106
|
+
* vitest's formatter then ASSIGNS to them, which throws on an accessor and
|
|
107
|
+
* replaces the real failure with a `TypeError`.
|
|
108
|
+
*/
|
|
109
|
+
get expectedVersion(): number {
|
|
110
|
+
return this.data!.expectedVersion;
|
|
88
111
|
}
|
|
89
112
|
|
|
90
|
-
|
|
91
|
-
|
|
113
|
+
/** The server's version at the time of the throw. Not `actual` — see {@link expectedVersion}. */
|
|
114
|
+
get actualVersion(): number {
|
|
115
|
+
return this.data!.actualVersion;
|
|
92
116
|
}
|
|
93
117
|
}
|
|
94
118
|
|
package/src/index.ts
CHANGED
|
@@ -24,6 +24,10 @@ export * from './errors';
|
|
|
24
24
|
export * from './host-diagnostics';
|
|
25
25
|
export * from './logger';
|
|
26
26
|
export * from './latency-collector';
|
|
27
|
+
// The primitives only. The `./messages` subpath additionally enumerates this
|
|
28
|
+
// package's own declarations, which the root barrel already re-exports through
|
|
29
|
+
// the modules that raise them.
|
|
30
|
+
export * from './messages/primitives';
|
|
27
31
|
export * from './patch-merge';
|
|
28
32
|
export * from './noop-logger';
|
|
29
33
|
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/data-session';
|
|
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';
|