dry-types/CHANGELOG.md

1111 lines
37 KiB
Markdown
Raw Permalink Normal View History

2020-12-12 06:02:47 +00:00
<!--- DO NOT EDIT THIS FILE - IT'S AUTOMATICALLY GENERATED VIA DEVTOOLS --->
2020-12-12 05:53:45 +00:00
2022-11-04 17:00:30 +00:00
## 1.7.0 2022-11-04
2022-10-30 10:00:58 +00:00
### Changed
2022-11-02 09:14:42 +00:00
- This version is compatible with recently released dry-rb dependencies (@flash-gordon)
2022-11-04 17:00:30 +00:00
- Updated to dry-core 1.0 (@flash-gordon + @solnic)
- Dependency on dry-container was dropped (@flash-gordon)
2022-10-30 10:00:58 +00:00
2022-11-04 17:00:30 +00:00
[Compare v1.6.1...v1.7.0](https://github.com/dry-rb/dry-types/compare/v1.6.1...v1.7.0)
2022-10-30 10:00:58 +00:00
2022-10-15 07:51:36 +00:00
## 1.6.1 2022-10-15
### Changed
- Fix issues with internal const_missing and Inflector/Module constants (@flash-gordon + @solnic)
[Compare v1.6.0...v1.6.1](https://github.com/dry-rb/dry-types/compare/v1.6.0...v1.6.1)
2022-10-15 05:08:07 +00:00
## 1.6.0 2022-10-15
2021-03-30 15:26:03 +00:00
### Changed
- Optimize `PredicateRegistry` for Ruby 2.7+ (see #420 for more details) (@casperisfine)
2022-10-15 05:08:07 +00:00
- Use zeitwerk for auto-loading (@flash-gordon)
2021-03-30 15:26:03 +00:00
2022-10-15 05:08:07 +00:00
[Compare v1.5.1...v1.6.0](https://github.com/dry-rb/dry-types/compare/v1.5.1...v1.6.0)
2021-03-30 15:26:03 +00:00
2021-02-16 11:21:00 +00:00
## 1.5.1 2021-02-16
### Fixed
- Add missing requires for internal usage of `Dry::Equalizer` (@timriley in #418)
[Compare v1.5.0...v1.5.1](https://github.com/dry-rb/dry-types/compare/v1.5.0...v1.5.1)
2021-01-21 18:52:39 +00:00
## 1.5.0 2021-01-21
2021-01-16 14:02:16 +00:00
### Added
- Wrapping constructor types :tada: (@flash-gordon)
2021-01-16 15:07:39 +00:00
Constructor blocks can have a second argument.
The second argument is the underlying type itself:
```ruby
age_from_year = Dry::Types['coercible.integer'].constructor do |input, type|
Date.today.year - type.(input)
end
age_from_year.('2000') # => 21
```
With wrapping constructors you have control over "type application". You can even
run it more than once:
```ruby
inc = Dry::Types['integer'].constructor(&:succ)
inc2x = inc.constructor { _2.(_2.(_2.(_1))) }
inc2x.(10) # => 13
```
2021-01-16 14:02:16 +00:00
- Fallbacks :tada: (@flash-gordon)
2021-01-16 15:07:39 +00:00
```ruby
age = Dry::Types['coercible.ineger'].fallback(18)
age.('10') # => 10
age.('20') # => 20
age.('abc') # => 18
```
2021-01-16 14:02:16 +00:00
2021-01-16 15:07:39 +00:00
Fallbacks are different from default values: the later will be evaluated
only when *no input* provided.
2021-01-16 14:02:16 +00:00
2021-01-16 15:07:39 +00:00
Under the hood, `.fallback` creates a wrapping constructor.
- `params.string` as an alias for `strict.string`. This addition should be non-breaking (@flash-gordon)
2021-01-21 17:56:14 +00:00
- API for defining custom type builders similar to `.default`, `.constructor`, or `.optional` (@flash-gordon)
```ruby
# Making an alias for `.fallback`
Dry::Types.define_builder(:or) { |type, v| type.fallback(v) }
# Using new builder
type = Dry::Types['integer'].or(-273)
type.(:invalid) # => -273
```
2021-01-16 14:02:16 +00:00
2021-01-17 10:28:27 +00:00
### Changed
2021-01-17 12:30:42 +00:00
- Inferring predicates from class names is deprecated. It's very unlikely your code depends on it,
however, if it does, you'll get an exception with instructions. (@flash-gordon)
2021-01-18 09:49:02 +00:00
If you don't rely on inferring, just disable it with:
```ruby
Dry::Types::PredicateInferrer::Compiler.infer_predicate_by_class_name false
```
Otherwise, enable it explicitly:
2021-01-17 12:30:42 +00:00
```ruby
Dry::Types::PredicateInferrer::Compiler.infer_predicate_by_class_name true
```
2021-01-16 14:02:16 +00:00
2021-01-21 18:37:32 +00:00
[Compare v1.4.0...v1.5.0](https://github.com/dry-rb/dry-types/compare/v1.4.0...v1.5.0)
2021-01-16 14:02:16 +00:00
2020-03-09 12:06:07 +00:00
## 1.4.0 2020-03-09
2020-03-08 22:12:16 +00:00
### Fixed
- `json.nil` no longer coerces empty strings to `nil`. It was a long-standing
2020-03-09 13:18:54 +00:00
bug that for some reason remained unnoticed for years. Technically,
this may be a breaking change for JSON schemas described with dry-schema (@flash-gordon)
2020-03-08 22:12:16 +00:00
2020-03-09 12:06:07 +00:00
[Compare v1.3.1...v1.4.0](https://github.com/dry-rb/dry-types/compare/v1.3.1...v1.4.0)
2020-03-08 22:12:16 +00:00
2020-02-16 20:34:09 +00:00
## 1.3.1 2020-02-17
2020-02-16 20:32:30 +00:00
### Changed
2020-02-16 20:37:52 +00:00
- Predicate inferrer now returns `hash?` for hash schemas. Note, it doesn't spit more complex preds because we have different plans for dry-schema (@flash-gordon)
2020-02-16 20:32:30 +00:00
2020-02-16 20:34:09 +00:00
[Compare v1.3.0...v1.3.1](https://github.com/dry-rb/dry-types/compare/v1.3.0...v1.3.1)
2020-02-16 20:32:30 +00:00
2020-02-10 09:59:22 +00:00
## 1.3.0 2020-02-10
2020-01-06 08:14:21 +00:00
2020-01-17 09:26:52 +00:00
### Added
2020-01-06 08:14:21 +00:00
2020-02-10 08:38:05 +00:00
- `Schema#merge` for merging two hash schemas (@waiting-for-dev)
2020-01-17 19:43:13 +00:00
- Aliases for `.constructor` to non-constructor types. Now you can call `.prepend`/`.append` without silly checks for the type being a constructor (flash-gordon)
```ruby
(Dry::Types['integer'].prepend(-> { _1 + 1 })).(1) # => 2
(Dry::Types['coercible.integer'] >> -> { _1 * 2 }).('99') # => 198
```
2020-01-19 10:39:53 +00:00
- `Hash::Schema#clear` returns a schema with the same options but without keys
2020-02-10 14:58:34 +00:00
- Optional namespace now includes strict types by default (@flash-gordon)
2020-02-02 13:38:07 +00:00
### Fixed
2020-02-10 08:38:05 +00:00
- `Schema::Key#optional` returns an instance of `Schema::Key` as it should have done
- Composition with function handling exceptions. This could occasionally lead to unexpected exceptions (@flash-gordon)
2020-01-18 14:15:45 +00:00
2020-01-18 11:00:07 +00:00
2020-01-19 10:39:53 +00:00
[Compare v1.2.2...v1.3.0](https://github.com/dry-rb/dry-types/compare/v1.2.2...v1.3.0)
2020-01-18 10:55:12 +00:00
2020-01-17 09:26:52 +00:00
## 1.2.2 2019-12-14
2020-01-06 08:14:21 +00:00
2019-11-30 11:45:36 +00:00
2020-01-17 09:26:52 +00:00
### Fixed
2019-11-30 11:45:36 +00:00
2020-02-10 08:38:05 +00:00
- `Types.Contructor` doesn't re-wrap class instances implementing type interface, this fixes some quirks in dry-struct (@flash-gordon)
2019-11-30 11:45:36 +00:00
2020-01-17 09:26:52 +00:00
### Changed
2019-11-30 11:45:36 +00:00
- Types now use immutable equalizers. This should improve performance in certain cases e.g. in ROM (flash-gordon)
2019-12-14 11:47:24 +00:00
- Attempting to use non-symbol keys in hash schemas raises an error. We always supported only symbols as keys but there was no check, now it'll throw an argument error. If you want to convert strings to symbols, use `Hash#with_key_transform` (flash-gordon)
- Params and JSON types accept Time/Date/Datetime instances and boolean values. This can be useful in tests but we discourage you from relying on this behavior in production code. For example, building structs with `Params` types is considered a smell. There are dedicated tools for coercion, namely dry-schema and dry-validation. Be responsible user of dry-types! ❤ (flash-gordon)
2020-01-18 11:00:07 +00:00
2020-01-18 10:55:12 +00:00
[Compare v1.2.1...v1.2.2](https://github.com/dry-rb/dry-types/compare/v1.2.1...v1.2.2)
2020-01-17 09:26:52 +00:00
## 1.2.1 2019-11-07
2019-11-30 11:45:36 +00:00
2019-11-07 13:56:00 +00:00
2020-01-17 09:26:52 +00:00
### Fixed
2019-11-07 13:56:00 +00:00
- Fix keyword warnings reported by Ruby 2.7 (flash-gordon)
- Error type in failing case in `Array::Member` (esparta)
2020-01-18 11:00:07 +00:00
2020-01-18 10:55:12 +00:00
[Compare v1.2.0...v1.2.1](https://github.com/dry-rb/dry-types/compare/v1.2.0...v1.2.1)
2020-01-17 09:26:52 +00:00
## 1.2.0 2019-10-06
2019-11-07 13:56:00 +00:00
2019-08-12 10:59:51 +00:00
2020-01-17 09:26:52 +00:00
### Added
2019-08-12 10:59:51 +00:00
2019-10-06 13:27:32 +00:00
- `Optional::Params` types that coerce empty strings to `nil` (flash-gordon)
2019-08-12 10:59:51 +00:00
```ruby
Dry::Types['optional.params.integer'].('') # => nil
Dry::Types['optional.params.integer'].('140') # => 140
Dry::Types['optional.params.integer'].('asd') # => exception!
```
2019-10-07 08:15:32 +00:00
Keep in mind, `Dry::Types['optional.params.integer']` and `Dry::Types['params.integer'].optional` are not the same, the latter doesn't handle empty strings.
2019-10-06 13:27:32 +00:00
- Predicate inferrer was ported from dry-schema (authored by solnic)
2019-08-12 10:59:51 +00:00
```ruby
require 'dry/types/predicate_inferrer'
2019-10-06 13:27:32 +00:00
Dry::Types::PredicateInferrer.new[Types::String]
2019-08-12 10:59:51 +00:00
# => [:str?]
Dry::Types::PredicateInferrer.new[Types::String | Types::Integer]
# => [[[:str?], [:int?]]]
```
Note that the API of the predicate inferrer can change in the stable version, it's dictated by the needs of dry-schema so it should be considered as semi-stable. If you depend on it, write specs covering the desired behavior. Another option is copy-and-paste the whole thing to your project.
2019-10-06 13:27:32 +00:00
- Primitive inferrer was ported from dry-schema (authored by solnic)
2019-08-12 10:59:51 +00:00
```ruby
require 'dry/types/primitive_inferrer'
Dry::Types::PrimitiveInferrer.new[Types::String]
# => [String]
Dry::Types::PrimitiveInferrer.new[Types::String | Types::Integer]
# => [String, Integer]
Dry::Types::PrimitiveInferrer.new[Types::String.optional]
# => [NilClass, String]
```
The primitive inferrer should be stable by now, you can rely on it.
2019-10-06 13:27:32 +00:00
- The `monads` extension adds `Dry::Types::Result#to_monad`. This makes it compatible with do notation from dry-monads. Load it with `Dry::Types.load_extensions(:monads)` (skryukov)
```ruby
Types = Dry.Types
Dry::Types.load_extensions(:monads)
class AddTen
include Dry::Monads[:result, :do]
def call(input)
integer = yield Types::Coercible::Integer.try(input)
Success(integer + 10)
end
end
```
2019-08-12 10:59:51 +00:00
2020-01-17 09:26:52 +00:00
### Fixed
2019-08-12 10:59:51 +00:00
2020-01-17 09:26:52 +00:00
- Bug with using a `Bool`-named struct as a schema key (flash-gordon)
- A bunch of issues related to using `meta` on complex types (flash-gordon)
- `Types.Constructor(...)` returns a `Types::Array` as it should (flash-gordon)
2019-07-26 09:28:41 +00:00
2020-01-17 09:26:52 +00:00
### Changed
- `Dry::Types.[]` used to work with classes, now it's deprecated (flash-gordon)
2020-01-18 11:00:07 +00:00
2020-01-18 10:55:12 +00:00
[Compare v1.1.1...v1.2.0](https://github.com/dry-rb/dry-types/compare/v1.1.1...v1.2.0)
2020-01-17 09:26:52 +00:00
## 1.1.1 2019-07-26
### Fixed
2019-07-26 09:28:41 +00:00
- A bug where meta was lost for lax array types (flash-gordon)
2020-01-18 11:00:07 +00:00
2020-01-18 10:55:12 +00:00
[Compare v1.1.0...v1.1.1](https://github.com/dry-rb/dry-types/compare/v1.1.0...v1.1.1)
2020-01-17 09:26:52 +00:00
## 1.1.0 2019-07-02
2019-07-26 09:28:41 +00:00
2019-06-04 14:01:17 +00:00
2020-01-17 09:26:52 +00:00
### Added
2019-06-04 14:01:17 +00:00
- New builder method `Interface` constructs a type which accepts objects that respond to the given methods (waiting-for-dev)
```ruby
Types = Dry.Types()
Types::Callable = Types.Interface(:call)
Types::Callable.valid?(Object.new) # => false
Types::Callable.valid?(proc {}) # => true
```
2019-06-23 09:18:17 +00:00
- New types: `coercible.symbol`, `params.symbol`, and `json.symbol`, all use `.to_sym` for coercion (waiting-for-dev)
2019-06-20 07:03:56 +00:00
2020-01-17 09:26:52 +00:00
### Fixed
2019-06-20 07:03:56 +00:00
- Converting schema keys to maybe types (flash-gordon)
2019-06-23 09:18:17 +00:00
- Using `Schema#key` and `Array#member` on constuctors (flash-gordon)
- Using `meta(omittable: true)` within `transform_types` works again but produces a warning, please migrate to `.omittable` or `.required(false)` (flash-gordon)
- Bug with a constructror defined on top of enum (flash-gordon)
2019-06-20 07:03:56 +00:00
2020-01-18 11:00:07 +00:00
2020-01-18 10:55:12 +00:00
[Compare v1.0.1...v1.1.0](https://github.com/dry-rb/dry-types/compare/v1.0.1...v1.1.0)
2020-01-17 09:26:52 +00:00
## 1.0.1 2019-06-04
2019-06-20 07:03:56 +00:00
2020-01-17 09:26:52 +00:00
### Added
2019-06-20 07:03:56 +00:00
- In a case of failure the constructor block can now pass a different value (flash-gordon)
2019-06-04 14:01:17 +00:00
```ruby
2019-06-20 07:03:56 +00:00
not_empty_string = Types::String.constructor do |value, &failure|
2019-06-04 14:01:17 +00:00
value.strip.empty? ? failure.(nil) : value.strip
end
not_empty_string.(' ') { |v| v } # => nil
not_empty_string.lax.(' ') # => nil
not_empty_string.lax.(' foo ') # => "foo"
```
- `Schema#strict` now accepts an boolean argument. If `fales` is passed this will turn a strict schema into a non-strict one (flash-gordon)
2020-01-18 11:00:07 +00:00
2020-01-18 10:55:12 +00:00
[Compare v1.0.0...v1.0.1](https://github.com/dry-rb/dry-types/compare/v1.0.0...v1.0.1)
2020-01-17 09:26:52 +00:00
## 1.0.0 2019-04-23
2019-04-19 12:15:19 +00:00
2020-01-17 09:26:52 +00:00
### Added
2019-04-19 12:17:34 +00:00
2019-04-23 21:08:41 +00:00
- API for custom constructor types was enhanced. If you pass your own callable to `.constructor` it can have a block in its signature. If a block is passed, you must call it on failed coercion, otherwise raise a type coercion error (flash-gordon)
2019-04-23 10:00:34 +00:00
Example:
```ruby
proc do |input, &block|
if input.is_a? String
Integer(input, 10)
else
Integer(input)
end
rescue ArgumentError, TypeError => error
if block
block.call
else
raise Dry::Types::CoercionError.new(
error.message,
backtrace: error.backtrace
)
end
end
```
This makes the exception handling your job so that dry-types won't have to catch and re-wrap all possible errors (this is not safe, generally speaking).
- Types now can be converted to procs thus you can pass them as blocks (flash-gordon)
2019-04-19 12:17:34 +00:00
```ruby
%w(1 2 3).map(&Types::Coercible::Integer)
# => [1, 2, 3]
```
2020-01-17 09:26:52 +00:00
### Changed
2019-04-19 12:15:19 +00:00
2020-01-17 09:26:52 +00:00
- [BREAKING] Behavior of built-in constructor types was changed to be more strict. They will always raise an error on failed coercion (flash-gordon)
Compare:
2019-02-24 12:19:56 +00:00
2019-03-22 13:22:08 +00:00
```ruby
2020-01-17 09:26:52 +00:00
# 0.15.0
Types::Params::Integer.('foo')
# => "foo"
# 1.0.0
Types::Params::Integer.('foo')
# => Dry::Types::CoercionError: invalid value for Integer(): "foo"
2019-03-22 13:22:08 +00:00
```
2020-01-17 09:26:52 +00:00
To handle coercion errors `Type#call` now yields a block:
2019-03-22 13:22:08 +00:00
```ruby
2020-01-17 09:26:52 +00:00
Types::Params::Integer.('foo') { :invalid } # => :invalid
2019-03-22 13:22:08 +00:00
```
2019-02-24 12:19:56 +00:00
2020-01-17 09:26:52 +00:00
This makes work with coercions more straightforward and way faster.
- [BREAKING] Safe types were renamed to Lax, this name better serves their purpose. The previous name is available but prints a warning (flash-gordon)
- [BREAKING] Metadata is now pushed down to the decorated type. It is not likely you will notice a difference but this a breaking change that enables some use cases in rom related to the usage of default types in relations (flash-gordon)
- Nominal types are now completely unconstrained. This fixes some inconsistencies when using them with constraints. `Nominal#try` will always return a successful result, for the previous behavior use `Nominal#try_coerce` or switch to strict types with passing a block to `#call` (flash-gordon)
- ## Performance improvements
- During the work on this release, a lot of performance improvements were made. dry-types 1.0 combined with dry-logic 1.0 are multiple times faster than dry-types 0.15 and dry-logic 0.5 for common cases including constraints checking and coercion (flash-gordon)
2020-01-18 11:00:07 +00:00
2020-01-18 10:55:12 +00:00
[Compare v0.15.0...v1.0.0](https://github.com/dry-rb/dry-types/compare/v0.15.0...v1.0.0)
2020-01-17 09:26:52 +00:00
## 0.15.0 2019-03-22
### Added
2019-02-24 12:19:56 +00:00
2019-03-22 13:22:08 +00:00
- Improved string representation of types (flash-gordon)
```ruby
Dry::Types['nominal.integer']
# => #<Dry::Types[Nominal<Integer>]>
Dry::Types['params.integer']
# => #<Dry::Types[Constructor<Nominal<Integer> fn=Dry::Types::Coercions::Params.to_int>]>
Dry::Types['hash'].schema(age?: 'integer')
# => #<Dry::Types[Constrained<Schema<keys={age?: Constrained<Nominal<Integer> rule=[type?(Integer)]>}> rule=[type?(Hash)]>]>
Dry::Types['array<integer>']
# => #<Dry::Types[Constrained<Array<Constrained<Nominal<Integer> rule=[type?(Integer)]>> rule=[type?(Array)]>]>
```
- Options for the list of types you want to import with `Dry.Types` (flash-gordon)
Cherry-pick only certain types:
```ruby
module Types
include Dry.Types(:strict, :nominal, :coercible)
end
Types.constants
# => [:Strict, :Nominal, :Coercible]
```
Change default top-level types:
```ruby
module Types
include Dry.Types(default: :coercible)
end
# => #<Dry::Types[Constructor<Nominal<Integer> fn=Kernel.Integer>]>
```
Rename type namespaces:
```ruby
module Types
include Dry.Types(strict: :Strong, coercible: :Kernel)
end
```
2019-02-24 12:19:56 +00:00
- Optional keys for schemas can be provided with ?-ending symbols (flash-gordon)
```ruby
2019-03-22 13:22:08 +00:00
Dry::Types['hash'].schema(name: 'string', age?: 'integer')
2019-02-24 12:19:56 +00:00
```
2019-02-25 08:45:42 +00:00
- Another way of making keys optional is setting `required: false` to meta. In fact, it is the preferable
2019-02-24 12:19:56 +00:00
way if you have to store this information in `meta`, otherwise use the Key's API (see below) (flash-gordon)
```ruby
2019-03-22 13:22:08 +00:00
Dry::Types['hash'].schema(
name: Dry::Types['string'],
age: Dry::Types['integer'].meta(required: false)
2019-02-24 12:19:56 +00:00
)
```
- Key types have API for making keys omittable and back (flash-gordon)
2019-02-24 12:19:56 +00:00
```ruby
# defining a base schema with optional keys
2019-03-22 13:22:08 +00:00
lax_hash = Dry::Types['hash'].with_type_transform { |key| key.required(false) }
2019-02-24 12:19:56 +00:00
# same as
2019-03-22 13:22:08 +00:00
lax_hash = Dry::Types['hash'].with_type_transform(&:omittable)
2019-02-24 12:19:56 +00:00
# keys in user_schema are not required
2019-03-22 13:22:08 +00:00
user_schema = lax_hash.schema(name: 'string', age: 'integer')
2019-02-24 12:19:56 +00:00
```
- `Type#optional?` now recognizes more cases where `nil` is an allowed value (flash-gordon)
2019-02-26 11:47:40 +00:00
- `Constructor#{prepend,append}` with `<<` and `>>` as aliases. `Constructor#append` works the same way `Constructor#constrcutor` does. `Constuctor#prepend` chains functions in the reverse order, see examples (flash-gordon)
2019-02-26 11:47:40 +00:00
```ruby
to_int = Types::Coercible::Integer
inc = to_int.append { |x| x + 2 }
inc.("1") # => "1" -> 1 -> 3
inc = to_int.prepend { |x| x + "2" }
inc.("1") # => "1" -> "12" -> 12
```
2019-03-22 13:22:08 +00:00
- Partial schema application for cases when you want to validate only a subset of keys (flash-gordon)
This is useful when you want to update a key or two in an already-validated hash. A perfect example is `Dry::Struct#new` where this feature is now used.
```ruby
schema = Dry::Types['hash'].schema(name: 'string', age: 'integer')
value = schema.(name: 'John', age: 20)
update = schema.apply({ age: 21 }, skip_missing: true)
value.merge(update)
```
2019-02-26 11:47:40 +00:00
2020-01-17 09:26:52 +00:00
### Fixed
2019-03-02 14:23:44 +00:00
- `Hash::Map` now behaves as a constrained type if its values are constrained (flash-gordon)
- `coercible.integer` now doesn't blow up on invalid strings (exterm)
2019-02-26 11:47:40 +00:00
2020-01-17 09:26:52 +00:00
### Changed
2019-02-24 12:19:56 +00:00
2020-01-17 09:26:52 +00:00
- [BREAKING] Internal representation of hash schemas was changed to be a simple list of key types (flash-gordon)
`Dry::Types::Hash#with_type_transform` now yields a key type instead of type + name:
```ruby
Dry::Types['strict.hash'].with_type_transform { |key| key.name == :age ? key.required(false) : key }
```
- [BREAKING] Definition types were renamed to nominal (flash-gordon)
- [BREAKING] Top-level types returned by `Dry::Types.[]` are now strict (flash-gordon)
```ruby
# before
Dry::Types['integer']
# => #<Dry::Types[Nominal<Integer>]>
# now
Dry::Types['integer']
# => <Dry::Types[Constrained<Nominal<Integer> rule=[type?(Integer)]>]>
# you can still access nominal types using namespace
Dry::Types['nominal.integer']
# => #<Dry::Types[Nominal<Integer>]>
```
- [BREAKING] Default values are not evaluated if the decorated type returns `nil`. They are triggered on `Undefined` instead (GustavoCaso + flash-gordon)
- [BREAKING] Support for old hash schemas was fully removed. This makes dry-types not compatible with dry-validation < 1.0 (flash-gordon)
- `Dry::Types.module` is deprecated in favor of `Dry.Types` (flash-gordon)
Keep in mind `Dry.Types` uses strict types for top-level names, that is after
```ruby
module Types
include Dry.Types
end
```
`Types::Integer` is a strict type. If you want it to be nominal, use `include Dry.Types(default: :nominal)`. See other options below.
- `params.integer` now always converts strings to decimal numbers, this means `09` will be coerced to `9` (threw an error before) (skryukov)
- Ruby 2.3 is EOL and not officially supported. It may work but we don't test it.
2020-01-18 11:00:07 +00:00
2020-01-18 10:55:12 +00:00
[Compare v0.14.1...v0.15.0](https://github.com/dry-rb/dry-types/compare/v0.14.1...v0.15.0)
2020-01-17 09:26:52 +00:00
## 0.14.1 2019-03-25
2019-03-25 11:59:01 +00:00
2020-01-17 09:26:52 +00:00
### Fixed
2019-03-25 11:59:01 +00:00
2020-01-17 09:26:52 +00:00
- `coercible.integer` now doesn't blow up on invalid strings (exterm)
2018-12-21 08:45:19 +00:00
2020-01-18 11:00:07 +00:00
2020-01-18 10:55:12 +00:00
[Compare v0.14.0...v0.14.1](https://github.com/dry-rb/dry-types/compare/v0.14.0...v0.14.1)
2020-01-17 09:26:52 +00:00
## 0.14.0 2019-01-29
2018-12-21 08:45:19 +00:00
2019-01-29 14:40:56 +00:00
2020-01-17 09:26:52 +00:00
### Fixed
2019-01-29 14:40:56 +00:00
- `valid?` works correctly with constructors now (cgeorgii)
2020-01-17 09:26:52 +00:00
### Changed
- [BREAKING] Support for Ruby 2.2 was dropped. It reached EOL on March 31, 2018.
- `dry-logic` was updated to `~> 0.5` (solnic)
2020-01-18 11:00:07 +00:00
2020-01-18 10:55:12 +00:00
[Compare v0.13.4...v0.14.0](https://github.com/dry-rb/dry-types/compare/v0.13.4...v0.14.0)
2020-01-17 09:26:52 +00:00
## 0.13.4 2018-12-21
2018-12-21 08:45:19 +00:00
2018-12-21 12:31:34 +00:00
2020-01-17 09:26:52 +00:00
### Fixed
2018-12-21 12:31:34 +00:00
2019-01-29 14:40:56 +00:00
- Fixed warnings about keyword arguments from Ruby 2.6. See https://bugs.ruby-lang.org/issues/14183 for all the details (flash-gordon)
2018-12-21 12:31:34 +00:00
2020-01-18 11:00:07 +00:00
2020-01-18 10:55:12 +00:00
[Compare v0.13.3...v0.13.4](https://github.com/dry-rb/dry-types/compare/v0.13.3...v0.13.4)
2020-01-17 09:26:52 +00:00
## 0.13.3 2018-11-25
2018-09-28 13:48:19 +00:00
2020-01-17 09:26:52 +00:00
### Fixed
2018-09-28 13:48:19 +00:00
2019-01-29 14:40:56 +00:00
- `Dry::Types::Hash#try` returns `Failure` instead of throwing an exception on missing keys (GustavoCaso)
2018-09-28 13:48:19 +00:00
2020-01-18 11:00:07 +00:00
2020-01-18 10:55:12 +00:00
[Compare v0.13.2...v0.13.3](https://github.com/dry-rb/dry-types/compare/v0.13.2...v0.13.3)
2020-01-17 09:26:52 +00:00
## 0.13.2 2018-05-30
2018-09-28 13:48:19 +00:00
2018-05-30 11:56:00 +00:00
2020-01-17 09:26:52 +00:00
### Fixed
2018-05-30 11:56:00 +00:00
2019-01-29 14:40:56 +00:00
- `Defaults#valid?` now works fine when passing `Dry::Core::Constans::Undefined` as value (GustavoCaso)
- `valid?` for constructor types wrapping `Sum`s (GustavoCaso)
2018-05-30 11:56:00 +00:00
2020-01-18 11:00:07 +00:00
2020-01-18 10:55:12 +00:00
[Compare v0.13.1...v0.13.2](https://github.com/dry-rb/dry-types/compare/v0.13.1...v0.13.2)
2020-01-17 09:26:52 +00:00
## 0.13.1 2018-05-28
2018-05-27 21:03:42 +00:00
2020-01-17 09:26:52 +00:00
### Added
2018-05-27 21:03:42 +00:00
2019-01-29 14:40:56 +00:00
- `params.int` was added to make the upgrade process in dry-validation smoother (available after you `require 'dry/types/compat/int'`) (flash-gordon)
2018-05-27 21:03:42 +00:00
2020-01-17 09:26:52 +00:00
### Fixed
2018-05-27 21:03:42 +00:00
2020-01-17 09:26:52 +00:00
- Defaults now works fine with meta (GustavoCaso)
- Defaults are now re-decorated properly (flash-gordon)
2018-04-16 17:52:46 +00:00
2020-01-18 11:00:07 +00:00
2020-01-18 10:55:12 +00:00
[Compare v0.13.0...v0.13.1](https://github.com/dry-rb/dry-types/compare/v0.13.0...v0.13.1)
2020-01-17 09:26:52 +00:00
## 0.13.0 2018-05-03
2018-04-16 17:52:46 +00:00
2020-01-17 09:26:52 +00:00
### Added
2019-01-29 14:40:56 +00:00
- Hash schemas were rewritten. The old API is still around but is going to be deprecated and removed before 1.0. The new API is simpler and more flexible. Instead of having a bunch of predefined schemas you can build your own by combining the following methods:
2018-04-16 17:52:46 +00:00
1. `Schema#with_key_transform`—transforms keys of input hashes, for things like symbolizing etc.
2. `Schema#strict`—makes a schema intolerant to unknown keys.
2018-04-16 22:34:20 +00:00
3. `Hash#with_type_transform`—transforms member types with an arbitrary block. For instance,
2019-01-29 14:40:56 +00:00
```ruby
optional_keys = Types::Hash.with_type_transform { |t, _key| t.optional }
schema = optional_keys.schema(name: 'strict.string', age: 'strict.int')
schema.(name: "Jane", age: nil) # => {name: "Jane", age: nil}
```
2018-04-16 17:52:46 +00:00
2018-05-14 20:33:34 +00:00
Note that by default all keys are required, if a key is expected to be absent, add to the corresponding type's meta `omittable: true`:
2018-04-16 22:34:20 +00:00
2018-04-16 17:52:46 +00:00
```ruby
intolerant = Types::Hash.schema(name: Types::Strict::String)
intolerant[{}] # => Dry::Types::MissingKeyError
tolerant = Types::Hash.schema(name: Types::Strict::String.meta(omittable: true))
tolerant[{}] # => {}
tolerant_with_default = Types::Hash.schema(name: Types::Strict::String.meta(omittable: true).default("John"))
tolerant[{}] # => {name: "John"}
```
2018-04-16 22:34:20 +00:00
2018-04-16 17:52:46 +00:00
The new API is composable in a natural way:
2018-04-16 22:34:20 +00:00
2018-04-16 17:52:46 +00:00
```ruby
TOLERANT = Types::Hash.with_type_transform { |t| t.meta(omittable: true) }.freeze
user = TOLERANT.schema(name: 'strict.string', age: 'strict.int')
user.(name: "Jane") # => {name: "Jane"}
2018-04-16 22:34:20 +00:00
2018-04-16 17:52:46 +00:00
TOLERANT_SYMBOLIZED = TOLERANT.with_key_transform(&:to_sym)
user_sym = TOLERANT_SYMBOLIZED.schema(name: 'strict.string', age: 'strict.int')
user_sym.("name" => "Jane") # => {name: "Jane"}
```
2018-04-16 22:34:20 +00:00
2018-04-16 17:52:46 +00:00
(flash-gordon)
2019-01-29 14:40:56 +00:00
- `Types.Strict` is an alias for `Types.Instance` (flash-gordon)
2018-04-16 17:52:46 +00:00
```ruby
strict_range = Types.Strict(Range)
strict_range == Types.Instance(Range) # => true
```
2019-01-29 14:40:56 +00:00
- `Enum#include?` is an alias to `Enum#valid?` (d-Pixie + flash-gordon)
- `Range` was added (GustavoCaso)
- `Array` types filter out `Undefined` values, if you have an array type with a constructor type as its member, the constructor now can return `Dry::Types::Undefined` to indicate empty value:
```ruby
2018-04-16 17:52:46 +00:00
filter_empty_strings = Types::Strict::Array.of(
2018-04-16 22:34:20 +00:00
Types::Strict::String.constructor { |input|
input.to_s.yield_self { |s| s.empty? ? Dry::Types::Undefined : s }
2018-04-16 17:52:46 +00:00
}
)
filter_empty_strings.(["John", nil, "", "Jane"]) # => ["John", "Jane"]
```
2019-01-29 14:40:56 +00:00
- `Types::Map` was added for homogeneous hashes, when only types of keys and values are known in advance, not specific key names (fledman + flash-gordon)
2018-04-24 15:44:06 +00:00
```ruby
int_to_string = Types::Hash.map('strict.integer', 'strict.string')
int_to_string[0 => 'foo'] # => { 0 => "foo" }
int_to_string[0 => 1] # Dry::Types::MapError: input value 1 for key 0 is invalid: type?(String, 1)
```
2019-01-29 14:40:56 +00:00
- Enum supports mappings (bolshakov + flash-gordon)
2018-04-16 22:34:20 +00:00
```ruby
dict = Types::Strict::String.enum('draft' => 0, 'published' => 10, 'archived' => 20)
dict['published'] # => 'published'
dict[10] # => 'published'
```
2018-04-16 17:52:46 +00:00
2020-01-17 09:26:52 +00:00
### Fixed
2018-04-16 17:52:46 +00:00
2019-01-29 14:40:56 +00:00
- Fixed applying constraints to optional type, i.e. `.optional.constrained` works correctly (flash-gordon)
- Fixed enum working with optionals (flash-gordon)
2020-01-17 09:26:52 +00:00
- ## Internal
2019-01-29 14:40:56 +00:00
- Dropped the `dry-configurable` dependency (GustavoCaso)
- The gem now uses `dry-inflector` for inflections instead of `inflecto` (GustavoCaso)
2020-01-17 09:26:52 +00:00
### Changed
- [BREAKING] Renamed `Types::Form` to `Types::Params`. You can opt-in the former name with `require 'dry/types/compat/form_types'`. It will be dropped in the next release (ndrluis)
- [BREAKING] The `Int` types was renamed to `Integer`, this was the only type named differently from the standard Ruby classes so it has been made consistent. The former name is available with `require 'dry/types/compat/int'` (GustavoCaso + flash-gordon)
- [BREAKING] Default types are not evaluated on `nil`. Default values are evaluated _only_ if no value were given.
```ruby
type = Types::Strict::String.default("hello")
type[nil] # => constraint error
type[] # => "hello"
```
This change allowed to greatly simplify hash schemas, make them a lot more flexible yet predictable (see below).
- [BREAKING] `Dry::Types.register_class` was removed, `Dry::Types.register` was made private API, do not register your types in the global `dry-types` container, use a module instead, e.g. `Types` (flash-gordon)
- [BREAKING] Enum types don't accept value index anymore. Instead, explicit mapping is supported, see below (flash-gordon)
2020-01-18 11:00:07 +00:00
2020-01-18 10:55:12 +00:00
[Compare v0.12.2...v0.13.0](https://github.com/dry-rb/dry-types/compare/v0.12.2...v0.13.0)
2020-01-17 09:26:52 +00:00
## 0.12.2 2017-11-04
2017-10-18 19:57:06 +00:00
2020-01-17 09:26:52 +00:00
### Fixed
2017-10-18 19:57:06 +00:00
2019-01-29 14:40:56 +00:00
- The type compiler was fixed for simple rules such as used for strict type checks (flash-gordon)
- Fixed an error on `Dry::Types['json.decimal'].try(nil)` (nesaulov)
- Fixed an error on calling `try` on an array type built of constrained types (flash-gordon)
- Implemented `===` for enum types (GustavoCaso)
2017-10-18 19:57:06 +00:00
2020-01-18 11:00:07 +00:00
2020-01-18 10:55:12 +00:00
[Compare v0.12.1...v0.12.2](https://github.com/dry-rb/dry-types/compare/v0.12.1...v0.12.2)
2020-01-17 09:26:52 +00:00
## 0.12.1 2017-10-11
2017-10-18 19:57:06 +00:00
2020-01-17 09:26:52 +00:00
### Fixed
2019-01-29 14:40:56 +00:00
- `Constructor#try` rescues `ArgumentError` (raised in cases like `Integer('foo')`) (flash-gordon)
- `#constructor` works correctly for default and enum types (solnic)
- Optional sum types work correctly in `safe` mode (GustavoCaso)
- The equalizer of constrained types respects meta (flash-gordon)
2020-01-18 11:00:07 +00:00
2020-01-18 10:55:12 +00:00
[Compare v0.12.0...v0.12.1](https://github.com/dry-rb/dry-types/compare/v0.12.0...v0.12.1)
2020-01-17 09:26:52 +00:00
## 0.12.0 2017-09-15
2017-08-26 19:44:12 +00:00
2020-01-17 09:26:52 +00:00
### Added
2017-08-28 22:50:56 +00:00
2019-01-29 14:40:56 +00:00
- A bunch of shortcut methods for constructing types to the autogenerated module, e.g. `Types.Constructor(String, &:to_s)` (flash-gordon)
2020-01-17 09:26:52 +00:00
- ## Deprecated
2019-01-29 14:40:56 +00:00
- `Types::Array#member` was deprecated in favor of `Types::Array#of` (flash-gordon)
2017-08-26 19:44:12 +00:00
2020-01-18 11:00:07 +00:00
2020-01-18 10:55:12 +00:00
[Compare v0.11.1...v0.12.0](https://github.com/dry-rb/dry-types/compare/v0.11.1...v0.12.0)
2020-01-17 09:26:52 +00:00
## 0.11.1 2017-08-14
2017-07-20 21:53:48 +00:00
2020-01-17 09:26:52 +00:00
### Fixed
2017-07-22 12:54:11 +00:00
2019-01-29 14:40:56 +00:00
- Fixed `Constructor#name` with `Sum`-types (flash-gordon)
2017-07-20 21:53:48 +00:00
2020-01-17 09:26:52 +00:00
### Changed
2017-07-20 21:53:48 +00:00
2020-01-17 09:26:52 +00:00
- Constructors are now equalized using `fn` and `meta` too (flash-gordon)
2020-01-18 11:00:07 +00:00
2020-01-18 10:55:12 +00:00
[Compare v0.11.0...v0.11.1](https://github.com/dry-rb/dry-types/compare/v0.11.0...v0.11.1)
2020-01-17 09:26:52 +00:00
## 0.11.0 2017-06-30
2017-06-30 20:01:12 +00:00
2020-01-17 09:26:52 +00:00
### Added
2017-06-30 20:01:12 +00:00
2019-01-29 14:40:56 +00:00
- `#to_ast` available for all type objects (GustavoCaso)
- `Types::Array#of` as an alias for `#member` (maliqq)
- Detailed failure objects are passed to results which improves constraint violation messages (GustavoCaso)
2017-06-30 20:01:12 +00:00
2020-01-18 11:00:07 +00:00
2020-01-18 10:55:12 +00:00
[Compare v0.10.3...v0.11.0](https://github.com/dry-rb/dry-types/compare/v0.10.3...v0.11.0)
2020-01-17 09:26:52 +00:00
## 0.10.3 2017-05-06
2017-06-30 20:01:12 +00:00
2017-05-06 14:24:25 +00:00
2020-01-17 09:26:52 +00:00
### Added
2017-05-06 14:24:25 +00:00
2019-01-29 14:40:56 +00:00
- Callable defaults accept the underlying type (v-kolesnikov)
2017-05-06 14:24:25 +00:00
2020-01-18 11:00:07 +00:00
2020-01-18 10:55:12 +00:00
[Compare v0.10.2...v0.10.3](https://github.com/dry-rb/dry-types/compare/v0.10.2...v0.10.3)
2020-01-17 09:26:52 +00:00
## 0.10.2 2017-04-28
2017-05-06 14:24:25 +00:00
2017-04-28 10:07:16 +00:00
2020-01-17 09:26:52 +00:00
### Fixed
2017-04-28 10:07:16 +00:00
2019-01-29 14:40:56 +00:00
- Fixed `Type#optional?` for sum types (flash-gordon)
2017-04-28 10:07:16 +00:00
2020-01-18 11:00:07 +00:00
2020-01-18 10:55:12 +00:00
[Compare v0.10.1...v0.10.2](https://github.com/dry-rb/dry-types/compare/v0.10.1...v0.10.2)
2020-01-17 09:26:52 +00:00
## 0.10.1 2017-04-28
2017-04-28 11:06:55 +00:00
2017-04-28 06:56:26 +00:00
2020-01-17 09:26:52 +00:00
### Added
2017-04-27 18:28:41 +00:00
2019-01-29 14:40:56 +00:00
- `Type#optional?` returns true if type is Sum and left is nil (GustavoCaso)
- `Type#pristine` returns a type without `meta` (flash-gordon)
2017-04-27 18:28:41 +00:00
2020-01-17 09:26:52 +00:00
### Fixed
2017-04-28 06:56:26 +00:00
2019-01-29 14:40:56 +00:00
- `meta` is used in type equality again (solnic)
- `Any` works correctly with meta again (flash-gordon)
2017-04-28 06:56:26 +00:00
2020-01-18 11:00:07 +00:00
2020-01-18 10:55:12 +00:00
[Compare v0.10.0...v0.10.1](https://github.com/dry-rb/dry-types/compare/v0.10.0...v0.10.1)
2020-01-17 09:26:52 +00:00
## 0.10.0 2017-04-26
2017-04-28 06:56:26 +00:00
2017-04-25 10:52:44 +00:00
2020-01-17 09:26:52 +00:00
### Added
2017-04-26 08:27:50 +00:00
2019-01-29 14:40:56 +00:00
- Types can be used in `case` statements now (GustavoCaso)
2017-04-26 08:27:50 +00:00
2020-01-17 09:26:52 +00:00
### Fixed
2017-04-26 08:21:55 +00:00
2019-01-29 14:40:56 +00:00
- Return original value when Date.parse raises a RangeError (jviney)
2017-04-26 08:21:55 +00:00
2020-01-17 09:26:52 +00:00
### Changed
2017-04-25 10:52:44 +00:00
2019-01-29 14:40:56 +00:00
- Meta data are now stored separately from options (flash-gordon)
- `Types::Object` was renamed to `Types::Any` (flash-gordon)
2020-01-18 11:00:07 +00:00
2020-01-18 10:55:12 +00:00
[Compare v0.9.4...v0.10.0](https://github.com/dry-rb/dry-types/compare/v0.9.4...v0.10.0)
2020-01-17 09:26:52 +00:00
## 0.9.4 2017-01-24
2017-04-25 10:52:44 +00:00
2020-01-17 09:26:52 +00:00
### Added
2019-01-29 14:40:56 +00:00
- Added `Types::Object` which passes an object of any type (flash-gordon)
2020-01-18 11:00:07 +00:00
2020-01-18 10:55:12 +00:00
[Compare v0.9.3...v0.9.4](https://github.com/dry-rb/dry-types/compare/v0.9.3...v0.9.4)
2020-01-17 09:26:52 +00:00
## 0.9.3 2016-12-03
2017-01-24 09:48:00 +00:00
2016-11-13 12:13:38 +00:00
2020-01-17 09:26:52 +00:00
### Fixed
2016-12-03 11:59:56 +00:00
2019-01-29 14:40:56 +00:00
- Updated to dry-core >= 0.2.1 (ruby warnings are gone) (flash-gordon)
2016-12-03 11:59:56 +00:00
2020-01-18 11:00:07 +00:00
2020-01-18 10:55:12 +00:00
[Compare v0.9.2...v0.9.3](https://github.com/dry-rb/dry-types/compare/v0.9.2...v0.9.3)
2020-01-17 09:26:52 +00:00
## 0.9.2 2016-11-13
2016-12-03 12:13:19 +00:00
2020-01-17 09:26:52 +00:00
### Added
2016-12-03 12:13:19 +00:00
2019-01-29 14:40:56 +00:00
- Support for `"Y"` and `"N"` as `true` and `false` values, respectively (scare21410)
2016-12-03 12:13:19 +00:00
2020-01-17 09:26:52 +00:00
### Changed
2016-11-13 11:56:35 +00:00
2019-01-29 14:40:56 +00:00
- Optimized object allocation in hash schemas, resulting in up to 25% speed boost (davydovanton)
2020-01-18 11:00:07 +00:00
2020-01-18 10:55:12 +00:00
[Compare v0.9.1...v0.9.2](https://github.com/dry-rb/dry-types/compare/v0.9.1...v0.9.2)
2020-01-17 09:26:52 +00:00
## 0.9.1 2016-11-04
2016-11-13 11:56:35 +00:00
2016-11-02 11:38:28 +00:00
2020-01-17 09:26:52 +00:00
### Fixed
2016-11-02 11:38:28 +00:00
2019-01-29 14:40:56 +00:00
- `Hash#strict_with_defaults` properly evaluates callable defaults (bolshakov)
2016-11-02 11:38:28 +00:00
2020-01-17 09:26:52 +00:00
### Changed
2016-11-04 11:25:41 +00:00
2019-01-29 14:40:56 +00:00
- `Hash#weak` accepts Hash-descendants again (solnic)
2020-01-18 11:00:07 +00:00
2020-01-18 10:55:12 +00:00
[Compare v0.9.0...v0.9.1](https://github.com/dry-rb/dry-types/compare/v0.9.0...v0.9.1)
2020-01-17 09:26:52 +00:00
## 0.9.0 2016-09-21
2016-11-04 11:25:41 +00:00
2016-11-02 11:38:28 +00:00
2020-01-17 09:26:52 +00:00
### Added
2016-08-25 11:26:47 +00:00
2019-01-29 14:40:56 +00:00
- `Hash#strict_with_defaults` which validates presence of all required keys and respects default types for missing _values_ (backus)
- `Type#constrained?` method (flash-gordon)
2016-08-25 11:26:47 +00:00
2020-01-17 09:26:52 +00:00
### Fixed
2016-08-25 11:26:47 +00:00
2019-01-29 14:40:56 +00:00
- Summing two constrained types works correctly (flash-gordon)
- `Types::Array::Member#valid?` in cases where member type is a constraint (solnic)
- `Hash::Schema#try` handles exceptions properly and returns a failure object (solnic)
2016-08-25 11:26:47 +00:00
2020-01-17 09:26:52 +00:00
### Changed
2016-08-25 11:26:47 +00:00
2019-01-29 14:40:56 +00:00
- [BREAKING] Renamed `Hash##{schema=>permissive}` (backus)
- [BREAKING] `dry-monads` dependency was made optional, Maybe types are available after `Dry::Types.load_extensions(:maybe)` (flash-gordon)
- [BREAKING] `Dry::Types::Struct` and `Dry::Types::Value` have been extracted to [`dry-struct`](https://github.com/dry-rb/dry-struct) (backus)
- `Types::Form::Bool` supports upcased true/false values (kirs)
- `Types::Form::{Date,DateTime,Time}` fail gracefully for invalid input (padde)
- ice_nine dependency has been dropped as it was required by Struct only (flash-gordon)
2020-01-18 11:00:07 +00:00
2020-01-18 10:55:12 +00:00
[Compare v0.8.1...v0.9.0](https://github.com/dry-rb/dry-types/compare/v0.8.1...v0.9.0)
2020-01-17 09:26:52 +00:00
## 0.8.1 2016-07-13
2016-07-13 10:02:25 +00:00
2020-01-17 09:26:52 +00:00
### Fixed
2016-07-13 10:02:25 +00:00
2019-01-29 14:40:56 +00:00
- Compiler no longer chokes on type nodes without args (solnic)
- Removed `bin/console` from gem package (solnic)
2016-07-13 10:02:25 +00:00
2020-01-18 11:00:07 +00:00
2020-01-18 10:55:12 +00:00
[Compare v0.8.0...v0.8.1](https://github.com/dry-rb/dry-types/compare/v0.8.0...v0.8.1)
2020-01-17 09:26:52 +00:00
## 0.8.0 2016-07-01
2016-07-13 10:02:25 +00:00
2016-07-01 10:58:08 +00:00
2020-01-17 09:26:52 +00:00
### Added
2016-07-01 10:58:08 +00:00
2019-01-29 14:40:56 +00:00
- `Struct` now implements `Type` interface so ie `SomeStruct | String` works now (flash-gordon)
- `:weak` Hash constructor which can partially coerce a hash even when it includes invalid values (solnic)
- Types include `Dry::Equalizer` now (flash-gordon)
2016-07-01 10:58:08 +00:00
2020-01-17 09:26:52 +00:00
### Fixed
2016-07-01 10:58:08 +00:00
2019-01-29 14:40:56 +00:00
- `Struct#to_hash` descends into arrays too (nepalez)
- `Default#with` works now (flash-gordon)
2016-07-01 10:58:08 +00:00
2020-01-17 09:26:52 +00:00
### Changed
2016-07-01 10:58:08 +00:00
2019-01-29 14:40:56 +00:00
- `:symbolized` hash schema is now based on `:weak` schema (solnic)
- `Struct::Value` instances are now **deeply frozen** via ice_nine (backus)
2020-01-18 11:00:07 +00:00
2020-01-18 10:55:12 +00:00
[Compare v0.7.2...v0.8.0](https://github.com/dry-rb/dry-types/compare/v0.7.2...v0.8.0)
2020-01-17 09:26:52 +00:00
## 0.7.2 2016-05-11
2016-07-01 10:58:08 +00:00
2016-04-07 10:24:44 +00:00
2020-01-17 09:26:52 +00:00
### Fixed
2016-04-07 10:24:44 +00:00
- `Bool#default` gladly accepts `false` as its value (solnic)
2016-05-11 20:32:56 +00:00
- Creating an empty schema with input processor no longer fails (lasseebert)
2020-01-17 09:26:52 +00:00
### Changed
2016-07-01 10:58:08 +00:00
2016-05-11 20:32:56 +00:00
- Allow multiple calls to meta (solnic)
- Allow capitalised versions of true and false values for boolean coercions (nil0bject)
- Replace kleisli with dry-monads (flash-gordon)
- Use coercions from Kernel (flash-gordon)
- Decimal coercions now work with Float (flash-gordon)
- Coerce empty strings in form posts to blank arrays and hashes (timriley)
- update to use dry-logic v0.2.3 (fran-worley)
2020-01-18 11:00:07 +00:00
2020-01-18 10:55:12 +00:00
[Compare v0.7.1...v0.7.2](https://github.com/dry-rb/dry-types/compare/v0.7.1...v0.7.2)
2020-01-17 09:26:52 +00:00
## 0.7.1 2016-04-06
2016-05-11 20:32:56 +00:00
2016-04-07 10:24:44 +00:00
2020-01-17 09:26:52 +00:00
### Added
2016-04-06 18:21:41 +00:00
- `JSON::*` types with JSON-specific coercions (coop)
2020-01-17 09:26:52 +00:00
### Fixed
2016-04-06 18:21:41 +00:00
- Schema is properly inherited in Struct (backus)
- `constructor_type` is properly inherited in Struct (fbernier)
2020-01-18 11:00:07 +00:00
2020-01-18 10:55:12 +00:00
[Compare v0.7.0...v0.7.1](https://github.com/dry-rb/dry-types/compare/v0.7.0...v0.7.1)
2020-01-17 09:26:52 +00:00
## 0.7.0 2016-03-30
2016-03-24 12:05:54 +00:00
2016-03-25 10:52:05 +00:00
Major focus of this release is to make complex type composition possible and improving constraint errors to be more meaningful.
2016-03-24 12:05:54 +00:00
2020-01-17 09:26:52 +00:00
### Added
2016-03-24 12:05:54 +00:00
- `Type#try` interface that tries to process the input and return a result object which can be either a success or failure (solnic)
2016-03-25 14:22:59 +00:00
- `#meta` interface for setting arbitrary meta data on types (solnic)
2016-03-24 12:08:40 +00:00
- `ConstraintError` has a message which includes information about the predicate which failed ie `nil violates constraints (type?(String) failed)` (solnic)
2016-03-25 16:48:53 +00:00
- `Struct` uses `Dry::Equalizer` too, just like `Value` (AMHOL)
2016-03-30 12:18:04 +00:00
- `Sum::Constrained` which has a disjunction rule built from its types (solnic)
2016-03-30 12:08:27 +00:00
- Compiler supports `[:constructor, [primitive, fn_proc]]` nodes (solnic)
- Compiler supports building schema-less `form.hash` types (solnic)
2016-03-24 12:05:54 +00:00
2020-01-17 09:26:52 +00:00
### Fixed
2016-03-24 12:05:54 +00:00
- `Sum` now supports complex types like `Array` or `Hash` with member types and/or constraints (solnic)
- `Default#constrained` will properly wrap a new constrained type (solnic)
2020-01-17 09:26:52 +00:00
### Changed
2016-03-24 12:05:54 +00:00
2016-03-25 10:52:05 +00:00
- [BREAKING] Renamed `Type#{optional=>maybe}` (AMHOL)
- [BREAKING] `Type#optional(other)` builds a sum: `Strict::Nil | other` (AMHOL)
2016-03-25 14:29:12 +00:00
- [BREAKING] Type objects are now frozen (solnic)
2016-03-25 16:48:53 +00:00
- [BREAKING] `Value` instances are frozen (AMHOL)
2016-03-24 12:05:54 +00:00
- `Array` is no longer a constructor and has a `Array::Member` subclass (solnic)
- `Hash` is no longer a constructor and is split into `Hash::Safe`, `Hash::Strict` and `Hash::Symbolized` (solnic)
- `Constrained` has now a `Constrained::Coercible` subclass which will try to apply its type prior applying its rule (solnic)
2016-03-25 12:22:57 +00:00
- `#maybe` uses `Strict::Nil` now (solnic)
2016-03-25 10:52:05 +00:00
- `Type#default` will raise if `nil` was passed for `Maybe` type (solnic)
- `Hash` with a schema will set maybe values for missing keys or nils (flash-gordon)
2020-01-18 11:00:07 +00:00
2020-01-18 10:55:12 +00:00
[Compare v0.6.0...v0.7.0](https://github.com/dry-rb/dry-types/compare/v0.6.0...v0.7.0)
2020-01-17 09:26:52 +00:00
## 0.6.0 2016-03-16
2016-02-05 20:51:14 +00:00
2016-03-07 11:37:40 +00:00
Renamed from `dry-data` to `dry-types` and:
2016-02-05 20:51:14 +00:00
2020-01-17 09:26:52 +00:00
### Added
2016-02-05 20:51:14 +00:00
2019-01-29 14:40:56 +00:00
- `Dry::Types.module` which returns a namespace for inclusion which has all
2016-03-07 11:37:40 +00:00
built-in types defined as constants (solnic)
2019-01-29 14:40:56 +00:00
- `Hash#schema` supports default values now (solnic)
- `Hash#symbolized` passes through keys that are already symbols (solnic)
- `Struct.new` uses an empty hash by default as input (solnic)
- `Struct.constructor_type` macro can be used to change attributes constructor (solnic)
- `default` accepts a block now for dynamic values (solnic)
- `Types.register_class` accepts a second arg which is the name of the class'
2016-03-16 09:10:39 +00:00
constructor method, defaults to `:new` (solnic)
2016-03-07 11:37:40 +00:00
2020-01-17 09:26:52 +00:00
### Fixed
2016-03-07 11:37:40 +00:00
2019-01-29 14:40:56 +00:00
- `Struct` will simply pass-through the input if it is already a struct (solnic)
- `default` will raise if a value violates constraints (solnic)
- Evaluating a default value tries to use type's constructor which makes it work
2016-03-16 09:10:39 +00:00
with types that may coerce an input into nil (solnic)
2019-01-29 14:40:56 +00:00
- `enum` works just fine with integer-values (solnic)
- `enum` + `default` works just fine (solnic)
- `Optional` no longer responds to `primitive` as it makes no sense since there's
2016-03-16 09:10:39 +00:00
no single primitive for an optional value (solnic)
2019-01-29 14:40:56 +00:00
- `Optional` passes-through a value which is already a maybe (solnic)
2016-03-07 11:37:40 +00:00
2020-01-17 09:26:52 +00:00
### Changed
2016-02-05 20:51:14 +00:00
2019-01-29 14:40:56 +00:00
- `Dry::Types::Definition` is now the base type definition object (solnic)
- `Dry::Types::Constructor` is now a type definition with a constructor function (solnic)
2020-01-18 11:00:07 +00:00
2020-01-18 10:55:12 +00:00
[Compare v0.5.1...v0.6.0](https://github.com/dry-rb/dry-types/compare/v0.5.1...v0.6.0)
2020-01-17 09:26:52 +00:00
## 0.5.1 2016-01-11
2016-03-07 11:37:40 +00:00
2016-01-11 19:50:50 +00:00
2020-01-17 09:26:52 +00:00
### Added
2016-01-11 19:50:50 +00:00
2019-01-29 14:40:56 +00:00
- `Dry::Data::Type#safe` for types which can skip constructor when primitive does
2016-01-11 19:50:50 +00:00
not match input's class (solnic)
2019-01-29 14:40:56 +00:00
- `form.array` and `form.hash` safe types (solnic)
2016-01-11 19:50:50 +00:00
2020-01-18 11:00:07 +00:00
2020-01-18 10:55:12 +00:00
[Compare v0.5.0...v0.5.1](https://github.com/dry-rb/dry-types/compare/v0.5.0...v0.5.1)
2020-01-17 09:26:52 +00:00
## 0.5.0 2016-01-11
2016-01-11 19:50:50 +00:00
2016-01-11 10:36:23 +00:00
2020-01-17 09:26:52 +00:00
### Added
2016-01-11 12:55:08 +00:00
2019-01-29 14:40:56 +00:00
- `Type#default` interface for defining a type with a default value (solnic)
2016-01-11 12:55:08 +00:00
2020-01-17 09:26:52 +00:00
### Fixed
- `attribute` raises proper error when type definition is missing (solnic)
### Changed
2016-01-11 10:36:23 +00:00
2019-01-29 14:40:56 +00:00
- [BREAKING] `Dry::Data::Type.new` accepts constructor and _options_ now (solnic)
- Renamed `Dry::Data::Type::{Enum,Constrained}` => `Dry::Data::{Enum,Constrained}` (solnic)
- `dry-logic` is now a dependency for constrained types (solnic)
- Constrained types are now always available (solnic)
- `strict.*` category uses constrained types with `:type?` predicate (solnic)
- `SumType#call` no longer needs to rescue from `TypeError` (solnic)
2020-01-18 11:00:07 +00:00
2020-01-18 10:55:12 +00:00
[Compare v0.4.2...v0.5.0](https://github.com/dry-rb/dry-types/compare/v0.4.2...v0.5.0)
2020-01-17 09:26:52 +00:00
## 0.4.2 2015-12-27
2016-01-11 10:36:23 +00:00
2015-12-11 16:27:26 +00:00
2020-01-17 09:26:52 +00:00
### Added
2015-12-11 16:27:26 +00:00
2019-01-29 14:40:56 +00:00
- Support for arrays in type compiler (solnic)
2015-12-11 16:27:26 +00:00
2020-01-17 09:26:52 +00:00
### Changed
2015-12-27 11:54:25 +00:00
2019-01-29 14:40:56 +00:00
- Array member uses type objects now rather than just their constructors (solnic)
2020-01-18 11:00:07 +00:00
2020-01-18 10:55:12 +00:00
[Compare v0.4.0...v0.4.2](https://github.com/dry-rb/dry-types/compare/v0.4.0...v0.4.2)
2020-01-17 09:26:52 +00:00
## 0.4.0 2015-12-11
2015-12-27 11:54:25 +00:00
2015-12-11 16:27:26 +00:00
2020-01-17 09:26:52 +00:00
### Added
2015-12-11 12:56:28 +00:00
2019-01-29 14:40:56 +00:00
- Support for sum-types with constraint type (solnic)
- `Dry::Data::Type#optional` for defining optional types (solnic)
2015-12-11 12:56:28 +00:00
2020-01-17 09:26:52 +00:00
### Changed
2015-12-11 12:56:28 +00:00
2019-01-29 14:40:56 +00:00
- `Dry::Data['optional']` was **removed** in favor of `Dry::Data::Type#optional` (solnic)
2020-01-18 11:00:07 +00:00
2020-01-18 10:55:12 +00:00
[Compare v0.3.2...v0.4.0](https://github.com/dry-rb/dry-types/compare/v0.3.2...v0.4.0)
2020-01-17 09:26:52 +00:00
## 0.3.2 2015-12-10
2015-12-11 12:56:28 +00:00
2015-12-10 16:25:25 +00:00
2020-01-17 09:26:52 +00:00
### Added
2015-12-10 16:25:25 +00:00
2019-01-29 14:40:56 +00:00
- `Dry::Data::Value` which works like a struct but is a value object with equalizer (solnic)
2015-12-10 16:25:25 +00:00
2020-01-17 09:26:52 +00:00
### Fixed
2015-12-10 16:35:12 +00:00
2019-01-29 14:40:56 +00:00
- Added missing require for `dry-equalizer` (solnic)
2015-12-10 16:35:12 +00:00
2020-01-18 11:00:07 +00:00
2020-01-18 10:55:12 +00:00
[Compare v0.3.1...v0.3.2](https://github.com/dry-rb/dry-types/compare/v0.3.1...v0.3.2)
2020-01-17 09:26:52 +00:00
## 0.3.1 2015-12-09
2015-12-10 16:25:25 +00:00
2015-12-09 21:48:27 +00:00
2020-01-17 09:26:52 +00:00
### Changed
2015-12-09 21:48:27 +00:00
2019-01-29 14:40:56 +00:00
- Removed require of constrained type and make it optional (solnic)
2020-01-18 11:00:07 +00:00
2020-01-18 10:55:12 +00:00
[Compare v0.3.0...v0.3.1](https://github.com/dry-rb/dry-types/compare/v0.3.0...v0.3.1)
2020-01-17 09:26:52 +00:00
## 0.3.0 2015-12-09
2015-12-09 21:48:27 +00:00
2015-12-09 12:41:46 +00:00
2020-01-17 09:26:52 +00:00
### Added
2015-12-09 12:41:46 +00:00
2019-01-29 14:40:56 +00:00
- `Type#constrained` interface for defining constrained types (solnic)
- `Dry::Data` can be configured with a type namespace (solnic)
- `Dry::Data.finalize` can be used to define types as constants under configured namespace (solnic)
- `Dry::Data::Type#enum` for defining an enum from a specific type (solnic)
- New types: `symbol` and `class` along with their `strict` versions (solnic)
2015-12-09 12:41:46 +00:00
2020-01-18 11:00:07 +00:00
2020-01-18 10:55:12 +00:00
[Compare v0.2.1...v0.3.0](https://github.com/dry-rb/dry-types/compare/v0.2.1...v0.3.0)
2020-01-17 09:26:52 +00:00
## 0.2.1 2015-11-30
2015-12-09 12:41:46 +00:00
2015-11-30 11:45:32 +00:00
2020-01-17 09:26:52 +00:00
### Added
2015-11-30 11:48:03 +00:00
2019-01-29 14:40:56 +00:00
- Type compiler supports nested hashes now (solnic)
2015-11-30 11:48:03 +00:00
2020-01-17 09:26:52 +00:00
### Fixed
2015-11-30 11:45:32 +00:00
2019-01-29 14:40:56 +00:00
- `form.bool` sum is using correct right-side `form.false` type (solnic)
2015-11-30 11:45:32 +00:00
2020-01-17 09:26:52 +00:00
### Changed
2015-11-30 11:45:32 +00:00
2019-01-29 14:40:56 +00:00
- Improved structure of the ast (solnic)
2020-01-18 11:00:07 +00:00
2020-01-18 10:55:12 +00:00
[Compare v0.2.0...v0.2.1](https://github.com/dry-rb/dry-types/compare/v0.2.0...v0.2.1)
2020-01-17 09:26:52 +00:00
## 0.2.0 2015-11-29
2015-11-30 11:45:32 +00:00
2020-01-17 09:26:52 +00:00
### Added
2015-11-29 15:21:43 +00:00
2019-01-29 14:40:56 +00:00
- `form.nil` which coerces empty strings to `nil` (solnic)
- `bool` sum-type (true | false) (solnic)
- Type compiler supports sum-types now (solnic)
2015-11-29 15:21:43 +00:00
2020-01-17 09:26:52 +00:00
### Changed
2015-11-29 15:21:43 +00:00
2019-01-29 14:40:56 +00:00
- Constructing optional types uses the new `Dry::Data["optional"]` built-in type (solnic)
2020-01-18 11:00:07 +00:00
2020-01-18 10:55:12 +00:00
[Compare v0.1.0...v0.2.0](https://github.com/dry-rb/dry-types/compare/v0.1.0...v0.2.0)
2020-01-17 09:26:52 +00:00
## 0.1.0 2015-11-27
2015-11-29 15:21:43 +00:00
2015-11-27 14:53:24 +00:00
2020-01-17 09:26:52 +00:00
### Added
2015-11-27 14:53:24 +00:00
2019-01-29 14:40:56 +00:00
- `form.*` coercible types (solnic)
- `Type::Hash#strict` for defining hashes with a strict schema (solnic)
- `Type::Hash#symbolized` for defining hashes that will symbolize keys (solnic)
- `Dry::Data.register_class` short-cut interface for registering a class and
2015-11-27 14:53:24 +00:00
setting its `.new` method as the constructor (solnic)
2019-01-29 14:40:56 +00:00
- `Dry::Data::Compiler` for building a type from a simple ast (solnic)
2015-11-27 14:53:24 +00:00
2020-01-18 11:00:07 +00:00
2020-01-18 10:55:12 +00:00
[Compare v0.0.1...v0.1.0](https://github.com/dry-rb/dry-types/compare/v0.0.1...v0.1.0)
2020-01-17 09:26:52 +00:00
## 0.0.1 2015-10-05
2015-10-05 12:56:46 +00:00
First public release