Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
# frozen_string_literal: true

require "elastic_graph/constants"
require "elastic_graph/json_ingestion/schema_definition/deprecated_element"
require "elastic_graph/json_ingestion/schema_definition/factory_extension"
require "elastic_graph/json_ingestion/schema_definition/state_extension"

Expand Down Expand Up @@ -143,28 +142,6 @@ def json_schema_strictness(allow_omitted_fields: false, allow_extra_fields: true
nil
end

# Registers the name of a type that existed in a prior JSON schema version but has been deleted.
#
# @note In situations where this API applies, ElasticGraph will give you an error message indicating that you need to use this API
# or {SchemaElements::TypeWithSubfieldsExtension#renamed_from}. Likewise, when ElasticGraph no longer needs to know about this,
# it'll give you a warning indicating the call to this method can be removed.
#
# @param name [String] name of type that used to exist but has been deleted
# @return [void]
#
# @example Indicate that `Widget` has been deleted
# ElasticGraph.define_schema do |schema|
# schema.deleted_type "Widget"
# end
def deleted_type(name)
json_ingestion_state.register_deleted_type(
name,
defined_at: caller_locations(1, 1).to_a.first, # : ::Thread::Backtrace::Location
defined_via: %(schema.deleted_type "#{name}")
)
nil
end

private

# Returns the API's `state` narrowed to include this gem's `StateExtension`. Centralizes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,11 @@ class Merger
attr_reader :unused_deprecated_elements

def initialize(schema_def_results)
json_ingestion_state = schema_def_results.state # : ::ElasticGraph::SchemaDefinition::State & SchemaDefinition::StateExtension
@field_metadata_by_type_and_field_name = schema_def_results.json_schema_field_metadata_by_type_and_field_name
@renamed_types_by_old_name = json_ingestion_state.renamed_types_by_old_name
@deleted_types_by_old_name = json_ingestion_state.deleted_types_by_old_name
@renamed_fields_by_type_name_and_old_field_name = json_ingestion_state.renamed_fields_by_type_name_and_old_field_name
@deleted_fields_by_type_name_and_old_field_name = json_ingestion_state.deleted_fields_by_type_name_and_old_field_name
@renamed_types_by_old_name = schema_def_results.state.renamed_types_by_old_name
@deleted_types_by_old_name = schema_def_results.state.deleted_types_by_old_name
@renamed_fields_by_type_name_and_old_field_name = schema_def_results.state.renamed_fields_by_type_name_and_old_field_name
@deleted_fields_by_type_name_and_old_field_name = schema_def_results.state.deleted_fields_by_type_name_and_old_field_name
@state = schema_def_results.state
@derived_indexing_type_names = schema_def_results.derived_indexing_type_names

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,33 +90,6 @@ def json_schema(nullable: nil, **options)
super(**options)
end

# Registers an old name that this field used to have in a prior JSON schema version.
#
# @note In situations where this API applies, ElasticGraph will give you an error message indicating that you need to use this API
# or {TypeWithSubfieldsExtension#deleted_field}. Likewise, when ElasticGraph no longer needs to know about this, it'll give you a warning
# indicating the call to this method can be removed.
#
# @param old_name [String] old name this field used to have in a prior version of the schema
# @return [void]
#
# @example Indicate that `Widget.description` used to be called `Widget.notes`.
# ElasticGraph.define_schema do |schema|
# schema.object_type "Widget" do |t|
# t.field "description", "String" do |f|
# f.renamed_from "notes"
# end
# end
# end
def renamed_from(old_name)
json_ingestion_state.register_renamed_field(
parent_type.name,
from: old_name,
to: name,
defined_at: caller_locations(1, 1).to_a.first, # : ::Thread::Backtrace::Location
defined_via: %(field.renamed_from "#{old_name}")
)
end

# @private
def to_indexing_field_reference
reference = super
Expand All @@ -131,12 +104,6 @@ def to_indexing_field_reference
doc_comment: doc_comment
)
end

private

def json_ingestion_state
schema_def_state # : ::ElasticGraph::SchemaDefinition::State & SchemaDefinition::StateExtension
end
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,67 +16,13 @@ module SchemaElements
module TypeWithSubfieldsExtension
include HasJSONSchema

