49 lines
1.4 KiB
TypeScript
49 lines
1.4 KiB
TypeScript
import type { Json } from "@/types/supabase";
|
|||
|
|
|
||
|
|
export type DocumentSavePayload = {
|
||
|
|
documentId: string;
|
||
|
|
workspaceId: string | null;
|
||
|
|
revision: number | null;
|
||
|
|
content: Json;
|
||
|
|
conflictDetectionKey: string | null;
|
||
|
|
snapshotCapturedAt: string | null;
|
||
|
|
blockCount: number | null;
|
||
|
|
};
|
||
|
|
|
||
|
|
export function buildDocumentSavePayload(input: {
|
||
|
|
documentId: string;
|
||
|
|
workspaceId?: string | null;
|
||
|
|
revision?: number | null;
|
||
|
|
content: Json;
|
||
|
|
conflictDetectionKey?: string | null;
|
||
|
|
snapshotCapturedAt?: string | null;
|
||
|
|
blockCount?: number | null;
|
||
|
|
}): DocumentSavePayload {
|
||
|
|
const revision =
|
||
|
|
typeof input.revision === "number" && Number.isInteger(input.revision) && input.revision >= 0
|
||
|
|
? input.revision
|
||
|
|
: null;
|
||
|
|
const conflictDetectionKey =
|
||
|
|
typeof input.conflictDetectionKey === "string" && input.conflictDetectionKey.trim()
|
||
|
|
? input.conflictDetectionKey.trim()
|
||
|
|
: null;
|
||
|
|
const snapshotCapturedAt =
|
||
|
|
typeof input.snapshotCapturedAt === "string" && input.snapshotCapturedAt.trim()
|
||
|
|
? input.snapshotCapturedAt.trim()
|
||
|
|
: null;
|
||
|
|
const blockCount =
|
||
|
|
typeof input.blockCount === "number" && Number.isInteger(input.blockCount) && input.blockCount >= 0
|
||
|
|
? input.blockCount
|
||
|
|
: null;
|
||
|
|
|
||
|
|
return {
|
||
|
|
documentId: input.documentId.trim(),
|
||
|
|
workspaceId: input.workspaceId?.trim() || null,
|
||
|
|
revision,
|
||
|
|
content: input.content,
|
||
|
|
conflictDetectionKey,
|
||
|
|
snapshotCapturedAt,
|
||
|
|
blockCount,
|
||
|
|
};
|
||
|
|
}
|