@vitejs/devtools-rpc 0.0.0-alpha.21 → 0.0.0-alpha.23

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,3 +1,14 @@
1
- import "../index.mjs";
2
- import { n as createWsRpcPreset, t as WebSocketRpcClientOptions } from "../../client-C3McYp9c.mjs";
1
+ import { RpcClientPreset } from "../index.mjs";
2
+ import { ChannelOptions } from "birpc";
3
+
4
+ //#region src/presets/ws/client.d.ts
5
+ interface WebSocketRpcClientOptions {
6
+ url: string;
7
+ onConnected?: (e: Event) => void;
8
+ onError?: (e: Error) => void;
9
+ onDisconnected?: (e: CloseEvent) => void;
10
+ authId?: string;
11
+ }
12
+ declare const createWsRpcPreset: RpcClientPreset<(options: WebSocketRpcClientOptions) => ChannelOptions>;
13
+ //#endregion
3
14
  export { WebSocketRpcClientOptions, createWsRpcPreset };
@@ -4,7 +4,9 @@ import { parse, stringify } from "structured-clone-es";
4
4
  //#region src/presets/ws/client.ts
5
5
  function NOOP() {}
6
6
  const createWsRpcPreset = defineRpcClientPreset((options) => {
7
- const ws = new WebSocket(options.url);
7
+ let url = options.url;
8
+ if (options.authId) url = `${url}?vite_devtools_auth_id=${encodeURIComponent(options.authId)}`;
9
+ const ws = new WebSocket(url);
8
10
  const { onConnected = NOOP, onError = NOOP, onDisconnected = NOOP } = options;
9
11
  ws.addEventListener("open", (e) => {
10
12
  onConnected(e);
@@ -1,503 +1,22 @@
1
1
  import { RpcServerPreset } from "../index.mjs";
2
- import { BirpcGroup, BirpcOptions, BirpcReturn } from "birpc";
3
- import { RpcFunctionsCollector, RpcFunctionsCollectorBase } from "birpc-x";
2
+ import { BirpcGroup, BirpcOptions } from "birpc";
3
+ import { IncomingMessage } from "node:http";
4
4
  import { WebSocket } from "ws";
5
- import { ResolvedConfig, ViteDevServer } from "vite";
6
- import { Raw } from "vue";
7
- import { ChildProcess } from "node:child_process";
8
5
 
9
- //#region ../kit/src/types/events.d.ts
10
- interface EventsMap {
11
- [event: string]: any;
12
- }
13
- interface EventUnsubscribe {
14
- (): void;
15
- }
16
- interface EventEmitter<Events extends EventsMap> {
17
- /**
18
- * Calls each of the listeners registered for a given event.
19
- *
20
- * ```js
21
- * ee.emit('tick', tickType, tickDuration)
22
- * ```
23
- *
24
- * @param event The event name.
25
- * @param args The arguments for listeners.
26
- */
27
- emit: <K extends keyof Events>(event: K, ...args: Parameters<Events[K]>) => void;
28
- /**
29
- * Calls the listeners for a given event once and then removes the listener.
30
- *
31
- * @param event The event name.
32
- * @param args The arguments for listeners.
33
- */
34
- emitOnce: <K extends keyof Events>(event: K, ...args: Parameters<Events[K]>) => void;
35
- /**
36
- * Event names in keys and arrays with listeners in values.
37
- *
38
- * @internal
39
- */
40
- _listeners: Partial<{ [E in keyof Events]: Events[E][] }>;
41
- /**
42
- * Add a listener for a given event.
43
- *
44
- * ```js
45
- * const unbind = ee.on('tick', (tickType, tickDuration) => {
46
- * count += 1
47
- * })
48
- *
49
- * disable () {
50
- * unbind()
51
- * }
52
- * ```
53
- *
54
- * @param event The event name.
55
- * @param cb The listener function.
56
- * @returns Unbind listener from event.
57
- */
58
- on: <K extends keyof Events>(event: K, cb: Events[K]) => EventUnsubscribe;
59
- /**
60
- * Add a listener for a given event once.
61
- *
62
- * ```js
63
- * const unbind = ee.once('tick', (tickType, tickDuration) => {
64
- * count += 1
65
- * })
66
- *
67
- * disable () {
68
- * unbind()
69
- * }
70
- * ```
71
- *
72
- * @param event The event name.
73
- * @param cb The listener function.
74
- * @returns Unbind listener from event.
75
- */
76
- once: <K extends keyof Events>(event: K, cb: Events[K]) => EventUnsubscribe;
77
- }
78
- //#endregion
79
- //#region ../kit/src/types/docks.d.ts
80
- interface DevToolsDockHost {
81
- readonly views: Map<string, DevToolsDockUserEntry>;
82
- readonly events: EventEmitter<{
83
- 'dock:entry:updated': (entry: DevToolsDockUserEntry) => void;
84
- }>;
85
- register: <T extends DevToolsDockUserEntry>(entry: T, force?: boolean) => {
86
- update: (patch: Partial<T>) => void;
87
- };
88
- update: (entry: DevToolsDockUserEntry) => void;
89
- values: () => DevToolsDockUserEntry[];
90
- }
91
- type DevToolsDockEntryCategory = 'app' | 'framework' | 'web' | 'advanced' | 'default';
92
- type DevToolsDockEntryIcon = string | {
93
- light: string;
94
- dark: string;
95
- };
96
- interface DevToolsDockEntryBase {
97
- id: string;
98
- title: string;
99
- icon: DevToolsDockEntryIcon;
100
- /**
101
- * The default order of the entry in the dock.
102
- * The higher the number the earlier it appears.
103
- * @default 0
104
- */
105
- defaultOrder?: number;
106
- /**
107
- * The category of the entry
108
- * @default 'default'
109
- */
110
- category?: DevToolsDockEntryCategory;
111
- /**
112
- * Whether the entry should be hidden from the user.
113
- * @default false
114
- */
115
- isHidden?: boolean;
116
- }
117
- interface ClientScriptEntry {
118
- /**
119
- * The filepath or module name to import from
120
- */
121
- importFrom: string;
122
- /**
123
- * The name to import the module as
124
- *
125
- * @default 'default'
126
- */
127
- importName?: string;
128
- }
129
- interface DevToolsViewIframe extends DevToolsDockEntryBase {
130
- type: 'iframe';
131
- url: string;
132
- /**
133
- * The id of the iframe, if multiple tabs is assigned with the same id, the iframe will be shared.
134
- *
135
- * When not provided, it would be treated as a unique frame.
136
- */
137
- frameId?: string;
138
- /**
139
- * Optional client script to import into the iframe
140
- */
141
- clientScript?: ClientScriptEntry;
142
- }
143
- type DevToolsViewLauncherStatus = 'idle' | 'loading' | 'success' | 'error';
144
- interface DevToolsViewLauncher extends DevToolsDockEntryBase {
145
- type: 'launcher';
146
- launcher: {
147
- icon?: DevToolsDockEntryIcon;
148
- title: string;
149
- status?: DevToolsViewLauncherStatus;
150
- error?: string;
151
- description?: string;
152
- buttonStart?: string;
153
- buttonLoading?: string;
154
- onLaunch: () => Promise<void>;
155
- };
156
- }
157
- interface DevToolsViewAction extends DevToolsDockEntryBase {
158
- type: 'action';
159
- action: ClientScriptEntry;
160
- }
161
- interface DevToolsViewCustomRender extends DevToolsDockEntryBase {
162
- type: 'custom-render';
163
- renderer: ClientScriptEntry;
164
- }
165
- interface DevToolsViewBuiltin extends DevToolsDockEntryBase {
166
- type: '~builtin';
167
- id: '~terminals' | '~logs' | '~client-auth-notice';
168
- }
169
- type DevToolsDockUserEntry = DevToolsViewIframe | DevToolsViewAction | DevToolsViewCustomRender | DevToolsViewLauncher;
170
- type DevToolsDockEntry = DevToolsDockUserEntry | DevToolsViewBuiltin;
171
- //#endregion
172
- //#region ../kit/src/types/rpc-augments.d.ts
173
- /**
174
- * To be extended
175
- */
176
- interface DevToolsRpcClientFunctions {}
177
- /**
178
- * To be extended
179
- */
180
- interface DevToolsRpcServerFunctions {}
181
- //#endregion
182
- //#region ../kit/src/client/rpc.d.ts
183
- interface DevToolsRpcClient {
184
- /**
185
- * The events of the client
186
- */
187
- events: EventEmitter<RpcClientEvents>;
188
- /**
189
- * Whether the client is trusted
190
- */
191
- readonly isTrusted: boolean | null;
192
- /**
193
- * The connection meta
194
- */
195
- readonly connectionMeta: ConnectionMeta;
196
- /**
197
- * Return a promise that resolves when the client is trusted
198
- *
199
- * Rejects with an error if the timeout is reached
200
- *
201
- * @param timeout - The timeout in milliseconds, default to 60 seconds
202
- */
203
- ensureTrusted: (timeout?: number) => Promise<boolean>;
204
- /**
205
- * Request trust from the server
206
- */
207
- requestTrust: () => Promise<boolean>;
208
- /**
209
- * Call a RPC function on the server
210
- */
211
- call: BirpcReturn<DevToolsRpcServerFunctions, DevToolsRpcClientFunctions>['$call'];
212
- /**
213
- * Call a RPC event on the server, and does not expect a response
214
- */
215
- callEvent: BirpcReturn<DevToolsRpcServerFunctions, DevToolsRpcClientFunctions>['$callEvent'];
216
- /**
217
- * Call a RPC optional function on the server
218
- */
219
- callOptional: BirpcReturn<DevToolsRpcServerFunctions, DevToolsRpcClientFunctions>['$callOptional'];
220
- /**
221
- * The client RPC host
222
- */
223
- client: DevToolsClientRpcHost;
224
- }
225
- //#endregion
226
- //#region ../kit/src/client/docks.d.ts
227
- interface DockPanelStorage {
228
- width: number;
229
- height: number;
230
- top: number;
231
- left: number;
232
- position: 'left' | 'right' | 'bottom' | 'top';
233
- open: boolean;
234
- inactiveTimeout: number;
235
- }
236
- interface DevToolsClientContext {
237
- /**
238
- * The RPC client to interact with the server
239
- */
240
- readonly rpc: DevToolsRpcClient;
241
- }
242
- interface DocksContext extends DevToolsClientContext {
243
- /**
244
- * Type of the client environment
245
- *
246
- * 'embedded' - running inside an embedded floating panel
247
- * 'standalone' - running inside a standalone window (no user app)
248
- */
249
- readonly clientType: 'embedded' | 'standalone';
250
- /**
251
- * The panel context
252
- */
253
- readonly panel: DocksPanelContext;
254
- /**
255
- * The docks entries context
256
- */
257
- readonly docks: DocksEntriesContext;
258
- }
259
- type DevToolsClientRpcHost = RpcFunctionsCollector<DevToolsRpcClientFunctions, DevToolsClientContext>;
260
- interface DocksPanelContext {
261
- store: DockPanelStorage;
262
- isDragging: boolean;
263
- isResizing: boolean;
264
- readonly isVertical: boolean;
265
- }
266
- interface DocksEntriesContext {
267
- selectedId: string | null;
268
- readonly selected: DevToolsDockEntry | null;
269
- entries: DevToolsDockEntry[];
270
- entryToStateMap: Map<string, DockEntryState>;
271
- /**
272
- * Get the state of a dock entry by its ID
273
- */
274
- getStateById: (id: string) => DockEntryState | undefined;
275
- /**
276
- * Switch to the selected dock entry, pass `null` to clear the selection
277
- *
278
- * @returns Whether the selection was changed successfully
279
- */
280
- switchEntry: (id?: string | null) => Promise<boolean>;
281
- /**
282
- * Toggle the selected dock entry
283
- *
284
- * @returns Whether the selection was changed successfully
285
- */
286
- toggleEntry: (id: string) => Promise<boolean>;
287
- }
288
- interface DockEntryState {
289
- entryMeta: DevToolsDockEntry;
290
- readonly isActive: boolean;
291
- domElements: {
292
- iframe?: HTMLIFrameElement | null;
293
- panel?: HTMLDivElement | null;
294
- };
295
- events: Raw<EventEmitter<DockEntryStateEvents>>;
296
- }
297
- interface DockEntryStateEvents {
298
- 'entry:activated': () => void;
299
- 'entry:deactivated': () => void;
300
- 'entry:updated': (newMeta: DevToolsDockUserEntry) => void;
301
- 'dom:panel:mounted': (panel: HTMLDivElement) => void;
302
- 'dom:iframe:mounted': (iframe: HTMLIFrameElement) => void;
303
- }
304
- interface RpcClientEvents {
305
- 'rpc:is-trusted:updated': (isTrusted: boolean) => void;
306
- }
307
- //#endregion
308
- //#region ../kit/src/client/client-script.d.ts
309
- /**
310
- * Context for client scripts running in dock entries
311
- */
312
- interface DockClientScriptContext extends DocksContext {
313
- /**
314
- * The state of the current dock entry
315
- */
316
- current: DockEntryState;
317
- }
318
- //#endregion
319
- //#region ../kit/src/types/terminals.d.ts
320
- interface DevToolsTerminalSessionStreamChunkEvent {
321
- id: string;
322
- chunks: string[];
323
- ts: number;
324
- }
325
- interface DevToolsTerminalHost {
326
- readonly sessions: Map<string, DevToolsTerminalSession>;
327
- readonly events: EventEmitter<{
328
- 'terminal:session:updated': (session: DevToolsTerminalSession) => void;
329
- 'terminal:session:stream-chunk': (data: DevToolsTerminalSessionStreamChunkEvent) => void;
330
- }>;
331
- register: (session: DevToolsTerminalSession) => DevToolsTerminalSession;
332
- update: (session: DevToolsTerminalSession) => void;
333
- startChildProcess: (executeOptions: DevToolsChildProcessExecuteOptions, terminal: Omit<DevToolsTerminalSessionBase, 'status'>) => Promise<DevToolsChildProcessTerminalSession>;
334
- }
335
- type DevToolsTerminalStatus = 'running' | 'stopped' | 'error';
336
- interface DevToolsTerminalSessionBase {
337
- id: string;
338
- title: string;
339
- description?: string;
340
- status: DevToolsTerminalStatus;
341
- icon?: DevToolsDockEntryIcon;
342
- }
343
- interface DevToolsTerminalSession extends DevToolsTerminalSessionBase {
344
- buffer?: string[];
345
- stream?: ReadableStream<string>;
346
- }
347
- interface DevToolsChildProcessExecuteOptions {
348
- command: string;
349
- args: string[];
350
- cwd?: string;
351
- env?: Record<string, string>;
352
- }
353
- interface DevToolsChildProcessTerminalSession extends DevToolsTerminalSession {
354
- type: 'child-process';
355
- executeOptions: DevToolsChildProcessExecuteOptions;
356
- getChildProcess: () => ChildProcess | undefined;
357
- terminate: () => Promise<void>;
358
- restart: () => Promise<void>;
359
- }
360
- //#endregion
361
- //#region ../kit/src/types/views.d.ts
362
- interface DevToolsViewHost {
363
- /**
364
- * @internal
365
- */
366
- buildStaticDirs: {
367
- baseUrl: string;
368
- distDir: string;
369
- }[];
370
- /**
371
- * Helper to host static files
372
- * - In `dev` mode, it will register middleware to `viteServer.middlewares` to host the static files
373
- * - In `build` mode, it will copy the static files to the dist directory
374
- */
375
- hostStatic: (baseUrl: string, distDir: string) => void;
376
- }
377
- //#endregion
378
- //#region ../kit/src/types/vite-plugin.d.ts
379
- interface DevToolsCapabilities {
380
- rpc?: boolean;
381
- views?: boolean;
382
- }
383
- interface DevToolsPluginOptions {
384
- capabilities?: {
385
- dev?: DevToolsCapabilities | boolean;
386
- build?: DevToolsCapabilities | boolean;
387
- };
388
- setup: (context: DevToolsNodeContext) => void | Promise<void>;
389
- }
390
- interface DevToolsNodeContext {
391
- /**
392
- * Workspace root directory of Vite DevTools
393
- */
394
- readonly workspaceRoot: string;
395
- /**
396
- * Current working directory of Vite DevTools
397
- */
398
- readonly cwd: string;
399
- /**
400
- * Current mode of Vite DevTools
401
- * - 'dev' - when Vite DevTools is running in dev mode
402
- * - 'build' - when Vite DevTools is running in build mode (no server)
403
- */
404
- readonly mode: 'dev' | 'build';
405
- /**
406
- * Resolved Vite configuration
407
- */
408
- readonly viteConfig: ResolvedConfig;
409
- /**
410
- * Vite dev server instance (only available in dev mode)
411
- */
412
- readonly viteServer?: ViteDevServer;
413
- /**
414
- * RPC functions host, for registering server-side RPC functions and calling client-side RPC functions
415
- */
416
- rpc: RpcFunctionsHost;
417
- /**
418
- * Docks host, for registering dock entries
419
- */
420
- docks: DevToolsDockHost;
421
- /**
422
- * Views host, for registering static views
423
- */
424
- views: DevToolsViewHost;
425
- /**
426
- * Utils for the node context
427
- */
428
- utils: DevToolsNodeUtils;
429
- /**
430
- * Terminals host, for registering terminal sessions and streaming terminal output
431
- */
432
- terminals: DevToolsTerminalHost;
433
- }
434
- interface DevToolsNodeUtils {
435
- /**
436
- * Create a simple client script from a function or stringified code
437
- *
438
- * @deprecated DO NOT USE. This is mostly for testing only. Please use a proper importable module instead.
439
- * @experimental
440
- */
441
- createSimpleClientScript: (fn: string | ((ctx: DockClientScriptContext) => void)) => ClientScriptEntry;
442
- }
443
- interface ConnectionMeta {
444
- backend: 'websocket' | 'static';
445
- websocket?: number | string;
446
- }
447
- //#endregion
448
- //#region ../kit/src/types/rpc.d.ts
6
+ //#region src/presets/ws/server.d.ts
449
7
  interface DevToolsNodeRpcSessionMeta {
450
8
  id: number;
451
9
  ws?: WebSocket;
452
10
  clientAuthId?: string;
453
11
  isTrusted?: boolean;
12
+ subscribedStates: Set<string>;
454
13
  }
455
- interface DevToolsNodeRpcSession {
456
- meta: DevToolsNodeRpcSessionMeta;
457
- rpc: BirpcReturn<DevToolsRpcClientFunctions, DevToolsRpcServerFunctions, false>;
458
- }
459
- type RpcFunctionsHost = RpcFunctionsCollectorBase<DevToolsRpcServerFunctions, DevToolsNodeContext> & {
460
- /**
461
- * Broadcast a message to all connected clients
462
- */
463
- broadcast: <T extends keyof DevToolsRpcClientFunctions, Args extends Parameters<DevToolsRpcClientFunctions[T]>>(name: T, ...args: Args) => Promise<(Awaited<ReturnType<DevToolsRpcClientFunctions[T]>> | undefined)[]>;
464
- /**
465
- * Get the current RPC client
466
- *
467
- * Available in RPC functions to get the current RPC client
468
- */
469
- getCurrentRpcSession: () => DevToolsNodeRpcSession | undefined;
470
- };
471
- //#endregion
472
- //#region ../kit/src/types/vite-augment.d.ts
473
- declare module 'vite' {
474
- interface Plugin {
475
- devtools?: DevToolsPluginOptions;
476
- }
477
- interface UserConfig {
478
- devtools?: ViteConfigDevtoolsOptions;
479
- }
480
- }
481
- interface ViteConfigDevtoolsOptions {
482
- /**
483
- * Disable client authentication.
484
- *
485
- * Beware that if you disable client authentication,
486
- * any browsers can connect to the devtools and access to your server and filesystem.
487
- * (including other devices, if you open server `host` option to LAN or WAN)
488
- *
489
- * @default true
490
- */
491
- clientAuth?: boolean;
492
- }
493
- //#endregion
494
- //#region src/presets/ws/server.d.ts
495
14
  interface WebSocketRpcServerOptions {
496
15
  port: number;
497
16
  host?: string;
498
- onConnected?: (ws: WebSocket, meta: DevToolsNodeRpcSessionMeta) => void;
17
+ onConnected?: (ws: WebSocket, req: IncomingMessage, meta: DevToolsNodeRpcSessionMeta) => void;
499
18
  onDisconnected?: (ws: WebSocket, meta: DevToolsNodeRpcSessionMeta) => void;
500
19
  }
501
20
  declare const createWsRpcPreset: RpcServerPreset<(options: WebSocketRpcServerOptions) => <ClientFunctions extends object, ServerFunctions extends object>(rpc: BirpcGroup<ClientFunctions, ServerFunctions, false>, options?: Pick<BirpcOptions<ClientFunctions, ServerFunctions, false>, 'serialize' | 'deserialize'>) => void>;
502
21
  //#endregion
503
- export { WebSocketRpcServerOptions, createWsRpcPreset };
22
+ export { DevToolsNodeRpcSessionMeta, WebSocketRpcServerOptions, createWsRpcPreset };
@@ -31,7 +31,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
31
31
  var __require = /* @__PURE__ */ createRequire(import.meta.url);
32
32
 
33
33
  //#endregion
34
- //#region ../../node_modules/.pnpm/ws@8.18.3/node_modules/ws/lib/constants.js
34
+ //#region ../../node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/constants.js
35
35
  var require_constants = /* @__PURE__ */ __commonJSMin(((exports, module) => {
36
36
  const BINARY_TYPES = [
37
37
  "nodebuffer",
@@ -42,6 +42,7 @@ var require_constants = /* @__PURE__ */ __commonJSMin(((exports, module) => {
42
42
  if (hasBlob) BINARY_TYPES.push("blob");
43
43
  module.exports = {
44
44
  BINARY_TYPES,
45
+ CLOSE_TIMEOUT: 3e4,
45
46
  EMPTY_BUFFER: Buffer.alloc(0),
46
47
  GUID: "258EAFA5-E914-47DA-95CA-C5AB0DC85B11",
47
48
  hasBlob,
@@ -54,7 +55,7 @@ var require_constants = /* @__PURE__ */ __commonJSMin(((exports, module) => {
54
55
  }));
55
56
 
56
57
  //#endregion
57
- //#region ../../node_modules/.pnpm/ws@8.18.3/node_modules/ws/lib/buffer-util.js
58
+ //#region ../../node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/buffer-util.js
58
59
  var require_buffer_util = /* @__PURE__ */ __commonJSMin(((exports, module) => {
59
60
  const { EMPTY_BUFFER } = require_constants();
60
61
  const FastBuffer = Buffer[Symbol.species];
@@ -155,7 +156,7 @@ var require_buffer_util = /* @__PURE__ */ __commonJSMin(((exports, module) => {
155
156
  }));
156
157
 
157
158
  //#endregion
158
- //#region ../../node_modules/.pnpm/ws@8.18.3/node_modules/ws/lib/limiter.js
159
+ //#region ../../node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/limiter.js
159
160
  var require_limiter = /* @__PURE__ */ __commonJSMin(((exports, module) => {
160
161
  const kDone = Symbol("kDone");
161
162
  const kRun = Symbol("kRun");
@@ -207,7 +208,7 @@ var require_limiter = /* @__PURE__ */ __commonJSMin(((exports, module) => {
207
208
  }));
208
209
 
209
210
  //#endregion
210
- //#region ../../node_modules/.pnpm/ws@8.18.3/node_modules/ws/lib/permessage-deflate.js
211
+ //#region ../../node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/permessage-deflate.js
211
212
  var require_permessage_deflate = /* @__PURE__ */ __commonJSMin(((exports, module) => {
212
213
  const zlib = __require("zlib");
213
214
  const bufferUtil = require_buffer_util();
@@ -541,7 +542,7 @@ var require_permessage_deflate = /* @__PURE__ */ __commonJSMin(((exports, module
541
542
  }));
542
543
 
543
544
  //#endregion
544
- //#region ../../node_modules/.pnpm/ws@8.18.3/node_modules/ws/lib/validation.js
545
+ //#region ../../node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/validation.js
545
546
  var require_validation = /* @__PURE__ */ __commonJSMin(((exports, module) => {
546
547
  const { isUtf8 } = __require("buffer");
547
548
  const { hasBlob } = require_constants();
@@ -738,7 +739,7 @@ var require_validation = /* @__PURE__ */ __commonJSMin(((exports, module) => {
738
739
  }));
739
740
 
740
741
  //#endregion
741
- //#region ../../node_modules/.pnpm/ws@8.18.3/node_modules/ws/lib/receiver.js
742
+ //#region ../../node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/receiver.js
742
743
  var require_receiver = /* @__PURE__ */ __commonJSMin(((exports, module) => {
743
744
  const { Writable } = __require("stream");
744
745
  const PerMessageDeflate = require_permessage_deflate();
@@ -1186,7 +1187,7 @@ var require_receiver = /* @__PURE__ */ __commonJSMin(((exports, module) => {
1186
1187
  }));
1187
1188
 
1188
1189
  //#endregion
1189
- //#region ../../node_modules/.pnpm/ws@8.18.3/node_modules/ws/lib/sender.js
1190
+ //#region ../../node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/sender.js
1190
1191
  var require_sender = /* @__PURE__ */ __commonJSMin(((exports, module) => {
1191
1192
  const { Duplex: Duplex$3 } = __require("stream");
1192
1193
  const { randomFillSync } = __require("crypto");
@@ -1682,7 +1683,7 @@ var require_sender = /* @__PURE__ */ __commonJSMin(((exports, module) => {
1682
1683
  }));
1683
1684
 
1684
1685
  //#endregion
1685
- //#region ../../node_modules/.pnpm/ws@8.18.3/node_modules/ws/lib/event-target.js
1686
+ //#region ../../node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/event-target.js
1686
1687
  var require_event_target = /* @__PURE__ */ __commonJSMin(((exports, module) => {
1687
1688
  const { kForOnEventAttribute, kListener } = require_constants();
1688
1689
  const kCode = Symbol("kCode");
@@ -1902,7 +1903,7 @@ var require_event_target = /* @__PURE__ */ __commonJSMin(((exports, module) => {
1902
1903
  }));
1903
1904
 
1904
1905
  //#endregion
1905
- //#region ../../node_modules/.pnpm/ws@8.18.3/node_modules/ws/lib/extension.js
1906
+ //#region ../../node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/extension.js
1906
1907
  var require_extension = /* @__PURE__ */ __commonJSMin(((exports, module) => {
1907
1908
  const { tokenChars } = require_validation();
1908
1909
  /**
@@ -2046,7 +2047,7 @@ var require_extension = /* @__PURE__ */ __commonJSMin(((exports, module) => {
2046
2047
  }));
2047
2048
 
2048
2049
  //#endregion
2049
- //#region ../../node_modules/.pnpm/ws@8.18.3/node_modules/ws/lib/websocket.js
2050
+ //#region ../../node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/websocket.js
2050
2051
  var require_websocket = /* @__PURE__ */ __commonJSMin(((exports, module) => {
2051
2052
  const EventEmitter$1 = __require("events");
2052
2053
  const https = __require("https");
@@ -2060,11 +2061,10 @@ var require_websocket = /* @__PURE__ */ __commonJSMin(((exports, module) => {
2060
2061
  const Receiver = require_receiver();
2061
2062
  const Sender = require_sender();
2062
2063
  const { isBlob } = require_validation();
2063
- const { BINARY_TYPES, EMPTY_BUFFER, GUID, kForOnEventAttribute, kListener, kStatusCode, kWebSocket, NOOP } = require_constants();
2064
+ const { BINARY_TYPES, CLOSE_TIMEOUT, EMPTY_BUFFER, GUID, kForOnEventAttribute, kListener, kStatusCode, kWebSocket, NOOP } = require_constants();
2064
2065
  const { EventTarget: { addEventListener, removeEventListener } } = require_event_target();
2065
2066
  const { format, parse } = require_extension();
2066
2067
  const { toBuffer } = require_buffer_util();
2067
- const closeTimeout = 30 * 1e3;
2068
2068
  const kAborted = Symbol("kAborted");
2069
2069
  const protocolVersions = [8, 13];
2070
2070
  const readyStates = [
@@ -2115,6 +2115,7 @@ var require_websocket = /* @__PURE__ */ __commonJSMin(((exports, module) => {
2115
2115
  initAsClient(this, address, protocols, options);
2116
2116
  } else {
2117
2117
  this._autoPong = options.autoPong;
2118
+ this._closeTimeout = options.closeTimeout;
2118
2119
  this._isServer = true;
2119
2120
  }
2120
2121
  }
@@ -2535,6 +2536,8 @@ var require_websocket = /* @__PURE__ */ __commonJSMin(((exports, module) => {
2535
2536
  * times in the same tick
2536
2537
  * @param {Boolean} [options.autoPong=true] Specifies whether or not to
2537
2538
  * automatically send a pong in response to a ping
2539
+ * @param {Number} [options.closeTimeout=30000] Duration in milliseconds to wait
2540
+ * for the closing handshake to finish after `websocket.close()` is called
2538
2541
  * @param {Function} [options.finishRequest] A function which can be used to
2539
2542
  * customize the headers of each http request before it is sent
2540
2543
  * @param {Boolean} [options.followRedirects=false] Whether or not to follow
@@ -2561,6 +2564,7 @@ var require_websocket = /* @__PURE__ */ __commonJSMin(((exports, module) => {
2561
2564
  const opts = {
2562
2565
  allowSynchronousEvents: true,
2563
2566
  autoPong: true,
2567
+ closeTimeout: CLOSE_TIMEOUT,
2564
2568
  protocolVersion: protocolVersions[1],
2565
2569
  maxPayload: 100 * 1024 * 1024,
2566
2570
  skipUTF8Validation: false,
@@ -2578,6 +2582,7 @@ var require_websocket = /* @__PURE__ */ __commonJSMin(((exports, module) => {
2578
2582
  port: void 0
2579
2583
  };
2580
2584
  websocket._autoPong = opts.autoPong;
2585
+ websocket._closeTimeout = opts.closeTimeout;
2581
2586
  if (!protocolVersions.includes(opts.protocolVersion)) throw new RangeError(`Unsupported protocol version: ${opts.protocolVersion} (supported versions: ${protocolVersions.join(", ")})`);
2582
2587
  let parsedUrl;
2583
2588
  if (address instanceof URL) parsedUrl = address;
@@ -2951,7 +2956,7 @@ var require_websocket = /* @__PURE__ */ __commonJSMin(((exports, module) => {
2951
2956
  * @private
2952
2957
  */
2953
2958
  function setCloseTimer(websocket) {
2954
- websocket._closeTimer = setTimeout(websocket._socket.destroy.bind(websocket._socket), closeTimeout);
2959
+ websocket._closeTimer = setTimeout(websocket._socket.destroy.bind(websocket._socket), websocket._closeTimeout);
2955
2960
  }
2956
2961
  /**
2957
2962
  * The listener of the socket `'close'` event.
@@ -2964,8 +2969,10 @@ var require_websocket = /* @__PURE__ */ __commonJSMin(((exports, module) => {
2964
2969
  this.removeListener("data", socketOnData);
2965
2970
  this.removeListener("end", socketOnEnd);
2966
2971
  websocket._readyState = WebSocket.CLOSING;
2967
- let chunk;
2968
- if (!this._readableState.endEmitted && !websocket._closeFrameReceived && !websocket._receiver._writableState.errorEmitted && (chunk = websocket._socket.read()) !== null) websocket._receiver.write(chunk);
2972
+ if (!this._readableState.endEmitted && !websocket._closeFrameReceived && !websocket._receiver._writableState.errorEmitted && this._readableState.length !== 0) {
2973
+ const chunk = this.read(this._readableState.length);
2974
+ websocket._receiver.write(chunk);
2975
+ }
2969
2976
  websocket._receiver.end();
2970
2977
  this[kWebSocket] = void 0;
2971
2978
  clearTimeout(websocket._closeTimer);
@@ -3012,7 +3019,7 @@ var require_websocket = /* @__PURE__ */ __commonJSMin(((exports, module) => {
3012
3019
  }));
3013
3020
 
3014
3021
  //#endregion
3015
- //#region ../../node_modules/.pnpm/ws@8.18.3/node_modules/ws/lib/stream.js
3022
+ //#region ../../node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/stream.js
3016
3023
  var require_stream = /* @__PURE__ */ __commonJSMin(((exports, module) => {
3017
3024
  require_websocket();
3018
3025
  const { Duplex: Duplex$1 } = __require("stream");
@@ -3129,7 +3136,7 @@ var require_stream = /* @__PURE__ */ __commonJSMin(((exports, module) => {
3129
3136
  }));
3130
3137
 
3131
3138
  //#endregion
3132
- //#region ../../node_modules/.pnpm/ws@8.18.3/node_modules/ws/lib/subprotocol.js
3139
+ //#region ../../node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/subprotocol.js
3133
3140
  var require_subprotocol = /* @__PURE__ */ __commonJSMin(((exports, module) => {
3134
3141
  const { tokenChars } = require_validation();
3135
3142
  /**
@@ -3169,7 +3176,7 @@ var require_subprotocol = /* @__PURE__ */ __commonJSMin(((exports, module) => {
3169
3176
  }));
3170
3177
 
3171
3178
  //#endregion
3172
- //#region ../../node_modules/.pnpm/ws@8.18.3/node_modules/ws/lib/websocket-server.js
3179
+ //#region ../../node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/websocket-server.js
3173
3180
  var require_websocket_server = /* @__PURE__ */ __commonJSMin(((exports, module) => {
3174
3181
  const EventEmitter = __require("events");
3175
3182
  const http = __require("http");
@@ -3179,7 +3186,7 @@ var require_websocket_server = /* @__PURE__ */ __commonJSMin(((exports, module)
3179
3186
  const PerMessageDeflate = require_permessage_deflate();
3180
3187
  const subprotocol = require_subprotocol();
3181
3188
  const WebSocket = require_websocket();
3182
- const { GUID, kWebSocket } = require_constants();
3189
+ const { CLOSE_TIMEOUT, GUID, kWebSocket } = require_constants();
3183
3190
  const keyRegex = /^[+/0-9A-Za-z]{22}==$/;
3184
3191
  const RUNNING = 0;
3185
3192
  const CLOSING = 1;
@@ -3203,6 +3210,9 @@ var require_websocket_server = /* @__PURE__ */ __commonJSMin(((exports, module)
3203
3210
  * pending connections
3204
3211
  * @param {Boolean} [options.clientTracking=true] Specifies whether or not to
3205
3212
  * track clients
3213
+ * @param {Number} [options.closeTimeout=30000] Duration in milliseconds to
3214
+ * wait for the closing handshake to finish after `websocket.close()` is
3215
+ * called
3206
3216
  * @param {Function} [options.handleProtocols] A hook to handle protocols
3207
3217
  * @param {String} [options.host] The hostname where to bind the server
3208
3218
  * @param {Number} [options.maxPayload=104857600] The maximum allowed message
@@ -3231,6 +3241,7 @@ var require_websocket_server = /* @__PURE__ */ __commonJSMin(((exports, module)
3231
3241
  perMessageDeflate: false,
3232
3242
  handleProtocols: null,
3233
3243
  clientTracking: true,
3244
+ closeTimeout: CLOSE_TIMEOUT,
3234
3245
  verifyClient: null,
3235
3246
  noServer: false,
3236
3247
  backlog: null,
@@ -3540,7 +3551,7 @@ var require_websocket_server = /* @__PURE__ */ __commonJSMin(((exports, module)
3540
3551
  }));
3541
3552
 
3542
3553
  //#endregion
3543
- //#region ../../node_modules/.pnpm/ws@8.18.3/node_modules/ws/wrapper.mjs
3554
+ //#region ../../node_modules/.pnpm/ws@8.19.0/node_modules/ws/wrapper.mjs
3544
3555
  var import_stream = /* @__PURE__ */ __toESM(require_stream(), 1);
3545
3556
  var import_receiver = /* @__PURE__ */ __toESM(require_receiver(), 1);
3546
3557
  var import_sender = /* @__PURE__ */ __toESM(require_sender(), 1);
@@ -3557,12 +3568,13 @@ const createWsRpcPreset = defineRpcServerPreset((options) => {
3557
3568
  port,
3558
3569
  host
3559
3570
  });
3560
- return (rpc, options$1) => {
3571
+ return (rpcGroup, options$1) => {
3561
3572
  const { serialize = stringify, deserialize = parse } = options$1 ?? {};
3562
- wss.on("connection", (ws) => {
3573
+ wss.on("connection", (ws, req) => {
3563
3574
  const meta = {
3564
3575
  id: id++,
3565
- ws
3576
+ ws,
3577
+ subscribedStates: /* @__PURE__ */ new Set()
3566
3578
  };
3567
3579
  const channel = {
3568
3580
  post: (data) => {
@@ -3577,17 +3589,17 @@ const createWsRpcPreset = defineRpcServerPreset((options) => {
3577
3589
  deserialize,
3578
3590
  meta
3579
3591
  };
3580
- rpc.updateChannels((channels) => {
3592
+ rpcGroup.updateChannels((channels) => {
3581
3593
  channels.push(channel);
3582
3594
  });
3583
3595
  ws.on("close", () => {
3584
- rpc.updateChannels((channels) => {
3596
+ rpcGroup.updateChannels((channels) => {
3585
3597
  const index = channels.indexOf(channel);
3586
3598
  if (index >= 0) channels.splice(index, 1);
3587
3599
  });
3588
3600
  onDisconnected(ws, meta);
3589
3601
  });
3590
- onConnected(ws, meta);
3602
+ onConnected(ws, req, meta);
3591
3603
  });
3592
3604
  };
3593
3605
  });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vitejs/devtools-rpc",
3
3
  "type": "module",
4
- "version": "0.0.0-alpha.21",
4
+ "version": "0.0.0-alpha.23",
5
5
  "description": "DevTools rpc for Vite (work in progress)",
6
6
  "author": "VoidZero Inc.",
7
7
  "license": "MIT",
@@ -41,8 +41,8 @@
41
41
  "structured-clone-es": "^1.0.0"
42
42
  },
43
43
  "devDependencies": {
44
- "tsdown": "^0.18.2",
45
- "ws": "^8.18.3"
44
+ "tsdown": "^0.18.4",
45
+ "ws": "^8.19.0"
46
46
  },
47
47
  "scripts": {
48
48
  "build": "tsdown",
@@ -1,13 +0,0 @@
1
- import { RpcClientPreset } from "./presets/index.mjs";
2
- import { ChannelOptions } from "birpc";
3
-
4
- //#region src/presets/ws/client.d.ts
5
- interface WebSocketRpcClientOptions {
6
- url: string;
7
- onConnected?: (e: Event) => void;
8
- onError?: (e: Error) => void;
9
- onDisconnected?: (e: CloseEvent) => void;
10
- }
11
- declare const createWsRpcPreset: RpcClientPreset<(options: WebSocketRpcClientOptions) => ChannelOptions>;
12
- //#endregion
13
- export { createWsRpcPreset as n, WebSocketRpcClientOptions as t };