Skip to content

Commit

Permalink
Fix merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
colinhacks committed Apr 24, 2024
1 parent 0712d80 commit ef919cd
Show file tree
Hide file tree
Showing 18 changed files with 51 additions and 102 deletions.
5 changes: 2 additions & 3 deletions deno/lib/__tests__/error.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion deno/lib/__tests__/firstpartyschematypes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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> =
Expand Down
2 changes: 1 addition & 1 deletion deno/lib/__tests__/preprocess.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand Down
2 changes: 1 addition & 1 deletion deno/lib/external.ts
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";
35 changes: 16 additions & 19 deletions deno/lib/helpers/objectUtil.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,14 @@
export type MergeShapes<U, V> = {
[k in Exclude<keyof U, keyof V>]: U[k];
} & V;

// type optionalKeys<T extends object> = {
// [k in keyof T]: undefined extends T[k] ? k : never;
// }[keyof T];

type requiredKeys<T extends object> = {
export type optionalKeys<T extends object> = {
[k in keyof T]: undefined extends T[k] ? k : never;
}[keyof T];
export type requiredKeys<T extends object> = {
[k in keyof T]: undefined extends T[k] ? never : k;
}[keyof T];

// type alkjsdf = addQuestionMarks<{ a: any }>;

export type addQuestionMarks<
T extends object,
R extends keyof T = requiredKeys<T>
// O extends keyof T = optionalKeys<T>
> = Pick<Required<T>, R> & Partial<T>;
// = { [k in O]?: T[k] } & { [k in R]: T[k] };
export type addQuestionMarks<T extends object, _O = any> = {
[K in requiredKeys<T>]: T[K];
} & {
[K in optionalKeys<T>]?: T[K];
} & { [k in keyof T]?: unknown };

export type identity<T> = T;
export type flatten<T> = identity<{ [k in keyof T]: T[k] }>;
Expand All @@ -37,4 +28,10 @@ export const mergeShapes = <U, T>(first: U, second: T): T & U => {
};
};

export type extendShape<A, B> = flatten<Omit<A, keyof B> & B>;
export type extendShape<A extends object, B extends object> = {
[K in keyof A | keyof B]: K extends keyof B
? B[K]
: K extends keyof A
? A[K]
: never;
};
2 changes: 1 addition & 1 deletion deno/lib/helpers/parseUtil.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { getErrorMap } from "../errors.ts";
import defaultErrorMap from "../locales/en.ts";
import type { IssueData, ZodErrorMap, ZodIssue } from "../ZodError.ts";
import type { ZodParsedType } from "./util.ts";
import type { ZodParsedType } from "../index.ts";

