diff options
-rw-r--r-- | .changeset/slimy-ravens-stare.md | 5 | ||||
-rw-r--r-- | packages/astro/client.d.ts | 5 | ||||
-rw-r--r-- | packages/astro/src/virtual-modules/content.ts | 76 | ||||
-rw-r--r-- | packages/astro/types/content.d.ts | 75 |
4 files changed, 81 insertions, 80 deletions
diff --git a/.changeset/slimy-ravens-stare.md b/.changeset/slimy-ravens-stare.md new file mode 100644 index 000000000..b1655b200 --- /dev/null +++ b/.changeset/slimy-ravens-stare.md @@ -0,0 +1,5 @@ +--- +"astro": patch +--- + +Fixes a regression in content collection types diff --git a/packages/astro/client.d.ts b/packages/astro/client.d.ts index 37df3b5d3..e3a19add3 100644 --- a/packages/astro/client.d.ts +++ b/packages/astro/client.d.ts @@ -1,4 +1,5 @@ /// <reference types="vite/types/import-meta.d.ts" /> +/// <reference path="./types/content.d.ts" /> // eslint-disable-next-line @typescript-eslint/no-namespace declare namespace App { @@ -160,10 +161,6 @@ declare module 'astro:components' { export * from 'astro/components'; } -declare module 'astro:content' { - export * from 'astro/virtual-modules/content.js'; -} - type MD = import('./dist/@types/astro.js').MarkdownInstance<Record<string, any>>; interface ExportedMarkdownModuleEntities { frontmatter: MD['frontmatter']; diff --git a/packages/astro/src/virtual-modules/content.ts b/packages/astro/src/virtual-modules/content.ts deleted file mode 100644 index 8424f3b06..000000000 --- a/packages/astro/src/virtual-modules/content.ts +++ /dev/null @@ -1,76 +0,0 @@ -import { defineCollection as _defineCollection } from '../content/runtime.js'; -import { z } from 'zod'; - -export { z }; - -// This needs to be in sync with ImageMetadata -export type ImageFunction = () => z.ZodObject<{ - src: z.ZodString; - width: z.ZodNumber; - height: z.ZodNumber; - format: z.ZodUnion< - [ - z.ZodLiteral<'png'>, - z.ZodLiteral<'jpg'>, - z.ZodLiteral<'jpeg'>, - z.ZodLiteral<'tiff'>, - z.ZodLiteral<'webp'>, - z.ZodLiteral<'gif'>, - z.ZodLiteral<'svg'>, - z.ZodLiteral<'avif'>, - ] - >; -}>; - -type BaseSchemaWithoutEffects = - | z.AnyZodObject - | z.ZodUnion<[BaseSchemaWithoutEffects, ...BaseSchemaWithoutEffects[]]> - | z.ZodDiscriminatedUnion<string, z.AnyZodObject[]> - | z.ZodIntersection<BaseSchemaWithoutEffects, BaseSchemaWithoutEffects>; - -type BaseSchema = BaseSchemaWithoutEffects | z.ZodEffects<BaseSchemaWithoutEffects>; - -export type SchemaContext = { image: ImageFunction }; - -type DataCollectionConfig<S extends BaseSchema> = { - type: 'data'; - schema?: S | ((context: SchemaContext) => S); -}; - -type ContentCollectionConfig<S extends BaseSchema> = { - type?: 'content'; - schema?: S | ((context: SchemaContext) => S); -}; - -type CollectionConfig<S extends BaseSchema> = ContentCollectionConfig<S> | DataCollectionConfig<S>; - -export function defineCollection<S extends BaseSchema>( - input: CollectionConfig<S> -): CollectionConfig<S> { - return _defineCollection(input); -} - -const noop: (...args: any[]) => any = () => {}; -/** Run `astro sync` to generate high fidelity types */ -export const getEntryBySlug = noop; -/** Run `astro sync` to generate high fidelity types */ -export const getDataEntryById = noop; -/** Run `astro sync` to generate high fidelity types */ -export const getCollection = noop; -/** Run `astro sync` to generate high fidelity types */ -export const getEntry = noop; -/** Run `astro sync` to generate high fidelity types */ -export const getEntries = noop; -/** Run `astro sync` to generate high fidelity types */ -export const reference = noop; -/** Run `astro sync` to generate high fidelity types */ -export type CollectionKey = any; -/** Run `astro sync` to generate high fidelity types */ -// eslint-disable-next-line @typescript-eslint/no-unused-vars -export type CollectionEntry<C> = any; -/** Run `astro sync` to generate high fidelity types */ -export type ContentCollectionKey = any; -/** Run `astro sync` to generate high fidelity types */ -export type DataCollectionKey = any; -/** Run `astro sync` to generate high fidelity types */ -export type ContentConfig = any; diff --git a/packages/astro/types/content.d.ts b/packages/astro/types/content.d.ts new file mode 100644 index 000000000..45f0d4af7 --- /dev/null +++ b/packages/astro/types/content.d.ts @@ -0,0 +1,75 @@ +declare module 'astro:content' { + export { z } from 'astro/zod'; + + // This needs to be in sync with ImageMetadata + export type ImageFunction = () => import('astro/zod').ZodObject<{ + src: import('astro/zod').ZodString; + width: import('astro/zod').ZodNumber; + height: import('astro/zod').ZodNumber; + format: import('astro/zod').ZodUnion< + [ + import('astro/zod').ZodLiteral<'png'>, + import('astro/zod').ZodLiteral<'jpg'>, + import('astro/zod').ZodLiteral<'jpeg'>, + import('astro/zod').ZodLiteral<'tiff'>, + import('astro/zod').ZodLiteral<'webp'>, + import('astro/zod').ZodLiteral<'gif'>, + import('astro/zod').ZodLiteral<'svg'>, + import('astro/zod').ZodLiteral<'avif'>, + ] + >; + }>; + + type BaseSchemaWithoutEffects = + | import('astro/zod').AnyZodObject + | import('astro/zod').ZodUnion<[BaseSchemaWithoutEffects, ...BaseSchemaWithoutEffects[]]> + | import('astro/zod').ZodDiscriminatedUnion<string, import('astro/zod').AnyZodObject[]> + | import('astro/zod').ZodIntersection<BaseSchemaWithoutEffects, BaseSchemaWithoutEffects>; + + type BaseSchema = + | BaseSchemaWithoutEffects + | import('astro/zod').ZodEffects<BaseSchemaWithoutEffects>; + + export type SchemaContext = { image: ImageFunction }; + + type DataCollectionConfig<S extends BaseSchema> = { + type: 'data'; + schema?: S | ((context: SchemaContext) => S); + }; + + type ContentCollectionConfig<S extends BaseSchema> = { + type?: 'content'; + schema?: S | ((context: SchemaContext) => S); + }; + + type CollectionConfig<S extends BaseSchema> = + | ContentCollectionConfig<S> + | DataCollectionConfig<S>; + + export function defineCollection<S extends BaseSchema>( + input: CollectionConfig<S> + ): CollectionConfig<S>; + + /** Run `astro sync` to generate high fidelity types */ + export const getEntryBySlug: (...args: any[]) => any; + /** Run `astro sync` to generate high fidelity types */ + export const getDataEntryById: (...args: any[]) => any; + /** Run `astro sync` to generate high fidelity types */ + export const getCollection: (...args: any[]) => any; + /** Run `astro sync` to generate high fidelity types */ + export const getEntry: (...args: any[]) => any; + /** Run `astro sync` to generate high fidelity types */ + export const getEntries: (...args: any[]) => any; + /** Run `astro sync` to generate high fidelity types */ + export const reference: (...args: any[]) => any; + /** Run `astro sync` to generate high fidelity types */ + export type CollectionKey = any; + /** Run `astro sync` to generate high fidelity types */ + export type CollectionEntry<C> = any; + /** Run `astro sync` to generate high fidelity types */ + export type ContentCollectionKey = any; + /** Run `astro sync` to generate high fidelity types */ + export type DataCollectionKey = any; + /** Run `astro sync` to generate high fidelity types */ + export type ContentConfig = any; +} |