/* eslint-disable @typescript-eslint/ban-types */ // tracing: off import type { Refinement } from "@effect-ts/system/Function" import type * as fc from "fast-check" import type { ParserEnv } from "../Parser.js" import type * as Th from "../These.js" import type { Annotation } from "./annotation.js" import type { AnyError } from "./error.js" import type { ApiSelfType, Schema, SchemaAny } from "./schema.js" import { SchemaAnnotated, SchemaArbitrary, SchemaConstructor, SchemaEncoder, SchemaGuard, SchemaIdentity, SchemaMapApi, SchemaMapConstructorError, SchemaMapParserError, SchemaNamed, SchemaParser, SchemaPipe, SchemaRefinement } from "./schema.js" export function opaque() { return ( schema: Schema ): Schema> => schema as any } export function named(name: Name) { return ( self: Schema ): Schema => new SchemaNamed(self, name) } export function identity(guard: (_: unknown) => _ is A): Schema { return new SchemaIdentity(guard) } export function constructor< NewConstructorInput, ParserInput, ParsedShape, ConstructorInput, Encoded, Api >(f: (_: NewConstructorInput) => Th.These) { return ( self: Schema ): Schema => new SchemaConstructor(self, f) } export function constructor_< NewConstructorInput, ParserInput, ParsedShape, ConstructorInput, Encoded, Api >( self: Schema, f: (_: NewConstructorInput) => Th.These ): Schema { return new SchemaConstructor(self, f) } export function parser< NewParserInput, ParserInput, ParsedShape, ConstructorInput, Encoded, Api >(f: (_: NewParserInput, env?: ParserEnv) => Th.These) { return ( self: Schema ): Schema => new SchemaParser(self, f) } export function parser_< NewParserInput, ParserInput, ParsedShape, ConstructorInput, Encoded, Api >( self: Schema, f: (_: NewParserInput) => Th.These ): Schema { return new SchemaParser(self, f) } export function arbitrary( f: (_: typeof fc) => fc.Arbitrary ) { return ( self: Schema ): Schema => new SchemaArbitrary(self, f) as any } export function arbitrary_( self: Schema, f: (_: typeof fc) => fc.Arbitrary ): Schema { return new SchemaArbitrary(self, f) } export function encoder(f: (_: ParsedShape) => A) { return ( self: Schema ): Schema => new SchemaEncoder(self, f) } export function encoder_( self: Schema, f: (_: ParsedShape) => A ): Schema { return new SchemaEncoder(self, f) } export function refine< E extends AnyError, NewParsedShape extends ParsedShape, ParsedShape >( refinement: Refinement, error: (value: ParsedShape) => E ): ( self: Schema ) => Schema { return self => new SchemaRefinement(self, refinement, error) } export function mapParserError( f: (e: E) => E1 ) { return ( self: Schema ): Schema => new SchemaMapParserError(self, f) } export function mapConstructorError( f: (e: E) => E1 ) { return ( self: Schema ): Schema => new SchemaMapConstructorError(self, f) } export function mapApi(f: (e: E) => E1) { return ( self: Schema ): Schema => new SchemaMapApi(self, f) } export function identified_< ParserInput, ParsedShape, ConstructorInput, Encoded, Api, Meta >( self: Schema, identifier: Annotation, meta: Meta ): Schema { return new SchemaAnnotated(self, identifier, meta) } export function annotate( annotation: Annotation, meta: Meta ): < Self extends SchemaAny & { readonly annotate: (annotation: Annotation, meta: Meta) => SchemaAny } >( self: Self ) => ReturnType { // @ts-expect-error return self => self.annotate(annotation, meta) } export function guard_( self: Schema, guard: (u: unknown) => u is ParsedShape ): Schema { return new SchemaGuard(self, guard) } export function guard( guard: (u: unknown) => u is ParsedShape ): ( self: Schema ) => Schema { return self => new SchemaGuard(self, guard) } export function into_< ParserInput, ParsedShape, ConstructorInput, Encoded, Api, ThatParsedShape, ThatConstructorInput, ThatApi >( self: Schema, that: Schema ): Schema { return new SchemaPipe(self, that) } export function into( that: Schema ): ( self: Schema ) => Schema { return self => new SchemaPipe(self, that) }