@hydranium/protocol 1.0.0-next.8 → 1.0.0-next.85
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 +6 -5
- package/lib/model-server.d.ts.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 +6 -5
- 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
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transfer-document.js","sourceRoot":"","sources":["../src/transfer-document.ts"],"names":[],"mappings":";AAAA;;;;;;;kFAOkF;;;
|
|
1
|
+
{"version":3,"file":"transfer-document.js","sourceRoot":"","sources":["../src/transfer-document.ts"],"names":[],"mappings":";AAAA;;;;;;;kFAOkF;;;AAIlF,uDAAmF;AAgDnF,IAAiB,gBAAgB,CAuDhC;AAvDD,WAAiB,gBAAgB;IAC9B;;;OAGG;IACH,SAAgB,QAAQ,CACrB,QAAkD;QAElD,OAAO,QAAQ,CAAC,IAAI,KAAK,SAAS,CAAC;IACtC,CAAC;IAJe,yBAAQ,WAIvB,CAAA;IAED;;;;;OAKG;IACH,SAAgB,YAAY,CACzB,QAAkD;QAElD,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC;YACvB,MAAM,IAAI,KAAK,CAAC,kBAAkB,QAAQ,CAAC,GAAG,EAAE,CAAC,CAAC;QACrD,CAAC;QACD,OAAO,QAAQ,CAAC;IACnB,CAAC;IAPe,6BAAY,eAO3B,CAAA;IAED;;;;;;;OAOG;IACH,SAAgB,MAAM,CACnB,GAAW,EACX,cAA6B,EAAE;QAE/B,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,IAAA,4BAAiB,EAAC,CAAC,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,WAAW,EAAE,CAAC;IAC/E,CAAC;IALe,uBAAM,SAKrB,CAAA;IAED;;;;;OAKG;IACH,SAAgB,MAAM,CACnB,GAAW,EACX,OAAe,EACf,IAAe,EACf,cAA6B,EAAE;QAE/B,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,IAAA,4BAAiB,EAAC,OAAO,CAAC,EAAE,IAAI,EAAE,WAAW,EAAE,CAAC;IAC1E,CAAC;IAPe,uBAAM,SAOrB,CAAA;AACJ,CAAC,EAvDgB,gBAAgB,gCAAhB,gBAAgB,QAuDhC"}
|
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.85",
|
|
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, and docs/adopting/requirements.md carries the block to paste.",
|
|
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
|
}
|
|
@@ -0,0 +1,181 @@
|
|
|
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 { FRAMEWORK_CLIENT_IDS } from '../client-ids';
|
|
11
|
+
import {
|
|
12
|
+
DATA_CLIENT_PROTOCOL_METHODS,
|
|
13
|
+
DATA_SERVER_WIRE_PREFIX,
|
|
14
|
+
type DataClientProtocol,
|
|
15
|
+
type DataServerProtocol,
|
|
16
|
+
type DiagnosticOf,
|
|
17
|
+
type ProjectOf
|
|
18
|
+
} from '../data';
|
|
19
|
+
import type { TransferElement } from '../transfer-element';
|
|
20
|
+
import { DataEvents } from './data-events';
|
|
21
|
+
import type { DataPort } from './data-port';
|
|
22
|
+
import { DataSession } from './data-session';
|
|
23
|
+
import { RpcConnection, type RpcConnectionLifecycle } from './rpc-connection';
|
|
24
|
+
|
|
25
|
+
/** Options for {@link DataConnection}. */
|
|
26
|
+
export interface DataConnectionOptions extends RpcConnectionLifecycle {
|
|
27
|
+
/**
|
|
28
|
+
* Wire namespace the server is addressed under. Defaults to the
|
|
29
|
+
* framework's {@link DATA_SERVER_WIRE_PREFIX}, which is what an unmodified
|
|
30
|
+
* `DataServer` binds. Override only alongside the server's own
|
|
31
|
+
* `methodNamespace` option — a mismatch turns every request into
|
|
32
|
+
* "Unhandled method" rather than failing at wire-up.
|
|
33
|
+
*/
|
|
34
|
+
readonly methodNamespace?: string;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** {@link DataConnectionOptions} for a client that does not speak {@link DataClientProtocol}. */
|
|
38
|
+
export interface DataConnectionOptionsWithMethods<TClient extends object> extends DataConnectionOptions {
|
|
39
|
+
/**
|
|
40
|
+
* Method names of the client to bind as inbound handlers. Declare it
|
|
41
|
+
* `as const satisfies ReadonlyArray<keyof YourClient & string>` so the list
|
|
42
|
+
* cannot drift from the interface.
|
|
43
|
+
*/
|
|
44
|
+
readonly clientMethods: readonly (keyof TClient & string)[];
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Trailing constructor arguments, required only when the client cannot take
|
|
49
|
+
* the framework's default method list.
|
|
50
|
+
*
|
|
51
|
+
* `bindRpcMethods` throws for a name the target does not implement, so a
|
|
52
|
+
* request/response-only client binding the default list fails at wire-up. The
|
|
53
|
+
* conditional turns that into a compile error.
|
|
54
|
+
*/
|
|
55
|
+
export type DataConnectionArgs<TTransfer extends TransferElement, TClient extends object> =
|
|
56
|
+
TClient extends DataClientProtocol<TTransfer>
|
|
57
|
+
? [options?: DataConnectionOptions & Partial<DataConnectionOptionsWithMethods<TClient>>]
|
|
58
|
+
: [options: DataConnectionOptionsWithMethods<TClient>];
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* A {@link RpcConnection} to the data head, carrying as many participants as
|
|
62
|
+
* the host has interested parties.
|
|
63
|
+
*
|
|
64
|
+
* Document operations live on the participants rather than here: they carry a
|
|
65
|
+
* `clientId`, which identifies a participant rather than a wire, and the server
|
|
66
|
+
* keys its holds and watches per `(uri, clientId)`. Two parties sharing one
|
|
67
|
+
* identity cannot tell each other's writes from their own echoes.
|
|
68
|
+
*
|
|
69
|
+
* Generic over the transfer root so this file names no grammar. An adopter
|
|
70
|
+
* binds the concrete root (or the union of them, for a multi-grammar head) at
|
|
71
|
+
* its own edge.
|
|
72
|
+
*/
|
|
73
|
+
export class DataConnection<
|
|
74
|
+
TTransfer extends TransferElement,
|
|
75
|
+
TServer extends DataServerProtocol<TTransfer, DiagnosticOf<TServer>> = DataServerProtocol<TTransfer>,
|
|
76
|
+
TClient extends object = DataClientProtocol<TTransfer>
|
|
77
|
+
> extends RpcConnection<TServer, TClient> {
|
|
78
|
+
protected readonly sessions = new Set<DataSession<TTransfer, TServer>>();
|
|
79
|
+
|
|
80
|
+
constructor(port: DataPort, client: TClient, ...rest: DataConnectionArgs<TTransfer, TClient>) {
|
|
81
|
+
const [options = {}] = rest as [(DataConnectionOptions & Partial<DataConnectionOptionsWithMethods<TClient>>)?];
|
|
82
|
+
super(port, client, {
|
|
83
|
+
methodNamespace: options.methodNamespace ?? DATA_SERVER_WIRE_PREFIX,
|
|
84
|
+
// The default is reachable only where `TClient` satisfies
|
|
85
|
+
// `DataClientProtocol`, which the constructor's conditional enforces;
|
|
86
|
+
// the compiler cannot carry that through to the generic parameter.
|
|
87
|
+
clientMethods: options.clientMethods ?? (DATA_CLIENT_PROTOCOL_METHODS as unknown as readonly (keyof TClient & string)[]),
|
|
88
|
+
lifecycle: options
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Mint a participant on this connection under `clientId`.
|
|
94
|
+
*
|
|
95
|
+
* `clientId` must be distinct per participant and stable for its lifetime:
|
|
96
|
+
* it keys the server's per-`(uri, clientId)` hold and watch, and it is the
|
|
97
|
+
* echo key an inbound `onDocumentUpdated` is matched against.
|
|
98
|
+
*
|
|
99
|
+
* Throws for an id in {@link FRAMEWORK_CLIENT_IDS} — those are authors the
|
|
100
|
+
* SERVER emits rather than participants, so a session holding one would read
|
|
101
|
+
* the framework's own broadcasts as its own echoes and drop them. Nothing
|
|
102
|
+
* about that fails on its own: the document simply stops following, which
|
|
103
|
+
* looks like a dead connection.
|
|
104
|
+
*
|
|
105
|
+
* Throws, too, for an id a LIVE session on this connection already holds.
|
|
106
|
+
* Per-document membership is a set of client ids, so two participants
|
|
107
|
+
* sharing one collapse to a single hold and the first close releases it
|
|
108
|
+
* under the survivor, which then stops receiving updates for a document it
|
|
109
|
+
* is still showing. A constant bound once per participant KIND — one per
|
|
110
|
+
* widget class rather than per instance — satisfies the type and violates
|
|
111
|
+
* this.
|
|
112
|
+
*
|
|
113
|
+
* The check spans this connection only, so a head several connections reach
|
|
114
|
+
* can still be addressed twice under one id.
|
|
115
|
+
*/
|
|
116
|
+
createSession(clientId: string): DataSession<TTransfer, TServer> {
|
|
117
|
+
this.assertLive();
|
|
118
|
+
if (FRAMEWORK_CLIENT_IDS.includes(clientId)) {
|
|
119
|
+
throw new Error(`clientId '${clientId}' is reserved by the framework and cannot identify a participant`);
|
|
120
|
+
}
|
|
121
|
+
if ([...this.sessions].some(session => session.clientId === clientId)) {
|
|
122
|
+
throw new Error(`clientId '${clientId}' already identifies a live participant on this connection`);
|
|
123
|
+
}
|
|
124
|
+
const session = new DataSession<TTransfer, TServer>(clientId, {
|
|
125
|
+
connected: () => this.connected(),
|
|
126
|
+
releaseSession: released => this.sessions.delete(released)
|
|
127
|
+
});
|
|
128
|
+
this.sessions.add(session);
|
|
129
|
+
return session;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Sessions are detached rather than disposed: the server releases every hold
|
|
134
|
+
* on a connection it sees close, so closing each document first sends
|
|
135
|
+
* requests over a connection this call is about to dispose.
|
|
136
|
+
*/
|
|
137
|
+
override dispose(): void {
|
|
138
|
+
for (const session of [...this.sessions]) {
|
|
139
|
+
session.detach();
|
|
140
|
+
}
|
|
141
|
+
this.sessions.clear();
|
|
142
|
+
super.dispose();
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* A {@link DataConnection} that brings its own {@link DataEvents}, so a host
|
|
148
|
+
* with several interested parties does not have to supply one.
|
|
149
|
+
*
|
|
150
|
+
* **The client slot holds exactly one object, and that is why this exists.**
|
|
151
|
+
* `createRpcProxy` binds a single `localTarget`, and underneath a method name
|
|
152
|
+
* maps to one handler — a second registration replaces the first silently. So a
|
|
153
|
+
* properties panel and a tree cannot both be the client; one fan-out sits in the
|
|
154
|
+
* slot and both subscribe to it.
|
|
155
|
+
*
|
|
156
|
+
* Use {@link DataConnection} directly instead when the client is yours: an
|
|
157
|
+
* adopter service that implements the protocol plus its own methods, a single
|
|
158
|
+
* consumer that IS the client, or a request/response-only client that binds
|
|
159
|
+
* nothing.
|
|
160
|
+
*/
|
|
161
|
+
export class DataConnectionWithEvents<
|
|
162
|
+
TTransfer extends TransferElement,
|
|
163
|
+
TServer extends DataServerProtocol<TTransfer, DiagnosticOf<TServer>> = DataServerProtocol<TTransfer>
|
|
164
|
+
> extends DataConnection<TTransfer, TServer, DataEvents<TTransfer, DiagnosticOf<TServer>, ProjectOf<TServer>>> {
|
|
165
|
+
/** Server pushes, fanned out to as many local listeners as the host has. */
|
|
166
|
+
readonly events: DataEvents<TTransfer, DiagnosticOf<TServer>, ProjectOf<TServer>>;
|
|
167
|
+
|
|
168
|
+
constructor(port: DataPort, options?: DataConnectionOptions) {
|
|
169
|
+
// Built as a local because `this` is unavailable before `super`, then
|
|
170
|
+
// read back onto the field.
|
|
171
|
+
const events = new DataEvents<TTransfer, DiagnosticOf<TServer>, ProjectOf<TServer>>();
|
|
172
|
+
super(port, events, options);
|
|
173
|
+
this.events = events;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/** Disposes the fan-out it created, which no caller else holds. */
|
|
177
|
+
override dispose(): void {
|
|
178
|
+
super.dispose();
|
|
179
|
+
this.events.dispose();
|
|
180
|
+
}
|
|
181
|
+
}
|
|
@@ -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,21 +8,25 @@
|
|
|
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
|
|
14
|
-
* connection to the data server, plus the
|
|
15
|
-
* with it.
|
|
15
|
+
* connection to the data server, plus the failure sink that goes with it.
|
|
16
16
|
*
|
|
17
|
-
* "Port" in the hexagonal sense — the host implements it, `
|
|
17
|
+
* "Port" in the hexagonal sense — the host implements it, `DataConnection`
|
|
18
18
|
* consumes it, and nothing on either side of the boundary imports the other.
|
|
19
19
|
*
|
|
20
|
+
* Carries no identity. A `clientId` names a participant, and one transport
|
|
21
|
+
* serves as many as the host has; binding an identity here is what makes two
|
|
22
|
+
* of them share one, so it lives on `DataSession` instead.
|
|
23
|
+
*
|
|
20
24
|
* **This deliberately does NOT wrap the protocol methods.** `createRpcProxy`
|
|
21
25
|
* already takes a promise of a connection and produces the whole typed
|
|
22
26
|
* `DataServerProtocol` surface, so wrapping it would re-derive the framework's
|
|
23
27
|
* pass-throughs in a second place and lose the `as const satisfies keyof`
|
|
24
28
|
* method allowlists, which cannot drift. Everything a form or a tree actually
|
|
25
|
-
* does — the wire contract, the open/watch/update/close sequence, `
|
|
29
|
+
* does — the wire contract, the open/watch/update/close sequence, `basedOn`
|
|
26
30
|
* conflict handling, echo filtering by `sourceClientId` — is host-invariant and
|
|
27
31
|
* lives above this interface. What varies between hosts is exactly the four
|
|
28
32
|
* members below.
|
|
@@ -45,22 +49,6 @@ import type { Event, MessageConnection } from 'vscode-jsonrpc';
|
|
|
45
49
|
* calls on the promise but never calls `listen` itself.
|
|
46
50
|
*/
|
|
47
51
|
export interface DataPort {
|
|
48
|
-
/**
|
|
49
|
-
* Stable identity of this client on the data server, passed as `clientId`
|
|
50
|
-
* on every document request.
|
|
51
|
-
*
|
|
52
|
-
* It has to be stable for the session because it is the echo key: an
|
|
53
|
-
* inbound `onDocumentUpdated` carries the originating mutation's
|
|
54
|
-
* `clientId` as `sourceClientId`, and a client that cannot recognise its
|
|
55
|
-
* own echo treats its own write as a concurrent third-party one. It also
|
|
56
|
-
* has to be distinct per client, since it keys the server's per-
|
|
57
|
-
* `(uri, clientId)` watch bucket.
|
|
58
|
-
*
|
|
59
|
-
* Avoid the three values the framework itself uses as sentinels —
|
|
60
|
-
* `'language-client'`, `'unknown'` and `'revert-on-close'`.
|
|
61
|
-
*/
|
|
62
|
-
readonly clientId: string;
|
|
63
|
-
|
|
64
52
|
/**
|
|
65
53
|
* Open the transport and hand back a listening `MessageConnection`.
|
|
66
54
|
*
|
|
@@ -77,10 +65,16 @@ export interface DataPort {
|
|
|
77
65
|
*
|
|
78
66
|
* It exists because the alternative is worse in both directions: this tier
|
|
79
67
|
* cannot import a host's UI, and swallowing the error makes a dead
|
|
80
|
-
* connection look like an empty model.
|
|
81
|
-
*
|
|
68
|
+
* connection look like an empty model.
|
|
69
|
+
*
|
|
70
|
+
* `reported` is a complete sentence plus the identity needed to render it in
|
|
71
|
+
* another language. It carries a value rather than using a protocol field
|
|
72
|
+
* because this tier does not know whether a process hop intervenes — in a
|
|
73
|
+
* webview host the render happens across one — and a `ResolvedMessage` is
|
|
74
|
+
* structured-clone safe either way. Render it with `renderFrameworkMessage`;
|
|
75
|
+
* passing no translation map yields the English.
|
|
82
76
|
*/
|
|
83
|
-
reportError(error: unknown,
|
|
77
|
+
reportError(error: unknown, reported: ResolvedMessage): void;
|
|
84
78
|
|
|
85
79
|
/**
|
|
86
80
|
* Fires when the host tears the transport down and the current connection
|