Skip to content

Commit

Permalink
AI Tools V2 (#1103)
Browse files Browse the repository at this point in the history
* More AI tools.

* More tools.
  • Loading branch information
SebastianStehle committed Jun 22, 2024
1 parent edd93b0 commit 96efe94
Show file tree
Hide file tree
Showing 96 changed files with 1,224 additions and 201 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@
<PackageReference Include="Elasticsearch.Net" Version="7.17.5" />
<PackageReference Include="Google.Cloud.Diagnostics.Common" Version="5.2.0" />
<PackageReference Include="Google.Cloud.Logging.V2" Version="4.4.0" />
<PackageReference Include="Google.Cloud.Monitoring.V3" Version="3.9.0" />
<PackageReference Include="Meziantou.Analyzer" Version="2.0.153">
<PackageReference Include="Google.Cloud.Monitoring.V3" Version="3.10.0" />
<PackageReference Include="Meziantou.Analyzer" Version="2.0.155">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Azure.CognitiveServices.Vision.ComputerVision" Version="7.0.1" />
<PackageReference Include="Microsoft.Azure.SignalR.Management" Version="1.25.2" />
<PackageReference Include="Microsoft.Extensions.Http" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
<PackageReference Include="Microsoft.OData.Core" Version="7.21.2" />
<PackageReference Include="Microsoft.OData.Core" Version="7.21.3" />
<PackageReference Include="NodaTime" Version="3.1.11" />
<PackageReference Include="OpenSearch.Net" Version="1.7.1" />
<PackageReference Include="OpenTelemetry.Exporter.Console" Version="1.8.1" />
Expand Down
2 changes: 1 addition & 1 deletion backend/src/Migrations/Migrations.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Meziantou.Analyzer" Version="2.0.153">
<PackageReference Include="Meziantou.Analyzer" Version="2.0.155">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public sealed class LanguagesConfigSurrogate : ISurrogate<LanguagesConfig>

public void FromSource(LanguagesConfig source)
{
Languages = source.Languages.ToDictionary(x => x.Key, source =>
Languages = source.Values.ToDictionary(x => x.Key, source =>
{
var surrogate = new LanguageConfigSurrogate();
Expand Down
33 changes: 16 additions & 17 deletions backend/src/Squidex.Domain.Apps.Core.Model/Apps/LanguagesConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public sealed class LanguagesConfig : IFieldPartitioning
},
Language.EN);

private readonly Dictionary<string, LanguageConfig> languages;
private readonly Dictionary<string, LanguageConfig> values;
private readonly string master;

public string Master
Expand All @@ -30,23 +30,22 @@ public string Master

public IEnumerable<string> AllKeys
{
get => languages.Keys;
get => values.Keys;
}

public IReadOnlyDictionary<string, LanguageConfig> Languages
public IReadOnlyDictionary<string, LanguageConfig> Values
{
get => languages;
get => values;
}

public LanguagesConfig(Dictionary<string, LanguageConfig> languages, string master)
public LanguagesConfig(Dictionary<string, LanguageConfig> values, string master)
{
Guard.NotNull(languages);
Guard.NotNull(values);
Guard.NotNullOrEmpty(master);

Cleanup(languages, ref master);

this.languages = languages;
Cleanup(values, ref master);

this.values = values;
this.master = master;
}

Expand All @@ -55,15 +54,15 @@ public LanguagesConfig MakeMaster(Language language)
{
Guard.NotNull(language);

return Build(languages, language);
return Build(values, language);
}

[Pure]
public LanguagesConfig Set(Language language, bool isOptional = false, params Language[]? fallbacks)
{
Guard.NotNull(language);

var newLanguages = new Dictionary<string, LanguageConfig>(languages)
var newLanguages = new Dictionary<string, LanguageConfig>(values)
{
[language] = new LanguageConfig(isOptional, ReadonlyList.Create(fallbacks))
};
Expand All @@ -76,7 +75,7 @@ public LanguagesConfig Remove(Language language)
{
Guard.NotNull(language);

var newLanguages = new Dictionary<string, LanguageConfig>(languages);
var newLanguages = new Dictionary<string, LanguageConfig>(values);

newLanguages.Remove(language);

Expand All @@ -102,7 +101,7 @@ private LanguagesConfig Build(Dictionary<string, LanguageConfig> newLanguages, s

private bool EqualLanguages(Dictionary<string, LanguageConfig> newLanguages)
{
return newLanguages.EqualsDictionary(languages);
return newLanguages.EqualsDictionary(values);
}

private void Cleanup(Dictionary<string, LanguageConfig> newLanguages, ref string newMaster)
Expand Down Expand Up @@ -152,7 +151,7 @@ public bool IsMaster(string key)

public string? GetName(string key)
{
if (key != null && languages.ContainsKey(key))
if (key != null && values.ContainsKey(key))
{
return Language.GetLanguage(key).EnglishName;
}
Expand All @@ -162,7 +161,7 @@ public bool IsMaster(string key)

public bool IsOptional(string key)
{
if (key != null && languages.TryGetValue(key, out var value))
if (key != null && values.TryGetValue(key, out var value))
{
return value.IsOptional;
}
Expand All @@ -178,7 +177,7 @@ public IEnumerable<string> GetPriorities(string key)
{
yield return key;
}
else if (languages.TryGetValue(key, out var config))
else if (values.TryGetValue(key, out var config))
{
yield return key;

Expand All @@ -197,7 +196,7 @@ public IEnumerable<string> GetPriorities(string key)

public bool Contains(string key)
{
return key != null && languages.ContainsKey(key);
return key != null && values.ContainsKey(key);
}

public override string ToString()
Expand Down
27 changes: 20 additions & 7 deletions backend/src/Squidex.Domain.Apps.Core.Model/Contents/ContentData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ public ContentData()
{
}

public ContentData(ContentData source)
: base(source, StringComparer.Ordinal)
public ContentData(int capacity)
: base(capacity, StringComparer.Ordinal)
{
}

public ContentData(int capacity)
: base(capacity, StringComparer.Ordinal)
public ContentData(IDictionary<string, ContentFieldData?> source)
: base(source, StringComparer.Ordinal)
{
}

Expand Down Expand Up @@ -96,16 +96,29 @@ private static ContentData MergeTo(ContentData target, params ContentData[] sour
continue;
}

var targetFieldData = target.GetOrAdd(fieldName, _ => new ContentFieldData());
if (Updates.IsUnset(sourceFieldData))
{
target.Remove(fieldName);
continue;
}

var targetFieldData = target.GetOrAdd(fieldName, _ => []);

if (targetFieldData == null)
{
continue;
}

foreach (var (partition, value) in sourceFieldData)
foreach (var (partition, sourceValue) in sourceFieldData)
{
targetFieldData[partition] = value;
if (Updates.IsUnset(sourceValue))
{
targetFieldData.Remove(partition);
}
else
{
targetFieldData[partition] = sourceValue;
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,9 @@ public ContentFieldData(int capacity)
{
}

public ContentFieldData(ContentFieldData source)
: base(source.Count, StringComparer.OrdinalIgnoreCase)
public ContentFieldData(IDictionary<string, JsonValue> source)
: base(source, StringComparer.Ordinal)
{
foreach (var (key, value) in source)
{
this[key] = value;
}
}

public bool TryGetNonNull(string key, [MaybeNullWhen(false)] out JsonValue result)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public static TranslationStatus Create(ContentData data, Schema schema, Language
Guard.NotNull(schema);
Guard.NotNull(languages);

var result = new TranslationStatus(languages.Languages.Count);
var result = new TranslationStatus(languages.Values.Count);

var localizedFields = schema.Fields.Where(x => x.Partitioning == Partitioning.Language).ToList();

Expand Down
59 changes: 59 additions & 0 deletions backend/src/Squidex.Domain.Apps.Core.Model/Contents/Updates.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// ==========================================================================
// Squidex Headless CMS
// ==========================================================================
// Copyright (c) Squidex UG (haftungsbeschraenkt)
// All rights reserved. Licensed under the MIT license.
// ==========================================================================

using Squidex.Infrastructure.Json.Objects;

namespace Squidex.Domain.Apps.Core.Contents;

public static class Updates
{
public static bool IsUnset(object? value)
{
if (value is JsonValue json)
{
return IsUnset(json.Value);
}

return value is IReadOnlyDictionary<string, JsonValue> obj && IsUnset(obj);
}

public static bool IsUnset(IReadOnlyDictionary<string, JsonValue>? obj)
{
return
obj is { Count: 1 } &&
obj.TryGetValue("$unset", out var item) &&
Equals(item.Value, true);
}

public static bool IsUpdate(object? value, out string expression)
{
expression = null!;

if (value is JsonValue json)
{
return IsUpdate(json.Value, out expression);
}

return value is IReadOnlyDictionary<string, JsonValue> obj && IsUpdate(obj, out expression);
}

public static bool IsUpdate(IReadOnlyDictionary<string, JsonValue>? obj, out string expression)
{
expression = null!;

if (obj is { Count: > 0 } &&
obj.TryGetValue("$update", out var item) &&
item.Value is string e &&
!string.IsNullOrWhiteSpace(e))
{
expression = e;
return true;
}

return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<DebugSymbols>True</DebugSymbols>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Meziantou.Analyzer" Version="2.0.153">
<PackageReference Include="Meziantou.Analyzer" Version="2.0.155">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
Loading

0 comments on commit 96efe94

Please sign in to comment.