payload
Version:
Node, React, Headless CMS and Application Framework built on Next.js
59 lines • 3.05 kB
TypeScript
import type { Payload } from '../../../types/index.js';
/**
* Convert to snake_case (matches to-snake-case library behavior)
* Handles camelCase, PascalCase, and hyphens
*/
export declare const toSnakeCase: (str: string) => string;
export type VersionRecord = {
_status: 'draft' | 'published';
created_at?: Date | string;
createdAt?: Date | string;
id: number | string;
parent: number | string;
published_locale?: string;
publishedLocale?: string;
snapshot?: boolean;
};
export type VersionLocaleStatusMap = Map<number | string, Map<string, 'draft' | 'published'>>;
/**
* Core logic for calculating the status of each locale for each version
* by processing version history chronologically.
*
* This works by:
* 1. Processing versions in chronological order (oldest first)
* 2. Tracking the cumulative published state for each document as we process versions
* 3. For each version, determining what status each locale should have based on:
* - Publish events with publishedLocale: mark that locale as published, version shows NEW state
* - Publish events without publishedLocale: mark all locales as published, version shows NEW state
* - Draft saves (_status='draft'): mark all locales as draft (unpublish everything)
* - Snapshots: preserve state AFTER publish (snapshots created after publishing specific locale)
*
* Snapshot creation flow when publishing one locale:
* 1. Merge incoming content with last published → update main table
* 2. Create snapshot object (preserves other locales' draft content + updates published locale)
* 3. Create publish version (_status='published', publishedLocale set)
* 4. Create snapshot version (_status='draft', snapshot=true)
* - Snapshot CONTENT is mixed (draft + published content)
* - Snapshot STATUS reflects which locales are actually published
*
* Example scenario:
* - V1: publish all locales (no snapshot) → state: {en: published, es: published, de: published}
* - V2: draft save → state: {en: draft, es: draft, de: draft}
* - V3: publish en only → state: {en: published, es: draft, de: draft}
* - V4: snapshot after publishing en → state: {en: published, es: draft, de: draft}
* - V5: publish all locales (no snapshot) → state: {en: published, es: published, de: published}
*
* @param versions - Array of version records (must be sorted by parent, then createdAt ASC)
* @param locales - Array of locale codes (e.g., ['en', 'es', 'pt'])
* @param payload - Payload instance for logging
* @returns Map of versionId -> Map of locale -> status
*/
export declare function calculateVersionLocaleStatuses(versions: VersionRecord[], locales: string[], payload: Payload): VersionLocaleStatusMap;
/**
* Sorts version records by parent document, then by creation date (oldest first)
*
* @param versions - Array of version records
* @returns Sorted array of version records
*/
export declare function sortVersionsChronologically(versions: VersionRecord[]): VersionRecord[];
//# sourceMappingURL=shared.d.ts.map