UNPKG

@jungvonmatt/sb-migrate

Version:

CLI tool for managing Storyblok schema and content migrations

96 lines (95 loc) 5.22 kB
import { IComponentSchemaItem, IComponentSchemaTab, IComponent } from "../types/IComponent"; import { IPendingDataSource, IPendingDataSourceEntry, IDataSource, IDataSourceEntry } from "../types/IDataSource"; import { IStoryContent } from "../types/stories/IStoryContent"; /** * Retrieves the translatable fields for a specific component. * This function uses the cached results from getAllTranslatableComponentFields. * * @param {string} component - The name of the component to get translatable fields for * @returns {Promise<string[]>} An array of translatable field names for the component */ export declare const getTranslatableComponentFields: (component: string) => Promise<string[]>; /** * Creates a new datasource or updates an existing one with the provided entries. * If the datasource exists, it will be updated with the new entries. * If it doesn't exist, a new one will be created. * * @param {string | IPendingDataSource} ds - Either a string name or a datasource object * @param {Omit<IPendingDataSourceEntry, "datasource_id">[]} dsEntries - Array of entries to add to the datasource * @returns {Promise<[IDataSource, IDataSourceEntry[]]>} Tuple containing the datasource and its entries */ export declare const addOrUpdateDatasource: (ds: string | IPendingDataSource, dsEntries: Omit<IPendingDataSourceEntry, "datasource_id">[]) => Promise<[IDataSource, IDataSourceEntry[]]>; /** * Resets a tab in a component's schema by clearing its keys. * * @param {IComponent} component - The component containing the tab * @param {string} name - The name of the tab to reset * @returns {IComponent} A new component with the reset tab */ export declare function resetTab(component: IComponent, name: string): IComponent; /** * Moves fields to a specified tab in a component's schema. * * @param {IComponent} component - The component to modify * @param {string} name - The name of the tab to move fields to * @param {string[]} keys - Array of field names to move to the tab * @param {number} [pos] - Optional position for the tab * @returns {IComponent} A new component with the updated tab */ export declare function moveToTab(component: IComponent, name: string, keys?: Array<string>, pos?: number): IComponent; /** * Gets the deprecated tab from a component's schema, or creates one if it doesn't exist. * * @param {IComponent} component - The component to get the deprecated tab from * @returns {[string, IComponentSchemaTab]} Tuple containing the tab key and the tab object */ export declare const getDeprecatedTab: (component: IComponent) => [string, IComponentSchemaTab]; /** * Moves fields to the deprecated tab in a component's schema. * * @param {IComponent} component - The component to modify * @param {string[]} keys - Array of field names to move to the deprecated tab * @returns {IComponent} A new component with the updated deprecated tab */ export declare function moveToDeprecated(component: IComponent, keys?: Array<string>): IComponent; /** * Moves fields to the settings tab in a component's schema. * * @param {IComponent} component - The component to modify * @param {string[]} keys - Array of field names to move to the settings tab * @returns {IComponent} A new component with the updated settings tab */ export declare function moveToSettings(component: IComponent, keys?: Array<string>): IComponent; /** * Adds or updates fields in a component's schema. * * @param {IComponent} component - The component to modify * @param {Record<string, IComponentSchemaItem | IComponentSchemaTab>} fields - The fields to add or update * @returns {IComponent} A new component with the updated fields */ export declare function addOrUpdateFields(component: IComponent, fields: Record<string, IComponentSchemaItem | IComponentSchemaTab>): IComponent; /** * Creates a rollback file to store the original state of stories for potential rollback operations. * The file is stored in the migrations/rollback directory with a date prefix. * * @param {any[]} rollbackData - Array containing story data for rollback * @param {string} component - Component name * @param {string} field - Field name or 'generic' for general migrations * @returns {Promise<{component: string, created: boolean}>} Object indicating success and component name * @throws {Error} If file creation fails */ export declare const createRollbackFile: (rollbackData: any[], component: string, field: string) => Promise<{ component: string; created: boolean; }>; /** * Recursively processes content to apply migrations to matching components. * This function handles nested components, blocks, and rich text content. * * @param {IStoryContent} content - Content structure from Storyblok * @param {string} component - Name of the component being processed * @param {Function} migrationFn - Migration function defined by user * @param {string} storyFullSlug - Full slug of the containing story * @returns {Promise<boolean>} True if processing completed successfully */ export declare const processMigration: (content: IStoryContent | undefined, component: string | undefined, migrationFn: (blok: IStoryContent) => void, storyFullSlug: string) => Promise<boolean>;