sorbet-runtime 0.5.5651 → 0.5.5657
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/types/props/decorator.rb +11 -23
- data/lib/types/props/private/serde_transform.rb +32 -0
- data/lib/types/props/type_validation.rb +9 -0
- 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: 04dbb8ac655032897af8b72e52e41e60bbb08d471e1bb3257422b0f765eca12e
|
4
|
+
data.tar.gz: 7e661cde9f4fefc762c72875b320c54da69971f96a0906137ed1c398aea4c9bd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4c7c50b7f66658e4e427629bcc881ddb9c7cf987c00b4a06e91c871c7e4105354811a4f6c40d72649a605b178ed8b7896f539f7329c30e6860ef8378964ce48b
|
7
|
+
data.tar.gz: 07d5d1764063df2a278a0eb16363756cf33d12afb19ea10727a77600787238b3219661b1c0113d4b3a90f970c245da3953df21254b2eccd494f3da2f8c8390f7
|
@@ -220,12 +220,6 @@ class T::Props::Decorator
|
|
220
220
|
raise ArgumentError.new("At least one invalid prop arg supplied in #{self}: #{rules.keys.inspect}")
|
221
221
|
end
|
222
222
|
|
223
|
-
if (array = rules[:array])
|
224
|
-
unless array.is_a?(Module)
|
225
|
-
raise ArgumentError.new("Bad class as subtype in prop #{@class.name}.#{name}: #{array.inspect}")
|
226
|
-
end
|
227
|
-
end
|
228
|
-
|
229
223
|
if !(rules[:clobber_existing_method!]) && !(rules[:without_accessors])
|
230
224
|
if BANNED_METHOD_NAMES.include?(name.to_sym)
|
231
225
|
raise ArgumentError.new(
|
@@ -350,7 +344,7 @@ class T::Props::Decorator
|
|
350
344
|
if !cls.is_a?(Module)
|
351
345
|
cls = convert_type_to_class(cls)
|
352
346
|
end
|
353
|
-
type_object = smart_coerce(type,
|
347
|
+
type_object = smart_coerce(type, enum: rules[:enum])
|
354
348
|
|
355
349
|
prop_validate_definition!(name, cls, rules, type_object)
|
356
350
|
|
@@ -441,27 +435,21 @@ class T::Props::Decorator
|
|
441
435
|
end
|
442
436
|
|
443
437
|
sig do
|
444
|
-
params(type: PropTypeOrClass,
|
438
|
+
params(type: PropTypeOrClass, enum: T.untyped)
|
445
439
|
.returns(T::Types::Base)
|
446
440
|
end
|
447
|
-
private def smart_coerce(type,
|
441
|
+
private def smart_coerce(type, enum:)
|
448
442
|
# Backwards compatibility for pre-T::Types style
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
T
|
456
|
-
end
|
457
|
-
elsif !enum.nil?
|
458
|
-
if T::Utils.unwrap_nilable(type)
|
459
|
-
T.nilable(T.enum(enum))
|
443
|
+
type = T::Utils.coerce(type)
|
444
|
+
if enum.nil?
|
445
|
+
type
|
446
|
+
else
|
447
|
+
nonnil_type = T::Utils.unwrap_nilable(type)
|
448
|
+
if nonnil_type
|
449
|
+
T.nilable(T.all(nonnil_type, T.enum(enum)))
|
460
450
|
else
|
461
|
-
T.enum(enum)
|
451
|
+
T.all(type, T.enum(enum))
|
462
452
|
end
|
463
|
-
else
|
464
|
-
T::Utils.coerce(type)
|
465
453
|
end
|
466
454
|
end
|
467
455
|
|
@@ -99,6 +99,38 @@ module T::Props
|
|
99
99
|
"T::Props::Utils.deep_clone_object(#{varname})"
|
100
100
|
end
|
101
101
|
end
|
102
|
+
when T::Types::Intersection
|
103
|
+
dynamic_fallback = "T::Props::Utils.deep_clone_object(#{varname})"
|
104
|
+
|
105
|
+
# Transformations for any members of the intersection type where we
|
106
|
+
# know what we need to do and did not have to fall back to the
|
107
|
+
# dynamic deep clone method.
|
108
|
+
#
|
109
|
+
# NB: This deliberately does include `nil`, which means we know we
|
110
|
+
# don't need to do any transforming.
|
111
|
+
inner_known = type.types
|
112
|
+
.map {|t| generate(t, mode, varname)}
|
113
|
+
.reject {|t| t == dynamic_fallback}
|
114
|
+
.uniq
|
115
|
+
|
116
|
+
if inner_known.size != 1
|
117
|
+
# If there were no cases where we could tell what we need to do,
|
118
|
+
# e.g. if this is `T.all(SomethingWeird, WhoKnows)`, just use the
|
119
|
+
# dynamic fallback.
|
120
|
+
#
|
121
|
+
# If there were multiple cases and they weren't consistent, e.g.
|
122
|
+
# if this is `T.all(String, T::Array[Integer])`, the type is probably
|
123
|
+
# bogus/uninhabited, but use the dynamic fallback because we still
|
124
|
+
# don't have a better option, and this isn't the place to raise that
|
125
|
+
# error.
|
126
|
+
dynamic_fallback
|
127
|
+
else
|
128
|
+
# This is probably something like `T.all(String, SomeMarker)` or
|
129
|
+
# `T.all(SomeEnum, T.enum(SomeEnum::FOO))` and we should treat it
|
130
|
+
# like String or SomeEnum even if we don't know what to do with
|
131
|
+
# the rest of the type.
|
132
|
+
inner_known.first
|
133
|
+
end
|
102
134
|
when T::Types::Enum
|
103
135
|
generate(T::Utils.lift_enum(type), mode, varname)
|
104
136
|
else
|
@@ -63,7 +63,16 @@ module T::Props::TypeValidation
|
|
63
63
|
when T::Types::FixedHash
|
64
64
|
type.types.values.map {|subtype| find_invalid_subtype(subtype)}.compact.first
|
65
65
|
when T::Types::Union, T::Types::FixedArray
|
66
|
+
# `T.any` is valid if all of the members are valid
|
66
67
|
type.types.map {|subtype| find_invalid_subtype(subtype)}.compact.first
|
68
|
+
when T::Types::Intersection
|
69
|
+
# `T.all` is valid if at least one of the members is valid
|
70
|
+
invalid = type.types.map {|subtype| find_invalid_subtype(subtype)}.compact
|
71
|
+
if invalid.length == type.types.length
|
72
|
+
invalid.first
|
73
|
+
else
|
74
|
+
nil
|
75
|
+
end
|
67
76
|
when T::Types::Enum, T::Types::ClassOf
|
68
77
|
nil
|
69
78
|
when T::Private::Types::TypeAlias
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sorbet-runtime
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.5657
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stripe
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-05-
|
11
|
+
date: 2020-05-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest
|