Skip to content

Releases: GoogleFeud/ts-runtime-checks

v0.3.2

29 Jul 13:01
Compare
Choose a tag to compare

Additions

  • You can use the Assert marker in class methods, constructors and getters/setters.

Bug fixes

v0.3.1

24 Jul 13:13
757ae42
Compare
Choose a tag to compare

Bug fixes

  • Fixes #23.
  • The generation of recursive functions for types with type parameters is now correct:
interface Value<T> {
    val1?: Value<string>,
    val2?: Value<T>,
    value: T
}

const isValid = is<Value<number>>(...);

// Transpiles to:
function value_6(param_4) { return typeof param_4 === "object" && param_4 !== null && typeof param_4.value === "string" && (param_4.val1 === undefined || value_6(param_4.val1)) && (param_4.val2 === undefined || value_6(param_4.val2)); }
function value_7(param_5) { return typeof param_5 === "object" && param_5 !== null && typeof param_5.value === "number" && (param_5.val1 === undefined || value_6(param_5.val1)) && (param_5.val2 === undefined || value_7(param_5.val2)); }
const isValid = value_7(...);

v0.3.0

19 Jul 14:42
Compare
Choose a tag to compare

Breaking changes

  • Removed the If utility marker.
  • Removed the Str utility marker.
  • Removed the Num utility marker.
  • Removed the Arr utility marker.
  • You can no longer use JSDoc tags to specify extra checks.

Additions

  • A new utility type, Check which is a lot more flexible than If.
    • Allows you to provide a custom error message.
    • You can now use the $parent function to access the value's parent object.
    • You can chain checks with the & (intersection) operator.
    function test(value: Assert<number & Float & Min<1> & Max<10>>) {
    
    }
    
    // Transpiles to:
    function test(value) {
        if (typeof value !== "number" || Number.isInteger(value) || value < 1 || value > 10)
            throw new Error("Expected value to be a number, to be a float, to be greater than 1, to be less than 10");
    }
  • The library provides built-in Checks: Min, Max, Int, Float, MinLen, MaxLen, Length, Matches, Not, and Or.

Bug fixes

  • Fixes #16
  • Fixes issue with check utility function generating code that may throw an error

v0.2.0

08 Jul 12:40
Compare
Choose a tag to compare
  • Support for typescript 5.x.

Breaking Changes

  • Removed the EarlyReturn marker.
    • Assert can now be used to return expressions or the error message.
  • Type parameters no longer generate any validation code.

Additions

  • Infer and Resolve markers which allow you to generate validation checks for type parameters. (#7)
    • You can use Infer to create one big union out of all the possible types of the type parameter.
    • You can use Resolve to move the validation code for the entire type at the call site.
  • Full support for unions.
    • Transformer now generates validation code for unions that contain compound types such as objects or arrays.
    • If the union is made up of multiple objects, and each object has a property that is a string/number literal, the objects get differentiated by that property. (#15)
  • Full support for recursive types. (#9 and #16)
  • Validation code now gets generated for index signatures in objects.
  • You can now choose to provide / return a raw error object instead of an error string. The object contains the value that's incorrect, it's property name information about the supposed correct type.
  • You can now use JSDoc comments to specify extra configuration for the string, number, and Array types instead of using their respective utility markers.
  • ExactProps marker now sets the property to undefined instead of using the delete operator if removeExcessive is set to true. A third type parameter useDeleteOperator now switches back to the delete operator.
  • jsonSchema config option that will generate JSON schemas for types you specify, or all types in the project.
  • Boolean literals now get validated.

Changes

  • Changes in generated code, the transformer now can minimize it if necessary to use a lot less branching.
  • Changed how error messages are generated, which may look slightly different but give all the same information.

Bug fixes

v0.1.3

26 Jul 18:06
Compare
Choose a tag to compare

Changes

  • The check function now detects if it's used in array deconstruction assignment (const [a, b] = ...) and is able to completely eliminate it.
  • Removed the Matches type.
  • Removed the NumRange type.

Additions

  • Added a more general Str type which allows you to validate a string's length and test it against regex.
  • Added a more general Num type which allows you to validate a number.
  • Added a more general Arr type which allows you to validate an array's length.
  • Added an extra type parameter to the ExactProps type - if it's set to true, instead of erroring, the validator will delete the extra properties in place.

v0.1.2

21 Jul 18:41
Compare
Choose a tag to compare

Changes

  • ExactProps is now recursive.
  • Renamed Range to NumRange to avoid conflict with global type.
  • Error messages are now a lot nicer.

Additions

  • A check function which transpiles to an IIFE which validates the data and returns an array of errors.

v0.1.1

31 Mar 12:54
Compare
Choose a tag to compare

Changes

  • All markers now work with mapped types.
  • Values that have any / unknown as a type are now skipped.
  • ErrorMsg type. When it's provided to EarlyReturn it'll return the error messages.
  • Optional tuple members are now handled a bit differently - previously, they were handled like unions (type | undefined), which means values of compound types weren't being checked.

v0.1.0

29 Mar 18:00
Compare
Choose a tag to compare

First release of ts-runtime-checks! 🥳🥳