Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion packages/zod/src/v4/classic/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,6 @@ export const _ZodString: core.$constructor<_ZodString> = /*@__PURE__*/ core.$con
inst.maxLength = bag.maximum ?? null;

// validations
// if (inst.regex) throw new Error("regex already defined");
inst.regex = (...args) => inst.check(checks.regex(...args));
inst.includes = (...args) => inst.check(checks.includes(...args));
inst.startsWith = (...args) => inst.check(checks.startsWith(...args));
Expand Down
17 changes: 10 additions & 7 deletions packages/zod/src/v4/core/checks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -611,8 +611,8 @@ export const $ZodCheckMaxLength: core.$constructor<$ZodCheckMaxLength> = /*@__PU
};

inst._zod.onattach.push((inst) => {
const curr = (inst._zod.bag.maximum ?? Number.POSITIVE_INFINITY) as number;
if (def.maximum < curr) inst._zod.bag.maximum = def.maximum;
const curr = (inst._zod.bag.maxLength ?? Number.POSITIVE_INFINITY) as number;
if (def.maximum < curr) inst._zod.bag.maxLength = def.maximum;
});

inst._zod.check = (payload) => {
Expand Down Expand Up @@ -662,8 +662,8 @@ export const $ZodCheckMinLength: core.$constructor<$ZodCheckMinLength> = /*@__PU
};

inst._zod.onattach.push((inst) => {
const curr = (inst._zod.bag.minimum ?? Number.NEGATIVE_INFINITY) as number;
if (def.minimum > curr) inst._zod.bag.minimum = def.minimum;
const curr = (inst._zod.bag.minLength ?? Number.NEGATIVE_INFINITY) as number;
if (def.minimum > curr) inst._zod.bag.minLength = def.minimum;
});

inst._zod.check = (payload) => {
Expand Down Expand Up @@ -715,9 +715,8 @@ export const $ZodCheckLengthEquals: core.$constructor<$ZodCheckLengthEquals> = /

inst._zod.onattach.push((inst) => {
const bag = inst._zod.bag;
bag.minimum = def.length;
bag.maximum = def.length;
bag.length = def.length;
bag.minLength = def.length;
bag.maxLength = def.length;
});

inst._zod.check = (payload) => {
Expand Down Expand Up @@ -799,6 +798,7 @@ export const $ZodCheckStringFormat: core.$constructor<$ZodCheckStringFormat> = /
if (def.pattern) {
bag.patterns ??= new Set();
bag.patterns.add(def.pattern);
bag.pattern = def.pattern.source;
}
});

Expand Down Expand Up @@ -967,6 +967,7 @@ export const $ZodCheckIncludes: core.$constructor<$ZodCheckIncludes> = /*@__PURE
const bag = inst._zod.bag as schemas.$ZodStringInternals<unknown>["bag"];
bag.patterns ??= new Set();
bag.patterns.add(pattern);
bag.pattern = pattern.source;
});

inst._zod.check = (payload) => {
Expand Down Expand Up @@ -1011,6 +1012,7 @@ export const $ZodCheckStartsWith: core.$constructor<$ZodCheckStartsWith> = /*@__
const bag = inst._zod.bag as schemas.$ZodStringInternals<unknown>["bag"];
bag.patterns ??= new Set();
bag.patterns.add(pattern);
bag.pattern = pattern.source;
});

inst._zod.check = (payload) => {
Expand Down Expand Up @@ -1055,6 +1057,7 @@ export const $ZodCheckEndsWith: core.$constructor<$ZodCheckEndsWith> = /*@__PURE
const bag = inst._zod.bag as schemas.$ZodStringInternals<unknown>["bag"];
bag.patterns ??= new Set();
bag.patterns.add(pattern);
bag.pattern = pattern.source;
});

inst._zod.check = (payload) => {
Expand Down
Loading
Loading