1- # typed: true # rubocop:todo Sorbet/StrictSigil
1+ # typed: strict
22# frozen_string_literal: true
33
44require "api/analytics"
@@ -11,10 +11,10 @@ module Homebrew
1111 module API
1212 extend Cachable
1313
14- HOMEBREW_CACHE_API = ( HOMEBREW_CACHE /"api" ) . freeze
15- HOMEBREW_CACHE_API_SOURCE = ( HOMEBREW_CACHE /"api-source" ) . freeze
14+ HOMEBREW_CACHE_API = T . let ( ( HOMEBREW_CACHE /"api" ) . freeze , Pathname )
15+ HOMEBREW_CACHE_API_SOURCE = T . let ( ( HOMEBREW_CACHE /"api-source" ) . freeze , Pathname )
1616
17- sig { params ( endpoint : String ) . returns ( Hash ) }
17+ sig { params ( endpoint : String ) . returns ( T :: Hash [ String , T . untyped ] ) }
1818 def self . fetch ( endpoint )
1919 return cache [ endpoint ] if cache . present? && cache . key? ( endpoint )
2020
@@ -33,7 +33,8 @@ def self.fetch(endpoint)
3333 end
3434
3535 sig {
36- params ( endpoint : String , target : Pathname , stale_seconds : Integer ) . returns ( [ T . any ( Array , Hash ) , T ::Boolean ] )
36+ params ( endpoint : String , target : Pathname ,
37+ stale_seconds : Integer ) . returns ( [ T . any ( T ::Array [ T . untyped ] , T ::Hash [ String , T . untyped ] ) , T ::Boolean ] )
3738 }
3839 def self . fetch_json_api_file ( endpoint , target : HOMEBREW_CACHE_API /endpoint ,
3940 stale_seconds : Homebrew ::EnvConfig . api_auto_update_secs . to_i )
@@ -96,7 +97,8 @@ def self.fetch_json_api_file(endpoint, target: HOMEBREW_CACHE_API/endpoint,
9697
9798 mtime = insecure_download ? Time . new ( 1970 , 1 , 1 ) : Time . now
9899 FileUtils . touch ( target , mtime :) unless skip_download
99- JSON . parse ( target . read ( encoding : Encoding ::UTF_8 ) , freeze : true )
100+ # Can use `target.read` again when/if https://github.com/sorbet/sorbet/pull/8999 is merged/released.
101+ JSON . parse ( File . read ( target , encoding : Encoding ::UTF_8 ) , freeze : true )
100102 rescue JSON ::ParserError
101103 target . unlink
102104 retry_count += 1
@@ -122,8 +124,11 @@ def self.fetch_json_api_file(endpoint, target: HOMEBREW_CACHE_API/endpoint,
122124 end
123125 end
124126
125- sig { params ( json : Hash , bottle_tag : T . nilable ( ::Utils ::Bottles ::Tag ) ) . returns ( Hash ) }
126- def self . merge_variations ( json , bottle_tag : nil )
127+ sig {
128+ params ( json : T ::Hash [ String , T . untyped ] ,
129+ bottle_tag : ::Utils ::Bottles ::Tag ) . returns ( T ::Hash [ String , T . untyped ] )
130+ }
131+ def self . merge_variations ( json , bottle_tag : T . unsafe ( nil ) )
127132 return json unless json . key? ( "variations" )
128133
129134 bottle_tag ||= Homebrew ::SimulateSystem . current_tag
@@ -147,7 +152,10 @@ def self.write_names_file(names, type, regenerate:)
147152 false
148153 end
149154
150- sig { params ( json_data : Hash ) . returns ( [ T ::Boolean , T . any ( String , Array , Hash ) ] ) }
155+ sig {
156+ params ( json_data : T ::Hash [ String , T . untyped ] )
157+ . returns ( [ T ::Boolean , T . any ( String , T ::Array [ T . untyped ] , T ::Hash [ String , T . untyped ] ) ] )
158+ }
151159 private_class_method def self . verify_and_parse_jws ( json_data )
152160 signatures = json_data [ "signatures" ]
153161 homebrew_signature = signatures &.find { |sig | sig . dig ( "header" , "kid" ) == "homebrew-1" }
0 commit comments