| | | 1 | | using Elsa.Expressions.Models; |
| | | 2 | | using Elsa.Extensions; |
| | | 3 | | using Jint; |
| | | 4 | | |
| | | 5 | | namespace Elsa.Expressions.JavaScript.Options; |
| | | 6 | | |
| | | 7 | | /// <summary> |
| | | 8 | | /// Options for the Jint JavaScript engine. |
| | | 9 | | /// </summary> |
| | | 10 | | public class JintOptions |
| | | 11 | | { |
| | | 12 | | /// <summary> |
| | | 13 | | /// A list of callbacks that are invoked when the Jint engine options is created. Use this to configure the engine o |
| | | 14 | | /// </summary> |
| | 289 | 15 | | internal Action<Jint.Options, ExpressionExecutionContext> ConfigureEngineOptionsCallback = (_, _) => { }; |
| | | 16 | | |
| | | 17 | | /// <summary> |
| | | 18 | | /// A list of callbacks that are invoked when the Jint engine is created. Use this to configure the engine. |
| | | 19 | | /// </summary> |
| | 289 | 20 | | internal Action<Engine, ExpressionExecutionContext> ConfigureEngineCallback = (_, _) => { }; |
| | | 21 | | |
| | | 22 | | /// <summary> |
| | | 23 | | /// Enables access to any .NET class. Do not enable if you are executing workflows from untrusted sources (e.g. user |
| | | 24 | | /// |
| | | 25 | | /// See Jint docs for more: https://github.com/sebastienros/jint#accessing-net-assemblies-and-classes |
| | | 26 | | /// </summary> |
| | 190 | 27 | | public bool AllowClrAccess { get; set; } |
| | | 28 | | |
| | | 29 | | /// <summary> |
| | | 30 | | /// Enables access to .NET configuration via the <c>getConfig</c> function. |
| | | 31 | | /// Do not enable if you are executing workflows from untrusted sources (e.g user defined workflows). |
| | | 32 | | /// </summary> |
| | 188 | 33 | | public bool AllowConfigurationAccess { get; set; } |
| | | 34 | | |
| | | 35 | | /// <summary> |
| | | 36 | | /// The timeout for script caching. |
| | | 37 | | /// </summary> |
| | | 38 | | /// <remarks> |
| | | 39 | | /// The <c>ScriptCacheTimeout</c> property specifies the duration for which the scripts are cached in the Jint JavaS |
| | | 40 | | /// If the value of <c>ScriptCacheTimeout</c> is <c>null</c>, the scripts are cached indefinitely. If a time value i |
| | | 41 | | /// </remarks> |
| | 375 | 42 | | public TimeSpan? ScriptCacheTimeout { get; set; } = TimeSpan.FromDays(1); |
| | | 43 | | |
| | | 44 | | /// <summary> |
| | | 45 | | /// Disables the generation of variable wrappers. E.g. <c>getMyVariable()</c> will no longer be available for variab |
| | | 46 | | /// This is useful if your application requires the use of invalid JavaScript variable names. |
| | | 47 | | /// </summary> |
| | 566 | 48 | | public bool DisableWrappers { get; set; } |
| | | 49 | | |
| | | 50 | | /// <summary> |
| | | 51 | | /// Disables copying workflow variables into the Jint engine and copying them back into the workflow execution conte |
| | | 52 | | /// Disabling this option will increase performance but will also prevent you from accessing workflow variables from |
| | | 53 | | /// </summary> |
| | 378 | 54 | | public bool DisableVariableCopying { get; set; } |
| | | 55 | | |
| | | 56 | | /// <summary> |
| | | 57 | | /// Configures the Jint engine options. |
| | | 58 | | /// </summary> |
| | | 59 | | /// <param name="configurator">A callback that is invoked when the Jint engine options are created. Use this to conf |
| | | 60 | | public JintOptions ConfigureEngineOptions(Action<Jint.Options> configurator) |
| | | 61 | | { |
| | 0 | 62 | | ConfigureEngineOptionsCallback += (options, _) => configurator(options); |
| | 0 | 63 | | return this; |
| | | 64 | | } |
| | | 65 | | |
| | | 66 | | /// <summary> |
| | | 67 | | /// Configures the Jint engine options. |
| | | 68 | | /// </summary> |
| | | 69 | | /// <param name="configurator">A callback that is invoked when the Jint engine options are created. Use this to conf |
| | | 70 | | public JintOptions ConfigureEngineOptions(Action<Jint.Options, ExpressionExecutionContext> configurator) |
| | | 71 | | { |
| | 0 | 72 | | ConfigureEngineOptionsCallback += configurator; |
| | 0 | 73 | | return this; |
| | | 74 | | } |
| | | 75 | | |
| | | 76 | | /// <summary> |
| | | 77 | | /// Configures the Jint engine. |
| | | 78 | | /// </summary> |
| | | 79 | | /// <param name="configurator">A callback that is invoked when the Jint engine is created. Use this to configure the |
| | | 80 | | public JintOptions ConfigureEngine(Action<Engine, ExpressionExecutionContext> configurator) |
| | | 81 | | { |
| | 2 | 82 | | ConfigureEngineCallback += configurator; |
| | 2 | 83 | | return this; |
| | | 84 | | } |
| | | 85 | | |
| | | 86 | | /// <summary> |
| | | 87 | | /// Configures the Jint engine. |
| | | 88 | | /// </summary> |
| | | 89 | | /// <param name="configurator">A callback that is invoked when the Jint engine is created. Use this to configure the |
| | | 90 | | public JintOptions ConfigureEngine(Action<Engine> configurator) |
| | | 91 | | { |
| | 36 | 92 | | return ConfigureEngine((engine, _) => configurator(engine)); |
| | | 93 | | } |
| | | 94 | | |
| | | 95 | | /// <summary> |
| | | 96 | | /// Registers the specified type <c>T</c> with the engine. |
| | | 97 | | /// </summary> |
| | | 98 | | public JintOptions RegisterType<T>() |
| | | 99 | | { |
| | 0 | 100 | | return ConfigureEngine(engine => engine.RegisterType<T>()); |
| | | 101 | | } |
| | | 102 | | |
| | | 103 | | /// <summary> |
| | | 104 | | /// Registers the specified type with the engine. |
| | | 105 | | /// </summary> |
| | | 106 | | public JintOptions RegisterType(Type type) |
| | | 107 | | { |
| | 0 | 108 | | return ConfigureEngine(engine => engine.RegisterType(type)); |
| | | 109 | | } |
| | | 110 | | } |