Skip to content

Commit 72791e3

Browse files
authored
Type runtime metadata extension refs as a record (#1432)
## Why Runtime metadata stores each extension as a ref hash with `name`, `require_path`, and, for an extension with options, a nested `config` hash. The RBS signatures type these refs as `Hash[String, String]`, which is wrong whenever `config` is present. #1424 registers an indexer extension with a nested `config`, which exposes the wrong type. ## What - Add an `extensionRefHash` record type: required `name` and `require_path`, optional `config`. - Use it for `ComponentExtension`, `GraphQLResolver`, and the scalar coercion adapter and indexing preparer refs. - Rewrite `Extension#to_dumpable_hash` so Steep can check it against the record. Its output does not change. ## Risk Low. The PR changes type signatures and rewrites one method without changing its output. ## Testing No manual testing. ## Bigger picture Second of three stacked PRs, on top of #1431. It moves out of #1424 so that #1424 only touches elasticgraph-proto_ingestion.
1 parent adf9368 commit 72791e3

5 files changed

Lines changed: 31 additions & 24 deletions

File tree

‎elasticgraph-schema_artifacts/lib/elastic_graph/schema_artifacts/runtime_metadata/extension.rb‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ def self.load_from_hash(hash, via:)
4040
# The serialized form of an extension.
4141
def to_dumpable_hash
4242
# Keys here are ordered alphabetically; please keep them that way.
43-
{
44-
"config" => Support::HashUtil.stringify_keys(config),
45-
"name" => name,
46-
"require_path" => require_path
47-
}.reject { |_, v| v.empty? }
43+
if config.empty?
44+
{"name" => name, "require_path" => require_path}
45+
else
46+
{"config" => Support::HashUtil.stringify_keys(config), "name" => name, "require_path" => require_path}
47+
end
4848
end
4949

5050
def verify_against!(interface_def)

‎elasticgraph-schema_artifacts/sig/elastic_graph/schema_artifacts/runtime_metadata/component_extension.rbs‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@ module ElasticGraph
22
module SchemaArtifacts
33
module RuntimeMetadata
44
class ComponentExtensionSupertype
5-
attr_reader extension_ref: ::Hash[::String, ::String]
5+
attr_reader extension_ref: extensionRefHash
66

77
def initialize: (
8-
extension_ref: ::Hash[::String, ::String]
8+
extension_ref: extensionRefHash
99
) -> void
1010

1111
def with: (
12-
?extension_ref: ::Hash[::String, ::String]
12+
?extension_ref: extensionRefHash
1313
) -> instance
1414

1515
def self.new:
16-
(extension_ref: ::Hash[::String, ::String]) -> instance
17-
| (::Hash[::String, ::String]) -> instance
16+
(extension_ref: extensionRefHash) -> instance
17+
| (extensionRefHash) -> instance
1818
end
1919

2020
class ComponentExtension < ComponentExtensionSupertype

‎elasticgraph-schema_artifacts/sig/elastic_graph/schema_artifacts/runtime_metadata/extension.rbs‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@ module ElasticGraph
33
module RuntimeMetadata
44
type extensionClass = ::Module | ::Class
55

6+
# The serialized form of an extension, as produced by `Extension#to_dumpable_hash`.
7+
type extensionRefHash = {
8+
"name" => ::String,
9+
"require_path" => ::String,
10+
?"config" => ::Hash[::String, untyped]
11+
}
12+
613
class ExtensionSupertype
714
attr_reader extension_class: extensionClass
815
attr_reader require_path: ::String
@@ -37,7 +44,7 @@ module ElasticGraph
3744
| (extensionClass, ::String, ::Hash[::Symbol | ::String, untyped], ?::String) -> Extension
3845

3946
def self.load_from_hash: (::Hash[::String, untyped], via: ExtensionLoader) -> Extension
40-
def to_dumpable_hash: () -> ::Hash[::String, untyped]
47+
def to_dumpable_hash: () -> extensionRefHash
4148

4249
def verify_against!: (extensionClass) -> void
4350
def verify_against: (extensionClass) -> ::Array[::String]

‎elasticgraph-schema_artifacts/sig/elastic_graph/schema_artifacts/runtime_metadata/graphql_resolver.rbs‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,21 @@ module ElasticGraph
33
module RuntimeMetadata
44
class GraphQLResolverSupertype
55
attr_reader needs_lookahead: bool
6-
attr_reader resolver_ref: ::Hash[::String, ::String]
6+
attr_reader resolver_ref: extensionRefHash
77

88
def initialize: (
99
needs_lookahead: bool,
10-
resolver_ref: ::Hash[::String, ::String]
10+
resolver_ref: extensionRefHash
1111
) -> void
1212

1313
def with: (
1414
?needs_lookahead: bool,
15-
?resolver_ref: ::Hash[::String, ::String]
15+
?resolver_ref: extensionRefHash
1616
) -> instance
1717

1818
def self.new:
19-
(needs_lookahead: bool, resolver_ref: ::Hash[::String, ::String]) -> instance
20-
| (bool, ::Hash[::String, ::String]) -> instance
19+
(needs_lookahead: bool, resolver_ref: extensionRefHash) -> instance
20+
| (bool, extensionRefHash) -> instance
2121
end
2222

2323
class GraphQLResolver < GraphQLResolverSupertype

‎elasticgraph-schema_artifacts/sig/elastic_graph/schema_artifacts/runtime_metadata/scalar_type.rbs‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@ module ElasticGraph
22
module SchemaArtifacts
33
module RuntimeMetadata
44
class ScalarTypeSupertype
5-
attr_reader coercion_adapter_ref: ::Hash[::String, ::String]
6-
attr_reader indexing_preparer_ref: ::Hash[::String, ::String]
5+
attr_reader coercion_adapter_ref: extensionRefHash
6+
attr_reader indexing_preparer_ref: extensionRefHash
77
attr_reader grouping_missing_value_placeholder: (::String | ::Numeric)?
88

99
def initialize: (
10-
coercion_adapter_ref: ::Hash[::String, ::String],
11-
indexing_preparer_ref: ::Hash[::String, ::String],
10+
coercion_adapter_ref: extensionRefHash,
11+
indexing_preparer_ref: extensionRefHash,
1212
grouping_missing_value_placeholder: (::String | ::Numeric)?
1313
) -> void
1414

1515
def with: (
16-
?coercion_adapter_ref: ::Hash[::String, ::String],
17-
?indexing_preparer_ref: ::Hash[::String, ::String],
16+
?coercion_adapter_ref: extensionRefHash,
17+
?indexing_preparer_ref: extensionRefHash,
1818
?grouping_missing_value_placeholder: (::String | ::Numeric)?
1919
) -> ScalarType
2020
end
@@ -26,8 +26,8 @@ module ElasticGraph
2626
self.@indexing_preparer_extension_loader: ExtensionLoader?
2727
def self.indexing_preparer_extension_loader: () -> ExtensionLoader
2828

29-
DEFAULT_COERCION_ADAPTER_REF: ::Hash[::String, ::String]
30-
DEFAULT_INDEXING_PREPARER_REF: ::Hash[::String, ::String]
29+
DEFAULT_COERCION_ADAPTER_REF: extensionRefHash
30+
DEFAULT_INDEXING_PREPARER_REF: extensionRefHash
3131

3232
def self.load_many: (::Hash[::String, ::Hash[::String, untyped]]) -> ::Hash[::String, ScalarType]
3333

0 commit comments

Comments
 (0)