terminal-shop 3.6.2 → 3.8.0

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.
Files changed (137) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +48 -0
  3. data/README.md +81 -53
  4. data/SECURITY.md +2 -2
  5. data/lib/terminal_shop/client.rb +4 -4
  6. data/lib/terminal_shop/errors.rb +1 -1
  7. data/lib/terminal_shop/internal/transport/base_client.rb +77 -5
  8. data/lib/terminal_shop/internal/transport/pooled_net_requester.rb +17 -1
  9. data/lib/terminal_shop/internal/type/array_of.rb +9 -1
  10. data/lib/terminal_shop/internal/type/base_model.rb +77 -30
  11. data/lib/terminal_shop/internal/type/boolean.rb +8 -0
  12. data/lib/terminal_shop/internal/type/converter.rb +18 -0
  13. data/lib/terminal_shop/internal/type/enum.rb +13 -0
  14. data/lib/terminal_shop/internal/type/file_input.rb +7 -0
  15. data/lib/terminal_shop/internal/type/hash_of.rb +9 -1
  16. data/lib/terminal_shop/internal/type/union.rb +13 -0
  17. data/lib/terminal_shop/internal/type/unknown.rb +8 -0
  18. data/lib/terminal_shop/internal/util.rb +101 -0
  19. data/lib/terminal_shop/internal.rb +9 -0
  20. data/lib/terminal_shop/models.rb +38 -0
  21. data/lib/terminal_shop/request_options.rb +4 -0
  22. data/lib/terminal_shop/version.rb +1 -1
  23. data/lib/terminal_shop.rb +2 -0
  24. data/rbi/terminal_shop/internal/transport/base_client.rbi +31 -8
  25. data/rbi/terminal_shop/internal/transport/pooled_net_requester.rbi +10 -4
  26. data/rbi/terminal_shop/internal/type/array_of.rbi +6 -0
  27. data/rbi/terminal_shop/internal/type/base_model.rbi +38 -15
  28. data/rbi/terminal_shop/internal/type/base_page.rbi +1 -1
  29. data/rbi/terminal_shop/internal/type/boolean.rbi +6 -0
  30. data/rbi/terminal_shop/internal/type/converter.rbi +2 -0
  31. data/rbi/terminal_shop/internal/type/enum.rbi +6 -0
  32. data/rbi/terminal_shop/internal/type/file_input.rbi +5 -0
  33. data/rbi/terminal_shop/internal/type/hash_of.rbi +6 -0
  34. data/rbi/terminal_shop/internal/type/union.rbi +6 -0
  35. data/rbi/terminal_shop/internal/type/unknown.rbi +6 -0
  36. data/rbi/terminal_shop/internal/util.rbi +62 -5
  37. data/rbi/terminal_shop/internal.rbi +7 -0
  38. data/rbi/terminal_shop/models/address.rbi +3 -1
  39. data/rbi/terminal_shop/models/address_create_params.rbi +6 -1
  40. data/rbi/terminal_shop/models/address_create_response.rbi +6 -1
  41. data/rbi/terminal_shop/models/address_delete_params.rbi +6 -1
  42. data/rbi/terminal_shop/models/address_delete_response.rbi +6 -1
  43. data/rbi/terminal_shop/models/address_get_params.rbi +3 -1
  44. data/rbi/terminal_shop/models/address_get_response.rbi +6 -1
  45. data/rbi/terminal_shop/models/address_list_params.rbi +6 -1
  46. data/rbi/terminal_shop/models/address_list_response.rbi +6 -1
  47. data/rbi/terminal_shop/models/app.rbi +3 -1
  48. data/rbi/terminal_shop/models/app_create_params.rbi +3 -1
  49. data/rbi/terminal_shop/models/app_create_response.rbi +12 -2
  50. data/rbi/terminal_shop/models/app_delete_params.rbi +3 -1
  51. data/rbi/terminal_shop/models/app_delete_response.rbi +6 -1
  52. data/rbi/terminal_shop/models/app_get_params.rbi +3 -1
  53. data/rbi/terminal_shop/models/app_get_response.rbi +6 -1
  54. data/rbi/terminal_shop/models/app_list_params.rbi +3 -1
  55. data/rbi/terminal_shop/models/app_list_response.rbi +6 -1
  56. data/rbi/terminal_shop/models/card.rbi +9 -2
  57. data/rbi/terminal_shop/models/card_collect_params.rbi +6 -1
  58. data/rbi/terminal_shop/models/card_collect_response.rbi +12 -2
  59. data/rbi/terminal_shop/models/card_create_params.rbi +3 -1
  60. data/rbi/terminal_shop/models/card_create_response.rbi +6 -1
  61. data/rbi/terminal_shop/models/card_delete_params.rbi +3 -1
  62. data/rbi/terminal_shop/models/card_delete_response.rbi +6 -1
  63. data/rbi/terminal_shop/models/card_get_params.rbi +3 -1
  64. data/rbi/terminal_shop/models/card_get_response.rbi +6 -1
  65. data/rbi/terminal_shop/models/card_list_params.rbi +3 -1
  66. data/rbi/terminal_shop/models/card_list_response.rbi +6 -1
  67. data/rbi/terminal_shop/models/cart.rbi +18 -4
  68. data/rbi/terminal_shop/models/cart_clear_params.rbi +3 -1
  69. data/rbi/terminal_shop/models/cart_clear_response.rbi +6 -1
  70. data/rbi/terminal_shop/models/cart_convert_params.rbi +6 -1
  71. data/rbi/terminal_shop/models/cart_convert_response.rbi +6 -1
  72. data/rbi/terminal_shop/models/cart_get_params.rbi +3 -1
  73. data/rbi/terminal_shop/models/cart_get_response.rbi +6 -1
  74. data/rbi/terminal_shop/models/cart_set_address_params.rbi +6 -1
  75. data/rbi/terminal_shop/models/cart_set_address_response.rbi +6 -1
  76. data/rbi/terminal_shop/models/cart_set_card_params.rbi +6 -1
  77. data/rbi/terminal_shop/models/cart_set_card_response.rbi +6 -1
  78. data/rbi/terminal_shop/models/cart_set_item_params.rbi +6 -1
  79. data/rbi/terminal_shop/models/cart_set_item_response.rbi +6 -1
  80. data/rbi/terminal_shop/models/email_create_params.rbi +6 -1
  81. data/rbi/terminal_shop/models/email_create_response.rbi +6 -1
  82. data/rbi/terminal_shop/models/order.rbi +24 -5
  83. data/rbi/terminal_shop/models/order_create_params.rbi +6 -1
  84. data/rbi/terminal_shop/models/order_create_response.rbi +6 -1
  85. data/rbi/terminal_shop/models/order_get_params.rbi +3 -1
  86. data/rbi/terminal_shop/models/order_get_response.rbi +6 -1
  87. data/rbi/terminal_shop/models/order_list_params.rbi +3 -1
  88. data/rbi/terminal_shop/models/order_list_response.rbi +6 -1
  89. data/rbi/terminal_shop/models/product.rbi +9 -2
  90. data/rbi/terminal_shop/models/product_get_params.rbi +3 -1
  91. data/rbi/terminal_shop/models/product_get_response.rbi +6 -1
  92. data/rbi/terminal_shop/models/product_list_params.rbi +6 -1
  93. data/rbi/terminal_shop/models/product_list_response.rbi +6 -1
  94. data/rbi/terminal_shop/models/product_variant.rbi +9 -2
  95. data/rbi/terminal_shop/models/profile.rbi +9 -2
  96. data/rbi/terminal_shop/models/profile_me_params.rbi +3 -1
  97. data/rbi/terminal_shop/models/profile_me_response.rbi +6 -1
  98. data/rbi/terminal_shop/models/profile_update_params.rbi +6 -1
  99. data/rbi/terminal_shop/models/profile_update_response.rbi +6 -1
  100. data/rbi/terminal_shop/models/subscription.rbi +17 -16
  101. data/rbi/terminal_shop/models/subscription_create_params.rbi +6 -1
  102. data/rbi/terminal_shop/models/subscription_create_response.rbi +6 -1
  103. data/rbi/terminal_shop/models/subscription_delete_params.rbi +6 -1
  104. data/rbi/terminal_shop/models/subscription_delete_response.rbi +6 -1
  105. data/rbi/terminal_shop/models/subscription_get_params.rbi +6 -1
  106. data/rbi/terminal_shop/models/subscription_get_response.rbi +6 -1
  107. data/rbi/terminal_shop/models/subscription_list_params.rbi +6 -1
  108. data/rbi/terminal_shop/models/subscription_list_response.rbi +6 -1
  109. data/rbi/terminal_shop/models/subscription_update_params.rbi +18 -3
  110. data/rbi/terminal_shop/models/subscription_update_response.rbi +6 -1
  111. data/rbi/terminal_shop/models/token.rbi +3 -1
  112. data/rbi/terminal_shop/models/token_create_params.rbi +6 -1
  113. data/rbi/terminal_shop/models/token_create_response.rbi +12 -2
  114. data/rbi/terminal_shop/models/token_delete_params.rbi +6 -1
  115. data/rbi/terminal_shop/models/token_delete_response.rbi +6 -1
  116. data/rbi/terminal_shop/models/token_get_params.rbi +3 -1
  117. data/rbi/terminal_shop/models/token_get_response.rbi +6 -1
  118. data/rbi/terminal_shop/models/token_list_params.rbi +3 -1
  119. data/rbi/terminal_shop/models/token_list_response.rbi +6 -1
  120. data/rbi/terminal_shop/models/view_init_params.rbi +3 -1
  121. data/rbi/terminal_shop/models/view_init_response.rbi +12 -2
  122. data/rbi/terminal_shop/request_options.rbi +3 -1
  123. data/sig/terminal_shop/internal/transport/base_client.rbs +16 -1
  124. data/sig/terminal_shop/internal/transport/pooled_net_requester.rbs +4 -0
  125. data/sig/terminal_shop/internal/type/array_of.rbs +3 -0
  126. data/sig/terminal_shop/internal/type/base_model.rbs +13 -5
  127. data/sig/terminal_shop/internal/type/base_page.rbs +1 -1
  128. data/sig/terminal_shop/internal/type/boolean.rbs +3 -0
  129. data/sig/terminal_shop/internal/type/converter.rbs +2 -0
  130. data/sig/terminal_shop/internal/type/enum.rbs +3 -0
  131. data/sig/terminal_shop/internal/type/file_input.rbs +2 -0
  132. data/sig/terminal_shop/internal/type/hash_of.rbs +3 -0
  133. data/sig/terminal_shop/internal/type/union.rbs +3 -0
  134. data/sig/terminal_shop/internal/type/unknown.rbs +3 -0
  135. data/sig/terminal_shop/internal/util.rbs +25 -0
  136. data/sig/terminal_shop/internal.rbs +4 -0
  137. metadata +2 -2
@@ -6,6 +6,7 @@ module TerminalShop
6
6
  # @abstract
7
7
  class BaseModel
8
8
  extend TerminalShop::Internal::Type::Converter
9
+ extend TerminalShop::Internal::Util::SorbetRuntimeSupport
9
10
 
10
11
  class << self
11
12
  # @api private
@@ -13,11 +14,17 @@ module TerminalShop
13
14
  # Assumes superclass fields are totally defined before fields are accessed /
14
15
  # defined on subclasses.
15
16
  #
16
- # @return [Hash{Symbol=>Hash{Symbol=>Object}}]
17
- def known_fields
18
- @known_fields ||= (self < TerminalShop::Internal::Type::BaseModel ? superclass.known_fields.dup : {})
17
+ # @param child [Class<TerminalShop::Internal::Type::BaseModel>]
18
+ def inherited(child)
19
+ super
20
+ child.known_fields.replace(known_fields.dup)
19
21
  end
20
22
 
23
+ # @api private
24
+ #
25
+ # @return [Hash{Symbol=>Hash{Symbol=>Object}}]
26
+ def known_fields = @known_fields ||= {}
27
+
21
28
  # @api private
22
29
  #
23
30
  # @return [Hash{Symbol=>Hash{Symbol=>Object}}]
@@ -204,7 +211,7 @@ module TerminalShop
204
211
  #
205
212
  # @option state [Integer] :branched
206
213
  #
207
- # @return [TerminalShop::Internal::Type::BaseModel, Object]
214
+ # @return [self, Object]
208
215
  def coerce(value, state:)
209
216
  exactness = state.fetch(:exactness)
210
217
 
@@ -263,7 +270,7 @@ module TerminalShop
263
270
 
264
271
  # @api private
265
272
  #
266
- # @param value [TerminalShop::Internal::Type::BaseModel, Object]
273
+ # @param value [self, Object]
267
274
  #
268
275
  # @param state [Hash{Symbol=>Object}] .
269
276
  #
@@ -302,6 +309,46 @@ module TerminalShop
302
309
 
303
310
  acc
304
311
  end
312
+
313
+ # @api private
314
+ #
315
+ # @return [Object]
316
+ def to_sorbet_type
317
+ self
318
+ end
319
+ end
320
+
321
+ class << self
322
+ # @api private
323
+ #
324
+ # @param model [TerminalShop::Internal::Type::BaseModel]
325
+ # @param convert [Boolean]
326
+ #
327
+ # @return [Hash{Symbol=>Object}]
328
+ def recursively_to_h(model, convert:)
329
+ rec = ->(x) do
330
+ case x
331
+ in TerminalShop::Internal::Type::BaseModel
332
+ if convert
333
+ fields = x.class.known_fields
334
+ x.to_h.to_h do |key, val|
335
+ [key, rec.call(fields.key?(key) ? x.public_send(key) : val)]
336
+ rescue TerminalShop::Errors::ConversionError
337
+ [key, rec.call(val)]
338
+ end
339
+ else
340
+ rec.call(x.to_h)
341
+ end
342
+ in Hash
343
+ x.transform_values(&rec)
344
+ in Array
345
+ x.map(&rec)
346
+ else
347
+ x
348
+ end
349
+ end
350
+ rec.call(model)
351
+ end
305
352
  end
306
353
 
307
354
  # @api public
@@ -340,9 +387,25 @@ module TerminalShop
340
387
 
341
388
  alias_method :to_hash, :to_h
342
389
 
390
+ # @api public
391
+ #
392
+ # In addition to the behaviour of `#to_h`, this method will recursively call
393
+ # `#to_h` on nested models.
394
+ #
395
+ # @return [Hash{Symbol=>Object}]
396
+ def deep_to_h = self.class.recursively_to_h(@data, convert: false)
397
+
343
398
  # @param keys [Array<Symbol>, nil]
344
399
  #
345
400
  # @return [Hash{Symbol=>Object}]
401
+ #
402
+ # @example
403
+ # # `product_api` is a `TerminalShop::ProductAPI`
404
+ # product_api => {
405
+ # id: id,
406
+ # description: description,
407
+ # name: name
408
+ # }
346
409
  def deconstruct_keys(keys)
347
410
  (keys || self.class.known_fields.keys)
348
411
  .filter_map do |k|
@@ -355,29 +418,6 @@ module TerminalShop
355
418
  .to_h
356
419
  end
357
420
 
358
- class << self
359
- # @api private
360
- #
361
- # @param model [TerminalShop::Internal::Type::BaseModel]
362
- #
363
- # @return [Hash{Symbol=>Object}]
364
- def walk(model)
365
- walk = ->(x) do
366
- case x
367
- in TerminalShop::Internal::Type::BaseModel
368
- walk.call(x.to_h)
369
- in Hash
370
- x.transform_values(&walk)
371
- in Array
372
- x.map(&walk)
373
- else
374
- x
375
- end
376
- end
377
- walk.call(model)
378
- end
379
- end
380
-
381
421
  # @api public
382
422
  #
383
423
  # @param a [Object]
@@ -423,12 +463,19 @@ module TerminalShop
423
463
  # @api public
424
464
  #
425
465
  # @return [String]
426
- def to_s = self.class.walk(@data).to_s
466
+ def to_s = deep_to_h.to_s
427
467
 
428
468
  # @api private
429
469
  #
430
470
  # @return [String]
431
- def inspect = "#<#{self.class}:0x#{object_id.to_s(16)} #{self}>"
471
+ def inspect
472
+ converted = self.class.recursively_to_h(self, convert: true)
473
+ "#<#{self.class}:0x#{object_id.to_s(16)} #{converted}>"
474
+ end
475
+
476
+ define_sorbet_constant!(:KnownField) do
477
+ T.type_alias { {mode: T.nilable(Symbol), required: T::Boolean, nilable: T::Boolean} }
478
+ end
432
479
  end
433
480
  end
434
481
  end
@@ -10,6 +10,7 @@ module TerminalShop
10
10
  # Ruby has no Boolean class; this is something for models to refer to.
11
11
  class Boolean
12
12
  extend TerminalShop::Internal::Type::Converter
13
+ extend TerminalShop::Internal::Util::SorbetRuntimeSupport
13
14
 
14
15
  private_class_method :new
15
16
 
@@ -56,6 +57,13 @@ module TerminalShop
56
57
  # @option state [Boolean] :can_retry
57
58
  #
58
59
  # @return [Boolean, Object]
60
+
61
+ # @api private
62
+ #
63
+ # @return [Object]
64
+ def to_sorbet_type
65
+ T::Boolean
66
+ end
59
67
  end
60
68
  end
61
69
  end
@@ -5,6 +5,8 @@ module TerminalShop
5
5
  module Type
6
6
  # @api private
7
7
  module Converter
8
+ extend TerminalShop::Internal::Util::SorbetRuntimeSupport
9
+
8
10
  # rubocop:disable Lint/UnusedMethodArgument
9
11
 
10
12
  # @api private
@@ -268,6 +270,22 @@ module TerminalShop
268
270
  end
269
271
  end
270
272
  end
273
+
274
+ define_sorbet_constant!(:Input) do
275
+ T.type_alias { T.any(TerminalShop::Internal::Type::Converter, T::Class[T.anything]) }
276
+ end
277
+ define_sorbet_constant!(:CoerceState) do
278
+ T.type_alias do
279
+ {
280
+ strictness: T.any(T::Boolean, Symbol),
281
+ exactness: {yes: Integer, no: Integer, maybe: Integer},
282
+ branched: Integer
283
+ }
284
+ end
285
+ end
286
+ define_sorbet_constant!(:DumpState) do
287
+ T.type_alias { {can_retry: T::Boolean} }
288
+ end
271
289
  end
272
290
  end
273
291
  end
@@ -42,6 +42,7 @@ module TerminalShop
42
42
  # end
43
43
  module Enum
44
44
  include TerminalShop::Internal::Type::Converter
45
+ include TerminalShop::Internal::Util::SorbetRuntimeSupport
45
46
 
46
47
  # All of the valid Symbol values for this enum.
47
48
  #
@@ -111,6 +112,18 @@ module TerminalShop
111
112
  #
112
113
  # @return [Symbol, Object]
113
114
 
115
+ # @api private
116
+ #
117
+ # @return [Object]
118
+ def to_sorbet_type
119
+ case values
120
+ in []
121
+ T.noreturn
122
+ in [value, *_]
123
+ T.all(TerminalShop::Internal::Util::SorbetRuntimeSupport.to_sorbet_type(value), self)
124
+ end
125
+ end
126
+
114
127
  # @api private
115
128
  #
116
129
  # @param depth [Integer]
@@ -89,6 +89,13 @@ module TerminalShop
89
89
 
90
90
  value
91
91
  end
92
+
93
+ # @api private
94
+ #
95
+ # @return [Object]
96
+ def to_sorbet_type
97
+ T.any(Pathname, StringIO, IO, String, TerminalShop::FilePart)
98
+ end
92
99
  end
93
100
  end
94
101
  end
@@ -12,6 +12,7 @@ module TerminalShop
12
12
  # Hash of items of a given type.
13
13
  class HashOf
14
14
  include TerminalShop::Internal::Type::Converter
15
+ include TerminalShop::Internal::Util::SorbetRuntimeSupport
15
16
 
16
17
  private_class_method :new
17
18
 
@@ -29,7 +30,7 @@ module TerminalShop
29
30
  #
30
31
  # @option spec [Boolean] :"nil?"
31
32
  #
32
- # @return [TerminalShop::Internal::Type::HashOf]
33
+ # @return [self]
33
34
  def self.[](...) = new(...)
34
35
 
35
36
  # @api public
@@ -130,6 +131,13 @@ module TerminalShop
130
131
  end
131
132
  end
132
133
 
134
+ # @api private
135
+ #
136
+ # @return [Object]
137
+ def to_sorbet_type
138
+ T::Hash[TerminalShop::Internal::Util::SorbetRuntimeSupport.to_sorbet_type(item_type)]
139
+ end
140
+
133
141
  # @api private
134
142
  #
135
143
  # @return [generic<Elem>]
@@ -6,6 +6,7 @@ module TerminalShop
6
6
  # @api private
7
7
  module Union
8
8
  include TerminalShop::Internal::Type::Converter
9
+ include TerminalShop::Internal::Util::SorbetRuntimeSupport
9
10
 
10
11
  # @api private
11
12
  #
@@ -196,6 +197,18 @@ module TerminalShop
196
197
  super
197
198
  end
