feat(shared): zod şemaları, Türkçe arama ve TL/tarih biçimleri

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-05 01:35:10 +03:00
parent c875847b65
commit 4dbd2eb441
11 changed files with 504 additions and 3 deletions
+36
View File
@@ -0,0 +1,36 @@
import { z } from "zod";
import { tr } from "../../i18n/tr";
const v = tr.validation;
/** Sistem rolleri (Better Auth admin plugin). */
export const SYSTEM_ROLES = ["admin", "user"] as const;
export const systemRoleSchema = z.enum(SYSTEM_ROLES);
export type SystemRole = z.infer<typeof systemRoleSchema>;
export const USERNAME_PATTERN = /^[a-z0-9._]{3,30}$/;
export const nameSchema = z.string().trim().min(2, v.nameMin).max(80, v.nameMax);
/** Kullanıcı adı küçük harfe çevrilir; Türkçe büyük İ/I sorununu önlemek için tr-TR kullanılır. */
export const usernameSchema = z
.string()
.trim()
.transform((s) => s.toLocaleLowerCase("tr-TR"))
.pipe(z.string().regex(USERNAME_PATTERN, v.usernameFormat));
export const emailSchema = z.string().trim().toLowerCase().pipe(z.email(v.email));
/** Boş bırakılabilen e-posta: "" → undefined. */
export const optionalEmailSchema = z
.string()
.trim()
.transform((s) => (s === "" ? undefined : s.toLowerCase()))
.pipe(z.email(v.email).optional());
export const passwordSchema = z.string().min(8, v.passwordMin).max(128, v.passwordMax);
/** Girilen değer e-posta mı (giriş sırasında e-posta/kullanıcı adı yöntemini seçmek için)? */
export function looksLikeEmail(value: string): boolean {
return value.includes("@");
}