VariantSchema overview
Added in v1.0.0
Table of contents
- accessors
- constructors
- extractors
- guards
- models
- overrideable
- type ids
accessors
fields
Signature
export declare const fields: <A extends Struct<any>>(self: A) => A[TypeId]
Added in v1.0.0
constructors
make
Signature
export declare const make: <
const Variants extends ReadonlyArray<string>,
const Default extends Variants[number]
>(options: {
readonly variants: Variants
readonly defaultVariant: Default
}) => {
readonly Struct: <const A extends Struct.Fields>(fields: A & Struct.Validate<A, Variants[number]>) => Struct<A>
readonly Field: <const A extends Field.ConfigWithKeys<Variants[number]>>(
config: A & { readonly [K in Exclude<keyof A, Variants[number]>]: never }
) => Field<A>
readonly FieldOnly: <const Keys extends ReadonlyArray<Variants[number]>>(
...keys: Keys
) => <S extends Schema.Schema.All | Schema.PropertySignature.All>(
schema: S
) => Field<{ readonly [K in Keys[number]]: S }>
readonly FieldExcept: <const Keys extends ReadonlyArray<Variants[number]>>(
...keys: Keys
) => <S extends Schema.Schema.All | Schema.PropertySignature.All>(
schema: S
) => Field<{ readonly [K in Exclude<Variants[number], Keys[number]>]: S }>
readonly fieldEvolve: {
<
Self extends Field<any> | Field.ValueAny,
const Mapping extends Self extends Field<infer S>
? { readonly [K in keyof S]?: (variant: S[K]) => Field.ValueAny }
: { readonly [K in Variants[number]]?: (variant: Self) => Field.ValueAny }
>(
f: Mapping
): (
self: Self
) => Field<
Self extends Field<infer S>
? {
readonly [K in keyof S]: K extends keyof Mapping
? Mapping[K] extends (arg: any) => any
? ReturnType<Mapping[K]>
: S[K]
: S[K]
}
: {
readonly [K in Variants[number]]: K extends keyof Mapping
? Mapping[K] extends (arg: any) => any
? ReturnType<Mapping[K]>
: Self
: Self
}
>
<
Self extends Field<any> | Field.ValueAny,
const Mapping extends Self extends Field<infer S>
? { readonly [K in keyof S]?: (variant: S[K]) => Field.ValueAny }
: { readonly [K in Variants[number]]?: (variant: Self) => Field.ValueAny }
>(
self: Self,
f: Mapping
): Field<
Self extends Field<infer S>
? {
readonly [K in keyof S]: K extends keyof Mapping
? Mapping[K] extends (arg: any) => any
? ReturnType<Mapping[K]>
: S[K]
: S[K]
}
: {
readonly [K in Variants[number]]: K extends keyof Mapping
? Mapping[K] extends (arg: any) => any
? ReturnType<Mapping[K]>
: Self
: Self
}
>
}
readonly fieldFromKey: {
<
Self extends Field<any> | Field.ValueAny,
const Mapping extends Self extends Field<infer S>
? { readonly [K in keyof S]?: string }
: { readonly [K in Variants[number]]?: string }
>(
mapping: Mapping
): (
self: Self
) => Field<
Self extends Field<infer S>
? {
readonly [K in keyof S]: K extends keyof Mapping
? Mapping[K] extends string
? fromKey.Rename<S[K], Mapping[K]>
: S[K]
: S[K]
}
: {
readonly [K in Variants[number]]: K extends keyof Mapping
? Mapping[K] extends string
? fromKey.Rename<Self, Mapping[K]>
: Self
: Self
}
>
<
Self extends Field<any> | Field.ValueAny,
const Mapping extends Self extends Field<infer S>
? { readonly [K in keyof S]?: string }
: { readonly [K in Variants[number]]?: string }
>(
self: Self,
mapping: Mapping
): Field<
Self extends Field<infer S>
? {
readonly [K in keyof S]: K extends keyof Mapping
? Mapping[K] extends string
? fromKey.Rename<S[K], Mapping[K]>
: S[K]
: S[K]
}
: {
readonly [K in Variants[number]]: K extends keyof Mapping
? Mapping[K] extends string
? fromKey.Rename<Self, Mapping[K]>
: Self
: Self
}
>
}
readonly Class: <Self = never>(
identifier: string
) => <const Fields extends Struct.Fields>(
fields: Fields & Struct.Validate<Fields, Variants[number]>,
annotations?: Schema.Annotations.Schema<Self>
) => [Self] extends [never]
? MissingSelfGeneric
: ClassFromFields<Self, Fields, Schema.Simplify<ExtractFields<Default, Fields, true>>> & {
readonly [V in Variants[number]]: Extract<V, Struct<Fields>>
}
readonly Union: <const Members extends ReadonlyArray<Struct<any>>>(
...members: Members
) => Union<Members> & Union.Variants<Members, Variants[number]>
readonly extract: {
<V extends Variants[number]>(
variant: V
): <A extends Struct<any>>(self: A) => Extract<V, A, V extends Default ? true : false>
<V extends Variants[number], A extends Struct<any>>(
self: A,
variant: V
): Extract<V, A, V extends Default ? true : false>
}
}
Added in v1.0.0
extractors
Extract (type alias)
Signature
export type Extract<V extends string, A extends Struct<any>, IsDefault = false> = [A] extends [Struct<infer Fields>]
? IsDefault extends true
? [A] extends [Schema.Schema.Any]
? A
: Schema.Struct<Schema.Simplify<ExtractFields<V, Fields>>>
: Schema.Struct<Schema.Simplify<ExtractFields<V, Fields>>>
: never
Added in v1.0.0
ExtractFields (type alias)
Signature
export type ExtractFields<V extends string, Fields extends Struct.Fields, IsDefault = false> = {
readonly [K in keyof Fields as [Fields[K]] extends [Field<infer Config>]
? V extends keyof Config
? K
: never
: K]: [Fields[K]] extends [Struct<infer _>]
? Extract<V, Fields[K], IsDefault>
: [Fields[K]] extends [Field<infer Config>]
? [Config[V]] extends [Schema.Schema.All | Schema.PropertySignature.All]
? Config[V]
: never
: [Fields[K]] extends [Schema.Schema.All | Schema.PropertySignature.All]
? Fields[K]
: never
}
Added in v1.0.0
guards
isField
Signature
export declare const isField: (u: unknown) => u is Field<any>
Added in v1.0.0
isStruct
Signature
export declare const isStruct: (u: unknown) => u is Struct<any>
Added in v1.0.0
models
Class (interface)
Signature
export interface Class<Self, Fields extends Struct.Fields, SchemaFields extends Schema.Struct.Fields, A, I, R, C>
extends Schema.Schema<Self, Schema.Simplify<I>, R>,
Struct<Fields> {
new (
props: RequiredKeys<C> extends never ? void | Schema.Simplify<C> : Schema.Simplify<C>,
options?: {
readonly disableValidation?: boolean
}
): A
readonly ast: AST.Transformation
make<Args extends Array<any>, X>(this: { new (...args: Args): X }, ...args: Args): X
annotations(annotations: Schema.Annotations.Schema<Self>): Schema.SchemaClass<Self, Schema.Simplify<I>, R>
readonly identifier: string
readonly fields: SchemaFields
}
Added in v1.0.0
Field (interface)
Signature
export interface Field<in out A extends Field.Config> extends Pipeable {
readonly [FieldTypeId]: FieldTypeId
readonly schemas: A
}
Added in v1.0.0
Field (namespace)
Added in v1.0.0
Any (type alias)
Signature
export type Any = { readonly [FieldTypeId]: FieldTypeId }
Added in v1.0.0
Config (type alias)
Signature
export type Config = {
readonly [key: string]: Schema.Schema.All | Schema.PropertySignature.All | undefined
}
Added in v1.0.0
ConfigWithKeys (type alias)
Signature
export type ConfigWithKeys<K extends string> = {
readonly [P in K]?: Schema.Schema.All | Schema.PropertySignature.All
}
Added in v1.0.0
Fields (type alias)
Signature
export type Fields = {
readonly [key: string]: Schema.Schema.All | Schema.PropertySignature.All | Field<any> | Struct<any> | undefined
}
Added in v1.0.0
Struct (interface)
Signature
export interface Struct<in out A extends Field.Fields> extends Pipeable {
readonly [TypeId]: A
/** @internal */
[cacheSymbol]?: Record<string, Schema.Schema.All>
}
Added in v1.0.0
Struct (namespace)
Added in v1.0.0
Any (type alias)
Signature
export type Any = { readonly [TypeId]: any }
Added in v1.0.0
Fields (type alias)
Signature
export type Fields = {
readonly [key: string]: Schema.Schema.All | Schema.PropertySignature.All | Field<any> | Struct<any> | undefined
}
Added in v1.0.0
Validate (type alias)
Signature
export type Validate<A, Variant extends string> = {
readonly [K in keyof A]: A[K] extends { readonly [TypeId]: infer _ }
? Validate<A[K], Variant>
: A[K] extends Field<infer Config>
? [keyof Config] extends [Variant]
? {}
: "field must have valid variants"
: {}
}
Added in v1.0.0
Union (interface)
Signature
export interface Union<Members extends ReadonlyArray<Struct<any>>>
extends Schema.Union<{
readonly [K in keyof Members]: [Members[K]] extends [Schema.Schema.All] ? Members[K] : never
}> {}
Added in v1.0.0
Union (namespace)
Added in v1.0.0
Variants (type alias)
Signature
export type Variants<Members extends ReadonlyArray<Struct<any>>, Variants extends string> = {
readonly [Variant in Variants]: Schema.Union<{
[K in keyof Members]: Extract<Variant, Members[K]>
}>
}
Added in v1.0.0
fromKey (interface)
Signature
export interface fromKey<S extends Schema.Schema.All, Key extends string>
extends Schema.PropertySignature<
":",
Schema.Schema.Type<S>,
Key,
":",
Schema.Schema.Encoded<S>,
false,
Schema.Schema.Context<S>
> {}
Added in v1.0.0
fromKey (namespace)
Added in v1.0.0
Rename (type alias)
Signature
export type Rename<S, Key extends string> =
S extends Schema.PropertySignature<
infer _TypeToken,
infer _Type,
infer _Key,
infer _EncodedToken,
infer _Encoded,
infer _HasDefault,
infer _R
>
? Schema.PropertySignature<_TypeToken, _Type, Key, _EncodedToken, _Encoded, _HasDefault, _R>
: S extends Schema.Schema.All
? fromKey<S, Key>
: never
Added in v1.0.0
overrideable
Override
Signature
export declare const Override: <A>(value: A) => A & Brand<"Override">
Added in v1.0.0
Overrideable
Signature
export declare const Overrideable: <From, IFrom, RFrom, To, ITo, R>(
from: Schema.Schema<From, IFrom, RFrom>,
to: Schema.Schema<To, ITo>,
options: { readonly generate: (_: Option.Option<ITo>) => Effect.Effect<From, ParseResult.ParseIssue, R> }
) => Overrideable<To, IFrom, RFrom | R>
Added in v1.0.0
Overrideable (interface)
Signature
export interface Overrideable<To, From, R = never>
extends Schema.PropertySignature<":", (To & Brand<"Override">) | undefined, never, ":", From, true, R> {}
Added in v1.0.0
type ids
FieldTypeId
Signature
export declare const FieldTypeId: typeof FieldTypeId
Added in v1.0.0
FieldTypeId (type alias)
Signature
export type FieldTypeId = typeof FieldTypeId
Added in v1.0.0
TypeId
Signature
export declare const TypeId: typeof TypeId
Added in v1.0.0
TypeId (type alias)
Signature
export type TypeId = typeof TypeId
Added in v1.0.0