@hydranium/protocol 1.0.0-next.31 → 1.0.0-next.32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +35 -1
- package/lib/messages/primitives.d.ts +12 -6
- package/lib/messages/primitives.d.ts.map +1 -1
- package/lib/messages/primitives.js.map +1 -1
- package/lib/rpc/bind-rpc-methods.d.ts +29 -3
- package/lib/rpc/bind-rpc-methods.d.ts.map +1 -1
- package/lib/rpc/bind-rpc-methods.js +22 -3
- package/lib/rpc/bind-rpc-methods.js.map +1 -1
- package/lib/rpc/create-rpc-proxy.d.ts +7 -0
- package/lib/rpc/create-rpc-proxy.d.ts.map +1 -1
- package/lib/rpc/create-rpc-proxy.js +6 -1
- package/lib/rpc/create-rpc-proxy.js.map +1 -1
- package/lib/testing/catalogue-audit.d.ts +80 -0
- package/lib/testing/catalogue-audit.d.ts.map +1 -0
- package/lib/testing/catalogue-audit.js +94 -0
- package/lib/testing/catalogue-audit.js.map +1 -0
- package/lib/testing/index.d.ts +1 -0
- package/lib/testing/index.d.ts.map +1 -1
- package/lib/testing/index.js +4 -1
- package/lib/testing/index.js.map +1 -1
- package/package.json +1 -1
- package/src/messages/primitives.ts +12 -6
- package/src/rpc/bind-rpc-methods.ts +49 -4
- package/src/rpc/create-rpc-proxy.ts +14 -1
- package/src/testing/catalogue-audit.ts +111 -0
- package/src/testing/index.ts +4 -1
package/README.md
CHANGED
|
@@ -60,7 +60,7 @@ names, a worked example — is in
|
|
|
60
60
|
@hydranium/protocol # transfer documents, references, RPC machinery
|
|
61
61
|
@hydranium/protocol/data # DataServerProtocol / DataClientProtocol
|
|
62
62
|
@hydranium/protocol/client # the host-neutral client tier
|
|
63
|
-
@hydranium/protocol/testing # test doubles
|
|
63
|
+
@hydranium/protocol/testing # test doubles, waiters, catalogue audit
|
|
64
64
|
@hydranium/protocol/testing/node # the Node-only doubles
|
|
65
65
|
```
|
|
66
66
|
|
|
@@ -69,6 +69,40 @@ narrower surface rather than reach; `testing` is only reachable by its own
|
|
|
69
69
|
specifier, which is what keeps the doubles out of a production bundle. The RPC
|
|
70
70
|
machinery documents itself in [`src/rpc/README.md`](./src/rpc/README.md).
|
|
71
71
|
|
|
72
|
+
### Auditing a translation catalogue
|
|
73
|
+
|
|
74
|
+
An adopter with i18n has one failure mode nothing else catches: a catalogue key
|
|
75
|
+
naming no declared code falls back to the English, which is byte-identical to
|
|
76
|
+
the deliberately-partial behaviour every adopter relies on. So a typo is
|
|
77
|
+
invisible at runtime, and `theia nls-extract` reports what the source declares
|
|
78
|
+
rather than whether a catalogue matches it.
|
|
79
|
+
|
|
80
|
+
`@hydranium/protocol/testing` ships the audit for it — call it from your own
|
|
81
|
+
test, over your own barrels:
|
|
82
|
+
|
|
83
|
+
<!-- snippet-preamble
|
|
84
|
+
import { flattenCatalogue, findUndeclaredCodes, findSharedCodes } from '@hydranium/protocol/testing';
|
|
85
|
+
import * as protocolMessages from '@hydranium/protocol';
|
|
86
|
+
declare const readFileSync: (path: string, encoding: string) => string;
|
|
87
|
+
declare const expect: (actual: unknown) => { toEqual(expected: unknown): void };
|
|
88
|
+
-->
|
|
89
|
+
|
|
90
|
+
```ts
|
|
91
|
+
const keys = Object.keys(flattenCatalogue(JSON.parse(readFileSync('nls/de.json', 'utf-8'))));
|
|
92
|
+
|
|
93
|
+
// Every key names a code some barrel declares. `exemptPrefixes` is for keys no
|
|
94
|
+
// barrel CAN declare — a host mechanism taking its key as an inline literal.
|
|
95
|
+
expect(findUndeclaredCodes(keys, [protocolMessages])).toEqual([]);
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
`flattenCatalogue` joins nested keys with `/` (the separator a code already
|
|
99
|
+
uses, and what Theia does to a nested catalogue) and drops `_`-prefixed note
|
|
100
|
+
keys, so a flat server-side catalogue and a nested host-side one both go through
|
|
101
|
+
it. `findSharedCodes` covers the other half: exactly one side renders a given
|
|
102
|
+
message, so two catalogues holding one code are two authorities over one
|
|
103
|
+
sentence — assert both key sets non-empty first, since an empty one satisfies
|
|
104
|
+
disjointness while proving nothing.
|
|
105
|
+
|
|
72
106
|
## Status
|
|
73
107
|
|
|
74
108
|
Alpha — pre-v0. The package is being populated incrementally, and its API is
|
|
@@ -8,12 +8,18 @@
|
|
|
8
8
|
********************************************************************************/
|
|
9
9
|
import { ResponseError } from 'vscode-jsonrpc';
|
|
10
10
|
/**
|
|
11
|
-
* The framework externalizes user-facing strings and
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
11
|
+
* The framework externalizes user-facing strings and SELECTS no locale: it
|
|
12
|
+
* relays the one its client declared and renders with whatever templates the
|
|
13
|
+
* adopter installed, defaulting to its English. Every such string carries a
|
|
14
|
+
* stable code beside that English, and exactly one side renders it — the side
|
|
15
|
+
* that knows the reading user's language.
|
|
16
|
+
*
|
|
17
|
+
* Which side that is depends on the message, not on the package. A server
|
|
18
|
+
* message is rendered by the server, at the one seam every carrier passes
|
|
19
|
+
* through, in the locale it was handed at init. A message the client tier raises
|
|
20
|
+
* is rendered there, because those fire when the server is unreachable. Nothing
|
|
21
|
+
* is rendered twice: two renders of one sentence are two authorities over it,
|
|
22
|
+
* and they diverge on the first reword.
|
|
17
23
|
*
|
|
18
24
|
* Codes are `hydranium/<unscoped-package>/<name>`. The package segment locates
|
|
19
25
|
* the declaration, so a message is declared in the package that raises it and a
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"primitives.d.ts","sourceRoot":"","sources":["../../src/messages/primitives.ts"],"names":[],"mappings":"AAAA;;;;;;;kFAOkF;AAElF,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAE/C
|
|
1
|
+
{"version":3,"file":"primitives.d.ts","sourceRoot":"","sources":["../../src/messages/primitives.ts"],"names":[],"mappings":"AAAA;;;;;;;kFAOkF;AAElF,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAE/C;;;;;;;;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E,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,CAG9G;AAED,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,aAAa,CAAC,OAAO,CAAC,GAAG,eAAe,GAAG,SAAS,CAEpG;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAEpD;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,iBAAiB,CAAC,MAAM,CAAC,CASvF;AAED;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,iBAAiB,CAAC,MAAM,CAAC,EAAE,CAE3E"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"primitives.js","sourceRoot":"","sources":["../../src/messages/primitives.ts"],"names":[],"mappings":";AAAA;;;;;;;kFAOkF;;
|
|
1
|
+
{"version":3,"file":"primitives.js","sourceRoot":"","sources":["../../src/messages/primitives.ts"],"names":[],"mappings":";AAAA;;;;;;;kFAOkF;;AAwDlF,sCAGC;AAeD,kCASC;AAoBD,kCAEC;AAOD,0BAEC;AASD,gDAUC;AAeD,oCAMC;AAOD,wDAGC;AAED,8DAEC;AAQD,sCAEC;AAOD,oDASC;AAWD,0CAEC;AA7MD,mDAA+C;AAgD/C;;;;;GAKG;AACH,SAAgB,aAAa,CAAmB,IAAY,EAAE,IAAoB;IAC/E,MAAM,OAAO,GAAG,IAAS,CAAC;IAC1B,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,GAAG,IAAI,EAAE,EAAE,CAAC,WAAW,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,EAAE,CAAC;AAC5F,CAAC;AAED,MAAM,WAAW,GAAG,cAAc,CAAC;AAEnC;;;;;;;;;;GAUG;AACH,SAAgB,WAAW,CAAC,QAAgB,EAAE,MA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AC;IACvF,OAAO,CACJ,OAAO,SAAS,KAAK,QAAQ;QAC7B,SAAS,KAAK,IAAI;QAClB,OAAO,SAAS,CAAC,IAAI,KAAK,QAAQ;QAClC,OAAO,SAAS,CAAC,IAAI,KAAK,QAAQ;QAClC,OAAO,SAAS,CAAC,MAAM,KAAK,UAAU,CACxC,CAAC;AACL,CAAC;AAED;;;;;;;;GAQG;AACH,SAAgB,eAAe,CAAC,MAAc;IAC3C,OAAQ,MAAM,CAAC,MAAM,CAAC,MAAM,CAAe,CAAC,MAAM,CAAC,oBAAoB,CAAC,CAAC;AAC5E,CAAC"}
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*
|
|
7
7
|
* SPDX-License-Identifier: MIT
|
|
8
8
|
********************************************************************************/
|
|
9
|
-
import type
|
|
9
|
+
import { ResponseError, type MessageConnection } from 'vscode-jsonrpc';
|
|
10
10
|
import type { LatencyCollector } from '../latency-collector';
|
|
11
11
|
import { type Disposable } from '../util';
|
|
12
12
|
/**
|
|
@@ -62,6 +62,30 @@ export interface BindRpcMethodsOptions {
|
|
|
62
62
|
* Requests and notifications are both timed. Absent by default (no overhead).
|
|
63
63
|
*/
|
|
64
64
|
readonly latency?: LatencyCollector;
|
|
65
|
+
/**
|
|
66
|
+
* Produce the `message` an outgoing rejection carries, so a user-facing
|
|
67
|
+
* error is rendered by the side that knows the reading user's language.
|
|
68
|
+
* Applied at this one chokepoint, which is what covers a caller's
|
|
69
|
+
* additional methods as well as the framework's own.
|
|
70
|
+
*
|
|
71
|
+
* Only a `ResponseError` is routed through it — a plain `Error` carries no
|
|
72
|
+
* identity to render from, and rewriting its message would relabel a
|
|
73
|
+
* developer-facing failure as a translated one. The rejection is
|
|
74
|
+
* RECONSTRUCTED rather than mutated, because the thrown value may be a
|
|
75
|
+
* shared constant; nothing is lost, since only `code`, `message` and `data`
|
|
76
|
+
* cross the wire and `instanceof` does not survive reconstruction anyway.
|
|
77
|
+
*
|
|
78
|
+
* Notifications are not covered, and "they have no reply channel" is only
|
|
79
|
+
* half the reason — a notification's own PAYLOAD can carry prose. What makes
|
|
80
|
+
* this sound is where that prose comes from: the only user-facing text on
|
|
81
|
+
* the data head's client surface is the diagnostics riding the
|
|
82
|
+
* document-updated and document-saved events, and those are read off
|
|
83
|
+
* `LangiumDocument.diagnostics`, which the document builder has already
|
|
84
|
+
* rendered at `Validated`. So they arrive rendered rather than escaping
|
|
85
|
+
* unrendered. A notification that ever carries prose of its OWN needs its
|
|
86
|
+
* own render at the raise site, as GLSP's actions do.
|
|
87
|
+
*/
|
|
88
|
+
readonly renderErrorMessage?: (error: ResponseError<unknown>) => string;
|
|
65
89
|
}
|
|
66
90
|
/**
|
|
67
91
|
* Register each named method on `target` as a handler on `connection`
|
|
@@ -82,8 +106,10 @@ export interface BindRpcMethodsOptions {
|
|
|
82
106
|
*
|
|
83
107
|
* Errors thrown synchronously from a request handler — or surfaced as a
|
|
84
108
|
* rejected promise — propagate back to the caller through vscode-jsonrpc's
|
|
85
|
-
* standard error envelope
|
|
86
|
-
*
|
|
109
|
+
* standard error envelope, with the message rendered when
|
|
110
|
+
* {@link BindRpcMethodsOptions.renderErrorMessage} is supplied. Errors from a
|
|
111
|
+
* notification handler cannot propagate, and are routed to
|
|
112
|
+
* {@link BindRpcMethodsOptions.onNotificationError} instead.
|
|
87
113
|
*
|
|
88
114
|
* Accepts either a ready connection or a `Promise<MessageConnection>` —
|
|
89
115
|
* registrations queue until the connection resolves, then attach. The
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bind-rpc-methods.d.ts","sourceRoot":"","sources":["../../src/rpc/bind-rpc-methods.ts"],"names":[],"mappings":"AAAA;;;;;;;kFAOkF;AAElF,OAAO,
|
|
1
|
+
{"version":3,"file":"bind-rpc-methods.d.ts","sourceRoot":"","sources":["../../src/rpc/bind-rpc-methods.ts"],"names":[],"mappings":"AAAA;;;;;;;kFAOkF;AAElF,OAAO,EAAE,aAAa,EAAE,KAAK,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACvE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAC7D,OAAO,EAAE,KAAK,UAAU,EAAwB,MAAM,SAAS,CAAC;AAIhE;;;;;;;GAOG;AACH,MAAM,WAAW,qBAAqB;IACnC;;;OAGG;IACH,QAAQ,CAAC,eAAe,CAAC,EAAE,MAAM,CAAC;IAElC;;;;;;OAMG;IACH,QAAQ,CAAC,cAAc,CAAC,EAAE,CAAC,UAAU,EAAE,MAAM,KAAK,OAAO,CAAC;IAE1D;;;;;;;;;OASG;IACH,QAAQ,CAAC,UAAU,CAAC,EAAE,OAAO,CAAC;IAE9B;;;;;;;;;;;OAWG;IACH,QAAQ,CAAC,mBAAmB,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;IAE1E;;;;;OAKG;IACH,QAAQ,CAAC,OAAO,CAAC,EAAE,gBAAgB,CAAC;IAEpC;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACH,QAAQ,CAAC,kBAAkB,CAAC,EAAE,CAAC,KAAK,EAAE,aAAa,CAAC,OAAO,CAAC,KAAK,MAAM,CAAC;CAC1E;AAOD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,wBAAgB,cAAc,CAAC,CAAC,SAAS,MAAM,EAC5C,UAAU,EAAE,iBAAiB,GAAG,OAAO,CAAC,iBAAiB,CAAC,EAC1D,MAAM,EAAE,CAAC,EACT,WAAW,EAAE,SAAS,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC,EAAE,EAC1C,OAAO,GAAE,qBAA0B,GACnC,UAAU,CAgFZ"}
|
|
@@ -9,9 +9,14 @@
|
|
|
9
9
|
********************************************************************************/
|
|
10
10
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
11
|
exports.bindRpcMethods = bindRpcMethods;
|
|
12
|
+
const vscode_jsonrpc_1 = require("vscode-jsonrpc");
|
|
12
13
|
const util_1 = require("../util");
|
|
13
14
|
const create_rpc_proxy_1 = require("./create-rpc-proxy");
|
|
14
15
|
const wire_prefix_1 = require("./wire-prefix");
|
|
16
|
+
/** The rejection to throw in place of `err`, with its message rendered. */
|
|
17
|
+
function renderRejection(err, render) {
|
|
18
|
+
return err instanceof vscode_jsonrpc_1.ResponseError ? new vscode_jsonrpc_1.ResponseError(err.code, render(err), err.data) : err;
|
|
19
|
+
}
|
|
15
20
|
/**
|
|
16
21
|
* Register each named method on `target` as a handler on `connection`
|
|
17
22
|
* under the wire-name `<prefix><methodName>`. Notification methods (by
|
|
@@ -31,8 +36,10 @@ const wire_prefix_1 = require("./wire-prefix");
|
|
|
31
36
|
*
|
|
32
37
|
* Errors thrown synchronously from a request handler — or surfaced as a
|
|
33
38
|
* rejected promise — propagate back to the caller through vscode-jsonrpc's
|
|
34
|
-
* standard error envelope
|
|
35
|
-
*
|
|
39
|
+
* standard error envelope, with the message rendered when
|
|
40
|
+
* {@link BindRpcMethodsOptions.renderErrorMessage} is supplied. Errors from a
|
|
41
|
+
* notification handler cannot propagate, and are routed to
|
|
42
|
+
* {@link BindRpcMethodsOptions.onNotificationError} instead.
|
|
36
43
|
*
|
|
37
44
|
* Accepts either a ready connection or a `Promise<MessageConnection>` —
|
|
38
45
|
* registrations queue until the connection resolves, then attach. The
|
|
@@ -84,7 +91,19 @@ function bindRpcMethods(connection, target, methodNames, options = {}) {
|
|
|
84
91
|
}));
|
|
85
92
|
}
|
|
86
93
|
else {
|
|
87
|
-
|
|
94
|
+
const render = options.renderErrorMessage;
|
|
95
|
+
disposables.push(resolved.onRequest(wireName, async (params) => {
|
|
96
|
+
if (!render) {
|
|
97
|
+
return dispatch(params);
|
|
98
|
+
}
|
|
99
|
+
try {
|
|
100
|
+
// Awaited inside the try, or a rejected promise escapes it.
|
|
101
|
+
return await dispatch(params);
|
|
102
|
+
}
|
|
103
|
+
catch (err) {
|
|
104
|
+
throw renderRejection(err, render);
|
|
105
|
+
}
|
|
106
|
+
}));
|
|
88
107
|
}
|
|
89
108
|
}
|
|
90
109
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bind-rpc-methods.js","sourceRoot":"","sources":["../../src/rpc/bind-rpc-methods.ts"],"names":[],"mappings":";AAAA;;;;;;;kFAOkF;;
|
|
1
|
+
{"version":3,"file":"bind-rpc-methods.js","sourceRoot":"","sources":["../../src/rpc/bind-rpc-methods.ts"],"names":[],"mappings":";AAAA;;;;;;;kFAOkF;;AAoIlF,wCAqFC;AAvND,mDAAuE;AAEvE,kCAAgE;AAChE,yDAA2D;AAC3D,+CAA2D;AAsF3D,2EAA2E;AAC3E,SAAS,eAAe,CAAC,GAAY,EAAE,MAAiD;IACrF,OAAO,GAAG,YAAY,8BAAa,CAAC,CAAC,CAAC,IAAI,8BAAa,CAAC,GAAG,CAAC,IAAI,EAAE,MAAM,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;AAClG,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,SAAgB,cAAc,CAC3B,UAA0D,EAC1D,MAAS,EACT,WAA0C,EAC1C,UAAiC,EAAE;IAEnC,MAAM,eAAe,GAAG,OAAO,CAAC,eAAe,IAAI,EAAE,CAAC;IACtD,IAAA,wCAA0B,EAAC,eAAe,EAAE,gBAAgB,CAAC,CAAC;IAC9D,MAAM,cAAc,GAAG,OAAO,CAAC,cAAc,IAAI,wCAAqB,CAAC;IACvE,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,IAAI,IAAI,CAAC;IAC9C,MAAM,mBAAmB,GACtB,OAAO,CAAC,mBAAmB;QAC3B,CAAC,CAAC,QAAgB,EAAE,KAAc,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,0CAA0C,QAAQ,UAAU,EAAE,KAAK,CAAC,CAAC,CAAC;IAC9H,MAAM,WAAW,GAAG,IAAI,2BA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AG,OAAO,CAAC,kBAAkB,CAAC;gBAC1C,WAAW,CAAC,IAAI,CACb,QAAQ,CAAC,SAAS,CAAC,QAAQ,EAAE,KAAK,EAAE,MAAe,EAAE,EAAE;oBACpD,IAAI,CAAC,MAAM,EAAE,CAAC;wBACX,OAAO,QAAQ,CAAC,MAAM,CAAC,CAAC;oBAC3B,CAAC;oBACD,IAAI,CAAC;wBACF,4DAA4D;wBAC5D,OAAO,MAAM,QAAQ,CAAC,MAAM,CAAC,CAAC;oBACjC,CAAC;oBAAC,OAAO,GAAY,EAAE,CAAC;wBACrB,MAAM,eAAe,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;oBACtC,CAAC;gBACJ,CAAC,CAAC,CACJ,CAAC;YACL,CAAC;QACJ,CAAC;IACJ,CAAC,CAAC;IAEF,IAAI,UAAU,YAAY,OAAO,EAAE,CAAC;QACjC,KAAK,UAAU;aACX,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;aAClC,KAAK,CAAC,GAAG,EAAE;YACT,iEAAiE;YACjE,iEAAiE;YACjE,8CAA8C;QACjD,CAAC,CAAC,CAAC;IACT,CAAC;SAAM,CAAC;QACL,MAAM,CAAC,UAAU,CAAC,CAAC;IACtB,CAAC;IAED,OAAO;QACJ,OAAO;YACJ,SAAS,GAAG,IAAI,CAAC;YACjB,WAAW,CAAC,OAAO,EAAE,CAAC;QACzB,CAAC;KACH,CAAC;AACL,CAAC"}
|
|
@@ -127,6 +127,13 @@ export interface CreateRpcProxyOptions<TLocal extends object = never> {
|
|
|
127
127
|
* `bindRpcMethods` call) still capture per-method latency. Absent by default.
|
|
128
128
|
*/
|
|
129
129
|
readonly latency?: BindRpcMethodsOptions['latency'];
|
|
130
|
+
/**
|
|
131
|
+
* Forwarded to the inbound {@link localTarget} binding: renders the message
|
|
132
|
+
* an outgoing rejection carries. Only the inbound direction has rejections
|
|
133
|
+
* to render — the outbound proxy is this side making requests, and a
|
|
134
|
+
* rejection it receives was rendered by whoever answered.
|
|
135
|
+
*/
|
|
136
|
+
readonly renderErrorMessage?: BindRpcMethodsOptions['renderErrorMessage'];
|
|
130
137
|
}
|
|
131
138
|
/**
|
|
132
139
|
* Default notification discriminator — `on`-followed-by-an-uppercase-letter
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-rpc-proxy.d.ts","sourceRoot":"","sources":["../../src/rpc/create-rpc-proxy.ts"],"names":[],"mappings":"AAAA;;;;;;;kFAOkF;AAElF,OAAO,EAAW,KAAK,KAAK,EAAE,KAAK,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAC7E,OAAO,EAAE,KAAK,qBAAqB,EAAkB,MAAM,oBAAoB,CAAC;AAGhF;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,WAAW,iBAAiB;IAC/B;;;;;;;;;;OAUG;IACH,QAAQ,CAAC,mBAAmB,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC;IAC1C;;;;OAIG;IACH,QAAQ,CAAC,oBAAoB,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC;CAC7C;AAED,qEAAqE;AACrE,MAAM,MAAM,QAAQ,CAAC,CAAC,SAAS,MAAM,IAAI,CAAC,GAAG,iBAAiB,CAAC;AAE/D;;;;;;;;GAQG;AACH,MAAM,WAAW,qBAAqB,CAAC,MAAM,SAAS,MAAM,GAAG,KAAK;IACjE;;;;;;;;;;OAUG;IACH,QAAQ,CAAC,eAAe,CAAC,EAAE,MAAM,CAAC;IAElC;;;;;;;;;;;;;OAaG;IACH,QAAQ,CAAC,cAAc,CAAC,EAAE,CAAC,UAAU,EAAE,MAAM,KAAK,OAAO,CAAC;IAE1D;;;;;;;;;;;;;OAaG;IACH,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAE9B;;;;;;;;;OASG;IACH,QAAQ,CAAC,YAAY,CAAC,EAAE,SAAS,CAAC,MAAM,MAAM,GAAG,MAAM,CAAC,EAAE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;;;OAKG;IACH,QAAQ,CAAC,kBAAkB,CAAC,EAAE,qBAAqB,CAAC,oBAAoB,CAAC,CAAC;CAC5E;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,qBAAqB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAEjE;AAiBD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,wBAAgB,cAAc,CAAC,CAAC,SAAS,MAAM,EAAE,MAAM,SAAS,MAAM,GAAG,KAAK,EAC3E,UAAU,EAAE,iBAAiB,GAAG,OAAO,CAAC,iBAAiB,CAAC,EAC1D,OAAO,GAAE,qBAAqB,CAAC,MAAM,CAAM,GAC3C,QAAQ,CAAC,CAAC,CAAC,CA+Eb"}
|
|
@@ -92,7 +92,12 @@ function createRpcProxy(connection, options = {}) {
|
|
|
92
92
|
// connection; see `localTarget` for why no `Disposable` is surfaced.
|
|
93
93
|
const { localTarget, localMethods } = options;
|
|
94
94
|
if (localTarget && localMethods && localMethods.length > 0) {
|
|
95
|
-
const binding = (0, bind_rpc_methods_1.bindRpcMethods)(connection, localTarget, localMethods, {
|
|
95
|
+
const binding = (0, bind_rpc_methods_1.bindRpcMethods)(connection, localTarget, localMethods, {
|
|
96
|
+
methodNamespace,
|
|
97
|
+
isNotification,
|
|
98
|
+
latency: options.latency,
|
|
99
|
+
renderErrorMessage: options.renderErrorMessage
|
|
100
|
+
});
|
|
96
101
|
resolvedConnection.then(conn => conn.onClose(() => binding.dispose())).catch(() => undefined);
|
|
97
102
|
}
|
|
98
103
|
const onDidOpenConnectionEmitter = new vscode_jsonrpc_1.Emitter();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-rpc-proxy.js","sourceRoot":"","sources":["../../src/rpc/create-rpc-proxy.ts"],"names":[],"mappings":";AAAA;;;;;;;kFAOkF;;
|
|
1
|
+
{"version":3,"file":"create-rpc-proxy.js","sourceRoot":"","sources":["../../src/rpc/create-rpc-proxy.ts"],"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,CAAC,EAAE,CAAC;gBACxB,OAAO,CAAC,GAAG,IAAe,EAAQ,EAAE;oBACjC,eAAe,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;oBAChC,mEAAmE;oBACnE,kEAAkE;oBAClE,gEAAgE;oBAChE,qCAAqC;oBACrC,KAAK,kBAAkB,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC,UAAU,CAAC,gBAAgB,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;gBACrH,CAAC,CAAC;YACL,CAAC;YACD,OAAO,CAAC,GAAG,IAAe,EAAoB,EAAE;gBAC7C,eAAe,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;gBAChC,qEAAqE;gBACrE,qEAAqE;gBACrE,sEAAsE;gBACtE,kEAAkE;gBAClE,4DAA4D;gBAC5D,MAAM,aAAa,GAAG,IAAI,KAAK,CAAC,gBAAgB,QAAQ,UAAU,CAAC,CAAC;gBACpE,OAAO,kBAAkB;qBACrB,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC,UAAU,CAAC,WAAW,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;qBAC7D,KAAK,CAAC,CAAC,GAAY,EAAE,EAAE;oBACrB,IAAI,GAAG,YAAY,KAAK,IAAI,aAAa,CAAC,KAAK,EAAE,CAAC;wBAC/C,GAAG,CAAC,KAAK,GAAG,GAAG,GAAG,CAAC,KAAK,IAAI,GAAG,CAAC,OAAO,8BAA8B,aAAa,CAAC,KAAK,EAAE,CAAC;oBAC9F,CAAC;oBACD,MAAM,GAAG,CAAC;gBACb,CAAC,CAAC,CAAC;YACT,CAAC,CAAC;QACL,CAAC;KACH,CAAgB,CAAC;AACrB,CAAC"}
|
|
@@ -0,0 +1,80 @@
|
|
|
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
|
+
* Audit a translation catalogue against the codes that actually exist.
|
|
11
|
+
*
|
|
12
|
+
* **The one failure mode a catalogue has, and the only one nothing else
|
|
13
|
+
* catches.** A key naming no declared code falls back to the English — which is
|
|
14
|
+
* byte-identical to a deliberate omission, so a typo is invisible at runtime and
|
|
15
|
+
* indistinguishable from the partial-catalogue behaviour every adopter relies
|
|
16
|
+
* on. Nothing on the render path can tell them apart, `theia nls-extract`
|
|
17
|
+
* reports what the SOURCE declares rather than whether a catalogue matches it,
|
|
18
|
+
* and the framework's own gates see only the framework's own files.
|
|
19
|
+
*
|
|
20
|
+
* Shipped as test support rather than as a runtime check on purpose: an
|
|
21
|
+
* orphaned key is an authoring mistake, and failing a server boot over one would
|
|
22
|
+
* take a running product down for a cosmetic defect.
|
|
23
|
+
*/
|
|
24
|
+
/**
|
|
25
|
+
* Flatten a nested catalogue into the `/`-joined keys a message code is spelled
|
|
26
|
+
* with, dropping `_`-prefixed keys as notes to a human reader.
|
|
27
|
+
*
|
|
28
|
+
* Nesting is a HOST convention, not the framework's: Theia flattens a nested
|
|
29
|
+
* catalogue by joining keys with `/`, which is the separator a code already
|
|
30
|
+
* uses, so an adopter on that host writes the file nested and one handed
|
|
31
|
+
* straight to a `ServerMessageRenderer` writes it flat. Both end up here.
|
|
32
|
+
*
|
|
33
|
+
* `_`-prefixed keys are dropped by PREFIX rather than by matching one literal
|
|
34
|
+
* name, so a second note added to a file cannot silently become a catalogue
|
|
35
|
+
* entry. A code is three `/`-separated segments, so no real entry can begin
|
|
36
|
+
* with `_`.
|
|
37
|
+
*/
|
|
38
|
+
export declare function flattenCatalogue(catalogue: Record<string, unknown>, prefix?: string): Record<string, string>;
|
|
39
|
+
/** Options for {@link findUndeclaredCodes}. */
|
|
40
|
+
export interface CatalogueAuditOptions {
|
|
41
|
+
/**
|
|
42
|
+
* Key prefixes to skip, for entries whose codes are NOT declared through a
|
|
43
|
+
* `defineMessage` barrel.
|
|
44
|
+
*
|
|
45
|
+
* The real case is a host's own mechanism: Theia's `nls.localize` takes its
|
|
46
|
+
* key as an inline literal at the call site, so those keys exist only in
|
|
47
|
+
* source text and no barrel can enumerate them. Keep this as narrow as the
|
|
48
|
+
* host layer actually is — exempting a namespace is exempting every typo in
|
|
49
|
+
* it, which is what this function exists to find.
|
|
50
|
+
*/
|
|
51
|
+
readonly exemptPrefixes?: readonly string[];
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Every catalogue key that names no code any of `barrels` declares.
|
|
55
|
+
*
|
|
56
|
+
* Barrels are taken as opaque objects and read with {@link collectMessages},
|
|
57
|
+
* which is what lets a caller pass a `import * as messages` namespace directly:
|
|
58
|
+
* a barrel's value type is a union of its declarations AND its functions, and
|
|
59
|
+
* filtering that union will not narrow to a `MessageDefinition`.
|
|
60
|
+
*
|
|
61
|
+
* Returns the offending keys rather than a boolean, so a failing assertion names
|
|
62
|
+
* WHICH key is wrong — a count says only that something is.
|
|
63
|
+
*/
|
|
64
|
+
export declare function findUndeclaredCodes(catalogueKeys: readonly string[], barrels: readonly object[], options?: CatalogueAuditOptions): string[];
|
|
65
|
+
/**
|
|
66
|
+
* Keys present in more than one catalogue — the shape a split catalogue rots
|
|
67
|
+
* into.
|
|
68
|
+
*
|
|
69
|
+
* Exactly one side renders a given message, so two catalogues holding one code
|
|
70
|
+
* are two authorities over one sentence and they diverge on the first reword.
|
|
71
|
+
* Nothing at runtime notices: both sides render, and whichever ran last wins on
|
|
72
|
+
* its own surface.
|
|
73
|
+
*
|
|
74
|
+
* Takes the key sets rather than a boolean answer for the same reason as
|
|
75
|
+
* {@link findUndeclaredCodes}, and reports NOTHING when a set is empty — an
|
|
76
|
+
* empty catalogue shares no key with anything, so a caller must assert
|
|
77
|
+
* non-emptiness separately or a failed read passes this vacuously.
|
|
78
|
+
*/
|
|
79
|
+
export declare function findSharedCodes(first: readonly string[], second: readonly string[]): string[];
|
|
80
|
+
//# sourceMappingURL=catalogue-audit.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"catalogue-audit.d.ts","sourceRoot":"","sources":["../../src/testing/catalogue-audit.ts"],"names":[],"mappings":"AAAA;;;;;;;kFAOkF;AAIlF;;;;;;;;;;;;;;GAcG;AAEH;;;;;;;;;;;;;GAaG;AACH,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,SAAK,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAcxG;AAED,+CAA+C;AAC/C,MAAM,WAAW,qBAAqB;IACnC;;;;;;;;;OASG;IACH,QAAQ,CAAC,cAAc,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CAC9C;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,mBAAmB,CAChC,aAAa,EAAE,SAAS,MAAM,EAAE,EAChC,OAAO,EAAE,SAAS,MAAM,EAAE,EAC1B,OAAO,GAAE,qBAA0B,GACnC,MAAM,EAAE,CAIV;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,EAAE,MAAM,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,EAAE,CAG7F"}
|
|
@@ -0,0 +1,94 @@
|
|
|
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.flattenCatalogue = flattenCatalogue;
|
|
12
|
+
exports.findUndeclaredCodes = findUndeclaredCodes;
|
|
13
|
+
exports.findSharedCodes = findSharedCodes;
|
|
14
|
+
const primitives_1 = require("../messages/primitives");
|
|
15
|
+
/**
|
|
16
|
+
* Audit a translation catalogue against the codes that actually exist.
|
|
17
|
+
*
|
|
18
|
+
* **The one failure mode a catalogue has, and the only one nothing else
|
|
19
|
+
* catches.** A key naming no declared code falls back to the English — which is
|
|
20
|
+
* byte-identical to a deliberate omission, so a typo is invisible at runtime and
|
|
21
|
+
* indistinguishable from the partial-catalogue behaviour every adopter relies
|
|
22
|
+
* on. Nothing on the render path can tell them apart, `theia nls-extract`
|
|
23
|
+
* reports what the SOURCE declares rather than whether a catalogue matches it,
|
|
24
|
+
* and the framework's own gates see only the framework's own files.
|
|
25
|
+
*
|
|
26
|
+
* Shipped as test support rather than as a runtime check on purpose: an
|
|
27
|
+
* orphaned key is an authoring mistake, and failing a server boot over one would
|
|
28
|
+
* take a running product down for a cosmetic defect.
|
|
29
|
+
*/
|
|
30
|
+
/**
|
|
31
|
+
* Flatten a nested catalogue into the `/`-joined keys a message code is spelled
|
|
32
|
+
* with, dropping `_`-prefixed keys as notes to a human reader.
|
|
33
|
+
*
|
|
34
|
+
* Nesting is a HOST convention, not the framework's: Theia flattens a nested
|
|
35
|
+
* catalogue by joining keys with `/`, which is the separator a code already
|
|
36
|
+
* uses, so an adopter on that host writes the file nested and one handed
|
|
37
|
+
* straight to a `ServerMessageRenderer` writes it flat. Both end up here.
|
|
38
|
+
*
|
|
39
|
+
* `_`-prefixed keys are dropped by PREFIX rather than by matching one literal
|
|
40
|
+
* name, so a second note added to a file cannot silently become a catalogue
|
|
41
|
+
* entry. A code is three `/`-separated segments, so no real entry can begin
|
|
42
|
+
* with `_`.
|
|
43
|
+
*/
|
|
44
|
+
function flattenCatalogue(catalogue, prefix = '') {
|
|
45
|
+
const flat = {};
|
|
46
|
+
for (const [key, value] of Object.entries(catalogue)) {
|
|
47
|
+
if (key.startsWith('_')) {
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
const joined = prefix ? `${prefix}/${key}` : key;
|
|
51
|
+
if (typeof value === 'string') {
|
|
52
|
+
flat[joined] = value;
|
|
53
|
+
}
|
|
54
|
+
else if (typeof value === 'object' && value !== null) {
|
|
55
|
+
Object.assign(flat, flattenCatalogue(value, joined));
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return flat;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Every catalogue key that names no code any of `barrels` declares.
|
|
62
|
+
*
|
|
63
|
+
* Barrels are taken as opaque objects and read with {@link collectMessages},
|
|
64
|
+
* which is what lets a caller pass a `import * as messages` namespace directly:
|
|
65
|
+
* a barrel's value type is a union of its declarations AND its functions, and
|
|
66
|
+
* filtering that union will not narrow to a `MessageDefinition`.
|
|
67
|
+
*
|
|
68
|
+
* Returns the offending keys rather than a boolean, so a failing assertion names
|
|
69
|
+
* WHICH key is wrong — a count says only that something is.
|
|
70
|
+
*/
|
|
71
|
+
function findUndeclaredCodes(catalogueKeys, barrels, options = {}) {
|
|
72
|
+
const declared = new Set(barrels.flatMap(barrel => (0, primitives_1.collectMessages)(barrel).map(message => message.code)));
|
|
73
|
+
const exempt = options.exemptPrefixes ?? [];
|
|
74
|
+
return catalogueKeys.filter(key => !exempt.some(prefix => key.startsWith(prefix)) && !declared.has(key));
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Keys present in more than one catalogue — the shape a split catalogue rots
|
|
78
|
+
* into.
|
|
79
|
+
*
|
|
80
|
+
* Exactly one side renders a given message, so two catalogues holding one code
|
|
81
|
+
* are two authorities over one sentence and they diverge on the first reword.
|
|
82
|
+
* Nothing at runtime notices: both sides render, and whichever ran last wins on
|
|
83
|
+
* its own surface.
|
|
84
|
+
*
|
|
85
|
+
* Takes the key sets rather than a boolean answer for the same reason as
|
|
86
|
+
* {@link findUndeclaredCodes}, and reports NOTHING when a set is empty — an
|
|
87
|
+
* empty catalogue shares no key with anything, so a caller must assert
|
|
88
|
+
* non-emptiness separately or a failed read passes this vacuously.
|
|
89
|
+
*/
|
|
90
|
+
function findSharedCodes(first, second) {
|
|
91
|
+
const other = new Set(second);
|
|
92
|
+
return first.filter(key => other.has(key));
|
|
93
|
+
}
|
|
94
|
+
//# sourceMappingURL=catalogue-audit.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"catalogue-audit.js","sourceRoot":"","sources":["../../src/testing/catalogue-audit.ts"],"names":[],"mappings":";AAAA;;;;;;;kFAOkF;;AAkClF,4CAcC;AA4BD,kDAQC;AAgBD,0CAGC;AArGD,uDAAyD;AAEzD;;;;;;;;;;;;;;GAcG;AAEH;;;;;;;;;;;;;GAaG;AACH,SAAgB,gBAAgB,CAAC,SAAkC,EAAE,MAAM,GAAG,EAAE;IAC7E,MAAM,IAAI,GAA2B,EAAE,CAAC;IACxC,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,CAAC;QACpD,IAAI,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;YACvB,SAAS;QACZ,CAAC;QACD,MAAM,MAAM,GAAG,MAAM,CAAC,CAAC,CAAC,GAAG,MAAM,IAAI,GAAG,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC;QACjD,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;YAC7B,IAAI,CAAC,MAAM,CAAC,GAAG,KAAK,CAAC;QACxB,CAAC;aAAM,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;YACtD,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,gBAAgB,CAAC,KAAgC,EAAE,MAAM,CAAC,CAAC,CAAC;QACnF,CAAC;IACJ,CAAC;IACD,OAAO,IAAI,CAAC;AACf,CAAC;AAiBD;;;;;;;;;;GAUG;AACH,SAAgB,mBAAmB,CAChC,aAAgC,EAChC,OAA0B,EAC1B,UAAiC,EAAE;IAEnC,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,IAAA,4BAAe,EAAC,MAAM,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAC1G,MAAM,MAAM,GAAG,OAAO,CAAC,cAAc,IAAI,EAAE,CAAC;IAC5C,OAAO,aAAa,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,GAAG,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;AAC5G,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,SAAgB,eAAe,CAAC,KAAwB,EAAE,MAAyB;IAChF,MAAM,KAAK,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,CAAC;IAC9B,OAAO,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;AAC9C,CAAC"}
|
package/lib/testing/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/testing/index.ts"],"names":[],"mappings":"AAAA;;;;;;;kFAOkF;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/testing/index.ts"],"names":[],"mappings":"AAAA;;;;;;;kFAOkF;AAiBlF,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC"}
|
package/lib/testing/index.js
CHANGED
|
@@ -25,7 +25,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
25
25
|
// Subpath barrel for `@hydranium/protocol/testing` — the BROWSER-NEUTRAL shared
|
|
26
26
|
// primitives: `makeFakeClock` (deterministic `Clock` double on one virtual time
|
|
27
27
|
// axis), `waitFor` / `tick`, the client-side data-head doubles
|
|
28
|
-
// (`makeFakeDataPort` / `makeCapturingDataClient`),
|
|
28
|
+
// (`makeFakeDataPort` / `makeCapturingDataClient`), the translation-catalogue
|
|
29
|
+
// audit (`flattenCatalogue` / `findUndeclaredCodes` / `findSharedCodes`), and
|
|
30
|
+
// the `Harness` marker
|
|
29
31
|
// interface every framework harness extends. Kept out of the main barrel so production bundles don't pull
|
|
30
32
|
// the test scaffolding in by default; adopters opt in by importing from
|
|
31
33
|
// `@hydranium/protocol/testing`.
|
|
@@ -34,6 +36,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
34
36
|
// duplex transports are NOT here: a `PassThrough` pair is in their exported
|
|
35
37
|
// type, so they cannot be made portable and live at `./testing/node` instead.
|
|
36
38
|
// The same rule the package surface uses — the portable name is the short one.
|
|
39
|
+
__exportStar(require("./catalogue-audit"), exports);
|
|
37
40
|
__exportStar(require("./data-doubles"), exports);
|
|
38
41
|
__exportStar(require("./fake-clock"), exports);
|
|
39
42
|
__exportStar(require("./harness"), exports);
|
package/lib/testing/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/testing/index.ts"],"names":[],"mappings":";AAAA;;;;;;;kFAOkF;;;;;;;;;;;;;;;;AAElF,gFAAgF;AAChF,gFAAgF;AAChF,+DAA+D;AAC/D,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/testing/index.ts"],"names":[],"mappings":";AAAA;;;;;;;kFAOkF;;;;;;;;;;;;;;;;AAElF,gFAAgF;AAChF,gFAAgF;AAChF,+DAA+D;AAC/D,8EAA8E;AAC9E,8EAA8E;AAC9E,uBAAuB;AACvB,0GAA0G;AAC1G,wEAAwE;AACxE,iCAAiC;AACjC,EAAE;AACF,8EAA8E;AAC9E,4EAA4E;AAC5E,8EAA8E;AAC9E,+EAA+E;AAE/E,oDAAkC;AAClC,iDAA+B;AAC/B,+CAA6B;AAC7B,4CAA0B;AAC1B,6CAA2B"}
|
package/package.json
CHANGED
|
@@ -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
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* SPDX-License-Identifier: MIT
|
|
8
8
|
********************************************************************************/
|
|
9
9
|
|
|
10
|
-
import type
|
|
10
|
+
import { ResponseError, type MessageConnection } from 'vscode-jsonrpc';
|
|
11
11
|
import type { LatencyCollector } from '../latency-collector';
|
|
12
12
|
import { type Disposable, DisposableCollection } from '../util';
|
|
13
13
|
import { defaultIsNotification } from './create-rpc-proxy';
|
|
@@ -70,6 +70,36 @@ export interface BindRpcMethodsOptions {
|
|
|
70
70
|
* Requests and notifications are both timed. Absent by default (no overhead).
|
|
71
71
|
*/
|
|
72
72
|
readonly latency?: LatencyCollector;
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Produce the `message` an outgoing rejection carries, so a user-facing
|
|
76
|
+
* error is rendered by the side that knows the reading user's language.
|
|
77
|
+
* Applied at this one chokepoint, which is what covers a caller's
|
|
78
|
+
* additional methods as well as the framework's own.
|
|
79
|
+
*
|
|
80
|
+
* Only a `ResponseError` is routed through it — a plain `Error` carries no
|
|
81
|
+
* identity to render from, and rewriting its message would relabel a
|
|
82
|
+
* developer-facing failure as a translated one. The rejection is
|
|
83
|
+
* RECONSTRUCTED rather than mutated, because the thrown value may be a
|
|
84
|
+
* shared constant; nothing is lost, since only `code`, `message` and `data`
|
|
85
|
+
* cross the wire and `instanceof` does not survive reconstruction anyway.
|
|
86
|
+
*
|
|
87
|
+
* Notifications are not covered, and "they have no reply channel" is only
|
|
88
|
+
* half the reason — a notification's own PAYLOAD can carry prose. What makes
|
|
89
|
+
* this sound is where that prose comes from: the only user-facing text on
|
|
90
|
+
* the data head's client surface is the diagnostics riding the
|
|
91
|
+
* document-updated and document-saved events, and those are read off
|
|
92
|
+
* `LangiumDocument.diagnostics`, which the document builder has already
|
|
93
|
+
* rendered at `Validated`. So they arrive rendered rather than escaping
|
|
94
|
+
* unrendered. A notification that ever carries prose of its OWN needs its
|
|
95
|
+
* own render at the raise site, as GLSP's actions do.
|
|
96
|
+
*/
|
|
97
|
+
readonly renderErrorMessage?: (error: ResponseError<unknown>) => string;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** The rejection to throw in place of `err`, with its message rendered. */
|
|
101
|
+
function renderRejection(err: unknown, render: (error: ResponseError<unknown>) => string): unknown {
|
|
102
|
+
return err instanceof ResponseError ? new ResponseError(err.code, render(err), err.data) : err;
|
|
73
103
|
}
|
|
74
104
|
|
|
75
105
|
/**
|
|
@@ -91,8 +121,10 @@ export interface BindRpcMethodsOptions {
|
|
|
91
121
|
*
|
|
92
122
|
* Errors thrown synchronously from a request handler — or surfaced as a
|
|
93
123
|
* rejected promise — propagate back to the caller through vscode-jsonrpc's
|
|
94
|
-
* standard error envelope
|
|
95
|
-
*
|
|
124
|
+
* standard error envelope, with the message rendered when
|
|
125
|
+
* {@link BindRpcMethodsOptions.renderErrorMessage} is supplied. Errors from a
|
|
126
|
+
* notification handler cannot propagate, and are routed to
|
|
127
|
+
* {@link BindRpcMethodsOptions.onNotificationError} instead.
|
|
96
128
|
*
|
|
97
129
|
* Accepts either a ready connection or a `Promise<MessageConnection>` —
|
|
98
130
|
* registrations queue until the connection resolves, then attach. The
|
|
@@ -154,7 +186,20 @@ export function bindRpcMethods<T extends object>(
|
|
|
154
186
|
})
|
|
155
187
|
);
|
|
156
188
|
} else {
|
|
157
|
-
|
|
189
|
+
const render = options.renderErrorMessage;
|
|
190
|
+
disposables.push(
|
|
191
|
+
resolved.onRequest(wireName, async (params: unknown) => {
|
|
192
|
+
if (!render) {
|
|
193
|
+
return dispatch(params);
|
|
194
|
+
}
|
|
195
|
+
try {
|
|
196
|
+
// Awaited inside the try, or a rejected promise escapes it.
|
|
197
|
+
return await dispatch(params);
|
|
198
|
+
} catch (err: unknown) {
|
|
199
|
+
throw renderRejection(err, render);
|
|
200
|
+
}
|
|
201
|
+
})
|
|
202
|
+
);
|
|
158
203
|
}
|
|
159
204
|
}
|
|
160
205
|
};
|
|
@@ -136,6 +136,14 @@ export interface CreateRpcProxyOptions<TLocal extends object = never> {
|
|
|
136
136
|
* `bindRpcMethods` call) still capture per-method latency. Absent by default.
|
|
137
137
|
*/
|
|
138
138
|
readonly latency?: BindRpcMethodsOptions['latency'];
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Forwarded to the inbound {@link localTarget} binding: renders the message
|
|
142
|
+
* an outgoing rejection carries. Only the inbound direction has rejections
|
|
143
|
+
* to render — the outbound proxy is this side making requests, and a
|
|
144
|
+
* rejection it receives was rendered by whoever answered.
|
|
145
|
+
*/
|
|
146
|
+
readonly renderErrorMessage?: BindRpcMethodsOptions['renderErrorMessage'];
|
|
139
147
|
}
|
|
140
148
|
|
|
141
149
|
/**
|
|
@@ -225,7 +233,12 @@ export function createRpcProxy<T extends object, TLocal extends object = never>(
|
|
|
225
233
|
// connection; see `localTarget` for why no `Disposable` is surfaced.
|
|
226
234
|
const { localTarget, localMethods } = options;
|
|
227
235
|
if (localTarget && localMethods && localMethods.length > 0) {
|
|
228
|
-
const binding = bindRpcMethods(connection, localTarget, localMethods, {
|
|
236
|
+
const binding = bindRpcMethods(connection, localTarget, localMethods, {
|
|
237
|
+
methodNamespace,
|
|
238
|
+
isNotification,
|
|
239
|
+
latency: options.latency,
|
|
240
|
+
renderErrorMessage: options.renderErrorMessage
|
|
241
|
+
});
|
|
229
242
|
resolvedConnection.then(conn => conn.onClose(() => binding.dispose())).catch(() => undefined);
|
|
230
243
|
}
|
|
231
244
|
|
|
@@ -0,0 +1,111 @@
|
|
|
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
|
+
import { collectMessages } from '../messages/primitives';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Audit a translation catalogue against the codes that actually exist.
|
|
14
|
+
*
|
|
15
|
+
* **The one failure mode a catalogue has, and the only one nothing else
|
|
16
|
+
* catches.** A key naming no declared code falls back to the English — which is
|
|
17
|
+
* byte-identical to a deliberate omission, so a typo is invisible at runtime and
|
|
18
|
+
* indistinguishable from the partial-catalogue behaviour every adopter relies
|
|
19
|
+
* on. Nothing on the render path can tell them apart, `theia nls-extract`
|
|
20
|
+
* reports what the SOURCE declares rather than whether a catalogue matches it,
|
|
21
|
+
* and the framework's own gates see only the framework's own files.
|
|
22
|
+
*
|
|
23
|
+
* Shipped as test support rather than as a runtime check on purpose: an
|
|
24
|
+
* orphaned key is an authoring mistake, and failing a server boot over one would
|
|
25
|
+
* take a running product down for a cosmetic defect.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Flatten a nested catalogue into the `/`-joined keys a message code is spelled
|
|
30
|
+
* with, dropping `_`-prefixed keys as notes to a human reader.
|
|
31
|
+
*
|
|
32
|
+
* Nesting is a HOST convention, not the framework's: Theia flattens a nested
|
|
33
|
+
* catalogue by joining keys with `/`, which is the separator a code already
|
|
34
|
+
* uses, so an adopter on that host writes the file nested and one handed
|
|
35
|
+
* straight to a `ServerMessageRenderer` writes it flat. Both end up here.
|
|
36
|
+
*
|
|
37
|
+
* `_`-prefixed keys are dropped by PREFIX rather than by matching one literal
|
|
38
|
+
* name, so a second note added to a file cannot silently become a catalogue
|
|
39
|
+
* entry. A code is three `/`-separated segments, so no real entry can begin
|
|
40
|
+
* with `_`.
|
|
41
|
+
*/
|
|
42
|
+
export function flattenCatalogue(catalogue: Record<string, unknown>, prefix = ''): Record<string, string> {
|
|
43
|
+
const flat: Record<string, string> = {};
|
|
44
|
+
for (const [key, value] of Object.entries(catalogue)) {
|
|
45
|
+
if (key.startsWith('_')) {
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
const joined = prefix ? `${prefix}/${key}` : key;
|
|
49
|
+
if (typeof value === 'string') {
|
|
50
|
+
flat[joined] = value;
|
|
51
|
+
} else if (typeof value === 'object' && value !== null) {
|
|
52
|
+
Object.assign(flat, flattenCatalogue(value as Record<string, unknown>, joined));
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return flat;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** Options for {@link findUndeclaredCodes}. */
|
|
59
|
+
export interface CatalogueAuditOptions {
|
|
60
|
+
/**
|
|
61
|
+
* Key prefixes to skip, for entries whose codes are NOT declared through a
|
|
62
|
+
* `defineMessage` barrel.
|
|
63
|
+
*
|
|
64
|
+
* The real case is a host's own mechanism: Theia's `nls.localize` takes its
|
|
65
|
+
* key as an inline literal at the call site, so those keys exist only in
|
|
66
|
+
* source text and no barrel can enumerate them. Keep this as narrow as the
|
|
67
|
+
* host layer actually is — exempting a namespace is exempting every typo in
|
|
68
|
+
* it, which is what this function exists to find.
|
|
69
|
+
*/
|
|
70
|
+
readonly exemptPrefixes?: readonly string[];
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Every catalogue key that names no code any of `barrels` declares.
|
|
75
|
+
*
|
|
76
|
+
* Barrels are taken as opaque objects and read with {@link collectMessages},
|
|
77
|
+
* which is what lets a caller pass a `import * as messages` namespace directly:
|
|
78
|
+
* a barrel's value type is a union of its declarations AND its functions, and
|
|
79
|
+
* filtering that union will not narrow to a `MessageDefinition`.
|
|
80
|
+
*
|
|
81
|
+
* Returns the offending keys rather than a boolean, so a failing assertion names
|
|
82
|
+
* WHICH key is wrong — a count says only that something is.
|
|
83
|
+
*/
|
|
84
|
+
export function findUndeclaredCodes(
|
|
85
|
+
catalogueKeys: readonly string[],
|
|
86
|
+
barrels: readonly object[],
|
|
87
|
+
options: CatalogueAuditOptions = {}
|
|
88
|
+
): string[] {
|
|
89
|
+
const declared = new Set(barrels.flatMap(barrel => collectMessages(barrel).map(message => message.code)));
|
|
90
|
+
const exempt = options.exemptPrefixes ?? [];
|
|
91
|
+
return catalogueKeys.filter(key => !exempt.some(prefix => key.startsWith(prefix)) && !declared.has(key));
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Keys present in more than one catalogue — the shape a split catalogue rots
|
|
96
|
+
* into.
|
|
97
|
+
*
|
|
98
|
+
* Exactly one side renders a given message, so two catalogues holding one code
|
|
99
|
+
* are two authorities over one sentence and they diverge on the first reword.
|
|
100
|
+
* Nothing at runtime notices: both sides render, and whichever ran last wins on
|
|
101
|
+
* its own surface.
|
|
102
|
+
*
|
|
103
|
+
* Takes the key sets rather than a boolean answer for the same reason as
|
|
104
|
+
* {@link findUndeclaredCodes}, and reports NOTHING when a set is empty — an
|
|
105
|
+
* empty catalogue shares no key with anything, so a caller must assert
|
|
106
|
+
* non-emptiness separately or a failed read passes this vacuously.
|
|
107
|
+
*/
|
|
108
|
+
export function findSharedCodes(first: readonly string[], second: readonly string[]): string[] {
|
|
109
|
+
const other = new Set(second);
|
|
110
|
+
return first.filter(key => other.has(key));
|
|
111
|
+
}
|
package/src/testing/index.ts
CHANGED
|
@@ -10,7 +10,9 @@
|
|
|
10
10
|
// Subpath barrel for `@hydranium/protocol/testing` — the BROWSER-NEUTRAL shared
|
|
11
11
|
// primitives: `makeFakeClock` (deterministic `Clock` double on one virtual time
|
|
12
12
|
// axis), `waitFor` / `tick`, the client-side data-head doubles
|
|
13
|
-
// (`makeFakeDataPort` / `makeCapturingDataClient`),
|
|
13
|
+
// (`makeFakeDataPort` / `makeCapturingDataClient`), the translation-catalogue
|
|
14
|
+
// audit (`flattenCatalogue` / `findUndeclaredCodes` / `findSharedCodes`), and
|
|
15
|
+
// the `Harness` marker
|
|
14
16
|
// interface every framework harness extends. Kept out of the main barrel so production bundles don't pull
|
|
15
17
|
// the test scaffolding in by default; adopters opt in by importing from
|
|
16
18
|
// `@hydranium/protocol/testing`.
|
|
@@ -20,6 +22,7 @@
|
|
|
20
22
|
// type, so they cannot be made portable and live at `./testing/node` instead.
|
|
21
23
|
// The same rule the package surface uses — the portable name is the short one.
|
|
22
24
|
|
|
25
|
+
export * from './catalogue-audit';
|
|
23
26
|
export * from './data-doubles';
|
|
24
27
|
export * from './fake-clock';
|
|
25
28
|
export * from './harness';
|