# Registers the name of a field that existed in a prior JSON schema version but has been deleted.
#
# @note In situations where this API applies, ElasticGraph will give you an error message indicating that you need to use this API
# or {FieldExtension#renamed_from}. Likewise, when ElasticGraph no longer needs to know about this, it'll give you a warning
# indicating the call to this method can be removed.
#
# @param field_name [String] name of field that used to exist but has been deleted
# @return [void]
#
# @example Indicate that `Widget.description` has been deleted
# ElasticGraph.define_schema do |schema|
# schema.object_type "Widget" do |t|
# t.deleted_field "description"
# end
# end
def deleted_field(field_name)
json_ingestion_state.register_deleted_field(
name,
field_name,
defined_at: caller_locations(2, 1).to_a.first, # : ::Thread::Backtrace::Location
defined_via: %(type.deleted_field "#{field_name}")
)
end

# Registers an old name that this type used to have in a prior JSON schema version.
#
# @note In situations where this API applies, ElasticGraph will give you an error message indicating that you need to use this API
# or {APIExtension#deleted_type}. Likewise, when ElasticGraph no longer needs to know about this, it'll give you a warning
# indicating the call to this method can be removed.
#
# @param old_name [String] old name this type used to have in a prior version of the schema
# @return [void]
#
# @example Indicate that `Widget` used to be called `Component`.
# ElasticGraph.define_schema do |schema|
# schema.object_type "Widget" do |t|
# t.renamed_from "Component"
# end
# end
def renamed_from(old_name)
json_ingestion_state.register_renamed_type(
name,
from: old_name,
defined_at: caller_locations(2, 1).to_a.first, # : ::Thread::Backtrace::Location
defined_via: %(type.renamed_from "#{old_name}")
)
end

# @private
def to_indexing_field_type
field_type = super # : Indexing::FieldType::Object
field_type.json_schema_options = json_schema_options
field_type.doc_comment = doc_comment
field_type
end

private

def json_ingestion_state
schema_def_state # : ::ElasticGraph::SchemaDefinition::State & SchemaDefinition::StateExtension
end
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
#
# frozen_string_literal: true

require "elastic_graph/json_ingestion/schema_definition/deprecated_element"

module ElasticGraph
module JSONIngestion
module SchemaDefinition
Expand All @@ -20,61 +18,14 @@ module StateExtension
# @dynamic enforce_json_schema_version, enforce_json_schema_version=
# @dynamic allow_omitted_json_schema_fields, allow_omitted_json_schema_fields=
# @dynamic allow_extra_json_schema_fields, allow_extra_json_schema_fields=
# @dynamic renamed_types_by_old_name, renamed_types_by_old_name=
# @dynamic deleted_types_by_old_name, deleted_types_by_old_name=
# @dynamic renamed_fields_by_type_name_and_old_field_name, renamed_fields_by_type_name_and_old_field_name=
# @dynamic deleted_fields_by_type_name_and_old_field_name, deleted_fields_by_type_name_and_old_field_name=
attr_accessor :json_schema_version, :json_schema_version_setter_location, :enforce_json_schema_version, :allow_omitted_json_schema_fields, :allow_extra_json_schema_fields,
:renamed_types_by_old_name, :deleted_types_by_old_name, :renamed_fields_by_type_name_and_old_field_name, :deleted_fields_by_type_name_and_old_field_name
attr_accessor :json_schema_version, :json_schema_version_setter_location, :enforce_json_schema_version, :allow_omitted_json_schema_fields, :allow_extra_json_schema_fields

def self.extended(state)
state.json_schema_version = nil
state.json_schema_version_setter_location = nil
state.enforce_json_schema_version = true
state.allow_omitted_json_schema_fields = false
state.allow_extra_json_schema_fields = true
state.renamed_types_by_old_name = {}
state.deleted_types_by_old_name = {}
state.renamed_fields_by_type_name_and_old_field_name = ::Hash.new { |h, k| h[k] = {} }
state.deleted_fields_by_type_name_and_old_field_name = ::Hash.new { |h, k| h[k] = {} }
end

def register_renamed_type(type_name, from:, defined_at:, defined_via:)
renamed_types_by_old_name[from] = DeprecatedElement.new(
schema_def_state: self,
name: type_name,
defined_at: defined_at,
defined_via: defined_via
)
end

def register_deleted_type(type_name, defined_at:, defined_via:)
deleted_types_by_old_name[type_name] = DeprecatedElement.new(
schema_def_state: self,
name: type_name,
defined_at: defined_at,
defined_via: defined_via
)
end

def register_renamed_field(type_name, from:, to:, defined_at:, defined_via:)
renamed_fields_by_old_field_name = renamed_fields_by_type_name_and_old_field_name[type_name]
renamed_fields_by_old_field_name[from] = DeprecatedElement.new(
schema_def_state: self,
name: to,
defined_at: defined_at,
defined_via: defined_via
)
end

