-
-
Notifications
You must be signed in to change notification settings - Fork 47
Migrate zod v3 to v4 #269
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Migrate zod v3 to v4 #269
Changes from all commits
f2e9232
ba4f18b
e0b65bf
e0a5bbc
0644a52
d1ec11d
9e3a67a
a6c40ef
977316a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,11 +12,12 @@ export function zodErrorToValidationErrors( | |
| let valid: ValidationError['valid']; | ||
|
|
||
| switch (issue.code) { | ||
| case 'invalid_enum_value': | ||
| case 'invalid_value': | ||
| // @ts-expect-error `valid` is not used currently. | ||
| // eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
| valid = issue.options; | ||
| valid = issue.values; | ||
|
Comment on lines
-17
to
+18
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| break; | ||
| case 'invalid_string': | ||
| case 'invalid_format': | ||
|
Comment on lines
-19
to
+20
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| type = 'contains'; | ||
| break; | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,19 +7,20 @@ export const SearchCollection = z.object({ | |
| descriptionField: z.string().optional().nullable(), | ||
| thumbnailField: z.string().optional().nullable(), | ||
| fields: z.array(z.string().min(1, 'field name cannot be empty')), | ||
| filter: z.object({}).optional().nullable() as z.ZodType<Filter | undefined>, | ||
| filter: z.object({}).optional().nullable() as z.ZodNullable<z.ZodOptional<z.ZodType<Filter>>>, | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not directly related to the upgrade, but it was causing a type error in |
||
| sort: z.string().optional().nullable(), | ||
| limit: z.number().gte(-1, 'greater than or equal to -1').nullable(), | ||
| availableGlobally: z.boolean().optional().default(false), | ||
| availableGlobally: z.boolean().optional().prefault(false), | ||
| }); | ||
|
|
||
| export const ModuleSettings = z.object({ | ||
| searchMode: z.enum(['as_you_type', 'on_submit'], { | ||
| errorMap: () => ({ message: 'either as_you_type or on_submit' }), | ||
| error: () => 'either as_you_type or on_submit', | ||
| }), | ||
| collections: z.array(SearchCollection), | ||
| triggerRate: z.number().gte(0, 'greater than or equal to 0').optional(), | ||
| commandPaletteEnabled: z.boolean().optional().default(true), | ||
| commandPaletteEnabled: z.boolean().optional().prefault(true), | ||
| recentSearchLimit: z.number().gte(0, 'greater than or equal to 0').optional(), | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This field is used by |
||
| }); | ||
|
|
||
| interface CollectionSearchInfo { | ||
|
|
@@ -38,6 +39,7 @@ export const defaultSettings: SearchConfigType = { | |
| collections: [], | ||
| triggerRate: 100, | ||
| commandPaletteEnabled: true, | ||
| recentSearchLimit: 5, | ||
| }; | ||
|
|
||
| export type SearchCollectionType = z.infer<typeof SearchCollection>; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,25 +1,26 @@ | ||
| import type { FilterOperator, ValidationError } from '@directus/types'; | ||
| import type { ZodError, ZodIssue } from 'zod'; | ||
| import type { core, ZodError } from 'zod'; | ||
|
|
||
| export function zodErrorToValidationErrors( | ||
| error: ZodError, | ||
| collection: string, | ||
| group: string | null = null, | ||
| ): ValidationError[] { | ||
| return error.issues.map((issue: ZodIssue): ValidationError => { | ||
| return error.issues.map((issue: core.$ZodIssue): ValidationError => { | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Issue-related interfaces are moved to a new |
||
| const field = issue.path.join('.'); | ||
| let type: FilterOperator = 'eq'; // Default value, modify as necessary | ||
| let valid: ValidationError['valid']; | ||
|
|
||
| switch (issue.code) { | ||
| case 'invalid_enum_value': | ||
| case 'invalid_value': | ||
| // @ts-expect-error `valid` is not used currently. | ||
| // eslint-disable-next-line unused-imports/no-unused-vars | ||
| valid = issue.options; | ||
| valid = issue.values; | ||
| break; | ||
| case 'invalid_string': | ||
| case 'invalid_format': | ||
| type = 'contains'; | ||
| break; | ||
| // Add more mappings as necessary | ||
| // Add more mappings as necessary | ||
| } | ||
|
|
||
| return { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,9 @@ | ||
| { | ||
| "compilerOptions": { | ||
| "target": "ES2019", | ||
| "lib": ["ES2019", "DOM"], | ||
| "lib": ["ES2021", "DOM"], | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The extension included uses of |
||
| "rootDir": "./src", | ||
| "moduleResolution": "node", | ||
| "moduleResolution": "bundler", | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| "resolveJsonModule": false, | ||
| "strict": true, | ||
| "strictBindCallApply": true, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
z.ZodInvalidEnumValueIssuehas merged withZodIssueInvalidValue