Remove alteration models and interfaces; refactor to use JsonObject.

This commit deletes all alteration-related models and the `IAlteration` interface in favor of using `JsonObject`. Adjustments were made to `AlterationPlan`, `AlterationPlanParams`, and `RunRequest` to replace `IAlteration` collections with `JsonObject`. Simplified the `RefitSettingsHelper` by eliminating polymorphism configuration for alterations.
This commit is contained in:
Sipke Schoorstra 2025-02-08 09:45:50 +01:00
parent 0e4a74bfba
commit e719bd7c7d
11 changed files with 7 additions and 117 deletions

View file

@ -1,9 +1,6 @@
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Text.Json.Serialization.Metadata;
using Elsa.Api.Client.Converters;
using Elsa.Api.Client.Resources.Alterations.Contracts;
using Elsa.Api.Client.Resources.Alterations.Models;
using Refit;
namespace Elsa.Api.Client;
@ -36,30 +33,7 @@ public static class RefitSettingsHelper
options.Converters.Add(new JsonStringEnumConverter());
options.Converters.Add(new VersionOptionsJsonConverter());
options.Converters.Add(new TypeJsonConverter());
var alterationTypes = new[] { typeof(Cancel) };
options.TypeInfoResolver = new DefaultJsonTypeInfoResolver()
.WithAddedModifier(typeInfo =>
{
if (typeInfo.Type != typeof(IAlteration))
return;
if (typeInfo.Kind != JsonTypeInfoKind.Object)
return;
var polymorphismOptions = new JsonPolymorphismOptions { TypeDiscriminatorPropertyName = "type" };
foreach (var alterationType in alterationTypes.ToList())
{
polymorphismOptions.DerivedTypes.Add(new(alterationType, alterationType.Name));
}
typeInfo.PolymorphismOptions = polymorphismOptions;
});
configureJsonSerializerOptions?.Invoke(serviceProvider, options);
return options;
}
}

View file

@ -1,6 +0,0 @@
namespace Elsa.Api.Client.Resources.Alterations.Contracts;
/// <summary>
/// Marker interface for all alteration classes
/// </summary>
public interface IAlteration;

View file

@ -1,8 +0,0 @@
using Elsa.Api.Client.Resources.Alterations.Contracts;
namespace Elsa.Api.Client.Resources.Alterations.Models;
/// <summary>
/// A base class for all IAlterations.
/// </summary>
public abstract class AlterationBase : IAlteration;

View file

@ -1,4 +1,4 @@
using Elsa.Api.Client.Resources.Alterations.Contracts;
using System.Text.Json.Nodes;
using Elsa.Api.Client.Resources.Alterations.Enums;
using Elsa.Api.Client.Shared.Models;
@ -12,7 +12,7 @@ public class AlterationPlan : Entity
/// <summary>
/// The alterations to be applied.
/// </summary>
public ICollection<IAlteration> Alterations { get; set; } = new List<IAlteration>();
public ICollection<JsonObject> Alterations { get; set; } = new List<JsonObject>();
/// <summary>
/// The IDs of the workflow instances that this plan applies to.

View file

@ -1,4 +1,4 @@
using Elsa.Api.Client.Resources.Alterations.Contracts;
using System.Text.Json.Nodes;
namespace Elsa.Api.Client.Resources.Alterations.Models;
@ -15,7 +15,7 @@ public class AlterationPlanParams
/// <summary>
/// The alterations to be applied.
/// </summary>
public ICollection<IAlteration> Alterations { get; set; } = new List<IAlteration>();
public ICollection<JsonObject> Alterations { get; set; } = new List<JsonObject>();
/// <summary>
/// The IDs of the workflow instances that this plan applies to.

View file

@ -1,6 +0,0 @@
namespace Elsa.Api.Client.Resources.Alterations.Models;
/// <summary>
/// Cancels the workflow instances in an alteration plan.
/// </summary>
public class Cancel : AlterationBase;

View file

@ -1,17 +0,0 @@
namespace Elsa.Api.Client.Resources.Alterations.Models;
/// <summary>
/// Cancels a workflow instance activity during an alteration
/// </summary>
public class CancelActivity : AlterationBase
{
/// <summary>
/// The ID of the activity to be cancelled. If not specified, the activity instance ID will be used.
/// </summary>
public string? ActivityId { get; set; }
/// <summary>
/// The ID of the activity instance to be cancelled. If specified, overrides <see cref="ActivityId"/>.
/// </summary>
public string? ActivityInstanceId { get; set; }
}

View file

@ -1,12 +0,0 @@
namespace Elsa.Api.Client.Resources.Alterations.Models;
/// <summary>
/// Migrates a workflow instance to a newer version in an alteration.
/// </summary>
public class Migrate : AlterationBase
{
/// <summary>
/// The target version to upgrade to.
/// </summary>
public int TargetVersion { get; set; }
}

View file

@ -1,18 +0,0 @@
namespace Elsa.Api.Client.Resources.Alterations.Models;
/// <summary>
/// Modifies a variable in a workflow instance alteration
/// </summary>
public class ModifyVariable : AlterationBase
{
/// <summary>
/// The ID of the variable to modify.
/// </summary>
public string VariableId { get; set; } = default!;
/// <summary>
/// The new value of the variable.
/// </summary>
public object? Value { get; set; }
}

View file

@ -1,17 +0,0 @@
namespace Elsa.Api.Client.Resources.Alterations.Models;
/// <summary>
/// Schedules an activity for execution in an alteration.
/// </summary>
public class ScheduleActivity : AlterationBase
{
/// <summary>
/// The ID of the next activity to be scheduled. If not specified, the ActivityInstanceId will be used.
/// </summary>
public string? ActivityId { get; set; }
/// <summary>
/// The ID of the activity instance to be scheduled. If not specified, the ActivityId will be used.
/// </summary>
public string? ActivityInstanceId { get; set; }
}

View file

@ -1,4 +1,4 @@
using Elsa.Api.Client.Resources.Alterations.Contracts;
using System.Text.Json.Nodes;
namespace Elsa.Api.Client.Resources.Alterations.Responses;
@ -10,7 +10,7 @@ public class RunRequest
/// <summary>
/// The alterations to be applied.
/// </summary>
public ICollection<IAlteration> Alterations { get; set; } = new List<IAlteration>();
public ICollection<JsonObject> Alterations { get; set; } = new List<JsonObject>();
/// <summary>
/// The IDs of the workflow instances that this plan applies to.