@bakit/service 3.2.1 → 4.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/dist/index.d.ts +274 -207
- package/dist/index.js +653 -349
- package/dist/service.js +25 -0
- package/package.json +2 -4
package/dist/index.d.ts
CHANGED
|
@@ -1,256 +1,323 @@
|
|
|
1
|
+
import EventEmitter from 'node:events';
|
|
2
|
+
import * as _bakit_utils from '@bakit/utils';
|
|
3
|
+
import { Awaitable, Collection, FunctionLike, Promisify } from '@bakit/utils';
|
|
1
4
|
import { Socket } from 'node:net';
|
|
2
|
-
import { EventBus, Awaitable, FunctionLike, Promisify } from '@bakit/utils';
|
|
3
|
-
import { ValueOf, MergeExclusive } from 'type-fest';
|
|
4
5
|
|
|
5
6
|
type Serializable =
|
|
6
|
-
| null
|
|
7
|
-
| undefined
|
|
8
7
|
| string
|
|
9
8
|
| number
|
|
10
9
|
| boolean
|
|
11
|
-
|
|
|
12
|
-
|
|
|
13
|
-
| Buffer
|
|
14
|
-
| Uint8Array
|
|
10
|
+
| null
|
|
11
|
+
| undefined
|
|
15
12
|
| Serializable[]
|
|
16
|
-
| { [key: string
|
|
17
|
-
| Map<string | number, Serializable>
|
|
18
|
-
| Set<Serializable>
|
|
19
|
-
| void;
|
|
13
|
+
| { [key: string]: Serializable };
|
|
20
14
|
|
|
21
|
-
interface
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
15
|
+
interface RPCResponseError {
|
|
16
|
+
message: string;
|
|
17
|
+
name: string;
|
|
18
|
+
constructorName: string;
|
|
19
|
+
stack?: string;
|
|
20
|
+
cause?: RPCResponseError;
|
|
21
|
+
errors?: RPCResponseError[]; // For AggregateError
|
|
22
|
+
[key: string]: unknown;
|
|
26
23
|
}
|
|
27
24
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
25
|
+
declare const SUPPORTED_LENGTH_BYTES: readonly [1, 2, 4, 8];
|
|
26
|
+
interface FrameCodecOptions {
|
|
27
|
+
maxBufferSize?: number;
|
|
28
|
+
maxFrameSize?: number;
|
|
29
|
+
lengthBytes?: (typeof SUPPORTED_LENGTH_BYTES)[number];
|
|
30
|
+
endian?: "big" | "little";
|
|
31
|
+
lengthIncludesHeader?: boolean;
|
|
33
32
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
33
|
+
declare class FrameCodec {
|
|
34
|
+
private buffer;
|
|
35
|
+
readonly options: Required<FrameCodecOptions>;
|
|
36
|
+
stats: {
|
|
37
|
+
bytesReceived: number;
|
|
38
|
+
bytesDecoded: number;
|
|
39
|
+
framesDecoded: number;
|
|
40
|
+
bufferCopies: number;
|
|
41
|
+
};
|
|
42
|
+
constructor(options?: FrameCodecOptions);
|
|
43
|
+
push(chunk: Buffer): Buffer[];
|
|
44
|
+
get bufferedBytes(): number;
|
|
45
|
+
reset(): void;
|
|
46
|
+
private readLength;
|
|
47
|
+
encode(payload: Buffer): Buffer<ArrayBufferLike>;
|
|
48
|
+
static encode(payload: Buffer, options?: FrameCodecOptions): Buffer;
|
|
49
|
+
static serialize(obj: Serializable): Buffer;
|
|
50
|
+
static deserialize(buf: Buffer): Serializable;
|
|
49
51
|
}
|
|
50
52
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
};
|
|
59
|
-
type SocketState = ValueOf<typeof SocketState>;
|
|
60
|
-
declare const IPCServerState: {
|
|
61
|
-
readonly Idle: 0;
|
|
62
|
-
readonly Listening: 1;
|
|
63
|
-
readonly Closed: 2;
|
|
64
|
-
};
|
|
65
|
-
type IPCServerState = ValueOf<typeof IPCServerState>;
|
|
66
|
-
interface IPCServerEvents extends BaseServerDriverEvents {
|
|
67
|
-
message: [socket: Socket, message: Serializable];
|
|
68
|
-
clientConnect: [socket: Socket];
|
|
69
|
-
clientDisconnect: [socket: Socket];
|
|
70
|
-
clientError: [socket: Socket, error: Error];
|
|
71
|
-
drain: [socket: Socket];
|
|
72
|
-
}
|
|
73
|
-
interface IPCClientEvents extends BaseClientDriverEvents {
|
|
53
|
+
type EventMap<T> = Record<keyof T, any[]> | DefaultEventMap;
|
|
54
|
+
type DefaultEventMap = [never];
|
|
55
|
+
interface BaseClientDriverEvents {
|
|
56
|
+
message: [message: Serializable];
|
|
57
|
+
connect: [];
|
|
58
|
+
disconnect: [];
|
|
59
|
+
error: [error: Error];
|
|
74
60
|
}
|
|
75
|
-
interface
|
|
76
|
-
listen
|
|
77
|
-
close
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
61
|
+
interface BaseServerDriverEvents<Connection = unknown> {
|
|
62
|
+
listen: [];
|
|
63
|
+
close: [];
|
|
64
|
+
error: [error: Error];
|
|
65
|
+
message: [connection: Connection, message: Serializable];
|
|
66
|
+
connectionAdd: [connection: Connection];
|
|
67
|
+
connectionRemove: [connection: Connection];
|
|
68
|
+
connectionError: [connection: Connection, error: Error];
|
|
81
69
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
destroy: () => void;
|
|
86
|
-
reconnect: () => void;
|
|
87
|
-
write: (chunk: Buffer) => void;
|
|
88
|
-
readonly state: SocketState;
|
|
89
|
-
readonly ready: boolean;
|
|
70
|
+
declare abstract class BaseDriver<Options extends object, Events extends EventMap<Events>> extends EventEmitter<Events> {
|
|
71
|
+
options: Options;
|
|
72
|
+
constructor(options: Options);
|
|
90
73
|
}
|
|
91
|
-
|
|
92
|
-
|
|
74
|
+
declare abstract class BaseClientDriver<Options extends object = object, Events extends EventMap<Events> & BaseClientDriverEvents = BaseClientDriverEvents> extends BaseDriver<Options, Events> {
|
|
75
|
+
constructor(options: Options);
|
|
76
|
+
abstract readonly ready: boolean;
|
|
77
|
+
abstract send(message: Serializable): Awaitable<void>;
|
|
78
|
+
abstract connect(): Awaitable<void>;
|
|
79
|
+
abstract disconnect(): Awaitable<void>;
|
|
93
80
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
81
|
+
declare abstract class BaseServerDriver<Options extends object = object, Connection = unknown, Events extends EventMap<Events> & BaseServerDriverEvents<Connection> = BaseServerDriverEvents<Connection>> extends BaseDriver<Options, Events> {
|
|
82
|
+
constructor(options: Options);
|
|
83
|
+
readonly _connectionType: Connection;
|
|
84
|
+
abstract readonly connections: Set<Connection> | Map<unknown, Connection> | Connection[];
|
|
85
|
+
abstract listen(): Awaitable<void>;
|
|
86
|
+
abstract close(): Awaitable<void>;
|
|
87
|
+
abstract send(connection: Connection, message: Serializable): Awaitable<void>;
|
|
88
|
+
abstract broadcast(message: Serializable): Awaitable<unknown>;
|
|
97
89
|
}
|
|
90
|
+
|
|
98
91
|
interface IPCClientOptions {
|
|
99
92
|
id: string;
|
|
100
|
-
|
|
101
|
-
|
|
93
|
+
codec?: FrameCodecOptions;
|
|
94
|
+
reconnect?: IPCClientReconnectOptions;
|
|
102
95
|
}
|
|
103
|
-
interface
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
96
|
+
interface IPCClientReconnectOptions {
|
|
97
|
+
/** Enable auto-reconnect (default: true) */
|
|
98
|
+
enabled?: boolean;
|
|
99
|
+
/** Max retry attempts (default: 5) */
|
|
100
|
+
maxRetries?: number;
|
|
101
|
+
/** Initial delay in ms (default: 1000) */
|
|
102
|
+
initialDelay?: number;
|
|
103
|
+
/** Backoff multiplier (default: 1.5) */
|
|
104
|
+
backoff?: number;
|
|
105
|
+
/** Max delay in ms (default: 30000) */
|
|
106
|
+
maxDelay?: number;
|
|
108
107
|
}
|
|
109
|
-
interface
|
|
110
|
-
|
|
111
|
-
|
|
108
|
+
interface IPCClientEvents extends BaseClientDriverEvents {
|
|
109
|
+
reconnect: [];
|
|
110
|
+
reconnecting: [attempt: number, delay: number];
|
|
112
111
|
}
|
|
113
|
-
declare
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
};
|
|
119
|
-
declare function getIPCPath(id: string, platform?: NodeJS.Platform): string;
|
|
120
|
-
declare function createIPCClient(options: IPCClientOptions): IPCSocketConnection;
|
|
121
|
-
declare function createIPCServer(options: IPCServerOptions): IPCServer;
|
|
122
|
-
declare function createIPCSocketConnection(socketPath: string, options?: IPCSocketConnectionOptions): IPCSocketConnection;
|
|
123
|
-
declare function createIPCSocketMessageHandler(options: IPCSocketMessageHandlerOptions): {
|
|
124
|
-
handleData: (chunk: Buffer) => void;
|
|
125
|
-
send: (message: Serializable) => void;
|
|
126
|
-
};
|
|
127
|
-
|
|
128
|
-
interface RPCErrorPayload {
|
|
129
|
-
message: string;
|
|
130
|
-
code?: number | string;
|
|
131
|
-
data?: Serializable;
|
|
112
|
+
declare enum IPCClientState {
|
|
113
|
+
Idle = 0,
|
|
114
|
+
Connecting = 1,
|
|
115
|
+
Connected = 2,
|
|
116
|
+
Disconnected = 3
|
|
132
117
|
}
|
|
133
|
-
declare
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
118
|
+
declare const DEFAULT_IPC_CLIENT_RECONNECT_OPTIONS: Required<IPCClientReconnectOptions>;
|
|
119
|
+
declare class IPCClient extends BaseClientDriver<IPCClientOptions, IPCClientEvents> {
|
|
120
|
+
private socket?;
|
|
121
|
+
private codec;
|
|
122
|
+
state: IPCClientState;
|
|
123
|
+
private _ready;
|
|
124
|
+
private reconnectTimer?;
|
|
125
|
+
private reconnectOptions;
|
|
126
|
+
private reconnectAttempt;
|
|
127
|
+
private isIntentionalClose;
|
|
128
|
+
private queue;
|
|
129
|
+
constructor(options: IPCClientOptions);
|
|
130
|
+
get path(): string;
|
|
131
|
+
get ready(): boolean;
|
|
132
|
+
connect(): Promise<void>;
|
|
133
|
+
send(message: Serializable): Promise<void>;
|
|
134
|
+
disconnect(): Promise<void>;
|
|
135
|
+
private init;
|
|
136
|
+
private cleanup;
|
|
137
|
+
private onSocketConnect;
|
|
138
|
+
private onSocketClose;
|
|
139
|
+
private onSocketError;
|
|
140
|
+
private onSocketData;
|
|
141
|
+
private scheduleReconnect;
|
|
142
|
+
private clearReconnectTimer;
|
|
143
|
+
private makeMessage;
|
|
144
|
+
private serialize;
|
|
145
|
+
private deserialize;
|
|
137
146
|
}
|
|
138
|
-
declare function
|
|
139
|
-
declare function deserializeRPCError(payload: RPCErrorPayload): RPCError;
|
|
147
|
+
declare function createIPCClient(options: IPCClientOptions): IPCClient;
|
|
140
148
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
/**
|
|
146
|
-
* Uses Unix Domain Sockets / Named Pipes for communications between processes.
|
|
147
|
-
*/
|
|
148
|
-
readonly IPC: "ipc";
|
|
149
|
-
};
|
|
150
|
-
type TransportDriver = ValueOf<typeof TransportDriver>;
|
|
151
|
-
interface TransportClientDriverSpecificOptions {
|
|
152
|
-
[TransportDriver.IPC]: IPCClientOptions;
|
|
153
|
-
}
|
|
154
|
-
interface TransportServerDriverSpecificOptions {
|
|
155
|
-
[TransportDriver.IPC]: IPCServerOptions;
|
|
156
|
-
}
|
|
157
|
-
type TransportClientOptions = {
|
|
158
|
-
[D in TransportDriver]: {
|
|
159
|
-
driver: D;
|
|
160
|
-
} & TransportClientDriverSpecificOptions[D];
|
|
161
|
-
}[TransportDriver];
|
|
162
|
-
type TransportServerOptions = {
|
|
163
|
-
[D in TransportDriver]: {
|
|
164
|
-
driver: D;
|
|
165
|
-
} & TransportServerDriverSpecificOptions[D];
|
|
166
|
-
}[TransportDriver];
|
|
167
|
-
interface TransportClient extends TransportClientProtocol, EventBus<TransportClientEvents> {
|
|
168
|
-
send: BaseServerDriver["send"];
|
|
169
|
-
connect: BaseClientDriver["connect"];
|
|
170
|
-
disconnect: BaseClientDriver["disconnect"];
|
|
171
|
-
readonly ready: boolean;
|
|
172
|
-
}
|
|
173
|
-
interface TransportServer extends TransportServerProtocol, EventBus<TransportServerEvents> {
|
|
174
|
-
broadcast: BaseServerDriver["broadcast"];
|
|
175
|
-
listen: BaseServerDriver["listen"];
|
|
176
|
-
close: BaseServerDriver["close"];
|
|
177
|
-
}
|
|
178
|
-
interface TransportClientProtocol {
|
|
179
|
-
request<T>(method: string, ...args: Serializable[]): Promise<T>;
|
|
149
|
+
interface IPCConnectionEvents {
|
|
150
|
+
message: [message: Serializable];
|
|
151
|
+
close: [];
|
|
152
|
+
error: [error: Error];
|
|
180
153
|
}
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
154
|
+
declare class IPCConnection extends EventEmitter<IPCConnectionEvents> {
|
|
155
|
+
server: IPCServer;
|
|
156
|
+
socket: Socket;
|
|
157
|
+
private codec;
|
|
158
|
+
constructor(server: IPCServer, socket: Socket);
|
|
159
|
+
send(message: Serializable): Promise<void>;
|
|
160
|
+
destroy(): void;
|
|
161
|
+
private setupListeners;
|
|
162
|
+
private handleData;
|
|
184
163
|
}
|
|
185
|
-
|
|
186
|
-
|
|
164
|
+
|
|
165
|
+
interface IPCServerOptions {
|
|
187
166
|
id: string;
|
|
188
|
-
|
|
189
|
-
args: Serializable[];
|
|
167
|
+
codec?: FrameCodecOptions;
|
|
190
168
|
}
|
|
191
|
-
type
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
169
|
+
type IPCServerEvents = BaseServerDriverEvents<IPCConnection>;
|
|
170
|
+
declare class IPCServer extends BaseServerDriver<IPCServerOptions, IPCConnection, IPCServerEvents> {
|
|
171
|
+
private server?;
|
|
172
|
+
private codecOptions;
|
|
173
|
+
connections: Collection<Socket, IPCConnection>;
|
|
174
|
+
codec: FrameCodec;
|
|
175
|
+
constructor(options: IPCServerOptions);
|
|
176
|
+
get path(): string;
|
|
177
|
+
listen(): Promise<void>;
|
|
178
|
+
private handleConnection;
|
|
179
|
+
send(connection: IPCConnection, message: Serializable): Awaitable<void>;
|
|
180
|
+
/**
|
|
181
|
+
* Send message to a specific client
|
|
182
|
+
*/
|
|
183
|
+
sendSocket(socket: Socket, message: Serializable): Promise<void>;
|
|
184
|
+
/**
|
|
185
|
+
* Broadcast to all connected clients
|
|
186
|
+
* Returns count of successful sends (fire-and-forget, errors emitted via 'clientError')
|
|
187
|
+
*/
|
|
188
|
+
broadcast(message: Serializable): Promise<void>;
|
|
189
|
+
/**
|
|
190
|
+
* Close server and disconnect all clients
|
|
191
|
+
*/
|
|
192
|
+
close(): Promise<void>;
|
|
193
|
+
private sendSocketFrame;
|
|
194
|
+
}
|
|
195
|
+
declare function createIPCServer(options: IPCServerOptions): IPCServer;
|
|
196
|
+
|
|
199
197
|
interface TransportClientEvents {
|
|
200
198
|
connect: [];
|
|
201
199
|
disconnect: [];
|
|
202
200
|
error: [error: Error];
|
|
201
|
+
message: [message: Serializable];
|
|
203
202
|
}
|
|
204
|
-
|
|
203
|
+
declare class TransportClient<D extends BaseClientDriver> extends EventEmitter<TransportClientEvents> {
|
|
204
|
+
readonly driver: D;
|
|
205
|
+
private pending;
|
|
206
|
+
constructor(driver: D);
|
|
207
|
+
connect(): _bakit_utils.Awaitable<void>;
|
|
208
|
+
disconnect(): _bakit_utils.Awaitable<void>;
|
|
209
|
+
request<Result extends Serializable>(method: string, ...args: Serializable[]): Promise<Result>;
|
|
210
|
+
send(message: Serializable): _bakit_utils.Awaitable<void>;
|
|
211
|
+
private setupDriverListeners;
|
|
212
|
+
private handleMessage;
|
|
213
|
+
private hydrateError;
|
|
214
|
+
private captureCallStack;
|
|
215
|
+
private isResponseMessage;
|
|
216
|
+
}
|
|
217
|
+
declare function createTransportClient<D extends BaseClientDriver<object, any>>(driver: D): TransportClient<D>;
|
|
218
|
+
|
|
219
|
+
type RPCHandler = (...args: Serializable[]) => Promise<Serializable | Error>;
|
|
220
|
+
interface TransportServerEvents<D extends BaseServerDriver> {
|
|
205
221
|
listen: [];
|
|
206
222
|
close: [];
|
|
207
223
|
error: [error: Error];
|
|
208
|
-
|
|
209
|
-
|
|
224
|
+
connectionAdd: [connection: D["_connectionType"]];
|
|
225
|
+
connectionRemove: [connection: D["_connectionType"]];
|
|
226
|
+
connectionError: [connection: D["_connectionType"], error: Error];
|
|
227
|
+
message: [connection: D["_connectionType"], message: Serializable];
|
|
210
228
|
}
|
|
211
|
-
declare
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
229
|
+
declare class TransportServer<D extends BaseServerDriver> extends EventEmitter<TransportServerEvents<D>> {
|
|
230
|
+
readonly driver: D;
|
|
231
|
+
private handlers;
|
|
232
|
+
constructor(driver: D);
|
|
233
|
+
get connections(): D["connections"];
|
|
234
|
+
handle(method: string, handler: RPCHandler): void;
|
|
235
|
+
listen(): ReturnType<D["listen"]>;
|
|
236
|
+
close(): ReturnType<D["close"]>;
|
|
237
|
+
broadcast(message: Serializable): ReturnType<D["broadcast"]>;
|
|
238
|
+
private setupDriverListeners;
|
|
239
|
+
private handleMessage;
|
|
240
|
+
private isRequestMessage;
|
|
241
|
+
}
|
|
242
|
+
declare function createTransportServer<D extends BaseServerDriver<object, any>>(driver: D): TransportServer<D>;
|
|
215
243
|
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
transport: TransportClientOptions & TransportServerOptions;
|
|
244
|
+
declare enum ServiceDriver {
|
|
245
|
+
IPC = "ipc"
|
|
219
246
|
}
|
|
220
|
-
interface
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
247
|
+
interface DriverOptionsMap {
|
|
248
|
+
[ServiceDriver.IPC]: {
|
|
249
|
+
id: string;
|
|
250
|
+
server?: Omit<IPCServerOptions, "id">;
|
|
251
|
+
client?: Omit<IPCClientOptions, "id">;
|
|
252
|
+
};
|
|
226
253
|
}
|
|
227
|
-
type
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
};
|
|
232
|
-
type ServiceRole = ValueOf<typeof ServiceRole>;
|
|
254
|
+
type ServiceOptions = {
|
|
255
|
+
[D in keyof DriverOptionsMap]: {
|
|
256
|
+
driver: D;
|
|
257
|
+
} & DriverOptionsMap[D];
|
|
258
|
+
}[keyof DriverOptionsMap];
|
|
233
259
|
interface ServiceClientRuntime {
|
|
234
|
-
role:
|
|
235
|
-
transport: TransportClient
|
|
260
|
+
role: "client";
|
|
261
|
+
transport: TransportClient<BaseClientDriver>;
|
|
236
262
|
}
|
|
237
263
|
interface ServiceServerRuntime {
|
|
238
|
-
role:
|
|
239
|
-
transport: TransportServer
|
|
240
|
-
}
|
|
241
|
-
type ServiceRuntime = ServiceClientRuntime | ServiceServerRuntime;
|
|
242
|
-
interface MutableRuntime {
|
|
243
|
-
role: ServiceRole | "unknown";
|
|
244
|
-
transport?: TransportClient | TransportServer;
|
|
264
|
+
role: "server";
|
|
265
|
+
transport: TransportServer<BaseServerDriver>;
|
|
245
266
|
}
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
267
|
+
declare class Service {
|
|
268
|
+
readonly options: ServiceOptions;
|
|
269
|
+
private runtime?;
|
|
270
|
+
private handlers;
|
|
271
|
+
private binding?;
|
|
272
|
+
constructor(options: ServiceOptions);
|
|
273
|
+
get role(): "client" | "server";
|
|
274
|
+
define<F extends FunctionLike>(method: string, handler: F): Promisify<F>;
|
|
275
|
+
protected ensureServerBound(): Promise<void> | undefined;
|
|
276
|
+
protected ensureClientBound(): Promise<void> | undefined;
|
|
249
277
|
}
|
|
250
278
|
declare function createService(options: ServiceOptions): Service;
|
|
251
|
-
declare function
|
|
252
|
-
declare function
|
|
253
|
-
|
|
254
|
-
|
|
279
|
+
declare function getServices(entryDir?: string, cwd?: string): Promise<string[]>;
|
|
280
|
+
declare function getServiceName(servicePath: string, cwd?: string): string;
|
|
281
|
+
|
|
282
|
+
interface ServiceProcessEvents {
|
|
283
|
+
stdout: [chunk: Buffer];
|
|
284
|
+
stderr: [chunk: Buffer];
|
|
285
|
+
spawn: [];
|
|
286
|
+
error: [err: Error];
|
|
287
|
+
exit: [code: number | null, signal: NodeJS.Signals | null];
|
|
288
|
+
}
|
|
289
|
+
declare enum ServiceState {
|
|
290
|
+
Idle = 0,
|
|
291
|
+
Starting = 1,
|
|
292
|
+
Running = 2,
|
|
293
|
+
Restarting = 3,
|
|
294
|
+
Stopping = 4,
|
|
295
|
+
Stopped = 5
|
|
296
|
+
}
|
|
297
|
+
declare class ServiceProcess extends EventEmitter<ServiceProcessEvents> {
|
|
298
|
+
readonly path: string;
|
|
299
|
+
private child?;
|
|
300
|
+
private spawnTimestamp;
|
|
301
|
+
private _state;
|
|
302
|
+
constructor(path: string);
|
|
303
|
+
get name(): string;
|
|
304
|
+
get state(): ServiceState;
|
|
305
|
+
get ready(): boolean;
|
|
306
|
+
get uptime(): number;
|
|
307
|
+
start(): void;
|
|
308
|
+
stop(): Promise<void>;
|
|
309
|
+
restart(): Promise<void>;
|
|
310
|
+
private init;
|
|
311
|
+
private cleanup;
|
|
312
|
+
private onChildSpawn;
|
|
313
|
+
private onChildExit;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
declare function getIPCPath(id: string, platform?: NodeJS.Platform): string;
|
|
317
|
+
declare function isServerRunning(path: string): Promise<boolean>;
|
|
318
|
+
|
|
319
|
+
declare function serializeRPCError(err: Error): RPCResponseError;
|
|
320
|
+
declare function createDynamicRPCError(data: RPCResponseError): Error;
|
|
321
|
+
declare function isSerializedError(value: unknown): value is RPCResponseError;
|
|
255
322
|
|
|
256
|
-
export {
|
|
323
|
+
export { BaseClientDriver, type BaseClientDriverEvents, BaseServerDriver, type BaseServerDriverEvents, DEFAULT_IPC_CLIENT_RECONNECT_OPTIONS, FrameCodec, type FrameCodecOptions, IPCClient, type IPCClientEvents, type IPCClientOptions, type IPCClientReconnectOptions, IPCClientState, IPCServer, type IPCServerEvents, type IPCServerOptions, type RPCHandler, Service, type ServiceClientRuntime, ServiceDriver, type ServiceOptions, ServiceProcess, type ServiceProcessEvents, type ServiceServerRuntime, ServiceState, TransportClient, type TransportClientEvents, TransportServer, type TransportServerEvents, createDynamicRPCError, createIPCClient, createIPCServer, createService, createTransportClient, createTransportServer, getIPCPath, getServiceName, getServices, isSerializedError, isServerRunning, serializeRPCError };
|