@hydranium/protocol 1.0.0-next.17 → 1.0.0-next.174
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 +157 -0
- package/lib/client/data-connection.d.ts.map +1 -0
- package/lib/client/data-connection.js +236 -0
- package/lib/client/data-connection.js.map +1 -0
- package/lib/client/data-events.d.ts +13 -1
- package/lib/client/data-events.d.ts.map +1 -1
- package/lib/client/data-events.js +21 -0
- package/lib/client/data-events.js.map +1 -1
- package/lib/client/data-port.d.ts +25 -23
- package/lib/client/data-port.d.ts.map +1 -1
- package/lib/client/data-session.d.ts +440 -78
- package/lib/client/data-session.d.ts.map +1 -1
- package/lib/client/data-session.js +697 -106
- package/lib/client/data-session.js.map +1 -1
- package/lib/client/index.d.ts +13 -8
- package/lib/client/index.d.ts.map +1 -1
- package/lib/client/index.js +13 -8
- package/lib/client/index.js.map +1 -1
- package/lib/client/message-relay.d.ts +9 -3
- package/lib/client/message-relay.d.ts.map +1 -1
- package/lib/client/message-relay.js +11 -5
- package/lib/client/message-relay.js.map +1 -1
- package/lib/client/post-message-transport.d.ts +64 -3
- package/lib/client/post-message-transport.d.ts.map +1 -1
- package/lib/client/post-message-transport.js +175 -1
- package/lib/client/post-message-transport.js.map +1 -1
- package/lib/client/rpc-connection.d.ts +149 -0
- package/lib/client/rpc-connection.d.ts.map +1 -0
- package/lib/client/rpc-connection.js +202 -0
- package/lib/client/rpc-connection.js.map +1 -0
- package/lib/client-ids.d.ts +45 -0
- package/lib/client-ids.d.ts.map +1 -0
- package/lib/client-ids.js +48 -0
- package/lib/client-ids.js.map +1 -0
- package/lib/clock.d.ts +38 -0
- package/lib/clock.d.ts.map +1 -1
- package/lib/clock.js +36 -1
- package/lib/clock.js.map +1 -1
- package/lib/data/data-protocol-methods.d.ts +4 -4
- package/lib/data/data-protocol-methods.d.ts.map +1 -1
- package/lib/data/data-protocol-methods.js +11 -1
- package/lib/data/data-protocol-methods.js.map +1 -1
- package/lib/data/data-server-protocol.d.ts +111 -31
- package/lib/data/data-server-protocol.d.ts.map +1 -1
- package/lib/data/events.d.ts +103 -14
- package/lib/data/events.d.ts.map +1 -1
- package/lib/data/requests.d.ts +67 -11
- package/lib/data/requests.d.ts.map +1 -1
- package/lib/errors.d.ts +163 -17
- package/lib/errors.d.ts.map +1 -1
- package/lib/errors.js +219 -22
- package/lib/errors.js.map +1 -1
- package/lib/glsp-save-model-actions.d.ts +50 -0
- package/lib/glsp-save-model-actions.d.ts.map +1 -0
- package/lib/glsp-save-model-actions.js +28 -0
- package/lib/glsp-save-model-actions.js.map +1 -0
- package/lib/index.d.ts +3 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +6 -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 +29 -0
- package/lib/messages/index.d.ts.map +1 -0
- package/lib/messages/index.js +58 -0
- package/lib/messages/index.js.map +1 -0
- package/lib/messages/primitives.d.ts +188 -0
- package/lib/messages/primitives.d.ts.map +1 -0
- package/lib/messages/primitives.js +161 -0
- package/lib/messages/primitives.js.map +1 -0
- package/lib/model-server.d.ts +60 -13
- 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/based-on.d.ts +57 -0
- package/lib/model-service/based-on.d.ts.map +1 -0
- package/lib/model-service/based-on.js +37 -0
- package/lib/model-service/based-on.js.map +1 -0
- package/lib/model-service/index.d.ts +1 -1
- package/lib/model-service/index.d.ts.map +1 -1
- package/lib/model-service/index.js +4 -5
- package/lib/model-service/index.js.map +1 -1
- package/lib/patch-merge.d.ts +28 -27
- package/lib/patch-merge.d.ts.map +1 -1
- package/lib/patch-merge.js +66 -22
- package/lib/patch-merge.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 +13 -12
- package/lib/testing/data-doubles.d.ts.map +1 -1
- package/lib/testing/data-doubles.js +19 -5
- package/lib/testing/data-doubles.js.map +1 -1
- package/lib/testing/fake-clock.d.ts +9 -1
- package/lib/testing/fake-clock.d.ts.map +1 -1
- package/lib/testing/fake-clock.js +54 -45
- package/lib/testing/fake-clock.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/testing/node/index.d.ts +1 -0
- package/lib/testing/node/index.d.ts.map +1 -1
- package/lib/testing/node/index.js +2 -2
- package/lib/testing/node/index.js.map +1 -1
- package/lib/testing/node/message-port-pair.d.ts +25 -0
- package/lib/testing/node/message-port-pair.d.ts.map +1 -0
- package/lib/testing/node/message-port-pair.js +26 -0
- package/lib/testing/node/message-port-pair.js.map +1 -0
- 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 +34 -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/lib/util.d.ts +8 -0
- package/lib/util.d.ts.map +1 -1
- package/lib/util.js +32 -0
- package/lib/util.js.map +1 -1
- package/package.json +11 -2
- package/src/client/data-connection.ts +314 -0
- package/src/client/data-events.ts +33 -1
- package/src/client/data-port.ts +26 -24
- package/src/client/data-session.ts +880 -123
- package/src/client/index.ts +13 -8
- package/src/client/message-relay.ts +29 -7
- package/src/client/post-message-transport.ts +219 -4
- package/src/client/rpc-connection.ts +268 -0
- package/src/client-ids.ts +49 -0
- package/src/clock.ts +56 -0
- package/src/data/data-protocol-methods.ts +11 -3
- package/src/data/data-server-protocol.ts +132 -31
- package/src/data/events.ts +109 -14
- package/src/data/requests.ts +71 -11
- package/src/errors.ts +259 -24
- package/src/glsp-save-model-actions.ts +59 -0
- package/src/index.ts +6 -0
- package/src/latency-collector.ts +8 -3
- package/src/messages/index.ts +36 -0
- package/src/messages/primitives.ts +271 -0
- package/src/model-server.ts +63 -18
- package/src/model-service/based-on.ts +63 -0
- package/src/model-service/index.ts +4 -5
- package/src/patch-merge.ts +90 -37
- 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 +42 -17
- package/src/testing/fake-clock.ts +62 -47
- package/src/testing/index.ts +4 -1
- package/src/testing/node/index.ts +2 -2
- package/src/testing/node/message-port-pair.ts +40 -0
- package/src/transfer-diagnostic.ts +40 -0
- package/src/transfer-document.ts +41 -6
- package/src/util.ts +33 -0
- package/lib/model-service/args.d.ts +0 -64
- package/lib/model-service/args.d.ts.map +0 -1
- package/lib/model-service/args.js +0 -11
- package/lib/model-service/args.js.map +0 -1
- package/src/model-service/args.ts +0 -67
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* SPDX-License-Identifier: MIT
|
|
8
8
|
********************************************************************************/
|
|
9
9
|
|
|
10
|
-
import { type Clock, type Stopwatch,
|
|
10
|
+
import { type Clock, type Stopwatch, SystemClock } from '../clock';
|
|
11
11
|
import { Disposable } from '../util';
|
|
12
12
|
|
|
13
13
|
/** A {@link Clock} whose time only moves when the test calls {@link FakeClock.advance}. */
|
|
@@ -17,9 +17,13 @@ export interface FakeClock extends Clock {
|
|
|
17
17
|
* whose deadline falls within the window — in chronological order, each at
|
|
18
18
|
* its own deadline (so `now()` inside a callback reads the fire instant, not
|
|
19
19
|
* the advance target). Timers scheduled by a callback fire too if they fall
|
|
20
|
-
* within the same window.
|
|
20
|
+
* within the same window. A {@link Clock.raceTimer} over a promise that
|
|
21
|
+
* settles through a chain still pending loses to the timer, so let that
|
|
22
|
+
* chain settle before advancing.
|
|
21
23
|
*/
|
|
22
24
|
advance(ms: number): void;
|
|
25
|
+
/** How many {@link Clock.setTimer} timers have neither fired nor been disposed. */
|
|
26
|
+
pendingTimers(): number;
|
|
23
27
|
}
|
|
24
28
|
|
|
25
29
|
interface FakeTimer {
|
|
@@ -39,68 +43,79 @@ interface FakeTimer {
|
|
|
39
43
|
*
|
|
40
44
|
* Server-free and DI-free — lives in `@hydranium/protocol/testing` so every
|
|
41
45
|
* head can bind it without pulling in a server package.
|
|
46
|
+
*
|
|
47
|
+
* The clock is a `SystemClock` with its time replaced, so its methods live on
|
|
48
|
+
* its prototype and a spread of it carries none of them. Replace one by
|
|
49
|
+
* assigning it onto the clock, or layer over the clock with `Object.create`.
|
|
42
50
|
*/
|
|
43
51
|
export function makeFakeClock(options: { now?: number } = {}): FakeClock {
|
|
44
|
-
|
|
45
|
-
|
|
52
|
+
return new VirtualClock(options.now ?? 0);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* A `SystemClock` whose time, stopwatches and timers read one virtual axis, so
|
|
57
|
+
* the `measure` and `raceTimer` it inherits run on that axis too.
|
|
58
|
+
*/
|
|
59
|
+
class VirtualClock extends SystemClock implements FakeClock {
|
|
60
|
+
protected readonly timers: FakeTimer[] = [];
|
|
46
61
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
62
|
+
constructor(protected current: number) {
|
|
63
|
+
super();
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
override now(): number {
|
|
67
|
+
return this.current;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
override setTimer(callback: () => void, ms: number): Disposable {
|
|
71
|
+
const timer: FakeTimer = { at: this.current + ms, callback, disposed: false, fired: false };
|
|
72
|
+
this.timers.push(timer);
|
|
73
|
+
return Disposable.create(() => {
|
|
74
|
+
timer.disposed = true;
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
override stopwatch(): Stopwatch {
|
|
79
|
+
const read = (): number => this.current;
|
|
80
|
+
const start = read();
|
|
81
|
+
let lastLap = start;
|
|
50
82
|
let stopped: number | undefined;
|
|
51
83
|
return {
|
|
52
84
|
get elapsedMs(): number {
|
|
53
|
-
return (stopped ??
|
|
85
|
+
return (stopped ?? read()) - start;
|
|
54
86
|
},
|
|
55
87
|
lap(): number {
|
|
56
|
-
const at = stopped ??
|
|
88
|
+
const at = stopped ?? read();
|
|
57
89
|
const split = at - lastLap;
|
|
58
90
|
lastLap = at;
|
|
59
91
|
return split;
|
|
60
92
|
},
|
|
61
93
|
stop(): number {
|
|
62
|
-
|
|
63
|
-
stopped = current;
|
|
64
|
-
}
|
|
94
|
+
stopped ??= read();
|
|
65
95
|
return stopped - start;
|
|
66
96
|
}
|
|
67
97
|
};
|
|
68
|
-
}
|
|
98
|
+
}
|
|
69
99
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
return (result as Promise<T>).then(value => ({ result: value, elapsedMs: stopwatch.elapsedMs }));
|
|
85
|
-
}
|
|
86
|
-
return { result: result as T, elapsedMs: stopwatch.elapsedMs };
|
|
87
|
-
}) as Clock['measure'],
|
|
88
|
-
advance(ms: number): void {
|
|
89
|
-
const target = current + ms;
|
|
90
|
-
// Fire due timers one at a time, re-scanning after each so a callback
|
|
91
|
-
// that schedules a nearer timer still fires within this window.
|
|
92
|
-
for (;;) {
|
|
93
|
-
const next = timers
|
|
94
|
-
.filter(timer => !timer.disposed && !timer.fired && timer.at <= target)
|
|
95
|
-
.sort((left, right) => left.at - right.at)[0];
|
|
96
|
-
if (!next) {
|
|
97
|
-
break;
|
|
98
|
-
}
|
|
99
|
-
current = next.at;
|
|
100
|
-
next.fired = true;
|
|
101
|
-
next.callback();
|
|
100
|
+
pendingTimers(): number {
|
|
101
|
+
return this.timers.filter(timer => !timer.disposed && !timer.fired).length;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
advance(ms: number): void {
|
|
105
|
+
const target = this.current + ms;
|
|
106
|
+
// Fire due timers one at a time, re-scanning after each so a callback
|
|
107
|
+
// that schedules a nearer timer still fires within this window.
|
|
108
|
+
for (;;) {
|
|
109
|
+
const next = this.timers
|
|
110
|
+
.filter(timer => !timer.disposed && !timer.fired && timer.at <= target)
|
|
111
|
+
.sort((left, right) => left.at - right.at)[0];
|
|
112
|
+
if (!next) {
|
|
113
|
+
break;
|
|
102
114
|
}
|
|
103
|
-
current =
|
|
115
|
+
this.current = next.at;
|
|
116
|
+
next.fired = true;
|
|
117
|
+
next.callback();
|
|
104
118
|
}
|
|
105
|
-
|
|
119
|
+
this.current = target;
|
|
120
|
+
}
|
|
106
121
|
}
|
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';
|
|
@@ -8,8 +8,7 @@
|
|
|
8
8
|
********************************************************************************/
|
|
9
9
|
|
|
10
10
|
// Subpath barrel for `@hydranium/protocol/testing/node` — the test transports
|
|
11
|
-
// that need a Node runtime
|
|
12
|
-
// `MessageConnection` bridge over it.
|
|
11
|
+
// that need a Node runtime.
|
|
13
12
|
//
|
|
14
13
|
// Separate from `./testing` because a `PassThrough` is in `DuplexStreamPair`'s
|
|
15
14
|
// exported type and `StreamMessageReader` comes from `vscode-jsonrpc/node`, so
|
|
@@ -20,3 +19,4 @@
|
|
|
20
19
|
|
|
21
20
|
export * from './duplex-connection';
|
|
22
21
|
export * from './duplex-stream';
|
|
22
|
+
export * from './message-port-pair';
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/********************************************************************************
|
|
2
|
+
* Copyright (c) 2026 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 { MessageChannel } from 'node:worker_threads';
|
|
11
|
+
import type { TransferredMessagePort } from '../../client/post-message-transport';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* The two ends of a `worker_threads` `MessageChannel`, typed as the transferred
|
|
15
|
+
* browser ports `createMessagePortTransport` takes. Node's port clones and keeps
|
|
16
|
+
* order as a browser's does, which is what lets a headless test stand in for a
|
|
17
|
+
* worker.
|
|
18
|
+
*
|
|
19
|
+
* `dispose` closes both ports. Node reports that as a close and a browser port
|
|
20
|
+
* reports nothing, so a test that asserts on a close does so before teardown.
|
|
21
|
+
*/
|
|
22
|
+
export interface MessagePortPair {
|
|
23
|
+
readonly port1: TransferredMessagePort;
|
|
24
|
+
readonly port2: TransferredMessagePort;
|
|
25
|
+
dispose(): void;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function makeMessagePortPair(): MessagePortPair {
|
|
29
|
+
const channel = new MessageChannel();
|
|
30
|
+
return {
|
|
31
|
+
// Node's port satisfies the structural type at runtime; the cast records
|
|
32
|
+
// one platform's port standing in for the other's.
|
|
33
|
+
port1: channel.port1 as unknown as TransferredMessagePort,
|
|
34
|
+
port2: channel.port2 as unknown as TransferredMessagePort,
|
|
35
|
+
dispose(): void {
|
|
36
|
+
channel.port1.close();
|
|
37
|
+
channel.port2.close();
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
}
|
|
@@ -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,13 @@ 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
|
-
* updates and reject them with `ConflictError`.
|
|
31
|
+
* server's text-document version counter. A caller that mutates the document
|
|
32
|
+
* subsequently sends this straight back as `TransferUpdateDocumentArgs.basedOn`, and
|
|
33
|
+
* the server rejects a stale-based update with `ConflictError`.
|
|
34
34
|
*
|
|
35
35
|
* See `@hydranium/protocol#errors` for the conflict-detection contract.
|
|
36
36
|
*/
|
|
37
|
-
version:
|
|
37
|
+
version: SnapshotVersion;
|
|
38
38
|
/**
|
|
39
39
|
* Absent when the document does not exist — the server answers an unknown URI
|
|
40
40
|
* with a shaped envelope rather than an error, so absence is an ordinary
|
|
@@ -43,6 +43,26 @@ export interface TransferDocument<TTransfer extends TransferElement, TDiagnostic
|
|
|
43
43
|
*/
|
|
44
44
|
root?: TTransfer;
|
|
45
45
|
diagnostics: TDiagnostic[];
|
|
46
|
+
/**
|
|
47
|
+
* Whether the server holds text for this document that its file does not,
|
|
48
|
+
* as the server last knew the file: set on every document a data server
|
|
49
|
+
* answers or sends that the server holds, and absent otherwise. A change
|
|
50
|
+
* after this snapshot arrives as `onDocumentDirtyChanged` to a client
|
|
51
|
+
* watching the document.
|
|
52
|
+
*/
|
|
53
|
+
dirty?: boolean;
|
|
54
|
+
/**
|
|
55
|
+
* What `textHash` makes of the text the server holds for this document
|
|
56
|
+
* when it sends it: set on every document a data server answers or sends
|
|
57
|
+
* that the server holds, and absent otherwise. Equal texts hash equal,
|
|
58
|
+
* whatever the version, so a client compares the text two snapshots hold,
|
|
59
|
+
* across a revert or a server restart that numbers versions afresh.
|
|
60
|
+
*
|
|
61
|
+
* Of the text alone. The data server's de-duplication fingerprint hashes the
|
|
62
|
+
* text or the transfer root together with the diagnostics, and changes with
|
|
63
|
+
* a diagnostic where this does not.
|
|
64
|
+
*/
|
|
65
|
+
textHash?: string;
|
|
46
66
|
}
|
|
47
67
|
|
|
48
68
|
/**
|
|
@@ -82,6 +102,21 @@ export namespace TransferDocument {
|
|
|
82
102
|
return document;
|
|
83
103
|
}
|
|
84
104
|
|
|
105
|
+
/**
|
|
106
|
+
* The envelope for a document the server does not have — `root` absent, and
|
|
107
|
+
* the version a read of a URI the store never saw reports.
|
|
108
|
+
*
|
|
109
|
+
* Exists so the absent branch is built the same way the present one is: both
|
|
110
|
+
* doors mark the version as coming from a read, and neither asks a caller to
|
|
111
|
+
* do it.
|
|
112
|
+
*/
|
|
113
|
+
export function absent<TTransfer extends TransferElement, TDiagnostic = TransferDiagnostic>(
|
|
114
|
+
uri: string,
|
|
115
|
+
diagnostics: TDiagnostic[] = []
|
|
116
|
+
): TransferDocument<TTransfer, TDiagnostic> {
|
|
117
|
+
return { uri, version: asSnapshotVersion(0), root: undefined, diagnostics };
|
|
118
|
+
}
|
|
119
|
+
|
|
85
120
|
/**
|
|
86
121
|
* Construct a {@link TransferDocument} envelope. `diagnostics` defaults
|
|
87
122
|
* to `[]` so test fixtures, fake protocol implementations, and the
|
|
@@ -94,6 +129,6 @@ export namespace TransferDocument {
|
|
|
94
129
|
root: TTransfer,
|
|
95
130
|
diagnostics: TDiagnostic[] = []
|
|
96
131
|
): TransferDocument<TTransfer, TDiagnostic> {
|
|
97
|
-
return { uri, version, root, diagnostics };
|
|
132
|
+
return { uri, version: asSnapshotVersion(version), root, diagnostics };
|
|
98
133
|
}
|
|
99
134
|
}
|
package/src/util.ts
CHANGED
|
@@ -248,3 +248,36 @@ export function getAt<T = unknown>(obj: unknown, path: string[]): T | undefined
|
|
|
248
248
|
}
|
|
249
249
|
return cur as T;
|
|
250
250
|
}
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* A stable, non-cryptographic digest of `text`, equal on every host for equal
|
|
254
|
+
* text: the `TransferDocument.textHash` a data server stamps, so a client can
|
|
255
|
+
* hash text of its own to compare. An array is read as its elements joined, so
|
|
256
|
+
* a large text is hashed in parts without concatenating it. It tells whether a
|
|
257
|
+
* text changed, not who could forge one.
|
|
258
|
+
*/
|
|
259
|
+
export function textHash(text: string | readonly string[]): string {
|
|
260
|
+
const { high, low } = cyrb53(typeof text === 'string' ? [text] : text);
|
|
261
|
+
return high.toString(16).padStart(8, '0') + low.toString(16).padStart(8, '0');
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* The two 32-bit words cyrb53 ends on, each unsigned, for `parts` read as one
|
|
266
|
+
* string. It needs no `node:*` module, so every host runs it.
|
|
267
|
+
*/
|
|
268
|
+
function cyrb53(parts: readonly string[]): { readonly high: number; readonly low: number } {
|
|
269
|
+
let h1 = 0xdeadbeef;
|
|
270
|
+
let h2 = 0x41c6ce57;
|
|
271
|
+
for (const part of parts) {
|
|
272
|
+
for (let i = 0; i < part.length; i++) {
|
|
273
|
+
const code = part.charCodeAt(i);
|
|
274
|
+
h1 = Math.imul(h1 ^ code, 2654435761);
|
|
275
|
+
h2 = Math.imul(h2 ^ code, 1597334677);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
h1 = Math.imul(h1 ^ (h1 >>> 16), 2246822507);
|
|
279
|
+
h1 ^= Math.imul(h2 ^ (h2 >>> 13), 3266489909);
|
|
280
|
+
h2 = Math.imul(h2 ^ (h2 >>> 16), 2246822507);
|
|
281
|
+
h2 ^= Math.imul(h1 ^ (h1 >>> 13), 3266489909);
|
|
282
|
+
return { high: h2 >>> 0, low: h1 >>> 0 };
|
|
283
|
+
}
|
|
@@ -1,64 +0,0 @@
|
|
|
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
|
-
* Argument shapes for the in-process `ModelService` facade — the
|
|
11
|
-
* canonical home for the lifecycle operation signatures. Implementation
|
|
12
|
-
* lives in `@hydranium/core/langium/model-service`; this protocol
|
|
13
|
-
* package owns the types so wire-side projections (the data-server
|
|
14
|
-
* protocol in `./data`) can structurally extend them rather than
|
|
15
|
-
* mirroring them by hand.
|
|
16
|
-
*
|
|
17
|
-
* `./model-server.ts` re-exports them, so an import from either path
|
|
18
|
-
* resolves.
|
|
19
|
-
*/
|
|
20
|
-
/** Identifies a client-document binding. Every facade operation carries these fields. */
|
|
21
|
-
export interface TransferClientArgs {
|
|
22
|
-
/** Document URI. */
|
|
23
|
-
uri: string;
|
|
24
|
-
/** Stable identifier for the client invoking the operation. */
|
|
25
|
-
clientId: string;
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Update a document's content via the in-process facade. `model` may be
|
|
29
|
-
* the structured (transfer-model or AST) root or its serialised textual
|
|
30
|
-
* form — implementations decide which is faster on their transport.
|
|
31
|
-
* Generic over `T` so adopters parameterise the structured shape against
|
|
32
|
-
* their grammar's transfer-model overlay; passing a string is always
|
|
33
|
-
* allowed.
|
|
34
|
-
*/
|
|
35
|
-
export interface TransferUpdateArgs<T> extends TransferClientArgs {
|
|
36
|
-
/** Structured model root or its serialised textual form. */
|
|
37
|
-
model: T | string;
|
|
38
|
-
/**
|
|
39
|
-
* Optional based-on version: the text-document version this update
|
|
40
|
-
* was authored against. When set, the server compares against its
|
|
41
|
-
* current text-document version for `uri` and throws
|
|
42
|
-
* `ConflictError` on mismatch. Omit to opt out of the gate — mirrors
|
|
43
|
-
* LSP's `OptionalVersionedTextDocumentIdentifier` posture, intended
|
|
44
|
-
* for headless / CLI / batch tooling without a meaningful based-on
|
|
45
|
-
* version.
|
|
46
|
-
*/
|
|
47
|
-
baseVersion?: number;
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Persist a document to disk via the in-process facade. Same `model`
|
|
51
|
-
* shape as {@link TransferUpdateArgs}.
|
|
52
|
-
*/
|
|
53
|
-
export interface TransferSaveArgs<T> extends TransferClientArgs {
|
|
54
|
-
/** Structured model root or its serialised textual form. */
|
|
55
|
-
model: T | string;
|
|
56
|
-
/**
|
|
57
|
-
* Optional based-on version — same semantics as
|
|
58
|
-
* {@link TransferUpdateArgs.baseVersion}. `save` delegates the gating
|
|
59
|
-
* check to its inner `update`, so this field threads through to the
|
|
60
|
-
* same `ConflictError` site.
|
|
61
|
-
*/
|
|
62
|
-
baseVersion?: number;
|
|
63
|
-
}
|
|
64
|
-
//# sourceMappingURL=args.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"args.d.ts","sourceRoot":"","sources":["../../src/model-service/args.ts"],"names":[],"mappings":"AAAA;;;;;;;kFAOkF;AAElF;;;;;;;;;;GAUG;AAEH,yFAAyF;AACzF,MAAM,WAAW,kBAAkB;IAChC,oBAAoB;IACpB,GAAG,EAAE,MAAM,CAAC;IACZ,+DAA+D;IAC/D,QAAQ,EAAE,MAAM,CAAC;CACnB;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,kBAAkB,CAAC,CAAC,CAAE,SAAQ,kBAAkB;IAC9D,4DAA4D;IAC5D,KAAK,EAAE,CAAC,GAAG,MAAM,CAAC;IAClB;;;;;;;;OAQG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;CACvB;AAED;;;GAGG;AACH,MAAM,WAAW,gBAAgB,CAAC,CAAC,CAAE,SAAQ,kBAAkB;IAC5D,4DAA4D;IAC5D,KAAK,EAAE,CAAC,GAAG,MAAM,CAAC;IAClB;;;;;OAKG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;CACvB"}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/********************************************************************************
|
|
3
|
-
* Copyright (c) 2026 CrossBreeze, EclipseSource and others.
|
|
4
|
-
*
|
|
5
|
-
* This program and the accompanying materials are made available under the
|
|
6
|
-
* terms of the MIT License which is available in the project root.
|
|
7
|
-
*
|
|
8
|
-
* SPDX-License-Identifier: MIT
|
|
9
|
-
********************************************************************************/
|
|
10
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
-
//# sourceMappingURL=args.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"args.js","sourceRoot":"","sources":["../../src/model-service/args.ts"],"names":[],"mappings":";AAAA;;;;;;;kFAOkF"}
|
|
@@ -1,67 +0,0 @@
|
|
|
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
|
-
* Argument shapes for the in-process `ModelService` facade — the
|
|
12
|
-
* canonical home for the lifecycle operation signatures. Implementation
|
|
13
|
-
* lives in `@hydranium/core/langium/model-service`; this protocol
|
|
14
|
-
* package owns the types so wire-side projections (the data-server
|
|
15
|
-
* protocol in `./data`) can structurally extend them rather than
|
|
16
|
-
* mirroring them by hand.
|
|
17
|
-
*
|
|
18
|
-
* `./model-server.ts` re-exports them, so an import from either path
|
|
19
|
-
* resolves.
|
|
20
|
-
*/
|
|
21
|
-
|
|
22
|
-
/** Identifies a client-document binding. Every facade operation carries these fields. */
|
|
23
|
-
export interface TransferClientArgs {
|
|
24
|
-
/** Document URI. */
|
|
25
|
-
uri: string;
|
|
26
|
-
/** Stable identifier for the client invoking the operation. */
|
|
27
|
-
clientId: string;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Update a document's content via the in-process facade. `model` may be
|
|
32
|
-
* the structured (transfer-model or AST) root or its serialised textual
|
|
33
|
-
* form — implementations decide which is faster on their transport.
|
|
34
|
-
* Generic over `T` so adopters parameterise the structured shape against
|
|
35
|
-
* their grammar's transfer-model overlay; passing a string is always
|
|
36
|
-
* allowed.
|
|
37
|
-
*/
|
|
38
|
-
export interface TransferUpdateArgs<T> extends TransferClientArgs {
|
|
39
|
-
/** Structured model root or its serialised textual form. */
|
|
40
|
-
model: T | string;
|
|
41
|
-
/**
|
|
42
|
-
* Optional based-on version: the text-document version this update
|
|
43
|
-
* was authored against. When set, the server compares against its
|
|
44
|
-
* current text-document version for `uri` and throws
|
|
45
|
-
* `ConflictError` on mismatch. Omit to opt out of the gate — mirrors
|
|
46
|
-
* LSP's `OptionalVersionedTextDocumentIdentifier` posture, intended
|
|
47
|
-
* for headless / CLI / batch tooling without a meaningful based-on
|
|
48
|
-
* version.
|
|
49
|
-
*/
|
|
50
|
-
baseVersion?: number;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Persist a document to disk via the in-process facade. Same `model`
|
|
55
|
-
* shape as {@link TransferUpdateArgs}.
|
|
56
|
-
*/
|
|
57
|
-
export interface TransferSaveArgs<T> extends TransferClientArgs {
|
|
58
|
-
/** Structured model root or its serialised textual form. */
|
|
59
|
-
model: T | string;
|
|
60
|
-
/**
|
|
61
|
-
* Optional based-on version — same semantics as
|
|
62
|
-
* {@link TransferUpdateArgs.baseVersion}. `save` delegates the gating
|
|
63
|
-
* check to its inner `update`, so this field threads through to the
|
|
64
|
-
* same `ConflictError` site.
|
|
65
|
-
*/
|
|
66
|
-
baseVersion?: number;
|
|
67
|
-
}
|