Effect Schema utilities for domain modeling with branded types.
- 🪧 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
});| 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.
Extracts the decoded type from a model (the branded/refined type).
Extracts the encoded type from a model (the raw input type).
See CONTRIBUTING.md for details.
MIT © Marc Gavanier