import * as fc from 'fast-check'; import type * as T from '@traversable/registry'; import { URI } from '@traversable/registry'; import { Json } from '@traversable/json'; import type { SchemaOptions } from '@traversable/schema'; import { t } from '@traversable/schema'; import type { ArrayBounds, BigIntBounds, ExclusiveBounds, InclusiveBounds, IntegerBounds, NumberBounds, StringBounds } from './bounds.js'; export { type Arbitraries, type Builder, type Constraints, type Fixpoint, type Free, type Nullary, type Positional, type Seed, type SortBias, type SpecialCase, type TypeName, type Unary, integerF as integer, bigintF as bigint, numberF as number, stringF as string, eqF as eq, refF as ref, optionalF as optional, arrayF as array, recordF as record, unionF as union, intersectF as intersect, objectF as object, tupleF as tuple, data, defaults, defineSeed, extensibleArbitrary, fold, fromJsonLiteral, fromSchema, Functor, getBounds, identity, initialOrder, is, isBoundable, isBoundableTag, isAssociative, isNullary, isPositional, isSeed, isSpecialCase, isUnary, laxMax, laxMin, numberConstraintsFromBounds, preprocessInclusiveBounds, parseConstraints, Algebra, schema, schemaWithMinDepth, seed, stringConstraintsFromBounds, arbitraryFromSchema, invalidArbitraryFromSchema, invalidValue, toArbitrary, toInvalidArbitrary, toSchema, toString, unfold, }; declare const invalidValue: any; interface SeedWithRoot> extends T.newtype { tree: T[keyof T]; root: fc.Arbitrary; } type WithRoot = never | SeedWithRoot>; type SeedIR = { eq: fc.Arbitrary>; array: fc.Arbitrary>; record: fc.Arbitrary>; optional: fc.Arbitrary>; tuple: fc.Arbitrary>; object: fc.Arbitrary>; union: fc.Arbitrary>; intersect: fc.Arbitrary>; never: fc.Arbitrary; any: fc.Arbitrary; unknown: fc.Arbitrary; void: fc.Arbitrary; null: fc.Arbitrary; undefined: fc.Arbitrary; symbol: fc.Arbitrary; boolean: fc.Arbitrary; integer: fc.Arbitrary; bigint: fc.Arbitrary; number: fc.Arbitrary; string: fc.Arbitrary; }; export declare const LEAST_UPPER_BOUND = 4294967296; export declare const GREATEST_LOWER_BOUND = 1e-8; export declare const isBounded: (x: number) => boolean; export type UniqueArrayDefaults = fc.UniqueArrayConstraintsRecommended; declare namespace InferSchema { type SchemaMap = { [URI.never]: t.never; [URI.any]: t.any; [URI.unknown]: t.unknown; [URI.void]: t.void; [URI.null]: t.null; [URI.undefined]: t.undefined; [URI.boolean]: t.boolean; [URI.symbol]: t.symbol; [URI.integer]: t.integer; [URI.bigint]: t.bigint; [URI.number]: t.number; [URI.string]: t.string; [URI.eq]: t.eq; [URI.array]: t.array; [URI.optional]: t.optional; [URI.record]: t.record; [URI.union]: t.union; [URI.intersect]: t.intersect; [URI.tuple]: t.tuple; [URI.object]: t.object; }; type LookupSchema = SchemaMap[(T extends Boundable ? T[0] : T) & keyof SchemaMap]; type CatchUnknown = unknown extends T ? SchemaMap[keyof SchemaMap] : T; type fromFixpoint = CatchUnknown : [Head, Tail] extends [URI.optional, Fixpoint] ? t.optional> : [Head, Tail] extends [URI.array, Fixpoint] ? t.array> : [Head, Tail] extends [URI.record, Fixpoint] ? t.record> : [Head, Tail] extends [URI.union, Fixpoint[]] ? t.union<{ [I in keyof Tail]: LookupSchema; }> : [Head, Tail] extends [URI.intersect, Fixpoint[]] ? t.intersect<{ [I in keyof Tail]: LookupSchema; }> : [Head, Tail] extends [URI.tuple, Fixpoint[]] ? t.tuple<{ [I in keyof Tail]: LookupSchema; }> : [Head, Tail] extends [URI.object, infer Entries extends [k: string, v: any][]] ? t.object<{ [E in Entries[number] as E[0]]: LookupSchema; }> : LookupSchema : unknown>; } /** * If you provide a partial weight map, missing properties will fall back to `0` */ type SortBias = T.Comparator | { [K in keyof T]+?: number; }; type TypeName = Exclude; declare const initialOrderMap: { readonly string: 0; readonly number: 1; readonly object: 2; readonly boolean: 3; readonly undefined: 4; readonly symbol: 5; readonly integer: 6; readonly bigint: 7; readonly null: 8; readonly eq: 9; readonly array: 9; readonly record: 10; readonly optional: 11; readonly tuple: 12; readonly intersect: 13; readonly union: 14; readonly any: 15; readonly unknown: 16; readonly void: 17; readonly never: 18; }; declare const initialOrder: (keyof typeof initialOrderMap)[]; type LibConstraints = { rootType?: Root; minDepth?: number; sortBias?: SortBias; exclude?: Exclude[]; include?: Include[]; forceInvalid?: boolean; }; type ObjectConstraints = { min?: number; max?: number; } & Omit; type Arbitraries = { never?: unknown; unknown?: unknown; void?: unknown; any?: unknown; undefined?: unknown; null?: unknown; symbol?: unknown; boolean?: unknown; integer?: unknown; number?: unknown; bigint?: unknown; string?: unknown; eq?(x: unknown, $?: SchemaOptions): unknown; ref?(x: unknown, id?: string, $?: SchemaOptions): unknown; array?(x: unknown, $?: SchemaOptions): unknown; record?(x: unknown, $?: SchemaOptions): unknown; optional?(x: unknown, $?: SchemaOptions): unknown; union?(x: readonly unknown[], $?: SchemaOptions): unknown; intersect?(x: readonly unknown[], $?: SchemaOptions): unknown; tuple?(x: readonly unknown[], $?: SchemaOptions): unknown; object?(x: { [x: string]: unknown; }, $?: SchemaOptions): unknown; }; type Constraints = LibConstraints & { arbitraries?: Arbitraries; integer?: TargetConstraints['integer']; bigint?: TargetConstraints['bigint']; number?: TargetConstraints['number']; string?: TargetConstraints['string']; array?: TargetConstraints['array']; union?: TargetConstraints['union']; intersect?: TargetConstraints['intersect']; tree?: TargetConstraints['tree']; object?: ObjectConstraints; tuple?: TargetConstraints['tuple']; eq?: TargetConstraints['eq']; }; type Seed = Nullary | Boundable | refF | eqF | arrayF | recordF | optionalF | tupleF | unionF | intersectF | objectF<[k: string, v: F][]>; type Fixpoint = Nullary | Boundable | refF | eqF | arrayF | recordF | optionalF | tupleF | unionF | intersectF | objectF<[k: string, v: Fixpoint][]>; interface Free extends T.HKT { [-1]: Seed; } type Inductive = [S] extends [infer T extends Nullary] ? T : [S] extends [readonly [Unary, infer T]] ? [tag: S[0], unary: Inductive] : [S] extends [readonly [Positional, infer T extends readonly unknown[]]] ? [S[0], { -readonly [Ix in keyof T]: Inductive; }] : [S] extends [readonly [Associative, infer T extends readonly [k: string, v: unknown][]]] ? [S[0], { -readonly [Ix in keyof T]: [k: T[Ix][0], v: Inductive]; }] : T.TypeError<'Expected: Fixpoint'>; interface Builder { never: neverF; any: anyF; unknown: unknownF; void: voidF; null: nullF; undefined: undefinedF; symbol: symbolF; boolean: booleanF; bigint: bigintF; integer: integerF; number: numberF; string: stringF; eq: eqF; array: arrayF; record: recordF; optional: optionalF; tuple: tupleF; union: unionF; intersect: intersectF; object: objectF<[k: string, Fixpoint][]>; tree: Omit[keyof Omit]; } declare namespace Seed { export { Builder, Free, Fixpoint, Inductive, Nullary, }; } declare const defaults: { sortBias: () => number; include: ("string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "never" | "any" | "unknown" | "void" | "null" | "integer" | "eq" | "array" | "record" | "optional" | "tuple" | "union" | "intersect")[]; exclude: []; forceInvalid: false; arbitraries: {}; minDepth: number; rootType: "tree"; integer: { min: number; max: number; }; bigint: { min: bigint; max: bigint; }; number: { min: number; max: number; noNaN: true; noDefaultInfinity: true; }; string: { min: number; max: number; }; array: { min: number; max: number; }; union: { readonly minLength: 2; readonly maxLength: 2; readonly size: "xsmall"; }; intersect: { readonly minLength: 1; readonly maxLength: 2; readonly size: "xsmall"; readonly depthIdentifier: fc.DepthContext; }; tuple: { readonly minLength: 1; readonly maxLength: 3; readonly size: "xsmall"; readonly depthIdentifier: fc.DepthContext; }; object: { min: number; max: number; size: "xsmall"; }; eq: { jsonArbitrary: fc.Arbitrary; }; tree: { readonly maxDepth: 3; readonly depthIdentifier: fc.DepthContext; readonly depthSize: "xsmall"; readonly withCrossShrink: false; }; }; interface neverF extends T.newtype { } interface anyF extends T.newtype { } interface unknownF extends T.newtype { } interface voidF extends T.newtype { } interface nullF extends T.newtype { } interface undefinedF extends T.newtype { } interface booleanF extends T.newtype { } interface symbolF extends T.newtype { } interface integerF extends T.newtype<[tag: URI.integer, constraints?: IntegerBounds]> { } interface bigintF extends T.newtype<[tag: URI.bigint, constraints?: BigIntBounds]> { } interface numberF extends T.newtype<[tag: URI.number, constraints?: NumberBounds]> { } interface stringF extends T.newtype<[tag: URI.string, constraints?: StringBounds]> { } interface arrayF extends T.newtype<[tag: URI.array, def: S, constraints?: ArrayBounds]> { } declare function integerF(constraints?: IntegerBounds): integerF; declare function bigintF(constraints?: BigIntBounds): bigintF; declare function numberF(constraints?: NumberBounds): numberF; declare function stringF(constraints?: StringBounds): stringF; declare function arrayF(def: S, constraints?: ArrayBounds): arrayF; interface eqF extends T.newtype<[tag: URI.eq, def: S]> { } interface refF extends T.newtype<[tag: URI.ref, def: S, id: string]> { } interface optionalF extends T.newtype<[tag: URI.optional, def: S]> { } interface recordF extends T.newtype<[tag: URI.record, def: S]> { } interface objectF extends T.newtype<[tag: URI.object, def: S]> { } interface tupleF extends T.newtype<[tag: URI.tuple, def: S]> { } interface unionF extends T.newtype<[tag: URI.union, def: S]> { } interface intersectF extends T.newtype<[tag: URI.intersect, def: S]> { } declare function eqF(def: V): eqF; declare function refF(def: S, id: string): refF; declare function optionalF(def: S): optionalF; declare function recordF(def: S): recordF; declare function objectF(def: readonly [...S]): objectF<[...S]>; declare function tupleF(def: readonly [...S]): tupleF; declare function unionF(def: readonly [...S]): unionF; declare function intersectF(def: readonly [...S]): intersectF; type Nullary = typeof NullaryTags[number]; declare const NullaryTags: ["@traversable/schema/URI::never", "@traversable/schema/URI::any", "@traversable/schema/URI::unknown", "@traversable/schema/URI::void", "@traversable/schema/URI::undefined", "@traversable/schema/URI::null", "@traversable/schema/URI::boolean", "@traversable/schema/URI::symbol"]; declare const isNullary: (u: unknown) => u is Nullary; declare const laxMin: (...xs: (number | undefined)[]) => number | undefined; declare const laxMax: (...xs: (number | undefined)[]) => number | undefined; declare const preprocessInclusiveBounds: ({ minimum, maximum }: InclusiveBounds) => InclusiveBounds | undefined; type Boundable = integerF | bigintF | numberF | stringF; type BoundableTag = typeof BoundableTags[number]; declare const BoundableTags: ["@traversable/schema/URI::bigint", "@traversable/schema/URI::integer", "@traversable/schema/URI::number", "@traversable/schema/URI::string"]; declare const isBoundableTag: (u: unknown) => u is BoundableTag; declare const isBoundable: (u: unknown) => u is Boundable; type SpecialCase = [SpecialCaseTag, T]; type SpecialCaseTag = typeof SpecialCaseTags[number]; declare const SpecialCaseTags: ["@traversable/schema/URI::eq"]; declare const isSpecialCase: (u: unknown) => u is SpecialCase; type Unary = arrayF | recordF | optionalF; declare const isUnary: (u: unknown) => u is Unary; type Positional = tupleF | unionF | intersectF; declare const isPositional: (u: unknown) => u is Positional; type Associative = [AssociativeTag, [k: string, v: T][]]; type AssociativeTag = typeof AssociativeTags[number]; declare const AssociativeTags: ["@traversable/schema/URI::object"]; declare const isAssociative: (u: unknown) => u is Associative; declare const isSeed: (u: unknown) => u is unknown; /** * ## {@link is `is`} * * Type-guard from `unknown` to {@link Seed `Seed`}. * * The {@link is `is`} function is also an object whose properties narrow * to a particular member or subset of members of {@link Seed `Seed`}. */ declare function is(u: unknown): boolean; declare namespace is { export var nullary: (u: unknown) => u is Nullary; export var unary: (u: unknown) => u is Unary; export var positional: (u: unknown) => u is Positional; export var associative: (u: unknown) => u is Associative; export var special: (u: unknown) => u is SpecialCase; export var never: (u: unknown) => u is "@traversable/schema/URI::never"; export var any: (u: unknown) => u is "@traversable/schema/URI::any"; export var unknown: (u: unknown) => u is "@traversable/schema/URI::unknown"; var _a: (u: unknown) => u is "@traversable/schema/URI::void"; var _b: (u: unknown) => u is "@traversable/schema/URI::null"; export var undefined: (u: unknown) => u is "@traversable/schema/URI::undefined"; export var boolean: (u: unknown) => u is "@traversable/schema/URI::boolean"; export var symbol: (u: unknown) => u is "@traversable/schema/URI::symbol"; export var string: t.has<[0], t.of<(u: unknown) => u is "@traversable/schema/URI::string">>; export var number: t.has<[0], t.of<(u: unknown) => u is "@traversable/schema/URI::number">>; export var integer: t.has<[0], t.of<(u: unknown) => u is "@traversable/schema/URI::integer">>; export var bigint: t.has<[0], t.of<(u: unknown) => u is "@traversable/schema/URI::bigint">>; export var eq: (u: unknown) => u is [tag: URI.eq, def: T]; export var array: (u: unknown) => u is [tag: URI.array, T]; export var optional: (u: unknown) => u is [tag: URI.optional, T]; export var record: (u: unknown) => u is [tag: URI.record, T]; export var union: (u: unknown) => u is [tag: URI.union, readonly T[]]; export var intersect: (u: unknown) => u is [tag: URI.intersect, readonly T[]]; export var tuple: (u: unknown) => u is [tag: URI.tuple, readonly T[]]; export var object: (u: unknown) => u is [tag: URI.tuple, { [x: string]: T; }]; export { _a as void, _b as null }; } /** * Hand-tuned constructor that gives you both more precise and * more localized feedback than the TS compiler when you make a mistake * in an inline {@link Seed `Seed`} definition. * * When you're working with deeply nested tuples where only certain sequences * are valid constructions, this turns out to be pretty useful / necessary. */ declare function defineSeed>(seed: T): T; declare const numberConstraintsFromBounds: (bounds?: InclusiveBounds & ExclusiveBounds) => fc.DoubleConstraints; declare const stringConstraintsFromBounds: ({ minimum: min, maximum: max }?: InclusiveBounds) => fc.StringConstraints; declare const Functor: T.Functor; type Index = { mode: 'INVALID' | 'VALID'; invalidGeneratedForLevel: boolean; }; declare const fold: (algebra: T.Algebra) => (term: S) => T; declare const unfold: (coalgebra: T.Coalgebra) => (expr: S) => Seed; type t_Boundable = t.Boundable | t.array; declare function getBounds(x: t_Boundable): (IntegerBounds & NumberBounds & BigIntBounds & StringBounds) | undefined; export declare const sortOptionalsLast: (l: unknown, r: unknown) => 1 | 0 | -1; export declare const pickAndSortNodes: (nodes: readonly TypeName[]) => (constraints?: Pick, 'exclude' | 'include' | 'sortBias'>) => TypeName[]; declare function parseConstraints(constraints?: Constraints): Required>; export declare const toJson: (seed: Seed.Fixpoint) => Json.Fixpoint; declare const schemaWithMinDepth: (_: Constraints | undefined, n: number) => fc.Arbitrary | t.array | t.optional | t.record | t.union | t.intersect | t.tuple | t.object>; declare function seed>>(constraints?: Constraints): (go: fc.LetrecTypedTie) => Build; declare namespace Algebra { const identity: T.Functor.Algebra; const toExtensibleSchema: (constraints?: Constraints['arbitraries']) => T.Functor.Algebra; const toSchema: T.Functor.Algebra; const fromSchema: T.Functor.Algebra; const toArbitrary: T.Functor.Algebra>; const arbitraryFromSchema: T.Functor.Algebra>; const invalidArbitraryFromSchema: T.Functor.Algebra>; const toInvalidArbitrary: T.Functor.Algebra>; const toString: T.Functor.Algebra; const fromJsonLiteral: T.Functor.Algebra; } declare const identity: (term: S) => Fixpoint; declare const toSchema: >(seed: T) => InferSchema.fromFixpoint; declare const toArbitrary: (term: S) => fc.Arbitrary; declare const arbitraryFromSchema: { (src: t.F>, ix?: t.Functor.Index | undefined): fc.Arbitrary; (src: t.Schema>, ix?: t.Functor.Index | undefined): fc.Arbitrary; (src: t.F>, ix?: t.Functor.Index | undefined): fc.Arbitrary; }; declare const invalidArbitraryFromSchema: { (src: t.F>, ix?: t.Functor.Index | undefined): fc.Arbitrary; (src: t.Schema>, ix?: t.Functor.Index | undefined): fc.Arbitrary; (src: t.F>, ix?: t.Functor.Index | undefined): fc.Arbitrary; }; declare const toInvalidArbitrary: (term: S, ix: Index) => fc.Arbitrary; declare const toString: (term: S) => string; declare const fromSchema: >>(term: S) => Fixpoint; declare const fromJsonLiteral: (term: S) => Fixpoint; /** * ## {@link schema `Seed.schema`} * * Generates an arbitrary, * [pseudo-random](https://en.wikipedia.org/wiki/Pseudorandomness) * {@link t `t`} schema. * * Internally, schemas are generated from a * {@link Seed `seed value`}, which is itself generated by a library * called [`fast-check`](https://github.com/dubzzz/fast-check). */ declare function schema(constraints?: Constraints): fc.Arbitrary, { tag: `${T.NS}${Exclude}`; }>>; declare function schema(constraints?: Constraints): fc.Arbitrary; declare const extensibleArbitrary: (constraints?: Constraints) => fc.Arbitrary; /** * ## {@link data `Seed.data`} * * Generates an arbitrary, * [pseudo-random](https://en.wikipedia.org/wiki/Pseudorandomness) * data generator. * * Internally, schemas are generated from a * {@link Seed `seed value`}, which is itself generated by a library * called [`fast-check`](https://github.com/dubzzz/fast-check). */ declare const data: (constraints?: Constraints) => fc.Arbitrary; export declare const REG_EXP: { alphanumeric: RegExp; ident: RegExp; exponential: RegExp; }; export declare const floatConstraints: { noDefaultInfinity: true; min: number; max: number; }; export declare const getExponential: (x: number) => number; export declare const toFixed: (x: number) => number; export declare const alphanumeric: fc.Arbitrary; export declare const int32toFixed: fc.Arbitrary; export declare const ident: fc.Arbitrary; export declare const jsonValue: fc.LetrecValue; export type DefaultSchemas = never | Exclude, { tag: `${T.NS}${typeof defaults.exclude[number]}`; }>; export type Options = { rootType?: keyof Builder; exclude?: [TypeName] extends [never] ? [] : TypeName[]; jsonArbitrary?: fc.Arbitrary; minDepth?: number; }; interface JsonBuilder { null: null; boolean: boolean; number: number; string: string; array: JsonValue[]; object: Record; tree: JsonValue; } type JsonValue = undefined | null | boolean | number | string | JsonValue[] | { [x: string]: JsonValue; }; type ExcludeBy = Exclude, { tag: `${T.NS}${TypeName}`; }>; export declare namespace SchemaGenerator { export { Options }; } export declare function SchemaGenerator(): fc.Arbitrary; export declare function SchemaGenerator(options?: Options): fc.Arbitrary>; export declare const exclude: ["any", "never", "unknown", "void", "intersect", "symbol"]; export declare const generatorDefaults: { exclude: ["any", "never", "unknown", "void", "intersect", "symbol"]; jsonArbitrary: fc.Arbitrary; rootType: "tree"; minDepth: number; }; //# sourceMappingURL=seed.d.ts.map