sorbet-schema 0.9.0 → 0.9.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2804e93c849ae225b0e969c926e6d45598d046cba32597de495fbbf2c9403e05
4
- data.tar.gz: c05a05390f42cc2ccb023fa5cd162544e6797acfdf7e5166169389e018d2ac91
3
+ metadata.gz: 4546ee5b80f3b538d7c3f9813501f066ef1f033693f5328f8789f26f9d7537dc
4
+ data.tar.gz: 3c658049c62dcd8ab506bc3cc72fa926731fd8a712c1436f0277339edc88d290
5
5
  SHA512:
6
- metadata.gz: 64b8c9f6c3178a37403f53e8117f417fa3de6f9ec867fc32abf11693e9a547effedce3602325518d539a27e342670ceaf2a6bd52096c69f8c082a819f838d177
7
- data.tar.gz: 948b563c632f8f599035ff93a17f779c1c18ecf002c484bfda3667874f83a41408ae3c5434d8122dc8f7cf085cf948f271ecd598219fb4e7b93eea5e8e174c55
6
+ metadata.gz: a2f8a6bec49a48abd11c0d6ee1eac7eb9d2a85965a02633635b9361d82bad46bedb6c02d213cf226f6cb644e803c575ded85e3eaf6c06cbe9ae34068e7dd1985
7
+ data.tar.gz: db1a6c0bf48b2fd6628b77dd324e06b42d9cb7e8e222b54523e0beeb7e10395b5a86d2a3fd7b3afe36453f2b8386f3bde758cbd9893aefee9e8d1fca8490f533
data/CHANGELOG.md CHANGED
@@ -4,6 +4,20 @@ All notable changes to this project will be documented in this file.
4
4
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5
5
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
 