def register_deleted_field(type_name, field_name, defined_at:, defined_via:)
deleted_fields_by_old_field_name = deleted_fields_by_type_name_and_old_field_name[type_name]
deleted_fields_by_old_field_name[field_name] = DeprecatedElement.new(
schema_def_state: self,
name: field_name,
defined_at: defined_at,
defined_via: defined_via
)
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ module ElasticGraph
def json_schema_version: (::Integer) -> void
def enforce_json_schema_version: (bool) -> void
def json_schema_strictness: (?allow_omitted_fields: bool, ?allow_extra_fields: bool) -> void
def deleted_type: (::String) -> void

def self.extended: (::ElasticGraph::SchemaDefinition::API & APIExtension) -> void

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,22 @@ module ElasticGraph
attr_reader json_schema: ::Hash[::String, untyped]
attr_reader missing_fields: ::Set[::String]
attr_reader missing_types: ::Set[::String]
attr_reader definition_conflicts: ::Set[ElasticGraph::JSONIngestion::SchemaDefinition::DeprecatedElement]
attr_reader definition_conflicts: ::Set[ElasticGraph::SchemaDefinition::SchemaElements::DeprecatedElement]
attr_reader missing_necessary_fields: ::Array[JSONSchemaWithMetadata::MissingNecessaryField]

def initialize: (
json_schema: ::Hash[::String, untyped],
missing_fields: ::Set[::String],
missing_types: ::Set[::String],
definition_conflicts: ::Set[ElasticGraph::JSONIngestion::SchemaDefinition::DeprecatedElement],
definition_conflicts: ::Set[ElasticGraph::SchemaDefinition::SchemaElements::DeprecatedElement],
missing_necessary_fields: ::Array[JSONSchemaWithMetadata::MissingNecessaryField]
) -> void

def with: (
?json_schema: ::Hash[::String, untyped],
?missing_fields: ::Set[::String],
?missing_types: ::Set[::String],
?definition_conflicts: ::Set[ElasticGraph::JSONIngestion::SchemaDefinition::DeprecatedElement],
?definition_conflicts: ::Set[ElasticGraph::SchemaDefinition::SchemaElements::DeprecatedElement],
?missing_necessary_fields: ::Array[JSONSchemaWithMetadata::MissingNecessaryField]
) -> instance
end
Expand All @@ -31,14 +31,14 @@ module ElasticGraph

class Merger
@field_metadata_by_type_and_field_name: ::Hash[::String, ::Hash[::String, JSONSchemaFieldMetadata]]
@renamed_types_by_old_name: ::Hash[::String, ElasticGraph::JSONIngestion::SchemaDefinition::DeprecatedElement]
@deleted_types_by_old_name: ::Hash[::String, ElasticGraph::JSONIngestion::SchemaDefinition::DeprecatedElement]
@renamed_fields_by_type_name_and_old_field_name: ::Hash[::String, ::Hash[::String, ElasticGraph::JSONIngestion::SchemaDefinition::DeprecatedElement]]
@deleted_fields_by_type_name_and_old_field_name: ::Hash[::String, ::Hash[::String, ElasticGraph::JSONIngestion::SchemaDefinition::DeprecatedElement]]
@renamed_types_by_old_name: ::Hash[::String, ElasticGraph::SchemaDefinition::SchemaElements::DeprecatedElement]
@deleted_types_by_old_name: ::Hash[::String, ElasticGraph::SchemaDefinition::SchemaElements::DeprecatedElement]
@renamed_fields_by_type_name_and_old_field_name: ::Hash[::String, ::Hash[::String, ElasticGraph::SchemaDefinition::SchemaElements::DeprecatedElement]]
@deleted_fields_by_type_name_and_old_field_name: ::Hash[::String, ::Hash[::String, ElasticGraph::SchemaDefinition::SchemaElements::DeprecatedElement]]
@state: ElasticGraph::SchemaDefinition::State
@derived_indexing_type_names: ::Set[::String]

attr_reader unused_deprecated_elements: ::Set[ElasticGraph::JSONIngestion::SchemaDefinition::DeprecatedElement]
attr_reader unused_deprecated_elements: ::Set[ElasticGraph::SchemaDefinition::SchemaElements::DeprecatedElement]

def initialize: ((ElasticGraph::SchemaDefinition::Results & ResultsExtension)) -> void
def merge_metadata_into: (::Hash[::String, untyped]) -> JSONSchemaWithMetadata
Expand All @@ -48,14 +48,14 @@ module ElasticGraph
def determine_current_type_name: (
::String,
missing_types: ::Set[::String],
definition_conflicts: ::Set[ElasticGraph::JSONIngestion::SchemaDefinition::DeprecatedElement]
definition_conflicts: ::Set[ElasticGraph::SchemaDefinition::SchemaElements::DeprecatedElement]
) -> ::String?

