Skip to content

arckit-dev/effect

Repository files navigation

@arckit/effect

Effect Schema utilities for domain modeling with branded types.

npm version npm downloads bundle size codecov TypeScript Effect

📑 Table of Contents

🪧 About

Factory function for creating domain models backed by Effect Schema. Produces callable model constructors with embedded schema validation and optional input transformation.

📦 Installation

pnpm add @arckit/effect

🚀 Usage

import { 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>; // string

Access the underlying schema for validation:

const validation = Schema.Struct({
  firstname: Firstname.schema
});

📖 API

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).

🤗 Contributing

See CONTRIBUTING.md for details.

📝 License

MIT © Marc Gavanier

About

Effect Schema utilities for domain modeling with branded types and input transformation

Resources

License

Contributing

Stars

Watchers

Forks

Packages

 
 
 

Contributors