teqo-backup/src/lib/schemas/primitives.ts
Francisco Ignácio Fontoura Solla 4806c417c8 Engineering Pass 3: consolidate patterns and lock them with guards.
Fold duplicated campanha access, loaders, list/filter/form shells, and scripts into shared modules; reorganize utilities by domain; stabilize e2e; and document prevention-first audit workflow so the same smells cannot creep back in.
2026-07-29 06:11:29 -03:00

43 lines
1.3 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { z } from 'zod'
import { BRAZILIAN_PHONE_INVALID_MESSAGE, normalizeBrazilianPhone } from '@/lib/phone'
export const positiveRelationshipId = z.number().int().positive()
export const trimmedOptionalText = (maximum: number) =>
z
.string()
.trim()
.max(maximum)
.optional()
.transform((value) => (value === '' ? undefined : value))
export const trimmedNullableText = (maximum: number) =>
z
.union([z.string().trim().max(maximum), z.null()])
.optional()
.transform((value) => (value === '' ? null : value))
export const brazilianMobile = z.string().transform((value, context) => {
const phone = normalizeBrazilianPhone(value)
if (phone) return phone
context.addIssue({
code: 'custom',
message: BRAZILIAN_PHONE_INVALID_MESSAGE,
})
return z.NEVER
})
export const optionalPersistedEmail = z
.union([z.email('E-mail inválido.'), z.literal('')])
.optional()
.transform((value) => (value === '' ? undefined : value))
export const nullablePersistedEmail = z
.union([z.email('E-mail inválido.'), z.literal(''), z.null()])
.optional()
.transform((value) => (value === '' ? null : value))
/** Upper bound for any vote count field — one bound, two validation layers (P3-K, was 1_000_000 spelled ×6). */
export const MAX_VOTE_COUNT = 1_000_000