import type { ErrorPayload, HotPayload } from 'vite'; /** marks a response body as JSON-encoded {@link SerializedError} */ export const ERROR_HEADER = 'x-dromi-error'; /** request error in Vite's overlay format */ export type SerializedError = ErrorPayload['err']; /** Vite hot channel payload, relayed in either direction */ export type HotMessage = { type: 'hot'; payload: HotPayload }; /** first message sent to the Deno process */ export type InitMessage = { type: 'init'; /** absolute path to the server entrypoint */ entry: string; /** URL of `vite/module-runner`, matching the `vite` that runs the dev server */ moduleRunner: string; }; /** Deno process log for Vite's logger */ export type LogMessage = { type: 'log'; level: 'error' | 'info'; message: string; }; /** sent by the Deno process once its server is listening */ export type ReadyMessage = { type: 'ready'; /** port of the server, on `127.0.0.1` */ port: number; }; /** requests a process restart for an unaccepted HMR update */ export type RestartMessage = { type: 'restart' }; /** worker module runner request to Vite's hot channel */ export type InvokeMessage = { type: 'invoke'; /** request id, unique across workers */ id: string; payload: HotPayload; }; /** response to an {@link InvokeMessage}, with the same `id` */ export type ResultMessage = { type: 'result'; id: string; result: { result: unknown } | { error: unknown }; }; /** message sent from the Vite host to the Deno process */ export type HostMessage = HotMessage | InitMessage | ResultMessage; /** message sent from the Deno process to the Vite host */ export type RunnerMessage = HotMessage | InvokeMessage | LogMessage | ReadyMessage | RestartMessage; /** `BroadcastChannel` shared by the Deno main thread and its workers */ export const WORKER_CHANNEL = 'dromi:worker'; /** worker requests and host responses relayed by the main thread over {@link WORKER_CHANNEL} */ export type WorkerChannelMessage = InvokeMessage | ResultMessage;