All Versions
Latest Version
Avg Release Cycle
94 days
Latest Release
107 days ago

Changelog History
Page 2

  • v1.1.1 Changes

    July 26, 2019

    1.1.1 2019-07-26

    ๐Ÿ›  Fixed

    • A bug where meta was lost for lax array types (flash-gordon)

    Compare v1.1.0...v1.1.1

  • v1.1.0 Changes

    July 02, 2019

    โž• Added

    • ๐Ÿ†• 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?( # => false Types::Callable.valid?(proc {}) # => true
    • ๐Ÿ†• New types: coercible.symbol, params.symbol, and json.symbol, all use .to_sym for coercion (waiting-for-dev)

    ๐Ÿ›  Fixed

    • Converting schema keys to maybe types (flash-gordon)
    • 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)

    Compare v1.0.1...v1.1.0

  • v1.0.1 Changes

    June 04, 2019

    โž• Added

    • In a case of failure the constructor block can now pass a different value (flash-gordon) ruby not_empty_string = Types::String.constructor do |value, &failure| 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)

    Compare v1.0.0...v1.0.1

  • v1.0.0 Changes

    April 23, 2019

    โž• Added

    • 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) Example: ruby proc do |input, &block| if input.is_a? String Integer(input, 10) else Integer(input) end rescue ArgumentError, TypeError => error if block else raise 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) ruby %w(1 2 3).map(&Types::Coercible::Integer) # => [1, 2, 3]

    ๐Ÿ”„ Changed

    • [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:
      # 0.15.0
      # => "foo"
      # 1.0.0
      # => Dry::Types::CoercionError: invalid value for Integer(): "foo"

    To handle coercion errors Type#call now yields a block:

      Types::Params::Integer.('foo') { :invalid } # => :invalid

    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)

    Compare v0.15.0...v1.0.0

  • v0.15.0 Changes

    March 22, 2019

    โž• Added

    • ๐Ÿ‘Œ 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
    • Optional keys for schemas can be provided with ?-ending symbols (flash-gordon) ruby Dry::Types['hash'].schema(name: 'string', age?: 'integer')
    • Another way of making keys optional is setting required: false to meta. In fact, it is the preferable way if you have to store this information in meta, otherwise use the Key's API (see below) (flash-gordon) ruby Dry::Types['hash'].schema( name: Dry::Types['string'], age: Dry::Types['integer'].meta(required: false) )
    • Key types have API for making keys omittable and back (flash-gordon)
      # defining a base schema with optional keys
      lax_hash = Dry::Types['hash'].with_type_transform { |key| key.required(false) }
      # same as
      lax_hash = Dry::Types['hash'].with_type_transform(&:omittable)
      # keys in user_schema are not required
      user_schema = lax_hash.schema(name: 'string', age: 'integer')
    • Type#optional? now recognizes more cases where nil is an allowed value (flash-gordon)
    • ๐Ÿ‘€ 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)
      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
    • 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)

    ๐Ÿ›  Fixed

    • 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)

    ๐Ÿ”„ Changed

    • [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| == :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>]>
    • 0๏ธโƒฃ [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.

    Compare v0.14.1...v0.15.0

  • v0.14.1 Changes

    March 25, 2019

    v0.14.1 2019-03-25

    ๐Ÿ›  Fixed

    • coercible.integer now doesn't blow up on invalid strings (exterm)

    Compare v0.14.0...v0.14.1

  • v0.14.0 Changes

    March 22, 2019

    0.14.0 2019-01-29

    ๐Ÿ”„ Changed

    • ๐Ÿ’Ž [BREAKING] Support for Ruby 2.2 was dropped. It reached EOL on March 31, 2018.
    • โšก๏ธ dry-logic was updated to ~> 0.5 (solnic)

    ๐Ÿ›  Fixed

    • valid? works correctly with constructors now (cgeorgii)

    Compare v0.13.4...v0.14.0

  • v0.13.4 Changes

    December 21, 2018

    ๐Ÿ›  Fixed

    Compare v0.13.3...v0.13.4

  • v0.13.3 Changes

    November 25, 2018

    v0.13.3 2018-11-25

    ๐Ÿ›  Fixed

    • ๐Ÿ‘ป Dry::Types::Hash#try returns Failure instead of throwing an exception on missing keys (GustavoCaso)

    Compare v0.13.2...v0.13.3

  • v0.13.2 Changes

    May 30, 2018

    ๐Ÿ›  Fixed

    • 0๏ธโƒฃ Defaults#valid? now works fine when passing Dry::Core::Constans::Undefined as value (GustavoCaso)
    • valid? for constructor types wrapping Sums (GustavoCaso)

    Compare v0.13.1...v0.13.2