@hydranium/protocol 1.0.0-next.8 → 1.0.0-next.86
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +35 -1
- package/lib/client/data-connection.d.ts +114 -0
- package/lib/client/data-connection.d.ts.map +1 -0
- package/lib/client/data-connection.js +128 -0
- package/lib/client/data-connection.js.map +1 -0
- package/lib/client/data-events.d.ts +9 -1
- package/lib/client/data-events.d.ts.map +1 -1
- package/lib/client/data-events.js +14 -0
- package/lib/client/data-events.js.map +1 -1
- package/lib/client/data-port.d.ts +17 -22
- package/lib/client/data-port.d.ts.map +1 -1
- package/lib/client/data-session.d.ts +95 -78
- package/lib/client/data-session.d.ts.map +1 -1
- package/lib/client/data-session.js +115 -108
- package/lib/client/data-session.js.map +1 -1
- package/lib/client/index.d.ts +10 -7
- package/lib/client/index.d.ts.map +1 -1
- package/lib/client/index.js +10 -7
- package/lib/client/index.js.map +1 -1
- package/lib/client/message-relay.d.ts +8 -2
- package/lib/client/message-relay.d.ts.map +1 -1
- package/lib/client/message-relay.js +10 -4
- package/lib/client/message-relay.js.map +1 -1
- package/lib/client/rpc-connection.d.ts +139 -0
- package/lib/client/rpc-connection.d.ts.map +1 -0
- package/lib/client/rpc-connection.js +171 -0
- package/lib/client/rpc-connection.js.map +1 -0
- package/lib/client-ids.d.ts +41 -0
- package/lib/client-ids.d.ts.map +1 -0
- package/lib/client-ids.js +44 -0
- package/lib/client-ids.js.map +1 -0
- package/lib/data/data-protocol-methods.d.ts +2 -2
- package/lib/data/data-protocol-methods.d.ts.map +1 -1
- package/lib/data/data-protocol-methods.js +6 -1
- package/lib/data/data-protocol-methods.js.map +1 -1
- package/lib/data/data-server-protocol.d.ts +35 -2
- package/lib/data/data-server-protocol.d.ts.map +1 -1
- package/lib/data/events.d.ts +70 -3
- package/lib/data/events.d.ts.map +1 -1
- package/lib/errors.d.ts +28 -11
- package/lib/errors.d.ts.map +1 -1
- package/lib/errors.js +35 -17
- package/lib/errors.js.map +1 -1
- package/lib/index.d.ts +2 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +5 -0
- package/lib/index.js.map +1 -1
- package/lib/messages/index.d.ts +28 -0
- package/lib/messages/index.d.ts.map +1 -0
- package/lib/messages/index.js +52 -0
- package/lib/messages/index.js.map +1 -0
- package/lib/messages/primitives.d.ts +141 -0
- package/lib/messages/primitives.d.ts.map +1 -0
- package/lib/messages/primitives.js +138 -0
- package/lib/messages/primitives.js.map +1 -0
- package/lib/model-server.d.ts +27 -10
- package/lib/model-server.d.ts.map +1 -1
- package/lib/model-server.js +4 -2
- package/lib/model-server.js.map +1 -1
- package/lib/model-service/args.d.ts +14 -13
- package/lib/model-service/args.d.ts.map +1 -1
- package/lib/model-service/based-on.d.ts +55 -0
- package/lib/model-service/based-on.d.ts.map +1 -0
- package/lib/model-service/based-on.js +34 -0
- package/lib/model-service/based-on.js.map +1 -0
- package/lib/model-service/index.d.ts +1 -0
- package/lib/model-service/index.d.ts.map +1 -1
- package/lib/model-service/index.js +1 -0
- package/lib/model-service/index.js.map +1 -1
- package/lib/rpc/bind-rpc-methods.d.ts +29 -3
- package/lib/rpc/bind-rpc-methods.d.ts.map +1 -1
- package/lib/rpc/bind-rpc-methods.js +22 -3
- package/lib/rpc/bind-rpc-methods.js.map +1 -1
- package/lib/rpc/create-rpc-proxy.d.ts +7 -0
- package/lib/rpc/create-rpc-proxy.d.ts.map +1 -1
- package/lib/rpc/create-rpc-proxy.js +6 -1
- package/lib/rpc/create-rpc-proxy.js.map +1 -1
- package/lib/testing/catalogue-audit.d.ts +80 -0
- package/lib/testing/catalogue-audit.d.ts.map +1 -0
- package/lib/testing/catalogue-audit.js +94 -0
- package/lib/testing/catalogue-audit.js.map +1 -0
- package/lib/testing/data-doubles.d.ts +11 -12
- package/lib/testing/data-doubles.d.ts.map +1 -1
- package/lib/testing/data-doubles.js +14 -5
- package/lib/testing/data-doubles.js.map +1 -1
- package/lib/testing/index.d.ts +1 -0
- package/lib/testing/index.d.ts.map +1 -1
- package/lib/testing/index.js +4 -1
- package/lib/testing/index.js.map +1 -1
- package/lib/transfer-diagnostic.d.ts +33 -0
- package/lib/transfer-diagnostic.d.ts.map +1 -1
- package/lib/transfer-diagnostic.js +23 -0
- package/lib/transfer-diagnostic.js.map +1 -1
- package/lib/transfer-document.d.ts +15 -5
- package/lib/transfer-document.d.ts.map +1 -1
- package/lib/transfer-document.js +14 -1
- package/lib/transfer-document.js.map +1 -1
- package/package.json +11 -2
- package/src/client/data-connection.ts +181 -0
- package/src/client/data-events.ts +24 -1
- package/src/client/data-port.ts +17 -23
- package/src/client/data-session.ts +172 -131
- package/src/client/index.ts +10 -7
- package/src/client/message-relay.ts +28 -6
- package/src/client/rpc-connection.ts +230 -0
- package/src/client-ids.ts +45 -0
- package/src/data/data-protocol-methods.ts +6 -3
- package/src/data/data-server-protocol.ts +46 -2
- package/src/data/events.ts +74 -3
- package/src/errors.ts +41 -19
- package/src/index.ts +5 -0
- package/src/messages/index.ts +35 -0
- package/src/messages/primitives.ts +215 -0
- package/src/model-server.ts +30 -11
- package/src/model-service/args.ts +15 -13
- package/src/model-service/based-on.ts +60 -0
- package/src/model-service/index.ts +1 -0
- package/src/rpc/bind-rpc-methods.ts +49 -4
- package/src/rpc/create-rpc-proxy.ts +14 -1
- package/src/testing/catalogue-audit.ts +111 -0
- package/src/testing/data-doubles.ts +33 -17
- package/src/testing/index.ts +4 -1
- package/src/transfer-diagnostic.ts +40 -0
- package/src/transfer-document.ts +22 -6
|
@@ -34,7 +34,14 @@
|
|
|
34
34
|
import { Emitter, type MessageConnection } from 'vscode-jsonrpc';
|
|
35
35
|
import type { DataPort } from '../client/data-port';
|
|
36
36
|
import type { DataClientProtocol } from '../data/data-server-protocol';
|
|
37
|
-
import type {
|
|
37
|
+
import type {
|
|
38
|
+
ProjectsChangedEvent,
|
|
39
|
+
TransferDocumentDeletedEvent,
|
|
40
|
+
TransferDocumentSavedEvent,
|
|
41
|
+
TransferDocumentsBuiltEvent,
|
|
42
|
+
TransferDocumentUpdatedEvent
|
|
43
|
+
} from '../data/events';
|
|
44
|
+
import type { ResolvedMessage } from '../messages/primitives';
|
|
38
45
|
import type { Project } from '../project';
|
|
39
46
|
import type { TransferDiagnostic } from '../transfer-diagnostic';
|
|
40
47
|
import type { TransferElement } from '../transfer-element';
|
|
@@ -51,13 +58,6 @@ export interface FakeDataPortOptions {
|
|
|
51
58
|
* which the consumer surfaces through {@link FakeDataPort.reported}.
|
|
52
59
|
*/
|
|
53
60
|
connect(): MessageConnection | Promise<MessageConnection>;
|
|
54
|
-
/**
|
|
55
|
-
* Stable client identity. Defaults to `'fake-data-port'`, which avoids the
|
|
56
|
-
* three sentinels the framework reserves (`'language-client'`, `'unknown'`,
|
|
57
|
-
* `'revert-on-close'`); override it when a test needs two distinguishable
|
|
58
|
-
* clients on one server.
|
|
59
|
-
*/
|
|
60
|
-
clientId?: string;
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
/** A {@link DataPort} that records what passed through it. */
|
|
@@ -73,10 +73,11 @@ export interface FakeDataPort extends DataPort {
|
|
|
73
73
|
/**
|
|
74
74
|
* Every {@link DataPort.reportError} call, in order. Read from outside: this
|
|
75
75
|
* is the only place a transport failure surfaces, so a test for the failure
|
|
76
|
-
* path asserts
|
|
77
|
-
*
|
|
76
|
+
* path asserts here rather than on a rejection the consumer may legitimately
|
|
77
|
+
* swallow. Prefer asserting on `message.code`, which is stable, over
|
|
78
|
+
* `message.text`, which is the English default and may be reworded.
|
|
78
79
|
*/
|
|
79
|
-
readonly reported: readonly { readonly error: unknown; readonly
|
|
80
|
+
readonly reported: readonly { readonly error: unknown; readonly message: ResolvedMessage }[];
|
|
80
81
|
/**
|
|
81
82
|
* Fire {@link DataPort.onDispose} — the host tearing the transport down, a
|
|
82
83
|
* language-server restart being the case that forces the event to exist.
|
|
@@ -96,10 +97,9 @@ export interface FakeDataPort extends DataPort {
|
|
|
96
97
|
*/
|
|
97
98
|
export function makeFakeDataPort(options: FakeDataPortOptions): FakeDataPort {
|
|
98
99
|
const connections: MessageConnection[] = [];
|
|
99
|
-
const reported: { error: unknown;
|
|
100
|
+
const reported: { error: unknown; message: ResolvedMessage }[] = [];
|
|
100
101
|
const disposeEmitter = new Emitter<void>();
|
|
101
102
|
return {
|
|
102
|
-
clientId: options.clientId ?? 'fake-data-port',
|
|
103
103
|
connections,
|
|
104
104
|
reported,
|
|
105
105
|
onDispose: disposeEmitter.event,
|
|
@@ -108,8 +108,8 @@ export function makeFakeDataPort(options: FakeDataPortOptions): FakeDataPort {
|
|
|
108
108
|
connections.push(connection);
|
|
109
109
|
return connection;
|
|
110
110
|
},
|
|
111
|
-
reportError(error: unknown,
|
|
112
|
-
reported.push({ error,
|
|
111
|
+
reportError(error: unknown, message: ResolvedMessage): void {
|
|
112
|
+
reported.push({ error, message });
|
|
113
113
|
},
|
|
114
114
|
fireDispose(): void {
|
|
115
115
|
disposeEmitter.fire(undefined);
|
|
@@ -132,6 +132,10 @@ export interface CapturingDataClient<
|
|
|
132
132
|
readonly updates: TransferDocumentUpdatedEvent<TTransfer, TDiagnostic>[];
|
|
133
133
|
/** Every `onDocumentSaved` event, in arrival order. */
|
|
134
134
|
readonly saves: TransferDocumentSavedEvent<TTransfer, TDiagnostic>[];
|
|
135
|
+
/** Every `onDocumentDeleted` event, in arrival order. */
|
|
136
|
+
readonly deletions: TransferDocumentDeletedEvent[];
|
|
137
|
+
/** Every `onDocumentsBuilt` event, in arrival order. */
|
|
138
|
+
readonly builds: TransferDocumentsBuiltEvent[];
|
|
135
139
|
/** Every `onProjectsChanged` event, in arrival order. */
|
|
136
140
|
readonly projectsChanges: ProjectsChangedEvent<TProject>[];
|
|
137
141
|
}
|
|
@@ -139,7 +143,7 @@ export interface CapturingDataClient<
|
|
|
139
143
|
/**
|
|
140
144
|
* A {@link DataClientProtocol} that records every notification it receives.
|
|
141
145
|
*
|
|
142
|
-
* Recording
|
|
146
|
+
* Recording EVERY channel even when a suite reads one is deliberate: an
|
|
143
147
|
* event delivered on the wrong channel is a real defect of the data head, and a
|
|
144
148
|
* double that drops the other two turns it into silence on the one being
|
|
145
149
|
* watched.
|
|
@@ -156,6 +160,8 @@ export function makeCapturingDataClient<
|
|
|
156
160
|
>(overrides: Partial<DataClientProtocol<TTransfer, TDiagnostic, TProject>> = {}): CapturingDataClient<TTransfer, TDiagnostic, TProject> {
|
|
157
161
|
const updates: TransferDocumentUpdatedEvent<TTransfer, TDiagnostic>[] = [];
|
|
158
162
|
const saves: TransferDocumentSavedEvent<TTransfer, TDiagnostic>[] = [];
|
|
163
|
+
const deletions: TransferDocumentDeletedEvent[] = [];
|
|
164
|
+
const builds: TransferDocumentsBuiltEvent[] = [];
|
|
159
165
|
const projectsChanges: ProjectsChangedEvent<TProject>[] = [];
|
|
160
166
|
const client: DataClientProtocol<TTransfer, TDiagnostic, TProject> = {
|
|
161
167
|
onDocumentUpdated:
|
|
@@ -168,11 +174,21 @@ export function makeCapturingDataClient<
|
|
|
168
174
|
(event => {
|
|
169
175
|
saves.push(event);
|
|
170
176
|
}),
|
|
177
|
+
onDocumentDeleted:
|
|
178
|
+
overrides.onDocumentDeleted ??
|
|
179
|
+
(event => {
|
|
180
|
+
deletions.push(event);
|
|
181
|
+
}),
|
|
182
|
+
onDocumentsBuilt:
|
|
183
|
+
overrides.onDocumentsBuilt ??
|
|
184
|
+
(event => {
|
|
185
|
+
builds.push(event);
|
|
186
|
+
}),
|
|
171
187
|
onProjectsChanged:
|
|
172
188
|
overrides.onProjectsChanged ??
|
|
173
189
|
(event => {
|
|
174
190
|
projectsChanges.push(event);
|
|
175
191
|
})
|
|
176
192
|
};
|
|
177
|
-
return { client, updates, saves, projectsChanges };
|
|
193
|
+
return { client, updates, saves, deletions, builds, projectsChanges };
|
|
178
194
|
}
|
package/src/testing/index.ts
CHANGED
|
@@ -10,7 +10,9 @@
|
|
|
10
10
|
// Subpath barrel for `@hydranium/protocol/testing` — the BROWSER-NEUTRAL shared
|
|
11
11
|
// primitives: `makeFakeClock` (deterministic `Clock` double on one virtual time
|
|
12
12
|
// axis), `waitFor` / `tick`, the client-side data-head doubles
|
|
13
|
-
// (`makeFakeDataPort` / `makeCapturingDataClient`),
|
|
13
|
+
// (`makeFakeDataPort` / `makeCapturingDataClient`), the translation-catalogue
|
|
14
|
+
// audit (`flattenCatalogue` / `findUndeclaredCodes` / `findSharedCodes`), and
|
|
15
|
+
// the `Harness` marker
|
|
14
16
|
// interface every framework harness extends. Kept out of the main barrel so production bundles don't pull
|
|
15
17
|
// the test scaffolding in by default; adopters opt in by importing from
|
|
16
18
|
// `@hydranium/protocol/testing`.
|
|
@@ -20,6 +22,7 @@
|
|
|
20
22
|
// type, so they cannot be made portable and live at `./testing/node` instead.
|
|
21
23
|
// The same rule the package surface uses — the portable name is the short one.
|
|
22
24
|
|
|
25
|
+
export * from './catalogue-audit';
|
|
23
26
|
export * from './data-doubles';
|
|
24
27
|
export * from './fake-clock';
|
|
25
28
|
export * from './harness';
|
|
@@ -7,6 +7,8 @@
|
|
|
7
7
|
* SPDX-License-Identifier: MIT
|
|
8
8
|
********************************************************************************/
|
|
9
9
|
|
|
10
|
+
import { type MessageParams, type ResolvedMessage } from './messages/primitives';
|
|
11
|
+
|
|
10
12
|
/**
|
|
11
13
|
* Generic, transport-friendly diagnostic shape used by the model-server protocol.
|
|
12
14
|
*
|
|
@@ -56,6 +58,21 @@ export interface TransferDiagnostic {
|
|
|
56
58
|
* is not usable as a rule identity on its own.
|
|
57
59
|
*/
|
|
58
60
|
code?: number | string;
|
|
61
|
+
/**
|
|
62
|
+
* Substitutions for the placeholders in the message this {@link code} names,
|
|
63
|
+
* present only for a diagnostic raised from a framework message declaration.
|
|
64
|
+
*
|
|
65
|
+
* Without them a translated template renders with its `{name}` tokens left
|
|
66
|
+
* standing, because substitution leaves an unmatched token in place rather
|
|
67
|
+
* than raising — so a surface that translates from {@link code} alone is
|
|
68
|
+
* correct for a parameterless sentence and visibly wrong for a parameterised
|
|
69
|
+
* one. This is the field that makes the second case work; the LSP carrier has
|
|
70
|
+
* always moved the params, and no carrier below it did.
|
|
71
|
+
*
|
|
72
|
+
* Prefer {@link TransferDiagnostic.resolved} over reading this: it decides
|
|
73
|
+
* whether an identity is present at all, which a lone `params` cannot.
|
|
74
|
+
*/
|
|
75
|
+
params?: MessageParams;
|
|
59
76
|
}
|
|
60
77
|
|
|
61
78
|
export namespace TransferDiagnostic {
|
|
@@ -74,6 +91,29 @@ export namespace TransferDiagnostic {
|
|
|
74
91
|
return diagnostic.type === 'parsing-error';
|
|
75
92
|
}
|
|
76
93
|
|
|
94
|
+
/**
|
|
95
|
+
* The diagnostic as a renderable message, for a surface that translates.
|
|
96
|
+
* `undefined` when it carries no framework identity — a syntactic error, an
|
|
97
|
+
* adopter's own check, a linker failure — which is the case a caller must
|
|
98
|
+
* distinguish rather than render.
|
|
99
|
+
*
|
|
100
|
+
* Hand the result to `renderFrameworkMessage` with whatever catalogue the
|
|
101
|
+
* host has loaded. The `text` is the server's English, so a code the
|
|
102
|
+
* catalogue does not carry still yields a complete sentence.
|
|
103
|
+
*
|
|
104
|
+
* `code` alone does not establish an identity: it also holds Langium's
|
|
105
|
+
* internal code and an adopter's own, and either would be looked up against a
|
|
106
|
+
* catalogue that cannot have it. Requiring `params` is what discriminates,
|
|
107
|
+
* and it is why a parameterless framework message still populates the field
|
|
108
|
+
* with an empty object rather than omitting it.
|
|
109
|
+
*/
|
|
110
|
+
export function resolved(diagnostic: TransferDiagnostic): ResolvedMessage | undefined {
|
|
111
|
+
if (typeof diagnostic.code !== 'string' || diagnostic.params === undefined) {
|
|
112
|
+
return undefined;
|
|
113
|
+
}
|
|
114
|
+
return { code: diagnostic.code, params: diagnostic.params, text: diagnostic.message };
|
|
115
|
+
}
|
|
116
|
+
|
|
77
117
|
export function getPath(diagnostic: TransferDiagnostic): string {
|
|
78
118
|
return diagnostic.property ? `${diagnostic.element}${ELEMENT_PROPERTY_SEPARATOR}${diagnostic.property}` : diagnostic.element;
|
|
79
119
|
}
|
package/src/transfer-document.ts
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
|
|
10
10
|
import type { TransferDiagnostic } from './transfer-diagnostic';
|
|
11
11
|
import type { TransferElement } from './transfer-element';
|
|
12
|
+
import { asSnapshotVersion, type SnapshotVersion } from './model-service/based-on';
|
|
12
13
|
|
|
13
14
|
/**
|
|
14
15
|
* Wire envelope exchanged between the model-server's data-server head and
|
|
@@ -27,14 +28,14 @@ export interface TransferDocument<TTransfer extends TransferElement, TDiagnostic
|
|
|
27
28
|
uri: string;
|
|
28
29
|
/**
|
|
29
30
|
* The document version this snapshot was taken at — sourced from the
|
|
30
|
-
* server's text-document version counter.
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
31
|
+
* server's text-document version counter. A caller that mutates the document
|
|
32
|
+
* subsequently sends this straight back as `TransferUpdateArgs.basedOn` (or
|
|
33
|
+
* `TransferSaveArgs.basedOn`), and the server rejects a stale-based update
|
|
34
|
+
* with `ConflictError`.
|
|
34
35
|
*
|
|
35
36
|
* See `@hydranium/protocol#errors` for the conflict-detection contract.
|
|
36
37
|
*/
|
|
37
|
-
version:
|
|
38
|
+
version: SnapshotVersion;
|
|
38
39
|
/**
|
|
39
40
|
* Absent when the document does not exist — the server answers an unknown URI
|
|
40
41
|
* with a shaped envelope rather than an error, so absence is an ordinary
|
|
@@ -82,6 +83,21 @@ export namespace TransferDocument {
|
|
|
82
83
|
return document;
|
|
83
84
|
}
|
|
84
85
|
|
|
86
|
+
/**
|
|
87
|
+
* The envelope for a document the server does not have — `root` absent, and
|
|
88
|
+
* the version a read of a URI the store never saw reports.
|
|
89
|
+
*
|
|
90
|
+
* Exists so the absent branch is built the same way the present one is: both
|
|
91
|
+
* doors mark the version as coming from a read, and neither asks a caller to
|
|
92
|
+
* do it.
|
|
93
|
+
*/
|
|
94
|
+
export function absent<TTransfer extends TransferElement, TDiagnostic = TransferDiagnostic>(
|
|
95
|
+
uri: string,
|
|
96
|
+
diagnostics: TDiagnostic[] = []
|
|
97
|
+
): TransferDocument<TTransfer, TDiagnostic> {
|
|
98
|
+
return { uri, version: asSnapshotVersion(0), root: undefined, diagnostics };
|
|
99
|
+
}
|
|
100
|
+
|
|
85
101
|
/**
|
|
86
102
|
* Construct a {@link TransferDocument} envelope. `diagnostics` defaults
|
|
87
103
|
* to `[]` so test fixtures, fake protocol implementations, and the
|
|
@@ -94,6 +110,6 @@ export namespace TransferDocument {
|
|
|
94
110
|
root: TTransfer,
|
|
95
111
|
diagnostics: TDiagnostic[] = []
|
|
96
112
|
): TransferDocument<TTransfer, TDiagnostic> {
|
|
97
|
-
return { uri, version, root, diagnostics };
|
|
113
|
+
return { uri, version: asSnapshotVersion(version), root, diagnostics };
|
|
98
114
|
}
|
|
99
115
|
}
|