Browse Source

Jint updated and tests fixed

pull/556/head
Sebastian 5 years ago
parent
commit
78836f2400
  1. 35
      backend/src/Squidex.Domain.Apps.Core.Operations/Scripting/ContentWrapper/ContentDataObject.cs
  2. 2
      backend/src/Squidex.Domain.Apps.Core.Operations/Scripting/ContentWrapper/ContentDataProperty.cs
  3. 43
      backend/src/Squidex.Domain.Apps.Core.Operations/Scripting/ContentWrapper/ContentFieldObject.cs
  4. 6
      backend/src/Squidex.Domain.Apps.Core.Operations/Scripting/ContentWrapper/JsonMapper.cs
  5. 9
      backend/src/Squidex.Domain.Apps.Core.Operations/Scripting/Extensions/HttpJintExtension.cs
  6. 10
      backend/src/Squidex.Domain.Apps.Core.Operations/Scripting/Internal/Parser.cs
  7. 2
      backend/src/Squidex.Domain.Apps.Core.Operations/Squidex.Domain.Apps.Core.Operations.csproj
  8. 1
      backend/src/Squidex.Domain.Apps.Entities/Apps/Templates/CreateIdentityV2CommandMiddleware.cs
  9. 1
      backend/src/Squidex.Domain.Apps.Entities/Squidex.Domain.Apps.Entities.csproj
  10. 3
      backend/tests/Squidex.Domain.Apps.Core.Tests/Operations/ValidateContent/Validators/NoValueValidatorTests.cs
  11. 3
      backend/tests/Squidex.Domain.Apps.Core.Tests/Operations/ValidateContent/Validators/RequiredStringValidatorTests.cs

35
backend/src/Squidex.Domain.Apps.Core.Operations/Scripting/ContentWrapper/ContentDataObject.cs

