Skip to main content
The Deno 2 Release Candidate is here
Learn more
Module

x/domain_functions/mod.ts

Types and functions to make composition easy and safe
Latest
import * as domainFunctions from "https://deno.land/x/domain_functions@v3.0.0/mod.ts";

Classes

A custom error class for environment errors.

A custom error class for input errors.

A custom error class for creating ErrorResult.

Functions

Creates a single domain function out of multiple domain functions. It will pass the same input and environment to each provided function. The functions will run in parallel. If all constituent functions are successful, The data field will be a tuple containing each function's output.

Use it to add conditional logic to your domain functions' compositions. It receives a domain function and a predicate function that should return the next domain function to be executed based on the previous domain function's output, like pipe. If the predicate returns null the result of the previous domain function will be returned and it won't be piped.

Receives a Record of domain functions, runs them all in parallel and preserves the shape of this record for the data property in successful results.

Receives a Record of domain functions, runs them all in sequence like pipe but preserves the shape of that record for the data property in successful results. It will pass the same environment to all given functions, and it will pass the output of a function as the next function's input in the given order.

Extracts the error messages for a property from the given ErrorResult.

Creates a composite domain function that will return the result of the first successful constituent domain function. It is important to notice that all constituent domain functions will be executed in parallel, so be mindful of the side effects.

A functions that helps incremental migration from the legacy domain-functions library to the composable-functions. Both libraries can be installed simultaneously, but to mix and match functions in compositions using toComposable and fromComposable are necessary to ensure the error types are compatible. It will convert any Composable<(input?: unknown, environment?: unknown) => T> into a DomainFunction

It can be used to call a domain function from another domain function. It will return the output of the given domain function if it was successfull, otherwise it will throw a ResultError that will bubble up to the parent function. Also good to use it in successfull test cases.

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.

It takes a domain function and a predicate to apply a transformation over the result.data of that function. It only runs if the function was successfull. When the given domain function fails, its error is returned wihout changes.

Creates a single domain function that will apply a transformation over the ErrorResult of a failed DomainFunction. When the given domain function succeeds, its result is returned without changes.

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.

NOTE : Try to use collect instead wherever possible since it is much safer. merge can create domain functions that will always fail in run-time or even overwrite data from successful constituent functions application. The collect function does not have these issues and serves a similar purpose.

Creates a single domain function out of a chain of multiple domain functions. It will pass the same environment to all given functions, and it will pass the output of a function as the next function's input in left-to-right order. The resulting data will be the output of the rightmost function.

A functions that turns the result of its callback into a Result object.

Creates a SchemaError (used in inputErrors and environmentErrors) from the given message and path.

Works like pipe but it will collect the output of every function in a tuple, similar to all.

A functions that helps incremental migration from the legacy domain-functions library to the composable-functions. Both libraries can be installed simultaneously, but to mix and match functions in compositions using toComposable and fromComposable are necessary to ensure the error types are compatible. It will convert any DomainFunction into a Composable<(input?: unknown, environment?: unknown) => T>

Turns the given 'unknown' error into an ErrorWithMessage.

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.

Type Aliases

It is similar to Partial but it requires at least one property to be defined.

A domain function. It carries the output type which can be further unpacked with UnpackData and other type helpers.

The properties of the ErrorResult which carry information about what made the domain function fail.

A failed domain function result.

Items in the errors array returned by failed domain functions.

Returns the last item of a tuple type.

A parsing error when validating the input or environment schemas. This will be transformed into a SchemaError before being returned from the domain function. It is usually not visible to the end user unless one wants to write an adapter for a schema validator.

The result of input or environment validation. See the type Result for the return values of domain functions. It is usually not visible to the end user unless one wants to write an adapter for a schema validator.

The object used to validate either input or environment when creating domain functions.

The content of the Promise a domain function returns.

Items in the inputErrors and environmentErrors array returned by failed domain functions.

A successful domain function result.

Converts a tuple type to a union type.

Unpacks a list of DomainFunctions into a tuple of their data types.

Unpacks the data type of a successful domain function.

Unpacks the result of a domain function.

Unpacks the data type of a successful domain function.