@hydranium/protocol 1.0.0-next.31 → 1.0.0-next.315
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 +44 -49
- package/lib/abstract-logger.d.ts +5 -0
- package/lib/abstract-logger.d.ts.map +1 -1
- package/lib/abstract-logger.js +7 -0
- package/lib/abstract-logger.js.map +1 -1
- package/lib/client/data-connection.d.ts +302 -0
- package/lib/client/data-connection.d.ts.map +1 -0
- package/lib/client/data-connection.js +533 -0
- package/lib/client/data-connection.js.map +1 -0
- package/lib/client/data-events.d.ts +17 -1
- package/lib/client/data-events.d.ts.map +1 -1
- package/lib/client/data-events.js +25 -0
- package/lib/client/data-events.js.map +1 -1
- package/lib/client/data-port.d.ts +34 -24
- package/lib/client/data-port.d.ts.map +1 -1
- package/lib/client/data-session.d.ts +657 -89
- package/lib/client/data-session.d.ts.map +1 -1
- package/lib/client/data-session.js +1113 -115
- package/lib/client/data-session.js.map +1 -1
- package/lib/client/index.d.ts +15 -9
- package/lib/client/index.d.ts.map +1 -1
- package/lib/client/index.js +15 -9
- package/lib/client/index.js.map +1 -1
- package/lib/client/message-relay.d.ts +4 -4
- package/lib/client/message-relay.js +4 -4
- 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 +157 -0
- package/lib/client/rpc-connection.d.ts.map +1 -0
- package/lib/client/rpc-connection.js +214 -0
- package/lib/client/rpc-connection.js.map +1 -0
- package/lib/client/worker-handshake.d.ts +86 -0
- package/lib/client/worker-handshake.d.ts.map +1 -0
- package/lib/client/worker-handshake.js +51 -0
- package/lib/client/worker-handshake.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 +50 -10
- package/lib/clock.d.ts.map +1 -1
- package/lib/clock.js +36 -1
- package/lib/clock.js.map +1 -1
- package/lib/console-logger.d.ts +23 -0
- package/lib/console-logger.d.ts.map +1 -0
- package/lib/console-logger.js +39 -0
- package/lib/console-logger.js.map +1 -0
- 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 +13 -1
- package/lib/data/data-protocol-methods.js.map +1 -1
- package/lib/data/data-server-protocol.d.ts +165 -48
- package/lib/data/data-server-protocol.d.ts.map +1 -1
- package/lib/data/events.d.ts +137 -21
- package/lib/data/events.d.ts.map +1 -1
- package/lib/data/requests.d.ts +71 -11
- package/lib/data/requests.d.ts.map +1 -1
- package/lib/debouncer.d.ts +3 -3
- package/lib/debouncer.d.ts.map +1 -1
- package/lib/debouncer.js +6 -9
- package/lib/debouncer.js.map +1 -1
- package/lib/errors.d.ts +183 -30
- package/lib/errors.d.ts.map +1 -1
- package/lib/errors.js +268 -32
- package/lib/errors.js.map +1 -1
- package/lib/glsp-request-model-args.d.ts +16 -0
- package/lib/glsp-request-model-args.d.ts.map +1 -0
- package/lib/glsp-request-model-args.js +19 -0
- package/lib/glsp-request-model-args.js.map +1 -0
- 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 +7 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +7 -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/logger.d.ts +38 -7
- package/lib/logger.d.ts.map +1 -1
- package/lib/logger.js +42 -4
- package/lib/logger.js.map +1 -1
- package/lib/messages/index.d.ts +4 -2
- package/lib/messages/index.d.ts.map +1 -1
- package/lib/messages/index.js +15 -4
- package/lib/messages/index.js.map +1 -1
- package/lib/messages/primitives.d.ts +71 -10
- package/lib/messages/primitives.d.ts.map +1 -1
- package/lib/messages/primitives.js +55 -3
- package/lib/messages/primitives.js.map +1 -1
- 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/base-version.d.ts +67 -0
- package/lib/model-service/base-version.d.ts.map +1 -0
- package/lib/model-service/base-version.js +44 -0
- package/lib/model-service/base-version.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/model-service/reference-candidate.d.ts +5 -3
- package/lib/model-service/reference-candidate.d.ts.map +1 -1
- package/lib/{model-service/args.js → node/index.d.ts} +2 -3
- package/lib/node/index.d.ts.map +1 -0
- package/lib/node/index.js +29 -0
- package/lib/node/index.js.map +1 -0
- package/lib/node/process-memory.d.ts +66 -0
- package/lib/node/process-memory.d.ts.map +1 -0
- package/lib/node/process-memory.js +291 -0
- package/lib/node/process-memory.js.map +1 -0
- package/lib/noop-logger.d.ts.map +1 -1
- package/lib/noop-logger.js.map +1 -1
- package/lib/observable-value.js.map +1 -1
- package/lib/patch-merge.d.ts +63 -35
- package/lib/patch-merge.d.ts.map +1 -1
- package/lib/patch-merge.js +171 -25
- 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/project.d.ts +4 -1
- package/lib/project.d.ts.map +1 -1
- package/lib/project.js.map +1 -1
- package/lib/random-uuid.d.ts +14 -0
- package/lib/random-uuid.d.ts.map +1 -0
- package/lib/random-uuid.js +24 -0
- package/lib/random-uuid.js.map +1 -0
- package/lib/reconcile-write.d.ts +67 -0
- package/lib/reconcile-write.d.ts.map +1 -0
- package/lib/reconcile-write.js +69 -0
- package/lib/reconcile-write.js.map +1 -0
- package/lib/rpc/bind-rpc-methods.d.ts +33 -3
- package/lib/rpc/bind-rpc-methods.d.ts.map +1 -1
- package/lib/rpc/bind-rpc-methods.js +32 -3
- package/lib/rpc/bind-rpc-methods.js.map +1 -1
- package/lib/rpc/create-rpc-proxy.d.ts +10 -0
- package/lib/rpc/create-rpc-proxy.d.ts.map +1 -1
- package/lib/rpc/create-rpc-proxy.js +12 -2
- package/lib/rpc/create-rpc-proxy.js.map +1 -1
- package/lib/rpc/index.d.ts +1 -0
- package/lib/rpc/index.d.ts.map +1 -1
- package/lib/rpc/index.js +1 -0
- package/lib/rpc/index.js.map +1 -1
- package/lib/rpc/send-by-method-name.d.ts +76 -0
- package/lib/rpc/send-by-method-name.d.ts.map +1 -0
- package/lib/rpc/send-by-method-name.js +120 -0
- package/lib/rpc/send-by-method-name.js.map +1 -0
- package/lib/rpc/wire-prefix.js.map +1 -1
- package/lib/save-text-document.d.ts +40 -0
- package/lib/save-text-document.d.ts.map +1 -0
- package/lib/save-text-document.js +34 -0
- package/lib/save-text-document.js.map +1 -0
- 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 +41 -12
- package/lib/testing/data-doubles.d.ts.map +1 -1
- package/lib/testing/data-doubles.js +56 -8
- package/lib/testing/data-doubles.js.map +1 -1
- package/lib/testing/fake-clock.d.ts +17 -2
- package/lib/testing/fake-clock.d.ts.map +1 -1
- package/lib/testing/fake-clock.js +61 -46
- 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 +5 -2
- package/lib/testing/index.js.map +1 -1
- package/lib/testing/node/duplex-connection.d.ts.map +1 -1
- package/lib/testing/node/duplex-connection.js +3 -2
- package/lib/testing/node/duplex-connection.js.map +1 -1
- package/lib/testing/node/duplex-stream.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/testing/wait-for.d.ts +9 -3
- package/lib/testing/wait-for.d.ts.map +1 -1
- package/lib/testing/wait-for.js +57 -11
- package/lib/testing/wait-for.js.map +1 -1
- package/lib/tracer.d.ts.map +1 -1
- package/lib/tracer.js +5 -9
- package/lib/tracer.js.map +1 -1
- package/lib/transfer-diagnostic.js.map +1 -1
- package/lib/transfer-document.d.ts +95 -32
- package/lib/transfer-document.d.ts.map +1 -1
- package/lib/transfer-document.js +17 -9
- package/lib/transfer-document.js.map +1 -1
- package/lib/uri.d.ts.map +1 -1
- package/lib/uri.js.map +1 -1
- package/lib/util.d.ts +8 -2
- package/lib/util.d.ts.map +1 -1
- package/lib/util.js +32 -4
- package/lib/util.js.map +1 -1
- package/package.json +24 -40
- package/src/abstract-logger.ts +8 -0
- package/src/client/data-connection.ts +653 -0
- package/src/client/data-events.ts +37 -1
- package/src/client/data-port.ts +36 -25
- package/src/client/data-session.ts +1427 -137
- package/src/client/index.ts +15 -9
- package/src/client/message-relay.ts +4 -4
- package/src/client/post-message-transport.ts +219 -4
- package/src/client/rpc-connection.ts +281 -0
- package/src/client/worker-handshake.ts +113 -0
- package/src/client-ids.ts +49 -0
- package/src/clock.ts +68 -10
- package/src/console-logger.ts +39 -0
- package/src/data/data-protocol-methods.ts +14 -4
- package/src/data/data-server-protocol.ts +192 -48
- package/src/data/events.ts +143 -21
- package/src/data/requests.ts +77 -11
- package/src/debouncer.ts +7 -10
- package/src/errors.ts +326 -40
- package/src/glsp-request-model-args.ts +16 -0
- package/src/glsp-save-model-actions.ts +59 -0
- package/src/index.ts +7 -0
- package/src/latency-collector.ts +8 -3
- package/src/logger.ts +44 -8
- package/src/messages/index.ts +4 -2
- package/src/messages/primitives.ts +102 -10
- package/src/model-server.ts +64 -19
- package/src/model-service/base-version.ts +75 -0
- package/src/model-service/index.ts +4 -5
- package/src/model-service/reference-candidate.ts +5 -3
- package/src/node/index.ts +14 -0
- package/src/node/process-memory.ts +299 -0
- package/src/patch-merge.ts +230 -45
- package/src/profile-session.ts +9 -4
- package/src/project.ts +4 -1
- package/src/random-uuid.ts +21 -0
- package/src/reconcile-write.ts +128 -0
- package/src/rpc/README.md +6 -6
- package/src/rpc/bind-rpc-methods.ts +59 -4
- package/src/rpc/create-rpc-proxy.ts +20 -2
- package/src/rpc/index.ts +1 -0
- package/src/rpc/send-by-method-name.ts +140 -0
- package/src/save-text-document.ts +39 -0
- package/src/testing/catalogue-audit.ts +111 -0
- package/src/testing/data-doubles.ts +141 -19
- package/src/testing/fake-clock.ts +76 -48
- package/src/testing/index.ts +5 -2
- package/src/testing/node/duplex-connection.ts +3 -2
- package/src/testing/node/index.ts +2 -2
- package/src/testing/node/message-port-pair.ts +40 -0
- package/src/testing/wait-for.ts +61 -13
- package/src/tracer.ts +5 -9
- package/src/transfer-document.ts +115 -34
- package/src/util.ts +33 -6
- 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.map +0 -1
- package/src/model-service/args.ts +0 -67
package/src/testing/wait-for.ts
CHANGED
|
@@ -33,13 +33,19 @@ export interface WaitForOptions {
|
|
|
33
33
|
readonly timeoutMs?: number;
|
|
34
34
|
/** Poll the predicate every this-many milliseconds. Default 5. */
|
|
35
35
|
readonly intervalMs?: number;
|
|
36
|
-
/**
|
|
37
|
-
|
|
36
|
+
/**
|
|
37
|
+
* Error message on timeout, and when the predicate throws. A function is
|
|
38
|
+
* called only then, so it can report the state the wait ended on; when it
|
|
39
|
+
* throws, the default text is used, with its throw as the error's `cause`
|
|
40
|
+
* unless the predicate threw. Default a generic phrasing.
|
|
41
|
+
*/
|
|
42
|
+
readonly message?: string | (() => string);
|
|
38
43
|
}
|
|
39
44
|
|
|
40
45
|
/**
|
|
41
46
|
* Resolve once `predicate()` returns true, polling at `intervalMs`; reject with
|
|
42
|
-
* `message` once `timeoutMs` elapses
|
|
47
|
+
* `message` once `timeoutMs` elapses, or at once when the predicate throws, with
|
|
48
|
+
* the throw as the error's `cause`. The **non-racy** alternative to a fixed
|
|
43
49
|
* sleep for awaiting an asynchronous side effect that lands on an observable
|
|
44
50
|
* value.
|
|
45
51
|
*
|
|
@@ -56,20 +62,62 @@ export interface WaitForOptions {
|
|
|
56
62
|
export function waitFor(predicate: () => boolean, options: WaitForOptions = {}): Promise<void> {
|
|
57
63
|
const timeoutMs = options.timeoutMs ?? 2000;
|
|
58
64
|
const intervalMs = options.intervalMs ?? 5;
|
|
59
|
-
const
|
|
60
|
-
if (predicate()) {
|
|
61
|
-
return Promise.resolve();
|
|
62
|
-
}
|
|
65
|
+
const defaultMessage = `Timed out after ${timeoutMs}ms waiting for a condition`;
|
|
63
66
|
return new Promise<void>((resolve, reject) => {
|
|
64
|
-
|
|
67
|
+
// A throw from the predicate or the message function would leave the
|
|
68
|
+
// promise unsettled from the poll's or the deadline's timer, or escape
|
|
69
|
+
// `waitFor` itself on the first check; it rejects instead, with the
|
|
70
|
+
// predicate's throw, else the message function's, as cause. True once
|
|
71
|
+
// the promise is settled.
|
|
72
|
+
const settle = (timedOut: boolean): boolean => {
|
|
73
|
+
let met = false;
|
|
74
|
+
let threw = false;
|
|
75
|
+
let cause: unknown;
|
|
76
|
+
try {
|
|
77
|
+
met = predicate();
|
|
78
|
+
} catch (error: unknown) {
|
|
79
|
+
threw = true;
|
|
80
|
+
cause = error;
|
|
81
|
+
}
|
|
82
|
+
if (met) {
|
|
83
|
+
resolve();
|
|
84
|
+
return true;
|
|
85
|
+
}
|
|
86
|
+
if (!timedOut && !threw) {
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
let message = defaultMessage;
|
|
90
|
+
try {
|
|
91
|
+
if (typeof options.message === 'function') {
|
|
92
|
+
message = options.message();
|
|
93
|
+
} else if (options.message !== undefined) {
|
|
94
|
+
message = options.message;
|
|
95
|
+
}
|
|
96
|
+
} catch (error: unknown) {
|
|
97
|
+
if (!threw) {
|
|
98
|
+
threw = true;
|
|
99
|
+
cause = error;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
reject(new Error(message, threw ? { cause } : undefined));
|
|
103
|
+
return true;
|
|
104
|
+
};
|
|
105
|
+
if (settle(false)) {
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
const stop = (): void => {
|
|
65
109
|
clearInterval(poll);
|
|
66
|
-
|
|
110
|
+
clearTimeout(deadline);
|
|
111
|
+
};
|
|
112
|
+
// A stalled loop can run the deadline after the condition came true but
|
|
113
|
+
// before the next poll saw it, so the deadline checks once more.
|
|
114
|
+
const deadline = setTimeout(() => {
|
|
115
|
+
settle(true);
|
|
116
|
+
stop();
|
|
67
117
|
}, timeoutMs);
|
|
68
118
|
const poll = setInterval(() => {
|
|
69
|
-
if (
|
|
70
|
-
|
|
71
|
-
clearTimeout(deadline);
|
|
72
|
-
resolve();
|
|
119
|
+
if (settle(false)) {
|
|
120
|
+
stop();
|
|
73
121
|
}
|
|
74
122
|
}, intervalMs);
|
|
75
123
|
});
|
package/src/tracer.ts
CHANGED
|
@@ -12,6 +12,7 @@ import { Format, Logger, type LogThreshold } from './logger';
|
|
|
12
12
|
import { NoopLogger } from './noop-logger';
|
|
13
13
|
import { DefaultProfileSession, type ProfileSession } from './profile-session';
|
|
14
14
|
import { Disposable } from './util';
|
|
15
|
+
import { describeErrorWithStack } from './messages/primitives';
|
|
15
16
|
|
|
16
17
|
/** Module-global so nested timers don't reuse ids. */
|
|
17
18
|
let nextTimerId = 0;
|
|
@@ -181,15 +182,10 @@ export class DefaultTracer implements Tracer {
|
|
|
181
182
|
const suffix = this.timingSuffix(status, elapsed, options);
|
|
182
183
|
this.logger[logLevel](`${label} [#${id} ${status}, ${Format.elapsed(elapsed)}${currentExtras()}${suffix}]`);
|
|
183
184
|
if (status === 'failed') {
|
|
184
|
-
//
|
|
185
|
-
//
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
const detail = error instanceof Error ? error.message : String(error);
|
|
189
|
-
this.logger.warn(`${label} [#${id}] failed: ${detail}`);
|
|
190
|
-
if (error instanceof Error && error.stack) {
|
|
191
|
-
this.logger.debug(error.stack);
|
|
192
|
-
}
|
|
185
|
+
// Reporting the failure is the caller's, who receives it: a line at
|
|
186
|
+
// warn here would exist only while `logLevel` is enabled.
|
|
187
|
+
const detail = describeErrorWithStack(error);
|
|
188
|
+
this.logger.debug(`${label} [#${id}] failed: ${detail}`);
|
|
193
189
|
}
|
|
194
190
|
};
|
|
195
191
|
let result: T;
|
package/src/transfer-document.ts
CHANGED
|
@@ -9,53 +9,123 @@
|
|
|
9
9
|
|
|
10
10
|
import type { TransferDiagnostic } from './transfer-diagnostic';
|
|
11
11
|
import type { TransferElement } from './transfer-element';
|
|
12
|
+
import { asModelVersion, type ModelVersion, type TextVersion } from './model-service/base-version';
|
|
13
|
+
|
|
14
|
+
/** The model a data server built for a document, encoded for the wire. */
|
|
15
|
+
export interface TransferModelSnapshot<TRoot extends TransferElement, TDiagnostic = TransferDiagnostic> {
|
|
16
|
+
root: TRoot;
|
|
17
|
+
/** Absent until the document is validated; `[]` once it is and nothing was found. */
|
|
18
|
+
diagnostics?: TDiagnostic[];
|
|
19
|
+
/**
|
|
20
|
+
* The version of the text `root` was parsed from. A caller that mutates the
|
|
21
|
+
* model sends this back as the `baseVersion` of its write, and the server
|
|
22
|
+
* rejects the write with `ConflictError` once its text has moved past it.
|
|
23
|
+
*/
|
|
24
|
+
version: ModelVersion;
|
|
25
|
+
/**
|
|
26
|
+
* The data server's fingerprint of `root` and `diagnostics`, or under its
|
|
27
|
+
* `'text-diagnostics'` strategy of the text `root` was parsed from and
|
|
28
|
+
* `diagnostics`.
|
|
29
|
+
* Independent of `version`; an equal hash also means equally validated.
|
|
30
|
+
*/
|
|
31
|
+
hash: string;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** The text a data server held for a document when it sent it. */
|
|
35
|
+
export interface TextState {
|
|
36
|
+
/**
|
|
37
|
+
* The server's version of that text. A `TransferModelSnapshot.version` below it
|
|
38
|
+
* means the model was parsed from older text, and an update at this version
|
|
39
|
+
* or a later one follows.
|
|
40
|
+
*/
|
|
41
|
+
version: TextVersion;
|
|
42
|
+
/**
|
|
43
|
+
* What `textHash` makes of the text alone: equal texts hash equal whatever
|
|
44
|
+
* their version or dirty state, across a revert or a server restart that
|
|
45
|
+
* numbers versions afresh.
|
|
46
|
+
*/
|
|
47
|
+
hash: string;
|
|
48
|
+
/**
|
|
49
|
+
* Whether the text differs from the file, as the server last knew the file.
|
|
50
|
+
* A later change arrives as `onDocumentDirtyChanged` to a client watching
|
|
51
|
+
* the document.
|
|
52
|
+
*/
|
|
53
|
+
dirty: boolean;
|
|
54
|
+
}
|
|
12
55
|
|
|
13
56
|
/**
|
|
14
57
|
* Wire envelope exchanged between the model-server's data-server head and
|
|
15
|
-
* its clients
|
|
16
|
-
*
|
|
58
|
+
* its clients: the server's model of a document and the text it holds for it,
|
|
59
|
+
* each absent where the server has none.
|
|
17
60
|
*
|
|
18
61
|
* The constraint `TTransfer extends TransferElement` pins the type system
|
|
19
62
|
* to the wire data shape (no `$container` cycles, references as strings;
|
|
20
|
-
* see {@link TransferElement}).
|
|
21
|
-
* `AstDocument<TAst extends AstNode, TDiagnostic>` in
|
|
22
|
-
* `@hydranium/core` — same structural shape, different generic
|
|
23
|
-
* constraint, used at the AST layer before the `TransferEncoder`
|
|
24
|
-
* translation produces a {@link TransferDocument}.
|
|
63
|
+
* see {@link TransferElement}).
|
|
25
64
|
*/
|
|
26
65
|
export interface TransferDocument<TTransfer extends TransferElement, TDiagnostic = TransferDiagnostic> {
|
|
27
66
|
uri: string;
|
|
28
67
|
/**
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
* (or `TransferSaveArgs.baseVersion`) so the server can detect stale-based
|
|
33
|
-
* updates and reject them with `ConflictError`.
|
|
34
|
-
*
|
|
35
|
-
* See `@hydranium/protocol#errors` for the conflict-detection contract.
|
|
68
|
+
* Absent when the document does not exist: the server answers an unknown
|
|
69
|
+
* URI with a shaped envelope rather than an error, so absence is an
|
|
70
|
+
* ordinary branch and not a catch.
|
|
36
71
|
*/
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
|
|
40
|
-
* with a shaped envelope rather than an error, so absence is an ordinary
|
|
41
|
-
* branch and not a catch. Declared required it reads as a guarantee, and
|
|
42
|
-
* every `root.x` compiles into a throw.
|
|
43
|
-
*/
|
|
44
|
-
root?: TTransfer;
|
|
45
|
-
diagnostics: TDiagnostic[];
|
|
72
|
+
model?: TransferModelSnapshot<TTransfer, TDiagnostic>;
|
|
73
|
+
/** Absent when the server holds no text for the document. */
|
|
74
|
+
text?: TextState;
|
|
46
75
|
}
|
|
47
76
|
|
|
48
77
|
/**
|
|
49
|
-
* A {@link TransferDocument} the server actually had, so `
|
|
78
|
+
* A {@link TransferDocument} the server actually had, so `model` is present.
|
|
50
79
|
* Narrowed to by {@link TransferDocument.isLoaded} / {@link TransferDocument.assertLoaded}.
|
|
51
80
|
*/
|
|
52
81
|
export type LoadedTransferDocument<TTransfer extends TransferElement, TDiagnostic = TransferDiagnostic> = TransferDocument<
|
|
53
82
|
TTransfer,
|
|
54
83
|
TDiagnostic
|
|
55
84
|
> & {
|
|
56
|
-
|
|
85
|
+
model: TransferModelSnapshot<TTransfer, TDiagnostic>;
|
|
57
86
|
};
|
|
58
87
|
|
|
88
|
+
/**
|
|
89
|
+
* What a save or a persist answers: the document, and in `persisted` the
|
|
90
|
+
* version of the text it wrote to the file. That can differ from
|
|
91
|
+
* `model.version` either way, since writes land between the build and the
|
|
92
|
+
* take, so a client marking a version saved takes it from here.
|
|
93
|
+
*/
|
|
94
|
+
export type TransferSavedDocument<TTransfer extends TransferElement, TDiagnostic = TransferDiagnostic> = TransferDocument<
|
|
95
|
+
TTransfer,
|
|
96
|
+
TDiagnostic
|
|
97
|
+
> & {
|
|
98
|
+
persisted: { version: TextVersion };
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* What a create answers: the document as a read after the create finds it,
|
|
103
|
+
* and in `created` the version the create's text took. Another client's write
|
|
104
|
+
* or an integrity repair can land between the create and that read, so
|
|
105
|
+
* `model.version` can be past it, and a write based on it would carry that
|
|
106
|
+
* text as the creator's; a write based on `created.version` conflicts instead.
|
|
107
|
+
* A model version, not a text version, because the creator holds the text at
|
|
108
|
+
* that version: it sent it.
|
|
109
|
+
*/
|
|
110
|
+
export type TransferCreatedDocument<TTransfer extends TransferElement, TDiagnostic = TransferDiagnostic> = TransferDocument<
|
|
111
|
+
TTransfer,
|
|
112
|
+
TDiagnostic
|
|
113
|
+
> & {
|
|
114
|
+
created: { version: ModelVersion };
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
/** What a watch answers, once it is in place. */
|
|
118
|
+
export interface TransferWatchedDocument {
|
|
119
|
+
/** The key the watch's events name the document by, which a symlinked URI does not spell. */
|
|
120
|
+
readonly uri: string;
|
|
121
|
+
/** Whether a document exists there; one the server fails to load counts, only a missing one does not. */
|
|
122
|
+
readonly exists: boolean;
|
|
123
|
+
/** The position of the last update or deletion event sent before `exists` was taken; an event past it was sent after. */
|
|
124
|
+
readonly sequence: number;
|
|
125
|
+
/** The text the server held when `exists` was taken, as a read answers it; absent when it held none. */
|
|
126
|
+
readonly text?: TextState;
|
|
127
|
+
}
|
|
128
|
+
|
|
59
129
|
export namespace TransferDocument {
|
|
60
130
|
/**
|
|
61
131
|
* Whether the server had this document. Branch on it where absence is an
|
|
@@ -64,13 +134,13 @@ export namespace TransferDocument {
|
|
|
64
134
|
export function isLoaded<TTransfer extends TransferElement, TDiagnostic = TransferDiagnostic>(
|
|
65
135
|
document: TransferDocument<TTransfer, TDiagnostic>
|
|
66
136
|
): document is LoadedTransferDocument<TTransfer, TDiagnostic> {
|
|
67
|
-
return document.
|
|
137
|
+
return document.model !== undefined;
|
|
68
138
|
}
|
|
69
139
|
|
|
70
140
|
/**
|
|
71
|
-
* The same document with `
|
|
141
|
+
* The same document with `model` no longer optional, or a throw. For call
|
|
72
142
|
* sites where absence is a bug rather than a branch; the whole envelope is
|
|
73
|
-
* returned because a caller needing `
|
|
143
|
+
* returned because a caller needing `model` usually needs `uri` or `text`
|
|
74
144
|
* with it.
|
|
75
145
|
*/
|
|
76
146
|
export function assertLoaded<TTransfer extends TransferElement, TDiagnostic = TransferDiagnostic>(
|
|
@@ -82,18 +152,29 @@ export namespace TransferDocument {
|
|
|
82
152
|
return document;
|
|
83
153
|
}
|
|
84
154
|
|
|
155
|
+
/** The envelope for a document the server does not have. */
|
|
156
|
+
export function absent<TTransfer extends TransferElement, TDiagnostic = TransferDiagnostic>(
|
|
157
|
+
uri: string
|
|
158
|
+
): TransferDocument<TTransfer, TDiagnostic> {
|
|
159
|
+
return { uri };
|
|
160
|
+
}
|
|
161
|
+
|
|
85
162
|
/**
|
|
86
|
-
* Construct a {@link TransferDocument} envelope
|
|
87
|
-
*
|
|
88
|
-
* "no diagnostics yet" code paths don't need to repeat the empty array
|
|
89
|
-
* at every call site.
|
|
163
|
+
* Construct a {@link TransferDocument} envelope with a model, its version
|
|
164
|
+
* marked as coming from a read. `diagnostics` absent means not validated.
|
|
90
165
|
*/
|
|
91
166
|
export function create<TTransfer extends TransferElement, TDiagnostic = TransferDiagnostic>(
|
|
92
167
|
uri: string,
|
|
93
168
|
version: number,
|
|
94
169
|
root: TTransfer,
|
|
95
|
-
|
|
170
|
+
hash: string,
|
|
171
|
+
diagnostics?: TDiagnostic[],
|
|
172
|
+
text?: TextState
|
|
96
173
|
): TransferDocument<TTransfer, TDiagnostic> {
|
|
97
|
-
return {
|
|
174
|
+
return {
|
|
175
|
+
uri,
|
|
176
|
+
model: { root, version: asModelVersion(version), hash, ...(diagnostics === undefined ? {} : { diagnostics }) },
|
|
177
|
+
...(text === undefined ? {} : { text })
|
|
178
|
+
};
|
|
98
179
|
}
|
|
99
180
|
}
|
package/src/util.ts
CHANGED
|
@@ -146,12 +146,6 @@ export function asMutable<T>(item: T): Mutable<T> {
|
|
|
146
146
|
return item;
|
|
147
147
|
}
|
|
148
148
|
|
|
149
|
-
/** Type-guard variant: narrows `item` to `Mutable<T> | undefined` if `guard` accepts it. */
|
|
150
|
-
export function toMutable<T>(item: unknown, guard: TypeGuard<T>): item is Mutable<T> | undefined;
|
|
151
|
-
export function toMutable<T>(item: unknown, guard?: TypeGuard<T>): item is Mutable<T> | undefined {
|
|
152
|
-
return guard ? guard(item) : true;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
149
|
/**
|
|
156
150
|
* Wrap `text` in `quoteChar`, escaping interior occurrences with `replaceChar`.
|
|
157
151
|
*
|
|
@@ -248,3 +242,36 @@ export function getAt<T = unknown>(obj: unknown, path: string[]): T | undefined
|
|
|
248
242
|
}
|
|
249
243
|
return cur as T;
|
|
250
244
|
}
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* A stable, non-cryptographic digest of `text`, equal on every host for equal
|
|
248
|
+
* text: the `TextState.hash` a data server stamps, so a client can
|
|
249
|
+
* hash text of its own to compare. An array is read as its elements joined, so
|
|
250
|
+
* a large text is hashed in parts without concatenating it. It tells whether a
|
|
251
|
+
* text changed, not who could forge one.
|
|
252
|
+
*/
|
|
253
|
+
export function textHash(text: string | readonly string[]): string {
|
|
254
|
+
const { high, low } = cyrb53(typeof text === 'string' ? [text] : text);
|
|
255
|
+
return high.toString(16).padStart(8, '0') + low.toString(16).padStart(8, '0');
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* The two 32-bit words cyrb53 ends on, each unsigned, for `parts` read as one
|
|
260
|
+
* string. It needs no `node:*` module, so every host runs it.
|
|
261
|
+
*/
|
|
262
|
+
function cyrb53(parts: readonly string[]): { readonly high: number; readonly low: number } {
|
|
263
|
+
let h1 = 0xdeadbeef;
|
|
264
|
+
let h2 = 0x41c6ce57;
|
|
265
|
+
for (const part of parts) {
|
|
266
|
+
for (let i = 0; i < part.length; i++) {
|
|
267
|
+
const code = part.charCodeAt(i);
|
|
268
|
+
h1 = Math.imul(h1 ^ code, 2654435761);
|
|
269
|
+
h2 = Math.imul(h2 ^ code, 1597334677);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
h1 = Math.imul(h1 ^ (h1 >>> 16), 2246822507);
|
|
273
|
+
h1 ^= Math.imul(h2 ^ (h2 >>> 13), 3266489909);
|
|
274
|
+
h2 = Math.imul(h2 ^ (h2 >>> 16), 2246822507);
|
|
275
|
+
h2 ^= Math.imul(h1 ^ (h1 >>> 13), 3266489909);
|
|
276
|
+
return { high: h2 >>> 0, low: h1 >>> 0 };
|
|
277
|
+
}
|
|
@@ -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 +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
|
-
}
|