@ -6,9 +6,11 @@
// ========================================================================== // ==========================================================================
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using Jint; using Jint;
using Jint.Native; using Jint.Native;
using Jint.Native.Object; using Jint.Native.Object;
using Jint.Runtime;
using Jint.Runtime.Descriptors; using Jint.Runtime.Descriptors;
using Squidex.Domain.Apps.Core.Contents; using Squidex.Domain.Apps.Core.Contents;
using Squidex.Infrastructure; using Squidex.Infrastructure;
@ -24,11 +26,11 @@ namespace Squidex.Domain.Apps.Core.Scripting.ContentWrapper
private Dictionary<string, PropertyDescriptor> fieldProperties; private Dictionary<string, PropertyDescriptor> fieldProperties;
private bool isChanged; private bool isChanged;
public override bool Extensible => true;
public ContentDataObject(Engine engine, NamedContentData contentData) public ContentDataObject(Engine engine, NamedContentData contentData)
: base(engine) : base(engine)
{ {
Extensible = true;
this.contentData = contentData; this.contentData = contentData;
} }
@ -68,23 +70,27 @@ namespace Squidex.Domain.Apps.Core.Scripting.ContentWrapper
return isChanged; return isChanged;
} }
public override void RemoveOwnProperty(string propertyName) public override void RemoveOwnProperty(JsValue property)
{ {
if (fieldsToDelete == null) if (fieldsToDelete == null)
{ {
fieldsToDelete = new HashSet<string>(); fieldsToDelete = new HashSet<string>();
} }
var propertyName = property.AsString();
fieldsToDelete.Add(propertyName); fieldsToDelete.Add(propertyName);
fieldProperties?.Remove(propertyName); fieldProperties?.Remove(propertyName);
MarkChanged(); MarkChanged();
} }
public override bool DefineOwnProperty(string propertyName, PropertyDescriptor desc, bool throwOnError) public override bool DefineOwnProperty(JsValue property, PropertyDescriptor desc)
{ {
EnsurePropertiesInitialized(); EnsurePropertiesInitialized();
var propertyName = property.AsString();
if (!fieldProperties.ContainsKey(propertyName)) if (!fieldProperties.ContainsKey(propertyName))
{ {
fieldProperties[propertyName] = new ContentDataProperty(this) { Value = desc.Value }; fieldProperties[propertyName] = new ContentDataProperty(this) { Value = desc.Value };
@ -93,25 +99,38 @@ namespace Squidex.Domain.Apps.Core.Scripting.ContentWrapper
return true; return true;
} }
public override void Put(string propertyName, JsValue value, bool throwOnError) public override bool Set(JsValue property, JsValue value, JsValue receiver)
{ {
EnsurePropertiesInitialized(); EnsurePropertiesInitialized();
var propertyName = property.AsString();
fieldProperties.GetOrAdd(propertyName, this, (k, c) => new ContentDataProperty(c)).Value = value; fieldProperties.GetOrAdd(propertyName, this, (k, c) => new ContentDataProperty(c)).Value = value;
return true;
} }
public override PropertyDescriptor GetOwnProperty(string propertyName) public override PropertyDescriptor GetOwnProperty(JsValue property)
{ {
EnsurePropertiesInitialized(); EnsurePropertiesInitialized();
var propertyName = property.AsString();
return fieldProperties.GetOrAdd(propertyName, this, (k, c) => new ContentDataProperty(c, new ContentFieldObject(c, new ContentFieldData(), false))); return fieldProperties.GetOrAdd(propertyName, this, (k, c) => new ContentDataProperty(c, new ContentFieldObject(c, new ContentFieldData(), false)));
} }
public override IEnumerable<KeyValuePair<string, PropertyDescriptor>> GetOwnProperties() public override IEnumerable<KeyValuePair<JsValue, PropertyDescriptor>> GetOwnProperties()
{
EnsurePropertiesInitialized();
return fieldProperties.Select(x => new KeyValuePair<JsValue, PropertyDescriptor>(x.Key, x.Value));
}
public override List<JsValue> GetOwnPropertyKeys(Types types = Types.String | Types.Symbol)
{ {
EnsurePropertiesInitialized(); EnsurePropertiesInitialized();
return fieldProperties; return fieldProperties.Keys.Select(x => (JsValue)x).ToList();
} }
private void EnsurePropertiesInitialized() private void EnsurePropertiesInitialized()

2
backend/src/Squidex.Domain.Apps.Core.Operations/Scripting/ContentWrapper/ContentDataProperty.cs

@ -38,7 +38,7 @@ namespace Squidex.Domain.Apps.Core.Scripting.ContentWrapper
foreach (var (key, propertyDescriptor) in obj.GetOwnProperties()) foreach (var (key, propertyDescriptor) in obj.GetOwnProperties())
{ {
contentField.Put(key, propertyDescriptor.Value, true); contentField.Set(key, propertyDescriptor.Value);
} }
this.value = contentField; this.value = contentField;

43
backend/src/Squidex.Domain.Apps.Core.Operations/Scripting/ContentWrapper/ContentFieldObject.cs

@ -6,7 +6,11 @@
// ========================================================================== // ==========================================================================
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using Jint;
using Jint.Native;
using Jint.Native.Object; using Jint.Native.Object;
using Jint.Runtime;
using Jint.Runtime.Descriptors; using Jint.Runtime.Descriptors;
using Squidex.Domain.Apps.Core.Contents; using Squidex.Domain.Apps.Core.Contents;
using Squidex.Infrastructure; using Squidex.Infrastructure;
@ -28,12 +32,13 @@ namespace Squidex.Domain.Apps.Core.Scripting.ContentWrapper
get { return fieldData; } get { return fieldData; }
} }
public override bool Extensible => true;
public ContentFieldObject(ContentDataObject contentData, ContentFieldData? fieldData, bool isNew) public ContentFieldObject(ContentDataObject contentData, ContentFieldData? fieldData, bool isNew)
: base(contentData.Engine) : base(contentData.Engine)
{ {
Extensible = true;
this.contentData = contentData; this.contentData = contentData;
this.fieldData = fieldData; this.fieldData = fieldData;
if (isNew) if (isNew)
@ -80,23 +85,38 @@ namespace Squidex.Domain.Apps.Core.Scripting.ContentWrapper
return isChanged; return isChanged;
} }
public override void RemoveOwnProperty(string propertyName) public override void RemoveOwnProperty(JsValue property)
{ {
if (valuesToDelete == null) if (valuesToDelete == null)
{ {
valuesToDelete = new HashSet<string>(); valuesToDelete = new HashSet<string>();
} }
var propertyName = property.AsString();
valuesToDelete.Add(propertyName); valuesToDelete.Add(propertyName);
valueProperties?.Remove(propertyName); valueProperties?.Remove(propertyName);
MarkChanged(); MarkChanged();
} }
public override bool DefineOwnProperty(string propertyName, PropertyDescriptor desc, bool throwOnError) public override bool Set(JsValue property, JsValue value, JsValue receiver)
{ {
EnsurePropertiesInitialized(); EnsurePropertiesInitialized();
var propertyName = property.AsString();
valueProperties.GetOrAdd(propertyName, k => new ContentFieldProperty(this)).Value = value;
return true;
}
public override bool DefineOwnProperty(JsValue property, PropertyDescriptor desc)
{
EnsurePropertiesInitialized();
var propertyName = property.AsString();
if (!valueProperties.ContainsKey(propertyName)) if (!valueProperties.ContainsKey(propertyName))
{ {
valueProperties[propertyName] = new ContentFieldProperty(this) { Value = desc.Value }; valueProperties[propertyName] = new ContentFieldProperty(this) { Value = desc.Value };
@ -105,18 +125,27 @@ namespace Squidex.Domain.Apps.Core.Scripting.ContentWrapper
return true; return true;
} }
public override PropertyDescriptor GetOwnProperty(string propertyName) public override PropertyDescriptor GetOwnProperty(JsValue property)
{ {
EnsurePropertiesInitialized(); EnsurePropertiesInitialized();
var propertyName = property.AsString();
return valueProperties?.GetOrDefault(propertyName) ?? PropertyDescriptor.Undefined; return valueProperties?.GetOrDefault(propertyName) ?? PropertyDescriptor.Undefined;
} }
public override IEnumerable<KeyValuePair<string, PropertyDescriptor>> GetOwnProperties() public override IEnumerable<KeyValuePair<JsValue, PropertyDescriptor>> GetOwnProperties()
{
EnsurePropertiesInitialized();
return valueProperties.Select(x => new KeyValuePair<JsValue, PropertyDescriptor>(x.Key, x.Value));
}
public override List<JsValue> GetOwnPropertyKeys(Types types = Types.String | Types.Symbol)
{ {
EnsurePropertiesInitialized(); EnsurePropertiesInitialized();
return valueProperties; return valueProperties.Keys.Select(x => (JsValue)x).ToList();
} }
private void EnsurePropertiesInitialized() private void EnsurePropertiesInitialized()

6
backend/src/Squidex.Domain.Apps.Core.Operations/Scripting/ContentWrapper/JsonMapper.cs

@ -62,6 +62,8 @@ namespace Squidex.Domain.Apps.Core.Scripting.ContentWrapper
target.FastAddProperty(key, Map(value, engine), false, true, true); target.FastAddProperty(key, Map(value, engine), false, true, true);
} }
target.PreventExtensions();
return target; return target;
} }
@ -103,7 +105,7 @@ namespace Squidex.Domain.Apps.Core.Scripting.ContentWrapper
var result = JsonValue.Array(); var result = JsonValue.Array();
for (var i = 0; i < arr.GetLength(); i++) for (var i = 0; i < arr.Length; i++)
{ {
result.Add(Map(arr.Get(i.ToString()))); result.Add(Map(arr.Get(i.ToString())));
} }
@ -119,7 +121,7 @@ namespace Squidex.Domain.Apps.Core.Scripting.ContentWrapper
foreach (var (key, propertyDescriptor) in obj.GetOwnProperties()) foreach (var (key, propertyDescriptor) in obj.GetOwnProperties())
{ {
result[key] = Map(propertyDescriptor.Value); result[key.AsString()] = Map(propertyDescriptor.Value);
} }
return result; return result;

