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

View File

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

View File

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

View File

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