Published API · 0.1.0-rc.1
foldkit · schema
Published foldkit API declarations for schema.
./schema
@wsagency/wseffect-foldkit · MIT · source · MIT license · WS-AGENCY-NOTICE · THIRD-PARTY-NOTICES
This entry point is published in @wsagency/wseffect-foldkit@0.1.0-rc.1. Import it from the package subpath shown below; the signatures and documentation are read from the installed package declarations.
import * as Wseffect from '@wsagency/wseffect-foldkit/schema'
Exported declarations
CallableTaggedStruct
A `TaggedStruct` schema that can be called directly as a constructor: `Foo({ count: 1 })` instead of `Foo.make({ count: 1 })`.
export type CallableTaggedStruct<Tag extends string, Fields extends Schema.Struct.Fields> = Schema.TaggedStruct<Tag, Fields> & (keyof Fields extends never ? (value?: Parameters<Schema.TaggedStruct<Tag, Fields>['make']>[0] | void) => Types.Simplify<Schema.Struct.Type<{
readonly _tag: Schema.tag<Tag>;
} & Fields>> : (value: Parameters<Schema.TaggedStruct<Tag, Fields>['make']>[0]) => Types.Simplify<Schema.Struct.Type<{
readonly _tag: Schema.tag<Tag>;
} & Fields>>);
defineTaggedUnion
Declares every variant of a domain union in one object. Use it for Model
states, submission results, filter modes, and other unions that are not
Messages or Routes.
The result is both a Schema and a namespace. It provides:
- One callable Schema constructor per variant.
- `match` for exhaustive handling.
- `matchOrElse` for selected variants with a fallback for the rest.
- `guards` and `isAnyOf` for variant checks.
- `subset` for a Schema that accepts only the named variants.
- `members` for APIs such as `Machine.define` that enumerate the union.
Use `taggedStruct` when the variants cannot be declared together. Recursive
unions and standalone tagged structs are the common cases.
A tag cannot use a name already owned by the union, such as `make`, `match`,
`matchOrElse`, `cases`, `ast`, `members`, or `subset`. TypeScript rejects
these names, and untyped calls throw an error.
export declare function defineTaggedUnion<const CasesByTag extends Record<string, Schema.Struct.Fields>>(casesByTag: CasesByTag & ValidateVariantNames<CasesByTag>): TaggedUnion<CasesByTag>;
taggedStruct
export declare function taggedStruct<Tag extends string, Fields extends Schema.Struct.Fields>(tag: Tag, fields: Fields): CallableTaggedStruct<Tag, Fields>;
taggedStruct
Declares one tagged struct as a callable Schema. Call `Loading()` instead of
`Loading.make()`.
Prefer `defineTaggedUnion` when every variant can be declared together. Use
`taggedStruct` for a recursive union, a union assembled across modules, a
tagged child struct that is not a union variant, or a variant created inside
a generic Schema factory.
export declare function taggedStruct<Tag extends string>(tag: Tag): CallableTaggedStruct<Tag, {}>;
TaggedUnion
The Schema returned by `defineTaggedUnion`. It includes callable variant
constructors, exhaustive `match`, partial `matchOrElse`, `guards`,
`isAnyOf`, `subset`, and `members`. With no output type argument, `match`
returns the union of the handler results. Pass an output type argument when
every handler must return that type. Pass a structurally refined union as
the optional second type argument to preserve narrower payload fields in
each handler.
export type TaggedUnion<CasesByTag extends Record<string, Schema.Struct.Fields>> = RichUnionSchema<CasesByTag> & {
readonly [Tag in keyof CasesByTag & string]: CallableTaggedStruct<Tag, CasesByTag[Tag]>;
};