refactor: 'zod' function() instead of self made refine()
This commit is contained in:
parent
b61e1f9ba3
commit
036bac730d
1 changed files with 4 additions and 12 deletions
|
@ -4,17 +4,9 @@ import { SITEMAP_CONFIG_DEFAULTS } from './config-defaults';
|
||||||
|
|
||||||
const localeKeySchema = () => z.string().min(1);
|
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
|
export const SitemapOptionsSchema = z
|
||||||
.object({
|
.object({
|
||||||
filter: fnSchema(),
|
filter: z.function().optional(),
|
||||||
customPages: z.string().url().array().optional(),
|
customPages: z.string().url().array().optional(),
|
||||||
canonicalURL: z.string().url().optional(),
|
canonicalURL: z.string().url().optional(),
|
||||||
|
|
||||||
|
@ -32,12 +24,12 @@ export const SitemapOptionsSchema = z
|
||||||
),
|
),
|
||||||
})
|
})
|
||||||
.refine((val) => !val || val.locales[val.defaultLocale], {
|
.refine((val) => !val || val.locales[val.defaultLocale], {
|
||||||
message: '`defaultLocale` must exists in `locales` keys',
|
message: '`defaultLocale` must exist in `locales` keys',
|
||||||
})
|
})
|
||||||
.optional(),
|
.optional(),
|
||||||
|
|
||||||
entryLimit: z.number().nonnegative().default(SITEMAP_CONFIG_DEFAULTS.entryLimit),
|
entryLimit: z.number().nonnegative().optional().default(SITEMAP_CONFIG_DEFAULTS.entryLimit),
|
||||||
serialize: fnSchema(),
|
serialize: z.function().optional(),
|
||||||
|
|
||||||
changefreq: z.enum(changefreqValues).optional(),
|
changefreq: z.enum(changefreqValues).optional(),
|
||||||
lastmod: z.date().optional(),
|
lastmod: z.date().optional(),
|
||||||
|
|
Loading…
Add table
Reference in a new issue