Skip to main content
Module

x/domain_functions/mod.ts

Decouple your business logic from your framework. With first-class type inference from end to end.
Latest
import * as domainFunctions from "https://deno.land/x/domain_functions@v2.6.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.

Variables

Parses the given Request's formData into an object.

Parses the given FormData into an object.

Parses the given URLSearchParams into an object.

Parses the given Request URL's queryString into an object.

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.

Takes a function with 2 parameters and partially applies the second one. This is useful when one wants to use a domain function having a fixed environment.

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.

Creates a single function out of multiple Composables. It will pass the same input 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.

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

Creates a composable function. That function is gonna catch any errors and always return a Result.

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

Creates a new function that will apply a transformation over a resulting Failure from the given function. When the given function succeeds, its result is returned without changes.

Creates a single function out of a chain of multiple Composables. 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.

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

Turns the given 'unknown' error into an ErrorWithMessage.

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.

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.

Merges a list of objects into a single object. It is a type-safe version of Object.assign.

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.

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.

Returns the last item of a tuple type.

Merges the data types of a list of objects.

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.