refactor(simulation): type frontend RPC methods
This commit is contained in:
parent
ba42a0a7c3
commit
e9c5164e4d
2 changed files with 5 additions and 2 deletions
|
|
@ -16,7 +16,7 @@ function parseRequest(input: string | Buffer) {
|
|||
}
|
||||
|
||||
async function handle(harness: Harness, request: SimulationProtocol.JsonRpc.Request, headless: boolean) {
|
||||
switch (request.method) {
|
||||
switch (SimulationProtocol.Frontend.decodeMethod(request.method)) {
|
||||
case "ui.state": {
|
||||
if (headless) await harness.renderOnce()
|
||||
const result = SimulationActions.state(harness)
|
||||
|
|
@ -33,7 +33,6 @@ async function handle(harness: Harness, request: SimulationProtocol.JsonRpc.Requ
|
|||
case "trace.export":
|
||||
return SimulationTrace.exportTrace()
|
||||
}
|
||||
throw new Error(`Unknown simulation method: ${request.method}`)
|
||||
}
|
||||
|
||||
export function start(harness: Harness, endpoint: string, headless: boolean): Server {
|
||||
|
|
|
|||
|
|
@ -46,6 +46,10 @@ export namespace JsonRpc {
|
|||
}
|
||||
|
||||
export namespace Frontend {
|
||||
export const Method = Schema.Literals(["ui.state", "ui.action", "trace.list", "trace.clear", "trace.export"])
|
||||
export type Method = Schema.Schema.Type<typeof Method>
|
||||
export const decodeMethod = Schema.decodeUnknownSync(Method)
|
||||
|
||||
export const KeyModifiers = Schema.Struct({
|
||||
ctrl: Schema.optional(Schema.Boolean),
|
||||
shift: Schema.optional(Schema.Boolean),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue