Commit 7ec7159f authored by Ben Gubler's avatar Ben Gubler

feat: upgrade Zod from v3 to v4

parent 1c5f64b9
......@@ -15,7 +15,7 @@
"@slack/web-api": "^7.6.0",
"ai": "^3.4.14",
"slack-block-builder": "^2.8.0",
"zod": "^3.25.76"
"zod": "^4.0.14"
},
"devDependencies": {
"@vercel/ncc": "^0.38.3"
......
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -14,6 +14,6 @@
"react": "rc",
"react-dom": "rc",
"typescript": "5.3.3",
"zod": "^3.22.4"
"zod": "^4.0.14"
}
}
......@@ -353,8 +353,8 @@
"webpack-sources1": "npm:webpack-sources@1.4.3",
"webpack-sources3": "npm:webpack-sources@3.2.3",
"ws": "8.2.3",
"zod": "3.25.76",
"zod-validation-error": "3.4.0"
"zod": "4.0.14",
"zod-validation-error": "4.0.1"
},
"keywords": [
"react",
......
......@@ -73,16 +73,14 @@ export function parseAppSegmentConfig(
route: string
): AppSegmentConfig {
const parsed = AppSegmentConfigSchema.safeParse(data, {
errorMap: (issue, ctx) => {
if (issue.path.length === 1 && issue.path[0] === 'revalidate') {
return {
message: `Invalid revalidate value ${JSON.stringify(
ctx.data
)} on "${route}", must be a non-negative number or false`,
}
error: (input) => {
if (input.path?.length === 1 && input.path[0] === 'revalidate') {
return `Invalid revalidate value ${JSON.stringify(
input.data
)} on "${route}", must be a non-negative number or false`
}
return { message: ctx.defaultError }
return undefined
},
})
......
......@@ -8,11 +8,11 @@ const RouteHasSchema = z.discriminatedUnion('type', [
.object({
type: z.enum(['header', 'query', 'cookie']),
key: z.string({
required_error: 'key is required when type is header, query or cookie',
error: 'key is required when type is header, query or cookie',
}),
value: z
.string({
invalid_type_error: 'value must be a string',
error: 'value must be a string',
})
.optional(),
})
......@@ -21,7 +21,7 @@ const RouteHasSchema = z.discriminatedUnion('type', [
.object({
type: z.literal('host'),
value: z.string({
required_error: 'host must have a value',
error: () => 'host must have a value',
}),
})
.strict(),
......@@ -32,23 +32,28 @@ const RouteHasSchema = z.discriminatedUnion('type', [
*/
export const SourceSchema = z
.string({
required_error: 'source is required',
error: (issue) =>
typeof issue.input !== 'string'
? 'source must be a string'
: 'source is required',
})
.max(4096, 'exceeds max built length of 4096 for route')
.superRefine((val, ctx) => {
if (!val.startsWith('/')) {
return ctx.addIssue({
code: z.ZodIssueCode.custom,
ctx.issues.push({
code: 'custom',
message: `source must start with /`,
input: '',
})
}
const { error, regexStr } = tryToParsePath(val)
if (error || !regexStr) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
ctx.issues.push({
code: 'custom',
message: `Invalid source '${val}': ${error.message}`,
input: '',
})
}
})
......@@ -66,7 +71,7 @@ const MiddlewareConfigMatcherInputSchema = z.union([
SourceSchema,
z.array(
z.union([SourceSchema, MiddlewareMatcherInputSchema], {
invalid_type_error: 'must be an array of strings or middleware matchers',
error: () => 'must be an array of strings or middleware matchers',
})
),
])
......@@ -82,9 +87,10 @@ const GlobSchema = z.string().superRefine((val, ctx) => {
try {
picomatch(val)
} catch (err: any) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
ctx.issues.push({
code: 'custom',
message: `Invalid glob pattern '${val}': ${err.message}`,
input: '',
})
}
})
......
......@@ -31,6 +31,33 @@ const zSizeLimit = z.custom<SizeLimit>((val) => {
return false
})
const functionSchema = <T>(_schema: T) =>
z.custom<
(
defaultMap: ExportPathMap,
ctx: {
dev: boolean
dir: string
outDir: string | null
distDir: string
buildId: string
}
) => ExportPathMap | Promise<ExportPathMap>
>((val) => typeof val === 'function')
const generateBuildIdSchema = <T>(_schema: T) =>
z.custom<() => string | Promise<string | null> | null>(
(val) => typeof val === 'function'
)
const runAfterProductionCompileSchema = <T>(_schema: T) =>
z.custom<
(metadata: { projectDir: string; distDir: string }) => Promise<void>
>((val) => typeof val === 'function')
const createAsyncFunctionSchema = <T>(_schema: T) =>
z.custom<() => Promise<any>>((val) => typeof val === 'function')
const zExportMap: zod.ZodType<ExportPathMap> = z.record(
z.string(),
z.object({
......@@ -271,10 +298,11 @@ export const configSchema: zod.ZodType<NextConfig> = z.lazy(() =>
]),
define: z.record(z.string(), z.string()).optional(),
defineServer: z.record(z.string(), z.string()).optional(),
runAfterProductionCompile: z
.function()
.returns(z.promise(z.void()))
.optional(),
runAfterProductionCompile: runAfterProductionCompileSchema(
z.function({
output: z.promise(z.void()),
})
).optional(),
})
.optional(),
compress: z.boolean().optional(),
......@@ -340,6 +368,7 @@ export const configSchema: zod.ZodType<NextConfig> = z.lazy(() =>
.optional(),
cacheLife: z
.record(
z.string(),
z.object({
stale: z.number().optional(),
revalidate: z.number().optional(),
......@@ -538,37 +567,36 @@ export const configSchema: zod.ZodType<NextConfig> = z.lazy(() =>
optimizeRouterScrolling: z.boolean().optional(),
})
.optional(),
exportPathMap: z
.function()
.args(
zExportMap,
z.object({
dev: z.boolean(),
dir: z.string(),
outDir: z.string().nullable(),
distDir: z.string(),
buildId: z.string(),
})
)
.returns(z.union([zExportMap, z.promise(zExportMap)]))
.optional(),
generateBuildId: z
.function()
.args()
.returns(
z.union([
exportPathMap: functionSchema(
z.function({
input: z.tuple([
zExportMap,
z.object({
dev: z.boolean(),
dir: z.string(),
outDir: z.string().nullable(),
distDir: z.string(),
buildId: z.string(),
}),
]),
output: z.union([zExportMap, z.promise(zExportMap)]),
})
).optional(),
generateBuildId: generateBuildIdSchema(
z.function({
output: z.union([
z.string(),
z.null(),
z.promise(z.union([z.string(), z.null()])),
])
)
.optional(),
]),
})
).optional(),
generateEtags: z.boolean().optional(),
headers: z
.function()
.args()
.returns(z.promise(z.array(zHeader)))
.optional(),
headers: createAsyncFunctionSchema(
z.function({
output: z.promise(z.array(zHeader)),
})
).optional(),
htmlLimitedBots: z.instanceof(RegExp).optional(),
httpAgentOptions: z
.strictObject({ keepAlive: z.boolean().optional() })
......@@ -699,16 +727,14 @@ export const configSchema: zod.ZodType<NextConfig> = z.lazy(() =>
reactProductionProfiling: z.boolean().optional(),
reactStrictMode: z.boolean().nullable().optional(),
reactMaxHeadersLength: z.number().nonnegative().int().optional(),
redirects: z
.function()
.args()
.returns(z.promise(z.array(zRedirect)))
.optional(),
rewrites: z
.function()
.args()
.returns(
z.promise(
redirects: createAsyncFunctionSchema(
z.function({
output: z.promise(z.array(zRedirect)),
})
).optional(),
rewrites: createAsyncFunctionSchema(
z.function({
output: z.promise(
z.union([
z.array(zRewrite),
z.object({
......@@ -717,9 +743,9 @@ export const configSchema: zod.ZodType<NextConfig> = z.lazy(() =>
fallback: z.array(zRewrite),
}),
])
)
)
.optional(),
),
})
).optional(),
// sassOptions properties are unknown besides implementation, use z.any() here
sassOptions: z
.object({
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment