sorbet-runtime 0.5.5576 → 0.5.5579
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/lib/types/enum.rb +2 -11
- data/lib/types/props/_props.rb +1 -5
- data/lib/types/props/custom_type.rb +43 -31
- data/lib/types/props/decorator.rb +2 -5
- data/lib/types/props/private/serde_transform.rb +1 -2
- data/lib/types/props/private/setter_factory.rb +5 -12
- data/lib/types/props/type_validation.rb +1 -1
- 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: 64118c41b03c7b4d993275e0ff71f853fa8ffa2078fbaf769ca6755564fb0ef8
|
4
|
+
data.tar.gz: ae794f0928f3b8fbf95e154afccb21b3fc206a3c096eb9b9bdaa159638fe6599
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 27ebb20c813c95d0d3b4e354d72f4cae80297050fbf3697fd9fa9512fed0c9cc04f9fc7a315e25aad267c222fc2e0fc05bb2e2436877d0e0b8ad97ebe87a5a18
|
7
|
+
data.tar.gz: c0b048e1a48b5481ad65b81d1a0cdeeab956b4aa3edf61f2e7381cfc077996ce459899cc680ac1948fe68a4e892c05f8b9c7510ac3412f4cb3f9db623ef131e7
|
data/lib/types/enum.rb
CHANGED
@@ -97,17 +97,8 @@ class T::Enum
|
|
97
97
|
@mapping.include?(serialized_val)
|
98
98
|
end
|
99
99
|
|
100
|
-
|
101
|
-
## T::Props::CustomType
|
102
|
-
|
103
|
-
# Note: Failed CriticalMethodsNoRuntimeTypingTest
|
104
|
-
sig {params(value: T.untyped).returns(T::Boolean).checked(:never)}
|
105
|
-
def self.instance?(value)
|
106
|
-
value.is_a?(self)
|
107
|
-
end
|
108
|
-
|
109
100
|
# Note: Failed CriticalMethodsNoRuntimeTypingTest
|
110
|
-
sig {params(instance: T.nilable(T::Enum)).returns(SerializedVal).checked(:never)}
|
101
|
+
sig {override.params(instance: T.nilable(T::Enum)).returns(SerializedVal).checked(:never)}
|
111
102
|
def self.serialize(instance)
|
112
103
|
# This is needed otherwise if a Chalk::ODM::Document with a property of the shape
|
113
104
|
# T::Hash[T.nilable(MyEnum), Integer] and a value that looks like {nil => 0} is
|
@@ -124,7 +115,7 @@ class T::Enum
|
|
124
115
|
end
|
125
116
|
|
126
117
|
# Note: Failed CriticalMethodsNoRuntimeTypingTest
|
127
|
-
sig {params(mongo_value: SerializedVal).returns(T.attached_class).checked(:never)}
|
118
|
+
sig {override.params(mongo_value: SerializedVal).returns(T.attached_class).checked(:never)}
|
128
119
|
def self.deserialize(mongo_value)
|
129
120
|
if self == T::Enum
|
130
121
|
raise "Cannot call T::Enum.deserialize directly. You must call on a specific child class."
|
data/lib/types/props/_props.rb
CHANGED
@@ -39,7 +39,7 @@ module T::Props
|
|
39
39
|
# a document class.
|
40
40
|
#
|
41
41
|
# @param name [Symbol] The name of this property
|
42
|
-
# @param cls [Class,T::
|
42
|
+
# @param cls [Class,T::Types::Base] The type of this
|
43
43
|
# property. If the type is itself a {Document} subclass, this
|
44
44
|
# property will be recursively serialized/deserialized.
|
45
45
|
# @param rules [Hash] Options to control this property's behavior.
|
@@ -90,10 +90,6 @@ module T::Props
|
|
90
90
|
# none is provided.
|
91
91
|
# @option rules [T::Boolean] :immutable If true, this prop cannot be
|
92
92
|
# modified after an instance is created or loaded from a hash.
|
93
|
-
# @option rules [Class,T::Props::CustomType] :array If set, specifies the
|
94
|
-
# type of individual members of a prop with `type` `Array`. This
|
95
|
-
# allows for typechecking of arrays, and also for recursive
|
96
|
-
# serialization of arrays of sub-{Document}s.
|
97
93
|
# @option rules [T::Boolean] :override It is an error to redeclare a
|
98
94
|
# `prop` that has already been declared (including on a
|
99
95
|
# superclass), unless `:override` is set to `true`.
|
@@ -1,20 +1,35 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
# typed:
|
2
|
+
# typed: strict
|
3
3
|
|
4
4
|
module T::Props
|
5
5
|
module CustomType
|
6
|
+
extend T::Sig
|
7
|
+
extend T::Helpers
|
8
|
+
|
9
|
+
abstract!
|
10
|
+
|
6
11
|
include Kernel # for `is_a?`
|
7
12
|
|
8
|
-
#
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
13
|
+
# Alias for backwards compatibility
|
14
|
+
sig(:final) do
|
15
|
+
params(
|
16
|
+
value: BasicObject,
|
17
|
+
)
|
18
|
+
.returns(T::Boolean)
|
19
|
+
.checked(:never)
|
20
|
+
end
|
21
|
+
def instance?(value)
|
22
|
+
self.===(value)
|
15
23
|
end
|
16
24
|
|
17
|
-
# Alias for
|
25
|
+
# Alias for backwards compatibility
|
26
|
+
sig(:final) do
|
27
|
+
params(
|
28
|
+
value: BasicObject,
|
29
|
+
)
|
30
|
+
.returns(T::Boolean)
|
31
|
+
.checked(:never)
|
32
|
+
end
|
18
33
|
def valid?(value)
|
19
34
|
instance?(value)
|
20
35
|
end
|
@@ -24,30 +39,30 @@ module T::Props
|
|
24
39
|
#
|
25
40
|
# @param [Object] _instance
|
26
41
|
# @return An instance of one of T::Configuration.scalar_types
|
27
|
-
|
28
|
-
|
29
|
-
end
|
42
|
+
sig {abstract.params(instance: T.untyped).returns(T.untyped).checked(:never)}
|
43
|
+
def serialize(instance); end
|
30
44
|
|
31
45
|
# Given the serialized form of your type, this returns an instance
|
32
46
|
# of that custom type representing that value.
|
33
47
|
#
|
34
|
-
# @param
|
48
|
+
# @param scalar One of T::Configuration.scalar_types
|
35
49
|
# @return Object
|
36
|
-
|
37
|
-
|
38
|
-
end
|
50
|
+
sig {abstract.params(scalar: T.untyped).returns(T.untyped).checked(:never)}
|
51
|
+
def deserialize(scalar); end
|
39
52
|
|
53
|
+
sig {override.params(_base: Module).void}
|
40
54
|
def self.included(_base)
|
41
55
|
super
|
42
56
|
|
43
57
|
raise 'Please use "extend", not "include" to attach this module'
|
44
58
|
end
|
45
59
|
|
60
|
+
sig(:final) {params(val: Object).returns(T::Boolean).checked(:never)}
|
46
61
|
def self.scalar_type?(val)
|
47
62
|
# We don't need to check for val's included modules in
|
48
63
|
# T::Configuration.scalar_types, because T::Configuration.scalar_types
|
49
64
|
# are all classes.
|
50
|
-
klass = val.class
|
65
|
+
klass = T.let(val.class, T.nilable(Class))
|
51
66
|
until klass.nil?
|
52
67
|
return true if T::Configuration.scalar_types.include?(klass.to_s)
|
53
68
|
klass = klass.superclass
|
@@ -59,16 +74,8 @@ module T::Props
|
|
59
74
|
# implement set-like fields that store a unique-array, but forbid
|
60
75
|
# hashes; Custom hash types should be implemented via an emebdded
|
61
76
|
# T::Struct (or a subclass like Chalk::ODM::Document) or via T.
|
62
|
-
|
63
|
-
|
64
|
-
# Special case we allow for backwards compatibility with props formerly
|
65
|
-
# typed as "Object" or "Hash", which contain arbitrarily-nested BSON
|
66
|
-
# data (e.g. parsed API request bodies). In general, we aren't pushing
|
67
|
-
# to convert these to Chalk::ODM::BsonTypes - we'd rather delurk them -
|
68
|
-
# but this lets us convert events with these types to Proto.
|
69
|
-
return true
|
70
|
-
end
|
71
|
-
|
77
|
+
sig(:final) {params(val: Object).returns(T::Boolean).checked(:never)}
|
78
|
+
def self.valid_serialization?(val)
|
72
79
|
case val
|
73
80
|
when Array
|
74
81
|
val.each do |v|
|
@@ -81,10 +88,15 @@ module T::Props
|
|
81
88
|
end
|
82
89
|
end
|
83
90
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
91
|
+
sig(:final) do
|
92
|
+
params(instance: Object)
|
93
|
+
.returns(T.untyped)
|
94
|
+
.checked(:never)
|
95
|
+
end
|
96
|
+
def self.checked_serialize(instance)
|
97
|
+
val = T.cast(instance.class, T::Props::CustomType).serialize(instance)
|
98
|
+
unless valid_serialization?(val)
|
99
|
+
msg = "#{instance.class} did not serialize to a valid scalar type. It became a: #{val.class}"
|
88
100
|
if val.is_a?(Hash)
|
89
101
|
msg += "\nIf you want to store a structured Hash, consider using a T::Struct as your type."
|
90
102
|
end
|
@@ -12,7 +12,7 @@ class T::Props::Decorator
|
|
12
12
|
|
13
13
|
Rules = T.type_alias {T::Hash[Symbol, T.untyped]}
|
14
14
|
DecoratedInstance = T.type_alias {Object} # Would be T::Props, but that produces circular reference errors in some circumstances
|
15
|
-
PropType = T.type_alias {T
|
15
|
+
PropType = T.type_alias {T::Types::Base}
|
16
16
|
PropTypeOrClass = T.type_alias {T.any(PropType, Module)}
|
17
17
|
|
18
18
|
class NoRulesError < StandardError; end
|
@@ -335,10 +335,7 @@ class T::Props::Decorator
|
|
335
335
|
if !cls.is_a?(Module)
|
336
336
|
cls = convert_type_to_class(cls)
|
337
337
|
end
|
338
|
-
type_object = type
|
339
|
-
if !(type_object.singleton_class < T::Props::CustomType)
|
340
|
-
type_object = smart_coerce(type_object, array: rules[:array], enum: rules[:enum])
|
341
|
-
end
|
338
|
+
type_object = smart_coerce(type, array: rules[:array], enum: rules[:enum])
|
342
339
|
|
343
340
|
prop_validate_definition!(name, cls, rules, type_object)
|
344
341
|
|
@@ -128,8 +128,7 @@ module T::Props
|
|
128
128
|
private_class_method def self.handle_custom_type(varname, type, mode)
|
129
129
|
case mode
|
130
130
|
when Serialize
|
131
|
-
|
132
|
-
"T::Props::CustomType.checked_serialize(#{type_name}, #{varname})"
|
131
|
+
"T::Props::CustomType.checked_serialize(#{varname})"
|
133
132
|
when Deserialize
|
134
133
|
type_name = T.must(module_name(type))
|
135
134
|
"#{type_name}.deserialize(#{varname})"
|
@@ -20,17 +20,10 @@ module T::Props
|
|
20
20
|
end
|
21
21
|
def self.build_setter_proc(klass, prop, rules)
|
22
22
|
# Our nil check works differently than a simple T.nilable for various
|
23
|
-
# reasons (including the `raise_on_nil_write` setting
|
24
|
-
# of defaults & factories,
|
25
|
-
#
|
26
|
-
# `valid?` on it won't work as expected), so unwrap any T.nilable and
|
27
|
-
# do a check manually. (Note this hack does not fix custom types as
|
28
|
-
# collection elements.)
|
23
|
+
# reasons (including the `raise_on_nil_write` setting and the existence
|
24
|
+
# of defaults & factories), so unwrap any T.nilable and do a check
|
25
|
+
# manually.
|
29
26
|
non_nil_type = T::Utils::Nilable.get_underlying_type_object(rules.fetch(:type_object))
|
30
|
-
if non_nil_type.is_a?(T::Types::Simple) && non_nil_type.raw_type.singleton_class < T::Props::CustomType
|
31
|
-
non_nil_type = non_nil_type.raw_type
|
32
|
-
end
|
33
|
-
|
34
27
|
accessor_key = rules.fetch(:accessor_key)
|
35
28
|
validate = rules[:setter_validate]
|
36
29
|
|
@@ -51,7 +44,7 @@ module T::Props
|
|
51
44
|
params(
|
52
45
|
prop: Symbol,
|
53
46
|
accessor_key: Symbol,
|
54
|
-
non_nil_type: T
|
47
|
+
non_nil_type: T::Types::Base,
|
55
48
|
klass: T.all(Module, T::Props::ClassMethods),
|
56
49
|
validate: T.nilable(ValidateProc)
|
57
50
|
)
|
@@ -80,7 +73,7 @@ module T::Props
|
|
80
73
|
params(
|
81
74
|
prop: Symbol,
|
82
75
|
accessor_key: Symbol,
|
83
|
-
non_nil_type: T
|
76
|
+
non_nil_type: T::Types::Base,
|
84
77
|
klass: T.all(Module, T::Props::ClassMethods),
|
85
78
|
validate: T.nilable(ValidateProc),
|
86
79
|
)
|
@@ -28,7 +28,7 @@ module T::Props::TypeValidation
|
|
28
28
|
def prop_validate_definition!(name, _cls, rules, type)
|
29
29
|
super
|
30
30
|
|
31
|
-
if !rules[:DEPRECATED_underspecified_type]
|
31
|
+
if !rules[:DEPRECATED_underspecified_type]
|
32
32
|
validate_type(type, field_name: name)
|
33
33
|
elsif rules[:DEPRECATED_underspecified_type] && find_invalid_subtype(type).nil?
|
34
34
|
raise ArgumentError.new("DEPRECATED_underspecified_type set unnecessarily for #{@class.name}.#{name} - #{type} is a valid type")
|
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.5579
|
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-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest
|