def field_metadata_for: (
::String,
::String,
missing_fields: ::Set[::String],
definition_conflicts: ::Set[ElasticGraph::JSONIngestion::SchemaDefinition::DeprecatedElement]
definition_conflicts: ::Set[ElasticGraph::SchemaDefinition::SchemaElements::DeprecatedElement]
) -> JSONSchemaFieldMetadata?

def identify_missing_necessary_fields: (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ module ElasticGraph
def initialize: (io) -> void

def report_errors: (::Array[Indexing::JSONSchemaWithMetadata]) -> void
def report_warnings: (::Set[::ElasticGraph::JSONIngestion::SchemaDefinition::DeprecatedElement]) -> void
def report_warnings: (::Set[::ElasticGraph::SchemaDefinition::SchemaElements::DeprecatedElement]) -> void

private

@output: io

def format_deprecated_elements: (::Enumerable[::ElasticGraph::JSONIngestion::SchemaDefinition::DeprecatedElement]) -> ::String
def format_deprecated_elements: (::Enumerable[::ElasticGraph::SchemaDefinition::SchemaElements::DeprecatedElement]) -> ::String
def missing_field_error_for: (::String, ::Array[::Integer]) -> ::String
def missing_type_error_for: (::String, ::Array[::Integer]) -> ::String
def missing_necessary_field_error_for: (Indexing::JSONSchemaWithMetadata::MissingNecessaryField, ::Array[::Integer]) -> ::String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module ElasticGraph
def json_schema_field_metadata_by_type_and_field_name: () -> ::Hash[::String, ::Hash[::String, Indexing::JSONSchemaFieldMetadata]]
def current_public_json_schema: () -> ::Hash[::String, untyped]
def merge_field_metadata_into_json_schema: (::Hash[::String, untyped]) -> Indexing::JSONSchemaWithMetadata
def unused_deprecated_elements: () -> ::Set[::ElasticGraph::JSONIngestion::SchemaDefinition::DeprecatedElement]
def unused_deprecated_elements: () -> ::Set[::ElasticGraph::SchemaDefinition::SchemaElements::DeprecatedElement]

private

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,7 @@ module ElasticGraph

def non_nullable_in_json_schema?: () -> bool
def json_schema: (?nullable: bool?, **untyped) -> void
def renamed_from: (::String) -> void
def to_indexing_field_reference: () -> Indexing::FieldReference?

private

def json_ingestion_state: () -> (::ElasticGraph::SchemaDefinition::State & SchemaDefinition::StateExtension)
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,7 @@ module ElasticGraph
module TypeWithSubfieldsExtension: ::ElasticGraph::SchemaDefinition::SchemaElements::TypeWithSubfields
include HasJSONSchema

def deleted_field: (::String) -> void
def renamed_from: (::String) -> void
def to_indexing_field_type: () -> Indexing::FieldType::Object

private

def json_ingestion_state: () -> (::ElasticGraph::SchemaDefinition::State & SchemaDefinition::StateExtension)
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,8 @@ module ElasticGraph
attr_accessor enforce_json_schema_version: bool
attr_accessor allow_omitted_json_schema_fields: bool
attr_accessor allow_extra_json_schema_fields: bool
attr_accessor renamed_types_by_old_name: ::Hash[::String, DeprecatedElement]
attr_accessor deleted_types_by_old_name: ::Hash[::String, DeprecatedElement]
attr_accessor renamed_fields_by_type_name_and_old_field_name: ::Hash[::String, ::Hash[::String, DeprecatedElement]]
attr_accessor deleted_fields_by_type_name_and_old_field_name: ::Hash[::String, ::Hash[::String, DeprecatedElement]]

def self.extended: (::ElasticGraph::SchemaDefinition::State & StateExtension) -> void
def register_renamed_type: (::String, from: ::String, defined_at: ::Thread::Backtrace::Location, defined_via: ::String) -> void
def register_deleted_type: (::String, defined_at: ::Thread::Backtrace::Location, defined_via: ::String) -> void
def register_renamed_field: (::String, from: ::String, to: ::String, defined_at: ::Thread::Backtrace::Location, defined_via: ::String) -> void
def register_deleted_field: (::String, ::String, defined_at: ::Thread::Backtrace::Location, defined_via: ::String) -> void
end
end
end
Expand Down
Loading