198
199
 
200
+ # @api private
201
+ #
202
+ # @return [Object]
203
+ def to_sorbet_type
204
+ case (v = variants)
205
+ in []
206
+ T.noreturn
207
+ else
208
+ T.any(*v.map { TerminalShop::Internal::Util::SorbetRuntimeSupport.to_sorbet_type(_1) })
209
+ end
210
+ end
211
+
199
212
  # rubocop:enable Style/CaseEquality
200
213
  # rubocop:enable Style/HashEachMethods
201
214
 
@@ -10,6 +10,7 @@ module TerminalShop
10
10
  # When we don't know what to expect for the value.
11
11
  class Unknown
12
12
  extend TerminalShop::Internal::Type::Converter
13
+ extend TerminalShop::Internal::Util::SorbetRuntimeSupport
13
14
 
14
15
  # rubocop:disable Lint/UnusedMethodArgument
15
16
 
@@ -58,6 +59,13 @@ module TerminalShop
58
59
  # @option state [Boolean] :can_retry
59
60
  #
60
61
  # @return [Object]
62
+
63
+ # @api private
64
+ #
65
+ # @return [Object]
66
+ def to_sorbet_type
67
+ T.anything
68
+ end
61
69
  end
62
70
 
63
71
  # rubocop:enable Lint/UnusedMethodArgument
@@ -9,6 +9,23 @@ module TerminalShop
9
9
  # @return [Float]
10
10
  def self.monotonic_secs = Process.clock_gettime(Process::CLOCK_MONOTONIC)
11
11
 
12
+ # @api private
13
+ #
14
+ # @param ns [Module, Class]
15
+ #
16
+ # @return [Enumerable<Module, Class>]
17
+ def self.walk_namespaces(ns)
18
+ ns.constants(false).lazy.flat_map do
19
+ case (c = ns.const_get(_1, false))
20
+ in Module | Class
21
+ walk_namespaces(c)
22
+ else
23
+ []
24
+ end
25
+ end
26
+ .chain([ns])
27
+ end
28
+
12
29
  class << self
13
30
  # @api private
14
31
  #
@@ -801,6 +818,90 @@ module TerminalShop
801
818
  end
802
819
  end
803
820
  end
821
+
822
+ # @api private
823
+ module SorbetRuntimeSupport
824
+ class MissingSorbetRuntimeError < ::RuntimeError
825
+ end
826
+
827
+ # @api private
828
+ #
829
+ # @return [Hash{Symbol=>Object}]
830
+ private def sorbet_runtime_constants = @sorbet_runtime_constants ||= {}
831
+
832
+ # @api private
833
+ #
834
+ # @param name [Symbol]
835
+ def const_missing(name)
836
+ super unless sorbet_runtime_constants.key?(name)
837
+
838
+ unless Object.const_defined?(:T)
839
+ message = "Trying to access a Sorbet constant #{name.inspect} without `sorbet-runtime`."
840
+ raise MissingSorbetRuntimeError.new(message)
841
+ end
842
+
843
+ sorbet_runtime_constants.fetch(name).call
844
+ end
845
+
846
+ # @api private
847
+ #
848
+ # @param name [Symbol]
849
+ #
850
+ # @return [Boolean]
851
+ def sorbet_constant_defined?(name) = sorbet_runtime_constants.key?(name)
852
+
853
+ # @api private
854
+ #
855
+ # @param name [Symbol]
856
+ # @param blk [Proc]
857
+ def define_sorbet_constant!(name, &blk) = sorbet_runtime_constants.store(name, blk)
858
+
859
+ # @api private
860
+ #
861
+ # @return [Object]
862
+ def to_sorbet_type = raise NotImplementedError
863
+
864
+ class << self
865
+ # @api private
866
+ #
867
+ # @param type [TerminalShop::Internal::Util::SorbetRuntimeSupport, Object]
868
+ #
869
+ # @return [Object]
870
+ def to_sorbet_type(type)
871
+ case type
872
+ in TerminalShop::Internal::Util::SorbetRuntimeSupport
873
+ type.to_sorbet_type
874
+ else
875
+ type
876
+ end
877
+ end
878
+ end
879
+ end
880
+
881
+ extend TerminalShop::Internal::Util::SorbetRuntimeSupport
882
+
883
+ define_sorbet_constant!(:ParsedUri) do
884
+ T.type_alias do
885
+ {
886
+ scheme: T.nilable(String),
887
+ host: T.nilable(String),
888
+ port: T.nilable(Integer),
889
+ path: T.nilable(String),
890
+ query: T::Hash[String, T::Array[String]]
891
+ }
892
+ end
893
+ end
894
+
895
+ define_sorbet_constant!(:ServerSentEvent) do
896
+ T.type_alias do
897
+ {
898
+ event: T.nilable(String),
899
+ data: T.nilable(String),
900
+ id: T.nilable(String),
901
+ retry: T.nilable(Integer)
902
+ }
903
+ end
904
+ end
804
905
  end
