@arckit/effect
v1.0.1
Published
Effect Schema utilities for domain modeling with branded types
Maintainers
Readme
@arckit/effect
Effect Schema utilities for domain modeling with branded types.
📑 Table of Contents
- 🪧 About
- 📦 Installation
- 🚀 Usage
- 📖 API
- 🤗 Contributing
- 📝 License
Factory function for creating domain models backed by Effect Schema. Produces callable model constructors with embedded schema validation and optional input transformation.
pnpm add @arckit/effectimport { defineModel } from '@arckit/effect';
import { Schema } from 'effect';
const Firstname = defineModel(
Schema.NonEmptyTrimmedString,
(input) => input.charAt(0).toUpperCase() + input.slice(1).toLowerCase()
);
const firstname = Firstname('jean'); // 'Jean' (branded NonEmptyTrimmedString)Use Model.TypeOf and Model.EncodedOf to extract types:
type FirstnameType = Model.TypeOf<typeof Firstname>; // branded string
type FirstnameInput = Model.EncodedOf<typeof Firstname>; // stringAccess the underlying schema for validation:
const validation = Schema.Struct({
firstname: Firstname.schema
});defineModel<S>(schema, transform?) => Model<S>
| Parameter | Description |
|-----------|-------------|
| schema | An Effect Schema.Schema defining the domain type |
| transform | Optional function to transform the input before decoding (e.g., normalize casing) |
Returns a Model<S> — a callable that decodes input through the schema, with a .schema property for validation use.
Model.TypeOf<M>
Extracts the decoded type from a model (the branded/refined type).
Model.EncodedOf<M>
Extracts the encoded type from a model (the raw input type).
See CONTRIBUTING.md for details.
MIT © Marc Gavanier