7
+ ## [0.9.2](https://github.com/maxveldink/sorbet-schema/compare/v0.9.1...v0.9.2) (2024-09-04)
8
+
9
+
10
+ ### Bug Fixes
11
+
12
+ * bug coercing boolean strings ([#126](https://github.com/maxveldink/sorbet-schema/issues/126)) ([8035695](https://github.com/maxveldink/sorbet-schema/commit/8035695ab79af2b9eb03d7f6418409bd3a899084))
13
+
14
+ ## [0.9.1](https://github.com/maxveldink/sorbet-schema/compare/v0.9.0...v0.9.1) (2024-08-14)
15
+
16
+
17
+ ### Bug Fixes
18
+
19
+ * add sorbet-schema shim for better T:Struct extension compatability ([#123](https://github.com/maxveldink/sorbet-schema/issues/123)) ([b47cafb](https://github.com/maxveldink/sorbet-schema/commit/b47cafb9820141c7e8e7759e3a561f23bc01f9aa))
20
+
7
21
  ## [0.9.0](https://github.com/maxveldink/sorbet-schema/compare/v0.8.0...v0.9.0) (2024-08-05)
8
22
 
9
23
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- sorbet-schema (0.9.0)
4
+ sorbet-schema (0.9.2)
5
5
  sorbet-result (~> 1.1)
6
6
  sorbet-runtime (~> 0.5)
7
7
  sorbet-struct-comparable (~> 1.3)
@@ -1,18 +1,12 @@
1
- # typed: strict
1
+ # typed: true
2
2
 
3
3
  module T
4
4
  class Struct
5
- extend T::Sig
6
-
7
5
  class << self
8
- extend T::Sig
9
-
10
- sig { overridable.returns(Typed::Schema) }
11
6
  def schema
12
7
  Typed::Schema.from_struct(self)
13
8
  end
14
9
 
15
- sig { params(type: Symbol, options: T::Hash[Symbol, T.untyped]).returns(Typed::Serializer[T.untyped, T.untyped]) }
16
10
  def serializer(type, options: {})
17
11
  case type
18
12
  when :hash
@@ -24,13 +18,11 @@ module T
24
18
  end
25
19
  end
26
20
 
27
- sig { params(serializer_type: Symbol, source: T.untyped, options: T::Hash[Symbol, T.untyped]).returns(Typed::Serializer::DeserializeResult) }
28
21
  def deserialize_from(serializer_type, source, options: {})
29
- serializer(serializer_type, options:).deserialize(source)
22
+ T.unsafe(serializer(serializer_type, options:).deserialize(source))
30
23
  end
31
24
  end
32
25
 
33
- sig { params(serializer_type: Symbol, options: T::Hash[Symbol, T.untyped]).returns(Typed::Result[T.untyped, Typed::SerializeError]) }
34
26
  def serialize_to(serializer_type, options: {})
35
27
  self.class.serializer(serializer_type, options:).serialize(self)
36
28
  end
@@ -1,5 +1,5 @@
1
1
  # typed: strict
2
2
 
3
3
  module SorbetSchema
4
- VERSION = "0.9.0"
4
+ VERSION = "0.9.2"
5
5
  end
@@ -34,11 +34,19 @@ module Typed
34
34
  def deserialize_from_creation_params(creation_params)
35
35
  results = schema.fields.map do |field|
36
36
  value = creation_params.fetch(field.name, nil)
37
+ coercer = Coercion::CoercerRegistry.instance.select_coercer_by(type: field.type)
37
38
 
38
39
  if value.nil? && !field.default.nil?
39
40
  Success.new(Validations::ValidatedValue.new(name: field.name, value: field.default))
40
41
  elsif value.nil? || field.works_with?(value)
41
42
  field.validate(value)
43
+ elsif !coercer.nil?
44
+ result = coercer.new.coerce(type: field.type, value:)
45
+ if result.success?
46
+ field.validate(result.payload)
47
+ else
48
+ Failure.new(Validations::ValidationError.new(result.error.message))
49
+ end
42
50
  elsif field.type.class <= T::Types::Union
43
51
  errors = []
44
52
  validated_value = T.let(nil, T.nilable(Typed::Result[Typed::Validations::ValidatedValue, Typed::Validations::ValidationError]))
@@ -60,13 +68,7 @@ module Typed
60
68
 
61
69
  validated_value.nil? ? Failure.new(Validations::ValidationError.new(errors.map(&:message).join(", "))) : validated_value
62
70
  else
63
- coercion_result = Coercion.coerce(type: field.type, value:)
64
-
65
- if coercion_result.success?
66
- field.validate(coercion_result.payload)
67
- else
68
- Failure.new(Validations::ValidationError.new(coercion_result.error.message))
69
- end
71
+ Failure.new(Validations::ValidationError.new("Coercer not found for type #{field.type}."))
70
72
  end
71
73
  end
72
74
 
@@ -0,0 +1,21 @@
1
+ # typed: strict
2
+
3
+ class T::Struct
4
+ class << self
5
+ sig { overridable.returns(Typed::Schema) }
6
+ def schema
7
+ end
8
+
9
+ sig { params(type: Symbol, options: T::Hash[Symbol, T.untyped]).returns(Typed::Serializer[T.untyped, T.untyped]) }
10
+ def serializer(type, options: {})
11
+ end
12
+
13
+ sig { params(serializer_type: Symbol, source: T.untyped, options: T::Hash[Symbol, T.untyped]).returns(Typed::Result[T.attached_class, Typed::DeserializeError]) }
14
+ def deserialize_from(serializer_type, source, options: {})
15
+ end
16
+ end
17
+
18
+ sig { params(serializer_type: Symbol, options: T::Hash[Symbol, T.untyped]).returns(Typed::Result[T.untyped, Typed::SerializeError]) }
19
+ def serialize_to(serializer_type, options: {})
20
+ end
21
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sorbet-schema
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.9.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Max VelDink
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-08-05 00:00:00.000000000 Z
11
+ date: 2024-09-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sorbet-result
@@ -121,6 +121,7 @@ files:
121
121
  - lib/typed/validations/validated_value.rb
122
122
  - lib/typed/validations/validation_error.rb
123
123
  - lib/typed/validations/validation_results.rb
124
+ - rbi/sorbet-schema.rbi
124
125
  - release-please-config.json
125
126
  - release-please-manifest.json
126
127
  - sorbet/config
@@ -182,6 +183,7 @@ post_install_message:
182
183
  rdoc_options: []
183
184
  require_paths:
184
185
  - lib
186
+ - rbi
185
187
  required_ruby_version: !ruby/object:Gem::Requirement
186
188
  requirements:
187
189
  - - ">="