fix(dashboard): dont use crypto randomUUID
Some checks failed
Build and Publish Docker Image / build-and-push (push) Failing after 2m38s
Some checks failed
Build and Publish Docker Image / build-and-push (push) Failing after 2m38s
use nanoid for jrpc request id generation instead Co-authored-by: Ona <no-reply@ona.com>
This commit is contained in:
@@ -1,49 +1,40 @@
|
||||
import type { ZigbeeDeviceName, ZigbeeDeviceStates } from "@eva/zigbee"
|
||||
import { nanoid } from "nanoid"
|
||||
|
||||
export type JrpcRequestId = string & { __brand: "JrpcRequestId" }
|
||||
|
||||
export type JrpcSchema = {
|
||||
subscribeToDevice: {
|
||||
Params: {
|
||||
deviceName: ZigbeeDeviceName
|
||||
}
|
||||
Response: true
|
||||
}
|
||||
setDeviceState: {
|
||||
Params: {
|
||||
deviceName: ZigbeeDeviceName
|
||||
state: unknown
|
||||
}
|
||||
Response: true
|
||||
}
|
||||
showDeviceState: {
|
||||
Params: {
|
||||
[key in ZigbeeDeviceName]: {
|
||||
deviceName: key
|
||||
state: ZigbeeDeviceStates[key]
|
||||
}
|
||||
}[ZigbeeDeviceName]
|
||||
Response: true
|
||||
}
|
||||
subscribeToDevice(p: { deviceName: ZigbeeDeviceName }): true
|
||||
unsubscribeFromDevice(p: { deviceName: ZigbeeDeviceName }): true
|
||||
setDeviceState(p: { deviceName: ZigbeeDeviceName; state: unknown }): true
|
||||
showDeviceState<DeviceName extends ZigbeeDeviceName>(
|
||||
p: { [K in ZigbeeDeviceName]: { deviceName: K; state: ZigbeeDeviceStates[K] } }[DeviceName],
|
||||
): ZigbeeDeviceStates[ZigbeeDeviceName]
|
||||
}
|
||||
|
||||
export type JrpcRequest<Method extends keyof JrpcSchema = keyof JrpcSchema> = {
|
||||
[M in keyof JrpcSchema]: {
|
||||
id: string
|
||||
id: JrpcRequestId
|
||||
jsonrpc: "2.0"
|
||||
method: M
|
||||
params: JrpcSchema[M]["Params"]
|
||||
params: Parameters<JrpcSchema[M]>[0]
|
||||
}
|
||||
}[Method]
|
||||
|
||||
export type JrpcResponse<Method extends keyof JrpcSchema = keyof JrpcSchema> = {
|
||||
[M in keyof JrpcSchema]:
|
||||
| {
|
||||
id: string
|
||||
id: JrpcRequestId
|
||||
jsonrpc: "2.0"
|
||||
result: JrpcSchema[M]["Response"]
|
||||
result: ReturnType<JrpcSchema[M]>
|
||||
}
|
||||
| {
|
||||
id: string
|
||||
id: JrpcRequestId
|
||||
jsonrpc: "2.0"
|
||||
error: string
|
||||
}
|
||||
}[Method]
|
||||
|
||||
export function newJrpcRequestId(): JrpcRequestId {
|
||||
return nanoid()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user