Skip to content

Commit

Permalink
refactor: enumerate valid schema types
Browse files Browse the repository at this point in the history
  • Loading branch information
bholmesdev committed Jan 5, 2023
1 parent 7721e5f commit 8c4ef10
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
17 changes: 15 additions & 2 deletions examples/with-content/src/content/types.generated.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,20 @@ declare module 'astro:content' {
export type CollectionEntry<C extends keyof typeof entryMap> =
typeof entryMap[C][keyof typeof entryMap[C]] & Render;

type BaseCollectionConfig<S extends import('astro/zod').ZodType> = {
type BaseSchemaWithoutEffects =
| import('astro/zod').AnyZodObject
| import('astro/zod').ZodUnion<import('astro/zod').AnyZodObject[]>
| import('astro/zod').ZodDiscriminatedUnion<string, import('astro/zod').AnyZodObject[]>
| import('astro/zod').ZodIntersection<
import('astro/zod').AnyZodObject,
import('astro/zod').AnyZodObject
>;

type BaseSchema =
| BaseSchemaWithoutEffects
| import('astro/zod').ZodEffects<BaseSchemaWithoutEffects>;

type BaseCollectionConfig<S extends BaseSchema> = {
schema?: S;
slug?: (entry: {
id: CollectionEntry<keyof typeof entryMap>['id'];
Expand All @@ -13,7 +26,7 @@ declare module 'astro:content' {
data: import('astro/zod').infer<S>;
}) => string | Promise<string>;
};
export function defineCollection<S extends import('astro/zod').ZodType>(
export function defineCollection<S extends BaseSchema>(
input: BaseCollectionConfig<S>
): BaseCollectionConfig<S>;

Expand Down
17 changes: 15 additions & 2 deletions packages/astro/src/content/template/types.generated.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,20 @@ declare module 'astro:content' {
export type CollectionEntry<C extends keyof typeof entryMap> =
typeof entryMap[C][keyof typeof entryMap[C]] & Render;

type BaseCollectionConfig<S extends import('astro/zod').ZodType> = {
type BaseSchemaWithoutEffects =
| import('astro/zod').AnyZodObject
| import('astro/zod').ZodUnion<import('astro/zod').AnyZodObject[]>
| import('astro/zod').ZodDiscriminatedUnion<string, import('astro/zod').AnyZodObject[]>
| import('astro/zod').ZodIntersection<
import('astro/zod').AnyZodObject,
import('astro/zod').AnyZodObject
>;

type BaseSchema =
| BaseSchemaWithoutEffects
| import('astro/zod').ZodEffects<BaseSchemaWithoutEffects>;

type BaseCollectionConfig<S extends BaseSchema> = {
schema?: S;
slug?: (entry: {
id: CollectionEntry<keyof typeof entryMap>['id'];
Expand All @@ -13,7 +26,7 @@ declare module 'astro:content' {
data: import('astro/zod').infer<S>;
}) => string | Promise<string>;
};
export function defineCollection<S extends import('astro/zod').ZodType>(
export function defineCollection<S extends BaseSchema>(
input: BaseCollectionConfig<S>
): BaseCollectionConfig<S>;

Expand Down

0 comments on commit 8c4ef10

Please sign in to comment.