@hydranium/protocol 1.0.0-next.11 → 1.0.0-next.111
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 +152 -0
- package/lib/client/data-connection.d.ts.map +1 -0
- package/lib/client/data-connection.js +214 -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 +154 -76
- package/lib/client/data-session.d.ts.map +1 -1
- package/lib/client/data-session.js +194 -109
- 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 +143 -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/latency-collector.d.ts +8 -4
- package/lib/latency-collector.d.ts.map +1 -1
- package/lib/latency-collector.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 +174 -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/profile-session.d.ts +8 -4
- package/lib/profile-session.d.ts.map +1 -1
- package/lib/profile-session.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 +266 -0
- package/src/client/data-events.ts +24 -1
- package/src/client/data-port.ts +17 -23
- package/src/client/data-session.ts +279 -131
- package/src/client/index.ts +10 -7
- package/src/client/message-relay.ts +28 -6
- package/src/client/rpc-connection.ts +235 -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/latency-collector.ts +8 -3
- package/src/messages/index.ts +35 -0
- package/src/messages/primitives.ts +250 -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/profile-session.ts +9 -4
- 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
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
********************************************************************************/
|
|
9
9
|
import type { TransferDiagnostic } from './transfer-diagnostic';
|
|
10
10
|
import type { TransferElement } from './transfer-element';
|
|
11
|
+
import { type SnapshotVersion } from './model-service/based-on';
|
|
11
12
|
/**
|
|
12
13
|
* Wire envelope exchanged between the model-server's data-server head and
|
|
13
14
|
* its clients. Carries a transfer-shaped root — never an AST root — plus
|
|
@@ -25,14 +26,14 @@ export interface TransferDocument<TTransfer extends TransferElement, TDiagnostic
|
|
|
25
26
|
uri: string;
|
|
26
27
|
/**
|
|
27
28
|
* The document version this snapshot was taken at — sourced from the
|
|
28
|
-
* server's text-document version counter.
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
29
|
+
* server's text-document version counter. A caller that mutates the document
|
|
30
|
+
* subsequently sends this straight back as `TransferUpdateArgs.basedOn` (or
|
|
31
|
+
* `TransferSaveArgs.basedOn`), and the server rejects a stale-based update
|
|
32
|
+
* with `ConflictError`.
|
|
32
33
|
*
|
|
33
34
|
* See `@hydranium/protocol#errors` for the conflict-detection contract.
|
|
34
35
|
*/
|
|
35
|
-
version:
|
|
36
|
+
version: SnapshotVersion;
|
|
36
37
|
/**
|
|
37
38
|
* Absent when the document does not exist — the server answers an unknown URI
|
|
38
39
|
* with a shaped envelope rather than an error, so absence is an ordinary
|
|
@@ -62,6 +63,15 @@ export declare namespace TransferDocument {
|
|
|
62
63
|
* with it.
|
|
63
64
|
*/
|
|
64
65
|
function assertLoaded<TTransfer extends TransferElement, TDiagnostic = TransferDiagnostic>(document: TransferDocument<TTransfer, TDiagnostic>): LoadedTransferDocument<TTransfer, TDiagnostic>;
|
|
66
|
+
/**
|
|
67
|
+
* The envelope for a document the server does not have — `root` absent, and
|
|
68
|
+
* the version a read of a URI the store never saw reports.
|
|
69
|
+
*
|
|
70
|
+
* Exists so the absent branch is built the same way the present one is: both
|
|
71
|
+
* doors mark the version as coming from a read, and neither asks a caller to
|
|
72
|
+
* do it.
|
|
73
|
+
*/
|
|
74
|
+
function absent<TTransfer extends TransferElement, TDiagnostic = TransferDiagnostic>(uri: string, diagnostics?: TDiagnostic[]): TransferDocument<TTransfer, TDiagnostic>;
|
|
65
75
|
/**
|
|
66
76
|
* Construct a {@link TransferDocument} envelope. `diagnostics` defaults
|
|
67
77
|
* to `[]` so test fixtures, fake protocol implementations, and the
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transfer-document.d.ts","sourceRoot":"","sources":["../src/transfer-document.ts"],"names":[],"mappings":"AAAA;;;;;;;kFAOkF;AAElF,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAChE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"transfer-document.d.ts","sourceRoot":"","sources":["../src/transfer-document.ts"],"names":[],"mappings":"AAAA;;;;;;;kFAOkF;AAElF,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAChE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,EAAqB,KAAK,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAEnF;;;;;;;;;;;;GAYG;AACH,MAAM,WAAW,gBAAgB,CAAC,SAAS,SAAS,eAAe,EAAE,WAAW,GAAG,kBAAkB;IAClG,GAAG,EAAE,MAAM,CAAC;IACZ;;;;;;;;OAQG;IACH,OAAO,EAAE,eAAe,CAAC;IACzB;;;;;OAKG;IACH,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB,WAAW,EAAE,WAAW,EAAE,CAAC;CAC7B;AAED;;;GAGG;AACH,MAAM,MAAM,sBAAsB,CAAC,SAAS,SAAS,eAAe,EAAE,WAAW,GAAG,kBAAkB,IAAI,gBAAgB,CACvH,SAAS,EACT,WAAW,CACb,GAAG;IACD,IAAI,EAAE,SAAS,CAAC;CAClB,CAAC;AAEF,yBAAiB,gBAAgB,CAAC;IAC/B;;;OAGG;IACH,SAAgB,QAAQ,CAAC,SAAS,SAAS,eAAe,EAAE,WAAW,GAAG,kBAAkB,EACzF,QAAQ,EAAE,gBAAgB,CAAC,SAAS,EAAE,WAAW,CAAC,GAClD,QAAQ,IAAI,sBAAsB,CAAC,SAAS,EAAE,WAAW,CAAC,CAE5D;IAED;;;;;OAKG;IACH,SAAgB,YAAY,CAAC,SAAS,SAAS,eAAe,EAAE,WAAW,GAAG,kBAAkB,EAC7F,QAAQ,EAAE,gBAAgB,CAAC,SAAS,EAAE,WAAW,CAAC,GAClD,sBAAsB,CAAC,SAAS,EAAE,WAAW,CAAC,CAKhD;IAED;;;;;;;OAOG;IACH,SAAgB,MAAM,CAAC,SAAS,SAAS,eAAe,EAAE,WAAW,GAAG,kBAAkB,EACvF,GAAG,EAAE,MAAM,EACX,WAAW,GAAE,WAAW,EAAO,GAC/B,gBAAgB,CAAC,SAAS,EAAE,WAAW,CAAC,CAE1C;IAED;;;;;OAKG;IACH,SAAgB,MAAM,CAAC,SAAS,SAAS,eAAe,EAAE,WAAW,GAAG,kBAAkB,EACvF,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,SAAS,EACf,WAAW,GAAE,WAAW,EAAO,GAC/B,gBAAgB,CAAC,SAAS,EAAE,WAAW,CAAC,CAE1C;CACH"}
|
package/lib/transfer-document.js
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
********************************************************************************/
|
|
10
10
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
11
|
exports.TransferDocument = void 0;
|
|
12
|
+
const based_on_1 = require("./model-service/based-on");
|
|
12
13
|
var TransferDocument;
|
|
13
14
|
(function (TransferDocument) {
|
|
14
15
|
/**
|
|
@@ -32,6 +33,18 @@ var TransferDocument;
|
|
|
32
33
|
return document;
|
|
33
34
|
}
|
|
34
35
|
TransferDocument.assertLoaded = assertLoaded;
|
|
36
|
+
/**
|
|
37
|
+
* The envelope for a document the server does not have — `root` absent, and
|
|
38
|
+
* the version a read of a URI the store never saw reports.
|
|
39
|
+
*
|
|
40
|
+
* Exists so the absent branch is built the same way the present one is: both
|
|
41
|
+
* doors mark the version as coming from a read, and neither asks a caller to
|
|
42
|
+
* do it.
|
|
43
|
+
*/
|
|
44
|
+
function absent(uri, diagnostics = []) {
|
|
45
|
+
return { uri, version: (0, based_on_1.asSnapshotVersion)(0), root: undefined, diagnostics };
|
|
46
|
+
}
|
|
47
|
+
TransferDocument.absent = absent;
|
|
35
48
|
/**
|
|
36
49
|
* Construct a {@link TransferDocument} envelope. `diagnostics` defaults
|
|
37
50
|
* to `[]` so test fixtures, fake protocol implementations, and the
|
|
@@ -39,7 +52,7 @@ var TransferDocument;
|
|
|
39
52
|
* at every call site.
|
|
40
53
|
*/
|
|
41
54
|
function create(uri, version, root, diagnostics = []) {
|
|
42
|
-
return { uri, version, root, diagnostics };
|
|
55
|
+
return { uri, version: (0, based_on_1.asSnapshotVersion)(version), root, diagnostics };
|
|
43
56
|
}
|
|
44
57
|
TransferDocument.create = create;
|
|
45
58
|
})(TransferDocument || (exports.TransferDocument = TransferDocument = {}));
|
|
@@ -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.111",
|
|
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,266 @@
|
|
|
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
|
+
* Holds a disposed session could not release, keyed `clientId` + `uri` so a
|
|
81
|
+
* repeated handover does not queue the same close twice.
|
|
82
|
+
*
|
|
83
|
+
* Retried on this connection's own activity rather than on a timer: every
|
|
84
|
+
* session operation asks for the proxy, so a shared connection with anything
|
|
85
|
+
* else going on supplies the occasions, and one with nothing going on has
|
|
86
|
+
* nobody whose documents the stale hold could affect.
|
|
87
|
+
*/
|
|
88
|
+
protected readonly orphanedHolds = new Map<string, { readonly uri: string; readonly clientId: string }>();
|
|
89
|
+
/** Guards {@link releaseOrphanedHolds} against re-entering through its own proxy lookup. */
|
|
90
|
+
protected releasingOrphans = false;
|
|
91
|
+
|
|
92
|
+
constructor(port: DataPort, client: TClient, ...rest: DataConnectionArgs<TTransfer, TClient>) {
|
|
93
|
+
const [options = {}] = rest as [(DataConnectionOptions & Partial<DataConnectionOptionsWithMethods<TClient>>)?];
|
|
94
|
+
super(port, client, {
|
|
95
|
+
methodNamespace: options.methodNamespace ?? DATA_SERVER_WIRE_PREFIX,
|
|
96
|
+
// The default is reachable only where `TClient` satisfies
|
|
97
|
+
// `DataClientProtocol`, which the constructor's conditional enforces;
|
|
98
|
+
// the compiler cannot carry that through to the generic parameter.
|
|
99
|
+
clientMethods: options.clientMethods ?? (DATA_CLIENT_PROTOCOL_METHODS as unknown as readonly (keyof TClient & string)[]),
|
|
100
|
+
lifecycle: options
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Mint a participant on this connection under `clientId`.
|
|
106
|
+
*
|
|
107
|
+
* `clientId` must be distinct per participant and stable for its lifetime:
|
|
108
|
+
* it keys the server's per-`(uri, clientId)` hold and watch, and it is the
|
|
109
|
+
* echo key an inbound `onDocumentUpdated` is matched against.
|
|
110
|
+
*
|
|
111
|
+
* Throws for an id in {@link FRAMEWORK_CLIENT_IDS} — those are authors the
|
|
112
|
+
* SERVER emits rather than participants, so a session holding one would read
|
|
113
|
+
* the framework's own broadcasts as its own echoes and drop them. Nothing
|
|
114
|
+
* about that fails on its own: the document simply stops following, which
|
|
115
|
+
* looks like a dead connection.
|
|
116
|
+
*
|
|
117
|
+
* Throws, too, for an id a LIVE session on this connection already holds.
|
|
118
|
+
* Per-document membership is a set of client ids, so two participants
|
|
119
|
+
* sharing one collapse to a single hold and the first close releases it
|
|
120
|
+
* under the survivor, which then stops receiving updates for a document it
|
|
121
|
+
* is still showing. A constant bound once per participant KIND — one per
|
|
122
|
+
* widget class rather than per instance — satisfies the type and violates
|
|
123
|
+
* this.
|
|
124
|
+
*
|
|
125
|
+
* And throws for an id whose previous session left a hold this connection is
|
|
126
|
+
* still trying to release. That release closes `(uri, clientId)`, so an id
|
|
127
|
+
* reissued while it is outstanding can have the new participant's hold closed
|
|
128
|
+
* out from under it. The id frees itself as soon as the release lands.
|
|
129
|
+
*
|
|
130
|
+
* The checks span this connection only, so a head several connections reach
|
|
131
|
+
* can still be addressed twice under one id.
|
|
132
|
+
*/
|
|
133
|
+
createSession(clientId: string): DataSession<TTransfer, TServer> {
|
|
134
|
+
this.assertLive();
|
|
135
|
+
if (FRAMEWORK_CLIENT_IDS.includes(clientId)) {
|
|
136
|
+
throw new Error(`clientId '${clientId}' is reserved by the framework and cannot identify a participant`);
|
|
137
|
+
}
|
|
138
|
+
if ([...this.sessions].some(session => session.clientId === clientId)) {
|
|
139
|
+
throw new Error(`clientId '${clientId}' already identifies a live participant on this connection`);
|
|
140
|
+
}
|
|
141
|
+
if ([...this.orphanedHolds.values()].some(hold => hold.clientId === clientId)) {
|
|
142
|
+
// A retry is still outstanding for this id, and it closes
|
|
143
|
+
// `(uri, clientId)` — which the server keys one hold per. Handing the
|
|
144
|
+
// id over now lets that close land on the NEW participant's hold
|
|
145
|
+
// instead, taking a document away from a session that opened it
|
|
146
|
+
// successfully. Nothing about that fails on its own: the document
|
|
147
|
+
// simply stops following, and the close that did it was issued for a
|
|
148
|
+
// participant already gone.
|
|
149
|
+
//
|
|
150
|
+
// Attempted first, so an id whose release has become possible is free
|
|
151
|
+
// by the next call rather than waiting for other traffic.
|
|
152
|
+
void this.releaseOrphanedHolds();
|
|
153
|
+
throw new Error(`clientId '${clientId}' has an unreleased hold on this connection and cannot identify a new participant yet`);
|
|
154
|
+
}
|
|
155
|
+
const session = new DataSession<TTransfer, TServer>(clientId, {
|
|
156
|
+
connected: async () => {
|
|
157
|
+
const server = await this.connected();
|
|
158
|
+
// Unawaited: a session's own operation must not wait on, or fail
|
|
159
|
+
// for, the release of a hold another participant abandoned.
|
|
160
|
+
void this.releaseOrphanedHolds();
|
|
161
|
+
return server;
|
|
162
|
+
},
|
|
163
|
+
releaseSession: released => this.sessions.delete(released),
|
|
164
|
+
orphanHold: (uri, holder) => this.orphanHold(uri, holder)
|
|
165
|
+
});
|
|
166
|
+
this.sessions.add(session);
|
|
167
|
+
return session;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Take over a `(uri, clientId)` hold a disposed session could not release.
|
|
172
|
+
*
|
|
173
|
+
* One attempt is made straight away, since whatever refused the session's
|
|
174
|
+
* close may already be over; a refusal leaves the entry for the next
|
|
175
|
+
* operation on this connection to retry.
|
|
176
|
+
*/
|
|
177
|
+
protected orphanHold(uri: string, clientId: string): void {
|
|
178
|
+
this.orphanedHolds.set(`${clientId}\u0000${uri}`, { uri, clientId });
|
|
179
|
+
void this.releaseOrphanedHolds();
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Try to close every hold handed over by a disposed session, keeping the ones
|
|
184
|
+
* the server still refuses.
|
|
185
|
+
*
|
|
186
|
+
* Errors are swallowed per entry: this runs off another participant's
|
|
187
|
+
* operation, which has no interest in an unrelated release and no caller to
|
|
188
|
+
* surface it to. A hold that survives every attempt is released by the
|
|
189
|
+
* server's connection-close cleanup.
|
|
190
|
+
*/
|
|
191
|
+
protected async releaseOrphanedHolds(): Promise<void> {
|
|
192
|
+
if (this.releasingOrphans || this.orphanedHolds.size === 0 || this.disposed) {
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
this.releasingOrphans = true;
|
|
196
|
+
try {
|
|
197
|
+
const server = await this.connected();
|
|
198
|
+
for (const [key, hold] of [...this.orphanedHolds]) {
|
|
199
|
+
try {
|
|
200
|
+
await server.closeModelDocument({ uri: hold.uri, clientId: hold.clientId });
|
|
201
|
+
this.orphanedHolds.delete(key);
|
|
202
|
+
} catch {
|
|
203
|
+
// Kept for the next occasion.
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
} catch {
|
|
207
|
+
// No proxy to release through; the entries wait for one.
|
|
208
|
+
} finally {
|
|
209
|
+
this.releasingOrphans = false;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* Sessions are detached rather than disposed: the server releases every hold
|
|
215
|
+
* on a connection it sees close, so closing each document first sends
|
|
216
|
+
* requests over a connection this call is about to dispose.
|
|
217
|
+
*/
|
|
218
|
+
override dispose(): void {
|
|
219
|
+
for (const session of [...this.sessions]) {
|
|
220
|
+
session.detach();
|
|
221
|
+
}
|
|
222
|
+
this.sessions.clear();
|
|
223
|
+
// Dropped rather than closed, for the same reason the sessions detach: the
|
|
224
|
+
// server releases every hold on a connection it sees close, and the close
|
|
225
|
+
// would travel over the connection being disposed.
|
|
226
|
+
this.orphanedHolds.clear();
|
|
227
|
+
super.dispose();
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* A {@link DataConnection} that brings its own {@link DataEvents}, so a host
|
|
233
|
+
* with several interested parties does not have to supply one.
|
|
234
|
+
*
|
|
235
|
+
* **The client slot holds exactly one object, and that is why this exists.**
|
|
236
|
+
* `createRpcProxy` binds a single `localTarget`, and underneath a method name
|
|
237
|
+
* maps to one handler — a second registration replaces the first silently. So a
|
|
238
|
+
* properties panel and a tree cannot both be the client; one fan-out sits in the
|
|
239
|
+
* slot and both subscribe to it.
|
|
240
|
+
*
|
|
241
|
+
* Use {@link DataConnection} directly instead when the client is yours: an
|
|
242
|
+
* adopter service that implements the protocol plus its own methods, a single
|
|
243
|
+
* consumer that IS the client, or a request/response-only client that binds
|
|
244
|
+
* nothing.
|
|
245
|
+
*/
|
|
246
|
+
export class DataConnectionWithEvents<
|
|
247
|
+
TTransfer extends TransferElement,
|
|
248
|
+
TServer extends DataServerProtocol<TTransfer, DiagnosticOf<TServer>> = DataServerProtocol<TTransfer>
|
|
249
|
+
> extends DataConnection<TTransfer, TServer, DataEvents<TTransfer, DiagnosticOf<TServer>, ProjectOf<TServer>>> {
|
|
250
|
+
/** Server pushes, fanned out to as many local listeners as the host has. */
|
|
251
|
+
readonly events: DataEvents<TTransfer, DiagnosticOf<TServer>, ProjectOf<TServer>>;
|
|
252
|
+
|
|
253
|
+
constructor(port: DataPort, options?: DataConnectionOptions) {
|
|
254
|
+
// Built as a local because `this` is unavailable before `super`, then
|
|
255
|
+
// read back onto the field.
|
|
256
|
+
const events = new DataEvents<TTransfer, DiagnosticOf<TServer>, ProjectOf<TServer>>();
|
|
257
|
+
super(port, events, options);
|
|
258
|
+
this.events = events;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/** Disposes the fan-out it created, which no caller else holds. */
|
|
262
|
+
override dispose(): void {
|
|
263
|
+
super.dispose();
|
|
264
|
+
this.events.dispose();
|
|
265
|
+
}
|
|
266
|
+
}
|
|
@@ -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
|