@lspeasy/server 4.0.0 → 4.0.2
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.
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Capability validation for server handlers
|
|
3
3
|
*
|
|
4
|
-
* Ensures handlers can only be registered for declared capabilities
|
|
4
|
+
* Ensures handlers can only be registered for declared server capabilities,
|
|
5
|
+
* and that server-to-client messages respect declared client capabilities.
|
|
5
6
|
*/
|
|
6
7
|
import type { ClientCapabilities, ServerCapabilities } from '@lspeasy/core';
|
|
7
8
|
import type { Logger } from '@lspeasy/core';
|
|
@@ -14,15 +15,7 @@ export declare class CapabilityGuard {
|
|
|
14
15
|
private readonly logger;
|
|
15
16
|
private readonly strict;
|
|
16
17
|
constructor(capabilities: Partial<ServerCapabilities>, logger: Logger, strict?: boolean);
|
|
17
|
-
/**
|
|
18
|
-
* Check if handler registration is allowed for this method
|
|
19
|
-
*
|
|
20
|
-
* @param method - LSP method name
|
|
21
|
-
* @returns true if allowed, false otherwise
|
|
22
|
-
* @throws Error if strict mode enabled and capability not declared
|
|
23
|
-
*/
|
|
24
18
|
canRegisterHandler(method: string): boolean;
|
|
25
|
-
getAllowedMethods(): string[];
|
|
26
19
|
}
|
|
27
20
|
/**
|
|
28
21
|
* Validates that server-to-client messages respect declared client capabilities
|
|
@@ -32,25 +25,8 @@ export declare class ClientCapabilityGuard {
|
|
|
32
25
|
private readonly logger;
|
|
33
26
|
private readonly strict;
|
|
34
27
|
constructor(capabilities: Partial<ClientCapabilities>, logger: Logger, strict?: boolean);
|
|
35
|
-
/**
|
|
36
|
-
* Check if a request can be sent to the client
|
|
37
|
-
*
|
|
38
|
-
* @param method - LSP method name
|
|
39
|
-
* @returns true if allowed, false otherwise
|
|
40
|
-
* @throws Error if strict mode enabled and client capability not declared
|
|
41
|
-
*/
|
|
42
28
|
canSendRequest(method: string): boolean;
|
|
43
|
-
/**
|
|
44
|
-
* Check if a notification can be sent to the client
|
|
45
|
-
*
|
|
46
|
-
* @param method - LSP method name
|
|
47
|
-
* @returns true if allowed, false otherwise
|
|
48
|
-
* @throws Error if strict mode enabled and client capability not declared
|
|
49
|
-
*/
|
|
50
29
|
canSendNotification(method: string): boolean;
|
|
51
|
-
/**
|
|
52
|
-
* Get list of capabilities the client declared
|
|
53
|
-
*/
|
|
54
30
|
getClientCapabilities(): Partial<ClientCapabilities>;
|
|
55
31
|
}
|
|
56
32
|
//# 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;;;GAGG;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,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAe1C;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,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAWtC;IAED,mBAAmB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAW3C;IAED,qBAAqB,IAAI,OAAO,CAAC,kBAAkB,CAAC,CAEnD;CACF"}
|
package/dist/capability-guard.js
CHANGED
|
@@ -1,34 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Capability validation for server handlers
|
|
3
3
|
*
|
|
4
|
-
* Ensures handlers can only be registered for declared capabilities
|
|
4
|
+
* Ensures handlers can only be registered for declared server capabilities,
|
|
5
|
+
* and that server-to-client messages respect declared client capabilities.
|
|
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
9
|
* Validates that a handler can be registered for a method
|
|
34
10
|
* based on declared server capabilities
|
|
@@ -42,66 +18,19 @@ export class CapabilityGuard {
|
|
|
42
18
|
this.logger = logger;
|
|
43
19
|
this.strict = strict;
|
|
44
20
|
}
|
|
45
|
-
/**
|
|
46
|
-
* Check if handler registration is allowed for this method
|
|
47
|
-
*
|
|
48
|
-
* @param method - LSP method name
|
|
49
|
-
* @returns true if allowed, false otherwise
|
|
50
|
-
* @throws Error if strict mode enabled and capability not declared
|
|
51
|
-
*/
|
|
52
21
|
canRegisterHandler(method) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
this.
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
65
|
-
if (SERVER_METHODS.alwaysAllowed.has(method)) {
|
|
66
|
-
return true;
|
|
67
|
-
}
|
|
68
|
-
// Check if method requires a capability (try both request and notification)
|
|
69
|
-
let capabilityKey = getCapabilityForRequestMethod(method);
|
|
70
|
-
if (!capabilityKey) {
|
|
71
|
-
capabilityKey = getCapabilityForNotificationMethod(method);
|
|
72
|
-
}
|
|
73
|
-
if (!capabilityKey) {
|
|
74
|
-
// Unknown method - allow in non-strict mode
|
|
75
|
-
if (!this.strict) {
|
|
76
|
-
this.logger.debug(`Unknown method ${method}, allowing in non-strict mode`);
|
|
77
|
-
return true;
|
|
78
|
-
}
|
|
79
|
-
const error = `Cannot register handler for unknown method: ${method}`;
|
|
80
|
-
this.logger.error(error);
|
|
81
|
-
if (this.strict) {
|
|
82
|
-
throw new Error(error);
|
|
83
|
-
}
|
|
84
|
-
return false;
|
|
85
|
-
}
|
|
86
|
-
if (capabilityKey === 'alwaysOn') {
|
|
87
|
-
return true;
|
|
88
|
-
}
|
|
89
|
-
// Check if capability is declared
|
|
90
|
-
if (!hasServerCapability(this.capabilities, capabilityKey)) {
|
|
91
|
-
const error = `Cannot register handler for ${method}: server capability '${capabilityKey}' not declared`;
|
|
92
|
-
this.logger.warn(error);
|
|
93
|
-
if (this.strict) {
|
|
94
|
-
throw new Error(error);
|
|
95
|
-
}
|
|
96
|
-
return false;
|
|
97
|
-
}
|
|
98
|
-
return true;
|
|
99
|
-
}
|
|
100
|
-
getAllowedMethods() {
|
|
101
|
-
// This would require iterating through all LSP methods
|
|
102
|
-
// For now, return an empty array - can be enhanced if needed
|
|
103
|
-
this.logger.warn('getAllowedMethods not fully implemented - returns empty array');
|
|
104
|
-
return [];
|
|
22
|
+
return checkMethod({
|
|
23
|
+
method,
|
|
24
|
+
methodSets: SERVER_METHODS,
|
|
25
|
+
getCapabilityKey: (m) => {
|
|
26
|
+
return (getCapabilityForRequestMethod(m) ?? getCapabilityForNotificationMethod(m));
|
|
27
|
+
},
|
|
28
|
+
hasCapability: (key) => hasServerCapability(this.capabilities, key),
|
|
29
|
+
actionLabel: 'register handler',
|
|
30
|
+
capabilityLabel: 'server capability',
|
|
31
|
+
logger: this.logger,
|
|
32
|
+
strict: this.strict
|
|
33
|
+
});
|
|
105
34
|
}
|
|
106
35
|
}
|
|
107
36
|
/**
|
|
@@ -116,95 +45,30 @@ export class ClientCapabilityGuard {
|
|
|
116
45
|
this.logger = logger;
|
|
117
46
|
this.strict = strict;
|
|
118
47
|
}
|
|
119
|
-
/**
|
|
120
|
-
* Check if a request can be sent to the client
|
|
121
|
-
*
|
|
122
|
-
* @param method - LSP method name
|
|
123
|
-
* @returns true if allowed, false otherwise
|
|
124
|
-
* @throws Error if strict mode enabled and client capability not declared
|
|
125
|
-
*/
|
|
126
48
|
canSendRequest(method) {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
return true;
|
|
138
|
-
}
|
|
139
|
-
const capabilityKey = getClientCapabilityForRequestMethod(method);
|
|
140
|
-
if (!capabilityKey) {
|
|
141
|
-
if (!this.strict) {
|
|
142
|
-
this.logger.debug(`Unknown request method ${method}, allowing in non-strict mode`);
|
|
143
|
-
return true;
|
|
144
|
-
}
|
|
145
|
-
const error = `Cannot send request for unknown method: ${method}`;
|
|
146
|
-
this.logger.error(error);
|
|
147
|
-
throw new Error(error);
|
|
148
|
-
}
|
|
149
|
-
if (capabilityKey === 'alwaysOn') {
|
|
150
|
-
return true;
|
|
151
|
-
}
|
|
152
|
-
if (!hasClientCapability(this.capabilities, capabilityKey)) {
|
|
153
|
-
const error = `Cannot send request ${method}: client capability '${capabilityKey}' not declared`;
|
|
154
|
-
this.logger.warn(error);
|
|
155
|
-
if (this.strict) {
|
|
156
|
-
throw new Error(error);
|
|
157
|
-
}
|
|
158
|
-
return false;
|
|
159
|
-
}
|
|
160
|
-
return true;
|
|
49
|
+
return checkMethod({
|
|
50
|
+
method,
|
|
51
|
+
methodSets: CLIENT_METHODS,
|
|
52
|
+
getCapabilityKey: (m) => getClientCapabilityForRequestMethod(m),
|
|
53
|
+
hasCapability: (key) => hasClientCapability(this.capabilities, key),
|
|
54
|
+
actionLabel: 'send request',
|
|
55
|
+
capabilityLabel: 'client capability',
|
|
56
|
+
logger: this.logger,
|
|
57
|
+
strict: this.strict
|
|
58
|
+
});
|
|
161
59
|
}
|
|
162
|
-
/**
|
|
163
|
-
* Check if a notification can be sent to the client
|
|
164
|
-
*
|
|
165
|
-
* @param method - LSP method name
|
|
166
|
-
* @returns true if allowed, false otherwise
|
|
167
|
-
* @throws Error if strict mode enabled and client capability not declared
|
|
168
|
-
*/
|
|
169
60
|
canSendNotification(method) {
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
return true;
|
|
181
|
-
}
|
|
182
|
-
const capabilityKey = getClientCapabilityForNotificationMethod(method);
|
|
183
|
-
if (!capabilityKey) {
|
|
184
|
-
if (!this.strict) {
|
|
185
|
-
this.logger.debug(`Unknown notification method ${method}, allowing in non-strict mode`);
|
|
186
|
-
return true;
|
|
187
|
-
}
|
|
188
|
-
const error = `Cannot send notification for unknown method: ${method}`;
|
|
189
|
-
this.logger.error(error);
|
|
190
|
-
throw new Error(error);
|
|
191
|
-
}
|
|
192
|
-
if (capabilityKey === 'alwaysOn') {
|
|
193
|
-
return true;
|
|
194
|
-
}
|
|
195
|
-
if (!hasClientCapability(this.capabilities, capabilityKey)) {
|
|
196
|
-
const error = `Cannot send notification ${method}: client capability '${capabilityKey}' not declared`;
|
|
197
|
-
this.logger.warn(error);
|
|
198
|
-
if (this.strict) {
|
|
199
|
-
throw new Error(error);
|
|
200
|
-
}
|
|
201
|
-
return false;
|
|
202
|
-
}
|
|
203
|
-
return true;
|
|
61
|
+
return checkMethod({
|
|
62
|
+
method,
|
|
63
|
+
methodSets: CLIENT_METHODS,
|
|
64
|
+
getCapabilityKey: (m) => getClientCapabilityForNotificationMethod(m),
|
|
65
|
+
hasCapability: (key) => hasClientCapability(this.capabilities, key),
|
|
66
|
+
actionLabel: 'send notification',
|
|
67
|
+
capabilityLabel: 'client capability',
|
|
68
|
+
logger: this.logger,
|
|
69
|
+
strict: this.strict
|
|
70
|
+
});
|
|
204
71
|
}
|
|
205
|
-
/**
|
|
206
|
-
* Get list of capabilities the client declared
|
|
207
|
-
*/
|
|
208
72
|
getClientCapabilities() {
|
|
209
73
|
return { ...this.capabilities };
|
|
210
74
|
}
|
|
@@ -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,EAC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AAI,CAAC,YAAY,EAAE,GAAU,CAAC;YAC1E,WAAW,EAAE,cAAc;YAC3B,eAAe,EAAE,mBAAmB;YACpC,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,MAAM,EAAE,IAAI,CAAC,MAAM;SACpB,CAAC,CAAC;IAAA,CACJ;IAED,mBAAmB,CAAC,MAAc,EAAW;QAC3C,OAAO,WAAW,CAAC;YACjB,MAAM;YACN,UAAU,EAAE,cAAc;YAC1B,gBAAgB,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,wCAAwC,CAAC,CAAQ,CAAC;YAC3E,aAAa,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,mBAAmB,CAAC,IAAI,CAAC,YAAY,EAAE,GAAU,CAAC;YAC1E,WAAW,EAAE,mBAAmB;YAChC,eAAe,EAAE,mBAAmB;YACpC,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,MAAM,EAAE,IAAI,CAAC,MAAM;SACpB,CAAC,CAAC;IAAA,CACJ;IAED,qBAAqB,GAAgC;QACnD,OAAO,EAAE,GAAG,IAAI,CAAC,YAAY,EAAE,CAAC;IAAA,CACjC;CACF"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lspeasy/server",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.2",
|
|
4
4
|
"description": "Build LSP servers with simple, typed API",
|
|
5
|
+
"private": false,
|
|
5
6
|
"keywords": [
|
|
6
7
|
"lsp",
|
|
7
8
|
"language-server-protocol",
|
|
@@ -36,7 +37,7 @@
|
|
|
36
37
|
"access": "public"
|
|
37
38
|
},
|
|
38
39
|
"dependencies": {
|
|
39
|
-
"@lspeasy/core": "2.1.
|
|
40
|
+
"@lspeasy/core": "2.1.2"
|
|
40
41
|
},
|
|
41
42
|
"optionalDependencies": {
|
|
42
43
|
"zod": "^4.3.6"
|
|
@@ -51,7 +52,7 @@
|
|
|
51
52
|
},
|
|
52
53
|
"scripts": {
|
|
53
54
|
"build": "tsgo --build",
|
|
54
|
-
"clean": "rm -rf dist
|
|
55
|
+
"clean": "rm -rf dist tsconfig.tsbuildinfo",
|
|
55
56
|
"dev": "tsgo --build --watch",
|
|
56
57
|
"type-check": "tsgo --noEmit"
|
|
57
58
|
}
|