9
backend/src/Squidex.Domain.Apps.Core.Operations/Scripting/Extensions/HttpJintExtension.cs

@ -8,6 +8,7 @@
using System; using System;
using System.Net.Http; using System.Net.Http;
using System.Threading.Tasks; using System.Threading.Tasks;
using Jint;
using Jint.Native; using Jint.Native;
using Jint.Native.Json; using Jint.Native.Json;
using Jint.Runtime; using Jint.Runtime;
@ -58,7 +59,7 @@ namespace Squidex.Domain.Apps.Core.Scripting.Extensions
var responseObject = await ParseResponse(context, response); var responseObject = await ParseResponse(context, response);
context.Engine.ResetTimeoutTicks(); context.Engine.ResetConstraints();
callback(responseObject); callback(responseObject);
} }
@ -86,9 +87,11 @@ namespace Squidex.Domain.Apps.Core.Scripting.Extensions
{ {
var value = TypeConverter.ToString(property.Value); var value = TypeConverter.ToString(property.Value);
if (!string.IsNullOrWhiteSpace(key)) var keyString = key.AsString();
if (!string.IsNullOrWhiteSpace(keyString))
{ {
request.Headers.TryAddWithoutValidation(key, value ?? string.Empty); request.Headers.TryAddWithoutValidation(keyString, value ?? string.Empty);
} }
} }
} }

10
backend/src/Squidex.Domain.Apps.Core.Operations/Scripting/Internal/Parser.cs

@ -30,20 +30,20 @@ namespace Squidex.Domain.Apps.Core.Scripting.Internal
this.memoryCache = memoryCache; this.memoryCache = memoryCache;
} }
public Program Parse(string script) public Script Parse(string script)
{ {
var key = Key(script); var key = Key(script);
if (!memoryCache.TryGetValue<Program>(key, out var program)) if (!memoryCache.TryGetValue<Script>(key, out var compiledScript))
{ {
var parser = new JavaScriptParser(script, DefaultParserOptions); var parser = new JavaScriptParser(script, DefaultParserOptions);
program = parser.ParseProgram(); compiledScript = parser.ParseScript();
memoryCache.Set(key, program, Expiration); memoryCache.Set(key, compiledScript, Expiration);
} }
return program; return compiledScript;
} }
private static string Key(string script) private static string Key(string script)