805
906
  end
806
907
  end
@@ -2,10 +2,19 @@
2
2
 
3
3
  module TerminalShop
4
4
  module Internal
5
+ extend TerminalShop::Internal::Util::SorbetRuntimeSupport
6
+
5
7
  OMIT =
6
8
  Object.new.tap do
7
9
  _1.define_singleton_method(:inspect) { "#<#{TerminalShop::Internal}::OMIT>" }
8
10
  end
9
11
  .freeze
12
+
13
+ define_sorbet_constant!(:AnyHash) do
14
+ T.type_alias { T::Hash[Symbol, T.anything] }
15
+ end
16
+ define_sorbet_constant!(:FileInput) do
17
+ T.type_alias { T.any(Pathname, StringIO, IO, String, TerminalShop::FilePart) }
18
+ end
10
19
  end
11
20
  end
@@ -1,6 +1,44 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TerminalShop
4
+ [TerminalShop::Internal::Type::BaseModel, *TerminalShop::Internal::Type::BaseModel.subclasses].each do |cls|
5
+ cls.define_sorbet_constant!(:OrHash) { T.type_alias { T.any(cls, TerminalShop::Internal::AnyHash) } }
6
+ end
7
+
8
+ TerminalShop::Internal::Util.walk_namespaces(TerminalShop::Models).each do |mod|
9
+ case mod
10
+ in TerminalShop::Internal::Type::Enum | TerminalShop::Internal::Type::Union
11
+ mod.constants.each do |name|
12
+ case mod.const_get(name)
13
+ in true | false
14
+ mod.define_sorbet_constant!(:TaggedBoolean) { T.type_alias { T.all(T::Boolean, mod) } }
15
+ mod.define_sorbet_constant!(:OrBoolean) { T.type_alias { T::Boolean } }
16
+ in Integer
17
+ mod.define_sorbet_constant!(:TaggedInteger) { T.type_alias { T.all(Integer, mod) } }
18
+ mod.define_sorbet_constant!(:OrInteger) { T.type_alias { Integer } }
19
+ in Float
20
+ mod.define_sorbet_constant!(:TaggedFloat) { T.type_alias { T.all(Float, mod) } }
21
+ mod.define_sorbet_constant!(:OrFloat) { T.type_alias { Float } }
22
+ in Symbol
23
+ mod.define_sorbet_constant!(:TaggedSymbol) { T.type_alias { T.all(Symbol, mod) } }
24
+ mod.define_sorbet_constant!(:OrSymbol) { T.type_alias { T.any(Symbol, String) } }
25
+ else
26
+ end
27
+ end
28
+ else
29
+ end
30
+ end
31
+
32
+ TerminalShop::Internal::Util.walk_namespaces(TerminalShop::Models)
33
+ .lazy
34
+ .grep(TerminalShop::Internal::Type::Union)
35
+ .each do |mod|
36
+ const = :Variants
37
+ next if mod.sorbet_constant_defined?(const)
38
+
39
+ mod.define_sorbet_constant!(const) { T.type_alias { mod.to_sorbet_type } }
40
+ end
41
+
4
42
  AddressAPI = TerminalShop::Models::AddressAPI
5
43
 
6
44
  AddressCreateParams = TerminalShop::Models::AddressCreateParams
@@ -69,5 +69,9 @@ module TerminalShop
69
69
  # Returns a new instance of RequestOptions.
70
70
  #
71
71
  # @param values [Hash{Symbol=>Object}]
72
+
73
+ define_sorbet_constant!(:OrHash) do
74
+ T.type_alias { T.any(TerminalShop::RequestOptions, TerminalShop::Internal::AnyHash) }
75
+ end
72
76
  end
