Skip to content
Merged
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
4 changes: 2 additions & 2 deletions app/graphql/types/input/node_function_input_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ class NodeFunctionInputType < Types::BaseInputObject
argument :id, Types::GlobalIdType[::NodeFunction],
required: true, description: 'The identifier of the Node Function used to create/update the flow'

argument :runtime_function_id, Types::GlobalIdType[::RuntimeFunctionDefinition],
required: true, description: 'The identifier of the Runtime Function Definition'
argument :function_definition_id, Types::GlobalIdType[::FunctionDefinition],
required: true, description: 'The identifier of the Function Definition'

argument :next_node_id, Types::GlobalIdType[::NodeFunction], required: false,
description: 'The next Node Function in the flow'
Expand Down
4 changes: 2 additions & 2 deletions app/graphql/types/input/node_parameter_input_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ module Input
class NodeParameterInputType < Types::BaseInputObject
description 'Input type for Node parameter'

argument :runtime_parameter_definition_id, Types::GlobalIdType[::RuntimeParameterDefinition],
required: true, description: 'The identifier of the Runtime Parameter Definition'
argument :parameter_definition_id, Types::GlobalIdType[::ParameterDefinition],
required: true, description: 'The identifier of the Parameter Definition'

argument :value, Types::Input::NodeParameterValueInputType, required: false,
description: 'The value of the parameter'
Expand Down
7 changes: 4 additions & 3 deletions app/graphql/types/literal_value_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ module Types
class LiteralValueType < Types::BaseObject
description 'Represents a literal value, such as a string or number.'

authorize :read_datatype

field :value, GraphQL::Types::JSON, null: false, description: 'The literal value itself as JSON.'
field :value, GraphQL::Types::JSON,
null: false,
description: 'The literal value itself as JSON.',
method: :itself

timestamps
end
Expand Down
1 change: 0 additions & 1 deletion app/graphql/types/node_function_id_wrapper_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ module Types
class NodeFunctionIdWrapperType < Types::BaseObject
description 'Represents a Node Function id wrapper.'

authorize :read_flow
id_field NodeFunction
end
end
4 changes: 2 additions & 2 deletions app/graphql/types/node_parameter_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ class NodeParameterType < Types::BaseObject

authorize :read_flow

field :runtime_parameter, Types::RuntimeParameterDefinitionType, null: false,
description: 'The definition of the parameter'
field :parameter_definition, Types::ParameterDefinitionType, null: false,
description: 'The definition of the parameter'
field :value, Types::NodeParameterValueType, null: true, description: 'The value of the parameter'

def value
Expand Down
2 changes: 0 additions & 2 deletions app/graphql/types/reference_path_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ module Types
class ReferencePathType < Types::BaseObject
description 'Represents a reference path in a flow'

authorize :read_flow

field :array_index, Integer, null: true, description: 'The array index of the referenced data by the path'
field :path, String, null: true, description: 'The path to the reference in the flow'

Expand Down
12 changes: 8 additions & 4 deletions app/graphql/types/reference_value_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ module Types
class ReferenceValueType < Types::BaseObject
description 'Represents a reference value in the system.'

authorize :read_flow

field :node_function_id, GlobalIdType[::NodeFunction], null: false, description: 'The referenced value.'

field :data_type_identifier, Types::DataTypeIdentifierType,
Expand All @@ -15,10 +13,16 @@ class ReferenceValueType < Types::BaseObject
field :node, Int, null: false, description: 'The node of the reference value.'
field :scope, [Int], null: false, description: 'The scope of the reference value.'

field :reference_path, [Types::ReferencePathType], null: false,
description: 'The paths associated with this reference value.'
field :reference_path, [Types::ReferencePathType],
null: false,
description: 'The paths associated with this reference value.',
method: :reference_paths

id_field ReferenceValue
timestamps

def node_function_id
object.node_function.to_global_id
end
end
end
1 change: 1 addition & 0 deletions app/models/function_definition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class FunctionDefinition < ApplicationRecord
belongs_to :runtime_function_definition
belongs_to :return_type, class_name: 'DataTypeIdentifier', optional: true

has_many :node_functions, inverse_of: :function_definition
has_many :parameter_definitions, inverse_of: :function_definition

has_many :names, -> { by_purpose(:name) }, class_name: 'Translation', as: :owner, inverse_of: :owner
Expand Down
8 changes: 5 additions & 3 deletions app/models/node_function.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

class NodeFunction < ApplicationRecord
belongs_to :runtime_function, class_name: 'RuntimeFunctionDefinition'
belongs_to :function_definition, inverse_of: :node_functions
belongs_to :next_node, class_name: 'NodeFunction', optional: true
belongs_to :flow, class_name: 'Flow'

Expand All @@ -16,7 +16,9 @@ class NodeFunction < ApplicationRecord

has_many :node_parameters,
class_name: 'NodeParameter',
inverse_of: :node_function
inverse_of: :node_function,
dependent: :destroy,
autosave: true

