@sensinum/astro-strapi-loader
Version:
Astro loader for Strapi CMS
42 lines (41 loc) • 2.04 kB
TypeScript
import type { CollectionConfig } from "astro/content/config";
import { z } from "astro/zod";
import type { StrapiComponent, StrapiContentType } from "../types/strapi";
export interface StrapiRequestOptions {
url: string;
token?: string;
path: string;
queryParams?: string;
headers?: Record<string, string>;
}
export interface StrapiCollectionsGeneratorOptions extends Omit<StrapiRequestOptions, "path"> {
strict?: boolean;
}
export interface StrapiCollection {
name: string;
query?: Record<string, any>;
/**
* Custom name for the collection. Allows multiple collections from the same endpoint.
*/
collectionName?: string;
/**
* Custom function to generate ID from item data.
* Default: uses documentId field.
*/
idGenerator?: (data: Record<string, unknown>) => string;
/**
* Locale configuration:
* - undefined: no locale parameter (default behavior)
* - string: single locale (e.g., 'en')
* - string[]: multiple locales (e.g., ['en', 'de']) - returns structure like { 'en': items, 'de': items }
*/
locale?: string | string[];
}
export declare function fetchContentTypes(options: Omit<StrapiRequestOptions, "path">): Promise<Array<StrapiContentType>>;
export declare function fetchComponents(options: Omit<StrapiRequestOptions, "path">): Promise<Array<StrapiComponent>>;
export declare function fetchContent(options: Omit<StrapiRequestOptions, "path"> & {
contentType: string;
}): Promise<any>;
export declare function generateStrapiSchema(options: Omit<StrapiCollectionsGeneratorOptions, "path">): Promise<Record<string, z.ZodObject<any>>>;
export declare function generateCollection(contentType: string, schema: z.ZodObject<any>, options: StrapiCollectionsGeneratorOptions, collectionConfig?: Partial<StrapiCollection>): CollectionConfig<any>;
export declare function generateCollections(options: StrapiCollectionsGeneratorOptions, reqCollections?: Array<StrapiCollection | string>): Promise<Record<string, CollectionConfig<any>>>;