import { z } from 'zod'; import * as fc from 'fast-check'; import type { inline } from '@traversable/registry'; import { symbol } from '@traversable/registry'; type Config = import('./generator-options.js').Config; import * as Config from './generator-options.js'; import * as Bounds from './generator-bounds.js'; import type { Tag } from './generator-seed.js'; import { Seed } from './generator-seed.js'; export interface SeedBuilder { (tie: fc.LetrecTypedTie, $: Config.byTypeName[K]): fc.Arbitrary; } export type SeedMap = { [K in keyof Seed]: SeedBuilder; }; export declare const SeedMap: { array: (tie: fc.LetrecTypedTie) => fc.Arbitrary<[1000, unknown, Bounds.array]>; catch: (tie: fc.LetrecTypedTie) => fc.Arbitrary<[5000, unknown]>; custom: (tie: fc.LetrecTypedTie) => fc.Arbitrary<[9500, unknown]>; default: (tie: fc.LetrecTypedTie) => fc.Arbitrary<[5500, unknown]>; prefault: (tie: fc.LetrecTypedTie) => fc.Arbitrary<[5600, unknown]>; lazy: (tie: fc.LetrecTypedTie) => fc.Arbitrary<[10500, () => unknown]>; nonoptional: (tie: fc.LetrecTypedTie) => fc.Arbitrary<[1500, unknown]>; nullable: (tie: fc.LetrecTypedTie) => fc.Arbitrary<[2000, unknown]>; optional: (tie: fc.LetrecTypedTie) => fc.Arbitrary<[2500, unknown]>; readonly: (tie: fc.LetrecTypedTie) => fc.Arbitrary<[3000, unknown]>; record: (tie: fc.LetrecTypedTie) => fc.Arbitrary<[7000, unknown]>; set: (tie: fc.LetrecTypedTie) => fc.Arbitrary<[3500, unknown]>; success: (tie: fc.LetrecTypedTie) => fc.Arbitrary<[4000, unknown]>; object: (tie: fc.LetrecTypedTie, $: fc.UniqueArrayConstraintsRecommended<[k: string, v: unknown], string>) => fc.Arbitrary<[7500, [string, unknown][]]>; tuple: (tie: fc.LetrecTypedTie, $: fc.ArrayConstraints) => fc.Arbitrary<[8000, unknown[]]>; union: (tie: fc.LetrecTypedTie, $: fc.ArrayConstraints) => fc.Arbitrary<[8500, unknown[]]>; intersection: (tie: fc.LetrecTypedTie) => fc.Arbitrary<[6000, [[7500, [string, unknown][]], [7500, [string, unknown][]]]]>; map: (tie: fc.LetrecTypedTie) => fc.Arbitrary<[6500, [unknown, unknown]]>; pipe: (tie: fc.LetrecTypedTie) => fc.Arbitrary<[9000, [unknown, unknown]]>; transform: (tie: fc.LetrecTypedTie) => fc.Arbitrary<[10000, unknown]>; promise: (tie: fc.LetrecTypedTie) => fc.Arbitrary<[100000, unknown]>; enum: (y?: S | undefined) => fc.Arbitrary<[500, any]>; literal: (y?: S | undefined) => fc.Arbitrary<[550, string | number | bigint | boolean]>; template_literal: (_tie: fc.LetrecTypedTie, $: fc.ArrayConstraints) => fc.Arbitrary; bigint: (y?: S | undefined) => fc.Arbitrary<[150, Bounds.bigint]>; int: (y?: S | undefined) => fc.Arbitrary<[100, Bounds.int]>; number: (y?: S | undefined) => fc.Arbitrary<[200, Bounds.number]>; string: (y?: S | undefined) => fc.Arbitrary<[250, Bounds.string]>; any: (y?: S | undefined) => fc.Arbitrary<[10]>; boolean: (y?: S | undefined) => fc.Arbitrary<[15]>; date: (y?: S | undefined) => fc.Arbitrary<[20]>; file: (y?: S | undefined) => fc.Arbitrary<[25]>; nan: (y?: S | undefined) => fc.Arbitrary<[30]>; never: (y?: S | undefined) => fc.Arbitrary<[35]>; null: (y?: S | undefined) => fc.Arbitrary<[40]>; undefined: (y?: S | undefined) => fc.Arbitrary<[50]>; unknown: (y?: S | undefined) => fc.Arbitrary<[55]>; void: (y?: S | undefined) => fc.Arbitrary<[60]>; symbol: (y?: S | undefined) => fc.Arbitrary<[45]>; }; export declare function isTerminal(x: unknown): x is Seed.Terminal | Seed.Boundable; export declare const pickAndSortNodes: (nodes: readonly ([keyof SeedMap, unknown])[]) => ($: Config) => (keyof SeedMap)[]; export declare const z_int: (bounds?: Bounds.int) => z.ZodNumber; export declare const z_bigint: (bounds?: Bounds.bigint) => z.ZodBigInt; export declare const z_number: (bounds?: Bounds.number) => z.ZodNumber; export declare const z_string: (bounds?: Bounds.string) => z.ZodString; export declare const z_array: (elementSchema: T, bounds?: Bounds.array) => z.ZodArray; export interface Builder extends inline<{ [K in Tag]+?: fc.Arbitrary; }> { root?: fc.Arbitrary; invalid?: fc.Arbitrary; ['*']: fc.Arbitrary; } export declare function Builder(base: Gen.Base): >(options?: Options, overrides?: Partial>) => (tie: fc.LetrecLooselyTypedTie) => Builder; export declare namespace Gen { type Base = { [K in keyof T]: (tie: fc.LetrecLooselyTypedTie, constraints: $[K & keyof $]) => fc.Arbitrary; }; type Values = never | T[Exclude]; type InferArb = S extends fc.Arbitrary ? T : never; interface Builder extends T { ['*']: fc.Arbitrary>>; } type BuildBuilder, Out extends {} = BuilderBase> = never | Builder; type BuilderBase, $ extends ParseOptions = ParseOptions> = never | ([$['root']] extends [never] ? unknown : { root: fc.Arbitrary<$['root']>; }) & { [K in Exclude<$['include'], $['exclude']>]: fc.Arbitrary; }; type ParseOptions> = never | { include: Options['include'] extends readonly unknown[] ? Options['include'][number] : keyof T; exclude: Options['exclude'] extends readonly unknown[] ? Options['exclude'][number] : never; root: Options['root'] extends keyof T ? T[Options['root']] : never; }; } /** * ## {@link Gen `Gen`} */ export declare function Gen(base: Gen.Base): >(options?: Options, overrides?: Partial>) => Gen.BuildBuilder; /** * ## {@link seedToValidDataGenerator `seedToValidDataGenerator`} * * Convert a seed into an valid data generator. * * Valid in this context means that it will always satisfy the zod schema that the seed produces. * * To use it, you'll need to have [fast-check](https://github.com/dubzzz/fast-check) installed. * * To convert a seed to a zod schema, use {@link seedToSchema `seedToSchema`}. * * To convert a seed to an _invalid_ data generator, use {@link seedToInvalidDataGenerator `seedToInvalidDataGenerator`}. */ export declare function seedToValidDataGenerator(seed: Seed.F, options?: Config.Options): fc.Arbitrary; /** * ## {@link seedToInvalidDataGenerator `seedToInvalidDataGenerator`} * * Convert a seed into an invalid data generator. * * Invalid in this context means that it will never satisfy the zod schema that the seed produces. * * To use it, you'll need to have [fast-check](https://github.com/dubzzz/fast-check) installed. * * To convert a seed to a zod schema, use {@link seedToSchema `seedToSchema`}. * * To convert a seed to an _valid_ data generator, use * {@link seedToValidDataGenerator `seedToValidDataGenerator`}. */ export declare function seedToInvalidDataGenerator(seed: T, options?: Config.Options): fc.Arbitrary; export declare function seedToInvalidDataGenerator(seed: Seed.F, options?: Config.Options): fc.Arbitrary; /** * ## {@link SeedGenerator `SeedGenerator`} * * Pseudo-random seed generator. * * The generator supports a wide range of discoverable configuration options via the * optional `options` argument. * * Many of those options are forwarded to the corresponding `fast-check` arbitrary. * * To use it, you'll need to have [fast-check](https://github.com/dubzzz/fast-check) installed. * * See also: * - {@link SeedGenerator `SeedGenerator`} * * @example * import * as fc from 'fast-check' * import { z } from 'zod' * import { zxTest } from '@traversable/zod-test' * * const Json = zxTest.SeedGenerator({ include: ['null', 'boolean', 'number', 'string', 'array', 'object'] }) * const [jsonNumber, jsonObject, anyJson] = [ * fc.sample(Json.number, 1)[0], * fc.sample(Json.object, 1)[0], * fc.sample(Json['*'], 1)[0], * ] as const * * console.log(JSON.stringify(jsonNumber)) * // => [200,[2.96e-322,1,null,false,true]] * * console.log(zxTest.toString(zxTest.seedToSchema(jsonNumber))) * // => z.number().min(2.96e-322).lt(1) * * console.log(JSON.stringify(jsonObject)) * // => [7500,[["n;}289K~",[250,[null,null]]]]] * * console.log(zxTest.toString(zxTest.seedToSchema(jsonObject))) * // => z.object({ "n;}289K~": z.string() }) * * console.log(anyJson) * // => [250,[23,64]] * * console.log(zxTest.toString(zxTest.seedToSchema(anyJson))) * // => z.string().min(23).max(64) */ export declare const SeedGenerator: unknown]; nonoptional: [1500, unknown]; nullable: [2000, unknown]; optional: [2500, unknown]; readonly: [3000, unknown]; record: [7000, unknown]; set: [3500, unknown]; success: [4000, unknown]; object: [7500, [string, unknown][]]; tuple: [8000, unknown[]]; union: [8500, unknown[]]; intersection: [6000, [[7500, [string, unknown][]], [7500, [string, unknown][]]]]; map: [6500, [unknown, unknown]]; pipe: [9000, [unknown, unknown]]; transform: [10000, unknown]; promise: [100000, unknown]; enum: [500, any]; literal: [550, string | number | bigint | boolean]; template_literal: Seed.TemplateLiteral; bigint: [150, Bounds.bigint]; int: [100, Bounds.int]; number: [200, Bounds.number]; string: [250, Bounds.string]; any: [10]; boolean: [15]; date: [20]; file: [25]; nan: [30]; never: [35]; null: [40]; undefined: [50]; unknown: [55]; void: [60]; symbol: [45]; }>>(options?: Options | undefined, overrides?: Partial unknown]; nonoptional: [1500, unknown]; nullable: [2000, unknown]; optional: [2500, unknown]; readonly: [3000, unknown]; record: [7000, unknown]; set: [3500, unknown]; success: [4000, unknown]; object: [7500, [string, unknown][]]; tuple: [8000, unknown[]]; union: [8500, unknown[]]; intersection: [6000, [[7500, [string, unknown][]], [7500, [string, unknown][]]]]; map: [6500, [unknown, unknown]]; pipe: [9000, [unknown, unknown]]; transform: [10000, unknown]; promise: [100000, unknown]; enum: [500, any]; literal: [550, string | number | bigint | boolean]; template_literal: Seed.TemplateLiteral; bigint: [150, Bounds.bigint]; int: [100, Bounds.int]; number: [200, Bounds.number]; string: [250, Bounds.string]; any: [10]; boolean: [15]; date: [20]; file: [25]; nan: [30]; never: [35]; null: [40]; undefined: [50]; unknown: [55]; void: [60]; symbol: [45]; }, Config.byTypeName>> | undefined) => Gen.Builder<([Options["root"] extends "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "map" | "int" | "null" | "void" | "never" | "any" | "unknown" | "date" | "record" | "file" | "array" | "tuple" | "union" | "intersection" | "set" | "enum" | "literal" | "nullable" | "optional" | "nonoptional" | "success" | "transform" | "default" | "prefault" | "catch" | "nan" | "pipe" | "readonly" | "template_literal" | "promise" | "lazy" | "custom" ? { array: [1000, unknown, Bounds.array]; catch: [5000, unknown]; custom: [9500, unknown]; default: [5500, unknown]; prefault: [5600, unknown]; lazy: [10500, () => unknown]; nonoptional: [1500, unknown]; nullable: [2000, unknown]; optional: [2500, unknown]; readonly: [3000, unknown]; record: [7000, unknown]; set: [3500, unknown]; success: [4000, unknown]; object: [7500, [string, unknown][]]; tuple: [8000, unknown[]]; union: [8500, unknown[]]; intersection: [6000, [[7500, [string, unknown][]], [7500, [string, unknown][]]]]; map: [6500, [unknown, unknown]]; pipe: [9000, [unknown, unknown]]; transform: [10000, unknown]; promise: [100000, unknown]; enum: [500, any]; literal: [550, string | number | bigint | boolean]; template_literal: Seed.TemplateLiteral; bigint: [150, Bounds.bigint]; int: [100, Bounds.int]; number: [200, Bounds.number]; string: [250, Bounds.string]; any: [10]; boolean: [15]; date: [20]; file: [25]; nan: [30]; never: [35]; null: [40]; undefined: [50]; unknown: [55]; void: [60]; symbol: [45]; }[Options["root"]] : never] extends [never] ? unknown : { root: fc.Arbitrary unknown]; nonoptional: [1500, unknown]; nullable: [2000, unknown]; optional: [2500, unknown]; readonly: [3000, unknown]; record: [7000, unknown]; set: [3500, unknown]; success: [4000, unknown]; object: [7500, [string, unknown][]]; tuple: [8000, unknown[]]; union: [8500, unknown[]]; intersection: [6000, [[7500, [string, unknown][]], [7500, [string, unknown][]]]]; map: [6500, [unknown, unknown]]; pipe: [9000, [unknown, unknown]]; transform: [10000, unknown]; promise: [100000, unknown]; enum: [500, any]; literal: [550, string | number | bigint | boolean]; template_literal: Seed.TemplateLiteral; bigint: [150, Bounds.bigint]; int: [100, Bounds.int]; number: [200, Bounds.number]; string: [250, Bounds.string]; any: [10]; boolean: [15]; date: [20]; file: [25]; nan: [30]; never: [35]; null: [40]; undefined: [50]; unknown: [55]; void: [60]; symbol: [45]; }[Options["root"]] : never>; }) & { [K in Exclude]: fc.Arbitrary<{ array: [1000, unknown, Bounds.array]; catch: [5000, unknown]; custom: [9500, unknown]; default: [5500, unknown]; prefault: [5600, unknown]; lazy: [10500, () => unknown]; nonoptional: [1500, unknown]; nullable: [2000, unknown]; optional: [2500, unknown]; readonly: [3000, unknown]; record: [7000, unknown]; set: [3500, unknown]; success: [4000, unknown]; object: [7500, [string, unknown][]]; tuple: [8000, unknown[]]; union: [8500, unknown[]]; intersection: [6000, [[7500, [string, unknown][]], [7500, [string, unknown][]]]]; map: [6500, [unknown, unknown]]; pipe: [9000, [unknown, unknown]]; transform: [10000, unknown]; promise: [100000, unknown]; enum: [500, any]; literal: [550, string | number | bigint | boolean]; template_literal: Seed.TemplateLiteral; bigint: [150, Bounds.bigint]; int: [100, Bounds.int]; number: [200, Bounds.number]; string: [250, Bounds.string]; any: [10]; boolean: [15]; date: [20]; file: [25]; nan: [30]; never: [35]; null: [40]; undefined: [50]; unknown: [55]; void: [60]; symbol: [45]; }[K]>; }>; /** * ## {@link SeedValidDataGenerator `SeedValidDataGenerator`} * * A seed generator that can be interpreted to produce reliably valid data. * * This was originally developed to test for parity between various schema libraries. * * To use it, you'll need to have [fast-check](https://github.com/dubzzz/fast-check) installed. * * Note that certain schemas make generating valid data impossible * (like {@link z.never `z.never`}) or or prohibitively difficult * (like {@link z.pipe `z.pipe`}). For this reason, those schemas are not seeded. * * To see the list of excluded schemas, see * {@link seedsThatPreventGeneratingValidData `seedsThatPreventGeneratingValidData`}. * * See also: * - {@link SeedInvalidDataGenerator `SeedInvalidDataGenerator`} * * @example * import * as fc from 'fast-check' * import { z } from 'zod' * import { zxTest } from '@traversable/zod-test' * * const [seed] = fc.sample(zxTest.SeedValidDataGenerator, 1) * const ZodSchema = zxTest.seedToSchema(seed) * const dataset = fc.sample(zxTest.seedToValidData(seed), 5) * * const results = dataset.map((data) => ZodSchema.safeParse(data).success) * * console.log(results) // => [true, true, true, true, true] */ export declare const SeedValidDataGenerator: fc.Arbitrary unknown] | [2000, unknown] | [2500, unknown] | [3000, unknown] | [7000, unknown] | [3500, unknown] | [4000, unknown] | [7500, [string, unknown][]] | [8000, unknown[]] | [8500, unknown[]] | [6000, [[7500, [string, unknown][]], [7500, [string, unknown][]]]] | [6500, [unknown, unknown]] | [10000, unknown]>; /** * ## {@link SeedInvalidDataGenerator `zxTest.SeedInvalidDataGenerator`} * * A seed generator that can be interpreted to produce reliably invalid data. * * This was originally developed to test for parity between various schema libraries. * * To use it, you'll need to have [fast-check](https://github.com/dubzzz/fast-check) installed. * * Note that certain schemas make generating invalid data impossible * (like {@link z.any `z.any`}) or prohibitively difficult * (like {@link z.catch `z.catch`}). For this reason, those schemas are not seeded. * * To see the list of excluded schemas, see * {@link seedsThatPreventGeneratingInvalidData `zxTest.seedsThatPreventGeneratingInvalidData`}. * * See also: * - {@link SeedValidDataGenerator `zxTest.SeedValidDataGenerator`} * * @example * import * as fc from 'fast-check' * import { z } from 'zod' * import { zxTest } from '@traversable/zod-test' * * const [seed] = fc.sample(zxTest.SeedInvalidDataGenerator, 1) * const ZodSchema = zxTest.seedToSchema(seed) * const dataset = fc.sample(zxTest.seedToInvalidData(seed), 5) * * const results = dataset.map((data) => ZodSchema.safeParse(data).success) * * console.log(results) // => [false, false, false, false, false] */ export declare const SeedInvalidDataGenerator: fc.Arbitrary<[1000, unknown, Bounds.array] | [7000, unknown] | [7500, [string, unknown][]] | [8000, unknown[]]>; /** * ## {@link SchemaGenerator `zxTest.SchemaGenerator`} * * A zod schema generator that can be interpreted to produce an arbitrary `zod` schema (v4, classic). * * The generator supports a wide range of configuration options that are discoverable via the * optional `options` argument. * * Many of those options are forwarded to the corresponding `fast-check` arbitrary. * * To use it, you'll need to have [`fast-check`](https://github.com/dubzzz/fast-check) installed. * * See also: * - {@link SeedGenerator `zxTest.SeedGenerator`} * * @example * import * as fc from 'fast-check' * import { z } from 'zod' * import { zxTest } from '@traversable/zod-test' * * const tenSchemas = fc.sample(zxTest.SchemaGenerator({ * include: ['null', 'boolean', 'number', 'string', 'array', 'object'] * }), 10) * * tenSchemas.forEach((s) => console.log(zxTest.toString(s))) * // => z.number() * // => z.string().max(64) * // => z.null() * // => z.array(z.boolean()) * // => z.boolean() * // => z.object({ "": z.object({ "/d2P} {/": z.boolean() }), "svH2]L'x": z.number().lt(-65536) }) * // => z.null() * // => z.string() * // => z.array(z.array(z.null())) * // => z.object({ "y(Qza": z.boolean(), "G1S\\U 4Y6i": z.object({ "YtO3]ia0cM": z.boolean() }) }) */ export declare const SchemaGenerator: unknown]; nonoptional: [1500, unknown]; nullable: [2000, unknown]; optional: [2500, unknown]; readonly: [3000, unknown]; record: [7000, unknown]; set: [3500, unknown]; success: [4000, unknown]; object: [7500, [string, unknown][]]; tuple: [8000, unknown[]]; union: [8500, unknown[]]; intersection: [6000, [[7500, [string, unknown][]], [7500, [string, unknown][]]]]; map: [6500, [unknown, unknown]]; pipe: [9000, [unknown, unknown]]; transform: [10000, unknown]; promise: [100000, unknown]; enum: [500, any]; literal: [550, string | number | bigint | boolean]; template_literal: Seed.TemplateLiteral; bigint: [150, Bounds.bigint]; int: [100, Bounds.int]; number: [200, Bounds.number]; string: [250, Bounds.string]; any: [10]; boolean: [15]; date: [20]; file: [25]; nan: [30]; never: [35]; null: [40]; undefined: [50]; unknown: [55]; void: [60]; symbol: [45]; }>>(options?: Options | undefined, overrides?: Partial unknown]; nonoptional: [1500, unknown]; nullable: [2000, unknown]; optional: [2500, unknown]; readonly: [3000, unknown]; record: [7000, unknown]; set: [3500, unknown]; success: [4000, unknown]; object: [7500, [string, unknown][]]; tuple: [8000, unknown[]]; union: [8500, unknown[]]; intersection: [6000, [[7500, [string, unknown][]], [7500, [string, unknown][]]]]; map: [6500, [unknown, unknown]]; pipe: [9000, [unknown, unknown]]; transform: [10000, unknown]; promise: [100000, unknown]; enum: [500, any]; literal: [550, string | number | bigint | boolean]; template_literal: Seed.TemplateLiteral; bigint: [150, Bounds.bigint]; int: [100, Bounds.int]; number: [200, Bounds.number]; string: [250, Bounds.string]; any: [10]; boolean: [15]; date: [20]; file: [25]; nan: [30]; never: [35]; null: [40]; undefined: [50]; unknown: [55]; void: [60]; symbol: [45]; }, Config.byTypeName>> | undefined) => fc.Arbitrary>>; export declare namespace SchemaGenerator { type Options = Config.Options; } /** * ## {@link seedToSchema `zxTest.seedToSchema`} * * Interpreter that converts a seed value into the corresponding zod schema. * * To get a seed, use {@link SeedGenerator `zxTest.SeedGenerator`}. */ export declare function seedToSchema(seed: T): Seed.schemaFromComposite[T[0]]; export declare function seedToSchema(seed: Seed.F): z.ZodType; /** * ## {@link seedToValidData `seedToValidData`} * * Given a seed, generates an single example of valid data. * * Valid in this context means that it will always satisfy the zod schema that the seed produces. * * To use it, you'll need to have [fast-check](https://github.com/dubzzz/fast-check) installed. * * To convert a seed to a zod schema, use {@link seedToSchema `seedToSchema`}. * * To convert a seed to a single example of _invalid_ data, use {@link seedToInvalidData `seedToInvalidData`}. */ export declare const seedToValidData: (seed: Seed.F, options?: Config.Options | undefined) => unknown; /** * ## {@link seedToInvalidData `seedToInvalidData`} * * Given a seed, generates an single example of invalid data. * * Invalid in this context means that it will never satisfy the zod schema that the seed produces. * * To use it, you'll need to have [fast-check](https://github.com/dubzzz/fast-check) installed. * * To convert a seed to a zod schema, use {@link seedToSchema `seedToSchema`}. * * To convert a seed to a single example of _valid_ data, use {@link seedToValidData `seedToValidData`}. */ export declare const seedToInvalidData: (seed: Seed.F, options?: Config.Options | undefined) => unknown; export {}; //# sourceMappingURL=generator.d.ts.map