feat: Fix some typings

This commit is contained in:
Wanjohi
2025-11-04 07:04:00 +03:00
parent 86959f93d9
commit bcb4763532
5 changed files with 33 additions and 22 deletions

View File

@@ -10,9 +10,9 @@ import {
AudioCodecName,
RetryOptions,
SessionInfo,
type SessionInfo as SessionInfoType,
type Session as SessionInterface,
type Config as SessionConfig,
type Session as SessionInterface,
type SessionInfo as SessionInfoType,
} from "./types.js";
import { Actor } from "../actor.js";
import { Database } from "../drizzle/index.js";
@@ -93,16 +93,16 @@ export namespace Session {
export function serialize(
input: typeof sessionTable.$inferSelect,
): z.infer<typeof SessionInfo> {
): z.infer<typeof Info> {
return {
id: input.id,
room: input.room || undefined,
// room: input.room || undefined,
machine: input.machine,
relayUrl: input.relayUrl,
retry: input.retry || undefined,
queue: input.queue || undefined,
machine: input.machine || undefined,
description: input.description || undefined,
maxDuration: input.maxDuration || undefined,
relayUrl: input.relayUrl || undefined,
resolution: input.resolution || undefined,
framerate: input.framerate || undefined,
gpuVendor: input.gpuVendor || undefined,

View File

@@ -33,14 +33,17 @@ export const sessionTable = pgTable("sessions", {
.notNull(),
retry: jsonb("retry").$type<RetryOptions>(),
queue: jsonb("queue").$type<Queue>(),
machine: varchar("machine", { length: 200 }).$type<MachinePresetName>(),
machine: varchar("machine", { length: 200 })
.$type<MachinePresetName>()
.notNull()
.default("ns3-micro"),
maxDuration: integer("max_duration"),
relayUrl: varchar("relay_url", { length: 500 }),
relayUrl: varchar("relay_url", { length: 500 }).notNull(),
resolution: varchar("resolution", {
length: 20,
}).$type<ScreenResolutionPresetName>(),
framerate: integer("framerate"),
room: varchar("room", { length: 255 }),
// room: varchar("room", { length: 255 }),
gpuVendor: varchar("gpu_vendor", { length: 100 }),
gpuName: varchar("gpu_name", { length: 255 }),
gpuIndex: integer("gpu_index"),

View File

@@ -123,20 +123,26 @@ export const SessionInfo = z
example: Examples.Session.queue,
}),
/** Machine preset for the session */
machine: MachinePresetName.optional().meta({
description: "Machine preset for the session",
example: Examples.Session.machine,
}),
machine: MachinePresetName.optional()
.meta({
description: "Machine preset for the session",
example: Examples.Session.machine,
})
.default("ns3-micro"),
/** Maximum duration in seconds the session can run */
maxDuration: z.number().optional().meta({
description: "Maximum duration in seconds the session can run",
example: Examples.Session.maxDuration,
}),
/** Nestri relay URL for streaming and signaling */
relayUrl: z.url().optional().meta({
description: "Nestri relay URL for streaming and signaling",
example: Examples.Session.relayUrl,
}),
relayUrl: z
.url()
.optional()
.meta({
description: "Nestri relay URL for streaming and signaling",
example: Examples.Session.relayUrl,
})
.default("https://relay.nestri.io"),
/** Display or stream resolution in 'WxH' format */
resolution: ScreenResolutionPresetName.optional().meta({
description: "Display or stream resolution in 'WxH' format",
@@ -148,10 +154,10 @@ export const SessionInfo = z
example: Examples.Session.framerate,
}),
/** Room name or identifier for multiplayer sessions */
room: z.string().optional().meta({
description: "Room name or identifier for multiplayer sessions",
example: Examples.Session.room,
}),
// room: z.string().optional().meta({
// description: "Room name or identifier for multiplayer sessions",
// example: Examples.Session.room,
// }),
/** Preferred GPU vendor */
gpuVendor: z.string().optional().meta({
description: "Preferred GPU vendor",

View File

@@ -3,6 +3,7 @@ import { Hono } from "hono";
import { cors } from "hono/cors";
import { auth } from "./utils/auth";
import { Log } from "@nestri/core/utils/log";
import { SessionApi } from "./routes/session.js";
import { HTTPException } from "hono/http-exception";
import { VisibleError, ErrorCodes } from "@nestri/core/error";
import { openAPIRouteHandler, validator } from "hono-openapi";
@@ -38,6 +39,7 @@ export const routes = app
.get("/", async (c) => {
return c.text("ok");
})
.route("/session", SessionApi.route)
.onError((error, c) => {
// Handle our custom VisibleError
if (error instanceof VisibleError) {

View File

@@ -4,7 +4,7 @@ import { ErrorResponses } from "../utils/error.js";
import { Session } from "@nestri/core/session/index";
import { describeRoute, resolver, validator } from "hono-openapi";
export namespace SessionRoute {
export namespace SessionApi {
export const route = new Hono()
.use(notPublic)
.get(