/opt/canhelp/node_modules/better-auth/node_modules/zod/src/v4/classic/tests
NameSizeModeActions
anyunknown.test.ts6390644editdlrm
apply.test.ts15090644editdlrm
array.test.ts72480644editdlrm
assignability.test.ts67900644editdlrm
async-parsing.test.ts123110644editdlrm
async-refinements.test.ts18670644editdlrm
base.test.ts1790644editdlrm
bigint.test.ts19560644editdlrm
brand.test.ts35740644editdlrm
catch.test.ts78310644editdlrm
coalesce.test.ts7430644editdlrm
codec-examples.test.ts190300644editdlrm
codec.test.ts188530644editdlrm
coerce.test.ts77360644editdlrm
continuability.test.ts80200644editdlrm
custom.test.ts12150644editdlrm
date.test.ts16710644editdlrm
datetime.test.ts119320644editdlrm
default.test.ts92260644editdlrm
describe-meta-checks.test.ts9650644editdlrm
description.test.ts12940644editdlrm
discriminated-unions.test.ts176650644editdlrm
enum.test.ts84880644editdlrm
error-utils.test.ts137440644editdlrm
error.test.ts195020644editdlrm
file.test.ts26410644editdlrm
firstparty.test.ts30450644editdlrm
fix-json-issue.test.ts7710644editdlrm
from-json-schema.test.ts214980644editdlrm
function.test.ts83440644editdlrm
generics.test.ts21620644editdlrm
hash.test.ts32040644editdlrm
index.test.ts311910644editdlrm
instanceof.test.ts16580644editdlrm
intersection.test.ts55550644editdlrm
json.test.ts33270644editdlrm
lazy.test.ts47560644editdlrm
literal.test.ts30950644editdlrm
map.test.ts76220644editdlrm
nan.test.ts6450644editdlrm
nested-refine.test.ts36230644editdlrm
nonoptional.test.ts28410644editdlrm
nullable.test.ts5910644editdlrm
number.test.ts86440644editdlrm
object.test.ts184810644editdlrm
optional.test.ts73320644editdlrm
partial.test.ts129730644editdlrm
pickomit.test.ts68850644editdlrm
pipe.test.ts23380644editdlrm
prefault.test.ts20630644editdlrm
preprocess.test.ts65220644editdlrm
primitive.test.ts76490644editdlrm
promise.test.ts23240644editdlrm
prototypes.test.ts4980644editdlrm
readonly.test.ts117860644editdlrm
record.test.ts172260644editdlrm
recursive-types.test.ts126930644editdlrm
refine.test.ts156490644editdlrm
registries.test.ts73910644editdlrm
set.test.ts56220644editdlrm
standard-schema.test.ts37700644editdlrm
string-formats.test.ts37000644editdlrm
string.test.ts780690644editdlrm
stringbool.test.ts35360644editdlrm
template-literal.test.ts358940644editdlrm
to-json-schema-methods.test.ts101000644editdlrm
to-json-schema.test.ts786390644editdlrm
transform.test.ts82980644editdlrm
tuple.test.ts55320644editdlrm
union.test.ts59360644editdlrm
url.test.ts4020644editdlrm
validations.test.ts67360644editdlrm
void.test.ts3060644editdlrm
Edit: /opt/canhelp/node_modules/better-auth/node_modules/zod/src/v4/classic/tests/registries.test.ts (7391B)
import { expect, expectTypeOf, test } from "vitest"; import * as z from "zod/v4"; test("globalRegistry", () => { const reg = z.registry(); const a = z.string(); reg.add(a); expect(reg.has(a)).toEqual(true); reg.remove(a); expect(reg.has(a)).toEqual(false); a.register(z.globalRegistry, { field: "sup" }); expect(z.globalRegistry.has(a)).toEqual(true); expect(z.globalRegistry.get(a)).toEqual({ field: "sup" }); z.globalRegistry.remove(a); expect(z.globalRegistry.has(a)).toEqual(false); }); test("globalRegistry is singleton and attached to globalThis", () => { expect(z.globalRegistry).toBe((globalThis as any).__zod_globalRegistry); }); test("z.registry", () => { const fieldRegistry = z.registry<{ name: string; description: string }>(); const a = z.string(); fieldRegistry.add(a, { name: "hello", description: "world" }); const a_meta = fieldRegistry.get(a); expect(a_meta).toEqual({ name: "hello", description: "world" }); fieldRegistry.remove(a); expect(fieldRegistry.has(a)).toEqual(false); expect(fieldRegistry.get(a)).toEqual(undefined); }); test("z.registry no metadata", () => { const fieldRegistry = z.registry(); const a = z.string(); fieldRegistry.add(a); fieldRegistry.add(z.number()); expect(fieldRegistry.get(a)).toEqual(undefined); expect(fieldRegistry.has(a)).toEqual(true); }); test("z.registry with schema constraints", () => { const fieldRegistry = z.registry<{ name: string; description: string }, z.ZodString>(); const a = z.string(); fieldRegistry.add(a, { name: "hello", description: "world" }); // @ts-expect-error fieldRegistry.add(z.number(), { name: "test" }); // @ts-expect-error z.number().register(fieldRegistry, { name: "test", description: "test" }); }); // test("z.namedRegistry", () => { // const namedReg = z // .namedRegistry<{ name: string; description: string }>() // .add(z.string(), { name: "hello", description: "world" }) // .add(z.number(), { name: "number", description: "number" }); // expect(namedReg.get("hello")).toEqual({ // name: "hello", // description: "world", // }); // expect(namedReg.has("hello")).toEqual(true); // expect(namedReg.get("number")).toEqual({ // name: "number", // description: "number", // }); // // @ts-expect-error // namedReg.get("world"); // // @ts-expect-error // expect(namedReg.get("world")).toEqual(undefined); // const hello = namedReg.get("hello"); // expect(hello).toEqual({ name: "hello", description: "world" }); // expectTypeOf().toEqualTypeOf<{ // name: "hello"; // description: "world"; // }>(); // expectTypeOf().toEqualTypeOf<{ // hello: { name: "hello"; description: "world" }; // number: { name: "number"; description: "number" }; // }>(); // }); test("output type in registry meta", () => { const reg = z.registry<{ out: z.$output }>(); const a = z.string(); reg.add(a, { out: "asdf" }); // @ts-expect-error reg.add(a, 1234); expectTypeOf(reg.get(a)).toEqualTypeOf<{ out: string } | undefined>(); }); test("output type in registry meta - objects and arrays", () => { const reg = z.registry<{ name: string; examples: z.$output[] }>(); const a = z.string(); reg.add(a, { name: "hello", examples: ["world"] }); // @ts-expect-error reg.add(a, { name: "hello", examples: "world" }); expectTypeOf(reg.get(a)).toEqualTypeOf<{ name: string; examples: string[] } | undefined>(); }); test("input type in registry meta", () => { const reg = z.registry<{ in: z.$input }>(); const a = z.pipe(z.number(), z.transform(String)); reg.add(a, { in: 1234 }); // @ts-expect-error reg.add(a, "1234"); expectTypeOf(reg.get(a)).toEqualTypeOf<{ in: number } | undefined>(); }); test("input type in registry meta - objects and arrays", () => { const reg = z.registry<{ name: string; examples: z.$input[] }>(); const a = z.pipe(z.number(), z.transform(String)); reg.add(a, { name: "hello", examples: [1234] }); // @ts-expect-error reg.add(a, { name: "hello", examples: "world" }); expectTypeOf(reg.get(a)).toEqualTypeOf<{ name: string; examples: number[] } | undefined>(); }); test(".meta method", () => { const a1 = z.string(); const a2 = a1.meta({ name: "hello" }); expect(a1.meta()).toEqual(undefined); expect(a2.meta()).toEqual({ name: "hello" }); expect(a1 === a2).toEqual(false); }); test(".meta metadata does not bubble up", () => { const a1 = z.string().meta({ name: "hello" }); const a2 = a1.optional(); expect(a1.meta()).toEqual({ name: "hello" }); expect(a2.meta()).toEqual(undefined); }); test(".describe", () => { const a1 = z.string(); const a2 = a1.describe("Hello"); expect(a1.description).toEqual(undefined); expect(a2.description).toEqual("Hello"); }); test("inherit across clone", () => { const A = z.string().meta({ a: true }); expect(A.meta()).toEqual({ a: true }); const B = A.meta({ b: true }); expect(B.meta()).toEqual({ a: true, b: true }); const C = B.describe("hello"); expect(C.meta()).toEqual({ a: true, b: true, description: "hello" }); }); test("loose examples", () => { z.string().register(z.globalRegistry, { examples: ["example"], }); }); test("function meta without replacement", () => { const myReg = z.registry<{ defaulter: (arg: string, test: boolean) => number; }>(); const mySchema = z.date(); myReg.add(mySchema, { defaulter: (arg, _test) => { return arg.length; }, }); expect(myReg.get(mySchema)!.defaulter("hello", true)).toEqual(5); }); test("function meta with replacement", () => { const myReg = z.registry<{ defaulter: (arg: z.$input, test: boolean) => z.$output; }>(); const mySchema = z.string().transform((val) => val.length); myReg.add(mySchema, { defaulter: (arg, _test) => { return arg.length; }, }); expect(myReg.get(mySchema)!.defaulter("hello", true)).toEqual(5); }); test("test .clear()", () => { const reg = z.registry(); const a = z.string(); reg.add(a); expect(reg.has(a)).toEqual(true); reg.clear(); expect(reg.has(a)).toEqual(false); }); test("re-registering same id silently overwrites", () => { const reg = z.registry(); const a = z.string(); const b = z.number(); reg.add(a, { id: "shared-id" }); reg.add(b, { id: "shared-id" }); // No error thrown, b now owns the id expect(reg._idmap.get("shared-id")).toBe(b); }); test("toJSONSchema throws on duplicate id across different schemas", () => { const reg = z.registry(); const a = z.string().register(reg, { id: "duplicate-id" }); const b = z.number().register(reg, { id: "duplicate-id" }); const wrapper = z.object({ a, b }); expect(() => z.toJSONSchema(wrapper, { metadata: reg })).toThrow( 'Duplicate schema id "duplicate-id" detected during JSON Schema conversion. Two different schemas cannot share the same id when converted together.' ); }); test("toJSONSchema allows same schema with same id", () => { const reg = z.registry(); const shared = z.string().register(reg, { id: "shared-id" }); const wrapper = z.object({ a: shared, b: shared }); // Should not throw - same schema instance used twice const result = z.toJSONSchema(wrapper, { metadata: reg }); expect(result.$defs?.["shared-id"]).toBeDefined(); });