dry-schema 1.2.0 → 1.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +214 -100
- data/README.md +4 -2
- data/config/errors.yml +9 -0
- data/lib/dry/schema/constants.rb +3 -2
- data/lib/dry/schema/dsl.rb +64 -17
- data/lib/dry/schema/extensions/hints/message_set_methods.rb +48 -1
- data/lib/dry/schema/macros/dsl.rb +22 -11
- data/lib/dry/schema/macros/filled.rb +0 -7
- data/lib/dry/schema/macros/key.rb +0 -1
- data/lib/dry/schema/macros/schema.rb +18 -7
- data/lib/dry/schema/macros/value.rb +21 -2
- data/lib/dry/schema/message.rb +1 -1
- data/lib/dry/schema/message_compiler.rb +2 -1
- data/lib/dry/schema/messages/abstract.rb +42 -12
- data/lib/dry/schema/messages/i18n.rb +9 -0
- data/lib/dry/schema/messages/namespaced.rb +6 -1
- data/lib/dry/schema/messages/yaml.rb +12 -0
- data/lib/dry/schema/namespaced_rule.rb +2 -1
- data/lib/dry/schema/path.rb +10 -6
- data/lib/dry/schema/predicate_inferrer.rb +69 -16
- data/lib/dry/schema/predicate_registry.rb +2 -23
- data/lib/dry/schema/processor.rb +9 -26
- data/lib/dry/schema/processor_steps.rb +116 -0
- data/lib/dry/schema/trace.rb +15 -20
- data/lib/dry/schema/type_registry.rb +2 -2
- data/lib/dry/schema/version.rb +1 -1
- metadata +5 -5
- data/lib/dry/schema/primitive_inferrer.rb +0 -98
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 130427870a9d2f124a3fbd39a55f700c2c905c34a6ffab9b5e12946321f647aa
|
4
|
+
data.tar.gz: 71514ff28540db733a7d280656931c2e0f54b4f73b4a94b21e3a092234bfdfae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 42ed8a3c94600c20c2a1e843c76b2a945d9ef0b46bfa8379acf5369016899642525a9f3f6b574cc4e71b211ee690845abb0d164c07b681d19dfce474abd9ef92
|
7
|
+
data.tar.gz: c0485078b33e945a2174c3ceb349c7e46c40ada2007c8a6e6f671c8e31c57e25e4142902e0ff9638f118179169162c8225292bde042dc2e2082b4dd078bfc36f
|
data/CHANGELOG.md
CHANGED
@@ -1,22 +1,136 @@
|
|
1
|
+
# 1.4.1 2019-10-08
|
2
|
+
|
3
|
+
### Fixed
|
4
|
+
|
5
|
+
- Child schemas no longer mutate processing steps of their parent classes (@skryukov)
|
6
|
+
|
7
|
+
[Compare v1.4.0...v1.4.1](https://github.com/dry-rb/dry-schema/compare/v1.4.0...v1.4.1)
|
8
|
+
|
9
|
+
# 1.4.0 2019-10-08
|
10
|
+
|
11
|
+
### Added
|
12
|
+
|
13
|
+
- Support for passing multiple parent schemas. They are inherited from left to right (@ianwhite)
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
Dry::Schema.define(parent: [parent_a, parent_b, parent_c]) do
|
17
|
+
...
|
18
|
+
end
|
19
|
+
```
|
20
|
+
|
21
|
+
- Improved error messages about missing translations (@skryukov)
|
22
|
+
- [experimental] before/after callbacks for schema steps (@skryukov)
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
Dry::Schema.Params do
|
26
|
+
required(:name).value(:string)
|
27
|
+
optional(:age).value(:integer)
|
28
|
+
|
29
|
+
before(:value_coercer) do |result|
|
30
|
+
result.to_h.compact
|
31
|
+
end
|
32
|
+
end
|
33
|
+
```
|
34
|
+
|
35
|
+
### Fixed
|
36
|
+
|
37
|
+
- Added/fixed support for custom optional types (@flash-gordon)
|
38
|
+
|
39
|
+
[Compare v1.3.4...v1.4.0](https://github.com/dry-rb/dry-schema/compare/v1.3.4...v1.4.0)
|
40
|
+
|
41
|
+
# 1.3.4 2019-09-11
|
42
|
+
|
43
|
+
### Fixed
|
44
|
+
|
45
|
+
- Fixed regression where using `array?` predicate within a block would crach (issue #186) (@skryukov)
|
46
|
+
|
47
|
+
[Compare v1.3.3...v1.3.4](https://github.com/dry-rb/dry-schema/compare/v1.3.3...v1.3.4)
|
48
|
+
|
49
|
+
# 1.3.3 2019-08-14
|
50
|
+
|
51
|
+
### Fixed
|
52
|
+
|
53
|
+
- Reject attempts to build a nested schema for array types built on `Dry::Types::Nominal` (fixed #171) (@flash-gordon)
|
54
|
+
- Current `I18n.locale` is now properly handled when caching message templates (@flash-gordon)
|
55
|
+
- Default processor uses strict types by default, which fixes various cases when `maybe` is used with a constructor type (@flash-gordon)
|
56
|
+
- Namespaced messages no longer causes a crash when used with nested schemas (fixed #176) (@solnic)
|
57
|
+
|
58
|
+
[Compare v1.3.2...v1.3.3](https://github.com/dry-rb/dry-schema/compare/v1.3.2...v1.3.3)
|
59
|
+
|
60
|
+
# 1.3.2 2019-08-01
|
61
|
+
|
62
|
+
### Added
|
63
|
+
|
64
|
+
- Support for new predicates: `bytesize?`, `min_bytesize?` and `max_bytesize?` (@bmalinconico)
|
65
|
+
|
66
|
+
[Compare v1.3.1...v1.3.2](https://github.com/dry-rb/dry-schema/compare/v1.3.1...v1.3.2)
|
67
|
+
|
68
|
+
# 1.3.1 2019-07-08
|
69
|
+
|
70
|
+
### Fixed
|
71
|
+
|
72
|
+
- `Result#error?` works correctly with nested hashes and arrays (@solnic)
|
73
|
+
- `:hints` extension no longer causes a crash where base messages are generated too (issue #165) (@solnic)
|
74
|
+
|
75
|
+
[Compare v1.3.0...v1.3.1](https://github.com/dry-rb/dry-schema/compare/v1.3.0...v1.3.1)
|
76
|
+
|
77
|
+
# 1.3.0 2019-07-06
|
78
|
+
|
79
|
+
### Added
|
80
|
+
|
81
|
+
- Automatic predicate inferring for constrained types! (@flash-gordon)
|
82
|
+
|
83
|
+
```ruby
|
84
|
+
Types::Name = Types::String.constrained(min_size: 1)
|
85
|
+
|
86
|
+
schema = Dry::Schema.define do
|
87
|
+
required(:name).value(Types::Name)
|
88
|
+
end
|
89
|
+
|
90
|
+
schema.(name: '').errors.to_h # => { name: ["size cannot be less than 1"] }
|
91
|
+
```
|
92
|
+
|
93
|
+
- Support for redefining re-used schemas (issue #43) (@skryukov)
|
94
|
+
|
95
|
+
### Fixed
|
96
|
+
|
97
|
+
- Type container is passed down to nested schemas (@flash-gordon)
|
98
|
+
|
99
|
+
[Compare v1.2.0...v1.3.0](https://github.com/dry-rb/dry-schema/compare/v1.2.0...v1.3.0)
|
100
|
+
|
1
101
|
# v1.2.0 2019-06-13
|
2
102
|
|
3
103
|
### Added
|
4
104
|
|
5
|
-
|
105
|
+
- Ability to configure your own type container (@Morozzzko)
|
106
|
+
|
107
|
+
```ruby
|
108
|
+
types = Dry::Schema::TypeContainer.new
|
109
|
+
types.register(
|
110
|
+
'params.trimmed_string',
|
111
|
+
Types::String.constructor(&:strip).constructor(&:downcase)
|
112
|
+
)
|
113
|
+
|
114
|
+
Dry::Schema.Params do
|
115
|
+
config.types = types
|
116
|
+
|
117
|
+
require(:name).value(:trimmed_string)
|
118
|
+
end
|
119
|
+
```
|
6
120
|
|
7
121
|
### Fixed
|
8
122
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
123
|
+
- `filled` macro no longer generates incorrect messages for arrays (issue #151) (@solnic)
|
124
|
+
- `filled` macro works correctly with constructor types (@solnic)
|
125
|
+
- `filled` works correctly with nested schemas (#149) (@solnic + @timriley)
|
126
|
+
- Custom array constructors are no longer discredited by `array` macro (@solnic)
|
127
|
+
- `BigDecimal` type is correctly handled by predicate inference (@solnic)
|
128
|
+
- Works with latest `dry-logic` which provides the new `respond_to?` predicate (#153) (@flash-gordon)
|
15
129
|
|
16
130
|
### Changed
|
17
131
|
|
18
|
-
|
19
|
-
|
132
|
+
- Fixes related to `filled` restored pre-1.1.0 behavior of `:hints` which are again included (@solnic)
|
133
|
+
- `filled` no longer uses filter rules to handle empty strings in `Params` (@solnic)
|
20
134
|
|
21
135
|
[Compare v1.1.0...v1.2.0](https://github.com/dry-rb/dry-schema/compare/v1.1.0...v1.2.0)
|
22
136
|
|
@@ -24,18 +138,18 @@
|
|
24
138
|
|
25
139
|
### Added
|
26
140
|
|
27
|
-
|
28
|
-
|
141
|
+
- `config.messages.default_locale` for setting...default locale (surprise, surprise) (@solnic)
|
142
|
+
- `Config` exposes `predicates` setting too (@solnic)
|
29
143
|
|
30
144
|
### Fixed
|
31
145
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
146
|
+
- `filled` macro behavior results in `must be filled` error messages when appropriate - see PR #141 for more information (issue #134) (@solnic)
|
147
|
+
- Filter rules no longer cause keys to be added to input (issue #142) (@solnic)
|
148
|
+
- Filter rules work now with inheritance (@solnic)
|
149
|
+
- Inherited type schemas used by coercion are now properly configured as `lax` type (@solnic)
|
150
|
+
- `Config` is now finalized before instantiating schemas and properly dupped when its inherited (@flash-gordon + @solnic)
|
151
|
+
- `Config#eql?` works as expected (@solnic)
|
152
|
+
- Predicates are properly inferred from array with a member type spec, ie `array[:integer]` results in `array? + each(:integer?)` (issue #140) (@solnic)
|
39
153
|
|
40
154
|
[Compare v1.0.3...v1.1.0](https://github.com/dry-rb/dry-schema/compare/v1.0.3...v1.1.0)
|
41
155
|
|
@@ -43,9 +157,9 @@
|
|
43
157
|
|
44
158
|
### Fixed
|
45
159
|
|
46
|
-
|
47
|
-
|
48
|
-
|
160
|
+
- `Object#hash` is no longer used to calculate cache keys due to a potential risk of having hash collisions (@solnic)
|
161
|
+
- Predicate arguments are used again for template cache keys (@solnic)
|
162
|
+
- `I18n` messages backend no longer evaluates templates twice (@solnic)
|
49
163
|
|
50
164
|
[Compare v1.0.2...v1.0.3](https://github.com/dry-rb/dry-schema/compare/v1.0.2...v1.0.3)
|
51
165
|
|
@@ -53,7 +167,7 @@
|
|
53
167
|
|
54
168
|
### Fixed
|
55
169
|
|
56
|
-
|
170
|
+
- Caching message templates uses restricted set of known keys to calculate cache keys (issue #132) (@solnic)
|
57
171
|
|
58
172
|
[Compare v1.0.1...v1.0.2](https://github.com/dry-rb/dry-schema/compare/v1.0.1...v1.0.2)
|
59
173
|
|
@@ -61,7 +175,7 @@
|
|
61
175
|
|
62
176
|
### Fixed
|
63
177
|
|
64
|
-
|
178
|
+
- Applying `key?` predicate no longer causes recursive calls to `Result#errors` (issue #130) (@solnic)
|
65
179
|
|
66
180
|
[Compare v1.0.0...v1.0.1](https://github.com/dry-rb/dry-schema/compare/v1.0.0...v1.0.1)
|
67
181
|
|
@@ -69,12 +183,12 @@
|
|
69
183
|
|
70
184
|
### Changed
|
71
185
|
|
72
|
-
|
186
|
+
- [BREAKING] `Result#to_hash` was removed (@solnic)
|
73
187
|
|
74
188
|
### Fixed
|
75
189
|
|
76
|
-
|
77
|
-
|
190
|
+
- Setting `:any` as the type spec no longer crashes (@solnic)
|
191
|
+
- `Result#error?` handles paths to array elements correctly (@solnic)
|
78
192
|
|
79
193
|
[Compare v0.6.0...v1.0.0](https://github.com/dry-rb/dry-schema/compare/v0.6.0...v1.0.0)
|
80
194
|
|
@@ -82,9 +196,9 @@
|
|
82
196
|
|
83
197
|
### Changed
|
84
198
|
|
85
|
-
|
86
|
-
|
87
|
-
|
199
|
+
- Dependency on `dry-types` was bumped to `~> 1.0` (@solnic)
|
200
|
+
- Dependency on `dry-logic` was bumped to `~> 1.0` (@solnic)
|
201
|
+
- Dependency on `dry-initializer` was bumped to `~> 3.0` (@solnic)
|
88
202
|
|
89
203
|
[Compare v0.5.1...v0.6.0](https://github.com/dry-rb/dry-schema/compare/v0.5.1...v0.6.0)
|
90
204
|
|
@@ -92,7 +206,7 @@
|
|
92
206
|
|
93
207
|
### Fixed
|
94
208
|
|
95
|
-
|
209
|
+
- Key map no longer crashes on unexpected input (issue #118) (@solnic)
|
96
210
|
|
97
211
|
[Compare v0.5.0...v0.5.1](https://github.com/dry-rb/dry-schema/compare/v0.5.0...v0.5.1)
|
98
212
|
|
@@ -100,40 +214,40 @@
|
|
100
214
|
|
101
215
|
### Added
|
102
216
|
|
103
|
-
|
217
|
+
- Support for arbitrary meta-data in messages, ie:
|
104
218
|
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
219
|
+
```yaml
|
220
|
+
en:
|
221
|
+
dry_schema:
|
222
|
+
errors:
|
223
|
+
filled?:
|
224
|
+
text: "cannot be blank"
|
225
|
+
code: 123
|
226
|
+
```
|
113
227
|
|
114
|
-
|
228
|
+
Now your error hash will include `{ foo: [{ text: 'cannot be blank', code: 123 }] }` (@solnic + @flash-gordon)
|
115
229
|
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
230
|
+
- Support for type specs in `array` macro, ie `required(:tags).array(:integer)` (@solnic)
|
231
|
+
- Support for type specs in `each` macro, ie `required(:tags).each(:integer)` (@solnic)
|
232
|
+
- Shortcut for defining an array with hash as its member, ie:
|
233
|
+
|
234
|
+
```ruby
|
235
|
+
Dry::Schema.Params do
|
236
|
+
required(:tags).array(:hash) do
|
237
|
+
required(:name).filled(:string)
|
238
|
+
end
|
239
|
+
end
|
240
|
+
```
|
127
241
|
|
128
242
|
### Fixed
|
129
243
|
|
130
|
-
|
131
|
-
|
244
|
+
- Inferring predicates doesn't crash when `Any` type is used (@flash-gordon)
|
245
|
+
- Inferring type specs when type is already set works correctly (@solnic)
|
132
246
|
|
133
247
|
### Changed
|
134
248
|
|
135
|
-
|
136
|
-
|
249
|
+
- [BREAKING] `:monads` extension wraps entire result objects in `Success` or `Failure` (@flash-gordon)
|
250
|
+
- When `:hints` are disabled, result AST will not include hint nodes (@solnic)
|
137
251
|
|
138
252
|
[Compare v0.4.0...v0.5.0](https://github.com/dry-rb/dry-schema/compare/v0.4.0...v0.5.0)
|
139
253
|
|
@@ -141,30 +255,30 @@
|
|
141
255
|
|
142
256
|
### Added
|
143
257
|
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
258
|
+
- Schemas are now compatible with procs via `#to_proc` (issue #53) (@solnic)
|
259
|
+
- Support for configuring `top_namespace` for localized messages (@solnic)
|
260
|
+
- Support for configuring more than one load path for localized messages (@solnic)
|
261
|
+
- Support for inferring predicates from arbitrary types (issue #101) (@solnic)
|
148
262
|
|
149
263
|
### Fixed
|
150
264
|
|
151
|
-
|
152
|
-
|
153
|
-
|
265
|
+
- Handling of messages for `optional` keys without value rules works correctly (issue #87) (@solnic)
|
266
|
+
- Message structure for `optional` keys with an array of hashes no longer duplicates keys (issue #89) (@solnic)
|
267
|
+
- Inferring `:date_time?` predicate works correctly with `DateTime` types (issue #97) (@solnic)
|
154
268
|
|
155
269
|
### Changed
|
156
270
|
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
271
|
+
- [BREAKING] Updated to work with `dry-types 0.15.0` (@flash-gordon)
|
272
|
+
- [BREAKING] `Result#{errors,messages,hints}` returns `MessageSet` object now which is an enumerable coercible to a hash (@solnic)
|
273
|
+
- [BREAKING] `Messages` backend classes no longer use global configuration (@solnic)
|
274
|
+
- [BREAKING] Passing a non-symbol key name in the DSL will raise `ArgumentError` (issue #29) (@solnic)
|
275
|
+
- [BREAKING] Configuration for message backends is now nested under `messages` key with following settings:
|
276
|
+
- `messages.backend` - previously `messages`
|
277
|
+
- `messages.load_paths` - previously `messages_path`
|
278
|
+
- `messages.namespace` - previously `namespace`
|
279
|
+
- `messages.top_namespace` - **new setting** see above
|
280
|
+
- [BREAKING] `Messages::I18n` uses `I18.store_translations` instead of messing with `I18n.load_path` (@solnic)
|
281
|
+
- Schemas (`Params` and `JSON`) have nicer inspect (@solnic)
|
168
282
|
|
169
283
|
[Compare v0.3.0...v0.4.0](https://github.com/dry-rb/dry-schema/compare/v0.3.0...v0.4.0)
|
170
284
|
|
@@ -172,16 +286,16 @@
|
|
172
286
|
|
173
287
|
### Fixed
|
174
288
|
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
289
|
+
- Configuration is properly inherited from a parent schema (@skryukov)
|
290
|
+
- `Result#error?` returns `true` when a preceding key has errors (@solnic)
|
291
|
+
- Predicate inferrer no longer chokes on sum, constructor and enum types (@solnic)
|
292
|
+
- Predicate inferrer infers `:bool?` from boolean types (@solnic)
|
293
|
+
- Block-based definitions using `array` works correctly (@solnic)
|
294
|
+
- Using a disjunction with `array` and `hash` produces correct errors when element validation for array failed (@solnic)
|
181
295
|
|
182
296
|
### Changed
|
183
297
|
|
184
|
-
|
298
|
+
- Required ruby version was removed from gemspec for people who are stuck on MRI 2.3.x (@solnic)
|
185
299
|
|
186
300
|
[Compare v0.2.0...v0.3.0](https://github.com/dry-rb/dry-schema/compare/v0.2.0...v0.3.0)
|
187
301
|
|
@@ -189,28 +303,28 @@
|
|
189
303
|
|
190
304
|
### Added
|
191
305
|
|
192
|
-
|
193
|
-
|
306
|
+
- New `hash` macro which prepends `hash?` type-check and allows nested schema definition (@solnic)
|
307
|
+
- New `array` macro which works like `each` but prepends `array?` type-check (@solnic)
|
194
308
|
|
195
309
|
### Fixed
|
196
310
|
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
311
|
+
- Rule name translation works correctly with I18n (issue #52) (@solnic)
|
312
|
+
- Rule name translation works correctly with namespaced messages (both I18n and plain YAML) (issue #57) (@solnic)
|
313
|
+
- Error messages under namespaces are correctly resolved for overridden names (issue #53) (@solnic)
|
314
|
+
- Namespaced error messages work correctly when schemas are reused within other schemas (issue #49) (@solnic)
|
315
|
+
- Child schema can override inherited rules now (issue #66) (@skryukov)
|
316
|
+
- Hints are correctly generated for disjunction that use type-check predicates (issue #24) (@solnic)
|
317
|
+
- Hints are correctly generated for nested schemas (issue #26) (@solnic)
|
318
|
+
- `filled` macro respects inferred type-check predicates and puts them in front (@solnic)
|
319
|
+
- Value coercion works correctly with re-usable nested schemas (issue #25) (@solnic)
|
206
320
|
|
207
321
|
### Changed
|
208
322
|
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
323
|
+
- [BREAKING] **Messages are now configured under `dry_schema` namespace by default** (issue #38) (@solnic)
|
324
|
+
- [BREAKING] Hints are now an optional feature provided by `:hints` extension, to load it do `Dry::Schema.load_extensions(:hints)` (@solnic)
|
325
|
+
- [BREAKING] Hints generation was improved in general, output of `Result#messages` and `Result#hints` changed in some cases (@solnic)
|
326
|
+
- [BREAKING] `schema` macro no longer prepends `hash?` check, for this behavior use the new `hash` macro (see #31) (@solnic)
|
327
|
+
- [BREAKING] Support for MRI < 2.4 was dropped (@solnic)
|
214
328
|
|
215
329
|
[Compare v0.1.1...v0.2.0](https://github.com/dry-rb/dry-schema/compare/v0.1.1...v0.2.0)
|
216
330
|
|
@@ -218,16 +332,16 @@
|
|
218
332
|
|
219
333
|
### Added
|
220
334
|
|
221
|
-
- `Result#error?` supports checking nested errors too ie`result.error?('user.address')` (solnic)
|
335
|
+
- `Result#error?` supports checking nested errors too ie`result.error?('user.address')` (@solnic)
|
222
336
|
|
223
337
|
### Fixed
|
224
338
|
|
225
|
-
- Fix issues with templates and invalid tokens (issue #27) (solnic)
|
226
|
-
- Fix Ruby warnings (flash-gordon)
|
339
|
+
- Fix issues with templates and invalid tokens (issue #27) (@solnic)
|
340
|
+
- Fix Ruby warnings (@flash-gordon)
|
227
341
|
|
228
342
|
### Internal
|
229
343
|
|
230
|
-
- Key and value coercers are now equalizable (flash-gordon)
|
344
|
+
- Key and value coercers are now equalizable (@flash-gordon)
|
231
345
|
|
232
346
|
[Compare v0.1.0...v0.1.1](https://github.com/dry-rb/dry-schema/compare/v0.1.0...v0.1.1)
|
233
347
|
|