refactor: strengthen upload boundary types

This commit is contained in:
Tom Boullay
2026-04-27 17:21:44 +02:00
parent d049318a73
commit fd586f4185
7 changed files with 96 additions and 39 deletions
+28
View File
@@ -0,0 +1,28 @@
export type DriveAction = 'new' | 'replace'
interface StagingRequestBody {
stagingId: string
}
interface DriveRequestBody extends StagingRequestBody {
action: DriveAction
}
function isRecord(value: unknown): value is Record<string, unknown> {
return typeof value === 'object' && value !== null
}
export function parseStagingRequestBody(value: unknown): StagingRequestBody {
if (!isRecord(value) || typeof value.stagingId !== 'string' || value.stagingId.trim() === '') {
throw new Error('stagingId manquant')
}
return { stagingId: value.stagingId }
}
export function parseDriveRequestBody(value: unknown): DriveRequestBody {
const { stagingId } = parseStagingRequestBody(value)
const action = isRecord(value) && value.action === 'replace' ? 'replace' : 'new'
return { stagingId, action }
}