Migrate from Zod v3 to v4 (#14639)

Closes [#1526](https://github.com/twentyhq/core-team-issues/issues/1526)

---------

Co-authored-by: Félix Malfait <felix@twenty.com>
Co-authored-by: Félix Malfait <felix.malfait@gmail.com>
This commit is contained in:
Abdul Rahman
2025-09-24 21:59:05 +05:30
committed by GitHub
parent 8d78032357
commit 3cada58908
98 changed files with 809 additions and 1075 deletions
@@ -1,6 +1,6 @@
import { type WorkflowRunState } from '@/workflow/types/Workflow';
import { workflowRunStateSchema } from '@/workflow/validation-schemas/workflowSchema';
import { isDefined } from 'twenty-shared/utils';
import { workflowRunStateSchema } from 'twenty-shared/workflow';
import { type JsonValue } from 'type-fest';
export const orderWorkflowRunState = (value: JsonValue) => {
@@ -290,7 +290,7 @@ export const FieldActorValueSchema = z.object({
name: z.string(),
context: z
.object({
provider: z.nativeEnum(ConnectedAccountProvider).optional(),
provider: z.enum(ConnectedAccountProvider).optional(),
})
.nullable(),
});
@@ -4,7 +4,7 @@ import { CurrencyCode } from '../CurrencyCode';
import { type FieldCurrencyValue } from '../FieldMetadata';
const currencySchema = z.object({
currencyCode: z.nativeEnum(CurrencyCode).nullable(),
currencyCode: z.enum(CurrencyCode).nullable(),
amountMicros: z.number().nullable(),
});
@@ -5,13 +5,17 @@ import { type FieldJsonValue, type Json } from '../FieldMetadata';
// See https://zod.dev/?id=json-type
const literalSchema = z.union([z.string(), z.number(), z.boolean(), z.null()]);
const jsonSchema: z.ZodType<Json> = z.lazy(() =>
z.union([literalSchema, z.array(jsonSchema), z.record(jsonSchema)]),
z.union([
literalSchema,
z.array(jsonSchema),
z.record(z.string(), jsonSchema),
]),
);
export const jsonWithoutLiteralsSchema: z.ZodType<FieldJsonValue> = z.union([
z.null(), // Exclude literal values other than null
z.array(jsonSchema),
z.record(jsonSchema),
z.record(z.string(), jsonSchema),
]);
export const isFieldRawJsonValue = (
@@ -2,4 +2,4 @@ import { z } from 'zod';
import { CurrencyCode } from '@/object-record/record-field/ui/types/CurrencyCode';
export const currencyCodeSchema = z.nativeEnum(CurrencyCode);
export const currencyCodeSchema = z.enum(CurrencyCode);
@@ -10,6 +10,8 @@ export const currencyFieldDefaultValueSchema = z.object({
currencyCode: simpleQuotesStringSchema.refine(
(value): value is `'${CurrencyCode}'` =>
currencyCodeSchema.safeParse(stripSimpleQuotesFromString(value)).success,
{ message: 'String is not a valid currencyCode' },
{
error: 'String is not a valid currencyCode',
},
),
});
@@ -1,3 +1,3 @@
import { z } from 'zod';
export const emailSchema = z.string().email();
export const emailSchema = z.email();