mirror of
https://github.com/wu736139669/hapi.git
synced 2026-08-05 06:24:37 +00:00
fix: add type safety improvements and fix Bun runtime type issues
- Replace embeddedAssets stub with generated type definitions - Fix Bun.isCompiled access with proper type assertion to prevent undefined errors - Improve router search validation with explicit SessionFileSearch type - Simplify middleware return patterns for better readability
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
// Stub types for embeddedAssets.generated.ts when the manifest is not generated.
|
||||
|
||||
export interface EmbeddedWebAsset {
|
||||
path: string;
|
||||
sourcePath: string;
|
||||
mimeType: string;
|
||||
}
|
||||
|
||||
export const embeddedAssets: EmbeddedWebAsset[];
|
||||
@@ -1,10 +0,0 @@
|
||||
// Stub types for embeddedAssets.generated.ts when the manifest is not generated.
|
||||
declare module './embeddedAssets.generated' {
|
||||
export interface EmbeddedWebAsset {
|
||||
path: string;
|
||||
sourcePath: string;
|
||||
mimeType: string;
|
||||
}
|
||||
|
||||
export const embeddedAssets: EmbeddedWebAsset[];
|
||||
}
|
||||
@@ -95,13 +95,11 @@ function createWebApp(options: {
|
||||
|
||||
app.use('*', async (c, next) => {
|
||||
if (c.req.path.startsWith('/api')) {
|
||||
await next()
|
||||
return
|
||||
return await next()
|
||||
}
|
||||
|
||||
if (c.req.method !== 'GET' && c.req.method !== 'HEAD') {
|
||||
await next()
|
||||
return
|
||||
return await next()
|
||||
}
|
||||
|
||||
const asset = embeddedAssetMap.get(c.req.path)
|
||||
@@ -109,7 +107,7 @@ function createWebApp(options: {
|
||||
return serveEmbeddedAsset(asset)
|
||||
}
|
||||
|
||||
await next()
|
||||
return await next()
|
||||
})
|
||||
|
||||
app.get('*', async (c, next) => {
|
||||
@@ -165,7 +163,8 @@ export async function startWebServer(options: {
|
||||
jwtSecret: Uint8Array
|
||||
socketEngine: SocketEngine
|
||||
}): Promise<BunServer<WebSocketData>> {
|
||||
const embeddedAssetMap = Bun.isCompiled ? await loadEmbeddedAssetMap() : null
|
||||
const bunRuntime = (globalThis as typeof globalThis & { Bun?: { isCompiled?: boolean } }).Bun
|
||||
const embeddedAssetMap = bunRuntime?.isCompiled ? await loadEmbeddedAssetMap() : null
|
||||
const app = createWebApp({
|
||||
getSyncEngine: options.getSyncEngine,
|
||||
getSseManager: options.getSseManager,
|
||||
|
||||
+11
-4
@@ -201,17 +201,24 @@ const sessionFilesRoute = createRoute({
|
||||
component: FilesPage,
|
||||
})
|
||||
|
||||
type SessionFileSearch = {
|
||||
path: string
|
||||
staged?: boolean
|
||||
}
|
||||
|
||||
const sessionFileRoute = createRoute({
|
||||
getParentRoute: () => rootRoute,
|
||||
path: '/sessions/$sessionId/file',
|
||||
validateSearch: (search: Record<string, unknown>) => ({
|
||||
path: typeof search.path === 'string' ? search.path : '',
|
||||
staged: search.staged === true || search.staged === 'true'
|
||||
validateSearch: (search: Record<string, unknown>): SessionFileSearch => {
|
||||
const path = typeof search.path === 'string' ? search.path : ''
|
||||
const staged = search.staged === true || search.staged === 'true'
|
||||
? true
|
||||
: search.staged === false || search.staged === 'false'
|
||||
? false
|
||||
: undefined
|
||||
}),
|
||||
|
||||
return staged === undefined ? { path } : { path, staged }
|
||||
},
|
||||
component: FilePage,
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user