import type { Refinement } from "effect-app/Function" import { isValidEmail } from "effect-app/validation" import * as S from "effect/Schema" import type { Simplify } from "effect/Types" import type { B } from "./schema.js" import type { NonEmptyStringBrand } from "./strings.js" export interface EmailBrand extends Simplify> {} export type Email = string & EmailBrand export const Email = S .String .pipe( S.annotate({ title: "Email", description: "an email according to RFC 5322", format: "email" }), S.check(S.isMinLength(3), /* a@b */ S.isMaxLength(998)), S.refine(isValidEmail as Refinement, { identifier: "Email", description: "an email according to RFC 5322", jsonSchema: { format: "email", minLength: 3, maxLength: 998 } }), S.annotate({ toArbitrary: () => (fc) => fc.emailAddress().map((_) => _ as Email) }) )