Skip to main content
Module

x/domain_functions/src/domain-functions.ts>trace

Decouple your business logic from your framework. With first-class type inference from end to end.
Go to Latest
function trace
import { trace } from "https://deno.land/x/domain_functions@v2.6.0/src/domain-functions.ts";

Whenever you need to intercept inputs and a domain function result without changing them you can use this function. The most common use case is to log failures to the console or to an external service.

Examples

import { mdf, trace } from 'domain-functions'

const trackErrors = trace(({ input, output, result }) => { if(!result.success) sendToExternalService({ input, output, result }) }) const increment = mdf(z.object({ id: z.number() }))(({ id }) => id + 1) const incrementAndTrackErrors = trackErrors(increment) // ^? DomainFunction

Type Parameters

optional
D extends DomainFunction = DomainFunction<unknown>

Parameters

traceFn: (unnamed 0: TraceData<UnpackResult<D>>) => Promise<void> | void

A function that receives the input, environment and result of a domain function.