Skip to content

Commit b80bef4

Browse files
committed
Add JSON ingestion indexing wrappers
1 parent 0a7ca8d commit b80bef4

11 files changed

Lines changed: 347 additions & 0 deletions

File tree

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Copyright 2024 - 2026 Block, Inc.
2+
#
3+
# Use of this source code is governed by an MIT-style
4+
# license that can be found in the LICENSE file or at
5+
# https://opensource.org/licenses/MIT.
6+
#
7+
# frozen_string_literal: true
8+
9+
module ElasticGraph
10+
module JSONIngestion
11+
module SchemaDefinition
12+
module Indexing
13+
# @!parse class FieldReference < ::Data; end
14+
FieldReference = ::Data.define(
15+
:field_reference,
16+
:json_schema_layers,
17+
:json_schema_customizations
18+
)
19+
20+
# A JSON-schema-aware wrapper around the core indexing field reference.
21+
#
22+
# @api private
23+
class FieldReference < ::Data
24+
# Resolves this field reference, or `nil` if unresolvable.
25+
#
26+
# @return [ElasticGraph::SchemaDefinition::Indexing::Field, nil]
27+
def resolve
28+
field_reference.resolve
29+
end
30+
31+
# @dynamic initialize, with, field_reference, json_schema_layers, json_schema_customizations
32+
end
33+
end
34+
end
35+
end
36+
end
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Copyright 2024 - 2026 Block, Inc.
2+
#
3+
# Use of this source code is governed by an MIT-style
4+
# license that can be found in the LICENSE file or at
5+
# https://opensource.org/licenses/MIT.
6+
#
7+
# frozen_string_literal: true
8+
9+
require "elastic_graph/schema_definition/indexing/field_type/enum"
10+
11+
module ElasticGraph
12+
module JSONIngestion
13+
module SchemaDefinition
14+
module Indexing
15+
# Namespace for JSON-ingestion indexing field type wrappers.
16+
module FieldType
17+
# JSON-ingestion indexing field type wrapper for enums.
18+
#
19+
# @private
20+
class Enum
21+
def self.wrap(field_type)
22+
new(field_type)
23+
end
24+
25+
def initialize(field_type)
26+
@field_type = field_type
27+
end
28+
29+
def enum_value_names
30+
@field_type.enum_value_names
31+
end
32+
33+
def to_mapping
34+
@field_type.to_mapping
35+
end
36+
end
37+
end
38+
end
39+
end
40+
end
41+
end
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Copyright 2024 - 2026 Block, Inc.
2+
#
3+
# Use of this source code is governed by an MIT-style
4+
# license that can be found in the LICENSE file or at
5+
# https://opensource.org/licenses/MIT.
6+
#
7+
# frozen_string_literal: true
8+
9+
require "elastic_graph/schema_definition/indexing/field_type/object"
10+
11+
module ElasticGraph
12+
module JSONIngestion
13+
module SchemaDefinition
14+
module Indexing
15+
module FieldType
16+
# JSON-ingestion indexing field type wrapper for objects.
17+
#
18+
# @private
19+
class Object
20+
def self.wrap(field_type, json_schema_options:)
21+
new(field_type)
22+
end
23+
24+
def initialize(field_type)
25+
@field_type = field_type
26+
end
27+
28+
def schema_def_state
29+
@field_type.schema_def_state
30+
end
31+
32+
def type_name
33+
@field_type.type_name
34+
end
35+
36+
def subfields
37+
@field_type.subfields
38+
end
39+
40+
def mapping_options
41+
@field_type.mapping_options
42+
end
43+
44+
def doc_comment
45+
@field_type.doc_comment
46+
end
47+
48+
def to_mapping
49+
@field_type.to_mapping
50+
end
51+
end
52+
end
53+
end
54+
end
55+
end
56+
end
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Copyright 2024 - 2026 Block, Inc.
2+
#
3+
# Use of this source code is governed by an MIT-style
4+
# license that can be found in the LICENSE file or at
5+
# https://opensource.org/licenses/MIT.
6+
#
7+
# frozen_string_literal: true
8+
9+
require "elastic_graph/schema_definition/indexing/field_type/scalar"
10+
11+
module ElasticGraph
12+
module JSONIngestion
13+
module SchemaDefinition
14+
module Indexing
15+
module FieldType
16+
# JSON-ingestion indexing field type wrapper for scalars.
17+
#
18+
# @private
19+
class Scalar
20+
def self.wrap(field_type)
21+
new(field_type)
22+
end
23+
24+
def initialize(field_type)
25+
@field_type = field_type
26+
end
27+
28+
def scalar_type
29+
@field_type.scalar_type
30+
end
31+
32+
def to_mapping
33+
@field_type.to_mapping
34+
end
35+
end
36+
end
37+
end
38+
end
39+
end
40+
end
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Copyright 2024 - 2026 Block, Inc.
2+
#
3+
# Use of this source code is governed by an MIT-style
4+
# license that can be found in the LICENSE file or at
5+
# https://opensource.org/licenses/MIT.
6+
#
7+
# frozen_string_literal: true
8+
9+
require "elastic_graph/schema_definition/indexing/field_type/union"
10+
11+
module ElasticGraph
12+
module JSONIngestion
13+
module SchemaDefinition
14+
module Indexing
15+
module FieldType
16+
# JSON-ingestion indexing field type wrapper for unions.
17+
#
18+
# @private
19+
class Union
20+
def self.wrap(field_type)
21+
new(field_type)
22+
end
23+
24+
def initialize(field_type)
25+
@field_type = field_type
26+
end
27+
28+
def subtypes_by_name
29+
@field_type.subtypes_by_name
30+
end
31+
32+
def to_mapping
33+
@field_type.to_mapping
34+
end
35+
end
36+
end
37+
end
38+
end
39+
end
40+
end
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
module ElasticGraph
2+
module JSONIngestion
3+
module SchemaDefinition
4+
module Indexing
5+
class FieldReference
6+
attr_reader field_reference: ::ElasticGraph::SchemaDefinition::Indexing::FieldReference
7+
attr_reader json_schema_layers: ::ElasticGraph::SchemaDefinition::jsonSchemaLayersArray
8+
attr_reader json_schema_customizations: ::Hash[::Symbol, untyped]
9+
10+
def initialize: (
11+
field_reference: ::ElasticGraph::SchemaDefinition::Indexing::FieldReference,
12+
json_schema_layers: ::ElasticGraph::SchemaDefinition::jsonSchemaLayersArray,
13+
json_schema_customizations: ::Hash[::Symbol, untyped]
14+
) -> void
15+
16+
def with: (
17+
?field_reference: ::ElasticGraph::SchemaDefinition::Indexing::FieldReference,
18+
?json_schema_layers: ::ElasticGraph::SchemaDefinition::jsonSchemaLayersArray,
19+
?json_schema_customizations: ::Hash[::Symbol, untyped]
20+
) -> FieldReference
21+
22+
def resolve: () -> ::ElasticGraph::SchemaDefinition::Indexing::Field?
23+
end
24+
end
25+
end
26+
end
27+
end
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
module ElasticGraph
2+
module JSONIngestion
3+
module SchemaDefinition
4+
module Indexing
5+
interface _EnumFieldType
6+
def enum_value_names: () -> ::Array[::String]
7+
end
8+
9+
interface _ObjectFieldType
10+
def schema_def_state: () -> ::ElasticGraph::SchemaDefinition::State
11+
def type_name: () -> ::String
12+
def subfields: () -> ::Array[::ElasticGraph::SchemaDefinition::Indexing::Field]
13+
def mapping_options: () -> ::ElasticGraph::SchemaDefinition::Mixins::HasTypeInfo::optionsHash
14+
def doc_comment: () -> ::String?
15+
end
16+
17+
interface _ScalarFieldType
18+
def scalar_type: () -> ::ElasticGraph::SchemaDefinition::SchemaElements::ScalarType
19+
end
20+
21+
interface _UnionFieldType
22+
def subtypes_by_name: () -> ::Hash[::String, ::Object]
23+
end
24+
end
25+
end
26+
end
27+
end
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
module ElasticGraph
2+
module JSONIngestion
3+
module SchemaDefinition
4+
module Indexing
5+
module FieldType
6+
class Enum
7+
include _EnumFieldType
8+
9+
@field_type: ::ElasticGraph::SchemaDefinition::Indexing::FieldType::Enum
10+
11+
def self.wrap: (::ElasticGraph::SchemaDefinition::Indexing::FieldType::Enum) -> Enum
12+
def initialize: (::ElasticGraph::SchemaDefinition::Indexing::FieldType::Enum) -> void
13+
def to_mapping: () -> ::Hash[::String, untyped]
14+
end
15+
end
16+
end
17+
end
18+
end
19+
end
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
module ElasticGraph
2+
module JSONIngestion
3+
module SchemaDefinition
4+
module Indexing
5+
module FieldType
6+
class Object
7+
include _ObjectFieldType
8+
9+
@field_type: ::ElasticGraph::SchemaDefinition::Indexing::FieldType::Object
10+
11+
def self.wrap: (
12+
::ElasticGraph::SchemaDefinition::Indexing::FieldType::Object,
13+
json_schema_options: ::Hash[::Symbol, untyped]
14+
) -> Object
15+
16+
def initialize: (::ElasticGraph::SchemaDefinition::Indexing::FieldType::Object) -> void
17+
def to_mapping: () -> ::Hash[::String, untyped]
18+
end
19+
end
20+
end
21+
end
22+
end
23+
end
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
module ElasticGraph
2+
module JSONIngestion
3+
module SchemaDefinition
4+
module Indexing
5+
module FieldType
6+
class Scalar
7+
include _ScalarFieldType
8+
9+
@field_type: ::ElasticGraph::SchemaDefinition::Indexing::FieldType::Scalar
10+
11+
def self.wrap: (::ElasticGraph::SchemaDefinition::Indexing::FieldType::Scalar) -> Scalar
12+
def initialize: (::ElasticGraph::SchemaDefinition::Indexing::FieldType::Scalar) -> void
13+
def to_mapping: () -> ::Hash[::String, untyped]
14+
end
15+
end
16+
end
17+
end
18+
end
19+
end

0 commit comments

Comments
 (0)