From 64255e6085536454c35bb629fa583082a4ab46b6 Mon Sep 17 00:00:00 2001 From: Charles d'Avernas Date: Wed, 22 May 2024 19:20:59 +0200 Subject: [PATCH 1/2] feat(Solution): Implemented Serverless Workflow version 1.0.0-alpha1 Signed-off-by: Charles d'Avernas --- .editorconfig | 4 +- .github/workflows/build-dotnet.yml | 52 ++ .github/workflows/ci-pipeline.yml | 35 + .github/workflows/dotnet.yml | 24 - .github/workflows/publish.yml | 26 + .github/workflows/release.yml | 39 + .github/workflows/test-dotnet.yml | 41 ++ .github/workflows/versioning.yml | 28 + README.md | 258 +------ ServerlessWorkflow.Sdk.sln | 42 +- .../AuthenticationPolicyDefinitionBuilder.cs | 65 ++ .../BackoffStrategyDefinitionBuilder.cs | 64 ++ ...icAuthenticationSchemeDefinitionBuilder.cs | 63 ++ ...erAuthenticationSchemeDefinitionBuilder.cs | 48 ++ .../CallTaskDefinitionBuilder.cs | 72 ++ .../CompositeTaskDefinitionBuilder.cs | 85 +++ .../ConstantBackoffDefinitionBuilder.cs} | 17 +- .../ContainerProcessDefinitionBuilder.cs | 132 ++++ .../EmitTaskDefinitionBuilder.cs | 62 ++ .../ErrorCatcherDefinitionBuilder.cs | 139 ++++ .../ErrorDefinitionBuilder.cs | 104 +++ .../ErrorFilterDefinitionBuilder.cs | 50 ++ .../EventDefinitionBuilder.cs | 50 ++ .../EventFilterDefinitionBuilder.cs | 50 ++ .../EventFilterDefinitionCollectionBuilder.cs | 58 ++ .../ExponentialBackoffDefinitionBuilder.cs | 31 + .../ExtensionDefinitionBuilder.cs | 92 +++ .../ExternalResourceDefinitionBuilder.cs | 100 +++ .../ForTaskDefinitionBuilder.cs | 95 +++ .../GenericTaskDefinitionBuilder.cs | 148 ++++ .../HttpCallDefinitionBuilder.cs | 155 ++++ .../IAuthenticationPolicyDefinitionBuilder.cs | 46 ++ .../IAuthenticationSchemeDefinitionBuilder.cs | 45 ++ .../Interfaces/IBackoffDefinitionBuilder.cs | 45 ++ .../IBackoffStrategyDefinitionBuilder.cs | 46 ++ ...icAuthenticationSchemeDefinitionBuilder.cs | 37 + ...rAuthenticationSchemeDefinitionBuilder.cs} | 19 +- .../Interfaces/ICallTaskDefinitionBuilder.cs | 44 ++ .../ICompositeTaskDefinitionBuilder.cs} | 14 +- .../IConstantBackoffDefinitionBuilder.cs} | 10 +- .../IContainerProcessDefinitionBuilder.cs | 82 +++ .../Interfaces/IEmitTaskDefinitionBuilder.cs | 37 + .../Interfaces/IEndpointDefinitionBuilder.cs | 69 ++ .../IErrorCatcherDefinitionBuilder.cs | 91 +++ .../Interfaces/IErrorDefinitionBuilder.cs | 63 ++ .../IErrorFilterDefinitionBuilder.cs | 43 ++ .../Interfaces/IEventDefinitionBuilder.cs | 43 ++ .../IEventFilterDefinitionBuilder.cs | 43 ++ ...IEventFilterDefinitionCollectionBuilder.cs | 44 ++ .../IExponentialBackoffDefinitionBuilder.cs} | 13 +- .../Interfaces/IExtensionDefinitionBuilder.cs | 78 ++ .../IExternalResourceDefinitionBuilder.cs | 36 + .../Interfaces/IForTaskDefinitionBuilder.cs | 51 ++ .../IGenericTaskDefinitionBuilder.cs | 121 +++ .../Interfaces/IHttpCallDefinitionBuilder.cs | 102 +++ .../Interfaces/IJitterDefinitionBuilder.cs | 42 ++ .../ILinearBackoffDefinitionBuilder.cs | 30 + .../IListenTaskDefinitionBuilder.cs | 30 + .../Interfaces/IListenerDefinitionBuilder.cs} | 25 +- .../IListenerTargetDefinitionBuilder.cs | 46 ++ ...h2AuthenticationClientDefinitionBuilder.cs | 42 ++ ...h2AuthenticationSchemeDefinitionBuilder.cs | 94 +++ .../Interfaces/IProcessDefinitionBuilder.cs | 45 ++ .../Interfaces/IRaiseTaskDefinitionBuilder.cs | 36 + .../IRetryAttemptLimitDefinitionBuilder.cs | 42 ++ .../IRetryPolicyDefinitionBuilder.cs | 91 +++ .../IRetryPolicyLimitDefinitionBuilder.cs | 41 ++ .../Interfaces/IRunTaskDefinitionBuilder.cs | 47 ++ .../IScriptProcessDefinitionBuilder.cs | 53 ++ .../Interfaces/ISetTaskDefinitionBuilder.cs | 38 + .../IShellProcessDefinitionBuilder.cs | 61 ++ .../ISwitchCaseDefinitionBuilder.cs | 42 ++ .../ISwitchTaskDefinitionBuilder.cs | 36 + .../Interfaces/ITaskDefinitionBuilder.cs | 45 ++ .../ITaskDefinitionMappingBuilder.cs | 51 ++ ...ITaskExecutionStrategyDefinitionBuilder.cs | 61 ++ .../Interfaces/ITryTaskDefinitionBuilder.cs | 37 + .../Interfaces/IWaitTaskDefinitionBuilder.cs} | 18 +- .../Interfaces/IWorkflowDefinitionBuilder.cs | 173 +++++ .../IWorkflowProcessDefinitionBuilder.cs | 53 ++ .../JitterDefinitionBuilder.cs | 63 ++ .../LinearBackoffDefinitionBuilder.cs | 45 ++ .../ListenTaskDefinitionBuilder.cs | 51 ++ .../ListenerDefinitionBuilder.cs | 48 ++ .../ListenerTargetDefinitionBuilder.cs | 71 ++ ...h2AuthenticationClientDefinitionBuilder.cs | 60 ++ ...h2AuthenticationSchemeDefinitionBuilder.cs | 170 +++++ .../ProcessDefinitionBuilder.cs | 29 + .../RaiseTaskDefinitionBuilder.cs | 59 ++ .../RetryAttemptLimitDefinitionBuilder.cs | 54 ++ .../RetryPolicyDefinitionBuilder.cs | 133 ++++ .../RetryPolicyLimitDefinitionBuilder.cs | 54 ++ .../RunTaskDefinitionBuilder.cs | 79 ++ .../ScriptProcessDefinitionBuilder.cs | 94 +++ .../ServerlessWorkflow.Sdk.Builders.csproj | 39 + .../SetTaskDefinitionBuilder.cs | 54 ++ .../ShellProcessDefinitionBuilder.cs | 95 +++ .../SwitchCaseDefinitionBuilder.cs | 58 ++ .../SwitchTaskDefinitionBuilder.cs | 48 ++ .../TaskDefinitionBuilder.cs | 41 ++ .../TaskDefinitionMappingBuilder.cs | 50 ++ .../TaskExecutionStrategyDefinitionBuilder.cs | 80 ++ .../TryTaskDefinitionBuilder.cs | 64 ++ src/ServerlessWorkflow.Sdk.Builders/Usings.cs | 16 + .../WaitTaskDefinitionBuilder.cs | 47 ++ .../WorkflowDefinitionBuilder.cs | 275 +++++++ .../WorkflowProcessDefinitionBuilder.cs | 94 +++ .../IServiceCollectionExtensions.cs | 49 ++ .../Interfaces/IWorkflowDefinitionReader.cs} | 10 +- .../Interfaces/IWorkflowDefinitionWriter.cs} | 11 +- .../RelativeUriReferenceResolutionMode.cs | 12 +- .../ServerlessWorkflow.Sdk.IO.csproj | 43 ++ src/ServerlessWorkflow.Sdk.IO/Usings.cs | 14 + .../WorkflowDefinitionFormat.cs | 12 +- .../WorkflowDefinitionReader.cs | 65 ++ .../WorkflowDefinitionReaderOptions.cs | 42 ++ .../WorkflowDefinitionWriter.cs | 65 ++ .../SemanticVersionAttribute.cs} | 16 +- .../AuthenticationScheme.cs | 27 +- src/ServerlessWorkflow.Sdk/Cron.cs | 51 -- ...imeExpressionLanguage.cs => DslVersion.cs} | 10 +- src/ServerlessWorkflow.Sdk/ErrorStatus.cs | 55 ++ src/ServerlessWorkflow.Sdk/ErrorTitle.cs | 43 ++ src/ServerlessWorkflow.Sdk/ErrorType.cs | 44 ++ .../Extensions/DurationExtensions.cs | 19 +- .../Extensions/EvaluationResultsExtensions.cs | 32 - .../Extensions/ExceptionExtensions.cs | 53 ++ .../IServiceCollectionExtensions.cs | 46 -- .../Extensions/IWorkflowReaderExtensions.cs | 73 -- .../Extensions/JsonNodeExtensions.cs | 89 --- .../Extensions/JsonSchemaExtensions.cs | 72 -- .../Extensions/StringExtensions.cs | 60 -- .../Extensions/TypeExtensions.cs | 44 -- .../WorkflowDefinitionExtensions.cs | 77 +- ...CompletionBehavior.cs => FlowDirective.cs} | 18 +- .../{FunctionType.cs => Function.cs} | 47 +- .../{ActionType.cs => HttpOutputFormat.cs} | 24 +- .../{IOneOf.cs => IExtendable.cs} | 11 +- .../{IMetadata.cs => IReferenceable.cs} | 10 +- src/ServerlessWorkflow.Sdk/Iso8601TimeSpan.cs | 38 - .../Models/ActionDataFilterDefinition.cs | 48 -- .../Models/ActionDefinition.cs | 175 ----- .../Models/ActionExecutionDelayDefinition.cs | 35 - .../BasicAuthenticationSchemeDefinition.cs | 42 ++ .../BearerAuthenticationSchemeDefinition.cs | 34 + .../OAuth2AuthenticationClientDefinition.cs | 36 + .../OAuth2AuthenticationSchemeDefinition.cs | 86 +++ .../Authentication/OAuth2TokenDefinition.cs | 35 + .../Models/AuthenticationDefinition.cs | 98 --- .../Models/AuthenticationPolicyDefinition.cs | 50 ++ .../Models/AuthenticationProperties.cs | 57 -- ...n.cs => AuthenticationSchemeDefinition.cs} | 23 +- ...CaseDefinition.cs => BackoffDefinition.cs} | 9 +- .../Models/BackoffStrategyDefinition.cs | 41 ++ .../Models/BasicAuthenticationProperties.cs | 66 -- .../Models/BearerAuthenticationProperties.cs | 49 -- .../Models/BranchDefinition.cs | 89 --- ...OutcomeDefinition.cs => CallDefinition.cs} | 6 +- .../Models/Calls/AsyncApiCallDefinition.cs | 68 ++ .../Models/Calls/GrpcCallDefinition.cs | 51 ++ .../Models/Calls/HttpCallDefinition.cs | 56 ++ .../Models/Calls/OpenApiCallDefinition.cs | 56 ++ ...seDefinition.cs => ComponentDefinition.cs} | 15 +- .../Models/ComponentDefinitionCollection.cs | 59 ++ .../Models/ConstantBackoffDefinition.cs | 26 + .../Models/CorrelationDefinition.cs | 35 + .../Models/CronDefinition.cs | 41 -- .../Models/DataInputSchemaDefinition.cs | 42 -- .../Models/DataModelDefinition.cs | 35 + src/ServerlessWorkflow.Sdk/Models/Duration.cs | 166 +++++ .../Models/DynamicMapping.cs | 122 --- .../Models/EndDefinition.cs | 42 -- ...ateDefinition.cs => EndpointDefinition.cs} | 22 +- .../Models/ErrorCatcherDefinition.cs | 59 ++ .../Models/ErrorDefinition.cs | 59 ++ .../Models/ErrorFilterDefinition.cs | 29 + .../Models/ErrorHandlerDefinition.cs | 97 --- .../EventConsumptionStrategyDefinition.cs | 41 ++ .../Models/EventCorrelationDefinition.cs | 61 -- .../Models/EventDataFilterDefinition.cs | 43 -- .../Models/EventDefinition.cs | 65 +- .../Models/EventEmissionDefinition.cs | 30 + .../Models/EventFilterDefinition.cs | 35 + .../Models/EventReference.cs | 117 --- .../Models/EventStateTriggerDefinition.cs | 85 --- .../Models/ExponentialBackoffDefinition.cs | 26 + .../Models/Extendable.cs | 29 + .../Models/ExtensionDefinition.cs | 45 +- .../Models/ExternalDefinitionCollection.cs | 66 -- .../Models/ExternalResourceDefinition.cs | 31 + .../Models/ForLoopDefinition.cs | 48 ++ .../Models/FunctionDefinition.cs | 66 -- .../Models/FunctionReference.cs | 52 -- .../Models/GrpcServiceDefinition.cs | 49 ++ .../Models/HttpRequest.cs | 49 ++ .../Models/HttpResponse.cs | 49 ++ .../Models/InputDataModelDefinition.cs | 26 + ...StateDefinition.cs => JitterDefinition.cs} | 24 +- .../Models/LinearBackoffDefinition.cs | 30 + .../Models/ListenerDefinition.cs | 30 + .../Models/OAuth2AuthenticationProperties.cs | 246 ------- .../Models/OAuth2GrantType.cs | 61 ++ src/ServerlessWorkflow.Sdk/Models/OneOf.cs | 90 --- ...nition.cs => OutputDataModelDefinition.cs} | 15 +- .../Models/ProcessDefinition.cs | 26 + .../Models/ProcessType.cs | 55 ++ .../Models/ProcessTypeDefinition.cs | 65 ++ .../Processes/ContainerProcessDefinition.cs | 55 ++ .../Processes/ScriptProcessDefinition.cs | 49 ++ .../Processes/ShellProcessDefinition.cs | 43 ++ .../Processes/WorkflowProcessDefinition.cs | 53 ++ .../Models/ProduceEventDefinition.cs | 43 -- .../Models/RaiseErrorDefinition.cs | 30 + .../ReferenceableComponentDefinition.cs | 36 + .../Models/RetryAttemptLimitDefinition.cs | 35 + .../Models/RetryDefinition.cs | 117 --- .../Models/RetryPolicyDefinition.cs | 60 ++ .../Models/RetryPolicyLimitDefinition.cs | 35 + ...untimeExpressionEvaluationConfiguration.cs | 35 + .../Models/ScheduleDefinition.cs | 84 --- .../Models/SchemaDefinition.cs | 44 ++ .../Models/SchemaFormat.cs | 46 ++ .../SecretBasedAuthenticationProperties.cs | 46 -- .../Models/StartDefinition.cs | 42 -- .../Models/StateDataFilterDefinition.cs | 40 - .../Models/StateDefinition.cs | 227 ------ .../Models/States/CallbackStateDefinition.cs | 57 -- .../Models/States/EventStateDefinition.cs | 81 -- .../Models/States/ForEachStateDefinition.cs | 109 --- .../Models/States/OperationStateDefinition.cs | 83 --- .../Models/States/ParallelStateDefinition.cs | 70 -- .../Models/States/SwitchStateDefinition.cs | 141 ---- .../Models/SubflowReference.cs | 108 --- .../Models/SwitchCaseDefinition.cs | 116 +-- .../Models/TaskDefinition.cs | 58 ++ .../Models/TaskExecutionStrategyDefinition.cs | 47 ++ src/ServerlessWorkflow.Sdk/Models/TaskType.cs | 91 +++ .../Models/Tasks/CallTaskDefinition.cs | 47 ++ .../Models/Tasks/CompositeTaskDefinition.cs | 35 + .../Models/Tasks/EmitTaskDefinition.cs | 34 + .../Tasks/ExtensionTaskDefinition.cs} | 25 +- .../Models/Tasks/ForTaskDefinition.cs | 48 ++ .../Models/Tasks/ListenTaskDefinition.cs | 35 + .../Models/Tasks/RaiseTaskDefinition.cs | 35 + .../Models/Tasks/RunTaskDefinition.cs | 35 + .../Models/Tasks/SetTaskDefinition.cs | 35 + .../Models/Tasks/SwitchTaskDefinition.cs | 35 + .../Models/Tasks/TryTaskDefinition.cs | 42 ++ .../Models/Tasks/WaitTaskDefinition.cs | 35 + ...tionProperties.cs => TimeoutDefinition.cs} | 19 +- .../Models/TransitionDefinition.cs | 43 -- .../Models/WorkflowDefinition.cs | 692 +----------------- .../Models/WorkflowDefinitionMetadata.cs | 75 ++ .../WorkflowExecutionTimeoutDefinition.cs | 51 -- .../Models/WorkflowScheduleDefinition.cs | 47 ++ .../Models/WorkflowTimeoutDefinition.cs | 61 -- .../NamingConvention.cs | 39 + src/ServerlessWorkflow.Sdk/OAuth2GrantType.cs | 37 - src/ServerlessWorkflow.Sdk/OAuth2TokenType.cs | 32 - .../ParallelCompletionType.cs | 32 - ....cs => RuntimeExpressionEvaluationMode.cs} | 17 +- .../RuntimeExpressions.cs | 72 ++ .../Serialization/Json/DictionaryConverter.cs | 65 -- .../Json/Iso8601TimeSpanConverter.cs | 60 -- .../Json/JsonTypeInfoModifiers.cs | 145 ---- .../Serialization/Json/OneOfConverter.cs | 52 -- .../Serialization/Json/Serializer.cs | 230 ------ .../Json/TaskDefinitionJsonConverter.cs | 53 ++ .../Yaml/ChainedObjectGraphVisitor.cs | 58 -- .../Yaml/IExtensibleDeserializer.cs | 47 -- .../Serialization/Yaml/InferTypeResolver.cs | 69 -- .../Yaml/Iso8601TimeSpanSerializer.cs | 39 - .../Yaml/JsonElementConverter.cs | 52 -- .../Serialization/Yaml/JsonNodeConverter.cs | 109 --- .../Serialization/Yaml/OneOfConverter.cs | 39 - .../Serialization/Yaml/OneOfDeserializer.cs | 57 -- .../Serialization/Yaml/Serializer.cs | 107 --- ...rter.cs => TaskDefinitionYamlConverter.cs} | 34 +- .../Serialization/Yaml/UriTypeSerializer.cs | 43 -- .../ServerlessWorkflow.Sdk.csproj | 68 +- .../ServerlessWorkflowSpecVersion.cs | 32 - .../Services/FluentBuilders/ActionBuilder.cs | 284 ------- .../AuthenticationDefinitionBuilder.cs | 71 -- .../BasicAuthenticationBuilder.cs | 49 -- .../BearerAuthenticationBuilder.cs | 41 -- .../Services/FluentBuilders/BranchBuilder.cs | 113 --- .../FluentBuilders/CallbackStateBuilder.cs | 105 --- .../FluentBuilders/DataSwitchCaseBuilder.cs | 59 -- .../FluentBuilders/ErrorHandlerBuilder.cs | 115 --- .../Services/FluentBuilders/EventBuilder.cs | 130 ---- .../FluentBuilders/EventStateBuilder.cs | 67 -- .../EventStateTriggerBuilder.cs | 141 ---- .../FluentBuilders/EventSwitchCaseBuilder.cs | 73 -- .../FluentBuilders/ForEachStateBuilder.cs | 108 --- .../FluentBuilders/FunctionBuilder.cs | 152 ---- .../FluentBuilders/InjectStateBuilder.cs | 37 - .../Interfaces/IActionBuilder.cs | 123 ---- .../Interfaces/IActionCollectionBuilder.cs | 37 - .../Interfaces/IActionContainerBuilder.cs | 46 -- .../IAuthenticationDefinitionBuilder.cs | 42 -- .../Interfaces/IBasicAuthenticationBuilder.cs | 37 - .../IBearerAuthenticationBuilder.cs | 30 - .../Interfaces/IBranchBuilder.cs | 36 - .../Interfaces/ICallbackStateBuilder.cs | 80 -- .../Interfaces/IDataSwitchCaseBuilder.cs | 36 - .../Interfaces/IDataSwitchStateBuilder.cs | 38 - .../Interfaces/IErrorHandlerBuilder.cs | 64 -- .../Interfaces/IEventBuilder.cs | 84 --- .../Interfaces/IEventStateBuilder.cs | 55 -- .../Interfaces/IEventStateTriggerBuilder.cs | 64 -- .../Interfaces/IEventSwitchCaseBuilder.cs | 50 -- .../Interfaces/IEventSwitchStateBuilder.cs | 45 -- .../Interfaces/IEventTriggerActionBuilder.cs | 58 -- .../Interfaces/IExtensibleBuilder.cs | 39 - .../Interfaces/IForEachStateBuilder.cs | 52 -- .../Interfaces/IFunctionActionBuilder.cs | 46 -- .../Interfaces/IFunctionBuilder.cs | 95 --- .../Interfaces/IMetadataContainerBuilder.cs | 44 -- .../IOAuth2AuthenticationBuilder.cs | 95 --- .../Interfaces/IParallelStateBuilder.cs | 51 -- .../Interfaces/IPipelineBuilder.cs | 107 --- .../Interfaces/IRetryStrategyBuilder.cs | 91 --- .../Interfaces/IScheduleBuilder.cs | 50 -- .../Interfaces/IStateBuilder.cs | 94 --- .../Interfaces/IStateBuilderFactory.cs | 116 --- .../Interfaces/IStateOutcomeBuilder.cs | 48 -- .../Interfaces/ISubflowActionBuilder.cs | 48 -- .../Interfaces/ISubflowRunnerBuilder.cs | 28 - .../Interfaces/ISwitchStateBuilder.cs | 43 -- .../Interfaces/IWorkflowBuilder.cs | 303 -------- .../IWorkflowExecutionTimeoutBuilder.cs | 63 -- .../MetadataContainerBuilder.cs | 45 -- .../OAuth2AuthenticationBuilder.cs | 113 --- .../FluentBuilders/OperationStateBuilder.cs | 80 -- .../FluentBuilders/ParallelStateBuilder.cs | 68 -- .../FluentBuilders/PipelineBuilder.cs | 143 ---- .../FluentBuilders/RetryStrategyBuilder.cs | 112 --- .../FluentBuilders/ScheduleBuilder.cs | 58 -- .../FluentBuilders/SleepStateBuilder.cs | 41 -- .../Services/FluentBuilders/StateBuilder.cs | 140 ---- .../FluentBuilders/StateBuilderFactory.cs | 149 ---- .../FluentBuilders/StateOutcomeBuilder.cs | 72 -- .../FluentBuilders/SwitchCaseBuilder.cs | 44 -- .../FluentBuilders/SwitchStateBuilder.cs | 113 --- .../FluentBuilders/WorkflowBuilder.cs | 386 ---------- .../WorkflowExecutionTimeoutBuilder.cs | 87 --- .../IWorkflowExternalDefinitionResolver.cs | 31 - .../IO/WorkflowExternalDefinitionResolver.cs | 171 ----- .../Services/IO/WorkflowReader.cs | 70 -- .../Services/IO/WorkflowReaderOptions.cs | 62 -- .../Services/IO/WorkflowWriter.cs | 52 -- .../Validation/ActionDefinitionValidator.cs | 67 -- .../AuthenticationDefinitionValidator.cs | 75 -- .../BasicAuthenticationPropertiesValidator.cs | 36 - ...BearerAuthenticationPropertiesValidator.cs | 34 - .../Validation/CallbackStateValidator.cs | 49 -- .../Validation/CollectionPropertyValidator.cs | 65 -- .../Validation/DataCaseDefinitionValidator.cs | 38 - .../DefaultCaseDefinitionValidator.cs | 34 - .../ErrorHandlerDefinitionValidator.cs | 59 -- .../EventCaseDefinitionValidator.cs | 53 -- .../Validation/EventReferenceValidator.cs | 94 --- .../EventStateTriggerDefinitionValidator.cs | 81 -- .../Validation/EventStateValidator.cs | 41 -- .../Validation/ForEachStateValidator.cs | 41 -- .../FunctionDefinitionCollectionValidator.cs | 50 -- .../Validation/FunctionDefinitionValidator.cs | 57 -- .../Validation/FunctionReferenceValidator.cs | 84 --- .../Validation/InjectStateValidator.cs | 37 - .../Interfaces/IWorkflowSchemaValidator.cs | 30 - .../Interfaces/IWorkflowValidationResult.cs | 37 - .../Interfaces/IWorkflowValidator.cs | 32 - ...OAuth2AuthenticationPropertiesValidator.cs | 42 -- .../Validation/OperationStateValidator.cs | 41 -- .../RetryStrategyDefinitionValidator.cs | 35 - .../Validation/SleepStateValidator.cs | 34 - .../Validation/StateDefinitionValidator.cs | 131 ---- .../Validation/SubflowReferenceValidator.cs | 42 -- .../SwitchCaseDefinitionValidator.cs | 76 -- .../Validation/SwitchStateValidator.cs | 59 -- .../TransitionDefinitionValidator.cs | 41 -- .../Validation/WorkflowDefinitionValidator.cs | 129 ---- .../Validation/WorkflowSchemaValidator.cs | 148 ---- .../WorkflowStatesPropertyValidator.cs | 87 --- .../Validation/WorkflowValidationResult.cs | 48 -- .../Services/Validation/WorkflowValidator.cs | 96 --- src/ServerlessWorkflow.Sdk/StateType.cs | 78 -- .../SwitchCaseOutcomeType.cs | 32 - src/ServerlessWorkflow.Sdk/SwitchStateType.cs | 32 - ...nExecutionMode.cs => TaskExecutionMode.cs} | 15 +- src/ServerlessWorkflow.Sdk/Usings.cs | 12 +- src/ServerlessWorkflow.Sdk/icon.png | Bin 38143 -> 0 bytes .../condition-state-type.json | 175 ----- .../greet-function-type.json | 28 - .../WorkflowDefinitionBuilderTests.cs | 188 +++++ .../Cases/FluentBuilder/FluentBuilderTests.cs | 561 -------------- .../Cases/IO/WorkflowDefinitionReaderTests.cs | 62 ++ .../Cases/IO/WorkflowDefinitionWriterTests.cs | 62 ++ .../Cases/IO/WorkflowReaderTests.cs | 149 ---- .../Cases/IO/WorkflowWriterTests.cs | 86 --- .../Serialization/JsonSerializationTests.cs | 26 - .../Serialization/YamlSerializationTests.cs | 26 - .../Cases/SerializationTestsBase.cs | 37 - .../Cases/Validation/ActionValidationTests.cs | 45 -- .../CallbackStateValidationTests.cs | 97 --- .../EventReferenceValidationTests.cs | 149 ---- .../EventStateTriggerValidationTests.cs | 44 -- .../Validation/EventStateValidationTests.cs | 54 -- .../FunctionDefinitionValidationTests.cs | 83 --- .../FunctionReferenceValidationTests.cs | 115 --- .../Validation/InjectStateValidationTests.cs | 53 -- .../OperationStateValidationTests.cs | 42 -- .../SubflowReferenceValidationTests.cs | 38 - .../Validation/SwitchStateValidationTests.cs | 75 -- .../Validation/WorkflowValidationTests.cs | 92 --- .../CloudFlows.Sdk.UnitTests.csproj | 35 + .../Resources/auths/default.json | 44 -- .../Resources/auths/default.yaml | 27 - .../Resources/constants/petstore.json | 3 - .../Resources/constants/petstore.yaml | 1 - .../dataSchemas/input-data-schema.json | 4 - .../Resources/events/petstore.json | 14 - .../Resources/events/petstore.yaml | 8 - .../extensions/state-type-extension.json | 63 -- .../Resources/functions/petstore.json | 10 - .../Resources/functions/petstore.yaml | 4 - .../Resources/retries/default.json | 11 - .../Resources/retries/default.yaml | 7 - .../Resources/schemas/externalref.json | 34 - .../Resources/schemas/externalref.yaml | 20 - .../Resources/schemas/input-data.json | 12 - .../Resources/secrets/default.json | 3 - .../Resources/secrets/default.yaml | 1 - .../Resources/workflows/extended.json | 25 - .../external-function-definition.json | 22 - .../workflows/external-input-data-schema.json | 15 - .../Resources/workflows/externalref.json | 28 - .../Resources/workflows/externalref.yaml | 19 - .../workflows/input-data-schema.json | 18 - .../workflows/missing-transition.json | 57 -- .../Resources/workflows/operation.json | 56 -- .../Resources/workflows/operation.yaml | 32 - .../ServerlessWorkflow.Sdk.UnitTests.csproj | 116 --- .../Services/WorkflowDefinitionFactory.cs | 184 ++++- .../Usings.cs | 6 +- 445 files changed, 10835 insertions(+), 17318 deletions(-) create mode 100644 .github/workflows/build-dotnet.yml create mode 100644 .github/workflows/ci-pipeline.yml delete mode 100644 .github/workflows/dotnet.yml create mode 100644 .github/workflows/publish.yml create mode 100644 .github/workflows/release.yml create mode 100644 .github/workflows/test-dotnet.yml create mode 100644 .github/workflows/versioning.yml create mode 100644 src/ServerlessWorkflow.Sdk.Builders/AuthenticationPolicyDefinitionBuilder.cs create mode 100644 src/ServerlessWorkflow.Sdk.Builders/BackoffStrategyDefinitionBuilder.cs create mode 100644 src/ServerlessWorkflow.Sdk.Builders/BasicAuthenticationSchemeDefinitionBuilder.cs create mode 100644 src/ServerlessWorkflow.Sdk.Builders/BearerAuthenticationSchemeDefinitionBuilder.cs create mode 100644 src/ServerlessWorkflow.Sdk.Builders/CallTaskDefinitionBuilder.cs create mode 100644 src/ServerlessWorkflow.Sdk.Builders/CompositeTaskDefinitionBuilder.cs rename src/{ServerlessWorkflow.Sdk/Services/FluentBuilders/ExtensionStateBuilder.cs => ServerlessWorkflow.Sdk.Builders/ConstantBackoffDefinitionBuilder.cs} (57%) create mode 100644 src/ServerlessWorkflow.Sdk.Builders/ContainerProcessDefinitionBuilder.cs create mode 100644 src/ServerlessWorkflow.Sdk.Builders/EmitTaskDefinitionBuilder.cs create mode 100644 src/ServerlessWorkflow.Sdk.Builders/ErrorCatcherDefinitionBuilder.cs create mode 100644 src/ServerlessWorkflow.Sdk.Builders/ErrorDefinitionBuilder.cs create mode 100644 src/ServerlessWorkflow.Sdk.Builders/ErrorFilterDefinitionBuilder.cs create mode 100644 src/ServerlessWorkflow.Sdk.Builders/EventDefinitionBuilder.cs create mode 100644 src/ServerlessWorkflow.Sdk.Builders/EventFilterDefinitionBuilder.cs create mode 100644 src/ServerlessWorkflow.Sdk.Builders/EventFilterDefinitionCollectionBuilder.cs create mode 100644 src/ServerlessWorkflow.Sdk.Builders/ExponentialBackoffDefinitionBuilder.cs create mode 100644 src/ServerlessWorkflow.Sdk.Builders/ExtensionDefinitionBuilder.cs create mode 100644 src/ServerlessWorkflow.Sdk.Builders/ExternalResourceDefinitionBuilder.cs create mode 100644 src/ServerlessWorkflow.Sdk.Builders/ForTaskDefinitionBuilder.cs create mode 100644 src/ServerlessWorkflow.Sdk.Builders/GenericTaskDefinitionBuilder.cs create mode 100644 src/ServerlessWorkflow.Sdk.Builders/HttpCallDefinitionBuilder.cs create mode 100644 src/ServerlessWorkflow.Sdk.Builders/Interfaces/IAuthenticationPolicyDefinitionBuilder.cs create mode 100644 src/ServerlessWorkflow.Sdk.Builders/Interfaces/IAuthenticationSchemeDefinitionBuilder.cs create mode 100644 src/ServerlessWorkflow.Sdk.Builders/Interfaces/IBackoffDefinitionBuilder.cs create mode 100644 src/ServerlessWorkflow.Sdk.Builders/Interfaces/IBackoffStrategyDefinitionBuilder.cs create mode 100644 src/ServerlessWorkflow.Sdk.Builders/Interfaces/IBasicAuthenticationSchemeDefinitionBuilder.cs rename src/{ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/ISwitchCaseBuilder.cs => ServerlessWorkflow.Sdk.Builders/Interfaces/IBearerAuthenticationSchemeDefinitionBuilder.cs} (55%) create mode 100644 src/ServerlessWorkflow.Sdk.Builders/Interfaces/ICallTaskDefinitionBuilder.cs rename src/{ServerlessWorkflow.Sdk/IExtensible.cs => ServerlessWorkflow.Sdk.Builders/Interfaces/ICompositeTaskDefinitionBuilder.cs} (61%) rename src/{ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IExtensionStateBuilder.cs => ServerlessWorkflow.Sdk.Builders/Interfaces/IConstantBackoffDefinitionBuilder.cs} (72%) create mode 100644 src/ServerlessWorkflow.Sdk.Builders/Interfaces/IContainerProcessDefinitionBuilder.cs create mode 100644 src/ServerlessWorkflow.Sdk.Builders/Interfaces/IEmitTaskDefinitionBuilder.cs create mode 100644 src/ServerlessWorkflow.Sdk.Builders/Interfaces/IEndpointDefinitionBuilder.cs create mode 100644 src/ServerlessWorkflow.Sdk.Builders/Interfaces/IErrorCatcherDefinitionBuilder.cs create mode 100644 src/ServerlessWorkflow.Sdk.Builders/Interfaces/IErrorDefinitionBuilder.cs create mode 100644 src/ServerlessWorkflow.Sdk.Builders/Interfaces/IErrorFilterDefinitionBuilder.cs create mode 100644 src/ServerlessWorkflow.Sdk.Builders/Interfaces/IEventDefinitionBuilder.cs create mode 100644 src/ServerlessWorkflow.Sdk.Builders/Interfaces/IEventFilterDefinitionBuilder.cs create mode 100644 src/ServerlessWorkflow.Sdk.Builders/Interfaces/IEventFilterDefinitionCollectionBuilder.cs rename src/{ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IOperationStateBuilder.cs => ServerlessWorkflow.Sdk.Builders/Interfaces/IExponentialBackoffDefinitionBuilder.cs} (69%) create mode 100644 src/ServerlessWorkflow.Sdk.Builders/Interfaces/IExtensionDefinitionBuilder.cs create mode 100644 src/ServerlessWorkflow.Sdk.Builders/Interfaces/IExternalResourceDefinitionBuilder.cs create mode 100644 src/ServerlessWorkflow.Sdk.Builders/Interfaces/IForTaskDefinitionBuilder.cs create mode 100644 src/ServerlessWorkflow.Sdk.Builders/Interfaces/IGenericTaskDefinitionBuilder.cs create mode 100644 src/ServerlessWorkflow.Sdk.Builders/Interfaces/IHttpCallDefinitionBuilder.cs create mode 100644 src/ServerlessWorkflow.Sdk.Builders/Interfaces/IJitterDefinitionBuilder.cs create mode 100644 src/ServerlessWorkflow.Sdk.Builders/Interfaces/ILinearBackoffDefinitionBuilder.cs create mode 100644 src/ServerlessWorkflow.Sdk.Builders/Interfaces/IListenTaskDefinitionBuilder.cs rename src/{ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IInjectStateBuilder.cs => ServerlessWorkflow.Sdk.Builders/Interfaces/IListenerDefinitionBuilder.cs} (56%) create mode 100644 src/ServerlessWorkflow.Sdk.Builders/Interfaces/IListenerTargetDefinitionBuilder.cs create mode 100644 src/ServerlessWorkflow.Sdk.Builders/Interfaces/IOAuth2AuthenticationClientDefinitionBuilder.cs create mode 100644 src/ServerlessWorkflow.Sdk.Builders/Interfaces/IOAuth2AuthenticationSchemeDefinitionBuilder.cs create mode 100644 src/ServerlessWorkflow.Sdk.Builders/Interfaces/IProcessDefinitionBuilder.cs create mode 100644 src/ServerlessWorkflow.Sdk.Builders/Interfaces/IRaiseTaskDefinitionBuilder.cs create mode 100644 src/ServerlessWorkflow.Sdk.Builders/Interfaces/IRetryAttemptLimitDefinitionBuilder.cs create mode 100644 src/ServerlessWorkflow.Sdk.Builders/Interfaces/IRetryPolicyDefinitionBuilder.cs create mode 100644 src/ServerlessWorkflow.Sdk.Builders/Interfaces/IRetryPolicyLimitDefinitionBuilder.cs create mode 100644 src/ServerlessWorkflow.Sdk.Builders/Interfaces/IRunTaskDefinitionBuilder.cs create mode 100644 src/ServerlessWorkflow.Sdk.Builders/Interfaces/IScriptProcessDefinitionBuilder.cs create mode 100644 src/ServerlessWorkflow.Sdk.Builders/Interfaces/ISetTaskDefinitionBuilder.cs create mode 100644 src/ServerlessWorkflow.Sdk.Builders/Interfaces/IShellProcessDefinitionBuilder.cs create mode 100644 src/ServerlessWorkflow.Sdk.Builders/Interfaces/ISwitchCaseDefinitionBuilder.cs create mode 100644 src/ServerlessWorkflow.Sdk.Builders/Interfaces/ISwitchTaskDefinitionBuilder.cs create mode 100644 src/ServerlessWorkflow.Sdk.Builders/Interfaces/ITaskDefinitionBuilder.cs create mode 100644 src/ServerlessWorkflow.Sdk.Builders/Interfaces/ITaskDefinitionMappingBuilder.cs create mode 100644 src/ServerlessWorkflow.Sdk.Builders/Interfaces/ITaskExecutionStrategyDefinitionBuilder.cs create mode 100644 src/ServerlessWorkflow.Sdk.Builders/Interfaces/ITryTaskDefinitionBuilder.cs rename src/{ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IDelayStateBuilder.cs => ServerlessWorkflow.Sdk.Builders/Interfaces/IWaitTaskDefinitionBuilder.cs} (58%) create mode 100644 src/ServerlessWorkflow.Sdk.Builders/Interfaces/IWorkflowDefinitionBuilder.cs create mode 100644 src/ServerlessWorkflow.Sdk.Builders/Interfaces/IWorkflowProcessDefinitionBuilder.cs create mode 100644 src/ServerlessWorkflow.Sdk.Builders/JitterDefinitionBuilder.cs create mode 100644 src/ServerlessWorkflow.Sdk.Builders/LinearBackoffDefinitionBuilder.cs create mode 100644 src/ServerlessWorkflow.Sdk.Builders/ListenTaskDefinitionBuilder.cs create mode 100644 src/ServerlessWorkflow.Sdk.Builders/ListenerDefinitionBuilder.cs create mode 100644 src/ServerlessWorkflow.Sdk.Builders/ListenerTargetDefinitionBuilder.cs create mode 100644 src/ServerlessWorkflow.Sdk.Builders/OAuth2AuthenticationClientDefinitionBuilder.cs create mode 100644 src/ServerlessWorkflow.Sdk.Builders/OAuth2AuthenticationSchemeDefinitionBuilder.cs create mode 100644 src/ServerlessWorkflow.Sdk.Builders/ProcessDefinitionBuilder.cs create mode 100644 src/ServerlessWorkflow.Sdk.Builders/RaiseTaskDefinitionBuilder.cs create mode 100644 src/ServerlessWorkflow.Sdk.Builders/RetryAttemptLimitDefinitionBuilder.cs create mode 100644 src/ServerlessWorkflow.Sdk.Builders/RetryPolicyDefinitionBuilder.cs create mode 100644 src/ServerlessWorkflow.Sdk.Builders/RetryPolicyLimitDefinitionBuilder.cs create mode 100644 src/ServerlessWorkflow.Sdk.Builders/RunTaskDefinitionBuilder.cs create mode 100644 src/ServerlessWorkflow.Sdk.Builders/ScriptProcessDefinitionBuilder.cs create mode 100644 src/ServerlessWorkflow.Sdk.Builders/ServerlessWorkflow.Sdk.Builders.csproj create mode 100644 src/ServerlessWorkflow.Sdk.Builders/SetTaskDefinitionBuilder.cs create mode 100644 src/ServerlessWorkflow.Sdk.Builders/ShellProcessDefinitionBuilder.cs create mode 100644 src/ServerlessWorkflow.Sdk.Builders/SwitchCaseDefinitionBuilder.cs create mode 100644 src/ServerlessWorkflow.Sdk.Builders/SwitchTaskDefinitionBuilder.cs create mode 100644 src/ServerlessWorkflow.Sdk.Builders/TaskDefinitionBuilder.cs create mode 100644 src/ServerlessWorkflow.Sdk.Builders/TaskDefinitionMappingBuilder.cs create mode 100644 src/ServerlessWorkflow.Sdk.Builders/TaskExecutionStrategyDefinitionBuilder.cs create mode 100644 src/ServerlessWorkflow.Sdk.Builders/TryTaskDefinitionBuilder.cs create mode 100644 src/ServerlessWorkflow.Sdk.Builders/Usings.cs create mode 100644 src/ServerlessWorkflow.Sdk.Builders/WaitTaskDefinitionBuilder.cs create mode 100644 src/ServerlessWorkflow.Sdk.Builders/WorkflowDefinitionBuilder.cs create mode 100644 src/ServerlessWorkflow.Sdk.Builders/WorkflowProcessDefinitionBuilder.cs create mode 100644 src/ServerlessWorkflow.Sdk.IO/Extensions/IServiceCollectionExtensions.cs rename src/{ServerlessWorkflow.Sdk/Services/IO/Interfaces/IWorkflowReader.cs => ServerlessWorkflow.Sdk.IO/Interfaces/IWorkflowDefinitionReader.cs} (73%) rename src/{ServerlessWorkflow.Sdk/Services/IO/Interfaces/IWorkflowWriter.cs => ServerlessWorkflow.Sdk.IO/Interfaces/IWorkflowDefinitionWriter.cs} (72%) rename src/{ServerlessWorkflow.Sdk => ServerlessWorkflow.Sdk.IO}/RelativeUriReferenceResolutionMode.cs (71%) create mode 100644 src/ServerlessWorkflow.Sdk.IO/ServerlessWorkflow.Sdk.IO.csproj create mode 100644 src/ServerlessWorkflow.Sdk.IO/Usings.cs rename src/{ServerlessWorkflow.Sdk => ServerlessWorkflow.Sdk.IO}/WorkflowDefinitionFormat.cs (77%) create mode 100644 src/ServerlessWorkflow.Sdk.IO/WorkflowDefinitionReader.cs create mode 100644 src/ServerlessWorkflow.Sdk.IO/WorkflowDefinitionReaderOptions.cs create mode 100644 src/ServerlessWorkflow.Sdk.IO/WorkflowDefinitionWriter.cs rename src/ServerlessWorkflow.Sdk/{EventKind.cs => Attributes/SemanticVersionAttribute.cs} (54%) delete mode 100644 src/ServerlessWorkflow.Sdk/Cron.cs rename src/ServerlessWorkflow.Sdk/{RuntimeExpressionLanguage.cs => DslVersion.cs} (73%) create mode 100644 src/ServerlessWorkflow.Sdk/ErrorStatus.cs create mode 100644 src/ServerlessWorkflow.Sdk/ErrorTitle.cs create mode 100644 src/ServerlessWorkflow.Sdk/ErrorType.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Extensions/EvaluationResultsExtensions.cs create mode 100644 src/ServerlessWorkflow.Sdk/Extensions/ExceptionExtensions.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Extensions/IServiceCollectionExtensions.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Extensions/IWorkflowReaderExtensions.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Extensions/JsonNodeExtensions.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Extensions/JsonSchemaExtensions.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Extensions/StringExtensions.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Extensions/TypeExtensions.cs rename src/ServerlessWorkflow.Sdk/{SubflowParentCompletionBehavior.cs => FlowDirective.cs} (51%) rename src/ServerlessWorkflow.Sdk/{FunctionType.cs => Function.cs} (51%) rename src/ServerlessWorkflow.Sdk/{ActionType.cs => HttpOutputFormat.cs} (56%) rename src/ServerlessWorkflow.Sdk/{IOneOf.cs => IExtendable.cs} (68%) rename src/ServerlessWorkflow.Sdk/{IMetadata.cs => IReferenceable.cs} (71%) delete mode 100644 src/ServerlessWorkflow.Sdk/Iso8601TimeSpan.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Models/ActionDataFilterDefinition.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Models/ActionDefinition.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Models/ActionExecutionDelayDefinition.cs create mode 100644 src/ServerlessWorkflow.Sdk/Models/Authentication/BasicAuthenticationSchemeDefinition.cs create mode 100644 src/ServerlessWorkflow.Sdk/Models/Authentication/BearerAuthenticationSchemeDefinition.cs create mode 100644 src/ServerlessWorkflow.Sdk/Models/Authentication/OAuth2AuthenticationClientDefinition.cs create mode 100644 src/ServerlessWorkflow.Sdk/Models/Authentication/OAuth2AuthenticationSchemeDefinition.cs create mode 100644 src/ServerlessWorkflow.Sdk/Models/Authentication/OAuth2TokenDefinition.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Models/AuthenticationDefinition.cs create mode 100644 src/ServerlessWorkflow.Sdk/Models/AuthenticationPolicyDefinition.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Models/AuthenticationProperties.cs rename src/ServerlessWorkflow.Sdk/Models/{States/ExtensionStateDefinition.cs => AuthenticationSchemeDefinition.cs} (62%) rename src/ServerlessWorkflow.Sdk/Models/{DefaultCaseDefinition.cs => BackoffDefinition.cs} (71%) create mode 100644 src/ServerlessWorkflow.Sdk/Models/BackoffStrategyDefinition.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Models/BasicAuthenticationProperties.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Models/BearerAuthenticationProperties.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Models/BranchDefinition.cs rename src/ServerlessWorkflow.Sdk/Models/{StateOutcomeDefinition.cs => CallDefinition.cs} (78%) create mode 100644 src/ServerlessWorkflow.Sdk/Models/Calls/AsyncApiCallDefinition.cs create mode 100644 src/ServerlessWorkflow.Sdk/Models/Calls/GrpcCallDefinition.cs create mode 100644 src/ServerlessWorkflow.Sdk/Models/Calls/HttpCallDefinition.cs create mode 100644 src/ServerlessWorkflow.Sdk/Models/Calls/OpenApiCallDefinition.cs rename src/ServerlessWorkflow.Sdk/Models/{DataCaseDefinition.cs => ComponentDefinition.cs} (56%) create mode 100644 src/ServerlessWorkflow.Sdk/Models/ComponentDefinitionCollection.cs create mode 100644 src/ServerlessWorkflow.Sdk/Models/ConstantBackoffDefinition.cs create mode 100644 src/ServerlessWorkflow.Sdk/Models/CorrelationDefinition.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Models/CronDefinition.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Models/DataInputSchemaDefinition.cs create mode 100644 src/ServerlessWorkflow.Sdk/Models/DataModelDefinition.cs create mode 100644 src/ServerlessWorkflow.Sdk/Models/Duration.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Models/DynamicMapping.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Models/EndDefinition.cs rename src/ServerlessWorkflow.Sdk/Models/{States/InjectStateDefinition.cs => EndpointDefinition.cs} (52%) create mode 100644 src/ServerlessWorkflow.Sdk/Models/ErrorCatcherDefinition.cs create mode 100644 src/ServerlessWorkflow.Sdk/Models/ErrorDefinition.cs create mode 100644 src/ServerlessWorkflow.Sdk/Models/ErrorFilterDefinition.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Models/ErrorHandlerDefinition.cs create mode 100644 src/ServerlessWorkflow.Sdk/Models/EventConsumptionStrategyDefinition.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Models/EventCorrelationDefinition.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Models/EventDataFilterDefinition.cs create mode 100644 src/ServerlessWorkflow.Sdk/Models/EventEmissionDefinition.cs create mode 100644 src/ServerlessWorkflow.Sdk/Models/EventFilterDefinition.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Models/EventReference.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Models/EventStateTriggerDefinition.cs create mode 100644 src/ServerlessWorkflow.Sdk/Models/ExponentialBackoffDefinition.cs create mode 100644 src/ServerlessWorkflow.Sdk/Models/Extendable.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Models/ExternalDefinitionCollection.cs create mode 100644 src/ServerlessWorkflow.Sdk/Models/ExternalResourceDefinition.cs create mode 100644 src/ServerlessWorkflow.Sdk/Models/ForLoopDefinition.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Models/FunctionDefinition.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Models/FunctionReference.cs create mode 100644 src/ServerlessWorkflow.Sdk/Models/GrpcServiceDefinition.cs create mode 100644 src/ServerlessWorkflow.Sdk/Models/HttpRequest.cs create mode 100644 src/ServerlessWorkflow.Sdk/Models/HttpResponse.cs create mode 100644 src/ServerlessWorkflow.Sdk/Models/InputDataModelDefinition.cs rename src/ServerlessWorkflow.Sdk/Models/{States/SleepStateDefinition.cs => JitterDefinition.cs} (50%) create mode 100644 src/ServerlessWorkflow.Sdk/Models/LinearBackoffDefinition.cs create mode 100644 src/ServerlessWorkflow.Sdk/Models/ListenerDefinition.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Models/OAuth2AuthenticationProperties.cs create mode 100644 src/ServerlessWorkflow.Sdk/Models/OAuth2GrantType.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Models/OneOf.cs rename src/ServerlessWorkflow.Sdk/Models/{EventCaseDefinition.cs => OutputDataModelDefinition.cs} (57%) create mode 100644 src/ServerlessWorkflow.Sdk/Models/ProcessDefinition.cs create mode 100644 src/ServerlessWorkflow.Sdk/Models/ProcessType.cs create mode 100644 src/ServerlessWorkflow.Sdk/Models/ProcessTypeDefinition.cs create mode 100644 src/ServerlessWorkflow.Sdk/Models/Processes/ContainerProcessDefinition.cs create mode 100644 src/ServerlessWorkflow.Sdk/Models/Processes/ScriptProcessDefinition.cs create mode 100644 src/ServerlessWorkflow.Sdk/Models/Processes/ShellProcessDefinition.cs create mode 100644 src/ServerlessWorkflow.Sdk/Models/Processes/WorkflowProcessDefinition.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Models/ProduceEventDefinition.cs create mode 100644 src/ServerlessWorkflow.Sdk/Models/RaiseErrorDefinition.cs create mode 100644 src/ServerlessWorkflow.Sdk/Models/ReferenceableComponentDefinition.cs create mode 100644 src/ServerlessWorkflow.Sdk/Models/RetryAttemptLimitDefinition.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Models/RetryDefinition.cs create mode 100644 src/ServerlessWorkflow.Sdk/Models/RetryPolicyDefinition.cs create mode 100644 src/ServerlessWorkflow.Sdk/Models/RetryPolicyLimitDefinition.cs create mode 100644 src/ServerlessWorkflow.Sdk/Models/RuntimeExpressionEvaluationConfiguration.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Models/ScheduleDefinition.cs create mode 100644 src/ServerlessWorkflow.Sdk/Models/SchemaDefinition.cs create mode 100644 src/ServerlessWorkflow.Sdk/Models/SchemaFormat.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Models/SecretBasedAuthenticationProperties.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Models/StartDefinition.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Models/StateDataFilterDefinition.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Models/StateDefinition.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Models/States/CallbackStateDefinition.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Models/States/EventStateDefinition.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Models/States/ForEachStateDefinition.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Models/States/OperationStateDefinition.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Models/States/ParallelStateDefinition.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Models/States/SwitchStateDefinition.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Models/SubflowReference.cs create mode 100644 src/ServerlessWorkflow.Sdk/Models/TaskDefinition.cs create mode 100644 src/ServerlessWorkflow.Sdk/Models/TaskExecutionStrategyDefinition.cs create mode 100644 src/ServerlessWorkflow.Sdk/Models/TaskType.cs create mode 100644 src/ServerlessWorkflow.Sdk/Models/Tasks/CallTaskDefinition.cs create mode 100644 src/ServerlessWorkflow.Sdk/Models/Tasks/CompositeTaskDefinition.cs create mode 100644 src/ServerlessWorkflow.Sdk/Models/Tasks/EmitTaskDefinition.cs rename src/ServerlessWorkflow.Sdk/{Extensions/JsonElementExtensions.cs => Models/Tasks/ExtensionTaskDefinition.cs} (52%) create mode 100644 src/ServerlessWorkflow.Sdk/Models/Tasks/ForTaskDefinition.cs create mode 100644 src/ServerlessWorkflow.Sdk/Models/Tasks/ListenTaskDefinition.cs create mode 100644 src/ServerlessWorkflow.Sdk/Models/Tasks/RaiseTaskDefinition.cs create mode 100644 src/ServerlessWorkflow.Sdk/Models/Tasks/RunTaskDefinition.cs create mode 100644 src/ServerlessWorkflow.Sdk/Models/Tasks/SetTaskDefinition.cs create mode 100644 src/ServerlessWorkflow.Sdk/Models/Tasks/SwitchTaskDefinition.cs create mode 100644 src/ServerlessWorkflow.Sdk/Models/Tasks/TryTaskDefinition.cs create mode 100644 src/ServerlessWorkflow.Sdk/Models/Tasks/WaitTaskDefinition.cs rename src/ServerlessWorkflow.Sdk/Models/{ExtensionAuthenticationProperties.cs => TimeoutDefinition.cs} (60%) delete mode 100644 src/ServerlessWorkflow.Sdk/Models/TransitionDefinition.cs create mode 100644 src/ServerlessWorkflow.Sdk/Models/WorkflowDefinitionMetadata.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Models/WorkflowExecutionTimeoutDefinition.cs create mode 100644 src/ServerlessWorkflow.Sdk/Models/WorkflowScheduleDefinition.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Models/WorkflowTimeoutDefinition.cs create mode 100644 src/ServerlessWorkflow.Sdk/NamingConvention.cs delete mode 100644 src/ServerlessWorkflow.Sdk/OAuth2GrantType.cs delete mode 100644 src/ServerlessWorkflow.Sdk/OAuth2TokenType.cs delete mode 100644 src/ServerlessWorkflow.Sdk/ParallelCompletionType.cs rename src/ServerlessWorkflow.Sdk/{InvocationMode.cs => RuntimeExpressionEvaluationMode.cs} (53%) create mode 100644 src/ServerlessWorkflow.Sdk/RuntimeExpressions.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Serialization/Json/DictionaryConverter.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Serialization/Json/Iso8601TimeSpanConverter.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Serialization/Json/JsonTypeInfoModifiers.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Serialization/Json/OneOfConverter.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Serialization/Json/Serializer.cs create mode 100644 src/ServerlessWorkflow.Sdk/Serialization/Json/TaskDefinitionJsonConverter.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Serialization/Yaml/ChainedObjectGraphVisitor.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Serialization/Yaml/IExtensibleDeserializer.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Serialization/Yaml/InferTypeResolver.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Serialization/Yaml/Iso8601TimeSpanSerializer.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Serialization/Yaml/JsonElementConverter.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Serialization/Yaml/JsonNodeConverter.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Serialization/Yaml/OneOfConverter.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Serialization/Yaml/OneOfDeserializer.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Serialization/Yaml/Serializer.cs rename src/ServerlessWorkflow.Sdk/Serialization/Yaml/{Iso8601TimeSpanConverter.cs => TaskDefinitionYamlConverter.cs} (50%) delete mode 100644 src/ServerlessWorkflow.Sdk/Serialization/Yaml/UriTypeSerializer.cs delete mode 100644 src/ServerlessWorkflow.Sdk/ServerlessWorkflowSpecVersion.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Services/FluentBuilders/ActionBuilder.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Services/FluentBuilders/AuthenticationDefinitionBuilder.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Services/FluentBuilders/BasicAuthenticationBuilder.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Services/FluentBuilders/BearerAuthenticationBuilder.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Services/FluentBuilders/BranchBuilder.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Services/FluentBuilders/CallbackStateBuilder.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Services/FluentBuilders/DataSwitchCaseBuilder.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Services/FluentBuilders/ErrorHandlerBuilder.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Services/FluentBuilders/EventBuilder.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Services/FluentBuilders/EventStateBuilder.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Services/FluentBuilders/EventStateTriggerBuilder.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Services/FluentBuilders/EventSwitchCaseBuilder.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Services/FluentBuilders/ForEachStateBuilder.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Services/FluentBuilders/FunctionBuilder.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Services/FluentBuilders/InjectStateBuilder.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IActionBuilder.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IActionCollectionBuilder.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IActionContainerBuilder.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IAuthenticationDefinitionBuilder.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IBasicAuthenticationBuilder.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IBearerAuthenticationBuilder.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IBranchBuilder.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/ICallbackStateBuilder.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IDataSwitchCaseBuilder.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IDataSwitchStateBuilder.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IErrorHandlerBuilder.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IEventBuilder.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IEventStateBuilder.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IEventStateTriggerBuilder.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IEventSwitchCaseBuilder.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IEventSwitchStateBuilder.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IEventTriggerActionBuilder.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IExtensibleBuilder.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IForEachStateBuilder.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IFunctionActionBuilder.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IFunctionBuilder.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IMetadataContainerBuilder.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IOAuth2AuthenticationBuilder.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IParallelStateBuilder.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IPipelineBuilder.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IRetryStrategyBuilder.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IScheduleBuilder.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IStateBuilder.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IStateBuilderFactory.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IStateOutcomeBuilder.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/ISubflowActionBuilder.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/ISubflowRunnerBuilder.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/ISwitchStateBuilder.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IWorkflowBuilder.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IWorkflowExecutionTimeoutBuilder.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Services/FluentBuilders/MetadataContainerBuilder.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Services/FluentBuilders/OAuth2AuthenticationBuilder.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Services/FluentBuilders/OperationStateBuilder.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Services/FluentBuilders/ParallelStateBuilder.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Services/FluentBuilders/PipelineBuilder.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Services/FluentBuilders/RetryStrategyBuilder.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Services/FluentBuilders/ScheduleBuilder.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Services/FluentBuilders/SleepStateBuilder.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Services/FluentBuilders/StateBuilder.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Services/FluentBuilders/StateBuilderFactory.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Services/FluentBuilders/StateOutcomeBuilder.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Services/FluentBuilders/SwitchCaseBuilder.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Services/FluentBuilders/SwitchStateBuilder.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Services/FluentBuilders/WorkflowBuilder.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Services/FluentBuilders/WorkflowExecutionTimeoutBuilder.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Services/IO/Interfaces/IWorkflowExternalDefinitionResolver.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Services/IO/WorkflowExternalDefinitionResolver.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Services/IO/WorkflowReader.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Services/IO/WorkflowReaderOptions.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Services/IO/WorkflowWriter.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Services/Validation/ActionDefinitionValidator.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Services/Validation/AuthenticationDefinitionValidator.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Services/Validation/BasicAuthenticationPropertiesValidator.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Services/Validation/BearerAuthenticationPropertiesValidator.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Services/Validation/CallbackStateValidator.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Services/Validation/CollectionPropertyValidator.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Services/Validation/DataCaseDefinitionValidator.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Services/Validation/DefaultCaseDefinitionValidator.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Services/Validation/ErrorHandlerDefinitionValidator.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Services/Validation/EventCaseDefinitionValidator.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Services/Validation/EventReferenceValidator.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Services/Validation/EventStateTriggerDefinitionValidator.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Services/Validation/EventStateValidator.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Services/Validation/ForEachStateValidator.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Services/Validation/FunctionDefinitionCollectionValidator.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Services/Validation/FunctionDefinitionValidator.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Services/Validation/FunctionReferenceValidator.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Services/Validation/InjectStateValidator.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Services/Validation/Interfaces/IWorkflowSchemaValidator.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Services/Validation/Interfaces/IWorkflowValidationResult.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Services/Validation/Interfaces/IWorkflowValidator.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Services/Validation/OAuth2AuthenticationPropertiesValidator.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Services/Validation/OperationStateValidator.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Services/Validation/RetryStrategyDefinitionValidator.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Services/Validation/SleepStateValidator.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Services/Validation/StateDefinitionValidator.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Services/Validation/SubflowReferenceValidator.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Services/Validation/SwitchCaseDefinitionValidator.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Services/Validation/SwitchStateValidator.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Services/Validation/TransitionDefinitionValidator.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Services/Validation/WorkflowDefinitionValidator.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Services/Validation/WorkflowSchemaValidator.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Services/Validation/WorkflowStatesPropertyValidator.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Services/Validation/WorkflowValidationResult.cs delete mode 100644 src/ServerlessWorkflow.Sdk/Services/Validation/WorkflowValidator.cs delete mode 100644 src/ServerlessWorkflow.Sdk/StateType.cs delete mode 100644 src/ServerlessWorkflow.Sdk/SwitchCaseOutcomeType.cs delete mode 100644 src/ServerlessWorkflow.Sdk/SwitchStateType.cs rename src/ServerlessWorkflow.Sdk/{ActionExecutionMode.cs => TaskExecutionMode.cs} (71%) delete mode 100644 src/ServerlessWorkflow.Sdk/icon.png delete mode 100644 tests/ServerlessWorkflow.Sdk.UnitTests/Assets/WorkflowExtensions/condition-state-type.json delete mode 100644 tests/ServerlessWorkflow.Sdk.UnitTests/Assets/WorkflowExtensions/greet-function-type.json create mode 100644 tests/ServerlessWorkflow.Sdk.UnitTests/Cases/Builders/WorkflowDefinitionBuilderTests.cs delete mode 100644 tests/ServerlessWorkflow.Sdk.UnitTests/Cases/FluentBuilder/FluentBuilderTests.cs create mode 100644 tests/ServerlessWorkflow.Sdk.UnitTests/Cases/IO/WorkflowDefinitionReaderTests.cs create mode 100644 tests/ServerlessWorkflow.Sdk.UnitTests/Cases/IO/WorkflowDefinitionWriterTests.cs delete mode 100644 tests/ServerlessWorkflow.Sdk.UnitTests/Cases/IO/WorkflowReaderTests.cs delete mode 100644 tests/ServerlessWorkflow.Sdk.UnitTests/Cases/IO/WorkflowWriterTests.cs delete mode 100644 tests/ServerlessWorkflow.Sdk.UnitTests/Cases/Serialization/JsonSerializationTests.cs delete mode 100644 tests/ServerlessWorkflow.Sdk.UnitTests/Cases/Serialization/YamlSerializationTests.cs delete mode 100644 tests/ServerlessWorkflow.Sdk.UnitTests/Cases/SerializationTestsBase.cs delete mode 100644 tests/ServerlessWorkflow.Sdk.UnitTests/Cases/Validation/ActionValidationTests.cs delete mode 100644 tests/ServerlessWorkflow.Sdk.UnitTests/Cases/Validation/CallbackStateValidationTests.cs delete mode 100644 tests/ServerlessWorkflow.Sdk.UnitTests/Cases/Validation/EventReferenceValidationTests.cs delete mode 100644 tests/ServerlessWorkflow.Sdk.UnitTests/Cases/Validation/EventStateTriggerValidationTests.cs delete mode 100644 tests/ServerlessWorkflow.Sdk.UnitTests/Cases/Validation/EventStateValidationTests.cs delete mode 100644 tests/ServerlessWorkflow.Sdk.UnitTests/Cases/Validation/FunctionDefinitionValidationTests.cs delete mode 100644 tests/ServerlessWorkflow.Sdk.UnitTests/Cases/Validation/FunctionReferenceValidationTests.cs delete mode 100644 tests/ServerlessWorkflow.Sdk.UnitTests/Cases/Validation/InjectStateValidationTests.cs delete mode 100644 tests/ServerlessWorkflow.Sdk.UnitTests/Cases/Validation/OperationStateValidationTests.cs delete mode 100644 tests/ServerlessWorkflow.Sdk.UnitTests/Cases/Validation/SubflowReferenceValidationTests.cs delete mode 100644 tests/ServerlessWorkflow.Sdk.UnitTests/Cases/Validation/SwitchStateValidationTests.cs delete mode 100644 tests/ServerlessWorkflow.Sdk.UnitTests/Cases/Validation/WorkflowValidationTests.cs create mode 100644 tests/ServerlessWorkflow.Sdk.UnitTests/CloudFlows.Sdk.UnitTests.csproj delete mode 100644 tests/ServerlessWorkflow.Sdk.UnitTests/Resources/auths/default.json delete mode 100644 tests/ServerlessWorkflow.Sdk.UnitTests/Resources/auths/default.yaml delete mode 100644 tests/ServerlessWorkflow.Sdk.UnitTests/Resources/constants/petstore.json delete mode 100644 tests/ServerlessWorkflow.Sdk.UnitTests/Resources/constants/petstore.yaml delete mode 100644 tests/ServerlessWorkflow.Sdk.UnitTests/Resources/dataSchemas/input-data-schema.json delete mode 100644 tests/ServerlessWorkflow.Sdk.UnitTests/Resources/events/petstore.json delete mode 100644 tests/ServerlessWorkflow.Sdk.UnitTests/Resources/events/petstore.yaml delete mode 100644 tests/ServerlessWorkflow.Sdk.UnitTests/Resources/extensions/state-type-extension.json delete mode 100644 tests/ServerlessWorkflow.Sdk.UnitTests/Resources/functions/petstore.json delete mode 100644 tests/ServerlessWorkflow.Sdk.UnitTests/Resources/functions/petstore.yaml delete mode 100644 tests/ServerlessWorkflow.Sdk.UnitTests/Resources/retries/default.json delete mode 100644 tests/ServerlessWorkflow.Sdk.UnitTests/Resources/retries/default.yaml delete mode 100644 tests/ServerlessWorkflow.Sdk.UnitTests/Resources/schemas/externalref.json delete mode 100644 tests/ServerlessWorkflow.Sdk.UnitTests/Resources/schemas/externalref.yaml delete mode 100644 tests/ServerlessWorkflow.Sdk.UnitTests/Resources/schemas/input-data.json delete mode 100644 tests/ServerlessWorkflow.Sdk.UnitTests/Resources/secrets/default.json delete mode 100644 tests/ServerlessWorkflow.Sdk.UnitTests/Resources/secrets/default.yaml delete mode 100644 tests/ServerlessWorkflow.Sdk.UnitTests/Resources/workflows/extended.json delete mode 100644 tests/ServerlessWorkflow.Sdk.UnitTests/Resources/workflows/external-function-definition.json delete mode 100644 tests/ServerlessWorkflow.Sdk.UnitTests/Resources/workflows/external-input-data-schema.json delete mode 100644 tests/ServerlessWorkflow.Sdk.UnitTests/Resources/workflows/externalref.json delete mode 100644 tests/ServerlessWorkflow.Sdk.UnitTests/Resources/workflows/externalref.yaml delete mode 100644 tests/ServerlessWorkflow.Sdk.UnitTests/Resources/workflows/input-data-schema.json delete mode 100644 tests/ServerlessWorkflow.Sdk.UnitTests/Resources/workflows/missing-transition.json delete mode 100644 tests/ServerlessWorkflow.Sdk.UnitTests/Resources/workflows/operation.json delete mode 100644 tests/ServerlessWorkflow.Sdk.UnitTests/Resources/workflows/operation.yaml delete mode 100644 tests/ServerlessWorkflow.Sdk.UnitTests/ServerlessWorkflow.Sdk.UnitTests.csproj diff --git a/.editorconfig b/.editorconfig index 5d532cf..1e82c2d 100644 --- a/.editorconfig +++ b/.editorconfig @@ -66,6 +66,7 @@ dotnet_style_prefer_compound_assignment = true:suggestion dotnet_style_prefer_simplified_interpolation = true:suggestion dotnet_style_namespace_match_folder = true:suggestion dotnet_style_readonly_field = true:suggestion +dotnet_style_prefer_collection_expression = when_types_loosely_match:suggestion [*.cs] csharp_indent_labels = one_less_than_current @@ -98,4 +99,5 @@ csharp_style_deconstructed_variable_declaration = true:suggestion csharp_style_unused_value_assignment_preference = discard_variable:suggestion csharp_style_unused_value_expression_statement_preference = discard_variable:silent -file_header_template = Copyright © 2023-Present The Serverless Workflow Specification Authors\n\nLicensed under the Apache License, Version 2.0 (the "License"),\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\nhttp://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an "AS IS" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License. \ No newline at end of file +file_header_template = Copyright © 2024-Present The Serverless Workflow Specification Authors\n\nLicensed under the Apache License, Version 2.0 (the "License"),\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\nhttp://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an "AS IS" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License. +csharp_style_prefer_primary_constructors = true:suggestion \ No newline at end of file diff --git a/.github/workflows/build-dotnet.yml b/.github/workflows/build-dotnet.yml new file mode 100644 index 0000000..1852267 --- /dev/null +++ b/.github/workflows/build-dotnet.yml @@ -0,0 +1,52 @@ +name: Build .NET + +on: + pull_request: + branches: [ main ] + paths-ignore: + - '.github/**' + - '**/*.md' + - 'assets/**' + - 'deployments/**' + workflow_call: + +env: + SOLUTION: ./ServerlessWorkflow.Sdk.sln + +jobs: + build: + runs-on: ubuntu-latest + strategy: + matrix: + dotnet-version: ['8.0.x' ] + + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 2 + + - name: Pull latest version tag + if: github.event_name != 'pull_request' + run: | + git fetch + git pull + + - name: Setup .NET ${{ matrix.dotnet-version }} + uses: actions/setup-dotnet@v2 + with: + dotnet-version: ${{ matrix.dotnet-version }} + + - name: Restore dependencies + run: dotnet restore "${{ env.SOLUTION }}" + + - name: Build + run: dotnet build "${{ env.SOLUTION }}" --configuration Release --no-restore + + - name: Cache build items + if: github.event_name != 'pull_request' + uses: actions/cache@v3 + id: build-dotnet-cache + with: + path: ./**/Release/*.nupkg + key: build-dotnet-cache-${{ github.sha }} diff --git a/.github/workflows/ci-pipeline.yml b/.github/workflows/ci-pipeline.yml new file mode 100644 index 0000000..6760aab --- /dev/null +++ b/.github/workflows/ci-pipeline.yml @@ -0,0 +1,35 @@ +name: Continuous integration + +on: + push: + branches: [ main ] + paths-ignore: + - '.github/**' + - '**/*.md' + - 'assets/**' + - 'deployments/**' + workflow_dispatch: + +jobs: + + #test: + # # Skip if it's not running in the main branch of the `serverlessworkflow/sdk-net` repo + # if: github.repository == 'serverlessworkflow/sdk-net' && github.ref_name == 'main' + # uses: ./.github/serverlessworkflow/sdk-net/test-dotnet.yml + # secrets: inherit + + versioning: + #needs: [test] + if: github.repository == 'cloud-flows/sdk-net' && github.ref_name == 'main' + uses: ./.github/workflows/versioning.yml + secrets: inherit + + build: + needs: [versioning] + uses: ./.github/workflows/build-dotnet.yml + secrets: inherit + + release: + needs: [build] + uses: ./.github/workflows/release.yml + secrets: inherit diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml deleted file mode 100644 index 5c23d65..0000000 --- a/.github/workflows/dotnet.yml +++ /dev/null @@ -1,24 +0,0 @@ -name: Publish Packages - -on: - push: - branches: [ main ] - -jobs: - build: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v2 - - name: Setup .NET - uses: actions/setup-dotnet@v1 - with: - dotnet-version: 7.0.x - - name: Install dependencies - run: dotnet restore "./ServerlessWorkflow.Sdk.sln" - - name: Build - run: dotnet build "./ServerlessWorkflow.Sdk.sln" --configuration Release --no-restore - #- name: Test - # run: dotnet test "./ServerlessWorkflow.Sdk.sln" --no-restore --verbosity detailed - - name: Push1 - run: dotnet nuget push "./src/*/bin/Release/*.nupkg" --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json --skip-duplicate diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..b8af145 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,26 @@ +name: Manual publish of .NET packages + +on: + release: + types: [published] + workflow_dispatch: + +env: + SOLUTION: ./ServerlessWorkflow.Sdk.sln + REGISTRY: ghcr.io + +jobs: + publish-packages: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Setup .NET + uses: actions/setup-dotnet@v1 + with: + dotnet-version: 8.0.x + - name: Restore dependencies + run: dotnet restore "${{ env.SOLUTION }}" + - name: Build + run: dotnet build "${{ env.SOLUTION }}" --configuration Release --no-restore + - name: Push1 + run: dotnet nuget push "./src/*/bin/Release/*.nupkg" --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json --skip-duplicate diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..de61acc --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,39 @@ +name: Release + +on: + workflow_call: + +jobs: + release: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Pull latest version tag + run: | + git fetch + git pull + LATEST_TAG=$(git describe --tags $(git rev-list --tags --max-count=1)) + echo "LATEST_TAG=$LATEST_TAG" >> $GITHUB_ENV + echo "LATEST_VERSION=${LATEST_TAG:1}" >> $GITHUB_ENV + + - name: Retrieve build items + uses: actions/cache@v3 + id: build-dotnet-cache + with: + path: ./**/Release/*.nupkg + key: build-dotnet-cache-${{ github.sha }} + + - name: Release + uses: softprops/action-gh-release@v1 + with: + tag_name: ${{ env.LATEST_TAG }} + name: ${{ env.LATEST_VERSION }} + token: ${{ secrets.BOT_PAT }} + generate_release_notes: true + files: | + LICENSE + # other files will be appended during/after publish \ No newline at end of file diff --git a/.github/workflows/test-dotnet.yml b/.github/workflows/test-dotnet.yml new file mode 100644 index 0000000..6bc95a6 --- /dev/null +++ b/.github/workflows/test-dotnet.yml @@ -0,0 +1,41 @@ +name: Test .NET + +on: + pull_request: + branches: [ main ] + paths-ignore: + - '.github/**' + - '**/*.md' + - 'assets/**' + - 'deployments/**' + workflow_call: + +env: + SOLUTION: ./ServerlessWorkflow.Sdk.sln + +jobs: + build: + runs-on: ubuntu-latest + strategy: + matrix: + dotnet-version: ['8.0.x' ] + + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Setup .NET ${{ matrix.dotnet-version }} + uses: actions/setup-dotnet@v2 + with: + dotnet-version: ${{ matrix.dotnet-version }} + + - name: Restore dependencies + run: dotnet restore "${{ env.SOLUTION }}" + + # - name: Test + # run: dotnet test "${{ env.SOLUTION }}" --no-restore --verbosity normal" + + # Test "per domain" for ease of readability + - name: Test Core + run: dotnet test "${{ env.SOLUTION }}" --no-restore --filter "FullyQualifiedName~Cases.Core" + # ... diff --git a/.github/workflows/versioning.yml b/.github/workflows/versioning.yml new file mode 100644 index 0000000..d4664eb --- /dev/null +++ b/.github/workflows/versioning.yml @@ -0,0 +1,28 @@ +name: Auto Versioning .NET + +on: + workflow_call: + +jobs: + increment-version: + runs-on: windows-latest + + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + token: ${{ secrets.BOT_PAT }} + + - name: Reset Origin + run: | + git remote set-url origin "https://${{ secrets.BOT_USERNAME }}:${{ secrets.BOT_PAT }}@github.com/${{ github.repository }}.git" + git checkout ${{ github.ref_name }} + + - name: Install Versioning.NET + run: | + dotnet tool install --global Versioning.NET + + - name: Increment Version + run: | + dotnet-version increment-version-with-git-hints -g "." --branch-name ${{ github.ref_name }} --author-email ${{ secrets.BOT_EMAIL }} diff --git a/README.md b/README.md index a5b9689..975013a 100644 --- a/README.md +++ b/README.md @@ -1,250 +1,56 @@ -![Publish Packages](https://github.com/serverlessworkflow/sdk-net/workflows/Publish%20Packages/badge.svg) [![Gitpod ready-to-code](https://img.shields.io/badge/Gitpod-ready--to--code-blue?logo=gitpod)](https://gitpod.io/#https://github.com/serverlessworkflow/sdk-net) +# Serverless Workflow .NET SDK +The official .NET SDK for the [Serverless Workflow DSL](https://github.com/serverlessworkflow/specification/blob/main/dsl.md). -# Serverless Workflow Specification - .NET SDK +The SDK is composed of three Nuget packages: -Provides .NET 7.0 API/SPI and Model Validation for the [Serverless Workflow Specification](https://github.com/serverlessworkflow/specification) +- [Core](#), which contains the models of the Serverless Workflow DSL +- [Builders](#), which contains service used to build workflow definitions programmatically +- [IO](#), which contains the services used to read and write workflow definitions -With the SDK, you can: +## Installation -- [x] Read and write workflow JSON and YAML definitions -- [x] Programmatically build workflow definitions -- [x] Validate workflow definitions (both schema and DSL integrity validation) - -### Status - -| Latest Releases | Conformance to spec version | -| :---: | :---: | -| [0.8.7](https://github.com/serverlessworkflow/sdk-net/releases/) | [0.8](https://github.com/serverlessworkflow/specification/tree/0.8.x) | - -### Getting Started +Core: ```bash -dotnet nuget add package ServerlessWorkflow.Sdk -``` - -```csharp -services.AddServerlessWorkflow(); -``` - -### Usage - -#### Build workflows programatically - -```csharp -var workflow = WorkflowDefinition.Create("MyWorkflow", "MyWorkflow", "1.0") - .StartsWith("inject", flow => - flow.Inject(new { username = "test", password = "123456" })) - .Then("operation", flow => - flow.Execute("fakeApiFunctionCall", action => - { - action.Invoke(function => - function.WithName("fakeFunction") - .SetOperationUri(new Uri("https://fake.com/swagger.json#fake"))) - .WithArgument("username", "${ .username }") - .WithArgument("password", "${ .password }"); - }) - .Execute("fakeEventTrigger", action => - { - action - .Consume(e => - e.WithName("fakeEvent") - .WithSource(new Uri("https://fakesource.com")) - .WithType("fakeType")) - .ThenProduce(e => - e.WithName("otherEvent") - .WithSource(new Uri("https://fakesource.com")) - .WithType("fakeType")); - })) - .End() - .Build(); +dotnet add package ServerlessWorkflow.Sdk ``` -#### Read workflows +Builders: -```csharp -var reader = WorkflowReader.Create(); -using(Stream stream = File.OpenRead("myWorkflow.json")) -{ - var definition = reader.Read(stream, WorkflowDefinitionFormat.Json); -} ``` - -#### Write workflows - -```csharp - var writer = WorkflowWriter.Create(); - using(Stream stream = new MemoryStream()) - { - writer.Write(workflow, stream); - stream.Flush(); - stream.Position = 0; - using(StreamReader reader = new StreamReader(stream)) - { - var yaml = reader.ReadToEnd(); - Console.WriteLine(yaml); - Console.ReadLine(); - } - } +dotnet add package ServerlessWorkflow.Sdk.Builders ``` -#### Validate workflows +IO: -```csharp -var validator = serviceProvider.GetRequiredService>(); -var validationResult = validator.Validate(myWorkflow); ``` - -#### Extend Workflows - -The SDK allows extending the Serverless Workflow in two ways, possibly combined: via metadata and via extensions. - -#### Metadata - -Workflow components that support metadata, such as `WorkflowDefinition` or `StateDefinition`, expose a `metadata` property, -which is a dynamic name/value mapping of properties used to enrich the serverless workflow model with information beyond its core definitions. - -It has the advantage of being an easy, cross-compatible way of declaring additional data, but lacks well-defined, well-documented schema of the data, thus loosing the ability to validate it -without custom implementation. - -*Adding metadata to a workflow:* -```csharp -var workflow = new WorkflowBuilder() - ... - .WithMetadata(new Dictionary() { { "metadataPropertyName", metadataPropertyValue } }) - ... - .Build(); +dotnet add package ServerlessWorkflow.Sdk.IO ``` -*Resulting workflow:* +## Example usage -```yaml -id: sample-workflow -version: 1.0.0 -specVersion: 0.8 -metadata: - metadataPropertyName: metadataPropertyValue #added to the metadata property of supporting components -... -``` - - -#### Extension - -Users have the ability to define extensions, providing the ability to extend, override or replace parts of the Serverless Workflow schema. - -To do so, you must first create a file containing the JsonSchema of your extension, then reference it in your workflow definition. - -*Schema of a sample extension that adds a new `greet` `functionType`:* - - - - - - - - - - -
JSONYAML
- -```json -{ - "$defs": { - "functions": { - "definitions": { - "function": { - "type": "object", - "properties": { - "type": { - "type": "string", - "description": "Defines the function type. Is either `rest`, `asyncapi, `rpc`, `graphql`, `odata`, `expression` or `greet`. Default is `rest`", - "enum": [ - "rest", - "asyncapi", - "rpc", - "graphql", - "odata", - "expression", - "custom", - "greet" - ], - "default": "rest" - } - } - } - } - } - } -} -``` - - - -```yaml -'$defs': - functions: - definitions: - function: - type: object - properties: - type: - type: string - description: Defines the function type. Is either `rest`, `asyncapi, `rpc`, - `graphql`, `odata`, `expression` or `greet`. Default is `rest` - enum: - - rest - - asyncapi - - rpc - - graphql - - odata - - expression - - custom - - greet - default: rest -``` - -
+Building a workflow definition programmatically: -The above example refers to `/$defs/functions`, because upon validation the SDK bundles all the Serverless Workflow Specification's schemas into the `$defs` property of a single schema. - -*In this case, `functions` is the extensionless name of the schema file we want to override (https://serverlessworkflow.io/schemas/latest/functions.json). - -A [Json Merge Patch](https://datatracker.ietf.org/doc/html/rfc7386) is performed sequentially on the bundled schema with the defined extensions, in declaring order. - -*In this case, the above schema will patch the object defined at `/functions/definitions/function` in file https://serverlessworkflow.io/schemas/latest/functions.json* - -*Extending a workflow:* -```csharp -var workflow = new WorkflowBuilder() - .WithId("sample-extended") - .WithName("Sample Extended Workflow") - .WithVersion("1.0.0") - .UseSpecVersion(ServerlessWorkflowSpecVersion.V08) - .UseExtension("extensionId", new Uri("file://.../extensions/greet-function-type.json")) - .StartsWith("do-work", flow => flow.Execute("greet", action => action - .Invoke(function => function - .OfType("greet") - .WithName("greet") - .ForOperation("#")))) - .End() +```c# +var definition = new WorkflowDefinitionBuilder() + .WithName("fake-workflow") + .WithVersion("0.1.0:fake") + .Do("todo-1", task => task + .Call("http") + .With("method", "get") + .With("uri", "https://fake-api.com")) .Build(); ``` -*Adding extension properties:* -```csharp -var workflow = new WorkflowBuilder() - ... - .WithExtensionProperty("extensionPropertyName", propertyValue } }) - ... - .Build(); -``` +Reading and writing a workflow definition: -*Resulting workflow:* +```c# +using var inputStream = File.OpenRead("workflow.yaml"); +var reader = WorkflowDefinitionReader.Create(); +var workflow = await reader.ReadAsync(inputStream); -```yaml -id: sample-workflow -version: 1.0.0 -specVersion: 0.8 -extensionPropertyName: propertyValue #added as top level property of extended component, as opposed to metadata -... -``` \ No newline at end of file +using var outputStream = File.Create("workflow.yaml"); +var writer = WorkflowDefinitionWriter.Create(); +await writer.WriteAsync(workflow, stream, WorkflowDefinitionFormat.Yaml); +``` diff --git a/ServerlessWorkflow.Sdk.sln b/ServerlessWorkflow.Sdk.sln index 7578fae..913c969 100644 --- a/ServerlessWorkflow.Sdk.sln +++ b/ServerlessWorkflow.Sdk.sln @@ -17,36 +17,50 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "docs", "docs", "{0CD38EC5-C README.md = README.md EndProjectSection EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ServerlessWorkflow.Sdk", "src\ServerlessWorkflow.Sdk\ServerlessWorkflow.Sdk.csproj", "{1C104B2C-A3E8-4CB9-AE1D-28370B7A705D}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ServerlessWorkflow.Sdk.UnitTests", "tests\ServerlessWorkflow.Sdk.UnitTests\ServerlessWorkflow.Sdk.UnitTests.csproj", "{F1575E10-B57B-4012-97FF-AF942A558D7C}" -EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "solution", "solution", "{F3B6D944-46DA-4CAF-A8BE-0C8F230869F9}" ProjectSection(SolutionItems) = preProject .editorconfig = .editorconfig EndProjectSection EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ServerlessWorkflow.Sdk", "src\ServerlessWorkflow.Sdk\ServerlessWorkflow.Sdk.csproj", "{8D4E5FB8-79BC-442B-852F-5891B39A5A1C}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ServerlessWorkflow.Sdk.Builders", "src\ServerlessWorkflow.Sdk.Builders\ServerlessWorkflow.Sdk.Builders.csproj", "{53A4A0D8-E2F4-43BC-808F-37B1EB7837DE}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ServerlessWorkflow.Sdk.IO", "src\ServerlessWorkflow.Sdk.IO\ServerlessWorkflow.Sdk.IO.csproj", "{9993989F-B8D6-481C-A59C-A76070CA32F4}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CloudFlows.Sdk.UnitTests", "tests\ServerlessWorkflow.Sdk.UnitTests\CloudFlows.Sdk.UnitTests.csproj", "{7BFC0DDB-7864-4C5A-AC91-EB7B3E93242E}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU Release|Any CPU = Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {1C104B2C-A3E8-4CB9-AE1D-28370B7A705D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {1C104B2C-A3E8-4CB9-AE1D-28370B7A705D}.Debug|Any CPU.Build.0 = Debug|Any CPU - {1C104B2C-A3E8-4CB9-AE1D-28370B7A705D}.Release|Any CPU.ActiveCfg = Release|Any CPU - {1C104B2C-A3E8-4CB9-AE1D-28370B7A705D}.Release|Any CPU.Build.0 = Release|Any CPU - {F1575E10-B57B-4012-97FF-AF942A558D7C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {F1575E10-B57B-4012-97FF-AF942A558D7C}.Debug|Any CPU.Build.0 = Debug|Any CPU - {F1575E10-B57B-4012-97FF-AF942A558D7C}.Release|Any CPU.ActiveCfg = Release|Any CPU - {F1575E10-B57B-4012-97FF-AF942A558D7C}.Release|Any CPU.Build.0 = Release|Any CPU + {8D4E5FB8-79BC-442B-852F-5891B39A5A1C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8D4E5FB8-79BC-442B-852F-5891B39A5A1C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8D4E5FB8-79BC-442B-852F-5891B39A5A1C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8D4E5FB8-79BC-442B-852F-5891B39A5A1C}.Release|Any CPU.Build.0 = Release|Any CPU + {53A4A0D8-E2F4-43BC-808F-37B1EB7837DE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {53A4A0D8-E2F4-43BC-808F-37B1EB7837DE}.Debug|Any CPU.Build.0 = Debug|Any CPU + {53A4A0D8-E2F4-43BC-808F-37B1EB7837DE}.Release|Any CPU.ActiveCfg = Release|Any CPU + {53A4A0D8-E2F4-43BC-808F-37B1EB7837DE}.Release|Any CPU.Build.0 = Release|Any CPU + {9993989F-B8D6-481C-A59C-A76070CA32F4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9993989F-B8D6-481C-A59C-A76070CA32F4}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9993989F-B8D6-481C-A59C-A76070CA32F4}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9993989F-B8D6-481C-A59C-A76070CA32F4}.Release|Any CPU.Build.0 = Release|Any CPU + {7BFC0DDB-7864-4C5A-AC91-EB7B3E93242E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7BFC0DDB-7864-4C5A-AC91-EB7B3E93242E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7BFC0DDB-7864-4C5A-AC91-EB7B3E93242E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7BFC0DDB-7864-4C5A-AC91-EB7B3E93242E}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection GlobalSection(NestedProjects) = preSolution - {1C104B2C-A3E8-4CB9-AE1D-28370B7A705D} = {9016CF88-4100-425F-9E1A-B6099F55A35B} - {F1575E10-B57B-4012-97FF-AF942A558D7C} = {60FE2678-84CF-492C-950D-3485582F6712} + {8D4E5FB8-79BC-442B-852F-5891B39A5A1C} = {9016CF88-4100-425F-9E1A-B6099F55A35B} + {53A4A0D8-E2F4-43BC-808F-37B1EB7837DE} = {9016CF88-4100-425F-9E1A-B6099F55A35B} + {9993989F-B8D6-481C-A59C-A76070CA32F4} = {9016CF88-4100-425F-9E1A-B6099F55A35B} + {7BFC0DDB-7864-4C5A-AC91-EB7B3E93242E} = {60FE2678-84CF-492C-950D-3485582F6712} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {1402FB0B-4169-41A6-A372-DA260E79481B} diff --git a/src/ServerlessWorkflow.Sdk.Builders/AuthenticationPolicyDefinitionBuilder.cs b/src/ServerlessWorkflow.Sdk.Builders/AuthenticationPolicyDefinitionBuilder.cs new file mode 100644 index 0000000..2045432 --- /dev/null +++ b/src/ServerlessWorkflow.Sdk.Builders/AuthenticationPolicyDefinitionBuilder.cs @@ -0,0 +1,65 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Builders; + +/// +/// Represents the default implementation of the interface +/// +public class AuthenticationPolicyDefinitionBuilder + : IAuthenticationPolicyDefinitionBuilder +{ + + /// + /// Gets/sets the to use + /// + protected IAuthenticationSchemeDefinitionBuilder? SchemeBuilder { get; set; } + + /// + public virtual IBasicAuthenticationSchemeDefinitionBuilder Basic() + { + var builder = new BasicAuthenticationSchemeDefinitionBuilder(); + this.SchemeBuilder = builder; + return builder; + } + + /// + public virtual IBearerAuthenticationSchemeDefinitionBuilder Bearer() + { + var builder = new BearerAuthenticationSchemeDefinitionBuilder(); + this.SchemeBuilder = builder; + return builder; + } + + /// + public virtual IOAuth2AuthenticationSchemeDefinitionBuilder OAuth2() + { + var builder = new OAuth2AuthenticationSchemeDefinitionBuilder(); + this.SchemeBuilder = builder; + return builder; + } + + /// + public virtual AuthenticationPolicyDefinition Build() + { + if (this.SchemeBuilder == null) throw new NullReferenceException("The authentication scheme must be set"); + var scheme = this.SchemeBuilder.Build(); + return new() + { + Basic = scheme is BasicAuthenticationSchemeDefinition basic ? basic : null, + Bearer = scheme is BearerAuthenticationSchemeDefinition bearer ? bearer : null, + OAuth2 = scheme is OAuth2AuthenticationSchemeDefinition oauth2 ? oauth2 : null, + }; + } + +} diff --git a/src/ServerlessWorkflow.Sdk.Builders/BackoffStrategyDefinitionBuilder.cs b/src/ServerlessWorkflow.Sdk.Builders/BackoffStrategyDefinitionBuilder.cs new file mode 100644 index 0000000..d117801 --- /dev/null +++ b/src/ServerlessWorkflow.Sdk.Builders/BackoffStrategyDefinitionBuilder.cs @@ -0,0 +1,64 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Builders; + +/// +/// Represents the default implementation of the interface +/// +public class BackoffStrategyDefinitionBuilder + : IBackoffStrategyDefinitionBuilder +{ + + /// + /// Gets the underlying service used to build the to use + /// + protected IBackoffDefinitionBuilder? Backoff { get; set; } + + /// + public virtual IConstantBackoffDefinitionBuilder Constant() + { + var builder = new ConstantBackoffDefinitionBuilder(); + this.Backoff = builder; + return builder; + } + + /// + public virtual IExponentialBackoffDefinitionBuilder Exponential() + { + var builder = new ExponentialBackoffDefinitionBuilder(); + this.Backoff = builder; + return builder; + } + + /// + public virtual ILinearBackoffDefinitionBuilder Linear(Duration? increment = null) + { + var builder = new LinearBackoffDefinitionBuilder(); + this.Backoff = builder; + return builder; + } + + /// + public virtual BackoffStrategyDefinition Build() + { + if (this.Backoff == null) throw new NullReferenceException("The backoff strategy must be set"); + return new() + { + Constant = this.Backoff is ConstantBackoffDefinition constant ? constant : null, + Exponential = this.Backoff is ExponentialBackoffDefinition exponential ? exponential : null, + Linear = this.Backoff is LinearBackoffDefinition linear ? linear : null, + }; + } + +} \ No newline at end of file diff --git a/src/ServerlessWorkflow.Sdk.Builders/BasicAuthenticationSchemeDefinitionBuilder.cs b/src/ServerlessWorkflow.Sdk.Builders/BasicAuthenticationSchemeDefinitionBuilder.cs new file mode 100644 index 0000000..c5f6a8e --- /dev/null +++ b/src/ServerlessWorkflow.Sdk.Builders/BasicAuthenticationSchemeDefinitionBuilder.cs @@ -0,0 +1,63 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Builders; + +/// +/// Represents the default implementation of the interface +/// +public class BasicAuthenticationSchemeDefinitionBuilder + : IBasicAuthenticationSchemeDefinitionBuilder +{ + + /// + /// Gets/sets the username to use + /// + protected string? Username { get; set; } + + /// + /// Gets/sets the password to use + /// + protected string? Password { get; set; } + + /// + public virtual IBasicAuthenticationSchemeDefinitionBuilder WithUsername(string username) + { + ArgumentException.ThrowIfNullOrWhiteSpace(username); + this.Username = username; + return this; + } + + /// + public virtual IBasicAuthenticationSchemeDefinitionBuilder WithPassword(string password) + { + ArgumentException.ThrowIfNullOrWhiteSpace(password); + this.Password = password; + return this; + } + + /// + public virtual BasicAuthenticationSchemeDefinition Build() + { + if (string.IsNullOrWhiteSpace(this.Username)) throw new NullReferenceException("The username must be set"); + if (string.IsNullOrWhiteSpace(this.Password)) throw new NullReferenceException("The password must be set"); + return new() + { + Username = this.Username, + Password = this.Password + }; + } + + AuthenticationSchemeDefinition IAuthenticationSchemeDefinitionBuilder.Build() => this.Build(); + +} diff --git a/src/ServerlessWorkflow.Sdk.Builders/BearerAuthenticationSchemeDefinitionBuilder.cs b/src/ServerlessWorkflow.Sdk.Builders/BearerAuthenticationSchemeDefinitionBuilder.cs new file mode 100644 index 0000000..a7f9099 --- /dev/null +++ b/src/ServerlessWorkflow.Sdk.Builders/BearerAuthenticationSchemeDefinitionBuilder.cs @@ -0,0 +1,48 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Builders; + +/// +/// Represents the default implementation of the interface +/// +public class BearerAuthenticationSchemeDefinitionBuilder + : IBearerAuthenticationSchemeDefinitionBuilder +{ + + /// + /// Gets/sets the bearer token to use + /// + protected string? Token { get; set; } + + /// + public virtual IBearerAuthenticationSchemeDefinitionBuilder WithToken(string token) + { + ArgumentException.ThrowIfNullOrWhiteSpace(token); + this.Token = token; + return this; + } + + /// + public virtual BearerAuthenticationSchemeDefinition Build() + { + if (string.IsNullOrWhiteSpace(this.Token)) throw new NullReferenceException("The token must be set"); + return new() + { + Token = this.Token + }; + } + + AuthenticationSchemeDefinition IAuthenticationSchemeDefinitionBuilder.Build() => this.Build(); + +} diff --git a/src/ServerlessWorkflow.Sdk.Builders/CallTaskDefinitionBuilder.cs b/src/ServerlessWorkflow.Sdk.Builders/CallTaskDefinitionBuilder.cs new file mode 100644 index 0000000..49a1f6d --- /dev/null +++ b/src/ServerlessWorkflow.Sdk.Builders/CallTaskDefinitionBuilder.cs @@ -0,0 +1,72 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +using Neuroglia; + +namespace ServerlessWorkflow.Sdk.Builders; + +/// +/// Represents the default implementation of the interface +/// +/// The name of the function to call +public class CallTaskDefinitionBuilder(string? functionName = null) + : TaskDefinitionBuilder, ICallTaskDefinitionBuilder +{ + + /// + /// Gets the name of the function to call + /// + protected virtual string? FunctionName { get; set; } = functionName; + + /// + /// Gets a name/value mapping of the function's arguments, if any + /// + protected virtual EquatableDictionary? FunctionArguments { get; set; } + + /// + public virtual ICallTaskDefinitionBuilder Function(string name) + { + ArgumentException.ThrowIfNullOrWhiteSpace(name); + this.FunctionName = name; + return this; + } + + /// + public virtual ICallTaskDefinitionBuilder With(string name, object value) + { + ArgumentException.ThrowIfNullOrWhiteSpace(name); + this.FunctionArguments ??= []; + this.FunctionArguments[name] = value; + return this; + } + + /// + public virtual ICallTaskDefinitionBuilder With(IDictionary arguments) + { + ArgumentNullException.ThrowIfNull(arguments); + this.FunctionArguments = new(arguments); + return this; + } + + /// + public override CallTaskDefinition Build() + { + if (string.IsNullOrWhiteSpace(this.FunctionName)) throw new NullReferenceException("The function to call is required"); + return this.Configure(new() + { + Call = this.FunctionName, + With = this.FunctionArguments, + }); + } + +} diff --git a/src/ServerlessWorkflow.Sdk.Builders/CompositeTaskDefinitionBuilder.cs b/src/ServerlessWorkflow.Sdk.Builders/CompositeTaskDefinitionBuilder.cs new file mode 100644 index 0000000..8f7cceb --- /dev/null +++ b/src/ServerlessWorkflow.Sdk.Builders/CompositeTaskDefinitionBuilder.cs @@ -0,0 +1,85 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +using Neuroglia; + +namespace ServerlessWorkflow.Sdk.Builders; + +/// +/// Represents the default implementation of the interface +/// +public class CompositeTaskDefinitionBuilder + : TaskDefinitionBuilder, ICompositeTaskDefinitionBuilder +{ + + /// + /// Gets/sets a name/definition mapping of the tasks to execute sequentially, if any + /// + protected EquatableDictionary? SequentialTasks { get; set; } + + /// + /// Gets/sets a name/definition mapping of the tasks to execute concurrently, if any + /// + protected EquatableDictionary? ConcurrentTasks { get; set; } + + /// + /// Gets/sets a boolean indicating whether or not the concurrent tasks should race each other + /// + protected bool? ShouldCompete { get; set; } + + /// + public virtual ICompositeTaskDefinitionBuilder Sequentially(Action setup) + { + var builder = new TaskDefinitionMappingBuilder(); + setup(builder); + this.SequentialTasks = builder.Build(); + this.ConcurrentTasks = null!; + return this; + } + + /// + public virtual ICompositeTaskDefinitionBuilder Concurrently(Action setup) + { + var builder = new TaskDefinitionMappingBuilder(); + setup(builder); + this.ConcurrentTasks = builder.Build(); + this.SequentialTasks = null; + return this; + } + + /// + public virtual ICompositeTaskDefinitionBuilder Compete() + { + if (this.ConcurrentTasks?.Count < 1) throw new Exception("Racing is only possible when executing tasks concurrently"); + this.ShouldCompete = true; + return this; + } + + /// + public override CompositeTaskDefinition Build() + { + if (this.SequentialTasks?.Count < 2 && this.ConcurrentTasks?.Count < 2) throw new NullReferenceException("The execution strategy must define at least two subtasks"); + return new() + { + Execute = new() + { + Sequentially = this.SequentialTasks, + Concurrently = this.ConcurrentTasks, + Compete = this.ShouldCompete + } + }; + } + + TaskExecutionStrategyDefinition ITaskExecutionStrategyDefinitionBuilder.Build() => this.Build().Execute; + +} \ No newline at end of file diff --git a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/ExtensionStateBuilder.cs b/src/ServerlessWorkflow.Sdk.Builders/ConstantBackoffDefinitionBuilder.cs similarity index 57% rename from src/ServerlessWorkflow.Sdk/Services/FluentBuilders/ExtensionStateBuilder.cs rename to src/ServerlessWorkflow.Sdk.Builders/ConstantBackoffDefinitionBuilder.cs index 7633347..4c0de1c 100644 --- a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/ExtensionStateBuilder.cs +++ b/src/ServerlessWorkflow.Sdk.Builders/ConstantBackoffDefinitionBuilder.cs @@ -1,4 +1,4 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors +// Copyright © 2024-Present The Serverless Workflow Specification Authors // // Licensed under the Apache License, Version 2.0 (the "License"), // you may not use this file except in compliance with the License. @@ -11,16 +11,21 @@ // See the License for the specific language governing permissions and // limitations under the License. -namespace ServerlessWorkflow.Sdk.Services.FluentBuilders; +namespace ServerlessWorkflow.Sdk.Builders; /// -/// Represents the default implementation of the interface +/// Represents the default implementation of the interface /// -public class ExtensionStateBuilder - : StateBuilder, IExtensionStateBuilder +public class ConstantBackoffDefinitionBuilder + : IConstantBackoffDefinitionBuilder { /// - public ExtensionStateBuilder(IPipelineBuilder pipeline, string type) : base(pipeline) { this.State = new ExtensionStateDefinition(type); } + public virtual ConstantBackoffDefinition Build() => new() + { + + }; + + BackoffDefinition IBackoffDefinitionBuilder.Build() => this.Build(); } diff --git a/src/ServerlessWorkflow.Sdk.Builders/ContainerProcessDefinitionBuilder.cs b/src/ServerlessWorkflow.Sdk.Builders/ContainerProcessDefinitionBuilder.cs new file mode 100644 index 0000000..c157e7d --- /dev/null +++ b/src/ServerlessWorkflow.Sdk.Builders/ContainerProcessDefinitionBuilder.cs @@ -0,0 +1,132 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +using ServerlessWorkflow.Sdk.Models.Processes; +using Neuroglia; + +namespace ServerlessWorkflow.Sdk.Builders; + +/// +/// Represents the default implementation of the interface +/// +public class ContainerProcessDefinitionBuilder + : ProcessDefinitionBuilder, IContainerProcessDefinitionBuilder +{ + + /// + /// Gets/sets the name of the container image to run + /// + protected virtual string? Image { get; set; } + + /// + /// Gets/sets the command, if any, to execute on the container + /// + protected virtual string? Command { get; set; } + + /// + /// Gets/sets a list containing the container's port mappings, if any + /// + protected virtual EquatableDictionary? Ports { get; set; } + + /// + /// Gets/sets the volumes mapping for the container, if any + /// + protected virtual EquatableDictionary? Volumes { get; set; } + + /// + /// Gets/sets a key/value mapping of the environment variables, if any, to use when running the configured process + /// + protected virtual EquatableDictionary? Environment { get; set; } + + /// + public virtual IContainerProcessDefinitionBuilder WithImage(string image) + { + ArgumentException.ThrowIfNullOrWhiteSpace(image); + this.Image = image; + return this; + } + + /// + public virtual IContainerProcessDefinitionBuilder WithCommand(string command) + { + ArgumentException.ThrowIfNullOrWhiteSpace(command); + this.Command = command; + return this; + } + + /// + public virtual IContainerProcessDefinitionBuilder WithPort(ushort hostPort, ushort containerPort) + { + this.Ports ??= []; + this.Ports[hostPort] = containerPort; + return this; + } + + /// + public virtual IContainerProcessDefinitionBuilder WithPorts(IDictionary portMapping) + { + ArgumentNullException.ThrowIfNull(portMapping); + this.Ports = new(portMapping); + return this; + } + + /// + public virtual IContainerProcessDefinitionBuilder WithVolume(string key, string value) + { + ArgumentException.ThrowIfNullOrWhiteSpace(key); + this.Volumes ??= []; + this.Volumes[key] = value; + return this; + } + + /// + public virtual IContainerProcessDefinitionBuilder WithVolumes(IDictionary volumes) + { + ArgumentNullException.ThrowIfNull(volumes); + this.Volumes = new(volumes); + return this; + } + + /// + public virtual IContainerProcessDefinitionBuilder WithEnvironment(string name, string value) + { + ArgumentException.ThrowIfNullOrWhiteSpace(name); + ArgumentException.ThrowIfNullOrWhiteSpace(value); + this.Environment ??= []; + this.Environment[name] = value; + return this; + } + + /// + public virtual IContainerProcessDefinitionBuilder WithEnvironment(IDictionary environment) + { + ArgumentNullException.ThrowIfNull(environment); + this.Environment = new(environment); + return this; + } + + /// + public override ContainerProcessDefinition Build() + { + if (string.IsNullOrWhiteSpace(this.Image)) throw new NullReferenceException("The image of the container to run must be set"); + return new() + { + Image = this.Image, + Command = this.Command, + Ports = this.Ports, + Volumes = this.Volumes, + Environment = this.Environment + }; + } + +} diff --git a/src/ServerlessWorkflow.Sdk.Builders/EmitTaskDefinitionBuilder.cs b/src/ServerlessWorkflow.Sdk.Builders/EmitTaskDefinitionBuilder.cs new file mode 100644 index 0000000..f31df31 --- /dev/null +++ b/src/ServerlessWorkflow.Sdk.Builders/EmitTaskDefinitionBuilder.cs @@ -0,0 +1,62 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Builders; + +/// +/// Represents the default implementation of the interface +/// +/// The definition of the event to emit +public class EmitTaskDefinitionBuilder(EventDefinition? e = null) + : IEmitTaskDefinitionBuilder +{ + + /// + /// Gets/sets the definition of the event to emit + /// + protected virtual EventDefinition? EventDefinition { get; set; } = e; + + /// + public virtual IEmitTaskDefinitionBuilder Event(EventDefinition e) + { + ArgumentNullException.ThrowIfNull(e); + this.EventDefinition = e; + return this; + } + + /// + public virtual IEmitTaskDefinitionBuilder Event(Action setup) + { + ArgumentNullException.ThrowIfNull(setup); + var builder = new EventDefinitionBuilder(); + setup(builder); + this.EventDefinition = builder.Build(); + return this; + } + + /// + public virtual EmitTaskDefinition Build() + { + if (this.EventDefinition == null) throw new NullReferenceException("The event to emit must be defined"); + return new() + { + Emit = new() + { + Event = this.EventDefinition + } + }; + } + + TaskDefinition ITaskDefinitionBuilder.Build() => this.Build(); + +} diff --git a/src/ServerlessWorkflow.Sdk.Builders/ErrorCatcherDefinitionBuilder.cs b/src/ServerlessWorkflow.Sdk.Builders/ErrorCatcherDefinitionBuilder.cs new file mode 100644 index 0000000..9aa52b3 --- /dev/null +++ b/src/ServerlessWorkflow.Sdk.Builders/ErrorCatcherDefinitionBuilder.cs @@ -0,0 +1,139 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Builders; + +/// +/// Represents the default implementation of the interface +/// +public class ErrorCatcherDefinitionBuilder + : IErrorCatcherDefinitionBuilder +{ + + /// + /// Gets/sets the definition of the errors to catch + /// + protected ErrorFilterDefinition? CatchErrors { get; set; } + + /// + /// Gets/sets the name of the runtime expression variable to save the error as. Defaults to 'error'. + /// + protected string? CatchAs { get; set; } + + /// + /// Gets/sets a runtime expression used to determine whether or not to catch the filtered error + /// + protected string? CatchWhen { get; set; } + + /// + /// Gets/sets a runtime expression used to determine whether or not to catch the filtered error + /// + protected string? CatchExceptWhen { get; set; } + + /// + /// Gets/sets a reference to the definition of the retry policy to use when catching errors + /// + protected Uri? RetryPolicyReference { get; set; } + + /// + /// Gets/sets the definition of the retry policy to use when catching errors + /// + protected RetryPolicyDefinition? RetryPolicy { get; set; } + + /// + /// Gets/sets the definition of the task to run when catching an error + /// + protected TaskDefinition? RetryDo { get; set; } + + /// + public virtual IErrorCatcherDefinitionBuilder Errors(ErrorFilterDefinition filter) + { + ArgumentNullException.ThrowIfNull(filter); + this.CatchErrors = filter; + return this; + } + + /// + public virtual IErrorCatcherDefinitionBuilder Errors(Action setup) + { + ArgumentNullException.ThrowIfNull(setup); + var builder = new ErrorFilterDefinitionBuilder(); + setup(builder); + return this.Errors(builder.Build()); + } + + /// + public virtual IErrorCatcherDefinitionBuilder As(string variableName) + { + this.CatchAs = variableName; + return this; + } + + /// + public virtual IErrorCatcherDefinitionBuilder When(string expression) + { + this.CatchWhen = expression; + return this; + } + + /// + public virtual IErrorCatcherDefinitionBuilder ExceptWhen(string expression) + { + this.CatchExceptWhen = expression; + return this; + } + + /// + public virtual IErrorCatcherDefinitionBuilder Retry(Uri reference) + { + this.RetryPolicyReference = reference; + return this; + } + + /// + public virtual IErrorCatcherDefinitionBuilder Retry(RetryPolicyDefinition retryPolicy) + { + this.RetryPolicy = retryPolicy; + return this; + } + + /// + public virtual IErrorCatcherDefinitionBuilder Retry(Action setup) + { + ArgumentNullException.ThrowIfNull(setup); + var builder = new RetryPolicyDefinitionBuilder(); + setup(builder); + return this.Retry(builder.Build()); + } + + /// + public virtual IErrorCatcherDefinitionBuilder Do(Action setup) + { + ArgumentNullException.ThrowIfNull(setup); + var builder = new GenericTaskDefinitionBuilder(); + this.RetryDo = builder.Build(); + return this; + } + + /// + public virtual ErrorCatcherDefinition Build() => new() + { + Errors = this.CatchErrors, + As = this.CatchAs, + When = this.CatchWhen, + ExceptWhen = this.CatchExceptWhen, + Retry = this.RetryPolicyReference == null ? this.RetryPolicy : new() { Ref = this.RetryPolicyReference }, + Do = this.RetryDo + }; + +} \ No newline at end of file diff --git a/src/ServerlessWorkflow.Sdk.Builders/ErrorDefinitionBuilder.cs b/src/ServerlessWorkflow.Sdk.Builders/ErrorDefinitionBuilder.cs new file mode 100644 index 0000000..8bc33ee --- /dev/null +++ b/src/ServerlessWorkflow.Sdk.Builders/ErrorDefinitionBuilder.cs @@ -0,0 +1,104 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Builders; + +/// +/// Represents the default implementation of the interface +/// +public class ErrorDefinitionBuilder + : IErrorDefinitionBuilder +{ + + /// + /// Gets the type of the error to build + /// + protected string? Type { get; set; } + + /// + /// Gets the status of the error to build + /// + protected string? Status { get; set; } + + /// + /// Gets the title of the error to build + /// + protected string? Title { get; set; } + + /// + /// Gets the detail of the error to build + /// + protected string? Detail { get; set; } + + /// + /// Gets the instance of the error to build + /// + protected string? Instance { get; set; } + + /// + public virtual IErrorDefinitionBuilder WithType(string type) + { + ArgumentException.ThrowIfNullOrWhiteSpace(type); + this.Type = type; + return this; + } + + /// + public virtual IErrorDefinitionBuilder WithStatus(string status) + { + ArgumentException.ThrowIfNullOrWhiteSpace(status); + this.Status = status; + return this; + } + + /// + public virtual IErrorDefinitionBuilder WithTitle(string title) + { + ArgumentException.ThrowIfNullOrWhiteSpace(title); + this.Title = title; + return this; + } + + /// + public virtual IErrorDefinitionBuilder WithDetail(string detail) + { + ArgumentException.ThrowIfNullOrWhiteSpace(detail); + this.Detail = detail; + return this; + } + + /// + public virtual IErrorDefinitionBuilder WithInstance(string instance) + { + ArgumentException.ThrowIfNullOrWhiteSpace(instance); + this.Instance = instance; + return this; + } + + /// + public virtual ErrorDefinition Build() + { + if (string.IsNullOrWhiteSpace(this.Type)) throw new NullReferenceException("The error type must be set"); + if (string.IsNullOrWhiteSpace(this.Title)) throw new NullReferenceException("The error title must be set"); + if (string.IsNullOrWhiteSpace(this.Status)) throw new NullReferenceException("The error status must be set"); + return new() + { + Type = this.Type, + Status = this.Status, + Title = this.Title, + Detail = this.Detail, + Instance = this.Instance + }; + } + +} diff --git a/src/ServerlessWorkflow.Sdk.Builders/ErrorFilterDefinitionBuilder.cs b/src/ServerlessWorkflow.Sdk.Builders/ErrorFilterDefinitionBuilder.cs new file mode 100644 index 0000000..61fe52d --- /dev/null +++ b/src/ServerlessWorkflow.Sdk.Builders/ErrorFilterDefinitionBuilder.cs @@ -0,0 +1,50 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +using Neuroglia; + +namespace ServerlessWorkflow.Sdk.Builders; + +/// +/// Represents the default implementation of the interface +/// +/// A name/value mapping of the attributes to filter errors by. Supports runtime expressions +public class ErrorFilterDefinitionBuilder(IDictionary? attributes = null) + : IErrorFilterDefinitionBuilder +{ + + /// + /// Gets a name/value mapping of the attributes to filter errors by + /// + protected virtual EquatableDictionary Attributes { get; set; } = [.. attributes]; + + /// + public virtual IErrorFilterDefinitionBuilder With(string name, object value) + { + ArgumentException.ThrowIfNullOrWhiteSpace(name); + this.Attributes[name] = value; + return this; + } + + /// + public virtual IErrorFilterDefinitionBuilder With(IDictionary attributes) + { + ArgumentNullException.ThrowIfNull(attributes); + this.Attributes = new(attributes); + return this; + } + + /// + public virtual ErrorFilterDefinition Build() => new() { With = this.Attributes }; + +} diff --git a/src/ServerlessWorkflow.Sdk.Builders/EventDefinitionBuilder.cs b/src/ServerlessWorkflow.Sdk.Builders/EventDefinitionBuilder.cs new file mode 100644 index 0000000..5339262 --- /dev/null +++ b/src/ServerlessWorkflow.Sdk.Builders/EventDefinitionBuilder.cs @@ -0,0 +1,50 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +using Neuroglia; + +namespace ServerlessWorkflow.Sdk.Builders; + +/// +/// Represents the default implementation of the interface +/// +/// A name/value mapping of the event's attributes. Supports runtime expressions +public class EventDefinitionBuilder(IDictionary? attributes = null) + : IEventDefinitionBuilder +{ + + /// + /// Gets a name/value mapping of the event's attributes + /// + protected virtual EquatableDictionary Attributes { get; set; } = attributes == null ? new() : new(attributes); + + /// + public virtual IEventDefinitionBuilder With(string name, object value) + { + ArgumentException.ThrowIfNullOrWhiteSpace(name); + this.Attributes[name] = value; + return this; + } + + /// + public virtual IEventDefinitionBuilder With(IDictionary attributes) + { + ArgumentNullException.ThrowIfNull(attributes); + this.Attributes = new(attributes); + return this; + } + + /// + public virtual EventDefinition Build() => new() { With = this.Attributes }; + +} diff --git a/src/ServerlessWorkflow.Sdk.Builders/EventFilterDefinitionBuilder.cs b/src/ServerlessWorkflow.Sdk.Builders/EventFilterDefinitionBuilder.cs new file mode 100644 index 0000000..89aa4df --- /dev/null +++ b/src/ServerlessWorkflow.Sdk.Builders/EventFilterDefinitionBuilder.cs @@ -0,0 +1,50 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +using Neuroglia; + +namespace ServerlessWorkflow.Sdk.Builders; + +/// +/// Represents the default implementation of the interface +/// +/// A name/value mapping of the attributes to filter events by. Supports runtime expressions +public class EventFilterDefinitionBuilder(IDictionary? attributes = null) + : IEventFilterDefinitionBuilder +{ + + /// + /// Gets a name/value mapping of the attributes to filter errors by + /// + protected virtual EquatableDictionary Attributes { get; set; } = attributes == null ? new() : new(attributes); + + /// + public virtual IEventFilterDefinitionBuilder With(string name, object value) + { + ArgumentException.ThrowIfNullOrWhiteSpace(name); + this.Attributes[name] = value; + return this; + } + + /// + public virtual IEventFilterDefinitionBuilder With(IDictionary attributes) + { + ArgumentNullException.ThrowIfNull(attributes); + this.Attributes = new(attributes); + return this; + } + + /// + public virtual EventFilterDefinition Build() => new() { With = this.Attributes }; + +} \ No newline at end of file diff --git a/src/ServerlessWorkflow.Sdk.Builders/EventFilterDefinitionCollectionBuilder.cs b/src/ServerlessWorkflow.Sdk.Builders/EventFilterDefinitionCollectionBuilder.cs new file mode 100644 index 0000000..210481e --- /dev/null +++ b/src/ServerlessWorkflow.Sdk.Builders/EventFilterDefinitionCollectionBuilder.cs @@ -0,0 +1,58 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +using Neuroglia; + +namespace ServerlessWorkflow.Sdk.Builders; + +/// +/// Represents the default implementation of the interface +/// +public class EventFilterDefinitionCollectionBuilder + : IEventFilterDefinitionCollectionBuilder +{ + + /// + /// Gets/sets the filters the collection to build is made out of + /// + protected EquatableList? Filters { get; set; } + + /// + public virtual IEventFilterDefinitionCollectionBuilder Event(EventFilterDefinition filter) + { + ArgumentNullException.ThrowIfNull(filter); + this.Filters ??= []; + this.Filters.Add(filter); + return this; + } + + /// + public virtual IEventFilterDefinitionCollectionBuilder Event(Action setup) + { + ArgumentNullException.ThrowIfNull(setup); + var builder = new EventFilterDefinitionBuilder(); + setup(builder); + var filter = builder.Build(); + this.Filters ??= []; + this.Filters.Add(filter); + return this; + } + + /// + public virtual EquatableList Build() + { + if (this.Filters == null || this.Filters.Count < 1) throw new NullReferenceException("The collection must contain at least one event filter"); + return this.Filters; + } + +} diff --git a/src/ServerlessWorkflow.Sdk.Builders/ExponentialBackoffDefinitionBuilder.cs b/src/ServerlessWorkflow.Sdk.Builders/ExponentialBackoffDefinitionBuilder.cs new file mode 100644 index 0000000..21343eb --- /dev/null +++ b/src/ServerlessWorkflow.Sdk.Builders/ExponentialBackoffDefinitionBuilder.cs @@ -0,0 +1,31 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Builders; + +/// +/// Represents the default implementation of the interface +/// +public class ExponentialBackoffDefinitionBuilder + : IExponentialBackoffDefinitionBuilder +{ + + /// + public virtual ExponentialBackoffDefinition Build() => new() + { + + }; + + BackoffDefinition IBackoffDefinitionBuilder.Build() => this.Build(); + +} \ No newline at end of file diff --git a/src/ServerlessWorkflow.Sdk.Builders/ExtensionDefinitionBuilder.cs b/src/ServerlessWorkflow.Sdk.Builders/ExtensionDefinitionBuilder.cs new file mode 100644 index 0000000..5e529b7 --- /dev/null +++ b/src/ServerlessWorkflow.Sdk.Builders/ExtensionDefinitionBuilder.cs @@ -0,0 +1,92 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Builders; + +/// +/// Represents the default implementation of the interface +/// +public class ExtensionDefinitionBuilder + : IExtensionDefinitionBuilder +{ + + /// + /// Gets/sets the type of the extended task + /// + protected string? TaskType { get; set; } + + /// + /// Gets/sets the expression used to evaluate whether or not the extension applies + /// + protected string? WhenExpression { get; set; } + + /// + /// Gets/sets the definition of the task to run before the extended one + /// + protected TaskDefinition? BeforeTask { get; set; } + + /// + /// Gets/sets the definition of the task to run after the extended one + /// + protected TaskDefinition? AfterTask { get; set; } + + /// + public virtual IExtensionDefinitionBuilder Extend(string taskType) + { + ArgumentException.ThrowIfNullOrWhiteSpace(taskType); + this.TaskType = taskType; + return this; + } + + /// + public virtual IExtensionDefinitionBuilder When(string when) + { + ArgumentException.ThrowIfNullOrWhiteSpace(when); + this.WhenExpression = when; + return this; + } + + /// + public virtual IExtensionDefinitionBuilder Before(Action setup) + { + ArgumentNullException.ThrowIfNull(setup); + var builder = new GenericTaskDefinitionBuilder(); + setup(builder); + this.BeforeTask = builder.Build(); + return this; + } + + /// + public virtual IExtensionDefinitionBuilder After(Action setup) + { + ArgumentNullException.ThrowIfNull(setup); + var builder = new GenericTaskDefinitionBuilder(); + setup(builder); + this.AfterTask = builder.Build(); + return this; + } + + /// + public virtual ExtensionDefinition Build() + { + ArgumentException.ThrowIfNullOrWhiteSpace(this.TaskType); + return new() + { + Extend = this.TaskType, + When = this.WhenExpression, + Before = this.BeforeTask, + After = this.AfterTask + }; + } + +} \ No newline at end of file diff --git a/src/ServerlessWorkflow.Sdk.Builders/ExternalResourceDefinitionBuilder.cs b/src/ServerlessWorkflow.Sdk.Builders/ExternalResourceDefinitionBuilder.cs new file mode 100644 index 0000000..741bd8a --- /dev/null +++ b/src/ServerlessWorkflow.Sdk.Builders/ExternalResourceDefinitionBuilder.cs @@ -0,0 +1,100 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Builders; + +/// +/// Represents the default implementation of the interface +/// +public class ExternalResourceDefinitionBuilder + : IExternalResourceDefinitionBuilder +{ + + /// + /// Gets/sets the external resource's name + /// + protected virtual string? Name { get; set; } + + /// + /// Gets/sets the uri that references the external resource + /// + protected virtual Uri? Uri { get; set; } + + /// + /// Gets/sets a reference to the authentication policy to use + /// + protected virtual Uri? AuthenticationReference { get; set; } + + /// + /// Gets/sets the authentication policy to use + /// + protected virtual AuthenticationPolicyDefinition? Authentication { get; set; } + + /// + public virtual IExternalResourceDefinitionBuilder WithName(string name) + { + this.Name = name; + return this; + } + + /// + public virtual IExternalResourceDefinitionBuilder WithUri(Uri uri) + { + ArgumentNullException.ThrowIfNull(uri); + this.Uri = uri; + return this; + } + + /// + public virtual IExternalResourceDefinitionBuilder UseAuthentication(Uri reference) + { + ArgumentNullException.ThrowIfNull(reference); + this.AuthenticationReference = reference; + return this; + } + + /// + public virtual IExternalResourceDefinitionBuilder UseAuthentication(AuthenticationPolicyDefinition authentication) + { + ArgumentNullException.ThrowIfNull(authentication); + this.Authentication = authentication; + return this; + } + + /// + public virtual IExternalResourceDefinitionBuilder UseAuthentication(Action setup) + { + ArgumentNullException.ThrowIfNull(setup); + var builder = new AuthenticationPolicyDefinitionBuilder(); + setup(builder); + this.Authentication = builder.Build(); + return this; + } + + /// + public virtual ExternalResourceDefinition Build() + { + if (this.Uri == null) throw new NullReferenceException("The uri that references the external resource must be set"); + var reference = new ExternalResourceDefinition() + { + Name = this.Name, + Uri = this.Uri + }; + if (this.AuthenticationReference == null) reference.Authentication = new() { Ref = this.AuthenticationReference }; + else if (this.Authentication != null) reference.Authentication = this.Authentication; + return reference; + } + + EndpointDefinition IEndpointDefinitionBuilder.Build() => this.Build(); + +} diff --git a/src/ServerlessWorkflow.Sdk.Builders/ForTaskDefinitionBuilder.cs b/src/ServerlessWorkflow.Sdk.Builders/ForTaskDefinitionBuilder.cs new file mode 100644 index 0000000..f0a42ed --- /dev/null +++ b/src/ServerlessWorkflow.Sdk.Builders/ForTaskDefinitionBuilder.cs @@ -0,0 +1,95 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Builders; + +/// +/// Represents the default implementation of the interface +/// +public class ForTaskDefinitionBuilder + : TaskDefinitionBuilder, IForTaskDefinitionBuilder +{ + + /// + /// Gets/sets the name of the variable that represents each element in the collection during iteration + /// + protected virtual string? EachVariableName { get; set; } + + /// + /// Gets/sets the runtime expression used to get the collection to iterate over + /// + protected virtual string? InExpression { get; set; } + + /// + /// Gets/sets the name of the variable used to hold the index of each element in the collection during iteration + /// + protected virtual string? AtVariableName { get; set; } + + /// + /// Gets an used to setup the task to perform for each iteration + /// + protected virtual Action? DoSetup { get; set; } + + /// + public virtual IForTaskDefinitionBuilder Each(string variableName) + { + ArgumentException.ThrowIfNullOrWhiteSpace(variableName); + this.EachVariableName = variableName; + return this; + } + + /// + public virtual IForTaskDefinitionBuilder In(string expression) + { + ArgumentException.ThrowIfNullOrWhiteSpace(expression); + this.InExpression = expression; + return this; + } + + /// + public virtual IForTaskDefinitionBuilder At(string variableName) + { + ArgumentException.ThrowIfNullOrWhiteSpace(variableName); + this.AtVariableName = variableName; + return this; + } + + /// + public virtual IForTaskDefinitionBuilder Do(Action setup) + { + ArgumentNullException.ThrowIfNull(setup); + this.DoSetup = setup; + return this; + } + + /// + public override ForTaskDefinition Build() + { + if (string.IsNullOrWhiteSpace(this.EachVariableName)) throw new NullReferenceException("The variable name used to store the iterated items must be set"); + if (string.IsNullOrWhiteSpace(this.InExpression)) throw new NullReferenceException("The runtime expression used to resolve the collection to iterate must be set"); + if (this.DoSetup == null) throw new NullReferenceException("The task to perform at each iteration must be set"); + var taskBuilder = new GenericTaskDefinitionBuilder(); + this.DoSetup(taskBuilder); + return new() + { + For = new() + { + Each = this.EachVariableName, + In = this.InExpression, + At = this.AtVariableName + }, + Do = taskBuilder.Build() + }; + } + +} diff --git a/src/ServerlessWorkflow.Sdk.Builders/GenericTaskDefinitionBuilder.cs b/src/ServerlessWorkflow.Sdk.Builders/GenericTaskDefinitionBuilder.cs new file mode 100644 index 0000000..ed1f969 --- /dev/null +++ b/src/ServerlessWorkflow.Sdk.Builders/GenericTaskDefinitionBuilder.cs @@ -0,0 +1,148 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Builders; + +/// +/// Represents the default implementation of the interface +/// +public class GenericTaskDefinitionBuilder + : IGenericTaskDefinitionBuilder +{ + + /// + /// Gets the underlying + /// + protected ITaskDefinitionBuilder? Builder { get; set; } + + /// + public virtual ICallTaskDefinitionBuilder Call(string? function = null) + { + var builder = new CallTaskDefinitionBuilder(function); + this.Builder = builder; + return builder; + } + + /// + public virtual IEmitTaskDefinitionBuilder Emit(EventDefinition e) + { + ArgumentNullException.ThrowIfNull(e); + var builder = new EmitTaskDefinitionBuilder(e); + this.Builder = builder; + return builder; + } + + /// + public virtual IEmitTaskDefinitionBuilder Emit(Action setup) + { + ArgumentNullException.ThrowIfNull(setup); + var builder = new EventDefinitionBuilder(); + setup(builder); + var e = builder.Build(); + return this.Emit(e); + } + + /// + public virtual IForTaskDefinitionBuilder For() + { + var builder = new ForTaskDefinitionBuilder(); + this.Builder = builder; + return builder; + } + + /// + public virtual IListenTaskDefinitionBuilder Listen() + { + var builder = new ListenTaskDefinitionBuilder(); + this.Builder = builder; + return builder; + } + + /// + public virtual ICompositeTaskDefinitionBuilder Execute() + { + var builder = new CompositeTaskDefinitionBuilder(); + this.Builder = builder; + return builder; + } + + /// + public virtual IRaiseTaskDefinitionBuilder Raise(ErrorDefinition error) + { + ArgumentNullException.ThrowIfNull(error); + var builder = new RaiseTaskDefinitionBuilder(error); + this.Builder = builder; + return builder; + } + + /// + public virtual IRaiseTaskDefinitionBuilder Raise(Action setup) + { + ArgumentNullException.ThrowIfNull(setup); + var builder = new ErrorDefinitionBuilder(); + setup(builder); + var error = builder.Build(); + return this.Raise(error); + } + + /// + public virtual IRunTaskDefinitionBuilder Run() + { + var builder = new RunTaskDefinitionBuilder(); + this.Builder = builder; + return builder; + } + + /// + public virtual ISetTaskDefinitionBuilder Set(string name, string value) => this.Set(new Dictionary() { { name, value } }); + + /// + public virtual ISetTaskDefinitionBuilder Set(IDictionary? variables = null) + { + var builder = new SetTaskDefinitionBuilder(variables); + this.Builder = builder; + return builder; + } + + /// + public virtual ISwitchTaskDefinitionBuilder Switch() + { + var builder = new SwitchTaskDefinitionBuilder(); + this.Builder = builder; + return builder; + } + + /// + public virtual ITryTaskDefinitionBuilder Try() + { + var builder = new TryTaskDefinitionBuilder(); + this.Builder = builder; + return builder; + } + + /// + public virtual IWaitTaskDefinitionBuilder Wait(Duration? duration = null) + { + var builder = new WaitTaskDefinitionBuilder(duration); + this.Builder = builder; + return builder; + } + + /// + public virtual TaskDefinition Build() + { + if (this.Builder == null) throw new NullReferenceException(); + return this.Builder.Build(); + } + +} diff --git a/src/ServerlessWorkflow.Sdk.Builders/HttpCallDefinitionBuilder.cs b/src/ServerlessWorkflow.Sdk.Builders/HttpCallDefinitionBuilder.cs new file mode 100644 index 0000000..be1b82e --- /dev/null +++ b/src/ServerlessWorkflow.Sdk.Builders/HttpCallDefinitionBuilder.cs @@ -0,0 +1,155 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +using ServerlessWorkflow.Sdk.Models.Calls; +using Neuroglia; +using System.Runtime.Serialization; + +namespace ServerlessWorkflow.Sdk.Builders; + +/// +/// Represents the default implementation of the interface +/// +[DataContract] +public class HttpCallDefinitionBuilder + : IHttpCallDefinitionBuilder +{ + + /// + /// Gets/sets the HTTP method of the request to perform + /// + protected string? Method { get; set; } + + /// + /// Gets/sets the definition of the endpoint to request + /// + protected EndpointDefinition? Endpoint { get; set; } + + /// + /// Gets/sets a name/value mapping of the headers, if any, of the HTTP request to perform + /// + protected EquatableDictionary? Headers { get; set; } + + /// + /// Gets/sets a name/value mapping of the cookies, if any, of the HTTP request to perform + /// + protected EquatableDictionary? Cookies { get; set; } + + /// + /// Gets/sets the body, if any, of the HTTP request to perform + /// + protected object? Body { get; set; } + + /// + /// Gets/sets the http call output format. Defaults to . + /// + protected string? OutputFormat { get; set; } + + /// + public virtual IHttpCallDefinitionBuilder WithMethod(string method) + { + ArgumentException.ThrowIfNullOrWhiteSpace(method); + this.Method = method; + return this; + } + + /// + public virtual IHttpCallDefinitionBuilder WithUri(Uri uri) + { + ArgumentNullException.ThrowIfNull(uri); + this.Endpoint = new() { Uri = uri }; + return this; + } + + /// + public virtual IHttpCallDefinitionBuilder WithEndpoint(EndpointDefinition endpoint) + { + ArgumentNullException.ThrowIfNull(endpoint); + this.Endpoint = endpoint; + return this; + } + + /// + public virtual IHttpCallDefinitionBuilder WithEndpoint(Action setup) + { + ArgumentNullException.ThrowIfNull(setup); + var builder = (IEndpointDefinitionBuilder)new ExternalResourceDefinitionBuilder(); + setup(builder); + return this.WithEndpoint(builder.Build()); + } + + /// + public virtual IHttpCallDefinitionBuilder WithHeader(string name, string value) + { + ArgumentException.ThrowIfNullOrWhiteSpace(name); + ArgumentException.ThrowIfNullOrWhiteSpace(value); + this.Headers ??= []; + this.Headers[name] = value; + return this; + } + + /// + public virtual IHttpCallDefinitionBuilder WithHeaders(IDictionary headers) + { + this.Headers = headers == null ? null : new(headers); + return this; + } + + /// + public virtual IHttpCallDefinitionBuilder WithCookie(string name, string value) + { + ArgumentException.ThrowIfNullOrWhiteSpace(name); + ArgumentException.ThrowIfNullOrWhiteSpace(value); + this.Cookies ??= []; + this.Cookies[name] = value; + return this; + } + + /// + public virtual IHttpCallDefinitionBuilder WithCookies(IDictionary cookies) + { + this.Cookies = cookies == null ? null : new(cookies); + return this; + } + + /// + public virtual IHttpCallDefinitionBuilder WithBody(object body) + { + this.Body = body; + return this; + } + + /// + public virtual IHttpCallDefinitionBuilder WithOutputFormat(string format) + { + ArgumentException.ThrowIfNullOrWhiteSpace(format); + this.OutputFormat = format; + return this; + } + + /// + public virtual HttpCallDefinition Build() + { + if (string.IsNullOrWhiteSpace(this.Method)) throw new NullReferenceException("The HTTP method must be set"); + if (this.Endpoint == null) throw new NullReferenceException("The HTTP endpoint must be set"); + return new() + { + Method = this.Method, + Endpoint = this.Endpoint, + Headers = this.Headers, + Body = this.Body, + Output = this.OutputFormat + }; + } + +} \ No newline at end of file diff --git a/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IAuthenticationPolicyDefinitionBuilder.cs b/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IAuthenticationPolicyDefinitionBuilder.cs new file mode 100644 index 0000000..5c05d72 --- /dev/null +++ b/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IAuthenticationPolicyDefinitionBuilder.cs @@ -0,0 +1,46 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Builders; + +/// +/// Defines the fundamentals of a service used to build s +/// +public interface IAuthenticationPolicyDefinitionBuilder +{ + + /// + /// Configures the policy to use 'Basic' authentication + /// + /// A new + IBasicAuthenticationSchemeDefinitionBuilder Basic(); + + /// + /// Configures the policy to use 'Bearer' authentication + /// + /// A new + IBearerAuthenticationSchemeDefinitionBuilder Bearer(); + + /// + /// Configures the policy to use 'OAuth2' authentication + /// + /// A new + IOAuth2AuthenticationSchemeDefinitionBuilder OAuth2(); + + /// + /// Builds the configured + /// + /// A new + AuthenticationPolicyDefinition Build(); + +} \ No newline at end of file diff --git a/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IAuthenticationSchemeDefinitionBuilder.cs b/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IAuthenticationSchemeDefinitionBuilder.cs new file mode 100644 index 0000000..769fd98 --- /dev/null +++ b/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IAuthenticationSchemeDefinitionBuilder.cs @@ -0,0 +1,45 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Builders; + +/// +/// Defines the fundamentals of a service used to builder s +/// +public interface IAuthenticationSchemeDefinitionBuilder +{ + + /// + /// Builds the configured + /// + /// A new + AuthenticationSchemeDefinition Build(); + +} + +/// +/// Defines the fundamentals of a service used to builder s +/// +public interface IAuthenticationSchemeDefinitionBuilder + : IAuthenticationSchemeDefinitionBuilder + where TDefinition : AuthenticationSchemeDefinition + +{ + + /// + /// Builds the configured + /// + /// A new + new TDefinition Build(); + +} \ No newline at end of file diff --git a/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IBackoffDefinitionBuilder.cs b/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IBackoffDefinitionBuilder.cs new file mode 100644 index 0000000..d1a539a --- /dev/null +++ b/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IBackoffDefinitionBuilder.cs @@ -0,0 +1,45 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Builders; + +/// +/// Defines the fundamentals of a service used to build s +/// +public interface IBackoffDefinitionBuilder +{ + + /// + /// Builds the configured + /// + /// A new + BackoffDefinition Build(); + +} + +/// +/// Defines the fundamentals of a service used to build s +/// +/// The type of to build +public interface IBackoffDefinitionBuilder + : IBackoffDefinitionBuilder + where TDefinition : BackoffDefinition +{ + + /// + /// Builds the configured + /// + /// A new + new TDefinition Build(); + +} \ No newline at end of file diff --git a/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IBackoffStrategyDefinitionBuilder.cs b/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IBackoffStrategyDefinitionBuilder.cs new file mode 100644 index 0000000..df9232c --- /dev/null +++ b/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IBackoffStrategyDefinitionBuilder.cs @@ -0,0 +1,46 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Builders; + +/// +/// Defines the fundamentals of a service used to build s +/// +public interface IBackoffStrategyDefinitionBuilder +{ + + /// + /// Configures a constant backoff strategy + /// + /// A new + IConstantBackoffDefinitionBuilder Constant(); + + /// + /// Configures an exponential backoff strategy + /// + /// A new + IExponentialBackoffDefinitionBuilder Exponential(); + + /// + /// Configures a linear backoff strategy + /// + /// A new + ILinearBackoffDefinitionBuilder Linear(Duration? increment = null); + + /// + /// Builds the configured + /// + /// A new + BackoffStrategyDefinition Build(); + +} diff --git a/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IBasicAuthenticationSchemeDefinitionBuilder.cs b/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IBasicAuthenticationSchemeDefinitionBuilder.cs new file mode 100644 index 0000000..7f8f2fd --- /dev/null +++ b/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IBasicAuthenticationSchemeDefinitionBuilder.cs @@ -0,0 +1,37 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Builders; + +/// +/// Defines the fundamentals of a service used to build s +/// +public interface IBasicAuthenticationSchemeDefinitionBuilder + : IAuthenticationSchemeDefinitionBuilder +{ + + /// + /// Sets the username to use + /// + /// The username to use + /// The configured + IBasicAuthenticationSchemeDefinitionBuilder WithUsername(string username); + + /// + /// Sets the password to use + /// + /// The password to use + /// The configured + IBasicAuthenticationSchemeDefinitionBuilder WithPassword(string password); + +} diff --git a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/ISwitchCaseBuilder.cs b/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IBearerAuthenticationSchemeDefinitionBuilder.cs similarity index 55% rename from src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/ISwitchCaseBuilder.cs rename to src/ServerlessWorkflow.Sdk.Builders/Interfaces/IBearerAuthenticationSchemeDefinitionBuilder.cs index 728db3b..b90b3f0 100644 --- a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/ISwitchCaseBuilder.cs +++ b/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IBearerAuthenticationSchemeDefinitionBuilder.cs @@ -1,4 +1,4 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors +// Copyright © 2024-Present The Serverless Workflow Specification Authors // // Licensed under the Apache License, Version 2.0 (the "License"), // you may not use this file except in compliance with the License. @@ -11,21 +11,20 @@ // See the License for the specific language governing permissions and // limitations under the License. -namespace ServerlessWorkflow.Sdk.Services.FluentBuilders; +namespace ServerlessWorkflow.Sdk.Builders; /// -/// Defines the fundamentals of a service used to build s +/// Defines the fundamentals of a service used to build s /// -public interface ISwitchCaseBuilder - : IStateOutcomeBuilder - where TBuilder : ISwitchCaseBuilder +public interface IBearerAuthenticationSchemeDefinitionBuilder + : IAuthenticationSchemeDefinitionBuilder { /// - /// Sets the 's name + /// Sets the bearer token to use /// - /// The name of the to build - /// The configured - TBuilder WithName(string name); + /// The username to use + /// The configured + IBearerAuthenticationSchemeDefinitionBuilder WithToken(string token); } diff --git a/src/ServerlessWorkflow.Sdk.Builders/Interfaces/ICallTaskDefinitionBuilder.cs b/src/ServerlessWorkflow.Sdk.Builders/Interfaces/ICallTaskDefinitionBuilder.cs new file mode 100644 index 0000000..b0602b8 --- /dev/null +++ b/src/ServerlessWorkflow.Sdk.Builders/Interfaces/ICallTaskDefinitionBuilder.cs @@ -0,0 +1,44 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Builders; + +/// +/// Defines the fundamentals of a service used to build s +/// +public interface ICallTaskDefinitionBuilder +{ + + /// + /// Configures the task to call the specified function + /// + /// The name of the function to call + /// The configured + ICallTaskDefinitionBuilder Function(string name); + + /// + /// Adds a new argument to call the function with + /// + /// The argument's name + /// The argument's value + /// The configured + ICallTaskDefinitionBuilder With(string name, object value); + + /// + /// Sets the arguments to call the function with + /// + /// A name/value mapping of the arguments to call the function with + /// The configured + ICallTaskDefinitionBuilder With(IDictionary arguments); + +} diff --git a/src/ServerlessWorkflow.Sdk/IExtensible.cs b/src/ServerlessWorkflow.Sdk.Builders/Interfaces/ICompositeTaskDefinitionBuilder.cs similarity index 61% rename from src/ServerlessWorkflow.Sdk/IExtensible.cs rename to src/ServerlessWorkflow.Sdk.Builders/Interfaces/ICompositeTaskDefinitionBuilder.cs index 1e0a299..6a2b59d 100644 --- a/src/ServerlessWorkflow.Sdk/IExtensible.cs +++ b/src/ServerlessWorkflow.Sdk.Builders/Interfaces/ICompositeTaskDefinitionBuilder.cs @@ -1,4 +1,4 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors +// Copyright © 2024-Present The Serverless Workflow Specification Authors // // Licensed under the Apache License, Version 2.0 (the "License"), // you may not use this file except in compliance with the License. @@ -11,17 +11,15 @@ // See the License for the specific language governing permissions and // limitations under the License. -namespace ServerlessWorkflow.Sdk; +namespace ServerlessWorkflow.Sdk.Builders; /// -/// Defines the fundamentals of an extensible object +/// Defines the fundamentals of a service used to build s /// -internal interface IExtensible +public interface ICompositeTaskDefinitionBuilder + : ITaskDefinitionBuilder, ITaskExecutionStrategyDefinitionBuilder { - /// - /// Gets an containing the object's extension data, if any - /// - IDictionary? ExtensionData { get; } + } diff --git a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IExtensionStateBuilder.cs b/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IConstantBackoffDefinitionBuilder.cs similarity index 72% rename from src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IExtensionStateBuilder.cs rename to src/ServerlessWorkflow.Sdk.Builders/Interfaces/IConstantBackoffDefinitionBuilder.cs index 90997a3..3f6604a 100644 --- a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IExtensionStateBuilder.cs +++ b/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IConstantBackoffDefinitionBuilder.cs @@ -1,4 +1,4 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors +// Copyright © 2024-Present The Serverless Workflow Specification Authors // // Licensed under the Apache License, Version 2.0 (the "License"), // you may not use this file except in compliance with the License. @@ -11,13 +11,13 @@ // See the License for the specific language governing permissions and // limitations under the License. -namespace ServerlessWorkflow.Sdk.Services.FluentBuilders; +namespace ServerlessWorkflow.Sdk.Builders; /// -/// Defines the fundamentals of a service used to build s fluently +/// Defines the fundamentals of a service used to build s /// -public interface IExtensionStateBuilder - : IStateBuilder +public interface IConstantBackoffDefinitionBuilder + : IBackoffDefinitionBuilder { diff --git a/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IContainerProcessDefinitionBuilder.cs b/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IContainerProcessDefinitionBuilder.cs new file mode 100644 index 0000000..afe3ade --- /dev/null +++ b/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IContainerProcessDefinitionBuilder.cs @@ -0,0 +1,82 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +using ServerlessWorkflow.Sdk.Models.Processes; + +namespace ServerlessWorkflow.Sdk.Builders; + +/// +/// Defines the fundamentals of a service used to build s +/// +public interface IContainerProcessDefinitionBuilder + : IProcessDefinitionBuilder +{ + + /// + /// Configures the container to use the specified image + /// + /// The image to use + /// The configured + IContainerProcessDefinitionBuilder WithImage(string image); + + /// + /// Configures the command, if any, to execute on the container + /// + /// The command to execute + /// The configured + IContainerProcessDefinitionBuilder WithCommand(string command); + + /// + /// Adds the specified container port mapping + /// + /// The configured + IContainerProcessDefinitionBuilder WithPort(ushort hostPort, ushort containerPort); + + /// + /// Sets the container's port mapping + /// + /// The host/container port mapping to use + /// The configured + IContainerProcessDefinitionBuilder WithPorts(IDictionary portMapping); + + /// + /// Adds the specified volume to the container + /// + /// The key of the volume to add + /// The volume to add + /// The configured + IContainerProcessDefinitionBuilder WithVolume(string key, string value); + + /// + /// Sets the container's volumes + /// + /// A key/value mapping of the volumes to use + /// The configured + IContainerProcessDefinitionBuilder WithVolumes(IDictionary volumes); + + /// + /// Adds the specified environment variable to the container + /// + /// The environment variable's name + /// The environment variable's value + /// The configured + IContainerProcessDefinitionBuilder WithEnvironment(string name, string value); + + /// + /// Sets the container's environment variables + /// + /// A name/value mapping of the environment variables to use + /// The configured + IContainerProcessDefinitionBuilder WithEnvironment(IDictionary environment); + +} diff --git a/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IEmitTaskDefinitionBuilder.cs b/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IEmitTaskDefinitionBuilder.cs new file mode 100644 index 0000000..dc032ea --- /dev/null +++ b/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IEmitTaskDefinitionBuilder.cs @@ -0,0 +1,37 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Builders; + +/// +/// Defines the fundamentals of a service used to build s +/// +public interface IEmitTaskDefinitionBuilder + : ITaskDefinitionBuilder +{ + + /// + /// Configures the that defines the event to emit + /// + /// The event to emit + /// The configured + IEmitTaskDefinitionBuilder Event(EventDefinition e); + + /// + /// Configures the that defines the event to emit + /// + /// An used to setup the event to emit + /// The configured + IEmitTaskDefinitionBuilder Event(Action setup); + +} diff --git a/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IEndpointDefinitionBuilder.cs b/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IEndpointDefinitionBuilder.cs new file mode 100644 index 0000000..eb49eca --- /dev/null +++ b/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IEndpointDefinitionBuilder.cs @@ -0,0 +1,69 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Builders; + +/// +/// Defines the fundamentals of a service used to build s +/// +/// The type of the to use +public interface IEndpointDefinitionBuilder + where TBuilder : IEndpointDefinitionBuilder +{ + + /// + /// Sets the endpoint's + /// + /// The endpoint's + /// The configured + TBuilder WithUri(Uri uri); + + /// + /// Configures the authentication policy used to get the external resource + /// + /// A reference to the authentication policy to use + /// The configured + TBuilder UseAuthentication(Uri reference); + + /// + /// Configures the authentication policy used to get the external resource + /// + /// The authentication policy to use + /// The configured + TBuilder UseAuthentication(AuthenticationPolicyDefinition authenticationPolicy); + + /// + /// Configures the authentication policy used to get the external resource + /// + /// An used to configure the authentication policy to use + /// The configured + TBuilder UseAuthentication(Action setup); + + /// + /// Builds the configured + /// + /// A new + EndpointDefinition Build(); + +} + +/// +/// Defines the fundamentals of a service used to build s +/// +public interface IEndpointDefinitionBuilder + : IEndpointDefinitionBuilder +{ + + + +} \ No newline at end of file diff --git a/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IErrorCatcherDefinitionBuilder.cs b/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IErrorCatcherDefinitionBuilder.cs new file mode 100644 index 0000000..b432310 --- /dev/null +++ b/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IErrorCatcherDefinitionBuilder.cs @@ -0,0 +1,91 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Builders; + +/// +/// Defines the fundamentals of a service used to build s +/// +public interface IErrorCatcherDefinitionBuilder +{ + + /// + /// Catches errors matching the specified filter + /// + /// The filter used to catch errors. If not set, catches all errors. + /// The configured + IErrorCatcherDefinitionBuilder Errors(ErrorFilterDefinition filter); + + /// + /// Catches errors matching the specified filter + /// + /// An used to setup the filter used to catch errors. If not set, catches all errors. + /// The configured + IErrorCatcherDefinitionBuilder Errors(Action setup); + + /// + /// Sets the name of the variable that contains caught errors + /// + /// The name of the variable that contains caught errors + /// The configured + IErrorCatcherDefinitionBuilder As(string variableName); + + /// + /// Sets the runtime expression used to determine whether to catch the filtered error + /// + /// The runtime expression used to determine whether to catch the filtered error + /// The configured + IErrorCatcherDefinitionBuilder When(string expression); + + /// + /// Sets the runtime expression used to determine whether not to catch the filtered error + /// + /// The runtime expression used to determine whether not to catch the filtered error + /// The configured + IErrorCatcherDefinitionBuilder ExceptWhen(string expression); + + /// + /// Sets the reference to the retry policy to use + /// + /// A reference to the retry policy to use + /// The configured + IErrorCatcherDefinitionBuilder Retry(Uri reference); + + /// + /// Sets the reference to the retry policy to use + /// + /// The retry policy to use + /// The configured + IErrorCatcherDefinitionBuilder Retry(RetryPolicyDefinition retryPolicy); + + /// + /// Sets the reference to the retry policy to use + /// + /// An used to setup the retry policy to use + /// The configured + IErrorCatcherDefinitionBuilder Retry(Action setup); + + /// + /// Configures the task to execute the specified task after catching or after retry exhaustion + /// + /// An used to setup the retry policy to use + /// The configured + IErrorCatcherDefinitionBuilder Do(Action setup); + + /// + /// Builds the configured + /// + /// A new + ErrorCatcherDefinition Build(); + +} diff --git a/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IErrorDefinitionBuilder.cs b/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IErrorDefinitionBuilder.cs new file mode 100644 index 0000000..342ee7f --- /dev/null +++ b/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IErrorDefinitionBuilder.cs @@ -0,0 +1,63 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Builders; + +/// +/// Defines the fundamentals of a service used to build s +/// +public interface IErrorDefinitionBuilder +{ + + /// + /// Sets the error's type + /// + /// The type of the error to build. Supports runtime expressions + /// The configures + IErrorDefinitionBuilder WithType(string type); + + /// + /// Sets the error's status + /// + /// The status of the error to build. Supports runtime expressions + /// The configures + IErrorDefinitionBuilder WithStatus(string status); + + /// + /// Sets the error's title + /// + /// The type of the error to build. Supports runtime expressions + /// The configures + IErrorDefinitionBuilder WithTitle(string title); + + /// + /// Sets the error's detail + /// + /// The detail of the error to build. Supports runtime expressions + /// The configures + IErrorDefinitionBuilder WithDetail(string detail); + + /// + /// Sets a reference to the component the error concerns + /// + /// The instance of the error to build. Supports runtime expressions + /// The configures + IErrorDefinitionBuilder WithInstance(string instance); + + /// + /// Builds the configured + /// + /// A new + ErrorDefinition Build(); + +} diff --git a/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IErrorFilterDefinitionBuilder.cs b/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IErrorFilterDefinitionBuilder.cs new file mode 100644 index 0000000..17b9029 --- /dev/null +++ b/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IErrorFilterDefinitionBuilder.cs @@ -0,0 +1,43 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Builders; + +/// +/// Defines the fundamentals of a service used to build s +/// +public interface IErrorFilterDefinitionBuilder +{ + + /// + /// Adds a new attribute filter + /// + /// The name of the attribute to filter errors by + /// The value of the attribute to filter errors by. Supports runtime expressions + /// The configured + IErrorFilterDefinitionBuilder With(string name, object value); + + /// + /// Sets a name/value mapping of the attributes to filter errors by + /// + /// A name/value mapping of the attributes to filter errors by. Supports runtime expressions + /// The configured + IErrorFilterDefinitionBuilder With(IDictionary attributes); + + /// + /// Builds the configured + /// + /// A new + ErrorFilterDefinition Build(); + +} diff --git a/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IEventDefinitionBuilder.cs b/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IEventDefinitionBuilder.cs new file mode 100644 index 0000000..5686b3e --- /dev/null +++ b/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IEventDefinitionBuilder.cs @@ -0,0 +1,43 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Builders; + +/// +/// Defines the fundamentals of a service used to build s +/// +public interface IEventDefinitionBuilder +{ + + /// + /// Adds a new attribute to the event + /// + /// The attribute's name + /// The attribute's value. Supports runtime expressions + /// The configured + IEventDefinitionBuilder With(string name, object value); + + /// + /// Sets the event's attributes + /// + /// A name/value mapping of the event's attributes. Supports runtime expressions + /// The configured + IEventDefinitionBuilder With(IDictionary attributes); + + /// + /// Builds the configured + /// + /// A new + EventDefinition Build(); + +} diff --git a/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IEventFilterDefinitionBuilder.cs b/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IEventFilterDefinitionBuilder.cs new file mode 100644 index 0000000..999cc64 --- /dev/null +++ b/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IEventFilterDefinitionBuilder.cs @@ -0,0 +1,43 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Builders; + +/// +/// Defines the fundamentals of a service used to build s +/// +public interface IEventFilterDefinitionBuilder +{ + + /// + /// Adds a new attribute to filter events by + /// + /// The name of the attribute to filter events by + /// The value of the attribute to filter events by. Supports runtime expressions + /// The configured + IEventFilterDefinitionBuilder With(string name, object value); + + /// + /// Sets a name/value mapping of the attributes to filter events by + /// + /// A name/value mapping of the attributes to filter events by. Supports runtime expressions + /// The configured + IEventFilterDefinitionBuilder With(IDictionary attributes); + + /// + /// Builds the configured + /// + /// A new + EventFilterDefinition Build(); + +} diff --git a/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IEventFilterDefinitionCollectionBuilder.cs b/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IEventFilterDefinitionCollectionBuilder.cs new file mode 100644 index 0000000..b410e26 --- /dev/null +++ b/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IEventFilterDefinitionCollectionBuilder.cs @@ -0,0 +1,44 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +using Neuroglia; + +namespace ServerlessWorkflow.Sdk.Builders; + +/// +/// Defines the fundamentals of a service used to build collections of s +/// +public interface IEventFilterDefinitionCollectionBuilder +{ + + /// + /// Adds the specified event filter to the collection + /// + /// The filter to add + /// The configured + IEventFilterDefinitionCollectionBuilder Event(EventFilterDefinition filter); + + /// + /// Adds the specified event filter to the collection + /// + /// An used to setup the filter to add + /// The configured + IEventFilterDefinitionCollectionBuilder Event(Action setup); + + /// + /// Builds the configured collection of s + /// + /// A new collection of s + EquatableList Build(); + +} diff --git a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IOperationStateBuilder.cs b/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IExponentialBackoffDefinitionBuilder.cs similarity index 69% rename from src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IOperationStateBuilder.cs rename to src/ServerlessWorkflow.Sdk.Builders/Interfaces/IExponentialBackoffDefinitionBuilder.cs index 570ac8a..56ce618 100644 --- a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IOperationStateBuilder.cs +++ b/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IExponentialBackoffDefinitionBuilder.cs @@ -1,4 +1,4 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors +// Copyright © 2024-Present The Serverless Workflow Specification Authors // // Licensed under the Apache License, Version 2.0 (the "License"), // you may not use this file except in compliance with the License. @@ -11,14 +11,15 @@ // See the License for the specific language governing permissions and // limitations under the License. -namespace ServerlessWorkflow.Sdk.Services.FluentBuilders; +namespace ServerlessWorkflow.Sdk.Builders; /// -/// Defines the fundamentals of a service used to build s +/// Defines the fundamentals of a service used to build s /// -public interface IOperationStateBuilder - : IStateBuilder, - IActionCollectionBuilder +public interface IExponentialBackoffDefinitionBuilder + : IBackoffDefinitionBuilder { + + } diff --git a/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IExtensionDefinitionBuilder.cs b/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IExtensionDefinitionBuilder.cs new file mode 100644 index 0000000..9ddc887 --- /dev/null +++ b/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IExtensionDefinitionBuilder.cs @@ -0,0 +1,78 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Builders; + +/// +/// Defines the fundamentals of a service used to build s +/// +public interface IExtensionDefinitionBuilder +{ + + /// + /// Configures the extension to build to extend the specified task type + /// + /// The type of task to extend + /// The configured + IExtensionDefinitionBuilder Extend(string taskType); + + /// + /// Configures the extension to build to extend the specified task type + /// + /// A runtime expression used to determine whether or not the extension applies + /// The configured + IExtensionDefinitionBuilder When(string when); + + /// + /// Configures the extension to execute the specified task before running the extended one + /// + /// An used to setup the task to execute + /// The configured + IExtensionDefinitionBuilder Before(Action setup); + + /// + /// Configures the extension to execute the specified task after running the extended one + /// + /// An used to setup the task to execute + /// The configured + IExtensionDefinitionBuilder After(Action setup); + + /// + /// Builds the configured + /// + /// A new + ExtensionDefinition Build(); + +} + +/// +/// Defines extensions for s +/// +public static class IExtensionDefinitionBuilderExtensions +{ + + /// + /// Configure the extension to build to extend all tasks + /// + /// The to configure + /// The configured + public static IExtensionDefinitionBuilder ExtendAll(this IExtensionDefinitionBuilder builder) => builder.Extend("all"); + + /// + /// Configure the extension to build to extend call tasks + /// + /// The to configure + /// The configured + public static IExtensionDefinitionBuilder ExtendCallTasks(this IExtensionDefinitionBuilder builder) => builder.Extend(TaskType.Call); + +} \ No newline at end of file diff --git a/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IExternalResourceDefinitionBuilder.cs b/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IExternalResourceDefinitionBuilder.cs new file mode 100644 index 0000000..23fc3a7 --- /dev/null +++ b/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IExternalResourceDefinitionBuilder.cs @@ -0,0 +1,36 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Builders; + +/// +/// Defines the fundamentals of a service used to build s +/// +public interface IExternalResourceDefinitionBuilder + : IEndpointDefinitionBuilder +{ + + /// + /// Configures the name of the referenced external resource + /// + /// The name of the referenced external resource + /// The configured + IExternalResourceDefinitionBuilder WithName(string name); + + /// + /// Builds the configured + /// + /// A new + new ExternalResourceDefinition Build(); + +} diff --git a/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IForTaskDefinitionBuilder.cs b/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IForTaskDefinitionBuilder.cs new file mode 100644 index 0000000..e84fcd6 --- /dev/null +++ b/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IForTaskDefinitionBuilder.cs @@ -0,0 +1,51 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Builders; + +/// +/// Defines the fundamentals of a service used to build s +/// +public interface IForTaskDefinitionBuilder + : ITaskDefinitionBuilder +{ + + /// + /// Sets the name of the variable to store the iteration item to + /// + /// The name of the variable to store the iteration item to + /// The configured + IForTaskDefinitionBuilder Each(string variableName); + + /// + /// Sets the runtime expression used to resolve the collection to iterate + /// + /// The runtime expression used to resolve the collection to iterate + /// The configured + IForTaskDefinitionBuilder In(string expression); + + /// + /// Sets the name of the variable to store the iteration index to + /// + /// The name of the variable to store the iteration index to + /// The configured + IForTaskDefinitionBuilder At(string variableName); + + /// + /// Configures the task to execute the specified task for each item in the specified collection + /// + /// An used to setup the to execute + /// The configured + IForTaskDefinitionBuilder Do(Action setup); + +} diff --git a/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IGenericTaskDefinitionBuilder.cs b/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IGenericTaskDefinitionBuilder.cs new file mode 100644 index 0000000..64222f1 --- /dev/null +++ b/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IGenericTaskDefinitionBuilder.cs @@ -0,0 +1,121 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Builders; + +/// +/// Defines the fundamentals of a service used to create s +/// +public interface IGenericTaskDefinitionBuilder +{ + + /// + /// Configures the task to call the specified function + /// + /// The name of the function to call + /// A new + ICallTaskDefinitionBuilder Call(string? function = null); + + /// + /// Configures the task to emit the specified event + /// + /// The event to emit + /// The configured + IEmitTaskDefinitionBuilder Emit(EventDefinition e); + + /// + /// Configures the task to emit the specified event + /// + /// An used to setup the event to emit + /// The configured + IEmitTaskDefinitionBuilder Emit(Action setup); + + /// + /// Configures the task to iterate over a collection and perform a task for each of the items it contains + /// + /// A new + IForTaskDefinitionBuilder For(); + + /// + /// Configures the task to listen for events + /// + /// A new + IListenTaskDefinitionBuilder Listen(); + + /// + /// Configures the task to perform a list of subtasks + /// + /// A new + ICompositeTaskDefinitionBuilder Execute(); + + /// + /// Configures the task to raise the specified error + /// + /// The error to raise + /// The configured + IRaiseTaskDefinitionBuilder Raise(ErrorDefinition error); + + /// + /// Configures the task to raise the specified error + /// + /// An used to configure the error to raise + /// The configured + IRaiseTaskDefinitionBuilder Raise(Action setup); + + /// + /// Configures the task to run a process + /// + /// A new + IRunTaskDefinitionBuilder Run(); + + /// + /// Sets the specified variable + /// + /// The name of the variable to set + /// The value of the variable to set. Supports runtime expressions + /// A new + ISetTaskDefinitionBuilder Set(string name, string value); + + /// + /// Configures the task to set the specified variable + /// + /// A name/value mapping of the variables to set. Supports runtime expressions + /// A new + ISetTaskDefinitionBuilder Set(IDictionary? variables = null); + + /// + /// Configures the task to branch the flow based on defined conditions + /// + /// A new + ISwitchTaskDefinitionBuilder Switch(); + + /// + /// Configures the task to try executing a specific task, and handle potential errors + /// + /// + ITryTaskDefinitionBuilder Try(); + + /// + /// Configures the task to wait a defined amount of time + /// + /// The duration to wait for + /// A new + IWaitTaskDefinitionBuilder Wait(Duration? duration = null); + + /// + /// Builds a new + /// + /// A new + TaskDefinition Build(); + +} \ No newline at end of file diff --git a/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IHttpCallDefinitionBuilder.cs b/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IHttpCallDefinitionBuilder.cs new file mode 100644 index 0000000..222121f --- /dev/null +++ b/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IHttpCallDefinitionBuilder.cs @@ -0,0 +1,102 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +using ServerlessWorkflow.Sdk.Models.Calls; + +namespace ServerlessWorkflow.Sdk.Builders; + +/// +/// Defines the fundamentals of a service used to build s +/// +public interface IHttpCallDefinitionBuilder +{ + + /// + /// Sets the HTTP method of the request to perform + /// + /// The HTTP method of the request to perform + /// The configured + IHttpCallDefinitionBuilder WithMethod(string method); + + /// + /// Sets the to request + /// + /// The to request + /// The configured + IHttpCallDefinitionBuilder WithUri(Uri uri); + + /// + /// Sets the endpoint to request + /// + /// An used to setup the endpoint to request + /// The configured + IHttpCallDefinitionBuilder WithEndpoint(EndpointDefinition endpoint); + + /// + /// Sets the endpoint to request + /// + /// An used to setup the endpoint to request + /// The configured + IHttpCallDefinitionBuilder WithEndpoint(Action setup); + + /// + /// Sets the value of the header with the specified name + /// + /// The name of the header to set + /// The value of the header to set + /// The configured + IHttpCallDefinitionBuilder WithHeader(string name, string value); + + /// + /// Sets the headers of the HTTP request to perform + /// + /// The headers of the HTTP request to perform + /// The configured + IHttpCallDefinitionBuilder WithHeaders(IDictionary headers); + + /// + /// Sets the value of the cookie with the specified name + /// + /// The name of the cookie to set + /// The value of the cookie to set + /// The configured + IHttpCallDefinitionBuilder WithCookie(string name, string value); + + /// + /// Sets the cookies of the HTTP request to perform + /// + /// The cookies of the HTTP request to perform + /// The configured + IHttpCallDefinitionBuilder WithCookies(IDictionary cookies); + + /// + /// Sets the HTTP request body + /// + /// The request body + /// The configured + IHttpCallDefinitionBuilder WithBody(object body); + + /// + /// Uses the specified output format + /// + /// The format of the call's output + /// The configured + IHttpCallDefinitionBuilder WithOutputFormat(string format); + + /// + /// Builds the configured + /// + /// A new + HttpCallDefinition Build(); + +} \ No newline at end of file diff --git a/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IJitterDefinitionBuilder.cs b/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IJitterDefinitionBuilder.cs new file mode 100644 index 0000000..a4e389f --- /dev/null +++ b/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IJitterDefinitionBuilder.cs @@ -0,0 +1,42 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Builders; + +/// +/// Defines the fundamentals of a service used to build s +/// +public interface IJitterDefinitionBuilder +{ + + /// + /// Sets the jitter range's minimum duration + /// + /// The jitter range's minimum duration + /// The configured + IJitterDefinitionBuilder From(Duration from); + + /// + /// Sets the jitter range's maximum duration + /// + /// The jitter range's maximum duration + /// The configured + IJitterDefinitionBuilder To(Duration to); + + /// + /// Builds the configured + /// + /// A new + JitterDefinition Build(); + +} diff --git a/src/ServerlessWorkflow.Sdk.Builders/Interfaces/ILinearBackoffDefinitionBuilder.cs b/src/ServerlessWorkflow.Sdk.Builders/Interfaces/ILinearBackoffDefinitionBuilder.cs new file mode 100644 index 0000000..5e40990 --- /dev/null +++ b/src/ServerlessWorkflow.Sdk.Builders/Interfaces/ILinearBackoffDefinitionBuilder.cs @@ -0,0 +1,30 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Builders; + +/// +/// Defines the fundamentals of a service used to build s +/// +public interface ILinearBackoffDefinitionBuilder + : IBackoffDefinitionBuilder +{ + + /// + /// Sets the linear incrementation to the delay between retry attempts + /// + /// The linear incrementation to the delay between retry attempts + /// The configured + ILinearBackoffDefinitionBuilder WithIncrement(Duration increment); + +} diff --git a/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IListenTaskDefinitionBuilder.cs b/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IListenTaskDefinitionBuilder.cs new file mode 100644 index 0000000..0e6249e --- /dev/null +++ b/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IListenTaskDefinitionBuilder.cs @@ -0,0 +1,30 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Builders; + +/// +/// Defines the fundamentals of a service used to build s +/// +public interface IListenTaskDefinitionBuilder + : ITaskDefinitionBuilder +{ + + /// + /// Configures the task to listen to the specified event(s) + /// + /// An used to setup the task's listener target + /// The configured + IListenTaskDefinitionBuilder To(Action setup); + +} diff --git a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IInjectStateBuilder.cs b/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IListenerDefinitionBuilder.cs similarity index 56% rename from src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IInjectStateBuilder.cs rename to src/ServerlessWorkflow.Sdk.Builders/Interfaces/IListenerDefinitionBuilder.cs index 2933bec..b30dbd1 100644 --- a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IInjectStateBuilder.cs +++ b/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IListenerDefinitionBuilder.cs @@ -1,4 +1,4 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors +// Copyright © 2024-Present The Serverless Workflow Specification Authors // // Licensed under the Apache License, Version 2.0 (the "License"), // you may not use this file except in compliance with the License. @@ -11,20 +11,25 @@ // See the License for the specific language governing permissions and // limitations under the License. -namespace ServerlessWorkflow.Sdk.Services.FluentBuilders; +namespace ServerlessWorkflow.Sdk.Builders; /// -/// Defines the fundamentals of a service used to build s +/// Defines the fundamentals of a service used to build s /// -public interface IInjectStateBuilder - : IStateBuilder +public interface IListenerDefinitionBuilder { /// - /// Injects the specified data into the workflow + /// Configures the /// - /// The data to inject - /// A new - IInjectStateBuilder Data(object data); + /// + /// + IListenerDefinitionBuilder To(Action setup); -} + /// + /// Builds the configured + /// + /// A new + ListenerDefinition Build(); + +} \ No newline at end of file diff --git a/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IListenerTargetDefinitionBuilder.cs b/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IListenerTargetDefinitionBuilder.cs new file mode 100644 index 0000000..45a558c --- /dev/null +++ b/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IListenerTargetDefinitionBuilder.cs @@ -0,0 +1,46 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Builders; + +/// +/// Defines the fundamentals of a service used to build s +/// +public interface IListenerTargetDefinitionBuilder +{ + + /// + /// Configures the task to listen for all of the defined events + /// + /// A new + IEventFilterDefinitionCollectionBuilder All(); + + /// + /// Configures the task to listen for any of the defined events + /// + /// A new + IEventFilterDefinitionCollectionBuilder Any(); + + /// + /// Configures the task to listen for one single event + /// + /// A new + IEventFilterDefinitionBuilder One(); + + /// + /// Builds the configured + /// + /// A new + EventConsumptionStrategyDefinition Build(); + +} diff --git a/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IOAuth2AuthenticationClientDefinitionBuilder.cs b/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IOAuth2AuthenticationClientDefinitionBuilder.cs new file mode 100644 index 0000000..a0d7e40 --- /dev/null +++ b/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IOAuth2AuthenticationClientDefinitionBuilder.cs @@ -0,0 +1,42 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Builders; + +/// +/// Defines the fundamentals of a service used to build s +/// +public interface IOAuth2AuthenticationClientDefinitionBuilder +{ + + /// + /// Sets the OAUTH2 client's id + /// + /// The client's id + /// The configured + IOAuth2AuthenticationClientDefinitionBuilder WithId(string id); + + /// + /// Sets the OAUTH2 client's secret + /// + /// The client's secret + /// The configured + IOAuth2AuthenticationClientDefinitionBuilder WithSecret(string secret); + + /// + /// Builds the configured + /// + /// A new + OAuth2AuthenticationClientDefinition Build(); + +} diff --git a/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IOAuth2AuthenticationSchemeDefinitionBuilder.cs b/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IOAuth2AuthenticationSchemeDefinitionBuilder.cs new file mode 100644 index 0000000..6ec864f --- /dev/null +++ b/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IOAuth2AuthenticationSchemeDefinitionBuilder.cs @@ -0,0 +1,94 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Builders; + +/// +/// Defines the fundamentals of a service used to build s +/// +public interface IOAuth2AuthenticationSchemeDefinitionBuilder + : IAuthenticationSchemeDefinitionBuilder +{ + + /// + /// Sets the uri of the OAUTH2 authority to use + /// + /// The to the OAUTH2 authority to use + /// The configured + IOAuth2AuthenticationSchemeDefinitionBuilder WithAuthority(Uri uri); + + /// + /// Sets the grant type to use + /// + /// The grant type to use + /// The configured + IOAuth2AuthenticationSchemeDefinitionBuilder WithGrantType(string grantType); + + /// + /// Sets the definition of the client to use + /// + /// The to use + /// The configured + IOAuth2AuthenticationSchemeDefinitionBuilder WithClient(OAuth2AuthenticationClientDefinition client); + + /// + /// Sets the definition of the client to use + /// + /// An used to setup the to use + /// The configured + IOAuth2AuthenticationSchemeDefinitionBuilder WithClient(Action setup); + + /// + /// Sets the scopes to request the token for + /// + /// The scopes to request the token for + /// The configured + IOAuth2AuthenticationSchemeDefinitionBuilder WithScopes(params string[] scopes); + + /// + /// Sets the audiences to request the token for + /// + /// The audiences to request the token for + /// The configured + IOAuth2AuthenticationSchemeDefinitionBuilder WithAudiences(params string[] audiences); + + /// + /// Sets the username to use. Used only if grant type is + /// + /// The username to use + /// The configured + IOAuth2AuthenticationSchemeDefinitionBuilder WithUsername(string username); + + /// + /// Sets the password to use. Used only if grant type is + /// + /// The password to use + /// The configured + IOAuth2AuthenticationSchemeDefinitionBuilder WithPassword(string password); + + /// + /// Sets the security token that represents the identity of the party on behalf of whom the request is being made. Used only if grant type is , in which case it is required + /// + /// The representing the identity of the party + /// The configured + IOAuth2AuthenticationSchemeDefinitionBuilder WithSubject(OAuth2TokenDefinition subject); + + /// + /// Sets the security token that represents the identity of the acting party. Typically, this will be the party that is authorized to use the requested security token and act on behalf of the subject. + /// Used only if grant type is , in which case it is required + /// + /// The representing the identity of the acting party + /// The configured + IOAuth2AuthenticationSchemeDefinitionBuilder WithActor(OAuth2TokenDefinition actor); + +} diff --git a/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IProcessDefinitionBuilder.cs b/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IProcessDefinitionBuilder.cs new file mode 100644 index 0000000..23996be --- /dev/null +++ b/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IProcessDefinitionBuilder.cs @@ -0,0 +1,45 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Builders; + +/// +/// Defines the fundamentals of a service used to build s +/// +public interface IProcessDefinitionBuilder +{ + + /// + /// Builds the configured + /// + /// A new + ProcessDefinition Build(); + +} + +/// +/// Defines the fundamentals of a service used to build s +/// +/// The type of to build +public interface IProcessDefinitionBuilder + : IProcessDefinitionBuilder + where TDefinition : ProcessDefinition +{ + + /// + /// Builds the configured + /// + /// A new + new TDefinition Build(); + +} \ No newline at end of file diff --git a/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IRaiseTaskDefinitionBuilder.cs b/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IRaiseTaskDefinitionBuilder.cs new file mode 100644 index 0000000..0f9933b --- /dev/null +++ b/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IRaiseTaskDefinitionBuilder.cs @@ -0,0 +1,36 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Builders; + +/// +/// Defines the fundamentals of a service used to build s +/// +public interface IRaiseTaskDefinitionBuilder +{ + + /// + /// Configures the task to raise the specified error + /// + /// The error to raise + /// The configured + IRaiseTaskDefinitionBuilder Error(ErrorDefinition error); + + /// + /// Configures the task to raise the specified error + /// + /// An used to configure the error to raise + /// The configured + IRaiseTaskDefinitionBuilder Error(Action setup); + +} diff --git a/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IRetryAttemptLimitDefinitionBuilder.cs b/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IRetryAttemptLimitDefinitionBuilder.cs new file mode 100644 index 0000000..1261723 --- /dev/null +++ b/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IRetryAttemptLimitDefinitionBuilder.cs @@ -0,0 +1,42 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Builders; + +/// +/// Defines the fundamentals of a service used to build s +/// +public interface IRetryAttemptLimitDefinitionBuilder +{ + + /// + /// Sets the maximum attempts count + /// + /// The maximum attempts count + /// The configured + IRetryAttemptLimitDefinitionBuilder Count(uint count); + + /// + /// Sets the maximum duration per attempt + /// + /// The maximum duration per attempt + /// The configured + IRetryAttemptLimitDefinitionBuilder Duration(Duration duration); + + /// + /// Builds the configured + /// + /// A new + RetryAttemptLimitDefinition Build(); + +} diff --git a/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IRetryPolicyDefinitionBuilder.cs b/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IRetryPolicyDefinitionBuilder.cs new file mode 100644 index 0000000..f1c61e3 --- /dev/null +++ b/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IRetryPolicyDefinitionBuilder.cs @@ -0,0 +1,91 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Builders; + +/// +/// Defines the fundamentals of a service used to build s +/// +public interface IRetryPolicyDefinitionBuilder +{ + + /// + /// Sets the runtime expression used to determine whether to retry the filtered error + /// + /// The runtime expression used to determine whether to retry the filtered error + /// The configured + IRetryPolicyDefinitionBuilder When(string expression); + + /// + /// Sets the runtime expression used to determine whether not to retry the filtered error + /// + /// The runtime expression used to determine whether not to retry the filtered error + /// The configured + IRetryPolicyDefinitionBuilder ExceptWhen(string expression); + + /// + /// Sets the limits of the retry policy to build + /// + /// The to use + /// The configured + IRetryPolicyDefinitionBuilder Limit(RetryPolicyLimitDefinition limits); + + /// + /// Sets the limits of the retry policy to build + /// + /// An used to build the to use + /// The configured + IRetryPolicyDefinitionBuilder Limit(Action setup); + + /// + /// Sets the delay duration between retry attempts + /// + /// The duration between retry attempts + /// The configured + IRetryPolicyDefinitionBuilder Delay(Duration duration); + + /// + /// Sets the backoff strategy of the retry policy to build + /// + /// The to use + /// The configured + IRetryPolicyDefinitionBuilder Backoff(BackoffStrategyDefinition backoff); + + /// + /// Sets the backoff strategy of the retry policy to build + /// + /// An used to build the to use + /// The configured + IRetryPolicyDefinitionBuilder Backoff(Action setup); + + /// + /// Sets the jitter to apply to the retry policy to build + /// + /// The to use + /// The configured + IRetryPolicyDefinitionBuilder Jitter(JitterDefinition jitter); + + /// + /// Sets the jitter to apply to the retry policy to build + /// + /// An used to build the to use + /// The configured + IRetryPolicyDefinitionBuilder Jitter(Action setup); + + /// + /// Builds the configured + /// + /// A new + RetryPolicyDefinition Build(); + +} diff --git a/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IRetryPolicyLimitDefinitionBuilder.cs b/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IRetryPolicyLimitDefinitionBuilder.cs new file mode 100644 index 0000000..33f3982 --- /dev/null +++ b/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IRetryPolicyLimitDefinitionBuilder.cs @@ -0,0 +1,41 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Builders; + +/// +/// Defines the fundamentals of a service used to build s +/// +public interface IRetryPolicyLimitDefinitionBuilder +{ + + /// + /// Configures retry attempts limits + /// + /// A new + IRetryAttemptLimitDefinitionBuilder Attempt(); + + /// + /// Configures the maximum duration during which retrying is allowed + /// + /// The maximum duration during which retrying is allowed + /// The configured + IRetryPolicyLimitDefinitionBuilder Duration(Duration duration); + + /// + /// Builds the configured + /// + /// A new + RetryPolicyLimitDefinition Build(); + +} diff --git a/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IRunTaskDefinitionBuilder.cs b/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IRunTaskDefinitionBuilder.cs new file mode 100644 index 0000000..acc3993 --- /dev/null +++ b/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IRunTaskDefinitionBuilder.cs @@ -0,0 +1,47 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Builders; + +/// +/// Defines the fundamentals of a service used to build s +/// +public interface IRunTaskDefinitionBuilder + : ITaskDefinitionBuilder +{ + + /// + /// Configures the task to run the specified container + /// + /// A new + IContainerProcessDefinitionBuilder Container(); + + /// + /// Configures the task to run the specified script + /// + /// A new + IScriptProcessDefinitionBuilder Script(); + + /// + /// Configures the task to run the specified shell command + /// + /// A new + IShellProcessDefinitionBuilder Shell(); + + /// + /// Configures the task to run the specified workflow + /// + /// A new + IWorkflowProcessDefinitionBuilder Workflow(); + +} diff --git a/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IScriptProcessDefinitionBuilder.cs b/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IScriptProcessDefinitionBuilder.cs new file mode 100644 index 0000000..53cdf74 --- /dev/null +++ b/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IScriptProcessDefinitionBuilder.cs @@ -0,0 +1,53 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +using ServerlessWorkflow.Sdk.Models.Processes; + +namespace ServerlessWorkflow.Sdk.Builders; + +/// +/// Defines the fundamentals of a service used to build s +/// +public interface IScriptProcessDefinitionBuilder + : IProcessDefinitionBuilder +{ + + /// + /// Sets the language of the script to run + /// + /// The language of the script to run + /// The configured + IScriptProcessDefinitionBuilder WithLanguage(string language); + + /// + /// Sets the code of the script to run + /// + /// The script's code + /// The configured + IScriptProcessDefinitionBuilder WithCode(string code); + + /// + /// Sets the source of the script to run + /// + /// A uri that reference the script's source + /// The configured + IScriptProcessDefinitionBuilder WithSource(Uri source); + + /// + /// Sets the source of the script to run + /// + /// An used to setup the script's source + /// The configured + IScriptProcessDefinitionBuilder WithSource(Action setup); + +} diff --git a/src/ServerlessWorkflow.Sdk.Builders/Interfaces/ISetTaskDefinitionBuilder.cs b/src/ServerlessWorkflow.Sdk.Builders/Interfaces/ISetTaskDefinitionBuilder.cs new file mode 100644 index 0000000..6073be7 --- /dev/null +++ b/src/ServerlessWorkflow.Sdk.Builders/Interfaces/ISetTaskDefinitionBuilder.cs @@ -0,0 +1,38 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Builders; + +/// +/// Defines the fundamentals of a service used to build s +/// +public interface ISetTaskDefinitionBuilder + : ITaskDefinitionBuilder +{ + + /// + /// Sets the specified variable + /// + /// The name of the variable to set + /// The value of the variable to set. Supports runtime expressions + /// The configured + ISetTaskDefinitionBuilder Set(string name, object value); + + /// + /// Configures the task to set the specified variable + /// + /// A name/value mapping of the variables to set + /// The configured + ISetTaskDefinitionBuilder Set(IDictionary variables); + +} diff --git a/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IShellProcessDefinitionBuilder.cs b/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IShellProcessDefinitionBuilder.cs new file mode 100644 index 0000000..8a1d33d --- /dev/null +++ b/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IShellProcessDefinitionBuilder.cs @@ -0,0 +1,61 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +using ServerlessWorkflow.Sdk.Models.Processes; + +namespace ServerlessWorkflow.Sdk.Builders; + +/// +/// Defines the fundamentals of a service used to build shell-based s +/// +public interface IShellProcessDefinitionBuilder + : IProcessDefinitionBuilder +{ + + /// + /// Configures the task to execute the specified shell command + /// + /// The shell command to execute. Supports runtime expressions + /// The configured + IShellProcessDefinitionBuilder WithCommand(string command); + + /// + /// Adds a new argument to execute the shell command with + /// + /// The argument to use + /// The configured + IShellProcessDefinitionBuilder WithArgument(string argument); + + /// + /// Sets the arguments of the shell command to execute + /// + /// A list of the arguments to use + /// The configured + IShellProcessDefinitionBuilder WithArguments(IEnumerable arguments); + + /// + /// Adds the specified environment variable to the process + /// + /// The environment variable's name + /// The environment variable's value + /// The configured + IShellProcessDefinitionBuilder WithEnvironment(string name, string value); + + /// + /// Sets the process's environment variables + /// + /// A name/value mapping of the environment variables to use + /// The configured + IShellProcessDefinitionBuilder WithEnvironment(IDictionary environment); + +} diff --git a/src/ServerlessWorkflow.Sdk.Builders/Interfaces/ISwitchCaseDefinitionBuilder.cs b/src/ServerlessWorkflow.Sdk.Builders/Interfaces/ISwitchCaseDefinitionBuilder.cs new file mode 100644 index 0000000..9e834c8 --- /dev/null +++ b/src/ServerlessWorkflow.Sdk.Builders/Interfaces/ISwitchCaseDefinitionBuilder.cs @@ -0,0 +1,42 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Builders; + +/// +/// Defines the fundamentals of a service used to build s +/// +public interface ISwitchCaseDefinitionBuilder +{ + + /// + /// Sets a runtime expression that defines whether or not the case applies + /// + /// A runtime expression that defines whether or not the case applies + /// The configured + ISwitchCaseDefinitionBuilder When(string expression); + + /// + /// Sets the flow directive to execute when the case is matched + /// + /// The flow directive to execute + /// The configured + ISwitchCaseDefinitionBuilder Then(string directive); + + /// + /// Builds the configured + /// + /// A new + SwitchCaseDefinition Build(); + +} diff --git a/src/ServerlessWorkflow.Sdk.Builders/Interfaces/ISwitchTaskDefinitionBuilder.cs b/src/ServerlessWorkflow.Sdk.Builders/Interfaces/ISwitchTaskDefinitionBuilder.cs new file mode 100644 index 0000000..d1f0b0d --- /dev/null +++ b/src/ServerlessWorkflow.Sdk.Builders/Interfaces/ISwitchTaskDefinitionBuilder.cs @@ -0,0 +1,36 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Builders; + +/// +/// Defines the fundamentals of a service used to build s +/// +public interface ISwitchTaskDefinitionBuilder +{ + + /// + /// Adds a new case + /// + /// The name of the case to add + /// An used to setup the case to add + /// The configured + ISwitchTaskDefinitionBuilder Case(string name, Action setup); + + /// + /// Builds the configured + /// + /// A new + SwitchTaskDefinition Build(); + +} diff --git a/src/ServerlessWorkflow.Sdk.Builders/Interfaces/ITaskDefinitionBuilder.cs b/src/ServerlessWorkflow.Sdk.Builders/Interfaces/ITaskDefinitionBuilder.cs new file mode 100644 index 0000000..fea0f01 --- /dev/null +++ b/src/ServerlessWorkflow.Sdk.Builders/Interfaces/ITaskDefinitionBuilder.cs @@ -0,0 +1,45 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Builders; + +/// +/// Defines the fundamentals of a service used to build s +/// +public interface ITaskDefinitionBuilder +{ + + /// + /// Builds the configured + /// + /// A new + TaskDefinition Build(); + +} + +/// +/// Defines the fundamentals of a service used to build s +/// +/// The type of to build and configure +public interface ITaskDefinitionBuilder + : ITaskDefinitionBuilder + where TDefinition : TaskDefinition +{ + + /// + /// Builds the + /// + /// A new + new TDefinition Build(); + +} diff --git a/src/ServerlessWorkflow.Sdk.Builders/Interfaces/ITaskDefinitionMappingBuilder.cs b/src/ServerlessWorkflow.Sdk.Builders/Interfaces/ITaskDefinitionMappingBuilder.cs new file mode 100644 index 0000000..a123e65 --- /dev/null +++ b/src/ServerlessWorkflow.Sdk.Builders/Interfaces/ITaskDefinitionMappingBuilder.cs @@ -0,0 +1,51 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +using Neuroglia; + +namespace ServerlessWorkflow.Sdk.Builders; + +/// +/// Defines the fundamentals of a service used to build a configure collections +/// +/// The type of the +public interface ITaskDefinitionMappingBuilder + where TBuilder : ITaskDefinitionMappingBuilder +{ + + /// + /// Adds a new task with the specified name and configuration setup to the builder. + /// + /// The name of the task to add. + /// An action to configure the task definition. + /// The current instance of the task definition mapping builder. + TBuilder Do(string name, Action setup); + + /// + /// Builds the configured collection + /// + /// A new mapping of s by name + EquatableDictionary Build(); + +} + +/// +/// Defines the fundamentals of a service used to build a configure collections +/// +public interface ITaskDefinitionMappingBuilder + : ITaskDefinitionMappingBuilder +{ + + + +} diff --git a/src/ServerlessWorkflow.Sdk.Builders/Interfaces/ITaskExecutionStrategyDefinitionBuilder.cs b/src/ServerlessWorkflow.Sdk.Builders/Interfaces/ITaskExecutionStrategyDefinitionBuilder.cs new file mode 100644 index 0000000..db2c42a --- /dev/null +++ b/src/ServerlessWorkflow.Sdk.Builders/Interfaces/ITaskExecutionStrategyDefinitionBuilder.cs @@ -0,0 +1,61 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Builders; + +/// +/// Defines the fundamentals of a service used to build s +/// +/// The type of the +public interface ITaskExecutionStrategyDefinitionBuilder + where TBuilder : ITaskExecutionStrategyDefinitionBuilder +{ + + /// + /// Executes the specified subtasks sequentially + /// + /// An used to configure the subtasks to execute + /// The configured + TBuilder Sequentially(Action setup); + + /// + /// Executes the specified subtasks concurrently + /// + /// An used to configure the subtasks to execute + /// The configured + TBuilder Concurrently(Action setup); + + /// + /// Configures the concurrent tasks to race each other, with only one winner setting the task's output + /// + /// The configure + TBuilder Compete(); + + /// + /// Builds the configured + /// + /// A new + TaskExecutionStrategyDefinition Build(); + +} + +/// +/// Defines the fundamentals of a service used to build s +/// +public interface ITaskExecutionStrategyDefinitionBuilder + : ITaskExecutionStrategyDefinitionBuilder +{ + + + +} \ No newline at end of file diff --git a/src/ServerlessWorkflow.Sdk.Builders/Interfaces/ITryTaskDefinitionBuilder.cs b/src/ServerlessWorkflow.Sdk.Builders/Interfaces/ITryTaskDefinitionBuilder.cs new file mode 100644 index 0000000..a6db4a5 --- /dev/null +++ b/src/ServerlessWorkflow.Sdk.Builders/Interfaces/ITryTaskDefinitionBuilder.cs @@ -0,0 +1,37 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Builders; + +/// +/// Defines the fundamentals of a service used to build s +/// +public interface ITryTaskDefinitionBuilder + : ITaskDefinitionBuilder +{ + + /// + /// Configures the task to try executing the specified task + /// + /// An used to setup the task to try + /// The configured + ITryTaskDefinitionBuilder Do(Action setup); + + /// + /// Configures the task to catch defined errors + /// + /// An used to setup the to use + /// The configured + ITryTaskDefinitionBuilder Catch(Action setup); + +} diff --git a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IDelayStateBuilder.cs b/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IWaitTaskDefinitionBuilder.cs similarity index 58% rename from src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IDelayStateBuilder.cs rename to src/ServerlessWorkflow.Sdk.Builders/Interfaces/IWaitTaskDefinitionBuilder.cs index 8c5d1e9..620282b 100644 --- a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IDelayStateBuilder.cs +++ b/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IWaitTaskDefinitionBuilder.cs @@ -1,4 +1,4 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors +// Copyright © 2024-Present The Serverless Workflow Specification Authors // // Licensed under the Apache License, Version 2.0 (the "License"), // you may not use this file except in compliance with the License. @@ -11,20 +11,20 @@ // See the License for the specific language governing permissions and // limitations under the License. -namespace ServerlessWorkflow.Sdk.Services.FluentBuilders; +namespace ServerlessWorkflow.Sdk.Builders; /// -/// Defines the fundamentals of a service used to build s +/// Defines the fundamentals of a service used to build s /// -public interface IDelayStateBuilder - : IStateBuilder +public interface IWaitTaskDefinitionBuilder + : ITaskDefinitionBuilder { /// - /// Configures the duration of the workflow execution's delay + /// Configures the task to wait for a specified amount of time /// - /// The duration of the workflow execution's delay - /// The configured - IDelayStateBuilder For(TimeSpan duration); + /// The amount of time to wait for + /// The configured + public IWaitTaskDefinitionBuilder For(Duration duration); } diff --git a/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IWorkflowDefinitionBuilder.cs b/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IWorkflowDefinitionBuilder.cs new file mode 100644 index 0000000..30db594 --- /dev/null +++ b/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IWorkflowDefinitionBuilder.cs @@ -0,0 +1,173 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Builders; + +/// +/// Defines the fundamentals of a service used to build and configure s +/// +public interface IWorkflowDefinitionBuilder + : ITaskDefinitionMappingBuilder +{ + + /// + /// Sets the workflow's namespace + /// + /// The workflow's namespace + /// The configured + IWorkflowDefinitionBuilder WithNamespace(string @namespace); + + /// + /// Sets the workflow's name + /// + /// The workflow's name + /// The configured + IWorkflowDefinitionBuilder WithName(string name); + + /// + /// Sets the workflow's semantic version + /// + /// The workflow's semantic version + /// The configured + IWorkflowDefinitionBuilder WithVersion(string version); + + /// + /// Sets the workflow's title + /// + /// The workflow's title + /// The configured + IWorkflowDefinitionBuilder WithTitle(string title); + + /// + /// Sets the workflow's summary + /// + /// The workflow's summary + /// The configured + IWorkflowDefinitionBuilder WithSummary(string summary); + + /// + /// Adds a new tag to the workflow + /// + /// The tag's name + /// The tag's value + /// The configured + IWorkflowDefinitionBuilder WithTag(string name, string value); + + /// + /// Sets the tags of the workflow + /// + /// A name/value mapping of the workflow's tags + /// The configured + IWorkflowDefinitionBuilder WithTag(IDictionary arguments); + + /// + /// Uses the specified authentication policy + /// + /// The name of the authentication policy to register + /// The authentication policy to use + /// The configured + IWorkflowDefinitionBuilder UseAuthentication(string name, AuthenticationPolicyDefinition authentication); + + /// + /// Uses the specified authentication policy + /// + /// The name of the authentication policy to register + /// An used to setup the authentication policy to use + /// The configured + IWorkflowDefinitionBuilder UseAuthentication(string name, Action setup); + + /// + /// Uses the specified extension + /// + /// The name of the extension to use + /// The definition of the extension to use + /// The configured + IWorkflowDefinitionBuilder UseExtension(string name, ExtensionDefinition extension); + + /// + /// Uses the specified extension + /// + /// The name of the extension to use + /// An used to setup the definition of the extension to use + /// The configured + IWorkflowDefinitionBuilder UseExtension(string name, Action setup); + + /// + /// Uses the specified function + /// + /// The name of the function to use + /// The underlying call task the function performs + /// The configured + IWorkflowDefinitionBuilder UseFunction(string name, CallTaskDefinition call); + + /// + /// Uses the specified function + /// + /// The name of the function to use + /// An used to setup the underlying call task the function performs + /// The configured + IWorkflowDefinitionBuilder UseFunction(string name, Action setup); + + /// + /// Uses the specified function + /// + /// The name of the function to use + /// The underlying run task the function performs + /// The configured + IWorkflowDefinitionBuilder UseFunction(string name, RunTaskDefinition run); + + /// + /// Uses the specified function + /// + /// The name of the function to use + /// An used to setup the underlying run task the function performs + /// The configured + IWorkflowDefinitionBuilder UseFunction(string name, Action setup); + + /// + /// Uses the specified retry policy + /// + /// The name of the retry policy to register + /// The retry policy to use + /// The configured + IWorkflowDefinitionBuilder UseRetry(string name, RetryPolicyDefinition retry); + + /// + /// Uses the specified retry policy + /// + /// The name of the retry policy to register + /// An used to setup the retry policy to use + /// The configured + IWorkflowDefinitionBuilder UseRetry(string name, Action setup); + + /// + /// Uses the specified secret + /// + /// The name of the secret to use + /// The configured + IWorkflowDefinitionBuilder UseSecret(string secret); + + /// + /// Uses the specified secrets + /// + /// A list containing the secrets to use + /// The configured + IWorkflowDefinitionBuilder UseSecrets(params string[] secrets); + + /// + /// Builds the configured + /// + /// A new + new WorkflowDefinition Build(); + +} diff --git a/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IWorkflowProcessDefinitionBuilder.cs b/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IWorkflowProcessDefinitionBuilder.cs new file mode 100644 index 0000000..f17c60b --- /dev/null +++ b/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IWorkflowProcessDefinitionBuilder.cs @@ -0,0 +1,53 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +using ServerlessWorkflow.Sdk.Models.Processes; + +namespace ServerlessWorkflow.Sdk.Builders; + +/// +/// Defines the fundamentals of a service used to build s +/// +public interface IWorkflowProcessDefinitionBuilder + : IProcessDefinitionBuilder +{ + + /// + /// Configures the task to run the workflow with the specified namespace + /// + /// The namespace the workflow to run belongs to + /// The configured + IWorkflowProcessDefinitionBuilder WithNamespace(string @namespace); + + /// + /// Configures the task to run the workflow with the specified name + /// + /// The name of the workflow to run + /// The configured + IWorkflowProcessDefinitionBuilder WithName(string name); + + /// + /// Configures the task to run the workflow with the specified version + /// + /// The version of the workflow to run + /// The configured + IWorkflowProcessDefinitionBuilder WithVersion(string version); + + /// + /// Sets the input of the workflow to run + /// + /// The input of the workflow to run. Supports runtime expressions + /// The configured + IWorkflowProcessDefinitionBuilder WithInput(object input); + +} \ No newline at end of file diff --git a/src/ServerlessWorkflow.Sdk.Builders/JitterDefinitionBuilder.cs b/src/ServerlessWorkflow.Sdk.Builders/JitterDefinitionBuilder.cs new file mode 100644 index 0000000..ee294d4 --- /dev/null +++ b/src/ServerlessWorkflow.Sdk.Builders/JitterDefinitionBuilder.cs @@ -0,0 +1,63 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Builders; + +/// +/// Represents the default implementation of the interface +/// +/// The minimum duration of the jitter range +/// The maximum duration of the jitter range +public class JitterDefinitionBuilder(Duration? from = null, Duration? to = null) + : IJitterDefinitionBuilder +{ + + /// + /// Gets the minimum duration of the jitter range + /// + protected Duration? JitterFrom { get; set; } = from; + + /// + /// Gets the maximum duration of the jitter range + /// + protected Duration? JitterTo { get; set; } = to; + + /// + public virtual IJitterDefinitionBuilder From(Duration from) + { + ArgumentNullException.ThrowIfNull(from); + this.JitterFrom = from; + return this; + } + + /// + public virtual IJitterDefinitionBuilder To(Duration to) + { + ArgumentNullException.ThrowIfNull(to); + this.JitterTo = to; + return this; + } + + /// + public virtual JitterDefinition Build() + { + if (this.JitterFrom == null) throw new NullReferenceException("The jitter range's minimum duration must be set"); + if (this.JitterTo == null) throw new NullReferenceException("The jitter range's maximum duration must be set"); + return new() + { + From = this.JitterFrom, + To = this.JitterTo, + }; + } + +} diff --git a/src/ServerlessWorkflow.Sdk.Builders/LinearBackoffDefinitionBuilder.cs b/src/ServerlessWorkflow.Sdk.Builders/LinearBackoffDefinitionBuilder.cs new file mode 100644 index 0000000..36f8f7a --- /dev/null +++ b/src/ServerlessWorkflow.Sdk.Builders/LinearBackoffDefinitionBuilder.cs @@ -0,0 +1,45 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Builders; + +/// +/// Represents the default implementation of the interface +/// +/// The linear incrementation to the delay between retry attempts +public class LinearBackoffDefinitionBuilder(Duration? increment = null) + : ILinearBackoffDefinitionBuilder +{ + + /// + /// Gets/sets the linear incrementation to the delay between retry attempts + /// + protected Duration? LinearIncrement { get; set; } = increment; + + /// + public virtual ILinearBackoffDefinitionBuilder WithIncrement(Duration increment) + { + ArgumentNullException.ThrowIfNull(increment); + this.LinearIncrement = increment; + return this; + } + + /// + public virtual LinearBackoffDefinition Build() => new() + { + Increment = this.LinearIncrement + }; + + BackoffDefinition IBackoffDefinitionBuilder.Build() => this.Build(); + +} diff --git a/src/ServerlessWorkflow.Sdk.Builders/ListenTaskDefinitionBuilder.cs b/src/ServerlessWorkflow.Sdk.Builders/ListenTaskDefinitionBuilder.cs new file mode 100644 index 0000000..194513f --- /dev/null +++ b/src/ServerlessWorkflow.Sdk.Builders/ListenTaskDefinitionBuilder.cs @@ -0,0 +1,51 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Builders; + +/// +/// Represents the default implementation of the interface +/// +public class ListenTaskDefinitionBuilder + : TaskDefinitionBuilder, IListenTaskDefinitionBuilder +{ + + /// + /// Gets/sets the task's listener configuration + /// + protected ListenerDefinition? Listener { get; set; } + + /// + public virtual IListenTaskDefinitionBuilder To(Action setup) + { + var builder = new ListenerTargetDefinitionBuilder(); + setup(builder); + var target = builder.Build(); + this.Listener = new() + { + To = target + }; + return this; + } + + /// + public override ListenTaskDefinition Build() + { + if (this.Listener == null) throw new NullReferenceException("The listener must be set"); + return new() + { + Listen = this.Listener + }; + } + +} \ No newline at end of file diff --git a/src/ServerlessWorkflow.Sdk.Builders/ListenerDefinitionBuilder.cs b/src/ServerlessWorkflow.Sdk.Builders/ListenerDefinitionBuilder.cs new file mode 100644 index 0000000..850af66 --- /dev/null +++ b/src/ServerlessWorkflow.Sdk.Builders/ListenerDefinitionBuilder.cs @@ -0,0 +1,48 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Builders; + +/// +/// Represents the default implementation of the interface +/// +/// The listener's target +public class ListenerDefinitionBuilder(EventConsumptionStrategyDefinition? target = null) + : IListenerDefinitionBuilder +{ + + /// + /// Gets/sets the listener's target + /// + protected EventConsumptionStrategyDefinition? Target { get; set; } = target; + + /// + public virtual IListenerDefinitionBuilder To(Action setup) + { + var builder = new ListenerTargetDefinitionBuilder(); + setup(builder); + this.Target = builder.Build(); + return this; + } + + /// + public virtual ListenerDefinition Build() + { + if (this.Target == null) throw new NullReferenceException("The listener's target must be set"); + return new() + { + To = this.Target + }; + } + +} \ No newline at end of file diff --git a/src/ServerlessWorkflow.Sdk.Builders/ListenerTargetDefinitionBuilder.cs b/src/ServerlessWorkflow.Sdk.Builders/ListenerTargetDefinitionBuilder.cs new file mode 100644 index 0000000..16a1225 --- /dev/null +++ b/src/ServerlessWorkflow.Sdk.Builders/ListenerTargetDefinitionBuilder.cs @@ -0,0 +1,71 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Builders; + +/// +/// Represents the default implementation of the interface +/// +public class ListenerTargetDefinitionBuilder + : IListenerTargetDefinitionBuilder +{ + + /// + /// Gets/sets a list containing all the events that must be listened to, if any + /// + protected IEventFilterDefinitionCollectionBuilder? AllEvents { get; set; } + + /// + /// Gets/sets a list containing any of the events to listen to, if any + /// + protected IEventFilterDefinitionCollectionBuilder? AnyEvents { get; set; } + + /// + /// Gets/sets the single event to listen to + /// + protected IEventFilterDefinitionBuilder? SingleEvent { get; set; } + + /// + public virtual IEventFilterDefinitionCollectionBuilder All() + { + this.AllEvents = new EventFilterDefinitionCollectionBuilder(); + return this.AllEvents; + } + + /// + public virtual IEventFilterDefinitionCollectionBuilder Any() + { + this.AnyEvents = new EventFilterDefinitionCollectionBuilder(); + return this.AnyEvents; + } + + /// + public virtual IEventFilterDefinitionBuilder One() + { + this.SingleEvent = new EventFilterDefinitionBuilder(); + return this.SingleEvent; + } + + /// + public virtual EventConsumptionStrategyDefinition Build() + { + if (this.AllEvents == null && this.AnyEvents == null && this.SingleEvent == null) throw new NullReferenceException("The target must be defined"); + return new() + { + All = this.AllEvents?.Build(), + Any = this.AnyEvents?.Build(), + One = this.SingleEvent?.Build() + }; + } + +} diff --git a/src/ServerlessWorkflow.Sdk.Builders/OAuth2AuthenticationClientDefinitionBuilder.cs b/src/ServerlessWorkflow.Sdk.Builders/OAuth2AuthenticationClientDefinitionBuilder.cs new file mode 100644 index 0000000..6333c2a --- /dev/null +++ b/src/ServerlessWorkflow.Sdk.Builders/OAuth2AuthenticationClientDefinitionBuilder.cs @@ -0,0 +1,60 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Builders; + +/// +/// Represents the default implementation of the interface +/// +public class OAuth2AuthenticationClientDefinitionBuilder + : IOAuth2AuthenticationClientDefinitionBuilder +{ + + /// + /// Gets/sets the OAUTH2 `client_id` to use + /// + protected string? Id { get; set; } + + /// + /// Gets/sets the OAUTH2 `client_secret` to use, if any + /// + protected string? Secret { get; set; } + + /// + public virtual IOAuth2AuthenticationClientDefinitionBuilder WithId(string id) + { + ArgumentException.ThrowIfNullOrEmpty(id); + this.Id = id; + return this; + } + + /// + public virtual IOAuth2AuthenticationClientDefinitionBuilder WithSecret(string secret) + { + ArgumentException.ThrowIfNullOrEmpty(secret); + this.Secret = secret; + return this; + } + + /// + public virtual OAuth2AuthenticationClientDefinition Build() + { + if (string.IsNullOrWhiteSpace(this.Id)) throw new NullReferenceException("The client id must be set"); + return new() + { + Id = this.Id!, + Secret = this.Secret + }; + } + +} diff --git a/src/ServerlessWorkflow.Sdk.Builders/OAuth2AuthenticationSchemeDefinitionBuilder.cs b/src/ServerlessWorkflow.Sdk.Builders/OAuth2AuthenticationSchemeDefinitionBuilder.cs new file mode 100644 index 0000000..47d87de --- /dev/null +++ b/src/ServerlessWorkflow.Sdk.Builders/OAuth2AuthenticationSchemeDefinitionBuilder.cs @@ -0,0 +1,170 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +using Neuroglia; + +namespace ServerlessWorkflow.Sdk.Builders; + +/// +/// Represents the default implementation of the interface +/// +public class OAuth2AuthenticationSchemeDefinitionBuilder + : IOAuth2AuthenticationSchemeDefinitionBuilder +{ + + /// + /// Gets/sets the uri that references the OAUTH2 authority to use + /// + protected Uri? Authority { get; set; } + + /// + /// Gets/sets the grant type to use + /// + protected string? GrantType { get; set; } + + /// + /// Gets/sets the definition of the client to use + /// + protected OAuth2AuthenticationClientDefinition? Client { get; set; } + + /// + /// Gets/sets the scopes, if any, to request the token for + /// + protected EquatableList? Scopes { get; set; } + + /// + /// Gets/sets the audiences, if any, to request the token for + /// + protected EquatableList? Audiences { get; set; } + + /// + /// Gets/sets the username to use. Used only if is + /// + protected string? Username { get; set; } + + /// + /// Gets/sets the password to use. Used only if is + /// + protected string? Password { get; set; } + + /// + /// Gets/sets the security token that represents the identity of the party on behalf of whom the request is being made. Used only if is , in which case it is required + /// + protected OAuth2TokenDefinition? Subject { get; set; } + + /// + /// Gets/sets the security token that represents the identity of the acting party. Typically, this will be the party that is authorized to use the requested security token and act on behalf of the subject. + /// Used only if is , in which case it is required + /// + protected OAuth2TokenDefinition? Actor { get; set; } + + /// + public virtual IOAuth2AuthenticationSchemeDefinitionBuilder WithAuthority(Uri uri) + { + ArgumentNullException.ThrowIfNull(uri); + this.Authority = uri; + return this; + } + + /// + public virtual IOAuth2AuthenticationSchemeDefinitionBuilder WithGrantType(string grantType) + { + ArgumentException.ThrowIfNullOrWhiteSpace(grantType); + this.GrantType = grantType; + return this; + } + + /// + public virtual IOAuth2AuthenticationSchemeDefinitionBuilder WithClient(OAuth2AuthenticationClientDefinition client) + { + ArgumentNullException.ThrowIfNull(client); + this.Client = client; + return this; + } + + /// + public virtual IOAuth2AuthenticationSchemeDefinitionBuilder WithClient(Action setup) + { + ArgumentNullException.ThrowIfNull(setup); + var builder = new OAuth2AuthenticationClientDefinitionBuilder(); + setup(builder); + this.Client = builder.Build(); + return this; + } + + /// + public virtual IOAuth2AuthenticationSchemeDefinitionBuilder WithAudiences(params string[] audiences) + { + ArgumentNullException.ThrowIfNull(audiences); + this.Audiences = new(audiences); + return this; + } + + /// + public virtual IOAuth2AuthenticationSchemeDefinitionBuilder WithScopes(params string[] scopes) + { + this.Scopes = new(scopes); + return this; + } + + /// + public virtual IOAuth2AuthenticationSchemeDefinitionBuilder WithActor(OAuth2TokenDefinition actor) + { + ArgumentNullException.ThrowIfNull(actor); + this.Actor = actor; + return this; + } + + /// + public virtual IOAuth2AuthenticationSchemeDefinitionBuilder WithUsername(string username) + { + this.Username = username; + return this; + } + + /// + public virtual IOAuth2AuthenticationSchemeDefinitionBuilder WithPassword(string password) + { + this.Password = password; + return this; + } + + /// + public virtual IOAuth2AuthenticationSchemeDefinitionBuilder WithSubject(OAuth2TokenDefinition subject) + { + this.Subject = subject; + return this; + } + + /// + public virtual OAuth2AuthenticationSchemeDefinition Build() + { + if (this.Authority == null) throw new NullReferenceException("The authority must be set"); + if (string.IsNullOrWhiteSpace(this.GrantType)) throw new NullReferenceException("The grant type must be set"); + if (this.Client == null) throw new NullReferenceException("The client must be set"); + return new() + { + Authority = this.Authority, + Grant = this.GrantType, + Client = this.Client, + Audiences = this.Audiences, + Scopes = this.Scopes, + Actor = this.Actor, + Username = this.Username, + Password = this.Password, + Subject = this.Subject + }; + } + + AuthenticationSchemeDefinition IAuthenticationSchemeDefinitionBuilder.Build() => this.Build(); +} diff --git a/src/ServerlessWorkflow.Sdk.Builders/ProcessDefinitionBuilder.cs b/src/ServerlessWorkflow.Sdk.Builders/ProcessDefinitionBuilder.cs new file mode 100644 index 0000000..0fa8ae6 --- /dev/null +++ b/src/ServerlessWorkflow.Sdk.Builders/ProcessDefinitionBuilder.cs @@ -0,0 +1,29 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Builders; + +/// +/// Represents the base class for all implementation of the interface +/// +/// The type of to build +public abstract class ProcessDefinitionBuilder + : IProcessDefinitionBuilder + where TDefinition : ProcessDefinition +{ + + /// + public abstract TDefinition Build(); + + ProcessDefinition IProcessDefinitionBuilder.Build() => this.Build(); +} \ No newline at end of file diff --git a/src/ServerlessWorkflow.Sdk.Builders/RaiseTaskDefinitionBuilder.cs b/src/ServerlessWorkflow.Sdk.Builders/RaiseTaskDefinitionBuilder.cs new file mode 100644 index 0000000..047177a --- /dev/null +++ b/src/ServerlessWorkflow.Sdk.Builders/RaiseTaskDefinitionBuilder.cs @@ -0,0 +1,59 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Builders; + +/// +/// Represents the default implementation of the interface +/// +/// The error to raise +public class RaiseTaskDefinitionBuilder(ErrorDefinition? errorDefinition = null) + : TaskDefinitionBuilder, IRaiseTaskDefinitionBuilder +{ + + /// + /// Gets/sets the error to raise + /// + protected ErrorDefinition? ErrorDefinition { get; set; } = errorDefinition; + + /// + public virtual IRaiseTaskDefinitionBuilder Error(ErrorDefinition error) + { + ArgumentNullException.ThrowIfNull(error); + this.ErrorDefinition = error; + return this; + } + + /// + public virtual IRaiseTaskDefinitionBuilder Error(Action setup) + { + ArgumentNullException.ThrowIfNull(setup); + var builder = new ErrorDefinitionBuilder(); + setup(builder); + return this.Error(builder.Build()); + } + + /// + public override RaiseTaskDefinition Build() + { + if (this.ErrorDefinition == null) throw new NullReferenceException("The error to raise must be set"); + return new() + { + Raise = new() + { + Error = this.ErrorDefinition + } + }; + } + +} diff --git a/src/ServerlessWorkflow.Sdk.Builders/RetryAttemptLimitDefinitionBuilder.cs b/src/ServerlessWorkflow.Sdk.Builders/RetryAttemptLimitDefinitionBuilder.cs new file mode 100644 index 0000000..3d20f28 --- /dev/null +++ b/src/ServerlessWorkflow.Sdk.Builders/RetryAttemptLimitDefinitionBuilder.cs @@ -0,0 +1,54 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Builders; + +/// +/// Represents the default implementation +/// +public class RetryAttemptLimitDefinitionBuilder + : IRetryAttemptLimitDefinitionBuilder +{ + + /// + /// Gets/sets the maximum attempts count + /// + protected uint? AttemptCount { get; set; } + + /// + /// Gets/sets the duration limit, if any, for all retry attempts + /// + protected Duration? AttemptDuration { get; set; } + + /// + public virtual IRetryAttemptLimitDefinitionBuilder Count(uint count) + { + this.AttemptCount = count; + return this; + } + + /// + public virtual IRetryAttemptLimitDefinitionBuilder Duration(Duration duration) + { + this.AttemptDuration = duration; + return this; + } + + /// + public virtual RetryAttemptLimitDefinition Build() => new() + { + Count = AttemptCount, + Duration = AttemptDuration + }; + +} \ No newline at end of file diff --git a/src/ServerlessWorkflow.Sdk.Builders/RetryPolicyDefinitionBuilder.cs b/src/ServerlessWorkflow.Sdk.Builders/RetryPolicyDefinitionBuilder.cs new file mode 100644 index 0000000..c8adb67 --- /dev/null +++ b/src/ServerlessWorkflow.Sdk.Builders/RetryPolicyDefinitionBuilder.cs @@ -0,0 +1,133 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Builders; + +/// +/// Represents the default implementation of the interface +/// +public class RetryPolicyDefinitionBuilder + : IRetryPolicyDefinitionBuilder +{ + + /// + /// Gets/sets a runtime expression used to determine whether or not to retry running the task, in a given context + /// + protected string? RetryWhen { get; set; } + + /// + /// Gets/sets a runtime expression used to determine whether or not to retry running the task, in a given context + /// + protected string? RetryExceptWhen { get; set; } + + /// + /// Gets/sets the parameters, if any, that control the randomness or variability of the delay between retry attempts + /// + protected RetryPolicyLimitDefinition? RetryLimit { get; set; } + + /// + /// Gets/sets the delay duration between retry attempts + /// + protected Duration? RetryDelay { get; set; } + + /// + /// Gets/sets the limits, if any, of the retry policy to build + /// + protected BackoffStrategyDefinition? RetryBackoff { get; set; } + + /// + /// Gets/sets the backoff strategy to use, if any + /// + protected JitterDefinition? RetryJitter { get; set; } + + /// + public virtual IRetryPolicyDefinitionBuilder When(string expression) + { + this.RetryWhen = expression; + return this; + } + + /// + public virtual IRetryPolicyDefinitionBuilder ExceptWhen(string expression) + { + this.RetryExceptWhen = expression; + return this; + } + + /// + public virtual IRetryPolicyDefinitionBuilder Limit(RetryPolicyLimitDefinition limits) + { + this.RetryLimit = limits; + return this; + } + + /// + public virtual IRetryPolicyDefinitionBuilder Limit(Action setup) + { + ArgumentNullException.ThrowIfNull(setup); + var builder = new RetryPolicyLimitDefinitionBuilder(); + setup(builder); + return this.Limit(builder.Build()); + } + + /// + public virtual IRetryPolicyDefinitionBuilder Delay(Duration duration) + { + this.RetryDelay = duration; + return this; + } + + /// + public virtual IRetryPolicyDefinitionBuilder Backoff(BackoffStrategyDefinition backoff) + { + this.RetryBackoff = backoff; + return this; + } + + /// + public virtual IRetryPolicyDefinitionBuilder Backoff(Action setup) + { + ArgumentNullException.ThrowIfNull(setup); + var builder = new BackoffStrategyDefinitionBuilder(); + setup(builder); + return this.Backoff(builder.Build()); + } + + /// + public virtual IRetryPolicyDefinitionBuilder Jitter(JitterDefinition jitter) + { + this.RetryJitter = jitter; + return this; + } + + /// + public virtual IRetryPolicyDefinitionBuilder Jitter(Action setup) + { + ArgumentNullException.ThrowIfNull(setup); + var builder = new JitterDefinitionBuilder(); + setup(builder); + return this.Jitter(builder.Build()); + } + + /// + public virtual RetryPolicyDefinition Build() => new() + { + When = this.RetryWhen, + ExceptWhen = this.RetryExceptWhen, + Limit = this.RetryLimit, + Delay = this.RetryDelay, + Backoff = this.RetryBackoff, + Jitter = this.RetryJitter + }; + +} diff --git a/src/ServerlessWorkflow.Sdk.Builders/RetryPolicyLimitDefinitionBuilder.cs b/src/ServerlessWorkflow.Sdk.Builders/RetryPolicyLimitDefinitionBuilder.cs new file mode 100644 index 0000000..4f0a83a --- /dev/null +++ b/src/ServerlessWorkflow.Sdk.Builders/RetryPolicyLimitDefinitionBuilder.cs @@ -0,0 +1,54 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Builders; + +/// +/// Represents the default implementation of the interface +/// +public class RetryPolicyLimitDefinitionBuilder + : IRetryPolicyLimitDefinitionBuilder +{ + + /// + /// Gets the service used to build the definition of the limits for all retry attempts of a given policy + /// + protected IRetryAttemptLimitDefinitionBuilder? LimitAttempt { get; set; } + + /// + /// Gets the maximum duration during which retrying is allowed + /// + protected Duration? LimitDuration { get; set; } + + /// + public virtual IRetryAttemptLimitDefinitionBuilder Attempt() + { + this.LimitAttempt = new RetryAttemptLimitDefinitionBuilder(); + return this.LimitAttempt; + } + + /// + public virtual IRetryPolicyLimitDefinitionBuilder Duration(Duration duration) + { + this.LimitDuration = duration; + return this; + } + + /// + public virtual RetryPolicyLimitDefinition Build() => new() + { + Attempt = this.LimitAttempt?.Build(), + Duration = this.LimitDuration, + }; + +} \ No newline at end of file diff --git a/src/ServerlessWorkflow.Sdk.Builders/RunTaskDefinitionBuilder.cs b/src/ServerlessWorkflow.Sdk.Builders/RunTaskDefinitionBuilder.cs new file mode 100644 index 0000000..273fcd2 --- /dev/null +++ b/src/ServerlessWorkflow.Sdk.Builders/RunTaskDefinitionBuilder.cs @@ -0,0 +1,79 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +using ServerlessWorkflow.Sdk.Models.Processes; + +namespace ServerlessWorkflow.Sdk.Builders; + +/// +/// Represents the default implementation of the interface +/// +public class RunTaskDefinitionBuilder + : TaskDefinitionBuilder, IRunTaskDefinitionBuilder +{ + + /// + /// Gets/sets the process to run + /// + protected IProcessDefinitionBuilder? ProcessBuilder { get; set; } + + /// + public virtual IContainerProcessDefinitionBuilder Container() + { + var builder = new ContainerProcessDefinitionBuilder(); + this.ProcessBuilder = builder; + return builder; + } + + /// + public virtual IScriptProcessDefinitionBuilder Script() + { + var builder = new ScriptProcessDefinitionBuilder(); + this.ProcessBuilder = builder; + return builder; + } + + /// + public virtual IShellProcessDefinitionBuilder Shell() + { + var builder = new ShellProcessDefinitionBuilder(); + this.ProcessBuilder = builder; + return builder; + } + + /// + public virtual IWorkflowProcessDefinitionBuilder Workflow() + { + var builder = new WorkflowProcessDefinitionBuilder(); + this.ProcessBuilder = builder; + return builder; + } + + /// + public override RunTaskDefinition Build() + { + if (this.ProcessBuilder == null) throw new NullReferenceException("The process to run must be set"); + var process = this.ProcessBuilder.Build(); + return new() + { + Run = new() + { + Container = process is ContainerProcessDefinition container ? container : null, + Script = process is ScriptProcessDefinition script ? script : null, + Shell = process is ShellProcessDefinition shell ? shell : null, + Workflow = process is WorkflowProcessDefinition workflow ? workflow : null + } + }; + } + +} diff --git a/src/ServerlessWorkflow.Sdk.Builders/ScriptProcessDefinitionBuilder.cs b/src/ServerlessWorkflow.Sdk.Builders/ScriptProcessDefinitionBuilder.cs new file mode 100644 index 0000000..ecff1f3 --- /dev/null +++ b/src/ServerlessWorkflow.Sdk.Builders/ScriptProcessDefinitionBuilder.cs @@ -0,0 +1,94 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +using ServerlessWorkflow.Sdk.Models.Processes; + +namespace ServerlessWorkflow.Sdk.Builders; + +/// +/// Represents the default implementation of the interface +/// +public class ScriptProcessDefinitionBuilder + : ProcessDefinitionBuilder, IScriptProcessDefinitionBuilder +{ + + /// + /// Gets/sets the language of the script to run + /// + public virtual string? Language { get; set; } + + /// + /// Gets/sets the script's code + /// + public virtual string? Code { get; set; } + + /// + /// Gets/sets the script's source + /// + public ExternalResourceDefinition? Source { get; set; } + + /// + /// Gets/sets the uri that references the script's source. + /// + public Uri? SourceUri { get; set; } + + /// + public virtual IScriptProcessDefinitionBuilder WithLanguage(string language) + { + ArgumentException.ThrowIfNullOrWhiteSpace(language); + this.Language = language; + return this; + } + + /// + public virtual IScriptProcessDefinitionBuilder WithCode(string code) + { + ArgumentException.ThrowIfNullOrWhiteSpace(code); + this.Code = code; + return this; + } + + /// + public virtual IScriptProcessDefinitionBuilder WithSource(Uri source) + { + ArgumentNullException.ThrowIfNull(source); + this.SourceUri = source; + return this; + } + + /// + public virtual IScriptProcessDefinitionBuilder WithSource(Action setup) + { + ArgumentNullException.ThrowIfNull(setup); + var builder = new ExternalResourceDefinitionBuilder(); + setup(builder); + this.Source = builder.Build(); + return this; + } + + /// + public override ScriptProcessDefinition Build() + { + if (string.IsNullOrWhiteSpace(this.Language)) throw new NullReferenceException("The language in which the script to run is expressed must be set"); + if (string.IsNullOrWhiteSpace(this.Code) && this.Source == null && this.SourceUri == null) throw new NullReferenceException("Either the code or the source properties must be set"); + var process = new ScriptProcessDefinition() + { + Language = this.Language, + Code = this.Code, + }; + if(this.Source != null) process.Source = this.Source; + else if(this.SourceUri != null) process.Source = new() { Uri = this.SourceUri }; + return process; + } + +} diff --git a/src/ServerlessWorkflow.Sdk.Builders/ServerlessWorkflow.Sdk.Builders.csproj b/src/ServerlessWorkflow.Sdk.Builders/ServerlessWorkflow.Sdk.Builders.csproj new file mode 100644 index 0000000..ea83870 --- /dev/null +++ b/src/ServerlessWorkflow.Sdk.Builders/ServerlessWorkflow.Sdk.Builders.csproj @@ -0,0 +1,39 @@ + + + + net8.0 + enable + enable + $(VersionPrefix)-alpha1 + 1.0.0 + $(VersionPrefix) + $(VersionPrefix) + en + true + True + true + Serverless Workflow SDK - Builders + Contains services used to build ServerlessWorkflow workflow definitions programatically + serverless-workflow;serverless;workflow;dsl;sdk;builders + true + Apache-2.0 + readme.md + Copyright © 2024-Present The Serverless Workflow Authors. All rights reserved. + https://github.com/serverlessworkflow/sdk-net + https://github.com/serverlessworkflow/sdk-net + git + embedded + + + + + \ + True + + + + + + + + diff --git a/src/ServerlessWorkflow.Sdk.Builders/SetTaskDefinitionBuilder.cs b/src/ServerlessWorkflow.Sdk.Builders/SetTaskDefinitionBuilder.cs new file mode 100644 index 0000000..277608f --- /dev/null +++ b/src/ServerlessWorkflow.Sdk.Builders/SetTaskDefinitionBuilder.cs @@ -0,0 +1,54 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +using Neuroglia; + +namespace ServerlessWorkflow.Sdk.Builders; + +/// +/// Represents the default implementation of the interface +/// +/// A name/value mapping of the variables to set +public class SetTaskDefinitionBuilder(IDictionary? variables = null) + : TaskDefinitionBuilder, + ISetTaskDefinitionBuilder +{ + + /// + /// Gets a name/value mapping of the variables to set + /// + protected EquatableDictionary Variables { get; set; } = [..variables]; + + /// + public virtual ISetTaskDefinitionBuilder Set(string name, object value) + { + ArgumentException.ThrowIfNullOrWhiteSpace(name); + this.Variables[name] = value; + return this; + } + + /// + public virtual ISetTaskDefinitionBuilder Set(IDictionary variables) + { + ArgumentNullException.ThrowIfNull(variables); + this.Variables = new(variables); + return this; + } + + /// + public override SetTaskDefinition Build() => new() + { + Set = this.Variables + }; + +} diff --git a/src/ServerlessWorkflow.Sdk.Builders/ShellProcessDefinitionBuilder.cs b/src/ServerlessWorkflow.Sdk.Builders/ShellProcessDefinitionBuilder.cs new file mode 100644 index 0000000..d0055ca --- /dev/null +++ b/src/ServerlessWorkflow.Sdk.Builders/ShellProcessDefinitionBuilder.cs @@ -0,0 +1,95 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +using ServerlessWorkflow.Sdk.Models.Processes; +using Neuroglia; + +namespace ServerlessWorkflow.Sdk.Builders; + +/// +/// Represents the default implementation of the interface +/// +public class ShellProcessDefinitionBuilder + : ProcessDefinitionBuilder, IShellProcessDefinitionBuilder +{ + + /// + /// Gets the command to execute + /// + protected virtual string? Command { get; set; } + + /// + /// Gets the arguments, if any, of the command to execute + /// + protected virtual EquatableList? Arguments { get; set; } + + /// + /// Gets/sets the environment variables, if any, of the shell command to execute + /// + protected virtual EquatableDictionary? Environment { get; set; } + + /// + public virtual IShellProcessDefinitionBuilder WithCommand(string command) + { + ArgumentException.ThrowIfNullOrWhiteSpace(command); + this.Command = command; + return this; + } + + /// + public virtual IShellProcessDefinitionBuilder WithArgument(string argument) + { + ArgumentException.ThrowIfNullOrWhiteSpace(argument); + this.Arguments ??= []; + this.Arguments.Add(argument); + return this; + } + + /// + public virtual IShellProcessDefinitionBuilder WithArguments(IEnumerable arguments) + { + ArgumentNullException.ThrowIfNull(arguments); + this.Arguments = new(arguments); + return this; + } + + /// + public virtual IShellProcessDefinitionBuilder WithEnvironment(string name, string value) + { + ArgumentException.ThrowIfNullOrWhiteSpace(name); + this.Environment ??= []; + this.Environment[name] = value; + return this; + } + + /// + public virtual IShellProcessDefinitionBuilder WithEnvironment(IDictionary environment) + { + ArgumentNullException.ThrowIfNull(environment); + this.Environment = new(environment); + return this; + } + + /// + public override ShellProcessDefinition Build() + { + if (string.IsNullOrWhiteSpace(this.Command)) throw new NullReferenceException("The shell command to execute must be set"); + return new() + { + Command = this.Command, + Arguments = this.Arguments, + Environment = this.Environment + }; + } + +} diff --git a/src/ServerlessWorkflow.Sdk.Builders/SwitchCaseDefinitionBuilder.cs b/src/ServerlessWorkflow.Sdk.Builders/SwitchCaseDefinitionBuilder.cs new file mode 100644 index 0000000..59ef137 --- /dev/null +++ b/src/ServerlessWorkflow.Sdk.Builders/SwitchCaseDefinitionBuilder.cs @@ -0,0 +1,58 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Builders; + +/// +/// Represents the default implementation of the interface +/// +public class SwitchCaseDefinitionBuilder + : ISwitchCaseDefinitionBuilder +{ + + /// + /// Gets/sets the runtime expression used to determine whether or not the case to build matches + /// + protected virtual string? WhenExpression { get; set; } + + /// + /// Gets/sets the flow directive to execute when the case to build matches + /// + protected virtual string? ThenDirective { get; set; } + + /// + public virtual ISwitchCaseDefinitionBuilder When(string expression) + { + this.WhenExpression = expression; + return this; + } + /// + public virtual ISwitchCaseDefinitionBuilder Then(string directive) + { + ArgumentException.ThrowIfNullOrWhiteSpace(directive); + this.ThenDirective = directive; + return this; + } + + /// + public virtual SwitchCaseDefinition Build() + { + if (string.IsNullOrWhiteSpace(this.ThenDirective)) throw new NullReferenceException("The flow directive to execute when the switch case matches must be set"); + return new() + { + When = this.WhenExpression, + Then = this.ThenDirective + }; + } + +} \ No newline at end of file diff --git a/src/ServerlessWorkflow.Sdk.Builders/SwitchTaskDefinitionBuilder.cs b/src/ServerlessWorkflow.Sdk.Builders/SwitchTaskDefinitionBuilder.cs new file mode 100644 index 0000000..16f5104 --- /dev/null +++ b/src/ServerlessWorkflow.Sdk.Builders/SwitchTaskDefinitionBuilder.cs @@ -0,0 +1,48 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +using Neuroglia; + +namespace ServerlessWorkflow.Sdk.Builders; + +/// +/// Represents the default implementation of the interface +/// +public class SwitchTaskDefinitionBuilder + : TaskDefinitionBuilder, ISwitchTaskDefinitionBuilder +{ + + /// + /// Gets a name/value mapping of the cases of the to build + /// + protected EquatableDictionary Cases { get; } = []; + + /// + public ISwitchTaskDefinitionBuilder Case(string name, Action setup) + { + ArgumentException.ThrowIfNullOrWhiteSpace(name); + ArgumentNullException.ThrowIfNull(setup); + var builder = new SwitchCaseDefinitionBuilder(); + setup(builder); + var @case = builder.Build(); + this.Cases[name] = @case; + return this; + } + + /// + public override SwitchTaskDefinition Build() => new() + { + Switch = this.Cases + }; + +} \ No newline at end of file diff --git a/src/ServerlessWorkflow.Sdk.Builders/TaskDefinitionBuilder.cs b/src/ServerlessWorkflow.Sdk.Builders/TaskDefinitionBuilder.cs new file mode 100644 index 0000000..d22c9a2 --- /dev/null +++ b/src/ServerlessWorkflow.Sdk.Builders/TaskDefinitionBuilder.cs @@ -0,0 +1,41 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Builders; + +/// +/// Represents the base class for all implementations +/// +/// The type of to build +public abstract class TaskDefinitionBuilder + : ITaskDefinitionBuilder + where TDefinition : TaskDefinition +{ + + /// + /// Applies the configuration common to all types of tasks + /// + /// The task definition to configure + /// The configured task definition + protected virtual TDefinition Configure(TDefinition definition) + { + //todo: common properties (timeouts, etc) + return definition; + } + + /// + public abstract TDefinition Build(); + + TaskDefinition ITaskDefinitionBuilder.Build() => this.Build(); + +} diff --git a/src/ServerlessWorkflow.Sdk.Builders/TaskDefinitionMappingBuilder.cs b/src/ServerlessWorkflow.Sdk.Builders/TaskDefinitionMappingBuilder.cs new file mode 100644 index 0000000..ea9b97f --- /dev/null +++ b/src/ServerlessWorkflow.Sdk.Builders/TaskDefinitionMappingBuilder.cs @@ -0,0 +1,50 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + + +using Neuroglia; + +namespace ServerlessWorkflow.Sdk.Builders; + +/// +/// Represents the default implementation of the interface +/// +public class TaskDefinitionMappingBuilder + : ITaskDefinitionMappingBuilder +{ + + /// + /// Gets a name/value mapping of the tasks the workflow is made out of + /// + protected EquatableDictionary? Tasks { get; set; } + + /// + public virtual ITaskDefinitionMappingBuilder Do(string name, Action setup) + { + ArgumentException.ThrowIfNullOrWhiteSpace(name); + ArgumentNullException.ThrowIfNull(setup); + var builder = new GenericTaskDefinitionBuilder(); + setup(builder); + this.Tasks ??= []; + this.Tasks[name] = builder.Build(); + return this; + } + + /// + public virtual EquatableDictionary Build() + { + if (this.Tasks == null || this.Tasks.Count < 1) throw new NullReferenceException("The task must define at least one subtask"); + return this.Tasks; + } + +} \ No newline at end of file diff --git a/src/ServerlessWorkflow.Sdk.Builders/TaskExecutionStrategyDefinitionBuilder.cs b/src/ServerlessWorkflow.Sdk.Builders/TaskExecutionStrategyDefinitionBuilder.cs new file mode 100644 index 0000000..05832c4 --- /dev/null +++ b/src/ServerlessWorkflow.Sdk.Builders/TaskExecutionStrategyDefinitionBuilder.cs @@ -0,0 +1,80 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +using Neuroglia; + +namespace ServerlessWorkflow.Sdk.Builders; + +/// +/// Represents the default implementation of the interface +/// +public class TaskExecutionStrategyDefinitionBuilder + : ITaskExecutionStrategyDefinitionBuilder +{ + + /// + /// Gets/sets a name/definition mapping of the tasks to execute sequentially, if any + /// + protected EquatableDictionary? SequentialTasks { get; set; } + + /// + /// Gets/sets a name/definition mapping of the tasks to execute concurrently, if any + /// + protected EquatableDictionary? ConcurrentTasks { get; set; } + + /// + /// Gets/sets a boolean indicating whether or not the concurrent tasks should race each other + /// + protected bool? ShouldCompete { get; set; } + + /// + public virtual ITaskExecutionStrategyDefinitionBuilder Sequentially(Action setup) + { + var builder = new TaskDefinitionMappingBuilder(); + setup(builder); + this.SequentialTasks = builder.Build(); + this.ConcurrentTasks = null; + return this; + } + + /// + public virtual ITaskExecutionStrategyDefinitionBuilder Concurrently(Action setup) + { + var builder = new TaskDefinitionMappingBuilder(); + setup(builder); + this.ConcurrentTasks = builder.Build(); + this.SequentialTasks = null; + return this; + } + + /// + public virtual ITaskExecutionStrategyDefinitionBuilder Compete() + { + if (this.ConcurrentTasks?.Count < 1) throw new Exception("Racing is only possible when executing tasks concurrently"); + this.ShouldCompete = true; + return this; + } + + /// + public virtual TaskExecutionStrategyDefinition Build() + { + if (this.SequentialTasks?.Count < 2 && this.ConcurrentTasks?.Count < 2) throw new NullReferenceException("The execution strategy must define at least two subtasks"); + return new() + { + Sequentially = this.SequentialTasks, + Concurrently = this.ConcurrentTasks, + Compete = this.ShouldCompete + }; + } + +} diff --git a/src/ServerlessWorkflow.Sdk.Builders/TryTaskDefinitionBuilder.cs b/src/ServerlessWorkflow.Sdk.Builders/TryTaskDefinitionBuilder.cs new file mode 100644 index 0000000..5aec6fb --- /dev/null +++ b/src/ServerlessWorkflow.Sdk.Builders/TryTaskDefinitionBuilder.cs @@ -0,0 +1,64 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Builders; + +/// +/// Represents the default implementation of the interface +/// +public class TryTaskDefinitionBuilder + : TaskDefinitionBuilder, ITryTaskDefinitionBuilder +{ + + /// + /// Gets/sets the task to try + /// + protected TaskDefinition? TryTask { get; set; } + + /// + /// Gets/sets the definition of the error catcher to use + /// + protected ErrorCatcherDefinition? ErrorCatcher { get; set; } + + /// + public virtual ITryTaskDefinitionBuilder Do(Action setup) + { + ArgumentNullException.ThrowIfNull(setup); + var builder = new GenericTaskDefinitionBuilder(); + setup(builder); + this.TryTask = builder.Build(); + return this; + } + + /// + public virtual ITryTaskDefinitionBuilder Catch(Action setup) + { + ArgumentNullException.ThrowIfNull(setup); + var builder = new ErrorCatcherDefinitionBuilder(); + this.ErrorCatcher = builder.Build(); + return this; + } + + /// + public override TryTaskDefinition Build() + { + if (this.TryTask == null) throw new NullReferenceException("The task to try must be set"); + if (this.ErrorCatcher == null) throw new NullReferenceException("The catch clause must be set"); + return new() + { + Try = this.TryTask, + Catch = this.ErrorCatcher + }; + } + +} diff --git a/src/ServerlessWorkflow.Sdk.Builders/Usings.cs b/src/ServerlessWorkflow.Sdk.Builders/Usings.cs new file mode 100644 index 0000000..03361af --- /dev/null +++ b/src/ServerlessWorkflow.Sdk.Builders/Usings.cs @@ -0,0 +1,16 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +global using ServerlessWorkflow.Sdk.Models; +global using ServerlessWorkflow.Sdk.Models.Authentication; +global using ServerlessWorkflow.Sdk.Models.Tasks; \ No newline at end of file diff --git a/src/ServerlessWorkflow.Sdk.Builders/WaitTaskDefinitionBuilder.cs b/src/ServerlessWorkflow.Sdk.Builders/WaitTaskDefinitionBuilder.cs new file mode 100644 index 0000000..046be19 --- /dev/null +++ b/src/ServerlessWorkflow.Sdk.Builders/WaitTaskDefinitionBuilder.cs @@ -0,0 +1,47 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Builders; + +/// +/// Represents the default implementation of the interface +/// +/// The amount of time to wait for +public class WaitTaskDefinitionBuilder(Duration? duration = null) + : TaskDefinitionBuilder, IWaitTaskDefinitionBuilder +{ + + /// + /// Gets/sets the amount of time to wait for + /// + protected Duration? Duration { get; set; } = duration; + + /// + public virtual IWaitTaskDefinitionBuilder For(Duration duration) + { + ArgumentNullException.ThrowIfNull(duration); + this.Duration = duration; + return this; + } + + /// + public override WaitTaskDefinition Build() + { + if (this.Duration == null) throw new NullReferenceException("The amount of time to wait for must be set"); + return new() + { + Wait = this.Duration + }; + } + +} \ No newline at end of file diff --git a/src/ServerlessWorkflow.Sdk.Builders/WorkflowDefinitionBuilder.cs b/src/ServerlessWorkflow.Sdk.Builders/WorkflowDefinitionBuilder.cs new file mode 100644 index 0000000..2826985 --- /dev/null +++ b/src/ServerlessWorkflow.Sdk.Builders/WorkflowDefinitionBuilder.cs @@ -0,0 +1,275 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +using Neuroglia; +using Semver; +using YamlDotNet.Serialization; + +namespace ServerlessWorkflow.Sdk.Builders; + +/// +/// Represents the default implementation of the interface +/// +public class WorkflowDefinitionBuilder + : IWorkflowDefinitionBuilder +{ + + /// + /// Gets/sets the workflow's namespace + /// + protected string? Namespace { get; set; } + + /// + /// Gets/sets the workflow's name + /// + protected string? Name { get; set; } + + /// + /// Gets the workflow's semantic version + /// + protected string? Version { get; set; } + + /// + /// Gets/sets the workflow's title + /// + protected string? Title { get; set; } + + /// + /// Gets/sets the workflow's Markdown summary + /// + protected string? Summary { get; set; } + + /// + /// Gets/sets the workflow's tags + /// + protected EquatableDictionary? Tags { get; set; } + + /// + /// Gets/sets a name/value mapping of the workflow's reusable components + /// + protected ComponentDefinitionCollection? Components { get; set; } + + /// + /// Gets/sets a name/value mapping of the tasks the workflow is made out of + /// + protected EquatableDictionary? Tasks { get; set; } + + /// + public virtual IWorkflowDefinitionBuilder WithNamespace(string @namespace) + { + ArgumentException.ThrowIfNullOrWhiteSpace(@namespace); + if (!NamingConvention.IsValidName(@namespace)) throw new ArgumentException($"The the specified value '{@namespace}' is not a valid RFC1123 DNS label name", nameof(@namespace)); + this.Namespace = @namespace; + return this; + } + + /// + public virtual IWorkflowDefinitionBuilder WithName(string name) + { + ArgumentException.ThrowIfNullOrWhiteSpace(name); + if (!NamingConvention.IsValidName(name)) throw new ArgumentException($"The the specified value '{name}' is not a valid RFC1123 DNS label name", nameof(name)); + this.Name = name; + return this; + } + + /// + public virtual IWorkflowDefinitionBuilder WithVersion(string version) + { + ArgumentException.ThrowIfNullOrWhiteSpace(version); + if (!SemVersion.TryParse(version, SemVersionStyles.Strict, out _)) throw new ArgumentException($"The specified value '{version}' is not a valid semantic version (SemVer 2.0)", nameof(version)); + this.Version = version; + return this; + } + + /// + public virtual IWorkflowDefinitionBuilder WithTitle(string title) + { + this.Title = title; + return this; + } + + /// + public virtual IWorkflowDefinitionBuilder WithSummary(string description) + { + this.Summary = description; + return this; + } + + /// + public virtual IWorkflowDefinitionBuilder WithTag(string name, string value) + { + ArgumentException.ThrowIfNullOrWhiteSpace(name); + this.Tags ??= []; + this.Tags[name] = value; + return this; + } + + /// + public virtual IWorkflowDefinitionBuilder WithTag(IDictionary arguments) + { + ArgumentNullException.ThrowIfNull(arguments); + this.Tags = new(arguments); + return this; + } + + /// + public virtual IWorkflowDefinitionBuilder UseAuthentication(string name, AuthenticationPolicyDefinition authentication) + { + ArgumentException.ThrowIfNullOrWhiteSpace(name); + ArgumentNullException.ThrowIfNull(authentication); + this.Components ??= new(); + this.Components.Authentications ??= []; + this.Components.Authentications[name] = authentication; + return this; + } + + /// + public virtual IWorkflowDefinitionBuilder UseAuthentication(string name, Action setup) + { + var builder = new AuthenticationPolicyDefinitionBuilder(); + setup(builder); + return this.UseAuthentication(name, builder.Build()); + } + + /// + public virtual IWorkflowDefinitionBuilder UseExtension(string name, ExtensionDefinition extension) + { + ArgumentException.ThrowIfNullOrWhiteSpace(name); + ArgumentNullException.ThrowIfNull(extension); + this.Components ??= new(); + this.Components.Extensions ??= []; + this.Components.Extensions[name] = extension; + return this; + } + + /// + public virtual IWorkflowDefinitionBuilder UseExtension(string name, Action setup) + { + var builder = new ExtensionDefinitionBuilder(); + setup(builder); + return this.UseExtension(name, builder.Build()); + } + + /// + public virtual IWorkflowDefinitionBuilder UseFunction(string name, CallTaskDefinition call) + { + ArgumentException.ThrowIfNullOrWhiteSpace(name); + ArgumentNullException.ThrowIfNull(call); + this.Components ??= new(); + this.Components.Functions ??= []; + this.Components.Functions[name] = call; + return this; + } + + /// + public virtual IWorkflowDefinitionBuilder UseFunction(string name, Action setup) + { + var builder = new CallTaskDefinitionBuilder(); + setup(builder); + return this.UseFunction(name, builder.Build()); + } + + /// + public virtual IWorkflowDefinitionBuilder UseFunction(string name, RunTaskDefinition run) + { + ArgumentException.ThrowIfNullOrWhiteSpace(name); + ArgumentNullException.ThrowIfNull(run); + this.Components ??= new(); + this.Components.Functions ??= []; + this.Components.Functions[name] = run; + return this; + } + + /// + public virtual IWorkflowDefinitionBuilder UseFunction(string name, Action setup) + { + var builder = new RunTaskDefinitionBuilder(); + setup(builder); + return this.UseFunction(name, builder.Build()); + } + + /// + public virtual IWorkflowDefinitionBuilder UseRetry(string name, RetryPolicyDefinition retry) + { + ArgumentException.ThrowIfNullOrWhiteSpace(name); + ArgumentNullException.ThrowIfNull(retry); + this.Components ??= new(); + this.Components.Retries ??= []; + this.Components.Retries[name] = retry; + return this; + } + + /// + public virtual IWorkflowDefinitionBuilder UseRetry(string name, Action setup) + { + var builder = new RetryPolicyDefinitionBuilder(); + setup(builder); + return this.UseRetry(name, builder.Build()); + } + + /// + public virtual IWorkflowDefinitionBuilder UseSecret(string secret) + { + ArgumentException.ThrowIfNullOrWhiteSpace(secret); + this.Components ??= new(); + this.Components.Secrets ??= []; + this.Components.Secrets.Add(secret); + return this; + } + + /// + public virtual IWorkflowDefinitionBuilder UseSecrets(params string[] secrets) + { + ArgumentNullException.ThrowIfNull(secrets); + this.Components ??= new(); + this.Components.Secrets = new(secrets); + return this; + } + + /// + public virtual IWorkflowDefinitionBuilder Do(string name, Action setup) + { + ArgumentException.ThrowIfNullOrWhiteSpace(name); + ArgumentNullException.ThrowIfNull(setup); + var builder = new GenericTaskDefinitionBuilder(); + setup(builder); + this.Tasks ??= []; + this.Tasks[name] = builder.Build(); + return this; + } + + /// + public virtual WorkflowDefinition Build() + { + if (string.IsNullOrWhiteSpace(this.Name)) throw new NullReferenceException("The workflow name must be set"); + if (this.Tasks == null || this.Tasks.Count < 1) throw new NullReferenceException("The workflow must define at least one task"); + return new() + { + Document = new() + { + Dsl = DslVersion.V010, + Namespace = string.IsNullOrWhiteSpace(this.Namespace) ? WorkflowDefinitionMetadata.DefaultNamespace : this.Namespace, + Name = this.Name, + Version = string.IsNullOrWhiteSpace(this.Version) ? "latest" : this.Version, + Title = this.Title, + Summary = this.Summary, + Tags = this.Tags + }, + Use = this.Components, + Do = this.Tasks + }; + } + + EquatableDictionary ITaskDefinitionMappingBuilder.Build() => this.Tasks!; + +} diff --git a/src/ServerlessWorkflow.Sdk.Builders/WorkflowProcessDefinitionBuilder.cs b/src/ServerlessWorkflow.Sdk.Builders/WorkflowProcessDefinitionBuilder.cs new file mode 100644 index 0000000..e546c48 --- /dev/null +++ b/src/ServerlessWorkflow.Sdk.Builders/WorkflowProcessDefinitionBuilder.cs @@ -0,0 +1,94 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +using ServerlessWorkflow.Sdk.Models.Processes; +using Semver; + +namespace ServerlessWorkflow.Sdk.Builders; + +/// +/// Represents the default implementation of the interface +/// +public class WorkflowProcessDefinitionBuilder + : ProcessDefinitionBuilder, IWorkflowProcessDefinitionBuilder +{ + + /// + /// Gets/sets the namespace of the workflow to run + /// + protected virtual string? Namespace { get; set; } + + /// + /// Gets/sets the name of the workflow to run + /// + protected virtual string? Name { get; set; } + + /// + /// Gets/sets the version of the workflow to run. Defaults to `latest` + /// + protected virtual string Version { get; set; } = "latest"; + + /// + /// Gets/sets the data, if any, to pass as input to the workflow to execute. The value should be validated against the target workflow's input schema, if specified + /// + protected virtual object? Input { get; set; } + + /// + public virtual IWorkflowProcessDefinitionBuilder WithNamespace(string @namespace) + { + ArgumentException.ThrowIfNullOrWhiteSpace(@namespace); + if (!NamingConvention.IsValidName(@namespace)) throw new ArgumentException($"The the specified value '{@namespace}' is not a valid RFC1123 DNS label name", nameof(@namespace)); + this.Namespace = @namespace; + return this; + } + + /// + public virtual IWorkflowProcessDefinitionBuilder WithName(string name) + { + ArgumentException.ThrowIfNullOrWhiteSpace(name); + if (!NamingConvention.IsValidName(name)) throw new ArgumentException($"The the specified value '{name}' is not a valid RFC1123 DNS label name", nameof(name)); + this.Name = name; + return this; + } + + /// + public virtual IWorkflowProcessDefinitionBuilder WithVersion(string version) + { + ArgumentException.ThrowIfNullOrWhiteSpace(version); + if (!SemVersion.TryParse(version, SemVersionStyles.Strict, out _)) throw new ArgumentException($"The specified value '{version}' is not a valid semantic version (SemVer 2.0)", nameof(version)); + this.Version = version; + return this; + } + + /// + public virtual IWorkflowProcessDefinitionBuilder WithInput(object input) + { + this.Input = input; + return this; + } + + /// + public override WorkflowProcessDefinition Build() + { + if (string.IsNullOrWhiteSpace(this.Name)) throw new NullReferenceException("The name of the workflow to run must be set"); + if (string.IsNullOrWhiteSpace(this.Version)) throw new NullReferenceException("The version of the workflow to run must be set"); + return new() + { + Namespace = string.IsNullOrWhiteSpace(this.Namespace) ? WorkflowDefinitionMetadata.DefaultNamespace : this.Namespace, + Name = this.Name, + Version = this.Version, + Input = this.Input + }; + } + +} diff --git a/src/ServerlessWorkflow.Sdk.IO/Extensions/IServiceCollectionExtensions.cs b/src/ServerlessWorkflow.Sdk.IO/Extensions/IServiceCollectionExtensions.cs new file mode 100644 index 0000000..1a9c5c1 --- /dev/null +++ b/src/ServerlessWorkflow.Sdk.IO/Extensions/IServiceCollectionExtensions.cs @@ -0,0 +1,49 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +using ServerlessWorkflow.Sdk.Serialization.Yaml; +using Microsoft.Extensions.DependencyInjection; +using Neuroglia.Serialization; +using Neuroglia.Serialization.Yaml; + +namespace ServerlessWorkflow.Sdk.IO; + +/// +/// Defines extensions for s +/// +public static class IServiceCollectionExtensions +{ + + /// + /// Adds and configures ServerlessWorkflow IO services + /// + /// The to configure + /// The configured + public static IServiceCollection AddServerlessWorkflowIO(this IServiceCollection services) + { + services.AddJsonSerializer(); + services.AddYamlDotNetSerializer(options => + { + YamlSerializer.DefaultSerializerConfiguration(options.Serializer); + YamlSerializer.DefaultDeserializerConfiguration(options.Deserializer); + options.Deserializer.WithNodeDeserializer( + inner => new TaskDefinitionYamlDeserializer(inner), + syntax => syntax.InsteadOf()); + }); + services.AddSingleton(); + services.AddSingleton(); + services.AddSingleton(); + return services; + } + +} diff --git a/src/ServerlessWorkflow.Sdk/Services/IO/Interfaces/IWorkflowReader.cs b/src/ServerlessWorkflow.Sdk.IO/Interfaces/IWorkflowDefinitionReader.cs similarity index 73% rename from src/ServerlessWorkflow.Sdk/Services/IO/Interfaces/IWorkflowReader.cs rename to src/ServerlessWorkflow.Sdk.IO/Interfaces/IWorkflowDefinitionReader.cs index 58ed2fc..3fa0eba 100644 --- a/src/ServerlessWorkflow.Sdk/Services/IO/Interfaces/IWorkflowReader.cs +++ b/src/ServerlessWorkflow.Sdk.IO/Interfaces/IWorkflowDefinitionReader.cs @@ -1,4 +1,4 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors +// Copyright © 2024-Present The Serverless Workflow Specification Authors // // Licensed under the Apache License, Version 2.0 (the "License"), // you may not use this file except in compliance with the License. @@ -11,21 +11,21 @@ // See the License for the specific language governing permissions and // limitations under the License. -namespace ServerlessWorkflow.Sdk.Services.IO; +namespace ServerlessWorkflow.Sdk.IO; /// /// Defines the fundamentals of a service used to read s /// -public interface IWorkflowReader +public interface IWorkflowDefinitionReader { /// /// Reads a from the specified /// /// The to read the from - /// The to use + /// The to use /// A /// A new - Task ReadAsync(Stream stream, WorkflowReaderOptions? options = null, CancellationToken cancellationToken = default); + Task ReadAsync(Stream stream, WorkflowDefinitionReaderOptions? options = null, CancellationToken cancellationToken = default); } diff --git a/src/ServerlessWorkflow.Sdk/Services/IO/Interfaces/IWorkflowWriter.cs b/src/ServerlessWorkflow.Sdk.IO/Interfaces/IWorkflowDefinitionWriter.cs similarity index 72% rename from src/ServerlessWorkflow.Sdk/Services/IO/Interfaces/IWorkflowWriter.cs rename to src/ServerlessWorkflow.Sdk.IO/Interfaces/IWorkflowDefinitionWriter.cs index 82c7e7d..dc0f63a 100644 --- a/src/ServerlessWorkflow.Sdk/Services/IO/Interfaces/IWorkflowWriter.cs +++ b/src/ServerlessWorkflow.Sdk.IO/Interfaces/IWorkflowDefinitionWriter.cs @@ -1,4 +1,4 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors +// Copyright © 2024-Present The Serverless Workflow Specification Authors // // Licensed under the Apache License, Version 2.0 (the "License"), // you may not use this file except in compliance with the License. @@ -11,12 +11,12 @@ // See the License for the specific language governing permissions and // limitations under the License. -namespace ServerlessWorkflow.Sdk.Services.IO; +namespace ServerlessWorkflow.Sdk.IO; /// /// Defines the fundamentals of a service used to write s /// -public interface IWorkflowWriter +public interface IWorkflowDefinitionWriter { /// @@ -25,7 +25,8 @@ public interface IWorkflowWriter /// The to write /// The to read the from /// The format of the to read. Defaults to '' - /// A new - void Write(WorkflowDefinition workflow, Stream stream, string format = WorkflowDefinitionFormat.Yaml); + /// A + /// A new awaitable + Task WriteAsync(WorkflowDefinition workflow, Stream stream, string format = WorkflowDefinitionFormat.Yaml, CancellationToken cancellationToken = default); } diff --git a/src/ServerlessWorkflow.Sdk/RelativeUriReferenceResolutionMode.cs b/src/ServerlessWorkflow.Sdk.IO/RelativeUriReferenceResolutionMode.cs similarity index 71% rename from src/ServerlessWorkflow.Sdk/RelativeUriReferenceResolutionMode.cs rename to src/ServerlessWorkflow.Sdk.IO/RelativeUriReferenceResolutionMode.cs index 796c964..b5ed458 100644 --- a/src/ServerlessWorkflow.Sdk/RelativeUriReferenceResolutionMode.cs +++ b/src/ServerlessWorkflow.Sdk.IO/RelativeUriReferenceResolutionMode.cs @@ -1,4 +1,4 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors +// Copyright © 2024-Present The Serverless Workflow Specification Authors // // Licensed under the Apache License, Version 2.0 (the "License"), // you may not use this file except in compliance with the License. @@ -11,7 +11,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -namespace ServerlessWorkflow.Sdk; +namespace ServerlessWorkflow.Sdk.IO; /// /// Enumerates all types of reference resolution modes for relative s @@ -20,18 +20,18 @@ public static class RelativeUriReferenceResolutionMode { /// - /// Indicates that relative uris should be converted to an absolute one by combining them to a specified base uri + /// Indicates that relative uri instances should be converted to an absolute one by combining them to a specified base uri /// public const string ConvertToAbsolute = "convertToAbsolute"; /// - /// Indicates that relative uris should be converted to a file path relative to a specified base directory + /// Indicates that relative uri instances should be converted to a file path relative to a specified base directory /// public const string ConvertToRelativeFilePath = "convertToRelativeFilePath"; /// - /// Indicates that relative uris should not be resolved + /// Indicates that relative uri instances should not be resolved /// public const string None = "none"; -} +} \ No newline at end of file diff --git a/src/ServerlessWorkflow.Sdk.IO/ServerlessWorkflow.Sdk.IO.csproj b/src/ServerlessWorkflow.Sdk.IO/ServerlessWorkflow.Sdk.IO.csproj new file mode 100644 index 0000000..7be45e5 --- /dev/null +++ b/src/ServerlessWorkflow.Sdk.IO/ServerlessWorkflow.Sdk.IO.csproj @@ -0,0 +1,43 @@ + + + + net8.0 + enable + enable + $(VersionPrefix)-alpha1 + 1.0.0 + $(VersionPrefix) + $(VersionPrefix) + en + true + True + true + Serverless Workflow SDK - IO + Contains services used to read and write ServerlessWorkflow workflow definitions + serverless-workflow;serverless;workflow;dsl;sdk;io + true + Apache-2.0 + readme.md + Copyright © 2024-Present The Serverless Workflow Authors. All rights reserved. + https://github.com/serverlessworkflow/sdk-net + https://github.com/serverlessworkflow/sdk-net + git + embedded + + + + + \ + True + + + + + + + + + + + + diff --git a/src/ServerlessWorkflow.Sdk.IO/Usings.cs b/src/ServerlessWorkflow.Sdk.IO/Usings.cs new file mode 100644 index 0000000..34fbf4b --- /dev/null +++ b/src/ServerlessWorkflow.Sdk.IO/Usings.cs @@ -0,0 +1,14 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +global using ServerlessWorkflow.Sdk.Models; \ No newline at end of file diff --git a/src/ServerlessWorkflow.Sdk/WorkflowDefinitionFormat.cs b/src/ServerlessWorkflow.Sdk.IO/WorkflowDefinitionFormat.cs similarity index 77% rename from src/ServerlessWorkflow.Sdk/WorkflowDefinitionFormat.cs rename to src/ServerlessWorkflow.Sdk.IO/WorkflowDefinitionFormat.cs index 0a3e7ea..fa25064 100644 --- a/src/ServerlessWorkflow.Sdk/WorkflowDefinitionFormat.cs +++ b/src/ServerlessWorkflow.Sdk.IO/WorkflowDefinitionFormat.cs @@ -1,4 +1,4 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors +// Copyright © 2024-Present The Serverless Workflow Specification Authors // // Licensed under the Apache License, Version 2.0 (the "License"), // you may not use this file except in compliance with the License. @@ -11,22 +11,22 @@ // See the License for the specific language governing permissions and // limitations under the License. -namespace ServerlessWorkflow.Sdk; +namespace ServerlessWorkflow.Sdk.IO; /// -/// Enumerates all workflow definition formats +/// Exposes default workflow definition formats /// public static class WorkflowDefinitionFormat { /// - /// Indicates YAML + /// The YAML workflow definition format /// public const string Yaml = "yaml"; /// - /// Indicates JSON + /// The JSON workflow definition format /// public const string Json = "json"; -} +} \ No newline at end of file diff --git a/src/ServerlessWorkflow.Sdk.IO/WorkflowDefinitionReader.cs b/src/ServerlessWorkflow.Sdk.IO/WorkflowDefinitionReader.cs new file mode 100644 index 0000000..6ae2691 --- /dev/null +++ b/src/ServerlessWorkflow.Sdk.IO/WorkflowDefinitionReader.cs @@ -0,0 +1,65 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +using ServerlessWorkflow.Sdk.Serialization.Yaml; +using Microsoft.Extensions.DependencyInjection; +using Neuroglia.Serialization; +using Neuroglia.Serialization.Yaml; + +namespace ServerlessWorkflow.Sdk.IO; + +/// +/// Represents the default implementation of the interface +/// +/// The service used to serialize/deserialize objects to/from JSON +/// The service used to serialize/deserialize objects to/from JSON +public class WorkflowDefinitionReader(IJsonSerializer jsonSerializer, IYamlSerializer yamlSerializer) + : IWorkflowDefinitionReader +{ + + /// + /// Gets the service used to serialize/deserialize objects to/from JSON + /// + protected IJsonSerializer JsonSerializer { get; } = jsonSerializer; + + /// + /// Gets the service used to serialize/deserialize objects to/from YAML + /// + protected IYamlSerializer YamlSerializer { get; } = yamlSerializer; + + /// + public virtual Task ReadAsync(Stream stream, WorkflowDefinitionReaderOptions? options = null, CancellationToken cancellationToken = default) + { + ArgumentNullException.ThrowIfNull(stream); + options ??= new WorkflowDefinitionReaderOptions(); + using var reader = new StreamReader(stream); + var input = reader.ReadToEnd(); + var workflow = (input.TrimStart().StartsWith('{') && input.TrimEnd().EndsWith('}') + ? this.JsonSerializer.Deserialize(input) + : this.YamlSerializer.Deserialize(input)) + ?? throw new NullReferenceException(); + return Task.FromResult(workflow); + } + + /// + /// Creates a new + /// + /// A new + public static IWorkflowDefinitionReader Create() + { + var services = new ServiceCollection(); + services.AddServerlessWorkflowIO(); + return services.BuildServiceProvider().GetRequiredService(); + } + +} \ No newline at end of file diff --git a/src/ServerlessWorkflow.Sdk.IO/WorkflowDefinitionReaderOptions.cs b/src/ServerlessWorkflow.Sdk.IO/WorkflowDefinitionReaderOptions.cs new file mode 100644 index 0000000..e0379d8 --- /dev/null +++ b/src/ServerlessWorkflow.Sdk.IO/WorkflowDefinitionReaderOptions.cs @@ -0,0 +1,42 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.IO; + +/// +/// Represents the options used to configure an +/// +public class WorkflowDefinitionReaderOptions +{ + + /// + /// Gets/sets the base to use to combine to relative s when the property is set to + /// + public virtual Uri? BaseUri { get; set; } + + /// + /// Gets/sets the base directory to use when resolving relative when the property is set to . Defaults to + /// + public virtual string BaseDirectory { get; set; } = AppContext.BaseDirectory; + + /// + /// Gets/sets the to use. Defaults to + /// + public virtual string RelativeUriResolutionMode { get; set; } = RelativeUriReferenceResolutionMode.ConvertToRelativeFilePath; + + /// + /// Gets/sets a boolean indicating whether or not to load external definitions + /// + public virtual bool LoadExternalDefinitions { get; set; } + +} diff --git a/src/ServerlessWorkflow.Sdk.IO/WorkflowDefinitionWriter.cs b/src/ServerlessWorkflow.Sdk.IO/WorkflowDefinitionWriter.cs new file mode 100644 index 0000000..310cd8c --- /dev/null +++ b/src/ServerlessWorkflow.Sdk.IO/WorkflowDefinitionWriter.cs @@ -0,0 +1,65 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +using Microsoft.Extensions.DependencyInjection; +using Neuroglia.Serialization; + +namespace ServerlessWorkflow.Sdk.IO; + +/// +/// Represents the default implementation of the interface +/// +/// /// The service used to serialize/deserialize objects to/from JSON +/// The service used to serialize/deserialize objects to/from JSON +public class WorkflowDefinitionWriter(IJsonSerializer jsonSerializer, IYamlSerializer yamlSerializer) + : IWorkflowDefinitionWriter +{ + + /// + /// Gets the service used to serialize/deserialize objects to/from JSON + /// + protected IJsonSerializer JsonSerializer { get; } = jsonSerializer; + + /// + /// Gets the service used to serialize/deserialize objects to/from YAML + /// + protected IYamlSerializer YamlSerializer { get; } = yamlSerializer; + + /// + public virtual async Task WriteAsync(WorkflowDefinition workflow, Stream stream, string format = WorkflowDefinitionFormat.Yaml, CancellationToken cancellationToken = default) + { + if (workflow == null) throw new ArgumentNullException(nameof(workflow)); + if (stream == null) throw new ArgumentNullException(nameof(stream)); + var input = format switch + { + WorkflowDefinitionFormat.Json => this.JsonSerializer.SerializeToText(workflow), + WorkflowDefinitionFormat.Yaml => this.YamlSerializer.SerializeToText(workflow), + _ => throw new NotSupportedException($"The specified workflow definition format '{format}' is not supported"), + }; + using var streamWriter = new StreamWriter(stream, leaveOpen: true); + await streamWriter.WriteAsync(input).ConfigureAwait(false); + await streamWriter.FlushAsync(cancellationToken).ConfigureAwait(false); + } + + /// + /// Creates a new default instance of the interface + /// + /// A new + public static IWorkflowDefinitionWriter Create() + { + var services = new ServiceCollection(); + services.AddServerlessWorkflowIO(); + return services.BuildServiceProvider().GetRequiredService(); + } + +} \ No newline at end of file diff --git a/src/ServerlessWorkflow.Sdk/EventKind.cs b/src/ServerlessWorkflow.Sdk/Attributes/SemanticVersionAttribute.cs similarity index 54% rename from src/ServerlessWorkflow.Sdk/EventKind.cs rename to src/ServerlessWorkflow.Sdk/Attributes/SemanticVersionAttribute.cs index 36dcbaa..03458c9 100644 --- a/src/ServerlessWorkflow.Sdk/EventKind.cs +++ b/src/ServerlessWorkflow.Sdk/Attributes/SemanticVersionAttribute.cs @@ -1,4 +1,4 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors +// Copyright © 2024-Present The Serverless Workflow Specification Authors // // Licensed under the Apache License, Version 2.0 (the "License"), // you may not use this file except in compliance with the License. @@ -14,19 +14,13 @@ namespace ServerlessWorkflow.Sdk; /// -/// Enumerates all kinds of workflow events +/// Represents a used to validate semantic versions /// -public static class EventKind +[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter, AllowMultiple = false)] +public class SemanticVersionAttribute() + : RegularExpressionAttribute(@"^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$") { - /// - /// Indicates an event to consume - /// - public const string Consumed = "consumed"; - /// - /// Indicates an event to produce - /// - public const string Produced = "produced"; } diff --git a/src/ServerlessWorkflow.Sdk/AuthenticationScheme.cs b/src/ServerlessWorkflow.Sdk/AuthenticationScheme.cs index 229d316..77da321 100644 --- a/src/ServerlessWorkflow.Sdk/AuthenticationScheme.cs +++ b/src/ServerlessWorkflow.Sdk/AuthenticationScheme.cs @@ -1,4 +1,4 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors +// Copyright © 2024-Present The Serverless Workflow Specification Authors // // Licensed under the Apache License, Version 2.0 (the "License"), // you may not use this file except in compliance with the License. @@ -14,22 +14,33 @@ namespace ServerlessWorkflow.Sdk; /// -/// Enumerates all supported authentication schemes +/// Exposes all default authentication schemes /// public static class AuthenticationScheme { /// - /// Gets the 'basic' authentication scheme + /// Gets the 'Basic' authentication scheme /// - public const string Basic = "basic"; + public const string Basic = "Basic"; /// - /// Gets the 'bearer' authentication scheme + /// Gets the 'Bearer' authentication scheme /// - public const string Bearer = "bearer"; + public const string Bearer = "Bearer"; /// - /// Gets the 'oauth2' authentication scheme + /// Gets the 'OAuth2' authentication scheme /// - public const string OAuth2 = "oauth2"; + public const string OAuth2 = "OAuth2"; + + /// + /// Gets a new containing the authentication schemes supported by default + /// + /// A new containing the authentication schemes supported by default + public static IEnumerable AsEnumerable() + { + yield return Basic; + yield return Bearer; + yield return OAuth2; + } } diff --git a/src/ServerlessWorkflow.Sdk/Cron.cs b/src/ServerlessWorkflow.Sdk/Cron.cs deleted file mode 100644 index 4ecf422..0000000 --- a/src/ServerlessWorkflow.Sdk/Cron.cs +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -using Cronos; - -namespace ServerlessWorkflow.Sdk; - -/// -/// Defines helper methods to handle CRON expressions -/// -public static class Cron -{ - - /// - /// Parses the specified input into a new - /// - /// The input to parse - /// A new - public static CronExpression Parse(string input) => CronExpression.Parse(input); - - /// - /// Parses the specified input into a new - /// - /// The input to parse - /// The parsed , if any - /// A boolean indicating whether or not the specified input could be parsed - public static bool TryParse(string input, out CronExpression? cron) - { - cron = default; - try - { - cron = Parse(input); - return true; - } - catch - { - return false; - } - } - -} \ No newline at end of file diff --git a/src/ServerlessWorkflow.Sdk/RuntimeExpressionLanguage.cs b/src/ServerlessWorkflow.Sdk/DslVersion.cs similarity index 73% rename from src/ServerlessWorkflow.Sdk/RuntimeExpressionLanguage.cs rename to src/ServerlessWorkflow.Sdk/DslVersion.cs index e5c96e0..40e4688 100644 --- a/src/ServerlessWorkflow.Sdk/RuntimeExpressionLanguage.cs +++ b/src/ServerlessWorkflow.Sdk/DslVersion.cs @@ -1,4 +1,4 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors +// Copyright © 2024-Present The Serverless Workflow Specification Authors // // Licensed under the Apache License, Version 2.0 (the "License"), // you may not use this file except in compliance with the License. @@ -14,14 +14,14 @@ namespace ServerlessWorkflow.Sdk; /// -/// Enumerates all well-known runtime expression languages +/// Exposes supported Serverless Workflow DSL versions /// -public static class RuntimeExpressionLanguage +public static class DslVersion { /// - /// Gets the JQ expression language + /// Gets the Serverless Workflow DSL version '0.10' /// - public const string JQ = "jq"; + public const string V010 = "0.10"; } \ No newline at end of file diff --git a/src/ServerlessWorkflow.Sdk/ErrorStatus.cs b/src/ServerlessWorkflow.Sdk/ErrorStatus.cs new file mode 100644 index 0000000..39f5a26 --- /dev/null +++ b/src/ServerlessWorkflow.Sdk/ErrorStatus.cs @@ -0,0 +1,55 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk; + +/// +/// Exposes all default ServerlessWorkflow error statuses +/// +public static class ErrorStatus +{ + + /// + /// Gets the default status for all configuration errors + /// + public const int Configuration = 400; + /// + /// Gets the default status for all validation errors + /// + public const int Validation = 400; + /// + /// Gets the default status for all runtime expression errors + /// + public const int RuntimeExpression = 400; + /// + /// Gets the default status for all authentication errors + /// + public const int Authentication = 401; + /// + /// Gets the default status for all authorization errors + /// + public const int Authorization = 403; + /// + /// Gets the default status for all timeout errors + /// + public const int Timeout = 408; + /// + /// Gets the default status for all communication errors + /// + public const int Communication = 500; + /// + /// Gets the default status for all runtime errors + /// + public const int Runtime = 500; + +} \ No newline at end of file diff --git a/src/ServerlessWorkflow.Sdk/ErrorTitle.cs b/src/ServerlessWorkflow.Sdk/ErrorTitle.cs new file mode 100644 index 0000000..99a9cf1 --- /dev/null +++ b/src/ServerlessWorkflow.Sdk/ErrorTitle.cs @@ -0,0 +1,43 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk; + +/// +/// Exposes the titles of all default ServerlessWorkflow errors +/// +public static class ErrorTitle +{ + + /// + /// Gets the title of communication errors + /// + public const string Communication = "Communication Error"; + /// + /// Gets the title of configuration errors + /// + public const string Configuration = "Configuration Error"; + /// + /// Gets the title of runtime errors + /// + public const string Runtime = "Runtime Error"; + /// + /// Gets the title of timeout errors + /// + public const string Timeout = "Timeout Error"; + /// + /// Gets the title of validation errors + /// + public const string Validation = "Validation Error"; + +} diff --git a/src/ServerlessWorkflow.Sdk/ErrorType.cs b/src/ServerlessWorkflow.Sdk/ErrorType.cs new file mode 100644 index 0000000..213174c --- /dev/null +++ b/src/ServerlessWorkflow.Sdk/ErrorType.cs @@ -0,0 +1,44 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk; + +/// +/// Exposes ServerlessWorkflow default error types +/// +public static class ErrorType +{ + + const string BaseUri = "https://serverlessworkflow.io/dsl/errors/types"; + /// + /// Gets the default type for communication errors + /// + public static readonly Uri Communication = new($"{BaseUri}/communication"); + /// + /// Gets the default type for configuration errors + /// + public static readonly Uri Configuration = new($"{BaseUri}/configuration"); + /// + /// Gets the default type for runtime errors + /// + public static readonly Uri Runtime = new($"{BaseUri}/runtime"); + /// + /// Gets the default type for timeout errors + /// + public static readonly Uri Timeout = new($"{BaseUri}/timeout"); + /// + /// Gets the default type for validation errors + /// + public static readonly Uri Validation = new($"{BaseUri}/validation"); + +} diff --git a/src/ServerlessWorkflow.Sdk/Extensions/DurationExtensions.cs b/src/ServerlessWorkflow.Sdk/Extensions/DurationExtensions.cs index 99a3158..c90a145 100644 --- a/src/ServerlessWorkflow.Sdk/Extensions/DurationExtensions.cs +++ b/src/ServerlessWorkflow.Sdk/Extensions/DurationExtensions.cs @@ -1,4 +1,4 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors +// Copyright © 2024-Present The Serverless Workflow Specification Authors // // Licensed under the Apache License, Version 2.0 (the "License"), // you may not use this file except in compliance with the License. @@ -11,22 +11,21 @@ // See the License for the specific language governing permissions and // limitations under the License. +using ServerlessWorkflow.Sdk.Models; + namespace ServerlessWorkflow.Sdk; /// -/// Defines extensions for Iso8601DurationHelper.Durations +/// Defines extensions for s /// public static class DurationExtensions { /// - /// Converts the into a + /// Converts the into a new /// - /// The to convert - /// The converted - public static TimeSpan ToTimeSpan(this Iso8601DurationHelper.Duration duration) - { - return new TimeSpan((int)(duration.Days + duration.Weeks * 7 + duration.Months * 30 + duration.Years * 365), (int)duration.Hours, (int)duration.Minutes, (int)duration.Seconds); - } + /// The to convert + /// A new + public static TimeSpan ToTimeSpan(this Duration duration) => new(duration.Days.HasValue ? (int)duration.Days : 0, duration.Hours.HasValue ? (int)duration.Hours : 0, duration.Minutes.HasValue ? (int)duration.Minutes : 0, duration.Seconds.HasValue ? (int)duration.Seconds : 0, duration.Milliseconds.HasValue ? (int)duration.Milliseconds : 0); -} +} \ No newline at end of file diff --git a/src/ServerlessWorkflow.Sdk/Extensions/EvaluationResultsExtensions.cs b/src/ServerlessWorkflow.Sdk/Extensions/EvaluationResultsExtensions.cs deleted file mode 100644 index 7ef3b0c..0000000 --- a/src/ServerlessWorkflow.Sdk/Extensions/EvaluationResultsExtensions.cs +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace ServerlessWorkflow.Sdk; - -/// -/// Defines extensions for -/// -public static class EvaluationResultsExtensions -{ - - /// - /// Gets the errors that have occured during evaluation - /// - /// The extended - /// A new containing key/value mapping of the errors that have occured during evaluation - public static IEnumerable> GetErrors(this EvaluationResults results) - { - return results.Details.Where(d => !d.IsValid && d.Errors?.Any() == true).Select(e => new KeyValuePair(e.EvaluationPath.ToString(), string.Join(Environment.NewLine, e.Errors!.Select(kvp => kvp.Value)))); - } - -} diff --git a/src/ServerlessWorkflow.Sdk/Extensions/ExceptionExtensions.cs b/src/ServerlessWorkflow.Sdk/Extensions/ExceptionExtensions.cs new file mode 100644 index 0000000..ce03035 --- /dev/null +++ b/src/ServerlessWorkflow.Sdk/Extensions/ExceptionExtensions.cs @@ -0,0 +1,53 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +using System.Net; + +namespace ServerlessWorkflow.Sdk; + +/// +/// Defines extensions for s +/// +public static class ExceptionExtensions +{ + + /// + /// Converts the into a new + /// + /// The to convert + /// The , if any, that references the instance to which the to create applies + /// A new based on the specified + public static Error ToError(this Exception ex, Uri? instance = null) + { + return ex switch + { + HttpRequestException httpEx => new() + { + Status = (ushort)(httpEx.StatusCode ?? HttpStatusCode.InternalServerError), + Type = ErrorType.Communication, + Title = ErrorTitle.Communication, + Instance = instance, + Detail = httpEx.Message + }, + _ => new() + { + Status = ErrorStatus.Runtime, + Type = ErrorType.Runtime, + Title = ErrorTitle.Runtime, + Instance = instance, + Detail = ex.Message + } + }; + } + +} \ No newline at end of file diff --git a/src/ServerlessWorkflow.Sdk/Extensions/IServiceCollectionExtensions.cs b/src/ServerlessWorkflow.Sdk/Extensions/IServiceCollectionExtensions.cs deleted file mode 100644 index 728b296..0000000 --- a/src/ServerlessWorkflow.Sdk/Extensions/IServiceCollectionExtensions.cs +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -using FluentValidation; -using Microsoft.Extensions.DependencyInjection; -using ServerlessWorkflow.Sdk.Services.FluentBuilders; -using ServerlessWorkflow.Sdk.Services.IO; -using ServerlessWorkflow.Sdk.Services.Validation; - -namespace ServerlessWorkflow.Sdk; - -/// -/// Defines extensions for s -/// -public static class IServiceCollectionExtensions -{ - - /// - /// Adds and configures Serverless Workflow services (s, , , ...) - /// - /// The to configure - /// The configured - public static IServiceCollection AddServerlessWorkflow(this IServiceCollection services) - { - services.AddHttpClient(); - services.AddSingleton(); - services.AddSingleton(); - services.AddSingleton(); - services.AddSingleton(); - services.AddSingleton(); - services.AddTransient(); - services.AddValidatorsFromAssemblyContaining(ServiceLifetime.Singleton); - return services; - } - -} diff --git a/src/ServerlessWorkflow.Sdk/Extensions/IWorkflowReaderExtensions.cs b/src/ServerlessWorkflow.Sdk/Extensions/IWorkflowReaderExtensions.cs deleted file mode 100644 index 9dd13b2..0000000 --- a/src/ServerlessWorkflow.Sdk/Extensions/IWorkflowReaderExtensions.cs +++ /dev/null @@ -1,73 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -using ServerlessWorkflow.Sdk.Models; -using ServerlessWorkflow.Sdk.Services.IO; -using System; -using System.IO; -using System.Text; -using System.Threading; -using System.Threading.Tasks; - -namespace ServerlessWorkflow.Sdk -{ - - /// - /// Defines extensions for s - /// - public static class IWorkflowReaderExtensions - { - - /// - /// Reads a from the specified - /// - /// The extended - /// The to read the from - /// A - /// A new - public static async Task ReadAsync(this IWorkflowReader reader, Stream stream, CancellationToken cancellationToken = default) - { - return await reader.ReadAsync(stream, new(), cancellationToken); - } - - /// - /// Parses the specified input into a new - /// - /// The extended - /// The input to parse - /// to use - /// A - /// A new - public static async Task ParseAsync(this IWorkflowReader reader, string input, WorkflowReaderOptions options, CancellationToken cancellationToken = default) - { - if (string.IsNullOrWhiteSpace(input)) - throw new ArgumentNullException(nameof(input)); - using Stream stream = new MemoryStream(Encoding.UTF8.GetBytes(input)); - return await reader.ReadAsync(stream, options, cancellationToken); - } - - /// - /// Parses the specified input into a new - /// - /// The extended - /// The input to parse - /// A - /// A new - public static async Task ParseAsync(this IWorkflowReader reader, string input,CancellationToken cancellationToken = default) - { - return await reader.ParseAsync(input, new(), cancellationToken); - } - - } - -} diff --git a/src/ServerlessWorkflow.Sdk/Extensions/JsonNodeExtensions.cs b/src/ServerlessWorkflow.Sdk/Extensions/JsonNodeExtensions.cs deleted file mode 100644 index f226e08..0000000 --- a/src/ServerlessWorkflow.Sdk/Extensions/JsonNodeExtensions.cs +++ /dev/null @@ -1,89 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -using System.Dynamic; - -namespace ServerlessWorkflow.Sdk; - -/// -/// Defines extensions for s -/// -public static class JsonNodeExtensions -{ - - /// - /// Unwraps and deserializes and the - /// - /// The to unwrap - /// The unwrapped - public static object? ToObject(this JsonNode jsonNode) - { - return jsonNode switch - { - JsonArray array => array.ToObject(), - JsonObject obj => obj.ToObject(), - JsonValue value => value.ToObject(), - _ => throw new NotSupportedException($"The specified JsonNode type '{jsonNode.GetType()}' is not supported") - }; - } - - /// - /// Unwraps and deserializes and the - /// - /// The to unwrap - /// The unwrapped - public static IEnumerable? ToObject(this JsonArray jsonArray) - { - foreach (var jsonNode in jsonArray) - { - if (jsonNode == null) yield return null!; - else yield return jsonNode!.ToObject()!; - } - } - - /// - /// Unwraps and deserializes and the - /// - /// The to unwrap - /// The unwrapped - public static object? ToObject(this JsonObject jsonObject) - { - var expandoObject = new ExpandoObject(); - foreach (var property in jsonObject) - { - ((IDictionary)expandoObject!).Add(property.Key, property.Value?.ToObject()!); - } - return expandoObject; - } - - /// - /// Unwraps and deserializes and the - /// - /// The to unwrap - /// The unwrapped - public static object? ToObject(this JsonValue jsonValue) - { - var jsonElement = jsonValue.Deserialize(); - var json = jsonElement.ToString(); - return jsonElement.ValueKind switch - { - JsonValueKind.Undefined or JsonValueKind.Null => null, - JsonValueKind.String => jsonElement.Deserialize(), - JsonValueKind.True => true, - JsonValueKind.False => false, - JsonValueKind.Number => json.Contains('.') || json.Contains(',') ? jsonElement.Deserialize() : jsonElement.Deserialize(), - _ => throw new NotSupportedException($"The specified {nameof(JsonValueKind)} '{jsonElement.ValueKind}' is not supported") - }; - } - -} \ No newline at end of file diff --git a/src/ServerlessWorkflow.Sdk/Extensions/JsonSchemaExtensions.cs b/src/ServerlessWorkflow.Sdk/Extensions/JsonSchemaExtensions.cs deleted file mode 100644 index 64a2d5c..0000000 --- a/src/ServerlessWorkflow.Sdk/Extensions/JsonSchemaExtensions.cs +++ /dev/null @@ -1,72 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -using System.Reflection; - -namespace ServerlessWorkflow.Sdk; - -public static class JsonSchemaExtensions -{ - - static readonly MethodInfo JsonSchemaInitializeMethod = typeof(JsonSchema).GetMethods(BindingFlags.Default | BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Static).Single(m => m.Name == "Initialize"); - static readonly MethodInfo JsonSchemaGetSubschemasMethod = typeof(JsonSchema).GetMethods(BindingFlags.Default | BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Static).Single(m => m.Name == "GetSubschemas"); - - public static JsonSchema Bundle(this JsonSchema jsonSchema) - { - var options = EvaluationOptions.From(EvaluationOptions.Default); - JsonSchemaInitializeMethod.Invoke(null, new object[] { jsonSchema, options.SchemaRegistry, null! }); - var schemasToSearch = new List(); - var externalSchemas = new Dictionary(); - var bundledReferences = new List(); - var referencesToCheck = new List { jsonSchema.BaseUri }; - - while (referencesToCheck.Count != 0) - { - var nextReference = referencesToCheck[0]; - referencesToCheck.RemoveAt(0); - var resolved = options.SchemaRegistry.Get(nextReference) ?? throw new JsonSchemaException($"Cannot resolve reference: '{nextReference}'"); - if (resolved is not JsonSchema resolvedSchema) throw new NotSupportedException("Bundling is not supported for non-schema root documents"); - JsonSchemaInitializeMethod.Invoke(null, new object[] { resolvedSchema, options.SchemaRegistry, null! }); - var schemaId = new FileInfo(resolvedSchema.GetId()!.AbsolutePath).Name.Split('.').First(); - if (!bundledReferences.Contains(nextReference) && !externalSchemas.ContainsKey(schemaId)) externalSchemas.Add(schemaId, resolvedSchema); - schemasToSearch.Add(resolvedSchema); - while (schemasToSearch.Count != 0) - { - var schema = schemasToSearch[0]; - schemasToSearch.RemoveAt(0); - - if (schema.Keywords == null) continue; - - schemasToSearch.AddRange(schema.Keywords.SelectMany(k => (IEnumerable)JsonSchemaGetSubschemasMethod.Invoke(null, new object[] { k })!)); - - if (schema.BaseUri != nextReference && !bundledReferences.Contains(schema.BaseUri)) - bundledReferences.Add(schema.BaseUri); - - var reference = schema.GetRef(); - if (reference != null) - { - var newUri = new Uri(schema.BaseUri, reference); - if (newUri == schema.BaseUri) continue; // same document - - referencesToCheck.Add(newUri); - } - } - } - - return new JsonSchemaBuilder() - .Id(jsonSchema.BaseUri.OriginalString + "(bundled)") - .Defs(externalSchemas) - .Ref(jsonSchema.BaseUri); - } - -} \ No newline at end of file diff --git a/src/ServerlessWorkflow.Sdk/Extensions/StringExtensions.cs b/src/ServerlessWorkflow.Sdk/Extensions/StringExtensions.cs deleted file mode 100644 index b562167..0000000 --- a/src/ServerlessWorkflow.Sdk/Extensions/StringExtensions.cs +++ /dev/null @@ -1,60 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace ServerlessWorkflow.Sdk; - -/// -/// Defines extensions for s -/// -public static class StringExtensions -{ - - /// - /// Converts the string to camel case - /// - /// The string to convert - /// The camel-cased string - public static string ToCamelCase(this string input) => YamlDotNet.Serialization.NamingConventions.CamelCaseNamingConvention.Instance.Apply(input); - - /// - /// Converts the string to hyphen case - /// - /// The string to convert - /// The hyphen-cased string - public static string ToHyphenCase(this string input) => YamlDotNet.Serialization.NamingConventions.HyphenatedNamingConvention.Instance.Apply(input); - - /// - /// Converts the string to snake case - /// - /// The string to convert - /// The snake-cased string - public static string ToSnakeCase(this string input) => YamlDotNet.Serialization.NamingConventions.UnderscoredNamingConvention.Instance.Apply(input); - - /// - /// Determines whether or not the specified input is JSON format - /// - /// The input to check - /// A boolean indicating whether or not the specified text is JSON format - public static bool IsJson(this string text) - { - if (string.IsNullOrWhiteSpace(text)) throw new ArgumentNullException(nameof(text)); - var text2 = text.Trim(); - if (!text2.StartsWith("[") || !text2.EndsWith("]")) - { - if (text2.StartsWith("{")) return text2.EndsWith("}"); - else return false; - } - return true; - } - -} diff --git a/src/ServerlessWorkflow.Sdk/Extensions/TypeExtensions.cs b/src/ServerlessWorkflow.Sdk/Extensions/TypeExtensions.cs deleted file mode 100644 index 34372df..0000000 --- a/src/ServerlessWorkflow.Sdk/Extensions/TypeExtensions.cs +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace ServerlessWorkflow.Sdk; - -/// -/// Defines extensions for s -/// -public static class TypeExtensions -{ - - /// - /// Gets the type's generic type of the specified generic type definition - /// - /// The extended type - /// The generic type definition to get the generic type of - /// The type's generic type of the specified generic type definition - public static Type? GetGenericType(this Type extended, Type genericTypeDefinition) - { - Type? baseType, result; - if (genericTypeDefinition == null)throw new ArgumentNullException(nameof(genericTypeDefinition)); - if (!genericTypeDefinition.IsGenericTypeDefinition)throw new ArgumentException("The specified type is not a generic type definition", nameof(genericTypeDefinition)); - baseType = extended; - while (baseType != null) - { - if (baseType.IsGenericType&& baseType.GetGenericTypeDefinition() == genericTypeDefinition)return baseType; - result = baseType.GetInterfaces().Select(i => i.GetGenericType(genericTypeDefinition)).Where(t => t != null).FirstOrDefault(); - if (result != null)return result; - baseType = baseType.BaseType; - } - return null; - } - -} diff --git a/src/ServerlessWorkflow.Sdk/Extensions/WorkflowDefinitionExtensions.cs b/src/ServerlessWorkflow.Sdk/Extensions/WorkflowDefinitionExtensions.cs index 77062b0..5571423 100644 --- a/src/ServerlessWorkflow.Sdk/Extensions/WorkflowDefinitionExtensions.cs +++ b/src/ServerlessWorkflow.Sdk/Extensions/WorkflowDefinitionExtensions.cs @@ -1,4 +1,4 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors +// Copyright © 2024-Present The Serverless Workflow Specification Authors // // Licensed under the Apache License, Version 2.0 (the "License"), // you may not use this file except in compliance with the License. @@ -11,6 +11,11 @@ // See the License for the specific language governing permissions and // limitations under the License. +using ServerlessWorkflow.Sdk.Models; +using Json.Pointer; +using Neuroglia; +using Neuroglia.Serialization.Json; + namespace ServerlessWorkflow.Sdk; /// @@ -20,45 +25,59 @@ public static class WorkflowDefinitionExtensions { /// - /// Gets all the s of the specified type declared in the + /// Builds a reference to the specified /// - /// The to query - /// The type of s to get. A null value gets all s - /// A new containing the s of the specified type declared in the - public static IEnumerable GetActions(this WorkflowDefinition workflow, string? type = null) + /// The extended + /// The to reference + /// The name or path to the task to reference + /// A reference to the 's parent, if any + /// A new used to reference the + public static Uri BuildReferenceTo(this WorkflowDefinition workflow, TaskDefinition task, string path, Uri? parentReference = null) { - var actions = workflow.States.SelectMany(s => s switch - { - CallbackStateDefinition callbackState => new ActionDefinition[] { callbackState.Action! }, - EventStateDefinition eventState => eventState.OnEvents.SelectMany(t => t.Actions), - ForEachStateDefinition foreachState => foreachState.Actions, - OperationStateDefinition operationState => operationState.Actions, - ParallelStateDefinition parallelState => parallelState.Branches.SelectMany(b => b.Actions), - _ => Array.Empty() - }); - if (!string.IsNullOrWhiteSpace(type)) actions = actions.Where(a => a.Type == type); - return actions; + ArgumentNullException.ThrowIfNull(workflow); + ArgumentNullException.ThrowIfNull(task); + ArgumentException.ThrowIfNullOrWhiteSpace(path); + return parentReference == null + ? new Uri($"/{nameof(WorkflowDefinition.Do).ToCamelCase()}/{path}", UriKind.Relative) + : new Uri($"{parentReference.OriginalString}/{path}", UriKind.Relative); } /// - /// Gets all the s declared in the + /// Builds a reference to the specified /// - /// The to query - /// A new containing the s declared in the - public static IEnumerable GetFunctionReferences(this WorkflowDefinition workflow) => workflow.GetActions(ActionType.Function).Select(a => a.Function)!; + /// The extended + /// The to reference + /// A reference to the 's parent, if any + /// A new used to reference the + public static Uri BuildReferenceTo(this WorkflowDefinition workflow, KeyValuePair task, Uri? parentReference = null) => workflow.BuildReferenceTo(task.Value, task.Key, parentReference); /// - /// Gets all the s declared in the + /// Gets the 's component at the specified path /// - /// The to query - /// A new containing the s declared in the - public static IEnumerable GetEventReferences(this WorkflowDefinition workflow) => workflow.GetActions(ActionType.Event).Select(a => a.Event)!; + /// The type of component to get + /// The extended + /// The path to the component to get + /// The component at the specified path + public static TComponent GetComponent(this WorkflowDefinition workflow, string path) + { + ArgumentException.ThrowIfNullOrWhiteSpace(path); + var jsonNode = JsonSerializer.Default.SerializeToNode(workflow)!; + var jsonPointer = JsonPointer.Parse(path); + if (!jsonPointer.TryEvaluate(jsonNode, out var matchNode) || matchNode == null) throw new NullReferenceException($"Failed to find a component definition of type '{typeof(TComponent).Name}' at '{path}'"); + return JsonSerializer.Default.Deserialize(matchNode)!; + } /// - /// Gets all the s declared in the + /// Gets the specified /// - /// The to query - /// A new containing the s declared in the - public static IEnumerable GetSubflowReferences(this WorkflowDefinition workflow) => workflow.GetActions(ActionType.Subflow).Select(a => a.Subflow)!; + /// The that defines the to get + /// The name of/the reference to the policy to get + /// The specified + public static AuthenticationPolicyDefinition GetAuthenticationPolicy(this WorkflowDefinition workflow, string nameOrReference) + { + ArgumentException.ThrowIfNullOrWhiteSpace(nameOrReference); + if (nameOrReference.StartsWith('/') && Uri.TryCreate(nameOrReference, UriKind.Relative, out var uri) && uri != null) return workflow.GetComponent(nameOrReference); + else return workflow.Use?.Authentications?.FirstOrDefault(a => string.Equals(a.Key, nameOrReference, StringComparison.OrdinalIgnoreCase)).Value ?? throw new NullReferenceException($"Failed to find an authentication policy definition with the specified name '{nameOrReference}'"); + } } diff --git a/src/ServerlessWorkflow.Sdk/SubflowParentCompletionBehavior.cs b/src/ServerlessWorkflow.Sdk/FlowDirective.cs similarity index 51% rename from src/ServerlessWorkflow.Sdk/SubflowParentCompletionBehavior.cs rename to src/ServerlessWorkflow.Sdk/FlowDirective.cs index ec1bd36..3ea4eb7 100644 --- a/src/ServerlessWorkflow.Sdk/SubflowParentCompletionBehavior.cs +++ b/src/ServerlessWorkflow.Sdk/FlowDirective.cs @@ -1,4 +1,4 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors +// Copyright © 2024-Present The Serverless Workflow Specification Authors // // Licensed under the Apache License, Version 2.0 (the "License"), // you may not use this file except in compliance with the License. @@ -14,18 +14,22 @@ namespace ServerlessWorkflow.Sdk; /// -/// Enumerates the ways a subflow should behave when its parent completes before it +/// Exposes constants representing different transition options for a workflow /// -public static class SubflowParentCompletionBehavior +public static class FlowDirective { /// - /// Indicates that the subflow is terminated upon completion of its parent + /// Indicates that the workflow should continue its execution, possibly exiting the current branch and/or completing execution if transitionning from the last task /// - public const string Terminate = "terminate"; + public const string Continue = "continue"; /// - /// Indicates that the subflow should continue to run even if its parent has completed + /// Indicates that the workflow should end its execution, possibly ignoring other defined tasks in the flow /// - public const string Continue = "continue"; + public const string End = "end"; + /// + /// Indicates that the workflow should exit the current branch, iteration or loop, possibly completing execution if transitionning from the main branch + /// + public const string Exit = "exit"; } diff --git a/src/ServerlessWorkflow.Sdk/FunctionType.cs b/src/ServerlessWorkflow.Sdk/Function.cs similarity index 51% rename from src/ServerlessWorkflow.Sdk/FunctionType.cs rename to src/ServerlessWorkflow.Sdk/Function.cs index 3cb5d41..bd5f2b2 100644 --- a/src/ServerlessWorkflow.Sdk/FunctionType.cs +++ b/src/ServerlessWorkflow.Sdk/Function.cs @@ -1,4 +1,4 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors +// Copyright © 2024-Present The Serverless Workflow Specification Authors // // Licensed under the Apache License, Version 2.0 (the "License"), // you may not use this file except in compliance with the License. @@ -14,53 +14,38 @@ namespace ServerlessWorkflow.Sdk; /// -/// Enumerates all types of functions +/// Exposes ServerlessWorkflow default functions /// -public static class FunctionType +public static class Function { /// - /// Indicates an Async API function + /// The function used to perform an AsyncAPI call /// public const string AsyncApi = "asyncapi"; - /// - /// Indicates an expression function + /// The function used to perform a GRPC call /// - public const string Expression = "expression"; - - /// - /// Indicates a GraphQL function - /// - public const string GraphQL = "graphql"; - + public const string Grpc = "grpc"; /// - /// Indicates an OData function + /// The function used to perform an HTTP call /// - public const string OData = "odata"; - - /// - /// Indicates a REST function - /// - public const string Rest = "rest"; - + public const string Http = "http"; /// - /// Indicates an Remote Procedure Call (RPC) + /// The function used to perform an OpenAPI call /// - public const string Rpc = "rpc"; + public const string OpenApi = "openapi"; /// - /// Gets all supported values + /// Enumerates all default functions /// - /// A new containing all supported values - public static IEnumerable GetValues() + /// A new containing all default functions + public static IEnumerable AsEnumerable() { - yield return Rest; - yield return Rpc; - yield return GraphQL; - yield return OData; - yield return Expression; yield return AsyncApi; + yield return Grpc; + yield return Http; + yield return OpenApi; } } diff --git a/src/ServerlessWorkflow.Sdk/ActionType.cs b/src/ServerlessWorkflow.Sdk/HttpOutputFormat.cs similarity index 56% rename from src/ServerlessWorkflow.Sdk/ActionType.cs rename to src/ServerlessWorkflow.Sdk/HttpOutputFormat.cs index 0d9b776..2dfb271 100644 --- a/src/ServerlessWorkflow.Sdk/ActionType.cs +++ b/src/ServerlessWorkflow.Sdk/HttpOutputFormat.cs @@ -1,4 +1,4 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors +// Copyright © 2024-Present The Serverless Workflow Specification Authors // // Licensed under the Apache License, Version 2.0 (the "License"), // you may not use this file except in compliance with the License. @@ -11,27 +11,27 @@ // See the License for the specific language governing permissions and // limitations under the License. +using ServerlessWorkflow.Sdk.Models; + namespace ServerlessWorkflow.Sdk; /// -/// Enumerates all types of actions +/// Exposes all supported HTTP call output formats /// -public static class ActionType +public static class HttpOutputFormat { /// - /// Indicates an action that invokes a function + /// Indicates that the HTTP call should output the HTTP response's raw content /// - public const string Function = "function"; - + public const string Raw = "raw"; /// - /// Indicates an action that executes a cloud event trigger + /// Indicates that the HTTP call should output the HTTP response's content, possibly deserialized /// - public const string Event = "event"; - + public const string Content = "content"; /// - /// Indicates an action that executes a subflow + /// Indicates that the HTTP call should output an /// - public const string Subflow = "subflow"; + public const string Response = "response"; -} +} \ No newline at end of file diff --git a/src/ServerlessWorkflow.Sdk/IOneOf.cs b/src/ServerlessWorkflow.Sdk/IExtendable.cs similarity index 68% rename from src/ServerlessWorkflow.Sdk/IOneOf.cs rename to src/ServerlessWorkflow.Sdk/IExtendable.cs index 9c0d9bb..0fe4338 100644 --- a/src/ServerlessWorkflow.Sdk/IOneOf.cs +++ b/src/ServerlessWorkflow.Sdk/IExtendable.cs @@ -1,4 +1,4 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors +// Copyright © 2024-Present The Serverless Workflow Specification Authors // // Licensed under the Apache License, Version 2.0 (the "License"), // you may not use this file except in compliance with the License. @@ -14,15 +14,14 @@ namespace ServerlessWorkflow.Sdk; /// -/// Defines the fundamentals of a service that wraps around multiple alternative value types +/// Defines the fundamentals of an object that can be extended /// -public interface IOneOf +public interface IExtendable { /// - /// Gets the object's current value + /// Gets/sets a name/definition mapping of the component's extensions, if any /// - /// The object's current value - object? GetValue(); + EquatableDictionary? Extensions { get; set; } } diff --git a/src/ServerlessWorkflow.Sdk/IMetadata.cs b/src/ServerlessWorkflow.Sdk/IReferenceable.cs similarity index 71% rename from src/ServerlessWorkflow.Sdk/IMetadata.cs rename to src/ServerlessWorkflow.Sdk/IReferenceable.cs index 511478a..0ae15fd 100644 --- a/src/ServerlessWorkflow.Sdk/IMetadata.cs +++ b/src/ServerlessWorkflow.Sdk/IReferenceable.cs @@ -1,4 +1,4 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors +// Copyright © 2024-Present The Serverless Workflow Specification Authors // // Licensed under the Apache License, Version 2.0 (the "License"), // you may not use this file except in compliance with the License. @@ -14,14 +14,14 @@ namespace ServerlessWorkflow.Sdk; /// -/// Defines the fundamentals of an object that exposes metadata +/// Defines the fundamentals of a referenceable object /// -public interface IMetadata +public interface IReferenceable { /// - /// Gets an that contains the object's metadata + /// Gets an URI, if any, that references the object's definition /// - DynamicMapping? Metadata { get; } + Uri? Ref { get; } } diff --git a/src/ServerlessWorkflow.Sdk/Iso8601TimeSpan.cs b/src/ServerlessWorkflow.Sdk/Iso8601TimeSpan.cs deleted file mode 100644 index 68938f7..0000000 --- a/src/ServerlessWorkflow.Sdk/Iso8601TimeSpan.cs +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -using System.Xml; - -namespace ServerlessWorkflow.Sdk; - -/// -/// Represents an helper class for handling ISO 8601 timespans -/// -public static class Iso8601TimeSpan -{ - - /// - /// Parses the specified input - /// - /// The input string to parse - /// The parsed - public static TimeSpan Parse(string input) => Iso8601DurationHelper.Duration.Parse(input).ToTimeSpan(); - - /// - /// Formats the specified System.TimeSpan - /// - /// The to format - /// The parsed - public static string Format(TimeSpan timeSpan) => XmlConvert.ToString(timeSpan); - -} \ No newline at end of file diff --git a/src/ServerlessWorkflow.Sdk/Models/ActionDataFilterDefinition.cs b/src/ServerlessWorkflow.Sdk/Models/ActionDataFilterDefinition.cs deleted file mode 100644 index f3d9e38..0000000 --- a/src/ServerlessWorkflow.Sdk/Models/ActionDataFilterDefinition.cs +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace ServerlessWorkflow.Sdk.Models; - -/// -/// Represents the object used to configure how actions filter the state data for both input and output -/// -[DataContract] -public class ActionDataFilterDefinition -{ - - /// - /// Gets/sets an expression that filters state data that can be used by the action - /// - [DataMember(Order = 1, Name = "fromStateData"), JsonPropertyOrder(1), JsonPropertyName("fromStateData"), YamlMember(Alias = "fromStateData", Order = 1)] - public virtual string? FromStateData { get; set; } - - /// - /// Gets/sets an expression that filters the actions data results - /// - [DataMember(Order = 2, Name = "results"), JsonPropertyOrder(2), JsonPropertyName("results"), YamlMember(Alias = "results", Order = 2)] - public virtual string? Results { get; set; } - - /// - /// Gets/sets an expression that selects a state data element to which the action results should be added/merged into. If not specified denotes the top-level state data element - /// - [DataMember(Order = 3, Name = "toStateData"), JsonPropertyOrder(3), JsonPropertyName("toStateData"), YamlMember(Alias = "toStateData", Order = 3)] - public virtual string? ToStateData { get; set; } - - /// - /// Gets/sets a boolean indicating whether or not to merge the action's data into state data. If set to false, action data results are not added/merged to state data. In this case 'results' and 'toStateData' should be ignored. Defaults to true. - /// - [DataMember(Order = 4, Name = "useResults"), JsonPropertyOrder(4), JsonPropertyName("useResults"), YamlMember(Alias = "useResults", Order = 4)] - [DefaultValue(true)] - public virtual bool UseResults { get; set; } = true; - -} \ No newline at end of file diff --git a/src/ServerlessWorkflow.Sdk/Models/ActionDefinition.cs b/src/ServerlessWorkflow.Sdk/Models/ActionDefinition.cs deleted file mode 100644 index 04107ae..0000000 --- a/src/ServerlessWorkflow.Sdk/Models/ActionDefinition.cs +++ /dev/null @@ -1,175 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace ServerlessWorkflow.Sdk.Models; - -/// -/// Represents the object used to define a workflow action -/// -[DataContract] -public class ActionDefinition - : IExtensible -{ - - /// - /// Gets/sets the unique action definition name - /// - [DataMember(Order = 1, Name = "name"), JsonPropertyOrder(1), JsonPropertyName("name"), YamlMember(Alias = "name", Order = 1)] - public virtual string? Name { get; set; } - - /// - /// Gets the 's type - /// - [IgnoreDataMember, JsonIgnore, YamlIgnore] - public virtual string Type - { - get - { - if (this.Function != null) - return ActionType.Function; - else if (this.Event != null) - return ActionType.Event; - else if (this.Subflow != null) - return ActionType.Subflow; - else - return string.Empty; - } - } - - /// - /// Gets/sets a that represents the function to invoke - /// - [DataMember(Order = 2, Name = "functionRef"), JsonPropertyOrder(2), JsonPropertyName("functionRef"), YamlMember(Alias = "functionRef", Order = 2)] - [JsonConverter(typeof(OneOfConverter))] - protected virtual OneOf? FunctionValue { get; set; } - - /// - /// Gets the object used to configure the reference of the function to invoke - /// - [IgnoreDataMember, JsonIgnore, YamlIgnore] - public virtual FunctionReference? Function - { - get - { - if (this.FunctionValue?.T1Value == null - && !string.IsNullOrWhiteSpace(this.FunctionValue?.T2Value)) - return new FunctionReference() { RefName = this.FunctionValue.T2Value }; - else - return this.FunctionValue?.T1Value; - } - set - { - if (value == null) - this.FunctionValue = null; - else - this.FunctionValue = value; - } - } - - /// - /// Gets the object used to configure the reference of the event to produce or consume - /// - [DataMember(Order = 3, Name = "eventRef"), JsonPropertyOrder(3), JsonPropertyName("eventRef"), YamlMember(Alias = "eventRef", Order = 3)] - public virtual EventReference? Event { get; set; } - - /// - /// Gets/sets a that references a subflow to run - /// - [DataMember(Order = 4, Name = "subFlowRef"), JsonPropertyOrder(4), JsonPropertyName("subFlowRef"), YamlMember(Alias = "subFlowRef", Order = 4)] - [JsonConverter(typeof(OneOfConverter))] - protected virtual OneOf? SubflowValue { get; set; } - - /// - /// Gets the object used to configure the reference of the subflow to run - /// - [IgnoreDataMember, JsonIgnore, YamlIgnore] - public virtual SubflowReference? Subflow - { - get - { - if (this.SubflowValue?.T1Value == null - && !string.IsNullOrWhiteSpace(this.SubflowValue?.T2Value)) - { - var components = this.SubflowValue.T2Value.Split(':', StringSplitOptions.RemoveEmptyEntries); - var id = components.First(); - var version = null as string; - if (components.Length > 1) - { - version = components.Last(); - id = this.SubflowValue.T2Value[..^(version.Length + 1)]; - } - return new() { WorkflowId = id, Version = version }; - } - return this.SubflowValue?.T1Value; - } - set - { - if (value == null) - this.SubflowValue = null; - else - this.SubflowValue = value; - } - } - - /// - /// Gets/sets the name of the workflow retry definition to use. If not defined uses the default runtime retry definition - /// - [DataMember(Order = 5, Name = "retryRef"), JsonPropertyOrder(5), JsonPropertyName("retryRef"), YamlMember(Alias = "retryRef", Order = 5)] - public virtual string? RetryRef { get; set; } - - /// - /// Gets/sets alist containing references to defined s for which the action should not be retried. Used only when `` is set to `true` - /// - [DataMember(Order = 6, Name = "nonRetryableErrors"), JsonPropertyOrder(6), JsonPropertyName("nonRetryableErrors"), YamlMember(Alias = "nonRetryableErrors", Order = 6)] - public virtual List? NonRetryableErrors { get; set; } - - /// - /// Gets/sets alist containing references to defined s for which the action should be retried. Used only when `` is set to `false` - /// - [DataMember(Order = 7, Name = "retryableErrors"), JsonPropertyOrder(7), JsonPropertyName("retryableErrors"), YamlMember(Alias = "retryableErrors", Order = 7)] - public virtual List? RetryableErrors { get; set; } - - /// - /// Gets/sets an object used to define the way to filter the action's data - /// - [DataMember(Order = 8, Name = "actionDataFilter"), JsonPropertyOrder(8), JsonPropertyName("actionDataFilter"), YamlMember(Alias = "actionDataFilter", Order = 8)] - public ActionDataFilterDefinition? ActionDataFilter { get; set; } - - /// - /// Gets/sets the 's execution delay configuration - /// - [DataMember(Order = 9, Name = "sleep"), JsonPropertyOrder(9), JsonPropertyName("sleep"), YamlMember(Alias = "sleep", Order = 9)] - public virtual ActionExecutionDelayDefinition? Sleep { get; set; } - - /// - /// Gets/sets an expression to be evaluated positively as a condition for the to execute. - /// - [DataMember(Order = 10, Name = "condition"), JsonPropertyOrder(10), JsonPropertyName("condition"), YamlMember(Alias = "condition", Order = 10)] - public virtual string? Condition { get; set; } - - /// - /// Gets/sets an containing the 's extension properties - /// - [DataMember(Order = 11, Name = "extensionData"), JsonExtensionData] - public virtual IDictionary? ExtensionData { get; set; } - - /// - public override string? ToString() - { - if (string.IsNullOrWhiteSpace(this.Name)) - return base.ToString(); - else - return this.Name; - } - -} diff --git a/src/ServerlessWorkflow.Sdk/Models/ActionExecutionDelayDefinition.cs b/src/ServerlessWorkflow.Sdk/Models/ActionExecutionDelayDefinition.cs deleted file mode 100644 index d030184..0000000 --- a/src/ServerlessWorkflow.Sdk/Models/ActionExecutionDelayDefinition.cs +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace ServerlessWorkflow.Sdk.Models; - -/// -/// Represents an object used to configure an 's execution delay -/// -[DataContract] -public class ActionExecutionDelayDefinition -{ - - /// - /// Gets/sets the amount of time to wait before executing the configured - /// - [DataMember(Order = 1, Name = "before"), JsonPropertyOrder(1), JsonPropertyName("before"), YamlMember(Alias = "before", Order = 1)] - public virtual TimeSpan? Before { get; set; } - - /// - /// Gets/sets the amount of time to wait after having executed the configured - /// - [DataMember(Order = 2, Name = "after"), JsonPropertyOrder(2), JsonPropertyName("after"), YamlMember(Alias = "after", Order = 2)] - public virtual TimeSpan? After { get; set; } - -} \ No newline at end of file diff --git a/src/ServerlessWorkflow.Sdk/Models/Authentication/BasicAuthenticationSchemeDefinition.cs b/src/ServerlessWorkflow.Sdk/Models/Authentication/BasicAuthenticationSchemeDefinition.cs new file mode 100644 index 0000000..f6cbccc --- /dev/null +++ b/src/ServerlessWorkflow.Sdk/Models/Authentication/BasicAuthenticationSchemeDefinition.cs @@ -0,0 +1,42 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Models.Authentication; + +/// +/// Represents the definition of a basic authentication scheme +/// +[DataContract] +public record BasicAuthenticationSchemeDefinition + : AuthenticationSchemeDefinition +{ + + /// + [IgnoreDataMember, JsonIgnore, YamlIgnore] + public override string Scheme => AuthenticationScheme.Basic; + + /// + /// Gets/sets the username used for authentication + /// + [Required, MinLength(1)] + [DataMember(Name = "username", Order = 1), JsonPropertyName("username"), JsonPropertyOrder(1), YamlMember(Alias = "username", Order = 1)] + public required virtual string Username { get; set; } + + /// + /// Gets/sets the password used for authentication + /// + [Required, MinLength(1)] + [DataMember(Name = "password", Order = 2), JsonPropertyName("password"), JsonPropertyOrder(2), YamlMember(Alias = "password", Order = 2)] + public required virtual string Password { get; set; } + +} diff --git a/src/ServerlessWorkflow.Sdk/Models/Authentication/BearerAuthenticationSchemeDefinition.cs b/src/ServerlessWorkflow.Sdk/Models/Authentication/BearerAuthenticationSchemeDefinition.cs new file mode 100644 index 0000000..08f6747 --- /dev/null +++ b/src/ServerlessWorkflow.Sdk/Models/Authentication/BearerAuthenticationSchemeDefinition.cs @@ -0,0 +1,34 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Models.Authentication; + +/// +/// Represents the definition of a bearer authentication scheme +/// +[DataContract] +public record BearerAuthenticationSchemeDefinition + : AuthenticationSchemeDefinition +{ + + /// + [IgnoreDataMember, JsonIgnore, YamlIgnore] + public override string Scheme => AuthenticationScheme.Bearer; + + /// + /// Gets/sets the bearer token used for authentication + /// + [DataMember(Name = "token", Order = 1), JsonPropertyName("token"), JsonPropertyOrder(1), YamlMember(Alias = "token", Order = 1)] + public required virtual string Token { get; set; } + +} diff --git a/src/ServerlessWorkflow.Sdk/Models/Authentication/OAuth2AuthenticationClientDefinition.cs b/src/ServerlessWorkflow.Sdk/Models/Authentication/OAuth2AuthenticationClientDefinition.cs new file mode 100644 index 0000000..273f063 --- /dev/null +++ b/src/ServerlessWorkflow.Sdk/Models/Authentication/OAuth2AuthenticationClientDefinition.cs @@ -0,0 +1,36 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Models.Authentication; + +/// +/// Represents the definition of an OAUTH2 client +/// +[DataContract] +public record OAuth2AuthenticationClientDefinition +{ + + /// + /// Gets/sets the OAUTH2 `client_id` to use + /// + [Required] + [DataMember(Name = "id", Order = 1), JsonPropertyName("id"), JsonPropertyOrder(1), YamlMember(Alias = "id", Order = 1)] + public required virtual string Id { get; set; } + + /// + /// Gets/sets the OAUTH2 `client_secret` to use, if any + /// + [DataMember(Name = "secret", Order = 2), JsonPropertyName("secret"), JsonPropertyOrder(2), YamlMember(Alias = "secret", Order = 2)] + public virtual string? Secret { get; set; } + +} diff --git a/src/ServerlessWorkflow.Sdk/Models/Authentication/OAuth2AuthenticationSchemeDefinition.cs b/src/ServerlessWorkflow.Sdk/Models/Authentication/OAuth2AuthenticationSchemeDefinition.cs new file mode 100644 index 0000000..be3ac59 --- /dev/null +++ b/src/ServerlessWorkflow.Sdk/Models/Authentication/OAuth2AuthenticationSchemeDefinition.cs @@ -0,0 +1,86 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Models.Authentication; + +/// +/// Represents the definition of an Open ID Connect authentication scheme +/// +[DataContract] +public record OAuth2AuthenticationSchemeDefinition + : AuthenticationSchemeDefinition +{ + + /// + [IgnoreDataMember, JsonIgnore, YamlIgnore] + public override string Scheme => AuthenticationScheme.OAuth2; + + /// + /// Gets/sets the uri that references the OAUTH2 authority to use + /// + [Required] + [DataMember(Name = "authority", Order = 1), JsonPropertyName("authority"), JsonPropertyOrder(1), YamlMember(Alias = "authority", Order = 1)] + public required virtual Uri Authority { get; set; } + + /// + /// Gets/sets the grant type to use + /// + [Required] + [DataMember(Name = "grant", Order = 2), JsonPropertyName("grant"), JsonPropertyOrder(2), YamlMember(Alias = "grant", Order = 2)] + public required virtual string Grant { get; set; } + + /// + /// Gets/sets the definition of the client to use + /// + [Required] + [DataMember(Name = "client", Order = 3), JsonPropertyName("client"), JsonPropertyOrder(3), YamlMember(Alias = "client", Order = 3)] + public required virtual OAuth2AuthenticationClientDefinition Client { get; set; } + + /// + /// Gets/sets the scopes, if any, to request the token for + /// + [DataMember(Name = "scopes", Order = 4), JsonPropertyName("scopes"), JsonPropertyOrder(4), YamlMember(Alias = "scopes", Order = 4)] + public virtual EquatableList? Scopes { get; set; } + + /// + /// Gets/sets the audiences, if any, to request the token for + /// + [DataMember(Name = "audiences", Order = 5), JsonPropertyName("audiences"), JsonPropertyOrder(5), YamlMember(Alias = "audiences", Order = 5)] + public virtual EquatableList? Audiences { get; set; } + + /// + /// Gets/sets the username to use. Used only if is + /// + [DataMember(Name = "username", Order = 6), JsonPropertyName("username"), JsonPropertyOrder(6), YamlMember(Alias = "username", Order = 6)] + public virtual string? Username { get; set; } + + /// + /// Gets/sets the password to use. Used only if is + /// + [DataMember(Name = "password", Order = 7), JsonPropertyName("password"), JsonPropertyOrder(7), YamlMember(Alias = "password", Order = 7)] + public virtual string? Password { get; set; } + + /// + /// Gets/sets the security token that represents the identity of the party on behalf of whom the request is being made. Used only if is , in which case it is required + /// + [DataMember(Name = "subject", Order = 8), JsonPropertyName("subject"), JsonPropertyOrder(8), YamlMember(Alias = "subject", Order = 8)] + public virtual OAuth2TokenDefinition? Subject { get; set; } + + /// + /// Gets/sets the security token that represents the identity of the acting party. Typically, this will be the party that is authorized to use the requested security token and act on behalf of the subject. + /// Used only if is , in which case it is required + /// + [DataMember(Name = "actor", Order = 9), JsonPropertyName("actor"), JsonPropertyOrder(9), YamlMember(Alias = "actor", Order = 9)] + public virtual OAuth2TokenDefinition? Actor { get; set; } + +} diff --git a/src/ServerlessWorkflow.Sdk/Models/Authentication/OAuth2TokenDefinition.cs b/src/ServerlessWorkflow.Sdk/Models/Authentication/OAuth2TokenDefinition.cs new file mode 100644 index 0000000..1c66841 --- /dev/null +++ b/src/ServerlessWorkflow.Sdk/Models/Authentication/OAuth2TokenDefinition.cs @@ -0,0 +1,35 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Models.Authentication; + +/// +/// Represents the definition of an OAUTH2 token +/// +[DataContract] +public record OAuth2TokenDefinition +{ + + /// + /// Gets/sets the security token to use + /// + [DataMember(Name = "token", Order = 1), JsonPropertyName("token"), JsonPropertyOrder(1), YamlMember(Alias = "token", Order = 1)] + public required virtual string Token { get; set; } + + /// + /// Gets/sets the type of security token to use + /// + [DataMember(Name = "type", Order = 2), JsonPropertyName("type"), JsonPropertyOrder(2), YamlMember(Alias = "type", Order = 2)] + public required virtual string Type { get; set; } + +} \ No newline at end of file diff --git a/src/ServerlessWorkflow.Sdk/Models/AuthenticationDefinition.cs b/src/ServerlessWorkflow.Sdk/Models/AuthenticationDefinition.cs deleted file mode 100644 index 53626f8..0000000 --- a/src/ServerlessWorkflow.Sdk/Models/AuthenticationDefinition.cs +++ /dev/null @@ -1,98 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -using Neuroglia; -using ServerlessWorkflow.Sdk.Serialization; - -namespace ServerlessWorkflow.Sdk.Models; - -/// -/// Represents a reusable definition of a workflow authentication mechanism -/// -[DataContract] -public class AuthenticationDefinition - : IExtensible -{ - - /// - /// Gets/sets the authentication definition's name - /// - [Required, MinLength(1)] - [DataMember(Order = 1, Name = "name", IsRequired = true), JsonPropertyOrder(1), JsonPropertyName("name"), YamlMember(Alias = "name", Order = 1)] - public virtual string Name { get; set; } = null!; - - /// - /// Gets/sets the authentication definition's scheme - /// - [Required, MinLength(1)] - [DataMember(Order = 2, Name = "scheme", IsRequired = true), JsonPropertyOrder(2), JsonPropertyName("scheme"), YamlMember(Alias = "scheme", Order = 2)] - public virtual string Scheme { get; set; } = null!; - - /// - /// Gets/sets a that represents the authentication definition's - /// - [Required, MinLength(1)] - [DataMember(Order = 3, Name = "properties", IsRequired = true), JsonPropertyOrder(3), JsonPropertyName("properties"), YamlMember(Alias = "properties", Order = 3)] - [JsonConverter(typeof(OneOfConverter))] - protected virtual OneOf PropertiesValue { get; set; } = null!; - - /// - /// Gets/sets the 's properties - /// - [IgnoreDataMember, JsonIgnore, YamlIgnore] - public virtual AuthenticationProperties Properties - { - get - { - if (!string.IsNullOrWhiteSpace(this.PropertiesValue.T1Value)) return new SecretBasedAuthenticationProperties(this.PropertiesValue.T1Value); - if (this.PropertiesValue?.T2Value == null) return null!; - return this.Scheme switch - { - AuthenticationScheme.Basic => new BasicAuthenticationProperties(this.PropertiesValue.T2Value), - AuthenticationScheme.Bearer => new BearerAuthenticationProperties(this.PropertiesValue.T2Value), - AuthenticationScheme.OAuth2 => new OAuth2AuthenticationProperties(this.PropertiesValue.T2Value), - _ => new ExtensionAuthenticationProperties(this.PropertiesValue.T2Value) - }; - } - set - { - if (value == null) throw new ArgumentNullException(nameof(value)); - switch (value) - { - case BasicAuthenticationProperties: - this.Scheme = AuthenticationScheme.Basic; - break; - case BearerAuthenticationProperties: - this.Scheme = AuthenticationScheme.Bearer; - break; - case OAuth2AuthenticationProperties: - this.Scheme = AuthenticationScheme.OAuth2; - break; - case SecretBasedAuthenticationProperties secretBasedProperties: - this.PropertiesValue = secretBasedProperties.Secret; - break; - default: - throw new NotSupportedException($"The specified authentication info type '{value.GetType()}' is not supported"); - } - this.PropertiesValue = new DynamicMapping(value.Properties); - } - } - - /// - [DataMember(Order = 4, Name = "extensionData"), JsonExtensionData] - public IDictionary? ExtensionData { get; set; } - - /// - public override string ToString() => this.Name; - -} \ No newline at end of file diff --git a/src/ServerlessWorkflow.Sdk/Models/AuthenticationPolicyDefinition.cs b/src/ServerlessWorkflow.Sdk/Models/AuthenticationPolicyDefinition.cs new file mode 100644 index 0000000..4f5d62c --- /dev/null +++ b/src/ServerlessWorkflow.Sdk/Models/AuthenticationPolicyDefinition.cs @@ -0,0 +1,50 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +using ServerlessWorkflow.Sdk.Models.Authentication; + +namespace ServerlessWorkflow.Sdk.Models; + +/// +/// Represents the definition of an authentication policy +/// +[DataContract] +public record AuthenticationPolicyDefinition + : ReferenceableComponentDefinition +{ + + /// + /// Gets the configured authentication scheme + /// + [IgnoreDataMember, JsonIgnore, YamlIgnore] + public virtual string Scheme => this.Basic?.Scheme ?? this.Bearer?.Scheme ?? this.OAuth2?.Scheme ?? throw new NullReferenceException(); + + /// + /// Gets/sets the `basic` authentication scheme to use, if any + /// + [DataMember(Name = "basic", Order = 1), JsonPropertyName("basic"), JsonPropertyOrder(1), YamlMember(Alias = "basic", Order = 1)] + public virtual BasicAuthenticationSchemeDefinition? Basic { get; set; } + + /// + /// Gets/sets the `Bearer` authentication scheme to use, if any + /// + [DataMember(Name = "bearer", Order = 2), JsonPropertyName("bearer"), JsonPropertyOrder(2), YamlMember(Alias = "bearer", Order = 2)] + public virtual BearerAuthenticationSchemeDefinition? Bearer { get; set; } + + /// + /// Gets/sets the OAUTH2 authentication scheme to use, if any + /// + [DataMember(Name = "oauth2", Order = 3), JsonPropertyName("oauth2"), JsonPropertyOrder(3), YamlMember(Alias = "oauth2", Order = 3)] + public virtual OAuth2AuthenticationSchemeDefinition? OAuth2 { get; set; } + +} diff --git a/src/ServerlessWorkflow.Sdk/Models/AuthenticationProperties.cs b/src/ServerlessWorkflow.Sdk/Models/AuthenticationProperties.cs deleted file mode 100644 index 505d676..0000000 --- a/src/ServerlessWorkflow.Sdk/Models/AuthenticationProperties.cs +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace ServerlessWorkflow.Sdk.Models; - -/// -/// Represents an object used to configure an authentication mechanism -/// -[DataContract, KnownType(nameof(GetKnownTypes))] -public abstract class AuthenticationProperties -{ - - /// - /// Initializes a new - /// - protected AuthenticationProperties() - { - this.Properties = new Dictionary(); - } - - /// - /// Initializes a new - /// - /// A key/value mapping of the authentication properties to wrap - protected AuthenticationProperties(IDictionary properties) - { - this.Properties = properties ?? throw new ArgumentNullException(nameof(properties)); - } - - /// - /// Gets/sets a key/value mapping of the authentication properties to wrap - /// - [IgnoreDataMember, JsonIgnore, YamlIgnore] - public virtual IDictionary Properties { get; set; } - - static Type[] GetKnownTypes() - { - return new Type[] - { - typeof(BasicAuthenticationProperties), - typeof(BearerAuthenticationProperties), - typeof(OAuth2AuthenticationProperties), - typeof(SecretBasedAuthenticationProperties) - }; - } - -} diff --git a/src/ServerlessWorkflow.Sdk/Models/States/ExtensionStateDefinition.cs b/src/ServerlessWorkflow.Sdk/Models/AuthenticationSchemeDefinition.cs similarity index 62% rename from src/ServerlessWorkflow.Sdk/Models/States/ExtensionStateDefinition.cs rename to src/ServerlessWorkflow.Sdk/Models/AuthenticationSchemeDefinition.cs index 5028a30..8456bc7 100644 --- a/src/ServerlessWorkflow.Sdk/Models/States/ExtensionStateDefinition.cs +++ b/src/ServerlessWorkflow.Sdk/Models/AuthenticationSchemeDefinition.cs @@ -1,4 +1,4 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors +// Copyright © 2024-Present The Serverless Workflow Specification Authors // // Licensed under the Apache License, Version 2.0 (the "License"), // you may not use this file except in compliance with the License. @@ -11,23 +11,20 @@ // See the License for the specific language governing permissions and // limitations under the License. -using Neuroglia; - namespace ServerlessWorkflow.Sdk.Models; /// -/// Represents the definition of an extension state +/// Represents the base class for all authentication scheme definitions /// [DataContract] -[DiscriminatedByDefault] -public class ExtensionStateDefinition - : StateDefinition +public abstract record AuthenticationSchemeDefinition + : Extendable { - /// - public ExtensionStateDefinition() { } - - /// - public ExtensionStateDefinition(string type): base(type) { } + /// + /// Gets the name of the authentication scheme + /// + [IgnoreDataMember, JsonIgnore, YamlIgnore] + public abstract string Scheme { get; } -} \ No newline at end of file +} diff --git a/src/ServerlessWorkflow.Sdk/Models/DefaultCaseDefinition.cs b/src/ServerlessWorkflow.Sdk/Models/BackoffDefinition.cs similarity index 71% rename from src/ServerlessWorkflow.Sdk/Models/DefaultCaseDefinition.cs rename to src/ServerlessWorkflow.Sdk/Models/BackoffDefinition.cs index 0949054..b06a00f 100644 --- a/src/ServerlessWorkflow.Sdk/Models/DefaultCaseDefinition.cs +++ b/src/ServerlessWorkflow.Sdk/Models/BackoffDefinition.cs @@ -1,4 +1,4 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors +// Copyright © 2024-Present The Serverless Workflow Specification Authors // // Licensed under the Apache License, Version 2.0 (the "License"), // you may not use this file except in compliance with the License. @@ -14,13 +14,12 @@ namespace ServerlessWorkflow.Sdk.Models; /// -/// Represents an object used to define the transition of the workflow if there is no matching cases or event timeout is reached +/// Represents the base class of all backoff definitions /// [DataContract] -public class DefaultCaseDefinition - : SwitchCaseDefinition +public abstract record BackoffDefinition { -} \ No newline at end of file +} diff --git a/src/ServerlessWorkflow.Sdk/Models/BackoffStrategyDefinition.cs b/src/ServerlessWorkflow.Sdk/Models/BackoffStrategyDefinition.cs new file mode 100644 index 0000000..af64167 --- /dev/null +++ b/src/ServerlessWorkflow.Sdk/Models/BackoffStrategyDefinition.cs @@ -0,0 +1,41 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Models; + +/// +/// Represents the definition of a retry backoff strategy +/// +[DataContract] +public record BackoffStrategyDefinition +{ + + /// + /// Gets/sets the definition of the constant backoff to use, if any + /// + [DataMember(Name = "constant", Order = 1), JsonPropertyName("constant"), JsonPropertyOrder(1), YamlMember(Alias = "constant", Order = 1)] + public virtual ConstantBackoffDefinition? Constant { get; set; } + + /// + /// Gets/sets the definition of the exponential backoff to use, if any + /// + [DataMember(Name = "exponential", Order = 2), JsonPropertyName("exponential"), JsonPropertyOrder(2), YamlMember(Alias = "exponential", Order = 2)] + public virtual ExponentialBackoffDefinition? Exponential { get; set; } + + /// + /// Gets/sets the definition of the linear backoff to use, if any + /// + [DataMember(Name = "linear", Order = 3), JsonPropertyName("linear"), JsonPropertyOrder(3), YamlMember(Alias = "linear", Order = 3)] + public virtual LinearBackoffDefinition? Linear { get; set; } + +} diff --git a/src/ServerlessWorkflow.Sdk/Models/BasicAuthenticationProperties.cs b/src/ServerlessWorkflow.Sdk/Models/BasicAuthenticationProperties.cs deleted file mode 100644 index 3d64d5c..0000000 --- a/src/ServerlessWorkflow.Sdk/Models/BasicAuthenticationProperties.cs +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace ServerlessWorkflow.Sdk.Models; - -/// -/// Represents an object used to configure a 'Basic' authentication scheme -/// -[DataContract] -public class BasicAuthenticationProperties - : AuthenticationProperties -{ - - /// - public BasicAuthenticationProperties() { } - - /// - public BasicAuthenticationProperties(IDictionary properties) : base(properties) { } - - /// - /// Gets/sets the username to use when authenticating - /// - [Required, MinLength(1)] - [IgnoreDataMember, JsonIgnore, YamlIgnore] - public virtual string Username - { - get - { - if (this.Properties.TryGetValue(nameof(Username).ToCamelCase(), out var value)) return (string)value; - else return null!; - } - set - { - this.Properties[nameof(Username).ToCamelCase()] = value; - } - } - - /// - /// Gets/sets the password to use when authenticating - /// - [Required, MinLength(1)] - [IgnoreDataMember, JsonIgnore, YamlIgnore] - public virtual string Password - { - get - { - if (this.Properties.TryGetValue(nameof(Password).ToCamelCase(), out var value)) return (string)value; - else return null!; - } - set - { - this.Properties[nameof(Password).ToCamelCase()] = value; - } - } - -} diff --git a/src/ServerlessWorkflow.Sdk/Models/BearerAuthenticationProperties.cs b/src/ServerlessWorkflow.Sdk/Models/BearerAuthenticationProperties.cs deleted file mode 100644 index 5dd29a9..0000000 --- a/src/ServerlessWorkflow.Sdk/Models/BearerAuthenticationProperties.cs +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace ServerlessWorkflow.Sdk.Models; - -/// -/// Represents an object used to configure a 'Bearer' authentication scheme -/// - -[DataContract] -public class BearerAuthenticationProperties - : AuthenticationProperties -{ - - /// - public BearerAuthenticationProperties() { } - - /// - public BearerAuthenticationProperties(IDictionary properties) : base(properties) { } - - /// - /// Gets/sets the token used to authenticate - /// - [Required, MinLength(1)] - [IgnoreDataMember, JsonIgnore, YamlIgnore] - public virtual string Token - { - get - { - if (this.Properties.TryGetValue(nameof(Token).ToCamelCase(), out var value)) return (string)value; - else return null!; - } - set - { - this.Properties[nameof(Token).ToCamelCase()] = value; - } - } - -} diff --git a/src/ServerlessWorkflow.Sdk/Models/BranchDefinition.cs b/src/ServerlessWorkflow.Sdk/Models/BranchDefinition.cs deleted file mode 100644 index 60fccca..0000000 --- a/src/ServerlessWorkflow.Sdk/Models/BranchDefinition.cs +++ /dev/null @@ -1,89 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace ServerlessWorkflow.Sdk.Models; - -/// -/// Represents a workflow execution branch -/// -[DataContract] -public class BranchDefinition - : IExtensible -{ - - /// - /// gets/sets the branch's name - /// - [Required, MinLength(1)] - [DataMember(Order = 1, Name = "name", IsRequired = true), JsonPropertyOrder(1), JsonPropertyName("name"), YamlMember(Alias = "name", Order = 1)] - public virtual string Name { get; set; } = null!; - - /// - /// Gets/sets a value that specifies how actions are to be performed (in sequence of parallel) - /// - [DefaultValue(ActionExecutionMode.Sequential)] - [DataMember(Order = 2, Name = "actionMode"), JsonPropertyOrder(2), JsonPropertyName("actionMode"), YamlMember(Alias = "actionMode", Order = 2)] - public virtual string ActionMode { get; set; } = ActionExecutionMode.Sequential; - - /// - /// Gets/sets anlist containing the actions to be executed in this branch - /// - [Required, MinLength(1)] - [DataMember(Order = 3, Name = "actions", IsRequired = true), JsonPropertyOrder(3), JsonPropertyName("actions"), YamlMember(Alias = "actions", Order = 3)] - public virtual List Actions { get; set; } = new List(); - - /// - [DataMember(Order = 999, Name = "extensionData"), JsonExtensionData] - public IDictionary? ExtensionData { get; set; } - - /// - /// Gets the with the specified name - /// - /// The name of the to get - /// The with the specified name - public virtual ActionDefinition? GetAction(string name) => this.Actions.FirstOrDefault(s => s.Name == name); - - /// - /// Attempts to get the with the specified name - /// - /// The name of the to get - /// The with the specified name - /// A boolean indicating whether or not a with the specified name could be found - public virtual bool TryGetAction(string name, out ActionDefinition action) - { - action = this.GetAction(name)!; - return action != null; - } - - /// - /// Attempts to get the next in the pipeline - /// - /// The name of the to get the next for - /// The next , if any - /// A boolean indicating whether or not there is a next in the pipeline - public virtual bool TryGetNextAction(string previousActionName, out ActionDefinition action) - { - action = null!; - var previousAction = this.Actions.FirstOrDefault(a => a.Name == previousActionName); - if (previousAction == null) return false; - int previousActionIndex = this.Actions.ToList().IndexOf(previousAction); - int nextIndex = previousActionIndex + 1; - if (nextIndex >= this.Actions.Count()) return false; - action = this.Actions.ElementAt(nextIndex); - return true; - } - - /// - public override string ToString() => this.Name; - -} \ No newline at end of file diff --git a/src/ServerlessWorkflow.Sdk/Models/StateOutcomeDefinition.cs b/src/ServerlessWorkflow.Sdk/Models/CallDefinition.cs similarity index 78% rename from src/ServerlessWorkflow.Sdk/Models/StateOutcomeDefinition.cs rename to src/ServerlessWorkflow.Sdk/Models/CallDefinition.cs index bd98fa8..0e7cda4 100644 --- a/src/ServerlessWorkflow.Sdk/Models/StateOutcomeDefinition.cs +++ b/src/ServerlessWorkflow.Sdk/Models/CallDefinition.cs @@ -1,4 +1,4 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors +// Copyright © 2024-Present The Serverless Workflow Specification Authors // // Licensed under the Apache License, Version 2.0 (the "License"), // you may not use this file except in compliance with the License. @@ -14,10 +14,10 @@ namespace ServerlessWorkflow.Sdk.Models; /// -/// Represents the base class for all state definition's outcomes +/// Represents the base class for all call definitions /// [DataContract] -public abstract class StateOutcomeDefinition +public abstract record CallDefinition { diff --git a/src/ServerlessWorkflow.Sdk/Models/Calls/AsyncApiCallDefinition.cs b/src/ServerlessWorkflow.Sdk/Models/Calls/AsyncApiCallDefinition.cs new file mode 100644 index 0000000..20e5a80 --- /dev/null +++ b/src/ServerlessWorkflow.Sdk/Models/Calls/AsyncApiCallDefinition.cs @@ -0,0 +1,68 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Models.Calls; + +/// +/// Represents the definition of an AsyncAPI call +/// +[DataContract] +public record AsyncApiCallDefinition + : CallDefinition +{ + + /// + /// Gets/sets the document that defines the AsyncAPI operation to call + /// + [Required] + [DataMember(Name = "document", Order = 1), JsonPropertyName("document"), JsonPropertyOrder(1), YamlMember(Alias = "document", Order = 1)] + public required virtual ExternalResourceDefinition Document { get; set; } + + /// + /// Gets/sets a reference to the AsyncAPI operation to call + /// + [Required] + [DataMember(Name = "operationRef", Order = 2), JsonPropertyName("operationRef"), JsonPropertyOrder(2), JsonInclude, YamlMember(Alias = "operationRef", Order = 2)] + public required virtual string OperationRef { get; set; } + + /// + /// Gets/sets a reference to the server to call the specified AsyncAPI operation on. If not set, default to the first server matching the operation's channel. + /// + [DataMember(Name = "server", Order = 3), JsonPropertyName("server"), JsonPropertyOrder(3), JsonInclude, YamlMember(Alias = "server", Order = 3)] + public virtual string? Server { get; set; } + + /// + /// Gets/sets the name of the message to use. If not set, defaults to the first message defined by the operation + /// + [DataMember(Name = "message", Order = 4), JsonPropertyName("message"), JsonPropertyOrder(4), JsonInclude, YamlMember(Alias = "message", Order = 4)] + public virtual string? Message { get; set; } + + /// + /// Gets/sets the name of the binding to use. If not set, defaults to the first binding defined by the operation + /// + [DataMember(Name = "binding", Order = 5), JsonPropertyName("binding"), JsonPropertyOrder(5), JsonInclude, YamlMember(Alias = "binding", Order = 5)] + public virtual string? Binding { get; set; } + + /// + /// Gets/sets the payload to call the AsyncAPI operation with + /// + [DataMember(Name = "payload", Order = 6), JsonPropertyName("payload"), JsonPropertyOrder(6), JsonInclude, YamlMember(Alias = "payload", Order = 6)] + public virtual object? Payload { get; set; } + + /// + /// Gets/sets the authentication policy, if any, to use when calling the AsyncAPI operation + /// + [DataMember(Name = "authentication", Order = 7), JsonPropertyName("authentication"), JsonPropertyOrder(7), JsonInclude, YamlMember(Alias = "authentication", Order = 7)] + public virtual AuthenticationPolicyDefinition? Authentication { get; set; } + +} \ No newline at end of file diff --git a/src/ServerlessWorkflow.Sdk/Models/Calls/GrpcCallDefinition.cs b/src/ServerlessWorkflow.Sdk/Models/Calls/GrpcCallDefinition.cs new file mode 100644 index 0000000..ee32f9d --- /dev/null +++ b/src/ServerlessWorkflow.Sdk/Models/Calls/GrpcCallDefinition.cs @@ -0,0 +1,51 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Models.Calls; + +/// +/// Represents the definition of a GRPC call +/// +[DataContract] +public record GrpcCallDefinition + : CallDefinition +{ + + /// + /// Gets the proto resource that describes the GRPC service to call + /// + [Required] + [DataMember(Name = "proto", Order = 1), JsonPropertyName("proto"), JsonPropertyOrder(1), YamlMember(Alias = "proto", Order = 1)] + public required virtual ExternalResourceDefinition Proto { get; set; } + + /// + /// Gets/sets the definition of the GRPC service to call + /// + [Required] + [DataMember(Name = "service", Order = 2), JsonPropertyName("service"), JsonPropertyOrder(2), YamlMember(Alias = "service", Order = 2)] + public required virtual GrpcServiceDefinition Service { get; set; } + + /// + /// Gets/sets the name of the GRPC service method to call + /// + [Required, MinLength(1)] + [DataMember(Name = "method", Order = 3), JsonPropertyName("method"), JsonPropertyOrder(3), YamlMember(Alias = "method", Order = 3)] + public required virtual string Method { get; set; } + + /// + /// Gets/sets the method call's arguments, if any + /// + [DataMember(Name = "arguments", Order = 4), JsonPropertyName("arguments"), JsonPropertyOrder(4), YamlMember(Alias = "arguments", Order = 4)] + public virtual IDictionary? Arguments { get; set; } + +} diff --git a/src/ServerlessWorkflow.Sdk/Models/Calls/HttpCallDefinition.cs b/src/ServerlessWorkflow.Sdk/Models/Calls/HttpCallDefinition.cs new file mode 100644 index 0000000..831e466 --- /dev/null +++ b/src/ServerlessWorkflow.Sdk/Models/Calls/HttpCallDefinition.cs @@ -0,0 +1,56 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Models.Calls; + +/// +/// Represents the definition of an HTTP call +/// +[DataContract] +public record HttpCallDefinition + : CallDefinition +{ + + /// + /// Gets/sets the HTTP method of the request to perform + /// + [Required, MinLength(1)] + [DataMember(Name = "method", Order = 1), JsonPropertyName("method"), JsonPropertyOrder(1), YamlMember(Alias = "method", Order = 1)] + public required virtual string Method { get; set; } + + /// + /// Gets/sets the definition of the endpoint to request + /// + [Required] + [DataMember(Name = "endpoint", Order = 2), JsonPropertyName("endpoint"), JsonPropertyOrder(2), YamlMember(Alias = "endpoint", Order = 2)] + public required virtual EndpointDefinition Endpoint { get; set; } + + /// + /// Gets/sets a name/value mapping of the headers, if any, of the HTTP request to perform + /// + [DataMember(Name = "headers", Order = 3), JsonPropertyName("headers"), JsonPropertyOrder(3), YamlMember(Alias = "headers", Order = 3)] + public virtual EquatableDictionary? Headers { get; set; } + + /// + /// Gets/sets the body, if any, of the HTTP request to perform + /// + [DataMember(Name = "body", Order = 4), JsonPropertyName("body"), JsonPropertyOrder(4), YamlMember(Alias = "body", Order = 4)] + public virtual object? Body { get; set; } + + /// + /// Gets/sets the http call output format. Defaults to . + /// + [DataMember(Name = "output", Order = 5), JsonPropertyName("output"), JsonPropertyOrder(5), YamlMember(Alias = "output", Order = 5)] + public virtual string? Output { get; set; } + +} \ No newline at end of file diff --git a/src/ServerlessWorkflow.Sdk/Models/Calls/OpenApiCallDefinition.cs b/src/ServerlessWorkflow.Sdk/Models/Calls/OpenApiCallDefinition.cs new file mode 100644 index 0000000..dde27c9 --- /dev/null +++ b/src/ServerlessWorkflow.Sdk/Models/Calls/OpenApiCallDefinition.cs @@ -0,0 +1,56 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Models.Calls; + +/// +/// Represents the definition of an OpenAPI call +/// +[DataContract] +public record OpenApiCallDefinition + : CallDefinition +{ + + /// + /// Gets/sets the document that defines the OpenAPI operation to call + /// + [Required] + [DataMember(Name = "document", Order = 1), JsonPropertyName("document"), JsonPropertyOrder(1), YamlMember(Alias = "document", Order = 1)] + public required virtual ExternalResourceDefinition Document { get; set; } + + /// + /// Gets/sets the id of the OpenAPI operation to call + /// + [Required] + [DataMember(Name = "operationId", Order = 2), JsonPropertyName("operationId"), JsonPropertyOrder(2), JsonInclude, YamlMember(Alias = "operationId", Order = 2)] + public required virtual string OperationId { get; set; } + + /// + /// Gets/sets a name/value mapping of the parameters of the OpenAPI operation to call + /// + [DataMember(Name = "parameters", Order = 3), JsonPropertyName("parameters"), JsonPropertyOrder(3), YamlMember(Alias = "parameters", Order = 3)] + public virtual EquatableDictionary? Parameters { get; set; } + + /// + /// Gets/sets the authentication policy, if any, to use when calling the OpenAPI operation + /// + [DataMember(Name = "authentication", Order = 4), JsonPropertyName("authentication"), JsonPropertyOrder(4), YamlMember(Alias = "authentication", Order = 4)] + public virtual AuthenticationPolicyDefinition? Authentication { get; set; } + + /// + /// Gets/sets the http output format. Defaults to . + /// + [DataMember(Name = "output", Order = 6), JsonPropertyName("output"), JsonPropertyOrder(6), YamlMember(Alias = "output", Order = 6)] + public virtual string? Output { get; set; } + +} diff --git a/src/ServerlessWorkflow.Sdk/Models/DataCaseDefinition.cs b/src/ServerlessWorkflow.Sdk/Models/ComponentDefinition.cs similarity index 56% rename from src/ServerlessWorkflow.Sdk/Models/DataCaseDefinition.cs rename to src/ServerlessWorkflow.Sdk/Models/ComponentDefinition.cs index 18d23d7..5fccddd 100644 --- a/src/ServerlessWorkflow.Sdk/Models/DataCaseDefinition.cs +++ b/src/ServerlessWorkflow.Sdk/Models/ComponentDefinition.cs @@ -1,4 +1,4 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors +// Copyright © 2024-Present The Serverless Workflow Specification Authors // // Licensed under the Apache License, Version 2.0 (the "License"), // you may not use this file except in compliance with the License. @@ -14,18 +14,17 @@ namespace ServerlessWorkflow.Sdk.Models; /// -/// Represents a data-based +/// Represents the base class for all ServerlessWorkflow workflow components /// [DataContract] -public class DataCaseDefinition - : SwitchCaseDefinition +public abstract record ComponentDefinition + : IExtendable { /// - /// Gets/sets an expression evaluated against state data. True if results are not empty + /// Gets/sets a key/value mapping of the object's extension data, if any /// - [Required, MinLength(1)] - [DataMember(Order = 1, Name = "condition", IsRequired = true), JsonPropertyOrder(1), JsonPropertyName("condition"), YamlMember(Alias = "condition", Order = 1)] - public virtual string Condition { get; set; } = null!; + [DataMember(Name = "extensions", Order = 99), JsonPropertyName("extensions"), JsonPropertyOrder(99), YamlMember(Alias = "extensions", Order = 99)] + public virtual EquatableDictionary? Extensions { get; set; } } diff --git a/src/ServerlessWorkflow.Sdk/Models/ComponentDefinitionCollection.cs b/src/ServerlessWorkflow.Sdk/Models/ComponentDefinitionCollection.cs new file mode 100644 index 0000000..12d687c --- /dev/null +++ b/src/ServerlessWorkflow.Sdk/Models/ComponentDefinitionCollection.cs @@ -0,0 +1,59 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Models; + +/// +/// Represents a collection of workflow components +/// +[DataContract] +public record ComponentDefinitionCollection +{ + + /// + /// Gets/sets a name/value mapping of the workflow's reusable authentication policies + /// + [DataMember(Name = "authentications", Order = 1), JsonPropertyName("authentications"), JsonPropertyOrder(1), YamlMember(Alias = "authentications", Order = 1)] + public virtual EquatableDictionary? Authentications { get; set; } + + /// + /// Gets/sets a name/value mapping of the workflow's errors, if any + /// + [DataMember(Name = "errors", Order = 2), JsonPropertyName("errors"), JsonPropertyOrder(2), YamlMember(Alias = "errors", Order = 2)] + public virtual EquatableDictionary? Errors { get; set; } + + /// + /// Gets/sets a name/value mapping of the workflow's extensions, if any + /// + [DataMember(Name = "extensions", Order = 3), JsonPropertyName("extensions"), JsonPropertyOrder(3), YamlMember(Alias = "extensions", Order = 3)] + public virtual EquatableDictionary? Extensions { get; set; } + + /// + /// Gets/sets a name/value mapping of the workflow's reusable functions + /// + [DataMember(Name = "functions", Order = 4), JsonPropertyName("functions"), JsonPropertyOrder(4), YamlMember(Alias = "functions", Order = 4)] + public virtual EquatableDictionary? Functions { get; set; } + + /// + /// Gets/sets a name/value mapping of the workflow's reusable retry policies + /// + [DataMember(Name = "retries", Order = 5), JsonPropertyName("retries"), JsonPropertyOrder(5), YamlMember(Alias = "retries", Order = 5)] + public virtual EquatableDictionary? Retries { get; set; } + + /// + /// Gets/sets a list containing the names of the secrets to use + /// + [DataMember(Name = "secrets", Order = 6), JsonPropertyName("secrets"), JsonPropertyOrder(6), YamlMember(Alias = "secrets", Order = 6)] + public virtual EquatableList? Secrets { get; set; } + +} diff --git a/src/ServerlessWorkflow.Sdk/Models/ConstantBackoffDefinition.cs b/src/ServerlessWorkflow.Sdk/Models/ConstantBackoffDefinition.cs new file mode 100644 index 0000000..799accb --- /dev/null +++ b/src/ServerlessWorkflow.Sdk/Models/ConstantBackoffDefinition.cs @@ -0,0 +1,26 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Models; + +/// +/// Represents the definition of a constant backoff +/// +[DataContract] +public record ConstantBackoffDefinition + : BackoffDefinition +{ + + + +} diff --git a/src/ServerlessWorkflow.Sdk/Models/CorrelationDefinition.cs b/src/ServerlessWorkflow.Sdk/Models/CorrelationDefinition.cs new file mode 100644 index 0000000..54866d0 --- /dev/null +++ b/src/ServerlessWorkflow.Sdk/Models/CorrelationDefinition.cs @@ -0,0 +1,35 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Models; + +/// +/// Represents the definition of a event correlation +/// +[DataContract] +public record CorrelationDefinition +{ + + /// + /// Gets/sets a runtime expression used to extract the correlation value from events. + /// + [DataMember(Name = "from", Order = 1), JsonPropertyName("from"), JsonPropertyOrder(1), YamlMember(Alias = "from", Order = 1)] + public required virtual string From { get; set; } + + /// + /// Gets/sets a constant or a runtime expression, if any, used to determine whether or not the extracted correlation value matches expectations and should be correlated. If not set, the first extracted value will be used as the correlation's expectation. + /// + [DataMember(Name = "expect", Order = 2), JsonPropertyName("expect"), JsonPropertyOrder(2), YamlMember(Alias = "expect", Order = 2)] + public virtual string? Expect { get; set; } + +} diff --git a/src/ServerlessWorkflow.Sdk/Models/CronDefinition.cs b/src/ServerlessWorkflow.Sdk/Models/CronDefinition.cs deleted file mode 100644 index 439008c..0000000 --- a/src/ServerlessWorkflow.Sdk/Models/CronDefinition.cs +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace ServerlessWorkflow.Sdk.Models; - -/// -/// Represents a CRON expression definition -/// -[DataContract] -public class CronDefinition - : IExtensible -{ - - /// - /// Gets/sets the repeating interval (cron expression) describing when the workflow instance should be created - /// - [Required] - [DataMember(Order = 1, Name = "expression", IsRequired = true), JsonPropertyName("expression"), YamlMember(Alias = "expression")] - public virtual string Expression { get; set; } = null!; - - /// - /// Gets/sets the date and time when the cron expression invocation is no longer valid - /// - [DataMember(Order = 2, Name = "validUntil", IsRequired = true), JsonPropertyName("validUntil"), YamlMember(Alias = "validUntil")] - public virtual DateTime? ValidUntil { get; set; } - - /// - [DataMember(Order = 3, Name = "extensionData"), JsonExtensionData] - public IDictionary? ExtensionData { get; set; } - -} diff --git a/src/ServerlessWorkflow.Sdk/Models/DataInputSchemaDefinition.cs b/src/ServerlessWorkflow.Sdk/Models/DataInputSchemaDefinition.cs deleted file mode 100644 index 687589e..0000000 --- a/src/ServerlessWorkflow.Sdk/Models/DataInputSchemaDefinition.cs +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace ServerlessWorkflow.Sdk.Models; - -/// -/// Represents the object used to configure a workflow definition's data input schema -/// -[DataContract] -public class DataInputSchemaDefinition - : IExtensible -{ - - /// - /// Gets/sets the url of the workflow definition's input data schema - /// - [DataMember(Order = 1, Name = "schema"), JsonPropertyName("schema"), YamlMember(Alias = "schema")] - [JsonConverter(typeof(OneOfConverter))] - public virtual OneOf? Schema { get; set; } - - /// - /// Gets/sets a boolean indicating whether or not to terminate the workflow definition's execution whenever the validation of the input data fails. Defaults to true. - /// - [DefaultValue(true)] - [DataMember(Order = 2, Name = "failOnValidationErrors"), JsonPropertyName("failOnValidationErrors"), YamlMember(Alias = "failOnValidationErrors")] - public virtual bool FailOnValidationErrors { get; set; } = true; - - /// - [DataMember(Order = 3, Name = "extensionData"), JsonExtensionData] - public IDictionary? ExtensionData { get; set; } - -} \ No newline at end of file diff --git a/src/ServerlessWorkflow.Sdk/Models/DataModelDefinition.cs b/src/ServerlessWorkflow.Sdk/Models/DataModelDefinition.cs new file mode 100644 index 0000000..c80c286 --- /dev/null +++ b/src/ServerlessWorkflow.Sdk/Models/DataModelDefinition.cs @@ -0,0 +1,35 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Models; + +/// +/// Represents the definition of a data model +/// +[DataContract] +public abstract record DataModelDefinition +{ + + /// + /// Gets/sets the schema, if any, that defines and describes the defined data model + /// + [DataMember(Name = "schema", Order = 1), JsonPropertyName("schema"), JsonPropertyOrder(1), YamlMember(Alias = "schema", Order = 1)] + public virtual SchemaDefinition? Schema { get; set; } + + /// + /// Gets/sets a runtime expression, if any, used to build the defined model using both input and scope data + /// + [DataMember(Name = "from", Order = 2), JsonPropertyName("from"), JsonPropertyOrder(2), JsonInclude, YamlMember(Alias = "from", Order = 2)] + public virtual object? From { get; set; } + +} diff --git a/src/ServerlessWorkflow.Sdk/Models/Duration.cs b/src/ServerlessWorkflow.Sdk/Models/Duration.cs new file mode 100644 index 0000000..ca97f79 --- /dev/null +++ b/src/ServerlessWorkflow.Sdk/Models/Duration.cs @@ -0,0 +1,166 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Models; + +/// +/// Represents a duration +/// +[DataContract] +public record Duration +{ + + /// + /// Gets/sets the numbers of days, if any + /// + [DataMember(Name = "days", Order = 1), JsonPropertyName("days"), JsonPropertyOrder(1), YamlMember(Alias = "days", Order = 1)] + public virtual uint? Days { get; set; } + + /// + /// Gets/sets the numbers of hours, if any + /// + [DataMember(Name = "hours", Order = 2), JsonPropertyName("hours"), JsonPropertyOrder(2), YamlMember(Alias = "hours", Order = 2)] + public virtual uint? Hours { get; set; } + + /// + /// Gets/sets the numbers of minutes, if any + /// + [DataMember(Name = "minutes", Order = 3), JsonPropertyName("minutes"), JsonPropertyOrder(3), YamlMember(Alias = "minutes", Order = 3)] + public virtual uint? Minutes { get; set; } + + /// + /// Gets/sets the numbers of seconds, if any + /// + [DataMember(Name = "seconds", Order = 4), JsonPropertyName("seconds"), JsonPropertyOrder(4), YamlMember(Alias = "seconds", Order = 4)] + public virtual uint? Seconds { get; set; } + + /// + /// Gets/sets the numbers of milliseconds, if any + /// + [DataMember(Name = "milliseconds", Order = 5), JsonPropertyName("milliseconds"), JsonPropertyOrder(5), YamlMember(Alias = "milliseconds", Order = 5)] + public virtual uint? Milliseconds { get; set; } + + /// + /// Gets the the duration's total amount of days + /// + [IgnoreDataMember, JsonIgnore, YamlIgnore] + public virtual double TotalDays => this.TotalHours / 24; + + /// + /// Gets the the duration's total amount of hours + /// + [IgnoreDataMember, JsonIgnore, YamlIgnore] + public virtual double TotalHours => this.TotalMinutes / 60; + + /// + /// Gets the the duration's total amount of minutes + /// + [IgnoreDataMember, JsonIgnore, YamlIgnore] + public virtual double TotalMinutes => this.TotalSeconds / 60; + + /// + /// Gets the the duration's total amount of seconds + /// + [IgnoreDataMember, JsonIgnore, YamlIgnore] + public virtual double TotalSeconds => this.TotalMilliseconds / 1000; + + /// + /// Gets the the duration's total amount of milliseconds + /// + [IgnoreDataMember, JsonIgnore, YamlIgnore] + public virtual uint TotalMilliseconds + { + get + { + var milliseconds = this.Days.HasValue ? this.Days * 24 * 60 * 60 * 1000 : 0; + milliseconds += this.Hours.HasValue ? this.Hours * 60 * 60 * 1000 : 0; + milliseconds += this.Minutes.HasValue ? this.Minutes * 60 * 1000 : 0; + milliseconds += this.Seconds.HasValue ? this.Seconds * 1000 : 0; + milliseconds += this.Milliseconds.HasValue ? this.Milliseconds : 0; + return milliseconds ?? 0; + } + } + + /// + /// Converts the to a new + /// + /// A new + public virtual TimeSpan ToTimeSpan() => new((int)(this.Days ?? 0), (int)(this.Hours ?? 0), (int)(this.Minutes ?? 0), (int)(this.Seconds ?? 0), (int)(this.Milliseconds ?? 0)); + + /// + /// Gets a zero value + /// + public static readonly Duration Zero = new(); + + /// + /// Creates a new object representing the specified number of days. + /// + /// The number of days. + /// A new object with the specified number of days. + public static Duration FromDays(uint days) => new() { Days = days }; + + /// + /// Creates a new object representing the specified number of hours. + /// + /// The number of hours. + /// A new object with the specified number of hours. + public static Duration FromHours(uint hours) => new() { Hours = hours }; + + /// + /// Creates a new object representing the specified number of minutes. + /// + /// The number of minutes. + /// A new object with the specified number of minutes. + public static Duration FromMinutes(uint minutes) => new() { Minutes = minutes }; + + /// + /// Creates a new object representing the specified number of seconds. + /// + /// The number of seconds. + /// A new object with the specified number of seconds. + public static Duration FromSeconds(uint seconds) => new() { Seconds = seconds }; + + /// + /// Creates a new object representing the specified number of milliseconds. + /// + /// The number of milliseconds. + /// A new object with the specified number of milliseconds. + public static Duration FromMilliseconds(uint milliseconds) => new() { Milliseconds = milliseconds }; + + /// + /// Creates a new representing the specified . + /// + /// The to convert. + /// A new representing the specified . + public static Duration FromTimeSpan(TimeSpan timeSpan) => new() + { + Days = (uint)timeSpan.Days, + Hours = (uint)timeSpan.Hours, + Minutes = (uint)timeSpan.Minutes, + Seconds = (uint)timeSpan.Seconds, + Milliseconds = (uint)timeSpan.Milliseconds + }; + + /// + /// Converts the specified into a new + /// + /// The to convert + public static implicit operator TimeSpan?(Duration? duration) => duration?.ToTimeSpan(); + + /// + /// Converts the specified into a new + /// + /// The to convert + public static implicit operator Duration?(TimeSpan? timeSpan) => timeSpan == null ? null : FromTimeSpan(timeSpan.Value); + +} \ No newline at end of file diff --git a/src/ServerlessWorkflow.Sdk/Models/DynamicMapping.cs b/src/ServerlessWorkflow.Sdk/Models/DynamicMapping.cs deleted file mode 100644 index b74bdf2..0000000 --- a/src/ServerlessWorkflow.Sdk/Models/DynamicMapping.cs +++ /dev/null @@ -1,122 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -using ServerlessWorkflow.Sdk.Serialization; -using System.Collections; -using System.Dynamic; - -namespace ServerlessWorkflow.Sdk.Models; - -/// -/// Represents a dynamic dictionary -/// -[CollectionDataContract] -[JsonConverter(typeof(DynamicMappingConverter))] -public class DynamicMapping - : DynamicObject, IDictionary -{ - - /// - /// Initializes a new - /// - public DynamicMapping() { } - - /// - /// Initializes a new - /// - /// A name/value mapping of the 's properties - public DynamicMapping(IDictionary properties) - { - this.Properties = properties ?? throw new ArgumentNullException(nameof(properties)); - } - - /// - /// Gets a name/value mapping of the 's properties - /// - [JsonExtensionData] - public IDictionary Properties { get; } = new Dictionary(); - - ICollection IDictionary.Keys => this.Properties.Keys; - - ICollection IDictionary.Values => this.Properties.Values; - - int ICollection>.Count => this.Properties.Count; - - bool ICollection>.IsReadOnly => this.Properties.IsReadOnly; - - /// - public object this[string key] { get => this.Properties[key]; set => this.Properties[key] = value; } - - /// - public override bool TryGetMember(GetMemberBinder binder, out object? result) => this.Properties.TryGetValue(binder.Name, out result); - - /// - public override bool TrySetMember(SetMemberBinder binder, object? value) - { - this.Properties[binder.Name] = value!; - return true; - } - - /// - public override bool TryGetIndex(GetIndexBinder binder, object[] indexes, out object? result) - { - if (indexes[0] is int index) - { - result = this.Properties.ElementAtOrDefault(index); - return result != null; - } - else if (indexes[0] is string key) return this.Properties.TryGetValue(key, out result); - else throw new NotSupportedException($"The specified index type '{indexes[0].GetType().Name}' is not supported"); - } - - /// - public override bool TrySetIndex(SetIndexBinder binder, object[] indexes, object? value) - { - if (indexes[0] is int index) - { - if (index >= this.Properties.Keys.Count) throw new IndexOutOfRangeException(nameof(index)); - var kvp = this.Properties.ElementAt(index); - this.Properties[kvp.Key] = value!; - return kvp.Key != default; - } - else if (indexes[0] is string key) - { - this.Properties[key] = value!; - return true; - } - else throw new NotSupportedException($"The specified index type '{indexes[0].GetType().Name}' is not supported"); - } - - void IDictionary.Add(string key, object value) => this.Properties.Add(key, value); - - bool IDictionary.ContainsKey(string key) => this.Properties.ContainsKey(key); - - bool IDictionary.Remove(string key) => this.Properties.Remove(key); - - bool IDictionary.TryGetValue(string key, out object value) => this.Properties.TryGetValue(key, out value!); - - void ICollection>.Add(KeyValuePair item) => this.Properties.Add(item); - - void ICollection>.Clear() => this.Properties.Clear(); - - bool ICollection>.Contains(KeyValuePair item) => this.Properties.Contains(item); - - void ICollection>.CopyTo(KeyValuePair[] array, int arrayIndex) => ((IDictionary)this.Properties).CopyTo(array, arrayIndex); - - bool ICollection>.Remove(KeyValuePair item) => ((IDictionary)this.Properties).Remove(item); - - IEnumerator> IEnumerable>.GetEnumerator() => this.Properties.GetEnumerator(); - - IEnumerator IEnumerable.GetEnumerator() => ((IDictionary)this).GetEnumerator(); - -} diff --git a/src/ServerlessWorkflow.Sdk/Models/EndDefinition.cs b/src/ServerlessWorkflow.Sdk/Models/EndDefinition.cs deleted file mode 100644 index 18b26b3..0000000 --- a/src/ServerlessWorkflow.Sdk/Models/EndDefinition.cs +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace ServerlessWorkflow.Sdk.Models; - -/// -/// Represents an object used to explicitly define execution completion of a workflow instance or workflow execution path. -/// -[DataContract] -public class EndDefinition - : StateOutcomeDefinition -{ - - /// - /// Gets/sets a boolean indicating whether or not to terminate the executing workflow. If true, completes all execution flows in the given workflow instance. Defaults to false. - /// - [DataMember(Order = 1, Name = "terminate"), JsonPropertyOrder(1), JsonPropertyName("terminate"), YamlMember(Alias = "terminate", Order = 1)] - public virtual bool Terminate { get; set; } = false; - - /// - /// Gets/sets an containing the events that should be produced - /// - [DataMember(Order = 2, Name = "produceEvents"), JsonPropertyOrder(2), JsonPropertyName("produceEvents"), YamlMember(Alias = "produceEvents", Order = 2)] - public virtual IEnumerable? ProduceEvents { get; set; } - - /// - /// Gets/sets a boolean indicating whether or not the state should trigger compensation. Default is false. - /// - [DataMember(Order = 3, Name = "compensate"), JsonPropertyOrder(3), JsonPropertyName("compensate"), YamlMember(Alias = "compensate", Order = 3)] - public virtual bool Compensate { get; set; } = false; - -} \ No newline at end of file diff --git a/src/ServerlessWorkflow.Sdk/Models/States/InjectStateDefinition.cs b/src/ServerlessWorkflow.Sdk/Models/EndpointDefinition.cs similarity index 52% rename from src/ServerlessWorkflow.Sdk/Models/States/InjectStateDefinition.cs rename to src/ServerlessWorkflow.Sdk/Models/EndpointDefinition.cs index a137a1b..b6afcf8 100644 --- a/src/ServerlessWorkflow.Sdk/Models/States/InjectStateDefinition.cs +++ b/src/ServerlessWorkflow.Sdk/Models/EndpointDefinition.cs @@ -1,4 +1,4 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors +// Copyright © 2024-Present The Serverless Workflow Specification Authors // // Licensed under the Apache License, Version 2.0 (the "License"), // you may not use this file except in compliance with the License. @@ -11,28 +11,26 @@ // See the License for the specific language governing permissions and // limitations under the License. -using Neuroglia; - namespace ServerlessWorkflow.Sdk.Models; /// -/// Represents the definition of an inject state +/// Represents the definition of an endpoint /// [DataContract] -[DiscriminatorValue(StateType.Inject)] -public class InjectStateDefinition - : StateDefinition +public record EndpointDefinition { /// - /// Initializes a new + /// Gets/sets the endpoint's uri /// - public InjectStateDefinition() : base(StateType.Inject) { } + [Required] + [DataMember(Name = "uri", Order = 1), JsonPropertyName("uri"), JsonPropertyOrder(1), YamlMember(Alias = "uri", Order = 1)] + public required virtual Uri Uri { get; set; } /// - /// Gets/sets the object to inject within the state's data input and can be manipulated via filter + /// Gets/sets the endpoint's authentication policy, if any /// - [DataMember(Order = 6, Name = "data"), JsonPropertyOrder(6), JsonPropertyName("data"), YamlMember(Alias = "data", Order = 6)] - public virtual object Data { get; set; } = null!; + [DataMember(Name = "authentication", Order = 2), JsonPropertyName("authentication"), JsonPropertyOrder(2), YamlMember(Alias = "authentication", Order = 2)] + public virtual AuthenticationPolicyDefinition? Authentication { get; set; } } diff --git a/src/ServerlessWorkflow.Sdk/Models/ErrorCatcherDefinition.cs b/src/ServerlessWorkflow.Sdk/Models/ErrorCatcherDefinition.cs new file mode 100644 index 0000000..57bac2f --- /dev/null +++ b/src/ServerlessWorkflow.Sdk/Models/ErrorCatcherDefinition.cs @@ -0,0 +1,59 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Models; + +/// +/// Represents the configuration of a concept used to catch errors +/// +[DataContract] +public record ErrorCatcherDefinition +{ + + /// + /// Gets/sets the definition of the errors to catch + /// + [DataMember(Name = "errors", Order = 1), JsonPropertyName("errors"), JsonPropertyOrder(1), YamlMember(Alias = "errors", Order = 1)] + public virtual ErrorFilterDefinition? Errors { get; set; } + + /// + /// Gets/sets the name of the runtime expression variable to save the error as. Defaults to 'error'. + /// + [DataMember(Name = "as", Order = 2), JsonPropertyName("as"), JsonPropertyOrder(2), YamlMember(Alias = "as", Order = 2)] + public virtual string? As { get; set; } + + /// + /// Gets/sets a runtime expression used to determine whether or not to catch the filtered error + /// + [DataMember(Name = "when", Order = 3), JsonPropertyName("when"), JsonPropertyOrder(3), YamlMember(Alias = "when", Order = 3)] + public virtual string? When { get; set; } + + /// + /// Gets/sets a runtime expression used to determine whether or not to catch the filtered error + /// + [DataMember(Name = "exceptWhen", Order = 4), JsonPropertyName("exceptWhen"), JsonPropertyOrder(4), YamlMember(Alias = "exceptWhen", Order = 4)] + public virtual string? ExceptWhen { get; set; } + + /// + /// Gets/sets the endpoint's retry policy, if any + /// + [DataMember(Name = "retry", Order = 5), JsonPropertyName("retry"), JsonPropertyOrder(5), YamlMember(Alias = "retry", Order = 5)] + public virtual RetryPolicyDefinition? Retry { get; set; } + + /// + /// Gets/sets the definition of the task to run when catching an error + /// + [DataMember(Name = "do", Order = 6), JsonPropertyName("do"), JsonPropertyOrder(6), YamlMember(Alias = "do", Order = 6)] + public virtual TaskDefinition? Do { get; set; } + +} diff --git a/src/ServerlessWorkflow.Sdk/Models/ErrorDefinition.cs b/src/ServerlessWorkflow.Sdk/Models/ErrorDefinition.cs new file mode 100644 index 0000000..4d61bf9 --- /dev/null +++ b/src/ServerlessWorkflow.Sdk/Models/ErrorDefinition.cs @@ -0,0 +1,59 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Models; + +/// +/// Represents the definition an error to raise +/// +[DataContract] +public record ErrorDefinition +{ + + /// + /// Gets/sets an uri that reference the type of the described error. + /// + [DataMember(Order = 1, Name = "type"), JsonPropertyName("type"), JsonPropertyOrder(1), YamlMember(Alias = "type", Order = 1)] + public required virtual string Type { get; set; } + + /// + /// Gets/sets a short, human-readable summary of the error type.It SHOULD NOT change from occurrence to occurrence of the error, except for purposes of localization. + /// + [DataMember(Order = 2, Name = "title"), JsonPropertyName("title"), JsonPropertyOrder(2), YamlMember(Alias = "title", Order = 2)] + public required virtual string Title { get; set; } + + /// + /// Gets/sets the status code produced by the described error + /// + [DataMember(Order = 3, Name = "status"), JsonPropertyName("status"), JsonPropertyOrder(3), YamlMember(Alias = "status", Order = 3)] + public required virtual object Status { get; set; } + + /// + /// Gets/sets a human-readable explanation specific to this occurrence of the error. + /// + [DataMember(Order = 4, Name = "detail"), JsonPropertyName("detail"), JsonPropertyOrder(4), YamlMember(Alias = "detail", Order = 4)] + public virtual string? Detail { get; set; } + + /// + /// Gets/sets a reference that identifies the specific occurrence of the error.It may or may not yield further information if dereferenced. + /// + [DataMember(Order = 5, Name = "instance"), JsonPropertyName("instance"), JsonPropertyOrder(5), YamlMember(Alias = "instance", Order = 5)] + public virtual string? Instance { get; set; } + + /// + /// Gets/sets a mapping containing error details extension data, if any + /// + [DataMember(Order = 6, Name = "extensionData"), JsonExtensionData] + public virtual IDictionary? ExtensionData { get; set; } + +} \ No newline at end of file diff --git a/src/ServerlessWorkflow.Sdk/Models/ErrorFilterDefinition.cs b/src/ServerlessWorkflow.Sdk/Models/ErrorFilterDefinition.cs new file mode 100644 index 0000000..e6bd81a --- /dev/null +++ b/src/ServerlessWorkflow.Sdk/Models/ErrorFilterDefinition.cs @@ -0,0 +1,29 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Models; + +/// +/// Represents the definition an an error filter +/// +[DataContract] +public record ErrorFilterDefinition +{ + + /// + /// Gets/sets a key/value mapping of the properties errors to filter must define + /// + [DataMember(Name = "with", Order = 1), JsonPropertyName("with"), JsonPropertyOrder(1), YamlMember(Alias = "with", Order = 1)] + public virtual EquatableDictionary? With { get; set; } + +} diff --git a/src/ServerlessWorkflow.Sdk/Models/ErrorHandlerDefinition.cs b/src/ServerlessWorkflow.Sdk/Models/ErrorHandlerDefinition.cs deleted file mode 100644 index b300d25..0000000 --- a/src/ServerlessWorkflow.Sdk/Models/ErrorHandlerDefinition.cs +++ /dev/null @@ -1,97 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace ServerlessWorkflow.Sdk.Models; - -/// -/// Represents the definition of an error handler -/// -[DataContract] -public class ErrorHandlerDefinition - : IExtensible -{ - - /// - /// Gets/sets a domain-specific error name, or '*' to indicate all possible errors. If other handlers are declared, the will only be considered on errors that have NOT been handled by any other. - /// - [Required, MinLength(1)] - [DataMember(Order = 1, Name = "error"), JsonPropertyOrder(1), JsonPropertyName("error"), YamlMember(Alias = "error", Order = 1)] - public virtual string Error { get; set; } = null!; - - /// - /// Gets/sets the error code. Can be used in addition to the name to help runtimes resolve to technical errors/exceptions. Should not be defined if error is set to '*'. - /// - [DataMember(Order = 2, Name = "code"), JsonPropertyOrder(2), JsonPropertyName("code"), YamlMember(Alias = "code", Order = 2)] - public virtual string? Code { get; set; } - - /// - /// Gets/sets a reference to the to use - /// - [DataMember(Order = 3, Name = "retryRef"), JsonPropertyOrder(3), JsonPropertyName("retryRef"), YamlMember(Alias = "retryRef", Order = 3)] - public virtual string? RetryRef { get; set; } = null!; - - /// - /// Gets/sets the object that represents the 's - /// - [DataMember(Order = 4, Name = "transition"), JsonPropertyOrder(4), JsonPropertyName("transition"), YamlMember(Alias = "transition", Order = 4)] - protected virtual OneOf? TransitionValue { get; set; } - - /// - /// Gets/sets the object used to configure the state definition's transition to another state definition upon completion - /// - [IgnoreDataMember, JsonIgnore, YamlIgnore] - public virtual TransitionDefinition? Transition - { - get - { - if (this.TransitionValue?.T1Value == null && !string.IsNullOrWhiteSpace(this.TransitionValue?.T2Value)) return new() { NextState = this.TransitionValue.T2Value }; - else return this.TransitionValue?.T1Value; - } - set - { - if (value == null) this.TransitionValue = null; - else this.TransitionValue = value; - } - } - - /// - /// Gets/sets the name of the state definition to transition to upon completion - /// - [IgnoreDataMember, JsonIgnore, YamlIgnore] - public virtual string? TransitionToStateName - { - get - { - return this.TransitionValue?.T2Value; - } - set - { - if (value == null) this.TransitionValue = null; - else this.TransitionValue = value; - } - } - - /// - /// Gets/sets the object that represents the 's - /// - [DataMember(Order = 5, Name = "end"), JsonPropertyOrder(5), JsonPropertyName("end"), YamlMember(Alias = "end", Order = 5)] - public virtual object? End { get; set; } - - /// - [DataMember(Order = 6, Name = "extensionData"), JsonExtensionData] - public IDictionary? ExtensionData { get; set; } - - /// - public override string ToString() => $"{this.Error}{(string.IsNullOrWhiteSpace(this.Code) ? string.Empty : $" (code: '{this.Code}')")}"; - -} diff --git a/src/ServerlessWorkflow.Sdk/Models/EventConsumptionStrategyDefinition.cs b/src/ServerlessWorkflow.Sdk/Models/EventConsumptionStrategyDefinition.cs new file mode 100644 index 0000000..145ebce --- /dev/null +++ b/src/ServerlessWorkflow.Sdk/Models/EventConsumptionStrategyDefinition.cs @@ -0,0 +1,41 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Models; + +/// +/// Represents the configuration of an event consumption strategy +/// +[DataContract] +public record EventConsumptionStrategyDefinition +{ + + /// + /// Gets/sets a list containing all the events that must be consumed, if any + /// + [DataMember(Name = "all", Order = 1), JsonPropertyName("all"), JsonPropertyOrder(1), YamlMember(Alias = "all", Order = 1)] + public virtual EquatableList? All { get; set; } + + /// + /// Gets/sets a list containing any of the events to consume, if any + /// + [DataMember(Name = "any", Order = 2), JsonPropertyName("any"), JsonPropertyOrder(2), YamlMember(Alias = "any", Order = 2)] + public virtual EquatableList? Any { get; set; } + + /// + /// Gets/sets the single event to consume + /// + [DataMember(Name = "one", Order = 3), JsonPropertyName("one"), JsonPropertyOrder(3), YamlMember(Alias = "one", Order = 3)] + public virtual EventFilterDefinition? One { get; set; } + +} diff --git a/src/ServerlessWorkflow.Sdk/Models/EventCorrelationDefinition.cs b/src/ServerlessWorkflow.Sdk/Models/EventCorrelationDefinition.cs deleted file mode 100644 index 3cafe71..0000000 --- a/src/ServerlessWorkflow.Sdk/Models/EventCorrelationDefinition.cs +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace ServerlessWorkflow.Sdk.Models; - -/// -/// Represents an object used to define the way to correlate a cloud event -/// -[DataContract] -public class EventCorrelationDefinition - : IExtensible -{ - - /// - /// Initializes a new - /// - public EventCorrelationDefinition() { } - - /// - /// Initializes a new - /// - /// The name of the cloud event extension attribute to correlate events by - /// The value of the cloud event extension attribute to correlate events by - public EventCorrelationDefinition(string attributeName, string attributeValue) - { - if(string.IsNullOrWhiteSpace(attributeName)) throw new ArgumentNullException(nameof(attributeName)); - if (string.IsNullOrWhiteSpace(attributeValue)) throw new ArgumentNullException(nameof(attributeValue)); - this.ContextAttributeName = attributeName; - this.ContextAttributeValue = attributeValue; - } - - /// - /// Gets/sets the name of the cloud event extension attribute to correlate events by - /// - [Required] - [DataMember(Order = 1, Name = "contextAttributeName", IsRequired = true), JsonPropertyName("contextAttributeName"), YamlMember(Alias = "contextAttributeName")] - public virtual string ContextAttributeName { get; set; } = null!; - - /// - /// Gets/sets the value of the cloud event extension attribute to correlate events by - /// - [DataMember(Order = 2, Name = "contextAttributeValue", IsRequired = true), JsonPropertyName("contextAttributeValue"), YamlMember(Alias = "contextAttributeValue")] - public virtual string? ContextAttributeValue { get; set; } - - /// - /// Gets/sets an containing the 's extension properties - /// - [DataMember(Order = 3, Name = "extensionData"), JsonExtensionData] - public virtual IDictionary? ExtensionData { get; set; } - -} \ No newline at end of file diff --git a/src/ServerlessWorkflow.Sdk/Models/EventDataFilterDefinition.cs b/src/ServerlessWorkflow.Sdk/Models/EventDataFilterDefinition.cs deleted file mode 100644 index c05b8f2..0000000 --- a/src/ServerlessWorkflow.Sdk/Models/EventDataFilterDefinition.cs +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace ServerlessWorkflow.Sdk.Models; - - -/// -/// Represents an object used to configure how event data is to be filtered and added to or merged with the state data -/// -[DataContract] -public class EventDataFilterDefinition -{ - - /// - /// Gets/sets an expression that filters the event data (payload) - /// - [DataMember(Order = 1, Name = "data"), JsonPropertyOrder(1), JsonPropertyName("data"), YamlMember(Alias = "data", Order = 1)] - public virtual string? Data { get; set; } - - /// - /// Gets/sets an expression that selects a state data element to which the action results should be added/merged into. If not specified denotes the top-level state data element - /// - [DataMember(Order = 2, Name = "toStateData"), JsonPropertyOrder(2), JsonPropertyName("toStateData"), YamlMember(Alias = "toStateData", Order = 2)] - public virtual string? ToStateData { get; set; } - - /// - /// Gets/sets a boolean indicating whether or not to merge the event's data into state data. If set to false, action data results are not added/merged to state data. In this case 'data' and 'toStateData' should be ignored. Defaults to true. - /// - [DefaultValue(true)] - [DataMember(Order = 3, Name = "useData"), JsonPropertyOrder(3), JsonPropertyName("useData"), YamlMember(Alias = "useData", Order = 3)] - public virtual bool UseData { get; set; } = true; - -} \ No newline at end of file diff --git a/src/ServerlessWorkflow.Sdk/Models/EventDefinition.cs b/src/ServerlessWorkflow.Sdk/Models/EventDefinition.cs index f04fcd3..3803add 100644 --- a/src/ServerlessWorkflow.Sdk/Models/EventDefinition.cs +++ b/src/ServerlessWorkflow.Sdk/Models/EventDefinition.cs @@ -1,4 +1,4 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors +// Copyright © 2024-Present The Serverless Workflow Specification Authors // // Licensed under the Apache License, Version 2.0 (the "License"), // you may not use this file except in compliance with the License. @@ -14,66 +14,17 @@ namespace ServerlessWorkflow.Sdk.Models; /// -/// Represents an object used to define events and their correlations +/// Represents the definition of an event /// [DataContract] -public class EventDefinition - : IMetadata, IExtensible +public record EventDefinition { /// - /// Gets/sets the Unique event name + /// Gets/sets a key/value mapping of the attributes of the configured event /// - [Required, MinLength(1)] - [DataMember(Order = 1, Name = "name", IsRequired = true), JsonPropertyOrder(1), JsonPropertyName("name"), YamlMember(Alias = "name", Order = 1)] - public virtual string Name { get; set; } = null!; + [Required] + [DataMember(Name = "with", Order = 2), JsonPropertyName("with"), JsonPropertyOrder(2), YamlMember(Alias = "with", Order = 2)] + public required virtual EquatableDictionary With { get; set; } - /// - /// Gets/sets the cloud event source - /// - [DataMember(Order = 2, Name = "source"), JsonPropertyOrder(2), JsonPropertyName("source"), YamlMember(Alias = "source", Order = 2)] - public virtual Uri? Source { get; set; } - - /// - /// Gets/sets the cloud event type - /// - [DataMember(Order = 3, Name = "type"), JsonPropertyOrder(3), JsonPropertyName("type"), YamlMember(Alias = "type", Order = 3)] - public virtual string? Type { get; set; } = null!; - - /// - /// Gets/sets a value that defines the CloudEvent as either '' or '' by the workflow. Default is ''. - /// - [DefaultValue(EventKind.Consumed)] - [DataMember(Order = 4, Name = "kind"), JsonPropertyOrder(4), JsonPropertyName("kind"), YamlMember(Alias = "kind", Order = 4)] - public virtual string Kind { get; set; } = EventKind.Consumed; - - /// - /// Gets/sets anlist containing the s used to define the way the cloud event is correlated - /// - [DataMember(Order = 5, Name = "correlation"), JsonPropertyOrder(5), JsonPropertyName("correlation"), YamlMember(Alias = "correlation", Order = 5)] - public virtual List? Correlations { get; set; } - - /// - /// Gets/sets a boolean indicating whether or not to use the event's data only (thus making data the top level element, instead of including all context attributes at top level). Defaults to true. - /// - [DefaultValue(true)] - [DataMember(Order = 6, Name = "dataOnly"), JsonPropertyOrder(6), JsonPropertyName("dataOnly"), YamlMember(Alias = "dataOnly", Order = 6)] - - public virtual bool DataOnly { get; set; } = true; - - /// - /// Gets/sets the 's metadata - /// - [DataMember(Order = 7, Name = "metadata"), JsonPropertyOrder(7), JsonPropertyName("metadata"), YamlMember(Alias = "metadata", Order = 7)] - public virtual DynamicMapping? Metadata { get; set; } - - /// - /// Gets/sets an containing the 's extension properties - /// - [DataMember(Order = 8, Name = "extensionData"), JsonExtensionData] - public virtual IDictionary? ExtensionData { get; set; } - - /// - public override string ToString() => this.Name; - -} +} \ No newline at end of file diff --git a/src/ServerlessWorkflow.Sdk/Models/EventEmissionDefinition.cs b/src/ServerlessWorkflow.Sdk/Models/EventEmissionDefinition.cs new file mode 100644 index 0000000..955d17d --- /dev/null +++ b/src/ServerlessWorkflow.Sdk/Models/EventEmissionDefinition.cs @@ -0,0 +1,30 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Models; + +/// +/// Represents the configuration of an event's emission +/// +[DataContract] +public record EventEmissionDefinition +{ + + /// + /// Gets/sets the definition of the event to emit + /// + [Required] + [DataMember(Name = "event", Order = 1), JsonPropertyName("event"), JsonPropertyOrder(1), YamlMember(Alias = "event", Order = 1)] + public required virtual EventDefinition Event { get; set; } + +} diff --git a/src/ServerlessWorkflow.Sdk/Models/EventFilterDefinition.cs b/src/ServerlessWorkflow.Sdk/Models/EventFilterDefinition.cs new file mode 100644 index 0000000..8429f6e --- /dev/null +++ b/src/ServerlessWorkflow.Sdk/Models/EventFilterDefinition.cs @@ -0,0 +1,35 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Models; + +/// +/// Represents the configuration of an event filter +/// +[DataContract] +public record EventFilterDefinition +{ + + /// + /// Gets/sets a name/value mapping of the attributes filtered events must define. Supports both regular expressions and runtime expressions. + /// + [DataMember(Name = "with", Order = 1), JsonPropertyName("with"), JsonPropertyOrder(1), YamlMember(Alias = "with", Order = 1)] + public virtual EquatableDictionary? With { get; set; } + + /// + /// Gets/sets a name/definition mapping of the correlation to attempt when filtering events. + /// + [DataMember(Name = "correlate", Order = 2), JsonPropertyName("correlate"), JsonPropertyOrder(2), YamlMember(Alias = "correlate", Order = 2)] + public virtual EquatableDictionary? Correlate { get; set; } + +} diff --git a/src/ServerlessWorkflow.Sdk/Models/EventReference.cs b/src/ServerlessWorkflow.Sdk/Models/EventReference.cs deleted file mode 100644 index 537fdd0..0000000 --- a/src/ServerlessWorkflow.Sdk/Models/EventReference.cs +++ /dev/null @@ -1,117 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace ServerlessWorkflow.Sdk.Models; - -/// -/// Represents a reference to an -/// -[DataContract] -public class EventReference - : IExtensible -{ - - /// - /// Gets the name of the event to produce - /// - [Required, MinLength(1)] - [DataMember(Order = 1, Name = "triggerEventRef", IsRequired = true), JsonPropertyOrder(1), JsonPropertyName("triggerEventRef"), YamlMember(Alias = "triggerEventRef", Order = 1)] - public virtual string TriggerEventRef { get; set; } = null!; - - /// - /// Gets the name of the event to consume - /// - [DataMember(Order = 2, Name = "resultEventRef"), JsonPropertyOrder(2), JsonPropertyName("resultEventRef"), YamlMember(Alias = "resultEventRef", Order = 2)] - public virtual string? ResultEventRef { get; set; } - - /// - /// Gets/sets the data to become the cloud event's payload. - /// If string type, an expression which selects parts of the states data output to become the data (payload) of the event referenced by ''. - /// If object type, a custom object to become the data (payload) of the event referenced by ''. - /// - [DataMember(Order = 3, Name = "data"), JsonPropertyOrder(3), JsonPropertyName("data"), YamlMember(Alias = "data", Order = 3)] - [JsonConverter(typeof(OneOfConverter, string>))] - protected virtual OneOf, string>? DataValue { get; set; } - - /// - /// Gets/sets a custom object to become the data (payload) of the event referenced by the 'triggerEventRef' - /// - [IgnoreDataMember, JsonIgnore, YamlIgnore] - public virtual IDictionary? Data - { - get - { - return this.DataValue?.T1Value; - } - set - { - if (value == null) - this.DataValue = null; - else - this.DataValue = new(value); - } - } - - /// - /// Gets/sets an expression which selects parts of the states data output to become the data (payload) of the event referenced by 'triggerEventRef' - /// - [IgnoreDataMember, JsonIgnore, YamlIgnore] - public virtual string? DataExpression - { - get - { - return this.DataValue?.T2Value; - } - set - { - if (value == null) - this.DataValue = null; - else - this.DataValue = value; - } - } - - /// - /// Gets/sets additional extension context attributes to the produced event - /// - [DataMember(Order = 4, Name = "contextAttributes"), JsonPropertyOrder(4), JsonPropertyName("contextAttributes"), YamlMember(Alias = "contextAttributes", Order = 4)] - public virtual IDictionary? ContextAttributes { get; set; } - - /// - /// Gets the maximum amount of time to wait for the result event. If not defined it be set to the actionExecutionTimeout - /// - [DataMember(Order = 5, Name = "consumeEventTimeout"), JsonPropertyOrder(5), JsonPropertyName("consumeEventTimeout"), YamlMember(Alias = "consumeEventTimeout", Order = 5)] - [JsonConverter(typeof(Iso8601NullableTimeSpanConverter))] - public virtual TimeSpan? ConsumeEventTimeout { get; set; } - - /// - /// Gets/sets the reference event's 'InvocationMode'. Default is 'InvocationMode.Synchronous'. - /// - /// - /// Default value of this property is sync, meaning that workflow execution should wait until the function completes (the result event is received). - /// If set to async, workflow execution should just produce the trigger event and should not wait for the result event - /// - [DefaultValue(Sdk.InvocationMode.Synchronous)] - [DataMember(Order = 6, Name = "invoke"), JsonPropertyOrder(6), JsonPropertyName("invoke"), YamlMember(Alias = "invoke", Order = 6)] - public virtual string InvocationMode { get; set; } = Sdk.InvocationMode.Synchronous; - - /// - /// Gets/sets an containing the 's extension properties - /// - [DataMember(Order = 7, Name = "extensionData"), JsonExtensionData] - public virtual IDictionary? ExtensionData { get; set; } - - /// - public override string ToString() => $"[{this.TriggerEventRef}] => [{this.ResultEventRef}]"; - -} \ No newline at end of file diff --git a/src/ServerlessWorkflow.Sdk/Models/EventStateTriggerDefinition.cs b/src/ServerlessWorkflow.Sdk/Models/EventStateTriggerDefinition.cs deleted file mode 100644 index cd6fd3a..0000000 --- a/src/ServerlessWorkflow.Sdk/Models/EventStateTriggerDefinition.cs +++ /dev/null @@ -1,85 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace ServerlessWorkflow.Sdk.Models; - -/// -/// Represents the definition of an 's trigger -/// -[DataContract] -public class EventStateTriggerDefinition -{ - - /// - /// Gets/sets an containing the references one or more unique event names in the defined workflow events - /// - [Required, MinLength(1)] - [DataMember(Order = 1, Name = "eventRefs", IsRequired = true), JsonPropertyOrder(1), JsonPropertyName("eventRefs"), YamlMember(Alias = "eventRefs", Order = 1)] - public virtual List EventRefs { get; set; } = new List(); - - /// - /// Gets/sets a value that specifies how actions are to be performed (in sequence of parallel) - /// - [DataMember(Order = 2, Name = "actionMode"), JsonPropertyOrder(2), JsonPropertyName("actionMode"), YamlMember(Alias = "actionMode", Order = 2)] - public virtual string ActionMode { get; set; } = ActionExecutionMode.Sequential; - - /// - /// Gets/sets an containing the actions to be performed if expression matches - /// - [DataMember(Order = 3, Name = "actions"), JsonPropertyOrder(3), JsonPropertyName("actions"), YamlMember(Alias = "actions", Order = 3)] - public virtual List Actions { get; set; } = new List(); - - /// - /// Gets/sets an object used to filter the event data - /// - [DataMember(Order = 4, Name = "eventDataFilter"), JsonPropertyOrder(4), JsonPropertyName("eventDataFilter"), YamlMember(Alias = "eventDataFilter", Order = 4)] - public virtual EventDataFilterDefinition EventDataFilter { get; set; } = new EventDataFilterDefinition(); - - /// - /// Gets the with the specified name - /// - /// The name of the to get - /// The with the specified name - public virtual ActionDefinition? GetAction(string name) => this.Actions.FirstOrDefault(s => s.Name == name); - - /// - /// Attempts to get the with the specified name - /// - /// The name of the to get - /// The with the specified name - /// A boolean indicating whether or not a with the specified name could be found - public virtual bool TryGetAction(string name, out ActionDefinition action) - { - action = this.GetAction(name)!; - return action != null; - } - - /// - /// Attempts to get the next in the pipeline - /// - /// The name of the to get the next for - /// The next , if any - /// A boolean indicating whether or not there is a next in the pipeline - public virtual bool TryGetNextAction(string previousActionName, out ActionDefinition action) - { - action = null!; - var previousAction = this.Actions.FirstOrDefault(a => a.Name == previousActionName); - if (previousAction == null) return false; - var previousActionIndex = this.Actions.ToList().IndexOf(previousAction); - var nextIndex = previousActionIndex + 1; - if (nextIndex >= this.Actions.Count) return false; - action = this.Actions.ElementAt(nextIndex); - return true; - } - -} diff --git a/src/ServerlessWorkflow.Sdk/Models/ExponentialBackoffDefinition.cs b/src/ServerlessWorkflow.Sdk/Models/ExponentialBackoffDefinition.cs new file mode 100644 index 0000000..4d5e6eb --- /dev/null +++ b/src/ServerlessWorkflow.Sdk/Models/ExponentialBackoffDefinition.cs @@ -0,0 +1,26 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Models; + +/// +/// Represents the definition of an exponential backoff +/// +[DataContract] +public record ExponentialBackoffDefinition + : BackoffDefinition +{ + + + +} diff --git a/src/ServerlessWorkflow.Sdk/Models/Extendable.cs b/src/ServerlessWorkflow.Sdk/Models/Extendable.cs new file mode 100644 index 0000000..38cc78e --- /dev/null +++ b/src/ServerlessWorkflow.Sdk/Models/Extendable.cs @@ -0,0 +1,29 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Models; + +/// +/// Represents the base class of extendable objects +/// +public abstract record Extendable + : IExtendable +{ + + /// + /// Gets/sets a key/value mapping of the object's extension data, if any + /// + [DataMember(Name = "extensions", Order = 99), JsonPropertyName("extensions"), JsonPropertyOrder(99), YamlMember(Alias = "extensions", Order = 99)] + public virtual EquatableDictionary? Extensions { get; set; } + +} diff --git a/src/ServerlessWorkflow.Sdk/Models/ExtensionDefinition.cs b/src/ServerlessWorkflow.Sdk/Models/ExtensionDefinition.cs index c833f65..5f723e8 100644 --- a/src/ServerlessWorkflow.Sdk/Models/ExtensionDefinition.cs +++ b/src/ServerlessWorkflow.Sdk/Models/ExtensionDefinition.cs @@ -1,4 +1,4 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors +// Copyright © 2024-Present The Serverless Workflow Specification Authors // // Licensed under the Apache License, Version 2.0 (the "License"), // you may not use this file except in compliance with the License. @@ -14,45 +14,36 @@ namespace ServerlessWorkflow.Sdk.Models; /// -/// Represents the definition of a Serverless Workflow extension +/// Represents the definition of a an extension /// [DataContract] -public class ExtensionDefinition - : IExtensible +public record ExtensionDefinition + : Extendable { /// - /// Initializes a new + /// Gets/sets the type of task to extend /// - public ExtensionDefinition() { } + [Required] + [DataMember(Name = "extend", Order = 1), JsonPropertyName("extend"), JsonPropertyOrder(1), YamlMember(Alias = "extend", Order = 1)] + public required virtual string Extend { get; set; } /// - /// Initializes a new + /// Gets/sets a runtime expression, if any, used to determine whether or not the extension should apply in the specified context /// - /// The id that uniquely identifies the extension to import - /// The uri that references the extension resource - public ExtensionDefinition(string extensionId, Uri resource) - { - if(string.IsNullOrWhiteSpace(extensionId)) throw new ArgumentNullException(nameof(extensionId)); - this.ExtensionId = extensionId; - this.Resource = resource ?? throw new ArgumentNullException(nameof(resource)); - } + [DataMember(Name = "when", Order = 2), JsonPropertyName("when"), JsonPropertyOrder(2), YamlMember(Alias = "when", Order = 2)] + public virtual string? When { get; set; } /// - /// Gets/sets the extension's unique id + /// Gets/sets the task to execute before the extended task, if any /// - [Required, MinLength(1)] - [DataMember(Order = 1, Name = "extensionId", IsRequired = true), JsonPropertyName("extensionsId"), YamlMember(Alias = "extensionId")] - public virtual string ExtensionId { get; set; } = null!; + [DataMember(Name = "before", Order = 3), JsonPropertyName("before"), JsonPropertyOrder(3), YamlMember(Alias = "before", Order = 3)] + public virtual TaskDefinition? Before { get; set; } /// - /// Gets/sets an uri to a resource containing the workflow extension definition (json or yaml) + /// Gets/sets the task to execute after the extended task, if any /// - [DataMember(Order = 2, Name = "resource", IsRequired = true), JsonPropertyName("resource"), YamlMember(Alias = "resource")] - public virtual Uri Resource { get; set; } = null!; + [DataMember(Name = "after", Order = 4), JsonPropertyName("after"), JsonPropertyOrder(4), YamlMember(Alias = "after", Order = 4)] + public virtual TaskDefinition? After { get; set; } - /// - [DataMember(Order = 3, Name = "extensionData"), JsonExtensionData] - public IDictionary? ExtensionData { get; set; } - -} +} \ No newline at end of file diff --git a/src/ServerlessWorkflow.Sdk/Models/ExternalDefinitionCollection.cs b/src/ServerlessWorkflow.Sdk/Models/ExternalDefinitionCollection.cs deleted file mode 100644 index 8ce42ea..0000000 --- a/src/ServerlessWorkflow.Sdk/Models/ExternalDefinitionCollection.cs +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace ServerlessWorkflow.Sdk.Models; - -/// -/// Represents a that can be loaded from an external definition file -/// -/// The type of elements contained by the -public class ExternalDefinitionCollection - : List -{ - - /// - /// Initializes a new - /// - public ExternalDefinitionCollection() - : base() - { - this.DefinitionUri = null!; - this.Loaded = true; - } - - /// - /// Initializes a new - /// - /// The collection whose elements are copied into the - public ExternalDefinitionCollection(IEnumerable collection) - : base(collection) - { - this.DefinitionUri = null!; - this.Loaded = true; - } - - /// - /// Initializes a new - /// - /// The used to reference the file that defines the elements contained by the - public ExternalDefinitionCollection(Uri definitionUri) - : base() - { - this.DefinitionUri = definitionUri; - this.Loaded = false; - } - - /// - /// Gets the used to reference the file that defines the elements contained by the - /// - public virtual Uri DefinitionUri { get; private set; } - - /// - /// Gets a boolean indicating whether or not the has been loaded - /// - public virtual bool Loaded { get; } - -} diff --git a/src/ServerlessWorkflow.Sdk/Models/ExternalResourceDefinition.cs b/src/ServerlessWorkflow.Sdk/Models/ExternalResourceDefinition.cs new file mode 100644 index 0000000..f3e077f --- /dev/null +++ b/src/ServerlessWorkflow.Sdk/Models/ExternalResourceDefinition.cs @@ -0,0 +1,31 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Models; + +/// +/// Represents the definition of an external resource +/// +[DataContract] +public record ExternalResourceDefinition + : EndpointDefinition +{ + + /// + /// Gets/sets the external resource's name, if any + /// + [Required] + [DataMember(Name = "name", Order = 1), JsonPropertyName("name"), JsonPropertyOrder(1), YamlMember(Alias = "name", Order = 1)] + public virtual string? Name { get; set; } + +} \ No newline at end of file diff --git a/src/ServerlessWorkflow.Sdk/Models/ForLoopDefinition.cs b/src/ServerlessWorkflow.Sdk/Models/ForLoopDefinition.cs new file mode 100644 index 0000000..c82e7b1 --- /dev/null +++ b/src/ServerlessWorkflow.Sdk/Models/ForLoopDefinition.cs @@ -0,0 +1,48 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Models; + +/// +/// Represents the definition of a loop that iterates over a range of values +/// +[DataContract] +public record ForLoopDefinition +{ + + /// + /// Gets/sets the name of the variable that represents each element in the collection during iteration + /// + [Required] + [DataMember(Name = "each", Order = 1), JsonPropertyName("each"), JsonPropertyOrder(1), YamlMember(Alias = "each", Order = 1)] + public required virtual string Each { get; set; } + + /// + /// Gets/sets the runtime expression used to get the collection to iterate over + /// + [DataMember(Name = "in", Order = 2), JsonPropertyName("in"), JsonPropertyOrder(2), YamlMember(Alias = "in", Order = 2)] + public required virtual string In { get; set; } + + /// + /// Gets/sets the name of the variable used to hold the index of each element in the collection during iteration + /// + [DataMember(Name = "at", Order = 3), JsonPropertyName("at"), JsonPropertyOrder(3), YamlMember(Alias = "at", Order = 3)] + public virtual string? At { get; set; } + + /// + /// Gets/sets the definition of the data, if any, to pass to iterations to run + /// + [DataMember(Name = "input", Order = 4), JsonPropertyName("input"), JsonPropertyOrder(4), YamlMember(Alias = "input", Order = 4)] + public virtual InputDataModelDefinition? Input { get; set; } + +} diff --git a/src/ServerlessWorkflow.Sdk/Models/FunctionDefinition.cs b/src/ServerlessWorkflow.Sdk/Models/FunctionDefinition.cs deleted file mode 100644 index 9cecf1d..0000000 --- a/src/ServerlessWorkflow.Sdk/Models/FunctionDefinition.cs +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace ServerlessWorkflow.Sdk.Models; - -/// -/// Represents an object used to define a reusable function -/// -[DataContract] -public class FunctionDefinition - : IMetadata, IExtensible -{ - - /// - /// Gets/sets a unique function name - /// - [Required, MinLength(1)] - [DataMember(Order = 1, Name = "name", IsRequired = true), JsonPropertyName("name"), YamlMember(Alias = "name")] - public virtual string Name { get; set; } = null!; - - /// - /// Gets/sets the operation. If type '', combination of the function/service OpenAPI definition URI and the operationID of the operation that needs to be invoked, separated by a '#'. - /// If type is `` defines the workflow expression. - /// - [Required, MinLength(1)] - [DataMember(Order = 2, Name = "operation", IsRequired = true), JsonPropertyName("operation"), YamlMember(Alias = "operation")] - public virtual string Operation { get; set; } = null!; - - /// - /// Gets/sets the type of the defined function. Defaults to '' - /// - [DataMember(Order = 3, Name = "type", IsRequired = true), JsonPropertyName("type"), YamlMember(Alias = "type")] - public virtual string Type { get; set; } = FunctionType.Rest; - - /// - /// Gets/sets the reference to the authentication definition to use when invoking the function. Ignored when has been set to - /// - [DataMember(Order = 4, Name = "authRef", IsRequired = true), JsonPropertyName("authRef"), YamlMember(Alias = "authRef")] - public virtual string? AuthRef { get; set; } - - /// - /// Gets/sets the function's metadata - /// - [DataMember(Order = 5, Name = "metadata", IsRequired = true), JsonPropertyName("metadata"), YamlMember(Alias = "metadata")] - public virtual DynamicMapping? Metadata { get; set; } - - /// - /// Gets/sets an containing the 's extension properties - /// - [DataMember(Order = 6, Name = "extensionData"), JsonExtensionData] - public virtual IDictionary? ExtensionData { get; set; } - - /// - public override string ToString() => this.Name; - -} diff --git a/src/ServerlessWorkflow.Sdk/Models/FunctionReference.cs b/src/ServerlessWorkflow.Sdk/Models/FunctionReference.cs deleted file mode 100644 index 15d5a72..0000000 --- a/src/ServerlessWorkflow.Sdk/Models/FunctionReference.cs +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace ServerlessWorkflow.Sdk.Models; - -/// -/// Represents a reference to a -/// -[DataContract] -public class FunctionReference - : IExtensible -{ - - /// - /// Gets/sets the referenced function's name - /// - [Required, MinLength(1)] - [DataMember(Order = 1, Name = "refName", IsRequired = true), JsonPropertyOrder(1), JsonPropertyName("refName"), YamlMember(Alias = "refName", Order = 1)] - public virtual string RefName { get; set; } = null!; - - /// - /// Gets/sets a name/value mapping of the parameters to invoke the configured function with - /// - [DataMember(Order = 2, Name = "arguments"), JsonPropertyOrder(2), JsonPropertyName("arguments"), YamlMember(Alias = "arguments", Order = 2)] - public virtual IDictionary? Arguments { get; set; } - - /// - /// Gets/sets a GraphQL selection set - /// - [DataMember(Order = 3, Name = "selectionSet"), JsonPropertyOrder(3), JsonPropertyName("selectionSet"), YamlMember(Alias = "selectionSet", Order = 3)] - public virtual string? SelectionSet { get; set; } - - /// - /// Gets/sets an containing the 's extension properties - /// - [DataMember(Order = 4, Name = "extensionData"), JsonExtensionData] - public virtual IDictionary? ExtensionData { get; set; } - - /// - public override string ToString() => this.RefName; - -} \ No newline at end of file diff --git a/src/ServerlessWorkflow.Sdk/Models/GrpcServiceDefinition.cs b/src/ServerlessWorkflow.Sdk/Models/GrpcServiceDefinition.cs new file mode 100644 index 0000000..6d32078 --- /dev/null +++ b/src/ServerlessWorkflow.Sdk/Models/GrpcServiceDefinition.cs @@ -0,0 +1,49 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Models; + +/// +/// Represents the definition of a GRPC service +/// +[DataContract] +public record GrpcServiceDefinition +{ + + /// + /// Gets/sets the GRPC service name + /// + [Required, MinLength(1)] + [DataMember(Name = "name", Order = 1), JsonPropertyName("name"), JsonPropertyOrder(1), YamlMember(Alias = "name", Order = 1)] + public required virtual string Name { get; set; } + + /// + /// Gets/sets the hostname of the GRPC service to call + /// + [Required, MinLength(1)] + [DataMember(Name = "host", Order = 2), JsonPropertyName("host"), JsonPropertyOrder(2), YamlMember(Alias = "host", Order = 2)] + public required virtual string Host { get; set; } + + /// + /// Gets/sets the port number of the GRPC service to call + /// + [DataMember(Name = "port", Order = 3), JsonPropertyName("port"), JsonPropertyOrder(3), YamlMember(Alias = "port", Order = 3)] + public virtual int? Port { get; set; } + + /// + /// Gets/sets the endpoint's authentication policy, if any + /// + [DataMember(Name = "authentication", Order = 4), JsonPropertyName("authentication"), JsonPropertyOrder(4), JsonInclude, YamlMember(Alias = "authentication", Order = 4)] + public virtual AuthenticationPolicyDefinition? Authentication { get; set; } + +} \ No newline at end of file diff --git a/src/ServerlessWorkflow.Sdk/Models/HttpRequest.cs b/src/ServerlessWorkflow.Sdk/Models/HttpRequest.cs new file mode 100644 index 0000000..2b4224b --- /dev/null +++ b/src/ServerlessWorkflow.Sdk/Models/HttpRequest.cs @@ -0,0 +1,49 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Models; + +/// +/// Represents an object used to describe an HTTP request +/// +[DataContract] +public record HttpRequest +{ + + /// + /// Gets/sets the HTTP method of the described request + /// + [Required, MinLength(1)] + [DataMember(Name = "method", Order = 1), JsonPropertyName("method"), JsonPropertyOrder(1), YamlMember(Alias = "method", Order = 1)] + public required virtual string Method { get; set; } + + /// + /// Gets/sets the request URI + /// + [Required] + [DataMember(Name = "uri", Order = 2), JsonPropertyName("uri"), JsonPropertyOrder(2), YamlMember(Alias = "uri", Order = 2)] + public required virtual Uri Uri { get; set; } + + /// + /// Gets/sets the request headers, if any + /// + [DataMember(Name = "headers", Order = 3), JsonPropertyName("headers"), JsonPropertyOrder(3), YamlMember(Alias = "headers", Order = 3)] + public virtual EquatableDictionary? Headers { get; set; } + + /// + /// Gets/sets the request body, if any + /// + [DataMember(Name = "body", Order = 4), JsonPropertyName("body"), JsonPropertyOrder(4), YamlMember(Alias = "body", Order = 4)] + public virtual object? Body { get; set; } + +} diff --git a/src/ServerlessWorkflow.Sdk/Models/HttpResponse.cs b/src/ServerlessWorkflow.Sdk/Models/HttpResponse.cs new file mode 100644 index 0000000..773ff4c --- /dev/null +++ b/src/ServerlessWorkflow.Sdk/Models/HttpResponse.cs @@ -0,0 +1,49 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Models; + +/// +/// Represents an object used to describe an HTTP response +/// +[DataContract] +public record HttpResponse +{ + + /// + /// Gets/sets the HTTP request associated with the HTTP response + /// + [Required] + [DataMember(Name = "request", Order = 1), JsonPropertyName("request"), JsonPropertyOrder(1), YamlMember(Alias = "request", Order = 1)] + public required virtual HttpRequest Request { get; set; } + + /// + /// Gets/sets the HTTP response's status code + /// + [Required] + [DataMember(Name = "statusCode", Order = 2), JsonPropertyName("statusCode"), JsonPropertyOrder(2), YamlMember(Alias = "statusCode", Order = 2)] + public required virtual int StatusCode { get; set; } + + /// + /// Gets/sets the response headers, if any + /// + [DataMember(Name = "headers", Order = 3), JsonPropertyName("headers"), JsonPropertyOrder(3), YamlMember(Alias = "headers", Order = 3)] + public virtual EquatableDictionary? Headers { get; set; } + + /// + /// Gets/sets the HTTP response's content, if any + /// + [DataMember(Name = "content", Order = 4), JsonPropertyName("content"), JsonPropertyOrder(4), YamlMember(Alias = "content", Order = 4)] + public virtual object? Content { get; set; } + +} diff --git a/src/ServerlessWorkflow.Sdk/Models/InputDataModelDefinition.cs b/src/ServerlessWorkflow.Sdk/Models/InputDataModelDefinition.cs new file mode 100644 index 0000000..d2026e9 --- /dev/null +++ b/src/ServerlessWorkflow.Sdk/Models/InputDataModelDefinition.cs @@ -0,0 +1,26 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Models; + +/// +/// Represents the definition of an output data model +/// +[DataContract] +public record InputDataModelDefinition + : DataModelDefinition +{ + + + +} diff --git a/src/ServerlessWorkflow.Sdk/Models/States/SleepStateDefinition.cs b/src/ServerlessWorkflow.Sdk/Models/JitterDefinition.cs similarity index 50% rename from src/ServerlessWorkflow.Sdk/Models/States/SleepStateDefinition.cs rename to src/ServerlessWorkflow.Sdk/Models/JitterDefinition.cs index 1a325c3..861e193 100644 --- a/src/ServerlessWorkflow.Sdk/Models/States/SleepStateDefinition.cs +++ b/src/ServerlessWorkflow.Sdk/Models/JitterDefinition.cs @@ -1,4 +1,4 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors +// Copyright © 2024-Present The Serverless Workflow Specification Authors // // Licensed under the Apache License, Version 2.0 (the "License"), // you may not use this file except in compliance with the License. @@ -11,29 +11,25 @@ // See the License for the specific language governing permissions and // limitations under the License. -using Neuroglia; - namespace ServerlessWorkflow.Sdk.Models; /// -/// Represents a workflow state that waits for a certain amount of time before transitioning to a next state +/// Represents the definition of the parameters that control the randomness or variability of a delay, typically between retry attempts /// [DataContract] -[DiscriminatorValue(StateType.Sleep)] -public class SleepStateDefinition - : StateDefinition +public record JitterDefinition { /// - /// Initializes a new + /// Gets/sets the minimum duration of the jitter range /// - public SleepStateDefinition() : base(StateType.Sleep) { } + [DataMember(Name = "from", Order = 1), JsonPropertyName("from"), JsonPropertyOrder(1), YamlMember(Alias = "from", Order = 1)] + public required virtual Duration From { get; set; } /// - /// Gets/sets the amount of time to delay when in this state + /// Gets/sets the maximum duration of the jitter range /// - [DataMember(Order = 6, Name = "duration"), JsonPropertyOrder(6), JsonPropertyName("duration"), YamlMember(Alias = "duration", Order = 6)] - [JsonConverter(typeof(Iso8601TimeSpanConverter))] - public virtual TimeSpan Duration { get; set; } + [DataMember(Name = "to", Order = 2), JsonPropertyName("to"), JsonPropertyOrder(2), YamlMember(Alias = "to", Order = 2)] + public required virtual Duration To { get; set; } -} \ No newline at end of file +} diff --git a/src/ServerlessWorkflow.Sdk/Models/LinearBackoffDefinition.cs b/src/ServerlessWorkflow.Sdk/Models/LinearBackoffDefinition.cs new file mode 100644 index 0000000..502403d --- /dev/null +++ b/src/ServerlessWorkflow.Sdk/Models/LinearBackoffDefinition.cs @@ -0,0 +1,30 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Models; + +/// +/// Represents the definition of a linear backoff +/// +[DataContract] +public record LinearBackoffDefinition + : BackoffDefinition +{ + + /// + /// Gets/sets the linear incrementation to the delay between retry attempts + /// + [DataMember(Name = "increment", Order = 1), JsonPropertyName("increment"), JsonPropertyOrder(1), YamlMember(Alias = "increment", Order = 1)] + public virtual Duration? Increment { get; set; } + +} diff --git a/src/ServerlessWorkflow.Sdk/Models/ListenerDefinition.cs b/src/ServerlessWorkflow.Sdk/Models/ListenerDefinition.cs new file mode 100644 index 0000000..d90a198 --- /dev/null +++ b/src/ServerlessWorkflow.Sdk/Models/ListenerDefinition.cs @@ -0,0 +1,30 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Models; + +/// +/// Represents the configuration of an event listener +/// +[DataContract] +public record ListenerDefinition +{ + + /// + /// Gets/sets the listener's target + /// + [Required] + [DataMember(Name = "to", Order = 1), JsonPropertyName("to"), JsonPropertyOrder(1), YamlMember(Alias = "to", Order = 1)] + public required virtual EventConsumptionStrategyDefinition To { get; set; } + +} diff --git a/src/ServerlessWorkflow.Sdk/Models/OAuth2AuthenticationProperties.cs b/src/ServerlessWorkflow.Sdk/Models/OAuth2AuthenticationProperties.cs deleted file mode 100644 index a766b2d..0000000 --- a/src/ServerlessWorkflow.Sdk/Models/OAuth2AuthenticationProperties.cs +++ /dev/null @@ -1,246 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace ServerlessWorkflow.Sdk.Models; - -/// -/// Represents an object used to configure an 'OAuth2' authentication scheme -/// -[DataContract] -public class OAuth2AuthenticationProperties - : AuthenticationProperties -{ - - /// - public OAuth2AuthenticationProperties() { } - - /// - public OAuth2AuthenticationProperties(IDictionary properties) : base(properties) { } - - /// - /// Gets/sets the OAuth2 grant type to use - /// - [Required, MinLength(1)] - [IgnoreDataMember, JsonIgnore, YamlIgnore] - public virtual string GrantType - { - get - { - if (this.Properties.TryGetValue(nameof(GrantType).ToCamelCase(), out var value)) return (string)value; - else return null!; - } - set - { - this.Properties[nameof(GrantType).ToCamelCase()] = value; - } - } - - /// - /// Gets/sets the uri of the OAuth2 authority to use to generate an access token - /// - [Required, MinLength(1)] - [IgnoreDataMember, JsonIgnore, YamlIgnore] - public virtual Uri Authority - { - get - { - if (this.Properties.TryGetValue(nameof(Authority).ToCamelCase(), out var value)) return new((string)value); - else return null!; - } - set - { - this.Properties[nameof(Authority).ToCamelCase()] = value.ToString(); - } - } - - /// - /// Gets/sets the id of the OAuth2 client to use - /// - [Required, MinLength(1)] - [IgnoreDataMember, JsonIgnore, YamlIgnore] - public virtual string ClientId - { - get - { - if (this.Properties.TryGetValue(nameof(ClientId).ToCamelCase(), out var value)) return (string)value; - else return null!; - } - set - { - this.Properties[nameof(ClientId).ToCamelCase()] = value; - } - } - - /// - /// Gets/sets the secret of the non-public OAuth2 client to use. Required when has been set to - /// - [IgnoreDataMember, JsonIgnore, YamlIgnore] - public virtual string? ClientSecret - { - get - { - if (this.Properties.TryGetValue(nameof(ClientSecret).ToCamelCase(), out var value)) return (string)value; - else return null!; - } - set - { - if (value == null) this.Properties.Remove(nameof(ClientSecret).ToCamelCase()); - else this.Properties[nameof(ClientSecret).ToCamelCase()] = value; - } - } - - /// - /// Gets/sets the username to use when authenticating - /// - [IgnoreDataMember, JsonIgnore, YamlIgnore] - public virtual string? Username - { - get - { - if (this.Properties.TryGetValue(nameof(Username).ToCamelCase(), out var value)) return (string)value; - else return null!; - } - set - { - if (value == null) this.Properties.Remove(nameof(Username).ToCamelCase()); - else this.Properties[nameof(Username).ToCamelCase()] = value; - } - } - - /// - /// Gets/sets the password to use when authenticating - /// - [IgnoreDataMember, JsonIgnore, YamlIgnore] - public virtual string? Password - { - get - { - if (this.Properties.TryGetValue(nameof(Password).ToCamelCase(), out var value)) return (string)value; - else return null!; - } - set - { - if (value == null) this.Properties.Remove(nameof(Password).ToCamelCase()); - else this.Properties[nameof(Password).ToCamelCase()] = value; - } - } - - /// - /// Gets/sets a space-separated list containing the authorized scopes to request - /// - [IgnoreDataMember, JsonIgnore, YamlIgnore] - public virtual string? Scope - { - get - { - if (this.Properties.TryGetValue(nameof(Scope).ToCamelCase(), out var value)) return (string)value; - else return null!; - } - set - { - if (value == null) this.Properties.Remove(nameof(Scope).ToCamelCase()); - else this.Properties[nameof(Scope).ToCamelCase()] = value; - } - } - - /// - /// Gets/sets a space-separated list containing the authorized audiences of the resulting token - /// - [IgnoreDataMember, JsonIgnore, YamlIgnore] - public virtual string? Audience - { - get - { - if (this.Properties.TryGetValue(nameof(Audience).ToCamelCase(), out var value)) return (string)value; - else return null!; - } - set - { - if (value == null) this.Properties.Remove(nameof(Audience).ToCamelCase()); - else this.Properties[nameof(Audience).ToCamelCase()] = value; - } - } - - /// - /// Gets/sets the token that represents the identity of the party on behalf of whom the request is being made.Typically, the subject of this token will be the subject of the security token issued in response to the request. - /// - [IgnoreDataMember, JsonIgnore, YamlIgnore] - public virtual string? SubjectToken - { - get - { - if (this.Properties.TryGetValue(nameof(SubjectToken).ToCamelCase(), out var value)) return (string)value; - else return null!; - } - set - { - if (value == null) this.Properties.Remove(nameof(SubjectToken).ToCamelCase()); - else this.Properties[nameof(SubjectToken).ToCamelCase()] = value; - } - } - - /// - /// Gets/sets an identifie that indicates the type of the security token in the "subject_token" parameter. - /// - [IgnoreDataMember, JsonIgnore, YamlIgnore] - public virtual string? SubjectTokenType - { - get - { - if (this.Properties.TryGetValue(nameof(SubjectTokenType).ToCamelCase(), out var value)) return (string)value; - else return null!; - } - set - { - if (value == null) this.Properties.Remove(nameof(SubjectTokenType).ToCamelCase()); - else this.Properties[nameof(SubjectTokenType).ToCamelCase()] = value; - } - } - - /// - /// Gets/sets a token that represents the identity of the acting party.Typically, this will be the party that is authorized to use the requested security token and act on behalf of the subject. - /// - [IgnoreDataMember, JsonIgnore, YamlIgnore] - public virtual string? ActorToken - { - get - { - if (this.Properties.TryGetValue(nameof(ActorToken).ToCamelCase(), out var value)) return (string)value; - else return null!; - } - set - { - if (value == null) this.Properties.Remove(nameof(ActorToken).ToCamelCase()); - else this.Properties[nameof(ActorToken).ToCamelCase()] = value; - } - } - - /// - /// Gets/sets an identifier, as described in Section 3, that indicates the type of the security token in the "actor_token" parameter. This is REQUIRED when the "actor_token" parameter is present in the request but MUST NOT be included otherwise. - /// - [IgnoreDataMember, JsonIgnore, YamlIgnore] - public virtual string? ActorTokenType - { - get - { - if (this.Properties.TryGetValue(nameof(ActorTokenType).ToCamelCase(), out var value)) return (string)value; - else return null!; - } - set - { - if (value == null) this.Properties.Remove(nameof(ActorTokenType).ToCamelCase()); - else this.Properties[nameof(ActorTokenType).ToCamelCase()] = value; - } - } - -} diff --git a/src/ServerlessWorkflow.Sdk/Models/OAuth2GrantType.cs b/src/ServerlessWorkflow.Sdk/Models/OAuth2GrantType.cs new file mode 100644 index 0000000..968f122 --- /dev/null +++ b/src/ServerlessWorkflow.Sdk/Models/OAuth2GrantType.cs @@ -0,0 +1,61 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk; + +/// +/// Exposes the default OAUTH2 grant types +/// +public static class OAuth2GrantType +{ + + /// + /// Gets the 'authorization_code' OAUTH2 grant types + /// + public const string AuthorizationCode = "authorization_code"; + /// + /// Gets the 'client_credentials' OAUTH2 grant types + /// + public const string ClientCredentials = "client_credentials"; + /// + /// Gets the 'implicit' OAUTH2 grant types + /// + public const string Implicit = "implicit"; + /// + /// Gets the 'password' OAUTH2 grant types + /// + public const string Password = "password"; + /// + /// Gets the 'refresh_token' OAUTH2 grant types + /// + public const string RefreshToken = "refresh_token"; + /// + /// Gets the 'token_exchange' OAUTH2 grant types + /// + public const string TokenExchange = "urn:ietf:params:oauth:grant-type:token-exchange"; + + /// + /// Gets a new containing the OAUTH2 grant types supported by default + /// + /// A new containing the OAUTH2 grant types supported by default + public static IEnumerable AsEnumerable() + { + yield return AuthorizationCode; + yield return ClientCredentials; + yield return Implicit; + yield return Password; + yield return RefreshToken; + yield return TokenExchange; + } + +} \ No newline at end of file diff --git a/src/ServerlessWorkflow.Sdk/Models/OneOf.cs b/src/ServerlessWorkflow.Sdk/Models/OneOf.cs deleted file mode 100644 index 0bb7f97..0000000 --- a/src/ServerlessWorkflow.Sdk/Models/OneOf.cs +++ /dev/null @@ -1,90 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace ServerlessWorkflow.Sdk.Models; - -/// -/// Represents an object that can be of one of the specified types -/// -/// A first type alternative -/// A second type alternative -[DataContract] -public class OneOf - : IOneOf -{ - - /// - /// Initializes a new - /// - public OneOf() { } - - /// - /// Initializes a new - /// - /// The value of the - public OneOf(T1 value) - : this() - { - this.T1Value = value; - } - - /// - /// Initializes a new - /// - /// The value of the - public OneOf(T2 value) - : this() - { - this.T2Value = value; - } - - /// - /// Gets the first possible value - /// - [DataMember(Order = 1), JsonIgnore, YamlIgnore] - public T1? T1Value { get; set; } - - /// - /// Gets the second possible value - /// - [DataMember(Order = 2), JsonIgnore, YamlIgnore] - public T2? T2Value { get; set; } - - /// - public virtual object? GetValue() => this.T1Value == null ? this.T2Value : this.T1Value; - - /// - /// Implicitly convert the specified value into a new - /// - /// The value to convert - public static implicit operator OneOf(T1 value) => new(value); - - /// - /// Implicitly convert the specified value into a new - /// - /// The value to convert - public static implicit operator OneOf(T2 value) => new(value); - - /// - /// Implicitly convert the specified into a new value - /// - /// The to convert - public static implicit operator T1?(OneOf value) => value.T1Value; - - /// - /// Implicitly convert the specified into a new value - /// - /// The to convert - public static implicit operator T2?(OneOf value) => value.T2Value; - -} diff --git a/src/ServerlessWorkflow.Sdk/Models/EventCaseDefinition.cs b/src/ServerlessWorkflow.Sdk/Models/OutputDataModelDefinition.cs similarity index 57% rename from src/ServerlessWorkflow.Sdk/Models/EventCaseDefinition.cs rename to src/ServerlessWorkflow.Sdk/Models/OutputDataModelDefinition.cs index 5a913f4..35520fd 100644 --- a/src/ServerlessWorkflow.Sdk/Models/EventCaseDefinition.cs +++ b/src/ServerlessWorkflow.Sdk/Models/OutputDataModelDefinition.cs @@ -1,4 +1,4 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors +// Copyright © 2024-Present The Serverless Workflow Specification Authors // // Licensed under the Apache License, Version 2.0 (the "License"), // you may not use this file except in compliance with the License. @@ -14,18 +14,17 @@ namespace ServerlessWorkflow.Sdk.Models; /// -/// Represents the definition of an event-based +/// Represents the definition of an output data model /// [DataContract] -public class EventCaseDefinition - : SwitchCaseDefinition +public record OutputDataModelDefinition + : DataModelDefinition { /// - /// Gets/sets the unique event name the condition applies to + /// Gets/sets a runtime expression, if any, used to output specific data to the scope data /// - [Required, MinLength(1)] - [DataMember(Order = 1, Name = "eventRef", IsRequired = true), JsonPropertyOrder(1), JsonPropertyName("eventRef"), YamlMember(Alias = "eventRef", Order = 1)] - public string EventRef { get; set; } = null!; + [DataMember(Name = "to", Order = 3), JsonPropertyName("to"), JsonPropertyOrder(3), YamlMember(Alias = "to", Order = 3)] + public virtual object? To { get; set; } } \ No newline at end of file diff --git a/src/ServerlessWorkflow.Sdk/Models/ProcessDefinition.cs b/src/ServerlessWorkflow.Sdk/Models/ProcessDefinition.cs new file mode 100644 index 0000000..9a7c7f2 --- /dev/null +++ b/src/ServerlessWorkflow.Sdk/Models/ProcessDefinition.cs @@ -0,0 +1,26 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Models; + +/// +/// Represents the base class for all process definitions +/// +[DataContract] +public abstract record ProcessDefinition + : Extendable +{ + + + +} diff --git a/src/ServerlessWorkflow.Sdk/Models/ProcessType.cs b/src/ServerlessWorkflow.Sdk/Models/ProcessType.cs new file mode 100644 index 0000000..3b664f2 --- /dev/null +++ b/src/ServerlessWorkflow.Sdk/Models/ProcessType.cs @@ -0,0 +1,55 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Models; + +/// +/// Exposes process types +/// +public static class ProcessType +{ + + /// + /// Gets the 'container' process type + /// + public const string Container = "container"; + /// + /// Gets the 'script' process type + /// + public const string Script = "script"; + /// + /// Gets the 'shell' process type + /// + public const string Shell = "shell"; + /// + /// Gets the 'workflow' process type + /// + public const string Workflow = "workflow"; + /// + /// Gets the 'extension' process type + /// + public const string Extension = "extension"; + + /// + /// Gets a new containing all supported process types + /// + /// + public static IEnumerable AsEnumerable() + { + yield return Container; + yield return Script; + yield return Shell; + yield return Workflow; + } + +} diff --git a/src/ServerlessWorkflow.Sdk/Models/ProcessTypeDefinition.cs b/src/ServerlessWorkflow.Sdk/Models/ProcessTypeDefinition.cs new file mode 100644 index 0000000..ef91f38 --- /dev/null +++ b/src/ServerlessWorkflow.Sdk/Models/ProcessTypeDefinition.cs @@ -0,0 +1,65 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +using ServerlessWorkflow.Sdk.Models.Processes; + +namespace ServerlessWorkflow.Sdk.Models; + +/// +/// Represents the configuration of a process execution +/// +[DataContract] +public record ProcessTypeDefinition +{ + + /// + /// Gets/sets the configuration of the container to run + /// + [DataMember(Name = "container", Order = 1), JsonPropertyName("container"), JsonPropertyOrder(1), YamlMember(Alias = "container", Order = 1)] + public virtual ContainerProcessDefinition? Container { get; set; } + + /// + /// Gets/sets the configuration of the shell command to run + /// + [DataMember(Name = "shell", Order = 2), JsonPropertyName("shell"), JsonPropertyOrder(2), YamlMember(Alias = "shell", Order = 2)] + public virtual ShellProcessDefinition? Shell { get; set; } + + /// + /// Gets/sets the configuration of the script to run + /// + [DataMember(Name = "script", Order = 3), JsonPropertyName("script"), JsonPropertyOrder(3), YamlMember(Alias = "script", Order = 3)] + public virtual ScriptProcessDefinition? Script { get; set; } + + /// + /// Gets/sets the configuration of the workflow to run + /// + [DataMember(Name = "workflow", Order = 4), JsonPropertyName("workflow"), JsonPropertyOrder(4), YamlMember(Alias = "workflow", Order = 4)] + public virtual WorkflowProcessDefinition? Workflow { get; set; } + + /// + /// Gets the type of the defined process tasks + /// + [IgnoreDataMember, JsonIgnore, YamlIgnore] + public virtual string ProcessType + { + get + { + if (this.Container != null) return Models.ProcessType.Container; + if (this.Shell != null) return Models.ProcessType.Shell; + if (this.Script != null) return Models.ProcessType.Script; + if (this.Workflow != null) return Models.ProcessType.Workflow; + return Models.ProcessType.Extension; + } + } + +} diff --git a/src/ServerlessWorkflow.Sdk/Models/Processes/ContainerProcessDefinition.cs b/src/ServerlessWorkflow.Sdk/Models/Processes/ContainerProcessDefinition.cs new file mode 100644 index 0000000..c17af67 --- /dev/null +++ b/src/ServerlessWorkflow.Sdk/Models/Processes/ContainerProcessDefinition.cs @@ -0,0 +1,55 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Models.Processes; + +/// +/// Represents the configuration of a container process +/// +[DataContract] +public record ContainerProcessDefinition + : ProcessDefinition +{ + + /// + /// Gets/sets the name of the container image to run + /// + [Required, MinLength(1)] + [DataMember(Name = "image", Order = 1), JsonPropertyName("image"), JsonPropertyOrder(1), YamlMember(Alias = "image", Order = 1)] + public required virtual string Image { get; set; } = null!; + + /// + /// Gets/sets the command, if any, to execute on the container + /// + [DataMember(Name = "command", Order = 2), JsonPropertyName("command"), JsonPropertyOrder(2), YamlMember(Alias = "command", Order = 2)] + public virtual string? Command { get; set; } + + /// + /// Gets/sets a list containing the container's port mappings, if any + /// + [DataMember(Name = "ports", Order = 3), JsonPropertyName("ports"), JsonPropertyOrder(3), YamlMember(Alias = "ports", Order = 3)] + public virtual EquatableDictionary? Ports { get; set; } + + /// + /// Gets/sets the volume mapping for the container, if any + /// + [DataMember(Name = "volumes", Order = 4), JsonPropertyName("volumes"), JsonPropertyOrder(4), YamlMember(Alias = "volumes", Order = 4)] + public virtual EquatableDictionary? Volumes { get; set; } + + /// + /// Gets/sets a key/value mapping of the environment variables, if any, to use when running the configured process + /// + [DataMember(Name = "environment", Order = 5), JsonPropertyName("environment"), JsonPropertyOrder(5), YamlMember(Alias = "environment", Order = 5)] + public virtual EquatableDictionary? Environment { get; set; } + +} diff --git a/src/ServerlessWorkflow.Sdk/Models/Processes/ScriptProcessDefinition.cs b/src/ServerlessWorkflow.Sdk/Models/Processes/ScriptProcessDefinition.cs new file mode 100644 index 0000000..d682560 --- /dev/null +++ b/src/ServerlessWorkflow.Sdk/Models/Processes/ScriptProcessDefinition.cs @@ -0,0 +1,49 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Models.Processes; + +/// +/// Represents the definition of a script evaluation process +/// +[DataContract] +public record ScriptProcessDefinition + : ProcessDefinition +{ + + /// + /// Gets/sets the language of the script to run + /// + [DataMember(Name = "language", Order = 1), JsonPropertyName("language"), JsonPropertyOrder(1), YamlMember(Alias = "language", Order = 1)] + public required virtual string Language { get; set; } + + /// + /// Gets/sets the script's code. Required if has not been set. + /// + [DataMember(Name = "code", Order = 2), JsonPropertyName("code"), JsonPropertyOrder(2), YamlMember(Alias = "code", Order = 2)] + public virtual string? Code { get; set; } + + /// + /// Gets the the script's source. Required if has not been set. + /// + [DataMember(Name = "source", Order = 3), JsonPropertyName("source"), JsonPropertyOrder(3), YamlMember(Alias = "source", Order = 3)] + public virtual ExternalResourceDefinition? Source { get; set; } + + /// + /// Gets/sets a key/value mapping of the environment variables, if any, to use when running the configured process + /// + [DataMember(Name = "environment", Order = 4), JsonPropertyName("environment"), JsonPropertyOrder(4), YamlMember(Alias = "environment", Order = 4)] + public virtual EquatableDictionary? Environment { get; set; } + + +} diff --git a/src/ServerlessWorkflow.Sdk/Models/Processes/ShellProcessDefinition.cs b/src/ServerlessWorkflow.Sdk/Models/Processes/ShellProcessDefinition.cs new file mode 100644 index 0000000..5661485 --- /dev/null +++ b/src/ServerlessWorkflow.Sdk/Models/Processes/ShellProcessDefinition.cs @@ -0,0 +1,43 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Models.Processes; + +/// +/// Represents the definition of a shell process +/// +[DataContract] +public record ShellProcessDefinition + : ProcessDefinition +{ + + /// + /// Gets/sets the shell command to run + /// + [Required, MinLength(1)] + [DataMember(Name = "command", Order = 1), JsonPropertyName("command"), JsonPropertyOrder(1), YamlMember(Alias = "command", Order = 1)] + public required virtual string Command { get; set; } + + /// + /// Gets/sets the arguments of the shell command to run + /// + [DataMember(Name = "arguments", Order = 2), JsonPropertyName("arguments"), JsonPropertyOrder(2), YamlMember(Alias = "arguments", Order = 2)] + public virtual EquatableList? Arguments { get; set; } + + /// + /// Gets/sets a key/value mapping of the environment variables, if any, to use when running the configured process + /// + [DataMember(Name = "environment", Order = 3), JsonPropertyName("environment"), JsonPropertyOrder(3), YamlMember(Alias = "environment", Order = 3)] + public virtual EquatableDictionary? Environment { get; set; } + +} diff --git a/src/ServerlessWorkflow.Sdk/Models/Processes/WorkflowProcessDefinition.cs b/src/ServerlessWorkflow.Sdk/Models/Processes/WorkflowProcessDefinition.cs new file mode 100644 index 0000000..2913975 --- /dev/null +++ b/src/ServerlessWorkflow.Sdk/Models/Processes/WorkflowProcessDefinition.cs @@ -0,0 +1,53 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +using YamlDotNet.Core; + +namespace ServerlessWorkflow.Sdk.Models.Processes; + +/// +/// Represents the definition of a (sub)workflow process +/// +[DataContract] +public record WorkflowProcessDefinition + : ProcessDefinition +{ + + /// + /// Gets/sets the namespace the workflow to run belongs to + /// + [Required, MinLength(1), MaxLength(63)] + [DataMember(Name = "namespace", Order = 1), JsonPropertyName("namespace"), JsonPropertyOrder(1), YamlMember(Alias = "namespace", Order = 1)] + public required virtual string Namespace { get; set; } + + /// + /// Gets/sets the name of the workflow to run + /// + [Required, MinLength(1), MaxLength(63)] + [DataMember(Name = "name", Order = 2), JsonPropertyName("name"), JsonPropertyOrder(2), YamlMember(Alias = "name", Order = 2)] + public required virtual string Name { get; set; } + + /// + /// Gets/sets the version of the workflow to run. Defaults to `latest` + /// + [SemanticVersion] + [DataMember(Name = "version", Order = 3), JsonPropertyName("version"), JsonPropertyOrder(3), YamlMember(Alias = "version", Order = 3, ScalarStyle = ScalarStyle.SingleQuoted)] + public virtual string Version { get; set; } = "latest"; + + /// + /// Gets/sets the data, if any, to pass as input to the workflow to execute. The value should be validated against the target workflow's input schema, if specified + /// + [DataMember(Name = "input", Order = 4), JsonPropertyName("input"), JsonPropertyOrder(4), YamlMember(Alias = "input", Order = 4)] + public virtual object? Input { get; set; } + +} \ No newline at end of file diff --git a/src/ServerlessWorkflow.Sdk/Models/ProduceEventDefinition.cs b/src/ServerlessWorkflow.Sdk/Models/ProduceEventDefinition.cs deleted file mode 100644 index 0c50c1d..0000000 --- a/src/ServerlessWorkflow.Sdk/Models/ProduceEventDefinition.cs +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace ServerlessWorkflow.Sdk.Models; - -/// -/// Represents the object used to configure an event o produce -/// -[DataContract] -public class ProduceEventDefinition - : IExtensible -{ - - /// - /// Gets/sets the name of a defined event to produce - /// - [Required, MinLength(1)] - [DataMember(Order = 1, Name = "eventReference", IsRequired = true), JsonPropertyName("eventReference"), YamlMember(Alias = "eventReference")] - public string EventReference { get; set; } = null!; - - /// - /// Gets/sets the data to pass to the cloud event to produce. If String, expression which selects parts of the states data output to become the data of the produced event. If object a custom object to become the data of produced event. - /// - [DataMember(Order = 2, Name = "data"), JsonPropertyName("data"), YamlMember(Alias = "data")] - public IDictionary? Data { get; set; } - - /// - /// Gets/sets an containing the 's extension properties - /// - [DataMember(Order = 3, Name = "extensionData"), JsonExtensionData] - public virtual IDictionary? ExtensionData { get; set; } - -} diff --git a/src/ServerlessWorkflow.Sdk/Models/RaiseErrorDefinition.cs b/src/ServerlessWorkflow.Sdk/Models/RaiseErrorDefinition.cs new file mode 100644 index 0000000..fbc5ff3 --- /dev/null +++ b/src/ServerlessWorkflow.Sdk/Models/RaiseErrorDefinition.cs @@ -0,0 +1,30 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Models; + +/// +/// Represents the definition of the error to raise +/// +[DataContract] +public record RaiseErrorDefinition +{ + + /// + /// Gets/sets the definition of the error to raise + /// + [Required] + [DataMember(Name = "error", Order = 1), JsonPropertyName("error"), JsonPropertyOrder(1), YamlMember(Alias = "error", Order = 1)] + public required virtual ErrorDefinition Error { get; set; } + +} diff --git a/src/ServerlessWorkflow.Sdk/Models/ReferenceableComponentDefinition.cs b/src/ServerlessWorkflow.Sdk/Models/ReferenceableComponentDefinition.cs new file mode 100644 index 0000000..1732ba4 --- /dev/null +++ b/src/ServerlessWorkflow.Sdk/Models/ReferenceableComponentDefinition.cs @@ -0,0 +1,36 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Models; + +/// +/// Represents the base class for all ServerlessWorkflow referenceable workflow components +/// +[DataContract] +public abstract record ReferenceableComponentDefinition + : ComponentDefinition, IReferenceable +{ + + /// + /// Gets/sets an URI, if any, that reference the component's definition + /// + [DataMember(Order = 1, Name = "$ref"), JsonPropertyOrder(1), JsonPropertyName("$ref"), YamlMember(Order = 1, Alias = "$ref")] + public virtual Uri? Ref { get; set; } + + /// + /// Gets/sets the endpoint's authentication policy, if any + /// + [DataMember(Name = "authentication", Order = 2), JsonPropertyName("authentication"), JsonPropertyOrder(2), YamlMember(Alias = "authentication", Order = 2)] + public virtual AuthenticationPolicyDefinition? Authentication { get; set; } + +} \ No newline at end of file diff --git a/src/ServerlessWorkflow.Sdk/Models/RetryAttemptLimitDefinition.cs b/src/ServerlessWorkflow.Sdk/Models/RetryAttemptLimitDefinition.cs new file mode 100644 index 0000000..256aca1 --- /dev/null +++ b/src/ServerlessWorkflow.Sdk/Models/RetryAttemptLimitDefinition.cs @@ -0,0 +1,35 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Models; + +/// +/// Represents the definition of the limits for all retry attempts of a given policy +/// +[DataContract] +public record RetryAttemptLimitDefinition +{ + + /// + /// Gets/sets the maximum attempts count + /// + [DataMember(Name = "count", Order = 1), JsonPropertyName("count"), JsonPropertyOrder(1), YamlMember(Alias = "count", Order = 1)] + public virtual uint? Count { get; set; } + + /// + /// Gets/sets the duration limit, if any, for all retry attempts + /// + [DataMember(Name = "duration", Order = 2), JsonPropertyName("duration"), JsonPropertyOrder(2), YamlMember(Alias = "duration", Order = 2)] + public virtual Duration? Duration { get; set; } + +} diff --git a/src/ServerlessWorkflow.Sdk/Models/RetryDefinition.cs b/src/ServerlessWorkflow.Sdk/Models/RetryDefinition.cs deleted file mode 100644 index 17cd1f0..0000000 --- a/src/ServerlessWorkflow.Sdk/Models/RetryDefinition.cs +++ /dev/null @@ -1,117 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace ServerlessWorkflow.Sdk.Models; - -/// -/// Represents an object that defines workflow states retry policy strategy. This is an explicit definition and can be reused across multiple defined workflow state errors. -/// -[DataContract] -public class RetryDefinition - : IExtensible -{ - - /// - /// Gets/sets the 's name - /// - [Required] - [DataMember(Order = 1, Name = "name", IsRequired = true), JsonPropertyOrder(1), JsonPropertyName("name"), YamlMember(Alias = "name", Order = 1)] - public virtual string Name { get; set; } = null!; - - /// - /// Gets/sets delay between retry attempts - /// - [DataMember(Order = 2, Name = "delay"), JsonPropertyOrder(2), JsonPropertyName("delay"), YamlMember(Alias = "delay", Order = 2)] - [JsonConverter(typeof(Iso8601NullableTimeSpanConverter))] - public virtual TimeSpan? Delay { get; set; } - - /// - /// Gets/sets the maximum amount of retries allowed - /// - [DataMember(Order = 3, Name = "maxAttempts"), JsonPropertyOrder(3), JsonPropertyName("maxAttempts"), YamlMember(Alias = "maxAttempts", Order = 3)] - public virtual uint? MaxAttempts { get; set; } - - /// - /// Gets/sets the maximum delay between retries - /// - [DataMember(Order = 4, Name = "maxDelay"), JsonPropertyOrder(4), JsonPropertyName("maxDelay"), YamlMember(Alias = "maxDelay", Order = 4)] - [JsonConverter(typeof(Iso8601NullableTimeSpanConverter))] - public virtual TimeSpan? MaxDelay { get; set; } - - /// - /// Gets/sets the duration which will be added to the delay between successive retries - /// - [DataMember(Order = 5, Name = "increment"), JsonPropertyOrder(5), JsonPropertyName("increment"), YamlMember(Alias = "increment", Order = 5)] - [JsonConverter(typeof(Iso8601NullableTimeSpanConverter))] - public virtual TimeSpan? Increment { get; set; } - - /// - /// Gets/sets a value by which the delay is multiplied before each attempt. For example: "1.2" meaning that each successive delay is 20% longer than the previous delay. - /// For example, if delay is 'PT10S', then the delay between the first and second attempts will be 10 seconds, and the delay before the third attempt will be 12 seconds. - /// - [DataMember(Order = 6, Name = "multiplier"), JsonPropertyOrder(6), JsonPropertyName("multiplier"), YamlMember(Alias = "multiplier", Order = 6)] - public virtual float? Multiplier { get; set; } - - /// - /// Gets/sets the object that represents the 's jitter. - /// If float type, maximum amount of random time added or subtracted from the delay between each retry relative to total delay (between 0.0 and 1.0). - /// If string type, absolute maximum amount of random time added or subtracted from the delay between each retry (ISO 8601 duration format) - /// - [DataMember(Order = 7, Name = "jitter"), JsonPropertyOrder(7), JsonPropertyName("jitter"), YamlMember(Alias = "jitter", Order = 7)] - [JsonConverter(typeof(OneOfConverter))] - public virtual OneOf? JitterValue { get; set; } - - /// - /// Gets/sets the maximum amount of random time added or subtracted from the delay between each retry relative to total delay (between 0.0 and 1.0) - /// - [IgnoreDataMember, JsonIgnore, YamlIgnore] - public virtual float? JitterMultiplier - { - get - { - return this.JitterValue?.T1Value; - } - set - { - if (value == null) this.JitterValue = null; - else this.JitterValue = value; - } - } - - /// - /// Gets/sets the absolute maximum amount of random time added or subtracted from the delay between each retry - /// - [IgnoreDataMember, JsonIgnore, YamlIgnore] - public virtual TimeSpan? JitterDuration - { - get - { - if (string.IsNullOrWhiteSpace(this.JitterValue?.T2Value)) - return null; - return Iso8601TimeSpan.Parse(this.JitterValue.T2Value); - } - set - { - if (value == null) this.JitterValue = null; - else this.JitterValue = Iso8601TimeSpan.Format(value.Value); - } - } - - /// - [DataMember(Order = 8, Name = "extensionData"), JsonExtensionData] - public IDictionary? ExtensionData { get; set; } - - /// - public override string ToString() => this.Name; - -} \ No newline at end of file diff --git a/src/ServerlessWorkflow.Sdk/Models/RetryPolicyDefinition.cs b/src/ServerlessWorkflow.Sdk/Models/RetryPolicyDefinition.cs new file mode 100644 index 0000000..2f408a8 --- /dev/null +++ b/src/ServerlessWorkflow.Sdk/Models/RetryPolicyDefinition.cs @@ -0,0 +1,60 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Models; + +/// +/// Represents the definition of a retry policy +/// +[DataContract] +public record RetryPolicyDefinition + : ReferenceableComponentDefinition +{ + + /// + /// Gets/sets a runtime expression used to determine whether or not to retry running the task, in a given context + /// + [DataMember(Name = "when", Order = 1), JsonPropertyName("when"), JsonPropertyOrder(1), YamlMember(Alias = "when", Order = 1)] + public virtual string? When { get; set; } + + /// + /// Gets/sets a runtime expression used to determine whether or not to retry running the task, in a given context + /// + [DataMember(Name = "exceptWhen", Order = 2), JsonPropertyName("exceptWhen"), JsonPropertyOrder(2), YamlMember(Alias = "exceptWhen", Order = 2)] + public virtual string? ExceptWhen { get; set; } + + /// + /// Gets/sets the limits, if any, of the retry policy + /// + [DataMember(Name = "limit", Order = 3), JsonPropertyName("limit"), JsonPropertyOrder(2), YamlMember(Alias = "limit", Order = 3)] + public virtual RetryPolicyLimitDefinition? Limit { get; set; } + + /// + /// Gets/sets the delay duration between retry attempts + /// + [DataMember(Name = "delay", Order = 4), JsonPropertyName("delay"), JsonPropertyOrder(4), YamlMember(Alias = "delay", Order = 4)] + public virtual Duration? Delay { get; set; } + + /// + /// Gets/sets the backoff strategy to use, if any + /// + [DataMember(Name = "backoff", Order = 5), JsonPropertyName("backoff"), JsonPropertyOrder(5), YamlMember(Alias = "backoff", Order = 5)] + public virtual BackoffStrategyDefinition? Backoff { get; set; } + + /// + /// Gets/sets the parameters, if any, that control the randomness or variability of the delay between retry attempts + /// + [DataMember(Name = "jitter", Order = 6), JsonPropertyName("jitter"), JsonPropertyOrder(6), YamlMember(Alias = "jitter", Order = 6)] + public virtual JitterDefinition? Jitter { get; set; } + +} diff --git a/src/ServerlessWorkflow.Sdk/Models/RetryPolicyLimitDefinition.cs b/src/ServerlessWorkflow.Sdk/Models/RetryPolicyLimitDefinition.cs new file mode 100644 index 0000000..1e3f360 --- /dev/null +++ b/src/ServerlessWorkflow.Sdk/Models/RetryPolicyLimitDefinition.cs @@ -0,0 +1,35 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Models; + +/// +/// Represents the configuration of the limits of a retry policy +/// +[DataContract] +public record RetryPolicyLimitDefinition +{ + + /// + /// Gets/sets the definition of the limits for all retry attempts of a given policy + /// + [DataMember(Name = "attempt", Order = 1), JsonPropertyName("attempt"), JsonPropertyOrder(1), YamlMember(Alias = "attempt", Order = 1)] + public virtual RetryAttemptLimitDefinition? Attempt { get; set; } + + /// + /// Gets/sets the maximum duration, if any, during which to retry a given task + /// + [DataMember(Name = "duration", Order = 2), JsonPropertyName("duration"), JsonPropertyOrder(2), YamlMember(Alias = "duration", Order = 2)] + public virtual Duration? Duration { get; set; } + +} diff --git a/src/ServerlessWorkflow.Sdk/Models/RuntimeExpressionEvaluationConfiguration.cs b/src/ServerlessWorkflow.Sdk/Models/RuntimeExpressionEvaluationConfiguration.cs new file mode 100644 index 0000000..6f6c33b --- /dev/null +++ b/src/ServerlessWorkflow.Sdk/Models/RuntimeExpressionEvaluationConfiguration.cs @@ -0,0 +1,35 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Models; + +/// +/// Represents an object used to configure the workflow's runtime expression evaluation +/// +[DataContract] +public record RuntimeExpressionEvaluationConfiguration +{ + + /// + /// Gets/sets the language used for writing runtime expressions. Defaults to . + /// + [DataMember(Name = "language", Order = 1), JsonPropertyName("language"), JsonPropertyOrder(1), YamlMember(Alias = "language", Order = 1)] + public virtual string Language { get; set; } = RuntimeExpressions.Languages.JQ; + + /// + /// Gets/sets the language used for writing runtime expressions. Defaults to + /// + [DataMember(Name = "mode", Order = 2), JsonPropertyName("mode"), JsonPropertyOrder(2), YamlMember(Alias = "mode", Order = 2)] + public virtual string? Mode { get; set; } + +} \ No newline at end of file diff --git a/src/ServerlessWorkflow.Sdk/Models/ScheduleDefinition.cs b/src/ServerlessWorkflow.Sdk/Models/ScheduleDefinition.cs deleted file mode 100644 index d2e31c1..0000000 --- a/src/ServerlessWorkflow.Sdk/Models/ScheduleDefinition.cs +++ /dev/null @@ -1,84 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace ServerlessWorkflow.Sdk.Models; - -/// -/// Represents an object used to define the time/repeating intervals at which workflow instances can/should be started -/// -[DataContract] -public class ScheduleDefinition - : IExtensible -{ - - /// - /// Gets/sets the time interval (ISO 8601 format) describing when workflow instances can be created. - /// - [DataMember(Order = 1, Name = "interval"), JsonPropertyOrder(1), JsonPropertyName("interval"), YamlMember(Alias = "interval", Order = 1)] - [JsonConverter(typeof(Iso8601NullableTimeSpanConverter))] - public virtual TimeSpan? Interval { get; set; } - - /// - /// Gets/sets a object that represents the CRON expression that defines when the workflow instance should be created - /// - [DataMember(Order = 2, Name = "cron"), JsonPropertyOrder(2), JsonPropertyName("cron"), YamlMember(Alias = "cron", Order = 2)] - [JsonConverter(typeof(OneOfConverter))] - public virtual OneOf? CronValue { get; set; } - - /// - /// Gets/sets an object used to configure the schedule following which workflow instances should be created - /// - [IgnoreDataMember, JsonIgnore, YamlIgnore] - public virtual CronDefinition? Cron - { - get - { - if (this.CronValue?.T1Value == null && !string.IsNullOrWhiteSpace(this.CronValue?.T2Value)) return new() { Expression = this.CronValue.T2Value }; - else return this.CronValue?.T1Value; - } - set - { - if (value == null) this.CronValue = null; - else this.CronValue = value; - } - } - - /// - /// Gets/sets a CRON expression that defines when the workflow instance should be created - /// - [IgnoreDataMember, JsonIgnore, YamlIgnore] - public virtual string? CronExpression - { - get - { - if (this.CronValue?.T1Value == null) return this.CronValue?.T2Value; - else return this.CronValue?.T1Value?.Expression; - } - set - { - if (value == null) this.CronValue = null; - else this.CronValue = value; - } - } - - /// - /// Gets/sets the timezone name used to evaluate the cron expression. Not used for interval as timezone can be specified there directly. If not specified, should default to local machine timezone. - /// - [DataMember(Order = 3, Name = "timezone"), JsonPropertyOrder(3), JsonPropertyName("timezone"), YamlMember(Alias = "timezone", Order = 3)] - public virtual string? Timezone { get; set; } - - /// - [DataMember(Order = 4, Name = "extensionData"), JsonExtensionData] - public IDictionary? ExtensionData { get; set; } - -} diff --git a/src/ServerlessWorkflow.Sdk/Models/SchemaDefinition.cs b/src/ServerlessWorkflow.Sdk/Models/SchemaDefinition.cs new file mode 100644 index 0000000..ace3349 --- /dev/null +++ b/src/ServerlessWorkflow.Sdk/Models/SchemaDefinition.cs @@ -0,0 +1,44 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +using System.Text.Json.Nodes; + +namespace ServerlessWorkflow.Sdk.Models; + +/// +/// Represents the definition of a schema +/// +[DataContract] +public record SchemaDefinition +{ + + /// + /// Gets/sets the schema's format. Defaults to 'json'. The (optional) version of the format can be set using `{format}:{version}`. + /// + [Required] + [DataMember(Name = "format", Order = 1), JsonPropertyName("format"), JsonPropertyOrder(1), YamlMember(Alias = "format", Order = 1)] + public virtual string Format { get; set; } = SchemaFormat.Json; + + /// + /// Gets/sets the schema's external resource, if any. Required if has not been set. + /// + [DataMember(Name = "resource", Order = 2), JsonPropertyName("resource"), JsonPropertyOrder(2), YamlMember(Alias = "resource", Order = 2)] + public virtual ExternalResourceDefinition? Resource { get; set; } + + /// + /// Gets/sets the inline definition of the schema to use. Required if has not been set. + /// + [DataMember(Name = "document", Order = 3), JsonPropertyName("document"), JsonPropertyOrder(3), YamlMember(Alias = "document", Order = 3)] + public virtual object? Document { get; set; } + +} diff --git a/src/ServerlessWorkflow.Sdk/Models/SchemaFormat.cs b/src/ServerlessWorkflow.Sdk/Models/SchemaFormat.cs new file mode 100644 index 0000000..5da69df --- /dev/null +++ b/src/ServerlessWorkflow.Sdk/Models/SchemaFormat.cs @@ -0,0 +1,46 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Models; + +/// +/// Exposes all schema formats supported by default by ServerlessWorkflow +/// +public static class SchemaFormat +{ + + /// + /// Gets the Avro schema format + /// + public const string Avro = "avro"; + /// + /// Gets the JSON schema format + /// + public const string Json = "json"; + /// + /// Gets the XML schema format + /// + public const string Xml = "xml"; + + /// + /// Gets an containing all default schema format + /// + /// A new containing all default schema format + public static IEnumerable AsEnumerable() + { + yield return Avro; + yield return Json; + yield return Xml; + } + +} \ No newline at end of file diff --git a/src/ServerlessWorkflow.Sdk/Models/SecretBasedAuthenticationProperties.cs b/src/ServerlessWorkflow.Sdk/Models/SecretBasedAuthenticationProperties.cs deleted file mode 100644 index 9fc55bb..0000000 --- a/src/ServerlessWorkflow.Sdk/Models/SecretBasedAuthenticationProperties.cs +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace ServerlessWorkflow.Sdk.Models; - -/// -/// Represents loaded from a specific secret -/// -[DataContract] -public class SecretBasedAuthenticationProperties - : AuthenticationProperties -{ - - /// - /// Initializes a new - /// - public SecretBasedAuthenticationProperties() { } - - /// - /// Initializes a new - /// - /// The name of the secret to load the from - public SecretBasedAuthenticationProperties(string secret) - { - if (string.IsNullOrWhiteSpace(secret)) throw new ArgumentNullException(nameof(secret)); - this.Secret = secret; - } - - /// - /// Gets the name of the secret to load the from - /// - [Required, MinLength(1)] - [DataMember(Order = 1, Name = "secret", IsRequired = true), JsonPropertyName("secret"), YamlMember(Alias = "secret")] - public virtual string Secret { get; set; } = null!; - -} diff --git a/src/ServerlessWorkflow.Sdk/Models/StartDefinition.cs b/src/ServerlessWorkflow.Sdk/Models/StartDefinition.cs deleted file mode 100644 index e7c145e..0000000 --- a/src/ServerlessWorkflow.Sdk/Models/StartDefinition.cs +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace ServerlessWorkflow.Sdk.Models; - -/// -/// Represents an object used to explicitly define how/when workflow instances should be created -/// -[DataContract] -public class StartDefinition - : IExtensible -{ - - /// - /// Gets/sets the name of the workflow definition's start state definition. If not defined, defaults to the first defined state - /// - [Required] - [DataMember(Order = 1, Name = "stateName", IsRequired = true), JsonPropertyName("stateName"), YamlMember(Alias = "stateName")] - public virtual string StateName { get; set; } = null!; - - /// - /// Gets/sets the object used to define the time/repeating intervals at which workflow instances can/should be started - /// - [Required] - [DataMember(Order = 2, Name = "schedule", IsRequired = true), JsonPropertyName("schedule"), YamlMember(Alias = "schedule")] - public virtual ScheduleDefinition? Schedule { get; set; } - - /// - [DataMember(Order = 3, Name = "extensionData"), JsonExtensionData] - public IDictionary? ExtensionData { get; set; } - -} diff --git a/src/ServerlessWorkflow.Sdk/Models/StateDataFilterDefinition.cs b/src/ServerlessWorkflow.Sdk/Models/StateDataFilterDefinition.cs deleted file mode 100644 index bf6c135..0000000 --- a/src/ServerlessWorkflow.Sdk/Models/StateDataFilterDefinition.cs +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace ServerlessWorkflow.Sdk.Models; - -/// -/// Represents the definition of a state's data filter -/// -[DataContract] -public class StateDataFilterDefinition - : IExtensible -{ - - /// - /// Gets/sets an expression to filter the states data input - /// - [DataMember(Order = 1, Name = "input"), JsonPropertyName("input"), YamlMember(Alias = "input")] - public virtual string? Input { get; set; } - - /// - /// Gets/sets an expression that filters the states data output - /// - [DataMember(Order = 2), JsonPropertyName("output"), YamlMember(Alias = "output")] - public virtual string? Output { get; set; } - - /// - [DataMember(Order = 3, Name = "extensionData"), JsonExtensionData] - public virtual IDictionary? ExtensionData { get; set; } - -} \ No newline at end of file diff --git a/src/ServerlessWorkflow.Sdk/Models/StateDefinition.cs b/src/ServerlessWorkflow.Sdk/Models/StateDefinition.cs deleted file mode 100644 index e03e681..0000000 --- a/src/ServerlessWorkflow.Sdk/Models/StateDefinition.cs +++ /dev/null @@ -1,227 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -using Neuroglia; - -namespace ServerlessWorkflow.Sdk.Models; - -/// -/// Represents the definition of a workflow state -/// -[Discriminator(nameof(Type))] -[DataContract, KnownType(typeof(ExtensionStateDefinition)), KnownType(typeof(InjectStateDefinition))] -[JsonConverter(typeof(AbstractClassConverterFactory))] -public abstract class StateDefinition - : IMetadata, IExtensible -{ - - /// - /// Initializes a new state definition - /// - protected StateDefinition() { } - - /// - /// Initializes a new state definition - /// - /// The state definition's type - protected StateDefinition(string type) - { - this.Type = type; - } - - /// - /// Gets/sets the state definition's id - /// - [DataMember(Order = 1, Name = "id"), JsonPropertyOrder(1), JsonPropertyName("id"), YamlMember(Alias = "id", Order = 1)] - public virtual string? Id { get; set; } - - /// - /// Gets/sets the state definition's id - /// - [Required, MinLength(1)] - [DataMember(Order = 2, Name = "name", IsRequired = true), JsonPropertyOrder(2), JsonPropertyName("name"), YamlMember(Alias = "name", Order = 2)] - public virtual string Name { get; set; } = null!; - - /// - /// Gets the state definition's type - /// - [DataMember(Order = 3, Name = "type"), JsonPropertyOrder(3), JsonPropertyName("type"), YamlMember(Alias = "type", Order = 3)] - public virtual string Type { get; protected set; } = null!; - - /// - /// Gets/sets the filter to apply to the state definition's input and output data - /// - [DataMember(Order = 4, Name = "stateDataFilter"), JsonPropertyOrder(4), JsonPropertyName("stateDataFilter"), YamlMember(Alias = "stateDataFilter", Order = 4)] - public virtual StateDataFilterDefinition? DataFilter { get; set; } - - /// - /// Gets/sets the that represents the workflow definition's data input - /// - [DataMember(Order = 5, Name = "dataInputSchema"), JsonPropertyOrder(5), JsonPropertyName("dataInputSchema"), YamlMember(Alias = "dataInputSchema", Order = 5)] - [JsonConverter(typeof(OneOfConverter))] - protected virtual OneOf? DataInputSchemaValue { get; set; } - - /// - /// Gets/sets the object used to configure the workflow definition's data input schema - /// - [IgnoreDataMember, JsonIgnore, YamlIgnore] - public virtual DataInputSchemaDefinition? DataInputSchema - { - get - { - return this.DataInputSchemaValue?.T1Value; - } - set - { - if (value == null) this.DataInputSchemaValue = null; - else this.DataInputSchemaValue = value; - } - } - - /// - /// Gets/sets an uri pointing at the workflow definition's input data schema - /// - [IgnoreDataMember, JsonIgnore, YamlIgnore] - public virtual Uri? DataInputSchemaUri - { - get - { - return this.DataInputSchemaValue?.T2Value; - } - set - { - if (value == null) - this.DataInputSchemaValue = null; - else - this.DataInputSchemaValue = value; - } - } - - /// - /// Gets/sets the configuration of the state definition's error handling - /// - [DataMember(Order = 90, Name = "onErrors"), JsonPropertyOrder(90), JsonPropertyName("onErrors"), YamlMember(Alias = "onErrors", Order = 90)] - public virtual List? Errors { get; set; } - - /// - /// Gets/sets the id of the state definition used to compensate the state definition - /// - [DataMember(Order = 91, Name = "compensatedBy"), JsonPropertyOrder(91), JsonPropertyName("compensatedBy"), YamlMember(Alias = "compensatedBy", Order = 91)] - public virtual string? CompensatedBy { get; set; } - - /// - /// Gets/sets a boolean indicating whether or not the state definition is used for compensating another state definition - /// - [DataMember(Order = 92, Name = "usedForCompensation"), JsonPropertyOrder(92), JsonPropertyName("usedForCompensation"), YamlMember(Alias = "usedForCompensation", Order = 92)] - public virtual bool UsedForCompensation { get; set; } - - /// - /// Gets/sets the state definition's metadata, if any - /// - [DataMember(Order = 93, Name = "metadata"), JsonPropertyOrder(93), JsonPropertyName("metadata"), YamlMember(Alias = "metadata", Order = 93)] - public virtual DynamicMapping? Metadata { get; set; } - - /// - /// Gets/sets the that represents the state definition's - /// - [DataMember(Order = 94, Name = "transition"), JsonPropertyOrder(94), JsonPropertyName("transition"), YamlMember(Alias = "transition", Order = 94)] - [JsonConverter(typeof(OneOfConverter))] - protected virtual OneOf? TransitionValue { get; set; } - - /// - /// Gets/sets the object used to configure the state definition's transition to another state definition upon completion - /// - [IgnoreDataMember, JsonIgnore, YamlIgnore] - public virtual TransitionDefinition? Transition - { - get - { - if (this.TransitionValue?.T1Value == null && !string.IsNullOrWhiteSpace(this.TransitionValue?.T2Value)) return new() { NextState = this.TransitionValue.T2Value }; - else return this.TransitionValue?.T1Value; - } - set - { - if (value == null) this.TransitionValue = null; - else this.TransitionValue = value; - } - } - - /// - /// Gets/sets the name of the state definition to transition to upon completion - /// - [IgnoreDataMember, JsonIgnore, YamlIgnore] - public virtual string? TransitionToStateName - { - get - { - return this.TransitionValue?.T2Value; - } - set - { - if (value == null) this.TransitionValue = null; - else this.TransitionValue = value; - } - } - - /// - /// Gets/sets an object used to configure the state definition's end, if any - /// - [DataMember(Order = 95, Name = "end"), JsonPropertyOrder(95), JsonPropertyName("end"), YamlMember(Alias = "end", Order = 95)] - [JsonConverter(typeof(OneOfConverter))] - protected virtual OneOf? EndValue { get; set; } - - /// - /// Gets/sets the object used to configure the state definition's transition to another state definition upon completion - /// - [IgnoreDataMember, JsonIgnore, YamlIgnore] - public virtual EndDefinition? End - { - get - { - if (this.EndValue?.T1Value == null && (this.EndValue != null && this.EndValue.T2Value)) return new() { }; - else return this.EndValue?.T1Value; - } - set - { - if (value == null) this.EndValue = null; - else this.EndValue = value; - } - } - - /// - /// Gets/sets a boolean indicating whether or not the state definition is the end of a logicial workflow path - /// - [IgnoreDataMember, JsonIgnore, YamlIgnore] - public virtual bool IsEnd - { - get - { - if (this.EndValue == null) return false; - else return this.EndValue.T2Value; - } - set - { - this.EndValue = value; - } - } - - /// - /// Gets/sets an containing the state definition's extension properties - /// - [DataMember(Order = 999, Name = "extensionData"), JsonExtensionData] - public virtual IDictionary? ExtensionData { get; set; } - - /// - public override string ToString() => this.Name; - -} diff --git a/src/ServerlessWorkflow.Sdk/Models/States/CallbackStateDefinition.cs b/src/ServerlessWorkflow.Sdk/Models/States/CallbackStateDefinition.cs deleted file mode 100644 index 3bcbe3c..0000000 --- a/src/ServerlessWorkflow.Sdk/Models/States/CallbackStateDefinition.cs +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -using Neuroglia; - -namespace ServerlessWorkflow.Sdk.Models; - -/// -/// Represents a workflow state that performs an action, then waits for the callback event that denotes completion of the action -/// -[DataContract] -[DiscriminatorValue(StateType.Callback)] -public class CallbackStateDefinition - : StateDefinition -{ - - /// - /// Initializes a new - /// - public CallbackStateDefinition() : base(StateType.Callback) { } - - /// - /// Gets/sets the action to be executed - /// - [DataMember(Order = 6, Name = "action"), JsonPropertyOrder(6), JsonPropertyName("action"), YamlMember(Alias = "action", Order = 6)] - public virtual ActionDefinition? Action { get; set; } - - /// - /// Gets/sets a reference to the callback event to await - /// - [DataMember(Order = 7, Name = "eventRef"), JsonPropertyOrder(7), JsonPropertyName("eventRef"), YamlMember(Alias = "eventRef", Order = 7)] - public virtual string? EventRef { get; set; } - - /// - /// Gets/sets the time period to wait for incoming events - /// - [DataMember(Order = 8, Name = "timeout"), JsonPropertyOrder(8), JsonPropertyName("timeout"), YamlMember(Alias = "timeout", Order = 8)] - [JsonConverter(typeof(Iso8601NullableTimeSpanConverter))] - public virtual TimeSpan? Timeout { get; set; } - - /// - /// Gets/sets the callback event data filter definition - /// - [DataMember(Order = 9, Name = "eventDataFilter"), JsonPropertyOrder(9), JsonPropertyName("eventDataFilter"), YamlMember(Alias = "eventDataFilter", Order = 9)] - public virtual EventDataFilterDefinition EventDataFilter { get; set; } = new(); - -} diff --git a/src/ServerlessWorkflow.Sdk/Models/States/EventStateDefinition.cs b/src/ServerlessWorkflow.Sdk/Models/States/EventStateDefinition.cs deleted file mode 100644 index 459e106..0000000 --- a/src/ServerlessWorkflow.Sdk/Models/States/EventStateDefinition.cs +++ /dev/null @@ -1,81 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -using Neuroglia; - -namespace ServerlessWorkflow.Sdk.Models; - -/// -/// Represents a workflow state that awaits one or more events and perform actions when they are received -/// -[DataContract] -[DiscriminatorValue(StateType.Event)] -public class EventStateDefinition - : StateDefinition -{ - - /// - /// Initializes a new - /// - public EventStateDefinition() : base(StateType.Event) { } - - /// - /// Gets/sets a boolean indicating whether or not the awaits one or all of defined events. - /// If 'true', consuming one of the defined events causes its associated actions to be performed. If 'false', all of the defined events must be consumed in order for actions to be performed. Defaults to 'true'. - /// - [DefaultValue(true)] - [DataMember(Order = 6, Name = "exclusive"), JsonPropertyOrder(6), JsonPropertyName("exclusive"), YamlMember(Alias = "exclusive", Order = 6)] - public virtual bool Exclusive { get; set; } = true; - - /// - /// Gets/sets an object used to configure the 's triggers and actions - /// - [Required, MinLength(1)] - [DataMember(Order = 7, Name = "onEvents", IsRequired = true), JsonPropertyOrder(7), JsonPropertyName("onEvents"), YamlMember(Alias = "onEvents", Order = 7)] - public virtual List OnEvents { get; set; } = new List(); - - /// - /// Gets/sets the duration to wait for incoming events - /// - [DataMember(Order = 8, Name = "timeout", IsRequired = true), JsonPropertyOrder(8), JsonPropertyName("timeout"), YamlMember(Alias = "timeout", Order = 8)] - [JsonConverter(typeof(Iso8601NullableTimeSpanConverter))] - public virtual TimeSpan? Timeout { get; set; } - - /// - /// Gets the with the specified id - /// - /// The id of the to get - /// The with the specified id - public virtual EventStateTriggerDefinition GetTrigger(int id) => this.OnEvents.ElementAt(id); - - /// - /// Attempts to get the with the specified id - /// - /// The name of the to get - /// The with the specified id - /// A boolean indicating whether or not a with the specified id could be found - public virtual bool TryGetTrigger(int id, out EventStateTriggerDefinition? trigger) - { - trigger = null!; - try - { - trigger = this.GetTrigger(id); - } - catch - { - return false; - } - return trigger != null; - } - -} diff --git a/src/ServerlessWorkflow.Sdk/Models/States/ForEachStateDefinition.cs b/src/ServerlessWorkflow.Sdk/Models/States/ForEachStateDefinition.cs deleted file mode 100644 index 0fb6fad..0000000 --- a/src/ServerlessWorkflow.Sdk/Models/States/ForEachStateDefinition.cs +++ /dev/null @@ -1,109 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -using Neuroglia; - -namespace ServerlessWorkflow.Sdk.Models; - -/// -/// Represents a workflow state that executes a set of defined actions or workflows for each element of a data array -/// -[DataContract] -[DiscriminatorValue(StateType.ForEach)] -public class ForEachStateDefinition - : StateDefinition -{ - - /// - /// Initializes a new - /// - public ForEachStateDefinition() : base(StateType.ForEach) { } - - /// - /// gets/sets an expression selecting an array element of the states data - /// - [DataMember(Order = 6, Name = "inputCollection"), JsonPropertyOrder(6), JsonPropertyName("inputCollection"), YamlMember(Alias = "inputCollection", Order = 6)] - public virtual string? InputCollection { get; set; } - - /// - /// Gets/sets an expression specifying an array element of the states data to add the results of each iteration - /// - [DataMember(Order = 7, Name = "outputCollection"), JsonPropertyOrder(7), JsonPropertyName("outputCollection"), YamlMember(Alias = "outputCollection", Order = 7)] - public virtual string? OutputCollection { get; set; } - - /// - /// Gets/sets the name of the iteration parameter that can be referenced in actions/workflow. For each parallel iteration, this param should contain an unique element of the array referenced by the expression - /// - [DataMember(Order = 8, Name = "iterationParam"), JsonPropertyOrder(8), JsonPropertyName("iterationParam"), YamlMember(Alias = "iterationParam", Order = 8)] - public virtual string? IterationParam { get; set; } - - /// - /// Gets/sets a uint that specifies how upper bound on how many iterations may run in parallel - /// - [DataMember(Order = 9, Name = "batchSize"), JsonPropertyOrder(9), JsonPropertyName("batchSize"), YamlMember(Alias = "batchSize", Order = 9)] - public virtual int? BatchSize { get; set; } - - /// - /// Gets/sets a value used to configure the way the actions of each iterations should be executed - /// - [DataMember(Order = 10, Name = "mode"), JsonPropertyOrder(10), JsonPropertyName("mode"), YamlMember(Alias = "mode", Order = 10)] - public virtual string Mode { get; set; } = ActionExecutionMode.Sequential; - - /// - /// Gets/sets an of actions to be executed for each of the elements of the - /// - [Required, MinLength(1)] - [DataMember(Order = 11, Name = "actions"), JsonPropertyOrder(11), JsonPropertyName("actions"), YamlMember(Alias = "actions", Order = 11)] - public virtual List Actions { get; set; } = new List(); - - /// - /// Gets the with the specified name - /// - /// The name of the to get - /// The with the specified name - public virtual ActionDefinition? GetAction(string name) - { - return this.Actions.FirstOrDefault(s => s.Name == name); - } - - /// - /// Attempts to get the with the specified name - /// - /// The name of the to get - /// The with the specified name - /// A boolean indicating whether or not a with the specified name could be found - public virtual bool TryGetAction(string name, out ActionDefinition action) - { - action = this.GetAction(name)!; - return action != null; - } - - /// - /// Attempts to get the next in the pipeline - /// - /// The name of the to get the next for - /// The next , if any - /// A boolean indicating whether or not there is a next in the pipeline - public virtual bool TryGetNextAction(string previousActionName, out ActionDefinition action) - { - action = null!; - var previousAction = this.Actions.FirstOrDefault(a => a.Name == previousActionName)!; - var previousActionIndex = this.Actions.ToList().IndexOf(previousAction); - var nextIndex = previousActionIndex + 1; - if (nextIndex >= this.Actions.Count) - return false; - action = this.Actions.ElementAt(nextIndex); - return true; - } - -} diff --git a/src/ServerlessWorkflow.Sdk/Models/States/OperationStateDefinition.cs b/src/ServerlessWorkflow.Sdk/Models/States/OperationStateDefinition.cs deleted file mode 100644 index 8a0289c..0000000 --- a/src/ServerlessWorkflow.Sdk/Models/States/OperationStateDefinition.cs +++ /dev/null @@ -1,83 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -using Neuroglia; - -namespace ServerlessWorkflow.Sdk.Models; - -/// -/// Represents a workflow state that defines a set of actions to be performed in sequence or in parallel. Once all actions have been performed, a transition to another state can occur. -/// -[DataContract] -[DiscriminatorValue(StateType.Operation)] -public class OperationStateDefinition - : StateDefinition -{ - - /// - /// Initializes a new - /// - public OperationStateDefinition() : base(StateType.Operation) { } - - /// - /// Gets/sets a value that specifies how actions are to be performed (in sequence of parallel). Defaults to sequential - /// - [DefaultValue(ActionExecutionMode.Sequential)] - [DataMember(Order = 6, Name = "actionMode"), JsonPropertyOrder(6), JsonPropertyName("actionMode"), YamlMember(Alias = "actionMode", Order = 6)] - public virtual string ActionMode { get; set; } = ActionExecutionMode.Sequential; - - /// - /// Gets/sets an of actions to be performed if expression matches - /// - [Required, MinLength(1)] - [DataMember(Order = 7, Name = "actions", IsRequired = true), JsonPropertyOrder(7), JsonPropertyName("actions"), YamlMember(Alias = "actions", Order = 7)] - public virtual List Actions { get; set; } = new List(); - - /// - /// Gets the with the specified name - /// - /// The name of the to get - /// The with the specified name - public virtual ActionDefinition? GetAction(string name) => this.Actions.FirstOrDefault(s => s.Name == name); - - /// - /// Attempts to get the with the specified name - /// - /// The name of the to get - /// The with the specified name - /// A boolean indicating whether or not a with the specified name could be found - public virtual bool TryGetAction(string name, out ActionDefinition? action) - { - action = this.GetAction(name); - return action != null; - } - - /// - /// Attempts to get the next in the pipeline - /// - /// The name of the to get the next for - /// The next , if any - /// A boolean indicating whether or not there is a next in the pipeline - public virtual bool TryGetNextAction(string previousActionName, out ActionDefinition? action) - { - action = null; - var previousAction = this.Actions.FirstOrDefault(a => a.Name == previousActionName); - if (previousAction == null) return false; - var previousActionIndex = this.Actions.ToList().IndexOf(previousAction); - var nextIndex = previousActionIndex + 1; - if (nextIndex >= this.Actions.Count) return false; - action = this.Actions.ElementAt(nextIndex); - return true; - } - -} diff --git a/src/ServerlessWorkflow.Sdk/Models/States/ParallelStateDefinition.cs b/src/ServerlessWorkflow.Sdk/Models/States/ParallelStateDefinition.cs deleted file mode 100644 index 9f1684d..0000000 --- a/src/ServerlessWorkflow.Sdk/Models/States/ParallelStateDefinition.cs +++ /dev/null @@ -1,70 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -using Neuroglia; - -namespace ServerlessWorkflow.Sdk.Models; - -/// -/// Represents a workflow state that executes es in parallel -/// -[DataContract] -[DiscriminatorValue(StateType.Parallel)] -public class ParallelStateDefinition - : StateDefinition -{ - - /// - /// Initializes a new - /// - public ParallelStateDefinition() : base(StateType.Parallel) { } - - /// - /// Gets/sets an containing the es executed by the - /// - [Required, MinLength(1)] - [DataMember(Order = 6, Name = "branches"), JsonPropertyOrder(6), JsonPropertyName("branches"), YamlMember(Alias = "branches", Order = 6)] - public virtual List Branches { get; set; } = new List(); - - /// - /// Gets/sets a value that configures the way the completes. Defaults to 'And' - /// - [DataMember(Order = 7, Name = "completionType"), JsonPropertyOrder(7), JsonPropertyName("completionType"), YamlMember(Alias = "completionType", Order = 7)] - public virtual string CompletionType { get; set; } = ParallelCompletionType.AllOf; - - /// - /// Gets/sets a value that represents the amount of es to complete for completing the state, when is set to - /// - [DataMember(Order = 8, Name = "n"), JsonPropertyOrder(8), JsonPropertyName("n"), YamlMember(Alias = "n", Order = 8)] - public virtual uint? N { get; set; } - - /// - /// Gets the with the specified name - /// - /// The name of the to get - /// The with the specified name - public virtual BranchDefinition? GetBranch(string name) => this.Branches.FirstOrDefault(b => b.Name == name); - - /// - /// Attempts to get the with the specified name - /// - /// The name of the to get - /// The with the specified name - /// A boolean indicating whether or not a with the specified name could be found - public virtual bool TryGetBranch(string name, out BranchDefinition branch) - { - branch = this.GetBranch(name)!; - return branch != null; - } - -} diff --git a/src/ServerlessWorkflow.Sdk/Models/States/SwitchStateDefinition.cs b/src/ServerlessWorkflow.Sdk/Models/States/SwitchStateDefinition.cs deleted file mode 100644 index 838dcd6..0000000 --- a/src/ServerlessWorkflow.Sdk/Models/States/SwitchStateDefinition.cs +++ /dev/null @@ -1,141 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -using Neuroglia; - -namespace ServerlessWorkflow.Sdk.Models; - -/// -/// Represents a workflow state that can be seen as a workflow gateway: they can direct transitions of a workflow based on certain conditions -/// -[DataContract] -[DiscriminatorValue(StateType.Switch)] -public class SwitchStateDefinition - : StateDefinition -{ - - /// - /// Initializes a new - /// - public SwitchStateDefinition() : base(StateType.Switch) { } - - /// - /// Gets the 's type - /// - public virtual string SwitchType - { - get - { - if (this.DataConditions != null && this.DataConditions.Any()) return SwitchStateType.Data; - else if (this.EventConditions != null && this.EventConditions.Any()) return SwitchStateType.Event; - else throw new Exception($"A switch state must define at least one data-based or one event-based condition"); - } - } - - /// - /// Gets/sets an of s between which to switch. Assigning the property sets the 's to . - /// - [DataMember(Order = 6, Name = "dataConditions"), JsonPropertyOrder(6), JsonPropertyName("dataConditions"), YamlMember(Alias = "dataConditions", Order = 6)] - public virtual List? DataConditions { get; set; } - - /// - /// Gets/sets an of s between which to switch. Assigning the property sets the 's to . - /// - [DataMember(Order = 7, Name = "eventConditions"), JsonPropertyOrder(7), JsonPropertyName("eventConditions"), YamlMember(Alias = "eventConditions", Order = 7)] - public virtual List? EventConditions { get; set; } - - /// - /// Gets/sets the duration to wait for incoming events - /// - [DataMember(Order = 8, Name = "eventTimeout"), JsonPropertyOrder(8), JsonPropertyName("eventTimeout"), YamlMember(Alias = "eventTimeout", Order = 8)] - [JsonConverter(typeof(Iso8601NullableTimeSpanConverter))] - public virtual TimeSpan? EventTimeout { get; set; } - - /// - /// Gets/sets an object used to configure the 's default condition, in case none of the specified conditions were met - /// - [Required, MinLength(1)] - [DataMember(Order = 9, Name = "defaultCondition", IsRequired = true), JsonPropertyOrder(9), JsonPropertyName("defaultCondition"), YamlMember(Alias = "defaultCondition", Order = 9)] - public virtual DefaultCaseDefinition DefaultCondition { get; set; } = null!; - - /// - /// Gets the with the specified name - /// - /// The name of the to get - /// The with the specified name - public virtual SwitchCaseDefinition? GetCase(string caseName) - { - SwitchCaseDefinition @case; - switch (this.SwitchType) - { - case SwitchStateType.Data: - if (caseName == "default") @case = new DataCaseDefinition() { Name = "default", Transition = this.DefaultCondition.Transition, End = this.DefaultCondition.End }; - else @case = this.DataConditions!.Single(c => c.Name == caseName); - break; - case SwitchStateType.Event: - if (caseName == "default") @case = new EventCaseDefinition() { Name = "default", Transition = this.DefaultCondition.Transition, End = this.DefaultCondition.End }; - else @case = this.EventConditions!.Single(c => c.Name == caseName); - break; - default: throw new NotSupportedException($"The specified switch state type '{this.SwitchType}' is not supported in this context"); - } - return @case; - } - - /// - /// Attempts to get the with the specified name - /// - /// The name of the to get - /// The with the specified name - /// A boolean indicating whether or not the with the specified name could be found - public virtual bool TryGetCase(string caseName, out SwitchCaseDefinition @case) - { - @case = null!; - try - { - @case = this.GetCase(caseName)!; - } - catch - { - return false; - } - return @case != null; - } - - /// - /// Gets the that applies to the specified event - /// - /// The name of the event the to get applies to - /// The that applies to the specified event - public virtual EventCaseDefinition? GetEventCase(string eventReference) => this.EventConditions?.FirstOrDefault(c => c.EventRef == eventReference); - - /// - /// Attempts to get the that applies to the specified event - /// - /// The reference of the event the to get applies to - /// The that applies to the specified event - /// A boolean indicating whether or not a with the specified id could be found - public virtual bool TryGetEventCase(string eventReference, out EventCaseDefinition @case) - { - @case = null!; - try - { - @case = this.GetEventCase(eventReference)!; - } - catch - { - return false; - } - return @case != null; - } - -} diff --git a/src/ServerlessWorkflow.Sdk/Models/SubflowReference.cs b/src/ServerlessWorkflow.Sdk/Models/SubflowReference.cs deleted file mode 100644 index ac25fdc..0000000 --- a/src/ServerlessWorkflow.Sdk/Models/SubflowReference.cs +++ /dev/null @@ -1,108 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace ServerlessWorkflow.Sdk.Models; - -/// -/// Represents a reference to a sub workflow definition -/// -[DataContract] -public class SubflowReference - : IExtensible -{ - - /// - /// Initializes a new - /// - public SubflowReference() { } - - /// - /// Initializes a new - /// - /// The id of the workflow definition to run - /// The version of the workflow definition to run. Defaults to 'latest' - /// The subflow's . Defaults to . - public SubflowReference(string workflowId, string? version = null, string invocationMode = Sdk.InvocationMode.Synchronous) - : this() - { - if (string.IsNullOrWhiteSpace(workflowId)) throw new ArgumentNullException(nameof(workflowId)); - this.WorkflowId = workflowId; - this.Version = version; - this.InvocationMode = invocationMode; - } - - /// - /// Initializes a new - /// - /// The id of the workflow definition to run - /// The subflow's . Defaults to . - public SubflowReference(string workflowId, string invocationMode = Sdk.InvocationMode.Synchronous) : this(workflowId, null, invocationMode) { } - - /// - /// Gets/sets the id of the workflow definition to run - /// - [Required, MinLength(1)] - [DataMember(Order = 1, Name = "workflowId", IsRequired = true), JsonPropertyOrder(1), JsonPropertyName("workflowId"), YamlMember(Alias = "workflowId", Order = 1)] - public virtual string WorkflowId { get; set; } = null!; - - /// - /// Gets/sets the version of the workflow definition to run. Defaults to 'latest' - /// - [DataMember(Order = 2, Name = "version"), JsonPropertyOrder(2), JsonPropertyName("version"), YamlMember(Alias = "version", Order = 2)] - public virtual string? Version { get; set; } = "latest"; - - /// - /// Gets/sets the subflow's . Defaults to . - /// - /// - /// Default value of this property is sync, meaning that workflow execution should wait until the subflow completes. - /// If set to async, workflow execution should just invoke the subflow and not wait for its results. Note that in this case the action does not produce any results, and the associated actions actionDataFilter as well as its retry definition, if defined, should be ignored. - /// Subflows that are invoked async do not propagate their errors to the associated action definition and the workflow state, meaning that any errors that happen during their execution cannot be handled in the workflow states onErrors definition. - /// Note that errors raised during subflows that are invoked async should not fail workflow execution. - /// - [DataMember(Order = 3, Name = "invoke"), JsonPropertyOrder(3), JsonPropertyName("invoke"), YamlMember(Alias = "invoke", Order = 3)] - public virtual string InvocationMode { get; set; } = Sdk.InvocationMode.Synchronous; - - /// - /// Gets/sets a value that defines how subflow execution that is invoked async should behave if the parent workflow completes execution before the subflow completes its own execution - /// - [DataMember(Order = 4, Name = "onParentComplete"), JsonPropertyOrder(4), JsonPropertyName("onParentComplete"), YamlMember(Alias = "onParentComplete", Order = 4)] - public virtual bool OnParentComplete { get; set; } - - /// - /// Gets/sets an containing the 's extension properties - /// - [DataMember(Order = 5, Name = "extensionData"), JsonExtensionData] - public IDictionary? ExtensionData { get; set; } - - /// - public override string ToString() => string.IsNullOrWhiteSpace(this.Version) ? $"{this.WorkflowId}:latest" : $"{this.WorkflowId}:{this.Version}"; - - /// - /// Parses the specified input into a new - /// - /// The input to parse - /// A new - public static SubflowReference Parse(string input) - { - if (string.IsNullOrWhiteSpace(input)) - throw new ArgumentNullException(nameof(input)); - var components = input.Split(":", StringSplitOptions.RemoveEmptyEntries); - var workflowId = components.First(); - var version = null as string; - if (components.Length > 1) - version = components.Last(); - return new SubflowReference(workflowId, version!); - } - -} \ No newline at end of file diff --git a/src/ServerlessWorkflow.Sdk/Models/SwitchCaseDefinition.cs b/src/ServerlessWorkflow.Sdk/Models/SwitchCaseDefinition.cs index 28dcfd8..fc5c9d7 100644 --- a/src/ServerlessWorkflow.Sdk/Models/SwitchCaseDefinition.cs +++ b/src/ServerlessWorkflow.Sdk/Models/SwitchCaseDefinition.cs @@ -1,4 +1,4 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors +// Copyright © 2024-Present The Serverless Workflow Specification Authors // // Licensed under the Apache License, Version 2.0 (the "License"), // you may not use this file except in compliance with the License. @@ -14,116 +14,22 @@ namespace ServerlessWorkflow.Sdk.Models; /// -/// Represents the base class for all case implementations +/// Represents the definition of a case within a switch task, defining a condition and corresponding tasks to execute if the condition is met /// -[DataContract, KnownType(nameof(GetKnownTypes))] -public abstract class SwitchCaseDefinition +[DataContract] +public record SwitchCaseDefinition { /// - /// Gets the 's type + /// Gets/sets the condition that determines whether or not the case should be executed in a switch task /// - [IgnoreDataMember, JsonIgnore, YamlIgnore] - public string OutcomeType => this.Transition == null ? SwitchCaseOutcomeType.End : SwitchCaseOutcomeType.Transition; + [DataMember(Name = "when", Order = 1), JsonPropertyName("when"), JsonPropertyOrder(1), YamlMember(Alias = "when", Order = 1)] + public virtual string? When { get; set; } /// - /// Gets/sets the 's name + /// Gets/sets the transition to perform when the case matches /// - [DataMember(Order = 1, Name = "name"), JsonPropertyOrder(1), JsonPropertyName("name"), YamlMember(Alias = "name", Order = 1)] - public virtual string? Name { get; set; } + [DataMember(Name = "then", Order = 2), JsonPropertyName("then"), JsonPropertyOrder(2), YamlMember(Alias = "then", Order = 2)] + public virtual string? Then { get; set; } - /// - /// Gets/sets the object that represents the 's - /// - [DataMember(Order = 2, Name = "transition"), JsonPropertyOrder(2), JsonPropertyName("transition"), YamlMember(Alias = "transition", Order = 2)] - [JsonConverter(typeof(OneOfConverter))] - protected virtual OneOf? TransitionValue { get; set; } - - /// - /// Gets/sets the object used to configure the state definition's transition to another state definition upon completion - /// - [IgnoreDataMember, JsonIgnore, YamlIgnore] - public virtual TransitionDefinition? Transition - { - get - { - if (this.TransitionValue?.T1Value == null && !string.IsNullOrWhiteSpace(this.TransitionValue?.T2Value)) return new() { NextState = this.TransitionValue.T2Value }; - else return this.TransitionValue?.T1Value; - } - set - { - if (value == null) this.TransitionValue = null; - else this.TransitionValue = value; - } - } - - /// - /// Gets/sets the name of the state definition to transition to upon completion - /// - [IgnoreDataMember, JsonIgnore, YamlIgnore] - public virtual string? TransitionToStateName - { - get - { - return this.TransitionValue?.T2Value; - } - set - { - if (value == null) this.TransitionValue = null; - else this.TransitionValue = value; - } - } - - /// - /// Gets/sets the object that represents the 's - /// - [DataMember(Order = 3, Name = "end"), JsonPropertyOrder(3), JsonPropertyName("end"), YamlMember(Alias = "end", Order = 3)] - [JsonConverter(typeof(OneOfConverter))] - protected virtual OneOf? EndValue { get; set; } - - /// - /// Gets/sets the object used to configure the state definition's transition to another state definition upon completion - /// - [IgnoreDataMember, JsonIgnore, YamlIgnore] - public virtual EndDefinition? End - { - get - { - if (this.EndValue?.T1Value == null && (this.EndValue != null && this.EndValue.T2Value)) return new() { }; - else return this.EndValue?.T1Value; - } - set - { - if (value == null) this.EndValue = null; - else this.EndValue = value; - } - } - - /// - /// Gets/sets a boolean indicating whether or not the state definition is the end of a logicial workflow path - /// - [IgnoreDataMember, JsonIgnore, YamlIgnore] - public virtual bool IsEnd - { - get - { - if (this.EndValue == null) return false; - else return this.EndValue.T2Value; - } - set - { - this.EndValue = value; - } - } - - /// - public override string? ToString() => string.IsNullOrWhiteSpace(this.Name) ? base.ToString() : this.Name; - - static IEnumerable GetKnownTypes() - { - yield return typeof(DataCaseDefinition); - yield return typeof(EventCaseDefinition); - yield return typeof(DefaultCaseDefinition); - } - -} +} \ No newline at end of file diff --git a/src/ServerlessWorkflow.Sdk/Models/TaskDefinition.cs b/src/ServerlessWorkflow.Sdk/Models/TaskDefinition.cs new file mode 100644 index 0000000..8facecf --- /dev/null +++ b/src/ServerlessWorkflow.Sdk/Models/TaskDefinition.cs @@ -0,0 +1,58 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +using ServerlessWorkflow.Sdk.Serialization.Json; +using System.ComponentModel; + +namespace ServerlessWorkflow.Sdk.Models; + +/// +/// Represents the definition of a task +/// +[DataContract, JsonConverter(typeof(TaskDefinitionJsonConverter))] +public abstract record TaskDefinition + : ComponentDefinition +{ + + /// + /// Gets the type of the defined task + /// + [IgnoreDataMember, JsonIgnore, YamlIgnore] + public abstract string Type { get; } + + /// + /// Gets/sets the definition, if any, of the task's input data + /// + [DataMember(Name = "input", Order = 10), JsonPropertyName("input"), JsonPropertyOrder(10), YamlMember(Alias = "input", Order = 10)] + public virtual InputDataModelDefinition? Input { get; set; } + + /// + /// Gets/sets the definition, if any, of the task's output data + /// + [DataMember(Name = "output", Order = 11), JsonPropertyName("output"), JsonPropertyOrder(11), YamlMember(Alias = "output", Order = 11)] + public virtual OutputDataModelDefinition? Output { get; set; } + + /// + /// Gets/sets a boolean indicating whether or not to return the result, if any, of the defined task + /// + [DataMember(Name = "timeout", Order = 12), JsonPropertyName("timeout"), JsonPropertyOrder(12), YamlMember(Alias = "timeout", Order = 12)] + public virtual TimeoutDefinition? Timeout { get; set; } + + /// + /// Gets/sets the flow directive to be performed upon completion of the task + /// + [DataMember(Name = "then", Order = 13), JsonPropertyName("then"), JsonPropertyOrder(13), YamlMember(Alias = "then", Order = 13)] + public virtual string? Then { get; set; } + +} + diff --git a/src/ServerlessWorkflow.Sdk/Models/TaskExecutionStrategyDefinition.cs b/src/ServerlessWorkflow.Sdk/Models/TaskExecutionStrategyDefinition.cs new file mode 100644 index 0000000..364897d --- /dev/null +++ b/src/ServerlessWorkflow.Sdk/Models/TaskExecutionStrategyDefinition.cs @@ -0,0 +1,47 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Models; + +/// +/// Represents the definition of a task execution strategy +/// +[DataContract] +public record TaskExecutionStrategyDefinition +{ + + /// + /// Gets a value indicating how the defines tasks should be executed + /// + [IgnoreDataMember, JsonIgnore, YamlIgnore] + public virtual string ExecutionMode => this.Sequentially?.Count > 0 ? TaskExecutionMode.Sequential : this.Concurrently?.Count > 0 ? TaskExecutionMode.Concurrent : throw new Exception("The task execution strategy must be set"); + + /// + /// Gets/sets a name/value mapping of the task to execute sequentially. Required if has not been set, otherwise null. + /// + [DataMember(Name = "sequentially", Order = 1), JsonPropertyName("sequentially"), JsonPropertyOrder(1), YamlMember(Alias = "sequentially", Order = 1)] + public virtual EquatableDictionary? Sequentially { get; set; } + + /// + /// Gets/sets a name/value mapping of the task to execute concurrently. Required if has not been set, otherwise null. + /// + [DataMember(Name = "concurrently", Order = 2), JsonPropertyName("concurrently"), JsonPropertyOrder(2), YamlMember(Alias = "concurrently", Order = 2)] + public virtual EquatableDictionary? Concurrently { get; set; } + + /// + /// Gets/sets a boolean indicating whether or not concurrently executed tasks should race each other, with only one winner setting the task's output. + /// + [DataMember(Name = "compete", Order = 3), JsonPropertyName("compete"), JsonPropertyOrder(3), YamlMember(Alias = "compete", Order = 3)] + public virtual bool? Compete { get; set; } + +} diff --git a/src/ServerlessWorkflow.Sdk/Models/TaskType.cs b/src/ServerlessWorkflow.Sdk/Models/TaskType.cs new file mode 100644 index 0000000..7f4abcd --- /dev/null +++ b/src/ServerlessWorkflow.Sdk/Models/TaskType.cs @@ -0,0 +1,91 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Models; + +/// +/// Exposes task types +/// +public static class TaskType +{ + + /// + /// Gets the 'call' task type + /// + public const string Call = "call"; + /// + /// Gets the 'composite' task type + /// + public const string Composite = "composite"; + /// + /// Gets the 'emit' task type + /// + public const string Emit = "emit"; + /// + /// Gets the 'extension' task type + /// + public const string Extension = "extension"; + /// + /// Gets the 'for' task type + /// + public const string For = "for"; + /// + /// Gets the 'listen' task type + /// + public const string Listen = "listen"; + /// + /// Gets the 'raise' task type + /// + public const string Raise = "raise"; + /// + /// Gets the 'run' task type + /// + public const string Run = "run"; + /// + /// Gets the 'set' task type + /// + public const string Set = "set"; + /// + /// Gets the 'switch' task type + /// + public const string Switch = "switch"; + /// + /// Gets the 'try' task type + /// + public const string Try = "try"; + /// + /// Gets the 'wait' task type + /// + public const string Wait = "wait"; + + /// + /// Gets a new containing all supported task types + /// + /// + public static IEnumerable AsEnumerable() + { + yield return Call; + yield return Composite; + yield return Emit; + yield return Extension; + yield return For; + yield return Listen; + yield return Raise; + yield return Run; + yield return Set; + yield return Switch; + yield return Try; + yield return Wait; + } + +} \ No newline at end of file diff --git a/src/ServerlessWorkflow.Sdk/Models/Tasks/CallTaskDefinition.cs b/src/ServerlessWorkflow.Sdk/Models/Tasks/CallTaskDefinition.cs new file mode 100644 index 0000000..f52ae0c --- /dev/null +++ b/src/ServerlessWorkflow.Sdk/Models/Tasks/CallTaskDefinition.cs @@ -0,0 +1,47 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Models.Tasks; + +/// +/// Represents the definition of a task used to call a predefined function +/// +[DataContract] +public record CallTaskDefinition + : TaskDefinition +{ + + /// + [IgnoreDataMember, JsonIgnore, YamlIgnore] + public override string Type => TaskType.Call; + + /// + /// Gets/sets the reference to the function to call + /// + [Required, MinLength(1)] + [DataMember(Name = "call", Order = 1), JsonPropertyName("call"), JsonPropertyOrder(1), YamlMember(Alias = "call", Order = 1)] + public required virtual string Call { get; set; } + + /// + /// Gets/sets a key/value mapping of the call's arguments + /// + [DataMember(Name = "with", Order = 2), JsonPropertyName("with"), JsonPropertyOrder(2), YamlMember(Alias = "with", Order = 2)] + public virtual EquatableDictionary? With { get; set; } + + /// + /// Gets/sets a boolean indicating whether or not to wait for the called function to return. Defaults to true. + /// + [DataMember(Name = "await", Order = 3), JsonPropertyName("await"), JsonPropertyOrder(3), YamlMember(Alias = "await", Order = 3)] + public virtual bool? Await { get; set; } + +} diff --git a/src/ServerlessWorkflow.Sdk/Models/Tasks/CompositeTaskDefinition.cs b/src/ServerlessWorkflow.Sdk/Models/Tasks/CompositeTaskDefinition.cs new file mode 100644 index 0000000..4e1c49c --- /dev/null +++ b/src/ServerlessWorkflow.Sdk/Models/Tasks/CompositeTaskDefinition.cs @@ -0,0 +1,35 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Models.Tasks; + +/// +/// Represents the configuration of a task that is composed of multiple subtasks +/// +[DataContract] +public record CompositeTaskDefinition + : TaskDefinition +{ + + /// + [IgnoreDataMember, JsonIgnore, YamlIgnore] + public override string Type => TaskType.Composite; + + /// + /// Gets/sets a name/definition mapping of the subtasks to execute + /// + [Required] + [DataMember(Name = "execute", Order = 1), JsonPropertyName("execute"), JsonPropertyOrder(1), YamlMember(Alias = "execute", Order = 1)] + public required virtual TaskExecutionStrategyDefinition Execute { get; set; } + +} diff --git a/src/ServerlessWorkflow.Sdk/Models/Tasks/EmitTaskDefinition.cs b/src/ServerlessWorkflow.Sdk/Models/Tasks/EmitTaskDefinition.cs new file mode 100644 index 0000000..3eced45 --- /dev/null +++ b/src/ServerlessWorkflow.Sdk/Models/Tasks/EmitTaskDefinition.cs @@ -0,0 +1,34 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Models.Tasks; + +/// +/// Represents the configuration of a task used to emit an event +/// +[DataContract] +public record EmitTaskDefinition + : TaskDefinition +{ + + /// + [IgnoreDataMember, JsonIgnore, YamlIgnore] + public override string Type => TaskType.Emit; + + /// + /// Gets/sets the configuration of an event's emission + /// + [DataMember(Name = "emit", Order = 1), JsonPropertyName("emit"), JsonPropertyOrder(1), YamlMember(Alias = "emit", Order = 1)] + public required virtual EventEmissionDefinition Emit { get; set; } + +} diff --git a/src/ServerlessWorkflow.Sdk/Extensions/JsonElementExtensions.cs b/src/ServerlessWorkflow.Sdk/Models/Tasks/ExtensionTaskDefinition.cs similarity index 52% rename from src/ServerlessWorkflow.Sdk/Extensions/JsonElementExtensions.cs rename to src/ServerlessWorkflow.Sdk/Models/Tasks/ExtensionTaskDefinition.cs index a2de831..67d5dc3 100644 --- a/src/ServerlessWorkflow.Sdk/Extensions/JsonElementExtensions.cs +++ b/src/ServerlessWorkflow.Sdk/Models/Tasks/ExtensionTaskDefinition.cs @@ -1,4 +1,4 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors +// Copyright © 2024-Present The Serverless Workflow Specification Authors // // Licensed under the Apache License, Version 2.0 (the "License"), // you may not use this file except in compliance with the License. @@ -11,21 +11,24 @@ // See the License for the specific language governing permissions and // limitations under the License. -using Json.More; - -namespace ServerlessWorkflow.Sdk; +namespace ServerlessWorkflow.Sdk.Models.Tasks; /// -/// Defines extensions for s +/// Represents the definition of an extension's task /// -public static class JsonElementExtensions +[DataContract] +public record ExtensionTaskDefinition + : TaskDefinition, IExtensible { + /// + [IgnoreDataMember, JsonIgnore, YamlIgnore] + public override string Type => TaskType.Extension; + /// - /// Unwraps the into a new, non-JSON value + /// Gets/sets the task definition's extension data, if any /// - /// The to unwrap - /// The unwrapped value - public static object? ToObject(this JsonElement jsonElement) => jsonElement.AsNode()?.ToObject(); + [DataMember(Name = "extensionData", Order = 1), JsonExtensionData] + public virtual IDictionary? ExtensionData { get; set; } -} +} \ No newline at end of file diff --git a/src/ServerlessWorkflow.Sdk/Models/Tasks/ForTaskDefinition.cs b/src/ServerlessWorkflow.Sdk/Models/Tasks/ForTaskDefinition.cs new file mode 100644 index 0000000..e9cf5c7 --- /dev/null +++ b/src/ServerlessWorkflow.Sdk/Models/Tasks/ForTaskDefinition.cs @@ -0,0 +1,48 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Models.Tasks; + +/// +/// Represents the definition of a task that executes a set of subtasks iteratively for each element in a collection +/// +[DataContract] +public record ForTaskDefinition + : TaskDefinition +{ + + /// + [IgnoreDataMember, JsonIgnore, YamlIgnore] + public override string Type => TaskType.For; + + /// + /// Gets/sets the definition of the loop that iterates over a range of values + /// + [Required] + [DataMember(Name = "for", Order = 1), JsonPropertyName("for"), JsonPropertyOrder(1), YamlMember(Alias = "for", Order = 1)] + public required virtual ForLoopDefinition For { get; set; } + + /// + /// Gets/sets a runtime expression that represents the condition, if any, that must be met for the iteration to continue + /// + [DataMember(Name = "while", Order = 2), JsonPropertyName("while"), JsonPropertyOrder(2), YamlMember(Alias = "while", Order = 2)] + public virtual string? While { get; set; } + + /// + /// Gets/sets the task to perform for each item in the collection + /// + [Required] + [DataMember(Name = "do", Order = 3), JsonPropertyName("do"), JsonPropertyOrder(3), YamlMember(Alias = "do", Order = 3)] + public required virtual TaskDefinition Do { get; set; } + +} diff --git a/src/ServerlessWorkflow.Sdk/Models/Tasks/ListenTaskDefinition.cs b/src/ServerlessWorkflow.Sdk/Models/Tasks/ListenTaskDefinition.cs new file mode 100644 index 0000000..96fabd8 --- /dev/null +++ b/src/ServerlessWorkflow.Sdk/Models/Tasks/ListenTaskDefinition.cs @@ -0,0 +1,35 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Models.Tasks; + +/// +/// Represents the configuration of a task used to listen to specific events +/// +[DataContract] +public record ListenTaskDefinition + : TaskDefinition +{ + + /// + [IgnoreDataMember, JsonIgnore, YamlIgnore] + public override string Type => TaskType.Listen; + + /// + /// Gets/sets the configuration of the listener to use + /// + [Required] + [DataMember(Name = "listen", Order = 1), JsonPropertyName("listen"), JsonPropertyOrder(1), YamlMember(Alias = "listen", Order = 1)] + public required virtual ListenerDefinition Listen { get; set; } + +} diff --git a/src/ServerlessWorkflow.Sdk/Models/Tasks/RaiseTaskDefinition.cs b/src/ServerlessWorkflow.Sdk/Models/Tasks/RaiseTaskDefinition.cs new file mode 100644 index 0000000..f11b2ed --- /dev/null +++ b/src/ServerlessWorkflow.Sdk/Models/Tasks/RaiseTaskDefinition.cs @@ -0,0 +1,35 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Models.Tasks; + +/// +/// Represents the definition of a task used to raise an error +/// +[DataContract] +public record RaiseTaskDefinition + : TaskDefinition +{ + + /// + [IgnoreDataMember, JsonIgnore, YamlIgnore] + public override string Type => TaskType.Raise; + + /// + /// Gets/sets the definition of the error to raise + /// + [Required] + [DataMember(Name = "raise", Order = 1), JsonPropertyName("raise"), JsonPropertyOrder(1), YamlMember(Alias = "raise", Order = 1)] + public required virtual RaiseErrorDefinition Raise { get; set; } + +} diff --git a/src/ServerlessWorkflow.Sdk/Models/Tasks/RunTaskDefinition.cs b/src/ServerlessWorkflow.Sdk/Models/Tasks/RunTaskDefinition.cs new file mode 100644 index 0000000..01cecc0 --- /dev/null +++ b/src/ServerlessWorkflow.Sdk/Models/Tasks/RunTaskDefinition.cs @@ -0,0 +1,35 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Models.Tasks; + +/// +/// Represents the configuration of a task used to run a given process +/// +[DataContract] +public record RunTaskDefinition + : TaskDefinition +{ + + /// + [IgnoreDataMember, JsonIgnore, YamlIgnore] + public override string Type => TaskType.Run; + + /// + /// Gets/sets the configuration of the process to execute + /// + [Required] + [DataMember(Name = "run", Order = 1), JsonPropertyName("run"), JsonPropertyOrder(1), YamlMember(Alias = "run", Order = 1)] + public required virtual ProcessTypeDefinition Run { get; set; } = null!; + +} diff --git a/src/ServerlessWorkflow.Sdk/Models/Tasks/SetTaskDefinition.cs b/src/ServerlessWorkflow.Sdk/Models/Tasks/SetTaskDefinition.cs new file mode 100644 index 0000000..ce54d40 --- /dev/null +++ b/src/ServerlessWorkflow.Sdk/Models/Tasks/SetTaskDefinition.cs @@ -0,0 +1,35 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Models.Tasks; + +/// +/// Represents the definition of a task used to set data +/// +[DataContract] +public record SetTaskDefinition + : TaskDefinition +{ + + /// + [IgnoreDataMember, JsonIgnore, YamlIgnore] + public override string Type => TaskType.Set; + + /// + /// Gets/sets the data to set + /// + [Required, MinLength(1)] + [DataMember(Name = "set", Order = 1), JsonPropertyName("set"), JsonPropertyOrder(1), YamlMember(Alias = "set", Order = 1)] + public required virtual EquatableDictionary Set { get; set; } + +} diff --git a/src/ServerlessWorkflow.Sdk/Models/Tasks/SwitchTaskDefinition.cs b/src/ServerlessWorkflow.Sdk/Models/Tasks/SwitchTaskDefinition.cs new file mode 100644 index 0000000..622243d --- /dev/null +++ b/src/ServerlessWorkflow.Sdk/Models/Tasks/SwitchTaskDefinition.cs @@ -0,0 +1,35 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Models.Tasks; + +/// +/// Represents the definition of a task that evaluates conditions and executes specific branches based on the result +/// +[DataContract] +public record SwitchTaskDefinition + : TaskDefinition +{ + + /// + [IgnoreDataMember, JsonIgnore, YamlIgnore] + public override string Type => TaskType.Switch; + + /// + /// Gets/sets the definition of the switch to use + /// + [Required] + [DataMember(Name = "switch", Order = 1), JsonPropertyName("switch"), JsonPropertyOrder(1), YamlMember(Alias = "switch", Order = 1)] + public required virtual EquatableDictionary Switch { get; set; } + +} diff --git a/src/ServerlessWorkflow.Sdk/Models/Tasks/TryTaskDefinition.cs b/src/ServerlessWorkflow.Sdk/Models/Tasks/TryTaskDefinition.cs new file mode 100644 index 0000000..ba72832 --- /dev/null +++ b/src/ServerlessWorkflow.Sdk/Models/Tasks/TryTaskDefinition.cs @@ -0,0 +1,42 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Models.Tasks; + +/// +/// Represents the definition of a task used to try one or more subtasks, and to catch/handle the errors that can potentially be raised during execution +/// +[DataContract] +public record TryTaskDefinition + : TaskDefinition +{ + + /// + [IgnoreDataMember, JsonIgnore, YamlIgnore] + public override string Type => TaskType.Try; + + /// + /// Gets/sets the definition of the task to try running + /// + [Required] + [DataMember(Name = "try", Order = 1), JsonPropertyName("try"), JsonPropertyOrder(1), YamlMember(Alias = "try", Order = 1)] + public required virtual TaskDefinition Try { get; set; } + + /// + /// Gets/sets the object used to define the errors to catch + /// + [Required] + [DataMember(Name = "catch", Order = 2), JsonPropertyName("catch"), JsonPropertyOrder(2), YamlMember(Alias = "catch", Order = 2)] + public required virtual ErrorCatcherDefinition Catch { get; set; } + +} diff --git a/src/ServerlessWorkflow.Sdk/Models/Tasks/WaitTaskDefinition.cs b/src/ServerlessWorkflow.Sdk/Models/Tasks/WaitTaskDefinition.cs new file mode 100644 index 0000000..8baf689 --- /dev/null +++ b/src/ServerlessWorkflow.Sdk/Models/Tasks/WaitTaskDefinition.cs @@ -0,0 +1,35 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Models.Tasks; + +/// +/// Represents the definition of a task used to wait a certain amount of time +/// +[DataContract] +public record WaitTaskDefinition + : TaskDefinition +{ + + /// + [IgnoreDataMember, JsonIgnore, YamlIgnore] + public override string Type => TaskType.Wait; + + /// + /// Gets/sets the amount of time to wait before resuming workflow + /// + [Required] + [DataMember(Name = "wait", Order = 1), JsonPropertyName("wait"), JsonPropertyOrder(1), YamlMember(Alias = "wait", Order = 1)] + public required virtual Duration Wait { get; set; } + +} diff --git a/src/ServerlessWorkflow.Sdk/Models/ExtensionAuthenticationProperties.cs b/src/ServerlessWorkflow.Sdk/Models/TimeoutDefinition.cs similarity index 60% rename from src/ServerlessWorkflow.Sdk/Models/ExtensionAuthenticationProperties.cs rename to src/ServerlessWorkflow.Sdk/Models/TimeoutDefinition.cs index e25a179..4d4b404 100644 --- a/src/ServerlessWorkflow.Sdk/Models/ExtensionAuthenticationProperties.cs +++ b/src/ServerlessWorkflow.Sdk/Models/TimeoutDefinition.cs @@ -1,4 +1,4 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors +// Copyright © 2024-Present The Serverless Workflow Specification Authors // // Licensed under the Apache License, Version 2.0 (the "License"), // you may not use this file except in compliance with the License. @@ -14,17 +14,18 @@ namespace ServerlessWorkflow.Sdk.Models; /// -/// Represents an object used to configure an extension authentication mechanism +/// Represents the definition of a timeout /// [DataContract] -public class ExtensionAuthenticationProperties - : AuthenticationProperties +public record TimeoutDefinition { - /// - public ExtensionAuthenticationProperties() { } - - /// - public ExtensionAuthenticationProperties(IDictionary properties) : base(properties) { } + /// + /// Gets/sets the duration after which to timeout + /// + [Required] + [DataMember(Name = "after", Order = 1), JsonPropertyName("after"), JsonPropertyOrder(1), YamlMember(Alias = "after", Order = 1)] + public required virtual Duration After { get; set; } } + diff --git a/src/ServerlessWorkflow.Sdk/Models/TransitionDefinition.cs b/src/ServerlessWorkflow.Sdk/Models/TransitionDefinition.cs deleted file mode 100644 index c38c55d..0000000 --- a/src/ServerlessWorkflow.Sdk/Models/TransitionDefinition.cs +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace ServerlessWorkflow.Sdk.Models; - -/// -/// Represents an object used to define a state transition -/// -[DataContract] -public class TransitionDefinition - : StateOutcomeDefinition -{ - - /// - /// Gets/sets the name of state to transition to - /// - [Required, MinLength(1)] - [DataMember(Order = 1, Name = "nextState", IsRequired = true), JsonPropertyName("nextState"), YamlMember(Alias = "nextState")] - public virtual string NextState { get; set; } = null!; - - /// - /// Gets/sets an containing the events to be produced before the transition happens - /// - [DataMember(Order = 2, Name = "produceEvents"), JsonPropertyName("produceEvents"), YamlMember(Alias = "produceEvents")] - public virtual List? ProduceEvents { get; set; } - - /// - /// Gets/sets a boolean indicating whether or not to trigger workflow compensation before the transition is taken. Default is false - /// - [DataMember(Order = 3, Name = "compensate"), JsonPropertyName("compensate"), YamlMember(Alias = "compensate")] - public virtual bool Compensate { get; set; } = false; - -} diff --git a/src/ServerlessWorkflow.Sdk/Models/WorkflowDefinition.cs b/src/ServerlessWorkflow.Sdk/Models/WorkflowDefinition.cs index afafbe1..36384da 100644 --- a/src/ServerlessWorkflow.Sdk/Models/WorkflowDefinition.cs +++ b/src/ServerlessWorkflow.Sdk/Models/WorkflowDefinition.cs @@ -1,4 +1,4 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors +// Copyright © 2024-Present The Serverless Workflow Specification Authors // // Licensed under the Apache License, Version 2.0 (the "License"), // you may not use this file except in compliance with the License. @@ -11,699 +11,63 @@ // See the License for the specific language governing permissions and // limitations under the License. -using ServerlessWorkflow.Sdk.Services.FluentBuilders; -using System.Dynamic; - namespace ServerlessWorkflow.Sdk.Models; /// -/// Represents the definition of a Serverless Workflow +/// Represents the definition of a workflow /// [DataContract] -public class WorkflowDefinition - : IExtensible, IMetadata +public record WorkflowDefinition { /// - /// Gets/sets the workflow definition's unique identifier - /// - [DataMember(Order = 1, Name = "id"), JsonPropertyName("id"), YamlMember(Alias = "id")] - public virtual string? Id { get; set; } - - /// - /// Gets/sets the workflow definition's domain-specific workflow identifier - /// - [DataMember(Order = 2, Name = "key"), JsonPropertyName("key"), YamlMember(Alias = "key")] - public virtual string? Key { get; set; } - - /// - /// Gets/sets the workflow definition's name + /// Gets/sets an object used to document the defined workflow /// - [DataMember(Order = 3, Name = "name"), JsonPropertyName("name"), YamlMember(Alias = "name")] - [Required, MinLength(1)] - public virtual string Name { get; set; } = null!; + [Required] + [DataMember(Name = "document", Order = 1), JsonPropertyName("document"), JsonPropertyOrder(1), YamlMember(Alias = "document", Order = 1)] + public required virtual WorkflowDefinitionMetadata Document { get; set; } /// - /// Gets/sets the workflow definition's description + /// Gets/sets the workflow's input definition, if any /// - [DataMember(Order = 4, Name = "description"), JsonPropertyName("description"), YamlMember(Alias = "description")] - public virtual string? Description { get; set; } + [DataMember(Name = "input", Order = 2), JsonPropertyName("input"), JsonPropertyOrder(2), YamlMember(Alias = "input", Order = 3)] + public virtual InputDataModelDefinition? Input { get; set; } /// - /// Gets/sets the workflow definition's version + /// Gets/sets a collection that contains reusable components for the workflow definition /// - [DataMember(Order = 5, Name = "version", IsRequired = true), JsonPropertyName("version"), YamlMember(Alias = "version", ScalarStyle = ScalarStyle.SingleQuoted), Required, MinLength(1)] - public virtual string Version { get; set; } = null!; + [DataMember(Name = "use", Order = 3), JsonPropertyName("use"), JsonPropertyOrder(3), YamlMember(Alias = "use", Order = 3)] + public virtual ComponentDefinitionCollection? Use { get; set; } /// - /// Gets/sets the of the Serverless Workflow schema to use + /// Gets/sets a name/value mapping of the tasks to perform /// [Required, MinLength(1)] - [DataMember(Order = 6, Name = "specVersion", IsRequired = true), JsonPropertyName("specVersion"), YamlMember(Alias = "specVersion", ScalarStyle = ScalarStyle.SingleQuoted)] - public virtual string SpecVersion { get; set; } = null!; - - /// - /// Gets/sets the language the workflow definition's expressions are expressed in - /// - [Required, DefaultValue(RuntimeExpressionLanguage.JQ)] - [DataMember(Order = 7, Name = "expressionLang"), JsonPropertyName("expressionLang"), YamlMember(Alias = "expressionLang")] - public virtual string ExpressionLanguage { get; set; } = RuntimeExpressionLanguage.JQ; - - /// - /// Gets/sets alist containing the workflow definition's annotations - /// - [DataMember(Order = 8, Name = "annotations"), JsonPropertyName("annotations"), YamlMember(Alias = "annotations")] - public virtual List? Annotations { get; set; } - - /// - /// Gets/sets the workflow definition's metadata - /// - [DataMember(Order = 9, Name = "metadata"), JsonPropertyName("metadata"), YamlMember(Alias = "metadata")] - public virtual DynamicMapping? Metadata { get; set; } - - /// - /// Gets/sets the that represents the workflow definition's data input - /// - [DataMember(Order = 10, Name = "dataInputSchema"), JsonPropertyName("dataInputSchema"), YamlMember(Alias = "dataInputSchema")] - [JsonConverter(typeof(OneOfConverter))] - protected virtual OneOf? DataInputSchemaValue { get; set; } - - /// - /// Gets/sets the object used to configure the workflow definition's data input schema - /// - [IgnoreDataMember, JsonIgnore, YamlIgnore] - public virtual DataInputSchemaDefinition? DataInputSchema - { - get - { - return this.DataInputSchemaValue?.T1Value; - } - set - { - if (value == null) this.DataInputSchemaValue = null; - else this.DataInputSchemaValue = value; - } - } - - /// - /// Gets/sets an uri pointing at the workflow definition's input data schema - /// - [IgnoreDataMember, JsonIgnore, YamlIgnore] - public virtual Uri? DataInputSchemaUri - { - get - { - return this.DataInputSchemaValue?.T2Value; - } - set - { - if (value == null) - this.DataInputSchemaValue = null; - else - this.DataInputSchemaValue = value; - } - } - - /// - /// Gets/sets the that represents the workflow definition's secrets - /// - [DataMember(Order = 11, Name = "secrets"), JsonPropertyName("secrets"), YamlMember(Alias = "secrets")] - [JsonConverter(typeof(OneOfConverter, Uri>))] - protected virtual OneOf, Uri>? SecretsValue { get; set; } - - /// - /// Gets/sets alist containing the workflow definition's secrets - /// - [IgnoreDataMember, JsonIgnore, YamlIgnore] - public virtual List? Secrets - { - get - { - return this.SecretsValue?.T1Value; - } - set - { - if (value == null) this.SecretsValue = null; - else this.SecretsValue = value; - } - } - - /// - /// Gets/sets an uri pointing at a file containing the workflow definition's secrets - /// - [IgnoreDataMember, JsonIgnore, YamlIgnore] - public virtual Uri? SecretsUri - { - get - { - return this.SecretsValue?.T2Value; - } - set - { - if (value == null) this.SecretsValue = null; - else this.SecretsValue = value; - } - } - - /// - /// Gets/sets the that represents the workflow definition's authentication definitions - /// - [DataMember(Order = 12, Name = "auth"), JsonPropertyName("auth"), YamlMember(Alias = "auth")] - [JsonConverter(typeof(OneOfConverter, Uri>))] - protected virtual OneOf, Uri>? AuthValue { get; set; } + [DataMember(Name = "do", Order = 4), JsonPropertyName("do"), JsonPropertyOrder(4), YamlMember(Alias = "do", Order = 4)] + public required virtual EquatableDictionary Do { get; set; } = []; /// - /// Gets/sets a list containing the workflow definition's authentication definition collection + /// Gets/sets a name/value mapping of the tasks to perform /// - [IgnoreDataMember, JsonIgnore, YamlIgnore] - public virtual List? Auth - { - get - { - return this.AuthValue?.T1Value; - } - set - { - if (value == null) - this.AuthValue = null; - else - this.AuthValue = value; - } - } + [DataMember(Name = "timeout", Order = 5), JsonPropertyName("timeout"), JsonPropertyOrder(5), YamlMember(Alias = "timeout", Order = 5)] + public virtual TimeoutDefinition? Timeout { get; set; } /// - /// Gets/sets an uri pointing at a file containing the workflow definition's authentication definition collection + /// Gets/sets the workflow's output definition, if any /// - [IgnoreDataMember, JsonIgnore, YamlIgnore] - public virtual Uri? AuthUri - { - get - { - return this.AuthValue?.T2Value; - } - set - { - if (value == null) - this.AuthValue = null; - else - this.AuthValue = value; - } - } + [DataMember(Name = "output", Order = 6), JsonPropertyName("output"), JsonPropertyOrder(6), YamlMember(Alias = "output", Order = 6)] + public virtual OutputDataModelDefinition? Output { get; set; } /// - /// Gets/sets the that represents the workflow definition's constants + /// Gets/sets the definition of the workflow's schedule, if any /// - [DataMember(Order = 13, Name = "constants"), JsonPropertyName("constants"), YamlMember(Alias = "constants")] - [JsonConverter(typeof(OneOfConverter))] - protected virtual OneOf? ConstantsValue { get; set; } - - /// - /// Gets/sets a containing the 's constants - /// - [IgnoreDataMember, JsonIgnore, YamlIgnore] - public virtual DynamicMapping? Constants - { - get - { - return this.ConstantsValue?.T1Value; - } - set - { - if (value == null) this.ConstantsValue = null; - else this.ConstantsValue = new(value); - } - } - - /// - /// Gets/sets an pointing at a file containing the 's constants - /// - [IgnoreDataMember, JsonIgnore, YamlIgnore] - public virtual Uri? ConstantsUri - { - get - { - return this.ConstantsValue?.T2Value; - } - set - { - if (value == null) this.ConstantsValue = null; - else this.ConstantsValue = value; - } - } - - /// - /// Gets/sets the that represents the workflow definition's collection - /// - [DataMember(Order = 14, Name = "events"), JsonPropertyName("events"), YamlMember(Alias = "events")] - [JsonConverter(typeof(OneOfConverter, Uri>))] - protected virtual OneOf, Uri>? EventsValue { get; set; } - - /// - /// Gets/sets a containing the 's s - /// - [IgnoreDataMember, JsonIgnore, YamlIgnore] - public virtual List? Events - { - get - { - return this.EventsValue?.T1Value; - } - set - { - if (value == null) this.EventsValue = null; - else this.EventsValue = value; - } - } - - /// - /// Gets/sets an pointing at a file containing the 's collection - /// - [IgnoreDataMember, JsonIgnore, YamlIgnore] - public virtual Uri? EventsUri - { - get - { - return this.EventsValue?.T2Value; - } - set - { - if (value == null) this.EventsValue = null; - else this.EventsValue = value; - } - } - - /// - /// Gets/sets the that represents the workflow definition's collection - /// - [DataMember(Order = 15, Name = "functions"), JsonPropertyName("functions"), YamlMember(Alias = "functions")] - [JsonConverter(typeof(OneOfConverter, Uri>))] - protected virtual OneOf, Uri>? FunctionsValue { get; set; } - - /// - /// Gets/sets a containing the 's s - /// - [IgnoreDataMember, JsonIgnore, YamlIgnore] - public virtual List? Functions - { - get - { - return this.FunctionsValue?.T1Value; - } - set - { - if (value == null) this.FunctionsValue = null; - else this.FunctionsValue = value; - } - } - - /// - /// Gets/sets an pointing at a file containing the 's collection - /// - [IgnoreDataMember, JsonIgnore, YamlIgnore] - public virtual Uri? FunctionsUri - { - get - { - return this.FunctionsValue?.T2Value; - } - set - { - if (value == null) this.FunctionsValue = null; - else this.FunctionsValue = value; - } - } - - /// - /// Gets/sets the object used to configure the workflow definition's execution timeouts - /// - [DataMember(Order = 16, Name = "timeouts"), JsonPropertyName("timeouts"), YamlMember(Alias = "timeouts")] - [JsonConverter(typeof(OneOfConverter))] - public virtual OneOf? TimeoutsValue { get; set; } - - /// - /// Gets/sets the object used to configure the 's execution timeouts - /// - [IgnoreDataMember, JsonIgnore, YamlIgnore] - public virtual WorkflowTimeoutDefinition? Timeouts - { - get - { - return this.TimeoutsValue?.T1Value; - } - set - { - if (value == null) this.TimeoutsValue = null; - else this.TimeoutsValue = value; - } - } - - /// - /// Gets/sets an pointing at the 's - /// - [IgnoreDataMember, JsonIgnore, YamlIgnore] - public virtual Uri? TimeoutsUri - { - get - { - return this.TimeoutsValue?.T2Value; - } - set - { - if (value == null) this.TimeoutsValue = null; - else this.TimeoutsValue = value; - } - } - - /// - /// Gets/sets the that represents the workflow definition's collection - /// - [DataMember(Order = 17, Name = "retries"), JsonPropertyName("retries"), YamlMember(Alias = "retries")] - [JsonConverter(typeof(OneOfConverter, Uri>))] - protected virtual OneOf, Uri>? RetriesValue { get; set; } - - /// - /// Gets/sets a containing the 's s - /// - [IgnoreDataMember, JsonIgnore, YamlIgnore] - public virtual List? Retries - { - get - { - return this.RetriesValue?.T1Value; - } - set - { - if (value == null) this.RetriesValue = null; - else this.RetriesValue = value; - } - } - - /// - /// Gets/sets an pointing at a file containing the 's collection - /// - [IgnoreDataMember, JsonIgnore, YamlIgnore] - public virtual Uri? RetriesUri - { - get - { - return this.RetriesValue?.T2Value; - } - set - { - if (value == null) this.RetriesValue = null; - else this.RetriesValue = value; - } - } - - /// - /// Gets/sets the that defines the workflow definition's start - /// - [DataMember(Order = 18, Name = "start"), JsonPropertyName("start"), YamlMember(Alias = "start")] - [JsonConverter(typeof(OneOfConverter))] - protected virtual OneOf? StartValue { get; set; } - - /// - /// Gets/sets the object used to configure the 's - /// - [IgnoreDataMember, JsonIgnore, YamlIgnore] - public virtual StartDefinition? Start - { - get - { - return this.StartValue?.T1Value; - } - set - { - if (value == null) this.StartValue = null; - else this.StartValue = value; - } - } - - /// - /// Gets/sets the name of the 's start state definition - /// - [IgnoreDataMember, JsonIgnore, YamlIgnore] - public virtual string? StartStateName - { - get - { - return this.StartValue?.T2Value; - } - set - { - if (value == null) this.StartValue = null; - else this.StartValue = value; - } - } - - /// - /// Gets/sets an containing the workflow definition's state definitions - /// - [DataMember(Order = 19, Name = "states"), JsonPropertyName("states"), YamlMember(Alias = "states")] - public virtual List States { get; set; } = new(); - - /// - /// Gets/sets a boolean indicating whether or not actions should automatically be retried on unchecked errors. Defaults to false. - /// - [DataMember(Order = 20, Name = "autoRetries"), JsonPropertyName("autoRetries"), YamlMember(Alias = "autoRetries")] - public virtual bool AutoRetries { get; set; } - - /// - /// Gets/sets a boolean indicating whether or not to keep instances of the workflow definition active even if there are no active execution paths. Instance can be terminated via 'terminate end definition' or reaching defined 'execTimeout' - /// - [DataMember(Order = 21, Name = "keepActive"), JsonPropertyName("keepActive"), YamlMember(Alias = "keepActive")] - public virtual bool KeepActive { get; set; } = false; - - /// - /// Gets/sets the that represents the workflow definition's s - /// - [DataMember(Order = 22, Name = "extensions"), JsonPropertyName("extensions"), YamlMember(Alias = "extensions")] - public virtual OneOf, Uri>? ExtensionsValue { get; set; } - - /// - /// Gets/sets a containing the 's collection - /// - [IgnoreDataMember, JsonIgnore, YamlIgnore] - public virtual List? Extensions - { - get - { - return this.ExtensionsValue?.T1Value; - } - set - { - if (value == null) this.ExtensionsValue = null; - else this.ExtensionsValue = value; - } - } - - /// - /// Gets/sets an pointing at a file containing the 's collection - /// - [IgnoreDataMember, JsonIgnore, YamlIgnore] - public virtual Uri? ExtensionsUri - { - get - { - return this.ExtensionsValue?.T2Value; - } - set - { - if (value == null) this.ExtensionsValue = null; - else this.ExtensionsValue = value; - } - } - - /// - [DataMember(Order = 23, Name = "extensionData"), JsonExtensionData] - public IDictionary? ExtensionData { get; set; } - - /// - /// Gets the start state definition - /// - /// The state definition the starts with - public virtual StateDefinition GetStartState() - { - var stateName = this.StartStateName; - if (this.Start != null) stateName = this.Start.StateName; - if (string.IsNullOrWhiteSpace(stateName)) return this.States.First(); - if (!this.TryGetState(stateName, out var state)) throw new NullReferenceException($"Failed to find a state definition with name '{state}'"); - return state; - } - - /// - /// Attempts to the start state definition - /// - /// The start state definition - /// A boolean indicating whether or not the 's start state definition could be found - public virtual bool TryGetStartState(out StateDefinition state) - { - state = this.GetStartState()!; - return state != null; - } - - /// - /// Gets the start state definition - /// - /// The expected type of the 's start state definition - /// The start state definition - public virtual TState? GetStartState() where TState : StateDefinition => this.GetStartState() as TState; - - /// - /// Attempts to the start state definition - /// - /// The start state definition - /// A boolean indicating whether or not the 's start state definition could be found - public virtual bool TryGetStartState(out TState state) - where TState : StateDefinition - { - state = this.GetStartState()!; - return state != null; - } - - /// - /// Gets the state definition with the specified name - /// - /// The name of the state definition to get - /// The state definition with the specified name, if any - public virtual StateDefinition? GetState(string name) - { - if (string.IsNullOrWhiteSpace(name)) throw new ArgumentNullException(nameof(name)); - return this.States?.FirstOrDefault(s => s.Name == name); - } - - /// - /// Attempts to retrieve the state definition with the specified name - /// - /// The name of the state definition to retrieve - /// The state definition with the specified name, if any - /// A boolean indicating whether or not a state definition with the specified name could be found - public virtual bool TryGetState(string name, out StateDefinition state) - { - if (string.IsNullOrWhiteSpace(name)) throw new ArgumentNullException(nameof(name)); - state = this.GetState(name)!; - return state != null; - } - - /// - /// Gets the state definition with the specified name - /// - /// The expected type of the state definition with the specified name - /// The name of the state definition to get - /// The state definition with the specified name, if any - public virtual TState? GetState(string name) - where TState : StateDefinition - { - if (string.IsNullOrWhiteSpace(name)) throw new ArgumentNullException(nameof(name)); - return this.GetState(name) as TState; - } - - /// - /// Attempts to retrieve the state definition with the specified name - /// - /// The expected type of the state definition with the specified name - /// The name of the state definition to retrieve - /// The state definition with the specified name, if any - /// A boolean indicating whether or not a state definition with the specified name could be found - public virtual bool TryGetState(string name, out TState state) - where TState : StateDefinition - { - if (string.IsNullOrWhiteSpace(name)) throw new ArgumentNullException(nameof(name)); - state = this.GetState(name)!; - return state != null; - } - - /// - /// Gets the with the specified name - /// - /// The name of the to get - /// The with the specified name, if any - public virtual EventDefinition? GetEvent(string name) - { - if (string.IsNullOrWhiteSpace(name)) throw new ArgumentNullException(nameof(name)); - return this.Events?.FirstOrDefault(e => e.Name == name); - } - - /// - /// Attempts to retrieve the with the specified name - /// - /// The name of the to retrieve - /// The with the specified name, if any - /// A boolean indicating whether or not a with the specified name could be found - public virtual bool TryGetEvent(string name, out EventDefinition e) - { - if (string.IsNullOrWhiteSpace(name)) throw new ArgumentNullException(nameof(name)); - e = this.GetEvent(name)!; - return e != null; - } - - /// - /// Gets the with the specified name - /// - /// The name of the to get - /// The with the specified name, if any - public virtual FunctionDefinition? GetFunction(string name) - { - if (string.IsNullOrWhiteSpace(name)) throw new ArgumentNullException(nameof(name)); - return this.Functions?.FirstOrDefault(e => e.Name == name); - } - - /// - /// Attempts to retrieve the with the specified name - /// - /// The name of the to retrieve - /// The with the specified name, if any - /// A boolean indicating whether or not a with the specified name could be found - public virtual bool TryGetFunction(string name, out FunctionDefinition function) - { - if (string.IsNullOrWhiteSpace(name)) throw new ArgumentNullException(nameof(name)); - function = this.GetFunction(name)!; - return function != null; - } - - /// - /// Gets the with the specified name - /// - /// The name of the to get - /// The with the specified name, if any - public virtual AuthenticationDefinition? GetAuthentication(string name) - { - if (string.IsNullOrWhiteSpace(name)) throw new ArgumentNullException(nameof(name)); - return this.Auth?.FirstOrDefault(e => e.Name == name); - } - - /// - /// Attempts to retrieve the with the specified name - /// - /// The name of the to retrieve - /// The with the specified name, if any - /// A boolean indicating whether or not a with the specified name could be found - public virtual bool TryGetAuthentication(string name, out AuthenticationDefinition authentication) - { - if (string.IsNullOrWhiteSpace(name)) throw new ArgumentNullException(nameof(name)); - authentication = this.GetAuthentication(name)!; - return authentication != null; - } - - /// - public override string ToString() => $"{this.Id} {this.Version}"; + [DataMember(Name = "schedule", Order = 7), JsonPropertyName("schedule"), JsonPropertyOrder(7), YamlMember(Alias = "schedule", Order = 7)] + public virtual WorkflowScheduleDefinition? Schedule { get; set; } /// - /// Creates a new used to build a new + /// Gets/sets the configuration of how the runtime expressions /// - /// The id of the to create - /// The name of the to create - /// The version of the to create - /// A new - public static IWorkflowBuilder Create(string id, string name, string version) - { - if (string.IsNullOrWhiteSpace(id)) throw new ArgumentNullException(nameof(id)); - if (string.IsNullOrWhiteSpace(name)) throw new ArgumentNullException(nameof(name)); - if (string.IsNullOrWhiteSpace(version)) throw new ArgumentNullException(nameof(version)); - return new WorkflowBuilder() - .WithId(id) - .WithName(name) - .WithVersion(version); - } + [DataMember(Name = "evaluate", Order = 8), JsonPropertyName("evaluate"), JsonPropertyOrder(8), YamlMember(Alias = "evaluate", Order = 8)] + public virtual RuntimeExpressionEvaluationConfiguration? Evaluate { get; set; } } diff --git a/src/ServerlessWorkflow.Sdk/Models/WorkflowDefinitionMetadata.cs b/src/ServerlessWorkflow.Sdk/Models/WorkflowDefinitionMetadata.cs new file mode 100644 index 0000000..28f8907 --- /dev/null +++ b/src/ServerlessWorkflow.Sdk/Models/WorkflowDefinitionMetadata.cs @@ -0,0 +1,75 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +using YamlDotNet.Core; + +namespace ServerlessWorkflow.Sdk.Models; + +/// +/// Represents the metadata of a workflow, including its name, version, and description. +/// +[DataContract] +public record WorkflowDefinitionMetadata +{ + + /// + /// Gets the namespace to use by default for workflow definitions + /// + public const string DefaultNamespace = "default"; + + /// + /// Gets/sets the version of the DSL used to define the workflow + /// + [Required, MinLength(1)] + [DataMember(Name = "dsl", Order = 1), JsonPropertyName("dsl"), JsonPropertyOrder(1), YamlMember(Alias = "dsl", Order = 1, ScalarStyle = ScalarStyle.SingleQuoted)] + public required virtual string Dsl { get; set; } = null!; + + /// + /// Gets/sets the workflow's namespace + /// + [DataMember(Name = "namespace", Order = 2), JsonPropertyName("namespace"), JsonPropertyOrder(2), YamlMember(Alias = "namespace", Order = 2)] + public virtual string Namespace { get; set; } = DefaultNamespace; + + /// + /// Gets/sets the workflow's name + /// + [Required, MinLength(1)] + [DataMember(Name = "name", Order = 3), JsonPropertyName("name"), JsonPropertyOrder(3), YamlMember(Alias = "name", Order = 3)] + public required virtual string Name { get; set; } = null!; + + /// + /// Gets/sets the workflow's semantic version. Defaults to `latest` + /// + [Required, MinLength(1)] + [DataMember(Name = "version", Order = 4), JsonPropertyName("version"), JsonPropertyOrder(4), YamlMember(Alias = "version", Order = 4, ScalarStyle = ScalarStyle.SingleQuoted)] + public required virtual string Version { get; set; } = "latest"; + + /// + /// Gets/sets the workflow's title, if any + /// + [DataMember(Name = "title", Order = 5), JsonPropertyName("title"), JsonPropertyOrder(5), YamlMember(Alias = "title", Order = 5)] + public virtual string? Title { get; set; } + + /// + /// Gets/sets the workflow's Markdown summary, if any + /// + [DataMember(Name = "summary", Order = 6), JsonPropertyName("summary"), JsonPropertyOrder(6), YamlMember(Alias = "summary", Order = 6)] + public virtual string? Summary { get; set; } + + /// + /// Gets/sets a key/value mapping of the workflow's tags, if any + /// + [DataMember(Name = "tags", Order = 7), JsonPropertyName("tags"), JsonPropertyOrder(7), YamlMember(Alias = "tags", Order = 7)] + public virtual EquatableDictionary? Tags { get; set; } + +} \ No newline at end of file diff --git a/src/ServerlessWorkflow.Sdk/Models/WorkflowExecutionTimeoutDefinition.cs b/src/ServerlessWorkflow.Sdk/Models/WorkflowExecutionTimeoutDefinition.cs deleted file mode 100644 index 835a418..0000000 --- a/src/ServerlessWorkflow.Sdk/Models/WorkflowExecutionTimeoutDefinition.cs +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -using ServerlessWorkflow.Sdk.Serialization.Json; - -namespace ServerlessWorkflow.Sdk.Models; - -/// -/// Represents an object used to define the execution timeout for a workflow instance -/// -[DataContract] -public class WorkflowExecutionTimeoutDefinition - : IExtensible -{ - - /// - /// Gets/sets the duration after which the workflow's execution will time out - /// - [Required] - [DataMember(Order = 1, Name = "duration", IsRequired = true), JsonPropertyName("duration"), YamlMember(Alias = "duration")] - [JsonConverter(typeof(Iso8601TimeSpanConverter))] - public virtual TimeSpan Duration { get; set; } - - /// - /// Gets/sets a boolean indicating whether or not to terminate the workflow execution. Defaults to true. - /// - [DefaultValue(true)] - [DataMember(Order = 2, Name = "interrupt", IsRequired = true), JsonPropertyName("interrupt"), YamlMember(Alias = "interrupt")] - public virtual bool Interrupt { get; set; } = true; - - /// - /// Gets/sets the name of a workflow state to be executed before workflow instance is terminated - /// - [DataMember(Order = 3, Name = "runBefore", IsRequired = true), JsonPropertyName("runBefore"), YamlMember(Alias = "runBefore")] - public virtual string? RunBefore { get; set; } - - /// - [DataMember(Order = 4, Name = "extensionData"), JsonExtensionData] - public IDictionary? ExtensionData { get; set; } - -} \ No newline at end of file diff --git a/src/ServerlessWorkflow.Sdk/Models/WorkflowScheduleDefinition.cs b/src/ServerlessWorkflow.Sdk/Models/WorkflowScheduleDefinition.cs new file mode 100644 index 0000000..82231a4 --- /dev/null +++ b/src/ServerlessWorkflow.Sdk/Models/WorkflowScheduleDefinition.cs @@ -0,0 +1,47 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Models; + +/// +/// Represents the definition of a workflow's schedule +/// +[DataContract] +public record WorkflowScheduleDefinition +{ + + /// + /// Gets/sets an object used to document the defined workflow + /// + [DataMember(Name = "every", Order = 1), JsonPropertyName("every"), JsonPropertyOrder(1), YamlMember(Alias = "every", Order = 1)] + public virtual Duration? Every { get; set; } + + /// + /// Gets/sets the schedule using a CRON expression, e.g., '0 0 * * *' for daily at midnight. + /// + [DataMember(Name = "cron", Order = 2), JsonPropertyName("cron"), JsonPropertyOrder(2), YamlMember(Alias = "cron", Order = 2)] + public virtual string? Cron { get; set; } + + /// + /// Gets/sets a delay duration, if any, that the workflow must wait before starting again after it completes. In other words, when this workflow completes, it should run again after the specified amount of time. + /// + [DataMember(Name = "after", Order = 3), JsonPropertyName("after"), JsonPropertyOrder(3), YamlMember(Alias = "after", Order = 3)] + public virtual Duration? After { get; set; } + + /// + /// Gets/sets the events that trigger the workflow execution. + /// + [DataMember(Name = "on", Order = 4), JsonPropertyName("on"), JsonPropertyOrder(4), YamlMember(Alias = "on", Order = 4)] + public virtual EventConsumptionStrategyDefinition? On { get; set; } + +} \ No newline at end of file diff --git a/src/ServerlessWorkflow.Sdk/Models/WorkflowTimeoutDefinition.cs b/src/ServerlessWorkflow.Sdk/Models/WorkflowTimeoutDefinition.cs deleted file mode 100644 index a5a90d0..0000000 --- a/src/ServerlessWorkflow.Sdk/Models/WorkflowTimeoutDefinition.cs +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace ServerlessWorkflow.Sdk.Models; - -/// -/// Represents the object used to configure a workflow definition's timeout -/// -[DataContract] -public class WorkflowTimeoutDefinition -{ - - /// - /// Gets/sets the workflow definition's execution timeout - /// - [DataMember(Order = 1, Name = "workflowExecTimeout"), JsonPropertyName("workflowExecTimeout"), YamlMember(Alias = "workflowExecTimeout")] - public virtual OneOf? WorkflowExecTimeout { get; set; } - - /// - /// Gets/sets the duration after which to timeout states by default - /// - [DataMember(Order = 2, Name = "stateExecTimeout"), JsonPropertyName("stateExecTimeout"), YamlMember(Alias = "stateExecTimeout")] - [JsonConverter(typeof(Iso8601NullableTimeSpanConverter))] - public TimeSpan? StateExecutionTimeout { get; set; } - - /// - /// Gets/sets the duration after which to timeout actions by default - /// - [DataMember(Order = 3, Name = "actionExecTimeout"), JsonPropertyName("actionExecTimeout"), YamlMember(Alias = "actionExecTimeout")] - [JsonConverter(typeof(Iso8601NullableTimeSpanConverter))] - public TimeSpan? ActionExecTimeout { get; set; } - - /// - /// Gets/sets the duration after which to timeout branches by default - /// - [DataMember(Order = 4, Name = "branchExecTimeout"), JsonPropertyName("branchExecTimeout"), YamlMember(Alias = "branchExecTimeout")] - [JsonConverter(typeof(Iso8601NullableTimeSpanConverter))] - public TimeSpan? BranchExecutionTimeout { get; set; } - - /// - /// Gets/sets the duration after which to timeout events by default - /// - [DataMember(Order = 5, Name = "eventTimeout"), JsonPropertyName("eventTimeout"), YamlMember(Alias = "eventTimeout")] - [JsonConverter(typeof(Iso8601NullableTimeSpanConverter))] - public TimeSpan? EventTimeout { get; set; } - - /// - [DataMember(Order = 6, Name = "extensionData"), JsonExtensionData] - public IDictionary? ExtensionData { get; set; } - -} \ No newline at end of file diff --git a/src/ServerlessWorkflow.Sdk/NamingConvention.cs b/src/ServerlessWorkflow.Sdk/NamingConvention.cs new file mode 100644 index 0000000..619e365 --- /dev/null +++ b/src/ServerlessWorkflow.Sdk/NamingConvention.cs @@ -0,0 +1,39 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk; + +/// +/// Exposes constants about the Serverless Workflow DSL naming convention +/// +public static class NamingConvention +{ + + static readonly int _nameMaxLength = 63; + + /// + /// Determines whether or not the specified value is a valid name, following RFC 1123 DNS label name + /// + /// The name to check + /// A boolean indicating whether or not the specified name follows specification for RFC 1123 DNS label name + public static bool IsValidName(string name) + { + if (string.IsNullOrWhiteSpace(name)) throw new ArgumentNullException(nameof(name)); + return name.Length <= _nameMaxLength + && name.IsLowercased() + && name.IsAlphanumeric('-') + && char.IsLetterOrDigit(name.First()) + && char.IsLetterOrDigit(name.Last()); + } + +} diff --git a/src/ServerlessWorkflow.Sdk/OAuth2GrantType.cs b/src/ServerlessWorkflow.Sdk/OAuth2GrantType.cs deleted file mode 100644 index 49ad6c6..0000000 --- a/src/ServerlessWorkflow.Sdk/OAuth2GrantType.cs +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace ServerlessWorkflow.Sdk; - -/// -/// Enumerates all OAuth 2 grant types supported for workflow runtime token generation -/// -public static class OAuth2GrantType -{ - - /// - /// Indicates the resource-owner password credentials grant type - /// - public const string Password = "password"; - - /// - /// Indicates the client credentials grant type - /// - public const string ClientCredentials = "clientCredentials"; - - /// - /// Indicates the token exchange grant type - /// - public const string TokenExchange = "urn:ietf:params:oauth:grant-type:token-exchange"; - -} diff --git a/src/ServerlessWorkflow.Sdk/OAuth2TokenType.cs b/src/ServerlessWorkflow.Sdk/OAuth2TokenType.cs deleted file mode 100644 index a7735c2..0000000 --- a/src/ServerlessWorkflow.Sdk/OAuth2TokenType.cs +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace ServerlessWorkflow.Sdk; - -/// -/// Enumerates all supported token types -/// -public static class OAuth2TokenType -{ - - /// - /// Indicates an access token - /// - public const string AccessToken = "urn:ietf:params:oauth:token-type:access_token"; - - /// - /// Indicates an identity token - /// - public const string IdentityToken = "urn:ietf:params:oauth:token-type:id_token"; - -} diff --git a/src/ServerlessWorkflow.Sdk/ParallelCompletionType.cs b/src/ServerlessWorkflow.Sdk/ParallelCompletionType.cs deleted file mode 100644 index c370131..0000000 --- a/src/ServerlessWorkflow.Sdk/ParallelCompletionType.cs +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace ServerlessWorkflow.Sdk; - -/// -/// Enumerates all parallel completion types -/// -public static class ParallelCompletionType -{ - - /// - /// Indicates that all branches should be completed before completing the parallel execution - /// - public const string AllOf = "allOf"; - - /// - /// Indicates that 'N' amount of branches should complete before completing the parallel execution, thus potentially cancelling running branches - /// - public const string AtLeastN = "atLeast"; - -} diff --git a/src/ServerlessWorkflow.Sdk/InvocationMode.cs b/src/ServerlessWorkflow.Sdk/RuntimeExpressionEvaluationMode.cs similarity index 53% rename from src/ServerlessWorkflow.Sdk/InvocationMode.cs rename to src/ServerlessWorkflow.Sdk/RuntimeExpressionEvaluationMode.cs index e5d0991..60914ca 100644 --- a/src/ServerlessWorkflow.Sdk/InvocationMode.cs +++ b/src/ServerlessWorkflow.Sdk/RuntimeExpressionEvaluationMode.cs @@ -1,4 +1,4 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors +// Copyright © 2024-Present The Serverless Workflow Specification Authors // // Licensed under the Apache License, Version 2.0 (the "License"), // you may not use this file except in compliance with the License. @@ -14,19 +14,18 @@ namespace ServerlessWorkflow.Sdk; /// -/// Enumerates all invocation modes +/// Exposes the default runtime expression evaluation modes /// -public static class InvocationMode +public static class RuntimeExpressionEvaluationMode { /// - /// Indicates a synchronous invocation mode + /// Gets the 'strict' runtime expression evaluation mode, which requires all expressions to be enclosed within ${ } for proper identification and evaluation. /// - public const string Synchronous = "sync"; - + public const string Strict = "strict"; /// - /// Indicates an asynchronous invocation mode + /// Gets the 'loose' runtime expression evaluation mode, which evaluates any value provided. If the evaluation fails, it results in a string with the expression as its content. /// - public const string Asynchronous = "async"; + public const string Loose = "loose"; -} +} \ No newline at end of file diff --git a/src/ServerlessWorkflow.Sdk/RuntimeExpressions.cs b/src/ServerlessWorkflow.Sdk/RuntimeExpressions.cs new file mode 100644 index 0000000..642e5c8 --- /dev/null +++ b/src/ServerlessWorkflow.Sdk/RuntimeExpressions.cs @@ -0,0 +1,72 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk; + +/// +/// Exposes statics and constants about ServerlessWorkflow runtime expressions +/// +public static class RuntimeExpressions +{ + + /// + /// Exposes the runtime expression language supported by default + /// + public static class Languages + { + + /// + /// Gets the 'jq' runtime expression language + /// + public const string JQ = "jq"; + + } + + /// + /// Exposes default ServerlessWorkflow runtime expression arguments + /// + public static class Arguments + { + + /// + /// Gets the name of the 'workflow' argument, used to access the current workflow resource + /// + public const string Workflow = "workflow"; + /// + /// Gets the name of the 'context' argument, used to access the current context data + /// + public const string Context = "context"; + /// + /// Gets the name of the 'item' argument, used to access the current item of the collection being enumerated + /// + public const string Each = "item"; + /// + /// Gets the name of the 'index' argument, used to access the index of the current item of the collection being enumerated + /// + public const string Index = "index"; + /// + /// Gets the name of the 'task' argument + /// + public const string Task = "task"; + /// + /// Gets the name of the 'input' argument + /// + public const string Input = "input"; + /// + /// Gets the name of the 'error' argument, used to access the current error, if any + /// + public const string Error = "error"; + + } + +} \ No newline at end of file diff --git a/src/ServerlessWorkflow.Sdk/Serialization/Json/DictionaryConverter.cs b/src/ServerlessWorkflow.Sdk/Serialization/Json/DictionaryConverter.cs deleted file mode 100644 index 6d9ba3f..0000000 --- a/src/ServerlessWorkflow.Sdk/Serialization/Json/DictionaryConverter.cs +++ /dev/null @@ -1,65 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -using Neuroglia; - -namespace ServerlessWorkflow.Sdk.Serialization; - -/// -/// Represents the used to serialize and deserialize instances, and unwraps their values (as opposed to keeping JsonElement values) -/// -public class DictionaryConverter - : JsonConverter> -{ - - /// - public override bool CanConvert(Type typeToConvert) => typeToConvert == typeof(IDictionary); - - /// - public override IDictionary? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) - { - var doc = JsonDocument.ParseValue(ref reader); - var result = Serializer.Json.Deserialize>(doc.RootElement.ToString())!; - return result.ToDictionary(kvp => kvp.Key, kvp => kvp.Value is JsonElement jsonElement ? jsonElement.ToObject() : kvp.Value)!; - } - - /// - public override void Write(Utf8JsonWriter writer, IDictionary value, JsonSerializerOptions options) - { - JsonSerializer.Serialize(writer, value, options); - } - -} - -/// -/// Represents the used to serialize and deserialize s -/// -public class DynamicMappingConverter - : JsonConverter -{ - - /// - public override DynamicMapping? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) - { - var doc = JsonDocument.ParseValue(ref reader); - var result = Serializer.Json.Deserialize>(doc.RootElement.ToString())!; - return new(result.ToDictionary(kvp => kvp.Key, kvp => kvp.Value is JsonElement jsonElement ? jsonElement.ToObject() : kvp.Value)!); - } - - /// - public override void Write(Utf8JsonWriter writer, DynamicMapping value, JsonSerializerOptions options) - { - JsonSerializer.Serialize(writer, value.Properties, options); - } - -} diff --git a/src/ServerlessWorkflow.Sdk/Serialization/Json/Iso8601TimeSpanConverter.cs b/src/ServerlessWorkflow.Sdk/Serialization/Json/Iso8601TimeSpanConverter.cs deleted file mode 100644 index 7e41a64..0000000 --- a/src/ServerlessWorkflow.Sdk/Serialization/Json/Iso8601TimeSpanConverter.cs +++ /dev/null @@ -1,60 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace ServerlessWorkflow.Sdk.Serialization.Json; - -/// -/// Represents the used to convert s from and to ISO 8601 durations -/// -public class Iso8601TimeSpanConverter - : JsonConverter -{ - - /// - public override TimeSpan Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) - { - var iso8601Input = reader.GetString(); - if (string.IsNullOrWhiteSpace(iso8601Input)) return TimeSpan.Zero; - return Iso8601TimeSpan.Parse(iso8601Input); - } - - /// - public override void Write(Utf8JsonWriter writer, TimeSpan value, JsonSerializerOptions options) - { - writer.WriteStringValue(Iso8601TimeSpan.Format(value)); - } - -} - -/// -/// Represents the used to convert s from and to ISO 8601 durations -/// -public class Iso8601NullableTimeSpanConverter - : JsonConverter -{ - - /// - public override TimeSpan? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) - { - var iso8601Input = reader.GetString(); - if (string.IsNullOrWhiteSpace(iso8601Input)) return null; - return Iso8601TimeSpan.Parse(iso8601Input); - } - - /// - public override void Write(Utf8JsonWriter writer, TimeSpan? value, JsonSerializerOptions options) - { - if (value.HasValue) writer.WriteStringValue(Iso8601TimeSpan.Format(value.Value)); - } - -} \ No newline at end of file diff --git a/src/ServerlessWorkflow.Sdk/Serialization/Json/JsonTypeInfoModifiers.cs b/src/ServerlessWorkflow.Sdk/Serialization/Json/JsonTypeInfoModifiers.cs deleted file mode 100644 index 4b55c8d..0000000 --- a/src/ServerlessWorkflow.Sdk/Serialization/Json/JsonTypeInfoModifiers.cs +++ /dev/null @@ -1,145 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -using System.Reflection; -using System.Text.Json.Serialization.Metadata; - -namespace ServerlessWorkflow.Sdk.Serialization; - -/// -/// Defines extension modifiers for s -/// -/// Code taken from https://stackoverflow.com/a/76296944/3637555 -public static partial class JsonTypeInfoModifiers -{ - - /// - /// Includes non public properties in the specified - /// - /// A new used to modify a by including non-public properties - public static Action IncludeNonPublicProperties() => typeInfo => - { - if (typeInfo.Kind != JsonTypeInfoKind.Object) return; - foreach (var type in typeInfo.Type.BaseTypesAndSelf().TakeWhile(b => b != typeof(object))) - IncludeNonPublicProperties(typeInfo, type, p => Attribute.IsDefined(p, typeof(JsonPropertyNameAttribute))); - }; - - /// - /// Includes non public properties in the specified - /// - /// The type to include the non-public properties of - /// A new used to modify a by including non-public properties - public static Action IncludeNonPublicProperties(Type declaredType) => typeInfo => - IncludeNonPublicProperties(typeInfo, declaredType, p => true); - - /// - /// Includes the specified non-public property - /// - /// The type that defines the property to include - /// The name of the property to include - /// A new used to modify a by including non-public properties - public static Action IncludeNonPublicProperty(Type declaredType, string propertyName) => typeInfo => - { - if (typeInfo.Kind != JsonTypeInfoKind.Object || !declaredType.IsAssignableFrom(typeInfo.Type)) return; - var propertyInfo = declaredType.GetProperty(propertyName, BindingFlags.Instance | BindingFlags.NonPublic) ?? throw new ArgumentException(string.Format("Private roperty {0} not found in type {1}", propertyName, declaredType)); - if (typeInfo.Properties.Any(p => p.GetMemberInfo() == propertyInfo)) return; - IncludeProperty(typeInfo, propertyInfo); - }; - - static void IncludeNonPublicProperties(JsonTypeInfo typeInfo, Type declaredType, Func filter) - { - if (typeInfo.Kind != JsonTypeInfoKind.Object || !declaredType.IsAssignableFrom(typeInfo.Type)) return; - var propertyInfos = declaredType.GetProperties(BindingFlags.Instance | BindingFlags.NonPublic); - foreach (var propertyInfo in propertyInfos.Where(p => p.GetIndexParameters().Length == 0 && filter(p))) - IncludeProperty(typeInfo, propertyInfo); - } - - static void IncludeProperty(JsonTypeInfo typeInfo, PropertyInfo propertyInfo) - { - if (propertyInfo.GetIndexParameters().Length > 0) throw new ArgumentException("Indexed properties are not supported."); - var ignore = propertyInfo.GetCustomAttribute(); - if (ignore?.Condition == JsonIgnoreCondition.Always) return; - var name = propertyInfo.GetCustomAttribute()?.Name - ?? typeInfo.Options?.PropertyNamingPolicy?.ConvertName(propertyInfo.Name) - ?? propertyInfo.Name; - var property = typeInfo.Properties.FirstOrDefault(p => p.Name == name); - if (property != null) typeInfo.Properties.Remove(property); - property = typeInfo.CreateJsonPropertyInfo(propertyInfo.PropertyType, name); - property.Get = CreateGetter(typeInfo.Type, propertyInfo.GetGetMethod(true)); - property.Set = CreateSetter(typeInfo.Type, propertyInfo.GetSetMethod(true)); - property.AttributeProvider = propertyInfo; - property.CustomConverter = propertyInfo.GetCustomAttribute()?.ConverterType is { } converterType - ? (JsonConverter?)Activator.CreateInstance(converterType) - : null; - property.Order = propertyInfo.GetCustomAttribute()?.Order ?? 0; - property.IsExtensionData = propertyInfo.GetCustomAttribute() != null; - typeInfo.Properties.Add(property); - } - - delegate TValue RefFunc(ref TObject arg); - - static Func? CreateGetter(Type type, MethodInfo? method) - { - if (method == null) return null; - var myMethod = typeof(JsonTypeInfoModifiers).GetMethod(nameof(JsonTypeInfoModifiers.CreateGetterGeneric), BindingFlags.NonPublic | BindingFlags.Static)!; - return (Func)(myMethod.MakeGenericMethod(new[] { type, method.ReturnType }).Invoke(null, new[] { method })!); - } - - static Func CreateGetterGeneric(MethodInfo method) - { - if (method == null) throw new ArgumentNullException(nameof(method)); - if (typeof(TObject).IsValueType) - { - var func = (RefFunc)Delegate.CreateDelegate(typeof(RefFunc), null, method); - return (o) => { var tObj = (TObject)o; return func(ref tObj); }; - } - else - { - var func = (Func)Delegate.CreateDelegate(typeof(Func), method); - return (o) => func((TObject)o); - } - } - - static Action? CreateSetter(Type type, MethodInfo? method) - { - if (method == null) return null; - var myMethod = typeof(JsonTypeInfoModifiers).GetMethod(nameof(JsonTypeInfoModifiers.CreateSetterGeneric), BindingFlags.NonPublic | BindingFlags.Static)!; - return (Action)(myMethod.MakeGenericMethod(new[] { type, method.GetParameters().Single().ParameterType }).Invoke(null, new[] { method })!); - } - - static Action? CreateSetterGeneric(MethodInfo method) - { - if (method == null) throw new ArgumentNullException(nameof(method)); - if (typeof(TObject).IsValueType) - { - return (o, v) => method.Invoke(o, new[] { v }); - } - else - { - var func = (Action)Delegate.CreateDelegate(typeof(Action), method); - return (o, v) => func((TObject)o, (TValue?)v); - } - } - - static MemberInfo? GetMemberInfo(this JsonPropertyInfo property) => (property.AttributeProvider as MemberInfo); - - static IEnumerable BaseTypesAndSelf(this Type? type) - { - while (type != null) - { - yield return type; - type = type.BaseType; - } - } - -} \ No newline at end of file diff --git a/src/ServerlessWorkflow.Sdk/Serialization/Json/OneOfConverter.cs b/src/ServerlessWorkflow.Sdk/Serialization/Json/OneOfConverter.cs deleted file mode 100644 index b7d4f23..0000000 --- a/src/ServerlessWorkflow.Sdk/Serialization/Json/OneOfConverter.cs +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace ServerlessWorkflow.Sdk.Serialization.Json; - -/// -/// Represents the service used to convert -/// -/// The first type alternative -/// The second type alternative -public class OneOfConverter - : JsonConverter> -{ - - /// - public override OneOf? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) - { - var doc = JsonDocument.ParseValue(ref reader); - try - { - var value = Serializer.Json.Deserialize(doc.RootElement); - if (value == null) return null; - return new(value); - } - catch - { - var value = Serializer.Json.Deserialize(doc.RootElement); - if (value == null) return null; - return new(value); - } - } - - /// - public override void Write(Utf8JsonWriter writer, OneOf value, JsonSerializerOptions options) - { - string? json; - if (value.T1Value != null) json = Serializer.Json.Serialize(value.T1Value); - else json = Serializer.Json.Serialize(value.T2Value); - writer.WriteRawValue(json); - } - -} \ No newline at end of file diff --git a/src/ServerlessWorkflow.Sdk/Serialization/Json/Serializer.cs b/src/ServerlessWorkflow.Sdk/Serialization/Json/Serializer.cs deleted file mode 100644 index f74bb17..0000000 --- a/src/ServerlessWorkflow.Sdk/Serialization/Json/Serializer.cs +++ /dev/null @@ -1,230 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -using System.Text.Json.Serialization.Metadata; - -namespace ServerlessWorkflow.Sdk.Serialization; - -/// -/// Provides functionality to serialize/deserialize objects to/from JSON and YAML -/// -public static partial class Serializer -{ - - /// - /// Provides functionality to serialize/deserialize objects to/from JSON - /// - public static class Json - { - - /// - /// Gets/sets an used to configure the used by default - /// - public static Action? DefaultOptionsConfiguration { get; set; } = (options) => - { - options.TypeInfoResolver = new DefaultJsonTypeInfoResolver - { - Modifiers = { JsonTypeInfoModifiers.IncludeNonPublicProperties() } - }; - options.PropertyNamingPolicy = JsonNamingPolicy.CamelCase; - options.DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingDefault; - }; - - static JsonSerializerOptions? _DefaultOptions; - /// - /// Gets/sets the default - /// - public static JsonSerializerOptions DefaultOptions - { - get - { - if (_DefaultOptions != null) return _DefaultOptions; - _DefaultOptions = new JsonSerializerOptions(); - DefaultOptionsConfiguration?.Invoke(_DefaultOptions); - return _DefaultOptions; - } - } - - static JsonSerializerOptions? _DefaultIndentedOptions; - /// - /// Gets/sets the default indented - /// - public static JsonSerializerOptions DefaultIndentedOptions - { - get - { - if (_DefaultIndentedOptions != null) return _DefaultIndentedOptions; - _DefaultIndentedOptions = new JsonSerializerOptions(); - DefaultOptionsConfiguration?.Invoke(_DefaultIndentedOptions); - _DefaultIndentedOptions.WriteIndented = true; - return _DefaultIndentedOptions; - } - } - - /// - /// Serializes the specified object to JSON - /// - /// The type of object to serialize - /// The object to serialized - /// A boolean indicating whether or not to indent the output - /// The JSON of the serialized object - public static string Serialize(T graph, bool indented = false) => indented ? - JsonSerializer.Serialize(graph, DefaultIndentedOptions) : - JsonSerializer.Serialize(graph, DefaultOptions); - - /// - /// Serializes the specified object to JSON - /// - /// The object to serialized - /// The type of object to serialize - /// A boolean indicating whether or not to indent the output - /// The JSON of the serialized object - public static string Serialize(object graph, Type inputType, bool indented = false) => indented ? - JsonSerializer.Serialize(graph, inputType, DefaultIndentedOptions) : - JsonSerializer.Serialize(graph, inputType, DefaultOptions); - - /// - /// Serializes the specified object into a new - /// - /// The type of object to serialize - /// The object to serialize - /// A new - public static JsonNode? SerializeToNode(T graph) => JsonSerializer.SerializeToNode(graph, DefaultOptions); - - /// - /// Serializes the specified object into a new - /// - /// The type of object to serialize - /// The object to serialize - /// A new - public static JsonElement? SerializeToElement(T graph) => JsonSerializer.SerializeToElement(graph, DefaultOptions); - - /// - /// Serializes the specified object into a new - /// - /// The type of object to serialize - /// The object to serialize - /// A new - public static JsonDocument? SerializeToDocument(T graph) => JsonSerializer.SerializeToDocument(graph, DefaultOptions); - - /// - /// Serializes an object to the specified - /// - /// The type of the object to serialize - /// The to serialize the object to - /// The object to serialize - /// A boolean indicating whether or not to indent the output - /// A - /// A new awaitable - public static Task SerializeAsync(Stream stream, T graph, bool indented = false, CancellationToken cancellationToken = default) => indented ? - JsonSerializer.SerializeAsync(stream, graph, DefaultIndentedOptions, cancellationToken) : - JsonSerializer.SerializeAsync(stream, graph, DefaultOptions, cancellationToken); - - /// - /// Serializes an object to the specified - /// - /// The to serialize the object to - /// The object to serialize - /// The type of the object to serialize - /// A boolean indicating whether or not to indent the output - /// A - /// A new awaitable - public static Task SerializeAsync(Stream stream, object graph, Type inputType, bool indented = false, CancellationToken cancellationToken = default) => indented ? - JsonSerializer.SerializeAsync(stream, graph, inputType, DefaultIndentedOptions, cancellationToken) : - JsonSerializer.SerializeAsync(stream, graph, inputType, DefaultOptions, cancellationToken); - - /// - /// Deserializes the specified JSON input - /// - /// The JSON input to deserialize - /// The type to deserialize the JSON into - /// An object that results from the specified JSON input's deserialization - public static object? Deserialize(string json, Type returnType) => JsonSerializer.Deserialize(json, returnType, DefaultOptions); - - /// - /// Deserializes the specified - /// - /// The type to deserialize the specified into - /// The to deserialize - /// The deserialized value - public static T? Deserialize(JsonElement element) => JsonSerializer.Deserialize(element, DefaultOptions); - - /// - /// Deserializes the specified - /// - /// The type to deserialize the specified into - /// The to deserialize - /// The deserialized value - public static T? Deserialize(JsonDocument document) => JsonSerializer.Deserialize(document, DefaultOptions); - - /// - /// Deserializes the specified JSON input - /// - /// The type to deserialize the specified JSON into - /// The JSON input to deserialize - /// The deserialized value - public static T? Deserialize(string json) => JsonSerializer.Deserialize(json, DefaultOptions); - - /// - /// Deserializes the specified - /// - /// The type to deserialize the specified into - /// The to deserialize - /// The deserialized value - public static T? Deserialize(JsonNode node) => JsonSerializer.Deserialize(node, DefaultOptions); - - /// - /// Deserializes the specified JSON input - /// - /// The type to deserialize the specified JSON into - /// The JSON input to deserialize - /// The deserialized value - public static T? Deserialize(ReadOnlySpan buffer) => JsonSerializer.Deserialize(buffer, DefaultOptions); - - /// - /// Deserializes the specified as a new - /// - /// The expected type of elements to enumerate - /// The to deserialize - /// A - /// A new - public static IAsyncEnumerable DeserializeAsyncEnumerable(Stream stream, CancellationToken cancellationToken = default) => JsonSerializer.DeserializeAsyncEnumerable(stream, DefaultOptions, cancellationToken); - - /// - /// Converts the specified YAML input into JSON - /// - /// The YAML input to convert - /// A boolean indicating whether or not to indent the output - /// The YAML input converted into JSON - public static string ConvertFromYaml(string yaml, bool indented = false) - { - if (string.IsNullOrWhiteSpace(yaml)) return null!; - var graph = Yaml.Deserialize(yaml); - return Serialize(graph, indented); - } - - /// - /// Converts the specified JSON input into YAML - /// - /// The JSON input to convert - /// The JSON input converted into YAML - public static string ConvertToYaml(string json) - { - if (string.IsNullOrWhiteSpace(json)) return null!; - var graph = Deserialize(json); - return Yaml.Serialize(graph); - } - - } - -} diff --git a/src/ServerlessWorkflow.Sdk/Serialization/Json/TaskDefinitionJsonConverter.cs b/src/ServerlessWorkflow.Sdk/Serialization/Json/TaskDefinitionJsonConverter.cs new file mode 100644 index 0000000..cfbc877 --- /dev/null +++ b/src/ServerlessWorkflow.Sdk/Serialization/Json/TaskDefinitionJsonConverter.cs @@ -0,0 +1,53 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +using ServerlessWorkflow.Sdk.Models; +using ServerlessWorkflow.Sdk.Models.Tasks; +using System.Text.Json; + +namespace ServerlessWorkflow.Sdk.Serialization.Json; + +/// +/// Represents the used to serialize and deserialize s to/from JSON +/// +public class TaskDefinitionJsonConverter + : JsonConverter +{ + + /// + public override TaskDefinition Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + { + if (reader.TokenType != JsonTokenType.StartObject) throw new JsonException("Expected start of object"); + using var document = JsonDocument.ParseValue(ref reader); + var root = document.RootElement; + if (root.TryGetProperty(nameof(CallTaskDefinition.Call).ToCamelCase(), out _)) return JsonSerializer.Deserialize(root.GetRawText(), options)!; + else if (root.TryGetProperty(nameof(CompositeTaskDefinition.Execute).ToCamelCase(), out _)) return JsonSerializer.Deserialize(root.GetRawText(), options)!; + else if (root.TryGetProperty(nameof(EmitTaskDefinition.Emit).ToCamelCase(), out _)) return JsonSerializer.Deserialize(root.GetRawText(), options)!; + else if (root.TryGetProperty(nameof(ForTaskDefinition.For).ToCamelCase(), out _)) return JsonSerializer.Deserialize(root.GetRawText(), options)!; + else if (root.TryGetProperty(nameof(ListenTaskDefinition.Listen).ToCamelCase(), out _)) return JsonSerializer.Deserialize(root.GetRawText(), options)!; + else if (root.TryGetProperty(nameof(RaiseTaskDefinition.Raise).ToCamelCase(), out _)) return JsonSerializer.Deserialize(root.GetRawText(), options)!; + else if (root.TryGetProperty(nameof(RunTaskDefinition.Run).ToCamelCase(), out _)) return JsonSerializer.Deserialize(root.GetRawText(), options)!; + else if (root.TryGetProperty(nameof(SetTaskDefinition.Set).ToCamelCase(), out _)) return JsonSerializer.Deserialize(root.GetRawText(), options)!; + else if (root.TryGetProperty(nameof(SwitchTaskDefinition.Switch).ToCamelCase(), out _)) return JsonSerializer.Deserialize(root.GetRawText(), options)!; + else if (root.TryGetProperty(nameof(TryTaskDefinition.Try).ToCamelCase(), out _)) return JsonSerializer.Deserialize(root.GetRawText(), options)!; + else if (root.TryGetProperty(nameof(WaitTaskDefinition.Wait).ToCamelCase(), out _)) return JsonSerializer.Deserialize(root.GetRawText(), options)!; + else return JsonSerializer.Deserialize(root.GetRawText(), options)!; + } + + /// + public override void Write(Utf8JsonWriter writer, TaskDefinition value, JsonSerializerOptions options) + { + JsonSerializer.Serialize(writer, value, value.GetType(), options); + } + +} diff --git a/src/ServerlessWorkflow.Sdk/Serialization/Yaml/ChainedObjectGraphVisitor.cs b/src/ServerlessWorkflow.Sdk/Serialization/Yaml/ChainedObjectGraphVisitor.cs deleted file mode 100644 index c6b3106..0000000 --- a/src/ServerlessWorkflow.Sdk/Serialization/Yaml/ChainedObjectGraphVisitor.cs +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -using System.Collections; - -namespace ServerlessWorkflow.Sdk.Serialization; - -/// -/// Represents a used to ignore the serialization of empty s -/// -/// Based on Kees C. Bakker's answer on StackOverflow -public class ChainedObjectGraphVisitor - : YamlDotNet.Serialization.ObjectGraphVisitors.ChainedObjectGraphVisitor -{ - - /// - /// Initializes a new - /// - /// - public ChainedObjectGraphVisitor(IObjectGraphVisitor nextVisitor) : base(nextVisitor) { } - - /// - public override bool Enter(IObjectDescriptor value, IEmitter context) - { - if (this.IsEmptyEnumerable(value)) return false; - return base.Enter(value, context); - } - - /// - public override bool EnterMapping(IPropertyDescriptor key, IObjectDescriptor value, IEmitter context) - { - if (this.IsEmptyEnumerable(value)) return false; - return base.EnterMapping(key, value, context); - } - - /// - /// Determines whether or not the specified is an empty - /// - /// The to check - /// A boolean indicating whether or not the specified is an empty - protected virtual bool IsEmptyEnumerable(IObjectDescriptor descriptor) - { - if (descriptor.Value == null) return true; - if (typeof(IEnumerable).IsAssignableFrom(descriptor.Value.GetType())) return !((IEnumerable)descriptor.Value).GetEnumerator().MoveNext(); - return false; - } - -} \ No newline at end of file diff --git a/src/ServerlessWorkflow.Sdk/Serialization/Yaml/IExtensibleDeserializer.cs b/src/ServerlessWorkflow.Sdk/Serialization/Yaml/IExtensibleDeserializer.cs deleted file mode 100644 index bfa28c8..0000000 --- a/src/ServerlessWorkflow.Sdk/Serialization/Yaml/IExtensibleDeserializer.cs +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace ServerlessWorkflow.Sdk.Serialization.Yaml; - -/// -/// Represents an used to deserialize instances -/// -public class IExtensibleDeserializer - : INodeDeserializer -{ - - /// - /// Initializes a new - /// - /// The inner - public IExtensibleDeserializer(INodeDeserializer inner) - { - this.Inner = inner; - } - - /// - /// Gets the inner - /// - protected INodeDeserializer Inner { get; } - - /// - public virtual bool Deserialize(IParser reader, Type expectedType, Func nestedObjectDeserializer, out object? value) - { - if(!typeof(IExtensible).IsAssignableFrom(expectedType)) return this.Inner.Deserialize(reader, expectedType, nestedObjectDeserializer, out value); - var succeeded = this.Inner.Deserialize(reader, typeof(IDictionary), nestedObjectDeserializer, out value); - var json = Serializer.Json.Serialize(value); - if (succeeded) value = Serializer.Json.Deserialize(json, expectedType); - return succeeded; - } - -} diff --git a/src/ServerlessWorkflow.Sdk/Serialization/Yaml/InferTypeResolver.cs b/src/ServerlessWorkflow.Sdk/Serialization/Yaml/InferTypeResolver.cs deleted file mode 100644 index 7a3f676..0000000 --- a/src/ServerlessWorkflow.Sdk/Serialization/Yaml/InferTypeResolver.cs +++ /dev/null @@ -1,69 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -using YamlDotNet.Core.Events; - -namespace ServerlessWorkflow.Sdk.Serialization.Yaml; - -/// -/// Represents an used to infer node types from deserialized values -/// -public class InferTypeResolver - : INodeTypeResolver -{ - - /// - public bool Resolve(NodeEvent? nodeEvent, ref Type currentType) - { - if (nodeEvent is Scalar scalar) - { - if (scalar.Style == ScalarStyle.SingleQuoted || scalar.Style == ScalarStyle.DoubleQuoted) - { - currentType = typeof(string); - return true; - } - if (bool.TryParse(scalar.Value, out _)) - { - currentType = typeof(bool); - return true; - } - if (byte.TryParse(scalar.Value, out _)) - { - currentType = typeof(byte); - return true; - } - if (short.TryParse(scalar.Value, out _)) - { - currentType = typeof(short); - return true; - } - if (int.TryParse(scalar.Value, out _)) - { - currentType = typeof(int); - return true; - } - if (long.TryParse(scalar.Value, out _)) - { - currentType = typeof(long); - return true; - } - if (decimal.TryParse(scalar.Value, out _)) - { - currentType = typeof(decimal); - return true; - } - } - return false; - } - -} diff --git a/src/ServerlessWorkflow.Sdk/Serialization/Yaml/Iso8601TimeSpanSerializer.cs b/src/ServerlessWorkflow.Sdk/Serialization/Yaml/Iso8601TimeSpanSerializer.cs deleted file mode 100644 index 13e9d7b..0000000 --- a/src/ServerlessWorkflow.Sdk/Serialization/Yaml/Iso8601TimeSpanSerializer.cs +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -using System.Xml; -using YamlDotNet.Core; -using YamlDotNet.Core.Events; - -namespace ServerlessWorkflow.Sdk.Serialization.Yaml; - -/// -/// Represents the used to serialize ISO 8601 s -/// -public class Iso8601TimeSpanSerializer - : IYamlTypeConverter -{ - - /// - public virtual bool Accepts(Type type) => type == typeof(TimeSpan); - - /// - public virtual object ReadYaml(IParser parser, Type type) => throw new NotImplementedException(); - - /// - public virtual void WriteYaml(IEmitter emitter, object? value, Type type) - { - emitter.Emit(new Scalar(XmlConvert.ToString((TimeSpan)value!))); - } - -} \ No newline at end of file diff --git a/src/ServerlessWorkflow.Sdk/Serialization/Yaml/JsonElementConverter.cs b/src/ServerlessWorkflow.Sdk/Serialization/Yaml/JsonElementConverter.cs deleted file mode 100644 index b6483a9..0000000 --- a/src/ServerlessWorkflow.Sdk/Serialization/Yaml/JsonElementConverter.cs +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -using YamlDotNet.Core; -using YamlDotNet.Core.Events; - -namespace ServerlessWorkflow.Sdk.Serialization; - -/// -/// Represents the used to serialize s -/// -public class JsonElementConverter - : IYamlTypeConverter -{ - - /// - public virtual bool Accepts(Type type) => typeof(JsonElement).IsAssignableFrom(type); - - /// - public virtual object ReadYaml(IParser parser, Type type) => throw new NotImplementedException(); - - /// - public virtual void WriteYaml(IEmitter emitter, object? value, Type type) - { - var token = (JsonElement?)value; - if (token == null) return; - switch (token.Value!.ValueKind) - { - case JsonValueKind.True: - emitter.Emit(new Scalar(AnchorName.Empty, TagName.Empty, "true", ScalarStyle.Plain, true, true)); - break; - case JsonValueKind.False: - emitter.Emit(new Scalar(AnchorName.Empty, TagName.Empty, "false", ScalarStyle.Plain, true, true)); - break; - default: - var node = Serializer.Json.SerializeToNode(token); - new JsonNodeConverter().WriteYaml(emitter, node, type); - break; - } - } - -} diff --git a/src/ServerlessWorkflow.Sdk/Serialization/Yaml/JsonNodeConverter.cs b/src/ServerlessWorkflow.Sdk/Serialization/Yaml/JsonNodeConverter.cs deleted file mode 100644 index 95be1e6..0000000 --- a/src/ServerlessWorkflow.Sdk/Serialization/Yaml/JsonNodeConverter.cs +++ /dev/null @@ -1,109 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -using YamlDotNet.Core.Events; - -namespace ServerlessWorkflow.Sdk.Serialization; - -/// -/// Represents the used to serialize s -/// -public class JsonNodeConverter - : IYamlTypeConverter -{ - - /// - public virtual bool Accepts(Type type) => typeof(JsonNode).IsAssignableFrom(type); - - /// - public virtual object ReadYaml(IParser parser, Type type) => throw new NotImplementedException(); - - /// - public virtual void WriteYaml(IEmitter emitter, object? value, Type type) => this.WriteJsonNode(emitter, (JsonNode?)value); - - void WriteJsonNode(IEmitter emitter, JsonNode? node) - { - if (node == null) return; - switch (node) - { - case JsonArray jsonArray: - this.WriteJsonArray(emitter, jsonArray); - break; - case JsonObject jsonObject: - this.WriteJsonObject(emitter, jsonObject); - break; - case JsonValue jsonValue: - this.WriteJsonValue(emitter, jsonValue); - break; - default: - throw new NotSupportedException($"The specified JSON node type '{node.GetType().FullName}' is not supported"); - } - } - - void WriteJsonArray(IEmitter emitter, JsonArray jsonArray) - { - emitter.Emit(new SequenceStart(null, null, false, SequenceStyle.Block)); - foreach (var node in jsonArray) - { - this.WriteJsonNode(emitter, node); - } - emitter.Emit(new SequenceEnd()); - } - - void WriteJsonObject(IEmitter emitter, JsonObject jsonObject) - { - emitter.Emit(new MappingStart(null, null, false, MappingStyle.Block)); - foreach (var property in jsonObject) - { - this.WriteJsonProperty(emitter, property); - } - emitter.Emit(new MappingEnd()); - } - - void WriteJsonProperty(IEmitter emitter, KeyValuePair jsonProperty) - { - if (jsonProperty.Value == null) return; - emitter.Emit(new Scalar(jsonProperty.Key)); - this.WriteJsonNode(emitter, jsonProperty.Value); - } - - void WriteJsonValue(IEmitter emitter, JsonValue jsonValue) - { - var value = Serializer.Json.Deserialize(jsonValue); - if (value == null) return; - Scalar scalar = value switch - { - bool boolValue => new(boolValue.ToString().ToLowerInvariant()), - DateTime dateTime => new(dateTime.ToString()), - DateTimeOffset dateTimeOffset => new(dateTimeOffset.ToString()), - float floatValue => new(AnchorName.Empty, TagName.Empty, floatValue.ToString(), ScalarStyle.Plain, true, false), - Guid guid => new(guid.ToString()), - TimeSpan timeSpan => new(Iso8601TimeSpan.Format(timeSpan)), - JsonElement jsonElement => ConvertToScalar(jsonElement), - _ => new(AnchorName.Empty, TagName.Empty, value.ToString()!, ScalarStyle.SingleQuoted, true, true) - }; - emitter.Emit(scalar); - } - - Scalar ConvertToScalar(JsonElement jsonElement) - { - return jsonElement.ValueKind switch - { - JsonValueKind.True => new(AnchorName.Empty, TagName.Empty, "true", ScalarStyle.Plain, true, true), - JsonValueKind.False => new(AnchorName.Empty, TagName.Empty, "false", ScalarStyle.Plain, true, true), - JsonValueKind.String => new(AnchorName.Empty, TagName.Empty, jsonElement.ToString(), jsonElement.ToString().All(c => char.IsDigit(c) || c == '.' || c == ',') ? ScalarStyle.SingleQuoted : ScalarStyle.Any, true, true), - _ => new(AnchorName.Empty, TagName.Empty, jsonElement.ToString()!) - }; - } - -} diff --git a/src/ServerlessWorkflow.Sdk/Serialization/Yaml/OneOfConverter.cs b/src/ServerlessWorkflow.Sdk/Serialization/Yaml/OneOfConverter.cs deleted file mode 100644 index 1770d31..0000000 --- a/src/ServerlessWorkflow.Sdk/Serialization/Yaml/OneOfConverter.cs +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace ServerlessWorkflow.Sdk.Serialization; - -/// -/// Represents the used to serialize and deserialize instances -/// -public class OneOfConverter - : IYamlTypeConverter -{ - - /// - public virtual bool Accepts(Type type) => typeof(IOneOf).IsAssignableFrom(type); - - /// - public virtual object ReadYaml(IParser parser, Type type) => throw new NotImplementedException(); - - /// - public virtual void WriteYaml(IEmitter emitter, object? value, Type type) - { - if (value == null) return; - var toSerialize = value; - if (value is IOneOf oneOf) toSerialize = oneOf.GetValue(); - var node = Serializer.Json.SerializeToNode(toSerialize); - new JsonNodeConverter().WriteYaml(emitter, node, typeof(JsonNode)); - } - -} diff --git a/src/ServerlessWorkflow.Sdk/Serialization/Yaml/OneOfDeserializer.cs b/src/ServerlessWorkflow.Sdk/Serialization/Yaml/OneOfDeserializer.cs deleted file mode 100644 index 9bc2313..0000000 --- a/src/ServerlessWorkflow.Sdk/Serialization/Yaml/OneOfDeserializer.cs +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace ServerlessWorkflow.Sdk.Serialization.Yaml; - -/// -/// Represents an used to deserialize instances -/// -public class OneOfDeserializer - : INodeDeserializer -{ - - /// - /// Initializes a new - /// - /// The inner - public OneOfDeserializer(INodeDeserializer inner) - { - this.Inner = inner; - } - - /// - /// Gets the inner - /// - protected INodeDeserializer Inner { get; } - - /// - public virtual bool Deserialize(IParser reader, Type expectedType, Func nestedObjectDeserializer, out object? value) - { - var oneOfType = expectedType.GetGenericType(typeof(OneOf<,>)); - if(oneOfType == null || !oneOfType.IsAssignableFrom(expectedType)) return this.Inner.Deserialize(reader, expectedType, nestedObjectDeserializer, out value); - var t1 = oneOfType.GetGenericArguments()[0]; - var t2 = oneOfType.GetGenericArguments()[1]; - value = nestedObjectDeserializer(reader, typeof(object)); - var json = Serializer.Json.Serialize(value); - try - { - value = Serializer.Json.Deserialize(json, t1); - } - catch - { - value = Serializer.Json.Deserialize(json, t2); - } - return true; - } - -} diff --git a/src/ServerlessWorkflow.Sdk/Serialization/Yaml/Serializer.cs b/src/ServerlessWorkflow.Sdk/Serialization/Yaml/Serializer.cs deleted file mode 100644 index 0b98193..0000000 --- a/src/ServerlessWorkflow.Sdk/Serialization/Yaml/Serializer.cs +++ /dev/null @@ -1,107 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -using ServerlessWorkflow.Sdk.Serialization.Yaml; -using YamlDotNet.Serialization.NamingConventions; -using YamlDotNet.Serialization.NodeDeserializers; - -namespace ServerlessWorkflow.Sdk.Serialization; - -/// -/// Provides functionality to serialize/deserialize objects to/from JSON and YAML -/// -public static partial class Serializer -{ - - /// - /// Provides functionality to serialize/deserialize objects to/from YAML - /// - public static class Yaml - { - - static readonly ISerializer Serializer; - static readonly IDeserializer Deserializer; - - static Yaml() - { - Serializer = new SerializerBuilder() - .ConfigureDefaultValuesHandling(DefaultValuesHandling.OmitNull | DefaultValuesHandling.OmitDefaults | DefaultValuesHandling.OmitEmptyCollections) - .WithNamingConvention(CamelCaseNamingConvention.Instance) - .IncludeNonPublicProperties() - .WithTypeConverter(new OneOfConverter()) - .WithTypeConverter(new JsonNodeConverter()) - .WithTypeConverter(new JsonElementConverter()) - .WithTypeConverter(new UriTypeSerializer()) - .WithEmissionPhaseObjectGraphVisitor(args => new ChainedObjectGraphVisitor(args.InnerVisitor)) - .Build(); - Deserializer = new DeserializerBuilder() - .IncludeNonPublicProperties() - .WithNamingConvention(CamelCaseNamingConvention.Instance) - .WithNodeTypeResolver(new InferTypeResolver()) - .WithTypeConverter(new UriTypeSerializer()) - .WithNodeDeserializer( - inner => new IExtensibleDeserializer(inner), - syntax => syntax.InsteadOf()) - .WithNodeDeserializer( - inner => new Serialization.Yaml.Iso8601TimeSpanConverter(inner), - syntax => syntax.InsteadOf()) - .WithNodeDeserializer( - inner => new OneOfDeserializer(inner), - syntax => syntax.InsteadOf()) - .Build(); - } - - /// - /// Serializes the specified object to YAML - /// - /// The type of object to serialize - /// The object to serialized - /// The YAML of the serialized object - public static string Serialize(T graph) => Serializer.Serialize(graph!); - - /// - /// Serializes the specified object to YAML - /// - /// The type of object to serialize - /// The to the YAML to - /// The object to serialized - /// The YAML of the serialized object - public static void Serialize(TextWriter writer, T graph) => Serializer.Serialize(writer, graph!); - - /// - /// Deserializes the specified YAML input - /// - /// The type to deserialize the specified YAML into - /// The YAML input to deserialize - /// The deserialized value - public static T? Deserialize(string yaml) => Deserializer.Deserialize(yaml); - - /// - /// Deserializes the specified YAML input - /// - /// The type to deserialize the specified YAML into - /// The to read the YAML to deserialize - /// The deserialized value - public static T? Deserialize(TextReader reader) => Deserializer.Deserialize(reader); - - /// - /// Deserializes the specified YAML input - /// - /// The to read the YAML to deserialize - /// The type to deserialize the specified YAML into - /// The deserialized value - public static object? Deserialize(TextReader reader, Type type) => Deserializer.Deserialize(reader, type); - - } - -} diff --git a/src/ServerlessWorkflow.Sdk/Serialization/Yaml/Iso8601TimeSpanConverter.cs b/src/ServerlessWorkflow.Sdk/Serialization/Yaml/TaskDefinitionYamlConverter.cs similarity index 50% rename from src/ServerlessWorkflow.Sdk/Serialization/Yaml/Iso8601TimeSpanConverter.cs rename to src/ServerlessWorkflow.Sdk/Serialization/Yaml/TaskDefinitionYamlConverter.cs index 4bffa2b..5b1d353 100644 --- a/src/ServerlessWorkflow.Sdk/Serialization/Yaml/Iso8601TimeSpanConverter.cs +++ b/src/ServerlessWorkflow.Sdk/Serialization/Yaml/TaskDefinitionYamlConverter.cs @@ -1,4 +1,4 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors +// Copyright © 2024-Present The Serverless Workflow Specification Authors // // Licensed under the Apache License, Version 2.0 (the "License"), // you may not use this file except in compliance with the License. @@ -11,36 +11,36 @@ // See the License for the specific language governing permissions and // limitations under the License. +using ServerlessWorkflow.Sdk.Models; +using Neuroglia.Serialization.Json; +using YamlDotNet.Core; + namespace ServerlessWorkflow.Sdk.Serialization.Yaml; /// -/// Represents an used to deserialize ISO8601 s +/// Represents the service used to deserialize s from YAML /// -public class Iso8601TimeSpanConverter +/// +/// Initializes a new +/// +/// The inner +public class TaskDefinitionYamlDeserializer(INodeDeserializer inner) : INodeDeserializer { - /// - /// Initializes a new - /// - /// The inner - public Iso8601TimeSpanConverter(INodeDeserializer inner) - { - this.Inner = inner; - } - /// /// Gets the inner /// - protected INodeDeserializer Inner { get; } - + protected INodeDeserializer Inner { get; } = inner; + /// public virtual bool Deserialize(IParser reader, Type expectedType, Func nestedObjectDeserializer, out object? value) { - if (expectedType != typeof(TimeSpan)&& expectedType != typeof(TimeSpan?)) return this.Inner.Deserialize(reader, expectedType, nestedObjectDeserializer, out value); - if (!this.Inner.Deserialize(reader, typeof(string), nestedObjectDeserializer, out value))return false; - value = Iso8601TimeSpan.Parse((string)value!); + if (!typeof(TaskDefinition).IsAssignableFrom(expectedType)) return this.Inner.Deserialize(reader, expectedType, nestedObjectDeserializer, out value); + if (!this.Inner.Deserialize(reader, typeof(Dictionary), nestedObjectDeserializer, out value)) return false; + value = JsonSerializer.Default.Deserialize(JsonSerializer.Default.SerializeToText(value!)); return true; } } + diff --git a/src/ServerlessWorkflow.Sdk/Serialization/Yaml/UriTypeSerializer.cs b/src/ServerlessWorkflow.Sdk/Serialization/Yaml/UriTypeSerializer.cs deleted file mode 100644 index 93be00a..0000000 --- a/src/ServerlessWorkflow.Sdk/Serialization/Yaml/UriTypeSerializer.cs +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -using YamlDotNet.Core.Events; - -namespace ServerlessWorkflow.Sdk.Serialization.Yaml; - -/// -/// Represents the used to serialize s -/// -public class UriTypeSerializer - : IYamlTypeConverter -{ - - /// - public virtual bool Accepts(Type type) => typeof(Uri).IsAssignableFrom(type); - - /// - public virtual object ReadYaml(IParser parser, Type type) - { - Scalar scalar = (Scalar)parser.Current!; - parser.MoveNext(); - return new Uri(scalar.Value, UriKind.RelativeOrAbsolute); - } - - /// - public virtual void WriteYaml(IEmitter emitter, object? value, Type type) - { - if (value == null) return; - emitter.Emit(new Scalar(((Uri)value).ToString())); - } - -} diff --git a/src/ServerlessWorkflow.Sdk/ServerlessWorkflow.Sdk.csproj b/src/ServerlessWorkflow.Sdk/ServerlessWorkflow.Sdk.csproj index 8302c62..b17d744 100644 --- a/src/ServerlessWorkflow.Sdk/ServerlessWorkflow.Sdk.csproj +++ b/src/ServerlessWorkflow.Sdk/ServerlessWorkflow.Sdk.csproj @@ -1,62 +1,40 @@ - net7.0 + net8.0 enable enable - 0.8.8 - en - true - true - LICENSE - Cloud Native Computing Foundation - The Serverless Workflow Specification Authors - Serverless Workflow Specification 0.8 - .NET 7.0 SDK - Copyright © 2021 The Serverless Workflow Specification Authors - https://github.com/serverlessworkflow/sdk-net - https://github.com/serverlessworkflow/sdk-net - git - serverless workflow sdk - The .NET 7.0 SDK for the Serverless Workflow - icon.png - Serverless Workflow Specification 0.8 - .NET 7.0 SDK - README.md - $(VersionPrefix).0 - $(VersionPrefix).0 + $(VersionPrefix)-alpha1 + 1.0.0 + $(VersionPrefix) + $(VersionPrefix) + en + true + True + true + Serverless Workflow SDK + Contains Serverless Workflow DSL models + serverless-workflow;serverless;workflow;dsl;sdk + true + Apache-2.0 + readme.md + Copyright © 2024-Present The Serverless Workflow Authors. All rights reserved. + https://github.com/serverlessworkflow/sdk-net + https://github.com/serverlessworkflow/sdk-net + git + embedded - - - - - - True - \ - - + True \ - - True - \ - - - - - - - - - - - - - + + diff --git a/src/ServerlessWorkflow.Sdk/ServerlessWorkflowSpecVersion.cs b/src/ServerlessWorkflow.Sdk/ServerlessWorkflowSpecVersion.cs deleted file mode 100644 index 43d4e7d..0000000 --- a/src/ServerlessWorkflow.Sdk/ServerlessWorkflowSpecVersion.cs +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace ServerlessWorkflow.Sdk; - -/// -/// Enumerates all well-known Serverless Workflow Specification versions -/// -public static class ServerlessWorkflowSpecVersion -{ - - /// - /// Gets the v0.8 version - /// - public const string V08 = "0.8"; - - /// - /// Gets the latest version - /// - public const string Latest = V08; - -} diff --git a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/ActionBuilder.cs b/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/ActionBuilder.cs deleted file mode 100644 index acacb3b..0000000 --- a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/ActionBuilder.cs +++ /dev/null @@ -1,284 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace ServerlessWorkflow.Sdk.Services.FluentBuilders; - -/// -/// Represents the default implementation of the interface -/// -public class ActionBuilder - : IActionBuilder, IEventTriggerActionBuilder, IFunctionActionBuilder, ISubflowActionBuilder -{ - - /// - /// Initializes a new - /// - /// The the belongs to - public ActionBuilder(IPipelineBuilder pipeline) - { - this.Pipeline = pipeline; - } - - /// - /// Gets the the belongs to - /// - protected IPipelineBuilder Pipeline { get; set; } - - /// - /// Gets the to configure - /// - protected ActionDefinition Action { get; } = new ActionDefinition(); - - /// - public virtual IActionBuilder WithName(string name) - { - if (string.IsNullOrWhiteSpace(name)) throw new ArgumentNullException(nameof(name)); - this.Action.Name = name; - return this; - } - - /// - public virtual IActionBuilder WithCondition(string expression) - { - if (string.IsNullOrWhiteSpace(expression)) throw new ArgumentNullException(nameof(expression)); - this.Action.Condition = expression; - return this; - } - - /// - public virtual IActionBuilder FromStateData(string expression) - { - this.Action.ActionDataFilter!.FromStateData = expression; - return this; - } - - /// - public virtual IActionBuilder FilterResults(string expression) - { - this.Action.ActionDataFilter!.Results = expression; - return this; - } - - /// - public virtual IActionBuilder ToStateData(string expression) - { - this.Action.ActionDataFilter!.ToStateData = expression; - return this; - } - - /// - public virtual IFunctionActionBuilder Invoke(string function) - { - if (string.IsNullOrWhiteSpace(function)) throw new ArgumentNullException(nameof(function)); - this.Action.Function = new FunctionReference() { RefName = function }; - return this; - } - - /// - public virtual IFunctionActionBuilder Invoke(Action functionSetup) - { - if (functionSetup == null) throw new ArgumentNullException(nameof(functionSetup)); - var function = this.Pipeline.AddFunction(functionSetup); - this.Action.Function = new FunctionReference() { RefName = function.Name }; - return this; - } - - /// - public virtual IFunctionActionBuilder Invoke(FunctionDefinition function) - { - if (function == null) throw new ArgumentNullException(nameof(function)); - this.Pipeline.AddFunction(function); - this.Action.Function = new FunctionReference() { RefName = function.Name }; - return this; - } - - /// - public virtual IFunctionActionBuilder WithArgument(string name, object value) - { - if (this.Action.Function!.Arguments == null) this.Action.Function.Arguments = new Dictionary(); - this.Action.Function.Arguments[name] = value; - return this; - } - - /// - public virtual IFunctionActionBuilder WithArguments(IDictionary args) - { - this.Action.Function!.Arguments = args.ToDictionary(kvp => kvp.Key, kvp => (object)kvp.Value); - return this; - } - - /// - public virtual IFunctionActionBuilder WithSelectionSet(string selectionSet) - { - if (string.IsNullOrWhiteSpace(selectionSet)) throw new ArgumentNullException(nameof(selectionSet)); - this.Action.Function!.SelectionSet = selectionSet; - return this; - } - - /// - public virtual IEventTriggerActionBuilder Consume(string e) - { - if (string.IsNullOrWhiteSpace(e)) throw new ArgumentNullException(nameof(e)); - this.Action.Event = new EventReference() { TriggerEventRef = e, ResultEventRef = string.Empty }; - return this; - } - - /// - public virtual IEventTriggerActionBuilder Consume(Action eventSetup) - { - if (eventSetup == null) throw new ArgumentNullException(nameof(eventSetup)); - var e = this.Pipeline.AddEvent(eventSetup); - this.Action.Event = new EventReference() { TriggerEventRef = e.Name, ResultEventRef = string.Empty }; - return this; - } - - /// - public virtual IEventTriggerActionBuilder Consume(EventDefinition e) - { - if (e == null) - throw new ArgumentNullException(nameof(e)); - this.Pipeline.AddEvent(e); - this.Action.Event = new EventReference() { TriggerEventRef = e.Name, ResultEventRef = string.Empty }; - return this; - } - - /// - public virtual IEventTriggerActionBuilder ThenProduce(string e) - { - this.Action.Event!.ResultEventRef = e; - return this; - } - - /// - public virtual IEventTriggerActionBuilder ThenProduce(Action eventSetup) - { - var e = this.Pipeline.AddEvent(eventSetup); - this.Action.Event!.TriggerEventRef = e.Name; - return this; - } - - /// - public virtual IEventTriggerActionBuilder WithContextAttribute(string name, string value) - { - if (this.Action.Event!.ContextAttributes == null) this.Action.Event.ContextAttributes = new Dictionary(); - this.Action.Event.ContextAttributes[name] = value; - return this; - } - - /// - public virtual IEventTriggerActionBuilder WithContextAttributes(IDictionary contextAttributes) - { - this.Action.Event!.ContextAttributes = contextAttributes.ToDictionary(kvp => kvp.Key, kvp => (object)kvp.Value); - return this; - } - - /// - public virtual ISubflowActionBuilder Run(string workflowId, string version, string invocationMode = InvocationMode.Synchronous) - { - if (string.IsNullOrWhiteSpace(workflowId)) throw new ArgumentNullException(nameof(workflowId)); - this.Action.Subflow = new SubflowReference(workflowId, version, invocationMode); - return this; - } - - /// - public virtual ISubflowActionBuilder Run(string workflowId, string invocationMode = InvocationMode.Synchronous) - { - if (string.IsNullOrWhiteSpace(workflowId)) throw new ArgumentNullException(nameof(workflowId)); - return this.Run(workflowId, null!, invocationMode); - } - - /// - public virtual ISubflowActionBuilder Synchronously() - { - this.Action.Subflow!.InvocationMode = InvocationMode.Synchronous; - return this; - } - - /// - public virtual ISubflowActionBuilder Asynchronously() - { - this.Action.Subflow!.InvocationMode = InvocationMode.Asynchronous; - return this; - } - - /// - public virtual ISubflowActionBuilder LatestVersion() => this.Version("latest"); - - /// - public virtual ISubflowActionBuilder Version(string version) - { - if (string.IsNullOrWhiteSpace(version)) throw new ArgumentNullException(nameof(version)); - this.Action.Subflow!.Version = version; - return this; - } - - /// - public virtual ActionDefinition Build() => this.Action; - - IActionBuilder IExtensibleBuilder.WithExtensionProperty(string name, object value) - { - if (string.IsNullOrWhiteSpace(name)) throw new ArgumentNullException(nameof(name)); - this.Action.ExtensionData ??= new Dictionary(); - this.Action.ExtensionData[name] = value; - return this; - } - - IActionBuilder IExtensibleBuilder.WithExtensionProperties(IDictionary properties) - { - this.Action.ExtensionData = properties ?? throw new ArgumentNullException(nameof(properties)); - return this; - } - - IEventTriggerActionBuilder IExtensibleBuilder.WithExtensionProperty(string name, object value) - { - if (string.IsNullOrWhiteSpace(name)) throw new ArgumentNullException(nameof(name)); - this.Action.Event!.ExtensionData ??= new Dictionary(); - this.Action.Event!.ExtensionData[name] = value; - return this; - } - - IEventTriggerActionBuilder IExtensibleBuilder.WithExtensionProperties(IDictionary properties) - { - this.Action.Event!.ExtensionData = properties ?? throw new ArgumentNullException(nameof(properties)); - return this; - } - - IFunctionActionBuilder IExtensibleBuilder.WithExtensionProperty(string name, object value) - { - if (string.IsNullOrWhiteSpace(name)) throw new ArgumentNullException(nameof(name)); - this.Action.Function!.ExtensionData ??= new Dictionary(); - this.Action.Function!.ExtensionData[name] = value; - return this; - } - - IFunctionActionBuilder IExtensibleBuilder.WithExtensionProperties(IDictionary properties) - { - this.Action.Function!.ExtensionData = properties ?? throw new ArgumentNullException(nameof(properties)); - return this; - } - - ISubflowActionBuilder IExtensibleBuilder.WithExtensionProperty(string name, object value) - { - if (string.IsNullOrWhiteSpace(name)) throw new ArgumentNullException(nameof(name)); - this.Action.Subflow!.ExtensionData ??= new Dictionary(); - this.Action.Subflow!.ExtensionData[name] = value; - return this; - } - - ISubflowActionBuilder IExtensibleBuilder.WithExtensionProperties(IDictionary properties) - { - this.Action.Subflow!.ExtensionData = properties ?? throw new ArgumentNullException(nameof(properties)); - return this; - } - -} diff --git a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/AuthenticationDefinitionBuilder.cs b/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/AuthenticationDefinitionBuilder.cs deleted file mode 100644 index 92d4c17..0000000 --- a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/AuthenticationDefinitionBuilder.cs +++ /dev/null @@ -1,71 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace ServerlessWorkflow.Sdk.Services.FluentBuilders; - -/// -/// Represents the base class for all implementations -/// -public abstract class AuthenticationDefinitionBuilder - : IAuthenticationDefinitionBuilder -{ - - /// - /// Initializes a new - /// - /// The to configure - protected AuthenticationDefinitionBuilder(AuthenticationDefinition authenticationDefinition) - { - this.AuthenticationDefinition = authenticationDefinition ?? throw new ArgumentNullException(nameof(authenticationDefinition)); - } - - /// - /// Gets the to configure - /// - protected AuthenticationDefinition AuthenticationDefinition { get; } - - /// - public virtual IAuthenticationDefinitionBuilder WithName(string name) - { - if (string.IsNullOrWhiteSpace(name)) throw new ArgumentNullException(nameof(name)); - this.AuthenticationDefinition.Name = name; - return this; - } - - /// - public virtual IAuthenticationDefinitionBuilder WithExtensionProperty(string name, object value) - { - if (string.IsNullOrWhiteSpace(name)) throw new ArgumentNullException(nameof(name)); - this.AuthenticationDefinition.ExtensionData ??= new Dictionary(); - this.AuthenticationDefinition.ExtensionData[name] = value; - return this; - } - - /// - public virtual IAuthenticationDefinitionBuilder WithExtensionProperties(IDictionary properties) - { - this.AuthenticationDefinition.ExtensionData = properties ?? throw new ArgumentNullException(nameof(properties)); - return this; - } - - /// - public virtual void LoadFromSecret(string secret) - { - if (string.IsNullOrWhiteSpace(secret)) throw new ArgumentNullException(nameof(secret)); - this.AuthenticationDefinition.Properties = new SecretBasedAuthenticationProperties(secret); - } - - /// - public virtual AuthenticationDefinition Build() => this.AuthenticationDefinition; - -} diff --git a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/BasicAuthenticationBuilder.cs b/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/BasicAuthenticationBuilder.cs deleted file mode 100644 index d396ddb..0000000 --- a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/BasicAuthenticationBuilder.cs +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace ServerlessWorkflow.Sdk.Services.FluentBuilders; - -/// -/// Represents the default implementation of the -/// -public class BasicAuthenticationBuilder - : AuthenticationDefinitionBuilder, IBasicAuthenticationBuilder -{ - - /// - /// Initializes a new - /// - public BasicAuthenticationBuilder() : base(new AuthenticationDefinition() { Scheme = AuthenticationScheme.Basic, Properties = new BasicAuthenticationProperties() }) { } - - /// - /// Gets the of the authentication definition to build - /// - protected BasicAuthenticationProperties Properties => (BasicAuthenticationProperties)this.AuthenticationDefinition.Properties!; - - /// - public virtual IBasicAuthenticationBuilder WithUserName(string username) - { - if (string.IsNullOrWhiteSpace(username)) throw new ArgumentNullException(nameof(username)); - this.Properties.Username = username; - return this; - } - - /// - public virtual IBasicAuthenticationBuilder WithPassword(string password) - { - if (string.IsNullOrWhiteSpace(password)) throw new ArgumentNullException(nameof(password)); - this.Properties.Password = password; - return this; - } - -} diff --git a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/BearerAuthenticationBuilder.cs b/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/BearerAuthenticationBuilder.cs deleted file mode 100644 index 5865ec6..0000000 --- a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/BearerAuthenticationBuilder.cs +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace ServerlessWorkflow.Sdk.Services.FluentBuilders; - -/// -/// Represents the default implementation of the -/// -public class BearerAuthenticationBuilder - : AuthenticationDefinitionBuilder, IBearerAuthenticationBuilder -{ - - /// - /// Initializes a new - /// - public BearerAuthenticationBuilder() : base(new AuthenticationDefinition() { Scheme = AuthenticationScheme.Bearer, Properties = new BearerAuthenticationProperties() }) { } - - /// - /// Gets the of the authentication definition to build - /// - protected BearerAuthenticationProperties Properties => (BearerAuthenticationProperties)this.AuthenticationDefinition.Properties!; - - /// - public virtual IBearerAuthenticationBuilder WithToken(string token) - { - if (string.IsNullOrWhiteSpace(token)) throw new ArgumentNullException(nameof(token)); - this.Properties.Token = token; - return this; - } - -} diff --git a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/BranchBuilder.cs b/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/BranchBuilder.cs deleted file mode 100644 index 53375d5..0000000 --- a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/BranchBuilder.cs +++ /dev/null @@ -1,113 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace ServerlessWorkflow.Sdk.Services.FluentBuilders; - -/// -/// Represents the default implementation of the interface -/// -public class BranchBuilder - : IBranchBuilder -{ - - /// - /// Initializes a new - /// - /// The the belongs to - public BranchBuilder(IPipelineBuilder pipeline) - { - this.Pipeline = pipeline; - } - - /// - /// Gets the the belongs to - /// - protected IPipelineBuilder Pipeline { get; set; } - - /// - /// Gets the to configure - /// - protected BranchDefinition Branch { get; } = new BranchDefinition(); - - /// - public virtual IBranchBuilder WithName(string name) - { - if (string.IsNullOrWhiteSpace(name)) throw new ArgumentNullException(nameof(name)); - this.Branch.Name = name; - return this; - } - - /// - public virtual IBranchBuilder WithExtensionProperty(string name, object value) - { - if (string.IsNullOrWhiteSpace(name)) throw new ArgumentNullException(nameof(name)); - this.Branch.ExtensionData ??= new Dictionary(); - this.Branch.ExtensionData[name] = value; - return this; - } - - /// - public virtual IBranchBuilder WithExtensionProperties(IDictionary properties) - { - this.Branch.ExtensionData = properties ?? throw new ArgumentNullException(nameof(properties)); - return this; - } - - /// - public virtual IBranchBuilder Execute(ActionDefinition action) - { - if (action == null) throw new ArgumentNullException(nameof(action)); - this.Branch.Actions.Add(action); - return this; - } - - /// - public virtual IBranchBuilder Execute(Action actionSetup) - { - if (actionSetup == null) throw new ArgumentNullException(nameof(actionSetup)); - var actionBuilder = new ActionBuilder(this.Pipeline); - actionSetup(actionBuilder); - this.Branch.Actions.Add(actionBuilder.Build()); - return this; - } - - /// - public virtual IBranchBuilder Execute(string name, Action actionSetup) - { - if (string.IsNullOrWhiteSpace(name)) throw new ArgumentNullException(nameof(name)); - if (actionSetup == null) throw new ArgumentNullException(nameof(actionSetup)); - return this.Execute(a => - { - actionSetup(a); - a.WithName(name); - }); - } - - /// - public virtual IBranchBuilder Concurrently() - { - this.Branch.ActionMode = ActionExecutionMode.Parallel; - return this; - } - - /// - public virtual IBranchBuilder Sequentially() - { - this.Branch.ActionMode = ActionExecutionMode.Sequential; - return this; - } - - /// - public virtual BranchDefinition Build() => this.Branch; - -} diff --git a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/CallbackStateBuilder.cs b/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/CallbackStateBuilder.cs deleted file mode 100644 index 9fecef1..0000000 --- a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/CallbackStateBuilder.cs +++ /dev/null @@ -1,105 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace ServerlessWorkflow.Sdk.Services.FluentBuilders; - -/// -/// Represents the default implementation of the interface -/// -public class CallbackStateBuilder - : StateBuilder, ICallbackStateBuilder -{ - - /// - /// Initializes a new - /// - /// The the belongs to - public CallbackStateBuilder(IPipelineBuilder pipeline) - : base(pipeline) - { - - } - - /// - public virtual ICallbackStateBuilder Execute(Action actionSetup) - { - if (actionSetup == null) throw new ArgumentNullException(nameof(actionSetup)); - var builder = new ActionBuilder(this.Pipeline); - actionSetup(builder); - var action = builder.Build(); - return this.Execute(action); - } - - /// - public ICallbackStateBuilder Execute(string name, Action actionSetup) - { - if (actionSetup == null) throw new ArgumentNullException(nameof(actionSetup)); - var builder = new ActionBuilder(this.Pipeline); - builder.WithName(name); - actionSetup(builder); - var action = builder.Build(); - return this.Execute(action); - } - - /// - public virtual ICallbackStateBuilder Execute(ActionDefinition action) - { - if (action == null) - throw new ArgumentNullException(nameof(action)); - this.State.Action = action; - return this; - } - - /// - public virtual ICallbackStateBuilder FilterPayload(string expression) - { - this.State.EventDataFilter.Data = expression; - return this; - } - - /// - public virtual ICallbackStateBuilder ToStateData(string expression) - { - this.State.EventDataFilter.ToStateData = expression; - return this; - } - - /// - public virtual ICallbackStateBuilder On(string e) - { - if (string.IsNullOrWhiteSpace(e)) - throw new ArgumentNullException(nameof(e)); - this.State.EventRef = e; - return this; - } - - /// - public virtual ICallbackStateBuilder On(Action eventSetup) - { - if (eventSetup == null) - throw new ArgumentNullException(nameof(eventSetup)); - this.State.EventRef = this.Pipeline.AddEvent(eventSetup).Name; - return this; - } - - /// - public virtual ICallbackStateBuilder On(EventDefinition e) - { - if (e == null) - throw new ArgumentNullException(nameof(e)); - this.Pipeline.AddEvent(e); - this.State.EventRef = e.Name; - return this; - } - -} diff --git a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/DataSwitchCaseBuilder.cs b/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/DataSwitchCaseBuilder.cs deleted file mode 100644 index cd6809f..0000000 --- a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/DataSwitchCaseBuilder.cs +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace ServerlessWorkflow.Sdk.Services.FluentBuilders; - -/// -/// Represents the default implementation of the interface -/// -public class DataSwitchCaseBuilder - : SwitchCaseBuilder, IDataSwitchCaseBuilder -{ - - /// - /// Initializes a new - /// - /// The the belongs to - public DataSwitchCaseBuilder(IPipelineBuilder pipeline) - : base(pipeline) - { - - } - - /// - public virtual IDataSwitchCaseBuilder When(string expression) - { - if (string.IsNullOrWhiteSpace(expression)) throw new ArgumentNullException(nameof(expression)); - this.Case.Condition = expression; - return this; - } - - /// - public virtual new DataCaseDefinition Build() - { - var outcome = base.Build(); - switch (outcome) - { - case EndDefinition end: - this.Case.End = end; - break; - case TransitionDefinition transition: - this.Case.Transition = transition; - break; - default: - throw new NotSupportedException($"The specified outcome type '{outcome.GetType().Name}' is not supported"); - } - return this.Case; - } - -} diff --git a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/ErrorHandlerBuilder.cs b/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/ErrorHandlerBuilder.cs deleted file mode 100644 index e00b7e5..0000000 --- a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/ErrorHandlerBuilder.cs +++ /dev/null @@ -1,115 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace ServerlessWorkflow.Sdk.Services.FluentBuilders; - -/// -/// Represents the default implementation of the interface -/// -public class ErrorHandlerBuilder - : IErrorHandlerBuilder -{ - - /// - /// Initializes a new - /// - /// The the belongs to - public ErrorHandlerBuilder(IPipelineBuilder pipeline) - { - this.Pipeline = pipeline; - this.Outcome = new StateOutcomeBuilder(this.Pipeline); - } - - /// - /// Gets the the belongs to - /// - protected IPipelineBuilder Pipeline { get; } - - /// - /// Gets the to configure - /// - protected ErrorHandlerDefinition ErrorHandler { get; } = new ErrorHandlerDefinition(); - - /// - /// Gets the service used to build the 's outcome - /// - protected IStateOutcomeBuilder Outcome { get; } - - /// - public virtual IErrorHandlerBuilder WithExtensionProperty(string name, object value) - { - if (string.IsNullOrWhiteSpace(name)) throw new ArgumentNullException(nameof(name)); - this.ErrorHandler.ExtensionData ??= new Dictionary(); - this.ErrorHandler.ExtensionData[name] = value; - return this; - } - - /// - public virtual IErrorHandlerBuilder WithExtensionProperties(IDictionary properties) - { - this.ErrorHandler.ExtensionData = properties ?? throw new ArgumentNullException(nameof(properties)); - return this; - } - - /// - public virtual IErrorHandlerBuilder Catch(string error, string errorCode) - { - this.ErrorHandler.Error = error; - this.ErrorHandler.Code = errorCode; - return this; - } - - /// - public virtual IErrorHandlerBuilder Catch(string error) - { - this.ErrorHandler.Error = error; - return this; - } - - /// - public virtual IErrorHandlerBuilder CatchAll() => this.Catch("*"); - - /// - public virtual IErrorHandlerBuilder Retry(string policy) - { - this.ErrorHandler.RetryRef = policy; - return this; - } - - /// - public virtual IErrorHandlerBuilder Then(Action outcomeSetup) - { - if (outcomeSetup == null) throw new ArgumentNullException(nameof(outcomeSetup)); - outcomeSetup(this.Outcome); - return this; - } - - /// - public virtual ErrorHandlerDefinition Build() - { - var outcome = this.Outcome.Build(); - switch (outcome) - { - case TransitionDefinition transition: - this.ErrorHandler.Transition = transition; - break; - case EndDefinition end: - this.ErrorHandler.End = end; - break; - default: - throw new NotSupportedException($"the specified {nameof(StateOutcomeDefinition)} type '{outcome.GetType().Name}' is not supported"); - } - return this.ErrorHandler; - } - -} diff --git a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/EventBuilder.cs b/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/EventBuilder.cs deleted file mode 100644 index 75073cd..0000000 --- a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/EventBuilder.cs +++ /dev/null @@ -1,130 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace ServerlessWorkflow.Sdk.Services.FluentBuilders; - -/// -/// Represents the default implementation of the interface -/// -public class EventBuilder - : MetadataContainerBuilder, IEventBuilder -{ - - /// - /// Gets the to configure - /// - protected EventDefinition Event { get; } = new(); - - /// - public override DynamicMapping? Metadata - { - get - { - return this.Event.Metadata; - } - protected set - { - this.Event.Metadata = value; - } - } - - /// - public virtual IEventBuilder WithName(string name) - { - if (string.IsNullOrWhiteSpace(name)) throw new ArgumentNullException(nameof(name)); - this.Event.Name = name; - return this; - } - - /// - public virtual IEventBuilder WithSource(Uri source) - { - this.Event.Source = source ?? throw new ArgumentNullException(nameof(source)); - return this; - } - - /// - public virtual IEventBuilder WithType(string type) - { - this.Event.Type = type; - return this; - } - - /// - public virtual IEventBuilder WithExtensionProperty(string name, object value) - { - if (string.IsNullOrWhiteSpace(name)) throw new ArgumentNullException(nameof(name)); - this.Event.ExtensionData ??= new Dictionary(); - this.Event.ExtensionData[name] = value; - return this; - } - - /// - public virtual IEventBuilder WithExtensionProperties(IDictionary properties) - { - this.Event.ExtensionData = properties ?? throw new ArgumentNullException(nameof(properties)); - return this; - } - - /// - public virtual IEventBuilder CorrelateUsing(string contextAttributeName) - { - if (string.IsNullOrWhiteSpace(contextAttributeName)) throw new ArgumentNullException(nameof(contextAttributeName)); - var correlation = this.Event.Correlations?.FirstOrDefault(c => c.ContextAttributeName == contextAttributeName); - if (this.Event.Correlations == null) this.Event.Correlations = new(); - if (correlation != null) this.Event.Correlations!.Remove(correlation); - this.Event.Correlations.Add(new() { ContextAttributeName = contextAttributeName }); - return this; - } - - /// - public virtual IEventBuilder CorrelateUsing(string contextAttributeName, string contextAttributeValue) - { - if (string.IsNullOrWhiteSpace(contextAttributeName)) throw new ArgumentNullException(nameof(contextAttributeName)); - var correlation = this.Event.Correlations?.FirstOrDefault(c => c.ContextAttributeName == contextAttributeName); - if (this.Event.Correlations == null) this.Event.Correlations = new(); - if (correlation != null) - { - if (correlation.ContextAttributeValue == contextAttributeValue) return this; - this.Event.Correlations.Remove(correlation); - } - this.Event.Correlations.Add(new() { ContextAttributeName = contextAttributeName, ContextAttributeValue = contextAttributeValue }); - return this; - } - - /// - public virtual IEventBuilder CorrelateUsing(IDictionary correlations) - { - if (correlations == null) throw new ArgumentNullException(nameof(correlations)); - this.Event.Correlations = correlations.Select(kvp => new EventCorrelationDefinition() { ContextAttributeName = kvp.Key, ContextAttributeValue = kvp.Value }).ToList(); - return this; - } - - /// - public virtual IEventBuilder IsConsumed() - { - this.Event.Kind = EventKind.Consumed; - return this; - } - - /// - public virtual IEventBuilder IsProduced() - { - this.Event.Kind = EventKind.Produced; - return this; - } - - /// - public virtual EventDefinition Build() => this.Event; - -} diff --git a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/EventStateBuilder.cs b/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/EventStateBuilder.cs deleted file mode 100644 index c9b87ca..0000000 --- a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/EventStateBuilder.cs +++ /dev/null @@ -1,67 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace ServerlessWorkflow.Sdk.Services.FluentBuilders; - -/// -/// Represents the default implementation of the interface -/// -public class EventStateBuilder - : StateBuilder, IEventStateBuilder -{ - - /// - /// Initializes a new - /// - /// The the belongs to - public EventStateBuilder(IPipelineBuilder pipeline) : base(pipeline) { } - - /// - public virtual IEventStateBuilder TriggeredBy(Action triggerSetup) - { - if (triggerSetup == null) throw new ArgumentNullException(nameof(triggerSetup)); - var builder = new EventStateTriggerBuilder(this.Pipeline); - triggerSetup(builder); - this.State.OnEvents.Add(builder.Build()); - return this; - } - - /// - public virtual IEventStateBuilder WaitForAll() - { - this.State.Exclusive = false; - return this; - } - - /// - public virtual IEventStateBuilder WaitForAny() - { - this.State.Exclusive = true; - return this; - } - - /// - public virtual IEventStateBuilder For(TimeSpan duration) - { - this.State.Timeout = duration; - return this; - } - - /// - public virtual IEventStateBuilder Forever() - { - this.State.Timeout = null; - return this; - } - -} diff --git a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/EventStateTriggerBuilder.cs b/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/EventStateTriggerBuilder.cs deleted file mode 100644 index 6d1d2a4..0000000 --- a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/EventStateTriggerBuilder.cs +++ /dev/null @@ -1,141 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace ServerlessWorkflow.Sdk.Services.FluentBuilders; - -/// -/// Represents the default implementation of the interface -/// -public class EventStateTriggerBuilder - : IEventStateTriggerBuilder -{ - - /// - /// Initializes a new - /// - /// The the belongs to - public EventStateTriggerBuilder(IPipelineBuilder pipeline) - { - this.Pipeline = pipeline; - } - - /// - /// Gets the the belongs to - /// - protected IPipelineBuilder Pipeline { get; } - - /// - /// Gets the to configure - /// - protected EventStateTriggerDefinition Trigger { get; } = new EventStateTriggerDefinition(); - - /// - public virtual IEventStateTriggerBuilder On(params string[] events) - { - if (events != null) - { - foreach(string e in events) - { - this.Trigger.EventRefs.Add(e); - } - } - return this; - } - - /// - public virtual IEventStateTriggerBuilder On(params Action[] eventSetups) - { - if (eventSetups != null) - { - foreach (Action eventSetup in eventSetups) - { - this.Trigger.EventRefs.Add(this.Pipeline.AddEvent(eventSetup).Name); - } - } - return this; - } - - /// - public virtual IEventStateTriggerBuilder On(params EventDefinition[] events) - { - if (events != null) - { - foreach (EventDefinition e in events) - { - this.Trigger.EventRefs.Add(this.Pipeline.AddEvent(e).Name); - } - } - return this; - } - - /// - public virtual IEventStateTriggerBuilder Execute(ActionDefinition action) - { - if (action == null) throw new ArgumentNullException(nameof(action)); - this.Trigger.Actions.Add(action); - return this; - } - - /// - public virtual IEventStateTriggerBuilder Execute(Action actionSetup) - { - if (actionSetup == null) throw new ArgumentNullException(nameof(actionSetup)); - var builder = new ActionBuilder(this.Pipeline); - actionSetup(builder); - return this.Execute(builder.Build()); - } - - /// - public virtual IEventStateTriggerBuilder Execute(string name, Action actionSetup) - { - if (string.IsNullOrWhiteSpace(name)) throw new ArgumentNullException(nameof(name)); - if (actionSetup == null) throw new ArgumentNullException(nameof(actionSetup)); - return this.Execute(a => - { - actionSetup(a); - a.WithName(name); - }); - } - - /// - public virtual IEventStateTriggerBuilder Sequentially() - { - this.Trigger.ActionMode = ActionExecutionMode.Sequential; - return this; - } - - /// - public virtual IEventStateTriggerBuilder Concurrently() - { - this.Trigger.ActionMode = ActionExecutionMode.Parallel; - return this; - } - - /// - public virtual IEventStateTriggerBuilder FilterPayload(string expression) - { - this.Trigger.EventDataFilter.Data = expression; - return this; - } - - /// - public virtual IEventStateTriggerBuilder ToStateData(string expression) - { - this.Trigger.EventDataFilter.ToStateData = expression; - return this; - } - - /// - public virtual EventStateTriggerDefinition Build() => this.Trigger; - -} diff --git a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/EventSwitchCaseBuilder.cs b/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/EventSwitchCaseBuilder.cs deleted file mode 100644 index f292e8e..0000000 --- a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/EventSwitchCaseBuilder.cs +++ /dev/null @@ -1,73 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace ServerlessWorkflow.Sdk.Services.FluentBuilders; - -/// -/// Represents the default implementation of the interface -/// -public class EventSwitchCaseBuilder - : SwitchCaseBuilder, IEventSwitchCaseBuilder -{ - - /// - /// Initializes a new - /// - /// The the belongs to - public EventSwitchCaseBuilder(IPipelineBuilder pipeline) : base(pipeline) { } - - /// - public virtual IStateOutcomeBuilder On(string e) - { - if(string.IsNullOrWhiteSpace(e)) throw new ArgumentNullException(nameof(e)); - this.Case.EventRef = e; - return this; - } - - /// - public virtual IStateOutcomeBuilder On(Action eventSetup) - { - if (eventSetup == null) throw new ArgumentNullException(nameof(eventSetup)); - var e = this.Pipeline.AddEvent(eventSetup); - this.Case.EventRef = e.Name; - return this; - } - - /// - public virtual IStateOutcomeBuilder On(EventDefinition e) - { - if (e == null) throw new ArgumentNullException(nameof(e)); - this.Pipeline.AddEvent(e); - this.Case.EventRef = e.Name; - return this; - } - - /// - public virtual new EventCaseDefinition Build() - { - var outcome = base.Build(); - switch (outcome) - { - case EndDefinition end: - this.Case.End = end; - break; - case TransitionDefinition transition: - this.Case.Transition = transition; - break; - default: - throw new NotSupportedException($"The specified outcome type '{outcome.GetType().Name}' is not supported"); - } - return this.Case; - } - -} diff --git a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/ForEachStateBuilder.cs b/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/ForEachStateBuilder.cs deleted file mode 100644 index feb61c1..0000000 --- a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/ForEachStateBuilder.cs +++ /dev/null @@ -1,108 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace ServerlessWorkflow.Sdk.Services.FluentBuilders; - -/// -/// Represents the default implementation of the interface -/// -public class ForEachStateBuilder - : StateBuilder, IForEachStateBuilder -{ - - /// - /// Initializes a new - /// - /// The the belongs to - public ForEachStateBuilder(IPipelineBuilder pipeline) - : base(pipeline) - { - - } - - /// - public virtual IForEachStateBuilder Execute(ActionDefinition action) - { - if (action == null) throw new ArgumentNullException(nameof(action)); - this.State.Actions.Add(action); - return this; - } - - /// - public virtual IForEachStateBuilder Execute(Action actionSetup) - { - if (actionSetup == null) throw new ArgumentNullException(nameof(actionSetup)); - var actionBuilder = new ActionBuilder(this.Pipeline); - actionSetup(actionBuilder); - this.State.Actions.Add(actionBuilder.Build()); - return this; - } - - /// - public virtual IForEachStateBuilder Execute(string name, Action actionSetup) - { - if (string.IsNullOrWhiteSpace(name)) throw new ArgumentNullException(nameof(name)); - if (actionSetup == null) throw new ArgumentNullException(nameof(actionSetup)); - return this.Execute(a => - { - actionSetup(a); - a.WithName(name); - }); - } - - /// - public virtual IForEachStateBuilder Concurrently() - { - this.State.Mode = ActionExecutionMode.Parallel; - return this; - } - - /// - public virtual IForEachStateBuilder Sequentially() - { - this.State.Mode = ActionExecutionMode.Sequential; - return this; - } - - /// - public virtual IForEachStateBuilder UseInputCollection(string expression) - { - if (string.IsNullOrWhiteSpace(expression)) throw new ArgumentNullException(nameof(expression)); - this.State.InputCollection = expression; - return this; - } - - /// - public virtual IForEachStateBuilder UseIterationParameter(string expression) - { - if (string.IsNullOrWhiteSpace(expression)) throw new ArgumentNullException(nameof(expression)); - this.State.IterationParam = expression; - return this; - } - - /// - public virtual IForEachStateBuilder UseOutputCollection(string expression) - { - if (string.IsNullOrWhiteSpace(expression)) throw new ArgumentNullException(nameof(expression)); - this.State.OutputCollection = expression; - return this; - } - - /// - public virtual IForEachStateBuilder WithBatchSize(int? batchSize) - { - this.State.BatchSize = batchSize; - return this; - } - -} diff --git a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/FunctionBuilder.cs b/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/FunctionBuilder.cs deleted file mode 100644 index 9ae4f94..0000000 --- a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/FunctionBuilder.cs +++ /dev/null @@ -1,152 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace ServerlessWorkflow.Sdk.Services.FluentBuilders; - -/// -/// Represents the default implementation of the interface -/// -public class FunctionBuilder - : MetadataContainerBuilder, IFunctionBuilder -{ - - /// - /// Initializes a new - /// - /// The service used to build the workflow definition the to build belongs to - public FunctionBuilder(IWorkflowBuilder workflow) - { - this.Workflow = workflow; - } - - /// - /// Gets the service used to build the workflow definition the to build belongs to - /// - protected IWorkflowBuilder Workflow { get; } - - /// - /// Gets the to configure - /// - protected FunctionDefinition Function { get; } = new FunctionDefinition(); - - /// - public override DynamicMapping? Metadata - { - get - { - return this.Function.Metadata; - } - protected set - { - this.Function.Metadata = value; - } - } - - /// - public virtual IFunctionBuilder WithName(string name) - { - if (string.IsNullOrWhiteSpace(name)) throw new ArgumentNullException(nameof(name)); - this.Function.Name = name; - return this; - } - - /// - public virtual IFunctionBuilder WithExtensionProperty(string name, object value) - { - if (string.IsNullOrWhiteSpace(name)) throw new ArgumentNullException(nameof(name)); - this.Function.ExtensionData ??= new Dictionary(); - this.Function.ExtensionData[name] = value; - return this; - } - - /// - public virtual IFunctionBuilder WithExtensionProperties(IDictionary properties) - { - this.Function.ExtensionData = properties ?? throw new ArgumentNullException(nameof(properties)); - return this; - } - - /// - public virtual IFunctionBuilder OfType(string type) - { - this.Function.Type = type; - return this; - } - - /// - public virtual IFunctionBuilder ForOperation(string operation) - { - if (string.IsNullOrWhiteSpace(operation)) throw new ArgumentNullException(nameof(operation)); - this.Function.Operation = operation; - return this; - } - - /// - public virtual IFunctionBuilder ForOperation(Uri operation) - { - if (operation == null) throw new ArgumentNullException(nameof(operation)); - this.Function.Operation = operation.ToString(); - return this; - } - - /// - public virtual IFunctionBuilder UseAuthentication(string authentication) - { - if (string.IsNullOrWhiteSpace(authentication)) throw new ArgumentNullException(nameof(authentication)); - this.Function.AuthRef = authentication; - return this; - } - - /// - public virtual IFunctionBuilder UseAuthentication(AuthenticationDefinition authenticationDefinition) - { - if (authenticationDefinition == null) throw new ArgumentNullException(nameof(authenticationDefinition)); - this.Function.AuthRef = authenticationDefinition.Name; - this.Workflow.AddAuthentication(authenticationDefinition); - return this; - } - - /// - public virtual IFunctionBuilder UseBasicAuthentication(string name, Action configurationAction) - { - if (string.IsNullOrWhiteSpace(name)) throw new ArgumentNullException(nameof(name)); - if (configurationAction == null) throw new ArgumentNullException(nameof(configurationAction)); - this.Function.AuthRef = name; - this.Workflow.AddBasicAuthentication(name, configurationAction); - return this; - } - - /// - public virtual IFunctionBuilder UseBearerAuthentication(string name, Action configurationAction) - { - if (string.IsNullOrWhiteSpace(name)) throw new ArgumentNullException(nameof(name)); - if (configurationAction == null) throw new ArgumentNullException(nameof(configurationAction)); - this.Function.AuthRef = name; - this.Workflow.AddBearerAuthentication(name, configurationAction); - return this; - } - - /// - public virtual IFunctionBuilder UseOAuth2Authentication(string name, Action configurationAction) - { - if (string.IsNullOrWhiteSpace(name)) throw new ArgumentNullException(nameof(name)); - if (configurationAction == null) throw new ArgumentNullException(nameof(configurationAction)); - this.Function.AuthRef = name; - this.Workflow.AddOAuth2Authentication(name, configurationAction); - return this; - } - - /// - public virtual FunctionDefinition Build() => this.Function; - -} diff --git a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/InjectStateBuilder.cs b/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/InjectStateBuilder.cs deleted file mode 100644 index 7a9d14e..0000000 --- a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/InjectStateBuilder.cs +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace ServerlessWorkflow.Sdk.Services.FluentBuilders; - -/// -/// Represents the default implementation of the interface -/// -public class InjectStateBuilder - : StateBuilder, IInjectStateBuilder -{ - - /// - /// Initializes a new - /// - /// The the belongs to - public InjectStateBuilder(IPipelineBuilder pipeline) : base(pipeline) { } - - /// - public virtual IInjectStateBuilder Data(object data) - { - if (data == null) throw new ArgumentNullException(nameof(data)); - this.State.Data = data; - return this; - } - -} diff --git a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IActionBuilder.cs b/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IActionBuilder.cs deleted file mode 100644 index 135f848..0000000 --- a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IActionBuilder.cs +++ /dev/null @@ -1,123 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace ServerlessWorkflow.Sdk.Services.FluentBuilders; - -/// -/// Defines the fundamentals of a service used to build s -/// -public interface IActionBuilder - : IExtensibleBuilder -{ - - /// - /// Sets the name of the to build - /// - /// The name of the to build - /// The configured - IActionBuilder WithName(string name); - - /// - /// Sets a runtime expression that represents the condition, if any, the to build must satisfy to be run - /// - /// The runtime expression that represents the condition the must satisfy to run - /// The configured - IActionBuilder WithCondition(string expression); - - /// - /// Configures the workflow expression used to filter the state data passed to the - /// - /// The workflow expression used to filter the 's input state data - /// The configured - IActionBuilder FromStateData(string expression); - - /// - /// Configures the workflow expression used to filter the 's results - /// - /// The workflow expression used to filter the 's results - /// The configured - IActionBuilder FilterResults(string expression); - - /// - /// Configures the workflow expression used to merge the 's results into the state data - /// - /// The workflow expression used to merge the 's results into the state data - /// The configured - IActionBuilder ToStateData(string expression); - - /// - /// Invokes the specified - /// - /// The reference name of the to invoke. Requires the referenced to have been previously defined - /// The configured - IFunctionActionBuilder Invoke(string function); - - /// - /// Invokes the specified - /// - /// An used to setup the to invoke - /// The configured - IFunctionActionBuilder Invoke(Action functionSetup); - - /// - /// Invokes the specified - /// - /// The to invoke - /// The configured - IFunctionActionBuilder Invoke(FunctionDefinition function); - - /// - /// Configures the to build to consume the specified - /// - /// The reference name of the to consume. Requires the referenced to have been previously defined - /// The configured - IEventTriggerActionBuilder Consume(string e); - - /// - /// Configures the to build to consume the specified - /// - /// The used to create the to consume - /// The configured - IEventTriggerActionBuilder Consume(Action eventSetup); - - /// - /// Configures the to build to consume the specified - /// - /// The to consume - /// The configured - IEventTriggerActionBuilder Consume(EventDefinition e); - - /// - /// Configures the to build to run the specified workflow definition - /// - /// The id of the workflow definition to run - /// The version of the workflow definition to run - /// The 's . Defaults to - /// The service used to build s - ISubflowActionBuilder Run(string workflowId, string version, string invocationMode = InvocationMode.Synchronous); - - /// - /// Configures the to build to run the specified workflow definition - /// - /// The id of the workflow definition to run - /// The 's . Defaults to - /// The service used to build s - ISubflowActionBuilder Run(string workflowId, string invocationMode = InvocationMode.Synchronous); - - /// - /// Builds the - /// - /// A new - ActionDefinition Build(); - -} diff --git a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IActionCollectionBuilder.cs b/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IActionCollectionBuilder.cs deleted file mode 100644 index 919e031..0000000 --- a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IActionCollectionBuilder.cs +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace ServerlessWorkflow.Sdk.Services.FluentBuilders; - -/// -/// Defines the fundamentals of a service used to build a collection of s -/// -/// -public interface IActionCollectionBuilder - : IActionContainerBuilder - where TContainer : class, IActionCollectionBuilder -{ - - /// - /// Configures the container to run defined actions sequentially - /// - /// The configured container - TContainer Sequentially(); - - /// - /// Configures the container to run defined actions concurrently - /// - /// The configured container - TContainer Concurrently(); - -} diff --git a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IActionContainerBuilder.cs b/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IActionContainerBuilder.cs deleted file mode 100644 index e3d5bca..0000000 --- a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IActionContainerBuilder.cs +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace ServerlessWorkflow.Sdk.Services.FluentBuilders; - -/// -/// Defines the fundamentals of a service that defines an -/// -/// The container's type -public interface IActionContainerBuilder - where TContainer : class, IActionContainerBuilder -{ - - /// - /// Creates and configures a new to be executed by the container - /// - /// The to execute - /// The configured container - TContainer Execute(ActionDefinition action); - - /// - /// Creates and configures a new to be executed by the container - /// - /// An used to setup the to execute - /// The configured container - TContainer Execute(Action actionSetup); - - /// - /// Creates and configures a new to be executed by the container - /// - /// The name of the to execute - /// An used to setup the to execute - /// The configured container - TContainer Execute(string name, Action actionSetup); - -} diff --git a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IAuthenticationDefinitionBuilder.cs b/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IAuthenticationDefinitionBuilder.cs deleted file mode 100644 index 401d311..0000000 --- a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IAuthenticationDefinitionBuilder.cs +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace ServerlessWorkflow.Sdk.Services.FluentBuilders; - -/// -/// Defines the fundamentals of a service used to build an authentication definition -/// -public interface IAuthenticationDefinitionBuilder - : IExtensibleBuilder -{ - - /// - /// Sets the name of the authentication definition to build - /// - /// The name of the authentication definition to build - /// The configured - IAuthenticationDefinitionBuilder WithName(string name); - - /// - /// Loads the authentication definition from a secret - /// - /// The name of the secret to load the authentication definition from - void LoadFromSecret(string secret); - - /// - /// Builds the authentication definition - /// - /// A new authentication definition - AuthenticationDefinition Build(); - -} diff --git a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IBasicAuthenticationBuilder.cs b/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IBasicAuthenticationBuilder.cs deleted file mode 100644 index a55691f..0000000 --- a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IBasicAuthenticationBuilder.cs +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace ServerlessWorkflow.Sdk.Services.FluentBuilders; - -/// -/// Defines the fundamentals of a service used to build a authentication definition with scheme -/// -public interface IBasicAuthenticationBuilder - : IAuthenticationDefinitionBuilder -{ - - /// - /// Configures the authentication definition to use the specified username to authenticate - /// - /// The username to use - /// The configured - IBasicAuthenticationBuilder WithUserName(string username); - - /// - /// Configures the authentication definition to use the specified password to authenticate - /// - /// The password to use - /// The configured - IBasicAuthenticationBuilder WithPassword(string password); - -} diff --git a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IBearerAuthenticationBuilder.cs b/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IBearerAuthenticationBuilder.cs deleted file mode 100644 index dc4f7f3..0000000 --- a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IBearerAuthenticationBuilder.cs +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace ServerlessWorkflow.Sdk.Services.FluentBuilders; - -/// -/// Defines the fundamentals of a service used to build a authentication definition with scheme -/// -public interface IBearerAuthenticationBuilder - : IAuthenticationDefinitionBuilder -{ - - /// - /// Configures the authentication definition to use the specified token to authenticate - /// - /// The token to use - /// The configured - IBearerAuthenticationBuilder WithToken(string token); - -} diff --git a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IBranchBuilder.cs b/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IBranchBuilder.cs deleted file mode 100644 index 6f5d02e..0000000 --- a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IBranchBuilder.cs +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace ServerlessWorkflow.Sdk.Services.FluentBuilders; - -/// -/// Defines the fundamentals of a service used to configure s -/// -public interface IBranchBuilder - : IActionCollectionBuilder, IExtensibleBuilder -{ - - /// - /// Sets the 's name - /// - /// The 's name - /// The configured - IBranchBuilder WithName(string name); - - /// - /// Builds the - /// - /// A new - BranchDefinition Build(); - -} diff --git a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/ICallbackStateBuilder.cs b/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/ICallbackStateBuilder.cs deleted file mode 100644 index 72f131d..0000000 --- a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/ICallbackStateBuilder.cs +++ /dev/null @@ -1,80 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace ServerlessWorkflow.Sdk.Services.FluentBuilders; - -/// -/// Defines the fundamentals of the service used to build s -/// -public interface ICallbackStateBuilder - : IStateBuilder -{ - - /// - /// Configures the to execute the specified upon consumption of the callback - /// - /// The name of the to build - /// The used to create the to execute - /// The configured - ICallbackStateBuilder Execute(string name, Action actionSetup); - - /// - /// Configures the to execute the specified upon consumption of the callback - /// - /// The used to create the to execute - /// The configured - ICallbackStateBuilder Execute(Action actionSetup); - - /// - /// Configures the to execute the specified upon consumption of the callback - /// - /// The to execute - /// The configured - ICallbackStateBuilder Execute(ActionDefinition action); - - /// - /// Configures the to wait for the consumption of a defined by specified - /// - /// The reference name of the that defines the to consume - /// The configured - ICallbackStateBuilder On(string e); - - /// - /// Configures the to wait for the consumption of a defined by specified - /// - /// The used to build the that defines the to consume - /// The configured - ICallbackStateBuilder On(Action eventSetup); - - /// - /// Configures the to wait for the consumption of a defined by specified - /// - /// The that defines the to consume - /// The configured - ICallbackStateBuilder On(EventDefinition e); - - /// - /// Configures the to filter the payload of the callback - /// - /// The workflow expression used to filter payload of the callback - /// The configured - ICallbackStateBuilder FilterPayload(string expression); - - /// - /// Configures the to filter the payload of the callback - /// - /// The expression that selects a state data element to which the action results should be added/merged into - /// The configured - ICallbackStateBuilder ToStateData(string expression); - -} diff --git a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IDataSwitchCaseBuilder.cs b/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IDataSwitchCaseBuilder.cs deleted file mode 100644 index 2dc0cfd..0000000 --- a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IDataSwitchCaseBuilder.cs +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace ServerlessWorkflow.Sdk.Services.FluentBuilders; - -/// -/// Defines the fundamentals of a service used to build data-based -/// -public interface IDataSwitchCaseBuilder - : ISwitchCaseBuilder -{ - - /// - /// Sets the 's workflow expression used to evaluate the data - /// - /// The workflow expression used to evaluate the data - /// The configured - IDataSwitchCaseBuilder When(string expression); - - /// - /// Builds the - /// - /// A new - new DataCaseDefinition Build(); - -} diff --git a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IDataSwitchStateBuilder.cs b/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IDataSwitchStateBuilder.cs deleted file mode 100644 index a7602c8..0000000 --- a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IDataSwitchStateBuilder.cs +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace ServerlessWorkflow.Sdk.Services.FluentBuilders; - -/// -/// Defines the fundamentals of a service used to build s -/// -public interface IDataSwitchStateBuilder - : ISwitchStateBuilder -{ - - /// - /// Creates and configures a new data-based - /// - /// The used to build the data-based - /// The configured - IDataSwitchStateBuilder WithCase(Action caseBuilder); - - /// - /// Creates and configures a new data-based - /// - /// The name of the to add - /// The used to build the data-based - /// The configured - IDataSwitchStateBuilder WithCase(string name, Action caseBuilder); - -} diff --git a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IErrorHandlerBuilder.cs b/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IErrorHandlerBuilder.cs deleted file mode 100644 index b035b5e..0000000 --- a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IErrorHandlerBuilder.cs +++ /dev/null @@ -1,64 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace ServerlessWorkflow.Sdk.Services.FluentBuilders; - -/// -/// Defines the fundamentals of a service used to build s -/// -public interface IErrorHandlerBuilder - : IExtensibleBuilder -{ - - /// - /// Configures the used by - /// - /// The reference name of the to use - /// - IErrorHandlerBuilder Retry(string strategy); - - /// - /// Configures the to catch the specified errors - /// - /// The domain-specific errors to catch - /// The code of the errors to catch - /// The configured - IErrorHandlerBuilder Catch(string error, string errorCode); - - /// - /// Configures the to catch the specified errors - /// - /// The domain-specific errors to catch - /// The configured - IErrorHandlerBuilder Catch(string error); - - /// - /// Configures the to catch any error - /// - /// The configured - IErrorHandlerBuilder CatchAll(); - - /// - /// Configures the outcome of handled errors - /// - /// An used to setup the outcome of handled errors - /// The configured - IErrorHandlerBuilder Then(Action outcomeSetup); - - /// - /// Builds the - /// - /// A new - ErrorHandlerDefinition Build(); - -} diff --git a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IEventBuilder.cs b/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IEventBuilder.cs deleted file mode 100644 index 1962694..0000000 --- a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IEventBuilder.cs +++ /dev/null @@ -1,84 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace ServerlessWorkflow.Sdk.Services.FluentBuilders; - -/// -/// Defines the fundamentals of a service used to build s -/// -public interface IEventBuilder - : IMetadataContainerBuilder, IExtensibleBuilder -{ - - /// - /// Sets the name of the to build - /// - /// The name of the to build - /// The configured - IEventBuilder WithName(string name); - - /// - /// Sets the 's to - /// - /// The configured - IEventBuilder IsConsumed(); - - /// - /// Sets the 's to - /// - /// The configured - IEventBuilder IsProduced(); - - /// - /// Sets the source of the to build - /// - /// The source of the to build - /// The configured - IEventBuilder WithSource(Uri source); - - /// - /// Sets the type of the to build - /// - /// The type of the to build - /// The configured - IEventBuilder WithType(string type); - - /// - /// Configures the to use the specified context attribute while performing correlation - /// - /// The name of the context attribute to use - /// The configured - IEventBuilder CorrelateUsing(string contextAttributeName); - - /// - /// Configures the to use the specified context attribute while performing correlation - /// - /// The name of the context attribute to use - /// The static value or workflow expression used during correlation - /// The configured - IEventBuilder CorrelateUsing(string contextAttributeName, string contextAttributeValue); - - /// - /// Configures the to use the specified context attribute while performing correlation - /// - /// A containing the context attribute key/value pairs to used when performing correlation - /// The configured - IEventBuilder CorrelateUsing(IDictionary correlations); - - /// - /// Builds the - /// - /// A new - EventDefinition Build(); - -} diff --git a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IEventStateBuilder.cs b/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IEventStateBuilder.cs deleted file mode 100644 index efe7bbf..0000000 --- a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IEventStateBuilder.cs +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace ServerlessWorkflow.Sdk.Services.FluentBuilders; - -/// -/// Defines the fundamentals of the service used to build s -/// -public interface IEventStateBuilder - : IStateBuilder -{ - - /// - /// Builds, configures and adds a new to the - /// - /// The used to build the - /// The configured - IEventStateBuilder TriggeredBy(Action triggerSetup); - - /// - /// Configures the to wait for all triggers to complete before resuming the workflow's execution - /// - /// The configured - IEventStateBuilder WaitForAll(); - - /// - /// Configures the to wait for any trigger to complete before resuming the workflow's execution - /// - /// The configured - IEventStateBuilder WaitForAny(); - - /// - /// Sets the duration after which the times out - /// - /// The duration after which the times out - /// The configured - IEventStateBuilder For(TimeSpan duration); - - /// - /// Configures the to never time out - /// - /// The configured - IEventStateBuilder Forever(); - -} diff --git a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IEventStateTriggerBuilder.cs b/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IEventStateTriggerBuilder.cs deleted file mode 100644 index d4a1ed7..0000000 --- a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IEventStateTriggerBuilder.cs +++ /dev/null @@ -1,64 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace ServerlessWorkflow.Sdk.Services.FluentBuilders; - -/// -/// Defines the fundamentals of the service used to build s -/// -public interface IEventStateTriggerBuilder - : IActionCollectionBuilder -{ - - /// - /// Configures the to consume the s defined by the specified s - /// - /// An array containing the reference names of the s that define the s to consume - /// The configured - IEventStateTriggerBuilder On(params string[] events); - - /// - /// Configures the to consume the s defined by the specified s - /// - /// An array containing the s used to build the s that define the s to consume - /// The configured - IEventStateTriggerBuilder On(params Action[] eventSetups); - - /// - /// Configures the to consume the s defined by the specified s - /// - /// An array the s that define the s to consume - /// The configured - IEventStateTriggerBuilder On(params EventDefinition[] events); - - /// - /// Configures the to filter the payload of consumed s - /// - /// The workflow expression used to filter payload of consumed s - /// The configured - IEventStateTriggerBuilder FilterPayload(string expression); - - /// - /// Configures the to select the state data element to which the action results should be added/merged into - /// - /// The expression that selects a state data element to which the action results should be added/merged into - /// The configured - IEventStateTriggerBuilder ToStateData(string expression); - - /// - /// Builds the - /// - /// A new - EventStateTriggerDefinition Build(); - -} diff --git a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IEventSwitchCaseBuilder.cs b/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IEventSwitchCaseBuilder.cs deleted file mode 100644 index 9d29ba1..0000000 --- a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IEventSwitchCaseBuilder.cs +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace ServerlessWorkflow.Sdk.Services.FluentBuilders; - -/// -/// Defines the fundamentals of a service used to build -based -/// -public interface IEventSwitchCaseBuilder - : ISwitchCaseBuilder -{ - - /// - /// Creates and configures a new outcome when consuming any of the specified events - /// - /// The reference name of the s to consume - /// A new used to build the outcome of the consumed s - IStateOutcomeBuilder On(string e); - - /// - /// Creates and configures a new outcome when consuming any of the specified events - /// - /// The used to build the s to consume - /// A new used to build the outcome of the consumed s - IStateOutcomeBuilder On(Action eventSetup); - - /// - /// Creates and configures a new outcome when consuming any of the specified events - /// - /// The s to consume - /// A new used to build the outcome of the consumed s - IStateOutcomeBuilder On(EventDefinition e); - - /// - /// Builds the - /// - /// A new - new EventCaseDefinition Build(); - -} diff --git a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IEventSwitchStateBuilder.cs b/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IEventSwitchStateBuilder.cs deleted file mode 100644 index cc1a949..0000000 --- a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IEventSwitchStateBuilder.cs +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace ServerlessWorkflow.Sdk.Services.FluentBuilders; - -/// -/// Defines the fundamentals of a service used to build -based -/// -public interface IEventSwitchStateBuilder - : ISwitchStateBuilder -{ - - /// - /// Sets the duration after which the 's execution times out - /// - /// The duration after which the 's execution times out - /// The configured - IEventSwitchStateBuilder TimeoutAfter(TimeSpan duration); - - /// - /// Creates and configures a new data-based - /// - /// The used to build the -based - /// The configured - IEventSwitchStateBuilder WithCase(Action caseBuilder); - - /// - /// Creates and configures a new data-based - /// - /// The name of the case to add - /// The used to build the -based - /// The configured - IEventSwitchStateBuilder WithCase(string name, Action caseBuilder); - -} diff --git a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IEventTriggerActionBuilder.cs b/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IEventTriggerActionBuilder.cs deleted file mode 100644 index a3febdd..0000000 --- a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IEventTriggerActionBuilder.cs +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace ServerlessWorkflow.Sdk.Services.FluentBuilders; - -/// -/// Defines the fundamentals of a service used to build s of type -/// -public interface IEventTriggerActionBuilder - : IExtensibleBuilder -{ - - /// - /// Configures the to produce the specified when triggered - /// - /// The reference name of the to produce. Requires the referenced to have been previously defined. - /// The configured - IEventTriggerActionBuilder ThenProduce(string e); - - /// - /// Configures the to produce the specified when triggered - /// - /// The used to create the to produce - /// The configured - IEventTriggerActionBuilder ThenProduce(Action eventSetup); - - /// - /// Adds the specified context attribute to the produced as a result of the trigger - /// - /// The name of the context attribute to add - /// The value of the context attribute to add - /// The configured - IEventTriggerActionBuilder WithContextAttribute(string name, string value); - - /// - /// Adds the specified context attribute to the produced as a result of the trigger - /// - /// An containing the context attributes to add to the e produced as a result of the trigger - /// The configured - IEventTriggerActionBuilder WithContextAttributes(IDictionary contextAttributes); - - /// - /// Builds the - /// - /// A new - ActionDefinition Build(); - -} diff --git a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IExtensibleBuilder.cs b/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IExtensibleBuilder.cs deleted file mode 100644 index 891a68c..0000000 --- a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IExtensibleBuilder.cs +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace ServerlessWorkflow.Sdk.Services.FluentBuilders; - -/// -/// Defines the fundamentals of a service used to build s -/// -/// The type of the -public interface IExtensibleBuilder - where TExtensible : class, IExtensibleBuilder -{ - - /// - /// Adds the specified extension property - /// - /// The extension property name - /// The extension property value - /// The configured container - TExtensible WithExtensionProperty(string name, object value); - - /// - /// Adds the specified extension property - /// - /// A name/value mapping of the extension properties to add - /// The configured container - TExtensible WithExtensionProperties(IDictionary properties); - -} \ No newline at end of file diff --git a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IForEachStateBuilder.cs b/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IForEachStateBuilder.cs deleted file mode 100644 index 1632716..0000000 --- a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IForEachStateBuilder.cs +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace ServerlessWorkflow.Sdk.Services.FluentBuilders; - -/// -/// Defines the fundamentals of a service used to build s -/// -public interface IForEachStateBuilder - : IStateBuilder, - IActionCollectionBuilder -{ - - /// - /// Configures the to use the specified expression when resolving the input collection - /// - /// The expression to use when resolving the input collection - /// The configured - IForEachStateBuilder UseInputCollection(string expression); - - /// - /// Configures the to use the specified expression when resolving the iteration parameter - /// - /// The expression to use when resolving the iteration parameter - /// The configured - IForEachStateBuilder UseIterationParameter(string expression); - - /// - /// Configures the to use the specified expression when resolving the output collection - /// - /// The expression to use when resolving the output collection - /// The configured - IForEachStateBuilder UseOutputCollection(string expression); - - /// - /// Configures how many iterations may run in parallel at the same time. Used if '' has been set to '' - /// - /// The maximum amount of iterations allowed - /// The configured - IForEachStateBuilder WithBatchSize(int? batchSize); - -} diff --git a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IFunctionActionBuilder.cs b/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IFunctionActionBuilder.cs deleted file mode 100644 index 6474669..0000000 --- a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IFunctionActionBuilder.cs +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace ServerlessWorkflow.Sdk.Services.FluentBuilders; - -/// -/// Defines the service used to build s of type -/// -public interface IFunctionActionBuilder - : IActionBuilder, IExtensibleBuilder -{ - - /// - /// Configures the to use the specified GraphQL selection set - /// - /// The GraphQL selection set to use - /// Only supported for s of type - /// The configured - IFunctionActionBuilder WithSelectionSet(string selectionSet); - - /// - /// Configures the to use the specified argument when performing the function call - /// - /// The name of the argument to add - /// The value or workflow expression of the argument to add - /// The configured - IFunctionActionBuilder WithArgument(string name, object value); - - /// - /// Configures the to use the specified argument when performing the function call - /// - /// An containing the name/value pairs of the arguments to use - /// The configured - IFunctionActionBuilder WithArguments(IDictionary args); - -} diff --git a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IFunctionBuilder.cs b/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IFunctionBuilder.cs deleted file mode 100644 index 7e6aa62..0000000 --- a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IFunctionBuilder.cs +++ /dev/null @@ -1,95 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace ServerlessWorkflow.Sdk.Services.FluentBuilders; - -/// -/// Defines the fundamentals of a service used to build s -/// -public interface IFunctionBuilder - : IMetadataContainerBuilder, IExtensibleBuilder -{ - - /// - /// Sets the name of the to build - /// - /// The name of the to build - /// The configured - IFunctionBuilder WithName(string name); - - /// - /// Sets the type of the to build - /// - /// The type of the to build - /// The configured - IFunctionBuilder OfType(string type); - - /// - /// Sets the 's operation expression. Sets the 's to - /// - /// The 's operation expression - /// The configured - IFunctionBuilder ForOperation(string operation); - - /// - /// Sets the 's operation uri. Sets the 's to - /// - /// The 's operation uri - /// The configured - IFunctionBuilder ForOperation(Uri operation); - - /// - /// Configures the to use the specified authentication definition - /// - /// The name of the authentication definition to use - /// The configured - IFunctionBuilder UseAuthentication(string authentication); - - /// - /// Configures the to use the specified authentication definition - /// - /// The authentication definition to use - /// The configured - IFunctionBuilder UseAuthentication(AuthenticationDefinition authenticationDefinition); - - /// - /// Configures the to use an authentication definition with scheme - /// - /// The name of the authentication definition to use - /// An to setup the authentication definition to use - /// The configured - IFunctionBuilder UseBasicAuthentication(string name, Action configurationAction); - - /// - /// Configures the to use an authentication definition with scheme - /// - /// The name of the authentication definition to use - /// An to setup the authentication definition to use - /// The configured - IFunctionBuilder UseBearerAuthentication(string name, Action configurationAction); - - /// - /// Configures the to use an authentication definition with scheme - /// - /// The name of the authentication definition to use - /// An to setup the authentication definition to use - /// The configured - IFunctionBuilder UseOAuth2Authentication(string name, Action configurationAction); - - /// - /// Builds the - /// - /// A new - FunctionDefinition Build(); - -} diff --git a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IMetadataContainerBuilder.cs b/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IMetadataContainerBuilder.cs deleted file mode 100644 index a860ac2..0000000 --- a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IMetadataContainerBuilder.cs +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace ServerlessWorkflow.Sdk.Services.FluentBuilders; - -/// -/// Defines the fundamentals of a service used to build metadata containers -/// -/// The type of the -public interface IMetadataContainerBuilder - where TContainer : class, IMetadataContainerBuilder -{ - - /// - /// Gets the container's metadata - /// - DynamicMapping? Metadata { get; } - - /// - /// Adds the specified metadata - /// - /// The metadata key - /// The metadata value - /// The configured container - TContainer WithMetadata(string key, object value); - - /// - /// Adds the specified metadata - /// - /// An representing the container's metadata - /// The configured container - TContainer WithMetadata(IDictionary metadata); - -} diff --git a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IOAuth2AuthenticationBuilder.cs b/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IOAuth2AuthenticationBuilder.cs deleted file mode 100644 index bde3109..0000000 --- a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IOAuth2AuthenticationBuilder.cs +++ /dev/null @@ -1,95 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace ServerlessWorkflow.Sdk.Services.FluentBuilders; - -/// -/// Defines the fundamentals of a service used to build a authentication definition with scheme -/// -public interface IOAuth2AuthenticationBuilder - : IAuthenticationDefinitionBuilder -{ - - /// - /// Configures the authentication definition to use the specified when requesting an access token - /// - /// The to use - /// The configured - IOAuth2AuthenticationBuilder UseGrantType(string grantType); - - /// - /// Configures the authentication definition to use the specified authority to generate an access token - /// - /// The uri of the OAuth2 authority to use - /// The configured - IOAuth2AuthenticationBuilder WithAuthority(Uri authority); - - /// - /// Configures the authentication definition to use the specified client ID when requesting an access token - /// - /// The client ID to use - /// The configured - IOAuth2AuthenticationBuilder WithClientId(string clientId); - - /// - /// Configures the authentication definition to use the specified client secret when requesting an access token - /// - /// The username to use - /// The configured - IOAuth2AuthenticationBuilder WithClientSecret(string clientSecret); - - /// - /// Configures the authentication definition to use the specified username to authenticate - /// - /// The username to use - /// The configured - IOAuth2AuthenticationBuilder WithUserName(string username); - - /// - /// Configures the authentication definition to use the specified password to authenticate - /// - /// The password to use - /// The configured - IOAuth2AuthenticationBuilder WithPassword(string password); - - /// - /// Configures the authentication definition to use the specified scopes when requesting an access token - /// - /// An array containing the scopes to use - /// The configured - IOAuth2AuthenticationBuilder UseScopes(params string[] scopes); - - /// - /// Configures the authentication definition to use the specified audiences when requesting an access token - /// - /// An array containing the audiences to use - /// The configured - IOAuth2AuthenticationBuilder UseAudiences(params string[] audiences); - - /// - /// Configures the token that represents the identity of the party on behalf of whom the request is being made.Typically, the subject of this token will be the subject of the security token issued in response to the request. - /// - /// The type of the specified token - /// The subject token - /// The configured - IOAuth2AuthenticationBuilder WithSubjectToken(string tokenType, string token); - - /// - /// Configures the token that represents the identity of the acting party.Typically, this will be the party that is authorized to use the requested security token and act on behalf of the subject. - /// - /// The type of the specified token - /// The actor token - /// The configured - IOAuth2AuthenticationBuilder WithActorToken(string tokenType, string token); - -} diff --git a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IParallelStateBuilder.cs b/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IParallelStateBuilder.cs deleted file mode 100644 index a1ba271..0000000 --- a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IParallelStateBuilder.cs +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace ServerlessWorkflow.Sdk.Services.FluentBuilders; - -/// -/// Defines the fundamentals of a service used to build s -/// -public interface IParallelStateBuilder - : IStateBuilder -{ - - /// - /// Creates and configures a new - /// - /// The used to setup the - /// The configured - IParallelStateBuilder Branch(Action branchSetup); - - /// - /// Creates and configures a new - /// - /// The name of the to build - /// The used to setup the - /// The configured - IParallelStateBuilder Branch(string name, Action branchSetup); - - /// - /// Configures the to wait for all branches to complete before resuming the workflow's execution - /// - /// The configured - IParallelStateBuilder WaitForAll(); - - /// - /// Configures the to wait for the specified amount of branches to complete before resuming the workflow's execution - /// - /// The amount of branches to wait for the execution of - /// The configured - IParallelStateBuilder WaitFor(uint amount); - -} diff --git a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IPipelineBuilder.cs b/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IPipelineBuilder.cs deleted file mode 100644 index 5210503..0000000 --- a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IPipelineBuilder.cs +++ /dev/null @@ -1,107 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace ServerlessWorkflow.Sdk.Services.FluentBuilders; - - -/// -/// Defines the fundamentals of a service used to build state definition charts -/// -public interface IPipelineBuilder -{ - - /// - /// Adds the specified to the pipeline - /// - /// The used to setup the to add - /// A new - EventDefinition AddEvent(Action eventSetup); - - /// - /// Adds the specified to the pipeline - /// - /// The to add - /// A new - EventDefinition AddEvent(EventDefinition e); - - /// - /// Adds the specified to the pipeline - /// - /// The used to setup the to add - /// A new - FunctionDefinition AddFunction(Action functionSetup); - - /// - /// Adds the specified to the pipeline - /// - /// The to add - /// A new - FunctionDefinition AddFunction(FunctionDefinition function); - - /// - /// Adds the specified state definition to the pipeline - /// - /// The used to build and configure the state definition to add - /// A new state definition - StateDefinition AddState(Func stateSetup); - - /// - /// Adds the specified state definition to the pipeline - /// - /// The state definition to add - /// The newly added state definition - StateDefinition AddState(StateDefinition state); - - /// - /// Transitions to the specified state definition - /// - /// An used to setup the state definition to transition to - /// A new used to configure the state definition to transition to - IPipelineBuilder Then(Func stateSetup); - - /// - /// Transitions to the specified state definition - /// - /// The name of the state definition to transition to - /// An used to setup the state definition to transition to - /// A new used to configure the state definition to transition to - IPipelineBuilder Then(string name, Func stateSetup); - - /// - /// Configure the state definition to end the workflow upon completion - /// - /// An used to setup the state definition to end the workflow with - /// The configured - IWorkflowBuilder EndsWith(Func stateSetup); - - /// - /// Configure the state definition to end the workflow upon completion - /// - /// The name of the state definition to end the workflow execution with - /// An used to setup the state definition to end the workflow with - /// The configured - IWorkflowBuilder EndsWith(string name, Func stateSetup); - - /// - /// Configures the last state definition to end the workflow upon completion - /// - /// The configured - IWorkflowBuilder End(); - - /// - /// Builds the pipeline - /// - /// A new that contains the state definitions the pipeline is made out of - IEnumerable Build(); - -} diff --git a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IRetryStrategyBuilder.cs b/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IRetryStrategyBuilder.cs deleted file mode 100644 index a9cea33..0000000 --- a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IRetryStrategyBuilder.cs +++ /dev/null @@ -1,91 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace ServerlessWorkflow.Sdk.Services.FluentBuilders; - -/// -/// Defines the fundamentals of a service used to build s -/// -public interface IRetryStrategyBuilder - : IExtensibleBuilder -{ - - /// - /// Sets the name of the to build - /// - /// The name of the to build - /// The configured - IRetryStrategyBuilder WithName(string name); - - /// - /// Sets the duration between successive retry attempts - /// - /// The duration to wait between two retry attempts - /// The configured - IRetryStrategyBuilder WithDelayOf(TimeSpan duration); - - /// - /// Configures the to not delay successive retry attempts - /// - /// The configured - IRetryStrategyBuilder WithNoDelay(); - - /// - /// Configures the 's max delay between retry attempts - /// - /// The maximum duration to wait between two retry attempt - /// The configured - IRetryStrategyBuilder WithMaxDelay(TimeSpan duration); - - /// - /// Configures the maximum amount of retry attempts - /// - /// The maximum amount of retry attempts - /// The configured - IRetryStrategyBuilder MaxAttempts(uint maxAttempts); - - /// - /// Configures the duration which will be added to the delay between successive retries - /// - /// The duration which will be added to the delay between successive retries - /// The configured - IRetryStrategyBuilder WithDelayIncrement(TimeSpan duration); - - /// - /// Configures the value by which the delay is multiplied before each attempt. - /// - /// The value by which the delay is multiplied before each attempt. - /// The configured - IRetryStrategyBuilder WithDelayMultiplier(float multiplier); - - /// - /// Configures the maximum amount of random time added or subtracted from the delay between each retry relative to total delay - /// - /// The maximum amount of random time added or subtracted from the delay between each retry relative to total delay - /// The configured - IRetryStrategyBuilder WithJitterMultiplier(float multiplier); - - /// - /// Configures the absolute maximum amount of random time added or subtracted from the delay between each retry - /// - /// The absolute maximum amount of random time added or subtracted from the delay between each retry - /// The configured - IRetryStrategyBuilder WithJitterDuration(TimeSpan duration); - - /// - /// Builds the - /// - /// A new - RetryDefinition Build(); - -} diff --git a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IScheduleBuilder.cs b/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IScheduleBuilder.cs deleted file mode 100644 index 6588c2c..0000000 --- a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IScheduleBuilder.cs +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace ServerlessWorkflow.Sdk.Services.FluentBuilders; - -/// -/// Defines the fundamentals of a service used to build a -/// -public interface IScheduleBuilder -{ - - /// - /// Configures the to execute at the specified interval - /// - /// The interval at which to execute the - /// The configured - IScheduleBuilder AtInterval(TimeSpan interval); - - /// - /// Configures the to execute at a frequency defined by the specified CRON expression - /// - /// A CRON expression that defines the frequency at which to execute the - /// The date and time when the cron expression invocation is no longer valid - /// The configured - IScheduleBuilder Every(string cronExpression, DateTime? validUntil = null); - - /// - /// Configures the to use the specified timezone - /// - /// The timezone to use - /// The configured - IScheduleBuilder UseTimezone(string? timezone); - - /// - /// Builds a new - /// - /// A new - ScheduleDefinition Build(); - -} diff --git a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IStateBuilder.cs b/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IStateBuilder.cs deleted file mode 100644 index 5791e73..0000000 --- a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IStateBuilder.cs +++ /dev/null @@ -1,94 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace ServerlessWorkflow.Sdk.Services.FluentBuilders; - -/// -/// Defines the fundamentals of a service used to configure a state definition -/// -public interface IStateBuilder -{ - - /// - /// Sets the name of the state definition to build - /// - /// The name of the state definition to build - /// The configured - IStateBuilder WithName(string name); - - /// - /// Builds the state definition - /// - /// A new state definition - StateDefinition Build(); - -} - -/// -/// Defines the fundamentals of a service used to configure a state definition -/// -/// The type of state definition to build -public interface IStateBuilder - : IStateBuilder, IMetadataContainerBuilder>, IExtensibleBuilder> - where TState : StateDefinition, new() -{ - - /// - /// Sets the name of the state definition to build - /// - /// The name of the state definition to build - /// The configured - new IStateBuilder WithName(string name); - - /// - /// Filters the state definition's input - /// - /// The workflow expression used to filter the state definition's input - /// The configured - IStateBuilder FilterInput(string expression); - - /// - /// Filters the state definition's output - /// - /// The workflow expression used to filter the state definition's output - /// The configured - IStateBuilder FilterOutput(string expression); - - /// - /// Configures the handling for the specified error - /// - /// The configured - IStateBuilder HandleError(Action builder); - - /// - /// Compensates the state definition with the specified state definition - /// - /// The name of the state definition to use for compensation - /// The configured - IStateBuilder CompensateWith(string name); - - /// - /// Compensates the state definition with the specified state definition - /// - /// A used to create the state definition to use for compensation - /// The configured - IStateBuilder CompensateWith(Func stateSetup); - - /// - /// Compensates the state definition with the specified state definition - /// - /// Tthe state definition to use for compensation - /// The configured - IStateBuilder CompensateWith(StateDefinition state); - -} diff --git a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IStateBuilderFactory.cs b/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IStateBuilderFactory.cs deleted file mode 100644 index 83da8b2..0000000 --- a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IStateBuilderFactory.cs +++ /dev/null @@ -1,116 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace ServerlessWorkflow.Sdk.Services.FluentBuilders; - -/// -/// Defines the fundamentals of a service used to create instances -/// -public interface IStateBuilderFactory -{ - - /// - /// Creates and configures a new - /// - /// A new - ICallbackStateBuilder Callback(); - - /// - /// Creates and configures a new - /// - /// The delay's duration - /// A new - IDelayStateBuilder Delay(TimeSpan duration); - - /// - /// Creates and configures a new - /// - /// A new - IDelayStateBuilder Delay(); - - /// - /// Creates and configures a new - /// - /// A new - IInjectStateBuilder Inject(); - - /// - /// Creates and configures a new - /// - /// The data to inject - /// A new - IInjectStateBuilder Inject(object data); - - /// - /// Creates and configures a new - /// - /// The type of the to build - /// A new - IExtensionStateBuilder Extension(string type); - - /// - /// Creates and configures a new - /// - /// The to execute - /// A new - IOperationStateBuilder Execute(ActionDefinition action); - - /// - /// Creates and configures a new - /// - /// An used to setup the to execute - /// A new - IOperationStateBuilder Execute(Action actionSetup); - - /// - /// Creates and configures a new - /// - /// the name of the to execute - /// An used to setup the to execute - /// A new - IOperationStateBuilder Execute(string name, Action actionSetup); - - /// - /// Creates and configures a new - /// - /// A new - IParallelStateBuilder ExecuteInParallel(); - - /// - /// Creates and configures a new - /// - /// An expression that defines the input collection - /// An expression that defines the iteration parameter - /// An expression that defines the output collection - /// A new - IForEachStateBuilder ForEach(string inputCollection, string iterationParameter, string outputCollection); - - /// - /// Creates and configures a new data-based - /// - /// A new - IDataSwitchStateBuilder Switch(); - - /// - /// Creates and configures a new -based - /// - /// A new - IEventSwitchStateBuilder SwitchEvents(); - - /// - /// Creates and configures a new - /// - /// A new - IEventStateBuilder Events(); - -} diff --git a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IStateOutcomeBuilder.cs b/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IStateOutcomeBuilder.cs deleted file mode 100644 index 5935a74..0000000 --- a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IStateOutcomeBuilder.cs +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace ServerlessWorkflow.Sdk.Services.FluentBuilders; - -/// -/// Defines the fundamentals of a service used to build s -/// -public interface IStateOutcomeBuilder -{ - - /// - /// Transitions to the specified state definition - /// - /// The name of the state definition to transition to - /// A new used to configure the state definition to transition to - void TransitionTo(string stateName); - - /// - /// Transitions to the specified state definition - /// - /// An used to setup the state definition to transition to - /// A new used to configure the state definition to transition to - void TransitionTo(Func stateSetup); - - /// - /// Configure the state definition to end the workflow - /// - /// The configured - void End(); - - /// - /// Builds the - /// - /// A new - StateOutcomeDefinition Build(); - -} diff --git a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/ISubflowActionBuilder.cs b/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/ISubflowActionBuilder.cs deleted file mode 100644 index 50d237a..0000000 --- a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/ISubflowActionBuilder.cs +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace ServerlessWorkflow.Sdk.Services.FluentBuilders; - -/// -/// Defines the fundamentals of a service used to build s of type -/// -public interface ISubflowActionBuilder - : IActionBuilder, IExtensibleBuilder -{ - - /// - /// Configures the to run the latest version of the specified workflow definition - /// - /// The configured - ISubflowActionBuilder LatestVersion(); - - /// - /// Configures the to run the workflow definition with the specified version - /// - /// The version of the workflow definition to run - /// The configured - ISubflowActionBuilder Version(string version); - - /// - /// Configures the to run the referenced workflow definition synchronously, which is the default. - /// - /// The configured - ISubflowActionBuilder Synchronously(); - - /// - /// Configures the to run the referenced workflow definition asynchronously - /// - /// The configured - ISubflowActionBuilder Asynchronously(); - -} diff --git a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/ISubflowRunnerBuilder.cs b/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/ISubflowRunnerBuilder.cs deleted file mode 100644 index 2936426..0000000 --- a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/ISubflowRunnerBuilder.cs +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace ServerlessWorkflow.Sdk.Services.FluentBuilders; - -/// -/// Defines the fundamentals of a service used to build workflow runners -/// -public interface ISubflowRunnerBuilder -{ - - /// - /// Runs the specified workflow - /// - /// The workflow to run - void RunSubflow(string workflowId); - -} diff --git a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/ISwitchStateBuilder.cs b/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/ISwitchStateBuilder.cs deleted file mode 100644 index 03eba02..0000000 --- a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/ISwitchStateBuilder.cs +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace ServerlessWorkflow.Sdk.Services.FluentBuilders; - -/// -/// Defines the fundamentals of a service used to build s -/// -public interface ISwitchStateBuilder - : IStateBuilder -{ - - /// - /// Switches on the 's data - /// - /// The configured - IDataSwitchStateBuilder SwitchData(); - - /// - /// Switches on consumed s - /// - /// The configured - IEventSwitchStateBuilder SwitchEvents(); - - /// - /// Configures the 's default case - /// - /// The name of the default case - /// An action used to configure the outcome of the default case - /// The configured - ISwitchStateBuilder WithDefaultCase(string name, Action outcomeSetup); - -} diff --git a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IWorkflowBuilder.cs b/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IWorkflowBuilder.cs deleted file mode 100644 index 0232397..0000000 --- a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IWorkflowBuilder.cs +++ /dev/null @@ -1,303 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace ServerlessWorkflow.Sdk.Services.FluentBuilders; - -/// -/// Defines the fundamentals of a service used to build workflow definitions -/// -public interface IWorkflowBuilder - : IMetadataContainerBuilder -{ - - /// - /// Sets the id of the workflow definition to create - /// - /// The id of the workflow definition to create - /// The configured - IWorkflowBuilder WithId(string key); - - /// - /// Sets the unique key of the workflow definition to create - /// - /// The unique key of the workflow definition to create - /// The configured - IWorkflowBuilder WithKey(string key); - - /// - /// Sets the name of the workflow definition to create - /// - /// The name of the workflow definition to create - /// The configured - IWorkflowBuilder WithName(string name); - - /// - /// Sets the description of the workflow definition to create - /// - /// The description of the workflow definition to create - /// The configured - IWorkflowBuilder WithDescription(string description); - - /// - /// Sets the version of the workflow definition to create - /// - /// The description of the workflow definition to create - /// The configured - IWorkflowBuilder WithVersion(string version); - - /// - /// Sets the Serverless Workflow specification version. Defaults to latest - /// - /// The Serverless Workflow specification version - /// The configured - IWorkflowBuilder UseSpecVersion(string specVersion); - - /// - /// Sets the workflow definition's data input uri - /// - /// The uri to the data workflow definition's data input - /// The configured - IWorkflowBuilder WithDataInputSchema(Uri uri); - - /// - /// Sets the workflow definition data input - /// - /// The workflow definition's - /// The configured - IWorkflowBuilder WithDataInputSchema(JsonSchema schema); - - /// - /// Annotates the workflow definition to build - /// - /// The annotation to append to the workflow definition to build - /// The configured - IWorkflowBuilder WithAnnotation(string annotation); - - /// - /// Configures the expression language used by the workflow definition to build - /// - /// The expression language to use - /// The configured - IWorkflowBuilder UseExpressionLanguage(string language); - - /// - /// Configures the workflow definition to use the 'jq' expression language - /// - /// The configured - IWorkflowBuilder UseJq(); - - /// - /// Configures the workflow definition to use the specified extension - /// - /// The id of the workflow extension to use - /// The uri that references the extension resource - /// The configure - IWorkflowBuilder UseExtension(string id, Uri resourceUri); - - /// - /// Adds the workflow definition authentication definitions defined in the specified file - /// - /// The uri of the file that defines the authentication definitions - /// The configured - IWorkflowBuilder ImportAuthenticationDefinitionsFrom(Uri uri); - - /// - /// Uses the specified workflow definition's authentication definitions - /// - /// An array that contains the workflow definition's authentication definitions - /// The configured - IWorkflowBuilder UseAuthenticationDefinitions(params AuthenticationDefinition[] authenticationDefinitions); - - /// - /// Adds the specified authentication definition to the workflow definition - /// - /// The authentication definition to add - /// The configured - IWorkflowBuilder AddAuthentication(AuthenticationDefinition authenticationDefinition); - - /// - /// Adds a new authentication definition with scheme to the workflow definition - /// - /// The name of the authentication definition to add - /// An used to configure the service used to build authentication definition to add - /// The configured - IWorkflowBuilder AddBasicAuthentication(string name, Action configurationAction); - - /// - /// Adds a new authentication definition with scheme to the workflow definition - /// - /// The name of the authentication definition to add - /// An used to configure the service used to build authentication definition to add - /// The configured - IWorkflowBuilder AddBearerAuthentication(string name, Action configurationAction); - - /// - /// Adds a new authentication definition with scheme to the workflow definition - /// - /// The name of the authentication definition to add - /// An used to configure the service used to build authentication definition to add - /// The configured - IWorkflowBuilder AddOAuth2Authentication(string name, Action configurationAction); - - /// - /// Adds the workflow definition constants defined in the specified file - /// - /// The uri of the file that defines the constants - /// The configured - IWorkflowBuilder ImportConstantsFrom(Uri uri); - - /// - /// Uses the specified workflow definition's constants - /// - /// An object that represents the workflow definition's constants - /// The configured - IWorkflowBuilder UseConstants(object constants); - - /// - /// Adds the specified constants to the workflow definition - /// - /// The name of the constant to add - /// The value of the constant to add - /// The configured - IWorkflowBuilder AddConstant(string name, object value); - - /// - /// Uses the specified workflow definition secrets - /// - /// An containing the secrets to use - /// The configured - IWorkflowBuilder UseSecrets(IEnumerable secrets); - - /// - /// Adds the specified secret to the workflow definition - /// - /// The secret to add - /// The configured - IWorkflowBuilder AddSecret(string secret); - - /// - /// Configures the workflow definition's - /// - /// An used to setup the workflow definition's - /// The configured - IWorkflowBuilder WithExecutionTimeout(Action timeoutSetup); - - /// - /// Configures the workflow definition to not terminate its execution when there are no active execution paths - /// - /// A boolean indicating whether or not to keep the workflow definition active - /// The configured - IWorkflowBuilder KeepActive(bool keepActive = true); - - /// - /// Sets and configures the startup state definition - /// - /// An used to setup the startup state definition - /// A new used to configure the workflow definition's state definitions - IPipelineBuilder StartsWith(Func stateSetup); - - /// - /// Sets and configures the startup state definition - /// - /// The name of the startup state definition - /// An used to setup the startup state definition - /// A new used to configure the workflow definition's state definitions - IPipelineBuilder StartsWith(string name, Func stateSetup); - - /// - /// Sets and configures the startup state definition - /// - /// An used to setup the startup state definition - /// An used to setup the workflow definition's schedule - /// A new used to configure the workflow definition's state definitions - IPipelineBuilder StartsWith(Func stateSetup, Action scheduleSetup); - - /// - /// Sets and configures the startup state definition - /// - /// The name of the startup state definition - /// An used to setup the startup state definition - /// An used to setup the workflow definition's schedule - /// A new used to configure the workflow definition's state definitions - IPipelineBuilder StartsWith(string name, Func stateSetup, Action scheduleSetup); - - /// - /// Adds the s defined in the specified file - /// - /// The uri of the file that defines the s - /// The configured - IWorkflowBuilder ImportEventsFrom(Uri uri); - - /// - /// Adds the specified to the workflow definition to create - /// - /// The to add - /// The configured - IWorkflowBuilder AddEvent(EventDefinition e); - - /// - /// Adds the specified to the workflow definition to create - /// - /// The used to setup the to add - /// The configured - IWorkflowBuilder AddEvent(Action eventSetup); - - /// - /// Adds the s defined in the specified file - /// - /// The uri of the file that defines the s - /// The configured - IWorkflowBuilder ImportFunctionsFrom(Uri uri); - - /// - /// Adds the specified to the workflow definition to create - /// - /// The used to setup the to add - /// The configured - IWorkflowBuilder AddFunction(Action functionSetup); - - /// - /// Adds the specified to the workflow definition to create - /// - /// The to add - /// The configured - IWorkflowBuilder AddFunction(FunctionDefinition function); - - /// - /// Adds the s defined in the specified file - /// - /// The uri of the file that defines the s - /// The configured - IWorkflowBuilder ImportRetryStrategiesFrom(Uri uri); - - /// - /// Adds the specified to the workflow definition to create - /// - /// The used to setup the to add - /// The configured - IWorkflowBuilder AddRetryStrategy(RetryDefinition strategy); - - /// - /// Adds the specified to the workflow definition to create - /// - /// The used to setup the to add - /// The configured - IWorkflowBuilder AddRetryStrategy(Action retryStrategySetup); - - /// - /// Builds the workflow definition - /// - /// A new workflow definition - WorkflowDefinition Build(); - -} diff --git a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IWorkflowExecutionTimeoutBuilder.cs b/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IWorkflowExecutionTimeoutBuilder.cs deleted file mode 100644 index de2dac4..0000000 --- a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/Interfaces/IWorkflowExecutionTimeoutBuilder.cs +++ /dev/null @@ -1,63 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace ServerlessWorkflow.Sdk.Services.FluentBuilders; - -/// -/// Defines the fundamentals of a service used to build s -/// -public interface IWorkflowExecutionTimeoutBuilder -{ - - /// - /// Configures the workflow definition's execution to time out after the specified duration - /// - /// The duration after which to time out the workflow definition's execution - /// The configured - IWorkflowExecutionTimeoutBuilder After(TimeSpan duration); - - /// - /// Configures the workflow definition to interrupt its execution on timeout - /// - /// A boolean indicating whether or not interrupt the workflow definition's execution - /// The configured - IWorkflowExecutionTimeoutBuilder InterruptExecution(bool interrupts = true); - - /// - /// Configures the workflow definition to run the specified state definition before terminating its execution - /// - /// The reference name of the state definition to run before termination - /// The configured - IWorkflowExecutionTimeoutBuilder Run(string state); - - /// - /// Configures the workflow definition to run the specified state definition before terminating its execution - /// - /// The used to build the state definition to run before termination - /// The configured - IWorkflowExecutionTimeoutBuilder Run(Func stateSetup); - - /// - /// Configures the workflow definition to run the specified state definition before terminating its execution - /// - /// The state definition to run before termination - /// The configured - IWorkflowExecutionTimeoutBuilder Run(StateDefinition state); - - /// - /// Builds the - /// - /// A new - WorkflowExecutionTimeoutDefinition Build(); - -} diff --git a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/MetadataContainerBuilder.cs b/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/MetadataContainerBuilder.cs deleted file mode 100644 index 0f824ce..0000000 --- a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/MetadataContainerBuilder.cs +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace ServerlessWorkflow.Sdk.Services.FluentBuilders; - -/// -/// Represents the base class for all -/// -/// The type of the -public abstract class MetadataContainerBuilder - : IMetadataContainerBuilder - where TContainer : class, IMetadataContainerBuilder -{ - - /// - public virtual DynamicMapping? Metadata { get; protected set; } - - /// - public virtual TContainer WithMetadata(string key, object value) - { - if (string.IsNullOrWhiteSpace(key)) throw new ArgumentNullException(nameof(key)); - this.Metadata ??= new(); - this.Metadata[key] = value; - return (TContainer)(object)this; - } - - /// - public virtual TContainer WithMetadata(IDictionary metadata) - { - if(metadata == null) throw new ArgumentNullException(nameof(metadata)); - this.Metadata = new(metadata); - return (TContainer)(object)this; - } - -} diff --git a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/OAuth2AuthenticationBuilder.cs b/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/OAuth2AuthenticationBuilder.cs deleted file mode 100644 index 7768ddc..0000000 --- a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/OAuth2AuthenticationBuilder.cs +++ /dev/null @@ -1,113 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace ServerlessWorkflow.Sdk.Services.FluentBuilders; - -/// -/// Represents the default implementation of the -/// -public class OAuth2AuthenticationBuilder - : AuthenticationDefinitionBuilder, IOAuth2AuthenticationBuilder -{ - - /// - /// Initializes a new - /// - public OAuth2AuthenticationBuilder() : base(new AuthenticationDefinition() { Scheme = AuthenticationScheme.OAuth2, Properties = new OAuth2AuthenticationProperties() }) { } - - /// - /// Gets the of the authentication definition to build - /// - protected OAuth2AuthenticationProperties Properties => (OAuth2AuthenticationProperties)this.AuthenticationDefinition.Properties!; - - /// - public virtual IOAuth2AuthenticationBuilder UseAudiences(params string[] audiences) - { - if (audiences == null) throw new ArgumentNullException(nameof(audiences)); - this.Properties.Audience = string.Join(" ", audiences); - return this; - } - - /// - public virtual IOAuth2AuthenticationBuilder UseGrantType(string grantType) - { - this.Properties.GrantType = grantType; - return this; - } - - /// - public virtual IOAuth2AuthenticationBuilder UseScopes(params string[] scopes) - { - if (scopes == null) throw new ArgumentNullException(nameof(scopes)); - this.Properties.Audience = string.Join(" ", scopes); - return this; - } - - /// - public virtual IOAuth2AuthenticationBuilder WithAuthority(Uri authority) - { - this.Properties.Authority = authority ?? throw new ArgumentNullException(nameof(authority)); - return this; - } - - /// - public virtual IOAuth2AuthenticationBuilder WithClientId(string clientId) - { - if (string.IsNullOrWhiteSpace(clientId)) throw new ArgumentNullException(nameof(clientId)); - this.Properties.ClientId = clientId; - return this; - } - - /// - public virtual IOAuth2AuthenticationBuilder WithClientSecret(string clientSecret) - { - if (string.IsNullOrWhiteSpace(clientSecret)) throw new ArgumentNullException(nameof(clientSecret)); - this.Properties.ClientSecret = clientSecret; - return this; - } - - /// - public virtual IOAuth2AuthenticationBuilder WithUserName(string username) - { - if (string.IsNullOrWhiteSpace(username)) throw new ArgumentNullException(nameof(username)); - this.Properties.Username = username; - return this; - } - - /// - public virtual IOAuth2AuthenticationBuilder WithPassword(string password) - { - if (string.IsNullOrWhiteSpace(password)) throw new ArgumentNullException(nameof(password)); - this.Properties.Password = password; - return this; - } - - /// - public virtual IOAuth2AuthenticationBuilder WithSubjectToken(string tokenType, string token) - { - if (string.IsNullOrWhiteSpace(token)) throw new ArgumentNullException(nameof(token)); - this.Properties.SubjectTokenType = tokenType; - this.Properties.SubjectToken = token; - return this; - } - - /// - public virtual IOAuth2AuthenticationBuilder WithActorToken(string tokenType, string token) - { - if (string.IsNullOrWhiteSpace(token)) throw new ArgumentNullException(nameof(token)); - this.Properties.ActorTokenType = tokenType; - this.Properties.ActorToken = token; - return this; - } - -} diff --git a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/OperationStateBuilder.cs b/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/OperationStateBuilder.cs deleted file mode 100644 index 051b1d1..0000000 --- a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/OperationStateBuilder.cs +++ /dev/null @@ -1,80 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace ServerlessWorkflow.Sdk.Services.FluentBuilders; - -/// -/// Represents the default implementation of the interface -/// -public class OperationStateBuilder - : StateBuilder, IOperationStateBuilder -{ - - /// - /// Initializes a new - /// - /// The the belongs to - public OperationStateBuilder(IPipelineBuilder pipeline) - : base(pipeline) - { - } - - /// - public virtual IOperationStateBuilder Execute(ActionDefinition action) - { - if (action == null) - throw new ArgumentNullException(nameof(action)); - this.State.Actions.Add(action); - return this; - } - - /// - public virtual IOperationStateBuilder Execute(Action actionSetup) - { - if (actionSetup == null) - throw new ArgumentNullException(nameof(actionSetup)); - IActionBuilder actionBuilder = new ActionBuilder(this.Pipeline); - actionSetup(actionBuilder); - this.State.Actions.Add(actionBuilder.Build()); - return this; - } - - /// - public virtual IOperationStateBuilder Execute(string name, Action actionSetup) - { - if (string.IsNullOrWhiteSpace(name)) - throw new ArgumentNullException(nameof(name)); - if (actionSetup == null) - throw new ArgumentNullException(nameof(actionSetup)); - return this.Execute(a => - { - actionSetup(a); - a.WithName(name); - }); - } - - /// - public virtual IOperationStateBuilder Concurrently() - { - this.State.ActionMode = ActionExecutionMode.Parallel; - return this; - } - - /// - public virtual IOperationStateBuilder Sequentially() - { - this.State.ActionMode = ActionExecutionMode.Sequential; - return this; - } - -} diff --git a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/ParallelStateBuilder.cs b/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/ParallelStateBuilder.cs deleted file mode 100644 index effe427..0000000 --- a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/ParallelStateBuilder.cs +++ /dev/null @@ -1,68 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace ServerlessWorkflow.Sdk.Services.FluentBuilders; - -/// -/// Represents the default implementation of the interface -/// -public class ParallelStateBuilder - : StateBuilder, IParallelStateBuilder -{ - - /// - /// Initializes a new - /// - /// The the belongs to - public ParallelStateBuilder(IPipelineBuilder pipeline) - : base(pipeline) - { - - } - - /// - public virtual IParallelStateBuilder Branch(Action branchSetup) - { - var branch = new BranchBuilder(this.Pipeline); - branchSetup(branch); - this.State.Branches.Add(branch.Build()); - return this; - } - - /// - public virtual IParallelStateBuilder Branch(string name, Action branchSetup) - { - if (string.IsNullOrWhiteSpace(name)) throw new ArgumentNullException(nameof(name)); - if (branchSetup == null) throw new ArgumentNullException(nameof(branchSetup)); - var branch = new BranchBuilder(this.Pipeline).WithName(name); - branchSetup(branch); - this.State.Branches.Add(branch.Build()); - return this; - } - - /// - public virtual IParallelStateBuilder WaitFor(uint amount) - { - this.State.CompletionType = ParallelCompletionType.AtLeastN; - this.State.N = amount; - return this; - } - - /// - public virtual IParallelStateBuilder WaitForAll() - { - this.State.CompletionType = ParallelCompletionType.AllOf; - return this; - } - -} diff --git a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/PipelineBuilder.cs b/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/PipelineBuilder.cs deleted file mode 100644 index b58bec4..0000000 --- a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/PipelineBuilder.cs +++ /dev/null @@ -1,143 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace ServerlessWorkflow.Sdk.Services.FluentBuilders; - -/// -/// Represents the default implementation of the interface -/// -public class PipelineBuilder - : IPipelineBuilder -{ - - /// - /// Initializes a new - /// - /// The the belongs to - public PipelineBuilder(IWorkflowBuilder workflow) - { - this.Workflow = workflow; - } - - /// - /// Gets the the belongs to - /// - protected IWorkflowBuilder Workflow { get; } - - /// - /// Gets alist containing the state definitions the pipeline is made out of - /// - protected List States { get; } = new List(); - - /// - /// Gets the current state definition in the main pipeline of the workflow definition - /// - protected StateDefinition CurrentState { get; private set; } = null!; - - /// - public virtual EventDefinition AddEvent(Action eventSetup) - { - if (eventSetup == null) throw new ArgumentNullException(nameof(eventSetup)); - var builder = new EventBuilder(); - eventSetup(builder); - return this.AddEvent(builder.Build()); - } - - /// - public virtual EventDefinition AddEvent(EventDefinition e) - { - if (e == null) throw new ArgumentNullException(nameof(e)); - this.Workflow.AddEvent(e); - return e; - } - - /// - public virtual FunctionDefinition AddFunction(Action functionSetup) - { - if (functionSetup == null)throw new ArgumentNullException(nameof(functionSetup)); - var builder = new FunctionBuilder(this.Workflow); - functionSetup(builder); - return this.AddFunction(builder.Build()); - } - - /// - public virtual FunctionDefinition AddFunction(FunctionDefinition function) - { - if (function == null)throw new ArgumentNullException(nameof(function)); - this.Workflow.AddFunction(function); - return function; - } - - /// - public virtual StateDefinition AddState(StateDefinition state) - { - if (state == null)throw new ArgumentNullException(nameof(state)); - this.States.Add(state); - return state; - } - - /// - public virtual StateDefinition AddState(Func stateSetup) - { - if (stateSetup == null)throw new ArgumentNullException(nameof(stateSetup)); - var builder = stateSetup(new StateBuilderFactory(this)); - var state = this.AddState(builder.Build()); - this.CurrentState ??= state; - return state; - } - - /// - public virtual IPipelineBuilder Then(Func stateSetup) - { - if (stateSetup == null) - throw new ArgumentNullException(nameof(stateSetup)); - var nextState = this.AddState(stateSetup); - this.CurrentState.TransitionToStateName = nextState.Name; - this.CurrentState = nextState; - return this; - } - - /// - public virtual IPipelineBuilder Then(string name, Func stateSetup) - { - if (string.IsNullOrWhiteSpace(name))throw new ArgumentNullException(nameof(name)); - if (stateSetup == null) throw new ArgumentNullException(nameof(stateSetup)); - return this.Then(flow => stateSetup(flow).WithName(name)); - } - - /// - public virtual IWorkflowBuilder EndsWith(Func stateSetup) - { - var state = this.AddState(stateSetup); - state.End = new EndDefinition(); - return this.Workflow; - } - - /// - public virtual IWorkflowBuilder EndsWith(string name, Func stateSetup) - { - if (string.IsNullOrWhiteSpace(name))throw new ArgumentNullException(nameof(name)); - return this.EndsWith(flow => stateSetup(flow).WithName(name)); - } - - /// - public virtual IWorkflowBuilder End() - { - this.CurrentState.IsEnd = true; - return this.Workflow; - } - - /// - public virtual IEnumerable Build() => this.States; - -} diff --git a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/RetryStrategyBuilder.cs b/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/RetryStrategyBuilder.cs deleted file mode 100644 index 6d6334f..0000000 --- a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/RetryStrategyBuilder.cs +++ /dev/null @@ -1,112 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace ServerlessWorkflow.Sdk.Services.FluentBuilders; - -/// -/// Represents the default implementation of the interface -/// -public class RetryStrategyBuilder - : IRetryStrategyBuilder -{ - - /// - /// Gets the to configure - /// - protected RetryDefinition Strategy { get; } = new RetryDefinition(); - - /// - public virtual IRetryStrategyBuilder WithName(string name) - { - if (string.IsNullOrWhiteSpace(name)) - throw new ArgumentNullException(nameof(name)); - this.Strategy.Name = name; - return this; - } - - /// - public virtual IRetryStrategyBuilder WithNoDelay() - { - this.Strategy.Delay = null; - return this; - } - - /// - public virtual IRetryStrategyBuilder WithDelayOf(TimeSpan duration) - { - this.Strategy.Delay = duration; - return this; - } - - /// - public virtual IRetryStrategyBuilder WithDelayIncrement(TimeSpan duration) - { - this.Strategy.Increment = duration; - return this; - } - - /// - public virtual IRetryStrategyBuilder WithDelayMultiplier(float multiplier) - { - this.Strategy.Multiplier = multiplier; - return this; - } - - /// - public virtual IRetryStrategyBuilder WithMaxDelay(TimeSpan duration) - { - this.Strategy.MaxDelay = duration; - return this; - } - - /// - public virtual IRetryStrategyBuilder MaxAttempts(uint maxAttempts) - { - this.Strategy.MaxAttempts = maxAttempts; - return this; - } - - /// - public virtual IRetryStrategyBuilder WithJitterDuration(TimeSpan duration) - { - this.Strategy.JitterDuration = duration; - return this; - } - - /// - public virtual IRetryStrategyBuilder WithJitterMultiplier(float multiplier) - { - this.Strategy.JitterMultiplier = multiplier; - return this; - } - - /// - public virtual IRetryStrategyBuilder WithExtensionProperty(string name, object value) - { - if (string.IsNullOrWhiteSpace(name)) throw new ArgumentNullException(nameof(name)); - this.Strategy.ExtensionData ??= new Dictionary(); - this.Strategy.ExtensionData[name] = value; - return this; - } - - /// - public virtual IRetryStrategyBuilder WithExtensionProperties(IDictionary properties) - { - this.Strategy.ExtensionData = properties ?? throw new ArgumentNullException(nameof(properties)); - return this; - } - - /// - public virtual RetryDefinition Build() => this.Strategy; - -} diff --git a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/ScheduleBuilder.cs b/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/ScheduleBuilder.cs deleted file mode 100644 index f322a40..0000000 --- a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/ScheduleBuilder.cs +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace ServerlessWorkflow.Sdk.Services.FluentBuilders; - -/// -/// Represents the default implementation of the interface -/// -public class ScheduleBuilder - : IScheduleBuilder -{ - - /// - /// Gets the to build - /// - protected ScheduleDefinition Schedule { get; } = new(); - - /// - public virtual IScheduleBuilder AtInterval(TimeSpan interval) - { - this.Schedule.Interval = interval; - this.Schedule.CronExpression = null; - this.Schedule.Cron = null; - return this; - } - - /// - public virtual IScheduleBuilder Every(string cronExpression, DateTime? validUntil = null) - { - if (string.IsNullOrWhiteSpace(cronExpression)) throw new ArgumentNullException(nameof(cronExpression)); - if (!Cron.TryParse(cronExpression, out _)) throw new ArgumentException($"The specified value '{cronExpression}' is not a valid CRON expression"); - if (validUntil.HasValue) this.Schedule.Cron = new CronDefinition() { Expression = cronExpression, ValidUntil = validUntil.Value }; - else this.Schedule.CronExpression = cronExpression; - this.Schedule.Interval = null; - return this; - } - - /// - public virtual IScheduleBuilder UseTimezone(string? timezone) - { - this.Schedule.Timezone = timezone; - return this; - } - - /// - public virtual ScheduleDefinition Build() => this.Schedule; - -} diff --git a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/SleepStateBuilder.cs b/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/SleepStateBuilder.cs deleted file mode 100644 index 5a73ee2..0000000 --- a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/SleepStateBuilder.cs +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace ServerlessWorkflow.Sdk.Services.FluentBuilders; - - -/// -/// Represents the default implementation of the interface -/// -public class SleepStateBuilder - : StateBuilder, IDelayStateBuilder -{ - - /// - /// Initializes a new - /// - /// The the belongs to - public SleepStateBuilder(IPipelineBuilder pipeline) - : base(pipeline) - { - - } - - /// - public virtual IDelayStateBuilder For(TimeSpan duration) - { - this.State.Duration = duration; - return this; - } - -} diff --git a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/StateBuilder.cs b/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/StateBuilder.cs deleted file mode 100644 index 7b2ae64..0000000 --- a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/StateBuilder.cs +++ /dev/null @@ -1,140 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace ServerlessWorkflow.Sdk.Services.FluentBuilders; - -/// -/// Represents the default implementation of the interface -/// -/// The type of state definition to build -public abstract class StateBuilder - : MetadataContainerBuilder>, IStateBuilder - where TState : StateDefinition, new() -{ - - /// - /// Initializes a new - /// - /// The the belongs to - protected StateBuilder(IPipelineBuilder pipeline) - { - this.Pipeline = pipeline; - } - - /// - /// Gets the the belongs to - /// - protected IPipelineBuilder Pipeline { get; } - - /// - /// Gets the state definition to configure - /// - protected TState State { get; set; } = new TState(); - - /// - public override DynamicMapping? Metadata - { - get - { - return this.State.Metadata; - } - protected set - { - this.State.Metadata = value; - } - } - - /// - public virtual IStateBuilder WithName(string name) - { - if (string.IsNullOrWhiteSpace(name)) throw new ArgumentNullException(nameof(name)); - this.State.Name = name; - return this; - } - - IStateBuilder IStateBuilder.WithName(string name) => this.WithName(name); - - /// - public virtual IStateBuilder WithExtensionProperty(string name, object value) - { - this.State.ExtensionData ??= new Dictionary(); - this.State.ExtensionData[name] = value; - return this; - } - - /// - public virtual IStateBuilder WithExtensionProperties(IDictionary properties) - { - this.State.ExtensionData = properties; - return this; - } - - /// - public virtual IStateBuilder FilterInput(string expression) - { - if (this.State.DataFilter == null) this.State.DataFilter = new(); - this.State.DataFilter.Input = expression; - return this; - } - - /// - public virtual IStateBuilder FilterOutput(string expression) - { - if (this.State.DataFilter == null) this.State.DataFilter = new(); - this.State.DataFilter.Output = expression; - return this; - } - - /// - public virtual IStateBuilder CompensateWith(string name) - { - if (string.IsNullOrWhiteSpace(name)) throw new ArgumentNullException(nameof(name)); - this.State.CompensatedBy = name; - return this; - } - - /// - public virtual IStateBuilder CompensateWith(Func stateSetup) - { - if (stateSetup == null) throw new ArgumentNullException(nameof(stateSetup)); - var compensatedBy = this.Pipeline.AddState(stateSetup); - compensatedBy.UsedForCompensation = true; - this.State.CompensatedBy = compensatedBy.Name; - return this; - } - - /// - public virtual IStateBuilder CompensateWith(StateDefinition state) - { - if (state == null) throw new ArgumentNullException(nameof(state)); - state.UsedForCompensation = true; - this.State.CompensatedBy = this.Pipeline.AddState(state).Name; - return this; - } - - /// - public virtual IStateBuilder HandleError(Action setupAction) - { - if (setupAction == null) throw new ArgumentNullException(nameof(setupAction)); - var builder = new ErrorHandlerBuilder(this.Pipeline); - setupAction(builder); - var errorHandler = builder.Build(); - if (this.State.Errors == null) this.State.Errors = new(); - this.State.Errors.Add(errorHandler); - return this; - } - - /// - public virtual StateDefinition Build() => this.State; - -} diff --git a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/StateBuilderFactory.cs b/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/StateBuilderFactory.cs deleted file mode 100644 index f0f3743..0000000 --- a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/StateBuilderFactory.cs +++ /dev/null @@ -1,149 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace ServerlessWorkflow.Sdk.Services.FluentBuilders; - -/// -/// Represents the default implementation of the interface -/// -public class StateBuilderFactory - : IStateBuilderFactory -{ - - /// - /// Initializes a new - /// - /// The the belongs to - public StateBuilderFactory(IPipelineBuilder pipeline) - { - this.Pipeline = pipeline; - } - - /// - /// Gets the the belongs to - /// - protected IPipelineBuilder Pipeline { get; } - - /// - public virtual ICallbackStateBuilder Callback() - { - return new CallbackStateBuilder(this.Pipeline); - } - - /// - public virtual IDelayStateBuilder Delay(TimeSpan duration) - { - return this.Delay().For(duration); - } - - /// - public virtual IDelayStateBuilder Delay() - { - return new SleepStateBuilder(this.Pipeline); - } - - /// - public virtual IEventStateBuilder Events() - { - return new EventStateBuilder(this.Pipeline); - } - - /// - public virtual IOperationStateBuilder Execute(ActionDefinition action) - { - if (action == null) - throw new ArgumentNullException(nameof(action)); - IOperationStateBuilder builder = new OperationStateBuilder(this.Pipeline); - builder.Execute(action); - return builder; - } - - /// - public virtual IOperationStateBuilder Execute(Action actionSetup) - { - if (actionSetup == null) - throw new ArgumentNullException(nameof(actionSetup)); - IOperationStateBuilder builder = new OperationStateBuilder(this.Pipeline); - builder.Execute(actionSetup); - return builder; - } - - /// - public virtual IOperationStateBuilder Execute(string name, Action actionSetup) - { - if (string.IsNullOrWhiteSpace(name)) - throw new ArgumentNullException(nameof(name)); - if (actionSetup == null) - throw new ArgumentNullException(nameof(actionSetup)); - return this.Execute(a => - { - actionSetup(a); - a.WithName(name); - }); - } - - /// - public virtual IParallelStateBuilder ExecuteInParallel() - { - return new ParallelStateBuilder(this.Pipeline); - } - - /// - public virtual IForEachStateBuilder ForEach(string inputCollection, string iterationParameter, string outputCollection) - { - if (string.IsNullOrWhiteSpace(inputCollection)) - throw new ArgumentNullException(nameof(inputCollection)); - if (string.IsNullOrWhiteSpace(iterationParameter)) - throw new ArgumentNullException(nameof(iterationParameter)); - if (string.IsNullOrWhiteSpace(outputCollection)) - throw new ArgumentNullException(nameof(outputCollection)); - return new ForEachStateBuilder(this.Pipeline) - .UseInputCollection(inputCollection) - .UseIterationParameter(iterationParameter) - .UseOutputCollection(outputCollection); - } - - /// - public virtual IInjectStateBuilder Inject() - { - return new InjectStateBuilder(this.Pipeline); - } - - /// - public virtual IInjectStateBuilder Inject(object data) - { - if (data == null) - throw new ArgumentNullException(nameof(data)); - return this.Inject().Data(data); - } - - /// - public virtual IDataSwitchStateBuilder Switch() - { - return new SwitchStateBuilder(this.Pipeline); - } - - /// - public virtual IEventSwitchStateBuilder SwitchEvents() - { - return new SwitchStateBuilder(this.Pipeline); - } - - /// - public virtual IExtensionStateBuilder Extension(string type) - { - if(string.IsNullOrWhiteSpace(type)) throw new ArgumentNullException(nameof(type)); - return new ExtensionStateBuilder(this.Pipeline, type); - } - -} diff --git a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/StateOutcomeBuilder.cs b/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/StateOutcomeBuilder.cs deleted file mode 100644 index 20d51bd..0000000 --- a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/StateOutcomeBuilder.cs +++ /dev/null @@ -1,72 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace ServerlessWorkflow.Sdk.Services.FluentBuilders; - -/// -/// Represents the default implementation of the interface -/// -public class StateOutcomeBuilder - : IStateOutcomeBuilder -{ - - /// - /// Initializes a new - /// - /// The the belongs to - public StateOutcomeBuilder(IPipelineBuilder pipeline) - { - this.Pipeline = pipeline; - } - - /// - /// Gets the the belongs to - /// - protected IPipelineBuilder Pipeline { get; } - - /// - /// Gets the to configure - /// - protected StateOutcomeDefinition Outcome { get; set; } = null!; - - /// - public virtual void TransitionTo(Func stateSetup) - { - if(stateSetup == null) throw new ArgumentNullException(nameof(stateSetup)); - //TODO: configure transition - var state = this.Pipeline.AddState(stateSetup); - this.Outcome = new TransitionDefinition() { NextState = state.Name }; - } - - /// - public virtual void TransitionTo(string stateName) - { - if (string.IsNullOrWhiteSpace(stateName)) throw new ArgumentNullException(nameof(stateName)); - //TODO: configure transition - this.Outcome = new TransitionDefinition() { NextState = stateName }; - } - - /// - public virtual void End() - { - //TODO: configure end - this.Outcome = new EndDefinition(); - } - - /// - public virtual StateOutcomeDefinition Build() - { - return this.Outcome; - } - -} diff --git a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/SwitchCaseBuilder.cs b/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/SwitchCaseBuilder.cs deleted file mode 100644 index 3df0c04..0000000 --- a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/SwitchCaseBuilder.cs +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace ServerlessWorkflow.Sdk.Services.FluentBuilders; - -/// -/// Represents the default implementation of the interface -/// -public abstract class SwitchCaseBuilder - : StateOutcomeBuilder, ISwitchCaseBuilder - where TBuilder : class, ISwitchCaseBuilder - where TCase : SwitchCaseDefinition, new() -{ - - /// - /// Initializes a new - /// - /// The the belongs to - public SwitchCaseBuilder(IPipelineBuilder pipeline) : base(pipeline) { } - - /// - /// Gets the to configure - /// - protected TCase Case { get; } = new TCase(); - - /// - public virtual TBuilder WithName(string name) - { - if (string.IsNullOrWhiteSpace(name)) throw new ArgumentNullException(nameof(name)); - this.Case.Name = name; - return (TBuilder)(object)this; - } - -} diff --git a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/SwitchStateBuilder.cs b/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/SwitchStateBuilder.cs deleted file mode 100644 index b2e6847..0000000 --- a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/SwitchStateBuilder.cs +++ /dev/null @@ -1,113 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace ServerlessWorkflow.Sdk.Services.FluentBuilders; - -/// -/// Represents the default implementation of the interface -/// -public class SwitchStateBuilder - : StateBuilder, IDataSwitchStateBuilder, IEventSwitchStateBuilder -{ - - /// - /// Initializes a new - /// - /// The the belongs to - public SwitchStateBuilder(IPipelineBuilder pipeline) : base(pipeline) { } - - /// - public virtual IDataSwitchStateBuilder SwitchData() => this; - - /// - public virtual IEventSwitchStateBuilder SwitchEvents() => this; - - /// - public ISwitchStateBuilder WithDefaultCase(string name, Action outcomeSetup) - { - if (string.IsNullOrWhiteSpace(name)) throw new ArgumentNullException(nameof(name)); - if (outcomeSetup == null) throw new ArgumentNullException(nameof(outcomeSetup)); - this.State.DefaultCondition = new() { Name = name }; - var outcomeBuilder = new StateOutcomeBuilder(this.Pipeline); - outcomeSetup(outcomeBuilder); - var outcome = outcomeBuilder.Build(); - switch (outcome) - { - case EndDefinition end: - this.State.DefaultCondition.End = end; - break; - case TransitionDefinition transition: - this.State.DefaultCondition.Transition = transition; - break; - default: - throw new NotSupportedException($"The specified outcome type '{outcome.GetType().Name}' is not supported"); - } - return this; - } - - IDataSwitchStateBuilder IDataSwitchStateBuilder.WithCase(Action caseSetup) - { - if (caseSetup == null) throw new ArgumentException(nameof(caseSetup)); - var builder = new DataSwitchCaseBuilder(this.Pipeline); - caseSetup(builder); - this.State.DataConditions = new() - { - builder.Build() - }; - return this; - } - - /// - IDataSwitchStateBuilder IDataSwitchStateBuilder.WithCase(string name, Action caseSetup) - { - if (string.IsNullOrWhiteSpace(name)) throw new ArgumentNullException(nameof(name)); - if (caseSetup == null) throw new ArgumentException(nameof(caseSetup)); - var builder = new DataSwitchCaseBuilder(this.Pipeline).WithName(name); - caseSetup(builder); - this.State.DataConditions ??= new(); - this.State.DataConditions.Add(builder.Build()); - return this; - } - - /// - IEventSwitchStateBuilder IEventSwitchStateBuilder.WithCase(Action caseSetup) - { - if (caseSetup == null) throw new ArgumentException(nameof(caseSetup)); - var builder = new EventSwitchCaseBuilder(this.Pipeline); - caseSetup(builder); - this.State.EventConditions ??= new(); - this.State.EventConditions.Add(builder.Build()); - return this; - } - - /// - IEventSwitchStateBuilder IEventSwitchStateBuilder.WithCase(string name, Action caseSetup) - { - if (string.IsNullOrWhiteSpace(name)) throw new ArgumentNullException(nameof(name)); - if (caseSetup == null) throw new ArgumentException(nameof(caseSetup)); - var builder = new EventSwitchCaseBuilder(this.Pipeline).WithName(name); - caseSetup(builder); - this.State.EventConditions ??= new(); - this.State.EventConditions.Add(builder.Build()); - return this; - } - - /// - IEventSwitchStateBuilder IEventSwitchStateBuilder.TimeoutAfter(TimeSpan duration) - { - this.State.EventTimeout = duration; - return this; - } - - -} diff --git a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/WorkflowBuilder.cs b/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/WorkflowBuilder.cs deleted file mode 100644 index 3f2bd2c..0000000 --- a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/WorkflowBuilder.cs +++ /dev/null @@ -1,386 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace ServerlessWorkflow.Sdk.Services.FluentBuilders; - -/// -/// Represents the default implementation of the interface -/// -public class WorkflowBuilder - : MetadataContainerBuilder, IWorkflowBuilder -{ - - /// - /// Initializes a new - /// - public WorkflowBuilder() - { - this.Pipeline = new PipelineBuilder(this); - } - - /// - /// Gets the workflow definition to configure - /// - protected WorkflowDefinition Workflow { get; } = new WorkflowDefinition(); - - /// - /// Gets the service used to build the workflow definition's chart - /// - protected IPipelineBuilder Pipeline { get; } - - /// - public override DynamicMapping? Metadata - { - get - { - return this.Workflow.Metadata; - } - protected set - { - this.Workflow.Metadata = value; - } - } - - /// - public virtual IWorkflowBuilder WithKey(string key) - { - if (string.IsNullOrWhiteSpace(key)) throw new ArgumentNullException(nameof(key)); - this.Workflow.Key = key; - return this; - } - - /// - public virtual IWorkflowBuilder WithId(string id) - { - if (string.IsNullOrWhiteSpace(id)) throw new ArgumentNullException(nameof(id)); - this.Workflow.Id = id; - return this; - } - - /// - public virtual IWorkflowBuilder WithName(string name) - { - if (string.IsNullOrWhiteSpace(name)) throw new ArgumentNullException(nameof(name)); - this.Workflow.Name = name; - return this; - } - - /// - public virtual IWorkflowBuilder WithDescription(string description) - { - this.Workflow.Description = description; - return this; - } - - /// - public virtual IWorkflowBuilder WithVersion(string version) - { - if (string.IsNullOrWhiteSpace(version)) throw new ArgumentNullException(nameof(version)); - this.Workflow.Version = version; - return this; - } - - /// - public virtual IWorkflowBuilder UseSpecVersion(string specVersion) - { - if (string.IsNullOrWhiteSpace(specVersion)) - throw new ArgumentNullException(nameof(specVersion)); - this.Workflow.SpecVersion = specVersion; - return this; - } - - /// - public virtual IWorkflowBuilder WithDataInputSchema(Uri uri) - { - this.Workflow.DataInputSchemaUri = uri ?? throw new ArgumentNullException(nameof(uri)); - return this; - } - - /// - public virtual IWorkflowBuilder WithDataInputSchema(JsonSchema schema) - { - this.Workflow.DataInputSchema = new DataInputSchemaDefinition() { Schema = schema } ?? throw new ArgumentNullException(nameof(schema)); - return this; - } - - /// - public virtual IWorkflowBuilder WithAnnotation(string annotation) - { - if (string.IsNullOrWhiteSpace(annotation)) throw new ArgumentNullException(nameof(annotation)); - if (this.Workflow.Annotations == null) this.Workflow.Annotations = new(); - this.Workflow.Annotations.Add(annotation); - return this; - } - - /// - public virtual IWorkflowBuilder UseExpressionLanguage(string language) - { - if (string.IsNullOrWhiteSpace(language)) throw new ArgumentNullException(nameof(language)); - this.Workflow.ExpressionLanguage = language; - return this; - } - - /// - public virtual IWorkflowBuilder UseJq() => this.UseExpressionLanguage("jq"); - - /// - public virtual IWorkflowBuilder UseExtension(string id, Uri resourceUri) - { - if (string.IsNullOrWhiteSpace(id)) throw new ArgumentNullException(nameof(id)); - if (resourceUri == null) throw new ArgumentNullException(nameof(resourceUri)); - this.Workflow.Extensions ??= new(); - if (this.Workflow.Extensions.Any(e => e.ExtensionId == id)) throw new Exception($"An extension with the specified id '{id}' has already been registered"); - this.Workflow.Extensions.Add(new(id, resourceUri)); - return this; - } - - /// - public virtual IWorkflowBuilder WithExecutionTimeout(Action timeoutSetup) - { - var builder = new WorkflowExecutionTimeoutBuilder(this.Pipeline); - timeoutSetup(builder); - //todo: this.Workflow.ExecutionTimeout = builder.Build(); - return this; - } - - /// - public virtual IWorkflowBuilder KeepActive(bool keepActive = true) - { - this.Workflow.KeepActive = keepActive; - return this; - } - - /// - public virtual IWorkflowBuilder ImportConstantsFrom(Uri uri) - { - this.Workflow.ConstantsUri = uri ?? throw new ArgumentNullException(nameof(uri)); - return this; - } - - /// - public virtual IWorkflowBuilder UseConstants(object constants) - { - if (constants == null) throw new ArgumentNullException(nameof(constants)); - this.Workflow.Constants = new(constants is IDictionary dico ? dico.ToDictionary(kvp => kvp.Key, kvp => kvp.Value) : Serialization.Serializer.Json.Deserialize>(Serialization.Serializer.Json.Serialize(constants))!); - return this; - } - - /// - public virtual IWorkflowBuilder AddConstant(string name, object value) - { - if (string.IsNullOrWhiteSpace(name)) throw new ArgumentNullException(nameof(name)); - if (this.Workflow.Constants == null) this.Workflow.Constants = new(); - this.Workflow.Constants[name] = value ?? throw new ArgumentNullException(nameof(value)); - return this; - } - - /// - public virtual IWorkflowBuilder UseSecrets(IEnumerable secrets) - { - this.Workflow.Secrets = secrets?.ToList()!; - return this; - } - - /// - public virtual IWorkflowBuilder AddSecret(string secret) - { - if (this.Workflow.Secrets == null) this.Workflow.Secrets = new(); - this.Workflow.Secrets.Add(secret); - return this; - } - - /// - public virtual IWorkflowBuilder ImportEventsFrom(Uri uri) - { - this.Workflow.EventsUri = uri ?? throw new ArgumentNullException(nameof(uri)); - return this; - } - - /// - public virtual IWorkflowBuilder AddEvent(EventDefinition e) - { - if (e == null) throw new ArgumentNullException(nameof(e)); - if (this.Workflow.Events == null) this.Workflow.Events = new(); - if (this.Workflow.Events.Any(ed => ed.Name == e.Name)) throw new ArgumentException($"The workflow already defines an event with the specified name '{e.Name}'", nameof(e)); - this.Workflow.Events.Add(e); - return this; - } - - /// - public virtual IWorkflowBuilder AddEvent(Action eventSetup) - { - if (eventSetup == null) throw new ArgumentNullException(nameof(eventSetup)); - var builder = new EventBuilder(); - eventSetup(builder); - return this.AddEvent(builder.Build()); - } - - /// - public virtual IWorkflowBuilder ImportFunctionsFrom(Uri uri) - { - this.Workflow.FunctionsUri = uri ?? throw new ArgumentNullException(nameof(uri)); - return this; - } - - /// - public virtual IWorkflowBuilder AddFunction(FunctionDefinition function) - { - if (function == null) throw new ArgumentNullException(nameof(function)); - if (this.Workflow.Functions == null) this.Workflow.Functions = new(); - if (this.Workflow.Functions.Any(fd => fd.Name == function.Name)) throw new ArgumentException($"The workflow already defines a function with the specified name '{function.Name}'", nameof(function)); - this.Workflow.Functions.Add(function); - return this; - } - - /// - public virtual IWorkflowBuilder AddFunction(Action functionSetup) - { - if (functionSetup == null) throw new ArgumentNullException(nameof(functionSetup)); - var builder = new FunctionBuilder(this); - functionSetup(builder); - return this.AddFunction(builder.Build()); - } - - /// - public virtual IWorkflowBuilder ImportRetryStrategiesFrom(Uri uri) - { - this.Workflow.RetriesUri = uri ?? throw new ArgumentNullException(nameof(uri)); - return this; - } - - /// - public virtual IWorkflowBuilder AddRetryStrategy(RetryDefinition strategy) - { - if (strategy == null) throw new ArgumentNullException(nameof(strategy)); - if (this.Workflow.Retries == null) this.Workflow.Retries = new(); - if (this.Workflow.Retries.Any(rs => rs.Name == strategy.Name)) throw new ArgumentException($"The workflow already defines a function with the specified name '{strategy.Name}'", nameof(strategy)); - this.Workflow.Retries.Add(strategy); - return this; - } - - /// - public virtual IWorkflowBuilder AddRetryStrategy(Action retryStrategySetup) - { - if (retryStrategySetup == null) throw new ArgumentNullException(nameof(retryStrategySetup)); - var builder = new RetryStrategyBuilder(); - retryStrategySetup(builder); - return this.AddRetryStrategy(builder.Build()); - } - - /// - public virtual IWorkflowBuilder ImportAuthenticationDefinitionsFrom(Uri uri) - { - this.Workflow.AuthUri = uri ?? throw new ArgumentNullException(nameof(uri)); - return this; - } - - /// - public virtual IWorkflowBuilder UseAuthenticationDefinitions(params AuthenticationDefinition[] authenticationDefinitions) - { - if (authenticationDefinitions == null) throw new ArgumentNullException(nameof(authenticationDefinitions)); - this.Workflow.Auth = authenticationDefinitions.ToList(); - return this; - } - - /// - public virtual IWorkflowBuilder AddAuthentication(AuthenticationDefinition authenticationDefinition) - { - if (authenticationDefinition == null) throw new ArgumentNullException(nameof(authenticationDefinition)); - if (this.Workflow.Auth == null) this.Workflow.Auth = new(); - this.Workflow.Auth.Add(authenticationDefinition); - return this; - } - - /// - public virtual IWorkflowBuilder AddBasicAuthentication(string name, Action configurationAction) - { - var builder = new BasicAuthenticationBuilder(); - builder.WithName(name); - configurationAction(builder); - return AddAuthentication(builder.Build()); - } - - /// - public virtual IWorkflowBuilder AddBearerAuthentication(string name, Action configurationAction) - { - var builder = new BearerAuthenticationBuilder(); - builder.WithName(name); - configurationAction(builder); - return AddAuthentication(builder.Build()); - } - - /// - public virtual IWorkflowBuilder AddOAuth2Authentication(string name, Action configurationAction) - { - var builder = new OAuth2AuthenticationBuilder(); - builder.WithName(name); - configurationAction(builder); - return AddAuthentication(builder.Build()); - } - - /// - public virtual IPipelineBuilder StartsWith(StateDefinition state) - { - if (state == null) throw new ArgumentNullException(nameof(state)); - this.Pipeline.AddState(state); - this.Workflow.StartStateName = state.Name; - return this.Pipeline; - } - - /// - public virtual IPipelineBuilder StartsWith(Func stateSetup) - { - if (stateSetup == null) throw new ArgumentNullException(nameof(stateSetup)); - var state = this.Pipeline.AddState(stateSetup); - this.Workflow.StartStateName = state.Name; - return this.Pipeline; - } - - /// - public virtual IPipelineBuilder StartsWith(string name, Func stateSetup) - { - if (string.IsNullOrWhiteSpace(name)) throw new ArgumentNullException(nameof(name)); - if (stateSetup == null) throw new ArgumentNullException(nameof(stateSetup)); - return this.StartsWith(flow => stateSetup(flow).WithName(name)); - } - - /// - public virtual IPipelineBuilder StartsWith(Func stateSetup, Action scheduleSetup) - { - if (stateSetup == null) throw new ArgumentNullException(nameof(stateSetup)); - if (scheduleSetup == null) throw new ArgumentNullException(nameof(scheduleSetup)); - var state = this.Pipeline.AddState(stateSetup); - var schedule = new ScheduleBuilder(); - scheduleSetup(schedule); - this.Workflow.Start = new() { StateName = state.Name, Schedule = schedule.Build() }; - return this.Pipeline; - } - - /// - public virtual IPipelineBuilder StartsWith(string name, Func stateSetup, Action scheduleSetup) - { - if (stateSetup == null) throw new ArgumentNullException(nameof(stateSetup)); - if (scheduleSetup == null) throw new ArgumentNullException(nameof(scheduleSetup)); - if (string.IsNullOrWhiteSpace(name)) throw new ArgumentNullException(nameof(name)); - if (stateSetup == null) throw new ArgumentNullException(nameof(stateSetup)); - return this.StartsWith(flow => stateSetup(flow).WithName(name), scheduleSetup); - } - - /// - public virtual WorkflowDefinition Build() - { - this.Workflow.States = this.Pipeline.Build().ToList(); - return this.Workflow; - } - -} diff --git a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/WorkflowExecutionTimeoutBuilder.cs b/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/WorkflowExecutionTimeoutBuilder.cs deleted file mode 100644 index 2796e50..0000000 --- a/src/ServerlessWorkflow.Sdk/Services/FluentBuilders/WorkflowExecutionTimeoutBuilder.cs +++ /dev/null @@ -1,87 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace ServerlessWorkflow.Sdk.Services.FluentBuilders; - -/// -/// Represents the default implementation of the interface -/// -public class WorkflowExecutionTimeoutBuilder - : IWorkflowExecutionTimeoutBuilder -{ - - /// - /// Initializes a new - /// - /// The the belongs to - public WorkflowExecutionTimeoutBuilder(IPipelineBuilder pipeline) - { - this.Pipeline = pipeline; - } - - /// - /// Gets the the belongs to - /// - protected IPipelineBuilder Pipeline { get; } - - /// - /// Gets the to configure - /// - protected WorkflowExecutionTimeoutDefinition Timeout { get; } = new WorkflowExecutionTimeoutDefinition(); - - /// - public virtual IWorkflowExecutionTimeoutBuilder After(TimeSpan duration) - { - this.Timeout.Duration = duration; - return this; - } - - /// - public virtual IWorkflowExecutionTimeoutBuilder InterruptExecution(bool interrupts = true) - { - this.Timeout.Interrupt = interrupts; - return this; - } - - /// - public virtual IWorkflowExecutionTimeoutBuilder Run(string state) - { - if (string.IsNullOrWhiteSpace(state)) - throw new ArgumentNullException(nameof(state)); - this.Timeout.RunBefore = state; - return this; - } - - /// - public virtual IWorkflowExecutionTimeoutBuilder Run(Func stateSetup) - { - if(stateSetup == null) - throw new ArgumentNullException(nameof(stateSetup)); - return this.Run(this.Pipeline.AddState(stateSetup).Name); - } - - /// - public virtual IWorkflowExecutionTimeoutBuilder Run(StateDefinition state) - { - if (state == null) - throw new ArgumentNullException(nameof(state)); - return this.Run(this.Pipeline.AddState(state).Name); - } - - /// - public virtual WorkflowExecutionTimeoutDefinition Build() - { - return this.Timeout; - } - -} diff --git a/src/ServerlessWorkflow.Sdk/Services/IO/Interfaces/IWorkflowExternalDefinitionResolver.cs b/src/ServerlessWorkflow.Sdk/Services/IO/Interfaces/IWorkflowExternalDefinitionResolver.cs deleted file mode 100644 index a57f19e..0000000 --- a/src/ServerlessWorkflow.Sdk/Services/IO/Interfaces/IWorkflowExternalDefinitionResolver.cs +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace ServerlessWorkflow.Sdk.Services.IO; - -/// -/// Defines the fundamentals of a service used to resolve the external definitions referenced by a -/// -public interface IWorkflowExternalDefinitionResolver -{ - - /// - /// Loads the external definitions referenced by the specified - /// - /// The to load the external references of - /// The options used to configure how to read external definitions - /// A - /// The loaded - Task LoadExternalDefinitionsAsync(WorkflowDefinition workflow, WorkflowReaderOptions options, CancellationToken cancellationToken = default); - -} diff --git a/src/ServerlessWorkflow.Sdk/Services/IO/WorkflowExternalDefinitionResolver.cs b/src/ServerlessWorkflow.Sdk/Services/IO/WorkflowExternalDefinitionResolver.cs deleted file mode 100644 index 39e8fea..0000000 --- a/src/ServerlessWorkflow.Sdk/Services/IO/WorkflowExternalDefinitionResolver.cs +++ /dev/null @@ -1,171 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -using Microsoft.Extensions.Logging; - -namespace ServerlessWorkflow.Sdk.Services.IO; - -/// -/// Represents the default implementation of the interface -/// -public class WorkflowExternalDefinitionResolver - : IWorkflowExternalDefinitionResolver -{ - - /// - /// Initializes a new - /// - /// The service used to perform logging - /// The service used to serialize and deserialize JSON - /// The service used to serialize and deserialize YAML - /// The service used to create s - public WorkflowExternalDefinitionResolver(ILogger logger, IHttpClientFactory httpClientFactory) - { - this.Logger = logger; - this.HttpClient = httpClientFactory.CreateClient(); - } - - /// - /// Gets the service used to perform logging - /// - protected ILogger Logger { get; } - - /// - /// Gets the used to retrieve external definitions - /// - protected HttpClient HttpClient { get; } - - /// - public virtual async Task LoadExternalDefinitionsAsync(WorkflowDefinition workflow, WorkflowReaderOptions options, CancellationToken cancellationToken = default) - { - if (workflow == null) throw new ArgumentNullException(nameof(workflow)); - var bundledWorkflow = Serialization.Serializer.Json.Deserialize(Serialization.Serializer.Json.Serialize(workflow))!; - if (bundledWorkflow.DataInputSchemaUri != null && bundledWorkflow.DataInputSchema == null) bundledWorkflow.DataInputSchema = await this.LoadDataInputSchemaAsync(bundledWorkflow.DataInputSchemaUri, options, cancellationToken).ConfigureAwait(false); //todo: load schema sub property - if (bundledWorkflow.EventsUri != null && bundledWorkflow.Events == null) bundledWorkflow.Events = await this.LoadExternalDefinitionCollectionAsync(bundledWorkflow.EventsUri, options, cancellationToken).ConfigureAwait(false); - if (bundledWorkflow.FunctionsUri != null && bundledWorkflow.Functions == null) bundledWorkflow.Functions = await this.LoadExternalDefinitionCollectionAsync(bundledWorkflow.FunctionsUri, options, cancellationToken).ConfigureAwait(false); - if (bundledWorkflow.RetriesUri != null && bundledWorkflow.Retries == null) bundledWorkflow.Retries = await this.LoadExternalDefinitionCollectionAsync(bundledWorkflow.RetriesUri, options, cancellationToken).ConfigureAwait(false); - if (bundledWorkflow.ConstantsUri != null && bundledWorkflow.Constants == null) bundledWorkflow.Constants = await this.LoadExternalDefinitionAsync(bundledWorkflow.ConstantsUri, options, cancellationToken).ConfigureAwait(false); - if (bundledWorkflow.SecretsUri != null && bundledWorkflow.Secrets == null) bundledWorkflow.Secrets = await this.LoadExternalDefinitionCollectionAsync(bundledWorkflow.SecretsUri, options, cancellationToken).ConfigureAwait(false); - if (bundledWorkflow.AuthUri != null && bundledWorkflow.Auth == null) bundledWorkflow.Auth = await this.LoadExternalDefinitionCollectionAsync(bundledWorkflow.AuthUri, options, cancellationToken).ConfigureAwait(false); - return bundledWorkflow; - } - - /// - /// Loads the at the specified - /// - /// The the to load is located at - /// The to use - /// A - /// The loaded - protected virtual async Task LoadDataInputSchemaAsync(Uri uri, WorkflowReaderOptions options, CancellationToken cancellationToken = default) - { - if (uri == null)throw new ArgumentNullException(nameof(uri)); - string? content; - if (!uri.IsAbsoluteUri|| (uri.IsFile && Path.IsPathRooted(uri.LocalPath))) uri = this.ResolveRelativeUri(uri, options); - if (uri.IsFile) - { - var filePath = uri.LocalPath; - if (filePath.StartsWith('/')) filePath = filePath[1..]; - content = File.ReadAllText(filePath); - } - else - { - using var response = await this.HttpClient.GetAsync(uri, cancellationToken).ConfigureAwait(false); - content = await response.Content?.ReadAsStringAsync(cancellationToken)!; - if (!response.IsSuccessStatusCode) response.EnsureSuccessStatusCode(); - } - if (!content.IsJson()) content = Serialization.Serializer.Json.Serialize(Serialization.Serializer.Yaml.Deserialize>(content)); - return Serialization.Serializer.Json.Deserialize(content)!; - } - - /// - /// Loads an external definition - /// - /// The the external definition to load is located at - /// The to use - /// A - /// A new object that represents the object defined in the loaded external definition - protected virtual async Task LoadExternalDefinitionAsync(Uri uri, WorkflowReaderOptions options, CancellationToken cancellationToken = default) - { - if (uri == null)throw new ArgumentNullException(nameof(uri)); - string? content; - if (!uri.IsAbsoluteUri|| (uri.IsFile && Path.IsPathRooted(uri.LocalPath)))uri = this.ResolveRelativeUri(uri, options); - if (uri.IsFile) - { - var filePath = uri.LocalPath; - if (filePath.StartsWith('/'))filePath = filePath[1..]; - content = File.ReadAllText(filePath); - } - else - { - using var response = await this.HttpClient.GetAsync(uri, cancellationToken).ConfigureAwait(false); - content = await response.Content?.ReadAsStringAsync(cancellationToken)!; - if (!response.IsSuccessStatusCode)response.EnsureSuccessStatusCode(); - } - if (content.IsJson()) return Serialization.Serializer.Json.Deserialize(content)!; - else return Serialization.Serializer.Yaml.Deserialize(content)!; - } - - /// - /// Loads external definitions of the specified type - /// - /// The type of external definition to load - /// The the external definition to load is located at - /// The to use - /// A - /// A new containing the elements defined by the loaded external definition - protected virtual async Task> LoadExternalDefinitionCollectionAsync(Uri uri, WorkflowReaderOptions options, CancellationToken cancellationToken = default) - { - if (uri == null) throw new ArgumentNullException(nameof(uri)); - string? content; - if (!uri.IsAbsoluteUri || (uri.IsFile && Path.IsPathRooted(uri.LocalPath))) uri = this.ResolveRelativeUri(uri, options); - if (uri.IsFile) - { - var filePath = uri.LocalPath; - if (filePath.StartsWith("/")) filePath = filePath[1..]; - content = File.ReadAllText(filePath); - } - else - { - using var response = await this.HttpClient.GetAsync(uri, cancellationToken); - content = await response.Content?.ReadAsStringAsync(cancellationToken)!; - if (!response.IsSuccessStatusCode) response.EnsureSuccessStatusCode(); - } - if (content.IsJson()) return Serialization.Serializer.Json.Deserialize>(content)!; - else return Serialization.Serializer.Yaml.Deserialize>(content)!; - } - - /// - /// Resolves the specified relative - /// - /// The relative to resolve - /// The to use - /// The resolved - protected virtual Uri ResolveRelativeUri(Uri uri, WorkflowReaderOptions options) - { - if (uri == null) throw new ArgumentNullException(nameof(uri)); - switch (options.RelativeUriResolutionMode) - { - case RelativeUriReferenceResolutionMode.ConvertToAbsolute: - if (options.BaseUri == null) throw new NullReferenceException($"The '{nameof(WorkflowReaderOptions.BaseUri)}' property must be set when using the specified {nameof(RelativeUriReferenceResolutionMode)} '{RelativeUriReferenceResolutionMode.ConvertToAbsolute}'"); - return new(options.BaseUri, uri.ToString()); - case RelativeUriReferenceResolutionMode.ConvertToRelativeFilePath: - var localPath = uri.LocalPath; - if (localPath.StartsWith("//") || localPath.StartsWith("\\\\")) localPath = localPath[2..]; - return new Uri(Path.Combine(options.BaseDirectory, localPath)); - case RelativeUriReferenceResolutionMode.None: throw new NotSupportedException($"Relative uris are not supported when using the specified {nameof(RelativeUriReferenceResolutionMode)} '{RelativeUriReferenceResolutionMode.ConvertToAbsolute}'"); - default: throw new NotSupportedException($"The specified {nameof(RelativeUriReferenceResolutionMode)} '{RelativeUriReferenceResolutionMode.ConvertToAbsolute}' is not supported"); - } - } - -} diff --git a/src/ServerlessWorkflow.Sdk/Services/IO/WorkflowReader.cs b/src/ServerlessWorkflow.Sdk/Services/IO/WorkflowReader.cs deleted file mode 100644 index d8736ac..0000000 --- a/src/ServerlessWorkflow.Sdk/Services/IO/WorkflowReader.cs +++ /dev/null @@ -1,70 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Logging; - -namespace ServerlessWorkflow.Sdk.Services.IO; - -/// -/// Represents the default implementation of the interface -/// -public class WorkflowReader - : IWorkflowReader -{ - - /// - /// Initializes a new - /// - /// The service used to perform logging - /// The service used to resolve external definitions referenced by s - public WorkflowReader(ILogger logger, IWorkflowExternalDefinitionResolver externalDefinitionResolver) - { - this.Logger = logger; - this.ExternalDefinitionResolver = externalDefinitionResolver; - } - - /// - /// Gets the service used to perform logging - /// - protected ILogger Logger { get; } - - /// - /// Gets the service used to resolve external definitions referenced by s - /// - protected IWorkflowExternalDefinitionResolver ExternalDefinitionResolver { get; } - - /// - public virtual async Task ReadAsync(Stream stream, WorkflowReaderOptions? options = null, CancellationToken cancellationToken = default) - { - if (stream == null)throw new ArgumentNullException(nameof(stream)); - options ??= new WorkflowReaderOptions(); - using var reader = new StreamReader(stream); - var input = reader.ReadToEnd(); - var workflowDefinition = input.IsJson() ? Serialization.Serializer.Json.Deserialize(input)! : Serialization.Serializer.Yaml.Deserialize(input)!; - if(options.LoadExternalDefinitions) workflowDefinition = await this.ExternalDefinitionResolver.LoadExternalDefinitionsAsync(workflowDefinition, options, cancellationToken); - return workflowDefinition; - } - - /// - /// Creates a new default instance of the interface - /// - /// A new - public static IWorkflowReader Create() - { - var services = new ServiceCollection(); - services.AddServerlessWorkflow(); - return services.BuildServiceProvider().GetRequiredService(); - } - -} diff --git a/src/ServerlessWorkflow.Sdk/Services/IO/WorkflowReaderOptions.cs b/src/ServerlessWorkflow.Sdk/Services/IO/WorkflowReaderOptions.cs deleted file mode 100644 index a03aea9..0000000 --- a/src/ServerlessWorkflow.Sdk/Services/IO/WorkflowReaderOptions.cs +++ /dev/null @@ -1,62 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/* - * Copyright 2021-Present The Serverless Workflow Specification Authors - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ -using System; - -namespace ServerlessWorkflow.Sdk.Services.IO -{ - ///

- /// Represents the options used to configure an - /// - public class WorkflowReaderOptions - { - - /// - /// Gets/sets the base to use to combine to relative s when the property is set to - /// - public virtual Uri? BaseUri { get; set; } - - /// - /// Gets/sets the base directory to use when resolving relative when the property is set to . Defaults to - /// - public virtual string BaseDirectory { get; set; } = AppContext.BaseDirectory; - - /// - /// Gets/sets the to use. Defaults to - /// - public virtual string RelativeUriResolutionMode { get; set; } = RelativeUriReferenceResolutionMode.ConvertToRelativeFilePath; - - /// - /// Gets/sets a boolean indicating whether or not to load external definitions - /// - public virtual bool LoadExternalDefinitions { get; set; } - - } - -} diff --git a/src/ServerlessWorkflow.Sdk/Services/IO/WorkflowWriter.cs b/src/ServerlessWorkflow.Sdk/Services/IO/WorkflowWriter.cs deleted file mode 100644 index f509768..0000000 --- a/src/ServerlessWorkflow.Sdk/Services/IO/WorkflowWriter.cs +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -using Microsoft.Extensions.DependencyInjection; - -namespace ServerlessWorkflow.Sdk.Services.IO; - -/// -/// Represents the default implementation of the interface -/// -public class WorkflowWriter - : IWorkflowWriter -{ - - /// - public virtual void Write(WorkflowDefinition workflow, Stream stream, string format = WorkflowDefinitionFormat.Yaml) - { - if (workflow == null) throw new ArgumentNullException(nameof(workflow)); - if (stream == null)throw new ArgumentNullException(nameof(stream)); - var input = format switch - { - WorkflowDefinitionFormat.Json => Serialization.Serializer.Json.Serialize(workflow), - WorkflowDefinitionFormat.Yaml => Serialization.Serializer.Yaml.Serialize(workflow), - _ => throw new NotSupportedException($"The specified workflow definition format '{format}' is not supported"), - }; - using var streamWriter = new StreamWriter(stream, leaveOpen: true); - streamWriter.Write(input); - streamWriter.Flush(); - } - - /// - /// Creates a new default instance of the interface - /// - /// A new - public static IWorkflowWriter Create() - { - var services = new ServiceCollection(); - services.AddServerlessWorkflow(); - return services.BuildServiceProvider().GetRequiredService(); - } - -} diff --git a/src/ServerlessWorkflow.Sdk/Services/Validation/ActionDefinitionValidator.cs b/src/ServerlessWorkflow.Sdk/Services/Validation/ActionDefinitionValidator.cs deleted file mode 100644 index 5b21248..0000000 --- a/src/ServerlessWorkflow.Sdk/Services/Validation/ActionDefinitionValidator.cs +++ /dev/null @@ -1,67 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -using FluentValidation; - -namespace ServerlessWorkflow.Sdk.Services.Validation; - - -/// -/// Represents the service used to validate s -/// -public class ActionDefinitionValidator - : AbstractValidator -{ - - /// - /// Initializes a new - /// - /// The the s to validate belong to - public ActionDefinitionValidator(WorkflowDefinition workflow) - { - this.Workflow = workflow; - - this.RuleFor(a => a.Event) - .NotNull() - .When(a => a.Function == null && a.Subflow == null) - .WithErrorCode($"{nameof(ActionDefinition)}.{nameof(ActionDefinition.Event)}"); - this.RuleFor(a => a.Event!) - .SetValidator(new EventReferenceValidator(this.Workflow)) - .When(a => a.Event != null) - .WithErrorCode($"{nameof(ActionDefinition)}.{nameof(ActionDefinition.Event)}"); - - this.RuleFor(a => a.Function) - .NotNull() - .When(a => a.Event == null && a.Subflow == null) - .WithErrorCode($"{nameof(ActionDefinition)}.{nameof(ActionDefinition.Function)}"); - this.RuleFor(a => a.Function!) - .SetValidator(new FunctionReferenceValidator(this.Workflow)) - .When(a => a.Function != null) - .WithErrorCode($"{nameof(ActionDefinition)}.{nameof(ActionDefinition.Function)}"); - - this.RuleFor(a => a.Subflow) - .NotNull() - .When(a => a.Event == null && a.Function == null) - .WithErrorCode($"{nameof(ActionDefinition)}.{nameof(ActionDefinition.Subflow)}"); - this.RuleFor(a => a.Subflow!) - .SetValidator(new SubflowReferenceValidator(this.Workflow)) - .When(a => a.Subflow != null) - .WithErrorCode($"{nameof(ActionDefinition)}.{nameof(ActionDefinition.Subflow)}"); - } - - /// - /// Gets the the s to validate belong to - /// - protected WorkflowDefinition Workflow { get; } - -} diff --git a/src/ServerlessWorkflow.Sdk/Services/Validation/AuthenticationDefinitionValidator.cs b/src/ServerlessWorkflow.Sdk/Services/Validation/AuthenticationDefinitionValidator.cs deleted file mode 100644 index d7d7e61..0000000 --- a/src/ServerlessWorkflow.Sdk/Services/Validation/AuthenticationDefinitionValidator.cs +++ /dev/null @@ -1,75 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -using FluentValidation; - -namespace ServerlessWorkflow.Sdk.Services.Validation; - -/// -/// Represents the service used to validate s -/// -public class AuthenticationDefinitionValidator - : AbstractValidator -{ - - /// - /// Initializes a new - /// - /// The the s to validate belong to - public AuthenticationDefinitionValidator(WorkflowDefinition workflow) - { - this.Workflow = workflow; - this.RuleFor(a => a.Name) - .NotEmpty() - .WithErrorCode($"{nameof(AuthenticationDefinition)}.{nameof(AuthenticationDefinition.Name)}"); - this.RuleFor(a => a.Properties) - .NotNull() - .WithErrorCode($"{nameof(AuthenticationDefinition)}.{nameof(AuthenticationDefinition.Properties)}"); - this.RuleFor(a => a.Properties) - .Must(BeOfExpectedType) - .WithErrorCode($"{nameof(AuthenticationDefinition)}.{nameof(AuthenticationDefinition.Properties)}") - .WithMessage((auth, properties) => $"The specified properties object cannot be discriminated against the expected type for scheme '{auth.Scheme}'") - .When(a => a.Properties != null); - this.RuleFor(a => a.Properties) - .SetInheritanceValidator(v => - { - v.Add(new BasicAuthenticationPropertiesValidator()); - v.Add(new BearerAuthenticationPropertiesValidator()); - v.Add(new OAuth2AuthenticationPropertiesValidator()); - }); - } - - /// - /// Gets the the s to validate belong to - /// - protected WorkflowDefinition Workflow { get; } - - /// - /// Determines whether or not the specified match the defined and are valid - /// - /// The to check - /// The to check - /// A boolean indicating whether or not the specified match the defined and are valid - protected virtual bool BeOfExpectedType(AuthenticationDefinition authentication, AuthenticationProperties properties) - { - return properties switch - { - BasicAuthenticationProperties => authentication.Scheme == AuthenticationScheme.Basic, - BearerAuthenticationProperties => authentication.Scheme == AuthenticationScheme.Bearer, - OAuth2AuthenticationProperties => authentication.Scheme == AuthenticationScheme.OAuth2, - SecretBasedAuthenticationProperties => true, - _ => false, - }; - } - -} diff --git a/src/ServerlessWorkflow.Sdk/Services/Validation/BasicAuthenticationPropertiesValidator.cs b/src/ServerlessWorkflow.Sdk/Services/Validation/BasicAuthenticationPropertiesValidator.cs deleted file mode 100644 index 7466e04..0000000 --- a/src/ServerlessWorkflow.Sdk/Services/Validation/BasicAuthenticationPropertiesValidator.cs +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -using FluentValidation; - -namespace ServerlessWorkflow.Sdk.Services.Validation; - -/// -/// Represents the service used to validate s -/// -public class BasicAuthenticationPropertiesValidator - : AbstractValidator -{ - - /// - /// Initializes a new - /// - public BasicAuthenticationPropertiesValidator() - { - this.RuleFor(p => p.Username) - .NotEmpty(); - this.RuleFor(p => p.Password) - .NotEmpty(); - } - -} diff --git a/src/ServerlessWorkflow.Sdk/Services/Validation/BearerAuthenticationPropertiesValidator.cs b/src/ServerlessWorkflow.Sdk/Services/Validation/BearerAuthenticationPropertiesValidator.cs deleted file mode 100644 index c5fe4ba..0000000 --- a/src/ServerlessWorkflow.Sdk/Services/Validation/BearerAuthenticationPropertiesValidator.cs +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -using FluentValidation; - -namespace ServerlessWorkflow.Sdk.Services.Validation; - -/// -/// Represents the service used to validate s -/// -public class BearerAuthenticationPropertiesValidator - : AbstractValidator -{ - - /// - /// Initializes a new - /// - public BearerAuthenticationPropertiesValidator() - { - this.RuleFor(p => p.Token) - .NotEmpty(); - } - -} diff --git a/src/ServerlessWorkflow.Sdk/Services/Validation/CallbackStateValidator.cs b/src/ServerlessWorkflow.Sdk/Services/Validation/CallbackStateValidator.cs deleted file mode 100644 index 7be89f7..0000000 --- a/src/ServerlessWorkflow.Sdk/Services/Validation/CallbackStateValidator.cs +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -using FluentValidation; - -namespace ServerlessWorkflow.Sdk.Services.Validation; - -/// -/// Represents a service used to validate s -/// -public class CallbackStateValidator - : StateDefinitionValidator -{ - - /// - /// Initializes a new - /// - /// The to validate - public CallbackStateValidator(WorkflowDefinition workflow) - : base(workflow) - { - this.RuleFor(s => s.Action) - .NotNull() - .WithErrorCode($"{nameof(CallbackStateDefinition)}.{nameof(CallbackStateDefinition.Action)}"); - this.RuleFor(s => s.Action!) - .SetValidator(new ActionDefinitionValidator(workflow)) - .When(s => s.Action != null) - .WithErrorCode($"{nameof(CallbackStateDefinition)}.{nameof(CallbackStateDefinition.Action)}"); - this.RuleFor(s => s.EventRef) - .NotEmpty() - .WithErrorCode($"{nameof(CallbackStateDefinition)}.{nameof(CallbackStateDefinition.EventRef)}"); - this.RuleFor(s => s.EventRef!) - .Must(ReferenceExistingEvent) - .When(s => !string.IsNullOrWhiteSpace(s.EventRef)) - .WithErrorCode($"{nameof(CallbackStateDefinition)}.{nameof(CallbackStateDefinition.EventRef)}") - .WithMessage((state, eventRef) => $"Failed to find the event with name '{eventRef}' defined by the callback state with name '{state.Name}'"); - } - -} diff --git a/src/ServerlessWorkflow.Sdk/Services/Validation/CollectionPropertyValidator.cs b/src/ServerlessWorkflow.Sdk/Services/Validation/CollectionPropertyValidator.cs deleted file mode 100644 index 98bb7ae..0000000 --- a/src/ServerlessWorkflow.Sdk/Services/Validation/CollectionPropertyValidator.cs +++ /dev/null @@ -1,65 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -using FluentValidation; -using FluentValidation.Validators; -using Microsoft.Extensions.DependencyInjection; - -namespace ServerlessWorkflow.Sdk.Services.Validation; - - -/// -/// Represents the service used to validate a workflow's s -/// -public class CollectionPropertyValidator - : PropertyValidator?> -{ - - /// - /// Initializes a new - /// - /// The current - public CollectionPropertyValidator(IServiceProvider serviceProvider) - { - this.ServiceProvider = serviceProvider; - } - - /// - public override string Name => "CollectionValidator"; - - /// - /// Gets the current - /// - protected IServiceProvider ServiceProvider { get; } - - /// - public override bool IsValid(ValidationContext context, IEnumerable? value) - { - var index = 0; - if (value == null) return true; - foreach (TElement elem in value) - { - IEnumerable> validators = this.ServiceProvider.GetServices>(); - foreach (IValidator validator in validators) - { - FluentValidation.Results.ValidationResult validationResult = validator.Validate(elem); - if (validationResult.IsValid) continue; - foreach (var failure in validationResult.Errors) context.AddFailure(failure); - return false; - } - index++; - } - return true; - } - -} diff --git a/src/ServerlessWorkflow.Sdk/Services/Validation/DataCaseDefinitionValidator.cs b/src/ServerlessWorkflow.Sdk/Services/Validation/DataCaseDefinitionValidator.cs deleted file mode 100644 index c6f1ebf..0000000 --- a/src/ServerlessWorkflow.Sdk/Services/Validation/DataCaseDefinitionValidator.cs +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -using FluentValidation; - -namespace ServerlessWorkflow.Sdk.Services.Validation; - -/// -/// Represents a service used to validate s -/// -public class DataCaseDefinitionValidator - : SwitchCaseDefinitionValidator -{ - - /// - /// Initializes a new - /// - /// The the to validate belongs to - /// The the to validate belongs to - public DataCaseDefinitionValidator(WorkflowDefinition workflow, SwitchStateDefinition state) - : base(workflow, state) - { - this.RuleFor(c => c.Condition) - .NotEmpty() - .WithErrorCode($"{nameof(DataCaseDefinition)}.{nameof(DataCaseDefinition.Condition)}"); - } - -} diff --git a/src/ServerlessWorkflow.Sdk/Services/Validation/DefaultCaseDefinitionValidator.cs b/src/ServerlessWorkflow.Sdk/Services/Validation/DefaultCaseDefinitionValidator.cs deleted file mode 100644 index 34f3f65..0000000 --- a/src/ServerlessWorkflow.Sdk/Services/Validation/DefaultCaseDefinitionValidator.cs +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace ServerlessWorkflow.Sdk.Services.Validation; - -/// -/// Represents a service used to validate s -/// -public class DefaultCaseDefinitionValidator - : SwitchCaseDefinitionValidator -{ - - /// - /// Initializes a new - /// - /// The the to validate belongs to - /// The the to validate belongs to - public DefaultCaseDefinitionValidator(WorkflowDefinition workflow, SwitchStateDefinition state) - : base(workflow, state) - { - - } - -} diff --git a/src/ServerlessWorkflow.Sdk/Services/Validation/ErrorHandlerDefinitionValidator.cs b/src/ServerlessWorkflow.Sdk/Services/Validation/ErrorHandlerDefinitionValidator.cs deleted file mode 100644 index a5ff020..0000000 --- a/src/ServerlessWorkflow.Sdk/Services/Validation/ErrorHandlerDefinitionValidator.cs +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -using FluentValidation; - -namespace ServerlessWorkflow.Sdk.Services.Validation; - -/// -/// Represents the service used to validate s -/// -public class ErrorHandlerDefinitionValidator - : AbstractValidator -{ - - /// - /// Initializes a new - /// - /// The the s to validate belong to - /// The state definition the s to validate belong to - public ErrorHandlerDefinitionValidator(WorkflowDefinition workflow, StateDefinition state) - { - this.Workflow = workflow; - this.State = state; - this.RuleFor(h => h.Error) - .NotEmpty(); - this.RuleFor(h => h.Code) - .Empty() - .When(h => h.Error == "*") - .WithMessage("The 'Code' property cannot be set when the 'Error' property has been set to '*'"); - this.RuleFor(h => h.End) - .NotNull() - .When(h => h.Transition == null); - this.RuleFor(h => h.Transition!) - .NotNull() - .When(h => h.End == null) - .SetValidator(new TransitionDefinitionValidator(workflow)); - } - - /// - /// Gets the the s to validate belong to - /// - protected WorkflowDefinition Workflow { get; } - - /// - /// Gets the state definition the s to validate belong to - /// - protected StateDefinition State { get; } - -} diff --git a/src/ServerlessWorkflow.Sdk/Services/Validation/EventCaseDefinitionValidator.cs b/src/ServerlessWorkflow.Sdk/Services/Validation/EventCaseDefinitionValidator.cs deleted file mode 100644 index f57b817..0000000 --- a/src/ServerlessWorkflow.Sdk/Services/Validation/EventCaseDefinitionValidator.cs +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -using FluentValidation; - -namespace ServerlessWorkflow.Sdk.Services.Validation; - -/// -/// Represents a service used to validate s -/// -public class EventCaseDefinitionValidator - : SwitchCaseDefinitionValidator -{ - - /// - /// Initializes a new - /// - /// The the to validate belongs to - /// The the to validate belongs to - public EventCaseDefinitionValidator(WorkflowDefinition workflow, SwitchStateDefinition state) - : base(workflow, state) - { - this.RuleFor(c => c.EventRef) - .NotEmpty() - .WithErrorCode($"{nameof(EventCaseDefinition)}.{nameof(EventCaseDefinition.EventRef)}"); - this.RuleFor(c => c.EventRef) - .Must(ReferenceExistingEvent) - .When(c => !string.IsNullOrWhiteSpace(c.EventRef)) - .WithErrorCode($"{nameof(EventCaseDefinition)}.{nameof(EventCaseDefinition.EventRef)}") - .WithMessage(e => $"Failed to find an event definition with the specified name '{e.EventRef}'"); - } - - /// - /// Determines whether or not the specified exists - /// - /// The name of the to check - /// A boolean indicating whether or not the specified exists - protected virtual bool ReferenceExistingEvent(string eventName) - { - return this.Workflow.TryGetEvent(eventName, out _); - } - -} diff --git a/src/ServerlessWorkflow.Sdk/Services/Validation/EventReferenceValidator.cs b/src/ServerlessWorkflow.Sdk/Services/Validation/EventReferenceValidator.cs deleted file mode 100644 index dff9662..0000000 --- a/src/ServerlessWorkflow.Sdk/Services/Validation/EventReferenceValidator.cs +++ /dev/null @@ -1,94 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -using FluentValidation; - -namespace ServerlessWorkflow.Sdk.Services.Validation; - -/// -/// Represents the service used to validate s -/// -public class EventReferenceValidator - : AbstractValidator -{ - - /// - /// Initializes a new - /// - /// The the s to validate belong to - public EventReferenceValidator(WorkflowDefinition workflow) - { - this.Workflow = workflow; - this.RuleFor(e => e.TriggerEventRef) - .NotEmpty() - .WithErrorCode($"{nameof(EventReference)}.{nameof(EventReference.TriggerEventRef)}"); - this.RuleFor(e => e.TriggerEventRef) - .Must(ReferenceExistingEvent) - .When(e => !string.IsNullOrWhiteSpace(e.TriggerEventRef)) - .WithErrorCode($"{nameof(EventReference)}.{nameof(EventReference.TriggerEventRef)}") - .WithMessage(eventRef => $"Failed to find the event with name '{eventRef.TriggerEventRef}'"); - this.RuleFor(e => e.TriggerEventRef) - .Must(BeProduced) - .When(e => !string.IsNullOrWhiteSpace(e.TriggerEventRef)) - .WithErrorCode($"{nameof(EventReference)}.{nameof(EventReference.TriggerEventRef)}") - .WithMessage(eventRef => $"The event with name '{eventRef.TriggerEventRef}' must be of kind '{EventKind.Produced}'"); - this.RuleFor(e => e.ResultEventRef) - .NotEmpty() - .WithErrorCode($"{nameof(EventReference)}.{nameof(EventReference.ResultEventRef)}"); - this.RuleFor(e => e.ResultEventRef) - .Must(ReferenceExistingEvent!) - .When(e => !string.IsNullOrWhiteSpace(e.ResultEventRef)) - .WithErrorCode($"{nameof(EventReference)}.{nameof(EventReference.ResultEventRef)}") - .WithMessage(eventRef => $"Failed to find the event with name '{eventRef.ResultEventRef}'"); - this.RuleFor(e => e.ResultEventRef) - .Must(BeConsumed!) - .When(e => !string.IsNullOrWhiteSpace(e.ResultEventRef)) - .WithErrorCode($"{nameof(EventReference)}.{nameof(EventReference.ResultEventRef)}") - .WithMessage(eventRef => $"The event with name '{eventRef.ResultEventRef}' must be of kind '{EventKind.Consumed}'"); - } - - /// - /// Gets the the s to validate belong to - /// - protected WorkflowDefinition Workflow { get; } - - /// - /// Determines whether or not the specified exists - /// - /// The name of the to check - /// A boolean indicating whether or not the specified exists - protected virtual bool ReferenceExistingEvent(string eventName) => this.Workflow.TryGetEvent(eventName, out _); - - /// - /// Determines whether or not the specified is of kind - /// - /// The name of the to check - /// A boolean indicating whether or not the specified of kind - protected virtual bool BeProduced(string name) - { - if (!this.Workflow.TryGetEvent(name, out EventDefinition e)) return false; - return e.Kind == EventKind.Produced; - } - - /// - /// Determines whether or not the specified is of kind - /// - /// The name of the to check - /// A boolean indicating whether or not the specified of kind - protected virtual bool BeConsumed(string name) - { - if (!this.Workflow.TryGetEvent(name, out EventDefinition e)) return false; - return e.Kind == EventKind.Consumed; - } - -} diff --git a/src/ServerlessWorkflow.Sdk/Services/Validation/EventStateTriggerDefinitionValidator.cs b/src/ServerlessWorkflow.Sdk/Services/Validation/EventStateTriggerDefinitionValidator.cs deleted file mode 100644 index 312e0d0..0000000 --- a/src/ServerlessWorkflow.Sdk/Services/Validation/EventStateTriggerDefinitionValidator.cs +++ /dev/null @@ -1,81 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -using FluentValidation; - -namespace ServerlessWorkflow.Sdk.Services.Validation; - -/// -/// Represents a service used to validate s -/// -public class EventStateTriggerDefinitionValidator - : AbstractValidator -{ - - /// - /// Initializes a new - /// - /// The the to validate belongs to - /// The the to validate belongs to - public EventStateTriggerDefinitionValidator(WorkflowDefinition workflow, EventStateDefinition eventState) - { - this.Workflow = workflow; - this.EventState = eventState; - this.RuleForEach(t => t.Actions) - .SetValidator(new ActionDefinitionValidator(this.Workflow)) - .When(t => t.Actions != null && t.Actions.Any()) - .WithErrorCode($"{nameof(EventStateTriggerDefinition)}.{nameof(EventStateTriggerDefinition.Actions)}"); - this.RuleFor(t => t.EventRefs) - .NotEmpty() - .WithErrorCode($"{nameof(EventStateTriggerDefinition)}.{nameof(EventStateTriggerDefinition.EventRefs)}"); - this.RuleForEach(t => t.EventRefs) - .Must(ReferenceExistingEvent) - .When(t => t.EventRefs != null && t.EventRefs.Any()) - .WithErrorCode($"{nameof(EventStateTriggerDefinition)}.{nameof(EventStateTriggerDefinition.EventRefs)}") - .WithMessage(eventRef => $"Failed to find an event with name '{eventRef}'"); - this.RuleForEach(t => t.EventRefs) - .Must(BeConsumed) - .When(t => t.EventRefs != null && t.EventRefs.Any()) - .WithErrorCode($"{nameof(EventStateTriggerDefinition)}.{nameof(EventStateTriggerDefinition.EventRefs)}") - .WithMessage(eventRef => $"The event with name '{eventRef}' must be of kind '{EventKind.Consumed}' to be used in an event state trigger"); - } - - /// - /// Gets the the to validate belongs to - /// - protected WorkflowDefinition Workflow { get; } - - /// - /// Gets the the to validate belongs to - /// - protected EventStateDefinition EventState { get; } - - /// - /// Determines whether or not the specified exists - /// - /// The name of the to check - /// A boolean indicating whether or not the specified exists - protected virtual bool ReferenceExistingEvent(string eventName) => this.Workflow.TryGetEvent(eventName, out _); - - /// - /// Determines whether or not the specified is of kind - /// - /// The name of the to check - /// A boolean indicating whether or not the specified of kind - protected virtual bool BeConsumed(string name) - { - if (!this.Workflow.TryGetEvent(name, out var e)) return false; - return e.Kind == EventKind.Consumed; - } - -} diff --git a/src/ServerlessWorkflow.Sdk/Services/Validation/EventStateValidator.cs b/src/ServerlessWorkflow.Sdk/Services/Validation/EventStateValidator.cs deleted file mode 100644 index ea55b65..0000000 --- a/src/ServerlessWorkflow.Sdk/Services/Validation/EventStateValidator.cs +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -using FluentValidation; - -namespace ServerlessWorkflow.Sdk.Services.Validation; - -/// -/// Represents a service used to validate s -/// -public class EventStateValidator - : StateDefinitionValidator -{ - - /// - /// Initializes a new - /// - /// The to validate - public EventStateValidator(WorkflowDefinition workflow) - : base(workflow) - { - this.RuleFor(s => s.OnEvents) - .NotEmpty() - .WithErrorCode($"{nameof(EventStateDefinition)}.{nameof(EventStateDefinition.OnEvents)}"); - this.RuleForEach(s => s.OnEvents) - .SetValidator(state => new EventStateTriggerDefinitionValidator(this.Workflow, state)) - .When(s => s.OnEvents != null && s.OnEvents.Any()) - .WithErrorCode($"{nameof(EventStateDefinition)}.{nameof(EventStateDefinition.OnEvents)}"); - } - -} diff --git a/src/ServerlessWorkflow.Sdk/Services/Validation/ForEachStateValidator.cs b/src/ServerlessWorkflow.Sdk/Services/Validation/ForEachStateValidator.cs deleted file mode 100644 index 524d7b4..0000000 --- a/src/ServerlessWorkflow.Sdk/Services/Validation/ForEachStateValidator.cs +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -using FluentValidation; - -namespace ServerlessWorkflow.Sdk.Services.Validation; - -/// -/// Represents a service used to validate s -/// -public class ForEachStateValidator - : StateDefinitionValidator -{ - - /// - /// Initializes a new - /// - /// The to validate - public ForEachStateValidator(WorkflowDefinition workflow) - : base(workflow) - { - this.RuleFor(s => s.Actions) - .NotEmpty() - .WithErrorCode($"{nameof(ForEachStateDefinition)}.{nameof(ForEachStateDefinition.Actions)}"); - this.RuleForEach(s => s.Actions) - .SetValidator(new ActionDefinitionValidator(this.Workflow)) - .When(s => s.Actions != null && s.Actions.Any()) - .WithErrorCode($"{nameof(ForEachStateDefinition)}.{nameof(ForEachStateDefinition.Actions)}"); - } - -} diff --git a/src/ServerlessWorkflow.Sdk/Services/Validation/FunctionDefinitionCollectionValidator.cs b/src/ServerlessWorkflow.Sdk/Services/Validation/FunctionDefinitionCollectionValidator.cs deleted file mode 100644 index a464741..0000000 --- a/src/ServerlessWorkflow.Sdk/Services/Validation/FunctionDefinitionCollectionValidator.cs +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -using FluentValidation; -using FluentValidation.Validators; - -namespace ServerlessWorkflow.Sdk.Services.Validation; - -/// -/// Represents the used to validate a collection -/// -public class FunctionDefinitionCollectionValidator - : PropertyValidator> -{ - - /// - public override string Name => "FunctionDefinitionCollection"; - - /// - public override bool IsValid(ValidationContext context, IEnumerable value) - { - var workflow = context.InstanceToValidate; - var index = 0; - var validator = new FunctionDefinitionValidator(workflow); - foreach (var function in value) - { - - var validationResult = validator.Validate(function); - if (validationResult.IsValid) - { - index++; - continue; - } - foreach(var failure in validationResult.Errors) context.AddFailure(failure); - return false; - } - return true; - } - -} diff --git a/src/ServerlessWorkflow.Sdk/Services/Validation/FunctionDefinitionValidator.cs b/src/ServerlessWorkflow.Sdk/Services/Validation/FunctionDefinitionValidator.cs deleted file mode 100644 index b738946..0000000 --- a/src/ServerlessWorkflow.Sdk/Services/Validation/FunctionDefinitionValidator.cs +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -using FluentValidation; - -namespace ServerlessWorkflow.Sdk.Services.Validation; - -/// -/// Represents the service used to validate s -/// -public class FunctionDefinitionValidator - : AbstractValidator -{ - - /// - /// Initializes a new - /// - /// The the s to validate belong to - public FunctionDefinitionValidator(WorkflowDefinition workflow) - { - this.Workflow = workflow; - this.RuleFor(f => f.Name) - .NotEmpty() - .WithErrorCode($"{nameof(FunctionDefinition)}.{nameof(FunctionDefinition.Name)}"); - this.RuleFor(f => f.Operation) - .NotEmpty() - .WithErrorCode($"{nameof(FunctionDefinition)}.{nameof(FunctionDefinition.Operation)}"); - this.RuleFor(f => f.AuthRef!) - .Must(ReferenceExistingAuthentication) - .WithErrorCode($"{nameof(FunctionDefinition)}.{nameof(FunctionDefinition.AuthRef)}") - .WithMessage(f => $"Failed to find an authentication definition with name '{f.AuthRef}'") - .When(f => !string.IsNullOrWhiteSpace(f.AuthRef)); - } - - /// - /// Gets the the s to validate belong to - /// - protected WorkflowDefinition Workflow { get; } - - /// - /// Determines whether or not the specified exists - /// - /// The name of the to check - /// A boolean indicating whether or not the specified exists - protected virtual bool ReferenceExistingAuthentication(string authenticationName) => this.Workflow.TryGetAuthentication(authenticationName, out _); - -} diff --git a/src/ServerlessWorkflow.Sdk/Services/Validation/FunctionReferenceValidator.cs b/src/ServerlessWorkflow.Sdk/Services/Validation/FunctionReferenceValidator.cs deleted file mode 100644 index c90c367..0000000 --- a/src/ServerlessWorkflow.Sdk/Services/Validation/FunctionReferenceValidator.cs +++ /dev/null @@ -1,84 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -using FluentValidation; - -namespace ServerlessWorkflow.Sdk.Services.Validation; - -/// -/// Represents the service used to validate s -/// -public class FunctionReferenceValidator - : AbstractValidator -{ - - /// - /// Initializes a new - /// - /// The the s to validate belong to - public FunctionReferenceValidator(WorkflowDefinition workflow) - { - this.Workflow = workflow; - this.RuleFor(f => f.RefName) - .NotEmpty() - .WithErrorCode($"{nameof(FunctionReference)}.{nameof(FunctionReference.RefName)}"); - this.RuleFor(f => f.RefName) - .Must(ReferenceExistingFunction) - .When(f => !string.IsNullOrWhiteSpace(f.RefName)) - .WithErrorCode($"{nameof(FunctionReference)}.{nameof(FunctionReference.RefName)}") - .WithMessage(f => $"Failed to find a function with name '{f.RefName}'"); - this.RuleFor(f => f.SelectionSet) - .Empty() - .When(DoesNotReferenceGraphQLFunction); - this.RuleFor(f => f.SelectionSet) - .NotEmpty() - .When(ReferencesGraphQLFunction); - } - - /// - /// Gets the the s to validate belong to - /// - protected WorkflowDefinition Workflow { get; } - - /// - /// Determines whether or not the specified exists - /// - /// The name of the to check - /// A boolean indicating whether or not the specified exists - protected virtual bool ReferenceExistingFunction(string functionName) => this.Workflow.TryGetFunction(functionName, out _); - - /// - /// Determines whether or not the specified references a of type '' - /// - /// The to validate - /// A boolean indicating whether or not the referenced is not of '' type - protected virtual bool DoesNotReferenceGraphQLFunction(FunctionReference functionReference) - { - if (string.IsNullOrWhiteSpace(functionReference.RefName)) return false; - if (!this.Workflow.TryGetFunction(functionReference.RefName, out FunctionDefinition function)) return false; - return function.Type != FunctionType.GraphQL; - } - - /// - /// Determines whether or not the specified references a of type '' - /// - /// The to validate - /// A boolean indicating whether or not the referenced is of '' type - protected virtual bool ReferencesGraphQLFunction(FunctionReference functionReference) - { - if (string.IsNullOrWhiteSpace(functionReference.RefName)) return false; - if (!this.Workflow.TryGetFunction(functionReference.RefName, out FunctionDefinition function)) return false; - return function.Type == FunctionType.GraphQL; - } - -} diff --git a/src/ServerlessWorkflow.Sdk/Services/Validation/InjectStateValidator.cs b/src/ServerlessWorkflow.Sdk/Services/Validation/InjectStateValidator.cs deleted file mode 100644 index 8385c31..0000000 --- a/src/ServerlessWorkflow.Sdk/Services/Validation/InjectStateValidator.cs +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -using FluentValidation; - -namespace ServerlessWorkflow.Sdk.Services.Validation; - -/// -/// Represents a service used to validate s -/// -public class InjectStateValidator - : StateDefinitionValidator -{ - - /// - /// Initializes a new - /// - /// The to validate - public InjectStateValidator(WorkflowDefinition workflow) - : base(workflow) - { - this.RuleFor(s => s.Data) - .NotNull() - .WithErrorCode($"{nameof(InjectStateDefinition)}.{nameof(InjectStateDefinition.Data)}"); - } - -} diff --git a/src/ServerlessWorkflow.Sdk/Services/Validation/Interfaces/IWorkflowSchemaValidator.cs b/src/ServerlessWorkflow.Sdk/Services/Validation/Interfaces/IWorkflowSchemaValidator.cs deleted file mode 100644 index c680fef..0000000 --- a/src/ServerlessWorkflow.Sdk/Services/Validation/Interfaces/IWorkflowSchemaValidator.cs +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace ServerlessWorkflow.Sdk.Services.Validation; - -/// -/// Defines the fundamentals of a service used to validate s against the adequate version of the Serverless Workflow Specification schema -/// -public interface IWorkflowSchemaValidator -{ - - /// - /// Validates the specified against the adequate version of the Serverless Workflow Specification schema - /// - /// The to validate - /// A - /// A new that describes the result of the validation - Task ValidateAsync(WorkflowDefinition workflow, CancellationToken cancellationToken = default); - -} diff --git a/src/ServerlessWorkflow.Sdk/Services/Validation/Interfaces/IWorkflowValidationResult.cs b/src/ServerlessWorkflow.Sdk/Services/Validation/Interfaces/IWorkflowValidationResult.cs deleted file mode 100644 index 9addd1e..0000000 --- a/src/ServerlessWorkflow.Sdk/Services/Validation/Interfaces/IWorkflowValidationResult.cs +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace ServerlessWorkflow.Sdk.Services.Validation; - -/// -/// Defines the fundamentals of an object used to describe a 's validation results -/// -public interface IWorkflowValidationResult -{ - - /// - /// Gets an containing the schema-related validation errors that have occured during the 's validation - /// - IEnumerable>? SchemaValidationErrors { get; } - - /// - /// Gets an containing the DSL-related validation errors that have occured during the 's validation - /// - IEnumerable>? DslValidationErrors { get; } - - /// - /// Gets a boolean indicating whether or not the is valid - /// - bool IsValid { get; } - -} diff --git a/src/ServerlessWorkflow.Sdk/Services/Validation/Interfaces/IWorkflowValidator.cs b/src/ServerlessWorkflow.Sdk/Services/Validation/Interfaces/IWorkflowValidator.cs deleted file mode 100644 index bcd0b43..0000000 --- a/src/ServerlessWorkflow.Sdk/Services/Validation/Interfaces/IWorkflowValidator.cs +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace ServerlessWorkflow.Sdk.Services.Validation; - -/// -/// Defines the fundamentals of a service used to validate s -/// -public interface IWorkflowValidator -{ - - /// - /// Validates the specified - /// - /// The to validate - /// A boolean indicating whether or not to validate the schema of the specified - /// A boolean indicating whether or not to validate the DSL of the specified - /// A - /// A new - Task ValidateAsync(WorkflowDefinition workflowDefinition, bool validateSchema = true, bool validateDsl = true, CancellationToken cancellationToken = default); - -} diff --git a/src/ServerlessWorkflow.Sdk/Services/Validation/OAuth2AuthenticationPropertiesValidator.cs b/src/ServerlessWorkflow.Sdk/Services/Validation/OAuth2AuthenticationPropertiesValidator.cs deleted file mode 100644 index 8986603..0000000 --- a/src/ServerlessWorkflow.Sdk/Services/Validation/OAuth2AuthenticationPropertiesValidator.cs +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -using FluentValidation; - -namespace ServerlessWorkflow.Sdk.Services.Validation; - -/// -/// Represents the service used to validate s -/// -public class OAuth2AuthenticationPropertiesValidator - : AbstractValidator -{ - - /// - /// Initializes a new - /// - public OAuth2AuthenticationPropertiesValidator() - { - this.RuleFor(a => a.Authority) - .NotNull(); - this.RuleFor(a => a.ClientId) - .NotEmpty(); - this.RuleFor(a => a.Username) - .NotEmpty() - .When(a => a.GrantType == OAuth2GrantType.Password); - this.RuleFor(a => a.Password) - .NotEmpty() - .When(a => a.GrantType == OAuth2GrantType.Password); - } - -} diff --git a/src/ServerlessWorkflow.Sdk/Services/Validation/OperationStateValidator.cs b/src/ServerlessWorkflow.Sdk/Services/Validation/OperationStateValidator.cs deleted file mode 100644 index 976f92e..0000000 --- a/src/ServerlessWorkflow.Sdk/Services/Validation/OperationStateValidator.cs +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -using FluentValidation; - -namespace ServerlessWorkflow.Sdk.Services.Validation; - -/// -/// Represents a service used to validate s -/// -public class OperationStateValidator - : StateDefinitionValidator -{ - - /// - /// Initializes a new - /// - /// The to validate - public OperationStateValidator(WorkflowDefinition workflow) - : base(workflow) - { - this.RuleFor(s => s.Actions) - .NotEmpty() - .WithErrorCode($"{nameof(OperationStateDefinition)}.{nameof(OperationStateDefinition.Actions)}"); - this.RuleForEach(s => s.Actions) - .SetValidator(new ActionDefinitionValidator(this.Workflow)) - .When(s => s.Actions != null && s.Actions.Any()) - .WithErrorCode($"{nameof(OperationStateDefinition)}.{nameof(OperationStateDefinition.Actions)}"); - } - -} diff --git a/src/ServerlessWorkflow.Sdk/Services/Validation/RetryStrategyDefinitionValidator.cs b/src/ServerlessWorkflow.Sdk/Services/Validation/RetryStrategyDefinitionValidator.cs deleted file mode 100644 index 84a5d83..0000000 --- a/src/ServerlessWorkflow.Sdk/Services/Validation/RetryStrategyDefinitionValidator.cs +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -using FluentValidation; - -namespace ServerlessWorkflow.Sdk.Services.Validation; - -/// -/// Represents the service used to validate s -/// -public class RetryStrategyDefinitionValidator - : AbstractValidator -{ - - /// - /// Initializes a new - /// - public RetryStrategyDefinitionValidator() - { - this.RuleFor(r => r.Name) - .NotEmpty() - .WithErrorCode($"{nameof(RetryDefinition)}.{nameof(RetryDefinition.Name)}"); - } - -} diff --git a/src/ServerlessWorkflow.Sdk/Services/Validation/SleepStateValidator.cs b/src/ServerlessWorkflow.Sdk/Services/Validation/SleepStateValidator.cs deleted file mode 100644 index c0fd270..0000000 --- a/src/ServerlessWorkflow.Sdk/Services/Validation/SleepStateValidator.cs +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace ServerlessWorkflow.Sdk.Services.Validation; - - -/// -/// Represents a service used to validate s -/// -public class SleepStateValidator - : StateDefinitionValidator -{ - - /// - /// Initializes a new - /// - /// The to validate - public SleepStateValidator(WorkflowDefinition workflow) - : base(workflow) - { - - } - -} diff --git a/src/ServerlessWorkflow.Sdk/Services/Validation/StateDefinitionValidator.cs b/src/ServerlessWorkflow.Sdk/Services/Validation/StateDefinitionValidator.cs deleted file mode 100644 index a12f421..0000000 --- a/src/ServerlessWorkflow.Sdk/Services/Validation/StateDefinitionValidator.cs +++ /dev/null @@ -1,131 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -using FluentValidation; - -namespace ServerlessWorkflow.Sdk.Services.Validation; - -/// -/// Represents the base class for all s used to validate state definitions -/// -/// The type of state definition to validate -public abstract class StateDefinitionValidator - : AbstractValidator - where TState : StateDefinition -{ - - /// - /// Initializes a new - /// - /// The to validate - protected StateDefinitionValidator(WorkflowDefinition workflow) - { - this.Workflow = workflow; - this.RuleFor(s => s.Name) - .NotNull(); - this.RuleFor(s => s.CompensatedBy!) - .Must(ReferenceExistingState) - .When(s => !string.IsNullOrWhiteSpace(s.CompensatedBy)) - .WithMessage((state, stateName) => $"Failed to find the state '{stateName}' to use for compensation"); - this.RuleFor(s => s.Transition!) - .Must(ReferenceExistingState) - .When(s => s.Transition != null) - .WithMessage((state, stateName) => $"Failed to find the state '{stateName}' to transition to"); - this.RuleFor(s => s.Transition!) - .Must(DefineCompensationState) - .When(s => s.Transition != null && s.Transition.Compensate) - .WithMessage(state => $"The '{nameof(StateDefinition.CompensatedBy)}' property of the state '{state.Name}' must be set when enabling its compensation (in both Transition and End definitions)"); - this.RuleFor(s => s.End!) - .Must(DefineCompensationState) - .When(s => s.End != null && s.End.Compensate) - .WithMessage(state => $"The '{nameof(StateDefinition.CompensatedBy)}' property of the state '{state.Name}' must be set when enabling its compensation (in both Transition and End definitions)"); - this.RuleForEach(s => s.Errors) - .SetValidator((s, e) => new ErrorHandlerDefinitionValidator(this.Workflow, s)); - this.RuleFor(s => s.UsedForCompensation) - .Must(BeAvailableForCompensation) - .When(state => state.UsedForCompensation) - .WithMessage(state => $"The state with name '{state.Name}' must not be part of the main control flow to be used as a compensation state"); - } - - /// - /// Gets the to validate - /// - protected WorkflowDefinition Workflow { get; } - - /// - /// Determines whether or not the specified state definition exists - /// - /// The name of the state definition to check - /// A boolean indicating whether or not the specified state definition exists - protected virtual bool ReferenceExistingState(TransitionDefinition transition) - { - return this.Workflow.TryGetState(transition.NextState, out _); - } - - /// - /// Determines whether or not the specified state definition exists - /// - /// The name of the state definition to check - /// A boolean indicating whether or not the specified state definition exists - protected virtual bool ReferenceExistingState(string stateName) - { - return this.Workflow.TryGetState(stateName, out _); - } - - /// - /// Determines whether or not the specified exists - /// - /// The name of the to check - /// A boolean indicating whether or not the specified exists - protected virtual bool ReferenceExistingEvent(string eventName) - { - return this.Workflow.TryGetEvent(eventName, out _); - } - - /// - /// Determines whether or not the specified state definition defines a compensation state - /// - /// The state definition to check - /// The that references the state definition to check - /// A boolean indicating whether or not the specified state definition defines a compensation state - protected virtual bool DefineCompensationState(TState state, TransitionDefinition oneOf) - { - return !string.IsNullOrWhiteSpace(state.CompensatedBy); - } - - /// - /// Determines whether or not the specified state definition defines a compensation state - /// - /// The state definition to check - /// The that references the state definition to check - /// A boolean indicating whether or not the specified state definition defines a compensation state - protected virtual bool DefineCompensationState(TState state, EndDefinition oneOf) - { - return !string.IsNullOrWhiteSpace(state.CompensatedBy); - } - - /// - /// Determines whether or not the specified state definition can be used for compensation - /// - /// The state definition to check - /// A boolean indicating whether or not the states needs to be compensated. Always true. - /// A boolean indicating whether or not the specified state definition defines a compensation state - protected virtual bool BeAvailableForCompensation(TState state, bool useForCompensation) - { - return true; - //TODO - //if (useForCompensation && this.Workflow.IsPartOfMainFlow(state)) - // context.AddFailure($"The state with name '{state.Name}' must not be part of the main control flow to be used as a compensation state"); - } - -} diff --git a/src/ServerlessWorkflow.Sdk/Services/Validation/SubflowReferenceValidator.cs b/src/ServerlessWorkflow.Sdk/Services/Validation/SubflowReferenceValidator.cs deleted file mode 100644 index 7fa5c08..0000000 --- a/src/ServerlessWorkflow.Sdk/Services/Validation/SubflowReferenceValidator.cs +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -using FluentValidation; - -namespace ServerlessWorkflow.Sdk.Services.Validation; - -/// -/// Represents the service used to validate s -/// -public class SubflowReferenceValidator - : AbstractValidator -{ - - /// - /// Initializes a new - /// - /// The the s to validate belong to - public SubflowReferenceValidator(WorkflowDefinition workflow) - { - this.Workflow = workflow; - this.RuleFor(w => w.WorkflowId) - .NotEmpty() - .WithErrorCode($"{nameof(SubflowReference)}.{nameof(SubflowReference.WorkflowId)}"); - } - - /// - /// Gets the the s to validate belong to - /// - protected WorkflowDefinition Workflow { get; } - -} diff --git a/src/ServerlessWorkflow.Sdk/Services/Validation/SwitchCaseDefinitionValidator.cs b/src/ServerlessWorkflow.Sdk/Services/Validation/SwitchCaseDefinitionValidator.cs deleted file mode 100644 index 4a8529d..0000000 --- a/src/ServerlessWorkflow.Sdk/Services/Validation/SwitchCaseDefinitionValidator.cs +++ /dev/null @@ -1,76 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -using FluentValidation; - -namespace ServerlessWorkflow.Sdk.Services.Validation; - -/// -/// Represents the base class of all services used to validate s -/// -/// The type of to validate -public abstract class SwitchCaseDefinitionValidator - : AbstractValidator - where TCondition : SwitchCaseDefinition -{ - - /// - /// Initializes a new - /// - /// The the to validate belongs to - /// The the to validate belongs to - protected SwitchCaseDefinitionValidator(WorkflowDefinition workflow, SwitchStateDefinition state) - { - this.Workflow = workflow; - this.State = state; - this.RuleFor(s => s.Transition!) - .Must(ReferenceExistingState) - .When(s => s.Transition != null) - .WithMessage((state, transition) => $"Failed to find the state '{transition.NextState}' to transition to"); - this.RuleFor(c => c.Transition) - .NotNull() - .When(c => c.End == null) - .WithErrorCode($"{nameof(DataCaseDefinition)}.{nameof(DataCaseDefinition.Transition)}") - .WithMessage($"One of either '{nameof(DataCaseDefinition.Transition)}' or '{nameof(DataCaseDefinition.End)}' properties must be set"); - this.RuleFor(c => c.End) - .NotNull() - .When(c => c.Transition == null) - .WithErrorCode($"{nameof(DataCaseDefinition)}.{nameof(DataCaseDefinition.End)}") - .WithMessage($"One of either '{nameof(DataCaseDefinition.Transition)}' or '{nameof(DataCaseDefinition.End)}' properties must be set"); - - } - - /// - /// Gets the the to validate belongs to - /// - protected WorkflowDefinition Workflow { get; } - - /// - /// Gets the the to validate belongs to - /// - protected SwitchStateDefinition State { get; } - - /// - /// Determines whether or not the specified state definition exists - /// - /// The name of the state definition to check - /// A boolean indicating whether or not the specified state definition exists - protected virtual bool ReferenceExistingState(TransitionDefinition transition) => this.Workflow.TryGetState(transition.NextState, out _); - - /// - /// Determines whether or not the specified state definition exists - /// - /// The name of the state definition to check - /// A boolean indicating whether or not the specified state definition exists - protected virtual bool ReferenceExistingState(string stateName) => this.Workflow.TryGetState(stateName, out _); -} diff --git a/src/ServerlessWorkflow.Sdk/Services/Validation/SwitchStateValidator.cs b/src/ServerlessWorkflow.Sdk/Services/Validation/SwitchStateValidator.cs deleted file mode 100644 index 0807a71..0000000 --- a/src/ServerlessWorkflow.Sdk/Services/Validation/SwitchStateValidator.cs +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -using FluentValidation; - -namespace ServerlessWorkflow.Sdk.Services.Validation; - -/// -/// Represents a service used to validate s -/// -public class SwitchStateValidator - : StateDefinitionValidator -{ - - /// - /// Initializes a new - /// - /// The to validate - public SwitchStateValidator(WorkflowDefinition workflow) - : base(workflow) - { - this.RuleFor(s => s.DataConditions) - .NotEmpty() - .When(s => s.EventConditions == null || !s.EventConditions.Any()) - .WithErrorCode($"{nameof(SwitchStateDefinition)}.{nameof(SwitchStateDefinition.DataConditions)}") - .WithMessage($"One of either '{nameof(SwitchStateDefinition.DataConditions)}' or '{nameof(SwitchStateDefinition.EventConditions)}' properties must be set"); - this.RuleForEach(s => s.DataConditions) - .SetValidator(state => new DataCaseDefinitionValidator(this.Workflow, state)) - .When(s => s.DataConditions != null && s.DataConditions.Any()) - .WithErrorCode($"{nameof(SwitchStateDefinition)}.{nameof(SwitchStateDefinition.DataConditions)}"); - this.RuleFor(s => s.EventConditions) - .NotEmpty() - .When(s => s.DataConditions == null || !s.DataConditions.Any()) - .WithErrorCode($"{nameof(SwitchStateDefinition)}.{nameof(SwitchStateDefinition.EventConditions)}") - .WithMessage($"One of either '{nameof(SwitchStateDefinition.DataConditions)}' or '{nameof(SwitchStateDefinition.EventConditions)}' properties must be set"); - this.RuleForEach(s => s.EventConditions) - .SetValidator(state => new EventCaseDefinitionValidator(this.Workflow, state)) - .When(s => s.EventConditions != null && s.EventConditions.Any()) - .WithErrorCode($"{nameof(SwitchStateDefinition)}.{nameof(SwitchStateDefinition.EventConditions)}"); - this.RuleFor(s => s.DefaultCondition) - .NotNull() - .WithErrorCode($"{nameof(SwitchStateDefinition)}.{nameof(SwitchStateDefinition.DefaultCondition)}"); - this.RuleFor(s => s.DefaultCondition) - .SetValidator(c => new DefaultCaseDefinitionValidator(this.Workflow, c)) - .WithErrorCode($"{nameof(SwitchStateDefinition)}.{nameof(SwitchStateDefinition.DefaultCondition)}"); - - } - -} diff --git a/src/ServerlessWorkflow.Sdk/Services/Validation/TransitionDefinitionValidator.cs b/src/ServerlessWorkflow.Sdk/Services/Validation/TransitionDefinitionValidator.cs deleted file mode 100644 index 211a466..0000000 --- a/src/ServerlessWorkflow.Sdk/Services/Validation/TransitionDefinitionValidator.cs +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -using FluentValidation; - -namespace ServerlessWorkflow.Sdk.Services.Validation; - -/// -/// Represents the service used to validate s -/// -public class TransitionDefinitionValidator - : AbstractValidator -{ - - /// - /// Initializes a new - /// - /// The the s to validate belong to - public TransitionDefinitionValidator(WorkflowDefinition workflow) - { - this.Workflow = workflow; - this.RuleFor(t => t.NextState) - .NotEmpty(); - } - - /// - /// Gets the the s to validate belong to - /// - protected WorkflowDefinition Workflow { get; } - -} diff --git a/src/ServerlessWorkflow.Sdk/Services/Validation/WorkflowDefinitionValidator.cs b/src/ServerlessWorkflow.Sdk/Services/Validation/WorkflowDefinitionValidator.cs deleted file mode 100644 index 471e8fe..0000000 --- a/src/ServerlessWorkflow.Sdk/Services/Validation/WorkflowDefinitionValidator.cs +++ /dev/null @@ -1,129 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -using FluentValidation; -using FluentValidation.Results; - -namespace ServerlessWorkflow.Sdk.Services.Validation; - -/// -/// Represents the service used to validate s -/// -public class WorkflowDefinitionValidator - : AbstractValidator -{ - - /// - /// Initializes a new - /// - /// The current - public WorkflowDefinitionValidator(IServiceProvider serviceProvider) - { - this.ServiceProvider = serviceProvider; - this.RuleFor(w => w.Id) - .NotEmpty() - .When(w => string.IsNullOrWhiteSpace(w.Key)); - this.RuleFor(w => w.Key) - .NotEmpty() - .When(w => string.IsNullOrWhiteSpace(w.Id)); - this.RuleFor(w => w.Name) - .NotEmpty(); - this.RuleFor(w => w.Version) - .NotEmpty(); - this.RuleFor(w => w.ExpressionLanguage) - .NotEmpty(); - this.RuleFor(w => w.Start!) - .Must(ReferenceExistingState) - .When(w => w.Start != null) - .WithMessage((workflow, start) => $"Failed to find the state with name '{start.StateName}' specified by the workflow's start definition"); - this.RuleFor(w => w.StartStateName!) - .Must(ReferenceExistingState) - .When(w => w.StartStateName != null) - .WithMessage((workflow, startState) => $"Failed to find the state with name '{startState}' specified by the workflow's start definition"); - this.RuleFor(w => w.Events) - .Must(events => events!.Select(s => s.Name).Distinct().Count() == events!.Count) - .When(w => w.Events != null) - .WithMessage("Duplicate EventDefinition name(s) found"); - this.RuleFor(w => w.Events) - .SetValidator(new CollectionPropertyValidator(this.ServiceProvider)) - .When(w => w.Events != null); - this.RuleFor(w => w.Functions) - .Must(functions => functions!.Select(s => s.Name).Distinct().Count() == functions!.Count) - .When(w => w.Functions != null) - .WithMessage("Duplicate FunctionDefinition name(s) found"); - this.RuleFor(w => w.Functions!) - .SetValidator(new FunctionDefinitionCollectionValidator()) - .When(w => w.Functions != null); - this.RuleFor(w => w.Retries) - .Must(retries => retries!.Select(s => s.Name).Distinct().Count() == retries!.Count) - .When(w => w.Retries != null) - .WithMessage("Duplicate RetryPolicyDefinition name(s) found"); - this.RuleFor(w => w.Retries) - .SetValidator(new CollectionPropertyValidator(this.ServiceProvider)) - .When(w => w.Retries != null); - this.RuleFor(w => w.Auth!) - .Must(auths => auths.Select(s => s.Name).Distinct().Count() == auths.Count) - .When(w => w.Auth != null) - .WithMessage("Duplicate AuthenticationDefinition name(s) found"); - this.RuleFor(w => w.Auth!) - .SetValidator(new CollectionPropertyValidator(this.ServiceProvider)) - .When(w => w.Auth != null); - this.RuleFor(w => w.States) - .NotEmpty(); - this.RuleFor(w => w.States) - .Must(states => states.Select(s => s.Name).Distinct().Count() == states.Count) - .When(w => w.States != null) - .WithMessage("Duplicate StateDefinition name(s) found"); - this.RuleFor(w => w.States) - .SetValidator(new WorkflowStatesPropertyValidator(this.ServiceProvider)) - .When(w => w.States != null); - } - - /// - /// Gets the current - /// - protected IServiceProvider ServiceProvider { get; } - - /// - public override FluentValidation.Results.ValidationResult Validate(ValidationContext context) - { - FluentValidation.Results.ValidationResult validationResult = base.Validate(context); - if (context.InstanceToValidate.States != null - && !context.InstanceToValidate.States.Any(s => s.End != null)) - validationResult.Errors.Add(new ValidationFailure("End", $"The workflow's main control flow must specify an EndDefinition")); - return validationResult; - } - - /// - /// Determines whether or not the specified references an existing state definition - /// - /// The to validate - /// The to check - /// A boolean indicating whether or not the specified state definition exists - protected virtual bool ReferenceExistingState(WorkflowDefinition workflow, StartDefinition start) - { - return workflow.TryGetState(start.StateName, out _); - } - - /// - /// Determines whether or not the specified references an existing state definition - /// - /// The to validate - /// The name of the start state definition - /// A boolean indicating whether or not the specified state definition exists - protected virtual bool ReferenceExistingState(WorkflowDefinition workflow, string startStateName) - { - return workflow.TryGetState(startStateName, out _); - } - -} diff --git a/src/ServerlessWorkflow.Sdk/Services/Validation/WorkflowSchemaValidator.cs b/src/ServerlessWorkflow.Sdk/Services/Validation/WorkflowSchemaValidator.cs deleted file mode 100644 index 34663ba..0000000 --- a/src/ServerlessWorkflow.Sdk/Services/Validation/WorkflowSchemaValidator.cs +++ /dev/null @@ -1,148 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -using JsonCons.Utilities; -using Microsoft.Extensions.DependencyInjection; -using System.Collections.Concurrent; - -namespace ServerlessWorkflow.Sdk.Services.Validation; - -/// -/// Represents the default implementation of the interface -/// -public class WorkflowSchemaValidator - : IWorkflowSchemaValidator -{ - - /// - /// Initializes a new - /// - /// The service used to create s - public WorkflowSchemaValidator(IHttpClientFactory httpClientFactory) - { - this.HttpClient = httpClientFactory.CreateClient(); - SchemaRegistry.Global.Fetch = GetExternalJsonSchema; - } - - /// - /// Gets the service used to perform HTTP requests - /// - protected HttpClient HttpClient { get; } - - /// - /// Gets a containing the loaded Serverless Workflow spec s - /// - protected ConcurrentDictionary Schemas { get; } = new(); - - /// - public async Task ValidateAsync(WorkflowDefinition workflow, CancellationToken cancellationToken = default) - { - if (workflow == null) throw new ArgumentNullException(nameof(workflow)); - var jsonDocument = Serialization.Serializer.Json.SerializeToDocument(workflow)!; - var jsonSchema = await this.GetOrLoadSpecificationSchemaAsync(workflow.SpecVersion, cancellationToken).ConfigureAwait(false); - if (workflow.Extensions?.Any() == true) - { - var jsonSchemaElement = Serialization.Serializer.Json.SerializeToElement(jsonSchema)!.Value; - var jsonSchemaDocument = Serialization.Serializer.Json.SerializeToDocument(jsonSchema)!; - foreach (var extension in workflow.Extensions) - { - var extensionSchemaElement = await this.GetExtensionSchemaAsync(extension, cancellationToken); - jsonSchemaDocument = JsonMergePatch.ApplyMergePatch(jsonSchemaElement, extensionSchemaElement); - } - jsonSchema = Serialization.Serializer.Json.Deserialize(jsonSchemaDocument)!; - } - var evaluationOptions = EvaluationOptions.Default; - evaluationOptions.OutputFormat = OutputFormat.List; - return jsonSchema.Evaluate(jsonDocument, evaluationOptions); - } - - /// - /// Loads the Serverless Workflow - /// - /// The Serverless Workflow - protected virtual async Task GetOrLoadSpecificationSchemaAsync(string specVersion, CancellationToken cancellationToken = default) - { - if (this.Schemas.TryGetValue(specVersion, out var schema) && schema != null) return schema; - using var response = await this.HttpClient.GetAsync($"https://serverlessworkflow.io/schemas/{specVersion}/workflow.json", cancellationToken).ConfigureAwait(false); - using var stream = await response.Content.ReadAsStreamAsync(cancellationToken).ConfigureAwait(false); - schema = await JsonSchema.FromStream(stream).ConfigureAwait(false); - schema = schema.Bundle(); - this.Schemas.TryAdd(specVersion, schema); - return schema; - } - - /// - /// Retrieves the JSON content of the specified 's schema - /// - /// The that defines the referenced JSON schema - /// A - /// The JSON content of the specified schema - protected virtual async Task GetExtensionSchemaAsync(ExtensionDefinition extension, CancellationToken cancellationToken = default) - { - if (extension == null) throw new ArgumentNullException(nameof(extension)); - var uri = extension.Resource; - if (!uri.IsAbsoluteUri) uri = this.ResolveRelativeUri(uri); - string json; - if (uri.IsFile) - { - json = await File.ReadAllTextAsync(uri.LocalPath, cancellationToken); - } - else - { - using HttpResponseMessage response = await this.HttpClient.GetAsync(uri, cancellationToken); - json = await response.Content?.ReadAsStringAsync(cancellationToken)!; - } - return Serialization.Serializer.Json.Deserialize(json); - } - - /// - /// Retrieves the at the specified - /// - /// The of the external to retrieve - /// The referenced by the specified - protected virtual JsonSchema GetExternalJsonSchema(Uri uri) - { - using var response = this.HttpClient.GetAsync(uri).ConfigureAwait(false).GetAwaiter().GetResult(); - using var stream = response.Content.ReadAsStream(); - using var streamReader = new StreamReader(stream); - return JsonSchema.FromText(streamReader.ReadToEnd()); - } - - /// - /// Resolves the specified relative - /// - /// The relative to resolve - /// The resolved - protected virtual Uri ResolveRelativeUri(Uri uri) - { - if (uri == null) throw new ArgumentNullException(nameof(uri)); - var localPath = uri.ToString(); - if (localPath.StartsWith("//") || localPath.StartsWith("\\\\")) localPath = localPath[2..]; - return new Uri(Path.Combine(AppContext.BaseDirectory, localPath)); - } - - /// - /// Creates a new - /// - /// A new - public static WorkflowSchemaValidator Create() - { - var services = new ServiceCollection(); - services.AddLogging(); - services.AddHttpClient(); - services.AddSingleton(); - services.AddSingleton(provider => provider.GetRequiredService()); - return services.BuildServiceProvider().GetRequiredService(); - } - -} \ No newline at end of file diff --git a/src/ServerlessWorkflow.Sdk/Services/Validation/WorkflowStatesPropertyValidator.cs b/src/ServerlessWorkflow.Sdk/Services/Validation/WorkflowStatesPropertyValidator.cs deleted file mode 100644 index 2913226..0000000 --- a/src/ServerlessWorkflow.Sdk/Services/Validation/WorkflowStatesPropertyValidator.cs +++ /dev/null @@ -1,87 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -using FluentValidation; -using FluentValidation.Results; -using FluentValidation.Validators; -using ServerlessWorkflow.Sdk.Models; -using System; -using System.Collections.Generic; -using System.Linq; - -namespace ServerlessWorkflow.Sdk.Services.Validation; - - -/// -/// Represents the service used to validate a workflow's state definitions -/// -public class WorkflowStatesPropertyValidator - : PropertyValidator> -{ - - private static readonly Dictionary> StateValidatorTypes = typeof(WorkflowDefinitionValidator).Assembly.GetTypes() - .Where(t => !t.IsAbstract && !t.IsInterface && !t.IsGenericType && t.IsClass && t.GetGenericType(typeof(StateDefinitionValidator<>)) != null) - .GroupBy(t => t.GetGenericType(typeof(StateDefinitionValidator<>))!.GetGenericArguments().First()) - .ToDictionary(g => g.Key, g => g.AsEnumerable()); - - /// - /// Initializes a new - /// - /// The current - public WorkflowStatesPropertyValidator(IServiceProvider serviceProvider) - { - this.ServiceProvider = serviceProvider; - } - - /// - public override string Name => nameof(WorkflowStatesPropertyValidator); - - /// - /// Gets the current - /// - protected IServiceProvider ServiceProvider { get; } - - protected override string GetDefaultMessageTemplate(string errorCode) => "Failed to validate the state"; - - /// - public override bool IsValid(ValidationContext context, List value) - { - var index = 0; - foreach (var state in value) - { - if (!StateValidatorTypes.TryGetValue(state.GetType(), out var validatorTypes)) continue; - var validators = validatorTypes!.Select(t => (IValidator)Activator.CreateInstance(t, context.InstanceToValidate)!); - foreach (IValidator validator in validators) - { - var args = new object[] { state }; - var validationMethod = typeof(IValidator<>).MakeGenericType(state.GetType()) - .GetMethods() - .Single(m => - m.Name == nameof(IValidator.Validate) - && m.GetParameters().Length == 1 - && m.GetParameters().First().ParameterType != typeof(IValidationContext)); - var validationResult = (FluentValidation.Results.ValidationResult)validationMethod.Invoke(validator, args)!; - if (validationResult.IsValid) continue; - foreach (var failure in validationResult.Errors) - { - failure.PropertyName = $"{nameof(WorkflowDefinition.States)}[{index}].{failure.PropertyName}"; - context.AddFailure(failure); - } - return false; - } - index++; - } - return true; - } - -} diff --git a/src/ServerlessWorkflow.Sdk/Services/Validation/WorkflowValidationResult.cs b/src/ServerlessWorkflow.Sdk/Services/Validation/WorkflowValidationResult.cs deleted file mode 100644 index 8a042c9..0000000 --- a/src/ServerlessWorkflow.Sdk/Services/Validation/WorkflowValidationResult.cs +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace ServerlessWorkflow.Sdk.Services.Validation; - -/// -/// Represents the default implementation of the -/// -public class WorkflowValidationResult - : IWorkflowValidationResult -{ - - /// - /// Inherits a new - /// - protected WorkflowValidationResult() { } - - /// - /// Inherits a new - /// - /// An containing the schema-related validation errors that have occured while validating the read - /// An containing the Serverless Workflow DSL-related validation errors that have occured while validating the read - public WorkflowValidationResult(IEnumerable>? schemaValidationErrors, IEnumerable>? dslValidationErrors) - { - this.SchemaValidationErrors = schemaValidationErrors; - this.DslValidationErrors = dslValidationErrors; - } - - /// - public virtual IEnumerable>? SchemaValidationErrors { get; } - - /// - public virtual IEnumerable>? DslValidationErrors { get; } - - /// - public virtual bool IsValid => this.SchemaValidationErrors?.Any() != true && this.DslValidationErrors?.Any() != true; - -} diff --git a/src/ServerlessWorkflow.Sdk/Services/Validation/WorkflowValidator.cs b/src/ServerlessWorkflow.Sdk/Services/Validation/WorkflowValidator.cs deleted file mode 100644 index f40e24e..0000000 --- a/src/ServerlessWorkflow.Sdk/Services/Validation/WorkflowValidator.cs +++ /dev/null @@ -1,96 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -using FluentValidation; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Logging; -using ServerlessWorkflow.Sdk.Services.IO; - -namespace ServerlessWorkflow.Sdk.Services.Validation; - -/// -/// Represents the default implementation of the interface -/// -public class WorkflowValidator - : IWorkflowValidator -{ - - /// - /// Initializes a new - /// - /// The service used to perform logging - /// The service used to resolve external definitions referenced by s - /// The service used to validate s - /// An containing the services used to validate Serverless Workflow DSL - public WorkflowValidator(ILogger logger, IWorkflowExternalDefinitionResolver externalDefinitionResolver, IWorkflowSchemaValidator schemaValidator, IEnumerable> dslValidators) - { - this.Logger = logger; - this.ExternalDefinitionResolver = externalDefinitionResolver; - this.SchemaValidator = schemaValidator; - this.DslValidators = dslValidators; - } - - /// - /// Gets the service used to perform logging - /// - protected ILogger Logger { get; } - - /// - /// Gets the service used to resolve external definitions referenced by s - /// - protected IWorkflowExternalDefinitionResolver ExternalDefinitionResolver { get; } - - /// - /// Gets the service used to validate s - /// - protected IWorkflowSchemaValidator SchemaValidator { get; } - - /// - /// Gets an containing the services used to validate Serverless Workflow DSL - /// - protected IEnumerable> DslValidators { get; } - - /// - public virtual async Task ValidateAsync(WorkflowDefinition workflowDefinition, bool validateSchema = true, bool validateDsl = true, CancellationToken cancellationToken = default) - { - workflowDefinition = await this.ExternalDefinitionResolver.LoadExternalDefinitionsAsync(workflowDefinition, new(), cancellationToken); - IEnumerable>? schemaValidationErrors = null; - if (validateSchema) - { - var evaluationResults = await this.SchemaValidator.ValidateAsync(workflowDefinition, cancellationToken).ConfigureAwait(false); - if(!evaluationResults.IsValid) schemaValidationErrors = evaluationResults.GetErrors(); - } - var dslValidationErrors = new List>(); - if (validateDsl) - { - foreach (var dslValidator in this.DslValidators) - { - var validationResult = await dslValidator.ValidateAsync(workflowDefinition, cancellationToken); - if (validationResult.Errors != null) dslValidationErrors.AddRange(validationResult.Errors.Select(e => new KeyValuePair(e.PropertyName, e.ErrorMessage))); - } - } - return new WorkflowValidationResult(schemaValidationErrors, dslValidationErrors); - } - - /// - /// Creates a new default instance of the interface - /// - /// A new - public static IWorkflowValidator Create() - { - var services = new ServiceCollection(); - services.AddServerlessWorkflow(); - return services.BuildServiceProvider().GetRequiredService(); - } - -} diff --git a/src/ServerlessWorkflow.Sdk/StateType.cs b/src/ServerlessWorkflow.Sdk/StateType.cs deleted file mode 100644 index 3363a09..0000000 --- a/src/ServerlessWorkflow.Sdk/StateType.cs +++ /dev/null @@ -1,78 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace ServerlessWorkflow.Sdk; - -/// -/// Enumerates all types of states -/// -public static class StateType -{ - - /// - /// Indicates an operation state - /// - public const string Operation = "operation"; - - /// - /// Indicates a sleep state - /// - public const string Sleep = "sleep"; - - /// - /// Indicates an event state - /// - public const string Event = "event"; - - /// - /// Indicates a parallel state - /// - public const string Parallel = "parallel"; - - /// - /// Indicates a switch state - /// - public const string Switch = "switch"; - - /// - /// Indicates an inject state - /// - public const string Inject = "inject"; - - /// - /// Indicates a foreach state - /// - public const string ForEach = "foreach"; - - /// - /// Indicates a callback state - /// - public const string Callback = "callback"; - - /// - /// Gets all supported values - /// - /// A new containing all supported values - public static IEnumerable GetValues() - { - yield return Operation; - yield return Sleep; - yield return Event; - yield return Parallel; - yield return Switch; - yield return Inject; - yield return ForEach; - yield return Callback; - } - -} diff --git a/src/ServerlessWorkflow.Sdk/SwitchCaseOutcomeType.cs b/src/ServerlessWorkflow.Sdk/SwitchCaseOutcomeType.cs deleted file mode 100644 index b7fe40f..0000000 --- a/src/ServerlessWorkflow.Sdk/SwitchCaseOutcomeType.cs +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace ServerlessWorkflow.Sdk; - -/// -/// Enumerates all types of conditions -/// -public static class SwitchCaseOutcomeType -{ - - /// - /// Indicates a transition condition - /// - public const string Transition = "transition"; - - /// - /// Indicates an end condition - /// - public const string End = "end"; - -} diff --git a/src/ServerlessWorkflow.Sdk/SwitchStateType.cs b/src/ServerlessWorkflow.Sdk/SwitchStateType.cs deleted file mode 100644 index 62f5e1d..0000000 --- a/src/ServerlessWorkflow.Sdk/SwitchStateType.cs +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace ServerlessWorkflow.Sdk; - -/// -/// Enumerates all types of switch states -/// -public static class SwitchStateType -{ - - /// - /// Indicates a data switch - /// - public const string Data = "data"; - - /// - /// Indicates an event switch - /// - public const string Event = "event"; - -} diff --git a/src/ServerlessWorkflow.Sdk/ActionExecutionMode.cs b/src/ServerlessWorkflow.Sdk/TaskExecutionMode.cs similarity index 71% rename from src/ServerlessWorkflow.Sdk/ActionExecutionMode.cs rename to src/ServerlessWorkflow.Sdk/TaskExecutionMode.cs index 627a828..adda773 100644 --- a/src/ServerlessWorkflow.Sdk/ActionExecutionMode.cs +++ b/src/ServerlessWorkflow.Sdk/TaskExecutionMode.cs @@ -1,4 +1,4 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors +// Copyright © 2024-Present The Serverless Workflow Specification Authors // // Licensed under the Apache License, Version 2.0 (the "License"), // you may not use this file except in compliance with the License. @@ -14,19 +14,18 @@ namespace ServerlessWorkflow.Sdk; /// -/// Enumerates all types of actions +/// Exposes the default task execution modes /// -public static class ActionExecutionMode +public static class TaskExecutionMode { /// - /// Indicates a sequential execution of actions + /// Gets the 'concurrent' task execution mode /// - public const string Sequential = "sequential"; - + public const string Concurrent = "concurrent"; /// - /// Indicates a parallel execution of actions + /// Gets the 'sequential' task execution mode /// - public const string Parallel = "parallel"; + public const string Sequential = "sequential"; } diff --git a/src/ServerlessWorkflow.Sdk/Usings.cs b/src/ServerlessWorkflow.Sdk/Usings.cs index d239661..a011d2a 100644 --- a/src/ServerlessWorkflow.Sdk/Usings.cs +++ b/src/ServerlessWorkflow.Sdk/Usings.cs @@ -1,4 +1,4 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors +// Copyright © 2024-Present The Serverless Workflow Specification Authors // // Licensed under the Apache License, Version 2.0 (the "License"), // you may not use this file except in compliance with the License. @@ -11,14 +11,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -global using Json.Schema; -global using ServerlessWorkflow.Sdk.Serialization.Json; -global using System.ComponentModel; -global using System.ComponentModel.DataAnnotations; global using System.Runtime.Serialization; -global using System.Text.Json; -global using System.Text.Json.Nodes; global using System.Text.Json.Serialization; -global using YamlDotNet.Core; global using YamlDotNet.Serialization; -global using ServerlessWorkflow.Sdk.Models; +global using System.ComponentModel.DataAnnotations; +global using Neuroglia; \ No newline at end of file diff --git a/src/ServerlessWorkflow.Sdk/icon.png b/src/ServerlessWorkflow.Sdk/icon.png deleted file mode 100644 index 3a8c828d9c4dfc34f0d5b0d50a794a1a3f0f6f9e..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 38143 zcmeFZRaBK>7cTk%!U91+5dmpIK#&j>7hNKtgh(lkbhAK08flPFlukjqyStQ@?(UZE z^M3g6fA5QZv&Y$EoSSpuK$dUJeCB-ToJ+sgGU7L`-@Oh&&<#n6=WihB+8q1`8w-5$ zm~?Lf{J^o4cxMekY;^D+H2a@|wh%-ENj?`=u#Z`v5VW8ls(yCV7wl)@gl4hiyRaRuk#C9Xf%37*R2F`gqH#00^r?x(4WWdxybqD7p zPhl$EY_S2!5R`Dg0SW&!^y9#Xf2!R3i~)YQh5euX^Dm$4Hy~)^T^B+wJLpxzZ zr+tlm`WX}wET^a#Mh;HSi;>O|!Dh@o57qD@lxf{Dlnf~_OQ zb2%CW^pUUy4XO*P))OBeJG14}XUe4@MjAgG0pW$iOqOVINB38b<8SUvIaS9YKG^^w9@Q*H240J#YU)cD>2UcdIk zorcX&8PiSs79dziG_3F!${AZ!^wMU(p1`&Rt*#E1Vgee9WXz_qnD1>DL+T&`@)jjU zKu~9yU*$-YEg69)1YrrmpOE`k4&j%)72lnMv}jpIih`}=?n=;e1iotXh&q1ZnMBgMS%vV97Xnj1Nk||%{HlyC9A!Wa^*q*xFEarO)5e~OM(dw{hdt8+I9(>; z1-offx)=zso>-f)*GJkx9QLq0kEq|o64`}^0;!I7hhsq>|D*tqy3A+E5!joyax1nc z78xGMxelFc!BmX|_)y{%|Fq^w7*vHM;$Q;2hvH6BJj!+npydegyIU5kL1?D^aD9(@ z3#A(*F&z{bK7<3|o5&rYI;Dn1ZemcQjv{W!R_;_DlvM7XvD|4=-01 zjR!ROfK6rb>^C59S)e>2+gWWaakAXAeJie!jrujnZ5@_K+e^Nt>3h41@h!3LkWf2p zU-Jw@2mQ||fpEt~B_YGuJ_R(Wt;LEfoq!#gKP&im3`n|2JQo3BNyF#f`6n&%%yS}k z5$w~s<5|6K4H5|NE0-cLVGBSYHtqP^mC{ihTDARc8?-ta9Qa;$Zq(L+C3iH%;V~w9 z-D{W@(jp+myCTSf-&;1o18p5I?xN9rgr$sSa^-?Cq!m#{JOBt#c@mmut-i4B2*z;RfI)`i$zs#fIYU7E-3D?rH-TQD)H*HL+z1*KdRaxAwLBLHwTl0eH(JS~m(RSua;G6lNVoiT*yV9%%FZXeMV^qltW zHkT^K!l*lk#V+yXpx=Ch)qqHw2^#l+g_sPu%H+W-FplL7W*k9>OgJ8cPj#ENm&jQL z$@kC7V8`M-6oKk8u1>`P_qo5*t9~5F+6dM8!v>Sw5L4#DFfE`Kv9vO%H3IlZ43o6XyOC}*9Kbk%4sFo@x)Vy@ zmlYa#eMQ}pt-^#hwe*3Ks&9+NT4c#stsbK)VFTOr0>F?D6FLcE3xNpsGbIMe#a6Vs zD=%NBv!4B9dt0^+6PiqrCWhQJ{Ajy=DoSenuk^&i{<8Oj9EzEdP0Okm<_>1C3eMI^*E}#ny7Nw&@J&~kcYAWug{TmrRfEOdc3ymgh zVn>ILVN>t%3LyO*k_zLF=>}Tc z7ueZUh(#lE75E*2($oQ-&bPpJq_V5x$lTBR``L&x+CP^!>ZRV~uQrQt#&SNdXk zzigF0TGea;qOZIc8Vv#_r^Niq=V}yFa~CXpp3bW4P>zbEa=W{#8;M|uhg8xnzB@d9CX@9M}< z+!zgD+(EBPfc?wxj~Jd@0uJNOa}9_T52oYEJ#PlhbcP#_|3J9z^)MN5%$B0m0WGk_dy(JFW1Y!7f^%j~mB@B;jySH~OCR@Au!mUqG0G z6_eZsD`xNq|97g079uA!8g5t|gEmBsgv)<~`F@c=Uw^=6`@MO4?oIRZmnmRksduiq zDZpI5{dHxsPMIou9sdzWvPd*D1a0ZbQ1F+K$R1$2(O)fW7Q^FD2$q?}sfBtRM*)c2 zr;=JZ{d~DMo=Mn{W2*?Abis6NCi8#yl$w(St4v@zCV^TgLOyxe&$2^%VX&YlnZ56Z zXNZ1s;RVjDf`m>aV0@DWz;RC4P|7U&BhHHuzcUykAs9B-Z90@p%!q2TDSI4*2UXJn zx0sd&oKq^&q8NARwV-8Upqmi)A6d3Kbyl~hHil?D`^E};t=GEO-rMhd|G`0+D}r4K zGL~f`fEilT{skEZuKdodzPLM@f`ONUNA(~UiH?~JXbGjL>d9$8BImaTp{`cUSCEG3?X(P5UqswZMM5{md!agT>xIMY9Asp>V?!>h(4hu zSOdmMbJmD`wyAIHE%euaZVs8{JLKW8AKFO<1jFeNRvJ^LxJ8GrW4!h5+~3=cIF)q2 z>NT+IJwOm({EXq|{&8cz-$p%}I{arQvEAzi!k8u^5442G@X2w9oqm-8>U5EQiA{~; zYeKd~ndm(aV6r7*&Pz(`d3hfE{+;s$4@h(ZsZ40K+bH=5og1nENw=H3@8hW`(uQ31 zrvyWXSG_ zp&v+-DrJH^dHLn;{@Zk|`JH(YImRnH~2jiw$O8)(W zp4R)U`TS3_%1%=QW5Xl9Uep{HuHKO5NnTYd6iBWR3(94C$C zfCbaPY4{4WPNF55__=H?yJ7{b-2k^WX=nOCth4gE#D<>8029Y~@H=Dj#-4O*?onx} zK~kzDaZtT#7lTdaO!@c8DE3)4PP99aDeMe>z8mS?jy++@rMIaj;{wOO^|7FrXMg03 zV=qd>5E7-BhM<+@cESsOjP8}B9VgVy#`jVC68vZhu;)t%$tmqiWhGHn{|Wt(6{LK0 zC_Hwpx%1>bpJtYo5IU514_L~cnw-)p{|(X{owbL1E%r5Keux`ApUG{mx#eu74qG=<q6#NhpZTAesru-qus>R^uhDbD+4bXEW+Cga%?hKn^!5rr*Ybo|Xa$#buwj za3IJ&5S+nt#~|xQesLd2gCTqP&>Z^KAr-#; z4VhWTYarpp1VnvEWy+kecUbKK2?*o{D{ms*qs$0vKOX-B0~L4*!AUJ8)9+P~RE5ZG z5X?GafutOkv7Xqw4Ie_b$62R(PFoNZ0<&1e)FsodEi|+>a?sugEcD zZn_3(EyJWI{K%3K#TGYqut4N{Lm1^_D0MNaznB)lzU&e$2py zqR2$K8Z7~SHN2JoM~02bMBIdL4>M5LmAwwW{zpkCk2RnKm9j+%xuL=0^?x6b9Lisr zst#hWE-X2l#isp61ty@S3|P{ieq>R35eD^VJi`Zq?5xHHsjoP&mMyt&iu_GyFJm2+ z3Yap_#{=qQL53ZV3sPCIZQJG9sJvtQ8FI440R5k1REf$dkpKZbUCnkdV}o-#Xay#K z@}H(MWw&C18^k!?1PMEA-;?)B1T-?GIYHQfLaqTms?;f)HqxXyQ&1(;AVZCU*8r}P z2phgs&@Ux0W%i8+0PCv-OiVuoX6sFu(@*~{9QE*!jO4&?gRjm zknh78_GSZxKVcQhzzd~;px*AAO3!5p0aWtjz;`pft+&tQX{p;>Xa_`Qv?&HkF;~Qb z-^{URej5|1-_a}1C550O00ly9=I;aUodv*RDgr^FZkkxn=BCJS;h(C+3n?{V8;}{e zn8OeV$D6P#o6`>I7Z3Di=moB-_hxDgC74U=i4yH$YQir(+6G~tOGQt8J z0`#QIZ1)cW>Q{USGH-Bi-88Upa*?uvf~=JvOqtGN7?4&pd_b?XDZi%;s4hWTYw+(c z|Cv(eZ~hHpJw0XMk*WYVwK)EnlByinhg*WLfIg7GY&-yq7_8n;mKj`90M~NhdhZ|j zv$k0bHy#PX89Fe+kg9)Ho<)Cy7kHk692#W!74VV_u!mfP!!q8i9AL7h4fxm}eB3|L z6eco^1slPWmq1(v{sk2Pf!+z1nC3FERI-C*u+Zs&)JR2;r4B{&^e&5_8bk-~{wfd1 z$@cg#&ERqXYBQ67o#Zr_917OQFgbxhff9hfU=eI_rNAHxa7M-v1dW4ooty5JcsL~D zbJW4#EQmp6ivV!=pxiI}Q_p>vobhP*Uf@Ttwp8|-G~|?QjX*Tz0?VqEuOMLjW$$Cg zok9>-SOBQ>n1IBw=axk9L{m2t2n5doJ5vMMZoEoYE5@c8J)KapD%)%Zr zEdyVi2x2Z_gJ@>G5G)|$M7)Mby`w#bLV9T#N5Mx2!UEY{A9{R(0Y>N3Nhr&8BjrP z9Y8h9zZJ2y#rJ?*E_#D45FnjtLSmuzM8f_3@v@0$7jiZM8ljI1Z8c8~`YU(ha(3dK zPg?M6!XG_9`+}S^c~%n-9M;I1J)XD9AK}KQVa+(=(rT6vJhgjC(u4--8Y(D$w?SM5 zu6v%AIWDTZlFqBk8zT~#k6GaS@$E&RzuEdP`x>Ow89%6&7|LV1-58GxT;pHilu;#Qon=bmpnwSHFgJX&zdbV^ zAuR@hI|T69LxJ|@u|^~jT!#YuC2-3Q6u^mGofiBXEy!kF7K(trE!Tz?$Fb=H~r3kW`pPXO$ z?s5~09s<}UsOQ1?3&>l{MX;A1`DRjj5ystt(=z7-I$2@>f{6fA%Pak7#-dYbJ=cC@ z9aysy0!ljp@{ch8&cL6gs+l_@Mj>5w!MrYDz)oAbdry+StSCBsdL7e zb2H6)1ez^y_6_CT)TRjWa_sP{Y`=QyxQPn287A80} zWL9k6#>0Ac(`sRs=x%9Jvgz_`v>BJ#r~PwJ#hvzRTOe<&$lxeWQ>#xtQ8#JGyzj1vYniM8Q;I)`E zdRJOy7vtZh`#e|UWIOF*es@xlIRv8&WbLG1TPaH!q6%{?f4Hu99&OVpFL$DC7Eya&3DhxHebjiF2O}8gjvMf5&;keo;!FGAZF>pj@S{Hb z7K=%G=gKaSxg`z`A1d#MPNbrlO-D?Gd&k(UR+XYGK#KRsWZlKTVAR5L*fP|77LzS6 zQsBb5PZU&9zR=(g+D^>+2K(fPy0d2F3a+sQ5;oZF=#INOvu`$+Xq!O%G@m_KRp^*_ zuG8{8mDl0Vr5x^Ah$*X#phk42sn!-d7hbPT%=12)aOk({Tou|(M}&>t+~QxIm}lHN zLSTy}B0N!f>J}!_)$LEZ`t7L!bDga~+)<=x*wYzi<|Y#6FL*OFTOw0u8VZb{6=6_~BCO$0YM)KPgA zq@QfgV^4C0%xmX{9%1LR?&stq?aFWYir9ezFn4^+`nbhal(#@my%Q#TZai8XKsg){ zn=-!8pM!kcuBa)KK+kx~_?$ zor;BHaXgT`|C{L>7~V=mCmR!CCzr^-xY zzCSw?Bmyk^RtgJjNzRG2IGo@sU`lW1(^nQS!O06H~XS%44QdU)-P`9KEOYcrLDT) z^Omln73guU`njfEIhUZuWL z!uRTG@*#QPHAH}EC3uIrPH^&lLd9GNy&*{Y@7{8yue6`FCtUh<<8M>fQ5@Cb^v@?N ziMG)2umVkJ_S$m;ACa|L8wLNV?*wxgOIda?wY^~#8(Yu5&Bl*%O5HvjvJWP83HDP=?vAbVxqEiT;Fj!yiYR`mr3yFRpioZI!EDTYR?U*C z;j8L)(c1JL(D629>Uy|3)+x*%zMffDE%+<)p>oOu;;X_oiFM$;=Nsz;}gFB2{gtdv@T!aK{3;tcGNR9 z+EEUX*$3Nq+C9$Wk=CJkHXK<=S@d&qp|1FWDbODmVLT7j{nw45NZHLIM6MpODCk?0 zq>3~wQdN8;O#ywRs5T4Mz2?`sNvnr@$AlQ=_JJ2>;y(4&fe5ucpuAzJmx2oWm>qgC zjCR8wL%T}*Y&BHszD0UGb&SJ3nDqyBpnUDTaRwY`74JMGwA;tZUe@$gb}kybSrLQi(>b)ANGpIJo%L73U* zmG4r>Opq4LWVKdNo3U9KX)tQyL#_V#b)&L+A;hSrz7%Y z@VGYd6?`r#n8@5@xqe)tsti`9T9XLm<@+phr08)+&s*N2e{v5{vsFN3*S60P;`YW;4LFx;zloenA72N3HU_zNjfInOGd5*sw79VG*DY>V z8+8(@TcXwg8$TU2hMwZ(wx}rUoa(KP?T@{8p)l>5lDqsUgaJ00>&2H+wl$aZues-R z_n#9!0p+C3@*bIEk0Dj%t$_pLOKV%l>{j5G;~zBB@|cs^HGgKHZ#i z&@dvutO|-DJ%>68Tk0K~s41S|2r8B4xRh?ngbuOMU`DTj3If;CR+>RkYQt!UpX$`o zSe)G*0$hivU-+6+BR!BdMO8d?OyvNtbX=~L%8ZFDZZYjdaJh0``3cs+OG?LPjJt2Y zaHGh}KW`)j2CV&6d@-em;Nj8&ts;9LQclXWUfzLcrJBTg`$gs$_G3Ar_FulX_cfUD zSbbI8;_s}6aO}%|V_Yi%0}wGMfnEaM_kR*k zYs6I@P>+_bC8BCU5{lytiu31r4AY9|6L2;V=SW)trW6k5Bt7=VLU)|B5mK$Q9$l$9 zlH|M18zY8E+*T-QtF5D>p%*#Z zwZ$OcMsuS&M-6?{#(y5EwThQn@?Sq>{OnQcEBJ5}Z6%ZPSwXdasp4JyL4Hr~7PT@z znEKME1arRMiyM;dIoEUuqFp%xroHn_f9k7-MfF^Cge52 z54*;GYTK5ddWpDy?4HI9B*&jry%e zENVOI==r*kw1n?5il4}%mr=6XkSga-O4B*O4*A+#$y+TpbundK=W8^a!sDxI0S!@} zsBInF<}W{zkgp>ydQ`r}nOIwt=ztbE`QO-w+G_0`esprY`ecm`o+!d*`TZh{kPMdH zIR`P)@VIowQ&np-AIYzAflIilqNP9sx9qgBSh7GpamO>6@KY*xvguvBgEH(@_pw4b zXN*%&Se57zcH$6)XU7!z@`fpc!_rqnz-nh`MJmDh zz95zz61IHFCRHe#)=ldOUL){nOkNvZkKPAXqh6c+%i$+~vHD`uBQ0M1=b!9|TD}y@ z%ibeH0%6j01z8suN2SDV=5D-jG%lbDTnbn!CrM;oZ2ICZuYT9^nKs2ce_qP2YymP3 z!5nI;W_8BorMkZJ0dRCc8B6${)1x@{4ptLMJf@BXo#m8@C)4H)NUH@OcQwE)26z;O zkJf&*W$Sk-1>#($RW67#O0|fkOrD=joRYQY)utHnOFfO~7M1~Y16}n7+72X7U>8pT zjN2yV_lY5U;( zou^8Y4BdQ5I*e?Ij*vM;hkIH`ND6{!>Xs=hhl9)x7BO3-7Q(Kia(&hXp8dkpE6oy=(-f_`xTRAgPEA z3=0DnHNpO8tpMjle%NxJkyrR`MeoG~E#X!ss)9z(ccQbIZ2Zr!(9AOMKr=O!*7MaG z-qv1gnP@=JZM~lx>}HoPj$C)o%z?1qbaS6&AlSY3o%!R~W8y|Z2k$Jqu5y5Y_RymH z1^!oBRoj+FZ}V;1xD4%UGfA;}zaZ__iS}g&ZTOfB^WHmV^ax0^7p0akx{w^Hy4z*i zy^YVf$xYPqNLP9BL*2`N#v^yWJuL|wz5j^^xA8L<`OtksKFwk0KUA(Pc~O0df^DDd zZnivK~tY$|Qwr)2Cyqoti|TlHXe^Yn!P{Tiq{=Gn6PSwQNz&GYCUP3hWlL9p`He;t z6*3OC-d6H807S-rX2ua6@*UnQ0uWbL%O6WNFG1Sc6VpOYJADC|e#^IdiCnvvyuq|j z4!ZDGX$x%cG(Rr|BvLc|AqSNP+-z+fWvXkTV4}n0rs_3{FE=`Y<>|n+iv8{VtbmY` zOa)m#P(mdr8o$5hWs-Q%G$o1fu3t=94E+i=iCQI!L3j0B)LH=$?H`VYf-N~lrs}VH z0igWiq3R|9!9|38b}LDJz9%MBf%<*DGxi**r~UO{#?YRJz(r@|C|YD3R=JUq{41JW z4EswPX;)?dduqnmLGzTDPqfhP`fmo%G4gH*l^n+3o#U|uV%}6}N{($syr>3)tG4IW zjQ_;Efhxl>Z53v&jm!h%9=`&1dDIB&4*=BU1Dv1OJQ5oelTc;mmD<>o>|;UH6v0B~ zshn#ACY{_IO)mRM`xJ<6(ukr92>Hat8cc|-+KzfqRoxyuY>O$gjUYl~4@;UgVT}85 z1og){_!DIRM_}Q$we%Zlxx7;0g_4vUG2o$;S0mfHE0%%qqHm5t8V;nJ$au?;iWkfp z@tRX5@B^?}KQL7wFu0_L6_jDY*bG7;0w?|?s?uPG{^O{&3`LQ_YE)<<01(dIYYEQ( z*)ioL_^SeYCF+3VsKVE*D0$)gLH_}uE7sod`E^l-&vcSI-zW>s63D^&Ex9T(Mt(=< zNG}j_R!f#bVMgo#B*U@=#p>936xWQO=GoEGkAL;i5=)XD^|DM52!M?C4GEizp(*#F*a@F9%Zt@{RR^ zq`;p4F^aN+pM2oiLMses;%10ZFk(3+nyu^16UR=qq~XccG*#R_Q!6jg@^MOr&PN*X z@}i34ujj3kX5dy}{$!PQGhSESvq-(z$s>{fsWc3Mv9zqdwFb_-`=lIHUhX$rzTDER z>yiDBc(*<{e6_jx=c(CRiz|1uT7>KOWM$jBlGRbu_sc(%atH)JF@Q@%zyyidvircN zNlw8W$KY9M-jxxS-^Q8QNnjwh#-00cMB>j17`%^jyg5p^)D)SDeZDZm?(ql=QXBs< z$yc9FPyN>8XhZmcbc|s|$jNf&`zYhu6mX)z?rXr^T*UkK_W^9MX6J2Lzn{XS$wpG^J`4S^9`#4~9^UvPBO?y3%9(g3Il@01* zd!qJKD2&at9wqBAP9F8eR!rSj+&&)AbIbi{vd*f4rMD2N z_>?+w|HfDA+e@20aMXQOY4p{$zyGWmOa`)0$if)-V<$|{h54cyCySPqF~6AN>;2D3 zrL#udpixJ^@<;5A-RyWxuoa-nlGx7MVs#WFo1Pz3m~EYlXf9+T`7w?Dmc9aG1bdO} zZzZCEp8XpG<8@Wtilm>#YJw7~Osq&85PV6=ORXC#JiZ8J;jduv8&k63LY|N(yK@zG z6c(G3-Jr*KI7$iDuTBVr5AsQZc?vi`xv{g=Ud)iZ@!Lc54WP?zmLx+R#eoM@+;&zr zAKUun2HY1S@SOey5B(r}3o-Ng_no#aZhKp_YP*7`pExyl5t=u!A$-_|qEBTDS%pq= zhMZO{N@b%o$`Vb#*WLA=D@x?fgvT7JZ`Df3W?jbveYuGYj3@(c5*lrmQb%@!P|@1N z{|SSiMchHNevLxHpChPdC;685FL1t*vh<`J9^vNgG5KO-$_mKacAmg^F3pSA-DuOw zBQyl~esP9w^OqbC%ntnXhf``jRkuC$>eL&p=^;iAVC>0Ll+`csK<19coxeJZNXeTm zy^OYiko;sKXe#hwxZ5E6$Svxih4mK;aasnBUK+2fu~m4!DMLw#mRG0 zarUOU1^#qTzG2Ki*>j}mA#v45j>qvJDbA@)*X8GA%(2mLuFq4Cl#^oiM15d$(RO%) zb8NpXlFqx>dVlLIup9}7FGBZ#?Q_iKiY-bC-=SC(;sh+ze<#Oj>#DiG)wMB_hL0xD zxqnVjXG3WSgoMlM{B^IR^IqLx45^>Ub#N}Tz)vSbVlcQa^JPT zaz0D_Yf-9gqhE0dL1Ehpzcz*Xt}f}{`II!BQN_Lk*URwBW7qSw?u!sdvNwCZ_BGp} zA#fDCgm!IyCV`0sF%QpN@({^Za_6Ck{9FpFb_BtW=k^iPAy4vZp=MX3pn&CpoCwJK z0y2S5JlgkhI&w?}I{0u8-=dTS|L@-XfhqmxH9uIW`6u*X+wy7ele3k2O)GX$W{u|1 z&ns{XarBTXIfGaQcBy^JsF-uk7*Z zYZ}D62nTE_O`N&qPZ!Q@eUC|=pMxZ%B3;x2WN;bnn&;e3f(}3yC(9$C{Ru{BoQan7 zR7lzy8$q8V`>8YC=Oo3QfNhBZTHbwpPjM9D&biG@QT>ziT@Ov4_7#Kj@I(uZ5!9$A z%4NKEj27`OkIZutSXYS&vCqTUmRRh)2-|_8bF;sv+e7i^w1=E~znX#2tA}(@;(1|; zq&3w)vec$}!1$z!{I~C-xA%1Bnf((Fx>Pv?@JfX+;GN`m|eo}kniji!yFW-#dz+QI44Vp zTKw?7ZeU%i8Y7ZC4|nX=r;64ZX+|E3EP0|#rTL2LNhs$R-i^!EA8}9q$Zg&AnyAAduD!(HAoQ;1wu!({ztxgYyc4jYU_(ou3&=ACe#4TAm$LF- z>u)Tn^5qpL<8Y_I`_u37qJsXjj%v;<2}OvHJc3JCxYGDX&FS{DnRZR57)P>_8Q3=o z?_um{hXRE!Xv-;8@PKilpq6I#BD(KhrcSGM-h55ba-yq5`wQKI_^#BKY=@jrt^m>= zY2kDDaf7!<6o(Z5an}miX148xb$rAVS0c$UE3_+{Z5PGny1%r2zAU_{XV_4<}3_|tq;)mHpExl<+VkM~=AzlXh_ZJ>u<*5|k+Uq88p=3*q2c9NfT_F0z zBDXVysI8tu4a_M^5@+9P>5VwTTzv3oe#R$S4)E1^R`&dVF@Mt^a6E=%;D#^Biv zJdZ{S!&r_W26bc+S^ZZ+1R9d$SH^JqR7ULo3cq<8b*)ddycXBm-Os9Up zhSwkoW?I6&mSE2rK0lk~k&|v~pq?A&;IsoqW8mo$>qz-#@7(b2#ojb~dAPPZ`?}|> z^p4{;u9v$o$7#$U*yhj9*5(l^|1s2d;Q9Yz`dM?p^bI?g;JU&7;WW{A_j$_OdU^~@ z*@P|m`A1$h312zvWn>l@XUBy|a{NyIE>Zi`2D^qkk}2(gXN>*mWw@kI5Tz-GhvfnX zVwC2y4&6?`?;Iql0As3E>TtCV+n5}C2c}@46NvzX#hu%qo1af zcm~4bz%Nw(opKe>2r34ZxhdU^bPBvMN?KETssnA` zk3as4?`oewI_7oY#C4|@x42w*l+C}uY91K~7z#TQ(^aOx8w#-3@_;wuKe|*P?)z|@ zDd@8${%+Ed4`f$4)`n6sKaa(Uy>zAdll93xQCVxli8naj+OTxy(*&h}WKpJ5>Sdpx z;E_#Pj7!+qn2Vk`;~3#mE>92IACM`b8jynv0odMaUqaXVK zJsy%J=ujcvx{fW`KgCc>;Cenn?Y*rO)ajRGVv8%9J23Qs8fSJm418zTzrDJdNNG(S zACZAAx&0wn12n2HC|t~+{@LAKRXm!yICaIn+`p7Q;0prp&1TTIMx23x)Dz*uIAb9T zC%LJ)7NQVs7EjcZdy@(SiQ_^3A{P8Wyc?=iCt%p?M4_Gz_iNnc!sW4G_jWd zgdCpzDBOJVy|XU!3uj;2#Ph!mc3)bAp7eB0jN|r_WHn=s6JnAYPTxV356wy;N$K%0 z-Mptzz=Eg6Sxq)B{k)r6>ro|{R?qtwB#m|w+i#u%Lw~`^@GOTZ9vcDby5$c^GgW-z z4)6B)yLV%L80Yvfm!B$;U?n=ERc|z4c{6?HJ!)EPTG_fRZ>w?LTYD>TdTK7K*XExw z^1EO?PWn@%QT!L>v4&f(y1-=mvNTiq6sIiy;^sz0N2wWxsG@?jquXvBR`XJ&=J~;z z?ZC6B`YEq%UG2G^&hL0C$eu|s?ddS&ZMiYipSPx@cW@bZTW2+;n3QtX^bIxEF5|SGA${^4)gh*e)*B~N zlub8NgudM6PZQ*ueN;`D+Fi4&Jkou+?vdzpaByELTA=s(K!biw!$OhujCqM-$|t1v zOFaq?LVcYqo^uZtYj7bh$)(eK#<{)2OEujo!IS+e!P82>n(7xeTBoG6D9TuRj(l6G z_6%Ev_aG2)G}vsKJ=o!|L=T^BzCT>9RV5p1o&CG*;LI_q$M z8nZ^@X^F4x>&>NzmBdP$GthGC@;_z)+MVtf<=j=l?HjSv#?ZON%y(#N>~zr@f04PK zWOB)o+r3d4B8S6jdm+_0GTM$7eht<10+6n#(D^d$oAoX1B|v^+e?K{mQLeDz>5Yl}|;VB^}-d<0otQ%3nM17XCuhS?lN1gZxPPJW} z#!p5p7`QU|>NF`e%#bJNWV^XkR^z=U6z@=Ix#{(qGGEV)wQ3P%xaHmZ=H{*3XSHX0 zYsaX^d8K(M`^WqH`s2WG2p9zlI_WcRBt27CXnC9VneO^Vy13&>Z`>!(K0=ytQawtE zI{&Q;r1L>+?QfS01M0o=kuj1dBwQR0Hjx%lnNmNf4Bpww6ShWxy)S3Nsuit0B_g;{ z^gq+04ulqoDydRyFPH9}Ui9Xko~&E2n^KquJK@Zj=o@{FsOAW2#zuc3PAXp1pt!Yx zGs9mg@oCb=vNngT7Lr5E)Q=R?h|@#o>LJJc0t+jf{J`i?{j zoxUznr$V+}MPZ5uugO}|JO>99cjrm-slmmoK#o59m-qHY zMQgg8fG>-(466?#t71=hM3A251k2|1wWLkUG(|}cCHEyq707;8bi{i_stA6-ivZQCof;kh&TIRq-$oxf{nw9nVm8HrA7!{rdve4rq%Wyrb*Lec!qLob2~#h3QZJcLmq!JqPDTzJwC`Gqq;dY)Y$Yt7pxheNtD*Px zumBgw*w(zT|9C2FU*?m@Nshx%c#u$F@j|L*cQ9}BW<$%&M*k3kVSy8YHI1-| z6fC}JDPWed-H`Fe1?#yZvs%#BUx_Pkx#)|xh&kKduuBxhi3nOkEUqNd;4^?h2M+PB zX;m!U`)85YQV1_5u`TZHx4Ry@>Ry`7Oi^5JgI>?K20i@XEOKj0!bK|#BG64|S-i_} z&0N-t1)K4&c}Gyc&(P)6I>GV&L8G9`Fmg{FJG^l74f$f7Svm*!KGn4u`kRZAj?5ou zVmh`|+KqV|dZSl7q750op{nY?SnZ92?%*mkfHfYfLYtnRtBJ`JKcum$v!QzgK3F^y2y}-WW zhwUYAG_RHUb9gAV3lv(lziga`*OMPbgp236`e)-0vjnAVol!ekYwqLN`Hr0a(>&4U-ae5cdLyh=!o!+?yP zQ!=)6w%r5ocE-VAvYRdSp5UI<+e_ZXTKG!pqmc4YmmhCt_Ku_Grk>zMqmL4|#+cXu zDIR{f!ELO(`$WtAR@IpQ1EQ z1Y)tIZh$hIwPeGefNhuEA?afrKv~L4!rW7_fpHnwEXiWKC?Ur+Sc=h2&Biz~I4Kae0RGuKRzj2tr+rIGB(ntKnAgJr{JJ{+C z%)AKLblT~=5^YcuELy$+RL7^ohe*&-(KV9O!&hjoCx*|RnmDXbX{~jmp9?~HOiq(~_-|FsJeJ;JZx8pjVic=I`+emS5Bm?vGF?3b4V&S0i%!Smi^W4~ zeG8Z4l`283@Ip0(K#ZFauhW9YN;UT8!*Fe<#{e-c>3D^+o@8t@hGzL@>`ok>#eF$< ztAYI?Jw1MXv`v()37#RH0|m6M7J6@O-x95hy(tr57`~ttNA7x75-zxYRdjPVqz}_Hhp{X7q;}pZM02{uCS1uZ)ip(Y0&oc|W_H?njGHm5^%ACG zDq1x^Yi#Naz!FHnDeD+#ZiNM8JR-nlBgDURm`%jLErSK>mkLL-sTPQtJDge~usx1V zdqfPrg6+`1v2L<&*FE)X((rcB^Hl(mnJ^#;4G22>>dQRb zlOz=f)&D(dFH9*Aeo#gaT@5;d1125ho<5V;yoP+Gz9?JxaI8@1L+3aWI1-lT!JZNO zI1iSTK1&f!Py-x*T=tr~O|P)AS)sKTv1LFnOWK+iNz#gEFX4p)U?nFwpMQZdK35Mm zN0{(DV2)cTWOO-d4>ufxkTu1CPwK8Am!m1Qzek{Lx!l6|U@GW}uZ zo=h!Ir2-#19PdiPt6wIpw419hc4x80Y=MAm z9;SEr<{iUEhFqn*LZ>l^#s(a`K{-IwQ5-?NoR?m4=?QMQK%s0u59}5K7e5}<@7loz zo@|pXZ^=9Xedx4fg%8%RnO+G9AlKqlO+06R0A5!%2TANMi@_3bRCyrstS+uNQS=#{ z4V{0LViBI-jNoC(k_GGJwELozF zt&pUIEJgN^Eqj^}#aLSGBl}W}WG$lS+&s;qL%ln*b zJfQ74P4Lq13v1JfPthqdw4dzBqq*JZznyXAYadkPh&}c>=ZtNA)>{Qs5Jk?><-dIJ z+taA-8fAAqY%YkU96AdMGMAZ`N_fg<5)-!^34QYA{*|ppR1gOL*<_7eG^$ReE-GW{ zUCe^g9S1nBXhh-z;*Q$m9i|?IH^_5EEW0T%`%nFse1@vH&tPNQ%#?&n9#-n4fmKW} z*}LH}D#Y38TTxm4Y1-iN>`=uEZR&rR4nLuAN5AIn6H|r>9&y|6EA~niE{F(9x#V2G zTDd1PJ9hZ^DF^8}o4sSZiwagq>*9b?J7!+|A%}G^Vf5-yM$vtfn}28f2JScfO3uFf z(AVsjY>%fmFfoKGV|vQcvK=;kl7E~x^&1AV)&3Zc-kMx~wX=CQS|`0xvi%9;hUn0L z-hh!!zxznXn(h(x{MEZPrS*_k$uTJ5e(+)|3O*?$%Eujo`DdL>P|dqTD((e^`l`hf&|%fWs-@{t&d;60gRv*v`5F%#ccR& z5Z`Rfx?KFh7>Agf$)AtszVRT#^x}J|FZ};i8`6?)g?%Z4VL7ntiDon&_dx@26bCKP;^# zc^MQ$Pd1%4Ws#2wT;iwCz`AG~9T#_BeePh;NW7@?6-Msk=D+ppYhvKQ{ab&>cy3jg zUgZYPTsFV{Z?lF%XjB*)tAbs#a`-hYY3GQg5cMTitiib*V|WnvcQ$y=TOmb-A_k z^MgP*<0yg*{-6KxeFEE}oYRS^ka2ugBQUx^qwEmu`;Q^5%v)9Aw;pbd{5_jS?oyI= z^XUdF?P*Q}Th`&2sNemSpEF(`ZSS3vzCq}832N<))#Bm5x!LcQc{U?0Z|gv`&vegc z8P&~>#pRlg`>F~Fq1=_bJj<82p4&R3O7TF~$S=VJ0e@Ya$`^|7g^r6&%wE_`Uysh* zsP%A>tLNZXn{|2P?C?}-eJN;bw7;u&+j`J9?;&l1=L05*CziKGXDKOTZNWOdATE{a zrW({R`d6O^l!U+d5QnvI z=$2QxZK=*bf*Kw#u{XObQC4vIYI*`?7r`ae^JePi+$=JK1(oe3vY*Y4Dzp5Xq zD|^Mkqu+x;nrum5o^HYD0(^Bbio-hIt578&WHb8ZTKT%FZMh!kns-um`8}pdA`)<; zT&!_fE<>r+et%X4{vJc613E79{e!#Hvk_siB>n8)NG|90-hPB`OD7B8_MFzKt9~5L5``EpWh)-RB|k0}XQ@aA+~AhQy-`rkYyV^M*imxVojz2W zg5uHgF8n;g4GHTYpIXh6&Yeum0P}8?XGdjF zCwHCW%jd7^z}FJo8ENYoYG1LyY4*JKL8%cR9csPADK3xmyaqYzE7^lp;wuUz>|f9w z3%u$G0ek7*Xz<)@93Y6njJ)V4h+p!f9KP&G{LtvHRnyIB*+tNMx_ z4LJ~s=)N7Q1n2IlE7$BN7NyIZ7b1Gi$GzU!ZeHYN zd;Rd=)-}~L)2+w$CT`=fJOJ>GlNPCr`2+*7+*5V+#`9G_Slqf$))Dhosz_}_DJm$x zYhRpEVEVUFu?e0ulxSbS1S#z=dR=@$S8M-v_62L+FyJZoLB@+*?tZkRoY238`^Lqq z=wKC0tW8ai3D9MzyehYNJQlc+u@w{VYu2LfBS{j4X%$cw-|@JmaB#m`4Zqja$;$9u z+IBsSyJ#x&vQ@JtnS2immKaVap+H`H3N=pL>K)JRFkwkox8q^cuX~#!K%*S>G!E{=7@Yn%4Q=6p+@dTO%4TD`92b@7|4TlP8+M!kXsCIB{8*@dd`$E|mhqiazdDb- zWFLhh0&xd&D^9>6<9T}M!WY~$R}`>IFr6yC%UJkio!GG@%5Jdga5@hnHCyb&>ytQg zlgW3LKoy@W042f7v_n^1Y%D5<79$S{npy9)0BsFs-;DNfS@g$%iV{!xu>EQ0D(;`0 z3-L8OFkZv7(`9NcIdYMmIg#Dnz>JII(Wxtz zqsEMy|M3Y3C*Zb*G{=F7*>kdbRp8uA+c>}$Uh`@a%bWm1yl2jEF*jb+MjY5)>ksZS z_UjhrCN3xU%wwLs80=1KEm)zCVC`OgQQ+SH_K1p2zdVJ1obF}&pWoeLYf1eQ4nnbso)CjTLJSomUNbv5N4R7X-UH{-zaLAEqH0OQP)G)dv>2U9rK zp8yxuz2=^cb0!cWdZ~VfnU!{L{761w_l7s2@^V=% zxo?Q*i3mUilz-qQ>C`qFmFOUSip4_2vpu6?49JA1M5PxX;& z5xZ&M9mXM0vI;$ipGi?ut5=V`1aoExJRM9hvZ;^KRfhU$fCDd<@Ml$W14<`vYH9r+pd>kM{T~u+t9I)6sc% zgzg2_s~jRA)lbHk`WzbuIzQ}(U&qI3=+Nd6LfRvcoKwY?1tFqPl>w42;uvKnh{Y9N z>(o-B_R}G>ad3f3vh}%2l!#kggjX04= zqYek7v0b;k2S8raH0#6&qSlPaODGtDNIw3v!>?b>>+03W2GF}QI`(B1S&@aC5MC+J zq(zd@g?k%oO)Ht77U`r;P=+-EjEP6j}F%6m`L$K7}UOA9I~j0HpeANIz+xZ_jTCNjULej2P@wd zS*U(ux1w3cN%CLYD~sz;m`g(Iki104m9Iq4WwiqBQjfOtTUZLVOPi^xFQH`|)hioH zJb#g;S1zkijG2%)W%w?xY#8`l?-tF5PoZ@Wl+xNMIxFb-!uOVJ3ocGNKf;+HSjo*r7pVv$r$9=ez`-jgH?Q`e42sH!OF3genjAF?0iG_V>Z2-pXw zDg+_wWoVs?sLJ^bE4PAJECM)C_{XaRxWlb)M#Qvr0P2UGh9wa^uKCQq|8x*kI{F8= zg7}3#B;u_qf`G9H^V&nhqHaAc*$wq!A&(w0zCOCQM`Pe@5JvEroSQr-PKZvs$)?JY zE)!cshwQT-2MmFH0&g8ctU((9TL3DH{HLTs5>yL7;@D-{5F`nJegxmMzC7|RyP3fB??wE-VkWG@Gtx#yj{ATs(78JU*%5(Y+JU-@kiQU9!aH=aGJi25yjFb(*$>9X3e2jG*t zh2_o|O?kzbk?zpU%N2PvsgPis1+jOi2d3!i_XLuD~ImjCAyrR*^>1JWel1gge%hX9q&VRX@Rp!1sqqAur+N6=4)UgkZi z%YO;g_~>A<&~HZH!ibpC^LNaY#Zh|1C^;m52-+qTzV`Y?*q z8tjN&KueJNdS%f!KWMLVr#odG8br4%MA&;yu)WOZiXzyRcTjb`pke=ZCe67UFF>d6 z-GkUk+ml<5x9?7K9ru6+ODxUpg_Z*2}yIBJ4z_3-ZIKf4I?dUTE)E=ON(CEFrzd>OG9M=Fc14j^DI@ zWfo!yx-ZLL3x8$nMRf**pg=d_olgzBz#Hgz-tQ?_BVawmK0-i2$@D{V+9~d0F0dITL_YRKv{gaMAo}G5D(b*W3ujVvmoroj*RMF zF#Xn+ULbD_{wmYP#A|OaDYhxWWw;?7$%BS{IWq~4w z7V!f|bYgwg1JvD@O-Yt?HQSBEpEK3l-)xP#-=I;Y#}7GC&!xyw?+*+Fgy?*r_SH3& z(+S{byWXhTic(n-jwV2!N{T*1Jy|VRyB0nPu|9=!vGHxzUbEUP;%z9o$RlIB;El#A z&zf_>Ed-&bYjdPy|NDK1))6EQMN3uDJ@ieN?MB6JruS}X79j}s*Lvq#LWGZ(!a? zazKc)VKYgAzOm^L-vdoQOWOw@R5Se#FLEbohG%0^g&7Tt?GpjG{z)97UZ~vKofrzR zkI1)R`4~@}h){)vYzaMzuq7=1x!zR#kwXIy=i)(807YDjj2!d{sBrhh5Z}8PWg9Ra zKu<-{!Lqp(9UnZxhDt)zZQD8vWk}J0=K;r0D;?jY5jLhS2?*GDi(tU!(E%<-qd8T} zD=rGD(pZEU=yKNL@o=fuiq1K9(DF_dJUa7Pt{l{sjOBXG5%0rq!C22~V_*rY%LeA= zDKO-^(M9|5`BrzrE_7_C#}XSuhI5_uQ!vDg>tmcjpYQE*hVG@`;Ad05%OiFkU@kfkv7>QbU}o}d^m~^x=;1Jwy5^t9HyVBguNgXCb;DPA-o^V#wVUxdn z_O^u~@CP$kGfr;<_rh6u>ieH~yS-rPAzry+vAhcO);j3nd`Rzwm`oN7GD*%1IuXQ4 zf==<~Xwtn(#f9Qmw8*rE8D3^`ixIvKJvvlDOTMFa1tHbvMLF!P$ZG`e*&!*bn%4j+ zB5=S-Zc+LL8L4&^eRc~5Bcy>x&pfGL*>4Mz_`tCz#+SqbokXpRCBeaJ(_e-o>sa!M z#9h}X zdD^#dx6I13yeEg5Iyp^EXb44mXcv3Ul2Qq{+ua3><(GW%pFQRdAskGR!Rv)QGG$jX zPzcGd%AmQo%){cS5THW>M!WA@822M4fO4sF#X9sVAHgDNjFCYwkL(%q{lZWKL6Eun zxJjr*9l+z3b}&)FBYv&T z{d}u^ses4vIY~D`O}WOR7fR_jc1{rnud%_JGXjAG`(3Ht%lE)sTdSjzqO3X^TQU}% z&sUn*5@VA@lb?CGHf??B3&|U1OjJ%1IdvTl2+bs>D!%DPi6JxXiwYGNn$FS;zVOE{ zM+!XmsQViHea_=#pilCZb-jlp3^DKImM7NxdBx#1w$QJq?edBx#qH?ZoYC=5 zI87z)CI|QK9{Nk{obEO^fPA0OT31F`#HCAR@6_>K2;zOVsI=t}DD$e-Cz(lxgJbY_x<9Scr0-A@>J1riY0+`S ze}w7!lEV)QRi&~m8Ph)+RA0ytt6|~`>-~~)yV@Sq7xDHoxu)Rcdw!(=zp1-jeaX$A zRv6z9%BBJb=I3*IMlU#<@?&aPxZYB}q0B6vX02rmD@D8K^S-)&2er@MYw` zg?yV9!alu!Zw1;dTOr&p2}!}CySki{r@L0mEzX_u_Rtz#7_4JF!bV!Rqpjhe^HA-!PS6E)PUc%cW1x|;RT>$NO zb6pAWR7kVEH5;At<-hJXjZHiBXNzwi$%}DVXuRi|a>3YM4A%VVjdnqVO@W$Ecomru z)T6@<_t~^k!s0h&!|I&5M~(TPJj5UqSt?wTR6(o75=RDJF}DKpNu%S``WMc(<*VcA zGRim+9sz2;heBW3(aq|-C%M{n1XHnzr2Iw4>Z!LhiWA@u;Nbb_!A)m>BHsTx+(r>=6CQcDvU$59A;JdEkp+b9P3GlF2pl+w zXK=fn`v7=Iata~#YgmoPT!yp2Y$CLO$I9q9#1=NggTlU2!+Xsl2gsnPb|y2?c`a8< zE_1cBB0m`%tkV_WMTbT!y|I;9dWx)R5`tF7v?gkIv8 zdHtK?YSmmxosshOTOcHBVz64ih37 z_*SpCHjtiyA@_VJ3{usSdTRx7nVtv3W)KoF?EC8dd4>~X4OsVD;TVStH;Q;pOxd_d zz>P(M^B<4G5rJpAS>vYi+0T%r|9PfMy|Cf)VChA+Y)AAeu3*&P>o|b5M2sK_Yv;GJi)<3;PdGRurA2U=t62a* zsk|=0MH>S*QzK>w=V5xvfc`ID3O3jiber_k}r2rX$?0LN+uyZfS3|i|r}M zj(e9gq0&&!-hv5!ONBeVWskj(Sz8`f&n{!Fie5LqAhs4y3pXE1NKdHCFoRqz+=@ld zEqn8-o6rRV({~?1-%DhtJsdL6gP{GZ_Eb5j+_xUa;n>yq9G(Y?9^GhX?F)@(yKX5x${>lVig zdLzp<5(YU3M!@FgN^EvmUQtA;Za0)*u=YsCHvdRx;sfVpV@LkFgwP4MDoL+p{%@fC zi!;4mDYz^cOby4~pdLhYTRZXz`@}2bEr2HzI=U@co87>|Oj%_FB@BBS-9~0s3RFvO>ZBtg|(}XPJ!%(rZvu<}l9}VOQ~4ekg>-t!7`z{b6sJ zm;fDf$N(|s#^vquB;X|7?A+n)Oz>;Ia_jou=u#n9__ZPp$r9V;DX@t}o|jrA{+1c~ zpiB=}EPM^*xqoFWqUUfRqxxldTXEAT`9+ii+JNxNSGCec!oEJuaEgy5qq>-;V>Qz~ zJ1g=Dr(*cot;Z2Z5NprS)EA^9&4vrQi{N!I6D4z>Xs7jfPQBD*ZFqQsCs8(Ts4N$W zNfyLupEbjKiNrYU9VEDqoN3CVh!$wWn@50J75udoAwsYWb*M|8jM4rEd9TFMJ5 zN>g=E-M?SEgDen-#*`Vu1<<>Vro|{%pC<}@5`Varbgf@FYsx0i1|f4vU^k-W(TnSN@pFNPffMtaL*Gb9r0RO^*o=vUKBaeo3S8-QqXc?j;A+o%U^`$ z@qpzK$Vu<#)#PTO@cyEwE7kV*%dP<)Jt+u^JzN>%Y^k9Q~H?%5w-CHo9KGR-D z*-0K~l}!*>NDmLmQYmQvBt|^=4 zgv7NcEjVcxIQYU+_J(*}mqW&6#~XV_#CJex`RbROd52bO1o z4>MolKmV?>9TV;2FI z-h6S`5vN|=KgPkWgv3}Tv96PE%8w?AWEf&IMIZ|XY*?nM7c`e7eG#6QpiQ51}j_s555EMJvQ;|VosiWN$2JPvZ2A(|+ED7*R&yPvceUin3@Dw}4ezo^}cZr5{QklC4g~}>hrg0*J8{;^S40QH6g4Qa_Ep+4FkU7TbWl@B9L5_<0*2(Iv zeWM3Jj;3(6=DC_21{clM$P6mNJcw9KmKHE$$mh$bE95Z_CI9D)< zzbGsZA7v9XgI9CeIVAz}(d zrZDGX3GROozJ6fP51R4p37#>aTqxNeQ6f3!$7AKS03;G!Fu)x7^tSvnCUNrzU!ZMo z(69{5(t*c27HG~*wwMvYn6As%*D15NJ3$0gw^vWHAZhG5hx_P2MY%fN;Qn(@!?_KK zhhEX80s9TpyRS*chaqRN+`~(dlouW~nhT>6p{q^SNd}@yRG3oA+SOavv=S(> z;k#Q7k-rWv{n@oL4+>D#QR#fZH(mzYm|Qk5=gT{Lx7W;$vm%Q|rs7=UZ#^dcwu*e| z%dh|}RYEi?V=28oiwBt40D@pX*be6?DTYVn#1c?1U~KpAQbH%_dv{C*l7bce!1=JW$YEc%%;QvI)!1VMc!pAPi!|Ln&KKASk$mQq{$ z*YHVumM4iC48t^ThbbybSn^vCh{IXoOGbhoo ziwt!i37L=dzdk5S6yMW`!LFi4KnivQEyVbcYRhhXnKMbK|T>D@6ehMcxS>H$VvLnhK-G-B0a4P-dI> zJDw#J;!HXhjE+MbefV?`A5kL^Ki%f~6O6&3(Q{!Q>L zk&9N1MAZWg#YV3)L*qVOmDoK4MeTnoSwhR9F&mhp)eI*VB9cRulV?QmE$!-OFHvW03XKZ(9VE*;i%e7E-s$rty*&8RWV(- znxd7{tehIQkB7JCI>EVMl(?%N6)^WAK0ta?lE=lZ z5|+?~3t^pM8|3fh5VXIoAfEwBcLq%-9^h($=yZLE-+*?^z%5!jYNe{k$SyA>r^dJ^ zhL{_c2;HItNLDEe_G&zIgxZ8t%jw5yezml>3;0sn+RnRb?5^$}O2?w;1&>(RIiJ&W z`I|*5xqDx@xz_QDF%Lo)sj{2v=-g&5sYA zoabknQLd0VCsHtC>aO)3 z{S$fW{Xdtm9|8tG)lM9scM`(q@Uf26n`#Y$|90)?j&RB^tE=wH}MBH4v-kSLXYy*^d@(Yeo4ux&7^Wy-%i8~m$P-l z4FV_hcU^;pG<}Up{0X2MOY4_bw~JoX!QsLWL;naq*GFI%8;t%le>yLs&iL$i|Hk&- z*ko1pQ)^oCRUF$hGD5?P;d|K5jtOvGQ%?khZo}YARK$;xqFp%V;Ahf&wTELuMZ?*? zebc%1Z6Tb^U0AB*uGv1CWlxX7j#Yp9IcbgIdHf4+CH`88d|zz9&eB;(c*qyp@_mz` z>h`f43&n(~NAnUf<2aLL)mKbevq6Tw)pp&t-Mio(|BTk$MaCR-P6{%#>NZ~@)0 zoW^jwY=7e4ny$y&LiBFuE$I8)BmVwb`kPb4$rJB;>1~ICT3_YJ{kenw2B>h^Kvd~s zP)-;9leu+heDw<5vzN?Mhp&hAM5qVgVt4xv-0fb-HW6RgC~Ripdf#X8=jnaAE4f=g z#0H7|-T^SQaOa`bJC;l9z$N>D)ZmYJ%LQ_X%U*N?E_I;oyPfcU3XmM$*E|xLA(^;G zXXXQ{_pG5ELqYCh!7?WLX<2UfeGh0;0XfhGYj%yrXRAr6Dd0p`HM)Z7qkmbev(!pG zJp41>d3BGOFCJmG<@@8zQgvK~A4NRb{i5Y-b{tC+Ql8i*#6n62aj9F&cM|b1c&=t@3|5}x*kSf*AtQzn;4C1bkozSbA$xqbtv7V zJZ`z|9%;#pK}NG&w4NJ&=(BmUOo)l+jlx34&wjCqX9q!bXC7UvIWpa-CuYjGkOv`# z(WH;2*I2HmQ{dQ&G{1yAhfqT-hGDvm2YFq_v*g15L z!bgelW)mB$oc~~^(i*iZSC zM8Cb;8GGajYPT*@GtSM8gWhO!M%q+7{`gGa38RCQQngxj`9t_ z8@;^IB=HP64eSwfLEbZMy5I&}z2_O{IKT=fp%g@T6~O|G)x(X4uSs z3706I8vI=^4m;oSU)<1SjVpkEI5zE7Q=|9oU;sTzu?WfRm0ZqOUn4B(9YC=Bj-6U? zO*(kPP6a`74&1>e0Ww#RJ|tD6Y4LB>4Ydz?hb-{Ka^V10xe|GeIs;<=m&#!gQYuoO z=ab?i(UNLMW}v-x1*`gYl;fWUjG~6#d{o0VduzA|xuQZDNddqQ#kgwg^P^8) zy>Pj+e&l01wB|eUjZ&E~Tmrpu9Cr-U50TB$ANoab8`lN>qZ}kBz=Ftqal4gjtXKjM zT~UCreF-n1)9y&c7XaFLBFT!{I zItG04ar_gl8{C0+e+F$7AWolZDnKX)T1_J!a4nu8cwG==KCBo^gbUJ%@xL?ak&+-u zFQht@2~RxG|&feQ+iN zpo@05mdIaa=2+oHMmD!SbZh$%yO%b-Zns>Rh@SwdX7OTZ+x5)1W=Sj(0}=FR;A68} z=**OWQEUa;RBb&7Le9Yca1tLBv>CKVh(@qHoPhl!Crbq&$b=W0Ob{l@bT#POOvpg~ zP;j#GhKn->(RNKRzTmC5+Ovja8}ZVSduq~lBRoYSwLC;)=oFq*9Z3(cL!YENl7H{Jpwc%S-V1^zVbN$crz7o zJMVGWf{@LbdFCGIpiR683qIs#x0LyMY{Zuxv5Pks%|6*@YU?IIxB*L1W5@-v)7s$X zQ|uW)zzItY?!(O=LP%M!V|YnOIm}eJ$bIu9N)SK=0zvH7U>IN0v@Ky6pV47BY|@jH zVdXy*{5xAZ03J>$W_!;{)7ce+TrkPG2iy~kixI+1>pJ2Ir$06XB*^Q@OWu^3AjrwUq2md~ z40cNe4L_&{2n;?$PqQD{3`xK+3zx>Of`F>zLm|=xQJAX9ncvaDg0Y4{O}kE5`KutAI8m<#tiC6&5XCu=_7Olf$gqC7(;qNM zOnQxn`U80IXtD^b@rCI|%t@G0xl=kws=WHMqG?Z<=pF%Zk@KxG=ozouyvAbdfDQKV zY`#n=$b=B`=IF;%EqsY;K;v=rn-Z@VE~iw=zaX~&=p5yUHl?4$MCU;V(nxt3n7y*m zN*)ze$Zd3BtQRHmBwAFA?z}APHHPrR7#I1_0a8A|qjVtVDLVsrL*T}Z!g!G@1Ops$ zB(=r^u>^eV`G?SudI&ij+Yd`biXcD4B8)#(Z_q-wCDtIp=?aFn<)3n5gn6oA~YgpF6Z*q1G} z0@8r4#2IMBCu88gCRvwr0r&IJ!O^X~WIhIe`?cQMF#DA8py}xKLoY(`;K6f%Md-xnA4)q0|b${?TvF~%?WQ|8I&_*;!2x$Q_5=wqO@XGma zxA*G}Js;%=k?Swge7>#je)zL!L!zqo*1ogn;n;N+`g_z$o4)Fy5hJ1u=?HeL?&OD? z!y5+X+nCopb5t)l1i#Wxn>sXBTLm+XwkRr(IN~1O;1i_j8-jzDUWBUZ zJ)eF*=%iSkLRLk$)2-hP34gEb;>K-xDc-N9zt#brNur&d{N-6J=E{i@+G^tf#rH+j z!uxqG;n{J^7y0IIe!y`V-IZbVJ~0Fjae0Cp5bf@rwlEVjoxt*_v-|%bwUGt-!jsm) zwr1AeZ{&G4J*|NXO5=k*@_P1q4afzi!@A_L)4r$rG+trbGWw)wKZq9Q&oN3(pbiC)TAkHow zxR3+nUu0f?z<$W-8*#L8p4%WC8_}^NC;j^SN8VZWny>JibK8$uht4#-=6(j*Iz-+( z7ET~PUvE(q%{=crkIFlYul}Mp%AX4ItTR8B=smVb_YATHiOKJ&TGl3fxsPm4L^IuA z*Y{~OuMT;9?Bm+Hj_1$tu4Jm8fSk{jZ*)f>*TK%|x}_cYVPLk(qLKM@+S@-T=Ki@q zv-Q*SdeZL$0-5iQsv?Xappx?QtmOZ>y7`u3N4JRGb9vvrlA4>{%VN`w3=tSc5R*xz zc;SXh`{sOp6t=&=^zdf%AB&}&D+S?Ad`JTvG=_OeB8j27w&Uh<#)>Adk!AC$ ztqh5;#q_B+WB+^$B8Pu&U?Q<@U2;X*U=3y-eJXR`e4e!BWjK4=>Qo&U;hF*UhyLXE zYBi@{^}PvA?;rls-Az;im2UJF=n!$1m&Yrs*k?Yt8tnFamM0c$Il3`bNYdS>R}Ud6cY0GDhu7L485buhCC$>MMv*x=yw)ywIqnot#qUyi2p z7()F`d9O#t0cE+bx*|12+;w)_F@x4gxC7PkihO(omM8V8|B!;4-;z}eJ}&v)9$8X` z03+f6%C4OuoW=4U?VrMH)RDj&vZMB7G2AWO1Um!51Le7q&~`3%80L)S{J3nL_5Ptn z58`+;xl`!teW?RsG9sL)a|}}=_p$cLi%A=5$%XNv5GpdkR<88&#){q2SZ8!`er){@ zEWrurxh5H$Dlz`J&g}x#ReKMj=377Y>cfv!V2IcUyAWM)e-Mq{7oD&+nOe)X9q+Ak z>(1OoklvHzHW#GYC1CBXH#NGO_~F+Fa|}V)b7&adA9|#uf@%eHCd#JDtiQ}Jfv9>86*6Dc^b3_bYl?AU|ibb7tR?R zd{oyz>e=w~Ad4O4;y-VN7V=J##~O`Ua@R z!Ux~HoZ-E$Hu94=(#mWomqkNBQ=^0rMg&V8e54dB;5p*dHq}-mBliuXd&;WJ>wHy^ zs*6JHp0=rE4}Yt-bV7K<%LMEs6AUr!uE4+>OZ%2*R|?v+5oGg{6FAi%XA4vg^nWax zX9j6r>L8=xkH7|N1AqS~KdT@6UU}) zTlJ&)Yb95n77`9F^*F(#&=fmgysa~d9mdoC=NnV7%#6<@ znkVm(hnwU{4Ge$~7fL8~lyUrH_J7R^rRablG;K67d>Kf)7Q z@FQ?P24T(wBU&_jf?hk_(#LmJ(S1qf$CI{u4G75vCQ5t_M(G3N3zX#_x9-+>aTdC7 zPStkV{GtU=&wu89@&6k2finL;Yp10ny2V|8wvM&Me9u9YlBZAVpD5O}yZ!$F?3ogn diff --git a/tests/ServerlessWorkflow.Sdk.UnitTests/Assets/WorkflowExtensions/condition-state-type.json b/tests/ServerlessWorkflow.Sdk.UnitTests/Assets/WorkflowExtensions/condition-state-type.json deleted file mode 100644 index c7c8d96..0000000 --- a/tests/ServerlessWorkflow.Sdk.UnitTests/Assets/WorkflowExtensions/condition-state-type.json +++ /dev/null @@ -1,175 +0,0 @@ -{ - "$defs": { - "workflow": { - "properties": { - "states": { - "items": { - "anyOf": [ - { - "title": "Sleep State", - "$ref": "#/definitions/sleepstate" - }, - { - "title": "Event State", - "$ref": "#/definitions/eventstate" - }, - { - "title": "Operation State", - "$ref": "#/definitions/operationstate" - }, - { - "title": "Parallel State", - "$ref": "#/definitions/parallelstate" - }, - { - "title": "Switch State", - "$ref": "#/definitions/switchstate" - }, - { - "title": "Inject State", - "$ref": "#/definitions/injectstate" - }, - { - "title": "ForEach State", - "$ref": "#/definitions/foreachstate" - }, - { - "title": "Callback State", - "$ref": "#/definitions/callbackstate" - }, - { - "title": "Condition State", - "$ref": "#/definitions/conditionState" - } - ] - } - } - }, - "definitions": { - "conditionState": { - "type": "object", - "description": "Enables the use of a ternary", - "properties": { - "id": { - "type": "string", - "description": "Unique State id", - "minLength": 1 - }, - "name": { - "type": "string", - "description": "State name" - }, - "type": { - "type": "string", - "const": "condition", - "description": "State type" - }, - "end": { - "$ref": "#/definitions/end", - "description": "State end definition" - }, - "stateDataFilter": { - "description": "State data filter", - "$ref": "#/definitions/statedatafilter" - }, - "if": { - "type": "object", - "properties": { - "condition": { - "type": "string" - }, - "action": { - "$ref": "#/definitions/action" - } - }, - "required": [ "condition", "action" ] - }, - "else": { - "type": "object", - "properties": { - "action": { - "$ref": "#/definitions/action" - } - }, - "required": [ "action" ] - }, - "timeouts": { - "type": "object", - "description": "State specific timeouts", - "properties": { - "stateExecTimeout": { - "$ref": "timeouts.json#/definitions/stateExecTimeout" - } - }, - "required": [] - }, - "onErrors": { - "type": "array", - "description": "States error handling definitions", - "items": { - "type": "object", - "$ref": "#/definitions/error" - }, - "additionalItems": false - }, - "transition": { - "description": "Next transition of the workflow after the workflow sleep", - "$ref": "#/definitions/transition" - }, - "compensatedBy": { - "type": "string", - "minLength": 1, - "description": "Unique Name of a workflow state which is responsible for compensation of this state" - }, - "usedForCompensation": { - "type": "boolean", - "default": false, - "description": "If true, this state is used to compensate another state. Default is false" - }, - "metadata": { - "$ref": "common.json#/definitions/metadata" - } - }, - "additionalProperties": false, - "if": { - "properties": { - "usedForCompensation": { - "const": true - } - }, - "required": [ - "usedForCompensation" - ] - }, - "then": { - "required": [ - "name", - "type", - "if" - ] - }, - "else": { - "oneOf": [ - { - "required": [ - "name", - "type", - "if", - "end" - ] - }, - { - "required": [ - "name", - "type", - "if", - "transition" - ] - } - ] - } - } - } - } - } -} \ No newline at end of file diff --git a/tests/ServerlessWorkflow.Sdk.UnitTests/Assets/WorkflowExtensions/greet-function-type.json b/tests/ServerlessWorkflow.Sdk.UnitTests/Assets/WorkflowExtensions/greet-function-type.json deleted file mode 100644 index 3b7bbf3..0000000 --- a/tests/ServerlessWorkflow.Sdk.UnitTests/Assets/WorkflowExtensions/greet-function-type.json +++ /dev/null @@ -1,28 +0,0 @@ -{ - "$defs": { - "functions": { - "definitions": { - "function": { - "type": "object", - "properties": { - "type": { - "type": "string", - "description": "Defines the function type. Is either `rest`, `asyncapi, `rpc`, `graphql`, `odata`, `expression` or `greet`. Default is `rest`", - "enum": [ - "rest", - "asyncapi", - "rpc", - "graphql", - "odata", - "expression", - "custom", - "greet" - ], - "default": "rest" - } - } - } - } - } - } -} \ No newline at end of file diff --git a/tests/ServerlessWorkflow.Sdk.UnitTests/Cases/Builders/WorkflowDefinitionBuilderTests.cs b/tests/ServerlessWorkflow.Sdk.UnitTests/Cases/Builders/WorkflowDefinitionBuilderTests.cs new file mode 100644 index 0000000..616b0d5 --- /dev/null +++ b/tests/ServerlessWorkflow.Sdk.UnitTests/Cases/Builders/WorkflowDefinitionBuilderTests.cs @@ -0,0 +1,188 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +using ServerlessWorkflow.Sdk.Builders; +using Neuroglia.Serialization.Yaml; + +namespace ServerlessWorkflow.Sdk.UnitTests.Cases.Builders; + +public class WorkflowDefinitionBuilderTests +{ + + [Fact] + public void Build_Should_Work() + { + //arrange + var name = "fake-workflow"; + var version = "1.0.0-alpha2"; + var title = "Fake Title"; + var summary = "fake Markdown summary"; + var fakeTagName = "fakeTagName"; + var fakeTagValue = "fakeTagValue"; + + //act + var workflow = new WorkflowDefinitionBuilder() + .WithName(name) + .WithVersion(version) + .WithTitle(title) + .WithSummary(summary) + .WithTag(fakeTagName, fakeTagValue) + .UseAuthentication("fakeBasic", authentication => authentication + .Basic() + .WithUsername("fake-user") + .WithPassword("fake-password")) + .UseAuthentication("fakeBearer", authentication => authentication + .Bearer() + .WithToken("fake-token")) + .UseAuthentication("fakeOAuth2", authentication => authentication + .OAuth2() + .WithAuthority(new("https://fake-authority.com")) + .WithGrantType(OAuth2GrantType.ClientCredentials) + .WithClient(client => client + .WithId("fake-client-id") + .WithSecret("fake-client-secret"))) + .UseFunction("fakeFunction1", function => function + .Function("http") + .With("method", "post") + .With("uri", "https://test.com")) + .UseFunction("fakeFunction2", function => function + .Shell() + .WithCommand(@"echo ""Hello, World!""")) + .UseExtension("fakeLoggingExtension", extension => extension + .ExtendAll() + .When("fake-expression") + .Before(task => task + .Call("http") + .With("method", "post") + .With("uri", "https://fake.log.collector.com") + .With("body", new + { + message = @"${ ""Executing task '\($task.reference)'..."" }" + })) + .After(task => task + .Call("http") + .With("method", "post") + .With("uri", "https://fake.log.collector.com") + .With("body", new + { + message = @"${ ""Executed task '\($task.reference)'..."" }" + }))) + .UseSecret("fake-secret") + .Do("todo-1", task => task + .Call("http") + .With("method", "get") + .With("uri", "https://unit-tests.serverlessworkflow.io")) + .Do("todo-2", task => task + .Emit(e => e + .With("type", "io.serverlessworkflow.unit-tests.fake.event.type.v1"))) + .Do("todo-3", task => task + .For() + .Each("color") + .In(".colors") + .At("index") + .Do(subtask => subtask + .Set("processed", ".processed + [$color]"))) + .Do("todo-4", task => task + .Listen() + .To(to => to + .Any() + .Event(e => e + .With("foo", "bar")) + .Event(e => e + .With(new Dictionary() { { "foo", "bar" }, { "bar", "baz" } })))) + .Do("todo-5", task => task + .Raise(error => error + .WithType("fake-error-type") + .WithStatus("400") + .WithTitle("fake-error-title"))) + .Do("todo-6", task => task + .Run() + .Container() + .WithImage("fake-image:latest") + .WithCommand("fake command --arg1 arg1") + .WithEnvironment("ASPNET_ENVIRONMENT", "Development")) + .Do("todo-7", task => task + .Run() + .Shell() + .WithCommand("fake command --arg1 arg1") + .WithArgument("--arg2 arg2") + .WithEnvironment("ASPNET_ENVIRONMENT", "Development")) + .Do("todo-8", task => task + .Run() + .Script() + .WithLanguage("js") + .WithCode(@"console.log(""Hello, World!"")")) + .Do("todo-9", task => task + .Run() + .Workflow() + .WithName("fake-workflow") + .WithVersion("1.0.0") + .WithInput(new { foo = "bar" })) + .Do("todo-10", task => task + .Set("foo", "bar") + .Set("bar", new { baz = "foo" })) + .Do("todo-11", task => task + .Switch() + .Case("case-1", @case => @case + .When("fake-condition") + .Then(FlowDirective.Continue)) + .Case("case-2", @case => @case + .When("another-fake-condition") + .Then(FlowDirective.Exit)) + .Case("default", @case => @case + .Then(FlowDirective.End))) + .Do("todo-12", task => task + .Try() + .Do(subtask => subtask + .Set("foo", "bar")) + .Catch(error => error + .Errors(filter => filter + .With("status", ". == 400")) + .As("error") + .When("fake-condition") + .ExceptWhen("another-fake-condition") + .Retry(retry => retry + .When("fake-condition") + .ExceptWhen("another-fake-condition") + .Limit(limits => limits + .Attempt() + .Count(10))) + .Do(subtask => subtask + .Set("foo", "bar")))) + .Do("todo-13", task => task + .Wait() + .For(Duration.FromMinutes(5))) + .Do("todo-14", task => task + .Execute() + .Sequentially(tasks => tasks + .Do("todo-14-1", task => task + .Call("http") + .With("method", "get") + .With("uri", "https://unit-tests.serverlessworkflow.io")) + .Do("todo-14-2", task => task + .Emit(e => e + .With("type", "io.serverlessworkflow.unit-tests.fake.event.type.v1"))) + .Do("todo-14-3", task => task + .For() + .Each("color") + .In(".colors") + .At("index") + .Do(subtask => subtask + .Set("processed", ".processed + [$color]"))))) + .Build(); + + //assert + var yaml = YamlSerializer.Default.Serialize(workflow); + } + +} diff --git a/tests/ServerlessWorkflow.Sdk.UnitTests/Cases/FluentBuilder/FluentBuilderTests.cs b/tests/ServerlessWorkflow.Sdk.UnitTests/Cases/FluentBuilder/FluentBuilderTests.cs deleted file mode 100644 index 94c1098..0000000 --- a/tests/ServerlessWorkflow.Sdk.UnitTests/Cases/FluentBuilder/FluentBuilderTests.cs +++ /dev/null @@ -1,561 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace ServerlessWorkflow.Sdk.UnitTests.Cases.FluentApi; - -public class FluentBuilderTests -{ - - [Fact] - public void Build_GenericState_Should_Work() - { - //arrange - var stateBuilder = new InjectStateBuilder(new PipelineBuilder(new WorkflowBuilder())); - var name = "fake-state-name"; - var metadata = new Dictionary() { { "fake-extension-property", new { foo = new { bar = "baz" } } } }; - var compensationState = "fake-compensation-state"; - var filterInputExpression = "${ . }"; - var filterOutputExpression = "${ . }"; - var error = "fake-error"; - var errorCode = "fake-error-code"; - - //act - var state = (InjectStateDefinition)stateBuilder - .WithName(name) - .WithMetadata(metadata) - .CompensateWith(compensationState) - .FilterInput(filterInputExpression) - .FilterOutput(filterOutputExpression) - .HandleError(ex => ex.Catch(error, errorCode).Then(flow => flow.End())) - .Build(); - - //assert - state.Should().NotBeNull(); - state.Name.Should().Be(name); - state.Metadata.Should().BeEquivalentTo(metadata); - state.CompensatedBy.Should().Be(compensationState); - state.DataFilter.Should().NotBeNull(); - state.DataFilter!.Input.Should().Be(filterInputExpression); - state.DataFilter!.Output.Should().Be(filterOutputExpression); - state.Errors.Should().ContainSingle(); - state.Errors![0].Error.Should().Be(error); - state.Errors![0].Code.Should().Be(errorCode); - } - - [Fact] - public void Build_CallbackState_Should_Work() - { - //arrange - var eventName = "fake-event"; - var action1Name = "fake-action-1"; - var functionName = "fake-function"; - var stateBuilder = new CallbackStateBuilder(new PipelineBuilder(new WorkflowBuilder())); - - //act - var state = (CallbackStateDefinition)stateBuilder - .On(eventName) - .Execute(action1Name, action => action.Invoke(function => function.OfType(FunctionType.Expression).WithName(functionName))) - .Build(); - - //assert - state.Should().NotBeNull(); - state.EventRef.Should().Be(eventName); - state.Action.Should().NotBeNull(); - state.Action!.Type.Should().Be(ActionType.Function); - state.Action.Name.Should().Be(action1Name); - state.Action.Function.Should().NotBeNull(); - state.Action.Function!.RefName.Should().Be(functionName); - } - - [Fact] - public void Build_EventState_Should_Work() - { - //arrange - var event1Name = "fake-event-1"; - var event2Name = "fake-event-2"; - var event3Name = "fake-event-3"; - var action1Name = "fake-action-1"; - var action2Name = "fake-action-2"; - var function1Name = "fake-function-1"; - var function2Name = "fake-function-2"; - var waitDuration = TimeSpan.FromHours(1.5); - var stateBuilder = new EventStateBuilder(new PipelineBuilder(new WorkflowBuilder())); - - //act - var state = (EventStateDefinition)stateBuilder - .TriggeredBy(trigger => trigger - .On(event1Name) - .Execute(action1Name, action => action.Invoke(function => function.OfType(FunctionType.Expression).WithName(function1Name))) - .Concurrently()) - .TriggeredBy(trigger => trigger - .On(event2Name, event3Name) - .Execute(action2Name, action => action.Invoke(function => function.OfType(FunctionType.Expression).WithName(function2Name))) - .Sequentially()) - .WaitForAll() - .For(waitDuration) - .Build(); - - //assert - state.Should().NotBeNull(); - state.OnEvents.Should().HaveCount(2); - - state.OnEvents[0].EventRefs.Should().ContainSingle(); - state.OnEvents[0].EventRefs[0].Should().Be(event1Name); - state.OnEvents[0].Actions.Should().ContainSingle(); - state.OnEvents[0].Actions[0].Type.Should().Be(ActionType.Function); - state.OnEvents[0].Actions[0].Name.Should().Be(action1Name); - state.OnEvents[0].Actions[0].Function.Should().NotBeNull(); - state.OnEvents[0].Actions[0].Function!.RefName.Should().Be(function1Name); - - state.OnEvents[1].EventRefs.Should().HaveCount(2); - state.OnEvents[1].EventRefs.Should().Contain(new string[] { event2Name, event3Name }); - state.OnEvents[1].Actions.Should().ContainSingle(); - state.OnEvents[1].Actions[0].Type.Should().Be(ActionType.Function); - state.OnEvents[1].Actions[0].Name.Should().Be(action2Name); - state.OnEvents[1].Actions[0].Function.Should().NotBeNull(); - state.OnEvents[1].Actions[0].Function!.RefName.Should().Be(function2Name); - } - - [Fact] - public void Build_ExtensionState_Should_Work() - { - //arrange - var metadata = new Dictionary() - { - { "fake-property-1", "fake-property-1-value" }, - { "FakeProperty2", "fakeProperty2" }, - { "fake_Property_3", new { foo = new { bar = "baz" } } } - }; - var type = "fake-state-type"; - var stateBuilder = new ExtensionStateBuilder(new PipelineBuilder(new WorkflowBuilder()), type); - - //act - var state = stateBuilder - .WithMetadata(metadata) - .Build(); - - //assert - state.Should().NotBeNull(); - state.Type.Should().Be(type); - state.Metadata.Should().BeEquivalentTo(metadata); - } - - [Fact] - public void Build_InjectState_Should_Work() - { - //arrange - var stateBuilder = new InjectStateBuilder(new PipelineBuilder(new WorkflowBuilder())); - var data = new { foo = new { bar = "baz" } }; - - //act - var state = (InjectStateDefinition)stateBuilder - .Data(data) - .Build(); - - //assert - state.Should().NotBeNull(); - state.Data.Should().NotBeNull(); - state.Data.Should().Be(data); - } - - [Fact] - public void Build_OperationState_Should_Work() - { - //arrange - var action1Name = "fake-action-1"; - var action2Name = "fake-action-2"; - var functionName = "fake-function"; - var eventName = "fake-event"; - var stateBuilder = new OperationStateBuilder(new PipelineBuilder(new WorkflowBuilder())); - - //act - var state = (OperationStateDefinition)stateBuilder - .Execute(action1Name, action => action.Invoke(function => function.OfType(FunctionType.Expression).WithName(functionName))) - .Execute(action2Name, action => action.Consume(e => e.WithName(eventName).IsConsumed())) - .Build(); - - //assert - state.Should().NotBeNull(); - - state.Actions.Should().HaveCount(2); - state.Actions[0].Type.Should().Be(ActionType.Function); - state.Actions[0].Name.Should().Be(action1Name); - state.Actions[0].Function.Should().NotBeNull(); - state.Actions[0].Function!.RefName.Should().Be(functionName); - - state.Actions[1].Type.Should().Be(ActionType.Event); - state.Actions[1].Name.Should().Be(action2Name); - state.Actions[1].Event.Should().NotBeNull(); - state.Actions[1].Event!.TriggerEventRef.Should().Be(eventName); - } - - [Fact] - public void Build_ParallelState_Should_Work() - { - //arrange - var branch1Name = "fake-branch-1"; - var branch2Name = "fake-branch-2"; - var action1Name = "fake-action-1"; - var action2Name = "fake-action-2"; - var functionName = "fake-function"; - var eventName = "fake-event"; - var stateBuilder = new ParallelStateBuilder(new PipelineBuilder(new WorkflowBuilder())); - - //act - var state = (ParallelStateDefinition)stateBuilder - .Branch(branch1Name, branch => branch - .Execute(action1Name, action => action.Invoke(function => function.OfType(FunctionType.Expression).WithName(functionName)))) - .Branch(branch2Name, branch => branch - .Execute(action2Name, action => action.Consume(e => e.WithName(eventName).IsConsumed()))) - .Build(); - - //assert - state.Should().NotBeNull(); - state.Branches.Should().HaveCount(2); - - state.Branches[0].Actions.Should().ContainSingle(); - state.Branches[0].Actions[0].Type.Should().Be(ActionType.Function); - state.Branches[0].Actions[0].Name.Should().Be(action1Name); - state.Branches[0].Actions[0].Function.Should().NotBeNull(); - state.Branches[0].Actions[0].Function!.RefName.Should().Be(functionName); - - state.Branches[1].Actions.Should().ContainSingle(); - state.Branches[1].Actions[0].Type.Should().Be(ActionType.Event); - state.Branches[1].Actions[0].Name.Should().Be(action2Name); - state.Branches[1].Actions[0].Event.Should().NotBeNull(); - state.Branches[1].Actions[0].Event!.TriggerEventRef.Should().Be(eventName); - } - - [Fact] - public void Build_SleepState_Should_Work() - { - //arrange - var duration = TimeSpan.FromSeconds(20); - var stateBuilder = new SleepStateBuilder(new PipelineBuilder(new WorkflowBuilder())); - - //act - var state = (SleepStateDefinition)stateBuilder - .For(duration) - .Build(); - - //assert - state.Should().NotBeNull(); - state.Duration.Should().Be(duration); - } - - [Fact] - public void Build_SwitchDataState_Should_Work() - { - //arrange - var case1Name = "fake-data-case-1"; - var case1Condition = "${ true }"; - var case2Condition = "${ false }"; - var case1TransitionTo = "fake-state-1"; - var case2Name = "fake-data-case-1"; - var defaultCaseName = "fake-default-case"; - var defaultCaseTransitionTo = "fake-state-2"; - var stateBuilder = new SwitchStateBuilder(new PipelineBuilder(new WorkflowBuilder())); - - //act - var state = (SwitchStateDefinition)stateBuilder - .SwitchData() - .WithCase(case1Name, switchCase => switchCase - .When(case1Condition) - .TransitionTo(case1TransitionTo)) - .WithCase(case2Name, switchCase => switchCase - .When(case2Condition) - .End()) - .WithDefaultCase(defaultCaseName, outcome => outcome.TransitionTo(defaultCaseTransitionTo)) - .Build(); - - //assert - state.Should().NotBeNull(); - state.SwitchType.Should().Be(SwitchStateType.Data); - state.DataConditions.Should().HaveCount(2); - - state.DataConditions![0].Name.Should().Be(case1Name); - state.DataConditions[0].OutcomeType.Should().Be(SwitchCaseOutcomeType.Transition); - state.DataConditions![0].Condition.Should().Be(case1Condition); - state.DataConditions[0].Transition.Should().NotBeNull(); - state.DataConditions[0].Transition!.NextState.Should().Be(case1TransitionTo); - - state.DataConditions![1].Name.Should().Be(case2Name); - state.DataConditions[1].OutcomeType.Should().Be(SwitchCaseOutcomeType.End); - state.DataConditions![1].Condition.Should().Be(case2Condition); - state.DataConditions[1].End.Should().NotBeNull(); - - state.DefaultCondition.Should().NotBeNull(); - state.DefaultCondition.Name.Should().Be(defaultCaseName); - state.DefaultCondition.OutcomeType.Should().Be(SwitchCaseOutcomeType.Transition); - state.DefaultCondition.Transition.Should().NotBeNull(); - state.DefaultCondition.Transition!.NextState.Should().Be(defaultCaseTransitionTo); - } - - [Fact] - public void Build_SwitchEventState_Should_Work() - { - //arrange - var case1Name = "fake-event-case-1"; - var case1Event = "fake-event-1"; - var case2Event = "fake-event-2"; - var case1TransitionTo = "fake-state-1"; - var case2Name = "fake-event-case-1"; - var defaultCaseName = "fake-default-case"; - var defaultCaseTransitionTo = "fake-state-2"; - var stateBuilder = new SwitchStateBuilder(new PipelineBuilder(new WorkflowBuilder())); - - //act - var state = (SwitchStateDefinition)stateBuilder - .SwitchEvents() - .WithCase(case1Name, switchCase => switchCase - .On(case1Event) - .TransitionTo(case1TransitionTo)) - .WithCase(case2Name, switchCase => switchCase - .On(case2Event) - .End()) - .WithDefaultCase(defaultCaseName, outcome => outcome.TransitionTo(defaultCaseTransitionTo)) - .Build(); - - //assert - state.Should().NotBeNull(); - state.SwitchType.Should().Be(SwitchStateType.Event); - state.EventConditions.Should().HaveCount(2); - - state.EventConditions![0].Name.Should().Be(case1Name); - state.EventConditions[0].OutcomeType.Should().Be(SwitchCaseOutcomeType.Transition); - state.EventConditions[0].EventRef.Should().Be(case1Event); - state.EventConditions[0].Transition.Should().NotBeNull(); - state.EventConditions[0].Transition!.NextState.Should().Be(case1TransitionTo); - - state.EventConditions![1].Name.Should().Be(case2Name); - state.EventConditions[1].OutcomeType.Should().Be(SwitchCaseOutcomeType.End); - state.EventConditions[1].EventRef.Should().Be(case2Event); - state.EventConditions[1].End.Should().NotBeNull(); - - state.DefaultCondition.Should().NotBeNull(); - state.DefaultCondition.Name.Should().Be(defaultCaseName); - state.DefaultCondition.OutcomeType.Should().Be(SwitchCaseOutcomeType.Transition); - state.DefaultCondition.Transition.Should().NotBeNull(); - state.DefaultCondition.Transition!.NextState.Should().Be(defaultCaseTransitionTo); - } - - [Fact] - public void Build_Function_Should_Work() - { - //arrange - var builder = new FunctionBuilder(new WorkflowBuilder()); - var type = FunctionType.OData; - var name = "fake-name"; - var metadata = new Dictionary() { { "fake-extension-property", new { foo = new { bar = "baz" } } } }; - var operation = "https://tests.sdk-net.serverlessworkflow.io#fake-operation"; - var authentication = "fake-authentication"; - - //act - var function = builder - .OfType(type) - .WithName(name) - .WithMetadata(metadata) - .ForOperation(operation) - .UseAuthentication(authentication) - .Build(); - - //assert - function.Should().NotBeNull(); - function.Type.Should().Be(type); - function.Name.Should().Be(name); - function.Metadata.Should().BeEquivalentTo(metadata); - function.Operation.Should().Be(operation); - function.AuthRef.Should().Be(authentication); - } - - [Fact] - public void Build_Event_Should_Work() - { - //arrange - var builder = new EventBuilder(); - var name = "fake-name"; - var metadata = new Dictionary() { { "fake-extension-property", new { foo = new { bar = "baz" } } } }; - var source = new Uri("https://tests.sdk-net.serverlessworkflow.io#fake-operation"); - var type = "fake-type"; - var correlations = new Dictionary() { { "fakeAttribute", "fakeAttributeValue" } }; - - //act - var e = builder - .WithName(name) - .WithMetadata(metadata) - .WithSource(source) - .WithType(type) - .IsConsumed() - .CorrelateUsing(correlations) - .Build(); - - //assert - e.Should().NotBeNull(); - e.Type.Should().Be(type); - e.Name.Should().Be(name); - e.Metadata.Should().BeEquivalentTo(metadata); - e.Source.Should().Be(source); - e.Type.Should().Be(type); - e.Correlations.Should().BeEquivalentTo(correlations.Select(kvp => new EventCorrelationDefinition(kvp.Key, kvp.Value))); - } - - [Fact] - public void Build_RetryStrategy_Should_Work() - { - //arrange - var builder = new RetryStrategyBuilder(); - var name = "fake-name"; - var maxAttempts = 5u; - var delay = TimeSpan.FromSeconds(3); - var maxDelay = TimeSpan.FromSeconds(30); - var delayIncrement = TimeSpan.FromSeconds(1); - var delayMultiplier = 2; - var jitterDuration = TimeSpan.FromSeconds(2); - - //act - var strategy = builder - .WithName(name) - .MaxAttempts(maxAttempts) - .WithDelayOf(delay) - .WithMaxDelay(maxDelay) - .WithDelayIncrement(delayIncrement) - .WithDelayMultiplier(delayMultiplier) - .WithJitterDuration(jitterDuration) - .Build(); - - //assert - strategy.Should().NotBeNull(); - strategy.Name.Should().Be(name); - strategy.MaxAttempts.Should().Be(maxAttempts); - strategy.Delay.Should().Be(delay); - strategy.MaxDelay.Should().Be(maxDelay); - strategy.Increment.Should().Be(delayIncrement); - strategy.Multiplier.Should().Be(delayMultiplier); - strategy.JitterDuration.Should().Be(jitterDuration); - } - - [Fact] - public void Build_ErrorHandler_Should_Work() - { - //arrange - var builder = new ErrorHandlerBuilder(new PipelineBuilder(new WorkflowBuilder())); - var retryStrategy = "fake-retry-strategy"; - var error = "fake-error"; - var errorCode = "fake-error-code"; - var nextState = "fake-next-state"; - - //act - var handler = builder - .Catch(error, errorCode) - .Retry(retryStrategy) - .Then(flow => flow.TransitionTo(nextState)) - .Build(); - - //assert - handler.Should().NotBeNull(); - handler.Error.Should().Be(error); - handler.Code.Should().Be(errorCode); - handler.RetryRef.Should().Be(retryStrategy); - handler.Transition.Should().NotBeNull(); - handler.Transition!.NextState.Should().Be(nextState); - } - - [Fact] - public void Build_EventAction_Should_Work() - { - //arrange - var builder = new ActionBuilder(new PipelineBuilder(new WorkflowBuilder())); - var name = "fake-name"; - var condition = "${ true }"; - var consumeEventRef = "fake-consume-event-ref"; - var produceEventRef = "fake-produce-event-ref"; - var contextAttributes = new Dictionary() { { "fake-attribute-1", "fake-attribute-1-value" } }; - - //act - var action = builder - .WithName(name) - .WithCondition(condition) - .Consume(consumeEventRef) - .ThenProduce(produceEventRef) - .WithContextAttributes(contextAttributes) - .Build(); - - //assert - action.Should().NotBeNull(); - action.Name.Should().Be(name); - action.Condition.Should().Be(condition); - action.Type.Should().Be(ActionType.Event); - action.Event.Should().NotBeNull(); - action.Event!.TriggerEventRef.Should().Be(consumeEventRef); - action.Event.ResultEventRef.Should().Be(produceEventRef); - action.Event.ContextAttributes.Should().BeEquivalentTo(contextAttributes); - } - - [Fact] - public void Build_FunctionAction_Should_Work() - { - //arrange - var builder = new ActionBuilder(new PipelineBuilder(new WorkflowBuilder())); - var name = "fake-name"; - var condition = "${ true }"; - var function = "fake-function"; - var arguments = new Dictionary() { }; - - //act - var action = builder - .WithName(name) - .WithCondition(condition) - .Invoke(function) - .WithArguments(arguments) - .Build(); - - //assert - action.Should().NotBeNull(); - action.Name.Should().Be(name); - action.Condition.Should().Be(condition); - action.Type.Should().Be(ActionType.Function); - action.Function.Should().NotBeNull(); - action.Function!.RefName.Should().Be(function); - action.Function.Arguments.Should().BeEquivalentTo(arguments); - } - - [Fact] - public void Build_SubflowAction_Should_Work() - { - //arrange - var builder = new ActionBuilder(new PipelineBuilder(new WorkflowBuilder())); - var name = "fake-name"; - var condition = "${ true }"; - var workflowId = "fake-workflow-id"; - var workflowVersion = "0.1.0"; - var invocationMode = InvocationMode.Asynchronous; - - //act - var action = builder - .WithName(name) - .WithCondition(condition) - .Run(workflowId, workflowVersion, invocationMode) - .Build(); - - //assert - action.Should().NotBeNull(); - action.Should().NotBeNull(); - action.Name.Should().Be(name); - action.Condition.Should().Be(condition); - action.Type.Should().Be(ActionType.Subflow); - action.Subflow.Should().NotBeNull(); - action.Subflow!.WorkflowId.Should().Be(workflowId); - action.Subflow.Version.Should().Be(workflowVersion); - } - -} diff --git a/tests/ServerlessWorkflow.Sdk.UnitTests/Cases/IO/WorkflowDefinitionReaderTests.cs b/tests/ServerlessWorkflow.Sdk.UnitTests/Cases/IO/WorkflowDefinitionReaderTests.cs new file mode 100644 index 0000000..d1772fe --- /dev/null +++ b/tests/ServerlessWorkflow.Sdk.UnitTests/Cases/IO/WorkflowDefinitionReaderTests.cs @@ -0,0 +1,62 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +using ServerlessWorkflow.Sdk.IO; +using Neuroglia.Serialization.Json; +using Neuroglia.Serialization.Yaml; + +namespace ServerlessWorkflow.Sdk.UnitTests.Cases.IO; + +public class WorkflowDefinitionReaderTests +{ + + [Fact] + public async Task Read_Workflow_Definition_From_Json_Should_Work() + { + //arrange + var toSerialize = WorkflowDefinitionFactory.Create(); + using var stream = new MemoryStream(); + JsonSerializer.Default.Serialize(toSerialize, stream); + await stream.FlushAsync(); + stream.Position = 0; + var reader = WorkflowDefinitionReader.Create(); + + //act + var deserialized = await reader.ReadAsync(stream); + + //assert + deserialized.Should().NotBeNull(); + deserialized.Should().BeEquivalentTo(toSerialize); + } + + [Fact] + public async Task Read_Workflow_Definition_From_Yaml_Should_Work() + { + //arrange + var toSerialize = WorkflowDefinitionFactory.Create(); + using var stream = new MemoryStream(); + YamlSerializer.Default.Serialize(toSerialize, stream); + await stream.FlushAsync(); + stream.Position = 0; + var reader = WorkflowDefinitionReader.Create(); + + //act + var deserialized = await reader.ReadAsync(stream); + + //assert + deserialized.Should().NotBeNull(); + deserialized.Should().BeEquivalentTo(toSerialize); + } + +} + diff --git a/tests/ServerlessWorkflow.Sdk.UnitTests/Cases/IO/WorkflowDefinitionWriterTests.cs b/tests/ServerlessWorkflow.Sdk.UnitTests/Cases/IO/WorkflowDefinitionWriterTests.cs new file mode 100644 index 0000000..b3a0037 --- /dev/null +++ b/tests/ServerlessWorkflow.Sdk.UnitTests/Cases/IO/WorkflowDefinitionWriterTests.cs @@ -0,0 +1,62 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +using ServerlessWorkflow.Sdk.IO; + +namespace ServerlessWorkflow.Sdk.UnitTests.Cases.IO; + +public class WorkflowDefinitionWriterTests +{ + + [Fact] + public async Task Write_Workflow_Definition_To_Yaml_Should_Work() + { + //arrange + var toSerialize = WorkflowDefinitionFactory.Create(); + using var stream = new MemoryStream(); + var writer = WorkflowDefinitionWriter.Create(); + var reader = WorkflowDefinitionReader.Create(); + + //act + await writer.WriteAsync(toSerialize, stream, WorkflowDefinitionFormat.Yaml); + await stream.FlushAsync(); + stream.Position = 0; + var deserialized = await reader.ReadAsync(stream); + + //assert + deserialized.Should().NotBeNull(); + deserialized.Should().BeEquivalentTo(toSerialize); + } + + [Fact] + public async Task Write_Workflow_Definition_To_Json_Should_Work() + { + //arrange + var toSerialize = WorkflowDefinitionFactory.Create(); + using var stream = new MemoryStream(); + var writer = WorkflowDefinitionWriter.Create(); + var reader = WorkflowDefinitionReader.Create(); + + //act + await writer.WriteAsync(toSerialize, stream, WorkflowDefinitionFormat.Json); + await stream.FlushAsync(); + stream.Position = 0; + var deserialized = await reader.ReadAsync(stream); + + //assert + deserialized.Should().NotBeNull(); + deserialized.Should().BeEquivalentTo(toSerialize); + } + +} + diff --git a/tests/ServerlessWorkflow.Sdk.UnitTests/Cases/IO/WorkflowReaderTests.cs b/tests/ServerlessWorkflow.Sdk.UnitTests/Cases/IO/WorkflowReaderTests.cs deleted file mode 100644 index b5317bb..0000000 --- a/tests/ServerlessWorkflow.Sdk.UnitTests/Cases/IO/WorkflowReaderTests.cs +++ /dev/null @@ -1,149 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -using ServerlessWorkflow.Sdk.Services.IO; - -namespace ServerlessWorkflow.Sdk.UnitTests.Cases.IO; - -public class WorkflowReaderTests -{ - - protected IWorkflowReader Reader { get; } = WorkflowReader.Create(); - - [Fact] - public async Task Read_Yaml_ShouldWork() - { - //arrange - var yaml = File.ReadAllText(Path.Combine("Resources", "workflows", "operation.yaml")); - - //act - var parsedWorkflow = await this.Reader.ParseAsync(yaml); - - //assert - parsedWorkflow - .Should() - .NotBeNull(); - parsedWorkflow.Events - .Should() - .NotBeEmpty(); - parsedWorkflow.Functions - .Should() - .NotBeEmpty(); - parsedWorkflow.States - .Should() - .NotBeEmpty(); - parsedWorkflow.Metadata - .Should() - .NotBeNull(); - parsedWorkflow.Metadata!["podSize"] - .Should() - .Be("small"); - } - - [Fact] - public async Task Read_Json_ShouldWork() - { - //arrange - var yaml = File.ReadAllText(Path.Combine("Resources", "workflows", "operation.json")); - - //act - var parsedWorkflow = await this.Reader.ParseAsync(yaml); - - //assert - parsedWorkflow - .Should() - .NotBeNull(); - parsedWorkflow.Events - .Should() - .NotBeEmpty(); - parsedWorkflow.Functions - .Should() - .NotBeEmpty(); - parsedWorkflow.States - .Should() - .NotBeEmpty(); - parsedWorkflow.Metadata - .Should() - .NotBeNull(); - parsedWorkflow.Metadata!["podSize"] - .Should() - .Be("small"); - } - - [Fact] - public async Task Read_Yaml_ExternalDefinitions_ShouldWork() - { - //arrange - var yaml = File.ReadAllText(Path.Combine("Resources", "workflows", "externalref.yaml")); - - //act - var workflow = await this.Reader.ParseAsync(yaml); - - //assert - workflow - .Should() - .NotBeNull(); - workflow.ConstantsUri - .Should() - .NotBeNull(); - workflow.SecretsUri - .Should() - .NotBeNull(); - workflow.DataInputSchemaUri - .Should() - .NotBeNull(); - workflow.EventsUri - .Should() - .NotBeNull(); - workflow.FunctionsUri - .Should() - .NotBeNull(); - workflow.RetriesUri - .Should() - .NotBeNull(); - } - - [Fact] - public async Task Read_Json_ExternalDefinitions_ShouldWork() - { - //arrange - var yaml = File.ReadAllText(Path.Combine("Resources", "workflows", "externalref.json")); - - //act - var workflow = await this.Reader.ParseAsync(yaml, new WorkflowReaderOptions() { LoadExternalDefinitions = true }); - - //assert - workflow - .Should() - .NotBeNull(); - workflow.Constants - .Should() - .NotBeNull(); - workflow.Secrets - .Should() - .NotBeEmpty(); - workflow.DataInputSchema - .Should() - .NotBeNull(); - workflow.Events - .Should() - .NotBeEmpty(); - workflow.Functions - .Should() - .NotBeEmpty(); - workflow.Retries - .Should() - .NotBeEmpty(); - } - -} diff --git a/tests/ServerlessWorkflow.Sdk.UnitTests/Cases/IO/WorkflowWriterTests.cs b/tests/ServerlessWorkflow.Sdk.UnitTests/Cases/IO/WorkflowWriterTests.cs deleted file mode 100644 index f320c56..0000000 --- a/tests/ServerlessWorkflow.Sdk.UnitTests/Cases/IO/WorkflowWriterTests.cs +++ /dev/null @@ -1,86 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -using ServerlessWorkflow.Sdk.Services.IO; - -namespace ServerlessWorkflow.Sdk.UnitTests.Cases.IO; - -public class WorkflowWriterTests -{ - - protected IWorkflowWriter Writer { get; } = WorkflowWriter.Create(); - - protected IWorkflowReader Reader { get; } = WorkflowReader.Create(); - - protected static WorkflowDefinition BuildWorkflow() - { - return WorkflowDefinition.Create("MyWorkflow", "MyWorkflow", "1.0") - .WithExecutionTimeout(timeout => - timeout.After(new TimeSpan(30, 2, 0, 0))) - .StartsWith("inject", flow => - flow.Inject(new { username = "test", password = "123456"/*, scopes = new string[] { "api", "test" }*/ })) - .Then("operation", flow => - flow.Execute("fakeApiFunctionCall", action => - { - action.Invoke(function => - function.WithName("fakeFunction") - .ForOperation(new Uri("https://fake.com/swagger.json#fake"))) - .WithArgument("username", "${ .username }") - .WithArgument("password", "${ .password }"); - }) - .Execute("fakeEventTrigger", action => - { - action - .Consume(e => - e.WithName("fakeEvent") - .WithSource(new Uri("https://fakesource.com")) - .WithType("fakeType")) - .ThenProduce(e => - e.WithName("otherEvent") - .WithSource(new Uri("https://fakesource.com")) - .WithType("fakeType")); - })) - .End() - .Build(); - } - - [Fact(Skip = "YAML parsing issue for non-complex properties (ex: externalRefs)")] - public async Task Write_Yaml_ShouldWork() - { - var workflow = BuildWorkflow(); - using Stream stream = new MemoryStream(); - this.Writer.Write(workflow, stream); - stream.Flush(); - stream.Position = 0; - using StreamReader reader = new(stream); - string yaml = reader.ReadToEnd(); - stream.Position = 0; - workflow = await this.Reader.ReadAsync(stream); - Assert.NotNull(workflow); - } - - [Fact] - public async Task Write_Json_ShoudlWork() - { - var toSerialize = BuildWorkflow(); - using var stream = new MemoryStream(); - this.Writer.Write(toSerialize, stream, WorkflowDefinitionFormat.Json); - stream.Flush(); - using StreamReader reader = new(stream); - string json = reader.ReadToEnd(); - stream.Position = 0; - var deserialized = await this.Reader.ReadAsync(stream); - Assert.NotNull(deserialized); - } - -} diff --git a/tests/ServerlessWorkflow.Sdk.UnitTests/Cases/Serialization/JsonSerializationTests.cs b/tests/ServerlessWorkflow.Sdk.UnitTests/Cases/Serialization/JsonSerializationTests.cs deleted file mode 100644 index e4ab891..0000000 --- a/tests/ServerlessWorkflow.Sdk.UnitTests/Cases/Serialization/JsonSerializationTests.cs +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -using ServerlessWorkflow.Sdk.Serialization; - -namespace ServerlessWorkflow.Sdk.UnitTests.Cases.Serialization; - -public class JsonSerializationTests - : SerializationTestsBase -{ - - protected override T Deserialize(string input) => Serializer.Json.Deserialize(input)!; - - protected override string Serialize(T graph) => Serializer.Json.Serialize(graph); - -} diff --git a/tests/ServerlessWorkflow.Sdk.UnitTests/Cases/Serialization/YamlSerializationTests.cs b/tests/ServerlessWorkflow.Sdk.UnitTests/Cases/Serialization/YamlSerializationTests.cs deleted file mode 100644 index 3b27e75..0000000 --- a/tests/ServerlessWorkflow.Sdk.UnitTests/Cases/Serialization/YamlSerializationTests.cs +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -using ServerlessWorkflow.Sdk.Serialization; - -namespace ServerlessWorkflow.Sdk.UnitTests.Cases.Serialization; - -public class YamlSerializationTests - : SerializationTestsBase -{ - - protected override T Deserialize(string input) => Serializer.Yaml.Deserialize(input)!; - - protected override string Serialize(T graph) => Serializer.Yaml.Serialize(graph); - -} diff --git a/tests/ServerlessWorkflow.Sdk.UnitTests/Cases/SerializationTestsBase.cs b/tests/ServerlessWorkflow.Sdk.UnitTests/Cases/SerializationTestsBase.cs deleted file mode 100644 index 657c3a7..0000000 --- a/tests/ServerlessWorkflow.Sdk.UnitTests/Cases/SerializationTestsBase.cs +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -namespace ServerlessWorkflow.Sdk.UnitTests.Cases; - -public abstract class SerializationTestsBase -{ - - protected abstract string Serialize(T graph); - - protected abstract T Deserialize(string input); - - [Fact] - public void Serialize_And_Deserialize_WorkflowDefinition_Should_Work() - { - //arrange - var toSerialize = WorkflowDefinitionFactory.Create(); - - //act - var text = Serialize(toSerialize); - var deserialized = Deserialize(text); - - //assert - deserialized.Should().BeEquivalentTo(toSerialize); - } - -} \ No newline at end of file diff --git a/tests/ServerlessWorkflow.Sdk.UnitTests/Cases/Validation/ActionValidationTests.cs b/tests/ServerlessWorkflow.Sdk.UnitTests/Cases/Validation/ActionValidationTests.cs deleted file mode 100644 index c5865f6..0000000 --- a/tests/ServerlessWorkflow.Sdk.UnitTests/Cases/Validation/ActionValidationTests.cs +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -using ServerlessWorkflow.Sdk.Services.Validation; - -namespace ServerlessWorkflow.Sdk.UnitTests.Cases.Validation; - -public class ActionValidationTests -{ - - [Fact] - public void Validate_Action_NoFunctionNorEvent_ShouldFail() - { - //arrange - var workflow = WorkflowDefinition.Create("fake", "fake", "fake") - .StartsWith("fake", flow => flow.Callback()) - .End() - .Build(); - var action = new ActionDefinition(); - - //act - var result = new ActionDefinitionValidator(workflow).Validate(action); - - //assert - result.Should() - .NotBeNull(); - result.Errors.Should() - .NotBeNullOrEmpty() - .And.HaveCount(3) - .And.Contain(e => e.PropertyName == nameof(ActionDefinition.Event)) - .And.Contain(e => e.PropertyName == nameof(ActionDefinition.Function)) - .And.Contain(e => e.PropertyName == nameof(ActionDefinition.Subflow)); - } - -} diff --git a/tests/ServerlessWorkflow.Sdk.UnitTests/Cases/Validation/CallbackStateValidationTests.cs b/tests/ServerlessWorkflow.Sdk.UnitTests/Cases/Validation/CallbackStateValidationTests.cs deleted file mode 100644 index 2b889d5..0000000 --- a/tests/ServerlessWorkflow.Sdk.UnitTests/Cases/Validation/CallbackStateValidationTests.cs +++ /dev/null @@ -1,97 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -using FluentValidation; -using Microsoft.Extensions.DependencyInjection; - -namespace ServerlessWorkflow.Sdk.UnitTests.Cases.Validation; - -public class CallbackStateValidationTests -{ - - public CallbackStateValidationTests() - { - IServiceCollection services = new ServiceCollection(); - services.AddServerlessWorkflow(); - this.ServiceProvider = services.BuildServiceProvider(); - this.WorkflowDefinitionValidator = this.ServiceProvider.GetRequiredService>(); - } - - protected IServiceProvider ServiceProvider { get; } - - protected IValidator WorkflowDefinitionValidator { get; } - - [Fact] - public void Validate_CallbackState_ActionNull_ShouldFail() - { - //arrange - var workflow = WorkflowDefinition.Create("fake", "fake", "fake") - .StartsWith("fake", flow => flow.Callback()) - .End() - .Build(); - - //act - var result = this.WorkflowDefinitionValidator.Validate(workflow); - - //assert - result.Should() - .NotBeNull(); - result.Errors.Should() - .NotBeNullOrEmpty() - .And.Contain(e => e.ErrorCode.StartsWith($"{nameof(CallbackStateDefinition)}.{nameof(CallbackStateDefinition.Action)}")); - } - - [Fact] - public void Validate_CallbackState_EventNull_ShouldFail() - { - //arrange - var workflow = WorkflowDefinition.Create("fake", "fake", "fake") - .StartsWith("fake", flow => flow.Callback()) - .End() - .Build(); - - //act - var result = this.WorkflowDefinitionValidator.Validate(workflow); - - //assert - result.Should() - .NotBeNull(); - result.Errors.Should() - .NotBeNullOrEmpty() - .And.Contain(e => e.ErrorCode.Contains($"{nameof(CallbackStateDefinition)}.{nameof(CallbackStateDefinition.EventRef)}")); - } - - [Fact] - public void Validate_CallbackState_EventNotFound_ShouldFail() - { - //arrange - var workflow = WorkflowDefinition.Create("fake", "fake", "fake") - .StartsWith("fake", flow => - flow.Callback() - .On("fake") - .Execute(action => action.Invoke("fake"))) - .End() - .Build(); - - //act - var result = this.WorkflowDefinitionValidator.Validate(workflow); - - //assert - result.Should() - .NotBeNull(); - result.Errors.Should() - .NotBeNullOrEmpty() - .And.Contain(e => e.ErrorCode.Contains($"{nameof(CallbackStateDefinition)}.{nameof(CallbackStateDefinition.EventRef)}")); - } - -} diff --git a/tests/ServerlessWorkflow.Sdk.UnitTests/Cases/Validation/EventReferenceValidationTests.cs b/tests/ServerlessWorkflow.Sdk.UnitTests/Cases/Validation/EventReferenceValidationTests.cs deleted file mode 100644 index 946b6c8..0000000 --- a/tests/ServerlessWorkflow.Sdk.UnitTests/Cases/Validation/EventReferenceValidationTests.cs +++ /dev/null @@ -1,149 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -using ServerlessWorkflow.Sdk.Services.Validation; - -namespace ServerlessWorkflow.Sdk.UnitTests.Cases.Validation; - -public class EventReferenceValidationTests -{ - - [Fact] - public void Validate_EventReference_TriggerEventNotSet_ShouldFail() - { - //arrange - var workflow = WorkflowDefinition.Create("fake", "fake", "fake") - .StartsWith("fake", flow => flow.Callback()) - .End() - .Build(); - var eventRef = new EventReference(); - - //act - var result = new EventReferenceValidator(workflow).Validate(eventRef); - - //assert - result.Should() - .NotBeNull(); - result.Errors.Should() - .NotBeNullOrEmpty() - .And.Contain(e => e.PropertyName == nameof(EventReference.TriggerEventRef)); - } - - [Fact] - public void Validate_EventReference_TriggerEventNotFound_ShouldFail() - { - //arrange - var workflow = WorkflowDefinition.Create("fake", "fake", "fake") - .StartsWith("fake", flow => flow.Callback()) - .End() - .Build(); - var eventRef = new EventReference() { TriggerEventRef = "fake" }; - - //act - var result = new EventReferenceValidator(workflow).Validate(eventRef); - - //assert - result.Should() - .NotBeNull(); - result.Errors.Should() - .NotBeNullOrEmpty() - .And.Contain(e => e.PropertyName == nameof(EventReference.TriggerEventRef)); - } - - [Fact] - public void Validate_EventReference_TriggerEventConsumed_ShouldFail() - { - //arrange - var workflow = WorkflowDefinition.Create("fake", "fake", "fake") - .AddEvent(new EventDefinition() { Kind = EventKind.Consumed, Name = "fake" }) - .StartsWith("fake", flow => flow.Callback()) - .End() - .Build(); - var eventRef = new EventReference() { TriggerEventRef = "fake" }; - - //act - var result = new EventReferenceValidator(workflow).Validate(eventRef); - - //assert - result.Should() - .NotBeNull(); - result.Errors.Should() - .NotBeNullOrEmpty() - .And.Contain(e => e.PropertyName == nameof(EventReference.TriggerEventRef)); - } - - [Fact] - public void Validate_EventReference_ResultEventNotSet_ShouldFail() - { - //arrange - var workflow = WorkflowDefinition.Create("fake", "fake", "fake") - .StartsWith("fake", flow => flow.Callback()) - .End() - .Build(); - var eventRef = new EventReference() { TriggerEventRef = "fake" }; - - //act - var result = new EventReferenceValidator(workflow).Validate(eventRef); - - //assert - result.Should() - .NotBeNull(); - result.Errors.Should() - .NotBeNullOrEmpty() - .And.Contain(e => e.PropertyName == nameof(EventReference.ResultEventRef)); - } - - [Fact] - public void Validate_EventReference_ResultEventNotFound_ShouldFail() - { - //arrange - var workflow = WorkflowDefinition.Create("fake", "fake", "fake") - .StartsWith("fake", flow => flow.Callback()) - .End() - .Build(); - var eventRef = new EventReference() { TriggerEventRef = "fakeTrigger", ResultEventRef = "fakeResult" }; - - //act - var result = new EventReferenceValidator(workflow).Validate(eventRef); - - //assert - result.Should() - .NotBeNull(); - result.Errors.Should() - .NotBeNullOrEmpty() - .And.Contain(e => e.PropertyName == nameof(EventReference.ResultEventRef)); - } - - [Fact] - public void Validate_EventReference_ResultEventProduced_ShouldFail() - { - //arrange - var workflow = WorkflowDefinition.Create("fake", "fake", "fake") - .AddEvent(new EventDefinition() { Kind = EventKind.Produced, Name = "fakeResult" }) - .StartsWith("fake", flow => flow.Callback()) - .End() - .Build(); - var eventRef = new EventReference() { TriggerEventRef = "fakeTrigger", ResultEventRef = "fakeResult" }; - - //act - var result = new EventReferenceValidator(workflow).Validate(eventRef); - - //assert - result.Should() - .NotBeNull(); - result.Errors.Should() - .NotBeNullOrEmpty() - .And.Contain(e => e.PropertyName == nameof(EventReference.ResultEventRef)); - } - -} diff --git a/tests/ServerlessWorkflow.Sdk.UnitTests/Cases/Validation/EventStateTriggerValidationTests.cs b/tests/ServerlessWorkflow.Sdk.UnitTests/Cases/Validation/EventStateTriggerValidationTests.cs deleted file mode 100644 index 3111034..0000000 --- a/tests/ServerlessWorkflow.Sdk.UnitTests/Cases/Validation/EventStateTriggerValidationTests.cs +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -using ServerlessWorkflow.Sdk.Services.Validation; - -namespace ServerlessWorkflow.Sdk.UnitTests.Cases.Validation; - - -public class EventStateTriggerValidationTests -{ - - [Fact] - public void Validate_EventStateTrigger_NoEvents_ShouldFail() - { - //arrange - var workflow = WorkflowDefinition.Create("fake", "fake", "fake") - .StartsWith("fake", flow => flow.Events()) - .End() - .Build(); - var state = new EventStateDefinition(); - var trigger = new EventStateTriggerDefinition(); - - //act - var result = new EventStateTriggerDefinitionValidator(workflow, state).Validate(trigger); - - //assert - result.Should() - .NotBeNull(); - result.Errors.Should() - .NotBeNullOrEmpty() - .And.Contain(e => e.PropertyName == nameof(EventStateTriggerDefinition.EventRefs)); - } - -} diff --git a/tests/ServerlessWorkflow.Sdk.UnitTests/Cases/Validation/EventStateValidationTests.cs b/tests/ServerlessWorkflow.Sdk.UnitTests/Cases/Validation/EventStateValidationTests.cs deleted file mode 100644 index cdbc79d..0000000 --- a/tests/ServerlessWorkflow.Sdk.UnitTests/Cases/Validation/EventStateValidationTests.cs +++ /dev/null @@ -1,54 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -using FluentValidation; -using Microsoft.Extensions.DependencyInjection; - -namespace ServerlessWorkflow.Sdk.UnitTests.Cases.Validation; - -public class EventStateValidationTests -{ - - public EventStateValidationTests() - { - IServiceCollection services = new ServiceCollection(); - services.AddServerlessWorkflow(); - this.ServiceProvider = services.BuildServiceProvider(); - this.WorkflowDefinitionValidator = this.ServiceProvider.GetRequiredService>(); - } - - protected IServiceProvider ServiceProvider { get; } - - protected IValidator WorkflowDefinitionValidator { get; } - - [Fact] - public void Validate_EventState_NoTriggers_ShouldFail() - { - //arrange - var workflow = WorkflowDefinition.Create("fake", "fake", "fake") - .StartsWith("fake", flow => flow.Events()) - .End() - .Build(); - - //act - var result = this.WorkflowDefinitionValidator.Validate(workflow); - - //assert - result.Should() - .NotBeNull(); - result.Errors.Should() - .NotBeNullOrEmpty() - .And.Contain(e => e.ErrorCode.StartsWith($"{nameof(EventStateDefinition)}.{nameof(EventStateDefinition.OnEvents)}")); - } - -} diff --git a/tests/ServerlessWorkflow.Sdk.UnitTests/Cases/Validation/FunctionDefinitionValidationTests.cs b/tests/ServerlessWorkflow.Sdk.UnitTests/Cases/Validation/FunctionDefinitionValidationTests.cs deleted file mode 100644 index 56a3993..0000000 --- a/tests/ServerlessWorkflow.Sdk.UnitTests/Cases/Validation/FunctionDefinitionValidationTests.cs +++ /dev/null @@ -1,83 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -using ServerlessWorkflow.Sdk.Services.Validation; - -namespace ServerlessWorkflow.Sdk.UnitTests.Cases.Validation; - -public class FunctionDefinitionValidationTests -{ - - [Fact] - public void Validate_Function_WithAutentication_ShouldWork() - { - //arrange - var function = new FunctionDefinition() - { - Name = "Fake", - Operation = "http://fake.com/fake#fake", - AuthRef = "fake" - }; - var workflow = WorkflowDefinition.Create("fake", "fake", "fake") - .AddBasicAuthentication("fake", auth => auth.LoadFromSecret("fake")) - .StartsWith("fake", flow => - flow.Execute(action => - action.Invoke(function))) - .End() - .Build(); - - - //act - var result = new FunctionDefinitionValidator(workflow).Validate(function); - - //assert - result.Should() - .NotBeNull(); - result.Errors.Should() - .BeNullOrEmpty(); - } - - [Fact] - public void Validate_Function_NoAuthentication_ShouldFail() - { - //arrange - var workflow = WorkflowDefinition.Create("fake", "fake", "fake") - .StartsWith("fake", flow => - flow.Execute(action => - action.Invoke(function => - function.WithName("fake") - .OfType(FunctionType.Rest) - .ForOperation(new Uri("http://fake.com/fake#fake")) - .UseAuthentication("basic")))) - .End() - .Build(); - var function = new FunctionDefinition() - { - Name = "Fake", - Operation = "http://fake.com/fake#fake", - AuthRef = "fake" - }; - - //act - var result = new FunctionDefinitionValidator(workflow).Validate(function); - - //assert - result.Should() - .NotBeNull(); - result.Errors.Should() - .NotBeNullOrEmpty() - .And.HaveCount(1) - .And.Contain(e => e.PropertyName == nameof(FunctionDefinition.AuthRef)); - } - -} diff --git a/tests/ServerlessWorkflow.Sdk.UnitTests/Cases/Validation/FunctionReferenceValidationTests.cs b/tests/ServerlessWorkflow.Sdk.UnitTests/Cases/Validation/FunctionReferenceValidationTests.cs deleted file mode 100644 index ee0ffbc..0000000 --- a/tests/ServerlessWorkflow.Sdk.UnitTests/Cases/Validation/FunctionReferenceValidationTests.cs +++ /dev/null @@ -1,115 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -using ServerlessWorkflow.Sdk.Services.Validation; - -namespace ServerlessWorkflow.Sdk.UnitTests.Cases.Validation; - -public class FunctionReferenceValidationTests -{ - - [Fact] - public void Validate_FunctionReference_NameNotSet_ShouldFail() - { - //arrange - var workflow = WorkflowDefinition.Create("fake", "fake", "fake") - .StartsWith("fake", flow => flow.Inject(new { })) - .End() - .Build(); - var functionRef = new FunctionReference(); - - //act - var result = new FunctionReferenceValidator(workflow).Validate(functionRef); - - //assert - result.Should() - .NotBeNull(); - result.Errors.Should() - .NotBeNullOrEmpty() - .And.Contain(e => e.PropertyName == nameof(FunctionReference.RefName)); - } - - [Fact] - public void Validate_FunctionReference_FunctionNotFound_ShouldFail() - { - //arrange - var workflow = WorkflowDefinition.Create("fake", "fake", "fake") - .StartsWith("fake", flow => flow.Callback()) - .End() - .Build(); - var functionRef = new FunctionReference() { RefName = "fake" }; - - //act - var result = new FunctionReferenceValidator(workflow).Validate(functionRef); - - //assert - result.Should() - .NotBeNull(); - result.Errors.Should() - .NotBeNullOrEmpty() - .And.Contain(e => e.PropertyName == nameof(FunctionReference.RefName)); - } - - [Fact] - public void Validate_FunctionReference_GraphQL_SelectionSetEmpty_ShouldFail() - { - //arrange - var functionName = "fake"; - var workflow = WorkflowDefinition.Create("fake", "fake", "fake") - .AddFunction(function => function - .WithName(functionName) - .OfType(FunctionType.GraphQL)) - .StartsWith("fake", flow => flow - .Execute(action => action.Invoke(functionName))) - .End() - .Build(); - var functionRef = new FunctionReference() { RefName = functionName }; - - //act - var result = new FunctionReferenceValidator(workflow).Validate(functionRef); - - //assert - result.Should() - .NotBeNull(); - result.Errors.Should() - .NotBeNullOrEmpty() - .And.Contain(e => e.PropertyName == nameof(FunctionReference.SelectionSet)); - } - - [Fact] - public void Validate_FunctionReference_SelectionSetNotEmpty_ShouldFail() - { - //arrange - var functionName = "fake"; - var workflow = WorkflowDefinition.Create("fake", "fake", "fake") - .AddFunction(function => function - .WithName(functionName) - .OfType(FunctionType.Rest)) - .StartsWith("fake", flow => flow - .Execute(action => action.Invoke(functionName))) - .End() - .Build(); - var functionRef = new FunctionReference() { RefName = functionName, SelectionSet = "{ id, name }" }; - - //act - var result = new FunctionReferenceValidator(workflow).Validate(functionRef); - - //assert - result.Should() - .NotBeNull(); - result.Errors.Should() - .NotBeNullOrEmpty() - .And.Contain(e => e.PropertyName == nameof(FunctionReference.SelectionSet)); - } - -} diff --git a/tests/ServerlessWorkflow.Sdk.UnitTests/Cases/Validation/InjectStateValidationTests.cs b/tests/ServerlessWorkflow.Sdk.UnitTests/Cases/Validation/InjectStateValidationTests.cs deleted file mode 100644 index 4783436..0000000 --- a/tests/ServerlessWorkflow.Sdk.UnitTests/Cases/Validation/InjectStateValidationTests.cs +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -using FluentValidation; -using Microsoft.Extensions.DependencyInjection; - -namespace ServerlessWorkflow.Sdk.UnitTests.Cases.Validation; -public class InjectStateValidationTests -{ - - public InjectStateValidationTests() - { - IServiceCollection services = new ServiceCollection(); - services.AddServerlessWorkflow(); - this.ServiceProvider = services.BuildServiceProvider(); - this.WorkflowDefinitionValidator = this.ServiceProvider.GetRequiredService>(); - } - - protected IServiceProvider ServiceProvider { get; } - - protected IValidator WorkflowDefinitionValidator { get; } - - [Fact] - public void Validate_InjectState_NoData_ShouldFail() - { - //arrange - var workflow = WorkflowDefinition.Create("fake", "fake", "fake") - .StartsWith("fake", flow => flow.Inject()) - .End() - .Build(); - - //act - var result = this.WorkflowDefinitionValidator.Validate(workflow); - - //assert - result.Should() - .NotBeNull(); - result.Errors.Should() - .NotBeNullOrEmpty() - .And.Contain(e => e.ErrorCode.StartsWith($"{nameof(InjectStateDefinition)}.{nameof(InjectStateDefinition.Data)}")); - } - -} diff --git a/tests/ServerlessWorkflow.Sdk.UnitTests/Cases/Validation/OperationStateValidationTests.cs b/tests/ServerlessWorkflow.Sdk.UnitTests/Cases/Validation/OperationStateValidationTests.cs deleted file mode 100644 index 97292c8..0000000 --- a/tests/ServerlessWorkflow.Sdk.UnitTests/Cases/Validation/OperationStateValidationTests.cs +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -using ServerlessWorkflow.Sdk.Services.Validation; - -namespace ServerlessWorkflow.Sdk.UnitTests.Cases.Validation; - -public class OperationStateValidationTests -{ - - [Fact] - public void Validate_OperationState_NoActions_ShouldFail() - { - //arrange - var workflow = WorkflowDefinition.Create("fake", "fake", "fake") - .StartsWith("fake", flow => flow.Events()) - .End() - .Build(); - var state = new OperationStateDefinition(); - - //act - var result = new OperationStateValidator(workflow).Validate(state); - - //assert - result.Should() - .NotBeNull(); - result.Errors.Should() - .NotBeNullOrEmpty() - .And.Contain(e => e.PropertyName == nameof(OperationStateDefinition.Actions)); - } - -} diff --git a/tests/ServerlessWorkflow.Sdk.UnitTests/Cases/Validation/SubflowReferenceValidationTests.cs b/tests/ServerlessWorkflow.Sdk.UnitTests/Cases/Validation/SubflowReferenceValidationTests.cs deleted file mode 100644 index cd7908b..0000000 --- a/tests/ServerlessWorkflow.Sdk.UnitTests/Cases/Validation/SubflowReferenceValidationTests.cs +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -using ServerlessWorkflow.Sdk.Services.Validation; - -namespace ServerlessWorkflow.Sdk.UnitTests.Cases.Validation; - -public class SubflowReferenceValidationTests -{ - - [Fact] - public void Validate_SubflowReference_WorkflowIdNotSet_ShouldFail() - { - //arrange - var subflowRef = new SubflowReference(); - - //act - var result = new SubflowReferenceValidator(new()).Validate(subflowRef); - - //assert - result.Should() - .NotBeNull(); - result.Errors.Should() - .NotBeNullOrEmpty() - .And.Contain(e => e.PropertyName == nameof(SubflowReference.WorkflowId)); - } - -} diff --git a/tests/ServerlessWorkflow.Sdk.UnitTests/Cases/Validation/SwitchStateValidationTests.cs b/tests/ServerlessWorkflow.Sdk.UnitTests/Cases/Validation/SwitchStateValidationTests.cs deleted file mode 100644 index 85c20ef..0000000 --- a/tests/ServerlessWorkflow.Sdk.UnitTests/Cases/Validation/SwitchStateValidationTests.cs +++ /dev/null @@ -1,75 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -using FluentValidation; -using Microsoft.Extensions.DependencyInjection; - -namespace ServerlessWorkflow.Sdk.UnitTests.Cases.Validation; - -public class SwitchStateValidationTests -{ - - public SwitchStateValidationTests() - { - IServiceCollection services = new ServiceCollection(); - services.AddServerlessWorkflow(); - this.ServiceProvider = services.BuildServiceProvider(); - this.WorkflowDefinitionValidator = this.ServiceProvider.GetRequiredService>(); - } - - protected IServiceProvider ServiceProvider { get; } - - protected IValidator WorkflowDefinitionValidator { get; } - - [Fact] - public void Validate_SwitchState_NoDataOrEventConditions_ShouldFail() - { - //arrange - var workflow = WorkflowDefinition.Create("fake", "fake", "fake") - .StartsWith("fake", flow => flow.Switch()) - .End() - .Build(); - - //act - var result = this.WorkflowDefinitionValidator.Validate(workflow); - - //assert - result.Should() - .NotBeNull(); - result.Errors.Should() - .NotBeNullOrEmpty() - .And.Contain(e => e.ErrorCode.Contains($"{nameof(SwitchStateDefinition)}.{nameof(SwitchStateDefinition.DataConditions)}")) - .And.Contain(e => e.ErrorCode.Contains($"{nameof(SwitchStateDefinition)}.{nameof(SwitchStateDefinition.EventConditions)}")); - } - - [Fact] - public void Validate_SwitchState_NoDefaultCondition_ShouldFail() - { - //arrange - var workflow = WorkflowDefinition.Create("fake", "fake", "fake") - .StartsWith("fake", flow => flow.Switch()) - .End() - .Build(); - - //act - var result = this.WorkflowDefinitionValidator.Validate(workflow); - - //assert - result.Should() - .NotBeNull(); - result.Errors.Should() - .NotBeNullOrEmpty() - .And.Contain(e => e.ErrorCode.Contains($"{nameof(SwitchStateDefinition)}.{nameof(SwitchStateDefinition.DefaultCondition)}")); - } - -} diff --git a/tests/ServerlessWorkflow.Sdk.UnitTests/Cases/Validation/WorkflowValidationTests.cs b/tests/ServerlessWorkflow.Sdk.UnitTests/Cases/Validation/WorkflowValidationTests.cs deleted file mode 100644 index fb28c14..0000000 --- a/tests/ServerlessWorkflow.Sdk.UnitTests/Cases/Validation/WorkflowValidationTests.cs +++ /dev/null @@ -1,92 +0,0 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"), -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -using ServerlessWorkflow.Sdk.Services.Validation; - -namespace ServerlessWorkflow.Sdk.UnitTests.Cases.Validation; - -public class WorkflowValidationTests -{ - - [Fact] - public async Task Validate_WorkflowDefinition_Should_Work() - { - //arrange - var workflow = WorkflowDefinitionFactory.Create(); - var validator = WorkflowSchemaValidator.Create(); - - //act - var result = await validator.ValidateAsync(workflow).ConfigureAwait(false); - - //assert - result.Should().NotBeNull(); - result.IsValid.Should().BeTrue(); - } - - [Fact] - public async Task Validate_WorkflowDefinition_WithStateTypeExtensions_Should_Work() - { - //arrange - var workflow = new WorkflowBuilder() - .WithId("fake") - .WithName("Fake Workflow") - .WithDescription("Fake Workflow Description") - .UseSpecVersion(ServerlessWorkflowSpecVersion.Latest) - .WithVersion("1.0.0") - .UseExtension("fake-extension", new($"file://{Path.Combine(AppContext.BaseDirectory, "Assets", "WorkflowExtensions", "condition-state-type.json")}")) - .StartsWith("fake-state", flow => flow - .Extension("condition") - .WithExtensionProperty("if", new { condition = "${ true }", action = new { name = "fake", functionRef = new FunctionReference() { RefName = "fake-function" } } }) - .WithExtensionProperty("else", new { action = new { name = "fake", functionRef = new FunctionReference() { RefName = "fake-function" } } })) - .End() - .Build(); - var validator = WorkflowSchemaValidator.Create(); - - //act - var result = await validator.ValidateAsync(workflow).ConfigureAwait(false); - - //asserts - result.Should().NotBeNull(); - result.IsValid.Should().BeTrue(); - } - - [Fact] - public async Task Validate_WorkflowDefinition_WithFunctionTypeExtension_Should_Work() - { - //arrange - var workflow = new WorkflowBuilder() - .WithId("fake") - .WithName("Fake Workflow") - .WithDescription("Fake Workflow Description") - .UseSpecVersion(ServerlessWorkflowSpecVersion.Latest) - .WithVersion("1.0.0") - .UseExtension("fake-extension", new($"file://{Path.Combine(AppContext.BaseDirectory, "Assets", "WorkflowExtensions", "greet-function-type.json")}")) - .StartsWith("fake-state", flow => flow - .Execute(action => action - .Invoke(function => function - .ForOperation("https://unittests.sdk-net.serverlessworkflow.io#fake-operation") - .OfType("greet") - .WithName("greet")))) - .End() - .Build(); - var validator = WorkflowSchemaValidator.Create(); - - //act - var result = await validator.ValidateAsync(workflow).ConfigureAwait(false); - - //assert - result.Should().NotBeNull(); - result.IsValid.Should().BeTrue(); - } - -} diff --git a/tests/ServerlessWorkflow.Sdk.UnitTests/CloudFlows.Sdk.UnitTests.csproj b/tests/ServerlessWorkflow.Sdk.UnitTests/CloudFlows.Sdk.UnitTests.csproj new file mode 100644 index 0000000..284fc2a --- /dev/null +++ b/tests/ServerlessWorkflow.Sdk.UnitTests/CloudFlows.Sdk.UnitTests.csproj @@ -0,0 +1,35 @@ + + + + net8.0 + enable + enable + + false + true + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + + + + + diff --git a/tests/ServerlessWorkflow.Sdk.UnitTests/Resources/auths/default.json b/tests/ServerlessWorkflow.Sdk.UnitTests/Resources/auths/default.json deleted file mode 100644 index 408f58d..0000000 --- a/tests/ServerlessWorkflow.Sdk.UnitTests/Resources/auths/default.json +++ /dev/null @@ -1,44 +0,0 @@ -[ - { - "name": "basic_foobar", - "scheme": "basic", - "properties": { - "username": "foo", - "password": "bar" - } - }, - { - "name": "basic_fromsecret", - "scheme": "basic", - "properties": "basic" - }, - { - "name": "bearer_foobar", - "scheme": "bearer", - "properties": { - "token": "foobar" - } - }, - { - "name": "bearer_fromsecret", - "scheme": "bearer", - "properties": "bearer" - }, - { - "name": "oauth2_password_foobar", - "scheme": "oauth2", - "properties": { - "authority": "https://idp.test.com", - "clientId": "workflow-engine", - "clientSecret": "supersecret", - "grantType": "password", - "username": "foo", - "password": "bar" - } - }, - { - "name": "oauth2_password_fromsecret", - "scheme": "oauth2", - "properties": "oauth2_password" - } -] \ No newline at end of file diff --git a/tests/ServerlessWorkflow.Sdk.UnitTests/Resources/auths/default.yaml b/tests/ServerlessWorkflow.Sdk.UnitTests/Resources/auths/default.yaml deleted file mode 100644 index 8dffb17..0000000 --- a/tests/ServerlessWorkflow.Sdk.UnitTests/Resources/auths/default.yaml +++ /dev/null @@ -1,27 +0,0 @@ -- name: basic_foobar - scheme: basic - properties: - username: foo - password: bar -- name: basic_fromsecret - scheme: basic - properties: basic -- name: bearer_foobar - scheme: bearer - properties: - token: foobar -- name: bearer_fromsecret - scheme: bearer - properties: bearer -- name: oauth2_password_foobar - scheme: oauth2 - properties: - authority: https://idp.test.com - clientId: workflow-engine - clientSecret: supersecret - grantType: password - username: foo - password: bar -- name: oauth2_password_fromsecret - scheme: oauth2 - properties: oauth2_password \ No newline at end of file diff --git a/tests/ServerlessWorkflow.Sdk.UnitTests/Resources/constants/petstore.json b/tests/ServerlessWorkflow.Sdk.UnitTests/Resources/constants/petstore.json deleted file mode 100644 index 819aeba..0000000 --- a/tests/ServerlessWorkflow.Sdk.UnitTests/Resources/constants/petstore.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "hello": "world" -} \ No newline at end of file diff --git a/tests/ServerlessWorkflow.Sdk.UnitTests/Resources/constants/petstore.yaml b/tests/ServerlessWorkflow.Sdk.UnitTests/Resources/constants/petstore.yaml deleted file mode 100644 index e734915..0000000 --- a/tests/ServerlessWorkflow.Sdk.UnitTests/Resources/constants/petstore.yaml +++ /dev/null @@ -1 +0,0 @@ -hello: world \ No newline at end of file diff --git a/tests/ServerlessWorkflow.Sdk.UnitTests/Resources/dataSchemas/input-data-schema.json b/tests/ServerlessWorkflow.Sdk.UnitTests/Resources/dataSchemas/input-data-schema.json deleted file mode 100644 index 819b7e4..0000000 --- a/tests/ServerlessWorkflow.Sdk.UnitTests/Resources/dataSchemas/input-data-schema.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "schema": "file://resources/schemas/input-data.json", - "failOnValidationErrors": false -} \ No newline at end of file diff --git a/tests/ServerlessWorkflow.Sdk.UnitTests/Resources/events/petstore.json b/tests/ServerlessWorkflow.Sdk.UnitTests/Resources/events/petstore.json deleted file mode 100644 index 2f2453e..0000000 --- a/tests/ServerlessWorkflow.Sdk.UnitTests/Resources/events/petstore.json +++ /dev/null @@ -1,14 +0,0 @@ -[ - { - "name": "PetCreated", - "kind": "produced", - "type": "io.swagger.petstore.pets.created", - "source": "https://petstore.swagger.io" - }, - { - "name": "PetDeleted", - "kind": "produced", - "type": "io.swagger.petstore.pets.deleted", - "source": "https://petstore.swagger.io" - } -] \ No newline at end of file diff --git a/tests/ServerlessWorkflow.Sdk.UnitTests/Resources/events/petstore.yaml b/tests/ServerlessWorkflow.Sdk.UnitTests/Resources/events/petstore.yaml deleted file mode 100644 index 988814c..0000000 --- a/tests/ServerlessWorkflow.Sdk.UnitTests/Resources/events/petstore.yaml +++ /dev/null @@ -1,8 +0,0 @@ -- name: PetCreated - kind: produced - type: io.swagger.petstore.pets.created - source: https://petstore.swagger.io -- name: PetDeleted - kind: produced - type: io.swagger.petstore.pets.deleted - source: https://petstore.swagger.io \ No newline at end of file diff --git a/tests/ServerlessWorkflow.Sdk.UnitTests/Resources/extensions/state-type-extension.json b/tests/ServerlessWorkflow.Sdk.UnitTests/Resources/extensions/state-type-extension.json deleted file mode 100644 index ae6e80d..0000000 --- a/tests/ServerlessWorkflow.Sdk.UnitTests/Resources/extensions/state-type-extension.json +++ /dev/null @@ -1,63 +0,0 @@ -{ - "type": "object", - "properties": { - "states": { - "items": { - "anyOf": [ - { - "$ref": "#/definitions/x-aws-step-function-state" - } - ] - } - } - }, - "definitions": { - "x-aws-step-function-state": { - "type": "object", - "properties": { - "name": { - "type": "string", - "description": "State name" - }, - "type": { - "type": "string", - "const": "x-aws-step-function", - "description": "State type" - }, - "functions": { - "type": "array", - "minLength": 1, - "items": { - "$ref": "#/definitions/x-aws-step-function" - } - }, - "end": { - "$ref": "#/definitions/end", - "description": "State end definition" - }, - "transition": { - "description": "Next transition of the workflow after the state", - "$ref": "#/definitions/transition" - }, - "metadata": { - "$ref": "common.json#/definitions/metadata" - } - }, - "required": [ "name", "type", "functions" ], - "additionalProperties": false - }, - "x-aws-step-function": { - "type": "object", - "properties": { - "name": { - "type": "string", - "minLength": 1 - }, - "payload": { - "type": "object" - } - }, - "required": [ "name" ] - } - } -} \ No newline at end of file diff --git a/tests/ServerlessWorkflow.Sdk.UnitTests/Resources/functions/petstore.json b/tests/ServerlessWorkflow.Sdk.UnitTests/Resources/functions/petstore.json deleted file mode 100644 index ad7d17f..0000000 --- a/tests/ServerlessWorkflow.Sdk.UnitTests/Resources/functions/petstore.json +++ /dev/null @@ -1,10 +0,0 @@ -[ - { - "name": "AddPet", - "operation": "https://petstore.swagger.io/v2/swagger.json#addPet" - }, - { - "name": "GetPetById", - "operation": "https://petstore.swagger.io/v2/swagger.json#getPetById" - } -] \ No newline at end of file diff --git a/tests/ServerlessWorkflow.Sdk.UnitTests/Resources/functions/petstore.yaml b/tests/ServerlessWorkflow.Sdk.UnitTests/Resources/functions/petstore.yaml deleted file mode 100644 index 0cd2a54..0000000 --- a/tests/ServerlessWorkflow.Sdk.UnitTests/Resources/functions/petstore.yaml +++ /dev/null @@ -1,4 +0,0 @@ -- name: AddPet - operation: https://petstore.swagger.io/v2/swagger.json#addPet -- name: GetPetById - operation: https://petstore.swagger.io/v2/swagger.json#getPetById \ No newline at end of file diff --git a/tests/ServerlessWorkflow.Sdk.UnitTests/Resources/retries/default.json b/tests/ServerlessWorkflow.Sdk.UnitTests/Resources/retries/default.json deleted file mode 100644 index 4281797..0000000 --- a/tests/ServerlessWorkflow.Sdk.UnitTests/Resources/retries/default.json +++ /dev/null @@ -1,11 +0,0 @@ -[ - { - "name": "default", - "delay": "PT10S", - "maxAttempts": 5, - "maxDelay": "PT20S", - "increment": "PT2S", - "multiplier": 1.2, - "jitter": 0.25 - } -] \ No newline at end of file diff --git a/tests/ServerlessWorkflow.Sdk.UnitTests/Resources/retries/default.yaml b/tests/ServerlessWorkflow.Sdk.UnitTests/Resources/retries/default.yaml deleted file mode 100644 index f9ff63a..0000000 --- a/tests/ServerlessWorkflow.Sdk.UnitTests/Resources/retries/default.yaml +++ /dev/null @@ -1,7 +0,0 @@ -- name: default - delay: PT10S - maxAttempts: 5 - maxDelay: PT20S - increment: PT2S - multiplier: 1.2 - jitter: 0.25 \ No newline at end of file diff --git a/tests/ServerlessWorkflow.Sdk.UnitTests/Resources/schemas/externalref.json b/tests/ServerlessWorkflow.Sdk.UnitTests/Resources/schemas/externalref.json deleted file mode 100644 index fa47456..0000000 --- a/tests/ServerlessWorkflow.Sdk.UnitTests/Resources/schemas/externalref.json +++ /dev/null @@ -1,34 +0,0 @@ -{ - "schema": { - "title": "ExternalRefWorkflow", - "type": "object", - "x-tags": [ - "workflow" - ], - "examples": [ - { - "id": "string" - } - ], - "description": "The data input schema for the official 'externalRef' testworkflow, used by the .NET SDK", - "properties": { - "id": { - "type": "string" - }, - "pet": { - "type": [ - "string", - "object" - ], - "properties": { - "name": { - "type": "string" - }, - "category": { - "type": "string" - } - } - } - } - } -} \ No newline at end of file diff --git a/tests/ServerlessWorkflow.Sdk.UnitTests/Resources/schemas/externalref.yaml b/tests/ServerlessWorkflow.Sdk.UnitTests/Resources/schemas/externalref.yaml deleted file mode 100644 index 35da58e..0000000 --- a/tests/ServerlessWorkflow.Sdk.UnitTests/Resources/schemas/externalref.yaml +++ /dev/null @@ -1,20 +0,0 @@ -schema: - title: ExternalRefWorkflow - type: object - x-tags: - - workflow - examples: - - id: string - description: 'The data input schema for the official ''externalRef'' testworkflow, used by the .NET SDK' - properties: - id: - type: string - pet: - type: - - string - - object - properties: - name: - type: string - category: - type: string \ No newline at end of file diff --git a/tests/ServerlessWorkflow.Sdk.UnitTests/Resources/schemas/input-data.json b/tests/ServerlessWorkflow.Sdk.UnitTests/Resources/schemas/input-data.json deleted file mode 100644 index 033f5e1..0000000 --- a/tests/ServerlessWorkflow.Sdk.UnitTests/Resources/schemas/input-data.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "type": "object", - "properties":{ - "firstName":{ - "type": "string" - }, - "lastName":{ - "type": "string" - } - }, - "required": [ "firstName", "lastName" ] -} \ No newline at end of file diff --git a/tests/ServerlessWorkflow.Sdk.UnitTests/Resources/secrets/default.json b/tests/ServerlessWorkflow.Sdk.UnitTests/Resources/secrets/default.json deleted file mode 100644 index 215d4a9..0000000 --- a/tests/ServerlessWorkflow.Sdk.UnitTests/Resources/secrets/default.json +++ /dev/null @@ -1,3 +0,0 @@ -[ - "test" -] \ No newline at end of file diff --git a/tests/ServerlessWorkflow.Sdk.UnitTests/Resources/secrets/default.yaml b/tests/ServerlessWorkflow.Sdk.UnitTests/Resources/secrets/default.yaml deleted file mode 100644 index 3a1dd92..0000000 --- a/tests/ServerlessWorkflow.Sdk.UnitTests/Resources/secrets/default.yaml +++ /dev/null @@ -1 +0,0 @@ -- test \ No newline at end of file diff --git a/tests/ServerlessWorkflow.Sdk.UnitTests/Resources/workflows/extended.json b/tests/ServerlessWorkflow.Sdk.UnitTests/Resources/workflows/extended.json deleted file mode 100644 index e9ae04c..0000000 --- a/tests/ServerlessWorkflow.Sdk.UnitTests/Resources/workflows/extended.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "id": "extended-workflow", - "name": "Extended workflow", - "version": "1.0.0", - "specVersion": "0.8", - "extensions": [ - { - "extensionId": "customState", - "resource": "resources\\extensions\\state-type-extension.json" - } - ], - "states": [ - { - "name": "AWS Step Function State", - "type": "x-aws-step-function", - "functions": [ - { - "name": "arn:aws:lambda:us-east-1:YOUR_ACCCOUNT_NUMBER:function:ApiCaller:$LATEST", - "payload": {} - } - ], - "end": true - } - ] -} \ No newline at end of file diff --git a/tests/ServerlessWorkflow.Sdk.UnitTests/Resources/workflows/external-function-definition.json b/tests/ServerlessWorkflow.Sdk.UnitTests/Resources/workflows/external-function-definition.json deleted file mode 100644 index 31b8fdd..0000000 --- a/tests/ServerlessWorkflow.Sdk.UnitTests/Resources/workflows/external-function-definition.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "id": "undefined", - "name": "Undefined", - "version": "0.1.0", - "specVersion": "0.8", - "functions": "file://resources/functions/petstore.json", - "states": [ - { - "name": "Test", - "type": "operation", - "actions": [ - { - "name": "test", - "functionRef": { - "refName": "GetPetById" - } - } - ], - "end": true - } - ] -} \ No newline at end of file diff --git a/tests/ServerlessWorkflow.Sdk.UnitTests/Resources/workflows/external-input-data-schema.json b/tests/ServerlessWorkflow.Sdk.UnitTests/Resources/workflows/external-input-data-schema.json deleted file mode 100644 index 3bf2b17..0000000 --- a/tests/ServerlessWorkflow.Sdk.UnitTests/Resources/workflows/external-input-data-schema.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "id": "flow-with-input-data", - "name": "flow-with-input-data", - "version": "0.1.0", - "specVersion": "0.8", - "dataInputSchema": "file://resources/dataschemas/input-data-schema.json", - "states": [ - { - "name": "inject", - "type": "inject", - "data": {}, - "end": true - } - ] -} \ No newline at end of file diff --git a/tests/ServerlessWorkflow.Sdk.UnitTests/Resources/workflows/externalref.json b/tests/ServerlessWorkflow.Sdk.UnitTests/Resources/workflows/externalref.json deleted file mode 100644 index 6073ccd..0000000 --- a/tests/ServerlessWorkflow.Sdk.UnitTests/Resources/workflows/externalref.json +++ /dev/null @@ -1,28 +0,0 @@ -{ - "id": "ExternalRef", - "name": "ExternalRef", - "version": "0.1.0", - "dataInputSchema": "file://resources/schemas/externalref.json", - "constants": "file://resources/constants/petstore.json", - "events": "file://resources/events/petstore.json", - "functions": "file://resources/functions/petstore.json", - "retries": "file://resources/retries/default.json", - "secrets": "file://resources/secrets/default.json", - "auth": "file://resources/auths/default.json", - "states": [ - { - "name": "CreatePet", - "type": "operation", - "actions": [ - { - "name": "CreatePet", - "eventRef": { - "triggerEventRef": "PetCreated", - "resultEventRef": "PetCreated" - } - } - ], - "end": true - } - ] -} \ No newline at end of file diff --git a/tests/ServerlessWorkflow.Sdk.UnitTests/Resources/workflows/externalref.yaml b/tests/ServerlessWorkflow.Sdk.UnitTests/Resources/workflows/externalref.yaml deleted file mode 100644 index 275e4cf..0000000 --- a/tests/ServerlessWorkflow.Sdk.UnitTests/Resources/workflows/externalref.yaml +++ /dev/null @@ -1,19 +0,0 @@ -id: ExternalRef -name: ExternalRef -version: "0.1.0" -dataInputSchema: file:///resources/schemas/externalref.yaml -constants: file:///resources/constants/petstore.yaml -events: file:///resources/events/petstore.yaml -functions: file:///resources/functions/petstore.yaml -retries: file:///resources/retries/default.yaml -secrets: file:///resources/secrets/default.yaml -auth: file:///resources/auths/default.yaml -states: - - name: CreatePet - type: operation - actions: - - name: CreatePet - eventRef: - triggerEventRef: PetCreated - resultEventRef: PetCreated - end: true \ No newline at end of file diff --git a/tests/ServerlessWorkflow.Sdk.UnitTests/Resources/workflows/input-data-schema.json b/tests/ServerlessWorkflow.Sdk.UnitTests/Resources/workflows/input-data-schema.json deleted file mode 100644 index fbb5355..0000000 --- a/tests/ServerlessWorkflow.Sdk.UnitTests/Resources/workflows/input-data-schema.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "id": "flow-with-input-data", - "name": "flow-with-input-data", - "version": "0.1.0", - "specVersion": "0.8", - "dataInputSchema": { - "schema": "file://resources/schemas/input-data.json", - "failOnValidationErrors": false - }, - "states": [ - { - "name": "inject", - "type": "inject", - "data": {}, - "end": true - } - ] - } \ No newline at end of file diff --git a/tests/ServerlessWorkflow.Sdk.UnitTests/Resources/workflows/missing-transition.json b/tests/ServerlessWorkflow.Sdk.UnitTests/Resources/workflows/missing-transition.json deleted file mode 100644 index 4d39ec8..0000000 --- a/tests/ServerlessWorkflow.Sdk.UnitTests/Resources/workflows/missing-transition.json +++ /dev/null @@ -1,57 +0,0 @@ -{ - "id": "compensation-test", - "name": "Compensation Test", - "version": "0.1.0", - "specVersion": "0.8", - "functions": [ - { - "name": "is-odd", - "type": "expression", - "operation": ".number % 2 == 1" - }, - { - "name": "i-fail", - "type": "rest", - "operation": "http://somefail.com/fails#fake" - } - ], - "states": [ - { - "name": "Good odds", - "type": "switch", - "dataConditions": [ - { - "name": "Is Odd", - "condition": "${ fn:is-odd }", - "end": true - } - ], - "defaultCondition": { - "transition": "Non existing state, should not be valid" - } - }, - { - "name": "I have something to compensate...", - "type": "operation", - "actions": [ - { - "name": "Call i-fail", - "functionRef": { - "refName": "i-fail" - } - } - ], - "compensatedBy": "Compensate", - "end": true - }, - { - "name": "Compensate", - "type": "inject", - "data": { - "status": "compensated" - }, - "usedForCompensation": true, - "end": true - } - ] -} \ No newline at end of file diff --git a/tests/ServerlessWorkflow.Sdk.UnitTests/Resources/workflows/operation.json b/tests/ServerlessWorkflow.Sdk.UnitTests/Resources/workflows/operation.json deleted file mode 100644 index 48502c8..0000000 --- a/tests/ServerlessWorkflow.Sdk.UnitTests/Resources/workflows/operation.json +++ /dev/null @@ -1,56 +0,0 @@ -{ - "id": "operation", - "name": "Operation", - "version": "0.1.0", - "events": [ - { - "name": "ProducedEvent", - "kind": "produced", - "type": "producedEvent", - "source": "workflow", - "dataOnly": false - }, - { - "name": "ConsumedEvent", - "kind": "consumed", - "type": "consumedEvent", - "source": "workflow", - "dataOnly": false - } - ], - "functions": [ - { - "name": "Function", - "operation": "http://fake.address" - } - ], - "metadata": { - "podSize": "small" - }, - "start": "Operation", - "states": [ - { - "name": "Operation", - "type": "operation", - "actions": [ - { - "name": "Function1", - "functionRef": { - "refName": "Function", - "arguments": { - "message": "Hello world!" - } - } - }, - { - "name": "Function2", - "eventRef": { - "triggerEventRef": "ProducedEvent", - "resultEventRef": "ConsumedEvent" - } - } - ], - "end": true - } - ] -} \ No newline at end of file diff --git a/tests/ServerlessWorkflow.Sdk.UnitTests/Resources/workflows/operation.yaml b/tests/ServerlessWorkflow.Sdk.UnitTests/Resources/workflows/operation.yaml deleted file mode 100644 index ff79a25..0000000 --- a/tests/ServerlessWorkflow.Sdk.UnitTests/Resources/workflows/operation.yaml +++ /dev/null @@ -1,32 +0,0 @@ -id: operation -name: Operation -version: "0.1.0" -events: - - name: ProducedEvent - kind: produced - type: producedEvent - source: workflow - - name: ConsumedEvent - kind: consumed - type: consumedEvent - source: workflow -functions: - - name: Function - operation: http://fake.address -metadata: - podSize: small -start: Operation -states: - - name: Operation - type: operation - actions: - - name: Function - functionRef: - refName: Function - arguments: - message: Hello world! - - name: Function - eventRef: - triggerEventRef: ProducedEvent - resultEventRef: ConsumedEvent - end: true \ No newline at end of file diff --git a/tests/ServerlessWorkflow.Sdk.UnitTests/ServerlessWorkflow.Sdk.UnitTests.csproj b/tests/ServerlessWorkflow.Sdk.UnitTests/ServerlessWorkflow.Sdk.UnitTests.csproj deleted file mode 100644 index bf61538..0000000 --- a/tests/ServerlessWorkflow.Sdk.UnitTests/ServerlessWorkflow.Sdk.UnitTests.csproj +++ /dev/null @@ -1,116 +0,0 @@ - - - - net7.0 - enable - enable - - false - - - - - - - - runtime; build; native; contentfiles; analyzers; buildtransitive - all - - - runtime; build; native; contentfiles; analyzers; buildtransitive - all - - - - - - - - - - PreserveNewest - - - PreserveNewest - - - Always - - - Always - - - Always - - - Always - - - PreserveNewest - - - Always - - - Always - - - PreserveNewest - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - - PreserveNewest - - - Always - - - Always - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - Always - - - Always - - - PreserveNewest - - - PreserveNewest - - - Always - - - Always - - - - diff --git a/tests/ServerlessWorkflow.Sdk.UnitTests/Services/WorkflowDefinitionFactory.cs b/tests/ServerlessWorkflow.Sdk.UnitTests/Services/WorkflowDefinitionFactory.cs index 9dad876..28f5649 100644 --- a/tests/ServerlessWorkflow.Sdk.UnitTests/Services/WorkflowDefinitionFactory.cs +++ b/tests/ServerlessWorkflow.Sdk.UnitTests/Services/WorkflowDefinitionFactory.cs @@ -1,4 +1,4 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors +// Copyright © 2024-Present The Serverless Workflow Specification Authors // // Licensed under the Apache License, Version 2.0 (the "License"), // you may not use this file except in compliance with the License. @@ -11,41 +11,163 @@ // See the License for the specific language governing permissions and // limitations under the License. +using ServerlessWorkflow.Sdk.Builders; + namespace ServerlessWorkflow.Sdk.UnitTests.Services; -public static class WorkflowDefinitionFactory +internal static class WorkflowDefinitionFactory { - public static WorkflowDefinition Create() + internal static WorkflowDefinition Create() { - return new WorkflowBuilder() - .WithId("fake") - .WithName("Fake Workflow") - .WithDescription("Fake Workflow Description") - .UseSpecVersion(ServerlessWorkflowSpecVersion.Latest) - .WithVersion("1.0.0") - .WithAnnotation("fake-annotation: Fake value") - .WithDataInputSchema(new Uri("https://tests.serverlessworkflow.io")) - .WithMetadata(new Dictionary() { { "fakeMetadataKey", "fakeMetadataValue" } }) - .WithExecutionTimeout(time => time.Run("fake-workflow:1.0.1").After(TimeSpan.FromSeconds(30))) - .AddBasicAuthentication("fake-auth-basic", basic => basic.WithUserName("fake@email.com").WithPassword("0123456789")) - .AddBearerAuthentication("fake-auth-bearer", bearer => bearer.WithToken("fake-token")) - .AddOAuth2Authentication("fake-auth-oauth2", oauth2 => oauth2.UseGrantType(OAuth2GrantType.ClientCredentials).WithClientId("fake-client").WithPassword("fake-password")) - .AddConstant("fake-constant", "fakeValue") - .AddEvent(e => e.WithName("fake-event-consumed").WithSource(new Uri("https://tests.serverlessworkflow.io")).WithType("tests.serverlessworkflow.io").CorrelateUsing("subject").IsConsumed()) - .AddEvent(e => e.WithName("fake-event-produced").WithSource(new Uri("https://tests.serverlessworkflow.io")).WithType("tests.serverlessworkflow.io").CorrelateUsing("subject").IsProduced()) - .AddFunction(f => f.WithName("fake-function-asyncapi").UseAuthentication("fake-auth-basic").OfType(FunctionType.AsyncApi).ForOperation(new Uri("https://tests.serverlessworkflow.io#fakeOperationId"))) - .AddFunction(f => f.WithName("fake-function-expression").UseAuthentication("fake-auth-bearer").OfType(FunctionType.Expression).ForOperation("${ . }")) - .AddFunction(f => f.WithName("fake-function-graphql").UseAuthentication("fake-auth-oauth2").OfType(FunctionType.GraphQL).ForOperation(new Uri("https://tests.serverlessworkflow.io#fakeOperationId"))) - .AddFunction(f => f.WithName("fake-function-odata").UseAuthentication("fake-auth-basic").OfType(FunctionType.OData).ForOperation(new Uri("https://tests.serverlessworkflow.io#fakeOperationId"))) - .AddFunction(f => f.WithName("fake-function-rest").UseAuthentication("fake-auth-bearer").OfType(FunctionType.Rest).ForOperation(new Uri("https://tests.serverlessworkflow.io#fakeOperationId"))) - .AddFunction(f => f.WithName("fake-function-rpc").UseAuthentication("fake-auth-oauth2").OfType(FunctionType.Rpc).ForOperation(new Uri("https://tests.serverlessworkflow.io#fakeOperationId"))) - .AddRetryStrategy(retry => retry.WithName("fakeRetry").WithDelayOf(TimeSpan.FromSeconds(2)).WithMaxDelay(TimeSpan.FromSeconds(10)).MaxAttempts(3)) - .AddSecret("fake-secret") - .UseJq() - .StartsWith("fake-inject", state => state.Inject(new { foo = "bar" })) - .Then("fake-operation", state => state.Execute("fake-function-asyncapi", action => action.Invoke("fake-function-asyncapi").Invoke("fake-function-rest").WithArguments(new Dictionary() { { "fake-argument-1", "fake-argument-1-value" }, { "fake-argument-2", "fake-argument-2-value" } }))) - .End() + return new WorkflowDefinitionBuilder() + .WithName("fake-name") + .WithVersion("0.1.0") + .WithTitle("Fake Title") + .WithSummary("Fake MD summary") + .WithTag("fakeTagName", "fakeTagValue") + .UseAuthentication("fakeBasic", authentication => authentication + .Basic() + .WithUsername("fake-user") + .WithPassword("fake-password")) + .UseAuthentication("fakeBearer", authentication => authentication + .Bearer() + .WithToken("fake-token")) + .UseAuthentication("fakeOAuth2", authentication => authentication + .OAuth2() + .WithAuthority(new("https://fake-authority.com")) + .WithGrantType(OAuth2GrantType.ClientCredentials) + .WithClient(client => client + .WithId("fake-client-id") + .WithSecret("fake-client-secret"))) + .UseFunction("fakeFunction1", function => function + .Function("http") + .With("method", "post") + .With("uri", "https://test.com")) + .UseFunction("fakeFunction2", function => function + .Shell() + .WithCommand(@"echo ""Hello, World!""")) + .UseExtension("fakeLoggingExtension", extension => extension + .ExtendAll() + .When("fake-expression") + .Before(task => task + .Call("http") + .With("method", "post") + .With("uri", "https://fake.log.collector.com") + .With("body", new + { + message = @"${ ""Executing task '\($task.reference)'..."" }" + })) + .After(task => task + .Call("http") + .With("method", "post") + .With("uri", "https://fake.log.collector.com") + .With("body", new + { + message = @"${ ""Executed task '\($task.reference)'..."" }" + }))) + .UseSecret("fake-secret") + .Do("todo-1", task => task + .Call("http") + .With("method", "get") + .With("uri", "https://unit-tests.serverlessworkflow.io")) + .Do("todo-2", task => task + .Emit(e => e + .With("type", "io.serverlessworkflow.unit-tests.fake.event.type.v1"))) + .Do("todo-3", task => task + .For() + .Each("color") + .In(".colors") + .At("index") + .Do(subtask => subtask + .Set("processed", ".processed + [$color]"))) + .Do("todo-4", task => task + .Listen() + .To(to => to + .Any() + .Event(e => e + .With("foo", "bar")) + .Event(e => e + .With(new Dictionary() { { "foo", "bar" }, { "bar", "baz" } })))) + .Do("todo-5", task => task + .Raise(error => error + .WithType("fake-error-type") + .WithStatus("400") + .WithTitle("fake-error-title"))) + .Do("todo-6", task => task + .Run() + .Container() + .WithImage("fake-image:latest") + .WithCommand("fake command --arg1 arg1") + .WithEnvironment("ASPNET_ENVIRONMENT", "Development")) + .Do("todo-7", task => task + .Run() + .Shell() + .WithCommand("fake command --arg1 arg1") + .WithArgument("--arg2 arg2") + .WithEnvironment("ASPNET_ENVIRONMENT", "Development")) + .Do("todo-8", task => task + .Run() + .Script() + .WithLanguage("js") + .WithCode(@"console.log(""Hello, World!"")")) + .Do("todo-9", task => task + .Run() + .Workflow() + .WithName("fake-workflow") + .WithVersion("1.0.0") + .WithInput(new { foo = "bar" })) + .Do("todo-10", task => task + .Set("foo", "bar") + .Set("bar", new { baz = "foo" })) + .Do("todo-11", task => task + .Switch() + .Case("case-1", @case => @case + .When("fake-condition") + .Then(FlowDirective.Continue)) + .Case("case-2", @case => @case + .When("another-fake-condition") + .Then(FlowDirective.Exit)) + .Case("default", @case => @case + .Then(FlowDirective.End))) + .Do("todo-12", task => task + .Try() + .Do(subtask => subtask + .Set("foo", "bar")) + .Catch(error => error + .Errors(filter => filter + .With("status", ". == 400")) + .As("error") + .When("fake-condition") + .ExceptWhen("another-fake-condition") + .Retry(retry => retry + .When("fake-condition") + .ExceptWhen("another-fake-condition") + .Limit(limits => limits + .Attempt() + .Count(10))) + .Do(subtask => subtask + .Set("foo", "bar")))) + .Do("todo-13", task => task + .Wait() + .For(Duration.FromMinutes(5))) + .Do("todo-14", task => task + .Execute() + .Sequentially(tasks => tasks + .Do("todo-14-1", task => task + .Call("http") + .With("method", "get") + .With("uri", "https://unit-tests.serverlessworkflow.io")) + .Do("todo-14-2", task => task + .Emit(e => e + .With("type", "io.serverlessworkflow.unit-tests.fake.event.type.v1"))) + .Do("todo-14-3", task => task + .For() + .Each("color") + .In(".colors") + .At("index") + .Do(subtask => subtask + .Set("processed", ".processed + [$color]"))))) .Build(); } diff --git a/tests/ServerlessWorkflow.Sdk.UnitTests/Usings.cs b/tests/ServerlessWorkflow.Sdk.UnitTests/Usings.cs index 7df36ac..3a0dcdd 100644 --- a/tests/ServerlessWorkflow.Sdk.UnitTests/Usings.cs +++ b/tests/ServerlessWorkflow.Sdk.UnitTests/Usings.cs @@ -1,4 +1,4 @@ -// Copyright © 2023-Present The Serverless Workflow Specification Authors +// Copyright © 2024-Present The Serverless Workflow Specification Authors // // Licensed under the Apache License, Version 2.0 (the "License"), // you may not use this file except in compliance with the License. @@ -11,8 +11,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -global using FluentAssertions; global using ServerlessWorkflow.Sdk.Models; -global using ServerlessWorkflow.Sdk.Services.FluentBuilders; global using ServerlessWorkflow.Sdk.UnitTests.Services; -global using Xunit; +global using FluentAssertions; From e288a91219820ef5aadd00eeae6d6fe55285541f Mon Sep 17 00:00:00 2001 From: Charles d'Avernas Date: Wed, 22 May 2024 19:31:00 +0200 Subject: [PATCH 2/2] fix(Solution): Fixed project version tags, and instead used VersionSuffix Signed-off-by: Charles d'Avernas --- .../ServerlessWorkflow.Sdk.Builders.csproj | 2 +- src/ServerlessWorkflow.Sdk.IO/ServerlessWorkflow.Sdk.IO.csproj | 2 +- src/ServerlessWorkflow.Sdk/ServerlessWorkflow.Sdk.csproj | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ServerlessWorkflow.Sdk.Builders/ServerlessWorkflow.Sdk.Builders.csproj b/src/ServerlessWorkflow.Sdk.Builders/ServerlessWorkflow.Sdk.Builders.csproj index ea83870..3aef435 100644 --- a/src/ServerlessWorkflow.Sdk.Builders/ServerlessWorkflow.Sdk.Builders.csproj +++ b/src/ServerlessWorkflow.Sdk.Builders/ServerlessWorkflow.Sdk.Builders.csproj @@ -4,8 +4,8 @@ net8.0 enable enable - $(VersionPrefix)-alpha1 1.0.0 + alpha1 $(VersionPrefix) $(VersionPrefix) en diff --git a/src/ServerlessWorkflow.Sdk.IO/ServerlessWorkflow.Sdk.IO.csproj b/src/ServerlessWorkflow.Sdk.IO/ServerlessWorkflow.Sdk.IO.csproj index 7be45e5..fc23d87 100644 --- a/src/ServerlessWorkflow.Sdk.IO/ServerlessWorkflow.Sdk.IO.csproj +++ b/src/ServerlessWorkflow.Sdk.IO/ServerlessWorkflow.Sdk.IO.csproj @@ -4,8 +4,8 @@ net8.0 enable enable - $(VersionPrefix)-alpha1 1.0.0 + alpha1 $(VersionPrefix) $(VersionPrefix) en diff --git a/src/ServerlessWorkflow.Sdk/ServerlessWorkflow.Sdk.csproj b/src/ServerlessWorkflow.Sdk/ServerlessWorkflow.Sdk.csproj index b17d744..dbc6ae2 100644 --- a/src/ServerlessWorkflow.Sdk/ServerlessWorkflow.Sdk.csproj +++ b/src/ServerlessWorkflow.Sdk/ServerlessWorkflow.Sdk.csproj @@ -4,8 +4,8 @@ net8.0 enable enable - $(VersionPrefix)-alpha1 1.0.0 + alpha1 $(VersionPrefix) $(VersionPrefix) en