@hydranium/protocol 1.0.0-next.10
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/LICENSE +21 -0
- package/README.md +81 -0
- package/lib/abstract-logger.d.ts +66 -0
- package/lib/abstract-logger.d.ts.map +1 -0
- package/lib/abstract-logger.js +110 -0
- package/lib/abstract-logger.js.map +1 -0
- package/lib/browser-runtime.d.ts +124 -0
- package/lib/browser-runtime.d.ts.map +1 -0
- package/lib/browser-runtime.js +11 -0
- package/lib/browser-runtime.js.map +1 -0
- package/lib/client/data-events.d.ts +49 -0
- package/lib/client/data-events.d.ts.map +1 -0
- package/lib/client/data-events.js +60 -0
- package/lib/client/data-events.js.map +1 -0
- package/lib/client/data-port.d.ts +95 -0
- package/lib/client/data-port.d.ts.map +1 -0
- package/lib/client/data-port.js +11 -0
- package/lib/client/data-port.js.map +1 -0
- package/lib/client/data-session.d.ts +129 -0
- package/lib/client/data-session.d.ts.map +1 -0
- package/lib/client/data-session.js +179 -0
- package/lib/client/data-session.js.map +1 -0
- package/lib/client/index.d.ts +39 -0
- package/lib/client/index.d.ts.map +1 -0
- package/lib/client/index.js +55 -0
- package/lib/client/index.js.map +1 -0
- package/lib/client/message-relay.d.ts +111 -0
- package/lib/client/message-relay.d.ts.map +1 -0
- package/lib/client/message-relay.js +139 -0
- package/lib/client/message-relay.js.map +1 -0
- package/lib/client/post-message-transport.d.ts +77 -0
- package/lib/client/post-message-transport.d.ts.map +1 -0
- package/lib/client/post-message-transport.js +95 -0
- package/lib/client/post-message-transport.js.map +1 -0
- package/lib/clock.d.ts +111 -0
- package/lib/clock.d.ts.map +1 -0
- package/lib/clock.js +74 -0
- package/lib/clock.js.map +1 -0
- package/lib/data/data-protocol-methods.d.ts +39 -0
- package/lib/data/data-protocol-methods.d.ts.map +1 -0
- package/lib/data/data-protocol-methods.js +61 -0
- package/lib/data/data-protocol-methods.js.map +1 -0
- package/lib/data/data-server-protocol.d.ts +264 -0
- package/lib/data/data-server-protocol.d.ts.map +1 -0
- package/lib/data/data-server-protocol.js +11 -0
- package/lib/data/data-server-protocol.js.map +1 -0
- package/lib/data/diagnostics.d.ts +97 -0
- package/lib/data/diagnostics.d.ts.map +1 -0
- package/lib/data/diagnostics.js +25 -0
- package/lib/data/diagnostics.js.map +1 -0
- package/lib/data/events.d.ts +107 -0
- package/lib/data/events.d.ts.map +1 -0
- package/lib/data/events.js +11 -0
- package/lib/data/events.js.map +1 -0
- package/lib/data/index.d.ts +15 -0
- package/lib/data/index.d.ts.map +1 -0
- package/lib/data/index.js +38 -0
- package/lib/data/index.js.map +1 -0
- package/lib/data/methods.d.ts +57 -0
- package/lib/data/methods.d.ts.map +1 -0
- package/lib/data/methods.js +60 -0
- package/lib/data/methods.js.map +1 -0
- package/lib/data/requests.d.ts +65 -0
- package/lib/data/requests.d.ts.map +1 -0
- package/lib/data/requests.js +11 -0
- package/lib/data/requests.js.map +1 -0
- package/lib/debouncer.d.ts +75 -0
- package/lib/debouncer.d.ts.map +1 -0
- package/lib/debouncer.js +91 -0
- package/lib/debouncer.js.map +1 -0
- package/lib/errors.d.ts +84 -0
- package/lib/errors.d.ts.map +1 -0
- package/lib/errors.js +113 -0
- package/lib/errors.js.map +1 -0
- package/lib/host-diagnostics.d.ts +58 -0
- package/lib/host-diagnostics.d.ts.map +1 -0
- package/lib/host-diagnostics.js +18 -0
- package/lib/host-diagnostics.js.map +1 -0
- package/lib/index.d.ts +34 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +56 -0
- package/lib/index.js.map +1 -0
- package/lib/latency-collector.d.ts +126 -0
- package/lib/latency-collector.d.ts.map +1 -0
- package/lib/latency-collector.js +137 -0
- package/lib/latency-collector.js.map +1 -0
- package/lib/logger.d.ts +119 -0
- package/lib/logger.d.ts.map +1 -0
- package/lib/logger.js +126 -0
- package/lib/logger.js.map +1 -0
- package/lib/model-server.d.ts +352 -0
- package/lib/model-server.d.ts.map +1 -0
- package/lib/model-server.js +160 -0
- package/lib/model-server.js.map +1 -0
- package/lib/model-service/args.d.ts +64 -0
- package/lib/model-service/args.d.ts.map +1 -0
- package/lib/model-service/args.js +11 -0
- package/lib/model-service/args.js.map +1 -0
- package/lib/model-service/index.d.ts +11 -0
- package/lib/model-service/index.d.ts.map +1 -0
- package/lib/model-service/index.js +31 -0
- package/lib/model-service/index.js.map +1 -0
- package/lib/model-service/reference-candidate.d.ts +56 -0
- package/lib/model-service/reference-candidate.d.ts.map +1 -0
- package/lib/model-service/reference-candidate.js +11 -0
- package/lib/model-service/reference-candidate.js.map +1 -0
- package/lib/noop-logger.d.ts +25 -0
- package/lib/noop-logger.d.ts.map +1 -0
- package/lib/noop-logger.js +36 -0
- package/lib/noop-logger.js.map +1 -0
- package/lib/observable-value.d.ts +72 -0
- package/lib/observable-value.d.ts.map +1 -0
- package/lib/observable-value.js +52 -0
- package/lib/observable-value.js.map +1 -0
- package/lib/patch-merge.d.ts +123 -0
- package/lib/patch-merge.d.ts.map +1 -0
- package/lib/patch-merge.js +104 -0
- package/lib/patch-merge.js.map +1 -0
- package/lib/profile-session.d.ts +87 -0
- package/lib/profile-session.d.ts.map +1 -0
- package/lib/profile-session.js +98 -0
- package/lib/profile-session.js.map +1 -0
- package/lib/profiling.d.ts +83 -0
- package/lib/profiling.d.ts.map +1 -0
- package/lib/profiling.js +20 -0
- package/lib/profiling.js.map +1 -0
- package/lib/project.d.ts +121 -0
- package/lib/project.d.ts.map +1 -0
- package/lib/project.js +34 -0
- package/lib/project.js.map +1 -0
- package/lib/rpc/bind-rpc-methods.d.ts +100 -0
- package/lib/rpc/bind-rpc-methods.d.ts.map +1 -0
- package/lib/rpc/bind-rpc-methods.js +110 -0
- package/lib/rpc/bind-rpc-methods.js.map +1 -0
- package/lib/rpc/create-rpc-proxy.d.ts +188 -0
- package/lib/rpc/create-rpc-proxy.d.ts.map +1 -0
- package/lib/rpc/create-rpc-proxy.js +158 -0
- package/lib/rpc/create-rpc-proxy.js.map +1 -0
- package/lib/rpc/index.d.ts +12 -0
- package/lib/rpc/index.d.ts.map +1 -0
- package/lib/rpc/index.js +31 -0
- package/lib/rpc/index.js.map +1 -0
- package/lib/rpc/wire-prefix.d.ts +37 -0
- package/lib/rpc/wire-prefix.d.ts.map +1 -0
- package/lib/rpc/wire-prefix.js +49 -0
- package/lib/rpc/wire-prefix.js.map +1 -0
- package/lib/testing/data-doubles.d.ts +121 -0
- package/lib/testing/data-doubles.d.ts.map +1 -0
- package/lib/testing/data-doubles.js +102 -0
- package/lib/testing/data-doubles.js.map +1 -0
- package/lib/testing/fake-clock.d.ts +35 -0
- package/lib/testing/fake-clock.d.ts.map +1 -0
- package/lib/testing/fake-clock.js +86 -0
- package/lib/testing/fake-clock.js.map +1 -0
- package/lib/testing/harness.d.ts +24 -0
- package/lib/testing/harness.d.ts.map +1 -0
- package/lib/testing/harness.js +11 -0
- package/lib/testing/harness.js.map +1 -0
- package/lib/testing/index.d.ts +13 -0
- package/lib/testing/index.d.ts.map +1 -0
- package/lib/testing/index.js +41 -0
- package/lib/testing/index.js.map +1 -0
- package/lib/testing/node/duplex-connection.d.ts +25 -0
- package/lib/testing/node/duplex-connection.d.ts.map +1 -0
- package/lib/testing/node/duplex-connection.js +34 -0
- package/lib/testing/node/duplex-connection.js.map +1 -0
- package/lib/testing/node/duplex-stream.d.ts +32 -0
- package/lib/testing/node/duplex-stream.d.ts.map +1 -0
- package/lib/testing/node/duplex-stream.js +35 -0
- package/lib/testing/node/duplex-stream.js.map +1 -0
- package/lib/testing/node/index.d.ts +11 -0
- package/lib/testing/node/index.d.ts.map +1 -0
- package/lib/testing/node/index.js +37 -0
- package/lib/testing/node/index.js.map +1 -0
- package/lib/testing/wait-for.d.ts +69 -0
- package/lib/testing/wait-for.d.ts.map +1 -0
- package/lib/testing/wait-for.js +67 -0
- package/lib/testing/wait-for.js.map +1 -0
- package/lib/tracer.d.ts +115 -0
- package/lib/tracer.d.ts.map +1 -0
- package/lib/tracer.js +205 -0
- package/lib/tracer.js.map +1 -0
- package/lib/transfer-diagnostic.d.ts +73 -0
- package/lib/transfer-diagnostic.d.ts.map +1 -0
- package/lib/transfer-diagnostic.js +45 -0
- package/lib/transfer-diagnostic.js.map +1 -0
- package/lib/transfer-document.d.ts +73 -0
- package/lib/transfer-document.d.ts.map +1 -0
- package/lib/transfer-document.js +46 -0
- package/lib/transfer-document.js.map +1 -0
- package/lib/transfer-element.d.ts +39 -0
- package/lib/transfer-element.d.ts.map +1 -0
- package/lib/transfer-element.js +11 -0
- package/lib/transfer-element.js.map +1 -0
- package/lib/uri.d.ts +62 -0
- package/lib/uri.d.ts.map +1 -0
- package/lib/uri.js +28 -0
- package/lib/uri.js.map +1 -0
- package/lib/util.d.ts +147 -0
- package/lib/util.d.ts.map +1 -0
- package/lib/util.js +211 -0
- package/lib/util.js.map +1 -0
- package/package.json +100 -0
- package/src/abstract-logger.ts +120 -0
- package/src/browser-runtime.ts +135 -0
- package/src/client/data-events.ts +71 -0
- package/src/client/data-port.ts +99 -0
- package/src/client/data-session.ts +209 -0
- package/src/client/index.ts +40 -0
- package/src/client/message-relay.ts +216 -0
- package/src/client/post-message-transport.ts +167 -0
- package/src/clock.ts +173 -0
- package/src/data/data-protocol-methods.ts +79 -0
- package/src/data/data-server-protocol.ts +296 -0
- package/src/data/diagnostics.ts +116 -0
- package/src/data/events.ts +127 -0
- package/src/data/index.ts +23 -0
- package/src/data/methods.ts +59 -0
- package/src/data/requests.ts +70 -0
- package/src/debouncer.ts +118 -0
- package/src/errors.ts +127 -0
- package/src/host-diagnostics.ts +63 -0
- package/src/index.ts +41 -0
- package/src/latency-collector.ts +231 -0
- package/src/logger.ts +172 -0
- package/src/model-server.ts +479 -0
- package/src/model-service/args.ts +67 -0
- package/src/model-service/index.ts +16 -0
- package/src/model-service/reference-candidate.ts +58 -0
- package/src/noop-logger.ts +36 -0
- package/src/observable-value.ts +92 -0
- package/src/patch-merge.ts +165 -0
- package/src/profile-session.ts +164 -0
- package/src/profiling.ts +113 -0
- package/src/project.ts +125 -0
- package/src/rpc/README.md +163 -0
- package/src/rpc/bind-rpc-methods.ts +180 -0
- package/src/rpc/create-rpc-proxy.ts +292 -0
- package/src/rpc/index.ts +16 -0
- package/src/rpc/wire-prefix.ts +48 -0
- package/src/testing/data-doubles.ts +178 -0
- package/src/testing/fake-clock.ts +106 -0
- package/src/testing/harness.ts +24 -0
- package/src/testing/index.ts +26 -0
- package/src/testing/node/duplex-connection.ts +50 -0
- package/src/testing/node/duplex-stream.ts +51 -0
- package/src/testing/node/index.ts +22 -0
- package/src/testing/wait-for.ts +94 -0
- package/src/tracer.ts +277 -0
- package/src/transfer-diagnostic.ts +92 -0
- package/src/transfer-document.ts +99 -0
- package/src/transfer-element.ts +43 -0
- package/src/uri.ts +61 -0
- package/src/util.ts +250 -0
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/********************************************************************************
|
|
3
|
+
* Copyright (c) 2023-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
|
+
exports.TransferDocument = void 0;
|
|
12
|
+
var TransferDocument;
|
|
13
|
+
(function (TransferDocument) {
|
|
14
|
+
/**
|
|
15
|
+
* Whether the server had this document. Branch on it where absence is an
|
|
16
|
+
* ordinary state — a view bound to a file that may not exist yet.
|
|
17
|
+
*/
|
|
18
|
+
function isLoaded(document) {
|
|
19
|
+
return document.root !== undefined;
|
|
20
|
+
}
|
|
21
|
+
TransferDocument.isLoaded = isLoaded;
|
|
22
|
+
/**
|
|
23
|
+
* The same document with `root` no longer optional, or a throw. For call
|
|
24
|
+
* sites where absence is a bug rather than a branch; the whole envelope is
|
|
25
|
+
* returned because a caller needing `root` usually needs `uri` or `version`
|
|
26
|
+
* with it.
|
|
27
|
+
*/
|
|
28
|
+
function assertLoaded(document) {
|
|
29
|
+
if (!isLoaded(document)) {
|
|
30
|
+
throw new Error(`No document at ${document.uri}`);
|
|
31
|
+
}
|
|
32
|
+
return document;
|
|
33
|
+
}
|
|
34
|
+
TransferDocument.assertLoaded = assertLoaded;
|
|
35
|
+
/**
|
|
36
|
+
* Construct a {@link TransferDocument} envelope. `diagnostics` defaults
|
|
37
|
+
* to `[]` so test fixtures, fake protocol implementations, and the
|
|
38
|
+
* "no diagnostics yet" code paths don't need to repeat the empty array
|
|
39
|
+
* at every call site.
|
|
40
|
+
*/
|
|
41
|
+
function create(uri, version, root, diagnostics = []) {
|
|
42
|
+
return { uri, version, root, diagnostics };
|
|
43
|
+
}
|
|
44
|
+
TransferDocument.create = create;
|
|
45
|
+
})(TransferDocument || (exports.TransferDocument = TransferDocument = {}));
|
|
46
|
+
//# sourceMappingURL=transfer-document.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transfer-document.js","sourceRoot":"","sources":["../src/transfer-document.ts"],"names":[],"mappings":";AAAA;;;;;;;kFAOkF;;;AAmDlF,IAAiB,gBAAgB,CAwChC;AAxCD,WAAiB,gBAAgB;IAC9B;;;OAGG;IACH,SAAgB,QAAQ,CACrB,QAAkD;QAElD,OAAO,QAAQ,CAAC,IAAI,KAAK,SAAS,CAAC;IACtC,CAAC;IAJe,yBAAQ,WAIvB,CAAA;IAED;;;;;OAKG;IACH,SAAgB,YAAY,CACzB,QAAkD;QAElD,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC;YACvB,MAAM,IAAI,KAAK,CAAC,kBAAkB,QAAQ,CAAC,GAAG,EAAE,CAAC,CAAC;QACrD,CAAC;QACD,OAAO,QAAQ,CAAC;IACnB,CAAC;IAPe,6BAAY,eAO3B,CAAA;IAED;;;;;OAKG;IACH,SAAgB,MAAM,CACnB,GAAW,EACX,OAAe,EACf,IAAe,EACf,cAA6B,EAAE;QAE/B,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,CAAC;IAC9C,CAAC;IAPe,uBAAM,SAOrB,CAAA;AACJ,CAAC,EAxCgB,gBAAgB,gCAAhB,gBAAgB,QAwChC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/********************************************************************************
|
|
2
|
+
* Copyright (c) 2023-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
|
+
* Base shapes for the transfer-model overlay generated per consumer language.
|
|
11
|
+
*
|
|
12
|
+
* Every node in a generated transfer model extends {@link TransferElement} and
|
|
13
|
+
* cross-references between nodes serialise as plain strings. These types carry no
|
|
14
|
+
* language-specific knowledge — language-specific types live in the consumer's
|
|
15
|
+
* generated `transfer-model.ts` overlay, emitted by the code generator from
|
|
16
|
+
* the consumer's grammar.
|
|
17
|
+
*/
|
|
18
|
+
/** Base type of every transfer-model node — carries the AST type discriminator. */
|
|
19
|
+
export interface TransferElement {
|
|
20
|
+
readonly $type: string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Type-level lookup: given an AST node type `T` (with a string-literal
|
|
24
|
+
* `$type` discriminator from Langium's generated AST) and a per-grammar
|
|
25
|
+
* `TTransferMap` overlay keyed by those `$type` strings, resolve to the
|
|
26
|
+
* declared wire shape — or fall back to the structural base
|
|
27
|
+
* {@link TransferElement} when no entry is declared.
|
|
28
|
+
*
|
|
29
|
+
* Adopters declare the overlay by interface merging or by generating an
|
|
30
|
+
* interface keyed on those `$type` strings. Types not in the overlay resolve to
|
|
31
|
+
* `TransferElement` — the framework default behaves correctly without an
|
|
32
|
+
* overlay (no autocomplete, but no compile error either).
|
|
33
|
+
*
|
|
34
|
+
* The lookup is compile-time only; no runtime cost.
|
|
35
|
+
*/
|
|
36
|
+
export type TransferTypeFor<TAst extends {
|
|
37
|
+
readonly $type: string;
|
|
38
|
+
}, TTransferMap> = TAst['$type'] extends keyof TTransferMap ? TTransferMap[TAst['$type']] extends TransferElement ? TTransferMap[TAst['$type']] : TransferElement : TransferElement;
|
|
39
|
+
//# sourceMappingURL=transfer-element.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transfer-element.d.ts","sourceRoot":"","sources":["../src/transfer-element.ts"],"names":[],"mappings":"AAAA;;;;;;;kFAOkF;AAElF;;;;;;;;GAQG;AAEH,mFAAmF;AACnF,MAAM,WAAW,eAAe;IAC7B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CACzB;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,MAAM,eAAe,CAAC,IAAI,SAAS;IAAE,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;CAAE,EAAE,YAAY,IAAI,IAAI,CAAC,OAAO,CAAC,SAAS,MAAM,YAAY,GACxH,YAAY,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,SAAS,eAAe,GAChD,YAAY,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,GAC3B,eAAe,GAClB,eAAe,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/********************************************************************************
|
|
3
|
+
* Copyright (c) 2023-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=transfer-element.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transfer-element.js","sourceRoot":"","sources":["../src/transfer-element.ts"],"names":[],"mappings":";AAAA;;;;;;;kFAOkF"}
|
package/lib/uri.d.ts
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
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
|
+
* Branded URI-string types distinguishing the framework's two document-identity
|
|
11
|
+
* spaces. Both are `string` at runtime — the brand is a phantom field, erased by
|
|
12
|
+
* the compiler, so there is zero runtime cost and the values pass freely to any
|
|
13
|
+
* `string` sink (`UriUtils`, RPC payloads, logs). At compile time they are
|
|
14
|
+
* **nominally distinct and mutually non-assignable**, so one cannot be used
|
|
15
|
+
* where the other is expected.
|
|
16
|
+
*
|
|
17
|
+
* - {@link CanonicalUri} — *server-identity* space: the single canonical key a
|
|
18
|
+
* document is stored under (`LangiumDocuments` keying, AST-document event
|
|
19
|
+
* filters, request-path lookups). Minted ONLY by
|
|
20
|
+
* `DocumentUriPolicy.canonicalUri` — the single point that defines what
|
|
21
|
+
* "canonical" means, so every `CanonicalUri` has provable provenance.
|
|
22
|
+
* - {@link LanguageClientUri} — the URI the LSP *textual* language client
|
|
23
|
+
* (Monaco / VS Code) actually opened a document under, which may differ from
|
|
24
|
+
* its canonical identity (e.g. a symlinked path while the document is keyed by
|
|
25
|
+
* its real path). This is the URI `applyEditToLanguageClient` and diagnostics must
|
|
26
|
+
* address. Named for the *language client* specifically — the GLSP and
|
|
27
|
+
* data-server heads are also clients, but they are addressed canonically.
|
|
28
|
+
*
|
|
29
|
+
* Why both are real brands rather than aliases: a plain `type X = string` is
|
|
30
|
+
* assignable to and from any `string` (and a `CanonicalUri` *is* a `string`), so
|
|
31
|
+
* an alias would let a canonical URI flow into a language-client sink unchecked —
|
|
32
|
+
* exactly the class of bug where an outbound sync addressed the client by the
|
|
33
|
+
* canonical URI it never opened. The distinct `__uriSpace` discriminants make
|
|
34
|
+
* that a compile error, and make plain `string` assignable to neither — forcing
|
|
35
|
+
* values through a mint point.
|
|
36
|
+
*
|
|
37
|
+
* Scope: these are an **internal** server-identity discipline. RPC/wire fields
|
|
38
|
+
* and public service parameters stay plain `string` so the brands never leak to
|
|
39
|
+
* adopters or across the wire; conversion happens at the framework boundary.
|
|
40
|
+
*/
|
|
41
|
+
export type CanonicalUri = string & {
|
|
42
|
+
readonly __uriSpace: 'canonical';
|
|
43
|
+
};
|
|
44
|
+
/** The LSP textual language client's document URI. See {@link CanonicalUri} for the full rationale. */
|
|
45
|
+
export type LanguageClientUri = string & {
|
|
46
|
+
readonly __uriSpace: 'languageClient';
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* Mint a {@link CanonicalUri}. The single sanctioned place the brand assertion
|
|
50
|
+
* lives — call this from the one component that defines canonicalisation
|
|
51
|
+
* (`DocumentUriPolicy.canonicalUri`) instead of scattering `as CanonicalUri`
|
|
52
|
+
* casts, so a call site reads as a deliberate identity mint rather than an
|
|
53
|
+
* escape hatch.
|
|
54
|
+
*/
|
|
55
|
+
export declare const asCanonicalUri: (value: string) => CanonicalUri;
|
|
56
|
+
/**
|
|
57
|
+
* Mint a {@link LanguageClientUri}. The single sanctioned place the brand
|
|
58
|
+
* assertion lives — call this from the component that owns the language-client
|
|
59
|
+
* URI space (the text store's `toLanguageClientUri`). See {@link asCanonicalUri}.
|
|
60
|
+
*/
|
|
61
|
+
export declare const asLanguageClientUri: (value: string) => LanguageClientUri;
|
|
62
|
+
//# sourceMappingURL=uri.d.ts.map
|
package/lib/uri.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"uri.d.ts","sourceRoot":"","sources":["../src/uri.ts"],"names":[],"mappings":"AAAA;;;;;;;kFAOkF;AAElF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG;IAAE,QAAQ,CAAC,UAAU,EAAE,WAAW,CAAA;CAAE,CAAC;AAEzE,uGAAuG;AACvG,MAAM,MAAM,iBAAiB,GAAG,MAAM,GAAG;IAAE,QAAQ,CAAC,UAAU,EAAE,gBAAgB,CAAA;CAAE,CAAC;AAEnF;;;;;;GAMG;AACH,eAAO,MAAM,cAAc,GAAI,OAAO,MAAM,KAAG,YAAqC,CAAC;AAErF;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,GAAI,OAAO,MAAM,KAAG,iBAA+C,CAAC"}
|
package/lib/uri.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
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
|
+
exports.asLanguageClientUri = exports.asCanonicalUri = void 0;
|
|
12
|
+
/**
|
|
13
|
+
* Mint a {@link CanonicalUri}. The single sanctioned place the brand assertion
|
|
14
|
+
* lives — call this from the one component that defines canonicalisation
|
|
15
|
+
* (`DocumentUriPolicy.canonicalUri`) instead of scattering `as CanonicalUri`
|
|
16
|
+
* casts, so a call site reads as a deliberate identity mint rather than an
|
|
17
|
+
* escape hatch.
|
|
18
|
+
*/
|
|
19
|
+
const asCanonicalUri = (value) => value;
|
|
20
|
+
exports.asCanonicalUri = asCanonicalUri;
|
|
21
|
+
/**
|
|
22
|
+
* Mint a {@link LanguageClientUri}. The single sanctioned place the brand
|
|
23
|
+
* assertion lives — call this from the component that owns the language-client
|
|
24
|
+
* URI space (the text store's `toLanguageClientUri`). See {@link asCanonicalUri}.
|
|
25
|
+
*/
|
|
26
|
+
const asLanguageClientUri = (value) => value;
|
|
27
|
+
exports.asLanguageClientUri = asLanguageClientUri;
|
|
28
|
+
//# sourceMappingURL=uri.js.map
|
package/lib/uri.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"uri.js","sourceRoot":"","sources":["../src/uri.ts"],"names":[],"mappings":";AAAA;;;;;;;kFAOkF;;;AAuClF;;;;;;GAMG;AACI,MAAM,cAAc,GAAG,CAAC,KAAa,EAAgB,EAAE,CAAC,KAAqB,CAAC;AAAxE,QAAA,cAAc,kBAA0D;AAErF;;;;GAIG;AACI,MAAM,mBAAmB,GAAG,CAAC,KAAa,EAAqB,EAAE,CAAC,KAA0B,CAAC;AAAvF,QAAA,mBAAmB,uBAAoE"}
|
package/lib/util.d.ts
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
/********************************************************************************
|
|
2
|
+
* Copyright (c) 2023 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
|
+
/** A user-defined type predicate. */
|
|
10
|
+
export type TypeGuard<T> = (item: unknown) => item is T;
|
|
11
|
+
/**
|
|
12
|
+
* Minimal disposable shape, intentionally identical to `vscode-jsonrpc.Disposable`
|
|
13
|
+
* by structural typing so it interoperates without an actual dependency on that
|
|
14
|
+
* library. Consumers may pass instances of this type wherever a `Disposable`
|
|
15
|
+
* is expected, and vice versa.
|
|
16
|
+
*
|
|
17
|
+
* Re-defined locally rather than re-exported from `vscode-jsonrpc` so adopters
|
|
18
|
+
* pulling this interface in do not transitively see `vscode-jsonrpc` types as
|
|
19
|
+
* part of the framework's public surface.
|
|
20
|
+
*/
|
|
21
|
+
export interface Disposable {
|
|
22
|
+
dispose(): void;
|
|
23
|
+
}
|
|
24
|
+
export declare namespace Disposable {
|
|
25
|
+
function create(dispose: () => void): Disposable;
|
|
26
|
+
/**
|
|
27
|
+
* Shared no-op {@link Disposable} — `dispose()` does nothing. Use wherever a
|
|
28
|
+
* disposable is required but there is nothing to release (a subscription with
|
|
29
|
+
* no teardown, a listener registration in a test double) instead of a fresh
|
|
30
|
+
* `{ dispose: () => undefined }` literal. Frozen so the shared instance can't
|
|
31
|
+
* be mutated.
|
|
32
|
+
*/
|
|
33
|
+
const EMPTY: Disposable;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* A collection of disposables that itself implements {@link Disposable}.
|
|
37
|
+
*
|
|
38
|
+
* - {@link dispose} is idempotent: repeat calls are safe.
|
|
39
|
+
* - {@link push} returns the added disposable for chaining.
|
|
40
|
+
* - Push-after-disposal disposes the added item immediately (prevents leaks
|
|
41
|
+
* from late arrivals on a collection that has already been torn down).
|
|
42
|
+
* - LIFO drain order: last-pushed disposes first. Matches the convention that
|
|
43
|
+
* later disposables typically depend on earlier ones (e.g., a subscription
|
|
44
|
+
* depends on a connection, so the subscription must dispose first before
|
|
45
|
+
* the connection tears down its transport).
|
|
46
|
+
* - A throwing dispose does not strand subsequent disposables in the drain.
|
|
47
|
+
*
|
|
48
|
+
* Fills the gap left by vscode-jsonrpc and Langium, which provide only the
|
|
49
|
+
* `Disposable` interface and a `Disposable.create()` factory.
|
|
50
|
+
*/
|
|
51
|
+
export declare class DisposableCollection implements Disposable {
|
|
52
|
+
protected readonly disposables: Disposable[];
|
|
53
|
+
protected _disposed: boolean;
|
|
54
|
+
get disposed(): boolean;
|
|
55
|
+
push(disposable: Disposable): Disposable;
|
|
56
|
+
dispose(): void;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* A `Promise` paired with its `resolve` / `reject` callbacks, so producer
|
|
60
|
+
* and consumer code can be in different scopes. Use when a constructor
|
|
61
|
+
* needs to expose a `ready` promise that a later method resolves.
|
|
62
|
+
*
|
|
63
|
+
* Equivalent to Theia / GLSP / Langium's `Deferred` utility — re-implemented
|
|
64
|
+
* here so `@hydranium/protocol` stays runtime-dependency-free.
|
|
65
|
+
*/
|
|
66
|
+
export declare class Deferred<T = void> {
|
|
67
|
+
readonly promise: Promise<T>;
|
|
68
|
+
resolve: (value: T | PromiseLike<T>) => void;
|
|
69
|
+
reject: (reason?: unknown) => void;
|
|
70
|
+
constructor();
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* A value that is either `T` directly (sync) or a thenable that resolves to `T`
|
|
74
|
+
* (async). Used in framework hook signatures where adopter overrides may be
|
|
75
|
+
* either sync or async without forcing the synchronous fast path to pay an
|
|
76
|
+
* unconditional microtask tick.
|
|
77
|
+
*
|
|
78
|
+
* Uses the permissive `PromiseLike<T>` form so externally-produced thenables
|
|
79
|
+
* (non-native Promise implementations) also flow through.
|
|
80
|
+
*
|
|
81
|
+
* Pair with {@link isPromiseLike} at hot-loop call sites to preserve
|
|
82
|
+
* the sync fast path (an `await` on a non-promise still schedules a microtask).
|
|
83
|
+
*/
|
|
84
|
+
export type MaybePromise<T> = T | PromiseLike<T>;
|
|
85
|
+
/**
|
|
86
|
+
* Type guard distinguishing the async branch of {@link MaybePromise}.
|
|
87
|
+
*
|
|
88
|
+
* At framework call sites in tight loops, guarding before the `await` keeps
|
|
89
|
+
* sync implementations on the synchronous fast path — `await` on
|
|
90
|
+
* a non-promise still schedules a microtask, which for per-node loops adds
|
|
91
|
+
* up. Outside of tight loops a naive `await maybe` is equivalent and
|
|
92
|
+
* shorter; reach for the guard only when the call sits on the build's
|
|
93
|
+
* critical path.
|
|
94
|
+
*
|
|
95
|
+
* Thenable check (`'then' in value`) rather than `instanceof Promise` so
|
|
96
|
+
* non-native Promise implementations also classify as async.
|
|
97
|
+
*/
|
|
98
|
+
export declare function isPromiseLike<T = unknown>(value: MaybePromise<T>): value is PromiseLike<T>;
|
|
99
|
+
/** Removes `readonly` from all properties of `T`. */
|
|
100
|
+
export type Mutable<T> = {
|
|
101
|
+
-readonly [P in keyof T]: T[P];
|
|
102
|
+
};
|
|
103
|
+
/** Returns the same value typed as a {@link Mutable}. Compile-time only. */
|
|
104
|
+
export declare function asMutable<T>(item: T): Mutable<T>;
|
|
105
|
+
/** Type-guard variant: narrows `item` to `Mutable<T> | undefined` if `guard` accepts it. */
|
|
106
|
+
export declare function toMutable<T>(item: unknown, guard: TypeGuard<T>): item is Mutable<T> | undefined;
|
|
107
|
+
/**
|
|
108
|
+
* Wrap `text` in `quoteChar`, escaping interior occurrences with `replaceChar`.
|
|
109
|
+
*
|
|
110
|
+
* - Empty input becomes a pair of quote characters.
|
|
111
|
+
* - Pre-existing surrounding quotes are not double-wrapped.
|
|
112
|
+
* - Interior `quoteChar` runs are mapped to `replaceChar`.
|
|
113
|
+
*/
|
|
114
|
+
export declare function quote(text: string, quoteChar?: string, replaceChar?: string): string;
|
|
115
|
+
/** Strip a single layer of `quoteChar` from the start and end of `text` if present. */
|
|
116
|
+
export declare function unquote(text: string, quoteChar?: string): string;
|
|
117
|
+
/** Capitalise the first character of `input`. */
|
|
118
|
+
export declare function toPascal(input: string): string;
|
|
119
|
+
/**
|
|
120
|
+
* Format a [codicon](https://github.com/microsoft/vscode-codicons) name as the
|
|
121
|
+
* CSS class string consumed by VS Code- and Theia-style icon hosts.
|
|
122
|
+
*
|
|
123
|
+
* Presentation, not wire contract, and a duplicate of `@eclipse-glsp/client`'s
|
|
124
|
+
* export of the same name — a file importing both barrels gets an ambiguity, so
|
|
125
|
+
* client code that already depends on GLSP takes the upstream one. It stays on
|
|
126
|
+
* this barrel because adopter protocol packages re-export these helpers
|
|
127
|
+
* wholesale, which makes relocating it a breaking change rather than a move.
|
|
128
|
+
*/
|
|
129
|
+
export declare function codiconCSSString(icon: string): string;
|
|
130
|
+
/** The identity function. Useful as a default mapping callback. */
|
|
131
|
+
export declare function identity<T>(value: T): T;
|
|
132
|
+
/** Find a name based on `suggestion` that is not already in `existing`, appending an
|
|
133
|
+
* incrementing numeric suffix until a free slot is found. */
|
|
134
|
+
export declare function findNextUnique(suggestion: string, existing: string[]): string;
|
|
135
|
+
export declare function findNextUnique<T>(suggestion: string, existing: T[], nameGetter: (element: T) => string): string;
|
|
136
|
+
/** Throw if reached. Helper for exhaustiveness checks at the end of a discriminated-union switch. */
|
|
137
|
+
export declare function unreachable(input: never): never;
|
|
138
|
+
/**
|
|
139
|
+
* Resolve a nested value from a plain object using a path of property names.
|
|
140
|
+
* Returns `undefined` for any segment that is not an object or is null.
|
|
141
|
+
*
|
|
142
|
+
* The generic `T` is a caller-provided assertion about the value's type — it
|
|
143
|
+
* is not validated at runtime. Use `unknown` (the default) if the type is
|
|
144
|
+
* uncertain, then narrow with a type-guard.
|
|
145
|
+
*/
|
|
146
|
+
export declare function getAt<T = unknown>(obj: unknown, path: string[]): T | undefined;
|
|
147
|
+
//# sourceMappingURL=util.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"AAAA;;;;;;;kFAOkF;AAElF,qCAAqC;AACrC,MAAM,MAAM,SAAS,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,OAAO,KAAK,IAAI,IAAI,CAAC,CAAC;AAExD;;;;;;;;;GASG;AACH,MAAM,WAAW,UAAU;IACxB,OAAO,IAAI,IAAI,CAAC;CAClB;AAED,yBAAiB,UAAU,CAAC;IACzB,SAAgB,MAAM,CAAC,OAAO,EAAE,MAAM,IAAI,GAAG,UAAU,CAEtD;IACD;;;;;;OAMG;IACI,MAAM,KAAK,EAAE,UAAwD,CAAC;CAC/E;AAED;;;;;;;;;;;;;;;GAeG;AACH,qBAAa,oBAAqB,YAAW,UAAU;IACpD,SAAS,CAAC,QAAQ,CAAC,WAAW,EAAE,UAAU,EAAE,CAAM;IAClD,SAAS,CAAC,SAAS,UAAS;IAE5B,IAAI,QAAQ,IAAI,OAAO,CAEtB;IAED,IAAI,CAAC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SAAM,GAAG,MAAM,CAI7D;AAED,iDAAiD;AACjD,wBAAgB,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAE9C;AAED;;;;;;;;;GASG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAErD;AAED,mEAAmE;AACnE,wBAAgB,QAAQ,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC,CAEvC;AAED;8DAC8D;AAC9D,wBAAgB,cAAc,CAAC,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC;AAC/E,wBAAgB,cAAc,CAAC,CAAC,EAAE,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,EAAE,EAAE,UAAU,EAAE,CAAC,OAAO,EAAE,CAAC,KAAK,MAAM,GAAG,MAAM,CAAC;AAWjH,qGAAqG;AACrG,wBAAgB,WAAW,CAAC,KAAK,EAAE,KAAK,GAAG,KAAK,CAE/C;AAED;;;;;;;GAOG;AACH,wBAAgB,KAAK,CAAC,CAAC,GAAG,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,CAAC,GAAG,SAAS,CAS9E"}
|
package/lib/util.js
ADDED
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/********************************************************************************
|
|
3
|
+
* Copyright (c) 2023 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
|
+
exports.Deferred = exports.DisposableCollection = exports.Disposable = void 0;
|
|
12
|
+
exports.isPromiseLike = isPromiseLike;
|
|
13
|
+
exports.asMutable = asMutable;
|
|
14
|
+
exports.toMutable = toMutable;
|
|
15
|
+
exports.quote = quote;
|
|
16
|
+
exports.unquote = unquote;
|
|
17
|
+
exports.toPascal = toPascal;
|
|
18
|
+
exports.codiconCSSString = codiconCSSString;
|
|
19
|
+
exports.identity = identity;
|
|
20
|
+
exports.findNextUnique = findNextUnique;
|
|
21
|
+
exports.unreachable = unreachable;
|
|
22
|
+
exports.getAt = getAt;
|
|
23
|
+
var Disposable;
|
|
24
|
+
(function (Disposable) {
|
|
25
|
+
function create(dispose) {
|
|
26
|
+
return { dispose };
|
|
27
|
+
}
|
|
28
|
+
Disposable.create = create;
|
|
29
|
+
/**
|
|
30
|
+
* Shared no-op {@link Disposable} — `dispose()` does nothing. Use wherever a
|
|
31
|
+
* disposable is required but there is nothing to release (a subscription with
|
|
32
|
+
* no teardown, a listener registration in a test double) instead of a fresh
|
|
33
|
+
* `{ dispose: () => undefined }` literal. Frozen so the shared instance can't
|
|
34
|
+
* be mutated.
|
|
35
|
+
*/
|
|
36
|
+
Disposable.EMPTY = Object.freeze({ dispose: () => undefined });
|
|
37
|
+
})(Disposable || (exports.Disposable = Disposable = {}));
|
|
38
|
+
/**
|
|
39
|
+
* A collection of disposables that itself implements {@link Disposable}.
|
|
40
|
+
*
|
|
41
|
+
* - {@link dispose} is idempotent: repeat calls are safe.
|
|
42
|
+
* - {@link push} returns the added disposable for chaining.
|
|
43
|
+
* - Push-after-disposal disposes the added item immediately (prevents leaks
|
|
44
|
+
* from late arrivals on a collection that has already been torn down).
|
|
45
|
+
* - LIFO drain order: last-pushed disposes first. Matches the convention that
|
|
46
|
+
* later disposables typically depend on earlier ones (e.g., a subscription
|
|
47
|
+
* depends on a connection, so the subscription must dispose first before
|
|
48
|
+
* the connection tears down its transport).
|
|
49
|
+
* - A throwing dispose does not strand subsequent disposables in the drain.
|
|
50
|
+
*
|
|
51
|
+
* Fills the gap left by vscode-jsonrpc and Langium, which provide only the
|
|
52
|
+
* `Disposable` interface and a `Disposable.create()` factory.
|
|
53
|
+
*/
|
|
54
|
+
class DisposableCollection {
|
|
55
|
+
disposables = [];
|
|
56
|
+
_disposed = false;
|
|
57
|
+
get disposed() {
|
|
58
|
+
return this._disposed;
|
|
59
|
+
}
|
|
60
|
+
push(disposable) {
|
|
61
|
+
if (this._disposed) {
|
|
62
|
+
disposable.dispose();
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
this.disposables.push(disposable);
|
|
66
|
+
}
|
|
67
|
+
return disposable;
|
|
68
|
+
}
|
|
69
|
+
dispose() {
|
|
70
|
+
if (this._disposed) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
this._disposed = true;
|
|
74
|
+
while (this.disposables.length > 0) {
|
|
75
|
+
try {
|
|
76
|
+
this.disposables.pop().dispose();
|
|
77
|
+
}
|
|
78
|
+
catch (_err) {
|
|
79
|
+
// Continue draining — one failed dispose shouldn't strand the rest.
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
exports.DisposableCollection = DisposableCollection;
|
|
85
|
+
/**
|
|
86
|
+
* A `Promise` paired with its `resolve` / `reject` callbacks, so producer
|
|
87
|
+
* and consumer code can be in different scopes. Use when a constructor
|
|
88
|
+
* needs to expose a `ready` promise that a later method resolves.
|
|
89
|
+
*
|
|
90
|
+
* Equivalent to Theia / GLSP / Langium's `Deferred` utility — re-implemented
|
|
91
|
+
* here so `@hydranium/protocol` stays runtime-dependency-free.
|
|
92
|
+
*/
|
|
93
|
+
class Deferred {
|
|
94
|
+
promise;
|
|
95
|
+
resolve;
|
|
96
|
+
reject;
|
|
97
|
+
constructor() {
|
|
98
|
+
this.promise = new Promise((resolve, reject) => {
|
|
99
|
+
this.resolve = resolve;
|
|
100
|
+
this.reject = reject;
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
exports.Deferred = Deferred;
|
|
105
|
+
/**
|
|
106
|
+
* Type guard distinguishing the async branch of {@link MaybePromise}.
|
|
107
|
+
*
|
|
108
|
+
* At framework call sites in tight loops, guarding before the `await` keeps
|
|
109
|
+
* sync implementations on the synchronous fast path — `await` on
|
|
110
|
+
* a non-promise still schedules a microtask, which for per-node loops adds
|
|
111
|
+
* up. Outside of tight loops a naive `await maybe` is equivalent and
|
|
112
|
+
* shorter; reach for the guard only when the call sits on the build's
|
|
113
|
+
* critical path.
|
|
114
|
+
*
|
|
115
|
+
* Thenable check (`'then' in value`) rather than `instanceof Promise` so
|
|
116
|
+
* non-native Promise implementations also classify as async.
|
|
117
|
+
*/
|
|
118
|
+
function isPromiseLike(value) {
|
|
119
|
+
return !!value && typeof value.then === 'function';
|
|
120
|
+
}
|
|
121
|
+
/** Returns the same value typed as a {@link Mutable}. Compile-time only. */
|
|
122
|
+
function asMutable(item) {
|
|
123
|
+
return item;
|
|
124
|
+
}
|
|
125
|
+
function toMutable(item, guard) {
|
|
126
|
+
return guard ? guard(item) : true;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Wrap `text` in `quoteChar`, escaping interior occurrences with `replaceChar`.
|
|
130
|
+
*
|
|
131
|
+
* - Empty input becomes a pair of quote characters.
|
|
132
|
+
* - Pre-existing surrounding quotes are not double-wrapped.
|
|
133
|
+
* - Interior `quoteChar` runs are mapped to `replaceChar`.
|
|
134
|
+
*/
|
|
135
|
+
function quote(text, quoteChar = '"', replaceChar = "'") {
|
|
136
|
+
if (text.length === 0) {
|
|
137
|
+
return quoteChar + quoteChar;
|
|
138
|
+
}
|
|
139
|
+
let quoted = text;
|
|
140
|
+
if (!quoted.startsWith(quoteChar)) {
|
|
141
|
+
quoted = quoteChar + quoted;
|
|
142
|
+
}
|
|
143
|
+
if (!quoted.endsWith(quoteChar)) {
|
|
144
|
+
quoted += quoteChar;
|
|
145
|
+
}
|
|
146
|
+
return (quoteChar +
|
|
147
|
+
quoted
|
|
148
|
+
.substring(1, quoted.length - 1)
|
|
149
|
+
.split(quoteChar)
|
|
150
|
+
.join(replaceChar) +
|
|
151
|
+
quoteChar);
|
|
152
|
+
}
|
|
153
|
+
/** Strip a single layer of `quoteChar` from the start and end of `text` if present. */
|
|
154
|
+
function unquote(text, quoteChar = '"') {
|
|
155
|
+
const start = text.startsWith(quoteChar) ? 1 : undefined;
|
|
156
|
+
const end = text.endsWith(quoteChar) ? -1 : undefined;
|
|
157
|
+
return text.slice(start, end);
|
|
158
|
+
}
|
|
159
|
+
/** Capitalise the first character of `input`. */
|
|
160
|
+
function toPascal(input) {
|
|
161
|
+
return input.charAt(0).toLocaleUpperCase() + input.slice(1);
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Format a [codicon](https://github.com/microsoft/vscode-codicons) name as the
|
|
165
|
+
* CSS class string consumed by VS Code- and Theia-style icon hosts.
|
|
166
|
+
*
|
|
167
|
+
* Presentation, not wire contract, and a duplicate of `@eclipse-glsp/client`'s
|
|
168
|
+
* export of the same name — a file importing both barrels gets an ambiguity, so
|
|
169
|
+
* client code that already depends on GLSP takes the upstream one. It stays on
|
|
170
|
+
* this barrel because adopter protocol packages re-export these helpers
|
|
171
|
+
* wholesale, which makes relocating it a breaking change rather than a move.
|
|
172
|
+
*/
|
|
173
|
+
function codiconCSSString(icon) {
|
|
174
|
+
return `codicon codicon-${icon}`;
|
|
175
|
+
}
|
|
176
|
+
/** The identity function. Useful as a default mapping callback. */
|
|
177
|
+
function identity(value) {
|
|
178
|
+
return value;
|
|
179
|
+
}
|
|
180
|
+
function findNextUnique(suggestion, existing, nameGetter) {
|
|
181
|
+
const names = nameGetter ? existing.map(nameGetter) : existing;
|
|
182
|
+
let name = suggestion;
|
|
183
|
+
let index = 1;
|
|
184
|
+
while (names.includes(name)) {
|
|
185
|
+
name = suggestion + index++;
|
|
186
|
+
}
|
|
187
|
+
return name;
|
|
188
|
+
}
|
|
189
|
+
/** Throw if reached. Helper for exhaustiveness checks at the end of a discriminated-union switch. */
|
|
190
|
+
function unreachable(input) {
|
|
191
|
+
throw new Error('Value detected in unreachable assertion: ' + `${input}`);
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Resolve a nested value from a plain object using a path of property names.
|
|
195
|
+
* Returns `undefined` for any segment that is not an object or is null.
|
|
196
|
+
*
|
|
197
|
+
* The generic `T` is a caller-provided assertion about the value's type — it
|
|
198
|
+
* is not validated at runtime. Use `unknown` (the default) if the type is
|
|
199
|
+
* uncertain, then narrow with a type-guard.
|
|
200
|
+
*/
|
|
201
|
+
function getAt(obj, path) {
|
|
202
|
+
let cur = obj;
|
|
203
|
+
for (const seg of path) {
|
|
204
|
+
if (cur == null || typeof cur !== 'object') {
|
|
205
|
+
return undefined;
|
|
206
|
+
}
|
|
207
|
+
cur = cur[seg];
|
|
208
|
+
}
|
|
209
|
+
return cur;
|
|
210
|
+
}
|
|
211
|
+
//# sourceMappingURL=util.js.map
|
package/lib/util.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"util.js","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":";AAAA;;;;;;;kFAOkF;;;AAiIlF,sCAEC;AAMD,8BAEC;AAID,8BAEC;AASD,sBAmBC;AAGD,0BAIC;AAGD,4BAEC;AAYD,4CAEC;AAGD,4BAEC;AAMD,wCAQC;AAGD,kCAEC;AAUD,sBASC;AA/ND,IAAiB,UAAU,CAY1B;AAZD,WAAiB,UAAU;IACxB,SAAgB,MAAM,CAAC,OAAmB;QACvC,OAAO,EAAE,OAAO,EAAE,CAAC;IACtB,CAAC;IAFe,iBAAM,SAErB,CAAA;IACD;;;;;;OAMG;IACU,gBAAK,GAAe,MAAM,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,SAAS,EAAE,CAAC,CAAC;AAChF,CAAC,EAZgB,UAAU,0BAAV,UAAU,QAY1B;AAED;;;;;;;;;;;;;;;GAeG;AACH,MAAa,oBAAoB;IACX,WAAW,GAAiB,EAAE,CAAC;IACxC,SAAS,GAAG,KAAK,CAAC;IAE5B,IAAI,QAAQ;QACT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