@lspeasy/client 3.0.1 → 3.0.3
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/dist/capability-guard.d.ts +67 -21
- package/dist/capability-guard.d.ts.map +1 -1
- package/dist/capability-guard.js +101 -176
- package/dist/capability-guard.js.map +1 -1
- package/dist/capability-proxy.js.map +1 -1
- package/dist/client.d.ts +215 -13
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +162 -14
- package/dist/client.js.map +1 -1
- package/dist/connection/health.d.ts +40 -0
- package/dist/connection/health.d.ts.map +1 -1
- package/dist/connection/health.js +40 -0
- package/dist/connection/health.js.map +1 -1
- package/dist/connection/heartbeat.d.ts +29 -0
- package/dist/connection/heartbeat.d.ts.map +1 -1
- package/dist/connection/heartbeat.js +29 -0
- package/dist/connection/heartbeat.js.map +1 -1
- package/dist/connection/partial-result-collector.js.map +1 -1
- package/dist/connection/registration-store.js.map +1 -1
- package/dist/connection/types.d.ts +46 -4
- package/dist/connection/types.d.ts.map +1 -1
- package/dist/connection/types.js +11 -3
- package/dist/connection/types.js.map +1 -1
- package/dist/index.d.ts +48 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +48 -1
- package/dist/index.js.map +1 -1
- package/dist/notifications/wait.d.ts +57 -2
- package/dist/notifications/wait.d.ts.map +1 -1
- package/dist/notifications/wait.js +44 -1
- package/dist/notifications/wait.js.map +1 -1
- package/dist/progress.js.map +1 -1
- package/dist/types.d.ts +51 -6
- package/dist/types.d.ts.map +1 -1
- package/dist/validation.d.ts +1 -1
- package/dist/validation.d.ts.map +1 -1
- package/dist/validation.js.map +1 -1
- package/package.json +6 -7
|
@@ -1,13 +1,36 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Capability validation for client requests
|
|
3
3
|
*
|
|
4
|
-
* Ensures clients only send requests/notifications that the server supports
|
|
4
|
+
* Ensures clients only send requests/notifications that the server supports,
|
|
5
|
+
* and only register handlers for methods the client declared support for.
|
|
5
6
|
*/
|
|
6
7
|
import type { ClientCapabilities, ServerCapabilities } from '@lspeasy/core';
|
|
7
8
|
import type { Logger } from '@lspeasy/core';
|
|
8
9
|
/**
|
|
9
|
-
* Validates
|
|
10
|
-
* declared
|
|
10
|
+
* Validates outgoing client requests and notifications against the server's
|
|
11
|
+
* declared capabilities.
|
|
12
|
+
*
|
|
13
|
+
* @remarks
|
|
14
|
+
* Created internally by `LSPClient` after a successful `initialize` handshake.
|
|
15
|
+
* In non-strict mode (default) violations are logged as warnings; in strict
|
|
16
|
+
* mode they throw.
|
|
17
|
+
*
|
|
18
|
+
* @useWhen
|
|
19
|
+
* You are implementing a custom client layer and need the same validation
|
|
20
|
+
* behaviour that `LSPClient` uses. Otherwise this is an internal detail.
|
|
21
|
+
*
|
|
22
|
+
* @see {@link ClientCapabilityGuard} for the companion guard that validates
|
|
23
|
+
* server-to-client handler registrations against client capabilities.
|
|
24
|
+
*
|
|
25
|
+
* @throws Error When `strict` is `true` and a method is not in the known
|
|
26
|
+
* method set or the required server capability has not been declared.
|
|
27
|
+
*
|
|
28
|
+
* @never
|
|
29
|
+
* NEVER construct `CapabilityGuard` before the `initialize` handshake completes.
|
|
30
|
+
* Server capabilities are only known after the `InitializeResult` is received;
|
|
31
|
+
* instantiating the guard too early will treat all methods as unsupported.
|
|
32
|
+
*
|
|
33
|
+
* @category Client
|
|
11
34
|
*/
|
|
12
35
|
export declare class CapabilityGuard {
|
|
13
36
|
private readonly capabilities;
|
|
@@ -15,29 +38,48 @@ export declare class CapabilityGuard {
|
|
|
15
38
|
private readonly strict;
|
|
16
39
|
constructor(capabilities: Partial<ServerCapabilities>, logger: Logger, strict?: boolean);
|
|
17
40
|
/**
|
|
18
|
-
*
|
|
41
|
+
* Returns `true` if the server capability for `method` is declared.
|
|
42
|
+
*
|
|
43
|
+
* @param method - The LSP request method string to check (e.g. `'textDocument/hover'`).
|
|
44
|
+
* @returns `true` if allowed; `false` (non-strict) if the required server capability
|
|
45
|
+
* is missing.
|
|
46
|
+
*
|
|
47
|
+
* @throws Error In strict mode, throws if `method` is unknown or its required
|
|
48
|
+
* server capability has not been declared.
|
|
19
49
|
*
|
|
20
|
-
* @
|
|
21
|
-
* @returns true if allowed, false otherwise
|
|
22
|
-
* @throws Error if strict mode enabled and server capability not declared
|
|
50
|
+
* @see {@link CapabilityGuard} for full class documentation.
|
|
23
51
|
*/
|
|
24
52
|
canSendRequest(method: string): boolean;
|
|
25
53
|
/**
|
|
26
|
-
*
|
|
54
|
+
* Returns `true` if the server capability for `method` is declared.
|
|
27
55
|
*
|
|
28
|
-
* @param method - LSP method
|
|
29
|
-
* @returns true if allowed
|
|
30
|
-
*
|
|
56
|
+
* @param method - The LSP notification method string to check.
|
|
57
|
+
* @returns `true` if allowed; `false` (or throws in strict mode) if the required
|
|
58
|
+
* server capability is missing.
|
|
31
59
|
*/
|
|
32
60
|
canSendNotification(method: string): boolean;
|
|
33
61
|
/**
|
|
34
|
-
*
|
|
62
|
+
* Returns a defensive copy of the server capabilities this guard was built from.
|
|
63
|
+
*
|
|
64
|
+
* @returns A shallow copy of the server capabilities object.
|
|
35
65
|
*/
|
|
36
66
|
getServerCapabilities(): Partial<ServerCapabilities>;
|
|
37
67
|
}
|
|
38
68
|
/**
|
|
39
|
-
* Validates that
|
|
40
|
-
* declared
|
|
69
|
+
* Validates that server-to-client handler registrations are backed by
|
|
70
|
+
* client capabilities declared in the `initialize` request.
|
|
71
|
+
*
|
|
72
|
+
* @remarks
|
|
73
|
+
* Created internally by `LSPClient`. In non-strict mode violations are logged
|
|
74
|
+
* as warnings; in strict mode they throw.
|
|
75
|
+
*
|
|
76
|
+
* @never
|
|
77
|
+
* NEVER register server-to-client handlers for capabilities not declared in
|
|
78
|
+
* the original `initialize` request — the server may send the corresponding
|
|
79
|
+
* requests, but without the capability declaration the client has no contract
|
|
80
|
+
* to handle them, leading to silent failures or unexpected errors.
|
|
81
|
+
*
|
|
82
|
+
* @category Client
|
|
41
83
|
*/
|
|
42
84
|
export declare class ClientCapabilityGuard {
|
|
43
85
|
private readonly capabilities;
|
|
@@ -45,18 +87,22 @@ export declare class ClientCapabilityGuard {
|
|
|
45
87
|
private readonly strict;
|
|
46
88
|
constructor(capabilities: Partial<ClientCapabilities>, logger: Logger, strict?: boolean);
|
|
47
89
|
/**
|
|
48
|
-
*
|
|
90
|
+
* Returns `true` if the client has declared the capability required to handle `method`.
|
|
49
91
|
*
|
|
50
|
-
* @param method - LSP method
|
|
51
|
-
* @returns true if
|
|
52
|
-
*
|
|
92
|
+
* @param method - The LSP method string to validate against client capabilities.
|
|
93
|
+
* @returns `true` if the client capability is declared; `false` (non-strict) if missing.
|
|
94
|
+
*
|
|
95
|
+
* @throws Error In strict mode, throws if `method` is unknown or the required
|
|
96
|
+
* client capability was not declared in the `initialize` request.
|
|
97
|
+
*
|
|
98
|
+
* @see {@link ClientCapabilityGuard} for full class documentation.
|
|
53
99
|
*/
|
|
54
100
|
canRegisterHandler(method: string): boolean;
|
|
55
101
|
/**
|
|
56
|
-
*
|
|
102
|
+
* Returns a defensive copy of the client capabilities this guard was built from.
|
|
103
|
+
*
|
|
104
|
+
* @returns A shallow copy of the client capabilities object.
|
|
57
105
|
*/
|
|
58
106
|
getClientCapabilities(): Partial<ClientCapabilities>;
|
|
59
|
-
private isRequestAllowed;
|
|
60
|
-
private isNotificationAllowed;
|
|
61
107
|
}
|
|
62
108
|
//# sourceMappingURL=capability-guard.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"capability-guard.d.ts","sourceRoot":"","sources":["../src/capability-guard.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"capability-guard.d.ts","sourceRoot":"","sources":["../src/capability-guard.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAC5E,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAa5C;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,qBAAa,eAAe;IAExB,OAAO,CAAC,QAAQ,CAAC,YAAY;IAC7B,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,MAAM;IAHzB,YACmB,YAAY,EAAE,OAAO,CAAC,kBAAkB,CAAC,EACzC,MAAM,EAAE,MAAM,EACd,MAAM,GAAE,OAAe,EACtC;IAEJ;;;;;;;;;;;OAWG;IACH,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAWtC;IAED;;;;;;OAMG;IACH,mBAAmB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAW3C;IAED;;;;OAIG;IACH,qBAAqB,IAAI,OAAO,CAAC,kBAAkB,CAAC,CAEnD;CACF;AAED;;;;;;;;;;;;;;;GAeG;AACH,qBAAa,qBAAqB;IAE9B,OAAO,CAAC,QAAQ,CAAC,YAAY;IAC7B,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,MAAM;IAHzB,YACmB,YAAY,EAAE,OAAO,CAAC,kBAAkB,CAAC,EACzC,MAAM,EAAE,MAAM,EACd,MAAM,GAAE,OAAe,EACtC;IAEJ;;;;;;;;;;OAUG;IACH,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAgB1C;IAED;;;;OAIG;IACH,qBAAqB,IAAI,OAAO,CAAC,kBAAkB,CAAC,CAEnD;CACF"}
|
package/dist/capability-guard.js
CHANGED
|
@@ -1,37 +1,35 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Capability validation for client requests
|
|
3
3
|
*
|
|
4
|
-
* Ensures clients only send requests/notifications that the server supports
|
|
4
|
+
* Ensures clients only send requests/notifications that the server supports,
|
|
5
|
+
* and only register handlers for methods the client declared support for.
|
|
5
6
|
*/
|
|
6
|
-
import {
|
|
7
|
-
function buildMethodSets(capabilityKey) {
|
|
8
|
-
const all = new Set();
|
|
9
|
-
const alwaysAllowed = new Set();
|
|
10
|
-
for (const namespaceDefinitions of Object.values(LSPRequest)) {
|
|
11
|
-
for (const definition of Object.values(namespaceDefinitions)) {
|
|
12
|
-
const entry = definition;
|
|
13
|
-
all.add(entry.Method);
|
|
14
|
-
if (!entry[capabilityKey]) {
|
|
15
|
-
alwaysAllowed.add(entry.Method);
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
for (const namespaceDefinitions of Object.values(LSPNotification)) {
|
|
20
|
-
for (const definition of Object.values(namespaceDefinitions)) {
|
|
21
|
-
const entry = definition;
|
|
22
|
-
all.add(entry.Method);
|
|
23
|
-
if (!entry[capabilityKey]) {
|
|
24
|
-
alwaysAllowed.add(entry.Method);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
return { all, alwaysAllowed };
|
|
29
|
-
}
|
|
30
|
-
const SERVER_METHODS = buildMethodSets('ServerCapability');
|
|
31
|
-
const CLIENT_METHODS = buildMethodSets('ClientCapability');
|
|
7
|
+
import { SERVER_METHODS, CLIENT_METHODS, checkMethod, getClientCapabilityForNotificationMethod, getClientCapabilityForRequestMethod, hasServerCapability, hasClientCapability, getCapabilityForNotificationMethod, getCapabilityForRequestMethod } from '@lspeasy/core';
|
|
32
8
|
/**
|
|
33
|
-
* Validates
|
|
34
|
-
* declared
|
|
9
|
+
* Validates outgoing client requests and notifications against the server's
|
|
10
|
+
* declared capabilities.
|
|
11
|
+
*
|
|
12
|
+
* @remarks
|
|
13
|
+
* Created internally by `LSPClient` after a successful `initialize` handshake.
|
|
14
|
+
* In non-strict mode (default) violations are logged as warnings; in strict
|
|
15
|
+
* mode they throw.
|
|
16
|
+
*
|
|
17
|
+
* @useWhen
|
|
18
|
+
* You are implementing a custom client layer and need the same validation
|
|
19
|
+
* behaviour that `LSPClient` uses. Otherwise this is an internal detail.
|
|
20
|
+
*
|
|
21
|
+
* @see {@link ClientCapabilityGuard} for the companion guard that validates
|
|
22
|
+
* server-to-client handler registrations against client capabilities.
|
|
23
|
+
*
|
|
24
|
+
* @throws Error When `strict` is `true` and a method is not in the known
|
|
25
|
+
* method set or the required server capability has not been declared.
|
|
26
|
+
*
|
|
27
|
+
* @never
|
|
28
|
+
* NEVER construct `CapabilityGuard` before the `initialize` handshake completes.
|
|
29
|
+
* Server capabilities are only known after the `InitializeResult` is received;
|
|
30
|
+
* instantiating the guard too early will treat all methods as unsupported.
|
|
31
|
+
*
|
|
32
|
+
* @category Client
|
|
35
33
|
*/
|
|
36
34
|
export class CapabilityGuard {
|
|
37
35
|
capabilities;
|
|
@@ -43,109 +41,72 @@ export class CapabilityGuard {
|
|
|
43
41
|
this.strict = strict;
|
|
44
42
|
}
|
|
45
43
|
/**
|
|
46
|
-
*
|
|
44
|
+
* Returns `true` if the server capability for `method` is declared.
|
|
45
|
+
*
|
|
46
|
+
* @param method - The LSP request method string to check (e.g. `'textDocument/hover'`).
|
|
47
|
+
* @returns `true` if allowed; `false` (non-strict) if the required server capability
|
|
48
|
+
* is missing.
|
|
47
49
|
*
|
|
48
|
-
* @
|
|
49
|
-
*
|
|
50
|
-
*
|
|
50
|
+
* @throws Error In strict mode, throws if `method` is unknown or its required
|
|
51
|
+
* server capability has not been declared.
|
|
52
|
+
*
|
|
53
|
+
* @see {@link CapabilityGuard} for full class documentation.
|
|
51
54
|
*/
|
|
52
55
|
canSendRequest(method) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
return true;
|
|
64
|
-
}
|
|
65
|
-
// Check if server supports this request method
|
|
66
|
-
const capabilityKey = getCapabilityForRequestMethod(method);
|
|
67
|
-
if (!capabilityKey) {
|
|
68
|
-
// Unknown method - allow in non-strict mode with warning
|
|
69
|
-
if (!this.strict) {
|
|
70
|
-
this.logger.debug(`Unknown request method ${method}, allowing in non-strict mode`);
|
|
71
|
-
return true;
|
|
72
|
-
}
|
|
73
|
-
const error = `Cannot send request for unknown method: ${method}`;
|
|
74
|
-
this.logger.error(error);
|
|
75
|
-
throw new Error(error);
|
|
76
|
-
}
|
|
77
|
-
// Methods marked as 'alwaysOn' don't require explicit capabilities
|
|
78
|
-
if (capabilityKey === 'alwaysOn') {
|
|
79
|
-
return true;
|
|
80
|
-
}
|
|
81
|
-
// Check if server declared this capability
|
|
82
|
-
if (!hasServerCapability(this.capabilities, capabilityKey)) {
|
|
83
|
-
const error = `Cannot send request ${method}: server capability '${capabilityKey}' not declared`;
|
|
84
|
-
this.logger.warn(error);
|
|
85
|
-
if (this.strict) {
|
|
86
|
-
throw new Error(error);
|
|
87
|
-
}
|
|
88
|
-
return false;
|
|
89
|
-
}
|
|
90
|
-
return true;
|
|
56
|
+
return checkMethod({
|
|
57
|
+
method,
|
|
58
|
+
methodSets: SERVER_METHODS,
|
|
59
|
+
getCapabilityKey: (m) => getCapabilityForRequestMethod(m),
|
|
60
|
+
hasCapability: (key) => hasServerCapability(this.capabilities, key),
|
|
61
|
+
actionLabel: 'send request',
|
|
62
|
+
capabilityLabel: 'server capability',
|
|
63
|
+
logger: this.logger,
|
|
64
|
+
strict: this.strict
|
|
65
|
+
});
|
|
91
66
|
}
|
|
92
67
|
/**
|
|
93
|
-
*
|
|
68
|
+
* Returns `true` if the server capability for `method` is declared.
|
|
94
69
|
*
|
|
95
|
-
* @param method - LSP method
|
|
96
|
-
* @returns true if allowed
|
|
97
|
-
*
|
|
70
|
+
* @param method - The LSP notification method string to check.
|
|
71
|
+
* @returns `true` if allowed; `false` (or throws in strict mode) if the required
|
|
72
|
+
* server capability is missing.
|
|
98
73
|
*/
|
|
99
74
|
canSendNotification(method) {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
return true;
|
|
111
|
-
}
|
|
112
|
-
// Check if server supports this notification method
|
|
113
|
-
const capabilityKey = getCapabilityForNotificationMethod(method);
|
|
114
|
-
if (!capabilityKey) {
|
|
115
|
-
// Unknown method - allow in non-strict mode with warning
|
|
116
|
-
if (!this.strict) {
|
|
117
|
-
this.logger.debug(`Unknown notification method ${method}, allowing in non-strict mode`);
|
|
118
|
-
return true;
|
|
119
|
-
}
|
|
120
|
-
const error = `Cannot send notification for unknown method: ${method}`;
|
|
121
|
-
this.logger.error(error);
|
|
122
|
-
throw new Error(error);
|
|
123
|
-
}
|
|
124
|
-
// Methods marked as 'alwaysOn' don't require explicit capabilities
|
|
125
|
-
if (capabilityKey === 'alwaysOn') {
|
|
126
|
-
return true;
|
|
127
|
-
}
|
|
128
|
-
// Check if server declared this capability
|
|
129
|
-
if (!hasServerCapability(this.capabilities, capabilityKey)) {
|
|
130
|
-
const error = `Cannot send notification ${method}: server capability '${capabilityKey}' not declared`;
|
|
131
|
-
this.logger.warn(error);
|
|
132
|
-
if (this.strict) {
|
|
133
|
-
throw new Error(error);
|
|
134
|
-
}
|
|
135
|
-
return false;
|
|
136
|
-
}
|
|
137
|
-
return true;
|
|
75
|
+
return checkMethod({
|
|
76
|
+
method,
|
|
77
|
+
methodSets: SERVER_METHODS,
|
|
78
|
+
getCapabilityKey: (m) => getCapabilityForNotificationMethod(m),
|
|
79
|
+
hasCapability: (key) => hasServerCapability(this.capabilities, key),
|
|
80
|
+
actionLabel: 'send notification',
|
|
81
|
+
capabilityLabel: 'server capability',
|
|
82
|
+
logger: this.logger,
|
|
83
|
+
strict: this.strict
|
|
84
|
+
});
|
|
138
85
|
}
|
|
139
86
|
/**
|
|
140
|
-
*
|
|
87
|
+
* Returns a defensive copy of the server capabilities this guard was built from.
|
|
88
|
+
*
|
|
89
|
+
* @returns A shallow copy of the server capabilities object.
|
|
141
90
|
*/
|
|
142
91
|
getServerCapabilities() {
|
|
143
92
|
return { ...this.capabilities };
|
|
144
93
|
}
|
|
145
94
|
}
|
|
146
95
|
/**
|
|
147
|
-
* Validates that
|
|
148
|
-
* declared
|
|
96
|
+
* Validates that server-to-client handler registrations are backed by
|
|
97
|
+
* client capabilities declared in the `initialize` request.
|
|
98
|
+
*
|
|
99
|
+
* @remarks
|
|
100
|
+
* Created internally by `LSPClient`. In non-strict mode violations are logged
|
|
101
|
+
* as warnings; in strict mode they throw.
|
|
102
|
+
*
|
|
103
|
+
* @never
|
|
104
|
+
* NEVER register server-to-client handlers for capabilities not declared in
|
|
105
|
+
* the original `initialize` request — the server may send the corresponding
|
|
106
|
+
* requests, but without the capability declaration the client has no contract
|
|
107
|
+
* to handle them, leading to silent failures or unexpected errors.
|
|
108
|
+
*
|
|
109
|
+
* @category Client
|
|
149
110
|
*/
|
|
150
111
|
export class ClientCapabilityGuard {
|
|
151
112
|
capabilities;
|
|
@@ -157,74 +118,38 @@ export class ClientCapabilityGuard {
|
|
|
157
118
|
this.strict = strict;
|
|
158
119
|
}
|
|
159
120
|
/**
|
|
160
|
-
*
|
|
121
|
+
* Returns `true` if the client has declared the capability required to handle `method`.
|
|
161
122
|
*
|
|
162
|
-
* @param method - LSP method
|
|
163
|
-
* @returns true if
|
|
164
|
-
*
|
|
123
|
+
* @param method - The LSP method string to validate against client capabilities.
|
|
124
|
+
* @returns `true` if the client capability is declared; `false` (non-strict) if missing.
|
|
125
|
+
*
|
|
126
|
+
* @throws Error In strict mode, throws if `method` is unknown or the required
|
|
127
|
+
* client capability was not declared in the `initialize` request.
|
|
128
|
+
*
|
|
129
|
+
* @see {@link ClientCapabilityGuard} for full class documentation.
|
|
165
130
|
*/
|
|
166
131
|
canRegisterHandler(method) {
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
if (!capabilityKey) {
|
|
181
|
-
const notificationCapability = getClientCapabilityForNotificationMethod(method);
|
|
182
|
-
if (!notificationCapability) {
|
|
183
|
-
if (!this.strict) {
|
|
184
|
-
this.logger.debug(`Unknown method ${method}, allowing in non-strict mode`);
|
|
185
|
-
return true;
|
|
186
|
-
}
|
|
187
|
-
const error = `Cannot register handler for unknown method: ${method}`;
|
|
188
|
-
this.logger.error(error);
|
|
189
|
-
throw new Error(error);
|
|
190
|
-
}
|
|
191
|
-
return this.isNotificationAllowed(method, notificationCapability);
|
|
192
|
-
}
|
|
193
|
-
return this.isRequestAllowed(method, capabilityKey);
|
|
132
|
+
return checkMethod({
|
|
133
|
+
method,
|
|
134
|
+
methodSets: CLIENT_METHODS,
|
|
135
|
+
getCapabilityKey: (m) => {
|
|
136
|
+
return (getClientCapabilityForRequestMethod(m) ??
|
|
137
|
+
getClientCapabilityForNotificationMethod(m));
|
|
138
|
+
},
|
|
139
|
+
hasCapability: (key) => hasClientCapability(this.capabilities, key),
|
|
140
|
+
actionLabel: 'register handler',
|
|
141
|
+
capabilityLabel: 'client capability',
|
|
142
|
+
logger: this.logger,
|
|
143
|
+
strict: this.strict
|
|
144
|
+
});
|
|
194
145
|
}
|
|
195
146
|
/**
|
|
196
|
-
*
|
|
147
|
+
* Returns a defensive copy of the client capabilities this guard was built from.
|
|
148
|
+
*
|
|
149
|
+
* @returns A shallow copy of the client capabilities object.
|
|
197
150
|
*/
|
|
198
151
|
getClientCapabilities() {
|
|
199
152
|
return { ...this.capabilities };
|
|
200
153
|
}
|
|
201
|
-
isRequestAllowed(method, capabilityKey) {
|
|
202
|
-
if (capabilityKey === 'alwaysOn') {
|
|
203
|
-
return true;
|
|
204
|
-
}
|
|
205
|
-
if (!hasClientCapability(this.capabilities, capabilityKey)) {
|
|
206
|
-
const error = `Cannot register handler for ${method}: client capability '${capabilityKey}' not declared`;
|
|
207
|
-
this.logger.warn(error);
|
|
208
|
-
if (this.strict) {
|
|
209
|
-
throw new Error(error);
|
|
210
|
-
}
|
|
211
|
-
return false;
|
|
212
|
-
}
|
|
213
|
-
return true;
|
|
214
|
-
}
|
|
215
|
-
isNotificationAllowed(method, capabilityKey) {
|
|
216
|
-
if (capabilityKey === 'alwaysOn') {
|
|
217
|
-
return true;
|
|
218
|
-
}
|
|
219
|
-
if (!hasClientCapability(this.capabilities, capabilityKey)) {
|
|
220
|
-
const error = `Cannot register handler for ${method}: client capability '${capabilityKey}' not declared`;
|
|
221
|
-
this.logger.warn(error);
|
|
222
|
-
if (this.strict) {
|
|
223
|
-
throw new Error(error);
|
|
224
|
-
}
|
|
225
|
-
return false;
|
|
226
|
-
}
|
|
227
|
-
return true;
|
|
228
|
-
}
|
|
229
154
|
}
|
|
230
155
|
//# sourceMappingURL=capability-guard.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"capability-guard.js","sourceRoot":"","sources":["../src/capability-guard.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"capability-guard.js","sourceRoot":"","sources":["../src/capability-guard.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,EACL,cAAc,EACd,cAAc,EACd,WAAW,EACX,wCAAwC,EACxC,mCAAmC,EACnC,mBAAmB,EACnB,mBAAmB,EACnB,kCAAkC,EAClC,6BAA6B,EAC9B,MAAM,eAAe,CAAC;AAEvB;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,OAAO,eAAe;IAEP,YAAY;IACZ,MAAM;IACN,MAAM;IAHzB,YACmB,YAAyC,EACzC,MAAc,EACd,MAAM,GAAY,KAAK;4BAFvB,YAAY;sBACZ,MAAM;sBACN,MAAM;IACtB,CAAC;IAEJ;;;;;;;;;;;OAWG;IACH,cAAc,CAAC,MAAc;QAC3B,OAAO,WAAW,CAAC;YACjB,MAAM;YACN,UAAU,EAAE,cAAc;YAC1B,gBAAgB,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,6BAA6B,CAAC,CAAQ,CAAC;YAChE,aAAa,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,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E,CAAC,mBAAmB,CAAC,IAAI,CAAC,YAAY,EAAE,GAAU,CAAC;YAC1E,WAAW,EAAE,kBAAkB;YAC/B,eAAe,EAAE,mBAAmB;YACpC,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,MAAM,EAAE,IAAI,CAAC,MAAM;SACpB,CAAC,CAAC;IACL,CAAC;IAED;;;;OAIG;IACH,qBAAqB;QACnB,OAAO,EAAE,GAAG,IAAI,CAAC,YAAY,EAAE,CAAC;IAClC,CAAC;CACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"capability-proxy.js","sourceRoot":"","sources":["../src/capability-proxy.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EACL,UAAU,EACV,eAAe,EACf,uBAAuB,EACvB,4BAA4B,EAC5B,mBAAmB,EACpB,MAAM,eAAe,CAAC;AAEvB,OAAO,SAAS,MAAM,WAAW,CAAC;AAElC,SAAS,2BAA2B,CAAC,aAAqB,EAAE,eAAuB
|
|
1
|
+
{"version":3,"file":"capability-proxy.js","sourceRoot":"","sources":["../src/capability-proxy.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EACL,UAAU,EACV,eAAe,EACf,uBAAuB,EACvB,4BAA4B,EAC5B,mBAAmB,EACpB,MAAM,eAAe,CAAC;AAEvB,OAAO,SAAS,MAAM,WAAW,CAAC;AAElC,SAAS,2BAA2B,CAAC,aAAqB,EAAE,eAAuB;IACjF,IAAI,eAAe,CAAC,QAAQ,CAAC,aAAa,CAAC,EAAE,CAAC;QAC5C,OAAO,eAAe,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;IACzD,CAAC;IACD,OAAO,eAAe,CAAC;AACzB,CAAC;AAED,SAAS,2BAA2B,CAElC,MAA6B;IAC7B,MAAM,OAAO,GAAG,MAAM,CAAC,sBAAsB,EAAE,CAAC;IAChD,OAAO,IAAI,GAAG,CAAC,OAAO,CAAC,oBAA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