dry-schema 1.10.1 → 1.10.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -0
- data/lib/dry/schema/dsl.rb +12 -5
- data/lib/dry/schema/macros/schema.rb +2 -2
- data/lib/dry/schema/macros/value.rb +2 -2
- data/lib/dry/schema/processor.rb +10 -1
- data/lib/dry/schema/types_merger.rb +49 -35
- data/lib/dry/schema/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0e0f30051a5014afc7cf0dc8f66f23a20f05e83dd3b2a970491d85d84e5be988
|
4
|
+
data.tar.gz: 771b790fd369f36abf86367a95afaac387825df4b041bdc325c02f7f41cd3487
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 12759b86883bd94e85480124539c44a3280491935a86addacd02c799696cce5d5e1cec54238b17d89c05cbe704e2394ac4749c9349e9f8e1bbe6ed92f344af73
|
7
|
+
data.tar.gz: 57b2a77a57ef8587a3a520eeecc7cc3dd5d766a92ba5096ed2306c0e466ee0c9580e7550c3ef475e88eb61a58ce7c92de3860442e29455f5590ccfa0bd7b5eda
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,15 @@
|
|
1
1
|
<!--- DO NOT EDIT THIS FILE - IT'S AUTOMATICALLY GENERATED VIA DEVTOOLS --->
|
2
2
|
|
3
|
+
## 1.10.2 2022-08-23
|
4
|
+
|
5
|
+
|
6
|
+
### Fixed
|
7
|
+
|
8
|
+
- Fix value coercion for composed schemas (via #421) (@robhanlon22)
|
9
|
+
|
10
|
+
|
11
|
+
[Compare v1.10.1...v1.10.2](https://github.com/dry-rb/dry-schema/compare/v1.10.1...v1.10.2)
|
12
|
+
|
3
13
|
## 1.10.1 2022-08-22
|
4
14
|
|
5
15
|
|
data/lib/dry/schema/dsl.rb
CHANGED
@@ -288,13 +288,20 @@ module Dry
|
|
288
288
|
|
289
289
|
# Return type schema used by the value coercer
|
290
290
|
#
|
291
|
-
# @return [Dry::Types::
|
291
|
+
# @return [Dry::Types::Lax]
|
292
292
|
#
|
293
293
|
# @api private
|
294
294
|
def type_schema
|
295
|
-
|
296
|
-
|
297
|
-
|
295
|
+
strict_type_schema.lax
|
296
|
+
end
|
297
|
+
|
298
|
+
# Return type schema used when composing subschemas
|
299
|
+
#
|
300
|
+
# @return [Dry::Types::Schema]
|
301
|
+
#
|
302
|
+
# @api private
|
303
|
+
def strict_type_schema
|
304
|
+
type_registry["hash"].schema(types)
|
298
305
|
end
|
299
306
|
|
300
307
|
# Return a new DSL instance using the same processor type
|
@@ -316,7 +323,7 @@ module Dry
|
|
316
323
|
# @api private
|
317
324
|
def set_type(name, spec)
|
318
325
|
type = resolve_type(spec)
|
319
|
-
meta = {required:
|
326
|
+
meta = {required: true, maybe: type.optional?}
|
320
327
|
|
321
328
|
@types[name] = type.meta(meta)
|
322
329
|
end
|
@@ -62,11 +62,11 @@ module Dry
|
|
62
62
|
schema = definition.call
|
63
63
|
type_schema =
|
64
64
|
if array_type?(parent_type)
|
65
|
-
build_array_type(parent_type, definition.
|
65
|
+
build_array_type(parent_type, definition.strict_type_schema)
|
66
66
|
elsif redefined_schema?(args)
|
67
67
|
parent_type.schema(definition.types)
|
68
68
|
else
|
69
|
-
definition.
|
69
|
+
definition.strict_type_schema
|
70
70
|
end
|
71
71
|
final_type = optional? ? type_schema.optional : type_schema
|
72
72
|
|
@@ -30,9 +30,9 @@ module Dry
|
|
30
30
|
|
31
31
|
updated_type =
|
32
32
|
if array_type?(current_type)
|
33
|
-
build_array_type(current_type, schema.
|
33
|
+
build_array_type(current_type, schema.strict_type_schema)
|
34
34
|
else
|
35
|
-
schema.
|
35
|
+
schema.strict_type_schema
|
36
36
|
end
|
37
37
|
|
38
38
|
import_steps(schema)
|
data/lib/dry/schema/processor.rb
CHANGED
@@ -138,13 +138,22 @@ module Dry
|
|
138
138
|
|
139
139
|
# Return the type schema
|
140
140
|
#
|
141
|
-
# @return [Dry::Types::
|
141
|
+
# @return [Dry::Types::Lax]
|
142
142
|
#
|
143
143
|
# @api private
|
144
144
|
def type_schema
|
145
145
|
steps.type_schema
|
146
146
|
end
|
147
147
|
|
148
|
+
# Return type schema used when composing subschemas
|
149
|
+
#
|
150
|
+
# @return [Dry::Types::Schema]
|
151
|
+
#
|
152
|
+
# @api private
|
153
|
+
def strict_type_schema
|
154
|
+
schema_dsl.strict_type_schema
|
155
|
+
end
|
156
|
+
|
148
157
|
# Return the rule applier
|
149
158
|
#
|
150
159
|
# @api private
|
@@ -27,34 +27,34 @@ module Dry
|
|
27
27
|
|
28
28
|
# @api private
|
29
29
|
def call
|
30
|
-
|
30
|
+
if op_class <= Dry::Logic::Operations::Or
|
31
|
+
merge_or
|
32
|
+
elsif op_class <= Dry::Logic::Operations::And
|
33
|
+
merge_and
|
34
|
+
elsif op_class <= Dry::Logic::Operations::Implication
|
35
|
+
merge_implication
|
36
|
+
else
|
37
|
+
raise ArgumentError, <<~MESSAGE
|
38
|
+
Can't merge operations, op_class=#{op_class}
|
39
|
+
MESSAGE
|
40
|
+
end
|
31
41
|
end
|
32
42
|
|
33
43
|
private
|
34
44
|
|
35
45
|
# @api private
|
36
|
-
def
|
37
|
-
@handlers ||=
|
38
|
-
{
|
39
|
-
Dry::Logic::Operations::Or => method(:handle_or),
|
40
|
-
Dry::Logic::Operations::And => method(:handle_and),
|
41
|
-
Dry::Logic::Operations::Implication => method(:handle_implication)
|
42
|
-
}
|
43
|
-
end
|
44
|
-
|
45
|
-
# @api private
|
46
|
-
def handle_or
|
46
|
+
def merge_or
|
47
47
|
old | new
|
48
48
|
end
|
49
49
|
|
50
50
|
# @api private
|
51
|
-
def
|
51
|
+
def merge_ordered
|
52
52
|
return old if old == new
|
53
53
|
|
54
54
|
unwrapped_old, old_rule = unwrap_type(old)
|
55
55
|
unwrapped_new, new_rule = unwrap_type(new)
|
56
56
|
|
57
|
-
type =
|
57
|
+
type = merge_unwrapped_types(unwrapped_old, unwrapped_new)
|
58
58
|
|
59
59
|
rule = [old_rule, new_rule].compact.reduce { op_class.new(_1, _2) }
|
60
60
|
|
@@ -63,32 +63,44 @@ module Dry
|
|
63
63
|
type
|
64
64
|
end
|
65
65
|
|
66
|
-
alias_method :
|
67
|
-
alias_method :
|
66
|
+
alias_method :merge_and, :merge_ordered
|
67
|
+
alias_method :merge_implication, :merge_ordered
|
68
68
|
|
69
69
|
# @api private
|
70
|
-
def
|
70
|
+
def merge_unwrapped_types(unwrapped_old, unwrapped_new)
|
71
71
|
case [unwrapped_old, unwrapped_new]
|
72
72
|
in Dry::Types::Schema, Dry::Types::Schema
|
73
|
-
|
74
|
-
types_merger.call(
|
75
|
-
op_class,
|
76
|
-
unwrapped_old.name_key_map,
|
77
|
-
unwrapped_new.name_key_map
|
78
|
-
)
|
79
|
-
)
|
73
|
+
merge_schemas(unwrapped_old, unwrapped_new)
|
80
74
|
in [Dry::Types::AnyClass, _] | [Dry::Types::Hash, Dry::Types::Schema]
|
81
75
|
unwrapped_new
|
82
|
-
in [Dry::Types::
|
76
|
+
in [Dry::Types::Schema, Dry::Types::Hash] | [_, Dry::Types::AnyClass]
|
83
77
|
unwrapped_old
|
84
78
|
else
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
MESSAGE
|
89
|
-
end
|
79
|
+
merge_equivalent_types(unwrapped_old, unwrapped_new)
|
80
|
+
end
|
81
|
+
end
|
90
82
|
|
83
|
+
# @api private
|
84
|
+
def merge_schemas(unwrapped_old, unwrapped_new)
|
85
|
+
types_merger.type_registry["hash"].schema(
|
86
|
+
types_merger.call(
|
87
|
+
op_class,
|
88
|
+
unwrapped_old.name_key_map,
|
89
|
+
unwrapped_new.name_key_map
|
90
|
+
)
|
91
|
+
)
|
92
|
+
end
|
93
|
+
|
94
|
+
# @api private
|
95
|
+
def merge_equivalent_types(unwrapped_old, unwrapped_new)
|
96
|
+
if unwrapped_old.primitive <= unwrapped_new.primitive
|
97
|
+
unwrapped_new
|
98
|
+
elsif unwrapped_new.primitive <= unwrapped_old.primitive
|
91
99
|
unwrapped_old
|
100
|
+
else
|
101
|
+
raise ArgumentError, <<~MESSAGE
|
102
|
+
Can't merge types, unwrapped_old=#{unwrapped_old.inspect}, unwrapped_new=#{unwrapped_new.inspect}
|
103
|
+
MESSAGE
|
92
104
|
end
|
93
105
|
end
|
94
106
|
|
@@ -96,13 +108,15 @@ module Dry
|
|
96
108
|
def unwrap_type(type)
|
97
109
|
rules = []
|
98
110
|
|
99
|
-
|
100
|
-
rules << type.rule if type.
|
111
|
+
loop do
|
112
|
+
rules << type.rule if type.respond_to?(:rule)
|
101
113
|
|
102
|
-
if type.
|
103
|
-
type = type.right
|
104
|
-
|
114
|
+
if type.optional?
|
115
|
+
type = type.left.primitive?(nil) ? type.right : type.left
|
116
|
+
elsif type.is_a?(Dry::Types::Decorator)
|
105
117
|
type = type.type
|
118
|
+
else
|
119
|
+
break
|
106
120
|
end
|
107
121
|
end
|
108
122
|
|
data/lib/dry/schema/version.rb
CHANGED
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.10.
|
4
|
+
version: 1.10.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Piotr Solnica
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-08-
|
11
|
+
date: 2022-08-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|