Releases: leafo/tableshape
Releases · leafo/tableshape
v2.6.0
v2.5.0
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
removeinitial_type
option - Undocumented and unused
transformer = true
field on the Transform type has been removed - Reimplement
types.integer
using updatedtypes.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 atself.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 finalopts
argument has been removed from many type node constructors
- The default constructor of
- Undocumented featured removed: Previously it was possible to pass in
optional = true
to an options object to automatically callis_optional
on the resulting node. This has been removed - Undocumented feature removed: Previously it was possible for override the
_describe
method by passing in adescribe
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 theopts
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
, removeopts
argument - Type:
length
option now usescoerce_literal
to guarantee a valid value is passed for type checking - Type: remove
self.opts
- ArrayType: remove
self.opts
, removeopts
argument - OneOf: remove
self.opts
, removeopts
argument - AllOf: remove
self.opts
, removeopts
argument - ArrayOf:
length
option now usescoerce_literal
- ArrayOf: remove
self.opts
, removeopts
argument - ArrayContains: remove
self.opts
, removeopts
argument - MapOf: Expected key and value now use
coerce_literal
- MapOf: remove
self.opts
, removeopts
argument - Shape:
extra_fields
option is now asserted to be a subclass ofBaseType
- Shape:
is_open
will exclude theextra_fields
option when creating the newShape
object - Shape: remove
self.opts
- Pattern: remove
self.opts
, - Literal: remove
self.opts
, removeopts
argument - Custom: assert that the custom checker is a function type
- Custom: remove
self.opts
, removeopts
argument - Equivalent: remove
self.opts
, removeopts
argument - Range: remove
self.opts
, removeopts
argument - Proxy: remove
self.opts
, removeopts
argument - AssertType: remove
self.opts
, removeopts
argument - NotType: remove
self.opts
, removeopts
argument - MetatableIsType: remove
self.opts
Full Changelog: v2.4.0...v2.5.0
v2.4.0
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 fornil
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 returntrue
when passed an appropriate instance of a MoonScript class is_type
does not incorrectly returntrue
when passed a class object extended fromBaseType
. It only returnstrue
when passed an instance of a type checker. For example, passing in a type constructortypes.is_type(types.shape)
used to returntrue
but now correctly returnsfalse
. The result oftypes.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
What's Changed
- Provide missing
_describe
implementations formap_of
andequivalent
- Fix bug where
tag
(andscope
) nodes would not correctly show the tag name when describing assert
node uses theassert
property of the class instead of directly calling theassert
global, so it can be overwritten by subclasses- Minor readme typo fixes
New Contributors
- @IsLilyYaGirl made their first contribution in #13
Full Changelog: v2.2.0...v2.3.0
v2.2.0
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