-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: tree shake named exports (#2850)
* fix: tree shake named exports * docs: explain why wrapper functions * fix: make coerce tree shakeable * fix: make util tree shakeable * Fix merge conflicts --------- Co-authored-by: Colin McDonnell <[email protected]>
- Loading branch information
1 parent
35b25b9
commit dc6365c
Showing
83 changed files
with
890 additions
and
866 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
import { expect } from "https://deno.land/x/[email protected]/mod.ts"; | ||
const test = Deno.test; | ||
|
||
import { util } from "../helpers/util.ts"; | ||
import { util } from "../helpers/index.ts"; | ||
import * as z from "../index.ts"; | ||
|
||
const Test = z.object({ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
import { expect } from "https://deno.land/x/[email protected]/mod.ts"; | ||
const test = Deno.test; | ||
|
||
import { util } from "../helpers/util.ts"; | ||
import { util } from "../helpers/index.ts"; | ||
import * as z from "../index.ts"; | ||
|
||
test("check any inference", () => { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
import { expect } from "https://deno.land/x/[email protected]/mod.ts"; | ||
const test = Deno.test; | ||
|
||
import { util } from "../helpers/util.ts"; | ||
import { util } from "../helpers/index.ts"; | ||
import * as z from "../index.ts"; | ||
|
||
const minTwo = z.string().array().min(2); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
import { expect } from "https://deno.land/x/[email protected]/mod.ts"; | ||
const test = Deno.test; | ||
|
||
import { util } from "../helpers/util.ts"; | ||
import { util } from "../helpers/index.ts"; | ||
import * as z from "../index.ts"; | ||
|
||
test("type guard", () => { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
import { expect } from "https://deno.land/x/[email protected]/mod.ts"; | ||
const test = Deno.test; | ||
|
||
import { util } from "../helpers/util.ts"; | ||
import { util } from "../helpers/index.ts"; | ||
import * as z from "../index.ts"; | ||
|
||
test("branded types", () => { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ import { expect } from "https://deno.land/x/[email protected]/mod.ts"; | |
const test = Deno.test; | ||
|
||
import { z } from "../index.ts"; | ||
import { util } from "../helpers/util.ts"; | ||
import { util } from "../helpers/index.ts"; | ||
|
||
test("basic catch", () => { | ||
expect(z.string().catch("default").parse(undefined)).toBe("default"); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ import { expect } from "https://deno.land/x/[email protected]/mod.ts"; | |
const test = Deno.test; | ||
|
||
import { z } from "../index.ts"; | ||
import { util } from "../helpers/util.ts"; | ||
import { util } from "../helpers/index.ts"; | ||
|
||
test("basic defaults", () => { | ||
expect(z.string().default("default").parse(undefined)).toBe("default"); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
import { expect } from "https://deno.land/x/[email protected]/mod.ts"; | ||
const test = Deno.test; | ||
|
||
import { util } from "../helpers/util.ts"; | ||
import { util } from "../helpers/index.ts"; | ||
import * as z from "../index.ts"; | ||
|
||
test("create enum", () => { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,16 +2,15 @@ | |
import { expect } from "https://deno.land/x/[email protected]/mod.ts"; | ||
const test = Deno.test; | ||
|
||
import { ZodParsedType } from "../helpers/util.ts"; | ||
import * as z from "../index.ts"; | ||
import { ZodError, ZodIssueCode } from "../ZodError.ts"; | ||
|
||
test("error creation", () => { | ||
const err1 = ZodError.create([]); | ||
err1.addIssue({ | ||
code: ZodIssueCode.invalid_type, | ||
expected: ZodParsedType.object, | ||
received: ZodParsedType.string, | ||
expected: z.ZodParsedType.object, | ||
received: z.ZodParsedType.string, | ||
path: [], | ||
message: "", | ||
fatal: true, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
import { expect } from "https://deno.land/x/[email protected]/mod.ts"; | ||
const test = Deno.test; | ||
|
||
import { util } from "../helpers/util.ts"; | ||
import { util } from "../helpers/index.ts"; | ||
import * as z from "../index.ts"; | ||
|
||
test("first party switch", () => { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ import { expect } from "https://deno.land/x/[email protected]/mod.ts"; | |
const test = Deno.test; | ||
|
||
import { ZodFirstPartySchemaTypes, ZodFirstPartyTypeKind } from "../index.ts"; | ||
import { util } from "../helpers/util.ts"; | ||
import { util } from "../helpers/index.ts"; | ||
|
||
test("Identify missing [ZodFirstPartySchemaTypes]", () => { | ||
type ZodFirstPartySchemaForType<T extends ZodFirstPartyTypeKind> = | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
import { expect } from "https://deno.land/x/[email protected]/mod.ts"; | ||
const test = Deno.test; | ||
|
||
import { util } from "../helpers/util.ts"; | ||
import { util } from "../helpers/index.ts"; | ||
import * as z from "../index.ts"; | ||
|
||
const args1 = z.tuple([z.string()]); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
import { expect } from "https://deno.land/x/[email protected]/mod.ts"; | ||
const test = Deno.test; | ||
|
||
import { util } from "../helpers/util.ts"; | ||
import { util } from "../helpers/index.ts"; | ||
import * as z from "../index.ts"; | ||
|
||
test("generics", () => { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
import { expect } from "https://deno.land/x/[email protected]/mod.ts"; | ||
const test = Deno.test; | ||
|
||
import { util } from "../helpers/util.ts"; | ||
import { util } from "../helpers/index.ts"; | ||
import * as z from "../index.ts"; | ||
|
||
test("instanceof", async () => { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
import { expect } from "https://deno.land/x/[email protected]/mod.ts"; | ||
const test = Deno.test; | ||
|
||
import { util } from "../helpers/util.ts"; | ||
import { util } from "../helpers/index.ts"; | ||
import * as z from "../index.ts"; | ||
import { ZodIssueCode } from "../index.ts"; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
import { expect } from "https://deno.land/x/[email protected]/mod.ts"; | ||
const test = Deno.test; | ||
|
||
import { util } from "../helpers/util.ts"; | ||
import { util } from "../helpers/index.ts"; | ||
import * as z from "../index.ts"; | ||
|
||
test("nativeEnum test with consts", () => { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
import { expect } from "https://deno.land/x/[email protected]/mod.ts"; | ||
const test = Deno.test; | ||
|
||
import { util } from "../helpers/util.ts"; | ||
import { util } from "../helpers/index.ts"; | ||
import * as z from "../index.ts"; | ||
|
||
const Test = z.object({ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
import { expect } from "https://deno.land/x/[email protected]/mod.ts"; | ||
const test = Deno.test; | ||
|
||
import { util } from "../helpers/util.ts"; | ||
import { util } from "../helpers/index.ts"; | ||
import * as z from "../index.ts"; | ||
import { ZodNullable, ZodOptional } from "../index.ts"; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
import { expect } from "https://deno.land/x/[email protected]/mod.ts"; | ||
const test = Deno.test; | ||
|
||
import { util } from "../helpers/util.ts"; | ||
import { util } from "../helpers/index.ts"; | ||
import * as z from "../index.ts"; | ||
|
||
const fish = z.object({ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
import { expect } from "https://deno.land/x/[email protected]/mod.ts"; | ||
const test = Deno.test; | ||
|
||
import { util } from "../helpers/util.ts"; | ||
import { util } from "../helpers/index.ts"; | ||
import * as z from "../index.ts"; | ||
|
||
test("preprocess", () => { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
import { expect } from "https://deno.land/x/[email protected]/mod.ts"; | ||
const test = Deno.test; | ||
|
||
import { util } from "../helpers/util.ts"; | ||
import { util } from "../helpers/index.ts"; | ||
import * as z from "../index.ts"; | ||
import { Mocker } from "./Mocker.ts"; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
import { expect } from "https://deno.land/x/[email protected]/mod.ts"; | ||
const test = Deno.test; | ||
|
||
import { util } from "../helpers/util.ts"; | ||
import { util } from "../helpers/index.ts"; | ||
import * as z from "../index.ts"; | ||
|
||
const promSchema = z.promise( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
import { expect } from "https://deno.land/x/[email protected]/mod.ts"; | ||
const test = Deno.test; | ||
|
||
import { util } from "../helpers/util.ts"; | ||
import { util } from "../helpers/index.ts"; | ||
import * as z from "../index.ts"; | ||
|
||
enum testEnum { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
import { expect } from "https://deno.land/x/[email protected]/mod.ts"; | ||
const test = Deno.test; | ||
|
||
import { util } from "../helpers/util.ts"; | ||
import { util } from "../helpers/index.ts"; | ||
import * as z from "../index.ts"; | ||
|
||
const booleanRecord = z.record(z.boolean()); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
import { expect } from "https://deno.land/x/[email protected]/mod.ts"; | ||
const test = Deno.test; | ||
|
||
import { util } from "../helpers/util.ts"; | ||
import { util } from "../helpers/index.ts"; | ||
import * as z from "../index.ts"; | ||
import { ZodIssueCode } from "../ZodError.ts"; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
import { expect } from "https://deno.land/x/[email protected]/mod.ts"; | ||
const test = Deno.test; | ||
|
||
import { util } from "../helpers/util.ts"; | ||
import { util } from "../helpers/index.ts"; | ||
import * as z from "../index.ts"; | ||
import { ZodIssueCode } from "../index.ts"; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
import { expect } from "https://deno.land/x/[email protected]/mod.ts"; | ||
const test = Deno.test; | ||
|
||
import { util } from "../helpers/util.ts"; | ||
import { util } from "../helpers/index.ts"; | ||
import * as z from "../index.ts"; | ||
|
||
const stringToNumber = z.string().transform((arg) => parseFloat(arg)); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
import { expect } from "https://deno.land/x/[email protected]/mod.ts"; | ||
const test = Deno.test; | ||
|
||
import { util } from "../helpers/util.ts"; | ||
import { util } from "../helpers/index.ts"; | ||
import * as z from "../index.ts"; | ||
import { ZodError } from "../ZodError.ts"; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
import { expect } from "https://deno.land/x/[email protected]/mod.ts"; | ||
const test = Deno.test; | ||
|
||
import { util } from "../helpers/util.ts"; | ||
import { util } from "../helpers/index.ts"; | ||
import * as z from "../index.ts"; | ||
test("void", () => { | ||
const v = z.void(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { ZodBigInt, ZodBoolean, ZodDate, ZodNumber, ZodString } from "./types.ts"; | ||
|
||
const coerceString = ((arg) => | ||
ZodString.create({ ...arg, coerce: true })) as (typeof ZodString)["create"]; | ||
const coerceNumber = ((arg) => | ||
ZodNumber.create({ ...arg, coerce: true })) as (typeof ZodNumber)["create"]; | ||
const coerceBoolean = ((arg) => | ||
ZodBoolean.create({ | ||
...arg, | ||
coerce: true, | ||
})) as (typeof ZodBoolean)["create"]; | ||
const coerceBigint = ((arg) => | ||
ZodBigInt.create({ ...arg, coerce: true })) as (typeof ZodBigInt)["create"]; | ||
const coerceDate = ((arg) => | ||
ZodDate.create({ ...arg, coerce: true })) as (typeof ZodDate)["create"]; | ||
|
||
export { | ||
coerceBigint as bigint, | ||
coerceBoolean as boolean, | ||
coerceDate as date, | ||
coerceNumber as number, | ||
coerceString as string, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
export * from "./errors.ts"; | ||
export * from "./helpers/index.ts"; | ||
export * from "./helpers/parseUtil.ts"; | ||
export * from "./helpers/typeAliases.ts"; | ||
export * from "./helpers/util.ts"; | ||
export * from "./types.ts"; | ||
export * from "./ZodError.ts"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,17 @@ | ||
export namespace enumUtil { | ||
type UnionToIntersectionFn<T> = ( | ||
T extends unknown ? (k: () => T) => void : never | ||
) extends (k: infer Intersection) => void | ||
? Intersection | ||
: never; | ||
type UnionToIntersectionFn<T> = ( | ||
T extends unknown ? (k: () => T) => void : never | ||
) extends (k: infer Intersection) => void | ||
? Intersection | ||
: never; | ||
|
||
type GetUnionLast<T> = UnionToIntersectionFn<T> extends () => infer Last | ||
? Last | ||
: never; | ||
type GetUnionLast<T> = UnionToIntersectionFn<T> extends () => infer Last | ||
? Last | ||
: never; | ||
|
||
type UnionToTuple<T, Tuple extends unknown[] = []> = [T] extends [never] | ||
? Tuple | ||
: UnionToTuple<Exclude<T, GetUnionLast<T>>, [GetUnionLast<T>, ...Tuple]>; | ||
type UnionToTuple<T, Tuple extends unknown[] = []> = [T] extends [never] | ||
? Tuple | ||
: UnionToTuple<Exclude<T, GetUnionLast<T>>, [GetUnionLast<T>, ...Tuple]>; | ||
|
||
type CastToStringTuple<T> = T extends [string, ...string[]] ? T : never; | ||
type CastToStringTuple<T> = T extends [string, ...string[]] ? T : never; | ||
|
||
export type UnionToTupleString<T> = CastToStringTuple<UnionToTuple<T>>; | ||
} | ||
export type UnionToTupleString<T> = CastToStringTuple<UnionToTuple<T>>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,5 @@ | ||
export namespace errorUtil { | ||
export type ErrMessage = string | { message?: string }; | ||
export const errToObj = (message?: ErrMessage) => | ||
typeof message === "string" ? { message } : message || {}; | ||
export const toString = (message?: ErrMessage): string | undefined => | ||
typeof message === "string" ? message : message?.message; | ||
} | ||
export type ErrMessage = string | { message?: string }; | ||
export const errToObj = (message?: ErrMessage) => | ||
typeof message === "string" ? { message } : message || {}; | ||
export const toString = (message?: ErrMessage): string | undefined => | ||
typeof message === "string" ? message : message?.message; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export * as enumUtil from "./enumUtil.ts"; | ||
export * as errorUtil from "./errorUtil.ts"; | ||
export * as objectUtil from "./objectUtil.ts"; | ||
export * as partialUtil from "./partialUtil.ts"; | ||
export * as util from "./util.ts"; |
Oops, something went wrong.