export const makeIssue = (params: {
data: any;
Expand Down
60 changes: 5 additions & 55 deletions deno/lib/helpers/util.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { objectUtil } from "./index.ts";
// import { objectUtil } from ".";

type AssertEqual<T, U> = (<V>() => V extends T ? 1 : 2) extends <
export type AssertEqual<T, U> = (<V>() => V extends T ? 1 : 2) extends <
V
>() => V extends U ? 1 : 2
? true
Expand All @@ -17,6 +17,7 @@ export type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
export type OmitKeys<T, K extends string> = Pick<T, Exclude<keyof T, K>>;
export type MakePartial<T, K extends keyof T> = Omit<T, K> &
Partial<Pick<T, K>>;
export type Exactly<T, X> = T & Record<Exclude<keyof X, keyof T>, never>;

export const arrayToEnum = <T extends string, U extends [T, ...T[]]>(
items: U
Expand All @@ -28,13 +29,6 @@ export const arrayToEnum = <T extends string, U extends [T, ...T[]]>(
return obj as any;
};

<<<<<<< HEAD
export type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
export type OmitKeys<T, K extends string> = Pick<T, Exclude<keyof T, K>>;
export type MakePartial<T, K extends keyof T> = Omit<T, K> &
Partial<Pick<T, K>>;
export type Exactly<T, X> = T & Record<Exclude<keyof X, keyof T>, never>;
=======
export const getValidEnumValues = (obj: any) => {
const validKeys = objectKeys(obj).filter(
(k: any) => typeof obj[obj[k]] !== "number"
Expand All @@ -45,7 +39,6 @@ export const getValidEnumValues = (obj: any) => {
}
return objectValues(filtered);
};
>>>>>>> 19fbb9a (fix: make util tree shakeable)

export const objectValues = (obj: any) => {
return objectKeys(obj).map(function (e) {
Expand Down Expand Up @@ -73,8 +66,8 @@ export const find = <T>(arr: T[], checker: (arg: T) => any): T | undefined => {
return undefined;
};

export type identity<T> = objectUtil.identity<T>;
export type flatten<T> = objectUtil.flatten<T>;
// export type identity<T> = objectUtil.identity<T>;
// export type flatten<T> = objectUtil.flatten<T>;

export type noUndefined<T> = T extends undefined ? never : T;

Expand All @@ -100,50 +93,7 @@ export const jsonStringifyReplacer = (_: string, value: any): any => {
return value;
};

<<<<<<< HEAD
type optionalKeys<T extends object> = {
[k in keyof T]: undefined extends T[k] ? k : never;
}[keyof T];
type requiredKeys<T extends object> = {
[k in keyof T]: undefined extends T[k] ? never : k;
}[keyof T];
export type addQuestionMarks<T extends object, _O = any> = {
[K in requiredKeys<T>]: T[K];
} & {
[K in optionalKeys<T>]?: T[K];
} & { [k in keyof T]?: unknown };

export type identity<T> = T;
export type flatten<T> = identity<{ [k in keyof T]: T[k] }>;

export type noNeverKeys<T> = {
[k in keyof T]: [T[k]] extends [never] ? never : k;
}[keyof T];

export type noNever<T> = identity<{
[k in noNeverKeys<T>]: k extends keyof T ? T[k] : never;
}>;

export const mergeShapes = <U, T>(first: U, second: T): T & U => {
return {
...first,
...second, // second overwrites first
};
};

export type extendShape<A extends object, B extends object> = {
[K in keyof A | keyof B]: K extends keyof B
? B[K]
: K extends keyof A
? A[K]
: never;
};
}

export const ZodParsedType = util.arrayToEnum([
=======
export const ZodParsedType = arrayToEnum([
>>>>>>> 19fbb9a (fix: make util tree shakeable)
"string",
"nan",
"number",
Expand Down
4 changes: 2 additions & 2 deletions deno/lib/locales/en.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { util } from "../helpers/index.ts";
import { ZodParsedType } from "../helpers/util.ts";

import { ZodErrorMap, ZodIssueCode } from "../ZodError.ts";

const errorMap: ZodErrorMap = (issue, _ctx) => {
let message: string;
switch (issue.code) {
case ZodIssueCode.invalid_type:
if (issue.received === ZodParsedType.undefined) {
if (issue.received === util.ZodParsedType.undefined) {
message = "Required";
} else {
message = `Expected ${issue.expected}, received ${issue.received}`;
Expand Down
6 changes: 4 additions & 2 deletions deno/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ import {
ZodIssueCode,
} from "./ZodError.ts";

export { ZodParsedType } from "./helpers/util.ts";

///////////////////////////////////////
///////////////////////////////////////
////////// //////////
Expand Down Expand Up @@ -3007,7 +3009,7 @@ export class ZodObject<
ZodTypeAny,
objectOutputType<T, ZodTypeAny, "strip">,
objectInputType<T, ZodTypeAny, "strip">
> => {
> {
return new ZodObject({
shape: () => shape,
unknownKeys: "strip",
Expand Down Expand Up @@ -5187,7 +5189,7 @@ export class ZodReadonly<T extends ZodTypeAny> extends ZodType<
typeName: ZodFirstPartyTypeKind.ZodReadonly,
...processCreateParams(params),
}) as any;
};
}

unwrap() {
return this._def.innerType;
Expand Down
4 changes: 2 additions & 2 deletions playground.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { z } from "./src";
import { z } from "./src/index";

z;
z.string().parse("asdf");
5 changes: 2 additions & 3 deletions src/__tests__/error.test.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
// @ts-ignore TS6133
import { expect, test } from "@jest/globals";

import { ZodParsedType } from "../helpers/util";
import * as z from "../index";
import { ZodError, ZodIssueCode } from "../ZodError";

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,
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/firstpartyschematypes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { test } from "@jest/globals";

import { ZodFirstPartySchemaTypes, ZodFirstPartyTypeKind } from "..";
import { util } from "../helpers/util";
import { util } from "../helpers";

test("Identify missing [ZodFirstPartySchemaTypes]", () => {
type ZodFirstPartySchemaForType<T extends ZodFirstPartyTypeKind> =
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/preprocess.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// @ts-ignore TS6133
import { expect, test } from "@jest/globals";

import { util } from "../helpers/util";
import { util } from "../helpers";
import * as z from "../index";

test("preprocess", () => {
Expand Down
2 changes: 1 addition & 1 deletion src/external.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export * from "./errors";
export * from "./helpers/index";
export * from "./helpers/parseUtil";
export * from "./helpers/typeAliases";
export * from "./helpers/util";
export * from "./types";
export * from "./ZodError";
2 changes: 1 addition & 1 deletion src/helpers/parseUtil.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { getErrorMap } from "../errors";
import defaultErrorMap from "../locales/en";
import type { IssueData, ZodErrorMap, ZodIssue } from "../ZodError";
import type { ZodParsedType } from "./util";
import type { ZodParsedType } from "..";

export const makeIssue = (params: {
data: any;
Expand Down
8 changes: 4 additions & 4 deletions src/helpers/util.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { objectUtil } from ".";
// import { objectUtil } from ".";

type AssertEqual<T, U> = (<V>() => V extends T ? 1 : 2) extends <
export type AssertEqual<T, U> = (<V>() => V extends T ? 1 : 2) extends <
V
>() => V extends U ? 1 : 2
? true
Expand Down Expand Up @@ -66,8 +66,8 @@ export const find = <T>(arr: T[], checker: (arg: T) => any): T | undefined => {
return undefined;
};

export type identity<T> = objectUtil.identity<T>;
export type flatten<T> = objectUtil.flatten<T>;
// export type identity<T> = objectUtil.identity<T>;
// export type flatten<T> = objectUtil.flatten<T>;

export type noUndefined<T> = T extends undefined ? never : T;

Expand Down
4 changes: 2 additions & 2 deletions src/locales/en.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { util } from "../helpers";
import { ZodParsedType } from "../helpers/util";

import { ZodErrorMap, ZodIssueCode } from "../ZodError";

const errorMap: ZodErrorMap = (issue, _ctx) => {
let message: string;
switch (issue.code) {
case ZodIssueCode.invalid_type:
if (issue.received === ZodParsedType.undefined) {
if (issue.received === util.ZodParsedType.undefined) {
message = "Required";
} else {
message = `Expected ${issue.expected}, received ${issue.received}`;
Expand Down
6 changes: 4 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ import {
ZodIssueCode,
} from "./ZodError";

export { ZodParsedType } from "./helpers/util";

///////////////////////////////////////
///////////////////////////////////////
////////// //////////
Expand Down Expand Up @@ -3007,7 +3009,7 @@ export class ZodObject<
ZodTypeAny,
objectOutputType<T, ZodTypeAny, "strip">,
objectInputType<T, ZodTypeAny, "strip">
> => {
> {
return new ZodObject({
shape: () => shape,
unknownKeys: "strip",
Expand Down Expand Up @@ -5187,7 +5189,7 @@ export class ZodReadonly<T extends ZodTypeAny> extends ZodType<
typeName: ZodFirstPartyTypeKind.ZodReadonly,
...processCreateParams(params),
}) as any;
};
}

unwrap() {
return this._def.innerType;
Expand Down

0 comments on commit ef919cd

Please sign in to comment.