sorbet-schema 0.6.0 → 0.7.1

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: 1b4040ccaa87f90e0d32acee9868fffb0f4d645e599fe29726738fdb54c4f1e6
4
- data.tar.gz: b83d96b38d8b7d786a3e174e576053f531bf03e237d7c1f049e98b9c813dc117
3
+ metadata.gz: e46419810b44afbd517689ff86c8eb5af8a5b70ef8883ae94d5c9b2645d5b68d
4
+ data.tar.gz: 054a2bcef831395c8a4010099441bbf8ac661292812f078cfd595012f337ada9
5
5
  SHA512:
6
- metadata.gz: 248121230fc7a86b616259a89db47c210360034aad0ec70a23e2b25d73b350e16eff09c09ea87efd0aa859ef86b6f5c7f7700043b2e0d3e1f570555e98baac31
7
- data.tar.gz: 6f0c35a33ff1e84ebe704c30a6d0ba4b3520030c8ca59c897c33cc96f736c48c16e8672e7f4efef6f81f4a9816326db41c1cc625f49addd520a437066a04db1c
6
+ metadata.gz: de8f70512ab216e8cb937b0910b8f69ea9cd8028bb2fb8f1c881ff2a296131e4608d48f2e74306918a8ab876573aef75d8b821a783351dfc0657d7d33fb46764
7
+ data.tar.gz: ae7541ea2939e65524dfbf9940d8aad2fd5e743a01ab23c16d3ce0b8f151b47122e856ed2ec7864d06c24c89c9bb1bac35baa377e86c24dcb3d85efe21376424
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 3.3.0
1
+ 3.3.4
data/CHANGELOG.md CHANGED
@@ -4,6 +4,24 @@ 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.7.1](https://github.com/maxveldink/sorbet-schema/compare/v0.7.0...v0.7.1) (2024-07-09)
8
+
9
+
10
+ ### Features
11
+
12
+ * Add clearer message for CoercionNotSupportedError ([#113](https://github.com/maxveldink/sorbet-schema/issues/113)) ([0eff2f7](https://github.com/maxveldink/sorbet-schema/commit/0eff2f77d0ae3dfb9def11a696afd338df993a54))
13
+
14
+ ## [0.7.0](https://github.com/maxveldink/sorbet-schema/compare/v0.6.0...v0.7.0) (2024-07-08)
15
+
16
+
17
+ ### ⚠ BREAKING CHANGES
18
+
19
+ * Fix mis-serializing hash keys that were suppose to be strings ([#111](https://github.com/maxveldink/sorbet-schema/issues/111))
20
+
21
+ ### Bug Fixes
22
+
23
+ * Fix mis-serializing hash keys that were suppose to be strings ([#111](https://github.com/maxveldink/sorbet-schema/issues/111)) ([485a6c7](https://github.com/maxveldink/sorbet-schema/commit/485a6c7a83b9e70c731930d8406925304efa04a8))
24
+
7
25
  ## [0.6.0](https://github.com/maxveldink/sorbet-schema/compare/v0.5.1...v0.6.0) (2024-07-07)
8
26
 
9
27
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- sorbet-schema (0.6.0)
4
+ sorbet-schema (0.7.1)
5
5
  sorbet-result (~> 1.1)
6
6
  sorbet-runtime (~> 0.5)
7
7
  sorbet-struct-comparable (~> 1.3)
@@ -19,13 +19,13 @@ GEM
19
19
  reline (>= 0.3.8)
20
20
  erubi (1.13.0)
21
21
  io-console (0.7.2)
22
- irb (1.13.2)
22
+ irb (1.14.0)
23
23
  rdoc (>= 4.0.0)
24
24
  reline (>= 0.4.2)
25
25
  json (2.7.2)
26
26
  language_server-protocol (3.17.0.3)
27
27
  lint_roller (1.1.0)
28
- minitest (5.24.0)
28
+ minitest (5.24.1)
29
29
  minitest-focus (1.4.0)
30
30
  minitest (>= 4, < 6)
31
31
  minitest-reporters (1.7.1)
@@ -52,7 +52,7 @@ GEM
52
52
  regexp_parser (2.9.2)
53
53
  reline (0.5.9)
54
54
  io-console (~> 0.5)
55
- rexml (3.3.0)
55
+ rexml (3.3.1)
56
56
  strscan
57
57
  rubocop (1.64.1)
58
58
  json (~> 2.3)
@@ -73,24 +73,24 @@ GEM
73
73
  rubocop-sorbet (0.7.8)
74
74
  rubocop (>= 0.90.0)
75
75
  ruby-progressbar (1.13.0)
76
- sorbet (0.5.11444)
77
- sorbet-static (= 0.5.11444)
76
+ sorbet (0.5.11475)
77
+ sorbet-static (= 0.5.11475)
78
78
  sorbet-result (1.1.0)
79
79
  sorbet-runtime (~> 0.5)
80
- sorbet-runtime (0.5.11444)
81
- sorbet-static (0.5.11444-universal-darwin)
82
- sorbet-static (0.5.11444-x86_64-linux)
83
- sorbet-static-and-runtime (0.5.11444)
84
- sorbet (= 0.5.11444)
85
- sorbet-runtime (= 0.5.11444)
80
+ sorbet-runtime (0.5.11475)
81
+ sorbet-static (0.5.11475-universal-darwin)
82
+ sorbet-static (0.5.11475-x86_64-linux)
83
+ sorbet-static-and-runtime (0.5.11475)
84
+ sorbet (= 0.5.11475)
85
+ sorbet-runtime (= 0.5.11475)
86
86
  sorbet-struct-comparable (1.3.0)
87
87
  sorbet-runtime (>= 0.5)
88
- spoom (1.3.2)
88
+ spoom (1.3.3)
89
89
  erubi (>= 1.10.0)
90
- prism (>= 0.19.0)
90
+ prism (>= 0.28.0)
91
91
  sorbet-static-and-runtime (>= 0.5.10187)
92
92
  thor (>= 0.19.2)
93
- standard (1.39.0)
93
+ standard (1.39.1)
94
94
  language_server-protocol (~> 3.17.0.2)
95
95
  lint_roller (~> 1.0)
96
96
  rubocop (~> 1.64.0)
@@ -107,7 +107,7 @@ GEM
107
107
  rubocop-sorbet (~> 0.7.0)
108
108
  stringio (3.1.1)
109
109
  strscan (3.1.0)
110
- tapioca (0.14.4)
110
+ tapioca (0.15.0)
111
111
  bundler (>= 2.2.25)
112
112
  netrc (>= 0.11.0)
113
113
  parallel (>= 1.21.0)
@@ -119,9 +119,9 @@ GEM
119
119
  thor (1.3.1)
120
120
  unicode-display_width (2.5.0)
121
121
  yard (0.9.36)
122
- yard-sorbet (0.8.1)
123
- sorbet-runtime (>= 0.5)
124
- yard (>= 0.9)
122
+ yard-sorbet (0.9.0)
123
+ sorbet-runtime
124
+ yard
125
125
  zeitwerk (2.6.16)
126
126
 
127
127
  PLATFORMS
@@ -145,4 +145,4 @@ DEPENDENCIES
145
145
  tapioca
146
146
 
147
147
  BUNDLED WITH
148
- 2.5.9
148
+ 2.5.15
@@ -4,44 +4,21 @@
4
4
  # This is a simplified version of ActiveSupport's Key Hash extension
5
5
  # https://github.com/rails/rails/blob/main/activesupport/lib/active_support/core_ext/hash/keys.rb
6
6
  class HashTransformer
7
- extend T::Sig
7
+ class << self
8
+ extend T::Sig
8
9
 
9
- sig { params(should_serialize_values: T::Boolean).void }
10
- def initialize(should_serialize_values: false)
11
- @should_serialize_values = should_serialize_values
12
- end
13
-
14
- sig { params(hash: T::Hash[T.untyped, T.untyped]).returns(T::Hash[Symbol, T.untyped]) }
15
- def deep_symbolize_keys(hash)
16
- hash.each_with_object({}) do |(key, value), result|
17
- result[key.to_sym] = transform_value(value, hash_transformation_method: :deep_symbolize_keys)
18
- end
19
- end
20
-
21
- sig { params(hash: T::Hash[T.untyped, T.untyped]).returns(T::Hash[String, T.untyped]) }
22
- def deep_stringify_keys(hash)
23
- hash.each_with_object({}) do |(key, value), result|
24
- result[key.to_s] = transform_value(value, hash_transformation_method: :deep_stringify_keys)
10
+ sig { params(hash: T::Hash[T.untyped, T.untyped]).returns(T::Hash[Symbol, T.untyped]) }
11
+ def symbolize_keys(hash)
12
+ hash.each_with_object({}) do |(key, value), result|
13
+ result[key.to_sym] = value
14
+ end
25
15
  end
26
- end
27
-
28
- private
29
-
30
- sig { returns(T::Boolean) }
31
- attr_reader :should_serialize_values
32
16
 
33
- sig { params(value: T.untyped, hash_transformation_method: Symbol).returns(T.untyped) }
34
- def transform_value(value, hash_transformation_method:)
35
- if value.is_a?(Hash)
36
- send(hash_transformation_method, value)
37
- elsif value.is_a?(Array)
38
- value.map { |inner_val| transform_value(inner_val, hash_transformation_method: hash_transformation_method) }
39
- elsif value.is_a?(T::Struct) && should_serialize_values
40
- deep_symbolize_keys(value.serialize)
41
- elsif value.respond_to?(:serialize) && should_serialize_values
42
- value.serialize
43
- else
44
- value
17
+ sig { params(hash: T::Hash[T.untyped, T.untyped]).returns(T::Hash[T.untyped, T.untyped]) }
18
+ def serialize_values(hash)
19
+ hash.each_with_object({}) do |(key, value), result|
20
+ result[key] = SerializeValue.serialize(value)
21
+ end
45
22
  end
46
23
  end
47
24
  end
@@ -0,0 +1,20 @@
1
+ # typed: strict
2
+
3
+ class SerializeValue
4
+ extend T::Sig
5
+
6
+ sig { params(value: T.untyped).returns(T.untyped) }
7
+ def self.serialize(value)
8
+ if value.is_a?(Hash)
9
+ HashTransformer.serialize_values(value)
10
+ elsif value.is_a?(Array)
11
+ value.map { |item| serialize(item) }
12
+ elsif value.is_a?(T::Struct)
13
+ value.serialize_to(:hash).payload_or(value)
14
+ elsif value.respond_to?(:serialize)
15
+ value.serialize
16
+ else
17
+ value
18
+ end
19
+ end
20
+ end
@@ -1,5 +1,5 @@
1
1
  # typed: strict
2
2
 
3
3
  module SorbetSchema
4
- VERSION = "0.6.0"
4
+ VERSION = "0.7.1"
5
5
  end
data/lib/sorbet-schema.rb CHANGED
@@ -16,10 +16,11 @@ loader.inflector.inflect(
16
16
  )
17
17
  loader.setup
18
18
 
19
- # We don't want to place this in the `Typed` module.
19
+ # We don't want to place these in the `Typed` module.
20
20
  # `sorbet-schema` is a directory that is not autoloaded
21
21
  # but contains extensions, so we need to manually require it.
22
22
  require_relative "sorbet-schema/hash_transformer"
23
+ require_relative "sorbet-schema/serialize_value"
23
24
 
24
25
  # We want to add a default `schema` method to structs
25
26
  # that will guarentee a schema can be created for use
@@ -2,6 +2,13 @@
2
2
 
3
3
  module Typed
4
4
  module Coercion
5
- class CoercionNotSupportedError < CoercionError; end
5
+ class CoercionNotSupportedError < CoercionError
6
+ extend T::Sig
7
+
8
+ sig { params(type: T::Types::Base).void }
9
+ def initialize(type:)
10
+ super("Coercer not found for type #{type}.")
11
+ end
12
+ end
6
13
  end
7
14
  end
@@ -11,11 +11,11 @@ module Typed
11
11
 
12
12
  sig { type_parameters(:U).params(type: T::Types::Base, value: Value).returns(Result[Value, CoercionError]) }
13
13
  def self.coerce(type:, value:)
14
- coercer = CoercerRegistry.instance.select_coercer_by(type: type)
14
+ coercer = CoercerRegistry.instance.select_coercer_by(type:)
15
15
 
16
- return Failure.new(CoercionNotSupportedError.new) unless coercer
16
+ return Failure.new(CoercionNotSupportedError.new(type:)) unless coercer
17
17
 
18
- coercer.new.coerce(type: type, value: value)
18
+ coercer.new.coerce(type:, value:)
19
19
  end
20
20
  end
21
21
  end
@@ -15,14 +15,14 @@ module Typed
15
15
 
16
16
  sig { override.params(source: Input).returns(Result[T::Struct, DeserializeError]) }
17
17
  def deserialize(source)
18
- deserialize_from_creation_params(HashTransformer.new(should_serialize_values: should_serialize_values).deep_symbolize_keys(source))
18
+ deserialize_from_creation_params(HashTransformer.symbolize_keys(source))
19
19
  end
20
20
 
21
21
  sig { override.params(struct: T::Struct).returns(Result[Output, SerializeError]) }
22
22
  def serialize(struct)
23
23
  return Failure.new(SerializeError.new("'#{struct.class}' cannot be serialized to target type of '#{schema.target}'.")) if struct.class != schema.target
24
24
 
25
- Success.new(serialize_from_struct(struct: struct, should_serialize_values: should_serialize_values))
25
+ Success.new(serialize_from_struct(struct:, should_serialize_values:))
26
26
  end
27
27
 
28
28
  private
@@ -24,7 +24,7 @@ module Typed
24
24
  def serialize(struct)
25
25
  return Failure.new(SerializeError.new("'#{struct.class}' cannot be serialized to target type of '#{schema.target}'.")) if struct.class != schema.target
26
26
 
27
- Success.new(JSON.generate(serialize_from_struct(struct: struct, should_serialize_values: true)))
27
+ Success.new(JSON.generate(serialize_from_struct(struct:, should_serialize_values: true)))
28
28
  end
29
29
  end
30
30
  end
@@ -82,7 +82,11 @@ module Typed
82
82
  def serialize_from_struct(struct:, should_serialize_values: false)
83
83
  hsh = schema.fields.each_with_object({}) { |field, hsh| hsh[field.name] = field.serialize(struct.send(field.name)) }.compact
84
84
 
85
- HashTransformer.new(should_serialize_values: should_serialize_values).deep_symbolize_keys(hsh)
85
+ if should_serialize_values
86
+ hsh = HashTransformer.serialize_values(hsh)
87
+ end
88
+
89
+ hsh
86
90
  end
87
91
  end
88
92
  end
@@ -7,25 +7,25 @@
7
7
 
8
8
  # source://minitest-focus//lib/minitest/focus.rb#3
9
9
  class Minitest::Test < ::Minitest::Runnable
10
- # source://minitest/5.23.1/lib/minitest/test.rb#191
10
+ # source://minitest/5.24.1/lib/minitest/test.rb#191
11
11
  def capture_exceptions; end
12
12
 
13
- # source://minitest/5.23.1/lib/minitest/test.rb#15
13
+ # source://minitest/5.24.1/lib/minitest/test.rb#15
14
14
  def class_name; end
15
15
 
16
- # source://minitest/5.23.1/lib/minitest/test.rb#208
16
+ # source://minitest/5.24.1/lib/minitest/test.rb#208
17
17
  def neuter_exception(e); end
18
18
 
19
- # source://minitest/5.23.1/lib/minitest/test.rb#219
19
+ # source://minitest/5.24.1/lib/minitest/test.rb#219
20
20
  def new_exception(klass, msg, bt, kill = T.unsafe(nil)); end
21
21
 
22
- # source://minitest/5.23.1/lib/minitest/test.rb#87
22
+ # source://minitest/5.24.1/lib/minitest/test.rb#87
23
23
  def run; end
24
24
 
25
- # source://minitest/5.23.1/lib/minitest/test.rb#201
25
+ # source://minitest/5.24.1/lib/minitest/test.rb#201
26
26
  def sanitize_exception(e); end
27
27
 
28
- # source://minitest/5.23.1/lib/minitest/test.rb#233
28
+ # source://minitest/5.24.1/lib/minitest/test.rb#233
29
29
  def with_info_handler(&block); end
30
30
 
31
31
  class << self
@@ -59,22 +59,22 @@ class Minitest::Test < ::Minitest::Runnable
59
59
  # source://minitest-focus//lib/minitest/focus.rb#40
60
60
  def focus(name = T.unsafe(nil)); end
61
61
 
62
- # source://minitest/5.23.1/lib/minitest/test.rb#35
62
+ # source://minitest/5.24.1/lib/minitest/test.rb#35
63
63
  def i_suck_and_my_tests_are_order_dependent!; end
64
64
 
65
- # source://minitest/5.23.1/lib/minitest/test.rb#26
65
+ # source://minitest/5.24.1/lib/minitest/test.rb#26
66
66
  def io_lock; end
67
67
 
68
- # source://minitest/5.23.1/lib/minitest/test.rb#26
68
+ # source://minitest/5.24.1/lib/minitest/test.rb#26
69
69
  def io_lock=(_arg0); end
70
70
 
71
- # source://minitest/5.23.1/lib/minitest/test.rb#48
71
+ # source://minitest/5.24.1/lib/minitest/test.rb#48
72
72
  def make_my_diffs_pretty!; end
73
73
 
74
- # source://minitest/5.23.1/lib/minitest/test.rb#60
74
+ # source://minitest/5.24.1/lib/minitest/test.rb#60
75
75
  def parallelize_me!; end
76
76
 
77
- # source://minitest/5.23.1/lib/minitest/test.rb#70
77
+ # source://minitest/5.24.1/lib/minitest/test.rb#70
78
78
  def runnable_methods; end
79
79
 
80
80
  # Sets a one-off method_added callback to set focus on the method
@@ -8,85 +8,85 @@
8
8
  # source://minitest-reporters//lib/minitest/reporters.rb#3
9
9
  module Minitest
10
10
  class << self
11
- # source://minitest/5.24.0/lib/minitest.rb#323
11
+ # source://minitest/5.24.1/lib/minitest.rb#323
12
12
  def __run(reporter, options); end
13
13
 
14
- # source://minitest/5.24.0/lib/minitest.rb#97
14
+ # source://minitest/5.24.1/lib/minitest.rb#97
15
15
  def after_run(&block); end
16
16
 
17
- # source://minitest/5.24.0/lib/minitest.rb#19
17
+ # source://minitest/5.24.1/lib/minitest.rb#19
18
18
  def allow_fork; end
19
19
 
20
- # source://minitest/5.24.0/lib/minitest.rb#19
20
+ # source://minitest/5.24.1/lib/minitest.rb#19
21
21
  def allow_fork=(_arg0); end
22
22
 
23
- # source://minitest/5.24.0/lib/minitest.rb#69
23
+ # source://minitest/5.24.1/lib/minitest.rb#69
24
24
  def autorun; end
25
25
 
26
- # source://minitest/5.24.0/lib/minitest.rb#19
26
+ # source://minitest/5.24.1/lib/minitest.rb#19
27
27
  def backtrace_filter; end
28
28
 
29
- # source://minitest/5.24.0/lib/minitest.rb#19
29
+ # source://minitest/5.24.1/lib/minitest.rb#19
30
30
  def backtrace_filter=(_arg0); end
31
31
 
32
- # source://minitest/5.24.0/lib/minitest.rb#18
32
+ # source://minitest/5.24.1/lib/minitest.rb#18
33
33
  def cattr_accessor(name); end
34
34
 
35
- # source://minitest/5.24.0/lib/minitest.rb#1208
35
+ # source://minitest/5.24.1/lib/minitest.rb#1208
36
36
  def clock_time; end
37
37
 
38
- # source://minitest/5.24.0/lib/minitest.rb#303
38
+ # source://minitest/5.24.1/lib/minitest.rb#303
39
39
  def empty_run!(options); end
40
40
 
41
- # source://minitest/5.24.0/lib/minitest.rb#19
41
+ # source://minitest/5.24.1/lib/minitest.rb#19
42
42
  def extensions; end
43
43
 
44
- # source://minitest/5.24.0/lib/minitest.rb#19
44
+ # source://minitest/5.24.1/lib/minitest.rb#19
45
45
  def extensions=(_arg0); end
46
46
 
47
- # source://minitest/5.24.0/lib/minitest.rb#336
47
+ # source://minitest/5.24.1/lib/minitest.rb#336
48
48
  def filter_backtrace(bt); end
49
49
 
50
- # source://minitest/5.24.0/lib/minitest.rb#19
50
+ # source://minitest/5.24.1/lib/minitest.rb#19
51
51
  def info_signal; end
52
52
 
53
- # source://minitest/5.24.0/lib/minitest.rb#19
53
+ # source://minitest/5.24.1/lib/minitest.rb#19
54
54
  def info_signal=(_arg0); end
55
55
 
56
- # source://minitest/5.24.0/lib/minitest.rb#125
56
+ # source://minitest/5.24.1/lib/minitest.rb#125
57
57
  def init_plugins(options); end
58
58
 
59
- # source://minitest/5.24.0/lib/minitest.rb#109
59
+ # source://minitest/5.24.1/lib/minitest.rb#109
60
60
  def load_plugins; end
61
61
 
62
- # source://minitest/5.24.0/lib/minitest.rb#19
62
+ # source://minitest/5.24.1/lib/minitest.rb#19
63
63
  def parallel_executor; end
64
64
 
65
- # source://minitest/5.24.0/lib/minitest.rb#19
65
+ # source://minitest/5.24.1/lib/minitest.rb#19
66
66
  def parallel_executor=(_arg0); end
67
67
 
68
- # source://minitest/5.24.0/lib/minitest.rb#143
68
+ # source://minitest/5.24.1/lib/minitest.rb#143
69
69
  def process_args(args = T.unsafe(nil)); end
70
70
 
71
- # source://minitest/5.24.0/lib/minitest.rb#104
71
+ # source://minitest/5.24.1/lib/minitest.rb#104
72
72
  def register_plugin(name_or_mod); end
73
73
 
74
- # source://minitest/5.24.0/lib/minitest.rb#19
74
+ # source://minitest/5.24.1/lib/minitest.rb#19
75
75
  def reporter; end
76
76
 
77
- # source://minitest/5.24.0/lib/minitest.rb#19
77
+ # source://minitest/5.24.1/lib/minitest.rb#19
78
78
  def reporter=(_arg0); end
79
79
 
80
- # source://minitest/5.24.0/lib/minitest.rb#269
80
+ # source://minitest/5.24.1/lib/minitest.rb#269
81
81
  def run(args = T.unsafe(nil)); end
82
82
 
83
- # source://minitest/5.24.0/lib/minitest.rb#1199
83
+ # source://minitest/5.24.1/lib/minitest.rb#1199
84
84
  def run_one_method(klass, method_name); end
85
85
 
86
- # source://minitest/5.24.0/lib/minitest.rb#19
86
+ # source://minitest/5.24.1/lib/minitest.rb#19
87
87
  def seed; end
88
88
 
89
- # source://minitest/5.24.0/lib/minitest.rb#19
89
+ # source://minitest/5.24.1/lib/minitest.rb#19
90
90
  def seed=(_arg0); end
91
91
  end
92
92
  end