Skip to content

Releases: leafo/tableshape

v2.6.0

03 Jan 02:57
Compare
Choose a tag to compare

Changes

  • Remove undocumented type_switch helper function
  • Remove the __eq metamethod on the type objects

Full Changelog: v2.5.0...v2.6.0

v2.5.0

15 Nov 05:34
Compare
Choose a tag to compare

Install

luarocks install tableshape
opm get leafo/tableshape

What's new?

  • add subclass_of MoonScript type checker

What's changed?

  • add strict type coersion/assertion for types that can take values instead of type literals. Specific changes listed below
  • add strict type coersion/assertion to * and + operators: you must pass a valid type or something that can unambiguously be converted into a type literal
  • + operator can simplify node tree if combining with another add node on both left and right hand side
  • Undocumented: types.pattern coerce option has been reimplemented, supports using a type transformer
  • Undocumented: types.pattern remove initial_type option
  • Undocumented and unused transformer = true field on the Transform type has been removed
  • Reimplement types.integer using updated types.pattern

Removal of internal self.opts field on nodes

These changes should not affect you unless you were using undocumented functionality. The overall goals of these changes are to standardize how type nodes are configured, simplify arguments for type node constructors, and remove multiple ways to accomplish the same thing

  • There was an undocumented field on some tableshape types called opts that could be used to control some aspects of the type
    • The default constructor of BaseType would look at self.opts, if it existed, to alter its behavior
    • This self.opts field has been removed from all nodes
    • Instead of having general purpose opts field, each node now must implement their own constructor to handle arguments as they see fit. No documented argument signatures have been changed, but a undocumented final opts argument has been removed from many type node constructors
  • Undocumented featured removed: Previously it was possible to pass in optional = true to an options object to automatically call is_optional on the resulting node. This has been removed
  • Undocumented feature removed: Previously it was possible for override the _describe method by passing in a describe field to the options of some nodes. This has been removed. Use the :describe method to return a new node with that description.
  • The undocumented clone_opts method is now disabled and will throw an error. It previously would clone the opts field
  • The default constructor is now an empty function. It is not necessary to call super when inheriting from BaseType when creating your own type class

Stricter validation on options parsing for various types, clean up of arguments

For nodes where the opts argument has been removed: Many nodes supported a last argument of an options table that would be assigned to self.opts. This was inconsistently implemented, but has been universally removed in this update. See the list below to see what nodes are affected.

  • AnnotateNode: format_error option must always be a function if provided
  • AnnotateNode: remove self.opts
  • OptionalType: remove self.opts, remove opts argument
  • Type: length option now uses coerce_literal to guarantee a valid value is passed for type checking
  • Type: remove self.opts
  • ArrayType: remove self.opts, remove opts argument
  • OneOf: remove self.opts, remove opts argument
  • AllOf: remove self.opts, remove opts argument
  • ArrayOf: length option now uses coerce_literal
  • ArrayOf: remove self.opts, remove opts argument
  • ArrayContains: remove self.opts, remove opts argument
  • MapOf: Expected key and value now use coerce_literal
  • MapOf: remove self.opts, remove opts argument
  • Shape: extra_fields option is now asserted to be a subclass of BaseType
  • Shape: is_open will exclude the extra_fields option when creating the new Shape object
  • Shape: remove self.opts
  • Pattern: remove self.opts,
  • Literal: remove self.opts, remove opts argument
  • Custom: assert that the custom checker is a function type
  • Custom: remove self.opts, remove opts argument
  • Equivalent: remove self.opts, remove opts argument
  • Range: remove self.opts, remove opts argument
  • Proxy: remove self.opts, remove opts argument
  • AssertType: remove self.opts, remove opts argument
  • NotType: remove self.opts, remove opts argument
  • MetatableIsType: remove self.opts

Full Changelog: v2.4.0...v2.5.0

v2.4.0

30 Oct 07:16
Compare
Choose a tag to compare

What's New

  • add types.metatable_is(t) type constructor for testing the type of a table's metatable
  • add types.clone as a special type checker that will shallow clone an object via its transformation (that is valid to be cloned)
  • add types.null as an alias for nil checker, so you can reference it without quoting it in Lua
  • add __tostring metamethod on all type objects. Converting a type object into a string will display its description

Bug Fixes

  • MoonScript type checkers for instances no longer incorrectly return true when passed class objects. They will only return true when passed an appropriate instance of a MoonScript class
  • is_type does not incorrectly return true when passed a class object extended from BaseType. It only returns true when passed an instance of a type checker. For example, passing in a type constructor types.is_type(types.shape) used to return true but now correctly returns false. The result of types.is_type(types.shape({...})) will still correctly return true`

Misc

  • Minor refactoring of internal code with regard to describing nodes
  • Clarify many parts of the documentation regarding how state works
  • Write clear example about transform and avoiding mutating objects

Full Changelog: v2.3.0...v2.4.0

v2.3.0

31 May 19:12
Compare
Choose a tag to compare

What's Changed

  • Provide missing _describe implementations for map_of and equivalent
  • Fix bug where tag (and scope) nodes would not correctly show the tag name when describing
  • assert node uses the assertproperty of the class instead of directly calling the assert global, so it can be overwritten by subclasses
  • Minor readme typo fixes

New Contributors

Full Changelog: v2.2.0...v2.3.0

v2.2.0

04 Nov 22:16
Compare
Choose a tag to compare

Originally published Jan 25 2021

https://luarocks.org/modules/leafo/tableshape/2.2.0-1

  • Fixed bug where state could be overidden when tagging in array_contains
  • Expose (and add docs for) for types.proxy
  • Add experimental Annotated type
  • Update test suite to GitHub Actions

v2.1.0

20 Oct 00:32
Compare
Choose a tag to compare
  • Add types.partial alias for open shape
  • Add types.array_contains
  • Add not type, and unary minus operator
  • Add MoonScript module: class_type, instance_type, instance_type checkers