import { CheckOrEffectIR, FileCheckIR, SetCheckIR } from "../../types.js"; import { CodeGenContext, SlowGen } from "../context.js"; //#region src/core/codegen/schemas/sizeable.d.ts /** * String length tests over Unicode CODE POINTS, gated so the count is only * paid for when the UTF-16 unit count leaves the verdict in doubt. * * zod measures `z.string().min()/.max()/.length()` in code points * (`util.codePointLength`), so `"😀"` has length 1, and it computes that count * only when the unit count could sit on the other side of the bound. A code * point is one or two units, so `units/2 <= codePoints <= units` — which pins * the doubtful band tighter than zod's own gate without changing a verdict: * `min(N)` is settled outside `N <= units < 2*ceil(N)-1` (so `min(1)` stays a * plain `length>=1`; see {@link certainlyAtLeast} for the fractional case), * `max(N)` outside `N < units <= 2N`, and `length(N)` outside `N <= units <= * 2N`. Every test leads with the plain unit comparison, so an ASCII string of * ordinary length never reaches the helper. * * `mayNotBeString` adds the `typeof` guard zod applies (`typeof input === * "string" && …`) for a site whose input is not statically a string — a * length check firing on the wrong type through its `when` predicate; an array * measures elements, never code points. Only the failure-direction forms take * it: `min`/`max`/`equals` are reached solely from `fastStringCheck`, whose * input is statically a string. */ declare const stringLengthTests: { min(x: string, min: number, ctx: CodeGenContext): string; max(x: string, max: number, ctx: CodeGenContext): string; equals(x: string, length: number, ctx: CodeGenContext): string; /** * The FAILING condition of `min`/`max`, with the negation pushed inward so a * check with no doubtful band emits the plain comparison the slow path always * used (`x.length<1`, not `!(x.length>=1)`). */ minFails(x: string, min: number, ctx: CodeGenContext, mayNotBeString?: boolean): string; maxFails(x: string, max: number, ctx: CodeGenContext, mayNotBeString?: boolean): string; /** * The measured length zod compares in `$ZodCheckLengthEquals` — code points * inside the doubtful band, units outside it — for the slow path, which has * to know WHICH side of the bound the value fell on. */ measure(x: string, length: number, ctx: CodeGenContext, mayNotBeString?: boolean): string; }; /** * Length/size checks re-emitted for the branch where the node's TYPE CHECK * ALREADY FAILED. * * zod skips a schema's checks once its parse aborted — except the ones carrying * a `when` predicate, which `runChecks` consults instead of the abort flag: * * ```js * if (ch._zod.def.when) { if (!ch._zod.def.when(payload)) continue; } * else if (isAborted) continue; * ``` * * and `$ZodCheckMinLength` & co. install exactly such a predicate — * `!nullish(value) && value.length !== undefined` (`.size` for the size family) * — so they run on ANY input carrying that property, of any type. Hence * `z.string().min(2).safeParse([])` reports TWO issues in zod: the * `invalid_type`, and a `too_small` whose `origin` is `"array"`, because the * empty array satisfied the `when`. Compiled output kept every check inside the * matched-type branch and reported only the first. Same for * `z.array(…).min(3)` over a short string, `z.set(…).min(2)` over a `Map`, and * `z.file().min(2)` over a `Set`. * * Emitted as a SEPARATE copy in the failure branch rather than hoisted out of * both, so the success path — where the origin is statically known and the guard * is trivially true — stays byte-for-byte what it was. This is cold code: it * runs only for input the node has already rejected. * * `origin` is computed at runtime here (see ZC_LENGTH_ORIGIN_DECL), because the * value that reached this branch is by definition not the schema's own type. * * `mayBeString` is set by a non-string node whose length checks can fire on a * string (`z.array(…).min(2)` over `"😀"`): zod then measures it in code * points, so those tests take the guarded form of {@link stringLengthTests}. A * string node's own failure branch never holds a string and keeps the plain * unit comparison. */ declare function whenGatedSizeChecks(checks: readonly (CheckOrEffectIR | SetCheckIR | FileCheckIR)[], g: SlowGen, family: "length" | "size", mayBeString?: boolean): string; //#endregion export { stringLengthTests, whenGatedSizeChecks }; //# sourceMappingURL=sizeable.d.ts.map