@procwire/transport 1.0.0
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 +844 -0
- package/dist/channel/builder.d.ts +68 -0
- package/dist/channel/builder.d.ts.map +1 -0
- package/dist/channel/builder.js +120 -0
- package/dist/channel/builder.js.map +1 -0
- package/dist/channel/index.d.ts +6 -0
- package/dist/channel/index.d.ts.map +1 -0
- package/dist/channel/index.js +6 -0
- package/dist/channel/index.js.map +1 -0
- package/dist/channel/quickstart.d.ts +94 -0
- package/dist/channel/quickstart.d.ts.map +1 -0
- package/dist/channel/quickstart.js +104 -0
- package/dist/channel/quickstart.js.map +1 -0
- package/dist/channel/request-channel.d.ts +119 -0
- package/dist/channel/request-channel.d.ts.map +1 -0
- package/dist/channel/request-channel.js +476 -0
- package/dist/channel/request-channel.js.map +1 -0
- package/dist/channel/types.d.ts +226 -0
- package/dist/channel/types.d.ts.map +1 -0
- package/dist/channel/types.js +2 -0
- package/dist/channel/types.js.map +1 -0
- package/dist/framing/index.d.ts +4 -0
- package/dist/framing/index.d.ts.map +1 -0
- package/dist/framing/index.js +4 -0
- package/dist/framing/index.js.map +1 -0
- package/dist/framing/length-prefixed.d.ts +55 -0
- package/dist/framing/length-prefixed.d.ts.map +1 -0
- package/dist/framing/length-prefixed.js +102 -0
- package/dist/framing/length-prefixed.js.map +1 -0
- package/dist/framing/line-delimited.d.ts +61 -0
- package/dist/framing/line-delimited.d.ts.map +1 -0
- package/dist/framing/line-delimited.js +94 -0
- package/dist/framing/line-delimited.js.map +1 -0
- package/dist/framing/types.d.ts +35 -0
- package/dist/framing/types.d.ts.map +1 -0
- package/dist/framing/types.js +2 -0
- package/dist/framing/types.js.map +1 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +26 -0
- package/dist/index.js.map +1 -0
- package/dist/process/handle.d.ts +64 -0
- package/dist/process/handle.d.ts.map +1 -0
- package/dist/process/handle.js +107 -0
- package/dist/process/handle.js.map +1 -0
- package/dist/process/index.d.ts +37 -0
- package/dist/process/index.d.ts.map +1 -0
- package/dist/process/index.js +37 -0
- package/dist/process/index.js.map +1 -0
- package/dist/process/manager.d.ts +58 -0
- package/dist/process/manager.d.ts.map +1 -0
- package/dist/process/manager.js +360 -0
- package/dist/process/manager.js.map +1 -0
- package/dist/process/types.d.ts +322 -0
- package/dist/process/types.d.ts.map +1 -0
- package/dist/process/types.js +2 -0
- package/dist/process/types.js.map +1 -0
- package/dist/protocol/index.d.ts +4 -0
- package/dist/protocol/index.d.ts.map +1 -0
- package/dist/protocol/index.js +6 -0
- package/dist/protocol/index.js.map +1 -0
- package/dist/protocol/jsonrpc.d.ts +146 -0
- package/dist/protocol/jsonrpc.d.ts.map +1 -0
- package/dist/protocol/jsonrpc.js +288 -0
- package/dist/protocol/jsonrpc.js.map +1 -0
- package/dist/protocol/simple.d.ts +139 -0
- package/dist/protocol/simple.d.ts.map +1 -0
- package/dist/protocol/simple.js +297 -0
- package/dist/protocol/simple.js.map +1 -0
- package/dist/protocol/types.d.ts +117 -0
- package/dist/protocol/types.d.ts.map +1 -0
- package/dist/protocol/types.js +2 -0
- package/dist/protocol/types.js.map +1 -0
- package/dist/serialization/index.d.ts +5 -0
- package/dist/serialization/index.d.ts.map +1 -0
- package/dist/serialization/index.js +5 -0
- package/dist/serialization/index.js.map +1 -0
- package/dist/serialization/json.d.ts +66 -0
- package/dist/serialization/json.d.ts.map +1 -0
- package/dist/serialization/json.js +66 -0
- package/dist/serialization/json.js.map +1 -0
- package/dist/serialization/raw.d.ts +38 -0
- package/dist/serialization/raw.d.ts.map +1 -0
- package/dist/serialization/raw.js +41 -0
- package/dist/serialization/raw.js.map +1 -0
- package/dist/serialization/registry.d.ts +91 -0
- package/dist/serialization/registry.d.ts.map +1 -0
- package/dist/serialization/registry.js +119 -0
- package/dist/serialization/registry.js.map +1 -0
- package/dist/serialization/types.d.ts +27 -0
- package/dist/serialization/types.d.ts.map +1 -0
- package/dist/serialization/types.js +2 -0
- package/dist/serialization/types.js.map +1 -0
- package/dist/transport/factory.d.ts +139 -0
- package/dist/transport/factory.d.ts.map +1 -0
- package/dist/transport/factory.js +162 -0
- package/dist/transport/factory.js.map +1 -0
- package/dist/transport/index.d.ts +6 -0
- package/dist/transport/index.d.ts.map +1 -0
- package/dist/transport/index.js +9 -0
- package/dist/transport/index.js.map +1 -0
- package/dist/transport/socket-server.d.ts +48 -0
- package/dist/transport/socket-server.d.ts.map +1 -0
- package/dist/transport/socket-server.js +215 -0
- package/dist/transport/socket-server.js.map +1 -0
- package/dist/transport/socket-transport.d.ts +67 -0
- package/dist/transport/socket-transport.d.ts.map +1 -0
- package/dist/transport/socket-transport.js +193 -0
- package/dist/transport/socket-transport.js.map +1 -0
- package/dist/transport/stdio-transport.d.ts +94 -0
- package/dist/transport/stdio-transport.d.ts.map +1 -0
- package/dist/transport/stdio-transport.js +234 -0
- package/dist/transport/stdio-transport.js.map +1 -0
- package/dist/transport/types.d.ts +131 -0
- package/dist/transport/types.d.ts.map +1 -0
- package/dist/transport/types.js +2 -0
- package/dist/transport/types.js.map +1 -0
- package/dist/utils/assert.d.ts +16 -0
- package/dist/utils/assert.d.ts.map +1 -0
- package/dist/utils/assert.js +31 -0
- package/dist/utils/assert.js.map +1 -0
- package/dist/utils/disposables.d.ts +38 -0
- package/dist/utils/disposables.d.ts.map +1 -0
- package/dist/utils/disposables.js +59 -0
- package/dist/utils/disposables.js.map +1 -0
- package/dist/utils/errors.d.ts +43 -0
- package/dist/utils/errors.d.ts.map +1 -0
- package/dist/utils/errors.js +69 -0
- package/dist/utils/errors.js.map +1 -0
- package/dist/utils/events.d.ts +58 -0
- package/dist/utils/events.d.ts.map +1 -0
- package/dist/utils/events.js +95 -0
- package/dist/utils/events.js.map +1 -0
- package/dist/utils/index.d.ts +8 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +8 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/pipe-path.d.ts +48 -0
- package/dist/utils/pipe-path.d.ts.map +1 -0
- package/dist/utils/pipe-path.js +89 -0
- package/dist/utils/pipe-path.js.map +1 -0
- package/dist/utils/platform.d.ts +16 -0
- package/dist/utils/platform.d.ts.map +1 -0
- package/dist/utils/platform.js +22 -0
- package/dist/utils/platform.js.map +1 -0
- package/dist/utils/time.d.ts +38 -0
- package/dist/utils/time.d.ts.map +1 -0
- package/dist/utils/time.js +55 -0
- package/dist/utils/time.js.map +1 -0
- package/package.json +85 -0
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
import type { EventMap } from "../utils/events.js";
|
|
2
|
+
import type { Unsubscribe } from "../utils/disposables.js";
|
|
3
|
+
import type { FramingCodec } from "../framing/types.js";
|
|
4
|
+
import type { SerializationCodec } from "../serialization/types.js";
|
|
5
|
+
import type { Protocol } from "../protocol/types.js";
|
|
6
|
+
import type { ResponseAccessor } from "../channel/types.js";
|
|
7
|
+
import type { Channel } from "../channel/types.js";
|
|
8
|
+
/**
|
|
9
|
+
* Process lifecycle states.
|
|
10
|
+
*/
|
|
11
|
+
export type ProcessState = "starting" | "running" | "stopping" | "stopped" | "crashed" | "error";
|
|
12
|
+
/**
|
|
13
|
+
* Restart policy configuration.
|
|
14
|
+
*/
|
|
15
|
+
export interface RestartPolicy {
|
|
16
|
+
/**
|
|
17
|
+
* Whether automatic restart is enabled.
|
|
18
|
+
*/
|
|
19
|
+
enabled: boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Maximum number of restart attempts.
|
|
22
|
+
*/
|
|
23
|
+
maxRestarts: number;
|
|
24
|
+
/**
|
|
25
|
+
* Initial backoff delay in milliseconds.
|
|
26
|
+
*/
|
|
27
|
+
backoffMs: number;
|
|
28
|
+
/**
|
|
29
|
+
* Maximum backoff delay in milliseconds (optional).
|
|
30
|
+
* Caps exponential backoff growth.
|
|
31
|
+
*/
|
|
32
|
+
maxBackoffMs?: number;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Channel configuration for control or data channels.
|
|
36
|
+
*/
|
|
37
|
+
export interface ChannelConfig {
|
|
38
|
+
/**
|
|
39
|
+
* Framing codec: predefined name or custom codec.
|
|
40
|
+
* @default 'line-delimited' for control, 'length-prefixed' for data
|
|
41
|
+
*/
|
|
42
|
+
framing?: "line-delimited" | "length-prefixed" | FramingCodec;
|
|
43
|
+
/**
|
|
44
|
+
* Serialization codec: predefined name or custom codec.
|
|
45
|
+
* @default 'json'
|
|
46
|
+
*/
|
|
47
|
+
serialization?: "json" | "raw" | SerializationCodec;
|
|
48
|
+
/**
|
|
49
|
+
* Protocol: predefined name or custom protocol.
|
|
50
|
+
* @default 'jsonrpc'
|
|
51
|
+
*/
|
|
52
|
+
protocol?: "jsonrpc" | "simple" | Protocol;
|
|
53
|
+
/**
|
|
54
|
+
* Request timeout in milliseconds.
|
|
55
|
+
* @default 30000
|
|
56
|
+
*/
|
|
57
|
+
timeoutMs?: number;
|
|
58
|
+
/**
|
|
59
|
+
* Custom response accessor for protocol-specific response handling.
|
|
60
|
+
*/
|
|
61
|
+
responseAccessor?: ResponseAccessor;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Data channel configuration.
|
|
65
|
+
*/
|
|
66
|
+
export interface DataChannelConfig {
|
|
67
|
+
/**
|
|
68
|
+
* Whether data channel is enabled.
|
|
69
|
+
* @default false
|
|
70
|
+
*/
|
|
71
|
+
enabled?: boolean;
|
|
72
|
+
/**
|
|
73
|
+
* Named pipe/unix socket path for data channel.
|
|
74
|
+
* If not provided, auto-generated using PipePath.forModule(namespace, processId).
|
|
75
|
+
*/
|
|
76
|
+
path?: string;
|
|
77
|
+
/**
|
|
78
|
+
* Transport type (currently only 'pipe' is supported).
|
|
79
|
+
* @default 'pipe'
|
|
80
|
+
*/
|
|
81
|
+
transport?: "pipe";
|
|
82
|
+
/**
|
|
83
|
+
* Channel configuration for data channel.
|
|
84
|
+
*/
|
|
85
|
+
channel?: ChannelConfig;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Options for spawning a managed process.
|
|
89
|
+
*/
|
|
90
|
+
export interface SpawnOptions {
|
|
91
|
+
/**
|
|
92
|
+
* Path to executable to spawn.
|
|
93
|
+
*/
|
|
94
|
+
executablePath: string;
|
|
95
|
+
/**
|
|
96
|
+
* Command line arguments.
|
|
97
|
+
*/
|
|
98
|
+
args?: string[];
|
|
99
|
+
/**
|
|
100
|
+
* Working directory for the process.
|
|
101
|
+
*/
|
|
102
|
+
cwd?: string;
|
|
103
|
+
/**
|
|
104
|
+
* Environment variables.
|
|
105
|
+
*/
|
|
106
|
+
env?: Record<string, string>;
|
|
107
|
+
/**
|
|
108
|
+
* Startup timeout in milliseconds.
|
|
109
|
+
* @default 10000
|
|
110
|
+
*/
|
|
111
|
+
startupTimeout?: number;
|
|
112
|
+
/**
|
|
113
|
+
* Control channel configuration.
|
|
114
|
+
* Control channel uses stdio transport.
|
|
115
|
+
*/
|
|
116
|
+
controlChannel?: ChannelConfig;
|
|
117
|
+
/**
|
|
118
|
+
* Data channel configuration (optional secondary channel).
|
|
119
|
+
*/
|
|
120
|
+
dataChannel?: DataChannelConfig;
|
|
121
|
+
/**
|
|
122
|
+
* Custom restart policy for this process.
|
|
123
|
+
* Overrides manager default.
|
|
124
|
+
*/
|
|
125
|
+
restartPolicy?: RestartPolicy;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Process manager configuration.
|
|
129
|
+
*/
|
|
130
|
+
export interface ProcessManagerConfig {
|
|
131
|
+
/**
|
|
132
|
+
* Default request timeout for all channels.
|
|
133
|
+
* @default 30000
|
|
134
|
+
*/
|
|
135
|
+
defaultTimeout?: number;
|
|
136
|
+
/**
|
|
137
|
+
* Default restart policy for all processes.
|
|
138
|
+
*/
|
|
139
|
+
restartPolicy?: RestartPolicy;
|
|
140
|
+
/**
|
|
141
|
+
* Namespace for auto-generated pipe paths.
|
|
142
|
+
* @default 'procwire'
|
|
143
|
+
*/
|
|
144
|
+
namespace?: string;
|
|
145
|
+
/**
|
|
146
|
+
* Graceful shutdown timeout in milliseconds.
|
|
147
|
+
* @default 5000
|
|
148
|
+
*/
|
|
149
|
+
gracefulShutdownMs?: number;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Process manager events.
|
|
153
|
+
*/
|
|
154
|
+
export interface ProcessManagerEvents extends EventMap {
|
|
155
|
+
/**
|
|
156
|
+
* Fired when a process is spawned.
|
|
157
|
+
*/
|
|
158
|
+
spawn: {
|
|
159
|
+
id: string;
|
|
160
|
+
pid: number;
|
|
161
|
+
};
|
|
162
|
+
/**
|
|
163
|
+
* Fired when a process exits.
|
|
164
|
+
*/
|
|
165
|
+
exit: {
|
|
166
|
+
id: string;
|
|
167
|
+
code: number | null;
|
|
168
|
+
signal: string | null;
|
|
169
|
+
};
|
|
170
|
+
/**
|
|
171
|
+
* Fired when a process crashes.
|
|
172
|
+
*/
|
|
173
|
+
crash: {
|
|
174
|
+
id: string;
|
|
175
|
+
error: Error;
|
|
176
|
+
};
|
|
177
|
+
/**
|
|
178
|
+
* Fired when a process restart is attempted.
|
|
179
|
+
*/
|
|
180
|
+
restart: {
|
|
181
|
+
id: string;
|
|
182
|
+
attempt: number;
|
|
183
|
+
delayMs: number;
|
|
184
|
+
};
|
|
185
|
+
/**
|
|
186
|
+
* Fired when a process is ready (channels connected).
|
|
187
|
+
*/
|
|
188
|
+
ready: {
|
|
189
|
+
id: string;
|
|
190
|
+
};
|
|
191
|
+
/**
|
|
192
|
+
* Fired when an error occurs.
|
|
193
|
+
*/
|
|
194
|
+
error: {
|
|
195
|
+
id: string;
|
|
196
|
+
error: Error;
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Process handle events.
|
|
201
|
+
*/
|
|
202
|
+
export interface ProcessHandleEvents extends EventMap {
|
|
203
|
+
/**
|
|
204
|
+
* Fired when process state changes.
|
|
205
|
+
*/
|
|
206
|
+
stateChange: {
|
|
207
|
+
from: ProcessState;
|
|
208
|
+
to: ProcessState;
|
|
209
|
+
};
|
|
210
|
+
/**
|
|
211
|
+
* Fired when process exits.
|
|
212
|
+
*/
|
|
213
|
+
exit: {
|
|
214
|
+
code: number | null;
|
|
215
|
+
signal: string | null;
|
|
216
|
+
};
|
|
217
|
+
/**
|
|
218
|
+
* Fired when an error occurs.
|
|
219
|
+
*/
|
|
220
|
+
error: Error;
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Process handle interface.
|
|
224
|
+
* Provides access to a managed process and its channels.
|
|
225
|
+
*/
|
|
226
|
+
export interface ProcessHandle {
|
|
227
|
+
/**
|
|
228
|
+
* Unique process identifier.
|
|
229
|
+
*/
|
|
230
|
+
readonly id: string;
|
|
231
|
+
/**
|
|
232
|
+
* Process ID (OS-level).
|
|
233
|
+
*/
|
|
234
|
+
readonly pid: number | null;
|
|
235
|
+
/**
|
|
236
|
+
* Current process state.
|
|
237
|
+
*/
|
|
238
|
+
readonly state: ProcessState;
|
|
239
|
+
/**
|
|
240
|
+
* Control channel (stdio-based, always available).
|
|
241
|
+
*/
|
|
242
|
+
readonly controlChannel: Channel;
|
|
243
|
+
/**
|
|
244
|
+
* Data channel (pipe-based, optional).
|
|
245
|
+
*/
|
|
246
|
+
readonly dataChannel: Channel | null;
|
|
247
|
+
/**
|
|
248
|
+
* Sends a request via control channel.
|
|
249
|
+
* @param method - Method name
|
|
250
|
+
* @param params - Optional parameters
|
|
251
|
+
* @param timeout - Optional timeout override
|
|
252
|
+
* @returns Promise resolving to response result
|
|
253
|
+
*/
|
|
254
|
+
request(method: string, params?: unknown, timeout?: number): Promise<unknown>;
|
|
255
|
+
/**
|
|
256
|
+
* Sends a notification via control channel.
|
|
257
|
+
* @param method - Method name
|
|
258
|
+
* @param params - Optional parameters
|
|
259
|
+
*/
|
|
260
|
+
notify(method: string, params?: unknown): Promise<void>;
|
|
261
|
+
/**
|
|
262
|
+
* Sends a request via data channel.
|
|
263
|
+
* @param method - Method name
|
|
264
|
+
* @param params - Optional parameters
|
|
265
|
+
* @param timeout - Optional timeout override
|
|
266
|
+
* @returns Promise resolving to response result
|
|
267
|
+
* @throws {Error} if data channel is not enabled
|
|
268
|
+
*/
|
|
269
|
+
requestViaData(method: string, params?: unknown, timeout?: number): Promise<unknown>;
|
|
270
|
+
/**
|
|
271
|
+
* Closes the handle and its channels.
|
|
272
|
+
* Does not terminate the process - use ProcessManager.terminate() for that.
|
|
273
|
+
*/
|
|
274
|
+
close(): Promise<void>;
|
|
275
|
+
/**
|
|
276
|
+
* Subscribes to handle events.
|
|
277
|
+
* @returns Unsubscribe function
|
|
278
|
+
*/
|
|
279
|
+
on<K extends keyof ProcessHandleEvents>(event: K, handler: (data: ProcessHandleEvents[K]) => void): Unsubscribe;
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* Process manager interface.
|
|
283
|
+
* Manages the lifecycle of multiple child processes.
|
|
284
|
+
*/
|
|
285
|
+
export interface ProcessManager {
|
|
286
|
+
/**
|
|
287
|
+
* Spawns a new managed process.
|
|
288
|
+
* @param id - Unique process identifier
|
|
289
|
+
* @param options - Spawn options
|
|
290
|
+
* @returns Promise resolving to process handle
|
|
291
|
+
* @throws {Error} if process with this ID already exists
|
|
292
|
+
*/
|
|
293
|
+
spawn(id: string, options: SpawnOptions): Promise<ProcessHandle>;
|
|
294
|
+
/**
|
|
295
|
+
* Terminates a managed process.
|
|
296
|
+
* @param id - Process identifier
|
|
297
|
+
* @throws {Error} if process doesn't exist
|
|
298
|
+
*/
|
|
299
|
+
terminate(id: string): Promise<void>;
|
|
300
|
+
/**
|
|
301
|
+
* Terminates all managed processes.
|
|
302
|
+
*/
|
|
303
|
+
terminateAll(): Promise<void>;
|
|
304
|
+
/**
|
|
305
|
+
* Gets a process handle by ID.
|
|
306
|
+
* @param id - Process identifier
|
|
307
|
+
* @returns Process handle or null if not found
|
|
308
|
+
*/
|
|
309
|
+
getHandle(id: string): ProcessHandle | null;
|
|
310
|
+
/**
|
|
311
|
+
* Checks if a process is running.
|
|
312
|
+
* @param id - Process identifier
|
|
313
|
+
* @returns true if process exists and is in 'running' state
|
|
314
|
+
*/
|
|
315
|
+
isRunning(id: string): boolean;
|
|
316
|
+
/**
|
|
317
|
+
* Subscribes to manager events.
|
|
318
|
+
* @returns Unsubscribe function
|
|
319
|
+
*/
|
|
320
|
+
on<K extends keyof ProcessManagerEvents>(event: K, handler: (data: ProcessManagerEvents[K]) => void): Unsubscribe;
|
|
321
|
+
}
|
|
322
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/process/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AACpE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAC5D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAEnD;;GAEG;AACH,MAAM,MAAM,YAAY,GACpB,UAAU,GACV,SAAS,GACT,UAAU,GACV,SAAS,GACT,SAAS,GACT,OAAO,CAAC;AAEZ;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B;;OAEG;IACH,OAAO,EAAE,OAAO,CAAC;IAEjB;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC;IAEpB;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;IAElB;;;OAGG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B;;;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AE,MAAM,GAAG,aAAa,GAAG,IAAI,CAAC;IAE5C;;;;OAIG;IACH,SAAS,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC;IAE/B;;;OAGG;IACH,EAAE,CAAC,CAAC,SAAS,MAAM,oBAAoB,EACrC,KAAK,EAAE,CAAC,EACR,OAAO,EAAE,CAAC,IAAI,EAAE,oBAAoB,CAAC,CAAC,CAAC,KAAK,IAAI,GAC/C,WAAW,CAAC;CAChB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/process/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/protocol/index.ts"],"names":[],"mappings":"AACA,cAAc,YAAY,CAAC;AAG3B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/protocol/index.ts"],"names":[],"mappings":"AAAA,aAAa;AACb,cAAc,YAAY,CAAC;AAE3B,2BAA2B;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC"}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import type { Protocol, ParsedMessage, RequestId, ProtocolDataError } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* JSON-RPC 2.0 error codes.
|
|
4
|
+
* @see https://www.jsonrpc.org/specification#error_object
|
|
5
|
+
*/
|
|
6
|
+
export declare const JsonRpcErrorCodes: {
|
|
7
|
+
/** Invalid JSON was received by the server. */
|
|
8
|
+
readonly PARSE_ERROR: -32700;
|
|
9
|
+
/** The JSON sent is not a valid Request object. */
|
|
10
|
+
readonly INVALID_REQUEST: -32600;
|
|
11
|
+
/** The method does not exist / is not available. */
|
|
12
|
+
readonly METHOD_NOT_FOUND: -32601;
|
|
13
|
+
/** Invalid method parameter(s). */
|
|
14
|
+
readonly INVALID_PARAMS: -32602;
|
|
15
|
+
/** Internal JSON-RPC error. */
|
|
16
|
+
readonly INTERNAL_ERROR: -32603;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* JSON-RPC 2.0 request message.
|
|
20
|
+
*/
|
|
21
|
+
export interface JsonRpcRequest {
|
|
22
|
+
jsonrpc: "2.0";
|
|
23
|
+
id: RequestId;
|
|
24
|
+
method: string;
|
|
25
|
+
params?: unknown;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* JSON-RPC 2.0 response message (success).
|
|
29
|
+
*/
|
|
30
|
+
export interface JsonRpcResponse {
|
|
31
|
+
jsonrpc: "2.0";
|
|
32
|
+
id: RequestId;
|
|
33
|
+
result: unknown;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* JSON-RPC 2.0 error response message.
|
|
37
|
+
*/
|
|
38
|
+
export interface JsonRpcErrorResponse {
|
|
39
|
+
jsonrpc: "2.0";
|
|
40
|
+
id: RequestId;
|
|
41
|
+
error: ProtocolDataError;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* JSON-RPC 2.0 notification message (no response expected).
|
|
45
|
+
*/
|
|
46
|
+
export interface JsonRpcNotification {
|
|
47
|
+
jsonrpc: "2.0";
|
|
48
|
+
method: string;
|
|
49
|
+
params?: unknown;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Union of all JSON-RPC message types for responses.
|
|
53
|
+
*/
|
|
54
|
+
export type JsonRpcResponseMessage = JsonRpcResponse | JsonRpcErrorResponse;
|
|
55
|
+
/**
|
|
56
|
+
* JSON-RPC 2.0 protocol implementation.
|
|
57
|
+
*
|
|
58
|
+
* Follows the JSON-RPC 2.0 specification for request/response messaging.
|
|
59
|
+
* Provides strict validation and automatic ID generation.
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```ts
|
|
63
|
+
* const protocol = new JsonRpcProtocol();
|
|
64
|
+
* const req = protocol.createRequest('getUser', { id: 42 });
|
|
65
|
+
* const res = protocol.createResponse(req.id, { name: 'Alice' });
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
export declare class JsonRpcProtocol implements Protocol<JsonRpcRequest, JsonRpcResponseMessage, JsonRpcNotification> {
|
|
69
|
+
readonly name = "jsonrpc";
|
|
70
|
+
readonly version = "2.0";
|
|
71
|
+
private idCounter;
|
|
72
|
+
/**
|
|
73
|
+
* Creates a JSON-RPC 2.0 request message.
|
|
74
|
+
*
|
|
75
|
+
* @param method - Method name (must be non-empty string)
|
|
76
|
+
* @param params - Optional parameters
|
|
77
|
+
* @param id - Optional request ID (auto-generated if not provided)
|
|
78
|
+
* @returns JSON-RPC request object
|
|
79
|
+
* @throws {ProtocolError} if method is invalid
|
|
80
|
+
*/
|
|
81
|
+
createRequest(method: string, params?: unknown, id?: RequestId): JsonRpcRequest;
|
|
82
|
+
/**
|
|
83
|
+
* Creates a JSON-RPC 2.0 success response message.
|
|
84
|
+
*
|
|
85
|
+
* @param id - Request ID
|
|
86
|
+
* @param result - Response result
|
|
87
|
+
* @returns JSON-RPC response object
|
|
88
|
+
*/
|
|
89
|
+
createResponse(id: RequestId, result: unknown): JsonRpcResponse;
|
|
90
|
+
/**
|
|
91
|
+
* Creates a JSON-RPC 2.0 error response message.
|
|
92
|
+
*
|
|
93
|
+
* @param id - Request ID
|
|
94
|
+
* @param error - Error details
|
|
95
|
+
* @returns JSON-RPC error response object
|
|
96
|
+
*/
|
|
97
|
+
createErrorResponse(id: RequestId, error: ProtocolDataError): JsonRpcErrorResponse;
|
|
98
|
+
/**
|
|
99
|
+
* Creates a JSON-RPC 2.0 notification message.
|
|
100
|
+
*
|
|
101
|
+
* @param method - Method name (must be non-empty string)
|
|
102
|
+
* @param params - Optional parameters
|
|
103
|
+
* @returns JSON-RPC notification object
|
|
104
|
+
* @throws {ProtocolError} if method is invalid
|
|
105
|
+
*/
|
|
106
|
+
createNotification(method: string, params?: unknown): JsonRpcNotification;
|
|
107
|
+
/**
|
|
108
|
+
* Parses incoming data as JSON-RPC 2.0 message.
|
|
109
|
+
* Does not throw - returns 'invalid' kind for malformed messages.
|
|
110
|
+
*
|
|
111
|
+
* @param data - Raw incoming data
|
|
112
|
+
* @returns ParsedMessage discriminated union
|
|
113
|
+
*/
|
|
114
|
+
parseMessage(data: unknown): ParsedMessage<JsonRpcRequest, JsonRpcResponseMessage, JsonRpcNotification>;
|
|
115
|
+
/**
|
|
116
|
+
* Type guard for request messages.
|
|
117
|
+
*/
|
|
118
|
+
isRequest(msg: ParsedMessage<JsonRpcRequest, JsonRpcResponseMessage, JsonRpcNotification>): msg is Extract<ParsedMessage<JsonRpcRequest, JsonRpcResponseMessage, JsonRpcNotification>, {
|
|
119
|
+
kind: "request";
|
|
120
|
+
}>;
|
|
121
|
+
/**
|
|
122
|
+
* Type guard for response messages.
|
|
123
|
+
*/
|
|
124
|
+
isResponse(msg: ParsedMessage<JsonRpcRequest, JsonRpcResponseMessage, JsonRpcNotification>): msg is Extract<ParsedMessage<JsonRpcRequest, JsonRpcResponseMessage, JsonRpcNotification>, {
|
|
125
|
+
kind: "response";
|
|
126
|
+
}>;
|
|
127
|
+
/**
|
|
128
|
+
* Type guard for notification messages.
|
|
129
|
+
*/
|
|
130
|
+
isNotification(msg: ParsedMessage<JsonRpcRequest, JsonRpcResponseMessage, JsonRpcNotification>): msg is Extract<ParsedMessage<JsonRpcRequest, JsonRpcResponseMessage, JsonRpcNotification>, {
|
|
131
|
+
kind: "notification";
|
|
132
|
+
}>;
|
|
133
|
+
/**
|
|
134
|
+
* Parses a response message (success or error).
|
|
135
|
+
*/
|
|
136
|
+
private parseResponse;
|
|
137
|
+
/**
|
|
138
|
+
* Parses a request or notification message.
|
|
139
|
+
*/
|
|
140
|
+
private parseRequestOrNotification;
|
|
141
|
+
/**
|
|
142
|
+
* Generates a unique request ID.
|
|
143
|
+
*/
|
|
144
|
+
private generateId;
|
|
145
|
+
}
|
|
146
|
+
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