The minimalistic document archiving platform.
feat(custom-properties): migrate from zod to valibot validation (#1049)
Corentin Thomasset2b0c258f8a6a
diff --git a/apps/papra-server/src/modules/custom-properties/custom-properties.routes.ts b/apps/papra-server/src/modules/custom-properties/custom-properties.routes.tsindex 312eae0f..8155b5b3 100644--- a/apps/papra-server/src/modules/custom-properties/custom-properties.routes.ts+++ b/apps/papra-server/src/modules/custom-properties/custom-properties.routes.ts@@ -10,7 +10,6 @@ import { organizationIdSchema } from '../organizations/organization.schemas';import { createOrganizationsRepository } from '../organizations/organizations.repository';import { ensureUserIsInOrganization } from '../organizations/organizations.usecases';import { validateJsonBody, validateParams } from '../shared/validation/validation';-import { legacyValidateJsonBody } from '../shared/validation/validation.legacy';import { aggregateDocumentCustomPropertyValues } from './custom-properties.models';import { createCustomPropertiesRepository } from './custom-properties.repository';import { customPropertyDefinitionIdSchema } from './custom-properties.schemas';@@ -37,7 +36,7 @@ function setupCreatePropertyDefinitionRoute({ app, db, config }: RouteDefinitionvalidateParams(v.strictObject({organizationId: organizationIdSchema,})),- legacyValidateJsonBody(createPropertyDefinitionBodySchema),+ validateJsonBody(createPropertyDefinitionBodySchema),async (context) => {const { userId } = getUser({ context });const { organizationId } = context.req.valid('param');diff --git a/apps/papra-server/src/modules/custom-properties/custom-properties.schemas.legacy.ts b/apps/papra-server/src/modules/custom-properties/custom-properties.schemas.legacy.tsdeleted file mode 100644index 4f3ecf12..00000000--- a/apps/papra-server/src/modules/custom-properties/custom-properties.schemas.legacy.ts+++ /dev/null@@ -1,5 +0,0 @@-import { z } from 'zod';-import { CUSTOM_PROPERTY_DEFINITION_ID_REGEX, CUSTOM_PROPERTY_TYPES_LIST } from './custom-properties.constants';--export const customPropertyDefinitionIdSchema = z.string().regex(CUSTOM_PROPERTY_DEFINITION_ID_REGEX);-export const customPropertyTypeSchema = z.enum(CUSTOM_PROPERTY_TYPES_LIST as [string, ...string[]]);diff --git a/apps/papra-server/src/modules/custom-properties/custom-properties.usecases.ts b/apps/papra-server/src/modules/custom-properties/custom-properties.usecases.tsindex 60e5f64b..5442b490 100644--- a/apps/papra-server/src/modules/custom-properties/custom-properties.usecases.ts+++ b/apps/papra-server/src/modules/custom-properties/custom-properties.usecases.ts@@ -2,8 +2,11 @@ import type { Config } from '../config/config.types';import type { DocumentsRepository } from '../documents/documents.repository';import type { OrganizationsRepository } from '../organizations/organizations.repository';import type { CustomPropertiesRepository } from './custom-properties.repository';+import type { BaseUpdateFields } from './definitions/custom-property-definition.models';import type { CreatePropertyDefinition } from './definitions/custom-property-definition.registry';import type { CustomPropertiesOptionsRepository } from './options/custom-properties-options.repository';+import * as v from 'valibot';+import {createCustomPropertyDefinitionInvalidUpdateError,createCustomPropertyDefinitionNotFoundError,@@ -70,13 +73,13 @@ export async function updatePropertyDefinition({const customPropertyTypeDefinition = getCustomPropertyTypeDefinition({ type: existingDefinition.type });- const parseResult = customPropertyTypeDefinition.definition.updatePropertySchema.safeParse(rawDefinition);+ const parseResult = v.safeParse(customPropertyTypeDefinition.definition.updatePropertySchema, rawDefinition);if (!parseResult.success) {throw createCustomPropertyDefinitionInvalidUpdateError();}- const definition = parseResult.data;+ const definition = parseResult.output as BaseUpdateFields & Record<string, unknown>;const { propertyDefinition } = await customPropertiesRepository.updatePropertyDefinition({propertyDefinitionId,@@ -133,13 +136,13 @@ export async function setDocumentCustomPropertyValue({const customPropertyTypeDefinition = getCustomPropertyTypeDefinition({ type: customProperty.type });- const parseResult = customPropertyTypeDefinition.value.inputSchema.safeParse(value);+ const parseResult = v.safeParse(customPropertyTypeDefinition.value.inputSchema, value);if (!parseResult.success) {throw createCustomPropertyValueInvalidError();}- const parsedValue = parseResult.data;+ const parsedValue = parseResult.output;await customPropertyTypeDefinition.value.extendInputValidation?.({value: parsedValue,diff --git a/apps/papra-server/src/modules/custom-properties/definitions/boolean/boolean.custom-property-definition.ts b/apps/papra-server/src/modules/custom-properties/definitions/boolean/boolean.custom-property-definition.tsindex 045ea49b..f986f07f 100644--- a/apps/papra-server/src/modules/custom-properties/definitions/boolean/boolean.custom-property-definition.ts+++ b/apps/papra-server/src/modules/custom-properties/definitions/boolean/boolean.custom-property-definition.ts@@ -1,4 +1,4 @@-import z from 'zod';+import * as v from 'valibot';import { defineCustomPropertyType, ensureRow } from '../custom-property-definition.models';export const booleanCustomPropertyDefinition = defineCustomPropertyType({@@ -6,7 +6,7 @@ export const booleanCustomPropertyDefinition = defineCustomPropertyType({value: {- inputSchema: z.boolean(),+ inputSchema: v.boolean(),toDb: ({ value }) => ({ booleanValue: value }),diff --git a/apps/papra-server/src/modules/custom-properties/definitions/custom-property-definition.models.ts b/apps/papra-server/src/modules/custom-properties/definitions/custom-property-definition.models.tsindex 3234b9e6..084a7807 100644--- a/apps/papra-server/src/modules/custom-properties/definitions/custom-property-definition.models.ts+++ b/apps/papra-server/src/modules/custom-properties/definitions/custom-property-definition.models.ts@@ -4,7 +4,7 @@ import type { OrganizationsRepository } from '../../organizations/organizations.import type { CustomPropertiesRepository } from '../custom-properties.repository';import type { CustomPropertyDefinition, DbInsertableDocumentCustomPropertyValue } from '../custom-properties.types';import type { CustomPropertiesOptionsRepository } from '../options/custom-properties-options.repository';-import z from 'zod';+import * as v from 'valibot';import { isNil } from '../../shared/utils';import { customPropertyDefinitionDescriptionSchema, customPropertyDefinitionDisplayOrderSchema, customPropertyDefinitionNameSchema } from './custom-property-definition.schema';@@ -51,19 +51,19 @@ type BaseCreateFields<TypeName extends string> = {displayOrder?: number;};-type BaseUpdateFields = {+export type BaseUpdateFields = {name?: string;description?: string | null;displayOrder?: number;};-type InferExtraFields<T> = T extends z.ZodType<infer U> ? U : Record<string, never>;+type InferExtraFields<T> = T extends v.GenericSchema ? v.InferOutput<T> : Record<string, never>;export type CustomPropertyTypeDefinitionInput<TypeName extends string = string,ValueInput = unknown,- CreateExtraSchema extends z.ZodObject<Record<string, z.ZodTypeAny>> | undefined = undefined,- UpdateExtraSchema extends z.ZodObject<Record<string, z.ZodTypeAny>> | undefined = undefined,+ CreateExtraSchema extends v.ObjectSchema<v.ObjectEntries, undefined> | undefined = undefined,+ UpdateExtraSchema extends v.ObjectSchema<v.ObjectEntries, undefined> | undefined = undefined,> = {typeName: TypeName;@@ -88,7 +88,7 @@ export type CustomPropertyTypeDefinitionInput<};value: {- inputSchema: z.ZodType<ValueInput, z.ZodTypeDef, unknown>;+ inputSchema: v.BaseSchema<unknown, ValueInput, v.BaseIssue<unknown>>;extendInputValidation?: (args: {value: ValueInput;@@ -112,10 +112,10 @@ export type CustomPropertyTypeDefinitionInput<export type CustomPropertyTypeDefinition = {typeName: string;definition: {- createExtraSchema?: z.ZodObject<Record<string, z.ZodTypeAny>>;- updateExtraSchema?: z.ZodObject<Record<string, z.ZodTypeAny>>;- createPropertySchema: z.ZodType<BaseCreateFields<string>>;- updatePropertySchema: z.ZodType<BaseUpdateFields>;+ createExtraSchema?: v.ObjectSchema<v.ObjectEntries, undefined>;+ updateExtraSchema?: v.ObjectSchema<v.ObjectEntries, undefined>;+ createPropertySchema: v.GenericSchema;+ updatePropertySchema: v.GenericSchema;onCreate?: (args: {apiInput: BaseCreateFields<string> & Record<string, unknown>;propertyDefinition: CustomPropertyDefinition;@@ -130,7 +130,7 @@ export type CustomPropertyTypeDefinition = {}) => Promise<void>;};value: {- inputSchema: z.ZodType<unknown, z.ZodTypeDef, unknown>;+ inputSchema: v.GenericSchema;extendInputValidation?: (args: {value: unknown;customProperty: CustomPropertyDefinition;@@ -146,46 +146,46 @@ export type CustomPropertyTypeDefinition = {// Conditional types that properly resolve the schema shape based on whether extra schemas are provided.// This concentrates type assertions in defineCustomPropertyType so all consumer code is cast-free.-const baseCreatePropertySchema = z.object({+const baseCreatePropertySchema = v.object({name: customPropertyDefinitionNameSchema,- description: customPropertyDefinitionDescriptionSchema.optional(),- displayOrder: customPropertyDefinitionDisplayOrderSchema.optional(),+ description: v.optional(customPropertyDefinitionDescriptionSchema),+ displayOrder: v.optional(customPropertyDefinitionDisplayOrderSchema),});-const baseUpdatePropertySchema = z.object({- name: customPropertyDefinitionNameSchema.optional(),- description: customPropertyDefinitionDescriptionSchema.nullable().optional(),- displayOrder: customPropertyDefinitionDisplayOrderSchema.optional(),+const baseUpdatePropertySchema = v.object({+ name: v.optional(customPropertyDefinitionNameSchema),+ description: v.optional(v.nullable(customPropertyDefinitionDescriptionSchema)),+ displayOrder: v.optional(customPropertyDefinitionDisplayOrderSchema),});-type BaseCreateSchemaShape = typeof baseCreatePropertySchema.shape;-type BaseUpdateSchemaShape = typeof baseUpdatePropertySchema.shape;+type BaseCreateEntries = typeof baseCreatePropertySchema.entries;+type BaseUpdateEntries = typeof baseUpdatePropertySchema.entries;-type CreatePropertySchemaFor<T extends string, Extra extends z.ZodObject<Record<string, z.ZodTypeAny>> | undefined>- = Extra extends z.ZodObject<infer E extends z.ZodRawShape>- ? z.ZodObject<{ type: z.ZodLiteral<T> } & BaseCreateSchemaShape & E>- : z.ZodObject<{ type: z.ZodLiteral<T> } & BaseCreateSchemaShape>;+type CreatePropertySchemaFor<T extends string, Extra extends v.ObjectSchema<v.ObjectEntries, undefined> | undefined>+ = Extra extends v.ObjectSchema<infer E extends v.ObjectEntries, undefined>+ ? v.ObjectSchema<{ type: v.LiteralSchema<T, undefined> } & BaseCreateEntries & E, undefined>+ : v.ObjectSchema<{ type: v.LiteralSchema<T, undefined> } & BaseCreateEntries, undefined>;-type UpdatePropertySchemaFor<Extra extends z.ZodObject<Record<string, z.ZodTypeAny>> | undefined>- = Extra extends z.ZodObject<infer E extends z.ZodRawShape>- ? z.ZodObject<BaseUpdateSchemaShape & E>- : z.ZodObject<BaseUpdateSchemaShape>;+type UpdatePropertySchemaFor<Extra extends v.ObjectSchema<v.ObjectEntries, undefined> | undefined>+ = Extra extends v.ObjectSchema<infer E extends v.ObjectEntries, undefined>+ ? v.ObjectSchema<BaseUpdateEntries & E, undefined>+ : v.ObjectSchema<BaseUpdateEntries, undefined>;-function buildCreatePropertySchema(typeName: string, extraSchema?: z.ZodObject<z.ZodRawShape>) {- const schema = baseCreatePropertySchema.extend({ type: z.literal(typeName) });+function buildCreatePropertySchema(typeName: string, extraSchema?: v.ObjectSchema<v.ObjectEntries, undefined>) {+ const schema = v.object({ type: v.literal(typeName), ...baseCreatePropertySchema.entries });- return extraSchema ? schema.merge(extraSchema) : schema;+ return extraSchema ? v.object({ ...schema.entries, ...extraSchema.entries }) : schema;}-function buildUpdatePropertySchema(extraSchema?: z.ZodObject<z.ZodRawShape>) {- return extraSchema ? baseUpdatePropertySchema.merge(extraSchema) : baseUpdatePropertySchema;+function buildUpdatePropertySchema(extraSchema?: v.ObjectSchema<v.ObjectEntries, undefined>) {+ return extraSchema ? v.object({ ...baseUpdatePropertySchema.entries, ...extraSchema.entries }) : baseUpdatePropertySchema;}export function defineCustomPropertyType<TypeName extends string,ValueInput,- CreateExtraSchema extends z.ZodObject<Record<string, z.ZodTypeAny>> | undefined = undefined,- UpdateExtraSchema extends z.ZodObject<Record<string, z.ZodTypeAny>> | undefined = undefined,+ CreateExtraSchema extends v.ObjectSchema<v.ObjectEntries, undefined> | undefined = undefined,+ UpdateExtraSchema extends v.ObjectSchema<v.ObjectEntries, undefined> | undefined = undefined,>(config: CustomPropertyTypeDefinitionInput<TypeName, ValueInput, CreateExtraSchema, UpdateExtraSchema>) {return {...config,diff --git a/apps/papra-server/src/modules/custom-properties/definitions/custom-property-definition.registry.ts b/apps/papra-server/src/modules/custom-properties/definitions/custom-property-definition.registry.tsindex f8d0bc23..07129a0c 100644--- a/apps/papra-server/src/modules/custom-properties/definitions/custom-property-definition.registry.ts+++ b/apps/papra-server/src/modules/custom-properties/definitions/custom-property-definition.registry.ts@@ -1,5 +1,5 @@import type { CustomPropertyTypeDefinition } from './custom-property-definition.models';-import { z } from 'zod';+import * as v from 'valibot';import { createError } from '../../shared/errors/errors';import { booleanCustomPropertyDefinition } from './boolean/boolean.custom-property-definition';import { dateCustomPropertyDefinition } from './date/date.custom-property-definition';@@ -39,16 +39,6 @@ export function getCustomPropertyTypeDefinition({ type }: { type: string }) {return definition;}-// Build schemas as explicit tuples so TypeScript preserves individual types for the discriminated union-export const createPropertyDefinitionBodySchema = z.discriminatedUnion('type', [- textCustomPropertyDefinition.definition.createPropertySchema,- numberCustomPropertyDefinition.definition.createPropertySchema,- dateCustomPropertyDefinition.definition.createPropertySchema,- booleanCustomPropertyDefinition.definition.createPropertySchema,- selectCustomPropertyDefinition.definition.createPropertySchema,- multiSelectCustomPropertyDefinition.definition.createPropertySchema,- userRelationCustomPropertyDefinition.definition.createPropertySchema,- documentRelationCustomPropertyDefinition.definition.createPropertySchema,-]);--export type CreatePropertyDefinition = z.infer<typeof createPropertyDefinitionBodySchema>;+export const createPropertyDefinitionBodySchema = v.variant('type', customPropertyDefinitions.map(def => def.definition.createPropertySchema));++export type CreatePropertyDefinition = v.InferOutput<typeof createPropertyDefinitionBodySchema>;diff --git a/apps/papra-server/src/modules/custom-properties/definitions/custom-property-definition.schema.ts b/apps/papra-server/src/modules/custom-properties/definitions/custom-property-definition.schema.tsindex b04660fc..99f49cf9 100644--- a/apps/papra-server/src/modules/custom-properties/definitions/custom-property-definition.schema.ts+++ b/apps/papra-server/src/modules/custom-properties/definitions/custom-property-definition.schema.ts@@ -1,5 +1,5 @@-import { z } from 'zod';+import * as v from 'valibot';-export const customPropertyDefinitionNameSchema = z.string().trim().min(1).max(255);-export const customPropertyDefinitionDescriptionSchema = z.string().trim().max(1000);-export const customPropertyDefinitionDisplayOrderSchema = z.number().int().min(0);+export const customPropertyDefinitionNameSchema = v.pipe(v.string(), v.trim(), v.minLength(1), v.maxLength(255));+export const customPropertyDefinitionDescriptionSchema = v.pipe(v.string(), v.trim(), v.maxLength(1000));+export const customPropertyDefinitionDisplayOrderSchema = v.pipe(v.number(), v.integer(), v.minValue(0));diff --git a/apps/papra-server/src/modules/custom-properties/definitions/date/date.custom-property-definition.ts b/apps/papra-server/src/modules/custom-properties/definitions/date/date.custom-property-definition.tsindex 36b28ecf..682a899a 100644--- a/apps/papra-server/src/modules/custom-properties/definitions/date/date.custom-property-definition.ts+++ b/apps/papra-server/src/modules/custom-properties/definitions/date/date.custom-property-definition.ts@@ -1,23 +1,14 @@-import z from 'zod';-import { isValidDate } from '../../../shared/date';+import * as v from 'valibot';import { defineCustomPropertyType, ensureRow } from '../custom-property-definition.models';-const dateInputSchema = z.union([z.string(), z.number()]).transform((value) => {- const date = new Date(value);-- if (!isValidDate(date)) {- throw new Error('Invalid date value');- }-- return date;-});-export const dateCustomPropertyDefinition = defineCustomPropertyType({typeName: 'date',value: {-- inputSchema: dateInputSchema,+ inputSchema: v.pipe(+ v.union([v.string(), v.number()]),+ v.toDate(),+ ),toDb: ({ value }) => ({ dateValue: value }),diff --git a/apps/papra-server/src/modules/custom-properties/definitions/document-relation/document-relation.custom-property-definition.ts b/apps/papra-server/src/modules/custom-properties/definitions/document-relation/document-relation.custom-property-definition.tsindex 8550d07b..4191188b 100644--- a/apps/papra-server/src/modules/custom-properties/definitions/document-relation/document-relation.custom-property-definition.ts+++ b/apps/papra-server/src/modules/custom-properties/definitions/document-relation/document-relation.custom-property-definition.ts@@ -1,4 +1,4 @@-import z from 'zod';+import * as v from 'valibot';import { createCustomPropertyRelatedDocumentNotFoundError } from '../../custom-properties.errors';import { defineCustomPropertyType } from '../custom-property-definition.models';@@ -7,7 +7,7 @@ export const documentRelationCustomPropertyDefinition = defineCustomPropertyTypevalue: {- inputSchema: z.array(z.string()),+ inputSchema: v.array(v.string()),extendInputValidation: async ({ value: documentIds, customProperty, documentsRepository }) => {const allDocumentsAreFromOrganization = await documentsRepository.areAllDocumentsInOrganization({diff --git a/apps/papra-server/src/modules/custom-properties/definitions/multi-select/multi-select.custom-property-definition.ts b/apps/papra-server/src/modules/custom-properties/definitions/multi-select/multi-select.custom-property-definition.tsindex bb56b862..7bcdd777 100644--- a/apps/papra-server/src/modules/custom-properties/definitions/multi-select/multi-select.custom-property-definition.ts+++ b/apps/papra-server/src/modules/custom-properties/definitions/multi-select/multi-select.custom-property-definition.ts@@ -1,19 +1,19 @@-import z from 'zod';-import { customPropertySelectOptionIdSchema } from '../../options/custom-properties-options.schemas.legacy';+import * as v from 'valibot';+import { customPropertySelectOptionIdSchema, selectCustomPropertyOptionNameSchema } from '../../options/custom-properties-options.schemas';import { ensureOptionsExist } from '../../options/custom-properties-options.usecases';import { defineCustomPropertyType } from '../custom-property-definition.models';-import { selectCustomPropertyOptionNameSchema } from '../select/select.custom-property-definition.schemas.legacy';export const multiSelectCustomPropertyDefinition = defineCustomPropertyType({typeName: 'multi_select',definition: {- createExtraSchema: z.object({- options: z- .array(z.object({+ createExtraSchema: v.object({+ options: v.pipe(+ v.array(v.object({name: selectCustomPropertyOptionNameSchema,- }))- .min(1, 'At least one option must be provided'),+ })),+ v.minLength(1, 'At least one option must be provided'),+ ),}),onCreate: async ({@@ -27,11 +27,14 @@ export const multiSelectCustomPropertyDefinition = defineCustomPropertyType({});},- updateExtraSchema: z.object({- options: z.array(z.object({- id: customPropertySelectOptionIdSchema.optional(),- name: selectCustomPropertyOptionNameSchema,- })).min(1, 'At least one option must be provided').optional(),+ updateExtraSchema: v.object({+ options: v.optional(v.pipe(+ v.array(v.object({+ id: v.optional(customPropertySelectOptionIdSchema),+ name: selectCustomPropertyOptionNameSchema,+ })),+ v.minLength(1, 'At least one option must be provided'),+ )),}),onUpdate: async ({@@ -50,7 +53,7 @@ export const multiSelectCustomPropertyDefinition = defineCustomPropertyType({value: {- inputSchema: z.array(customPropertySelectOptionIdSchema),+ inputSchema: v.array(customPropertySelectOptionIdSchema),extendInputValidation: async ({ value, customProperty, customPropertiesOptionsRepository }) => {await ensureOptionsExist({diff --git a/apps/papra-server/src/modules/custom-properties/definitions/number/number.custom-property-definition.ts b/apps/papra-server/src/modules/custom-properties/definitions/number/number.custom-property-definition.tsindex f6e58bd2..baa4dac3 100644--- a/apps/papra-server/src/modules/custom-properties/definitions/number/number.custom-property-definition.ts+++ b/apps/papra-server/src/modules/custom-properties/definitions/number/number.custom-property-definition.ts@@ -1,11 +1,11 @@-import z from 'zod';+import * as v from 'valibot';import { defineCustomPropertyType, ensureRow } from '../custom-property-definition.models';export const numberCustomPropertyDefinition = defineCustomPropertyType({typeName: 'number',value: {- inputSchema: z.number().finite(),+ inputSchema: v.pipe(v.number(), v.finite()),toDb: ({ value }) => ({ numberValue: value }),diff --git a/apps/papra-server/src/modules/custom-properties/definitions/select/select.custom-property-definition.schemas.legacy.ts b/apps/papra-server/src/modules/custom-properties/definitions/select/select.custom-property-definition.schemas.legacy.tsdeleted file mode 100644index e5af26c3..00000000--- a/apps/papra-server/src/modules/custom-properties/definitions/select/select.custom-property-definition.schemas.legacy.ts+++ /dev/null@@ -1,3 +0,0 @@-import z from 'zod';--export const selectCustomPropertyOptionNameSchema = z.string().trim().min(1).max(255);diff --git a/apps/papra-server/src/modules/custom-properties/definitions/select/select.custom-property-definition.ts b/apps/papra-server/src/modules/custom-properties/definitions/select/select.custom-property-definition.tsindex b1576f32..3fa6116d 100644--- a/apps/papra-server/src/modules/custom-properties/definitions/select/select.custom-property-definition.ts+++ b/apps/papra-server/src/modules/custom-properties/definitions/select/select.custom-property-definition.ts@@ -1,19 +1,17 @@-import z from 'zod';-import { customPropertySelectOptionIdSchema } from '../../options/custom-properties-options.schemas.legacy';+import * as v from 'valibot';+import { customPropertySelectOptionIdSchema, selectCustomPropertyOptionNameSchema } from '../../options/custom-properties-options.schemas';import { ensureOptionExists } from '../../options/custom-properties-options.usecases';import { defineCustomPropertyType } from '../custom-property-definition.models';-import { selectCustomPropertyOptionNameSchema } from './select.custom-property-definition.schemas.legacy';export const selectCustomPropertyDefinition = defineCustomPropertyType({typeName: 'select',definition: {- createExtraSchema: z.object({- options: z- .array(z.object({- name: selectCustomPropertyOptionNameSchema,- }))- .min(1, 'At least one option must be provided'),+ createExtraSchema: v.object({+ options: v.pipe(+ v.array(v.object({ name: selectCustomPropertyOptionNameSchema })),+ v.minLength(1, 'At least one option must be provided'),+ ),}),onCreate: async ({@@ -27,11 +25,14 @@ export const selectCustomPropertyDefinition = defineCustomPropertyType({});},- updateExtraSchema: z.object({- options: z.array(z.object({- id: customPropertySelectOptionIdSchema.optional(),- name: selectCustomPropertyOptionNameSchema,- })).min(1, 'At least one option must be provided').optional(),+ updateExtraSchema: v.object({+ options: v.optional(v.pipe(+ v.array(v.object({+ id: v.optional(customPropertySelectOptionIdSchema),+ name: selectCustomPropertyOptionNameSchema,+ })),+ v.minLength(1, 'At least one option must be provided'),+ )),}),onUpdate: async ({diff --git a/apps/papra-server/src/modules/custom-properties/definitions/text/text.custom-property-definition.ts b/apps/papra-server/src/modules/custom-properties/definitions/text/text.custom-property-definition.tsindex 995d7c6e..42ac0d73 100644--- a/apps/papra-server/src/modules/custom-properties/definitions/text/text.custom-property-definition.ts+++ b/apps/papra-server/src/modules/custom-properties/definitions/text/text.custom-property-definition.ts@@ -1,4 +1,4 @@-import z from 'zod';+import * as v from 'valibot';import { defineCustomPropertyType, ensureRow } from '../custom-property-definition.models';export const textCustomPropertyDefinition = defineCustomPropertyType({@@ -6,7 +6,7 @@ export const textCustomPropertyDefinition = defineCustomPropertyType({value: {- inputSchema: z.string().max(10_000, 'Text custom property value must be at most 10,000 characters long'),+ inputSchema: v.pipe(v.string(), v.maxLength(10_000, 'Text custom property value must be at most 10,000 characters long')),toDb: ({ value }) => ({ textValue: value }),diff --git a/apps/papra-server/src/modules/custom-properties/definitions/user-relation/user-relation.custom-property-definition.ts b/apps/papra-server/src/modules/custom-properties/definitions/user-relation/user-relation.custom-property-definition.tsindex e416a298..57a7de69 100644--- a/apps/papra-server/src/modules/custom-properties/definitions/user-relation/user-relation.custom-property-definition.ts+++ b/apps/papra-server/src/modules/custom-properties/definitions/user-relation/user-relation.custom-property-definition.ts@@ -1,4 +1,4 @@-import z from 'zod';+import * as v from 'valibot';import { createCustomPropertyUserNotFoundError } from '../../custom-properties.errors';import { defineCustomPropertyType } from '../custom-property-definition.models';@@ -6,7 +6,7 @@ export const userRelationCustomPropertyDefinition = defineCustomPropertyType({typeName: 'user_relation',value: {- inputSchema: z.array(z.string()),+ inputSchema: v.array(v.string()),extendInputValidation: async ({ value: userIds, customProperty, organizationsRepository }) => {const { members } = await organizationsRepository.getOrganizationMembers({ organizationId: customProperty.organizationId });diff --git a/apps/papra-server/src/modules/custom-properties/options/custom-properties-options.schemas.legacy.ts b/apps/papra-server/src/modules/custom-properties/options/custom-properties-options.schemas.legacy.tsdeleted file mode 100644index 1f082957..00000000--- a/apps/papra-server/src/modules/custom-properties/options/custom-properties-options.schemas.legacy.ts+++ /dev/null@@ -1,4 +0,0 @@-import z from 'zod';-import { CUSTOM_PROPERTY_SELECT_OPTION_ID_REGEX } from './custom-properties-options.constants';--export const customPropertySelectOptionIdSchema = z.string().regex(CUSTOM_PROPERTY_SELECT_OPTION_ID_REGEX);diff --git a/apps/papra-server/src/modules/custom-properties/options/custom-properties-options.schemas.ts b/apps/papra-server/src/modules/custom-properties/options/custom-properties-options.schemas.tsnew file mode 100644index 00000000..b663f51f--- /dev/null+++ b/apps/papra-server/src/modules/custom-properties/options/custom-properties-options.schemas.ts@@ -0,0 +1,6 @@+import * as v from 'valibot';+import { createRegexSchema } from '../../shared/schemas/string.schemas';+import { CUSTOM_PROPERTY_SELECT_OPTION_ID_REGEX } from './custom-properties-options.constants';++export const customPropertySelectOptionIdSchema = createRegexSchema(CUSTOM_PROPERTY_SELECT_OPTION_ID_REGEX);+export const selectCustomPropertyOptionNameSchema = v.pipe(v.string(), v.trim(), v.minLength(1), v.maxLength(255));