From c6bb75f230a5d2cae50cc4643bc6c406a9ba6932 Mon Sep 17 00:00:00 2001 From: Arnaud Babol Date: Thu, 18 Jul 2024 03:55:51 +0200 Subject: [PATCH] Add de, es, fr, pt-br, pt-pt locales (#3637) --- packages/zod/src/locales/de.ts | 162 ++++++++++++++++++++++++++++ packages/zod/src/locales/es.ts | 170 +++++++++++++++++++++++++++++ packages/zod/src/locales/fr.ts | 162 ++++++++++++++++++++++++++++ packages/zod/src/locales/pt-br.ts | 174 ++++++++++++++++++++++++++++++ packages/zod/src/locales/pt-pt.ts | 174 ++++++++++++++++++++++++++++++ 5 files changed, 842 insertions(+) create mode 100644 packages/zod/src/locales/de.ts create mode 100644 packages/zod/src/locales/es.ts create mode 100644 packages/zod/src/locales/fr.ts create mode 100644 packages/zod/src/locales/pt-br.ts create mode 100644 packages/zod/src/locales/pt-pt.ts diff --git a/packages/zod/src/locales/de.ts b/packages/zod/src/locales/de.ts new file mode 100644 index 000000000..f19fb3bb0 --- /dev/null +++ b/packages/zod/src/locales/de.ts @@ -0,0 +1,162 @@ +import { type ZodErrorMap, ZodIssueCode } from "../ZodError"; +import { util } from "../helpers"; + +const errorMap: ZodErrorMap = (issue, _ctx) => { + let message: string; + switch (issue.code) { + case ZodIssueCode.invalid_type: + if (issue.received === util.ZodParsedType.undefined) { + message = "Darf nicht leer sein"; + } else { + message = `${issue.expected} erwartet, ${issue.received} erhalten`; + } + break; + case ZodIssueCode.invalid_literal: + message = `Ungültiger Literalwert, ${JSON.stringify( + issue.expected, + util.jsonStringifyReplacer + )} erwartet`; + break; + case ZodIssueCode.unrecognized_keys: + message = `Unbekannte Schlüssel im Objekt: ${util.joinValues( + issue.keys, + ", " + )}`; + break; + case ZodIssueCode.invalid_union: + message = `Ungültige Eingabe`; + break; + case ZodIssueCode.invalid_union_discriminator: + message = `Ungültiger Diskriminatorwert, ${util.joinValues( + issue.options + )} erwartet`; + break; + case ZodIssueCode.invalid_enum_value: + message = `Ungültiger Enum-Wert. ${util.joinValues( + issue.options + )} erwartet, '${issue.received}' erhalten`; + break; + case ZodIssueCode.invalid_arguments: + message = `Ungültige Funktionsargumente`; + break; + case ZodIssueCode.invalid_return_type: + message = `Ungültiger Funktionsrückgabewert`; + break; + case ZodIssueCode.invalid_date: + message = `Ungültiges Datum`; + break; + case ZodIssueCode.invalid_string: + if (typeof issue.validation === "object") { + if ("includes" in issue.validation) { + message = `Ungültige Eingabe: muss "${issue.validation.includes}" enthalten`; + if (typeof issue.validation.position === "number") { + message = `${message} an einer oder mehreren Positionen größer oder gleich ${issue.validation.position}`; + } + } else if ("startsWith" in issue.validation) { + message = `Ungültige Eingabe: muss mit "${issue.validation.startsWith}" beginnen`; + } else if ("endsWith" in issue.validation) { + message = `Ungültige Eingabe: muss mit "${issue.validation.endsWith}" enden`; + } else { + util.assertNever(issue.validation); + } + } else if (issue.validation !== "regex") { + message = `Ungültige ${issue.validation}`; + } else { + message = "Ungültig"; + } + break; + case ZodIssueCode.too_small: + if (issue.type === "array") + message = `Array muss ${ + issue.exact ? "genau" : issue.inclusive ? `mindestens` : `mehr als` + } ${issue.minimum} Element(e) enthalten`; + else if (issue.type === "string") + message = `String muss ${ + issue.exact ? "genau" : issue.inclusive ? `mindestens` : `mehr als` + } ${issue.minimum} Zeichen enthalten`; + else if (issue.type === "number") + message = `Zahl muss ${ + issue.exact + ? `genau` + : issue.inclusive + ? `größer oder gleich` + : `größer als` + } ${issue.minimum} sein`; + else if (issue.type === "date") + message = `Datum muss ${ + issue.exact + ? `genau` + : issue.inclusive + ? `größer oder gleich` + : `größer als` + } ${new Date(Number(issue.minimum))} sein`; + else message = "Ungültige Eingabe"; + break; + case ZodIssueCode.too_big: + if (issue.type === "array") + message = `Array muss ${ + issue.exact ? `genau` : issue.inclusive ? `höchstens` : `weniger als` + } ${issue.maximum} Element(e) enthalten`; + else if (issue.type === "string") + message = `String muss ${ + issue.exact ? `genau` : issue.inclusive ? `höchstens` : `weniger als` + } ${issue.maximum} Zeichen enthalten`; + else if (issue.type === "number") + message = `Zahl muss ${ + issue.exact + ? `genau` + : issue.inclusive + ? `kleiner oder gleich` + : `kleiner als` + } ${issue.maximum} sein`; + else if (issue.type === "bigint") + message = `Bigint muss ${ + issue.exact + ? `genau` + : issue.inclusive + ? `kleiner oder gleich` + : `kleiner als` + } ${issue.maximum} sein`; + else if (issue.type === "date") + message = `Datum muss ${ + issue.exact + ? `genau` + : issue.inclusive + ? `kleiner oder gleich` + : `kleiner als` + } ${new Date(Number(issue.maximum))} sein`; + else message = "Ungültige Eingabe"; + break; + case ZodIssueCode.custom: + message = `Ungültige Eingabe`; + break; + case ZodIssueCode.invalid_intersection_types: + message = `Schnittmengenergebnisse konnten nicht zusammengeführt werden`; + break; + case ZodIssueCode.not_multiple_of: + message = `Zahl muss ein Vielfaches von ${issue.multipleOf} sein`; + break; + case ZodIssueCode.not_finite: + message = "Zahl muss endlich sein"; + break; + case ZodIssueCode.uniqueness: + message = issue.duplicateElements?.length + ? `Element(e): '${issue.duplicateElements}' nicht eindeutig` + : "Werte müssen eindeutig sein"; + break; + case ZodIssueCode.invalid_file_type: + message = `Ungültiger Dateityp. ${util.joinValues( + issue.expected + )} erwartet, '${issue.received}' erhalten`; + break; + case ZodIssueCode.invalid_file_name: + message = `Ungültiger Dateiname`; + break; + default: + message = _ctx.defaultError; + util.assertNever(issue); + } + return { message }; +}; + +export default errorMap; diff --git a/packages/zod/src/locales/es.ts b/packages/zod/src/locales/es.ts new file mode 100644 index 000000000..b00e3f62d --- /dev/null +++ b/packages/zod/src/locales/es.ts @@ -0,0 +1,170 @@ +import { type ZodErrorMap, ZodIssueCode } from "../ZodError"; +import { util } from "../helpers"; + +const errorMap: ZodErrorMap = (issue, _ctx) => { + let message: string; + switch (issue.code) { + case ZodIssueCode.invalid_type: + if (issue.received === util.ZodParsedType.undefined) { + message = "Requerido"; + } else { + message = `Se esperaba ${issue.expected}, se recibió ${issue.received}`; + } + break; + case ZodIssueCode.invalid_literal: + message = `Valor literal inválido, se esperaba ${JSON.stringify( + issue.expected, + util.jsonStringifyReplacer + )}`; + break; + case ZodIssueCode.unrecognized_keys: + message = `Llave(s) no reconocida(s) en el objeto: ${util.joinValues( + issue.keys, + ", " + )}`; + break; + case ZodIssueCode.invalid_union: + message = `Entrada inválida`; + break; + case ZodIssueCode.invalid_union_discriminator: + message = `Valor discriminador inválido. Se esperaba ${util.joinValues( + issue.options + )}`; + break; + case ZodIssueCode.invalid_enum_value: + message = `Valor inválido. Se esperaba ${util.joinValues( + issue.options + )}, se recibió '${issue.received}'`; + break; + case ZodIssueCode.invalid_arguments: + message = `Argumentos de función inválidos`; + break; + case ZodIssueCode.invalid_return_type: + message = `Tipo de retorno de función inválido`; + break; + case ZodIssueCode.invalid_date: + message = `Fecha inválida`; + break; + case ZodIssueCode.invalid_string: + if (typeof issue.validation === "object") { + if ("includes" in issue.validation) { + message = `Entrada inválida: debe incluir "${issue.validation.includes}"`; + if (typeof issue.validation.position === "number") { + message = `${message} en una o más posiciones mayores o iguales a ${issue.validation.position}`; + } + } else if ("startsWith" in issue.validation) { + message = `Entrada inválida: debe comenzar con "${issue.validation.startsWith}"`; + } else if ("endsWith" in issue.validation) { + message = `Entrada inválida: debe finalizar con "${issue.validation.endsWith}"`; + } else { + util.assertNever(issue.validation); + } + } else if (issue.validation !== "regex") { + message = `${issue.validation} inválido`; + } else { + message = "Inválido"; + } + break; + case ZodIssueCode.too_small: + if (issue.type === "array") + message = `La lista debe contener ${ + issue.exact ? "exactamente" : issue.inclusive ? `al menos` : `más de` + } ${issue.minimum} elemento(s)`; + else if (issue.type === "string") + message = `El texto debe contener ${ + issue.exact ? "exactamente" : issue.inclusive ? `al menos` : `más de` + } ${issue.minimum} carácter(es)`; + else if (issue.type === "number") + message = `El número debe ser ${ + issue.exact + ? `exactamente` + : issue.inclusive + ? `mayor o igual a` + : `mayor que` + } ${issue.minimum}`; + else if (issue.type === "date") + message = `La fecha debe ser ${ + issue.exact + ? `exactamente` + : issue.inclusive + ? `mayor o igual al` + : `mayor que el` + } ${new Date(Number(issue.minimum))}`; + else message = "Entrada inválida"; + break; + case ZodIssueCode.too_big: + if (issue.type === "array") + message = `La lista debe contener ${ + issue.exact + ? `exactamente` + : issue.inclusive + ? `como máximo` + : `menos que` + } ${issue.maximum} elemento(s)`; + else if (issue.type === "string") + message = `El texto debe contener ${ + issue.exact + ? `exactamente` + : issue.inclusive + ? `como máximo` + : `menos de` + } ${issue.maximum} carácter(es)`; + else if (issue.type === "number") + message = `El número debe ser ${ + issue.exact + ? `exactamente` + : issue.inclusive + ? `menor o igual a` + : `menor que` + } ${issue.maximum}`; + else if (issue.type === "bigint") + message = `El entero grande debe ser ${ + issue.exact + ? `exactamente` + : issue.inclusive + ? `menor o igual a` + : `menor que` + } ${issue.maximum}`; + else if (issue.type === "date") + message = `La fecha debe ser ${ + issue.exact + ? `exactamente` + : issue.inclusive + ? `menor o igual al` + : `menor que el` + } ${new Date(Number(issue.maximum))}`; + else message = "Entrada inválida"; + break; + case ZodIssueCode.custom: + message = `Entrada inválida`; + break; + case ZodIssueCode.invalid_intersection_types: + message = `Valores de intersección no pudieron ser mezclados`; + break; + case ZodIssueCode.not_multiple_of: + message = `Número debe ser múltiplo de ${issue.multipleOf}`; + break; + case ZodIssueCode.not_finite: + message = "Número no puede ser infinito"; + break; + case ZodIssueCode.uniqueness: + message = issue.duplicateElements?.length + ? `Elemento(s): '${issue.duplicateElements}' no son únicos` + : "Los valores deben ser únicos"; + break; + case ZodIssueCode.invalid_file_type: + message = `Tipo de archivo inválido. Se esperaba ${util.joinValues( + issue.expected + )}, se recibió '${issue.received}'`; + break; + case ZodIssueCode.invalid_file_name: + message = `Nombre de archivo inválido`; + break; + default: + message = _ctx.defaultError; + util.assertNever(issue); + } + return { message }; +}; + +export default errorMap; diff --git a/packages/zod/src/locales/fr.ts b/packages/zod/src/locales/fr.ts new file mode 100644 index 000000000..fe5de5d95 --- /dev/null +++ b/packages/zod/src/locales/fr.ts @@ -0,0 +1,162 @@ +import { type ZodErrorMap, ZodIssueCode } from "../ZodError"; +import { util } from "../helpers"; + +const errorMap: ZodErrorMap = (issue, _ctx) => { + let message: string; + switch (issue.code) { + case ZodIssueCode.invalid_type: + if (issue.received === util.ZodParsedType.undefined) { + message = "Obligatoire"; + } else { + message = `Le type « ${issue.expected} » est attendu mais « ${issue.received} » a été reçu`; + } + break; + case ZodIssueCode.invalid_literal: + message = `La valeur doit être ${JSON.stringify( + issue.expected, + util.jsonStringifyReplacer + )}`; + break; + case ZodIssueCode.unrecognized_keys: + message = `Une ou plusieurs clé(s) non reconnue(s) dans l'objet : ${util.joinValues( + issue.keys, + ", " + )}`; + break; + case ZodIssueCode.invalid_union: + message = `Champ non valide`; + break; + case ZodIssueCode.invalid_union_discriminator: + message = `La valeur du discriminateur est non valide. Options attendues : ${util.joinValues( + issue.options + )}`; + break; + case ZodIssueCode.invalid_enum_value: + message = `La valeur « ${ + issue.received + } » n'existe pas dans les options : ${util.joinValues(issue.options)}`; + break; + case ZodIssueCode.invalid_arguments: + message = `Les arguments de la fonction sont non valides`; + break; + case ZodIssueCode.invalid_return_type: + message = `Le type de retour de la fonction n'est pas valide`; + break; + case ZodIssueCode.invalid_date: + message = `La date est non valide`; + break; + case ZodIssueCode.invalid_string: + if (typeof issue.validation === "object") { + if ("includes" in issue.validation) { + message = `Champ non valide : doit inclure « ${issue.validation.includes} »`; + if (typeof issue.validation.position === "number") { + message = `${message} à une ou plusieurs positions supérieures ou égales à ${issue.validation.position}`; + } + } else if ("startsWith" in issue.validation) { + message = `Le champ doit commencer par « ${issue.validation.startsWith} »`; + } else if ("endsWith" in issue.validation) { + message = `Le champ doit se terminer par « ${issue.validation.endsWith} »`; + } else { + util.assertNever(issue.validation); + } + } else if (issue.validation !== "regex") { + message = `${issue.validation} non valide`; + } else { + message = "Champ non valide"; + } + break; + case ZodIssueCode.too_small: + if (issue.type === "array") + message = `La liste doit contenir ${ + issue.exact ? "exactement" : issue.inclusive ? `au moins` : `plus de` + } ${issue.minimum} élément(s)`; + else if (issue.type === "string") + message = `Le texte doit contenir ${ + issue.exact ? "exactement" : issue.inclusive ? `au moins` : `plus de` + } ${issue.minimum} caractère(s)`; + else if (issue.type === "number") + message = `Le nombre doit être ${ + issue.exact + ? `égal à ` + : issue.inclusive + ? `supérieur ou égal à ` + : `supérieur à ` + }${issue.minimum}`; + else if (issue.type === "date") + message = `La date doit être ${ + issue.exact + ? `égale au ` + : issue.inclusive + ? `ultérieure ou égale au ` + : `ultérieure au ` + }${new Date(Number(issue.minimum))}`; + else message = "Champ non valide"; + break; + case ZodIssueCode.too_big: + if (issue.type === "array") + message = `La liste doit contenir ${ + issue.exact ? `exactement` : issue.inclusive ? `au plus` : `moins de` + } ${issue.maximum} élément(s)`; + else if (issue.type === "string") + message = `Le texte doit contenir ${ + issue.exact ? `exactement` : issue.inclusive ? `au plus` : `moins de` + } ${issue.maximum} caractère(s)`; + else if (issue.type === "number") + message = `Le nombre doit être ${ + issue.exact + ? `égal à` + : issue.inclusive + ? `inférieur ou égal à` + : `inférieur à` + } ${issue.maximum}`; + else if (issue.type === "bigint") + message = `Le grand entier doit être ${ + issue.exact + ? `exactement` + : issue.inclusive + ? `inférieur ou égal à` + : `inférieur à` + } ${issue.maximum}`; + else if (issue.type === "date") + message = `La date doit être ${ + issue.exact + ? `égale au` + : issue.inclusive + ? `antérieure ou égale au` + : `antérieure au` + } ${new Date(Number(issue.maximum))}`; + else message = "Champ non valide"; + break; + case ZodIssueCode.custom: + message = `Champ non valide`; + break; + case ZodIssueCode.invalid_intersection_types: + message = `Les résultats d'intersection n'ont pas pu être fusionnés`; + break; + case ZodIssueCode.not_multiple_of: + message = `Le nombre doit être un multiple de ${issue.multipleOf}`; + break; + case ZodIssueCode.not_finite: + message = "Le nombre doit être fini"; + break; + case ZodIssueCode.uniqueness: + message = issue.duplicateElements?.length + ? `Élément(s) : '${issue.duplicateElements}' non unique(s)` + : "Les valeurs doivent être uniques"; + break; + case ZodIssueCode.invalid_file_type: + message = `Type de fichier non valide. ${util.joinValues( + issue.expected + )} attendu, '${issue.received}' reçu`; + break; + case ZodIssueCode.invalid_file_name: + message = `Nom de fichier non valide`; + break; + default: + message = _ctx.defaultError; + util.assertNever(issue); + } + return { message }; +}; + +export default errorMap; diff --git a/packages/zod/src/locales/pt-br.ts b/packages/zod/src/locales/pt-br.ts new file mode 100644 index 000000000..fe3b41875 --- /dev/null +++ b/packages/zod/src/locales/pt-br.ts @@ -0,0 +1,174 @@ +import { type ZodErrorMap, ZodIssueCode } from "../ZodError"; +import { util } from "../helpers"; + +const errorMap: ZodErrorMap = (issue, _ctx) => { + let message: string; + switch (issue.code) { + case ZodIssueCode.invalid_type: + if (issue.received === util.ZodParsedType.undefined) { + message = "Obrigatório"; + } else { + message = `O dado deve ser do tipo ${issue.expected}, porém foi enviado ${issue.received}`; + } + break; + case ZodIssueCode.invalid_literal: + message = `Valor literal inválido, era esperado ${JSON.stringify( + issue.expected, + util.jsonStringifyReplacer + )}`; + break; + case ZodIssueCode.unrecognized_keys: + message = `Chave(s) não reconhecida(s) no objeto: ${util.joinValues( + issue.keys, + ", " + )}`; + break; + case ZodIssueCode.invalid_union: + message = `Entrada inválida`; + break; + case ZodIssueCode.invalid_union_discriminator: + message = `Valor discriminador inválido. Foi esperado ${util.joinValues( + issue.options + )}`; + break; + case ZodIssueCode.invalid_enum_value: + message = `Enum no formato inválido. Foi esperado ${util.joinValues( + issue.options + )}, porém foi recebido '${issue.received}'`; + break; + case ZodIssueCode.invalid_arguments: + message = `Argumento de função inválido`; + break; + case ZodIssueCode.invalid_return_type: + message = `Tipo de retorno de função inválido`; + break; + case ZodIssueCode.invalid_date: + message = `Data inválida`; + break; + case ZodIssueCode.invalid_string: + if (typeof issue.validation === "object") { + if ("includes" in issue.validation) { + message = `Entrada inválida: deve incluir "${issue.validation.includes}"`; + if (typeof issue.validation.position === "number") { + message = `${message} em uma ou mais posições maiores ou iguais a ${issue.validation.position}`; + } + } else if ("startsWith" in issue.validation) { + message = `Entrada inválida: deve iniciar com "${issue.validation.startsWith}"`; + } else if ("endsWith" in issue.validation) { + message = `Entrada inválida: deve terminar com "${issue.validation.endsWith}"`; + } else { + util.assertNever(issue.validation); + } + } else if (issue.validation !== "regex") { + message = `${issue.validation} inválido`; + } else { + message = "Combinação inválida"; + } + break; + case ZodIssueCode.too_small: + if (issue.type === "array") + message = `Lista deve conter ${ + issue.exact ? "exatamente" : issue.inclusive ? `no mínimo` : `mais de` + } ${issue.minimum} elemento(s)`; + else if (issue.type === "string") + message = `Texto deve conter ${ + issue.exact + ? "exatamente" + : issue.inclusive + ? `pelo menos` + : `mais de` + } ${issue.minimum} caracter(es)`; + else if (issue.type === "number") + message = `Número deve ser ${ + issue.exact + ? `exatamente igual a` + : issue.inclusive + ? `maior ou igual a` + : `maior que` + } ${issue.minimum}`; + else if (issue.type === "date") + message = `Data deve ser ${ + issue.exact + ? `exatamente` + : issue.inclusive + ? `maior ou igual a` + : `maior que` + } ${new Date(Number(issue.minimum))}`; + else message = "Entrada inválida"; + break; + case ZodIssueCode.too_big: + if (issue.type === "array") + message = `Lista deve conter ${ + issue.exact + ? `exatamente` + : issue.inclusive + ? `no máximo` + : `menos de` + } ${issue.maximum} elemento(s)`; + else if (issue.type === "string") + message = `Texto deve conter ${ + issue.exact + ? `exatamente` + : issue.inclusive + ? `no máximo` + : `menos que` + } ${issue.maximum} caracter(es)`; + else if (issue.type === "number") + message = `Número deve ser ${ + issue.exact + ? `exatamente igual a` + : issue.inclusive + ? `menor ou igual a` + : `menor que` + } ${issue.maximum}`; + else if (issue.type === "bigint") + message = `BigInt deve ser ${ + issue.exact + ? `exatamente igual a` + : issue.inclusive + ? `menor ou igual a` + : `menor que` + } ${issue.maximum}`; + else if (issue.type === "date") + message = `Data deve ser ${ + issue.exact + ? `exatamente` + : issue.inclusive + ? `menor ou igual a` + : `menor que` + } ${new Date(Number(issue.maximum))}`; + else message = "Entrada inválida"; + break; + case ZodIssueCode.custom: + message = `Entrada inválida`; + break; + case ZodIssueCode.invalid_intersection_types: + message = `Valores de interseção não puderam ser mesclados`; + break; + case ZodIssueCode.not_multiple_of: + message = `O número deverá ser múltiplo de ${issue.multipleOf}`; + break; + case ZodIssueCode.not_finite: + message = "Número não pode ser infinito"; + break; + case ZodIssueCode.uniqueness: + message = issue.duplicateElements?.length + ? `Elemento(s): '${issue.duplicateElements}' não são únicos` + : "Os valores devem ser únicos"; + break; + case ZodIssueCode.invalid_file_type: + message = `Tipo de arquivo inválido. Era esperado ${util.joinValues( + issue.expected + )}, porém foi recebido '${issue.received}'`; + break; + case ZodIssueCode.invalid_file_name: + message = `Nome de arquivo inválido`; + break; + default: + message = _ctx.defaultError; + util.assertNever(issue); + } + return { message }; +}; + +export default errorMap; diff --git a/packages/zod/src/locales/pt-pt.ts b/packages/zod/src/locales/pt-pt.ts new file mode 100644 index 000000000..aa1f75722 --- /dev/null +++ b/packages/zod/src/locales/pt-pt.ts @@ -0,0 +1,174 @@ +import { type ZodErrorMap, ZodIssueCode } from "../ZodError"; +import { util } from "../helpers"; + +const errorMap: ZodErrorMap = (issue, _ctx) => { + let message: string; + switch (issue.code) { + case ZodIssueCode.invalid_type: + if (issue.received === util.ZodParsedType.undefined) { + message = "Obrigatório"; + } else { + message = `O dado deve ser do tipo ${issue.expected}, mas foi enviado ${issue.received}`; + } + break; + case ZodIssueCode.invalid_literal: + message = `Valor literal inválido, era esperado ${JSON.stringify( + issue.expected, + util.jsonStringifyReplacer + )}`; + break; + case ZodIssueCode.unrecognized_keys: + message = `Chave(s) não reconhecida(s) no objeto: ${util.joinValues( + issue.keys, + ", " + )}`; + break; + case ZodIssueCode.invalid_union: + message = `Entrada inválida`; + break; + case ZodIssueCode.invalid_union_discriminator: + message = `Valor discriminador inválido. Era esperado ${util.joinValues( + issue.options + )}`; + break; + case ZodIssueCode.invalid_enum_value: + message = `Enum no formato inválido. Era esperado ${util.joinValues( + issue.options + )}, mas foi recebido '${issue.received}'`; + break; + case ZodIssueCode.invalid_arguments: + message = `Argumento de função inválido`; + break; + case ZodIssueCode.invalid_return_type: + message = `Tipo de retorno de função inválido`; + break; + case ZodIssueCode.invalid_date: + message = `Data inválida`; + break; + case ZodIssueCode.invalid_string: + if (typeof issue.validation === "object") { + if ("includes" in issue.validation) { + message = `Entrada inválida: deve incluir "${issue.validation.includes}"`; + if (typeof issue.validation.position === "number") { + message = `${message} numa ou mais posições maiores ou iguais a ${issue.validation.position}`; + } + } else if ("startsWith" in issue.validation) { + message = `Entrada inválida: deve começar com "${issue.validation.startsWith}"`; + } else if ("endsWith" in issue.validation) { + message = `Entrada inválida: deve terminar com "${issue.validation.endsWith}"`; + } else { + util.assertNever(issue.validation); + } + } else if (issue.validation !== "regex") { + message = `${issue.validation} inválido`; + } else { + message = "Combinação inválida"; + } + break; + case ZodIssueCode.too_small: + if (issue.type === "array") + message = `Lista deve conter ${ + issue.exact ? "exatamente" : issue.inclusive ? `no mínimo` : `mais de` + } ${issue.minimum} elemento(s)`; + else if (issue.type === "string") + message = `Texto deve conter ${ + issue.exact + ? "exatamente" + : issue.inclusive + ? `pelo menos` + : `mais de` + } ${issue.minimum} carácter(es)`; + else if (issue.type === "number") + message = `Número deve ser ${ + issue.exact + ? `exatamente igual a` + : issue.inclusive + ? `maior ou igual a` + : `maior que` + } ${issue.minimum}`; + else if (issue.type === "date") + message = `Data deve ser ${ + issue.exact + ? `exatamente` + : issue.inclusive + ? `maior ou igual a` + : `maior que` + } ${new Date(Number(issue.minimum))}`; + else message = "Entrada inválida"; + break; + case ZodIssueCode.too_big: + if (issue.type === "array") + message = `Lista deve conter ${ + issue.exact + ? `exatamente` + : issue.inclusive + ? `no máximo` + : `menos de` + } ${issue.maximum} elemento(s)`; + else if (issue.type === "string") + message = `Texto deve conter ${ + issue.exact + ? `exatamente` + : issue.inclusive + ? `no máximo` + : `menos que` + } ${issue.maximum} carácter(es)`; + else if (issue.type === "number") + message = `Número deve ser ${ + issue.exact + ? `exatamente igual a` + : issue.inclusive + ? `menor ou igual a` + : `menor que` + } ${issue.maximum}`; + else if (issue.type === "bigint") + message = `BigInt deve ser ${ + issue.exact + ? `exatamente igual a` + : issue.inclusive + ? `menor ou igual a` + : `menor que` + } ${issue.maximum}`; + else if (issue.type === "date") + message = `Data deve ser ${ + issue.exact + ? `exatamente` + : issue.inclusive + ? `menor ou igual a` + : `menor que` + } ${new Date(Number(issue.maximum))}`; + else message = "Entrada inválida"; + break; + case ZodIssueCode.custom: + message = `Entrada inválida`; + break; + case ZodIssueCode.invalid_intersection_types: + message = `Valores de interseção não puderam ser combinados`; + break; + case ZodIssueCode.not_multiple_of: + message = `O número deverá ser múltiplo de ${issue.multipleOf}`; + break; + case ZodIssueCode.not_finite: + message = "Número não pode ser infinito"; + break; + case ZodIssueCode.uniqueness: + message = issue.duplicateElements?.length + ? `Elemento(s): '${issue.duplicateElements}' não são únicos` + : "Os valores devem ser únicos"; + break; + case ZodIssueCode.invalid_file_type: + message = `Tipo de ficheiro inválido. Era esperado ${util.joinValues( + issue.expected + )}, mas foi recebido '${issue.received}'`; + break; + case ZodIssueCode.invalid_file_name: + message = `Nome de ficheiro inválido`; + break; + default: + message = _ctx.defaultError; + util.assertNever(issue); + } + return { message }; +}; + +export default errorMap;