Skip to content

Contract

A rule to statically validate received data. Any object following the strict API could be used as a Contract.

Packages that use Contract

API reference

To create a Contract you need to provide an object with the following fields:

ts
interface Contract<Raw, Data extends Raw> {
  /**
   * Checks if Raw is Data
   */
  isData: (prepared: Raw) => prepared is Data;
  /**
   * - empty array is dedicated for valid response
   * - array of string with validation erorrs for invalidDataError
   */
  getErrorMessages: (prepared: Raw) => string[];
}

Released under the MIT License.