fix(dashboard): dont use crypto randomUUID
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:
2025-10-30 00:13:08 +00:00
parent 4478cdbcb3
commit fb1fa642af
6 changed files with 40 additions and 43 deletions

View File

@@ -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()
}

View File

@@ -3,7 +3,8 @@
"module": "index.ts",
"type": "module",
"dependencies": {
"@eva/zigbee": "workspace:*"
"@eva/zigbee": "workspace:*",
"nanoid": "^5.1.6"
},
"devDependencies": {
"@types/bun": "latest"

View File

@@ -4,7 +4,6 @@ export const ZIGBEE_DEVICE = {
deskLamp: "desk_lamp",
livingRoomFloorLamp: "living_room_floor_lamp",
} as const
export type ZigbeeDeviceName = (typeof ZIGBEE_DEVICE)[keyof typeof ZIGBEE_DEVICE]
export type ZigbeeDeviceStates = {
[ZIGBEE_DEVICE.deskLamp]: {
@@ -26,6 +25,8 @@ export type ZigbeeDeviceStates = {
}
}
export const ALL_ZIGBEE_DEVICE_NAMES: ZigbeeDeviceName[] = Object.values(ZIGBEE_DEVICE)
export type ZigbeeDeviceName = keyof ZigbeeDeviceStates
export type ZigbeeDeviceState = ZigbeeDeviceStates[keyof ZigbeeDeviceStates]
export type ZigbeeDeviceState<DeviceName extends ZigbeeDeviceName = ZigbeeDeviceName> = ZigbeeDeviceStates[DeviceName]
export const ALL_ZIGBEE_DEVICE_NAMES: ZigbeeDeviceName[] = Object.values(ZIGBEE_DEVICE)