validate :validate_recursion, if: :next_node_changed?

Expand All @@ -35,7 +37,7 @@ def validate_recursion
def to_grpc
Tucana::Shared::NodeFunction.new(
database_id: id,
runtime_function_id: runtime_function.runtime_name,
runtime_function_id: function_definition.runtime_function_definition.runtime_name,
parameters: node_parameters.map(&:to_grpc),
next_node_id: next_node&.id
)
Expand Down
6 changes: 3 additions & 3 deletions app/models/node_parameter.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# frozen_string_literal: true

class NodeParameter < ApplicationRecord
belongs_to :runtime_parameter, class_name: 'RuntimeParameterDefinition'
belongs_to :reference_value, optional: true
belongs_to :parameter_definition, inverse_of: :node_parameters
belongs_to :reference_value, optional: true, autosave: true
belongs_to :function_value, class_name: 'NodeFunction', optional: true, inverse_of: :node_parameter_values
belongs_to :node_function, class_name: 'NodeFunction', inverse_of: :node_parameters

Expand All @@ -11,7 +11,7 @@ class NodeParameter < ApplicationRecord
def to_grpc
param = Tucana::Shared::NodeParameter.new(
database_id: id,
runtime_parameter_id: runtime_parameter.runtime_name
runtime_parameter_id: parameter_definition.runtime_parameter_definition.runtime_name
)

param.value = Tucana::Shared::NodeValue.new(literal_value: Tucana::Shared::Value.from_ruby({}))
Expand Down
2 changes: 2 additions & 0 deletions app/models/parameter_definition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ class ParameterDefinition < ApplicationRecord

belongs_to :function_definition, inverse_of: :parameter_definitions

has_many :node_parameters, inverse_of: :parameter_definition

has_many :names, -> { by_purpose(:name) }, class_name: 'Translation', as: :owner, inverse_of: :owner
has_many :descriptions, -> { by_purpose(:description) }, class_name: 'Translation', as: :owner, inverse_of: :owner
has_many :documentations, -> { by_purpose(:documentation) }, class_name: 'Translation', as: :owner, inverse_of: :owner
Expand Down
2 changes: 1 addition & 1 deletion app/models/reference_value.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
class ReferenceValue < ApplicationRecord
belongs_to :node_function # real value association
belongs_to :data_type_identifier
has_many :reference_paths, inverse_of: :reference_value
has_many :reference_paths, inverse_of: :reference_value, autosave: true
has_many :node_parameters, inverse_of: :reference_value

def to_grpc
Expand Down
5 changes: 3 additions & 2 deletions app/services/error_code.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,9 @@ def self.error_codes
license_not_found: { description: 'The namespace license with the given identifier was not found' },
flow_type_not_found: { description: 'The flow type with the given identifier was not found' },
organization_not_found: { description: 'The organization with the given identifier was not found' },
invalid_runtime_function_id: { description: 'The runtime function ID is invalid' },
invalid_runtime_parameter_id: { description: 'The runtime parameter ID is invalid' },
invalid_function_id: { description: 'The function ID is invalid' },
invalid_parameter_id: { description: 'The parameter ID is invalid' },
invalid_reference_value: { description: 'The reference value is invalid' },
referenced_value_not_found: { description: 'A referenced value could not be found' },
invalid_runtime_parameter_definition: { description: 'The runtime parameter definition is invalid' },
invalid_runtime_function_definition: { description: 'The runtime function definition is invalid' },
Expand Down
29 changes: 17 additions & 12 deletions app/services/namespaces/projects/flows/update_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,11 @@ def update_nodes(t)
updated_nodes.each do |node|
update_node_parameters(t, node[:node], node[:input], updated_nodes)
update_next_node(t, node[:node], node[:input], updated_nodes)
end

# rubocop:disable Style/CombinableLoops -- this loop has to be separate
# A node can be invalid during the loop, but be valid again after all nodes have been processed
updated_nodes.each do |node|
next if node[:node].save

t.rollback_and_return! ServiceResponse.error(
Expand All @@ -99,6 +103,7 @@ def update_nodes(t)
details: node[:node].errors
)
end
# rubocop:enable Style/CombinableLoops

update_starting_node(t, updated_nodes)

Expand Down Expand Up @@ -133,17 +138,17 @@ def delete_old_nodes(t, remaining_nodes)
end

