@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/logger.ts
CHANGED
|
@@ -24,6 +24,7 @@ export const LEVEL_LABELS: Record<LogLevel, string> = {
|
|
|
24
24
|
/** Module-global threshold; shared by every `AbstractLogger` instance so derived child
|
|
25
25
|
* loggers pick up live updates without each having to subscribe to a configuration source. */
|
|
26
26
|
let currentLevel: LogThreshold = 'info';
|
|
27
|
+
let fileLevel: LogThreshold | undefined;
|
|
27
28
|
|
|
28
29
|
/**
|
|
29
30
|
* Cross-side public logger contract. Every consumer of the framework — browser
|
|
@@ -38,15 +39,15 @@ let currentLevel: LogThreshold = 'info';
|
|
|
38
39
|
* and every `for` / `sub` / `with` derivation preserves the implementation type.
|
|
39
40
|
*/
|
|
40
41
|
export interface Logger {
|
|
41
|
-
/**
|
|
42
|
+
/** Requested work failed; logged once, by the code that ends the failure, not by one that rethrows it. */
|
|
42
43
|
error(message?: string, ...args: unknown[]): this;
|
|
43
|
-
/**
|
|
44
|
+
/** An anomaly that was handled, or work declined by design, such as a conflict or a cap; a clean run logs none. */
|
|
44
45
|
warn(message?: string, ...args: unknown[]): this;
|
|
45
|
-
/**
|
|
46
|
+
/** A milestone the person running the server would recognise without knowing the internals. */
|
|
46
47
|
info(message?: string, ...args: unknown[]): this;
|
|
47
|
-
/**
|
|
48
|
+
/** Diagnosis; its level decides whether the line is built, never which code runs. */
|
|
48
49
|
debug(message?: string, ...args: unknown[]): this;
|
|
49
|
-
/** High-volume
|
|
50
|
+
/** High-volume diagnosis, emitted only at the `'trace'` threshold; as for `debug`, no code runs only for it. */
|
|
50
51
|
trace(message?: string, ...args: unknown[]): this;
|
|
51
52
|
/** Log a message at info-level threshold with a `Log` label (rather than `Info`). */
|
|
52
53
|
log(message?: string, ...args: unknown[]): this;
|
|
@@ -93,12 +94,32 @@ export namespace Logger {
|
|
|
93
94
|
return currentLevel;
|
|
94
95
|
}
|
|
95
96
|
/**
|
|
96
|
-
*
|
|
97
|
+
* Set the log file's own threshold, which {@link setLevel} does not move;
|
|
98
|
+
* `undefined` makes the file follow {@link getLevel}. A file sink compares
|
|
99
|
+
* against `getFileLevel() ?? getLevel()`, every other sink against
|
|
100
|
+
* {@link getLevel}.
|
|
101
|
+
*
|
|
102
|
+
* Set it through the file sink's own configuration, which clears it with
|
|
103
|
+
* the file: set here with no file configured, it widens
|
|
104
|
+
* {@link isLevelEnabled} for lines nothing writes.
|
|
105
|
+
*/
|
|
106
|
+
export function setFileLevel(level: LogThreshold | undefined): void {
|
|
107
|
+
fileLevel = level;
|
|
108
|
+
}
|
|
109
|
+
/** Read the log file's own threshold, `undefined` while it follows {@link getLevel}. */
|
|
110
|
+
export function getFileLevel(): LogThreshold | undefined {
|
|
111
|
+
return fileLevel;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Whether any sink takes a message at `level`: the more verbose of
|
|
115
|
+
* {@link getLevel} and {@link getFileLevel} decides. A sink that admits less
|
|
116
|
+
* re-checks its own threshold before writing.
|
|
117
|
+
*
|
|
97
118
|
* Use to guard expensive log-line construction:
|
|
98
119
|
* `if (Logger.isLevelEnabled('trace')) logger.trace(buildPayload())`.
|
|
99
120
|
*/
|
|
100
121
|
export function isLevelEnabled(level: LogLevel): boolean {
|
|
101
|
-
return LEVEL_ORDER[level] <= LEVEL_ORDER[currentLevel];
|
|
122
|
+
return LEVEL_ORDER[level] <= Math.max(LEVEL_ORDER[currentLevel], fileLevel ? LEVEL_ORDER[fileLevel] : 0);
|
|
102
123
|
}
|
|
103
124
|
/**
|
|
104
125
|
* Whether a message at `threshold` would be emitted: `false` for `'off'`,
|
|
@@ -134,8 +155,23 @@ export function parseLogLevel(value: unknown): LogThreshold | undefined {
|
|
|
134
155
|
* instead of duplicating the literal string.
|
|
135
156
|
*/
|
|
136
157
|
export const DEFAULT_LOG_LEVEL_ENV = 'HYDRANIUM_LOG_LEVEL';
|
|
137
|
-
/**
|
|
158
|
+
/**
|
|
159
|
+
* Env var the server reads its log file-tee target from. The path may hold
|
|
160
|
+
* `{workspace}`, filled in once the server knows its workspace, and `{pid}`.
|
|
161
|
+
* See {@link DEFAULT_LOG_LEVEL_ENV}.
|
|
162
|
+
*/
|
|
138
163
|
export const DEFAULT_LOG_FILE_ENV = 'HYDRANIUM_LOG_FILE';
|
|
164
|
+
/**
|
|
165
|
+
* Env var the server reads the file tee's own threshold from, which the LSP
|
|
166
|
+
* log-level setting does not change. See {@link Logger.setFileLevel}.
|
|
167
|
+
*/
|
|
168
|
+
export const DEFAULT_LOG_FILE_LEVEL_ENV = 'HYDRANIUM_LOG_FILE_LEVEL';
|
|
169
|
+
/**
|
|
170
|
+
* Env var naming the file a Node server writes its CPU profile to when it
|
|
171
|
+
* ends. Takes `{workspace}` and `{pid}` as {@link DEFAULT_LOG_FILE_ENV} does;
|
|
172
|
+
* the write replaces the file, so `{pid}` keeps one per server.
|
|
173
|
+
*/
|
|
174
|
+
export const DEFAULT_CPU_PROFILE_FILE_ENV = 'HYDRANIUM_CPU_PROFILE_FILE';
|
|
139
175
|
|
|
140
176
|
/**
|
|
141
177
|
* Human-readable formatting helpers used in log lines and diagnostic output.
|
package/src/messages/index.ts
CHANGED
|
@@ -25,8 +25,10 @@
|
|
|
25
25
|
|
|
26
26
|
export * from './primitives';
|
|
27
27
|
|
|
28
|
-
export {
|
|
29
|
-
export {
|
|
28
|
+
export { DOCUMENT_NOT_OPEN, DUPLICATE_CLIENT_ID, SESSION_CLOSED, STALE_BASE_VERSION_SAVE, STALE_BASE_VERSION_UPDATE } from '../errors';
|
|
29
|
+
export { DATA_CONNECTION_SESSION_RESTORE_FAILED, DATA_CONNECTION_WATCH_RESTORE_FAILED } from '../client/data-connection';
|
|
30
|
+
export { DATA_SERVER_CONNECT_FAILED, DATA_SERVER_NOT_READY } from '../client/rpc-connection';
|
|
31
|
+
export { DATA_SESSION_ANSWER_WITHOUT_MODEL, DATA_SESSION_RESTORE_FAILED, DATA_SESSION_UNSAVED_LOST } from '../client/data-session';
|
|
30
32
|
export {
|
|
31
33
|
RELAY_REPLAY_FAILED,
|
|
32
34
|
RELAY_TRANSPORT_OPEN_FAILED,
|
|
@@ -10,12 +10,18 @@
|
|
|
10
10
|
import { ResponseError } from 'vscode-jsonrpc';
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
|
-
* The framework externalizes user-facing strings and
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
13
|
+
* The framework externalizes user-facing strings and SELECTS no locale: it
|
|
14
|
+
* relays the one its client declared and renders with whatever templates the
|
|
15
|
+
* adopter installed, defaulting to its English. Every such string carries a
|
|
16
|
+
* stable code beside that English, and exactly one side renders it — the side
|
|
17
|
+
* that knows the reading user's language.
|
|
18
|
+
*
|
|
19
|
+
* Which side that is depends on the message, not on the package. A server
|
|
20
|
+
* message is rendered by the server, at the one seam every carrier passes
|
|
21
|
+
* through, in the locale it was handed at init. A message the client tier raises
|
|
22
|
+
* is rendered there, because those fire when the server is unreachable. Nothing
|
|
23
|
+
* is rendered twice: two renders of one sentence are two authorities over it,
|
|
24
|
+
* and they diverge on the first reword.
|
|
19
25
|
*
|
|
20
26
|
* Codes are `hydranium/<unscoped-package>/<name>`. The package segment locates
|
|
21
27
|
* the declaration, so a message is declared in the package that raises it and a
|
|
@@ -156,11 +162,67 @@ export function messageError<S extends string>(
|
|
|
156
162
|
}
|
|
157
163
|
|
|
158
164
|
/**
|
|
159
|
-
*
|
|
160
|
-
*
|
|
161
|
-
*
|
|
165
|
+
* The reading user's language, as the tag a client declared.
|
|
166
|
+
*
|
|
167
|
+
* Neither validated nor normalised anywhere: rejecting an unfamiliar tag would
|
|
168
|
+
* be selecting a locale, which the framework does not do.
|
|
169
|
+
*
|
|
170
|
+
* NOT a Langium language id, which names a grammar. The two are strings of the
|
|
171
|
+
* same shape reachable from the same services, so one used where the other
|
|
172
|
+
* belongs misses every lookup rather than failing.
|
|
173
|
+
*/
|
|
174
|
+
export type Locale = string;
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* A host's templates for one locale, keyed by the whole message code.
|
|
178
|
+
*
|
|
179
|
+
* **Flat, not nested.** A code is one key here, `/` separators included; a host
|
|
180
|
+
* whose own catalogue format nests — Theia's does — flattens on the way in. A
|
|
181
|
+
* map that nests instead misses every lookup while type-checking, because the
|
|
182
|
+
* value this is indexed by is `ResolvedMessage.code`.
|
|
183
|
+
*
|
|
184
|
+
* **Partial by nature rather than by convention.** A code with no entry renders
|
|
185
|
+
* its English default, so a catalogue covering none of a package's codes is a
|
|
186
|
+
* valid catalogue and not a broken one — which is what lets an adopter translate
|
|
187
|
+
* as much or as little as they like.
|
|
188
|
+
*
|
|
189
|
+
* Deliberately NOT narrowed to the codes that exist, and a `Code extends string`
|
|
190
|
+
* parameter would not buy what it appears to: a catalogue is loaded as JSON, so
|
|
191
|
+
* it reaches a checked position as a variable rather than as an object literal,
|
|
192
|
+
* and excess-property checking — the only thing that would reject a mistyped
|
|
193
|
+
* key — does not run there. The gain is a compile error for a catalogue with no
|
|
194
|
+
* correct key at all; the cost is a code union to maintain by hand, since a
|
|
195
|
+
* declaration does not carry its code as a literal type.
|
|
196
|
+
*/
|
|
197
|
+
export type MessageCatalogue = Readonly<Record<string, string>>;
|
|
198
|
+
|
|
199
|
+
export namespace MessageCatalogue {
|
|
200
|
+
/**
|
|
201
|
+
* One catalogue from several, for a renderer whose override supplies entries
|
|
202
|
+
* over the ones it inherits.
|
|
203
|
+
*
|
|
204
|
+
* **Later wins**, so a caller passes the inherited answer before its own.
|
|
205
|
+
*
|
|
206
|
+
* **No source at all answers `undefined`, not `{}`.** A renderer holds that
|
|
207
|
+
* answer as the locale having no catalogue and renders straight through; an
|
|
208
|
+
* empty object is a catalogue that misses every lookup, so returning one
|
|
209
|
+
* turns the opt-out into a per-message search that yields the same English.
|
|
210
|
+
*/
|
|
211
|
+
export function merge(...catalogues: ReadonlyArray<MessageCatalogue | undefined>): MessageCatalogue | undefined {
|
|
212
|
+
const present = catalogues.filter((catalogue): catalogue is MessageCatalogue => catalogue !== undefined);
|
|
213
|
+
if (present.length <= 1) {
|
|
214
|
+
return present[0];
|
|
215
|
+
}
|
|
216
|
+
return Object.assign({}, ...present) as MessageCatalogue;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* Render on the side that knows the reading user's locale. Omitting
|
|
222
|
+
* `translations` is how an adopter without i18n opts out, and yields the
|
|
223
|
+
* English.
|
|
162
224
|
*/
|
|
163
|
-
export function renderFrameworkMessage(message: ResolvedMessage, translations?:
|
|
225
|
+
export function renderFrameworkMessage(message: ResolvedMessage, translations?: MessageCatalogue): string {
|
|
164
226
|
const template = translations?.[message.code];
|
|
165
227
|
return template ? interpolate(template, message.params) : message.text;
|
|
166
228
|
}
|
|
@@ -174,11 +236,41 @@ export function resolvedFromResponseError(error: ResponseError<unknown>): Resolv
|
|
|
174
236
|
* to pass as a parameter for the same reason a number is: it is not itself
|
|
175
237
|
* translatable text, so it needs no code of its own. A PROSE fragment is not,
|
|
176
238
|
* and must become one code per value instead.
|
|
239
|
+
*
|
|
240
|
+
* For a reader of the client; the log takes {@link describeErrorWithStack}.
|
|
177
241
|
*/
|
|
178
242
|
export function describeError(error: unknown): string {
|
|
179
243
|
return error instanceof Error ? error.message : String(error);
|
|
180
244
|
}
|
|
181
245
|
|
|
246
|
+
/**
|
|
247
|
+
* An error for the log: its stack where it has one, which names where it was
|
|
248
|
+
* thrown, and its causes, which name what failed when an error wraps another.
|
|
249
|
+
* Never for the client, whose reader cannot act on a stack.
|
|
250
|
+
*/
|
|
251
|
+
export function describeErrorWithStack(error: unknown): string {
|
|
252
|
+
// A cause chain may loop back on itself.
|
|
253
|
+
return describeChain(error, new Set());
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
function describeChain(error: unknown, seen: Set<unknown>): string {
|
|
257
|
+
const lines: string[] = [];
|
|
258
|
+
let current: unknown = error;
|
|
259
|
+
let prefix = '';
|
|
260
|
+
do {
|
|
261
|
+
seen.add(current);
|
|
262
|
+
lines.push(prefix + (current instanceof Error ? (current.stack ?? current.message) : String(current)));
|
|
263
|
+
// Node fails a connect to several addresses with one, whose own message is empty.
|
|
264
|
+
if (current instanceof AggregateError) {
|
|
265
|
+
const errors: unknown[] = current.errors;
|
|
266
|
+
lines.push(...errors.filter(inner => !seen.has(inner)).map(inner => `Including: ${describeChain(inner, seen)}`));
|
|
267
|
+
}
|
|
268
|
+
current = current instanceof Error ? current.cause : undefined;
|
|
269
|
+
prefix = 'Caused by: ';
|
|
270
|
+
} while (current !== undefined && current !== null && !seen.has(current));
|
|
271
|
+
return lines.join('\n');
|
|
272
|
+
}
|
|
273
|
+
|
|
182
274
|
/**
|
|
183
275
|
* Recognises a declaration among a barrel's exports. The `format` check is what
|
|
184
276
|
* discriminates: a `code` + `text` pair alone admits any object that happens to
|
package/src/model-server.ts
CHANGED
|
@@ -14,17 +14,19 @@
|
|
|
14
14
|
* over `TRoot`.
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
-
import type { TransferClientArgs } from './model-service/args';
|
|
18
17
|
import type { ReferenceCandidate } from './model-service/reference-candidate';
|
|
19
18
|
|
|
20
19
|
// ---------------------------------------------------------------------------
|
|
21
20
|
// Client / server arguments
|
|
22
21
|
// ---------------------------------------------------------------------------
|
|
23
22
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
23
|
+
/** Identifies a client-document binding. */
|
|
24
|
+
export interface TransferClientArgs {
|
|
25
|
+
/** Document URI. */
|
|
26
|
+
uri: string;
|
|
27
|
+
/** Stable identifier for the client invoking the operation. */
|
|
28
|
+
clientId: string;
|
|
29
|
+
}
|
|
28
30
|
|
|
29
31
|
/** Open a document on behalf of a client. */
|
|
30
32
|
export interface OpenModelArgs extends TransferClientArgs {
|
|
@@ -47,14 +49,22 @@ export interface OpenModelArgs extends TransferClientArgs {
|
|
|
47
49
|
* means read from the filesystem, which is the normal case.
|
|
48
50
|
*
|
|
49
51
|
* Honoured only on the first open of a URI: opening an already-open document
|
|
50
|
-
*
|
|
51
|
-
* through the update path instead.
|
|
52
|
+
* attaches the caller to the existing shared entry and does not replace its
|
|
53
|
+
* content with this seed. Write through the update path instead. The open
|
|
54
|
+
* response reads the current shared content after registration; a textual
|
|
55
|
+
* `didOpen` attach may separately refresh the build.
|
|
52
56
|
*/
|
|
53
57
|
text?: string;
|
|
58
|
+
/**
|
|
59
|
+
* Kept on the server for this client's open until it closes, for the
|
|
60
|
+
* server's own open path to read. Only a client session's open keeps them,
|
|
61
|
+
* and a repeat open keeps the first open's.
|
|
62
|
+
*/
|
|
63
|
+
options?: object;
|
|
54
64
|
}
|
|
55
65
|
|
|
56
66
|
/** Close a previously-opened document for the client. */
|
|
57
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
|
|
67
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-object-type -- close names its own args; it adds no field to the base
|
|
58
68
|
export interface CloseModelArgs extends TransferClientArgs {}
|
|
59
69
|
|
|
60
70
|
// ---------------------------------------------------------------------------
|
|
@@ -63,9 +73,25 @@ export interface CloseModelArgs extends TransferClientArgs {}
|
|
|
63
73
|
|
|
64
74
|
export interface TransferUpdatedEvent<TDocument> {
|
|
65
75
|
document: TDocument;
|
|
76
|
+
/**
|
|
77
|
+
* The client whose write this event echoes: the author of the version on a
|
|
78
|
+
* `'changed'`, and the unknown-client id on a `'rebuilt'`, which echoes no
|
|
79
|
+
* write. A recipient compares it against its own id to recognise its echo.
|
|
80
|
+
*/
|
|
66
81
|
sourceClientId: string;
|
|
67
|
-
/** See `
|
|
68
|
-
reason: 'changed' | '
|
|
82
|
+
/** See `TransferDocumentUpdateReason` in `./data/events` for the canonical reason set + semantics. */
|
|
83
|
+
reason: 'changed' | 'rebuilt' | 'saved';
|
|
84
|
+
/**
|
|
85
|
+
* The client whose write caused the build that produced this event, or the
|
|
86
|
+
* unknown-client id when no single client's did. On a `'changed'` it is the
|
|
87
|
+
* version's author. A `'rebuilt'` names the writer of another document, so
|
|
88
|
+
* it is a cause, never an echo: its diagnostics and references are new to
|
|
89
|
+
* that writer too.
|
|
90
|
+
*
|
|
91
|
+
* In-process only: the data head does not send it, and an event built
|
|
92
|
+
* elsewhere may leave it out, which a reader takes as "not known".
|
|
93
|
+
*/
|
|
94
|
+
causedBy?: string;
|
|
69
95
|
}
|
|
70
96
|
|
|
71
97
|
export interface TransferSavedEvent<TDocument> {
|
|
@@ -147,10 +173,10 @@ export function isElementSource(object: unknown): object is ElementSource {
|
|
|
147
173
|
/** An element of a document that does not yet exist on disk — used during element creation flows. */
|
|
148
174
|
export interface SyntheticSource {
|
|
149
175
|
/**
|
|
150
|
-
* The document the element would belong to.
|
|
151
|
-
*
|
|
152
|
-
*
|
|
153
|
-
*
|
|
176
|
+
* The document the element would belong to. It need not be loaded, or
|
|
177
|
+
* exist — an unloaded URI materialises a transient empty document, so a
|
|
178
|
+
* folder is a valid anchor. A URI that IS loaded contributes that
|
|
179
|
+
* document's parse root as the container, putting its contents in scope.
|
|
154
180
|
*/
|
|
155
181
|
uri: string;
|
|
156
182
|
/**
|
|
@@ -159,6 +185,16 @@ export interface SyntheticSource {
|
|
|
159
185
|
* it is what scoping filters candidates against.
|
|
160
186
|
*/
|
|
161
187
|
type: string;
|
|
188
|
+
/**
|
|
189
|
+
* The grammar the element will belong to, as a language id.
|
|
190
|
+
*
|
|
191
|
+
* Optional because `uri` and `type` each answer on their own when
|
|
192
|
+
* unambiguous. Set it when neither is: a URI naming no file carries no
|
|
193
|
+
* extension to route on, and a `type` two grammars can produce identifies
|
|
194
|
+
* neither. Unset, such a source reaches the server's own policy, which
|
|
195
|
+
* answers the same way for every caller.
|
|
196
|
+
*/
|
|
197
|
+
language?: string;
|
|
162
198
|
}
|
|
163
199
|
|
|
164
200
|
export function isSyntheticSource(object: unknown): object is SyntheticSource {
|
|
@@ -183,8 +219,10 @@ export namespace ReferenceSource {
|
|
|
183
219
|
export function element(name: string, type?: string): ElementSource {
|
|
184
220
|
return { name, type };
|
|
185
221
|
}
|
|
186
|
-
export function synthetic(uri: string, type: string): SyntheticSource {
|
|
187
|
-
|
|
222
|
+
export function synthetic(uri: string, type: string, language?: string): SyntheticSource {
|
|
223
|
+
// The key is omitted rather than set to `undefined`, so a source built
|
|
224
|
+
// without a language stays deep-equal to the two-argument form.
|
|
225
|
+
return language === undefined ? { uri, type } : { uri, type, language };
|
|
188
226
|
}
|
|
189
227
|
}
|
|
190
228
|
|
|
@@ -457,9 +495,10 @@ export interface FindNextNameArgs {
|
|
|
457
495
|
*/
|
|
458
496
|
uri: string;
|
|
459
497
|
/**
|
|
460
|
-
* The AST `$type` of the element being named. Collisions are
|
|
461
|
-
* among elements of that
|
|
462
|
-
*
|
|
498
|
+
* The AST `$type` of the element being named. Collisions are looked for
|
|
499
|
+
* among elements of that type and of any subtype of it, so a supertype
|
|
500
|
+
* names a uniqueness scope its concrete types share; the returned name may
|
|
501
|
+
* still be taken by an element outside that hierarchy.
|
|
463
502
|
*/
|
|
464
503
|
type: string;
|
|
465
504
|
/**
|
|
@@ -476,4 +515,10 @@ export interface FindNextNameArgs {
|
|
|
476
515
|
* See {@link NameTier} for what each tier covers.
|
|
477
516
|
*/
|
|
478
517
|
tier?: NameTier;
|
|
518
|
+
/**
|
|
519
|
+
* The grammar to name under, routed as {@link SyntheticSource.language} —
|
|
520
|
+
* this call builds one. A caller that sets it there must set it here, or
|
|
521
|
+
* candidates and the name it proposes come from different grammars.
|
|
522
|
+
*/
|
|
523
|
+
language?: string;
|
|
479
524
|
}
|
|
@@ -0,0 +1,75 @@
|
|
|
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
|
+
declare const snapshotMarker: unique symbol;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* The version of the text a model was parsed from: a snapshot of the store's
|
|
14
|
+
* {@link TextVersion}, not a counter of its own. A document envelope carries
|
|
15
|
+
* it, and it cannot move once the envelope exists. A create's answer carries
|
|
16
|
+
* a second snapshot of the same kind, the version the create's text took,
|
|
17
|
+
* which its creator holds because it sent the text.
|
|
18
|
+
*
|
|
19
|
+
* A plain number at runtime, usable anywhere a number is, and it travels the
|
|
20
|
+
* wire as one. The marker exists only so the compiler can tell it apart from a
|
|
21
|
+
* version read off a LIVE document, which is the same number type and is the
|
|
22
|
+
* defect the conflict gate exists to prevent: read at write time it is whatever
|
|
23
|
+
* the server is at now, which is the number the gate is about to compare it
|
|
24
|
+
* against, so the gate passes unconditionally and a concurrent edit is
|
|
25
|
+
* overwritten with nothing logged.
|
|
26
|
+
*/
|
|
27
|
+
export type ModelVersion = number & { readonly [snapshotMarker]: true };
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* The store's version of a document's text, which moves with every change of it.
|
|
31
|
+
* Unbranded, so a write refuses it as `baseVersion`: it can name text newer than
|
|
32
|
+
* the caller's model, and a write based on it would pass the gate with older content.
|
|
33
|
+
*/
|
|
34
|
+
export type TextVersion = number;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* The version a write was authored against, from a snapshot read, or `'any'`: a
|
|
38
|
+
* precondition that always holds, so the write overwrites whatever the server has.
|
|
39
|
+
* `'any'` is a lie for a write authored against a document a read handed over.
|
|
40
|
+
*/
|
|
41
|
+
export type BaseVersion = ModelVersion | 'any';
|
|
42
|
+
|
|
43
|
+
/** Whether `baseVersion` names a version, and so arms the gate. */
|
|
44
|
+
export function isModelVersion(baseVersion: BaseVersion): baseVersion is ModelVersion {
|
|
45
|
+
return typeof baseVersion === 'number';
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Mark a version as having come from a snapshot read.
|
|
50
|
+
*
|
|
51
|
+
* **For the envelope constructors, not for callers.** Every door that builds a
|
|
52
|
+
* document envelope applies it on the way in, the create's answer included
|
|
53
|
+
* for the version its text took, so anything a read returns already carries
|
|
54
|
+
* it and a writer never needs this. A caller reaching for it is
|
|
55
|
+
* asserting a provenance the compiler was about to deny — the read-late defect
|
|
56
|
+
* written out where a reviewer can see it.
|
|
57
|
+
*/
|
|
58
|
+
export function asModelVersion(version: number): ModelVersion {
|
|
59
|
+
return version as ModelVersion;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* The model version of a root no document factory path built, so nothing
|
|
64
|
+
* records the text it came from. No write matches it, so a write based on it
|
|
65
|
+
* conflicts.
|
|
66
|
+
*/
|
|
67
|
+
export const UNRECORDED_VERSION: ModelVersion = asModelVersion(-2);
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* The model version of a root parsed from text the store holds under no
|
|
71
|
+
* version: the file, read while the store held the document open with other
|
|
72
|
+
* text. Below every text version, so the model reads as behind and a write
|
|
73
|
+
* based on it conflicts.
|
|
74
|
+
*/
|
|
75
|
+
export const STALE_VERSION: ModelVersion = asModelVersion(-1);
|
|
@@ -7,10 +7,9 @@
|
|
|
7
7
|
* SPDX-License-Identifier: MIT
|
|
8
8
|
********************************************************************************/
|
|
9
9
|
|
|
10
|
-
//
|
|
11
|
-
//
|
|
12
|
-
//
|
|
13
|
-
// protocol can structurally agree on the lifecycle shape.
|
|
10
|
+
// Generic payload types the data protocol shares with core: the base
|
|
11
|
+
// version, which the server's model service checks writes against, and the
|
|
12
|
+
// reference candidates, which core's scope and completion code produce.
|
|
14
13
|
|
|
15
|
-
export * from './
|
|
14
|
+
export * from './base-version';
|
|
16
15
|
export * from './reference-candidate';
|
|
@@ -50,9 +50,11 @@ export interface ReferenceCandidate {
|
|
|
50
50
|
* node's subtree, NOT the whole document root — callers that want the full
|
|
51
51
|
* document fetch it via `getModelDocument(uri)`.
|
|
52
52
|
*
|
|
53
|
-
*
|
|
53
|
+
* `TElement` is the type of the target node, not of a document root. A server
|
|
54
|
+
* answers with the structural base, since a reference can name any node; a
|
|
55
|
+
* caller that knows what the reference targets may narrow it.
|
|
54
56
|
*/
|
|
55
|
-
export interface ReferenceTarget<
|
|
57
|
+
export interface ReferenceTarget<TElement extends TransferElement = TransferElement> extends ReferenceCandidate {
|
|
56
58
|
/** The resolved target node, encoded as a transfer subtree. */
|
|
57
|
-
element:
|
|
59
|
+
element: TElement;
|
|
58
60
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
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
|
+
// Subpath barrel for `@hydranium/protocol/node` — the diagnostics helpers that
|
|
11
|
+
// need a Node runtime, kept out of the root barrel so the root stays
|
|
12
|
+
// bundleable for a browser.
|
|
13
|
+
|
|
14
|
+
export * from './process-memory';
|