Skip to content

Commit

Permalink
refactor: 'zod' function() instead of self made refine()
Browse files Browse the repository at this point in the history
  • Loading branch information
alextim committed Jun 16, 2022
1 parent b61e1f9 commit 036bac7
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions packages/integrations/sitemap/src/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,9 @@ import { SITEMAP_CONFIG_DEFAULTS } from './config-defaults';

const localeKeySchema = () => z.string().min(1);

const isFunction = (fn: any) => fn instanceof Function;

const fnSchema = () =>
z
.any()
.refine((val) => !val || isFunction(val), { message: 'Not a function' })
.optional();

export const SitemapOptionsSchema = z
.object({
filter: fnSchema(),
filter: z.function().optional(),
customPages: z.string().url().array().optional(),
canonicalURL: z.string().url().optional(),

Expand All @@ -32,12 +24,12 @@ export const SitemapOptionsSchema = z
),
})
.refine((val) => !val || val.locales[val.defaultLocale], {
message: '`defaultLocale` must exists in `locales` keys',
message: '`defaultLocale` must exist in `locales` keys',
})
.optional(),

entryLimit: z.number().nonnegative().default(SITEMAP_CONFIG_DEFAULTS.entryLimit),
serialize: fnSchema(),
entryLimit: z.number().nonnegative().optional().default(SITEMAP_CONFIG_DEFAULTS.entryLimit),
serialize: z.function().optional(),

changefreq: z.enum(changefreqValues).optional(),
lastmod: z.date().optional(),
Expand Down

0 comments on commit 036bac7

Please sign in to comment.