diff --git a/deno/lib/helpers/parseUtil.ts b/deno/lib/helpers/parseUtil.ts
index 17fff0256..81790a58a 100644
--- a/deno/lib/helpers/parseUtil.ts
+++ b/deno/lib/helpers/parseUtil.ts
@@ -125,13 +125,6 @@ export type ParsePath = ParsePathComponent[];
export const EMPTY_PATH: ParsePath = [];
export interface ParseContext {
-<<<<<<< HEAD
- readonly path: ParsePath;
- readonly issues: ZodIssue[];
- readonly schemaErrorMap?: ZodErrorMap;
- readonly contextualErrorMap?: ZodErrorMap;
- readonly async: boolean;
-=======
readonly common: {
readonly issues: ZodIssue[];
readonly contextualErrorMap?: ZodErrorMap;
@@ -140,7 +133,6 @@ export interface ParseContext {
};
readonly path: ParsePath;
readonly schemaErrorMap?: ZodErrorMap;
->>>>>>> 4404b27 (Consolidate common elements of ctx. Remove spreads.)
readonly parent: ParseContext | null;
readonly data: any;
readonly parsedType: ZodParsedType;
@@ -161,21 +153,13 @@ export function addIssueToContext(
data: ctx.data,
path: ctx.path,
errorMaps: [
-<<<<<<< HEAD
- ctx.contextualErrorMap, // contextual error map is first priority
-=======
ctx.common.contextualErrorMap, // contextual error map is first priority
->>>>>>> 4404b27 (Consolidate common elements of ctx. Remove spreads.)
ctx.schemaErrorMap, // then schema-bound map if available
overrideErrorMap, // then global override map
defaultErrorMap, // then global default map
].filter((x) => !!x) as ZodErrorMap[],
});
-<<<<<<< HEAD
- ctx.issues.push(issue);
-=======
ctx.common.issues.push(issue);
->>>>>>> 4404b27 (Consolidate common elements of ctx. Remove spreads.)
}
export type ObjectPair = {
diff --git a/deno/lib/types.ts b/deno/lib/types.ts
index 76f2e17b2..4aa3b0814 100644
--- a/deno/lib/types.ts
+++ b/deno/lib/types.ts
@@ -2,10 +2,7 @@ import { errorUtil } from "./helpers/errorUtil.ts";
import {
addIssueToContext,
AsyncParseReturnType,
-<<<<<<< HEAD
DIRTY,
-=======
->>>>>>> 4404b27 (Consolidate common elements of ctx. Remove spreads.)
getParsedType,
INVALID,
isAborted,
@@ -88,17 +85,10 @@ const handleResult = (
if (isValid(result)) {
return { success: true, data: result.value };
} else {
-<<<<<<< HEAD
- if (!ctx.issues.length) {
- throw new Error("Validation failed but no issues detected.");
- }
- const error = new ZodError(ctx.issues);
-=======
if (!ctx.common.issues.length) {
throw new Error("Validation failed but no issues detected.");
}
const error = new ZodError(ctx.common.issues);
->>>>>>> 4404b27 (Consolidate common elements of ctx. Remove spreads.)
return { success: false, error };
}
};
@@ -165,17 +155,11 @@ export abstract class ZodType<
): ParseContext {
return (
ctx || {
-<<<<<<< HEAD
- ...input.parent,
- data: input.data,
- parsedType: getParsedType(input.data),
-=======
common: input.parent.common,
data: input.data,
parsedType: getParsedType(input.data),
->>>>>>> 4404b27 (Consolidate common elements of ctx. Remove spreads.)
schemaErrorMap: this._def.errorMap,
path: input.path,
parent: input.parent,
@@ -190,17 +174,11 @@ export abstract class ZodType<
return {
status: new ParseStatus(),
ctx: {
-<<<<<<< HEAD
- ...input.parent,
- data: input.data,
- parsedType: getParsedType(input.data),
-=======
common: input.parent.common,
data: input.data,
parsedType: getParsedType(input.data),
->>>>>>> 4404b27 (Consolidate common elements of ctx. Remove spreads.)
schemaErrorMap: this._def.errorMap,
path: input.path,
parent: input.parent,
@@ -233,13 +211,6 @@ export abstract class ZodType<
params?: Partial
): SafeParseReturnType {
const ctx: ParseContext = {
-<<<<<<< HEAD
- path: params?.path || [],
- issues: [],
- contextualErrorMap: params?.errorMap,
- schemaErrorMap: this._def.errorMap,
- async: params?.async ?? false,
-=======
common: {
issues: [],
async: params?.async ?? false,
@@ -248,7 +219,6 @@ export abstract class ZodType<
},
path: params?.path || [],
schemaErrorMap: this._def.errorMap,
->>>>>>> 4404b27 (Consolidate common elements of ctx. Remove spreads.)
parent: null,
data,
parsedType: getParsedType(data),
@@ -272,13 +242,6 @@ export abstract class ZodType<
params?: Partial
): Promise> {
const ctx: ParseContext = {
-<<<<<<< HEAD
- path: params?.path || [],
- issues: [],
- contextualErrorMap: params?.errorMap,
- schemaErrorMap: this._def.errorMap,
- async: true,
-=======
common: {
issues: [],
contextualErrorMap: params?.errorMap,
@@ -287,7 +250,6 @@ export abstract class ZodType<
},
path: params?.path || [],
schemaErrorMap: this._def.errorMap,
->>>>>>> 4404b27 (Consolidate common elements of ctx. Remove spreads.)
parent: null,
data,
parsedType: getParsedType(data),
@@ -1328,11 +1290,7 @@ export class ZodArray<
}
}
-<<<<<<< HEAD
- if (ctx.async) {
-=======
if (ctx.common.async) {
->>>>>>> 4404b27 (Consolidate common elements of ctx. Remove spreads.)
return Promise.all(
(ctx.data as any[]).map((item, i) => {
return def.type._parseAsync({
@@ -1645,11 +1603,7 @@ export class ZodObject<
}
}
-<<<<<<< HEAD
- if (ctx.async) {
-=======
if (ctx.common.async) {
->>>>>>> 4404b27 (Consolidate common elements of ctx. Remove spreads.)
return Promise.resolve()
.then(async () => {
const syncPairs: any[] = [];
@@ -1944,25 +1898,16 @@ export class ZodUnion extends ZodType<
if (result.result.status === "dirty") {
// add issues from dirty option
-<<<<<<< HEAD
- ctx.issues.push(...result.ctx.issues);
-=======
ctx.common.issues.push(...result.ctx.common.issues);
->>>>>>> 4404b27 (Consolidate common elements of ctx. Remove spreads.)
return result.result;
}
}
// return invalid
const unionErrors = results.map(
-<<<<<<< HEAD
- (result) => new ZodError(result.ctx.issues)
- );
-
-=======
(result) => new ZodError(result.ctx.common.issues)
);
->>>>>>> 4404b27 (Consolidate common elements of ctx. Remove spreads.)
+
addIssueToContext(ctx, {
code: ZodIssueCode.invalid_union,
unionErrors,
@@ -1970,23 +1915,15 @@ export class ZodUnion extends ZodType<
return INVALID;
}
-<<<<<<< HEAD
- if (ctx.async) {
-=======
if (ctx.common.async) {
->>>>>>> 4404b27 (Consolidate common elements of ctx. Remove spreads.)
return Promise.all(
options.map(async (option) => {
const childCtx: ParseContext = {
...ctx,
-<<<<<<< HEAD
- issues: [],
-=======
common: {
...ctx.common,
issues: [],
},
->>>>>>> 4404b27 (Consolidate common elements of ctx. Remove spreads.)
parent: null,
};
return {
@@ -2000,14 +1937,16 @@ export class ZodUnion extends ZodType<
})
).then(handleResults);
} else {
-<<<<<<< HEAD
let dirty: undefined | { result: DIRTY; ctx: ParseContext } =
undefined;
const issues: ZodIssue[][] = [];
for (const option of options) {
const childCtx: ParseContext = {
...ctx,
- issues: [],
+ common: {
+ ...ctx.common,
+ issues: [],
+ },
parent: null,
};
const result = option._parseSync({
@@ -2022,13 +1961,13 @@ export class ZodUnion extends ZodType<
dirty = { result, ctx: childCtx };
}
- if (childCtx.issues.length) {
- issues.push(childCtx.issues);
+ if (childCtx.common.issues.length) {
+ issues.push(childCtx.common.issues);
}
}
if (dirty) {
- ctx.issues.push(...dirty.ctx.issues);
+ ctx.common.issues.push(...dirty.ctx.common.issues);
return dirty.result;
}
@@ -2039,28 +1978,6 @@ export class ZodUnion extends ZodType<
});
return INVALID;
-=======
- const optionResults = options.map((option) => {
- const childCtx: ParseContext = {
- ...ctx,
- common: {
- ...ctx.common,
- issues: [],
- },
- parent: null,
- };
- return {
- result: option._parseSync({
- data: ctx.data,
- path: ctx.path,
- parent: childCtx,
- }),
- ctx: childCtx,
- };
- });
-
- return handleResults(optionResults);
->>>>>>> 4404b27 (Consolidate common elements of ctx. Remove spreads.)
}
}
@@ -2143,11 +2060,7 @@ export class ZodDiscriminatedUnion<
return INVALID;
}
-<<<<<<< HEAD
- if (ctx.async) {
-=======
if (ctx.common.async) {
->>>>>>> 4404b27 (Consolidate common elements of ctx. Remove spreads.)
return option._parseAsync({
data: ctx.data,
path: ctx.path,
@@ -2332,11 +2245,7 @@ export class ZodIntersection<
return { status: status.value, value: merged.data as any };
};
-<<<<<<< HEAD
- if (ctx.async) {
-=======
if (ctx.common.async) {
->>>>>>> 4404b27 (Consolidate common elements of ctx. Remove spreads.)
return Promise.all([
this._def.left._parseAsync({
data: ctx.data,
@@ -2471,11 +2380,7 @@ export class ZodTuple<
})
.filter((x) => !!x); // filter nulls
-<<<<<<< HEAD
- if (ctx.async) {
-=======
if (ctx.common.async) {
->>>>>>> 4404b27 (Consolidate common elements of ctx. Remove spreads.)
return Promise.all(items).then((results) => {
return ParseStatus.mergeArray(status, results);
});
@@ -2580,11 +2485,7 @@ export class ZodRecord<
});
}
-<<<<<<< HEAD
- if (ctx.async) {
-=======
if (ctx.common.async) {
->>>>>>> 4404b27 (Consolidate common elements of ctx. Remove spreads.)
return ParseStatus.mergeObjectAsync(status, pairs);
} else {
return ParseStatus.mergeObjectSync(status, pairs as any);
@@ -2678,11 +2579,7 @@ export class ZodMap<
}
);
-<<<<<<< HEAD
- if (ctx.async) {
-=======
if (ctx.common.async) {
->>>>>>> 4404b27 (Consolidate common elements of ctx. Remove spreads.)
const finalMap = new Map();
return Promise.resolve().then(async () => {
for (const pair of pairs) {
@@ -2808,11 +2705,7 @@ export class ZodSet extends ZodType<
valueType._parse({ data: item, path: [...ctx.path, i], parent: ctx })
);
-<<<<<<< HEAD
- if (ctx.async) {
-=======
if (ctx.common.async) {
->>>>>>> 4404b27 (Consolidate common elements of ctx. Remove spreads.)
return Promise.all(elements).then((elements) => finalizeSet(elements));
} else {
return finalizeSet(elements as SyncParseReturnType[]);
@@ -2909,11 +2802,7 @@ export class ZodFunction<
data: args,
path: ctx.path,
errorMaps: [
-<<<<<<< HEAD
- ctx.contextualErrorMap,
-=======
ctx.common.contextualErrorMap,
->>>>>>> 4404b27 (Consolidate common elements of ctx. Remove spreads.)
ctx.schemaErrorMap,
overrideErrorMap,
defaultErrorMap,
@@ -2930,11 +2819,7 @@ export class ZodFunction<
data: returns,
path: ctx.path,
errorMaps: [
-<<<<<<< HEAD
- ctx.contextualErrorMap,
-=======
ctx.common.contextualErrorMap,
->>>>>>> 4404b27 (Consolidate common elements of ctx. Remove spreads.)
ctx.schemaErrorMap,
overrideErrorMap,
defaultErrorMap,
@@ -2946,11 +2831,7 @@ export class ZodFunction<
});
}
-<<<<<<< HEAD
- const params = { errorMap: ctx.contextualErrorMap };
-=======
const params = { errorMap: ctx.common.contextualErrorMap };
->>>>>>> 4404b27 (Consolidate common elements of ctx. Remove spreads.)
const fn = ctx.data;
if (this._def.returns instanceof ZodPromise) {
@@ -3282,14 +3163,10 @@ export class ZodPromise extends ZodType<
> {
_parse(input: ParseInput): ParseReturnType {
const { ctx } = this._processInputParams(input);
-<<<<<<< HEAD
- if (ctx.parsedType !== ZodParsedType.promise && ctx.async === false) {
-=======
if (
ctx.parsedType !== ZodParsedType.promise &&
ctx.common.async === false
) {
->>>>>>> 4404b27 (Consolidate common elements of ctx. Remove spreads.)
addIssueToContext(ctx, {
code: ZodIssueCode.invalid_type,
expected: ZodParsedType.promise,
@@ -3307,11 +3184,7 @@ export class ZodPromise extends ZodType<
promisified.then((data: any) => {
return this._def.type.parseAsync(data, {
path: ctx.path,
-<<<<<<< HEAD
- errorMap: ctx.contextualErrorMap,
-=======
errorMap: ctx.common.contextualErrorMap,
->>>>>>> 4404b27 (Consolidate common elements of ctx. Remove spreads.)
});
})
);
@@ -3381,11 +3254,7 @@ export class ZodEffects<
if (effect.type === "preprocess") {
const processed = effect.transform(ctx.data);
-<<<<<<< HEAD
- if (ctx.async) {
-=======
if (ctx.common.async) {
->>>>>>> 4404b27 (Consolidate common elements of ctx. Remove spreads.)
return Promise.resolve(processed).then((processed) => {
return this._def.schema._parseAsync({
data: processed,
@@ -3424,11 +3293,7 @@ export class ZodEffects<
// effect: RefinementEffect
): any => {
const result = effect.refinement(acc, checkCtx);
-<<<<<<< HEAD
- if (ctx.async) {
-=======
if (ctx.common.async) {
->>>>>>> 4404b27 (Consolidate common elements of ctx. Remove spreads.)
return Promise.resolve(result);
}
if (result instanceof Promise) {
@@ -3439,11 +3304,7 @@ export class ZodEffects<
return acc;
};
-<<<<<<< HEAD
- if (ctx.async === false) {
-=======
if (ctx.common.async === false) {
->>>>>>> 4404b27 (Consolidate common elements of ctx. Remove spreads.)
const inner = this._def.schema._parseSync({
data: ctx.data,
path: ctx.path,
@@ -3470,11 +3331,7 @@ export class ZodEffects<
}
if (effect.type === "transform") {
-<<<<<<< HEAD
- if (ctx.async === false) {
-=======
if (ctx.common.async === false) {
->>>>>>> 4404b27 (Consolidate common elements of ctx. Remove spreads.)
const base = this._def.schema._parseSync({
data: ctx.data,
path: ctx.path,