2
backend/src/Squidex.Domain.Apps.Core.Operations/Squidex.Domain.Apps.Core.Operations.csproj

@ -18,7 +18,7 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Fluid.Core.Squidex" Version="1.0.0-beta" /> <PackageReference Include="Fluid.Core.Squidex" Version="1.0.0-beta" />
<PackageReference Include="HtmlAgilityPack" Version="1.11.24" /> <PackageReference Include="HtmlAgilityPack" Version="1.11.24" />
<PackageReference Include="Jint" Version="3.0.0-beta-1580" /> <PackageReference Include="Jint" Version="3.0.0-beta-1828" />
<PackageReference Include="Markdig" Version="0.20.0" /> <PackageReference Include="Markdig" Version="0.20.0" />
<PackageReference Include="Microsoft.Extensions.Http" Version="3.1.4" /> <PackageReference Include="Microsoft.Extensions.Http" Version="3.1.4" />
<PackageReference Include="Microsoft.OData.Core" Version="7.6.4" /> <PackageReference Include="Microsoft.OData.Core" Version="7.6.4" />

1
backend/src/Squidex.Domain.Apps.Entities/Apps/Templates/CreateIdentityV2CommandMiddleware.cs

@ -7,7 +7,6 @@
using System; using System;
using System.Threading.Tasks; using System.Threading.Tasks;
using Fluid;
using Squidex.Domain.Apps.Entities.Apps.Commands; using Squidex.Domain.Apps.Entities.Apps.Commands;
using Squidex.Domain.Apps.Entities.Apps.Templates.Builders; using Squidex.Domain.Apps.Entities.Apps.Templates.Builders;
using Squidex.Infrastructure; using Squidex.Infrastructure;

1
backend/src/Squidex.Domain.Apps.Entities/Squidex.Domain.Apps.Entities.csproj

@ -20,7 +20,6 @@
<PackageReference Include="CsvHelper" Version="15.0.5" /> <PackageReference Include="CsvHelper" Version="15.0.5" />
<PackageReference Include="Elasticsearch.Net" Version="7.7.1" /> <PackageReference Include="Elasticsearch.Net" Version="7.7.1" />
<PackageReference Include="Equals.Fody" Version="4.0.1" PrivateAssets="all" /> <PackageReference Include="Equals.Fody" Version="4.0.1" PrivateAssets="all" />
<PackageReference Include="FluentValidation" Version="9.0.1" />
<PackageReference Include="Fody" Version="6.2.0"> <PackageReference Include="Fody" Version="6.2.0">
<PrivateAssets>all</PrivateAssets> <PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>

3
backend/tests/Squidex.Domain.Apps.Core.Tests/Operations/ValidateContent/Validators/NoValueValidatorTests.cs

@ -8,6 +8,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading.Tasks; using System.Threading.Tasks;
using FluentAssertions; using FluentAssertions;
using Squidex.Domain.Apps.Core.TestHelpers;
using Squidex.Domain.Apps.Core.ValidateContent; using Squidex.Domain.Apps.Core.ValidateContent;
using Squidex.Domain.Apps.Core.ValidateContent.Validators; using Squidex.Domain.Apps.Core.ValidateContent.Validators;
using Squidex.Infrastructure.Json.Objects; using Squidex.Infrastructure.Json.Objects;
@ -15,7 +16,7 @@ using Xunit;
namespace Squidex.Domain.Apps.Core.Operations.ValidateContent.Validators namespace Squidex.Domain.Apps.Core.Operations.ValidateContent.Validators
{ {
public class NoValueValidatorTests public class NoValueValidatorTests : IClassFixture<TranslationsFixture>
{ {
private readonly List<string> errors = new List<string>(); private readonly List<string> errors = new List<string>();

3
backend/tests/Squidex.Domain.Apps.Core.Tests/Operations/ValidateContent/Validators/RequiredStringValidatorTests.cs

@ -8,12 +8,13 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading.Tasks; using System.Threading.Tasks;
using FluentAssertions; using FluentAssertions;
using Squidex.Domain.Apps.Core.TestHelpers;
using Squidex.Domain.Apps.Core.ValidateContent.Validators; using Squidex.Domain.Apps.Core.ValidateContent.Validators;
using Xunit; using Xunit;
namespace Squidex.Domain.Apps.Core.Operations.ValidateContent.Validators namespace Squidex.Domain.Apps.Core.Operations.ValidateContent.Validators
{ {
public class RequiredStringValidatorTests public class RequiredStringValidatorTests : IClassFixture<TranslationsFixture>
{ {
private readonly List<string> errors = new List<string>(); private readonly List<string> errors = new List<string>();

Loading…
Cancel
Save