73
77
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TerminalShop
4
- VERSION = "3.6.2"
4
+ VERSION = "3.8.0"
5
5
  end
data/lib/terminal_shop.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Standard libraries.
4
+ # rubocop:disable Lint/RedundantRequireStatement
4
5
  require "English"
5
6
  require "cgi"
6
7
  require "date"
@@ -15,6 +16,7 @@ require "set"
15
16
  require "stringio"
16
17
  require "time"
17
18
  require "uri"
19
+ # rubocop:enable Lint/RedundantRequireStatement
18
20
 
19
21
  # We already ship the preferred sorbet manifests in the package itself.
20
22
  # `tapioca` currently does not offer us a way to opt out of unnecessary compilation.
@@ -5,9 +5,11 @@ module TerminalShop
5
5
  module Transport
6
6
  # @api private
7
7
  class BaseClient
8
+ extend TerminalShop::Internal::Util::SorbetRuntimeSupport
9
+
8
10
  abstract!
9
11
 
10
- RequestComponentsShape =
12
+ RequestComponents =
11
13
  T.type_alias do
12
14
  {
13
15
  method: Symbol,
@@ -53,7 +55,7 @@ module TerminalShop
53
55
  }
54
56
  end
55
57
 
56
- RequestInputShape =
58
+ RequestInput =
57
59
  T.type_alias do
58
60
  {
59
61
  method: Symbol,
@@ -75,7 +77,7 @@ module TerminalShop
75
77
  sig do
76
78
  params(
77
79
  req:
78
- TerminalShop::Internal::Transport::BaseClient::RequestComponentsShape
80
+ TerminalShop::Internal::Transport::BaseClient::RequestComponents
79
81
  ).void
80
82
  end
81
83
  def validate!(req)
@@ -95,11 +97,11 @@ module TerminalShop
95
97
  sig do
96
98
  params(
97
99
  request:
98
- TerminalShop::Internal::Transport::BaseClient::RequestInputShape,
100
+ TerminalShop::Internal::Transport::BaseClient::RequestInput,
99
101
  status: Integer,
100
102
  response_headers: T.any(T::Hash[String, String], Net::HTTPHeader)
101
103
  ).returns(
102
- TerminalShop::Internal::Transport::BaseClient::RequestInputShape
104
+ TerminalShop::Internal::Transport::BaseClient::RequestInput
103
105
  )
104
106
  end
105
107
  def follow_redirect(request, status:, response_headers:)
@@ -116,6 +118,27 @@ module TerminalShop
116
118
  end
117
119
  end
118
120
 
121
+ sig { returns(URI::Generic) }
122
+ attr_reader :base_url
123
+
124
+ sig { returns(Float) }
125
+ attr_reader :timeout
126
+
127
+ sig { returns(Integer) }
128
+ attr_reader :max_retries
129
+
130
+ sig { returns(Float) }
131
+ attr_reader :initial_retry_delay
132
+
133
+ sig { returns(Float) }
134
+ attr_reader :max_retry_delay
135
+
136
+ sig { returns(T::Hash[String, String]) }
137
+ attr_reader :headers
138
+
139
+ sig { returns(T.nilable(String)) }
140
+ attr_reader :idempotency_header
141
+
119
142
  # @api private
120
143
  sig { returns(TerminalShop::Internal::Transport::PooledNetRequester) }
121
144
  attr_reader :requester
@@ -168,11 +191,11 @@ module TerminalShop
168
191
  overridable
169
192
  .params(
170
193
  req:
171
- TerminalShop::Internal::Transport::BaseClient::RequestComponentsShape,
194
+ TerminalShop::Internal::Transport::BaseClient::RequestComponents,
172
195
  opts: TerminalShop::Internal::AnyHash
173
196
  )
174
197
  .returns(
175
- TerminalShop::Internal::Transport::BaseClient::RequestInputShape
198
+ TerminalShop::Internal::Transport::BaseClient::RequestInput
176
199
  )
177
200
  end
178
201
  private def build_request(req, opts)
@@ -192,7 +215,7 @@ module TerminalShop
192
215
  sig do
193
216
  params(
194
217
  request:
195
- TerminalShop::Internal::Transport::BaseClient::RequestInputShape,
218
+ TerminalShop::Internal::Transport::BaseClient::RequestInput,
196
219
  redirect_count: Integer,
197
220
  retry_count: Integer,
198
221
  send_retry_header: T::Boolean