call method

Future<Map<String, dynamic>> call({
  1. required Map<String, RuleNode> nodes,
  2. required Map<String, dynamic> context,
})

Implementation

Future<Map<String, dynamic>> call({
  required Map<String, RuleNode> nodes,
  required Map<String, dynamic> context,
}) async {
  resetLoops();

  final rootNode = getRootNode(nodes);
  if (rootNode == null) {
    throw Exception("No root node found");
  }

  try {
    // Execute the root node
    final result = await callNode(
      nodeId: rootNode.id,
      nodes: nodes,
      context: context,
    );

    // Process any output connections
    final outputs = await resolveOutputs(
      nodeId: rootNode.id,
      nodes: nodes,
      context: context,
    );

    return {
      ...result,
      if (outputs.isNotEmpty) 'outputs': outputs,
    };
  } catch (e) {
    if (e is LoopError) {
      rethrow;
    }
    throw Exception("Rules execution failed: $e");
  }
}