2023-03-03 21:47:23 +00:00
|
|
|
using Elsa.Expressions.Contracts;
|
2022-05-26 10:47:31 +00:00
|
|
|
using Elsa.Expressions.Models;
|
2023-11-14 19:44:42 +00:00
|
|
|
using Elsa.Extensions;
|
2022-05-26 10:47:31 +00:00
|
|
|
using Elsa.JavaScript.Expressions;
|
Add JS functions for encoding/decoding byte arrays from and to strings (#5902)
* Add handlers and improve JavaScript engine configuration
Added several new handlers for configuring the JavaScript engine with common types, functions, variable accessors, and input/output accessors. Refactored the JintJavaScriptEvaluator for better clarity and modularity by breaking down configuration steps into separate methods. Also replaced `IsInsideCompositeActivity` with `IsContainedWithinCompositeActivity` for better semantic consistency.
* Refactor to use primary constructor syntax for TypeDefinitionProviders
Updated CommonTypeDefinitionProvider, VariableTypeDefinitionProvider, and ActivityOutputFunctionsDefinitionProvider to use primary constructors for dependency injection. This change reduces redundancy and simplifies the code structure for better readability and maintainability.
* Add byte conversion functions to JavaScript engine
Introduced functions for converting bytes to/from strings and Base64. Updated CommonFunctionsDefinitionProvider and ConfigureEngineWithCommonFunctions to incorporate these new functions. This enhances the JavaScript engine's ability to handle byte array manipulations.
* Add tests for JavaScript byte and string conversions.
Introduce integration tests to verify byte array to string, string to byte array, byte array to Base64, and Base64 to byte array conversions using JavaScript functions. Ensure accurate transformation of data within different encoding scenarios.
* Add meaningful summaries to Jint engine configuration handlers
Updated comment summaries in four handler classes to provide clear and concise descriptions of their purpose. This helps improve code readability and understanding for future developers.
* Rename and merge variable and input/output handlers
Merged the variable accessor logic into the input/output handler and renamed the class to reflect its broader functionality. This consolidation ensures the accessors are registered in the right order.
* Add string base64 conversion functions
Introduced `stringToBase64` and `stringFromBase64` functions to handle base64 encoding and decoding of strings. Updated corresponding provider, handler, and added tests to ensure functionality.
2024-08-14 15:43:35 +00:00
|
|
|
using JetBrains.Annotations;
|
2023-11-14 19:44:42 +00:00
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
2022-01-11 12:28:21 +00:00
|
|
|
|
2022-05-26 10:47:31 +00:00
|
|
|
namespace Elsa.JavaScript.Providers;
|
2022-01-11 12:28:21 +00:00
|
|
|
|
Add JS functions for encoding/decoding byte arrays from and to strings (#5902)
* Add handlers and improve JavaScript engine configuration
Added several new handlers for configuring the JavaScript engine with common types, functions, variable accessors, and input/output accessors. Refactored the JintJavaScriptEvaluator for better clarity and modularity by breaking down configuration steps into separate methods. Also replaced `IsInsideCompositeActivity` with `IsContainedWithinCompositeActivity` for better semantic consistency.
* Refactor to use primary constructor syntax for TypeDefinitionProviders
Updated CommonTypeDefinitionProvider, VariableTypeDefinitionProvider, and ActivityOutputFunctionsDefinitionProvider to use primary constructors for dependency injection. This change reduces redundancy and simplifies the code structure for better readability and maintainability.
* Add byte conversion functions to JavaScript engine
Introduced functions for converting bytes to/from strings and Base64. Updated CommonFunctionsDefinitionProvider and ConfigureEngineWithCommonFunctions to incorporate these new functions. This enhances the JavaScript engine's ability to handle byte array manipulations.
* Add tests for JavaScript byte and string conversions.
Introduce integration tests to verify byte array to string, string to byte array, byte array to Base64, and Base64 to byte array conversions using JavaScript functions. Ensure accurate transformation of data within different encoding scenarios.
* Add meaningful summaries to Jint engine configuration handlers
Updated comment summaries in four handler classes to provide clear and concise descriptions of their purpose. This helps improve code readability and understanding for future developers.
* Rename and merge variable and input/output handlers
Merged the variable accessor logic into the input/output handler and renamed the class to reflect its broader functionality. This consolidation ensures the accessors are registered in the right order.
* Add string base64 conversion functions
Introduced `stringToBase64` and `stringFromBase64` functions to handle base64 encoding and decoding of strings. Updated corresponding provider, handler, and added tests to ensure functionality.
2024-08-14 15:43:35 +00:00
|
|
|
[UsedImplicitly]
|
2023-11-14 19:44:42 +00:00
|
|
|
internal class JavaScriptExpressionDescriptorProvider : IExpressionDescriptorProvider
|
2022-01-11 12:28:21 +00:00
|
|
|
{
|
2023-11-14 19:44:42 +00:00
|
|
|
private const string TypeName = "JavaScript";
|
2022-01-11 12:28:21 +00:00
|
|
|
|
2023-12-10 20:43:24 +00:00
|
|
|
public IEnumerable<ExpressionDescriptor> GetDescriptors()
|
2022-01-11 12:28:21 +00:00
|
|
|
{
|
2023-12-10 20:43:24 +00:00
|
|
|
yield return new()
|
|
|
|
|
{
|
|
|
|
|
Type = TypeName,
|
|
|
|
|
DisplayName = "JavaScript",
|
|
|
|
|
Properties = new { MonacoLanguage = "javascript" }.ToDictionary(),
|
|
|
|
|
HandlerFactory = ActivatorUtilities.GetServiceOrCreateInstance<JavaScriptExpressionHandler>
|
|
|
|
|
};
|
2022-01-11 12:28:21 +00:00
|
|
|
}
|
|
|
|
|
}
|