def update_node(t, current_node, current_node_input)
runtime_function_definition = flow.project.primary_runtime.runtime_function_definitions.find_by(
id: current_node_input.runtime_function_id.model_id
function_definition = flow.project.primary_runtime.function_definitions.find_by(
id: current_node_input.function_definition_id.model_id
)
if runtime_function_definition.nil?
if function_definition.nil?
t.rollback_and_return! ServiceResponse.error(
message: 'Invalid runtime function id',
error_code: :invalid_runtime_function_id
message: 'Invalid function id',
error_code: :invalid_function_id
)
end

current_node.runtime_function = runtime_function_definition
current_node.function_definition = function_definition
end

def update_next_node(t, current_node, current_node_input, all_nodes)
Expand All @@ -164,17 +169,17 @@ def update_node_parameters(t, current_node, current_node_input, all_nodes)
current_node_input.parameters.each_with_index do |parameter, index|
db_parameters[index] ||= current_node.node_parameters.build

runtime_parameter = current_node.runtime_function.parameters.find_by(
id: parameter.runtime_parameter_definition_id.model_id
parameter_definition = current_node.function_definition.parameter_definitions.find_by(
id: parameter.parameter_definition_id.model_id
)
if runtime_parameter.nil?
if parameter_definition.nil?
t.rollback_and_return! ServiceResponse.error(
message: 'Invalid runtime parameter id',
error_code: :invalid_runtime_parameter_id
message: 'Invalid parameter id',
error_code: :invalid_parameter_id
)
end

db_parameters[index].runtime_parameter = runtime_parameter
db_parameters[index].parameter_definition = parameter_definition

db_parameters[index].literal_value = parameter.value.literal_value

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ def execute
end

if data_type_identifier.generic_key.present?
unless node.runtime_function.generic_keys.include?(data_type_identifier.generic_key)
runtime_function_definition = node.function_definition.runtime_function_definition
unless runtime_function_definition.generic_keys.include?(data_type_identifier.generic_key)
errors << ValidationResult.error(
:data_type_identifier_generic_key_not_found,
location: data_type_identifier
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ def execute
target = generic_mapper.target

# Validate the target the identifier gets validated later
unless parameter.node_function.runtime_function.generic_keys.include?(target)
runtime_function_definition = parameter.node_function.function_definition.runtime_function_definition
unless runtime_function_definition.generic_keys.include?(target)
errors << ValidationResult.error(
:generic_key_not_found,
location: generic_mapper
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ def execute
location: parameter
)
end
if parameter.runtime_parameter.runtime_function_definition.runtime != flow.project.primary_runtime
runtime_parameter_definition = parameter.parameter_definition.runtime_parameter_definition
if runtime_parameter_definition.runtime_function_definition.runtime != flow.project.primary_runtime
errors << ValidationResult.error(
:node_parameter_runtime_mismatch,
location: parameter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ def execute
location: node_function
)
end
if node_function.runtime_function.runtime != flow.project.primary_runtime
if node_function.function_definition.runtime_function_definition.runtime != flow.project.primary_runtime
errors << ValidationResult.error(
:node_function_runtime_mismatch,
location: node_function
)
end

node_function.runtime_function.tap do |runtime_function|
node_function.function_definition.runtime_function_definition.tap do |runtime_function|
logger
.debug("Validating runtime function: #{runtime_function.id} for node function: #{node_function.id}")
if runtime_function.runtime != flow.project.primary_runtime
Expand All @@ -50,8 +50,9 @@ def execute

node_function.node_parameters.each do |parameter|
logger.debug("Validating node parameter: #{parameter.id} for function: #{node_function.id}")
parameter_function_definition = parameter.parameter_definition.function_definition

if parameter.runtime_parameter.runtime_function_definition != node_function.runtime_function
if parameter_function_definition != node_function.function_definition
logger.debug(message: 'Node parameter does not match its function',
node_function: node_function.id,
runtime_parameter: parameter.runtime_parameter.id,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# frozen_string_literal: true

class LinkNodeFunctionsToFunctionDefinitions < Code0::ZeroTrack::Database::Migration[1.0]
def change
# rubocop:disable Rails/NotNullColumn -- backwards compatibility intentionally ignored
add_reference :node_functions, :function_definition, null: false, foreign_key: { on_delete: :restrict }
# rubocop:enable Rails/NotNullColumn
remove_reference :node_functions, :runtime_function, null: false, foreign_key: {
on_delete: :restrict,
to_table: :runtime_function_definitions,
}
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# frozen_string_literal: true

class LinkNodeParametersToParameterDefinitions < Code0::ZeroTrack::Database::Migration[1.0]
def change
# rubocop:disable Rails/NotNullColumn -- backwards compatibility intentionally ignored
add_reference :node_parameters, :parameter_definition, null: false, foreign_key: { on_delete: :restrict }
# rubocop:enable Rails/NotNullColumn
remove_reference :node_parameters, :runtime_parameter, null: false, foreign_key: {
on_delete: :cascade,
to_table: :runtime_parameter_definitions,
}
end
end
1 change: 1 addition & 0 deletions db/schema_migrations/20260115182425
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
5b7050d1dd0f20888ecf4287f04de346d9d4e37a3dccc796d7d6682d9a2dfef4
1 change: 1 addition & 0 deletions db/schema_migrations/20260115184937
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
481a244e97396174f7937edda0e1d20d17c95b85f51f051daa0e1bcc590cf853
Loading