29 lines
818 B
TypeScript
29 lines
818 B
TypeScript
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 }
|
|
}
|