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:
+2
-2
@@ -1,4 +1,4 @@
|
||||
import { type SafeParseError } from 'zod';
|
||||
import { type ZodSafeParseError } from 'zod';
|
||||
|
||||
import { camelCaseStringSchema } from '../camelCaseStringSchema';
|
||||
|
||||
@@ -11,7 +11,7 @@ describe('camelCaseStringSchema', () => {
|
||||
it('fails for non-camel case strings', () => {
|
||||
const result = camelCaseStringSchema.safeParse('NotCamelCase');
|
||||
expect(result.success).toBe(false);
|
||||
expect((result as SafeParseError<string>).error.errors).toEqual([
|
||||
expect((result as ZodSafeParseError<string>).error.issues).toEqual([
|
||||
{
|
||||
code: 'custom',
|
||||
message: 'String should be camel case',
|
||||
|
||||
+2
-2
@@ -1,4 +1,4 @@
|
||||
import { type SafeParseError } from 'zod';
|
||||
import { type ZodSafeParseError } from 'zod';
|
||||
|
||||
import { simpleQuotesStringSchema } from '../simpleQuotesStringSchema';
|
||||
|
||||
@@ -27,7 +27,7 @@ describe('simpleQuotesStringSchema', () => {
|
||||
|
||||
// Then
|
||||
expect(result.success).toBe(false);
|
||||
expect((result as SafeParseError<string>).error.errors).toEqual([
|
||||
expect((result as ZodSafeParseError<string>).error.issues).toEqual([
|
||||
{
|
||||
code: 'custom',
|
||||
message: 'String should be wrapped in simple quotes',
|
||||
|
||||
@@ -4,5 +4,5 @@ import { z } from 'zod';
|
||||
export const camelCaseStringSchema = z
|
||||
.string()
|
||||
.refine((value) => camelCase(value) === value, {
|
||||
message: 'String should be camel case',
|
||||
error: 'String should be camel case',
|
||||
});
|
||||
|
||||
@@ -1,15 +1,11 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
export const simpleQuotesStringSchema: z.ZodType<
|
||||
`'${string}'`,
|
||||
z.ZodTypeDef,
|
||||
string
|
||||
> = z
|
||||
export const simpleQuotesStringSchema = z
|
||||
.string()
|
||||
.refine(
|
||||
(value: string): value is `'${string}'` =>
|
||||
value.startsWith("'") && value.endsWith("'"),
|
||||
{
|
||||
message: 'String should be wrapped in simple quotes',
|
||||
error: 'String should be wrapped in simple quotes',
|
||||
},
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user