studiocms
Version:
Astro Native CMS for AstroDB. Built from the ground up by the Astro community.
143 lines (142 loc) • 6.81 kB
TypeScript
import { z } from 'astro/zod';
/**
* Zod schema for validating and transforming data when creating a new StudioCMS page.
*
* Fields:
* - `title`: Required string. The title of the page. Must not be empty.
* - `slug`: Required string. Must be lowercase, only contain letters, numbers, and hyphens (no leading/trailing hyphens).
* - `description`: Optional string. A description of the page.
* - `package`: Required string. The package associated with the page.
* - `showOnNav`: Optional boolean (default: false). Whether to show the page in navigation.
* - `heroImage`: Optional string. URL or path to the hero image.
* - `parentFolder`: Optional string or null (default: null). The parent folder for the page.
* - `draft`: Optional boolean (default: false). Whether the page is a draft.
* - `showAuthor`: Optional boolean (default: false). Whether to display the author.
* - `showContributors`: Optional boolean (default: false). Whether to display contributors.
* - `categories`: Optional string or array of strings (default: []). Transformed to an array of strings.
* - `tags`: Optional string or array of strings (default: []). Transformed to an array of strings.
*
* Uses custom transformations to ensure `categories` and `tags` are always arrays of strings.
*/
export declare const studioCMSCreatePageDataSchema: z.ZodObject<{
title: z.ZodString;
slug: z.ZodEffects<z.ZodString, string, string>;
description: z.ZodOptional<z.ZodString>;
package: z.ZodString;
showOnNav: z.ZodEffects<z.ZodOptional<z.ZodString>, boolean, string | undefined>;
heroImage: z.ZodOptional<z.ZodString>;
parentFolder: z.ZodDefault<z.ZodOptional<z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodNull]>, string | null, string | null>>>;
draft: z.ZodEffects<z.ZodOptional<z.ZodString>, boolean, string | undefined>;
showAuthor: z.ZodEffects<z.ZodOptional<z.ZodString>, boolean, string | undefined>;
showContributors: z.ZodEffects<z.ZodOptional<z.ZodString>, boolean, string | undefined>;
categories: z.ZodDefault<z.ZodEffects<z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>, string[], string | string[] | undefined>>;
tags: z.ZodDefault<z.ZodEffects<z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>, string[], string | string[] | undefined>>;
}, "strip", z.ZodTypeAny, {
title: string;
slug: string;
categories: string[];
package: string;
showOnNav: boolean;
tags: string[];
showAuthor: boolean;
showContributors: boolean;
parentFolder: string | null;
draft: boolean;
description?: string | undefined;
heroImage?: string | undefined;
}, {
title: string;
slug: string;
package: string;
description?: string | undefined;
categories?: string | string[] | undefined;
showOnNav?: string | undefined;
heroImage?: string | undefined;
tags?: string | string[] | undefined;
showAuthor?: string | undefined;
showContributors?: string | undefined;
parentFolder?: string | null | undefined;
draft?: string | undefined;
}>;
/**
* Schema for editing page data and content in StudioCMS.
*
* Extends the `studioCMSCreatePageDataSchema` with additional fields required for editing:
* - `id`: The unique identifier for the page.
* - `content`: The main content of the page as a string.
* - `contentId`: The unique identifier for the content.
* - `pluginFields`: An optional record of plugin-specific fields, where each value is a `FormDataEntryValue` or null.
*/
export declare const studioCMSEditPageDataAndContentSchema: z.ZodObject<{
title: z.ZodString;
slug: z.ZodEffects<z.ZodString, string, string>;
description: z.ZodOptional<z.ZodString>;
package: z.ZodString;
showOnNav: z.ZodEffects<z.ZodOptional<z.ZodString>, boolean, string | undefined>;
heroImage: z.ZodOptional<z.ZodString>;
parentFolder: z.ZodDefault<z.ZodOptional<z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodNull]>, string | null, string | null>>>;
draft: z.ZodEffects<z.ZodOptional<z.ZodString>, boolean, string | undefined>;
showAuthor: z.ZodEffects<z.ZodOptional<z.ZodString>, boolean, string | undefined>;
showContributors: z.ZodEffects<z.ZodOptional<z.ZodString>, boolean, string | undefined>;
categories: z.ZodDefault<z.ZodEffects<z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>, string[], string | string[] | undefined>>;
tags: z.ZodDefault<z.ZodEffects<z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>, string[], string | string[] | undefined>>;
} & {
id: z.ZodString;
content: z.ZodString;
contentId: z.ZodString;
pluginFields: z.ZodDefault<z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodNullable<z.ZodType<FormDataEntryValue, z.ZodTypeDef, FormDataEntryValue>>>>>;
augments: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
}, "strip", z.ZodTypeAny, {
title: string;
slug: string;
id: string;
categories: string[];
package: string;
showOnNav: boolean;
tags: string[];
showAuthor: boolean;
showContributors: boolean;
parentFolder: string | null;
draft: boolean;
contentId: string;
content: string;
pluginFields: Record<string, FormDataEntryValue | null>;
description?: string | undefined;
augments?: string[] | undefined;
heroImage?: string | undefined;
}, {
title: string;
slug: string;
id: string;
package: string;
contentId: string;
content: string;
description?: string | undefined;
augments?: string[] | undefined;
categories?: string | string[] | undefined;
showOnNav?: string | undefined;
heroImage?: string | undefined;
tags?: string | string[] | undefined;
showAuthor?: string | undefined;
showContributors?: string | undefined;
parentFolder?: string | null | undefined;
draft?: string | undefined;
pluginFields?: Record<string, FormDataEntryValue | null> | undefined;
}>;
/**
* Converts a FormData object into a plain record object, optionally remapping keys.
*
* @param formData - The FormData instance to convert.
* @param keyRemapping - An optional mapping of original keys to new keys.
* @returns A record object where each key is either the original or remapped key, and each value is the corresponding FormData entry value.
*/
export declare function formDataToRecord(formData: FormData, keyRemapping?: Record<string, string>): Record<string, FormDataEntryValue>;
/**
* Transform a string true/false value to boolean.
*
* - If the input value is undefined, return false.
*
* @param value - The value to transform, can be undefined, 'true' or 'false'.
* @returns Transformed value in boolean.
*/
export declare function transformStringToBoolean(value: string | undefined): boolean;