UNPKG

@inox-tools/content-utils

Version:

Utilities to work with content collections on an Astro project from an integration or library.

34 lines (30 loc) 1.8 kB
/// <reference path="../virtual.d.ts" /> import { BaseSchema, z, SchemaContext, defineCollection as defineCollection$1 } from 'astro:content'; export { BaseSchema } from 'astro:content'; /** Type that extends a collection's default schema with an optional, user-defined schema. */ type ExtendedSchema<S extends BaseSchema, T extends BaseSchema | never = never> = [ T ] extends [never] ? S : T extends BaseSchema ? z.ZodIntersection<S, T> : S; type CollectionConfig<S extends BaseSchema> = ReturnType<typeof defineCollection$1<S>>; interface CollectionExtensionOptions<E extends BaseSchema> { extends?: E | ((context: SchemaContext) => E); } type ExtendedCollection<S extends BaseSchema, E extends BaseSchema> = ExtendedSchema<S, E> extends BaseSchema ? CollectionConfig<ExtendedSchema<S, E>> : CollectionConfig<S>; type FancyCollection<S extends BaseSchema = BaseSchema> = <E extends BaseSchema>(options?: CollectionExtensionOptions<E>) => ExtendedCollection<S, E>; /** * Define a collection from an integration that can be extended by users of the integration. * * Also known as a FancyCollection 💅 */ declare function defineCollection<S extends BaseSchema>(config: CollectionConfig<S>): FancyCollection<S>; /** * Guard checking that a value is a FancyCollection. */ declare function isFancyCollection(something: any): something is FancyCollection; /** * Extract the original FancyCollection from a value, if it was derived from one. * * If the value was not derived from a FancyCollection, return null; */ declare function tryGetOriginalFancyCollection(something: any): FancyCollection | null; export { type CollectionExtensionOptions, type ExtendedCollection, type ExtendedSchema, type FancyCollection, defineCollection, isFancyCollection, tryGetOriginalFancyCollection };