From fb6b0a73b174d7e0e40d77c69f9f6a2f631fba90 Mon Sep 17 00:00:00 2001 From: Colin McDonnell Date: Sun, 17 Jul 2022 21:06:19 -0700 Subject: [PATCH] Fix Deno bundle error --- deno/lib/ZodError.ts | 10 +++++++--- deno/lib/helpers/parseUtil.ts | 4 ++-- deno/lib/types.ts | 6 +++--- package.json | 2 +- src/ZodError.ts | 10 +++++++--- src/helpers/parseUtil.ts | 4 ++-- src/types.ts | 6 +++--- 7 files changed, 25 insertions(+), 17 deletions(-) diff --git a/deno/lib/ZodError.ts b/deno/lib/ZodError.ts index 50d7a1b6c..a30f2767f 100644 --- a/deno/lib/ZodError.ts +++ b/deno/lib/ZodError.ts @@ -413,8 +413,12 @@ export const defaultErrorMap = ( return { message }; }; -export let overrideErrorMap = defaultErrorMap; +let overrideErrorMap = defaultErrorMap; -export const setErrorMap = (map: ZodErrorMap) => { +export function setErrorMap(map: ZodErrorMap) { overrideErrorMap = map; -}; +} + +export function getErrorMap() { + return overrideErrorMap; +} diff --git a/deno/lib/helpers/parseUtil.ts b/deno/lib/helpers/parseUtil.ts index 0da0f46b8..78c8531d7 100644 --- a/deno/lib/helpers/parseUtil.ts +++ b/deno/lib/helpers/parseUtil.ts @@ -1,5 +1,5 @@ import type { IssueData, ZodErrorMap, ZodIssue } from "../ZodError.ts"; -import { defaultErrorMap, overrideErrorMap } from "../ZodError.ts"; +import { defaultErrorMap, getErrorMap } from "../ZodError.ts"; import type { ZodParsedType } from "./util.ts"; export const makeIssue = (params: { @@ -71,7 +71,7 @@ export function addIssueToContext( errorMaps: [ ctx.common.contextualErrorMap, // contextual error map is first priority ctx.schemaErrorMap, // then schema-bound map if available - overrideErrorMap, // then global override map + getErrorMap(), // then global override map defaultErrorMap, // then global default map ].filter((x) => !!x) as ZodErrorMap[], }); diff --git a/deno/lib/types.ts b/deno/lib/types.ts index ac179c295..e51e2b25e 100644 --- a/deno/lib/types.ts +++ b/deno/lib/types.ts @@ -23,8 +23,8 @@ import { Primitive } from "./helpers/typeAliases.ts"; import { getParsedType, util, ZodParsedType } from "./helpers/util.ts"; import { defaultErrorMap, + getErrorMap, IssueData, - overrideErrorMap, StringValidation, ZodCustomIssue, ZodError, @@ -2823,7 +2823,7 @@ export class ZodFunction< errorMaps: [ ctx.common.contextualErrorMap, ctx.schemaErrorMap, - overrideErrorMap, + getErrorMap(), defaultErrorMap, ].filter((x) => !!x) as ZodErrorMap[], issueData: { @@ -2840,7 +2840,7 @@ export class ZodFunction< errorMaps: [ ctx.common.contextualErrorMap, ctx.schemaErrorMap, - overrideErrorMap, + getErrorMap(), defaultErrorMap, ].filter((x) => !!x) as ZodErrorMap[], issueData: { diff --git a/package.json b/package.json index 54b7fc19a..c99a790bd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "zod", - "version": "3.17.5", + "version": "3.17.6", "description": "TypeScript-first schema declaration and validation library with static type inference", "main": "./lib/index.js", "types": "./index.d.ts", diff --git a/src/ZodError.ts b/src/ZodError.ts index ef6259120..4b80d539f 100644 --- a/src/ZodError.ts +++ b/src/ZodError.ts @@ -413,8 +413,12 @@ export const defaultErrorMap = ( return { message }; }; -export let overrideErrorMap = defaultErrorMap; +let overrideErrorMap = defaultErrorMap; -export const setErrorMap = (map: ZodErrorMap) => { +export function setErrorMap(map: ZodErrorMap) { overrideErrorMap = map; -}; +} + +export function getErrorMap() { + return overrideErrorMap; +} diff --git a/src/helpers/parseUtil.ts b/src/helpers/parseUtil.ts index bea90bcf1..7df8c0b02 100644 --- a/src/helpers/parseUtil.ts +++ b/src/helpers/parseUtil.ts @@ -1,5 +1,5 @@ import type { IssueData, ZodErrorMap, ZodIssue } from "../ZodError"; -import { defaultErrorMap, overrideErrorMap } from "../ZodError"; +import { defaultErrorMap, getErrorMap } from "../ZodError"; import type { ZodParsedType } from "./util"; export const makeIssue = (params: { @@ -71,7 +71,7 @@ export function addIssueToContext( errorMaps: [ ctx.common.contextualErrorMap, // contextual error map is first priority ctx.schemaErrorMap, // then schema-bound map if available - overrideErrorMap, // then global override map + getErrorMap(), // then global override map defaultErrorMap, // then global default map ].filter((x) => !!x) as ZodErrorMap[], }); diff --git a/src/types.ts b/src/types.ts index 5d78e224b..4f014884a 100644 --- a/src/types.ts +++ b/src/types.ts @@ -23,8 +23,8 @@ import { Primitive } from "./helpers/typeAliases"; import { getParsedType, util, ZodParsedType } from "./helpers/util"; import { defaultErrorMap, + getErrorMap, IssueData, - overrideErrorMap, StringValidation, ZodCustomIssue, ZodError, @@ -2823,7 +2823,7 @@ export class ZodFunction< errorMaps: [ ctx.common.contextualErrorMap, ctx.schemaErrorMap, - overrideErrorMap, + getErrorMap(), defaultErrorMap, ].filter((x) => !!x) as ZodErrorMap[], issueData: { @@ -2840,7 +2840,7 @@ export class ZodFunction< errorMaps: [ ctx.common.contextualErrorMap, ctx.schemaErrorMap, - overrideErrorMap, + getErrorMap(), defaultErrorMap, ].filter((x) => !!x) as ZodErrorMap[], issueData: {