Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/domain_functions/src/constructor.ts>mdf

Types and functions to make composition easy and safe
Latest
function mdf
import { mdf } from "https://deno.land/x/domain_functions@v3.0.0/src/constructor.ts";

Creates a domain function. After giving the input and environment schemas, you can pass a handler function that takes type safe input and environment. That function is gonna catch any errors and always return a Result.

Examples

const safeFunction = makeDomainFunction( z.object({ greeting: z.string() }), z.object({ user: z.object({ name: z.string() }) }), ) const myDf = safeFunction(({ greeting }, { user }) => { return { message: ${greeting} ${user.name} } })

Parameters

optional
inputSchema: ParserSchema<I>

the schema for the input

optional
environmentSchema: ParserSchema<E>

the schema for the environment