sorbet-schema 0.5.0 → 0.5.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c06e03c3878ac6b3cf04305124e1d3786de57f0543ee320181565a8b59f8c4b3
4
- data.tar.gz: 97d11102e65875b5f77f06095fdacf1dea0fabdd1fd1a91b5428a509dd6bac4b
3
+ metadata.gz: 32a23b4d9a5e1eda6fcf49b64428f55fbf1d89f63754de35bf2e0e3a875e018c
4
+ data.tar.gz: e76f273b8e566f78e6c18effa1699e3f6afa17311abee06a2183778e7a97f93a
5
5
  SHA512:
6
- metadata.gz: 84e7f4308162784ee84b063ff743293cd6c72487479f23de3cf1ed31089f13ff8a148c4aad85854394343aa97eafbbab15551d54fd17ce8e390db343db5083c9
7
- data.tar.gz: 37301dfecd29623d2f5be76220e70d0aa1a650dc2c792c3e01e15b4bce17abb2bf468f04dbfd5026686c11aa594590a91b369b49ef2a1de5393ff77af07d5d8b
6
+ metadata.gz: 5e7dcb508366dcda8311bf089ae6877c8ff5ba8fc41e0bec9adcd18ca8f3b3723693cd5139a1ee34d46dfcf0643d511edc04d689a93715e72aa33a2f764454e2
7
+ data.tar.gz: bf2c62a198b37caae70736bd1aa954476ef2697c44aa793381f91787b4ad6b78bad0e731a69c3dddb4c7398a3a07092cdebf779d95e27be1fbb68d43bf74958f
data/CHANGELOG.md CHANGED
@@ -4,6 +4,13 @@ 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.5.1](https://github.com/maxveldink/sorbet-schema/compare/v0.5.0...v0.5.1) (2024-06-26)
8
+
9
+
10
+ ### Features
11
+
12
+ * support nested structs ([#102](https://github.com/maxveldink/sorbet-schema/issues/102)) ([08428e1](https://github.com/maxveldink/sorbet-schema/commit/08428e18afdbb4121ef2f290e8a85651b2e13edf))
13
+
7
14
  ## [0.5.0](https://github.com/maxveldink/sorbet-schema/compare/v0.4.2...v0.5.0) (2024-04-19)
8
15
 
9
16
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- sorbet-schema (0.5.0)
4
+ sorbet-schema (0.5.1)
5
5
  sorbet-result (~> 1.1)
6
6
  sorbet-runtime (~> 0.5)
7
7
  sorbet-struct-comparable (~> 1.3)
@@ -13,32 +13,32 @@ GEM
13
13
  ansi (1.5.0)
14
14
  ast (2.4.2)
15
15
  bigdecimal (3.1.8)
16
- builder (3.2.4)
16
+ builder (3.3.0)
17
17
  debug (1.9.2)
18
18
  irb (~> 1.10)
19
19
  reline (>= 0.3.8)
20
- erubi (1.12.0)
20
+ erubi (1.13.0)
21
21
  io-console (0.7.2)
22
- irb (1.13.1)
22
+ irb (1.13.2)
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.23.1)
28
+ minitest (5.24.0)
29
29
  minitest-focus (1.4.0)
30
30
  minitest (>= 4, < 6)
31
- minitest-reporters (1.6.1)
31
+ minitest-reporters (1.7.1)
32
32
  ansi
33
33
  builder
34
34
  minitest (>= 5.0)
35
35
  ruby-progressbar
36
36
  netrc (0.11.0)
37
- parallel (1.24.0)
38
- parser (3.3.1.0)
37
+ parallel (1.25.1)
38
+ parser (3.3.3.0)
39
39
  ast (~> 2.4.1)
40
40
  racc
41
- prism (0.29.0)
41
+ prism (0.30.0)
42
42
  psych (5.1.2)
43
43
  stringio
44
44
  racc (1.8.0)
@@ -50,11 +50,11 @@ GEM
50
50
  rdoc (6.7.0)
51
51
  psych (>= 4.0.0)
52
52
  regexp_parser (2.9.2)
53
- reline (0.5.7)
53
+ reline (0.5.9)
54
54
  io-console (~> 0.5)
55
- rexml (3.2.8)
56
- strscan (>= 3.0.9)
57
- rubocop (1.63.5)
55
+ rexml (3.3.0)
56
+ strscan
57
+ rubocop (1.64.1)
58
58
  json (~> 2.3)
59
59
  language_server-protocol (>= 3.17.0)
60
60
  parallel (~> 1.10)
@@ -67,22 +67,22 @@ GEM
67
67
  unicode-display_width (>= 2.4.0, < 3.0)
68
68
  rubocop-ast (1.31.3)
69
69
  parser (>= 3.3.1.0)
70
- rubocop-performance (1.21.0)
70
+ rubocop-performance (1.21.1)
71
71
  rubocop (>= 1.48.1, < 2.0)
72
72
  rubocop-ast (>= 1.31.1, < 2.0)
73
73
  rubocop-sorbet (0.7.8)
74
74
  rubocop (>= 0.90.0)
75
75
  ruby-progressbar (1.13.0)
76
- sorbet (0.5.11391)
77
- sorbet-static (= 0.5.11391)
76
+ sorbet (0.5.11444)
77
+ sorbet-static (= 0.5.11444)
78
78
  sorbet-result (1.1.0)
79
79
  sorbet-runtime (~> 0.5)
80
- sorbet-runtime (0.5.11391)
81
- sorbet-static (0.5.11391-universal-darwin)
82
- sorbet-static (0.5.11391-x86_64-linux)
83
- sorbet-static-and-runtime (0.5.11391)
84
- sorbet (= 0.5.11391)
85
- sorbet-runtime (= 0.5.11391)
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)
86
86
  sorbet-struct-comparable (1.3.0)
87
87
  sorbet-runtime (>= 0.5)
88
88
  spoom (1.3.2)
@@ -90,10 +90,10 @@ GEM
90
90
  prism (>= 0.19.0)
91
91
  sorbet-static-and-runtime (>= 0.5.10187)
92
92
  thor (>= 0.19.2)
93
- standard (1.36.0)
93
+ standard (1.39.0)
94
94
  language_server-protocol (~> 3.17.0.2)
95
95
  lint_roller (~> 1.0)
96
- rubocop (~> 1.63.0)
96
+ rubocop (~> 1.64.0)
97
97
  standard-custom (~> 1.0.0)
98
98
  standard-performance (~> 1.4)
99
99
  standard-custom (1.0.2)
@@ -105,9 +105,9 @@ GEM
105
105
  standard-sorbet (0.0.2)
106
106
  lint_roller (~> 1.1)
107
107
  rubocop-sorbet (~> 0.7.0)
108
- stringio (3.1.0)
108
+ stringio (3.1.1)
109
109
  strscan (3.1.0)
110
- tapioca (0.14.2)
110
+ tapioca (0.14.4)
111
111
  bundler (>= 2.2.25)
112
112
  netrc (>= 0.11.0)
113
113
  parallel (>= 1.21.0)
@@ -122,7 +122,7 @@ GEM
122
122
  yard-sorbet (0.8.1)
123
123
  sorbet-runtime (>= 0.5)
124
124
  yard (>= 0.9)
125
- zeitwerk (2.6.15)
125
+ zeitwerk (2.6.16)
126
126
 
127
127
  PLATFORMS
128
128
  arm64-darwin-22
@@ -1,5 +1,5 @@
1
1
  # typed: strict
2
2
 
3
3
  module SorbetSchema
4
- VERSION = "0.5.0"
4
+ VERSION = "0.5.1"
5
5
  end
@@ -21,7 +21,41 @@ module Typed
21
21
 
22
22
  return Failure.new(CoercionError.new("Value of type '#{value.class}' cannot be coerced to #{type} Struct.")) unless value.is_a?(Hash)
23
23
 
24
- Success.new(T.cast(type, T::Types::Simple).raw_type.from_hash!(HashTransformer.new.deep_stringify_keys(value)))
24
+ values = {}
25
+
26
+ type = T.cast(type, T::Types::Simple)
27
+
28
+ type.raw_type.props.each do |name, prop|
29
+ attribute_type = prop[:type_object]
30
+ value = HashTransformer.new.deep_symbolize_keys(value)
31
+
32
+ if value[name].nil?
33
+ # if the value is nil but the type is nilable, no need to coerce
34
+ next if attribute_type.respond_to?(:valid?) && attribute_type.valid?(value[name])
35
+
36
+ return Typed::Failure.new(CoercionError.new("#{name} is required but nil given"))
37
+ end
38
+
39
+ # now that we've done the nil check, we can unwrap the nilable type to get the raw type
40
+ simple_attribute_type = attribute_type.respond_to?(:unwrap_nilable) ? attribute_type.unwrap_nilable : attribute_type
41
+
42
+ # if the prop is a struct, we need to recursively coerce it
43
+ if simple_attribute_type.respond_to?(:raw_type) && simple_attribute_type.raw_type <= T::Struct
44
+ Typed::HashSerializer
45
+ .new(schema: simple_attribute_type.raw_type.schema)
46
+ .deserialize(value[name])
47
+ .and_then { |struct| Typed::Success.new(values[name] = struct) }
48
+ .on_error { |error| return Typed::Failure.new(CoercionError.new("Nested hash for #{type} could not be coerced to #{name}, error: #{error}")) }
49
+ else
50
+ value = HashTransformer.new.deep_symbolize_keys(value)
51
+
52
+ Coercion
53
+ .coerce(type: attribute_type, value: value[name])
54
+ .and_then { |coerced_value| Typed::Success.new(values[name] = coerced_value) }
55
+ end
56
+ end
57
+
58
+ Success.new(type.raw_type.new(values))
25
59
  rescue ArgumentError, RuntimeError
26
60
  Failure.new(CoercionError.new("Given hash could not be coerced to #{type}."))
27
61
  end
@@ -8,7 +8,7 @@
8
8
  # If the Builder::XChar module is not currently defined, fail on any
9
9
  # name clashes in standard library classes.
10
10
  #
11
- # source://builder//lib/builder/blankslate.rb#17
11
+ # source://builder//lib/builder/xmlbase.rb#4
12
12
  module Builder
13
13
  class << self
14
14
  # source://builder//lib/builder/xchar.rb#13
@@ -16,12 +16,9 @@ module Builder
16
16
  end
17
17
  end
18
18
 
19
- # source://builder//lib/builder/blankslate.rb#19
20
- Builder::BlankSlate = BasicObject
21
-
22
19
  # Generic error for builder
23
20
  #
24
- # source://builder//lib/builder/xmlbase.rb#9
21
+ # source://builder//lib/builder/xmlbase.rb#7
25
22
  class Builder::IllegalBlockError < ::RuntimeError; end
26
23
 
27
24
  # source://builder//lib/builder/xchar.rb#33
@@ -86,7 +83,7 @@ Builder::XChar::XML_PREDEFINED = T.let(T.unsafe(nil), Regexp)
86
83
  # XmlBase is a base class for building XML builders. See
87
84
  # Builder::XmlMarkup and Builder::XmlEvents for examples.
88
85
  #
89
- # source://builder//lib/builder/xmlbase.rb#13
86
+ # source://builder//lib/builder/xmlbase.rb#11
90
87
  class Builder::XmlBase < ::BasicObject
91
88
  # Create an XML markup builder.
92
89
  #
@@ -101,7 +98,7 @@ class Builder::XmlBase < ::BasicObject
101
98
  #
102
99
  # @return [XmlBase] a new instance of XmlBase
103
100
  #
104
- # source://builder//lib/builder/xmlbase.rb#29
101
+ # source://builder//lib/builder/xmlbase.rb#27
105
102
  def initialize(indent = T.unsafe(nil), initial = T.unsafe(nil), encoding = T.unsafe(nil)); end
106
103
 
107
104
  # Append text to the output target without escaping any markup.
@@ -118,19 +115,19 @@ class Builder::XmlBase < ::BasicObject
118
115
  # method/operation builders can use other builders as their
119
116
  # targets.
120
117
  #
121
- # source://builder//lib/builder/xmlbase.rb#118
118
+ # source://builder//lib/builder/xmlbase.rb#116
122
119
  def <<(text); end
123
120
 
124
121
  # @return [Boolean]
125
122
  #
126
- # source://builder//lib/builder/xmlbase.rb#35
123
+ # source://builder//lib/builder/xmlbase.rb#33
127
124
  def explicit_nil_handling?; end
128
125
 
129
126
  # Create XML markup based on the name of the method. This method
130
127
  # is never invoked directly, but is called for each markup method
131
128
  # in the markup block that isn't cached.
132
129
  #
133
- # source://builder//lib/builder/xmlbase.rb#92
130
+ # source://builder//lib/builder/xmlbase.rb#90
134
131
  def method_missing(sym, *args, &block); end
135
132
 
136
133
  # For some reason, nil? is sent to the XmlMarkup object. If nil?
@@ -142,14 +139,14 @@ class Builder::XmlBase < ::BasicObject
142
139
  #
143
140
  # @return [Boolean]
144
141
  #
145
- # source://builder//lib/builder/xmlbase.rb#128
142
+ # source://builder//lib/builder/xmlbase.rb#126
146
143
  def nil?; end
147
144
 
148
145
  # Create a tag named +sym+. Other than the first argument which
149
146
  # is the tag name, the arguments are the same as the tags
150
147
  # implemented via <tt>method_missing</tt>.
151
148
  #
152
- # source://builder//lib/builder/xmlbase.rb#42
149
+ # source://builder//lib/builder/xmlbase.rb#40
153
150
  def tag!(sym, *args, &block); end
154
151
 
155
152
  # Append text to the output target. Escape any markup. May be
@@ -157,24 +154,24 @@ class Builder::XmlBase < ::BasicObject
157
154
  #
158
155
  # builder.p { |b| b.br; b.text! "HI" } #=> <p><br/>HI</p>
159
156
  #
160
- # source://builder//lib/builder/xmlbase.rb#101
157
+ # source://builder//lib/builder/xmlbase.rb#99
161
158
  def text!(text); end
162
159
 
163
160
  private
164
161
 
165
- # source://builder//lib/builder/xmlbase.rb#136
162
+ # source://builder//lib/builder/xmlbase.rb#134
166
163
  def _escape(text); end
167
164
 
168
- # source://builder//lib/builder/xmlbase.rb#159
165
+ # source://builder//lib/builder/xmlbase.rb#157
169
166
  def _escape_attribute(text); end
170
167
 
171
- # source://builder//lib/builder/xmlbase.rb#169
168
+ # source://builder//lib/builder/xmlbase.rb#167
172
169
  def _indent; end
173
170
 
174
- # source://builder//lib/builder/xmlbase.rb#174
171
+ # source://builder//lib/builder/xmlbase.rb#172
175
172
  def _nested_structures(block); end
176
173
 
177
- # source://builder//lib/builder/xmlbase.rb#164
174
+ # source://builder//lib/builder/xmlbase.rb#162
178
175
  def _newline; end
179
176
 
180
177
  # If XmlBase.cache_method_calls = true, we dynamicly create the method
@@ -184,20 +181,20 @@ class Builder::XmlBase < ::BasicObject
184
181
  # method_missing is very slow, this speeds up document generation
185
182
  # significantly.
186
183
  #
187
- # source://builder//lib/builder/xmlbase.rb#187
184
+ # source://builder//lib/builder/xmlbase.rb#185
188
185
  def cache_method_call(sym); end
189
186
 
190
187
  class << self
191
188
  # Returns the value of attribute cache_method_calls.
192
189
  #
193
- # source://builder//lib/builder/xmlbase.rb#16
190
+ # source://builder//lib/builder/xmlbase.rb#14
194
191
  def cache_method_calls; end
195
192
 
196
193
  # Sets the attribute cache_method_calls
197
194
  #
198
195
  # @param value the value to set the attribute cache_method_calls to.
199
196
  #
200
- # source://builder//lib/builder/xmlbase.rb#16
197
+ # source://builder//lib/builder/xmlbase.rb#14
201
198
  def cache_method_calls=(_arg0); end
202
199
  end
203
200
  end
@@ -348,15 +345,15 @@ end
348
345
  #
349
346
  # Example:
350
347
  #
351
- # xm = Builder.new(:indent=>2)
348
+ # xm = Builder::XmlMarkup.new(:indent=>2)
352
349
  # # xm will produce nicely formatted and indented XML.
353
350
  #
354
- # xm = Builder.new(:indent=>2, :margin=>4)
351
+ # xm = Builder::XmlMarkup.new(:indent=>2, :margin=>4)
355
352
  # # xm will produce nicely formatted and indented XML with 2
356
353
  # # spaces per indent and an over all indentation level of 4.
357
354
  #
358
355
  # builder = Builder::XmlMarkup.new(:target=>$stdout, :indent=>2)
359
- # builder.name { |b| b.first("Jim"); b.last("Weirich) }
356
+ # builder.name { |b| b.first("Jim"); b.last("Weirich") }
360
357
  # # prints:
361
358
  # # <name>
362
359
  # # <first>Jim</first>
@@ -385,7 +382,7 @@ end
385
382
  #
386
383
  # xml_builder = Builder::XmlMarkup.new
387
384
  # xml_builder.div { |xml|
388
- # xml.stong("text")
385
+ # xml.strong("text")
389
386
  # }
390
387
  #
391
388
  # source://builder//lib/builder/xmlmarkup.rb#161
@@ -7,12 +7,16 @@
7
7
 
8
8
  # source://erubi//lib/erubi.rb#3
9
9
  module Erubi
10
+ private
11
+
12
+ def h(_arg0); end
13
+
10
14
  class << self
11
15
  def h(_arg0); end
12
16
  end
13
17
  end
14
18
 
15
- # source://erubi//lib/erubi.rb#54
19
+ # source://erubi//lib/erubi.rb#51
16
20
  class Erubi::Engine
17
21
  # Initialize a new Erubi::Engine. Options:
18
22
  # +:bufval+ :: The value to use for the buffer variable, as a string (default <tt>'::String.new'</tt>).
@@ -43,64 +47,64 @@ class Erubi::Engine
43
47
  #
44
48
  # @return [Engine] a new instance of Engine
45
49
  #
46
- # source://erubi//lib/erubi.rb#94
50
+ # source://erubi//lib/erubi.rb#91
47
51
  def initialize(input, properties = T.unsafe(nil)); end
48
52
 
49
53
  # The variable name used for the buffer variable.
50
54
  #
51
- # source://erubi//lib/erubi.rb#65
55
+ # source://erubi//lib/erubi.rb#62
52
56
  def bufvar; end
53
57
 
54
58
  # The filename of the template, if one was given.
55
59
  #
56
- # source://erubi//lib/erubi.rb#62
60
+ # source://erubi//lib/erubi.rb#59
57
61
  def filename; end
58
62
 
59
63
  # The frozen ruby source code generated from the template, which can be evaled.
60
64
  #
61
- # source://erubi//lib/erubi.rb#59
65
+ # source://erubi//lib/erubi.rb#56
62
66
  def src; end
63
67
 
64
68
  private
65
69
 
66
70
  # Add ruby code to the template
67
71
  #
68
- # source://erubi//lib/erubi.rb#226
72
+ # source://erubi//lib/erubi.rb#223
69
73
  def add_code(code); end
70
74
 
71
75
  # Add the given ruby expression result to the template,
72
76
  # escaping it based on the indicator given and escape flag.
73
77
  #
74
- # source://erubi//lib/erubi.rb#235
78
+ # source://erubi//lib/erubi.rb#232
75
79
  def add_expression(indicator, code); end
76
80
 
77
81
  # Add the result of Ruby expression to the template
78
82
  #
79
- # source://erubi//lib/erubi.rb#244
83
+ # source://erubi//lib/erubi.rb#241
80
84
  def add_expression_result(code); end
81
85
 
82
86
  # Add the escaped result of Ruby expression to the template
83
87
  #
84
- # source://erubi//lib/erubi.rb#249
88
+ # source://erubi//lib/erubi.rb#246
85
89
  def add_expression_result_escaped(code); end
86
90
 
87
91
  # Add the given postamble to the src. Can be overridden in subclasses
88
92
  # to make additional changes to src that depend on the current state.
89
93
  #
90
- # source://erubi//lib/erubi.rb#255
94
+ # source://erubi//lib/erubi.rb#252
91
95
  def add_postamble(postamble); end
92
96
 
93
97
  # Add raw text to the template. Modifies argument if argument is mutable as a memory optimization.
94
98
  # Must be called with a string, cannot be called with nil (Rails's subclass depends on it).
95
99
  #
96
- # source://erubi//lib/erubi.rb#213
100
+ # source://erubi//lib/erubi.rb#210
97
101
  def add_text(text); end
98
102
 
99
103
  # Raise an exception, as the base engine class does not support handling other indicators.
100
104
  #
101
105
  # @raise [ArgumentError]
102
106
  #
103
- # source://erubi//lib/erubi.rb#261
107
+ # source://erubi//lib/erubi.rb#258
104
108
  def handle(indicator, code, tailch, rspace, lspace); end
105
109
 
106
110
  # Make sure that any current expression has been terminated.
@@ -108,7 +112,7 @@ class Erubi::Engine
108
112
  # the chain_appends option is used, expressions may not be
109
113
  # terminated.
110
114
  #
111
- # source://erubi//lib/erubi.rb#289
115
+ # source://erubi//lib/erubi.rb#286
112
116
  def terminate_expression; end
113
117
 
114
118
  # Make sure the buffer variable is the target of the next append
@@ -118,13 +122,13 @@ class Erubi::Engine
118
122
  # This method should only be called if the block will result in
119
123
  # code where << will append to the bufvar.
120
124
  #
121
- # source://erubi//lib/erubi.rb#271
125
+ # source://erubi//lib/erubi.rb#268
122
126
  def with_buffer; end
123
127
  end
124
128
 
125
129
  # The default regular expression used for scanning.
126
130
  #
127
- # source://erubi//lib/erubi.rb#56
131
+ # source://erubi//lib/erubi.rb#53
128
132
  Erubi::Engine::DEFAULT_REGEXP = T.let(T.unsafe(nil), Regexp)
129
133
 
130
134
  # source://erubi//lib/erubi.rb#17