Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 3 additions & 19 deletions packages/schema/src/Arbitrary/_arbitrary/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,29 +23,13 @@ export const interpreters: ((schema: S.SchemaAny) => O.Option<() => Gen<unknown>
}
}
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_<ParserInput, ParsedShape, ConstructorInput, Encoded, Api>(
schema: S.Schema<ParserInput, ParsedShape, ConstructorInput, Encoded, Api>
): Gen<ParsedShape> {
if (cache.has(schema)) {
return cache.get(schema)
Expand Down
14 changes: 2 additions & 12 deletions packages/schema/src/Collect/_collect/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ParserInput, ParsedShape, ConstructorInput, Encoded, Api>
): CollectAnnotations {
if (cache.has(schema)) {
return cache.get(schema)
Expand Down
30 changes: 7 additions & 23 deletions packages/schema/src/Constructor/_constructor/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,38 +68,22 @@ 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<ConstructorInput, ParsedShape, ConstructorError> {
function constructorFor<ParserInput, ParsedShape, ConstructorInput, Encoded, Api>(
schema: S.Schema<ParserInput, ParsedShape, ConstructorInput, Encoded, Api>
): Constructor<ConstructorInput, ParsedShape, any> {
if (cache.has(schema)) {
return cache.get(schema)
}
if (schema instanceof S.SchemaLazy) {
const of_: Constructor<unknown, unknown, unknown> = (__) =>
constructorFor(schema.self())(__)
cache.set(schema, of_)
return of_ as Constructor<ConstructorInput, ParsedShape, ConstructorError>
return of_ as Constructor<ConstructorInput, ParsedShape, any>
}
for (const interpreter of interpreters) {
const _ = interpreter(schema)
Expand All @@ -112,7 +96,7 @@ function constructorFor<
return x(__)
}
cache.set(schema, of_)
return of_ as Constructor<ConstructorInput, ParsedShape, ConstructorError>
return of_ as Constructor<ConstructorInput, ParsedShape, any>
}
}
if (hasContinuation(schema)) {
Expand All @@ -123,7 +107,7 @@ function constructorFor<
}
return x(__)
}
return of_ as Constructor<ConstructorInput, ParsedShape, ConstructorError>
return of_ as Constructor<ConstructorInput, ParsedShape, any>
}
throw new Error(`Missing guard integration for: ${JSON.stringify(schema)}`)
}
Expand Down
22 changes: 3 additions & 19 deletions packages/schema/src/Encoder/_encoder/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ParserInput, ParsedShape, ConstructorInput, Encoded, Api>(
schema: S.Schema<ParserInput, ParsedShape, ConstructorInput, Encoded, Api>
): Encoder<ParsedShape, Encoded> {
if (cache.has(schema)) {
return cache.get(schema)
Expand Down
22 changes: 3 additions & 19 deletions packages/schema/src/Guard/_guard/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,29 +23,13 @@ export const interpreters: ((schema: S.SchemaAny) => O.Option<() => Guard<unknow
}
}
return miss()
})
}),
]

const cache = new WeakMap()

function guardFor<
ParserInput,
ParserError extends S.AnyError,
ParsedShape,
ConstructorInput,
ConstructorError extends S.AnyError,
Encoded,
Api
>(
schema: S.Schema<
ParserInput,
ParserError,
ParsedShape,
ConstructorInput,
ConstructorError,
Encoded,
Api
>
function guardFor<ParserInput, ParsedShape, ConstructorInput, Encoded, Api>(
schema: S.Schema<ParserInput, ParsedShape, ConstructorInput, Encoded, Api>
): Guard<ParsedShape> {
if (cache.has(schema)) {
return cache.get(schema)
Expand Down
30 changes: 7 additions & 23 deletions packages/schema/src/Parser/_parser/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,38 +99,22 @@ 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<ParserInput, ParserError, ParsedShape> {
function parserFor<ParserInput, ParsedShape, ConstructorInput, Encoded, Api>(
schema: Schema<ParserInput, ParsedShape, ConstructorInput, Encoded, Api>
): Parser<ParserInput, any, ParsedShape> {
if (cache.has(schema)) {
return cache.get(schema)
}
if (schema instanceof S.SchemaLazy) {
const parser: Parser<unknown, unknown, unknown> = (__) =>
parserFor(schema.self())(__)
cache.set(schema, parser)
return parser as Parser<ParserInput, ParserError, ParsedShape>
return parser as Parser<ParserInput, any, ParsedShape>
}
for (const interpreter of interpreters) {
const _ = interpreter(schema)
Expand All @@ -142,7 +126,7 @@ function parserFor<
}
return x(__)
}
return parser as Parser<ParserInput, ParserError, ParsedShape>
return parser as Parser<ParserInput, any, ParsedShape>
}
}
if (hasContinuation(schema)) {
Expand All @@ -154,7 +138,7 @@ function parserFor<
return x(__)
}
cache.set(schema, parser)
return parser as Parser<ParserInput, ParserError, ParsedShape>
return parser as Parser<ParserInput, any, ParsedShape>
}
throw new Error(`Missing parser integration for: ${schema.constructor}`)
}
Expand Down
26 changes: 3 additions & 23 deletions packages/schema/src/_api/array.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ParsedShape, ConstructorInput, Encoded, Api>(
self: S.Schema<unknown, ParsedShape, ConstructorInput, Encoded, Api>
): DefaultSchema<
unknown,
S.CompositionE<
| S.PrevE<S.RefinementE<S.LeafE<S.UnknownArrayE>>>
| S.NextE<S.CollectionE<S.OptionalIndexE<number, ParserError>>>
>,
readonly ParsedShape[],
readonly ParsedShape[],
never,
readonly Encoded[],
{ self: Api }
> {
Expand All @@ -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 })),
Expand Down
11 changes: 1 addition & 10 deletions packages/schema/src/_api/bool.ts
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -10,15 +9,7 @@ import { withDefaults } from "./withDefaults"

export const boolIdentifier = makeAnnotation<{}>()

export const bool: DefaultSchema<
unknown,
S.RefinementE<S.LeafE<ParseBoolE>>,
boolean,
boolean,
never,
boolean,
{}
> = pipe(
export const bool: DefaultSchema<unknown, boolean, boolean, boolean, {}> = pipe(
refinement(
(u): u is boolean => typeof u === "boolean",
(v) => S.leafE(parseBoolE(v))
Expand Down
31 changes: 3 additions & 28 deletions packages/schema/src/_api/brand.ts
Original file line number Diff line number Diff line change
@@ -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<B>() {
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<B>
> => {
return <ParserInput, ParsedShape, ConstructorInput, Encoded, Api>(
self: Schema<ParserInput, ParsedShape, ConstructorInput, Encoded, Api>
): DefaultSchema<ParserInput, B, ConstructorInput, Encoded, Api & ApiSelfType<B>> => {
// @ts-expect-error
return withDefaults(self)
}
Expand Down
Loading