dry-schema 1.13.4 → 1.14.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +20 -0
- data/README.md +1 -1
- data/config/errors.yml +9 -1
- data/dry-schema.gemspec +15 -17
- data/lib/dry/schema/config.rb +6 -6
- data/lib/dry/schema/constants.rb +2 -2
- data/lib/dry/schema/dsl.rb +18 -18
- data/lib/dry/schema/extensions/hints/message_compiler_methods.rb +1 -1
- data/lib/dry/schema/extensions/info/schema_compiler.rb +16 -7
- data/lib/dry/schema/extensions/json_schema/schema_compiler.rb +3 -3
- data/lib/dry/schema/extensions/monads.rb +1 -1
- data/lib/dry/schema/extensions/struct.rb +3 -3
- data/lib/dry/schema/key.rb +4 -4
- data/lib/dry/schema/key_coercer.rb +3 -3
- data/lib/dry/schema/key_map.rb +5 -5
- data/lib/dry/schema/key_validator.rb +19 -8
- data/lib/dry/schema/macros/dsl.rb +8 -8
- data/lib/dry/schema/macros/each.rb +2 -2
- data/lib/dry/schema/macros/filled.rb +4 -5
- data/lib/dry/schema/macros/hash.rb +2 -2
- data/lib/dry/schema/macros/maybe.rb +2 -2
- data/lib/dry/schema/macros/schema.rb +3 -3
- data/lib/dry/schema/macros/value.rb +12 -12
- data/lib/dry/schema/message.rb +4 -4
- data/lib/dry/schema/message_compiler.rb +8 -8
- data/lib/dry/schema/message_set.rb +8 -8
- data/lib/dry/schema/messages/abstract.rb +12 -12
- data/lib/dry/schema/messages/namespaced.rb +1 -1
- data/lib/dry/schema/messages/template.rb +2 -2
- data/lib/dry/schema/messages/yaml.rb +3 -3
- data/lib/dry/schema/path.rb +12 -12
- data/lib/dry/schema/predicate.rb +4 -4
- data/lib/dry/schema/predicate_registry.rb +2 -2
- data/lib/dry/schema/processor.rb +10 -10
- data/lib/dry/schema/processor_steps.rb +1 -1
- data/lib/dry/schema/result.rb +6 -6
- data/lib/dry/schema/rule_applier.rb +1 -1
- data/lib/dry/schema/trace.rb +1 -1
- data/lib/dry/schema/type_container.rb +2 -2
- data/lib/dry/schema/type_registry.rb +1 -1
- data/lib/dry/schema/types.rb +1 -1
- data/lib/dry/schema/types_merger.rb +18 -62
- data/lib/dry/schema/value_coercer.rb +1 -1
- data/lib/dry/schema/version.rb +1 -1
- data/lib/dry/schema.rb +11 -11
- metadata +20 -78
@@ -27,14 +27,14 @@ module Dry
|
|
27
27
|
|
28
28
|
# @api private
|
29
29
|
def call
|
30
|
-
if op_class <= Dry::Logic::Operations::Or
|
30
|
+
if op_class <= ::Dry::Logic::Operations::Or
|
31
31
|
merge_or
|
32
|
-
elsif op_class <= Dry::Logic::Operations::And
|
32
|
+
elsif op_class <= ::Dry::Logic::Operations::And
|
33
33
|
merge_and
|
34
|
-
elsif op_class <= Dry::Logic::Operations::Implication
|
34
|
+
elsif op_class <= ::Dry::Logic::Operations::Implication
|
35
35
|
merge_implication
|
36
36
|
else
|
37
|
-
raise ArgumentError, <<~MESSAGE
|
37
|
+
raise ::ArgumentError, <<~MESSAGE
|
38
38
|
Can't merge operations, op_class=#{op_class}
|
39
39
|
MESSAGE
|
40
40
|
end
|
@@ -58,7 +58,7 @@ module Dry
|
|
58
58
|
|
59
59
|
rule = [old_rule, new_rule].compact.reduce { op_class.new(_1, _2) }
|
60
60
|
|
61
|
-
type = Dry::Types::Constrained.new(type, rule: rule) if rule
|
61
|
+
type = ::Dry::Types::Constrained.new(type, rule: rule) if rule
|
62
62
|
|
63
63
|
type
|
64
64
|
end
|
@@ -66,61 +66,17 @@ module Dry
|
|
66
66
|
alias_method :merge_and, :merge_ordered
|
67
67
|
alias_method :merge_implication, :merge_ordered
|
68
68
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
else
|
81
|
-
merge_equivalent_types(unwrapped_old, unwrapped_new)
|
82
|
-
end
|
83
|
-
end
|
84
|
-
RUBY
|
85
|
-
else
|
86
|
-
# @api private
|
87
|
-
def merge_unwrapped_types(unwrapped_old, unwrapped_new)
|
88
|
-
if change_from_schema_to_schema?(unwrapped_old, unwrapped_new)
|
89
|
-
merge_schemas(unwrapped_old, unwrapped_new)
|
90
|
-
elsif change_from_any?(unwrapped_old) || change_from_hash_to_schema?(unwrapped_old,
|
91
|
-
unwrapped_new)
|
92
|
-
unwrapped_new
|
93
|
-
elsif change_from_schema_to_hash?(unwrapped_old,
|
94
|
-
unwrapped_new) || change_to_any?(unwrapped_new)
|
95
|
-
unwrapped_old
|
96
|
-
else
|
97
|
-
merge_equivalent_types(unwrapped_old, unwrapped_new)
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
# @api private
|
102
|
-
def change_from_any?(unwrapped_old)
|
103
|
-
unwrapped_old.is_a?(Dry::Types::AnyClass)
|
104
|
-
end
|
105
|
-
|
106
|
-
# @api private
|
107
|
-
def change_to_any?(unwrapped_new)
|
108
|
-
unwrapped_new.is_a?(Dry::Types::AnyClass)
|
109
|
-
end
|
110
|
-
|
111
|
-
# @api private
|
112
|
-
def change_from_hash_to_schema?(unwrapped_old, unwrapped_new)
|
113
|
-
unwrapped_old.is_a?(Dry::Types::Hash) && unwrapped_new.is_a?(Dry::Types::Schema)
|
114
|
-
end
|
115
|
-
|
116
|
-
# @api private
|
117
|
-
def change_from_schema_to_hash?(unwrapped_old, unwrapped_new)
|
118
|
-
unwrapped_old.is_a?(Dry::Types::Schema) && unwrapped_new.is_a?(Dry::Types::Hash)
|
119
|
-
end
|
120
|
-
|
121
|
-
# @api private
|
122
|
-
def change_from_schema_to_schema?(unwrapped_old, unwrapped_new)
|
123
|
-
unwrapped_old.is_a?(Dry::Types::Schema) && unwrapped_new.is_a?(Dry::Types::Schema)
|
69
|
+
# @api private
|
70
|
+
def merge_unwrapped_types(unwrapped_old, unwrapped_new)
|
71
|
+
case [unwrapped_old, unwrapped_new]
|
72
|
+
in ::Dry::Types::Schema, ::Dry::Types::Schema
|
73
|
+
merge_schemas(unwrapped_old, unwrapped_new)
|
74
|
+
in [::Dry::Types::AnyClass, _] | [::Dry::Types::Hash, ::Dry::Types::Schema]
|
75
|
+
unwrapped_new
|
76
|
+
in [::Dry::Types::Schema, ::Dry::Types::Hash] | [_, ::Dry::Types::AnyClass]
|
77
|
+
unwrapped_old
|
78
|
+
else
|
79
|
+
merge_equivalent_types(unwrapped_old, unwrapped_new)
|
124
80
|
end
|
125
81
|
end
|
126
82
|
|
@@ -142,7 +98,7 @@ module Dry
|
|
142
98
|
elsif unwrapped_new.primitive <= unwrapped_old.primitive
|
143
99
|
unwrapped_old
|
144
100
|
else
|
145
|
-
raise ArgumentError, <<~MESSAGE
|
101
|
+
raise ::ArgumentError, <<~MESSAGE
|
146
102
|
Can't merge types, unwrapped_old=#{unwrapped_old.inspect}, unwrapped_new=#{unwrapped_new.inspect}
|
147
103
|
MESSAGE
|
148
104
|
end
|
@@ -157,7 +113,7 @@ module Dry
|
|
157
113
|
|
158
114
|
if type.optional?
|
159
115
|
type = type.left.primitive?(nil) ? type.right : type.left
|
160
|
-
elsif type.is_a?(Dry::Types::Decorator)
|
116
|
+
elsif type.is_a?(::Dry::Types::Decorator)
|
161
117
|
type = type.type
|
162
118
|
else
|
163
119
|
break
|
data/lib/dry/schema/version.rb
CHANGED
data/lib/dry/schema.rb
CHANGED
@@ -12,14 +12,14 @@ module Dry
|
|
12
12
|
#
|
13
13
|
# @api public
|
14
14
|
module Schema
|
15
|
-
extend Dry::Core::Extensions
|
15
|
+
extend ::Dry::Core::Extensions
|
16
16
|
|
17
17
|
# @api private
|
18
18
|
def self.loader
|
19
|
-
@loader ||= Zeitwerk::Loader.new.tap do |loader|
|
20
|
-
root = File.expand_path("..", __dir__)
|
19
|
+
@loader ||= ::Zeitwerk::Loader.new.tap do |loader|
|
20
|
+
root = ::File.expand_path("..", __dir__)
|
21
21
|
loader.tag = "dry-schema"
|
22
|
-
loader.inflector = Zeitwerk::GemInflector.new("#{root}/dry-schema.rb")
|
22
|
+
loader.inflector = ::Zeitwerk::GemInflector.new("#{root}/dry-schema.rb")
|
23
23
|
loader.inflector.inflect(
|
24
24
|
"dsl" => "DSL",
|
25
25
|
"yaml" => "YAML",
|
@@ -64,8 +64,8 @@ module Dry
|
|
64
64
|
# @see DSL.new
|
65
65
|
#
|
66
66
|
# @api public
|
67
|
-
def self.define(
|
68
|
-
DSL.new(
|
67
|
+
def self.define(...)
|
68
|
+
DSL.new(...).call
|
69
69
|
end
|
70
70
|
|
71
71
|
# Define a schema suitable for HTTP params
|
@@ -83,10 +83,10 @@ module Dry
|
|
83
83
|
# @see Schema#define
|
84
84
|
#
|
85
85
|
# @api public
|
86
|
-
def self.Params(**options, &
|
87
|
-
define(**options, processor_type: Params, &
|
86
|
+
def self.Params(**options, &)
|
87
|
+
define(**options, processor_type: Params, &)
|
88
88
|
end
|
89
|
-
singleton_class.
|
89
|
+
singleton_class.alias_method(:Form, :Params)
|
90
90
|
|
91
91
|
# Define a schema suitable for JSON data
|
92
92
|
#
|
@@ -103,8 +103,8 @@ module Dry
|
|
103
103
|
# @see Schema#define
|
104
104
|
#
|
105
105
|
# @api public
|
106
|
-
def self.JSON(**options, &
|
107
|
-
define(**options, processor_type: JSON, &
|
106
|
+
def self.JSON(**options, &)
|
107
|
+
define(**options, processor_type: JSON, &)
|
108
108
|
end
|
109
109
|
|
110
110
|
loader.setup
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dry-schema
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.14.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Piotr Solnica
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-01-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|
@@ -50,74 +50,56 @@ dependencies:
|
|
50
50
|
requirements:
|
51
51
|
- - "~>"
|
52
52
|
- !ruby/object:Gem::Version
|
53
|
-
version: '1.
|
54
|
-
- - "<"
|
55
|
-
- !ruby/object:Gem::Version
|
56
|
-
version: '2'
|
53
|
+
version: '1.1'
|
57
54
|
type: :runtime
|
58
55
|
prerelease: false
|
59
56
|
version_requirements: !ruby/object:Gem::Requirement
|
60
57
|
requirements:
|
61
58
|
- - "~>"
|
62
59
|
- !ruby/object:Gem::Version
|
63
|
-
version: '1.
|
64
|
-
- - "<"
|
65
|
-
- !ruby/object:Gem::Version
|
66
|
-
version: '2'
|
60
|
+
version: '1.1'
|
67
61
|
- !ruby/object:Gem::Dependency
|
68
62
|
name: dry-initializer
|
69
63
|
requirement: !ruby/object:Gem::Requirement
|
70
64
|
requirements:
|
71
65
|
- - "~>"
|
72
66
|
- !ruby/object:Gem::Version
|
73
|
-
version: '3.
|
67
|
+
version: '3.2'
|
74
68
|
type: :runtime
|
75
69
|
prerelease: false
|
76
70
|
version_requirements: !ruby/object:Gem::Requirement
|
77
71
|
requirements:
|
78
72
|
- - "~>"
|
79
73
|
- !ruby/object:Gem::Version
|
80
|
-
version: '3.
|
74
|
+
version: '3.2'
|
81
75
|
- !ruby/object:Gem::Dependency
|
82
76
|
name: dry-logic
|
83
77
|
requirement: !ruby/object:Gem::Requirement
|
84
78
|
requirements:
|
85
|
-
- - "
|
86
|
-
- !ruby/object:Gem::Version
|
87
|
-
version: '1.4'
|
88
|
-
- - "<"
|
79
|
+
- - "~>"
|
89
80
|
- !ruby/object:Gem::Version
|
90
|
-
version: '
|
81
|
+
version: '1.5'
|
91
82
|
type: :runtime
|
92
83
|
prerelease: false
|
93
84
|
version_requirements: !ruby/object:Gem::Requirement
|
94
85
|
requirements:
|
95
|
-
- - "
|
96
|
-
- !ruby/object:Gem::Version
|
97
|
-
version: '1.4'
|
98
|
-
- - "<"
|
86
|
+
- - "~>"
|
99
87
|
- !ruby/object:Gem::Version
|
100
|
-
version: '
|
88
|
+
version: '1.5'
|
101
89
|
- !ruby/object:Gem::Dependency
|
102
90
|
name: dry-types
|
103
91
|
requirement: !ruby/object:Gem::Requirement
|
104
92
|
requirements:
|
105
|
-
- - "
|
106
|
-
- !ruby/object:Gem::Version
|
107
|
-
version: '1.7'
|
108
|
-
- - "<"
|
93
|
+
- - "~>"
|
109
94
|
- !ruby/object:Gem::Version
|
110
|
-
version: '
|
95
|
+
version: '1.8'
|
111
96
|
type: :runtime
|
112
97
|
prerelease: false
|
113
98
|
version_requirements: !ruby/object:Gem::Requirement
|
114
99
|
requirements:
|
115
|
-
- - "
|
116
|
-
- !ruby/object:Gem::Version
|
117
|
-
version: '1.7'
|
118
|
-
- - "<"
|
100
|
+
- - "~>"
|
119
101
|
- !ruby/object:Gem::Version
|
120
|
-
version: '
|
102
|
+
version: '1.8'
|
121
103
|
- !ruby/object:Gem::Dependency
|
122
104
|
name: zeitwerk
|
123
105
|
requirement: !ruby/object:Gem::Requirement
|
@@ -132,48 +114,6 @@ dependencies:
|
|
132
114
|
- - "~>"
|
133
115
|
- !ruby/object:Gem::Version
|
134
116
|
version: '2.6'
|
135
|
-
- !ruby/object:Gem::Dependency
|
136
|
-
name: bundler
|
137
|
-
requirement: !ruby/object:Gem::Requirement
|
138
|
-
requirements:
|
139
|
-
- - ">="
|
140
|
-
- !ruby/object:Gem::Version
|
141
|
-
version: '0'
|
142
|
-
type: :development
|
143
|
-
prerelease: false
|
144
|
-
version_requirements: !ruby/object:Gem::Requirement
|
145
|
-
requirements:
|
146
|
-
- - ">="
|
147
|
-
- !ruby/object:Gem::Version
|
148
|
-
version: '0'
|
149
|
-
- !ruby/object:Gem::Dependency
|
150
|
-
name: rake
|
151
|
-
requirement: !ruby/object:Gem::Requirement
|
152
|
-
requirements:
|
153
|
-
- - ">="
|
154
|
-
- !ruby/object:Gem::Version
|
155
|
-
version: '0'
|
156
|
-
type: :development
|
157
|
-
prerelease: false
|
158
|
-
version_requirements: !ruby/object:Gem::Requirement
|
159
|
-
requirements:
|
160
|
-
- - ">="
|
161
|
-
- !ruby/object:Gem::Version
|
162
|
-
version: '0'
|
163
|
-
- !ruby/object:Gem::Dependency
|
164
|
-
name: rspec
|
165
|
-
requirement: !ruby/object:Gem::Requirement
|
166
|
-
requirements:
|
167
|
-
- - ">="
|
168
|
-
- !ruby/object:Gem::Version
|
169
|
-
version: '0'
|
170
|
-
type: :development
|
171
|
-
prerelease: false
|
172
|
-
version_requirements: !ruby/object:Gem::Requirement
|
173
|
-
requirements:
|
174
|
-
- - ">="
|
175
|
-
- !ruby/object:Gem::Version
|
176
|
-
version: '0'
|
177
117
|
description: |+
|
178
118
|
dry-schema provides a DSL for defining schemas with keys and rules that should be applied to
|
179
119
|
values. It supports coercion, input sanitization, custom types and localized error messages
|
@@ -266,7 +206,8 @@ metadata:
|
|
266
206
|
changelog_uri: https://github.com/dry-rb/dry-schema/blob/main/CHANGELOG.md
|
267
207
|
source_code_uri: https://github.com/dry-rb/dry-schema
|
268
208
|
bug_tracker_uri: https://github.com/dry-rb/dry-schema/issues
|
269
|
-
|
209
|
+
rubygems_mfa_required: 'true'
|
210
|
+
post_install_message:
|
270
211
|
rdoc_options: []
|
271
212
|
require_paths:
|
272
213
|
- lib
|
@@ -274,7 +215,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
274
215
|
requirements:
|
275
216
|
- - ">="
|
276
217
|
- !ruby/object:Gem::Version
|
277
|
-
version: '
|
218
|
+
version: '3.1'
|
278
219
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
279
220
|
requirements:
|
280
221
|
- - ">="
|
@@ -282,7 +223,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
282
223
|
version: '0'
|
283
224
|
requirements: []
|
284
225
|
rubygems_version: 3.3.27
|
285
|
-
signing_key:
|
226
|
+
signing_key:
|
286
227
|
specification_version: 4
|
287
228
|
summary: Coercion and validation for data structures
|
288
229
|
test_files: []
|
230
|
+
...
|