diff --git a/packages/schema/src/Arbitrary/_arbitrary/index.ts b/packages/schema/src/Arbitrary/_arbitrary/index.ts index 59ee84c..d6be9c8 100644 --- a/packages/schema/src/Arbitrary/_arbitrary/index.ts +++ b/packages/schema/src/Arbitrary/_arbitrary/index.ts @@ -23,29 +23,13 @@ export const interpreters: ((schema: S.SchemaAny) => O.Option<() => Gen } } return miss() - }) + }), ] const cache = new WeakMap() -function for_< - ParserInput, - ParserError extends S.AnyError, - ParsedShape, - ConstructorInput, - ConstructorError extends S.AnyError, - Encoded, - Api ->( - schema: S.Schema< - ParserInput, - ParserError, - ParsedShape, - ConstructorInput, - ConstructorError, - Encoded, - Api - > +function for_( + schema: S.Schema ): Gen { if (cache.has(schema)) { return cache.get(schema) diff --git a/packages/schema/src/Collect/_collect/index.ts b/packages/schema/src/Collect/_collect/index.ts index 8488c37..c473b70 100644 --- a/packages/schema/src/Collect/_collect/index.ts +++ b/packages/schema/src/Collect/_collect/index.ts @@ -58,29 +58,19 @@ export const interpreters: ((schema: S.SchemaAny) => O.Option<() => any>)[] = [ return () => collectAnnotationsFor(schema.self) } return miss() - }) + }), ] const cache = new WeakMap() export function collectAnnotationsFor< ParserInput, - ParserError extends S.AnyError, ParsedShape, ConstructorInput, - ConstructorError extends S.AnyError, Encoded, Api >( - schema: S.Schema< - ParserInput, - ParserError, - ParsedShape, - ConstructorInput, - ConstructorError, - Encoded, - Api - > + schema: S.Schema ): CollectAnnotations { if (cache.has(schema)) { return cache.get(schema) diff --git a/packages/schema/src/Constructor/_constructor/index.ts b/packages/schema/src/Constructor/_constructor/index.ts index ca7b898..075938b 100644 --- a/packages/schema/src/Constructor/_constructor/index.ts +++ b/packages/schema/src/Constructor/_constructor/index.ts @@ -68,30 +68,14 @@ export const interpreters: (( } } return miss() - }) + }), ] const cache = new WeakMap() -function constructorFor< - ParserInput, - ParserError extends S.AnyError, - ParsedShape, - ConstructorInput, - ConstructorError extends S.AnyError, - Encoded, - Api ->( - schema: S.Schema< - ParserInput, - ParserError, - ParsedShape, - ConstructorInput, - ConstructorError, - Encoded, - Api - > -): Constructor { +function constructorFor( + schema: S.Schema +): Constructor { if (cache.has(schema)) { return cache.get(schema) } @@ -99,7 +83,7 @@ function constructorFor< const of_: Constructor = (__) => constructorFor(schema.self())(__) cache.set(schema, of_) - return of_ as Constructor + return of_ as Constructor } for (const interpreter of interpreters) { const _ = interpreter(schema) @@ -112,7 +96,7 @@ function constructorFor< return x(__) } cache.set(schema, of_) - return of_ as Constructor + return of_ as Constructor } } if (hasContinuation(schema)) { @@ -123,7 +107,7 @@ function constructorFor< } return x(__) } - return of_ as Constructor + return of_ as Constructor } throw new Error(`Missing guard integration for: ${JSON.stringify(schema)}`) } diff --git a/packages/schema/src/Encoder/_encoder/index.ts b/packages/schema/src/Encoder/_encoder/index.ts index 8abbe05..548ec50 100644 --- a/packages/schema/src/Encoder/_encoder/index.ts +++ b/packages/schema/src/Encoder/_encoder/index.ts @@ -28,29 +28,13 @@ export const interpreters: (( return () => schema.encoder } return miss() - }) + }), ] const cache = new WeakMap() -function encoderFor< - ParserInput, - ParserError extends S.AnyError, - ParsedShape, - ConstructorInput, - ConstructorError extends S.AnyError, - Encoded, - Api ->( - schema: S.Schema< - ParserInput, - ParserError, - ParsedShape, - ConstructorInput, - ConstructorError, - Encoded, - Api - > +function encoderFor( + schema: S.Schema ): Encoder { if (cache.has(schema)) { return cache.get(schema) diff --git a/packages/schema/src/Guard/_guard/index.ts b/packages/schema/src/Guard/_guard/index.ts index e9163ca..4e09993 100644 --- a/packages/schema/src/Guard/_guard/index.ts +++ b/packages/schema/src/Guard/_guard/index.ts @@ -23,29 +23,13 @@ export const interpreters: ((schema: S.SchemaAny) => O.Option<() => Guard( - schema: S.Schema< - ParserInput, - ParserError, - ParsedShape, - ConstructorInput, - ConstructorError, - Encoded, - Api - > +function guardFor( + schema: S.Schema ): Guard { if (cache.has(schema)) { return cache.get(schema) diff --git a/packages/schema/src/Parser/_parser/index.ts b/packages/schema/src/Parser/_parser/index.ts index 85b7a4e..aca047b 100644 --- a/packages/schema/src/Parser/_parser/index.ts +++ b/packages/schema/src/Parser/_parser/index.ts @@ -99,30 +99,14 @@ export const interpreters: (( } } return miss() - }) + }), ] const cache = new WeakMap() -function parserFor< - ParserInput, - ParserError extends S.AnyError, - ParsedShape, - ConstructorInput, - ConstructorError extends S.AnyError, - Encoded, - Api ->( - schema: Schema< - ParserInput, - ParserError, - ParsedShape, - ConstructorInput, - ConstructorError, - Encoded, - Api - > -): Parser { +function parserFor( + schema: Schema +): Parser { if (cache.has(schema)) { return cache.get(schema) } @@ -130,7 +114,7 @@ function parserFor< const parser: Parser = (__) => parserFor(schema.self())(__) cache.set(schema, parser) - return parser as Parser + return parser as Parser } for (const interpreter of interpreters) { const _ = interpreter(schema) @@ -142,7 +126,7 @@ function parserFor< } return x(__) } - return parser as Parser + return parser as Parser } } if (hasContinuation(schema)) { @@ -154,7 +138,7 @@ function parserFor< return x(__) } cache.set(schema, parser) - return parser as Parser + return parser as Parser } throw new Error(`Missing parser integration for: ${schema.constructor}`) } diff --git a/packages/schema/src/_api/array.ts b/packages/schema/src/_api/array.ts index c321625..c483776 100644 --- a/packages/schema/src/_api/array.ts +++ b/packages/schema/src/_api/array.ts @@ -14,32 +14,12 @@ import { withDefaults } from "./withDefaults" export const arrayIdentifier = S.makeAnnotation<{ self: S.SchemaUPI }>() -export function array< - ParserError extends S.AnyError, - ParsedShape, - ConstructorInput, - ConstructorError extends S.AnyError, - Encoded, - Api ->( - self: S.Schema< - unknown, - ParserError, - ParsedShape, - ConstructorInput, - ConstructorError, - Encoded, - Api - > +export function array( + self: S.Schema ): DefaultSchema< unknown, - S.CompositionE< - | S.PrevE>> - | S.NextE>> - >, readonly ParsedShape[], readonly ParsedShape[], - never, readonly Encoded[], { self: Api } > { @@ -58,7 +38,7 @@ export function array< return pipe( chunk(self)[">>>"](fromChunk), - S.mapParserError((_) => Chunk.unsafeHead(_.errors).error), + S.mapParserError((_) => (Chunk.unsafeHead((_ as any).errors) as any).error), S.constructor((_: readonly ParsedShape[]) => Th.succeed(_)), S.encoder((u) => u.map(encodeSelf)), S.mapApi(() => ({ self: self.Api })), diff --git a/packages/schema/src/_api/bool.ts b/packages/schema/src/_api/bool.ts index 14ff527..90ec6b8 100644 --- a/packages/schema/src/_api/bool.ts +++ b/packages/schema/src/_api/bool.ts @@ -1,6 +1,5 @@ import { pipe } from "@effect-ts/core/Function" -import type { ParseBoolE } from "../_schema" import { makeAnnotation, parseBoolE } from "../_schema" import * as S from "../_schema" import * as Th from "../These" @@ -10,15 +9,7 @@ import { withDefaults } from "./withDefaults" export const boolIdentifier = makeAnnotation<{}>() -export const bool: DefaultSchema< - unknown, - S.RefinementE>, - boolean, - boolean, - never, - boolean, - {} -> = pipe( +export const bool: DefaultSchema = pipe( refinement( (u): u is boolean => typeof u === "boolean", (v) => S.leafE(parseBoolE(v)) diff --git a/packages/schema/src/_api/brand.ts b/packages/schema/src/_api/brand.ts index 5a74d95..97e0c7a 100644 --- a/packages/schema/src/_api/brand.ts +++ b/packages/schema/src/_api/brand.ts @@ -1,37 +1,12 @@ // tracing: off -import type * as MO from "../_schema" import type { ApiSelfType, Schema } from "../_schema/schema" import type { DefaultSchema } from "./withDefaults" import { withDefaults } from "./withDefaults" export function brand() { - return < - ParserInput, - ParserError extends MO.AnyError, - ParsedShape, - ConstructorInput, - ConstructorError extends MO.AnyError, - Encoded, - Api - >( - self: Schema< - ParserInput, - ParserError, - ParsedShape, - ConstructorInput, - ConstructorError, - Encoded, - Api - > - ): DefaultSchema< - ParserInput, - ParserError, - B, - ConstructorInput, - ConstructorError, - Encoded, - Api & ApiSelfType - > => { + return ( + self: Schema + ): DefaultSchema> => { // @ts-expect-error return withDefaults(self) } diff --git a/packages/schema/src/_api/chunk.ts b/packages/schema/src/_api/chunk.ts index a3ca439..b070d7d 100644 --- a/packages/schema/src/_api/chunk.ts +++ b/packages/schema/src/_api/chunk.ts @@ -21,25 +21,14 @@ export function fromChunk< ParserError extends S.AnyError, ParsedShape, ConstructorInput, - ConstructorError extends S.AnyError, Encoded, Api >( - self: S.Schema< - ParserInput, - ParserError, - ParsedShape, - ConstructorInput, - ConstructorError, - Encoded, - Api - > + self: S.Schema ): DefaultSchema< readonly ParserInput[], - S.CollectionE>, Chunk.Chunk, Iterable, - never, readonly Encoded[], { self: Api } > { @@ -94,32 +83,12 @@ export function fromChunk< export const chunkIdentifier = makeAnnotation<{ self: S.SchemaAny }>() -export function chunk< - ParserError extends S.AnyError, - ParsedShape, - ConstructorInput, - ConstructorError extends S.AnyError, - Encoded, - Api ->( - self: S.Schema< - unknown, - ParserError, - ParsedShape, - ConstructorInput, - ConstructorError, - Encoded, - Api - > +export function chunk( + self: S.Schema ): DefaultSchema< unknown, - S.CompositionE< - | S.PrevE>> - | S.NextE>> - >, Chunk.Chunk, Iterable, - never, readonly Encoded[], { self: Api } > { diff --git a/packages/schema/src/_api/date.ts b/packages/schema/src/_api/date.ts index ce1b701..0ca779e 100644 --- a/packages/schema/src/_api/date.ts +++ b/packages/schema/src/_api/date.ts @@ -9,15 +9,7 @@ import { withDefaults } from "./withDefaults" export const dateIdentifier = S.makeAnnotation<{}>() -export const date: DefaultSchema< - unknown, - S.LeafE, - Date, - Date, - never, - string, - {} -> = pipe( +export const date: DefaultSchema = pipe( S.identity((u): u is Date => u instanceof Date), S.parser((u: unknown) => { if (typeof u !== "string" || u == null) { @@ -38,15 +30,7 @@ export const date: DefaultSchema< export const dateMsIdentifier = S.makeAnnotation<{}>() -export const dateMs: DefaultSchema< - unknown, - S.LeafE, - Date, - Date, - never, - number, - {} -> = pipe( +export const dateMs: DefaultSchema = pipe( date, S.parser((u) => typeof u === "number" diff --git a/packages/schema/src/_api/ensure.ts b/packages/schema/src/_api/ensure.ts index 1ff33ba..6fd2101 100644 --- a/packages/schema/src/_api/ensure.ts +++ b/packages/schema/src/_api/ensure.ts @@ -1,5 +1,5 @@ import type { Schema } from "../_schema" export function ensureShape() { - return >(self: Self) => self + return >(self: Self) => self } diff --git a/packages/schema/src/_api/int.ts b/packages/schema/src/_api/int.ts index 923f79c..7dd64e9 100644 --- a/packages/schema/src/_api/int.ts +++ b/packages/schema/src/_api/int.ts @@ -17,15 +17,7 @@ export type Int = number & IntBrand export const intFromNumberIdentifier = S.makeAnnotation<{}>() -export const intFromNumber: DefaultSchema< - number, - S.RefinementE>, - Int, - number, - S.RefinementE>, - number, - {} -> = pipe( +export const intFromNumber: DefaultSchema = pipe( fromNumber, S.arbitrary((_) => _.integer()), S.refine( @@ -33,8 +25,8 @@ export const intFromNumber: DefaultSchema< (n) => S.leafE(S.invalidIntegerE(n)) ), S.encoder((_) => _ as number), - S.mapConstructorError((_) => Chunk.unsafeHead(_.errors).error), - S.mapParserError((_) => Chunk.unsafeHead(_.errors).error), + S.mapConstructorError((_) => (Chunk.unsafeHead((_ as any).errors) as any).error), + S.mapParserError((_) => (Chunk.unsafeHead((_ as any).errors) as any).error), S.mapApi(() => ({})), brand(), S.annotate(intFromNumberIdentifier, {}) @@ -44,13 +36,8 @@ export const stringIntFromStringIdentifier = S.makeAnnotation<{}>() export const stringIntFromString: DefaultSchema< string, - S.CompositionE< - | S.NextE>> - | S.PrevE> - >, Int, number, - S.RefinementE>, string, S.ApiSelfType > = pipe( @@ -63,18 +50,8 @@ export const stringIntIdentifier = S.makeAnnotation<{}>() export const stringInt: DefaultSchema< unknown, - S.CompositionE< - | S.PrevE>> - | S.NextE< - S.CompositionE< - | S.NextE>> - | S.PrevE> - > - > - >, Int, number, - S.RefinementE>, string, S.ApiSelfType > = pipe( @@ -85,15 +62,5 @@ export const stringInt: DefaultSchema< export const intIdentifier = S.makeAnnotation<{}>() -export const int: DefaultSchema< - unknown, - S.CompositionE< - | S.NextE>> - | S.PrevE>> - >, - Int, - number, - S.RefinementE>, - number, - S.ApiSelfType -> = pipe(number[">>>"](intFromNumber), brand(), S.annotate(intIdentifier, {})) +export const int: DefaultSchema> = + pipe(number[">>>"](intFromNumber), brand(), S.annotate(intIdentifier, {})) diff --git a/packages/schema/src/_api/intersect.ts b/packages/schema/src/_api/intersect.ts index 56c8ca6..8134a4e 100644 --- a/packages/schema/src/_api/intersect.ts +++ b/packages/schema/src/_api/intersect.ts @@ -25,14 +25,8 @@ export type IntersectionSchema< Api > = DefaultSchema< unknown, - S.IntersectionE< - S.MemberE<0, S.ParserErrorOf> | S.MemberE<1, S.ParserErrorOf> - >, S.ParsedShapeOf & S.ParsedShapeOf, S.ConstructorInputOf & S.ConstructorInputOf, - S.IntersectionE< - S.MemberE<0, S.ConstructorErrorOf> | S.MemberE<1, S.ConstructorErrorOf> - >, S.EncodedOf & S.EncodedOf, Api > @@ -41,43 +35,21 @@ export const intersectIdentifier = S.makeAnnotation<{ self: S.SchemaUPI; that: S.SchemaUPI }>() export function intersect_< - ParserError extends S.AnyError, ParsedShape, ConstructorInput, - ConstructorError extends S.AnyError, Encoded, Api, - ThatParserError extends S.AnyError, ThatParsedShape, ThatConstructorInput, - ThatConstructorError extends S.AnyError, ThatEncoded, ThatApi >( - self: S.Schema< - unknown, - ParserError, - ParsedShape, - ConstructorInput, - ConstructorError, - Encoded, - Api - >, - that: S.Schema< - unknown, - ThatParserError, - ThatParsedShape, - ThatConstructorInput, - ThatConstructorError, - ThatEncoded, - ThatApi - > + self: S.Schema, + that: S.Schema ): DefaultSchema< unknown, - S.IntersectionE | S.MemberE<1, ThatParserError>>, ParsedShape & ThatParsedShape, ConstructorInput & ThatConstructorInput, - S.IntersectionE | S.MemberE<1, ThatConstructorError>>, Encoded & ThatEncoded, IntersectionApi > { @@ -101,8 +73,7 @@ export function intersect_< const left = Th.result(parseSelf(u)) const right = Th.result(parseThat(u)) - let errors = - Chunk.empty | S.MemberE<1, ThatParserError>>() + let errors = Chunk.empty | S.MemberE<1, any>>() let errored = false let warned = false @@ -110,29 +81,26 @@ export function intersect_< const intersection = {} as unknown as ParsedShape & ThatParsedShape if (left._tag === "Left") { - errors = Chunk.append_(errors, S.memberE(0, left.left as ParserError)) + errors = Chunk.append_(errors, S.memberE(0, left.left as any)) errored = true } else { const warnings = left.right.get(1) if (warnings._tag === "Some") { - errors = Chunk.append_(errors, S.memberE(0, warnings.value as ParserError)) + errors = Chunk.append_(errors, S.memberE(0, warnings.value as any)) warned = true } Object.assign(intersection, left.right.get(0)) } if (right._tag === "Left") { - errors = Chunk.append_(errors, S.memberE(1, right.left as ThatParserError)) + errors = Chunk.append_(errors, S.memberE(1, right.left as any)) errored = true } else { const warnings = right.right.get(1) if (warnings._tag === "Some") { - errors = Chunk.append_( - errors, - S.memberE(1, warnings.value as ThatParserError) - ) + errors = Chunk.append_(errors, S.memberE(1, warnings.value as any)) warned = true } @@ -155,10 +123,7 @@ export function intersect_< const left = Th.result(constructSelf(u)) const right = Th.result(constructThat(u)) - let errors = - Chunk.empty< - S.MemberE<0, ConstructorError> | S.MemberE<1, ThatConstructorError> - >() + let errors = Chunk.empty | S.MemberE<1, any>>() let errored = false let warned = false @@ -166,32 +131,26 @@ export function intersect_< const intersection = {} as unknown as ParsedShape & ThatParsedShape if (left._tag === "Left") { - errors = Chunk.append_(errors, S.memberE(0, left.left as ConstructorError)) + errors = Chunk.append_(errors, S.memberE(0, left.left as any)) errored = true } else { const warnings = left.right.get(1) if (warnings._tag === "Some") { - errors = Chunk.append_( - errors, - S.memberE(0, warnings.value as ConstructorError) - ) + errors = Chunk.append_(errors, S.memberE(0, warnings.value as any)) warned = true } Object.assign(intersection, left.right.get(0)) } if (right._tag === "Left") { - errors = Chunk.append_(errors, S.memberE(1, right.left as ThatConstructorError)) + errors = Chunk.append_(errors, S.memberE(1, right.left as any)) errored = true } else { const warnings = right.right.get(1) if (warnings._tag === "Some") { - errors = Chunk.append_( - errors, - S.memberE(1, warnings.value as ThatConstructorError) - ) + errors = Chunk.append_(errors, S.memberE(1, warnings.value as any)) warned = true } @@ -212,7 +171,7 @@ export function intersect_< }), S.encoder((_): Encoded & ThatEncoded => ({ ...encodeSelf(_), - ...encodeThat(_) + ...encodeThat(_), })), S.arbitrary((FC) => { const self = arbSelf(FC) @@ -241,46 +200,14 @@ export function intersect_< ) } -export function intersect< - ThatParserError extends S.AnyError, - ThatParsedShape, - ThatConstructorInput, - ThatConstructorError extends S.AnyError, - ThatEncoded, - ThatApi ->( - that: S.Schema< - unknown, - ThatParserError, - ThatParsedShape, - ThatConstructorInput, - ThatConstructorError, - ThatEncoded, - ThatApi - > -): < - ParserError extends S.AnyError, - ParsedShape, - ConstructorInput, - ConstructorError extends S.AnyError, - Encoded, - Api ->( - self: S.Schema< - unknown, - ParserError, - ParsedShape, - ConstructorInput, - ConstructorError, - Encoded, - Api - > +export function intersect( + that: S.Schema +): ( + self: S.Schema ) => DefaultSchema< unknown, - S.IntersectionE | S.MemberE<1, ThatParserError>>, ParsedShape & ThatParsedShape, ConstructorInput & ThatConstructorInput, - S.IntersectionE | S.MemberE<1, ThatConstructorError>>, Encoded & ThatEncoded, IntersectionApi > { @@ -288,48 +215,25 @@ export function intersect< } export function intersectLazy< - ThatParserError extends S.AnyError, ThatParsedShape, ThatConstructorInput, - ThatConstructorError extends S.AnyError, ThatEncoded, ThatApi >( that: () => S.Schema< unknown, - ThatParserError, ThatParsedShape, ThatConstructorInput, - ThatConstructorError, ThatEncoded, ThatApi > ) { - return < - ParserError extends S.AnyError, - ParsedShape, - ConstructorInput, - ConstructorError extends S.AnyError, - Encoded, - Api - >( - self: S.Schema< - unknown, - ParserError, - ParsedShape, - ConstructorInput, - ConstructorError, - Encoded, - Api - > + return ( + self: S.Schema ): DefaultSchema< unknown, - S.IntersectionE | S.MemberE<1, ThatParserError>>, ParsedShape & ThatParsedShape, ConstructorInput & ThatConstructorInput, - S.IntersectionE< - S.MemberE<0, ConstructorError> | S.MemberE<1, ThatConstructorError> - >, Encoded & ThatEncoded, Api > => { diff --git a/packages/schema/src/_api/json.ts b/packages/schema/src/_api/json.ts index d8d6009..2d1ab93 100644 --- a/packages/schema/src/_api/json.ts +++ b/packages/schema/src/_api/json.ts @@ -21,15 +21,7 @@ export class JsonDecodingE } } -export const jsonString: DefaultSchema< - string, - S.LeafE, - unknown, - unknown, - never, - string, - {} -> = pipe( +export const jsonString: DefaultSchema = pipe( S.identity((u): u is string => typeof u === "string"), S.constructor((n) => Th.succeed(n)), S.arbitrary((_) => _.anything()), @@ -47,14 +39,8 @@ export const jsonString: DefaultSchema< export const jsonIdentifier = S.makeAnnotation<{}>() -export const json: DefaultSchema< - unknown, - S.CompositionE< - S.PrevE>> | S.NextE> - >, - unknown, - unknown, - never, - string, - {} -> = pipe(string[">>>"](jsonString), withDefaults, S.annotate(jsonIdentifier, {})) +export const json: DefaultSchema = pipe( + string[">>>"](jsonString), + withDefaults, + S.annotate(jsonIdentifier, {}) +) diff --git a/packages/schema/src/_api/lazy.ts b/packages/schema/src/_api/lazy.ts index 4f5e3aa..664c553 100644 --- a/packages/schema/src/_api/lazy.ts +++ b/packages/schema/src/_api/lazy.ts @@ -1,34 +1,10 @@ -import type { AnyError, Schema } from "../_schema" +import type { Schema } from "../_schema" import { SchemaLazy } from "../_schema" import type { DefaultSchema } from "./withDefaults" import { withDefaults } from "./withDefaults" -export function lazy< - ParserInput, - ParserError extends AnyError, - ParsedShape, - ConstructorInput, - ConstructorError extends AnyError, - Encoded, - Api ->( - self: () => Schema< - ParserInput, - ParserError, - ParsedShape, - ConstructorInput, - ConstructorError, - Encoded, - Api - > -): DefaultSchema< - ParserInput, - ParserError, - ParsedShape, - ConstructorInput, - ConstructorError, - Encoded, - {} -> { +export function lazy( + self: () => Schema +): DefaultSchema { return withDefaults(new SchemaLazy(self)) } diff --git a/packages/schema/src/_api/literal.ts b/packages/schema/src/_api/literal.ts index 1abab86..807ec5a 100644 --- a/packages/schema/src/_api/literal.ts +++ b/packages/schema/src/_api/literal.ts @@ -31,15 +31,7 @@ export const literalIdentifier = S.makeAnnotation<{ literals: readonly string[] export function literal( ...literals: KS -): DefaultSchema< - unknown, - S.RefinementE>>, - KS[number], - KS[number], - never, - KS[number], - LiteralApi -> { +): DefaultSchema> { const ko = {} for (const k of literals) { ko[k] = true @@ -57,7 +49,7 @@ export function literal( _AS: undefined as any, literals, matchS: (m) => (k) => m[k](k), - matchW: (m) => (k) => m[k](k) + matchW: (m) => (k) => m[k](k), }) ), withDefaults, diff --git a/packages/schema/src/_api/model.ts b/packages/schema/src/_api/model.ts index dab4ada..cdf3506 100644 --- a/packages/schema/src/_api/model.ts +++ b/packages/schema/src/_api/model.ts @@ -10,10 +10,8 @@ import * as S from "./schemed" export type SchemaForModel = MO.Schema< MO.ParserInputOf, - MO.ParserErrorOf, M, MO.ConstructorInputOf, - MO.ConstructorErrorOf, MO.EncodedOf, MO.ApiOf & MO.ApiSelfType > @@ -49,10 +47,8 @@ export interface Model extends S.Schemed, MO.Schema< MO.ParserInputOf, - MO.NamedE>, M, MO.ConstructorInputOf, - MO.NamedE>, MO.EncodedOf, MO.ApiOf > { @@ -78,42 +74,42 @@ export function Model(__name?: string) { const schema = S.schema(schemed) Object.defineProperty(schemed, MO.SchemaContinuationSymbol, { - value: schema + value: schema, }) Object.defineProperty(schemed, "Api", { get() { return self.Api - } + }, }) Object.defineProperty(schemed, ">>>", { - value: self[">>>"] + value: self[">>>"], }) Object.defineProperty(schemed, "Parser", { - value: Parser.for(schema) + value: Parser.for(schema), }) Object.defineProperty(schemed, "Constructor", { - value: Constructor.for(schema) + value: Constructor.for(schema), }) Object.defineProperty(schemed, "Encoder", { - value: Encoder.for(schema) + value: Encoder.for(schema), }) Object.defineProperty(schemed, "Guard", { - value: Guard.for(schema) + value: Guard.for(schema), }) Object.defineProperty(schemed, "Arbitrary", { - value: Arbitrary.for(schema) + value: Arbitrary.for(schema), }) Object.defineProperty(schemed, "annotate", { value: (identifier: Annotation, meta: Meta) => - new MO.SchemaAnnotated(schema, identifier, meta) + new MO.SchemaAnnotated(schema, identifier, meta), }) // @ts-expect-error the following is correct diff --git a/packages/schema/src/_api/nonEmpty.ts b/packages/schema/src/_api/nonEmpty.ts index 0074d9a..8d5be57 100644 --- a/packages/schema/src/_api/nonEmpty.ts +++ b/packages/schema/src/_api/nonEmpty.ts @@ -14,33 +14,16 @@ export const nonEmptyIdentifier = S.makeAnnotation<{ self: S.SchemaAny }>() export function nonEmpty< ParserInput, - ParserError extends S.AnyError, ParsedShape extends { length: number }, ConstructorInput, - ConstructorError extends S.AnyError, Encoded, Api >( - self: S.Schema< - ParserInput, - ParserError, - ParsedShape, - ConstructorInput, - ConstructorError, - Encoded, - Api - > + self: S.Schema ): DefaultSchema< ParserInput, - S.CompositionE< - S.NextE>>> | S.PrevE - >, ParsedShape & NonEmptyBrand, ConstructorInput, - S.CompositionE< - | S.NextE>>> - | S.PrevE - >, Encoded, Api > { diff --git a/packages/schema/src/_api/nonEmptyString.ts b/packages/schema/src/_api/nonEmptyString.ts index fefab2d..cdc1a11 100644 --- a/packages/schema/src/_api/nonEmptyString.ts +++ b/packages/schema/src/_api/nonEmptyString.ts @@ -16,18 +16,16 @@ export const nonEmptyStringFromStringIdentifier = S.makeAnnotation<{}>() export const nonEmptyStringFromString: DefaultSchema< string, - S.RefinementE>>, NonEmptyString, string, - S.RefinementE>>, string, {} > = pipe( fromString, S.arbitrary((FC) => FC.string({ minLength: 1 })), nonEmpty, - S.mapParserError((_) => Chunk.unsafeHead(_.errors).error), - S.mapConstructorError((_) => Chunk.unsafeHead(_.errors).error), + S.mapParserError((_) => (Chunk.unsafeHead((_ as any).errors) as any).error), + S.mapConstructorError((_) => (Chunk.unsafeHead((_ as any).errors) as any).error), brand(), S.annotate(nonEmptyStringFromStringIdentifier, {}) ) @@ -36,13 +34,8 @@ export const nonEmptyStringIdentifier = S.makeAnnotation<{}>() export const nonEmptyString: DefaultSchema< unknown, - S.CompositionE< - | S.NextE>>> - | S.PrevE>> - >, NonEmptyString, string, - S.RefinementE>>, string, S.ApiSelfType > = pipe( diff --git a/packages/schema/src/_api/nullable.ts b/packages/schema/src/_api/nullable.ts index 4556c55..5bc9a8c 100644 --- a/packages/schema/src/_api/nullable.ts +++ b/packages/schema/src/_api/nullable.ts @@ -13,30 +13,12 @@ import { withDefaults } from "./withDefaults" export const nullableIdentifier = S.makeAnnotation<{ self: S.SchemaAny }>() -export function nullable< - ParserInput, - ParserError extends S.AnyError, - ParsedShape, - ConstructorInput, - ConstructorError extends S.AnyError, - Encoded, - Api ->( - self: S.Schema< - ParserInput, - ParserError, - ParsedShape, - ConstructorInput, - ConstructorError, - Encoded, - Api - > +export function nullable( + self: S.Schema ): DefaultSchema< ParserInput | null, - ParserError, O.Option, O.Option, - ConstructorError, Encoded | null, Api > { diff --git a/packages/schema/src/_api/number.ts b/packages/schema/src/_api/number.ts index 8cbc75a..529bace 100644 --- a/packages/schema/src/_api/number.ts +++ b/packages/schema/src/_api/number.ts @@ -12,15 +12,7 @@ import { withDefaults } from "./withDefaults" export const fromNumberIdentifier = S.makeAnnotation<{}>() -export const fromNumber: DefaultSchema< - number, - never, - number, - number, - never, - number, - {} -> = pipe( +export const fromNumber: DefaultSchema = pipe( S.identity((u): u is number => typeof u === "number"), S.arbitrary((_) => _.double()), S.mapApi(() => ({})), @@ -30,15 +22,7 @@ export const fromNumber: DefaultSchema< export const numberIdentifier = S.makeAnnotation<{}>() -export const number: DefaultSchema< - unknown, - S.RefinementE>, - number, - number, - never, - number, - {} -> = pipe( +export const number: DefaultSchema = pipe( refinement( (u): u is number => typeof u === "number", (v) => S.leafE(S.parseNumberE(v)) @@ -53,44 +37,27 @@ export const number: DefaultSchema< export const stringNumberFromStringIdentifier = S.makeAnnotation<{}>() -export const stringNumberFromString: DefaultSchema< - string, - S.LeafE, - number, - number, - never, - string, - {} -> = pipe( - fromString[">>>"]( - pipe( - number, - S.encoder((_) => String(_)), - S.parser((s) => - pipe(Number.parseFloat(s), (n) => - Number.isNaN(n) ? Th.fail(S.leafE(S.parseNumberE(s))) : Th.succeed(n) +export const stringNumberFromString: DefaultSchema = + pipe( + fromString[">>>"]( + pipe( + number, + S.encoder((_) => String(_)), + S.parser((s) => + pipe(Number.parseFloat(s), (n) => + Number.isNaN(n) ? Th.fail(S.leafE(S.parseNumberE(s))) : Th.succeed(n) + ) ) ) - ) - ), - S.mapParserError((e) => Chunk.unsafeHead(e.errors).error), - withDefaults, - S.annotate(stringNumberFromStringIdentifier, {}) -) + ), + S.mapParserError((e) => (Chunk.unsafeHead((e as any).errors) as any).error), + withDefaults, + S.annotate(stringNumberFromStringIdentifier, {}) + ) export const stringNumberIdentifier = S.makeAnnotation<{}>() -export const stringNumber: DefaultSchema< - unknown, - S.CompositionE< - S.PrevE>> | S.NextE> - >, - number, - number, - never, - string, - {} -> = pipe( +export const stringNumber: DefaultSchema = pipe( string[">>>"](stringNumberFromString), withDefaults, S.annotate(stringNumberIdentifier, {}) diff --git a/packages/schema/src/_api/object.ts b/packages/schema/src/_api/object.ts index eedf013..9e91943 100644 --- a/packages/schema/src/_api/object.ts +++ b/packages/schema/src/_api/object.ts @@ -10,15 +10,7 @@ import { withDefaults } from "./withDefaults" export const objectIdentifier = S.makeAnnotation<{}>() -export const object: DefaultSchema< - unknown, - S.RefinementE>, - {}, - {}, - never, - {}, - {} -> = pipe( +export const object: DefaultSchema = pipe( refinement( (u): u is {} => typeof u === "object" && u != null, (v) => S.leafE(S.parseObjectE(v)) diff --git a/packages/schema/src/_api/positive.ts b/packages/schema/src/_api/positive.ts index 23f9eaf..e28d7e0 100644 --- a/packages/schema/src/_api/positive.ts +++ b/packages/schema/src/_api/positive.ts @@ -16,30 +16,16 @@ export const positiveIdentifier = S.makeAnnotation<{ self: S.SchemaAny }>() export function positive< ParserInput, - ParserError extends S.AnyError, ParsedShape extends number, ConstructorInput, - ConstructorError extends S.AnyError, Encoded, Api >( - self: S.Schema< - ParserInput, - ParserError, - ParsedShape, - ConstructorInput, - ConstructorError, - Encoded, - Api - > + self: S.Schema ): DefaultSchema< ParserInput, - S.CompositionE | S.NextE>>>, ParsedShape & PositiveBrand, ConstructorInput, - S.CompositionE< - S.PrevE | S.NextE>> - >, Encoded, Api > { diff --git a/packages/schema/src/_api/positiveInt.ts b/packages/schema/src/_api/positiveInt.ts index c6c0a73..a1c8d25 100644 --- a/packages/schema/src/_api/positiveInt.ts +++ b/packages/schema/src/_api/positiveInt.ts @@ -15,16 +15,8 @@ export const positiveIntFromNumberIdentifier = S.makeAnnotation<{}>() export const positiveIntFromNumber: DefaultSchema< number, - S.CompositionE< - | S.PrevE>> - | S.NextE>> - >, Int & Positive, number, - S.CompositionE< - | S.PrevE>> - | S.NextE>> - >, number, S.ApiSelfType > = pipe( @@ -39,21 +31,8 @@ export const positiveIntIdentifier = S.makeAnnotation<{}>() export const positiveInt: DefaultSchema< unknown, - S.CompositionE< - | S.PrevE>> - | S.NextE< - S.CompositionE< - | S.PrevE>> - | S.NextE>> - > - > - >, Int & Positive, number, - S.CompositionE< - | S.PrevE>> - | S.NextE>> - >, number, S.ApiSelfType > = pipe( diff --git a/packages/schema/src/_api/properties.ts b/packages/schema/src/_api/properties.ts index a8a89bc..3980b38 100644 --- a/packages/schema/src/_api/properties.ts +++ b/packages/schema/src/_api/properties.ts @@ -280,10 +280,8 @@ export const propertiesIdentifier = S.makeAnnotation<{ props: PropertyRecord }>( export type SchemaProperties = DefaultSchema< unknown, - ParserErrorFromProperties, ShapeFromProperties, ConstructorFromProperties, - never, EncodedFromProperties, { props: Props } > diff --git a/packages/schema/src/_api/refinement.ts b/packages/schema/src/_api/refinement.ts index c969363..8cb3869 100644 --- a/packages/schema/src/_api/refinement.ts +++ b/packages/schema/src/_api/refinement.ts @@ -5,7 +5,7 @@ import type { Refinement } from "@effect-ts/core/Function" import { pipe } from "@effect-ts/core/Function" import * as S from "../_schema" -import type { RefinementE } from "../_schema/error" +//import type { RefinementE } from "../_schema/error" import { unknown } from "./unknown" import type { DefaultSchema } from "./withDefaults" import { withDefaults } from "./withDefaults" @@ -19,20 +19,12 @@ export const refinementIdentifier = export function refinement( refinement: Refinement, error: (value: unknown) => E -): DefaultSchema< - unknown, - RefinementE, - NewParsedShape, - unknown, - RefinementE, - unknown, - {} -> { +): DefaultSchema { return pipe( unknown, S.refine(refinement, error), - S.mapParserError((e) => Chunk.unsafeHead(e.errors).error), - S.mapConstructorError((e) => Chunk.unsafeHead(e.errors).error), + S.mapParserError((e) => (Chunk.unsafeHead((e as any).errors) as any).error), + S.mapConstructorError((e) => (Chunk.unsafeHead((e as any).errors) as any).error), withDefaults, S.annotate(refinementIdentifier, { refinement, error }) ) diff --git a/packages/schema/src/_api/schemed.ts b/packages/schema/src/_api/schemed.ts index 499dc3a..04a7d9e 100644 --- a/packages/schema/src/_api/schemed.ts +++ b/packages/schema/src/_api/schemed.ts @@ -35,22 +35,12 @@ export type ShapeFromSchemedOut< export type SchemaForSchemed> = [ Self[schemaField] ] extends [ - S.Schema< - infer ParserInput, - infer ParserError, - any, - infer ConstructorInput, - infer ConstructorError, - infer Encoded, - infer Api - > + S.Schema ] ? S.Schema< ParserInput, - ParserError, ShapeFromSchemedOut, ConstructorInput, - ConstructorError, Encoded, Api & S.ApiSelfType> > @@ -77,9 +67,9 @@ type ShapeFromClass< export const fromFields = Symbol() -export function Schemed< - Self extends S.Schema ->(self: Self): Schemed { +export function Schemed>( + self: Self +): Schemed { const of_ = Constructor.for(self)["|>"](unsafe) // @ts-expect-error return class { diff --git a/packages/schema/src/_api/string.ts b/packages/schema/src/_api/string.ts index 8f8c5fc..d9d279b 100644 --- a/packages/schema/src/_api/string.ts +++ b/packages/schema/src/_api/string.ts @@ -10,15 +10,7 @@ import { withDefaults } from "./withDefaults" export const stringIdentifier = S.makeAnnotation<{}>() -export const string: DefaultSchema< - unknown, - S.RefinementE>, - string, - string, - never, - string, - {} -> = pipe( +export const string: DefaultSchema = pipe( refinement( (u): u is string => typeof u === "string", (v) => S.leafE(S.parseStringE(v)) @@ -33,15 +25,7 @@ export const string: DefaultSchema< export const fromStringIdentifier = S.makeAnnotation<{}>() -export const fromString: DefaultSchema< - string, - never, - string, - string, - never, - string, - {} -> = pipe( +export const fromString: DefaultSchema = pipe( S.identity((u): u is string => typeof u === "string"), S.arbitrary((_) => _.string()), S.mapApi(() => ({})), diff --git a/packages/schema/src/_api/union.ts b/packages/schema/src/_api/union.ts index 50a4313..6092e66 100644 --- a/packages/schema/src/_api/union.ts +++ b/packages/schema/src/_api/union.ts @@ -120,23 +120,12 @@ export interface UnionApi> export type SchemaUnion> = DefaultSchema< unknown, - S.CompositionE< - | S.PrevE> - | S.NextE< - S.UnionE< - { - [k in keyof Props]: S.MemberE> - }[keyof Props] - > - > - >, { [k in keyof Props]: S.ParsedShapeOf }[keyof Props], { [k in keyof Props]: S.ParsedShapeOf }[keyof Props], - never, { [k in keyof Props]: S.EncodedOf }[keyof Props], @@ -172,7 +161,7 @@ export function union>( k, "props" in s.Api && isPropertyRecord(s.Api["props"]) ? tagsFromProps(s.Api["props"]) - : {} + : {}, ] as const ) @@ -196,7 +185,7 @@ export function union>( key: tagField, index: D.fromArray(tags), reverse: D.fromArray(tags.map(({ tuple: [a, b] }) => tuple(b, a))), - values: tags.map((_) => _.get(0)) + values: tags.map((_) => _.get(0)), }) } @@ -276,7 +265,7 @@ export function union>( ) ) } else { - // @ts-expect-error + // // @ts-expect-error return Th.mapError_(parsers[tag.value.index[u[tag.value.key]]](u), (e) => S.compositionE( Chunk.single( @@ -296,7 +285,6 @@ export function union>( const res = parser(u) if (res.effect._tag === "Right") { - // @ts-expect-error return Th.mapError_(res, (e) => S.compositionE(Chunk.single(S.nextE(S.unionE(Chunk.single(S.memberE(k, e)))))) ) @@ -339,7 +327,7 @@ export function union>( } } throw new Error(`bug: can't find any valid matcher`) - } + }, } as UnionApi) ), withDefaults, diff --git a/packages/schema/src/_api/unknown.ts b/packages/schema/src/_api/unknown.ts index 03233a4..b3ac78f 100644 --- a/packages/schema/src/_api/unknown.ts +++ b/packages/schema/src/_api/unknown.ts @@ -9,15 +9,7 @@ import { withDefaults } from "./withDefaults" export const unknownIdentifier = S.makeAnnotation<{}>() -export const unknown: DefaultSchema< - unknown, - never, - unknown, - unknown, - never, - unknown, - {} -> = pipe( +export const unknown: DefaultSchema = pipe( identity((_): _ is unknown => true), withDefaults, annotate(unknownIdentifier, {}) diff --git a/packages/schema/src/_api/unknownArray.ts b/packages/schema/src/_api/unknownArray.ts index d3c2ae0..869fc54 100644 --- a/packages/schema/src/_api/unknownArray.ts +++ b/packages/schema/src/_api/unknownArray.ts @@ -12,10 +12,8 @@ export const unknownArrayIdentifier = S.makeAnnotation<{}>() export const unknownArray: DefaultSchema< unknown, - S.RefinementE>, readonly unknown[], unknown, - S.RefinementE>, readonly unknown[], {} > = pipe( @@ -24,8 +22,8 @@ export const unknownArray: DefaultSchema< (u): u is readonly unknown[] => Array.isArray(u), (val) => S.leafE(S.unknownArrayE(val)) ), - S.mapParserError((_) => Chunk.unsafeHead(_.errors).error), - S.mapConstructorError((_) => Chunk.unsafeHead(_.errors).error), + S.mapParserError((_) => (Chunk.unsafeHead((_ as any).errors) as any).error), + S.mapConstructorError((_) => (Chunk.unsafeHead((_ as any).errors) as any).error), S.encoder((_) => _), withDefaults, S.annotate(unknownArrayIdentifier, {}) diff --git a/packages/schema/src/_api/uuid.ts b/packages/schema/src/_api/uuid.ts index d9e134d..33b6325 100644 --- a/packages/schema/src/_api/uuid.ts +++ b/packages/schema/src/_api/uuid.ts @@ -25,26 +25,12 @@ const isUUID: Refinement = (s: string): s is UUID => { return regexUUID.test(s) } -export const UUIDFromString: DefaultSchema< - string, - S.CompositionE< - | S.NextE>> - | S.PrevE>>> - >, - UUID, - string, - S.CompositionE< - | S.NextE>> - | S.PrevE>>> - >, - string, - {} -> = pipe( +export const UUIDFromString: DefaultSchema = pipe( fromString, S.arbitrary((FC) => FC.uuid()), nonEmpty, - S.mapParserError((_) => Chunk.unsafeHead(_.errors).error), - S.mapConstructorError((_) => Chunk.unsafeHead(_.errors).error), + S.mapParserError((_) => (Chunk.unsafeHead((_ as any).errors) as any).error), + S.mapConstructorError((_) => (Chunk.unsafeHead((_ as any).errors) as any).error), S.refine(isUUID, (n) => S.leafE(parseUuidE(n))), brand(), S.annotate(UUIDFromStringIdentifier, {}) @@ -52,23 +38,5 @@ export const UUIDFromString: DefaultSchema< export const UUIDIdentifier = S.makeAnnotation<{}>() -export const UUID: DefaultSchema< - unknown, - S.CompositionE< - | S.PrevE>> - | S.NextE< - S.CompositionE< - | S.NextE>> - | S.PrevE>>> - > - > - >, - UUID, - string, - S.CompositionE< - | S.NextE>> - | S.PrevE>>> - >, - string, - S.ApiSelfType -> = pipe(string[">>>"](UUIDFromString), brand(), S.annotate(UUIDIdentifier, {})) +export const UUID: DefaultSchema> = + pipe(string[">>>"](UUIDFromString), brand(), S.annotate(UUIDIdentifier, {})) diff --git a/packages/schema/src/_api/withDefaultConstructorField.ts b/packages/schema/src/_api/withDefaultConstructorField.ts index 3024803..9966a67 100644 --- a/packages/schema/src/_api/withDefaultConstructorField.ts +++ b/packages/schema/src/_api/withDefaultConstructorField.ts @@ -25,29 +25,12 @@ export function withDefaultConstructorField< >( key: Key, value: Lazy -): < - ParserInput, - ParserError extends S.AnyError, - ParsedShape, - ConstructorError extends S.AnyError, - Encoded, - Api ->( - self: S.Schema< - ParserInput, - ParserError, - ParsedShape, - ConstructorInput, - ConstructorError, - Encoded, - Api - > +): ( + self: S.Schema ) => DefaultSchema< ParserInput, - ParserError, ParsedShape, OptionalKey, - ConstructorError, Encoded, Api > { diff --git a/packages/schema/src/_api/withDefaults.ts b/packages/schema/src/_api/withDefaults.ts index 23586cb..5e17357 100644 --- a/packages/schema/src/_api/withDefaults.ts +++ b/packages/schema/src/_api/withDefaults.ts @@ -12,30 +12,16 @@ import { unsafe } from "./condemn" export interface SchemaDefaultSchema< ParserInput, - ParserError extends MO.AnyError, ParsedShape, ConstructorInput, - ConstructorError extends MO.AnyError, Encoded, Api -> extends Schema< - ParserInput, - ParserError, - ParsedShape, - ConstructorInput, - ConstructorError, - Encoded, - Api - > { +> extends Schema { (_: ConstructorInput): ParsedShape - readonly Parser: Parser.Parser + readonly Parser: Parser.Parser - readonly Constructor: Constructor.Constructor< - ConstructorInput, - ParsedShape, - ConstructorError - > + readonly Constructor: Constructor.Constructor readonly Encoder: Encoder.Encoder @@ -46,35 +32,12 @@ export interface SchemaDefaultSchema< readonly annotate: ( identifier: Annotation, meta: Meta - ) => DefaultSchema< - ParserInput, - ParserError, - ParsedShape, - ConstructorInput, - ConstructorError, - Encoded, - Api - > + ) => DefaultSchema } -export type DefaultSchema< - ParserInput, - ParserError extends MO.AnyError, - ParsedShape, - ConstructorInput, - ConstructorError extends MO.AnyError, - Encoded, - Api -> = SchemaDefaultSchema< - ParserInput, - ParserError, - ParsedShape, - ConstructorInput, - ConstructorError, - Encoded, - Api -> & - CarryFromApi +export type DefaultSchema = + SchemaDefaultSchema & + CarryFromApi const carryOver = ["matchW", "matchS", "props"] as const @@ -86,33 +49,9 @@ type CarryFromApi = UnionToIntersection< }[keyof Api] > -export function withDefaults< - ParserInput, - ParsedShape, - ParserError extends MO.AnyError, - ConstructorInput, - ConstructorError extends MO.AnyError, - Encoded, - Api ->( - self: Schema< - ParserInput, - ParserError, - ParsedShape, - ConstructorInput, - ConstructorError, - Encoded, - Api - > -): DefaultSchema< - ParserInput, - ParserError, - ParsedShape, - ConstructorInput, - ConstructorError, - Encoded, - Api -> { +export function withDefaults( + self: Schema +): DefaultSchema { const of_ = Constructor.for(self)["|>"](unsafe) function schemed(_: ConstructorInput) { @@ -120,49 +59,49 @@ export function withDefaults< } Object.defineProperty(schemed, MO.SchemaContinuationSymbol, { - value: self + value: self, }) Object.defineProperty(schemed, "Api", { get() { return self.Api - } + }, }) Object.defineProperty(schemed, ">>>", { - value: self[">>>"] + value: self[">>>"], }) Object.defineProperty(schemed, "Parser", { - value: Parser.for(self) + value: Parser.for(self), }) Object.defineProperty(schemed, "Constructor", { - value: Constructor.for(self) + value: Constructor.for(self), }) Object.defineProperty(schemed, "Encoder", { - value: Encoder.for(self) + value: Encoder.for(self), }) Object.defineProperty(schemed, "Guard", { - value: Guard.for(self) + value: Guard.for(self), }) Object.defineProperty(schemed, "Arbitrary", { - value: Arbitrary.for(self) + value: Arbitrary.for(self), }) Object.defineProperty(schemed, "annotate", { value: (annotation: Annotation, meta: Meta) => - withDefaults(self.annotate(annotation, meta)) + withDefaults(self.annotate(annotation, meta)), }) for (const k of carryOver) { Object.defineProperty(schemed, k, { get() { return self.Api[k] - } + }, }) } diff --git a/packages/schema/src/_schema/error.ts b/packages/schema/src/_schema/error.ts index 843f195..4614ece 100644 --- a/packages/schema/src/_schema/error.ts +++ b/packages/schema/src/_schema/error.ts @@ -54,8 +54,8 @@ export interface LeafErrors { export type LeafError = Extract -export const defaultLeafSymbol = Symbol.for("@effect-ts/schema/error/defaultLeaf") -export const toTreeSymbol = Symbol.for("@effect-ts/schema/error/defaultLeaf/toTree") +export const defaultLeafSymbol = Symbol.for("@effect-ts-app/core/Schema/custom/error/defaultLeaf") +export const toTreeSymbol = Symbol.for("@effect-ts-app/core/Schema/custom/error/defaultLeaf/toTree") export interface HasDefaultLeafE { readonly [toTreeSymbol]: Tree diff --git a/packages/schema/src/_schema/primitives.ts b/packages/schema/src/_schema/primitives.ts index f71f71a..835283b 100644 --- a/packages/schema/src/_schema/primitives.ts +++ b/packages/schema/src/_schema/primitives.ts @@ -5,7 +5,7 @@ import type * as fc from "fast-check" import type * as Th from "../These" import type { Annotation } from "./annotation" -import type { AnyError, CompositionE, NamedE, NextE, PrevE, RefinementE } from "./error" +import type { AnyError } from "./error" import type { ApiSelfType, Schema, SchemaAny } from "./schema" import { SchemaAnnotated, @@ -20,324 +20,110 @@ import { SchemaNamed, SchemaParser, SchemaPipe, - SchemaRefinement + SchemaRefinement, } from "./schema" export function opaque() { - return < - ConstructorInput, - ConstructorError extends AnyError, - ParserInput, - ParserError extends AnyError, - Encoded, - Api - >( - schema: Schema< - ParserInput, - ParserError, - Shape, - ConstructorInput, - ConstructorError, - Encoded, - Api - > - ): Schema< - ParserInput, - ParserError, - Shape, - ConstructorInput, - ConstructorError, - Encoded, - Api & ApiSelfType - > => schema as any + return ( + schema: Schema + ): Schema> => + schema as any } export function named(name: Name) { - return < - ParserInput, - ParserError extends AnyError, - ParsedShape, - ConstructorInput, - ConstructorError extends AnyError, - Encoded, - Api - >( - self: Schema< - ParserInput, - ParserError, - ParsedShape, - ConstructorInput, - ConstructorError, - Encoded, - Api - > - ): Schema< - ParserInput, - NamedE, - ParsedShape, - ConstructorInput, - NamedE, - Encoded, - Api - > => new SchemaNamed(self, name) + return ( + self: Schema + ): Schema => + new SchemaNamed(self, name) } -export function identity( - guard: (_: unknown) => _ is A -): Schema { +export function identity(guard: (_: unknown) => _ is A): Schema { return new SchemaIdentity(guard) } export function constructor< NewConstructorInput, - NewConstructorError extends AnyError, ParserInput, - ParserError extends AnyError, ParsedShape, ConstructorInput, - ConstructorError extends AnyError, Encoded, Api ->(f: (_: NewConstructorInput) => Th.These) { +>(f: (_: NewConstructorInput) => Th.These) { return ( - self: Schema< - ParserInput, - ParserError, - ParsedShape, - ConstructorInput, - ConstructorError, - Encoded, - Api - > - ): Schema< - ParserInput, - ParserError, - ParsedShape, - NewConstructorInput, - NewConstructorError, - Encoded, - Api - > => new SchemaConstructor(self, f) + self: Schema + ): Schema => + new SchemaConstructor(self, f) } export function constructor_< NewConstructorInput, - NewConstructorError extends AnyError, ParserInput, - ParserError extends AnyError, ParsedShape, ConstructorInput, - ConstructorError extends AnyError, Encoded, Api >( - self: Schema< - ParserInput, - ParserError, - ParsedShape, - ConstructorInput, - ConstructorError, - Encoded, - Api - >, - f: (_: NewConstructorInput) => Th.These -): Schema< - ParserInput, - ParserError, - ParsedShape, - NewConstructorInput, - NewConstructorError, - Encoded, - Api -> { + self: Schema, + f: (_: NewConstructorInput) => Th.These +): Schema { return new SchemaConstructor(self, f) } export function parser< NewParserInput, - NewParserError extends AnyError, ParserInput, - ParserError extends AnyError, ParsedShape, ConstructorInput, - ConstructorError extends AnyError, Encoded, Api ->(f: (_: NewParserInput) => Th.These) { +>(f: (_: NewParserInput) => Th.These) { return ( - self: Schema< - ParserInput, - ParserError, - ParsedShape, - ConstructorInput, - ConstructorError, - Encoded, - Api - > - ): Schema< - NewParserInput, - NewParserError, - ParsedShape, - ConstructorInput, - ConstructorError, - Encoded, - Api - > => new SchemaParser(self, f) + self: Schema + ): Schema => + new SchemaParser(self, f) } export function parser_< NewParserInput, - NewParserError extends AnyError, ParserInput, - ParserError extends AnyError, ParsedShape, ConstructorInput, - ConstructorError extends AnyError, Encoded, Api >( - self: Schema< - ParserInput, - ParserError, - ParsedShape, - ConstructorInput, - ConstructorError, - Encoded, - Api - >, - f: (_: NewParserInput) => Th.These -): Schema< - NewParserInput, - NewParserError, - ParsedShape, - ConstructorInput, - ConstructorError, - Encoded, - Api -> { + self: Schema, + f: (_: NewParserInput) => Th.These +): Schema { return new SchemaParser(self, f) } export function arbitrary( f: (_: typeof fc) => fc.Arbitrary ) { - return < - ParserInput, - ParserError extends AnyError, - ConstructorInput, - ConstructorError extends AnyError, - Encoded, - Api - >( - self: Schema< - ParserInput, - ParserError, - ParsedShape, - ConstructorInput, - ConstructorError, - Encoded, - Api - > - ): Schema< - ParserInput, - ParserError, - ParsedShape, - ConstructorInput, - ConstructorError, - Encoded, - Api - > => new SchemaArbitrary(self, f) as any + return ( + self: Schema + ): Schema => + new SchemaArbitrary(self, f) as any } -export function arbitrary_< - ParserInput, - ParserError extends AnyError, - ParsedShape, - ConstructorInput, - ConstructorError extends AnyError, - Encoded, - Api ->( - self: Schema< - ParserInput, - ParserError, - ParsedShape, - ConstructorInput, - ConstructorError, - Encoded, - Api - >, +export function arbitrary_( + self: Schema, f: (_: typeof fc) => fc.Arbitrary -): Schema< - ParserInput, - ParserError, - ParsedShape, - ConstructorInput, - ConstructorError, - Encoded, - Api -> { +): Schema { return new SchemaArbitrary(self, f) } export function encoder(f: (_: ParsedShape) => A) { - return < - ParserInput, - ParserError extends AnyError, - ConstructorInput, - ConstructorError extends AnyError, - Encoded, - Api - >( - self: Schema< - ParserInput, - ParserError, - ParsedShape, - ConstructorInput, - ConstructorError, - Encoded, - Api - > - ): Schema< - ParserInput, - ParserError, - ParsedShape, - ConstructorInput, - ConstructorError, - A, - Api - > => new SchemaEncoder(self, f) + return ( + self: Schema + ): Schema => + new SchemaEncoder(self, f) } -export function encoder_< - ParserInput, - ParserError extends AnyError, - ParsedShape, - ConstructorInput, - ConstructorError extends AnyError, - Encoded, - Api, - A ->( - self: Schema< - ParserInput, - ParserError, - ParsedShape, - ConstructorInput, - ConstructorError, - Encoded, - Api - >, +export function encoder_( + self: Schema, f: (_: ParsedShape) => A -): Schema< - ParserInput, - ParserError, - ParsedShape, - ConstructorInput, - ConstructorError, - A, - Api -> { +): Schema { return new SchemaEncoder(self, f) } @@ -348,156 +134,49 @@ export function refine< >( refinement: Refinement, error: (value: ParsedShape) => E -): < - ParserInput, - ParserError extends AnyError, - ConstructorInput, - ConstructorError extends AnyError, - Encoded, - Api ->( - self: Schema< - ParserInput, - ParserError, - ParsedShape, - ConstructorInput, - ConstructorError, - Encoded, - Api - > -) => Schema< - ParserInput, - CompositionE | NextE>>, - NewParsedShape, - ConstructorInput, - CompositionE | NextE>>, - Encoded, - Api -> { +): ( + self: Schema +) => Schema { return (self) => new SchemaRefinement(self, refinement, error) } export function mapParserError( f: (e: E) => E1 ) { - return < - ParserInput, - ParsedShape, - ConstructorInput, - ConstructorError extends AnyError, - Encoded, - Api - >( - self: Schema< - ParserInput, - E, - ParsedShape, - ConstructorInput, - ConstructorError, - Encoded, - Api - > - ): Schema< - ParserInput, - E1, - ParsedShape, - ConstructorInput, - ConstructorError, - Encoded, - Api - > => new SchemaMapParserError(self, f) + return ( + self: Schema + ): Schema => + new SchemaMapParserError(self, f) } export function mapConstructorError( f: (e: E) => E1 ) { - return < - ParserInput, - ParserError extends AnyError, - ParsedShape, - ConstructorInput, - Encoded, - Api - >( - self: Schema< - ParserInput, - ParserError, - ParsedShape, - ConstructorInput, - E, - Encoded, - Api - > - ): Schema< - ParserInput, - ParserError, - ParsedShape, - ConstructorInput, - E1, - Encoded, - Api - > => new SchemaMapConstructorError(self, f) + return ( + self: Schema + ): Schema => + new SchemaMapConstructorError(self, f) } export function mapApi(f: (e: E) => E1) { - return < - ParserInput, - ParserError extends AnyError, - ParsedShape, - ConstructorInput, - ConstructorError extends AnyError, - Encoded - >( - self: Schema< - ParserInput, - ParserError, - ParsedShape, - ConstructorInput, - ConstructorError, - Encoded, - E - > - ): Schema< - ParserInput, - ParserError, - ParsedShape, - ConstructorInput, - ConstructorError, - Encoded, - E1 - > => new SchemaMapApi(self, f) + return ( + self: Schema + ): Schema => + new SchemaMapApi(self, f) } export function identified_< ParserInput, - ParserError extends AnyError, ParsedShape, ConstructorInput, - ConstructorError extends AnyError, Encoded, Api, Meta >( - self: Schema< - ParserInput, - ParserError, - ParsedShape, - ConstructorInput, - ConstructorError, - Encoded, - Api - >, + self: Schema, identifier: Annotation, meta: Meta -): Schema< - ParserInput, - ParserError, - ParsedShape, - ConstructorInput, - ConstructorError, - Encoded, - Api -> { +): Schema { return new SchemaAnnotated(self, identifier, meta) } @@ -515,154 +194,41 @@ export function annotate( return (self) => self.annotate(annotation, meta) } -export function guard_< - ParserInput, - ParserError extends AnyError, - ParsedShape, - ConstructorInput, - ConstructorError extends AnyError, - Encoded, - Api ->( - self: Schema< - ParserInput, - ParserError, - ParsedShape, - ConstructorInput, - ConstructorError, - Encoded, - Api - >, +export function guard_( + self: Schema, guard: (u: unknown) => u is ParsedShape -): Schema< - ParserInput, - ParserError, - ParsedShape, - ConstructorInput, - ConstructorError, - Encoded, - Api -> { +): Schema { return new SchemaGuard(self, guard) } export function guard( guard: (u: unknown) => u is ParsedShape -): < - ParserInput, - ParserError extends AnyError, - ConstructorInput, - ConstructorError extends AnyError, - Encoded, - Api ->( - self: Schema< - ParserInput, - ParserError, - ParsedShape, - ConstructorInput, - ConstructorError, - Encoded, - Api - > -) => Schema< - ParserInput, - ParserError, - ParsedShape, - ConstructorInput, - ConstructorError, - Encoded, - Api -> { +): ( + self: Schema +) => Schema { return (self) => new SchemaGuard(self, guard) } export function into_< ParserInput, - ParserError extends AnyError, ParsedShape, ConstructorInput, - ConstructorError extends AnyError, Encoded, Api, - ThatParserError extends AnyError, ThatParsedShape, ThatConstructorInput, - ThatConstructorError extends AnyError, ThatApi >( - self: Schema< - ParserInput, - ParserError, - ParsedShape, - ConstructorInput, - ConstructorError, - Encoded, - Api - >, - that: Schema< - ParsedShape, - ThatParserError, - ThatParsedShape, - ThatConstructorInput, - ThatConstructorError, - ParsedShape, - ThatApi - > -): Schema< - ParserInput, - CompositionE | NextE>, - ThatParsedShape, - ThatConstructorInput, - ThatConstructorError, - Encoded, - ThatApi -> { + self: Schema, + that: Schema +): Schema { return new SchemaPipe(self, that) } -export function into< - Api, - ThatParserError extends AnyError, - ThatParsedShape, - ThatConstructorInput, - ThatConstructorError extends AnyError, - ThatApi, - ParsedShape ->( - that: Schema< - ParsedShape, - ThatParserError, - ThatParsedShape, - ThatConstructorInput, - ThatConstructorError, - ParsedShape, - ThatApi - > -): < - ParserInput, - ParserError extends AnyError, - ConstructorInput, - ConstructorError extends AnyError, - Encoded ->( - self: Schema< - ParserInput, - ParserError, - ParsedShape, - ConstructorInput, - ConstructorError, - Encoded, - Api - > -) => Schema< - ParserInput, - CompositionE | NextE>, - ThatParsedShape, - ThatConstructorInput, - ThatConstructorError, - Encoded, - ThatApi -> { +export function into( + that: Schema +): ( + self: Schema +) => Schema { return (self) => new SchemaPipe(self, that) } diff --git a/packages/schema/src/_schema/schema.ts b/packages/schema/src/_schema/schema.ts index 87210c7..3ae7c4c 100644 --- a/packages/schema/src/_schema/schema.ts +++ b/packages/schema/src/_schema/schema.ts @@ -1,3 +1,5 @@ +/* eslint-disable @typescript-eslint/ban-types */ +/* eslint-disable @typescript-eslint/no-explicit-any */ // tracing: off import type { Refinement } from "@effect-ts/core/Function" @@ -6,7 +8,7 @@ import type * as fc from "fast-check" import type * as Th from "../These" import type { Annotation } from "./annotation" -import type { AnyError, CompositionE, NamedE, NextE, PrevE, RefinementE } from "./error" +import type { AnyError } from "./error" // CompositionE, NamedE, NextE, PrevE, RefinementE export const SchemaSym = Symbol() export type SchemaSym = typeof SchemaSym @@ -24,76 +26,38 @@ export type SchemaSym = typeof SchemaSym * * 4) interacted with via `Api` */ -export abstract class Schema< - ParserInput, - ParserError extends AnyError, - ParsedShape, - ConstructorInput, - ConstructorError extends AnyError, - Encoded, - Api -> { +export abstract class Schema { readonly [SchemaSym]: SchemaSym = SchemaSym readonly _ParserInput!: (_: ParserInput) => void - readonly _ParserError!: () => ParserError + readonly _ParserError!: () => any readonly _ParsedShape!: () => ParsedShape readonly _ConstructorInput!: (_: ConstructorInput) => void - readonly _ConstructorError!: () => ConstructorError + readonly _ConstructorError!: () => any readonly _Encoded!: () => Encoded abstract readonly Api: Api - readonly [">>>"] = < - ThatParserError extends AnyError, - ThatParsedShape, - ThatConstructorInput, - ThatConstructorError extends AnyError, - ThatApi - >( + readonly [">>>"] = ( that: Schema< ParsedShape, - ThatParserError, ThatParsedShape, ThatConstructorInput, - ThatConstructorError, ParsedShape, ThatApi > - ): Schema< - ParserInput, - CompositionE | NextE>, - ThatParsedShape, - ThatConstructorInput, - ThatConstructorError, - Encoded, - ThatApi - > => new SchemaPipe(this, that) + ): Schema => + new SchemaPipe(this, that) readonly annotate = ( identifier: Annotation, meta: Meta - ): Schema< - ParserInput, - ParserError, - ParsedShape, - ConstructorInput, - ConstructorError, - Encoded, - Api - > => new SchemaAnnotated(this, identifier, meta) + ): Schema => + new SchemaAnnotated(this, identifier, meta) } -export type SchemaAny = Schema -export type SchemaUPI = Schema +export type SchemaAny = Schema +export type SchemaUPI = Schema -export type Standard = Schema< - unknown, - AnyError, - A, - A, - AnyError, - Enc, - {} -> +export type Standard = Schema export interface ApiSelfType { _AS: AS @@ -109,10 +73,8 @@ export type SchemaContinuationSymbol = typeof SchemaContinuationSymbol export interface HasContinuation { readonly [SchemaContinuationSymbol]: Schema< unknown, - AnyError, unknown, unknown, - AnyError, unknown, unknown > @@ -120,82 +82,65 @@ export interface HasContinuation { export function hasContinuation< ParserInput, - ParserError extends AnyError, ParsedShape, ConstructorInput, - ConstructorError extends AnyError, Encoded, Api >( - schema: Schema< - ParserInput, - ParserError, - ParsedShape, - ConstructorInput, - ConstructorError, - Encoded, - Api - > -): schema is Schema< - ParserInput, - ParserError, - ParsedShape, - ConstructorInput, - ConstructorError, - Encoded, - Api -> & + schema: Schema +): schema is Schema & HasContinuation { return SchemaContinuationSymbol in schema } -export type ParserInputOf> = [ - X -] extends [Schema] +export type ParserInputOf> = [X] extends [ + Schema +] ? Y : never -export type ParserErrorOf> = [ - X -] extends [Schema] - ? Y extends AnyError +export type ParserErrorOf> = [X] extends [ + Schema +] + ? any /*Y extends AnyError ? Y - : never + : never*/ : never -export type ConstructorInputOf> = [ +export type ConstructorInputOf> = [ X -] extends [Schema] +] extends [Schema] ? Y : never -export type ConstructorErrorOf> = [ +export type ConstructorErrorOf> = [ X -] extends [Schema] - ? Y extends AnyError +] extends [Schema] + ? any /*Y extends AnyError ? Y : never + */ : never -export type EncodedOf> = [ - X -] extends [Schema] +export type EncodedOf> = [X] extends [ + Schema +] ? Y : never -export type ParsedShapeOf> = [ - X -] extends [Schema] +export type ParsedShapeOf> = [X] extends [ + Schema +] ? Y : never -export type ApiOf> = [X] extends [ - Schema +export type ApiOf> = [X] extends [ + Schema ] ? Y : never -export class SchemaIdentity extends Schema { +export class SchemaIdentity extends Schema { readonly Api = {} constructor(readonly guard: (_: unknown) => _ is A) { @@ -205,24 +150,13 @@ export class SchemaIdentity extends Schema { export class SchemaConstructor< NewConstructorInput, - NewConstructorError extends AnyError, ParserInput, - ParserError extends AnyError, ParsedShape, ConstructorInput, - ConstructorError extends AnyError, - Encoded, - Api - > - extends Schema< - ParserInput, - ParserError, - ParsedShape, - NewConstructorInput, - NewConstructorError, Encoded, Api > + extends Schema implements HasContinuation { get Api() { @@ -231,16 +165,8 @@ export class SchemaConstructor< readonly [SchemaContinuationSymbol]: SchemaAny constructor( - readonly self: Schema< - ParserInput, - ParserError, - ParsedShape, - ConstructorInput, - ConstructorError, - Encoded, - Api - >, - readonly of: (i: NewConstructorInput) => Th.These + readonly self: Schema, + readonly of: (i: NewConstructorInput) => Th.These ) { super() this[SchemaContinuationSymbol] = self @@ -249,24 +175,13 @@ export class SchemaConstructor< export class SchemaParser< NewParserInput, - NewParserError extends AnyError, ParserInput, - ParserError extends AnyError, ParsedShape, ConstructorInput, - ConstructorError extends AnyError, - Encoded, - Api - > - extends Schema< - NewParserInput, - NewParserError, - ParsedShape, - ConstructorInput, - ConstructorError, Encoded, Api > + extends Schema implements HasContinuation { get Api() { @@ -276,40 +191,16 @@ export class SchemaParser< readonly [SchemaContinuationSymbol]: SchemaAny constructor( - readonly self: Schema< - ParserInput, - ParserError, - ParsedShape, - ConstructorInput, - ConstructorError, - Encoded, - Api - >, - readonly parser: (i: NewParserInput) => Th.These + readonly self: Schema, + readonly parser: (i: NewParserInput) => Th.These ) { super() this[SchemaContinuationSymbol] = self } } -export class SchemaArbitrary< - ParserInput, - ParserError extends AnyError, - ParsedShape, - ConstructorInput, - ConstructorError extends AnyError, - Encoded, - Api - > - extends Schema< - ParserInput, - ParserError, - ParsedShape, - ConstructorInput, - ConstructorError, - Encoded, - Api - > +export class SchemaArbitrary + extends Schema implements HasContinuation { get Api() { @@ -319,15 +210,7 @@ export class SchemaArbitrary< readonly [SchemaContinuationSymbol]: SchemaAny constructor( - readonly self: Schema< - ParserInput, - ParserError, - ParsedShape, - ConstructorInput, - ConstructorError, - Encoded, - Api - >, + readonly self: Schema, readonly arbitrary: (_: typeof fc) => fc.Arbitrary ) { super() @@ -337,23 +220,13 @@ export class SchemaArbitrary< export class SchemaEncoder< ParserInput, - ParserError extends AnyError, ParsedShape, ConstructorInput, - ConstructorError extends AnyError, Encoded, Api, Encoded2 > - extends Schema< - ParserInput, - ParserError, - ParsedShape, - ConstructorInput, - ConstructorError, - Encoded2, - Api - > + extends Schema implements HasContinuation { get Api() { @@ -363,15 +236,7 @@ export class SchemaEncoder< readonly [SchemaContinuationSymbol]: SchemaAny constructor( - readonly self: Schema< - ParserInput, - ParserError, - ParsedShape, - ConstructorInput, - ConstructorError, - Encoded, - Api - >, + readonly self: Schema, readonly encoder: (_: ParsedShape) => Encoded2 ) { super() @@ -383,35 +248,17 @@ export class SchemaRefinement< E extends AnyError, NewParsedShape extends ParsedShape, ParserInput, - ParserError extends AnyError, ParsedShape, ConstructorInput, - ConstructorError extends AnyError, - Encoded, - Api -> extends Schema< - ParserInput, - CompositionE | NextE>>, - NewParsedShape, - ConstructorInput, - CompositionE | NextE>>, Encoded, Api -> { +> extends Schema { get Api() { return this.self.Api } constructor( - readonly self: Schema< - ParserInput, - ParserError, - ParsedShape, - ConstructorInput, - ConstructorError, - Encoded, - Api - >, + readonly self: Schema, readonly refinement: Refinement, readonly error: (value: ParsedShape) => E ) { @@ -421,27 +268,15 @@ export class SchemaRefinement< export class SchemaPipe< ParserInput, - ParserError extends AnyError, ParsedShape, ConstructorInput, - ConstructorError extends AnyError, Encoded, Api, - ThatParserError extends AnyError, ThatParsedShape, ThatConstructorInput, - ThatConstructorError extends AnyError, - ThatApi - > - extends Schema< - ParserInput, - CompositionE | NextE>, - ThatParsedShape, - ThatConstructorInput, - ThatConstructorError, - Encoded, ThatApi > + extends Schema implements HasContinuation { get Api() { @@ -451,21 +286,11 @@ export class SchemaPipe< readonly [SchemaContinuationSymbol]: SchemaAny = this.that constructor( - readonly self: Schema< - ParserInput, - ParserError, - ParsedShape, - ConstructorInput, - ConstructorError, - Encoded, - Api - >, + readonly self: Schema, readonly that: Schema< ParsedShape, - ThatParserError, ThatParsedShape, ThatConstructorInput, - ThatConstructorError, ParsedShape, ThatApi > @@ -476,23 +301,12 @@ export class SchemaPipe< export class SchemaMapParserError< ParserInput, - ParserError extends AnyError, - ParserError2 extends AnyError, ParsedShape, ConstructorInput, - ConstructorError extends AnyError, - Encoded, - Api - > - extends Schema< - ParserInput, - ParserError2, - ParsedShape, - ConstructorInput, - ConstructorError, Encoded, Api > + extends Schema implements HasContinuation { get Api() { @@ -502,16 +316,8 @@ export class SchemaMapParserError< readonly [SchemaContinuationSymbol]: SchemaAny = this.self constructor( - readonly self: Schema< - ParserInput, - ParserError, - ParsedShape, - ConstructorInput, - ConstructorError, - Encoded, - Api - >, - readonly mapError: (_: ParserError) => ParserError2 + readonly self: Schema, + readonly mapError: (_: any) => any ) { super() } @@ -519,23 +325,12 @@ export class SchemaMapParserError< export class SchemaMapConstructorError< ParserInput, - ParserError extends AnyError, ParsedShape, ConstructorInput, - ConstructorError extends AnyError, - ConstructorError2 extends AnyError, - Encoded, - Api - > - extends Schema< - ParserInput, - ParserError, - ParsedShape, - ConstructorInput, - ConstructorError2, Encoded, Api > + extends Schema implements HasContinuation { get Api() { @@ -545,16 +340,8 @@ export class SchemaMapConstructorError< readonly [SchemaContinuationSymbol]: SchemaAny = this.self constructor( - readonly self: Schema< - ParserInput, - ParserError, - ParsedShape, - ConstructorInput, - ConstructorError, - Encoded, - Api - >, - readonly mapError: (_: ConstructorError) => ConstructorError2 + readonly self: Schema, + readonly mapError: (_: any) => any ) { super() } @@ -562,23 +349,13 @@ export class SchemaMapConstructorError< export class SchemaMapApi< ParserInput, - ParserError extends AnyError, ParsedShape, ConstructorInput, - ConstructorError extends AnyError, Encoded, Api, Api2 > - extends Schema< - ParserInput, - ParserError, - ParsedShape, - ConstructorInput, - ConstructorError, - Encoded, - Api2 - > + extends Schema implements HasContinuation { @LazyGetter() @@ -589,15 +366,7 @@ export class SchemaMapApi< readonly [SchemaContinuationSymbol]: SchemaAny = this.self constructor( - readonly self: Schema< - ParserInput, - ParserError, - ParsedShape, - ConstructorInput, - ConstructorError, - Encoded, - Api - >, + readonly self: Schema, readonly mapApi: (_: Api) => Api2 ) { super() @@ -606,23 +375,13 @@ export class SchemaMapApi< export class SchemaNamed< ParserInput, - ParserError extends AnyError, ParsedShape, ConstructorInput, - ConstructorError extends AnyError, Encoded, Api, Name extends string > - extends Schema< - ParserInput, - NamedE, - ParsedShape, - ConstructorInput, - NamedE, - Encoded, - Api - > + extends Schema implements HasContinuation { get Api() { @@ -632,15 +391,7 @@ export class SchemaNamed< readonly [SchemaContinuationSymbol]: SchemaAny = this.self constructor( - readonly self: Schema< - ParserInput, - ParserError, - ParsedShape, - ConstructorInput, - ConstructorError, - Encoded, - Api - >, + readonly self: Schema, readonly name: Name ) { super() @@ -681,23 +432,13 @@ export function isAnnotatedSchema( export class SchemaAnnotated< ParserInput, - ParserError extends AnyError, ParsedShape, ConstructorInput, - ConstructorError extends AnyError, Encoded, Api, Meta > - extends Schema< - ParserInput, - ParserError, - ParsedShape, - ConstructorInput, - ConstructorError, - Encoded, - Api - > + extends Schema implements HasContinuation { get Api() { @@ -709,15 +450,7 @@ export class SchemaAnnotated< readonly [SchemaContinuationSymbol]: SchemaAny = this.self constructor( - readonly self: Schema< - ParserInput, - ParserError, - ParsedShape, - ConstructorInput, - ConstructorError, - Encoded, - Api - >, + readonly self: Schema, readonly annotation: Annotation, readonly meta: Meta ) { @@ -725,24 +458,8 @@ export class SchemaAnnotated< } } -export class SchemaGuard< - ParserInput, - ParserError extends AnyError, - ParsedShape, - ConstructorInput, - ConstructorError extends AnyError, - Encoded, - Api - > - extends Schema< - ParserInput, - ParserError, - ParsedShape, - ConstructorInput, - ConstructorError, - Encoded, - Api - > +export class SchemaGuard + extends Schema implements HasContinuation { get Api() { @@ -752,39 +469,15 @@ export class SchemaGuard< readonly [SchemaContinuationSymbol]: SchemaAny = this.self constructor( - readonly self: Schema< - ParserInput, - ParserError, - ParsedShape, - ConstructorInput, - ConstructorError, - Encoded, - Api - >, + readonly self: Schema, readonly guard: (u: unknown) => u is ParsedShape ) { super() } } -export class SchemaLazy< - ParserInput, - ParserError extends AnyError, - ParsedShape, - ConstructorInput, - ConstructorError extends AnyError, - Encoded, - Api - > - extends Schema< - ParserInput, - ParserError, - ParsedShape, - ConstructorInput, - ConstructorError, - Encoded, - {} - > +export class SchemaLazy + extends Schema implements HasContinuation { readonly Api = {} @@ -794,25 +487,15 @@ export class SchemaLazy< } @LazyGetter() - get lazy(): Schema< - ParserInput, - ParserError, - ParsedShape, - ConstructorInput, - ConstructorError, - Encoded, - Api - > { + get lazy(): Schema { return this.self() } constructor( readonly self: () => Schema< ParserInput, - ParserError, ParsedShape, ConstructorInput, - ConstructorError, Encoded, Api >