Skip to content

Commit

Permalink
Fix Deno bundle error
Browse files Browse the repository at this point in the history
  • Loading branch information
Colin McDonnell committed Jul 18, 2022
1 parent cbfe704 commit fb6b0a7
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 17 deletions.
10 changes: 7 additions & 3 deletions deno/lib/ZodError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
4 changes: 2 additions & 2 deletions deno/lib/helpers/parseUtil.ts
Original file line number Diff line number Diff line change
@@ -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: {
Expand Down Expand Up @@ -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[],
});
Expand Down
6 changes: 3 additions & 3 deletions deno/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -2823,7 +2823,7 @@ export class ZodFunction<
errorMaps: [
ctx.common.contextualErrorMap,
ctx.schemaErrorMap,
overrideErrorMap,
getErrorMap(),
defaultErrorMap,
].filter((x) => !!x) as ZodErrorMap[],
issueData: {
Expand All @@ -2840,7 +2840,7 @@ export class ZodFunction<
errorMaps: [
ctx.common.contextualErrorMap,
ctx.schemaErrorMap,
overrideErrorMap,
getErrorMap(),
defaultErrorMap,
].filter((x) => !!x) as ZodErrorMap[],
issueData: {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
10 changes: 7 additions & 3 deletions src/ZodError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
4 changes: 2 additions & 2 deletions src/helpers/parseUtil.ts
Original file line number Diff line number Diff line change
@@ -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: {
Expand Down Expand Up @@ -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[],
});
Expand Down
6 changes: 3 additions & 3 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import { Primitive } from "./helpers/typeAliases";
import { getParsedType, util, ZodParsedType } from "./helpers/util";
import {
defaultErrorMap,
getErrorMap,
IssueData,
overrideErrorMap,
StringValidation,
ZodCustomIssue,
ZodError,
Expand Down Expand Up @@ -2823,7 +2823,7 @@ export class ZodFunction<
errorMaps: [
ctx.common.contextualErrorMap,
ctx.schemaErrorMap,
overrideErrorMap,
getErrorMap(),
defaultErrorMap,
].filter((x) => !!x) as ZodErrorMap[],
issueData: {
Expand All @@ -2840,7 +2840,7 @@ export class ZodFunction<
errorMaps: [
ctx.common.contextualErrorMap,
ctx.schemaErrorMap,
overrideErrorMap,
getErrorMap(),
defaultErrorMap,
].filter((x) => !!x) as ZodErrorMap[],
issueData: {
Expand Down

0 comments on commit fb6b0a7

Please sign in to comment.